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
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
|
<?php /** * Finnet Finpay * @author Garrick Lam */
class Finpay extends AbstractPaymentGateway { const SUCCESS = '00'; const INVALID_SIGNATURE = '01'; const UNPAID = '04'; const EXPIRED = '05'; const DATA_INCOMPLETE = '99';
public $key; public $isSandbox = false;
protected $payment_method = 'FINPAY'; protected $merchant_id; protected $password; protected $signaturekey; protected $invoice;
public $gateway_url;
private $bypassValidation = false;
protected $rest_merchantinfo_url = "http://116.90.162.170:10809/rest/merchant/merchantinfo";
public function __construct() { // Your Credentials provided by Finnet $this->merchant_id = MasterSetting::get('FINPAY_MERCHANT_ID'); $this->password = MasterSetting::get('FINPAY_PASSWORD'); // FINPAY_VAPERMATA_MERCHANT_ID // FINPAY_VAPERMATA_PASSWORD // FINPAY_TCASH_MERCHANT_ID // FINPAY_TCASH_PASSWORD // FINPAY_VA_MERCHANT_ID // FINPAY_VA_PASSWORD // FINPAY_CC_MERCHANT_ID // FINPAY_CC_PASSWORD
$this->gateway_url = $this->gateway_url_production; $this->payment_currency = "IDR"; // or USD }
public function sandbox() { $this->isSandbox = true; // $this->bypassValidation = true; $this->gateway_url = $this->gateway_url_sandbox; return $this; }
// public function setInvoice(Invoice $invoice) // { // $this->invoice = $invoice; // }
public function paymentParam($payment_method) { throw new Exception("Error Processing Request", 1); }
protected function generateCustomizedData($args) { return []; }
protected function generateSignature($args) { return []; }
public function paymentVerify($data, &$messages = array()) { // maybe move validate password, signature, invoice here }
// the string will have to be converted to UPPERCASE before hashing is done. protected function sign($arg) { return hash('sha256', strtoupper($arg) . $this->password); }
public function processNotification($request) { $apiLog = ApiLog::create([ 'type' => get_class($this), 'endpoint' => $_SERVER['REQUEST_URI'], 'request' => $request, 'desc_en' => json_encode($_SERVER, JSON_PRETTY_PRINT), ]);
switch ($request['trax_type']) { // payment code case '195Code': case 'vaCode': case '02111Code': $response = $this->processPaymentCode($request); break;
case 'Payment': // if payment_method = FinpayCode or FINPAYVA // Finpay Code normalize $finpayCode = new FinpayCode; if ($this->isSandbox) { $finpayCode->sandbox(); } // $response = $finpayCode->processPaymentNotification($request); switch ($request['result_code']) { case self::SUCCESS: $response = $finpayCode->processPaymentNotification($request); break;
case self::EXPIRED: $response = $finpayCode->processExpiredCodeNotification($request); break;
default: $response = "Unexpected Result Code: {$request['result_code']}"; break; } break;
default: // Finpay TCash if($request['payment_method'] == "FINPAY_TCASH") { $finpayTCash = new FinpayTCash; if ($this->isSandbox) { $finpayTCash->sandbox(); } $response = $finpayTCash->processPaymentNotification($request); break; }
// Finpay CreditCard if ($request['trx_type'] == "Pay") { $finpayCreditCard = new FinpayCreditCard; if ($this->isSandbox) { $finpayCreditCard->sandbox(); } $response = $finpayCreditCard->processPaymentNotification($request); break; }
$response = "Unexpected API: {$request['action']}"; // exit("Unexpected API: {$request['action']}"); break; }
$apiLog->fill([ 'response' => $response, 'desc_en' => json_encode($_SERVER, JSON_PRETTY_PRINT), ])->Save();
return $response; }
// important // 7.1. Merchant Request : merchant’s initiation to get Finnet’s payment code protected function merchantRequest($request) { $param = [ 'mer_signature', ];
$param = array_merge($param, $this->generateSignature($param));
$response = $this->_excute($endpoint, $param); $this->processPaymentCode($response); }
// 7.2. Response – payment code : response contains payment code to merchant’s return url protected function processPaymentCode($request) {
}
// important // 7.5. Merchant Request – check payment code status : merchants’ initiation to get the payment code’s information and status, whether it’s expired or has been paid. public function checkPaymentCodeStaus() {
$response = $this->processCheckPaymentCodeStaus($response); }
// 7.6. Response -check payment code status : notification response for check payment code that sent to merchant’s return URL public function processCheckPaymentCodeStaus($response) {
}
// important // 7.7. Merchant Request – cancel payment code : merchants’ initiation to cancel the payment code’s that already generate. public function cancelPaymentCode() {
$response = $this->processCheckPaymentCodeStaus($response); }
// 7.8. Response – cancel payment code: notification response for cancel payment code that sent to merchant’s return URL public function processCancelPaymentCode() {
}
// important // 7.9. Merchant Request – change transaction: merchants’ initiation to change payment amount that already processed. public function changeTransaction() {
$response = $this->processCheckPaymentCodeStaus($response); }
// 7.10. Response – change transaction: notification response for change payment amount that sent to merchant’s return URL public function processChangeTranscation() {
}
// 7.11. Request TCash public function requestTCash() {
$response = $this->processRequestTCash($response); }
// 7.12. Response TCash public function processRequestTCash() {
}
/** * CURL POST data to the payment gateway * @param string $endpoint endpoint URL * @param array $param parameters to pass * @return string server response string */ protected static function _excute($endpoint, $param) { $ch = curl_init(); curl_setopt_array($ch, [ CURLOPT_URL => $endpoint, CURLOPT_RETURNTRANSFER => true, CURLOPT_POST => true, CURLOPT_POSTFIELDS => http_build_query($param), CURLOPT_HEADER => false, // CURLOPT_ENCODING => 'gzip', CURLOPT_TIMEOUT => 60, CURLOPT_CONNECTTIMEOUT => 60, // CURLOPT_FOLLOWLOCATION => true, CURLOPT_SSL_VERIFYHOST => false, CURLOPT_SSL_VERIFYPEER => false, CURLOPT_SSLVERSION => 1, CURLOPT_VERBOSE => true, // CURLOPT_STDERR => $verbose, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, ]);
$output = curl_exec($ch); curl_close($ch);
// vdump(curl_errno($ch), curl_getinfo($ch));
$output = trim($output);
ApiLog::create([ 'type' => get_class($this), 'endpoint' => $endpoint, 'request' => $param, 'response' => $output, 'desc_tc' => http_build_query($param), ]);
return $output; }
// public static function resolve_pstatus($v_pstatus, $translation_fn=false){ // switch ($v_pstatus) { // case '': // case '0': // $description = "Not paid"; // break; // case '1': // case '20': // $description = "Paid"; // break; // case '2': // $description = "Not confirmed Payment"; // break; // case '3': // case '30': // $description = "Rejected Payment"; // break; // case '4': // $description = "Refund in progress"; // break; // case '5': // $description = "Refund is completed"; // break; // case '6': // $description = "Fail to refund"; // break; // case '7': // $description = "Card holder rejected"; // break; // case '8': // $description = "Abnormal refund"; // break; // default: // $description = "Invalid"; // break; // } // return is_callable($translation_fn) ? call_user_func($translation_fn, $description) : $description; // }
}
|