forked from plationline/po-php
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathauth_response.php
executable file
·292 lines (247 loc) · 11.9 KB
/
auth_response.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
<?php
header('Content-Type: text/html; charset=utf-8');
echo '<h1>Transaction response page</h1>';
require_once("PlatiOnline/PO5.php");
use PlatiOnline\PO5 as PO5;
$po = new PO5();
// RSA Private ITSN [Merchant side]:
$po->setRSAKeyDecrypt('RSA Private ITSN [Merchant side]');
//IV ITSN:
$po->setIVITSN('IV ITSN');
// POST response for PTOR, POST_S2S_PO_PAGE, POST_S2S_MT_PAGE of f_relay_method
// PTOR is recommended, a redirect from PO server to response page from merchant website is performed
// POST_S2S_PO_PAGE - POST response Server2Server, PlatiOnline template
// POST_S2S_MT_PAGE - POST response Server2Server, merchant template
// SOAP_PO_PAGE - SOAP response, PlatiOnline template
// SOAP_MT_PAGE - SOAP response, merchant template
$authorization_response = $po->auth_response($_POST['F_Relay_Message'], $_POST['F_Crypt_Message']);
//the other POST fields are the fields sent by the merchant in $f_request['merchants_fields'] field, plain text
/**************************************************************************************************
**************************************************************************************************
*** ***
*** $authorization_response looks like this: ***
*** array(1) { ***
*** ["PO_AUTH_RESPONSE"]=> ***
*** array(14) { ***
*** ["F_LOGIN"] => string(15) "PO WWW.DEMO.RO" ***
*** ["F_WEBSITE"] => string(0) "WWW.DEMO.RO" ***
*** ["F_TEST_REQUEST"] => string(1) "1" ***
*** ["F_TIMESTAMP"] => string(38) "Fri , 14 Mar 2014 15:10:56 +0300 (GMT)" ***
*** ["F_ORDER_NUMBER"] => string(12) "Order 1 test" ***
*** ["F_ACTION"] => string(1) "2" ***
*** ["F_AMOUNT"] => string(5) "11.99" ***
*** ["F_CURRENCY"] => string(3) "RON" ***
*** ["X_RESPONSE_CODE"] => string(1) "2" ***
*** ["X_RESPONSE_REASON_CODE"] => string(5) "60036" ***
*** ["X_RESPONSE_REASON_TEXT"] => string(11) "Autorizată" ***
*** ["X_AUTH_CODE"] => string(6) "POTEST" ***
*** ["X_ACTION_CODE"] => string(2) "NA" ***
*** ["X_TRANS_ID"] => string(7) "1175053" ***
*** } ***
*** } ***
*** ***
**************************************************************************************************
**************************************************************************************************/
$X_RESPONSE_CODE = $po->get_xml_tag_content($authorization_response, 'X_RESPONSE_CODE');
// ---------------------------------------------------------------------------------------------------------------------------//
/////////////////////////////////////////
// //
// raspuns metoda PTOR //
// //
/////////////////////////////////////////
switch ($X_RESPONSE_CODE) {
case '2':
// authorized
echo '<h2>The transaction was authorized!</h2>';
// please update the order status in your system
break;
case '13':
// on hold
echo '<h2>The transaction is on hold, additional checking is needed!</h2>';
// please update the order status in your system
break;
case '8':
// declined
echo '<h2>The transaction was declined! Reason: ' . $po->get_xml_tag_content($authorization_response, 'X_RESPONSE_REASON_TEXT') . '</h2>';
// please update the order status in your system
break;
case '10';
// error
echo '<h2>An error was encountered in authorization process</h2>';
// please update the order status in your system
break;
}
// ---------------------------------------------------------------------------------------------------------------------------//
/////////////////////////////////////////
// //
// raspuns metoda POST_S2S_PO_PAGE //
// //
/////////////////////////////////////////
/*
$raspuns_procesat = true;
switch($X_RESPONSE_CODE) {
case '2':
// authorized
// please update the order status in your system
break;
case '13':
// on hold
// please update the order status in your system
break;
case '8':
// declined
// please update the order status in your system
break;
case '10';
// error
// please update the order status in your system
break;
default:
$raspuns_procesat = false;
}
// this works for f_relay_handshake = 1 in authorization request. I want HANDSHAKE between merchant server and PO server for POST_S2S_PO_PAGE
// if the response was processed, I send TRUE to PO server for PO_Transaction_Response_Processing
// if the response was not processed and I want the PO server to resend the transaction status, I send RETRY to PO server for PO_Transaction_Response_Processing
header('User-Agent:Mozilla/5.0 (Plati Online Relay Response Service)');
if ($raspuns_procesat) {
header('PO_Transaction_Response_Processing: true');
}
else {
header('PO_Transaction_Response_Processing: retry');
}
*/
// ---------------------------------------------------------------------------------------------------------------------------//
/////////////////////////////////////////
// //
// raspuns metoda POST_S2S_MT_PAGE //
// //
/////////////////////////////////////////
/*
$raspuns_procesat = true;
switch($X_RESPONSE_CODE) {
case '2':
// authorized
echo '<h2>The transaction was authorized!</h2>';
// please update the order status in your system
break;
case '13':
// on hold
echo '<h2>The transaction is on hold, additional checking is needed!</h2>';
// please update the order status in your system
break;
case '8':
// declined
echo '<h2>The transaction was declined! Reason: '.$po->get_xml_tag_content($authorization_response,'X_RESPONSE_REASON_TEXT').'</h2>';
// please update the order status in your system
break;
case '10';
// error
echo '<h2>An error was encountered in authorization process</h2>';
// please update the order status in your system
break;
default:
$raspuns_procesat = false;
}
// instead of sending a <h2> tag using echo, you can send an HTML code, based on X_RESPONSE_CODE
// this works for f_relay_handshake = 1 in authorization request. I want HANDSHAKE between merchant server and PO server for POST_S2S_MT_PAGE
// if the response was processed, I send TRUE to PO server for PO_Transaction_Response_Processing
// if the response was not processed and I want the PO server to resend the transaction status, I send RETRY to PO server for PO_Transaction_Response_Processing
header('User-Agent:Mozilla/5.0 (Plati Online Relay Response Service)');
if ($raspuns_procesat) {
header('PO_Transaction_Response_Processing: true');
}
else {
header('PO_Transaction_Response_Processing: retry');
}
*/
// ---------------------------------------------------------------------------------------------------------------------------//
/////////////////////////////////////////
// //
// raspuns metoda SOAP_PO_PAGE //
// //
/////////////////////////////////////////
/*
$soap_xml = file_get_contents("php://input");
$soap_parsed = $po->parse_soap_response($soap_xml);
$authorization_response = $po->auth_response($soap_parsed['PO_RELAY_REPONSE']['F_RELAY_MESSAGE'], $soap_parsed['PO_RELAY_REPONSE']['F_CRYPT_MESSAGE']);
$X_RESPONSE_CODE = $authorization_response['PO_AUTH_RESPONSE']['X_RESPONSE_CODE'];
$raspuns_procesat = true;
switch($X_RESPONSE_CODE) {
case '2':
// authorized
// please update the order status in your system
break;
case '13':
// on hold
// please update the order status in your system
break;
case '8':
// declined
// please update the order status in your system
break;
case '10';
// error
// please update the order status in your system
break;
default:
$raspuns_procesat = false;
}
// this works for f_relay_handshake = 1 in authorization request. I want HANDSHAKE between merchant server and PO server for SOAP_PO_PAGE
// if the response was processed, I send TRUE to PO server for PO_Transaction_Response_Processing
// if the response was not processed and I want the PO server to resend the transaction status, I send RETRY to PO server for PO_Transaction_Response_Processing
header('User-Agent:Mozilla/5.0 (Plati Online Relay Response Service)');
if ($raspuns_procesat) {
header('PO_Transaction_Response_Processing: true');
}
else {
header('PO_Transaction_Response_Processing: retry');
}
*/
// ---------------------------------------------------------------------------------------------------------------------------//
/////////////////////////////////////////
// //
// raspuns metoda SOAP_MT_PAGE //
// //
/////////////////////////////////////////
/*
$soap_xml = file_get_contents("php://input");
$soap_parsed = $po->parse_soap_response($soap_xml);
$authorization_response = $po->auth_response($soap_parsed['PO_RELAY_REPONSE']['F_RELAY_MESSAGE'], $soap_parsed['PO_RELAY_REPONSE']['F_CRYPT_MESSAGE']);
$X_RESPONSE_CODE = $authorization_response['PO_AUTH_RESPONSE']['X_RESPONSE_CODE'];
$raspuns_procesat = true;
switch($X_RESPONSE_CODE) {
case '2':
// authorized
echo '<h2>The transaction was authorized!</h2>';
// please update the order status in your system
break;
case '13':
// on hold
echo '<h2>The transaction is on hold, additional checking is needed!</h2>';
// please update the order status in your system
break;
case '8':
// declined
echo '<h2>The transaction was declined! Reason: '.$po->get_xml_tag_content($authorization_response,'X_RESPONSE_REASON_TEXT').'</h2>';
// please update the order status in your system
break;
case '10';
// error
echo '<h2>An error was encountered in authorization process</h2>';
// please update the order status in your system
break;
default:
$raspuns_procesat = false;
}
// instead of sending a <h2> tag using echo, you can send an HTML code, based on X_RESPONSE_CODE
// this works for f_relay_handshake = 1 in authorization request. I want HANDSHAKE between merchant server and PO server for POST_S2S_MT_PAGE
// if the response was processed, I send TRUE to PO server for PO_Transaction_Response_Processing
// if the response was not processed and I want the PO server to resend the transaction status, I send RETRY to PO server for PO_Transaction_Response_Processing
header('User-Agent:Mozilla/5.0 (Plati Online Relay Response Service)');
if ($raspuns_procesat) {
header('PO_Transaction_Response_Processing: true');
}
else {
header('PO_Transaction_Response_Processing: retry');
}
*/