-
Notifications
You must be signed in to change notification settings - Fork 0
/
class-wpg-admin.php
84 lines (72 loc) · 2.8 KB
/
class-wpg-admin.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
<?php
// Exit if accessed directly
if (!defined('ABSPATH'))
exit;
/**
* Admin Class
*
* Handles adding scripts functionality to the admin pages
* as well as the front pages.
*
* @package WooCommerce Bring Gateway
* @since 1.0.0
*/
class Wpg_Admin {
/**
* Add the gateway to WC Available Gateways
*
* @since 1.0.0
* @param array $gateways all available WC gateways
* @return array $gateways all WC gateways + Bring gateway
*/
function wpg_add_to_gateways($gateways) {
$gateways[] = 'wc_unelmapay_gateway';
return $gateways;
}
function wpg_unelmapay_gateway_icon($icon, $id) {
if ($id === 'unelmapay_gateway') {
return '<img src="' . WPG_URL . 'includes/images/logo.png" alt="unelmapay" width="80px"/>';
} else {
return $icon;
}
}
public function wpg_check_unelmapay_response() {
global $woocommerce;
/* Change IPN URL */
if (isset($_REQUEST['hash']) && isset($_REQUEST['order']) && isset($_GET['wc-api']) && $_GET['wc-api'] == 'wc_unelmapay') {
$order_id = $_REQUEST['order'];
if ($order_id != '') {
try {
$order = new WC_Order($order_id);
$hash = $_REQUEST['hash'];
$status = $_REQUEST['status'];
$trans_authorised = false;
if ('completed' !== $order->status) {
$status = strtolower($status);
if ('confirmed' == $status) {
$trans_authorised = true;
$message = "Thank you for the order. Your account has been charged and your transaction is successful.";
$class = 'success';
$order->add_order_note('unelmapay payment successful.<br/>unelmapay Transaction ID: ' . $_REQUEST['id_transfer']);
$order->payment_complete();
$woocommerce->cart->empty_cart();
$order->update_status('completed');
} else {
$class = 'error';
$message = "Thank you for the order. However, the transaction has been declined.";
$order->add_order_note('Transaction Fail');
}
}
} catch (Exception $e) {
$msg = "Error";
}
}
}
}
function add_hooks() {
add_filter('woocommerce_payment_gateways', array($this, 'wpg_add_to_gateways'));
add_filter('woocommerce_gateway_icon', array($this, 'wpg_unelmapay_gateway_icon'), 10, 2);
add_action('init', array($this, 'wpg_check_unelmapay_response'));
}
}
?>