@@ -171,13 +171,6 @@ public function init_form_fields() {
171
171
),
172
172
'default ' => 'no '
173
173
),
174
- 'delete_chargily_customer_ids ' => array (
175
- 'title ' => __ ('Update the database ' , 'chargilytextdomain ' ),
176
- 'type ' => 'button ' ,
177
- 'description ' => __ ('Use this button to Update the database. <br>
178
- Click this button if you have encountered problems in previous versions ' , 'chargilytextdomain ' ),
179
- ),
180
-
181
174
// END
182
175
);
183
176
}
@@ -397,14 +390,10 @@ public function process_payment( $order_id ) {
397
390
$ order_type ='Test ' ;
398
391
$ order ->update_meta_data ( 'chargily_order_type ' , $ order_type );
399
392
$ order ->save ();
400
- $ user_id = get_current_user_id ();
401
- $ chargily_customers_id = get_user_meta ($ user_id , 'chargily_customers_id_test ' , true );
402
393
} else {
403
394
$ order_type ='Live ' ;
404
395
$ order ->update_meta_data ( 'chargily_order_type ' , $ order_type );
405
396
$ order ->save ();
406
- $ user_id = get_current_user_id ();
407
- $ chargily_customers_id = get_user_meta ($ user_id , 'chargily_customers_id_live ' , true );
408
397
}
409
398
410
399
$ languages_type = $ this ->get_option ('languages_type ' );
@@ -434,8 +423,6 @@ public function process_payment( $order_id ) {
434
423
}
435
424
436
425
$ encryption_key = $ this ->get_encryption_key ();
437
- $ user_id = get_current_user_id ();
438
- //$chargily_customers_id = get_user_meta($user_id, 'chargily_customers_id', true);
439
426
440
427
function filter_empty_values ($ value ) {
441
428
if (is_array ($ value )) {
@@ -445,34 +432,12 @@ function filter_empty_values($value) {
445
432
}
446
433
447
434
if ( is_user_logged_in () ) {
448
- if ( isset ( $ _COOKIE ['chargily_customers_id_test ' ] ) ) {
449
- unset( $ _COOKIE ['chargily_customers_id_test ' ] );
450
- }
451
- if ( isset ( $ _COOKIE ['chargily_customers_id_live ' ] ) ) {
452
- unset( $ _COOKIE ['chargily_customers_id_live ' ] );
453
- }
454
- }
455
-
456
- if ($ user_id ) {
457
435
458
- if ( is_user_logged_in () ) {
459
- if ( isset ( $ _COOKIE ['chargily_customers_id_test ' ] ) ) {unset( $ _COOKIE ['chargily_customers_id_test ' ] );}
460
- if ( isset ( $ _COOKIE ['chargily_customers_id_live ' ] ) ) {unset( $ _COOKIE ['chargily_customers_id_live ' ] );}
461
- }
462
-
436
+ $ user_id = get_current_user_id ();
463
437
$ is_test_mode = $ this ->get_option ('test_mode ' ) === 'yes ' ;
464
438
$ meta_key = $ is_test_mode ? 'chargily_customers_id_test ' : 'chargily_customers_id_live ' ;
465
439
$ chargily_customers_id = get_user_meta ($ user_id , $ meta_key , true );
466
- if (isset ($ chargily_customers_id )) {
467
- $ is_test_mode = $ this ->get_option ('test_mode ' ) === 'yes ' ;
468
- $ meta_key = $ is_test_mode ? 'chargily_customers_id_test ' : 'chargily_customers_id_live ' ;
469
- $ chargily_customers_id = get_user_meta ($ user_id , $ meta_key , true );
470
- } else {
471
- $ user_id = get_current_user_id ();
472
- $ is_test_mode = $ this ->get_option ('test_mode ' ) === 'yes ' ;
473
- $ meta_key = $ is_test_mode ? 'chargily_customers_id_test ' : 'chargily_customers_id_live ' ;
474
- $ chargily_customers_id = get_user_meta ($ user_id , $ meta_key , true );
475
- if (!$ this ->customer_exists ($ chargily_customers_id , $ user_id )) {
440
+ if (!$ this ->customer_exists ($ chargily_customers_id , $ user_id )) {
476
441
// إنشاء بيانات العميل لإرسالها إلى API
477
442
$ address = array_filter (array (
478
443
"country " => $ order ->get_billing_country (),
@@ -505,13 +470,14 @@ function filter_empty_values($value) {
505
470
// No data to send
506
471
return ;
507
472
}
473
+
508
474
$ user_id = get_current_user_id ();
509
475
$ chargily_customers_id = $ this ->create_chargily_customer ($ user_data , $ user_id );
510
476
if (is_wp_error ($ chargily_customers_id )) {
511
477
wc_add_notice ($ chargily_customers_id ->get_error_message (), 'error ' );
512
478
return ;
513
479
}
514
- }
480
+ // end
515
481
}
516
482
} else {
517
483
// العميل هو زائر
@@ -644,11 +610,6 @@ function filter_empty_values($value) {
644
610
);
645
611
}
646
612
647
-
648
- if (!empty ($ chargily_customers_id )) {
649
- $ payload ['customer_id ' ] = $ chargily_customers_id ;
650
- }
651
-
652
613
$ response = $ this ->create_chargilyv2_checkout ($ payload );
653
614
654
615
if (is_wp_error ($ response )) {
@@ -675,12 +636,15 @@ function filter_empty_values($value) {
675
636
}
676
637
677
638
678
- private function customer_exists ($ customer_id , $ user_id ) {
639
+ private function customer_exists ($ chargily_customers_id , $ user_id ) {
640
+ if (empty ($ chargily_customers_id )) {
641
+ $ chargily_customers_id = "0000000099999 " ;
642
+ }
679
643
$ credentials = $ this ->get_api_credentials ();
680
644
$ is_test_mode = $ this ->get_option ('test_mode ' ) === 'yes ' ;
681
645
$ api_url = $ is_test_mode
682
- ? 'https://pay.chargily.net/test/api/v2/customers/ ' . $ customer_id
683
- : 'https://pay.chargily.net/api/v2/customers/ ' . $ customer_id ;
646
+ ? 'https://pay.chargily.net/test/api/v2/customers/ ' . $ chargily_customers_id
647
+ : 'https://pay.chargily.net/api/v2/customers/ ' . $ chargily_customers_id ;
684
648
685
649
$ headers = array (
686
650
'Authorization ' => 'Bearer ' . $ credentials ['api_secret ' ],
@@ -1175,7 +1139,6 @@ function update_chargily_pay_settingss() {
1175
1139
}
1176
1140
}
1177
1141
1178
- //-------------
1179
1142
function custom_override_checkout_fields ( $ fields ) {
1180
1143
$ fields ['billing ' ]['billing_phone ' ]['validate ' ] = array ( 'phone ' );
1181
1144
$ fields ['billing ' ]['billing_phone ' ]['custom_attributes ' ] = array (
@@ -1190,39 +1153,38 @@ function custom_override_checkout_fields( $fields ) {
1190
1153
1191
1154
function custom_checkout_phone_validation_script () {
1192
1155
if ( is_checkout () ) {
1193
- ?>
1194
- <script>
1195
- jQuery(document).ready(function($) {
1196
- $('#billing_phone').on('change', function(){
1197
- var phone = $(this).val();
1198
- if ( phone.length < 8 || phone.length > 20 || !$.isNumeric(phone) ) {
1199
- $(this).get(0).setCustomValidity('رقم الهاتف يجب أن يكون بين 8 إلى 20 رقمًا.');
1200
- } else {
1201
- $(this).get(0).setCustomValidity('');
1202
- }
1203
- });
1204
- });
1205
- </script>
1206
- <?php
1156
+ if ( is_user_logged_in () ) {
1157
+ if ( isset ( $ _COOKIE ['chargily_customers_id ' ] ) ) {unset( $ _COOKIE ['chargily_customers_id ' ] );}
1158
+ if ( isset ( $ _COOKIE ['chargily_customers_id_test ' ] ) ) {unset( $ _COOKIE ['chargily_customers_id_test ' ] );}
1159
+ if ( isset ( $ _COOKIE ['chargily_customers_id_live ' ] ) ) {unset( $ _COOKIE ['chargily_customers_id_live ' ] );}
1160
+ }
1161
+ ?>
1162
+ <script>
1163
+ jQuery(document).ready(function($) {
1164
+ $('#billing_phone').on('change', function(){
1165
+ var phone = $(this).val();
1166
+ if ( phone.length < 8 || phone.length > 20 || !$.isNumeric(phone) ) {
1167
+ $(this).get(0).setCustomValidity('رقم الهاتف يجب أن يكون بين 8 إلى 20 رقمًا.');
1168
+ } else {
1169
+ $(this).get(0).setCustomValidity('');
1170
+ }
1171
+ });
1172
+ });
1173
+ function deleteCookie(name) {
1174
+ document.cookie = name + '=; Path=/; Expires=Thu, 01 Jan 1970 00:00:01 GMT;';
1175
+ }
1176
+
1177
+ window.onload = function() {
1178
+ deleteCookie('chargily_customers_id');
1179
+ deleteCookie('chargily_customers_id_test');
1180
+ deleteCookie('chargily_customers_id_live');
1181
+ };
1182
+ </script>
1183
+ <?php
1207
1184
}
1208
1185
}
1209
1186
add_action ( 'wp_footer ' , 'custom_checkout_phone_validation_script ' );
1210
1187
1211
-
1212
- add_action ('wp_ajax_delete_chargily_customer_ids ' , 'delete_chargily_customer_ids_callback ' );
1213
- function delete_chargily_customer_ids_callback () {
1214
- if ( is_admin () ) {
1215
- if (current_user_can ('administrator ' ) || current_user_can ('shop_manager ' )) {
1216
- $ users = get_users ();
1217
- foreach ($ users as $ user ) {
1218
- delete_user_meta ($ user ->ID , 'chargily_customers_id ' );
1219
- }
1220
- wp_send_json_success ('The database has been updated successfully. ' );
1221
- wp_die ();
1222
- }
1223
- }
1224
- }
1225
-
1226
1188
add_filter ( 'manage_edit-shop_order_columns ' , 'chargily_order_items_column ' );
1227
1189
add_filter ( 'manage_woocommerce_page_wc-orders_columns ' , 'chargily_order_items_column ' );
1228
1190
function chargily_order_items_column ( $ columns ) {
0 commit comments