/
payment-network.php
140 lines (107 loc) · 4.57 KB
/
payment-network.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
<?php
/*
Plugin Name: PaymentNetwork
Description: Provides the PaymentNetwork Payment Gateway for WooCommerce
*/
/**
* Initialise WC Payment Network Gateway
**/
add_action('plugins_loaded', 'init_wc_payment_network', 0);
/**
* Initialise WC PaymentNetwork Gateway
**/
if (function_exists('setup_module_database_tables')) {
register_activation_hook(__FILE__, 'setup_module_database_tables');
}
/**
* Delete PaymentNetwork Gateway
**/
if (function_exists('delete_plugin_database_table')) {
register_uninstall_hook(__FILE__, 'delete_plugin_database_table');
}
function init_wc_payment_network()
{
if (!class_exists('WC_Payment_Gateway')) {
return;
}
add_filter('plugin_action_links', 'add_wc_payment_network_action_plugin', 10, 5);
require_once __DIR__ . '/vendor/autoload.php';
add_filter('woocommerce_payment_gateways', 'add_payment_network_payment_gateway');
/**
* Add Apple Pay AJAX options
*/
include('includes/class-wc-payment-network.php');
include('includes/class-wc-payment-network-applepay.php');
// Validate Apple Pay merchant
add_action('wp_ajax_nopriv_process_applepay_payment', array(new WC_Payment_Network_ApplePay, 'process_applepay_payment'), 10, 2);
add_action('wp_ajax_process_applepay_payment', array(new WC_Payment_Network_ApplePay, 'process_applepay_payment'), 10, 2);
// Process Apple Pay payment token
add_action('wp_ajax_nopriv_validate_applepay_merchant', array(new WC_Payment_Network_ApplePay, 'validate_applepay_merchant'), 10, 2);
add_action('wp_ajax_validate_applepay_merchant', array(new WC_Payment_Network_ApplePay, 'validate_applepay_merchant'), 10, 2);
// Get Apple Pay request
add_action('wp_ajax_nopriv_get_applepay_request', array(new WC_Payment_Network_ApplePay, 'get_applepay_request'), 10, 2);
add_action('wp_ajax_get_applepay_request', array(new WC_Payment_Network_ApplePay, 'get_applepay_request'), 10, 2);
// Get updated Apple Pay request
add_action('wp_ajax_nopriv_get_shipping_methods', array(new WC_Payment_Network_ApplePay, 'get_shipping_methods'), 10, 2);
add_action('wp_ajax_get_shipping_methods', array(new WC_Payment_Network_ApplePay, 'get_shipping_methods'), 10, 2);
// Get updated Apple Pay request
add_action('wp_ajax_nopriv_update_shipping_method', array(new WC_Payment_Network_ApplePay, 'update_shipping_method'), 10, 2);
add_action('wp_ajax_update_shipping_method', array(new WC_Payment_Network_ApplePay, 'update_shipping_method'), 10, 2);
// Apple coupon code to Apple Pay request
add_action('wp_ajax_nopriv_apply_coupon_code', array(new WC_Payment_Network_ApplePay, 'apply_coupon_code'), 10, 2);
add_action('wp_ajax_update_apply_coupon_code', array(new WC_Payment_Network_ApplePay, 'apply_coupon_code'), 10, 2);
// Generate CSR and KEY files.
add_action('wp_ajax_generate_csr_and_key', array(new WC_Payment_Network_ApplePay, 'generate_csr_and_key'), 10, 2);
}
function add_wc_payment_network_action_plugin($actions, $plugin_file)
{
static $plugin;
if (!isset($plugin)) {
$plugin = plugin_basename(__FILE__);
}
if ($plugin == $plugin_file) {
$configs = include(dirname(__FILE__) . '/config.php');
$section = str_replace(' ', '', strtolower($configs['default']['gateway_title']));
$actions = array_merge(array('settings' => '<a href="' . admin_url('admin.php?page=wc-settings&tab=checkout§ion=' . $section) . '">' . __('Settings', 'General') . '</a>'), $actions);
}
return $actions;
}
function add_payment_network_payment_gateway($methods)
{
$methods[] = 'WC_Payment_Network';
$methods[] = 'WC_Payment_Network_ApplePay';
return $methods;
}
function setup_module_database_tables()
{
$module_prefix = 'payment_network_';
global $wpdb;
global $jal_db_version;
//Wallet table name.
$wallet_table_name = $wpdb->prefix . 'woocommerce_' . $module_prefix . 'wallets';
if ($wpdb->get_var($wpdb->prepare("SHOW TABLES LIKE %s", $wallet_table_name)) === null) {
$table_name = $wallet_table_name;
$charset_collate = $wpdb->get_charset_collate();
$sql = "CREATE TABLE $table_name (
id BIGINT(9) NOT NULL AUTO_INCREMENT,
merchants_id INT NOT NULL,
users_id BIGINT NOT NULL,
wallets_id BIGINT NOT NULL,
PRIMARY KEY (id)
) $charset_collate;";
require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
dbDelta($sql);
add_option('jal_db_version', $jal_db_version);
}
}
function delete_plugin_database_table()
{
$module_prefix = 'payment_network_';
global $wpdb;
$wpdb->show_errors();
$table_name = $wpdb->prefix . 'woocommerce_' . $module_prefix . 'wallets';
$sql = "DROP TABLE IF EXISTS $table_name";
$wpdb->query($sql);
//delete_option("my_plugin_db_version");
//error_log('Logging SQL table drop');
}