From e840358cb1f87bb0a7ce83485222c88d9d42fce2 Mon Sep 17 00:00:00 2001 From: Aryeh Schechter Date: Sun, 30 Aug 2020 13:07:18 +0300 Subject: [PATCH 1/4] If last four numbers of the card aren't returned try to get the numbers from the accountNumber in the response body --- src/Message/AIMResponse.php | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/Message/AIMResponse.php b/src/Message/AIMResponse.php index 785b6c24..22afaf1c 100644 --- a/src/Message/AIMResponse.php +++ b/src/Message/AIMResponse.php @@ -171,10 +171,17 @@ public function getTransactionReference($serialize = true) try { // Need to store card details in the transaction reference since it is required when doing a refund if ($card = $this->request->getCard()) { - $transactionRef->setCard(array( - 'number' => $card->getNumberLastFour(), - 'expiry' => $card->getExpiryDate('mY') - )); + if (isset($card->getNumberLastFour())) { + $transactionRef->setCard(array( + 'number' => $card->getNumberLastFour(), + 'expiry' => $card->getExpiryDate('mY') + )); + } elseif (isset($body->accountNumber)) { + $transactionRef->setCard(array( + 'number' => substr((string)$body->accountNumber, -4, 4) ?: null, + 'expiry' => $card->getExpiryDate('mY') + )); + } } elseif ($cardReference = $this->request->getCardReference()) { $transactionRef->setCardReference(new CardReference($cardReference)); } From 10d6bb5416476a9a91c49de842bb8d9e522ff137 Mon Sep 17 00:00:00 2001 From: Aryeh Schechter Date: Mon, 31 Aug 2020 09:44:29 +0300 Subject: [PATCH 2/4] fix checking if getNumberLastFour returns a value --- src/Message/AIMResponse.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Message/AIMResponse.php b/src/Message/AIMResponse.php index 22afaf1c..c40bb44a 100644 --- a/src/Message/AIMResponse.php +++ b/src/Message/AIMResponse.php @@ -171,7 +171,7 @@ public function getTransactionReference($serialize = true) try { // Need to store card details in the transaction reference since it is required when doing a refund if ($card = $this->request->getCard()) { - if (isset($card->getNumberLastFour())) { + if (null !== $card->getNumberLastFour()) { $transactionRef->setCard(array( 'number' => $card->getNumberLastFour(), 'expiry' => $card->getExpiryDate('mY') From aca6c03ec8dc8006046aabd1616ecaf7ee0b3614 Mon Sep 17 00:00:00 2001 From: Aryeh Schechter Date: Mon, 31 Aug 2020 09:45:34 +0300 Subject: [PATCH 3/4] Test for a purchase made without a card getting the card numbers from the response --- tests/Message/AIMResponseTest.php | 34 +++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/tests/Message/AIMResponseTest.php b/tests/Message/AIMResponseTest.php index 3e046436..7ca8b2bb 100644 --- a/tests/Message/AIMResponseTest.php +++ b/tests/Message/AIMResponseTest.php @@ -39,6 +39,40 @@ public function testAuthorizeSuccess() $this->assertSame('Visa', $response->getAccountType()); } + public function testAuthorizeCardlessSuccess() + { + $httpResponse = $this->getMockHttpResponse('AIMAuthorizeCardlessSuccess.txt'); + $request = new AIMAuthorizeRequest($this->getHttpClient(), $this->getHttpRequest()); + $request->initialize( + array( + 'clientIp' => '10.0.0.1', + 'amount' => '12.00', + 'customerId' => 'cust-id', + 'card' => array( + 'number' => null, + 'expiry' => '121999' + ), + 'duplicateWindow' => 0, + 'solutionId' => 'SOL12345ID', + 'marketType' => '2', + 'deviceType' => '1', + ) + ); + $request->setOpaqueDataDescriptor('COMMON.ACCEPT.INAPP.PAYMENT'); + $request->setOpaqueDataValue('jb2RlIjoiNTB'); + $response = new AIMResponse($request, $httpResponse->getBody()); + + $this->assertTrue($response->isSuccessful()); + $this->assertSame('{"approvalCode":"GA4OQP","transId":"2184493132","card":{"number":"1111","expiry":"121999"}}', $response->getTransactionReference()); + $this->assertSame('This transaction has been approved.', $response->getMessage()); + $this->assertSame(1, $response->getResultCode()); + $this->assertSame(1, $response->getReasonCode()); + $this->assertSame('GA4OQP', $response->getAuthorizationCode()); + $this->assertSame('Y', $response->getAVSCode()); + $this->assertSame('P', $response->getCVVCode()); + $this->assertSame('Visa', $response->getAccountType()); + } + public function testAuthorizeFailure() { $httpResponse = $this->getMockHttpResponse('AIMAuthorizeFailure.txt'); From 237d73ec05ce4902bd9c76d94c51a701a22bc7cc Mon Sep 17 00:00:00 2001 From: Aryeh Schechter Date: Mon, 31 Aug 2020 09:46:15 +0300 Subject: [PATCH 4/4] Include test Response for new cardless test --- tests/Mock/AIMAuthorizeCardlessSuccess.txt | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 tests/Mock/AIMAuthorizeCardlessSuccess.txt diff --git a/tests/Mock/AIMAuthorizeCardlessSuccess.txt b/tests/Mock/AIMAuthorizeCardlessSuccess.txt new file mode 100644 index 00000000..ab84ae68 --- /dev/null +++ b/tests/Mock/AIMAuthorizeCardlessSuccess.txt @@ -0,0 +1,13 @@ +HTTP/1.1 200 OK +Date: Sat, 02 Aug 2014 05:17:50 GMT +Server: Microsoft-IIS/6.0 +Access-Control-Allow-Origin: * +Access-Control-Allow-Methods: GET, POST, OPTIONS +Access-Control-Allow-Headers: x-requested-with, cache-control, content-type, origin, method +X-Powered-By: ASP.NET +X-AspNet-Version: 2.0.50727 +Cache-Control: private +Content-Type: text/xml; charset=utf-8 +Content-Length: 884 + +123456OkI00001Successful.1GA4OQPYP22184493132DEBBE205CFD3D2DD0FD760EEBAAB81CC0XXXX1111Visa1This transaction has been approved.