diff --git a/CHANGELOG.md b/CHANGELOG.md index 0da47089..48a6c8f8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,14 @@ # Changelog -## Latest Version - v13.0.4 (11/06/24) +## Latest Version - v13.0.5 (11/14/24) +### Enhancements: +- [GP-API] - Add new mapping fields on digital wallet transaction response: masked_number_last4, brand, brand_reference +- [MITC UPA] - Add new commands: getAppInfo, getParam, setTimeZone,clearDataLake, reset, returnToIdle, getDeviceConfig, + print, scan, getDebugInfo, setDebugLevel, getDebugLevel, getSignatureFile, communicationCheck, logon, + findBatches, getBatchDetails, getBatchReport, displayMessage + +## v13.0.4 (11/07/24) ### Enhancements: - [Portico] Added 'GatewayTxnId' value to GatewayException message when available diff --git a/metadata.xml b/metadata.xml index 2f724235..c0c28278 100644 --- a/metadata.xml +++ b/metadata.xml @@ -1,3 +1,3 @@ - 13.0.4 + 13.0.5 \ No newline at end of file diff --git a/src/Gateways/GpApiConnector.php b/src/Gateways/GpApiConnector.php index 30a7fb76..9704f90e 100644 --- a/src/Gateways/GpApiConnector.php +++ b/src/Gateways/GpApiConnector.php @@ -177,7 +177,7 @@ public function processBoardingUser(PayFacBuilder $builder): User } $response = $this->executeProcess($builder); - return GpApiMapping::mapMerchantsEndpointResponse($response, $builder->userReference); + return GpApiMapping::mapMerchantsEndpointResponse($response); } public function processPayFac(PayFacBuilder $builder) diff --git a/src/Mapping/GpApiMapping.php b/src/Mapping/GpApiMapping.php index af1e2525..83c31d8f 100644 --- a/src/Mapping/GpApiMapping.php +++ b/src/Mapping/GpApiMapping.php @@ -2,6 +2,8 @@ namespace GlobalPayments\Api\Mapping; +use DateTime; +use Exception; use GlobalPayments\Api\Entities\Address; use GlobalPayments\Api\Entities\AddressCollection; use GlobalPayments\Api\Entities\AlternativePaymentResponse; @@ -29,6 +31,7 @@ use GlobalPayments\Api\Entities\Enums\TransactionStatus; use GlobalPayments\Api\Entities\Enums\UserType; use GlobalPayments\Api\Entities\Exceptions\ApiException; +use GlobalPayments\Api\Entities\Exceptions\ArgumentException; use GlobalPayments\Api\Entities\FileList; use GlobalPayments\Api\Entities\FileProcessor; use GlobalPayments\Api\Entities\FileUploaded; @@ -38,7 +41,6 @@ use GlobalPayments\Api\Entities\GpApi\PagedResult; use GlobalPayments\Api\Entities\PayerDetails; use GlobalPayments\Api\Entities\PayByLinkResponse; -use GlobalPayments\Api\Entities\PayFac\UserReference; use GlobalPayments\Api\Entities\PaymentMethodList; use GlobalPayments\Api\Entities\Person; use GlobalPayments\Api\Entities\PersonList; @@ -92,8 +94,9 @@ class GpApiMapping * * @param Object $response * @return Transaction + * @throws Exception */ - public static function mapResponse($response) + public static function mapResponse(object $response): Transaction { $transaction = new Transaction(); @@ -176,7 +179,8 @@ public static function mapResponse($response) } return $transaction; } - private static function mapBatchCloseResponse(BatchSummary &$batchSummary, $response) : void + + private static function mapBatchCloseResponse(BatchSummary &$batchSummary, $response): void { $batchSummary->id = $response->id; $batchSummary->processedDeviceId = $response->device_reference ?? null; @@ -190,7 +194,7 @@ private static function mapBatchCloseResponse(BatchSummary &$batchSummary, $resp } } - private static function extractBatchTotals($response) : BatchTotals + private static function extractBatchTotals($response): BatchTotals { $batchTotals = new BatchTotals(); $batchTotals->salesCount = $response->sales->count ?? null; @@ -212,6 +216,10 @@ private static function extractBatchTotals($response) : BatchTotals return $batchTotals; } + + /** + * @throws Exception + */ private static function mapTransferFundsAccountDetails(&$transaction, $transfersResponse): void { $transfers = new TransferFundsAccountCollection(); @@ -219,7 +227,7 @@ private static function mapTransferFundsAccountDetails(&$transaction, $transfers $transfer = new FundsAccountDetails(); $transfer->id = $transferResponse->id; $transfer->timeCreated = !empty($transferResponse->time_created) ? - new \DateTime($transferResponse->time_created) : ''; + new DateTime($transferResponse->time_created) : ''; $transfer->amount = !empty($transferResponse->amount) ? StringUtils::toAmount($transferResponse->amount) : null; $transfer->reference = $transferResponse->reference ?? null; @@ -230,7 +238,7 @@ private static function mapTransferFundsAccountDetails(&$transaction, $transfers $transaction->transfersFundsAccount = $transfers; } - private static function mapPaymentMethodTransactionDetails(Transaction &$transaction, $paymentMethodResponse) + private static function mapPaymentMethodTransactionDetails(Transaction &$transaction, $paymentMethodResponse): void { $cardIssuerResponse = new CardIssuerResponse(); $cardIssuerResponse->result = $paymentMethodResponse->result ?? null; @@ -241,26 +249,24 @@ private static function mapPaymentMethodTransactionDetails(Transaction &$transac $paymentMethodResponse->fingerprint : null; $transaction->fingerprintIndicator = !empty($paymentMethodResponse->fingerprint_presence_indicator) ? $paymentMethodResponse->fingerprint_presence_indicator : null; - if (!empty($paymentMethodResponse->card)) { - $card = $paymentMethodResponse->card; - $transaction->cardDetails = self::mapCardDetails($card); - - $transaction->cardLast4 = !empty($card->masked_number_last4) ? - $card->masked_number_last4 : null; - $transaction->cardType = !empty($card->brand) ? $card->brand : null; - $transaction->cvnResponseCode = !empty($card->cvv) ? $card->cvv : null; - $transaction->cvnResponseMessage = !empty($card->cvv_result) ? $card->cvv_result : null; - $transaction->cardBrandTransactionId = !empty($card->brand_reference) ? - $card->brand_reference : null; - $transaction->avsResponseCode = !empty($card->avs_postal_code_result) ? - $card->avs_postal_code_result : null; - $transaction->avsAddressResponse = !empty($card->avs_address_result) ? $card->avs_address_result : null; - $transaction->avsResponseMessage = !empty($card->avs_action) ? $card->avs_action : null; - $transaction->authorizationCode = $card->authcode ?? null; - if (!empty($card->provider)) { - self::mapCardIssuerResponse($cardIssuerResponse, $card->provider); + $paymentMethodObj = $paymentMethodResponse->card ?? ($paymentMethodResponse->digital_wallet ?? null); + if (!empty($paymentMethodObj)) { + $transaction->cardDetails = self::mapCardDetails($paymentMethodObj); + + $transaction->cardLast4 = $paymentMethodObj->masked_number_last4 ?? null; + $transaction->cardType = $paymentMethodObj->brand ?? null; + $transaction->cvnResponseCode = $paymentMethodObj->cvv ?? null; + $transaction->cvnResponseMessage = $paymentMethodObj->cvv_result ?? null; + $transaction->cardBrandTransactionId = $paymentMethodObj->brand_reference ?? null; + $transaction->avsResponseCode = $paymentMethodObj->avs_postal_code_result ?? null; + $transaction->avsAddressResponse = $paymentMethodObj->avs_address_result ?? null; + $transaction->avsResponseMessage = $paymentMethodObj->avs_action ?? null; + $transaction->authorizationCode = $paymentMethodObj->authcode ?? null; + if (!empty($paymentMethodObj->provider)) { + self::mapCardIssuerResponse($cardIssuerResponse, $paymentMethodObj->provider); } } + $transaction->cardIssuerResponse = $cardIssuerResponse; if (!empty($paymentMethodResponse->apm) && $paymentMethodResponse->apm->provider == strtolower(PaymentProvider::OPEN_BANKING) @@ -300,8 +306,8 @@ private static function mapPayerDetails($payer, $shippingAddress = null): PayerD $payerDetails->email = $payer->email ?? null; if (!empty($payer->billing_address)) { $billingAddress = $payer->billing_address; - $payerDetails->firstName = $billingAddress->first_name ?? null; - $payerDetails->lastName = $billingAddress->last_name ?? null; + $payerDetails->firstName = $billingAddress->first_name ?? null; + $payerDetails->lastName = $billingAddress->last_name ?? null; $payerDetails->billingAddress = self::mapAddressObject( $billingAddress, AddressType::BILLING @@ -333,7 +339,7 @@ private static function mapFraudManagement($fraudResponse): FraudManagementRespo return $fraudFilterResponse; } - private static function mapFraudResponseResult($fraudResponseResult) + private static function mapFraudResponseResult($fraudResponseResult): string { switch ($fraudResponseResult) { case 'PENDING_REVIEW': @@ -353,7 +359,7 @@ private static function mapFraudResponseResult($fraudResponseResult) } } - private static function mapDccInfo($response) + private static function mapDccInfo($response): DccRateData { $dccRateData = new DccRateData(); $dccRateData->cardHolderCurrency = !empty($response->payer_currency) ? $response->payer_currency : null; @@ -369,7 +375,7 @@ private static function mapDccInfo($response) $dccRateData->commissionPercentage = !empty($response->commission_percentage) ? $response->commission_percentage : null; $dccRateData->exchangeRateSourceTimestamp = !empty($response->exchange_rate_time_created) ? - $response->exchange_rate_time_created: null; + $response->exchange_rate_time_created : null; $dccRateData->dccId = !empty($response->id) ? $response->id : null; return $dccRateData; @@ -378,8 +384,11 @@ private static function mapDccInfo($response) /** * @param $response * @param $reportType + * @return PayByLinkSummary|TransactionSummary|PagedResult|MerchantAccountSummary|DisputeSummary|ActionSummary|StoredPaymentMethodSummary|DepositSummary|DisputeDocument + * @throws ApiException + * @throws Exception */ - public static function mapReportResponse($response, $reportType) + public static function mapReportResponse($response, $reportType): PayByLinkSummary|TransactionSummary|PagedResult|MerchantAccountSummary|DisputeSummary|ActionSummary|StoredPaymentMethodSummary|DepositSummary|DisputeDocument { switch ($reportType) { case ReportType::TRANSACTION_DETAIL: @@ -398,7 +407,7 @@ public static function mapReportResponse($response, $reportType) case ReportType::FIND_DEPOSITS_PAGED: $report = self::setPagingInfo($response); foreach ($response->deposits as $deposit) { - array_push($report->result, self::mapDepositSummary($deposit)); + $report->result[] = self::mapDepositSummary($deposit); } break; case ReportType::DOCUMENT_DISPUTE_DETAIL: @@ -414,13 +423,13 @@ public static function mapReportResponse($response, $reportType) case ReportType::FIND_SETTLEMENT_DISPUTES_PAGED: $report = self::setPagingInfo($response); foreach ($response->disputes as $dispute) { - array_push($report->result, self::mapDisputeSummary($dispute)); + $report->result[] = self::mapDisputeSummary($dispute); } break; case ReportType::FIND_STORED_PAYMENT_METHODS_PAGED: $report = self::setPagingInfo($response); foreach ($response->payment_methods as $spm) { - array_push($report->result, self::mapStoredPaymentMethodSummary($spm)); + $report->result[] = self::mapStoredPaymentMethodSummary($spm); } break; case ReportType::STORED_PAYMENT_METHOD_DETAIL: @@ -432,7 +441,7 @@ public static function mapReportResponse($response, $reportType) case ReportType::FIND_ACTIONS_PAGED: $report = self::setPagingInfo($response); foreach ($response->actions as $action) { - array_push($report->result, self::mapActionsSummary($action)); + $report->result[] = self::mapActionsSummary($action); } break; case ReportType::PAYBYLINK_DETAIL: @@ -441,19 +450,19 @@ public static function mapReportResponse($response, $reportType) case ReportType::FIND_PAYBYLINK_PAGED: $report = self::setPagingInfo($response); foreach ($response->links as $link) { - array_push($report->result, self::mapPayByLinkSummary($link)); + $report->result[] = self::mapPayByLinkSummary($link); } break; case ReportType::FIND_MERCHANTS_PAGED: $report = self::setPagingInfo($response); foreach ($response->merchants as $merchant) { - array_push($report->result, self::mapMerchantSummary($merchant)); + $report->result[] = self::mapMerchantSummary($merchant); } return $report; case ReportType::FIND_ACCOUNTS_PAGED: $report = self::setPagingInfo($response); foreach ($response->accounts as $account) { - array_push($report->result, self::mapMerchantAccountSummary($account)); + $report->result[] = self::mapMerchantAccountSummary($account); } return $report; case ReportType::FIND_ACCOUNT_DETAIL: @@ -470,22 +479,23 @@ public static function mapReportResponse($response, $reportType) * * @param $response * @return TransactionSummary + * @throws Exception */ - public static function mapTransactionSummary($response) + public static function mapTransactionSummary($response): TransactionSummary { $summary = self::createTransactionSummary($response); $summary->transactionLocalDate = !empty($response->time_created_reference) ? - new \DateTime($response->time_created_reference) : ''; + new DateTime($response->time_created_reference) : ''; $summary->batchSequenceNumber = $response->batch_id; $summary->country = !empty($response->country) ? $response->country : null; $summary->originalTransactionId = !empty($response->parent_resource_id) ? $response->parent_resource_id : null; $summary->depositReference = !empty($response->deposit_id) ? $response->deposit_id : ''; $summary->depositStatus = !empty($response->deposit_status) ? $response->deposit_status : ''; $summary->depositTimeCreated = !empty($response->deposit_time_created) ? - new \DateTime($response->deposit_time_created) : ''; + new DateTime($response->deposit_time_created) : ''; $summary->settlementAmount = !empty($response->deposit_amount) ? StringUtils::toAmount($response->deposit_amount) : null; - $summary->batchCloseDate = !empty($response->batch_time_created) ? new \DateTime($response->batch_time_created) : ''; + $summary->batchCloseDate = !empty($response->batch_time_created) ? new DateTime($response->batch_time_created) : ''; $summary->orderId = $response->order->reference ?? null; if (isset($response->system)) { @@ -501,7 +511,7 @@ public static function mapTransactionSummary($response) /** map card details */ if (isset($paymentMethod->card)) { $card = $paymentMethod->card; - $summary->aquirerReferenceNumber = isset($card->arn) ? $card->arn : null; + $summary->aquirerReferenceNumber = $card->arn ?? null; $summary->maskedCardNumber = $card->masked_number_first6last4 ?? null; $summary->paymentType = PaymentMethodName::CARD; $summary->cardDetails = self::mapCardDetails($card); @@ -547,7 +557,8 @@ public static function mapTransactionSummary($response) $bankPaymentResponse->redirectUrl = $response->payment_method->redirect_url ?? null; $summary->bankPaymentResponse = $bankPaymentResponse; $summary->accountNumberLast4 = $response->payment_method->bank_transfer->masked_account_number_last4 ?? null; - } else { /** map APMs (Paypal) response info */ + } else { + /** map APMs (Paypal) response info */ $apm = $response->payment_method->apm; $alternativePaymentResponse = new AlternativePaymentResponse(); $alternativePaymentResponse->redirectUrl = !empty($response->payment_method->redirect_url) ? @@ -588,12 +599,13 @@ public static function mapTransactionSummary($response) * @param Object $response * * @return DepositSummary + * @throws Exception */ - public static function mapDepositSummary($response) + public static function mapDepositSummary(object $response): DepositSummary { $summary = new DepositSummary(); $summary->depositId = $response->id; - $summary->depositDate = new \DateTime($response->time_created); + $summary->depositDate = new DateTime($response->time_created); $summary->status = $response->status; $summary->type = $response->funding_type; $summary->amount = StringUtils::toAmount($response->amount); @@ -603,13 +615,13 @@ public static function mapDepositSummary($response) } if (isset($response->sales)) { $sales = $response->sales; - $summary->salesTotalCount = isset($sales->count) ? $sales->count : 0; + $summary->salesTotalCount = $sales->count ?? 0; $summary->salesTotalAmount = isset($sales->amount) ? StringUtils::toAmount($sales->amount) : 0; } if (isset($response->refunds)) { $refunds = $response->refunds; - $summary->refundsTotalCount = isset($refunds->count) ? $refunds->count : 0; + $summary->refundsTotalCount = $refunds->count ?? 0; $summary->refundsTotalAmount = isset($refunds->amount) ? StringUtils::toAmount($refunds->amount) : 0; } @@ -620,11 +632,11 @@ public static function mapDepositSummary($response) if (isset($response->disputes)) { $disputes = $response->disputes; - $summary->chargebackTotalCount = isset($disputes->chargebacks->count) ? $disputes->chargebacks->count : 0; + $summary->chargebackTotalCount = $disputes->chargebacks->count ?? 0; $summary->chargebackTotalAmount = isset($disputes->chargebacks->amount) ? StringUtils::toAmount($disputes->chargebacks->amount) : 0; - $summary->adjustmentTotalCount = isset($disputes->reversals->count) ? $disputes->reversals->count : 0; + $summary->adjustmentTotalCount = $disputes->reversals->count ?? 0; $summary->adjustmentTotalAmount = isset($disputes->reversals->amount) ? StringUtils::toAmount($disputes->reversals->amount) : 0; } @@ -640,16 +652,17 @@ public static function mapDepositSummary($response) * @param Object $response * * @return DisputeSummary + * @throws Exception */ - public static function mapDisputeSummary($response) + public static function mapDisputeSummary(object $response): DisputeSummary { $summary = new DisputeSummary(); $summary->caseId = $response->id; - $summary->caseIdTime = !empty($response->time_created) ? new \DateTime($response->time_created) : null; + $summary->caseIdTime = !empty($response->time_created) ? new DateTime($response->time_created) : null; $summary->caseStatus = $response->status; $summary->caseStage = $response->stage; $summary->disputeStageTime = - (!empty($response->stage_time_created) ? new \DateTime($response->stage_time_created) : null); + (!empty($response->stage_time_created) ? new DateTime($response->stage_time_created) : null); $summary->caseAmount = StringUtils::toAmount($response->amount); $summary->caseCurrency = $response->currency; @@ -695,7 +708,7 @@ public static function mapDisputeSummary($response) $summary->reasonCode = $response->reason_code; $summary->reason = $response->reason_description; $summary->respondByDate = !empty($response->time_to_respond_by) ? - new \DateTime($response->time_to_respond_by) : null; + new DateTime($response->time_to_respond_by) : null; $summary->result = $response->result; $summary->fundingType = $response->funding_type ?? null; $summary->lastAdjustmentAmount = !empty($response->last_adjustment_amount) ? @@ -730,12 +743,13 @@ public static function mapDisputeSummary($response) * @param $response * * @return StoredPaymentMethodSummary + * @throws Exception */ - public static function mapStoredPaymentMethodSummary($response) + public static function mapStoredPaymentMethodSummary($response): StoredPaymentMethodSummary { $summary = new StoredPaymentMethodSummary(); $summary->paymentMethodId = $response->id; - $summary->timeCreated = !empty($response->time_created) ? new \DateTime($response->time_created) : ''; + $summary->timeCreated = !empty($response->time_created) ? new DateTime($response->time_created) : ''; $summary->status = !empty($response->status) ? $response->status : ''; $summary->reference = !empty($response->reference) ? $response->reference : ''; $summary->cardHolderName = !empty($response->name) ? $response->name : ''; @@ -750,12 +764,15 @@ public static function mapStoredPaymentMethodSummary($response) return $summary; } - public static function mapActionsSummary($response) + /** + * @throws Exception + */ + public static function mapActionsSummary($response): ActionSummary { $summary = new ActionSummary(); $summary->id = $response->id; - $summary->timeCreated = !empty($response->time_created) ? new \DateTime($response->time_created) : null; + $summary->timeCreated = !empty($response->time_created) ? new DateTime($response->time_created) : null; $summary->type = !empty($response->type) ? $response->type : null; $summary->resource = !empty($response->resource) ? $response->resource : null; $summary->resourceId = !empty($response->resource_id) ? $response->resource_id : null; @@ -770,10 +787,11 @@ public static function mapActionsSummary($response) $summary->accountId = !empty($response->account_id) ? $response->account_id : null; $summary->rawRequest = $response->message_received ?? null; $summary->rawResponse = $response->message_sent ?? null; + return $summary; } - public static function mapRiskAssessmentResponse($response) + public static function mapRiskAssessmentResponse($response): RiskAssessment { $riskAssessment = new RiskAssessment(); $riskAssessment->id = $response->id; @@ -803,7 +821,7 @@ public static function mapRiskAssessmentResponse($response) return $riskAssessment; } - public static function mapCardDetails($paymentMethod) : Card + public static function mapCardDetails($paymentMethod): Card { $card = new Card(); $card->maskedNumberLast4 = $paymentMethod->masked_number_last4 ?? null; @@ -827,8 +845,9 @@ public static function mapCardDetails($paymentMethod) : Card /** * @param Object $response + * @return Transaction */ - public static function mapResponseSecure3D($response) + public static function mapResponseSecure3D(object $response): Transaction { $transaction = new Transaction(); $threeDSecure = new ThreeDSecure(); @@ -836,16 +855,11 @@ public static function mapResponseSecure3D($response) if (!empty($response->three_ds->message_version)) { $messageVersion = $response->three_ds->message_version; - switch (substr($messageVersion, 0, 2)) { - case '1.': - $version = Secure3dVersion::ONE; - break; - case '2.': - $version = Secure3dVersion::TWO; - break; - default: - $version = Secure3dVersion::ANY; - } + $version = match (substr($messageVersion, 0, 2)) { + '1.' => Secure3dVersion::ONE, + '2.' => Secure3dVersion::TWO, + default => Secure3dVersion::ANY, + }; $threeDSecure->messageVersion = $messageVersion; $threeDSecure->setVersion($version); } @@ -865,8 +879,8 @@ public static function mapResponseSecure3D($response) $response->three_ds->acs_info_indicator : null; $threeDSecure->acsReferenceNumber = $response->three_ds->acs_reference_number ?? null; $threeDSecure->providerServerTransRef = $response->three_ds->server_trans_ref ?? null; - $threeDSecure->challengeMandated = !empty($response->three_ds->challenge_status) ? - ($response->three_ds->challenge_status == 'MANDATED') : false; + $threeDSecure->challengeMandated = !empty($response->three_ds->challenge_status) && + $response->three_ds->challenge_status == 'MANDATED'; $threeDSecure->payerAuthenticationRequest = !empty($response->three_ds->method_data->encoded_method_data) ? $response->three_ds->method_data->encoded_method_data : null; $threeDSecure->issuerAcsUrl = !empty($response->three_ds->method_url) ? $response->three_ds->method_url : null; @@ -923,7 +937,7 @@ public static function mapResponseSecure3D($response) foreach ($response->three_ds->message_extension as $messageExtension) { $msgItem = new MessageExtension(); $msgItem->criticalityIndicator = !empty($messageExtension->criticality_indicator) ? - $messageExtension->criticality_indicator : null; + $messageExtension->criticality_indicator : null; $msgItem->messageExtensionData = !empty($messageExtension->data) ? json_encode($messageExtension->data) : null; $msgItem->messageExtensionId = !empty($messageExtension->id) ? $messageExtension->id : null; @@ -937,15 +951,15 @@ public static function mapResponseSecure3D($response) return $transaction; } - private static function setPagingInfo($response) + private static function setPagingInfo($response): PagedResult { $pageInfo = new PagedResult(); $pageInfo->totalRecordCount = !empty($response->total_count) ? $response->total_count : (!empty($response->total_record_count) ? $response->total_record_count : null); - $pageInfo->pageSize = !empty($response->paging->page_size) ? $response->paging->page_size : null; - $pageInfo->page = !empty($response->paging->page) ? $response->paging->page : null; - $pageInfo->order = !empty($response->paging->order) ? $response->paging->order : null; - $pageInfo->orderBy = !empty($response->paging->order_by) ? $response->paging->order_by : null; + $pageInfo->pageSize = !empty($response->paging->page_size) ? $response->paging->page_size : null; + $pageInfo->page = !empty($response->paging->page) ? $response->paging->page : null; + $pageInfo->order = !empty($response->paging->order) ? $response->paging->order : null; + $pageInfo->orderBy = !empty($response->paging->order_by) ? $response->paging->order_by : null; return $pageInfo; } @@ -956,8 +970,9 @@ private static function setPagingInfo($response) * @param Object $response * * @return Transaction + * @throws Exception */ - public static function mapResponseAPM($response) + public static function mapResponseAPM(object $response): Transaction { $apm = new AlternativePaymentResponse(); $transaction = self::mapResponse($response); @@ -965,6 +980,8 @@ public static function mapResponseAPM($response) $apm->redirectUrl = !empty($response->payment_method->redirect_url) ? $response->payment_method->redirect_url : ($paymentMethodApm->redirect_url ?? null); $apm->qrCodeImage = $response->payment_method->qr_code ?? null; + $apm->timeCreatedReference = !empty($paymentMethodApm->time_created_reference) ? + new DateTime($paymentMethodApm->time_created_reference) : null; if (is_string($paymentMethodApm->provider)) { $apm->providerName = $paymentMethodApm->provider; } elseif (is_object($paymentMethodApm->provider)) { @@ -979,10 +996,9 @@ public static function mapResponseAPM($response) $apm->correlationReference = $paymentMethodApm->correlation_reference ?? null; $apm->versionReference = $paymentMethodApm->version_reference ?? null; $apm->buildReference = $paymentMethodApm->build_reference ?? null; - $apm->timeCreatedReference = !empty($paymentMethodApm->time_created_reference) ? - new \DateTime($paymentMethodApm->time_created_reference) : null; + $apm->transactionReference = !empty($paymentMethodApm->transaction_reference) ? - $paymentMethodApm->transaction_reference: null; + $paymentMethodApm->transaction_reference : null; $apm->secureAccountReference = !empty($paymentMethodApm->secure_account_reference) ? $paymentMethodApm->secure_account_reference : null; $apm->reasonCode = !empty($paymentMethodApm->reason_code) ? $paymentMethodApm->reason_code : null; @@ -990,7 +1006,7 @@ public static function mapResponseAPM($response) $apm->grossAmount = !empty($paymentMethodApm->gross_amount) ? StringUtils::toAmount($paymentMethodApm->gross_amount) : null; $apm->paymentTimeReference = !empty($paymentMethodApm->payment_time_reference) ? - new \DateTime($paymentMethodApm->payment_time_reference) : null; + new DateTime($paymentMethodApm->payment_time_reference) : null; $apm->paymentType = !empty($paymentMethodApm->payment_type) ? $paymentMethodApm->payment_type : null; $apm->paymentStatus = !empty($paymentMethodApm->payment_status) ? $paymentMethodApm->payment_status : null; $apm->type = !empty($paymentMethodApm->type) ? $paymentMethodApm->type : null; @@ -1026,8 +1042,9 @@ public static function mapResponseAPM($response) /** * @param $response * @return PayByLinkSummary + * @throws Exception */ - public static function mapPayByLinkSummary($response) + public static function mapPayByLinkSummary($response): PayByLinkSummary { $summary = new PayByLinkSummary(); $summary->merchantId = $response->merchant_id ?? null; @@ -1045,7 +1062,7 @@ public static function mapPayByLinkSummary($response) $summary->description = $response->description ?? null; $summary->viewedCount = $response->viewed_count ?? null; $summary->expirationDate = !empty($response->expiration_date) ? - new \DateTime($response->expiration_date) : null; + new DateTime($response->expiration_date) : null; $summary->shippable = $response->shippable ?? null; $summary->usageCount = $response->usage_count ?? null; @@ -1058,7 +1075,7 @@ public static function mapPayByLinkSummary($response) $summary->allowedPaymentMethods = $response->transactions->allowed_payment_methods ?? null; //@TODO check if (!empty($response->transactions->transaction_list)) { foreach ($response->transactions->transaction_list as $transaction) { - $summary->transactions[] = self::createTransactionSummary($transaction); + $summary->transactions[] = self::createTransactionSummary($transaction); } } } @@ -1066,7 +1083,10 @@ public static function mapPayByLinkSummary($response) return $summary; } - public static function mapPayByLinkResponse($response) + /** + * @throws Exception + */ + public static function mapPayByLinkResponse($response): PayByLinkResponse { $payByLinkResponse = new PayByLinkResponse(); $payByLinkResponse->id = $response->id; @@ -1080,7 +1100,7 @@ public static function mapPayByLinkResponse($response) $payByLinkResponse->name = $response->name ?? null; $payByLinkResponse->description = $response->description ?? null; $payByLinkResponse->viewedCount = $response->viewed_count ?? null; - $payByLinkResponse->expirationDate = !empty($response->expiration_date) ? new \DateTime($response->expiration_date) : null; + $payByLinkResponse->expirationDate = !empty($response->expiration_date) ? new DateTime($response->expiration_date) : null; $payByLinkResponse->isShippable = $response->shippable ?? null; return $payByLinkResponse; @@ -1092,13 +1112,14 @@ public static function mapPayByLinkResponse($response) * @param $response * * @return TransactionSummary + * @throws Exception */ private static function createTransactionSummary($response): TransactionSummary { $transaction = new TransactionSummary(); $transaction->transactionId = $response->id ?? null; $timeCreated = self::validateStringDate($response->time_created); - $transaction->transactionDate = !empty($timeCreated) ? new \DateTime($timeCreated) : ''; + $transaction->transactionDate = !empty($timeCreated) ? new DateTime($timeCreated) : ''; $transaction->transactionStatus = $response->status; $transaction->transactionType = $response->type; $transaction->channel = !empty($response->channel) ? $response->channel : null; @@ -1118,7 +1139,7 @@ private static function createTransactionSummary($response): TransactionSummary * * @return Transaction */ - private static function mapBNPLResponse($response,Transaction $transaction) + private static function mapBNPLResponse($response, Transaction $transaction): Transaction { $transaction->paymentMethodType = PaymentMethodType::BNPL; $bnplResponse = new BNPLResponse(); @@ -1131,9 +1152,9 @@ private static function mapBNPLResponse($response,Transaction $transaction) return $transaction; } - private static function mapMerchantAccountSummary($account) + private static function mapMerchantAccountSummary($account): MerchantAccountSummary { - $merchantAccountSummary = new MerchantAccountSummary(); + $merchantAccountSummary = new MerchantAccountSummary(); $merchantAccountSummary->id = $account->id ?? null; $merchantAccountSummary->type = $account->type ?? null; $merchantAccountSummary->name = $account->name ?? null; @@ -1175,14 +1196,14 @@ private static function mapMerchantSummary($merchant): MerchantSummary /** * @param $response - * @param UserReference $userReference * @return User * @throws UnsupportedTransactionException + * @throws Exception */ - public static function mapMerchantsEndpointResponse($response,?UserReference $userReference): User + public static function mapMerchantsEndpointResponse($response): User { if (empty($response->action->type)) { - throw new UnsupportedTransactionException(sprintf("Empty action type response!")); + throw new UnsupportedTransactionException("Empty action type response!"); } switch ($response->action->type) { @@ -1210,9 +1231,9 @@ public static function mapMerchantsEndpointResponse($response,?UserReference $us $user->name = $response->name ?? null; $user->userStatus = $response->status; $user->userType = $response->type; - $user->timeCreate = !empty($response->time_created) ? new \DateTime($response->time_created) : null; + $user->timeCreate = !empty($response->time_created) ? new DateTime($response->time_created) : null; $user->timeLastUpdated = !empty($response->time_last_updated) ? - new \DateTime($response->time_last_updated) : null; + new DateTime($response->time_last_updated) : null; $user->responseCode = $response->action->result_code ?? null; $user->statusDescription = $response->status_description ?? null; $user->email = $response->email ?? null; @@ -1235,7 +1256,7 @@ public static function mapMerchantsEndpointResponse($response,?UserReference $us self::mapMerchantPersonList($response->persons, $user); } if (!empty($response->payment_methods)) { - self::mapMerchantPaymentMethods($response->payment_methods,$user); + self::mapMerchantPaymentMethods($response->payment_methods, $user); } return $user; case self::FUNDS: @@ -1261,7 +1282,10 @@ public static function mapMerchantsEndpointResponse($response,?UserReference $us } } - public static function mapFileProcessingResponse($response) + /** + * @throws UnsupportedTransactionException + */ + public static function mapFileProcessingResponse($response): FileProcessor { $fp = new FileProcessor(); switch ($response->action->type) { @@ -1304,8 +1328,9 @@ private static function mapGeneralFileProcessingResponse($response, &$fp) /** * @param $paymentMethods * @param User $user + * @throws ArgumentException */ - private static function mapMerchantPaymentMethods($paymentMethods, &$user) + private static function mapMerchantPaymentMethods($paymentMethods, User &$user): void { $pmList = new PaymentMethodList(); foreach ($paymentMethods as $paymentMethod) { @@ -1334,13 +1359,12 @@ private static function mapMerchantPaymentMethods($paymentMethods, &$user) $user->paymentMethodList = $pmList; } - private static function mapAddressObject($address, $type = null) + private static function mapAddressObject($address, $type = null): ?Address { if (empty($address)) { return null; } $userAddress = new Address(); - $userAddress->type = $type; $userAddress->streetAddress1 = $address->line_1 ?? null; $userAddress->streetAddress2 = $address->line_2 ?? null; $userAddress->streetAddress3 = $address->line_3 ?? null; @@ -1353,7 +1377,7 @@ private static function mapAddressObject($address, $type = null) return $userAddress; } - private static function mapMerchantPersonList($persons, &$user) + private static function mapMerchantPersonList($persons, &$user): void { $personList = new PersonList(); foreach ($persons as $person) { @@ -1386,9 +1410,9 @@ private static function mapMerchantPersonList($persons, &$user) private static function validateStringDate($date): string { try { - new \DateTime($date); - } catch (\Exception $e) { - $errors = \DateTime::getLastErrors(); + new DateTime($date); + } catch (Exception) { + $errors = DateTime::getLastErrors(); if (isset($errors['error_count']) && $errors['error_count'] > 0) { return ''; } @@ -1403,7 +1427,7 @@ private static function validateStringDate($date): string * @param CardIssuerResponse $cardIssuer * @param $cardIssuerResponse */ - private static function mapCardIssuerResponse(CardIssuerResponse &$cardIssuer, $cardIssuerResponse) + private static function mapCardIssuerResponse(CardIssuerResponse &$cardIssuer, $cardIssuerResponse): void { $cardIssuer->result = $cardIssuerResponse->result ?? null; $cardIssuer->avsResult = $cardIssuerResponse->avs_result ?? null; @@ -1416,7 +1440,7 @@ private static function mapCardIssuerResponse(CardIssuerResponse &$cardIssuer, $ * @param TransactionSummary|DepositSummary $summary * @param $system */ - private static function mapSystemResponse(TransactionSummary|DepositSummary &$summary, $system) + private static function mapSystemResponse(TransactionSummary|DepositSummary &$summary, $system): void { if (!isset($system)) { return; @@ -1428,7 +1452,7 @@ private static function mapSystemResponse(TransactionSummary|DepositSummary &$su $summary->merchantDbaName = $system->dba ?? null; } - public static function mapRecurringEntity($response,RecurringEntity $recurringEntity) : RecurringEntity + public static function mapRecurringEntity($response, RecurringEntity $recurringEntity): ?RecurringEntity { switch (get_class($recurringEntity)) { case Customer::class: @@ -1449,8 +1473,7 @@ public static function mapRecurringEntity($response,RecurringEntity $recurringEn } return $payer; default: - break; + return null; } } - } \ No newline at end of file diff --git a/src/Terminals/Abstractions/IDeviceInterface.php b/src/Terminals/Abstractions/IDeviceInterface.php index 420c52d4..91bc6d5a 100644 --- a/src/Terminals/Abstractions/IDeviceInterface.php +++ b/src/Terminals/Abstractions/IDeviceInterface.php @@ -15,6 +15,7 @@ use GlobalPayments\Api\Terminals\Entities\PromptMessages; use GlobalPayments\Api\Terminals\Entities\ScanData; use GlobalPayments\Api\Terminals\Entities\UDData; +use GlobalPayments\Api\Terminals\Enums\BatchReportType; use GlobalPayments\Api\Terminals\Enums\DeviceConfigType; use GlobalPayments\Api\Terminals\Enums\DisplayOption; use GlobalPayments\Api\Terminals\Enums\PromptType; @@ -255,7 +256,7 @@ public function getLastResponse(); public function getSAFReport() : TerminalReportBuilder; public function getBatchReport() : TerminalReportBuilder; - public function getBatchDetails(?string $batchId = null, bool $printReport = false) : ITerminalReport; + public function getBatchDetails(?string $batchId = null, bool $printReport = false, string|BatchReportType $reportType = null) : ITerminalReport; public function findBatches() : TerminalReportBuilder; public function getOpenTabDetails() : TerminalReportBuilder; } diff --git a/src/Terminals/Builders/TerminalSearchBuilder.php b/src/Terminals/Builders/TerminalSearchBuilder.php index 31916ec9..c8c7f274 100644 --- a/src/Terminals/Builders/TerminalSearchBuilder.php +++ b/src/Terminals/Builders/TerminalSearchBuilder.php @@ -25,6 +25,7 @@ class TerminalSearchBuilder public string $ecrId; public string $reportOutput; + public ?string $reportType; public string $batch; public function __construct($reportBuilder) diff --git a/src/Terminals/DeviceInterface.php b/src/Terminals/DeviceInterface.php index ed06c78a..2426a845 100644 --- a/src/Terminals/DeviceInterface.php +++ b/src/Terminals/DeviceInterface.php @@ -22,6 +22,7 @@ use GlobalPayments\Api\Terminals\Entities\PromptMessages; use GlobalPayments\Api\Terminals\Entities\ScanData; use GlobalPayments\Api\Terminals\Entities\UDData; +use GlobalPayments\Api\Terminals\Enums\BatchReportType; use GlobalPayments\Api\Terminals\Enums\CurrencyType; use GlobalPayments\Api\Terminals\Abstractions\IDeviceInterface; use GlobalPayments\Api\Terminals\Enums\DeviceConfigType; @@ -436,7 +437,7 @@ public function getBatchReport(): TerminalReportBuilder ); } - public function getBatchDetails(?string $batchId = null,bool $printReport = false): ITerminalReport + public function getBatchDetails(?string $batchId = null,bool $printReport = false, string|BatchReportType $reportType = null): ITerminalReport { throw new UnsupportedTransactionException( "This method is not supported by the currently configured device." diff --git a/src/Terminals/DeviceResponse.php b/src/Terminals/DeviceResponse.php index 2fdffd00..1b4a1921 100644 --- a/src/Terminals/DeviceResponse.php +++ b/src/Terminals/DeviceResponse.php @@ -18,6 +18,5 @@ abstract class DeviceResponse implements IDeviceResponse, IBatchCloseResponse, I public $deviceResponseCode; /** @var string */ public $deviceResponseText; - /** @var string */ - public $referenceNumber; + public ?string $referenceNumber; } \ No newline at end of file diff --git a/src/Terminals/Diamond/Entities/Enums/TransactionType.php b/src/Terminals/Diamond/Entities/Enums/TransactionTypeResponse.php similarity index 88% rename from src/Terminals/Diamond/Entities/Enums/TransactionType.php rename to src/Terminals/Diamond/Entities/Enums/TransactionTypeResponse.php index 36083a00..e158a773 100644 --- a/src/Terminals/Diamond/Entities/Enums/TransactionType.php +++ b/src/Terminals/Diamond/Entities/Enums/TransactionTypeResponse.php @@ -4,7 +4,7 @@ use GlobalPayments\Api\Entities\Enum; -class TransactionType extends Enum +class TransactionTypeResponse extends Enum { const UNKNOWN = '0'; const SALE = '1'; diff --git a/src/Terminals/Diamond/Responses/DiamondCloudResponse.php b/src/Terminals/Diamond/Responses/DiamondCloudResponse.php index 94587a05..b382f9e6 100644 --- a/src/Terminals/Diamond/Responses/DiamondCloudResponse.php +++ b/src/Terminals/Diamond/Responses/DiamondCloudResponse.php @@ -7,7 +7,7 @@ use GlobalPayments\Api\Terminals\Diamond\Entities\Enums\AuthorizationType; use GlobalPayments\Api\Terminals\Diamond\Entities\Enums\CardSource; use GlobalPayments\Api\Terminals\Diamond\Entities\Enums\TransactionResult; -use GlobalPayments\Api\Terminals\Diamond\Entities\Enums\TransactionType; +use GlobalPayments\Api\Terminals\Diamond\Entities\Enums\TransactionTypeResponse; use GlobalPayments\Api\Terminals\TerminalResponse; use GlobalPayments\Api\Utils\StringUtils; @@ -196,7 +196,7 @@ public function __construct($rawResponse) $this->transactionCurrency = $paymentDetails->transactionCurrency ?? null; $this->transactionTitle = $paymentDetails->transactionTitle ?? null; $this->transactionType = isset($paymentDetails->type) ? - TransactionType::getKey($paymentDetails->type) : null; + TransactionTypeResponse::getKey($paymentDetails->type) : null; $this->emvCardTransactionCounter = $paymentDetails->ATC ?? null; $this->emvCryptogram = $paymentDetails->AC ?? null; $this->emvApplicationId = $paymentDetails->AID ?? null; diff --git a/src/Terminals/Entities/UDData.php b/src/Terminals/Entities/UDData.php index 0cb0a465..da14c01e 100644 --- a/src/Terminals/Entities/UDData.php +++ b/src/Terminals/Entities/UDData.php @@ -15,8 +15,8 @@ class UDData /** @var UDFileTypes Contains the parameters for the file to be loaded */ public string $fileType; - /** @var string Slot number of the data file */ - public string $slotNum; + /** @var int Slot number of the data file */ + public int $slotNum; /** @var string Filename of the file to be stored in the device. Must include the file extension. * Must not contain a file path. diff --git a/src/Terminals/Enums/BatchReportType.php b/src/Terminals/Enums/BatchReportType.php new file mode 100644 index 00000000..c5855168 --- /dev/null +++ b/src/Terminals/Enums/BatchReportType.php @@ -0,0 +1,11 @@ +parseResponse($jsonResponse); } - protected function parseResponse($jsonResponse) + /** + * @throws GatewayException + * @throws MessageException + */ + protected function parseResponse($jsonResponse): void { - if (empty($jsonResponse->data) || empty($jsonResponse->data->cmdResult)) { + parent::parseResponse(ArrayUtils::jsonToArray($jsonResponse)); + $firstDataNode = $this->isGpApiResponse($jsonResponse) ? $jsonResponse->response : ($jsonResponse->data ?? null); + if (empty($firstDataNode) || empty($firstDataNode->cmdResult)) { throw new GatewayException(self::INVALID_RESPONSE_FORMAT); } - $firstDataNode = $jsonResponse->data; + $secondNode = $firstDataNode->data; $cmdResult = $firstDataNode->cmdResult; $this->status = $cmdResult->result ?? null; $this->command = $firstDataNode->response; - $this->ecrId = $firstDataNode->ecrId ?? null; - if (empty($this->status) || $this->status !== 'Success') { - $this->deviceResponseText = sprintf("Error: %s - %s", $cmdResult->errorCode, $cmdResult->errorMessage); - return; - } - $batches = $firstDataNode->data->batchesAvail ?? null; + $this->ecrId = $firstDataNode->EcrId ?? null; + $this->referenceNumber = $jsonResponse->id ?? null; + $this->requestId = $firstDataNode->requestId ?? null; + $this->deviceResponseCode = in_array($this->status, ['Success', 'COMPLETE']) ? '00' : null; + $batches = $secondNode->batchesAvail ?? null; foreach ($batches as $batch) { $this->batchIds[] = $batch->batchId; } diff --git a/src/Terminals/UPA/Responses/BatchReportResponse.php b/src/Terminals/UPA/Responses/BatchReportResponse.php index cd47a613..7efc1e5d 100644 --- a/src/Terminals/UPA/Responses/BatchReportResponse.php +++ b/src/Terminals/UPA/Responses/BatchReportResponse.php @@ -2,6 +2,7 @@ namespace GlobalPayments\Api\Terminals\UPA\Responses; +use GlobalPayments\Api\Entities\Card; use GlobalPayments\Api\Entities\Exceptions\GatewayException; use GlobalPayments\Api\Entities\Reporting\TransactionList; use GlobalPayments\Api\Entities\Reporting\TransactionSummary; @@ -28,7 +29,7 @@ protected function parseJsonResponse($jsonResponse): void { parent::parseJsonResponse($jsonResponse); $firstDataNode = $this->isGpApiResponse($jsonResponse) ? $jsonResponse->response : $jsonResponse->data; - $this->ecrId = $firstDataNode->ecrId ?? null; + $this->ecrId = $firstDataNode->EcrId ?? null; $secondDataNode = $firstDataNode->data ?? null; $this->merchantName = $secondDataNode->merchantName ?? null; $this->multipleMessage = $secondDataNode->multipleMessage ?? null; @@ -69,7 +70,10 @@ private function mapTransactionDetails(BatchRecordResponse &$batchRecordResponse $transactionSummary->authorizedAmount = $transaction->authorizedAmount; $transactionSummary->cardEntryMethod = $transaction->cardAcquisition ?? null; $transactionSummary->cardType = $transaction->cardType; - $transactionSummary->maskedCardNumber = $transaction->maskedPAN ?? null; + $transactionSummary->maskedCardNumber = $transaction->maskedPan ?? null; + $transactionSummary->cardDetails = new Card(); + $transactionSummary->cardDetails->brand = $transaction->cardType ?? null; + $transactionSummary->cardDetails->maskedCardNumber = $transaction->maskedPan ?? null; $transactionSummary->referenceNumber = $transaction->referenceNumber; $transactionSummary->issuerTransactionId = $transaction->gatewayTxnId; $transactionSummary->clerkId = $transaction->clerkId ?? null; @@ -81,6 +85,7 @@ private function mapTransactionDetails(BatchRecordResponse &$batchRecordResponse $transactionSummary->gratuityAmount = $transaction->tipAmount ?? null; $transactionSummary->settlementAmount = $transaction->settleAmount ?? null; $transactionSummary->taxAmount = $transaction->taxAmount ?? null; + $transactionSummary->cardSwiped = $transaction->cardSwiped ?? null; $batchRecordResponse->transactionDetails->add($transactionSummary); } } diff --git a/src/Terminals/UPA/Responses/SignatureResponse.php b/src/Terminals/UPA/Responses/SignatureResponse.php index 3d9479d7..5fe42ec2 100644 --- a/src/Terminals/UPA/Responses/SignatureResponse.php +++ b/src/Terminals/UPA/Responses/SignatureResponse.php @@ -16,13 +16,13 @@ public function __construct($jsonResponse) public function parseResponse($jsonResponse): void { parent::parseResponse($jsonResponse); - - if (empty($jsonResponse['data']['data'])) { + $firstDataNode = $this->isGpApiResponse($jsonResponse) ? $jsonResponse['response'] : $jsonResponse['data']; + if (empty($firstDataNode['data'])) { throw new MessageException(self::INVALID_RESPONSE_FORMAT); } switch ($this->command) { case UpaMessageId::GET_SIGNATURE: - $this->signatureData = $jsonResponse['data']['data']['signatureData'] ?? null; + $this->signatureData = $firstDataNode['data']['signatureData'] ?? null; break; } } diff --git a/src/Terminals/UPA/Responses/TerminalSetupResponse.php b/src/Terminals/UPA/Responses/TerminalSetupResponse.php index dcb6c8d9..59f9843e 100644 --- a/src/Terminals/UPA/Responses/TerminalSetupResponse.php +++ b/src/Terminals/UPA/Responses/TerminalSetupResponse.php @@ -22,10 +22,11 @@ public function __construct($jsonResponse) public function parseResponse($jsonResponse): void { parent::parseResponse($jsonResponse); - if (empty($jsonResponse['data']['data'])) { + $firstDataNode = $this->isGpApiResponse($jsonResponse) ? $jsonResponse['response'] : $jsonResponse['data']; + if (empty($firstDataNode['data'])) { return; } - $secondNode = $jsonResponse['data']['data']; + $secondNode = $firstDataNode['data']; switch ($this->command) { case UpaMessageId::GET_CONFIG_CONTENTS: $this->configType = $secondNode['configType'] ?? ''; diff --git a/src/Terminals/UPA/Responses/TransactionResponse.php b/src/Terminals/UPA/Responses/TransactionResponse.php index 6abe28fc..7518d1ed 100644 --- a/src/Terminals/UPA/Responses/TransactionResponse.php +++ b/src/Terminals/UPA/Responses/TransactionResponse.php @@ -2,7 +2,6 @@ namespace GlobalPayments\Api\Terminals\UPA\Responses; -use GlobalPayments\Api\Entities\Enums\GatewayProvider; use GlobalPayments\Api\Entities\Exceptions\MessageException; use GlobalPayments\Api\Terminals\Abstractions\IBatchCloseResponse; use GlobalPayments\Api\Terminals\Entities\{PANDetails, ThreeDesDukpt,TrackData}; diff --git a/src/Terminals/UPA/Responses/UpaBatchReport.php b/src/Terminals/UPA/Responses/UpaBatchReport.php index 91b44924..cfc2a1e0 100644 --- a/src/Terminals/UPA/Responses/UpaBatchReport.php +++ b/src/Terminals/UPA/Responses/UpaBatchReport.php @@ -4,8 +4,6 @@ class UpaBatchReport extends UpaResponseHandler { - public $deviceResponseCode; - public $merchantName; public $batchSummary; diff --git a/src/Terminals/UPA/Responses/UpaResponseHandler.php b/src/Terminals/UPA/Responses/UpaResponseHandler.php index 00d02949..e96f78a2 100644 --- a/src/Terminals/UPA/Responses/UpaResponseHandler.php +++ b/src/Terminals/UPA/Responses/UpaResponseHandler.php @@ -6,6 +6,7 @@ use GlobalPayments\Api\Entities\Exceptions\GatewayException; use GlobalPayments\Api\Entities\Exceptions\MessageException; use GlobalPayments\Api\Terminals\TerminalResponse; +use GlobalPayments\Api\Utils\ArrayUtils; class UpaResponseHandler extends TerminalResponse { @@ -47,25 +48,20 @@ protected function parseResponse(array $response): void $this->ecrId = $firstNodeData['EcrId'] ?? ''; } - protected function isGpApiResponse($jsonResponse) : bool - { - if (is_object($jsonResponse)) { - $jsonResponse = $this->jsonToArray($jsonResponse); - } - return !empty($jsonResponse['provider']) && $jsonResponse['provider'] === GatewayProvider::GP_API; - } - /** * @throws MessageException */ protected function parseJsonResponse($response): void { - $response = $this->jsonToArray($response); + $response = ArrayUtils::jsonToArray($response); $this->parseResponse($response); } - private function jsonToArray(object $response) : array + protected function isGpApiResponse($jsonResponse) : bool { - return json_decode(json_encode($response), true); + if (is_object($jsonResponse)) { + $jsonResponse = ArrayUtils::jsonToArray($jsonResponse); + } + return !empty($jsonResponse['provider']) && $jsonResponse['provider'] === GatewayProvider::GP_API; } } diff --git a/src/Terminals/UPA/SubGroups/RequestParamFields.php b/src/Terminals/UPA/SubGroups/RequestParamFields.php index d1fe9a62..5477e7a1 100644 --- a/src/Terminals/UPA/SubGroups/RequestParamFields.php +++ b/src/Terminals/UPA/SubGroups/RequestParamFields.php @@ -2,11 +2,12 @@ namespace GlobalPayments\Api\Terminals\UPA\SubGroups; +use GlobalPayments\Api\Entities\Enums\TransactionModifier; +use GlobalPayments\Api\Entities\Enums\TransactionType; use GlobalPayments\Api\PaymentMethods\CreditCardData; use GlobalPayments\Api\Terminals\Abstractions\IRequestSubGroup; use GlobalPayments\Api\Entities\Enums\StoredCredentialInitiator; use GlobalPayments\Api\Terminals\Builders\TerminalBuilder; -use GlobalPayments\Api\Terminals\Diamond\Entities\Enums\TransactionType; class RequestParamFields implements IRequestSubGroup { @@ -65,10 +66,21 @@ public function setParams(TerminalBuilder $builder) case TransactionType::VOID: $this->clerkId = $builder->clerkId ?? null; return; + case TransactionType::SALE: + case TransactionType::REFUND: + case TransactionType::VERIFY: + case TransactionType::AUTH: + case TransactionType::CAPTURE: + $this->clerkId = $builder->clerkId; + break; + case TransactionType::EDIT: + if ($builder->transactionModifier !== TransactionModifier::UPDATE_LODGING_DETAILS) { + $this->clerkId = $builder->clerkId; + } + break; default: break; } - $this->clerkId = $builder->clerkId ?? null; if (!empty($builder->cardOnFileIndicator)) { $this->cardOnFileIndicator = ($builder->cardOnFileIndicator === StoredCredentialInitiator::CARDHOLDER) @@ -80,15 +92,16 @@ public function setParams(TerminalBuilder $builder) } if (!empty($builder->requestMultiUseToken)) { - $this->tokenRequest = $builder->requestMultiUseToken; + $this->tokenRequest = $builder->requestMultiUseToken === true ? 1 : 0; } - if ($builder->paymentMethod != null && - $builder->paymentMethod instanceof CreditCardData && - !empty($builder->paymentMethod->token) - ) { + if ( + $builder->paymentMethod instanceof CreditCardData && + !empty($builder->paymentMethod->token) + ) { $this->tokenValue = $builder->paymentMethod->token; } + if (isset($builder->shippingDate) && !empty($builder->invoiceNumber)) { $this->directMktInvoiceNbr = $builder->invoiceNumber; $this->directMktShipMonth = $builder->shippingDate->format('m'); diff --git a/src/Terminals/UPA/SubGroups/RequestTransactionFields.php b/src/Terminals/UPA/SubGroups/RequestTransactionFields.php index df03503d..926e3478 100644 --- a/src/Terminals/UPA/SubGroups/RequestTransactionFields.php +++ b/src/Terminals/UPA/SubGroups/RequestTransactionFields.php @@ -135,6 +135,7 @@ public function setParams(TerminalBuilder $builder) case TransactionType::EDIT: if ($builder->transactionModifier == TransactionModifier::UPDATE_LODGING_DETAILS) { $this->amount = sprintf('%07.2f', $builder->amount); + $this->clerkId = $builder->clerkId ?? null; } break; case TransactionType::SALE: @@ -200,7 +201,6 @@ public function setParams(TerminalBuilder $builder) $this->taxIndicator = $builder->taxExempt ?? null; $this->processCPC = $builder->processCPC ?? null; $this->purchaseOrder = $builder->orderId ?? null; - $this->clerkId = $builder->clerkId ?? null; if (isset($builder->confirmAmount)) { $this->confirmAmount = $builder->confirmAmount === true ? "Y" : "N"; } diff --git a/src/Terminals/UPA/UpaController.php b/src/Terminals/UPA/UpaController.php index 5ddaf7f3..6b550677 100644 --- a/src/Terminals/UPA/UpaController.php +++ b/src/Terminals/UPA/UpaController.php @@ -351,6 +351,7 @@ private function buildReportTransaction(TerminalReportBuilder $builder) : IDevic case TerminalReportType::GET_BATCH_DETAILS: $requestMessage['data']["params"] = [ "reportOutput" => $builder->searchBuilder->reportOutput ?? null, + "reportType" => $builder->searchBuilder->reportType ?? null, "batch" => $builder->searchBuilder->batch ?? null ]; break; diff --git a/src/Terminals/UPA/UpaInterface.php b/src/Terminals/UPA/UpaInterface.php index e1d65cec..885a25cd 100644 --- a/src/Terminals/UPA/UpaInterface.php +++ b/src/Terminals/UPA/UpaInterface.php @@ -23,7 +23,8 @@ TerminalAuthBuilder, TerminalManageBuilder, TerminalReportBuilder }; -use GlobalPayments\Api\Terminals\Enums\{DebugLevel, +use GlobalPayments\Api\Terminals\Enums\{BatchReportType, + DebugLevel, DeviceConfigType, DisplayOption, PromptType, @@ -337,11 +338,15 @@ public function batchReport($batchId) return new UpaBatchReport($rawResponse, UpaMessageId::GET_BATCH_REPORT); } - public function getBatchDetails(?string $batchId = null, bool $printReport = false) : ITerminalReport + public function getBatchDetails(?string $batchId = null, bool $printReport = false, string|BatchReportType $reportType = null) : ITerminalReport { $builder = (new TerminalReportBuilder(TerminalReportType::GET_BATCH_DETAILS)) - ->where(UpaSearchCriteria::BATCH, $batchId) - ->andCondition(UpaSearchCriteria::ECR_ID, "1"); + ->where(UpaSearchCriteria::ECR_ID, "1"); + + if (!empty($batchId)) { + $builder->andCondition(UpaSearchCriteria::BATCH, $batchId); + } + if (true === $printReport) { $builder->andCondition( UpaSearchCriteria::REPORT_OUTPUT, @@ -349,6 +354,10 @@ public function getBatchDetails(?string $batchId = null, bool $printReport = fal ); } + if (!empty($reportType)) { + $builder->andCondition(UpaSearchCriteria::REPORT_TYPE, $reportType); + } + return $builder->execute(); } @@ -712,7 +721,7 @@ public function executeUDData(UDData $screen) : IDeviceScreen $data['params'] = [ 'fileType' => $screen->fileType, 'slotNum' => $screen->slotNum, - 'displayOption' => $screen->displayOption + 'displayOption' => $screen->displayOption ?? null ]; $message = TerminalUtils::buildUPAMessage( diff --git a/src/Utils/ArrayUtils.php b/src/Utils/ArrayUtils.php index 4e2fbc21..a491eb92 100644 --- a/src/Utils/ArrayUtils.php +++ b/src/Utils/ArrayUtils.php @@ -11,14 +11,14 @@ class ArrayUtils * * @return array */ - public static function array_remove_empty($haystack) + public static function array_remove_empty(?array $haystack): array { if (is_null($haystack)) { return []; } foreach ($haystack as $key => $value) { if (is_array($value) || is_object($value)) { - $v = (array) $haystack[$key]; + $v = (array)$value; $haystack[$key] = self::array_remove_empty($v); } if (empty($haystack[$key])) { @@ -30,4 +30,9 @@ public static function array_remove_empty($haystack) return $haystack; } + + public static function jsonToArray(object $response) : array + { + return json_decode(json_encode($response), true); + } } \ No newline at end of file diff --git a/test/Integration/Gateways/GpApiConnector/CreditCardNotPresentTest.php b/test/Integration/Gateways/GpApiConnector/CreditCardNotPresentTest.php index d667e2f6..735a0cd6 100644 --- a/test/Integration/Gateways/GpApiConnector/CreditCardNotPresentTest.php +++ b/test/Integration/Gateways/GpApiConnector/CreditCardNotPresentTest.php @@ -18,6 +18,8 @@ use GlobalPayments\Api\Entities\Enums\StoredPaymentMethodSortProperty; use GlobalPayments\Api\Entities\Enums\TransactionStatus; use GlobalPayments\Api\Entities\Enums\TransactionType; +use GlobalPayments\Api\Entities\Exceptions\ArgumentException; +use GlobalPayments\Api\Entities\Exceptions\BuilderException; use GlobalPayments\Api\Entities\Exceptions\GatewayException; use GlobalPayments\Api\Entities\Reporting\SearchCriteria; use GlobalPayments\Api\Entities\StoredCredential; @@ -741,6 +743,9 @@ public function testCardDelete_WrongId() } } + /** + * @throws BuilderException + */ public function testCardTokenizationThenUpdate() { // process an auto-capture authorization @@ -1257,12 +1262,16 @@ public function testCreditSaleWith_InvalidFingerPrint() } } + /** + * @throws ArgumentException + * @throws BuilderException + */ public function testUpdatePaymentToken() { $startDate = (new DateTime())->modify('-30 days')->setTime(0, 0, 0); $response = ReportingService::findStoredPaymentMethodsPaged(1, 1) - ->orderBy(StoredPaymentMethodSortProperty::TIME_CREATED, SortDirection::DESC) + ->orderBy(StoredPaymentMethodSortProperty::TIME_CREATED) ->where(SearchCriteria::START_DATE, $startDate) ->execute(); diff --git a/test/Integration/Gateways/GpApiConnector/GpApiDigitalWalletTest.php b/test/Integration/Gateways/GpApiConnector/GpApiDigitalWalletTest.php index f930a185..ee2e5f39 100644 --- a/test/Integration/Gateways/GpApiConnector/GpApiDigitalWalletTest.php +++ b/test/Integration/Gateways/GpApiConnector/GpApiDigitalWalletTest.php @@ -4,6 +4,7 @@ use GlobalPayments\Api\Entities\Address; use GlobalPayments\Api\Entities\Enums\AddressType; +use GlobalPayments\Api\Entities\Enums\CardType; use GlobalPayments\Api\Entities\Enums\Channel; use GlobalPayments\Api\Entities\Enums\EncyptedMobileType; use GlobalPayments\Api\Entities\Enums\TransactionModifier; @@ -32,9 +33,9 @@ public function setup(): void $this->card->cardHolderName = "James Mason"; $this->clickToPayToken = '8144735251653223601'; $this->googlePayToken = '{ - "signature": "MEUCIQCYj/IzxdfmoL03Buao0VyKERNQ5b9Sk0Wqr2KNDdyy5wIgfax2jPYMpcKgfLtsIwMRLojt3/nqVfz4Y5njfnaQ0Jc=", + "signature": "MEUCIHES+D2qscALKRtWzGb9ti5USOkP1M5myGG+n2gnLw7oAiEAwFj7JeulajB71ZdW9LvjRNwB6A4v7yjgNwTkzAR+fNo=", "protocolVersion": "ECv1", - "signedMessage": "{\"encryptedMessage\":\"2UHlq0quCxAIvVaFX3QioTH38wAPR9a2RXYZmIKkfMhB1ilOECL3c0u01aDsBr/gd+wMGT41CzxT+rrlbt+nouko823FgFyP+ofdJmvmcm23LsqvCL3TRp3mvpSVZ221Jb8P9W2DriaFbVej6hb/zYcNwxfcydR44TCS2YpZGW/ZwydG898JOwCdZiMw5gh19UdmiioDGF09dYijGWsiQjgX9e5kJXJ0LTuuxxP2s6oc6CrMOtTmTP9qBhaYpCyYsZCpXDYwycBUQLcB5StFLmJD6msD9gtMWgK0cyKcZdRyQozdngNUa09EIvvrOr1SmGGHkTnddJze0gWD/G8rpZj4wosZoMmc6FAwEOFMkqKEUGqrYLpZRXKFzmU1wM76I5JBg9cy7XH78YJLeLopn9xgOd9VtNrccqWJN1UV\",\"ephemeralPublicKey\":\"BKpOmGO/XVU8FjhVY5xgNLvfz7HAxaUVdn/d5G43V/vE4Y2Yjdr8Z1Ot4WUWBWGh5kFx2MTjP+tPJiAUggc4DUU\\u003d\",\"tag\":\"KiOuZ7MyMamxKLGhEfiMzj4WmjFLda/9tAgK1yKGSJc\\u003d\"}" + "signedMessage": "{\"encryptedMessage\":\"a0X0HwBemGudk84o6K+MUZG1YwInK4rgmNT4bLwtOrbVhQ/2jaT2EX0HYaxi3C5o063++A7EJ5KIl7uwqTSp1GWHtAFqZaWdIMKgK+0ZuGliVkPqFmYmXSD1ksQJQw/veDbANfbtQUiR1c4ZBWm9l2SUDTAbk/BICbYzdWlMIxv/d+wQEWaxYLekCRojSMPAA/tsJigswY8tGAbimvi6Q0eKP7LBd0lLYCP2OnICorODdYcv9kM8RPNXniPphxJ+DKIw9brWb4zSUq0/sJjQYoXIbz/eVXJ5wxZOHf0FUXz2gRwAteziL2HpuxlnNKWgi06TC/CuxrfnqWgJ8QE6bb9NDOrjHxiZS4hZnFsqhmcHZL8Idnmc0fSNY+2zbDkLS+sNrsbzahpEIrHJBGNkNbOEcq3JmFIR8U7Nc30z\",\"ephemeralPublicKey\":\"BCs/ogxOtzEsAmrHwSw1M2Ly2AhX7dUQ/M+HFjFwT4J9MD+nIl8Raruw488czk43t7nC0+wJhWCDzpR3W3Af3TM\\u003d\",\"tag\":\"bjWbrD74J3QPaLtCk7/4RKOPlb0xe33eYcRqUSqMovI\\u003d\"}" }'; } @@ -202,6 +203,8 @@ public function testPayWithGooglePayEncrypted() ->execute(); $this->assertTransactionResponse($response, TransactionStatus::CAPTURED); + $this->assertNotEmpty($response->cardBrandTransactionId); + $this->assertEquals(CardType::VISA, $response->cardDetails->brand); } public function testGooglePayEncrypted_LinkedRefund() diff --git a/test/Integration/Gateways/Terminals/UPA/UpaMicTests.php b/test/Integration/Gateways/Terminals/UPA/UpaMicTests.php index ddf9cdd5..a54dbcd3 100644 --- a/test/Integration/Gateways/Terminals/UPA/UpaMicTests.php +++ b/test/Integration/Gateways/Terminals/UPA/UpaMicTests.php @@ -2,19 +2,46 @@ namespace GlobalPayments\Api\Tests\Integration\Gateways\Terminals\UPA; +use GlobalPayments\Api\Entities\AutoSubstantiation; use GlobalPayments\Api\Entities\Enums\Channel; +use GlobalPayments\Api\Entities\Enums\StoredCredentialInitiator; +use GlobalPayments\Api\Entities\Enums\TaxType; +use GlobalPayments\Api\Entities\Enums\TimeZoneIdentifier; use GlobalPayments\Api\Entities\Exceptions\ApiException; use GlobalPayments\Api\Entities\Exceptions\BuilderException; use GlobalPayments\Api\Entities\Exceptions\GatewayException; use GlobalPayments\Api\Entities\GpApi\AccessTokenInfo; use GlobalPayments\Api\Services\DeviceService; use GlobalPayments\Api\Terminals\Abstractions\IDeviceInterface; +use GlobalPayments\Api\Terminals\Abstractions\IDeviceResponse; use GlobalPayments\Api\Terminals\ConnectionConfig; +use GlobalPayments\Api\Terminals\Entities\MessageLines; +use GlobalPayments\Api\Terminals\Entities\PrintData; +use GlobalPayments\Api\Terminals\Entities\PromptMessages; +use GlobalPayments\Api\Terminals\Entities\ScanData; +use GlobalPayments\Api\Terminals\Entities\UDData; +use GlobalPayments\Api\Terminals\Enums\BatchReportType; use GlobalPayments\Api\Terminals\Enums\ConnectionModes; +use GlobalPayments\Api\Terminals\Enums\DebugLevel; +use GlobalPayments\Api\Terminals\Enums\DebugLogsOutput; +use GlobalPayments\Api\Terminals\Enums\DeviceConfigType; use GlobalPayments\Api\Terminals\Enums\DeviceType; +use GlobalPayments\Api\Terminals\Enums\DisplayOption; +use GlobalPayments\Api\Terminals\Enums\LogFileIndicator; +use GlobalPayments\Api\Terminals\Enums\UDFileTypes; use GlobalPayments\Api\Terminals\UPA\Entities\CancelParameters; +use GlobalPayments\Api\Terminals\UPA\Entities\Enums\UpaMessageId; +use GlobalPayments\Api\Terminals\UPA\Entities\Enums\UpaSearchCriteria; +use GlobalPayments\Api\Terminals\UPA\Entities\SignatureData; +use GlobalPayments\Api\Terminals\UPA\Responses\BatchList; +use GlobalPayments\Api\Terminals\UPA\Responses\BatchReportResponse; +use GlobalPayments\Api\Terminals\UPA\Responses\BatchTransaction; +use GlobalPayments\Api\Terminals\UPA\Responses\BatchTransactionList; use GlobalPayments\Api\Terminals\UPA\Responses\OpenTabDetailsResponse; +use GlobalPayments\Api\Terminals\UPA\Responses\SignatureResponse; +use GlobalPayments\Api\Terminals\UPA\Responses\TerminalSetupResponse; use GlobalPayments\Api\Terminals\UPA\Responses\TransactionResponse; +use GlobalPayments\Api\Terminals\UPA\Responses\UDScreenResponse; use GlobalPayments\Api\Tests\Data\BaseGpApiTestConfig; use GlobalPayments\Api\Tests\Integration\Gateways\Terminals\RequestIdProvider; use GlobalPayments\Api\Utils\GenerationUtils; @@ -94,22 +121,17 @@ public function testCreditSaleWithTerminalRefNumber() public function testLineItem() { $this->device->ecrId = '12'; - - $response = $this->device->lineItem("Line Item #1", "10.00"); - $this->assertNotNull($response); - $this->assertEquals('00', $response->deviceResponseCode); - - $response = $this->device->lineItem("Line Item #2", "11.00"); - $this->assertNotNull($response); - $this->assertEquals('00', $response->deviceResponseCode); - - $response = $this->device->lineItem("Line Item #3", "12.00"); - $this->assertNotNull($response); - $this->assertEquals('00', $response->deviceResponseCode); - - $this->assertNotNull($response); - $this->assertEquals('00', $response->deviceResponseCode); - $this->assertEquals('COMPLETE', $response->deviceResponseText); + $items = [ + ["Line Item #1", 10], + ["Line Item #2", 11], + ["Line Item #3", 13], + ]; + foreach ($items as $item) { + $response = $this->device->lineItem($item[0], $item[1]); + $this->assertNotNull($response); + $this->assertEquals('00', $response->deviceResponseCode); + $this->assertEquals('COMPLETE', $response->deviceResponseText); + } sleep(5); @@ -146,8 +168,9 @@ public function testCreditRefund() public function testCreditVerify() { + /** @var TransactionResponse $response */ $response = $this->device->verify() - ->withEcrId('13') + ->withEcrId('1') ->execute(); $this->assertNotNull($response); @@ -155,10 +178,15 @@ public function testCreditVerify() $this->assertEquals('COMPLETE', $response->deviceResponseText); } + /** + * @throws ApiException + */ public function testCreditVoid() { + /** @var TransactionResponse $response */ $response = $this->device->sale(10) ->withEcrId('13') + ->withClerkId('1234') ->execute(); $this->assertNotNull($response); @@ -171,6 +199,8 @@ public function testCreditVoid() $response = $this->device->void() ->withEcrId('13') ->withTransactionId($response->transactionId) + ->withClerkId($response->clerkId) + ->withClientTransactionId($response->referenceNumber) ->execute(); $this->assertNotNull($response); @@ -218,6 +248,7 @@ public function testEndOfDay() $this->assertEquals('00', $response->deviceResponseCode); $this->assertEquals('COMPLETE', $response->deviceResponseText); $this->assertNotEmpty($response->batchId); + $this->assertNotEmpty($response->batchSeqNbr); } public function testCancel() @@ -266,10 +297,367 @@ public function testGetOpenTabDetails() public function testReboot() { + /** @var TransactionResponse $response */ $response = $this->device->reboot(); $this->assertNotNull($response); $this->assertEquals('00', $response->deviceResponseCode); + $this->assertEquals('COMPLETE', $response->status); + $this->assertNotNull($response->transactionId); sleep(60); } + + public function testGetAppInfo() + { + /** @var TransactionResponse $response */ + $response = $this->device->getAppInfo(); + + $this->assertNotNull($response); + $this->assertInstanceOf(IDeviceResponse::class, $response); + $this->assertEquals('00', $response->deviceResponseCode); + $this->assertEquals('COMPLETE', $response->status); + $this->assertNotNull($response->deviceSerialNum); + } + + public function testGetParam() + { + $params = ["TerminalLanguage", "PinBypassIsSupported"]; + /** @var TransactionResponse $response */ + $response = $this->device->getParam($params); + + $this->assertNotNull($response); + $this->assertInstanceOf(IDeviceResponse::class, $response); + $this->assertEquals('00', $response->deviceResponseCode); + $this->assertEquals('COMPLETE', $response->status); + } + + public function testSetTimeZone() + { + $response = $this->device->setTimeZone(TimeZoneIdentifier::AMERICA_LOS_ANGELES); + + $this->assertNotNull($response); + $this->assertInstanceOf(IDeviceResponse::class, $response); + $this->assertEquals('00', $response->deviceResponseCode); + $this->assertEquals('COMPLETE', $response->status); + } + + public function testClearDataLake() + { + $response = $this->device->clearDataLake(); + + $this->assertNotNull($response); + $this->assertInstanceOf(IDeviceResponse::class, $response); + $this->assertEquals('00', $response->deviceResponseCode); + $this->assertEquals('COMPLETE', $response->status); + } + + public function testRestart() + { + $response = $this->device->reset(); + + $this->assertNotNull($response); + $this->assertInstanceOf(IDeviceResponse::class, $response); + $this->assertEquals('00', $response->deviceResponseCode); + $this->assertEquals('COMPLETE', $response->status); + } + + public function testReturnToIdle() + { + $this->device->ecrId = '12'; + /** @var TransactionResponse $response */ + $response = $this->device->returnToIdle(); + + $this->assertNotNull($response); + $this->assertEquals('00', $response->deviceResponseCode); + $this->assertEquals('COMPLETE', $response->status); + $this->assertNotNull($response->transactionId); + } + + public function testGetConfigContents() + { + /** @var TerminalSetupResponse $response */ + $response = $this->device->getDeviceConfig(DeviceConfigType::CONTACT_TERMINAL_CONFIG); + + $this->assertNotNull($response); + $this->assertEquals('00', $response->deviceResponseCode); + $this->assertEquals('COMPLETE', $response->status); + $this->assertEquals(DeviceConfigType::CONTACT_TERMINAL_CONFIG, $response->configType); + $this->assertNotNull($response->fileContent); + file_put_contents("configuration.txt", $response->fileContent); + } + + public function testPrint() + { + $printData = new PrintData(); + $printData->line1 = 'Printing...'; + $printData->line2 = 'Please Wait...'; + $printData->displayOption = DisplayOption::NO_SCREEN_CHANGE; + $printData->filePath = __DIR__ . "/samples/download.png"; + + $this->device->ecrId = '12'; + /** @var TransactionResponse $response */ + $response = $this->device->print($printData); + + $this->assertNotNull($response); + $this->assertEquals('00', $response->deviceResponseCode); + $this->assertEquals('COMPLETE', $response->status); + } + public function testScanQR() + { + $scanData = new ScanData(); + $scanData->header = 'SCAN'; + $scanData->prompts = new PromptMessages(); + $scanData->prompts->prompt1 = 'SCAN QR CODE'; + $scanData->prompts->prompt2 = 'ALIGN THE QR CODE WITHIN THE FRAME TO SCAN'; + + $this->device->ecrId = '12'; + /** @var TransactionResponse $response */ + $response = $this->device->scan($scanData); + + $this->assertNotNull($response); + $this->assertEquals('00', $response->deviceResponseCode); + $this->assertEquals('COMPLETE', $response->status); + $this->assertNotNull($response->scanData); + } + + public function testGetDebugInfo() + { + $this->device->ecrId = '1'; + /** @var TransactionResponse $response */ + $response = $this->device->getDebugInfo("logs/DebugLogs", LogFileIndicator::DEBUG_FILE_1); + + $this->assertNotNull($response); + $this->assertEquals('00', $response->deviceResponseCode); + $this->assertEquals('COMPLETE', $response->status); + $this->assertNotNull($response->debugFileContents); + $this->assertNotNull($response->debugFileLength); + } + + public function testSetDebugLevel() + { + $this->device->ecrId = '1'; + $response = $this->device->setDebugLevel([DebugLevel::PACKETS, DebugLevel::DATA], DebugLogsOutput::FILE); + + $this->assertNotNull($response); + $this->assertEquals('00', $response->deviceResponseCode); + $this->assertEquals('COMPLETE', $response->status); + } + + public function testGetDebugLevel() + { + $this->device->ecrId = '1'; + /** @var TransactionResponse $response */ + $response = $this->device->getDebugLevel(); + + $this->assertNotNull($response); + $this->assertEquals('00', $response->deviceResponseCode); + $this->assertEquals('COMPLETE', $response->status); + $this->assertEquals('PACKETS|DATA', $response->debugLevel); + } + + public function testGetSignature() + { + $data = new SignatureData(); + $data->prompts = new PromptMessages(); + $data->prompts->prompt1 = 'Please sign'; + $data->displayOption = DisplayOption::RETURN_TO_IDLE_SCREEN; + /** @var SignatureResponse $response */ + $response = $this->device->getSignatureFile($data); + + $this->assertNotNull($response); + $this->assertEquals('00', $response->deviceResponseCode); + $this->assertEquals('COMPLETE', $response->status); + $this->assertNotNull($response->signatureData); + + /*Save image to file*/ + $imageType = explode('/', getimagesizefromstring(base64_decode($response->signatureData))['mime'])[1]; + file_put_contents("signature.$imageType", base64_decode($response->signatureData)); + } + + public function testCommunicationCheck() + { + /** @var TransactionResponse $response */ + $response = $this->device->communicationCheck(); + $this->assertNotNull($response); + $this->assertEquals('00', $response->deviceResponseCode); + $this->assertEquals('COMPLETE', $response->status); + $this->assertEquals('Success', $response->gatewayResponseMessage); + } + + public function testLogon() + { + /** @var TransactionResponse $response */ + $response = $this->device->logon(); + + $this->assertNotNull($response); + $this->assertEquals('00', $response->deviceResponseCode); + $this->assertEquals('COMPLETE', $response->status); + $this->assertEquals(UpaMessageId::LOGON, $response->command); + } + + public function testReturnDefaultScreen() + { + $this->markTestSkipped("APP005 - COMMAND NOT ALLOWED IN THE CURRENT APP MODE"); + $response = $this->device->returnDefaultScreen(DisplayOption::RETURN_TO_IDLE_SCREEN); + + $this->assertNotNull($response); + $this->assertEquals('00', $response->deviceResponseCode); + $this->assertEquals('COMPLETE', $response->status); + } + + public function testGetEncryptionType() + { + $this->markTestSkipped("APP005 - COMMAND NOT ALLOWED IN THE CURRENT APP MODE"); + /** @var TransactionResponse $response */ + $response = $this->device->getEncryptionType(); + + $this->assertNotNull($response); + $this->assertEquals('00', $response->deviceResponseCode); + $this->assertEquals('COMPLETE', $response->status); + $this->assertNotEmpty($response->dataEncryptionType); + } + + public function testLoadUDDataFile() + { + $this->markTestSkipped("UD006 - CANNOT LOAD USER-DEFINED FILE"); + $screen = new UDData(); + $screen->fileType = UDFileTypes::HTML5; + $screen->slotNum = '22'; + $screen->file = 'samples/UDDataFile.html'; + /** @var UDScreenResponse $response */ + $response = $this->device->loadUDData($screen); + + $this->assertNotNull($response); + $this->assertEquals('00', $response->deviceResponseCode); + $this->assertEquals('COMPLETE', $response->status); + } + public function testRemoveUDDataFile() + { + $this->markTestSkipped("UD005 - CANNOT DELETE USER-DEFINED FILE"); + $screen = new UDData(); + $screen->fileType = UDFileTypes::HTML5; + $screen->slotNum = '1'; + + $this->device->ecrId = '1'; + /** @var UDScreenResponse $response */ + $response = $this->device->removeUDData($screen); + + $this->assertNotNull($response); + $this->assertEquals('00', $response->deviceResponseCode); + $this->assertEquals('COMPLETE', $response->status); + } + + public function testExecuteUDDataFile() + { + $this->markTestSkipped("UD001 - INVALID SLOT NUMBER"); + $screen = new UDData(); + $screen->fileType = UDFileTypes::HTML5; + $screen->slotNum = 1; + $screen->displayOption = DisplayOption::RETURN_TO_IDLE_SCREEN; + + $this->device->ecrId = '1'; + /** @var UDScreenResponse $response */ + $response = $this->device->executeUDData($screen); + + $this->assertNotNull($response); + $this->assertEquals('00', $response->deviceResponseCode); + $this->assertEquals('COMPLETE', $response->status); + } + + public function testInjectUDDataFile() + { + $this->markTestSkipped("INVALID_REQUEST_DATA - Request contains unexpected data"); + $screen = new UDData(); + $screen->fileType = UDFileTypes::HTML5; + $screen->fileName = "index.html"; + // this is the file with the content you want to inject + $screen->localFile = __DIR__ . '/samples/UDDataFile.html'; + + $this->device->ecrId = '1'; + /** @var UDScreenResponse $response */ + $response = $this->device->injectUDData($screen); + + $this->assertNotNull($response); + $this->assertEquals('00', $response->deviceResponseCode); + $this->assertEquals('COMPLETE', $response->status); + } + + public function testFindAvailableBatches() + { + $this->device->ecrId = '12'; + /** @var BatchList $response */ + $response = $this->device->findBatches()->execute(); + + $this->assertNotNull($response); + $this->assertEquals('Success', $response->status); + $this->assertIsArray($response->batchIds); + $this->assertGreaterThan(0, $this->count($response->batchIds)); + } + + public function testGetBatchDetails() + { + /** @var BatchReportResponse $response */ + $response = $this->device->getBatchDetails(printReport: true); + + $this->assertNotNull($response); + $this->assertEquals('COMPLETE', $response->status); + $this->assertNotNull($response->batchRecord); + $this->assertNotNull($response->batchRecord->transactionDetails); + $this->assertNotEmpty($response->batchRecord->batchId); + } + + public function testGetBatchReport() + { + $this->device->ecrId = '13'; + /** @var BatchReportResponse $response */ + $response = $this->device->getBatchReport() + ->where(UpaSearchCriteria::BATCH, "1035184") + ->execute(); + + $this->assertNotNull($response); + $this->assertEquals('COMPLETE', $response->status); + } + + public function testCreditSaleFullParams() + { + $autoSubAmounts = new AutoSubstantiation(); + $autoSubAmounts->setDentalSubTotal(5.00); + $autoSubAmounts->setClinicSubTotal(5); + $autoSubAmounts->setVisionSubTotal(5); + $autoSubAmounts->setPrescriptionSubTotal(12.50); + + $response = $this->device->sale(5) + ->withEcrId('13') + ->withClerkId('1234') + ->withCardOnFileIndicator(StoredCredentialInitiator::CARDHOLDER) + ->withCardBrandTransId("transId") + ->withInvoiceNumber('123A10') + ->withShippingDate(new \DateTime()) + ->withTaxAmount(2.18) + ->withGratuity(12.56) + ->withTaxType(TaxType::TAX_EXEMPT) + ->withCashBack(0.1) + ->withConfirmationAmount(true) + ->withProcessCPC(true) +// ->withAutoSubstantiation($autoSubAmounts) + ->withRequestMultiUseToken(true) + ->execute(); + + $this->assertNotNull($response); + $this->assertEquals('00', $response->deviceResponseCode); + $this->assertEquals('COMPLETE', $response->deviceResponseText); + } + + public function testDisplayMessage() + { + $messageLines = new MessageLines(); + $messageLines->line1 = 'Please wait...'; + $messageLines->timeout = 0; + + $response = $this->device->displayMessage($messageLines); + + $this->assertNotNull($response); + $this->assertEquals('00', $response->deviceResponseCode); + $this->assertEquals('COMPLETE', $response->status); + } } \ No newline at end of file diff --git a/test/Integration/Gateways/Terminals/UPA/samples/download.png b/test/Integration/Gateways/Terminals/UPA/samples/download.png index c4c2ce42..4406f69e 100644 Binary files a/test/Integration/Gateways/Terminals/UPA/samples/download.png and b/test/Integration/Gateways/Terminals/UPA/samples/download.png differ