Skip to content

Commit 40beb16

Browse files
committed
Response::getTransactionReference() should always return value even if TxAuthNo is not present
1 parent 8a17c8f commit 40beb16

File tree

5 files changed

+40
-29
lines changed

5 files changed

+40
-29
lines changed

src/Omnipay/SagePay/Message/Response.php

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,16 +40,18 @@ public function isRedirect()
4040
*/
4141
public function getTransactionReference()
4242
{
43-
if (isset($this->data['SecurityKey']) && isset($this->data['TxAuthNo']) && isset($this->data['VPSTxId'])) {
44-
return json_encode(
45-
array(
46-
'SecurityKey' => $this->data['SecurityKey'],
47-
'TxAuthNo' => $this->data['TxAuthNo'],
48-
'VPSTxId' => $this->data['VPSTxId'],
49-
'VendorTxCode' => $this->getRequest()->getTransactionId(),
50-
)
51-
);
43+
$reference = array();
44+
$reference['VendorTxCode'] = $this->getRequest()->getTransactionId();
45+
46+
foreach (array('SecurityKey', 'TxAuthNo', 'VPSTxId') as $key) {
47+
if (isset($this->data[$key])) {
48+
$reference[$key] = $this->data[$key];
49+
}
5250
}
51+
52+
ksort($reference);
53+
54+
return json_encode($reference);
5355
}
5456

5557
public function getMessage()

tests/Omnipay/SagePay/DirectGatewayTest.php

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ public function setUp()
2121

2222
$this->captureOptions = array(
2323
'amount' => '10.00',
24+
'transactionId' => '123',
2425
'transactionReference' => '{"SecurityKey":"JEUPDN1N7E","TxAuthNo":"4255","VPSTxId":"{F955C22E-F67B-4DA3-8EA3-6DAC68FA59D2}","VendorTxCode":"438791"}',
2526
);
2627
}
@@ -45,7 +46,7 @@ public function testAuthorizeFailure()
4546

4647
$this->assertFalse($response->isSuccessful());
4748
$this->assertFalse($response->isRedirect());
48-
$this->assertNull($response->getTransactionReference());
49+
$this->assertSame('{"VendorTxCode":"123"}', $response->getTransactionReference());
4950
$this->assertSame('The VendorTxCode \'984297\' has been used before. Each transaction you send should have a unique VendorTxCode.', $response->getMessage());
5051
}
5152

@@ -57,7 +58,7 @@ public function testAuthorize3dSecure()
5758

5859
$this->assertFalse($response->isSuccessful());
5960
$this->assertTrue($response->isRedirect());
60-
$this->assertNull($response->getTransactionReference());
61+
$this->assertSame('{"VendorTxCode":"123"}', $response->getTransactionReference());
6162
$this->assertNull($response->getMessage());
6263
$this->assertSame('https://test.sagepay.com/Simulator/3DAuthPage.asp', $response->getRedirectUrl());
6364

@@ -87,7 +88,7 @@ public function testPurchaseFailure()
8788

8889
$this->assertFalse($response->isSuccessful());
8990
$this->assertFalse($response->isRedirect());
90-
$this->assertNull($response->getTransactionReference());
91+
$this->assertSame('{"VendorTxCode":"123"}', $response->getTransactionReference());
9192
$this->assertSame('The VendorTxCode \'984297\' has been used before. Each transaction you send should have a unique VendorTxCode.', $response->getMessage());
9293
}
9394

@@ -99,7 +100,7 @@ public function testPurchase3dSecure()
99100

100101
$this->assertFalse($response->isSuccessful());
101102
$this->assertTrue($response->isRedirect());
102-
$this->assertNull($response->getTransactionReference());
103+
$this->assertSame('{"VendorTxCode":"123"}', $response->getTransactionReference());
103104
$this->assertNull($response->getMessage());
104105
$this->assertSame('https://test.sagepay.com/Simulator/3DAuthPage.asp', $response->getRedirectUrl());
105106

@@ -116,7 +117,7 @@ public function testCaptureSuccess()
116117
$response = $this->gateway->capture($this->captureOptions)->send();
117118

118119
$this->assertTrue($response->isSuccessful());
119-
$this->assertNull($response->getTransactionReference());
120+
$this->assertSame('{"VendorTxCode":"123"}', $response->getTransactionReference());
120121
$this->assertSame('The transaction was RELEASEed successfully.', $response->getMessage());
121122
}
122123

@@ -127,7 +128,7 @@ public function testCaptureFailure()
127128
$response = $this->gateway->capture($this->captureOptions)->send();
128129

129130
$this->assertFalse($response->isSuccessful());
130-
$this->assertNull($response->getTransactionReference());
131+
$this->assertSame('{"VendorTxCode":"123"}', $response->getTransactionReference());
131132
$this->assertSame('You are trying to RELEASE a transaction that has already been RELEASEd or ABORTed.', $response->getMessage());
132133
}
133134

@@ -138,7 +139,7 @@ public function testRefundSuccess()
138139
$response = $this->gateway->refund($this->captureOptions)->send();
139140

140141
$this->assertTrue($response->isSuccessful());
141-
$this->assertNull($response->getTransactionReference());
142+
$this->assertSame('{"VendorTxCode":"123"}', $response->getTransactionReference());
142143
$this->assertSame('The transaction was RELEASEed successfully.', $response->getMessage());
143144
}
144145

@@ -149,7 +150,7 @@ public function testRefundFailure()
149150
$response = $this->gateway->refund($this->captureOptions)->send();
150151

151152
$this->assertFalse($response->isSuccessful());
152-
$this->assertNull($response->getTransactionReference());
153+
$this->assertSame('{"VendorTxCode":"123"}', $response->getTransactionReference());
153154
$this->assertSame('You are trying to RELEASE a transaction that has already been RELEASEd or ABORTed.', $response->getMessage());
154155
}
155156
}

tests/Omnipay/SagePay/Message/ResponseTest.php

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,16 @@
66

77
class ResponseTest extends TestCase
88
{
9+
public function setUp()
10+
{
11+
$this->getMockRequest()->shouldReceive('getTransactionId')->andReturn('123456');
12+
}
13+
914
public function testDirectPurchaseSuccess()
1015
{
1116
$httpResponse = $this->getMockHttpResponse('DirectPurchaseSuccess.txt');
1217
$response = new Response($this->getMockRequest(), $httpResponse->getBody());
1318

14-
$this->getMockRequest()->shouldReceive('getTransactionId')->once()->andReturn('123456');
15-
1619
$this->assertTrue($response->isSuccessful());
1720
$this->assertFalse($response->isRedirect());
1821
$this->assertSame('{"SecurityKey":"OUWLNYQTVT","TxAuthNo":"9962","VPSTxId":"{5A1BC414-5409-48DD-9B8B-DCDF096CE0BE}","VendorTxCode":"123456"}', $response->getTransactionReference());
@@ -26,7 +29,7 @@ public function testDirectPurchaseFailure()
2629

2730
$this->assertFalse($response->isSuccessful());
2831
$this->assertFalse($response->isRedirect());
29-
$this->assertNull($response->getTransactionReference());
32+
$this->assertSame('{"VendorTxCode":"123456"}', $response->getTransactionReference());
3033
$this->assertSame('The VendorTxCode \'984297\' has been used before. Each transaction you send should have a unique VendorTxCode.', $response->getMessage());
3134
}
3235

@@ -39,7 +42,7 @@ public function testDirectPurchase3dSecure()
3942

4043
$this->assertFalse($response->isSuccessful());
4144
$this->assertTrue($response->isRedirect());
42-
$this->assertNull($response->getTransactionReference());
45+
$this->assertSame('{"VendorTxCode":"123456"}', $response->getTransactionReference());
4346
$this->assertNull($response->getMessage());
4447
$this->assertSame('https://test.sagepay.com/Simulator/3DAuthPage.asp', $response->getRedirectUrl());
4548

@@ -55,7 +58,7 @@ public function testCaptureSuccess()
5558
$response = new Response($this->getMockRequest(), $httpResponse->getBody());
5659

5760
$this->assertTrue($response->isSuccessful());
58-
$this->assertNull($response->getTransactionReference());
61+
$this->assertSame('{"VendorTxCode":"123456"}', $response->getTransactionReference());
5962
$this->assertSame('The transaction was RELEASEed successfully.', $response->getMessage());
6063
}
6164

@@ -65,7 +68,7 @@ public function testCaptureFailure()
6568
$response = new Response($this->getMockRequest(), $httpResponse->getBody());
6669

6770
$this->assertFalse($response->isSuccessful());
68-
$this->assertNull($response->getTransactionReference());
71+
$this->assertSame('{"VendorTxCode":"123456"}', $response->getTransactionReference());
6972
$this->assertSame('You are trying to RELEASE a transaction that has already been RELEASEd or ABORTed.', $response->getMessage());
7073
}
7174
}

tests/Omnipay/SagePay/Message/ServerAuthorizeResponseTest.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,19 @@
66

77
class ServerAuthorizeResponseTest extends TestCase
88
{
9+
public function setUp()
10+
{
11+
$this->getMockRequest()->shouldReceive('getTransactionId')->andReturn('123456');
12+
}
13+
914
public function testServerPurchaseSuccess()
1015
{
1116
$httpResponse = $this->getMockHttpResponse('ServerPurchaseSuccess.txt');
1217
$response = new ServerAuthorizeResponse($this->getMockRequest(), $httpResponse->getBody());
1318

1419
$this->assertFalse($response->isSuccessful());
1520
$this->assertTrue($response->isRedirect());
16-
$this->assertNull($response->getTransactionReference());
21+
$this->assertSame('{"SecurityKey":"IK776BWNHN","VPSTxId":"{1E7D9C70-DBE2-4726-88EA-D369810D801D}","VendorTxCode":"123456"}', $response->getTransactionReference());
1722
$this->assertSame('Server transaction registered successfully.', $response->getMessage());
1823
$this->assertSame('https://test.sagepay.com/Simulator/VSPServerPaymentPage.asp?TransactionID={1E7D9C70-DBE2-4726-88EA-D369810D801D}', $response->getRedirectUrl());
1924
}
@@ -25,7 +30,7 @@ public function testServerPurchaseFailure()
2530

2631
$this->assertFalse($response->isSuccessful());
2732
$this->assertFalse($response->isRedirect());
28-
$this->assertNull($response->getTransactionReference());
33+
$this->assertSame('{"VendorTxCode":"123456"}', $response->getTransactionReference());
2934
$this->assertSame('The Description field should be between 1 and 100 characters long.', $response->getMessage());
3035
}
3136
}

tests/Omnipay/SagePay/ServerGatewayTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public function testAuthorizeSuccess()
4040

4141
$this->assertFalse($response->isSuccessful());
4242
$this->assertTrue($response->isRedirect());
43-
$this->assertNull($response->getTransactionReference());
43+
$this->assertSame('{"SecurityKey":"IK776BWNHN","VPSTxId":"{1E7D9C70-DBE2-4726-88EA-D369810D801D}","VendorTxCode":"123"}', $response->getTransactionReference());
4444
$this->assertSame('Server transaction registered successfully.', $response->getMessage());
4545
$this->assertSame('https://test.sagepay.com/Simulator/VSPServerPaymentPage.asp?TransactionID={1E7D9C70-DBE2-4726-88EA-D369810D801D}', $response->getRedirectUrl());
4646
}
@@ -53,7 +53,7 @@ public function testAuthorizeFailure()
5353

5454
$this->assertFalse($response->isSuccessful());
5555
$this->assertFalse($response->isRedirect());
56-
$this->assertNull($response->getTransactionReference());
56+
$this->assertSame('{"VendorTxCode":"123"}', $response->getTransactionReference());
5757
$this->assertSame('The Description field should be between 1 and 100 characters long.', $response->getMessage());
5858
}
5959

@@ -101,7 +101,7 @@ public function testPurchaseSuccess()
101101

102102
$this->assertFalse($response->isSuccessful());
103103
$this->assertTrue($response->isRedirect());
104-
$this->assertNull($response->getTransactionReference());
104+
$this->assertSame('{"SecurityKey":"IK776BWNHN","VPSTxId":"{1E7D9C70-DBE2-4726-88EA-D369810D801D}","VendorTxCode":"123"}', $response->getTransactionReference());
105105
$this->assertSame('Server transaction registered successfully.', $response->getMessage());
106106
$this->assertSame('https://test.sagepay.com/Simulator/VSPServerPaymentPage.asp?TransactionID={1E7D9C70-DBE2-4726-88EA-D369810D801D}', $response->getRedirectUrl());
107107
}
@@ -114,7 +114,7 @@ public function testPurchaseFailure()
114114

115115
$this->assertFalse($response->isSuccessful());
116116
$this->assertFalse($response->isRedirect());
117-
$this->assertNull($response->getTransactionReference());
117+
$this->assertSame('{"VendorTxCode":"123"}', $response->getTransactionReference());
118118
$this->assertSame('The Description field should be between 1 and 100 characters long.', $response->getMessage());
119119
}
120120

0 commit comments

Comments
 (0)