From 2924c58867c144b9b2660b0267b0aef49ba1b761 Mon Sep 17 00:00:00 2001 From: securesubmit-buildmaster Date: Wed, 4 Dec 2024 08:15:21 -0500 Subject: [PATCH] OctopusDeploy release: 13.0.7 --- CHANGELOG.md | 6 +- metadata.xml | 2 +- src/Gateways/Gateway.php | 22 +-- src/Utils/Logging/RequestConsoleLogger.php | 51 +++++++ src/Utils/Logging/SampleRequestLogger.php | 3 +- .../CreditCardNotPresentTest.php | 3 +- .../GpApiConnector/DccCardPresentTest.php | 60 +++------ .../Gateways/GpApiConnector/GpApi3DS2Test.php | 10 +- .../Gateways/GpApiConnector/GpApiAchTest.php | 2 +- .../GpApiMerchantAccountsTest.php | 2 +- .../GpEcomConnector/RecurringTest.php | 125 +++++++++++++++++- 11 files changed, 211 insertions(+), 75 deletions(-) create mode 100644 src/Utils/Logging/RequestConsoleLogger.php diff --git a/CHANGELOG.md b/CHANGELOG.md index 6792461e..bde4cefb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,8 +3,12 @@ # Changelog +## Latest Version - v13.0.7 (12/03/24) +### Enhancements: +- Add console logger feature +- [GP-API/GP-ECOM] Unit tests enhancements -## Latest Version - v13.0.6 (11/19/24) +## v13.0.6 (11/19/24) ### Enhancements: - [GP-API] - Add new mapping fields on get transaction list: "funding", "authentication" diff --git a/metadata.xml b/metadata.xml index f3910482..8eb7f265 100644 --- a/metadata.xml +++ b/metadata.xml @@ -1,3 +1,3 @@ - 13.0.6 + 13.0.7 \ No newline at end of file diff --git a/src/Gateways/Gateway.php b/src/Gateways/Gateway.php index 4dc13483..581b6968 100644 --- a/src/Gateways/Gateway.php +++ b/src/Gateways/Gateway.php @@ -92,7 +92,7 @@ protected function sendRequest( array $queryStringParams = null ) { try { - $queryString = $this->buildQueryString($queryStringParams); + $queryString = !empty($queryStringParams) ? "?" . http_build_query($queryStringParams) : ''; $request = curl_init($this->serviceUrl . $endpoint . $queryString); $headers = $this->prepareHeaders($data); @@ -213,24 +213,4 @@ private function prepareHeaders(?string $data) : array return $headers ?? []; } - - /** - * @param array|null $queryStringParams - * - * @return string - */ - private function buildQueryString(array $queryStringParams = null) - { - if ($queryStringParams === null) { - return ''; - } - - $query = []; - - foreach ($queryStringParams as $key => $value) { - $query[] = sprintf('%s=%s', $key, $value); - } - - return sprintf('?%s', implode('&', $query)); - } } diff --git a/src/Utils/Logging/RequestConsoleLogger.php b/src/Utils/Logging/RequestConsoleLogger.php new file mode 100644 index 00000000..cec82e08 --- /dev/null +++ b/src/Utils/Logging/RequestConsoleLogger.php @@ -0,0 +1,51 @@ +statusCode . PHP_EOL); + $rs = clone $response; + if (str_contains($rs->header, ': gzip')) { + $rs->rawResponse = gzdecode($rs->rawResponse); + } + if (StringUtils::isJson($rs->rawResponse)) { + $rs->rawResponse = json_encode(json_decode($rs->rawResponse), JSON_PRETTY_PRINT); + } + print_r("Response body: " . $rs->rawResponse . PHP_EOL); + print_r("Response END" . PHP_EOL); + print_r("Request/Response END" . PHP_EOL); + print_r("============================================="); + } + + public function responseError(\Exception $e, $headers = '') + { + print_r("Exception START" . PHP_EOL); + print_r("Response headers: " . $headers . PHP_EOL); + print_r("Error occurred while communicating with the gateway" . PHP_EOL); + print_r("Exception type: " . get_class($e) . PHP_EOL); + print_r("Exception message: " . $e->getMessage() . PHP_EOL); + print_r("Exception END" . PHP_EOL); + print_r("============================================="); + } +} \ No newline at end of file diff --git a/src/Utils/Logging/SampleRequestLogger.php b/src/Utils/Logging/SampleRequestLogger.php index 0c7e43ac..6941f8f5 100644 --- a/src/Utils/Logging/SampleRequestLogger.php +++ b/src/Utils/Logging/SampleRequestLogger.php @@ -27,13 +27,12 @@ public function requestSent($verb, $endpoint, $headers, $queryStringParams, $dat $this->logger->info("REQUEST END"); } - public function responseReceived(GatewayResponse $response) { $this->logger->info("Response START"); $this->logger->info("Status code: " . $response->statusCode); $rs = clone $response; - if (strpos($rs->header, ': gzip') !== false) { + if (str_contains($rs->header, ': gzip')) { $rs->rawResponse = gzdecode($rs->rawResponse); } if (StringUtils::isJson($rs->rawResponse)) { diff --git a/test/Integration/Gateways/GpApiConnector/CreditCardNotPresentTest.php b/test/Integration/Gateways/GpApiConnector/CreditCardNotPresentTest.php index 735a0cd6..49f293e0 100644 --- a/test/Integration/Gateways/GpApiConnector/CreditCardNotPresentTest.php +++ b/test/Integration/Gateways/GpApiConnector/CreditCardNotPresentTest.php @@ -31,6 +31,7 @@ use GlobalPayments\Api\Tests\Data\BaseGpApiTestConfig; use GlobalPayments\Api\Tests\Data\GpApiAvsCheckTestCards; use GlobalPayments\Api\Utils\GenerationUtils; +use GlobalPayments\Api\Utils\Logging\RequestConsoleLogger; use PHPUnit\Framework\TestCase; class CreditCardNotPresentTest extends TestCase @@ -1405,6 +1406,7 @@ public function AvsCardTests(): array public function setUpConfig(): GpApiConfig { $config = BaseGpApiTestConfig::gpApiSetupConfig(Channel::CardNotPresent); + $config->requestLogger = new RequestConsoleLogger(); //DO NO DELETE - usage example for some settings // $config->dynamicHeaders = [ // 'x-gp-platform' => 'prestashop;version=1.7.2', @@ -1412,7 +1414,6 @@ public function setUpConfig(): GpApiConfig // ]; // $config->permissions = ['TRN_POST_Authorize']; // $config->webProxy = new CustomWebProxy('127.0.0.1:8866'); -// $config->requestLogger = new SampleRequestLogger(new Logger("logs")); return $config; } diff --git a/test/Integration/Gateways/GpApiConnector/DccCardPresentTest.php b/test/Integration/Gateways/GpApiConnector/DccCardPresentTest.php index 75a3542b..12525b90 100644 --- a/test/Integration/Gateways/GpApiConnector/DccCardPresentTest.php +++ b/test/Integration/Gateways/GpApiConnector/DccCardPresentTest.php @@ -16,31 +16,25 @@ use GlobalPayments\Api\ServicesContainer; use GlobalPayments\Api\Tests\Data\BaseGpApiTestConfig; use GlobalPayments\Api\Utils\GenerationUtils; -use GlobalPayments\Api\Utils\Logging\Logger; -use GlobalPayments\Api\Utils\Logging\SampleRequestLogger; use PHPUnit\Framework\TestCase; class DccCardPresentTest extends TestCase { private string $currency = 'EUR'; - private float $amount = 15.11; + private float $amount = 0.10; /** @var CreditCardData */ private CreditCardData $card; - const DCC_RATE_CONFIG = 'dcc_rate'; public function setup(): void { - $this->markTestIncomplete(); $config = $this->setUpConfig(); + $config->country = 'GB'; $accessTokenInfo = GpApiService::generateTransactionKey($config); $config->accessTokenInfo->accessToken = $accessTokenInfo->accessToken; ServicesContainer::configureService($config); - $dccRateConfig = $this->setUpConfigDcc(); - $dccRateConfig->accessTokenInfo->accessToken = $accessTokenInfo->accessToken; - ServicesContainer::configureService($dccRateConfig, self::DCC_RATE_CONFIG); $this->card = new CreditCardData(); - $this->card->number = "4263970000005262"; + $this->card->number = "4242424242424242"; $this->card->expMonth = date('m'); $this->card->expYear = date('Y', strtotime('+1 year')); $this->card->cardHolderName = "James Mason"; @@ -56,32 +50,21 @@ public function setUpConfig(): GpApiConfig { $config = BaseGpApiTestConfig::gpApiSetupConfig(Channel::CardPresent); $accessTokenInfo = new AccessTokenInfo(); - $accessTokenInfo->transactionProcessingAccountName = 'dcc'; + $accessTokenInfo->transactionProcessingAccountName = 'dcc_p'; $config->accessTokenInfo = $accessTokenInfo; return $config; } - public function setUpConfigDcc(): GpApiConfig - { - $config = BaseGpApiTestConfig::gpApiSetupConfig(Channel::CardPresent); - $accessTokenInfo = new AccessTokenInfo(); - $accessTokenInfo->transactionProcessingAccountName = 'dcc_rate'; - $config->accessTokenInfo = $accessTokenInfo; - $config->requestLogger = new SampleRequestLogger(new Logger("logs")); - return $config; - } - private function getDccDetails(): Transaction { return $this->card->getDccRate() ->withAmount($this->amount) ->withCurrency($this->currency) - ->execute(self::DCC_RATE_CONFIG); + ->execute(); } public function testCreditGetDccInfo() { - $this->card->number = '4006097467207025'; $orderId = GenerationUtils::generateOrderId(); $dccDetails = $this->getDccDetails(); @@ -105,7 +88,6 @@ public function testCreditGetDccInfo() public function testCreditDccRateAuthorize() { - $this->card->number = '4006097467207025'; $orderId = GenerationUtils::generateOrderId(); $dccDetails = $this->getDccDetails(); @@ -129,7 +111,6 @@ public function testCreditDccRateAuthorize() public function testCreditDccRateRefundStandalone() { - $this->card->number = '4006097467207025'; $orderId = GenerationUtils::generateOrderId(); $dccDetails = $this->getDccDetails(); @@ -153,7 +134,6 @@ public function testCreditDccRateRefundStandalone() public function testCreditDccRateReversal() { - $this->card->number = '4006097467207025'; $orderId = GenerationUtils::generateOrderId(); $dccDetails = $this->getDccDetails(); @@ -185,7 +165,6 @@ public function testCreditDccRateReversal() public function testCreditDccRateRefund() { - $this->card->number = '4006097467207025'; $orderId = GenerationUtils::generateOrderId(); $dccDetails = $this->getDccDetails(); @@ -219,31 +198,32 @@ public function testCreditDccRateRefund() public function testCreditGetDccInfo_CreditTrackData() { $creditTrackData = new CreditTrackData(); - $creditTrackData->setTrackData('%B4012002000060016^VI TEST CREDIT^251210118039000000000396?;4012002000060016=25121011803939600000?'); - $creditTrackData->entryMethod = EntryMethod::SWIPE; + $creditTrackData->setTrackData(';4761739001010036=25122011184404889?'); + $creditTrackData->entryMethod = EntryMethod::PROXIMITY; + $tagData = "9F4005F000F0A0019F02060000000025009F03060000000000009F2608D90A06501B48564E82027C005F3401019F360200029F0702FF009F0802008C9F0902008C9F34030403029F2701809F0D05F0400088009F0E0508000000009F0F05F0400098005F280208409F390105FFC605DC4000A800FFC7050010000000FFC805DC4004F8009F3303E0B8C89F1A0208409F350122950500000080005F2A0208409A031409109B02E8009F21030811539C01009F37045EED3A8E4F07A00000000310109F0607A00000000310108407A00000000310109F100706010A03A400029F410400000001"; $orderId = GenerationUtils::generateOrderId(); - $dccDetails = $this->getDccDetails(); + $dccDetails = $creditTrackData->getDccRate() + ->withAmount($this->amount) + ->withCurrency($this->currency) + ->execute(); + $this->assertNotNull($dccDetails); $this->assertEquals('SUCCESS', $dccDetails->responseCode); - $this->assertEquals('NOT_AVAILABLE', $dccDetails->responseMessage); + $this->assertEquals('AVAILABLE', $dccDetails->responseMessage); $this->assertNotNull($dccDetails->dccRateData); - $exceptionCaught = false; - try { - $creditTrackData->charge($this->amount) + $transaction = $creditTrackData->charge($this->amount) ->withCurrency($this->currency) ->withAllowDuplicates(true) ->withDccRateData($dccDetails->dccRateData) ->withClientTransactionId($orderId) + ->withTagData($tagData) ->execute(); - } catch (GatewayException $e) { - $exceptionCaught = true; - $this->assertEquals('Status Code: MANDATORY_DATA_MISSING - 37,Request expects the following field payer_amount payer_currency exchange_rate commission_percentage from the Merchant.', $e->getMessage()); - $this->assertEquals('40211', $e->responseCode); - } finally { - $this->assertTrue($exceptionCaught); - } + + $this->assertNotNull($transaction); + $this->assertEquals('SUCCESS', $transaction->responseCode); + $this->assertEquals(TransactionStatus::CAPTURED, $transaction->responseMessage); } public function testCreditGetDccInfo_DebitTrackData() diff --git a/test/Integration/Gateways/GpApiConnector/GpApi3DS2Test.php b/test/Integration/Gateways/GpApiConnector/GpApi3DS2Test.php index 76151dbf..b3c5fa5d 100644 --- a/test/Integration/Gateways/GpApiConnector/GpApi3DS2Test.php +++ b/test/Integration/Gateways/GpApiConnector/GpApi3DS2Test.php @@ -569,7 +569,7 @@ public function testCardHolderChallengeRequired_PostResult() $this->assertEquals(Secure3dStatus::SUCCESS_AUTHENTICATED, $secureEcom->status); $this->assertEquals('05', $secureEcom->eci); - $this->assertEquals('2.1.0', $secureEcom->messageVersion); + $this->assertEquals('2.2.0', $secureEcom->messageVersion); $this->assertNotNull($secureEcom->acsTransactionId); $this->assertNotNull($secureEcom->serverTransactionId); $this->assertNotNull($secureEcom->directoryServerTransactionId); @@ -611,7 +611,7 @@ public function testCardHolderChallengeRequired_PostResult_WithIdempotencyKey() $this->assertEquals(Secure3dStatus::SUCCESS_AUTHENTICATED, $secureEcom->status); $this->assertEquals('05', $secureEcom->eci); - $this->assertEquals('2.1.0', $secureEcom->messageVersion); + $this->assertEquals(Secure3dVersion::TWO, $secureEcom->getVersion()); $this->assertNotNull($secureEcom->acsTransactionId); $this->assertNotNull($secureEcom->serverTransactionId); $this->assertNotNull($secureEcom->directoryServerTransactionId); @@ -664,7 +664,7 @@ public function testCardHolderFrictionless_PostResult() $this->assertEquals(Secure3dStatus::SUCCESS_AUTHENTICATED, $secureEcom->status); $this->assertEquals('05', $secureEcom->eci); - $this->assertEquals('2.2.0', $secureEcom->messageVersion); + $this->assertEquals(Secure3dVersion::TWO, $secureEcom->getVersion()); $this->assertNotNull($secureEcom->acsTransactionId); $this->assertNotNull($secureEcom->serverTransactionId); $this->assertNotNull($secureEcom->directoryServerTransactionId); @@ -702,7 +702,7 @@ public function testCardHolderFrictionless_PostResult_WithIdempotencyKey() $this->assertEquals(Secure3dStatus::SUCCESS_AUTHENTICATED, $secureEcom->status); $this->assertEquals('05', $secureEcom->eci); - $this->assertEquals('2.2.0', $secureEcom->messageVersion); + $this->assertEquals(Secure3dVersion::TWO, $secureEcom->getVersion()); $this->assertNotNull($secureEcom->acsTransactionId); $this->assertNotNull($secureEcom->serverTransactionId); $this->assertNotNull($secureEcom->directoryServerTransactionId); @@ -1290,7 +1290,7 @@ private function assertInitiate3DSV2(ThreeDSecure $initAuth): void $this->assertNotNull($initAuth->payerAuthenticationRequest); $this->assertNotNull($initAuth->acsTransactionId); $this->assertEmpty($initAuth->eci); - $this->assertEquals("2.1.0", $initAuth->messageVersion); + $this->assertEquals("2.2.0", $initAuth->messageVersion); } } \ No newline at end of file diff --git a/test/Integration/Gateways/GpApiConnector/GpApiAchTest.php b/test/Integration/Gateways/GpApiConnector/GpApiAchTest.php index 12c1776b..bcea63e2 100644 --- a/test/Integration/Gateways/GpApiConnector/GpApiAchTest.php +++ b/test/Integration/Gateways/GpApiConnector/GpApiAchTest.php @@ -152,7 +152,7 @@ public function testCheckReauthorize() $this->eCheck->routingNumber = '123456780'; $startDate = (new DateTime())->modify('-1 year'); $endDate = (new DateTime())->modify('-2 days'); - $amount = '1.29'; + $amount = '11'; $response = ReportingService::findTransactionsPaged(1, 10) ->orderBy(TransactionSortProperty::TIME_CREATED, SortDirection::DESC) ->where(SearchCriteria::START_DATE, $startDate) diff --git a/test/Integration/Gateways/GpApiConnector/GpApiMerchantAccountsTest.php b/test/Integration/Gateways/GpApiConnector/GpApiMerchantAccountsTest.php index 2190ac57..629474f1 100644 --- a/test/Integration/Gateways/GpApiConnector/GpApiMerchantAccountsTest.php +++ b/test/Integration/Gateways/GpApiConnector/GpApiMerchantAccountsTest.php @@ -249,7 +249,7 @@ public function testAccountAddressLookup() $address = new Address(); $address->postalCode = 'CB6 1AS'; $address->streetAddress1 = '2649'; - $address->streetAddress2 = 'Primrose'; + $address->streetAddress2 = 'Primrose Cottage'; /** @var MerchantAccountSummary $response */ $response = ReportingService::accountDetail($this->config->accessTokenInfo->merchantManagementAccountID) ->withPaging(1, 10) diff --git a/test/Integration/Gateways/GpEcomConnector/RecurringTest.php b/test/Integration/Gateways/GpEcomConnector/RecurringTest.php index f00ae09a..fbe74ca9 100644 --- a/test/Integration/Gateways/GpEcomConnector/RecurringTest.php +++ b/test/Integration/Gateways/GpEcomConnector/RecurringTest.php @@ -3,13 +3,22 @@ namespace GlobalPayments\Api\Tests\Integration\Gateways\GpEcomConnector; use GlobalPayments\Api\Entities\Address; +use GlobalPayments\Api\Entities\BrowserData; use GlobalPayments\Api\Entities\Customer; +use GlobalPayments\Api\Entities\Enums\AddressType; +use GlobalPayments\Api\Entities\Enums\AuthenticationSource; +use GlobalPayments\Api\Entities\Enums\ChallengeWindowSize; +use GlobalPayments\Api\Entities\Enums\ColorDepth; use GlobalPayments\Api\Entities\Enums\DccProcessor; use GlobalPayments\Api\Entities\Enums\DccRateType; +use GlobalPayments\Api\Entities\Enums\MethodUrlCompletion; use GlobalPayments\Api\Entities\Enums\RecurringSequence; use GlobalPayments\Api\Entities\Enums\RecurringType; use GlobalPayments\Api\Entities\Enums\ScheduleFrequency; +use GlobalPayments\Api\Entities\Enums\Secure3dStatus; +use GlobalPayments\Api\Entities\Enums\Secure3dVersion; use GlobalPayments\Api\Entities\Enums\TransactionModifier; +use GlobalPayments\Api\Entities\Enums\TransactionStatus; use GlobalPayments\Api\Entities\Exceptions\ApiException; use GlobalPayments\Api\Entities\Exceptions\BuilderException; use GlobalPayments\Api\Entities\Exceptions\GatewayException; @@ -20,8 +29,10 @@ use GlobalPayments\Api\PaymentMethods\RecurringPaymentMethod; use GlobalPayments\Api\ServiceConfigs\Gateways\GpEcomConfig; use GlobalPayments\Api\Services\RecurringService; +use GlobalPayments\Api\Services\Secure3dService; use GlobalPayments\Api\ServicesContainer; use GlobalPayments\Api\Tests\Data\TestCards; +use GlobalPayments\Api\Tests\Integration\Gateways\ThreeDSecureAcsClient; use GlobalPayments\Api\Utils\GenerationUtils; use GlobalPayments\Api\Utils\Logging\Logger; use GlobalPayments\Api\Utils\Logging\SampleRequestLogger; @@ -33,6 +44,7 @@ class RecurringTest extends TestCase public Customer $newCustomer; public CreditCardData $card; + public string $gatewayProvider; public function getCustomerId() { @@ -58,6 +70,8 @@ protected function config() $config->sharedSecret = "secret"; $config->requestLogger = new SampleRequestLogger(new Logger("logs")); $config->channel = 'ECOM'; + $config->challengeNotificationUrl = 'https://ensi808o85za.x.pipedream.net'; + return $config; } @@ -68,13 +82,16 @@ protected function dccSetup() $config->accountId = "apidcc"; $config->refundPassword = "refund"; $config->sharedSecret = "secret"; + $config->methodNotificationUrl = 'https://www.example.com/methodNotificationUrl'; ServicesContainer::configureService($config); } public function setup(): void { - ServicesContainer::configureService($this->config()); + $config = $this->config(); + ServicesContainer::configureService($config); + $this->gatewayProvider = $config->getGatewayProvider(); $this->newCustomer = new Customer(); $this->newCustomer->key = $this->getCustomerId(); @@ -210,7 +227,6 @@ public function testcardStorageChargeCard() public function testcardStorageThreeDSecureVerifyEnrolled() { $paymentMethod = new RecurringPaymentMethod($this->getCustomerId(), $this->getPaymentId("Credit")); - $response = $paymentMethod->verify() ->withAmount(10) ->withCurrency('USD') @@ -1054,4 +1070,109 @@ public function testGetPaymentScheduleById_NullId() $this->assertTrue($exceptionCaught); } } + + public function testcardStorage3DSflow() + { + $amount = 10.01; + $currency = 'USD'; + $shippingAddress = new Address(); + $shippingAddress->streetAddress1 = "Apartment 852"; + $shippingAddress->streetAddress2 = "Complex 741"; + $shippingAddress->streetAddress3 = "no"; + $shippingAddress->city = "Chicago"; + $shippingAddress->postalCode = "5001"; + $shippingAddress->state = "IL"; + $shippingAddress->countryCode = "840"; + + $browserData = new BrowserData(); + $browserData->acceptHeader = "text/html,application/xhtml+xml,application/xml;q=9,image/webp,img/apng,*/*;q=0.8"; + $browserData->colorDepth = ColorDepth::TWENTY_FOUR_BITS; + $browserData->ipAddress = "123.123.123.123"; + $browserData->javaEnabled = true; + $browserData->javaScriptEnabled = true; + $browserData->language = "en"; + $browserData->screenHeight = 1080; + $browserData->screenWidth = 1920; + $browserData->challengWindowSize = ChallengeWindowSize::WINDOWED_600X400; + $browserData->timeZone = "0"; + $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"; + + $paymentMethod = new RecurringPaymentMethod($this->getCustomerRef(), $this->getPaymentRef()); + sleep(5); + $secureEcom = Secure3dService::checkEnrollment($paymentMethod) + ->execute(); + + $this->assertNotNull($secureEcom); + $this->assertNotNull($secureEcom->serverTransactionId); + + $this->assertEquals(Secure3dStatus::ENROLLED, $secureEcom->enrolled); + $this->assertEquals(Secure3dVersion::TWO, $secureEcom->getVersion()); + + $initAuth = Secure3dService::initiateAuthentication($paymentMethod, $secureEcom) + ->withAmount($amount) + ->withCurrency($currency) + ->withAuthenticationSource(AuthenticationSource::BROWSER) + ->withMethodUrlCompletion(MethodUrlCompletion::YES) + ->withOrderCreateDate(date('Y-m-d H:i:s')) + ->withAddress($shippingAddress, AddressType::BILLING) + ->withAddress($shippingAddress, AddressType::SHIPPING) + ->withBrowserData($browserData) + ->withMethodUrlCompletion(MethodUrlCompletion::NO) + ->withCustomerEmail('me@globalpayments.com') + ->execute(); + + $this->assertNotNull($initAuth); + $this->assertEquals(Secure3dStatus::CHALLENGE_REQUIRED, $secureEcom->status); + $this->assertNotNull($initAuth->issuerAcsUrl); + $this->assertNotNull($initAuth->payerAuthenticationRequest); + $this->assertEmpty($initAuth->eci); + + $authClient = new ThreeDSecureAcsClient($secureEcom->issuerAcsUrl); + $authClient->setGatewayProvider($this->gatewayProvider); + $authResponse = $authClient->authenticate_v2($initAuth); + $this->assertTrue($authResponse->getStatus()); + $this->assertNotEmpty($authResponse->getMerchantData()); + + $secureEcom = Secure3dService::getAuthenticationData() + ->withServerTransactionId($secureEcom->serverTransactionId) + ->execute(); + + $this->assertEquals(Secure3dStatus::SUCCESS_AUTHENTICATED, $secureEcom->status); + + $paymentMethod->threeDSecure = $secureEcom; + $response = $paymentMethod->charge($amount)->withCurrency($currency)->execute(); + + $this->assertNotNull($response); + $this->assertEquals('SUCCESS', $response->responseCode); + $this->assertEquals(TransactionStatus::CAPTURED, $response->responseMessage); + } + + private function getCustomerRef() : ?string + { + try { + $customer = $this->newCustomer; + $customer->key = sprintf("%s-Realex", (new \DateTime())->format("YmdHms")); + $customer->Create(); + return $customer->id; + } catch (GatewayException $e) { + } + } + + private function getPaymentRef() + { + $card = new CreditCardData(); + $card->number = "4012001037141112"; + $card->expMonth = 10; + $card->expYear = TestCards::validCardExpYear(); + $card->cvn = '123'; + $card->cardHolderName = 'James Mason'; + $paymentId = sprintf("%s-Realex-%s", (new \DateTime())->format("YmdHms"), "Credit"); + try { + /** @var RecurringPaymentMethod $paymentMethod */ + $paymentMethod = $this->newCustomer->addPaymentMethod($paymentId, $card)->create(); + return $paymentMethod->id; + } catch (GatewayException $exc) { + return null; + } + } }