-
Notifications
You must be signed in to change notification settings - Fork 0
/
accept-wc.php
242 lines (215 loc) · 8.28 KB
/
accept-wc.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
<?php
/**
* Plugin Name: WooCommerce Accept Payments
* Plugin URI: https://weaccept.co
* Description: Adds powerful payment methods to your WooCommerce store.
* Version: 5.4.3
* Author: Accept
* Author URI: https://weaccept.co
* Copyright: © 2018 ~ 2019 Accpet
* License: GNU General Public License v3.0
* License URI: http://www.gnu.org/licenses/gpl-3.0.html
*/
define('ACCEPT_PLUGIN_VERSION', '5.4.3');
class WC_Accept_Payments
{
public function __construct()
{
$this->online = get_option('woocommerce_accept-online_settings');
$this->valu = get_option('woocommerce_accept-kiosk_settings');
$this->wallet = get_option('woocommerce_accept-wallet_settings');
// only display the notice when the user allows the control
if ($this->online['force_notice'] == "yes" || $this->valu['force_notice'] == "yes" || $this->wallet['force_notice'] == "yes")
{
add_filter('woocommerce_thankyou', array($this, 'notice'), 10);
}
add_action('init', array($this, 'init_gateway'));
add_action('wp_footer', array($this, 'render'));
add_filter('woocommerce_default_address_fields', array($this, 'custom_address_fields'));
add_filter('woocommerce_checkout_fields', array($this, 'add_address_fields'));
add_action('woocommerce_api_wc-accept-version', array($this, 'debug'));
}
public function debug()
{
echo ACCEPT_PLUGIN_VERSION;
exit;
}
/**
* Displays the WooCommerce Notices into the order page, as its not supported by some themes.
* @since 5.4.0
*/
public function notice(){
wc_print_notices();
}
public function render()
{
if (!is_admin()) {
if ( is_page('ACCEPT PAYMENTS') )
{
$script_url = plugins_url('/woo-accept/assets/js/scripts.js');
echo "<script src='$script_url'></script>";
}
}
}
public function init_gateway()
{
global $woocommerce;
if (!class_exists('WC_Payment_Gateway')) {
echo "Sorry this plugin needs WooCommerce installed on your website.";
return;
}
include_once 'helpers/admin-helper.php';
include_once 'helpers/pay-helper.php';
include_once 'gateways/online.php';
include_once 'gateways/kiosk.php';
include_once 'gateways/wallet.php';
include_once 'gateways/valu.php';
add_filter('woocommerce_payment_gateways', array($this, 'add_accept_gateways'));
}
public function add_accept_gateways($methods)
{
$methods[] = 'WC_Gateway_Accept_Online';
$methods[] = 'WC_Gateway_Accept_Kiosk';
$methods[] = 'WC_Gateway_Accept_Wallet';
$methods[] = 'WC_Gateway_Accept_Valu';
return $methods;
}
public function custom_address_fields($fields)
{
$fields['address_1'] = array(
'label' => __('Street Number', 'woocommerce'),
'class' => array('form-row-wide', 'address-field'),
'required' => true,
'priority' => 40,
);
$fields['address_2'] = array(
'placeholder' => __('More Address information', 'woocommerce'),
'class' => array('form-row-wide', 'address-field'),
'required' => false,
'priority' => 50,
);
$fields['city'] = array(
'label' => __('City'),
'class' => array('form-row-wide', 'address-field'),
'required' => true,
);
$fields['postcode'] = array(
'label' => __('Postcode', 'woocommerce'),
'class' => array('form-row-wide', 'address-field'),
'required' => false,
'priority' => 80,
);
$fields['state'] = array(
'label' => __('State', 'woocommerce'),
'class' => array('form-row-wide', 'address-field'),
'required' => false,
'priority' => 90,
);
return $fields;
}
public function add_address_fields($fields)
{
$fields['billing']['billing_phone'] = array(
'label' => __('Phone', 'woocommerce'),
'placeholder' => _x('Phone', 'placeholder', 'woocommerce'),
'class' => array('form-row-wide', 'address-field'),
'required' => true,
'priority' => 21,
);
$fields['billing']['billing_email'] = array(
'label' => __('Email', 'woocommerce'),
'placeholder' => _x('Email', 'placeholder', 'woocommerce'),
'class' => array('form-row-wide', 'address-field'),
'required' => true,
'priority' => 22,
);
$fields['shipping']['shipping_phone'] = array(
'label' => __('Phone', 'woocommerce'),
'placeholder' => _x('Phone', 'placeholder', 'woocommerce'),
'class' => array('form-row-wide', 'address-field'),
'clear' => true,
'required' => true,
'priority' => 21,
);
$fields['shipping']['shipping_email'] = array(
'label' => __('Email', 'woocommerce'),
'placeholder' => _x('Email', 'placeholder', 'woocommerce'),
'class' => array('form-row-wide', 'address-field'),
'clear' => true,
'required' => true,
'priority' => 22,
);
return $fields;
}
}
$GLOBALS['wc_accept_payments'] = new WC_Accept_Payments();
register_activation_hook(__FILE__, 'install');
function install()
{
global $wpdb;
$content = '
<style>
/**
* @Author Accept.
* @Description CSS for ACCEPT PAYMENTS page.
* @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
* It is better not to edit the contents of this page unless you know (HTML, CSS).
*
*/
#accepting-container div {display:none;}
#accepting-container div {text-align:center;}
#accepting-container {width:100%;margin:0.2rem auto;min-width:300px;min-height:100vh;}
#accepting-container .accept_error h1 {color:#e91e63;}
#accepting-container .accept_iframe iframe {border:none !important;width:100%;min-height:100vh;}
#accepting-container .accept_kiosk h1 {padding:0;color:#4caf50;}
#accepting-container .accept_kiosk p {color:#03a9f4;}
</style>
<div id="accepting-container">
<div class="accept_error">
<h1>Something went wrong, Please contact the store owner.</h1>
<p>
<code>Error code: EMPTY_SESSION</code>
</p>
</div>
<div class="accept_iframe"></div>
<div class="accept_kiosk">
<h2>Your Aman bill reference is</h2>
<h1 id="accept_kiosk_id"></h1>
<p>Please go to the nearest Kiosk oulet, ask for "Madfouaat Motanouea Accept" and provide your bill reference.</p>
</div>
</div>
';
if (get_page_by_path('accept-payments') == null) {
wp_insert_post(
array(
'page_template' => '',
'comment_status' => 'closed',
'post_date' => date('Y-m-d H:i:s'),
'post_title' => 'ACCEPT PAYMENTS',
'post_name' => 'accept-payments',
'post_status' => 'publish',
'post_type' => 'page',
'post_content' => "$content",
)
);
}else{
$update_page = array(
'ID' => get_page_by_title('ACCEPT PAYMENTS')->ID,
'post_content' => "$content",
);
wp_update_post( $update_page );
}
$table_name = $wpdb->prefix . 'accept_cards_token';
$charset_collate = $wpdb->get_charset_collate();
$sql = "CREATE TABLE $table_name (
id bigint(20) NOT NULL AUTO_INCREMENT,
user_id bigint(20) NOT NULL,
token varchar(56) DEFAULT '' NOT NULL,
masked_pan varchar(19) DEFAULT '' NOT NULL,
card_subtype varchar(56) DEFAULT '' NOT NULL,
PRIMARY KEY (id),
KEY user_id (user_id)
) $charset_collate;";
require_once ABSPATH . 'wp-admin/includes/upgrade.php';
dbDelta($sql);
}