From efd3b1be2e1b8880c120c482d9196b61b8305ccd Mon Sep 17 00:00:00 2001 From: BuildMaster Date: Tue, 9 Feb 2021 10:11:44 -0500 Subject: [PATCH] BuildMaster release: 2.2.5 --- .gitignore | 2 + composer.json | 4 +- phpunit.xml.dist | 98 +- src/Builders/AuthorizationBuilder.php | 198 +- src/Builders/ManagementBuilder.php | 37 + src/Builders/ReportBuilder.php | 2 + src/Builders/Secure3dBuilder.php | 20 +- src/Builders/TransactionReportBuilder.php | 153 +- src/Entities/Dispute.php | 20 + src/Entities/DisputeDocument.php | 16 + src/Entities/Enums/EbtCardType.php | 11 + src/Entities/Enums/EmvFallbackCondition.php | 20 + src/Entities/Enums/EmvLastChipRead.php | 32 + src/Entities/Enums/GatewayProvider.php | 1 + .../Enums/GpApi/AdjustmentFunding.php | 13 + src/Entities/Enums/GpApi/CaptureMode.php | 12 + src/Entities/Enums/GpApi/Channels.php | 12 + .../Enums/GpApi/DepositSortProperty.php | 15 + src/Entities/Enums/GpApi/DepositStatus.php | 17 + .../Enums/GpApi/DisputeSortProperty.php | 21 + src/Entities/Enums/GpApi/DisputeStage.php | 20 + src/Entities/Enums/GpApi/DisputeStatus.php | 14 + src/Entities/Enums/GpApi/EntryMode.php | 19 + src/Entities/Enums/GpApi/PaymentType.php | 13 + src/Entities/Enums/GpApi/SortDirection.php | 13 + .../Enums/GpApi/TransactionSortProperty.php | 15 + .../Enums/GpApi/TransactionStatus.php | 21 + src/Entities/Enums/ReportType.php | 7 + src/Entities/Enums/ServiceEndpoints.php | 2 + .../Enums/StoredCredentialInitiator.php | 17 + src/Entities/Enums/StoredCredentialReason.php | 16 + .../Enums/StoredCredentialSequence.php | 1 + src/Entities/Enums/StoredCredentialType.php | 4 + src/Entities/Enums/Target.php | 13 + src/Entities/Enums/TransactionStatus.php | 32 + src/Entities/Enums/TransactionType.php | 5 +- src/Entities/GpApi/AccessToken.php | 33 + src/Entities/GpApi/AccessTokenRequest.php | 34 + .../GpApi/Authentication3DSRequest.php | 198 + .../GpApi/CreatePaymentMethodRequest.php | 54 + src/Entities/GpApi/CreatePaymentRequest.php | 163 + src/Entities/GpApi/DTO/Authentication.php | 12 + src/Entities/GpApi/DTO/Card.php | 163 + src/Entities/GpApi/DTO/PaymentMethod.php | 18 + src/Entities/GpApi/GpApiRequest.php | 23 + src/Entities/GpApi/ManageCaptureRequest.php | 23 + src/Entities/GpApi/ManageRefundRequest.php | 21 + src/Entities/GpApi/ManageReversalRequest.php | 21 + src/Entities/GpApi/ReportMapper.php | 138 + src/Entities/GpApi/ReportingFindDeposits.php | 66 + .../ReportingFindSettlementTransactions.php | 87 + .../GpApi/ReportingFindTransactions.php | 78 + src/Entities/IRequestLogger.php | 15 + src/Entities/RecurringEntity.php | 222 +- .../Reporting/DataServiceCriteria.php | 38 + src/Entities/Reporting/DepositSummary.php | 141 + src/Entities/Reporting/DisputeSummary.php | 216 + src/Entities/Reporting/DisputeSummaryList.php | 11 + src/Entities/Reporting/SearchCriteria.php | 88 +- .../Reporting/SearchCriteriaBuilder.php | 227 +- src/Entities/Reporting/TransactionSummary.php | 208 +- src/Entities/StoredCredential.php | 5 + src/Entities/ThreeDSecure.php | 6 + src/Entities/Transaction.php | 6 + src/Gateways/Gateway.php | 32 +- src/Gateways/GatewayResponse.php | 5 + src/Gateways/Gp3DSProvider.php | 38 +- src/Gateways/GpApiConnector.php | 526 +++ src/Gateways/RestGateway.php | 76 +- src/Mapping/GpApiMapping.php | 289 ++ src/PaymentMethods/Credit.php | 73 +- src/PaymentMethods/CreditTrackData.php | 10 +- src/PaymentMethods/Debit.php | 1 + src/PaymentMethods/DebitTrackData.php | 9 + src/PaymentMethods/EBT.php | 6 + src/PaymentMethods/EBTTrackData.php | 17 + .../Interfaces/ITokenizable.php | 1 + src/PaymentMethods/TransactionReference.php | 1 + src/ServiceConfigs/Gateways/GpApiConfig.php | 192 + src/ServiceConfigs/Gateways/TransitConfig.php | 134 +- src/Services/GpApiService.php | 37 + src/Services/ReportingService.php | 43 +- src/Utils/AccessTokenInfo.php | 193 + src/Utils/AmountUtils.php | 2 +- src/Utils/CardUtils.php | 91 + src/Utils/GenerationUtils.php | 16 + src/Utils/Logging/Logger.php | 352 ++ src/Utils/Logging/SampleRequestLogger.php | 54 + src/Utils/StringUtils.php | 31 + test/Data/TestChecks.php | 74 +- .../GpApiConnector/AccessTokenTest.php | 122 + .../CapabilitiesCardPresentTest.php | 107 + .../GpApiSdkCertificationTest.php | 519 +++ .../CreditCardNotPresentTest.php | 923 ++++ .../GpApiConnector/CreditCardPresentTest.php | 115 + .../Gateways/GpApiConnector/DebitCardTest.php | 150 + .../Gateways/GpApiConnector/EbtCardTest.php | 62 + .../GpApiConnector/GpApi3DSecureTest.php | 449 ++ .../Gateways/GpApiConnector/MappingTest.php | 221 + .../GpApiConnector/ReportingDepositsTest.php | 189 + .../GpApiConnector/ReportingDisputesTest.php | 781 ++++ .../ReportingSettlementTransactionsTest.php | 664 +++ .../ReportingTransactionsTest.php | 667 +++ .../Certifications/CheckTest.php | 756 ++-- .../Certifications/EcommerceCheckTest.php | 216 +- .../Certifications/EcommerceTest.php | 3972 ++++++++--------- .../Certifications/MotoCheckTest.php | 216 +- .../Certifications/MotoTest.php | 3426 +++++++------- .../Certifications/RecurringTest.php | 1252 +++--- .../Certifications/RetailTest.php | 3964 ++++++++-------- .../Gateways/PorticoConnector/CreditTest.php | 730 +-- .../Gateways/PorticoConnector/DebitTest.php | 148 +- .../Gateways/PorticoConnector/EbtTest.php | 180 +- .../Gateways/PorticoConnector/GiftTest.php | 238 +- .../PorticoReportingTests.php | 594 +-- .../PorticoTokenManagementTest.php | 146 +- .../Gateways/RealexConnector/CreditTest.php | 574 +-- .../RealexConnector/Hpp/RealexHppClient.php | 502 +-- .../Gateways/RealexConnector/HppTest.php | 1512 +++---- .../Gateways/RealexConnector/HppTestCase.php | 482 +- .../RealexConnector/Realex3dSecureTests.php | 1000 ++--- .../RealexConnector/RealexApmTest.php | 382 +- .../RealexConnector/RecurringTest.php | 782 ++-- .../Certification/Ecommerce_3.php | 1572 +++---- .../Certification/Token_Request_Only.php | 524 +-- .../TransITConnector/CommercialCardTest.php | 442 +- .../TransITConnector/TransITAdminTest.php | 194 +- .../TransITConnector/TransITDebitTest.php | 106 +- .../TransITConnector/TransITTests.php | 650 +-- 129 files changed, 22297 insertions(+), 12766 deletions(-) create mode 100644 src/Entities/Dispute.php create mode 100644 src/Entities/DisputeDocument.php create mode 100644 src/Entities/Enums/EbtCardType.php create mode 100644 src/Entities/Enums/EmvFallbackCondition.php create mode 100644 src/Entities/Enums/EmvLastChipRead.php create mode 100644 src/Entities/Enums/GpApi/AdjustmentFunding.php create mode 100644 src/Entities/Enums/GpApi/CaptureMode.php create mode 100644 src/Entities/Enums/GpApi/Channels.php create mode 100644 src/Entities/Enums/GpApi/DepositSortProperty.php create mode 100644 src/Entities/Enums/GpApi/DepositStatus.php create mode 100644 src/Entities/Enums/GpApi/DisputeSortProperty.php create mode 100644 src/Entities/Enums/GpApi/DisputeStage.php create mode 100644 src/Entities/Enums/GpApi/DisputeStatus.php create mode 100644 src/Entities/Enums/GpApi/EntryMode.php create mode 100644 src/Entities/Enums/GpApi/PaymentType.php create mode 100644 src/Entities/Enums/GpApi/SortDirection.php create mode 100644 src/Entities/Enums/GpApi/TransactionSortProperty.php create mode 100644 src/Entities/Enums/GpApi/TransactionStatus.php create mode 100644 src/Entities/Enums/StoredCredentialReason.php create mode 100644 src/Entities/Enums/Target.php create mode 100644 src/Entities/Enums/TransactionStatus.php create mode 100644 src/Entities/GpApi/AccessToken.php create mode 100644 src/Entities/GpApi/AccessTokenRequest.php create mode 100644 src/Entities/GpApi/Authentication3DSRequest.php create mode 100644 src/Entities/GpApi/CreatePaymentMethodRequest.php create mode 100644 src/Entities/GpApi/CreatePaymentRequest.php create mode 100644 src/Entities/GpApi/DTO/Authentication.php create mode 100644 src/Entities/GpApi/DTO/Card.php create mode 100644 src/Entities/GpApi/DTO/PaymentMethod.php create mode 100644 src/Entities/GpApi/GpApiRequest.php create mode 100644 src/Entities/GpApi/ManageCaptureRequest.php create mode 100644 src/Entities/GpApi/ManageRefundRequest.php create mode 100644 src/Entities/GpApi/ManageReversalRequest.php create mode 100644 src/Entities/GpApi/ReportMapper.php create mode 100644 src/Entities/GpApi/ReportingFindDeposits.php create mode 100644 src/Entities/GpApi/ReportingFindSettlementTransactions.php create mode 100644 src/Entities/GpApi/ReportingFindTransactions.php create mode 100644 src/Entities/IRequestLogger.php create mode 100644 src/Entities/Reporting/DataServiceCriteria.php create mode 100644 src/Entities/Reporting/DepositSummary.php create mode 100644 src/Entities/Reporting/DisputeSummary.php create mode 100644 src/Entities/Reporting/DisputeSummaryList.php create mode 100644 src/Gateways/GpApiConnector.php create mode 100644 src/Mapping/GpApiMapping.php create mode 100644 src/ServiceConfigs/Gateways/GpApiConfig.php create mode 100644 src/Services/GpApiService.php create mode 100644 src/Utils/AccessTokenInfo.php create mode 100644 src/Utils/Logging/Logger.php create mode 100644 src/Utils/Logging/SampleRequestLogger.php create mode 100644 test/Integration/Gateways/GpApiConnector/AccessTokenTest.php create mode 100644 test/Integration/Gateways/GpApiConnector/Certifications/CapabilitiesCardPresentTest.php create mode 100644 test/Integration/Gateways/GpApiConnector/Certifications/GpApiSdkCertificationTest.php create mode 100644 test/Integration/Gateways/GpApiConnector/CreditCardNotPresentTest.php create mode 100644 test/Integration/Gateways/GpApiConnector/CreditCardPresentTest.php create mode 100644 test/Integration/Gateways/GpApiConnector/DebitCardTest.php create mode 100644 test/Integration/Gateways/GpApiConnector/EbtCardTest.php create mode 100644 test/Integration/Gateways/GpApiConnector/GpApi3DSecureTest.php create mode 100644 test/Integration/Gateways/GpApiConnector/MappingTest.php create mode 100644 test/Integration/Gateways/GpApiConnector/ReportingDepositsTest.php create mode 100644 test/Integration/Gateways/GpApiConnector/ReportingDisputesTest.php create mode 100644 test/Integration/Gateways/GpApiConnector/ReportingSettlementTransactionsTest.php create mode 100644 test/Integration/Gateways/GpApiConnector/ReportingTransactionsTest.php diff --git a/.gitignore b/.gitignore index caae86d0..85bee5ec 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,5 @@ composer.phar composer /docs/ /docs-cache/ + +.idea diff --git a/composer.json b/composer.json index ae26fd4e..c39787b1 100644 --- a/composer.json +++ b/composer.json @@ -14,7 +14,9 @@ "php": ">= 5.5.9", "ext-curl": "*", "ext-dom": "*", - "ext-openssl": "*" + "ext-openssl": "*", + "ext-json": "*", + "ext-zlib": "*" }, "require-dev": { "phpunit/phpunit": "~5.0", diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 4607ddf2..d2666d04 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,48 +1,50 @@ - - - - - - - - - - - - ./test/ - - - ./test/Unit/ - - - ./test/Integration/ - - - ./test/Integration/Gateways/PorticoConnector/Certifications/ - ./test/Integration/Gateways/RealexConnector/Certifications/ - - - ./test/Integration/Gateways/PorticoConnector/ - - - ./test/Integration/Gateways/RealexConnector/ - - - - - - - ./src/ - - ./test/ - - - - - + + + + + + + + + + + + ./test/ + + + ./test/Unit/ + + + ./test/Integration/ + + + ./test/Integration/Gateways/PorticoConnector/Certifications/ + ./test/Integration/Gateways/RealexConnector/Certifications/ + + + ./test/Integration/Gateways/PorticoConnector/ + + + ./test/Integration/Gateways/RealexConnector/ + + + ./test/Integration/Gateways/GpApiConnector/ + + + + + + ./src/ + + ./test/ + + + + + diff --git a/src/Builders/AuthorizationBuilder.php b/src/Builders/AuthorizationBuilder.php index 4134d783..22067bcf 100644 --- a/src/Builders/AuthorizationBuilder.php +++ b/src/Builders/AuthorizationBuilder.php @@ -5,6 +5,9 @@ use GlobalPayments\Api\Entities\Address; use GlobalPayments\Api\Entities\AutoSubstantiation; use GlobalPayments\Api\Entities\EcommerceInfo; +use GlobalPayments\Api\Entities\Enums\EmvFallbackCondition; +use GlobalPayments\Api\Entities\Enums\EmvLastChipRead; +use GlobalPayments\Api\Entities\Enums\PaymentMethodType; use GlobalPayments\Api\Entities\HostedPaymentData; use GlobalPayments\Api\Entities\Enums\AddressType; use GlobalPayments\Api\Entities\Enums\AliasAction; @@ -441,7 +444,7 @@ class AuthorizationBuilder extends TransactionBuilder * @var string */ public $cashTendered; - + /** * For TransIT transaction discount details * @@ -456,7 +459,7 @@ class AuthorizationBuilder extends TransactionBuilder * */ public $cardBrandTransactionId; - + /* * Card on File field * @var string @@ -464,6 +467,41 @@ class AuthorizationBuilder extends TransactionBuilder */ public $transactionInitiator; + /** + * @var string $tagData + */ + public $tagData; + + /** + * @var string $idempotencyKey + */ + public $idempotencyKey; + + /** + * @var EmvLastChipRead $emvLastChipRead + */ + public $emvLastChipRead; + + /** + * @var string $paymentApplicationVersion + */ + public $paymentApplicationVersion; + + /** + * @var EmvFallbackCondition $emvFallbackCondition + */ + public $emvFallbackCondition; + + /** + * @var EmvLastChipRead $emvChipCondition + */ + public $emvChipCondition; + + /** + * @var float $surchargeAmount + */ + public $surchargeAmount; + /** * {@inheritdoc} * @@ -519,70 +557,70 @@ protected function setupValidations() { $this->validations->of( TransactionType::AUTH | - TransactionType::SALE | - TransactionType::REFUND | - TransactionType::ADD_VALUE + TransactionType::SALE | + TransactionType::REFUND | + TransactionType::ADD_VALUE ) - ->with(TransactionModifier::NONE) - ->check('amount')->isNotNull() - ->check('currency')->isNotNull() - ->check('paymentMethod')->isNotNull(); - + ->with(TransactionModifier::NONE) + ->check('amount')->isNotNull() + ->check('currency')->isNotNull() + ->check('paymentMethod')->isNotNull(); + $this->validations->of( TransactionType::AUTH | - TransactionType::SALE + TransactionType::SALE ) - ->with(TransactionModifier::HOSTEDREQUEST) - ->check('amount')->isNotNull() - ->check('currency')->isNotNull(); + ->with(TransactionModifier::HOSTEDREQUEST) + ->check('amount')->isNotNull() + ->check('currency')->isNotNull(); $this->validations->of( TransactionType::AUTH | - TransactionType::SALE + TransactionType::SALE ) - ->with(TransactionModifier::OFFLINE) - ->check('amount')->isNotNull() - ->check('currency')->isNotNull() - ->check('offlineAuthCode')->isNotNull(); + ->with(TransactionModifier::OFFLINE) + ->check('amount')->isNotNull() + ->check('currency')->isNotNull() + ->check('offlineAuthCode')->isNotNull(); $this->validations->of(TransactionType::BALANCE) - ->check('paymentMethod')->isNotNull(); + ->check('paymentMethod')->isNotNull(); $this->validations->of(TransactionType::ALIAS) - ->check('aliasAction')->isNotNull() - ->check('alias')->isNotNull(); + ->check('aliasAction')->isNotNull() + ->check('alias')->isNotNull(); $this->validations->of(TransactionType::REPLACE) - ->check('replacementCard')->isNotNull(); + ->check('replacementCard')->isNotNull(); $this->validations->of( TransactionType::AUTH | - TransactionType::SALE + TransactionType::SALE ) - ->with(TransactionModifier::ENCRYPTED_MOBILE) - ->check('paymentMethod')->isNotNull() - ->check('token')->isNotNullInSubProperty('paymentMethod') - ->check('mobileType')->isNotNullInSubProperty('paymentMethod'); - + ->with(TransactionModifier::ENCRYPTED_MOBILE) + ->check('paymentMethod')->isNotNull() + ->check('token')->isNotNullInSubProperty('paymentMethod') + ->check('mobileType')->isNotNullInSubProperty('paymentMethod'); + $this->validations->of( TransactionType::VERIFY ) - ->with(TransactionModifier::HOSTEDREQUEST) - ->check('currency')->isNotNull(); - + ->with(TransactionModifier::HOSTEDREQUEST) + ->check('currency')->isNotNull(); + $this->validations->of( TransactionType::AUTH | - TransactionType::SALE + TransactionType::SALE ) - ->with(TransactionModifier::ALTERNATIVE_PAYMENT_METHOD) - ->check('amount')->isNotNull() - ->check('currency')->isNotNull() - ->check('paymentMethod')->isNotNull() - ->check('alternativePaymentMethodType')->isNotNullInSubProperty('paymentMethod') - ->check('returnUrl')->isNotNullInSubProperty('paymentMethod') - ->check('statusUpdateUrl')->isNotNullInSubProperty('paymentMethod') - ->check('country')->isNotNullInSubProperty('paymentMethod') - ->check('accountHolderName')->isNotNullInSubProperty('paymentMethod'); + ->with(TransactionModifier::ALTERNATIVE_PAYMENT_METHOD) + ->check('amount')->isNotNull() + ->check('currency')->isNotNull() + ->check('paymentMethod')->isNotNull() + ->check('alternativePaymentMethodType')->isNotNullInSubProperty('paymentMethod') + ->check('returnUrl')->isNotNullInSubProperty('paymentMethod') + ->check('statusUpdateUrl')->isNotNullInSubProperty('paymentMethod') + ->check('country')->isNotNullInSubProperty('paymentMethod') + ->check('accountHolderName')->isNotNullInSubProperty('paymentMethod'); } /** @@ -609,11 +647,11 @@ public function withAddress(Address $address, $type = AddressType::BILLING) /** * Set the request alias * - * @internal * @param string $aliasAction Request alias action * @param string $alias Request alias * * @return AuthorizationBuilder + * @internal */ public function withAlias($aliasAction, $alias) { @@ -661,7 +699,7 @@ public function withAmount($amount) return $this; } - /** @return AuthorizationBuilder */ + /** @return AuthorizationBuilder */ public function withAmountEstimated($value) { $this->amountEstimated = $value; @@ -1131,10 +1169,10 @@ public function withDccType($value) */ public function withConvenienceAmount($convenienceAmount) { - $this->convenienceAmount = $convenienceAmount; + $this->convenienceAmount = $convenienceAmount; return $this; } - + /** * Set the request shippingAmount * @@ -1221,7 +1259,7 @@ public function withScheduleId($scheduleId) $this->scheduleId = $scheduleId; return $this; } - + /** * Set the associated schedule ID * @@ -1234,7 +1272,7 @@ public function withDiscountDetails($discountDetails) $this->discountDetails = $discountDetails; return $this; } - + /** * Set the cash tendered amount * @@ -1247,7 +1285,7 @@ public function withCashTenderedDetails($cashTendered) $this->cashTendered = $cashTendered; return $this; } - + /** * Set the Card on File storage * @@ -1277,6 +1315,12 @@ public function withLastRegisteredDate($date) return $this; } + public function withMultiCapture($multiCapture = false) + { + $this->multiCapture = $multiCapture; + return $this; + } + /** * Depending on the parameters received, * Add supplementary data or @@ -1301,4 +1345,60 @@ public function withSupplementaryData($key, $value = null) return $this; } + + /** + * @param $value + */ + public function withTagData($value) + { + $this->tagData = $value; + + return $this; + } + + public function withIdempotencyKey($value) + { + $this->idempotencyKey = $value; + + return $this; + } + + public function hasEmvFallbackData() + { + return (!is_null($this->emvFallbackCondition) || !is_null($this->emvLastChipRead) || !empty($this->paymentApplicationVersion)); + } + + /** + * @param EmvFallbackCondition $condition + * @param EmvLastChipRead $lastRead + * @param string $appVersion + */ + public function withEmvFallbackData($condition, $lastRead, $appVersion = null) + { + $this->emvFallbackCondition = $condition; + $this->emvLastChipRead = $lastRead; + $this->paymentApplicationVersion = $appVersion; + } + + /** + * @param EmvLastChipRead $value + */ + public function withChipCondition($value) + { + $this->emvChipCondition = $value; + + return $this; + } + + /** + * @param float $value + * + * @return AuthorizationBuilder + */ + public function withSurchargeAmount($value) + { + $this->surchargeAmount = $value; + + return $this; + } } diff --git a/src/Builders/ManagementBuilder.php b/src/Builders/ManagementBuilder.php index 1c645dc6..fb2da3c4 100644 --- a/src/Builders/ManagementBuilder.php +++ b/src/Builders/ManagementBuilder.php @@ -123,12 +123,30 @@ class ManagementBuilder extends TransactionBuilder */ public $alternativePaymentType; + /** + * Dispute id + * + * @var int + */ + public $disputeId; + /** + * Array with DisputeDocument objects + * + * @var array + */ + public $disputeDocuments; + /** * @internal * @var string */ public $payerAuthenticationResponse; + /** + * @var string $idempotencyKey + */ + public $idempotencyKey; + /** * {@inheritdoc} * @@ -440,4 +458,23 @@ public function withPayerAuthenticationResponse($payerAuthenticationResponse) $this->payerAuthenticationResponse = $payerAuthenticationResponse; return $this; } + + public function withDisputeId($value) + { + $this->disputeId = $value; + return $this; + } + + public function withDisputeDocuments($value) + { + $this->disputeDocuments = $value; + return $this; + } + + public function withIdempotencyKey($value) + { + $this->idempotencyKey = $value; + + return $this; + } } diff --git a/src/Builders/ReportBuilder.php b/src/Builders/ReportBuilder.php index 8e31694b..6a79d0dc 100644 --- a/src/Builders/ReportBuilder.php +++ b/src/Builders/ReportBuilder.php @@ -2,6 +2,8 @@ namespace GlobalPayments\Api\Builders; +use GlobalPayments\Api\Entities\Enums\ReportType; +use GlobalPayments\Api\Entities\Enums\TimeZoneConversion; use GlobalPayments\Api\ServicesContainer; abstract class ReportBuilder extends BaseBuilder diff --git a/src/Builders/Secure3dBuilder.php b/src/Builders/Secure3dBuilder.php index 29ec953d..92c83759 100644 --- a/src/Builders/Secure3dBuilder.php +++ b/src/Builders/Secure3dBuilder.php @@ -182,6 +182,11 @@ class Secure3dBuilder extends BaseBuilder /** @var string */ public $workNumber; + /** + * @var string + */ + public $idempotencyKey; + public function __construct($transactionType) { parent::__construct(); @@ -1282,6 +1287,18 @@ public function withWorkNumber($countryCode, $number) return $this; } + /** + * @param string $value + * + * @return Secure3dBuilder + */ + public function withIdempotencyKey($value) + { + $this->idempotencyKey = $value; + + return $this; + } + /** * @throws ApiException * @return ThreeDSecure */ @@ -1342,7 +1359,7 @@ public function execute($configName = 'default', $version = Secure3dVersion::ANY case TransactionType::VERIFY_ENROLLED: if (!empty($response->threeDSecure)) { $rvalue = $response->threeDSecure; - if ((bool)$rvalue->enrolled) { + if (in_array($rvalue->enrolled, ['True', 'Y', true], true)) { $rvalue->setAmount($this->amount); $rvalue->setCurrency($this->currency); $rvalue->setOrderId($response->orderId); @@ -1361,6 +1378,7 @@ public function execute($configName = 'default', $version = Secure3dVersion::ANY } } } + return $rvalue; } diff --git a/src/Builders/TransactionReportBuilder.php b/src/Builders/TransactionReportBuilder.php index 6ccd5aa7..94cffc83 100644 --- a/src/Builders/TransactionReportBuilder.php +++ b/src/Builders/TransactionReportBuilder.php @@ -2,10 +2,17 @@ namespace GlobalPayments\Api\Builders; +use GlobalPayments\Api\Entities\Enums\GpApi\DepositSortProperty; +use GlobalPayments\Api\Entities\Enums\GpApi\DisputeSortProperty; +use GlobalPayments\Api\Entities\Enums\GpApi\SortDirection; +use GlobalPayments\Api\Entities\Enums\GpApi\TransactionSortProperty; use GlobalPayments\Api\Entities\Enums\ReportType; +use GlobalPayments\Api\Entities\Enums\TimeZoneConversion; +use GlobalPayments\Api\Entities\Exceptions\ApiException; use GlobalPayments\Api\ServicesContainer; use GlobalPayments\Api\Entities\Reporting\SearchCriteria; use GlobalPayments\Api\Entities\Reporting\SearchCriteriaBuilder; +use phpDocumentor\Parser\Exception; class TransactionReportBuilder extends ReportBuilder { @@ -17,13 +24,13 @@ class TransactionReportBuilder extends ReportBuilder /** * @internal - * @var DateTime + * @var \DateTime */ public $endDate; /** * @internal - * @var DateTime + * @var \DateTime */ public $startDate; @@ -32,19 +39,59 @@ class TransactionReportBuilder extends ReportBuilder * @var string */ public $transactionId; - + + /** + * @var integer + */ + public $page; + + /** + * @var integer + */ + public $pageSize; + + /** + * @var TransactionSortProperty + */ + public $transactionOrderBy; + + /** + * @var SortDirection + */ + public $transactionOrder; + + /** + * @var DepositSortProperty + */ + public $depositOrderBy; + + /** + * @var SortDirection + */ + public $depositOrder; + + /** + * @var DisputeSortProperty + */ + public $disputeOrderBy; + + /** + * @var SortDirection + */ + public $disputeOrder; + /** * @internal * @var string */ public $transactionType; - + /** * @internal * @var SearchCriteriaBuilder */ public $searchBuilder; - + /** * @internal * @var ReportType @@ -56,14 +103,25 @@ class TransactionReportBuilder extends ReportBuilder * @var TimeZoneConversion */ public $timeZoneConversion; - + public function __construct($activity) { parent::__construct($activity); - + $this->searchBuilder = new SearchCriteriaBuilder($this); } - + + /** + * Sets the gateway deposit id as criteria for the report. + * @param $depositId + * @return $this + */ + public function withDepositId($depositId) + { + $this->searchBuilder->depositId = $depositId; + return $this; + } + /** * Sets the device ID as criteria for the report. * @@ -77,10 +135,22 @@ public function withDeviceId($value) return $this; } + /** + * Sets the gateway dispute id as criteria for the report. + * + * @param $disputeId + * @return $this + */ + public function withDisputeId($disputeId) + { + $this->searchBuilder->disputeId = $disputeId; + return $this; + } + /** * Sets the end date as criteria for the report. * - * @param DateTime $value The end date + * @param \DateTime $value The end date * * @return TransactionReportBuilder */ @@ -93,7 +163,7 @@ public function withEndDate($value) /** * Sets the start date as criteria for the report. * - * @param DateTime $value The start date + * @param \DateTime $value The start date * * @return TransactionReportBuilder */ @@ -128,20 +198,75 @@ public function withTransactionId($value) $this->transactionId = $value; return $this; } - + + /** + * Set the gateway paging criteria for the report + * @param $page + * @param $pageSize + * @return $this + */ + public function withPaging($page, $pageSize) + { + $this->page = $page; + $this->pageSize = $pageSize; + return $this; + } + + /** + * Sets the gateway settlement dispute id as criteria for the report. + * + * @param $settlementDisputeId + * @return $this + */ + public function withSettlementDisputeId($settlementDisputeId) + { + $this->searchBuilder->settlementDisputeId = $settlementDisputeId; + return $this; + } + + /** + * Set the gateway order for the criteria + * @param string $sortProperty sorting property + * @param string $sortDirection sorting direction + * @return $this + */ + public function orderBy($sortProperty, $sortDirection = SortDirection::DESC) + { + switch ($this->reportType) { + case ReportType::FIND_TRANSACTIONS: + case ReportType::FIND_SETTLEMENT_TRANSACTIONS: + $this->transactionOrderBy = $sortProperty; + $this->transactionOrder = $sortDirection; + break; + case ReportType::FIND_DEPOSITS: + $this->depositOrderBy = $sortProperty; + $this->depositOrder = $sortDirection; + break; + case ReportType::FIND_DISPUTES: + case ReportType::FIND_SETTLEMENT_DISPUTES: + $this->disputeOrderBy = $sortProperty; + $this->disputeOrder = $sortDirection; + break; + default: + throw new \InvalidArgumentException("Invalid order found"); + } + + return $this; + } + /** * @return SearchCriteriaBuilder */ public function where($criteria, $value) { - return $this->searchBuilder->and($criteria, $value); + return $this->searchBuilder->andWith($criteria, $value); } - + protected function setupValidations() { $this->validations->of(ReportType::TRANSACTION_DETAIL) ->check('transactionId')->isNotNull(); - + $this->validations->of(ReportType::ACTIVITY) ->check('transactionId')->isNull(); } diff --git a/src/Entities/Dispute.php b/src/Entities/Dispute.php new file mode 100644 index 00000000..8fb14b87 --- /dev/null +++ b/src/Entities/Dispute.php @@ -0,0 +1,20 @@ + [ + Target::Transit => 'ICC_TERMINAL_ERROR' + ], + self::NO_CANDIDATE_LIST => [ + Target::Transit => 'NO_CANDIDATE_LIST' + ] + ]; +} \ No newline at end of file diff --git a/src/Entities/Enums/EmvLastChipRead.php b/src/Entities/Enums/EmvLastChipRead.php new file mode 100644 index 00000000..c674e288 --- /dev/null +++ b/src/Entities/Enums/EmvLastChipRead.php @@ -0,0 +1,32 @@ + [ + Target::GP_API => 'PREV_SUCCESS', + Target::Portico => 'CHIP_FAILED_PREV_SUCCESS', + Target::Transit => 'SUCCESSFUL' + ], + self::FAILED => [ + Target::GP_API => 'PREV_FAILED', + Target::Portico => 'CHIP_FAILED_PREV_FAILED', + Target::Transit => 'FAILED' + ], + self::NOT_A_CHIP_TRANSACTION => [ + Target::Transit => 'NOT_A_CHIP_TRANSACTION' + ], + self::UNKNOWN => [ + Target::Transit => 'UNKNOWN' + ] + ]; +} \ No newline at end of file diff --git a/src/Entities/Enums/GatewayProvider.php b/src/Entities/Enums/GatewayProvider.php index aa022318..7cda9d7b 100644 --- a/src/Entities/Enums/GatewayProvider.php +++ b/src/Entities/Enums/GatewayProvider.php @@ -10,4 +10,5 @@ class GatewayProvider extends Enum const GP_ECOM = 'GP_ECOM'; const GENIUS = 'GENIUS'; const TRANSIT = 'TRANSIT'; + const GP_API = 'GP-API'; } diff --git a/src/Entities/Enums/GpApi/AdjustmentFunding.php b/src/Entities/Enums/GpApi/AdjustmentFunding.php new file mode 100644 index 00000000..5472cde3 --- /dev/null +++ b/src/Entities/Enums/GpApi/AdjustmentFunding.php @@ -0,0 +1,13 @@ + [ + Target::Realex => self::CARDHOLDER, + Target::Portico => 'C', + Target::GP_API => self::PAYER + ], + self::MERCHANT => [ + Target::Realex => self::MERCHANT, + Target::Portico => 'M', + Target::GP_API => self::MERCHANT + ], + self::SCHEDULED => [ + Target::Realex => self::SCHEDULED + ] + ]; } diff --git a/src/Entities/Enums/StoredCredentialReason.php b/src/Entities/Enums/StoredCredentialReason.php new file mode 100644 index 00000000..20212bd5 --- /dev/null +++ b/src/Entities/Enums/StoredCredentialReason.php @@ -0,0 +1,16 @@ + self::INITIATED, + self::AUTHENTICATED => 'SUCCESS_AUTHENTICATED', + self::PENDING => self::PENDING, + self::DECLINED => self::DECLINED, + self::PREAUTHORIZED => self::PREAUTHORIZED, + self::CAPTURED => self::CAPTURED, + self::BATCHED => self::BATCHED, + self::REVERSED => self::REVERSED, + self::FUNDED => self::FUNDED, + self::REJECTED => self::REJECTED, + ]; +} \ No newline at end of file diff --git a/src/Entities/Enums/TransactionType.php b/src/Entities/Enums/TransactionType.php index 63fec60f..99720ab6 100644 --- a/src/Entities/Enums/TransactionType.php +++ b/src/Entities/Enums/TransactionType.php @@ -39,5 +39,8 @@ class TransactionType extends Enum const PRE_AUTH_COMPLETION = 1073741824; // 1 << 30 const TOKEN_UPDATE = 2147483648; // 1 << 31 const BENEFIT_WITHDRAWAL = 4294967296; // 1 <<32 - const TOKENIZE = 8589934592; // 1 << 33; + const TOKENIZE = 8589934592; // 1 << 33 + const DETOKENIZE = 17179869184; //1 << 34 + const DISPUTE_ACCEPTANCE = 274877906944; // 1 << 38 + const DISPUTE_CHALLENGE = 549755813888; // 1 << 39 } diff --git a/src/Entities/GpApi/AccessToken.php b/src/Entities/GpApi/AccessToken.php new file mode 100644 index 00000000..5a2a8a86 --- /dev/null +++ b/src/Entities/GpApi/AccessToken.php @@ -0,0 +1,33 @@ +token = $token; + $this->type = $type; + $this->time_created = $time_created; + $this->seconds_to_expire = $seconds_to_expire; + } + + + public function composeAuthorizationHeader() + { + return $this->type . ' ' . $this->token; + } +} diff --git a/src/Entities/GpApi/AccessTokenRequest.php b/src/Entities/GpApi/AccessTokenRequest.php new file mode 100644 index 00000000..97ce88a6 --- /dev/null +++ b/src/Entities/GpApi/AccessTokenRequest.php @@ -0,0 +1,34 @@ +app_id = $app_id; + $this->nonce = $nonce; + $this->secret = $secret; + $this->grant_type = $grant_type; + $this->seconds_to_expire = $seconds_to_expire; + $this->interval_to_expire = $interval_to_expire; + } +} \ No newline at end of file diff --git a/src/Entities/GpApi/Authentication3DSRequest.php b/src/Entities/GpApi/Authentication3DSRequest.php new file mode 100644 index 00000000..cdf0cad4 --- /dev/null +++ b/src/Entities/GpApi/Authentication3DSRequest.php @@ -0,0 +1,198 @@ +reference = !empty($builder->referenceNumber) ? $builder->referenceNumber : GenerationUtils::getGuid(); + $threeDS->amount = StringUtils::toNumeric($builder->amount); + $threeDS->currency = $builder->currency; + + $threeDS->payment_method = self::setPaymentMethodParam($builder->paymentMethod); + $threeDS->notifications = [ + 'challenge_return_url' => $config->getChallengeNotificationUrl(), + 'three_ds_method_return_url' => $config->getMethodNotificationUrl() + ]; + + return $threeDS; + } + + public static function initiateAuthenticationData(Secure3dBuilder $builder, GpApiConfig $config) + { + $threeDS = new Authentication3DSRequest(); + parent::initBaseParams($threeDS, $config); + $threeDS->amount = StringUtils::toNumeric($builder->amount); + $threeDS->currency = $builder->currency; + $threeDS->preference = $builder->challengeRequestIndicator; + $threeDS->method_url_completion_status = (string) $builder->methodUrlCompletion; + $threeDS->source = (string) $builder->authenticationSource; +// $threeDS->message_category = (string) $builder->messageCategory; ??? + $threeDS->merchant_contact_url = 'https://enp4qhvjseljg.x.pipedream.net/'; // @TODO + $order = [ + 'time_created_reference' => !empty($builder->orderCreateDate) ? + (new \DateTime($builder->orderCreateDate))->format('Y-m-d\TH:i:s.u\Z') : null, + 'amount' => StringUtils::toNumeric($builder->amount), + 'currency' => $builder->currency, + 'reference' => $builder->referenceNumber, + 'address_match_indicator' => $builder->isAddressMatchIndicator() ? true : false, + 'gift_card_count' => $builder->giftCardCount, + 'gift_card_currency'=> $builder->giftCardCurrency, + 'gift_card_amount' => $builder->giftCardAmount, + 'delivery_email' => $builder->deliveryEmail, + 'delivery_timeframe' => $builder->deliveryTimeframe, + 'shipping_method' => (string) $builder->shippingMethod, + 'shipping_name_matches_cardholder_name' => $builder->getShippingNameMatchesCardHolderName(), + 'preorder_indicator' => (string) $builder->preOrderIndicator, + 'preorder_availability_date' => !empty($builder->preOrderAvailabilityDate) ? + $builder->preOrderAvailabilityDate->format('Y-m-d') : null, + 'reorder_indicator' => (string) $builder->reorderIndicator, + 'transaction_type' => $builder->orderTransactionType + ]; + + if (!empty($builder->shippingAddress)) { + $order['shipping_address'] = [ + 'line1' => $builder->shippingAddress->streetAddress1, + 'line2' => $builder->shippingAddress->streetAddress2, + 'line3' => $builder->shippingAddress->streetAddress3, + 'city' => $builder->shippingAddress->city, + 'postal_code' => $builder->shippingAddress->postalCode, + 'state' => $builder->shippingAddress->state, + 'country' => $builder->shippingAddress->countryCode + ]; + } + $threeDS->order = $order; + $threeDS->payment_method = self::setPaymentMethodParam($builder->paymentMethod); + $threeDS->payer = [ + 'reference' => $builder->customerAccountId, + 'account_age' => (string) $builder->accountAgeIndicator, + 'account_creation_date' => !empty($builder->accountCreateDate) ? + $builder->accountCreateDate->format('Y-m-d') : null, + 'account_change_date' => !empty($builder->accountChangeDate) ? + $builder->accountChangeDate->format('Y-m-d') : null, + 'account_change_indicator' => (string) $builder->accountChangeIndicator, + 'account_password_change_date' => !empty($builder->passwordChangeDate) ? + $builder->passwordChangeDate->format('Y-m-d') : null, + 'account_password_change_indicator' => (string) $builder->passwordChangeIndicator, + 'home_phone' => [ + 'country_code' => $builder->homeCountryCode, + 'subscriber_number' => $builder->homeNumber + ], + 'work_phone' => [ + 'country_code' => $builder->workCountryCode, + 'subscriber_number' => $builder->workNumber + ], + 'payment_account_creation_date' => !empty($builder->paymentAccountCreateDate) ? + $builder->paymentAccountCreateDate->format('Y-m-d') : null, + 'payment_account_age_indicator' => (string) $builder->paymentAgeIndicator, + 'suspicious_account_activity' => $builder->previousSuspiciousActivity, + 'purchases_last_6months_count' => $builder->numberOfPurchasesInLastSixMonths, + 'transactions_last_24hours_count' => $builder->numberOfTransactionsInLast24Hours, + 'transaction_last_year_count' => $builder->numberOfTransactionsInLastYear, + 'provision_attempt_last_24hours_count' => $builder->numberOfAddCardAttemptsInLast24Hours, + 'shipping_address_time_created_reference' => !empty($builder->shippingAddressCreateDate) ? + $builder->shippingAddressCreateDate->format('Y-m-d') : null, + 'shipping_address_creation_indicator' => (string) $builder->shippingAddressUsageIndicator + ]; + + $threeDS->payer_prior_three_ds_authentication_data = [ + 'authentication_method' => (string) $builder->priorAuthenticationMethod, + 'acs_transaction_reference' => $builder->priorAuthenticationTransactionId, + 'authentication_timestamp' => !empty($builder->priorAuthenticationTimestamp) ? + $builder->priorAuthenticationTimestamp->format('Y-m-d\TH:i:s.u\Z') : null, + 'authentication_data' => $builder->priorAuthenticationData + ]; + + $threeDS->recurring_authorization_data = [ + 'max_number_of_instalments' => $builder->maxNumberOfInstallments, + 'frequency' => $builder->recurringAuthorizationFrequency, + 'expiry_date' => $builder->recurringAuthorizationExpiryDate + ]; + + $threeDS->payer_login_data = [ + 'authentication_data' => $builder->customerAuthenticationData, + 'authentication_timestamp' => !empty($builder->customerAuthenticationTimestamp) ? + $builder->customerAuthenticationTimestamp->format('Y-m-d\TH:i:s.u\Z') : null, + 'authentication_type' => (string) $builder->customerAuthenticationMethod + ]; + if (!empty($builder->browserData)) { + $threeDS->browser_data = [ + 'accept_header' => $builder->browserData->acceptHeader, + 'color_depth' => (string) $builder->browserData->colorDepth, + 'ip' => $builder->browserData->ipAddress, + 'java_enabled' => $builder->browserData->javaEnabled, + 'javascript_enabled' => $builder->browserData->javaScriptEnabled, + 'language' => $builder->browserData->language, + 'screen_height' => $builder->browserData->screenHeight, + 'screen_width' => $builder->browserData->screenWidth, + 'challenge_window_size' => (string) $builder->browserData->challengWindowSize, + 'timezone' => (string) $builder->browserData->timeZone, + 'user_agent' => $builder->browserData->userAgent + ]; + } + + return $threeDS; + } + + public static function setPaymentMethodParam($cardData) + { + $paymentMethod = new PaymentMethod(); + if ($cardData instanceof ITokenizable && !empty($cardData->token)) { + $paymentMethod->id = $cardData->token; + $paymentMethod->name = $cardData->cardHolderName; + } + if ($cardData instanceof ICardData) { + $paymentMethod->card = (object) [ + 'number' => $cardData->number, + 'expiry_month' => !empty($cardData->expMonth) ? $cardData->expMonth : '', + 'expiry_year' => !empty($cardData->expYear) ? + substr(str_pad($cardData->expYear, 4, '0', STR_PAD_LEFT), 2, 2) : '' + ];; + } + + return $paymentMethod; + } +} \ No newline at end of file diff --git a/src/Entities/GpApi/CreatePaymentMethodRequest.php b/src/Entities/GpApi/CreatePaymentMethodRequest.php new file mode 100644 index 00000000..e0d1c321 --- /dev/null +++ b/src/Entities/GpApi/CreatePaymentMethodRequest.php @@ -0,0 +1,54 @@ +account_name = $accessTokenInfo->getTokenizationAccountName(); + $createPaymentMethodRequest->name = $builder->description ? $builder->description : ""; + $createPaymentMethodRequest->reference = $builder->clientTransactionId ? + $builder->clientTransactionId : GenerationUtils::generateOrderId(); + $card = new Card(); + $builderCard = $builder->paymentMethod; + $card->setNumber($builderCard->number); + $card->setExpireMonth((string)$builderCard->expMonth); + $card->setExpireYear(substr(str_pad($builderCard->expYear, 4, '0', STR_PAD_LEFT), 2, 2)); + $createPaymentMethodRequest->card = GenerationUtils::convertObjectToArray($card); + + return $createPaymentMethodRequest; + } + + public static function createFromManagementBuilder(ManagementBuilder $builder) + { + $request = new CreatePaymentMethodRequest(); + $card = new Card(); + $builderCard = $builder->paymentMethod; + $card->setExpireMonth((string)$builderCard->expMonth); + $card->setExpireYear(substr(str_pad($builderCard->expYear, 4, '0', STR_PAD_LEFT), 2, 2)); + $request->card = GenerationUtils::convertObjectToArray($card); + + return $request; + } + +} diff --git a/src/Entities/GpApi/CreatePaymentRequest.php b/src/Entities/GpApi/CreatePaymentRequest.php new file mode 100644 index 00000000..04a579d7 --- /dev/null +++ b/src/Entities/GpApi/CreatePaymentRequest.php @@ -0,0 +1,163 @@ +account_name = $gpApiConfig->getAccessTokenInfo()->getTransactionProcessingAccountName(); + $paymentRequest->type = ($builder->transactionType == TransactionType::REFUND ? 'REFUND' : 'SALE'); + $paymentRequest->channel = $gpApiConfig->getChannel(); + $paymentRequest->capture_mode = !empty($captureMode) ? $captureMode : CaptureMode::AUTO; + $paymentRequest->authorization_mode = !empty($builder->allowPartialAuth) ? 'PARTIAL' : null; + $paymentRequest->amount = StringUtils::toNumeric($builder->amount); + $paymentRequest->currency = $builder->currency; + $paymentRequest->reference = !empty($builder->clientTransactionId) ? + $builder->clientTransactionId : GenerationUtils::getGuid(); + $paymentRequest->description = $builder->description; + $paymentRequest->order_reference = $builder->orderId; + $paymentRequest->gratuity_amount = StringUtils::toNumeric($builder->gratuity); + $paymentRequest->surcharge_amount = StringUtils::toNumeric($builder->surchargeAmount); + $paymentRequest->convenience_amount = StringUtils::toNumeric($builder->convenienceAmount); + $paymentRequest->cashback_amount = StringUtils::toNumeric($builder->cashBackAmount); + $paymentRequest->country = !empty($builder->billingAddress) ? + $builder->billingAddress->country : $gpApiConfig->getCountry(); + $paymentRequest->ip_address = $builder->customerIpAddress; + $paymentMethod = self::createPaymentMethodParam($builder, $entryMode); + + $paymentRequest->payment_method = $paymentMethod; + + if (!empty($builder->storedCredential)) { + $paymentRequest->initiator = + !empty(StoredCredentialInitiator::$mapInitiator[$builder->storedCredential->initiator]) ? + strtoupper(StoredCredentialInitiator::$mapInitiator[$builder->storedCredential->initiator][Target::GP_API]) : ''; + $paymentRequest->stored_credential = (object) [ + 'model' => strtoupper($builder->storedCredential->type), + 'reason' => strtoupper($builder->storedCredential->reason), + 'sequence' => strtoupper($builder->storedCredential->sequence) + ]; + } + + return $paymentRequest; + } + + + /** + * @param AuthorizationBuilder|ManagementBuilder $builder + * @param string $entryMode + * + * @return PaymentMethod + */ + public static function createPaymentMethodParam($builder, $entryMode) + { + /** @var CreditCardData|CreditTrackData|DebitTrackData $paymentMethodContainer */ + $paymentMethodContainer = $builder->paymentMethod; + $paymentMethod = new PaymentMethod(); + $paymentMethod->entry_mode = !empty($entryMode) ? $entryMode : null; + + //authentication + if ($paymentMethodContainer instanceof CreditCardData) { + $paymentMethod->name = $paymentMethodContainer->cardHolderName; + $secureEcom = $paymentMethodContainer->threeDSecure; + if (!empty($secureEcom)) { + $threeDS = (object) [ + 'message_version' => $secureEcom->getVersion(), + 'eci' => $secureEcom->eci, + 'value' => $secureEcom->authenticationValue, + 'server_trans_ref' => $secureEcom->serverTransactionId, + 'ds_trans_ref' => $secureEcom->directoryServerTransactionId + ]; + $paymentMethod->authentication = (object) ['three_ds' => $threeDS]; + } + } + + //encryption + if ($paymentMethodContainer instanceof IEncryptable) { + if (!empty($paymentMethodContainer->encryptionData)) { + /** + * @var EncryptionData $encryptionData + */ + $encryptionData = $paymentMethodContainer->encryptionData; + $encryption = (object) ['version' => $encryptionData->version]; + if (!empty($encryptionData->ktb)) { + $method = 'KBT'; + $info = $encryptionData->ktb; + } elseif (!empty($encryptionData->ksn)) { + $method = 'KSN'; + $info = $encryptionData->ksn; + } + if (!empty($info)) { + $encryption->method = $method; + $encryption->info = $info; + $paymentMethod->encryption = $encryption; + } + } + } + + if ($paymentMethodContainer instanceof ITokenizable && !empty($paymentMethodContainer->token)) { + $paymentMethod->id = $paymentMethodContainer->token; + } + + if (is_null($paymentMethod->id)) { + $paymentMethod->card = CardUtils::generateCard($builder); + } + + return $paymentMethod; + } +} diff --git a/src/Entities/GpApi/DTO/Authentication.php b/src/Entities/GpApi/DTO/Authentication.php new file mode 100644 index 00000000..daf95915 --- /dev/null +++ b/src/Entities/GpApi/DTO/Authentication.php @@ -0,0 +1,12 @@ +number; + } + + public function setNumber($value) + { + $this->number = $value; + } + + public function getExpireMonth() + { + return $this->expiry_month; + } + + public function setExpireMonth($value) + { + $this->expiry_month = $value; + } + + public function getExpireYear() + { + return $this->expiry_year; + } + + public function setExpireYear($value) + { + $this->expiry_year = $value; + } + + public function getCvv() + { + return $this->cvv; + } + + public function setCvv($value) + { + $this->cvv = $value; + } + + public function getCvvIndicator() + { + return $this->cvv_indicator; + } + + public function setCvvIndicator($value) + { + $this->cvv_indicator = $value; + } + + public function getAvsAddress() + { + return $this->avs_address; + } + + public function setAvsAddress($value) + { + $this->avs_address = $value; + } + + public function getAvsPostalCode() + { + return $this->avs_postal_code; + } + + public function setAvsPostalCode($value) + { + $this->avs_postal_code = $value; + } + + public function getTrack() + { + return $this->track; + } + + public function setTrack($value) + { + $this->track = $value; + } + + public function getTag() + { + return $this->tag; + } + + public function setTag($value) + { + $this->tag = $value; + } + + public function getFunding() + { + return $this->funding; + } + + public function setFunding($value) + { + $this->funding = $value; + } + + public function getChipCondition() + { + return $this->chip_condition; + } + + public function setChipCondition($value) + { + $this->chip_condition = $value; + } + + public function getPinBlock() + { + return $this->pin_block; + } + + public function setPinBlock($value) + { + $this->pin_block = $value; + } + + public function getBrandReference() + { + return $this->brand_reference; + } + + public function setBrandReference($value) + { + $this->brand_reference = $value; + } + + public function getAuthCode() + { + return $this->authcode; + } + + public function setAuthCode($value) + { + $this->authcode = $value; + } + } \ No newline at end of file diff --git a/src/Entities/GpApi/DTO/PaymentMethod.php b/src/Entities/GpApi/DTO/PaymentMethod.php new file mode 100644 index 00000000..96700440 --- /dev/null +++ b/src/Entities/GpApi/DTO/PaymentMethod.php @@ -0,0 +1,18 @@ +account_name = $config->getAccessTokenInfo()->getTransactionProcessingAccountName(); + $request->channel = $config->getChannel(); + $request->country = $config->getCountry(); + } +} \ No newline at end of file diff --git a/src/Entities/GpApi/ManageCaptureRequest.php b/src/Entities/GpApi/ManageCaptureRequest.php new file mode 100644 index 00000000..9420a8d5 --- /dev/null +++ b/src/Entities/GpApi/ManageCaptureRequest.php @@ -0,0 +1,23 @@ +amount = StringUtils::toNumeric($builder->amount); + $request->gratuity = StringUtils::toNumeric($builder->gratuity); + + return $request; + } +} \ No newline at end of file diff --git a/src/Entities/GpApi/ManageRefundRequest.php b/src/Entities/GpApi/ManageRefundRequest.php new file mode 100644 index 00000000..bc768774 --- /dev/null +++ b/src/Entities/GpApi/ManageRefundRequest.php @@ -0,0 +1,21 @@ +amount = !empty($builder->amount) ? StringUtils::toNumeric($builder->amount) : null; + + return $request; + } +} \ No newline at end of file diff --git a/src/Entities/GpApi/ManageReversalRequest.php b/src/Entities/GpApi/ManageReversalRequest.php new file mode 100644 index 00000000..bf4933b7 --- /dev/null +++ b/src/Entities/GpApi/ManageReversalRequest.php @@ -0,0 +1,21 @@ +amount = !empty($builder->amount) ? StringUtils::toNumeric($builder->amount) : null; + + return $request; + } +} \ No newline at end of file diff --git a/src/Entities/GpApi/ReportMapper.php b/src/Entities/GpApi/ReportMapper.php new file mode 100644 index 00000000..bae6c3c1 --- /dev/null +++ b/src/Entities/GpApi/ReportMapper.php @@ -0,0 +1,138 @@ +transactionId = isset($response->id) ? $response->id : null; + $summary->transactionDate = new \DateTime($response->time_created); + $summary->transactionStatus = $response->status; + $summary->transactionType = $response->type; + $summary->channel = !empty($response->channel) ? $response->channel : null; + $summary->amount = $response->amount; + $summary->currency = $response->currency; + $summary->referenceNumber = $response->reference; + $summary->clientTransactionId = $response->reference; + // $summary->unknown = $response->time_created_reference; + $summary->batchSequenceNumber = $response->batch_id; + $summary->country = !empty($response->country) ? $response->country : null; + // $summary->unknown = $response->action_create_id; + $summary->originalTransactionId = !empty($response->parent_resource_id) ? $response->parent_resource_id : null; + + if (isset($response->payment_method)) { + $summary->gatewayResponseMessage = isset($response->payment_method->message) ? + $response->payment_method->message : null; + $summary->entryMode = isset($response->payment_method->entry_mode) ? + $response->payment_method->entry_mode : null; + // $summary->unknown = isset($response->payment_method) ? $response->payment_method->name : null; + + if (isset($response->payment_method->card)) { + $card = $response->payment_method->card; + $summary->cardType = isset($card->brand) ? + $card->brand : null; + $summary->authCode = isset($card->authcode) ? + $card->authcode : null; + $summary->brandReference = isset($card->brand_reference) ? + $card->brand_reference : null; + $summary->aquirerReferenceNumber = isset($card->arn) ? + $card->arn : null; + $summary->maskedCardNumber = isset($card->masked_number_first6last4) ? + $card->masked_number_first6last4 : null; + } + } + return $summary; + } + + public static function mapDepositSummary($response) + { + $summary = new DepositSummary(); + $summary->depositId = $response->id; + $summary->depositDate = new \DateTime($response->time_created); + $summary->status = $response->status; + $summary->type = $response->funding_type; + $summary->amount = $response->amount; + $summary->currency = $response->currency; + + if (isset($response->system)) { + $system = $response->system; + $summary->merchantNumber = $system->mid; + $summary->merchantHierarchy = $system->hierarchy; + $summary->merchantName = $system->name; + $summary->merchantDbaName = $system->dba; + } + + if (isset($response->sales)) { + $sales = $response->sales; + $summary->salesTotalCount = isset($sales->count) ? $sales->count : 0; + $summary->salesTotalAmount = isset($sales->amount) ? $sales->amount : 0; + } + + if (isset($response->refunds)) { + $refunds = $response->refunds; + $summary->refundsTotalCount = isset($refunds->count) ? $refunds->count : 0; + $summary->refundsTotalAmount = isset($refunds->amount) ? $refunds->amount : 0; + } + + if (isset($response->disputes)) { + $disputes = $response->disputes; + $summary->chargebackTotalCount = isset($disputes->chargebacks->count) ? $disputes->chargebacks->count : 0; + $summary->chargebackTotalAmount = isset($disputes->chargebacks->amount) ? + $disputes->chargebacks->amount : 0; + + $summary->adjustmentTotalCount = isset($disputes->reversals->count) ? $disputes->reversals->count : 0; + $summary->adjustmentTotalAmount = isset($disputes->reversals->amount) ? $disputes->reversals->amount : 0; + } + + $summary->feesTotalAmount = isset($response->fees->amount) ? $response->fees->amount : 0; + return $summary; + } + + public static function mapDisputeSummary($response) + { + $summary = new DisputeSummary(); + $summary->caseId = $response->id; + $summary->caseIdTime = !empty($response->time_created) ? new \DateTime($response->time_created) : ''; + $summary->caseStatus = $response->status; + $summary->caseStage = $response->stage; + $summary->caseAmount = $response->amount; + $summary->caseCurrency = $response->currency; + if (isset($response->system)) { + $system = $response->system; + $summary->caseMerchantId = $system->mid; + $summary->merchantHierarchy = $system->hierarchy; + } + if ( + isset($response->payment_method) && + isset($response->payment_method->card) + ) { + $card = $response->payment_method->card; + $summary->transactionMaskedCardNumber = $card->number; + $summary->transactionARN = $card->arn; + $summary->transactionCardType = $card->brand; + } + $summary->reasonCode = $response->reason_code; + $summary->reason = $response->reason_description; + $summary->respondByDate = new \DateTime($response->time_to_respond_by); + $summary->result = $response->result; + $summary->lastAdjustmentAmount = $response->last_adjustment_amount; + $summary->lastAdjustmentCurrency = $response->last_adjustment_currency; + $summary->lastAdjustmentFunding = $response->last_adjustment_funding; + + return $summary; + } +} \ No newline at end of file diff --git a/src/Entities/GpApi/ReportingFindDeposits.php b/src/Entities/GpApi/ReportingFindDeposits.php new file mode 100644 index 00000000..47c0e608 --- /dev/null +++ b/src/Entities/GpApi/ReportingFindDeposits.php @@ -0,0 +1,66 @@ +page = $builder->page; + $deposit->page_size = $builder->pageSize; + $deposit->order_by = $builder->depositOrderBy; + $deposit->order = $builder->depositOrder; + $deposit->account_name = $tokenInfo->getDataAccountName(); + $deposit->from_time_created = !empty($builder->startDate) ? + $builder->startDate->format('Y-m-d') : null; + $deposit->to_time_created = !empty($builder->endDate) ? + $builder->endDate->format('Y-m-d') : null; + $deposit->id = $builder->searchBuilder->depositId; + $deposit->status = $builder->searchBuilder->depositStatus; + $deposit->amount = StringUtils::toNumeric($builder->searchBuilder->amount); + $deposit->masked_account_number_last4 = $builder->searchBuilder->accountNumberLastFour; + $deposit->systemMid = $builder->searchBuilder->merchantId; + $deposit->systemHierarchy = $builder->searchBuilder->systemHierarchy; + + $queryString = array(); + foreach ($deposit as $key => $value) { + if (!empty($value)) { + if ($key == 'systemMid') { + $queryString['system.mid'] = $value; + continue; + } + if ($key == 'systemHierarchy') { + $queryString['system.hierarchy'] = $value; + continue; + } + $queryString[$key] = $value; + } + } + + return $queryString; + } + +} \ No newline at end of file diff --git a/src/Entities/GpApi/ReportingFindSettlementTransactions.php b/src/Entities/GpApi/ReportingFindSettlementTransactions.php new file mode 100644 index 00000000..5432a2d8 --- /dev/null +++ b/src/Entities/GpApi/ReportingFindSettlementTransactions.php @@ -0,0 +1,87 @@ +page = $builder->page; + $settleTrans->page_size = $builder->pageSize; + $settleTrans->order = $builder->transactionOrder; + $settleTrans->order_by = $builder->transactionOrderBy; + $settleTrans->number_first6 = $builder->searchBuilder->cardNumberFirstSix; + $settleTrans->number_last4 = $builder->searchBuilder->cardNumberLastFour; + $settleTrans->deposit_status = $builder->searchBuilder->depositStatus; + $settleTrans->account_name = $accessTokenInfo->getDataAccountName(); + $settleTrans->brand = $builder->searchBuilder->cardBrand; + $settleTrans->arn = $builder->searchBuilder->aquirerReferenceNumber; + $settleTrans->brand_reference = $builder->searchBuilder->brandReference; + $settleTrans->authcode = $builder->searchBuilder->authCode; + $settleTrans->reference = $builder->searchBuilder->referenceNumber; + $settleTrans->status = $builder->searchBuilder->transactionStatus; + $settleTrans->from_time_created = !empty($builder->searchBuilder->startDate) ? $builder->searchBuilder->startDate->format('Y-m-d') : null; + $settleTrans->to_time_created = !empty($builder->searchBuilder->endDate) ? + $builder->searchBuilder->endDate->format('Y-m-d') : null; + $settleTrans->deposit_id = $builder->searchBuilder->depositId; + $settleTrans->from_deposit_time_created = !empty($builder->searchBuilder->startDepositDate) ? + $builder->searchBuilder->startDepositDate->format('Y-m-d') : null; + $settleTrans->to_deposit_time_created = !empty($builder->searchBuilder->endDepositDate) ? + $builder->searchBuilder->endDepositDate->format('Y-m-d') : null; + $settleTrans->from_batch_time_created = !empty($builder->searchBuilder->startBatchDate) ? + $builder->searchBuilder->startBatchDate->format('Y-m-d') : null; + $settleTrans->to_batch_time_created = !empty($builder->searchBuilder->endBatchDate) ? + $builder->searchBuilder->endBatchDate->format('Y-m-d') : null; + $settleTrans->systemMid = $builder->searchBuilder->merchantId; + $settleTrans->systemHierarchy = $builder->searchBuilder->systemHierarchy; + + $queryString = array(); + foreach ($settleTrans as $key => $value) { + if (!empty($value)) { + if ($key == 'systemMid') { + $queryString['system.mid'] = $value; + continue; + } + if ($key == 'systemHierarchy') { + $queryString['system.hierarchy'] = $value; + continue; + } + $queryString[$key] = $value; + } + } + + return $queryString; + } +} \ No newline at end of file diff --git a/src/Entities/GpApi/ReportingFindTransactions.php b/src/Entities/GpApi/ReportingFindTransactions.php new file mode 100644 index 00000000..86770b1a --- /dev/null +++ b/src/Entities/GpApi/ReportingFindTransactions.php @@ -0,0 +1,78 @@ +page = $builder->page; + $report->page_size = $builder->pageSize; + $report->order_by = $builder->transactionOrderBy; + $report->order = $builder->transactionOrder; + $report->id = $builder->transactionId; + $report->type = $builder->searchBuilder->paymentType; + $report->channel = $builder->searchBuilder->channel; + $report->amount = StringUtils::toNumeric($builder->searchBuilder->amount); + $report->currency = $builder->searchBuilder->currency; + $report->number_first6 = $builder->searchBuilder->cardNumberFirstSix; + $report->number_last4 = $builder->searchBuilder->cardNumberLastFour; + $report->token_first6 = $builder->searchBuilder->tokenFirstSix; + $report->token_last4 = $builder->searchBuilder->tokenLastFour; + $report->account_name = $builder->searchBuilder->accountName; + $report->brand = $builder->searchBuilder->cardBrand; + $report->brand_reference = $builder->searchBuilder->brandReference; + $report->authcode = $builder->searchBuilder->authCode; + $report->reference = $builder->searchBuilder->referenceNumber; + $report->status = $builder->searchBuilder->transactionStatus; + $report->from_time_created = !empty($builder->searchBuilder->startDate) ? + $builder->searchBuilder->startDate->format('Y-m-d') : null; + $report->to_time_created = !empty($builder->searchBuilder->endDate) ? + $builder->searchBuilder->endDate->format('Y-m-d') : (new \DateTime())->format('Y-m-d'); + $report->country = $builder->searchBuilder->country; + $report->batch_id = $builder->searchBuilder->batchId; + $report->entry_mode = $builder->searchBuilder->paymentEntryMode; + $report->name = $builder->searchBuilder->name; + + $queryString = array(); + foreach ($report as $name => $value) { + if (!empty($value)) { + $queryString[$name] = $value; + } + } + + return $queryString; + } +} \ No newline at end of file diff --git a/src/Entities/IRequestLogger.php b/src/Entities/IRequestLogger.php new file mode 100644 index 00000000..2b80c8b4 --- /dev/null +++ b/src/Entities/IRequestLogger.php @@ -0,0 +1,15 @@ + - */ -abstract class RecurringEntity implements IRecurringEntity -{ - /** - * All resource should be supplied a merchant-/application-defined ID. - * - * @var string - */ - public $id; - - /** - * All resources should be supplied a gateway-defined ID. - * - * @var string - */ - public $key; - - /** - * {@inheritDoc} - */ - public function create() - { - return RecurringService::create($this); - } - - /** - * {@inheritDoc} - */ - public function delete($force = false) - { - try { - return RecurringService::delete($this, $force); - } catch (ApiException $exc) { - throw new ApiException('Failed to delete record, see inner exception for more details', $exc); - } - } - - /** - * {@inheritDoc} - */ - public static function find($id, $configName = 'default') - { - $client = ServicesContainer::instance()->getRecurringClient($configName); - if (!$client->supportsRetrieval) { - throw new UnsupportedTransactionException(); - } - - $identifier = static::getIdentifierName(); - $response = RecurringService::search(static::class) - ->addSearchCriteria($identifier, $id) - ->execute(); - - foreach ($response as $entity) { - if ($entity->id === $id) { - return RecurringService::get($entity); - } - } - - return null; - } - - /** - * {@inheritDoc} - */ - public static function findAll($configName = 'default') - { - $client = ServicesContainer::instance()->getRecurringClient($configName); - if (!$client->supportsRetrieval) { - throw new UnsupportedTransactionException(); - } - - return RecurringService::search(static::class)->execute(); - } - - /** - * {@inheritDoc} - */ - public function saveChanges($configName = 'default') - { - try { - return RecurringService::edit($this); - } catch (ApiException $exc) { - throw new ApiException('Update failed, see inner exception for more details', $exc); - } - } - - protected static function getIdentifierName() - { - if (static::class === Customer::class) { - return 'customerIdentifier'; - } elseif (static::class === RecurringPaymentMethod::class) { - return 'paymentMethodIdentifier'; - } elseif (static::class === Schedule::class) { - return 'scheduleIdentifier'; - } - return ''; - } -} + + */ +abstract class RecurringEntity implements IRecurringEntity +{ + /** + * All resource should be supplied a merchant-/application-defined ID. + * + * @var string + */ + public $id; + + /** + * All resources should be supplied a gateway-defined ID. + * + * @var string + */ + public $key; + + /** + * {@inheritDoc} + */ + public function create() + { + return RecurringService::create($this); + } + + /** + * {@inheritDoc} + */ + public function delete($force = false) + { + try { + return RecurringService::delete($this, $force); + } catch (ApiException $exc) { + throw new ApiException('Failed to delete record, see inner exception for more details', $exc); + } + } + + /** + * {@inheritDoc} + */ + public static function find($id, $configName = 'default') + { + $client = ServicesContainer::instance()->getRecurringClient($configName); + if (!$client->supportsRetrieval) { + throw new UnsupportedTransactionException(); + } + + $identifier = static::getIdentifierName(); + $response = RecurringService::search(static::class) + ->addSearchCriteria($identifier, $id) + ->execute(); + + foreach ($response as $entity) { + if ($entity->id === $id) { + return RecurringService::get($entity); + } + } + + return null; + } + + /** + * {@inheritDoc} + */ + public static function findAll($configName = 'default') + { + $client = ServicesContainer::instance()->getRecurringClient($configName); + if (!$client->supportsRetrieval) { + throw new UnsupportedTransactionException(); + } + + return RecurringService::search(static::class)->execute(); + } + + /** + * {@inheritDoc} + */ + public function saveChanges($configName = 'default') + { + try { + return RecurringService::edit($this); + } catch (ApiException $exc) { + throw new ApiException('Update failed, see inner exception for more details', $exc); + } + } + + protected static function getIdentifierName() + { + if (static::class === Customer::class) { + return 'customerIdentifier'; + } elseif (static::class === RecurringPaymentMethod::class) { + return 'paymentMethodIdentifier'; + } elseif (static::class === Schedule::class) { + return 'scheduleIdentifier'; + } + return ''; + } +} diff --git a/src/Entities/Reporting/DataServiceCriteria.php b/src/Entities/Reporting/DataServiceCriteria.php new file mode 100644 index 00000000..e0936caf --- /dev/null +++ b/src/Entities/Reporting/DataServiceCriteria.php @@ -0,0 +1,38 @@ +withDisputeId($this->caseId); + } + + /** + * @param array $documents + * + * @return ManagementBuilder + */ + public function challenge($documents) + { + return (new ManagementBuilder(TransactionType::DISPUTE_CHALLENGE)) + ->withDisputeId($this->caseId) + ->withDisputeDocuments($documents); + } +} \ No newline at end of file diff --git a/src/Entities/Reporting/DisputeSummaryList.php b/src/Entities/Reporting/DisputeSummaryList.php new file mode 100644 index 00000000..b1df22ae --- /dev/null +++ b/src/Entities/Reporting/DisputeSummaryList.php @@ -0,0 +1,11 @@ + + * @var array */ public $cardTypes; + + /** + * @var Channels + */ + public $channel; /** * @var string @@ -106,37 +157,102 @@ class SearchCriteriaBuilder * @var string */ public $clientTransactionId; + + /** + * @var string + */ + public $country; + + /** + * @var string + */ + public $currency; /** * @var string */ public $customerId; + + /** + * @var string + */ + public $depositId; + + /** + * @var string + */ + public $depositReference; + + /** + * @var DepositStatus + */ + public $depositStatus; /** * @var string */ public $displayName; + + /** + * @var string + */ + public $disputeId; + + /** + * @var DisputeStage + */ + public $disputeStage; + + /** + * @var DisputeStatus + */ + public $disputeStatus; + + /** + * @var \DateTime + */ + public $endAdjustmentDate; + + /** + * @var \DateTime + */ + public $endBatchDate; /** - * @var DateTime + * @var \DateTime */ public $endDate; - + + /** + * @var \DateTime + */ + public $endDepositDate; + + /** + * @var \DateTime + */ + public $endStageDate; + + /** + * @var bool + */ + public $fullyCaptured; + /** * @var string */ public $giftCurrency; - + /** * @var string */ public $giftMaskedAlias; - + /** - * @var bool + * @var string */ - public $fullyCaptured; - + public $hierarchy; + /** * @var string */ @@ -151,19 +267,54 @@ class SearchCriteriaBuilder * @var string */ public $issuerTransactionId; + + /** + * @var \DateTime + */ + public $localTransactionEndTime; + + /** + * @var \DateTime + */ + public $localTransactionStartTime; + + /** + * @var string + */ + public $merchantId; + + /** + * @var string + */ + public $name; /** * @var bool */ public $oneTime; + + /** + * @var string + */ + public $oderId; + + /** + * @var EntryMode + */ + public $paymentEntryMode; /** * @var string */ public $paymentMethodKey; + + /** + * @var PaymentType + */ + public $paymentType; /** - * @var IEnumerable + * @var array */ public $paymentTypes; @@ -173,14 +324,19 @@ class SearchCriteriaBuilder public $referenceNumber; /** - * @var IEnumerable + * @var array */ public $transactionType; /** - * @var decimal + * @var integer */ public $settlementAmount; + + /** + * @var string + */ + public $settlementDisputeId; /** * @var string @@ -191,11 +347,51 @@ class SearchCriteriaBuilder * @var string */ public $siteTrace; + + /** + * @var \DateTime + */ + public $startAdjustmentDate; + + /** + * @var \DateTime + */ + public $startBatchDate; /** - * @var DateTime + * @var \DateTime */ public $startDate; + + /** + * @var \DateTime + */ + public $startDepositDate; + + /** + * @var \DateTime + */ + public $startStageDate; + + /** + * @var string + */ + public $systemHierarchy; + + /** + * @var string + */ + public $tokenFirstSix; + + /** + * @var string + */ + public $tokenLastFour; + + /** + * @var TransactionStatus + */ + public $transactionStatus; /** * @var string @@ -206,6 +402,11 @@ class SearchCriteriaBuilder * @var string */ public $username; + + /** + * @var string + */ + public $timezone; public function __construct(TransactionReportBuilder $reportBuilder = null) { diff --git a/src/Entities/Reporting/TransactionSummary.php b/src/Entities/Reporting/TransactionSummary.php index 4b85dc92..41c2efb5 100644 --- a/src/Entities/Reporting/TransactionSummary.php +++ b/src/Entities/Reporting/TransactionSummary.php @@ -1,8 +1,7 @@ cardHolderResponseInfo = $this->mergeValue($this->cardHolderResponseInfo, $secureEcom->cardHolderResponseInfo); $this->cavv = $this->mergeValue($this->cavv, $secureEcom->cavv); $this->challengeMandated = $this->mergeValue($this->challengeMandated, $secureEcom->challengeMandated); + $this->challengeValue = $this->mergeValue($this->challengeValue, $secureEcom->challengeValue); $this->criticalityIndicator = $this->mergeValue($this->criticalityIndicator, $secureEcom->criticalityIndicator); $this->currency = $this->mergeValue($this->currency, $secureEcom->currency); $this->decoupledResponseIndicator = $this->mergeValue($this->decoupledResponseIndicator, $secureEcom->decoupledResponseIndicator); diff --git a/src/Entities/Transaction.php b/src/Entities/Transaction.php index 157b7d61..c299ddbd 100644 --- a/src/Entities/Transaction.php +++ b/src/Entities/Transaction.php @@ -260,6 +260,12 @@ class Transaction */ public $cardBrandTransactionId; + public $cardNumber; + + public $cardExpMonth; + + public $cardExpYear; + /** * Creates a `Transaction` object from a stored transaction ID. * diff --git a/src/Gateways/Gateway.php b/src/Gateways/Gateway.php index b57e67ff..b127341f 100644 --- a/src/Gateways/Gateway.php +++ b/src/Gateways/Gateway.php @@ -2,12 +2,15 @@ namespace GlobalPayments\Api\Gateways; +use GlobalPayments\Api\Entities\IRequestLogger; +use GlobalPayments\Api\Utils\Logging\Logger; + abstract class Gateway { /** * @var string */ - private $contentType; + protected $contentType; /** * @var array @@ -29,6 +32,11 @@ abstract class Gateway */ public $curlOptions; + /** + * @var $requestLogger IRequestLogger + */ + public $requestLogger; + /** * @param string $contentType * @@ -63,15 +71,14 @@ protected function sendRequest( $verb, $endpoint, $data = null, - array $queryStringParams = null, - $headers = [] + array $queryStringParams = null ) { try { $queryString = $this->buildQueryString($queryStringParams); $request = curl_init($this->serviceUrl . $endpoint . $queryString); - $this->headers = array_merge($this->headers, $headers, [ - 'Content-Type' => sprintf('%s', $this->contentType), + $this->headers = array_merge($this->headers, [ + 'Content-Type' => sprintf('%s; charset=UTF-8', $this->contentType), 'Content-Length' => $data === null ? 0 : strlen($data), ]); @@ -80,6 +87,10 @@ protected function sendRequest( $headers[] = $key . ': '. $value; } + if (isset($this->requestLogger)) { + $this->requestLogger->requestSent($verb, $endpoint, $headers, $queryStringParams, $data); + } + curl_setopt($request, CURLOPT_CONNECTTIMEOUT, $this->timeout); curl_setopt($request, CURLOPT_TIMEOUT, $this->timeout); curl_setopt($request, CURLOPT_RETURNTRANSFER, true); @@ -90,6 +101,7 @@ protected function sendRequest( curl_setopt($request, CURLOPT_HTTPHEADER, $headers); curl_setopt($request, CURLOPT_PROTOCOLS, CURLPROTO_HTTPS); curl_setopt($request, CURLOPT_VERBOSE, false); + curl_setopt($request, CURLOPT_HEADER, true); // Define the constant manually for earlier versions of PHP. // Disable phpcs here since this constant does not exist until PHP 5.5.19. @@ -107,10 +119,18 @@ protected function sendRequest( $curlResponse = curl_exec($request); $curlInfo = curl_getinfo($request); $curlError = curl_errno($request); + $header_size = curl_getinfo($request, CURLINFO_HEADER_SIZE); + $header = substr($curlResponse, 0, $header_size); + $body = substr($curlResponse, $header_size); $response = new GatewayResponse(); $response->statusCode = $curlInfo['http_code']; - $response->rawResponse = $curlResponse; + $response->rawResponse = $body; + $response->header = $header; + + if (isset($this->requestLogger)) { + $this->requestLogger->responseReceived($response); + } return $response; } catch (\Exception $e) { diff --git a/src/Gateways/GatewayResponse.php b/src/Gateways/GatewayResponse.php index f573a660..ac0418d0 100644 --- a/src/Gateways/GatewayResponse.php +++ b/src/Gateways/GatewayResponse.php @@ -13,4 +13,9 @@ class GatewayResponse * @var string */ public $rawResponse; + + /** + * @var string + */ + public $header; } diff --git a/src/Gateways/Gp3DSProvider.php b/src/Gateways/Gp3DSProvider.php index 6369d91b..95a2d700 100644 --- a/src/Gateways/Gp3DSProvider.php +++ b/src/Gateways/Gp3DSProvider.php @@ -87,8 +87,8 @@ public function processSecure3d(Secure3dBuilder $builder) $timestamp = date("Y-m-d\TH:i:s.u"); $paymentMethod = $builder->getPaymentMethod(); $secure3d = $paymentMethod; - $request = []; + if ($transType === TransactionType::VERIFY_ENROLLED) { $request = $this->maybeSetKey($request, 'request_timestamp', $timestamp); $request = $this->maybeSetKey($request, 'merchant_id', $this->merchantId); @@ -109,21 +109,18 @@ public function processSecure3d(Secure3dBuilder $builder) } $hash = GenerationUtils::generateHash($this->sharedSecret, implode('.', [$timestamp, $this->merchantId, $hashValue])); - $headers['Authorization'] = sprintf('securehash %s', $hash); - $headers["X-GP-Version"] = "2.2.0"; - - $rawResponse = $this->doTransaction('POST', 'protocol-versions', json_encode($request), null, $headers); - return $this->mapResponse($rawResponse); + $verb = 'POST'; + $endpoint = 'protocol-versions'; + $queryValues = null; + $request = json_encode($request); } elseif ($transType === TransactionType::VERIFY_SIGNATURE) { $hash = GenerationUtils::generateHash($this->sharedSecret, implode('.', [$timestamp, $this->merchantId, $builder->getServerTransactionId()])); - $headers['Authorization'] = sprintf('securehash %s', $hash); - $headers["X-GP-Version"] = "2.2.0"; - $queryValues = []; $queryValues['merchant_id'] = $this->merchantId; $queryValues['request_timestamp'] = $timestamp; - $rawResponse = $this->doTransaction('GET', sprintf('authentications/%s', $builder->getServerTransactionId()), null, $queryValues, $headers); - return $this->mapResponse($rawResponse); + $verb = 'GET'; + $endpoint = sprintf('authentications/%s', $builder->getServerTransactionId()); + $request = null; } elseif ($transType === TransactionType::INITIATE_AUTHENTICATION) { $orderId = $builder->getOrderId(); if (empty($orderId)) { @@ -333,9 +330,22 @@ public function processSecure3d(Secure3dBuilder $builder) } $hash = GenerationUtils::generateHash($this->sharedSecret, implode('.', [$timestamp, $this->merchantId, $hashValue, $secureEcom->serverTransactionId])); - $headers['Authorization'] = sprintf('securehash %s', $hash); - $headers["X-GP-Version"] = "2.2.0"; - $rawResponse = $this->doTransaction('POST', 'authentications', json_encode($request, JSON_UNESCAPED_SLASHES), null, $headers); + $verb = 'POST'; + $endpoint = 'authentications'; + $queryValues = null; + $request = json_encode($request, JSON_UNESCAPED_SLASHES); + } + + if (!empty($verb) && !empty($endpoint)) { + $this->headers['Authorization'] = sprintf('securehash %s', $hash); + $this->headers["X-GP-Version"] = "2.2.0"; + $rawResponse = $this->doTransaction( + $verb, + $endpoint, + $request, + $queryValues + ); + return $this->mapResponse($rawResponse); } diff --git a/src/Gateways/GpApiConnector.php b/src/Gateways/GpApiConnector.php new file mode 100644 index 00000000..84bc3a65 --- /dev/null +++ b/src/Gateways/GpApiConnector.php @@ -0,0 +1,526 @@ +gpApiConfig = $gpApiConfig; + $this->accessToken = $gpApiConfig->getAccessTokenInfo()->getAccessToken(); + $this->headers['X-GP-VERSION'] = self::GP_API_VERSION; + $this->headers['Authorization'] = $this->accessToken->composeAuthorizationHeader(); + $this->headers['Accept'] = 'application/json'; + $this->headers['Accept-Encoding'] = 'gzip'; + } + + public function getVersion() + { + return Secure3dVersion::ANY; + } + + /** + * Serializes and executes authorization transactions + * + * @param AuthorizationBuilder $builder The transaction's builder + * + * @return Transaction + */ + public function processAuthorization(AuthorizationBuilder $builder) + { + $entryMode = $this->getEntryMode($builder); + $captureMode = $this->getCaptureMode($builder); + + if ($builder->transactionType == TransactionType::SALE || + $builder->transactionType == TransactionType::REFUND || + $builder->transactionType == TransactionType::AUTH) { + + $transaction = CreatePaymentRequest::createFromAuthorizationBuilder( + $builder, + $this->gpApiConfig, + $entryMode, + $captureMode + ); + $response = $this->doTransaction( + "POST", + self::TRANSACTION_ENDPOINT, + $transaction, + null, + $builder->idempotencyKey + ); + } elseif ($builder->transactionType == TransactionType::VERIFY) { + //or in other words, if we need to tokenize + if ($builder->requestMultiUseToken) { + $transaction = CreatePaymentMethodRequest::createFromAuthorizationBuilder( + $builder, + $this->gpApiConfig->getAccessTokenInfo() + ); + $response = $this->doTransaction( + "POST", + self::PAYMENT_METHODS_ENDPOINT, + $transaction, + null, + $builder->idempotencyKey + ); + //otherwise we just retrieve the payment method behind the token + } else { + if ($builder->paymentMethod instanceof ITokenizable && !empty($builder->paymentMethod->token)) { + $response = $this->doTransaction( + "GET", + self::PAYMENT_METHODS_ENDPOINT . '/' . $builder->paymentMethod->token, + null, + null, + $builder->idempotencyKey + ); + } else { + $verificationData = (object)[ + 'account_name' => $this->gpApiConfig->getAccessTokenInfo()->getTransactionProcessingAccountName(), + 'channel' => $this->gpApiConfig->getChannel(), + 'reference' => !empty($builder->clientTransactionId) ? + $builder->clientTransactionId : GenerationUtils::getGuid(), + 'currency' => $builder->currency, + 'country' => !empty($builder->billingAddress) ? + $builder->billingAddress->country : $this->gpApiConfig->getCountry(), + 'payment_method' => CreatePaymentRequest::createPaymentMethodParam($builder, $entryMode) + ]; + + $response = $this->doTransaction( + "POST", + self::VERIFICATIONS_ENDPOINT, + $verificationData, + null, + $builder->idempotencyKey + ); + } + } + } + + return GpApiMapping::mapResponse($response); + } + + public function processSecure3d(Secure3dBuilder $builder) + { + if (empty($this->accessToken)) { + $this->accessToken = $this->gpApiConfig->getAccessTokenInfo()->getAccessToken(); + } + + switch ($builder->transactionType) + { + case TransactionType::VERIFY_ENROLLED: + $data = Authentication3DSRequest::verifyEnrolled($builder, $this->gpApiConfig); + $verb = 'POST'; + $endpoint = self::AUTHENTICATIONS_ENDPOINT; + break; + case TransactionType::INITIATE_AUTHENTICATION: + $data = Authentication3DSRequest::initiateAuthenticationData($builder, $this->gpApiConfig); + $verb = 'POST'; + $endpoint = self::AUTHENTICATIONS_ENDPOINT . "/{$builder->getServerTransactionId()}/initiate"; + break; + case TransactionType::VERIFY_SIGNATURE: + $verb = 'GET'; + $endpoint = self::AUTHENTICATIONS_ENDPOINT . "/{$builder->getServerTransactionId()}/result"; + $data = null; + break; + default: + throw new ApiException("Transaction type not supported!"); + } + + $response = $this->doTransaction( + $verb, + $endpoint, + $data, + null, + $builder->idempotencyKey + ); + + return GpApiMapping::mapResponseSecure3D($response); + } + + /** + * Serializes and executes follow up transactions + * + * @param ManagementBuilder $builder The transaction's builder + * + * @return Transaction + */ + public function manageTransaction(ManagementBuilder $builder) + { + switch ($builder->transactionType) { + case TransactionType::DETOKENIZE: + $requestBody = null; + $endpoint = self::PAYMENT_METHODS_ENDPOINT . '/' . $builder->paymentMethod->token . '/detokenize'; + $verb = 'POST'; + $idempotencyKey = $builder->idempotencyKey; + break; + case TransactionType::TOKEN_DELETE: + $requestBody = null; + $endpoint = self::PAYMENT_METHODS_ENDPOINT . '/' . $builder->paymentMethod->token; + $verb = 'DELETE'; + $idempotencyKey = $builder->idempotencyKey; + break; + case TransactionType::TOKEN_UPDATE: + $requestBody = CreatePaymentMethodRequest::createFromManagementBuilder($builder); + $endpoint = self::PAYMENT_METHODS_ENDPOINT . '/' . $builder->paymentMethod->token; + $verb = 'PATCH'; + $idempotencyKey = $builder->idempotencyKey; + break; + case TransactionType::REFUND: + $requestBody = ManageRefundRequest::createFromManagementBuilder($builder); + $endpoint = self::TRANSACTION_ENDPOINT . '/' . $builder->paymentMethod->transactionId . '/refund'; + $verb = 'POST'; + $idempotencyKey = $builder->idempotencyKey; + break; + case TransactionType::REVERSAL: + $requestBody = ManageReversalRequest::createFromManagementBuilder($builder); + $endpoint = self::TRANSACTION_ENDPOINT . '/' . $builder->paymentMethod->transactionId . '/reversal'; + $verb = 'POST'; + $idempotencyKey = $builder->idempotencyKey; + break; + case TransactionType::CAPTURE: + $requestBody = ManageCaptureRequest::createFromManagementBuilder($builder); + $endpoint = self::TRANSACTION_ENDPOINT . '/' . $builder->paymentMethod->transactionId . '/capture'; + $verb = 'POST'; + $idempotencyKey = $builder->idempotencyKey; + break; + case TransactionType::DISPUTE_ACCEPTANCE: + $requestBody = null; + $endpoint = self::DISPUTES_ENDPOINT . '/' . $builder->disputeId . '/acceptance'; + $verb = 'POST'; + $idempotencyKey = null; + break; + case TransactionType::DISPUTE_CHALLENGE: + $requestBody = (object)['documents' => $builder->disputeDocuments]; + $endpoint = self::DISPUTES_ENDPOINT . '/' . $builder->disputeId . '/challenge'; + $verb = 'POST'; + $idempotencyKey = null; + break; + default: + throw new ApiException("Transaction type not supported!"); + } + + $response = $this->doTransaction( + $verb, + $endpoint, + $requestBody, + null, + $idempotencyKey + ); + + return GpApiMapping::mapResponse($response); + } + + public function processReport(ReportBuilder $builder) + { + switch ($builder->reportType) { + case ReportType::TRANSACTION_DETAIL: + $response = $this->doTransaction( + 'GET', + self::TRANSACTION_ENDPOINT . '/' . $builder->transactionId, + null, + null + ); + break; + case ReportType::FIND_TRANSACTIONS: + $queryString = ReportingFindTransactions::createFromTransactionReportBuilder($builder); + $response = $this->doTransaction( + 'GET', + self::TRANSACTION_ENDPOINT, + null, + $queryString + ); + break; + case ReportType::DEPOSIT_DETAIL: + $response = $this->doTransaction( + 'GET', + self::DEPOSITS_ENDPOINT . '/' . $builder->searchBuilder->depositId, + null, + null + ); + break; + case ReportType::FIND_DEPOSITS: + $queryString = ReportingFindDeposits::createFromTransactionReportBuilder( + $builder, + $this->gpApiConfig->getAccessTokenInfo() + ); + $response = $this->doTransaction( + 'GET', + self::DEPOSITS_ENDPOINT, + null, + $queryString + ); + break; + case ReportType::FIND_DISPUTES: + $queryString = [ + 'page' => $builder->page, + 'page_size' => $builder->pageSize, + 'order_by' => $builder->disputeOrderBy, + 'order' => $builder->disputeOrder, + 'arn' => $builder->searchBuilder->aquirerReferenceNumber, + 'brand' => $builder->searchBuilder->cardBrand, + 'status' => $builder->searchBuilder->disputeStatus, + 'stage' => $builder->searchBuilder->disputeStage, + 'from_stage_time_created' => !empty($builder->searchBuilder->startStageDate) ? + $builder->searchBuilder->startStageDate->format('Y-m-d') : null, + 'to_stage_time_created' => !empty($builder->searchBuilder->endStageDate) ? + $builder->searchBuilder->endStageDate->format('Y-m-d') : null, + 'adjustment_funding' => $builder->searchBuilder->adjustmentFunding, + 'from_adjustment_time_created' => !empty($builder->searchBuilder->startAdjustmentDate) ? + $builder->searchBuilder->startAdjustmentDate->format('Y-m-d') : null, + 'to_adjustment_time_created' => !empty($builder->searchBuilder->endAdjustmentDate) ? + $builder->searchBuilder->endAdjustmentDate->format('Y-m-d') : null, + 'system.mid' => $builder->searchBuilder->merchantId, + 'system.hierarchy' => $builder->searchBuilder->systemHierarchy + ]; + $response = $this->doTransaction( + 'GET', + self::DISPUTES_ENDPOINT, + null, + $queryString + ); + break; + case ReportType::FIND_SETTLEMENT_DISPUTES: + $queryString = [ + 'account_name' => $this->gpApiConfig->getAccessTokenInfo()->getDataAccountName(), + 'page' => $builder->page, + 'page_size' => $builder->pageSize, + 'order_by' => $builder->disputeOrderBy, + 'order' => $builder->disputeOrder, + 'arn' => $builder->searchBuilder->aquirerReferenceNumber, + 'brand' => $builder->searchBuilder->cardBrand, + 'STATUS' => $builder->searchBuilder->disputeStatus, + 'stage' => $builder->searchBuilder->disputeStage, + 'from_stage_time_created' => !empty($builder->searchBuilder->startStageDate) ? + $builder->searchBuilder->startStageDate->format('Y-m-d') : null, + 'to_stage_time_created' => !empty($builder->searchBuilder->endStageDate) ? + $builder->searchBuilder->endStageDate->format('Y-m-d') : null, + 'adjustment_funding' => $builder->searchBuilder->adjustmentFunding, + 'from_adjustment_time_created' => !empty($builder->searchBuilder->startAdjustmentDate) ? + $builder->searchBuilder->startAdjustmentDate->format('Y-m-d') : null, + 'to_adjustment_time_created' => !empty($builder->searchBuilder->endAdjustmentDate) ? + $builder->searchBuilder->endAdjustmentDate->format('Y-m-d') : null, + 'system.mid' => $builder->searchBuilder->merchantId, + 'system.hierarchy' => $builder->searchBuilder->systemHierarchy + ]; + $response = $this->doTransaction( + 'GET', + self::SETTLEMENT_DISPUTES_ENDPOINT, + null, + $queryString + ); + break; + case ReportType::DISPUTE_DETAIL: + $response = $this->doTransaction( + 'GET', + self::DISPUTES_ENDPOINT . '/' . $builder->searchBuilder->disputeId, + null, + null + ); + break; + case ReportType::SETTLEMENT_DISPUTE_DETAIL: + $response = $this->doTransaction( + 'GET', + self::SETTLEMENT_DISPUTES_ENDPOINT . '/' . $builder->searchBuilder->settlementDisputeId, + null, + null + ); + break; + case ReportType::FIND_SETTLEMENT_TRANSACTIONS: + $queryString = ReportingFindSettlementTransactions::createFromTransactionReportBuilder( + $builder, + $this->gpApiConfig->getAccessTokenInfo() + ); + $response = $this->doTransaction( + 'GET', + self::SETTLEMENT_TRANSACTIONS_ENDPOINT, + null, + $queryString + ); + break; + default: + throw new ApiException("Report type not supported!"); + } + + return $this->mapReportResponse($response, $builder->reportType); + } + + public function serializeRequest(AuthorizationBuilder $builder) + { + // TODO: Implement serializeRequest() method. + } + + /** + * @param $response + * @param $reportType ReportType + */ + protected function mapReportResponse($response, $reportType) + { + switch ($reportType) { + case ReportType::TRANSACTION_DETAIL: + $report = GpApiMapping::mapTransactionSummary($response); + break; + case ReportType::FIND_TRANSACTIONS: + case ReportType::FIND_SETTLEMENT_TRANSACTIONS: + $report = array(); + foreach ($response->transactions as $transaction) { + array_push($report, GpApiMapping::mapTransactionSummary($transaction)); + } + break; + case ReportType::DEPOSIT_DETAIL: + $report = GpApiMapping::mapDepositSummary($response); + break; + case ReportType::FIND_DEPOSITS: + $report = array(); + foreach ($response->deposits as $deposit) { + array_push($report, GpApiMapping::mapDepositSummary($deposit)); + } + break; + case ReportType::DISPUTE_DETAIL: + case ReportType::SETTLEMENT_DISPUTE_DETAIL: + $report = new DisputeSummaryList(); + $report->append(GpApiMapping::mapDisputeSummary($response)); + break; + case ReportType::FIND_DISPUTES: + case ReportType::FIND_SETTLEMENT_DISPUTES: + $report = new DisputeSummaryList(); + foreach ($response->disputes as $dispute) { + $report->append(GpApiMapping::mapDisputeSummary($dispute)); + } + break; + default: + throw new ApiException("Report type not supported!"); + } + + return $report; + } + + protected function doTransaction( + $verb, + $endpoint, + $data = null, + array $queryStringParams = null, + string $idempotencyKey = null + ) { + if (empty($this->accessToken)) { + $this->accessToken = $this->gpApiConfig->getAccessTokenInfo()->getAccessToken(); + } + if (!empty($idempotencyKey)) { + $this->headers[self::IDEMPOTENCY_HEADER] = $idempotencyKey; + } + + //weird bug where if you populate the contentType header on this endpoint it throws a 502 bad gateway error + //if you don't send it the error is even weirder, you just have to send it empty + if ( + strpos($endpoint, 'settlement') !== false || + (strpos($endpoint, 'disputes') !== false && strpos($endpoint, 'challenge') == false) + ) { + $this->contentType = ''; + } + + try { + $response = parent::doTransaction( + $verb, + $endpoint, + $data, + $queryStringParams + ); + } catch (GatewayException $exception) { + if ($exception->responseCode == 'NOT_AUTHENTICATED') { + $this->accessToken = $this->gpApiConfig->getAccessTokenInfo()->getAccessToken(); + return parent::doTransaction( + $verb, + $endpoint, + $data, + $queryStringParams + ); + } + + throw $exception; + } finally { + unset($this->headers[self::IDEMPOTENCY_HEADER]); + } + + return json_decode($response); + } + + private function getEntryMode(AuthorizationBuilder $builder) + { + if ($builder->paymentMethod instanceof ICardData) { + if ($builder->paymentMethod->readerPresent) { + return $builder->paymentMethod->cardPresent ? EntryMode::MANUAL : EntryMode::IN_APP; + } else { + return $builder->paymentMethod->cardPresent ? EntryMode::MANUAL : EntryMode::ECOM; + } + } elseif ($builder->paymentMethod instanceof ITrackData) { + if (!empty($builder->tagData)) { + return ($builder->paymentMethod->entryMethod == EntryMode::SWIPE) ? + EntryMode::CHIP : EntryMode::CONTACTLESS_CHIP; + } elseif (!empty($builder->hasEmvFallbackData())) { + return EntryMode::CONTACTLESS_SWIPE; + } else { + return EntryMode::SWIPE; + } + } + + return EntryMode::ECOM; + } + + private function getCaptureMode(AuthorizationBuilder $builder) + { + if ($builder->multiCapture) { + return CaptureMode::MULTIPLE; + } + if ($builder->transactionType == TransactionType::AUTH) { + return CaptureMode::LATER; + } + return CaptureMode::AUTO; + } +} diff --git a/src/Gateways/RestGateway.php b/src/Gateways/RestGateway.php index 58852cc6..e9dd12f8 100644 --- a/src/Gateways/RestGateway.php +++ b/src/Gateways/RestGateway.php @@ -17,30 +17,84 @@ public function __construct() * @param string|null $data * @param array|null $queryStringParams * - * @throws GatewayException * @return string + * @throws GatewayException */ protected function doTransaction( $verb, $endpoint, $data = null, - array $queryStringParams = null, - $headers = [] + array $queryStringParams = null ) { - $response = $this->sendRequest($verb, $endpoint, $data, $queryStringParams, $headers); + if ($this->isGpApi()) { + if (!empty($data)) { + $data = (array) $data; + $this->array_remove_empty($data); + $data = json_encode($data, JSON_UNESCAPED_SLASHES); + } + if (!empty($queryStringParams)){ + $this->array_remove_empty($queryStringParams); + } + } + + $response = $this->sendRequest($verb, $endpoint, $data, $queryStringParams); + if ($this->isGpApi()) { + if (strpos($response->header, 'Content-Encoding: gzip') !== false) { + $response->rawResponse = gzdecode($response->rawResponse); + } + } if (!in_array($response->statusCode, [200, 204])) { $parsed = json_decode($response->rawResponse); $error = isset($parsed->error) ? $parsed->error : $parsed; - throw new GatewayException( - sprintf( - 'Status Code: %s - %s', - $response->statusCode, - isset($error->error_description) ? $error->error_description : (isset($error->message) ? $error->message : (string) $error) - ) - ); + if ($this->isGpApi()) { + $gatewayException = new GatewayException( + sprintf( + 'Status Code: %s - %s', + $error->error_code, + isset($error->detailed_error_description) ? + $error->detailed_error_description : + (isset($error->detailed_error_code) ? $error->detailed_error_code : (string)$error) + ), + (!empty($error->detailed_error_code) ? $error->detailed_error_code : null) + ); + if ($this->requestLogger) { + $this->requestLogger->responseError($gatewayException); + } + throw $gatewayException; + } else { + throw new GatewayException( + sprintf( + 'Status Code: %s - %s', + $response->statusCode, + isset($error->error_description) ? $error->error_description : (isset($error->message) ? $error->message : (string)$error) + ) + ); + } } return $response->rawResponse; } + + private function isGpApi() + { + return isset($this->headers['X-GP-VERSION']); + } + + private function array_remove_empty(&$haystack) + { + foreach ($haystack as $key => $value) { + if (is_array($value) || is_object($value)) { + $v = (array) $haystack[$key]; + $haystack[$key] = $this->array_remove_empty($v); + } + if (empty($haystack[$key])) { + if (is_null($haystack[$key]) || is_array($haystack[$key]) || $haystack[$key] === '') { + unset($haystack[$key]); + } + } + } + + return $haystack; + } } diff --git a/src/Mapping/GpApiMapping.php b/src/Mapping/GpApiMapping.php new file mode 100644 index 00000000..9e5fbbdb --- /dev/null +++ b/src/Mapping/GpApiMapping.php @@ -0,0 +1,289 @@ +transactionId = $response->id; + $transaction->balanceAmount = !empty($response->amount) ? StringUtils::toAmount($response->amount) : null; + $transaction->timestamp = !empty($response->time_created) ? $response->time_created : ''; + $transaction->responseMessage = $response->status; + $transaction->referenceNumber = !empty($response->reference) ? $response->reference : null; + if (!empty($response->batch_id)) { + $batchSummary = new BatchSummary(); + $batchSummary->sequenceNumber = $response->batch_id; + $transaction->batchSummary = $batchSummary; + } + $transaction->responseCode = $response->action->result_code; + $transaction->token = $response->id; + if (!empty($response->payment_method)) { + $transaction->authorizationCode = $response->payment_method->result; + if (!empty($response->payment_method->card)) { + $card = $response->payment_method->card; + $transaction->cardLast4 = !empty($card->masked_number_last4) ? + $card->masked_number_last4 : null; + $transaction->cardType = !empty($card->brand) ? $card->brand : null; + } + } + if (!empty($response->card)) { + $transaction->cardNumber = !empty($response->card->number) ? $response->card->number : null; + $transaction->cardType = !empty($response->card->brand) ? $response->card->brand : ''; + $transaction->cardExpMonth = $response->card->expiry_month; + $transaction->cardExpYear = $response->card->expiry_year; + } + } + + return $transaction; + } + + /** + * @param $response + * @return TransactionSummary + * @throws \Exception + */ + public static function mapTransactionSummary($response) + { + $summary = new TransactionSummary(); + + $summary->transactionId = isset($response->id) ? $response->id : null; + $summary->transactionDate = new \DateTime($response->time_created); + $summary->transactionStatus = $response->status; + $summary->transactionType = $response->type; + $summary->channel = !empty($response->channel) ? $response->channel : null; + $summary->amount = StringUtils::toAmount($response->amount); + $summary->currency = $response->currency; + $summary->referenceNumber = $response->reference; + $summary->clientTransactionId = $response->reference; + // $summary->unknown = $response->time_created_reference; + $summary->batchSequenceNumber = $response->batch_id; + $summary->country = !empty($response->country) ? $response->country : null; + // $summary->unknown = $response->action_create_id; + $summary->originalTransactionId = !empty($response->parent_resource_id) ? $response->parent_resource_id : null; + $summary->depositId = !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) : ''; + $summary->batchCloseDate = !empty($response->batch_time_created) ? new \DateTime($response->batch_time_created) : ''; + if (isset($response->system)) { + $system = $response->system; + $summary->merchantId = $system->mid; + $summary->merchantHierarchy = $system->hierarchy; + $summary->merchantName = $system->name; + $summary->merchantDbaName = $system->dba; + } + if (isset($response->payment_method)) { + $paymentMethod = $response->payment_method; + $summary->gatewayResponseMessage = isset($paymentMethod->message) ? $paymentMethod->message : null; + $summary->entryMode = isset($paymentMethod->entry_mode) ? $paymentMethod->entry_mode : null; + $summary->cardHolderName = isset($paymentMethod->name) ? $paymentMethod->name : ''; + if (isset($response->payment_method->card)) { + $card = $response->payment_method->card; + $summary->aquirerReferenceNumber = isset($card->arn) ? $card->arn : null; + $summary->maskedCardNumber = isset($card->masked_number_first6last4) ? + $card->masked_number_first6last4 : null; + } elseif (isset($response->payment_method->digital_wallet)) { + $card = $response->payment_method->digital_wallet; + $summary->maskedCardNumber = isset($card->masked_token_first6last4) ? + $card->masked_token_first6last4 : null; + } + if (!empty($card)) { + $summary->cardType = isset($card->brand) ? $card->brand : null; + $summary->authCode = isset($card->authcode) ? $card->authcode : null; + $summary->brandReference = isset($card->brand_reference) ? $card->brand_reference : null; + } + } + + return $summary; + } + + /** + * @param Object $response + * + * @return DepositSummary + */ + public static function mapDepositSummary($response) + { + $summary = new DepositSummary(); + $summary->depositId = $response->id; + $summary->depositDate = new \DateTime($response->time_created); + $summary->status = $response->status; + $summary->type = $response->funding_type; + $summary->amount = StringUtils::toAmount($response->amount); + $summary->currency = $response->currency; + + if (isset($response->system)) { + $system = $response->system; + $summary->merchantNumber = $system->mid; + $summary->merchantHierarchy = $system->hierarchy; + $summary->merchantName = $system->name; + $summary->merchantDbaName = $system->dba; + } + + if (isset($response->sales)) { + $sales = $response->sales; + $summary->salesTotalCount = isset($sales->count) ? $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->refundsTotalAmount = isset($refunds->amount) ? StringUtils::toAmount($refunds->amount) : 0; + } + + if (isset($response->disputes)) { + $disputes = $response->disputes; + $summary->chargebackTotalCount = isset($disputes->chargebacks->count) ? $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->adjustmentTotalAmount = isset($disputes->reversals->amount) ? + StringUtils::toAmount($disputes->reversals->amount) : 0; + } + + $summary->feesTotalAmount = isset($response->fees->amount) ? StringUtils::toAmount($response->fees->amount) : 0; + + return $summary; + } + + /** + * @param Object $response + * + * @return DisputeSummary + */ + public static function mapDisputeSummary($response) + { + $summary = new DisputeSummary(); + $summary->caseId = $response->id; + $summary->caseIdTime = !empty($response->stage_time_created) ? new \DateTime($response->stage_time_created) : ''; + $summary->caseStatus = $response->status; + $summary->caseStage = $response->stage; + $summary->caseAmount = StringUtils::toAmount($response->amount); + $summary->caseCurrency = $response->currency; + if (isset($response->system)) { + $system = $response->system; + $summary->caseMerchantId = $system->mid; + $summary->merchantHierarchy = $system->hierarchy; + } + if ( + isset($response->payment_method) && + isset($response->payment_method->card) + ) { + $card = $response->payment_method->card; + $summary->transactionMaskedCardNumber = $card->number; + } + if ( + isset($response->transaction->payment_method) && + isset($response->transaction->payment_method->card) + ) { + $card = $response->transaction->payment_method->card; + $summary->transactionMaskedCardNumber = !empty($card->masked_number_first6last4) ? + $card->masked_number_first6last4 : ''; + } + if (!empty($card)) { + $summary->transactionARN = $card->arn; + $summary->transactionCardType = $card->brand; + } + $summary->reasonCode = $response->reason_code; + $summary->reason = $response->reason_description; + $summary->respondByDate = new \DateTime($response->time_to_respond_by); + $summary->result = $response->result; + $summary->lastAdjustmentAmount = StringUtils::toAmount($response->last_adjustment_amount); + $summary->lastAdjustmentCurrency = $response->last_adjustment_currency; + $summary->lastAdjustmentFunding = $response->last_adjustment_funding; + + return $summary; + } + + /** + * @param Object $response + */ + public static function mapResponseSecure3D($response) + { + $transaction = new Transaction(); + $threeDSecure = new ThreeDSecure(); + //@TODO: Complete required mappings + $threeDSecure->serverTransactionId = !empty($response->id) ? $response->id : + (!empty($response->three_ds->server_trans_ref) ? $response->three_ds->server_trans_ref : ''); + 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; + } + $threeDSecure->messageVersion = $messageVersion; + $threeDSecure->setVersion($version); + } + + $threeDSecure->directoryServerStartVersion = !empty($response->three_ds->ds_protocol_version_start) ? + $response->three_ds->ds_protocol_version_start : ''; + $threeDSecure->directoryServerEndVersion = !empty($response->three_ds->ds_protocol_version_end) ? + $response->three_ds->ds_protocol_version_end : ''; + $threeDSecure->acsStartVersion = !empty($response->three_ds->acs_protocol_version_start) ? + $response->three_ds->acs_protocol_version_start : ''; + $threeDSecure->acsEndVersion = !empty($response->three_ds->acs_protocol_version_end) ? + $response->three_ds->acs_protocol_version_end : ''; + $threeDSecure->enrolled = !empty($response->three_ds->enrolled_status) ? + $response->three_ds->enrolled_status : ''; + $threeDSecure->eci = !empty($response->three_ds->eci) ? $response->three_ds->eci : ''; + $threeDSecure->acsInfoIndicator = !empty($response->three_ds->acs_info_indicator) ? + $response->three_ds->acs_info_indicator : null; + $threeDSecure->challengeMandated = !empty($response->three_ds->challenge_status) ? + ($response->three_ds->challenge_status == 'MANDATED') : false; + $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 : ''; + $threeDSecure->challengeValue = !empty($response->three_ds->challenge_value) ? + $response->three_ds->challenge_value : ''; + if (!empty($response->three_ds->redirect_url) && $threeDSecure->challengeMandated === true) { + $threeDSecure->issuerAcsUrl = !empty($response->three_ds->redirect_url) ? + $response->three_ds->redirect_url : null; + $threeDSecure->payerAuthenticationRequest = !empty($response->three_ds->challenge_value) ? + $response->three_ds->challenge_value : ''; + } + $threeDSecure->setCurrency($response->currency); + $threeDSecure->setAmount(StringUtils::toAmount($response->amount)); + $threeDSecure->status = $response->status; + $threeDSecure->authenticationValue = !empty($response->three_ds->authenticationValue) ? + $response->three_ds->authenticationValue : ''; + $threeDSecure->directoryServerTransactionId = !empty($response->three_ds->ds_trans_ref) ? + $response->three_ds->ds_trans_ref : ''; + $threeDSecure->acsTransactionId = !empty($response->three_ds->acs_trans_ref) ? + $response->three_ds->acs_trans_ref : ''; + $threeDSecure->statusReason = !empty($response->three_ds->status_reason) ? + $response->three_ds->status_reason : ''; + $threeDSecure->messageCategory = !empty($response->three_ds->message_category) ? + $response->three_ds->message_category : ''; + + $transaction->threeDSecure = $threeDSecure; + + return $transaction; + } +} \ No newline at end of file diff --git a/src/PaymentMethods/Credit.php b/src/PaymentMethods/Credit.php index 342fd263..3a868fbd 100644 --- a/src/PaymentMethods/Credit.php +++ b/src/PaymentMethods/Credit.php @@ -17,6 +17,7 @@ use GlobalPayments\Api\PaymentMethods\Interfaces\IPrePayable; use GlobalPayments\Api\PaymentMethods\Interfaces\IRefundable; use GlobalPayments\Api\PaymentMethods\Interfaces\IReversable; +use GlobalPayments\Api\PaymentMethods\Interfaces\ISecure3d; use GlobalPayments\Api\PaymentMethods\Interfaces\ITokenizable; use GlobalPayments\Api\PaymentMethods\Interfaces\IVerifyable; @@ -30,7 +31,8 @@ abstract class Credit implements IReversable, IVerifyable, IPrePayable, - IBalanceable + IBalanceable, + ISecure3d { public $encryptionData; public $paymentMethodType = PaymentMethodType::CREDIT; @@ -170,21 +172,44 @@ public function tokenize() ->withRequestMultiUseToken(true); } + /** + * Tokenizes with idempotencyKey the payment method + * + * @param string $idempotencyKey + * + * @return AuthorizationBuilder + */ + public function tokenizeWithIdempotencyKey($idempotencyKey) + { + return $this->verify() + ->withRequestMultiUseToken(true) + ->withIdempotencyKey($idempotencyKey); + } + /** * Updates the token expiry date with the values proced to the card object * * @return bool value indicating success/failure */ public function updateTokenExpiry() + { + return $this->updateTokenExpiryWithIdemPotencyKey(null); + } + + public function updateTokenExpiryWithIdemPotencyKey($idemPotencyKey) { if (empty($this->token)) { throw new BuilderException('Token cannot be null'); } try { - (new ManagementBuilder(TransactionType::TOKEN_UPDATE)) - ->withPaymentMethod($this) - ->execute(); + $mb = (new ManagementBuilder(TransactionType::TOKEN_UPDATE)) + ->withPaymentMethod($this); + if (!empty($idemPotencyKey)) { + $mb->withIdempotencyKey($idemPotencyKey); + } + $mb->execute(); + return true; } catch (ApiException $exc) { return false; @@ -197,15 +222,32 @@ public function updateTokenExpiry() * @return bool value indicating success/failure */ public function deleteToken() + { + return $this->deleteTokenWithIdempotencyKey(null); + } + + /** + * Deletes the token associated with the current card object + * + * @param string $idempotencyKey + * + * @return bool + * @throws BuilderException + */ + public function deleteTokenWithIdempotencyKey($idempotencyKey) { if (empty($this->token)) { throw new BuilderException('Token cannot be null'); } try { - (new ManagementBuilder(TransactionType::TOKEN_DELETE)) - ->withPaymentMethod($this) - ->execute(); + $mb = (new ManagementBuilder(TransactionType::TOKEN_DELETE)) + ->withPaymentMethod($this); + if (!empty($idempotencyKey)) { + $mb->withIdempotencyKey($idempotencyKey); + } + $mb->execute(); + return true; } catch (ApiException $exc) { return false; @@ -223,4 +265,21 @@ public function getDccRate($dccRateType, $amount, $currency, $ccp, $orderId) ->withOrderId($orderId) ->execute(); } + + public function detokenize() + { + return $this->detokenizeWithIdempotencyKey(null); + } + + public function detokenizeWithIdempotencyKey($idempotencyKey) + { + if (empty($this->token)) { + throw new BuilderException("Token cannot be null or empty"); + } + $mb = (new ManagementBuilder(TransactionType::DETOKENIZE, $this)); + if (!empty($idempotencyKey)) { + $mb->withIdempotencyKey($idempotencyKey); + } + return $mb->execute(); + } } diff --git a/src/PaymentMethods/CreditTrackData.php b/src/PaymentMethods/CreditTrackData.php index 395d8472..d72d79a4 100644 --- a/src/PaymentMethods/CreditTrackData.php +++ b/src/PaymentMethods/CreditTrackData.php @@ -7,7 +7,6 @@ class CreditTrackData extends Credit implements ITrackData { - public $entryMethod; public $value; public $discretionaryData; @@ -17,6 +16,15 @@ class CreditTrackData extends Credit implements ITrackData public $trackNumber; public $trackData; + public function setTrackData($value) + { + if (empty($this->value)) { + $this->setValue($value); + } else { + $this->trackData = $value; + } + } + public function setValue($value) { $this->value = $value; diff --git a/src/PaymentMethods/Debit.php b/src/PaymentMethods/Debit.php index 14d4bdec..d83b4997 100644 --- a/src/PaymentMethods/Debit.php +++ b/src/PaymentMethods/Debit.php @@ -25,6 +25,7 @@ abstract class Debit implements public $encryptionData; public $paymentMethodType = PaymentMethodType::DEBIT; public $pinBlock; + public $cardType = 'Unknown'; /** * Adds value to the payment method diff --git a/src/PaymentMethods/DebitTrackData.php b/src/PaymentMethods/DebitTrackData.php index e49bc447..a2bc1833 100644 --- a/src/PaymentMethods/DebitTrackData.php +++ b/src/PaymentMethods/DebitTrackData.php @@ -16,6 +16,15 @@ class DebitTrackData extends Debit implements ITrackData public $trackNumber; public $trackData; + public function setTrackData($value) + { + if (empty($this->value)) { + $this->setValue($value); + } else { + $this->trackData = $value; + } + } + public function setValue($value) { $this->value = $value; diff --git a/src/PaymentMethods/EBT.php b/src/PaymentMethods/EBT.php index fea5d432..27169ae0 100644 --- a/src/PaymentMethods/EBT.php +++ b/src/PaymentMethods/EBT.php @@ -3,6 +3,7 @@ namespace GlobalPayments\Api\PaymentMethods; use GlobalPayments\Api\Builders\AuthorizationBuilder; +use GlobalPayments\Api\Entities\Enums\EbtCardType; use GlobalPayments\Api\Entities\Enums\InquiryType; use GlobalPayments\Api\Entities\Enums\PaymentMethodType; use GlobalPayments\Api\Entities\Enums\TransactionType; @@ -29,6 +30,11 @@ abstract class EBT implements public $paymentMethodType = PaymentMethodType::EBT; public $pinBlock; + /** + * @var EbtCardType $ebtCardType + */ + public $ebtCardType; + /** * Adds value to the payment method * diff --git a/src/PaymentMethods/EBTTrackData.php b/src/PaymentMethods/EBTTrackData.php index 266c753d..641b0fcd 100644 --- a/src/PaymentMethods/EBTTrackData.php +++ b/src/PaymentMethods/EBTTrackData.php @@ -2,12 +2,29 @@ namespace GlobalPayments\Api\PaymentMethods; +use GlobalPayments\Api\Entities\EncryptionData; +use GlobalPayments\Api\Entities\Enums\EntryMethod; +use GlobalPayments\Api\Entities\Enums\TrackNumber; use GlobalPayments\Api\PaymentMethods\Interfaces\IEncryptable; use GlobalPayments\Api\PaymentMethods\Interfaces\ITrackData; class EBTTrackData extends EBT implements ITrackData, IEncryptable { + public $discretionaryData; + /** + * @var EncryptionData $encryptionData + */ public $encryptionData; + /** + * @var EntryMethod $entryMethod + */ public $entryMethod; public $value; + public $expire; + public $pan; + public $purchaseDeviceSequenceNumber; + /** + * @var TrackNumber $trackNumber + */ + public $trackNumber; } diff --git a/src/PaymentMethods/Interfaces/ITokenizable.php b/src/PaymentMethods/Interfaces/ITokenizable.php index 26de0eda..e5db6fd6 100644 --- a/src/PaymentMethods/Interfaces/ITokenizable.php +++ b/src/PaymentMethods/Interfaces/ITokenizable.php @@ -7,4 +7,5 @@ interface ITokenizable public function tokenize(); public function updateTokenExpiry(); public function deleteToken(); + public function detokenize(); } diff --git a/src/PaymentMethods/TransactionReference.php b/src/PaymentMethods/TransactionReference.php index a8a4af63..6258454e 100644 --- a/src/PaymentMethods/TransactionReference.php +++ b/src/PaymentMethods/TransactionReference.php @@ -2,6 +2,7 @@ namespace GlobalPayments\Api\PaymentMethods; +use GlobalPayments\Api\Entities\Enums\PaymentMethodType; use GlobalPayments\Api\PaymentMethods\Interfaces\IPaymentMethod; class TransactionReference implements IPaymentMethod diff --git a/src/ServiceConfigs/Gateways/GpApiConfig.php b/src/ServiceConfigs/Gateways/GpApiConfig.php new file mode 100644 index 00000000..bdbcd6ac --- /dev/null +++ b/src/ServiceConfigs/Gateways/GpApiConfig.php @@ -0,0 +1,192 @@ +gatewayProvider = GatewayProvider::GP_API; + } + + public function configureContainer(ConfiguredServices $services) + { + // TODO: Implement configureContainer() method. + if (empty($this->serviceUrl)) { + $this->serviceUrl = ($this->environment == Environment::PRODUCTION) ? + ServiceEndpoints::GP_API_PRODUCTION : ServiceEndpoints::GP_API_TEST; + } + $this->accessTokenInfo->initialize($this); + $gateway = new GpApiConnector($this); + $gateway->serviceUrl = $this->serviceUrl; + + if (isset($this->requestLogger)) { + $gateway->requestLogger = $this->requestLogger; + } + + $services->gatewayConnector = $gateway; + + $services->reportingService = $gateway; + + $services->setSecure3dProvider(Secure3dVersion::ONE, $gateway); + $services->setSecure3dProvider(Secure3dVersion::TWO, $gateway); + } + + public function validate() + { + parent::validate(); // TODO: Change the autogenerated stub + if (empty($this->appId)) { + throw new ConfigurationException('AppId is required for this configuration'); + } + if (empty($this->appKey)) { + throw new ConfigurationException('AppKey is required for this configuration'); + } + if (empty($this->accessTokenInfo)) { + throw new ConfigurationException( + 'An Access Token Info instance is required for this configuration' + ); + } + } + + public function getAppId() + { + return $this->appId; + } + + public function getAppKey() + { + return $this->appKey; + } + public function getAccessTokenInfo() + { + return $this->accessTokenInfo; + } + + public function getChannel() + { + return $this->channel; + } + + public function getCountry() + { + return $this->country; + } + + public function getSecondsToExpire() + { + return $this->secondsToExpire; + } + public function getIntervalToExpire() + { + return $this->intervalToExpire; + } + + public function getChallengeNotificationUrl() + { + return $this->challengeNotificationUrl; + } + + public function getMethodNotificationUrl() + { + return $this->methodNotificationUrl; + } + + public function setAppId($appId) + { + $this->appId = $appId; + } + + public function setAppKey($appKey) + { + $this->appKey = $appKey; + } + + public function setAccessTokenInfo($accessTokenInfo) + { + $this->accessTokenInfo = $accessTokenInfo; + } + + public function setChannel($channel) + { + $this->channel = $channel; + } + + public function setCountry($country) + { + $this->country = $country; + } + + public function setSecondsToExpire($value) + { + $this->secondsToExpire = $value; + } + + public function setIntervalToExpire($value) + { + $this->intervalToExpire = $value; + } + + public function setChallengeNotificationUrl($value) + { + $this->challengeNotificationUrl = $value; + } + + public function setMethodNotificationUrl($value) + { + $this->methodNotificationUrl = $value; + } +} \ No newline at end of file diff --git a/src/ServiceConfigs/Gateways/TransitConfig.php b/src/ServiceConfigs/Gateways/TransitConfig.php index c0fcebd5..d43925cd 100644 --- a/src/ServiceConfigs/Gateways/TransitConfig.php +++ b/src/ServiceConfigs/Gateways/TransitConfig.php @@ -1,67 +1,67 @@ -gatewayProvider = GatewayProvider::TRANSIT; - } - - public function configureContainer(ConfiguredServices $services) - { - $gateway = new TransITConnector(); - $gateway->deviceId = $this->deviceId; - $gateway->developerId = $this->developerId; - $gateway->timeout = $this->timeout; - $gateway->serviceUrl = $this->serviceUrl; - $gateway->requestLogger = $this->requestLogger; - $gateway->acceptorConfig = $this->acceptorConfig; - $gateway->merchantId = $this->merchantId; - $gateway->transactionKey = $this->transactionKey; - $gateway->userId = $this->username; - $gateway->password = $this->password; - - if (empty($this->serviceUrl)) { - $gateway->serviceUrl = $this->environment == Environment::TEST ? ServiceEndpoints::TRANSIT_TEST : ServiceEndpoints::TRANSIT_PRODUCTION; - } - - $services->gatewayConnector = $gateway; - } - - public function validate() - { - parent::validate(); - - if ($this->acceptorConfig == null) { - throw new ConfigurationException("You must provide a valid AcceptorConfig."); - } else { - $this->acceptorConfig->validate(); - } - - if (empty($this->deviceId)) { - throw new ConfigurationException("DeviceId cannot be null."); - } - - if (empty($this->merchantId)) { - throw new ConfigurationException("MerchantId cannot be null."); - } - } -} +gatewayProvider = GatewayProvider::TRANSIT; + } + + public function configureContainer(ConfiguredServices $services) + { + $gateway = new TransITConnector(); + $gateway->deviceId = $this->deviceId; + $gateway->developerId = $this->developerId; + $gateway->timeout = $this->timeout; + $gateway->serviceUrl = $this->serviceUrl; + $gateway->requestLogger = $this->requestLogger; + $gateway->acceptorConfig = $this->acceptorConfig; + $gateway->merchantId = $this->merchantId; + $gateway->transactionKey = $this->transactionKey; + $gateway->userId = $this->username; + $gateway->password = $this->password; + + if (empty($this->serviceUrl)) { + $gateway->serviceUrl = $this->environment == Environment::TEST ? ServiceEndpoints::TRANSIT_TEST : ServiceEndpoints::TRANSIT_PRODUCTION; + } + + $services->gatewayConnector = $gateway; + } + + public function validate() + { + parent::validate(); + + if ($this->acceptorConfig == null) { + throw new ConfigurationException("You must provide a valid AcceptorConfig."); + } else { + $this->acceptorConfig->validate(); + } + + if (empty($this->deviceId)) { + throw new ConfigurationException("DeviceId cannot be null."); + } + + if (empty($this->merchantId)) { + throw new ConfigurationException("MerchantId cannot be null."); + } + } +} diff --git a/src/Services/GpApiService.php b/src/Services/GpApiService.php new file mode 100644 index 00000000..8c90cb13 --- /dev/null +++ b/src/Services/GpApiService.php @@ -0,0 +1,37 @@ +setAppId($appId); + $config->setAppKey($appKey); + $config->setSecondsToExpire($secondsToExpire); + $config->setIntervalToExpire($intervalToExpire); + $config->environment = $environment; + $config->serviceUrl = ($environment == Environment::PRODUCTION) ? ServiceEndpoints::GP_API_PRODUCTION : + ServiceEndpoints::GP_API_TEST; + $config->timeout = 10000; + $accessTokenManager = new AccessTokenInfo(); + $accessTokenManager->initialize($config); + $config->setAccessTokenInfo($accessTokenManager); + $gateway = new GpApiConnector($config); + + return $accessTokenManager; + } +} \ No newline at end of file diff --git a/src/Services/ReportingService.php b/src/Services/ReportingService.php index eea10a71..52ff1dad 100644 --- a/src/Services/ReportingService.php +++ b/src/Services/ReportingService.php @@ -16,16 +16,57 @@ public static function findTransactions($transactionId = null) return $response; } + public static function findDeposits() + { + $response = new TransactionReportBuilder(ReportType::FIND_DEPOSITS); + return $response; + } + + public static function findSettlementTransactions() + { + $response = new TransactionReportBuilder(ReportType::FIND_SETTLEMENT_TRANSACTIONS); + return $response; + } + public static function activity() { $response = (new TransactionReportBuilder(ReportType::ACTIVITY)); return $response; } - + public static function transactionDetail($transactionId) { $response = (new TransactionReportBuilder(ReportType::TRANSACTION_DETAIL)) ->withTransactionId($transactionId); return $response; } + + public static function depositDetail($depositId) + { + $response = (new TransactionReportBuilder(ReportType::DEPOSIT_DETAIL)) + ->withDepositId($depositId); + return $response; + } + + public static function findDisputes() + { + return new TransactionReportBuilder(ReportType::FIND_DISPUTES); + } + + public static function disputeDetail($disputeId) + { + return (new TransactionReportBuilder(ReportType::DISPUTE_DETAIL)) + ->withDisputeId($disputeId); + } + + public static function findSettlementDisputes() + { + return new TransactionReportBuilder(ReportType::FIND_SETTLEMENT_DISPUTES); + } + + public static function settlementDisputeDetail($settlementDisputeId) + { + return (new TransactionReportBuilder(ReportType::SETTLEMENT_DISPUTE_DETAIL)) + ->withSettlementDisputeId($settlementDisputeId); + } } diff --git a/src/Utils/AccessTokenInfo.php b/src/Utils/AccessTokenInfo.php new file mode 100644 index 00000000..3bc35558 --- /dev/null +++ b/src/Utils/AccessTokenInfo.php @@ -0,0 +1,193 @@ +headers = [ + 'X-GP-VERSION' => GpApiConnector::GP_API_VERSION, + 'Accept' => 'application/json', + 'Accept-Encoding' => 'gzip' + ]; + $endPoint = $this->servicePoint . GpApiConnector::ACCESS_TOKEN_ENDPOINT; + $requestBody = new AccessTokenRequest( + $this->appId, + $this->generateNonce(), + $this->generateSecret(), + 'client_credentials', + $this->secondsToExpire, + $this->intervalToExpire + ); + + $request = $this->doTransaction("POST", $endPoint, $requestBody, null); + $this->accessToken = new AccessToken( + $request->token, + $request->type, + $request->time_created, + $request->seconds_to_expire + ); + foreach ($request->scope->accounts as $account) { + switch (substr($account->id, 0, 4)) { + case self::DATA_ACCOUNT_NAME_PREFIX: + $this->dataAccountName = $account->name; + break; + case self::DISPUTE_MANAGEMENT_ACCOUNT_NAME_PREFIX: + $this->disputeManagementAccountName = $account->name; + break; + case self::TOKENIZATION_ACCOUNT_NAME_PREFIX: + $this->tokenizationAccountName = $account->name; + break; + case self::TRANSACTION_PROCESSING_ACCOUNT_NAME_PREFIX: + $this->transactionProcessingAccountName = $account->name; + break; + } + + } + return $this->accessToken; + } + + public function getAccessToken() + { + if (empty($this->accessToken) || ($this->accessToken->seconds_to_expire < 100)) { + $this->generateAccessToken(); + } + return $this->accessToken; + } + + public function setAccessToken(AccessToken $accessToken) + { + $this->accessToken = $accessToken; + return $this; + } + + public function initialize(GpApiConfig $servicesConfig) + { + $this->appId = $servicesConfig->getAppId(); + $this->appKey = $servicesConfig->getAppKey(); + $this->servicePoint = $servicesConfig->serviceUrl; + $this->secondsToExpire = $servicesConfig->getSecondsToExpire(); + $this->intervalToExpire = $servicesConfig->getIntervalToExpire(); + } + + public function getDataAccountName() + { + if (empty($this->dataAccountName)) { + $this->generateAccessToken(); + } + return $this->dataAccountName; + } + + public function getDisputeManagementAccountName() + { + if (empty($this->disputeManagementAccountName)) { + $this->generateAccessToken(); + } + return $this->disputeManagementAccountName; + } + + public function getTokenizationAccountName() + { + if (empty($this->tokenizationAccountName)) { + $this->generateAccessToken(); + } + return $this->tokenizationAccountName; + } + + public function getTransactionProcessingAccountName() + { + if (empty($this->transactionProcessingAccountName)) { + $this->generateAccessToken(); + } + return $this->transactionProcessingAccountName; + } + + /** + * @param mixed $dataAccountName + */ + public function setDataAccountName($dataAccountName) + { + $this->dataAccountName = $dataAccountName; + } + + /** + * @param mixed $disputeManagementAccountName + */ + public function setDisputeManagementAccountName($disputeManagementAccountName) + { + $this->disputeManagementAccountName = $disputeManagementAccountName; + } + + /** + * @param mixed $tokenizationAccountName + */ + public function setTokenizationAccountName($tokenizationAccountName) + { + $this->tokenizationAccountName = $tokenizationAccountName; + } + + /** + * @param mixed $transactionProcessingAccountName + */ + public function setTransactionProcessingAccountName($transactionProcessingAccountName) + { + $this->transactionProcessingAccountName = $transactionProcessingAccountName; + } + + private function generateSecret() + { + return hash('SHA512', $this->generateNonce() . $this->appKey); + } + + private function generateNonce() + { + $base = new \DateTime(); + return $base->format(\DateTime::RFC3339); + } + + protected function doTransaction( + $verb, + $endpoint, + $data = null, + array $queryStringParams = null + ) { + $response = parent::doTransaction($verb, $endpoint, $data, $queryStringParams); + return json_decode($response); + } +} \ No newline at end of file diff --git a/src/Utils/AmountUtils.php b/src/Utils/AmountUtils.php index ece5be17..3ce62e8a 100644 --- a/src/Utils/AmountUtils.php +++ b/src/Utils/AmountUtils.php @@ -14,6 +14,6 @@ class AmountUtils */ public static function transitFormat($amount) { - return number_format($amount, 2); + return number_format($amount, 2, '.', ''); } } diff --git a/src/Utils/CardUtils.php b/src/Utils/CardUtils.php index 6f40d05d..7deb00f0 100644 --- a/src/Utils/CardUtils.php +++ b/src/Utils/CardUtils.php @@ -2,7 +2,19 @@ namespace GlobalPayments\Api\Utils; +use GlobalPayments\Api\Builders\AuthorizationBuilder; +use GlobalPayments\Api\Builders\ManagementBuilder; +use GlobalPayments\Api\Entities\Enums\CvnPresenceIndicator; +use GlobalPayments\Api\Entities\Enums\EmvLastChipRead; +use GlobalPayments\Api\Entities\Enums\PaymentMethodType; +use GlobalPayments\Api\Entities\Enums\Target; use GlobalPayments\Api\Entities\Enums\TrackNumber; +use GlobalPayments\Api\Entities\Enums\TransactionType; +use GlobalPayments\Api\Entities\GpApi\DTO\Card; +use GlobalPayments\Api\PaymentMethods\Interfaces\ICardData; +use GlobalPayments\Api\PaymentMethods\Interfaces\IPinProtected; +use GlobalPayments\Api\PaymentMethods\Interfaces\ITrackData; +use Zend\Filter\Compress\Tar; class CardUtils { @@ -84,6 +96,7 @@ public static function parseTrackData($paymentMethod) $paymentMethod->trackData = str_replace('%', '', $matches[0]); } } + return $paymentMethod; } @@ -133,4 +146,82 @@ public static function isFleet($cardType, $pan) } return false; } + + /** + * Generate a card + * + * @param AuthorizationBuilder|ManagementBuilder $builder + * + * @return Card + */ + public static function generateCard($builder) + { + $paymentMethod = $builder->paymentMethod; + $transactionType = $builder->transactionType; + $funding = ($paymentMethod->paymentMethodType == PaymentMethodType::DEBIT) ? 'DEBIT' : 'CREDIT'; + $card = new Card(); + if ($paymentMethod instanceof ITrackData) { + $card->setTrack($paymentMethod->value); + if ($transactionType == TransactionType::SALE) { + if (empty($paymentMethod->value)) { + $card->setNumber($paymentMethod->pan); + if (!empty($paymentMethod->expiry)) { + $card->setExpireMonth(substr($paymentMethod->expiry, 2, 2)); + $card->setExpireYear(substr($paymentMethod->expiry, 0, 2)); + } + } + if (!empty($builder->emvChipCondition)) { + $card->setChipCondition(EmvLastChipRead::$emvLastChipRead[$builder->emvChipCondition][Target::GP_API]); + } + $card->setFunding($funding) ; + } + } elseif ($paymentMethod instanceof ICardData) { + $card->setNumber($paymentMethod->number); + $card->setExpireMonth(str_pad($paymentMethod->expMonth, 2, '0', STR_PAD_LEFT)); + $card->setExpireYear(substr(str_pad($paymentMethod->expYear, 4, '0', STR_PAD_LEFT), 2, 2)); + if (!empty($paymentMethod->cvn)) { + $card->setCvv($paymentMethod->cvn); + $cvnPresenceIndicator = !empty($paymentMethod->cvn) ? CvnPresenceIndicator::PRESENT : + (!empty($paymentMethod->cvnPresenceIndicator) ? $paymentMethod->cvnPresenceIndicator : ''); + $card->setCvvIndicator(self::getCvvIndicator($cvnPresenceIndicator)); + } + $card->setFunding($funding); + //we can't have tag and chip_condition in the same time in the request + if (!empty($builder->emvLastChipRead) && empty($builder->tagData)) { + $card->setChipCondition(EmvLastChipRead::$emvLastChipRead[$builder->emvLastChipRead][Target::GP_API]); + } + } + + $billingAddress = !empty($builder->billingAddress) ? $builder->billingAddress->streetAddress1 : ''; + $postalCode = !empty($builder->billingAddress) ? $builder->billingAddress->postalCode : ''; + $card->setTag($builder->tagData); + $card->setAvsAddress($billingAddress); + $card->setAvsPostalCode($postalCode); + $card->setAuthCode($builder->offlineAuthCode); + if ($paymentMethod instanceof IPinProtected) { + $card->setPinBlock($paymentMethod->pinBlock); + } + + return GenerationUtils::convertObjectToArray($card); + } + + public static function getCvvIndicator($cvnPresenceIndicator) + { + switch ($cvnPresenceIndicator) { + case 1: + $cvvIndicator = 'PRESENT'; + break; + case 2: + $cvvIndicator = 'ILLEGIBLE'; + break; + case 3: + $cvvIndicator = 'NOT_ON_CARD'; + break; + default: + $cvvIndicator = 'NOT_PRESENT'; + break; + } + + return $cvvIndicator; + } } diff --git a/src/Utils/GenerationUtils.php b/src/Utils/GenerationUtils.php index 29e19cc2..a34623e1 100644 --- a/src/Utils/GenerationUtils.php +++ b/src/Utils/GenerationUtils.php @@ -4,6 +4,7 @@ use DateTime; use GlobalPayments\Api\Entities\Enums\HppVersion; +use ReflectionClass; /** * Utils for the auto-generation of fields, for example the SHA1 hash. @@ -156,4 +157,19 @@ public static function decodeJson($json, $returnArray = true, $hppVersion = '') } return json_decode($json, $returnArray); } + + public static function convertObjectToArray($object) + { + $reflectionClass = new ReflectionClass(get_class($object)); + $array = array(); + foreach ($reflectionClass->getProperties() as $property) { + $property->setAccessible(true); + if (!empty($property->getValue($object))) { + $array[$property->getName()] = $property->getValue($object); + } + $property->setAccessible(false); + } + + return $array; + } } diff --git a/src/Utils/Logging/Logger.php b/src/Utils/Logging/Logger.php new file mode 100644 index 00000000..d5067c7d --- /dev/null +++ b/src/Utils/Logging/Logger.php @@ -0,0 +1,352 @@ +info('Returned a million search results'); //Prints to the log file + * $log->error('Oh dear.'); //Prints to the log file + * $log->debug('x = 5'); //Prints nothing due to current severity threshold + * + * @author Kenny Katzgrau + * @since July 26, 2008 + * @link https://github.com/katzgrau/KLogger + * @version 1.0.0 + */ +class Logger extends AbstractLogger +{ + + /** + * KLogger options + * Anything options not considered 'core' to the logging library should be + * settable view the third parameter in the constructor + * + * Core options include the log file path and the log threshold + * + * @var array + */ + protected $options = array( + 'extension' => 'txt', + 'dateFormat' => 'Y-m-d G:i:s.u', + 'filename' => false, + 'flushFrequency' => false, + 'prefix' => 'log_', + 'logFormat' => false, + 'appendContext' => true, + ); + + /** + * Path to the log file + * @var string + */ + private $logFilePath; + + /** + * Current minimum logging threshold + * @var integer + */ + protected $logLevelThreshold = LogLevel::DEBUG; + + /** + * The number of lines logged in this instance's lifetime + * @var int + */ + private $logLineCount = 0; + + /** + * Log Levels + * @var array + */ + protected $logLevels = array( + LogLevel::EMERGENCY => 0, + LogLevel::ALERT => 1, + LogLevel::CRITICAL => 2, + LogLevel::ERROR => 3, + LogLevel::WARNING => 4, + LogLevel::NOTICE => 5, + LogLevel::INFO => 6, + LogLevel::DEBUG => 7 + ); + + /** + * This holds the file handle for this instance's log file + * @var resource + */ + private $fileHandle; + + /** + * This holds the last line logged to the logger + * Used for unit tests + * @var string + */ + private $lastLine = ''; + + /** + * Octal notation for default permissions of the log file + * @var integer + */ + private $defaultPermissions = 0777; + + /** + * Class constructor + * + * @param string $logDirectory File path to the logging directory + * @param string $logLevelThreshold The LogLevel Threshold + * @param array $options + * + * @internal param string $logFilePrefix The prefix for the log file name + * @internal param string $logFileExt The extension for the log file + */ + public function __construct($logDirectory, $logLevelThreshold = LogLevel::DEBUG, array $options = array()) + { + $this->logLevelThreshold = $logLevelThreshold; + $this->options = array_merge($this->options, $options); + + $logDirectory = rtrim($logDirectory, DIRECTORY_SEPARATOR); + if (!file_exists($logDirectory)) { + mkdir($logDirectory, $this->defaultPermissions, true); + } + + if (strpos($logDirectory, 'php://') === 0) { + $this->setLogToStdOut($logDirectory); + $this->setFileHandle('w+'); + } else { + $this->setLogFilePath($logDirectory); + if (file_exists($this->logFilePath) && !is_writable($this->logFilePath)) { + throw new RuntimeException('The file could not be written to. Check that appropriate permissions have been set.'); + } + $this->setFileHandle('a'); + } + + if (!$this->fileHandle) { + throw new RuntimeException('The file could not be opened. Check permissions.'); + } + } + + /** + * @param string $stdOutPath + */ + public function setLogToStdOut($stdOutPath) + { + $this->logFilePath = $stdOutPath; + } + + /** + * @param string $logDirectory + */ + public function setLogFilePath($logDirectory) + { + if ($this->options['filename']) { + if (strpos($this->options['filename'], '.log') !== false || strpos($this->options['filename'], + '.txt') !== false) { + $this->logFilePath = $logDirectory . DIRECTORY_SEPARATOR . $this->options['filename']; + } else { + $this->logFilePath = $logDirectory . DIRECTORY_SEPARATOR . $this->options['filename'] . '.' . $this->options['extension']; + } + } else { + $this->logFilePath = $logDirectory . DIRECTORY_SEPARATOR . $this->options['prefix'] . date('Y-m-d') . '.' . $this->options['extension']; + } + } + + /** + * @param $writeMode + * + * @internal param resource $fileHandle + */ + public function setFileHandle($writeMode) + { + $this->fileHandle = fopen($this->logFilePath, $writeMode); + } + + + /** + * Class destructor + */ + public function __destruct() + { + if ($this->fileHandle) { + fclose($this->fileHandle); + } + } + + /** + * Sets the date format used by all instances of KLogger + * + * @param string $dateFormat Valid format string for date() + */ + public function setDateFormat($dateFormat) + { + $this->options['dateFormat'] = $dateFormat; + } + + /** + * Sets the Log Level Threshold + * + * @param string $logLevelThreshold The log level threshold + */ + public function setLogLevelThreshold($logLevelThreshold) + { + $this->logLevelThreshold = $logLevelThreshold; + } + + /** + * Logs with an arbitrary level. + * + * @param mixed $level + * @param string $message + * @param array $context + * @return null + */ + public function log($level, $message, array $context = array()) + { + if ($this->logLevels[$this->logLevelThreshold] < $this->logLevels[$level]) { + return; + } + $message = $this->formatMessage($level, $message, $context); + $this->write($message); + } + + /** + * Writes a line to the log without prepending a status or timestamp + * + * @param string $message Line to write to the log + * @return void + */ + public function write($message) + { + if (null !== $this->fileHandle) { + if (fwrite($this->fileHandle, $message) === false) { + throw new RuntimeException('The file could not be written to. Check that appropriate permissions have been set.'); + } else { + $this->lastLine = trim($message); + $this->logLineCount++; + + if ($this->options['flushFrequency'] && $this->logLineCount % $this->options['flushFrequency'] === 0) { + fflush($this->fileHandle); + } + } + } + } + + /** + * Get the file path that the log is currently writing to + * + * @return string + */ + public function getLogFilePath() + { + return $this->logFilePath; + } + + /** + * Get the last line logged to the log file + * + * @return string + */ + public function getLastLogLine() + { + return $this->lastLine; + } + + /** + * Formats the message for logging. + * + * @param string $level The Log Level of the message + * @param string $message The message to log + * @param array $context The context + * @return string + */ + protected function formatMessage($level, $message, $context) + { + if ($this->options['logFormat']) { + $parts = array( + 'date' => $this->getTimestamp(), + 'level' => strtoupper($level), + 'level-padding' => str_repeat(' ', 9 - strlen($level)), + 'priority' => $this->logLevels[$level], + 'message' => $message, + 'context' => json_encode($context), + ); + $message = $this->options['logFormat']; + foreach ($parts as $part => $value) { + $message = str_replace('{' . $part . '}', $value, $message); + } + + } else { + $message = "[{$this->getTimestamp()}] [{$level}] {$message}"; + } + + if ($this->options['appendContext'] && !empty($context)) { + $message .= PHP_EOL . $this->indent($this->contextToString($context)); + } + + return $message . PHP_EOL; + + } + + /** + * Gets the correctly formatted Date/Time for the log entry. + * + * PHP DateTime is dump, and you have to resort to trickery to get microseconds + * to work correctly, so here it is. + * + * @return string + */ + private function getTimestamp() + { + $originalTime = microtime(true); + $micro = sprintf("%06d", ($originalTime - floor($originalTime)) * 1000000); + $date = new DateTime(date('Y-m-d H:i:s.' . $micro, $originalTime)); + + return $date->format($this->options['dateFormat']); + } + + /** + * Takes the given context and coverts it to a string. + * + * @param array $context The Context + * @return string + */ + protected function contextToString($context) + { + $export = ''; + foreach ($context as $key => $value) { + $export .= "{$key}: "; + $export .= preg_replace(array( + '/=>\s+([a-zA-Z])/im', + '/array\(\s+\)/im', + '/^ |\G /m' + ), array( + '=> $1', + 'array()', + ' ' + ), str_replace('array (', 'array(', var_export($value, true))); + $export .= PHP_EOL; + } + return str_replace(array('\\\\', '\\\''), array('\\', '\''), rtrim($export)); + } + + /** + * Indents the given string with the given indent. + * + * @param string $string The string to indent + * @param string $indent What to use as the indent. + * @return string + */ + protected function indent($string, $indent = ' ') + { + return $indent . str_replace("\n", "\n" . $indent, $string); + } +} \ No newline at end of file diff --git a/src/Utils/Logging/SampleRequestLogger.php b/src/Utils/Logging/SampleRequestLogger.php new file mode 100644 index 00000000..84f04ffd --- /dev/null +++ b/src/Utils/Logging/SampleRequestLogger.php @@ -0,0 +1,54 @@ +logger = $logger; + } + + public function requestSent($verb, $endpoint, $headers, $queryStringParams, $data) + { + // TODO: Implement requestSent() method. + $this->logger->info("Request/Response START"); + $this->logger->info("Request START"); + $this->logger->info("Request verb: " . $verb); + $this->logger->info("Request endpoint: " . $endpoint); + $this->logger->info("Request headers: ", $headers); + $this->logger->info("Request query string: ", !empty($queryStringParams) ? $queryStringParams : array()); + $this->logger->info("Request body: ", !empty($data) ? json_decode($data, true) : array()); + $this->logger->info("REQUEST END"); + } + + + public function responseReceived(GatewayResponse $response) + { + // TODO: Implement responseReceived() method. + $this->logger->info("Response START"); + $this->logger->info("Status code: " . $response->statusCode); + $this->logger->info("Response body: ", json_decode(gzdecode($response->rawResponse), true)); + $this->logger->info("Response END"); + $this->logger->info("Request/Response END"); + } + + public function responseError(\Exception $e) + { + $this->logger->info("Exception START"); + $this->logger->info("Error occurred while communicating with the gateway"); + $this->logger->info("Exception type: " . get_class($e)); + $this->logger->info("Exception message: " . $e->getMessage()); + $this->logger->info("Exception END"); + } + + +} \ No newline at end of file diff --git a/src/Utils/StringUtils.php b/src/Utils/StringUtils.php index a2393f49..bb6f592f 100644 --- a/src/Utils/StringUtils.php +++ b/src/Utils/StringUtils.php @@ -3,6 +3,8 @@ namespace GlobalPayments\Api\Utils; use GlobalPayments\Api\Entities\Enums\TrackNumber; +use Locale; +use NumberFormatter; class StringUtils { @@ -38,4 +40,33 @@ public static function asPaddedAtFrontString($inString, $toLength, $padChar) $padStr = str_repeat($padChar, $toLength - strlen($inString)); return $padStr . $inString; } + + public static function toNumeric($value) + { + if (is_null($value)) { + return ""; + } + if ((string) $value == "0") { + return "000"; + } + $locale = Locale::getDefault(); + $formatter = new NumberFormatter($locale, NumberFormatter::CURRENCY); + $currency = $formatter->getSymbol(NumberFormatter::INTL_CURRENCY_SYMBOL); + + return ltrim(preg_replace("/[^0-9]/","", $formatter->formatCurrency($value, $currency)), "0"); + } + + /** + * @param string $str + * + * @return float|int + */ + public static function toAmount($str) + { + if (empty($str)) { + return 0; + } + + return $str / 100; + } } diff --git a/test/Data/TestChecks.php b/test/Data/TestChecks.php index 22cb4b05..e2cb2b0a 100644 --- a/test/Data/TestChecks.php +++ b/test/Data/TestChecks.php @@ -1,37 +1,37 @@ -accountNumber = '1357902468'; - $check->routingNumber = '122000030'; - $check->checkType = $checkType; - $check->accountType = $accountType; - $check->secCode = $secCode; - $check->entryMode = EntryMethod::MANUAL; - $check->checkHolderName = 'John Doe'; - $check->driversLicenseNumber = '09876543210'; - $check->driversLicenseState = 'TX'; - $check->phoneNumber = '8003214567'; - $check->birthYear = '1997'; - $check->ssnLast4 = '4321'; - if (!empty($checkHolderName)) { - $check->checkHolderName = $checkHolderName; - } - return $check; - } -} +accountNumber = '1357902468'; + $check->routingNumber = '122000030'; + $check->checkType = $checkType; + $check->accountType = $accountType; + $check->secCode = $secCode; + $check->entryMode = EntryMethod::MANUAL; + $check->checkHolderName = 'John Doe'; + $check->driversLicenseNumber = '09876543210'; + $check->driversLicenseState = 'TX'; + $check->phoneNumber = '8003214567'; + $check->birthYear = '1997'; + $check->ssnLast4 = '4321'; + if (!empty($checkHolderName)) { + $check->checkHolderName = $checkHolderName; + } + return $check; + } +} diff --git a/test/Integration/Gateways/GpApiConnector/AccessTokenTest.php b/test/Integration/Gateways/GpApiConnector/AccessTokenTest.php new file mode 100644 index 00000000..8390f54f --- /dev/null +++ b/test/Integration/Gateways/GpApiConnector/AccessTokenTest.php @@ -0,0 +1,122 @@ +setUpConfig()); + $accessToken = $this->accessTokenInfo->generateAccessToken(); + + $this->assertNotEmpty($accessToken->token); + } + + public function testAccessTokenInfoAccountNameExistence() + { + ServicesContainer::configureService($this->setUpConfig()); + $this->assertNotEmpty($this->accessTokenInfo->getDataAccountName()); + $this->assertNotEmpty($this->accessTokenInfo->getDisputeManagementAccountName()); + $this->assertNotEmpty($this->accessTokenInfo->getTransactionProcessingAccountName()); + $this->assertNotEmpty($this->accessTokenInfo->getTokenizationAccountName()); + } + + public function testGenerateAccessTokenManual() + { + /** + * @var AccessTokenInfo $accessTokenInfo + */ + $accessTokenInfo = GpApiService::generateTransactionKey($this->environment, $this->appId, $this->appKey); + + $this->assertNotNull($accessTokenInfo); + $this->assertNotNull($accessTokenInfo->getAccessToken()); + $this->assertNotNull($accessTokenInfo->getDataAccountName()); + $this->assertNotNull($accessTokenInfo->getDisputeManagementAccountName()); + $this->assertNotNull($accessTokenInfo->getTokenizationAccountName()); + $this->assertNotNull($accessTokenInfo->getTransactionProcessingAccountName()); + } + + public function testCreateAccessTokenWithSpecificExpiredDate() + { + $accessTokenInfo = GpApiService::generateTransactionKey($this->environment, $this->appId, $this->appKey, 200, 'WEEK'); + + $this->assertNotNull($accessTokenInfo); + $this->assertNotNull($accessTokenInfo->getAccessToken()); + $this->assertNotNull($accessTokenInfo->getDataAccountName()); + $this->assertNotNull($accessTokenInfo->getDisputeManagementAccountName()); + $this->assertNotNull($accessTokenInfo->getTokenizationAccountName()); + $this->assertNotNull($accessTokenInfo->getTransactionProcessingAccountName()); + } + + public function testCreateAccessTokenWithSpecific_SecondsToExpire() + { + $accessTokenInfo = GpApiService::generateTransactionKey($this->environment, $this->appId, $this->appKey, 200); + + $this->assertNotNull($accessTokenInfo); + $this->assertNotNull($accessTokenInfo->getAccessToken()); + $this->assertNotNull($accessTokenInfo->getDataAccountName()); + $this->assertNotNull($accessTokenInfo->getDisputeManagementAccountName()); + $this->assertNotNull($accessTokenInfo->getTokenizationAccountName()); + $this->assertNotNull($accessTokenInfo->getTransactionProcessingAccountName()); + } + + public function testCreateAccessTokenWithSpecific_IntervalToExpire() + { + $accessTokenInfo = GpApiService::generateTransactionKey($this->environment, $this->appId, $this->appKey, null, "1_HOUR"); + + $this->assertNotNull($accessTokenInfo); + $this->assertNotNull($accessTokenInfo->getAccessToken()); + $this->assertNotNull($accessTokenInfo->getDataAccountName()); + $this->assertNotNull($accessTokenInfo->getDisputeManagementAccountName()); + $this->assertNotNull($accessTokenInfo->getTokenizationAccountName()); + $this->assertNotNull($accessTokenInfo->getTransactionProcessingAccountName()); + } + + public function testGenerateAccessTokenWrongAppId() + { + try { + GpApiService::generateTransactionKey($this->environment, $this->appId . "a", $this->appKey); + } catch (GatewayException $e) { + $this->assertEquals('40004', $e->responseCode); + $this->assertEquals('Status Code: ACTION_NOT_AUTHORIZED - Credentials not recognized to create access token.', $e->getMessage()); + } + } + + public function testGenerateAccessTokenWrongAppKey() + { + try { + GpApiService::generateTransactionKey($this->environment, $this->appId, $this->appKey . "a"); + } catch (GatewayException $e) { + $this->assertEquals('40004', $e->responseCode); + $this->assertEquals('Status Code: ACTION_NOT_AUTHORIZED - Credentials not recognized to create access token.', $e->getMessage()); + } + } + + public function setUpConfig() + { + $config = new GpApiConfig(); + $accessTokenManager = new \GlobalPayments\Api\Utils\AccessTokenInfo(); + //this is gpapistuff stuff + $config->setAppId('VuKlC2n1cr5LZ8fzLUQhA7UObVks6tFF'); + $config->setAppKey('NmGM0kg92z2gA7Og'); + $config->setAccessTokenInfo($accessTokenManager); + $this->accessTokenInfo = $accessTokenManager; + + return $config; + } +} \ No newline at end of file diff --git a/test/Integration/Gateways/GpApiConnector/Certifications/CapabilitiesCardPresentTest.php b/test/Integration/Gateways/GpApiConnector/Certifications/CapabilitiesCardPresentTest.php new file mode 100644 index 00000000..8f050342 --- /dev/null +++ b/test/Integration/Gateways/GpApiConnector/Certifications/CapabilitiesCardPresentTest.php @@ -0,0 +1,107 @@ +setUpConfig()); + $this->card = new CreditCardData(); + $this->card->number = "4242424242424242"; + $this->card->expMonth = "09"; + $this->card->expYear = date('Y', strtotime('+1 year')); + $this->card->cardPresent = true; + $this->card->cardHolderName = 'Jon Dow'; + } + + public function setUpConfig() + { + $config = new GpApiConfig(); + $accessTokenManager = new AccessTokenInfo(); + //this is gpapistuff stuff + $config->setAppId('i872l4VgZRtSrykvSn8Lkah8RE1jihvT'); + $config->setAppKey( '9pArW2uWoA8enxKc'); + $config->environment = Environment::TEST; + $config->setAccessTokenInfo($accessTokenManager); + $config->setChannel(Channels::CardPresent); + + return $config; + } + + public function testDebitSaleWithChipCondition() + { + $debitCard = new DebitTrackData(); + $debitCard->value = ';4024720012345671=18125025432198712345?'; + $debitCard->pinBlock = 'AFEC374574FC90623D010000116001EE'; + $debitCard->entryMethod = EntryMethod::SWIPE; + $response = $debitCard->charge(100) + ->withCurrency("USD") + ->withChipCondition(EmvLastChipRead::SUCCESSFUL) + ->withAllowDuplicates(true) + ->execute(); + + $this->assertNotNull($response); + $this->assertEquals('SUCCESS', $response->responseCode); + $this->assertEquals(TransactionStatus::CAPTURED, $response->responseMessage); + } + + public function testDebitSaleContactlessChip() + { + $debitCard = new DebitTrackData(); + $debitCard->value = '%B4012002000060016^VI TEST CREDIT^251210118039000000000396?;4012002000060016=25121011803939600000?'; + $tagData = '82021C008407A0000002771010950580000000009A031709289C01005F280201245F2A0201245F3401019F02060000000010009F03060000000000009F080200019F090200019F100706010A03A420009F1A0201249F26089CC473F4A4CE18D39F2701809F3303E0F8C89F34030100029F3501229F360200639F370435EFED379F410400000019'; + + $response = $debitCard->charge(10) + ->withCurrency("USD") + ->withAllowDuplicates(true) + ->withTagData($tagData) + ->execute(); + + $this->assertNotNull($response); + $this->assertEquals('SUCCESS', $response->responseCode); + $this->assertEquals(TransactionStatus::CAPTURED, $response->responseMessage); + } + + public function testCardPresentManual() + { + $response = $this->card->charge(10) + ->withCurrency("USD") + ->withAllowDuplicates(true) + ->execute(); + + $this->assertNotNull($response); + $this->assertEquals('SUCCESS', $response->responseCode); + $this->assertEquals(TransactionStatus::CAPTURED, $response->responseMessage); + } + + public function testCardPresentGratuity() + { + $response = $this->card->charge(100) + ->withCurrency("USD") + ->withGratuity(20) + ->withAllowDuplicates(true) + ->execute(); + + $this->assertNotNull($response); + $this->assertEquals('SUCCESS', $response->responseCode); + $this->assertEquals(TransactionStatus::CAPTURED, $response->responseMessage); + } +} \ No newline at end of file diff --git a/test/Integration/Gateways/GpApiConnector/Certifications/GpApiSdkCertificationTest.php b/test/Integration/Gateways/GpApiConnector/Certifications/GpApiSdkCertificationTest.php new file mode 100644 index 00000000..cba73577 --- /dev/null +++ b/test/Integration/Gateways/GpApiConnector/Certifications/GpApiSdkCertificationTest.php @@ -0,0 +1,519 @@ +setUpConfig()); + $this->card = new CreditCardData(); + $this->card->expMonth = date('m'); + $this->card->expYear = date('Y', strtotime('+1 year')); + $this->card->cvn = "131"; + $this->card->cardHolderName = "James Mason"; + $this->card->cvnPresenceIndicator = CvnPresenceIndicator::PRESENT; + } + + public function setUpConfig() + { + $config = new GpApiConfig(); + //this is gpapistuff stuff + $config->setAppId('i872l4VgZRtSrykvSn8Lkah8RE1jihvT'); + $config->setAppKey( '9pArW2uWoA8enxKc'); + $config->environment = Environment::TEST; + $config->setAccessTokenInfo(new AccessTokenInfo()); + $config->setChannel(Channels::CardNotPresent); + + return $config; + } + + public function testCreditCard_Visa_Success() + { + $this->card->number = "4263970000005262"; + + $response = $this->card->charge(30) + ->withCurrency("USD") + ->WithDescription("CreditCard_Visa_Success") + ->execute(); + + $this->assertNotNull($response); + $this->assertEquals('VISA', $response->cardType); + $this->assertEquals('00', $response->authorizationCode); + $this->assertEquals('SUCCESS', $response->responseCode); + $this->assertEquals(TransactionStatus::CAPTURED, $response->responseMessage); + } + + public function testCreditCard_Mastercard_Success() + { + $this->card->number = '5425230000004415'; + + $response = $this->card->charge(30) + ->withCurrency("USD") + ->WithDescription("CreditCard_Mastercard_Success") + ->execute(); + + $this->assertNotNull($response); + $this->assertEquals('MASTERCARD', $response->cardType); + $this->assertEquals('SUCCESS', $response->responseCode); + $this->assertEquals(TransactionStatus::CAPTURED, $response->responseMessage); + } + + public function testCreditCard_AmericanExpress_Success() + { + $this->card->number = '374101000000608'; + $this->card->cvn = "1234"; + + $response = $this->card->charge(30) + ->withCurrency("USD") + ->WithDescription("CreditCard_AmericanExpress_Success") + ->execute(); + + $this->assertNotNull($response); + $this->assertEquals('AMEX', $response->cardType); + $this->assertEquals('SUCCESS', $response->responseCode); + $this->assertEquals(TransactionStatus::CAPTURED, $response->responseMessage); + } + + public function testCreditCard_DinersClub_Success() + { + $this->card->number = '36256000000725'; + + $response = $this->card->charge(30) + ->withCurrency("USD") + ->WithDescription("CreditCard_DinersClub_Success") + ->execute(); + + $this->assertNotNull($response); + $this->assertEquals('DINERS', $response->cardType); + $this->assertEquals('00', $response->authorizationCode); + $this->assertEquals('SUCCESS', $response->responseCode); + $this->assertEquals(TransactionStatus::CAPTURED, $response->responseMessage); + } + + public function testCreditCard_Discover_Success() + { + $this->card->number = '6011000000000087'; + + $response = $this->card->charge(30) + ->withCurrency("USD") + ->WithDescription("CreditCard_Discover_Success") + ->execute(); + + $this->assertNotNull($response); + $this->assertEquals('DISCOVER', $response->cardType); + $this->assertEquals('00', $response->authorizationCode); + $this->assertEquals('SUCCESS', $response->responseCode); + $this->assertEquals(TransactionStatus::CAPTURED, $response->responseMessage); + } + + public function testCreditCard_JCB_Success() + { + $this->card->number = '3566000000000000'; + + $response = $this->card->charge(15) + ->withCurrency("USD") + ->WithDescription("CreditCard_JCB_Success") + ->execute(); + + $this->assertNotNull($response); + $this->assertEquals('JCB', $response->cardType); + $this->assertEquals('00', $response->authorizationCode); + $this->assertEquals('SUCCESS', $response->responseCode); + $this->assertEquals(TransactionStatus::CAPTURED, $response->responseMessage); + } + + public function testCreditCard_Visa_Declined_101() + { + $this->card->number = '4000120000001154'; + + $response = $this->card->charge(30) + ->withCurrency("USD") + ->WithDescription("CreditCard_Visa_Declined_101") + ->execute(); + + $this->assertNotNull($response); + $this->assertEquals('VISA', $response->cardType); + $this->assertEquals('101', $response->authorizationCode); + $this->assertEquals(TransactionStatus::DECLINED, $response->responseMessage); + } + + public function testCreditCard_Visa_Declined_102() + { + $this->card->number = '4000130000001724'; + + $response = $this->card->charge(12) + ->withCurrency("USD") + ->WithDescription("CreditCard_Visa_Declined_102") + ->execute(); + $this->assertNotNull($response); + $this->assertEquals('VISA', $response->cardType); + $this->assertEquals('102', $response->authorizationCode); + $this->assertEquals(TransactionStatus::DECLINED, $response->responseMessage); + } + + public function testCreditCard_Visa_Declined_103() + { + $this->card->number = '4000160000004147'; + + $response = $this->card->charge(12) + ->withCurrency("USD") + ->WithDescription("CreditCard_Visa_Declined_103") + ->execute(); + + $this->assertNotNull($response); + $this->assertEquals('VISA', $response->cardType); + $this->assertEquals('103', $response->authorizationCode); + $this->assertEquals(TransactionStatus::DECLINED, $response->responseMessage); + } + + public function testCreditCard_Mastercard_Declined_101() + { + $this->card->number = '5114610000004778'; + + $response = $this->card->charge(12) + ->withCurrency("USD") + ->WithDescription("CreditCard_Mastercard_Declined_101") + ->execute(); + + $this->assertNotNull($response); + $this->assertEquals('MASTERCARD', $response->cardType); + $this->assertEquals('101', $response->authorizationCode); + $this->assertEquals(TransactionStatus::DECLINED, $response->responseMessage); + } + + public function testCreditCard_Mastercard_Declined_102() + { + $this->card->number = '5114630000009791'; + + $response = $this->card->charge(15) + ->withCurrency("USD") + ->WithDescription("CreditCard_Mastercard_Declined_102") + ->execute(); + + $this->assertNotNull($response); + $this->assertEquals('MASTERCARD', $response->cardType); + $this->assertEquals('102', $response->authorizationCode); + $this->assertEquals(TransactionStatus::DECLINED, $response->responseMessage); + } + + public function testCreditCard_Mastercard_Declined_103() + { + $this->card->number = '5121220000006921'; + $this->card->cvnPresenceIndicator = CvnPresenceIndicator::ILLEGIBLE; + + $response = $this->card->charge(27) + ->withCurrency("USD") + ->WithDescription("CreditCard_Mastercard_Declined_103") + ->execute(); + + $this->assertNotNull($response); + $this->assertEquals('MASTERCARD', $response->cardType); + $this->assertEquals('103', $response->authorizationCode); + $this->assertEquals(TransactionStatus::DECLINED, $response->responseMessage); + } + + public function testCreditCard_AmericanExpress_Declined_101() + { + $this->card->number = '376525000000010'; + $this->card->cvn = '1234'; + + $response = $this->card->charge(17) + ->withCurrency("USD") + ->WithDescription("CreditCard_AmericanExpress_Declined_101") + ->execute(); + + $this->assertNotNull($response); + $this->assertEquals('AMEX', $response->cardType); + $this->assertEquals('101', $response->authorizationCode); + $this->assertEquals(TransactionStatus::DECLINED, $response->responseMessage); + } + + public function testCreditCard_AmericanExpress_Declined_102() + { + $this->card->number = '375425000000907'; + $this->card->cvn = '1234'; + + $response = $this->card->charge(17) + ->withCurrency("USD") + ->WithDescription("CreditCard_AmericanExpress_Declined_102") + ->execute(); + + $this->assertNotNull($response); + $this->assertEquals('AMEX', $response->cardType); + $this->assertEquals('102', $response->authorizationCode); + $this->assertEquals(TransactionStatus::DECLINED, $response->responseMessage); + } + + public function testCreditCard_AmericanExpress_Declined_103() + { + $this->card->number = '343452000000306'; + $this->card->cvn = '1234'; + + $response = $this->card->charge(17) + ->withCurrency("USD") + ->WithDescription("CreditCard_AmericanExpress_Declined_103") + ->execute(); + + $this->assertNotNull($response); + $this->assertEquals('AMEX', $response->cardType); + $this->assertEquals('103', $response->authorizationCode); + $this->assertEquals(TransactionStatus::DECLINED, $response->responseMessage); + } + + public function testCreditCard_DinersClub_Declined_101() + { + $this->card->number = '36256000000998'; + + $response = $this->card->charge(17) + ->withCurrency("USD") + ->WithDescription("CreditCard_DinersClub_Declined_101") + ->execute(); + + $this->assertNotNull($response); + $this->assertEquals('DINERS', $response->cardType); + $this->assertEquals('101', $response->authorizationCode); + $this->assertEquals(TransactionStatus::DECLINED, $response->responseMessage); + } + + public function testCreditCard_DinersClub_Declined_102() + { + $this->card->number = '36256000000634'; + + $response = $this->card->charge(17) + ->withCurrency("USD") + ->WithDescription("CreditCard_DinersClub_Declined_102") + ->execute(); + + $this->assertNotNull($response); + $this->assertEquals('DINERS', $response->cardType); + $this->assertEquals('102', $response->authorizationCode); + $this->assertEquals(TransactionStatus::DECLINED, $response->responseMessage); + } + + public function testCreditCard_DinersClub_Declined_103() + { + $this->card->number = '38865000000705'; + + $response = $this->card->charge(20) + ->withCurrency("USD") + ->WithDescription("CreditCard_DinersClub_Declined_103") + ->execute(); + + $this->assertNotNull($response); + $this->assertEquals('DINERS', $response->cardType); + $this->assertEquals('103', $response->authorizationCode); + $this->assertEquals(TransactionStatus::DECLINED, $response->responseMessage); + } + + public function testCreditCard_Discover_Declined_101() + { + $this->card->number = '6011000000001010'; + + $response = $this->card->charge(20) + ->withCurrency("USD") + ->WithDescription("CreditCard_Discover_Declined_101") + ->execute(); + + $this->assertNotNull($response); + $this->assertEquals('DISCOVER', $response->cardType); + $this->assertEquals('101', $response->authorizationCode); + $this->assertEquals(TransactionStatus::DECLINED, $response->responseMessage); + } + + public function testCreditCard_Discover_Declined_102() + { + $this->card->number = '6011000000001028'; + + $response = $this->card->charge(20) + ->withCurrency("USD") + ->WithDescription("CreditCard_Discover_Declined_102") + ->execute(); + + $this->assertNotNull($response); + $this->assertEquals('DISCOVER', $response->cardType); + $this->assertEquals('102', $response->authorizationCode); + $this->assertEquals(TransactionStatus::DECLINED, $response->responseMessage); + } + + public function testCreditCard_Discover_Declined_103() + { + $this->card->number = '6011000000001036'; + + $response = $this->card->charge(20) + ->withCurrency("USD") + ->WithDescription("CreditCard_Discover_Declined_103") + ->execute(); + + $this->assertNotNull($response); + $this->assertEquals('DISCOVER', $response->cardType); + $this->assertEquals('103', $response->authorizationCode); + $this->assertEquals(TransactionStatus::DECLINED, $response->responseMessage); + } + + public function testCreditCard_JCB_Declined_101() + { + $this->card->number = '3566000000001016'; + + $response = $this->card->charge(20) + ->withCurrency("USD") + ->WithDescription("CreditCard_JCB_Declined_101") + ->execute(); + + $this->assertNotNull($response); + $this->assertEquals('JCB', $response->cardType); + $this->assertEquals('101', $response->authorizationCode); + $this->assertEquals(TransactionStatus::DECLINED, $response->responseMessage); + } + + public function testCreditCard_JCB_Declined_102() + { + $this->card->number = '3566000000001024'; + + $response = $this->card->charge(20) + ->withCurrency("USD") + ->WithDescription("CreditCard_JCB_Declined_102") + ->execute(); + + $this->assertNotNull($response); + $this->assertEquals('JCB', $response->cardType); + $this->assertEquals('102', $response->authorizationCode); + $this->assertEquals(TransactionStatus::DECLINED, $response->responseMessage); + } + + public function testCreditCard_JCB_Declined_103() + { + $this->card->number = '3566000000001032'; + + $response = $this->card->charge(20) + ->withCurrency("USD") + ->WithDescription("CreditCard_JCB_Declined_103") + ->execute(); + + $this->assertNotNull($response); + $this->assertEquals('JCB', $response->cardType); + $this->assertEquals('103', $response->authorizationCode); + $this->assertEquals(TransactionStatus::DECLINED, $response->responseMessage); + } + + public function testCreditCard_Visa_Processing_Error() + { + $this->card->number = '4009830000001985'; + try { + $response = $this->card->charge(17) + ->withCurrency("USD") + ->WithDescription("CreditCard_Visa_Processing_Error") + ->execute(); + } catch (GatewayException $e) { + $this->assertEquals("50013", $e->responseCode); + $this->assertContains("SYSTEM_ERROR_DOWNSTREAM", $e->getMessage()); + } + } + + public function testCreditCard_Visa_Processing_Error_Wrong_Currency() + { + $this->card->number = '4009830000001985'; + try { + $response = $this->card->charge(17) + ->withCurrency("XXX") + ->WithDescription("CreditCard_Visa_Processing_Error_Wrong_Currency") + ->execute(); + } catch (GatewayException $e) { + $this->assertEquals("50024", $e->responseCode); + $this->assertContains("SYSTEM_ERROR_DOWNSTREAM", $e->getMessage()); + } + } + + public function testCreditCard_Mastercard_Processing_Error() + { + $this->card->number = '5135020000005871'; + try { + $response = $this->card->charge(17) + ->withCurrency("USD") + ->WithDescription("CreditCard_Mastercard_Processing_Error") + ->execute(); + } catch (GatewayException $e) { + $this->assertEquals("50013", $e->responseCode); + $this->assertContains("SYSTEM_ERROR_DOWNSTREAM", $e->getMessage()); + } + } + + public function testCreditCard_AmericanExpress_Processing_Error() + { + $this->card->number = '372349000000852'; + $this->card->cvn = '1234'; + + try { + $response = $this->card->charge(17) + ->withCurrency("USD") + ->WithDescription("CreditCard_AmericanExpress_Processing_Error") + ->execute(); + } catch (GatewayException $e) { + $this->assertEquals("50013", $e->responseCode); + $this->assertContains("SYSTEM_ERROR_DOWNSTREAM", $e->getMessage()); + } + } + + public function testCreditCard_DinersClub_Processing_Error() + { + $this->card->number = '30450000000985'; + + try { + $response = $this->card->charge(17) + ->withCurrency("USD") + ->WithDescription("CreditCard_DinersClub_Processing_Error") + ->execute(); + } catch (GatewayException $e) { + $this->assertEquals("50013", $e->responseCode); + $this->assertContains("SYSTEM_ERROR_DOWNSTREAM", $e->getMessage()); + } + } + + public function testCreditCard_Discover_Processing_Error() + { + $this->card->number = '6011000000002000'; + + try { + $response = $this->card->charge(17) + ->withCurrency("USD") + ->WithDescription("CreditCard_Discover_Processing_Error") + ->execute(); + } catch (GatewayException $e) { + $this->assertEquals("50013", $e->responseCode); + $this->assertContains("SYSTEM_ERROR_DOWNSTREAM", $e->getMessage()); + } + } + + public function testCreditCard_JCB_Processing_Error() + { + $this->card->number = '3566000000002006'; + + try { + $response = $this->card->charge(4.99) + ->withCurrency("USD") + ->WithDescription("CreditCard_JCB_Processing_Error") + ->execute(); + } catch (GatewayException $e) { + $this->assertEquals("50013", $e->responseCode); + $this->assertContains("SYSTEM_ERROR_DOWNSTREAM", $e->getMessage()); + } + } +} \ No newline at end of file diff --git a/test/Integration/Gateways/GpApiConnector/CreditCardNotPresentTest.php b/test/Integration/Gateways/GpApiConnector/CreditCardNotPresentTest.php new file mode 100644 index 00000000..22bc2db6 --- /dev/null +++ b/test/Integration/Gateways/GpApiConnector/CreditCardNotPresentTest.php @@ -0,0 +1,923 @@ +setUpConfig()); + $this->card = new CreditCardData(); + $this->card->number = "4263970000005262"; + $this->card->expMonth = date('m'); + $this->card->expYear = date('Y', strtotime('+1 year')); + $this->card->cvn = "131"; + $this->card->cardHolderName = "James Mason"; + $this->idempotencyKey = GenerationUtils::getGuid(); + } + + public function testCreditSale() + { + $address = new Address(); + $address->streetAddress1 = "123 Main St."; + $address->city = "Downtown"; + $address->state = "NJ"; + $address->country = "US"; + $address->postalCode = "12345"; + + $response = $this->card->charge(69) + ->withCurrency("USD") + ->withAddress($address) + ->execute(); + + $this->assertNotNull($response); + $this->assertEquals('SUCCESS', $response->responseCode); + $this->assertEquals(TransactionStatus::CAPTURED, $response->responseMessage); + } + + public function testCreditAuthorization() + { + $transaction = $this->card->authorize(42) + ->withCurrency('USD') + ->withAllowDuplicates(true) + ->execute(); + + $this->assertNotNull($transaction); + $this->assertEquals('SUCCESS', $transaction->responseCode); + $this->assertEquals(TransactionStatus::PREAUTHORIZED, $transaction->responseMessage); + } + + public function testAuthorizationThenCapture() + { + try { + $transaction = $this->card->authorize(42) + ->withCurrency('USD') + ->withOrderId('123456-78910') + ->withAllowDuplicates(true) + ->execute(); + } catch (ApiException $e) { + $this->fail("Card Authorization Failed"); + } + + $this->assertNotNull($transaction); + $this->assertEquals('SUCCESS', $transaction->responseCode); + $this->assertEquals(TransactionStatus::PREAUTHORIZED, $transaction->responseMessage); + + try { + $capture = $transaction->capture(30) + ->withGratuity(12) + ->execute(); + } catch (ApiException $e) { + $this->fail("Transaction capture failed"); + } + + $this->assertNotNull($capture); + $this->assertEquals('SUCCESS', $capture->responseCode); + $this->assertEquals(TransactionStatus::CAPTURED, $capture->responseMessage); + } + + public function testAuthorizationThenCaptureWithIdempotencyKey() + { + $transaction = $this->card->authorize(42) + ->withCurrency('USD') + ->withIdempotencyKey($this->idempotencyKey) + ->withAllowDuplicates(true) + ->execute(); + + $this->assertNotNull($transaction); + $this->assertEquals('SUCCESS', $transaction->responseCode); + $this->assertEquals(TransactionStatus::PREAUTHORIZED, $transaction->responseMessage); + + try { + $transaction->capture(30) + ->withIdempotencyKey($this->idempotencyKey) + ->withGratuity(12) + ->execute(); + } catch (GatewayException $e) { + $this->assertEquals('40039', $e->responseCode); + $this->assertContains('Idempotency Key seen before', $e->getMessage()); + } + } + + public function testCreditRefund() + { + try { + // process an auto-capture authorization + $response = $this->card->refund(16) + ->withCurrency("USD") + ->withAllowDuplicates(true) + ->execute(); + } catch (ApiException $e) { + $this->fail('Credit Card Refund failed ' . $e->getMessage()); + } + + $this->assertNotNull($response); + $this->assertEquals('SUCCESS', $response->responseCode); + $this->assertEquals(TransactionStatus::CAPTURED, $response->responseMessage); + } + + public function testCreditDefaultRefund() + { + try { + $transaction = $this->card->charge(50) + ->withCurrency("USD") + ->withAllowDuplicates(true) + ->execute(); + } catch (ApiException $e) { + $this->fail("Card not present with ECOM transaction failed"); + } + + $this->assertNotNull($transaction); + $this->assertEquals('SUCCESS', $transaction->responseCode); + $this->assertEquals(TransactionStatus::CAPTURED, $transaction->responseMessage); + + try { + $response = $transaction->refund() + ->withCurrency("USD") + ->withAllowDuplicates(true) + ->execute(); + } catch (ApiException $e) { + $this->fail('Credit Card Refund failed ' . $e->getMessage()); + } + + $this->assertNotNull($response); + $this->assertEquals('SUCCESS', $response->responseCode); + $this->assertEquals(TransactionStatus::CAPTURED, $response->responseMessage); + } + + public function testCreditRefund_WithIdempotencyKey() + { + $idempotencyKey = GenerationUtils::getGuid(); + try { + $transaction = $this->card->charge(50) + ->withCurrency("USD") + ->withIdempotencyKey($idempotencyKey) + ->withAllowDuplicates(true) + ->execute(); + } catch (ApiException $e) { + $this->fail("Card not present with ECOM transaction failed"); + } + + $this->assertNotNull($transaction); + $this->assertEquals('SUCCESS', $transaction->responseCode); + $this->assertEquals(TransactionStatus::CAPTURED, $transaction->responseMessage); + + try { + $transaction->refund(50) + ->withCurrency("USD") + ->withIdempotencyKey($idempotencyKey) + ->withAllowDuplicates(true) + ->execute(); + } catch (GatewayException $e) { + $this->assertEquals('40039', $e->responseCode); + $this->assertContains('Idempotency Key seen before', $e->getMessage()); + } + } + + public function testTransactionThenRefund() + { + try { + $transaction = $this->card->charge(50) + ->withCurrency("USD") + ->withAllowDuplicates(true) + ->execute(); + } catch (ApiException $e) { + $this->fail("Card not present with ECOM transaction failed"); + } + + $this->assertNotNull($transaction); + $this->assertEquals('SUCCESS', $transaction->responseCode); + $this->assertEquals(TransactionStatus::CAPTURED, $transaction->responseMessage); + + try { + $partialRefund = $transaction->refund('22') + ->withCurrency('USD') + ->execute(); + $defaultRefund = $transaction->refund() + ->withCurrency('USD') + ->execute(); + } catch (ApiException $e) { + $this->fail("Card not present managed refund failed " . $e->getMessage()); + } + + $this->assertNotNull($partialRefund); + $this->assertEquals('SUCCESS', $partialRefund->responseCode); + $this->assertEquals(TransactionStatus::CAPTURED, $partialRefund->responseMessage); + + $this->assertNotNull($defaultRefund); + $this->assertEquals('SUCCESS', $defaultRefund->responseCode); + $this->assertEquals(TransactionStatus::CAPTURED, $defaultRefund->responseMessage); + } + + public function testTransactionThenReversal() + { + try { + $transaction = $this->card->charge(20) + ->withCurrency("EUR") + ->withAllowDuplicates(true) + ->execute(); + } catch (ApiException $e) { + $this->fail("Card not present with ECOM transaction failed"); + } + + $this->assertNotNull($transaction); + $this->assertEquals('SUCCESS', $transaction->responseCode); + $this->assertEquals(TransactionStatus::CAPTURED, $transaction->responseMessage); + + try { + $reverse = $transaction->reverse(20)->execute(); + } catch (ApiException $e) { + $this->fail("Card not present managed reversal failed"); + } + + $this->assertNotNull($reverse); + $this->assertEquals('SUCCESS', $reverse->responseCode); + $this->assertEquals(TransactionStatus::REVERSED, $reverse->responseMessage); + } + + public function testTransactionThenDefaultReversal() + { + try { + $transaction = $this->card->charge(20) + ->withCurrency("EUR") + ->withAllowDuplicates(true) + ->execute(); + } catch (ApiException $e) { + $this->fail("Card not present with ECOM transaction failed"); + } + + $this->assertNotNull($transaction); + $this->assertEquals('SUCCESS', $transaction->responseCode); + $this->assertEquals(TransactionStatus::CAPTURED, $transaction->responseMessage); + + try { + $defaultReversal = $transaction->reverse()->execute(); + } catch (ApiException $e) { + $this->fail("Card not present managed reversal failed"); + } + + $this->assertNotNull($defaultReversal); + $this->assertEquals('SUCCESS', $defaultReversal->responseCode); + $this->assertEquals(TransactionStatus::REVERSED, $defaultReversal->responseMessage); + } + + public function testReverseTransaction_WithIdempotencyKey() + { + $transaction = $this->card->charge(20) + ->withCurrency("EUR") + ->withAllowDuplicates(true) + ->withIdempotencyKey($this->idempotencyKey) + ->execute(); + + $this->assertNotNull($transaction); + $this->assertEquals('SUCCESS', $transaction->responseCode); + $this->assertEquals(TransactionStatus::CAPTURED, $transaction->responseMessage); + + try { + $transaction->reverse(20) + ->withIdempotencyKey($this->idempotencyKey) + ->execute(); + } catch (GatewayException $e) { + $this->assertEquals('40039', $e->responseCode); + $this->assertContains('Idempotency Key seen before', $e->getMessage()); + } + } + + public function testTransactionThenPartialReversal() + { + try { + $transaction = $this->card->charge(16) + ->withCurrency("EUR") + ->withAllowDuplicates(true) + ->execute(); + } catch (GatewayException $e) { + $this->fail("Card not present with ECOM transaction failed"); + } + + $this->assertNotNull($transaction); + $this->assertEquals('SUCCESS', $transaction->responseCode); + $this->assertEquals(TransactionStatus::CAPTURED, $transaction->responseMessage); + + try { + $transaction->reverse(10)->execute(); + } catch (GatewayException $e) { + $this->assertEquals('40006', $e->responseCode); + $this->assertEquals('Status Code: INVALID_REQUEST_DATA - partial reversal not supported', $e->getMessage()); + } + } + + public function testCreditAuthorizationForMultiCapture() + { + try { + $transaction = $this->card->authorize(42) + ->withCurrency('EUR') + ->withMultiCapture(true) + ->withAllowDuplicates(true) + ->execute(); + } catch (ApiException $e) { + $this->fail("Card Authorization Failed"); + } + + $this->assertNotNull($transaction); + $this->assertEquals('SUCCESS', $transaction->responseCode); + $this->assertEquals(TransactionStatus::PREAUTHORIZED, $transaction->responseMessage); + + $capture1 = $transaction->capture(10)->execute(); + + $this->assertNotNull($capture1); + $this->assertEquals('SUCCESS', $capture1->responseCode); + $this->assertEquals(TransactionStatus::CAPTURED, $capture1->responseMessage); + + $capture2 = $transaction->capture(20)->execute(); + + $this->assertNotNull($capture2); + $this->assertEquals('SUCCESS', $capture2->responseCode); + $this->assertEquals(TransactionStatus::CAPTURED, $capture2->responseMessage); + + $capture3 = $transaction->capture(10)->execute(); + + $this->assertNotNull($capture3); + $this->assertEquals('SUCCESS', $capture3->responseCode); + $this->assertEquals(TransactionStatus::CAPTURED, $capture3->responseMessage); + } + + public function testCreditChargeTransactions_WithSameIdempotencyKey() + { + $response = $this->card->charge(69) + ->withCurrency("EUR") + ->withIdempotencyKey($this->idempotencyKey) + ->execute(); + + $this->assertNotNull($response); + $this->assertEquals('SUCCESS', $response->responseCode); + $this->assertEquals(TransactionStatus::CAPTURED, $response->responseMessage); + + $exceptionCaught = false; + try { + $this->card->charge(69) + ->withCurrency("EUR") + ->withIdempotencyKey($this->idempotencyKey) + ->execute(); + } catch (GatewayException $e) { + $exceptionCaught = true; + $this->assertEquals( + sprintf( + "Status Code: %s - Idempotency Key seen before: id=%s, status=%s", + 'DUPLICATE_ACTION', + $response->transactionId, + TransactionStatus::CAPTURED + ), $e->getMessage() + ); + } finally { + $this->assertTrue($exceptionCaught); + } + } + + public function testCardTokenization() + { + try { + // process an auto-capture authorization + $response = $this->card->tokenize()->execute(); + } catch (ApiException $e) { + $this->fail('Credit Card Tokenization failed ' . $e->getMessage()); + } + + $this->assertNotNull($response); + $this->assertEquals('SUCCESS', $response->responseCode); + $this->assertEquals('ACTIVE', $response->responseMessage); + } + + public function testCardTokenization_MissingCardNumber() + { + $card = new CreditCardData(); + + try { + $card->tokenize()->execute(); + } catch (ApiException $e) { + $this->assertEquals('40005', $e->responseCode); + $this->assertEquals('Status Code: MANDATORY_DATA_MISSING - Request expects the following fields : number', $e->getMessage()); + } + } + + public function testCardTokenizationWithIdempotencyKey() + { + $response = $this->card->tokenizeWithIdempotencyKey($this->idempotencyKey)->execute(); + + $this->assertNotNull($response); + $this->assertEquals('SUCCESS', $response->responseCode); + $this->assertEquals('ACTIVE', $response->responseMessage); + + try { + $this->card->tokenizeWithIdempotencyKey($this->idempotencyKey)->execute(); + } catch (GatewayException $e) { + $this->assertEquals('40039', $e->responseCode); + $this->assertContains('Idempotency Key seen before', $e->getMessage()); + } + } + + public function testCardTokenizationThenPayingWithToken() + { + // process an auto-capture authorization + $response = $this->card->tokenize() + ->execute(); + $tokenId = $response->token; + + $tokenizedCard = new CreditCardData(); + $tokenizedCard->token = $tokenId; + $tokenizedCard->cardHolderName = "James Mason"; + + $response = $tokenizedCard->charge(69) + ->withCurrency("EUR") + ->withOrderId("124214-214221") + ->execute(); + + $this->assertNotNull($response); + $this->assertEquals('SUCCESS', $response->responseCode); + $this->assertEquals(TransactionStatus::CAPTURED, $response->responseMessage); + } + + public function testVerifyTokenizedPaymentMethod() + { + try { + // process an auto-capture authorization + $response = $this->card->tokenize() + ->execute(); + + } catch (ApiException $e) { + $this->fail('Credit Card Tokenization failed ' . $e->getMessage()); + } + $tokenizedCard = new CreditCardData(); + $tokenizedCard->token = $response->token; + + try { + $response = $tokenizedCard->verify()->execute(); + } catch (ApiException $e) { + $this->fail('Credit Card token retrieval failed ' . $e->getMessage()); + } + + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode); + $this->assertEquals('ACTIVE', $response->responseMessage); + } + + public function testVerifyTokenizedPaymentMethodWithIdempotencyKey() + { + try { + // process an auto-capture authorization + $response = $this->card->tokenize() + ->execute(); + + } catch (ApiException $e) { + $this->fail('Credit Card Tokenization failed ' . $e->getMessage()); + } + $tokenizedCard = new CreditCardData(); + $tokenizedCard->token = $response->token; + + try { + $response = $tokenizedCard->verify()->withIdempotencyKey($this->idempotencyKey)->execute(); + } catch (ApiException $e) { + $this->fail('Credit Card token retrieval failed ' . $e->getMessage()); + } + + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode); + $this->assertEquals('ACTIVE', $response->responseMessage); + + try { + $tokenizedCard->verify()->withIdempotencyKey($this->idempotencyKey)->execute(); + } catch (GatewayException $e) { + $this->assertEquals('40039', $e->responseCode); + $this->assertContains('Idempotency Key seen before', $e->getMessage()); + } + } + + public function testVerifyTokenizedPaymentMethod_WrongID() + { + $tokenizedCard = new CreditCardData(); + $tokenizedCard->token = "PMT_" . GenerationUtils::getGuid(); + + try { + $tokenizedCard->verify()->execute(); + } catch (ApiException $e) { + $this->assertEquals('40118', $e->responseCode); + $this->assertEquals('Status Code: RESOURCE_NOT_FOUND - PAYMENT_METHODS ' . $tokenizedCard->token . ' not found at this /ucp/payment-methods/' . $tokenizedCard->token, $e->getMessage()); + } + } + + public function testDetokenizePaymentMethodWithIdempotencyKey() + { + try { + // process an auto-capture authorization + $response = $this->card->tokenize() + ->execute(); + + } catch (ApiException $e) { + $this->fail('Credit Card Tokenization failed ' . $e->getMessage()); + } + $tokenizedCard = new CreditCardData(); + $tokenizedCard->token = $response->token; + + $detokenizedCard = $tokenizedCard->detokenizeWithIdempotencyKey($this->idempotencyKey); + $this->assertNotNull($response); + $this->assertEquals($this->card->number, $detokenizedCard->cardNumber); + $this->assertEquals($this->card->expMonth, $detokenizedCard->cardExpMonth); +// $this->assertEquals($this->card->expYear, $detokenizedCard->cardExpYear); + + try { + $tokenizedCard->detokenizeWithIdempotencyKey($this->idempotencyKey); + } catch (GatewayException $e) { + $this->assertEquals('40039', $e->responseCode); + $this->assertContains('Idempotency Key seen before', $e->getMessage()); + } + } + + public function testCreditVerify() + { + $response = $this->card->verify() + ->withCurrency('USD') + ->execute(); + + $this->assertNotNull($response); + $this->assertEquals('SUCCESS', $response->responseCode); + $this->assertEquals('VERIFIED', $response->responseMessage); + } + + public function testCreditVerifyWithIdempotencyKey() + { + $response = $this->card->verify() + ->withCurrency('USD') + ->withIdempotencyKey($this->idempotencyKey) + ->execute(); + + $this->assertNotNull($response); + $this->assertEquals('SUCCESS', $response->responseCode); + $this->assertEquals('VERIFIED', $response->responseMessage); + } + + public function testCardTokenizationThenCardDetokenization() + { + try { + // process an auto-capture authorization + $response = $this->card->tokenize() + ->execute(); + + } catch (ApiException $e) { + $this->fail('Credit Card Tokenization failed ' . $e->getMessage()); + } + + $tokenId = $response->token; + + $tokenizedCard = new CreditCardData(); + $tokenizedCard->token = $tokenId; + + try { + $response = $tokenizedCard->detokenize(); + } catch (ApiException $e) { + $this->fail('Credit Card detokenization failed ' . $e->getMessage()); + } + + $this->assertEquals('SUCCESS', $response->responseCode); + } + + public function testCardDetokenization_WrongId() + { + $tokenizedCard = new CreditCardData(); + $tokenizedCard->token = "PMT_" . GenerationUtils::getGuid(); + + try { + $tokenizedCard->detokenize(); + } catch (ApiException $e) { + $this->assertEquals('40116', $e->responseCode); + $this->assertEquals('Status Code: RESOURCE_NOT_FOUND - payment_method ' . $tokenizedCard->token . ' not found at this location.', $e->getMessage()); + } + } + + public function testCardTokenizationThenDeletion() + { + // process an auto-capture authorization + $response = $this->card->tokenize() + ->execute(); + $tokenId = $response->token; + + $tokenizedCard = new CreditCardData(); + $tokenizedCard->token = $tokenId; + + $response = $tokenizedCard->deleteToken(); + $this->assertEquals(true, $response); + + $response = $tokenizedCard->deleteToken(); + $this->assertEquals(false, $response); + } + + public function testCardTokenizationThenDeletion_WithIdempotencyKey() + { + // process an auto-capture authorization + $response = $this->card->tokenize() + ->execute(); + $tokenId = $response->token; + + $tokenizedCard = new CreditCardData(); + $tokenizedCard->token = $tokenId; + + $response = $tokenizedCard->deleteTokenWithIdempotencyKey($this->idempotencyKey); + $this->assertEquals(true, $response); + + try { + $tokenizedCard->deleteTokenWithIdempotencyKey($this->idempotencyKey); + } catch (GatewayException $e) { + $this->assertEquals('40039', $e->responseCode); + $this->assertContains('Idempotency Key seen before', $e->getMessage()); + } + } + + public function testCardDelete_WrongId() + { + $tokenizedCard = new CreditCardData(); + $tokenizedCard->token = "PMT_" . GenerationUtils::getGuid(); + + try { + $tokenizedCard->deleteToken(); + } catch (ApiException $e) { + $this->assertEquals('40006', $e->responseCode); + $this->assertEquals('Status Code: INVALID_REQUEST_DATA - payment_method.id: ' . $tokenizedCard->token . ' contains unexpected data', $e->getMessage()); + } + } + + public function testCardTokenizationThenUpdate() + { + try { + // process an auto-capture authorization + $response = $this->card->tokenize()->execute(); + } catch (ApiException $e) { + $this->fail('Credit Card Tokenization failed ' . $e->getMessage()); + } + $this->assertNotNull($response); + + $tokenizedCard = new CreditCardData(); + $tokenizedCard->token = $response->token; + $tokenizedCard->expYear = date('Y', strtotime('+1 year')); + $tokenizedCard->expMonth = date('m'); + + try { + $response = $tokenizedCard->updateTokenExpiry(); + } catch (ApiException $e) { + $this->fail('Credit Card token update failed ' . $e->getMessage()); + } + + $this->assertEquals(true, $response); + } + + public function testCardUpdate_WrongId() + { + $tokenizedCard = new CreditCardData(); + $tokenizedCard->token = "PMT_" . GenerationUtils::getGuid(); + $tokenizedCard->expYear = date('Y', strtotime('+1 year')); + $tokenizedCard->expMonth = date('m'); + + try { + $tokenizedCard->updateTokenExpiry(); + } catch (ApiException $e) { + $this->assertEquals('40006', $e->responseCode); + $this->assertEquals('Status Code: INVALID_REQUEST_DATA - payment_method.id: ' . $tokenizedCard->token . ' contains unexpected data', $e->getMessage()); + } + } + + public function testCardTokenizationThenUpdateWithIdempotencyKey() + { + try { + // process an auto-capture authorization + $response = $this->card->tokenize()->execute(); + } catch (ApiException $e) { + $this->fail('Credit Card Tokenization failed ' . $e->getMessage()); + } + $this->assertNotNull($response); + + $tokenizedCard = new CreditCardData(); + $tokenizedCard->token = $response->token; + $tokenizedCard->expYear = date('Y', strtotime('+1 year')); + $tokenizedCard->expMonth = date('m'); + + $this->assertTrue($tokenizedCard->updateTokenExpiryWithIdemPotencyKey($this->idempotencyKey)); + $this->assertFalse($tokenizedCard->updateTokenExpiryWithIdemPotencyKey($this->idempotencyKey)); + try { + $tokenizedCard->updateTokenExpiryWithIdemPotencyKey($this->idempotencyKey); + } catch (ApiException $e) { + $this->assertEquals('40031', $e->responseCode); + $this->assertContains('Idempotency Key seen before', $e->getMessage()); + } + + $response = $tokenizedCard->verify()->execute(); + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode); + $this->assertEquals('ACTIVE', $response->responseMessage); + + $tokenizedCard->expYear = date('Y', strtotime('+2 year')); + $this->assertTrue($tokenizedCard->updateTokenExpiry()); + } + + public function testCreditRefundTransactionWrongId() + { + $transaction = new Transaction(); + $transaction->transactionId = GenerationUtils::getGuid(); + try { + $transaction->refund(10) + ->withCurrency('USD') + ->withAllowDuplicates(true) + ->execute(); + } catch (GatewayException $e) { + $this->assertEquals('40118', $e->responseCode); + $this->assertContains('RESOURCE_NOT_FOUND', $e->getMessage()); + } + } + + public function testCreditRefundTransactionWithIdempotencyKey() + { + $transaction = $this->card->charge(10.22) + ->withCurrency('USD') + ->withIdempotencyKey($this->idempotencyKey) + ->withAllowDuplicates(true) + ->execute(); + + $this->assertNotNull($transaction); + $this->assertEquals('SUCCESS', $transaction->responseCode); + $this->assertEquals(TransactionStatus::CAPTURED, $transaction->responseMessage); + + try { + $transaction->refund(10.22) + ->withCurrency('USD') + ->withIdempotencyKey($this->idempotencyKey) + ->withAllowDuplicates(true) + ->execute(); + } catch (GatewayException $e) { + $this->assertEquals('40039', $e->responseCode); + $this->assertContains('Idempotency Key seen before', $e->getMessage()); + } + } + + public function testCreditSale_WithStoredCredentials() + { + $storeCredentials = new StoredCredential(); + $storeCredentials->initiator = StoredCredentialInitiator::MERCHANT; + $storeCredentials->type = StoredCredentialType::INSTALLMENT; + $storeCredentials->sequence = StoredCredentialSequence::SUBSEQUENT; + $storeCredentials->reason = StoredCredentialReason::INCREMENTAL; + + $response = $this->card->tokenize() + ->execute(); + $tokenId = $response->token; + $tokenizedCard = new CreditCardData(); + $tokenizedCard->token = $tokenId; + $tokenizedCard->cardHolderName = "James Mason"; + $response = $tokenizedCard->charge(50) + ->withCurrency("EUR") + ->withStoredCredential($storeCredentials) + ->execute(); + + $this->assertNotNull($response); + $this->assertEquals('SUCCESS', $response->responseCode); + $this->assertEquals(TransactionStatus::CAPTURED, $response->responseMessage); + } + + public function testCreditReverseTransactionWrongId() + { + $transaction = new Transaction(); + $transaction->transactionId = GenerationUtils::getGuid(); + try { + $transaction->reverse() + ->withCurrency('USD') + ->withAllowDuplicates(true) + ->execute(); + } catch (GatewayException $e) { + $this->assertEquals('40118', $e->responseCode); + $this->assertContains('RESOURCE_NOT_FOUND', $e->getMessage()); + } + } + + public function testCreditVerification() + { + $response = $this->card->verify() + ->withCurrency("USD") + ->execute(); + + $this->assertNotNull($response); + $this->assertEquals('SUCCESS', $response->responseCode); + $this->assertEquals("VERIFIED", $response->responseMessage); + } + + public function testCreditVerification_withIdempotencyKey() + { + $idempotencyKey = GenerationUtils::getGuid(); + + $response = $this->card->verify() + ->withIdempotencyKey($idempotencyKey) + ->withCurrency("USD") + ->execute(); + + $this->assertNotNull($response); + $this->assertEquals('SUCCESS', $response->responseCode); + $this->assertEquals("VERIFIED", $response->responseMessage); + + $exceptionCaught = false; + try { + $this->card->verify() + ->withIdempotencyKey($idempotencyKey) + ->withCurrency("USD") + ->execute(); + } catch (GatewayException $e) { + $exceptionCaught = true; + $this->assertEquals('40039', $e->responseCode); + $this->assertContains('Status Code: DUPLICATE_ACTION - Idempotency Key seen before: ', $e->getMessage()); + } finally { + $this->assertTrue($exceptionCaught); + } + } + + public function testCreditVerification_WithAddress() + { + $address = new Address(); + $address->streetAddress1 = "123 Main St."; + $address->city = "Downtown"; + $address->state = "NJ"; + $address->country = "US"; + $address->postalCode = "12345"; + + $response = $this->card->verify() + ->withCurrency("USD") + ->withAddress($address) + ->execute(); + + $this->assertNotNull($response); + $this->assertEquals('SUCCESS', $response->responseCode); + $this->assertEquals("VERIFIED", $response->responseMessage); + } + + public function testCreditVerification_WithoutCurrency() + { + try { + $this->card->verify() + ->execute(); + } catch (GatewayException $e) { + $this->assertEquals('40005', $e->responseCode); + $this->assertEquals('Status Code: MANDATORY_DATA_MISSING - Request expects the following fields currency', $e->getMessage()); + } + } + + public function testCreditVerification_InvalidCVV() + { + $this->card->cvn = "1234"; + + try { + $this->card->verify() + ->withCurrency("USD") + ->execute(); + } catch (GatewayException $e) { + $this->assertEquals('40085', $e->responseCode); + $this->assertEquals('Status Code: INVALID_REQUEST_DATA - Security Code/CVV2/CVC must be 3 digits', $e->getMessage()); + } + } + + public function setUpConfig() + { + $config = new GpApiConfig(); + $accessTokenInfo = new AccessTokenInfo(); + //this is gpapistuff stuff + $config->setAppId('VuKlC2n1cr5LZ8fzLUQhA7UObVks6tFF'); + $config->setAppKey('NmGM0kg92z2gA7Og'); + $config->environment = Environment::TEST; + $config->setAccessTokenInfo($accessTokenInfo); + $config->setChannel(Channels::CardNotPresent); + + return $config; + } + +} \ No newline at end of file diff --git a/test/Integration/Gateways/GpApiConnector/CreditCardPresentTest.php b/test/Integration/Gateways/GpApiConnector/CreditCardPresentTest.php new file mode 100644 index 00000000..8a4d5854 --- /dev/null +++ b/test/Integration/Gateways/GpApiConnector/CreditCardPresentTest.php @@ -0,0 +1,115 @@ +setUpConfig()); + } + + public function setUpConfig() + { + $config = new GpApiConfig(); + $accessTokenInfo = new AccessTokenInfo(); + //this is gpapistuff stuff + $config->setAppId('VuKlC2n1cr5LZ8fzLUQhA7UObVks6tFF'); + $config->setAppKey('NmGM0kg92z2gA7Og'); + $config->environment = Environment::TEST; + $config->setAccessTokenInfo($accessTokenInfo); + $config->setChannel(Channels::CardPresent); + + return $config; + } + + public function testCardPresentWithChipTransaction() + { + $card = new CreditTrackData(); + $card->setTrackData('%B4012002000060016^VI TEST CREDIT^251210118039000000000396?;4012002000060016=25121011803939600000?'); + $card->entryMethod = EntryMethod::SWIPE; + + $response = $card->charge(19) + ->withCurrency("EUR") + ->withChipCondition(EmvLastChipRead::SUCCESSFUL) + ->withAllowDuplicates(true) + ->execute(); + + $this->assertEquals('SUCCESS', $response->responseCode); + } + + public function testCardPresentWithSwipeTransaction() + { + $card = new CreditTrackData(); + $card->setTrackData('%B4012002000060016^VI TEST CREDIT^251210118039000000000396?;4012002000060016=25121011803939600000?'); + $card->entryMethod = EntryMethod::SWIPE; + + $response = $card->authorize(16) + ->withCurrency("EUR") + ->withOrderId("124214-214221") + ->withAllowDuplicates(true) + ->execute(); + + $this->assertEquals('SUCCESS', $response->responseCode); + } + + public function testRefundOnCardPresentChipCard() + { + $card = new CreditTrackData(); + $card->setTrackData('%B4012002000060016^VI TEST CREDIT^251210118039000000000396?;4012002000060016=25121011803939600000?'); + $tag = '9F4005F000F0A0019F02060000000025009F03060000000000009F2608D90A06501B48564E82027C005F3401019F360200029F0702FF009F0802008C9F0902008C9F34030403029F2701809F0D05F0400088009F0E0508000000009F0F05F0400098005F280208409F390105FFC605DC4000A800FFC7050010000000FFC805DC4004F8009F3303E0B8C89F1A0208409F350122950500000080005F2A0208409A031409109B02E8009F21030811539C01009F37045EED3A8E4F07A00000000310109F0607A00000000310108407A00000000310109F100706010A03A400029F410400000001'; + + $response = $card->refund(19) + ->withCurrency("EUR") + ->withOrderId("124214-214221") + ->withTagData($tag) + ->execute(); + + $this->assertEquals('SUCCESS', $response->responseCode); + } + + public function testCreditVerification_CardPresent() + { + $card = new CreditTrackData(); + $card->setTrackData('%B4012002000060016^VI TEST CREDIT^251210118039000000000396?;4012002000060016=25121011803939600000?'); + $card->entryMethod = EntryMethod::SWIPE; + + $response = $card->verify() + ->withCurrency("USD") + ->execute(); + + $this->assertNotNull($response); + $this->assertEquals('SUCCESS', $response->responseCode); + $this->assertEquals("VERIFIED", $response->responseMessage); + } + + public function testCreditVerification_CardPresent_CVNNotMatched() + { + $card = new CreditCardData(); + $card->number = "4263970000005262"; + $card->expMonth = date('m'); + $card->expYear = date('Y', strtotime('+1 year')); + $card->cvn = "852"; + $card->cardHolderName = "James Mason"; + + $response = $card->verify() + ->withCurrency("USD") + ->execute(); + + $this->assertNotNull($response); + $this->assertEquals('NOT_VERIFIED', $response->responseCode); + $this->assertEquals("NOT_VERIFIED", $response->responseMessage); + } + +} \ No newline at end of file diff --git a/test/Integration/Gateways/GpApiConnector/DebitCardTest.php b/test/Integration/Gateways/GpApiConnector/DebitCardTest.php new file mode 100644 index 00000000..6eeb3788 --- /dev/null +++ b/test/Integration/Gateways/GpApiConnector/DebitCardTest.php @@ -0,0 +1,150 @@ +setUpConfig()); + } + + public function testDebitSaleSwipe() + { + $debitCard = new DebitTrackData(); + $debitCard->value = '%B4012002000060016^VI TEST CREDIT^251210118039000000000396?;4012002000060016=25121011803939600000?'; + $debitCard->pinBlock = '32539F50C245A6A93D123412324000AA'; + $debitCard->entryMethod = EntryMethod::SWIPE; + + $response = $debitCard->charge(18) + ->withCurrency("EUR") + ->withAllowDuplicates(true) + ->execute(); + + $this->assertNotNull($response); + $this->assertEquals('SUCCESS', $response->responseCode); + $this->assertEquals(TransactionStatus::CAPTURED, $response->responseMessage); + } + + public function testDebitRefundSwipe() + { + $debitCard = new DebitTrackData(); + $debitCard->value = '%B4012002000060016^VI TEST CREDIT^251210118039000000000396?;4012002000060016=25121011803939600000?'; + $debitCard->pinBlock = '32539F50C245A6A93D123412324000AA'; + $debitCard->entryMethod = EntryMethod::SWIPE; + + $response = $debitCard->refund(18) + ->withCurrency("EUR") + ->withAllowDuplicates(true) + ->execute(); + + $this->assertNotNull($response); + $this->assertEquals('SUCCESS', $response->responseCode); + $this->assertEquals(TransactionStatus::CAPTURED, $response->responseMessage); + } + + public function testDebitRefundChip() + { + $debitCard = new DebitTrackData(); + $debitCard->setTrackData("%B4012002000060016^VI TEST CREDIT^251210118039000000000396?;4012002000060016=25121011803939600000?"); + $debitCard->entryMethod = EntryMethod::SWIPE; + $tagData = "9F4005F000F0A0019F02060000000025009F03060000000000009F2608D90A06501B48564E82027C005F3401019F360200029F0702FF009F0802008C9F0902008C9F34030403029F2701809F0D05F0400088009F0E0508000000009F0F05F0400098005F280208409F390105FFC605DC4000A800FFC7050010000000FFC805DC4004F8009F3303E0B8C89F1A0208409F350122950500000080005F2A0208409A031409109B02E8009F21030811539C01009F37045EED3A8E4F07A00000000310109F0607A00000000310108407A00000000310109F100706010A03A400029F410400000001"; + $response = $debitCard->refund(18) + ->withCurrency("EUR") + ->withAllowDuplicates(true) + ->withTagData($tagData) + ->execute(); + + $this->assertNotNull($response); + $this->assertEquals('SUCCESS', $response->responseCode); + $this->assertEquals(TransactionStatus::CAPTURED, $response->responseMessage); + } + + public function testDebitReverse() + { + $debitCard = new DebitTrackData(); + $debitCard->value = '%B4012002000060016^VI TEST CREDIT^251210118039000000000396?;4012002000060016=25121011803939600000?'; + $debitCard->pinBlock = '32539F50C245A6A93D123412324000AA'; + $debitCard->entryMethod = EntryMethod::SWIPE; + + $transaction = $debitCard->charge(18) + ->withCurrency("USD") + ->withAllowDuplicates(true) + ->execute(); + + $this->assertNotNull($transaction); + $this->assertEquals('SUCCESS', $transaction->responseCode); + $this->assertEquals(TransactionStatus::CAPTURED, $transaction->responseMessage); + + $response = $transaction->reverse() + ->withCurrency("USD") + ->execute(); + + $this->assertNotNull($response); + $this->assertEquals('SUCCESS', $response->responseCode); + $this->assertEquals(TransactionStatus::REVERSED, $response->responseMessage); + } + + public function testDebitSaleSwipeEncrypted() + { + $debitCard = new DebitTrackData(); + $debitCard->value = '%B4012002000060016^VI TEST CREDIT^251210118039000000000396?;4012002000060016=25121011803939600000?'; + $debitCard->pinBlock = '32539F50C245A6A93D123412324000AA'; + $debitCard->entryMethod = EntryMethod::SWIPE; + $debitCard->encryptionData = EncryptionData::version1(); + + $response = $debitCard->charge(18) + ->withCurrency("EUR") + ->withAllowDuplicates(true) + ->execute(); + + $this->assertNotNull($response); + $this->assertEquals('SUCCESS', $response->responseCode); + $this->assertEquals(TransactionStatus::CAPTURED, $response->responseMessage); + } + + public function testDebitSaleSwipeChip() + { + $debitCard = new DebitTrackData(); + $debitCard->value = ';4024720012345671=18125025432198712345?'; + $debitCard->pinBlock = 'AFEC374574FC90623D010000116001EE'; + $debitCard->entryMethod = EntryMethod::SWIPE; + $tagData = '82021C008407A0000002771010950580000000009A031709289C01005F280201245F2A0201245F3401019F02060000000010009F03060000000000009F080200019F090200019F100706010A03A420009F1A0201249F26089CC473F4A4CE18D39F2701809F3303E0F8C89F34030100029F3501229F360200639F370435EFED379F410400000019'; + $response = $debitCard->charge(100) + ->withCurrency("USD") + ->withAllowDuplicates(true) + ->withTagData($tagData) + ->execute(); + + $this->assertNotNull($response); + $this->assertEquals('SUCCESS', $response->responseCode); + $this->assertEquals(TransactionStatus::CAPTURED, $response->responseMessage); + } + + public function setUpConfig() + { + $config = new GpApiConfig(); + $accessTokenManager = new AccessTokenInfo(); + //this is gpapistuff stuff + $config->setAppId('i872l4VgZRtSrykvSn8Lkah8RE1jihvT'); + $config->setAppKey( '9pArW2uWoA8enxKc'); + $config->environment = Environment::TEST; + $config->setAccessTokenInfo($accessTokenManager); + $config->setChannel(Channels::CardPresent); + + return $config; + } +} \ No newline at end of file diff --git a/test/Integration/Gateways/GpApiConnector/EbtCardTest.php b/test/Integration/Gateways/GpApiConnector/EbtCardTest.php new file mode 100644 index 00000000..841014cc --- /dev/null +++ b/test/Integration/Gateways/GpApiConnector/EbtCardTest.php @@ -0,0 +1,62 @@ +setUpConfig()); + $this->card = TestCards::asEBTManual(TestCards::visaManual(), '32539F50C245A6A93D123412324000AA'); + } + + public function setUpConfig() + { + $config = new GpApiConfig(); + $accessTokenInfo = new AccessTokenInfo(); + //this is gpapistuff stuff + $config->setAppId('VuKlC2n1cr5LZ8fzLUQhA7UObVks6tFF'); + $config->setAppKey('NmGM0kg92z2gA7Og'); + $config->environment = Environment::TEST; + $config->setAccessTokenInfo($accessTokenInfo); + $config->setChannel(Channels::CardPresent); + + return $config; + } + + public function testEbtSale() + { + $response = $this->card->charge(10) + ->withCurrency('USD') + ->execute(); + + $this->assertNotNull($response); + $this->assertEquals('SUCCESS', $response->responseCode); + $this->assertEquals(TransactionStatus::CAPTURED, $response->responseMessage); + } + + public function testEbtRefund() + { + $response = $this->card->refund(10) + ->withCurrency('USD') + ->execute(); + + $this->assertNotNull($response); + $this->assertEquals('SUCCESS', $response->responseCode); + $this->assertEquals(TransactionStatus::CAPTURED, $response->responseMessage); + } + +} \ No newline at end of file diff --git a/test/Integration/Gateways/GpApiConnector/GpApi3DSecureTest.php b/test/Integration/Gateways/GpApiConnector/GpApi3DSecureTest.php new file mode 100644 index 00000000..700b3efe --- /dev/null +++ b/test/Integration/Gateways/GpApiConnector/GpApi3DSecureTest.php @@ -0,0 +1,449 @@ +setUpConfig()); + + $this->storedCard = new RecurringPaymentMethod( + "20190809-Realex", + "20190809-Realex-Credit" + ); + + $this->shippingAddress = new Address(); + $this->shippingAddress->streetAddress1 = "Apartment 852"; + $this->shippingAddress->streetAddress2 = "Complex 741"; + $this->shippingAddress->streetAddress3 = "no"; + $this->shippingAddress->city = "Chicago"; + $this->shippingAddress->postalCode = "5001"; + $this->shippingAddress->state = "IL"; + $this->shippingAddress->countryCode = "840"; + + $this->billingAddress = new Address(); + $this->billingAddress->streetAddress1 = "Flat 456"; + $this->billingAddress->streetAddress2 = "House 789"; + $this->billingAddress->streetAddress3 = "no"; + $this->billingAddress->city = "Halifax"; + $this->billingAddress->postalCode = "W5 9HR"; + $this->billingAddress->countryCode = "826"; + + $this->browserData = new BrowserData(); + $this->browserData->acceptHeader = "text/html,application/xhtml+xml,application/xml;q=9,image/webp,img/apng,*/*;q=0.8"; + $this->browserData->colorDepth = ColorDepth::TWENTY_FOUR_BITS; + $this->browserData->ipAddress = "123.123.123.123"; + $this->browserData->javaEnabled = true; + $this->browserData->javaScriptEnabled = true; + $this->browserData->language = "en"; + $this->browserData->screenHeight = 1080; + $this->browserData->screenWidth = 1920; + $this->browserData->challengWindowSize = ChallengeWindowSize::WINDOWED_600X400; + $this->browserData->timeZone = "0"; + $this->browserData->userAgent = "Mozilla/5.0 (Windows NT 6.1; Win64, x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.110 Safari/537.36"; + + } + + public function setUpConfig() + { + $config = new GpApiConfig(); + $accessTokenManager = new AccessTokenInfo(); + //this is gpapistuff stuff + $config->setAppId('P3LRVjtGRGxWQQJDE345mSkEh2KfdAyg'); + $config->setAppKey( 'ockJr6pv6KFoGiZA'); + $config->environment = Environment::TEST; + $config->setAccessTokenInfo($accessTokenManager); + $config->setChannel(Channels::CardNotPresent); + $config->setChallengeNotificationUrl('https://ensi808o85za.x.pipedream.net/'); + $config->setMethodNotificationUrl('https://ensi808o85za.x.pipedream.net/'); + + return $config; + } + + public function testFullCycle_v1() + { + $card = new CreditCardData(); + $card->number = '4012001037141112'; + $card->expMonth = '12'; + $card->expYear = date('Y', strtotime('+1 year')); + $card->cardHolderName = "James Mason"; + + $secureEcom = Secure3dService::checkEnrollment($card) + ->withCurrency('USD') + ->withAmount('10.01') + ->execute(); + + $this->assertNotNull($secureEcom); + + if ($secureEcom->enrolled == 'ENROLLED') { + $this->assertEquals(Secure3dVersion::ONE, $secureEcom->getVersion()); + if (strcmp($secureEcom->status, "AVAILABLE") === 0) { + $secureEcom =Secure3dService::getAuthenticationData() + ->withServerTransactionId($secureEcom->serverTransactionId) + ->execute(); + $card->threeDSecure = $secureEcom; + if (strcmp($secureEcom->status, 'SUCCESS_AUTHENTICATED') === 0) { + $response = $card->charge(10.01)->withCurrency('USD')->execute(); + $this->assertNotNull($response); + $this->assertEquals('SUCCESS', $response->responseCode); + $this->assertEquals( TransactionStatus::CAPTURED, $response->responseMessage); + } else { + $this->fail('Signature verification failed.'); + } + } else { + $this->fail("Expected status AVAILABLE. Current status: {$secureEcom->status}."); + } + } else { + $this->fail('Card not enrolled.'); + } + } + + public function testCardHolderEnrolled_ChallengeRequired_v1() + { + $card = new CreditCardData(); + $card->number = '4012001037141112'; + $card->expMonth = '12'; + $card->expYear = date('Y', strtotime('+1 year')); + $card->cardHolderName = "James Mason"; + + $secureEcom = Secure3dService::checkEnrollment($card) + ->withCurrency('USD') + ->withAmount('10.01') + ->execute(); + + $this->assertNotNull($secureEcom); + + if ($secureEcom->enrolled == 'ENROLLED') { + $this->assertEquals(Secure3dVersion::ONE, $secureEcom->getVersion()); + if (strcmp($secureEcom->status, 'CHALLENGE_REQUIRED') === 0) { + $this->assertTrue($secureEcom->challengeMandated); + $this->assertNotNull($secureEcom->issuerAcsUrl); + $this->assertNotNull( $secureEcom->challengeValue); + } else { + $this->fail("Expected status AVAILABLE. Current status: {$secureEcom->status}."); + } + } else { + $this->fail('Card not enrolled.'); + } + } + + public function testCardHolderNotEnrolled_v1() + { + $card = new CreditCardData(); + $card->number = '4917000000000087'; + $card->expMonth = '12'; + $card->expYear = date('Y', strtotime('+1 year')); + $card->cardHolderName = "James Mason"; + + $secureEcom = Secure3dService::checkEnrollment($card) + ->withCurrency('USD') + ->withAmount('10.01') + ->execute(); + + $this->assertNotNull($secureEcom); + $this->assertEquals(Secure3dVersion::ONE, $secureEcom->getVersion()); + $this->assertEquals( 'NOT_ENROLLED', $secureEcom->enrolled); + $this->assertEquals( 'NOT_ENROLLED', $secureEcom->status); + } + + /** + * Frictionless scenario + * + * @throws \GlobalPayments\Api\Entities\Exceptions\ApiException + */ + public function testFullCycle_v2() + { + $card = new CreditCardData(); + $card->number = '4263970000005262'; + $card->expMonth = '12'; + $card->expYear = date('Y', strtotime('+1 year')); + $card->cardHolderName = "James Mason"; + + $secureEcom = Secure3dService::checkEnrollment($card) + ->withCurrency('USD') + ->withAmount('10.01') + ->execute(); + + $this->assertNotNull($secureEcom); + + if ($secureEcom->enrolled == 'ENROLLED') { + $this->assertEquals(Secure3dVersion::TWO, $secureEcom->getVersion()); + if (strcmp($secureEcom->status, "AVAILABLE") === 0) { + $initAuth = Secure3dService::initiateAuthentication($card, $secureEcom) + ->withAmount(10.01) + ->withCurrency('USD') + ->withAuthenticationSource(AuthenticationSource::BROWSER) + ->withMethodUrlCompletion(MethodUrlCompletion::YES) + ->withOrderCreateDate(date('Y-m-d H:i:s')) + ->withAddress($this->billingAddress, AddressType::BILLING) + ->withAddress($this->shippingAddress, AddressType::SHIPPING) + ->withBrowserData($this->browserData) + ->execute(); + $this->assertNotNull($initAuth); + if (strcmp($initAuth->status, 'SUCCESS_AUTHENTICATED') === 0) { + $secureEcom = Secure3dService::getAuthenticationData() + ->withServerTransactionId($secureEcom->serverTransactionId) + ->execute(); + $card->threeDSecure = $initAuth; + if (strcmp($secureEcom->status, 'SUCCESS_AUTHENTICATED') === 0) { + $response = $card->charge(10.01)->withCurrency('USD')->execute(); + $this->assertNotNull($response); + $this->assertEquals('SUCCESS', $response->responseCode); + $this->assertEquals( TransactionStatus::CAPTURED, $response->responseMessage); + } else { + $this->fail('Signature verification failed.'); + } + } else { + $this->fail("Failed initiate authentication. Expected status SUCCESS_AUTHENTICATED. Current status: {$initAuth->status}."); + } + } else { + $this->fail("Expected status AVAILABLE. Current status: {$secureEcom->status}."); + } + } else { + $this->fail('Card not enrolled.'); + } + } + + /** + * Challenge scenario + * + * @throws \GlobalPayments\Api\Entities\Exceptions\ApiException + */ + public function testCardHolderEnrolled_ChallengeRequired_v2() + { + $card = new CreditCardData(); + $card->number = '4222000001227408'; + $card->expMonth = '12'; + $card->expYear = date('Y', strtotime('+1 year')); + $card->cardHolderName = "James Mason"; + + $secureEcom = Secure3dService::checkEnrollment($card) + ->withCurrency('USD') + ->withAmount('10.01') + ->execute(); + + $this->assertNotNull($secureEcom); + + if ($secureEcom->enrolled == 'ENROLLED') { + $this->assertEquals(Secure3dVersion::TWO, $secureEcom->getVersion()); + $this->assertEquals('AVAILABLE', $secureEcom->status); + $initAuth = Secure3dService::initiateAuthentication($card, $secureEcom) + ->withAmount(10.01) + ->withCurrency('USD') + ->withAuthenticationSource(AuthenticationSource::BROWSER) + ->withMethodUrlCompletion(MethodUrlCompletion::YES) + ->withOrderCreateDate(date('Y-m-d H:i:s')) + ->withAddress($this->billingAddress, AddressType::BILLING) + ->withAddress($this->shippingAddress, AddressType::SHIPPING) + ->withBrowserData($this->browserData) + ->execute(); + + $this->assertNotNull($initAuth); + $this->assertEquals('CHALLENGE_REQUIRED', $initAuth->status); + + $this->assertTrue($initAuth->challengeMandated); + $this->assertNotNull($initAuth->issuerAcsUrl); + $this->assertNotNull($initAuth->challengeValue); + $this->assertTrue($this->sendChallenge($initAuth->issuerAcsUrl, $initAuth->challengeValue)); + + $secureEcom = Secure3dService::getAuthenticationData() + ->withServerTransactionId($initAuth->serverTransactionId) + ->execute(); + $card->threeDSecure = $secureEcom; + + $this->assertEquals('SUCCESS_AUTHENTICATED', $secureEcom->status); + + $response = $card->charge(10.01)->withCurrency('USD')->execute(); + $this->assertNotNull($response); + $this->assertEquals('SUCCESS', $response->responseCode); + $this->assertEquals( TransactionStatus::CAPTURED, $response->responseMessage); + } else { + $this->fail('Card not enrolled.'); + } + } + + /** + * Challenge scenario + * + * @throws \GlobalPayments\Api\Entities\Exceptions\ApiException + */ + public function testChallengeRequired_GetResultFailed_v2() + { + $card = new CreditCardData(); + $card->number = '4222000001227408'; + $card->expMonth = '12'; + $card->expYear = date('Y', strtotime('+1 year')); + $card->cardHolderName = "James Mason"; + + $secureEcom = Secure3dService::checkEnrollment($card) + ->withCurrency('USD') + ->withAmount('10.01') + ->execute(); + + $this->assertNotNull($secureEcom); + + if ($secureEcom->enrolled == 'ENROLLED') { + $this->assertEquals(Secure3dVersion::TWO, $secureEcom->getVersion()); + if (strcmp($secureEcom->status, "AVAILABLE") === 0) { + $initAuth = Secure3dService::initiateAuthentication($card, $secureEcom) + ->withAmount(10.01) + ->withCurrency('USD') + ->withAuthenticationSource(AuthenticationSource::BROWSER) + ->withMethodUrlCompletion(MethodUrlCompletion::YES) + ->withOrderCreateDate(date('Y-m-d H:i:s')) + ->withAddress($this->billingAddress, AddressType::BILLING) + ->withAddress($this->shippingAddress, AddressType::SHIPPING) + ->withBrowserData($this->browserData) + ->execute(); + + $this->assertNotNull($initAuth); + if (strcmp($initAuth->status, 'CHALLENGE_REQUIRED') === 0) { + $this->assertTrue($initAuth->challengeMandated); + $this->assertNotNull($initAuth->issuerAcsUrl); + $this->assertNotNull($initAuth->challengeValue); + $secureEcom = Secure3dService::getAuthenticationData() + ->withServerTransactionId($initAuth->serverTransactionId) + ->execute(); + $this->assertEquals('FAILED', $secureEcom->status); + } else { + $this->fail("Failed initiate authentication. Expected status CHALLENGE_REQUIRED. Current status: {$initAuth->status}."); + } + } else { + $this->fail("Expected status AVAILABLE. Current status: {$secureEcom->status}."); + } + } else { + $this->fail('Card not enrolled.'); + } + } + + /** + * Frictionless scenario with tokenize card + * + * @throws \GlobalPayments\Api\Entities\Exceptions\ApiException + */ + public function testFullCycle_WithCardTokenization_v2() + { + $card = new CreditCardData(); + $card->number = '4263970000005262'; + $card->expMonth = '12'; + $card->expYear = date('Y', strtotime('+1 year')); + + $response = $card->tokenize()->execute(); + $tokenId = $response->token; + + $tokenizedCard = new CreditCardData(); + $tokenizedCard->token = $tokenId; + $tokenizedCard->cardHolderName = "James Mason"; + + $secureEcom = Secure3dService::checkEnrollment($tokenizedCard) + ->withCurrency('USD') + ->withAmount('10.01') + ->execute(); + + $this->assertNotNull($secureEcom); + + if ($secureEcom->enrolled == 'ENROLLED') { + $this->assertEquals(Secure3dVersion::TWO, $secureEcom->getVersion()); + if (strcmp($secureEcom->status, "AVAILABLE") === 0) { + $initAuth = Secure3dService::initiateAuthentication($tokenizedCard, $secureEcom) + ->withAmount(10.01) + ->withCurrency('USD') + ->withAuthenticationSource(AuthenticationSource::BROWSER) + ->withMethodUrlCompletion(MethodUrlCompletion::YES) + ->withOrderCreateDate(date('Y-m-d H:i:s')) + ->withAddress($this->billingAddress, AddressType::BILLING) + ->withAddress($this->shippingAddress, AddressType::SHIPPING) + ->withBrowserData($this->browserData) + ->execute(); + + $this->assertNotNull($initAuth); + if (strcmp($initAuth->status, 'SUCCESS_AUTHENTICATED') === 0) { + $secureEcom = Secure3dService::getAuthenticationData() + ->withServerTransactionId($secureEcom->serverTransactionId) + ->execute(); + $tokenizedCard->threeDSecure = $secureEcom; + if (strcmp($secureEcom->status, 'SUCCESS_AUTHENTICATED') === 0) { + $response = $tokenizedCard->charge(10.01)->withCurrency('USD')->execute(); + $this->assertNotNull($response); + $this->assertEquals('SUCCESS', $response->responseCode); + $this->assertEquals( TransactionStatus::CAPTURED, $response->responseMessage); + } else { + $this->fail('Signature verification failed.'); + } + } else { + $this->fail("Failed initiate authentication. Expected status SUCCESS_AUTHENTICATED. Current status: {$initAuth->status}."); + } + } else { + $this->fail("Expected status AVAILABLE. Current status: {$secureEcom->status}."); + } + } else { + $this->fail('Card not enrolled.'); + } + } + + private function sendChallenge($url, $challengeValue) + { + $request = curl_init(); + $data = 'challenge_value=' . urlencode($challengeValue); + curl_setopt_array($request, [ + CURLOPT_URL => $url . $data, + CURLOPT_RETURNTRANSFER => true, + CURLOPT_TIMEOUT => 30, + CURLOPT_CUSTOMREQUEST => "POST", + CURLOPT_POSTFIELDS => $data, + CURLOPT_HTTPHEADER => [ + "Content-Type: application/json; charset=UTF-8", + "cache-control: no-cache", + "X-GP-Version: {GpApiConnector::GpApiConnector::GP_API_VERSION}" + ], + ]); + + curl_exec($request); + $curlInfo = curl_getinfo($request); + curl_close($request); + + if ($curlInfo['http_code'] != 200) { + return false; + } + + return true; + } +} \ No newline at end of file diff --git a/test/Integration/Gateways/GpApiConnector/MappingTest.php b/test/Integration/Gateways/GpApiConnector/MappingTest.php new file mode 100644 index 00000000..e7a238c4 --- /dev/null +++ b/test/Integration/Gateways/GpApiConnector/MappingTest.php @@ -0,0 +1,221 @@ +assertEquals($doc->id, $transaction->transactionId); + $this->assertEquals(StringUtils::toAmount($doc->amount), $transaction->balanceAmount); + $this->assertEquals($doc->time_created, $transaction->timestamp); + $this->assertEquals($doc->status, $transaction->responseMessage); + $this->assertEquals($doc->reference, $transaction->referenceNumber); + $this->assertEquals($doc->action->result_code, $transaction->responseCode); + $this->assertEquals($doc->id, $transaction->token); + + if (!empty($transaction->batchSummary)) { + $this->assertEquals($doc->batch_id, $transaction->batchSummary->sequenceNumber); + } + + if (!empty($doc->payment_method)) { + $paymentMethod = $doc->payment_method; + $this->assertEquals($paymentMethod->result, $transaction->authorizationCode); + $this->assertEquals($paymentMethod->card->brand, $transaction->cardType); + $this->assertEquals($paymentMethod->card->masked_number_last4, $transaction->cardLast4); + } + + if (isset($doc->card)) { + $card = $doc->card; + $this->assertEquals($card->number, $transaction->cardNumber); + $this->assertEquals($card->brand, $transaction->cardType); + $this->assertEquals($card->expiry_month, $transaction->cardExpMonth); + $this->assertEquals($card->expiry_year, $transaction->cardExpYear); + } + } + + public function testMapTransactionSummaryTest() + { + $rawJson = "{\"id\":\"TRN_TvY1QFXxQKtaFSjNaLnDVdo3PZ7ivz\",\"time_created\":\"2020-06-05T03:08:20.896Z\",\"time_last_updated\":\"\",\"status\":\"PREAUTHORIZED\",\"type\":\"SALE\",\"merchant_id\":\"MER_c4c0df11039c48a9b63701adeaa296c3\",\"merchant_name\":\"Sandbox_merchant_2\",\"account_id\":\"TRA_6716058969854a48b33347043ff8225f\",\"account_name\":\"Transaction_Processing\",\"channel\":\"CNP\",\"amount\":\"10000\",\"currency\":\"CAD\",\"reference\":\"My-TRANS-184398775\",\"description\":\"41e7877b-da90-4c5f-befe-7f024b96311e\",\"order_reference\":\"\",\"time_created_reference\":\"\",\"batch_id\":\"\",\"initiator\":\"\",\"country\":\"\",\"language\":\"\",\"ip_address\":\"97.107.232.5\",\"site_reference\":\"\",\"payment_method\":{\"result\":\"00\",\"message\":\"SUCCESS\",\"entry_mode\":\"ECOM\",\"name\":\"NAME NOT PROVIDED\",\"card\":{\"funding\":\"CREDIT\",\"brand\":\"VISA\",\"authcode\":\"12345\",\"brand_reference\":\"TQ76bJf7qzkC30U0\",\"masked_number_first6last4\":\"411111XXXXXX1111\",\"cvv_indicator\":\"PRESENT\",\"cvv_result\":\"MATCHED\",\"avs_address_result\":\"MATCHED\",\"avs_postal_code_result\":\"MATCHED\"}},\"action_create_id\":\"ACT_TvY1QFXxQKtaFSjNaLnDVdo3PZ7ivz\",\"parent_resource_id\":\"TRN_TvY1QFXxQKtaFSjNaLnDVdo3PZ7ivz\",\"action\":{\"id\":\"ACT_kLkU0qND7wyuW0Br76ZNyAnlPTjHsb\",\"type\":\"TRANSACTION_SINGLE\",\"time_created\":\"2020-11-24T15:43:43.990Z\",\"result_code\":\"SUCCESS\",\"app_id\":\"JF2GQpeCrOivkBGsTRiqkpkdKp67Gxi0\",\"app_name\":\"test_app\"}}"; + + $doc = json_decode($rawJson); + + $transactionSummary = GpApiMapping::mapTransactionSummary($doc); + + $this->assertEquals($doc->id, $transactionSummary->transactionId); + $this->assertEquals(new \DateTime($doc->time_created), $transactionSummary->transactionDate); + $this->assertEquals($doc->status, $transactionSummary->transactionStatus); + $this->assertEquals($doc->type, $transactionSummary->transactionType); + $this->assertEquals($doc->channel, $transactionSummary->channel); + $this->assertEquals(StringUtils::toAmount($doc->amount), $transactionSummary->amount); + $this->assertEquals($doc->currency, $transactionSummary->currency); + $this->assertEquals($doc->reference, $transactionSummary->referenceNumber); + $this->assertEquals($doc->reference, $transactionSummary->clientTransactionId); + $this->assertEquals($doc->batch_id, $transactionSummary->batchSequenceNumber); + $this->assertEquals($doc->country, $transactionSummary->country); + $this->assertEquals($doc->parent_resource_id, $transactionSummary->originalTransactionId); + + if (isset($doc->payment_method)) { + $paymentMethod = $doc->payment_method; + $this->assertEquals($paymentMethod->message, $transactionSummary->gatewayResponseMessage); + $this->assertEquals($paymentMethod->entry_mode, $transactionSummary->entryMode); + $this->assertEquals($paymentMethod->name, $transactionSummary->cardHolderName); + + if (isset($paymentMethod->card)) { + $card = $paymentMethod->card; + $this->assertEquals($card->brand, $transactionSummary->cardType); + $this->assertEquals($card->authcode, $transactionSummary->authCode); + $this->assertEquals($card->brand_reference, $transactionSummary->brandReference); + if (!empty($card->arn)) { + $this->assertEquals($card->arn, $transactionSummary->aquirerReferenceNumber); + } + $this->assertEquals($card->masked_number_first6last4, $transactionSummary->maskedCardNumber); + } + } + } + + public function testMapTransactionSummaryTest_FromObject() + { + $obj = new stdClass(); + $obj->id = "TRN_TvY1QFXxQKtaFSjNaLnDVdo3PZ7ivz"; + $obj->time_created = (new \DateTime())->format('Y-m-d H:i:s'); + $obj->status = "PREAUTHORIZED"; + $obj->type = "SALE"; + $obj->channel = "CNP"; + $obj->amount = "10000"; + $obj->currency = "USD"; + $obj->reference = "My-TRANS-184398775"; + $obj->batch_id = "BATCH_123456"; + $obj->country = "US"; + $obj->parent_resource_id = "PARENT_456123"; + $obj->payment_method = new stdClass(); + $obj->payment_method->message = "SUCCESS"; + $obj->payment_method->entry_mode = "ECOM"; + $obj->payment_method->name = "James Mason"; + $obj->payment_method->card = new stdClass(); + $obj->payment_method->card->brand = "VISA"; + $obj->payment_method->card->authcode = "12345"; + $obj->payment_method->card->brand_reference = "TQ76bJf7qzkC30U0"; + $obj->payment_method->card->arn = "ARN_123456798"; + $obj->payment_method->card->masked_number_first6last4 = "411111XXXXXX1111"; + + $rawJson = json_encode($obj); + + $transactionSummary = GpApiMapping::mapTransactionSummary(json_decode($rawJson)); + + $this->assertEquals($obj->id, $transactionSummary->transactionId); + $this->assertEquals(new \DateTime($obj->time_created), $transactionSummary->transactionDate); + $this->assertEquals($obj->status, $transactionSummary->transactionStatus); + $this->assertEquals($obj->type, $transactionSummary->transactionType); + $this->assertEquals($obj->channel, $transactionSummary->channel); + $this->assertEquals(StringUtils::toAmount($obj->amount), $transactionSummary->amount); + $this->assertEquals($obj->currency, $transactionSummary->currency); + $this->assertEquals($obj->reference, $transactionSummary->referenceNumber); + $this->assertEquals($obj->reference, $transactionSummary->clientTransactionId); + $this->assertEquals($obj->batch_id, $transactionSummary->batchSequenceNumber); + $this->assertEquals($obj->country, $transactionSummary->country); + $this->assertEquals($obj->parent_resource_id, $transactionSummary->originalTransactionId); + + if (isset($obj->payment_method)) { + $paymentMethod = $obj->payment_method; + $this->assertEquals($paymentMethod->message, $transactionSummary->gatewayResponseMessage); + $this->assertEquals($paymentMethod->entry_mode, $transactionSummary->entryMode); + $this->assertEquals($paymentMethod->name, $transactionSummary->cardHolderName); + + if (isset($paymentMethod->card)) { + $card = $paymentMethod->card; + $this->assertEquals($card->brand, $transactionSummary->cardType); + $this->assertEquals($card->authcode, $transactionSummary->authCode); + $this->assertEquals($card->brand_reference, $transactionSummary->brandReference); + $this->assertEquals($card->arn, $transactionSummary->aquirerReferenceNumber); + $this->assertEquals($card->masked_number_first6last4, $transactionSummary->maskedCardNumber); + } + } + } + + public function testMapDepositSummaryTest() + { + $rawJson = "{\"id\":\"DEP_2342423423\",\"time_created\":\"2020-11-21\",\"status\":\"FUNDED\",\"funding_type\":\"CREDIT\",\"amount\":\"11400\",\"currency\":\"USD\",\"aggregation_model\":\"H-By Date\",\"bank_transfer\":{\"masked_account_number_last4\":\"XXXXXX9999\",\"bank\":{\"code\":\"XXXXX0001\"}},\"system\":{\"mid\":\"101023947262\",\"hierarchy\":\"055-70-024-011-019\",\"name\":\"XYZ LTD.\",\"dba\":\"XYZ Group\"},\"sales\":{\"count\":4,\"amount\":\"12400\"},\"refunds\":{\"count\":1,\"amount\":\"-1000\"},\"discounts\":{\"count\":0,\"amount\":\"\"},\"tax\":{\"count\":0,\"amount\":\"\"},\"disputes\":{\"chargebacks\":{\"count\":0,\"amount\":\"\"},\"reversals\":{\"count\":0,\"amount\":\"\"}},\"fees\":{\"amount\":\"\"},\"action\":{\"id\":\"ACT_TWdmMMOBZ91iQX1DcvxYermuVJ6E6h\",\"type\":\"DEPOSIT_SINGLE\",\"time_created\":\"2020-11-24T18:43:43.370Z\",\"result_code\":\"SUCCESS\",\"app_id\":\"JF2GQpeCrOivkBGsTRiqkpkdKp67Gxi0\",\"app_name\":\"test_app\"}}"; + $doc = json_decode($rawJson); + + $depositSummary = GpApiMapping::mapDepositSummary($doc); + + $this->assertEquals($doc->id, $depositSummary->depositId); + $this->assertEquals(new \DateTime($doc->time_created), $depositSummary->depositDate); + $this->assertEquals($doc->status, $depositSummary->status); + $this->assertEquals($doc->funding_type, $depositSummary->type); + $this->assertEquals(StringUtils::toAmount($doc->amount), $depositSummary->amount); + $this->assertEquals($doc->currency, $depositSummary->currency); + + if (isset($doc->system)) { + $system = $doc->system; + $this->assertEquals($system->mid, $depositSummary->merchantNumber); + $this->assertEquals($system->hierarchy, $depositSummary->merchantHierarchy); + $this->assertEquals($system->name, $depositSummary->merchantName); + $this->assertEquals($system->dba, $depositSummary->merchantDbaName); + } + + if (isset($doc->sales)) { + $this->assertEquals($doc->sales->count, $depositSummary->salesTotalCount); + $this->assertEquals(StringUtils::toAmount($doc->sales->amount), $depositSummary->salesTotalAmount); + } + + if (isset($doc->refunds)) { + $this->assertEquals($doc->refunds->count, $depositSummary->refundsTotalCount); + $this->assertEquals(StringUtils::toAmount($doc->refunds->amount), $depositSummary->refundsTotalAmount); + } + + if (isset($doc->disputes)) { + $disputes = $doc->disputes; + $this->assertEquals($disputes->chargebacks->count, $depositSummary->chargebackTotalCount); + $this->assertEquals(StringUtils::toAmount($disputes->chargebacks->amount), $depositSummary->chargebackTotalAmount); + + $this->assertEquals($disputes->reversals->count, $depositSummary->adjustmentTotalCount); + $this->assertEquals(StringUtils::toAmount($disputes->reversals->amount), $depositSummary->adjustmentTotalAmount); + } + + $this->assertEquals(StringUtils::toAmount($doc->fees->amount), $depositSummary->feesTotalAmount); + } + + public function testMapDisputeSummaryTest() + { + $rawJson = "{\"id\":\"DIS_SAND_abcd1234\",\"time_created\":\"2020-11-12T18:50:39.721Z\",\"merchant_id\":\"MER_62251730c5574bbcb268191b5f315de8\",\"merchant_name\":\"TEST MERCHANT\",\"account_id\":\"DIA_882c832d13e04185bb6e213d6303ed98\",\"account_name\":\"testdispute\",\"status\":\"WITH_MERCHANT\",\"status_time_created\":\"2020-11-14T18:50:39.721Z\",\"stage\":\"RETRIEVAL\",\"stage_time_created\":\"2020-11-17T18:50:39.722Z\",\"amount\":\"1000\",\"currency\":\"USD\",\"payer_amount\":\"1000\",\"payer_currency\":\"USD\",\"merchant_amount\":\"1000\",\"merchant_currency\":\"USD\",\"reason_code\":\"104\",\"reason_description\":\"Other Fraud-Card Absent Environment\",\"time_to_respond_by\":\"2020-11-29T18:50:39.722Z\",\"result\":\"PENDING\",\"investigator_comment\":\"WITH_MERCHANT RETRIEVAL PENDING 1000 USD 1000 USD\",\"system\":{\"mid\":\"627384967\",\"hierarchy\":\"111-23-099-001-001\",\"name\":\"ABC INC.\"},\"last_adjustment_amount\":\"\",\"last_adjustment_currency\":\"\",\"last_adjustment_funding\":\"\",\"last_adjustment_time_created\":\"2020-11-20T18:50:39.722Z\",\"net_financial_amount\":\"\",\"net_financial_currency\":\"\",\"net_financial_funding\":\"\",\"payment_method_provider\":[{\"comment\":\"issuer comments 34523\",\"reference\":\"issuer-reference-0001\",\"documents\":[{\"id\":\"DOC_MyEvidence_234234AVCDE-1\"}]}],\"transaction\":{\"time_created\":\"2020-10-05T18:50:39.726Z\",\"type\":\"SALE\",\"amount\":\"1000\",\"currency\":\"USD\",\"reference\":\"my-trans-AAA1\",\"remarks\":\"my-trans-AAA1\",\"payment_method\":{\"card\":{\"number\":\"424242xxxxxx4242\",\"arn\":\"834523482349123\",\"brand\":\"VISA\",\"authcode\":\"234AB\",\"brand_reference\":\"23423421342323A\"}}},\"documents\":[],\"action\":{\"id\":\"ACT_5blBTHnIs4aOCIvGwG7KizYUpsGI0g\",\"type\":\"DISPUTE_SINGLE\",\"time_created\":\"2020-11-24T18:50:39.925Z\",\"result_code\":\"SUCCESS\",\"app_id\":\"JF2GQpeCrOivkBGsTRiqkpkdKp67Gxi0\",\"app_name\":\"test_app\"}}"; + $doc = json_decode($rawJson); + + $disputeSummary = GpApiMapping::mapDisputeSummary($doc); + + $this->assertEquals($doc->id, $disputeSummary->caseId); + $this->assertEquals(new \DateTime($doc->time_created), $disputeSummary->caseIdTime); + $this->assertEquals($doc->status, $disputeSummary->caseStatus); + $this->assertEquals($doc->stage, $disputeSummary->caseStage); + $this->assertEquals(StringUtils::toAmount($doc->amount), $disputeSummary->caseAmount); + $this->assertEquals($doc->currency, $disputeSummary->caseCurrency); + + if (isset($doc->system)) { + $system = $doc->system; + $this->assertEquals($system->mid, $disputeSummary->caseMerchantId); + $this->assertEquals($system->hierarchy, $disputeSummary->merchantHierarchy); + } + + if (isset($doc->payment_method->card)) { + $card = $doc->payment_method; + $this->assertEquals($card->number, $disputeSummary->transactionMaskedCardNumber); + $this->assertEquals($card->arn, $disputeSummary->transactionARN); + $this->assertEquals($card->brand, $disputeSummary->transactionCardType); + } + + $this->assertEquals($doc->reason_code, $disputeSummary->reasonCode); + $this->assertEquals($doc->reason_description, $disputeSummary->reason); + $this->assertEquals(new \DateTime($doc->time_to_respond_by), $disputeSummary->respondByDate); + $this->assertEquals($doc->result, $disputeSummary->result); + $this->assertEquals(StringUtils::toAmount($doc->last_adjustment_amount), $disputeSummary->lastAdjustmentAmount); + $this->assertEquals($doc->last_adjustment_currency, $disputeSummary->lastAdjustmentCurrency); + $this->assertEquals($doc->last_adjustment_funding, $disputeSummary->lastAdjustmentFunding); + } +} \ No newline at end of file diff --git a/test/Integration/Gateways/GpApiConnector/ReportingDepositsTest.php b/test/Integration/Gateways/GpApiConnector/ReportingDepositsTest.php new file mode 100644 index 00000000..f3f5233c --- /dev/null +++ b/test/Integration/Gateways/GpApiConnector/ReportingDepositsTest.php @@ -0,0 +1,189 @@ +setUpConfig()); + } + + public function testReportDepositDetail() + { + $depositId = 'DEP_2342423443'; + try { + /** @var DepositSummary $response */ + $response = ReportingService::depositDetail($depositId) + ->execute(); + } catch (ApiException $e) { + $this->fail("Deposit detail failed with: " . $e->getMessage()); + } + + $this->assertNotNull($response); + $this->assertInstanceOf(DepositSummary::class, $response); + $this->assertEquals($depositId, $response->depositId); + } + + public function testReportFindDepositsByStartDateAndOrderByTimeCreated() + { + $startDate = new \DateTime('2020-11-01 midnight'); + try { + $response = ReportingService::findDeposits() + ->orderBy(DepositSortProperty::TIME_CREATED, SortDirection::DESC) + ->withPaging(1, 10) + ->where(SearchCriteria::START_DATE, $startDate) + ->execute(); + } catch (ApiException $e) { + $this->fail("Find deposits by start date failed with: " . $e->getMessage()); + } + /** @var DepositSummary $randomDeposit */ + $randomDeposit = $response[array_rand($response)]; + $this->assertNotNull($randomDeposit); + $this->assertInstanceOf(DepositSummary::class, $randomDeposit); + $this->assertGreaterThanOrEqual($startDate, $randomDeposit->depositDate); + } + + public function testReportFindDepositsOrderByDepositId() + { + $startDate = new \DateTime('2020-11-01 midnight'); + try { + $response = ReportingService::findDeposits() + ->orderBy(DepositSortProperty::DEPOSIT_ID, SortDirection::DESC) + ->withPaging(1, 10) + ->where(SearchCriteria::START_DATE, $startDate) + ->execute(); + } catch (ApiException $e) { + $this->fail("Find deposits order by deposit id failed with: " . $e->getMessage()); + } + /** @var DepositSummary $randomDeposit */ + $randomDeposit = $response[array_rand($response)]; + $this->assertNotNull($randomDeposit); + $this->assertInstanceOf(DepositSummary::class, $randomDeposit); + } + + public function testReportFindDepositsOrderByStatus() + { + $startDate = new \DateTime('2020-11-01 midnight'); + try { + $response = ReportingService::findDeposits() + ->orderBy(DepositSortProperty::STATUS, SortDirection::DESC) + ->withPaging(1, 10) + ->where(SearchCriteria::START_DATE, $startDate) + ->execute(); + } catch (ApiException $e) { + $this->fail("Find deposits order by status failed with: " . $e->getMessage()); + } + /** @var DepositSummary $randomDeposit */ + $randomDeposit = $response[array_rand($response)]; + $this->assertNotNull($randomDeposit); + $this->assertInstanceOf(DepositSummary::class, $randomDeposit); + } + + public function testReportFindDepositsOrderByType() + { + $startDate = new \DateTime('2020-11-01 midnight'); + try { + $response = ReportingService::findDeposits() + ->orderBy(DepositSortProperty::TYPE, SortDirection::DESC) + ->withPaging(1, 10) + ->where(SearchCriteria::START_DATE, $startDate) + ->execute(); + } catch (ApiException $e) { + $this->fail("Find deposits order by type failed with: " . $e->getMessage()); + } + /** @var DepositSummary $randomDeposit */ + $randomDeposit = $response[array_rand($response)]; + $this->assertNotNull($randomDeposit); + $this->assertInstanceOf(DepositSummary::class, $randomDeposit); + } + + public function testReportFindDepositsOrderByEndDateOrderByTimeCreated() + { + $startDate = new \DateTime('2020-11-01 midnight'); + $endDate = new \DateTime('2021-01-15 midnight'); + $response = ReportingService::findDeposits() + ->orderBy(DepositSortProperty::TIME_CREATED, SortDirection::DESC) + ->withPaging(1, 10) + ->where(SearchCriteria::START_DATE, $startDate) + ->andWith(SearchCriteria::END_DATE, $endDate) + ->execute(); + + + $randomDeposit = $response[array_rand($response)]; + $this->assertNotNull($randomDeposit); + $this->assertInstanceOf(DepositSummary::class, $randomDeposit); + } + + public function testReportFindDepositsByNotFoundAmount() + { + $startDate = new \DateTime('2020-11-01 midnight'); + $amount = 140; + + try { + $response = ReportingService::findDeposits() + ->orderBy(DepositSortProperty::TIME_CREATED, SortDirection::DESC) + ->withPaging(1, 10) + ->where(SearchCriteria::START_DATE, $startDate) + ->andWith(DataServiceCriteria::AMOUNT, $amount) + ->execute(); + } catch (ApiException $e) { + $this->fail("Find deposits not found amount failed with: " . $e->getMessage()); + } + + $this->assertNotNull($response); + $this->assertTrue(sizeof($response)==0); + } + + public function testReportFindDepositsByAmount() + { + $startDate = new \DateTime('2020-11-01 midnight'); + $amount = 141; + + try { + $response = ReportingService::findDeposits() + ->orderBy(DepositSortProperty::TIME_CREATED, SortDirection::DESC) + ->withPaging(1, 10) + ->where(SearchCriteria::START_DATE, $startDate) + ->andWith(DataServiceCriteria::AMOUNT, $amount) + ->execute(); + } catch (ApiException $e) { + $this->fail("Find deposits by amount failed with: " . $e->getMessage()); + } + /** @var DepositSummary $randomDeposit */ + $randomDeposit = $response[array_rand($response)]; + $this->assertNotNull($randomDeposit); + $this->assertInstanceOf(DepositSummary::class, $randomDeposit); + foreach ($response as $deposit) { + $this->assertEquals($deposit->amount, $amount); + } + } + + public function setUpConfig() + { + $config = new GpApiConfig(); + $accessTokenInfo = new \GlobalPayments\Api\Utils\AccessTokenInfo(); + //this is gpapistuff stuff + $config->setAppId('VuKlC2n1cr5LZ8fzLUQhA7UObVks6tFF'); + $config->setAppKey('NmGM0kg92z2gA7Og'); + $config->environment = Environment::TEST; + $config->setAccessTokenInfo($accessTokenInfo); +// $klogger = new Logger("C:\\laragon\\www\\PHP-SDK-v3\\logs"); +// $config->requestLogger = new SampleRequestLogger($klogger); + + return $config; + } +} \ No newline at end of file diff --git a/test/Integration/Gateways/GpApiConnector/ReportingDisputesTest.php b/test/Integration/Gateways/GpApiConnector/ReportingDisputesTest.php new file mode 100644 index 00000000..19fab575 --- /dev/null +++ b/test/Integration/Gateways/GpApiConnector/ReportingDisputesTest.php @@ -0,0 +1,781 @@ +setUpConfig()); + } + + public function setUpConfig() + { + $config = new GpApiConfig(); + $accessTokenInfo = new AccessTokenInfo(); + $config->setAppId('i872l4VgZRtSrykvSn8Lkah8RE1jihvT'); + $config->setAppKey( '9pArW2uWoA8enxKc'); + $config->environment = Environment::TEST; + $config->setAccessTokenInfo($accessTokenInfo); + + return $config; + } + + public function testReportDisputeDetail() + { + $disputeId = 'DIS_SAND_abcd1234'; + $response = ReportingService::disputeDetail($disputeId) + ->execute(); + $this->assertNotNull($response); + $this->assertInstanceOf(DisputeSummaryList::class, $response); + $this->assertEquals($disputeId, $response->getIterator()->current()->caseId); + } + + public function testReportDisputeDetailWrongId() + { + $disputeId = 'DIS_SAND_aaaa1111'; + try{ + ReportingService::disputeDetail($disputeId) + ->execute(); + } catch (GatewayException $e) { + $this->assertEquals('40073',$e->responseCode); + $this->assertEquals( + 'Status Code: INVALID_REQUEST_DATA - 101,Unable to locate dispute record for that ID. Please recheck the ID provided.', + $e->getMessage()); + } + } + + public function testReportFindDisputes_By_ARN() + { + $startDate = new \DateTime('2020-01-01 midnight'); + $arn = "135091790340196"; + $disputes = ReportingService::findDisputes() + ->withPaging(1, 10) + ->where(DataServiceCriteria::START_STAGE_DATE, $startDate) + ->andWith(SearchCriteria::AQUIRER_REFERENCE_NUMBER, $arn) + ->execute(); + $this->assertNotNull($disputes); + $this->assertInstanceOf(DisputeSummaryList::class, $disputes); + foreach ($disputes as $dispute) { + $this->assertEquals($dispute->transactionARN, $arn); + } + } + + public function testReportFindDisputes_By_ARN_NotFound() + { + $startDate = new \DateTime('2020-01-01 midnight'); + $arn = "874091790340471"; + try{ + ReportingService::findDisputes() + ->withPaging(1, 10) + ->where(DataServiceCriteria::START_STAGE_DATE, $startDate) + ->andWith(SearchCriteria::AQUIRER_REFERENCE_NUMBER, $arn) + ->execute(); + } catch (GatewayException $e) { + $this->assertEquals('40048',$e->responseCode); + $this->assertEquals( + 'Status Code: INVALID_REQUEST_DATA - 105,Unable to locate dispute record for arn. Please recheck thevalue provided for arn.', + $e->getMessage()); + } + } + + public function testReportFindDisputes_By_Brand() + { + $cardBrand = "VISA"; + $startDate = new \DateTime('2020-01-01 midnight'); + $disputes = ReportingService::findDisputes() + ->withPaging(1, 10) + ->where(DataServiceCriteria::START_STAGE_DATE, $startDate) + ->andWith(SearchCriteria::CARD_BRAND, $cardBrand) + ->execute(); + + $this->assertNotNull($disputes); + $this->assertInstanceOf(DisputeSummaryList::class, $disputes); + foreach ($disputes as $dispute) { + $this->assertEquals($dispute->transactionCardType, $cardBrand); + } + } + + public function testReportFindDisputes_By_Status() + { + $startDate = new \DateTime('2020-01-01 midnight'); + $disputes = ReportingService::findDisputes() + ->withPaging(1, 10) + ->where(DataServiceCriteria::START_STAGE_DATE, $startDate) + ->andWith(SearchCriteria::DISPUTE_STATUS, DisputeStatus::UNDER_REVIEW) + ->execute(); + + $this->assertNotNull($disputes); + $this->assertInstanceOf(DisputeSummaryList::class, $disputes); + foreach ($disputes as $dispute) { + $this->assertEquals($dispute->caseStatus, DisputeStatus::UNDER_REVIEW); + } + } + + public function testReportFindDisputes_By_Stage() + { + $disputeStage = DisputeStage::CHARGEBACK; + $startDate = new \DateTime('2020-01-01 midnight'); + $disputes = ReportingService::findDisputes() + ->withPaging(1, 10) + ->where(DataServiceCriteria::START_STAGE_DATE, $startDate) + ->andWith(SearchCriteria::DISPUTE_STAGE, $disputeStage) + ->execute(); + + $this->assertNotNull($disputes); + $this->assertInstanceOf(DisputeSummaryList::class, $disputes); + foreach ($disputes as $dispute) { + $this->assertEquals($dispute->caseStage, $disputeStage); + } + } + + public function testReportFindDisputes_By_MerchantId_And_SystemHierarchy() + { + $merchantId = "8593872"; + $systemHierarchy = "111-23-099-002-005"; + $startDate = new \DateTime('2020-01-01 midnight'); + $disputes = ReportingService::findDisputes() + ->withPaging(1, 10) + ->where(DataServiceCriteria::START_STAGE_DATE, $startDate) + ->andWith(DataServiceCriteria::MERCHANT_ID, $merchantId) + ->andWith(DataServiceCriteria::SYSTEM_HIERARCHY, $systemHierarchy) + ->execute(); + + $this->assertNotNull($disputes); + $this->assertInstanceOf(DisputeSummaryList::class, $disputes); + foreach ($disputes as $dispute) { + $this->assertEquals($dispute->caseMerchantId, $merchantId); + $this->assertEquals($dispute->merchantHierarchy, $systemHierarchy); + } + } + + public function testReportFindDisputes_By_From_And_To_Stage_Time_Created() + { + $startDate = new \DateTime('2020-01-01 midnight'); + $endDate = new \DateTime('2021-01-21 midnight'); + $disputes = ReportingService::findDisputes() + ->withPaging(1, 10) + ->where(DataServiceCriteria::START_STAGE_DATE, $startDate) + ->andWith(DataServiceCriteria::END_STAGE_DATE, $endDate) + ->execute(); + + $this->assertNotNull($disputes); + $this->assertInstanceOf(DisputeSummaryList::class, $disputes); + foreach ($disputes as $dispute) { + $this->assertTrue($dispute->caseIdTime >= $startDate && $dispute->caseIdTime <= $endDate); + } + } + + public function testReportFindDisputes_Filter_By_From_And_To_Adjustment_Time_Created() + { + $startDate = new \DateTime('2020-01-01 midnight'); + $endDate = new \DateTime('2021-01-21 midnight'); + $disputes = ReportingService::findDisputes() + ->withPaging(1, 10) + ->where(DataServiceCriteria::START_STAGE_DATE, $startDate) + ->andWith(DataServiceCriteria::START_ADJUSTMENT_DATE, $startDate) + ->andWith(DataServiceCriteria::END_ADJUSTMENT_DATE, $endDate) + ->execute(); + + $this->assertNotNull($disputes); + $this->assertInstanceOf(DisputeSummaryList::class, $disputes); + $this->assertTrue(sizeof($disputes) > 0); + } + + public function testReportFindDisputes_By_Adjustment_Funding() + { + $startDate = new \DateTime('2020-01-01 midnight'); + $disputes = ReportingService::findDisputes() + ->withPaging(1, 10) + ->where(DataServiceCriteria::START_STAGE_DATE, $startDate) + ->andWith(DataServiceCriteria::ADJUSTMENT_FUNDING, AdjustmentFunding::DEBIT) + ->execute(); + + $this->assertNotNull($disputes); + $this->assertInstanceOf(DisputeSummaryList::class, $disputes); + $this->assertTrue(sizeof($disputes) > 0); + } + + public function testReportFindDisputes_Order_By_Id() + { + $startDate = new \DateTime('2020-02-01 midnight'); + $disputes = ReportingService::findDisputes() + ->orderBy(DisputeSortProperty::ID, SortDirection::DESC) + ->withPaging(1, 10) + ->where(DataServiceCriteria::START_STAGE_DATE, $startDate) + ->execute(); + + $this->assertNotNull($disputes); + $this->assertInstanceOf(DisputeSummaryList::class, $disputes); + } + + public function testReportFindDisputes_Order_By_ARN() + { + $startDate = new \DateTime('2020-06-09 midnight'); + $endDate = new \DateTime('2020-06-22 midnight'); + // EndStageDate is mandatory in order to be able to sort by ARN + $disputes = ReportingService::findDisputes() + ->orderBy(DisputeSortProperty::ARN, SortDirection::DESC) + ->withPaging(1, 10) + ->where(DataServiceCriteria::START_STAGE_DATE, $startDate) + ->andWith(DataServiceCriteria::END_STAGE_DATE, $endDate) + ->execute(); + + $this->assertNotNull($disputes); + $this->assertInstanceOf(DisputeSummaryList::class, $disputes); + } + + public function testReportFindDisputes_Order_By_Brand() + { + $startDate = new \DateTime('2020-01-01 midnight'); + $disputes = ReportingService::findDisputes() + ->orderBy(DisputeSortProperty::BRAND, SortDirection::DESC) + ->withPaging(1, 10) + ->where(DataServiceCriteria::START_STAGE_DATE, $startDate) + ->execute(); + + $this->assertNotNull($disputes); + $this->assertInstanceOf(DisputeSummaryList::class, $disputes); + } + + public function testReportFindDisputes_Order_By_Status() + { + $startDate = new \DateTime('2020-01-01 midnight'); + $disputes = ReportingService::findDisputes() + ->orderBy(DisputeSortProperty::STATUS, SortDirection::DESC) + ->withPaging(1, 10) + ->where(DataServiceCriteria::START_STAGE_DATE, $startDate) + ->execute(); + + $this->assertNotNull($disputes); + $this->assertInstanceOf(DisputeSummaryList::class, $disputes); + } + + public function testReportFindDisputes_Order_By_Stage() + { + $startDate = new \DateTime('2020-01-01 midnight'); + $disputes = ReportingService::findDisputes() + ->orderBy(DisputeSortProperty::STAGE, SortDirection::DESC) + ->withPaging(1, 10) + ->where(DataServiceCriteria::START_STAGE_DATE, $startDate) + ->execute(); + + $this->assertNotNull($disputes); + $this->assertInstanceOf(DisputeSummaryList::class, $disputes); + } + + public function testReportFindDisputes_Order_By_FromStageTimeCreated() + { + $startDate = new \DateTime('2020-01-01 midnight'); + $disputes = ReportingService::findDisputes() + ->orderBy(DisputeSortProperty::FROM_STAGE_TIME_CREATED, SortDirection::DESC) + ->withPaging(1, 10) + ->where(DataServiceCriteria::START_STAGE_DATE, $startDate) + ->execute(); + + $this->assertNotNull($disputes); + $this->assertInstanceOf(DisputeSummaryList::class, $disputes); + } + + public function testReportFindDisputes_Order_By_ToStageTimeCreated() + { + $startDate = new \DateTime('2020-01-01 midnight'); + $disputes = ReportingService::findDisputes() + ->orderBy(DisputeSortProperty::TO_STAGE_TIME_CREATED, SortDirection::DESC) + ->withPaging(1, 10) + ->where(DataServiceCriteria::START_STAGE_DATE, $startDate) + ->execute(); + + $this->assertNotNull($disputes); + $this->assertInstanceOf(DisputeSummaryList::class, $disputes); + } + + public function testReportFindDisputes_Order_By_AdjustmentFunding() + { + $startDate = new \DateTime('2020-01-01 midnight'); + $disputes = ReportingService::findDisputes() + ->orderBy(DisputeSortProperty::ADJUSTMENT_FUNDING, SortDirection::DESC) + ->withPaging(1, 10) + ->where(DataServiceCriteria::START_STAGE_DATE, $startDate) + ->execute(); + + $this->assertNotNull($disputes); + $this->assertInstanceOf(DisputeSummaryList::class, $disputes); + } + + public function testReportFindDisputes_Order_By_FromAdjustmentTimeCreated() + { + $startDate = new \DateTime('2020-01-01 midnight'); + $disputes = ReportingService::findDisputes() + ->orderBy(DisputeSortProperty::FROM_ADJUSTMENT_TIME_CREATED, SortDirection::DESC) + ->withPaging(1, 10) + ->where(DataServiceCriteria::START_STAGE_DATE, $startDate) + ->execute(); + + $this->assertNotNull($disputes); + $this->assertInstanceOf(DisputeSummaryList::class, $disputes); + } + + public function testReportFindDisputes_Order_By_ToAdjustmentTimeCreated() + { + $startDate = new \DateTime('2020-01-01 midnight'); + $disputes = ReportingService::findDisputes() + ->orderBy(DisputeSortProperty::TO_ADJUSTMENT_TIME_CREATED, SortDirection::DESC) + ->withPaging(1, 10) + ->where(DataServiceCriteria::START_STAGE_DATE, $startDate) + ->execute(); + + $this->assertNotNull($disputes); + $this->assertInstanceOf(DisputeSummaryList::class, $disputes); + } + + public function testReportFindDisputes_Order_By_Id_With_Brand_VISA() + { + $startDate = new \DateTime('2020-01-01 midnight'); + $disputes = ReportingService::findDisputes() + ->orderBy(DisputeSortProperty::ID, SortDirection::ASC) + ->withPaging(1, 10) + ->where(DataServiceCriteria::START_STAGE_DATE, $startDate) + ->andWith(SearchCriteria::DISPUTE_STATUS, DisputeStatus::UNDER_REVIEW) + ->execute(); + + $this->assertNotNull($disputes); + $this->assertInstanceOf(DisputeSummaryList::class, $disputes); + } + + public function testReportFindDisputes_Order_By_Id_With_Stage_Chargeback() + { + $startDate = new \DateTime('2020-01-01 midnight'); + $disputes = ReportingService::findDisputes() + ->orderBy(DisputeSortProperty::ID, SortDirection::ASC) + ->withPaging(1, 10) + ->where(DataServiceCriteria::START_STAGE_DATE, $startDate) + ->andWith(SearchCriteria::DISPUTE_STAGE, DisputeStage::CHARGEBACK) + ->execute(); + + $this->assertNotNull($disputes); + $this->assertInstanceOf(DisputeSummaryList::class, $disputes); + } + + /*************************************** + * Settlement disputes * + ***************************************/ + + public function testReportSettlementDisputeDetail() + { + $settlementDisputeId = "DIS_810"; + $response = ReportingService::settlementDisputeDetail($settlementDisputeId) + ->execute(); + + $this->assertNotNull($response); + $this->assertInstanceOf(DisputeSummaryList::class, $response); + $this->assertEquals($settlementDisputeId, $response->getIterator()->current()->caseId); + } + + public function testReportSettlementDisputeDetailWrongId() + { + $settlementDisputeId = "DIS_010"; + try{ + ReportingService::settlementDisputeDetail($settlementDisputeId) + ->execute(); + } catch (GatewayException $ex){ + $this->assertEquals('40118',$ex->responseCode); + $this->assertEquals( + 'Status Code: RESOURCE_NOT_FOUND - Disputes DIS_010 not found at this /ucp/settlement/disputes/DIS_010', + $ex->getMessage()); + } + } + + public function testReportSettlementDispute_Order_By_Id_With_Status_UnderReview(){ + $startDate = new \DateTime('2020-01-01 midnight'); + $summary = ReportingService::findSettlementDisputes() + ->orderBy(DisputeSortProperty::ID, SortDirection::ASC) + ->withPaging(1,10) + ->where(DataServiceCriteria::START_STAGE_DATE, $startDate) + ->andWith(SearchCriteria::DISPUTE_STATUS, DisputeStatus::UNDER_REVIEW) + ->execute(); + + $this->assertNotNull($summary); + $this->assertInstanceOf(DisputeSummaryList::class, $summary); + foreach ($summary as $dispute) { + $this->assertEquals($dispute->caseStatus, DisputeStatus::UNDER_REVIEW); + } + } + + public function testReportFindSettlementDisputes_Order_By_Id() + { + $startDate = new \DateTime('2020-01-01 midnight'); + $summary = ReportingService::findSettlementDisputes() + ->orderBy(DisputeSortProperty::ID, SortDirection::ASC) + ->withPaging(1,10) + ->where(DataServiceCriteria::START_STAGE_DATE, $startDate) + ->execute(); + + $this->assertNotNull($summary); + $this->assertInstanceOf(DisputeSummaryList::class, $summary); + } + + public function testReportFindSettlementDisputes_Order_By_ARN() + { + $startDate = new \DateTime('2020-01-01 midnight'); + $summary = ReportingService::findSettlementDisputes() + ->orderBy(DisputeSortProperty::ARN, SortDirection::DESC) + ->withPaging(1,10) + ->where(DataServiceCriteria::START_STAGE_DATE, $startDate) + ->execute(); + + $this->assertNotNull($summary); + $this->assertInstanceOf(DisputeSummaryList::class, $summary); + } + + public function testReportFindSettlementDisputes_Order_By_Brand() + { + $startDate = new \DateTime('2020-01-01 midnight'); + $summary = ReportingService::findSettlementDisputes() + ->orderBy(DisputeSortProperty::BRAND, SortDirection::DESC) + ->withPaging(1,10) + ->where(DataServiceCriteria::START_STAGE_DATE, $startDate) + ->execute(); + + $this->assertNotNull($summary); + $this->assertInstanceOf(DisputeSummaryList::class, $summary); + } + + public function testReportFindSettlementDisputes_Order_By_Stage() + { + $startDate = new \DateTime('2020-01-01 midnight'); + $summary = ReportingService::findSettlementDisputes() + ->orderBy(DisputeSortProperty::STAGE, SortDirection::DESC) + ->withPaging(1,10) + ->where(DataServiceCriteria::START_STAGE_DATE, $startDate) + ->execute(); + + $this->assertNotNull($summary); + $this->assertInstanceOf(DisputeSummaryList::class, $summary); + } + + public function testReportFindSettlementDisputes_Order_By_FromStageTimeCreated() + { + $startDate = new \DateTime('2020-01-01 midnight'); + $summary = ReportingService::findSettlementDisputes() + ->orderBy(DisputeSortProperty::FROM_STAGE_TIME_CREATED, SortDirection::DESC) + ->withPaging(1,10) + ->where(DataServiceCriteria::START_STAGE_DATE, $startDate) + ->execute(); + + $this->assertNotNull($summary); + $this->assertInstanceOf(DisputeSummaryList::class, $summary); + } + + public function testReportFindSettlementDisputes_Order_By_ToStageTimeCreated() + { + $startDate = new \DateTime('2020-01-01 midnight'); + $summary = ReportingService::findSettlementDisputes() + ->orderBy(DisputeSortProperty::TO_STAGE_TIME_CREATED, SortDirection::DESC) + ->withPaging(1,10) + ->where(DataServiceCriteria::START_STAGE_DATE, $startDate) + ->execute(); + + $this->assertNotNull($summary); + $this->assertInstanceOf(DisputeSummaryList::class, $summary); + } + + public function testReportFindSettlementDisputes_Order_By_AdjustmentFunding() + { + $startDate = new \DateTime('2020-01-01 midnight'); + $summary = ReportingService::findSettlementDisputes() + ->orderBy(DisputeSortProperty::ADJUSTMENT_FUNDING, SortDirection::DESC) + ->withPaging(1,10) + ->where(DataServiceCriteria::START_STAGE_DATE, $startDate) + ->execute(); + + $this->assertNotNull($summary); + $this->assertInstanceOf(DisputeSummaryList::class, $summary); + } + + public function testReportFindSettlementDisputes_Order_By_FromAdjustmentTimeCreated() + { + $startDate = new \DateTime('2020-01-01 midnight'); + $summary = ReportingService::findSettlementDisputes() + ->orderBy(DisputeSortProperty::FROM_ADJUSTMENT_TIME_CREATED, SortDirection::DESC) + ->withPaging(1,10) + ->where(DataServiceCriteria::START_STAGE_DATE, $startDate) + ->execute(); + + $this->assertNotNull($summary); + $this->assertInstanceOf(DisputeSummaryList::class, $summary); + } + + public function testReportFindSettlementDisputes_Order_By_ToAdjustmentTimeCreated() + { + $startDate = new \DateTime('2020-01-01 midnight'); + $summary = ReportingService::findSettlementDisputes() + ->orderBy(DisputeSortProperty::TO_ADJUSTMENT_TIME_CREATED, SortDirection::DESC) + ->withPaging(1,10) + ->where(DataServiceCriteria::START_STAGE_DATE, $startDate) + ->execute(); + + $this->assertNotNull($summary); + $this->assertInstanceOf(DisputeSummaryList::class, $summary); + } + + public function testReportFindSettlementDisputes_FilterBy_ARN(){ + $startDate = new \DateTime('2020-01-01 midnight'); + $arn = '74500010037624410827759'; + + $summary = ReportingService::findSettlementDisputes() + ->orderBy(DisputeSortProperty::ID, SortDirection::ASC) + ->withPaging(1,10) + ->where(DataServiceCriteria::START_STAGE_DATE, $startDate) + ->andWith(SearchCriteria::AQUIRER_REFERENCE_NUMBER, $arn) + ->execute(); + + $this->assertNotNull($summary); + $this->assertInstanceOf(DisputeSummaryList::class, $summary); + foreach ($summary as $dispute) { + $this->assertEquals($dispute->transactionARN, $arn); + } + } + + public function testReportFindSettlementDisputes_FilterBy_ARN_NotFound(){ + $startDate = new \DateTime('2020-01-01 midnight'); + $arn = '00000010037624410827111'; + + $summary = ReportingService::findSettlementDisputes() + ->orderBy(DisputeSortProperty::ID, SortDirection::ASC) + ->withPaging(1,10) + ->where(DataServiceCriteria::START_STAGE_DATE, $startDate) + ->andWith(SearchCriteria::AQUIRER_REFERENCE_NUMBER, $arn) + ->execute(); + + $this->assertNotNull($summary); + $this->assertInstanceOf(DisputeSummaryList::class, $summary); + $this->assertTrue(sizeof($summary) == 0); + } + + public function testReportFindSettlementDisputes_FilterBy_Brand(){ + $startDate = new \DateTime('2020-01-01 midnight'); + $brand = 'VISA'; + + $summary = ReportingService::findSettlementDisputes() + ->orderBy(DisputeSortProperty::ID, SortDirection::ASC) + ->withPaging(1,10) + ->where(DataServiceCriteria::START_STAGE_DATE, $startDate) + ->andWith(SearchCriteria::CARD_BRAND, $brand) + ->execute(); + + $this->assertNotNull($summary); + $this->assertInstanceOf(DisputeSummaryList::class, $summary); + foreach ($summary as $dispute) { + $this->assertEquals($dispute->transactionCardType, $brand); + } + } + + public function testReportFindSettlementDisputes_FilterBy_Brand_NotFound(){ + $startDate = new \DateTime('2020-01-01 midnight'); + $brand = 'MASTERCAR'; + + $summary = ReportingService::findSettlementDisputes() + ->orderBy(DisputeSortProperty::ID, SortDirection::ASC) + ->withPaging(1,10) + ->where(DataServiceCriteria::START_STAGE_DATE, $startDate) + ->andWith(SearchCriteria::CARD_BRAND, $brand) + ->execute(); + + $this->assertNotNull($summary); + $this->assertInstanceOf(DisputeSummaryList::class, $summary); + $this->assertTrue($summary->count() == 0); + } + + public function testReportFindSettlementDisputes_FilterBy_Stage(){ + $startDate = new \DateTime('2020-01-01 midnight'); + $stage = 'CHARGEBACK'; + + $summary = ReportingService::findSettlementDisputes() + ->orderBy(DisputeSortProperty::ID, SortDirection::ASC) + ->withPaging(1,10) + ->where(DataServiceCriteria::START_STAGE_DATE, $startDate) + ->andWith(SearchCriteria::DISPUTE_STAGE, $stage) + ->execute(); + + $this->assertNotNull($summary); + $this->assertInstanceOf(DisputeSummaryList::class, $summary); + foreach ($summary as $dispute) { + $this->assertEquals($dispute->caseStage, $stage); + } + } + + public function testReportFindSettlementDisputes_FilterBy_FromAndToStageTimeCreated(){ + $startDate = new \DateTime('2020-01-01 midnight'); + $endDate = new \DateTime('2021-01-22 midnight'); + + $summary = ReportingService::findSettlementDisputes() + ->orderBy(DisputeSortProperty::ID, SortDirection::ASC) + ->withPaging(1,10) + ->where(DataServiceCriteria::START_STAGE_DATE, $startDate) + ->andWith(DataServiceCriteria::END_STAGE_DATE, $endDate) + ->execute(); + + $this->assertNotNull($summary); + $this->assertInstanceOf(DisputeSummaryList::class, $summary); + foreach ($summary as $dispute) { + $this->assertTrue($dispute->caseTime <= $endDate); + } + } + + public function testReportFindSettlementDisputes_FilterBy_AdjustmentFunding(){ + $startDate = new \DateTime('2020-01-01 midnight'); + $adjustmentFunding = AdjustmentFunding::CREDIT; + + $summary = ReportingService::findSettlementDisputes() + ->orderBy(DisputeSortProperty::ID, SortDirection::ASC) + ->withPaging(1,10) + ->where(DataServiceCriteria::START_STAGE_DATE, $startDate) + ->andWith(DataServiceCriteria::ADJUSTMENT_FUNDING, $adjustmentFunding) + ->execute(); + + $this->assertNotNull($summary); + $this->assertInstanceOf(DisputeSummaryList::class, $summary); + } + + public function testReportFindSettlementDisputes_FilterBy_FromAndToAdjustmentTimeCreated() + { + $startDate = new \DateTime('2020-01-01 midnight'); + $endDate = new \DateTime('2021-01-21 midnight'); + + $summary = ReportingService::findSettlementDisputes() + ->orderBy(DisputeSortProperty::ID, SortDirection::ASC) + ->withPaging(1,10) + ->where(DataServiceCriteria::START_STAGE_DATE, $startDate) + ->andWith(DataServiceCriteria::START_ADJUSTMENT_DATE, $endDate) + ->andWith(DataServiceCriteria::END_ADJUSTMENT_DATE, $endDate) + ->execute(); + + $this->assertNotNull($summary); + $this->assertInstanceOf(DisputeSummaryList::class, $summary); + } + + public function testReportFindSettlementDisputes_FilterBy_SystemMidAndHierarchy(){ + $startDate = new \DateTime('2020-01-01 midnight'); + $systemMid = '101023947262'; + $systemHierarchy = '055-70-024-011-019'; + + $summary = ReportingService::findSettlementDisputes() + ->orderBy(DisputeSortProperty::ID, SortDirection::ASC) + ->withPaging(1,10) + ->where(DataServiceCriteria::START_STAGE_DATE, $startDate) + ->andWith(DataServiceCriteria::MERCHANT_ID, $systemMid) + ->andWith(DataServiceCriteria::SYSTEM_HIERARCHY, $systemHierarchy) + ->execute(); + + $this->assertNotNull($summary); + $this->assertInstanceOf(DisputeSummaryList::class, $summary); + foreach ($summary as $dispute) { + $this->assertEquals($dispute->merchantHierarchy, $systemHierarchy); + $this->assertEquals($dispute->caseMerchantId, $systemMid); + } + } + + public function testReportFindSettlementDisputes_FilterBy_WrongSystemMid(){ + $startDate = new \DateTime('2020-01-01 midnight'); + $systemHierarchy = '000-70-024-011-111'; + + $summary = ReportingService::findSettlementDisputes() + ->orderBy(DisputeSortProperty::ID, SortDirection::ASC) + ->withPaging(1,10) + ->where(DataServiceCriteria::START_STAGE_DATE, $startDate) + ->andWith(DataServiceCriteria::SYSTEM_HIERARCHY, $systemHierarchy) + ->execute(); + + $this->assertNotNull($summary); + $this->assertInstanceOf(DisputeSummaryList::class, $summary); + $this->assertTrue(sizeof($summary) == 0); + } + + public function testReportFindSettlementDisputes_FilterBy_WrongSystemHierarchy(){ + $startDate = new \DateTime('2020-01-01 midnight'); + $systemMid = '000023947222'; + + $summary = ReportingService::findSettlementDisputes() + ->orderBy(DisputeSortProperty::ID, SortDirection::ASC) + ->withPaging(1,10) + ->where(DataServiceCriteria::START_STAGE_DATE, $startDate) + ->andWith(DataServiceCriteria::MERCHANT_ID, $systemMid) + ->execute(); + + $this->assertNotNull($summary); + $this->assertInstanceOf(DisputeSummaryList::class, $summary); + $this->assertTrue(sizeof($summary) == 0); + } + + public function testReportDisputeAcceptance() + { + $disputeId = "DIS_SAND_abcd1234"; + $dispute = ReportingService::disputeDetail($disputeId) + ->execute(); + $response = $dispute->getIterator()->current()->accept()->execute(); + + $this->assertNotNull($response); + $this->assertEquals('SUCCESS', $response->responseCode); + } + + public function testDisputeAcceptWrongId() + { + $dispute = new DisputeSummary(); + $dispute->caseId = "DIS_SAND_abcd1234ZZ"; + try { + $response = $dispute->accept()->execute(); + } catch (GatewayException $ex) { + $this->assertEquals("40067", $ex->responseCode); + $this->assertContains("INVALID_DISPUTE_ACTION", $ex->getMessage()); + } + } + + public function testReportDisputeChallenge() + { + $dispute = new DisputeSummary(); + $dispute->caseId = "DIS_SAND_abcd1234"; + $document = new DisputeDocument(); + $document->type = 'SALES_RECEIPT'; + $document->b64_content = 'R0lGODlhigPCAXAAACwAAAAAigPCAYf///8AQnv'; + $documents[] = $document; + $response = $dispute->challenge($documents)->execute(); + + $this->assertNotNull($response); + $this->assertEquals('SUCCESS', $response->responseCode); + } + + public function testReportDisputeChallengeWrongId() + { + $dispute = new DisputeSummary(); + $dispute->caseId = "DIS_SAND_aaaa0000"; + $document = new DisputeDocument(); + $document->type = 'SALES_RECEIPT'; + $document->b64_content = 'R0lGODlhigPCAXAAACwAAAAAigPCAYf///8AQnv'; + $documents[] = $document; + try{ + $dispute->challenge($documents)->execute(); + } catch(GatewayException $ex){ + $this->assertEquals("40060", $ex->responseCode); + $this->assertContains("INVALID_DISPUTE_ACTION", $ex->getMessage()); + } + } +} \ No newline at end of file diff --git a/test/Integration/Gateways/GpApiConnector/ReportingSettlementTransactionsTest.php b/test/Integration/Gateways/GpApiConnector/ReportingSettlementTransactionsTest.php new file mode 100644 index 00000000..af3a58ca --- /dev/null +++ b/test/Integration/Gateways/GpApiConnector/ReportingSettlementTransactionsTest.php @@ -0,0 +1,664 @@ +setUpConfig()); + } + + public function testReportFindSettlementTransactionsByStartDateAndEndDate() + { + $startDate = (new \DateTime())->modify('-30 days'); + $endDate = (new \DateTime())->modify('-3 days'); + try { + $response = ReportingService::findSettlementTransactions() + ->orderBy(TransactionSortProperty::TIME_CREATED, SortDirection::DESC) + ->withPaging(1, 10) + ->where(SearchCriteria::START_DATE, $startDate) + ->andWith(SearchCriteria::END_DATE, $endDate) + ->execute(); + } catch (ApiException $e) { + $this->fail('Find settlement transactions failed with: ' . $e->getMessage()); + } + /** @var TransactionSummary $rs */ + foreach ($response as $rs) { + $this->assertGreaterThanOrEqual($startDate, $rs->transactionDate); + $this->assertLessThanOrEqual($endDate, $rs->transactionDate); + } + } + + public function testReportFindSettlementTransactions_OrderBy_TimeCreated() + { + $startDate = (new \DateTime())->modify('-30 days'); + try { + $response = ReportingService::findSettlementTransactions() + ->orderBy(TransactionSortProperty::TIME_CREATED, SortDirection::DESC) + ->withPaging(1, 10) + ->where(SearchCriteria::START_DATE, $startDate) + ->execute(); + } catch (ApiException $e) { + $this->fail('Find settlement transactions failed with: ' . $e->getMessage()); + } + /** @var TransactionSummary $rs */ + foreach ($response as $rs) { + $this->assertInstanceOf(TransactionSummary::class, $rs); + $this->assertGreaterThanOrEqual($startDate, $rs->transactionDate); + } + + try { + $responseAsc = ReportingService::findSettlementTransactions() + ->orderBy(TransactionSortProperty::TIME_CREATED, SortDirection::ASC) + ->withPaging(1, 10) + ->where(SearchCriteria::START_DATE, $startDate) + ->execute(); + } catch (ApiException $e) { + $this->fail('Find settlement transactions failed with: ' . $e->getMessage()); + } + /** @var TransactionSummary $rs */ + foreach ($responseAsc as $rs) { + $this->assertInstanceOf(TransactionSummary::class, $rs); + $this->assertGreaterThanOrEqual($startDate, $rs->transactionDate); + } + + $this->assertNotSame($response, $responseAsc); + } + + public function testReportFindSettlementTransactions_OrderBy_Status() + { + $startDate = (new \DateTime())->modify('-30 days'); + try { + $response = ReportingService::findSettlementTransactions() + ->orderBy(TransactionSortProperty::STATUS, SortDirection::DESC) + ->withPaging(1, 10) + ->where(SearchCriteria::START_DATE, $startDate) + ->execute(); + } catch (ApiException $e) { + $this->fail('Find settlement transactions failed with: ' . $e->getMessage()); + } + /** @var TransactionSummary $randomTransaction */ + $randomTransaction = $response[array_rand($response)]; + $this->assertNotNull($randomTransaction); + $this->assertInstanceOf(TransactionSummary::class, $randomTransaction); + $this->assertGreaterThanOrEqual($startDate, $randomTransaction->transactionDate); + + try { + $responseAsc = ReportingService::findSettlementTransactions() + ->orderBy(TransactionSortProperty::STATUS, SortDirection::ASC) + ->withPaging(1, 10) + ->where(SearchCriteria::START_DATE, $startDate) + ->execute(); + } catch (ApiException $e) { + $this->fail('Find settlement transactions failed with: ' . $e->getMessage()); + } + /** @var TransactionSummary $randomTransaction */ + $randomTransaction = $responseAsc[array_rand($responseAsc)]; + $this->assertNotNull($randomTransaction); + $this->assertInstanceOf(TransactionSummary::class, $randomTransaction); + $this->assertGreaterThanOrEqual($startDate, $randomTransaction->transactionDate); + + $this->assertNotSame($response, $responseAsc); + } + + public function testReportFindSettlementTransactions_OrderBy_Type() + { + $startDate = (new \DateTime())->modify('-30 days'); + try { + $response = ReportingService::findSettlementTransactions() + ->orderBy(TransactionSortProperty::TYPE, SortDirection::DESC) + ->withPaging(1, 10) + ->where(SearchCriteria::START_DATE, $startDate) + ->execute(); + } catch (ApiException $e) { + $this->fail('Find settlement transactions failed with: ' . $e->getMessage()); + } + /** @var TransactionSummary $randomTransaction */ + $randomTransaction = $response[array_rand($response)]; + $this->assertNotNull($randomTransaction); + $this->assertInstanceOf(TransactionSummary::class, $randomTransaction); + $this->assertGreaterThanOrEqual($startDate, $randomTransaction->transactionDate); + + try { + $responseAsc = ReportingService::findSettlementTransactions() + ->orderBy(TransactionSortProperty::TYPE, SortDirection::ASC) + ->withPaging(1, 10) + ->where(SearchCriteria::START_DATE, $startDate) + ->execute(); + } catch (ApiException $e) { + $this->fail('Find settlement transactions failed with: ' . $e->getMessage()); + } + /** @var TransactionSummary $randomTransaction */ + $randomTransaction = $responseAsc[array_rand($responseAsc)]; + $this->assertNotNull($randomTransaction); + $this->assertInstanceOf(TransactionSummary::class, $randomTransaction); + $this->assertGreaterThanOrEqual($startDate, $randomTransaction->transactionDate); + + $this->assertNotSame($response, $responseAsc); + } + + public function testReportFindSettlementTransactions_OrderBy_TypeAndTimeCreated() + { + $startDate = (new \DateTime())->modify('-30 days'); + try { + $response = ReportingService::findSettlementTransactions() + ->orderBy(TransactionSortProperty::TIME_CREATED, SortDirection::DESC) + ->withPaging(1, 10) + ->where(SearchCriteria::START_DATE, $startDate) + ->execute(); + } catch (ApiException $e) { + $this->fail('Find settlement transactions failed with: ' . $e->getMessage()); + } + /** @var TransactionSummary $randomTransaction */ + $randomTransaction = $response[array_rand($response)]; + $this->assertNotNull($randomTransaction); + $this->assertInstanceOf(TransactionSummary::class, $randomTransaction); + $this->assertGreaterThanOrEqual($startDate, $randomTransaction->transactionDate); + + try { + $responseType = ReportingService::findSettlementTransactions() + ->orderBy(TransactionSortProperty::TYPE, SortDirection::ASC) + ->withPaging(1, 10) + ->where(SearchCriteria::START_DATE, $startDate) + ->execute(); + } catch (ApiException $e) { + $this->fail('Find settlement transactions failed with: ' . $e->getMessage()); + } + /** @var TransactionSummary $randomTransaction */ + $randomTransaction = $responseType[array_rand($responseType)]; + $this->assertNotNull($randomTransaction); + $this->assertInstanceOf(TransactionSummary::class, $randomTransaction); + $this->assertGreaterThanOrEqual($startDate, $randomTransaction->transactionDate); + + $this->assertNotSame($response, $responseType); + } + + public function testReportFindSettlementTransactions_FilterBy_NumberFirst6_And_NumberLast4() + { + $startDate = (new \DateTime())->modify('-30 days'); + $numberFirst6 = "376768"; + $numberLast4 = "5006"; + + try { + $response = ReportingService::findSettlementTransactions() + ->orderBy(TransactionSortProperty::TIME_CREATED, SortDirection::DESC) + ->withPaging(1, 10) + ->where(SearchCriteria::START_DATE, $startDate) + ->andWith(SearchCriteria::CARD_NUMBER_FIRST_SIX, $numberFirst6) + ->andWith(SearchCriteria::CARD_NUMBER_LAST_FOUR, $numberLast4) + ->execute(); + } catch (ApiException $e) { + $this->fail('Find settlement transactions failed with: ' . $e->getMessage()); + } + /** @var TransactionSummary $rs */ + foreach ($response as $rs) { + $this->assertInstanceOf(TransactionSummary::class, $rs); + $this->assertGreaterThanOrEqual($startDate, $rs->transactionDate); + $this->assertStringStartsWith($numberFirst6, $rs->maskedCardNumber); + $this->assertStringEndsWith($numberLast4, $rs->maskedCardNumber); + } + } + + public function testReportFindSettlementTransactions_FilterBy_DepositStatus() + { + $startDate = (new \DateTime())->modify('-30 days'); + $depositStatus = new DepositStatus(); + $reflectionClass = new ReflectionClass($depositStatus); + foreach ($reflectionClass->getConstants() as $value) { + try { + $response = ReportingService::findSettlementTransactions() + ->orderBy(TransactionSortProperty::TIME_CREATED, SortDirection::DESC) + ->withPaging(1, 10) + ->where(SearchCriteria::START_DATE, $startDate) + ->andWith(SearchCriteria::DEPOSIT_STATUS, $value) + ->execute(); + } catch (ApiException $e) { + $this->fail('Find settlement transactions failed with: ' . $e->getMessage()); + } + $this->assertNotNull($response); + $this->assertTrue(is_array($response)); + /** @var TransactionSummary $rs */ + foreach ($response as $rs) { + $this->assertInstanceOf(TransactionSummary::class, $rs); + $this->assertGreaterThanOrEqual($startDate, $rs->transactionDate); + $this->assertEquals($value, $rs->depositStatus); + } + } + } + + public function testReportFindSettlementTransactions_FilterBy_CardBrand() + { + $startDate = (new \DateTime())->modify('-30 days'); + $cardBrand = array("VISA", "MASTERCARD", "AMEX", "DINERS", "DISCOVER", "JCB", "CUP"); + foreach ($cardBrand as $value) { + try { + $response = ReportingService::findSettlementTransactions() + ->orderBy(TransactionSortProperty::TIME_CREATED, SortDirection::DESC) + ->withPaging(1, 10) + ->where(SearchCriteria::START_DATE, $startDate) + ->andWith(SearchCriteria::CARD_BRAND, $value) + ->execute(); + } catch (ApiException $e) { + $this->fail('Find settlement transactions failed with: ' . $e->getMessage()); + } + + $this->assertNotNull($response); + $this->assertTrue(is_array($response)); + /** @var TransactionSummary $rs */ + foreach ($response as $rs) { + $this->assertInstanceOf(TransactionSummary::class, $rs); + $this->assertGreaterThanOrEqual($startDate, $rs->transactionDate); + $this->assertStringStartsWith($value, $rs->cardType); + } + } + } + + public function testReportFindSettlementTransactions_FilterBy_Wrong_CardBrand() + { + $startDate = (new \DateTime())->modify('-30 days'); + $cardBrand = "Bank of America"; + try { + $response = ReportingService::findSettlementTransactions() + ->orderBy(TransactionSortProperty::TIME_CREATED, SortDirection::DESC) + ->withPaging(1, 10) + ->where(SearchCriteria::START_DATE, $startDate) + ->andWith(SearchCriteria::CARD_BRAND, $cardBrand) + ->execute(); + } catch (ApiException $e) { + $this->fail('Find settlement transactions failed with: ' . $e->getMessage()); + } + $this->assertNotNull($response); + $this->assertTrue(is_array($response)); + $this->assertEquals(0, count($response)); + } + + public function testReportFindSettlementTransactions_FilterBy_ARN() + { + $startDate = (new \DateTime())->modify('-30 days'); + $arn = "24137550037630153798573"; + + try { + $response = ReportingService::findSettlementTransactions() + ->orderBy(TransactionSortProperty::TIME_CREATED, SortDirection::DESC) + ->withPaging(1, 10) + ->where(SearchCriteria::START_DATE, $startDate) + ->andWith(SearchCriteria::AQUIRER_REFERENCE_NUMBER, $arn) + ->execute(); + } catch (ApiException $e) { + $this->fail('Find settlement transactions failed with: ' . $e->getMessage()); + } + /** @var TransactionSummary $rs */ + foreach ($response as $rs) { + $this->assertInstanceOf(TransactionSummary::class, $rs); + $this->assertGreaterThanOrEqual($startDate, $rs->transactionDate); + $this->assertEquals($arn, $rs->aquirerReferenceNumber); + } + } + + public function testReportFindSettlementTransactions_FilterBy_Wrong_ARN() + { + $startDate = (new \DateTime())->modify('-30 days'); + $arn = GenerationUtils::getGuid(); + + try { + $response = ReportingService::findSettlementTransactions() + ->orderBy(TransactionSortProperty::TIME_CREATED, SortDirection::DESC) + ->withPaging(1, 10) + ->where(SearchCriteria::START_DATE, $startDate) + ->andWith(SearchCriteria::AQUIRER_REFERENCE_NUMBER, $arn) + ->execute(); + } catch (ApiException $e) { + $this->fail('Find settlement transactions failed with: ' . $e->getMessage()); + } + $this->assertNotNull($response); + $this->assertTrue(is_array($response)); + $this->assertEquals(0, count($response)); + } + + public function testReportFindSettlementTransactions_FilterBy_BrandReference() + { + $startDate = (new \DateTime())->modify('-30 days'); + $brandReference = "460008653352066"; + + try { + $response = ReportingService::findSettlementTransactions() + ->orderBy(TransactionSortProperty::TIME_CREATED, SortDirection::DESC) + ->withPaging(1, 10) + ->where(SearchCriteria::START_DATE, $startDate) + ->andWith(SearchCriteria::BRAND_REFERENCE, $brandReference) + ->execute(); + } catch (ApiException $e) { + $this->fail('Find settlement transactions failed with: ' . $e->getMessage()); + } + /** @var TransactionSummary $rs */ + foreach ($response as $rs) { + $this->assertInstanceOf(TransactionSummary::class, $rs); + $this->assertGreaterThanOrEqual($startDate, $rs->transactionDate); + $this->assertEquals($brandReference, $rs->brandReference); + } + } + + public function testReportFindSettlementTransactions_FilterBy_Wrong_BrandReference() + { + $startDate = (new \DateTime())->modify('-30 days'); + $brandReference = GenerationUtils::getGuid(); + $brandReference = trim(str_replace("-", "", $brandReference)); + + try { + $response = ReportingService::findSettlementTransactions() + ->orderBy(TransactionSortProperty::TIME_CREATED, SortDirection::DESC) + ->withPaging(1, 10) + ->where(SearchCriteria::START_DATE, $startDate) + ->andWith(SearchCriteria::BRAND_REFERENCE, $brandReference) + ->execute(); + } catch (ApiException $e) { + $this->fail('Find settlement transactions failed with: ' . $e->getMessage()); + } + $this->assertNotNull($response); + $this->assertTrue(is_array($response)); + $this->assertEquals(0, count($response)); + } + + public function testReportFindSettlementTransactions_FilterBy_AuthCode() + { + $startDate = (new \DateTime())->modify('-30 days'); + $authCode = "931951"; + + try { + $response = ReportingService::findSettlementTransactions() + ->orderBy(TransactionSortProperty::TIME_CREATED, SortDirection::DESC) + ->withPaging(1, 10) + ->where(SearchCriteria::START_DATE, $startDate) + ->andWith(SearchCriteria::AUTH_CODE, $authCode) + ->execute(); + } catch (ApiException $e) { + $this->fail('Find settlement transactions failed with: ' . $e->getMessage()); + } + /** @var TransactionSummary $rs */ + foreach ($response as $rs) { + $this->assertInstanceOf(TransactionSummary::class, $rs); + $this->assertGreaterThanOrEqual($startDate, $rs->transactionDate); + $this->assertEquals($authCode, $rs->authCode); + } + } + + public function testReportFindSettlementTransactions_FilterBy_Reference() + { + $startDate = (new \DateTime())->modify('-30 days'); + $reference = "50080513769"; + + try { + $response = ReportingService::findSettlementTransactions() + ->orderBy(TransactionSortProperty::TIME_CREATED, SortDirection::DESC) + ->withPaging(1, 10) + ->where(SearchCriteria::START_DATE, $startDate) + ->andWith(SearchCriteria::REFERENCE_NUMBER, $reference) + ->execute(); + } catch (ApiException $e) { + $this->fail('Find settlement transactions failed with: ' . $e->getMessage()); + } + /** @var TransactionSummary $rs */ + foreach ($response as $rs) { + $this->assertInstanceOf(TransactionSummary::class, $rs); + $this->assertGreaterThanOrEqual($startDate, $rs->transactionDate); + $this->assertEquals($reference, $rs->referenceNumber); + } + } + + public function testReportFindSettlementTransactions_FilterBy_Random_Reference() + { + $startDate = (new \DateTime())->modify('-30 days'); + $reference = GenerationUtils::getGuid(); + $reference = trim(str_replace("-", "", $reference)); + + try { + $response = ReportingService::findSettlementTransactions() + ->orderBy(TransactionSortProperty::TIME_CREATED, SortDirection::DESC) + ->withPaging(1, 10) + ->where(SearchCriteria::START_DATE, $startDate) + ->andWith(SearchCriteria::REFERENCE_NUMBER, $reference) + ->execute(); + } catch (ApiException $e) { + $this->fail('Find settlement transactions failed with: ' . $e->getMessage()); + } + $this->assertNotNull($response); + $this->assertTrue(is_array($response)); + $this->assertEquals(0, count($response)); + } + + public function testReportFindSettlementTransactions_FilterBy_Status() + { + //only for Status = FUNDED and REJECTED + $startDate = (new \DateTime())->modify('-30 days'); + $transactionStatus = new TransactionStatus(); + $reflectionClass = new ReflectionClass($transactionStatus); + foreach ($reflectionClass->getConstants() as $value) { + try { + $response = ReportingService::findSettlementTransactions() + ->orderBy(TransactionSortProperty::TIME_CREATED, SortDirection::DESC) + ->withPaging(1, 10) + ->where(SearchCriteria::START_DATE, $startDate) + ->andWith(SearchCriteria::TRANSACTION_STATUS, $value) + ->execute(); + } catch (ApiException $e) { + $this->fail('Find settlement transactions failed with: ' . $e->getMessage()); + } + $this->assertNotNull($response); + $this->assertTrue(is_array($response)); + + /** @var TransactionSummary $rs */ + foreach ($response as $rs) { + $this->assertInstanceOf(TransactionSummary::class, $rs); + $this->assertGreaterThanOrEqual($startDate, $rs->transactionDate); + $this->assertEquals(TransactionStatus::$mapTransactionStatusResponse[$value], $rs->transactionStatus); + } + } + } + + public function testReportFindSettlementTransactions_FilterBy_DepositID() + { + $startDate = (new \DateTime())->modify('-30 days'); + $depositId = "DEP_2342423423"; + + try { + $response = ReportingService::findSettlementTransactions() + ->orderBy(TransactionSortProperty::TIME_CREATED, SortDirection::DESC) + ->withPaging(1, 10) + ->where(SearchCriteria::START_DATE, $startDate) + ->andWith(SearchCriteria::DEPOSIT_ID, $depositId) + ->execute(); + } catch (ApiException $e) { + $this->fail('Find settlement transactions failed with: ' . $e->getMessage()); + } + /** @var TransactionSummary $rs */ + foreach ($response as $rs) { + $this->assertInstanceOf(TransactionSummary::class, $rs); + $this->assertGreaterThanOrEqual($startDate, $rs->transactionDate); + $this->assertEquals($depositId, $rs->depositId); + } + } + + public function testReportFindSettlementTransactions_FilterBy_Random_DepositID() + { + $startDate = (new \DateTime())->modify('-30 days'); + $depositID = GenerationUtils::getGuid(); + $depositID = trim(str_replace("-", "", $depositID)); + + try { + $response = ReportingService::findSettlementTransactions() + ->orderBy(TransactionSortProperty::TIME_CREATED, SortDirection::DESC) + ->withPaging(1, 10) + ->where(SearchCriteria::START_DATE, $startDate) + ->andWith(SearchCriteria::DEPOSIT_ID, $depositID) + ->execute(); + } catch (ApiException $e) { + $this->fail('Find settlement transactions failed with: ' . $e->getMessage()); + } + $this->assertNotNull($response); + $this->assertTrue(is_array($response)); + $this->assertEquals(0, count($response)); + } + + public function testReportFindSettlementTransactions_FilterBy_FromDepositTimeCreated_And_ToDepositTimeCreated() + { + $startDate = (new \DateTime())->modify('-30 days'); + $endDate = (new \DateTime())->modify('-3 days'); + try { + $response = ReportingService::findSettlementTransactions() + ->orderBy(TransactionSortProperty::TIME_CREATED, SortDirection::DESC) + ->withPaging(1, 10) + ->where(SearchCriteria::START_DATE, $startDate) + ->andWith(DataServiceCriteria::START_DEPOSIT_DATE, $startDate) + ->andWith(DataServiceCriteria::END_DEPOSIT_DATE, $endDate) + ->execute(); + } catch (ApiException $e) { + $this->fail('Find settlement transactions failed with: ' . $e->getMessage()); + } + /** @var TransactionSummary $rs */ + foreach ($response as $rs) { + $this->assertInstanceOf(TransactionSummary::class, $rs); + $this->assertGreaterThanOrEqual($startDate, $rs->depositTimeCreated); + $this->assertLessThanOrEqual($endDate, $rs->depositTimeCreated); + } + } + + public function testReportFindSettlementTransactions_FilterBy_FromBatchTimeCreated_And_ToBatchTimeCreated() + { + $startDate = (new \DateTime())->modify('-30 days'); + $endDate = (new \DateTime())->modify('-3 days'); + try { + $response = ReportingService::findSettlementTransactions() + ->orderBy(TransactionSortProperty::TIME_CREATED, SortDirection::DESC) + ->withPaging(1, 10) + ->where(SearchCriteria::START_DATE, $startDate) + ->andWith(DataServiceCriteria::START_BATCH_DATE, $startDate) + ->andWith(DataServiceCriteria::END_BATCH_DATE, $endDate) + ->execute(); + } catch (ApiException $e) { + $this->fail('Find settlement transactions failed with: ' . $e->getMessage()); + } + /** @var TransactionSummary $rs */ + foreach ($response as $rs) { + $this->assertInstanceOf(TransactionSummary::class, $rs); + $this->assertGreaterThanOrEqual($startDate, $rs->batchCloseDate); + $this->assertLessThanOrEqual($endDate, $rs->batchCloseDate); + } + } + + public function testReportFindSettlementTransactions_FilterBy_SystemMid_And_SystemHierarchy() + { + $startDate = (new \DateTime())->modify('-30 days'); + $endDate = (new \DateTime())->modify('-10 days'); + $systemMid = "101023947262"; + $systemHierarchy = "055-70-024-011-019"; + try { + $response = ReportingService::findSettlementTransactions() + ->orderBy(TransactionSortProperty::TIME_CREATED, SortDirection::DESC) + ->withPaging(1, 10) + ->where(SearchCriteria::START_DATE, $startDate) + ->andWith(DataServiceCriteria::MERCHANT_ID, $systemMid) + ->andWith(DataServiceCriteria::SYSTEM_HIERARCHY, $systemHierarchy) + ->execute(); + } catch (ApiException $e) { + $this->fail('Find settlement transactions failed with: ' . $e->getMessage()); + } + /** @var TransactionSummary $rs */ + foreach ($response as $rs) { + $this->assertGreaterThanOrEqual($startDate, $rs->transactionDate); + $this->assertLessThanOrEqual($rs->transactionDate, $endDate); + $this->assertEquals($systemMid, $rs->merchantId); + $this->assertEquals($systemHierarchy, $rs->merchantHierarchy); + } + } + + public function testReportFindSettlementTransactions_FilterBy_Random_MerchantID() + { + $startDate = (new \DateTime())->modify('-30 days'); + $merchantID = "111"; + + try { + $response = ReportingService::findSettlementTransactions() + ->orderBy(TransactionSortProperty::TIME_CREATED, SortDirection::DESC) + ->withPaging(1, 10) + ->where(SearchCriteria::START_DATE, $startDate) + ->andWith(DataServiceCriteria::MERCHANT_ID, $merchantID) + ->execute(); + } catch (ApiException $e) { + $this->fail('Find settlement transactions failed with: ' . $e->getMessage()); + } + $this->assertNotNull($response); + $this->assertTrue(is_array($response)); + $this->assertEquals(0, count($response)); + } + + public function testReportFindSettlementTransactions_FilterBy_Random_SystemHierarchy() + { + $startDate = (new \DateTime())->modify('-30 days'); + $systemHierarchy = "100-00-000-000-001"; + + try { + $response = ReportingService::findSettlementTransactions() + ->orderBy(TransactionSortProperty::TIME_CREATED, SortDirection::DESC) + ->withPaging(1, 10) + ->where(SearchCriteria::START_DATE, $startDate) + ->andWith(DataServiceCriteria::SYSTEM_HIERARCHY, $systemHierarchy) + ->execute(); + } catch (ApiException $e) { + $this->fail('Find settlement transactions failed with: ' . $e->getMessage()); + } + $this->assertNotNull($response); + $this->assertTrue(is_array($response)); + $this->assertEquals(0, count($response)); + } + + public function testReportFindSettlementTransactions_FilterBy_Invalid_MerchantID() + { + $startDate = (new \DateTime())->modify('-30 days'); + $merchantID = GenerationUtils::getGuid(); + $merchantID = trim(str_replace("-", "", $merchantID)); + + try { + ReportingService::findSettlementTransactions() + ->orderBy(TransactionSortProperty::TIME_CREATED, SortDirection::DESC) + ->withPaging(1, 10) + ->where(SearchCriteria::START_DATE, $startDate) + ->andWith(DataServiceCriteria::MERCHANT_ID, $merchantID) + ->execute(); + } catch (GatewayException $e) { + $this->assertEquals('40100', $e->responseCode); + $this->assertEquals("Status Code: INVALID_REQUEST_DATA - Invalid Value provided in the input field - system.mid", $e->getMessage()); + } + } + + public function setUpConfig() + { + $config = new GpApiConfig(); + $accessTokenInfo = new \GlobalPayments\Api\Utils\AccessTokenInfo(); + //this is gpapistuff stuff + $config->setAppId('i872l4VgZRtSrykvSn8Lkah8RE1jihvT'); + $config->setAppKey('9pArW2uWoA8enxKc'); + $config->environment = Environment::TEST; + $config->setAccessTokenInfo($accessTokenInfo); +// $klogger = new Logger("C:\\laragon\\www\\PHP-SDK-v3\\logs"); +// $config->requestLogger = new SampleRequestLogger($klogger); + return $config; + } +} \ No newline at end of file diff --git a/test/Integration/Gateways/GpApiConnector/ReportingTransactionsTest.php b/test/Integration/Gateways/GpApiConnector/ReportingTransactionsTest.php new file mode 100644 index 00000000..d81436c6 --- /dev/null +++ b/test/Integration/Gateways/GpApiConnector/ReportingTransactionsTest.php @@ -0,0 +1,667 @@ +setUpConfig()); + } + + public function testTransactionDetailsReport() + { + $transactionId = 'TRN_piIDuelPio1Vk1JWE7bNatWngfxUQT'; + try { + /** @var TransactionSummary $response */ + $response = ReportingService::transactionDetail($transactionId)->execute(); + } catch (ApiException $e) { + $this->fail("Transaction details report failed with " . $e->getMessage()); + } + $this->assertNotNull($response); + $this->assertInstanceOf(TransactionSummary::class, $response); + $this->assertEquals($transactionId, $response->transactionId); + } + + public function testTransactionDetailsReport_WrongId() + { + $transactionId = GenerationUtils::getGuid(); + try { + ReportingService::transactionDetail($transactionId) + ->execute(); + } catch (GatewayException $e) { + $this->assertEquals('40118', $e->responseCode); + $this->assertEquals("Status Code: RESOURCE_NOT_FOUND - Transactions " . $transactionId . " not found at this /ucp/transactions/" . $transactionId . "", $e->getMessage()); + } + } + + public function testReportFindTransactionsByStartDateAndEndDate() + { + $startDate = new \DateTime('2020-11-01 midnight'); + $endDate = new \DateTime('2020-12-01 23:59'); + try { + $response = ReportingService::findTransactions() + ->orderBy(TransactionSortProperty::TIME_CREATED) + ->withPaging(1, 10) + ->where(SearchCriteria::START_DATE, $startDate) + ->andWith(SearchCriteria::END_DATE, $endDate) + ->execute(); + } catch (ApiException $e) { + $this->fail("Find transactions failed with " . $e->getMessage()); + } + + $this->assertNotNull($response); + $this->assertTrue(is_array($response)); + /** @var TransactionSummary $rs */ + foreach ($response as $rs) { + $this->assertLessThanOrEqual($endDate, $rs->transactionDate); + $this->assertGreaterThanOrEqual($startDate, $rs->transactionDate); + } + } + + public function testReportFindTransactionsById() + { + $transactionId = 'TRN_mCBetNCJSP0xdJK1QdlfBsMVzemHHt'; + $startDate = new \DateTime('2020-11-01 midnight'); + try { + $response = ReportingService::findTransactions() + ->withTransactionId($transactionId) + ->where(SearchCriteria::START_DATE, $startDate) + ->execute(); + } catch (ApiException $e) { + $this->fail("Find transactions by Id failed: " . $e->getMessage()); + } + + $this->assertNotNull($response); + $this->assertTrue(is_array($response)); + $this->assertEquals(1, count($response)); + $this->assertEquals($transactionId, $response[0]->transactionId); + } + + public function testReportFindTransactionsById_WrongId() + { + $transactionId = GenerationUtils::getGuid();; + $startDate = new \DateTime('2020-11-01 midnight'); + try { + $response = ReportingService::findTransactions() + ->withTransactionId($transactionId) + ->where(SearchCriteria::START_DATE, $startDate) + ->execute(); + } catch (ApiException $e) { + $this->fail("Find transactions by Id failed: " . $e->getMessage()); + } + + $this->assertNotNull($response); + $this->assertTrue(is_array($response)); + $this->assertEquals(0, count($response)); + } + + public function testReportFindTransactionsByBatchId() + { + $batchId = 'BAT_870078'; + $startDate = new \DateTime('2020-11-01 midnight'); + try { + $response = ReportingService::findTransactions() + ->orderBy(TransactionSortProperty::TIME_CREATED, SortDirection::DESC) + ->withPaging(1, 10) + ->where(SearchCriteria::BATCH_ID, $batchId) + ->andWith(SearchCriteria::START_DATE, $startDate) + ->execute(); + } catch (ApiException $e) { + $this->fail('Find transactions by batch id failed: ' . $e->getMessage()); + } + + $this->assertNotNull($response); + $this->assertTrue(is_array($response)); + /** @var TransactionSummary $rs */ + foreach ($response as $rs) { + $this->assertEquals($batchId, $rs->batchSequenceNumber); + } + } + + public function testReportFindTransactionsByType() + { + $paymentType = PaymentType::SALE; + $startDate = new \DateTime('2020-11-01 midnight'); + try { + $response = ReportingService::findTransactions() + ->orderBy(TransactionSortProperty::TIME_CREATED, SortDirection::DESC) + ->withPaging(1, 10) + ->where(SearchCriteria::PAYMENT_TYPE, $paymentType) + ->andWith(SearchCriteria::START_DATE, $startDate) + ->execute(); + } catch (ApiException $e) { + $this->fail('Find transactions by type failed: ' . $e->getMessage()); + } + + $this->assertNotNull($response); + $this->assertTrue(is_array($response)); + /** @var TransactionSummary $rs */ + foreach ($response as $rs) { + $this->assertEquals($paymentType, $rs->transactionType); + } + + $paymentTypeRefund = PaymentType::REFUND; + try { + $responseRefund = ReportingService::findTransactions() + ->orderBy(TransactionSortProperty::TIME_CREATED, SortDirection::DESC) + ->withPaging(1, 10) + ->where(SearchCriteria::PAYMENT_TYPE, $paymentTypeRefund) + ->andWith(SearchCriteria::START_DATE, $startDate) + ->execute(); + } catch (ApiException $e) { + $this->fail('Find transactions by type failed: ' . $e->getMessage()); + } + + $this->assertNotNull($responseRefund); + $this->assertTrue(is_array($responseRefund)); + /** @var TransactionSummary $rs */ + foreach ($responseRefund as $rs) { + $this->assertEquals($paymentTypeRefund, $rs->transactionType); + } + + $this->assertNotSame($response, $responseRefund); + } + + public function testReportFindTransactionsByAmountAndCurrencyAndCountry() + { + $amount = 19.99; + $currency = 'USD'; //case sensitive + $country = 'US'; //case sensitive + $startDate = new \DateTime('2020-11-01 midnight'); + try { + $response = ReportingService::findTransactions() + ->orderBy(TransactionSortProperty::TIME_CREATED, SortDirection::DESC) + ->withPaging(1, 10) + ->where(DataServiceCriteria::AMOUNT, $amount) + ->andWith(SearchCriteria::START_DATE, $startDate) + ->andWith(DataServiceCriteria::CURRENCY, $currency) + ->andWith(DataServiceCriteria::COUNTRY, $country) + ->execute(); + } catch (ApiException $e) { + $this->fail('Find transactions by amount, currency and country failed: ' . $e->getMessage()); + } + + $this->assertNotNull($response); + $this->assertTrue(is_array($response)); + /** @var TransactionSummary $rs */ + foreach ($response as $rs) { + $this->assertEquals($amount, $rs->amount); + $this->assertEquals($currency, $rs->currency); + $this->assertEquals($country, $rs->country); + } + } + + public function testReportFindTransactionsByChannel() + { + $channel = Channels::CardNotPresent; + $startDate = new \DateTime('2020-11-01 midnight'); + try { + $response = ReportingService::findTransactions() + ->orderBy(TransactionSortProperty::TIME_CREATED, SortDirection::DESC) + ->withPaging(1, 10) + ->where(SearchCriteria::CHANNEL, $channel) + ->andWith(SearchCriteria::START_DATE, $startDate) + ->execute(); + } catch (ApiException $e) { + $this->fail('Find transactions by channel failed: ' . $e->getMessage()); + } + + $this->assertNotNull($response); + $this->assertTrue(is_array($response)); + /** @var TransactionSummary $rs */ + foreach ($response as $rs) { + $this->assertEquals($channel, $rs->channel); + } + + $channelCP = Channels::CardPresent; + try { + $responseCP = ReportingService::findTransactions() + ->orderBy(TransactionSortProperty::TIME_CREATED, SortDirection::DESC) + ->withPaging(1, 10) + ->where(SearchCriteria::CHANNEL, $channelCP) + ->andWith(SearchCriteria::START_DATE, $startDate) + ->execute(); + } catch (ApiException $e) { + $this->fail('Find transactions by channel failed: ' . $e->getMessage()); + } + + $this->assertNotNull($responseCP); + $this->assertTrue(is_array($responseCP)); + /** @var TransactionSummary $rs */ + foreach ($responseCP as $rs) { + $this->assertEquals($channelCP, $rs->channel); + } + + $this->assertNotSame($response, $responseCP); + } + + public function testReportFindTransactionsByStatus() + { + $transactionStatus = TransactionStatus::CAPTURED; + $startDate = new \DateTime('2020-11-01 midnight'); + try { + $response = ReportingService::findTransactions() + ->orderBy(TransactionSortProperty::TIME_CREATED, SortDirection::DESC) + ->withPaging(1, 10) + ->where(SearchCriteria::TRANSACTION_STATUS, $transactionStatus) + ->andWith(SearchCriteria::START_DATE, $startDate) + ->execute(); + } catch (ApiException $e) { + $this->fail('Find transactions by status failed: ' . $e->getMessage()); + } + + $this->assertNotNull($response); + $this->assertTrue(is_array($response)); + /** @var TransactionSummary $rs */ + foreach ($response as $rs) { + $this->assertEquals($transactionStatus, $rs->transactionStatus); + } + } + + public function testReportFindTransactionsBy_AllStatuses() + { + $startDate = new \DateTime('2020-11-01 midnight'); + + $transactionStatus = new TransactionStatus(); + $reflectionClass = new ReflectionClass($transactionStatus); + foreach ($reflectionClass->getConstants() as $value) { + try { + $response = ReportingService::findTransactions() + ->orderBy(TransactionSortProperty::TIME_CREATED, SortDirection::DESC) + ->withPaging(1, 10) + ->where(SearchCriteria::TRANSACTION_STATUS, $value) + ->andWith(SearchCriteria::START_DATE, $startDate) + ->execute(); + } catch (ApiException $e) { + $this->fail('Find transactions by status failed: ' . $e->getMessage()); + } + + $this->assertNotNull($response); + $this->assertTrue(is_array($response)); + /** @var TransactionSummary $rs */ + foreach ($response as $rs) { + $this->assertEquals(TransactionStatus::$mapTransactionStatusResponse[$value], $rs->transactionStatus); + } + } + } + + public function testReportFindTransactionsByCardBrandAndAuthCode() + { + $cardBrand = 'VISA'; + $authCode = '12345'; + $startDate = new \DateTime('2020-11-01 midnight'); + try { + $response = ReportingService::findTransactions() + ->orderBy(TransactionSortProperty::TIME_CREATED, SortDirection::DESC) + ->withPaging(1, 10) + ->where(SearchCriteria::CARD_BRAND, $cardBrand) + ->andWith(SearchCriteria::START_DATE, $startDate) + ->andWith(SearchCriteria::AUTH_CODE, $authCode) + ->execute(); + } catch (ApiException $e) { + $this->fail('Find transactions by type failed: ' . $e->getMessage()); + } + + $this->assertNotNull($response); + $this->assertTrue(is_array($response)); + /** @var TransactionSummary $rs */ + foreach ($response as $rs) { + $this->assertEquals($cardBrand, $rs->cardType); + $this->assertEquals($authCode, $rs->authCode); + } + } + + public function testReportFindTransactionsBy_AllCardBrands() + { + $startDate = new \DateTime('2020-11-01 midnight'); + + $cardBrand = array("VISA", "MASTERCARD", "AMEX", "DINERS", "DISCOVER", "JCB", "CUP"); + foreach ($cardBrand as $value) { + try { + $response = ReportingService::findTransactions() + ->orderBy(TransactionSortProperty::TIME_CREATED, SortDirection::DESC) + ->withPaging(1, 10) + ->where(SearchCriteria::CARD_BRAND, $value) + ->andWith(SearchCriteria::START_DATE, $startDate) + ->execute(); + } catch (ApiException $e) { + $this->fail('Find transactions by type failed: ' . $e->getMessage()); + } + + $this->assertNotNull($response); + $this->assertTrue(is_array($response)); + if ($value == "MASTERCARD") { + $value = "MC"; + } + /** @var TransactionSummary $rs */ + foreach ($response as $rs) { + $this->assertEquals($value, $rs->cardType); + } + } + } + + public function testReportFindTransactionsByReference() + { + $referenceNumber = '1010000158841908572'; + $startDate = new \DateTime('2020-11-01 midnight'); + try { + $response = ReportingService::findTransactions() + ->orderBy(TransactionSortProperty::TIME_CREATED, SortDirection::DESC) + ->withPaging(1, 10) + ->where(SearchCriteria::REFERENCE_NUMBER, $referenceNumber) + ->andWith(SearchCriteria::START_DATE, $startDate) + ->execute(); + } catch (ApiException $e) { + $this->fail('Find transactions by type failed: ' . $e->getMessage()); + } + + $this->assertNotNull($response); + $this->assertTrue(is_array($response)); + /** @var TransactionSummary $rs */ + foreach ($response as $rs) { + $this->assertEquals($referenceNumber, $rs->referenceNumber); + } + } + + public function testReportFindTransactionsBy_WrongReference() + { + $referenceNumber = GenerationUtils::getGuid();; + $startDate = new \DateTime('2020-11-01 midnight'); + try { + $response = ReportingService::findTransactions() + ->orderBy(TransactionSortProperty::TIME_CREATED, SortDirection::DESC) + ->withPaging(1, 10) + ->where(SearchCriteria::REFERENCE_NUMBER, $referenceNumber) + ->andWith(SearchCriteria::START_DATE, $startDate) + ->execute(); + } catch (ApiException $e) { + $this->fail('Find transactions by type failed: ' . $e->getMessage()); + } + + $this->assertNotNull($response); + $this->assertTrue(is_array($response)); + $this->assertEquals(0, count($response)); + } + + public function testReportFindTransactionsByBrandReference() + { + $brandReference = 's9RpaDwXq1sPRkbP'; + $startDate = new \DateTime('2020-11-01 midnight'); + try { + $response = ReportingService::findTransactions() + ->orderBy(TransactionSortProperty::TIME_CREATED, SortDirection::DESC) + ->withPaging(1, 10) + ->where(SearchCriteria::BRAND_REFERENCE, $brandReference) + ->andWith(SearchCriteria::START_DATE, $startDate) + ->execute(); + } catch (ApiException $e) { + $this->fail('Find transactions by brand reference failed: ' . $e->getMessage()); + } + + $this->assertNotNull($response); + $this->assertTrue(is_array($response)); + /** @var TransactionSummary $rs */ + foreach ($response as $rs) { + $this->assertEquals($brandReference, $rs->brandReference); + } + } + + public function testReportFindTransactionsBy_WrongBrandReference() + { + $brandReference = GenerationUtils::getGuid();; + $startDate = new \DateTime('2020-11-01 midnight'); + try { + $response = ReportingService::findTransactions() + ->orderBy(TransactionSortProperty::TIME_CREATED, SortDirection::DESC) + ->withPaging(1, 10) + ->where(SearchCriteria::BRAND_REFERENCE, $brandReference) + ->andWith(SearchCriteria::START_DATE, $startDate) + ->execute(); + } catch (ApiException $e) { + $this->fail('Find transactions by brand reference failed: ' . $e->getMessage()); + } + + $this->assertNotNull($response); + $this->assertTrue(is_array($response)); + $this->assertEquals(0, count($response)); + } + + public function testReportFindTransactionsByEntryMode() + { + $startDate = new \DateTime('2020-11-01 midnight'); + $entryMode = new EntryMode(); + $reflectionClass = new ReflectionClass($entryMode); + foreach ($reflectionClass->getConstants() as $value) { + try { + $response = ReportingService::findTransactions() + ->orderBy(TransactionSortProperty::TIME_CREATED, SortDirection::DESC) + ->withPaging(1, 10) + ->where(SearchCriteria::PAYMENT_ENTRY_MODE, $value) + ->andWith(SearchCriteria::START_DATE, $startDate) + ->execute(); + } catch (ApiException $e) { + $this->fail('Find transactions by entry mode failed: ' . $e->getMessage()); + } + + $this->assertNotNull($response); + $this->assertTrue(is_array($response)); + /** @var TransactionSummary $rs */ + foreach ($response as $rs) { + $this->assertEquals($value, $rs->entryMode); + } + } + } + + public function testReportFindTransactionsBy_NumberFirst6_and_NumberLast4() + { + $numberFirst6 = "411111"; + $numberLast4 = "1111"; + + $startDate = new \DateTime('2020-11-01 midnight'); + try { + $response = ReportingService::findTransactions() + ->orderBy(TransactionSortProperty::TIME_CREATED, SortDirection::DESC) + ->withPaging(1, 10) + ->where(SearchCriteria::CARD_NUMBER_FIRST_SIX, $numberFirst6) + ->andWith(SearchCriteria::CARD_NUMBER_LAST_FOUR, $numberLast4) + ->andWith(SearchCriteria::START_DATE, $startDate) + ->execute(); + } catch (ApiException $e) { + $this->fail('Find transactions by entry mode failed: ' . $e->getMessage()); + } + + $this->assertNotNull($response); + $this->assertTrue(is_array($response)); + /** @var TransactionSummary $rs */ + foreach ($response as $rs) { + $this->assertStringStartsWith($numberFirst6, $rs->maskedCardNumber); + $this->assertStringEndsWith($numberLast4, $rs->maskedCardNumber); + } + } + + public function testReportFindTransactionsBy_TokenFirst6_and_TokenLast4() + { + $tokenFirst6 = "516730"; + $tokenLast4 = "5507"; + $startDate = new \DateTime('2020-11-01 midnight'); + try { + $response = ReportingService::findTransactions() + ->orderBy(TransactionSortProperty::TIME_CREATED, SortDirection::DESC) + ->withPaging(1, 10) + ->where(SearchCriteria::TOKEN_FIRST_SIX, $tokenFirst6) + ->andWith(SearchCriteria::TOKEN_LAST_FOUR, $tokenLast4) + ->andWith(SearchCriteria::START_DATE, $startDate) + ->execute(); + } catch (ApiException $e) { + $this->fail('Find transactions by entry mode failed: ' . $e->getMessage()); + } + $this->assertNotNull($response); + $this->assertTrue(is_array($response)); + /** @var TransactionSummary $rs */ + foreach ($response as $rs) { + $this->assertStringStartsWith($tokenFirst6, (string)$rs->maskedCardNumber); + $this->assertStringEndsWith($tokenLast4, $rs->maskedCardNumber); + } + } + + public function testReportFindTransactionsBy_Name() + { + $name = "NAME NOT PROVIDED"; + $startDate = new \DateTime('2020-11-01 midnight'); + try { + $response = ReportingService::findTransactions() + ->where(SearchCriteria::CARDHOLDER_NAME, $name) + ->andWith(SearchCriteria::START_DATE, $startDate) + ->execute(); + } catch (ApiException $e) { + $this->fail('Find transactions by entry mode failed: ' . $e->getMessage()); + } + $this->assertNotNull($response); + $this->assertTrue(is_array($response)); + /** @var TransactionSummary $rs */ + foreach ($response as $rs) { + $this->assertEquals($name, $rs->cardHolderName); + } + } + + public function testReportFindTransactions_OrderBy_Status() + { + $startDate = new \DateTime('2020-11-01 midnight'); + try { + $response = ReportingService::findTransactions() + ->orderBy(TransactionSortProperty::STATUS, SortDirection::DESC) + ->withPaging(1, 10) + ->where(SearchCriteria::START_DATE, $startDate) + ->execute(); + } catch (ApiException $e) { + $this->fail('Find transactions by entry mode failed: ' . $e->getMessage()); + } + + $this->assertNotNull($response); + $this->assertTrue(is_array($response)); + } + + public function testReportFindTransactions_OrderBy_Type() + { + $startDate = new \DateTime('2020-11-01 midnight'); + try { + $response = ReportingService::findTransactions() + ->orderBy(TransactionSortProperty::TYPE, SortDirection::DESC) + ->withPaging(1, 10) + ->where(SearchCriteria::START_DATE, $startDate) + ->execute(); + } catch (ApiException $e) { + $this->fail('Find transactions by entry mode failed: ' . $e->getMessage()); + } + + $this->assertNotNull($response); + $this->assertTrue(is_array($response)); + + try { + $responseAsc = ReportingService::findTransactions() + ->orderBy(TransactionSortProperty::TYPE, SortDirection::ASC) + ->withPaging(1, 10) + ->where(SearchCriteria::START_DATE, $startDate) + ->execute(); + } catch (ApiException $e) { + $this->fail('Find transactions by entry mode failed: ' . $e->getMessage()); + } + + $this->assertNotNull($responseAsc); + $this->assertTrue(is_array($responseAsc)); + + $this->assertNotSame($response, $responseAsc); + } + + public function testReportFindTransactions_OrderBy_TypeAndTimeCreated() + { + $startDate = new \DateTime('2020-11-01 midnight'); + try { + $response = ReportingService::findTransactions() + ->orderBy(TransactionSortProperty::TYPE, SortDirection::DESC) + ->withPaging(1, 10) + ->where(SearchCriteria::START_DATE, $startDate) + ->execute(); + } catch (ApiException $e) { + $this->fail('Find transactions by entry mode failed: ' . $e->getMessage()); + } + + $this->assertNotNull($response); + $this->assertTrue(is_array($response)); + + try { + $responseTime = ReportingService::findTransactions() + ->orderBy(TransactionSortProperty::TIME_CREATED, SortDirection::DESC) + ->withPaging(1, 10) + ->where(SearchCriteria::START_DATE, $startDate) + ->execute(); + } catch (ApiException $e) { + $this->fail('Find transactions by entry mode failed: ' . $e->getMessage()); + } + + $this->assertNotNull($responseTime); + $this->assertTrue(is_array($responseTime)); + + $this->assertNotSame($response, $responseTime); + } + + public function testReportFindTransactions_InvalidAccountName() + { + $startDate = new \DateTime('2020-11-01 midnight'); + try { + ReportingService::findTransactions() + ->where(SearchCriteria::START_DATE, $startDate) + ->andWith(SearchCriteria::ACCOUNT_NAME, "12345") + ->execute(); + } catch (ApiException $e) { + $this->assertEquals('40003', $e->responseCode); + $this->assertEquals("Status Code: ACTION_NOT_AUTHORIZED - Token does not match account_id or account_name in the request", $e->getMessage()); + } + } + + public function testReportFindTransactions_WithoutStartDate() + { + try { + ReportingService::findTransactions() + ->execute(); + } catch (ApiException $e) { + $this->assertEquals('40075', $e->responseCode); + $this->assertEquals("Status Code: MANDATORY_DATA_MISSING - Retrieving a list expects a date range to be populated", $e->getMessage()); + } + } + + public function setUpConfig() + { + $config = new GpApiConfig(); + $accessTokenInfo = new \GlobalPayments\Api\Utils\AccessTokenInfo(); + //this is gpapistuff stuff + $config->setAppId('VuKlC2n1cr5LZ8fzLUQhA7UObVks6tFF'); + $config->setAppKey('NmGM0kg92z2gA7Og'); + $config->environment = Environment::TEST; + $config->setAccessTokenInfo($accessTokenInfo); +// $klogger = new Logger("C:\\laragon\\www\\PHP-SDK-v3\\logs"); +// $config->requestLogger = new SampleRequestLogger($klogger); + + return $config; + } +} diff --git a/test/Integration/Gateways/PorticoConnector/Certifications/CheckTest.php b/test/Integration/Gateways/PorticoConnector/Certifications/CheckTest.php index 4a32f6d2..081f4b82 100644 --- a/test/Integration/Gateways/PorticoConnector/Certifications/CheckTest.php +++ b/test/Integration/Gateways/PorticoConnector/Certifications/CheckTest.php @@ -1,378 +1,378 @@ -secretApiKey = 'skapi_cert_MTyMAQBiHVEAewvIzXVFcmUd2UcyBge_eCpaASUp0A'; - $config->serviceUrl = ($this->enableCryptoUrl) ? - 'https://cert.api2-c.heartlandportico.com/': - 'https://cert.api2.heartlandportico.com'; - return $config; - } - - protected function setup() - { - ServicesContainer::configureService($this->config()); - - $this->address = new Address(); - $this->address->streetAddress1 = '123 Main St.'; - $this->address->city = 'Downtown'; - $this->address->province = 'NJ'; - $this->address->postalCode = '12345'; - } - - /// ACH Debit - Consumer - - public function test001ConsumerPersonalChecking() - { - $check = TestChecks::certification( - SecCode::PPD, - CheckType::PERSONAL, - AccountType::CHECKING - ); - - $response = $check->charge(11.00) - ->withCurrency('USD') - ->withAddress($this->address) - ->execute(); - - $this->assertNotNull($response); - $this->assertEquals('00', $response->responseCode); - - // test case 25 - $voidResponse = $response->void()->execute(); - $this->assertNotNull($voidResponse); - $this->assertEquals('00', $voidResponse->responseCode); - } - - public function test002ConsumerBusinessChecking() - { - $check = TestChecks::certification( - SecCode::PPD, - CheckType::BUSINESS, - AccountType::CHECKING - ); - - $response = $check->charge(12.00) - ->withCurrency('USD') - ->withAddress($this->address) - ->execute(); - - $this->assertNotNull($response); - $this->assertEquals('00', $response->responseCode); - } - - public function test003ConsumerPersonalSavings() - { - $check = TestChecks::certification( - SecCode::PPD, - CheckType::PERSONAL, - AccountType::SAVINGS - ); - - $response = $check->charge(13.00) - ->withCurrency('USD') - ->withAddress($this->address) - ->execute(); - - $this->assertNotNull($response); - $this->assertEquals('00', $response->responseCode); - } - - public function test004ConsumerBusinessSavings() - { - $check = TestChecks::certification( - SecCode::PPD, - CheckType::BUSINESS, - AccountType::SAVINGS - ); - - $response = $check->charge(14.00) - ->withCurrency('USD') - ->withAddress($this->address) - ->execute(); - - $this->assertNotNull($response); - $this->assertEquals('00', $response->responseCode); - } - - public function test005CorporatePersonalChecking() - { - $check = TestChecks::certification( - SecCode::CCD, - CheckType::PERSONAL, - AccountType::CHECKING, - "Heartland Pays" - ); - - $response = $check->charge(15.00) - ->withCurrency('USD') - ->withAddress($this->address) - ->execute(); - - $this->assertNotNull($response); - $this->assertEquals('00', $response->responseCode); - - // test case 26 - $voidResponse = $response->void()->execute(); - $this->assertNotNull($voidResponse); - $this->assertEquals('00', $voidResponse->responseCode); - } - - public function test006CorporateBusinessChecking() - { - $check = TestChecks::certification( - SecCode::CCD, - CheckType::BUSINESS, - AccountType::CHECKING, - "Heartland Pays" - ); - - $response = $check->charge(16.00) - ->withCurrency('USD') - ->withAddress($this->address) - ->execute(); - - $this->assertNotNull($response); - $this->assertEquals('00', $response->responseCode); - } - - public function test007CorporatePersonalSavings() - { - $check = TestChecks::certification( - SecCode::CCD, - CheckType::PERSONAL, - AccountType::SAVINGS, - "Heartland Pays" - ); - - $response = $check->charge(17.00) - ->withCurrency('USD') - ->withAddress($this->address) - ->execute(); - - $this->assertNotNull($response); - $this->assertEquals('00', $response->responseCode); - } - - public function test008CorporateBusinessSavings() - { - $check = TestChecks::certification( - SecCode::CCD, - CheckType::BUSINESS, - AccountType::SAVINGS, - "Heartland Pays" - ); - - $response = $check->charge(18.00) - ->withCurrency('USD') - ->withAddress($this->address) - ->execute(); - - $this->assertNotNull($response); - $this->assertEquals('00', $response->responseCode); - } - - public function test010EgoldBusinessChecking() - { - $check = TestChecks::certification( - SecCode::CCD, - CheckType::BUSINESS, - AccountType::CHECKING - ); - - $response = $check->charge(12.00) - ->withCurrency('USD') - ->withAddress($this->address) - ->execute(); - - $this->assertNotNull($response); - $this->assertEquals('00', $response->responseCode); - } - - public function test014EsilverBusinessChecking() - { - $check = TestChecks::certification( - SecCode::CCD, - CheckType::BUSINESS, - AccountType::CHECKING - ); - - $response = $check->charge(16.00) - ->withCurrency('USD') - ->withAddress($this->address) - ->execute(); - - $this->assertNotNull($response); - $this->assertEquals('00', $response->responseCode); - } - - /** - * @expectedException GlobalPayments\Api\Entities\Exceptions\GatewayException - * @expectedExceptionMessage Processor Configuration error - */ - public function test017EbronzePersonalChecking() - { - $check = TestChecks::certification( - SecCode::EBRONZE, - CheckType::PERSONAL, - AccountType::CHECKING - ); - - $response = $check->charge(19.00) - ->withCurrency('USD') - ->withAddress($this->address) - ->execute(); - - $this->assertNotNull($response); - $this->assertEquals('00', $response->responseCode); - } - - /** - * @expectedException GlobalPayments\Api\Entities\Exceptions\GatewayException - * @expectedExceptionMessage Processor Configuration error - */ - public function test018EbronzeBusinessChecking() - { - $check = TestChecks::certification( - SecCode::EBRONZE, - CheckType::BUSINESS, - AccountType::CHECKING - ); - - $response = $check->charge(20.00) - ->withCurrency('USD') - ->withAddress($this->address) - ->execute(); - - $this->assertNotNull($response); - $this->assertEquals('00', $response->responseCode); - } - - /** - * @expectedException GlobalPayments\Api\Entities\Exceptions\GatewayException - * @expectedExceptionMessage Processor Configuration error - */ - public function test019EbronzePersonalSavings() - { - $check = TestChecks::certification( - SecCode::EBRONZE, - CheckType::PERSONAL, - AccountType::SAVINGS - ); - - $response = $check->charge(21.00) - ->withCurrency('USD') - ->withAddress($this->address) - ->execute(); - - $this->assertNotNull($response); - $this->assertEquals('00', $response->responseCode); - } - - /** - * @expectedException GlobalPayments\Api\Entities\Exceptions\GatewayException - * @expectedExceptionMessage Processor Configuration error - */ - public function test020EbronzeBusinessSavings() - { - $check = TestChecks::certification( - SecCode::EBRONZE, - CheckType::BUSINESS, - AccountType::SAVINGS - ); - - $response = $check->charge(22.00) - ->withCurrency('USD') - ->withAddress($this->address) - ->execute(); - - $this->assertNotNull($response); - $this->assertEquals('00', $response->responseCode); - } - - public function test021WebPersonalChecking() - { - $check = TestChecks::certification( - SecCode::WEB, - CheckType::PERSONAL, - AccountType::CHECKING - ); - - $response = $check->charge(23.00) - ->withCurrency('USD') - ->withAddress($this->address) - ->execute(); - - $this->assertNotNull($response); - $this->assertEquals('00', $response->responseCode); - } - - public function test022WebBusinessChecking() - { - $check = TestChecks::certification( - SecCode::WEB, - CheckType::BUSINESS, - AccountType::CHECKING - ); - - $response = $check->charge(24.00) - ->withCurrency('USD') - ->withAddress($this->address) - ->execute(); - - $this->assertNotNull($response); - $this->assertEquals('00', $response->responseCode); - } - - public function test023WebPersonalSavings() - { - $check = TestChecks::certification( - SecCode::WEB, - CheckType::PERSONAL, - AccountType::SAVINGS - ); - - $response = $check->charge(25.00) - ->withCurrency('USD') - ->withAddress($this->address) - ->execute(); - - $this->assertNotNull($response); - $this->assertEquals('00', $response->responseCode); - } - - public function test024WebBusinessSavings() - { - $check = TestChecks::certification( - SecCode::WEB, - CheckType::BUSINESS, - AccountType::SAVINGS - ); - - $response = $check->charge(5.00) - ->withCurrency('USD') - ->withAddress($this->address) - ->execute(); - - $this->assertNotNull($response); - $this->assertEquals('00', $response->responseCode); - } -} +secretApiKey = 'skapi_cert_MTyMAQBiHVEAewvIzXVFcmUd2UcyBge_eCpaASUp0A'; + $config->serviceUrl = ($this->enableCryptoUrl) ? + 'https://cert.api2-c.heartlandportico.com/': + 'https://cert.api2.heartlandportico.com'; + return $config; + } + + protected function setup() + { + ServicesContainer::configureService($this->config()); + + $this->address = new Address(); + $this->address->streetAddress1 = '123 Main St.'; + $this->address->city = 'Downtown'; + $this->address->province = 'NJ'; + $this->address->postalCode = '12345'; + } + + /// ACH Debit - Consumer + + public function test001ConsumerPersonalChecking() + { + $check = TestChecks::certification( + SecCode::PPD, + CheckType::PERSONAL, + AccountType::CHECKING + ); + + $response = $check->charge(11.00) + ->withCurrency('USD') + ->withAddress($this->address) + ->execute(); + + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode); + + // test case 25 + $voidResponse = $response->void()->execute(); + $this->assertNotNull($voidResponse); + $this->assertEquals('00', $voidResponse->responseCode); + } + + public function test002ConsumerBusinessChecking() + { + $check = TestChecks::certification( + SecCode::PPD, + CheckType::BUSINESS, + AccountType::CHECKING + ); + + $response = $check->charge(12.00) + ->withCurrency('USD') + ->withAddress($this->address) + ->execute(); + + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode); + } + + public function test003ConsumerPersonalSavings() + { + $check = TestChecks::certification( + SecCode::PPD, + CheckType::PERSONAL, + AccountType::SAVINGS + ); + + $response = $check->charge(13.00) + ->withCurrency('USD') + ->withAddress($this->address) + ->execute(); + + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode); + } + + public function test004ConsumerBusinessSavings() + { + $check = TestChecks::certification( + SecCode::PPD, + CheckType::BUSINESS, + AccountType::SAVINGS + ); + + $response = $check->charge(14.00) + ->withCurrency('USD') + ->withAddress($this->address) + ->execute(); + + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode); + } + + public function test005CorporatePersonalChecking() + { + $check = TestChecks::certification( + SecCode::CCD, + CheckType::PERSONAL, + AccountType::CHECKING, + "Heartland Pays" + ); + + $response = $check->charge(15.00) + ->withCurrency('USD') + ->withAddress($this->address) + ->execute(); + + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode); + + // test case 26 + $voidResponse = $response->void()->execute(); + $this->assertNotNull($voidResponse); + $this->assertEquals('00', $voidResponse->responseCode); + } + + public function test006CorporateBusinessChecking() + { + $check = TestChecks::certification( + SecCode::CCD, + CheckType::BUSINESS, + AccountType::CHECKING, + "Heartland Pays" + ); + + $response = $check->charge(16.00) + ->withCurrency('USD') + ->withAddress($this->address) + ->execute(); + + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode); + } + + public function test007CorporatePersonalSavings() + { + $check = TestChecks::certification( + SecCode::CCD, + CheckType::PERSONAL, + AccountType::SAVINGS, + "Heartland Pays" + ); + + $response = $check->charge(17.00) + ->withCurrency('USD') + ->withAddress($this->address) + ->execute(); + + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode); + } + + public function test008CorporateBusinessSavings() + { + $check = TestChecks::certification( + SecCode::CCD, + CheckType::BUSINESS, + AccountType::SAVINGS, + "Heartland Pays" + ); + + $response = $check->charge(18.00) + ->withCurrency('USD') + ->withAddress($this->address) + ->execute(); + + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode); + } + + public function test010EgoldBusinessChecking() + { + $check = TestChecks::certification( + SecCode::CCD, + CheckType::BUSINESS, + AccountType::CHECKING + ); + + $response = $check->charge(12.00) + ->withCurrency('USD') + ->withAddress($this->address) + ->execute(); + + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode); + } + + public function test014EsilverBusinessChecking() + { + $check = TestChecks::certification( + SecCode::CCD, + CheckType::BUSINESS, + AccountType::CHECKING + ); + + $response = $check->charge(16.00) + ->withCurrency('USD') + ->withAddress($this->address) + ->execute(); + + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode); + } + + /** + * @expectedException GlobalPayments\Api\Entities\Exceptions\GatewayException + * @expectedExceptionMessage Processor Configuration error + */ + public function test017EbronzePersonalChecking() + { + $check = TestChecks::certification( + SecCode::EBRONZE, + CheckType::PERSONAL, + AccountType::CHECKING + ); + + $response = $check->charge(19.00) + ->withCurrency('USD') + ->withAddress($this->address) + ->execute(); + + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode); + } + + /** + * @expectedException GlobalPayments\Api\Entities\Exceptions\GatewayException + * @expectedExceptionMessage Processor Configuration error + */ + public function test018EbronzeBusinessChecking() + { + $check = TestChecks::certification( + SecCode::EBRONZE, + CheckType::BUSINESS, + AccountType::CHECKING + ); + + $response = $check->charge(20.00) + ->withCurrency('USD') + ->withAddress($this->address) + ->execute(); + + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode); + } + + /** + * @expectedException GlobalPayments\Api\Entities\Exceptions\GatewayException + * @expectedExceptionMessage Processor Configuration error + */ + public function test019EbronzePersonalSavings() + { + $check = TestChecks::certification( + SecCode::EBRONZE, + CheckType::PERSONAL, + AccountType::SAVINGS + ); + + $response = $check->charge(21.00) + ->withCurrency('USD') + ->withAddress($this->address) + ->execute(); + + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode); + } + + /** + * @expectedException GlobalPayments\Api\Entities\Exceptions\GatewayException + * @expectedExceptionMessage Processor Configuration error + */ + public function test020EbronzeBusinessSavings() + { + $check = TestChecks::certification( + SecCode::EBRONZE, + CheckType::BUSINESS, + AccountType::SAVINGS + ); + + $response = $check->charge(22.00) + ->withCurrency('USD') + ->withAddress($this->address) + ->execute(); + + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode); + } + + public function test021WebPersonalChecking() + { + $check = TestChecks::certification( + SecCode::WEB, + CheckType::PERSONAL, + AccountType::CHECKING + ); + + $response = $check->charge(23.00) + ->withCurrency('USD') + ->withAddress($this->address) + ->execute(); + + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode); + } + + public function test022WebBusinessChecking() + { + $check = TestChecks::certification( + SecCode::WEB, + CheckType::BUSINESS, + AccountType::CHECKING + ); + + $response = $check->charge(24.00) + ->withCurrency('USD') + ->withAddress($this->address) + ->execute(); + + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode); + } + + public function test023WebPersonalSavings() + { + $check = TestChecks::certification( + SecCode::WEB, + CheckType::PERSONAL, + AccountType::SAVINGS + ); + + $response = $check->charge(25.00) + ->withCurrency('USD') + ->withAddress($this->address) + ->execute(); + + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode); + } + + public function test024WebBusinessSavings() + { + $check = TestChecks::certification( + SecCode::WEB, + CheckType::BUSINESS, + AccountType::SAVINGS + ); + + $response = $check->charge(5.00) + ->withCurrency('USD') + ->withAddress($this->address) + ->execute(); + + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode); + } +} diff --git a/test/Integration/Gateways/PorticoConnector/Certifications/EcommerceCheckTest.php b/test/Integration/Gateways/PorticoConnector/Certifications/EcommerceCheckTest.php index 3beccb37..7ae28474 100644 --- a/test/Integration/Gateways/PorticoConnector/Certifications/EcommerceCheckTest.php +++ b/test/Integration/Gateways/PorticoConnector/Certifications/EcommerceCheckTest.php @@ -1,108 +1,108 @@ -secretApiKey = 'skapi_cert_MTyMAQBiHVEAewvIzXVFcmUd2UcyBge_eCpaASUp0A'; - $config->serviceUrl = ($this->enableCryptoUrl) ? - 'https://cert.api2-c.heartlandportico.com/': - 'https://cert.api2.heartlandportico.com'; - return $config; - } - - protected function setup() - { - ServicesContainer::configureService($this->config()); - - $this->address = new Address(); - $this->address->streetAddress1 = '123 Main St.'; - $this->address->city = 'Downtown'; - $this->address->province = 'NJ'; - $this->address->postalCode = '12345'; - } - - public function test001ConsumerPersonalChecking() - { - $check = TestChecks::certification( - SecCode::WEB, - CheckType::PERSONAL, - AccountType::CHECKING - ); - - $response = $check->charge(19.00) - ->withCurrency('USD') - ->withAddress($this->address) - ->execute(); - - $this->assertNotNull($response); - $this->assertEquals('00', $response->responseCode); - } - - public function test002ConsumerBusinessChecking() - { - $check = TestChecks::certification( - SecCode::WEB, - CheckType::BUSINESS, - AccountType::CHECKING - ); - - $response = $check->charge(20.00) - ->withCurrency('USD') - ->withAddress($this->address) - ->execute(); - - $this->assertNotNull($response); - $this->assertEquals('00', $response->responseCode); - } - - public function test003ConsumerPersonalSavings() - { - $check = TestChecks::certification( - SecCode::WEB, - CheckType::PERSONAL, - AccountType::SAVINGS - ); - - $response = $check->charge(21.00) - ->withCurrency('USD') - ->withAddress($this->address) - ->execute(); - - $this->assertNotNull($response); - $this->assertEquals('00', $response->responseCode); - } - - public function test004ConsumerBusinessSavings() - { - $check = TestChecks::certification( - SecCode::WEB, - CheckType::BUSINESS, - AccountType::SAVINGS - ); - - $response = $check->charge(22.00) - ->withCurrency('USD') - ->withAddress($this->address) - ->execute(); - - $this->assertNotNull($response); - $this->assertEquals('00', $response->responseCode); - } -} +secretApiKey = 'skapi_cert_MTyMAQBiHVEAewvIzXVFcmUd2UcyBge_eCpaASUp0A'; + $config->serviceUrl = ($this->enableCryptoUrl) ? + 'https://cert.api2-c.heartlandportico.com/': + 'https://cert.api2.heartlandportico.com'; + return $config; + } + + protected function setup() + { + ServicesContainer::configureService($this->config()); + + $this->address = new Address(); + $this->address->streetAddress1 = '123 Main St.'; + $this->address->city = 'Downtown'; + $this->address->province = 'NJ'; + $this->address->postalCode = '12345'; + } + + public function test001ConsumerPersonalChecking() + { + $check = TestChecks::certification( + SecCode::WEB, + CheckType::PERSONAL, + AccountType::CHECKING + ); + + $response = $check->charge(19.00) + ->withCurrency('USD') + ->withAddress($this->address) + ->execute(); + + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode); + } + + public function test002ConsumerBusinessChecking() + { + $check = TestChecks::certification( + SecCode::WEB, + CheckType::BUSINESS, + AccountType::CHECKING + ); + + $response = $check->charge(20.00) + ->withCurrency('USD') + ->withAddress($this->address) + ->execute(); + + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode); + } + + public function test003ConsumerPersonalSavings() + { + $check = TestChecks::certification( + SecCode::WEB, + CheckType::PERSONAL, + AccountType::SAVINGS + ); + + $response = $check->charge(21.00) + ->withCurrency('USD') + ->withAddress($this->address) + ->execute(); + + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode); + } + + public function test004ConsumerBusinessSavings() + { + $check = TestChecks::certification( + SecCode::WEB, + CheckType::BUSINESS, + AccountType::SAVINGS + ); + + $response = $check->charge(22.00) + ->withCurrency('USD') + ->withAddress($this->address) + ->execute(); + + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode); + } +} diff --git a/test/Integration/Gateways/PorticoConnector/Certifications/EcommerceTest.php b/test/Integration/Gateways/PorticoConnector/Certifications/EcommerceTest.php index 62320006..85a5752a 100644 --- a/test/Integration/Gateways/PorticoConnector/Certifications/EcommerceTest.php +++ b/test/Integration/Gateways/PorticoConnector/Certifications/EcommerceTest.php @@ -1,1986 +1,1986 @@ -value = $card->value; - $data->encryptionData = $card->encryptionData; - $data->pinBlock = $pinBlock; - return $data; - } - - public static function asEBTTrack($card, $pinBlock) - { - $data = new EBTTrackData(); - $data->value = $card->value; - $data->entryMethod = $card->entryMethod; - $data->encryptionData = $card->encryptionData; - $data->pinBlock = $pinBlock; - return $data; - } - - public static function asEBTManual($card, $pinBlock) - { - $data = new EBTCardData(); - $data->number = $card->number; - $data->expMonth = $card->expMonth; - $data->expYear = $card->expYear; - $data->pinBlock = $pinBlock; - return $data; - } - - public static function visaManual($cardPresent = false, $readerPresent = false) - { - $data = new CreditCardData(); - $data->number = '4012002000060016'; - $data->expMonth = 12; - $data->expYear = self::validCardExpYear(); - $data->cvn = '123'; - $data->cardPresent = $cardPresent; - $data->readerPresent = $readerPresent; - return $data; - } - - public static function visaSwipe($entryMethod = null) - { - if ($entryMethod === null) { - $entryMethod = EntryMethod::SWIPE; - } - - $data = new CreditTrackData(); - $data->value = '%B4012002000060016^VI TEST CREDIT^251210118039000000000396?;4012002000060016=25121011803939600000?'; - $data->entryMethod = $entryMethod; - return $data; - } - - public static function visaSwipeEncrypted($entryMethod = null) - { - if ($entryMethod === null) { - $entryMethod = EntryMethod::SWIPE; - } - - $encryptionData = new EncryptionData(); - $encryptionData->version = '01'; - - $data = new CreditTrackData(); - $data->value = ';'; - $data->entryMethod = $entryMethod; - $data->encryptionData = $encryptionData; - return $data; - } - - public static function masterCardManual($cardPresent = false, $readerPresent = false) - { - $data = new CreditCardData(); - $data->number = '5473500000000014'; - $data->expMonth = 12; - $data->expYear = self::validCardExpYear(); - $data->cvn = '123'; - $data->cardPresent = $cardPresent; - $data->readerPresent = $readerPresent; - return $data; - } - - public static function masterCardSeries2Manual($cardPresent = false, $readerPresent = false) - { - $data = new CreditCardData(); - $data->number = '2223000010005780'; - $data->expMonth = 12; - $data->expYear = self::validCardExpYear(); - $data->cvn = '123'; - $data->cardPresent = $cardPresent; - $data->readerPresent = $readerPresent; - return $data; - } - - public static function masterCardSwipe($entryMethod = null) - { - if ($entryMethod === null) { - $entryMethod = EntryMethod::SWIPE; - } - - $data = new CreditTrackData(); - $data->value = '%B5473500000000014^MC TEST CARD^251210199998888777766665555444433332?;5473500000000014=25121019999888877776?'; - $data->entryMethod = $entryMethod; - return $data; - } - - public static function masterCard24Swipe($entryMethod = null) - { - if ($entryMethod === null) { - $entryMethod = EntryMethod::SWIPE; - } - - $data = new CreditTrackData(); - $data->value = '%B2223000010005780^TEST CARD/EMV BIN-2^19121010000000009210?;2223000010005780=19121010000000009210?'; - $data->entryMethod = $entryMethod; - return $data; - } - - public static function masterCard25Swipe($entryMethod = null) - { - if ($entryMethod === null) { - $entryMethod = EntryMethod::SWIPE; - } - - $data = new CreditTrackData(); - $data->value = '%B2223000010005798^TEST CARD/EMV BIN-2^19121010000000003840?;2223000010005798=19121010000000003840?'; - $data->entryMethod = $entryMethod; - return $data; - } - - public static function masterCardSwipeEncrypted($entryMethod = null) - { - if ($entryMethod === null) { - $entryMethod = EntryMethod::SWIPE; - } - - $encryptionData = new EncryptionData(); - $encryptionData->version = '01'; - - $data = new CreditTrackData(); - $data->value = ''; - $data->entryMethod = $entryMethod; - $data->encryptionData = $encryptionData; - return $data; - } - - public static function discoverManual($cardPresent = false, $readerPresent = false) - { - $data = new CreditCardData(); - $data->number = '6011000990156527'; - $data->expMonth = 12; - $data->expYear = self::validCardExpYear(); - $data->cvn = '123'; - $data->cardPresent = $cardPresent; - $data->readerPresent = $readerPresent; - return $data; - } - - public static function discoverSwipe($entryMethod = null) - { - if ($entryMethod === null) { - $entryMethod = EntryMethod::SWIPE; - } - - $data = new CreditTrackData(); - $data->value = '%B6011000990156527^DIS TEST CARD^25121011000062111401?;6011000990156527=25121011000062111401?'; - $data->entryMethod = $entryMethod; - return $data; - } - - public static function discoverSwipeEncrypted($entryMethod = null) - { - if ($entryMethod === null) { - $entryMethod = EntryMethod::SWIPE; - } - - $encryptionData = new EncryptionData(); - $encryptionData->version = '01'; - - $data = new CreditTrackData(); - $data->value = ''; - $data->entryMethod = $entryMethod; - $data->encryptionData = $encryptionData; - return $data; - } - - public static function amexManual($cardPresent = false, $readerPresent = false) - { - $data = new CreditCardData(); - $data->number = '372700699251018'; - $data->expMonth = 12; - $data->expYear = self::validCardExpYear(); - $data->cvn = '1234'; - $data->cardPresent = $cardPresent; - $data->readerPresent = $readerPresent; - return $data; - } - - public static function amexSwipe($entryMethod = null) - { - if ($entryMethod === null) { - $entryMethod = EntryMethod::SWIPE; - } - - $data = new CreditTrackData(); - $data->value = '%B3727 006992 51018^AMEX TEST CARD^2512990502700?;372700699251018=2512990502700?'; - $data->entryMethod = $entryMethod; - return $data; - } - - public static function jcbManual($cardPresent = false, $readerPresent = false) - { - $data = new CreditCardData(); - $data->number = '3566007770007321'; - $data->expMonth = 12; - $data->expYear = self::validCardExpYear(); - $data->cvn = '123'; - $data->cardPresent = $cardPresent; - $data->readerPresent = $readerPresent; - return $data; - } - - public static function jcbSwipe($entryMethod = null) - { - if ($entryMethod === null) { - $entryMethod = EntryMethod::SWIPE; - } - - $data = new CreditTrackData(); - $data->value = '%B3566007770007321^JCB TEST CARD^2512101100000000000000000064300000?;3566007770007321=25121011000000076435?'; - $data->entryMethod = $entryMethod; - return $data; - } - - public static function giftCard1Swipe() - { - $data = new GiftCard(); - $data->trackData = '%B5022440000000000098^^391200081613?;5022440000000000098=391200081613?'; - return $data; - } - - public static function giftCard2Manual() - { - $data = new GiftCard(); - $data->number = '5022440000000000007'; - return $data; - } - - public static function gsbManual() - { - $data = new CreditCardData(); - $data->number = '6277220572999800'; - $data->expMonth = '12'; - $data->expYear = self::validCardExpYear(); - return $data; - } -} - - - -class EcommerceTest extends TestCase -{ - const NO_TRANS_IN_BATCH = 'Batch close was rejected because no transactions are associated with the currently open batch.'; - const BATCH_NOT_OPEN = 'Transaction was rejected because it requires a batch to be open.'; - - /** @var bool */ - private $useTokens = true; - - /** @var bool */ - private $usePrepaid = false; - - /** @var string */ - private $publicKey = ''; - - /** @var EcommerceInfo */ - private $ecommerceInfo = null; - - /** @var string|null */ - public static $visaToken = null; - - /** @var string|null */ - public static $mastercardToken = null; - - /** @var string|null */ - public static $discoverToken = null; - - /** @var string|null */ - public static $amexToken = null; - - private $enableCryptoUrl = true; - - private function config() - { - $config = new PorticoConfig(); - $config->secretApiKey = 'skapi_cert_MTyMAQBiHVEAewvIzXVFcmUd2UcyBge_eCpaASUp0A'; - $config->serviceUrl = ($this->enableCryptoUrl) ? - 'https://cert.api2-c.heartlandportico.com/': - 'https://cert.api2.heartlandportico.com'; - return $config; - } - - protected function setup() : void - { - ServicesContainer::configureService($this->config()); - $this->publicKey = 'pkapi_cert_jKc1FtuyAydZhZfbB3'; - - $this->ecommerceInfo = new EcommerceInfo(); - $this->ecommerceInfo->channel = EcommerceChannel::ECOM; - } - - public function test000CloseBatch() - { - try { - $response = BatchService::closeBatch(); - $this->assertNotNull($response); - } catch (ApiException $e) { - if (false === strpos($e->getMessage(), static::BATCH_NOT_OPEN) - && false === strpos($e->getMessage(), static::NO_TRANS_IN_BATCH) - ) { - $this->fail($e->getMessage()); - } - } - } - - /// CARD VERIFY - - /// Account Verification - - public function test001VerifyVisa() - { - $card = TestCards::visaManual(); - - $response = $card->verify() - ->withRequestMultiUseToken($this->useTokens) - ->execute(); - - $this->assertEquals(true, $response != null); - $this->assertEquals('00', $response->responseCode); - } - - public function test002VerifyMasterCard() - { - $card = TestCards::masterCardManual(); - $response = $card->verify() - ->withRequestMultiUseToken($this->useTokens) - ->execute(); - - $this->assertEquals(true, $response != null); - $this->assertEquals('00', $response->responseCode); - } - - public function test003VerifyDiscover() - { - $address = new Address(); - $address->postalCode = '75024'; - - $card = TestCards::discoverManual(); - - $response = $card->verify() - ->withAddress($address) - ->withRequestMultiUseToken($this->useTokens) - ->execute(); - - $this->assertEquals(true, $response != null); - $this->assertEquals('00', $response->responseCode); - } - - /// Address Verification - - public function test004VerifyAmex() - { - $address = new Address(); - $address->postalCode = '75024'; - - $card = TestCards::amexManual(); - - $response = $card->verify() - ->withAddress($address) - ->withRequestMultiUseToken($this->useTokens) - ->execute(); - - $this->assertEquals(true, $response != null); - $this->assertEquals('00', $response->responseCode); - } - - /// Balance Inquiry (for Prepaid Card) - - public function test005BalanceInquiryVisa() - { - if (false === $this->usePrepaid) { - $this->markTestSkipped('GSB not configured'); - } - - $card = TestCards::visaManual(); - - $response = $card->balanceInquiry() - ->execute(); - - $this->assertEquals(true, $response != null); - $this->assertEquals('00', $response->responseCode); - } - - /// CREDIT SALE (For Multi-Use Token Only) - - public function test006ChargeVisaToken() - { - $address = new Address(); - $address->streetAddress1 = '6860 Dallas Pkwy'; - $address->postalCode = '75024'; - - $card = TestCards::visaManual(); - - $response = $card->charge() - ->withCurrency('USD') - ->withAmount(13.01) - ->withInvoiceNumber('123456') - ->withAddress($address) - ->withRequestMultiUseToken(true) - ->withEcommerceInfo($this->ecommerceInfo) - ->withAllowDuplicates(true) - ->execute(); - - $this->assertEquals(true, $response != null); - $this->assertEquals('00', $response->responseCode); - $this->assertEquals(true, $response->token != null); - self::$visaToken = $response->token; - } - - public function test007ChargeMasterCardToken() - { - $address = new Address(); - $address->streetAddress1 = '6860'; - $address->postalCode = '75024'; - - $card = TestCards::masterCardManual(); - - $response = $card->charge() - ->withCurrency('USD') - ->withAmount(13.02) - ->withInvoiceNumber('123456') - ->withAddress($address) - ->withRequestMultiUseToken(true) - ->withEcommerceInfo($this->ecommerceInfo) - ->withAllowDuplicates(true) - ->execute(); - - $this->assertEquals(true, $response != null); - $this->assertEquals('00', $response->responseCode); - $this->assertEquals(true, $response->token != null); - self::$mastercardToken = $response->token; - } - - public function test008ChargeDiscoverToken() - { - $address = new Address(); - $address->streetAddress1 = '6860'; - $address->postalCode = '750241234'; - - $card = TestCards::discoverManual(); - - $response = $card->charge() - ->withCurrency('USD') - ->withAmount(13.03) - ->withInvoiceNumber('123456') - ->withAddress($address) - ->withRequestMultiUseToken(true) - ->withEcommerceInfo($this->ecommerceInfo) - ->withAllowDuplicates(true) - ->execute(); - - $this->assertEquals(true, $response != null); - $this->assertEquals('00', $response->responseCode); - $this->assertEquals(true, $response->token != null); - self::$discoverToken = $response->token; - } - - public function test009ChargeAmexToken() - { - $address = new Address(); - $address->streetAddress1 = '6860 Dallas Pkwy'; - $address->postalCode = '75024'; - - $card = TestCards::visaManual(); - - $response = $card->charge() - ->withCurrency('USD') - ->withAmount(13.04) - ->withAddress($address) - ->withInvoiceNumber('123456') - ->withRequestMultiUseToken(true) - ->withEcommerceInfo($this->ecommerceInfo) - ->withAllowDuplicates(true) - ->execute(); - - $this->assertEquals(true, $response != null); - $this->assertEquals('00', $response->responseCode); - $this->assertEquals(true, $response->token != null); - self::$amexToken = $response->token; - } - - /// CREDIT SALE - - public function test010ChargeVisa() - { - $address = new Address(); - $address->streetAddress1 = '6860 Dallas Pkwy'; - $address->postalCode = '75024'; - - $card = TestCards::visaManual(); - if ($this->useTokens) { - $card = new CreditCardData(); - $card->token = self::$visaToken; - } - - $response = $card->charge() - ->withCurrency('USD') - ->withAmount(17.01) - ->withAddress($address) - ->withInvoiceNumber('123456') - ->withEcommerceInfo($this->ecommerceInfo) - ->withAllowDuplicates(true) - ->execute(); - - $this->assertEquals(true, $response != null); - $this->assertEquals('00', $response->responseCode); - - $voidResponse = $response->void() - ->execute(); - $this->assertEquals(true, $voidResponse != null); - $this->assertEquals('00', $voidResponse->responseCode); - } - - public function test011ChargeMastercard() - { - $address = new Address(); - $address->streetAddress1 = '6860'; - $address->postalCode = '75024'; - - $card = TestCards::masterCardManual(); - if ($this->useTokens) { - $card = new CreditCardData(); - $card->token = self::$mastercardToken; - } - - $response = $card->charge() - ->withCurrency('USD') - ->withAmount(17.02) - ->withAddress($address) - ->withInvoiceNumber('123456') - ->withEcommerceInfo($this->ecommerceInfo) - ->withAllowDuplicates(true) - ->execute(); - - $this->assertEquals(true, $response != null); - $this->assertEquals('00', $response->responseCode); - } - - public function test012ChargeDiscover() - { - $address = new Address(); - $address->streetAddress1 = '6860'; - $address->postalCode = '750241234'; - - $card = TestCards::discoverManual(); - if ($this->useTokens) { - $card = new CreditCardData(); - $card->token = self::$discoverToken; - } - - $response = $card->charge() - ->withCurrency('USD') - ->withAmount(17.03) - ->withAddress($address) - ->withInvoiceNumber('123456') - ->withEcommerceInfo($this->ecommerceInfo) - ->withAllowDuplicates(true) - ->execute(); - - $this->assertEquals(true, $response != null); - $this->assertEquals('00', $response->responseCode); - } - - public function test013ChargeAmex() - { - $address = new Address(); - $address->streetAddress1 = '6860 Dallas Pkwy'; - $address->postalCode = '75024'; - - $card = TestCards::amexManual(); - if ($this->useTokens) { - $card = new CreditCardData(); - $card->token = self::$amexToken; - } - - $response = $card->charge() - ->withCurrency('USD') - ->withAmount(17.04) - ->withAddress($address) - ->withInvoiceNumber('123456') - ->withEcommerceInfo($this->ecommerceInfo) - ->withAllowDuplicates(true) - ->execute(); - - $this->assertEquals(true, $response != null); - $this->assertEquals('00', $response->responseCode); - } - - public function test014ChargeJcb() - { - $address = new Address(); - $address->streetAddress1 = '6860 Dallas Pkwy'; - $address->postalCode = '75024'; - - $card = TestCards::jcbManual(); - - $response = $card->charge() - ->withCurrency('USD') - ->withAmount(17.04) - ->withAddress($address) - ->withInvoiceNumber('123456') - ->withEcommerceInfo($this->ecommerceInfo) - ->withAllowDuplicates(true) - ->execute(); - - $this->assertEquals(true, $response != null); - $this->assertEquals('00', $response->responseCode); - } - - public function test011bChargeMasterCard() - { - $address = new Address(); - $address->streetAddress1 = '6860'; - $address->postalCode = '75024'; - - $card = TestCards::masterCardSeries2Manual(); - - $response = $card->charge() - ->withCurrency('USD') - ->withAmount(17.02) - ->withAddress($address) - ->withInvoiceNumber('123456') - ->withEcommerceInfo($this->ecommerceInfo) - ->withAllowDuplicates(true) - ->execute(); - - $this->assertEquals(true, $response != null); - $this->assertEquals('00', $response->responseCode); - } - - /// AUTHORIZATION - - public function test015AuthorizationVisa() - { - # Test 015a Authorization - $address = new Address(); - $address->streetAddress1 = '6860 Dallas Pkwy'; - $address->postalCode = '75024'; - - - $card = TestCards::visaManual(); - - $response = $card->authorize(17.06) - ->withCurrency('USD') - ->withAddress($address) - ->withInvoiceNumber('123456') - ->withEcommerceInfo($this->ecommerceInfo) - ->withAllowDuplicates(true) - ->execute(); - - $this->assertEquals(true, $response != null); - $this->assertEquals('00', $response->responseCode); - - # test 015b Capture/AddToBatch - $capture = $response->capture() - ->execute(); - $this->assertEquals(true, $capture != null); - $this->assertEquals('00', $capture->responseCode); - } - - public function test016AuthorizationMastercard() - { - # Test 016a Authorization - $address = new Address(); - $address->streetAddress1 = '6860 Dallas Pkwy'; - $address->postalCode = '750241234'; - - $card = TestCards::masterCardManual(); - - $response = $card->authorize(17.07) - ->withCurrency('USD') - ->withAddress($address) - ->withInvoiceNumber('123456') - ->withEcommerceInfo($this->ecommerceInfo) - ->withAllowDuplicates(true) - ->execute(); - - $this->assertEquals(true, $response != null); - $this->assertEquals('00', $response->responseCode); - - # test 016b Capture/AddToBatch - $capture = $response->capture() - ->execute(); - $this->assertEquals(true, $capture != null); - $this->assertEquals('00', $capture->responseCode); - } - - public function test017AuthorizationDiscover() - { - # Test 017a Authorization - $address = new Address(); - $address->streetAddress1 = '6860'; - $address->postalCode = '75024'; - - $card = TestCards::discoverManual(); - - $response = $card->authorize(17.08) - ->withCurrency('USD') - ->withAddress($address) - ->withInvoiceNumber('123456') - ->withEcommerceInfo($this->ecommerceInfo) - ->withAllowDuplicates(true) - ->execute(); - - $this->assertEquals(true, $response != null); - $this->assertEquals('00', $response->responseCode); - - # test 017b Capture/AddToBatch - # do not capture - } - - /// PARTIALLY - APPROVED SALE - - public function test018PartialApprovalVisa() - { - $address = new Address(); - $address->streetAddress1 = '6860'; - $address->postalCode = '75024'; - - $card = TestCards::visaManual(); - - $response = $card->charge(130) - ->withCurrency('USD') - ->withAddress($address) - ->withInvoiceNumber('123456') - ->withAllowPartialAuth(true) - ->withEcommerceInfo($this->ecommerceInfo) - ->execute(); - - $this->assertEquals(true, $response != null); - $this->assertEquals('10', $response->responseCode); - $this->assertEquals(true, $response->authorizedAmount != null); - $this->assertEquals('110.00', $response->authorizedAmount); - } - - public function test019PartialApprovalDiscover() - { - $address = new Address(); - $address->streetAddress1 = '6860'; - $address->postalCode = '75024'; - - $card = TestCards::discoverManual(); - - $response = $card->charge(145) - ->withCurrency('USD') - ->withAddress($address) - ->withInvoiceNumber('123456') - ->withAllowPartialAuth(true) - ->withEcommerceInfo($this->ecommerceInfo) - ->execute(); - - $this->assertEquals(true, $response != null); - $this->assertEquals('10', $response->responseCode); - $this->assertEquals(true, $response->authorizedAmount != null); - $this->assertEquals('65.00', $response->authorizedAmount); - } - - public function test020PartialApprovalMastercard() - { - $address = new Address(); - $address->streetAddress1 = '6860'; - $address->postalCode = '75024'; - - $card = TestCards::discoverManual(); - - $response = $card->charge(155) - ->withCurrency('USD') - ->withAddress($address) - ->withInvoiceNumber('123456') - ->withAllowPartialAuth(true) - ->withEcommerceInfo($this->ecommerceInfo) - ->execute(); - - $this->assertEquals(true, $response != null); - $this->assertEquals('10', $response->responseCode); - $this->assertEquals(true, $response->authorizedAmount != null); - $this->assertEquals('100.00', $response->authorizedAmount); - - $voidResponse = $response->void() - ->execute(); - $this->assertEquals(true, $voidResponse != null); - $this->assertEquals('00', $voidResponse->responseCode); - } - - /// LEVEL II CORPORATE PURCHASE CARD - - public function test021LevelIIResponseB() - { - $address = new Address(); - $address->streetAddress1 = '6860 Dallas Pkwy'; - $address->postalCode = '750241234'; - - $card = TestCards::visaManual(); - - $response = $card->charge(112.34) - ->withCurrency('USD') - ->withInvoiceNumber('123456') - ->withAddress($address) - ->withCommercialRequest(true) - ->withEcommerceInfo($this->ecommerceInfo) - ->withAllowDuplicates(true) - ->execute(); - - $this->assertEquals(true, $response != null); - $this->assertEquals('00', $response->responseCode); - $this->assertEquals('B', $response->commercialIndicator); - - $cpcResponse = $response->edit() - ->withPoNumber('9876543210') - ->withTaxType(TaxType::NOT_USED) - ->execute(); - - $this->assertEquals(true, $cpcResponse != null); - $this->assertEquals('00', $cpcResponse->responseCode); - } - - public function test022LevelIIResponseB() - { - $address = new Address(); - $address->streetAddress1 = '6860'; - $address->postalCode = '750241234'; - - $card = TestCards::visaManual(); - - $response = $card->charge(112.34) - ->withCurrency('USD') - ->withInvoiceNumber('123456') - ->withAddress($address) - ->withCommercialRequest(true) - ->withEcommerceInfo($this->ecommerceInfo) - ->withAllowDuplicates(true) - ->execute(); - - $this->assertEquals(true, $response != null); - $this->assertEquals('00', $response->responseCode); - $this->assertEquals('B', $response->commercialIndicator); - - $cpcResponse = $response->edit() - ->withTaxType(TaxType::SALES_TAX) - ->withTaxAmount(1.00) - ->execute(); - - $this->assertEquals(true, $cpcResponse != null); - $this->assertEquals('00', $cpcResponse->responseCode); - } - - public function test023LevelIIResponseR() - { - $address = new Address(); - $address->streetAddress1 = '6860'; - $address->postalCode = '75024'; - - $card = TestCards::visaManual(); - - $response = $card->charge(123.45) - ->withCurrency('USD') - ->withInvoiceNumber('123456') - ->withAddress($address) - ->withCommercialRequest(true) - ->withEcommerceInfo($this->ecommerceInfo) - ->execute(); - - $this->assertEquals(true, $response != null); - $this->assertEquals('00', $response->responseCode); - $this->assertEquals('R', $response->commercialIndicator); - - $cpcResponse = $response->edit() - ->withTaxType(TaxType::TAX_EXEMPT) - ->execute(); - - $this->assertEquals(true, $cpcResponse != null); - $this->assertEquals('00', $cpcResponse->responseCode); - } - - public function test024LevelIIResponseS() - { - $address = new Address(); - $address->streetAddress1 = '6860'; - $address->postalCode = '75024'; - - $card = TestCards::visaManual(); - - $response = $card->charge(134.56) - ->withCurrency('USD') - ->withInvoiceNumber('123456') - ->withAddress($address) - ->withCommercialRequest(true) - ->withEcommerceInfo($this->ecommerceInfo) - ->execute(); - - $this->assertEquals(true, $response != null); - $this->assertEquals('00', $response->responseCode); - $this->assertEquals('S', $response->commercialIndicator); - - $cpcResponse = $response->edit() - ->withPoNumber('9876543210') - ->withTaxType(TaxType::SALES_TAX) - ->withTaxAmount(1.00) - ->execute(); - - $this->assertEquals(true, $cpcResponse != null); - $this->assertEquals('00', $cpcResponse->responseCode); - } - - public function test025LevelIIResponseS() - { - $address = new Address(); - $address->streetAddress1 = '6860'; - $address->postalCode = '75024'; - - $card = TestCards::masterCardManual(); - - $response = $card->charge(111.06) - ->withCurrency('USD') - ->withInvoiceNumber('123456') - ->withAddress($address) - ->withCommercialRequest(true) - ->withEcommerceInfo($this->ecommerceInfo) - ->execute(); - - $this->assertEquals(true, $response != null); - $this->assertEquals('00', $response->responseCode); - $this->assertEquals('S', $response->commercialIndicator); - - $cpcResponse = $response->edit() - ->withPoNumber('9876543210') - ->withTaxType(TaxType::NOT_USED) - ->execute(); - - $this->assertEquals(true, $cpcResponse != null); - $this->assertEquals('00', $cpcResponse->responseCode); - } - - public function test026LevelIIResponseS() - { - $address = new Address(); - $address->streetAddress1 = '6860'; - $address->postalCode = '75024'; - - $card = TestCards::masterCardManual(); - - $response = $card->charge(111.07) - ->withCurrency('USD') - ->withInvoiceNumber('123456') - ->withAddress($address) - ->withCommercialRequest(true) - ->withEcommerceInfo($this->ecommerceInfo) - ->execute(); - - $this->assertEquals(true, $response != null); - $this->assertEquals('00', $response->responseCode); - $this->assertEquals('S', $response->commercialIndicator); - - $cpcResponse = $response->edit() - ->withTaxType(TaxType::SALES_TAX) - ->withTaxAmount(1.00) - ->execute(); - - $this->assertEquals(true, $cpcResponse != null); - $this->assertEquals('00', $cpcResponse->responseCode); - } - - public function test027LevelIIResponseS() - { - $address = new Address(); - $address->streetAddress1 = '6860'; - $address->postalCode = '75024'; - - $card = TestCards::masterCardManual(); - - $response = $card->charge(111.08) - ->withCurrency('USD') - ->withInvoiceNumber('123456') - ->withAddress($address) - ->withCommercialRequest(true) - ->withEcommerceInfo($this->ecommerceInfo) - ->execute(); - - $this->assertEquals(true, $response != null); - $this->assertEquals('00', $response->responseCode); - $this->assertEquals('S', $response->commercialIndicator); - - $cpcResponse = $response->edit() - ->withPoNumber('9876543210') - ->withTaxType(TaxType::SALES_TAX) - ->withTaxAmount(1.00) - ->execute(); - - $this->assertEquals(true, $cpcResponse != null); - $this->assertEquals('00', $cpcResponse->responseCode); - } - - public function test028LevelIIResponseS() - { - $address = new Address(); - $address->streetAddress1 = '6860'; - $address->postalCode = '75024'; - - $card = TestCards::masterCardManual(); - - $response = $card->charge(111.09) - ->withCurrency('USD') - ->withInvoiceNumber('123456') - ->withAddress($address) - ->withCommercialRequest(true) - ->withEcommerceInfo($this->ecommerceInfo) - ->execute(); - - $this->assertEquals(true, $response != null); - $this->assertEquals('00', $response->responseCode); - $this->assertEquals('S', $response->commercialIndicator); - - $cpcResponse = $response->edit() - ->withPoNumber('9876543210') - ->withTaxType(TaxType::TAX_EXEMPT) - ->execute(); - - $this->assertEquals(true, $cpcResponse != null); - $this->assertEquals('00', $cpcResponse->responseCode); - } - - public function test029LevelIINoResponse() - { - $address = new Address(); - $address->streetAddress1 = '6860'; - $address->postalCode = '75024'; - - $card = TestCards::amexManual(); - - $response = $card->charge(111.10) - ->withCurrency('USD') - ->withInvoiceNumber('123456') - ->withAddress($address) - ->withCommercialRequest(true) - ->withEcommerceInfo($this->ecommerceInfo) - ->execute(); - - $this->assertEquals(true, $response != null); - $this->assertEquals('00', $response->responseCode); - $this->assertEquals('0', $response->commercialIndicator); - - $cpcResponse = $response->edit() - ->withPoNumber('9876543210') - ->withTaxType(TaxType::NOT_USED) - ->execute(); - - $this->assertEquals(true, $cpcResponse != null); - $this->assertEquals('00', $cpcResponse->responseCode); - } - - public function test030LevelIINoResponse() - { - $address = new Address(); - $address->streetAddress1 = '6860'; - $address->postalCode = '750241234'; - - $card = TestCards::amexManual(); - - $response = $card->charge(111.11) - ->withCurrency('USD') - ->withInvoiceNumber('123456') - ->withAddress($address) - ->withCommercialRequest(true) - ->withEcommerceInfo($this->ecommerceInfo) - ->execute(); - - $this->assertEquals(true, $response != null); - $this->assertEquals('00', $response->responseCode); - $this->assertEquals('0', $response->commercialIndicator); - - $cpcResponse = $response->edit() - ->withTaxType(TaxType::SALES_TAX) - ->withTaxAmount(1.00) - ->execute(); - - $this->assertEquals(true, $cpcResponse != null); - $this->assertEquals('00', $cpcResponse->responseCode); - } - - public function test031LevelIINoResponse() - { - $address = new Address(); - $address->streetAddress1 = '6860'; - $address->postalCode = '75024'; - - $card = TestCards::amexManual(); - - $response = $card->charge(111.12) - ->withCurrency('USD') - ->withInvoiceNumber('123456') - ->withAddress($address) - ->withCommercialRequest(true) - ->withEcommerceInfo($this->ecommerceInfo) - ->execute(); - - $this->assertEquals(true, $response != null); - $this->assertEquals('00', $response->responseCode); - $this->assertEquals('0', $response->commercialIndicator); - - $cpcResponse = $response->edit() - ->withPoNumber('9876543210') - ->withTaxType(TaxType::SALES_TAX) - ->withTaxAmount(1.00) - ->execute(); - - $this->assertEquals(true, $cpcResponse != null); - $this->assertEquals('00', $cpcResponse->responseCode); - } - - public function test032LevelIINoResponse() - { - $address = new Address(); - $address->streetAddress1 = '6860'; - $address->postalCode = '75024'; - - $card = TestCards::amexManual(); - - $response = $card->charge(111.13) - ->withCurrency('USD') - ->withInvoiceNumber('123456') - ->withAddress($address) - ->withCommercialRequest(true) - ->withEcommerceInfo($this->ecommerceInfo) - ->execute(); - - $this->assertEquals(true, $response != null); - $this->assertEquals('00', $response->responseCode); - $this->assertEquals('0', $response->commercialIndicator); - - $cpcResponse = $response->edit() - ->withPoNumber('9876543210') - ->withTaxType(TaxType::TAX_EXEMPT) - ->execute(); - - $this->assertEquals(true, $cpcResponse != null); - $this->assertEquals('00', $cpcResponse->responseCode); - } - - /// PRIOR / VOICE AUTHORIZATION - - public function test033OfflineSale() - { - $card = TestCards::visaManual(); - - $response = $card->charge(17.10) - ->withCurrency('USD') - ->withModifier(TransactionModifier::OFFLINE) - ->withOfflineAuthCode('654321') - ->withInvoiceNumber('123456') - ->withEcommerceInfo($this->ecommerceInfo) - ->execute(); - - $this->assertEquals(true, $response != null); - $this->assertEquals('00', $response->responseCode); - } - - public function test033OfflineAuthorization() - { - $card = TestCards::visaManual(); - - $response = $card->authorize(17.10) - ->withCurrency('USD') - ->withModifier(TransactionModifier::OFFLINE) - ->withOfflineAuthCode('654321') - ->withInvoiceNumber('123456') - ->withEcommerceInfo($this->ecommerceInfo) - ->execute(); - - $this->assertEquals(true, $response != null); - $this->assertEquals('00', $response->responseCode); - } - - /// RETURN - - public function test034OfflineCreditReturn() - { - $card = TestCards::masterCardManual(); - - $response = $card->refund(15.15) - ->withCurrency('USD') - ->withInvoiceNumber('123456') - ->withEcommerceInfo($this->ecommerceInfo) - ->execute(); - - $this->assertEquals(true, $response != null); - $this->assertEquals('00', $response->responseCode); - } - - public function test034bOfflineCreditReturn() - { - $card = TestCards::masterCardManual(); - - $response = $card->refund(15.16) - ->withCurrency('USD') - ->withInvoiceNumber('123456') - ->withEcommerceInfo($this->ecommerceInfo) - ->execute(); - - $this->assertEquals(true, $response != null); - $this->assertEquals('00', $response->responseCode); - } - - /// ONLINE VOID / REVERSAL - - public function test035VoidTest10() - { - // see test 010 - } - - public function test036VoidTest20() - { - // see test 020 - } - - /// Time Out Reversal - public function test036bTimeoutReversal() - { - $sale = TestCards::visaManual()->charge(911) - ->withCurrency('USD') - ->withInvoiceNumber('123456') - ->withClientTransactionId('987321654') - ->withEcommerceInfo($this->ecommerceInfo) - ->execute(); - - $this->assertEquals(true, $sale != null); - $this->assertEquals('91', $sale->responseCode); - - $response = Transaction::fromId(null, PaymentMethodType::CREDIT); - $response->clientTransactionId = '987321654'; - - $this->expectException(GatewayException::class); - $response->reverse(911)->execute(); - } - - /// One time bill payment - - public function test010ChargeVisaOneTime() - { - $address = new Address(); - $address->streetAddress1 = '6860 Dallas Pkwy'; - $address->postalCode = '75024'; - - $card = null; - if ($this->useTokens) { - $card = new CreditCardData(); - $card->token = static::$visaToken; - } else { - $card = TestCards::visaManual(); - } - - $response = $card->charge(13.11) - ->withCurrency('USD') - ->withAddress($address) - ->withInvoiceNumber('123456') - ->withOneTimePayment(true) - ->withAllowDuplicates(true) - ->execute(); - - $this->assertEquals(true, $response != null); - $this->assertEquals('00', $response->responseCode); - - $void = $response->void()->execute(); - - $this->assertEquals(true, $void != null); - $this->assertEquals('00', $void->responseCode); - } - - public function test011ChargeMasterCardOneTime() - { - $address = new Address(); - $address->streetAddress1 = '6860'; - $address->postalCode = '750241234'; - - $card = null; - if ($this->useTokens) { - $card = new CreditCardData(); - $card->token = static::$mastercardToken; - } else { - $card = TestCards::masterCardManual(); - } - - $response = $card->charge(13.12) - ->withCurrency('USD') - ->withAddress($address) - ->withInvoiceNumber('123456') - ->withOneTimePayment(true) - ->withAllowDuplicates(true) - ->execute(); - - $this->assertEquals(true, $response != null); - $this->assertEquals('00', $response->responseCode); - } - - public function test012ChargeDiscoverOneTime() - { - $address = new Address(); - $address->streetAddress1 = '6860'; - $address->postalCode = '75024'; - - $card = null; - if ($this->useTokens) { - $card = new CreditCardData(); - $card->token = static::$discoverToken; - } else { - $card = TestCards::discoverManual(); - } - - $response = $card->charge(13.13) - ->withCurrency('USD') - ->withAddress($address) - ->withInvoiceNumber('123456') - ->withOneTimePayment(true) - ->withAllowDuplicates(true) - ->execute(); - - $this->assertEquals(true, $response != null); - $this->assertEquals('00', $response->responseCode); - } - - public function test013ChargeAmexOneTime() - { - $address = new Address(); - $address->streetAddress1 = '6860'; - $address->postalCode = '75024'; - - $card = null; - if ($this->useTokens) { - $card = new CreditCardData(); - $card->token = static::$amexToken; - } else { - $card = TestCards::amexManual(); - } - - $response = $card->charge(13.14) - ->withCurrency('USD') - ->withAddress($address) - ->withInvoiceNumber('123456') - ->withOneTimePayment(true) - ->withAllowDuplicates(true) - ->execute(); - - $this->assertEquals(true, $response != null); - $this->assertEquals('00', $response->responseCode); - } - - public function test014ChargeJcbOneTime() - { - $address = new Address(); - $address->streetAddress1 = '6860'; - $address->postalCode = '75024'; - - $card = new CreditCardData(); - $card->number = '3566007770007321'; - $card->expMonth = '12'; - $card->expYear = TestCards::validCardExpYear(); - $card->cvn = '123'; - - $response = $card->charge(13.15) - ->withCurrency('USD') - ->withAddress($address) - ->withInvoiceNumber('123456') - ->withOneTimePayment(true) - ->withAllowDuplicates(true) - ->execute(); - - $this->assertEquals(true, $response != null); - $this->assertEquals('00', $response->responseCode); - } - - /// ADVANCED FRAUD SCREENING - - /** - * TODO: Change code assertions when AFS is enabled on account - */ - public function test037FraudPreventionSale() - { - $card = TestCards::visaManual(); - - $response = $card->charge(15000) - ->withCurrency('USD') - ->execute(); - $this->assertEquals(true, $response != null); - $this->assertEquals('00', $response->responseCode); - // $this->assertEquals('FR', $response->responseCode); - } - - /** - * TODO: Change code assertions when AFS is enabled on account - */ - public function test038FraudPreventionReturn() - { - $card = TestCards::visaManual(); - - $response = $card->refund(15000) - ->withCurrency('USD') - ->execute(); - $this->assertEquals(true, $response != null); - $this->assertEquals('00', $response->responseCode); - // $this->assertEquals('41', $response->responseCode); - } - - /// ONE CARD - GSB CARD FUNCTIONS - - /// BALANCE INQUIRY - - public function test037BalanceInquiryGsb() - { - if (false === $this->usePrepaid) { - $this->markTestSkipped('GSB not configured'); - } - - $address = new Address(); - $address->streetAddress1 = '6860'; - $address->postalCode = '75024'; - - $card = TestCards::gsbManual(); - - $response = $card->balanceInquiry() - ->withAddress($address) - ->execute(); - - $this->assertEquals(true, $response != null); - $this->assertEquals('00', $response->responseCode); - } - - /// ADD VALUE - - public function test038AddValueGsb() - { - if (false === $this->usePrepaid) { - $this->markTestSkipped('GSB not configured'); - } - - $card = new CreditTrackData(); - $card->value = '%B6277220572999800^ / ^49121010557010000016000000?F;6277220572999800=49121010557010000016?'; - - $response = $card->addValue(15.00) - ->withCurrency('USD') - ->execute(); - - $this->assertEquals(true, $response != null); - $this->assertEquals('00', $response->responseCode); - } - - /// SALE - - public function test039ChargeGsb() - { - if (false === $this->usePrepaid) { - $this->markTestSkipped('GSB not configured'); - } - - $address = new Address(); - $address->streetAddress1 = '6860'; - $address->postalCode = '75024'; - - $card = TestCards::gsbManual(); - - $response = $card->charge(2.05) - ->withCurrency('USD') - ->withAddress($address) - ->withInvoiceNumber('123456') - ->execute(); - - $this->assertEquals(true, $response != null); - $this->assertEquals('00', $response->responseCode); - - $voidResponse = $response->void() - ->execute(); - $this->assertEquals(true, $voidResponse != null); - $this->assertEquals('00', $voidResponse->responseCode); - } - - public function test040ChargeGsb() - { - if (false === $this->usePrepaid) { - $this->markTestSkipped('GSB not configured'); - } - - $address = new Address(); - $address->streetAddress1 = '6860'; - $address->postalCode = '75024'; - - $card = TestCards::gsbManual(); - - $response = $card->charge(2.10) - ->withCurrency('USD') - ->withAddress($address) - ->withInvoiceNumber('123456') - ->execute(); - - $this->assertEquals(true, $response != null); - $this->assertEquals('00', $response->responseCode); - } - - /// ONLINE VOID / REVERSAL - - public function test041VoidGsb() - { - // see test 039 - } - - /// HMS GIFT - REWARDS - - /// ACTIVATE - - public function test042ActivateGift1() - { - $card = TestCards::giftCard1Swipe(); - - $response = $card->activate(6.00) - ->withCurrency('USD') - ->execute(); - $this->assertEquals(true, $response != null); - $this->assertEquals('00', $response->responseCode); - } - - public function test043ActivateGift2() - { - - $card = TestCards::giftCard2Manual(); - - $response = $card->activate(7.00) - ->withCurrency('USD') - ->execute(); - $this->assertEquals(true, $response != null); - $this->assertEquals('00', $response->responseCode); - } - - /// LOAD / ADD VALUE - - public function test044AddValueGift1() - { - $card = TestCards::giftCard1Swipe(); - - $response = $card->addValue(8.00) - ->withCurrency('USD') - ->execute(); - $this->assertEquals(true, $response != null); - $this->assertEquals('00', $response->responseCode); - } - - public function test045AddValueGift2() - { - $card = TestCards::giftCard2Manual(); - - $response = $card->addValue(9.00) - ->withCurrency('USD') - ->execute(); - $this->assertEquals(true, $response != null); - $this->assertEquals('00', $response->responseCode); - } - - /// BALANCE INQUIRY - - public function test046BalanceInquiryGift1() - { - $card = TestCards::giftCard1Swipe(); - - $response = $card->balanceInquiry() - ->execute(); - $this->assertEquals(true, $response != null); - $this->assertEquals('00', $response->responseCode); - $this->assertEquals('10.00', $response->balanceAmount); - } - - public function test047BalanceInquiryGift2() - { - $card = TestCards::giftCard2Manual(); - - $response = $card->balanceInquiry() - ->execute(); - $this->assertEquals(true, $response != null); - $this->assertEquals('00', $response->responseCode); - $this->assertEquals('10.00', $response->balanceAmount); - } - - /// REPLACE / TRANSFER - - public function test048ReplaceGift1() - { - $card = TestCards::giftCard1Swipe(); - - $response = $card->replaceWith(TestCards::giftCard2Manual()) - ->execute(); - - $this->assertEquals(true, $response != null); - $this->assertEquals('00', $response->responseCode); - $this->assertEquals('10.00', $response->balanceAmount); - } - - public function test049ReplaceGift2() - { - $card = TestCards::giftCard2Manual(); - - $response = $card->replaceWith(TestCards::giftCard1Swipe()) - ->execute(); - - $this->assertEquals(true, $response != null); - $this->assertEquals('00', $response->responseCode); - $this->assertEquals('10.00', $response->balanceAmount); - } - - /// SALE / REDEEM - - public function test050SaleGift1() - { - $card = TestCards::giftCard1Swipe(); - - $response = $card->charge(1.00) - ->withCurrency('USD') - ->execute(); - $this->assertEquals(true, $response != null); - $this->assertEquals('00', $response->responseCode); - } - - public function test051SaleGift2() - { - $card = TestCards::giftCard2Manual(); - - $response = $card->charge(2.00) - ->withCurrency('USD') - ->execute(); - $this->assertEquals(true, $response != null); - $this->assertEquals('00', $response->responseCode); - } - - public function test052SaleGift1Void() - { - $card = TestCards::giftCard1Swipe(); - - $response = $card->charge(3.00) - ->withCurrency('USD') - ->execute(); - $this->assertEquals(true, $response != null); - $this->assertEquals('00', $response->responseCode); - - $voidResponse = $response->void() - ->execute(); - $this->assertEquals(true, $voidResponse != null); - $this->assertEquals('00', $voidResponse->responseCode); - } - - public function test053SaleGift2Reversal() - { - $card = TestCards::giftCard2Manual(); - - $response = $card->charge(4.00) - ->withCurrency('USD') - ->execute(); - $this->assertEquals(true, $response != null); - $this->assertEquals('00', $response->responseCode); - - $reversalResponse = $response->reverse(4.00) - ->execute(); - $this->assertEquals(true, $reversalResponse != null); - $this->assertEquals('00', $reversalResponse->responseCode); - } - - /// VOID - - public function test054VoidGift() - { - // see test 052 - } - - /// REVERSAL - - public function test055ReversalGift() - { - // see test 053 - } - - public function test056ReversalGift2() - { - $card = TestCards::giftCard2Manual(); - - $reversalResponse = $card->reverse(2.00) - ->execute(); - $this->assertEquals(true, $reversalResponse != null); - $this->assertEquals('00', $reversalResponse->responseCode); - } - - /// DEACTIVATE - - public function test057DeactivateGift1() - { - $card = TestCards::giftCard1Swipe(); - - $response = $card->deactivate() - ->execute(); - $this->assertEquals(true, $response != null); - $this->assertEquals('00', $response->responseCode); - } - - /// RECEIPTS MESSAGING - - public function test058ReceiptsMessaging() - { - return; # print and scan receipt for test 51 - } - - /// REWARD - - /// BALANCE INQUIRY - - public function test059BalanceInquiryRewards1() - { - $card = TestCards::giftCard1Swipe(); - - $response = $card->balanceInquiry() - ->execute(); - $this->assertEquals(true, $response != null); - $this->assertEquals('00', $response->responseCode); - $this->assertTrue($response->pointsBalanceAmount > 0); - } - - public function test060BalanceInquiryRewards2() - { - $card = TestCards::giftCard2Manual(); - - $response = $card->balanceInquiry() - ->execute(); - $this->assertEquals(true, $response != null); - $this->assertEquals('00', $response->responseCode); - $this->assertTrue($response->pointsBalanceAmount > 0); - } - - /// ALIAS - - public function test061CreateAliasGift1() - { - $response = GiftCard::create('9725550100'); - - $this->assertEquals(true, $response != null); - } - - public function test062CreateAliasGift2() - { - $response = GiftCard::create('9725550100'); - - $this->assertEquals(true, $response != null); - } - - public function test063AddAliasGift1() - { - $card = TestCards::giftCard1Swipe(); - - $response = $card->addAlias('2145550199') - ->execute(); - $this->assertEquals(true, $response != null); - $this->assertEquals('00', $response->responseCode); - } - - public function test064AddAliasGift2() - { - $card = TestCards::giftCard2Manual(); - - $response = $card->addAlias('2145550199') - ->execute(); - $this->assertEquals(true, $response != null); - $this->assertEquals('00', $response->responseCode); - } - - public function test065DeleteAliasGift1() - { - $card = TestCards::giftCard1Swipe(); - - $response = $card->removeAlias('2145550199') - ->execute(); - $this->assertEquals(true, $response != null); - $this->assertEquals('00', $response->responseCode); - } - - /// SALE / REDEEM - - public function test066RedeemPointsGift1() - { - $card = TestCards::giftCard1Swipe(); - - $response = $card->charge(100) - ->withCurrency('POINTS') - ->execute(); - $this->assertEquals(true, $response != null); - $this->assertEquals('00', $response->responseCode); - } - - public function test067RedeemPointsGift2() - { - $card = TestCards::giftCard2Manual(); - - $response = $card->charge(200) - ->withCurrency('POINTS') - ->execute(); - $this->assertEquals(true, $response != null); - $this->assertEquals('00', $response->responseCode); - } - - public function test068RedeemPointsGift2() - { - $card = new GiftCard(); - $card->alias = '9725550100'; - - $response = $card->charge(300) - ->withCurrency('POINTS') - ->execute(); - $this->assertEquals(true, $response != null); - $this->assertEquals('00', $response->responseCode); - } - - /// REWARDS - - public function test069RewardsGift1() - { - $card = TestCards::giftCard1Swipe(); - - $response = $card->rewards(10) - ->execute(); - $this->assertEquals(true, $response != null); - $this->assertEquals('00', $response->responseCode); - } - - public function test070RewardsGift2() - { - $card = TestCards::giftCard2Manual(); - - $response = $card->rewards(11) - ->execute(); - $this->assertEquals(true, $response != null); - $this->assertEquals('00', $response->responseCode); - } - - /// REPLACE / TRANSFER - - public function test071ReplaceGift1() - { - $card = TestCards::giftCard1Swipe(); - - $response = $card->replaceWith(TestCards::giftCard2Manual()) - ->execute(); - $this->assertEquals(true, $response != null); - $this->assertEquals('00', $response->responseCode); - } - - public function test072ReplaceGift2() - { - $card = TestCards::giftCard2Manual(); - - $response = $card->replaceWith(TestCards::giftCard1Swipe()) - ->execute(); - $this->assertEquals(true, $response != null); - $this->assertEquals('00', $response->responseCode); - } - - /// DEACTIVATE - - public function test073DeactivateGift1() - { - $card = TestCards::giftCard1Swipe(); - - $response = $card->deactivate() - ->execute(); - $this->assertEquals(true, $response != null); - $this->assertEquals('00', $response->responseCode); - } - - public function test074DeactivateGift2() - { - $card = TestCards::giftCard2Manual(); - - $response = $card->deactivate() - ->execute(); - $this->assertEquals(true, $response != null); - $this->assertEquals('00', $response->responseCode); - } - - /// RECEIPTS MESSAGING - - public function test075ReceiptsMessaging() - { - return; # print and scan receipt for test 51 - } - - /// CLOSE BATCH - - public function test999CloseBatch() - { - try { - $response = BatchService::closeBatch(); - $this->assertNotNull($response); - // printf('batch id: %s', $response->id); - // printf('sequence number: %s', $response->sequenceNumber); - } catch (ApiException $e) { - if (false === strpos($e->getMessage(), static::BATCH_NOT_OPEN) - && false === strpos($e->getMessage(), static::NO_TRANS_IN_BATCH) - ) { - $this->fail($e->getMessage()); - } - } - } - - public function test100ChargeVisaEcommerceInfo() - { - $address = new Address(); - $address->streetAddress1 = '6860 Dallas Pkwy'; - $address->postalCode = '75024'; - - $secureEcom = new ThreeDSecure(); - $secureEcom->cavv = 'AAACBllleHchZTBWIGV4AAAAAAA='; - $secureEcom->xid = 'crqAeMwkEL9r4POdxpByWJ1/wYg='; - $secureEcom->eci = '5'; - $secureEcom->paymentDataSource = Secure3dPaymentDataSource::VISA_3DSECURE; - $secureEcom->paymentDataType = '3DSecure'; - - $card = TestCards::visaManual(); - $card->threeDSecure = $secureEcom; - - $response = $card->charge() - ->withCurrency('USD') - ->withAmount(13.01) - ->withAddress($address) - // ->withEcommerceInfo($this->ecommerceInfo) - ->withInvoiceNumber('12345') - ->withAllowDuplicates(true) - ->execute(); - - $this->assertEquals(true, $response != null); - $this->assertEquals('00', $response->responseCode); - } -} +value = $card->value; + $data->encryptionData = $card->encryptionData; + $data->pinBlock = $pinBlock; + return $data; + } + + public static function asEBTTrack($card, $pinBlock) + { + $data = new EBTTrackData(); + $data->value = $card->value; + $data->entryMethod = $card->entryMethod; + $data->encryptionData = $card->encryptionData; + $data->pinBlock = $pinBlock; + return $data; + } + + public static function asEBTManual($card, $pinBlock) + { + $data = new EBTCardData(); + $data->number = $card->number; + $data->expMonth = $card->expMonth; + $data->expYear = $card->expYear; + $data->pinBlock = $pinBlock; + return $data; + } + + public static function visaManual($cardPresent = false, $readerPresent = false) + { + $data = new CreditCardData(); + $data->number = '4012002000060016'; + $data->expMonth = 12; + $data->expYear = self::validCardExpYear(); + $data->cvn = '123'; + $data->cardPresent = $cardPresent; + $data->readerPresent = $readerPresent; + return $data; + } + + public static function visaSwipe($entryMethod = null) + { + if ($entryMethod === null) { + $entryMethod = EntryMethod::SWIPE; + } + + $data = new CreditTrackData(); + $data->value = '%B4012002000060016^VI TEST CREDIT^251210118039000000000396?;4012002000060016=25121011803939600000?'; + $data->entryMethod = $entryMethod; + return $data; + } + + public static function visaSwipeEncrypted($entryMethod = null) + { + if ($entryMethod === null) { + $entryMethod = EntryMethod::SWIPE; + } + + $encryptionData = new EncryptionData(); + $encryptionData->version = '01'; + + $data = new CreditTrackData(); + $data->value = ';'; + $data->entryMethod = $entryMethod; + $data->encryptionData = $encryptionData; + return $data; + } + + public static function masterCardManual($cardPresent = false, $readerPresent = false) + { + $data = new CreditCardData(); + $data->number = '5473500000000014'; + $data->expMonth = 12; + $data->expYear = self::validCardExpYear(); + $data->cvn = '123'; + $data->cardPresent = $cardPresent; + $data->readerPresent = $readerPresent; + return $data; + } + + public static function masterCardSeries2Manual($cardPresent = false, $readerPresent = false) + { + $data = new CreditCardData(); + $data->number = '2223000010005780'; + $data->expMonth = 12; + $data->expYear = self::validCardExpYear(); + $data->cvn = '123'; + $data->cardPresent = $cardPresent; + $data->readerPresent = $readerPresent; + return $data; + } + + public static function masterCardSwipe($entryMethod = null) + { + if ($entryMethod === null) { + $entryMethod = EntryMethod::SWIPE; + } + + $data = new CreditTrackData(); + $data->value = '%B5473500000000014^MC TEST CARD^251210199998888777766665555444433332?;5473500000000014=25121019999888877776?'; + $data->entryMethod = $entryMethod; + return $data; + } + + public static function masterCard24Swipe($entryMethod = null) + { + if ($entryMethod === null) { + $entryMethod = EntryMethod::SWIPE; + } + + $data = new CreditTrackData(); + $data->value = '%B2223000010005780^TEST CARD/EMV BIN-2^19121010000000009210?;2223000010005780=19121010000000009210?'; + $data->entryMethod = $entryMethod; + return $data; + } + + public static function masterCard25Swipe($entryMethod = null) + { + if ($entryMethod === null) { + $entryMethod = EntryMethod::SWIPE; + } + + $data = new CreditTrackData(); + $data->value = '%B2223000010005798^TEST CARD/EMV BIN-2^19121010000000003840?;2223000010005798=19121010000000003840?'; + $data->entryMethod = $entryMethod; + return $data; + } + + public static function masterCardSwipeEncrypted($entryMethod = null) + { + if ($entryMethod === null) { + $entryMethod = EntryMethod::SWIPE; + } + + $encryptionData = new EncryptionData(); + $encryptionData->version = '01'; + + $data = new CreditTrackData(); + $data->value = ''; + $data->entryMethod = $entryMethod; + $data->encryptionData = $encryptionData; + return $data; + } + + public static function discoverManual($cardPresent = false, $readerPresent = false) + { + $data = new CreditCardData(); + $data->number = '6011000990156527'; + $data->expMonth = 12; + $data->expYear = self::validCardExpYear(); + $data->cvn = '123'; + $data->cardPresent = $cardPresent; + $data->readerPresent = $readerPresent; + return $data; + } + + public static function discoverSwipe($entryMethod = null) + { + if ($entryMethod === null) { + $entryMethod = EntryMethod::SWIPE; + } + + $data = new CreditTrackData(); + $data->value = '%B6011000990156527^DIS TEST CARD^25121011000062111401?;6011000990156527=25121011000062111401?'; + $data->entryMethod = $entryMethod; + return $data; + } + + public static function discoverSwipeEncrypted($entryMethod = null) + { + if ($entryMethod === null) { + $entryMethod = EntryMethod::SWIPE; + } + + $encryptionData = new EncryptionData(); + $encryptionData->version = '01'; + + $data = new CreditTrackData(); + $data->value = ''; + $data->entryMethod = $entryMethod; + $data->encryptionData = $encryptionData; + return $data; + } + + public static function amexManual($cardPresent = false, $readerPresent = false) + { + $data = new CreditCardData(); + $data->number = '372700699251018'; + $data->expMonth = 12; + $data->expYear = self::validCardExpYear(); + $data->cvn = '1234'; + $data->cardPresent = $cardPresent; + $data->readerPresent = $readerPresent; + return $data; + } + + public static function amexSwipe($entryMethod = null) + { + if ($entryMethod === null) { + $entryMethod = EntryMethod::SWIPE; + } + + $data = new CreditTrackData(); + $data->value = '%B3727 006992 51018^AMEX TEST CARD^2512990502700?;372700699251018=2512990502700?'; + $data->entryMethod = $entryMethod; + return $data; + } + + public static function jcbManual($cardPresent = false, $readerPresent = false) + { + $data = new CreditCardData(); + $data->number = '3566007770007321'; + $data->expMonth = 12; + $data->expYear = self::validCardExpYear(); + $data->cvn = '123'; + $data->cardPresent = $cardPresent; + $data->readerPresent = $readerPresent; + return $data; + } + + public static function jcbSwipe($entryMethod = null) + { + if ($entryMethod === null) { + $entryMethod = EntryMethod::SWIPE; + } + + $data = new CreditTrackData(); + $data->value = '%B3566007770007321^JCB TEST CARD^2512101100000000000000000064300000?;3566007770007321=25121011000000076435?'; + $data->entryMethod = $entryMethod; + return $data; + } + + public static function giftCard1Swipe() + { + $data = new GiftCard(); + $data->trackData = '%B5022440000000000098^^391200081613?;5022440000000000098=391200081613?'; + return $data; + } + + public static function giftCard2Manual() + { + $data = new GiftCard(); + $data->number = '5022440000000000007'; + return $data; + } + + public static function gsbManual() + { + $data = new CreditCardData(); + $data->number = '6277220572999800'; + $data->expMonth = '12'; + $data->expYear = self::validCardExpYear(); + return $data; + } +} + + + +class EcommerceTest extends TestCase +{ + const NO_TRANS_IN_BATCH = 'Batch close was rejected because no transactions are associated with the currently open batch.'; + const BATCH_NOT_OPEN = 'Transaction was rejected because it requires a batch to be open.'; + + /** @var bool */ + private $useTokens = true; + + /** @var bool */ + private $usePrepaid = false; + + /** @var string */ + private $publicKey = ''; + + /** @var EcommerceInfo */ + private $ecommerceInfo = null; + + /** @var string|null */ + public static $visaToken = null; + + /** @var string|null */ + public static $mastercardToken = null; + + /** @var string|null */ + public static $discoverToken = null; + + /** @var string|null */ + public static $amexToken = null; + + private $enableCryptoUrl = true; + + private function config() + { + $config = new PorticoConfig(); + $config->secretApiKey = 'skapi_cert_MTyMAQBiHVEAewvIzXVFcmUd2UcyBge_eCpaASUp0A'; + $config->serviceUrl = ($this->enableCryptoUrl) ? + 'https://cert.api2-c.heartlandportico.com/': + 'https://cert.api2.heartlandportico.com'; + return $config; + } + + protected function setup() : void + { + ServicesContainer::configureService($this->config()); + $this->publicKey = 'pkapi_cert_jKc1FtuyAydZhZfbB3'; + + $this->ecommerceInfo = new EcommerceInfo(); + $this->ecommerceInfo->channel = EcommerceChannel::ECOM; + } + + public function test000CloseBatch() + { + try { + $response = BatchService::closeBatch(); + $this->assertNotNull($response); + } catch (ApiException $e) { + if (false === strpos($e->getMessage(), static::BATCH_NOT_OPEN) + && false === strpos($e->getMessage(), static::NO_TRANS_IN_BATCH) + ) { + $this->fail($e->getMessage()); + } + } + } + + /// CARD VERIFY + + /// Account Verification + + public function test001VerifyVisa() + { + $card = TestCards::visaManual(); + + $response = $card->verify() + ->withRequestMultiUseToken($this->useTokens) + ->execute(); + + $this->assertEquals(true, $response != null); + $this->assertEquals('00', $response->responseCode); + } + + public function test002VerifyMasterCard() + { + $card = TestCards::masterCardManual(); + $response = $card->verify() + ->withRequestMultiUseToken($this->useTokens) + ->execute(); + + $this->assertEquals(true, $response != null); + $this->assertEquals('00', $response->responseCode); + } + + public function test003VerifyDiscover() + { + $address = new Address(); + $address->postalCode = '75024'; + + $card = TestCards::discoverManual(); + + $response = $card->verify() + ->withAddress($address) + ->withRequestMultiUseToken($this->useTokens) + ->execute(); + + $this->assertEquals(true, $response != null); + $this->assertEquals('00', $response->responseCode); + } + + /// Address Verification + + public function test004VerifyAmex() + { + $address = new Address(); + $address->postalCode = '75024'; + + $card = TestCards::amexManual(); + + $response = $card->verify() + ->withAddress($address) + ->withRequestMultiUseToken($this->useTokens) + ->execute(); + + $this->assertEquals(true, $response != null); + $this->assertEquals('00', $response->responseCode); + } + + /// Balance Inquiry (for Prepaid Card) + + public function test005BalanceInquiryVisa() + { + if (false === $this->usePrepaid) { + $this->markTestSkipped('GSB not configured'); + } + + $card = TestCards::visaManual(); + + $response = $card->balanceInquiry() + ->execute(); + + $this->assertEquals(true, $response != null); + $this->assertEquals('00', $response->responseCode); + } + + /// CREDIT SALE (For Multi-Use Token Only) + + public function test006ChargeVisaToken() + { + $address = new Address(); + $address->streetAddress1 = '6860 Dallas Pkwy'; + $address->postalCode = '75024'; + + $card = TestCards::visaManual(); + + $response = $card->charge() + ->withCurrency('USD') + ->withAmount(13.01) + ->withInvoiceNumber('123456') + ->withAddress($address) + ->withRequestMultiUseToken(true) + ->withEcommerceInfo($this->ecommerceInfo) + ->withAllowDuplicates(true) + ->execute(); + + $this->assertEquals(true, $response != null); + $this->assertEquals('00', $response->responseCode); + $this->assertEquals(true, $response->token != null); + self::$visaToken = $response->token; + } + + public function test007ChargeMasterCardToken() + { + $address = new Address(); + $address->streetAddress1 = '6860'; + $address->postalCode = '75024'; + + $card = TestCards::masterCardManual(); + + $response = $card->charge() + ->withCurrency('USD') + ->withAmount(13.02) + ->withInvoiceNumber('123456') + ->withAddress($address) + ->withRequestMultiUseToken(true) + ->withEcommerceInfo($this->ecommerceInfo) + ->withAllowDuplicates(true) + ->execute(); + + $this->assertEquals(true, $response != null); + $this->assertEquals('00', $response->responseCode); + $this->assertEquals(true, $response->token != null); + self::$mastercardToken = $response->token; + } + + public function test008ChargeDiscoverToken() + { + $address = new Address(); + $address->streetAddress1 = '6860'; + $address->postalCode = '750241234'; + + $card = TestCards::discoverManual(); + + $response = $card->charge() + ->withCurrency('USD') + ->withAmount(13.03) + ->withInvoiceNumber('123456') + ->withAddress($address) + ->withRequestMultiUseToken(true) + ->withEcommerceInfo($this->ecommerceInfo) + ->withAllowDuplicates(true) + ->execute(); + + $this->assertEquals(true, $response != null); + $this->assertEquals('00', $response->responseCode); + $this->assertEquals(true, $response->token != null); + self::$discoverToken = $response->token; + } + + public function test009ChargeAmexToken() + { + $address = new Address(); + $address->streetAddress1 = '6860 Dallas Pkwy'; + $address->postalCode = '75024'; + + $card = TestCards::visaManual(); + + $response = $card->charge() + ->withCurrency('USD') + ->withAmount(13.04) + ->withAddress($address) + ->withInvoiceNumber('123456') + ->withRequestMultiUseToken(true) + ->withEcommerceInfo($this->ecommerceInfo) + ->withAllowDuplicates(true) + ->execute(); + + $this->assertEquals(true, $response != null); + $this->assertEquals('00', $response->responseCode); + $this->assertEquals(true, $response->token != null); + self::$amexToken = $response->token; + } + + /// CREDIT SALE + + public function test010ChargeVisa() + { + $address = new Address(); + $address->streetAddress1 = '6860 Dallas Pkwy'; + $address->postalCode = '75024'; + + $card = TestCards::visaManual(); + if ($this->useTokens) { + $card = new CreditCardData(); + $card->token = self::$visaToken; + } + + $response = $card->charge() + ->withCurrency('USD') + ->withAmount(17.01) + ->withAddress($address) + ->withInvoiceNumber('123456') + ->withEcommerceInfo($this->ecommerceInfo) + ->withAllowDuplicates(true) + ->execute(); + + $this->assertEquals(true, $response != null); + $this->assertEquals('00', $response->responseCode); + + $voidResponse = $response->void() + ->execute(); + $this->assertEquals(true, $voidResponse != null); + $this->assertEquals('00', $voidResponse->responseCode); + } + + public function test011ChargeMastercard() + { + $address = new Address(); + $address->streetAddress1 = '6860'; + $address->postalCode = '75024'; + + $card = TestCards::masterCardManual(); + if ($this->useTokens) { + $card = new CreditCardData(); + $card->token = self::$mastercardToken; + } + + $response = $card->charge() + ->withCurrency('USD') + ->withAmount(17.02) + ->withAddress($address) + ->withInvoiceNumber('123456') + ->withEcommerceInfo($this->ecommerceInfo) + ->withAllowDuplicates(true) + ->execute(); + + $this->assertEquals(true, $response != null); + $this->assertEquals('00', $response->responseCode); + } + + public function test012ChargeDiscover() + { + $address = new Address(); + $address->streetAddress1 = '6860'; + $address->postalCode = '750241234'; + + $card = TestCards::discoverManual(); + if ($this->useTokens) { + $card = new CreditCardData(); + $card->token = self::$discoverToken; + } + + $response = $card->charge() + ->withCurrency('USD') + ->withAmount(17.03) + ->withAddress($address) + ->withInvoiceNumber('123456') + ->withEcommerceInfo($this->ecommerceInfo) + ->withAllowDuplicates(true) + ->execute(); + + $this->assertEquals(true, $response != null); + $this->assertEquals('00', $response->responseCode); + } + + public function test013ChargeAmex() + { + $address = new Address(); + $address->streetAddress1 = '6860 Dallas Pkwy'; + $address->postalCode = '75024'; + + $card = TestCards::amexManual(); + if ($this->useTokens) { + $card = new CreditCardData(); + $card->token = self::$amexToken; + } + + $response = $card->charge() + ->withCurrency('USD') + ->withAmount(17.04) + ->withAddress($address) + ->withInvoiceNumber('123456') + ->withEcommerceInfo($this->ecommerceInfo) + ->withAllowDuplicates(true) + ->execute(); + + $this->assertEquals(true, $response != null); + $this->assertEquals('00', $response->responseCode); + } + + public function test014ChargeJcb() + { + $address = new Address(); + $address->streetAddress1 = '6860 Dallas Pkwy'; + $address->postalCode = '75024'; + + $card = TestCards::jcbManual(); + + $response = $card->charge() + ->withCurrency('USD') + ->withAmount(17.04) + ->withAddress($address) + ->withInvoiceNumber('123456') + ->withEcommerceInfo($this->ecommerceInfo) + ->withAllowDuplicates(true) + ->execute(); + + $this->assertEquals(true, $response != null); + $this->assertEquals('00', $response->responseCode); + } + + public function test011bChargeMasterCard() + { + $address = new Address(); + $address->streetAddress1 = '6860'; + $address->postalCode = '75024'; + + $card = TestCards::masterCardSeries2Manual(); + + $response = $card->charge() + ->withCurrency('USD') + ->withAmount(17.02) + ->withAddress($address) + ->withInvoiceNumber('123456') + ->withEcommerceInfo($this->ecommerceInfo) + ->withAllowDuplicates(true) + ->execute(); + + $this->assertEquals(true, $response != null); + $this->assertEquals('00', $response->responseCode); + } + + /// AUTHORIZATION + + public function test015AuthorizationVisa() + { + # Test 015a Authorization + $address = new Address(); + $address->streetAddress1 = '6860 Dallas Pkwy'; + $address->postalCode = '75024'; + + + $card = TestCards::visaManual(); + + $response = $card->authorize(17.06) + ->withCurrency('USD') + ->withAddress($address) + ->withInvoiceNumber('123456') + ->withEcommerceInfo($this->ecommerceInfo) + ->withAllowDuplicates(true) + ->execute(); + + $this->assertEquals(true, $response != null); + $this->assertEquals('00', $response->responseCode); + + # test 015b Capture/AddToBatch + $capture = $response->capture() + ->execute(); + $this->assertEquals(true, $capture != null); + $this->assertEquals('00', $capture->responseCode); + } + + public function test016AuthorizationMastercard() + { + # Test 016a Authorization + $address = new Address(); + $address->streetAddress1 = '6860 Dallas Pkwy'; + $address->postalCode = '750241234'; + + $card = TestCards::masterCardManual(); + + $response = $card->authorize(17.07) + ->withCurrency('USD') + ->withAddress($address) + ->withInvoiceNumber('123456') + ->withEcommerceInfo($this->ecommerceInfo) + ->withAllowDuplicates(true) + ->execute(); + + $this->assertEquals(true, $response != null); + $this->assertEquals('00', $response->responseCode); + + # test 016b Capture/AddToBatch + $capture = $response->capture() + ->execute(); + $this->assertEquals(true, $capture != null); + $this->assertEquals('00', $capture->responseCode); + } + + public function test017AuthorizationDiscover() + { + # Test 017a Authorization + $address = new Address(); + $address->streetAddress1 = '6860'; + $address->postalCode = '75024'; + + $card = TestCards::discoverManual(); + + $response = $card->authorize(17.08) + ->withCurrency('USD') + ->withAddress($address) + ->withInvoiceNumber('123456') + ->withEcommerceInfo($this->ecommerceInfo) + ->withAllowDuplicates(true) + ->execute(); + + $this->assertEquals(true, $response != null); + $this->assertEquals('00', $response->responseCode); + + # test 017b Capture/AddToBatch + # do not capture + } + + /// PARTIALLY - APPROVED SALE + + public function test018PartialApprovalVisa() + { + $address = new Address(); + $address->streetAddress1 = '6860'; + $address->postalCode = '75024'; + + $card = TestCards::visaManual(); + + $response = $card->charge(130) + ->withCurrency('USD') + ->withAddress($address) + ->withInvoiceNumber('123456') + ->withAllowPartialAuth(true) + ->withEcommerceInfo($this->ecommerceInfo) + ->execute(); + + $this->assertEquals(true, $response != null); + $this->assertEquals('10', $response->responseCode); + $this->assertEquals(true, $response->authorizedAmount != null); + $this->assertEquals('110.00', $response->authorizedAmount); + } + + public function test019PartialApprovalDiscover() + { + $address = new Address(); + $address->streetAddress1 = '6860'; + $address->postalCode = '75024'; + + $card = TestCards::discoverManual(); + + $response = $card->charge(145) + ->withCurrency('USD') + ->withAddress($address) + ->withInvoiceNumber('123456') + ->withAllowPartialAuth(true) + ->withEcommerceInfo($this->ecommerceInfo) + ->execute(); + + $this->assertEquals(true, $response != null); + $this->assertEquals('10', $response->responseCode); + $this->assertEquals(true, $response->authorizedAmount != null); + $this->assertEquals('65.00', $response->authorizedAmount); + } + + public function test020PartialApprovalMastercard() + { + $address = new Address(); + $address->streetAddress1 = '6860'; + $address->postalCode = '75024'; + + $card = TestCards::discoverManual(); + + $response = $card->charge(155) + ->withCurrency('USD') + ->withAddress($address) + ->withInvoiceNumber('123456') + ->withAllowPartialAuth(true) + ->withEcommerceInfo($this->ecommerceInfo) + ->execute(); + + $this->assertEquals(true, $response != null); + $this->assertEquals('10', $response->responseCode); + $this->assertEquals(true, $response->authorizedAmount != null); + $this->assertEquals('100.00', $response->authorizedAmount); + + $voidResponse = $response->void() + ->execute(); + $this->assertEquals(true, $voidResponse != null); + $this->assertEquals('00', $voidResponse->responseCode); + } + + /// LEVEL II CORPORATE PURCHASE CARD + + public function test021LevelIIResponseB() + { + $address = new Address(); + $address->streetAddress1 = '6860 Dallas Pkwy'; + $address->postalCode = '750241234'; + + $card = TestCards::visaManual(); + + $response = $card->charge(112.34) + ->withCurrency('USD') + ->withInvoiceNumber('123456') + ->withAddress($address) + ->withCommercialRequest(true) + ->withEcommerceInfo($this->ecommerceInfo) + ->withAllowDuplicates(true) + ->execute(); + + $this->assertEquals(true, $response != null); + $this->assertEquals('00', $response->responseCode); + $this->assertEquals('B', $response->commercialIndicator); + + $cpcResponse = $response->edit() + ->withPoNumber('9876543210') + ->withTaxType(TaxType::NOT_USED) + ->execute(); + + $this->assertEquals(true, $cpcResponse != null); + $this->assertEquals('00', $cpcResponse->responseCode); + } + + public function test022LevelIIResponseB() + { + $address = new Address(); + $address->streetAddress1 = '6860'; + $address->postalCode = '750241234'; + + $card = TestCards::visaManual(); + + $response = $card->charge(112.34) + ->withCurrency('USD') + ->withInvoiceNumber('123456') + ->withAddress($address) + ->withCommercialRequest(true) + ->withEcommerceInfo($this->ecommerceInfo) + ->withAllowDuplicates(true) + ->execute(); + + $this->assertEquals(true, $response != null); + $this->assertEquals('00', $response->responseCode); + $this->assertEquals('B', $response->commercialIndicator); + + $cpcResponse = $response->edit() + ->withTaxType(TaxType::SALES_TAX) + ->withTaxAmount(1.00) + ->execute(); + + $this->assertEquals(true, $cpcResponse != null); + $this->assertEquals('00', $cpcResponse->responseCode); + } + + public function test023LevelIIResponseR() + { + $address = new Address(); + $address->streetAddress1 = '6860'; + $address->postalCode = '75024'; + + $card = TestCards::visaManual(); + + $response = $card->charge(123.45) + ->withCurrency('USD') + ->withInvoiceNumber('123456') + ->withAddress($address) + ->withCommercialRequest(true) + ->withEcommerceInfo($this->ecommerceInfo) + ->execute(); + + $this->assertEquals(true, $response != null); + $this->assertEquals('00', $response->responseCode); + $this->assertEquals('R', $response->commercialIndicator); + + $cpcResponse = $response->edit() + ->withTaxType(TaxType::TAX_EXEMPT) + ->execute(); + + $this->assertEquals(true, $cpcResponse != null); + $this->assertEquals('00', $cpcResponse->responseCode); + } + + public function test024LevelIIResponseS() + { + $address = new Address(); + $address->streetAddress1 = '6860'; + $address->postalCode = '75024'; + + $card = TestCards::visaManual(); + + $response = $card->charge(134.56) + ->withCurrency('USD') + ->withInvoiceNumber('123456') + ->withAddress($address) + ->withCommercialRequest(true) + ->withEcommerceInfo($this->ecommerceInfo) + ->execute(); + + $this->assertEquals(true, $response != null); + $this->assertEquals('00', $response->responseCode); + $this->assertEquals('S', $response->commercialIndicator); + + $cpcResponse = $response->edit() + ->withPoNumber('9876543210') + ->withTaxType(TaxType::SALES_TAX) + ->withTaxAmount(1.00) + ->execute(); + + $this->assertEquals(true, $cpcResponse != null); + $this->assertEquals('00', $cpcResponse->responseCode); + } + + public function test025LevelIIResponseS() + { + $address = new Address(); + $address->streetAddress1 = '6860'; + $address->postalCode = '75024'; + + $card = TestCards::masterCardManual(); + + $response = $card->charge(111.06) + ->withCurrency('USD') + ->withInvoiceNumber('123456') + ->withAddress($address) + ->withCommercialRequest(true) + ->withEcommerceInfo($this->ecommerceInfo) + ->execute(); + + $this->assertEquals(true, $response != null); + $this->assertEquals('00', $response->responseCode); + $this->assertEquals('S', $response->commercialIndicator); + + $cpcResponse = $response->edit() + ->withPoNumber('9876543210') + ->withTaxType(TaxType::NOT_USED) + ->execute(); + + $this->assertEquals(true, $cpcResponse != null); + $this->assertEquals('00', $cpcResponse->responseCode); + } + + public function test026LevelIIResponseS() + { + $address = new Address(); + $address->streetAddress1 = '6860'; + $address->postalCode = '75024'; + + $card = TestCards::masterCardManual(); + + $response = $card->charge(111.07) + ->withCurrency('USD') + ->withInvoiceNumber('123456') + ->withAddress($address) + ->withCommercialRequest(true) + ->withEcommerceInfo($this->ecommerceInfo) + ->execute(); + + $this->assertEquals(true, $response != null); + $this->assertEquals('00', $response->responseCode); + $this->assertEquals('S', $response->commercialIndicator); + + $cpcResponse = $response->edit() + ->withTaxType(TaxType::SALES_TAX) + ->withTaxAmount(1.00) + ->execute(); + + $this->assertEquals(true, $cpcResponse != null); + $this->assertEquals('00', $cpcResponse->responseCode); + } + + public function test027LevelIIResponseS() + { + $address = new Address(); + $address->streetAddress1 = '6860'; + $address->postalCode = '75024'; + + $card = TestCards::masterCardManual(); + + $response = $card->charge(111.08) + ->withCurrency('USD') + ->withInvoiceNumber('123456') + ->withAddress($address) + ->withCommercialRequest(true) + ->withEcommerceInfo($this->ecommerceInfo) + ->execute(); + + $this->assertEquals(true, $response != null); + $this->assertEquals('00', $response->responseCode); + $this->assertEquals('S', $response->commercialIndicator); + + $cpcResponse = $response->edit() + ->withPoNumber('9876543210') + ->withTaxType(TaxType::SALES_TAX) + ->withTaxAmount(1.00) + ->execute(); + + $this->assertEquals(true, $cpcResponse != null); + $this->assertEquals('00', $cpcResponse->responseCode); + } + + public function test028LevelIIResponseS() + { + $address = new Address(); + $address->streetAddress1 = '6860'; + $address->postalCode = '75024'; + + $card = TestCards::masterCardManual(); + + $response = $card->charge(111.09) + ->withCurrency('USD') + ->withInvoiceNumber('123456') + ->withAddress($address) + ->withCommercialRequest(true) + ->withEcommerceInfo($this->ecommerceInfo) + ->execute(); + + $this->assertEquals(true, $response != null); + $this->assertEquals('00', $response->responseCode); + $this->assertEquals('S', $response->commercialIndicator); + + $cpcResponse = $response->edit() + ->withPoNumber('9876543210') + ->withTaxType(TaxType::TAX_EXEMPT) + ->execute(); + + $this->assertEquals(true, $cpcResponse != null); + $this->assertEquals('00', $cpcResponse->responseCode); + } + + public function test029LevelIINoResponse() + { + $address = new Address(); + $address->streetAddress1 = '6860'; + $address->postalCode = '75024'; + + $card = TestCards::amexManual(); + + $response = $card->charge(111.10) + ->withCurrency('USD') + ->withInvoiceNumber('123456') + ->withAddress($address) + ->withCommercialRequest(true) + ->withEcommerceInfo($this->ecommerceInfo) + ->execute(); + + $this->assertEquals(true, $response != null); + $this->assertEquals('00', $response->responseCode); + $this->assertEquals('0', $response->commercialIndicator); + + $cpcResponse = $response->edit() + ->withPoNumber('9876543210') + ->withTaxType(TaxType::NOT_USED) + ->execute(); + + $this->assertEquals(true, $cpcResponse != null); + $this->assertEquals('00', $cpcResponse->responseCode); + } + + public function test030LevelIINoResponse() + { + $address = new Address(); + $address->streetAddress1 = '6860'; + $address->postalCode = '750241234'; + + $card = TestCards::amexManual(); + + $response = $card->charge(111.11) + ->withCurrency('USD') + ->withInvoiceNumber('123456') + ->withAddress($address) + ->withCommercialRequest(true) + ->withEcommerceInfo($this->ecommerceInfo) + ->execute(); + + $this->assertEquals(true, $response != null); + $this->assertEquals('00', $response->responseCode); + $this->assertEquals('0', $response->commercialIndicator); + + $cpcResponse = $response->edit() + ->withTaxType(TaxType::SALES_TAX) + ->withTaxAmount(1.00) + ->execute(); + + $this->assertEquals(true, $cpcResponse != null); + $this->assertEquals('00', $cpcResponse->responseCode); + } + + public function test031LevelIINoResponse() + { + $address = new Address(); + $address->streetAddress1 = '6860'; + $address->postalCode = '75024'; + + $card = TestCards::amexManual(); + + $response = $card->charge(111.12) + ->withCurrency('USD') + ->withInvoiceNumber('123456') + ->withAddress($address) + ->withCommercialRequest(true) + ->withEcommerceInfo($this->ecommerceInfo) + ->execute(); + + $this->assertEquals(true, $response != null); + $this->assertEquals('00', $response->responseCode); + $this->assertEquals('0', $response->commercialIndicator); + + $cpcResponse = $response->edit() + ->withPoNumber('9876543210') + ->withTaxType(TaxType::SALES_TAX) + ->withTaxAmount(1.00) + ->execute(); + + $this->assertEquals(true, $cpcResponse != null); + $this->assertEquals('00', $cpcResponse->responseCode); + } + + public function test032LevelIINoResponse() + { + $address = new Address(); + $address->streetAddress1 = '6860'; + $address->postalCode = '75024'; + + $card = TestCards::amexManual(); + + $response = $card->charge(111.13) + ->withCurrency('USD') + ->withInvoiceNumber('123456') + ->withAddress($address) + ->withCommercialRequest(true) + ->withEcommerceInfo($this->ecommerceInfo) + ->execute(); + + $this->assertEquals(true, $response != null); + $this->assertEquals('00', $response->responseCode); + $this->assertEquals('0', $response->commercialIndicator); + + $cpcResponse = $response->edit() + ->withPoNumber('9876543210') + ->withTaxType(TaxType::TAX_EXEMPT) + ->execute(); + + $this->assertEquals(true, $cpcResponse != null); + $this->assertEquals('00', $cpcResponse->responseCode); + } + + /// PRIOR / VOICE AUTHORIZATION + + public function test033OfflineSale() + { + $card = TestCards::visaManual(); + + $response = $card->charge(17.10) + ->withCurrency('USD') + ->withModifier(TransactionModifier::OFFLINE) + ->withOfflineAuthCode('654321') + ->withInvoiceNumber('123456') + ->withEcommerceInfo($this->ecommerceInfo) + ->execute(); + + $this->assertEquals(true, $response != null); + $this->assertEquals('00', $response->responseCode); + } + + public function test033OfflineAuthorization() + { + $card = TestCards::visaManual(); + + $response = $card->authorize(17.10) + ->withCurrency('USD') + ->withModifier(TransactionModifier::OFFLINE) + ->withOfflineAuthCode('654321') + ->withInvoiceNumber('123456') + ->withEcommerceInfo($this->ecommerceInfo) + ->execute(); + + $this->assertEquals(true, $response != null); + $this->assertEquals('00', $response->responseCode); + } + + /// RETURN + + public function test034OfflineCreditReturn() + { + $card = TestCards::masterCardManual(); + + $response = $card->refund(15.15) + ->withCurrency('USD') + ->withInvoiceNumber('123456') + ->withEcommerceInfo($this->ecommerceInfo) + ->execute(); + + $this->assertEquals(true, $response != null); + $this->assertEquals('00', $response->responseCode); + } + + public function test034bOfflineCreditReturn() + { + $card = TestCards::masterCardManual(); + + $response = $card->refund(15.16) + ->withCurrency('USD') + ->withInvoiceNumber('123456') + ->withEcommerceInfo($this->ecommerceInfo) + ->execute(); + + $this->assertEquals(true, $response != null); + $this->assertEquals('00', $response->responseCode); + } + + /// ONLINE VOID / REVERSAL + + public function test035VoidTest10() + { + // see test 010 + } + + public function test036VoidTest20() + { + // see test 020 + } + + /// Time Out Reversal + public function test036bTimeoutReversal() + { + $sale = TestCards::visaManual()->charge(911) + ->withCurrency('USD') + ->withInvoiceNumber('123456') + ->withClientTransactionId('987321654') + ->withEcommerceInfo($this->ecommerceInfo) + ->execute(); + + $this->assertEquals(true, $sale != null); + $this->assertEquals('91', $sale->responseCode); + + $response = Transaction::fromId(null, PaymentMethodType::CREDIT); + $response->clientTransactionId = '987321654'; + + $this->expectException(GatewayException::class); + $response->reverse(911)->execute(); + } + + /// One time bill payment + + public function test010ChargeVisaOneTime() + { + $address = new Address(); + $address->streetAddress1 = '6860 Dallas Pkwy'; + $address->postalCode = '75024'; + + $card = null; + if ($this->useTokens) { + $card = new CreditCardData(); + $card->token = static::$visaToken; + } else { + $card = TestCards::visaManual(); + } + + $response = $card->charge(13.11) + ->withCurrency('USD') + ->withAddress($address) + ->withInvoiceNumber('123456') + ->withOneTimePayment(true) + ->withAllowDuplicates(true) + ->execute(); + + $this->assertEquals(true, $response != null); + $this->assertEquals('00', $response->responseCode); + + $void = $response->void()->execute(); + + $this->assertEquals(true, $void != null); + $this->assertEquals('00', $void->responseCode); + } + + public function test011ChargeMasterCardOneTime() + { + $address = new Address(); + $address->streetAddress1 = '6860'; + $address->postalCode = '750241234'; + + $card = null; + if ($this->useTokens) { + $card = new CreditCardData(); + $card->token = static::$mastercardToken; + } else { + $card = TestCards::masterCardManual(); + } + + $response = $card->charge(13.12) + ->withCurrency('USD') + ->withAddress($address) + ->withInvoiceNumber('123456') + ->withOneTimePayment(true) + ->withAllowDuplicates(true) + ->execute(); + + $this->assertEquals(true, $response != null); + $this->assertEquals('00', $response->responseCode); + } + + public function test012ChargeDiscoverOneTime() + { + $address = new Address(); + $address->streetAddress1 = '6860'; + $address->postalCode = '75024'; + + $card = null; + if ($this->useTokens) { + $card = new CreditCardData(); + $card->token = static::$discoverToken; + } else { + $card = TestCards::discoverManual(); + } + + $response = $card->charge(13.13) + ->withCurrency('USD') + ->withAddress($address) + ->withInvoiceNumber('123456') + ->withOneTimePayment(true) + ->withAllowDuplicates(true) + ->execute(); + + $this->assertEquals(true, $response != null); + $this->assertEquals('00', $response->responseCode); + } + + public function test013ChargeAmexOneTime() + { + $address = new Address(); + $address->streetAddress1 = '6860'; + $address->postalCode = '75024'; + + $card = null; + if ($this->useTokens) { + $card = new CreditCardData(); + $card->token = static::$amexToken; + } else { + $card = TestCards::amexManual(); + } + + $response = $card->charge(13.14) + ->withCurrency('USD') + ->withAddress($address) + ->withInvoiceNumber('123456') + ->withOneTimePayment(true) + ->withAllowDuplicates(true) + ->execute(); + + $this->assertEquals(true, $response != null); + $this->assertEquals('00', $response->responseCode); + } + + public function test014ChargeJcbOneTime() + { + $address = new Address(); + $address->streetAddress1 = '6860'; + $address->postalCode = '75024'; + + $card = new CreditCardData(); + $card->number = '3566007770007321'; + $card->expMonth = '12'; + $card->expYear = TestCards::validCardExpYear(); + $card->cvn = '123'; + + $response = $card->charge(13.15) + ->withCurrency('USD') + ->withAddress($address) + ->withInvoiceNumber('123456') + ->withOneTimePayment(true) + ->withAllowDuplicates(true) + ->execute(); + + $this->assertEquals(true, $response != null); + $this->assertEquals('00', $response->responseCode); + } + + /// ADVANCED FRAUD SCREENING + + /** + * TODO: Change code assertions when AFS is enabled on account + */ + public function test037FraudPreventionSale() + { + $card = TestCards::visaManual(); + + $response = $card->charge(15000) + ->withCurrency('USD') + ->execute(); + $this->assertEquals(true, $response != null); + $this->assertEquals('00', $response->responseCode); + // $this->assertEquals('FR', $response->responseCode); + } + + /** + * TODO: Change code assertions when AFS is enabled on account + */ + public function test038FraudPreventionReturn() + { + $card = TestCards::visaManual(); + + $response = $card->refund(15000) + ->withCurrency('USD') + ->execute(); + $this->assertEquals(true, $response != null); + $this->assertEquals('00', $response->responseCode); + // $this->assertEquals('41', $response->responseCode); + } + + /// ONE CARD - GSB CARD FUNCTIONS + + /// BALANCE INQUIRY + + public function test037BalanceInquiryGsb() + { + if (false === $this->usePrepaid) { + $this->markTestSkipped('GSB not configured'); + } + + $address = new Address(); + $address->streetAddress1 = '6860'; + $address->postalCode = '75024'; + + $card = TestCards::gsbManual(); + + $response = $card->balanceInquiry() + ->withAddress($address) + ->execute(); + + $this->assertEquals(true, $response != null); + $this->assertEquals('00', $response->responseCode); + } + + /// ADD VALUE + + public function test038AddValueGsb() + { + if (false === $this->usePrepaid) { + $this->markTestSkipped('GSB not configured'); + } + + $card = new CreditTrackData(); + $card->value = '%B6277220572999800^ / ^49121010557010000016000000?F;6277220572999800=49121010557010000016?'; + + $response = $card->addValue(15.00) + ->withCurrency('USD') + ->execute(); + + $this->assertEquals(true, $response != null); + $this->assertEquals('00', $response->responseCode); + } + + /// SALE + + public function test039ChargeGsb() + { + if (false === $this->usePrepaid) { + $this->markTestSkipped('GSB not configured'); + } + + $address = new Address(); + $address->streetAddress1 = '6860'; + $address->postalCode = '75024'; + + $card = TestCards::gsbManual(); + + $response = $card->charge(2.05) + ->withCurrency('USD') + ->withAddress($address) + ->withInvoiceNumber('123456') + ->execute(); + + $this->assertEquals(true, $response != null); + $this->assertEquals('00', $response->responseCode); + + $voidResponse = $response->void() + ->execute(); + $this->assertEquals(true, $voidResponse != null); + $this->assertEquals('00', $voidResponse->responseCode); + } + + public function test040ChargeGsb() + { + if (false === $this->usePrepaid) { + $this->markTestSkipped('GSB not configured'); + } + + $address = new Address(); + $address->streetAddress1 = '6860'; + $address->postalCode = '75024'; + + $card = TestCards::gsbManual(); + + $response = $card->charge(2.10) + ->withCurrency('USD') + ->withAddress($address) + ->withInvoiceNumber('123456') + ->execute(); + + $this->assertEquals(true, $response != null); + $this->assertEquals('00', $response->responseCode); + } + + /// ONLINE VOID / REVERSAL + + public function test041VoidGsb() + { + // see test 039 + } + + /// HMS GIFT - REWARDS + + /// ACTIVATE + + public function test042ActivateGift1() + { + $card = TestCards::giftCard1Swipe(); + + $response = $card->activate(6.00) + ->withCurrency('USD') + ->execute(); + $this->assertEquals(true, $response != null); + $this->assertEquals('00', $response->responseCode); + } + + public function test043ActivateGift2() + { + + $card = TestCards::giftCard2Manual(); + + $response = $card->activate(7.00) + ->withCurrency('USD') + ->execute(); + $this->assertEquals(true, $response != null); + $this->assertEquals('00', $response->responseCode); + } + + /// LOAD / ADD VALUE + + public function test044AddValueGift1() + { + $card = TestCards::giftCard1Swipe(); + + $response = $card->addValue(8.00) + ->withCurrency('USD') + ->execute(); + $this->assertEquals(true, $response != null); + $this->assertEquals('00', $response->responseCode); + } + + public function test045AddValueGift2() + { + $card = TestCards::giftCard2Manual(); + + $response = $card->addValue(9.00) + ->withCurrency('USD') + ->execute(); + $this->assertEquals(true, $response != null); + $this->assertEquals('00', $response->responseCode); + } + + /// BALANCE INQUIRY + + public function test046BalanceInquiryGift1() + { + $card = TestCards::giftCard1Swipe(); + + $response = $card->balanceInquiry() + ->execute(); + $this->assertEquals(true, $response != null); + $this->assertEquals('00', $response->responseCode); + $this->assertEquals('10.00', $response->balanceAmount); + } + + public function test047BalanceInquiryGift2() + { + $card = TestCards::giftCard2Manual(); + + $response = $card->balanceInquiry() + ->execute(); + $this->assertEquals(true, $response != null); + $this->assertEquals('00', $response->responseCode); + $this->assertEquals('10.00', $response->balanceAmount); + } + + /// REPLACE / TRANSFER + + public function test048ReplaceGift1() + { + $card = TestCards::giftCard1Swipe(); + + $response = $card->replaceWith(TestCards::giftCard2Manual()) + ->execute(); + + $this->assertEquals(true, $response != null); + $this->assertEquals('00', $response->responseCode); + $this->assertEquals('10.00', $response->balanceAmount); + } + + public function test049ReplaceGift2() + { + $card = TestCards::giftCard2Manual(); + + $response = $card->replaceWith(TestCards::giftCard1Swipe()) + ->execute(); + + $this->assertEquals(true, $response != null); + $this->assertEquals('00', $response->responseCode); + $this->assertEquals('10.00', $response->balanceAmount); + } + + /// SALE / REDEEM + + public function test050SaleGift1() + { + $card = TestCards::giftCard1Swipe(); + + $response = $card->charge(1.00) + ->withCurrency('USD') + ->execute(); + $this->assertEquals(true, $response != null); + $this->assertEquals('00', $response->responseCode); + } + + public function test051SaleGift2() + { + $card = TestCards::giftCard2Manual(); + + $response = $card->charge(2.00) + ->withCurrency('USD') + ->execute(); + $this->assertEquals(true, $response != null); + $this->assertEquals('00', $response->responseCode); + } + + public function test052SaleGift1Void() + { + $card = TestCards::giftCard1Swipe(); + + $response = $card->charge(3.00) + ->withCurrency('USD') + ->execute(); + $this->assertEquals(true, $response != null); + $this->assertEquals('00', $response->responseCode); + + $voidResponse = $response->void() + ->execute(); + $this->assertEquals(true, $voidResponse != null); + $this->assertEquals('00', $voidResponse->responseCode); + } + + public function test053SaleGift2Reversal() + { + $card = TestCards::giftCard2Manual(); + + $response = $card->charge(4.00) + ->withCurrency('USD') + ->execute(); + $this->assertEquals(true, $response != null); + $this->assertEquals('00', $response->responseCode); + + $reversalResponse = $response->reverse(4.00) + ->execute(); + $this->assertEquals(true, $reversalResponse != null); + $this->assertEquals('00', $reversalResponse->responseCode); + } + + /// VOID + + public function test054VoidGift() + { + // see test 052 + } + + /// REVERSAL + + public function test055ReversalGift() + { + // see test 053 + } + + public function test056ReversalGift2() + { + $card = TestCards::giftCard2Manual(); + + $reversalResponse = $card->reverse(2.00) + ->execute(); + $this->assertEquals(true, $reversalResponse != null); + $this->assertEquals('00', $reversalResponse->responseCode); + } + + /// DEACTIVATE + + public function test057DeactivateGift1() + { + $card = TestCards::giftCard1Swipe(); + + $response = $card->deactivate() + ->execute(); + $this->assertEquals(true, $response != null); + $this->assertEquals('00', $response->responseCode); + } + + /// RECEIPTS MESSAGING + + public function test058ReceiptsMessaging() + { + return; # print and scan receipt for test 51 + } + + /// REWARD + + /// BALANCE INQUIRY + + public function test059BalanceInquiryRewards1() + { + $card = TestCards::giftCard1Swipe(); + + $response = $card->balanceInquiry() + ->execute(); + $this->assertEquals(true, $response != null); + $this->assertEquals('00', $response->responseCode); + $this->assertTrue($response->pointsBalanceAmount > 0); + } + + public function test060BalanceInquiryRewards2() + { + $card = TestCards::giftCard2Manual(); + + $response = $card->balanceInquiry() + ->execute(); + $this->assertEquals(true, $response != null); + $this->assertEquals('00', $response->responseCode); + $this->assertTrue($response->pointsBalanceAmount > 0); + } + + /// ALIAS + + public function test061CreateAliasGift1() + { + $response = GiftCard::create('9725550100'); + + $this->assertEquals(true, $response != null); + } + + public function test062CreateAliasGift2() + { + $response = GiftCard::create('9725550100'); + + $this->assertEquals(true, $response != null); + } + + public function test063AddAliasGift1() + { + $card = TestCards::giftCard1Swipe(); + + $response = $card->addAlias('2145550199') + ->execute(); + $this->assertEquals(true, $response != null); + $this->assertEquals('00', $response->responseCode); + } + + public function test064AddAliasGift2() + { + $card = TestCards::giftCard2Manual(); + + $response = $card->addAlias('2145550199') + ->execute(); + $this->assertEquals(true, $response != null); + $this->assertEquals('00', $response->responseCode); + } + + public function test065DeleteAliasGift1() + { + $card = TestCards::giftCard1Swipe(); + + $response = $card->removeAlias('2145550199') + ->execute(); + $this->assertEquals(true, $response != null); + $this->assertEquals('00', $response->responseCode); + } + + /// SALE / REDEEM + + public function test066RedeemPointsGift1() + { + $card = TestCards::giftCard1Swipe(); + + $response = $card->charge(100) + ->withCurrency('POINTS') + ->execute(); + $this->assertEquals(true, $response != null); + $this->assertEquals('00', $response->responseCode); + } + + public function test067RedeemPointsGift2() + { + $card = TestCards::giftCard2Manual(); + + $response = $card->charge(200) + ->withCurrency('POINTS') + ->execute(); + $this->assertEquals(true, $response != null); + $this->assertEquals('00', $response->responseCode); + } + + public function test068RedeemPointsGift2() + { + $card = new GiftCard(); + $card->alias = '9725550100'; + + $response = $card->charge(300) + ->withCurrency('POINTS') + ->execute(); + $this->assertEquals(true, $response != null); + $this->assertEquals('00', $response->responseCode); + } + + /// REWARDS + + public function test069RewardsGift1() + { + $card = TestCards::giftCard1Swipe(); + + $response = $card->rewards(10) + ->execute(); + $this->assertEquals(true, $response != null); + $this->assertEquals('00', $response->responseCode); + } + + public function test070RewardsGift2() + { + $card = TestCards::giftCard2Manual(); + + $response = $card->rewards(11) + ->execute(); + $this->assertEquals(true, $response != null); + $this->assertEquals('00', $response->responseCode); + } + + /// REPLACE / TRANSFER + + public function test071ReplaceGift1() + { + $card = TestCards::giftCard1Swipe(); + + $response = $card->replaceWith(TestCards::giftCard2Manual()) + ->execute(); + $this->assertEquals(true, $response != null); + $this->assertEquals('00', $response->responseCode); + } + + public function test072ReplaceGift2() + { + $card = TestCards::giftCard2Manual(); + + $response = $card->replaceWith(TestCards::giftCard1Swipe()) + ->execute(); + $this->assertEquals(true, $response != null); + $this->assertEquals('00', $response->responseCode); + } + + /// DEACTIVATE + + public function test073DeactivateGift1() + { + $card = TestCards::giftCard1Swipe(); + + $response = $card->deactivate() + ->execute(); + $this->assertEquals(true, $response != null); + $this->assertEquals('00', $response->responseCode); + } + + public function test074DeactivateGift2() + { + $card = TestCards::giftCard2Manual(); + + $response = $card->deactivate() + ->execute(); + $this->assertEquals(true, $response != null); + $this->assertEquals('00', $response->responseCode); + } + + /// RECEIPTS MESSAGING + + public function test075ReceiptsMessaging() + { + return; # print and scan receipt for test 51 + } + + /// CLOSE BATCH + + public function test999CloseBatch() + { + try { + $response = BatchService::closeBatch(); + $this->assertNotNull($response); + // printf('batch id: %s', $response->id); + // printf('sequence number: %s', $response->sequenceNumber); + } catch (ApiException $e) { + if (false === strpos($e->getMessage(), static::BATCH_NOT_OPEN) + && false === strpos($e->getMessage(), static::NO_TRANS_IN_BATCH) + ) { + $this->fail($e->getMessage()); + } + } + } + + public function test100ChargeVisaEcommerceInfo() + { + $address = new Address(); + $address->streetAddress1 = '6860 Dallas Pkwy'; + $address->postalCode = '75024'; + + $secureEcom = new ThreeDSecure(); + $secureEcom->cavv = 'AAACBllleHchZTBWIGV4AAAAAAA='; + $secureEcom->xid = 'crqAeMwkEL9r4POdxpByWJ1/wYg='; + $secureEcom->eci = '5'; + $secureEcom->paymentDataSource = Secure3dPaymentDataSource::VISA_3DSECURE; + $secureEcom->paymentDataType = '3DSecure'; + + $card = TestCards::visaManual(); + $card->threeDSecure = $secureEcom; + + $response = $card->charge() + ->withCurrency('USD') + ->withAmount(13.01) + ->withAddress($address) + // ->withEcommerceInfo($this->ecommerceInfo) + ->withInvoiceNumber('12345') + ->withAllowDuplicates(true) + ->execute(); + + $this->assertEquals(true, $response != null); + $this->assertEquals('00', $response->responseCode); + } +} diff --git a/test/Integration/Gateways/PorticoConnector/Certifications/MotoCheckTest.php b/test/Integration/Gateways/PorticoConnector/Certifications/MotoCheckTest.php index 72afddf3..0e192914 100644 --- a/test/Integration/Gateways/PorticoConnector/Certifications/MotoCheckTest.php +++ b/test/Integration/Gateways/PorticoConnector/Certifications/MotoCheckTest.php @@ -1,108 +1,108 @@ -secretApiKey = 'skapi_cert_MTyMAQBiHVEAewvIzXVFcmUd2UcyBge_eCpaASUp0A'; - $config->serviceUrl = ($this->enableCryptoUrl) ? - 'https://cert.api2-c.heartlandportico.com/': - 'https://cert.api2.heartlandportico.com'; - return $config; - } - - protected function setup() - { - ServicesContainer::configureService($this->config()); - - $this->address = new Address(); - $this->address->streetAddress1 = '123 Main St.'; - $this->address->city = 'Downtown'; - $this->address->province = 'NJ'; - $this->address->postalCode = '12345'; - } - - public function test001ConsumerPersonalChecking() - { - $check = TestChecks::certification( - SecCode::WEB, - CheckType::PERSONAL, - AccountType::CHECKING - ); - - $response = $check->charge(19.00) - ->withCurrency('USD') - ->withAddress($this->address) - ->execute(); - - $this->assertNotNull($response); - $this->assertEquals('00', $response->responseCode); - } - - public function test002ConsumerBusinessChecking() - { - $check = TestChecks::certification( - SecCode::WEB, - CheckType::BUSINESS, - AccountType::CHECKING - ); - - $response = $check->charge(20.00) - ->withCurrency('USD') - ->withAddress($this->address) - ->execute(); - - $this->assertNotNull($response); - $this->assertEquals('00', $response->responseCode); - } - - public function test003ConsumerPersonalSavings() - { - $check = TestChecks::certification( - SecCode::WEB, - CheckType::PERSONAL, - AccountType::SAVINGS - ); - - $response = $check->charge(21.00) - ->withCurrency('USD') - ->withAddress($this->address) - ->execute(); - - $this->assertNotNull($response); - $this->assertEquals('00', $response->responseCode); - } - - public function test004ConsumerBusinessSavings() - { - $check = TestChecks::certification( - SecCode::WEB, - CheckType::BUSINESS, - AccountType::SAVINGS - ); - - $response = $check->charge(22.00) - ->withCurrency('USD') - ->withAddress($this->address) - ->execute(); - - $this->assertNotNull($response); - $this->assertEquals('00', $response->responseCode); - } -} +secretApiKey = 'skapi_cert_MTyMAQBiHVEAewvIzXVFcmUd2UcyBge_eCpaASUp0A'; + $config->serviceUrl = ($this->enableCryptoUrl) ? + 'https://cert.api2-c.heartlandportico.com/': + 'https://cert.api2.heartlandportico.com'; + return $config; + } + + protected function setup() + { + ServicesContainer::configureService($this->config()); + + $this->address = new Address(); + $this->address->streetAddress1 = '123 Main St.'; + $this->address->city = 'Downtown'; + $this->address->province = 'NJ'; + $this->address->postalCode = '12345'; + } + + public function test001ConsumerPersonalChecking() + { + $check = TestChecks::certification( + SecCode::WEB, + CheckType::PERSONAL, + AccountType::CHECKING + ); + + $response = $check->charge(19.00) + ->withCurrency('USD') + ->withAddress($this->address) + ->execute(); + + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode); + } + + public function test002ConsumerBusinessChecking() + { + $check = TestChecks::certification( + SecCode::WEB, + CheckType::BUSINESS, + AccountType::CHECKING + ); + + $response = $check->charge(20.00) + ->withCurrency('USD') + ->withAddress($this->address) + ->execute(); + + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode); + } + + public function test003ConsumerPersonalSavings() + { + $check = TestChecks::certification( + SecCode::WEB, + CheckType::PERSONAL, + AccountType::SAVINGS + ); + + $response = $check->charge(21.00) + ->withCurrency('USD') + ->withAddress($this->address) + ->execute(); + + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode); + } + + public function test004ConsumerBusinessSavings() + { + $check = TestChecks::certification( + SecCode::WEB, + CheckType::BUSINESS, + AccountType::SAVINGS + ); + + $response = $check->charge(22.00) + ->withCurrency('USD') + ->withAddress($this->address) + ->execute(); + + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode); + } +} diff --git a/test/Integration/Gateways/PorticoConnector/Certifications/MotoTest.php b/test/Integration/Gateways/PorticoConnector/Certifications/MotoTest.php index e73330a9..73d21c07 100644 --- a/test/Integration/Gateways/PorticoConnector/Certifications/MotoTest.php +++ b/test/Integration/Gateways/PorticoConnector/Certifications/MotoTest.php @@ -1,1713 +1,1713 @@ -secretApiKey = 'skapi_cert_MRCQAQBC_VQACBE0rFaZlbDDPieMGP06JDAtjyS7NQ'; - $config->serviceUrl = ($this->enableCryptoUrl) ? - 'https://cert.api2-c.heartlandportico.com/': - 'https://cert.api2.heartlandportico.com'; - return $config; - } - - protected function setup() - { - ServicesContainer::configureService($this->config()); - - $this->ecommerceInfo = new EcommerceInfo(); - $this->ecommerceInfo->channel = EcommerceChannel::MOTO; - } - - public function test000CloseBatch() - { - try { - $response = BatchService::closeBatch(); - $this->assertNotNull($response); - // print 'batch id: ' . $response->id . "\n"; - // print 'sequence number: ' . $response->sequenceNumber . "\n"; - } catch (ApiException $e) { - if (false === strpos($e->getMessage(), static::BATCH_NOT_OPEN) - && false === strpos($e->getMessage(), static::NO_TRANS_IN_BATCH) - ) { - $this->fail($e->getMessage()); - } - } - } - - public function test001VerifyVisa() - { - $card = new CreditCardData(); - $card->number = '4484958240202792'; - $card->expMonth = '12'; - $card->expYear = TestCards::validCardExpYear(); - - $response = $card->verify() - ->withRequestMultiUseToken($this->useTokens) - ->execute(); - - $this->assertNotNull($response); - $this->assertEquals('00', $response->responseCode); - } - - public function test002VerifyMasterCard() - { - $card = new CreditCardData(); - $card->number = '5356083898949891'; - $card->expMonth = '12'; - $card->expYear = TestCards::validCardExpYear(); - - $response = $card->verify() - ->withRequestMultiUseToken($this->useTokens) - ->execute(); - - $this->assertNotNull($response); - $this->assertEquals('00', $response->responseCode); - } - - public function test003VerifyDiscover() - { - $address = new Address(); - $address->postalCode = '75024'; - - $card = new CreditCardData(); - $card->number = '6223971100014620'; - $card->expMonth = '12'; - $card->expYear = TestCards::validCardExpYear(); - - $response = $card->verify() - ->withAddress($address) - ->withRequestMultiUseToken($this->useTokens) - ->execute(); - - $this->assertNotNull($response); - $this->assertEquals('00', $response->responseCode); - } - - // StreetAddress verification - - public function test004VerifyAmex() - { - $address = new Address(); - $address->postalCode = '75024'; - - $card = new CreditCardData(); - $card->number = '345039962663847'; - $card->expMonth = '12'; - $card->expYear = TestCards::validCardExpYear(); - - $response = $card->verify() - ->withAddress($address) - ->withRequestMultiUseToken($this->useTokens) - ->execute(); - - $this->assertNotNull($response); - $this->assertEquals('00', $response->responseCode); - } - - // Balance Inquiry (for prepaid card) - - public function test005BalanceInquiryVisa() - { - $card = new CreditCardData(); - $card->number = '4664383951958601'; - $card->expMonth = '12'; - $card->expYear = TestCards::validCardExpYear(); - - $response = $card->balanceInquiry()->execute(); - - $this->assertNotNull($response); - $this->assertEquals('00', $response->responseCode, $response->responseMessage); - } - - // CREDIT SALE (for multi-use token only) - - public function test006ChargeVisaToken() - { - $address = new Address(); - $address->streetAddress1 = '6860 Dallas Pkwy'; - $address->postalCode = '75024'; - - $card = new CreditCardData(); - $card->number = '4012002000060016'; - $card->expMonth = '12'; - $card->expYear = TestCards::validCardExpYear(); - - $response = $card->charge(13.01) - ->withCurrency('USD') - ->withInvoiceNumber('123456') - ->withEcommerceInfo($this->ecommerceInfo) - ->withAddress($address) - ->withRequestMultiUseToken(true) - ->withAllowDuplicates(true) - ->execute(); - - $this->assertNotNull($response); - $this->assertEquals('00', $response->responseCode); - static::$visaToken = $response->token; - } - - public function test007ChargeMasterCardToken() - { - $address = new Address(); - $address->streetAddress1 = '6860'; - $address->postalCode = '75024'; - - $card = new CreditCardData(); - $card->number = '5473500000000014'; - $card->expMonth = '12'; - $card->expYear = TestCards::validCardExpYear(); - $card->cvn = '123'; - - $response = $card->charge(13.02) - ->withCurrency('USD') - ->withInvoiceNumber('123456') - ->withEcommerceInfo($this->ecommerceInfo) - ->withAddress($address) - ->withRequestMultiUseToken(true) - ->withAllowDuplicates(true) - ->execute(); - - $this->assertNotNull($response); - $this->assertEquals('00', $response->responseCode); - static::$mastercardToken = $response->token; - } - - public function test008ChargeDiscoverToken() - { - $address = new Address(); - $address->streetAddress1 = '6860'; - $address->postalCode = '750241234'; - - $card = new CreditCardData(); - $card->number = '6011000990156527'; - $card->expMonth = '12'; - $card->expYear = TestCards::validCardExpYear(); - $card->cvn = '123'; - - $response = $card->charge(13.03) - ->withCurrency('USD') - ->withInvoiceNumber('123456') - ->withEcommerceInfo($this->ecommerceInfo) - ->withAddress($address) - ->withRequestMultiUseToken(true) - ->withAllowDuplicates(true) - ->execute(); - - $this->assertNotNull($response); - $this->assertEquals('00', $response->responseCode); - static::$discoverToken = $response->token; - } - - public function test009ChargeAmexToken() - { - $address = new Address(); - $address->streetAddress1 = '6860 Dallas Pkwy'; - $address->postalCode = '75024'; - - $card = new CreditCardData(); - $card->number = '372700699251018'; - $card->expMonth = '12'; - $card->expYear = TestCards::validCardExpYear(); - $card->cvn = '1234'; - - $response = $card->charge(13.04) - ->withCurrency('USD') - ->withInvoiceNumber('123456') - ->withEcommerceInfo($this->ecommerceInfo) - ->withAddress($address) - ->withRequestMultiUseToken(true) - ->withAllowDuplicates(true) - ->execute(); - - $this->assertNotNull($response); - $this->assertEquals('00', $response->responseCode); - static::$amexToken = $response->token; - } - - // CREDIT SALE - - public function test010ChargeVisa() - { - $address = new Address(); - $address->streetAddress1 = '6860 Dallas Pkwy'; - $address->postalCode = '75024'; - - $card = null; - if ($this->useTokens) { - $card = new CreditCardData(); - $card->token = static::$visaToken; - } else { - $card = TestCards::visaManual(); - } - - $response = $card->charge(17.01) - ->withCurrency('USD') - ->withEcommerceInfo($this->ecommerceInfo) - ->withAddress($address) - ->withInvoiceNumber('123456') - ->withAllowDuplicates(true) - ->execute(); - - $this->assertNotNull($response); - $this->assertEquals('00', $response->responseCode); - - // test case 35 - $void = $response->void()->execute(); - - $this->assertNotNull($void); - $this->assertEquals('00', $void->responseCode); - } - - public function test011ChargeMasterCard() - { - $address = new Address(); - $address->streetAddress1 = '6860'; - $address->postalCode = '75024'; - - $card = null; - if ($this->useTokens) { - $card = new CreditCardData(); - $card->token = static::$mastercardToken; - } else { - $card = TestCards::masterCardManual(); - } - - $response = $card->charge(17.02) - ->withCurrency('USD') - ->withEcommerceInfo($this->ecommerceInfo) - ->withAddress($address) - ->withInvoiceNumber('123456') - ->withAllowDuplicates(true) - ->execute(); - - $this->assertNotNull($response); - $this->assertEquals('00', $response->responseCode); - } - - public function test012ChargeDiscover() - { - $address = new Address(); - $address->streetAddress1 = '6860'; - $address->postalCode = '750241234'; - - $card = null; - if ($this->useTokens) { - $card = new CreditCardData(); - $card->token = static::$discoverToken; - } else { - $card = TestCards::discoverManual(); - } - - $response = $card->charge(17.03) - ->withCurrency('USD') - ->withEcommerceInfo($this->ecommerceInfo) - ->withAddress($address) - ->withInvoiceNumber('123456') - ->withAllowDuplicates(true) - ->execute(); - - $this->assertNotNull($response); - $this->assertEquals('00', $response->responseCode); - } - - public function test013ChargeAmex() - { - $address = new Address(); - $address->streetAddress1 = '6860 Dallas Pkwy'; - $address->postalCode = '75024'; - - $card = null; - if ($this->useTokens) { - $card = new CreditCardData(); - $card->token = static::$amexToken; - } else { - $card = TestCards::amexManual(); - } - - $response = $card->charge(17.04) - ->withCurrency('USD') - ->withEcommerceInfo($this->ecommerceInfo) - ->withAddress($address) - ->withInvoiceNumber('123456') - ->withAllowDuplicates(true) - ->execute(); - - $this->assertNotNull($response); - $this->assertEquals('00', $response->responseCode); - } - - public function test014ChargeJcb() - { - $address = new Address(); - $address->streetAddress1 = '6860 Dallas Pkwy'; - $address->postalCode = '750241234'; - - $card = new CreditCardData(); - $card->number = '3566007770007321'; - $card->expMonth = '12'; - $card->expYear = TestCards::validCardExpYear(); - $card->cvn = '123'; - - $response = $card->charge(17.05) - ->withCurrency('USD') - ->withEcommerceInfo($this->ecommerceInfo) - ->withAddress($address) - ->withInvoiceNumber('123456') - ->withAllowDuplicates(true) - ->execute(); - - $this->assertNotNull($response); - $this->assertEquals('00', $response->responseCode); - } - - public function test011bChargeMasterCard() - { - $address = new Address(); - $address->streetAddress1 = '6860'; - $address->postalCode = '75024'; - - $card = TestCards::masterCardSeries2Manual(); - - $response = $card->charge(17.02) - ->withCurrency('USD') - ->withEcommerceInfo($this->ecommerceInfo) - ->withAddress($address) - ->withInvoiceNumber('123456') - ->withAllowDuplicates(true) - ->execute(); - - $this->assertNotNull($response); - $this->assertEquals('00', $response->responseCode); - } - - // AUTHORIZATION - - - public function test015AuthorizationVisa() - { - $address = new Address(); - $address->streetAddress1 = '6860 Dallas Pkwy'; - $address->postalCode = '75024'; - - $card = TestCards::visaManual(); - - $response = $card->authorize(17.06) - ->withCurrency('USD') - ->withEcommerceInfo($this->ecommerceInfo) - ->withAddress($address) - ->withInvoiceNumber('123456') - ->withAllowDuplicates(true) - ->execute(); - - $this->assertNotNull($response); - $this->assertEquals('00', $response->responseCode); - - // test case 15b - $capture = $response->capture()->execute(); - - $this->assertNotNull($capture); - $this->assertEquals('00', $capture->responseCode); - } - - public function test016AuthorizationMasterCard() - { - $address = new Address(); - $address->streetAddress1 = '6860 Dallas Pkwy'; - $address->postalCode = '750241234'; - - $card = TestCards::masterCardManual(); - - $response = $card->authorize(17.07) - ->withCurrency('USD') - ->withEcommerceInfo($this->ecommerceInfo) - ->withAddress($address) - ->withInvoiceNumber('123456') - ->withAllowDuplicates(true) - ->execute(); - - $this->assertNotNull($response); - $this->assertEquals('00', $response->responseCode); - - // test case 16b - $capture = $response->capture()->execute(); - - $this->assertNotNull($capture); - $this->assertEquals('00', $capture->responseCode); - } - - public function test017AuthorizationDiscover() - { - $address = new Address(); - $address->streetAddress1 = '6860'; - $address->postalCode = '75024'; - - $card = TestCards::discoverManual(); - - $response = $card->authorize(17.08) - ->withCurrency('USD') - ->withEcommerceInfo($this->ecommerceInfo) - ->withAddress($address) - ->withInvoiceNumber('123456') - ->withAllowDuplicates(true) - ->execute(); - - $this->assertNotNull($response); - $this->assertEquals('00', $response->responseCode); - } - - public function test016bAuthorizationMasterCard() - { - $address = new Address(); - $address->streetAddress1 = '6860'; - $address->postalCode = '75024'; - - $card = TestCards::masterCardSeries2Manual(); - - $response = $card->authorize(17.02) - ->withCurrency('USD') - ->withEcommerceInfo($this->ecommerceInfo) - ->withAddress($address) - ->withInvoiceNumber('123456') - ->withAllowDuplicates(true) - ->execute(); - - $this->assertNotNull($response); - $this->assertEquals('00', $response->responseCode); - } - - // PARTIALLY APPROVED SALE - - public function test018PartialApprovalVisa() - { - $address = new Address(); - $address->streetAddress1 = '6860'; - $address->postalCode = '75024'; - - $card = TestCards::visaManual(); - - $response = $card->charge(130) - ->withCurrency('USD') - ->withEcommerceInfo($this->ecommerceInfo) - ->withAddress($address) - ->withInvoiceNumber('123456') - ->withAllowPartialAuth(true) - ->execute(); - - $this->assertNotNull($response); - $this->assertEquals('10', $response->responseCode); - $this->assertEquals('110.00', $response->authorizedAmount); - } - - public function test019PartialApprovalDiscover() - { - $address = new Address(); - $address->streetAddress1 = '6860'; - $address->postalCode = '75024'; - - $card = TestCards::discoverManual(); - - $response = $card->charge(145) - ->withCurrency('USD') - ->withEcommerceInfo($this->ecommerceInfo) - ->withAddress($address) - ->withInvoiceNumber('123456') - ->withAllowPartialAuth(true) - ->execute(); - - $this->assertNotNull($response); - $this->assertEquals('10', $response->responseCode); - $this->assertEquals('65.00', $response->authorizedAmount); - } - - public function test020PartialApprovalMasterCard() - { - $address = new Address(); - $address->streetAddress1 = '6860'; - $address->postalCode = '75024'; - - $card = TestCards::visaManual(); - - $response = $card->charge(155) - ->withCurrency('USD') - ->withEcommerceInfo($this->ecommerceInfo) - ->withAddress($address) - ->withInvoiceNumber('123456') - ->withAllowPartialAuth(true) - ->execute(); - - $this->assertNotNull($response); - $this->assertEquals('10', $response->responseCode); - $this->assertEquals('100.00', $response->authorizedAmount); - - // test case 36 - $void = $response->void()->execute(); - - $this->assertNotNull($void); - $this->assertEquals('00', $void->responseCode); - } - /// LEVEL II CORPORATE PURCHASE CARD - - public function test021LevelIIResponseB() - { - $address = new Address(); - $address->streetAddress1 = '6860 Dallas Pkwy'; - $address->postalCode = '750241234'; - - $card = TestCards::visaManual(); - - $response = $card->charge(112.34) - ->withCurrency('USD') - ->withInvoiceNumber('123456') - ->withAddress($address) - ->withCommercialRequest(true) - ->withEcommerceInfo($this->ecommerceInfo) - ->withAllowDuplicates(true) - ->execute(); - - $this->assertEquals(true, $response != null); - $this->assertEquals('00', $response->responseCode); - $this->assertEquals('B', $response->commercialIndicator); - - $cpcResponse = $response->edit() - ->withPoNumber('9876543210') - ->withTaxType(TaxType::NOT_USED) - ->execute(); - - $this->assertEquals(true, $cpcResponse != null); - $this->assertEquals('00', $cpcResponse->responseCode); - } - - public function test022LevelIIResponseB() - { - $address = new Address(); - $address->streetAddress1 = '6860'; - $address->postalCode = '750241234'; - - $card = TestCards::visaManual(); - - $response = $card->charge(112.34) - ->withCurrency('USD') - ->withInvoiceNumber('123456') - ->withAddress($address) - ->withCommercialRequest(true) - ->withEcommerceInfo($this->ecommerceInfo) - ->withAllowDuplicates(true) - ->execute(); - - $this->assertEquals(true, $response != null); - $this->assertEquals('00', $response->responseCode); - $this->assertEquals('B', $response->commercialIndicator); - - $cpcResponse = $response->edit() - ->withTaxType(TaxType::SALES_TAX) - ->withTaxAmount(1.00) - ->execute(); - - $this->assertEquals(true, $cpcResponse != null); - $this->assertEquals('00', $cpcResponse->responseCode); - } - - public function test023LevelIIResponseR() - { - $address = new Address(); - $address->streetAddress1 = '6860'; - $address->postalCode = '75024'; - - $card = TestCards::visaManual(); - - $response = $card->charge(123.45) - ->withCurrency('USD') - ->withInvoiceNumber('123456') - ->withAddress($address) - ->withCommercialRequest(true) - ->withEcommerceInfo($this->ecommerceInfo) - ->execute(); - - $this->assertEquals(true, $response != null); - $this->assertEquals('00', $response->responseCode); - $this->assertEquals('R', $response->commercialIndicator); - - $cpcResponse = $response->edit() - ->withTaxType(TaxType::TAX_EXEMPT) - ->execute(); - - $this->assertEquals(true, $cpcResponse != null); - $this->assertEquals('00', $cpcResponse->responseCode); - } - - public function test024LevelIIResponseS() - { - $address = new Address(); - $address->streetAddress1 = '6860'; - $address->postalCode = '75024'; - - $card = TestCards::visaManual(); - - $response = $card->charge(134.56) - ->withCurrency('USD') - ->withInvoiceNumber('123456') - ->withAddress($address) - ->withCommercialRequest(true) - ->withEcommerceInfo($this->ecommerceInfo) - ->execute(); - - $this->assertEquals(true, $response != null); - $this->assertEquals('00', $response->responseCode); - $this->assertEquals('S', $response->commercialIndicator); - - $cpcResponse = $response->edit() - ->withPoNumber('9876543210') - ->withTaxType(TaxType::SALES_TAX) - ->withTaxAmount(1.00) - ->execute(); - - $this->assertEquals(true, $cpcResponse != null); - $this->assertEquals('00', $cpcResponse->responseCode); - } - - public function test025LevelIIResponseS() - { - $address = new Address(); - $address->streetAddress1 = '6860'; - $address->postalCode = '75024'; - - $card = TestCards::masterCardManual(); - - $response = $card->charge(111.06) - ->withCurrency('USD') - ->withInvoiceNumber('123456') - ->withAddress($address) - ->withCommercialRequest(true) - ->withEcommerceInfo($this->ecommerceInfo) - ->execute(); - - $this->assertEquals(true, $response != null); - $this->assertEquals('00', $response->responseCode); - $this->assertEquals('S', $response->commercialIndicator); - - $cpcResponse = $response->edit() - ->withPoNumber('9876543210') - ->withTaxType(TaxType::NOT_USED) - ->execute(); - - $this->assertEquals(true, $cpcResponse != null); - $this->assertEquals('00', $cpcResponse->responseCode); - } - - public function test026LevelIIResponseS() - { - $address = new Address(); - $address->streetAddress1 = '6860'; - $address->postalCode = '75024'; - - $card = TestCards::masterCardManual(); - - $response = $card->charge(111.07) - ->withCurrency('USD') - ->withInvoiceNumber('123456') - ->withAddress($address) - ->withCommercialRequest(true) - ->withEcommerceInfo($this->ecommerceInfo) - ->execute(); - - $this->assertEquals(true, $response != null); - $this->assertEquals('00', $response->responseCode); - $this->assertEquals('S', $response->commercialIndicator); - - $cpcResponse = $response->edit() - ->withTaxType(TaxType::SALES_TAX) - ->withTaxAmount(1.00) - ->execute(); - - $this->assertEquals(true, $cpcResponse != null); - $this->assertEquals('00', $cpcResponse->responseCode); - } - - public function test027LevelIIResponseS() - { - $address = new Address(); - $address->streetAddress1 = '6860'; - $address->postalCode = '75024'; - - $card = TestCards::masterCardManual(); - - $response = $card->charge(111.08) - ->withCurrency('USD') - ->withInvoiceNumber('123456') - ->withAddress($address) - ->withCommercialRequest(true) - ->withEcommerceInfo($this->ecommerceInfo) - ->execute(); - - $this->assertEquals(true, $response != null); - $this->assertEquals('00', $response->responseCode); - $this->assertEquals('S', $response->commercialIndicator); - - $cpcResponse = $response->edit() - ->withPoNumber('9876543210') - ->withTaxType(TaxType::SALES_TAX) - ->withTaxAmount(1.00) - ->execute(); - - $this->assertEquals(true, $cpcResponse != null); - $this->assertEquals('00', $cpcResponse->responseCode); - } - - public function test028LevelIIResponseS() - { - $address = new Address(); - $address->streetAddress1 = '6860'; - $address->postalCode = '75024'; - - $card = TestCards::masterCardManual(); - - $response = $card->charge(111.09) - ->withCurrency('USD') - ->withInvoiceNumber('123456') - ->withAddress($address) - ->withCommercialRequest(true) - ->withEcommerceInfo($this->ecommerceInfo) - ->execute(); - - $this->assertEquals(true, $response != null); - $this->assertEquals('00', $response->responseCode); - $this->assertEquals('S', $response->commercialIndicator); - - $cpcResponse = $response->edit() - ->withPoNumber('9876543210') - ->withTaxType(TaxType::TAX_EXEMPT) - ->execute(); - - $this->assertEquals(true, $cpcResponse != null); - $this->assertEquals('00', $cpcResponse->responseCode); - } - - public function test029LevelIINoResponse() - { - $address = new Address(); - $address->streetAddress1 = '6860'; - $address->postalCode = '75024'; - - $card = TestCards::amexManual(); - - $response = $card->charge(111.10) - ->withCurrency('USD') - ->withInvoiceNumber('123456') - ->withAddress($address) - ->withCommercialRequest(true) - ->withEcommerceInfo($this->ecommerceInfo) - ->execute(); - - $this->assertEquals(true, $response != null); - $this->assertEquals('00', $response->responseCode); - $this->assertEquals('0', $response->commercialIndicator); - - $cpcResponse = $response->edit() - ->withPoNumber('9876543210') - ->withTaxType(TaxType::NOT_USED) - ->execute(); - - $this->assertEquals(true, $cpcResponse != null); - $this->assertEquals('00', $cpcResponse->responseCode); - } - - public function test030LevelIINoResponse() - { - $address = new Address(); - $address->streetAddress1 = '6860'; - $address->postalCode = '750241234'; - - $card = TestCards::amexManual(); - - $response = $card->charge(111.11) - ->withCurrency('USD') - ->withInvoiceNumber('123456') - ->withAddress($address) - ->withCommercialRequest(true) - ->withEcommerceInfo($this->ecommerceInfo) - ->execute(); - - $this->assertEquals(true, $response != null); - $this->assertEquals('00', $response->responseCode); - $this->assertEquals('0', $response->commercialIndicator); - - $cpcResponse = $response->edit() - ->withTaxType(TaxType::SALES_TAX) - ->withTaxAmount(1.00) - ->execute(); - - $this->assertEquals(true, $cpcResponse != null); - $this->assertEquals('00', $cpcResponse->responseCode); - } - - public function test031LevelIINoResponse() - { - $address = new Address(); - $address->streetAddress1 = '6860'; - $address->postalCode = '75024'; - - $card = TestCards::amexManual(); - - $response = $card->charge(111.12) - ->withCurrency('USD') - ->withInvoiceNumber('123456') - ->withAddress($address) - ->withCommercialRequest(true) - ->withEcommerceInfo($this->ecommerceInfo) - ->execute(); - - $this->assertEquals(true, $response != null); - $this->assertEquals('00', $response->responseCode); - $this->assertEquals('0', $response->commercialIndicator); - - $cpcResponse = $response->edit() - ->withPoNumber('9876543210') - ->withTaxType(TaxType::SALES_TAX) - ->withTaxAmount(1.00) - ->execute(); - - $this->assertEquals(true, $cpcResponse != null); - $this->assertEquals('00', $cpcResponse->responseCode); - } - - public function test032LevelIINoResponse() - { - $address = new Address(); - $address->streetAddress1 = '6860'; - $address->postalCode = '75024'; - - $card = TestCards::amexManual(); - - $response = $card->charge(111.13) - ->withCurrency('USD') - ->withInvoiceNumber('123456') - ->withAddress($address) - ->withCommercialRequest(true) - ->withEcommerceInfo($this->ecommerceInfo) - ->execute(); - - $this->assertEquals(true, $response != null); - $this->assertEquals('00', $response->responseCode); - $this->assertEquals('0', $response->commercialIndicator); - - $cpcResponse = $response->edit() - ->withPoNumber('9876543210') - ->withTaxType(TaxType::TAX_EXEMPT) - ->execute(); - - $this->assertEquals(true, $cpcResponse != null); - $this->assertEquals('00', $cpcResponse->responseCode); - } - - /// PRIOR / VOICE AUTHORIZATION - - public function test033OfflineSale() - { - $card = TestCards::visaManual(); - - $response = $card->charge(17.10) - ->withCurrency('USD') - ->withModifier(TransactionModifier::OFFLINE) - ->withOfflineAuthCode('654321') - ->withInvoiceNumber('123456') - ->withEcommerceInfo($this->ecommerceInfo) - ->execute(); - - $this->assertEquals(true, $response != null); - $this->assertEquals('00', $response->responseCode); - } - - public function test033OfflineAuthorization() - { - $card = TestCards::visaManual(); - - $response = $card->authorize(17.10) - ->withCurrency('USD') - ->withModifier(TransactionModifier::OFFLINE) - ->withOfflineAuthCode('654321') - ->withInvoiceNumber('123456') - ->withEcommerceInfo($this->ecommerceInfo) - ->execute(); - - $this->assertEquals(true, $response != null); - $this->assertEquals('00', $response->responseCode); - } - - /// RETURN - - public function test034OfflineCreditReturn() - { - $card = TestCards::masterCardManual(); - - $response = $card->refund(15.15) - ->withCurrency('USD') - ->withInvoiceNumber('123456') - ->withEcommerceInfo($this->ecommerceInfo) - ->execute(); - - $this->assertEquals(true, $response != null); - $this->assertEquals('00', $response->responseCode); - } - - public function test034bOfflineCreditReturn() - { - $card = TestCards::masterCardManual(); - - $response = $card->refund(15.16) - ->withCurrency('USD') - ->withInvoiceNumber('123456') - ->withEcommerceInfo($this->ecommerceInfo) - ->execute(); - - $this->assertEquals(true, $response != null); - $this->assertEquals('00', $response->responseCode); - } - - /// ONLINE VOID / REVERSAL - - public function test035VoidTest10() - { - // see test 010 - } - - public function test036VoidTest20() - { - // see test 020 - } - - /// Time Out Reversal - public function test036bTimeoutReversal() - { - $sale = TestCards::visaManual()->charge(911) - ->withCurrency('USD') - ->withInvoiceNumber('123456') - ->withClientTransactionId('987321654') - ->withEcommerceInfo($this->ecommerceInfo) - ->execute(); - - $this->assertEquals(true, $sale != null); - $this->assertEquals('91', $sale->responseCode); - - $response = Transaction::fromId(null, PaymentMethodType::CREDIT); - $response->clientTransactionId = '987321654'; - - $this->expectException(GatewayException::class); - $response->reverse(911)->execute(); - } - - /// One time bill payment - - public function test010ChargeVisaOneTime() - { - $address = new Address(); - $address->streetAddress1 = '6860 Dallas Pkwy'; - $address->postalCode = '75024'; - - $card = null; - if ($this->useTokens) { - $card = new CreditCardData(); - $card->token = static::$visaToken; - } else { - $card = TestCards::visaManual(); - } - - $response = $card->charge(13.11) - ->withCurrency('USD') - ->withAddress($address) - ->withInvoiceNumber('123456') - ->withOneTimePayment(true) - ->withAllowDuplicates(true) - ->execute(); - - $this->assertEquals(true, $response != null); - $this->assertEquals('00', $response->responseCode); - - $void = $response->void()->execute(); - - $this->assertEquals(true, $void != null); - $this->assertEquals('00', $void->responseCode); - } - - public function test011ChargeMasterCardOneTime() - { - $address = new Address(); - $address->streetAddress1 = '6860'; - $address->postalCode = '750241234'; - - $card = null; - if ($this->useTokens) { - $card = new CreditCardData(); - $card->token = static::$mastercardToken; - } else { - $card = TestCards::masterCardManual(); - } - - $response = $card->charge(13.12) - ->withCurrency('USD') - ->withAddress($address) - ->withInvoiceNumber('123456') - ->withOneTimePayment(true) - ->withAllowDuplicates(true) - ->execute(); - - $this->assertEquals(true, $response != null); - $this->assertEquals('00', $response->responseCode); - } - - public function test012ChargeDiscoverOneTime() - { - $address = new Address(); - $address->streetAddress1 = '6860'; - $address->postalCode = '75024'; - - $card = null; - if ($this->useTokens) { - $card = new CreditCardData(); - $card->token = static::$discoverToken; - } else { - $card = TestCards::discoverManual(); - } - - $response = $card->charge(13.13) - ->withCurrency('USD') - ->withAddress($address) - ->withInvoiceNumber('123456') - ->withOneTimePayment(true) - ->withAllowDuplicates(true) - ->execute(); - - $this->assertEquals(true, $response != null); - $this->assertEquals('00', $response->responseCode); - } - - public function test013ChargeAmexOneTime() - { - $address = new Address(); - $address->streetAddress1 = '6860'; - $address->postalCode = '75024'; - - $card = null; - if ($this->useTokens) { - $card = new CreditCardData(); - $card->token = static::$amexToken; - } else { - $card = TestCards::amexManual(); - } - - $response = $card->charge(13.14) - ->withCurrency('USD') - ->withAddress($address) - ->withInvoiceNumber('123456') - ->withOneTimePayment(true) - ->withAllowDuplicates(true) - ->execute(); - - $this->assertEquals(true, $response != null); - $this->assertEquals('00', $response->responseCode); - } - - public function test014ChargeJcbOneTime() - { - $address = new Address(); - $address->streetAddress1 = '6860'; - $address->postalCode = '75024'; - - $card = new CreditCardData(); - $card->number = '3566007770007321'; - $card->expMonth = '12'; - $card->expYear = TestCards::validCardExpYear(); - $card->cvn = '123'; - - $response = $card->charge(13.15) - ->withCurrency('USD') - ->withAddress($address) - ->withInvoiceNumber('123456') - ->withOneTimePayment(true) - ->withAllowDuplicates(true) - ->execute(); - - $this->assertEquals(true, $response != null); - $this->assertEquals('00', $response->responseCode); - } - - /// ADVANCED FRAUD SCREENING - - /** - * TODO: Change code assertions when AFS is enabled on account - */ - public function test037FraudPreventionSale() - { - $card = TestCards::visaManual(); - - $response = $card->charge(15000) - ->withCurrency('USD') - ->execute(); - $this->assertEquals(true, $response != null); - $this->assertEquals('00', $response->responseCode); - // $this->assertEquals('FR', $response->responseCode); - } - - /** - * TODO: Change code assertions when AFS is enabled on account - */ - public function test038FraudPreventionReturn() - { - $card = TestCards::visaManual(); - - $response = $card->refund(15000) - ->withCurrency('USD') - ->execute(); - $this->assertEquals(true, $response != null); - $this->assertEquals('00', $response->responseCode); - // $this->assertEquals('41', $response->responseCode); - } - - /// ONE CARD - GSB CARD FUNCTIONS - - /// BALANCE INQUIRY - - public function test037BalanceInquiryGsb() - { - if (false === $this->usePrepaid) { - $this->markTestSkipped('GSB not configured'); - } - - $address = new Address(); - $address->streetAddress1 = '6860'; - $address->postalCode = '75024'; - - $card = TestCards::gsbManual(); - - $response = $card->balanceInquiry() - ->withAddress($address) - ->execute(); - - $this->assertEquals(true, $response != null); - $this->assertEquals('00', $response->responseCode); - } - - /// ADD VALUE - - public function test038AddValueGsb() - { - if (false === $this->usePrepaid) { - $this->markTestSkipped('GSB not configured'); - } - - $card = new CreditTrackData(); - $card->value = '%B6277220572999800^ / ^49121010557010000016000000?F;6277220572999800=49121010557010000016?'; - - $response = $card->addValue(15.00) - ->withCurrency('USD') - ->execute(); - - $this->assertEquals(true, $response != null); - $this->assertEquals('00', $response->responseCode); - } - - /// SALE - - public function test039ChargeGsb() - { - if (false === $this->usePrepaid) { - $this->markTestSkipped('GSB not configured'); - } - - $address = new Address(); - $address->streetAddress1 = '6860'; - $address->postalCode = '75024'; - - $card = TestCards::gsbManual(); - - $response = $card->charge(2.05) - ->withCurrency('USD') - ->withAddress($address) - ->withInvoiceNumber('123456') - ->execute(); - - $this->assertEquals(true, $response != null); - $this->assertEquals('00', $response->responseCode); - - $voidResponse = $response->void() - ->execute(); - $this->assertEquals(true, $voidResponse != null); - $this->assertEquals('00', $voidResponse->responseCode); - } - - public function test040ChargeGsb() - { - if (false === $this->usePrepaid) { - $this->markTestSkipped('GSB not configured'); - } - - $address = new Address(); - $address->streetAddress1 = '6860'; - $address->postalCode = '75024'; - - $card = TestCards::gsbManual(); - - $response = $card->charge(2.10) - ->withCurrency('USD') - ->withAddress($address) - ->withInvoiceNumber('123456') - ->execute(); - - $this->assertEquals(true, $response != null); - $this->assertEquals('00', $response->responseCode); - } - - /// ONLINE VOID / REVERSAL - - public function test041VoidGsb() - { - // see test 039 - } - - /// HMS GIFT - REWARDS - - /// ACTIVATE - - public function test042ActivateGift1() - { - $card = TestCards::giftCard1Swipe(); - - $response = $card->activate(6.00) - ->execute(); - $this->assertEquals(true, $response != null); - $this->assertEquals('00', $response->responseCode); - } - - public function test043ActivateGift2() - { - - $card = TestCards::giftCard2Manual(); - - $response = $card->activate(7.00) - ->execute(); - $this->assertEquals(true, $response != null); - $this->assertEquals('00', $response->responseCode); - } - - /// LOAD / ADD VALUE - - public function test044AddValueGift1() - { - $card = TestCards::giftCard1Swipe(); - - $response = $card->addValue(8.00) - ->withCurrency('USD') - ->execute(); - $this->assertEquals(true, $response != null); - $this->assertEquals('00', $response->responseCode); - } - - public function test045AddValueGift2() - { - $card = TestCards::giftCard2Manual(); - - $response = $card->addValue(9.00) - ->withCurrency('USD') - ->execute(); - $this->assertEquals(true, $response != null); - $this->assertEquals('00', $response->responseCode); - } - - /// BALANCE INQUIRY - - public function test046BalanceInquiryGift1() - { - $card = TestCards::giftCard1Swipe(); - - $response = $card->balanceInquiry() - ->execute(); - $this->assertEquals(true, $response != null); - $this->assertEquals('00', $response->responseCode); - $this->assertEquals('10.00', $response->balanceAmount); - } - - public function test047BalanceInquiryGift2() - { - $card = TestCards::giftCard2Manual(); - - $response = $card->balanceInquiry() - ->execute(); - $this->assertEquals(true, $response != null); - $this->assertEquals('00', $response->responseCode); - $this->assertEquals('10.00', $response->balanceAmount); - } - - /// REPLACE / TRANSFER - - public function test048ReplaceGift1() - { - $card = TestCards::giftCard1Swipe(); - - $response = $card->replaceWith(TestCards::giftCard2Manual()) - ->execute(); - - $this->assertEquals(true, $response != null); - $this->assertEquals('00', $response->responseCode); - $this->assertEquals('10.00', $response->balanceAmount); - } - - public function test049ReplaceGift2() - { - $card = TestCards::giftCard2Manual(); - - $response = $card->replaceWith(TestCards::giftCard1Swipe()) - ->execute(); - - $this->assertEquals(true, $response != null); - $this->assertEquals('00', $response->responseCode); - $this->assertEquals('10.00', $response->balanceAmount); - } - - /// SALE / REDEEM - - public function test050SaleGift1() - { - $card = TestCards::giftCard1Swipe(); - - $response = $card->charge(1.00) - ->withCurrency('USD') - ->execute(); - $this->assertEquals(true, $response != null); - $this->assertEquals('00', $response->responseCode); - } - - public function test051SaleGift2() - { - $card = TestCards::giftCard2Manual(); - - $response = $card->charge(2.00) - ->withCurrency('USD') - ->execute(); - $this->assertEquals(true, $response != null); - $this->assertEquals('00', $response->responseCode); - } - - public function test052SaleGift1Void() - { - $card = TestCards::giftCard1Swipe(); - - $response = $card->charge(3.00) - ->withCurrency('USD') - ->execute(); - $this->assertEquals(true, $response != null); - $this->assertEquals('00', $response->responseCode); - - $voidResponse = $response->void() - ->execute(); - $this->assertEquals(true, $voidResponse != null); - $this->assertEquals('00', $voidResponse->responseCode); - } - - public function test053SaleGift2Reversal() - { - $card = TestCards::giftCard2Manual(); - - $response = $card->charge(4.00) - ->withCurrency('USD') - ->execute(); - $this->assertEquals(true, $response != null); - $this->assertEquals('00', $response->responseCode); - - $reversalResponse = $response->reverse(4.00) - ->execute(); - $this->assertEquals(true, $reversalResponse != null); - $this->assertEquals('00', $reversalResponse->responseCode); - } - - /// VOID - - public function test054VoidGift() - { - // see test 052 - } - - /// REVERSAL - - public function test055ReversalGift() - { - // see test 053 - } - - public function test056ReversalGift2() - { - $card = TestCards::giftCard2Manual(); - - $reversalResponse = $card->reverse(2.00) - ->execute(); - $this->assertEquals(true, $reversalResponse != null); - $this->assertEquals('00', $reversalResponse->responseCode); - } - - /// DEACTIVATE - - public function test057DeactivateGift1() - { - $card = TestCards::giftCard1Swipe(); - - $response = $card->deactivate() - ->execute(); - $this->assertEquals(true, $response != null); - $this->assertEquals('00', $response->responseCode); - } - - /// RECEIPTS MESSAGING - - public function test058ReceiptsMessaging() - { - return; # print and scan receipt for test 51 - } - - /// REWARD - - /// BALANCE INQUIRY - - public function test059BalanceInquiryRewards1() - { - $card = TestCards::giftCard1Swipe(); - - $response = $card->balanceInquiry() - ->execute(); - $this->assertEquals(true, $response != null); - $this->assertEquals('00', $response->responseCode); - $this->assertTrue($response->pointsBalanceAmount > 0); - } - - public function test060BalanceInquiryRewards2() - { - $card = TestCards::giftCard2Manual(); - - $response = $card->balanceInquiry() - ->execute(); - $this->assertEquals(true, $response != null); - $this->assertEquals('00', $response->responseCode); - $this->assertTrue($response->pointsBalanceAmount > 0); - } - - /// ALIAS - - public function test061CreateAliasGift1() - { - $response = GiftCard::create('9725550100'); - - $this->assertEquals(true, $response != null); - } - - public function test062CreateAliasGift2() - { - $response = GiftCard::create('9725550100'); - - $this->assertEquals(true, $response != null); - } - - public function test063AddAliasGift1() - { - $card = TestCards::giftCard1Swipe(); - - $response = $card->addAlias('2145550199') - ->execute(); - $this->assertEquals(true, $response != null); - $this->assertEquals('00', $response->responseCode); - } - - public function test064AddAliasGift2() - { - $card = TestCards::giftCard2Manual(); - - $response = $card->addAlias('2145550199') - ->execute(); - $this->assertEquals(true, $response != null); - $this->assertEquals('00', $response->responseCode); - } - - public function test065DeleteAliasGift1() - { - $card = TestCards::giftCard1Swipe(); - - $response = $card->removeAlias('2145550199') - ->execute(); - $this->assertEquals(true, $response != null); - $this->assertEquals('00', $response->responseCode); - } - - /// SALE / REDEEM - - public function test066RedeemPointsGift1() - { - $card = TestCards::giftCard1Swipe(); - - $response = $card->charge(100) - ->withCurrency('POINTS') - ->execute(); - $this->assertEquals(true, $response != null); - $this->assertEquals('00', $response->responseCode); - } - - public function test067RedeemPointsGift2() - { - $card = TestCards::giftCard2Manual(); - - $response = $card->charge(200) - ->withCurrency('POINTS') - ->execute(); - $this->assertEquals(true, $response != null); - $this->assertEquals('00', $response->responseCode); - } - - public function test068RedeemPointsGift2() - { - $card = new GiftCard(); - $card->alias = '9725550100'; - - $response = $card->charge(300) - ->withCurrency('POINTS') - ->execute(); - $this->assertEquals(true, $response != null); - $this->assertEquals('00', $response->responseCode); - } - - /// REWARDS - - public function test069RewardsGift1() - { - $card = TestCards::giftCard1Swipe(); - - $response = $card->rewards(10) - ->execute(); - $this->assertEquals(true, $response != null); - $this->assertEquals('00', $response->responseCode); - } - - public function test070RewardsGift2() - { - $card = TestCards::giftCard2Manual(); - - $response = $card->rewards(11) - ->execute(); - $this->assertEquals(true, $response != null); - $this->assertEquals('00', $response->responseCode); - } - - /// REPLACE / TRANSFER - - public function test071ReplaceGift1() - { - $card = TestCards::giftCard1Swipe(); - - $response = $card->replaceWith(TestCards::giftCard2Manual()) - ->execute(); - $this->assertEquals(true, $response != null); - $this->assertEquals('00', $response->responseCode); - } - - public function test072ReplaceGift2() - { - $card = TestCards::giftCard2Manual(); - - $response = $card->replaceWith(TestCards::giftCard1Swipe()) - ->execute(); - $this->assertEquals(true, $response != null); - $this->assertEquals('00', $response->responseCode); - } - - /// DEACTIVATE - - public function test073DeactivateGift1() - { - $card = TestCards::giftCard1Swipe(); - - $response = $card->deactivate() - ->execute(); - $this->assertEquals(true, $response != null); - $this->assertEquals('00', $response->responseCode); - } - - public function test074DeactivateGift2() - { - $card = TestCards::giftCard2Manual(); - - $response = $card->deactivate() - ->execute(); - $this->assertEquals(true, $response != null); - $this->assertEquals('00', $response->responseCode); - } - - /// RECEIPTS MESSAGING - - public function test075ReceiptsMessaging() - { - return; # print and scan receipt for test 51 - } - - /// CLOSE BATCH - - public function test999CloseBatch() - { - try { - $response = BatchService::closeBatch(); - $this->assertNotNull($response); - // printf('batch id: %s', $response->id); - // printf('sequence number: %s', $response->sequenceNumber); - } catch (ApiException $e) { - if (false === strpos($e->getMessage(), static::BATCH_NOT_OPEN) - || false === strpos($e->getMessage(), static::NO_TRANS_IN_BATCH) - ) { - $this->fail($e->getMessage()); - } - } - } -} +secretApiKey = 'skapi_cert_MRCQAQBC_VQACBE0rFaZlbDDPieMGP06JDAtjyS7NQ'; + $config->serviceUrl = ($this->enableCryptoUrl) ? + 'https://cert.api2-c.heartlandportico.com/': + 'https://cert.api2.heartlandportico.com'; + return $config; + } + + protected function setup() + { + ServicesContainer::configureService($this->config()); + + $this->ecommerceInfo = new EcommerceInfo(); + $this->ecommerceInfo->channel = EcommerceChannel::MOTO; + } + + public function test000CloseBatch() + { + try { + $response = BatchService::closeBatch(); + $this->assertNotNull($response); + // print 'batch id: ' . $response->id . "\n"; + // print 'sequence number: ' . $response->sequenceNumber . "\n"; + } catch (ApiException $e) { + if (false === strpos($e->getMessage(), static::BATCH_NOT_OPEN) + && false === strpos($e->getMessage(), static::NO_TRANS_IN_BATCH) + ) { + $this->fail($e->getMessage()); + } + } + } + + public function test001VerifyVisa() + { + $card = new CreditCardData(); + $card->number = '4484958240202792'; + $card->expMonth = '12'; + $card->expYear = TestCards::validCardExpYear(); + + $response = $card->verify() + ->withRequestMultiUseToken($this->useTokens) + ->execute(); + + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode); + } + + public function test002VerifyMasterCard() + { + $card = new CreditCardData(); + $card->number = '5356083898949891'; + $card->expMonth = '12'; + $card->expYear = TestCards::validCardExpYear(); + + $response = $card->verify() + ->withRequestMultiUseToken($this->useTokens) + ->execute(); + + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode); + } + + public function test003VerifyDiscover() + { + $address = new Address(); + $address->postalCode = '75024'; + + $card = new CreditCardData(); + $card->number = '6223971100014620'; + $card->expMonth = '12'; + $card->expYear = TestCards::validCardExpYear(); + + $response = $card->verify() + ->withAddress($address) + ->withRequestMultiUseToken($this->useTokens) + ->execute(); + + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode); + } + + // StreetAddress verification + + public function test004VerifyAmex() + { + $address = new Address(); + $address->postalCode = '75024'; + + $card = new CreditCardData(); + $card->number = '345039962663847'; + $card->expMonth = '12'; + $card->expYear = TestCards::validCardExpYear(); + + $response = $card->verify() + ->withAddress($address) + ->withRequestMultiUseToken($this->useTokens) + ->execute(); + + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode); + } + + // Balance Inquiry (for prepaid card) + + public function test005BalanceInquiryVisa() + { + $card = new CreditCardData(); + $card->number = '4664383951958601'; + $card->expMonth = '12'; + $card->expYear = TestCards::validCardExpYear(); + + $response = $card->balanceInquiry()->execute(); + + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode, $response->responseMessage); + } + + // CREDIT SALE (for multi-use token only) + + public function test006ChargeVisaToken() + { + $address = new Address(); + $address->streetAddress1 = '6860 Dallas Pkwy'; + $address->postalCode = '75024'; + + $card = new CreditCardData(); + $card->number = '4012002000060016'; + $card->expMonth = '12'; + $card->expYear = TestCards::validCardExpYear(); + + $response = $card->charge(13.01) + ->withCurrency('USD') + ->withInvoiceNumber('123456') + ->withEcommerceInfo($this->ecommerceInfo) + ->withAddress($address) + ->withRequestMultiUseToken(true) + ->withAllowDuplicates(true) + ->execute(); + + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode); + static::$visaToken = $response->token; + } + + public function test007ChargeMasterCardToken() + { + $address = new Address(); + $address->streetAddress1 = '6860'; + $address->postalCode = '75024'; + + $card = new CreditCardData(); + $card->number = '5473500000000014'; + $card->expMonth = '12'; + $card->expYear = TestCards::validCardExpYear(); + $card->cvn = '123'; + + $response = $card->charge(13.02) + ->withCurrency('USD') + ->withInvoiceNumber('123456') + ->withEcommerceInfo($this->ecommerceInfo) + ->withAddress($address) + ->withRequestMultiUseToken(true) + ->withAllowDuplicates(true) + ->execute(); + + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode); + static::$mastercardToken = $response->token; + } + + public function test008ChargeDiscoverToken() + { + $address = new Address(); + $address->streetAddress1 = '6860'; + $address->postalCode = '750241234'; + + $card = new CreditCardData(); + $card->number = '6011000990156527'; + $card->expMonth = '12'; + $card->expYear = TestCards::validCardExpYear(); + $card->cvn = '123'; + + $response = $card->charge(13.03) + ->withCurrency('USD') + ->withInvoiceNumber('123456') + ->withEcommerceInfo($this->ecommerceInfo) + ->withAddress($address) + ->withRequestMultiUseToken(true) + ->withAllowDuplicates(true) + ->execute(); + + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode); + static::$discoverToken = $response->token; + } + + public function test009ChargeAmexToken() + { + $address = new Address(); + $address->streetAddress1 = '6860 Dallas Pkwy'; + $address->postalCode = '75024'; + + $card = new CreditCardData(); + $card->number = '372700699251018'; + $card->expMonth = '12'; + $card->expYear = TestCards::validCardExpYear(); + $card->cvn = '1234'; + + $response = $card->charge(13.04) + ->withCurrency('USD') + ->withInvoiceNumber('123456') + ->withEcommerceInfo($this->ecommerceInfo) + ->withAddress($address) + ->withRequestMultiUseToken(true) + ->withAllowDuplicates(true) + ->execute(); + + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode); + static::$amexToken = $response->token; + } + + // CREDIT SALE + + public function test010ChargeVisa() + { + $address = new Address(); + $address->streetAddress1 = '6860 Dallas Pkwy'; + $address->postalCode = '75024'; + + $card = null; + if ($this->useTokens) { + $card = new CreditCardData(); + $card->token = static::$visaToken; + } else { + $card = TestCards::visaManual(); + } + + $response = $card->charge(17.01) + ->withCurrency('USD') + ->withEcommerceInfo($this->ecommerceInfo) + ->withAddress($address) + ->withInvoiceNumber('123456') + ->withAllowDuplicates(true) + ->execute(); + + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode); + + // test case 35 + $void = $response->void()->execute(); + + $this->assertNotNull($void); + $this->assertEquals('00', $void->responseCode); + } + + public function test011ChargeMasterCard() + { + $address = new Address(); + $address->streetAddress1 = '6860'; + $address->postalCode = '75024'; + + $card = null; + if ($this->useTokens) { + $card = new CreditCardData(); + $card->token = static::$mastercardToken; + } else { + $card = TestCards::masterCardManual(); + } + + $response = $card->charge(17.02) + ->withCurrency('USD') + ->withEcommerceInfo($this->ecommerceInfo) + ->withAddress($address) + ->withInvoiceNumber('123456') + ->withAllowDuplicates(true) + ->execute(); + + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode); + } + + public function test012ChargeDiscover() + { + $address = new Address(); + $address->streetAddress1 = '6860'; + $address->postalCode = '750241234'; + + $card = null; + if ($this->useTokens) { + $card = new CreditCardData(); + $card->token = static::$discoverToken; + } else { + $card = TestCards::discoverManual(); + } + + $response = $card->charge(17.03) + ->withCurrency('USD') + ->withEcommerceInfo($this->ecommerceInfo) + ->withAddress($address) + ->withInvoiceNumber('123456') + ->withAllowDuplicates(true) + ->execute(); + + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode); + } + + public function test013ChargeAmex() + { + $address = new Address(); + $address->streetAddress1 = '6860 Dallas Pkwy'; + $address->postalCode = '75024'; + + $card = null; + if ($this->useTokens) { + $card = new CreditCardData(); + $card->token = static::$amexToken; + } else { + $card = TestCards::amexManual(); + } + + $response = $card->charge(17.04) + ->withCurrency('USD') + ->withEcommerceInfo($this->ecommerceInfo) + ->withAddress($address) + ->withInvoiceNumber('123456') + ->withAllowDuplicates(true) + ->execute(); + + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode); + } + + public function test014ChargeJcb() + { + $address = new Address(); + $address->streetAddress1 = '6860 Dallas Pkwy'; + $address->postalCode = '750241234'; + + $card = new CreditCardData(); + $card->number = '3566007770007321'; + $card->expMonth = '12'; + $card->expYear = TestCards::validCardExpYear(); + $card->cvn = '123'; + + $response = $card->charge(17.05) + ->withCurrency('USD') + ->withEcommerceInfo($this->ecommerceInfo) + ->withAddress($address) + ->withInvoiceNumber('123456') + ->withAllowDuplicates(true) + ->execute(); + + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode); + } + + public function test011bChargeMasterCard() + { + $address = new Address(); + $address->streetAddress1 = '6860'; + $address->postalCode = '75024'; + + $card = TestCards::masterCardSeries2Manual(); + + $response = $card->charge(17.02) + ->withCurrency('USD') + ->withEcommerceInfo($this->ecommerceInfo) + ->withAddress($address) + ->withInvoiceNumber('123456') + ->withAllowDuplicates(true) + ->execute(); + + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode); + } + + // AUTHORIZATION + + + public function test015AuthorizationVisa() + { + $address = new Address(); + $address->streetAddress1 = '6860 Dallas Pkwy'; + $address->postalCode = '75024'; + + $card = TestCards::visaManual(); + + $response = $card->authorize(17.06) + ->withCurrency('USD') + ->withEcommerceInfo($this->ecommerceInfo) + ->withAddress($address) + ->withInvoiceNumber('123456') + ->withAllowDuplicates(true) + ->execute(); + + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode); + + // test case 15b + $capture = $response->capture()->execute(); + + $this->assertNotNull($capture); + $this->assertEquals('00', $capture->responseCode); + } + + public function test016AuthorizationMasterCard() + { + $address = new Address(); + $address->streetAddress1 = '6860 Dallas Pkwy'; + $address->postalCode = '750241234'; + + $card = TestCards::masterCardManual(); + + $response = $card->authorize(17.07) + ->withCurrency('USD') + ->withEcommerceInfo($this->ecommerceInfo) + ->withAddress($address) + ->withInvoiceNumber('123456') + ->withAllowDuplicates(true) + ->execute(); + + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode); + + // test case 16b + $capture = $response->capture()->execute(); + + $this->assertNotNull($capture); + $this->assertEquals('00', $capture->responseCode); + } + + public function test017AuthorizationDiscover() + { + $address = new Address(); + $address->streetAddress1 = '6860'; + $address->postalCode = '75024'; + + $card = TestCards::discoverManual(); + + $response = $card->authorize(17.08) + ->withCurrency('USD') + ->withEcommerceInfo($this->ecommerceInfo) + ->withAddress($address) + ->withInvoiceNumber('123456') + ->withAllowDuplicates(true) + ->execute(); + + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode); + } + + public function test016bAuthorizationMasterCard() + { + $address = new Address(); + $address->streetAddress1 = '6860'; + $address->postalCode = '75024'; + + $card = TestCards::masterCardSeries2Manual(); + + $response = $card->authorize(17.02) + ->withCurrency('USD') + ->withEcommerceInfo($this->ecommerceInfo) + ->withAddress($address) + ->withInvoiceNumber('123456') + ->withAllowDuplicates(true) + ->execute(); + + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode); + } + + // PARTIALLY APPROVED SALE + + public function test018PartialApprovalVisa() + { + $address = new Address(); + $address->streetAddress1 = '6860'; + $address->postalCode = '75024'; + + $card = TestCards::visaManual(); + + $response = $card->charge(130) + ->withCurrency('USD') + ->withEcommerceInfo($this->ecommerceInfo) + ->withAddress($address) + ->withInvoiceNumber('123456') + ->withAllowPartialAuth(true) + ->execute(); + + $this->assertNotNull($response); + $this->assertEquals('10', $response->responseCode); + $this->assertEquals('110.00', $response->authorizedAmount); + } + + public function test019PartialApprovalDiscover() + { + $address = new Address(); + $address->streetAddress1 = '6860'; + $address->postalCode = '75024'; + + $card = TestCards::discoverManual(); + + $response = $card->charge(145) + ->withCurrency('USD') + ->withEcommerceInfo($this->ecommerceInfo) + ->withAddress($address) + ->withInvoiceNumber('123456') + ->withAllowPartialAuth(true) + ->execute(); + + $this->assertNotNull($response); + $this->assertEquals('10', $response->responseCode); + $this->assertEquals('65.00', $response->authorizedAmount); + } + + public function test020PartialApprovalMasterCard() + { + $address = new Address(); + $address->streetAddress1 = '6860'; + $address->postalCode = '75024'; + + $card = TestCards::visaManual(); + + $response = $card->charge(155) + ->withCurrency('USD') + ->withEcommerceInfo($this->ecommerceInfo) + ->withAddress($address) + ->withInvoiceNumber('123456') + ->withAllowPartialAuth(true) + ->execute(); + + $this->assertNotNull($response); + $this->assertEquals('10', $response->responseCode); + $this->assertEquals('100.00', $response->authorizedAmount); + + // test case 36 + $void = $response->void()->execute(); + + $this->assertNotNull($void); + $this->assertEquals('00', $void->responseCode); + } + /// LEVEL II CORPORATE PURCHASE CARD + + public function test021LevelIIResponseB() + { + $address = new Address(); + $address->streetAddress1 = '6860 Dallas Pkwy'; + $address->postalCode = '750241234'; + + $card = TestCards::visaManual(); + + $response = $card->charge(112.34) + ->withCurrency('USD') + ->withInvoiceNumber('123456') + ->withAddress($address) + ->withCommercialRequest(true) + ->withEcommerceInfo($this->ecommerceInfo) + ->withAllowDuplicates(true) + ->execute(); + + $this->assertEquals(true, $response != null); + $this->assertEquals('00', $response->responseCode); + $this->assertEquals('B', $response->commercialIndicator); + + $cpcResponse = $response->edit() + ->withPoNumber('9876543210') + ->withTaxType(TaxType::NOT_USED) + ->execute(); + + $this->assertEquals(true, $cpcResponse != null); + $this->assertEquals('00', $cpcResponse->responseCode); + } + + public function test022LevelIIResponseB() + { + $address = new Address(); + $address->streetAddress1 = '6860'; + $address->postalCode = '750241234'; + + $card = TestCards::visaManual(); + + $response = $card->charge(112.34) + ->withCurrency('USD') + ->withInvoiceNumber('123456') + ->withAddress($address) + ->withCommercialRequest(true) + ->withEcommerceInfo($this->ecommerceInfo) + ->withAllowDuplicates(true) + ->execute(); + + $this->assertEquals(true, $response != null); + $this->assertEquals('00', $response->responseCode); + $this->assertEquals('B', $response->commercialIndicator); + + $cpcResponse = $response->edit() + ->withTaxType(TaxType::SALES_TAX) + ->withTaxAmount(1.00) + ->execute(); + + $this->assertEquals(true, $cpcResponse != null); + $this->assertEquals('00', $cpcResponse->responseCode); + } + + public function test023LevelIIResponseR() + { + $address = new Address(); + $address->streetAddress1 = '6860'; + $address->postalCode = '75024'; + + $card = TestCards::visaManual(); + + $response = $card->charge(123.45) + ->withCurrency('USD') + ->withInvoiceNumber('123456') + ->withAddress($address) + ->withCommercialRequest(true) + ->withEcommerceInfo($this->ecommerceInfo) + ->execute(); + + $this->assertEquals(true, $response != null); + $this->assertEquals('00', $response->responseCode); + $this->assertEquals('R', $response->commercialIndicator); + + $cpcResponse = $response->edit() + ->withTaxType(TaxType::TAX_EXEMPT) + ->execute(); + + $this->assertEquals(true, $cpcResponse != null); + $this->assertEquals('00', $cpcResponse->responseCode); + } + + public function test024LevelIIResponseS() + { + $address = new Address(); + $address->streetAddress1 = '6860'; + $address->postalCode = '75024'; + + $card = TestCards::visaManual(); + + $response = $card->charge(134.56) + ->withCurrency('USD') + ->withInvoiceNumber('123456') + ->withAddress($address) + ->withCommercialRequest(true) + ->withEcommerceInfo($this->ecommerceInfo) + ->execute(); + + $this->assertEquals(true, $response != null); + $this->assertEquals('00', $response->responseCode); + $this->assertEquals('S', $response->commercialIndicator); + + $cpcResponse = $response->edit() + ->withPoNumber('9876543210') + ->withTaxType(TaxType::SALES_TAX) + ->withTaxAmount(1.00) + ->execute(); + + $this->assertEquals(true, $cpcResponse != null); + $this->assertEquals('00', $cpcResponse->responseCode); + } + + public function test025LevelIIResponseS() + { + $address = new Address(); + $address->streetAddress1 = '6860'; + $address->postalCode = '75024'; + + $card = TestCards::masterCardManual(); + + $response = $card->charge(111.06) + ->withCurrency('USD') + ->withInvoiceNumber('123456') + ->withAddress($address) + ->withCommercialRequest(true) + ->withEcommerceInfo($this->ecommerceInfo) + ->execute(); + + $this->assertEquals(true, $response != null); + $this->assertEquals('00', $response->responseCode); + $this->assertEquals('S', $response->commercialIndicator); + + $cpcResponse = $response->edit() + ->withPoNumber('9876543210') + ->withTaxType(TaxType::NOT_USED) + ->execute(); + + $this->assertEquals(true, $cpcResponse != null); + $this->assertEquals('00', $cpcResponse->responseCode); + } + + public function test026LevelIIResponseS() + { + $address = new Address(); + $address->streetAddress1 = '6860'; + $address->postalCode = '75024'; + + $card = TestCards::masterCardManual(); + + $response = $card->charge(111.07) + ->withCurrency('USD') + ->withInvoiceNumber('123456') + ->withAddress($address) + ->withCommercialRequest(true) + ->withEcommerceInfo($this->ecommerceInfo) + ->execute(); + + $this->assertEquals(true, $response != null); + $this->assertEquals('00', $response->responseCode); + $this->assertEquals('S', $response->commercialIndicator); + + $cpcResponse = $response->edit() + ->withTaxType(TaxType::SALES_TAX) + ->withTaxAmount(1.00) + ->execute(); + + $this->assertEquals(true, $cpcResponse != null); + $this->assertEquals('00', $cpcResponse->responseCode); + } + + public function test027LevelIIResponseS() + { + $address = new Address(); + $address->streetAddress1 = '6860'; + $address->postalCode = '75024'; + + $card = TestCards::masterCardManual(); + + $response = $card->charge(111.08) + ->withCurrency('USD') + ->withInvoiceNumber('123456') + ->withAddress($address) + ->withCommercialRequest(true) + ->withEcommerceInfo($this->ecommerceInfo) + ->execute(); + + $this->assertEquals(true, $response != null); + $this->assertEquals('00', $response->responseCode); + $this->assertEquals('S', $response->commercialIndicator); + + $cpcResponse = $response->edit() + ->withPoNumber('9876543210') + ->withTaxType(TaxType::SALES_TAX) + ->withTaxAmount(1.00) + ->execute(); + + $this->assertEquals(true, $cpcResponse != null); + $this->assertEquals('00', $cpcResponse->responseCode); + } + + public function test028LevelIIResponseS() + { + $address = new Address(); + $address->streetAddress1 = '6860'; + $address->postalCode = '75024'; + + $card = TestCards::masterCardManual(); + + $response = $card->charge(111.09) + ->withCurrency('USD') + ->withInvoiceNumber('123456') + ->withAddress($address) + ->withCommercialRequest(true) + ->withEcommerceInfo($this->ecommerceInfo) + ->execute(); + + $this->assertEquals(true, $response != null); + $this->assertEquals('00', $response->responseCode); + $this->assertEquals('S', $response->commercialIndicator); + + $cpcResponse = $response->edit() + ->withPoNumber('9876543210') + ->withTaxType(TaxType::TAX_EXEMPT) + ->execute(); + + $this->assertEquals(true, $cpcResponse != null); + $this->assertEquals('00', $cpcResponse->responseCode); + } + + public function test029LevelIINoResponse() + { + $address = new Address(); + $address->streetAddress1 = '6860'; + $address->postalCode = '75024'; + + $card = TestCards::amexManual(); + + $response = $card->charge(111.10) + ->withCurrency('USD') + ->withInvoiceNumber('123456') + ->withAddress($address) + ->withCommercialRequest(true) + ->withEcommerceInfo($this->ecommerceInfo) + ->execute(); + + $this->assertEquals(true, $response != null); + $this->assertEquals('00', $response->responseCode); + $this->assertEquals('0', $response->commercialIndicator); + + $cpcResponse = $response->edit() + ->withPoNumber('9876543210') + ->withTaxType(TaxType::NOT_USED) + ->execute(); + + $this->assertEquals(true, $cpcResponse != null); + $this->assertEquals('00', $cpcResponse->responseCode); + } + + public function test030LevelIINoResponse() + { + $address = new Address(); + $address->streetAddress1 = '6860'; + $address->postalCode = '750241234'; + + $card = TestCards::amexManual(); + + $response = $card->charge(111.11) + ->withCurrency('USD') + ->withInvoiceNumber('123456') + ->withAddress($address) + ->withCommercialRequest(true) + ->withEcommerceInfo($this->ecommerceInfo) + ->execute(); + + $this->assertEquals(true, $response != null); + $this->assertEquals('00', $response->responseCode); + $this->assertEquals('0', $response->commercialIndicator); + + $cpcResponse = $response->edit() + ->withTaxType(TaxType::SALES_TAX) + ->withTaxAmount(1.00) + ->execute(); + + $this->assertEquals(true, $cpcResponse != null); + $this->assertEquals('00', $cpcResponse->responseCode); + } + + public function test031LevelIINoResponse() + { + $address = new Address(); + $address->streetAddress1 = '6860'; + $address->postalCode = '75024'; + + $card = TestCards::amexManual(); + + $response = $card->charge(111.12) + ->withCurrency('USD') + ->withInvoiceNumber('123456') + ->withAddress($address) + ->withCommercialRequest(true) + ->withEcommerceInfo($this->ecommerceInfo) + ->execute(); + + $this->assertEquals(true, $response != null); + $this->assertEquals('00', $response->responseCode); + $this->assertEquals('0', $response->commercialIndicator); + + $cpcResponse = $response->edit() + ->withPoNumber('9876543210') + ->withTaxType(TaxType::SALES_TAX) + ->withTaxAmount(1.00) + ->execute(); + + $this->assertEquals(true, $cpcResponse != null); + $this->assertEquals('00', $cpcResponse->responseCode); + } + + public function test032LevelIINoResponse() + { + $address = new Address(); + $address->streetAddress1 = '6860'; + $address->postalCode = '75024'; + + $card = TestCards::amexManual(); + + $response = $card->charge(111.13) + ->withCurrency('USD') + ->withInvoiceNumber('123456') + ->withAddress($address) + ->withCommercialRequest(true) + ->withEcommerceInfo($this->ecommerceInfo) + ->execute(); + + $this->assertEquals(true, $response != null); + $this->assertEquals('00', $response->responseCode); + $this->assertEquals('0', $response->commercialIndicator); + + $cpcResponse = $response->edit() + ->withPoNumber('9876543210') + ->withTaxType(TaxType::TAX_EXEMPT) + ->execute(); + + $this->assertEquals(true, $cpcResponse != null); + $this->assertEquals('00', $cpcResponse->responseCode); + } + + /// PRIOR / VOICE AUTHORIZATION + + public function test033OfflineSale() + { + $card = TestCards::visaManual(); + + $response = $card->charge(17.10) + ->withCurrency('USD') + ->withModifier(TransactionModifier::OFFLINE) + ->withOfflineAuthCode('654321') + ->withInvoiceNumber('123456') + ->withEcommerceInfo($this->ecommerceInfo) + ->execute(); + + $this->assertEquals(true, $response != null); + $this->assertEquals('00', $response->responseCode); + } + + public function test033OfflineAuthorization() + { + $card = TestCards::visaManual(); + + $response = $card->authorize(17.10) + ->withCurrency('USD') + ->withModifier(TransactionModifier::OFFLINE) + ->withOfflineAuthCode('654321') + ->withInvoiceNumber('123456') + ->withEcommerceInfo($this->ecommerceInfo) + ->execute(); + + $this->assertEquals(true, $response != null); + $this->assertEquals('00', $response->responseCode); + } + + /// RETURN + + public function test034OfflineCreditReturn() + { + $card = TestCards::masterCardManual(); + + $response = $card->refund(15.15) + ->withCurrency('USD') + ->withInvoiceNumber('123456') + ->withEcommerceInfo($this->ecommerceInfo) + ->execute(); + + $this->assertEquals(true, $response != null); + $this->assertEquals('00', $response->responseCode); + } + + public function test034bOfflineCreditReturn() + { + $card = TestCards::masterCardManual(); + + $response = $card->refund(15.16) + ->withCurrency('USD') + ->withInvoiceNumber('123456') + ->withEcommerceInfo($this->ecommerceInfo) + ->execute(); + + $this->assertEquals(true, $response != null); + $this->assertEquals('00', $response->responseCode); + } + + /// ONLINE VOID / REVERSAL + + public function test035VoidTest10() + { + // see test 010 + } + + public function test036VoidTest20() + { + // see test 020 + } + + /// Time Out Reversal + public function test036bTimeoutReversal() + { + $sale = TestCards::visaManual()->charge(911) + ->withCurrency('USD') + ->withInvoiceNumber('123456') + ->withClientTransactionId('987321654') + ->withEcommerceInfo($this->ecommerceInfo) + ->execute(); + + $this->assertEquals(true, $sale != null); + $this->assertEquals('91', $sale->responseCode); + + $response = Transaction::fromId(null, PaymentMethodType::CREDIT); + $response->clientTransactionId = '987321654'; + + $this->expectException(GatewayException::class); + $response->reverse(911)->execute(); + } + + /// One time bill payment + + public function test010ChargeVisaOneTime() + { + $address = new Address(); + $address->streetAddress1 = '6860 Dallas Pkwy'; + $address->postalCode = '75024'; + + $card = null; + if ($this->useTokens) { + $card = new CreditCardData(); + $card->token = static::$visaToken; + } else { + $card = TestCards::visaManual(); + } + + $response = $card->charge(13.11) + ->withCurrency('USD') + ->withAddress($address) + ->withInvoiceNumber('123456') + ->withOneTimePayment(true) + ->withAllowDuplicates(true) + ->execute(); + + $this->assertEquals(true, $response != null); + $this->assertEquals('00', $response->responseCode); + + $void = $response->void()->execute(); + + $this->assertEquals(true, $void != null); + $this->assertEquals('00', $void->responseCode); + } + + public function test011ChargeMasterCardOneTime() + { + $address = new Address(); + $address->streetAddress1 = '6860'; + $address->postalCode = '750241234'; + + $card = null; + if ($this->useTokens) { + $card = new CreditCardData(); + $card->token = static::$mastercardToken; + } else { + $card = TestCards::masterCardManual(); + } + + $response = $card->charge(13.12) + ->withCurrency('USD') + ->withAddress($address) + ->withInvoiceNumber('123456') + ->withOneTimePayment(true) + ->withAllowDuplicates(true) + ->execute(); + + $this->assertEquals(true, $response != null); + $this->assertEquals('00', $response->responseCode); + } + + public function test012ChargeDiscoverOneTime() + { + $address = new Address(); + $address->streetAddress1 = '6860'; + $address->postalCode = '75024'; + + $card = null; + if ($this->useTokens) { + $card = new CreditCardData(); + $card->token = static::$discoverToken; + } else { + $card = TestCards::discoverManual(); + } + + $response = $card->charge(13.13) + ->withCurrency('USD') + ->withAddress($address) + ->withInvoiceNumber('123456') + ->withOneTimePayment(true) + ->withAllowDuplicates(true) + ->execute(); + + $this->assertEquals(true, $response != null); + $this->assertEquals('00', $response->responseCode); + } + + public function test013ChargeAmexOneTime() + { + $address = new Address(); + $address->streetAddress1 = '6860'; + $address->postalCode = '75024'; + + $card = null; + if ($this->useTokens) { + $card = new CreditCardData(); + $card->token = static::$amexToken; + } else { + $card = TestCards::amexManual(); + } + + $response = $card->charge(13.14) + ->withCurrency('USD') + ->withAddress($address) + ->withInvoiceNumber('123456') + ->withOneTimePayment(true) + ->withAllowDuplicates(true) + ->execute(); + + $this->assertEquals(true, $response != null); + $this->assertEquals('00', $response->responseCode); + } + + public function test014ChargeJcbOneTime() + { + $address = new Address(); + $address->streetAddress1 = '6860'; + $address->postalCode = '75024'; + + $card = new CreditCardData(); + $card->number = '3566007770007321'; + $card->expMonth = '12'; + $card->expYear = TestCards::validCardExpYear(); + $card->cvn = '123'; + + $response = $card->charge(13.15) + ->withCurrency('USD') + ->withAddress($address) + ->withInvoiceNumber('123456') + ->withOneTimePayment(true) + ->withAllowDuplicates(true) + ->execute(); + + $this->assertEquals(true, $response != null); + $this->assertEquals('00', $response->responseCode); + } + + /// ADVANCED FRAUD SCREENING + + /** + * TODO: Change code assertions when AFS is enabled on account + */ + public function test037FraudPreventionSale() + { + $card = TestCards::visaManual(); + + $response = $card->charge(15000) + ->withCurrency('USD') + ->execute(); + $this->assertEquals(true, $response != null); + $this->assertEquals('00', $response->responseCode); + // $this->assertEquals('FR', $response->responseCode); + } + + /** + * TODO: Change code assertions when AFS is enabled on account + */ + public function test038FraudPreventionReturn() + { + $card = TestCards::visaManual(); + + $response = $card->refund(15000) + ->withCurrency('USD') + ->execute(); + $this->assertEquals(true, $response != null); + $this->assertEquals('00', $response->responseCode); + // $this->assertEquals('41', $response->responseCode); + } + + /// ONE CARD - GSB CARD FUNCTIONS + + /// BALANCE INQUIRY + + public function test037BalanceInquiryGsb() + { + if (false === $this->usePrepaid) { + $this->markTestSkipped('GSB not configured'); + } + + $address = new Address(); + $address->streetAddress1 = '6860'; + $address->postalCode = '75024'; + + $card = TestCards::gsbManual(); + + $response = $card->balanceInquiry() + ->withAddress($address) + ->execute(); + + $this->assertEquals(true, $response != null); + $this->assertEquals('00', $response->responseCode); + } + + /// ADD VALUE + + public function test038AddValueGsb() + { + if (false === $this->usePrepaid) { + $this->markTestSkipped('GSB not configured'); + } + + $card = new CreditTrackData(); + $card->value = '%B6277220572999800^ / ^49121010557010000016000000?F;6277220572999800=49121010557010000016?'; + + $response = $card->addValue(15.00) + ->withCurrency('USD') + ->execute(); + + $this->assertEquals(true, $response != null); + $this->assertEquals('00', $response->responseCode); + } + + /// SALE + + public function test039ChargeGsb() + { + if (false === $this->usePrepaid) { + $this->markTestSkipped('GSB not configured'); + } + + $address = new Address(); + $address->streetAddress1 = '6860'; + $address->postalCode = '75024'; + + $card = TestCards::gsbManual(); + + $response = $card->charge(2.05) + ->withCurrency('USD') + ->withAddress($address) + ->withInvoiceNumber('123456') + ->execute(); + + $this->assertEquals(true, $response != null); + $this->assertEquals('00', $response->responseCode); + + $voidResponse = $response->void() + ->execute(); + $this->assertEquals(true, $voidResponse != null); + $this->assertEquals('00', $voidResponse->responseCode); + } + + public function test040ChargeGsb() + { + if (false === $this->usePrepaid) { + $this->markTestSkipped('GSB not configured'); + } + + $address = new Address(); + $address->streetAddress1 = '6860'; + $address->postalCode = '75024'; + + $card = TestCards::gsbManual(); + + $response = $card->charge(2.10) + ->withCurrency('USD') + ->withAddress($address) + ->withInvoiceNumber('123456') + ->execute(); + + $this->assertEquals(true, $response != null); + $this->assertEquals('00', $response->responseCode); + } + + /// ONLINE VOID / REVERSAL + + public function test041VoidGsb() + { + // see test 039 + } + + /// HMS GIFT - REWARDS + + /// ACTIVATE + + public function test042ActivateGift1() + { + $card = TestCards::giftCard1Swipe(); + + $response = $card->activate(6.00) + ->execute(); + $this->assertEquals(true, $response != null); + $this->assertEquals('00', $response->responseCode); + } + + public function test043ActivateGift2() + { + + $card = TestCards::giftCard2Manual(); + + $response = $card->activate(7.00) + ->execute(); + $this->assertEquals(true, $response != null); + $this->assertEquals('00', $response->responseCode); + } + + /// LOAD / ADD VALUE + + public function test044AddValueGift1() + { + $card = TestCards::giftCard1Swipe(); + + $response = $card->addValue(8.00) + ->withCurrency('USD') + ->execute(); + $this->assertEquals(true, $response != null); + $this->assertEquals('00', $response->responseCode); + } + + public function test045AddValueGift2() + { + $card = TestCards::giftCard2Manual(); + + $response = $card->addValue(9.00) + ->withCurrency('USD') + ->execute(); + $this->assertEquals(true, $response != null); + $this->assertEquals('00', $response->responseCode); + } + + /// BALANCE INQUIRY + + public function test046BalanceInquiryGift1() + { + $card = TestCards::giftCard1Swipe(); + + $response = $card->balanceInquiry() + ->execute(); + $this->assertEquals(true, $response != null); + $this->assertEquals('00', $response->responseCode); + $this->assertEquals('10.00', $response->balanceAmount); + } + + public function test047BalanceInquiryGift2() + { + $card = TestCards::giftCard2Manual(); + + $response = $card->balanceInquiry() + ->execute(); + $this->assertEquals(true, $response != null); + $this->assertEquals('00', $response->responseCode); + $this->assertEquals('10.00', $response->balanceAmount); + } + + /// REPLACE / TRANSFER + + public function test048ReplaceGift1() + { + $card = TestCards::giftCard1Swipe(); + + $response = $card->replaceWith(TestCards::giftCard2Manual()) + ->execute(); + + $this->assertEquals(true, $response != null); + $this->assertEquals('00', $response->responseCode); + $this->assertEquals('10.00', $response->balanceAmount); + } + + public function test049ReplaceGift2() + { + $card = TestCards::giftCard2Manual(); + + $response = $card->replaceWith(TestCards::giftCard1Swipe()) + ->execute(); + + $this->assertEquals(true, $response != null); + $this->assertEquals('00', $response->responseCode); + $this->assertEquals('10.00', $response->balanceAmount); + } + + /// SALE / REDEEM + + public function test050SaleGift1() + { + $card = TestCards::giftCard1Swipe(); + + $response = $card->charge(1.00) + ->withCurrency('USD') + ->execute(); + $this->assertEquals(true, $response != null); + $this->assertEquals('00', $response->responseCode); + } + + public function test051SaleGift2() + { + $card = TestCards::giftCard2Manual(); + + $response = $card->charge(2.00) + ->withCurrency('USD') + ->execute(); + $this->assertEquals(true, $response != null); + $this->assertEquals('00', $response->responseCode); + } + + public function test052SaleGift1Void() + { + $card = TestCards::giftCard1Swipe(); + + $response = $card->charge(3.00) + ->withCurrency('USD') + ->execute(); + $this->assertEquals(true, $response != null); + $this->assertEquals('00', $response->responseCode); + + $voidResponse = $response->void() + ->execute(); + $this->assertEquals(true, $voidResponse != null); + $this->assertEquals('00', $voidResponse->responseCode); + } + + public function test053SaleGift2Reversal() + { + $card = TestCards::giftCard2Manual(); + + $response = $card->charge(4.00) + ->withCurrency('USD') + ->execute(); + $this->assertEquals(true, $response != null); + $this->assertEquals('00', $response->responseCode); + + $reversalResponse = $response->reverse(4.00) + ->execute(); + $this->assertEquals(true, $reversalResponse != null); + $this->assertEquals('00', $reversalResponse->responseCode); + } + + /// VOID + + public function test054VoidGift() + { + // see test 052 + } + + /// REVERSAL + + public function test055ReversalGift() + { + // see test 053 + } + + public function test056ReversalGift2() + { + $card = TestCards::giftCard2Manual(); + + $reversalResponse = $card->reverse(2.00) + ->execute(); + $this->assertEquals(true, $reversalResponse != null); + $this->assertEquals('00', $reversalResponse->responseCode); + } + + /// DEACTIVATE + + public function test057DeactivateGift1() + { + $card = TestCards::giftCard1Swipe(); + + $response = $card->deactivate() + ->execute(); + $this->assertEquals(true, $response != null); + $this->assertEquals('00', $response->responseCode); + } + + /// RECEIPTS MESSAGING + + public function test058ReceiptsMessaging() + { + return; # print and scan receipt for test 51 + } + + /// REWARD + + /// BALANCE INQUIRY + + public function test059BalanceInquiryRewards1() + { + $card = TestCards::giftCard1Swipe(); + + $response = $card->balanceInquiry() + ->execute(); + $this->assertEquals(true, $response != null); + $this->assertEquals('00', $response->responseCode); + $this->assertTrue($response->pointsBalanceAmount > 0); + } + + public function test060BalanceInquiryRewards2() + { + $card = TestCards::giftCard2Manual(); + + $response = $card->balanceInquiry() + ->execute(); + $this->assertEquals(true, $response != null); + $this->assertEquals('00', $response->responseCode); + $this->assertTrue($response->pointsBalanceAmount > 0); + } + + /// ALIAS + + public function test061CreateAliasGift1() + { + $response = GiftCard::create('9725550100'); + + $this->assertEquals(true, $response != null); + } + + public function test062CreateAliasGift2() + { + $response = GiftCard::create('9725550100'); + + $this->assertEquals(true, $response != null); + } + + public function test063AddAliasGift1() + { + $card = TestCards::giftCard1Swipe(); + + $response = $card->addAlias('2145550199') + ->execute(); + $this->assertEquals(true, $response != null); + $this->assertEquals('00', $response->responseCode); + } + + public function test064AddAliasGift2() + { + $card = TestCards::giftCard2Manual(); + + $response = $card->addAlias('2145550199') + ->execute(); + $this->assertEquals(true, $response != null); + $this->assertEquals('00', $response->responseCode); + } + + public function test065DeleteAliasGift1() + { + $card = TestCards::giftCard1Swipe(); + + $response = $card->removeAlias('2145550199') + ->execute(); + $this->assertEquals(true, $response != null); + $this->assertEquals('00', $response->responseCode); + } + + /// SALE / REDEEM + + public function test066RedeemPointsGift1() + { + $card = TestCards::giftCard1Swipe(); + + $response = $card->charge(100) + ->withCurrency('POINTS') + ->execute(); + $this->assertEquals(true, $response != null); + $this->assertEquals('00', $response->responseCode); + } + + public function test067RedeemPointsGift2() + { + $card = TestCards::giftCard2Manual(); + + $response = $card->charge(200) + ->withCurrency('POINTS') + ->execute(); + $this->assertEquals(true, $response != null); + $this->assertEquals('00', $response->responseCode); + } + + public function test068RedeemPointsGift2() + { + $card = new GiftCard(); + $card->alias = '9725550100'; + + $response = $card->charge(300) + ->withCurrency('POINTS') + ->execute(); + $this->assertEquals(true, $response != null); + $this->assertEquals('00', $response->responseCode); + } + + /// REWARDS + + public function test069RewardsGift1() + { + $card = TestCards::giftCard1Swipe(); + + $response = $card->rewards(10) + ->execute(); + $this->assertEquals(true, $response != null); + $this->assertEquals('00', $response->responseCode); + } + + public function test070RewardsGift2() + { + $card = TestCards::giftCard2Manual(); + + $response = $card->rewards(11) + ->execute(); + $this->assertEquals(true, $response != null); + $this->assertEquals('00', $response->responseCode); + } + + /// REPLACE / TRANSFER + + public function test071ReplaceGift1() + { + $card = TestCards::giftCard1Swipe(); + + $response = $card->replaceWith(TestCards::giftCard2Manual()) + ->execute(); + $this->assertEquals(true, $response != null); + $this->assertEquals('00', $response->responseCode); + } + + public function test072ReplaceGift2() + { + $card = TestCards::giftCard2Manual(); + + $response = $card->replaceWith(TestCards::giftCard1Swipe()) + ->execute(); + $this->assertEquals(true, $response != null); + $this->assertEquals('00', $response->responseCode); + } + + /// DEACTIVATE + + public function test073DeactivateGift1() + { + $card = TestCards::giftCard1Swipe(); + + $response = $card->deactivate() + ->execute(); + $this->assertEquals(true, $response != null); + $this->assertEquals('00', $response->responseCode); + } + + public function test074DeactivateGift2() + { + $card = TestCards::giftCard2Manual(); + + $response = $card->deactivate() + ->execute(); + $this->assertEquals(true, $response != null); + $this->assertEquals('00', $response->responseCode); + } + + /// RECEIPTS MESSAGING + + public function test075ReceiptsMessaging() + { + return; # print and scan receipt for test 51 + } + + /// CLOSE BATCH + + public function test999CloseBatch() + { + try { + $response = BatchService::closeBatch(); + $this->assertNotNull($response); + // printf('batch id: %s', $response->id); + // printf('sequence number: %s', $response->sequenceNumber); + } catch (ApiException $e) { + if (false === strpos($e->getMessage(), static::BATCH_NOT_OPEN) + || false === strpos($e->getMessage(), static::NO_TRANS_IN_BATCH) + ) { + $this->fail($e->getMessage()); + } + } + } +} diff --git a/test/Integration/Gateways/PorticoConnector/Certifications/RecurringTest.php b/test/Integration/Gateways/PorticoConnector/Certifications/RecurringTest.php index a190fc4b..fc0bc6df 100644 --- a/test/Integration/Gateways/PorticoConnector/Certifications/RecurringTest.php +++ b/test/Integration/Gateways/PorticoConnector/Certifications/RecurringTest.php @@ -1,626 +1,626 @@ -identifierBase, $this->todayDate, $identifier); - } - - /** - * @return PorticoConfig - */ - private function config() - { - $config = new PorticoConfig(); - $config->secretApiKey = 'skapi_cert_MTyMAQBiHVEAewvIzXVFcmUd2UcyBge_eCpaASUp0A'; - $config->serviceUrl = ($this->enableCryptoUrl) ? - 'https://cert.api2-c.heartlandportico.com/': - 'https://cert.api2.heartlandportico.com'; - return $config; - } - - public function setup() : void - { - ServicesContainer::configureService($this->config()); - - $this->todayDate = date('Ymd'); - $this->identifierBase = substr( - sprintf('%s-%%s', GenerationUtils::getGuid()), - 0, - 10 - ); - } - - public function test000CleanUp() - { - try { - $results = Schedule::findAll(); - foreach ($results as $schedule) { - $schedule->delete(true); - } - } catch (\Exception $e) { - } - - try { - $results = RecurringPaymentMethod::findAll(); - foreach ($results as $paymentMethod) { - $paymentMethod->delete(true); - } - } catch (\Exception $e) { - } - - try { - $results = Customer::findAll(); - foreach ($results as $customer) { - $customer->delete(true); - } - } catch (\Exception $e) { - } - } - - // CUSTOMER SETUP - - public function test001AddCustomerPerson() - { - $customer = new Customer(); - $customer->id = $this->getIdentifier('Person'); - $customer->firstName = 'John'; - $customer->lastName = 'Doe'; - $customer->status = 'Active'; - $customer->email = 'john.doe@example.com'; - $customer->address = new Address(); - $customer->address->streetAddress1 = '123 Main St.'; - $customer->address->city = 'Dallas'; - $customer->address->province = 'TX'; - $customer->address->postalCode = '75024'; - $customer->address->country = 'USA'; - $customer->workPhone = '5551112222'; - - $customer = $customer->create(); - - $this->assertNotNull($customer); - $this->assertNotNull($customer->key); - static::$customerPerson = $customer; - - $found = Customer::find($customer->id); - $this->assertNotNull($found); - } - - public function test002AddCustomerBusiness() - { - $customer = new Customer(); - $customer->id = $this->getIdentifier('Business'); - $customer->company = 'AcmeCo'; - $customer->status = 'Active'; - $customer->email = 'john.doe@example.com'; - $customer->address = new Address(); - $customer->address->streetAddress1 = '987 Elm St.'; - $customer->address->city = 'Princeton'; - $customer->address->province = 'NJ'; - $customer->address->postalCode = '12345'; - $customer->address->country = 'USA'; - $customer->workPhone = '5551112222'; - - $customer = $customer->create(); - - $this->assertNotNull($customer); - $this->assertNotNull($customer->key); - static::$customerBusiness = $customer; - } - - // PAYMENT METHOD SETUP - - public function test003AddPaymentCreditVisa() - { - if (static::$customerPerson === null) { - $this->markTestIncomplete(); - } - - $card = new CreditCardData(); - $card->number = '4012002000060016'; - $card->expMonth = '12'; - $card->expYear = TestCards::validCardExpYear(); - - $paymentMethod = static::$customerPerson->addPaymentMethod( - $this->getIdentifier('CreditV'), - $card - )->create(); - - $this->assertNotNull($paymentMethod); - $this->assertNotNull($paymentMethod->key); - static::$paymentMethodVisa = $paymentMethod; - } - - public function test004AddPaymentCreditMasterCard() - { - if (static::$customerPerson === null) { - $this->markTestIncomplete(); - } - - $card = new CreditCardData(); - $card->number = '5473500000000014'; - $card->expMonth = '12'; - $card->expYear = TestCards::validCardExpYear(); - - $paymentMethod = static::$customerPerson->addPaymentMethod( - $this->getIdentifier('CreditMC'), - $card - )->create(); - - $this->assertNotNull($paymentMethod); - $this->assertNotNull($paymentMethod->key); - static::$paymentMethodMasterCard = $paymentMethod; - } - - public function test005AddPaymentCheckPpd() - { - if (static::$customerPerson === null) { - $this->markTestIncomplete(); - } - - $check = new ECheck(); - $check->accountType = AccountType::CHECKING; - $check->checkType = CheckType::PERSONAL; - $check->secCode = SecCode::PPD; - $check->routingNumber = '122000030'; - $check->driversLicenseNumber = '7418529630'; - $check->driversLicenseState = 'TX'; - $check->accountNumber = '1357902468'; - $check->birthYear = 1989; - - $paymentMethod = static::$customerPerson->addPaymentMethod( - $this->getIdentifier('CheckPpd'), - $check - )->create(); - - $this->assertNotNull($paymentMethod); - $this->assertNotNull($paymentMethod->key); - static::$paymentMethodCheckPpd = $paymentMethod; - } - - public function test006AddPaymentCheckCcd() - { - if (static::$customerBusiness === null) { - $this->markTestIncomplete(); - } - - $check = new eCheck(); - $check->accountType = AccountType::CHECKING; - $check->checkType = CheckType::BUSINESS; - $check->secCode = SecCode::CCD; - $check->routingNumber = '122000030'; - $check->driversLicenseNumber = '7418529630'; - $check->driversLicenseState = 'TX'; - $check->accountNumber = '1357902468'; - $check->birthYear = 1989; - - $paymentMethod = static::$customerBusiness->addPaymentMethod( - $this->getIdentifier('CheckCcd'), - $check - )->create(); - - $this->assertNotNull($paymentMethod); - $this->assertNotNull($paymentMethod->key); - static::$paymentMethodCheckCcd = $paymentMethod; - } - - // PAYMENT SETUP - DECLINED - - /** - * expectedException GlobalPayments\Api\Entities\Exceptions\GatewayException - */ - public function test007AddPaymentCheckPpd() - { - if (static::$customerPerson === null) { - $this->markTestIncomplete(); - } - - $check = new eCheck(); - $check->accountType = AccountType::CHECKING; - $check->checkType = CheckType::PERSONAL; - $check->secCode = SecCode::PPD; - $check->routingNumber = '122000030'; - $check->driversLicenseNumber = '7418529630'; - $check->driversLicenseState = 'TX'; - $check->accountNumber = '1357902468'; - $check->birthYear = 1989; - - static::$customerPerson->addPaymentMethod( - $this->getIdentifier('CheckPpd'), - $check - )->create(); - } - - // Recurring Billing using PayPlan - Managed Schedule - - public function test008AddScheduleCreditVisa() - { - if (static::$paymentMethodVisa === null) { - $this->markTestIncomplete(); - } - - static::$scheduleVisaID = $this->getIdentifier('CreditV'); - - $schedule = static::$paymentMethodVisa->addSchedule( - static::$scheduleVisaID - ) - ->withStatus('Active') - ->withAmount(30.02) - ->withCurrency('USD') - ->withStartDate(\DateTime::createFromFormat('Y-m-d', '2027-02-01')) - ->withFrequency(ScheduleFrequency::WEEKLY) - ->withEndDate(\DateTime::createFromFormat('Y-m-d', '2027-04-01')) - ->withReprocessingCount(2) - ->create(); - - $this->assertNotNull($schedule); - $this->assertNotNull($schedule->key); - static::$scheduleVisa = $schedule; - } - - public function test009AddScheduleCreditMasterCard() - { - if (static::$paymentMethodMasterCard == null) { - $this->markTestIncomplete(); - } - - $schedule = static::$paymentMethodMasterCard->addSchedule( - $this->getIdentifier('CreditMC') - ) - ->withStatus('Active') - ->withAmount(30.02) - ->withCurrency('USD') - ->withStartDate(\DateTime::createFromFormat('Y-m-d', '2027-02-01')) - ->withFrequency(ScheduleFrequency::WEEKLY) - ->withEndDate(\DateTime::createFromFormat('Y-m-d', '2027-04-01')) - ->withReprocessingCount(2) - ->create(); - $this->assertNotNull($schedule); - $this->assertNotNull($schedule->key); - static::$scheduleMasterCard = $schedule; - } - - public function test010AddScheduleCheckPPD() - { - if (static::$paymentMethodCheckPpd == null) { - $this->markTestIncomplete(); - } - - $schedule = static::$paymentMethodCheckPpd->addSchedule( - $this->getIdentifier('CheckPPD') - ) - ->withStatus('Active') - ->withAmount(30.03) - ->withCurrency('USD') - ->withStartDate(\DateTime::createFromFormat('Y-m-d', '2027-02-01')) - ->withFrequency(ScheduleFrequency::MONTHLY) - ->withReprocessingCount(1) - ->withnumberOfPaymentsRemaining(2) - ->create(); - $this->assertNotNull($schedule); - $this->assertNotNull($schedule->key); - static::$scheduleCheckPpd = $schedule; - } - - public function test011AddScheduleCheckCCD() - { - if (static::$paymentMethodCheckCcd == null) { - $this->markTestIncomplete(); - } - - $schedule = static::$paymentMethodCheckCcd->addSchedule( - $this->getIdentifier('CheckCCD') - ) - ->withStatus('Active') - ->withAmount(30.04) - ->withCurrency('USD') - ->withStartDate(\DateTime::createFromFormat('Y-m-d', '2027-02-01')) - ->withFrequency(ScheduleFrequency::BI_WEEKLY) - ->withReprocessingCount(1) - ->create(); - $this->assertNotNull($schedule); - $this->assertNotNull($schedule->key); - static::$scheduleCheckCcd = $schedule; - } - - /** - * expectedException GlobalPayments\Api\Entities\Exceptions\GatewayException - */ - public function test012AddScheduleCreditVisa() - { - if (static::$paymentMethodVisa == null) { - $this->markTestIncomplete(); - } - - $schedule = static::$paymentMethodVisa->addSchedule( - $this->getIdentifier('CreditV') - ) - ->withStartDate(\DateTime::createFromFormat('Y-m-d', '2027-02-01')) - ->withAmount(30.01) - ->withCurrency('USD') - ->withFrequency(ScheduleFrequency::WEEKLY) - ->withReprocessingCount(1) - ->withStatus('Active') - ->create(); - } - - /** - * expectedException GlobalPayments\Api\Entities\Exceptions\GatewayException - */ - public function test013AddScheduleCCheckPPD() - { - if (static::$paymentMethodCheckPpd == null) { - $this->markTestIncomplete(); - } - - $schedule = static::$paymentMethodCheckPpd->addSchedule( - $this->getIdentifier('CheckPPD') - ) - ->withStatus('Active') - ->withAmount(30.03) - ->withCurrency('USD') - ->withStartDate(\DateTime::createFromFormat('Y-m-d', '2027-02-01')) - ->withFrequency(ScheduleFrequency::MONTHLY) - ->withReprocessingCount(1) - ->withnumberOfPaymentsRemaining(2) - ->create(); - } - - // Recurring Billing using PayPlan - Managed Schedule - - public function test014RecurringBillingVisa() - { - if (static::$paymentMethodVisa == null || static::$scheduleVisa == null) { - $this->markTestIncomplete(); - } - - $response = static::$paymentMethodVisa->charge(20.01) - ->withCurrency('USD') - ->withScheduleId(static::$scheduleVisa->key) - ->withOneTimePayment(false) - ->execute(); - $this->assertNotNull($response); - $this->assertEquals('00', $response->responseCode); - } - - public function test015RecurringBillingMasterCard() - { - if (true || static::$paymentMethodMasterCard == null || static::$scheduleMasterCard == null) { - $this->markTestIncomplete(); - } - - $response = static::$paymentMethodMasterCard->charge(20.02) - ->withCurrency('USD') - ->withScheduleId(static::$scheduleVisa->key) - ->withOneTimePayment(false) - ->execute(); - $this->assertNotNull($response); - $this->assertEquals('00', $response->responseCode); - } - - public function test016RecurringBillingCheckPPD() - { - if (static::$paymentMethodCheckPpd == null || static::$scheduleCheckPpd == null) { - $this->markTestIncomplete(); - } - - $response = static::$paymentMethodCheckPpd->charge(20.03) - ->withCurrency('USD') - ->withScheduleId(static::$scheduleVisa->key) - ->withOneTimePayment(false) - ->execute(); - $this->assertNotNull($response); - $this->assertEquals('00', $response->responseCode); - } - - public function test017RecurringBillingCheckCCD() - { - if (static::$paymentMethodCheckCcd == null || static::$scheduleCheckCcd == null) { - $this->markTestIncomplete(); - } - - $response = static::$paymentMethodCheckCcd->charge(20.04) - ->withCurrency('USD') - ->withScheduleId(static::$scheduleVisa->key) - ->withOneTimePayment(false) - ->execute(); - $this->assertNotNull($response); - $this->assertEquals('00', $response->responseCode); - } - - // One time bill payment - - public function test018RecurringBillingVisa() - { - if (static::$paymentMethodVisa == null) { - $this->markTestIncomplete(); - } - - $response = static::$paymentMethodVisa->charge(20.06) - ->withCurrency('USD') - ->execute(); - $this->assertNotNull($response); - $this->assertEquals('00', $response->responseCode); - } - - public function test019RecurringBillingMasterCard() - { - if (static::$paymentMethodMasterCard == null) { - $this->markTestIncomplete(); - } - - $response = static::$paymentMethodMasterCard->charge(20.07) - ->withCurrency('USD') - ->execute(); - $this->assertNotNull($response); - $this->assertEquals('00', $response->responseCode); - } - - public function test020RecurringBillingCheckPPD() - { - if (static::$paymentMethodCheckPpd == null) { - $this->markTestIncomplete(); - } - - $response = static::$paymentMethodCheckPpd->charge(20.08) - ->withCurrency('USD') - ->execute(); - $this->assertNotNull($response); - $this->assertEquals('00', $response->responseCode); - } - - public function test021RecurringBillingCheckCCD() - { - if (static::$paymentMethodCheckCcd == null) { - $this->markTestIncomplete(); - } - - $response = static::$paymentMethodCheckCcd->charge(20.09) - ->withCurrency('USD') - ->execute(); - $this->assertNotNull($response); - $this->assertEquals('00', $response->responseCode); - } - - // Onetime bill payment - declined - - public function test022RecurringBillingVisaDecline() - { - if (static::$paymentMethodVisa == null) { - $this->markTestIncomplete(); - } - - $response = static::$paymentMethodVisa->charge(10.08) - ->withCurrency('USD') - ->execute(); - $this->assertNotNull($response); - $this->assertEquals('51', $response->responseCode); - } - - public function test023RecurringBillingCheckPPDDecline() - { - if (true || static::$paymentMethodCheckPpd == null) { - $this->markTestIncomplete(); - } - - $response = static::$paymentMethodCheckPpd->charge(25.02) - ->withCurrency('USD') - ->execute(); - $this->assertNotNull($response); - $this->assertEquals('1', $response->responseCode); - } - - public function test024RecurringBillingVisaWithCOF() - { - if (static::$paymentMethodVisa == null || static::$scheduleVisa == null) { - $this->markTestIncomplete(); - } - - $response = static::$paymentMethodVisa->charge(20.01) - ->withCurrency('USD') - ->withScheduleId(static::$scheduleVisa->key) - ->withOneTimePayment(false) - ->withAllowDuplicates(true) - ->withCardBrandStorage(StoredCredentialInitiator::CARDHOLDER) - ->execute(); - - $this->assertNotNull($response); - $this->assertEquals('00', $response->responseCode); - $this->assertNotNull($response->cardBrandTransactionId); - - $nextResponse = static::$paymentMethodVisa->charge(20.01) - ->withCurrency('USD') - ->withScheduleId(static::$scheduleVisa->key) - ->withOneTimePayment(false) - ->withAllowDuplicates(true) - ->withCardBrandStorage(StoredCredentialInitiator::MERCHANT, $response->cardBrandTransactionId) - ->execute(); - - $this->assertNotNull($nextResponse); - $this->assertEquals('00', $nextResponse->responseCode); - } - - public function test025EditStartDateUsingString() - { - $schedule = Schedule::find(static::$scheduleVisaID); - $schedule->startDate = '01022026'; - $schedule->saveChanges(); - } - - public function test026EditStartDateUsingDateTimeObj() - { - $updateTimeValueAsObj = new DateTime(); - $updateTimeValueAsObj->add(new DateInterval('P1Y')); - - $schedule = Schedule::find(static::$scheduleVisaID); - $schedule->startDate = $updateTimeValueAsObj; - $schedule->saveChanges(); - } -} +identifierBase, $this->todayDate, $identifier); + } + + /** + * @return PorticoConfig + */ + private function config() + { + $config = new PorticoConfig(); + $config->secretApiKey = 'skapi_cert_MTyMAQBiHVEAewvIzXVFcmUd2UcyBge_eCpaASUp0A'; + $config->serviceUrl = ($this->enableCryptoUrl) ? + 'https://cert.api2-c.heartlandportico.com/': + 'https://cert.api2.heartlandportico.com'; + return $config; + } + + public function setup() : void + { + ServicesContainer::configureService($this->config()); + + $this->todayDate = date('Ymd'); + $this->identifierBase = substr( + sprintf('%s-%%s', GenerationUtils::getGuid()), + 0, + 10 + ); + } + + public function test000CleanUp() + { + try { + $results = Schedule::findAll(); + foreach ($results as $schedule) { + $schedule->delete(true); + } + } catch (\Exception $e) { + } + + try { + $results = RecurringPaymentMethod::findAll(); + foreach ($results as $paymentMethod) { + $paymentMethod->delete(true); + } + } catch (\Exception $e) { + } + + try { + $results = Customer::findAll(); + foreach ($results as $customer) { + $customer->delete(true); + } + } catch (\Exception $e) { + } + } + + // CUSTOMER SETUP + + public function test001AddCustomerPerson() + { + $customer = new Customer(); + $customer->id = $this->getIdentifier('Person'); + $customer->firstName = 'John'; + $customer->lastName = 'Doe'; + $customer->status = 'Active'; + $customer->email = 'john.doe@example.com'; + $customer->address = new Address(); + $customer->address->streetAddress1 = '123 Main St.'; + $customer->address->city = 'Dallas'; + $customer->address->province = 'TX'; + $customer->address->postalCode = '75024'; + $customer->address->country = 'USA'; + $customer->workPhone = '5551112222'; + + $customer = $customer->create(); + + $this->assertNotNull($customer); + $this->assertNotNull($customer->key); + static::$customerPerson = $customer; + + $found = Customer::find($customer->id); + $this->assertNotNull($found); + } + + public function test002AddCustomerBusiness() + { + $customer = new Customer(); + $customer->id = $this->getIdentifier('Business'); + $customer->company = 'AcmeCo'; + $customer->status = 'Active'; + $customer->email = 'john.doe@example.com'; + $customer->address = new Address(); + $customer->address->streetAddress1 = '987 Elm St.'; + $customer->address->city = 'Princeton'; + $customer->address->province = 'NJ'; + $customer->address->postalCode = '12345'; + $customer->address->country = 'USA'; + $customer->workPhone = '5551112222'; + + $customer = $customer->create(); + + $this->assertNotNull($customer); + $this->assertNotNull($customer->key); + static::$customerBusiness = $customer; + } + + // PAYMENT METHOD SETUP + + public function test003AddPaymentCreditVisa() + { + if (static::$customerPerson === null) { + $this->markTestIncomplete(); + } + + $card = new CreditCardData(); + $card->number = '4012002000060016'; + $card->expMonth = '12'; + $card->expYear = TestCards::validCardExpYear(); + + $paymentMethod = static::$customerPerson->addPaymentMethod( + $this->getIdentifier('CreditV'), + $card + )->create(); + + $this->assertNotNull($paymentMethod); + $this->assertNotNull($paymentMethod->key); + static::$paymentMethodVisa = $paymentMethod; + } + + public function test004AddPaymentCreditMasterCard() + { + if (static::$customerPerson === null) { + $this->markTestIncomplete(); + } + + $card = new CreditCardData(); + $card->number = '5473500000000014'; + $card->expMonth = '12'; + $card->expYear = TestCards::validCardExpYear(); + + $paymentMethod = static::$customerPerson->addPaymentMethod( + $this->getIdentifier('CreditMC'), + $card + )->create(); + + $this->assertNotNull($paymentMethod); + $this->assertNotNull($paymentMethod->key); + static::$paymentMethodMasterCard = $paymentMethod; + } + + public function test005AddPaymentCheckPpd() + { + if (static::$customerPerson === null) { + $this->markTestIncomplete(); + } + + $check = new ECheck(); + $check->accountType = AccountType::CHECKING; + $check->checkType = CheckType::PERSONAL; + $check->secCode = SecCode::PPD; + $check->routingNumber = '122000030'; + $check->driversLicenseNumber = '7418529630'; + $check->driversLicenseState = 'TX'; + $check->accountNumber = '1357902468'; + $check->birthYear = 1989; + + $paymentMethod = static::$customerPerson->addPaymentMethod( + $this->getIdentifier('CheckPpd'), + $check + )->create(); + + $this->assertNotNull($paymentMethod); + $this->assertNotNull($paymentMethod->key); + static::$paymentMethodCheckPpd = $paymentMethod; + } + + public function test006AddPaymentCheckCcd() + { + if (static::$customerBusiness === null) { + $this->markTestIncomplete(); + } + + $check = new eCheck(); + $check->accountType = AccountType::CHECKING; + $check->checkType = CheckType::BUSINESS; + $check->secCode = SecCode::CCD; + $check->routingNumber = '122000030'; + $check->driversLicenseNumber = '7418529630'; + $check->driversLicenseState = 'TX'; + $check->accountNumber = '1357902468'; + $check->birthYear = 1989; + + $paymentMethod = static::$customerBusiness->addPaymentMethod( + $this->getIdentifier('CheckCcd'), + $check + )->create(); + + $this->assertNotNull($paymentMethod); + $this->assertNotNull($paymentMethod->key); + static::$paymentMethodCheckCcd = $paymentMethod; + } + + // PAYMENT SETUP - DECLINED + + /** + * expectedException GlobalPayments\Api\Entities\Exceptions\GatewayException + */ + public function test007AddPaymentCheckPpd() + { + if (static::$customerPerson === null) { + $this->markTestIncomplete(); + } + + $check = new eCheck(); + $check->accountType = AccountType::CHECKING; + $check->checkType = CheckType::PERSONAL; + $check->secCode = SecCode::PPD; + $check->routingNumber = '122000030'; + $check->driversLicenseNumber = '7418529630'; + $check->driversLicenseState = 'TX'; + $check->accountNumber = '1357902468'; + $check->birthYear = 1989; + + static::$customerPerson->addPaymentMethod( + $this->getIdentifier('CheckPpd'), + $check + )->create(); + } + + // Recurring Billing using PayPlan - Managed Schedule + + public function test008AddScheduleCreditVisa() + { + if (static::$paymentMethodVisa === null) { + $this->markTestIncomplete(); + } + + static::$scheduleVisaID = $this->getIdentifier('CreditV'); + + $schedule = static::$paymentMethodVisa->addSchedule( + static::$scheduleVisaID + ) + ->withStatus('Active') + ->withAmount(30.02) + ->withCurrency('USD') + ->withStartDate(\DateTime::createFromFormat('Y-m-d', '2027-02-01')) + ->withFrequency(ScheduleFrequency::WEEKLY) + ->withEndDate(\DateTime::createFromFormat('Y-m-d', '2027-04-01')) + ->withReprocessingCount(2) + ->create(); + + $this->assertNotNull($schedule); + $this->assertNotNull($schedule->key); + static::$scheduleVisa = $schedule; + } + + public function test009AddScheduleCreditMasterCard() + { + if (static::$paymentMethodMasterCard == null) { + $this->markTestIncomplete(); + } + + $schedule = static::$paymentMethodMasterCard->addSchedule( + $this->getIdentifier('CreditMC') + ) + ->withStatus('Active') + ->withAmount(30.02) + ->withCurrency('USD') + ->withStartDate(\DateTime::createFromFormat('Y-m-d', '2027-02-01')) + ->withFrequency(ScheduleFrequency::WEEKLY) + ->withEndDate(\DateTime::createFromFormat('Y-m-d', '2027-04-01')) + ->withReprocessingCount(2) + ->create(); + $this->assertNotNull($schedule); + $this->assertNotNull($schedule->key); + static::$scheduleMasterCard = $schedule; + } + + public function test010AddScheduleCheckPPD() + { + if (static::$paymentMethodCheckPpd == null) { + $this->markTestIncomplete(); + } + + $schedule = static::$paymentMethodCheckPpd->addSchedule( + $this->getIdentifier('CheckPPD') + ) + ->withStatus('Active') + ->withAmount(30.03) + ->withCurrency('USD') + ->withStartDate(\DateTime::createFromFormat('Y-m-d', '2027-02-01')) + ->withFrequency(ScheduleFrequency::MONTHLY) + ->withReprocessingCount(1) + ->withnumberOfPaymentsRemaining(2) + ->create(); + $this->assertNotNull($schedule); + $this->assertNotNull($schedule->key); + static::$scheduleCheckPpd = $schedule; + } + + public function test011AddScheduleCheckCCD() + { + if (static::$paymentMethodCheckCcd == null) { + $this->markTestIncomplete(); + } + + $schedule = static::$paymentMethodCheckCcd->addSchedule( + $this->getIdentifier('CheckCCD') + ) + ->withStatus('Active') + ->withAmount(30.04) + ->withCurrency('USD') + ->withStartDate(\DateTime::createFromFormat('Y-m-d', '2027-02-01')) + ->withFrequency(ScheduleFrequency::BI_WEEKLY) + ->withReprocessingCount(1) + ->create(); + $this->assertNotNull($schedule); + $this->assertNotNull($schedule->key); + static::$scheduleCheckCcd = $schedule; + } + + /** + * expectedException GlobalPayments\Api\Entities\Exceptions\GatewayException + */ + public function test012AddScheduleCreditVisa() + { + if (static::$paymentMethodVisa == null) { + $this->markTestIncomplete(); + } + + $schedule = static::$paymentMethodVisa->addSchedule( + $this->getIdentifier('CreditV') + ) + ->withStartDate(\DateTime::createFromFormat('Y-m-d', '2027-02-01')) + ->withAmount(30.01) + ->withCurrency('USD') + ->withFrequency(ScheduleFrequency::WEEKLY) + ->withReprocessingCount(1) + ->withStatus('Active') + ->create(); + } + + /** + * expectedException GlobalPayments\Api\Entities\Exceptions\GatewayException + */ + public function test013AddScheduleCCheckPPD() + { + if (static::$paymentMethodCheckPpd == null) { + $this->markTestIncomplete(); + } + + $schedule = static::$paymentMethodCheckPpd->addSchedule( + $this->getIdentifier('CheckPPD') + ) + ->withStatus('Active') + ->withAmount(30.03) + ->withCurrency('USD') + ->withStartDate(\DateTime::createFromFormat('Y-m-d', '2027-02-01')) + ->withFrequency(ScheduleFrequency::MONTHLY) + ->withReprocessingCount(1) + ->withnumberOfPaymentsRemaining(2) + ->create(); + } + + // Recurring Billing using PayPlan - Managed Schedule + + public function test014RecurringBillingVisa() + { + if (static::$paymentMethodVisa == null || static::$scheduleVisa == null) { + $this->markTestIncomplete(); + } + + $response = static::$paymentMethodVisa->charge(20.01) + ->withCurrency('USD') + ->withScheduleId(static::$scheduleVisa->key) + ->withOneTimePayment(false) + ->execute(); + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode); + } + + public function test015RecurringBillingMasterCard() + { + if (true || static::$paymentMethodMasterCard == null || static::$scheduleMasterCard == null) { + $this->markTestIncomplete(); + } + + $response = static::$paymentMethodMasterCard->charge(20.02) + ->withCurrency('USD') + ->withScheduleId(static::$scheduleVisa->key) + ->withOneTimePayment(false) + ->execute(); + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode); + } + + public function test016RecurringBillingCheckPPD() + { + if (static::$paymentMethodCheckPpd == null || static::$scheduleCheckPpd == null) { + $this->markTestIncomplete(); + } + + $response = static::$paymentMethodCheckPpd->charge(20.03) + ->withCurrency('USD') + ->withScheduleId(static::$scheduleVisa->key) + ->withOneTimePayment(false) + ->execute(); + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode); + } + + public function test017RecurringBillingCheckCCD() + { + if (static::$paymentMethodCheckCcd == null || static::$scheduleCheckCcd == null) { + $this->markTestIncomplete(); + } + + $response = static::$paymentMethodCheckCcd->charge(20.04) + ->withCurrency('USD') + ->withScheduleId(static::$scheduleVisa->key) + ->withOneTimePayment(false) + ->execute(); + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode); + } + + // One time bill payment + + public function test018RecurringBillingVisa() + { + if (static::$paymentMethodVisa == null) { + $this->markTestIncomplete(); + } + + $response = static::$paymentMethodVisa->charge(20.06) + ->withCurrency('USD') + ->execute(); + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode); + } + + public function test019RecurringBillingMasterCard() + { + if (static::$paymentMethodMasterCard == null) { + $this->markTestIncomplete(); + } + + $response = static::$paymentMethodMasterCard->charge(20.07) + ->withCurrency('USD') + ->execute(); + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode); + } + + public function test020RecurringBillingCheckPPD() + { + if (static::$paymentMethodCheckPpd == null) { + $this->markTestIncomplete(); + } + + $response = static::$paymentMethodCheckPpd->charge(20.08) + ->withCurrency('USD') + ->execute(); + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode); + } + + public function test021RecurringBillingCheckCCD() + { + if (static::$paymentMethodCheckCcd == null) { + $this->markTestIncomplete(); + } + + $response = static::$paymentMethodCheckCcd->charge(20.09) + ->withCurrency('USD') + ->execute(); + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode); + } + + // Onetime bill payment - declined + + public function test022RecurringBillingVisaDecline() + { + if (static::$paymentMethodVisa == null) { + $this->markTestIncomplete(); + } + + $response = static::$paymentMethodVisa->charge(10.08) + ->withCurrency('USD') + ->execute(); + $this->assertNotNull($response); + $this->assertEquals('51', $response->responseCode); + } + + public function test023RecurringBillingCheckPPDDecline() + { + if (true || static::$paymentMethodCheckPpd == null) { + $this->markTestIncomplete(); + } + + $response = static::$paymentMethodCheckPpd->charge(25.02) + ->withCurrency('USD') + ->execute(); + $this->assertNotNull($response); + $this->assertEquals('1', $response->responseCode); + } + + public function test024RecurringBillingVisaWithCOF() + { + if (static::$paymentMethodVisa == null || static::$scheduleVisa == null) { + $this->markTestIncomplete(); + } + + $response = static::$paymentMethodVisa->charge(20.01) + ->withCurrency('USD') + ->withScheduleId(static::$scheduleVisa->key) + ->withOneTimePayment(false) + ->withAllowDuplicates(true) + ->withCardBrandStorage(StoredCredentialInitiator::CARDHOLDER) + ->execute(); + + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode); + $this->assertNotNull($response->cardBrandTransactionId); + + $nextResponse = static::$paymentMethodVisa->charge(20.01) + ->withCurrency('USD') + ->withScheduleId(static::$scheduleVisa->key) + ->withOneTimePayment(false) + ->withAllowDuplicates(true) + ->withCardBrandStorage(StoredCredentialInitiator::MERCHANT, $response->cardBrandTransactionId) + ->execute(); + + $this->assertNotNull($nextResponse); + $this->assertEquals('00', $nextResponse->responseCode); + } + + public function test025EditStartDateUsingString() + { + $schedule = Schedule::find(static::$scheduleVisaID); + $schedule->startDate = '01022026'; + $schedule->saveChanges(); + } + + public function test026EditStartDateUsingDateTimeObj() + { + $updateTimeValueAsObj = new DateTime(); + $updateTimeValueAsObj->add(new DateInterval('P1Y')); + + $schedule = Schedule::find(static::$scheduleVisaID); + $schedule->startDate = $updateTimeValueAsObj; + $schedule->saveChanges(); + } +} diff --git a/test/Integration/Gateways/PorticoConnector/Certifications/RetailTest.php b/test/Integration/Gateways/PorticoConnector/Certifications/RetailTest.php index 273bb3e8..8c72caa3 100644 --- a/test/Integration/Gateways/PorticoConnector/Certifications/RetailTest.php +++ b/test/Integration/Gateways/PorticoConnector/Certifications/RetailTest.php @@ -1,1982 +1,1982 @@ -secretApiKey = 'skapi_cert_MaePAQBr-1QAqjfckFC8FTbRTT120bVQUlfVOjgCBw'; - $config->serviceUrl = ($this->enableCryptoUrl) ? - 'https://cert.api2-c.heartlandportico.com/': - 'https://cert.api2.heartlandportico.com'; - ServicesContainer::configureService($config); - } - - public function testRetail000CloseBatch() - { - try { - $response = BatchService::closeBatch(); - $this->assertNotNull($response); - // error_log(sprintf('Batch ID: %s', $response->Id)); - // error_log(sprintf('Sequence Number: %s', $response->sequenceNumber)); - } catch (ApiException $e) { - if (false === strpos($e->getMessage(), static::BATCH_NOT_OPEN) - && false === strpos($e->getMessage(), static::NO_TRANS_IN_BATCH) - ) { - $this->fail($e->getMessage()); - } - } - } - - /* - CREDIT CARD FUNCTIONS - CARD VERIFY - ACCOUNT VERIFICATION - */ - - public function testRetail001CardVerifyVisa() - { - $visaenc = TestCards::visaSwipeEncrypted(); - - $response = $visaenc->verify() - ->withAllowDuplicates(true) - ->withRequestMultiUseToken(static::$useTokens) - ->execute(); - $this->assertNotNull($response, '$response is null'); - $this->assertEquals('00', $response->responseCode, $response->responseMessage); - - if (static::$useTokens) { - $this->assertNotNull($response->token, 'token is null'); - - $token = new CreditCardData(); - $token->token = $response->token; - - $saleResponse = $token->charge(15.01) - ->withAllowDuplicates(true) - ->execute(); - $this->assertNotNull($saleResponse); - $this->assertEquals('00', $saleResponse->responseCode); - } - } - - public function testRetail002CardVerifyMastercardSwipe() - { - $cardenc = TestCards::masterCardSwipeEncrypted(); - - $response = $cardenc->verify() - ->withAllowDuplicates(true) - ->withRequestMultiUseToken(static::$useTokens) - ->execute(); - $this->assertNotNull($response); - $this->assertEquals('00', $response->responseCode); - - if (static::$useTokens) { - $this->assertNotNull($response->token); - - $token = new CreditCardData(); - $token->token = $response->token; - - $saleResponse = $token->charge(15.02) - ->withAllowDuplicates(true) - ->execute(); - $this->assertNotNull($saleResponse); - $this->assertEquals('00', $saleResponse->responseCode); - } - } - - public function testRetail003CardVerifyDiscover() - { - $discoverenc = TestCards::discoverSwipeEncrypted(); - - $response = $discoverenc->verify() - ->withAllowDuplicates(true) - ->withRequestMultiUseToken(static::$useTokens) - ->execute(); - $this->assertNotNull($response); - $this->assertEquals('00', $response->responseCode); - - if (static::$useTokens) { - $this->assertNotNull($response->token); - - $token = new CreditCardData(); - $token->token = $response->token; - - $saleResponse = $token->charge(15.03) - ->withAllowDuplicates(true) - ->execute(); - $this->assertNotNull($saleResponse); - $this->assertEquals('00', $saleResponse->responseCode); - } - } - - // Address Verification - - public function testRetail004CardVerifyAmex() - { - $address = new Address(); - $address->postalCode = '75024'; - - $manualamex = TestCards::amexManual(false, true); - - $response = $manualamex->verify() - ->withAllowDuplicates(true) - ->withAddress($address) - ->withRequestMultiUseToken(static::$useTokens) - ->execute(); - $this->assertNotNull($response); - $this->assertEquals('00', $response->responseCode); - - if (static::$useTokens) { - $this->assertNotNull($response->token); - - $token = new CreditCardData(); - $token->token = $response->token; - - $saleResponse = $token->charge(15.04) - ->withAllowDuplicates(true) - ->execute(); - $this->assertNotNull($saleResponse); - $this->assertEquals('00', $saleResponse->responseCode); - } - } - - // Balance Inquiry (for Prepaid) - - public function testRetail005BalanceInquiryVisa() - { - $visaenc = TestCards::visaSwipeEncrypted(); - - $response = $visaenc->balanceInquiry()->execute(); - $this->assertNotNull($response); - $this->assertEquals('00', $response->responseCode); - } - - // CREDIT SALE (For multi-use token only) - - public function testRetail006ChargeVisaSwipeToken() - { - $card = TestCards::visaSwipe(); - $response = $card->charge(15.01) - ->withCurrency('USD') - ->withRequestMultiUseToken(true) - ->withAllowDuplicates(true) - ->execute(); - $this->assertNotNull($response); - $this->assertEquals('00', $response->responseCode); - - static::$visatoken = $response->token; - } - - public function testRetail007ChargeMastercardSwipeToken() - { - $card = TestCards::masterCardSwipe(); - $response = $card->charge(15.02) - ->withCurrency('USD') - ->withRequestMultiUseToken(true) - ->withAllowDuplicates(true) - ->execute(); - $this->assertNotNull($response); - $this->assertEquals('00', $response->responseCode); - - static::$mastercardtoken = $response->token; - } - - public function testRetail008ChargeDiscoverSwipeToken() - { - $card = TestCards::discoverSwipe(); - $response = $card->charge(15.03) - ->withCurrency('USD') - ->withRequestMultiUseToken(true) - ->withAllowDuplicates(true) - ->execute(); - $this->assertNotNull($response); - $this->assertEquals('00', $response->responseCode); - - static::$discovertoken = $response->token; - } - - public function testRetail009ChargeAmexSwipeToken() - { - $card = TestCards::amexSwipe(); - $response = $card->charge(15.04) - ->withCurrency('USD') - ->withRequestMultiUseToken(true) - ->withAllowDuplicates(true) - ->execute(); - $this->assertNotNull($response); - $this->assertEquals('00', $response->responseCode); - - static::$amextoken = $response->token; - } - - /* - CREDIT SALE - SWIPED - */ - - public function testRetail010ChargeVisaSwipe() - { - $card = TestCards::visaSwipe(); - $response = $card->charge(15.01) - ->withCurrency('USD') - ->withAllowDuplicates(true) - ->execute(); - $this->assertNotNull($response); - $this->assertEquals('00', $response->responseCode); - - // test 59 - $reverse = $response->reverse(15.01) - ->withAllowDuplicates(true) - ->execute(); - $this->assertNotNull($reverse); - $this->assertEquals('00', $reverse->responseCode); - } - - public function testRetail011ChargeMastercardSwipe() - { - $card = TestCards::masterCardSwipe(); - $response = $card->charge(15.02) - ->withCurrency('USD') - ->withAllowDuplicates(true) - ->execute(); - $this->assertNotNull($response); - $this->assertEquals('00', $response->responseCode); - } - - public function testRetail012ChargeDiscoverSwipe() - { - $card = TestCards::discoverSwipe(); - $response = $card->charge(15.03) - ->withCurrency('USD') - ->withAllowDuplicates(true) - ->execute(); - $this->assertNotNull($response); - $this->assertEquals('00', $response->responseCode); - } - - public function testRetail013ChargeAmexSwipe() - { - $card = TestCards::amexSwipe(); - $response = $card->charge(15.04) - ->withCurrency('USD') - ->withAllowDuplicates(true) - ->execute(); - $this->assertNotNull($response); - $this->assertEquals('00', $response->responseCode); - } - - public function testRetail014ChargeJcbSwipe() - { - $card = TestCards::JcbSwipe(); - $response = $card->charge(15.05) - ->withAllowDuplicates(true) - ->withCurrency('USD') - ->execute(); - $this->assertNotNull($response); - $this->assertEquals('00', $response->responseCode); - - // test case 58 - $refund = $response->refund(15.05) - ->withAllowDuplicates(true) - ->withCurrency('USD') - ->execute(); - $this->assertNotNull($refund); - $this->assertEquals('00', $refund->responseCode); - } - - public function testRetail014aChargeRetailMastercard24() - { - $card = TestCards::masterCard24Swipe(); - $response = $card->charge(15.34) - ->withCurrency('USD') - ->withAllowDuplicates(true) - ->execute(); - $this->assertNotNull($response); - $this->assertEquals('00', $response->responseCode); - } - - public function testRetail014bChargeRetailMastercard25() - { - $card = TestCards::masterCard25Swipe(); - $response = $card->charge(15.34) - ->withCurrency('USD') - ->withAllowDuplicates(true) - ->execute(); - $this->assertNotNull($response); - $this->assertEquals('00', $response->responseCode); - } - - public function testRetail015ChargeVisaSwipe() - { - $card = TestCards::visaSwipe(); - $response = $card->charge(15.06) - ->withCurrency('USD') - ->withAllowDuplicates(true) - ->execute(); - $this->assertNotNull($response); - $this->assertEquals('00', $response->responseCode); - - // test case 63 - $reversal = $response->reverse(15.06) - ->withAllowDuplicates(true) - ->withAuthAmount(5.06) - ->execute(); - $this->assertNotNull($response); - $this->assertEquals('00', $response->responseCode); - } - - // Manually Entered - Card Present - - public function testRetail016ChargeVisaManualCardPresent() - { - $address = new Address(); - $address->postalCode = '750241234'; - $address->streetAddress1 = '6860 Dallas Pkwy'; - - $manualcard = TestCards::visaManual(true, true); - $response = $manualcard->charge(16.01) - ->withAllowDuplicates(true) - ->withCurrency('USD') - ->withAddress($address) - ->execute(); - $this->assertNotNull($response); - $this->assertEquals('00', $response->responseCode); - } - - public function testRetail017ChargeMasterCardManualCardPresent() - { - $address = new Address(); - $address->postalCode = '75024'; - $address->streetAddress1 = '6860 Dallas Pkwy'; - - $manualcard = TestCards::masterCardManual(true, true); - $response = $manualcard->charge(16.02) - ->withAllowDuplicates(true) - ->withCurrency('USD') - ->withAddress($address) - ->execute(); - $this->assertNotNull($response); - $this->assertEquals('00', $response->responseCode); - - // test case 60 - $reverse = $response->reverse(16.02) - ->withAllowDuplicates(true) - ->execute(); - $this->assertNotNull($reverse); - $this->assertEquals('00', $reverse->responseCode); - } - - public function testRetail018ChargeDiscoverManualCardPresent() - { - $address = new Address(); - $address->postalCode = '750241234'; - - $manualcard = TestCards::discoverManual(true, true); - $response = $manualcard->charge(16.03) - ->withAllowDuplicates(true) - ->withCurrency('USD') - ->withAddress($address) - ->execute(); - $this->assertNotNull($response); - $this->assertEquals('00', $response->responseCode); - } - - public function testRetail019ChargeAmexManualCardPresent() - { - $address = new Address(); - $address->postalCode = '75024'; - $address->streetAddress1 = '6860'; - - $manualcard = TestCards::amexManual(true, true); - $response = $manualcard->charge(16.04) - ->withAllowDuplicates(true) - ->withCurrency('USD') - ->withAddress($address) - ->execute(); - $this->assertNotNull($response); - $this->assertEquals('00', $response->responseCode); - } - - public function testRetail020ChargeJcbManualCardPresent() - { - $address = new Address(); - $address->postalCode = '75024'; - - $manualcard = TestCards::JcbManual(true, true); - $response = $manualcard->charge(16.05) - ->withAllowDuplicates(true) - ->withCurrency('USD') - ->withAddress($address) - ->execute(); - $this->assertNotNull($response); - $this->assertEquals('00', $response->responseCode); - } - - public function testRetail021ChargeDiscoverManualCardPresent() - { - $address = new Address(); - $address->postalCode = '750241234'; - $address->streetAddress1 = '6860 Dallas Pkwy'; - - $manualcard = TestCards::discoverManual(true, true); - $response = $manualcard->charge(16.07) - ->withAllowDuplicates(true) - ->withCurrency('USD') - ->withAddress($address) - ->execute(); - $this->assertNotNull($response); - $this->assertEquals('00', $response->responseCode); - - // test case 64 - $reversal = $response->reverse(16.07) - ->withAllowDuplicates(true) - ->withAuthAmount(6.07) - ->execute(); - $this->assertNotNull($reversal); - $this->assertEquals('00', $reversal->responseCode); - } - - // Manually Entered - Card Not Present - - public function testRetail022ChargeVisaManualCardNotPresent() - { - $address = new Address(); - $address->postalCode = '750241234'; - $address->streetAddress1 = '6860 Dallas Pkwy'; - - $manualcard = null; - if (static::$useTokens) { - $manualcard = new CreditCardData(); - $manualcard->token = static::$visatoken; - } else { - $manualcard = TestCards::visaManual(false, true); - } - - $response = $manualcard->charge(17.01) - ->withAllowDuplicates(true) - ->withCurrency('USD') - ->withAddress($address) - ->execute(); - $this->assertNotNull($response); - $this->assertEquals('00', $response->responseCode); - } - - public function testRetail023ChargeMasterCardManualCardNotPresent() - { - $address = new Address(); - $address->postalCode = '75024'; - $address->streetAddress1 = '6860 Dallas Pkwy'; - - $manualcard = null; - if (static::$useTokens) { - $manualcard = new CreditCardData(); - $manualcard->token = static::$mastercardtoken; - } else { - $manualcard = TestCards::masterCardManual(false, true); - } - - $response = $manualcard->charge(17.02) - ->withAllowDuplicates(true) - ->withCurrency('USD') - ->withAddress($address) - ->execute(); - $this->assertNotNull($response); - $this->assertEquals('00', $response->responseCode); - - // test case 61 - $reversal = $response->reverse(17.02) - ->withAllowDuplicates(true) - ->execute(); - $this->assertNotNull($reversal); - $this->assertEquals('00', $reversal->responseCode); - } - - public function testRetail024ChargeDiscoverManualCardNotPresent() - { - $address = new Address(); - $address->postalCode = '750241234'; - - $manualcard = null; - if (static::$useTokens) { - $manualcard = new CreditCardData(); - $manualcard->token = static::$discovertoken; - } else { - $manualcard = TestCards::discoverManual(false, true); - } - - $response = $manualcard->charge(17.03) - ->withAllowDuplicates(true) - ->withCurrency('USD') - ->withAddress($address) - ->execute(); - $this->assertNotNull($response); - $this->assertEquals('00', $response->responseCode); - } - - public function testRetail025ChargeAmexManualCardNotPresent() - { - $address = new Address(); - $address->postalCode = '75024'; - $address->streetAddress1 = '6860'; - - $manualcard = null; - if (static::$useTokens) { - $manualcard = new CreditCardData(); - $manualcard->token = static::$amextoken; - } else { - $manualcard = TestCards::amexManual(false, true); - } - - $response = $manualcard->charge(17.04) - ->withAllowDuplicates(true) - ->withCurrency('USD') - ->withAddress($address) - ->execute(); - $this->assertNotNull($response); - $this->assertEquals('00', $response->responseCode); - } - - public function testRetail026ChargeJcbManualCardNotPresent() - { - $address = new Address(); - $address->postalCode = '75024'; - - $manualcard = TestCards::JcbManual(false, true); - $response = $manualcard->charge(17.05) - ->withAllowDuplicates(true) - ->withCurrency('USD') - ->withAddress($address) - ->execute(); - $this->assertNotNull($response); - $this->assertEquals('00', $response->responseCode); - } - - // Contactless - - public function testRetail027ChargeVisaContactless() - { - $card = TestCards::visaSwipe(EntryMethod::PROXIMITY); - $response = $card->charge(18.01) - ->withAllowDuplicates(true) - ->withCurrency('USD') - ->execute(); - $this->assertNotNull($response); - $this->assertEquals('00', $response->responseCode); - } - - public function testRetail028ChargeMastercardContactless() - { - $card = TestCards::masterCardSwipe(EntryMethod::PROXIMITY); - - $response = $card->charge(18.02) - ->withAllowDuplicates(true) - ->withCurrency('USD') - ->execute(); - $this->assertNotNull($response); - $this->assertEquals('00', $response->responseCode); - } - - public function testRetail029ChargeDiscoverContactless() - { - $card = TestCards::discoverSwipe(EntryMethod::PROXIMITY); - - $response = $card->charge(18.03) - ->withAllowDuplicates(true) - ->withCurrency('USD') - ->execute(); - $this->assertNotNull($response); - $this->assertEquals('00', $response->responseCode); - } - - public function testRetail030ChargeAmexContactless() - { - $card = TestCards::amexSwipe(EntryMethod::PROXIMITY); - - $response = $card->charge(18.04) - ->withAllowDuplicates(true) - ->withCurrency('USD') - ->execute(); - $this->assertNotNull($response); - $this->assertEquals('00', $response->responseCode); - } - - // AUTHORIZATION - - public function testRetail031AuthorizeVisaSwipe() - { - $card = TestCards::visaSwipe(); - - // 031a authorize - $response = $card->authorize(15.08) - ->withAllowDuplicates(true) - ->withCurrency('USD') - ->execute(); - $this->assertNotNull($response); - $this->assertEquals('00', $response->responseCode); - - // 031b capture - $captureResponse = $response->capture()->execute(); - $this->assertNotNull($captureResponse); - $this->assertEquals('00', $captureResponse->responseCode); - } - - public function testRetail032AuthorizeVisaSwipeAdditionalAuth() - { - $card = TestCards::visaSwipe(); - - // 032a authorize - $response = $card->authorize(15.09) - ->withAllowDuplicates(true) - ->withCurrency('USD') - ->execute(); - $this->assertNotNull($response); - $this->assertEquals('00', $response->responseCode); - - // 032b Additional Auth (restaurant only) - - // 032c Add to batch - $captureResponse = $response->capture()->execute(); - $this->assertNotNull($captureResponse); - $this->assertEquals('00', $captureResponse->responseCode); - } - - public function testRetail033AuthorizeMasterCardSwipe() - { - $card = TestCards::masterCardSwipe(); - - // 033a authorize - $response = $card->authorize(15.10) - ->withAllowDuplicates(true) - ->withCurrency('USD') - ->execute(); - $this->assertNotNull($response); - $this->assertEquals('00', $response->responseCode); - - // 033b capture - $captureResponse = $response->capture()->execute(); - $this->assertNotNull($captureResponse); - $this->assertEquals('00', $captureResponse->responseCode); - } - - public function testRetail033aAuthorizeDiscoverSwipe() - { - $card = TestCards::discoverSwipe(); - - $response = $card->authorize(15.10) - ->withCurrency('USD') - ->withAllowDuplicates(true) - ->execute(); - $this->assertNotNull($response); - $this->assertEquals('00', $response->responseCode); - } - - // AUTHORIZATION - Manually Entered, Card Present - - public function testRetail034AuthorizeVisaManualCardPresent() - { - $address = new Address(); - $address->postalCode = '75024'; - $address->streetAddress1 = '6860 Dallas Pkwy'; - - $card = TestCards::visaManual(true, true); - - // 034a authorize - $response = $card->authorize(16.08) - ->withAllowDuplicates(true) - ->withCurrency('USD') - ->withAddress($address) - ->execute(); - $this->assertNotNull($response); - $this->assertEquals('00', $response->responseCode); - - // 034b capture - $captureResponse = $response->capture()->execute(); - $this->assertNotNull($captureResponse); - $this->assertEquals('00', $captureResponse->responseCode); - } - - public function testRetail035AuthorizeVisaManualCardPresentAdditionalAuth() - { - $address = new Address(); - $address->postalCode = '75024'; - $address->streetAddress1 = '6860 Dallas Pkwy'; - - $card = TestCards::visaManual(true, true); - - // 035a authorize - $response = $card->authorize(16.09) - ->withAllowDuplicates(true) - ->withCurrency('USD') - ->withAddress($address) - ->execute(); - $this->assertNotNull($response); - $this->assertEquals('00', $response->responseCode); - - // 035b Additional Auth (restaurant only) - - // 035c Add to batch - $captureResponse = $response->capture()->execute(); - $this->assertNotNull($captureResponse); - $this->assertEquals('00', $captureResponse->responseCode); - } - - public function testRetail036AuthorizeMasterCardManualCardPresent() - { - $address = new Address(); - $address->postalCode = '75024'; - $address->streetAddress1 = '6860 Dallas Pkwy'; - - $card = TestCards::masterCardManual(true, true); - - // 036a authorize - $response = $card->authorize(16.10) - ->withAllowDuplicates(true) - ->withCurrency('USD') - ->withAddress($address) - ->execute(); - $this->assertNotNull($response); - $this->assertEquals('00', $response->responseCode); - - // 036b capture - $captureResponse = $response->capture()->execute(); - $this->assertNotNull($captureResponse); - $this->assertEquals('00', $captureResponse->responseCode); - } - - public function testRetail036aAuthorizeDiscoverManualCardPresent() - { - $address = new Address(); - $address->postalCode = '750241234'; - - $card = TestCards::discoverManual(true, true); - $response = $card->authorize(16.10) - ->withAllowDuplicates(true) - ->withCurrency('USD') - ->withAddress($address) - ->execute(); - $this->assertNotNull($response); - $this->assertEquals('00', $response->responseCode); - } - - // AUTHORIZATION - Manually Entered, Card Not Present - - public function testRetail037AuthorizeVisaManual() - { - $address = new Address(); - $address->postalCode = '750241234'; - $address->streetAddress1 = '6860 Dallas Pkwy'; - - $card = TestCards::visaManual(false, true); - - // 034a authorize - $response = $card->authorize(17.08) - ->withAllowDuplicates(true) - ->withCurrency('USD') - ->withAddress($address) - ->execute(); - $this->assertNotNull($response); - $this->assertEquals('00', $response->responseCode); - - // 034b capture - $captureResponse = $response->capture()->execute(); - $this->assertNotNull($captureResponse); - $this->assertEquals('00', $captureResponse->responseCode); - } - - public function testRetail038AuthorizeMasterCardManual() - { - $address = new Address(); - $address->postalCode = '750241234'; - $address->streetAddress1 = '6860'; - - $card = TestCards::masterCardManual(false, true); - - // 036a authorize - $response = $card->authorize(17.09) - ->withAllowDuplicates(true) - ->withCurrency('USD') - ->withAddress($address) - ->execute(); - $this->assertNotNull($response); - $this->assertEquals('00', $response->responseCode); - - // 036b capture - $captureResponse = $response->capture()->execute(); - $this->assertNotNull($captureResponse); - $this->assertEquals('00', $captureResponse->responseCode); - } - - public function testRetail038aAuthorizeDiscoverManual() - { - $address = new Address(); - $address->postalCode = '750241234'; - - $card = TestCards::discoverManual(false, true); - - $response = $card->authorize(17.10) - ->withAllowDuplicates(true) - ->withCurrency('USD') - ->withAddress($address) - ->execute(); - $this->assertNotNull($response); - $this->assertEquals('00', $response->responseCode); - } - - // PARTIALLY APPROVED SALE (Required) - - public function testRetail039ChargeDiscoverSwipePartialApproval() - { - $card = TestCards::discoverSwipe(); - - $response = $card->charge(40.00) - ->withAllowDuplicates(true) - ->withCurrency('USD') - ->withAllowPartialAuth(true) - ->execute(); - $this->assertNotNull($response); - $this->assertEquals('10', $response->responseCode); - $this->assertEquals(40.00, $response->authorizedAmount); - } - - public function testRetail040ChargeVisaSwipePartialApproval() - { - $card = TestCards::visaSwipe(); - $response = $card->charge(130.00) - ->withAllowDuplicates(true) - ->withCurrency('USD') - ->withAllowPartialAuth(true) - ->execute(); - $this->assertNotNull($response); - $this->assertEquals('10', $response->responseCode); - $this->assertEquals(110.00, $response->authorizedAmount); - } - - public function testRetail041ChargeDiscoverManualPartialApproval() - { - $address = new Address(); - $address->postalCode = '75024'; - $card = TestCards::discoverManual(true, true); - - $response = $card->charge(145.00) - ->withAllowDuplicates(true) - ->withCurrency('USD') - ->withAllowPartialAuth(true) - ->withAddress($address) - ->execute(); - $this->assertNotNull($response); - $this->assertEquals('10', $response->responseCode); - $this->assertEquals(65.00, $response->authorizedAmount); - } - - public function testRetail042ChargeMasterCardSwipePartialApproval() - { - $card = TestCards::masterCardSwipe(); - $response = $card->charge(155.00) - ->withAllowDuplicates(true) - ->withCurrency('USD') - ->withAllowPartialAuth(true) - ->execute(); - $this->assertNotNull($response); - $this->assertEquals('10', $response->responseCode); - $this->assertEquals(100.00, $response->authorizedAmount); - - // test case 62 - $reversal = $response->reverse(100.00) - ->withAllowDuplicates(true) - ->execute(); - $this->assertNotNull($reversal); - $this->assertEquals('00', $reversal->responseCode); - } - - /* - SALE WITH GRATUITY - Tip Edit (Tip at Settlement) - */ - - public function testRetail043ChargeVisaSwipeEditGratuity() - { - $card = TestCards::visaSwipe(); - $response = $card->charge(15.12) - ->withAllowDuplicates(true) - ->withCurrency('USD') - ->execute(); - $this->assertNotNull($response); - $this->assertEquals('00', $response->responseCode); - - $editResponse = $response->edit() - ->withAllowDuplicates(true) - ->withAmount(18.12) - ->withGratuity(3.00) - ->execute(); - $this->assertNotNull($editResponse); - $this->assertEquals('00', $editResponse->responseCode); - } - - public function testRetail044ChargeMasterCardManualEditGratuity() - { - $address = new Address(); - $address->postalCode = '75024'; - - $card = TestCards::masterCardManual(true, true); - $response = $card->charge(15.13) - ->withAllowDuplicates(true) - ->withCurrency('USD') - ->withAddress($address) - ->execute(); - $this->assertNotNull($response); - $this->assertEquals('00', $response->responseCode); - - $editResponse = $response->edit() - ->withAllowDuplicates(true) - ->withAmount(18.13) - ->withGratuity(3.00) - ->execute(); - $this->assertNotNull($editResponse); - $this->assertEquals('00', $editResponse->responseCode); - } - - // Tip on Purchase - - public function testRetail045ChargeVisaManualGratuity() - { - $address = new Address(); - $address->postalCode = '75024'; - - $card = TestCards::visaManual(true, true); - - $response = $card->charge(18.61) - ->withAllowDuplicates(true) - ->withCurrency('USD') - ->withAddress($address) - ->withGratuity(3.50) - ->execute(); - $this->assertNotNull($response); - $this->assertEquals('00', $response->responseCode); - } - - public function testRetail046ChargeMasterCardSwipeGratuity() - { - $card = TestCards::masterCardSwipe(); - - $response = $card->charge(18.62) - ->withAllowDuplicates(true) - ->withCurrency('USD') - ->withGratuity(3.50) - ->execute(); - $this->assertNotNull($response); - $this->assertEquals('00', $response->responseCode); - - $editResponse = $response->edit() - ->withAllowDuplicates(true) - ->withAmount(18.12) - ->withGratuity(3.00) - ->execute(); - $this->assertNotNull($editResponse); - $this->assertEquals('00', $editResponse->responseCode); - } - - // LEVEL II CORPORATE PURCHASE CARD - - public function testRetail047LevelIIVisaSwipeResponseB() - { - $card = TestCards::visaSwipe(); - - $response = $card->charge(112.34) - ->withAllowDuplicates(true) - ->withCurrency('USD') - ->withCommercialRequest(true) - ->execute(); - $this->assertNotNull($response); - $this->assertEquals('00', $response->responseCode); - $this->assertEquals('B', $response->commercialIndicator); - - $cpcResponse = $response->edit() - ->withAllowDuplicates(true) - ->withTaxType(TaxType::SALES_TAX) - ->withTaxAmount(1) - ->execute(); - $this->assertNotNull($cpcResponse); - $this->assertEquals('00', $cpcResponse->responseCode); - } - - public function testRetail047aLevelIIVisaSwipeResponseB() - { - $card = TestCards::visaSwipe(); - - $response = $card->charge(112.34) - ->withAllowDuplicates(true) - ->withCurrency('USD') - ->withCommercialRequest(true) - ->execute(); - $this->assertNotNull($response); - $this->assertEquals('00', $response->responseCode); - $this->assertEquals('B', $response->commercialIndicator); - - $cpcResponse = $response->edit() - ->withAllowDuplicates(true) - ->withTaxType(TaxType::NOT_USED) - ->execute(); - $this->assertNotNull($cpcResponse); - $this->assertEquals('00', $cpcResponse->responseCode); - } - - public function testRetail048LevelIIVisaSwipeResponseR() - { - $card = TestCards::visaSwipe(); - - $response = $card->charge(123.45) - ->withAllowDuplicates(true) - ->withCurrency('USD') - ->withCommercialRequest(true) - ->execute(); - $this->assertNotNull($response); - $this->assertEquals('00', $response->responseCode); - $this->assertEquals('R', $response->commercialIndicator); - - $cpcResponse = $response->edit() - ->withAllowDuplicates(true) - ->withTaxType(TaxType::TAX_EXEMPT) - ->execute(); - $this->assertNotNull($cpcResponse); - $this->assertEquals('00', $cpcResponse->responseCode); - } - - public function testRetail049LevelIIVisaManualResponseS() - { - $address = new Address(); - $address->postalCode = '75024'; - - $card = TestCards::visaManual(true, true); - - $response = $card->charge(134.56) - ->withAllowDuplicates(true) - ->withCurrency('USD') - ->withAddress($address) - ->withCommercialRequest(true) - ->execute(); - $this->assertNotNull($response); - $this->assertEquals('00', $response->responseCode); - $this->assertEquals('S', $response->commercialIndicator); - - $cpcResponse = $response->edit() - ->withAllowDuplicates(true) - ->withPoNumber('9876543210') - ->withTaxType(TaxType::SALES_TAX) - ->withTaxAmount(1) - ->execute(); - $this->assertNotNull($cpcResponse); - $this->assertEquals('00', $cpcResponse->responseCode); - } - - public function testRetail050LevelIIMasterCardSwipeResponseS() - { - $card = TestCards::masterCardSwipe(); - - $response = $card->charge(111.06) - ->withAllowDuplicates(true) - ->withCurrency('USD') - ->withCommercialRequest(true) - ->execute(); - $this->assertNotNull($response); - $this->assertEquals('00', $response->responseCode); - $this->assertEquals('S', $response->commercialIndicator); - - $cpcResponse = $response->edit() - ->withAllowDuplicates(true) - ->withPoNumber('9876543210') - ->withTaxType(TaxType::NOT_USED) - ->execute(); - $this->assertNotNull($cpcResponse); - $this->assertEquals('00', $cpcResponse->responseCode); - } - - public function testRetail051LevelIIMasterCardManualResponseS() - { - $address = new Address(); - $address->postalCode = '75024'; - - $card = TestCards::masterCardManual(true, true); - - $response = $card->charge(111.07) - ->withAllowDuplicates(true) - ->withCurrency('USD') - ->withAddress($address) - ->withCommercialRequest(true) - ->execute(); - $this->assertNotNull($response); - $this->assertEquals('00', $response->responseCode); - $this->assertEquals('S', $response->commercialIndicator); - - $cpcResponse = $response->edit() - ->withAllowDuplicates(true) - ->withPoNumber('9876543210') - ->withTaxType(TaxType::SALES_TAX) - ->withTaxAmount(1) - ->execute(); - $this->assertNotNull($cpcResponse); - $this->assertEquals('00', $cpcResponse->responseCode); - } - - public function testRetail051aLevelIIMasterCardManualResponseS() - { - $address = new Address(); - $address->postalCode = '75024'; - - $card = TestCards::masterCardManual(true, true); - $response = $card->charge(111.08) - ->withAllowDuplicates(true) - ->withCurrency('USD') - ->withAddress($address) - ->withCommercialRequest(true) - ->execute(); - $this->assertNotNull($response); - $this->assertEquals('00', $response->responseCode); - $this->assertEquals('S', $response->commercialIndicator); - - $cpcResponse = $response->edit() - ->withAllowDuplicates(true) - ->withPoNumber('9876543210') - ->withTaxType(TaxType::SALES_TAX) - ->withTaxAmount(1) - ->execute(); - $this->assertNotNull($cpcResponse); - $this->assertEquals('00', $cpcResponse->responseCode); - } - - public function testRetail052LevelIIMasterCardManualResponseS() - { - $address = new Address(); - $address->postalCode = '75024'; - - $card = TestCards::masterCardManual(true, true); - $response = $card->charge(111.09) - ->withAllowDuplicates(true) - ->withCurrency('USD') - ->withAddress($address) - ->withCommercialRequest(true) - ->execute(); - $this->assertNotNull($response); - $this->assertEquals('00', $response->responseCode); - $this->assertEquals('S', $response->commercialIndicator); - - $cpcResponse = $response->edit() - ->withAllowDuplicates(true) - ->withPoNumber('9876543210') - ->withTaxType(TaxType::TAX_EXEMPT) - ->execute(); - $this->assertNotNull($cpcResponse); - $this->assertEquals('00', $cpcResponse->responseCode); - } - - public function testRetail053LevelIIAmexSwipeNoResponse() - { - $card = TestCards::amexSwipe(); - $response = $card->charge(111.10) - ->withAllowDuplicates(true) - ->withCurrency('USD') - ->withCommercialRequest(true) - ->execute(); - $this->assertNotNull($response); - $this->assertEquals('00', $response->responseCode); - $this->assertEquals('0', $response->commercialIndicator); - - $cpcResponse = $response->edit() - ->withAllowDuplicates(true) - ->withTaxType(TaxType::SALES_TAX) - ->withTaxAmount(1) - ->execute(); - $this->assertNotNull($cpcResponse); - $this->assertEquals('00', $cpcResponse->responseCode); - } - - public function testRetail054LevelIIAmexManualNoResponse() - { - $address = new Address(); - $address->postalCode = '75024'; - - $card = TestCards::amexManual(true, true); - - $response = $card->charge(111.11) - ->withAllowDuplicates(true) - ->withCurrency('USD') - ->withAddress($address) - ->withCommercialRequest(true) - ->execute(); - $this->assertNotNull($response); - $this->assertEquals('00', $response->responseCode); - $this->assertEquals('0', $response->commercialIndicator); - - $cpcResponse = $response->edit() - ->withAllowDuplicates(true) - ->withPoNumber('9876543210') - ->withTaxType(TaxType::NOT_USED) - ->execute(); - $this->assertNotNull($cpcResponse); - $this->assertEquals('00', $cpcResponse->responseCode); - } - - public function testRetail055LevelIIAmexManualNoResponse() - { - $address = new Address(); - $address->postalCode = '75024'; - - $card = TestCards::amexManual(true, true); - $response = $card->charge(111.12) - ->withAllowDuplicates(true) - ->withCurrency('USD') - ->withAddress($address) - ->withCommercialRequest(true) - ->execute(); - $this->assertNotNull($response); - $this->assertEquals('00', $response->responseCode); - $this->assertEquals('0', $response->commercialIndicator); - - $cpcResponse = $response->edit() - ->withAllowDuplicates(true) - ->withPoNumber('9876543210') - ->withTaxType(TaxType::NOT_USED) - ->execute(); - $this->assertNotNull($cpcResponse); - $this->assertEquals('00', $cpcResponse->responseCode); - } - - public function testRetail055aLevelIIAmexManualNoResponse() - { - $address = new Address(); - $address->postalCode = '75024'; - - $card = TestCards::amexManual(true, true); - $response = $card->charge(111.13) - ->withAllowDuplicates(true) - ->withCurrency('USD') - ->withAddress($address) - ->withCommercialRequest(true) - ->execute(); - $this->assertNotNull($response); - $this->assertEquals('00', $response->responseCode); - $this->assertEquals('0', $response->commercialIndicator); - - $cpcResponse = $response->edit() - ->withAllowDuplicates(true) - ->withPoNumber('9876543210') - ->withTaxType(TaxType::TAX_EXEMPT) - ->execute(); - $this->assertNotNull($cpcResponse); - $this->assertEquals('00', $cpcResponse->responseCode); - } - - // OFFLINE SALE / AUTHORIZATION - - public function testRetail056OfflineChargeVisaManual() - { - $card = TestCards::visaManual(false, true); - - $response = $card->charge(15.12) - ->withAllowDuplicates(true) - ->withCurrency('USD') - ->withOfflineAuthCode('654321') - ->execute(); - $this->assertNotNull($response); - $this->assertEquals('00', $response->responseCode); - } - - public function testRetail056OfflineAuthVisaManual() - { - $card = TestCards::visaManual(false, true); - - $response = $card->authorize(15.11) - ->withAllowDuplicates(true) - ->withCurrency('USD') - ->withOfflineAuthCode('654321') - ->execute(); - $this->assertNotNull($response); - $this->assertEquals('00', $response->responseCode); - } - - // RETURN - - public function testRetail057ReturnMasterCard() - { - $card = TestCards::masterCardManual(false, true); - - $response = $card->refund(15.11) - ->withAllowDuplicates(true) - ->withCurrency('USD') - ->execute(); - $this->assertNotNull($response); - $this->assertEquals('00', $response->responseCode); - } - - public function testRetail057aReturnMasterCardSwipe() - { - $card = TestCards::masterCardSwipe(); - $response = $card->refund(15.15) - ->withAllowDuplicates(true) - ->withCurrency('USD') - ->execute(); - $this->assertNotNull($response); - $this->assertEquals('00', $response->responseCode); - } - - public function testRetail058ReturnJcbTransactionId() - { - // See test 14 - } - - // ONLINE VOID / REVERSAL (Required) - - public function testRetail059ReversalVisa() - { - // see test 10 - } - - public function testRetail060ReversalMasterCard() - { - // see test case 17 - } - - public function testRetail061ReversalMasterCard() - { - // see test case 23 - } - - public function testRetail062ReversalMasterCard() - { - // see test case 42 - } - - public function testRetail063ReversalVisaPartial() - { - // see test case 15 - } - - public function testRetail064ReversalDiscoverPartial() - { - // see test 21 - } - - // PIN DEBIT CARD FUNCTIONS - - public function testRetail065DebitSaleVisaSwipe() - { - $card = TestCards::asDebit(TestCards::visaSwipe(), '32539F50C245A6A93D123412324000AA'); - - $response = $card->charge(14.01) - ->withAllowDuplicates(true) - ->withCurrency('USD') - ->execute(); - $this->assertNotNull($response); - $this->assertEquals('00', $response->responseCode); - } - - public function testRetail066DebitSaleMasterCardSwipe() - { - $card = TestCards::asDebit(TestCards::masterCardSwipe(), 'F505AD81659AA42A3D123412324000AB'); - - $response = $card->charge(14.02) - ->withAllowDuplicates(true) - ->withCurrency('USD') - ->execute(); - $this->assertNotNull($response); - $this->assertEquals('00', $response->responseCode); - - // test case 71 - $reversal = $response->reverse(14.02) - ->withAllowDuplicates(true) - ->execute(); - $this->assertNotNull($reversal); - $this->assertEquals('00', $reversal->responseCode); - } - - public function testRetail067DebitSaleVisaSwipeCashBack() - { - $card = TestCards::asDebit(TestCards::visaSwipe(), '32539F50C245A6A93D123412324000AA'); - - $response = $card->charge(14.03) - ->withAllowDuplicates(true) - ->withCurrency('USD') - ->withCashBack(5.00) - ->execute(); - $this->assertNotNull($response); - $this->assertEquals('00', $response->responseCode); - } - - public function testRetail067aDebitSaleMasterCard() - { - $card = TestCards::asDebit(TestCards::masterCardSwipe(), 'F505AD81659AA42A3D123412324000AB'); - - $response = $card->charge(14.04) - ->withAllowDuplicates(true) - ->withCurrency('USD') - ->execute(); - $this->assertNotNull($response); - $this->assertEquals('00', $response->responseCode); - } - - // PARTIALLY APPROVED PURCHASE - - public function testRetail068DebitSaleMasterCardPartialApproval() - { - $card = TestCards::asDebit(TestCards::masterCardSwipe(), 'F505AD81659AA42A3D123412324000AB'); - - $response = $card->charge(33.00) - ->withAllowDuplicates(true) - ->withCurrency('USD') - ->withAllowPartialAuth(true) - ->execute(); - $this->assertNotNull($response); - $this->assertEquals('10', $response->responseCode); - $this->assertEquals(22.00, $response->authorizedAmount); - } - - public function testRetail069DebitSaleVisaPartialApproval() - { - $this->markTestSkipped(); - - $card = TestCards::asDebit(TestCards::visaSwipe(), '32539F50C245A6A93D123412324000AA'); - - $response = $card->charge(44.00) - ->withAllowDuplicates(true) - ->withCurrency('USD') - ->withAllowPartialAuth(true) - ->execute(); - $this->assertNotNull($response); - $this->assertEquals('00', $response->responseCode); - $this->assertEquals(33.00, $response->authorizedAmount); - - // test case 72 - $reversal = $response->reverse(33.00) - ->withAllowDuplicates(true) - ->execute(); - $this->assertNotNull($reversal); - $this->assertEquals('00', $reversal->responseCode); - } - - // RETURN - - public function testRetail070DebitReturnVisaSwipe() - { - $card = TestCards::asDebit(TestCards::visaSwipe(), '32539F50C245A6A93D123412324000AA'); - - $response = $card->refund(14.07) - ->withAllowDuplicates(true) - ->withCurrency('USD') - ->execute(); - $this->assertNotNull($response); - $this->assertEquals('00', $response->responseCode); - } - - public function testRetail070aDebitReturnVisaSwipe() - { - $card = TestCards::asDebit(TestCards::visaSwipe(), '32539F50C245A6A93D123412324000AA'); - - $response = $card->refund(14.08) - ->withAllowDuplicates(true) - ->withCurrency('USD') - ->execute(); - $this->assertNotNull($response); - $this->assertEquals('00', $response->responseCode); - - $reversalResponse = $response->reverse(14.08) - ->withAllowDuplicates(true) - ->execute(); - $this->assertNotNull($reversalResponse); - $this->assertEquals('00', $reversalResponse->responseCode); - } - - // REVERSAL - - public function testRetail071DebitReversalMasterCard() - { - // see test case 66 - } - - public function testRetail072DebitReversalVisa() - { - // see test case 96 - } - - /* - EBT FUNCTIONS - Food Stamp Purchase - */ - - public function testRetail080EbtfsPurchaseVisaSwipe() - { - $card = TestCards::asEBTTrack(TestCards::visaSwipe(), '32539F50C245A6A93D123412324000AA'); - - $response = $card->charge(101.01) - ->withAllowDuplicates(true) - ->withCurrency('USD') - ->execute(); - $this->assertNotNull($response); - $this->assertEquals('00', $response->responseCode); - } - - public function testRetail081EbtfsPurchaseVisaManual() - { - $card = TestCards::asEBTManual(TestCards::visaManual(false, true), '32539F50C245A6A93D123412324000AA'); - - $response = $card->charge(102.01) - ->withAllowDuplicates(true) - ->withCurrency('USD') - ->execute(); - $this->assertNotNull($response); - $this->assertEquals('00', $response->responseCode); - } - - // Food Stamp Electronic Voucher (Manual Entry Only) - - public function testRetail082EbtVoucherPurchaseVisa() - { - $card = TestCards::asEBTManual(TestCards::visaManual(false, true), '32539F50C245A6A93D123412324000AA'); - $card->SerialNumber = '123456789012345'; - $card->approvalCode = '123456'; - - $response = $card->charge(103.01) - ->withAllowDuplicates(true) - ->withCurrency('USD') - ->execute(); - $this->assertNotNull($response); - $this->assertEquals('00', $response->responseCode); - } - - // Food Stamp Balance Inquiry - - public function testRetail083EbtfsReturnVisaSwipe() - { - $card = TestCards::asEBTTrack(TestCards::visaSwipeEncrypted(), '32539F50C245A6A93D123412324000AA'); - - $response = $card->refund(104.01) - ->withAllowDuplicates(true) - ->withCurrency('USD') - ->execute(); - $this->assertNotNull($response); - $this->assertEquals('00', $response->responseCode); - } - - public function testRetail084EbtfsReturnVisaManual() - { - $card = TestCards::asEBTManual(TestCards::visaManual(false, true), '32539F50C245A6A93D123412324000AA'); - - $response = $card->refund(105.01) - ->withAllowDuplicates(true) - ->withCurrency('USD') - ->execute(); - $this->assertNotNull($response); - $this->assertEquals('00', $response->responseCode); - } - - // Food Stamp Balance Inquiry - - public function testRetail085EbtBalanceInquiryVisaSwipe() - { - $card = TestCards::asEBTTrack(TestCards::visaSwipeEncrypted(), '32539F50C245A6A93D123412324000AA'); - - $response = $card->balanceInquiry()->execute(); - $this->assertNotNull($response); - $this->assertEquals('00', $response->responseCode); - } - - public function testRetail086EbtBalanceInquiryVisaManual() - { - $card = TestCards::asEBTManual(TestCards::visaManual(true, true), '32539F50C245A6A93D123412324000AA'); - - $response = $card->balanceInquiry()->execute(); - $this->assertNotNull($response); - $this->assertEquals('00', $response->responseCode); - } - - /* - $this->assertEquals('00', $response->responseCode); - EBT CASH BENEFITS - Cash Back Purchase - */ - - public function testRetail087EbtCashBackPurchaseVisaSwipe() - { - $card = TestCards::asEBTTrack(TestCards::visaSwipeEncrypted(), '32539F50C245A6A93D123412324000AA'); - - $response = $card->charge(106.01) - ->withAllowDuplicates(true) - ->withCurrency('USD') - ->withCashBack(5.00) - ->execute(); - $this->assertNotNull($response); - $this->assertEquals('00', $response->responseCode); - } - - public function testRetail088EbtCashBackPurchaseVisaManual() - { - $card = TestCards::asEBTManual(TestCards::visaManual(false, true), '32539F50C245A6A93D123412324000AA'); - - $response = $card->charge(107.01) - ->withAllowDuplicates(true) - ->withCurrency('USD') - ->withCashBack(5.00) - ->execute(); - $this->assertNotNull($response); - $this->assertEquals('00', $response->responseCode); - } - - // No Cash Back Purchase - - public function testRetail089EbtCashBackPurchaseVisaSwipeNoCashBack() - { - $card = TestCards::asEBTTrack(TestCards::visaSwipeEncrypted(), '32539F50C245A6A93D123412324000AA'); - - $response = $card->charge(108.01) - ->withAllowDuplicates(true) - ->withCurrency('USD') - ->withCashBack(0) - ->execute(); - $this->assertNotNull($response); - $this->assertEquals('00', $response->responseCode); - } - - public function testRetail090EbtCashBackPurchaseVisaManualNoCashBack() - { - $card = TestCards::asEBTManual(TestCards::visaManual(false, true), '32539F50C245A6A93D123412324000AA'); - - $response = $card->charge(109.01) - ->withAllowDuplicates(true) - ->withCurrency('USD') - ->withCashBack(0) - ->execute(); - $this->assertNotNull($response); - $this->assertEquals('00', $response->responseCode); - } - - // Cash Back Balance Inquiry - - public function testRetail091EbtBalanceInquiryVisaSwipeCash() - { - $card = TestCards::asEBTTrack(TestCards::visaSwipeEncrypted(), '32539F50C245A6A93D123412324000AA'); - - $response = $card->balanceInquiry(InquiryType::CASH)->execute(); - $this->assertNotNull($response); - $this->assertEquals('00', $response->responseCode); - } - - public function testRetail092EbtBalanceInquiryVisaManualCash() - { - $card = TestCards::asEBTManual(TestCards::visaManual(true, true), '32539F50C245A6A93D123412324000AA'); - - $response = $card->balanceInquiry(InquiryType::CASH)->execute(); - $this->assertNotNull($response); - $this->assertEquals('00', $response->responseCode); - } - - // Cash Benefits Withdrawal - - public function testRetail093EbtBenefitWithDrawalVisaSwipe() - { - $card = TestCards::asEBTTrack(TestCards::visaSwipeEncrypted(), '32539F50C245A6A93D123412324000AA'); - - $response = $card->charge(110.01) - ->withAllowDuplicates(true) - ->withCurrency('USD') - ->execute(); - $this->assertNotNull($response); - $this->assertEquals('00', $response->responseCode); - } - - public function testRetail094EbtBenefitWithDrawalVisaManual() - { - $card = TestCards::asEBTManual(TestCards::visaManual(false, true), '32539F50C245A6A93D123412324000AA'); - - $response = $card->charge(111.01) - ->withAllowDuplicates(true) - ->withCurrency('USD') - ->withCashBack(0) - ->execute(); - $this->assertNotNull($response); - $this->assertEquals('00', $response->responseCode); - } - - /* - HMS GIFT - REWARDS - GIFT - ACTIVATE - */ - - public function testRetail095ActivateGift1Swipe() - { - $card = TestCards::giftCard1Swipe(); - - $response = $card->activate(6.00)->execute(); - $this->assertNotNull($response); - $this->assertEquals('0', $response->responseCode); - } - - public function testRetail096ActivateGift2Manual() - { - $card = TestCards::giftCard2Manual(); - - $response = $card->activate(7.00)->execute(); - $this->assertNotNull($response); - $this->assertEquals('0', $response->responseCode); - } - - // ADD VALUE - - public function testRetail097AddValueGift1Swipe() - { - $card = TestCards::giftCard1Swipe(); - - $response = $card->addValue(8.00) - ->withCurrency('USD') - ->execute(); - $this->assertNotNull($response); - $this->assertEquals('0', $response->responseCode); - } - - public function testRetail098AddValueGift2Manual() - { - $card = TestCards::giftCard2Manual(); - - $response = $card->activate(9.00)->execute(); - $this->assertNotNull($response); - $this->assertEquals('0', $response->responseCode); - } - - // BALANCE INQUIRY - - public function testRetail099BalanceInquiryGift1Swipe() - { - $card = TestCards::giftCard1Swipe(); - - $response = $card->balanceInquiry()->execute(); - $this->assertNotNull($response); - $this->assertEquals('00', $response->responseCode); - $this->assertEquals(10.00, $response->balanceAmount); - } - - public function testRetail100BalanceInquiryGift2Manual() - { - $card = TestCards::giftCard2Manual(); - - $response = $card->balanceInquiry()->execute(); - $this->assertNotNull($response); - $this->assertEquals('0', $response->responseCode); - $this->assertEquals(10.00, $response->balanceAmount); - } - - // REPLACE / TRANSFER - - public function testRetail101ReplaceGift1Swipe() - { - $oldCard = TestCards::giftCard1Swipe(); - $newCard = TestCards::giftCard2Manual(); - - $response = $oldCard->replaceWith($newCard)->execute(); - $this->assertNotNull($response); - $this->assertEquals('0', $response->responseCode); - } - - public function testRetail102ReplaceGift2Manual() - { - $newCard = TestCards::giftCard1Swipe(); - $oldCard = TestCards::giftCard2Manual(); - - $response = $oldCard->replaceWith($newCard)->execute(); - $this->assertNotNull($response); - $this->assertEquals('0', $response->responseCode); - } - - // SALE / REDEEM - - public function testRetail103SaleGift1Swipe() - { - $card = TestCards::giftCard1Swipe(); - - $response = $card->charge(1.00) - ->withCurrency('USD') - ->execute(); - $this->assertNotNull($response); - $this->assertEquals('0', $response->responseCode); - } - - public function testRetail104SaleGift2Manual() - { - $card = TestCards::giftCard2Manual(); - - $response = $card->charge(2.00) - ->withCurrency('USD') - ->execute(); - $this->assertNotNull($response); - $this->assertEquals('0', $response->responseCode); - } - - public function testRetail105SaleGift1VoidSwipe() - { - $card = TestCards::giftCard1Swipe(); - - $response = $card->charge(3.00) - ->withCurrency('USD') - ->execute(); - $this->assertNotNull($response); - $this->assertEquals('0', $response->responseCode); - - // test case 107 - $voidResponse = $response->void()->execute(); - $this->assertNotNull($voidResponse); - $this->assertEquals('0', $voidResponse->responseCode); - } - - public function testRetail106SaleGift2ReversalManual() - { - $card = TestCards::giftCard2Manual(); - - $response = $card->charge(4.00) - ->withCurrency('USD') - ->execute(); - $this->assertNotNull($response); - $this->assertEquals('0', $response->responseCode); - - //test case 108 - $voidResponse = $response->reverse(4.00)->execute(); - $this->assertNotNull($voidResponse); - $this->assertEquals('0', $voidResponse->responseCode); - } - - // VOID - - public function testRetail107VoidGift() - { - // see test case 105 - } - - // REVERSAL - - public function testRetail108ReversalGift() - { - // see test case 106 - } - - // DEACTIVATE - - public function testRetail109DeactivateGift1() - { - $card = TestCards::giftCard1Swipe(); - - $response = $card->deactivate()->execute(); - $this->assertNotNull($response); - $this->assertEquals('0', $response->responseCode); - } - - // RECEIPTS MESSAGING - - public function testRetail110ReceiptsMessaging() - { - // PRINT AND SCAN RECEIPT FOR TEST 107 - } - - /* - REWARDS - BALANCE INQUIRY - */ - - public function testRetail111BalanceInquiryRewards1() - { - $card = TestCards::giftCard1Swipe(); - - $response = $card->balanceInquiry()->execute(); - $this->assertNotNull($response); - $this->assertEquals('0', $response->responseCode); - $this->assertTrue($response->pointsBalanceAmount > 0); - } - - public function testRetail112BalanceInquiryRewards2() - { - $card = TestCards::giftCard2Manual(); - - $response = $card->balanceInquiry()->execute(); - $this->assertNotNull($response); - $this->assertEquals('0', $response->responseCode); - $this->assertTrue($response->pointsBalanceAmount > 0); - } - - // ALIAS - - public function testRetail113CreateAliasGift1() - { - $card = GiftCard::create('9725550100'); - $this->assertNotNull($card); - } - - public function testRetail114CreateAliasGift2() - { - $card = GiftCard::create('9725550100'); - $this->assertNotNull($card); - } - - public function testRetail115AddAliasGift1() - { - $card = TestCards::giftCard1Swipe(); - - $response = $card->addAlias('2145550199')->execute(); - $this->assertNotNull($response); - $this->assertEquals('0', $response->responseCode); - } - - public function testRetail116AddAliasGift2() - { - $card = TestCards::giftCard2Manual(); - - $response = $card->addAlias('2145550199')->execute(); - $this->assertNotNull($response); - $this->assertEquals('0', $response->responseCode); - } - - public function testRetail117DeleteAliasGift1() - { - $card = TestCards::giftCard1Swipe(); - - $response = $card->removeAlias('2145550199')->execute(); - $this->assertNotNull($response); - $this->assertEquals('0', $response->responseCode); - } - - public function testRetail999CloseBatch() - { - try { - $response = BatchService::closeBatch(); - $this->assertNotNull($response); - // error_log(sprintf('Batch ID: %s', $response->Id)); - // error_log(sprintf('Sequence Number: %s', $response->SequenceNumber)); - } catch (Exception $e) { - if (false === strpos($e->getMessage(), static::BATCH_NOT_OPEN) - && false === strpos($e->getMessage(), static::NO_TRANS_IN_BATCH) - ) { - $this->fail($e->getMessage()); - } - } - } -} +secretApiKey = 'skapi_cert_MaePAQBr-1QAqjfckFC8FTbRTT120bVQUlfVOjgCBw'; + $config->serviceUrl = ($this->enableCryptoUrl) ? + 'https://cert.api2-c.heartlandportico.com/': + 'https://cert.api2.heartlandportico.com'; + ServicesContainer::configureService($config); + } + + public function testRetail000CloseBatch() + { + try { + $response = BatchService::closeBatch(); + $this->assertNotNull($response); + // error_log(sprintf('Batch ID: %s', $response->Id)); + // error_log(sprintf('Sequence Number: %s', $response->sequenceNumber)); + } catch (ApiException $e) { + if (false === strpos($e->getMessage(), static::BATCH_NOT_OPEN) + && false === strpos($e->getMessage(), static::NO_TRANS_IN_BATCH) + ) { + $this->fail($e->getMessage()); + } + } + } + + /* + CREDIT CARD FUNCTIONS + CARD VERIFY + ACCOUNT VERIFICATION + */ + + public function testRetail001CardVerifyVisa() + { + $visaenc = TestCards::visaSwipeEncrypted(); + + $response = $visaenc->verify() + ->withAllowDuplicates(true) + ->withRequestMultiUseToken(static::$useTokens) + ->execute(); + $this->assertNotNull($response, '$response is null'); + $this->assertEquals('00', $response->responseCode, $response->responseMessage); + + if (static::$useTokens) { + $this->assertNotNull($response->token, 'token is null'); + + $token = new CreditCardData(); + $token->token = $response->token; + + $saleResponse = $token->charge(15.01) + ->withAllowDuplicates(true) + ->execute(); + $this->assertNotNull($saleResponse); + $this->assertEquals('00', $saleResponse->responseCode); + } + } + + public function testRetail002CardVerifyMastercardSwipe() + { + $cardenc = TestCards::masterCardSwipeEncrypted(); + + $response = $cardenc->verify() + ->withAllowDuplicates(true) + ->withRequestMultiUseToken(static::$useTokens) + ->execute(); + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode); + + if (static::$useTokens) { + $this->assertNotNull($response->token); + + $token = new CreditCardData(); + $token->token = $response->token; + + $saleResponse = $token->charge(15.02) + ->withAllowDuplicates(true) + ->execute(); + $this->assertNotNull($saleResponse); + $this->assertEquals('00', $saleResponse->responseCode); + } + } + + public function testRetail003CardVerifyDiscover() + { + $discoverenc = TestCards::discoverSwipeEncrypted(); + + $response = $discoverenc->verify() + ->withAllowDuplicates(true) + ->withRequestMultiUseToken(static::$useTokens) + ->execute(); + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode); + + if (static::$useTokens) { + $this->assertNotNull($response->token); + + $token = new CreditCardData(); + $token->token = $response->token; + + $saleResponse = $token->charge(15.03) + ->withAllowDuplicates(true) + ->execute(); + $this->assertNotNull($saleResponse); + $this->assertEquals('00', $saleResponse->responseCode); + } + } + + // Address Verification + + public function testRetail004CardVerifyAmex() + { + $address = new Address(); + $address->postalCode = '75024'; + + $manualamex = TestCards::amexManual(false, true); + + $response = $manualamex->verify() + ->withAllowDuplicates(true) + ->withAddress($address) + ->withRequestMultiUseToken(static::$useTokens) + ->execute(); + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode); + + if (static::$useTokens) { + $this->assertNotNull($response->token); + + $token = new CreditCardData(); + $token->token = $response->token; + + $saleResponse = $token->charge(15.04) + ->withAllowDuplicates(true) + ->execute(); + $this->assertNotNull($saleResponse); + $this->assertEquals('00', $saleResponse->responseCode); + } + } + + // Balance Inquiry (for Prepaid) + + public function testRetail005BalanceInquiryVisa() + { + $visaenc = TestCards::visaSwipeEncrypted(); + + $response = $visaenc->balanceInquiry()->execute(); + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode); + } + + // CREDIT SALE (For multi-use token only) + + public function testRetail006ChargeVisaSwipeToken() + { + $card = TestCards::visaSwipe(); + $response = $card->charge(15.01) + ->withCurrency('USD') + ->withRequestMultiUseToken(true) + ->withAllowDuplicates(true) + ->execute(); + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode); + + static::$visatoken = $response->token; + } + + public function testRetail007ChargeMastercardSwipeToken() + { + $card = TestCards::masterCardSwipe(); + $response = $card->charge(15.02) + ->withCurrency('USD') + ->withRequestMultiUseToken(true) + ->withAllowDuplicates(true) + ->execute(); + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode); + + static::$mastercardtoken = $response->token; + } + + public function testRetail008ChargeDiscoverSwipeToken() + { + $card = TestCards::discoverSwipe(); + $response = $card->charge(15.03) + ->withCurrency('USD') + ->withRequestMultiUseToken(true) + ->withAllowDuplicates(true) + ->execute(); + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode); + + static::$discovertoken = $response->token; + } + + public function testRetail009ChargeAmexSwipeToken() + { + $card = TestCards::amexSwipe(); + $response = $card->charge(15.04) + ->withCurrency('USD') + ->withRequestMultiUseToken(true) + ->withAllowDuplicates(true) + ->execute(); + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode); + + static::$amextoken = $response->token; + } + + /* + CREDIT SALE + SWIPED + */ + + public function testRetail010ChargeVisaSwipe() + { + $card = TestCards::visaSwipe(); + $response = $card->charge(15.01) + ->withCurrency('USD') + ->withAllowDuplicates(true) + ->execute(); + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode); + + // test 59 + $reverse = $response->reverse(15.01) + ->withAllowDuplicates(true) + ->execute(); + $this->assertNotNull($reverse); + $this->assertEquals('00', $reverse->responseCode); + } + + public function testRetail011ChargeMastercardSwipe() + { + $card = TestCards::masterCardSwipe(); + $response = $card->charge(15.02) + ->withCurrency('USD') + ->withAllowDuplicates(true) + ->execute(); + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode); + } + + public function testRetail012ChargeDiscoverSwipe() + { + $card = TestCards::discoverSwipe(); + $response = $card->charge(15.03) + ->withCurrency('USD') + ->withAllowDuplicates(true) + ->execute(); + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode); + } + + public function testRetail013ChargeAmexSwipe() + { + $card = TestCards::amexSwipe(); + $response = $card->charge(15.04) + ->withCurrency('USD') + ->withAllowDuplicates(true) + ->execute(); + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode); + } + + public function testRetail014ChargeJcbSwipe() + { + $card = TestCards::JcbSwipe(); + $response = $card->charge(15.05) + ->withAllowDuplicates(true) + ->withCurrency('USD') + ->execute(); + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode); + + // test case 58 + $refund = $response->refund(15.05) + ->withAllowDuplicates(true) + ->withCurrency('USD') + ->execute(); + $this->assertNotNull($refund); + $this->assertEquals('00', $refund->responseCode); + } + + public function testRetail014aChargeRetailMastercard24() + { + $card = TestCards::masterCard24Swipe(); + $response = $card->charge(15.34) + ->withCurrency('USD') + ->withAllowDuplicates(true) + ->execute(); + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode); + } + + public function testRetail014bChargeRetailMastercard25() + { + $card = TestCards::masterCard25Swipe(); + $response = $card->charge(15.34) + ->withCurrency('USD') + ->withAllowDuplicates(true) + ->execute(); + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode); + } + + public function testRetail015ChargeVisaSwipe() + { + $card = TestCards::visaSwipe(); + $response = $card->charge(15.06) + ->withCurrency('USD') + ->withAllowDuplicates(true) + ->execute(); + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode); + + // test case 63 + $reversal = $response->reverse(15.06) + ->withAllowDuplicates(true) + ->withAuthAmount(5.06) + ->execute(); + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode); + } + + // Manually Entered - Card Present + + public function testRetail016ChargeVisaManualCardPresent() + { + $address = new Address(); + $address->postalCode = '750241234'; + $address->streetAddress1 = '6860 Dallas Pkwy'; + + $manualcard = TestCards::visaManual(true, true); + $response = $manualcard->charge(16.01) + ->withAllowDuplicates(true) + ->withCurrency('USD') + ->withAddress($address) + ->execute(); + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode); + } + + public function testRetail017ChargeMasterCardManualCardPresent() + { + $address = new Address(); + $address->postalCode = '75024'; + $address->streetAddress1 = '6860 Dallas Pkwy'; + + $manualcard = TestCards::masterCardManual(true, true); + $response = $manualcard->charge(16.02) + ->withAllowDuplicates(true) + ->withCurrency('USD') + ->withAddress($address) + ->execute(); + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode); + + // test case 60 + $reverse = $response->reverse(16.02) + ->withAllowDuplicates(true) + ->execute(); + $this->assertNotNull($reverse); + $this->assertEquals('00', $reverse->responseCode); + } + + public function testRetail018ChargeDiscoverManualCardPresent() + { + $address = new Address(); + $address->postalCode = '750241234'; + + $manualcard = TestCards::discoverManual(true, true); + $response = $manualcard->charge(16.03) + ->withAllowDuplicates(true) + ->withCurrency('USD') + ->withAddress($address) + ->execute(); + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode); + } + + public function testRetail019ChargeAmexManualCardPresent() + { + $address = new Address(); + $address->postalCode = '75024'; + $address->streetAddress1 = '6860'; + + $manualcard = TestCards::amexManual(true, true); + $response = $manualcard->charge(16.04) + ->withAllowDuplicates(true) + ->withCurrency('USD') + ->withAddress($address) + ->execute(); + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode); + } + + public function testRetail020ChargeJcbManualCardPresent() + { + $address = new Address(); + $address->postalCode = '75024'; + + $manualcard = TestCards::JcbManual(true, true); + $response = $manualcard->charge(16.05) + ->withAllowDuplicates(true) + ->withCurrency('USD') + ->withAddress($address) + ->execute(); + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode); + } + + public function testRetail021ChargeDiscoverManualCardPresent() + { + $address = new Address(); + $address->postalCode = '750241234'; + $address->streetAddress1 = '6860 Dallas Pkwy'; + + $manualcard = TestCards::discoverManual(true, true); + $response = $manualcard->charge(16.07) + ->withAllowDuplicates(true) + ->withCurrency('USD') + ->withAddress($address) + ->execute(); + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode); + + // test case 64 + $reversal = $response->reverse(16.07) + ->withAllowDuplicates(true) + ->withAuthAmount(6.07) + ->execute(); + $this->assertNotNull($reversal); + $this->assertEquals('00', $reversal->responseCode); + } + + // Manually Entered - Card Not Present + + public function testRetail022ChargeVisaManualCardNotPresent() + { + $address = new Address(); + $address->postalCode = '750241234'; + $address->streetAddress1 = '6860 Dallas Pkwy'; + + $manualcard = null; + if (static::$useTokens) { + $manualcard = new CreditCardData(); + $manualcard->token = static::$visatoken; + } else { + $manualcard = TestCards::visaManual(false, true); + } + + $response = $manualcard->charge(17.01) + ->withAllowDuplicates(true) + ->withCurrency('USD') + ->withAddress($address) + ->execute(); + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode); + } + + public function testRetail023ChargeMasterCardManualCardNotPresent() + { + $address = new Address(); + $address->postalCode = '75024'; + $address->streetAddress1 = '6860 Dallas Pkwy'; + + $manualcard = null; + if (static::$useTokens) { + $manualcard = new CreditCardData(); + $manualcard->token = static::$mastercardtoken; + } else { + $manualcard = TestCards::masterCardManual(false, true); + } + + $response = $manualcard->charge(17.02) + ->withAllowDuplicates(true) + ->withCurrency('USD') + ->withAddress($address) + ->execute(); + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode); + + // test case 61 + $reversal = $response->reverse(17.02) + ->withAllowDuplicates(true) + ->execute(); + $this->assertNotNull($reversal); + $this->assertEquals('00', $reversal->responseCode); + } + + public function testRetail024ChargeDiscoverManualCardNotPresent() + { + $address = new Address(); + $address->postalCode = '750241234'; + + $manualcard = null; + if (static::$useTokens) { + $manualcard = new CreditCardData(); + $manualcard->token = static::$discovertoken; + } else { + $manualcard = TestCards::discoverManual(false, true); + } + + $response = $manualcard->charge(17.03) + ->withAllowDuplicates(true) + ->withCurrency('USD') + ->withAddress($address) + ->execute(); + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode); + } + + public function testRetail025ChargeAmexManualCardNotPresent() + { + $address = new Address(); + $address->postalCode = '75024'; + $address->streetAddress1 = '6860'; + + $manualcard = null; + if (static::$useTokens) { + $manualcard = new CreditCardData(); + $manualcard->token = static::$amextoken; + } else { + $manualcard = TestCards::amexManual(false, true); + } + + $response = $manualcard->charge(17.04) + ->withAllowDuplicates(true) + ->withCurrency('USD') + ->withAddress($address) + ->execute(); + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode); + } + + public function testRetail026ChargeJcbManualCardNotPresent() + { + $address = new Address(); + $address->postalCode = '75024'; + + $manualcard = TestCards::JcbManual(false, true); + $response = $manualcard->charge(17.05) + ->withAllowDuplicates(true) + ->withCurrency('USD') + ->withAddress($address) + ->execute(); + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode); + } + + // Contactless + + public function testRetail027ChargeVisaContactless() + { + $card = TestCards::visaSwipe(EntryMethod::PROXIMITY); + $response = $card->charge(18.01) + ->withAllowDuplicates(true) + ->withCurrency('USD') + ->execute(); + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode); + } + + public function testRetail028ChargeMastercardContactless() + { + $card = TestCards::masterCardSwipe(EntryMethod::PROXIMITY); + + $response = $card->charge(18.02) + ->withAllowDuplicates(true) + ->withCurrency('USD') + ->execute(); + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode); + } + + public function testRetail029ChargeDiscoverContactless() + { + $card = TestCards::discoverSwipe(EntryMethod::PROXIMITY); + + $response = $card->charge(18.03) + ->withAllowDuplicates(true) + ->withCurrency('USD') + ->execute(); + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode); + } + + public function testRetail030ChargeAmexContactless() + { + $card = TestCards::amexSwipe(EntryMethod::PROXIMITY); + + $response = $card->charge(18.04) + ->withAllowDuplicates(true) + ->withCurrency('USD') + ->execute(); + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode); + } + + // AUTHORIZATION + + public function testRetail031AuthorizeVisaSwipe() + { + $card = TestCards::visaSwipe(); + + // 031a authorize + $response = $card->authorize(15.08) + ->withAllowDuplicates(true) + ->withCurrency('USD') + ->execute(); + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode); + + // 031b capture + $captureResponse = $response->capture()->execute(); + $this->assertNotNull($captureResponse); + $this->assertEquals('00', $captureResponse->responseCode); + } + + public function testRetail032AuthorizeVisaSwipeAdditionalAuth() + { + $card = TestCards::visaSwipe(); + + // 032a authorize + $response = $card->authorize(15.09) + ->withAllowDuplicates(true) + ->withCurrency('USD') + ->execute(); + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode); + + // 032b Additional Auth (restaurant only) + + // 032c Add to batch + $captureResponse = $response->capture()->execute(); + $this->assertNotNull($captureResponse); + $this->assertEquals('00', $captureResponse->responseCode); + } + + public function testRetail033AuthorizeMasterCardSwipe() + { + $card = TestCards::masterCardSwipe(); + + // 033a authorize + $response = $card->authorize(15.10) + ->withAllowDuplicates(true) + ->withCurrency('USD') + ->execute(); + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode); + + // 033b capture + $captureResponse = $response->capture()->execute(); + $this->assertNotNull($captureResponse); + $this->assertEquals('00', $captureResponse->responseCode); + } + + public function testRetail033aAuthorizeDiscoverSwipe() + { + $card = TestCards::discoverSwipe(); + + $response = $card->authorize(15.10) + ->withCurrency('USD') + ->withAllowDuplicates(true) + ->execute(); + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode); + } + + // AUTHORIZATION - Manually Entered, Card Present + + public function testRetail034AuthorizeVisaManualCardPresent() + { + $address = new Address(); + $address->postalCode = '75024'; + $address->streetAddress1 = '6860 Dallas Pkwy'; + + $card = TestCards::visaManual(true, true); + + // 034a authorize + $response = $card->authorize(16.08) + ->withAllowDuplicates(true) + ->withCurrency('USD') + ->withAddress($address) + ->execute(); + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode); + + // 034b capture + $captureResponse = $response->capture()->execute(); + $this->assertNotNull($captureResponse); + $this->assertEquals('00', $captureResponse->responseCode); + } + + public function testRetail035AuthorizeVisaManualCardPresentAdditionalAuth() + { + $address = new Address(); + $address->postalCode = '75024'; + $address->streetAddress1 = '6860 Dallas Pkwy'; + + $card = TestCards::visaManual(true, true); + + // 035a authorize + $response = $card->authorize(16.09) + ->withAllowDuplicates(true) + ->withCurrency('USD') + ->withAddress($address) + ->execute(); + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode); + + // 035b Additional Auth (restaurant only) + + // 035c Add to batch + $captureResponse = $response->capture()->execute(); + $this->assertNotNull($captureResponse); + $this->assertEquals('00', $captureResponse->responseCode); + } + + public function testRetail036AuthorizeMasterCardManualCardPresent() + { + $address = new Address(); + $address->postalCode = '75024'; + $address->streetAddress1 = '6860 Dallas Pkwy'; + + $card = TestCards::masterCardManual(true, true); + + // 036a authorize + $response = $card->authorize(16.10) + ->withAllowDuplicates(true) + ->withCurrency('USD') + ->withAddress($address) + ->execute(); + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode); + + // 036b capture + $captureResponse = $response->capture()->execute(); + $this->assertNotNull($captureResponse); + $this->assertEquals('00', $captureResponse->responseCode); + } + + public function testRetail036aAuthorizeDiscoverManualCardPresent() + { + $address = new Address(); + $address->postalCode = '750241234'; + + $card = TestCards::discoverManual(true, true); + $response = $card->authorize(16.10) + ->withAllowDuplicates(true) + ->withCurrency('USD') + ->withAddress($address) + ->execute(); + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode); + } + + // AUTHORIZATION - Manually Entered, Card Not Present + + public function testRetail037AuthorizeVisaManual() + { + $address = new Address(); + $address->postalCode = '750241234'; + $address->streetAddress1 = '6860 Dallas Pkwy'; + + $card = TestCards::visaManual(false, true); + + // 034a authorize + $response = $card->authorize(17.08) + ->withAllowDuplicates(true) + ->withCurrency('USD') + ->withAddress($address) + ->execute(); + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode); + + // 034b capture + $captureResponse = $response->capture()->execute(); + $this->assertNotNull($captureResponse); + $this->assertEquals('00', $captureResponse->responseCode); + } + + public function testRetail038AuthorizeMasterCardManual() + { + $address = new Address(); + $address->postalCode = '750241234'; + $address->streetAddress1 = '6860'; + + $card = TestCards::masterCardManual(false, true); + + // 036a authorize + $response = $card->authorize(17.09) + ->withAllowDuplicates(true) + ->withCurrency('USD') + ->withAddress($address) + ->execute(); + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode); + + // 036b capture + $captureResponse = $response->capture()->execute(); + $this->assertNotNull($captureResponse); + $this->assertEquals('00', $captureResponse->responseCode); + } + + public function testRetail038aAuthorizeDiscoverManual() + { + $address = new Address(); + $address->postalCode = '750241234'; + + $card = TestCards::discoverManual(false, true); + + $response = $card->authorize(17.10) + ->withAllowDuplicates(true) + ->withCurrency('USD') + ->withAddress($address) + ->execute(); + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode); + } + + // PARTIALLY APPROVED SALE (Required) + + public function testRetail039ChargeDiscoverSwipePartialApproval() + { + $card = TestCards::discoverSwipe(); + + $response = $card->charge(40.00) + ->withAllowDuplicates(true) + ->withCurrency('USD') + ->withAllowPartialAuth(true) + ->execute(); + $this->assertNotNull($response); + $this->assertEquals('10', $response->responseCode); + $this->assertEquals(40.00, $response->authorizedAmount); + } + + public function testRetail040ChargeVisaSwipePartialApproval() + { + $card = TestCards::visaSwipe(); + $response = $card->charge(130.00) + ->withAllowDuplicates(true) + ->withCurrency('USD') + ->withAllowPartialAuth(true) + ->execute(); + $this->assertNotNull($response); + $this->assertEquals('10', $response->responseCode); + $this->assertEquals(110.00, $response->authorizedAmount); + } + + public function testRetail041ChargeDiscoverManualPartialApproval() + { + $address = new Address(); + $address->postalCode = '75024'; + $card = TestCards::discoverManual(true, true); + + $response = $card->charge(145.00) + ->withAllowDuplicates(true) + ->withCurrency('USD') + ->withAllowPartialAuth(true) + ->withAddress($address) + ->execute(); + $this->assertNotNull($response); + $this->assertEquals('10', $response->responseCode); + $this->assertEquals(65.00, $response->authorizedAmount); + } + + public function testRetail042ChargeMasterCardSwipePartialApproval() + { + $card = TestCards::masterCardSwipe(); + $response = $card->charge(155.00) + ->withAllowDuplicates(true) + ->withCurrency('USD') + ->withAllowPartialAuth(true) + ->execute(); + $this->assertNotNull($response); + $this->assertEquals('10', $response->responseCode); + $this->assertEquals(100.00, $response->authorizedAmount); + + // test case 62 + $reversal = $response->reverse(100.00) + ->withAllowDuplicates(true) + ->execute(); + $this->assertNotNull($reversal); + $this->assertEquals('00', $reversal->responseCode); + } + + /* + SALE WITH GRATUITY + Tip Edit (Tip at Settlement) + */ + + public function testRetail043ChargeVisaSwipeEditGratuity() + { + $card = TestCards::visaSwipe(); + $response = $card->charge(15.12) + ->withAllowDuplicates(true) + ->withCurrency('USD') + ->execute(); + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode); + + $editResponse = $response->edit() + ->withAllowDuplicates(true) + ->withAmount(18.12) + ->withGratuity(3.00) + ->execute(); + $this->assertNotNull($editResponse); + $this->assertEquals('00', $editResponse->responseCode); + } + + public function testRetail044ChargeMasterCardManualEditGratuity() + { + $address = new Address(); + $address->postalCode = '75024'; + + $card = TestCards::masterCardManual(true, true); + $response = $card->charge(15.13) + ->withAllowDuplicates(true) + ->withCurrency('USD') + ->withAddress($address) + ->execute(); + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode); + + $editResponse = $response->edit() + ->withAllowDuplicates(true) + ->withAmount(18.13) + ->withGratuity(3.00) + ->execute(); + $this->assertNotNull($editResponse); + $this->assertEquals('00', $editResponse->responseCode); + } + + // Tip on Purchase + + public function testRetail045ChargeVisaManualGratuity() + { + $address = new Address(); + $address->postalCode = '75024'; + + $card = TestCards::visaManual(true, true); + + $response = $card->charge(18.61) + ->withAllowDuplicates(true) + ->withCurrency('USD') + ->withAddress($address) + ->withGratuity(3.50) + ->execute(); + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode); + } + + public function testRetail046ChargeMasterCardSwipeGratuity() + { + $card = TestCards::masterCardSwipe(); + + $response = $card->charge(18.62) + ->withAllowDuplicates(true) + ->withCurrency('USD') + ->withGratuity(3.50) + ->execute(); + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode); + + $editResponse = $response->edit() + ->withAllowDuplicates(true) + ->withAmount(18.12) + ->withGratuity(3.00) + ->execute(); + $this->assertNotNull($editResponse); + $this->assertEquals('00', $editResponse->responseCode); + } + + // LEVEL II CORPORATE PURCHASE CARD + + public function testRetail047LevelIIVisaSwipeResponseB() + { + $card = TestCards::visaSwipe(); + + $response = $card->charge(112.34) + ->withAllowDuplicates(true) + ->withCurrency('USD') + ->withCommercialRequest(true) + ->execute(); + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode); + $this->assertEquals('B', $response->commercialIndicator); + + $cpcResponse = $response->edit() + ->withAllowDuplicates(true) + ->withTaxType(TaxType::SALES_TAX) + ->withTaxAmount(1) + ->execute(); + $this->assertNotNull($cpcResponse); + $this->assertEquals('00', $cpcResponse->responseCode); + } + + public function testRetail047aLevelIIVisaSwipeResponseB() + { + $card = TestCards::visaSwipe(); + + $response = $card->charge(112.34) + ->withAllowDuplicates(true) + ->withCurrency('USD') + ->withCommercialRequest(true) + ->execute(); + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode); + $this->assertEquals('B', $response->commercialIndicator); + + $cpcResponse = $response->edit() + ->withAllowDuplicates(true) + ->withTaxType(TaxType::NOT_USED) + ->execute(); + $this->assertNotNull($cpcResponse); + $this->assertEquals('00', $cpcResponse->responseCode); + } + + public function testRetail048LevelIIVisaSwipeResponseR() + { + $card = TestCards::visaSwipe(); + + $response = $card->charge(123.45) + ->withAllowDuplicates(true) + ->withCurrency('USD') + ->withCommercialRequest(true) + ->execute(); + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode); + $this->assertEquals('R', $response->commercialIndicator); + + $cpcResponse = $response->edit() + ->withAllowDuplicates(true) + ->withTaxType(TaxType::TAX_EXEMPT) + ->execute(); + $this->assertNotNull($cpcResponse); + $this->assertEquals('00', $cpcResponse->responseCode); + } + + public function testRetail049LevelIIVisaManualResponseS() + { + $address = new Address(); + $address->postalCode = '75024'; + + $card = TestCards::visaManual(true, true); + + $response = $card->charge(134.56) + ->withAllowDuplicates(true) + ->withCurrency('USD') + ->withAddress($address) + ->withCommercialRequest(true) + ->execute(); + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode); + $this->assertEquals('S', $response->commercialIndicator); + + $cpcResponse = $response->edit() + ->withAllowDuplicates(true) + ->withPoNumber('9876543210') + ->withTaxType(TaxType::SALES_TAX) + ->withTaxAmount(1) + ->execute(); + $this->assertNotNull($cpcResponse); + $this->assertEquals('00', $cpcResponse->responseCode); + } + + public function testRetail050LevelIIMasterCardSwipeResponseS() + { + $card = TestCards::masterCardSwipe(); + + $response = $card->charge(111.06) + ->withAllowDuplicates(true) + ->withCurrency('USD') + ->withCommercialRequest(true) + ->execute(); + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode); + $this->assertEquals('S', $response->commercialIndicator); + + $cpcResponse = $response->edit() + ->withAllowDuplicates(true) + ->withPoNumber('9876543210') + ->withTaxType(TaxType::NOT_USED) + ->execute(); + $this->assertNotNull($cpcResponse); + $this->assertEquals('00', $cpcResponse->responseCode); + } + + public function testRetail051LevelIIMasterCardManualResponseS() + { + $address = new Address(); + $address->postalCode = '75024'; + + $card = TestCards::masterCardManual(true, true); + + $response = $card->charge(111.07) + ->withAllowDuplicates(true) + ->withCurrency('USD') + ->withAddress($address) + ->withCommercialRequest(true) + ->execute(); + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode); + $this->assertEquals('S', $response->commercialIndicator); + + $cpcResponse = $response->edit() + ->withAllowDuplicates(true) + ->withPoNumber('9876543210') + ->withTaxType(TaxType::SALES_TAX) + ->withTaxAmount(1) + ->execute(); + $this->assertNotNull($cpcResponse); + $this->assertEquals('00', $cpcResponse->responseCode); + } + + public function testRetail051aLevelIIMasterCardManualResponseS() + { + $address = new Address(); + $address->postalCode = '75024'; + + $card = TestCards::masterCardManual(true, true); + $response = $card->charge(111.08) + ->withAllowDuplicates(true) + ->withCurrency('USD') + ->withAddress($address) + ->withCommercialRequest(true) + ->execute(); + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode); + $this->assertEquals('S', $response->commercialIndicator); + + $cpcResponse = $response->edit() + ->withAllowDuplicates(true) + ->withPoNumber('9876543210') + ->withTaxType(TaxType::SALES_TAX) + ->withTaxAmount(1) + ->execute(); + $this->assertNotNull($cpcResponse); + $this->assertEquals('00', $cpcResponse->responseCode); + } + + public function testRetail052LevelIIMasterCardManualResponseS() + { + $address = new Address(); + $address->postalCode = '75024'; + + $card = TestCards::masterCardManual(true, true); + $response = $card->charge(111.09) + ->withAllowDuplicates(true) + ->withCurrency('USD') + ->withAddress($address) + ->withCommercialRequest(true) + ->execute(); + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode); + $this->assertEquals('S', $response->commercialIndicator); + + $cpcResponse = $response->edit() + ->withAllowDuplicates(true) + ->withPoNumber('9876543210') + ->withTaxType(TaxType::TAX_EXEMPT) + ->execute(); + $this->assertNotNull($cpcResponse); + $this->assertEquals('00', $cpcResponse->responseCode); + } + + public function testRetail053LevelIIAmexSwipeNoResponse() + { + $card = TestCards::amexSwipe(); + $response = $card->charge(111.10) + ->withAllowDuplicates(true) + ->withCurrency('USD') + ->withCommercialRequest(true) + ->execute(); + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode); + $this->assertEquals('0', $response->commercialIndicator); + + $cpcResponse = $response->edit() + ->withAllowDuplicates(true) + ->withTaxType(TaxType::SALES_TAX) + ->withTaxAmount(1) + ->execute(); + $this->assertNotNull($cpcResponse); + $this->assertEquals('00', $cpcResponse->responseCode); + } + + public function testRetail054LevelIIAmexManualNoResponse() + { + $address = new Address(); + $address->postalCode = '75024'; + + $card = TestCards::amexManual(true, true); + + $response = $card->charge(111.11) + ->withAllowDuplicates(true) + ->withCurrency('USD') + ->withAddress($address) + ->withCommercialRequest(true) + ->execute(); + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode); + $this->assertEquals('0', $response->commercialIndicator); + + $cpcResponse = $response->edit() + ->withAllowDuplicates(true) + ->withPoNumber('9876543210') + ->withTaxType(TaxType::NOT_USED) + ->execute(); + $this->assertNotNull($cpcResponse); + $this->assertEquals('00', $cpcResponse->responseCode); + } + + public function testRetail055LevelIIAmexManualNoResponse() + { + $address = new Address(); + $address->postalCode = '75024'; + + $card = TestCards::amexManual(true, true); + $response = $card->charge(111.12) + ->withAllowDuplicates(true) + ->withCurrency('USD') + ->withAddress($address) + ->withCommercialRequest(true) + ->execute(); + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode); + $this->assertEquals('0', $response->commercialIndicator); + + $cpcResponse = $response->edit() + ->withAllowDuplicates(true) + ->withPoNumber('9876543210') + ->withTaxType(TaxType::NOT_USED) + ->execute(); + $this->assertNotNull($cpcResponse); + $this->assertEquals('00', $cpcResponse->responseCode); + } + + public function testRetail055aLevelIIAmexManualNoResponse() + { + $address = new Address(); + $address->postalCode = '75024'; + + $card = TestCards::amexManual(true, true); + $response = $card->charge(111.13) + ->withAllowDuplicates(true) + ->withCurrency('USD') + ->withAddress($address) + ->withCommercialRequest(true) + ->execute(); + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode); + $this->assertEquals('0', $response->commercialIndicator); + + $cpcResponse = $response->edit() + ->withAllowDuplicates(true) + ->withPoNumber('9876543210') + ->withTaxType(TaxType::TAX_EXEMPT) + ->execute(); + $this->assertNotNull($cpcResponse); + $this->assertEquals('00', $cpcResponse->responseCode); + } + + // OFFLINE SALE / AUTHORIZATION + + public function testRetail056OfflineChargeVisaManual() + { + $card = TestCards::visaManual(false, true); + + $response = $card->charge(15.12) + ->withAllowDuplicates(true) + ->withCurrency('USD') + ->withOfflineAuthCode('654321') + ->execute(); + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode); + } + + public function testRetail056OfflineAuthVisaManual() + { + $card = TestCards::visaManual(false, true); + + $response = $card->authorize(15.11) + ->withAllowDuplicates(true) + ->withCurrency('USD') + ->withOfflineAuthCode('654321') + ->execute(); + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode); + } + + // RETURN + + public function testRetail057ReturnMasterCard() + { + $card = TestCards::masterCardManual(false, true); + + $response = $card->refund(15.11) + ->withAllowDuplicates(true) + ->withCurrency('USD') + ->execute(); + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode); + } + + public function testRetail057aReturnMasterCardSwipe() + { + $card = TestCards::masterCardSwipe(); + $response = $card->refund(15.15) + ->withAllowDuplicates(true) + ->withCurrency('USD') + ->execute(); + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode); + } + + public function testRetail058ReturnJcbTransactionId() + { + // See test 14 + } + + // ONLINE VOID / REVERSAL (Required) + + public function testRetail059ReversalVisa() + { + // see test 10 + } + + public function testRetail060ReversalMasterCard() + { + // see test case 17 + } + + public function testRetail061ReversalMasterCard() + { + // see test case 23 + } + + public function testRetail062ReversalMasterCard() + { + // see test case 42 + } + + public function testRetail063ReversalVisaPartial() + { + // see test case 15 + } + + public function testRetail064ReversalDiscoverPartial() + { + // see test 21 + } + + // PIN DEBIT CARD FUNCTIONS + + public function testRetail065DebitSaleVisaSwipe() + { + $card = TestCards::asDebit(TestCards::visaSwipe(), '32539F50C245A6A93D123412324000AA'); + + $response = $card->charge(14.01) + ->withAllowDuplicates(true) + ->withCurrency('USD') + ->execute(); + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode); + } + + public function testRetail066DebitSaleMasterCardSwipe() + { + $card = TestCards::asDebit(TestCards::masterCardSwipe(), 'F505AD81659AA42A3D123412324000AB'); + + $response = $card->charge(14.02) + ->withAllowDuplicates(true) + ->withCurrency('USD') + ->execute(); + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode); + + // test case 71 + $reversal = $response->reverse(14.02) + ->withAllowDuplicates(true) + ->execute(); + $this->assertNotNull($reversal); + $this->assertEquals('00', $reversal->responseCode); + } + + public function testRetail067DebitSaleVisaSwipeCashBack() + { + $card = TestCards::asDebit(TestCards::visaSwipe(), '32539F50C245A6A93D123412324000AA'); + + $response = $card->charge(14.03) + ->withAllowDuplicates(true) + ->withCurrency('USD') + ->withCashBack(5.00) + ->execute(); + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode); + } + + public function testRetail067aDebitSaleMasterCard() + { + $card = TestCards::asDebit(TestCards::masterCardSwipe(), 'F505AD81659AA42A3D123412324000AB'); + + $response = $card->charge(14.04) + ->withAllowDuplicates(true) + ->withCurrency('USD') + ->execute(); + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode); + } + + // PARTIALLY APPROVED PURCHASE + + public function testRetail068DebitSaleMasterCardPartialApproval() + { + $card = TestCards::asDebit(TestCards::masterCardSwipe(), 'F505AD81659AA42A3D123412324000AB'); + + $response = $card->charge(33.00) + ->withAllowDuplicates(true) + ->withCurrency('USD') + ->withAllowPartialAuth(true) + ->execute(); + $this->assertNotNull($response); + $this->assertEquals('10', $response->responseCode); + $this->assertEquals(22.00, $response->authorizedAmount); + } + + public function testRetail069DebitSaleVisaPartialApproval() + { + $this->markTestSkipped(); + + $card = TestCards::asDebit(TestCards::visaSwipe(), '32539F50C245A6A93D123412324000AA'); + + $response = $card->charge(44.00) + ->withAllowDuplicates(true) + ->withCurrency('USD') + ->withAllowPartialAuth(true) + ->execute(); + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode); + $this->assertEquals(33.00, $response->authorizedAmount); + + // test case 72 + $reversal = $response->reverse(33.00) + ->withAllowDuplicates(true) + ->execute(); + $this->assertNotNull($reversal); + $this->assertEquals('00', $reversal->responseCode); + } + + // RETURN + + public function testRetail070DebitReturnVisaSwipe() + { + $card = TestCards::asDebit(TestCards::visaSwipe(), '32539F50C245A6A93D123412324000AA'); + + $response = $card->refund(14.07) + ->withAllowDuplicates(true) + ->withCurrency('USD') + ->execute(); + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode); + } + + public function testRetail070aDebitReturnVisaSwipe() + { + $card = TestCards::asDebit(TestCards::visaSwipe(), '32539F50C245A6A93D123412324000AA'); + + $response = $card->refund(14.08) + ->withAllowDuplicates(true) + ->withCurrency('USD') + ->execute(); + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode); + + $reversalResponse = $response->reverse(14.08) + ->withAllowDuplicates(true) + ->execute(); + $this->assertNotNull($reversalResponse); + $this->assertEquals('00', $reversalResponse->responseCode); + } + + // REVERSAL + + public function testRetail071DebitReversalMasterCard() + { + // see test case 66 + } + + public function testRetail072DebitReversalVisa() + { + // see test case 96 + } + + /* + EBT FUNCTIONS + Food Stamp Purchase + */ + + public function testRetail080EbtfsPurchaseVisaSwipe() + { + $card = TestCards::asEBTTrack(TestCards::visaSwipe(), '32539F50C245A6A93D123412324000AA'); + + $response = $card->charge(101.01) + ->withAllowDuplicates(true) + ->withCurrency('USD') + ->execute(); + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode); + } + + public function testRetail081EbtfsPurchaseVisaManual() + { + $card = TestCards::asEBTManual(TestCards::visaManual(false, true), '32539F50C245A6A93D123412324000AA'); + + $response = $card->charge(102.01) + ->withAllowDuplicates(true) + ->withCurrency('USD') + ->execute(); + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode); + } + + // Food Stamp Electronic Voucher (Manual Entry Only) + + public function testRetail082EbtVoucherPurchaseVisa() + { + $card = TestCards::asEBTManual(TestCards::visaManual(false, true), '32539F50C245A6A93D123412324000AA'); + $card->SerialNumber = '123456789012345'; + $card->approvalCode = '123456'; + + $response = $card->charge(103.01) + ->withAllowDuplicates(true) + ->withCurrency('USD') + ->execute(); + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode); + } + + // Food Stamp Balance Inquiry + + public function testRetail083EbtfsReturnVisaSwipe() + { + $card = TestCards::asEBTTrack(TestCards::visaSwipeEncrypted(), '32539F50C245A6A93D123412324000AA'); + + $response = $card->refund(104.01) + ->withAllowDuplicates(true) + ->withCurrency('USD') + ->execute(); + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode); + } + + public function testRetail084EbtfsReturnVisaManual() + { + $card = TestCards::asEBTManual(TestCards::visaManual(false, true), '32539F50C245A6A93D123412324000AA'); + + $response = $card->refund(105.01) + ->withAllowDuplicates(true) + ->withCurrency('USD') + ->execute(); + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode); + } + + // Food Stamp Balance Inquiry + + public function testRetail085EbtBalanceInquiryVisaSwipe() + { + $card = TestCards::asEBTTrack(TestCards::visaSwipeEncrypted(), '32539F50C245A6A93D123412324000AA'); + + $response = $card->balanceInquiry()->execute(); + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode); + } + + public function testRetail086EbtBalanceInquiryVisaManual() + { + $card = TestCards::asEBTManual(TestCards::visaManual(true, true), '32539F50C245A6A93D123412324000AA'); + + $response = $card->balanceInquiry()->execute(); + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode); + } + + /* + $this->assertEquals('00', $response->responseCode); + EBT CASH BENEFITS + Cash Back Purchase + */ + + public function testRetail087EbtCashBackPurchaseVisaSwipe() + { + $card = TestCards::asEBTTrack(TestCards::visaSwipeEncrypted(), '32539F50C245A6A93D123412324000AA'); + + $response = $card->charge(106.01) + ->withAllowDuplicates(true) + ->withCurrency('USD') + ->withCashBack(5.00) + ->execute(); + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode); + } + + public function testRetail088EbtCashBackPurchaseVisaManual() + { + $card = TestCards::asEBTManual(TestCards::visaManual(false, true), '32539F50C245A6A93D123412324000AA'); + + $response = $card->charge(107.01) + ->withAllowDuplicates(true) + ->withCurrency('USD') + ->withCashBack(5.00) + ->execute(); + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode); + } + + // No Cash Back Purchase + + public function testRetail089EbtCashBackPurchaseVisaSwipeNoCashBack() + { + $card = TestCards::asEBTTrack(TestCards::visaSwipeEncrypted(), '32539F50C245A6A93D123412324000AA'); + + $response = $card->charge(108.01) + ->withAllowDuplicates(true) + ->withCurrency('USD') + ->withCashBack(0) + ->execute(); + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode); + } + + public function testRetail090EbtCashBackPurchaseVisaManualNoCashBack() + { + $card = TestCards::asEBTManual(TestCards::visaManual(false, true), '32539F50C245A6A93D123412324000AA'); + + $response = $card->charge(109.01) + ->withAllowDuplicates(true) + ->withCurrency('USD') + ->withCashBack(0) + ->execute(); + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode); + } + + // Cash Back Balance Inquiry + + public function testRetail091EbtBalanceInquiryVisaSwipeCash() + { + $card = TestCards::asEBTTrack(TestCards::visaSwipeEncrypted(), '32539F50C245A6A93D123412324000AA'); + + $response = $card->balanceInquiry(InquiryType::CASH)->execute(); + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode); + } + + public function testRetail092EbtBalanceInquiryVisaManualCash() + { + $card = TestCards::asEBTManual(TestCards::visaManual(true, true), '32539F50C245A6A93D123412324000AA'); + + $response = $card->balanceInquiry(InquiryType::CASH)->execute(); + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode); + } + + // Cash Benefits Withdrawal + + public function testRetail093EbtBenefitWithDrawalVisaSwipe() + { + $card = TestCards::asEBTTrack(TestCards::visaSwipeEncrypted(), '32539F50C245A6A93D123412324000AA'); + + $response = $card->charge(110.01) + ->withAllowDuplicates(true) + ->withCurrency('USD') + ->execute(); + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode); + } + + public function testRetail094EbtBenefitWithDrawalVisaManual() + { + $card = TestCards::asEBTManual(TestCards::visaManual(false, true), '32539F50C245A6A93D123412324000AA'); + + $response = $card->charge(111.01) + ->withAllowDuplicates(true) + ->withCurrency('USD') + ->withCashBack(0) + ->execute(); + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode); + } + + /* + HMS GIFT - REWARDS + GIFT + ACTIVATE + */ + + public function testRetail095ActivateGift1Swipe() + { + $card = TestCards::giftCard1Swipe(); + + $response = $card->activate(6.00)->execute(); + $this->assertNotNull($response); + $this->assertEquals('0', $response->responseCode); + } + + public function testRetail096ActivateGift2Manual() + { + $card = TestCards::giftCard2Manual(); + + $response = $card->activate(7.00)->execute(); + $this->assertNotNull($response); + $this->assertEquals('0', $response->responseCode); + } + + // ADD VALUE + + public function testRetail097AddValueGift1Swipe() + { + $card = TestCards::giftCard1Swipe(); + + $response = $card->addValue(8.00) + ->withCurrency('USD') + ->execute(); + $this->assertNotNull($response); + $this->assertEquals('0', $response->responseCode); + } + + public function testRetail098AddValueGift2Manual() + { + $card = TestCards::giftCard2Manual(); + + $response = $card->activate(9.00)->execute(); + $this->assertNotNull($response); + $this->assertEquals('0', $response->responseCode); + } + + // BALANCE INQUIRY + + public function testRetail099BalanceInquiryGift1Swipe() + { + $card = TestCards::giftCard1Swipe(); + + $response = $card->balanceInquiry()->execute(); + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode); + $this->assertEquals(10.00, $response->balanceAmount); + } + + public function testRetail100BalanceInquiryGift2Manual() + { + $card = TestCards::giftCard2Manual(); + + $response = $card->balanceInquiry()->execute(); + $this->assertNotNull($response); + $this->assertEquals('0', $response->responseCode); + $this->assertEquals(10.00, $response->balanceAmount); + } + + // REPLACE / TRANSFER + + public function testRetail101ReplaceGift1Swipe() + { + $oldCard = TestCards::giftCard1Swipe(); + $newCard = TestCards::giftCard2Manual(); + + $response = $oldCard->replaceWith($newCard)->execute(); + $this->assertNotNull($response); + $this->assertEquals('0', $response->responseCode); + } + + public function testRetail102ReplaceGift2Manual() + { + $newCard = TestCards::giftCard1Swipe(); + $oldCard = TestCards::giftCard2Manual(); + + $response = $oldCard->replaceWith($newCard)->execute(); + $this->assertNotNull($response); + $this->assertEquals('0', $response->responseCode); + } + + // SALE / REDEEM + + public function testRetail103SaleGift1Swipe() + { + $card = TestCards::giftCard1Swipe(); + + $response = $card->charge(1.00) + ->withCurrency('USD') + ->execute(); + $this->assertNotNull($response); + $this->assertEquals('0', $response->responseCode); + } + + public function testRetail104SaleGift2Manual() + { + $card = TestCards::giftCard2Manual(); + + $response = $card->charge(2.00) + ->withCurrency('USD') + ->execute(); + $this->assertNotNull($response); + $this->assertEquals('0', $response->responseCode); + } + + public function testRetail105SaleGift1VoidSwipe() + { + $card = TestCards::giftCard1Swipe(); + + $response = $card->charge(3.00) + ->withCurrency('USD') + ->execute(); + $this->assertNotNull($response); + $this->assertEquals('0', $response->responseCode); + + // test case 107 + $voidResponse = $response->void()->execute(); + $this->assertNotNull($voidResponse); + $this->assertEquals('0', $voidResponse->responseCode); + } + + public function testRetail106SaleGift2ReversalManual() + { + $card = TestCards::giftCard2Manual(); + + $response = $card->charge(4.00) + ->withCurrency('USD') + ->execute(); + $this->assertNotNull($response); + $this->assertEquals('0', $response->responseCode); + + //test case 108 + $voidResponse = $response->reverse(4.00)->execute(); + $this->assertNotNull($voidResponse); + $this->assertEquals('0', $voidResponse->responseCode); + } + + // VOID + + public function testRetail107VoidGift() + { + // see test case 105 + } + + // REVERSAL + + public function testRetail108ReversalGift() + { + // see test case 106 + } + + // DEACTIVATE + + public function testRetail109DeactivateGift1() + { + $card = TestCards::giftCard1Swipe(); + + $response = $card->deactivate()->execute(); + $this->assertNotNull($response); + $this->assertEquals('0', $response->responseCode); + } + + // RECEIPTS MESSAGING + + public function testRetail110ReceiptsMessaging() + { + // PRINT AND SCAN RECEIPT FOR TEST 107 + } + + /* + REWARDS + BALANCE INQUIRY + */ + + public function testRetail111BalanceInquiryRewards1() + { + $card = TestCards::giftCard1Swipe(); + + $response = $card->balanceInquiry()->execute(); + $this->assertNotNull($response); + $this->assertEquals('0', $response->responseCode); + $this->assertTrue($response->pointsBalanceAmount > 0); + } + + public function testRetail112BalanceInquiryRewards2() + { + $card = TestCards::giftCard2Manual(); + + $response = $card->balanceInquiry()->execute(); + $this->assertNotNull($response); + $this->assertEquals('0', $response->responseCode); + $this->assertTrue($response->pointsBalanceAmount > 0); + } + + // ALIAS + + public function testRetail113CreateAliasGift1() + { + $card = GiftCard::create('9725550100'); + $this->assertNotNull($card); + } + + public function testRetail114CreateAliasGift2() + { + $card = GiftCard::create('9725550100'); + $this->assertNotNull($card); + } + + public function testRetail115AddAliasGift1() + { + $card = TestCards::giftCard1Swipe(); + + $response = $card->addAlias('2145550199')->execute(); + $this->assertNotNull($response); + $this->assertEquals('0', $response->responseCode); + } + + public function testRetail116AddAliasGift2() + { + $card = TestCards::giftCard2Manual(); + + $response = $card->addAlias('2145550199')->execute(); + $this->assertNotNull($response); + $this->assertEquals('0', $response->responseCode); + } + + public function testRetail117DeleteAliasGift1() + { + $card = TestCards::giftCard1Swipe(); + + $response = $card->removeAlias('2145550199')->execute(); + $this->assertNotNull($response); + $this->assertEquals('0', $response->responseCode); + } + + public function testRetail999CloseBatch() + { + try { + $response = BatchService::closeBatch(); + $this->assertNotNull($response); + // error_log(sprintf('Batch ID: %s', $response->Id)); + // error_log(sprintf('Sequence Number: %s', $response->SequenceNumber)); + } catch (Exception $e) { + if (false === strpos($e->getMessage(), static::BATCH_NOT_OPEN) + && false === strpos($e->getMessage(), static::NO_TRANS_IN_BATCH) + ) { + $this->fail($e->getMessage()); + } + } + } +} diff --git a/test/Integration/Gateways/PorticoConnector/CreditTest.php b/test/Integration/Gateways/PorticoConnector/CreditTest.php index 2a9316bf..7866adf8 100644 --- a/test/Integration/Gateways/PorticoConnector/CreditTest.php +++ b/test/Integration/Gateways/PorticoConnector/CreditTest.php @@ -1,365 +1,365 @@ -card = new CreditCardData(); - $this->card->number = '4111111111111111'; - $this->card->expMonth = 12; - $this->card->expYear = TestCards::validCardExpYear(); - $this->card->cvn = '123'; - $this->card->cardHolderName = 'Joe Smith'; - - - $this->track = new CreditTrackData(); - $this->track->value = ';'; - $this->track->encryptionData = new EncryptionData(); - $this->track->encryptionData->version = '01'; - - ServicesContainer::configureService($this->getConfig()); - } - - public function testCreditAuthorization() - { - $authorization = $this->card->authorize(14) - ->withCurrency('USD') - ->withAllowDuplicates(true) - ->execute(); - $this->assertNotNull($authorization); - $this->assertEquals('00', $authorization->responseCode); - - $capture = $authorization->capture(16) - ->withGratuity(2) - ->execute(); - $this->assertNotNull($capture); - $this->assertEquals('00', $capture->responseCode); - } - - public function testCreditServiceAuth() - { - $service = new CreditService( - $this->getConfig() - ); - - $authorization = $service->authorize(15) - ->withCurrency('USD') - ->withPaymentMethod($this->card) - ->withAllowDuplicates(true) - ->execute(); - $this->assertNotNull($authorization); - $this->assertEquals('00', $authorization->responseCode); - - $capture = $service->capture($authorization->transactionReference->transactionId) - ->withAmount(17) - ->withGratuity(2) - ->execute(); - $this->assertNotNull($capture); - $this->assertEquals('00', $capture->responseCode); - } - - public function testCreditSale() - { - $response = $this->card->charge(15) - ->withCurrency('USD') - ->withAllowDuplicates(true) - ->execute(); - - $this->assertNotNull($response); - $this->assertEquals('00', $response->responseCode); - } - - public function testCreditOfflineAuth() - { - $response = $this->card->authorize(16) - ->withCurrency('USD') - ->withOfflineAuthCode('12345') - ->withAllowDuplicates(true) - ->execute(); - $this->assertNotNull($response); - $this->assertEquals('00', $response->responseCode); - } - - public function testCreditOfflineSale() - { - $response = $this->card->charge(16) - ->withCurrency('USD') - ->withOfflineAuthCode('12345') - ->withAllowDuplicates(true) - ->execute(); - $this->assertNotNull($response); - $this->assertEquals('00', $response->responseCode); - } - - public function testCreditRefund() - { - $response = $this->card->refund(16) - ->withCurrency('USD') - ->withAllowDuplicates(true) - ->execute(); - - $this->assertNotNull($response); - $this->assertEquals('00', $response->responseCode); - } - - public function testCreditReverse() - { - $response = $this->card->reverse(15) - ->withAllowDuplicates(true) - ->execute(); - - $this->assertNotNull($response); - $this->assertEquals('00', $response->responseCode); - } - - public function testCreditVerify() - { - $response = $this->card->verify() - ->withAllowDuplicates(true) - ->execute(); - - $this->assertNotNull($response); - $this->assertEquals('00', $response->responseCode); - } - - public function testCreditSwipeAuthorization() - { - $authorization = $this->track->authorize(14) - ->withCurrency('USD') - ->withAllowDuplicates(true) - ->execute(); - $this->assertNotNull($authorization); - $this->assertEquals('00', $authorization->responseCode); - - $capture = $authorization->capture(16) - ->withGratuity(2) - ->execute(); - $this->assertNotNull($capture); - $this->assertEquals('00', $capture->responseCode); - } - - public function testCreditServiceSwipeAuth() - { - $service = new CreditService( - $this->getConfig() - ); - - $authorization = $service->authorize(15) - ->withCurrency('USD') - ->withPaymentMethod($this->track) - ->withAllowDuplicates(true) - ->execute(); - $this->assertNotNull($authorization); - $this->assertEquals('00', $authorization->responseCode); - - $capture = $service->capture($authorization->transactionReference->transactionId) - ->withAmount(17) - ->withGratuity(2) - ->execute(); - $this->assertNotNull($capture); - $this->assertEquals('00', $capture->responseCode); - } - - public function testCreditSwipeSale() - { - $response = $this->track->charge(15) - ->withCurrency('USD') - ->withAllowDuplicates(true) - ->execute(); - - $this->assertNotNull($response); - $this->assertEquals('00', $response->responseCode); - } - - public function testCreditSwipeOfflineAuth() - { - $response = $this->track->authorize(16) - ->withCurrency('USD') - ->withOfflineAuthCode('12345') - ->withAllowDuplicates(true) - ->execute(); - $this->assertNotNull($response); - $this->assertEquals('00', $response->responseCode); - } - - public function testCreditSwipeOfflineSale() - { - $response = $this->track->charge(16) - ->withCurrency('USD') - ->withOfflineAuthCode('12345') - ->withAllowDuplicates(true) - ->execute(); - $this->assertNotNull($response); - $this->assertEquals('00', $response->responseCode); - } - - public function testCreditSwipeAddValue() - { - $this->markTestSkipped('GSB not configured'); - - $response = $this->track->addValue(16) - ->withCurrency('USD') - ->withAllowDuplicates(true) - ->execute(); - $this->assertNotNull($response); - $this->assertEquals('00', $response->responseCode); - } - - public function testCreditSwipeBalanceInquiry() - { - $response = $this->track->balanceInquiry() - ->execute(); - $this->assertNotNull($response); - $this->assertEquals('00', $response->responseCode); - } - - public function testCreditSwipeRefund() - { - $response = $this->track->refund(16) - ->withCurrency('USD') - ->withAllowDuplicates(true) - ->execute(); - - $this->assertNotNull($response); - $this->assertEquals('00', $response->responseCode); - } - - public function testCreditSwipeReverse() - { - $response = $this->track->reverse(15) - ->withAllowDuplicates(true) - ->execute(); - - $this->assertNotNull($response); - $this->assertEquals('00', $response->responseCode); - } - - public function testCreditSwipeVerify() - { - $response = $this->track->verify() - ->withAllowDuplicates(true) - ->execute(); - - $this->assertNotNull($response); - $this->assertEquals('00', $response->responseCode); - } - - protected function getConfig() - { - $config = new PorticoConfig(); - $config->secretApiKey = 'skapi_cert_MTeSAQAfG1UA9qQDrzl-kz4toXvARyieptFwSKP24w'; - $config->serviceUrl = ($this->enableCryptoUrl) ? - 'https://cert.api2-c.heartlandportico.com/': - 'https://cert.api2.heartlandportico.com'; - return $config; - } - - public function testCreditSaleWithCOF() - { - $response = $this->card->charge(15) - ->withCurrency('USD') - ->withAllowDuplicates(true) - ->withCardBrandStorage(StoredCredentialInitiator::CARDHOLDER) - ->execute(); - - $this->assertNotNull($response); - $this->assertEquals('00', $response->responseCode); - $this->assertNotNull($response->cardBrandTransactionId); - - $nextResponse = $this->card->charge(15) - ->withCurrency('USD') - ->withAllowDuplicates(true) - ->withCardBrandStorage(StoredCredentialInitiator::MERCHANT, $response->cardBrandTransactionId) - ->execute(); - - $this->assertNotNull($nextResponse); - $this->assertEquals('00', $nextResponse->responseCode); - } - - public function testCreditVerifyWithCOF() - { - $response = $this->card->verify() - ->withAllowDuplicates(true) - ->withCardBrandStorage(StoredCredentialInitiator::CARDHOLDER) - ->execute(); - - $this->assertNotNull($response); - $this->assertEquals('00', $response->responseCode); - $this->assertNotNull($response->cardBrandTransactionId); - - $nextResponse = $this->card->verify() - ->withAllowDuplicates(true) - ->withCardBrandStorage(StoredCredentialInitiator::MERCHANT, $response->cardBrandTransactionId) - ->execute(); - - $this->assertNotNull($nextResponse); - $this->assertEquals('00', $nextResponse->responseCode); - } - - public function testCreditAuthorizationWithCOF() - { - $response = $this->card->authorize(14) - ->withCurrency('USD') - ->withAllowDuplicates(true) - ->withCardBrandStorage(StoredCredentialInitiator::CARDHOLDER) - ->execute(); - - $this->assertNotNull($response); - $this->assertEquals('00', $response->responseCode); - $this->assertNotNull($response->cardBrandTransactionId); - - $nextResponse = $this->card->authorize(14) - ->withCurrency('USD') - ->withAllowDuplicates(true) - ->withCardBrandStorage(StoredCredentialInitiator::MERCHANT, $response->cardBrandTransactionId) - ->execute(); - - $this->assertNotNull($nextResponse); - $this->assertEquals('00', $nextResponse->responseCode); - - $captureResponse = $nextResponse->capture(16) - ->withGratuity(2) - ->execute(); - - $this->assertNotNull($captureResponse); - $this->assertEquals('00', $captureResponse->responseCode); - } - - public function testCreditReverseViaClientTxnId() - { - $clientTxnId = time(); - - $authorization = $this->card->charge(420.69) - ->withClientTransactionId($clientTxnId) - ->withCurrency('USD') - ->withAllowDuplicates(true) - ->execute(); - - $this->assertNotNull($authorization); - $this->assertEquals('00', $authorization->responseCode); - - $reverse = Transaction::fromClientTransactionId($clientTxnId) - ->reverse(420.69) - ->execute(); - - $this->assertNotNull($reverse); - $this->assertEquals('00', $reverse->responseCode); - } -} +card = new CreditCardData(); + $this->card->number = '4111111111111111'; + $this->card->expMonth = 12; + $this->card->expYear = TestCards::validCardExpYear(); + $this->card->cvn = '123'; + $this->card->cardHolderName = 'Joe Smith'; + + + $this->track = new CreditTrackData(); + $this->track->value = ';'; + $this->track->encryptionData = new EncryptionData(); + $this->track->encryptionData->version = '01'; + + ServicesContainer::configureService($this->getConfig()); + } + + public function testCreditAuthorization() + { + $authorization = $this->card->authorize(14) + ->withCurrency('USD') + ->withAllowDuplicates(true) + ->execute(); + $this->assertNotNull($authorization); + $this->assertEquals('00', $authorization->responseCode); + + $capture = $authorization->capture(16) + ->withGratuity(2) + ->execute(); + $this->assertNotNull($capture); + $this->assertEquals('00', $capture->responseCode); + } + + public function testCreditServiceAuth() + { + $service = new CreditService( + $this->getConfig() + ); + + $authorization = $service->authorize(15) + ->withCurrency('USD') + ->withPaymentMethod($this->card) + ->withAllowDuplicates(true) + ->execute(); + $this->assertNotNull($authorization); + $this->assertEquals('00', $authorization->responseCode); + + $capture = $service->capture($authorization->transactionReference->transactionId) + ->withAmount(17) + ->withGratuity(2) + ->execute(); + $this->assertNotNull($capture); + $this->assertEquals('00', $capture->responseCode); + } + + public function testCreditSale() + { + $response = $this->card->charge(15) + ->withCurrency('USD') + ->withAllowDuplicates(true) + ->execute(); + + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode); + } + + public function testCreditOfflineAuth() + { + $response = $this->card->authorize(16) + ->withCurrency('USD') + ->withOfflineAuthCode('12345') + ->withAllowDuplicates(true) + ->execute(); + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode); + } + + public function testCreditOfflineSale() + { + $response = $this->card->charge(16) + ->withCurrency('USD') + ->withOfflineAuthCode('12345') + ->withAllowDuplicates(true) + ->execute(); + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode); + } + + public function testCreditRefund() + { + $response = $this->card->refund(16) + ->withCurrency('USD') + ->withAllowDuplicates(true) + ->execute(); + + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode); + } + + public function testCreditReverse() + { + $response = $this->card->reverse(15) + ->withAllowDuplicates(true) + ->execute(); + + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode); + } + + public function testCreditVerify() + { + $response = $this->card->verify() + ->withAllowDuplicates(true) + ->execute(); + + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode); + } + + public function testCreditSwipeAuthorization() + { + $authorization = $this->track->authorize(14) + ->withCurrency('USD') + ->withAllowDuplicates(true) + ->execute(); + $this->assertNotNull($authorization); + $this->assertEquals('00', $authorization->responseCode); + + $capture = $authorization->capture(16) + ->withGratuity(2) + ->execute(); + $this->assertNotNull($capture); + $this->assertEquals('00', $capture->responseCode); + } + + public function testCreditServiceSwipeAuth() + { + $service = new CreditService( + $this->getConfig() + ); + + $authorization = $service->authorize(15) + ->withCurrency('USD') + ->withPaymentMethod($this->track) + ->withAllowDuplicates(true) + ->execute(); + $this->assertNotNull($authorization); + $this->assertEquals('00', $authorization->responseCode); + + $capture = $service->capture($authorization->transactionReference->transactionId) + ->withAmount(17) + ->withGratuity(2) + ->execute(); + $this->assertNotNull($capture); + $this->assertEquals('00', $capture->responseCode); + } + + public function testCreditSwipeSale() + { + $response = $this->track->charge(15) + ->withCurrency('USD') + ->withAllowDuplicates(true) + ->execute(); + + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode); + } + + public function testCreditSwipeOfflineAuth() + { + $response = $this->track->authorize(16) + ->withCurrency('USD') + ->withOfflineAuthCode('12345') + ->withAllowDuplicates(true) + ->execute(); + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode); + } + + public function testCreditSwipeOfflineSale() + { + $response = $this->track->charge(16) + ->withCurrency('USD') + ->withOfflineAuthCode('12345') + ->withAllowDuplicates(true) + ->execute(); + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode); + } + + public function testCreditSwipeAddValue() + { + $this->markTestSkipped('GSB not configured'); + + $response = $this->track->addValue(16) + ->withCurrency('USD') + ->withAllowDuplicates(true) + ->execute(); + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode); + } + + public function testCreditSwipeBalanceInquiry() + { + $response = $this->track->balanceInquiry() + ->execute(); + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode); + } + + public function testCreditSwipeRefund() + { + $response = $this->track->refund(16) + ->withCurrency('USD') + ->withAllowDuplicates(true) + ->execute(); + + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode); + } + + public function testCreditSwipeReverse() + { + $response = $this->track->reverse(15) + ->withAllowDuplicates(true) + ->execute(); + + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode); + } + + public function testCreditSwipeVerify() + { + $response = $this->track->verify() + ->withAllowDuplicates(true) + ->execute(); + + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode); + } + + protected function getConfig() + { + $config = new PorticoConfig(); + $config->secretApiKey = 'skapi_cert_MTeSAQAfG1UA9qQDrzl-kz4toXvARyieptFwSKP24w'; + $config->serviceUrl = ($this->enableCryptoUrl) ? + 'https://cert.api2-c.heartlandportico.com/': + 'https://cert.api2.heartlandportico.com'; + return $config; + } + + public function testCreditSaleWithCOF() + { + $response = $this->card->charge(15) + ->withCurrency('USD') + ->withAllowDuplicates(true) + ->withCardBrandStorage(StoredCredentialInitiator::CARDHOLDER) + ->execute(); + + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode); + $this->assertNotNull($response->cardBrandTransactionId); + + $nextResponse = $this->card->charge(15) + ->withCurrency('USD') + ->withAllowDuplicates(true) + ->withCardBrandStorage(StoredCredentialInitiator::MERCHANT, $response->cardBrandTransactionId) + ->execute(); + + $this->assertNotNull($nextResponse); + $this->assertEquals('00', $nextResponse->responseCode); + } + + public function testCreditVerifyWithCOF() + { + $response = $this->card->verify() + ->withAllowDuplicates(true) + ->withCardBrandStorage(StoredCredentialInitiator::CARDHOLDER) + ->execute(); + + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode); + $this->assertNotNull($response->cardBrandTransactionId); + + $nextResponse = $this->card->verify() + ->withAllowDuplicates(true) + ->withCardBrandStorage(StoredCredentialInitiator::MERCHANT, $response->cardBrandTransactionId) + ->execute(); + + $this->assertNotNull($nextResponse); + $this->assertEquals('00', $nextResponse->responseCode); + } + + public function testCreditAuthorizationWithCOF() + { + $response = $this->card->authorize(14) + ->withCurrency('USD') + ->withAllowDuplicates(true) + ->withCardBrandStorage(StoredCredentialInitiator::CARDHOLDER) + ->execute(); + + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode); + $this->assertNotNull($response->cardBrandTransactionId); + + $nextResponse = $this->card->authorize(14) + ->withCurrency('USD') + ->withAllowDuplicates(true) + ->withCardBrandStorage(StoredCredentialInitiator::MERCHANT, $response->cardBrandTransactionId) + ->execute(); + + $this->assertNotNull($nextResponse); + $this->assertEquals('00', $nextResponse->responseCode); + + $captureResponse = $nextResponse->capture(16) + ->withGratuity(2) + ->execute(); + + $this->assertNotNull($captureResponse); + $this->assertEquals('00', $captureResponse->responseCode); + } + + public function testCreditReverseViaClientTxnId() + { + $clientTxnId = time(); + + $authorization = $this->card->charge(420.69) + ->withClientTransactionId($clientTxnId) + ->withCurrency('USD') + ->withAllowDuplicates(true) + ->execute(); + + $this->assertNotNull($authorization); + $this->assertEquals('00', $authorization->responseCode); + + $reverse = Transaction::fromClientTransactionId($clientTxnId) + ->reverse(420.69) + ->execute(); + + $this->assertNotNull($reverse); + $this->assertEquals('00', $reverse->responseCode); + } +} diff --git a/test/Integration/Gateways/PorticoConnector/DebitTest.php b/test/Integration/Gateways/PorticoConnector/DebitTest.php index dc412eb6..f8af8d79 100644 --- a/test/Integration/Gateways/PorticoConnector/DebitTest.php +++ b/test/Integration/Gateways/PorticoConnector/DebitTest.php @@ -1,74 +1,74 @@ -track = TestCards::asDebit(TestCards::visaSwipeEncrypted(), '32539F50C245A6A93D123412324000AA'); - - ServicesContainer::configureService($this->getConfig()); - } - - public function testDebitSale() - { - $response = $this->track->charge(17.01) - ->withCurrency('USD') - ->withAllowDuplicates(true) - ->execute(); - $this->assertNotNull($response); - $this->assertEquals('00', $response->responseCode); - } - - public function testDebitAddValue() - { - $this->markTestSkipped('GSB not configured'); - - $response = $this->track->addValue(15.01) - ->withCurrency('USD') - ->withAllowDuplicates(true) - ->execute(); - $this->assertNotNull($response); - $this->assertEquals('00', $response->responseCode); - } - - public function testDebitRefund() - { - $response = $this->track->refund(16.01) - ->withCurrency('USD') - ->withAllowDuplicates(true) - ->execute(); - $this->assertNotNull($response); - $this->assertEquals('00', $response->responseCode); - } - - public function testDebitReverse() - { - $response = $this->track->reverse(17.01) - ->withCurrency('USD') - ->withAllowDuplicates(true) - ->execute(); - $this->assertNotNull($response); - $this->assertEquals('00', $response->responseCode); - } - - protected function getConfig() - { - $config = new PorticoConfig(); - $config->secretApiKey = 'skapi_cert_MaePAQBr-1QAqjfckFC8FTbRTT120bVQUlfVOjgCBw'; - $config->serviceUrl = ($this->enableCryptoUrl) ? - 'https://cert.api2-c.heartlandportico.com/': - 'https://cert.api2.heartlandportico.com'; - return $config; - } -} +track = TestCards::asDebit(TestCards::visaSwipeEncrypted(), '32539F50C245A6A93D123412324000AA'); + + ServicesContainer::configureService($this->getConfig()); + } + + public function testDebitSale() + { + $response = $this->track->charge(17.01) + ->withCurrency('USD') + ->withAllowDuplicates(true) + ->execute(); + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode); + } + + public function testDebitAddValue() + { + $this->markTestSkipped('GSB not configured'); + + $response = $this->track->addValue(15.01) + ->withCurrency('USD') + ->withAllowDuplicates(true) + ->execute(); + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode); + } + + public function testDebitRefund() + { + $response = $this->track->refund(16.01) + ->withCurrency('USD') + ->withAllowDuplicates(true) + ->execute(); + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode); + } + + public function testDebitReverse() + { + $response = $this->track->reverse(17.01) + ->withCurrency('USD') + ->withAllowDuplicates(true) + ->execute(); + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode); + } + + protected function getConfig() + { + $config = new PorticoConfig(); + $config->secretApiKey = 'skapi_cert_MaePAQBr-1QAqjfckFC8FTbRTT120bVQUlfVOjgCBw'; + $config->serviceUrl = ($this->enableCryptoUrl) ? + 'https://cert.api2-c.heartlandportico.com/': + 'https://cert.api2.heartlandportico.com'; + return $config; + } +} diff --git a/test/Integration/Gateways/PorticoConnector/EbtTest.php b/test/Integration/Gateways/PorticoConnector/EbtTest.php index a8eb18f8..6ceff17c 100644 --- a/test/Integration/Gateways/PorticoConnector/EbtTest.php +++ b/test/Integration/Gateways/PorticoConnector/EbtTest.php @@ -1,90 +1,90 @@ -card = TestCards::asEBTManual(TestCards::visaManual(), '32539F50C245A6A93D123412324000AA'); - $this->track = TestCards::asEBTTrack(TestCards::visaSwipeEncrypted(), '32539F50C245A6A93D123412324000AA'); - - ServicesContainer::configureService($this->getConfig()); - } - - public function testEbtBalanceInquiry() - { - $response = $this->card->balanceInquiry() - ->execute(); - $this->assertNotNull($response); - $this->assertEquals('00', $response->responseCode); - } - - public function testEbtSale() - { - $response = $this->card->charge(10) - ->withCurrency('USD') - ->withAllowDuplicates(true) - ->execute(); - $this->assertNotNull($response); - $this->assertEquals('00', $response->responseCode); - } - - public function testEbtRefund() - { - $response = $this->card->refund(10) - ->withCurrency('USD') - ->withAllowDuplicates(true) - ->execute(); - $this->assertNotNull($response); - $this->assertEquals('00', $response->responseCode); - } - - public function testEbtSwipeBalanceInquiry() - { - $response = $this->track->balanceInquiry() - ->execute(); - $this->assertNotNull($response); - $this->assertEquals('00', $response->responseCode); - } - - public function testEbtSwipeSale() - { - $response = $this->track->charge(10) - ->withCurrency('USD') - ->withAllowDuplicates(true) - ->execute(); - $this->assertNotNull($response); - $this->assertEquals('00', $response->responseCode); - } - - public function testEbtSwipeRefund() - { - $response = $this->track->refund(10) - ->withCurrency('USD') - ->withAllowDuplicates(true) - ->execute(); - $this->assertNotNull($response); - $this->assertEquals('00', $response->responseCode); - } - - protected function getConfig() - { - $config = new PorticoConfig(); - $config->secretApiKey = 'skapi_cert_MaePAQBr-1QAqjfckFC8FTbRTT120bVQUlfVOjgCBw'; - $config->serviceUrl = ($this->enableCryptoUrl) ? - 'https://cert.api2-c.heartlandportico.com/': - 'https://cert.api2.heartlandportico.com'; - return $config; - } -} +card = TestCards::asEBTManual(TestCards::visaManual(), '32539F50C245A6A93D123412324000AA'); + $this->track = TestCards::asEBTTrack(TestCards::visaSwipeEncrypted(), '32539F50C245A6A93D123412324000AA'); + + ServicesContainer::configureService($this->getConfig()); + } + + public function testEbtBalanceInquiry() + { + $response = $this->card->balanceInquiry() + ->execute(); + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode); + } + + public function testEbtSale() + { + $response = $this->card->charge(10) + ->withCurrency('USD') + ->withAllowDuplicates(true) + ->execute(); + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode); + } + + public function testEbtRefund() + { + $response = $this->card->refund(10) + ->withCurrency('USD') + ->withAllowDuplicates(true) + ->execute(); + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode); + } + + public function testEbtSwipeBalanceInquiry() + { + $response = $this->track->balanceInquiry() + ->execute(); + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode); + } + + public function testEbtSwipeSale() + { + $response = $this->track->charge(10) + ->withCurrency('USD') + ->withAllowDuplicates(true) + ->execute(); + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode); + } + + public function testEbtSwipeRefund() + { + $response = $this->track->refund(10) + ->withCurrency('USD') + ->withAllowDuplicates(true) + ->execute(); + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode); + } + + protected function getConfig() + { + $config = new PorticoConfig(); + $config->secretApiKey = 'skapi_cert_MaePAQBr-1QAqjfckFC8FTbRTT120bVQUlfVOjgCBw'; + $config->serviceUrl = ($this->enableCryptoUrl) ? + 'https://cert.api2-c.heartlandportico.com/': + 'https://cert.api2.heartlandportico.com'; + return $config; + } +} diff --git a/test/Integration/Gateways/PorticoConnector/GiftTest.php b/test/Integration/Gateways/PorticoConnector/GiftTest.php index 1e136271..c89b6b7f 100644 --- a/test/Integration/Gateways/PorticoConnector/GiftTest.php +++ b/test/Integration/Gateways/PorticoConnector/GiftTest.php @@ -1,119 +1,119 @@ -card = new GiftCard(); - $this->card->number = '5022440000000000007'; - - $this->track = new GiftCard(); - $this->track->trackData = '%B5022440000000000098^^391200081613?;5022440000000000098=391200081613?'; - - ServicesContainer::configureService($this->getConfig()); - } - - public function testGiftCreate() - { - $newCard = GiftCard::create('2145550199'); - $this->assertNotNull($newCard); - $this->assertNotNull($newCard->number); - $this->assertNotNull($newCard->alias); - $this->assertNotNull($newCard->pin); - } - - public function testGiftAddAlias() - { - $response = $this->card->addAlias('2145550199') - ->execute(); - $this->assertNotNull($response); - $this->assertEquals('00', $response->responseCode); - } - - public function testGiftAddValue() - { - $response = $this->card->addValue(10) - ->withCurrency('USD') - ->execute(); - $this->assertNotNull($response); - $this->assertEquals('00', $response->responseCode); - } - - public function testGiftBalanceInquiry() - { - $response = $this->card->balanceInquiry() - ->execute(); - $this->assertNotNull($response); - $this->assertEquals('00', $response->responseCode); - } - - public function testGiftSale() - { - $response = $this->card->charge(10) - ->withCurrency('USD') - ->execute(); - $this->assertNotNull($response); - $this->assertEquals('00', $response->responseCode); - } - - public function testGiftDeactivate() - { - $response = $this->card->deactivate() - ->execute(); - $this->assertNotNull($response); - $this->assertEquals('00', $response->responseCode); - } - - public function testGiftRemoveAlias() - { - $response = $this->card->removeAlias('2145550199') - ->execute(); - $this->assertNotNull($response); - $this->assertEquals('00', $response->responseCode); - } - - public function testGiftReplace() - { - $response = $this->card->replaceWith($this->track) - ->execute(); - $this->assertNotNull($response); - $this->assertEquals('00', $response->responseCode); - } - - public function testGiftReverse() - { - $response = $this->card->reverse(10) - ->execute(); - $this->assertNotNull($response); - $this->assertEquals('00', $response->responseCode); - } - - public function testGiftRewards() - { - $response = $this->card->rewards(10) - ->execute(); - $this->assertNotNull($response); - $this->assertEquals('00', $response->responseCode); - } - - protected function getConfig() - { - $config = new PorticoConfig(); - $config->secretApiKey = 'skapi_cert_MaePAQBr-1QAqjfckFC8FTbRTT120bVQUlfVOjgCBw'; - $config->serviceUrl = ($this->enableCryptoUrl) ? - 'https://cert.api2-c.heartlandportico.com/': - 'https://cert.api2.heartlandportico.com'; - return $config; - } -} +card = new GiftCard(); + $this->card->number = '5022440000000000007'; + + $this->track = new GiftCard(); + $this->track->trackData = '%B5022440000000000098^^391200081613?;5022440000000000098=391200081613?'; + + ServicesContainer::configureService($this->getConfig()); + } + + public function testGiftCreate() + { + $newCard = GiftCard::create('2145550199'); + $this->assertNotNull($newCard); + $this->assertNotNull($newCard->number); + $this->assertNotNull($newCard->alias); + $this->assertNotNull($newCard->pin); + } + + public function testGiftAddAlias() + { + $response = $this->card->addAlias('2145550199') + ->execute(); + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode); + } + + public function testGiftAddValue() + { + $response = $this->card->addValue(10) + ->withCurrency('USD') + ->execute(); + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode); + } + + public function testGiftBalanceInquiry() + { + $response = $this->card->balanceInquiry() + ->execute(); + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode); + } + + public function testGiftSale() + { + $response = $this->card->charge(10) + ->withCurrency('USD') + ->execute(); + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode); + } + + public function testGiftDeactivate() + { + $response = $this->card->deactivate() + ->execute(); + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode); + } + + public function testGiftRemoveAlias() + { + $response = $this->card->removeAlias('2145550199') + ->execute(); + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode); + } + + public function testGiftReplace() + { + $response = $this->card->replaceWith($this->track) + ->execute(); + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode); + } + + public function testGiftReverse() + { + $response = $this->card->reverse(10) + ->execute(); + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode); + } + + public function testGiftRewards() + { + $response = $this->card->rewards(10) + ->execute(); + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode); + } + + protected function getConfig() + { + $config = new PorticoConfig(); + $config->secretApiKey = 'skapi_cert_MaePAQBr-1QAqjfckFC8FTbRTT120bVQUlfVOjgCBw'; + $config->serviceUrl = ($this->enableCryptoUrl) ? + 'https://cert.api2-c.heartlandportico.com/': + 'https://cert.api2.heartlandportico.com'; + return $config; + } +} diff --git a/test/Integration/Gateways/PorticoConnector/PorticoReportingTests.php b/test/Integration/Gateways/PorticoConnector/PorticoReportingTests.php index 15274506..73dd9dcd 100644 --- a/test/Integration/Gateways/PorticoConnector/PorticoReportingTests.php +++ b/test/Integration/Gateways/PorticoConnector/PorticoReportingTests.php @@ -1,297 +1,297 @@ -card = new CreditCardData(); - $this->card->number = '4111111111111111'; - $this->card->expMonth = 12; - $this->card->expYear = TestCards::validCardExpYear(); - $this->card->cvn = '123'; - $this->card->cardHolderName = 'Joe Smith'; - - - $this->reportingService = new ReportingService(); - $this->searchCriteria = new SearchCriteriaBuilder(); - - ServicesContainer::configureService($this->getConfig()); - } - - protected function getConfig() - { - $config = new PorticoConfig(); - $config->secretApiKey = 'skapi_cert_MaePAQBr-1QAqjfckFC8FTbRTT120bVQUlfVOjgCBw'; - $config->serviceUrl = ($this->enableCryptoUrl) ? - 'https://cert.api2-c.heartlandportico.com/': - 'https://cert.api2.heartlandportico.com'; - return $config; - } - - public function testReportActivity() - { - date_default_timezone_set("UTC"); - $dateFormat = 'Y-m-d\TH:i:s.00\Z'; - $dateMinus15days = new DateTime(); - $dateMinus15days->sub(new DateInterval('P15D')); - $dateMinus10Utc = gmdate($dateFormat, $dateMinus15days->Format('U')); - $nowUtc = gmdate($dateFormat); - - $response = $this->reportingService->activity() - ->withStartDate($dateMinus10Utc) - ->withEndDate($nowUtc) - ->execute(); - $this->assertNotNull($response); - $this->assertTrue(count($response) > 0); - } - - public function testReportActivityByDays() - { - date_default_timezone_set("UTC"); - $dateFormat = 'Y-m-d\TH:i:s.00\Z'; - $dateMinus5days = new DateTime(); - $dateMinus5days->sub(new DateInterval('P5D')); - $dateMinus10Utc = gmdate($dateFormat, $dateMinus5days->Format('U')); - $nowUtc = gmdate($dateFormat); - - $response = $this->reportingService->activity() - ->withStartDate($dateMinus10Utc) - ->withEndDate($nowUtc) - ->execute(); - $this->assertNotNull($response); - $this->assertTrue(count($response) > 0); - } - - public function testReportTransactionDetail() - { - $response = $this->reportingService->transactionDetail("1088532284")->execute(); - $this->assertNotNull($response); - } - - public function testInvoiceNumber() - { - $address = new Address(); - $address->postalCode = "12345"; - - $authResponse = $this->card->charge(10) - ->withCurrency("USD") - ->withAddress($address) - ->withInvoiceNumber('123456') - ->withAllowDuplicates(true) - ->execute(); - - $this->assertNotNull($authResponse); - $this->assertEquals('00', $authResponse->responseCode); - $this->assertNotNull($authResponse->transactionId); - - $report = ReportingService::transactionDetail($authResponse->transactionId) - ->execute(); - - $this->assertNotNull($report); - $this->assertEquals('123456', $report->invoiceNumber); - } - - public function testReportCardHolderName() - { - $gateway_response = $this->card->charge(10) - ->withCurrency('USD') - ->withAllowDuplicates(true) - ->execute(); - - $response = $this->reportingService->transactionDetail($gateway_response->transactionId)->execute(); - - $this->assertEquals('Joe', $response->cardHolderFirstName); - $this->assertEquals('Smith', $response->cardHolderLastName); - } - - public function testReportFindTransactionWithTransactionId() - { - $gateway_response = $this->card->charge(10) - ->withCurrency('USD') - ->withAllowDuplicates(true) - ->execute(); - - $response = $this->reportingService->findTransactions($gateway_response->transactionId)->execute(); - $this->assertNotNull($response); - } - - public function testReportFindTransactionNoCriteria() - { - $response = $this->reportingService->findTransactions()->execute(); - $this->assertNotNull($response); - } - - public function testReportFindTransactionWithCriteria() - { - date_default_timezone_set("UTC"); - $dateFormat = 'Y-m-d\TH:i:s.00\Z'; - $dateMinus10days = new DateTime(); - $dateMinus10days->sub(new DateInterval('P5D')); - $dateMinus5Utc = gmdate($dateFormat, $dateMinus10days->Format('U')); - $nowUtc = gmdate($dateFormat); - - $response = $this->reportingService->findTransactions() - ->withTimeZoneConversion(TimeZoneConversion::MERCHANT) - ->where('startDate', $dateMinus5Utc) - ->and('endDate', $nowUtc) - ->execute(); - - $this->assertNotNull($response); - $this->assertTrue(count($response) > 0); - } - - public function testCreditAuthWithConvenienceAmount() - { - $authorization = $this->card->authorize(14) - ->withCurrency('USD') - ->withAllowDuplicates(true) - ->withConvenienceAmount(2) - ->execute(); - - $this->assertNotNull($authorization); - $this->assertEquals('00', $authorization->responseCode); - - $report = $this->reportingService->transactionDetail($authorization->transactionId)->execute(); - $this->assertNotNull($report); - $this->assertEquals('2', $report->convenienceAmount); - } - - public function testCreditAuthWithShippingAmount() - { - $authorization = $this->card->authorize(14) - ->withCurrency('USD') - ->withAllowDuplicates(true) - ->withShippingAmount(2) - ->execute(); - - $this->assertNotNull($authorization); - $this->assertEquals('00', $authorization->responseCode); - - $report = $this->reportingService->transactionDetail($authorization->transactionId)->execute(); - $this->assertNotNull($report); - $this->assertEquals('2', $report->shippingAmount); - } - - public function testCreditSaleWithConvenienceAmount() - { - $response = $this->card->charge(15) - ->withCurrency('USD') - ->withAllowDuplicates(true) - ->withConvenienceAmount(2) - ->execute(); - - $this->assertNotNull($response); - $this->assertEquals('00', $response->responseCode); - - $report = $this->reportingService->transactionDetail($response->transactionId)->execute(); - $this->assertNotNull($report); - $this->assertEquals('2', $report->convenienceAmount); - } - - public function testCreditSaleWithShippingAmount() - { - $response = $this->card->charge(15) - ->withCurrency('USD') - ->withAllowDuplicates(true) - ->withShippingAmount(2) - ->execute(); - - $this->assertNotNull($response); - $this->assertEquals('00', $response->responseCode); - - $report = $this->reportingService->transactionDetail($response->transactionId)->execute(); - $this->assertNotNull($report); - $this->assertEquals('2', $report->shippingAmount); - } - - public function testCreditOfflineAuthWithConvenienceAmount() - { - $response = $this->card->authorize(16) - ->withCurrency('USD') - ->withOfflineAuthCode('12345') - ->withAllowDuplicates(true) - ->withConvenienceAmount(2) - ->execute(); - - $this->assertNotNull($response); - $this->assertEquals('00', $response->responseCode); - - $report = $this->reportingService->transactionDetail($response->transactionId)->execute(); - $this->assertNotNull($report); - $this->assertEquals('2', $report->convenienceAmount); - } - - public function testCreditOfflineAuthWithShippingAmount() - { - $response = $this->card->authorize(16) - ->withCurrency('USD') - ->withOfflineAuthCode('12345') - ->withAllowDuplicates(true) - ->withShippingAmount(2) - ->execute(); - - $this->assertNotNull($response); - $this->assertEquals('00', $response->responseCode); - - $report = $this->reportingService->transactionDetail($response->transactionId)->execute(); - $this->assertNotNull($report); - $this->assertEquals('2', $report->shippingAmount); - } - - public function testCreditOfflineSaleWithConvenienceAmount() - { - $response = $this->card->charge(17) - ->withCurrency('USD') - ->withOfflineAuthCode('12345') - ->withAllowDuplicates(true) - ->WithConvenienceAmount(2) - ->execute(); - - $this->assertNotNull($response); - $this->assertEquals('00', $response->responseCode); - - $report = $this->reportingService->transactionDetail($response->transactionId)->execute(); - $this->assertNotNull($report); - $this->assertEquals('2', $report->convenienceAmount); - } - - public function testCreditOfflineSaleWithShippingAmount() - { - $response = $this->card->charge(17) - ->withCurrency('USD') - ->withOfflineAuthCode('12345') - ->withAllowDuplicates(true) - ->withShippingAmount(2) - ->execute(); - - $this->assertNotNull($response); - $this->assertEquals('00', $response->responseCode); - - $report = $this->reportingService->transactionDetail($response->transactionId)->execute(); - $this->assertNotNull($report); - $this->assertEquals('2', $report->shippingAmount); - } -} +card = new CreditCardData(); + $this->card->number = '4111111111111111'; + $this->card->expMonth = 12; + $this->card->expYear = TestCards::validCardExpYear(); + $this->card->cvn = '123'; + $this->card->cardHolderName = 'Joe Smith'; + + + $this->reportingService = new ReportingService(); + $this->searchCriteria = new SearchCriteriaBuilder(); + + ServicesContainer::configureService($this->getConfig()); + } + + protected function getConfig() + { + $config = new PorticoConfig(); + $config->secretApiKey = 'skapi_cert_MaePAQBr-1QAqjfckFC8FTbRTT120bVQUlfVOjgCBw'; + $config->serviceUrl = ($this->enableCryptoUrl) ? + 'https://cert.api2-c.heartlandportico.com/': + 'https://cert.api2.heartlandportico.com'; + return $config; + } + + public function testReportActivity() + { + date_default_timezone_set("UTC"); + $dateFormat = 'Y-m-d\TH:i:s.00\Z'; + $dateMinus15days = new DateTime(); + $dateMinus15days->sub(new DateInterval('P15D')); + $dateMinus10Utc = gmdate($dateFormat, $dateMinus15days->Format('U')); + $nowUtc = gmdate($dateFormat); + + $response = $this->reportingService->activity() + ->withStartDate($dateMinus10Utc) + ->withEndDate($nowUtc) + ->execute(); + $this->assertNotNull($response); + $this->assertTrue(count($response) > 0); + } + + public function testReportActivityByDays() + { + date_default_timezone_set("UTC"); + $dateFormat = 'Y-m-d\TH:i:s.00\Z'; + $dateMinus5days = new DateTime(); + $dateMinus5days->sub(new DateInterval('P5D')); + $dateMinus10Utc = gmdate($dateFormat, $dateMinus5days->Format('U')); + $nowUtc = gmdate($dateFormat); + + $response = $this->reportingService->activity() + ->withStartDate($dateMinus10Utc) + ->withEndDate($nowUtc) + ->execute(); + $this->assertNotNull($response); + $this->assertTrue(count($response) > 0); + } + + public function testReportTransactionDetail() + { + $response = $this->reportingService->transactionDetail("1088532284")->execute(); + $this->assertNotNull($response); + } + + public function testInvoiceNumber() + { + $address = new Address(); + $address->postalCode = "12345"; + + $authResponse = $this->card->charge(10) + ->withCurrency("USD") + ->withAddress($address) + ->withInvoiceNumber('123456') + ->withAllowDuplicates(true) + ->execute(); + + $this->assertNotNull($authResponse); + $this->assertEquals('00', $authResponse->responseCode); + $this->assertNotNull($authResponse->transactionId); + + $report = ReportingService::transactionDetail($authResponse->transactionId) + ->execute(); + + $this->assertNotNull($report); + $this->assertEquals('123456', $report->invoiceNumber); + } + + public function testReportCardHolderName() + { + $gateway_response = $this->card->charge(10) + ->withCurrency('USD') + ->withAllowDuplicates(true) + ->execute(); + + $response = $this->reportingService->transactionDetail($gateway_response->transactionId)->execute(); + + $this->assertEquals('Joe', $response->cardHolderFirstName); + $this->assertEquals('Smith', $response->cardHolderLastName); + } + + public function testReportFindTransactionWithTransactionId() + { + $gateway_response = $this->card->charge(10) + ->withCurrency('USD') + ->withAllowDuplicates(true) + ->execute(); + + $response = $this->reportingService->findTransactions($gateway_response->transactionId)->execute(); + $this->assertNotNull($response); + } + + public function testReportFindTransactionNoCriteria() + { + $response = $this->reportingService->findTransactions()->execute(); + $this->assertNotNull($response); + } + + public function testReportFindTransactionWithCriteria() + { + date_default_timezone_set("UTC"); + $dateFormat = 'Y-m-d\TH:i:s.00\Z'; + $dateMinus10days = new DateTime(); + $dateMinus10days->sub(new DateInterval('P5D')); + $dateMinus5Utc = gmdate($dateFormat, $dateMinus10days->Format('U')); + $nowUtc = gmdate($dateFormat); + + $response = $this->reportingService->findTransactions() + ->withTimeZoneConversion(TimeZoneConversion::MERCHANT) + ->where('startDate', $dateMinus5Utc) + ->and('endDate', $nowUtc) + ->execute(); + + $this->assertNotNull($response); + $this->assertTrue(count($response) > 0); + } + + public function testCreditAuthWithConvenienceAmount() + { + $authorization = $this->card->authorize(14) + ->withCurrency('USD') + ->withAllowDuplicates(true) + ->withConvenienceAmount(2) + ->execute(); + + $this->assertNotNull($authorization); + $this->assertEquals('00', $authorization->responseCode); + + $report = $this->reportingService->transactionDetail($authorization->transactionId)->execute(); + $this->assertNotNull($report); + $this->assertEquals('2', $report->convenienceAmount); + } + + public function testCreditAuthWithShippingAmount() + { + $authorization = $this->card->authorize(14) + ->withCurrency('USD') + ->withAllowDuplicates(true) + ->withShippingAmount(2) + ->execute(); + + $this->assertNotNull($authorization); + $this->assertEquals('00', $authorization->responseCode); + + $report = $this->reportingService->transactionDetail($authorization->transactionId)->execute(); + $this->assertNotNull($report); + $this->assertEquals('2', $report->shippingAmount); + } + + public function testCreditSaleWithConvenienceAmount() + { + $response = $this->card->charge(15) + ->withCurrency('USD') + ->withAllowDuplicates(true) + ->withConvenienceAmount(2) + ->execute(); + + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode); + + $report = $this->reportingService->transactionDetail($response->transactionId)->execute(); + $this->assertNotNull($report); + $this->assertEquals('2', $report->convenienceAmount); + } + + public function testCreditSaleWithShippingAmount() + { + $response = $this->card->charge(15) + ->withCurrency('USD') + ->withAllowDuplicates(true) + ->withShippingAmount(2) + ->execute(); + + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode); + + $report = $this->reportingService->transactionDetail($response->transactionId)->execute(); + $this->assertNotNull($report); + $this->assertEquals('2', $report->shippingAmount); + } + + public function testCreditOfflineAuthWithConvenienceAmount() + { + $response = $this->card->authorize(16) + ->withCurrency('USD') + ->withOfflineAuthCode('12345') + ->withAllowDuplicates(true) + ->withConvenienceAmount(2) + ->execute(); + + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode); + + $report = $this->reportingService->transactionDetail($response->transactionId)->execute(); + $this->assertNotNull($report); + $this->assertEquals('2', $report->convenienceAmount); + } + + public function testCreditOfflineAuthWithShippingAmount() + { + $response = $this->card->authorize(16) + ->withCurrency('USD') + ->withOfflineAuthCode('12345') + ->withAllowDuplicates(true) + ->withShippingAmount(2) + ->execute(); + + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode); + + $report = $this->reportingService->transactionDetail($response->transactionId)->execute(); + $this->assertNotNull($report); + $this->assertEquals('2', $report->shippingAmount); + } + + public function testCreditOfflineSaleWithConvenienceAmount() + { + $response = $this->card->charge(17) + ->withCurrency('USD') + ->withOfflineAuthCode('12345') + ->withAllowDuplicates(true) + ->WithConvenienceAmount(2) + ->execute(); + + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode); + + $report = $this->reportingService->transactionDetail($response->transactionId)->execute(); + $this->assertNotNull($report); + $this->assertEquals('2', $report->convenienceAmount); + } + + public function testCreditOfflineSaleWithShippingAmount() + { + $response = $this->card->charge(17) + ->withCurrency('USD') + ->withOfflineAuthCode('12345') + ->withAllowDuplicates(true) + ->withShippingAmount(2) + ->execute(); + + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode); + + $report = $this->reportingService->transactionDetail($response->transactionId)->execute(); + $this->assertNotNull($report); + $this->assertEquals('2', $report->shippingAmount); + } +} diff --git a/test/Integration/Gateways/PorticoConnector/PorticoTokenManagementTest.php b/test/Integration/Gateways/PorticoConnector/PorticoTokenManagementTest.php index 78117b5a..fa73c7e0 100644 --- a/test/Integration/Gateways/PorticoConnector/PorticoTokenManagementTest.php +++ b/test/Integration/Gateways/PorticoConnector/PorticoTokenManagementTest.php @@ -1,73 +1,73 @@ -getConfig()); - - try { - $card = new CreditCardData(); - $card->number = '4111111111111111'; - $card->expMonth = 12; - $card->expYear = TestCards::validCardExpYear(); - $card->cvn = '123'; - - $this->token = $card->tokenize()->execute()->token; - $this->assertTrue(!empty($this->token), 'TOKEN COULD NOT BE GENERATED.'); - } catch (ApiException $exc) { - $this->fail($exc->getMessage()); - } - } - - protected function getConfig() - { - $config = new PorticoConfig(); - $config->secretApiKey = 'skapi_cert_MTyMAQBiHVEAewvIzXVFcmUd2UcyBge_eCpaASUp0A'; - $config->serviceUrl = 'https://cert.api2.heartlandportico.com'; - return $config; - } - - public function testUpdateToken() - { - $token = new CreditCardData(); - $token->token = $this->token; - $token->expMonth = 12; - $token->expYear = TestCards::validCardExpYear(); - - $this->assertTrue($token->updateTokenExpiry()); - - // should succeed - $response = $token->verify()->execute(); - $this->assertNotNull($response); - $this->assertEquals('00', $response->responseCode); - } - - public function testDeleteToken() - { - $token = new CreditCardData(); - $token->token = $this->token; - - $this->assertTrue($token->deleteToken()); - - // should fail - try { - $response = $token->verify()->execute(); - $this->assertTrue(false, 'Expected exception'); - } catch (GatewayException $exc) { - $this->assertEquals('23', $exc->responseCode); - } - } -} +getConfig()); + + try { + $card = new CreditCardData(); + $card->number = '4111111111111111'; + $card->expMonth = 12; + $card->expYear = TestCards::validCardExpYear(); + $card->cvn = '123'; + + $this->token = $card->tokenize()->execute()->token; + $this->assertTrue(!empty($this->token), 'TOKEN COULD NOT BE GENERATED.'); + } catch (ApiException $exc) { + $this->fail($exc->getMessage()); + } + } + + protected function getConfig() + { + $config = new PorticoConfig(); + $config->secretApiKey = 'skapi_cert_MTyMAQBiHVEAewvIzXVFcmUd2UcyBge_eCpaASUp0A'; + $config->serviceUrl = 'https://cert.api2.heartlandportico.com'; + return $config; + } + + public function testUpdateToken() + { + $token = new CreditCardData(); + $token->token = $this->token; + $token->expMonth = 12; + $token->expYear = TestCards::validCardExpYear(); + + $this->assertTrue($token->updateTokenExpiry()); + + // should succeed + $response = $token->verify()->execute(); + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode); + } + + public function testDeleteToken() + { + $token = new CreditCardData(); + $token->token = $this->token; + + $this->assertTrue($token->deleteToken()); + + // should fail + try { + $response = $token->verify()->execute(); + $this->assertTrue(false, 'Expected exception'); + } catch (GatewayException $exc) { + $this->assertEquals('23', $exc->responseCode); + } + } +} diff --git a/test/Integration/Gateways/RealexConnector/CreditTest.php b/test/Integration/Gateways/RealexConnector/CreditTest.php index 13107c87..0f8901e0 100644 --- a/test/Integration/Gateways/RealexConnector/CreditTest.php +++ b/test/Integration/Gateways/RealexConnector/CreditTest.php @@ -1,287 +1,287 @@ -number = '4111111111111111'; - $card->expMonth = 12; - $card->expYear = TestCards::validCardExpYear(); - $card->cvn = '123'; - $card->cardHolderName = 'Joe Smith'; - $this->card = $card; - - ServicesContainer::configureService($this->getConfig()); - } - - public function testCreditAuthorization() - { - $authorization = $this->card->authorize(14) - ->withCurrency('USD') - ->withAllowDuplicates(true) - ->execute(); - $this->assertNotNull($authorization); - $this->assertEquals('00', $authorization->responseCode); - - $capture = $authorization->capture(16) - ->withGratuity(2) - ->execute(); - $this->assertNotNull($capture); - $this->assertEquals('00', $capture->responseCode); - } - - public function testCreditServiceAuth() - { - $service = new CreditService( - $this->getConfig() - ); - - $authorization = $service->authorize(15) - ->withCurrency('USD') - ->withPaymentMethod($this->card) - ->withAllowDuplicates(true) - ->execute(); - $this->assertNotNull($authorization); - $this->assertEquals('00', $authorization->responseCode); - - $capture = $service->capture($authorization->transactionReference) - ->withAmount(17) - ->withGratuity(2) - ->execute(); - $this->assertNotNull($capture); - $this->assertEquals('00', $capture->responseCode); - } - - public function testCreditSale() - { - $response = $this->card->charge(15) - ->withCurrency('USD') - ->withAllowDuplicates(true) - ->execute(); - - $this->assertNotNull($response); - $this->assertEquals('00', $response->responseCode); - } - - public function testCreditRefund() - { - $response = $this->card->refund(16) - ->withCurrency('USD') - ->withAllowDuplicates(true) - ->execute(); - - $this->assertNotNull($response); - $this->assertEquals('00', $response->responseCode); - } - - public function testCreditRebate() - { - $response = $this->card->charge(17) - ->withCurrency('USD') - ->withAllowDuplicates(true) - ->execute(); - $this->assertNotNull($response); - $this->assertEquals('00', $response->responseCode, $response->responseMessage); - - $rebate = $response->refund(17) - ->withCurrency('USD') - ->execute(); - $this->assertNotNull($rebate); - $this->assertEquals('00', $rebate->responseCode, $rebate->responseMessage); - } - - public function testCreditVoid() - { - $response = $this->card->charge(15) - ->withCurrency('USD') - ->withAllowDuplicates(true) - ->execute(); - $this->assertNotNull($response); - $this->assertEquals('00', $response->responseCode, $response->responseMessage); - - $voidResponse = $response->void()->execute(); - $this->assertNotNull($voidResponse); - $this->assertEquals('00', $voidResponse->responseCode, $voidResponse->responseMessage); - } - - public function testCreditVerify() - { - $response = $this->card->verify() - ->withAllowDuplicates(true) - ->execute(); - - $this->assertNotNull($response); - $this->assertEquals('00', $response->responseCode); - } - - protected function getConfig() - { - $config = new GpEcomConfig(); - $config->merchantId = 'heartlandgpsandbox'; - $config->accountId = 'api'; - $config->sharedSecret = 'secret'; - $config->rebatePassword = 'rebate'; - $config->refundPassword = 'refund'; - $config->serviceUrl = 'https://api.sandbox.realexpayments.com/epage-remote.cgi'; - return $config; - } - - protected function dccSetup() - { - $config = new GpEcomConfig(); - $config->merchantId = "heartlandgpsandbox"; - $config->accountId = "apidcc"; - $config->refundPassword = "refund"; - $config->sharedSecret = "secret"; - $config->serviceUrl = "https://api.sandbox.realexpayments.com/epage-remote.cgi"; - - ServicesContainer::configureService($config); - } - - public function testCreditGetDccInfo() - { - $this->dccSetup(); - - $this->card->number = '4002933640008365'; - $orderId = GenerationUtils::generateOrderId(); - - $dccDetails = $this->card->getDccRate(DccRateType::SALE, 10, 'USD', DccProcessor::FEXCO, $orderId); - - $this->assertNotNull($dccDetails); - $this->assertEquals('00', $dccDetails->responseCode, $dccDetails->responseMessage); - $this->assertNotNull($dccDetails->dccResponseResult); - } - - public function testCreditDccRateAuthorize() - { - $this->dccSetup(); - - $this->card->number = '4006097467207025'; - $orderId = GenerationUtils::generateOrderId(); - - $dccDetails = $this->card->getDccRate(DccRateType::SALE, 1001, 'EUR', DccProcessor::FEXCO, $orderId); - - $this->assertNotNull($dccDetails); - $this->assertEquals('00', $dccDetails->responseCode, $dccDetails->responseMessage); - $this->assertNotNull($dccDetails->dccResponseResult); - - //set Currency conversion rates - $dccValues = new DccRateData(); - $dccValues->orderId = $dccDetails->transactionReference->orderId; - $dccValues->dccProcessor = DccProcessor::FEXCO; - $dccValues->dccType = 1; - $dccValues->dccRateType = DccRateType::SALE; - $dccValues->currency = $dccDetails->dccResponseResult->cardHolderCurrency; - $dccValues->dccRate = $dccDetails->dccResponseResult->cardHolderRate; - $dccValues->amount = $dccDetails->dccResponseResult->cardHolderAmount; - - $response = $this->card->authorize(1001) - ->withCurrency('EUR') - ->withAllowDuplicates(true) - ->withDccRateData($dccValues) - ->withOrderId($orderId) - ->execute(); - - $this->assertNotNull($response); - $this->assertEquals('00', $response->responseCode, $response->responseMessage); - } - - public function testCreditDccRateCharge() - { - $this->dccSetup(); - - $this->card->number = '4006097467207025'; - $orderId = GenerationUtils::generateOrderId(); - - $dccDetails = $this->card->getDccRate(DccRateType::SALE, 1001, 'EUR', DccProcessor::FEXCO, $orderId); - - $this->assertNotNull($dccDetails); - $this->assertEquals('00', $dccDetails->responseCode, $dccDetails->responseMessage); - $this->assertNotNull($dccDetails->dccResponseResult); - - //set Currency conversion rates - $dccValues = new DccRateData(); - $dccValues->orderId = $dccDetails->transactionReference->orderId; - $dccValues->dccProcessor = DccProcessor::FEXCO; - $dccValues->dccType = 1; - $dccValues->dccRateType = DccRateType::SALE; - $dccValues->currency = $dccDetails->dccResponseResult->cardHolderCurrency; - $dccValues->dccRate = $dccDetails->dccResponseResult->cardHolderRate; - $dccValues->amount = $dccDetails->dccResponseResult->cardHolderAmount; - - $response = $this->card->charge(1001) - ->withCurrency('EUR') - ->withAllowDuplicates(true) - ->withDccRateData($dccValues) - ->withOrderId($orderId) - ->execute(); - - $this->assertNotNull($response); - $this->assertEquals('00', $response->responseCode, $response->responseMessage); - } - - /** - * @expectedException GlobalPayments\Api\Entities\Exceptions\GatewayException - * @expectedExceptionMessage Unexpected Gateway Response: 105 - Cannot find DCC information for that card - */ - public function testCreditDccInfoNotFound() - { - $this->dccSetup(); - - $this->card->number = '4002933640008365'; - $orderId = GenerationUtils::generateOrderId(); - - $dccDetails = $this->card->getDccRate(DccRateType::SALE, 10, 'EUR', DccProcessor::FEXCO, $orderId); - } - - /** - * @expectedException GlobalPayments\Api\Entities\Exceptions\GatewayException - * @expectedExceptionMessage Unexpected Gateway Response: 508 - Incorrect DCC information - doesn't correspond to dccrate request - */ - public function testCreditDccInfoMismatch() - { - $this->dccSetup(); - - $this->card->number = '4006097467207025'; - $orderId = GenerationUtils::generateOrderId(); - - $dccDetails = $this->card->getDccRate(DccRateType::SALE, 1001, 'EUR', DccProcessor::FEXCO, $orderId); - - $this->assertNotNull($dccDetails); - $this->assertEquals('00', $dccDetails->responseCode, $dccDetails->responseMessage); - $this->assertNotNull($dccDetails->dccResponseResult); - - $dccValues = new DccRateData(); - $dccValues->orderId = $dccDetails->transactionReference->orderId; - $dccValues->dccProcessor = DccProcessor::FEXCO; - $dccValues->dccType = 1; - $dccValues->dccRateType = DccRateType::SALE; - $dccValues->currency = $dccDetails->dccResponseResult->cardHolderCurrency; - $dccValues->dccRate = $dccDetails->dccResponseResult->cardHolderRate; - $dccValues->amount = $dccDetails->dccResponseResult->cardHolderAmount; - - $response = $this->card->authorize(100) - ->withCurrency('EUR') - ->withAllowDuplicates(true) - ->withDccRateData($dccValues) - ->withOrderId($orderId) - ->execute(); - } -} +number = '4111111111111111'; + $card->expMonth = 12; + $card->expYear = TestCards::validCardExpYear(); + $card->cvn = '123'; + $card->cardHolderName = 'Joe Smith'; + $this->card = $card; + + ServicesContainer::configureService($this->getConfig()); + } + + public function testCreditAuthorization() + { + $authorization = $this->card->authorize(14) + ->withCurrency('USD') + ->withAllowDuplicates(true) + ->execute(); + $this->assertNotNull($authorization); + $this->assertEquals('00', $authorization->responseCode); + + $capture = $authorization->capture(16) + ->withGratuity(2) + ->execute(); + $this->assertNotNull($capture); + $this->assertEquals('00', $capture->responseCode); + } + + public function testCreditServiceAuth() + { + $service = new CreditService( + $this->getConfig() + ); + + $authorization = $service->authorize(15) + ->withCurrency('USD') + ->withPaymentMethod($this->card) + ->withAllowDuplicates(true) + ->execute(); + $this->assertNotNull($authorization); + $this->assertEquals('00', $authorization->responseCode); + + $capture = $service->capture($authorization->transactionReference) + ->withAmount(17) + ->withGratuity(2) + ->execute(); + $this->assertNotNull($capture); + $this->assertEquals('00', $capture->responseCode); + } + + public function testCreditSale() + { + $response = $this->card->charge(15) + ->withCurrency('USD') + ->withAllowDuplicates(true) + ->execute(); + + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode); + } + + public function testCreditRefund() + { + $response = $this->card->refund(16) + ->withCurrency('USD') + ->withAllowDuplicates(true) + ->execute(); + + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode); + } + + public function testCreditRebate() + { + $response = $this->card->charge(17) + ->withCurrency('USD') + ->withAllowDuplicates(true) + ->execute(); + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode, $response->responseMessage); + + $rebate = $response->refund(17) + ->withCurrency('USD') + ->execute(); + $this->assertNotNull($rebate); + $this->assertEquals('00', $rebate->responseCode, $rebate->responseMessage); + } + + public function testCreditVoid() + { + $response = $this->card->charge(15) + ->withCurrency('USD') + ->withAllowDuplicates(true) + ->execute(); + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode, $response->responseMessage); + + $voidResponse = $response->void()->execute(); + $this->assertNotNull($voidResponse); + $this->assertEquals('00', $voidResponse->responseCode, $voidResponse->responseMessage); + } + + public function testCreditVerify() + { + $response = $this->card->verify() + ->withAllowDuplicates(true) + ->execute(); + + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode); + } + + protected function getConfig() + { + $config = new GpEcomConfig(); + $config->merchantId = 'heartlandgpsandbox'; + $config->accountId = 'api'; + $config->sharedSecret = 'secret'; + $config->rebatePassword = 'rebate'; + $config->refundPassword = 'refund'; + $config->serviceUrl = 'https://api.sandbox.realexpayments.com/epage-remote.cgi'; + return $config; + } + + protected function dccSetup() + { + $config = new GpEcomConfig(); + $config->merchantId = "heartlandgpsandbox"; + $config->accountId = "apidcc"; + $config->refundPassword = "refund"; + $config->sharedSecret = "secret"; + $config->serviceUrl = "https://api.sandbox.realexpayments.com/epage-remote.cgi"; + + ServicesContainer::configureService($config); + } + + public function testCreditGetDccInfo() + { + $this->dccSetup(); + + $this->card->number = '4002933640008365'; + $orderId = GenerationUtils::generateOrderId(); + + $dccDetails = $this->card->getDccRate(DccRateType::SALE, 10, 'USD', DccProcessor::FEXCO, $orderId); + + $this->assertNotNull($dccDetails); + $this->assertEquals('00', $dccDetails->responseCode, $dccDetails->responseMessage); + $this->assertNotNull($dccDetails->dccResponseResult); + } + + public function testCreditDccRateAuthorize() + { + $this->dccSetup(); + + $this->card->number = '4006097467207025'; + $orderId = GenerationUtils::generateOrderId(); + + $dccDetails = $this->card->getDccRate(DccRateType::SALE, 1001, 'EUR', DccProcessor::FEXCO, $orderId); + + $this->assertNotNull($dccDetails); + $this->assertEquals('00', $dccDetails->responseCode, $dccDetails->responseMessage); + $this->assertNotNull($dccDetails->dccResponseResult); + + //set Currency conversion rates + $dccValues = new DccRateData(); + $dccValues->orderId = $dccDetails->transactionReference->orderId; + $dccValues->dccProcessor = DccProcessor::FEXCO; + $dccValues->dccType = 1; + $dccValues->dccRateType = DccRateType::SALE; + $dccValues->currency = $dccDetails->dccResponseResult->cardHolderCurrency; + $dccValues->dccRate = $dccDetails->dccResponseResult->cardHolderRate; + $dccValues->amount = $dccDetails->dccResponseResult->cardHolderAmount; + + $response = $this->card->authorize(1001) + ->withCurrency('EUR') + ->withAllowDuplicates(true) + ->withDccRateData($dccValues) + ->withOrderId($orderId) + ->execute(); + + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode, $response->responseMessage); + } + + public function testCreditDccRateCharge() + { + $this->dccSetup(); + + $this->card->number = '4006097467207025'; + $orderId = GenerationUtils::generateOrderId(); + + $dccDetails = $this->card->getDccRate(DccRateType::SALE, 1001, 'EUR', DccProcessor::FEXCO, $orderId); + + $this->assertNotNull($dccDetails); + $this->assertEquals('00', $dccDetails->responseCode, $dccDetails->responseMessage); + $this->assertNotNull($dccDetails->dccResponseResult); + + //set Currency conversion rates + $dccValues = new DccRateData(); + $dccValues->orderId = $dccDetails->transactionReference->orderId; + $dccValues->dccProcessor = DccProcessor::FEXCO; + $dccValues->dccType = 1; + $dccValues->dccRateType = DccRateType::SALE; + $dccValues->currency = $dccDetails->dccResponseResult->cardHolderCurrency; + $dccValues->dccRate = $dccDetails->dccResponseResult->cardHolderRate; + $dccValues->amount = $dccDetails->dccResponseResult->cardHolderAmount; + + $response = $this->card->charge(1001) + ->withCurrency('EUR') + ->withAllowDuplicates(true) + ->withDccRateData($dccValues) + ->withOrderId($orderId) + ->execute(); + + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode, $response->responseMessage); + } + + /** + * @expectedException GlobalPayments\Api\Entities\Exceptions\GatewayException + * @expectedExceptionMessage Unexpected Gateway Response: 105 - Cannot find DCC information for that card + */ + public function testCreditDccInfoNotFound() + { + $this->dccSetup(); + + $this->card->number = '4002933640008365'; + $orderId = GenerationUtils::generateOrderId(); + + $dccDetails = $this->card->getDccRate(DccRateType::SALE, 10, 'EUR', DccProcessor::FEXCO, $orderId); + } + + /** + * @expectedException GlobalPayments\Api\Entities\Exceptions\GatewayException + * @expectedExceptionMessage Unexpected Gateway Response: 508 - Incorrect DCC information - doesn't correspond to dccrate request + */ + public function testCreditDccInfoMismatch() + { + $this->dccSetup(); + + $this->card->number = '4006097467207025'; + $orderId = GenerationUtils::generateOrderId(); + + $dccDetails = $this->card->getDccRate(DccRateType::SALE, 1001, 'EUR', DccProcessor::FEXCO, $orderId); + + $this->assertNotNull($dccDetails); + $this->assertEquals('00', $dccDetails->responseCode, $dccDetails->responseMessage); + $this->assertNotNull($dccDetails->dccResponseResult); + + $dccValues = new DccRateData(); + $dccValues->orderId = $dccDetails->transactionReference->orderId; + $dccValues->dccProcessor = DccProcessor::FEXCO; + $dccValues->dccType = 1; + $dccValues->dccRateType = DccRateType::SALE; + $dccValues->currency = $dccDetails->dccResponseResult->cardHolderCurrency; + $dccValues->dccRate = $dccDetails->dccResponseResult->cardHolderRate; + $dccValues->amount = $dccDetails->dccResponseResult->cardHolderAmount; + + $response = $this->card->authorize(100) + ->withCurrency('EUR') + ->withAllowDuplicates(true) + ->withDccRateData($dccValues) + ->withOrderId($orderId) + ->execute(); + } +} diff --git a/test/Integration/Gateways/RealexConnector/Hpp/RealexHppClient.php b/test/Integration/Gateways/RealexConnector/Hpp/RealexHppClient.php index f67a188e..0c8ca3b5 100644 --- a/test/Integration/Gateways/RealexConnector/Hpp/RealexHppClient.php +++ b/test/Integration/Gateways/RealexConnector/Hpp/RealexHppClient.php @@ -1,251 +1,251 @@ -sharedSecret = $sharedSecret; - } - - public function sendRequest($jsonData, $hppVersion = '') - { - $this->paymentData = GenerationUtils::decodeJson($jsonData, true, $hppVersion); - - $timestamp = $this->getValue('TIMESTAMP'); - $merchantId = $this->getValue('MERCHANT_ID'); - $account = $this->getValue('ACCOUNT'); - $orderId = $this->getValue('ORDER_ID'); - $amount = $this->getValue('AMOUNT'); - $currency = $this->getValue('CURRENCY'); - $autoSettle = $this->getValue('AUTO_SETTLE_FLAG'); - $requestHash = $this->getValue('SHA1HASH'); - $shippingCode = $this->getValue('SHIPPING_CODE'); - $shippingCountry = $this->getValue('SHIPPING_CO'); - $billingCode = $this->getValue('BILLING_CODE'); - $billingCountry = $this->getValue('BILLING_CO'); - - $config = new GpEcomConfig(); - $config->merchantId = $merchantId; - $config->accountId = $account; - $config->sharedSecret = $this->sharedSecret; - $config->serviceUrl = 'https://api.sandbox.realexpayments.com/epage-remote.cgi'; - $config->hostedPaymentConfig = new HostedPaymentConfig(); - $config->hostedPaymentConfig->language = "GB"; - $config->hostedPaymentConfig->responseUrl = "http://requestb.in/10q2bjb1"; - $config->hostedPaymentConfig->version = $hppVersion; - - ServicesContainer::configureService($config); - - // create the card object - $card = new CreditCardData(); - $card->number = '4006097467207025'; - $card->expMonth = 12; - $card->expYear = TestCards::validCardExpYear(); - $card->cvn = '131'; - $card->cardHolderName = 'James Mason'; - - // // check hash - $hashParam = [ - $timestamp, - $merchantId, - $orderId, - $amount, - $currency - ]; - - //for stored card - - if (!empty($this->paymentData['OFFER_SAVE_CARD'])) { - $hashParam[] = (!empty($this->paymentData['PAYER_REF'])) ? - $this->paymentData['PAYER_REF'] : null; - $hashParam[] = (!empty($this->paymentData['PMT_REF'])) ? - $this->paymentData['PMT_REF'] : null; - } - - $newHash = GenerationUtils::generateHash( - $this->sharedSecret, - implode('.', $hashParam) - ); - if ($newHash != $requestHash) { - throw new ApiException("Incorrect hash. Please check your code and the Developers Documentation."); - } - - // build request - if ($amount == null) { - $validate = $this->getValue("VALIDATE_CARD_ONLY"); - if ($validate) { - $gatewayRequest = $card->verify(); - } else { - $gatewayRequest = $card->verify()->WithRequestMultiUseToken(true); - } - } else { - $amount = $amount / 100; - if ($autoSettle) { - $gatewayRequest = $card->charge($amount); - } else { - $gatewayRequest = $card->authorize($amount); - } - } - - try { - $gatewayRequest - ->WithCurrency($currency) - ->WithOrderId($orderId) - ->withTimeStamp($timestamp); - - $this->addAddressDetails($gatewayRequest, $billingCode, $billingCountry, AddressType::BILLING); - $this->addAddressDetails($gatewayRequest, $shippingCode, $shippingCountry, AddressType::SHIPPING); - - //handle DCC - $this->addDCCInfo($gatewayRequest, $orderId); - - //handle fraud management - $this->addFraudManagementInfo($gatewayRequest, $orderId); - - $gatewayResponse = $gatewayRequest->execute(); - - if ($gatewayResponse->responseCode === '00') { - return $this->convertResponse($gatewayResponse); - } - } catch (ApiException $exc) { - throw $exc; - } - return null; - } - - public function getValue($value) - { - if (isset($this->paymentData[$value])) { - return $this->paymentData[$value]; - } - return null; - } - - public function addDCCInfo($gatewayRequest, $orderId) - { - if (!empty($this->paymentData['DCC_ENABLE'])) { - $dccInfo = $this->getValue('DCC_INFO'); - - $dccValues = new DccRateData(); - $dccValues->orderId = $orderId; - $dccValues->dccProcessor = $dccInfo['CCP']; - $dccValues->dccType = $dccInfo['TYPE']; - $dccValues->dccRateType = $dccInfo['RATE_TYPE']; - $dccValues->currency = $dccInfo['CURRENCY']; - $dccValues->dccRate = $dccInfo['RATE']; - $dccValues->amount = $dccInfo['AMOUNT']; - - $gatewayRequest - ->withDccRateData($dccValues); - } - } - - public function addFraudManagementInfo($gatewayRequest, $orderId) - { - if (!empty($this->paymentData['HPP_FRAUD_FILTER_MODE'])) { - $tssInfo = $this->getValue('TSS_INFO'); - - $this->addAddressDetails( - $gatewayRequest, - $tssInfo['BILLING_ADDRESS']['CODE'], - $tssInfo['BILLING_ADDRESS']['COUNTRY'], - AddressType::BILLING - ); - - $this->addAddressDetails( - $gatewayRequest, - $tssInfo['SHIPPING_ADDRESS']['CODE'], - $tssInfo['SHIPPING_ADDRESS']['COUNTRY'], - AddressType::SHIPPING - ); - - $gatewayRequest - ->withProductId($tssInfo['PRODID']) // prodid - ->withClientTransactionId($tssInfo['VARREF']) // varref - ->withCustomerId($tssInfo['CUSTNUM']) // custnum - ->withCustomerIpAddress($tssInfo['CUSTIPADDRESS']) - ->withFraudFilter($this->paymentData['HPP_FRAUD_FILTER_MODE']); - } - } - - public function addAddressDetails($gatewayRequest, $code, $country, $addressType = AddressType::BILLING) - { - if ($code != null || $country != null) { - $address = new Address(); - $address->postalCode = $code; - $address->country = $country; - - $gatewayRequest - ->WithAddress($address, $addressType); - } - } - - public function convertResponse($gatewayResponse) - { - $merchantId = $this->paymentData['MERCHANT_ID']; - $account = $this->paymentData['ACCOUNT']; - - $newHash = GenerationUtils::generateHash( - $this->sharedSecret, - implode('.', [ - $gatewayResponse->timestamp, - $merchantId, - $gatewayResponse->transactionReference->orderId, - $gatewayResponse->responseCode, - $gatewayResponse->responseMessage, - $gatewayResponse->transactionReference->transactionId, - $gatewayResponse->transactionReference->authCode - ]) - ); - - // begin building response - $response = [ - 'MERCHANT_ID' => $merchantId, - 'ACCOUNT' => $this->getValue('ACCOUNT'), - 'ORDER_ID' => $gatewayResponse->transactionReference->orderId, - 'TIMESTAMP' => $gatewayResponse->timestamp, - 'RESULT' => $gatewayResponse->responseCode, - 'PASREF' => $gatewayResponse->transactionReference->transactionId, - 'AUTHCODE' => $gatewayResponse->transactionReference->authCode, - 'AVSPOSTCODERESULT' => $gatewayResponse->avsResponseCode, - 'CVNRESULT' => $gatewayResponse->cvnResponseCode, - 'HPP_LANG' => $this->getValue('HPP_LANG'), - 'SHIPPING_CODE' => $this->getValue('SHIPPING_CODE'), - 'SHIPPING_CO' => $this->getValue('SHIPPING_CO'), - 'BILLING_CODE' => $this->getValue('BILLING_CODE'), - 'BILLING_CO' => $this->getValue('BILLING_CO'), - 'ECI' => $this->getValue('ECI'), - 'CAVV' => $this->getValue('CAVV'), - 'XID' => $this->getValue('XID'), - 'MERCHANT_RESPONSE_URL' => $this->getValue('MERCHANT_RESPONSE_URL'), - 'CARD_PAYMENT_BUTTON' => $this->getValue('CARD_PAYMENT_BUTTON'), - 'MESSAGE' => $gatewayResponse->responseMessage, - 'AMOUNT' => $this->getValue('AMOUNT'), - 'SHA1HASH' => $newHash, - 'DCC_INFO_REQUST' => $this->getValue('DCC_INFO'), - 'DCC_INFO_RESPONSE' => $gatewayResponse->dccResponseResult, - 'HPP_FRAUD_FILTER_MODE' => $this->getValue('HPP_FRAUD_FILTER_MODE'), - 'TSS_INFO' => $this->getValue('TSS_INFO') - ]; - - return json_encode($response); - } -} +sharedSecret = $sharedSecret; + } + + public function sendRequest($jsonData, $hppVersion = '') + { + $this->paymentData = GenerationUtils::decodeJson($jsonData, true, $hppVersion); + + $timestamp = $this->getValue('TIMESTAMP'); + $merchantId = $this->getValue('MERCHANT_ID'); + $account = $this->getValue('ACCOUNT'); + $orderId = $this->getValue('ORDER_ID'); + $amount = $this->getValue('AMOUNT'); + $currency = $this->getValue('CURRENCY'); + $autoSettle = $this->getValue('AUTO_SETTLE_FLAG'); + $requestHash = $this->getValue('SHA1HASH'); + $shippingCode = $this->getValue('SHIPPING_CODE'); + $shippingCountry = $this->getValue('SHIPPING_CO'); + $billingCode = $this->getValue('BILLING_CODE'); + $billingCountry = $this->getValue('BILLING_CO'); + + $config = new GpEcomConfig(); + $config->merchantId = $merchantId; + $config->accountId = $account; + $config->sharedSecret = $this->sharedSecret; + $config->serviceUrl = 'https://api.sandbox.realexpayments.com/epage-remote.cgi'; + $config->hostedPaymentConfig = new HostedPaymentConfig(); + $config->hostedPaymentConfig->language = "GB"; + $config->hostedPaymentConfig->responseUrl = "http://requestb.in/10q2bjb1"; + $config->hostedPaymentConfig->version = $hppVersion; + + ServicesContainer::configureService($config); + + // create the card object + $card = new CreditCardData(); + $card->number = '4006097467207025'; + $card->expMonth = 12; + $card->expYear = TestCards::validCardExpYear(); + $card->cvn = '131'; + $card->cardHolderName = 'James Mason'; + + // // check hash + $hashParam = [ + $timestamp, + $merchantId, + $orderId, + $amount, + $currency + ]; + + //for stored card + + if (!empty($this->paymentData['OFFER_SAVE_CARD'])) { + $hashParam[] = (!empty($this->paymentData['PAYER_REF'])) ? + $this->paymentData['PAYER_REF'] : null; + $hashParam[] = (!empty($this->paymentData['PMT_REF'])) ? + $this->paymentData['PMT_REF'] : null; + } + + $newHash = GenerationUtils::generateHash( + $this->sharedSecret, + implode('.', $hashParam) + ); + if ($newHash != $requestHash) { + throw new ApiException("Incorrect hash. Please check your code and the Developers Documentation."); + } + + // build request + if ($amount == null) { + $validate = $this->getValue("VALIDATE_CARD_ONLY"); + if ($validate) { + $gatewayRequest = $card->verify(); + } else { + $gatewayRequest = $card->verify()->WithRequestMultiUseToken(true); + } + } else { + $amount = $amount / 100; + if ($autoSettle) { + $gatewayRequest = $card->charge($amount); + } else { + $gatewayRequest = $card->authorize($amount); + } + } + + try { + $gatewayRequest + ->WithCurrency($currency) + ->WithOrderId($orderId) + ->withTimeStamp($timestamp); + + $this->addAddressDetails($gatewayRequest, $billingCode, $billingCountry, AddressType::BILLING); + $this->addAddressDetails($gatewayRequest, $shippingCode, $shippingCountry, AddressType::SHIPPING); + + //handle DCC + $this->addDCCInfo($gatewayRequest, $orderId); + + //handle fraud management + $this->addFraudManagementInfo($gatewayRequest, $orderId); + + $gatewayResponse = $gatewayRequest->execute(); + + if ($gatewayResponse->responseCode === '00') { + return $this->convertResponse($gatewayResponse); + } + } catch (ApiException $exc) { + throw $exc; + } + return null; + } + + public function getValue($value) + { + if (isset($this->paymentData[$value])) { + return $this->paymentData[$value]; + } + return null; + } + + public function addDCCInfo($gatewayRequest, $orderId) + { + if (!empty($this->paymentData['DCC_ENABLE'])) { + $dccInfo = $this->getValue('DCC_INFO'); + + $dccValues = new DccRateData(); + $dccValues->orderId = $orderId; + $dccValues->dccProcessor = $dccInfo['CCP']; + $dccValues->dccType = $dccInfo['TYPE']; + $dccValues->dccRateType = $dccInfo['RATE_TYPE']; + $dccValues->currency = $dccInfo['CURRENCY']; + $dccValues->dccRate = $dccInfo['RATE']; + $dccValues->amount = $dccInfo['AMOUNT']; + + $gatewayRequest + ->withDccRateData($dccValues); + } + } + + public function addFraudManagementInfo($gatewayRequest, $orderId) + { + if (!empty($this->paymentData['HPP_FRAUD_FILTER_MODE'])) { + $tssInfo = $this->getValue('TSS_INFO'); + + $this->addAddressDetails( + $gatewayRequest, + $tssInfo['BILLING_ADDRESS']['CODE'], + $tssInfo['BILLING_ADDRESS']['COUNTRY'], + AddressType::BILLING + ); + + $this->addAddressDetails( + $gatewayRequest, + $tssInfo['SHIPPING_ADDRESS']['CODE'], + $tssInfo['SHIPPING_ADDRESS']['COUNTRY'], + AddressType::SHIPPING + ); + + $gatewayRequest + ->withProductId($tssInfo['PRODID']) // prodid + ->withClientTransactionId($tssInfo['VARREF']) // varref + ->withCustomerId($tssInfo['CUSTNUM']) // custnum + ->withCustomerIpAddress($tssInfo['CUSTIPADDRESS']) + ->withFraudFilter($this->paymentData['HPP_FRAUD_FILTER_MODE']); + } + } + + public function addAddressDetails($gatewayRequest, $code, $country, $addressType = AddressType::BILLING) + { + if ($code != null || $country != null) { + $address = new Address(); + $address->postalCode = $code; + $address->country = $country; + + $gatewayRequest + ->WithAddress($address, $addressType); + } + } + + public function convertResponse($gatewayResponse) + { + $merchantId = $this->paymentData['MERCHANT_ID']; + $account = $this->paymentData['ACCOUNT']; + + $newHash = GenerationUtils::generateHash( + $this->sharedSecret, + implode('.', [ + $gatewayResponse->timestamp, + $merchantId, + $gatewayResponse->transactionReference->orderId, + $gatewayResponse->responseCode, + $gatewayResponse->responseMessage, + $gatewayResponse->transactionReference->transactionId, + $gatewayResponse->transactionReference->authCode + ]) + ); + + // begin building response + $response = [ + 'MERCHANT_ID' => $merchantId, + 'ACCOUNT' => $this->getValue('ACCOUNT'), + 'ORDER_ID' => $gatewayResponse->transactionReference->orderId, + 'TIMESTAMP' => $gatewayResponse->timestamp, + 'RESULT' => $gatewayResponse->responseCode, + 'PASREF' => $gatewayResponse->transactionReference->transactionId, + 'AUTHCODE' => $gatewayResponse->transactionReference->authCode, + 'AVSPOSTCODERESULT' => $gatewayResponse->avsResponseCode, + 'CVNRESULT' => $gatewayResponse->cvnResponseCode, + 'HPP_LANG' => $this->getValue('HPP_LANG'), + 'SHIPPING_CODE' => $this->getValue('SHIPPING_CODE'), + 'SHIPPING_CO' => $this->getValue('SHIPPING_CO'), + 'BILLING_CODE' => $this->getValue('BILLING_CODE'), + 'BILLING_CO' => $this->getValue('BILLING_CO'), + 'ECI' => $this->getValue('ECI'), + 'CAVV' => $this->getValue('CAVV'), + 'XID' => $this->getValue('XID'), + 'MERCHANT_RESPONSE_URL' => $this->getValue('MERCHANT_RESPONSE_URL'), + 'CARD_PAYMENT_BUTTON' => $this->getValue('CARD_PAYMENT_BUTTON'), + 'MESSAGE' => $gatewayResponse->responseMessage, + 'AMOUNT' => $this->getValue('AMOUNT'), + 'SHA1HASH' => $newHash, + 'DCC_INFO_REQUST' => $this->getValue('DCC_INFO'), + 'DCC_INFO_RESPONSE' => $gatewayResponse->dccResponseResult, + 'HPP_FRAUD_FILTER_MODE' => $this->getValue('HPP_FRAUD_FILTER_MODE'), + 'TSS_INFO' => $this->getValue('TSS_INFO') + ]; + + return json_encode($response); + } +} diff --git a/test/Integration/Gateways/RealexConnector/HppTest.php b/test/Integration/Gateways/RealexConnector/HppTest.php index a10bea65..8d0ca1dc 100644 --- a/test/Integration/Gateways/RealexConnector/HppTest.php +++ b/test/Integration/Gateways/RealexConnector/HppTest.php @@ -1,756 +1,756 @@ -merchantId = "heartlandgpsandbox"; - $config->accountId = "hpp"; - $config->sharedSecret = "secret"; - $config->serviceUrl = "https://api.sandbox.realexpayments.com/epage-remote.cgi"; - $config->hostedPaymentConfig = new HostedPaymentConfig(); - $config->hostedPaymentConfig->language = "GB"; - $config->hostedPaymentConfig->responseUrl = "http://requestb.in/10q2bjb1"; - - return new HostedService($config); - } - - public function testCreditAuth() - { - $config = new GpEcomConfig(); - $config->merchantId = "heartlandgpsandbox"; - $config->accountId = "hpp"; - $config->sharedSecret = "secret"; - $config->serviceUrl = "https://api.sandbox.realexpayments.com/epage-remote.cgi"; - $config->hostedPaymentConfig = new HostedPaymentConfig(); - $config->hostedPaymentConfig->language = "GB"; - $config->hostedPaymentConfig->responseUrl = "http://requestb.in/10q2bjb1"; - - $client = new RealexHppClient("secret"); - - $address = new Address(); - $address->postalCode = "123|56"; - $address->country = "IRELAND"; - - //run test cases for different version - foreach ($this->hppVersionList as $hppVersion) { - $config->hostedPaymentConfig->version = $hppVersion; - $service = new HostedService($config); - - $json = $service->authorize(1) - ->withCurrency("EUR") - ->withCustomerId("123456") - ->withAddress($address) - ->serialize(); - - $this->assertNotNull($json); - - $response = $client->sendRequest($json, $hppVersion); - $this->assertNotNull($response); - - $parsedResponse = $service->parseResponse($response); - $this->assertEquals("00", $parsedResponse->responseCode); - } - } - - public function testCreditSale() - { - $config = new GpEcomConfig(); - $config->merchantId = "heartlandgpsandbox"; - $config->accountId = "hpp"; - $config->sharedSecret = "secret"; - $config->serviceUrl = "https://api.sandbox.realexpayments.com/epage-remote.cgi"; - $config->hostedPaymentConfig = new HostedPaymentConfig(); - $config->hostedPaymentConfig->language = "GB"; - $config->hostedPaymentConfig->responseUrl = "http://requestb.in/10q2bjb1"; - - $client = new RealexHppClient("secret"); - - $address = new Address(); - $address->postalCode = "123|56"; - $address->country = "IRELAND"; - - //run test cases for different version - foreach ($this->hppVersionList as $hppVersion) { - $config->hostedPaymentConfig->version = $hppVersion; - $service = new HostedService($config); - - $json = $service->charge(1) - ->withCurrency("EUR") - ->withCustomerId("123456") - ->withAddress($address) - ->serialize(); - $this->assertNotNull($json); - - $response = $client->sendRequest($json, $hppVersion); - $this->assertNotNull($response); - - $parsedResponse = $service->parseResponse($response); - - $this->assertNotNull($parsedResponse); - $this->assertEquals("00", $parsedResponse->responseCode); - } - } - - /* 03. ProcessPaymentOtbRequest */ - - public function testCreditVerify() - { - $config = new GpEcomConfig(); - $config->merchantId = "heartlandgpsandbox"; - $config->accountId = "hpp"; - $config->sharedSecret = "secret"; - $config->serviceUrl = "https://api.sandbox.realexpayments.com/epage-remote.cgi"; - $config->hostedPaymentConfig = new HostedPaymentConfig(); - $config->hostedPaymentConfig->language = "GB"; - $config->hostedPaymentConfig->responseUrl = "http://requestb.in/10q2bjb1"; - - $client = new RealexHppClient("secret"); - - $address = new Address(); - $address->postalCode = "123|56"; - $address->country = "IRELAND"; - - //run test cases for different version - foreach ($this->hppVersionList as $hppVersion) { - $config->hostedPaymentConfig->version = $hppVersion; - $service = new HostedService($config); - - $json = $service->verify() - ->withCurrency("EUR") - ->withCustomerId("123456") - ->withAddress($address) - ->serialize(); - $this->assertNotNull($json); - - $response = $client->sendRequest($json, $hppVersion); - $this->assertNotNull($response); - - $parsedResponse = $service->parseResponse($response); - $this->assertNotNull($parsedResponse); - $this->assertEquals("00", $parsedResponse->responseCode); - } - } - - /** - * @expectedException GlobalPayments\Api\Entities\Exceptions\BuilderException - */ - public function testAuthNoAmount() - { - $service = $this->basicSetup(); - $service->authorize(null)->withCurrency("USD")->serialize(); - } - - /** - * @expectedException GlobalPayments\Api\Entities\Exceptions\BuilderException - */ - public function testAuthNoCurrency() - { - $service = $this->basicSetup(); - $service->authorize(10)->serialize(); - } - - /** - * @expectedException GlobalPayments\Api\Entities\Exceptions\BuilderException - */ - public function testSaleNoAmount() - { - $service = $this->basicSetup(); - $service->charge(null)->withCurrency("USD")->serialize(); - } - - /** - * @expectedException GlobalPayments\Api\Entities\Exceptions\BuilderException - */ - public function testSaleNoCurrency() - { - $service = $this->basicSetup(); - $service->charge(10)->serialize(); - } - - /** - * @expectedException GlobalPayments\Api\Entities\Exceptions\BuilderException - */ - public function testVerifyNoCurrency() - { - $service = $this->basicSetup(); - $service->verify()->serialize(); - } - - /** - * @expectedException GlobalPayments\Api\Entities\Exceptions\BuilderException - */ - public function testVerifyWithAmount() - { - $service = $this->basicSetup(); - $service->verify()->withAmount(10)->serialize(); - } - - /* 05. CardStorageCreatePayerStoreCardRequest */ - - public function testCardStorageCreatePayer() - { - $config = new GpEcomConfig(); - $config->merchantId = "heartlandgpsandbox"; - $config->accountId = "3dsecure"; - $config->refundPassword = "refund"; - $config->sharedSecret = "secret"; - $config->serviceUrl = "https://api.sandbox.realexpayments.com/epage-remote.cgi"; - $config->hostedPaymentConfig = new HostedPaymentConfig(); - $config->hostedPaymentConfig->language = "GB"; - $config->hostedPaymentConfig->responseUrl = "http://requestb.in/10q2bjb1"; - - $client = new RealexHppClient("secret"); - - // data to be passed to the HPP along with transaction level settings - $hostedPaymentData = new HostedPaymentData(); - $hostedPaymentData->offerToSaveCard = "1"; // display the save card tick box - $hostedPaymentData->customerExists = "0"; // new customer - //run test cases for different version - foreach ($this->hppVersionList as $hppVersion) { - $config->hostedPaymentConfig->version = $hppVersion; - $service = new HostedService($config); - - $json = $service->charge(15) - ->withCurrency("EUR") - ->withHostedPaymentData($hostedPaymentData) - ->serialize(); - - $this->assertNotNull($json); - - $response = $client->sendRequest($json, $hppVersion); - $this->assertNotNull($response); - - $parsedResponse = $service->parseResponse($response); - $this->assertNotNull($parsedResponse); - $this->assertEquals("00", $parsedResponse->responseCode); - } - } - - /* 07. CardStorageDisplayStoredCardsRequest */ - - public function testCardStorageDisplayStoredCard() - { - $config = new GpEcomConfig(); - $config->merchantId = "heartlandgpsandbox"; - $config->accountId = "3dsecure"; - $config->refundPassword = "refund"; - $config->sharedSecret = "secret"; - $config->serviceUrl = "https://api.sandbox.realexpayments.com/epage-remote.cgi"; - $config->hostedPaymentConfig = new HostedPaymentConfig(); - $config->hostedPaymentConfig->language = "GB"; - $config->hostedPaymentConfig->responseUrl = "http://requestb.in/10q2bjb1"; - - $client = new RealexHppClient("secret"); - - // data to be passed to the HPP along with transaction level settings - $hostedPaymentData = new HostedPaymentData(); - $hostedPaymentData->offerToSaveCard = "1"; - $hostedPaymentData->customerExists = "1"; - $hostedPaymentData->customerKey = "5e7e9152-2d53-466d-91bc-6d12ebc56b79"; - - //run test cases for different version - foreach ($this->hppVersionList as $hppVersion) { - $config->hostedPaymentConfig->version = $hppVersion; - $service = new HostedService($config); - - $json = $service->charge(15) - ->withCurrency("EUR") - ->withHostedPaymentData($hostedPaymentData) - ->serialize(); - - $this->assertNotNull($json); - - $response = $client->sendRequest($json, $hppVersion); - $this->assertNotNull($response); - - $parsedResponse = $service->parseResponse($response); - $this->assertNotNull($parsedResponse); - $this->assertEquals("00", $parsedResponse->responseCode); - } - } - - /* 09. ContinuousAuthorityRequest */ - - public function testContinuousAuthorityRequest() - { - $config = new GpEcomConfig(); - $config->merchantId = "heartlandgpsandbox"; - $config->accountId = "3dsecure"; - $config->refundPassword = "refund"; - $config->sharedSecret = "secret"; - $config->serviceUrl = "https://api.sandbox.realexpayments.com/epage-remote.cgi"; - $config->hostedPaymentConfig = new HostedPaymentConfig(); - $config->hostedPaymentConfig->language = "GB"; - $config->hostedPaymentConfig->responseUrl = "http://requestb.in/10q2bjb1"; - - $client = new RealexHppClient("secret"); - - //run test cases for different version - foreach ($this->hppVersionList as $hppVersion) { - $config->hostedPaymentConfig->version = $hppVersion; - $service = new HostedService($config); - - $json = $service->charge(15) - ->withCurrency("EUR") - ->withRecurringInfo(RecurringType::FIXED, RecurringSequence::FIRST) - ->serialize(); - - $this->assertNotNull($json); - - $response = $client->sendRequest($json, $hppVersion); - $this->assertNotNull($response); - - $parsedResponse = $service->parseResponse($response); - $this->assertNotNull($parsedResponse); - $this->assertEquals("00", $parsedResponse->responseCode); - } - } - - /* 13. DynamicCurrencyConversionRequest */ - - public function testEnableDynamicCurrencyConversionRequest() - { - //set config for DCC - $config = new GpEcomConfig(); - $config->merchantId = "MerchantId"; - $config->accountId = "internet"; - $config->refundPassword = "refund"; - $config->sharedSecret = "secret"; - $config->serviceUrl = "https://api.sandbox.realexpayments.com/epage-remote.cgi"; - - $config->hostedPaymentConfig = new HostedPaymentConfig(); - $config->hostedPaymentConfig->language = "GB"; - $config->hostedPaymentConfig->responseUrl = "http://requestb.in/10q2bjb1"; - $config->hostedPaymentConfig->version = HppVersion::VERSION_2; - $config->hostedPaymentConfig->directCurrencyConversionEnabled = "1"; - - $service = new HostedService($config); - $client = new RealexHppClient("secret"); - - //serialize the request - $json = $service->Charge(19) - ->withCurrency("EUR") - ->withTimestamp("20170725154824") - ->withOrderId('GTI5Yxb0SumL_TkDMCAxQA') - ->serialize(); - - $this->assertNotNull($json); - $this->assertEquals($json, '{"MERCHANT_ID":"MerchantId","ACCOUNT":"internet","ORDER_ID":"GTI5Yxb0SumL_TkDMCAxQA","AMOUNT":"1900","CURRENCY":"EUR","TIMESTAMP":"20170725154824","AUTO_SETTLE_FLAG":"1","DCC_ENABLE":"1","HPP_LANG":"GB","MERCHANT_RESPONSE_URL":"http:\/\/requestb.in\/10q2bjb1","HPP_VERSION":"2","SHA1HASH":"448d742db89b05ce97152beb55157c904f3839cc"}'); - } - - public function testDisableDynamicCurrencyConversionRequest() - { - //set config for DCC - $config = new GpEcomConfig(); - $config->merchantId = "MerchantId"; - $config->accountId = "internet"; - $config->refundPassword = "refund"; - $config->sharedSecret = "secret"; - $config->serviceUrl = "https://api.sandbox.realexpayments.com/epage-remote.cgi"; - - $config->hostedPaymentConfig = new HostedPaymentConfig(); - $config->hostedPaymentConfig->language = "GB"; - $config->hostedPaymentConfig->responseUrl = "http://requestb.in/10q2bjb1"; - $config->hostedPaymentConfig->version = HppVersion::VERSION_2; - $config->hostedPaymentConfig->directCurrencyConversionEnabled = "0"; - - $service = new HostedService($config); - $client = new RealexHppClient("secret"); - - //serialize the request - $json = $service->Charge(19) - ->withCurrency("EUR") - ->withTimestamp("20170725154824") - ->withOrderId('GTI5Yxb0SumL_TkDMCAxQA') - ->serialize(); - - $this->assertNotNull($json); - $this->assertEquals($json, '{"MERCHANT_ID":"MerchantId","ACCOUNT":"internet","ORDER_ID":"GTI5Yxb0SumL_TkDMCAxQA","AMOUNT":"1900","CURRENCY":"EUR","TIMESTAMP":"20170725154824","AUTO_SETTLE_FLAG":"1","DCC_ENABLE":"0","HPP_LANG":"GB","MERCHANT_RESPONSE_URL":"http:\/\/requestb.in\/10q2bjb1","HPP_VERSION":"2","SHA1HASH":"448d742db89b05ce97152beb55157c904f3839cc"}'); - } - - /* 11. FraudManagementRequest */ - - public function testFraudManagementRequest() - { - $config = new GpEcomConfig(); - $config->merchantId = "heartlandgpsandbox"; - $config->accountId = "3dsecure"; - $config->refundPassword = "refund"; - $config->sharedSecret = "secret"; - $config->serviceUrl = "https://api.sandbox.realexpayments.com/epage-remote.cgi"; - $config->hostedPaymentConfig = new HostedPaymentConfig(); - $config->hostedPaymentConfig->language = "GB"; - $config->hostedPaymentConfig->responseUrl = "http://requestb.in/10q2bjb1"; - $config->hostedPaymentConfig->version = 2; - $config->hostedPaymentConfig->FraudFilterMode = FraudFilterMode::PASSIVE; - - $service = new HostedService($config); - $client = new RealexHppClient("secret"); - - // billing address - $billingAddress = new Address(); - $billingAddress->postalCode = "50001|Flat 123"; - $billingAddress->country = "US"; - - // shipping address - $shippingAddress = new Address(); - $shippingAddress->postalCode = "654|123"; - $shippingAddress->country = "GB"; - - // data to be passed to the HPP along with transaction level settings - $hostedPaymentData = new HostedPaymentData(); - $hostedPaymentData->customerNumber = "E8953893489"; // display the save card tick box - $hostedPaymentData->productId = "SID9838383"; // new customer - - //serialize the request - $json = $service->charge(19) - ->withCurrency("EUR") - ->withAddress($billingAddress, AddressType::BILLING) - ->withAddress($shippingAddress, AddressType::SHIPPING) - //->withProductId("SID9838383") // prodid - ->withClientTransactionId("Car Part HV") // varref - //->withCustomerId("E8953893489") // custnum - ->withCustomerIpAddress("123.123.123.123") - //->withFraudFilter(FraudFilterMode::PASSIVE) - ->withHostedPaymentData($hostedPaymentData) - ->serialize(); - - $this->assertNotNull($json); - - //make API call - $response = $client->sendRequest($json, $config->hostedPaymentConfig->version); - $this->assertNotNull($response); - - $parsedResponse = $service->parseResponse($response); - $this->assertNotNull($parsedResponse); - $this->assertEquals("00", $parsedResponse->responseCode); - } - - /* Serialize methods Test case */ - - public function testBasicAuthHppVersion1() - { - $config = new GpEcomConfig(); - $config->merchantId = "MerchantId"; - $config->accountId = "internet"; - $config->refundPassword = "refund"; - $config->sharedSecret = "secret"; - $config->serviceUrl = "https://pay.sandbox.realexpayments.com/pay"; - $config->hostedPaymentConfig = new HostedPaymentConfig(); - $config->hostedPaymentConfig->language = "GB"; - $config->hostedPaymentConfig->responseUrl = "https://www.example.com/response"; - $config->hostedPaymentConfig->version = HppVersion::VERSION_1; - - $service = new HostedService($config); - $client = new RealexHppClient("secret"); - - $json = $service->authorize(19.99) - ->withCurrency("EUR") - ->withTimeStamp("20170725154824") - ->WithOrderId("GTI5Yxb0SumL_TkDMCAxQA") - ->serialize(); - - $expectedJson = '{"MERCHANT_ID":"TWVyY2hhbnRJZA==","ACCOUNT":"aW50ZXJuZXQ=","ORDER_ID":"R1RJNVl4YjBTdW1MX1RrRE1DQXhRQQ==","AMOUNT":"MTk5OQ==","CURRENCY":"RVVS","TIMESTAMP":"MjAxNzA3MjUxNTQ4MjQ=","AUTO_SETTLE_FLAG":"MA==","HPP_LANG":"R0I=","MERCHANT_RESPONSE_URL":"aHR0cHM6Ly93d3cuZXhhbXBsZS5jb20vcmVzcG9uc2U=","HPP_VERSION":"MQ==","SHA1HASH":"MDYxNjA5Zjg1YThlMDE5MWRjN2Y0ODdmODI3OGU3MTg5OGEyZWUyZA=="}'; - $this->assertEquals($json, $expectedJson); - } - - public function testBasicAuthHppVersion2() - { - $config = new GpEcomConfig(); - $config->merchantId = "MerchantId"; - $config->accountId = "internet"; - $config->refundPassword = "refund"; - $config->sharedSecret = "secret"; - $config->serviceUrl = "https://pay.sandbox.realexpayments.com/pay"; - $config->hostedPaymentConfig = new HostedPaymentConfig(); - $config->hostedPaymentConfig->language = "GB"; - $config->hostedPaymentConfig->responseUrl = "https://www.example.com/response"; - $config->hostedPaymentConfig->version = HppVersion::VERSION_2; - - $service = new HostedService($config); - $client = new RealexHppClient("secret"); - - $json = $service->authorize(19.99) - ->withCurrency("EUR") - ->withTimeStamp("20170725154824") - ->WithOrderId("GTI5Yxb0SumL_TkDMCAxQA") - ->serialize(); - - $expectedJson = '{"MERCHANT_ID":"MerchantId","ACCOUNT":"internet","ORDER_ID":"GTI5Yxb0SumL_TkDMCAxQA","AMOUNT":"1999","CURRENCY":"EUR","TIMESTAMP":"20170725154824","AUTO_SETTLE_FLAG":"0","HPP_LANG":"GB","MERCHANT_RESPONSE_URL":"https:\/\/www.example.com\/response","HPP_VERSION":"2","SHA1HASH":"061609f85a8e0191dc7f487f8278e71898a2ee2d"}'; - $this->assertEquals($json, $expectedJson); - } - - public function testBasicSale() - { - $config = new GpEcomConfig(); - $config->merchantId = "MerchantId"; - $config->accountId = "internet"; - $config->refundPassword = "refund"; - $config->sharedSecret = "secret"; - $config->serviceUrl = "https://pay.sandbox.realexpayments.com/pay"; - $config->hostedPaymentConfig = new HostedPaymentConfig(); - $config->hostedPaymentConfig->language = "GB"; - $config->hostedPaymentConfig->responseUrl = "https://www.example.com/response"; - $config->hostedPaymentConfig->version = HppVersion::VERSION_2; - - $service = new HostedService($config); - $client = new RealexHppClient("secret"); - - $json = $service->charge(19.99) - ->withCurrency("EUR") - ->withTimeStamp("20170725154824") - ->WithOrderId("GTI5Yxb0SumL_TkDMCAxQA") - ->serialize(); - - $expectedJson = '{"MERCHANT_ID":"MerchantId","ACCOUNT":"internet","ORDER_ID":"GTI5Yxb0SumL_TkDMCAxQA","AMOUNT":"1999","CURRENCY":"EUR","TIMESTAMP":"20170725154824","AUTO_SETTLE_FLAG":"1","HPP_LANG":"GB","MERCHANT_RESPONSE_URL":"https:\/\/www.example.com\/response","HPP_VERSION":"2","SHA1HASH":"061609f85a8e0191dc7f487f8278e71898a2ee2d"}'; - $this->assertEquals($json, $expectedJson); - } - - public function testBasicHostedPaymentDataHppVersion1() - { - $config = new GpEcomConfig(); - $config->merchantId = "MerchantId"; - $config->accountId = "internet"; - $config->refundPassword = "refund"; - $config->sharedSecret = "secret"; - $config->serviceUrl = "https://pay.sandbox.realexpayments.com/pay"; - $config->hostedPaymentConfig = new HostedPaymentConfig(); - $config->hostedPaymentConfig->language = "GB"; - $config->hostedPaymentConfig->responseUrl = "https://www.example.com/response"; - $config->hostedPaymentConfig->version = HppVersion::VERSION_1; - - $service = new HostedService($config); - $client = new RealexHppClient("secret"); - - $hostedPaymentData = new HostedPaymentData(); - $hostedPaymentData->offerToSaveCard = "1"; // display the save card tick box - $hostedPaymentData->customerExists = "0"; // new customer - $hostedPaymentData->customerNumber = 'a028774f-beff-47bc-bd6e-ed7e04f5d758a028774f-btefa'; - $hostedPaymentData->productId = 'a0b38df5-b23c-4d82-88fe-2e9c47438972-b23c-4d82-88f'; - - $json = $service->charge(19.99) - ->withCurrency("EUR") - ->withTimeStamp("20170725154824") - ->WithOrderId("GTI5Yxb0SumL_TkDMCAxQA") - ->WithHostedPaymentData($hostedPaymentData) - ->WithDescription("Mobile Channel") - ->WithClientTransactionId("My Legal Entity") - ->serialize(); - - $expectedJson = '{"MERCHANT_ID":"TWVyY2hhbnRJZA==","ACCOUNT":"aW50ZXJuZXQ=","ORDER_ID":"R1RJNVl4YjBTdW1MX1RrRE1DQXhRQQ==","AMOUNT":"MTk5OQ==","CURRENCY":"RVVS","TIMESTAMP":"MjAxNzA3MjUxNTQ4MjQ=","AUTO_SETTLE_FLAG":"MQ==","COMMENT1":"TW9iaWxlIENoYW5uZWw=","CUST_NUM":"YTAyODc3NGYtYmVmZi00N2JjLWJkNmUtZWQ3ZTA0ZjVkNzU4YTAyODc3NGYtYnRlZmE=","OFFER_SAVE_CARD":"MQ==","PAYER_EXIST":"MA==","PROD_ID":"YTBiMzhkZjUtYjIzYy00ZDgyLTg4ZmUtMmU5YzQ3NDM4OTcyLWIyM2MtNGQ4Mi04OGY=","VAR_REF":"TXkgTGVnYWwgRW50aXR5","HPP_LANG":"R0I=","MERCHANT_RESPONSE_URL":"aHR0cHM6Ly93d3cuZXhhbXBsZS5jb20vcmVzcG9uc2U=","HPP_VERSION":"MQ==","SHA1HASH":"NzExNmM0OTgyNjM2N2M2NTEzZWZkYzBjYzgxZTI0M2I4MDk1ZDc4Zg=="}'; - $this->assertEquals($json, $expectedJson); - } - - public function testBasicHostedPaymentDataHppVersion2() - { - $config = new GpEcomConfig(); - $config->merchantId = "MerchantId"; - $config->accountId = "internet"; - $config->refundPassword = "refund"; - $config->sharedSecret = "secret"; - $config->serviceUrl = "https://pay.sandbox.realexpayments.com/pay"; - $config->hostedPaymentConfig = new HostedPaymentConfig(); - $config->hostedPaymentConfig->language = "GB"; - $config->hostedPaymentConfig->responseUrl = "https://www.example.com/response"; - $config->hostedPaymentConfig->version = HppVersion::VERSION_2; - - $service = new HostedService($config); - $client = new RealexHppClient("secret"); - - $hostedPaymentData = new HostedPaymentData(); - $hostedPaymentData->offerToSaveCard = "1"; // display the save card tick box - $hostedPaymentData->customerExists = "0"; // new customer - $hostedPaymentData->customerNumber = 'a028774f-beff-47bc-bd6e-ed7e04f5d758a028774f-btefa'; - $hostedPaymentData->productId = 'a0b38df5-b23c-4d82-88fe-2e9c47438972-b23c-4d82-88f'; - - $json = $service->charge(19.99) - ->withCurrency("EUR") - ->withTimeStamp("20170725154824") - ->WithOrderId("GTI5Yxb0SumL_TkDMCAxQA") - ->WithHostedPaymentData($hostedPaymentData) - ->WithDescription("Mobile Channel") - ->WithClientTransactionId("My Legal Entity") - ->serialize(); - - $expectedJson = '{"MERCHANT_ID":"MerchantId","ACCOUNT":"internet","ORDER_ID":"GTI5Yxb0SumL_TkDMCAxQA","AMOUNT":"1999","CURRENCY":"EUR","TIMESTAMP":"20170725154824","AUTO_SETTLE_FLAG":"1","COMMENT1":"Mobile Channel","CUST_NUM":"a028774f-beff-47bc-bd6e-ed7e04f5d758a028774f-btefa","OFFER_SAVE_CARD":"1","PAYER_EXIST":"0","PROD_ID":"a0b38df5-b23c-4d82-88fe-2e9c47438972-b23c-4d82-88f","VAR_REF":"My Legal Entity","HPP_LANG":"GB","MERCHANT_RESPONSE_URL":"https:\/\/www.example.com\/response","HPP_VERSION":"2","SHA1HASH":"7116c49826367c6513efdc0cc81e243b8095d78f"}'; - $this->assertEquals($json, $expectedJson); - } - - public function testParseResponse() - { - $config = new GpEcomConfig(); - $config->merchantId = "heartlandgpsandbox"; - $config->accountId = "hpp"; - $config->sharedSecret = "secret"; - $config->serviceUrl = "https://api.sandbox.realexpayments.com/epage-remote.cgi"; - $config->hostedPaymentConfig = new HostedPaymentConfig(); - $config->hostedPaymentConfig->language = "GB"; - $config->hostedPaymentConfig->responseUrl = "http://requestb.in/10q2bjb1"; - - $client = new RealexHppClient("secret"); - - $address = new Address(); - $address->postalCode = "123|56"; - $address->country = "IRELAND"; - - //run test cases for different version - foreach ($this->hppVersionList as $hppVersion) { - $config->hostedPaymentConfig->version = $hppVersion; - $service = new HostedService($config); - - $json = $service->authorize(1) - ->withCurrency("EUR") - ->withCustomerId("123456") - ->withAddress($address) - ->serialize(); - - $this->assertNotNull($json); - - $response = $client->sendRequest($json, $hppVersion); - $this->assertNotNull($response); - - // Base64 encode values - $iterator = new \RecursiveIteratorIterator(new \RecursiveArrayIterator(json_decode($response, true))); - foreach ($iterator as $key => $value) { - $iterator->getInnerIterator()->offsetSet($key, base64_encode($value)); - } - - $response = json_encode($iterator->getArrayCopy()); - - $parsedResponse = $service->parseResponse($response, true); - $this->assertEquals("00", $parsedResponse->responseCode); - } - } - - public function testHostedPaymentDataSupplementaryDataSerialize() - { - $config = new GpEcomConfig(); - $config->merchantId = "MerchantId"; - $config->accountId = "internet"; - $config->refundPassword = "refund"; - $config->sharedSecret = "secret"; - $config->serviceUrl = "https://pay.sandbox.realexpayments.com/pay"; - $config->hostedPaymentConfig = new HostedPaymentConfig(); - $config->hostedPaymentConfig->language = "GB"; - $config->hostedPaymentConfig->responseUrl = "https://www.example.com/response"; - $config->hostedPaymentConfig->version = HppVersion::VERSION_2; - $config->gatewayProvider = GatewayProvider::GP_ECOM; - - $service = new HostedService($config); - - $hostedPaymentData = new HostedPaymentData(); - $hostedPaymentData->offerToSaveCard = "1"; // display the save card tick box - $hostedPaymentData->customerExists = "0"; // new customer - $hostedPaymentData->customerNumber = 'a028774f-beff-47bc-bd6e-ed7e04f5d758a028774f-btefa'; - $hostedPaymentData->productId = 'a0b38df5-b23c-4d82-88fe-2e9c47438972-b23c-4d82-88f'; - $hostedPaymentData->supplementaryData = ['HPP_FRAUDFILTER_MODE' => 'ACTIVE']; - - $json = $service->charge(19.99) - ->withCurrency("EUR") - ->withTimeStamp("20170725154824") - ->withOrderId("GTI5Yxb0SumL_TkDMCAxQA") - ->withHostedPaymentData($hostedPaymentData) - ->withDescription("Mobile Channel") - ->withClientTransactionId("My Legal Entity") - ->serialize(); - - $expectedJson = '{"MERCHANT_ID":"MerchantId","ACCOUNT":"internet","ORDER_ID":"GTI5Yxb0SumL_TkDMCAxQA","AMOUNT":"1999","CURRENCY":"EUR","TIMESTAMP":"20170725154824","AUTO_SETTLE_FLAG":"1","COMMENT1":"Mobile Channel","CUST_NUM":"a028774f-beff-47bc-bd6e-ed7e04f5d758a028774f-btefa","OFFER_SAVE_CARD":"1","PAYER_EXIST":"0","PROD_ID":"a0b38df5-b23c-4d82-88fe-2e9c47438972-b23c-4d82-88f","VAR_REF":"My Legal Entity","HPP_LANG":"GB","MERCHANT_RESPONSE_URL":"https:\/\/www.example.com\/response","HPP_FRAUDFILTER_MODE":"ACTIVE","HPP_VERSION":"2","SHA1HASH":"7116c49826367c6513efdc0cc81e243b8095d78f"}'; - $this->assertEquals($json, $expectedJson); - } - - public function testSupplementaryDataWithOneValueSerialized() { - $config = new GpEcomConfig(); - $config->merchantId = "MerchantId"; - $config->accountId = "internet"; - $config->refundPassword = "refund"; - $config->sharedSecret = "secret"; - $config->serviceUrl = "https://pay.sandbox.realexpayments.com/pay"; - $config->hostedPaymentConfig = new HostedPaymentConfig(); - $config->hostedPaymentConfig->language = "GB"; - $config->hostedPaymentConfig->responseUrl = "https://www.example.com/response"; - $config->hostedPaymentConfig->version = HppVersion::VERSION_2; - $config->gatewayProvider = GatewayProvider::GP_ECOM; - - $service = new HostedService($config); - - $hostedPaymentData = new HostedPaymentData(); - $hostedPaymentData->offerToSaveCard = "1"; // display the save card tick box - $hostedPaymentData->customerExists = "0"; // new customer - $hostedPaymentData->customerNumber = 'a028774f-beff-47bc-bd6e-ed7e04f5d758a028774f-btefa'; - $hostedPaymentData->productId = 'a0b38df5-b23c-4d82-88fe-2e9c47438972-b23c-4d82-88f'; - - $json = $service->charge(19.99) - ->withCurrency("EUR") - ->withTimeStamp("20170725154824") - ->withOrderId("GTI5Yxb0SumL_TkDMCAxQA") - ->withHostedPaymentData($hostedPaymentData) - ->withDescription("Mobile Channel") - ->withClientTransactionId("My Legal Entity") - ->withSupplementaryData('HPP_FRAUDFILTER_MODE', 'ACTIVE') - ->serialize(); - - $expectedJson = '{"MERCHANT_ID":"MerchantId","ACCOUNT":"internet","ORDER_ID":"GTI5Yxb0SumL_TkDMCAxQA","AMOUNT":"1999","CURRENCY":"EUR","TIMESTAMP":"20170725154824","AUTO_SETTLE_FLAG":"1","COMMENT1":"Mobile Channel","CUST_NUM":"a028774f-beff-47bc-bd6e-ed7e04f5d758a028774f-btefa","OFFER_SAVE_CARD":"1","PAYER_EXIST":"0","PROD_ID":"a0b38df5-b23c-4d82-88fe-2e9c47438972-b23c-4d82-88f","VAR_REF":"My Legal Entity","HPP_LANG":"GB","MERCHANT_RESPONSE_URL":"https:\/\/www.example.com\/response","HPP_VERSION":"2","HPP_FRAUDFILTER_MODE":"ACTIVE","SHA1HASH":"7116c49826367c6513efdc0cc81e243b8095d78f"}'; - $this->assertEquals($json, $expectedJson); - } - - public function testSupplementaryDataWithTwoValuesSerialized() - { - $config = new GpEcomConfig(); - $config->merchantId = "MerchantId"; - $config->accountId = "internet"; - $config->refundPassword = "refund"; - $config->sharedSecret = "secret"; - $config->serviceUrl = "https://pay.sandbox.realexpayments.com/pay"; - $config->hostedPaymentConfig = new HostedPaymentConfig(); - $config->hostedPaymentConfig->language = "GB"; - $config->hostedPaymentConfig->responseUrl = "https://www.example.com/response"; - $config->hostedPaymentConfig->version = HppVersion::VERSION_2; - $config->gatewayProvider = GatewayProvider::GP_ECOM; - - $service = new HostedService($config); - - $hostedPaymentData = new HostedPaymentData(); - $hostedPaymentData->offerToSaveCard = "1"; // display the save card tick box - $hostedPaymentData->customerExists = "0"; // new customer - $hostedPaymentData->customerNumber = 'a028774f-beff-47bc-bd6e-ed7e04f5d758a028774f-btefa'; - $hostedPaymentData->productId = 'a0b38df5-b23c-4d82-88fe-2e9c47438972-b23c-4d82-88f'; - - $json = $service->charge(19.99) - ->withCurrency("EUR") - ->withTimeStamp("20170725154824") - ->withOrderId("GTI5Yxb0SumL_TkDMCAxQA") - ->withHostedPaymentData($hostedPaymentData) - ->withDescription("Mobile Channel") - ->withClientTransactionId("My Legal Entity") - ->withSupplementaryData(["RANDOM_KEY1" => "VALUE_1", "RANDOM_KEY2" => "VALUE_2"]) - ->serialize(); - - $expectedJson = '{"MERCHANT_ID":"MerchantId","ACCOUNT":"internet","ORDER_ID":"GTI5Yxb0SumL_TkDMCAxQA","AMOUNT":"1999","CURRENCY":"EUR","TIMESTAMP":"20170725154824","AUTO_SETTLE_FLAG":"1","COMMENT1":"Mobile Channel","CUST_NUM":"a028774f-beff-47bc-bd6e-ed7e04f5d758a028774f-btefa","OFFER_SAVE_CARD":"1","PAYER_EXIST":"0","PROD_ID":"a0b38df5-b23c-4d82-88fe-2e9c47438972-b23c-4d82-88f","VAR_REF":"My Legal Entity","HPP_LANG":"GB","MERCHANT_RESPONSE_URL":"https:\/\/www.example.com\/response","HPP_VERSION":"2","RANDOM_KEY1":"VALUE_1","RANDOM_KEY2":"VALUE_2","SHA1HASH":"7116c49826367c6513efdc0cc81e243b8095d78f"}'; - $this->assertEquals($json, $expectedJson); - } -} +merchantId = "heartlandgpsandbox"; + $config->accountId = "hpp"; + $config->sharedSecret = "secret"; + $config->serviceUrl = "https://api.sandbox.realexpayments.com/epage-remote.cgi"; + $config->hostedPaymentConfig = new HostedPaymentConfig(); + $config->hostedPaymentConfig->language = "GB"; + $config->hostedPaymentConfig->responseUrl = "http://requestb.in/10q2bjb1"; + + return new HostedService($config); + } + + public function testCreditAuth() + { + $config = new GpEcomConfig(); + $config->merchantId = "heartlandgpsandbox"; + $config->accountId = "hpp"; + $config->sharedSecret = "secret"; + $config->serviceUrl = "https://api.sandbox.realexpayments.com/epage-remote.cgi"; + $config->hostedPaymentConfig = new HostedPaymentConfig(); + $config->hostedPaymentConfig->language = "GB"; + $config->hostedPaymentConfig->responseUrl = "http://requestb.in/10q2bjb1"; + + $client = new RealexHppClient("secret"); + + $address = new Address(); + $address->postalCode = "123|56"; + $address->country = "IRELAND"; + + //run test cases for different version + foreach ($this->hppVersionList as $hppVersion) { + $config->hostedPaymentConfig->version = $hppVersion; + $service = new HostedService($config); + + $json = $service->authorize(1) + ->withCurrency("EUR") + ->withCustomerId("123456") + ->withAddress($address) + ->serialize(); + + $this->assertNotNull($json); + + $response = $client->sendRequest($json, $hppVersion); + $this->assertNotNull($response); + + $parsedResponse = $service->parseResponse($response); + $this->assertEquals("00", $parsedResponse->responseCode); + } + } + + public function testCreditSale() + { + $config = new GpEcomConfig(); + $config->merchantId = "heartlandgpsandbox"; + $config->accountId = "hpp"; + $config->sharedSecret = "secret"; + $config->serviceUrl = "https://api.sandbox.realexpayments.com/epage-remote.cgi"; + $config->hostedPaymentConfig = new HostedPaymentConfig(); + $config->hostedPaymentConfig->language = "GB"; + $config->hostedPaymentConfig->responseUrl = "http://requestb.in/10q2bjb1"; + + $client = new RealexHppClient("secret"); + + $address = new Address(); + $address->postalCode = "123|56"; + $address->country = "IRELAND"; + + //run test cases for different version + foreach ($this->hppVersionList as $hppVersion) { + $config->hostedPaymentConfig->version = $hppVersion; + $service = new HostedService($config); + + $json = $service->charge(1) + ->withCurrency("EUR") + ->withCustomerId("123456") + ->withAddress($address) + ->serialize(); + $this->assertNotNull($json); + + $response = $client->sendRequest($json, $hppVersion); + $this->assertNotNull($response); + + $parsedResponse = $service->parseResponse($response); + + $this->assertNotNull($parsedResponse); + $this->assertEquals("00", $parsedResponse->responseCode); + } + } + + /* 03. ProcessPaymentOtbRequest */ + + public function testCreditVerify() + { + $config = new GpEcomConfig(); + $config->merchantId = "heartlandgpsandbox"; + $config->accountId = "hpp"; + $config->sharedSecret = "secret"; + $config->serviceUrl = "https://api.sandbox.realexpayments.com/epage-remote.cgi"; + $config->hostedPaymentConfig = new HostedPaymentConfig(); + $config->hostedPaymentConfig->language = "GB"; + $config->hostedPaymentConfig->responseUrl = "http://requestb.in/10q2bjb1"; + + $client = new RealexHppClient("secret"); + + $address = new Address(); + $address->postalCode = "123|56"; + $address->country = "IRELAND"; + + //run test cases for different version + foreach ($this->hppVersionList as $hppVersion) { + $config->hostedPaymentConfig->version = $hppVersion; + $service = new HostedService($config); + + $json = $service->verify() + ->withCurrency("EUR") + ->withCustomerId("123456") + ->withAddress($address) + ->serialize(); + $this->assertNotNull($json); + + $response = $client->sendRequest($json, $hppVersion); + $this->assertNotNull($response); + + $parsedResponse = $service->parseResponse($response); + $this->assertNotNull($parsedResponse); + $this->assertEquals("00", $parsedResponse->responseCode); + } + } + + /** + * @expectedException GlobalPayments\Api\Entities\Exceptions\BuilderException + */ + public function testAuthNoAmount() + { + $service = $this->basicSetup(); + $service->authorize(null)->withCurrency("USD")->serialize(); + } + + /** + * @expectedException GlobalPayments\Api\Entities\Exceptions\BuilderException + */ + public function testAuthNoCurrency() + { + $service = $this->basicSetup(); + $service->authorize(10)->serialize(); + } + + /** + * @expectedException GlobalPayments\Api\Entities\Exceptions\BuilderException + */ + public function testSaleNoAmount() + { + $service = $this->basicSetup(); + $service->charge(null)->withCurrency("USD")->serialize(); + } + + /** + * @expectedException GlobalPayments\Api\Entities\Exceptions\BuilderException + */ + public function testSaleNoCurrency() + { + $service = $this->basicSetup(); + $service->charge(10)->serialize(); + } + + /** + * @expectedException GlobalPayments\Api\Entities\Exceptions\BuilderException + */ + public function testVerifyNoCurrency() + { + $service = $this->basicSetup(); + $service->verify()->serialize(); + } + + /** + * @expectedException GlobalPayments\Api\Entities\Exceptions\BuilderException + */ + public function testVerifyWithAmount() + { + $service = $this->basicSetup(); + $service->verify()->withAmount(10)->serialize(); + } + + /* 05. CardStorageCreatePayerStoreCardRequest */ + + public function testCardStorageCreatePayer() + { + $config = new GpEcomConfig(); + $config->merchantId = "heartlandgpsandbox"; + $config->accountId = "3dsecure"; + $config->refundPassword = "refund"; + $config->sharedSecret = "secret"; + $config->serviceUrl = "https://api.sandbox.realexpayments.com/epage-remote.cgi"; + $config->hostedPaymentConfig = new HostedPaymentConfig(); + $config->hostedPaymentConfig->language = "GB"; + $config->hostedPaymentConfig->responseUrl = "http://requestb.in/10q2bjb1"; + + $client = new RealexHppClient("secret"); + + // data to be passed to the HPP along with transaction level settings + $hostedPaymentData = new HostedPaymentData(); + $hostedPaymentData->offerToSaveCard = "1"; // display the save card tick box + $hostedPaymentData->customerExists = "0"; // new customer + //run test cases for different version + foreach ($this->hppVersionList as $hppVersion) { + $config->hostedPaymentConfig->version = $hppVersion; + $service = new HostedService($config); + + $json = $service->charge(15) + ->withCurrency("EUR") + ->withHostedPaymentData($hostedPaymentData) + ->serialize(); + + $this->assertNotNull($json); + + $response = $client->sendRequest($json, $hppVersion); + $this->assertNotNull($response); + + $parsedResponse = $service->parseResponse($response); + $this->assertNotNull($parsedResponse); + $this->assertEquals("00", $parsedResponse->responseCode); + } + } + + /* 07. CardStorageDisplayStoredCardsRequest */ + + public function testCardStorageDisplayStoredCard() + { + $config = new GpEcomConfig(); + $config->merchantId = "heartlandgpsandbox"; + $config->accountId = "3dsecure"; + $config->refundPassword = "refund"; + $config->sharedSecret = "secret"; + $config->serviceUrl = "https://api.sandbox.realexpayments.com/epage-remote.cgi"; + $config->hostedPaymentConfig = new HostedPaymentConfig(); + $config->hostedPaymentConfig->language = "GB"; + $config->hostedPaymentConfig->responseUrl = "http://requestb.in/10q2bjb1"; + + $client = new RealexHppClient("secret"); + + // data to be passed to the HPP along with transaction level settings + $hostedPaymentData = new HostedPaymentData(); + $hostedPaymentData->offerToSaveCard = "1"; + $hostedPaymentData->customerExists = "1"; + $hostedPaymentData->customerKey = "5e7e9152-2d53-466d-91bc-6d12ebc56b79"; + + //run test cases for different version + foreach ($this->hppVersionList as $hppVersion) { + $config->hostedPaymentConfig->version = $hppVersion; + $service = new HostedService($config); + + $json = $service->charge(15) + ->withCurrency("EUR") + ->withHostedPaymentData($hostedPaymentData) + ->serialize(); + + $this->assertNotNull($json); + + $response = $client->sendRequest($json, $hppVersion); + $this->assertNotNull($response); + + $parsedResponse = $service->parseResponse($response); + $this->assertNotNull($parsedResponse); + $this->assertEquals("00", $parsedResponse->responseCode); + } + } + + /* 09. ContinuousAuthorityRequest */ + + public function testContinuousAuthorityRequest() + { + $config = new GpEcomConfig(); + $config->merchantId = "heartlandgpsandbox"; + $config->accountId = "3dsecure"; + $config->refundPassword = "refund"; + $config->sharedSecret = "secret"; + $config->serviceUrl = "https://api.sandbox.realexpayments.com/epage-remote.cgi"; + $config->hostedPaymentConfig = new HostedPaymentConfig(); + $config->hostedPaymentConfig->language = "GB"; + $config->hostedPaymentConfig->responseUrl = "http://requestb.in/10q2bjb1"; + + $client = new RealexHppClient("secret"); + + //run test cases for different version + foreach ($this->hppVersionList as $hppVersion) { + $config->hostedPaymentConfig->version = $hppVersion; + $service = new HostedService($config); + + $json = $service->charge(15) + ->withCurrency("EUR") + ->withRecurringInfo(RecurringType::FIXED, RecurringSequence::FIRST) + ->serialize(); + + $this->assertNotNull($json); + + $response = $client->sendRequest($json, $hppVersion); + $this->assertNotNull($response); + + $parsedResponse = $service->parseResponse($response); + $this->assertNotNull($parsedResponse); + $this->assertEquals("00", $parsedResponse->responseCode); + } + } + + /* 13. DynamicCurrencyConversionRequest */ + + public function testEnableDynamicCurrencyConversionRequest() + { + //set config for DCC + $config = new GpEcomConfig(); + $config->merchantId = "MerchantId"; + $config->accountId = "internet"; + $config->refundPassword = "refund"; + $config->sharedSecret = "secret"; + $config->serviceUrl = "https://api.sandbox.realexpayments.com/epage-remote.cgi"; + + $config->hostedPaymentConfig = new HostedPaymentConfig(); + $config->hostedPaymentConfig->language = "GB"; + $config->hostedPaymentConfig->responseUrl = "http://requestb.in/10q2bjb1"; + $config->hostedPaymentConfig->version = HppVersion::VERSION_2; + $config->hostedPaymentConfig->directCurrencyConversionEnabled = "1"; + + $service = new HostedService($config); + $client = new RealexHppClient("secret"); + + //serialize the request + $json = $service->Charge(19) + ->withCurrency("EUR") + ->withTimestamp("20170725154824") + ->withOrderId('GTI5Yxb0SumL_TkDMCAxQA') + ->serialize(); + + $this->assertNotNull($json); + $this->assertEquals($json, '{"MERCHANT_ID":"MerchantId","ACCOUNT":"internet","ORDER_ID":"GTI5Yxb0SumL_TkDMCAxQA","AMOUNT":"1900","CURRENCY":"EUR","TIMESTAMP":"20170725154824","AUTO_SETTLE_FLAG":"1","DCC_ENABLE":"1","HPP_LANG":"GB","MERCHANT_RESPONSE_URL":"http:\/\/requestb.in\/10q2bjb1","HPP_VERSION":"2","SHA1HASH":"448d742db89b05ce97152beb55157c904f3839cc"}'); + } + + public function testDisableDynamicCurrencyConversionRequest() + { + //set config for DCC + $config = new GpEcomConfig(); + $config->merchantId = "MerchantId"; + $config->accountId = "internet"; + $config->refundPassword = "refund"; + $config->sharedSecret = "secret"; + $config->serviceUrl = "https://api.sandbox.realexpayments.com/epage-remote.cgi"; + + $config->hostedPaymentConfig = new HostedPaymentConfig(); + $config->hostedPaymentConfig->language = "GB"; + $config->hostedPaymentConfig->responseUrl = "http://requestb.in/10q2bjb1"; + $config->hostedPaymentConfig->version = HppVersion::VERSION_2; + $config->hostedPaymentConfig->directCurrencyConversionEnabled = "0"; + + $service = new HostedService($config); + $client = new RealexHppClient("secret"); + + //serialize the request + $json = $service->Charge(19) + ->withCurrency("EUR") + ->withTimestamp("20170725154824") + ->withOrderId('GTI5Yxb0SumL_TkDMCAxQA') + ->serialize(); + + $this->assertNotNull($json); + $this->assertEquals($json, '{"MERCHANT_ID":"MerchantId","ACCOUNT":"internet","ORDER_ID":"GTI5Yxb0SumL_TkDMCAxQA","AMOUNT":"1900","CURRENCY":"EUR","TIMESTAMP":"20170725154824","AUTO_SETTLE_FLAG":"1","DCC_ENABLE":"0","HPP_LANG":"GB","MERCHANT_RESPONSE_URL":"http:\/\/requestb.in\/10q2bjb1","HPP_VERSION":"2","SHA1HASH":"448d742db89b05ce97152beb55157c904f3839cc"}'); + } + + /* 11. FraudManagementRequest */ + + public function testFraudManagementRequest() + { + $config = new GpEcomConfig(); + $config->merchantId = "heartlandgpsandbox"; + $config->accountId = "3dsecure"; + $config->refundPassword = "refund"; + $config->sharedSecret = "secret"; + $config->serviceUrl = "https://api.sandbox.realexpayments.com/epage-remote.cgi"; + $config->hostedPaymentConfig = new HostedPaymentConfig(); + $config->hostedPaymentConfig->language = "GB"; + $config->hostedPaymentConfig->responseUrl = "http://requestb.in/10q2bjb1"; + $config->hostedPaymentConfig->version = 2; + $config->hostedPaymentConfig->FraudFilterMode = FraudFilterMode::PASSIVE; + + $service = new HostedService($config); + $client = new RealexHppClient("secret"); + + // billing address + $billingAddress = new Address(); + $billingAddress->postalCode = "50001|Flat 123"; + $billingAddress->country = "US"; + + // shipping address + $shippingAddress = new Address(); + $shippingAddress->postalCode = "654|123"; + $shippingAddress->country = "GB"; + + // data to be passed to the HPP along with transaction level settings + $hostedPaymentData = new HostedPaymentData(); + $hostedPaymentData->customerNumber = "E8953893489"; // display the save card tick box + $hostedPaymentData->productId = "SID9838383"; // new customer + + //serialize the request + $json = $service->charge(19) + ->withCurrency("EUR") + ->withAddress($billingAddress, AddressType::BILLING) + ->withAddress($shippingAddress, AddressType::SHIPPING) + //->withProductId("SID9838383") // prodid + ->withClientTransactionId("Car Part HV") // varref + //->withCustomerId("E8953893489") // custnum + ->withCustomerIpAddress("123.123.123.123") + //->withFraudFilter(FraudFilterMode::PASSIVE) + ->withHostedPaymentData($hostedPaymentData) + ->serialize(); + + $this->assertNotNull($json); + + //make API call + $response = $client->sendRequest($json, $config->hostedPaymentConfig->version); + $this->assertNotNull($response); + + $parsedResponse = $service->parseResponse($response); + $this->assertNotNull($parsedResponse); + $this->assertEquals("00", $parsedResponse->responseCode); + } + + /* Serialize methods Test case */ + + public function testBasicAuthHppVersion1() + { + $config = new GpEcomConfig(); + $config->merchantId = "MerchantId"; + $config->accountId = "internet"; + $config->refundPassword = "refund"; + $config->sharedSecret = "secret"; + $config->serviceUrl = "https://pay.sandbox.realexpayments.com/pay"; + $config->hostedPaymentConfig = new HostedPaymentConfig(); + $config->hostedPaymentConfig->language = "GB"; + $config->hostedPaymentConfig->responseUrl = "https://www.example.com/response"; + $config->hostedPaymentConfig->version = HppVersion::VERSION_1; + + $service = new HostedService($config); + $client = new RealexHppClient("secret"); + + $json = $service->authorize(19.99) + ->withCurrency("EUR") + ->withTimeStamp("20170725154824") + ->WithOrderId("GTI5Yxb0SumL_TkDMCAxQA") + ->serialize(); + + $expectedJson = '{"MERCHANT_ID":"TWVyY2hhbnRJZA==","ACCOUNT":"aW50ZXJuZXQ=","ORDER_ID":"R1RJNVl4YjBTdW1MX1RrRE1DQXhRQQ==","AMOUNT":"MTk5OQ==","CURRENCY":"RVVS","TIMESTAMP":"MjAxNzA3MjUxNTQ4MjQ=","AUTO_SETTLE_FLAG":"MA==","HPP_LANG":"R0I=","MERCHANT_RESPONSE_URL":"aHR0cHM6Ly93d3cuZXhhbXBsZS5jb20vcmVzcG9uc2U=","HPP_VERSION":"MQ==","SHA1HASH":"MDYxNjA5Zjg1YThlMDE5MWRjN2Y0ODdmODI3OGU3MTg5OGEyZWUyZA=="}'; + $this->assertEquals($json, $expectedJson); + } + + public function testBasicAuthHppVersion2() + { + $config = new GpEcomConfig(); + $config->merchantId = "MerchantId"; + $config->accountId = "internet"; + $config->refundPassword = "refund"; + $config->sharedSecret = "secret"; + $config->serviceUrl = "https://pay.sandbox.realexpayments.com/pay"; + $config->hostedPaymentConfig = new HostedPaymentConfig(); + $config->hostedPaymentConfig->language = "GB"; + $config->hostedPaymentConfig->responseUrl = "https://www.example.com/response"; + $config->hostedPaymentConfig->version = HppVersion::VERSION_2; + + $service = new HostedService($config); + $client = new RealexHppClient("secret"); + + $json = $service->authorize(19.99) + ->withCurrency("EUR") + ->withTimeStamp("20170725154824") + ->WithOrderId("GTI5Yxb0SumL_TkDMCAxQA") + ->serialize(); + + $expectedJson = '{"MERCHANT_ID":"MerchantId","ACCOUNT":"internet","ORDER_ID":"GTI5Yxb0SumL_TkDMCAxQA","AMOUNT":"1999","CURRENCY":"EUR","TIMESTAMP":"20170725154824","AUTO_SETTLE_FLAG":"0","HPP_LANG":"GB","MERCHANT_RESPONSE_URL":"https:\/\/www.example.com\/response","HPP_VERSION":"2","SHA1HASH":"061609f85a8e0191dc7f487f8278e71898a2ee2d"}'; + $this->assertEquals($json, $expectedJson); + } + + public function testBasicSale() + { + $config = new GpEcomConfig(); + $config->merchantId = "MerchantId"; + $config->accountId = "internet"; + $config->refundPassword = "refund"; + $config->sharedSecret = "secret"; + $config->serviceUrl = "https://pay.sandbox.realexpayments.com/pay"; + $config->hostedPaymentConfig = new HostedPaymentConfig(); + $config->hostedPaymentConfig->language = "GB"; + $config->hostedPaymentConfig->responseUrl = "https://www.example.com/response"; + $config->hostedPaymentConfig->version = HppVersion::VERSION_2; + + $service = new HostedService($config); + $client = new RealexHppClient("secret"); + + $json = $service->charge(19.99) + ->withCurrency("EUR") + ->withTimeStamp("20170725154824") + ->WithOrderId("GTI5Yxb0SumL_TkDMCAxQA") + ->serialize(); + + $expectedJson = '{"MERCHANT_ID":"MerchantId","ACCOUNT":"internet","ORDER_ID":"GTI5Yxb0SumL_TkDMCAxQA","AMOUNT":"1999","CURRENCY":"EUR","TIMESTAMP":"20170725154824","AUTO_SETTLE_FLAG":"1","HPP_LANG":"GB","MERCHANT_RESPONSE_URL":"https:\/\/www.example.com\/response","HPP_VERSION":"2","SHA1HASH":"061609f85a8e0191dc7f487f8278e71898a2ee2d"}'; + $this->assertEquals($json, $expectedJson); + } + + public function testBasicHostedPaymentDataHppVersion1() + { + $config = new GpEcomConfig(); + $config->merchantId = "MerchantId"; + $config->accountId = "internet"; + $config->refundPassword = "refund"; + $config->sharedSecret = "secret"; + $config->serviceUrl = "https://pay.sandbox.realexpayments.com/pay"; + $config->hostedPaymentConfig = new HostedPaymentConfig(); + $config->hostedPaymentConfig->language = "GB"; + $config->hostedPaymentConfig->responseUrl = "https://www.example.com/response"; + $config->hostedPaymentConfig->version = HppVersion::VERSION_1; + + $service = new HostedService($config); + $client = new RealexHppClient("secret"); + + $hostedPaymentData = new HostedPaymentData(); + $hostedPaymentData->offerToSaveCard = "1"; // display the save card tick box + $hostedPaymentData->customerExists = "0"; // new customer + $hostedPaymentData->customerNumber = 'a028774f-beff-47bc-bd6e-ed7e04f5d758a028774f-btefa'; + $hostedPaymentData->productId = 'a0b38df5-b23c-4d82-88fe-2e9c47438972-b23c-4d82-88f'; + + $json = $service->charge(19.99) + ->withCurrency("EUR") + ->withTimeStamp("20170725154824") + ->WithOrderId("GTI5Yxb0SumL_TkDMCAxQA") + ->WithHostedPaymentData($hostedPaymentData) + ->WithDescription("Mobile Channel") + ->WithClientTransactionId("My Legal Entity") + ->serialize(); + + $expectedJson = '{"MERCHANT_ID":"TWVyY2hhbnRJZA==","ACCOUNT":"aW50ZXJuZXQ=","ORDER_ID":"R1RJNVl4YjBTdW1MX1RrRE1DQXhRQQ==","AMOUNT":"MTk5OQ==","CURRENCY":"RVVS","TIMESTAMP":"MjAxNzA3MjUxNTQ4MjQ=","AUTO_SETTLE_FLAG":"MQ==","COMMENT1":"TW9iaWxlIENoYW5uZWw=","CUST_NUM":"YTAyODc3NGYtYmVmZi00N2JjLWJkNmUtZWQ3ZTA0ZjVkNzU4YTAyODc3NGYtYnRlZmE=","OFFER_SAVE_CARD":"MQ==","PAYER_EXIST":"MA==","PROD_ID":"YTBiMzhkZjUtYjIzYy00ZDgyLTg4ZmUtMmU5YzQ3NDM4OTcyLWIyM2MtNGQ4Mi04OGY=","VAR_REF":"TXkgTGVnYWwgRW50aXR5","HPP_LANG":"R0I=","MERCHANT_RESPONSE_URL":"aHR0cHM6Ly93d3cuZXhhbXBsZS5jb20vcmVzcG9uc2U=","HPP_VERSION":"MQ==","SHA1HASH":"NzExNmM0OTgyNjM2N2M2NTEzZWZkYzBjYzgxZTI0M2I4MDk1ZDc4Zg=="}'; + $this->assertEquals($json, $expectedJson); + } + + public function testBasicHostedPaymentDataHppVersion2() + { + $config = new GpEcomConfig(); + $config->merchantId = "MerchantId"; + $config->accountId = "internet"; + $config->refundPassword = "refund"; + $config->sharedSecret = "secret"; + $config->serviceUrl = "https://pay.sandbox.realexpayments.com/pay"; + $config->hostedPaymentConfig = new HostedPaymentConfig(); + $config->hostedPaymentConfig->language = "GB"; + $config->hostedPaymentConfig->responseUrl = "https://www.example.com/response"; + $config->hostedPaymentConfig->version = HppVersion::VERSION_2; + + $service = new HostedService($config); + $client = new RealexHppClient("secret"); + + $hostedPaymentData = new HostedPaymentData(); + $hostedPaymentData->offerToSaveCard = "1"; // display the save card tick box + $hostedPaymentData->customerExists = "0"; // new customer + $hostedPaymentData->customerNumber = 'a028774f-beff-47bc-bd6e-ed7e04f5d758a028774f-btefa'; + $hostedPaymentData->productId = 'a0b38df5-b23c-4d82-88fe-2e9c47438972-b23c-4d82-88f'; + + $json = $service->charge(19.99) + ->withCurrency("EUR") + ->withTimeStamp("20170725154824") + ->WithOrderId("GTI5Yxb0SumL_TkDMCAxQA") + ->WithHostedPaymentData($hostedPaymentData) + ->WithDescription("Mobile Channel") + ->WithClientTransactionId("My Legal Entity") + ->serialize(); + + $expectedJson = '{"MERCHANT_ID":"MerchantId","ACCOUNT":"internet","ORDER_ID":"GTI5Yxb0SumL_TkDMCAxQA","AMOUNT":"1999","CURRENCY":"EUR","TIMESTAMP":"20170725154824","AUTO_SETTLE_FLAG":"1","COMMENT1":"Mobile Channel","CUST_NUM":"a028774f-beff-47bc-bd6e-ed7e04f5d758a028774f-btefa","OFFER_SAVE_CARD":"1","PAYER_EXIST":"0","PROD_ID":"a0b38df5-b23c-4d82-88fe-2e9c47438972-b23c-4d82-88f","VAR_REF":"My Legal Entity","HPP_LANG":"GB","MERCHANT_RESPONSE_URL":"https:\/\/www.example.com\/response","HPP_VERSION":"2","SHA1HASH":"7116c49826367c6513efdc0cc81e243b8095d78f"}'; + $this->assertEquals($json, $expectedJson); + } + + public function testParseResponse() + { + $config = new GpEcomConfig(); + $config->merchantId = "heartlandgpsandbox"; + $config->accountId = "hpp"; + $config->sharedSecret = "secret"; + $config->serviceUrl = "https://api.sandbox.realexpayments.com/epage-remote.cgi"; + $config->hostedPaymentConfig = new HostedPaymentConfig(); + $config->hostedPaymentConfig->language = "GB"; + $config->hostedPaymentConfig->responseUrl = "http://requestb.in/10q2bjb1"; + + $client = new RealexHppClient("secret"); + + $address = new Address(); + $address->postalCode = "123|56"; + $address->country = "IRELAND"; + + //run test cases for different version + foreach ($this->hppVersionList as $hppVersion) { + $config->hostedPaymentConfig->version = $hppVersion; + $service = new HostedService($config); + + $json = $service->authorize(1) + ->withCurrency("EUR") + ->withCustomerId("123456") + ->withAddress($address) + ->serialize(); + + $this->assertNotNull($json); + + $response = $client->sendRequest($json, $hppVersion); + $this->assertNotNull($response); + + // Base64 encode values + $iterator = new \RecursiveIteratorIterator(new \RecursiveArrayIterator(json_decode($response, true))); + foreach ($iterator as $key => $value) { + $iterator->getInnerIterator()->offsetSet($key, base64_encode($value)); + } + + $response = json_encode($iterator->getArrayCopy()); + + $parsedResponse = $service->parseResponse($response, true); + $this->assertEquals("00", $parsedResponse->responseCode); + } + } + + public function testHostedPaymentDataSupplementaryDataSerialize() + { + $config = new GpEcomConfig(); + $config->merchantId = "MerchantId"; + $config->accountId = "internet"; + $config->refundPassword = "refund"; + $config->sharedSecret = "secret"; + $config->serviceUrl = "https://pay.sandbox.realexpayments.com/pay"; + $config->hostedPaymentConfig = new HostedPaymentConfig(); + $config->hostedPaymentConfig->language = "GB"; + $config->hostedPaymentConfig->responseUrl = "https://www.example.com/response"; + $config->hostedPaymentConfig->version = HppVersion::VERSION_2; + $config->gatewayProvider = GatewayProvider::GP_ECOM; + + $service = new HostedService($config); + + $hostedPaymentData = new HostedPaymentData(); + $hostedPaymentData->offerToSaveCard = "1"; // display the save card tick box + $hostedPaymentData->customerExists = "0"; // new customer + $hostedPaymentData->customerNumber = 'a028774f-beff-47bc-bd6e-ed7e04f5d758a028774f-btefa'; + $hostedPaymentData->productId = 'a0b38df5-b23c-4d82-88fe-2e9c47438972-b23c-4d82-88f'; + $hostedPaymentData->supplementaryData = ['HPP_FRAUDFILTER_MODE' => 'ACTIVE']; + + $json = $service->charge(19.99) + ->withCurrency("EUR") + ->withTimeStamp("20170725154824") + ->withOrderId("GTI5Yxb0SumL_TkDMCAxQA") + ->withHostedPaymentData($hostedPaymentData) + ->withDescription("Mobile Channel") + ->withClientTransactionId("My Legal Entity") + ->serialize(); + + $expectedJson = '{"MERCHANT_ID":"MerchantId","ACCOUNT":"internet","ORDER_ID":"GTI5Yxb0SumL_TkDMCAxQA","AMOUNT":"1999","CURRENCY":"EUR","TIMESTAMP":"20170725154824","AUTO_SETTLE_FLAG":"1","COMMENT1":"Mobile Channel","CUST_NUM":"a028774f-beff-47bc-bd6e-ed7e04f5d758a028774f-btefa","OFFER_SAVE_CARD":"1","PAYER_EXIST":"0","PROD_ID":"a0b38df5-b23c-4d82-88fe-2e9c47438972-b23c-4d82-88f","VAR_REF":"My Legal Entity","HPP_LANG":"GB","MERCHANT_RESPONSE_URL":"https:\/\/www.example.com\/response","HPP_FRAUDFILTER_MODE":"ACTIVE","HPP_VERSION":"2","SHA1HASH":"7116c49826367c6513efdc0cc81e243b8095d78f"}'; + $this->assertEquals($json, $expectedJson); + } + + public function testSupplementaryDataWithOneValueSerialized() { + $config = new GpEcomConfig(); + $config->merchantId = "MerchantId"; + $config->accountId = "internet"; + $config->refundPassword = "refund"; + $config->sharedSecret = "secret"; + $config->serviceUrl = "https://pay.sandbox.realexpayments.com/pay"; + $config->hostedPaymentConfig = new HostedPaymentConfig(); + $config->hostedPaymentConfig->language = "GB"; + $config->hostedPaymentConfig->responseUrl = "https://www.example.com/response"; + $config->hostedPaymentConfig->version = HppVersion::VERSION_2; + $config->gatewayProvider = GatewayProvider::GP_ECOM; + + $service = new HostedService($config); + + $hostedPaymentData = new HostedPaymentData(); + $hostedPaymentData->offerToSaveCard = "1"; // display the save card tick box + $hostedPaymentData->customerExists = "0"; // new customer + $hostedPaymentData->customerNumber = 'a028774f-beff-47bc-bd6e-ed7e04f5d758a028774f-btefa'; + $hostedPaymentData->productId = 'a0b38df5-b23c-4d82-88fe-2e9c47438972-b23c-4d82-88f'; + + $json = $service->charge(19.99) + ->withCurrency("EUR") + ->withTimeStamp("20170725154824") + ->withOrderId("GTI5Yxb0SumL_TkDMCAxQA") + ->withHostedPaymentData($hostedPaymentData) + ->withDescription("Mobile Channel") + ->withClientTransactionId("My Legal Entity") + ->withSupplementaryData('HPP_FRAUDFILTER_MODE', 'ACTIVE') + ->serialize(); + + $expectedJson = '{"MERCHANT_ID":"MerchantId","ACCOUNT":"internet","ORDER_ID":"GTI5Yxb0SumL_TkDMCAxQA","AMOUNT":"1999","CURRENCY":"EUR","TIMESTAMP":"20170725154824","AUTO_SETTLE_FLAG":"1","COMMENT1":"Mobile Channel","CUST_NUM":"a028774f-beff-47bc-bd6e-ed7e04f5d758a028774f-btefa","OFFER_SAVE_CARD":"1","PAYER_EXIST":"0","PROD_ID":"a0b38df5-b23c-4d82-88fe-2e9c47438972-b23c-4d82-88f","VAR_REF":"My Legal Entity","HPP_LANG":"GB","MERCHANT_RESPONSE_URL":"https:\/\/www.example.com\/response","HPP_VERSION":"2","HPP_FRAUDFILTER_MODE":"ACTIVE","SHA1HASH":"7116c49826367c6513efdc0cc81e243b8095d78f"}'; + $this->assertEquals($json, $expectedJson); + } + + public function testSupplementaryDataWithTwoValuesSerialized() + { + $config = new GpEcomConfig(); + $config->merchantId = "MerchantId"; + $config->accountId = "internet"; + $config->refundPassword = "refund"; + $config->sharedSecret = "secret"; + $config->serviceUrl = "https://pay.sandbox.realexpayments.com/pay"; + $config->hostedPaymentConfig = new HostedPaymentConfig(); + $config->hostedPaymentConfig->language = "GB"; + $config->hostedPaymentConfig->responseUrl = "https://www.example.com/response"; + $config->hostedPaymentConfig->version = HppVersion::VERSION_2; + $config->gatewayProvider = GatewayProvider::GP_ECOM; + + $service = new HostedService($config); + + $hostedPaymentData = new HostedPaymentData(); + $hostedPaymentData->offerToSaveCard = "1"; // display the save card tick box + $hostedPaymentData->customerExists = "0"; // new customer + $hostedPaymentData->customerNumber = 'a028774f-beff-47bc-bd6e-ed7e04f5d758a028774f-btefa'; + $hostedPaymentData->productId = 'a0b38df5-b23c-4d82-88fe-2e9c47438972-b23c-4d82-88f'; + + $json = $service->charge(19.99) + ->withCurrency("EUR") + ->withTimeStamp("20170725154824") + ->withOrderId("GTI5Yxb0SumL_TkDMCAxQA") + ->withHostedPaymentData($hostedPaymentData) + ->withDescription("Mobile Channel") + ->withClientTransactionId("My Legal Entity") + ->withSupplementaryData(["RANDOM_KEY1" => "VALUE_1", "RANDOM_KEY2" => "VALUE_2"]) + ->serialize(); + + $expectedJson = '{"MERCHANT_ID":"MerchantId","ACCOUNT":"internet","ORDER_ID":"GTI5Yxb0SumL_TkDMCAxQA","AMOUNT":"1999","CURRENCY":"EUR","TIMESTAMP":"20170725154824","AUTO_SETTLE_FLAG":"1","COMMENT1":"Mobile Channel","CUST_NUM":"a028774f-beff-47bc-bd6e-ed7e04f5d758a028774f-btefa","OFFER_SAVE_CARD":"1","PAYER_EXIST":"0","PROD_ID":"a0b38df5-b23c-4d82-88fe-2e9c47438972-b23c-4d82-88f","VAR_REF":"My Legal Entity","HPP_LANG":"GB","MERCHANT_RESPONSE_URL":"https:\/\/www.example.com\/response","HPP_VERSION":"2","RANDOM_KEY1":"VALUE_1","RANDOM_KEY2":"VALUE_2","SHA1HASH":"7116c49826367c6513efdc0cc81e243b8095d78f"}'; + $this->assertEquals($json, $expectedJson); + } +} diff --git a/test/Integration/Gateways/RealexConnector/HppTestCase.php b/test/Integration/Gateways/RealexConnector/HppTestCase.php index 9d000d8d..5c088e9c 100644 --- a/test/Integration/Gateways/RealexConnector/HppTestCase.php +++ b/test/Integration/Gateways/RealexConnector/HppTestCase.php @@ -1,241 +1,241 @@ -merchantId = "heartlandgpsandbox"; - $config->accountId = "hpp"; - $config->sharedSecret = "secret"; - $config->serviceUrl = "https://api.sandbox.realexpayments.com/epage-remote.cgi"; - - $config->hostedPaymentConfig = new HostedPaymentConfig(); - $config->hostedPaymentConfig->language = "GB"; - $config->hostedPaymentConfig->responseUrl = "http://requestb.in/10q2bjb1"; - return $config; - } - - public function setup() - { - $this->service = new HostedService($this->config()); - } - - /* 10. ThreedSecureResponse */ - - public function testThreedSecureResponse() - { - $config = new GpEcomConfig(); - $config->merchantId = 'heartlandgpsandbox'; - $config->accountId = 'hpp'; - $config->sharedSecret = 'secret'; - $config->serviceUrl = 'https://pay.sandbox.realexpayments.com/pay'; - - $service = new HostedService( - $config - ); - - //response - // TODO: grab the response JSON from the client-side for example: - $responseJson = '{"MERCHANT_ID":"heartlandgpsandbox","ACCOUNT":"hpp","ORDER_ID":"OTA4NUEzOEEtMkE3RjU2RQ","TIMESTAMP":"20180724124150","RESULT":"00","PASREF":"15324325098818233","AUTHCODE":"12345","AVSPOSTCODERESULT":"U","CVNRESULT":"U","HPP_LANG":"GB","SHIPPING_CODE":null,"SHIPPING_CO":null,"BILLING_CODE":"123|56","BILLING_CO":"IRELAND","ECI":null,"CAVV":null,"XID":null,"MERCHANT_RESPONSE_URL":"http:\/\/requestb.in\/10q2bjb1","CARD_PAYMENT_BUTTON":null,"MESSAGE":"[ test system ] Authorised","AMOUNT":null,"SHA1HASH":"d1ff806b449b86375dbda74e2611760c348fcdeb","DCC_INFO_REQUST":null,"DCC_INFO_RESPONSE":null,"HPP_FRAUD_FILTER_MODE":null,"TSS_INFO":null}'; - - $parsedResponse = $service->parseResponse($responseJson); - $responseCode = $parsedResponse->responseCode; // 00 - $responseMessage = $parsedResponse->responseMessage; // [ test system ] Authorised - $responseValues = $parsedResponse->responseValues; // get values accessible by key - - $eci = $responseValues["ECI"]; // 5 - fully authenticated - $cavv = $responseValues["CAVV"]; // AAACBUGDZYYYIgGFGYNlAAAAAAA= - $xid = $responseValues["XID"]; // vJ9NXpFueXsAqeb4iAbJJbe+66s= - // TODO: update your application and display transaction outcome to the customer - - $this->assertNotEquals(null, $parsedResponse); - $this->assertEquals("00", $responseCode); - } - - /* 02. ProcessPaymentConsumeHppResponse */ - - public function testprocessPaymentConsumeResponse() - { - $config = new GpEcomConfig(); - $config->merchantId = 'heartlandgpsandbox'; - $config->accountId = 'hpp'; - $config->sharedSecret = 'secret'; - $config->serviceUrl = 'https://pay.sandbox.realexpayments.com/pay'; - - $service = new HostedService($config); - - $responseJson = '{"MERCHANT_ID":"heartlandgpsandbox","ACCOUNT":"hpp","ORDER_ID":"NjMwNkMxMTAtMTA5RUNDRQ","TIMESTAMP":"20180720104340","RESULT":"00","PASREF":"15320798200414985","AUTHCODE":"12345","AVSPOSTCODERESULT":"U","CVNRESULT":"U","HPP_LANG":"GB","SHIPPING_CODE":null,"SHIPPING_CO":null,"BILLING_CODE":"123|56","BILLING_CO":"IRELAND","ECI":null,"CAVV":null,"XID":null,"MERCHANT_RESPONSE_URL":"http:\/\/requestb.in\/10q2bjb1","CARD_PAYMENT_BUTTON":null,"MESSAGE":"[ test system ] Authorised","AMOUNT":"100","SHA1HASH":"32628cf3f887ab9f4f1c547a10ac365c2168f0e2","DCC_INFO":null,"HPP_FRAUD_FILTER_MODE":null,"TSS_INFO":null}'; - - // create the response object from the response JSON - $parsedResponse = $service->parseResponse($responseJson); - - $orderId = $parsedResponse->orderId; // GTI5Yxb0SumL_TkDMCAxQA - $responseCode = $parsedResponse->responseCode; // 00 - $responseMessage = $parsedResponse->responseMessage; // [ test system ] Authorised - $responseValues = $parsedResponse->responseValues; // get values accessible by key - //$fraudFilterResult = $responseValues["HPP_FRAUDFILTER_RESULT"]; // PASS - - $this->assertNotEquals(null, $parsedResponse); - $this->assertEquals("00", $responseCode); - } - - /* 06. CardStorageCreatePayerStoreCardResponse */ - - public function testCardStorageCreatePayerStoreCardResponse() - { - $config = new GpEcomConfig(); - $config->merchantId = 'heartlandgpsandbox'; - $config->accountId = 'hpp'; - $config->sharedSecret = 'secret'; - $config->serviceUrl = 'https://pay.sandbox.realexpayments.com/pay'; - - $service = new HostedService( - $config - ); - - // TODO: grab the response JSON from the client-side for example: - //sample response JSON: - $responseJson = '{"MERCHANT_ID":"heartlandgpsandbox","ACCOUNT":"3dsecure","ORDER_ID":"NTgxMkMzODUtNTEwMkNCMw","TIMESTAMP":"20180723110112","RESULT":"00","PASREF":"15323400720177562","AUTHCODE":"12345","AVSPOSTCODERESULT":"U","CVNRESULT":"U","HPP_LANG":"GB","SHIPPING_CODE":null,"SHIPPING_CO":null,"BILLING_CODE":null,"BILLING_CO":null,"ECI":null,"CAVV":null,"XID":null,"MERCHANT_RESPONSE_URL":"http:\/\/requestb.in\/10q2bjb1","CARD_PAYMENT_BUTTON":null,"MESSAGE":"[ test system ] Authorised","AMOUNT":"1500","SHA1HASH":"4c7a635401c57371a0931bb3a21a849181cc963d","DCC_INFO":null,"HPP_FRAUD_FILTER_MODE":null,"TSS_INFO":null}'; - - $parsedResponse = $service->parseResponse($responseJson); - $responseCode = $parsedResponse->responseCode; // 00 - $responseMessage = $parsedResponse->responseMessage; // [ test system ] Authorised - $responseValues = $parsedResponse->responseValues; // get values accessible by key - /* - // Payer Setup Details - $payerSetupResult = $responseValues["PAYER_SETUP"]; // 00 - $payerSetupMessage = $responseValues["PAYER_SETUP_MSG"]; // Successful - $payerReference = $responseValues["SAVED_PAYER_REF"]; // 5e7e9152-2d53-466d-91bc-6d12ebc56b79 - // Card Setup Details - $cardSetupResult = $responseValues["PMT_SETUP"]; // 00 - $cardSetupMessage = $responseValues["PMT_SETUP_MSG"]; // Successful - $cardReference = $responseValues["SAVED_PMT_REF"]; // ca68dcac-9af2-4d65-b06c-eb54667dcd4a - // Card Details Stored - $cardType = $responseValues["SAVED_PMT_TYPE"]; // MC - $cardDigits = $responseValues["SAVED_PMT_DIGITS"]; // 542523xxxx4415 - $cardExpiry = $responseValues["SAVED_PMT_EXPDATE"]; // 1025 - $cardName = $responseValues["SAVED_PMT_NAME"]; // James Mason - */ - // TODO: update your application and display transaction outcome to the customer - - $this->assertNotEquals(null, $parsedResponse); - $this->assertEquals("00", $responseCode); - } - - /* 08. CardStorageDisplayStoredCardsResponse */ - - public function testCardStorageDisplayStoredCardsResponse() - { - $config = new GpEcomConfig(); - $config->merchantId = 'heartlandgpsandbox'; - $config->accountId = 'hpp'; - $config->sharedSecret = 'secret'; - $config->serviceUrl = 'https://pay.sandbox.realexpayments.com/pay'; - - $service = new HostedService( - $config - ); - - // TODO: grab the response JSON from the client-side for example: - //sample response JSON: - $responseJson = array("MERCHANT_ID" => "MerchantId", "ACCOUNT" => "internet", "ORDER_ID" => "GTI5Yxb0SumL_TkDMCAxQA", "AMOUNT" => "1999", "TIMESTAMP" => "20170725154824", "SHA1HASH" => "843680654f377bfa845387fdbace35acc9d95778", "RESULT" => "00", "AUTHCODE" => "12345", "CARD_PAYMENT_BUTTON" => "Place Order", "AVSADDRESSRESULT" => "M", "AVSPOSTCODERESULT" => "M", "BATCHID" => "445196", "MESSAGE" => "[ test system ] Authorised", "PASREF" => "15011597872195765", "CVNRESULT" => "M", "HPP_FRAUDFILTER_RESULT" => "PASS", "HPP_CHOSEN_PMT_REF" => "099efeb4-eda2-4fd7-a04d-29647bb6c51d", "HPP_EDITED_PMT_REF" => "037bd26a-c76b-4ee4-8063-376d8858f23d", "HPP_DELETED_PMT_REF" => "3db4c72c-cd95-4743-8070-f17e2b56b642"); - - $parsedResponse = $service->parseResponse(json_encode($responseJson)); - $responseCode = $parsedResponse->responseCode; // 00 - $responseMessage = $parsedResponse->responseMessage; // [ test system ] Authorised - $responseValues = $parsedResponse->responseValues; // get values accessible by key - // card used to complete payment, edited or deleted - $chosenCard = $responseValues["HPP_CHOSEN_PMT_REF"]; // 099efeb4-eda2-4fd7-a04d-29647bb6c51d - $editedCard = $responseValues["HPP_EDITED_PMT_REF"]; // 037bd26a-c76b-4ee4-8063-376d8858f23d - $deletedCard = $responseValues["HPP_DELETED_PMT_REF"]; // 3db4c72c-cd95-4743-8070-f17e2b56b642 - // TODO: update your application and display transaction outcome to the customer - - $this->assertNotEquals(null, $parsedResponse); - $this->assertEquals("00", $responseCode); - } - - /* 12. FraudManagementResponse */ - - public function testFraudManagementResponse() - { - $config = new GpEcomConfig(); - $config->merchantId = 'heartlandgpsandbox'; - $config->accountId = 'hpp'; - $config->sharedSecret = 'secret'; - $config->serviceUrl = 'https://pay.sandbox.realexpayments.com/pay'; - - $service = new HostedService( - $config - ); - - // TODO: grab the response JSON from the client-side for example: - //sample response JSON: - $responseJson = array("MERCHANT_ID" => "MerchantId", "ACCOUNT" => "internet", "ORDER_ID" => "GTI5Yxb0SumL_TkDMCAxQA", "AMOUNT" => "1999", "TIMESTAMP" => "20170725154824", "SHA1HASH" => "843680654f377bfa845387fdbace35acc9d95778", "RESULT" => "00", "AUTHCODE" => "12345", "CARD_PAYMENT_BUTTON" => "Place Order", "AVSADDRESSRESULT" => "M", "AVSPOSTCODERESULT" => "M", "BATCHID" => "445196", "MESSAGE" => "[ test system ] Authorised", "PASREF" => "15011597872195765", "CVNRESULT" => "M", "HPP_FRAUDFILTER_RESULT" => "HOLD", "HPP_FRAUDFILTER_RULE_56257838-4590-4227-b946-11e061fb15fe" => "HOLD", "HPP_FRAUDFILTER_RULE_cf609cf9-9e5a-4700-ac69-8aa09c119305" => "PASS"); - ; - - $parsedResponse = $service->parseResponse(json_encode($responseJson)); - $responseCode = $parsedResponse->responseCode; // 00 - $responseValues = $parsedResponse->responseValues; // get values accessible by key - - $fraudFilterResult = $responseValues["HPP_FRAUDFILTER_RESULT"]; // HOLD - $cardRuleResult = $responseValues["HPP_FRAUDFILTER_RULE_56257838-4590-4227-b946-11e061fb15fe"]; // HOLD - $ipRuleResult = $responseValues["HPP_FRAUDFILTER_RULE_cf609cf9-9e5a-4700-ac69-8aa09c119305"]; // PASS - // TODO: update your application and display transaction outcome to the customer - - $this->assertNotEquals(null, $parsedResponse); - $this->assertEquals("00", $responseCode); - } - - /* 14. DynamicCurrencyConversionResponse */ - - public function testDynamicCurrencyConversionResponse() - { - $config = new GpEcomConfig(); - $config->merchantId = 'heartlandgpsandbox'; - $config->accountId = 'hpp'; - $config->sharedSecret = 'secret'; - $config->serviceUrl = 'https://pay.sandbox.realexpayments.com/pay'; - - $service = new HostedService( - $config - ); - - // TODO: grab the response JSON from the client-side for example: - //sample response JSON: - $responseJson = '{"MERCHANT_ID":"heartlandgpsandbox","ACCOUNT":"apidcc","ORDER_ID":"NTQyQzgxREMtMzVFQzlDNw","TIMESTAMP":"20180724095953","RESULT":"00","PASREF":"15324227932436743","AUTHCODE":"12345","AVSPOSTCODERESULT":"U","CVNRESULT":"U","HPP_LANG":"GB","SHIPPING_CODE":null,"SHIPPING_CO":null,"BILLING_CODE":null,"BILLING_CO":null,"ECI":null,"CAVV":null,"XID":null,"MERCHANT_RESPONSE_URL":"http:\/\/requestb.in\/10q2bjb1","CARD_PAYMENT_BUTTON":null,"MESSAGE":"[ test system ] Authorised","AMOUNT":"100100","SHA1HASH":"320c7ddc49d292f5900c676168d5cc1f2a55306c","DCC_INFO_REQUST":{"CCP":"Fexco","TYPE":1,"RATE":"1.7203","RATE_TYPE":"S","AMOUNT":"172202","CURRENCY":"AUD"},"DCC_INFO_RESPONSE":{"cardHolderCurrency":"AUD","cardHolderAmount":"172202","cardHolderRate":"1.7203","merchantCurrency":"EUR","merchantAmount":"100100","marginRatePercentage":"","exchangeRateSourceName":"","commissionPercentage":"","exchangeRateSourceTimestamp":""},"HPP_FRAUD_FILTER_MODE":null,"TSS_INFO":null}'; - $parsedResponse = $service->parseResponse($responseJson); - - $responseCode = $parsedResponse->responseCode; // 00 - $responseValues = $parsedResponse->responseValues; // get values accessible by key - - $conversionProcessor = $responseValues['DCC_INFO_REQUST']["CCP"]; // fexco - $conversionRate = $responseValues['DCC_INFO_REQUST']["RATE"]; // 1.7203 - $merchantAmount = $responseValues['DCC_INFO_RESPONSE']["merchantAmount"]; // 1999 - $cardholderAmount = $responseValues['DCC_INFO_RESPONSE']["cardHolderAmount"]; // 3439 - $merchantCurrency = $responseValues['DCC_INFO_RESPONSE']["merchantCurrency"]; // EUR - $cardholderCurrency = $responseValues['DCC_INFO_RESPONSE']["cardHolderCurrency"]; // AUD - $marginPercentage = $responseValues['DCC_INFO_RESPONSE']["marginRatePercentage"]; // 3.75 - $exchangeSource = $responseValues['DCC_INFO_RESPONSE']["exchangeRateSourceName"]; // REUTERS WHOLESALE INTERBANK - $commissionPercentage = $responseValues['DCC_INFO_RESPONSE']["commissionPercentage"]; // 0 - $exchangeTimestamp = $responseValues['DCC_INFO_RESPONSE']["exchangeRateSourceTimestamp"]; // 20170518162700 - // TODO: update your application and display transaction outcome to the customer - $this->assertNotEquals(null, $parsedResponse); - $this->assertEquals("00", $responseCode); - } -} +merchantId = "heartlandgpsandbox"; + $config->accountId = "hpp"; + $config->sharedSecret = "secret"; + $config->serviceUrl = "https://api.sandbox.realexpayments.com/epage-remote.cgi"; + + $config->hostedPaymentConfig = new HostedPaymentConfig(); + $config->hostedPaymentConfig->language = "GB"; + $config->hostedPaymentConfig->responseUrl = "http://requestb.in/10q2bjb1"; + return $config; + } + + public function setup() + { + $this->service = new HostedService($this->config()); + } + + /* 10. ThreedSecureResponse */ + + public function testThreedSecureResponse() + { + $config = new GpEcomConfig(); + $config->merchantId = 'heartlandgpsandbox'; + $config->accountId = 'hpp'; + $config->sharedSecret = 'secret'; + $config->serviceUrl = 'https://pay.sandbox.realexpayments.com/pay'; + + $service = new HostedService( + $config + ); + + //response + // TODO: grab the response JSON from the client-side for example: + $responseJson = '{"MERCHANT_ID":"heartlandgpsandbox","ACCOUNT":"hpp","ORDER_ID":"OTA4NUEzOEEtMkE3RjU2RQ","TIMESTAMP":"20180724124150","RESULT":"00","PASREF":"15324325098818233","AUTHCODE":"12345","AVSPOSTCODERESULT":"U","CVNRESULT":"U","HPP_LANG":"GB","SHIPPING_CODE":null,"SHIPPING_CO":null,"BILLING_CODE":"123|56","BILLING_CO":"IRELAND","ECI":null,"CAVV":null,"XID":null,"MERCHANT_RESPONSE_URL":"http:\/\/requestb.in\/10q2bjb1","CARD_PAYMENT_BUTTON":null,"MESSAGE":"[ test system ] Authorised","AMOUNT":null,"SHA1HASH":"d1ff806b449b86375dbda74e2611760c348fcdeb","DCC_INFO_REQUST":null,"DCC_INFO_RESPONSE":null,"HPP_FRAUD_FILTER_MODE":null,"TSS_INFO":null}'; + + $parsedResponse = $service->parseResponse($responseJson); + $responseCode = $parsedResponse->responseCode; // 00 + $responseMessage = $parsedResponse->responseMessage; // [ test system ] Authorised + $responseValues = $parsedResponse->responseValues; // get values accessible by key + + $eci = $responseValues["ECI"]; // 5 - fully authenticated + $cavv = $responseValues["CAVV"]; // AAACBUGDZYYYIgGFGYNlAAAAAAA= + $xid = $responseValues["XID"]; // vJ9NXpFueXsAqeb4iAbJJbe+66s= + // TODO: update your application and display transaction outcome to the customer + + $this->assertNotEquals(null, $parsedResponse); + $this->assertEquals("00", $responseCode); + } + + /* 02. ProcessPaymentConsumeHppResponse */ + + public function testprocessPaymentConsumeResponse() + { + $config = new GpEcomConfig(); + $config->merchantId = 'heartlandgpsandbox'; + $config->accountId = 'hpp'; + $config->sharedSecret = 'secret'; + $config->serviceUrl = 'https://pay.sandbox.realexpayments.com/pay'; + + $service = new HostedService($config); + + $responseJson = '{"MERCHANT_ID":"heartlandgpsandbox","ACCOUNT":"hpp","ORDER_ID":"NjMwNkMxMTAtMTA5RUNDRQ","TIMESTAMP":"20180720104340","RESULT":"00","PASREF":"15320798200414985","AUTHCODE":"12345","AVSPOSTCODERESULT":"U","CVNRESULT":"U","HPP_LANG":"GB","SHIPPING_CODE":null,"SHIPPING_CO":null,"BILLING_CODE":"123|56","BILLING_CO":"IRELAND","ECI":null,"CAVV":null,"XID":null,"MERCHANT_RESPONSE_URL":"http:\/\/requestb.in\/10q2bjb1","CARD_PAYMENT_BUTTON":null,"MESSAGE":"[ test system ] Authorised","AMOUNT":"100","SHA1HASH":"32628cf3f887ab9f4f1c547a10ac365c2168f0e2","DCC_INFO":null,"HPP_FRAUD_FILTER_MODE":null,"TSS_INFO":null}'; + + // create the response object from the response JSON + $parsedResponse = $service->parseResponse($responseJson); + + $orderId = $parsedResponse->orderId; // GTI5Yxb0SumL_TkDMCAxQA + $responseCode = $parsedResponse->responseCode; // 00 + $responseMessage = $parsedResponse->responseMessage; // [ test system ] Authorised + $responseValues = $parsedResponse->responseValues; // get values accessible by key + //$fraudFilterResult = $responseValues["HPP_FRAUDFILTER_RESULT"]; // PASS + + $this->assertNotEquals(null, $parsedResponse); + $this->assertEquals("00", $responseCode); + } + + /* 06. CardStorageCreatePayerStoreCardResponse */ + + public function testCardStorageCreatePayerStoreCardResponse() + { + $config = new GpEcomConfig(); + $config->merchantId = 'heartlandgpsandbox'; + $config->accountId = 'hpp'; + $config->sharedSecret = 'secret'; + $config->serviceUrl = 'https://pay.sandbox.realexpayments.com/pay'; + + $service = new HostedService( + $config + ); + + // TODO: grab the response JSON from the client-side for example: + //sample response JSON: + $responseJson = '{"MERCHANT_ID":"heartlandgpsandbox","ACCOUNT":"3dsecure","ORDER_ID":"NTgxMkMzODUtNTEwMkNCMw","TIMESTAMP":"20180723110112","RESULT":"00","PASREF":"15323400720177562","AUTHCODE":"12345","AVSPOSTCODERESULT":"U","CVNRESULT":"U","HPP_LANG":"GB","SHIPPING_CODE":null,"SHIPPING_CO":null,"BILLING_CODE":null,"BILLING_CO":null,"ECI":null,"CAVV":null,"XID":null,"MERCHANT_RESPONSE_URL":"http:\/\/requestb.in\/10q2bjb1","CARD_PAYMENT_BUTTON":null,"MESSAGE":"[ test system ] Authorised","AMOUNT":"1500","SHA1HASH":"4c7a635401c57371a0931bb3a21a849181cc963d","DCC_INFO":null,"HPP_FRAUD_FILTER_MODE":null,"TSS_INFO":null}'; + + $parsedResponse = $service->parseResponse($responseJson); + $responseCode = $parsedResponse->responseCode; // 00 + $responseMessage = $parsedResponse->responseMessage; // [ test system ] Authorised + $responseValues = $parsedResponse->responseValues; // get values accessible by key + /* + // Payer Setup Details + $payerSetupResult = $responseValues["PAYER_SETUP"]; // 00 + $payerSetupMessage = $responseValues["PAYER_SETUP_MSG"]; // Successful + $payerReference = $responseValues["SAVED_PAYER_REF"]; // 5e7e9152-2d53-466d-91bc-6d12ebc56b79 + // Card Setup Details + $cardSetupResult = $responseValues["PMT_SETUP"]; // 00 + $cardSetupMessage = $responseValues["PMT_SETUP_MSG"]; // Successful + $cardReference = $responseValues["SAVED_PMT_REF"]; // ca68dcac-9af2-4d65-b06c-eb54667dcd4a + // Card Details Stored + $cardType = $responseValues["SAVED_PMT_TYPE"]; // MC + $cardDigits = $responseValues["SAVED_PMT_DIGITS"]; // 542523xxxx4415 + $cardExpiry = $responseValues["SAVED_PMT_EXPDATE"]; // 1025 + $cardName = $responseValues["SAVED_PMT_NAME"]; // James Mason + */ + // TODO: update your application and display transaction outcome to the customer + + $this->assertNotEquals(null, $parsedResponse); + $this->assertEquals("00", $responseCode); + } + + /* 08. CardStorageDisplayStoredCardsResponse */ + + public function testCardStorageDisplayStoredCardsResponse() + { + $config = new GpEcomConfig(); + $config->merchantId = 'heartlandgpsandbox'; + $config->accountId = 'hpp'; + $config->sharedSecret = 'secret'; + $config->serviceUrl = 'https://pay.sandbox.realexpayments.com/pay'; + + $service = new HostedService( + $config + ); + + // TODO: grab the response JSON from the client-side for example: + //sample response JSON: + $responseJson = array("MERCHANT_ID" => "MerchantId", "ACCOUNT" => "internet", "ORDER_ID" => "GTI5Yxb0SumL_TkDMCAxQA", "AMOUNT" => "1999", "TIMESTAMP" => "20170725154824", "SHA1HASH" => "843680654f377bfa845387fdbace35acc9d95778", "RESULT" => "00", "AUTHCODE" => "12345", "CARD_PAYMENT_BUTTON" => "Place Order", "AVSADDRESSRESULT" => "M", "AVSPOSTCODERESULT" => "M", "BATCHID" => "445196", "MESSAGE" => "[ test system ] Authorised", "PASREF" => "15011597872195765", "CVNRESULT" => "M", "HPP_FRAUDFILTER_RESULT" => "PASS", "HPP_CHOSEN_PMT_REF" => "099efeb4-eda2-4fd7-a04d-29647bb6c51d", "HPP_EDITED_PMT_REF" => "037bd26a-c76b-4ee4-8063-376d8858f23d", "HPP_DELETED_PMT_REF" => "3db4c72c-cd95-4743-8070-f17e2b56b642"); + + $parsedResponse = $service->parseResponse(json_encode($responseJson)); + $responseCode = $parsedResponse->responseCode; // 00 + $responseMessage = $parsedResponse->responseMessage; // [ test system ] Authorised + $responseValues = $parsedResponse->responseValues; // get values accessible by key + // card used to complete payment, edited or deleted + $chosenCard = $responseValues["HPP_CHOSEN_PMT_REF"]; // 099efeb4-eda2-4fd7-a04d-29647bb6c51d + $editedCard = $responseValues["HPP_EDITED_PMT_REF"]; // 037bd26a-c76b-4ee4-8063-376d8858f23d + $deletedCard = $responseValues["HPP_DELETED_PMT_REF"]; // 3db4c72c-cd95-4743-8070-f17e2b56b642 + // TODO: update your application and display transaction outcome to the customer + + $this->assertNotEquals(null, $parsedResponse); + $this->assertEquals("00", $responseCode); + } + + /* 12. FraudManagementResponse */ + + public function testFraudManagementResponse() + { + $config = new GpEcomConfig(); + $config->merchantId = 'heartlandgpsandbox'; + $config->accountId = 'hpp'; + $config->sharedSecret = 'secret'; + $config->serviceUrl = 'https://pay.sandbox.realexpayments.com/pay'; + + $service = new HostedService( + $config + ); + + // TODO: grab the response JSON from the client-side for example: + //sample response JSON: + $responseJson = array("MERCHANT_ID" => "MerchantId", "ACCOUNT" => "internet", "ORDER_ID" => "GTI5Yxb0SumL_TkDMCAxQA", "AMOUNT" => "1999", "TIMESTAMP" => "20170725154824", "SHA1HASH" => "843680654f377bfa845387fdbace35acc9d95778", "RESULT" => "00", "AUTHCODE" => "12345", "CARD_PAYMENT_BUTTON" => "Place Order", "AVSADDRESSRESULT" => "M", "AVSPOSTCODERESULT" => "M", "BATCHID" => "445196", "MESSAGE" => "[ test system ] Authorised", "PASREF" => "15011597872195765", "CVNRESULT" => "M", "HPP_FRAUDFILTER_RESULT" => "HOLD", "HPP_FRAUDFILTER_RULE_56257838-4590-4227-b946-11e061fb15fe" => "HOLD", "HPP_FRAUDFILTER_RULE_cf609cf9-9e5a-4700-ac69-8aa09c119305" => "PASS"); + ; + + $parsedResponse = $service->parseResponse(json_encode($responseJson)); + $responseCode = $parsedResponse->responseCode; // 00 + $responseValues = $parsedResponse->responseValues; // get values accessible by key + + $fraudFilterResult = $responseValues["HPP_FRAUDFILTER_RESULT"]; // HOLD + $cardRuleResult = $responseValues["HPP_FRAUDFILTER_RULE_56257838-4590-4227-b946-11e061fb15fe"]; // HOLD + $ipRuleResult = $responseValues["HPP_FRAUDFILTER_RULE_cf609cf9-9e5a-4700-ac69-8aa09c119305"]; // PASS + // TODO: update your application and display transaction outcome to the customer + + $this->assertNotEquals(null, $parsedResponse); + $this->assertEquals("00", $responseCode); + } + + /* 14. DynamicCurrencyConversionResponse */ + + public function testDynamicCurrencyConversionResponse() + { + $config = new GpEcomConfig(); + $config->merchantId = 'heartlandgpsandbox'; + $config->accountId = 'hpp'; + $config->sharedSecret = 'secret'; + $config->serviceUrl = 'https://pay.sandbox.realexpayments.com/pay'; + + $service = new HostedService( + $config + ); + + // TODO: grab the response JSON from the client-side for example: + //sample response JSON: + $responseJson = '{"MERCHANT_ID":"heartlandgpsandbox","ACCOUNT":"apidcc","ORDER_ID":"NTQyQzgxREMtMzVFQzlDNw","TIMESTAMP":"20180724095953","RESULT":"00","PASREF":"15324227932436743","AUTHCODE":"12345","AVSPOSTCODERESULT":"U","CVNRESULT":"U","HPP_LANG":"GB","SHIPPING_CODE":null,"SHIPPING_CO":null,"BILLING_CODE":null,"BILLING_CO":null,"ECI":null,"CAVV":null,"XID":null,"MERCHANT_RESPONSE_URL":"http:\/\/requestb.in\/10q2bjb1","CARD_PAYMENT_BUTTON":null,"MESSAGE":"[ test system ] Authorised","AMOUNT":"100100","SHA1HASH":"320c7ddc49d292f5900c676168d5cc1f2a55306c","DCC_INFO_REQUST":{"CCP":"Fexco","TYPE":1,"RATE":"1.7203","RATE_TYPE":"S","AMOUNT":"172202","CURRENCY":"AUD"},"DCC_INFO_RESPONSE":{"cardHolderCurrency":"AUD","cardHolderAmount":"172202","cardHolderRate":"1.7203","merchantCurrency":"EUR","merchantAmount":"100100","marginRatePercentage":"","exchangeRateSourceName":"","commissionPercentage":"","exchangeRateSourceTimestamp":""},"HPP_FRAUD_FILTER_MODE":null,"TSS_INFO":null}'; + $parsedResponse = $service->parseResponse($responseJson); + + $responseCode = $parsedResponse->responseCode; // 00 + $responseValues = $parsedResponse->responseValues; // get values accessible by key + + $conversionProcessor = $responseValues['DCC_INFO_REQUST']["CCP"]; // fexco + $conversionRate = $responseValues['DCC_INFO_REQUST']["RATE"]; // 1.7203 + $merchantAmount = $responseValues['DCC_INFO_RESPONSE']["merchantAmount"]; // 1999 + $cardholderAmount = $responseValues['DCC_INFO_RESPONSE']["cardHolderAmount"]; // 3439 + $merchantCurrency = $responseValues['DCC_INFO_RESPONSE']["merchantCurrency"]; // EUR + $cardholderCurrency = $responseValues['DCC_INFO_RESPONSE']["cardHolderCurrency"]; // AUD + $marginPercentage = $responseValues['DCC_INFO_RESPONSE']["marginRatePercentage"]; // 3.75 + $exchangeSource = $responseValues['DCC_INFO_RESPONSE']["exchangeRateSourceName"]; // REUTERS WHOLESALE INTERBANK + $commissionPercentage = $responseValues['DCC_INFO_RESPONSE']["commissionPercentage"]; // 0 + $exchangeTimestamp = $responseValues['DCC_INFO_RESPONSE']["exchangeRateSourceTimestamp"]; // 20170518162700 + // TODO: update your application and display transaction outcome to the customer + $this->assertNotEquals(null, $parsedResponse); + $this->assertEquals("00", $responseCode); + } +} diff --git a/test/Integration/Gateways/RealexConnector/Realex3dSecureTests.php b/test/Integration/Gateways/RealexConnector/Realex3dSecureTests.php index d29cc34f..6eacb6b1 100644 --- a/test/Integration/Gateways/RealexConnector/Realex3dSecureTests.php +++ b/test/Integration/Gateways/RealexConnector/Realex3dSecureTests.php @@ -1,500 +1,500 @@ -getConfig()); - } - - protected function getConfig() - { - $config = new GpEcomConfig(); - $config->merchantId = 'heartlandgpsandbox'; - $config->accountId = '3dsecure'; - $config->sharedSecret = 'secret'; - $config->rebatePassword = 'rebate'; - $config->refundPassword = 'refund'; - $config->serviceUrl = 'https://api.sandbox.realexpayments.com/epage-remote.cgi'; - return $config; - } - - public function testAcsClient() - { - $authClient = new ThreeDSecureAcsClient('https://pit.3dsecure.net/VbVTestSuiteService/pit1/acsService/paReq?summary=MTNmMzI4NzgtNTdmZi00OWEzLWJhZTAtYzFhNzAxMDJkMGNi'); - $this->assertNotNull($authClient->authenticate('eJxlUsFSwjAQvfsVTO82TSm0MNs4FVBwRkUF8ZomK1Rpimkr6NebYBEdc8jsy27evrwNnO3ydesddZkVKnao6zktVKKQmVrGznx2cRo5Z+wEZiuNOHxAUWtkcI1lyZfYymTs+KIjZYRt30tl0H2WPRpFIuQyDULsdTvoMJgm9/jGoOnCTBPXB3KAhk2LFVcVAy7ezic3LAgD2ouANBBy1JMh6zULyDcGxXNkK+S6WnMll5vS7GmxA7JPgChqVekPFgUekAOAWq/Zqqo2ZZ+Q7Xbr/r/visKtX4HYSiBHcdPaRqVh3mWSJcM7Nb7t0O1iGs6n7cXnI025N7hSk1EMxFaA5BUy36MhpX7Y8r1+J+hTI39/Djy3kqwZRl4DYGN7JE3GJn4fgDFfm+EcnnRAgLtNodBUGFd/YiBHwYOx9VZUxrVxdjEb1aPXy5f5k27Tmzo/v75N4ti6vS+wbJlxikb0m84CIJaCNIMkzfxN9OdffAF4VML9')); - } - - public function testMerchantDataEnumerator() - { - $keys = ['Key1', 'Key2', 'Key3']; - $values = ['Value1', 'Value2', 'Value3']; - - $merchantData = new MerchantDataCollection(); - for ($i=0; $i<3; $i++) { - $merchantData->add($keys[$i], $values[$i]); - } - - $this->assertEquals(3, $merchantData->count()); - - foreach ($merchantData->getKeys() as $key) { - $this->assertTrue(in_array($key, $keys)); - $this->assertTrue(in_array($merchantData->get($key), $values)); - } - } - - public function testMerchantDataWithHiddenValues() - { - $card = new CreditCardData(); - $card->number = 4012001037141112; - $card->expMonth = 12; - $card->expYear = TestCards::validCardExpYear(); - $card->cardHolderName = 'James Mason'; - - $enrolled = $card->verifyEnrolled(100, 'USD'); - $this->assertNotNull($enrolled); - if ($enrolled) { - $merchantData = $card->threeDSecure->getMerchantData(); - - $this->assertNotNull($merchantData); - $this->assertEquals(0, $merchantData->count()); - - $this->assertNull($merchantData->get('amount')); - $this->assertNull($merchantData->get('currency')); - $this->assertNull($merchantData->get('orderId')); - - for ($i=0; $i<3; $i++) { - $merchantData->add('Key'.$i, 'Value'.$i); - - $this->assertNotNull($merchantData->get('Key'.$i)); - $this->assertEquals('Value'.$i, $merchantData->get('Key'.$i)); - } - - $this->assertEquals(3, $merchantData->count()); - } - } - - public function testMerchantDataEncryptAndDecrypt() - { - $merchantData = new MerchantDataCollection(); - $merchantData->add('customerId', '12345'); - $merchantData->add('invoiceNumber', '54321'); - - $encoder = function ($input) { - $encoded = sprintf('%s.%s', $input, 'secret'); - return base64_encode($encoded); - }; - - $encrypted = $merchantData->toString($encoder); - - $decoder = function ($input) { - $decoded = explode('.', (string)base64_decode($input)); - $this->assertEquals('secret', $decoded[1]); - return $decoded[0]; - }; - - $decrypted = $merchantData->parse($encrypted, $decoder); - - $this->assertNotNull($decrypted); - $this->assertNotNull($decrypted->get('customerId')); - $this->assertEquals('12345', $decrypted->get('customerId')); - $this->assertNotNull($decrypted->get('invoiceNumber')); - $this->assertEquals('54321', $decrypted->get('invoiceNumber')); - } - - public function testMerchantDataMultiKey() - { - $this->expectExceptionMessage('Cannot access private property GlobalPayments\Api\Entities\MerchantDataCollection::$collection'); - - $mcd = new MerchantDataCollection(); - array_push($mcd->collection, array('amount'=>'10')); - array_push($mcd->collection, array('amount'=>'10')); - } - - public function testFullCycleWithMerchantData() - { - $card = new CreditCardData(); - $card->number = 4012001037141112; - $card->expMonth = 12; - $card->expYear = TestCards::validCardExpYear(); - $card->cardHolderName = 'John Smith'; - - $enrolled = $card->verifyEnrolled(1, 'USD'); - if ($enrolled) { - $secureEcom = $card->threeDSecure; - if (!empty($secureEcom)) { - $merchantData = new MerchantDataCollection(); - $merchantData->add('client_txn_id', '123456'); - - $authClient = new ThreeDSecureAcsClient($secureEcom->issuerAcsUrl); - $authResponse = $authClient->authenticate($secureEcom->payerAuthenticationRequest, (string)$secureEcom->getMerchantData()->toString()); - - $payerAuthenticationResponse = $authResponse->getAuthResponse(); - $md = MerchantDataCollection::parse($authResponse->getMerchantData()); - - if ($card->verifySignature($payerAuthenticationResponse, $md)) { - $response = $card->charge(1) - ->withCurrency('USD') - ->execute(); - $this->assertNotNull($response); - $this->assertEquals('00', $response->responseCode); - } else { - $this->fail('Signature verification failed.'); - } - } else { - $this->fail('Secure3Data was null.'); - } - } else { - $this->fail('Card not enrolled.'); - } - } - - public function testFullCycleWithNoMerchantData() - { - $card = new CreditCardData(); - $card->number = 4012001037141112; - $card->expMonth = 12; - $card->expYear = TestCards::validCardExpYear(); - $card->cardHolderName = 'James Mason'; - - $amount = 100; - $currency = 'USD'; - $orderId = GenerationUtils::generateOrderId(); - - $enrolled = $card->verifyEnrolled($amount, $currency, $orderId); - - if ($enrolled) { - $secureEcom = $card->threeDSecure; - - if ($secureEcom != null) { - $authClient = new ThreeDSecureAcsClient($secureEcom->issuerAcsUrl); - $authResponse = $authClient->authenticate($secureEcom->payerAuthenticationRequest, (string)$secureEcom->getMerchantData()->toString()); - - $payerAuthenticationResponse = $authResponse->getAuthResponse(); - - if ($card->verifySignature($payerAuthenticationResponse, null, $amount, $currency, $orderId)) { - $response = $card->charge($amount) - ->withCurrency($currency) - ->withOrderId($orderId) - ->execute(); - $this->assertNotNull($response); - $this->assertEquals('00', $response->responseCode); - } else { - $this->fail('Signature verification failed.'); - } - } else { - $this->fail('Secure3Data was null.'); - } - } else { - $this->fail('Card not enrolled.'); - } - } - - public function testVerifyEnrolledTrue() - { - $card = new CreditCardData(); - $card->number = 4012001037141112; - $card->expMonth = 12; - $card->expYear = TestCards::validCardExpYear(); - $card->cardHolderName = 'John Smith'; - - $enrolled = $card->verifyEnrolled(1, 'USD'); - $this->assertTrue($enrolled); - $this->assertNotNull($card->threeDSecure); - $this->assertNotNull($card->threeDSecure->payerAuthenticationRequest); - $this->assertNotNull($card->threeDSecure->issuerAcsUrl); - $this->assertNotNull($card->threeDSecure->xid); - } - - public function testVerifyEnrolledFalse() - { - $card = new CreditCardData(); - $card->number = 4012001038443335; - $card->expMonth = 12; - $card->expYear = TestCards::validCardExpYear(); - $card->cardHolderName = 'John Smith'; - - $enrolled = $card->verifyEnrolled(1, 'USD'); - $this->assertFalse($enrolled); - } - - /** - * @expectedException GlobalPayments\Api\Entities\Exceptions\GatewayException - */ - public function testVerifySignatureBadOrderId() - { - $card = new CreditCardData(); - $card->verifySignature('eNrVWNmyozqy/ZWK6kfHOcwYOly7Q8yDwWYe3jBgRjPbYL7+4r1r16muWx3RfZ/68oKUSKlU5sqVQod/LLf6yyMdxqJtvn1F/oS/fvnH28HOhzTlrDS+D+nbQUvHMcrSL0Xy7SuNIjEMX1L8iiX4FUcudEQjURzhOEHHaHL9+nY4AzMd3wcTCEbS2Cb6vsDbpv9P9AB9djfNQ5xHzfR2iOKekfU3fI8jNHWAvncPt3SQuTf6+3OAPvoH6K+J5/urNW5mLkXyVvi9feR6zi2AGBCUZax3S3EeCI1T3w7Qa8Qhiab0DYWRPYKg1BcU/jtM/h3DD9C7/NC91IFbe990IzB8gH4WHDZ/DGkTP98ofPv0o3dIl65t0m3Etrkf7QP0l21d1LzBPz3Itvime5MebP/tMBW339r0Lj+MUzTdx7fgAH1vHeLo8XgDALAM5nAuq6OAk/mToTv8DF7Pttf3IYc0Lt5gYjNqe7/PAnXWDsWU316m/rPgAL1Mgd7D93awiqzZFhvSLxtCmvHb13yaur9D0DzPf87Yn+2QQei2EQimoW1AMhbZ375+zEoTubm2/9E0NmrapoijulijaUOGlk55m3z5Ydvv1NjmSxMCmTz7x6bqjxjBmz9eEhhDiE0n9HulP+3s31nlV2OHMfpjzCPktcAvit4OZnpNX4hIvzim/O3r337gnyuydJz+L+t9rvWzhk99blTf07e0Cz2ekj38LKW5mBLXiiFuoZWxN/7b57yPkQfoh4Hfrf8I1U8u+RgYUzvuaUx4FwaJURWc56HH/Yq5TX6sxTUIH7Kxm3TLLCiuVcwIo9nqtl8jNXLXCCmXR6CecFdoVjhC4P0ss+gsd6d67xE6QiD56kCcejLFztTiiAvNZfLHeL1h887PuAlrHBgMsnZf9YZfoTItL9UYe9J5ARby8CUM707lwz+x+lUzLCrHSh492mJNPOddfW8pUpq5py89JfPspIjDqTKDUiiAz3qwq0CU5UKVeyQU3KNmSHust3NjQcmezBAvOSV5ztJ9m1H3heSvdSYxDya+QNxMqTNrQS52c1RdURkVO6pPBdtrqrYwNuqT5nWOWX7p67lbMl1rply2U6rhNPQWdh3/OCdC9u3bT5D5HhE1fX5EwCdgmoum6KPFpsNUXDfsbpSkyTIX2iwLKjQDs8yATHbBSZIUbSr2QSqRbBeaZo3T64pHXJVpABZZqxct+YJxBs+wswM0MVu4FehMprsM0GymZhRXoDnD5l2N0USAODy7aJpbKZ4rumsi6Ejkm7VmwDM7B5xrGCo/m57l6oxmUDNnvMskfg750CPQ0JcX3gbnD/2ZzfL64yLSz8AzH5oxzuzHeJGfFddZQSrM8KKX/KyVYNFKftU4IXrJTtw/yzQJLMIK3O92a9yNeFxu7jVG6+ZS02XoK7BmOjP/YeORA4tn1KET+jrsYG6XiM7C2eD4Mb/VGCFUHJj/yRexxlRmfWnCOi55UwPUhy82RxsoPV4wJQ9FamFXoHyMD2xQu/YWE0YuXzqqPq8KkZ5hBhi8AMCJBQYFXt/ZTN3aPChKJ7Rv9KCfnfwsk6PchIR1U8M48i5zEp0LledpSOG5tbi7ir4Hec0jitt7GL460igVzY4wc1uYey7SfdW1S5k/L3dU4wpyycNsiloIRW6sGtmr7z5Hx9Af7NgB04GanE0umIPQqSxX4ERiWA0/aPKiaiEGY8I9FxktVagm0Mie6yCHw0zfjq3LxbaOKSaxK38DNGlCZ93jqskK9hBDOHkn7oQtMXYZlOPpNT6Fij4n4qmushGzm77B7cezjM+7ihNvqLg/kVe85x2a7vlHGISCrRot3YaKedX2I3dUC0bCgTyeI0BwxaTsl5AQ+diwMtO3XMqWYsNjS3a98hg4ZtE09VLoE4bMAQMwv8M6wLccMYDT+2ITZSu+gxf3dO010B4bFRodi5D7MyPkHMTR/R4ttIZrBm+cqGZ25ztSHsnlKktetpZ+kZQQEWiwaIrHliUSnofTEtu7nrwGbTBZZ4PjvAc7AEdr54WOWa9iNY0M66TH97tThmDoxh3skCgCz9Rk3lQMBJMeWyyqBS+RzUNkzN5dLC6eOtOi7JTRftNTUB92CUEw+ykOUpg44rf5stc78xgaa+pvEUSlNnpk5vV5PnYpSybdIg0R2en6rBaDDldX/o6wyLnMhqeHb4nBqWo3BpBYXMM6ijGrTNR85tNZvndnZfSMUJ661BokqlB8wgn5dKKQnWW70fRgm+xcuPpj5z32i3yAfmWn39EVL77oahY/6coExyCmt6DtJ2uxyULc8bfi5jovGlHUNpTzR6xvqXJkDDBvXjlqoHpPQybXWNfVfk5he0vhLkb55biC6UM22kr9Lsssj4A3SrgHvtldUCK/sIy99dHI02uZF9YYpcvIE+DIo++a2c4ieKcNjl8EL/L1XBbd8oIi0zanDC3GNOxPqgKEZldPjdNWnUteVPXU142mbH7WOQ1/yf67KHbzvyX/6l9m8y+XZfwZcNt3o2W3NgPUIQkhwylnnFurfSUQjR3uT0F/q5A9luGXR4abO1XCkXVa49m562eyHcZdOMYoZAlb4UO1qzYjp/mMboUvz+mWSpjc3SttyjtuTM+lDnsSye2mHkiXErai/pT3OUPdoTqqLXqRLt3jWUE8sYqlaJ/mdisAst9VKXW3SNS+E5KqMuLyyENIscH9mjCPI1bsHK2/Vrq9+AGvAjWBpYKUpOFxqup+5rcDzCh3+BoOXcBB5j3h8MGQxNm3DDiiGH0x1uet9cq2OI2aKwdqhjxqQw5nGh902m0uk9nCCTLUY9wBviX16pwwaCDeOE8O9/N8IUeB2xtCKyqJTflFxUjxxJHnMKWSBuumccM/D0B0Yh4cy9xtYL3iJpkaA64Uz3JABIYEgYwHmmS8sJHIwJw0cZwjIxBCnN/o7VXUQMlk2cBkvMAYMQvMwI8kE465dnNBgiVPAn3h9njbsGDRc4RW88kIZHUOtlg70pZ789EGgZALVugzY/DKA8FsI1/LNgziCQe4zQZG/NffT+92G9S73RuuN9wEs/TCmgmfGCbgBa3N0gqUocDEcgae1dWyIGXbqsIM/5qe2WHkCoDGO2+4IfaOtwlYT0Qa5baiUVQqUoxrz86GhAfpg0jKGXaZx55mE+s5DZqT5VAMp1CwIreOQ9aTrJ/Twm0Jq6kRpnzeK80g+RatfRPLhI0s2fUcjK2Otv5kzWJMFRpwpko25QwJUeqIybfWlfbxObYLz8yHgQLtXXa286SQdeOz3ThRkjpYs28rzt99Uh/ZbvcEnKIE2DASLCjtZ60FhokpIwm4wd5nz9MsXdHpURzVZkJYS5KeO4IlnzgVnfir0t72NjhleF3WVWUKJ5XzHCeuEYWppCldnGML+SHiyrhvHlMVjdUwInN/7ypLpTPwkXEG6ITjxf6xE0MvszWxo9SSX/5NehbKLf0f5Cc9G+l0Ryxt6RpeB01zWpHz7jzZv55uHAFwTPe/qYbXNTB+0Fuu8e6tXgObf2gs/El5t3eZxSiXxqzjG5EnYr2d4oRRFvQ6bsIuQJ3M8PX1gurdB3Xji1iC4JNKefeD3kNvg7mHbDpeMBUYjcF9zn6dFPntxAhWbY3hk9tuMu1X2X9ZWfkP6FmvnGut3rqGQKdAxsKJ0c/eOcBHXFUaSHK9WOB2lltEJ4fxckpMn8n9okMtO4vyVF3V5WEVnGnerCvryArTw17NG9g9BscLxOzk02DORlaMPXbRYTk8ghheJbl7ev79FrXVuB8j88GNEToPlxXiJ6SvNLiEWgl6nIat7KkSrdBEX7E9vpWNkY+fRKPOV67qBPTaVuEEO6oqTIsrxRZ/tnhk1XVkQ/Fi6d3+0fnP5XG0Rhbyk4ES9zaboRfkufieUA5nGLlvMOUbRbWbUMZZ1EnzeSk3NmWv1mhDQHwsXH71zsPAT4C02Zijh1NHc93s64WliOe1ih3Hu0rbb4Cf0WmQFTbf0ige/6Dnu80yU/lRVj/pmbE3Wtzo+f89NTMLJT2jxABejTP3113Rsv0lCnolr79S82bTJzWniIjm5xGAndnqLRy7DbKz05iygsRggLDv2eZIC2ke3fF9ipFXV9SL9VQ9ZZsGktgOpIkc5ShX/R1P3nrDDsa1USwi9xVKpGL4DN+W0rXiy/5ZzQYxM0Hvexp68dWuONpp4HpXBAyC13fIkxZJEwanqDmWt1k3GTBkzwdZI0Z42Tsaxlxpi6jh+yBoR3gDCsXs6bpOCR9D5QddXu/xnYwjeWCO1dlayKDf9VvxHXFKN62TvoPO/Y2WlhmRMOi5ov1RxFdb3i+Ky/FWKPJ+lBxnVvE58mSmPipAzOQkVI9iSemHFzco5CtPp5cBzzCEQJnaZaUQFZ/npMzl+zGVUMS92FDy5CUJ/Iaaob/++aEf9wB/3RC833K+X7y+buZ+vpD9HwzDHH8=', null, 1, 'USD', 'orderId'); - } - - /** - * @expectedException GlobalPayments\Api\Entities\Exceptions\BuilderException - */ - public function testVerifySignatureNoPaymentResponse() - { - $card = new CreditCardData(); - $card->verifySignature(null); - } - - /** - * @expectedException GlobalPayments\Api\Entities\Exceptions\BuilderException - */ - public function testVerifySignatureNoAmount() - { - $card = new CreditCardData(); - $card->verifySignature('paymentResponse', null, null, 'USD', 'orderId'); - } - - /** - * @expectedException GlobalPayments\Api\Entities\Exceptions\BuilderException - */ - public function testVerifySignatureNoCurrency() - { - $card = new CreditCardData(); - $card->verifySignature('paymentResponse', null, 10, null, 'orderId'); - } - - /** - * @expectedException GlobalPayments\Api\Entities\Exceptions\BuilderException - */ - public function testVerifySignatureNoOrderId() - { - $card = new CreditCardData(); - $card->verifySignature('paymentResponse', null, 10, 'USD', null); - } - - public function testAuthorize3dSecure() - { - $secureEcom = new ThreeDSecure(); - $secureEcom->cavv = 'AAACBllleHchZTBWIGV4AAAAAAA='; - $secureEcom->xid = 'crqAeMwkEL9r4POdxpByWJ1/wYg='; - $secureEcom->eci = '5'; - - $card = new CreditCardData(); - $card->number = 4012001037141112; - $card->expMonth = 12; - $card->expYear = TestCards::validCardExpYear(); - $card->cardHolderName = 'Philip Marlowe'; - $card->threeDSecure = $secureEcom; - - $response = $card->charge(10) - ->withCurrency('EUR') - ->execute(); - - $this->assertNotNull($response); - $this->assertEquals('00', $response->responseCode); - } - - public function testCardHolderNotEnrolled() - { - $card = new CreditCardData(); - $card->number = 4012001038443335; - $card->expMonth = 12; - $card->expYear = TestCards::validCardExpYear(); - $card->cardHolderName = 'John Smith'; - - $enrolled = $card->verifyEnrolled(10, 'USD'); - $this->assertFalse($enrolled); - $this->assertNotNull($card->threeDSecure); - $this->assertEquals('6', $card->threeDSecure->eci); - - // .net test does not have amount or currency but validation would not allow this - $response = $card->charge(10) - ->withCurrency('USD') - ->execute(); - $this->assertNotNull($response); - $this->assertEquals('00', $response->responseCode); - } - - public function testUnableToVerifyEnrollment() - { - $card = new CreditCardData(); - $card->number = 4012001038488884; - $card->expMonth = 12; - $card->expYear = TestCards::validCardExpYear(); - $card->cardHolderName = 'John Smith'; - - $enrolled = $card->verifyEnrolled(10, 'USD'); - $this->assertFalse($enrolled); - $this->assertNotNull($card->threeDSecure); - $this->assertEquals('7', $card->threeDSecure->eci); - - $response = $card->charge(10) - ->withCurrency('USD') - ->execute(); - $this->assertNotNull($response); - $this->assertEquals('00', $response->responseCode); - } - - /** - * @expectedException GlobalPayments\Api\Entities\Exceptions\GatewayException - */ - public function testInvalidResponseFromEnrollmentServer() - { - $card = new CreditCardData(); - $card->number = 4012001036298889; - $card->expMonth = 12; - $card->expYear = TestCards::validCardExpYear(); - $card->cardHolderName = 'John Smith'; - - $card->verifyEnrolled(10, 'USD'); - } - - public function testCardHolderIsEnrolledACSAuthFailed() - { - $card = new CreditCardData(); - $card->number = 4012001036853337; - $card->expMonth = 12; - $card->expYear = TestCards::validCardExpYear(); - $card->cardHolderName = 'John Smith'; - - $enrolled = $card->verifyEnrolled(10, 'USD'); - $this->assertTrue($enrolled); - - $secureEcom = $card->threeDSecure; - $authClient = new ThreeDSecureAcsClient($secureEcom->issuerAcsUrl); - $authResponse = $authClient->authenticate($secureEcom->payerAuthenticationRequest, $secureEcom->getMerchantData()->toString()); - - // $payerAuthenticationResponse = $authResponse->parse(); - $payerAuthenticationResponse = $authResponse->getAuthResponse(); - $md = MerchantDataCollection::parse($authResponse->getMerchantData()); - - $verified = $card->verifySignature($payerAuthenticationResponse, $md); - $this->assertFalse($verified); - $this->assertNotNull($card->threeDSecure); - $this->assertEquals(7, $card->threeDSecure->eci); - - $response = $card->charge(10) - ->withCurrency('USD') - ->execute(); - $this->assertNotNull($response); - $this->assertEquals('00', $response->responseCode); - } - - public function testCardHolderIsEnrolledACSAcknowledged() - { - $card = new CreditCardData(); - $card->number = 4012001037167778; - $card->expMonth = 12; - $card->expYear = TestCards::validCardExpYear(); - $card->cardHolderName = 'John Smith'; - - $enrolled = $card->verifyEnrolled(10, 'USD'); - $this->assertTrue($enrolled); - - $secureEcom = $card->threeDSecure; - $authClient = new ThreeDSecureAcsClient($secureEcom->issuerAcsUrl); - $authResponse = $authClient->authenticate($secureEcom->payerAuthenticationRequest, $secureEcom->getMerchantData()->toString()); - - // $payerAuthenticationResponse = $authResponse->parse(); - $payerAuthenticationResponse = $authResponse->getAuthResponse(); - $md = MerchantDataCollection::parse($authResponse->getMerchantData()); - - $verified = $card->verifySignature($payerAuthenticationResponse, $md); - $this->assertTrue($verified); - $this->assertEquals('A', $card->threeDSecure->status); - - $response = $card->charge(10) - ->withCurrency('USD') - ->execute(); - $this->assertNotNull($response); - $this->assertEquals('00', $response->responseCode); - } - - public function testCardHolderIsEnrolledACSFailed() - { - $card = new CreditCardData(); - $card->number = 4012001037461114; - $card->expMonth = 12; - $card->expYear = TestCards::validCardExpYear(); - $card->cardHolderName = 'John Smith'; - - $enrolled = $card->verifyEnrolled(10, 'USD'); - $this->assertTrue($enrolled); - - $secureEcom = $card->threeDSecure; - $authClient = new ThreeDSecureAcsClient($secureEcom->issuerAcsUrl); - $authResponse = $authClient->authenticate($secureEcom->payerAuthenticationRequest, $secureEcom->getMerchantData()->toString()); - - // $payerAuthenticationResponse = $authResponse->parse(); - $payerAuthenticationResponse = $authResponse->getAuthResponse(); - $md = MerchantDataCollection::parse($authResponse->getMerchantData()); - - $verified = $card->verifySignature($payerAuthenticationResponse, $md); - $this->assertFalse($verified); - $this->assertEquals('N', $card->threeDSecure->status); - $this->assertEquals(7, $card->threeDSecure->eci); - - $response = $card->charge(10) - ->withCurrency('USD') - ->execute(); - $this->assertNotNull($response); - $this->assertEquals('00', $response->responseCode); - } - - public function testCardHolderIsEnrolledACSUnavailable() - { - $card = new CreditCardData(); - $card->number = 4012001037484447; - $card->expMonth = 12; - $card->expYear = TestCards::validCardExpYear(); - $card->cardHolderName = 'John Smith'; - - $enrolled = $card->verifyEnrolled(10, 'USD'); - $this->assertTrue($enrolled); - - $secureEcom = $card->threeDSecure; - $authClient = new ThreeDSecureAcsClient($secureEcom->issuerAcsUrl); - $authResponse = $authClient->authenticate($secureEcom->payerAuthenticationRequest, $secureEcom->getMerchantData()->toString()); - - $payerAuthenticationResponse = $authResponse->getAuthResponse(); - $md = MerchantDataCollection::parse($authResponse->getMerchantData()); - - $verified = $card->verifySignature($payerAuthenticationResponse, $md); - $this->assertFalse($verified); - $this->assertEquals('U', $card->threeDSecure->status); - $this->assertEquals(7, $card->threeDSecure->eci); - - $response = $card->charge(10) - ->withCurrency('USD') - ->execute(); - $this->assertNotNull($response); - $this->assertEquals('00', $response->responseCode); - } - - /** - * @expectedException GlobalPayments\Api\Entities\Exceptions\GatewayException - */ - public function testCardHolderIsEnrolledACSInvalid() - { - $card = new CreditCardData(); - $card->number = 4012001037490006; - $card->expMonth = 12; - $card->expYear = TestCards::validCardExpYear(); - $card->cardHolderName = 'John Smith'; - - $enrolled = $card->verifyEnrolled(10, 'USD'); - $this->assertTrue($enrolled); - - $secureEcom = $card->threeDSecure; - $authClient = new ThreeDSecureAcsClient($secureEcom->issuerAcsUrl); - $authResponse = $authClient->authenticate($secureEcom->payerAuthenticationRequest, $secureEcom->getMerchantData()->toString()); - - $payerAuthenticationResponse = $authResponse->getAuthResponse(); - $md = MerchantDataCollection::parse($authResponse->getMerchantData()); - - $card->verifySignature($payerAuthenticationResponse, $md); - } -} +getConfig()); + } + + protected function getConfig() + { + $config = new GpEcomConfig(); + $config->merchantId = 'heartlandgpsandbox'; + $config->accountId = '3dsecure'; + $config->sharedSecret = 'secret'; + $config->rebatePassword = 'rebate'; + $config->refundPassword = 'refund'; + $config->serviceUrl = 'https://api.sandbox.realexpayments.com/epage-remote.cgi'; + return $config; + } + + public function testAcsClient() + { + $authClient = new ThreeDSecureAcsClient('https://pit.3dsecure.net/VbVTestSuiteService/pit1/acsService/paReq?summary=MTNmMzI4NzgtNTdmZi00OWEzLWJhZTAtYzFhNzAxMDJkMGNi'); + $this->assertNotNull($authClient->authenticate('eJxlUsFSwjAQvfsVTO82TSm0MNs4FVBwRkUF8ZomK1Rpimkr6NebYBEdc8jsy27evrwNnO3ydesddZkVKnao6zktVKKQmVrGznx2cRo5Z+wEZiuNOHxAUWtkcI1lyZfYymTs+KIjZYRt30tl0H2WPRpFIuQyDULsdTvoMJgm9/jGoOnCTBPXB3KAhk2LFVcVAy7ezic3LAgD2ouANBBy1JMh6zULyDcGxXNkK+S6WnMll5vS7GmxA7JPgChqVekPFgUekAOAWq/Zqqo2ZZ+Q7Xbr/r/visKtX4HYSiBHcdPaRqVh3mWSJcM7Nb7t0O1iGs6n7cXnI025N7hSk1EMxFaA5BUy36MhpX7Y8r1+J+hTI39/Djy3kqwZRl4DYGN7JE3GJn4fgDFfm+EcnnRAgLtNodBUGFd/YiBHwYOx9VZUxrVxdjEb1aPXy5f5k27Tmzo/v75N4ti6vS+wbJlxikb0m84CIJaCNIMkzfxN9OdffAF4VML9')); + } + + public function testMerchantDataEnumerator() + { + $keys = ['Key1', 'Key2', 'Key3']; + $values = ['Value1', 'Value2', 'Value3']; + + $merchantData = new MerchantDataCollection(); + for ($i=0; $i<3; $i++) { + $merchantData->add($keys[$i], $values[$i]); + } + + $this->assertEquals(3, $merchantData->count()); + + foreach ($merchantData->getKeys() as $key) { + $this->assertTrue(in_array($key, $keys)); + $this->assertTrue(in_array($merchantData->get($key), $values)); + } + } + + public function testMerchantDataWithHiddenValues() + { + $card = new CreditCardData(); + $card->number = 4012001037141112; + $card->expMonth = 12; + $card->expYear = TestCards::validCardExpYear(); + $card->cardHolderName = 'James Mason'; + + $enrolled = $card->verifyEnrolled(100, 'USD'); + $this->assertNotNull($enrolled); + if ($enrolled) { + $merchantData = $card->threeDSecure->getMerchantData(); + + $this->assertNotNull($merchantData); + $this->assertEquals(0, $merchantData->count()); + + $this->assertNull($merchantData->get('amount')); + $this->assertNull($merchantData->get('currency')); + $this->assertNull($merchantData->get('orderId')); + + for ($i=0; $i<3; $i++) { + $merchantData->add('Key'.$i, 'Value'.$i); + + $this->assertNotNull($merchantData->get('Key'.$i)); + $this->assertEquals('Value'.$i, $merchantData->get('Key'.$i)); + } + + $this->assertEquals(3, $merchantData->count()); + } + } + + public function testMerchantDataEncryptAndDecrypt() + { + $merchantData = new MerchantDataCollection(); + $merchantData->add('customerId', '12345'); + $merchantData->add('invoiceNumber', '54321'); + + $encoder = function ($input) { + $encoded = sprintf('%s.%s', $input, 'secret'); + return base64_encode($encoded); + }; + + $encrypted = $merchantData->toString($encoder); + + $decoder = function ($input) { + $decoded = explode('.', (string)base64_decode($input)); + $this->assertEquals('secret', $decoded[1]); + return $decoded[0]; + }; + + $decrypted = $merchantData->parse($encrypted, $decoder); + + $this->assertNotNull($decrypted); + $this->assertNotNull($decrypted->get('customerId')); + $this->assertEquals('12345', $decrypted->get('customerId')); + $this->assertNotNull($decrypted->get('invoiceNumber')); + $this->assertEquals('54321', $decrypted->get('invoiceNumber')); + } + + public function testMerchantDataMultiKey() + { + $this->expectExceptionMessage('Cannot access private property GlobalPayments\Api\Entities\MerchantDataCollection::$collection'); + + $mcd = new MerchantDataCollection(); + array_push($mcd->collection, array('amount'=>'10')); + array_push($mcd->collection, array('amount'=>'10')); + } + + public function testFullCycleWithMerchantData() + { + $card = new CreditCardData(); + $card->number = 4012001037141112; + $card->expMonth = 12; + $card->expYear = TestCards::validCardExpYear(); + $card->cardHolderName = 'John Smith'; + + $enrolled = $card->verifyEnrolled(1, 'USD'); + if ($enrolled) { + $secureEcom = $card->threeDSecure; + if (!empty($secureEcom)) { + $merchantData = new MerchantDataCollection(); + $merchantData->add('client_txn_id', '123456'); + + $authClient = new ThreeDSecureAcsClient($secureEcom->issuerAcsUrl); + $authResponse = $authClient->authenticate($secureEcom->payerAuthenticationRequest, (string)$secureEcom->getMerchantData()->toString()); + + $payerAuthenticationResponse = $authResponse->getAuthResponse(); + $md = MerchantDataCollection::parse($authResponse->getMerchantData()); + + if ($card->verifySignature($payerAuthenticationResponse, $md)) { + $response = $card->charge(1) + ->withCurrency('USD') + ->execute(); + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode); + } else { + $this->fail('Signature verification failed.'); + } + } else { + $this->fail('Secure3Data was null.'); + } + } else { + $this->fail('Card not enrolled.'); + } + } + + public function testFullCycleWithNoMerchantData() + { + $card = new CreditCardData(); + $card->number = 4012001037141112; + $card->expMonth = 12; + $card->expYear = TestCards::validCardExpYear(); + $card->cardHolderName = 'James Mason'; + + $amount = 100; + $currency = 'USD'; + $orderId = GenerationUtils::generateOrderId(); + + $enrolled = $card->verifyEnrolled($amount, $currency, $orderId); + + if ($enrolled) { + $secureEcom = $card->threeDSecure; + + if ($secureEcom != null) { + $authClient = new ThreeDSecureAcsClient($secureEcom->issuerAcsUrl); + $authResponse = $authClient->authenticate($secureEcom->payerAuthenticationRequest, (string)$secureEcom->getMerchantData()->toString()); + + $payerAuthenticationResponse = $authResponse->getAuthResponse(); + + if ($card->verifySignature($payerAuthenticationResponse, null, $amount, $currency, $orderId)) { + $response = $card->charge($amount) + ->withCurrency($currency) + ->withOrderId($orderId) + ->execute(); + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode); + } else { + $this->fail('Signature verification failed.'); + } + } else { + $this->fail('Secure3Data was null.'); + } + } else { + $this->fail('Card not enrolled.'); + } + } + + public function testVerifyEnrolledTrue() + { + $card = new CreditCardData(); + $card->number = 4012001037141112; + $card->expMonth = 12; + $card->expYear = TestCards::validCardExpYear(); + $card->cardHolderName = 'John Smith'; + + $enrolled = $card->verifyEnrolled(1, 'USD'); + $this->assertTrue($enrolled); + $this->assertNotNull($card->threeDSecure); + $this->assertNotNull($card->threeDSecure->payerAuthenticationRequest); + $this->assertNotNull($card->threeDSecure->issuerAcsUrl); + $this->assertNotNull($card->threeDSecure->xid); + } + + public function testVerifyEnrolledFalse() + { + $card = new CreditCardData(); + $card->number = 4012001038443335; + $card->expMonth = 12; + $card->expYear = TestCards::validCardExpYear(); + $card->cardHolderName = 'John Smith'; + + $enrolled = $card->verifyEnrolled(1, 'USD'); + $this->assertFalse($enrolled); + } + + /** + * @expectedException GlobalPayments\Api\Entities\Exceptions\GatewayException + */ + public function testVerifySignatureBadOrderId() + { + $card = new CreditCardData(); + $card->verifySignature('eNrVWNmyozqy/ZWK6kfHOcwYOly7Q8yDwWYe3jBgRjPbYL7+4r1r16muWx3RfZ/68oKUSKlU5sqVQod/LLf6yyMdxqJtvn1F/oS/fvnH28HOhzTlrDS+D+nbQUvHMcrSL0Xy7SuNIjEMX1L8iiX4FUcudEQjURzhOEHHaHL9+nY4AzMd3wcTCEbS2Cb6vsDbpv9P9AB9djfNQ5xHzfR2iOKekfU3fI8jNHWAvncPt3SQuTf6+3OAPvoH6K+J5/urNW5mLkXyVvi9feR6zi2AGBCUZax3S3EeCI1T3w7Qa8Qhiab0DYWRPYKg1BcU/jtM/h3DD9C7/NC91IFbe990IzB8gH4WHDZ/DGkTP98ofPv0o3dIl65t0m3Etrkf7QP0l21d1LzBPz3Itvime5MebP/tMBW339r0Lj+MUzTdx7fgAH1vHeLo8XgDALAM5nAuq6OAk/mToTv8DF7Pttf3IYc0Lt5gYjNqe7/PAnXWDsWU316m/rPgAL1Mgd7D93awiqzZFhvSLxtCmvHb13yaur9D0DzPf87Yn+2QQei2EQimoW1AMhbZ375+zEoTubm2/9E0NmrapoijulijaUOGlk55m3z5Ydvv1NjmSxMCmTz7x6bqjxjBmz9eEhhDiE0n9HulP+3s31nlV2OHMfpjzCPktcAvit4OZnpNX4hIvzim/O3r337gnyuydJz+L+t9rvWzhk99blTf07e0Cz2ekj38LKW5mBLXiiFuoZWxN/7b57yPkQfoh4Hfrf8I1U8u+RgYUzvuaUx4FwaJURWc56HH/Yq5TX6sxTUIH7Kxm3TLLCiuVcwIo9nqtl8jNXLXCCmXR6CecFdoVjhC4P0ss+gsd6d67xE6QiD56kCcejLFztTiiAvNZfLHeL1h887PuAlrHBgMsnZf9YZfoTItL9UYe9J5ARby8CUM707lwz+x+lUzLCrHSh492mJNPOddfW8pUpq5py89JfPspIjDqTKDUiiAz3qwq0CU5UKVeyQU3KNmSHust3NjQcmezBAvOSV5ztJ9m1H3heSvdSYxDya+QNxMqTNrQS52c1RdURkVO6pPBdtrqrYwNuqT5nWOWX7p67lbMl1rply2U6rhNPQWdh3/OCdC9u3bT5D5HhE1fX5EwCdgmoum6KPFpsNUXDfsbpSkyTIX2iwLKjQDs8yATHbBSZIUbSr2QSqRbBeaZo3T64pHXJVpABZZqxct+YJxBs+wswM0MVu4FehMprsM0GymZhRXoDnD5l2N0USAODy7aJpbKZ4rumsi6Ejkm7VmwDM7B5xrGCo/m57l6oxmUDNnvMskfg750CPQ0JcX3gbnD/2ZzfL64yLSz8AzH5oxzuzHeJGfFddZQSrM8KKX/KyVYNFKftU4IXrJTtw/yzQJLMIK3O92a9yNeFxu7jVG6+ZS02XoK7BmOjP/YeORA4tn1KET+jrsYG6XiM7C2eD4Mb/VGCFUHJj/yRexxlRmfWnCOi55UwPUhy82RxsoPV4wJQ9FamFXoHyMD2xQu/YWE0YuXzqqPq8KkZ5hBhi8AMCJBQYFXt/ZTN3aPChKJ7Rv9KCfnfwsk6PchIR1U8M48i5zEp0LledpSOG5tbi7ir4Hec0jitt7GL460igVzY4wc1uYey7SfdW1S5k/L3dU4wpyycNsiloIRW6sGtmr7z5Hx9Af7NgB04GanE0umIPQqSxX4ERiWA0/aPKiaiEGY8I9FxktVagm0Mie6yCHw0zfjq3LxbaOKSaxK38DNGlCZ93jqskK9hBDOHkn7oQtMXYZlOPpNT6Fij4n4qmushGzm77B7cezjM+7ihNvqLg/kVe85x2a7vlHGISCrRot3YaKedX2I3dUC0bCgTyeI0BwxaTsl5AQ+diwMtO3XMqWYsNjS3a98hg4ZtE09VLoE4bMAQMwv8M6wLccMYDT+2ITZSu+gxf3dO010B4bFRodi5D7MyPkHMTR/R4ttIZrBm+cqGZ25ztSHsnlKktetpZ+kZQQEWiwaIrHliUSnofTEtu7nrwGbTBZZ4PjvAc7AEdr54WOWa9iNY0M66TH97tThmDoxh3skCgCz9Rk3lQMBJMeWyyqBS+RzUNkzN5dLC6eOtOi7JTRftNTUB92CUEw+ykOUpg44rf5stc78xgaa+pvEUSlNnpk5vV5PnYpSybdIg0R2en6rBaDDldX/o6wyLnMhqeHb4nBqWo3BpBYXMM6ijGrTNR85tNZvndnZfSMUJ661BokqlB8wgn5dKKQnWW70fRgm+xcuPpj5z32i3yAfmWn39EVL77oahY/6coExyCmt6DtJ2uxyULc8bfi5jovGlHUNpTzR6xvqXJkDDBvXjlqoHpPQybXWNfVfk5he0vhLkb55biC6UM22kr9Lsssj4A3SrgHvtldUCK/sIy99dHI02uZF9YYpcvIE+DIo++a2c4ieKcNjl8EL/L1XBbd8oIi0zanDC3GNOxPqgKEZldPjdNWnUteVPXU142mbH7WOQ1/yf67KHbzvyX/6l9m8y+XZfwZcNt3o2W3NgPUIQkhwylnnFurfSUQjR3uT0F/q5A9luGXR4abO1XCkXVa49m562eyHcZdOMYoZAlb4UO1qzYjp/mMboUvz+mWSpjc3SttyjtuTM+lDnsSye2mHkiXErai/pT3OUPdoTqqLXqRLt3jWUE8sYqlaJ/mdisAst9VKXW3SNS+E5KqMuLyyENIscH9mjCPI1bsHK2/Vrq9+AGvAjWBpYKUpOFxqup+5rcDzCh3+BoOXcBB5j3h8MGQxNm3DDiiGH0x1uet9cq2OI2aKwdqhjxqQw5nGh902m0uk9nCCTLUY9wBviX16pwwaCDeOE8O9/N8IUeB2xtCKyqJTflFxUjxxJHnMKWSBuumccM/D0B0Yh4cy9xtYL3iJpkaA64Uz3JABIYEgYwHmmS8sJHIwJw0cZwjIxBCnN/o7VXUQMlk2cBkvMAYMQvMwI8kE465dnNBgiVPAn3h9njbsGDRc4RW88kIZHUOtlg70pZ789EGgZALVugzY/DKA8FsI1/LNgziCQe4zQZG/NffT+92G9S73RuuN9wEs/TCmgmfGCbgBa3N0gqUocDEcgae1dWyIGXbqsIM/5qe2WHkCoDGO2+4IfaOtwlYT0Qa5baiUVQqUoxrz86GhAfpg0jKGXaZx55mE+s5DZqT5VAMp1CwIreOQ9aTrJ/Twm0Jq6kRpnzeK80g+RatfRPLhI0s2fUcjK2Otv5kzWJMFRpwpko25QwJUeqIybfWlfbxObYLz8yHgQLtXXa286SQdeOz3ThRkjpYs28rzt99Uh/ZbvcEnKIE2DASLCjtZ60FhokpIwm4wd5nz9MsXdHpURzVZkJYS5KeO4IlnzgVnfir0t72NjhleF3WVWUKJ5XzHCeuEYWppCldnGML+SHiyrhvHlMVjdUwInN/7ypLpTPwkXEG6ITjxf6xE0MvszWxo9SSX/5NehbKLf0f5Cc9G+l0Ryxt6RpeB01zWpHz7jzZv55uHAFwTPe/qYbXNTB+0Fuu8e6tXgObf2gs/El5t3eZxSiXxqzjG5EnYr2d4oRRFvQ6bsIuQJ3M8PX1gurdB3Xji1iC4JNKefeD3kNvg7mHbDpeMBUYjcF9zn6dFPntxAhWbY3hk9tuMu1X2X9ZWfkP6FmvnGut3rqGQKdAxsKJ0c/eOcBHXFUaSHK9WOB2lltEJ4fxckpMn8n9okMtO4vyVF3V5WEVnGnerCvryArTw17NG9g9BscLxOzk02DORlaMPXbRYTk8ghheJbl7ev79FrXVuB8j88GNEToPlxXiJ6SvNLiEWgl6nIat7KkSrdBEX7E9vpWNkY+fRKPOV67qBPTaVuEEO6oqTIsrxRZ/tnhk1XVkQ/Fi6d3+0fnP5XG0Rhbyk4ES9zaboRfkufieUA5nGLlvMOUbRbWbUMZZ1EnzeSk3NmWv1mhDQHwsXH71zsPAT4C02Zijh1NHc93s64WliOe1ih3Hu0rbb4Cf0WmQFTbf0ige/6Dnu80yU/lRVj/pmbE3Wtzo+f89NTMLJT2jxABejTP3113Rsv0lCnolr79S82bTJzWniIjm5xGAndnqLRy7DbKz05iygsRggLDv2eZIC2ke3fF9ipFXV9SL9VQ9ZZsGktgOpIkc5ShX/R1P3nrDDsa1USwi9xVKpGL4DN+W0rXiy/5ZzQYxM0Hvexp68dWuONpp4HpXBAyC13fIkxZJEwanqDmWt1k3GTBkzwdZI0Z42Tsaxlxpi6jh+yBoR3gDCsXs6bpOCR9D5QddXu/xnYwjeWCO1dlayKDf9VvxHXFKN62TvoPO/Y2WlhmRMOi5ov1RxFdb3i+Ky/FWKPJ+lBxnVvE58mSmPipAzOQkVI9iSemHFzco5CtPp5cBzzCEQJnaZaUQFZ/npMzl+zGVUMS92FDy5CUJ/Iaaob/++aEf9wB/3RC833K+X7y+buZ+vpD9HwzDHH8=', null, 1, 'USD', 'orderId'); + } + + /** + * @expectedException GlobalPayments\Api\Entities\Exceptions\BuilderException + */ + public function testVerifySignatureNoPaymentResponse() + { + $card = new CreditCardData(); + $card->verifySignature(null); + } + + /** + * @expectedException GlobalPayments\Api\Entities\Exceptions\BuilderException + */ + public function testVerifySignatureNoAmount() + { + $card = new CreditCardData(); + $card->verifySignature('paymentResponse', null, null, 'USD', 'orderId'); + } + + /** + * @expectedException GlobalPayments\Api\Entities\Exceptions\BuilderException + */ + public function testVerifySignatureNoCurrency() + { + $card = new CreditCardData(); + $card->verifySignature('paymentResponse', null, 10, null, 'orderId'); + } + + /** + * @expectedException GlobalPayments\Api\Entities\Exceptions\BuilderException + */ + public function testVerifySignatureNoOrderId() + { + $card = new CreditCardData(); + $card->verifySignature('paymentResponse', null, 10, 'USD', null); + } + + public function testAuthorize3dSecure() + { + $secureEcom = new ThreeDSecure(); + $secureEcom->cavv = 'AAACBllleHchZTBWIGV4AAAAAAA='; + $secureEcom->xid = 'crqAeMwkEL9r4POdxpByWJ1/wYg='; + $secureEcom->eci = '5'; + + $card = new CreditCardData(); + $card->number = 4012001037141112; + $card->expMonth = 12; + $card->expYear = TestCards::validCardExpYear(); + $card->cardHolderName = 'Philip Marlowe'; + $card->threeDSecure = $secureEcom; + + $response = $card->charge(10) + ->withCurrency('EUR') + ->execute(); + + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode); + } + + public function testCardHolderNotEnrolled() + { + $card = new CreditCardData(); + $card->number = 4012001038443335; + $card->expMonth = 12; + $card->expYear = TestCards::validCardExpYear(); + $card->cardHolderName = 'John Smith'; + + $enrolled = $card->verifyEnrolled(10, 'USD'); + $this->assertFalse($enrolled); + $this->assertNotNull($card->threeDSecure); + $this->assertEquals('6', $card->threeDSecure->eci); + + // .net test does not have amount or currency but validation would not allow this + $response = $card->charge(10) + ->withCurrency('USD') + ->execute(); + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode); + } + + public function testUnableToVerifyEnrollment() + { + $card = new CreditCardData(); + $card->number = 4012001038488884; + $card->expMonth = 12; + $card->expYear = TestCards::validCardExpYear(); + $card->cardHolderName = 'John Smith'; + + $enrolled = $card->verifyEnrolled(10, 'USD'); + $this->assertFalse($enrolled); + $this->assertNotNull($card->threeDSecure); + $this->assertEquals('7', $card->threeDSecure->eci); + + $response = $card->charge(10) + ->withCurrency('USD') + ->execute(); + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode); + } + + /** + * @expectedException GlobalPayments\Api\Entities\Exceptions\GatewayException + */ + public function testInvalidResponseFromEnrollmentServer() + { + $card = new CreditCardData(); + $card->number = 4012001036298889; + $card->expMonth = 12; + $card->expYear = TestCards::validCardExpYear(); + $card->cardHolderName = 'John Smith'; + + $card->verifyEnrolled(10, 'USD'); + } + + public function testCardHolderIsEnrolledACSAuthFailed() + { + $card = new CreditCardData(); + $card->number = 4012001036853337; + $card->expMonth = 12; + $card->expYear = TestCards::validCardExpYear(); + $card->cardHolderName = 'John Smith'; + + $enrolled = $card->verifyEnrolled(10, 'USD'); + $this->assertTrue($enrolled); + + $secureEcom = $card->threeDSecure; + $authClient = new ThreeDSecureAcsClient($secureEcom->issuerAcsUrl); + $authResponse = $authClient->authenticate($secureEcom->payerAuthenticationRequest, $secureEcom->getMerchantData()->toString()); + + // $payerAuthenticationResponse = $authResponse->parse(); + $payerAuthenticationResponse = $authResponse->getAuthResponse(); + $md = MerchantDataCollection::parse($authResponse->getMerchantData()); + + $verified = $card->verifySignature($payerAuthenticationResponse, $md); + $this->assertFalse($verified); + $this->assertNotNull($card->threeDSecure); + $this->assertEquals(7, $card->threeDSecure->eci); + + $response = $card->charge(10) + ->withCurrency('USD') + ->execute(); + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode); + } + + public function testCardHolderIsEnrolledACSAcknowledged() + { + $card = new CreditCardData(); + $card->number = 4012001037167778; + $card->expMonth = 12; + $card->expYear = TestCards::validCardExpYear(); + $card->cardHolderName = 'John Smith'; + + $enrolled = $card->verifyEnrolled(10, 'USD'); + $this->assertTrue($enrolled); + + $secureEcom = $card->threeDSecure; + $authClient = new ThreeDSecureAcsClient($secureEcom->issuerAcsUrl); + $authResponse = $authClient->authenticate($secureEcom->payerAuthenticationRequest, $secureEcom->getMerchantData()->toString()); + + // $payerAuthenticationResponse = $authResponse->parse(); + $payerAuthenticationResponse = $authResponse->getAuthResponse(); + $md = MerchantDataCollection::parse($authResponse->getMerchantData()); + + $verified = $card->verifySignature($payerAuthenticationResponse, $md); + $this->assertTrue($verified); + $this->assertEquals('A', $card->threeDSecure->status); + + $response = $card->charge(10) + ->withCurrency('USD') + ->execute(); + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode); + } + + public function testCardHolderIsEnrolledACSFailed() + { + $card = new CreditCardData(); + $card->number = 4012001037461114; + $card->expMonth = 12; + $card->expYear = TestCards::validCardExpYear(); + $card->cardHolderName = 'John Smith'; + + $enrolled = $card->verifyEnrolled(10, 'USD'); + $this->assertTrue($enrolled); + + $secureEcom = $card->threeDSecure; + $authClient = new ThreeDSecureAcsClient($secureEcom->issuerAcsUrl); + $authResponse = $authClient->authenticate($secureEcom->payerAuthenticationRequest, $secureEcom->getMerchantData()->toString()); + + // $payerAuthenticationResponse = $authResponse->parse(); + $payerAuthenticationResponse = $authResponse->getAuthResponse(); + $md = MerchantDataCollection::parse($authResponse->getMerchantData()); + + $verified = $card->verifySignature($payerAuthenticationResponse, $md); + $this->assertFalse($verified); + $this->assertEquals('N', $card->threeDSecure->status); + $this->assertEquals(7, $card->threeDSecure->eci); + + $response = $card->charge(10) + ->withCurrency('USD') + ->execute(); + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode); + } + + public function testCardHolderIsEnrolledACSUnavailable() + { + $card = new CreditCardData(); + $card->number = 4012001037484447; + $card->expMonth = 12; + $card->expYear = TestCards::validCardExpYear(); + $card->cardHolderName = 'John Smith'; + + $enrolled = $card->verifyEnrolled(10, 'USD'); + $this->assertTrue($enrolled); + + $secureEcom = $card->threeDSecure; + $authClient = new ThreeDSecureAcsClient($secureEcom->issuerAcsUrl); + $authResponse = $authClient->authenticate($secureEcom->payerAuthenticationRequest, $secureEcom->getMerchantData()->toString()); + + $payerAuthenticationResponse = $authResponse->getAuthResponse(); + $md = MerchantDataCollection::parse($authResponse->getMerchantData()); + + $verified = $card->verifySignature($payerAuthenticationResponse, $md); + $this->assertFalse($verified); + $this->assertEquals('U', $card->threeDSecure->status); + $this->assertEquals(7, $card->threeDSecure->eci); + + $response = $card->charge(10) + ->withCurrency('USD') + ->execute(); + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode); + } + + /** + * @expectedException GlobalPayments\Api\Entities\Exceptions\GatewayException + */ + public function testCardHolderIsEnrolledACSInvalid() + { + $card = new CreditCardData(); + $card->number = 4012001037490006; + $card->expMonth = 12; + $card->expYear = TestCards::validCardExpYear(); + $card->cardHolderName = 'John Smith'; + + $enrolled = $card->verifyEnrolled(10, 'USD'); + $this->assertTrue($enrolled); + + $secureEcom = $card->threeDSecure; + $authClient = new ThreeDSecureAcsClient($secureEcom->issuerAcsUrl); + $authResponse = $authClient->authenticate($secureEcom->payerAuthenticationRequest, $secureEcom->getMerchantData()->toString()); + + $payerAuthenticationResponse = $authResponse->getAuthResponse(); + $md = MerchantDataCollection::parse($authResponse->getMerchantData()); + + $card->verifySignature($payerAuthenticationResponse, $md); + } +} diff --git a/test/Integration/Gateways/RealexConnector/RealexApmTest.php b/test/Integration/Gateways/RealexConnector/RealexApmTest.php index e52db0c5..67755dd0 100644 --- a/test/Integration/Gateways/RealexConnector/RealexApmTest.php +++ b/test/Integration/Gateways/RealexConnector/RealexApmTest.php @@ -1,191 +1,191 @@ -merchantId = "heartlandgpsandbox"; - $config->accountId = "hpp"; - $config->rebatePassword = 'refund'; - $config->refundPassword = 'refund'; - $config->sharedSecret = "secret"; - $config->serviceUrl = "https://api.sandbox.realexpayments.com/epage-remote.cgi"; - return $config; - } - - public function setup() - { - ServicesContainer::configureService($this->config()); - } - - public function testApmForCharge() - { - $paymentMethod = new AlternativePaymentMethod(AlternativePaymentType::SOFORTUBERWEISUNG); - - $paymentMethod->returnUrl = 'https://www.example.com/returnUrl'; - $paymentMethod->statusUpdateUrl = 'https://www.example.com/statusUrl'; - $paymentMethod->descriptor = 'Test Transaction'; - $paymentMethod->country = 'DE'; - $paymentMethod->accountHolderName = 'James Mason'; - - $response = $paymentMethod->charge(10) - ->withCurrency("EUR") - ->withDescription('New APM') - ->execute(); - - $responseCode = $response->responseCode; // 00 == Success - $message = $response->responseMessage; // [ test system ] AUTHORISED - // get the reponse details to save to the DB for future transaction management requests - $orderId = $response->orderId; - $authCode = $response->authorizationCode; - $paymentsReference = $response->transactionId; // pasref - $apmResponse = $response->alternativePaymentResponse; - - $this->assertNotNull($response); - $this->assertEquals("01", $response->responseCode); - $this->assertNotNull($response->alternativePaymentResponse); - } - - /** - * @expectedException \GlobalPayments\Api\Entities\Exceptions\BuilderException - * @expectedExceptionMessage amount cannot be null for this transaction type - */ - public function testApmWithoutAmount() - { - $paymentMethod = new AlternativePaymentMethod(AlternativePaymentType::SOFORTUBERWEISUNG); - - $paymentMethod->returnUrl = 'https://www.example.com/returnUrl'; - $paymentMethod->statusUpdateUrl = 'https://www.example.com/statusUrl'; - $paymentMethod->descriptor = 'Test Transaction'; - $paymentMethod->country = 'DE'; - $paymentMethod->accountHolderName = 'James Mason'; - - $response = $paymentMethod->charge() - ->withCurrency("EUR") - ->withDescription('New APM') - ->execute(); - } - - /** - * @expectedException \GlobalPayments\Api\Entities\Exceptions\BuilderException - * @expectedExceptionMessage currency cannot be null for this transaction type - */ - public function testApmWithoutCurrency() - { - $paymentMethod = new AlternativePaymentMethod(AlternativePaymentType::SOFORTUBERWEISUNG); - - $paymentMethod->returnUrl = 'https://www.example.com/returnUrl'; - $paymentMethod->statusUpdateUrl = 'https://www.example.com/statusUrl'; - $paymentMethod->descriptor = 'Test Transaction'; - $paymentMethod->country = 'DE'; - $paymentMethod->accountHolderName = 'James Mason'; - - $response = $paymentMethod->charge(10) - ->withDescription('New APM') - ->execute(); - } - - /** - * @expectedException \GlobalPayments\Api\Entities\Exceptions\BuilderException - * @expectedExceptionMessage returnUrl cannot be null for this transaction type - */ - public function testApmWithoutReturnUrl() - { - $paymentMethod = new AlternativePaymentMethod(AlternativePaymentType::SOFORTUBERWEISUNG); - - $paymentMethod->statusUpdateUrl = 'https://www.example.com/statusUrl'; - $paymentMethod->descriptor = 'Test Transaction'; - $paymentMethod->country = 'DE'; - $paymentMethod->accountHolderName = 'James Mason'; - - $response = $paymentMethod->charge(1001) - ->withCurrency("EUR") - ->withDescription('New APM') - ->execute(); - } - - /** - * @expectedException \GlobalPayments\Api\Entities\Exceptions\BuilderException - * @expectedExceptionMessage statusUpdateUrl cannot be null for this transaction type - */ - public function testApmWithoutstatusUpdateUrl() - { - $paymentMethod = new AlternativePaymentMethod(AlternativePaymentType::SOFORTUBERWEISUNG); - - $paymentMethod->returnUrl = 'https://www.example.com/returnUrl'; - $paymentMethod->descriptor = 'Test Transaction'; - $paymentMethod->country = 'DE'; - $paymentMethod->accountHolderName = 'James Mason'; - - $response = $paymentMethod->charge(1001) - ->withCurrency("EUR") - ->withDescription('New APM') - ->execute(); - } - - /** - * @expectedException \GlobalPayments\Api\Entities\Exceptions\GatewayException - * @expectedExceptionMessage FAILED - */ - public function testAPMRefundPendingTransaction() - { - $paymentMethod = new AlternativePaymentMethod(AlternativePaymentType::TEST_PAY); - - $paymentMethod->returnUrl = 'https://www.example.com/returnUrl'; - $paymentMethod->statusUpdateUrl = 'https://www.example.com/statusUrl'; - $paymentMethod->descriptor = 'Test Transaction'; - $paymentMethod->country = 'DE'; - $paymentMethod->accountHolderName = 'James Mason'; - - $response = $paymentMethod->charge(10) - ->withCurrency("EUR") - ->withDescription('New APM') - ->execute(); - - $this->assertNotEquals(null, $response); - $this->assertEquals("01", $response->responseCode); - - // send the settle request, we must specify the amount and currency - $response = $response->refund(10) - ->withCurrency("EUR") - ->withAlternativePaymentType(AlternativePaymentType::TEST_PAY) - ->execute(); - } - - public function testApmForRefund() - { - // a settle request requires the original order id - $orderId = "20180912050207-5b989dcfc9433"; - // and the payments reference (pasref) from the authorization response - $paymentsReference = "15367285279651634"; - // and the auth code transaction response - $authCode = "12345"; - - // create the rebate transaction object - $transaction = Transaction::fromId($paymentsReference, $orderId); - $transaction->authorizationCode = $authCode; - - // send the settle request, we must specify the amount and currency - $response = $transaction->refund(10) - ->withCurrency("EUR") - ->withAlternativePaymentType(AlternativePaymentType::TEST_PAY) - ->execute(); - - $responseCode = $response->responseCode; // 00 == Success - $message = $response->responseMessage; // [ test system ] AUTHORISED - - $this->assertNotEquals(null, $response); - $this->assertEquals("00", $responseCode); - } -} +merchantId = "heartlandgpsandbox"; + $config->accountId = "hpp"; + $config->rebatePassword = 'refund'; + $config->refundPassword = 'refund'; + $config->sharedSecret = "secret"; + $config->serviceUrl = "https://api.sandbox.realexpayments.com/epage-remote.cgi"; + return $config; + } + + public function setup() + { + ServicesContainer::configureService($this->config()); + } + + public function testApmForCharge() + { + $paymentMethod = new AlternativePaymentMethod(AlternativePaymentType::SOFORTUBERWEISUNG); + + $paymentMethod->returnUrl = 'https://www.example.com/returnUrl'; + $paymentMethod->statusUpdateUrl = 'https://www.example.com/statusUrl'; + $paymentMethod->descriptor = 'Test Transaction'; + $paymentMethod->country = 'DE'; + $paymentMethod->accountHolderName = 'James Mason'; + + $response = $paymentMethod->charge(10) + ->withCurrency("EUR") + ->withDescription('New APM') + ->execute(); + + $responseCode = $response->responseCode; // 00 == Success + $message = $response->responseMessage; // [ test system ] AUTHORISED + // get the reponse details to save to the DB for future transaction management requests + $orderId = $response->orderId; + $authCode = $response->authorizationCode; + $paymentsReference = $response->transactionId; // pasref + $apmResponse = $response->alternativePaymentResponse; + + $this->assertNotNull($response); + $this->assertEquals("01", $response->responseCode); + $this->assertNotNull($response->alternativePaymentResponse); + } + + /** + * @expectedException \GlobalPayments\Api\Entities\Exceptions\BuilderException + * @expectedExceptionMessage amount cannot be null for this transaction type + */ + public function testApmWithoutAmount() + { + $paymentMethod = new AlternativePaymentMethod(AlternativePaymentType::SOFORTUBERWEISUNG); + + $paymentMethod->returnUrl = 'https://www.example.com/returnUrl'; + $paymentMethod->statusUpdateUrl = 'https://www.example.com/statusUrl'; + $paymentMethod->descriptor = 'Test Transaction'; + $paymentMethod->country = 'DE'; + $paymentMethod->accountHolderName = 'James Mason'; + + $response = $paymentMethod->charge() + ->withCurrency("EUR") + ->withDescription('New APM') + ->execute(); + } + + /** + * @expectedException \GlobalPayments\Api\Entities\Exceptions\BuilderException + * @expectedExceptionMessage currency cannot be null for this transaction type + */ + public function testApmWithoutCurrency() + { + $paymentMethod = new AlternativePaymentMethod(AlternativePaymentType::SOFORTUBERWEISUNG); + + $paymentMethod->returnUrl = 'https://www.example.com/returnUrl'; + $paymentMethod->statusUpdateUrl = 'https://www.example.com/statusUrl'; + $paymentMethod->descriptor = 'Test Transaction'; + $paymentMethod->country = 'DE'; + $paymentMethod->accountHolderName = 'James Mason'; + + $response = $paymentMethod->charge(10) + ->withDescription('New APM') + ->execute(); + } + + /** + * @expectedException \GlobalPayments\Api\Entities\Exceptions\BuilderException + * @expectedExceptionMessage returnUrl cannot be null for this transaction type + */ + public function testApmWithoutReturnUrl() + { + $paymentMethod = new AlternativePaymentMethod(AlternativePaymentType::SOFORTUBERWEISUNG); + + $paymentMethod->statusUpdateUrl = 'https://www.example.com/statusUrl'; + $paymentMethod->descriptor = 'Test Transaction'; + $paymentMethod->country = 'DE'; + $paymentMethod->accountHolderName = 'James Mason'; + + $response = $paymentMethod->charge(1001) + ->withCurrency("EUR") + ->withDescription('New APM') + ->execute(); + } + + /** + * @expectedException \GlobalPayments\Api\Entities\Exceptions\BuilderException + * @expectedExceptionMessage statusUpdateUrl cannot be null for this transaction type + */ + public function testApmWithoutstatusUpdateUrl() + { + $paymentMethod = new AlternativePaymentMethod(AlternativePaymentType::SOFORTUBERWEISUNG); + + $paymentMethod->returnUrl = 'https://www.example.com/returnUrl'; + $paymentMethod->descriptor = 'Test Transaction'; + $paymentMethod->country = 'DE'; + $paymentMethod->accountHolderName = 'James Mason'; + + $response = $paymentMethod->charge(1001) + ->withCurrency("EUR") + ->withDescription('New APM') + ->execute(); + } + + /** + * @expectedException \GlobalPayments\Api\Entities\Exceptions\GatewayException + * @expectedExceptionMessage FAILED + */ + public function testAPMRefundPendingTransaction() + { + $paymentMethod = new AlternativePaymentMethod(AlternativePaymentType::TEST_PAY); + + $paymentMethod->returnUrl = 'https://www.example.com/returnUrl'; + $paymentMethod->statusUpdateUrl = 'https://www.example.com/statusUrl'; + $paymentMethod->descriptor = 'Test Transaction'; + $paymentMethod->country = 'DE'; + $paymentMethod->accountHolderName = 'James Mason'; + + $response = $paymentMethod->charge(10) + ->withCurrency("EUR") + ->withDescription('New APM') + ->execute(); + + $this->assertNotEquals(null, $response); + $this->assertEquals("01", $response->responseCode); + + // send the settle request, we must specify the amount and currency + $response = $response->refund(10) + ->withCurrency("EUR") + ->withAlternativePaymentType(AlternativePaymentType::TEST_PAY) + ->execute(); + } + + public function testApmForRefund() + { + // a settle request requires the original order id + $orderId = "20180912050207-5b989dcfc9433"; + // and the payments reference (pasref) from the authorization response + $paymentsReference = "15367285279651634"; + // and the auth code transaction response + $authCode = "12345"; + + // create the rebate transaction object + $transaction = Transaction::fromId($paymentsReference, $orderId); + $transaction->authorizationCode = $authCode; + + // send the settle request, we must specify the amount and currency + $response = $transaction->refund(10) + ->withCurrency("EUR") + ->withAlternativePaymentType(AlternativePaymentType::TEST_PAY) + ->execute(); + + $responseCode = $response->responseCode; // 00 == Success + $message = $response->responseMessage; // [ test system ] AUTHORISED + + $this->assertNotEquals(null, $response); + $this->assertEquals("00", $responseCode); + } +} diff --git a/test/Integration/Gateways/RealexConnector/RecurringTest.php b/test/Integration/Gateways/RealexConnector/RecurringTest.php index f7b6c914..357cc2e5 100644 --- a/test/Integration/Gateways/RealexConnector/RecurringTest.php +++ b/test/Integration/Gateways/RealexConnector/RecurringTest.php @@ -1,391 +1,391 @@ -format("Ymd")); - } - - public function getPaymentId($type) - { - return sprintf("%s-Realex-%s", (new \DateTime())->format("Ymd"), $type); - } - - protected function config() - { - $config = new GpEcomConfig(); - $config->merchantId = "heartlandgpsandbox"; - $config->accountId = "3dsecure"; - $config->refundPassword = "refund"; - $config->sharedSecret = "secret"; - $config->serviceUrl = "https://api.sandbox.realexpayments.com/epage-remote.cgi"; - return $config; - } - - protected function dccSetup() - { - $config = new GpEcomConfig(); - $config->merchantId = "heartlandgpsandbox"; - $config->accountId = "apidcc"; - $config->refundPassword = "refund"; - $config->sharedSecret = "secret"; - $config->serviceUrl = "https://api.sandbox.realexpayments.com/epage-remote.cgi"; - - ServicesContainer::configureService($config); - } - - public function setup() - { - ServicesContainer::configureService($this->config()); - - $this->newCustomer = new Customer(); - $this->newCustomer->key = $this->getCustomerId(); - $this->newCustomer->title = "Mr."; - $this->newCustomer->firstName = "James"; - $this->newCustomer->lastName = "Mason"; - $this->newCustomer->company = "Realex Payments"; - $this->newCustomer->address = new Address(); - $this->newCustomer->address->streetAddress1 = "Flat 123"; - $this->newCustomer->address->streetAddress2 = "House 456"; - $this->newCustomer->address->streetAddress3 = "The Cul-De-Sac"; - $this->newCustomer->address->city = "Halifax"; - $this->newCustomer->address->province = "West Yorkshire"; - $this->newCustomer->address->pstalCode = "W6 9HR"; - $this->newCustomer->address->country = "United Kingdom"; - $this->newCustomer->homePhone = "+35312345678"; - $this->newCustomer->workPhone = "+3531987654321"; - $this->newCustomer->fax = "+124546871258"; - $this->newCustomer->mobilePhone = "+25544778544"; - $this->newCustomer->email = "text@example.com"; - $this->newCustomer->comments = "Campaign Ref E7373G"; - } - - /* 08. Card Storage Create Payer */ - /* Request Type: payer-new */ - - public function testcardStorageCreatePayer() - { - try { - $response = $this->newCustomer->Create(); - $this->assertNotNull($response); - $this->assertEquals("00", $response->responseCode); - } catch (GatewayException $exc) { - if ($exc->responseCode != '501' && $exc->responseCode != '520') { - throw $exc; - } - } - } - - /* 09. Card Storage Store Card */ - /* Request Type: card-new */ - - public function testcardStorageStoreCard() - { - $card = new CreditCardData(); - $card->number = "4012001037141112"; - $card->expMonth = 10; - $card->expYear = TestCards::validCardExpYear(); - $card->cvn = '123'; - $card->cardHolderName = 'James Mason'; - - try { - $paymentMethod = $this->newCustomer - ->addPaymentMethod($this->getPaymentId("Credit"), $card) - ->create(); - $this->assertNotNull($paymentMethod); - } catch (GatewayException $exc) { - if ($exc->responseCode != '501' && $exc->responseCode != '520') { - throw $exc; - } - } - } - - /* 10. Card Storage Charge Card */ - /* Request Type: receipt-in */ - - public function testcardStorageChargeCard() - { - $paymentMethod = new RecurringPaymentMethod($this->getCustomerId(), $this->getPaymentId("Credit")); - $response = $paymentMethod->charge(10) - ->withCurrency("EUR") - ->withCvn("123") - ->execute(); - - $responseCode = $response->responseCode; // 00 == Success - $message = $response->responseMessage; // [ test system ] AUTHORISED - // get the reponse details to save to the DB for future transaction management requests - $orderId = $response->orderId; - $authCode = $response->authorizationCode; - $paymentsReference = $response->transactionId; // pasref - - $this->assertNotNull($response); - $this->assertEquals("00", $response->responseCode); - } - - /* 11. CardStorage ThreeDSecure Verify Enrolled */ - /* Request Type: realvault-3ds-verifyenrolled */ - - public function testcardStorageThreeDSecureVerifyEnrolled() - { - $paymentMethod = new RecurringPaymentMethod($this->getCustomerId(), $this->getPaymentId("Credit")); - - $response = $paymentMethod->verify() - ->withAmount(10) - ->withCurrency('USD') - ->withModifier(TransactionModifier::SECURE3D) - ->execute(); - - // get the response details to update the DB - $responseCode = $response->responseCode; // 00 == Success - $message = $response->responseMessage; // [ test system ] AUTHORISED - - $this->assertNotNull($response); - $this->assertEquals("00", $response->responseCode); - } - - /* 12. CardStorage Dcc Rate Lookup */ - /* Request Type: realvault-dccrate */ - - public function testcardStorageDccRateLookup() - { - $this->dccSetup(); - - $orderId = GenerationUtils::generateOrderId(); - $paymentMethod = new RecurringPaymentMethod($this->getCustomerId(), $this->getPaymentId("Credit")); - $dccDetails = $paymentMethod->getDccRate(DccRateType::SALE, 1001, 'EUR', DccProcessor::FEXCO, $orderId); - - $this->assertNotNull($dccDetails); - $this->assertEquals('00', $dccDetails->responseCode, $dccDetails->responseMessage); - $this->assertNotNull($dccDetails->dccResponseResult); - } - - /* 14. CardStorage UpdatePayer */ - /* Request Type: payer-edit */ - - public function testcardStorageUpdatePayer() - { - $customer = new Customer(); - $customer->key = $this->getCustomerId(); - $customer->firstName = "Perry"; - - $response = $customer->saveChanges(); - - $this->assertNotNull($response); - $this->assertEquals("00", $response->responseCode); - } - - /* 15. CardStorage Continuous Authority First */ - /* Request Type: auth */ - - public function testContinuousAuthorityFirst() - { - // create the card object - $card = new CreditCardData(); - $card->number = '5425230000004415'; - $card->expMonth = 12; - $card->expYear = TestCards::validCardExpYear(); - $card->cvn = '131'; - $card->cardHolderName = 'James Mason'; - - - // process an auto-settle authorization - $response = $card->charge(15) - ->withCurrency("EUR") - ->withRecurringInfo(RecurringType::VARIABLE, RecurringSequence::FIRST) - ->execute(); - - $responseCode = $response->responseCode; // 00 == Success - $message = $response->responseMessage; // [ test system ] AUTHORISED - // get the details to save to the DB for future Transaction Management requests - $orderId = $response->orderId; - $authCode = $response->authorizationCode; - $paymentsReference = $response->transactionId; - - $this->assertNotEquals(null, $response); - $this->assertEquals("00", $responseCode); - } - - /* 15. CardStorage Continuous Authority Subsequent */ - /* Request Type: receipt-in */ - - public function testContinuousAuthoritySubsequent() - { - // create the payment method object - $paymentMethod = new RecurringPaymentMethod($this->getCustomerId(), $this->getPaymentId("Credit")); - - // charge the stored card/payment method - $response = $paymentMethod->charge(15) - ->withCurrency("EUR") - ->withCvn("123") - ->withRecurringInfo(RecurringType::VARIABLE, RecurringSequence::SUBSEQUENT) - ->execute(); - - $responseCode = $response->responseCode; // 00 == Success - - $this->assertNotEquals(null, $response); - $this->assertEquals("00", $responseCode); - } - - /* 15. CardStorage Continuous Authority Last */ - /* Request Type: receipt-in */ - - public function testContinuousAuthorityLast() - { - // create the payment method object - $paymentMethod = new RecurringPaymentMethod($this->getCustomerId(), $this->getPaymentId("Credit")); - - // charge the stored card/payment method - $response = $paymentMethod->charge(15) - ->withCurrency("EUR") - ->withCvn("123") - ->withRecurringInfo(RecurringType::VARIABLE, RecurringSequence::LAST) - ->execute(); - - $responseCode = $response->responseCode; // 00 == Success - - $this->assertNotEquals(null, $response); - $this->assertEquals("00", $responseCode); - } - - /* 16. Card Storage Refund */ - /* Request Type: payment-out */ - - public function testcardStorageRefund() - { - // create the payment method object - $paymentMethod = new RecurringPaymentMethod($this->getCustomerId(), $this->getPaymentId("Credit")); - - // charge the stored card/payment method - $response = $paymentMethod->refund(10) - ->withCurrency("EUR") - ->execute(); - - $responseCode = $response->responseCode; // 00 == Success - $message = $response->responseMessage; // [ test system ] AUTHORISED - - $this->assertNotEquals(null, $response); - $this->assertEquals("00", $responseCode); - } - - /* 17. Card Storage UpdateCard */ - /* Request Type: card-update-card */ - - public function testcardStorageUpdateCard() - { - $paymentMethod = new RecurringPaymentMethod($this->getCustomerId(), $this->getPaymentId("Credit")); - - $paymentMethod->paymentMethod = new CreditCardData(); - $paymentMethod->paymentMethod->number = "5425230000004415"; - $paymentMethod->paymentMethod->expMonth = 10; - $paymentMethod->paymentMethod->expYear = TestCards::validCardExpYear(); - $paymentMethod->paymentMethod->cardHolderName = "Philip Marlowe"; - - $response = $paymentMethod->SaveChanges(); - - $this->assertNotNull($response); - $this->assertEquals("00", $response->responseCode); - } - - /* 18. Card Storage Verify Card */ - /* Request Type: receipt-in-otb */ - - public function testcardStorageVerifyCard() - { - $paymentMethod = new RecurringPaymentMethod($this->getCustomerId(), $this->getPaymentId("Credit")); - - // verify the stored card/payment method is valid and active - $response = $paymentMethod->verify() - ->withCvn("123") - ->execute(); - - // get the response details to update the DB - $responseCode = $response->responseCode; // 00 == Success - $message = $response->responseMessage; // [ test system ] AUTHORISED - - $this->assertNotEquals(null, $response); - $this->assertEquals("00", $responseCode); - } - - /* 13. CardStorage DeleteCard */ - /* Request Type: card-cancel-card */ - - public function testcardStorageDeleteCard() - { - $paymentMethod = new RecurringPaymentMethod($this->getCustomerId(), $this->getPaymentId("Credit")); - - // delete the stored card/payment method - // WARNING! This can't be undone - $response = $paymentMethod->Delete(); - - $this->assertNotNull($response); - $this->assertEquals("00", $response->responseCode); - } - - /* Request Type: receipt-in */ - - public function testcardStorageChargeCardDCC() - { - $this->dccSetup(); - $this->testcardStorageCreatePayer(); - $this->testcardStorageStoreCard(); - - $paymentMethod = new RecurringPaymentMethod($this->getCustomerId(), $this->getPaymentId("Credit")); - - $orderId = GenerationUtils::generateOrderId(); - $dccDetails = $paymentMethod->getDccRate(DccRateType::SALE, 1001, 'EUR', DccProcessor::FEXCO, $orderId); - - $this->assertNotNull($dccDetails); - $this->assertEquals('00', $dccDetails->responseCode, $dccDetails->responseMessage); - $this->assertNotNull($dccDetails->dccResponseResult); - - $dccValues = new DccRateData(); - $dccValues->orderId = $dccDetails->transactionReference->orderId; - $dccValues->dccProcessor = DccProcessor::FEXCO; - $dccValues->dccType = 1; - $dccValues->dccRateType = DccRateType::SALE; - $dccValues->currency = $dccDetails->dccResponseResult->cardHolderCurrency; - $dccValues->dccRate = $dccDetails->dccResponseResult->cardHolderRate; - $dccValues->amount = $dccDetails->dccResponseResult->cardHolderAmount; - - $response = $paymentMethod->charge(1001) - ->withCurrency("EUR") - ->withCvn("123") - ->withDccRateData($dccValues) - ->withOrderId($orderId) - ->execute(); - - $responseCode = $response->responseCode; // 00 == Success - $message = $response->responseMessage; // [ test system ] AUTHORISED - // get the reponse details to save to the DB for future transaction management requests - $orderId = $response->orderId; - $authCode = $response->authorizationCode; - $paymentsReference = $response->transactionId; // pasref - - $this->assertNotNull($response); - $this->assertEquals("00", $response->responseCode); - } -} +format("Ymd")); + } + + public function getPaymentId($type) + { + return sprintf("%s-Realex-%s", (new \DateTime())->format("Ymd"), $type); + } + + protected function config() + { + $config = new GpEcomConfig(); + $config->merchantId = "heartlandgpsandbox"; + $config->accountId = "3dsecure"; + $config->refundPassword = "refund"; + $config->sharedSecret = "secret"; + $config->serviceUrl = "https://api.sandbox.realexpayments.com/epage-remote.cgi"; + return $config; + } + + protected function dccSetup() + { + $config = new GpEcomConfig(); + $config->merchantId = "heartlandgpsandbox"; + $config->accountId = "apidcc"; + $config->refundPassword = "refund"; + $config->sharedSecret = "secret"; + $config->serviceUrl = "https://api.sandbox.realexpayments.com/epage-remote.cgi"; + + ServicesContainer::configureService($config); + } + + public function setup() + { + ServicesContainer::configureService($this->config()); + + $this->newCustomer = new Customer(); + $this->newCustomer->key = $this->getCustomerId(); + $this->newCustomer->title = "Mr."; + $this->newCustomer->firstName = "James"; + $this->newCustomer->lastName = "Mason"; + $this->newCustomer->company = "Realex Payments"; + $this->newCustomer->address = new Address(); + $this->newCustomer->address->streetAddress1 = "Flat 123"; + $this->newCustomer->address->streetAddress2 = "House 456"; + $this->newCustomer->address->streetAddress3 = "The Cul-De-Sac"; + $this->newCustomer->address->city = "Halifax"; + $this->newCustomer->address->province = "West Yorkshire"; + $this->newCustomer->address->pstalCode = "W6 9HR"; + $this->newCustomer->address->country = "United Kingdom"; + $this->newCustomer->homePhone = "+35312345678"; + $this->newCustomer->workPhone = "+3531987654321"; + $this->newCustomer->fax = "+124546871258"; + $this->newCustomer->mobilePhone = "+25544778544"; + $this->newCustomer->email = "text@example.com"; + $this->newCustomer->comments = "Campaign Ref E7373G"; + } + + /* 08. Card Storage Create Payer */ + /* Request Type: payer-new */ + + public function testcardStorageCreatePayer() + { + try { + $response = $this->newCustomer->Create(); + $this->assertNotNull($response); + $this->assertEquals("00", $response->responseCode); + } catch (GatewayException $exc) { + if ($exc->responseCode != '501' && $exc->responseCode != '520') { + throw $exc; + } + } + } + + /* 09. Card Storage Store Card */ + /* Request Type: card-new */ + + public function testcardStorageStoreCard() + { + $card = new CreditCardData(); + $card->number = "4012001037141112"; + $card->expMonth = 10; + $card->expYear = TestCards::validCardExpYear(); + $card->cvn = '123'; + $card->cardHolderName = 'James Mason'; + + try { + $paymentMethod = $this->newCustomer + ->addPaymentMethod($this->getPaymentId("Credit"), $card) + ->create(); + $this->assertNotNull($paymentMethod); + } catch (GatewayException $exc) { + if ($exc->responseCode != '501' && $exc->responseCode != '520') { + throw $exc; + } + } + } + + /* 10. Card Storage Charge Card */ + /* Request Type: receipt-in */ + + public function testcardStorageChargeCard() + { + $paymentMethod = new RecurringPaymentMethod($this->getCustomerId(), $this->getPaymentId("Credit")); + $response = $paymentMethod->charge(10) + ->withCurrency("EUR") + ->withCvn("123") + ->execute(); + + $responseCode = $response->responseCode; // 00 == Success + $message = $response->responseMessage; // [ test system ] AUTHORISED + // get the reponse details to save to the DB for future transaction management requests + $orderId = $response->orderId; + $authCode = $response->authorizationCode; + $paymentsReference = $response->transactionId; // pasref + + $this->assertNotNull($response); + $this->assertEquals("00", $response->responseCode); + } + + /* 11. CardStorage ThreeDSecure Verify Enrolled */ + /* Request Type: realvault-3ds-verifyenrolled */ + + public function testcardStorageThreeDSecureVerifyEnrolled() + { + $paymentMethod = new RecurringPaymentMethod($this->getCustomerId(), $this->getPaymentId("Credit")); + + $response = $paymentMethod->verify() + ->withAmount(10) + ->withCurrency('USD') + ->withModifier(TransactionModifier::SECURE3D) + ->execute(); + + // get the response details to update the DB + $responseCode = $response->responseCode; // 00 == Success + $message = $response->responseMessage; // [ test system ] AUTHORISED + + $this->assertNotNull($response); + $this->assertEquals("00", $response->responseCode); + } + + /* 12. CardStorage Dcc Rate Lookup */ + /* Request Type: realvault-dccrate */ + + public function testcardStorageDccRateLookup() + { + $this->dccSetup(); + + $orderId = GenerationUtils::generateOrderId(); + $paymentMethod = new RecurringPaymentMethod($this->getCustomerId(), $this->getPaymentId("Credit")); + $dccDetails = $paymentMethod->getDccRate(DccRateType::SALE, 1001, 'EUR', DccProcessor::FEXCO, $orderId); + + $this->assertNotNull($dccDetails); + $this->assertEquals('00', $dccDetails->responseCode, $dccDetails->responseMessage); + $this->assertNotNull($dccDetails->dccResponseResult); + } + + /* 14. CardStorage UpdatePayer */ + /* Request Type: payer-edit */ + + public function testcardStorageUpdatePayer() + { + $customer = new Customer(); + $customer->key = $this->getCustomerId(); + $customer->firstName = "Perry"; + + $response = $customer->saveChanges(); + + $this->assertNotNull($response); + $this->assertEquals("00", $response->responseCode); + } + + /* 15. CardStorage Continuous Authority First */ + /* Request Type: auth */ + + public function testContinuousAuthorityFirst() + { + // create the card object + $card = new CreditCardData(); + $card->number = '5425230000004415'; + $card->expMonth = 12; + $card->expYear = TestCards::validCardExpYear(); + $card->cvn = '131'; + $card->cardHolderName = 'James Mason'; + + + // process an auto-settle authorization + $response = $card->charge(15) + ->withCurrency("EUR") + ->withRecurringInfo(RecurringType::VARIABLE, RecurringSequence::FIRST) + ->execute(); + + $responseCode = $response->responseCode; // 00 == Success + $message = $response->responseMessage; // [ test system ] AUTHORISED + // get the details to save to the DB for future Transaction Management requests + $orderId = $response->orderId; + $authCode = $response->authorizationCode; + $paymentsReference = $response->transactionId; + + $this->assertNotEquals(null, $response); + $this->assertEquals("00", $responseCode); + } + + /* 15. CardStorage Continuous Authority Subsequent */ + /* Request Type: receipt-in */ + + public function testContinuousAuthoritySubsequent() + { + // create the payment method object + $paymentMethod = new RecurringPaymentMethod($this->getCustomerId(), $this->getPaymentId("Credit")); + + // charge the stored card/payment method + $response = $paymentMethod->charge(15) + ->withCurrency("EUR") + ->withCvn("123") + ->withRecurringInfo(RecurringType::VARIABLE, RecurringSequence::SUBSEQUENT) + ->execute(); + + $responseCode = $response->responseCode; // 00 == Success + + $this->assertNotEquals(null, $response); + $this->assertEquals("00", $responseCode); + } + + /* 15. CardStorage Continuous Authority Last */ + /* Request Type: receipt-in */ + + public function testContinuousAuthorityLast() + { + // create the payment method object + $paymentMethod = new RecurringPaymentMethod($this->getCustomerId(), $this->getPaymentId("Credit")); + + // charge the stored card/payment method + $response = $paymentMethod->charge(15) + ->withCurrency("EUR") + ->withCvn("123") + ->withRecurringInfo(RecurringType::VARIABLE, RecurringSequence::LAST) + ->execute(); + + $responseCode = $response->responseCode; // 00 == Success + + $this->assertNotEquals(null, $response); + $this->assertEquals("00", $responseCode); + } + + /* 16. Card Storage Refund */ + /* Request Type: payment-out */ + + public function testcardStorageRefund() + { + // create the payment method object + $paymentMethod = new RecurringPaymentMethod($this->getCustomerId(), $this->getPaymentId("Credit")); + + // charge the stored card/payment method + $response = $paymentMethod->refund(10) + ->withCurrency("EUR") + ->execute(); + + $responseCode = $response->responseCode; // 00 == Success + $message = $response->responseMessage; // [ test system ] AUTHORISED + + $this->assertNotEquals(null, $response); + $this->assertEquals("00", $responseCode); + } + + /* 17. Card Storage UpdateCard */ + /* Request Type: card-update-card */ + + public function testcardStorageUpdateCard() + { + $paymentMethod = new RecurringPaymentMethod($this->getCustomerId(), $this->getPaymentId("Credit")); + + $paymentMethod->paymentMethod = new CreditCardData(); + $paymentMethod->paymentMethod->number = "5425230000004415"; + $paymentMethod->paymentMethod->expMonth = 10; + $paymentMethod->paymentMethod->expYear = TestCards::validCardExpYear(); + $paymentMethod->paymentMethod->cardHolderName = "Philip Marlowe"; + + $response = $paymentMethod->SaveChanges(); + + $this->assertNotNull($response); + $this->assertEquals("00", $response->responseCode); + } + + /* 18. Card Storage Verify Card */ + /* Request Type: receipt-in-otb */ + + public function testcardStorageVerifyCard() + { + $paymentMethod = new RecurringPaymentMethod($this->getCustomerId(), $this->getPaymentId("Credit")); + + // verify the stored card/payment method is valid and active + $response = $paymentMethod->verify() + ->withCvn("123") + ->execute(); + + // get the response details to update the DB + $responseCode = $response->responseCode; // 00 == Success + $message = $response->responseMessage; // [ test system ] AUTHORISED + + $this->assertNotEquals(null, $response); + $this->assertEquals("00", $responseCode); + } + + /* 13. CardStorage DeleteCard */ + /* Request Type: card-cancel-card */ + + public function testcardStorageDeleteCard() + { + $paymentMethod = new RecurringPaymentMethod($this->getCustomerId(), $this->getPaymentId("Credit")); + + // delete the stored card/payment method + // WARNING! This can't be undone + $response = $paymentMethod->Delete(); + + $this->assertNotNull($response); + $this->assertEquals("00", $response->responseCode); + } + + /* Request Type: receipt-in */ + + public function testcardStorageChargeCardDCC() + { + $this->dccSetup(); + $this->testcardStorageCreatePayer(); + $this->testcardStorageStoreCard(); + + $paymentMethod = new RecurringPaymentMethod($this->getCustomerId(), $this->getPaymentId("Credit")); + + $orderId = GenerationUtils::generateOrderId(); + $dccDetails = $paymentMethod->getDccRate(DccRateType::SALE, 1001, 'EUR', DccProcessor::FEXCO, $orderId); + + $this->assertNotNull($dccDetails); + $this->assertEquals('00', $dccDetails->responseCode, $dccDetails->responseMessage); + $this->assertNotNull($dccDetails->dccResponseResult); + + $dccValues = new DccRateData(); + $dccValues->orderId = $dccDetails->transactionReference->orderId; + $dccValues->dccProcessor = DccProcessor::FEXCO; + $dccValues->dccType = 1; + $dccValues->dccRateType = DccRateType::SALE; + $dccValues->currency = $dccDetails->dccResponseResult->cardHolderCurrency; + $dccValues->dccRate = $dccDetails->dccResponseResult->cardHolderRate; + $dccValues->amount = $dccDetails->dccResponseResult->cardHolderAmount; + + $response = $paymentMethod->charge(1001) + ->withCurrency("EUR") + ->withCvn("123") + ->withDccRateData($dccValues) + ->withOrderId($orderId) + ->execute(); + + $responseCode = $response->responseCode; // 00 == Success + $message = $response->responseMessage; // [ test system ] AUTHORISED + // get the reponse details to save to the DB for future transaction management requests + $orderId = $response->orderId; + $authCode = $response->authorizationCode; + $paymentsReference = $response->transactionId; // pasref + + $this->assertNotNull($response); + $this->assertEquals("00", $response->responseCode); + } +} diff --git a/test/Integration/Gateways/TransITConnector/Certification/Ecommerce_3.php b/test/Integration/Gateways/TransITConnector/Certification/Ecommerce_3.php index c9da22ee..9263f111 100644 --- a/test/Integration/Gateways/TransITConnector/Certification/Ecommerce_3.php +++ b/test/Integration/Gateways/TransITConnector/Certification/Ecommerce_3.php @@ -1,786 +1,786 @@ -getConfig()); - } - - protected function getConfig() { - $config = new TransitConfig(); - $config->merchantId = '887000003226'; - $config->username = 'TA5622118'; - $config->password = 'Hrcb^619'; - $config->deviceId = '88700000322601'; - $config->transactionKey = '57ZL83P6A2V8KGI49QWK017C7WXG03O8'; - $config->developerId = '003226G001'; - $config->gatewayProvider = GatewayProvider::TRANSIT; - $config->acceptorConfig = new AcceptorConfig(); // might need to adjust this per transaction or per file - return $config; - } - - public static $test20VoidTarget; - public static $test21VoidTarget; - public static $test30MUT; - public static $test31MUT; - - // These are all stolen from dotnet cert file - public function test01VisaLevelII() { - $commercialData = new CommercialData(TaxType::NOT_USED); - $commercialData->poNumber = '9876543210'; - $commercialData->taxAmount = 0; - - $response = $this->getVisa1()->charge(.52) - ->withCurrency("USD") - ->withCommercialData($commercialData) - ->withDescription("test01VisaLevelII") - ->execute(); - - $this->assertEquals('00', $response->responseCode); - } - - public function test02MasterCardLevelII() { - $commercialData = new CommercialData(TaxType::SALES_TAX); - $commercialData->poNumber = '9876543210'; - $commercialData->taxAmount = .02; - - $response = $this->getMCKeyedTIC()->charge(.52) - ->withCurrency("USD") - ->withCommercialData($commercialData) - ->withDescription("test02MasterCardLevelII") - ->execute(); - - $this->assertEquals('00', $response->responseCode); - } - - public function test03AmexManualLevelII() { - $commercialData = new CommercialData(TaxType::NOT_USED); - $commercialData->supplierReferenceNumber = "123456"; - $commercialData->customerReferenceId = "987654"; - $commercialData->destinationPostalCode = "85284"; - $commercialData->description = "AMEX LEVEL 2 TEST CASE"; - $commercialData->taxAmount = 0; - - $response = $this->getAmex()->charge(1.50) - ->withCurrency('USD') - ->withCommercialData($commercialData) - ->withDescription('test03AmexManualLevelII') - ->execute(); - - $this->assertEquals('00', $response->responseCode); - } - - public function test04MasterCard2BINSale() { - $response = $this->getMC2BIN()->charge(11.10) - ->withCurrency('USD') - ->withAddress($this->getAVSData()) - ->withClientTransactionId('test04' . time()) - ->execute(); - - $this->assertEquals('00', $response->responseCode); - } - - public function test05DiscoverSale() { - $response = $this->getDiscover()->charge(12.00) - ->withCurrency('USD') - ->withAddress($this->getAVSData()) - ->withClientTransactionId('test05' . time()) - ->execute(); - - $this->assertEquals('00', $response->responseCode); - } - - public function test06DinersAuth() { - $response = $this->getDiners()->authorize(6.00) - ->withCurrency('USD') - ->withAddress($this->getAVSData()) - ->withClientTransactionId('test06' . time()) - ->execute(); - - $this->assertEquals('00', $response->responseCode); - // $this->assertEquals(5.55, $response->authorizedAmount); test script is wrong, gateway doesn't return partial auth on this test - } - - public function test07MasterCardSale() { - $response = $this->getMCUnclassifiedTIC()->charge(15.00) - ->withCurrency('USD') - ->withAddress($this->getAVSData()) - ->withClientTransactionId('test07' . time()) - ->execute(); - - self::$test20VoidTarget = $response->transactionId; - - $this->assertEquals('00', $response->responseCode); - } - - public function test08MasterCardSale() { - $response = $this->getMCUnclassifiedTIC()->charge(34.13) - ->withCurrency('USD') - ->withAddress($this->getAVSData()) - ->withClientTransactionId('test08' . time()) - ->execute(); - - $this->assertEquals('00', $response->responseCode); - } - - public function test09JCBSale() { - $response = $this->getJCB()->charge(13.00) - ->withCurrency('USD') - ->withAddress($this->getAVSData()) - ->withClientTransactionId('test09' . time()) - ->execute(); - - $this->assertEquals('00', $response->responseCode); - } - - public function test10AMEX() { - $card = $this->getAmex(); - $card->cvn = null; - - $response = $card->charge(13.50) - ->withCurrency('USD') - ->withAddress($this->getAVSData()) - ->withClientTransactionId('test10' . time()) - ->execute(); - - $this->assertEquals('00', $response->responseCode); - } - - public function test11VisaSale() { - $response = $this->getVisa1()->charge(32.49) - ->withCurrency('USD') - ->withAddress($this->getAVSData()) - ->withClientTransactionId('test11' . time()) - ->execute(); - - $this->assertEquals('00', $response->responseCode); - } - - public function test12DiscoverCUPSale() { - $response = $this->getDiscoverCUP()->charge(10.00) - ->withCurrency('USD') - ->withAddress($this->getAVSData()) - ->withClientTransactionId('test12' . time()) - ->execute(); - - $this->assertEquals('00', $response->responseCode); - } - - public function test13VisaSale() { - $response = $this->getVisa1()->charge(11.12) - ->withCurrency('USD') - ->withAddress($this->getAVSData()) - ->withClientTransactionId('test13' . time()) - ->execute(); - - $this->assertEquals('00', $response->responseCode); - } - - public function test14AMEXSale() { - $response = $this->getAmex()->charge(4.00) - ->withCurrency('USD') - ->withAddress($this->getAVSData()) - ->withClientTransactionId('test14' . time()) - ->execute(); - - self::$test21VoidTarget = $response->transactionId; - - $this->assertEquals('00', $response->responseCode); - } - - public function test15VisaVerify() { - $response = $this->getVisa1()->verify() - ->withRequestMultiUseToken(true) - ->withAddress($this->getAVSData()) - ->withClientTransactionId('test15' . time()) - ->execute(); - - self::$test30MUT = $response->token; - - $this->assertEquals('00', $response->responseCode); - } - - public function test15aVisaVerify() { - $response = $this->getVisa1()->verify() - // ->withRequestMultiUseToken(true) - ->withAddress($this->getAVSData()) - ->withClientTransactionId('test15a' . time()) - ->execute(); - - $this->assertEquals('00', $response->responseCode); - } - - public function test16MasterCardVerify() { - $response = $this->getMCUnclassifiedTIC()->verify() - ->withAddress($this->getAVSData()) - ->withClientTransactionId('test16' . time()) - ->withRequestMultiUseToken(true) - ->execute(); - - self::$test31MUT = $response->token; - - $this->assertEquals('00', $response->responseCode); - } - - public function test16aMasterCardVerify() { - $response = $this->getMCUnclassifiedTIC()->verify() - ->withAddress($this->getAVSData()) - ->withClientTransactionId('test16a' . time()) - // ->withRequestMultiUseToken(true) - ->execute(); - - $this->assertEquals('00', $response->responseCode); - } - - public function test17AMEXVerify() { - $response = $this->getAmex()->verify() - ->withAddress($this->getAVSData()) - ->withClientTransactionId('test17' . time()) - ->execute(); - - $this->assertEquals('00', $response->responseCode); - } - - public function test18VisaLvl3() { - $commercialData = new CommercialData(TaxType::NOT_USED, CommercialIndicator::LEVEL_III); - $commercialData->poNumber = 1784951399984509620; - $commercialData->taxAmount = .01; - $commercialData->destinationPostalCode = '85212'; - $commercialData->destinationCountryCode = "USA"; - $commercialData->originPostalCode = "22193"; - $commercialData->summaryCommodityCode = "SCC"; - $commercialData->customerVatNumber = "123456789"; - $commercialData->vatInvoiceNumber = "UVATREF162"; - $commercialData->orderDate = date('m/d/Y'); - $commercialData->freightAmount = 0.01; - $commercialData->dutyAmount = 0.01; - $commercialData->additionalTaxDetails = new AdditionalTaxDetails( - .01, - TaxCategory::VAT, - .04, - "VAT" - ); - - $lineItem1 = new CommercialLineItem; - $lineItem1->productCode = "PRDCD1"; - $lineItem1->name = "PRDCD1NAME"; - $lineItem1->unitCost = 0.01; - $lineItem1->quantity = 1; - $lineItem1->unitOfMeasure = "METER"; - $lineItem1->description = "PRODUCT 1 NOTES"; - $lineItem1->commodityCode = "12DIGIT ACCO"; - $lineItem1->alternateTaxId = "1234567890"; - $lineItem1->creditDebitIndicator = CreditDebitIndicator::CREDIT; - $lineItem1->discountDetails = new DiscountDetails( - .50, - "Indep Sale 1", - .1, - "SALE" - ); - $lineItem1->taxAmount = 0; - $lineItem1->taxName = 'item 1 name'; - - $lineItem2 = new CommercialLineItem; - $lineItem2->productCode = "PRDCD2"; - $lineItem2->name = "PRDCD2NAME"; - $lineItem2->unitCost = 0.01; - $lineItem2->quantity = 1; - $lineItem2->unitOfMeasure = "METER"; - $lineItem2->description = "PRODUCT 2 NOTES"; - $lineItem2->commodityCode = "12DIGIT ACCO"; - $lineItem2->alternateTaxId = "1234567890"; - $lineItem2->creditDebitIndicator = CreditDebitIndicator::DEBIT; - $lineItem2->discountDetails = new DiscountDetails( - .50, - "Indep Sale 1", - .1, - "SALE" - ); - $lineItem2->taxAmount = .03; - $lineItem2->taxName = 'a tax name here'; - $lineItem2->taxType = TaxType::SALES_TAX; - $lineItem2->taxPercentage = .69; - - $commercialData->addLineItems($lineItem1, $lineItem2); // can pass multiple line items or just call this function multiple times - - $response = $this->getVisa1()->charge(.53) - ->withCurrency('USD') - ->withCommercialData($commercialData) - ->execute(); - - $this->assertEquals('00', $response->responseCode); - } - - public function test19MasterCardLvl3() { - $commercialData = new CommercialData(TaxType::NOT_USED, CommercialIndicator::LEVEL_III); - $commercialData->poNumber = "9876543210"; - $commercialData->taxAmount = 0.01; - $commercialData->destinationPostalCode = "85212"; - $commercialData->destinationCountryCode = "USA"; - $commercialData->originPostalCode = "22193"; - $commercialData->summaryCommodityCode = "SCC"; - $commercialData->customerVatNumber = "123456789"; - $commercialData->vatInvoiceNumber = "UVATREF162"; - $commercialData->orderDate = date('m/d/Y'); - $commercialData->freightAmount = 0.01; - $commercialData->dutyAmount = 0.01; - $commercialData->additionalTaxDetails = new AdditionalTaxDetails(.01, TaxCategory::VAT, .04, "VAT"); - - $lineItem = new CommercialLineItem; - $lineItem->productCode = "PRDCD1"; - $lineItem->name = "PRDCD1NAME"; - $lineItem->unitCost = 0.01; - $lineItem->quantity = 1; - $lineItem->unitOfMeasure = "METER"; - $lineItem->description = "PRODUCT 1 NOTES"; - $lineItem->commodityCode = "12DIGIT ACCO"; - $lineItem->alternateTaxId = "1234567890"; - $lineItem->creditDebitIndicator = CreditDebitIndicator::CREDIT; - $lineItem->discountDetails = new DiscountDetails( - .01, - 'little discount', - 1, - 'discount type 1' - ); - $lineItem->taxAmount = 1; - $lineItem->taxName = 'a tax name here'; - $lineItem->taxPercentage = 12; - - $commercialData->addLineItems($lineItem); - - $response = $this->getMCUnclassifiedTIC()->charge(.53) - ->withCurrency('USD') - ->withCommercialData($commercialData) - ->withAddress($this->getAVSData()) - ->execute(); - - $this->assertEquals('00', $response->responseCode); - } - - public function test20PartialVoid() { - $response = Transaction::fromId(self::$test20VoidTarget) - ->void(5.00) - ->withDescription('PARTIAL_REVERSAL') - ->execute(); - - $this->assertEquals('00', $response->responseCode); - } - - public function test21FullVoid() { - $response = Transaction::fromId(self::$test21VoidTarget) - ->void() - ->withDescription('POST_AUTH_USER_DECLINE') - ->execute(); - - $this->assertEquals('00', $response->responseCode); - } - - public function test22Visa3DS () { - $threeDeeInfo = new ThreeDSecure(); - $threeDeeInfo->eci = 5; - $threeDeeInfo->secureCode = '1234567890123456789012345678901234567890'; - // $threeDeeInfo->ucafIndicator = UcafIndicator::FULLY_AUTHENTICATED; - // $threeDeeInfo->setVersion(Secure3dVersion::ONE); - - $card = $this->getVisa1(); - $card->threeDSecure = $threeDeeInfo; - - $response = $card->charge(1.01) - ->withCurrency('USD') - ->withClientTransactionId('test22_' . time()) - ->execute(); - - $this->assertEquals('00', $response->responseCode); - } - - public function test23MC3DS_V1 () { - $threeDeeInfo = new ThreeDSecure(); - $threeDeeInfo->eci = 5; - $threeDeeInfo->secureCode = '12345678901234567890123456789012'; - $threeDeeInfo->authenticationType = '21'; - $threeDeeInfo->ucafIndicator = UcafIndicator::FULLY_AUTHENTICATED; - $threeDeeInfo->setVersion(Secure3dVersion::ONE); - - $card = $this->getMCUnclassifiedTIC(); - $card->threeDSecure = $threeDeeInfo; - - $response = $card->charge(34.02) - ->withCurrency('USD') - ->withClientTransactionId('test23_' . time()) - ->execute(); - - $this->assertEquals('00', $response->responseCode); - } - - public function test24MC3DS_V2 () { - $threeDeeInfo = new ThreeDSecure(); - $threeDeeInfo->eci = 5; - $threeDeeInfo->secureCode = '12345678901234567890123456789012'; - $threeDeeInfo->authenticationType = '21'; - $threeDeeInfo->directoryServerTransactionId = 'c272b04f-6e7b-43a2-bb78-90f4fb94aa25'; - $threeDeeInfo->ucafIndicator = UcafIndicator::FULLY_AUTHENTICATED; - $threeDeeInfo->setVersion(Secure3dVersion::TWO); - - $card = $this->getMCUnclassifiedTIC(); - $card->threeDSecure = $threeDeeInfo; - - $response = $card->charge(34.06) - ->withCurrency('USD') - ->withClientTransactionId('test24_' . time()) - ->execute(); - - $this->assertEquals('00', $response->responseCode); - } - - public function test25Discover3DS () { - $threeDeeInfo = new ThreeDSecure(); - $threeDeeInfo->eci = 5; - $threeDeeInfo->secureCode = '1234567890123456789012345678901234567890'; - // $threeDeeInfo->ucafIndicator = UcafIndicator::FULLY_AUTHENTICATED; - // $threeDeeInfo->setVersion(Secure3dVersion::ONE); - - $card = $this->getDiscover(); - $card->threeDSecure = $threeDeeInfo; - - $response = $card->charge(45.02) - ->withCurrency('USD') - ->withClientTransactionId('test25_' . time()) - ->execute(); - - $this->assertEquals('00', $response->responseCode); - } - - public function test26Amex3DS () { - $threeDeeInfo = new ThreeDSecure(); - $threeDeeInfo->eci = 5; - $threeDeeInfo->secureCode = '1234567890123456789012345678901234567890'; - // $threeDeeInfo->ucafIndicator = UcafIndicator::FULLY_AUTHENTICATED; - // $threeDeeInfo->setVersion(Secure3dVersion::ONE); - - $card = $this->getAmex(); - $card->threeDSecure = $threeDeeInfo; - - $response = $card->charge(32.02) - ->withCurrency('USD') - ->withClientTransactionId('test26_' . time()) - ->execute(); - - $this->assertEquals('00', $response->responseCode); - } - - public function test27MC3DS_V2_2 () { - $threeDeeInfo = new ThreeDSecure(); - $threeDeeInfo->eci = 5; - $threeDeeInfo->authenticationValue = 'ODQzNjgwNjU0ZjM3N2JmYTg0NTM='; - $threeDeeInfo->authenticationType = '24'; - $threeDeeInfo->directoryServerTransactionId = 'c272b04f-6e7b-43a2-bb78-90f4fb94aa25'; - $threeDeeInfo->ucafIndicator = UcafIndicator::MERCHANT_RISK_BASED; - $threeDeeInfo->setVersion(Secure3dVersion::TWO); - - $card = $this->getMCUnclassifiedTIC(); - $card->threeDSecure = $threeDeeInfo; - - $response = $card->charge(34.05) - ->withCurrency('USD') - ->withClientTransactionId('test27_' . time()) - ->execute(); - - $this->assertEquals('00', $response->responseCode); - } - - public function test28Visa3DS_ECI6 () { - $threeDeeInfo = new ThreeDSecure(); - $threeDeeInfo->eci = 6; - $threeDeeInfo->secureCode = '1234567890123456789012345678901234567890'; - // $threeDeeInfo->ucafIndicator = UcafIndicator::FULLY_AUTHENTICATED; - // $threeDeeInfo->setVersion(Secure3dVersion::TWO); - - $card = $this->getVisa1(); - $card->threeDSecure = $threeDeeInfo; - - $response = $card->charge(.81) - ->withCurrency('USD') - ->withClientTransactionId('test28_' . time()) - ->execute(); - - $this->assertEquals('00', $response->responseCode); - } - - public function test29MC3DS_ECI6 () { - $threeDeeInfo = new ThreeDSecure(); - $threeDeeInfo->eci = 6; - $threeDeeInfo->secureCode = '12345678901234567890123456789012'; - $threeDeeInfo->ucafIndicator = UcafIndicator::FULLY_AUTHENTICATED; - $threeDeeInfo->setVersion(Secure3dVersion::ONE); - - $card = $this->getMCUnclassifiedTIC(); - $card->threeDSecure = $threeDeeInfo; - - $response = $card->charge(29.00) - ->withCurrency('USD') - ->withClientTransactionId('test29_' . time()) - ->execute(); - - $this->assertEquals('00', $response->responseCode); - } - - public function test30SaleVisaCIT () { - $storedcreds = new StoredCredential; - $storedcreds->initiator = StoredCredentialInitiator::MERCHANT; - - $cardAsMUT = $this->getVisa1(); - $cardAsMUT->number = self::$test30MUT; - - $response = $cardAsMUT->charge(14.00) - ->withCurrency('USD') - ->withAddress($this->getAVSData()) - ->withClientTransactionId('test30_' . time()) - ->withStoredCredential($storedcreds) - ->execute(); - - $this->assertEquals('00', $response->responseCode); - } - - public function test31SaleNonVisaCIT () { - $storedcreds = new StoredCredential; - $storedcreds->initiator = StoredCredentialInitiator::MERCHANT; - - $cardAsMUT = $this->getMCUnclassifiedTIC(); - $cardAsMUT->number = self::$test31MUT; - - $response = $cardAsMUT->charge(15.00) - ->withCurrency('USD') - ->withAddress($this->getAVSData()) - ->withClientTransactionId('test31_' . time()) - ->withStoredCredential($storedcreds) - ->execute(); - - $this->assertEquals('00', $response->responseCode); - } - - public function test32VisaMultiCapture () { - $response = $this->getVisa1()->authorize(30.00) - ->withCurrency('USD') - ->withAddress($this->getAVSData()) - ->withClientTransactionId('test32_' . time()) - ->execute(); - - $this->assertEquals('00', $response->responseCode); - - $firstCaptureResponse = $response->capture(15.00) - ->withMultiCapture(1, 2) - ->execute(); - - $this->assertEquals('00', $firstCaptureResponse->responseCode); - - $secondCaptureResponse = $response->capture(15.00) - ->withMultiCapture(2, 2) - ->execute(); - - $this->assertEquals('00', $secondCaptureResponse->responseCode); - } - - public function test33MCMultiCapture () { - $response = $this->getMCUnclassifiedTIC()->authorize(50.00) - ->withCurrency('USD') - ->withAddress($this->getAVSData()) - ->withClientTransactionId('test33_' . time()) - ->execute(); - - $this->assertEquals('00', $response->responseCode); - - $firstCaptureResponse = $response->capture(30.00) - ->withMultiCapture(1, 3) - ->execute(); - - $this->assertEquals('00', $firstCaptureResponse->responseCode); - - $secondCaptureResponse = $response->capture(10.00) - ->withMultiCapture(2, 3) - ->execute(); - - $this->assertEquals('00', $secondCaptureResponse->responseCode); - - $thirdCaptureResponse = $response->capture(10.00) - ->withMultiCapture(3, 3) - ->execute(); - - $this->assertEquals('00', $thirdCaptureResponse->responseCode); - } - - public function test34MCMultiCapture () { - $response = $this->getMCUnclassifiedTIC()->authorize(60.00) - ->withCurrency('USD') - ->withAddress($this->getAVSData()) - ->withClientTransactionId('test34_' . time()) - ->execute(); - - $this->assertEquals('00', $response->responseCode); - - $captureResponse = $response->capture() - ->withMultiCapture() - ->execute(); - - $this->assertEquals('00', $captureResponse->responseCode); - } - - public function test35CloseBatch () { - $response = BatchService::closeBatch(); - - $this->assertEquals('00', $response->responseCode); - } - - public function getVisa1 () { - $card = new CreditCardData; - $card->number = 4012000098765439; - $card->expYear = 20; // magic number - $card->expMonth = 12; - $card->cvn = 999; - $card->cardType = CardType::VISA; - return $card; - } - - public function getVisa2 () { - $card = new CreditCardData; - $card->number = 4012881888818888; - $card->expYear = 20; // magic number - $card->expMonth = 12; - $card->cvn = 999; - $card->cardType = CardType::VISA; - return $card; - } - - public function getMCUnclassifiedTIC () { - $card = new CreditCardData; - $card->number = 5146315000000055; - $card->expYear = 20; // magic number - $card->expMonth = 12; - $card->cvn = 998; - $card->cardType = CardType::MASTERCARD; - return $card; - } - - public function getMCSwipeTIC () { - $card = new CreditCardData; - $card->number = 5146312200000035; - $card->expYear = 20; // magic number - $card->expMonth = 12; - $card->cvn = 998; - $card->cardType = CardType::MASTERCARD; - return $card; - } - - public function getMCKeyedTIC () { - $card = new CreditCardData; - $card->number = 5146312620000045; - $card->expYear = 20; // magic number - $card->expMonth = 12; - $card->cvn = 998; - $card->cardType = CardType::MASTERCARD; - return $card; - } - - public function getMC2BIN () { - $card = new CreditCardData; - $card->number = 2223000048400011; - $card->expYear = 25; // magic number - $card->expMonth = 12; - $card->cvn = 998; - $card->cardType = CardType::MASTERCARD; - return $card; - } - - public function getAmex () { - $card = new CreditCardData; - $card->number = 371449635392376; - $card->expYear = 25; // magic number - $card->expMonth = 12; - $card->cvn = 9997; - $card->cardType = CardType::AMEX; - return $card; - } - - public function getDiscover () { - $card = new CreditCardData; - $card->number = 6011000993026909; - $card->expYear = 20; // magic number - $card->expMonth = 12; - $card->cvn = 996; - $card->cardType = CardType::DISCOVER; - return $card; - } - - public function getDiscoverCUP () { - $card = new CreditCardData; - $card->number = 6282000123842342; - $card->expYear = 20; // magic number - $card->expMonth = 12; - $card->cvn = 996; - $card->cardType = CardType::DISCOVER; - return $card; - } - - public function getDiscoverCUP2 () { - $card = new CreditCardData; - $card->number = 6221261111112650; - $card->expYear = 20; // magic number - $card->expMonth = 12; - $card->cvn = 996; - $card->cardType = CardType::DISCOVER; - return $card; - } - - public function getDiners () { - $card = new CreditCardData; - $card->number = 3055155515160018; - $card->expYear = 20; // magic number - $card->expMonth = 12; - $card->cvn = 996; - $card->cardType = CardType::DINERS; - return $card; - } - - public function getJCB () { - $card = new CreditCardData; - $card->number = 3530142019945859; - $card->expYear = 20; // magic number - $card->expMonth = 12; - $card->cvn = 996; - $card->cardType = CardType::JCB; - return $card; - } - - public function getAVSData () { - $address = new Address(); - $address->streetAddress1 = '8320'; - $address->postalCode = '85284'; - return $address; - } -} +getConfig()); + } + + protected function getConfig() { + $config = new TransitConfig(); + $config->merchantId = '887000003226'; + $config->username = 'TA5622118'; + $config->password = 'Hrcb^619'; + $config->deviceId = '88700000322601'; + $config->transactionKey = '57ZL83P6A2V8KGI49QWK017C7WXG03O8'; + $config->developerId = '003226G001'; + $config->gatewayProvider = GatewayProvider::TRANSIT; + $config->acceptorConfig = new AcceptorConfig(); // might need to adjust this per transaction or per file + return $config; + } + + public static $test20VoidTarget; + public static $test21VoidTarget; + public static $test30MUT; + public static $test31MUT; + + // These are all stolen from dotnet cert file + public function test01VisaLevelII() { + $commercialData = new CommercialData(TaxType::NOT_USED); + $commercialData->poNumber = '9876543210'; + $commercialData->taxAmount = 0; + + $response = $this->getVisa1()->charge(.52) + ->withCurrency("USD") + ->withCommercialData($commercialData) + ->withDescription("test01VisaLevelII") + ->execute(); + + $this->assertEquals('00', $response->responseCode); + } + + public function test02MasterCardLevelII() { + $commercialData = new CommercialData(TaxType::SALES_TAX); + $commercialData->poNumber = '9876543210'; + $commercialData->taxAmount = .02; + + $response = $this->getMCKeyedTIC()->charge(.52) + ->withCurrency("USD") + ->withCommercialData($commercialData) + ->withDescription("test02MasterCardLevelII") + ->execute(); + + $this->assertEquals('00', $response->responseCode); + } + + public function test03AmexManualLevelII() { + $commercialData = new CommercialData(TaxType::NOT_USED); + $commercialData->supplierReferenceNumber = "123456"; + $commercialData->customerReferenceId = "987654"; + $commercialData->destinationPostalCode = "85284"; + $commercialData->description = "AMEX LEVEL 2 TEST CASE"; + $commercialData->taxAmount = 0; + + $response = $this->getAmex()->charge(1.50) + ->withCurrency('USD') + ->withCommercialData($commercialData) + ->withDescription('test03AmexManualLevelII') + ->execute(); + + $this->assertEquals('00', $response->responseCode); + } + + public function test04MasterCard2BINSale() { + $response = $this->getMC2BIN()->charge(11.10) + ->withCurrency('USD') + ->withAddress($this->getAVSData()) + ->withClientTransactionId('test04' . time()) + ->execute(); + + $this->assertEquals('00', $response->responseCode); + } + + public function test05DiscoverSale() { + $response = $this->getDiscover()->charge(12.00) + ->withCurrency('USD') + ->withAddress($this->getAVSData()) + ->withClientTransactionId('test05' . time()) + ->execute(); + + $this->assertEquals('00', $response->responseCode); + } + + public function test06DinersAuth() { + $response = $this->getDiners()->authorize(6.00) + ->withCurrency('USD') + ->withAddress($this->getAVSData()) + ->withClientTransactionId('test06' . time()) + ->execute(); + + $this->assertEquals('00', $response->responseCode); + // $this->assertEquals(5.55, $response->authorizedAmount); test script is wrong, gateway doesn't return partial auth on this test + } + + public function test07MasterCardSale() { + $response = $this->getMCUnclassifiedTIC()->charge(15.00) + ->withCurrency('USD') + ->withAddress($this->getAVSData()) + ->withClientTransactionId('test07' . time()) + ->execute(); + + self::$test20VoidTarget = $response->transactionId; + + $this->assertEquals('00', $response->responseCode); + } + + public function test08MasterCardSale() { + $response = $this->getMCUnclassifiedTIC()->charge(34.13) + ->withCurrency('USD') + ->withAddress($this->getAVSData()) + ->withClientTransactionId('test08' . time()) + ->execute(); + + $this->assertEquals('00', $response->responseCode); + } + + public function test09JCBSale() { + $response = $this->getJCB()->charge(13.00) + ->withCurrency('USD') + ->withAddress($this->getAVSData()) + ->withClientTransactionId('test09' . time()) + ->execute(); + + $this->assertEquals('00', $response->responseCode); + } + + public function test10AMEX() { + $card = $this->getAmex(); + $card->cvn = null; + + $response = $card->charge(13.50) + ->withCurrency('USD') + ->withAddress($this->getAVSData()) + ->withClientTransactionId('test10' . time()) + ->execute(); + + $this->assertEquals('00', $response->responseCode); + } + + public function test11VisaSale() { + $response = $this->getVisa1()->charge(32.49) + ->withCurrency('USD') + ->withAddress($this->getAVSData()) + ->withClientTransactionId('test11' . time()) + ->execute(); + + $this->assertEquals('00', $response->responseCode); + } + + public function test12DiscoverCUPSale() { + $response = $this->getDiscoverCUP()->charge(10.00) + ->withCurrency('USD') + ->withAddress($this->getAVSData()) + ->withClientTransactionId('test12' . time()) + ->execute(); + + $this->assertEquals('00', $response->responseCode); + } + + public function test13VisaSale() { + $response = $this->getVisa1()->charge(11.12) + ->withCurrency('USD') + ->withAddress($this->getAVSData()) + ->withClientTransactionId('test13' . time()) + ->execute(); + + $this->assertEquals('00', $response->responseCode); + } + + public function test14AMEXSale() { + $response = $this->getAmex()->charge(4.00) + ->withCurrency('USD') + ->withAddress($this->getAVSData()) + ->withClientTransactionId('test14' . time()) + ->execute(); + + self::$test21VoidTarget = $response->transactionId; + + $this->assertEquals('00', $response->responseCode); + } + + public function test15VisaVerify() { + $response = $this->getVisa1()->verify() + ->withRequestMultiUseToken(true) + ->withAddress($this->getAVSData()) + ->withClientTransactionId('test15' . time()) + ->execute(); + + self::$test30MUT = $response->token; + + $this->assertEquals('00', $response->responseCode); + } + + public function test15aVisaVerify() { + $response = $this->getVisa1()->verify() + // ->withRequestMultiUseToken(true) + ->withAddress($this->getAVSData()) + ->withClientTransactionId('test15a' . time()) + ->execute(); + + $this->assertEquals('00', $response->responseCode); + } + + public function test16MasterCardVerify() { + $response = $this->getMCUnclassifiedTIC()->verify() + ->withAddress($this->getAVSData()) + ->withClientTransactionId('test16' . time()) + ->withRequestMultiUseToken(true) + ->execute(); + + self::$test31MUT = $response->token; + + $this->assertEquals('00', $response->responseCode); + } + + public function test16aMasterCardVerify() { + $response = $this->getMCUnclassifiedTIC()->verify() + ->withAddress($this->getAVSData()) + ->withClientTransactionId('test16a' . time()) + // ->withRequestMultiUseToken(true) + ->execute(); + + $this->assertEquals('00', $response->responseCode); + } + + public function test17AMEXVerify() { + $response = $this->getAmex()->verify() + ->withAddress($this->getAVSData()) + ->withClientTransactionId('test17' . time()) + ->execute(); + + $this->assertEquals('00', $response->responseCode); + } + + public function test18VisaLvl3() { + $commercialData = new CommercialData(TaxType::NOT_USED, CommercialIndicator::LEVEL_III); + $commercialData->poNumber = 1784951399984509620; + $commercialData->taxAmount = .01; + $commercialData->destinationPostalCode = '85212'; + $commercialData->destinationCountryCode = "USA"; + $commercialData->originPostalCode = "22193"; + $commercialData->summaryCommodityCode = "SCC"; + $commercialData->customerVatNumber = "123456789"; + $commercialData->vatInvoiceNumber = "UVATREF162"; + $commercialData->orderDate = date('m/d/Y'); + $commercialData->freightAmount = 0.01; + $commercialData->dutyAmount = 0.01; + $commercialData->additionalTaxDetails = new AdditionalTaxDetails( + .01, + TaxCategory::VAT, + .04, + "VAT" + ); + + $lineItem1 = new CommercialLineItem; + $lineItem1->productCode = "PRDCD1"; + $lineItem1->name = "PRDCD1NAME"; + $lineItem1->unitCost = 0.01; + $lineItem1->quantity = 1; + $lineItem1->unitOfMeasure = "METER"; + $lineItem1->description = "PRODUCT 1 NOTES"; + $lineItem1->commodityCode = "12DIGIT ACCO"; + $lineItem1->alternateTaxId = "1234567890"; + $lineItem1->creditDebitIndicator = CreditDebitIndicator::CREDIT; + $lineItem1->discountDetails = new DiscountDetails( + .50, + "Indep Sale 1", + .1, + "SALE" + ); + $lineItem1->taxAmount = 0; + $lineItem1->taxName = 'item 1 name'; + + $lineItem2 = new CommercialLineItem; + $lineItem2->productCode = "PRDCD2"; + $lineItem2->name = "PRDCD2NAME"; + $lineItem2->unitCost = 0.01; + $lineItem2->quantity = 1; + $lineItem2->unitOfMeasure = "METER"; + $lineItem2->description = "PRODUCT 2 NOTES"; + $lineItem2->commodityCode = "12DIGIT ACCO"; + $lineItem2->alternateTaxId = "1234567890"; + $lineItem2->creditDebitIndicator = CreditDebitIndicator::DEBIT; + $lineItem2->discountDetails = new DiscountDetails( + .50, + "Indep Sale 1", + .1, + "SALE" + ); + $lineItem2->taxAmount = .03; + $lineItem2->taxName = 'a tax name here'; + $lineItem2->taxType = TaxType::SALES_TAX; + $lineItem2->taxPercentage = .69; + + $commercialData->addLineItems($lineItem1, $lineItem2); // can pass multiple line items or just call this function multiple times + + $response = $this->getVisa1()->charge(.53) + ->withCurrency('USD') + ->withCommercialData($commercialData) + ->execute(); + + $this->assertEquals('00', $response->responseCode); + } + + public function test19MasterCardLvl3() { + $commercialData = new CommercialData(TaxType::NOT_USED, CommercialIndicator::LEVEL_III); + $commercialData->poNumber = "9876543210"; + $commercialData->taxAmount = 0.01; + $commercialData->destinationPostalCode = "85212"; + $commercialData->destinationCountryCode = "USA"; + $commercialData->originPostalCode = "22193"; + $commercialData->summaryCommodityCode = "SCC"; + $commercialData->customerVatNumber = "123456789"; + $commercialData->vatInvoiceNumber = "UVATREF162"; + $commercialData->orderDate = date('m/d/Y'); + $commercialData->freightAmount = 0.01; + $commercialData->dutyAmount = 0.01; + $commercialData->additionalTaxDetails = new AdditionalTaxDetails(.01, TaxCategory::VAT, .04, "VAT"); + + $lineItem = new CommercialLineItem; + $lineItem->productCode = "PRDCD1"; + $lineItem->name = "PRDCD1NAME"; + $lineItem->unitCost = 0.01; + $lineItem->quantity = 1; + $lineItem->unitOfMeasure = "METER"; + $lineItem->description = "PRODUCT 1 NOTES"; + $lineItem->commodityCode = "12DIGIT ACCO"; + $lineItem->alternateTaxId = "1234567890"; + $lineItem->creditDebitIndicator = CreditDebitIndicator::CREDIT; + $lineItem->discountDetails = new DiscountDetails( + .01, + 'little discount', + 1, + 'discount type 1' + ); + $lineItem->taxAmount = 1; + $lineItem->taxName = 'a tax name here'; + $lineItem->taxPercentage = 12; + + $commercialData->addLineItems($lineItem); + + $response = $this->getMCUnclassifiedTIC()->charge(.53) + ->withCurrency('USD') + ->withCommercialData($commercialData) + ->withAddress($this->getAVSData()) + ->execute(); + + $this->assertEquals('00', $response->responseCode); + } + + public function test20PartialVoid() { + $response = Transaction::fromId(self::$test20VoidTarget) + ->void(5.00) + ->withDescription('PARTIAL_REVERSAL') + ->execute(); + + $this->assertEquals('00', $response->responseCode); + } + + public function test21FullVoid() { + $response = Transaction::fromId(self::$test21VoidTarget) + ->void() + ->withDescription('POST_AUTH_USER_DECLINE') + ->execute(); + + $this->assertEquals('00', $response->responseCode); + } + + public function test22Visa3DS () { + $threeDeeInfo = new ThreeDSecure(); + $threeDeeInfo->eci = 5; + $threeDeeInfo->secureCode = '1234567890123456789012345678901234567890'; + // $threeDeeInfo->ucafIndicator = UcafIndicator::FULLY_AUTHENTICATED; + // $threeDeeInfo->setVersion(Secure3dVersion::ONE); + + $card = $this->getVisa1(); + $card->threeDSecure = $threeDeeInfo; + + $response = $card->charge(1.01) + ->withCurrency('USD') + ->withClientTransactionId('test22_' . time()) + ->execute(); + + $this->assertEquals('00', $response->responseCode); + } + + public function test23MC3DS_V1 () { + $threeDeeInfo = new ThreeDSecure(); + $threeDeeInfo->eci = 5; + $threeDeeInfo->secureCode = '12345678901234567890123456789012'; + $threeDeeInfo->authenticationType = '21'; + $threeDeeInfo->ucafIndicator = UcafIndicator::FULLY_AUTHENTICATED; + $threeDeeInfo->setVersion(Secure3dVersion::ONE); + + $card = $this->getMCUnclassifiedTIC(); + $card->threeDSecure = $threeDeeInfo; + + $response = $card->charge(34.02) + ->withCurrency('USD') + ->withClientTransactionId('test23_' . time()) + ->execute(); + + $this->assertEquals('00', $response->responseCode); + } + + public function test24MC3DS_V2 () { + $threeDeeInfo = new ThreeDSecure(); + $threeDeeInfo->eci = 5; + $threeDeeInfo->secureCode = '12345678901234567890123456789012'; + $threeDeeInfo->authenticationType = '21'; + $threeDeeInfo->directoryServerTransactionId = 'c272b04f-6e7b-43a2-bb78-90f4fb94aa25'; + $threeDeeInfo->ucafIndicator = UcafIndicator::FULLY_AUTHENTICATED; + $threeDeeInfo->setVersion(Secure3dVersion::TWO); + + $card = $this->getMCUnclassifiedTIC(); + $card->threeDSecure = $threeDeeInfo; + + $response = $card->charge(34.06) + ->withCurrency('USD') + ->withClientTransactionId('test24_' . time()) + ->execute(); + + $this->assertEquals('00', $response->responseCode); + } + + public function test25Discover3DS () { + $threeDeeInfo = new ThreeDSecure(); + $threeDeeInfo->eci = 5; + $threeDeeInfo->secureCode = '1234567890123456789012345678901234567890'; + // $threeDeeInfo->ucafIndicator = UcafIndicator::FULLY_AUTHENTICATED; + // $threeDeeInfo->setVersion(Secure3dVersion::ONE); + + $card = $this->getDiscover(); + $card->threeDSecure = $threeDeeInfo; + + $response = $card->charge(45.02) + ->withCurrency('USD') + ->withClientTransactionId('test25_' . time()) + ->execute(); + + $this->assertEquals('00', $response->responseCode); + } + + public function test26Amex3DS () { + $threeDeeInfo = new ThreeDSecure(); + $threeDeeInfo->eci = 5; + $threeDeeInfo->secureCode = '1234567890123456789012345678901234567890'; + // $threeDeeInfo->ucafIndicator = UcafIndicator::FULLY_AUTHENTICATED; + // $threeDeeInfo->setVersion(Secure3dVersion::ONE); + + $card = $this->getAmex(); + $card->threeDSecure = $threeDeeInfo; + + $response = $card->charge(32.02) + ->withCurrency('USD') + ->withClientTransactionId('test26_' . time()) + ->execute(); + + $this->assertEquals('00', $response->responseCode); + } + + public function test27MC3DS_V2_2 () { + $threeDeeInfo = new ThreeDSecure(); + $threeDeeInfo->eci = 5; + $threeDeeInfo->authenticationValue = 'ODQzNjgwNjU0ZjM3N2JmYTg0NTM='; + $threeDeeInfo->authenticationType = '24'; + $threeDeeInfo->directoryServerTransactionId = 'c272b04f-6e7b-43a2-bb78-90f4fb94aa25'; + $threeDeeInfo->ucafIndicator = UcafIndicator::MERCHANT_RISK_BASED; + $threeDeeInfo->setVersion(Secure3dVersion::TWO); + + $card = $this->getMCUnclassifiedTIC(); + $card->threeDSecure = $threeDeeInfo; + + $response = $card->charge(34.05) + ->withCurrency('USD') + ->withClientTransactionId('test27_' . time()) + ->execute(); + + $this->assertEquals('00', $response->responseCode); + } + + public function test28Visa3DS_ECI6 () { + $threeDeeInfo = new ThreeDSecure(); + $threeDeeInfo->eci = 6; + $threeDeeInfo->secureCode = '1234567890123456789012345678901234567890'; + // $threeDeeInfo->ucafIndicator = UcafIndicator::FULLY_AUTHENTICATED; + // $threeDeeInfo->setVersion(Secure3dVersion::TWO); + + $card = $this->getVisa1(); + $card->threeDSecure = $threeDeeInfo; + + $response = $card->charge(.81) + ->withCurrency('USD') + ->withClientTransactionId('test28_' . time()) + ->execute(); + + $this->assertEquals('00', $response->responseCode); + } + + public function test29MC3DS_ECI6 () { + $threeDeeInfo = new ThreeDSecure(); + $threeDeeInfo->eci = 6; + $threeDeeInfo->secureCode = '12345678901234567890123456789012'; + $threeDeeInfo->ucafIndicator = UcafIndicator::FULLY_AUTHENTICATED; + $threeDeeInfo->setVersion(Secure3dVersion::ONE); + + $card = $this->getMCUnclassifiedTIC(); + $card->threeDSecure = $threeDeeInfo; + + $response = $card->charge(29.00) + ->withCurrency('USD') + ->withClientTransactionId('test29_' . time()) + ->execute(); + + $this->assertEquals('00', $response->responseCode); + } + + public function test30SaleVisaCIT () { + $storedcreds = new StoredCredential; + $storedcreds->initiator = StoredCredentialInitiator::MERCHANT; + + $cardAsMUT = $this->getVisa1(); + $cardAsMUT->number = self::$test30MUT; + + $response = $cardAsMUT->charge(14.00) + ->withCurrency('USD') + ->withAddress($this->getAVSData()) + ->withClientTransactionId('test30_' . time()) + ->withStoredCredential($storedcreds) + ->execute(); + + $this->assertEquals('00', $response->responseCode); + } + + public function test31SaleNonVisaCIT () { + $storedcreds = new StoredCredential; + $storedcreds->initiator = StoredCredentialInitiator::MERCHANT; + + $cardAsMUT = $this->getMCUnclassifiedTIC(); + $cardAsMUT->number = self::$test31MUT; + + $response = $cardAsMUT->charge(15.00) + ->withCurrency('USD') + ->withAddress($this->getAVSData()) + ->withClientTransactionId('test31_' . time()) + ->withStoredCredential($storedcreds) + ->execute(); + + $this->assertEquals('00', $response->responseCode); + } + + public function test32VisaMultiCapture () { + $response = $this->getVisa1()->authorize(30.00) + ->withCurrency('USD') + ->withAddress($this->getAVSData()) + ->withClientTransactionId('test32_' . time()) + ->execute(); + + $this->assertEquals('00', $response->responseCode); + + $firstCaptureResponse = $response->capture(15.00) + ->withMultiCapture(1, 2) + ->execute(); + + $this->assertEquals('00', $firstCaptureResponse->responseCode); + + $secondCaptureResponse = $response->capture(15.00) + ->withMultiCapture(2, 2) + ->execute(); + + $this->assertEquals('00', $secondCaptureResponse->responseCode); + } + + public function test33MCMultiCapture () { + $response = $this->getMCUnclassifiedTIC()->authorize(50.00) + ->withCurrency('USD') + ->withAddress($this->getAVSData()) + ->withClientTransactionId('test33_' . time()) + ->execute(); + + $this->assertEquals('00', $response->responseCode); + + $firstCaptureResponse = $response->capture(30.00) + ->withMultiCapture(1, 3) + ->execute(); + + $this->assertEquals('00', $firstCaptureResponse->responseCode); + + $secondCaptureResponse = $response->capture(10.00) + ->withMultiCapture(2, 3) + ->execute(); + + $this->assertEquals('00', $secondCaptureResponse->responseCode); + + $thirdCaptureResponse = $response->capture(10.00) + ->withMultiCapture(3, 3) + ->execute(); + + $this->assertEquals('00', $thirdCaptureResponse->responseCode); + } + + public function test34MCMultiCapture () { + $response = $this->getMCUnclassifiedTIC()->authorize(60.00) + ->withCurrency('USD') + ->withAddress($this->getAVSData()) + ->withClientTransactionId('test34_' . time()) + ->execute(); + + $this->assertEquals('00', $response->responseCode); + + $captureResponse = $response->capture() + ->withMultiCapture() + ->execute(); + + $this->assertEquals('00', $captureResponse->responseCode); + } + + public function test35CloseBatch () { + $response = BatchService::closeBatch(); + + $this->assertEquals('00', $response->responseCode); + } + + public function getVisa1 () { + $card = new CreditCardData; + $card->number = 4012000098765439; + $card->expYear = 20; // magic number + $card->expMonth = 12; + $card->cvn = 999; + $card->cardType = CardType::VISA; + return $card; + } + + public function getVisa2 () { + $card = new CreditCardData; + $card->number = 4012881888818888; + $card->expYear = 20; // magic number + $card->expMonth = 12; + $card->cvn = 999; + $card->cardType = CardType::VISA; + return $card; + } + + public function getMCUnclassifiedTIC () { + $card = new CreditCardData; + $card->number = 5146315000000055; + $card->expYear = 20; // magic number + $card->expMonth = 12; + $card->cvn = 998; + $card->cardType = CardType::MASTERCARD; + return $card; + } + + public function getMCSwipeTIC () { + $card = new CreditCardData; + $card->number = 5146312200000035; + $card->expYear = 20; // magic number + $card->expMonth = 12; + $card->cvn = 998; + $card->cardType = CardType::MASTERCARD; + return $card; + } + + public function getMCKeyedTIC () { + $card = new CreditCardData; + $card->number = 5146312620000045; + $card->expYear = 20; // magic number + $card->expMonth = 12; + $card->cvn = 998; + $card->cardType = CardType::MASTERCARD; + return $card; + } + + public function getMC2BIN () { + $card = new CreditCardData; + $card->number = 2223000048400011; + $card->expYear = 25; // magic number + $card->expMonth = 12; + $card->cvn = 998; + $card->cardType = CardType::MASTERCARD; + return $card; + } + + public function getAmex () { + $card = new CreditCardData; + $card->number = 371449635392376; + $card->expYear = 25; // magic number + $card->expMonth = 12; + $card->cvn = 9997; + $card->cardType = CardType::AMEX; + return $card; + } + + public function getDiscover () { + $card = new CreditCardData; + $card->number = 6011000993026909; + $card->expYear = 20; // magic number + $card->expMonth = 12; + $card->cvn = 996; + $card->cardType = CardType::DISCOVER; + return $card; + } + + public function getDiscoverCUP () { + $card = new CreditCardData; + $card->number = 6282000123842342; + $card->expYear = 20; // magic number + $card->expMonth = 12; + $card->cvn = 996; + $card->cardType = CardType::DISCOVER; + return $card; + } + + public function getDiscoverCUP2 () { + $card = new CreditCardData; + $card->number = 6221261111112650; + $card->expYear = 20; // magic number + $card->expMonth = 12; + $card->cvn = 996; + $card->cardType = CardType::DISCOVER; + return $card; + } + + public function getDiners () { + $card = new CreditCardData; + $card->number = 3055155515160018; + $card->expYear = 20; // magic number + $card->expMonth = 12; + $card->cvn = 996; + $card->cardType = CardType::DINERS; + return $card; + } + + public function getJCB () { + $card = new CreditCardData; + $card->number = 3530142019945859; + $card->expYear = 20; // magic number + $card->expMonth = 12; + $card->cvn = 996; + $card->cardType = CardType::JCB; + return $card; + } + + public function getAVSData () { + $address = new Address(); + $address->streetAddress1 = '8320'; + $address->postalCode = '85284'; + return $address; + } +} diff --git a/test/Integration/Gateways/TransITConnector/Certification/Token_Request_Only.php b/test/Integration/Gateways/TransITConnector/Certification/Token_Request_Only.php index 8f218199..fd0e7340 100644 --- a/test/Integration/Gateways/TransITConnector/Certification/Token_Request_Only.php +++ b/test/Integration/Gateways/TransITConnector/Certification/Token_Request_Only.php @@ -1,262 +1,262 @@ -getConfig()); - } - - public function getConfig() { - $config = new TransitConfig(); - $config->merchantId = '887000003226'; - $config->username = 'TA5622118'; - $config->password = 'f8mapGqWrE^rVaA9'; - $config->deviceId = '88700000322601'; - $config->transactionKey = '2HZFSJ98G4XEGHXGP31IRLLG8H3XAWB2'; - $config->developerId = '003226G001'; - $config->acceptorConfig = new AcceptorConfig(); - $config->acceptorConfig->operatingEnvironment = OperatingEnvironment::ON_MERCHANT_PREMISES_ATTENDED; - $config->acceptorConfig->cardDataSource = CardDataSource::INTERNET; - return $config; - } - - public function getMailConfig() { - $mailConfig = $this->getConfig(); - $mailConfig->acceptorConfig->cardDataSource = CardDataSource::MAIL; - $mailConfig->acceptorConfig->operatingEnvironment = OperatingEnvironment::ON_MERCHANT_PREMISES_ATTENDED; - return $mailConfig; - } - - public function getPhoneConfig() { - $phoneConfig = $this->getConfig(); - $phoneConfig->acceptorConfig->cardDataSource = CardDataSource::PHONE; - $phoneConfig->acceptorConfig->operatingEnvironment = OperatingEnvironment::ON_MERCHANT_PREMISES_ATTENDED; - return $phoneConfig; - } - - public function test01GenerateVisaMUT() { - $response = $this->getVisa1()->tokenize()->execute(); - - $this->assertEquals('00', $response->responseCode); - $this->assertNotNull($response->token); - } - - public function test02GenerateMasterCardMUT() { - $response = $this->getMCUnclassifiedTIC()->tokenize()->execute(); - - $this->assertEquals('00', $response->responseCode); - $this->assertNotNull($response->token); - } - - public function test03GenerateMasterCardBin2MUT() { - $response = $this->getMC2BIN()->tokenize()->execute(); - - $this->assertEquals('00', $response->responseCode); - $this->assertNotNull($response->token); - } - - public function test04GenerateDiscoverMUT() { - $response = $this->getDiscover()->tokenize()->execute(); - - $this->assertEquals('00', $response->responseCode); - $this->assertNotNull($response->token); - } - - public function test05GenerateAmexMUT() { - ServicesContainer::configureService($this->getPhoneConfig()); - - $response = $this->getAmex()->tokenize()->execute(); - - $this->assertEquals('00', $response->responseCode); - $this->assertNotNull($response->token); - } - - public function test06GenerateJCB_MUT() { - ServicesContainer::configureService($this->getMailConfig()); - - $response = $this->getJCB()->tokenize()->execute(); - - $this->assertEquals('00', $response->responseCode); - $this->assertNotNull($response->token); - } - - public function test07GeneratDiscoverCUP_MUT() { - ServicesContainer::configureService($this->getMailConfig()); - - $response = $this->getDiscoverCUP()->tokenize()->execute(); - - $this->assertEquals('00', $response->responseCode); - $this->assertNotNull($response->token); - } - - public function test08GenerateDinersMUT() { - ServicesContainer::configureService($this->getPhoneConfig()); - - $response = $this->getDiners()->tokenize()->execute(); - - $this->assertEquals('00', $response->responseCode); - $this->assertNotNull($response->token); - } - - public function getVisa1 () { - $card = new CreditCardData; - $card->number = 4012000098765439; - $card->expYear = 20; // magic number - $card->expMonth = 12; - $card->cvn = 999; - $card->cardType = CardType::VISA; - // $card->readerPresent = true; - $card->cardPresent = false; - return $card; - } - - public function getVisa2 () { - $card = new CreditCardData; - $card->number = 4012881888818888; - $card->expYear = 20; // magic number - $card->expMonth = 12; - $card->cvn = 999; - $card->cardType = CardType::VISA; - // $card->readerPresent = true; - $card->cardPresent = false; - return $card; - } - - public function getMCUnclassifiedTIC () { - $card = new CreditCardData; - $card->number = 5146315000000055; - $card->expYear = 20; // magic number - $card->expMonth = 12; - $card->cvn = 998; - $card->cardType = CardType::MASTERCARD; - // $card->readerPresent = true; - $card->cardPresent = false; - return $card; - } - - public function getMCSwipeTIC () { - $card = new CreditCardData; - $card->number = 5146312200000035; - $card->expYear = 20; // magic number - $card->expMonth = 12; - $card->cvn = 998; - $card->cardType = CardType::MASTERCARD; - // $card->readerPresent = true; - $card->cardPresent = false; - return $card; - } - - public function getMCKeyedTIC () { - $card = new CreditCardData; - $card->number = 5146312620000045; - $card->expYear = 20; // magic number - $card->expMonth = 12; - $card->cvn = 998; - $card->cardType = CardType::MASTERCARD; - // $card->readerPresent = true; - $card->cardPresent = false; - return $card; - } - - public function getMC2BIN () { - $card = new CreditCardData; - $card->number = 2223000048400011; - $card->expYear = 25; // magic number - $card->expMonth = 12; - $card->cvn = 998; - $card->cardType = CardType::MASTERCARD; - // $card->readerPresent = true; - $card->cardPresent = false; - return $card; - } - - public function getAmex () { - $card = new CreditCardData; - $card->number = 371449635392376; - $card->expYear = 25; // magic number - $card->expMonth = 12; - $card->cvn = 9997; - $card->cardType = CardType::AMEX; - // $card->readerPresent = true; - $card->cardPresent = false; - return $card; - } - - public function getDiscover () { - $card = new CreditCardData; - $card->number = 6011000993026909; - $card->expYear = 20; // magic number - $card->expMonth = 12; - $card->cvn = 996; - $card->cardType = CardType::DISCOVER; - // $card->readerPresent = true; - $card->cardPresent = false; - return $card; - } - - public function getDiscoverCUP () { - $card = new CreditCardData; - $card->number = 6282000123842342; - $card->expYear = 20; // magic number - $card->expMonth = 12; - $card->cvn = 996; - $card->cardType = CardType::DISCOVER; - // $card->readerPresent = true; - $card->cardPresent = false; - return $card; - } - - public function getDiscoverCUP2 () { - $card = new CreditCardData; - $card->number = 6221261111112650; - $card->expYear = 20; // magic number - $card->expMonth = 12; - $card->cvn = 996; - $card->cardType = CardType::DISCOVER; - // $card->readerPresent = true; - $card->cardPresent = false; - return $card; - } - - public function getDiners () { - $card = new CreditCardData; - $card->number = 3055155515160018; - $card->expYear = 20; // magic number - $card->expMonth = 12; - $card->cvn = 996; - $card->cardType = CardType::DINERS; - // $card->readerPresent = true; - $card->cardPresent = false; - return $card; - } - - public function getJCB () { - $card = new CreditCardData; - $card->number = 3530142019945859; - $card->expYear = 20; // magic number - $card->expMonth = 12; - $card->cvn = 996; - $card->cardType = CardType::JCB; - // $card->readerPresent = true; - $card->cardPresent = false; - return $card; - } - - public function getAVSData () { - $address = new Address(); - $address->streetAddress1 = '8320'; - $address->postalCode = '85284'; - return $address; - } -} +getConfig()); + } + + public function getConfig() { + $config = new TransitConfig(); + $config->merchantId = '887000003226'; + $config->username = 'TA5622118'; + $config->password = 'f8mapGqWrE^rVaA9'; + $config->deviceId = '88700000322601'; + $config->transactionKey = '2HZFSJ98G4XEGHXGP31IRLLG8H3XAWB2'; + $config->developerId = '003226G001'; + $config->acceptorConfig = new AcceptorConfig(); + $config->acceptorConfig->operatingEnvironment = OperatingEnvironment::ON_MERCHANT_PREMISES_ATTENDED; + $config->acceptorConfig->cardDataSource = CardDataSource::INTERNET; + return $config; + } + + public function getMailConfig() { + $mailConfig = $this->getConfig(); + $mailConfig->acceptorConfig->cardDataSource = CardDataSource::MAIL; + $mailConfig->acceptorConfig->operatingEnvironment = OperatingEnvironment::ON_MERCHANT_PREMISES_ATTENDED; + return $mailConfig; + } + + public function getPhoneConfig() { + $phoneConfig = $this->getConfig(); + $phoneConfig->acceptorConfig->cardDataSource = CardDataSource::PHONE; + $phoneConfig->acceptorConfig->operatingEnvironment = OperatingEnvironment::ON_MERCHANT_PREMISES_ATTENDED; + return $phoneConfig; + } + + public function test01GenerateVisaMUT() { + $response = $this->getVisa1()->tokenize()->execute(); + + $this->assertEquals('00', $response->responseCode); + $this->assertNotNull($response->token); + } + + public function test02GenerateMasterCardMUT() { + $response = $this->getMCUnclassifiedTIC()->tokenize()->execute(); + + $this->assertEquals('00', $response->responseCode); + $this->assertNotNull($response->token); + } + + public function test03GenerateMasterCardBin2MUT() { + $response = $this->getMC2BIN()->tokenize()->execute(); + + $this->assertEquals('00', $response->responseCode); + $this->assertNotNull($response->token); + } + + public function test04GenerateDiscoverMUT() { + $response = $this->getDiscover()->tokenize()->execute(); + + $this->assertEquals('00', $response->responseCode); + $this->assertNotNull($response->token); + } + + public function test05GenerateAmexMUT() { + ServicesContainer::configureService($this->getPhoneConfig()); + + $response = $this->getAmex()->tokenize()->execute(); + + $this->assertEquals('00', $response->responseCode); + $this->assertNotNull($response->token); + } + + public function test06GenerateJCB_MUT() { + ServicesContainer::configureService($this->getMailConfig()); + + $response = $this->getJCB()->tokenize()->execute(); + + $this->assertEquals('00', $response->responseCode); + $this->assertNotNull($response->token); + } + + public function test07GeneratDiscoverCUP_MUT() { + ServicesContainer::configureService($this->getMailConfig()); + + $response = $this->getDiscoverCUP()->tokenize()->execute(); + + $this->assertEquals('00', $response->responseCode); + $this->assertNotNull($response->token); + } + + public function test08GenerateDinersMUT() { + ServicesContainer::configureService($this->getPhoneConfig()); + + $response = $this->getDiners()->tokenize()->execute(); + + $this->assertEquals('00', $response->responseCode); + $this->assertNotNull($response->token); + } + + public function getVisa1 () { + $card = new CreditCardData; + $card->number = 4012000098765439; + $card->expYear = 20; // magic number + $card->expMonth = 12; + $card->cvn = 999; + $card->cardType = CardType::VISA; + // $card->readerPresent = true; + $card->cardPresent = false; + return $card; + } + + public function getVisa2 () { + $card = new CreditCardData; + $card->number = 4012881888818888; + $card->expYear = 20; // magic number + $card->expMonth = 12; + $card->cvn = 999; + $card->cardType = CardType::VISA; + // $card->readerPresent = true; + $card->cardPresent = false; + return $card; + } + + public function getMCUnclassifiedTIC () { + $card = new CreditCardData; + $card->number = 5146315000000055; + $card->expYear = 20; // magic number + $card->expMonth = 12; + $card->cvn = 998; + $card->cardType = CardType::MASTERCARD; + // $card->readerPresent = true; + $card->cardPresent = false; + return $card; + } + + public function getMCSwipeTIC () { + $card = new CreditCardData; + $card->number = 5146312200000035; + $card->expYear = 20; // magic number + $card->expMonth = 12; + $card->cvn = 998; + $card->cardType = CardType::MASTERCARD; + // $card->readerPresent = true; + $card->cardPresent = false; + return $card; + } + + public function getMCKeyedTIC () { + $card = new CreditCardData; + $card->number = 5146312620000045; + $card->expYear = 20; // magic number + $card->expMonth = 12; + $card->cvn = 998; + $card->cardType = CardType::MASTERCARD; + // $card->readerPresent = true; + $card->cardPresent = false; + return $card; + } + + public function getMC2BIN () { + $card = new CreditCardData; + $card->number = 2223000048400011; + $card->expYear = 25; // magic number + $card->expMonth = 12; + $card->cvn = 998; + $card->cardType = CardType::MASTERCARD; + // $card->readerPresent = true; + $card->cardPresent = false; + return $card; + } + + public function getAmex () { + $card = new CreditCardData; + $card->number = 371449635392376; + $card->expYear = 25; // magic number + $card->expMonth = 12; + $card->cvn = 9997; + $card->cardType = CardType::AMEX; + // $card->readerPresent = true; + $card->cardPresent = false; + return $card; + } + + public function getDiscover () { + $card = new CreditCardData; + $card->number = 6011000993026909; + $card->expYear = 20; // magic number + $card->expMonth = 12; + $card->cvn = 996; + $card->cardType = CardType::DISCOVER; + // $card->readerPresent = true; + $card->cardPresent = false; + return $card; + } + + public function getDiscoverCUP () { + $card = new CreditCardData; + $card->number = 6282000123842342; + $card->expYear = 20; // magic number + $card->expMonth = 12; + $card->cvn = 996; + $card->cardType = CardType::DISCOVER; + // $card->readerPresent = true; + $card->cardPresent = false; + return $card; + } + + public function getDiscoverCUP2 () { + $card = new CreditCardData; + $card->number = 6221261111112650; + $card->expYear = 20; // magic number + $card->expMonth = 12; + $card->cvn = 996; + $card->cardType = CardType::DISCOVER; + // $card->readerPresent = true; + $card->cardPresent = false; + return $card; + } + + public function getDiners () { + $card = new CreditCardData; + $card->number = 3055155515160018; + $card->expYear = 20; // magic number + $card->expMonth = 12; + $card->cvn = 996; + $card->cardType = CardType::DINERS; + // $card->readerPresent = true; + $card->cardPresent = false; + return $card; + } + + public function getJCB () { + $card = new CreditCardData; + $card->number = 3530142019945859; + $card->expYear = 20; // magic number + $card->expMonth = 12; + $card->cvn = 996; + $card->cardType = CardType::JCB; + // $card->readerPresent = true; + $card->cardPresent = false; + return $card; + } + + public function getAVSData () { + $address = new Address(); + $address->streetAddress1 = '8320'; + $address->postalCode = '85284'; + return $address; + } +} diff --git a/test/Integration/Gateways/TransITConnector/CommercialCardTest.php b/test/Integration/Gateways/TransITConnector/CommercialCardTest.php index f3cafac1..fbe24b0f 100644 --- a/test/Integration/Gateways/TransITConnector/CommercialCardTest.php +++ b/test/Integration/Gateways/TransITConnector/CommercialCardTest.php @@ -1,221 +1,221 @@ -getConfig()); - } - - protected function getConfig() { - $config = new TransitConfig(); - $config->merchantId = '887000003226'; - $config->username = 'TA5622118'; - $config->password = 'f8mapGqWrE^rVaA9'; - $config->deviceId = '88700000322602'; - $config->transactionKey = '2HZFSJ98G4XEGHXGP31IRLLG8H3XAWB2'; - $config->developerId = '003226G001'; - $config->gatewayProvider = GatewayProvider::TRANSIT; - $config->acceptorConfig = new AcceptorConfig(); - return $config; - } - - protected function getAddy() { - $addy = new Address(); - $addy->streetAddress1 = 'address line 1 contents'; - $addy->postalCode = '47130'; - return $addy; - } - - protected function getVisaManual() { - $visaManual = new CreditCardData(); - $visaManual->number = '4012000098765439'; - $visaManual->expMonth = 12; - $visaManual->expYear = TestCards::validCardExpYear(); - $visaManual->cvn = '999'; - return $visaManual; - } - - protected function getMasterCardManual() { - $masterCardManual = new CreditCardData(); - $masterCardManual->number = '5146315000000055'; - $masterCardManual->expMonth = 12; - $masterCardManual->expYear = TestCards::validCardExpYear(); - $masterCardManual->cvn = '998'; - return $masterCardManual; - } - - protected function getAmexManual() { - $amexManual = new CreditCardData(); - $amexManual->number = "371449635392376"; - $amexManual->expMonth = 12; - $amexManual->expYear = TestCards::validCardExpYear(); - $amexManual->cvn = "9997"; - return $amexManual; - } - - // These are all stolen from dotnet cert file - public function test01VisaManualLevelII() { - $commercialData = new CommercialData(TaxType::NOT_USED); - $commercialData->poNumber = '9876543210'; - $commercialData->taxAmount = 0; - - $response = $this->getVisaManual()->charge(52) - ->withCurrency("USD") - ->withCommercialData($commercialData) - ->withAddress($this->getAddy()) - ->withDescription("Test_001_Visa_Level_II_Sale") - ->execute(); - - $this->assertEquals('00', $response->responseCode); - } - - public function test02MasterCardManualLevelII() { - $commercialData = new CommercialData(TaxType::SALES_TAX); - $commercialData->poNumber = '9876543210'; - $commercialData->taxAmount = .02; - - $response = $this->getMasterCardManual()->charge(.52) - ->withCurrency("USD") - ->withCommercialData($commercialData) - ->withAddress($this->getAddy()) - ->execute(); - - $this->assertEquals('00', $response->responseCode); - } - - public function test03AmexManualLevelII() { - $commercialData = new CommercialData(TaxType::NOT_USED); - $commercialData->supplierReferenceNumber = "123456"; - $commercialData->customerReferenceId = "987654"; - $commercialData->destinationPostalCode = "85284"; - $commercialData->description = "AMEX LEVEL 2 TEST CASE"; - $commercialData->taxAmount = 0; - - $response = $this->getAmexManual()->charge(1.50) - ->withCurrency('USD') - ->withCommercialData($commercialData) - ->withAddress($this->getAddy()) - ->execute(); - - $this->assertEquals('00', $response->responseCode); - } - - public function test04VisaManualLevelIII() { - $commercialData = new CommercialData(TaxType::NOT_USED, CommercialIndicator::LEVEL_III); - $commercialData->poNumber = 1784951399984509620; - $commercialData->taxAmount = .01; - $commercialData->destinationPostalCode = '85212'; - $commercialData->destinationCountryCode = "USA"; - $commercialData->originPostalCode = "22193"; - $commercialData->summaryCommodityCode = "SCC"; - $commercialData->customerVatNumber = "123456789"; - $commercialData->vatInvoiceNumber = "UVATREF162"; - $commercialData->orderDate = date('m/d/Y'); - $commercialData->freightAmount = 0.01; - $commercialData->dutyAmount = 0.01; - $commercialData->additionalTaxDetails = new AdditionalTaxDetails( - .01, - TaxCategory::VAT, - .04, - "VAT" - ); - - $lineItem1 = new CommercialLineItem; - $lineItem1->productCode = "PRDCD1"; - $lineItem1->name = "PRDCD1NAME"; - $lineItem1->unitCost = 0.01; - $lineItem1->quantity = 1; - $lineItem1->unitOfMeasure = "METER"; - $lineItem1->description = "PRODUCT 1 NOTES"; - $lineItem1->commodityCode = "12DIGIT ACCO"; - $lineItem1->alternateTaxId = "1234567890"; - $lineItem1->creditDebitIndicator = CreditDebitIndicator::CREDIT; - $lineItem1->discountDetails = new DiscountDetails( - .50, - "Indep Sale 1", - .1, - "SALE" - ); - - $lineItem2 = new CommercialLineItem; - $lineItem2->productCode = "PRDCD2"; - $lineItem2->name = "PRDCD2NAME"; - $lineItem2->unitCost = 0.01; - $lineItem2->quantity = 1; - $lineItem2->unitOfMeasure = "METER"; - $lineItem2->description = "PRODUCT 2 NOTES"; - $lineItem2->commodityCode = "12DIGIT ACCO"; - $lineItem2->alternateTaxId = "1234567890"; - $lineItem2->creditDebitIndicator = CreditDebitIndicator::DEBIT; - $lineItem2->discountDetails = new DiscountDetails( - .50, - "Indep Sale 1", - .1, - "SALE" - ); - - $commercialData->addLineItems($lineItem1, $lineItem2); // can pass multiple line items or just call this function multiple times - - $response = $this->getVisaManual()->charge(.53) - ->withCurrency('USD') - ->withCommercialData($commercialData) - ->withAddress($this->getAddy()) - ->execute(); - - $this->assertEquals('00', $response->responseCode); - } - - public function test05MasterCardManualLevelIII() { - $commercialData = new CommercialData(TaxType::NOT_USED, CommercialIndicator::LEVEL_III); - $commercialData->poNumber = "9876543210"; - $commercialData->taxAmount = 0.01; - $commercialData->destinationPostalCode = "85212"; - $commercialData->destinationCountryCode = "USA"; - $commercialData->originPostalCode = "22193"; - $commercialData->summaryCommodityCode = "SCC"; - $commercialData->customerVatNumber = "123456789"; - $commercialData->vatInvoiceNumber = "UVATREF162"; - $commercialData->orderDate = date('m/d/Y'); - $commercialData->freightAmount = 0.01; - $commercialData->dutyAmount = 0.01; - $commercialData->additionalTaxDetails = new AdditionalTaxDetails(.01, TaxCategory::VAT, .04, "VAT"); - - $lineItem = new CommercialLineItem; - $lineItem->productCode = "PRDCD1"; - $lineItem->name = "PRDCD1NAME"; - $lineItem->unitCost = 0.01; - $lineItem->quantity = 1; - $lineItem->unitOfMeasure = "METER"; - $lineItem->description = "PRODUCT 1 NOTES"; - $lineItem->commodityCode = "12DIGIT ACCO"; - $lineItem->alternateTaxId = "1234567890"; - $lineItem->creditDebitIndicator = CreditDebitIndicator::CREDIT; - $commercialData->addLineItems($lineItem); - - $response = $this->getMasterCardManual()->charge(.53) - ->withCurrency('USD') - ->withCommercialData($commercialData) - ->withAddress($this->getAddy()) - ->execute(); - - $this->assertEquals('00', $response->responseCode); - } -} +getConfig()); + } + + protected function getConfig() { + $config = new TransitConfig(); + $config->merchantId = '887000003226'; + $config->username = 'TA5622118'; + $config->password = 'f8mapGqWrE^rVaA9'; + $config->deviceId = '88700000322602'; + $config->transactionKey = '2HZFSJ98G4XEGHXGP31IRLLG8H3XAWB2'; + $config->developerId = '003226G001'; + $config->gatewayProvider = GatewayProvider::TRANSIT; + $config->acceptorConfig = new AcceptorConfig(); + return $config; + } + + protected function getAddy() { + $addy = new Address(); + $addy->streetAddress1 = 'address line 1 contents'; + $addy->postalCode = '47130'; + return $addy; + } + + protected function getVisaManual() { + $visaManual = new CreditCardData(); + $visaManual->number = '4012000098765439'; + $visaManual->expMonth = 12; + $visaManual->expYear = TestCards::validCardExpYear(); + $visaManual->cvn = '999'; + return $visaManual; + } + + protected function getMasterCardManual() { + $masterCardManual = new CreditCardData(); + $masterCardManual->number = '5146315000000055'; + $masterCardManual->expMonth = 12; + $masterCardManual->expYear = TestCards::validCardExpYear(); + $masterCardManual->cvn = '998'; + return $masterCardManual; + } + + protected function getAmexManual() { + $amexManual = new CreditCardData(); + $amexManual->number = "371449635392376"; + $amexManual->expMonth = 12; + $amexManual->expYear = TestCards::validCardExpYear(); + $amexManual->cvn = "9997"; + return $amexManual; + } + + // These are all stolen from dotnet cert file + public function test01VisaManualLevelII() { + $commercialData = new CommercialData(TaxType::NOT_USED); + $commercialData->poNumber = '9876543210'; + $commercialData->taxAmount = 0; + + $response = $this->getVisaManual()->charge(52) + ->withCurrency("USD") + ->withCommercialData($commercialData) + ->withAddress($this->getAddy()) + ->withDescription("Test_001_Visa_Level_II_Sale") + ->execute(); + + $this->assertEquals('00', $response->responseCode); + } + + public function test02MasterCardManualLevelII() { + $commercialData = new CommercialData(TaxType::SALES_TAX); + $commercialData->poNumber = '9876543210'; + $commercialData->taxAmount = .02; + + $response = $this->getMasterCardManual()->charge(.52) + ->withCurrency("USD") + ->withCommercialData($commercialData) + ->withAddress($this->getAddy()) + ->execute(); + + $this->assertEquals('00', $response->responseCode); + } + + public function test03AmexManualLevelII() { + $commercialData = new CommercialData(TaxType::NOT_USED); + $commercialData->supplierReferenceNumber = "123456"; + $commercialData->customerReferenceId = "987654"; + $commercialData->destinationPostalCode = "85284"; + $commercialData->description = "AMEX LEVEL 2 TEST CASE"; + $commercialData->taxAmount = 0; + + $response = $this->getAmexManual()->charge(1.50) + ->withCurrency('USD') + ->withCommercialData($commercialData) + ->withAddress($this->getAddy()) + ->execute(); + + $this->assertEquals('00', $response->responseCode); + } + + public function test04VisaManualLevelIII() { + $commercialData = new CommercialData(TaxType::NOT_USED, CommercialIndicator::LEVEL_III); + $commercialData->poNumber = 1784951399984509620; + $commercialData->taxAmount = .01; + $commercialData->destinationPostalCode = '85212'; + $commercialData->destinationCountryCode = "USA"; + $commercialData->originPostalCode = "22193"; + $commercialData->summaryCommodityCode = "SCC"; + $commercialData->customerVatNumber = "123456789"; + $commercialData->vatInvoiceNumber = "UVATREF162"; + $commercialData->orderDate = date('m/d/Y'); + $commercialData->freightAmount = 0.01; + $commercialData->dutyAmount = 0.01; + $commercialData->additionalTaxDetails = new AdditionalTaxDetails( + .01, + TaxCategory::VAT, + .04, + "VAT" + ); + + $lineItem1 = new CommercialLineItem; + $lineItem1->productCode = "PRDCD1"; + $lineItem1->name = "PRDCD1NAME"; + $lineItem1->unitCost = 0.01; + $lineItem1->quantity = 1; + $lineItem1->unitOfMeasure = "METER"; + $lineItem1->description = "PRODUCT 1 NOTES"; + $lineItem1->commodityCode = "12DIGIT ACCO"; + $lineItem1->alternateTaxId = "1234567890"; + $lineItem1->creditDebitIndicator = CreditDebitIndicator::CREDIT; + $lineItem1->discountDetails = new DiscountDetails( + .50, + "Indep Sale 1", + .1, + "SALE" + ); + + $lineItem2 = new CommercialLineItem; + $lineItem2->productCode = "PRDCD2"; + $lineItem2->name = "PRDCD2NAME"; + $lineItem2->unitCost = 0.01; + $lineItem2->quantity = 1; + $lineItem2->unitOfMeasure = "METER"; + $lineItem2->description = "PRODUCT 2 NOTES"; + $lineItem2->commodityCode = "12DIGIT ACCO"; + $lineItem2->alternateTaxId = "1234567890"; + $lineItem2->creditDebitIndicator = CreditDebitIndicator::DEBIT; + $lineItem2->discountDetails = new DiscountDetails( + .50, + "Indep Sale 1", + .1, + "SALE" + ); + + $commercialData->addLineItems($lineItem1, $lineItem2); // can pass multiple line items or just call this function multiple times + + $response = $this->getVisaManual()->charge(.53) + ->withCurrency('USD') + ->withCommercialData($commercialData) + ->withAddress($this->getAddy()) + ->execute(); + + $this->assertEquals('00', $response->responseCode); + } + + public function test05MasterCardManualLevelIII() { + $commercialData = new CommercialData(TaxType::NOT_USED, CommercialIndicator::LEVEL_III); + $commercialData->poNumber = "9876543210"; + $commercialData->taxAmount = 0.01; + $commercialData->destinationPostalCode = "85212"; + $commercialData->destinationCountryCode = "USA"; + $commercialData->originPostalCode = "22193"; + $commercialData->summaryCommodityCode = "SCC"; + $commercialData->customerVatNumber = "123456789"; + $commercialData->vatInvoiceNumber = "UVATREF162"; + $commercialData->orderDate = date('m/d/Y'); + $commercialData->freightAmount = 0.01; + $commercialData->dutyAmount = 0.01; + $commercialData->additionalTaxDetails = new AdditionalTaxDetails(.01, TaxCategory::VAT, .04, "VAT"); + + $lineItem = new CommercialLineItem; + $lineItem->productCode = "PRDCD1"; + $lineItem->name = "PRDCD1NAME"; + $lineItem->unitCost = 0.01; + $lineItem->quantity = 1; + $lineItem->unitOfMeasure = "METER"; + $lineItem->description = "PRODUCT 1 NOTES"; + $lineItem->commodityCode = "12DIGIT ACCO"; + $lineItem->alternateTaxId = "1234567890"; + $lineItem->creditDebitIndicator = CreditDebitIndicator::CREDIT; + $commercialData->addLineItems($lineItem); + + $response = $this->getMasterCardManual()->charge(.53) + ->withCurrency('USD') + ->withCommercialData($commercialData) + ->withAddress($this->getAddy()) + ->execute(); + + $this->assertEquals('00', $response->responseCode); + } +} diff --git a/test/Integration/Gateways/TransITConnector/TransITAdminTest.php b/test/Integration/Gateways/TransITConnector/TransITAdminTest.php index 0ffd187e..77b3d8ba 100644 --- a/test/Integration/Gateways/TransITConnector/TransITAdminTest.php +++ b/test/Integration/Gateways/TransITConnector/TransITAdminTest.php @@ -1,97 +1,97 @@ -card = TestCards::visaManual(); - - ServicesContainer::configureService($this->getConfig()); - } - - protected function getConfig() - { - $config = new TransitConfig(); - $config->merchantId = '887000003226'; - $config->username = 'TA5622118'; - $config->password = 'f8mapGqWrE^rVaA9'; - $config->deviceId = '88700000322602'; - $config->transactionKey = '2HZFSJ98G4XEGHXGP31IRLLG8H3XAWB2'; - $config->developerId = '003226G001'; - $config->gatewayProvider = GatewayProvider::TRANSIT; - $config->acceptorConfig = new AcceptorConfig(); - - return $config; - } - - public function testTokenizeCardKeyed() - { - $token = $this->card->tokenize()->execute(); - $this->assertNotNull($token); - $this->assertEquals('00', $token->responseCode); - $this->assertNotNull($token->token); - } - - public function testCreateManifest() - { - $config = new TransitConfig(); - $config->merchantId = '887000003226'; - $config->username = 'TA5622118'; - $config->password = 'f8mapGqWrE^rVaA9'; - $config->deviceId = '88700000322602'; - $config->developerId = '003226G001'; - $config->gatewayProvider = GatewayProvider::TRANSIT; - $config->acceptorConfig = new AcceptorConfig(); - - ServicesContainer::configureService($config); - $provider = ServicesContainer::instance()->getClient(); - - //create Transaction Key - $response = $provider->getTransactionKey(); - - $this->assertNotNull($response); - $this->assertEquals('00', $response->responseCode); - $this->assertNotNull($response->transactionKey); - - //create Manifest - $provider->transactionKey = $response->transactionKey; - $manifest = $provider->createManifest(); - - $this->assertNotNull($manifest); - } - - public function testDisableTransactionKey() - { - $config = new TransitConfig(); - $config->merchantId = '887000003226'; - $config->username = 'TA5622118'; - $config->password = 'f8mapGqWrE^rVaA9'; - $config->deviceId = '88700000322602'; - $config->developerId = '003226G001'; - //TransactionKey needs to be disabled. Throw 'Invalid Transaction Key' when key is not in active state - $config->transactionKey = 'F508Z7TIGFORSTDYJQLMK9NGFFPBIXV0'; - $config->acceptorConfig = new AcceptorConfig(); - $config->gatewayProvider = GatewayProvider::TRANSIT; - - ServicesContainer::configureService($config); - $provider = ServicesContainer::instance()->getClient(); - - //create new Transaction Key - $response = $provider->getTransactionKey(); - - $this->assertNotNull($response); - $this->assertEquals('00', $response->responseCode); - $this->assertNotNull($response->transactionKey); - } -} +card = TestCards::visaManual(); + + ServicesContainer::configureService($this->getConfig()); + } + + protected function getConfig() + { + $config = new TransitConfig(); + $config->merchantId = '887000003226'; + $config->username = 'TA5622118'; + $config->password = 'f8mapGqWrE^rVaA9'; + $config->deviceId = '88700000322602'; + $config->transactionKey = '2HZFSJ98G4XEGHXGP31IRLLG8H3XAWB2'; + $config->developerId = '003226G001'; + $config->gatewayProvider = GatewayProvider::TRANSIT; + $config->acceptorConfig = new AcceptorConfig(); + + return $config; + } + + public function testTokenizeCardKeyed() + { + $token = $this->card->tokenize()->execute(); + $this->assertNotNull($token); + $this->assertEquals('00', $token->responseCode); + $this->assertNotNull($token->token); + } + + public function testCreateManifest() + { + $config = new TransitConfig(); + $config->merchantId = '887000003226'; + $config->username = 'TA5622118'; + $config->password = 'f8mapGqWrE^rVaA9'; + $config->deviceId = '88700000322602'; + $config->developerId = '003226G001'; + $config->gatewayProvider = GatewayProvider::TRANSIT; + $config->acceptorConfig = new AcceptorConfig(); + + ServicesContainer::configureService($config); + $provider = ServicesContainer::instance()->getClient(); + + //create Transaction Key + $response = $provider->getTransactionKey(); + + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode); + $this->assertNotNull($response->transactionKey); + + //create Manifest + $provider->transactionKey = $response->transactionKey; + $manifest = $provider->createManifest(); + + $this->assertNotNull($manifest); + } + + public function testDisableTransactionKey() + { + $config = new TransitConfig(); + $config->merchantId = '887000003226'; + $config->username = 'TA5622118'; + $config->password = 'f8mapGqWrE^rVaA9'; + $config->deviceId = '88700000322602'; + $config->developerId = '003226G001'; + //TransactionKey needs to be disabled. Throw 'Invalid Transaction Key' when key is not in active state + $config->transactionKey = 'F508Z7TIGFORSTDYJQLMK9NGFFPBIXV0'; + $config->acceptorConfig = new AcceptorConfig(); + $config->gatewayProvider = GatewayProvider::TRANSIT; + + ServicesContainer::configureService($config); + $provider = ServicesContainer::instance()->getClient(); + + //create new Transaction Key + $response = $provider->getTransactionKey(); + + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode); + $this->assertNotNull($response->transactionKey); + } +} diff --git a/test/Integration/Gateways/TransITConnector/TransITDebitTest.php b/test/Integration/Gateways/TransITConnector/TransITDebitTest.php index 8251e6d7..9ac73abd 100644 --- a/test/Integration/Gateways/TransITConnector/TransITDebitTest.php +++ b/test/Integration/Gateways/TransITConnector/TransITDebitTest.php @@ -1,53 +1,53 @@ -track = new DebitTrackData(); - - $encryptionData = new EncryptionData(); - $encryptionData->version = '01'; - $encryptionData->ksn = '000000000000000'; - - $this->track->encryptionData = $encryptionData; - $this->track->pinBlock = '0000'; - $this->track->setValue(';'); - - ServicesContainer::configureService($this->getConfig()); - } - - protected function getConfig() - { - $config = new TransitConfig(); - $config->merchantId = '887000003226'; - $config->username = 'TA5622118'; - $config->password = 'f8mapGqWrE^rVaA9'; - $config->deviceId = '88700000322602'; - $config->transactionKey = '2HZFSJ98G4XEGHXGP31IRLLG8H3XAWB2'; - $config->developerId = '003226G001'; - $config->acceptorConfig = new AcceptorConfig(); - return $config; - } - - public function testDebitSale() - { - $response = $this->track->charge(10) - ->withCurrency('USD') - ->execute(); - $this->assertNotNull($response); - $this->assertEquals('00', $response->responseCode); - } -} +track = new DebitTrackData(); + + $encryptionData = new EncryptionData(); + $encryptionData->version = '01'; + $encryptionData->ksn = '000000000000000'; + + $this->track->encryptionData = $encryptionData; + $this->track->pinBlock = '0000'; + $this->track->setValue(';'); + + ServicesContainer::configureService($this->getConfig()); + } + + protected function getConfig() + { + $config = new TransitConfig(); + $config->merchantId = '887000003226'; + $config->username = 'TA5622118'; + $config->password = 'f8mapGqWrE^rVaA9'; + $config->deviceId = '88700000322602'; + $config->transactionKey = '2HZFSJ98G4XEGHXGP31IRLLG8H3XAWB2'; + $config->developerId = '003226G001'; + $config->acceptorConfig = new AcceptorConfig(); + return $config; + } + + public function testDebitSale() + { + $response = $this->track->charge(10) + ->withCurrency('USD') + ->execute(); + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode); + } +} diff --git a/test/Integration/Gateways/TransITConnector/TransITTests.php b/test/Integration/Gateways/TransITConnector/TransITTests.php index c1b476d0..b0b2cbf5 100644 --- a/test/Integration/Gateways/TransITConnector/TransITTests.php +++ b/test/Integration/Gateways/TransITConnector/TransITTests.php @@ -1,325 +1,325 @@ -getConfig()); - - $this->address = new Address(); - $this->address->streetAddress1 = '1 Federal Street'; - $this->address->postalCode = '02110'; - - $this->card = TestCards::masterCardManual(); - - $this->track = new CreditTrackData(); - $this->track->setValue(';'); - - $this->tokenizedCard = new CreditCardData(); - $this->tokenizedCard->token = '5RpF5t9Asb9U6527'; - } - - protected function getConfig() - { - $config = new TransitConfig(); - $config->merchantId = '887000003226'; - $config->username = 'TA5622118'; - $config->password = 'f8mapGqWrE^rVaA9'; - $config->deviceId = '88700000322602'; - $config->transactionKey = '2HZFSJ98G4XEGHXGP31IRLLG8H3XAWB2'; - $config->developerId = '003226G001'; - $config->acceptorConfig = new AcceptorConfig(); - return $config; - } - - public function testAdjustTip() - { - $response = $this->card->charge(10) - ->withCurrency('USD') - ->execute(); - - $this->assertNotNull($response); - $this->assertEquals('00', $response->responseCode); - - $adjust = $response->edit() - ->withGratuity(1.05) - ->execute(); - - $this->assertNotNull($adjust); - $this->assertEquals('00', $response->responseCode); - } - - public function testAuthorizeKeyed() - { - $response = $this->card->authorize(10) - ->withCurrency('USD') - ->withAddress($this->address) - ->execute(); - - $this->assertNotNull($response); - $this->assertEquals('00', $response->responseCode); - $this->assertFalse($response->avsResponseCode == '0'); // verify an AVS response of some sort - } - - public function testAuthorizeSwiped() - { - $response = $this->track->authorize(100) - ->withCurrency('USD') - ->withInvoiceNumber('1264') - ->withClientTransactionId('137149') - ->execute(); - - $this->assertNotNull($response); - $this->assertEquals('00', $response->responseCode); - } - - public function testAuthorizeToken() - { - $response = $this->tokenizedCard->authorize(10) - ->withCurrency('USD') - ->withInvoiceNumber('1558') - ->execute(); - - $this->assertNotNull($response); - $this->assertEquals('00', $response->responseCode); - } - - public function testTokenizedCardSale() - { - $token = $this->card->tokenize()->execute(); - $this->assertNotNull($token); - $this->assertEquals('00', $token->responseCode); - $this->assertNotNull($token->token); - - $tokenizedCard = new CreditCardData(); - $tokenizedCard->token = $token->token; - - $response = $tokenizedCard->charge(10) - ->withCurrency('USD') - ->execute(); - - $this->assertNotNull($response); - $this->assertEquals('00', $response->responseCode); - } - - public function testBalanceInquiry() - { - $response = $this->card->balanceInquiry() - ->execute(); - - $this->assertNotNull($response); - $this->assertEquals('00', $response->responseCode); - } - - public function testCapture() - { - $response = $this->card->authorize(10) - ->withCurrency('USD') - ->execute(); - - $this->assertNotNull($response); - $this->assertEquals('00', $response->responseCode); - - $captureResponse = $response->capture()->execute(); - - $this->assertNotNull($captureResponse); - $this->assertEquals('00', $captureResponse->responseCode); - } - - public function testSaleKeyed() - { - - $response = $this->card->charge(100) - ->withCurrency('USD') - ->withAllowDuplicates(false) - ->execute(); - - $this->assertNotNull($response); - $this->assertEquals('00', $response->responseCode); - } - - public function testSaleSwiped() - { - $response = $this->track->charge(100) - ->withCurrency('USD') - ->execute(); - - $this->assertNotNull($response); - $this->assertEquals('00', $response->responseCode); - } - - public function testSaleToken() - { - $response = $this->tokenizedCard->charge(1.29) - ->withCurrency('USD') - ->withCashBack(0) - ->withConvenienceAmount(0) - ->withInvoiceNumber('1559') - ->withClientTransactionId('166909') - ->withAllowPartialAuth(false) - ->withAllowDuplicates(false) - ->execute(); - - $this->assertNotNull($response); - $this->assertEquals('00', $response->responseCode); - } - - // Response not mapping correctly - public function testSettleBatch() - { - $response = BatchService::closeBatch(); - - $this->assertNotNull($response); - $this->assertEquals('00', $response->responseCode); - $this->assertNotNull($response->batchSummary); - $this->assertNotNull($response->batchSummary->totalAmount); - } - - public function testVoid() - { - $response = $this->card->charge(10) - ->withCurrency('USD') - ->execute(); - - $this->assertNotNull($response); - $this->assertEquals('00', $response->responseCode); - - $voidResponse = $response->void() - ->withDescription('DEVICE_UNAVAILABLE') - ->execute(); - - $this->assertNotNull($voidResponse); - $this->assertEquals('00', $voidResponse->responseCode); - } - - public function testVerify() - { - $response = $this->card->verify() - ->execute(); - - $this->assertNotNull($response); - $this->assertEquals('00', $response->responseCode); - } - - public function testRequestMUTOnSale() { - $response = $this->card->charge(12.34) - ->withCurrency('USD') - ->withRequestMultiUseToken(true) - ->execute(); - - $this->assertNotNull($response); - $this->assertNotNull($response->token); - } - - public function testRefund() - { - $response = $this->card->charge(10) - ->withCurrency('USD') - ->execute(); - - $this->assertNotNull($response); - $this->assertEquals('00', $response->responseCode); - - $refundResponse = $response->refund() - ->withCurrency('USD') - ->execute(); - - $this->assertNotNull($refundResponse); - $this->assertEquals('00', $refundResponse->responseCode); - } - - public function testRefundByCard() - { - $response = $this->card->refund(15.11) - ->withCurrency('USD') - ->execute(); - $this->assertNotNull($response); - $this->assertEquals('00', $response->responseCode); - } - - public function testRefundBySwipe() - { - $response = $this->track->refund(15.11) - ->withCurrency('USD') - ->execute(); - $this->assertNotNull($response); - $this->assertEquals('00', $response->responseCode); - } - - public function testSaleSwipedTrack1Pattern() - { - $this->track = new CreditTrackData(); - $this->track->setValue('%B5473500000000014^MC TEST CARD^251210199998888777766665555444433332'); - - $response = $this->track->charge(10) - ->withCurrency('USD') - ->execute(); - - $this->assertNotNull($response); - $this->assertEquals('00', $response->responseCode); - } - - /** - * @expectedException GlobalPayments\Api\Entities\Exceptions\BuilderException - * @expectedExceptionMessage amount cannot be null for this transaction type. - */ - public function testAuthorizeWithoutAmount() - { - $response = $this->card->authorize() - ->withCurrency('USD') - ->execute(); - } - - /** - * @expectedException GlobalPayments\Api\Entities\Exceptions\BuilderException - * @expectedExceptionMessage amount cannot be null for this transaction type. - */ - public function testSaleWithoutAmount() - { - $response = $this->card->charge() - ->withCurrency('USD') - ->execute(); - } - - /** - * @expectedException GlobalPayments\Api\Entities\Exceptions\BuilderException - * @expectedExceptionMessage amount cannot be null for this transaction type. - */ - public function testRefundWithoutAmount() - { - $response = $this->card->refund() - ->withCurrency('USD') - ->execute(); - } - - /** - * @expectedException GlobalPayments\Api\Entities\Exceptions\ConfigurationException - * @expectedExceptionMessage deviceID is required for this configuration. - */ - public function testCredentialsError() - { - $config = new TransitConfig(); - $config->acceptorConfig = new AcceptorConfig(); - - ServicesContainer::configureService($config); - } -} +getConfig()); + + $this->address = new Address(); + $this->address->streetAddress1 = '1 Federal Street'; + $this->address->postalCode = '02110'; + + $this->card = TestCards::masterCardManual(); + + $this->track = new CreditTrackData(); + $this->track->setValue(';'); + + $this->tokenizedCard = new CreditCardData(); + $this->tokenizedCard->token = '5RpF5t9Asb9U6527'; + } + + protected function getConfig() + { + $config = new TransitConfig(); + $config->merchantId = '887000003226'; + $config->username = 'TA5622118'; + $config->password = 'f8mapGqWrE^rVaA9'; + $config->deviceId = '88700000322602'; + $config->transactionKey = '2HZFSJ98G4XEGHXGP31IRLLG8H3XAWB2'; + $config->developerId = '003226G001'; + $config->acceptorConfig = new AcceptorConfig(); + return $config; + } + + public function testAdjustTip() + { + $response = $this->card->charge(10) + ->withCurrency('USD') + ->execute(); + + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode); + + $adjust = $response->edit() + ->withGratuity(1.05) + ->execute(); + + $this->assertNotNull($adjust); + $this->assertEquals('00', $response->responseCode); + } + + public function testAuthorizeKeyed() + { + $response = $this->card->authorize(10) + ->withCurrency('USD') + ->withAddress($this->address) + ->execute(); + + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode); + $this->assertFalse($response->avsResponseCode == '0'); // verify an AVS response of some sort + } + + public function testAuthorizeSwiped() + { + $response = $this->track->authorize(100) + ->withCurrency('USD') + ->withInvoiceNumber('1264') + ->withClientTransactionId('137149') + ->execute(); + + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode); + } + + public function testAuthorizeToken() + { + $response = $this->tokenizedCard->authorize(10) + ->withCurrency('USD') + ->withInvoiceNumber('1558') + ->execute(); + + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode); + } + + public function testTokenizedCardSale() + { + $token = $this->card->tokenize()->execute(); + $this->assertNotNull($token); + $this->assertEquals('00', $token->responseCode); + $this->assertNotNull($token->token); + + $tokenizedCard = new CreditCardData(); + $tokenizedCard->token = $token->token; + + $response = $tokenizedCard->charge(10) + ->withCurrency('USD') + ->execute(); + + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode); + } + + public function testBalanceInquiry() + { + $response = $this->card->balanceInquiry() + ->execute(); + + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode); + } + + public function testCapture() + { + $response = $this->card->authorize(10) + ->withCurrency('USD') + ->execute(); + + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode); + + $captureResponse = $response->capture()->execute(); + + $this->assertNotNull($captureResponse); + $this->assertEquals('00', $captureResponse->responseCode); + } + + public function testSaleKeyed() + { + + $response = $this->card->charge(100) + ->withCurrency('USD') + ->withAllowDuplicates(false) + ->execute(); + + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode); + } + + public function testSaleSwiped() + { + $response = $this->track->charge(100) + ->withCurrency('USD') + ->execute(); + + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode); + } + + public function testSaleToken() + { + $response = $this->tokenizedCard->charge(1.29) + ->withCurrency('USD') + ->withCashBack(0) + ->withConvenienceAmount(0) + ->withInvoiceNumber('1559') + ->withClientTransactionId('166909') + ->withAllowPartialAuth(false) + ->withAllowDuplicates(false) + ->execute(); + + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode); + } + + // Response not mapping correctly + public function testSettleBatch() + { + $response = BatchService::closeBatch(); + + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode); + $this->assertNotNull($response->batchSummary); + $this->assertNotNull($response->batchSummary->totalAmount); + } + + public function testVoid() + { + $response = $this->card->charge(10) + ->withCurrency('USD') + ->execute(); + + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode); + + $voidResponse = $response->void() + ->withDescription('DEVICE_UNAVAILABLE') + ->execute(); + + $this->assertNotNull($voidResponse); + $this->assertEquals('00', $voidResponse->responseCode); + } + + public function testVerify() + { + $response = $this->card->verify() + ->execute(); + + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode); + } + + public function testRequestMUTOnSale() { + $response = $this->card->charge(12.34) + ->withCurrency('USD') + ->withRequestMultiUseToken(true) + ->execute(); + + $this->assertNotNull($response); + $this->assertNotNull($response->token); + } + + public function testRefund() + { + $response = $this->card->charge(10) + ->withCurrency('USD') + ->execute(); + + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode); + + $refundResponse = $response->refund() + ->withCurrency('USD') + ->execute(); + + $this->assertNotNull($refundResponse); + $this->assertEquals('00', $refundResponse->responseCode); + } + + public function testRefundByCard() + { + $response = $this->card->refund(15.11) + ->withCurrency('USD') + ->execute(); + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode); + } + + public function testRefundBySwipe() + { + $response = $this->track->refund(15.11) + ->withCurrency('USD') + ->execute(); + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode); + } + + public function testSaleSwipedTrack1Pattern() + { + $this->track = new CreditTrackData(); + $this->track->setValue('%B5473500000000014^MC TEST CARD^251210199998888777766665555444433332'); + + $response = $this->track->charge(10) + ->withCurrency('USD') + ->execute(); + + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode); + } + + /** + * @expectedException GlobalPayments\Api\Entities\Exceptions\BuilderException + * @expectedExceptionMessage amount cannot be null for this transaction type. + */ + public function testAuthorizeWithoutAmount() + { + $response = $this->card->authorize() + ->withCurrency('USD') + ->execute(); + } + + /** + * @expectedException GlobalPayments\Api\Entities\Exceptions\BuilderException + * @expectedExceptionMessage amount cannot be null for this transaction type. + */ + public function testSaleWithoutAmount() + { + $response = $this->card->charge() + ->withCurrency('USD') + ->execute(); + } + + /** + * @expectedException GlobalPayments\Api\Entities\Exceptions\BuilderException + * @expectedExceptionMessage amount cannot be null for this transaction type. + */ + public function testRefundWithoutAmount() + { + $response = $this->card->refund() + ->withCurrency('USD') + ->execute(); + } + + /** + * @expectedException GlobalPayments\Api\Entities\Exceptions\ConfigurationException + * @expectedExceptionMessage deviceID is required for this configuration. + */ + public function testCredentialsError() + { + $config = new TransitConfig(); + $config->acceptorConfig = new AcceptorConfig(); + + ServicesContainer::configureService($config); + } +}