diff --git a/src/Message/AIMResponse.php b/src/Message/AIMResponse.php index 785b6c24..c40bb44a 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 (null !== $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)); } 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'); 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.