Skip to content

Commit 4ff0114

Browse files
authored
Merge pull request #121 from academe/master
Fix for issue #120
2 parents c36ea1e + 539b3e8 commit 4ff0114

File tree

6 files changed

+57
-12
lines changed

6 files changed

+57
-12
lines changed

src/Message/Response.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public function getTransactionReference()
6161
// if not already in the response (it will be for Sage Pay Form).
6262

6363
if (! array_key_exists('VendorTxCode', $reference)) {
64-
$reference['VendorTxCode'] = $this->getRequest()->getTransactionId();
64+
$reference['VendorTxCode'] = $this->getTransactionId();
6565
}
6666

6767
ksort($reference);

src/Message/ServerCompleteAuthorizeResponse.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public function getTransactionReference()
2020
{
2121
if (isset($this->data['TxAuthNo'])) {
2222
$reference = json_decode($this->getRequest()->getTransactionReference(), true);
23-
$reference['VendorTxCode'] = $this->getRequest()->getTransactionId();
23+
$reference['VendorTxCode'] = $this->getTransactionId();
2424
$reference['TxAuthNo'] = $this->data['TxAuthNo'];
2525

2626
return json_encode($reference);

src/Message/ServerNotifyRequest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,4 +214,13 @@ public function sendResponse($status, $nextUrl, $detail = null)
214214
exit;
215215
}
216216
}
217+
218+
/**
219+
* Overrides the Form/Server/Direct method since there is no
220+
* getRequest() to inspect in a notification.
221+
*/
222+
public function getTransactionId()
223+
{
224+
return $this->getDataItem('VendorTxCode');
225+
}
217226
}

src/Traits/ResponseFieldsTrait.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,4 +254,16 @@ public function getExpiryYear()
254254
return (int)$dateTime->format('Y');
255255
}
256256
}
257+
258+
/**
259+
* The transaction ID will be returned in the data for the Form API, or
260+
* we will have to refer to the request for the Server and Direct APIs.
261+
*
262+
* @return @inherit
263+
*/
264+
public function getTransactionId()
265+
{
266+
return $this->getDataItem('VendorTxCode')
267+
?: $this->getRequest()->getTransactionId();
268+
}
257269
}

src/Traits/ServerNotifyTrait.php

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -150,15 +150,6 @@ public function getVPSTxId()
150150
return $this->getDataItem('VPSTxId');
151151
}
152152

153-
/**
154-
* The VendorTxCode is POSTed - we will need this for looking up the transaction
155-
* locally.
156-
*/
157-
public function getTransactionId()
158-
{
159-
return $this->getDataItem('VendorTxCode');
160-
}
161-
162153
/**
163154
* Gateway Reference.
164155
*
@@ -188,7 +179,7 @@ public function getTransactionReference()
188179

189180
$reference['SecurityKey'] = $this->getSecurityKey();
190181

191-
$reference['VendorTxCode'] = $this->getDataItem('VendorTxCode');
182+
$reference['VendorTxCode'] = $this->getTransactionId();
192183

193184
ksort($reference);
194185

tests/Message/ServerCompleteAuthorizeResponseTest.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,49 @@ public function testServerCompleteAuthorizeResponseSuccess()
2828
'DeclineCode' => '00',
2929
'ExpiryDate' => '0722',
3030
'BankAuthCode' => '999777',
31+
//'VendorTxCode' => '123', <-- Not in response
3132
)
3233
);
3334

35+
// The transaction ID is set in the original request only.
36+
3437
$this->getMockRequest()->shouldReceive('getTransactionId')->once()->andReturn('123');
3538
$this->getMockRequest()->shouldReceive('getTransactionReference')->once()->andReturn('{"SecurityKey":"JEUPDN1N7E","TxAuthNo":"4255","VPSTxId":"{F955C22E-F67B-4DA3-8EA3-6DAC68FA59D2}","VendorTxCode":"438791"}');
3639

3740
$this->assertTrue($response->isSuccessful());
3841
$this->assertFalse($response->isRedirect());
3942
$this->assertSame('{"SecurityKey":"JEUPDN1N7E","TxAuthNo":"b","VPSTxId":"{F955C22E-F67B-4DA3-8EA3-6DAC68FA59D2}","VendorTxCode":"123"}', $response->getTransactionReference());
4043
$this->assertNull($response->getMessage());
44+
45+
//$this->assertSame('123', $response->getTransactionId());
46+
}
47+
48+
public function testFormCompleteAuthorizeResponseSuccess()
49+
{
50+
$response = new ServerCompleteAuthorizeResponse(
51+
$this->getMockRequest(),
52+
array(
53+
'Status' => 'OK',
54+
'TxAuthNo' => 'b',
55+
'AVSCV2' => 'c',
56+
'AddressResult' => 'd',
57+
'PostCodeResult' => 'e',
58+
'CV2Result' => 'f',
59+
'GiftAid' => 'g',
60+
'3DSecureStatus' => 'h',
61+
'CAVV' => 'i',
62+
'AddressStatus' => 'j',
63+
'PayerStatus' => 'k',
64+
'CardType' => 'l',
65+
'Last4Digits' => 'm',
66+
'DeclineCode' => '00',
67+
'ExpiryDate' => '0722',
68+
'BankAuthCode' => '999777',
69+
'VendorTxCode' => '123', // In response
70+
)
71+
);
72+
73+
$this->assertSame('123', $response->getTransactionId());
4174
}
4275

4376
public function testServerCompleteAuthorizeResponseFailure()

0 commit comments

Comments
 (0)