From 9599204080af94df66723559e3ee0e65aac1f1ba Mon Sep 17 00:00:00 2001 From: securesubmit-buildmaster Date: Tue, 24 Oct 2023 08:02:26 -0400 Subject: [PATCH] OctopusDeploy release: 11.0.1 --- CHANGELOG.md | 11 +- examples/gp-api/end-to-end/authorization.php | 6 +- .../end-to-end/challengeNotificationUrl.php | 15 +- .../end-to-end/methodNotificationUrl.php | 4 +- metadata.xml | 2 +- src/Builders/PayFacBuilder.php | 5 +- .../GpApiAuthorizationRequestBuilder.php | 24 +- .../GpApi/GpApiPayFacRequestBuilder.php | 1 + src/Entities/Enums/Environment.php | 1 - src/Entities/Enums/ServiceEndpoints.php | 1 - src/ServiceConfigs/Gateways/GpApiConfig.php | 6 +- .../UPA/Interfaces/UpaMicInterface.php | 2 +- test/Data/BaseGpApiTestConfig.php | 6 +- .../CreditCardNotPresentTest.php | 18 + .../GpApiMerchantAccountsTest.php | 4 +- .../GpApiConnector/ReportingActionsTest.php | 2 +- .../Gateways/GpEcomConnector/HppTest.php | 517 +++++++++--------- .../Gateways/GpEcomConnector/HppTestCase.php | 260 --------- .../GpEcomConnector/OpenBankingTest.php | 7 +- .../GpEcomConnector/ReportingTest.php | 4 +- .../Gateways/Terminals/UPA/UpaMicTests.php | 172 +++++- 21 files changed, 503 insertions(+), 565 deletions(-) delete mode 100644 test/Integration/Gateways/GpEcomConnector/HppTestCase.php diff --git a/CHANGELOG.md b/CHANGELOG.md index 537cff2d..8628128b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,16 @@ # Changelog -## Latest Version - v11.0.0 (10/19/2023) +## Latest Version - v11.0.1 (10/24/2023) +### Enhancements: +- [GP-API] Add stored credentials to verify request +- [GP-API & GP-ECOM] Enhancements on unit tests +- [MEET-IN-THE-CLOUD][GP-API] Remove QA endpoint + +#### Bug Fixes: +-[GP-API]: Fix 3DS example + +## v11.0.0 (10/19/2023) ### Enhancements: - [DiamondCloud] Add support for Diamond Cloud provider payment terminals. - [Breaking] Terminals: Architecture update diff --git a/examples/gp-api/end-to-end/authorization.php b/examples/gp-api/end-to-end/authorization.php index 0fb3073c..f466d074 100644 --- a/examples/gp-api/end-to-end/authorization.php +++ b/examples/gp-api/end-to-end/authorization.php @@ -22,7 +22,7 @@ console_log($serverTransactionId); function console_log($data) { - $data = htmlspecialchars($data); + $data = htmlspecialchars($data, ENT_NOQUOTES); echo ' \ No newline at end of file diff --git a/examples/gp-api/end-to-end/methodNotificationUrl.php b/examples/gp-api/end-to-end/methodNotificationUrl.php index 3983a96d..0cc1dc41 100644 --- a/examples/gp-api/end-to-end/methodNotificationUrl.php +++ b/examples/gp-api/end-to-end/methodNotificationUrl.php @@ -12,8 +12,8 @@ try { $decodedThreeDSMethodData = base64_decode($threeDSMethodData); if (!empty($decodedThreeDSMethodData)) { - $convertedThreeDSMethodData = json_decode(htmlspecialchars($decodedThreeDSMethodData), true); - $serverTransID = htmlspecialchars($convertedThreeDSMethodData['threeDSServerTransID']); + $convertedThreeDSMethodData = json_decode(htmlspecialchars($decodedThreeDSMethodData, ENT_NOQUOTES), true); + $serverTransID = htmlspecialchars($convertedThreeDSMethodData['threeDSServerTransID'], ENT_NOQUOTES); } // TODO: notify client-side that the Method URL step is complete diff --git a/metadata.xml b/metadata.xml index 91b129ad..271badfb 100644 --- a/metadata.xml +++ b/metadata.xml @@ -1,3 +1,3 @@ - 11.0.0 + 11.0.1 \ No newline at end of file diff --git a/src/Builders/PayFacBuilder.php b/src/Builders/PayFacBuilder.php index f57793c7..e6f9d4b5 100644 --- a/src/Builders/PayFacBuilder.php +++ b/src/Builders/PayFacBuilder.php @@ -466,7 +466,10 @@ public function withUploadDocumentData($uploadDocumentData) { //file validations if (empty($uploadDocumentData->b64_content)) { - if (!file_exists($uploadDocumentData->documentLocation)) { + if ( + empty($uploadDocumentData->documentLocation) || + !file_exists($uploadDocumentData->documentLocation) + ) { throw new BuilderException('File not found!'); } elseif (filesize($uploadDocumentData->documentLocation) > 5000000) { throw new BuilderException('Max file size 5MB exceeded'); diff --git a/src/Builders/RequestBuilder/GpApi/GpApiAuthorizationRequestBuilder.php b/src/Builders/RequestBuilder/GpApi/GpApiAuthorizationRequestBuilder.php index e7601635..ce869774 100644 --- a/src/Builders/RequestBuilder/GpApi/GpApiAuthorizationRequestBuilder.php +++ b/src/Builders/RequestBuilder/GpApi/GpApiAuthorizationRequestBuilder.php @@ -31,6 +31,7 @@ use GlobalPayments\Api\Entities\PayByLinkData; use GlobalPayments\Api\Entities\PhoneNumber; use GlobalPayments\Api\Entities\Product; +use GlobalPayments\Api\Entities\StoredCredential; use GlobalPayments\Api\Gateways\OpenBankingProvider; use GlobalPayments\Api\Mapping\EnumMapping; use GlobalPayments\Api\PaymentMethods\BankPayment; @@ -216,7 +217,9 @@ private function generateVerificationRequest(AuthorizationBuilder $builder, GpAp $requestBody['currency'] = $builder->currency; $requestBody['country'] = $config->country; $requestBody['payment_method'] = $this->createPaymentMethodParam($builder, $config); - + if (!empty($builder->storedCredential)) { + $this->setRequestStoredCredentials($builder->storedCredential, $requestBody); + } return $requestBody; } @@ -277,13 +280,7 @@ private function createFromAuthorizationBuilder($builder, GpApiConfig $config) $this->setNotificationUrls($requestBody); } if (!empty($builder->storedCredential)) { - $initiator = EnumMapping::mapStoredCredentialInitiator(GatewayProvider::GP_API, $builder->storedCredential->initiator); - $requestBody['initiator'] = !empty($initiator) ? $initiator : null; - $requestBody['stored_credential'] = [ - 'model' => strtoupper($builder->storedCredential->type), - 'reason' => strtoupper($builder->storedCredential->reason), - 'sequence' => strtoupper($builder->storedCredential->sequence) - ]; + $this->setRequestStoredCredentials($builder->storedCredential, $requestBody); } if (!empty($builder->dccRateData)) { @@ -295,6 +292,17 @@ private function createFromAuthorizationBuilder($builder, GpApiConfig $config) return $requestBody; } + private function setRequestStoredCredentials(StoredCredential $storedCredential, &$request) + { + $request['initiator'] = !empty($storedCredential->initiator) ? + EnumMapping::mapStoredCredentialInitiator(GatewayProvider::GP_API, $storedCredential->initiator) : null; + $request['stored_credential'] = [ + 'model' => !empty($storedCredential->type) ? strtoupper($storedCredential->type) : null, + 'reason' => !empty($storedCredential->reason) ? strtoupper($storedCredential->reason) : null, + 'sequence' => !empty($storedCredential->sequence) ? strtoupper($storedCredential->sequence) : null + ]; + } + /** * Sets the information related to the payer * diff --git a/src/Builders/RequestBuilder/GpApi/GpApiPayFacRequestBuilder.php b/src/Builders/RequestBuilder/GpApi/GpApiPayFacRequestBuilder.php index 5ba89680..1a34d1c1 100644 --- a/src/Builders/RequestBuilder/GpApi/GpApiPayFacRequestBuilder.php +++ b/src/Builders/RequestBuilder/GpApi/GpApiPayFacRequestBuilder.php @@ -106,6 +106,7 @@ public function buildRequest(BaseBuilder $builder, $config) $this->mapAddress($this->builder->addresses->get(AddressType::BILLING), 'alpha2') : null ]; } + break; case TransactionType::ADD_FUNDS: $verb = 'POST'; $endpoint = GpApiRequest::MERCHANT_MANAGEMENT_ENDPOINT . '/' . $builder->userReference->userId . '/settlement/funds'; diff --git a/src/Entities/Enums/Environment.php b/src/Entities/Enums/Environment.php index 6b85d335..29188914 100644 --- a/src/Entities/Enums/Environment.php +++ b/src/Entities/Enums/Environment.php @@ -8,5 +8,4 @@ class Environment extends Enum { const TEST = "TEST"; const PRODUCTION = "PRODUCTION"; - const QA = 'QA'; } diff --git a/src/Entities/Enums/ServiceEndpoints.php b/src/Entities/Enums/ServiceEndpoints.php index 67140021..51d1c8a2 100644 --- a/src/Entities/Enums/ServiceEndpoints.php +++ b/src/Entities/Enums/ServiceEndpoints.php @@ -26,7 +26,6 @@ class ServiceEndpoints extends Enum const PROPAY_PRODUCTION_CANADIAN = "https://www.propaycanada.ca/API/PropayAPI.aspx"; const GP_API_TEST = "https://apis.sandbox.globalpay.com/ucp"; const GP_API_PRODUCTION = "https://apis.globalpay.com/ucp"; - const GP_API_QA = "https://apis-uat.globalpay.com/ucp"; const OPEN_BANKING_TEST = 'https://api.sandbox.globalpay-ecommerce.com/openbanking'; const OPEN_BANKING_PRODUCTION = 'https://api.globalpay-ecommerce.com/openbanking'; const TRANSACTION_API_TEST = "https://api.pit.paygateway.com/transactions/"; diff --git a/src/ServiceConfigs/Gateways/GpApiConfig.php b/src/ServiceConfigs/Gateways/GpApiConfig.php index 34fca67c..38e45f13 100644 --- a/src/ServiceConfigs/Gateways/GpApiConfig.php +++ b/src/ServiceConfigs/Gateways/GpApiConfig.php @@ -91,11 +91,7 @@ public function configureContainer(ConfiguredServices $services) { if (empty($this->serviceUrl)) { $this->serviceUrl = ($this->environment == Environment::PRODUCTION) ? - ServiceEndpoints::GP_API_PRODUCTION : - ( - $this->environment == Environment::QA ? - ServiceEndpoints::GP_API_QA :ServiceEndpoints::GP_API_TEST - ); + ServiceEndpoints::GP_API_PRODUCTION : ServiceEndpoints::GP_API_TEST; } $gateway = new GpApiConnector($this); $gateway->serviceUrl = $this->serviceUrl; diff --git a/src/Terminals/UPA/Interfaces/UpaMicInterface.php b/src/Terminals/UPA/Interfaces/UpaMicInterface.php index a3098893..4fd5e9c8 100644 --- a/src/Terminals/UPA/Interfaces/UpaMicInterface.php +++ b/src/Terminals/UPA/Interfaces/UpaMicInterface.php @@ -29,7 +29,7 @@ public function __construct(ITerminalConfiguration $config) public function connect() { $this->connector = ServicesContainer::instance()->getClient($this->config->getConfigName()); - if (empty($this->gatewayConfig->accessTokenInfo)) { + if (empty($this->gatewayConfig->accessTokenInfo->accessToken)) { $this->connector->signIn(); } } diff --git a/test/Data/BaseGpApiTestConfig.php b/test/Data/BaseGpApiTestConfig.php index e8a57958..f33f6e7b 100644 --- a/test/Data/BaseGpApiTestConfig.php +++ b/test/Data/BaseGpApiTestConfig.php @@ -4,6 +4,7 @@ use GlobalPayments\Api\Entities\CustomWebProxy; use GlobalPayments\Api\Entities\Enums\Environment; +use GlobalPayments\Api\Entities\GpApi\AccessTokenInfo; use GlobalPayments\Api\ServiceConfigs\Gateways\GpApiConfig; use GlobalPayments\Api\ServicesContainer; use GlobalPayments\Api\Utils\Logging\Logger; @@ -20,9 +21,6 @@ class BaseGpApiTestConfig public static string $appId = self::APP_ID; public static string $appKey = self::APP_KEY; #gitleaks:allow - const UPA_MIC_DEVICE_APP_ID = '83cdNQ0YBmzxzkLpFHpDGn2ir0WKTW0N'; - const UPA_MIC_DEVICE_APP_KEY = '1ASrcQZb0AEqR6ZT'; - private static bool $logEnabled = true; private static bool $dynamicHeaderEnabled = false; private static bool $permissionsEnabled = false; @@ -36,6 +34,8 @@ public static function gpApiSetupConfig($channel): GpApiConfig $config->environment = Environment::TEST; $config->channel = $channel; $config->country = 'US'; + $config->accessTokenInfo = new AccessTokenInfo(); + $config->accessTokenInfo->transactionProcessingAccountName = 'transaction_processing'; $config->challengeNotificationUrl = "https://ensi808o85za.x.pipedream.net/"; $config->methodNotificationUrl = "https://ensi808o85za.x.pipedream.net/"; diff --git a/test/Integration/Gateways/GpApiConnector/CreditCardNotPresentTest.php b/test/Integration/Gateways/GpApiConnector/CreditCardNotPresentTest.php index 6e5aaf92..cf11b321 100644 --- a/test/Integration/Gateways/GpApiConnector/CreditCardNotPresentTest.php +++ b/test/Integration/Gateways/GpApiConnector/CreditCardNotPresentTest.php @@ -897,6 +897,24 @@ public function testCreditVerification() $this->assertEquals("VERIFIED", $response->responseMessage); } + public function testCreditVerificationWithStoredCredentials() + { + $storeCredentials = new StoredCredential(); + $storeCredentials->initiator = StoredCredentialInitiator::MERCHANT; + $storeCredentials->type = StoredCredentialType::INSTALLMENT; + $storeCredentials->sequence = StoredCredentialSequence::SUBSEQUENT; + $storeCredentials->reason = StoredCredentialReason::INCREMENTAL; + + $response = $this->card->verify() + ->withCurrency($this->currency) + ->withStoredCredential($storeCredentials) + ->execute(); + + $this->assertNotNull($response); + $this->assertEquals('SUCCESS', $response->responseCode); + $this->assertEquals("VERIFIED", $response->responseMessage); + } + public function testCreditVerification_withIdempotencyKey() { $idempotencyKey = GenerationUtils::getGuid(); diff --git a/test/Integration/Gateways/GpApiConnector/GpApiMerchantAccountsTest.php b/test/Integration/Gateways/GpApiConnector/GpApiMerchantAccountsTest.php index d87280a4..2a8e9197 100644 --- a/test/Integration/Gateways/GpApiConnector/GpApiMerchantAccountsTest.php +++ b/test/Integration/Gateways/GpApiConnector/GpApiMerchantAccountsTest.php @@ -1205,7 +1205,7 @@ public function testAddFunds_WithoutUserRef() private function getAccountByType($merchantId, $type) { $response = ReportingService::findAccounts(1, 10) - ->orderBy(MerchantAccountsSortProperty::TIME_CREATED, SortDirection::ASC) + ->orderBy(MerchantAccountsSortProperty::TIME_CREATED, SortDirection::DESC) ->where(DataServiceCriteria::MERCHANT_ID, $merchantId) ->andWith(SearchCriteria::START_DATE, $this->startDate) ->andWith(SearchCriteria::END_DATE, $this->endDate) @@ -1221,7 +1221,7 @@ private function getAccountByType($merchantId, $type) private function getMerchants() { return ReportingService::findMerchants(1, 10) - ->orderBy(MerchantAccountsSortProperty::TIME_CREATED, SortDirection::ASC) + ->orderBy(MerchantAccountsSortProperty::TIME_CREATED, SortDirection::DESC) ->where(SearchCriteria::ACCOUNT_STATUS, MerchantAccountStatus::ACTIVE) ->execute(); } diff --git a/test/Integration/Gateways/GpApiConnector/ReportingActionsTest.php b/test/Integration/Gateways/GpApiConnector/ReportingActionsTest.php index 25a9c247..6d202e17 100644 --- a/test/Integration/Gateways/GpApiConnector/ReportingActionsTest.php +++ b/test/Integration/Gateways/GpApiConnector/ReportingActionsTest.php @@ -193,7 +193,7 @@ public function testFindActions_FilterBy_ResourceStatus() public function testFindActions_FilterBy_ResourceId() { - $resourceId = $this->actionSummary->resourceId ?? 'TRN_cf4e1008-c921-4096-bec9-2372cb9476d8'; + $resourceId = $this->actionSummary->resourceId ?? 'TRN_xrMGGiLzU8hmuj55ZfnnxVBetKS2EX'; $response = ReportingService::findActionsPaged(1, 10) ->where(SearchCriteria::RESOURCE_ID, $resourceId) ->execute(); diff --git a/test/Integration/Gateways/GpEcomConnector/HppTest.php b/test/Integration/Gateways/GpEcomConnector/HppTest.php index 805b1dc2..77917700 100644 --- a/test/Integration/Gateways/GpEcomConnector/HppTest.php +++ b/test/Integration/Gateways/GpEcomConnector/HppTest.php @@ -17,6 +17,7 @@ use GlobalPayments\Api\Entities\Enums\RemittanceReferenceType; use GlobalPayments\Api\Entities\Enums\ShaHashType; use GlobalPayments\Api\Entities\Enums\TransactionStatus; +use GlobalPayments\Api\Entities\Exceptions\ApiException; use GlobalPayments\Api\Entities\Exceptions\BuilderException; use GlobalPayments\Api\Entities\Exceptions\GatewayException; use GlobalPayments\Api\Entities\FraudRuleCollection; @@ -26,6 +27,9 @@ use GlobalPayments\Api\ServiceConfigs\Gateways\GpEcomConfig; use GlobalPayments\Api\Services\HostedService; use GlobalPayments\Api\Tests\Integration\Gateways\GpEcomConnector\Hpp\GpEcomHppClient; +use GlobalPayments\Api\Utils\GenerationUtils; +use GlobalPayments\Api\Utils\Logging\Logger; +use GlobalPayments\Api\Utils\Logging\SampleRequestLogger; use PHPUnit\Framework\TestCase; use RecursiveArrayIterator; use RecursiveIteratorIterator; @@ -35,6 +39,7 @@ class HppTest extends TestCase private Address $billingAddress; private Address $shippingAddress; + private string $currency = 'EUR'; private array $hppVersionList = [ HppVersion::VERSION_1, @@ -42,7 +47,10 @@ class HppTest extends TestCase '' ]; - public function setup(): void + protected HostedService $service; + protected GpEcomHppClient $client; + + protected function config(): GpEcomConfig { // billing address $this->billingAddress = new Address(); @@ -57,38 +65,42 @@ public function setup(): void $this->shippingAddress->streetAddress2 = 'House 123'; $this->shippingAddress->postalCode = "WB3 A21"; $this->shippingAddress->country = "GB"; - } - public function basicSetup(): HostedService - { $config = new GpEcomConfig(); $config->merchantId = "heartlandgpsandbox"; $config->accountId = "hpp"; $config->sharedSecret = "secret"; - $config->serviceUrl = "https://pay.sandbox.realexpayments.com/pay"; + $config->refundPassword = "refund"; + $config->serviceUrl = "https://api.sandbox.realexpayments.com/epage-remote.cgi"; + $config->requestLogger = new SampleRequestLogger(new Logger("logs")); + $config->hostedPaymentConfig = new HostedPaymentConfig(); $config->hostedPaymentConfig->language = "GB"; - $config->hostedPaymentConfig->responseUrl = "http://requestb.in/10q2bjb1"; + $config->hostedPaymentConfig->responseUrl = "https://requestb.in/10q2bjb1"; - return new HostedService($config); + return $config; } - public function testCreditAuth() + /** + * @throws ApiException + */ + public function setup(): void { - $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"; + $this->service = new HostedService($this->config()); + } + public function testCreditAuth() + { + $config = $this->config(); $client = new GpEcomHppClient("secret"); $address = new Address(); - $address->postalCode = "123|56"; - $address->country = "IRELAND"; + $address->streetAddress1 = "264 Fowler Avenue"; + $address->streetAddress2 = "Lake Charles"; + $address->city = "Gainesville"; + $address->state = "GA"; + $address->postalCode = "30501"; + $address->country = "US"; //run test cases for different version foreach ($this->hppVersionList as $hppVersion) { @@ -96,8 +108,8 @@ public function testCreditAuth() $service = new HostedService($config); $json = $service->authorize(1) - ->withCurrency("EUR") - ->withCustomerId("123456") + ->withCurrency($this->currency) + ->withCustomerId(GenerationUtils::getGuid()) ->withAddress($address) ->serialize(); @@ -113,15 +125,7 @@ public function testCreditAuth() 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"; - + $config = $this->config(); $client = new GpEcomHppClient("secret"); $address = new Address(); @@ -134,8 +138,8 @@ public function testCreditSale() $service = new HostedService($config); $json = $service->charge(1) - ->withCurrency("EUR") - ->withCustomerId("123456") + ->withCurrency($this->currency) + ->withCustomerId(GenerationUtils::getGuid()) ->withAddress($address) ->serialize(); $this->assertNotNull($json); @@ -154,15 +158,7 @@ public function testCreditSale() 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"; - + $config = $this->config(); $client = new GpEcomHppClient("secret"); $address = new Address(); @@ -175,8 +171,8 @@ public function testCreditVerify() $service = new HostedService($config); $json = $service->verify() - ->withCurrency("EUR") - ->withCustomerId("123456") + ->withCurrency($this->currency) + ->withCustomerId(GenerationUtils::getGuid()) ->withAddress($address) ->serialize(); $this->assertNotNull($json); @@ -193,59 +189,44 @@ public function testCreditVerify() public function testAuthNoAmount() { $this->expectException(BuilderException::class); - $service = $this->basicSetup(); - $service->authorize(null)->withCurrency("USD")->serialize(); + $this->service->authorize()->withCurrency("USD")->serialize(); } public function testAuthNoCurrency() { $this->expectException(BuilderException::class); - $service = $this->basicSetup(); - $service->authorize(10)->serialize(); + $this->service->authorize(10)->serialize(); } public function testSaleNoAmount() { $this->expectException(BuilderException::class); - $service = $this->basicSetup(); - $service->charge(null)->withCurrency("USD")->serialize(); + $this->service->charge()->withCurrency("USD")->serialize(); } public function testSaleNoCurrency() { $this->expectException(BuilderException::class); - $service = $this->basicSetup(); - $service->charge(10)->serialize(); + $this->service->charge(10)->serialize(); } public function testVerifyNoCurrency() { $this->expectException(BuilderException::class); - $service = $this->basicSetup(); - $service->verify()->serialize(); + $this->service->verify()->serialize(); } public function testVerifyWithAmount() { $this->expectException(BuilderException::class); - $service = $this->basicSetup(); - $service->verify()->withAmount(10)->serialize(); + $this->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"; - + $config = $this->config(); $client = new GpEcomHppClient("secret"); // data to be passed to the HPP along with transaction level settings @@ -258,7 +239,7 @@ public function testCardStorageCreatePayer() $service = new HostedService($config); $json = $service->charge(15) - ->withCurrency("EUR") + ->withCurrency($this->currency) ->withHostedPaymentData($hostedPaymentData) ->serialize(); @@ -277,15 +258,7 @@ public function testCardStorageCreatePayer() 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"; + $config = $this->config(); $client = new GpEcomHppClient("secret"); @@ -301,7 +274,7 @@ public function testCardStorageDisplayStoredCard() $service = new HostedService($config); $json = $service->charge(15) - ->withCurrency("EUR") + ->withCurrency($this->currency) ->withHostedPaymentData($hostedPaymentData) ->serialize(); @@ -320,15 +293,7 @@ public function testCardStorageDisplayStoredCard() 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"; + $config = $this->config(); $client = new GpEcomHppClient("secret"); @@ -338,7 +303,7 @@ public function testContinuousAuthorityRequest() $service = new HostedService($config); $json = $service->charge(15) - ->withCurrency("EUR") + ->withCurrency($this->currency) ->withRecurringInfo(RecurringType::FIXED, RecurringSequence::FIRST) ->serialize(); @@ -357,77 +322,55 @@ public function testContinuousAuthorityRequest() public function testEnableDynamicCurrencyConversionRequest() { + $config = $this->config(); //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 GpEcomHppClient("secret"); //serialize the request $json = $service->Charge(19) - ->withCurrency("EUR") + ->withCurrency($this->currency) ->withTimestamp("20170725154824") ->withOrderId('GTI5Yxb0SumL_TkDMCAxQA') ->serialize(); $this->assertNotNull($json); - $this->assertEquals('{"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"}', $json); + $this->assertEquals('{"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":"https:\/\/requestb.in\/10q2bjb1","HPP_VERSION":"2","SHA1HASH":"448d742db89b05ce97152beb55157c904f3839cc"}', $json); } public function testDisableDynamicCurrencyConversionRequest() { //set config for DCC - $config = new GpEcomConfig(); + $config = $this->config(); $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 GpEcomHppClient("secret"); //serialize the request $json = $service->Charge(19) - ->withCurrency("EUR") + ->withCurrency($this->currency) ->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"}'); + $this->assertEquals('{"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":"https:\/\/requestb.in\/10q2bjb1","HPP_VERSION":"2","SHA1HASH":"448d742db89b05ce97152beb55157c904f3839cc"}', $json); } /* 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 = $this->config(); $config->hostedPaymentConfig->version = 2; $config->hostedPaymentConfig->fraudFilterMode = FraudFilterMode::PASSIVE; @@ -441,7 +384,7 @@ public function testFraudManagementRequest() //serialize the request $json = $service->charge(19) - ->withCurrency("EUR") + ->withCurrency($this->currency) ->withAddress($this->billingAddress, AddressType::BILLING) ->withAddress($this->shippingAddress, AddressType::SHIPPING) ->withClientTransactionId("Car Part HV") // varref @@ -464,15 +407,9 @@ public function testFraudManagementRequest() public function testFraudManagementRequestWithRules() { - $config = new GpEcomConfig(); + $config = $this->config(); $config->merchantId = 'myMerchantId'; $config->accountId = 'internet'; - $config->sharedSecret = "secret"; - $config->serviceUrl = "https://api.sandbox.realexpayments.com/epage-remote.cgi"; - - $config->hostedPaymentConfig = new HostedPaymentConfig(); - $config->hostedPaymentConfig->language = "GB"; - $config->hostedPaymentConfig->responseUrl = "https://www.example.com/response"; $config->hostedPaymentConfig->version = HppVersion::VERSION_2; $config->hostedPaymentConfig->fraudFilterMode = FraudFilterMode::PASSIVE; @@ -493,7 +430,7 @@ public function testFraudManagementRequestWithRules() //serialize the request $json = $service->charge(19.99) - ->withCurrency("EUR") + ->withCurrency($this->currency) ->withAddress($this->billingAddress, AddressType::BILLING) ->withAddress($this->shippingAddress, AddressType::SHIPPING) ->withClientTransactionId("Car Part HV") // varref @@ -520,24 +457,18 @@ public function testFraudManagementRequestWithRules() public function testBasicAuthHppVersion1() { - $config = new GpEcomConfig(); + $config = $this->config(); $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->postDimensions = "https://www.example.com"; $config->hostedPaymentConfig->postResponse = "https://www.example.com"; $config->hostedPaymentConfig->version = HppVersion::VERSION_1; $service = new HostedService($config); - $client = new GpEcomHppClient("secret"); $json = $service->authorize(19.99) - ->withCurrency("EUR") + ->withCurrency($this->currency) ->withTimeStamp("20170725154824") ->WithOrderId("GTI5Yxb0SumL_TkDMCAxQA") ->serialize(); @@ -548,22 +479,16 @@ public function testBasicAuthHppVersion1() public function testBasicAuthHppVersion2() { - $config = new GpEcomConfig(); + $config = $this->config(); $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 GpEcomHppClient("secret"); $json = $service->authorize(19.99) - ->withCurrency("EUR") + ->withCurrency($this->currency) ->withTimeStamp("20170725154824") ->WithOrderId("GTI5Yxb0SumL_TkDMCAxQA") ->serialize(); @@ -574,22 +499,16 @@ public function testBasicAuthHppVersion2() public function testBasicSale() { - $config = new GpEcomConfig(); + $config = $this->config(); $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 GpEcomHppClient("secret"); $json = $service->charge(19.99) - ->withCurrency("EUR") + ->withCurrency($this->currency) ->withTimeStamp("20170725154824") ->WithOrderId("GTI5Yxb0SumL_TkDMCAxQA") ->serialize(); @@ -600,19 +519,13 @@ public function testBasicSale() public function testBasicHostedPaymentDataHppVersion1() { - $config = new GpEcomConfig(); + $config = $this->config(); $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 GpEcomHppClient("secret"); $hostedPaymentData = new HostedPaymentData(); $hostedPaymentData->offerToSaveCard = "1"; // display the save card tick box @@ -621,7 +534,7 @@ public function testBasicHostedPaymentDataHppVersion1() $hostedPaymentData->productId = 'a0b38df5-b23c-4d82-88fe-2e9c47438972-b23c-4d82-88f'; $json = $service->charge(19.99) - ->withCurrency("EUR") + ->withCurrency($this->currency) ->withTimeStamp("20170725154824") ->WithOrderId("GTI5Yxb0SumL_TkDMCAxQA") ->WithHostedPaymentData($hostedPaymentData) @@ -635,19 +548,13 @@ public function testBasicHostedPaymentDataHppVersion1() public function testBasicHostedPaymentDataHppVersion2() { - $config = new GpEcomConfig(); + $config = $this->config(); $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 GpEcomHppClient("secret"); $hostedPaymentData = new HostedPaymentData(); $hostedPaymentData->offerToSaveCard = "1"; // display the save card tick box @@ -656,7 +563,7 @@ public function testBasicHostedPaymentDataHppVersion2() $hostedPaymentData->productId = 'a0b38df5-b23c-4d82-88fe-2e9c47438972-b23c-4d82-88f'; $json = $service->charge(19.99) - ->withCurrency("EUR") + ->withCurrency($this->currency) ->withTimeStamp("20170725154824") ->WithOrderId("GTI5Yxb0SumL_TkDMCAxQA") ->WithHostedPaymentData($hostedPaymentData) @@ -670,15 +577,7 @@ public function testBasicHostedPaymentDataHppVersion2() 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"; - + $config = $this->config(); $client = new GpEcomHppClient("secret"); $address = new Address(); @@ -691,8 +590,8 @@ public function testParseResponse() $service = new HostedService($config); $json = $service->authorize(1) - ->withCurrency("EUR") - ->withCustomerId("123456") + ->withCurrency($this->currency) + ->withCustomerId(GenerationUtils::getGuid()) ->withAddress($address) ->serialize(); @@ -718,14 +617,9 @@ public function testParseResponse() public function testHostedPaymentDataSupplementaryDataSerialize() { - $config = new GpEcomConfig(); + $config = $this->config(); $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; @@ -740,7 +634,7 @@ public function testHostedPaymentDataSupplementaryDataSerialize() $hostedPaymentData->supplementaryData = ['HPP_FRAUDFILTER_MODE' => 'ACTIVE']; $json = $service->charge(19.99) - ->withCurrency("EUR") + ->withCurrency($this->currency) ->withTimeStamp("20170725154824") ->withOrderId("GTI5Yxb0SumL_TkDMCAxQA") ->withHostedPaymentData($hostedPaymentData) @@ -754,14 +648,9 @@ public function testHostedPaymentDataSupplementaryDataSerialize() public function testSupplementaryDataWithOneValueSerialized() { - $config = new GpEcomConfig(); + $config = $this->config(); $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; @@ -775,7 +664,7 @@ public function testSupplementaryDataWithOneValueSerialized() $hostedPaymentData->productId = 'a0b38df5-b23c-4d82-88fe-2e9c47438972-b23c-4d82-88f'; $json = $service->charge(19.99) - ->withCurrency("EUR") + ->withCurrency($this->currency) ->withTimeStamp("20170725154824") ->withOrderId("GTI5Yxb0SumL_TkDMCAxQA") ->withHostedPaymentData($hostedPaymentData) @@ -790,14 +679,9 @@ public function testSupplementaryDataWithOneValueSerialized() public function testSupplementaryDataWithTwoValuesSerialized() { - $config = new GpEcomConfig(); + $config = $this->config(); $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; @@ -811,7 +695,7 @@ public function testSupplementaryDataWithTwoValuesSerialized() $hostedPaymentData->productId = 'a0b38df5-b23c-4d82-88fe-2e9c47438972-b23c-4d82-88f'; $json = $service->charge(19.99) - ->withCurrency("EUR") + ->withCurrency($this->currency) ->withTimeStamp("20170725154824") ->withOrderId("GTI5Yxb0SumL_TkDMCAxQA") ->withHostedPaymentData($hostedPaymentData) @@ -826,14 +710,10 @@ public function testSupplementaryDataWithTwoValuesSerialized() public function testNetherlandsAntillesCountry() { - $config = new GpEcomConfig(); + $config = $this->config(); $config->merchantId = "MerchantId"; $config->accountId = "internet"; - $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; @@ -845,7 +725,7 @@ public function testNetherlandsAntillesCountry() $hostedPaymentData->productId = 'a0b38df5-b23c-4d82-88fe-2e9c47438972-b23c-4d82-88f'; $this->billingAddress->country = 'AN'; $json = $service->charge(19.99) - ->withCurrency("EUR") + ->withCurrency($this->currency) ->withHostedPaymentData($hostedPaymentData) ->withAddress($this->billingAddress, AddressType::BILLING) ->serialize(); @@ -857,11 +737,7 @@ public function testNetherlandsAntillesCountry() public function testCardBlockingPayment() { - $config = new GpEcomConfig(); - $config->merchantId = "heartlandgpsandbox"; - $config->accountId = "hpp"; - $config->sharedSecret = "secret"; - $config->serviceUrl = "https://pay.sandbox.realexpayments.com/pay"; + $config = $this->config(); $config->hostedPaymentConfig = new HostedPaymentConfig(); $config->hostedPaymentConfig->version = HppVersion::VERSION_2; @@ -878,7 +754,7 @@ public function testCardBlockingPayment() $hostedPaymentData->blockCardTypes = $blockCardTypes; $json = $service->charge(10.01) - ->withCurrency("EUR") + ->withCurrency($this->currency) ->withHostedPaymentData($hostedPaymentData) ->serialize(); $response = json_decode($json, true); @@ -893,11 +769,7 @@ public function testCardBlockingPayment() public function testCardBlockingPayment_AllCardTypes() { - $config = new GpEcomConfig(); - $config->merchantId = "heartlandgpsandbox"; - $config->accountId = "hpp"; - $config->sharedSecret = "secret"; - $config->serviceUrl = "https://pay.sandbox.realexpayments.com/pay"; + $config = $this->config(); $config->hostedPaymentConfig = new HostedPaymentConfig(); $config->hostedPaymentConfig->version = HppVersion::VERSION_2; @@ -914,7 +786,7 @@ public function testCardBlockingPayment_AllCardTypes() $hostedPaymentData->blockCardTypes = $blockCardTypes; $json = $service->charge(10.01) - ->withCurrency("EUR") + ->withCurrency($this->currency) ->withHostedPaymentData($hostedPaymentData) ->serialize(); $response = json_decode($json, true); @@ -939,11 +811,7 @@ public function testCardBlockingPayment_AllCardTypes() */ public function testBasicChargeAlternativePayment() { - $config = new GpEcomConfig(); - $config->merchantId = "heartlandgpsandbox"; - $config->accountId = "hpp"; - $config->sharedSecret = "secret"; - $config->serviceUrl = "https://pay.sandbox.realexpayments.com/pay"; + $config = $this->config(); $config->hostedPaymentConfig = new HostedPaymentConfig(); $config->hostedPaymentConfig->version = HppVersion::VERSION_2; @@ -966,7 +834,7 @@ public function testBasicChargeAlternativePayment() $hostedPaymentData->presetPaymentMethods = $apmTypes; $json = $service->charge(10.01) - ->withCurrency("EUR") + ->withCurrency($this->currency) ->withHostedPaymentData($hostedPaymentData) ->serialize(); @@ -991,26 +859,17 @@ public function testBasicChargeAlternativePayment() public function testCaptureBillingShippingInfo() { - $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 = $this->config(); $config->hostedPaymentConfig->version = HppVersion::VERSION_2; $service = new HostedService($config); - $client = new GpEcomHppClient("secret"); $hostedPaymentData = new HostedPaymentData(); $hostedPaymentData->addressCapture = true; $hostedPaymentData->notReturnAddress = false; $json = $service->charge(19) - ->withCurrency("EUR") + ->withCurrency($this->currency) ->withAddress($this->billingAddress, AddressType::BILLING) ->withAddress($this->shippingAddress, AddressType::SHIPPING) ->withHostedPaymentData($hostedPaymentData) @@ -1022,13 +881,7 @@ public function testCaptureBillingShippingInfo() public function testOpenBankingInitiate() { - $config = new GpEcomConfig(); - $config->merchantId = 'openbankingsandbox'; - $config->sharedSecret = 'sharedsecret'; - $config->accountId = 'internet'; - $config->serviceUrl = "https://pay.sandbox.realexpayments.com/pay"; - $config->enableBankPayment = true; - $config->hostedPaymentConfig = new HostedPaymentConfig(); + $config = $this->config(); $config->hostedPaymentConfig->version = HppVersion::VERSION_2; $config->shaHashType = ShaHashType::SHA256; @@ -1065,13 +918,7 @@ public function testOpenBankingInitiate() public function test3DSExemption() { - $config = new GpEcomConfig(); - $config->merchantId = "heartlandgpsandbox"; - $config->accountId = "3dsecure"; - $config->sharedSecret = "secret"; - $config->hostedPaymentConfig = new HostedPaymentConfig(); - $config->hostedPaymentConfig->language = "GB"; - $config->hostedPaymentConfig->responseUrl = "https://www.example.com/response"; + $config = $this->config(); $config->hostedPaymentConfig->version = HppVersion::VERSION_2; $service = new HostedService($config); @@ -1083,7 +930,7 @@ public function test3DSExemption() //serialize the request $json = $service->charge(10.01) - ->withCurrency("EUR") + ->withCurrency($this->currency) ->withAddress($this->billingAddress, AddressType::BILLING) ->withAddress($this->shippingAddress, AddressType::SHIPPING) ->withHostedPaymentData($hostedPaymentData) @@ -1094,4 +941,184 @@ public function test3DSExemption() $this->assertTrue(isset($jsonResponse['HPP_ENABLE_EXEMPTION_OPTIMIZATION'])); $this->assertTrue($jsonResponse['HPP_ENABLE_EXEMPTION_OPTIMIZATION']); } + + /* 10. ThreedSecureResponse */ + + public function testThreeDSecureResponse() + { + $config = $this->config(); + $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":"https:\/\/requestb.in\/10q2bjb1","CARD_PAYMENT_BUTTON":null,"MESSAGE":"[ test system ] Authorised","AMOUNT":null,"SHA1HASH":"d1ff806b449b86375dbda74e2611760c348fcdeb","DCC_INFO_REQUST":null,"DCC_INFO_RESPONSE":null,"HPP_FRAUDFILTER_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 = $this->config(); + $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":"https:\/\/requestb.in\/10q2bjb1","CARD_PAYMENT_BUTTON":null,"MESSAGE":"[ test system ] Authorised","AMOUNT":"100","SHA1HASH":"32628cf3f887ab9f4f1c547a10ac365c2168f0e2","DCC_INFO":null,"HPP_FRAUDFILTER_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 = $this->config(); + $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":"https:\/\/requestb.in\/10q2bjb1","CARD_PAYMENT_BUTTON":null,"MESSAGE":"[ test system ] Authorised","AMOUNT":"1500","SHA1HASH":"4c7a635401c57371a0931bb3a21a849181cc963d","DCC_INFO":null,"HPP_FRAUDFILTER_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 = $this->config(); + $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", "MERCHANT_RESPONSE_URL" => "https://requestb.in/10q2bjb1", "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 = $this->config(); + $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", "MERCHANT_RESPONSE_URL" => "https://requestb.in/10q2bjb1", "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 = $this->config(); + $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":"https:\/\/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_FRAUDFILTER_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); + } + + public function testCheckHashVulnerability() + { + $config = $this->config(); + $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":"https:\/\/requestb.in\/10q2bjb1","CARD_PAYMENT_BUTTON":null,"MESSAGE":"[ test system ] Authorised","AMOUNT":"100","SHA1HASH":true,"DCC_INFO":null,"HPP_FRAUDFILTER_MODE":null,"TSS_INFO":null}'; + + $exceptionCaught = false; + try { + $service->parseResponse($responseJson); + } catch (ApiException $e) { + $exceptionCaught = true; + $this->assertEquals('Incorrect hash. Please check your code and the Developers Documentation.', $e->getMessage()); + } finally { + $this->assertTrue($exceptionCaught); + } + } } diff --git a/test/Integration/Gateways/GpEcomConnector/HppTestCase.php b/test/Integration/Gateways/GpEcomConnector/HppTestCase.php deleted file mode 100644 index 7d145996..00000000 --- a/test/Integration/Gateways/GpEcomConnector/HppTestCase.php +++ /dev/null @@ -1,260 +0,0 @@ -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() : void - { - $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_FRAUDFILTER_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_FRAUDFILTER_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_FRAUDFILTER_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", "MERCHANT_RESPONSE_URL" => "http://requestb.in/10q2bjb1" ,"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","MERCHANT_RESPONSE_URL" => "http://requestb.in/10q2bjb1", "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_FRAUDFILTER_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); - } - - public function testCheckHashVulnerability() - { - $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":true,"DCC_INFO":null,"HPP_FRAUDFILTER_MODE":null,"TSS_INFO":null}'; - - $exceptionCaught = false; - try { - $service->parseResponse($responseJson); - } catch (ApiException $e) { - $exceptionCaught = true; - $this->assertEquals('Incorrect hash. Please check your code and the Developers Documentation.', $e->getMessage()); - } finally { - $this->assertTrue($exceptionCaught); - } - } -} diff --git a/test/Integration/Gateways/GpEcomConnector/OpenBankingTest.php b/test/Integration/Gateways/GpEcomConnector/OpenBankingTest.php index fd600b0e..b9537594 100644 --- a/test/Integration/Gateways/GpEcomConnector/OpenBankingTest.php +++ b/test/Integration/Gateways/GpEcomConnector/OpenBankingTest.php @@ -2,6 +2,7 @@ namespace GlobalPayments\Api\Tests\Integration\Gateways\GpEcomConnector; +use DateTime; use GlobalPayments\Api\Entities\Enums\{BankPaymentStatus, BankPaymentType, RemittanceReferenceType, ShaHashType}; use GlobalPayments\Api\Entities\Exceptions\GatewayException; use GlobalPayments\Api\Entities\GpApi\PagedResult; @@ -340,9 +341,9 @@ public function testFasterPaymentsCharge_MissingRemittanceReferenceType() $bankPayment = $this->fasterPaymentsConfig(); $trn = $bankPayment->charge($this->amount) - ->withCurrency($this->currency) - ->withRemittanceReference(null, $this->remittanceReferenceValue) - ->execute(); + ->withCurrency($this->currency) + ->withRemittanceReference(null, $this->remittanceReferenceValue) + ->execute(); $this->assertOpenBankingResponse($trn); } diff --git a/test/Integration/Gateways/GpEcomConnector/ReportingTest.php b/test/Integration/Gateways/GpEcomConnector/ReportingTest.php index b0a5b71c..9908c72e 100644 --- a/test/Integration/Gateways/GpEcomConnector/ReportingTest.php +++ b/test/Integration/Gateways/GpEcomConnector/ReportingTest.php @@ -31,13 +31,13 @@ public function setup(): void public function testGetTransactionDetail() { - $transactionId = "rMuOHxP5SCyCzOYE8mKCsA"; + $transactionId = "MTMzMmE3MjgtODA3ZmU2Mw"; /** @var TransactionSummary $response */ $response = ReportingService::transactionDetail($transactionId)->execute(); $this->assertNotNull($response); $this->assertEquals($transactionId, $response->orderId); - $this->assertEquals('5CoDxmuV5efGltP9', $response->schemeReferenceData); + $this->assertEquals('VVe8uPnxNDDt1LYw', $response->schemeReferenceData); $this->assertEquals('U', $response->avsResponseCode); $this->assertEquals('M', $response->cvnResponseCode); $this->assertEquals('00', $response->gatewayResponseCode); diff --git a/test/Integration/Gateways/Terminals/UPA/UpaMicTests.php b/test/Integration/Gateways/Terminals/UPA/UpaMicTests.php index e5b10478..ea652e66 100644 --- a/test/Integration/Gateways/Terminals/UPA/UpaMicTests.php +++ b/test/Integration/Gateways/Terminals/UPA/UpaMicTests.php @@ -2,50 +2,51 @@ namespace GlobalPayments\Api\Tests\Integration\Gateways\Terminals\UPA; -use _PHPStan_b8e553790\Nette\Schema\Elements\Base; use GlobalPayments\Api\Entities\Enums\Channel; -use GlobalPayments\Api\Entities\Enums\Environment; +use GlobalPayments\Api\Entities\Exceptions\ApiException; +use GlobalPayments\Api\Entities\Exceptions\BuilderException; use GlobalPayments\Api\Entities\GpApi\AccessTokenInfo; -use GlobalPayments\Api\ServiceConfigs\Gateways\GpApiConfig; use GlobalPayments\Api\Services\DeviceService; +use GlobalPayments\Api\Terminals\Abstractions\IDeviceInterface; use GlobalPayments\Api\Terminals\ConnectionConfig; use GlobalPayments\Api\Terminals\Enums\ConnectionModes; use GlobalPayments\Api\Terminals\Enums\DeviceType; -use GlobalPayments\Api\Terminals\TerminalResponse; use GlobalPayments\Api\Tests\Data\BaseGpApiTestConfig; use GlobalPayments\Api\Tests\Integration\Gateways\Terminals\LogManagement; use GlobalPayments\Api\Tests\Integration\Gateways\Terminals\RequestIdProvider; +use GlobalPayments\Api\Utils\GenerationUtils; use PHPUnit\Framework\TestCase; -class UpaMicTests extends TestCase +class UpaMicTests extends TestCase { - private $device; + private IDeviceInterface $device; - public function setup() : void + /** + * @throws ApiException + */ + public function setup(): void { $this->device = DeviceService::create($this->getConfig()); } - public function tearDown() : void + public function tearDown(): void { sleep(3); BaseGpApiTestConfig::resetGpApiConfig(); } - protected function getConfig() : ConnectionConfig + public function getConfig(): ConnectionConfig { $config = new ConnectionConfig(); $config->deviceType = DeviceType::UPA_DEVICE; $config->connectionMode = ConnectionModes::MIC; - BaseGpApiTestConfig::$appId = BaseGpApiTestConfig::UPA_MIC_DEVICE_APP_ID; #gitleaks:allow - BaseGpApiTestConfig::$appKey = BaseGpApiTestConfig::UPA_MIC_DEVICE_APP_KEY; #gitleaks:allow + BaseGpApiTestConfig::$appId = BaseGpApiTestConfig::APP_ID; #gitleaks:allow + BaseGpApiTestConfig::$appKey = BaseGpApiTestConfig::APP_KEY; #gitleaks:allow $gpApiConfig = BaseGpApiTestConfig::gpApiSetupConfig(Channel::CardPresent); - $gpApiConfig->environment = Environment::QA; $gpApiConfig->country = 'US'; $gpApiConfig->deviceCurrency = 'USD'; $accessTokenInfo = new AccessTokenInfo(); - $accessTokenInfo->transactionProcessingAccountName = "DublinTransAccount_Nucleus01"; - $accessTokenInfo->transactionProcessingAccountID = 'TRA_4dca2d890e914f7da0790a70947b98c8'; + $accessTokenInfo->transactionProcessingAccountName = "transaction_processing"; $gpApiConfig->accessTokenInfo = $accessTokenInfo; $config->gatewayConfig = $gpApiConfig; $config->requestIdProvider = new RequestIdProvider(); @@ -56,10 +57,18 @@ protected function getConfig() : ConnectionConfig public function testCreditSale() { - /** @var TerminalResponse $response */ $response = $this->device->sale(10) - ->withEcrId(13) - ->withTerminalRefNumber('1234') + ->execute(); + + $this->assertNotNull($response); + $this->assertEquals('00', $response->deviceResponseCode); + $this->assertEquals('INITIATED', $response->deviceResponseText); + } + + public function testCreditSaleWithTerminalRefNumber() + { + $response = $this->device->sale(10) + ->withTerminalRefNumber(GenerationUtils::getGuid()) ->execute(); $this->assertNotNull($response); @@ -74,4 +83,133 @@ public function testLineItem() $this->assertEquals('00', $response->deviceResponseCode); $this->assertEquals('INITIATED', $response->deviceResponseText); } + + public function testCreditAuth() + { + $response = $this->device->authorize(10) + ->withEcrId(13) + ->withTerminalRefNumber('1234') + ->execute(); + + $this->assertNotNull($response); + $this->assertEquals('00', $response->deviceResponseCode); + $this->assertEquals('INITIATED', $response->deviceResponseText); + } + + public function testCreditAuthAndCapture() + { + $response = $this->device->authorize(10) + ->withEcrId(13) + ->withTerminalRefNumber('1234') + ->execute(); + + $this->assertNotNull($response); + $this->assertEquals('00', $response->deviceResponseCode); + $this->assertEquals('INITIATED', $response->deviceResponseText); + + $response = $this->device->capture(10) + ->withTransactionId($response->transactionId) + ->execute(); + + $this->assertNotNull($response); + $this->assertEquals('00', $response->deviceResponseCode); + $this->assertEquals('INITIATED', $response->deviceResponseText); + } + + public function testCreditCapture_RandomId() + { + $response = $this->device->capture(10) + ->withTransactionId(GenerationUtils::getGuid()) + ->execute(); + + $this->assertNotNull($response); + $this->assertEquals('00', $response->deviceResponseCode); + $this->assertEquals('INITIATED', $response->deviceResponseText); + } + + public function testCreditRefund() + { + $response = $this->device->refund(10) + ->execute(); + + $this->assertNotNull($response); + $this->assertEquals('00', $response->deviceResponseCode); + $this->assertEquals('INITIATED', $response->deviceResponseText); + } + + public function testCreditVerify() + { + $response = $this->device->verify() + ->execute(); + + $this->assertNotNull($response); + $this->assertEquals('00', $response->deviceResponseCode); + $this->assertEquals('INITIATED', $response->deviceResponseText); + } + + public function testCreditVoid() + { + $response = $this->device->void() + ->execute(); + + $this->assertNotNull($response); + $this->assertEquals('00', $response->deviceResponseCode); + $this->assertEquals('INITIATED', $response->deviceResponseText); + } + + public function testCreditSale_WithoutAmount() + { + $exceptionCaught = false; + try { + $this->device->sale() + ->execute(); + } catch (BuilderException $e) { + $exceptionCaught = true; + $this->assertEquals('amount cannot be null for this transaction type.', $e->getMessage()); + } finally { + $this->assertTrue($exceptionCaught); + } + } + + public function testCreditAuth_WithoutAmount() + { + $exceptionCaught = false; + try { + $this->device->authorize() + ->execute(); + } catch (BuilderException $e) { + $exceptionCaught = true; + $this->assertEquals('amount cannot be null for this transaction type.', $e->getMessage()); + } finally { + $this->assertTrue($exceptionCaught); + } + } + + public function testCreditCapture_WithoutTransactionId() + { + $exceptionCaught = false; + try { + $this->device->capture(10) + ->execute(); + } catch (BuilderException $e) { + $exceptionCaught = true; + $this->assertEquals('transactionId cannot be null for this transaction type.', $e->getMessage()); + } finally { + $this->assertTrue($exceptionCaught); + } + } + + public function testCreditRefund_WithoutAmount() + { + $exceptionCaught = false; + try { + $this->device->refund() + ->execute(); + } catch (BuilderException $e) { + $exceptionCaught = true; + $this->assertEquals('amount cannot be null for this transaction type.', $e->getMessage()); + } finally { + $this->assertTrue($exceptionCaught); + } + } } \ No newline at end of file