-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy path2c2p.php
624 lines (506 loc) · 29.5 KB
/
2c2p.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
<?php
/*
Plugin Name: 2C2P Redirect API for WooCommerce
Description: Accept Payment (Credit/Debit Cards, Alipay, Alternative/Cash Payments) on your WooCommerce webstore.
Version: 7.0.1
Author: 2C2P
Author URI: http://www.2c2p.com/
*/
add_action('plugins_loaded', 'fun2c2p_init', 0);
add_action('admin_head', 'fun2c2p_backorder_font_icon');
add_action( 'init', 'fun2c2p_register_awaiting_payment_order_status' );
add_filter('wc_order_statuses', 'fun2c2p_add_awaiting_payment_to_order_statuses');
register_activation_hook(__FILE__, 'fun2c2p_register_activation_hook');
register_deactivation_hook( __FILE__, 'fun2c2p_register_deactivation_hook' );
function fun2c2p_register_activation_hook() {
global $woocommerce;
$args = array(
'post_type' => 'shop_order',
'post_status' => 'wc-pending',
'posts_per_page' => -1,
'meta_query' => array(
array(
'key' => '_payment_method',
'value' => '2c2p',
'compare' => 'LIKE',
)
)
);
$loop = new WP_Query($args);
try {
while ( $loop->have_posts() ) : $loop->the_post();
$order = new WC_Order($loop->post->ID);
$order->update_status('awaiting-payment');
endwhile;
} catch (Exception $e) {
}
}
function fun2c2p_register_deactivation_hook() {
global $woocommerce;
$args = array(
'post_type' => 'shop_order',
'post_status' => 'wc-awaiting-payment',
'posts_per_page' => -1,
'meta_query' => array(
array(
'key' => '_payment_method',
'value' => '2c2p',
'compare' => 'LIKE',
)
)
);
$loop = new WP_Query($args);
try {
while ( $loop->have_posts() ) : $loop->the_post();
$order = new WC_Order($loop->post->ID);
$order->update_status('pending');
endwhile;
} catch (Exception $e) {
}
}
/* This function is set the 2c2p icon in admin panel */
function fun2c2p_backorder_font_icon() {
echo '<style>
.widefat .column-order_status mark.awaiting-payment:after{
font-family:WooCommerce;
speak:none;
font-weight:400;
font-variant:normal;
text-transform:none;
line-height:1;
-webkit-font-smoothing:antialiased;
margin:0;
text-indent:0;
position:absolute;
top:0;
left:0;
width:100%;
height:100%;
text-align:center;
}
.widefat .column-order_status mark.awaiting-payment:after{
content:"\e012";
color:#0496c9;
}
</style>';
}
/* This function is used to add custom order status into post */
function fun2c2p_register_awaiting_payment_order_status() {
register_post_status('wc-awaiting-payment', array(
'label' => 'Awaiting Payment',
'public' => true,
'exclude_from_search' => false,
'show_in_admin_all_list' => true,
'show_in_admin_status_list' => true,
'label_count' => _n_noop('Awaiting Payment <span class="count">(%s)</span>', 'Awaiting Payment <span class="count">(%s)</span>' )
));
}
// Add to list of WC Order statuses
function fun2c2p_add_awaiting_payment_to_order_statuses( $order_statuses ) {
$new_order_statuses = array();
// add new order status after processing
foreach ( $order_statuses as $key => $status ) {
$new_order_statuses[ $key ] = $status;
if ( 'wc-processing' === $key ) {
$new_order_statuses['wc-awaiting-payment'] = 'Awaiting Payment';
}
}
return $new_order_statuses;
}
function fun2c2p_init()
{
if (!class_exists('WC_Payment_Gateway')) return;
//Included required files.
require_once(dirname(__FILE__) . '/Includes/wc-2c2p-constant.php');
require_once(dirname(__FILE__) . '/Includes/wc-2c2p-request-helper.php');
require_once(dirname(__FILE__) . '/Includes/wc-2c2p-hash-helper.php');
require_once(dirname(__FILE__) . '/Includes/wc-2c2p-validation-helper.php');
require_once(dirname(__FILE__) . '/Includes/wc-2c2p-meta-data-helper.php');
//Gateway class
class WC_Gateway_2c2p extends WC_Payment_Gateway {
//Make __construct()
public function __construct(){
$this->id = '2c2p'; // ID for WC to associate the gateway values
$this->method_title = '2C2P'; // Gateway Title as seen in Admin Dashboad
$this->method_description = '2C2P - Redefining Payments, Simplifying Lives'; // Gateway Description as seen in Admin Dashboad
$this->has_fields = false; // Inform WC if any fileds have to be displayed to the visitor in Frontend
$this->init_form_fields(); // defines your settings to WC
$this->init_settings(); // loads the Gateway settings into variables for WC
// Special settigns if gateway is on Test Mode
$test_title = '';
$test_description = '';
if (strcasecmp($this->settings['test_mode'], 'demo2') == 0 ) {
$demo = '2C2PFrontEnd/';
$test_description = '<br/><br/> Test Mode is <strong> ACTIVE </strong> Do not use personal detail to pay. Use only test detail for payment. <br/>';
}
else {
$demo = '';
}
//END--test_mode=yes
$this->title = $this->settings['title'] . $test_title; // Title as displayed on Frontend
$this->description = $this->settings['description'] . $test_description; // Description as displayed on Frontend
$this->liveurl = 'https://' . $this->settings['test_mode'] . '.2c2p.com/' . $demo . 'RedirectV3/payment';
$this->service_provider = array_key_exists('service_provider', $this->settings) ? $this->settings['service_provider'] : "";
$this->msg['message'] = '';
$this->msg['class'] = '';
add_action('init', array(&$this,'check_2c2p_response'));
add_action('woocommerce_api_' . strtolower(get_class($this)), array($this,'check_2c2p_response')); //update for woocommerce >2.0
add_action('woocommerce_receipt_2c2p', array(&$this,'receipt_page'));
add_action('woocommerce_checkout_update_order_meta', array(&$this,'wc_2c2p_custom_checkout_field_update_order_meta'));
//Load script's
add_action('wp_enqueue_scripts', array( &$this, 'wc_2c2p_load_scripts'));
if (version_compare(WOOCOMMERCE_VERSION, '2.0.0', '>=')) {
add_action('woocommerce_update_options_payment_gateways_' . $this->id, array(&$this,'process_admin_options')); //update for woocommerce >2.0
}
else {
add_action('woocommerce_update_options_payment_gateways', array(&$this,'process_admin_options')); // WC-1.6.6
}
} //END-__construct
/* Validating 123 payment expiry textbox */
public function validate_wc_2c2p_123_payment_expiry_field( $key, $value ) {
if (empty($value)) {
WC_Admin_Settings::add_error( esc_html__( 'Please enter 123 payment expiry like (8 - 720)', 'woo_2c2p'));
return $value = 0;
}
else if(!is_numeric($value)){
WC_Admin_Settings::add_error( esc_html__( 'Please enter 123 payment expiry in numeric like (8 - 720)', 'woo_2c2p'));
return $value = 0;
}
else if(!($value >= 8 && $value <= 720)){
WC_Admin_Settings::add_error( esc_html__( 'Please enter 123 payment expiry in between 8 - 720 hours only', 'woo_2c2p'));
return $value = 0;
}
return $value;
}
public function validate_key_id_field( $key, $value ) {
if (empty($value)) {
WC_Admin_Settings::add_error( esc_html__( 'Please Enter Merchant Id', 'woo_2c2p'));
return $value;
}
return $value;
}
public function validate_key_secret_field( $key, $value ) {
if (empty($value)) {
WC_Admin_Settings::add_error( esc_html__( 'Please Enter Secret Key', 'woo_2c2p'));
return $value;
}
return $value;
}
function wc_2c2p_custom_checkout_field_update_order_meta($order_id){
if(!isset($_POST['wc_2c2p_stored_card']) && empty($_POST['wc_2c2p_stored_card']))
return;
if(!intval($_POST['wc_2c2p_stored_card']))
return;
if ($_POST['wc_2c2p_stored_card'] > 0) {
update_post_meta($order_id, 'wc_2c2p_stored_card_token_id', intval($_POST['wc_2c2p_stored_card']));
}
}
/* load script for 2c2p payment. */
function wc_2c2p_load_scripts(){
wp_enqueue_script('wc-2c2p-scripts', plugin_dir_url( __FILE__ ) . 'Includes/wc-2c2p-script.js',array('jquery'), NULL, false);
}
public function wc_2c2p_get_setting(){
return $this->settings;
}
/* Get the plugin response URL */
public function wc_2c2p_response_url($order_Id){
$order = new WC_Order($order_Id);
$redirect_url = $this->get_return_url($order);
if (version_compare(WOOCOMMERCE_VERSION, '2.0.0', '>=')) {
$redirect_url = add_query_arg('wc-api', get_class($this), $redirect_url);
}
return $redirect_url;
}
/* Initiate Form Fields in the Admin Backend */
function init_form_fields(){
$this->form_fields = include(dirname(__FILE__) . '/Includes/wc-2c2p-setting.php');
}
/* Admin Panel Options.Show info on Admin Backend */
public function admin_options() {
echo '<h3>' . esc_html__('2C2P','woo_2c2p') . '</h3>';
echo '<p>' . esc_html__('2C2P provides a wide range of payment. you just save your account detail in it and enjoy shopping just in one click on 2C2P','woo_2c2p') . '</p>';
echo '<p><small><strong>' . esc_html__('Confirm your Mode: Is it LIVE or TEST.','woo_2c2p') . '</strong></small></p>';
echo '<table class="form-table">';
// Generate the HTML For the settings form.
$this->generate_settings_html();
echo '</table>';
}
/* There are no payment fields, but we want to show the description if set. */
function payment_fields(){
if (!empty($this->description)) {
echo wpautop(wptexturize($this->description));
if(is_user_logged_in()){
if(strcasecmp($this->settings['wc_2c2p_stored_card_payment'], "yes") == 0){
$strHtml = "";
$wc_2c2p_stored_card = get_user_meta(get_current_user_id(),"wc_2c2p_stored_card");
foreach ($wc_2c2p_stored_card as $key => $value) {
foreach ($value as $innerKey => $innerValue) {
$strHtml .= "<option value='". esc_attr(key($value)) ."'>". esc_attr(key($innerValue))."</option>";
}
}
if(!empty($strHtml)){
echo "<table id='tblToken'>";
echo "<tr>";
echo "<th style='width:140px;'>Select my card</th>";
echo "<td> <select id='wc_2c2p_stored_card' name='wc_2c2p_stored_card' >";
echo "<option value='0'>I'll use a new card</option>";
echo $strHtml;
echo "</select></td>";
echo "<td><input type='button' id='btn_2c2p_remove' name='btn_2c2p_remove' value='Remove Card' style='display:none;' ></td>";
echo "</tr>";
echo "</table>";
}
echo "<input type='hidden' value='". esc_url(admin_url('admin-ajax.php')) ."' id='ajax_url' />";
}
}
}
}
/* Receipt Page */
function receipt_page($order) {
echo $this->generate_2c2p_form($order);
}
/* Generate button link */
function generate_2c2p_form($order_id) {
$wc_2c2p_stored_card_token_id = 0;
if(is_user_logged_in()){
$wc_2c2p_token_id = get_post_meta($order_id, 'wc_2c2p_stored_card_token_id', true);
$wc_2c2p_stored_card = get_user_meta(get_current_user_id(),"wc_2c2p_stored_card");
foreach ($wc_2c2p_stored_card as $key => $value) {
foreach ($value as $innerKey => $innerValue) {
if(strcasecmp(key($value), $wc_2c2p_token_id) == 0){
$wc_2c2p_stored_card_token_id = $innerValue[key($innerValue)];
break;
}
}
}
}
global $woocommerce;
$order = new WC_Order( $order_id );
$redirect_url=$this->get_return_url( $order );
if (strcasecmp($this->service_provider,'money') == 0) {
$service_provider = '';
}
else {
$service_provider = '2C2P';
}
if(is_user_logged_in()){ // Customer is loggedin.
$loggedin_user_data = wp_get_current_user();
$cust_email = $loggedin_user_data->data->user_email;
}
else{
$cust_email = $order->data['billing']['email']; //Gust customer.
}
foreach($order->get_items() as $item){
$product_name .= $item['name'] . ', ';
}
$product_name = (strlen($product_name) > 0) ? substr($product_name, 0, strlen($product_name) - 2) : "";
$product_name .= '.';
$product_name = filter_var($product_name, FILTER_SANITIZE_STRING);
$fun2c2p_args = array(
'payment_description' => $product_name,
'order_id' => $order_id,
'invoice_no' => $order_id,
'amount' => $order->order_total,
'customer_email' => sanitize_email($cust_email),
'stored_card_unique_id' => $wc_2c2p_stored_card_token_id != 0 ? $wc_2c2p_stored_card_token_id : "",
'default_lang' => $default_lang
);
$objWC_2C2P_Validation_Helper = new WC_2C2P_Validation_Helper();
$isValid = $objWC_2C2P_Validation_Helper->wc_2c2p_is_valid_merchant_request($fun2c2p_args);
if (!$isValid) {
foreach ($objWC_2C2P_Validation_Helper->wc_2c2p_error as $key => $value) {
echo esc_html__($value,'woo_2c2p');
}
echo '</br>';
echo '  <a class="button cancel" href="' . esc_url($order->get_cancel_order_url()) . '">' . esc_html__('Cancel order & restore cart','woo_2c2p') . '</a>';
return;
}
else{
echo '<p><strong>' . esc_html__('Thank you for your order.','woo_2c2p') . '</strong> <br/>' . esc_html__('The payment page will open if you click on button "Pay via 2C2P".','woo_2c2p') . '</p>';
}
$fun2c2p_args['amount'] = $objWC_2C2P_Validation_Helper->wc_2c2p_validate_currency_exponent($fun2c2p_args['amount']);
$objwc_2c2p_construct_request = new wc_2c2p_construct_request_helper();
$wc_2c2p_form_field = $objwc_2c2p_construct_request->wc_2c2p_construct_request(is_user_logged_in(),$fun2c2p_args);
$strHtml = '';
$strHtml .= '<form action="' . esc_url($this->liveurl) . '" method="post" id="2c2p_payment_form">';
$strHtml .= $wc_2c2p_form_field;
$strHtml .= '<input type="submit" class="button-alt" id="submit_2c2p_payment_form" value="' . esc_html__('Pay via 2C2P','woo_2c2p') . '" />';
$strHtml .= '  <a class="button cancel" href="' . esc_url($order->get_cancel_order_url()) . '">' . esc_html__('Cancel order & restore cart','woo_2c2p') . '</a>';
$strHtml .= '</form>';
return $strHtml;
}
//Process the payment and return the result
function process_payment($order_id)
{
global $woocommerce;
$order = new WC_Order($order_id);
if (version_compare(WOOCOMMERCE_VERSION, '2.1.0', '>=')) { // For WC 2.1.0
$checkout_payment_url = $order->get_checkout_payment_url(true);
} else {
$checkout_payment_url = get_permalink(get_option('woocommerce_pay_page_id'));
}
return array('result' => 'success','redirect' => add_query_arg('order', $order->id, add_query_arg('key', $order->order_key, $checkout_payment_url)));
}
/* handle the PG response */
function check_2c2p_response() {
global $woocommerce;
if (isset($_REQUEST['order_id']) && isset($_REQUEST['merchant_id'])) {
$order_id = sanitize_text_field($_REQUEST['order_id']);
if (!empty($order_id)) {
try {
$order = new WC_Order($order_id);
/*Sanitize fields*/
$hash = sanitize_text_field($_REQUEST['hash_value']);
$transaction_ref = isset($_REQUEST['transaction_ref']) ? sanitize_text_field($_REQUEST['transaction_ref']) : "";
$payment_status = isset($_REQUEST['payment_status']) ? sanitize_text_field($_REQUEST['payment_status']) : "";
$payment_amount = isset($_REQUEST['amount']) ? sanitize_text_field($_REQUEST['amount']) : "";
$eic = isset($_REQUEST['eci']) ? sanitize_text_field($_REQUEST['eci']) : "";
$transaction_datetime = isset($_REQUEST['transaction_datetime']) ? sanitize_text_field($_REQUEST['transaction_datetime']) : "";
$approval_code = isset($_REQUEST['approval_code']) ? sanitize_text_field($_REQUEST['approval_code']) : "" ;
$masked_pan = isset($_REQUEST['masked_pan']) ? sanitize_text_field($_REQUEST['masked_pan']) : "" ;
$stored_card_unique_id = isset($_REQUEST['stored_card_unique_id']) ? sanitize_text_field($_REQUEST['stored_card_unique_id']) : "" ;
$objwc_2c2p_is_valid_hash = new wc_2c2p_hash_helper();
$isValidHash = $objwc_2c2p_is_valid_hash->wc_2c2p_is_valid_hash($_REQUEST);
$trans_authorised = false;
if ($order->status !== 'completed') {
if ($isValidHash) {
//Save data to meta data table.
$objWC_2C2P_Meta_Data_Helper = new WC_2C2P_Meta_Data_Helper();
$objWC_2C2P_Meta_Data_Helper-> wc_2c2p_store_response_meta($_REQUEST);
if (strcasecmp($payment_status, "000") == 0) { //Success using credit/debit card (Authorized) or Success when paid with cash channel (Paid)
$isFounded = false;
//Stored stored card toek into user meta table with loggedin users only.
if(is_user_logged_in() || $order->user_id > 0 ){
$stored_card = get_user_meta($order->user_id,"wc_2c2p_stored_card");
$stored_card_data = array($order_id => array($masked_pan => $stored_card_unique_id));
if(empty($stored_card)){
if(!empty($_REQUEST['stored_card_unique_id'])){
add_user_meta($order->user_id, "wc_2c2p_stored_card", $stored_card_data);
}
}
else{
foreach ($stored_card as $key => $value) {
foreach ($value as $innerKey => $innerValue) {
if(array_key_exists('masked_pan',$_REQUEST) && array_key_exists('stored_card_unique_id',$_REQUEST)){
if((strcasecmp(Key($innerValue), $_REQUEST['masked_pan']) == 0 && strcasecmp($innerValue[key($innerValue)], $_REQUEST['stored_card_unique_id']) == 0)){
$isFounded = true;
break;
}
}
}
}
if(!$isFounded) {
if(!empty($_REQUEST['masked_pan']) && !empty($_REQUEST['stored_card_unique_id'])){
add_user_meta($order->user_id, "wc_2c2p_stored_card", $stored_card_data);
}
}
}
}
$trans_authorised = true;
$this->msg['message'] = "Thank you for shopping with us. Your account has been charged and your transaction is successful.";
$this->msg['class'] = 'woocommerce-message';
if (strcasecmp($order->status, 'processing') == 0) {
$order->add_order_note('order_id: ' . $order_id . '<br/>transaction_ref: ' . $transaction_ref . '<br/>payment status: ' . $payment_status . '<br/>amount: ' . $payment_amount . '<br/>eci: ' . $eic . '<br/>transaction_datetime: ' . $transaction_datetime . '<br/>approval_code: ' . $approval_code);
$order->update_status('processing');
}
else {
$order->update_status('processing');
$order->payment_complete();
$order->add_order_note('2C2P payment transaction successful.<br/>order_id: ' . $order_id . '<br/>transaction_ref: ' . $transaction_ref . '<br/>eci: ' . $eic . '<br/>transaction_datetime: ' . $transaction_datetime . '<br/>approval_code: ' . $approval_code);
$woocommerce->cart->empty_cart();
}
}
else if (strcasecmp($payment_status, "001") == 0) { // Pending (Waiting customer to pay)
$trans_authorised = true;
$this->msg['message'] = "Thank you for shopping with us. Right now your payment status is pending. We will keep you posted regarding the status of your order through eMail";
$this->msg['class'] = 'woocommerce-info';
$order->add_order_note('2C2P payment status is pending<br/>order_id: ' . $order_id . '<br/>transaction_ref: ' . $transaction_ref . '<br/>eci: ' . $eic . '<br/>transaction_datetime: ' . $transaction_datetime . '<br/>approval_code: ' . $approval_code);
$order->update_status('awaiting-payment');
$woocommerce->cart->empty_cart();
}
else {
//Rejected,User cancel or Error.
$this->msg['class'] = 'woocommerce-error';
$this->msg['message'] = "Thank you for shopping with us. However, the transaction has been declined.";
$order->add_order_note('order_id: ' . $order_id . '<br/>transaction_ref: ' . $transaction_ref . '<br/>eci: ' . $eci . '<br/>transaction_datetime: ' . $transaction_datetime . '<br/>approval_code: ' . $approval_code);
}
}
else {
$this->msg['class'] = 'error';
$this->msg['message'] = "Security Error. Illegal access detected.";
$order->add_order_note('Checksum ERROR: ' . json_encode($_REQUEST));
$order->update_status('failed');
}
if (!$trans_authorised) {
$order->update_status('cancelled');
}
}
}
catch (Exception $e){
$msg = "Error";
}
}
if (strcasecmp($payment_status, "000") == 0 || strcasecmp($payment_status, "001") == 0) {
$redirect_url = $this->get_return_url($order);
}
else {
$redirect_url = get_site_url() . "/cart";
}
if (version_compare(WOOCOMMERCE_VERSION, '2.1.0', '>=')) { // For WC 2.1.0
$checkout_payment_url = $order->get_checkout_payment_url(true);
}
else {
$checkout_payment_url = get_permalink(get_option('woocommerce_pay_page_id'));
}
wp_redirect($redirect_url); exit;
}
}
public function thanku_page() { }
} //END-class
add_action('wp_ajax_paymentajax', 'wp_2c2p_remove_stored_card_Id_ajax');
add_action('wp_ajax_nopriv_paymentajax', 'wp_2c2p_remove_stored_card_Id_ajax');
function wp_2c2p_remove_stored_card_Id_ajax(){
$data = $_POST['data'];
if(!isset($data['token_id']) || !intval($data['token_id'])){
echo "0"; die;
}
$isFounded = false;
$wc_2c2p_stored_card = get_user_meta(get_current_user_id(),"wc_2c2p_stored_card");
foreach ($wc_2c2p_stored_card as $key => $value) {
foreach ($value as $innerKey => $innerValue) {
if(strcasecmp(key($value), $data['token_id']) == 0){
$stored_card_data = array($data['token_id'] => array(key($innerValue) => $innerValue[key($innerValue)]));
$isFounded = true;
break;
}
}
}
if($isFounded){
echo delete_user_meta(get_current_user_id(), 'wc_2c2p_stored_card',$stored_card_data); die;
}
else{
echo "0"; die;
}
}
//Add the Gateway to WooCommerce
function woocommerce_add_gateway_2c2p_gateway($methods) {
$methods[] = 'WC_Gateway_2c2p';
return $methods;
} //END-wc_add_gateway
add_filter('woocommerce_payment_gateways', 'woocommerce_add_gateway_2c2p_gateway');
} //END-init
//Virasat Solutions 'Settings' link on plugin page
add_filter('plugin_action_links', 'fun2c2p_add_action_plugin', 10, 5);
function fun2c2p_add_action_plugin($actions, $plugin_file)
{
static $plugin;
if (!isset($plugin))
$plugin = plugin_basename(__FILE__);
if ($plugin == $plugin_file) {
$settings = array(
'settings' => '<a href="admin.php?page=wc-settings&tab=checkout§ion=WC_Gateway_2c2p">' . esc_html__('Settings','woo_2c2p') . '</a>'
);
$actions = array_merge($settings, $actions);
}
return $actions;
} //END-settings_add_action_link