-
Notifications
You must be signed in to change notification settings - Fork 0
/
DotPay.php
executable file
·690 lines (617 loc) · 17.6 KB
/
DotPay.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
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
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
<?php
/**
* DotPay.php
*
* This is an implementation of a demonstration payment gateway plug-in.
* It demonstrates how a payment plug-in can be developed, and contains stubs for all API functions.
*
* Description:
*
* The Payment SDK API requires a number functions to be implemented.
* The function names must be named as follows: plug-in name prefix, underline symbol (e.g., DotPay_) and operation name (e.g., Sell)
* Example :
* function DotPay_Sell() {
* ...
* }
*
*
* Methods receive an array with some parameters specified for the *** function.
* The array with parameters may contain some of these values:
* ref_no - Internal Billing transaction ID
* transaction_amount - The amount to process within a transaction
* currency_iso - The currency of the amount in the ISO format
* account_info - Information on the Billing account including billing information, vendor information, etc.
* document_info - Information on the payment
* payment_method - Information on the payment method including token, public name, etc.
* previous_transaction_data - Plug-in specific data that was received from the previous transaction
* callback_params - Parameters received from the payment gateway site on callback
* config - Plug-in configuration data
* environment - Additional data that can be used for the payment processing: lang, callback URLs, etc.
*
* Methods return an array that mainly contains operation status.
* The result array (if not specified) contains the following values:
* STATUS - Operation result status.
* Possible values: APPROVED, FRAUD, DECLINED, PENDING, AUTHCALL, ERROR, REFUNDED, REDIRECT.
* TRANSACTION_DETAILS - The array that will be associated with current transaction.
* It will be represented back in unchanged form as the value of the previous_transaction_data parameter
* at the next call of transaction processing methods of the plug-in.
* REDIRECT_HASH - Information for redirect. It must contain:
* url - the URL where customer should be redirected to,
* method - the method used to pass the data: GET, POST,
* attrs - parameters and values which will be used for redirect.
* NEXT_TRANSACTION_GAP - The delay in seconds before another attempt to process the transaction will be taken
* (for STATUS = PENDING)
* TEXT - The array that contains parameters:
* customer_message - message that will be shown for customer
* vendor_message - message that will be shown for vendor
* ADD_NEW_METHOD - array with payment method to create.
* ADD_NEW_METHOD should contain paymethod_name value - it is a payment method's public name that is
* displayed to the customers. All other name-value pairs will be stored and passed to plug-in with
* next payment operation within payment_method array.
*
* All methods can throw an exception if there is an error. Exception message will be shown in the provider panel.
*
*/
require_once('DotPay_Helper.php');
/**
* Returns parameters to configure plug-in.
* Mandatory.
*
* @return array
*/
function DotPay_GetConfig( /*$params*/ ) {
return array(
'friendlyName' => pa_localized_string('title_key'),
'enable_tokens' => array(
'type' => 'yesno',
'friendlyName' => pa_localized_string('enable_tokens_key'),
'description' => pa_localized_string('enable_tokens_desc_key'),
'default' => true
),
'3dsecure' => array(
'type' => 'yesno',
'friendlyName' => pa_localized_string('enable_3dsecure_key'),
'description' => pa_localized_string('enable_3dsecure_desc_key'),
'default' => false
)
);
}
/**
* Returns status APPROVED if 3D Secure enabled or DECLINE otherwise
* Optional
*
* @return array
*/
function DotPay_Is3DSecureActive( $params ) {
if ( $params['config']['3dsecure'] ) {
return array( STATUS => STATUS_APPROVED );
}
return array( STATUS => STATUS_DECLINED );
}
/**
* Implements redirection to the payment gateway page.
* Mandatory if redirection to the gateway site is required
*
* @param $params - array of
* - ref_no
* - transaction_amount
* - currency_iso
* - account_info
* - document_info
* - config
* - environment
*
* @return array with redirect attributes or error description (see description above)
*/
function DotPay_Redirect( $params ) {
$config = $params['config'];
$doc_info = $params['document_info'];
$ref_no = $params['ref_no'];
$env = $params['environment'];
$accept_url = $env['return_url_ok'];
$decline_url = $env['return_url_failed'];
$redirect_hash = array(
'url' => 'https://demo-payment-gateway.com',
'method' => 'POST',
'attrs' => array(
'ref_no' => $ref_no,
'amount' => $params['transaction_amount'],
'currency' => $params['currency_iso'],
'accept_url' => $accept_url,
'decline_url' => $decline_url,
'enable_tokens' => isset($config['enable_tokens']) ? $config['enable_tokens'] : false
)
);
return array(
STATUS => STATUS_REDIRECT,
REDIRECT_HASH => $redirect_hash
);
}
/**
* Implements Sell transaction with a payment gateway.
* Mandatory for tokenization functionality implementation
*
* @param $params - array of
* - ref_no
* - transaction_amount
* - currency_iso
* - account_info
* - document_info
* - payment_method
* - config
* - environment
* @return array with Sell transaction result (see description above)
* @throws Exception
*/
function DotPay_Sell( $params ) {
if (!isset($params['payment_method'])) {
return DotPay_Redirect($params);
}
return array(
STATUS => STATUS_APPROVED,
TRANSACTION_DETAILS => array(
'trans_id' => _DotPay_FakeTransactionId()
)
);
}
/**
* Implements Auth transaction with a payment gateway.
* Optional. Required for 3D Secure implementation
*
* @param $params - array of
* - ref_no
* - transaction_amount
* - currency_iso
* - account_info
* - document_info
* - payment_method
* - previous_transaction_data
* - config
* - environment
* @return array with Auth transaction result (see description above)
* @throws Exception
*/
function DotPay_Auth( $params ) {
if (!isset($params['payment_method'])) {
return DotPay_Redirect($params);
}
if ( !$params['config']['3dsecure'] ) {
return array(
STATUS => STATUS_APPROVED,
TRANSACTION_DETAILS => array(
'trans_id' => _DotPay_FakeTransactionId()
)
);
}
if (isset($params['previous_transaction_data'])) {
$result = array();
if ($params['previous_transaction_data']['Enrolled'] === 'Y') {
$result[STATUS] = STATUS_APPROVED;
} else {
$result[STATUS] = STATUS_DECLINED;
$result[TEXT] = array(
'vendor_message' => 'Rejected by 3D Secure',
'customer_message' => 'Rejected by 3D Secure'
);
}
$result[TRANSACTION_DETAILS] = array(
'trans_id' => _DotPay_FakeTransactionId(),
'PaRes' => $params['previous_transaction_data']['PaRes'],
'Enrolled' => $params['previous_transaction_data']['Enrolled']
);
return $result;
}
return array(
STATUS => STATUS_3DSECURE,
REDIRECT_HASH => array(
'url' => 'https://demo-payment-gateway.com/3dsecure.php',
'method' => 'POST',
'attrs' => array(
'PaReq' => md5( (string) time() ),
'TermUrl' => $params['environment']['return_url_3dsecure'],
'amount' => $params['transaction_amount'],
'currency' => $params['currency_iso'],
)
)
);
}
/**
* Implements Sell transaction with a payment gateway.
* Mandatory if Auth method is implemented
*
* @param $params - array of
* - ref_no
* - transaction_amount
* - currency_iso
* - account_info
* - document_info
* - payment_method
* - config
* - environment
* @return array with Capture transaction result (see description above)
* @throws Exception
*/
function DotPay_Capture($params) {
return array(
STATUS => STATUS_APPROVED,
TRANSACTION_DETAILS => array(
'trans_id' => _DotPay_FakeTransactionId()
)
);
}
/**
* Implements RefundCredit transaction with a payment gateway.
* Optional
*
* @param $params - array of
* - ref_no
* - transaction_amount
* - currency_iso
* - account_info
* - document_info
* - payment_method
* - config
* - environment
*
* @return array with RefundCredit transaction result (see description above)
* @throws Exception
*/
function DotPay_RefundCredit( $params ) {
if (!isset($params['transaction_amount'])) {
throw new Exception('No transaction amount is set');
}
if (!isset($params['currency_iso']) ) {
throw new Exception('No currency is set');
}
return array(
STATUS => STATUS_APPROVED,
TRANSACTION_DETAILS => array(
'trans_id' => _DotPay_FakeTransactionId()
)
);
}
/**
* Processes 'Refund' transaction
* Optional
*
* @param $params - array of
* - ref_no
* - transaction_amount
* - currency_iso
* - account_info
* - document_info
* - payment_method
* - previous_transaction_data
* - config
* - environment
*
* @return array with Refund transaction result (see description above)
* @throws Exception
*/
function DotPay_Refund( $params ) {
if (!isset($params['previous_transaction_data'])) {
throw new Exception('No previous transaction data');
}
return array(
STATUS => STATUS_APPROVED,
TRANSACTION_DETAILS => array(
'trans_id' => _DotPay_FakeTransactionId()
)
);
}
/**
* Implements Partial Refund transaction with a payment gateway.
* Optional
*
* @param $params - array of
* - ref_no
* - transaction_amount
* - currency_iso
* - account_info
* - document_info
* - payment_method
* - previous_transaction_data
* - config
* - environment
*
* @return array with Partial Refund transaction result (see description above)
* @throws Exception
*/
function DotPay_RefundPartial( $params ) {
if (!isset($params['previous_transaction_data'])) {
throw new Exception('No previous transaction data');
}
return array(
STATUS => STATUS_APPROVED,
TRANSACTION_DETAILS => array(
'trans_id' => _DotPay_FakeTransactionId()
)
);
}
/**
* Implements voiding a transaction with a payment gateway.
* Optional
*
* @param $params - array of
* - ref_no
* - transaction_amount
* - currency_iso
* - account_info
* - document_info
* - payment_method
* - previous_transaction_data
* - config
* - environment
*
* @return array with Void transaction result (see description above)
* @throws Exception
*/
function DotPay_Void( $params ) {
if (!isset($params['previous_transaction_data'])) {
throw new Exception('No previous transaction data');
}
return array(
STATUS => STATUS_APPROVED,
TRANSACTION_DETAILS => array(
'trans_id' => _DotPay_FakeTransactionId()
)
);
}
/**
* Processes callback data received from a payment gateway.
* Optional
*
*
* @param $params - array of
* - ref_no
* - transaction_amount
* - currency_iso
* - account_info
* - document_info
* - payment_method
* - previous_transaction_data
* - callback_params
* - config
* - environment
*
* @return array with Callback transaction result (see description above)
*/
function DotPay_Callback( $params ) {
$callback_params = $params['callback_params'];
$result = $callback_params['returnResult'];
$txn_id = $callback_params['txn_id'];
switch ($result) {
case 'ok' :
$status = STATUS_APPROVED;
$desc = 'Success';
if (isset($callback_params['token']) && isset($callback_params['public_name'])) {
$new_method = array(
'token' => $callback_params['token'],
'paymethod_name' => $callback_params['public_name']
);
}
if (isset($new_method) && isset($callback_params['expires'])) {
$new_method['exp_date'] = $callback_params['expires'];
}
break;
case 'fail' :
$status = STATUS_DECLINED;
$desc = 'Declined';
break;
default :
$status = STATUS_ERROR;
$desc = "Unkown status '$result'";
break;
};
$details['desc'] = $desc;
$details['trans_id'] = $txn_id;
$response = array(
STATUS => $status,
TEXT => array( 'vendor_message' => $desc ),
TRANSACTION_DETAILS => $details
);
if (isset($new_method)) {
$response[ADD_NEW_METHOD] = $new_method;
}
return $response;
}
/**
* Checks a transaction current status on a payment gateway.
* Optional
*
* @param $params - array of
* - ref_no
* - transaction_amount
* - currency_iso
* - account_info
* - document_info
* - payment_method
* - previous_transaction_data
* - config
* - environment
*
* @return array with CheckStatus transaction result (see description above)
*/
function DotPay_CheckStatus( /*$params*/ ) {
return array(STATUS => STATUS_APPROVED);
}
/**
* Tests gateway availability using plug-in's specified config.
* Optional
*
* @param $params - array of
* - config
* - environment
*
* @return array with status "APPROVED" if connection test is successful, or "DECLINED" otherwise
*/
function DotPay_TestConnection( $params ) {
return array(STATUS => STATUS_APPROVED);
}
/**
* Validates plug-in's stored configuration
* Optional
*
* @param $params - array of
* - config
* - environment
*
* @return array with status "APPROVED" if plug-in's configuration is valid, or "DECLINED" otherwise
*/
function DotPay_ValidateConfig( /* $params */ ) {
return array(STATUS => STATUS_APPROVED);
}
/**
* Returns a list of currencies supported by gateway.
* Optional
*
* @return array of currencies
*/
function DotPay_GetSupportedCurrencies() {
return array(
'AED', # UAE Dirham
'AFN', # Afghan afghani
'ALL', # Lek
'AMD', # Armenian Dram
'ANG', # Antillian Guilder
'ARS', # Argentine Peso
'AUD', # Australian Dollar
'AWG', # Aruban Guilder
'BAM', # Convertible Marks
'BBD', # Barbados Dollar
'BDT', # Taka
'BGN', # Bulgarian LEV
'BHD', # Bahraini Dinar
'BIF', # Burundi Franc
'BMD', # Bermudian Dollar
'BND', # Brunei Dollar
'BRL', # Brazilian Real
'BSD', # Bahamian Dollar
'BTN', # Ngultrum
'BWP', # Pula
'BYR', # Belarussian Ruble
'BZD', # Belize Dollar
'CAD', # Canadian Dollar
'CDF', # Franc Congolais
'CHF', # Swiss Franc
'CLP', # Chilean Peso
'CNY', # Yuan Renminbi
'COP', # Colombian Peso
'CRC', # Costa Rican Colon
'CUP', # Cuban Peso
'CVE', # Cape Verde Escudo
'CZK', # Czech Koruna
'DJF', # Djibouti Franc
'DKK', # Danish Krone
'DOP', # Dominican Peso
'DZD', # Algerian Dinar
'EEK', # Kroon
'EGP', # Egyptian Pound
'ERN', # Nakfa
'ETB', # Ethiopian Birr
'EUR', # Euro
'FJD', # Fiji Dollar
'FKP', # Pound
'GBP', # Pound Sterling
'GEL', # Lari_r
'GIP', # Gibraltar Pound
'GMD', # Dalasi
'GNF', # Guinea Franc
'GTQ', # Quetzal
'GYD', # Guyana Dollar
'HKD', # Hong Kong Dollar
'HNL', # Lempira
'HRK', # Kuna
'HTG', # Gourde
'HUF', # Forint
'IDR', # Rupiah
'ILS', # New Israeli Sheqel
'INR', # Indian Rupee
'IQD', # Iraqi Dinar
'IRR', # Iranian Rial
'ISK', # Iceland Krona
'JMD', # Jamaican Dollar
'JOD', # Jordanian Dinar
'JPY', # Yen
'KES', # Kenyan Shilling
'KGS', # Som
'KHR', # Riel
'KMF', # Comoro Franc
'KPW', # North Korean Won
'KRW', # Won
'KWD', # Kuwaiti Dinar
'KYD', # Cayman Islands Dollar
'KZT', # Tenge
'LAK', # Kip
'LBP', # Lebanese Pound
'LKR', # Sri Lanka Rupee
'LRD', # Liberian Dollar
'LSL', # Loti
'LTL', # Lithuanian Litas
'LVL', # Latvian Lats
'LYD', # Libyan Dinar
'MAD', # Moroccan Dirham
'MDL', # Moldovan Leu
'MKD', # Denar
'MMK', # Kyat
'MNT', # Tugrik
'MOP', # Pataca
'MUR', # Mauritius Rupee
'MVR', # Rufiyaa
'MWK', # Kwacha
'MXN', # Mexican Peso
'MYR', # Malaysian Ringgit
'NAD', # Namibia Dollar
'NGN', # Naira
'NIO', # Cordoba Oro
'NOK', # Norwegian Krone
'NPR', # Nepalese Rupee
'NZD', # New Zealand Dollar
'OMR', # Rial Omani
'PAB', # Balboa
'PEN', # Nuevo Sol
'PGK', # Kina
'PHP', # Philippine Peso
'PKR', # Pakistan Rupee
'PLN', # Zloty
'PYG', # Guarani
'QAR', # Qatari Rial
'RUB', # Russian Ruble
'RWF', # Rwanda Franc
'SAR', # Saudi Riyal
'SBD', # Solomon Islands Dollar
'SCR', # Seychelles Rupee
'SEK', # Swedish Krona
'SGD', # Singapore Dollar
'SHP', # St Helena Pound
'SLL', # Leone
'SOS', # Somali Shilling
'STD', # Dobra
'SYP', # Syrian Pound
'SZL', # Lilangeni
'THB', # Baht
'TJS', # Somoni
'TND', # Tunisian Dinar
'TOP', # Paanga
'TRY', # Turkish Lira
'TTD', # Trinidad and Tobago Dollar
'TWD', # New Taiwan Dollar
'TZS', # Tanzanian Shilling
'UAH', # Hryvnia
'UGX', # Uganda Shilling
'USD', # US Dollar
'UYU', # Peso Uruguayo
'UZS', # Uzbekistan Sum
'VND', # Dong
'VUV', # Vatu
'WST', # Tala
'XAF', # CFA Franc BEAC
'XCD', # East Caribbean Dollar
'XOF', # CFA Franc BCEAO
'XPF', # CFP Franc
'YER', # Yemeni Rial
'ZAR', # Rand
'ZMK', # Kwacha
);
}
?>