|
1 | 1 | <?php
|
2 | 2 | /*
|
3 |
| - * Copyright (c) 2018 PayGate (Pty) Ltd |
| 3 | + * Copyright (c) 2021 PayGate (Pty) Ltd |
4 | 4 | *
|
5 | 5 | * Author: App Inlet (Pty) Ltd
|
6 |
| - * |
| 6 | + * |
7 | 7 | * Released under the GNU General Public License
|
8 | 8 | */
|
9 | 9 |
|
10 |
| -if ( !defined( 'BOOTSTRAP' ) ) { |
11 |
| - die( 'Access denied' ); |
| 10 | +if ( ! defined('BOOTSTRAP')) { |
| 11 | + die('Access denied'); |
12 | 12 | }
|
13 | 13 |
|
14 | 14 | function fn_paygate_install()
|
15 | 15 | {
|
16 |
| - db_query( "DELETE FROM ?:payment_processors WHERE processor_script = ?s", "paygate.php" ); |
17 |
| - db_query( "INSERT INTO ?:payment_processors (`processor`, `processor_script`, `processor_template`, `admin_template`, `callback`, `type`, `addon`) VALUES ('PayGate (Web)', 'paygate.php', 'views/orders/components/payments/cc_outside.tpl', 'paygate.tpl', 'Y', 'P', 'paygate')" ); |
| 16 | + db_query("DELETE FROM ?:payment_processors WHERE processor_script = ?s", "paygate.php"); |
| 17 | + db_query( |
| 18 | + "INSERT INTO ?:payment_processors (`processor`, `processor_script`, `processor_template`, `admin_template`, `callback`, `type`, `addon`) VALUES ('PayGate (Web)', 'paygate.php', 'views/orders/components/payments/paygate.tpl', 'paygate.tpl', 'Y', 'P', 'paygate')" |
| 19 | + ); |
18 | 20 | }
|
19 | 21 |
|
20 | 22 | function fn_paygate_uninstall()
|
21 | 23 | {
|
22 |
| - db_query( "DELETE FROM ?:payment_processors WHERE processor_script = ?s", "paygate.php" ); |
| 24 | + db_query("DELETE FROM ?:payment_processors WHERE processor_script = ?s", "paygate.php"); |
23 | 25 | }
|
24 | 26 |
|
25 |
| -function fn_process_paygate_ipn( $order_id, $data ) |
| 27 | +function fn_process_paygate_ipn($order_id, $data) |
26 | 28 | {
|
27 |
| - $order_info = fn_get_order_info( $order_id, true ); |
28 |
| - $status_completed = isset( $order_info['payment_method']['processor_params']['status']['completed'] ) ? $order_info['payment_method']['processor_params']['status']['completed'] : 'P'; |
29 |
| - $status_failed = isset( $order_info['payment_method']['processor_params']['status']['failed'] ) ? $order_info['payment_method']['processor_params']['status']['failed'] : 'F'; |
30 |
| - $wcRefNo = trim( @$data['TM_RefNo'] ); |
31 |
| - $wcPrice = trim( @$data['TM_DebitAmt'] ) * 1.00; |
32 |
| - $wcCurrency = trim( $data['TM_Currency'] ); |
33 |
| - $wcStatus = strtoupper( trim( $data['TM_Status'] ) ); |
34 |
| - $wcCode = trim( $data['TM_ApprovalCode'] ); |
35 |
| - $wcError = trim( trim( trim( $data['TM_Error'] ) . " - " . trim( $data['TM_ErrorMsg'] ) ), '-' ); |
36 |
| - $order_prefix = trim( $order_info['payment_method']['processor_params']['order_prefix'] ); |
37 |
| - $wcTotal = fn_format_price( $order_info['total'], $wcCurrency ) * 1.00; |
38 |
| - if ( $wcRefNo == trim( $order_prefix . @$order_info['order_id'] ) && $wcTotal == $wcPrice && $wcStatus != '' ) { |
| 29 | + $order_info = fn_get_order_info($order_id, true); |
| 30 | + $status_completed = isset($order_info['payment_method']['processor_params']['status']['completed']) ? $order_info['payment_method']['processor_params']['status']['completed'] : 'P'; |
| 31 | + $status_failed = isset($order_info['payment_method']['processor_params']['status']['failed']) ? $order_info['payment_method']['processor_params']['status']['failed'] : 'F'; |
| 32 | + $wcRefNo = trim(@$data['TM_RefNo']); |
| 33 | + $wcPrice = trim(@$data['TM_DebitAmt']) * 1.00; |
| 34 | + $wcCurrency = trim($data['TM_Currency']); |
| 35 | + $wcStatus = strtoupper(trim($data['TM_Status'])); |
| 36 | + $wcCode = trim($data['TM_ApprovalCode']); |
| 37 | + $wcError = trim(trim(trim($data['TM_Error']) . " - " . trim($data['TM_ErrorMsg'])), '-'); |
| 38 | + $order_prefix = trim($order_info['payment_method']['processor_params']['order_prefix']); |
| 39 | + $wcTotal = fn_format_price($order_info['total'], $wcCurrency) * 1.00; |
| 40 | + if ($wcRefNo == trim($order_prefix . @$order_info['order_id']) && $wcTotal == $wcPrice && $wcStatus != '') { |
39 | 41 | $orderStatus = $wcStatus == 'YES' ? $status_completed : $status_failed;
|
40 |
| - } else { $orderStatus = $status_failed;} |
41 |
| - $data['payment_status'] = ( $wcStatus == 'YES' ) ? 'Completed' : 'Failed'; |
42 |
| - fn_clear_cart( $cart, true ); |
43 |
| - $customer_auth = fn_fill_auth( array(), array(), false, 'C' ); |
44 |
| - fn_form_cart( $order_id, $cart, $customer_auth ); |
| 42 | + } else { |
| 43 | + $orderStatus = $status_failed; |
| 44 | + } |
| 45 | + $data['payment_status'] = ($wcStatus == 'YES') ? 'Completed' : 'Failed'; |
| 46 | + fn_clear_cart($cart, true); |
| 47 | + $customer_auth = fn_fill_auth(array(), array(), false, 'C'); |
| 48 | + fn_form_cart($order_id, $cart, $customer_auth); |
45 | 49 | $cart['payment_info'] = $order_info['payment_info'];
|
46 | 50 | $cart['payment_id'] = $order_info['payment_id'];
|
47 |
| - if ( $wcStatus == 'YES' ) { |
| 51 | + if ($wcStatus == 'YES') { |
48 | 52 | $cart['payment_info']['txn_id'] = $wcCode;
|
49 | 53 | }
|
50 |
| - if ( trim( $wcError ) != '' ) { |
| 54 | + if (trim($wcError) != '') { |
51 | 55 | $cart['payment_info']['reason_text'] = $wcError;
|
52 | 56 | }
|
53 |
| - fn_calculate_cart_content( $cart, $customer_auth ); |
54 |
| - list( $order_id ) = fn_update_order( $cart, $order_id ); |
55 |
| - if ( $order_id ) { |
56 |
| - fn_change_order_status( $order_id, $orderStatus ); |
| 57 | + fn_calculate_cart_content($cart, $customer_auth); |
| 58 | + list($order_id) = fn_update_order($cart, $order_id); |
| 59 | + if ($order_id) { |
| 60 | + fn_change_order_status($order_id, $orderStatus); |
57 | 61 | }
|
58 | 62 | echo 'DONE';
|
59 | 63 | }
|
0 commit comments