@@ -29,23 +29,91 @@ public function getTransactionReference()
29
29
/**
30
30
* Confirm (Sage Pay Server only)
31
31
*
32
+ * Notify Sage Pay you received the payment details and wish to confirm the payment, and
33
+ * provide a URL to forward the customer to.
34
+ *
35
+ * @param string URL to forward the customer to. Note this is different to your standard
36
+ * return controller action URL.
37
+ * @param string Optional human readable reasons for accepting the transaction.
38
+ */
39
+ public function confirm ($ nextUrl , $ detail = null )
40
+ {
41
+ $ this ->sendResponse ('OK ' , $ nextUrl , $ detail );
42
+ }
43
+
44
+ /**
45
+ * Error (Sage Pay Server only)
46
+ *
47
+ * Notify Sage Pay you received the payment details but there was an error and the payment
48
+ * cannot be completed. Error should be called rarely, and only when something unforseen
49
+ * has happened on your server or database.
50
+ *
51
+ * @param string URL to foward the customer to. Note this is different to your standard
52
+ * return controller action URL.
53
+ * @param string Optional human readable reasons for not accepting the transaction.
54
+ */
55
+ public function error ($ nextUrl , $ detail = null )
56
+ {
57
+ $ this ->sendResponse ('ERROR ' , $ nextUrl , $ detail );
58
+ }
59
+
60
+ /**
61
+ * Invalid (Sage Pay Server only)
62
+ *
63
+ * Notify Sage Pay you received the payment details but they were invalid and the payment
64
+ * cannot be completed. Invalid should be called if you are not happy with the contents
65
+ * of the POST, such as the MD5 hash signatures did not match or you do not wish to proceed
66
+ * with the order.
67
+ *
68
+ * @param string URL to foward the customer to. Note this is different to your standard
69
+ * return controller action URL.
70
+ * @param string Optional human readable reasons for not accepting the transaction.
71
+ */
72
+ public function invalid ($ nextUrl , $ detail = null )
73
+ {
74
+ $ this ->sendResponse ('INVALID ' , $ nextUrl , $ detail );
75
+ }
76
+
77
+ /**
78
+ * Respond to SagePay confirming or rejecting the payment.
79
+ *
32
80
* Sage Pay Server does things backwards compared to every other gateway (including Sage Pay
33
81
* Direct). The return URL is called by their server, and they expect you to confirm receipt
34
82
* and then pass a URL for them to forward the customer to.
35
83
*
36
84
* Because of this, an extra step is required. In your return controller, after calling
37
- * $gateway->completePurchase(), you should update your database with details of the
38
- * successful payment. You must then call $response->confirm () to notify Sage Pay you
39
- * received the payment details , and provide a URL to forward the customer to.
85
+ * $gateway->completePurchase(), you should attempt to process the payment. You must then call
86
+ * either $response->confirm(), $response->error() or $response->invalid () to notify Sage Pay
87
+ * whether to complete the payment or not , and provide a URL to forward the customer to.
40
88
*
41
89
* Keep in mind your original confirmPurchase() script is being called by Sage Pay, not
42
90
* the customer.
43
91
*
44
- * @param string URL to foward the customer to. Note this is different to your standard
92
+ * @param string The status to send to Sage Pay, either OK, INVALID or ERROR.
93
+ * @param string URL to forward the customer to. Note this is different to your standard
45
94
* return controller action URL.
95
+ * @param string Optional human readable reasons for accepting the transaction.
96
+ */
97
+ public function sendResponse ($ status , $ nextUrl , $ detail = null )
98
+ {
99
+ $ message = "Status= $ status \r\nRedirectUrl= $ nextUrl " ;
100
+
101
+ if (null !== $ detail ) {
102
+ $ message .= "\r\nStatusDetail= " .$ detail ;
103
+ }
104
+
105
+ $ this ->exitWith ($ message );
106
+ }
107
+
108
+ /**
109
+ * Exit to ensure no other HTML, headers, comments, or text are included.
110
+ *
111
+ * @access private
112
+ * @codeCoverageIgnore
46
113
*/
47
- public function confirm ( $ nextUrl )
114
+ public function exitWith ( $ message )
48
115
{
49
- exit ("Status=OK \r\nRedirectUrl= " .$ nextUrl );
116
+ echo $ message ;
117
+ exit ;
50
118
}
51
119
}
0 commit comments