Skip to content

Commit 9fc5c5b

Browse files
committed
Issue #19 extend test to include additional signature fields in callback.
1 parent a4614d1 commit 9fc5c5b

File tree

3 files changed

+40
-7
lines changed

3 files changed

+40
-7
lines changed

src/Message/ServerCompleteAuthorizeRequest.php

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,25 @@
99
*/
1010
class ServerCompleteAuthorizeRequest extends AbstractRequest
1111
{
12-
public function getData()
12+
/**
13+
* Get the signature calculated from the three pieces of saved local
14+
* information:
15+
* * VendorTxCode - merchant site ID (aka transactionId).
16+
* * VPSTxId - SagePay ID (aka transactionReference)
17+
* * SecurityKey - SagePay one-use token.
18+
* and the POSTed transaction results.
19+
* Note that the three items above are passed in as a single JSON structure
20+
* as the transactionReference. Would be nice if that were just the fallback,
21+
* if not passed in as three separate items to the relevant fields.
22+
*/
23+
public function getSignature()
1324
{
1425
$this->validate('transactionId', 'transactionReference');
1526

1627
$reference = json_decode($this->getTransactionReference(), true);
1728

18-
// validate VPSSignature
19-
$signature = md5(
29+
// Re-create the VPSSignature
30+
$signature_string =
2031
$reference['VPSTxId'].
2132
$reference['VendorTxCode'].
2233
$this->httpRequest->request->get('Status').
@@ -40,8 +51,17 @@ public function getData()
4051
$this->httpRequest->request->get('DeclineCode', '').
4152
$this->httpRequest->request->get('ExpiryDate', '').
4253
$this->httpRequest->request->get('FraudResponse', '').
43-
$this->httpRequest->request->get('BankAuthCode', '')
44-
);
54+
$this->httpRequest->request->get('BankAuthCode', '');
55+
56+
return md5($signature_string);
57+
}
58+
59+
/**
60+
* Get the POSTed data, checking that the signature is valid.
61+
*/
62+
public function getData()
63+
{
64+
$signature = $this->getSignature();
4565

4666
if (strtolower($this->httpRequest->request->get('VPSSignature')) !== $signature) {
4767
throw new InvalidResponseException;

tests/Message/ServerCompleteAuthorizeResponseTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ public function testServerCompleteAuthorizeResponseSuccess()
2525
'PayerStatus' => 'k',
2626
'CardType' => 'l',
2727
'Last4Digits' => 'm',
28+
'DeclineCode' => '00',
29+
'ExpiryDate' => '0722',
30+
'BankAuthCode' => '999777',
2831
)
2932
);
3033

tests/ServerGatewayTest.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,14 +76,24 @@ public function testCompleteAuthorizeSuccess()
7676
'PayerStatus' => 'k',
7777
'CardType' => 'l',
7878
'Last4Digits' => 'm',
79-
'VPSSignature' => md5('{F955C22E-F67B-4DA3-8EA3-6DAC68FA59D2}438791OKbexamplecJEUPDN1N7Edefghijklm'),
79+
// New fields for protocol v3.00
80+
'DeclineCode' => '00',
81+
'ExpiryDate' => '0722',
82+
'BankAuthCode' => '999777',
83+
'VPSSignature' => md5(
84+
'{F955C22E-F67B-4DA3-8EA3-6DAC68FA59D2}'
85+
. '438791' . 'OK' . 'bexamplecJEUPDN1N7Edefghijklm' . '00' . '0722' . '999777'
86+
),
8087
)
8188
);
8289

8390
$response = $this->gateway->completeAuthorize($this->completePurchaseOptions)->send();
8491

8592
$this->assertTrue($response->isSuccessful());
86-
$this->assertSame('{"SecurityKey":"JEUPDN1N7E","TxAuthNo":"b","VPSTxId":"{F955C22E-F67B-4DA3-8EA3-6DAC68FA59D2}","VendorTxCode":"123"}', $response->getTransactionReference());
93+
$this->assertSame(
94+
'{"SecurityKey":"JEUPDN1N7E","TxAuthNo":"b","VPSTxId":"{F955C22E-F67B-4DA3-8EA3-6DAC68FA59D2}","VendorTxCode":"123"}',
95+
$response->getTransactionReference()
96+
);
8797
$this->assertNull($response->getMessage());
8898
}
8999

0 commit comments

Comments
 (0)