From 7ccadb4f2902919ccf91ac0ae93fcf03da9604e0 Mon Sep 17 00:00:00 2001 From: Jason Judge Date: Wed, 14 Nov 2018 12:08:22 +0000 Subject: [PATCH] Issue #120 fix --- src/Message/Response.php | 2 +- .../ServerCompleteAuthorizeResponse.php | 2 +- src/Message/ServerNotifyRequest.php | 9 +++++ src/Traits/ResponseFieldsTrait.php | 12 +++++++ src/Traits/ServerNotifyTrait.php | 11 +------ .../ServerCompleteAuthorizeResponseTest.php | 33 +++++++++++++++++++ 6 files changed, 57 insertions(+), 12 deletions(-) diff --git a/src/Message/Response.php b/src/Message/Response.php index 4e555c0..5960f99 100644 --- a/src/Message/Response.php +++ b/src/Message/Response.php @@ -61,7 +61,7 @@ public function getTransactionReference() // if not already in the response (it will be for Sage Pay Form). if (! array_key_exists('VendorTxCode', $reference)) { - $reference['VendorTxCode'] = $this->getRequest()->getTransactionId(); + $reference['VendorTxCode'] = $this->getTransactionId(); } ksort($reference); diff --git a/src/Message/ServerCompleteAuthorizeResponse.php b/src/Message/ServerCompleteAuthorizeResponse.php index 7fd89b2..2630ad5 100644 --- a/src/Message/ServerCompleteAuthorizeResponse.php +++ b/src/Message/ServerCompleteAuthorizeResponse.php @@ -20,7 +20,7 @@ public function getTransactionReference() { if (isset($this->data['TxAuthNo'])) { $reference = json_decode($this->getRequest()->getTransactionReference(), true); - $reference['VendorTxCode'] = $this->getRequest()->getTransactionId(); + $reference['VendorTxCode'] = $this->getTransactionId(); $reference['TxAuthNo'] = $this->data['TxAuthNo']; return json_encode($reference); diff --git a/src/Message/ServerNotifyRequest.php b/src/Message/ServerNotifyRequest.php index 6b207a3..443187c 100644 --- a/src/Message/ServerNotifyRequest.php +++ b/src/Message/ServerNotifyRequest.php @@ -214,4 +214,13 @@ public function sendResponse($status, $nextUrl, $detail = null) exit; } } + + /** + * Overrides the Form/Server/Direct method since there is no + * getRequest() to inspect in a notification. + */ + public function getTransactionId() + { + return $this->getDataItem('VendorTxCode'); + } } diff --git a/src/Traits/ResponseFieldsTrait.php b/src/Traits/ResponseFieldsTrait.php index 19a8b6c..29ec068 100644 --- a/src/Traits/ResponseFieldsTrait.php +++ b/src/Traits/ResponseFieldsTrait.php @@ -254,4 +254,16 @@ public function getExpiryYear() return (int)$dateTime->format('Y'); } } + + /** + * The transaction ID will be returned in the data for the Form API, or + * we will have to refer to the request for the Server and Direct APIs. + * + * @return @inherit + */ + public function getTransactionId() + { + return $this->getDataItem('VendorTxCode') + ?: $this->getRequest()->getTransactionId(); + } } diff --git a/src/Traits/ServerNotifyTrait.php b/src/Traits/ServerNotifyTrait.php index 828d01b..0d54111 100644 --- a/src/Traits/ServerNotifyTrait.php +++ b/src/Traits/ServerNotifyTrait.php @@ -150,15 +150,6 @@ public function getVPSTxId() return $this->getDataItem('VPSTxId'); } - /** - * The VendorTxCode is POSTed - we will need this for looking up the transaction - * locally. - */ - public function getTransactionId() - { - return $this->getDataItem('VendorTxCode'); - } - /** * Gateway Reference. * @@ -188,7 +179,7 @@ public function getTransactionReference() $reference['SecurityKey'] = $this->getSecurityKey(); - $reference['VendorTxCode'] = $this->getDataItem('VendorTxCode'); + $reference['VendorTxCode'] = $this->getTransactionId(); ksort($reference); diff --git a/tests/Message/ServerCompleteAuthorizeResponseTest.php b/tests/Message/ServerCompleteAuthorizeResponseTest.php index 7196ba0..1bb23ab 100644 --- a/tests/Message/ServerCompleteAuthorizeResponseTest.php +++ b/tests/Message/ServerCompleteAuthorizeResponseTest.php @@ -28,9 +28,12 @@ public function testServerCompleteAuthorizeResponseSuccess() 'DeclineCode' => '00', 'ExpiryDate' => '0722', 'BankAuthCode' => '999777', + //'VendorTxCode' => '123', <-- Not in response ) ); + // The transaction ID is set in the original request only. + $this->getMockRequest()->shouldReceive('getTransactionId')->once()->andReturn('123'); $this->getMockRequest()->shouldReceive('getTransactionReference')->once()->andReturn('{"SecurityKey":"JEUPDN1N7E","TxAuthNo":"4255","VPSTxId":"{F955C22E-F67B-4DA3-8EA3-6DAC68FA59D2}","VendorTxCode":"438791"}'); @@ -38,6 +41,36 @@ public function testServerCompleteAuthorizeResponseSuccess() $this->assertFalse($response->isRedirect()); $this->assertSame('{"SecurityKey":"JEUPDN1N7E","TxAuthNo":"b","VPSTxId":"{F955C22E-F67B-4DA3-8EA3-6DAC68FA59D2}","VendorTxCode":"123"}', $response->getTransactionReference()); $this->assertNull($response->getMessage()); + + //$this->assertSame('123', $response->getTransactionId()); + } + + public function testFormCompleteAuthorizeResponseSuccess() + { + $response = new ServerCompleteAuthorizeResponse( + $this->getMockRequest(), + array( + 'Status' => 'OK', + 'TxAuthNo' => 'b', + 'AVSCV2' => 'c', + 'AddressResult' => 'd', + 'PostCodeResult' => 'e', + 'CV2Result' => 'f', + 'GiftAid' => 'g', + '3DSecureStatus' => 'h', + 'CAVV' => 'i', + 'AddressStatus' => 'j', + 'PayerStatus' => 'k', + 'CardType' => 'l', + 'Last4Digits' => 'm', + 'DeclineCode' => '00', + 'ExpiryDate' => '0722', + 'BankAuthCode' => '999777', + 'VendorTxCode' => '123', // In response + ) + ); + + $this->assertSame('123', $response->getTransactionId()); } public function testServerCompleteAuthorizeResponseFailure()