99 */
1010class 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 ' ).
@@ -33,8 +44,24 @@ public function getData()
3344 $ this ->httpRequest ->request ->get ('AddressStatus ' ).
3445 $ this ->httpRequest ->request ->get ('PayerStatus ' ).
3546 $ this ->httpRequest ->request ->get ('CardType ' ).
36- $ this ->httpRequest ->request ->get ('Last4Digits ' )
37- );
47+ $ this ->httpRequest ->request ->get ('Last4Digits ' ).
48+ // New for protocol v3.00
49+ // Described in the docs as "mandatory" but not supplied when PayPal is used,
50+ // so provide the defaults.
51+ $ this ->httpRequest ->request ->get ('DeclineCode ' , '' ).
52+ $ this ->httpRequest ->request ->get ('ExpiryDate ' , '' ).
53+ $ this ->httpRequest ->request ->get ('FraudResponse ' , '' ).
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 ();
3865
3966 if (strtolower ($ this ->httpRequest ->request ->get ('VPSSignature ' )) !== $ signature ) {
4067 throw new InvalidResponseException ;
0 commit comments