PluginProbe
PayPlug for WooCommerce (Official) / 2.8.2
PayPlug for WooCommerce (Official) v2.8.2
3.0.0 2.18.0 1.0.17 1.0.18 1.0.19 1.0.20 1.0.21 1.0.22 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.1.0 1.10.0 1.10.1 1.2.1 1.2.10 1.2.11 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 All 101 releases
payplug / src / Admin / Ajax.php

Ajax.php in PayPlug for WooCommerce (Official) 2.8.2, at src/Admin/Ajax.php

663 lines 22.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Payplug\PayplugWoocommerce\Admin;
4
5 // Exit if accessed directly
6 use Payplug\Exception\HttpException;
7 use Payplug\Payplug;
8 use Payplug\Authentication;
9 use Payplug\PayplugWoocommerce\Admin\Vue;
10 use Payplug\PayplugWoocommerce\Controller\ApplePay;
11 use Payplug\PayplugWoocommerce\Gateway\AmericanExpress;
12 use Payplug\PayplugWoocommerce\Gateway\Bancontact;
13 use Payplug\PayplugWoocommerce\Gateway\PayplugGateway;
14 use Payplug\PayplugWoocommerce\Gateway\PayplugGatewayOney3x;
15 use Payplug\PayplugWoocommerce\Gateway\PayplugPermissions;
16 use Payplug\PayplugWoocommerce\Gateway\PPRO\Ideal;
17 use Payplug\PayplugWoocommerce\Gateway\PPRO\Mybank;
18 use Payplug\PayplugWoocommerce\Gateway\PPRO\Satispay;
19 use Payplug\PayplugWoocommerce\Gateway\PPRO\Sofort;
20 use Payplug\PayplugWoocommerce\PayplugWoocommerceHelper;
21 use Payplug\Exception\PayplugException;
22 use WP_REST_Request;
23
24 if ( ! defined( 'ABSPATH' ) ) {
25 exit;
26 }
27
28 /**
29 * PayPlug admin ajax handler.
30 *
31 * @package Payplug\PayplugWoocommerce\Admin
32 */
33 class Ajax {
34
35 public function __construct() {
36 $permission = ( current_user_can('editor') || current_user_can('administrator') );
37
38 add_action( 'rest_api_init', function () use ($permission) {
39 //Path to REST route and the callback function
40 register_rest_route( 'payplug_api', '/save/', array(
41 'methods' => 'POST',
42 'callback' => [ $this, 'payplug_save_data' ],
43 'permission_callback' => function () use ($permission) {return $permission ;},
44 'show_in_index' => false
45 ) );
46 register_rest_route( 'payplug_api', '/init/', array(
47 'methods' => 'POST',
48 'callback' => [ $this, 'payplug_init' ],
49 'permission_callback' => function () use ($permission) {return $permission ;},
50 'show_in_index' => false
51 ) );
52 register_rest_route( 'payplug_api', '/login/', array(
53 'methods' => 'POST',
54 'callback' => [ $this, 'payplug_login' ],
55 'permission_callback' => function () use ($permission) {return $permission ;},
56 'show_in_index' => false
57 ) );
58 register_rest_route( 'payplug_api', '/logout/', array(
59 'methods' => 'POST',
60 'callback' => [ $this, 'payplug_logout' ],
61 'permission_callback' => function () use ($permission) {return $permission ;},
62 'show_in_index' => false
63 ) );
64 register_rest_route( 'payplug_api', '/refresh_keys/', array(
65 'methods' => 'POST',
66 'callback' => [ $this, 'refresh_keys' ],
67 'permission_callback' => function () use ($permission) {return $permission ;},
68 'show_in_index' => false
69 ) );
70 register_rest_route( 'payplug_api', '/check_requirements/', array(
71 'methods' => 'POST',
72 'callback' => [ $this, 'payplug_check_requirements' ],
73 'permission_callback' => function () use ($permission) {return $permission ;},
74 'show_in_index' => false
75 ) );
76 register_rest_route( 'payplug_api', '/bancontact_permissions/', array(
77 'methods' => 'POST',
78 'callback' => [ $this, 'api_check_bancontact_permissions' ],
79 'permission_callback' => function () use ($permission) {return $permission ;},
80 'show_in_index' => false
81 ) );
82 register_rest_route( 'payplug_api', '/applepay_permissions/', array(
83 'methods' => 'POST',
84 'callback' => [ $this, 'api_check_applepay_permissions' ],
85 'permission_callback' => function () use ($permission) {return $permission ;},
86 'show_in_index' => false
87 ) );
88 register_rest_route( 'payplug_api', '/american_express_permissions/', array(
89 'methods' => 'POST',
90 'callback' => [ $this, 'api_check_american_express_permissions' ],
91 'permission_callback' => function () use ($permission) {return $permission ;},
92 'show_in_index' => false
93 ) );
94 register_rest_route( 'payplug_api', '/oney_permissions/', array(
95 'methods' => 'POST',
96 'callback' => [ $this, 'api_check_oney_permissions' ],
97 'permission_callback' => function () use ($permission) {return $permission ;},
98 'show_in_index' => false
99 ) );
100 register_rest_route( 'payplug_api', '/one_click_permission/', array(
101 'methods' => 'POST',
102 'callback' => [ $this, 'api_check_one_click_permission' ],
103 'permission_callback' => function () use ($permission) {return $permission ;},
104 'show_in_index' => false
105 ) );
106 register_rest_route( 'payplug_api', '/satispay_permissions/', array(
107 'methods' => 'POST',
108 'callback' => [ $this, 'api_check_satispay_permissions' ],
109 'permission_callback' => function () use ($permission) {return $permission ;},
110 'show_in_index' => false
111 ) );
112 register_rest_route( 'payplug_api', '/mybank_permissions/', array(
113 'methods' => 'POST',
114 'callback' => [ $this, 'api_check_mybank_permissions' ],
115 'permission_callback' => function () use ($permission) {return $permission ;},
116 'show_in_index' => false
117 ) );
118 register_rest_route( 'payplug_api', '/sofort_permissions/', array(
119 'methods' => 'POST',
120 'callback' => [ $this, 'api_check_sofort_permissions' ],
121 'permission_callback' => function () use ($permission) {return $permission ;},
122 'show_in_index' => false
123 ) );
124
125 register_rest_route( 'payplug_api', '/ideal_permissions/', array(
126 'methods' => 'POST',
127 'callback' => [ $this, 'api_check_ideal_permissions' ],
128 'permission_callback' => function () use ($permission) {return $permission ;},
129 'show_in_index' => false
130 ) );
131 register_rest_route( 'payplug_api', '/integrated_permissions/', array(
132 'methods' => 'POST',
133 'callback' => [ $this, 'api_check_integrated_payment' ],
134 'permission_callback' => function () use ($permission) { return $permission ; }
135 ) );
136
137 });
138 }
139
140 public function refresh_keys(WP_REST_Request $request) {
141 $data = $request->get_params();
142 $email = sanitize_text_field( wp_unslash( $data['payplug_email'] ) );
143 $password = base64_decode(wp_unslash($data['payplug_password']));
144
145 if ( empty( $email ) || empty( $password ) ) {
146 wp_send_json_error(
147 array(
148 'message' => __( 'Invalid request.', 'payplug' ),
149 )
150 );
151 }
152
153 if ( ! WC()->payment_gateways() ) {
154 wp_send_json_error(
155 array(
156 'message' => __( 'An error occured with PayPlug gateway. Please make sure PayPlug settings are correct.', 'payplug' ),
157 )
158 );
159 }
160
161 $payment_gateways = WC()->payment_gateways()->payment_gateways();
162 if ( empty( $payment_gateways ) || ! isset( $payment_gateways['payplug'] ) ) {
163 wp_send_json_error(
164 array(
165 'message' => __( 'An error occured with PayPlug gateway. Please make sure PayPlug settings are correct.', 'payplug' ),
166 )
167 );
168 }
169
170 /* @var PayplugGateway $payplug_gateway */
171 $payplug_gateway = $payment_gateways['payplug'];
172 $keys = $payplug_gateway->retrieve_user_api_keys( $email, $password );
173 if ( is_wp_error( $keys ) ) {
174 wp_send_json_error(
175 array(
176 'message' => $keys->get_error_message(),
177 )
178 );
179 }
180
181 $success = $this->update_api_keys( $keys, $payplug_gateway );
182
183 if ( empty( $keys['live'] ) ) {
184 wp_send_json_error(
185 array(
186 'message' => __( 'Your account does not support LIVE mode at the moment, it must be validated first. If your account has already been validated, please log out and log in again.', 'payplug' ),
187 'still_inactive' => true
188 )
189 );
190 }
191
192 if ( ! $success ) {
193 wp_send_json_error(
194 array(
195 'message' => __( 'Something went wrong.', 'payplug' ),
196 )
197 );
198 }
199
200 wp_send_json_success(
201 array(
202 'message' => __( 'Your API keys has successfully been updated.', 'payplug' )
203 )
204 );
205 }
206
207 public function api_check_one_click_permission(WP_REST_Request $request){
208 wp_send_json_success(true);
209 }
210
211 public function api_check_bancontact_permissions(WP_REST_Request $request) {
212 $account = $this->generic_get_account($request, Bancontact::ENABLE_ON_TEST_MODE);
213
214 if(isset($account['httpResponse']['payment_methods']['bancontact']['enabled']) && $account['httpResponse']['payment_methods']['bancontact']['enabled']){
215 wp_send_json_success(true);
216 }
217
218 wp_send_json_error(array(
219 "title" => __( 'payplug_enable_feature', 'payplug' ),
220 "msg" => __( 'payplug_bancontact_access_error', 'payplug' ),
221 "close" => __( 'payplug_ok', 'payplug' )
222 ));
223
224 }
225
226 public function api_check_applepay_permissions(WP_REST_Request $request) {
227 $account = $this->generic_get_account($request, ApplePay::ENABLE_ON_TEST_MODE);
228
229 if ($account['httpResponse']['payment_methods']['apple_pay']['enabled']) {
230 if (in_array(strtr(get_site_url(), array("http://" => "", "https://" => "")), $account['httpResponse']['payment_methods']['apple_pay']['allowed_domain_names'])) {
231 wp_send_json_success(true);
232 }
233
234 }
235
236 wp_send_json_error(array(
237 "title" => __( 'payplug_enable_feature', 'payplug' ),
238 "msg" => __( 'payplug_applepay_access_error', 'payplug' ),
239 "close" => __( 'payplug_ok', 'payplug' )
240 ));
241
242 }
243
244 public function api_check_american_express_permissions(WP_REST_Request $request) {
245 $account = $this->generic_get_account($request, AmericanExpress::ENABLE_ON_TEST_MODE);
246
247 if(isset($account['httpResponse']['payment_methods']['american_express']['enabled']) && $account['httpResponse']['payment_methods']['american_express']['enabled']){
248 wp_send_json_success(true);
249 }
250
251 wp_send_json_error(array(
252 "title" => __( 'payplug_enable_feature', 'payplug' ),
253 "msg" => __( 'payplug_amex_access_error', 'payplug' ),
254 "close" => __( 'payplug_ok', 'payplug' )
255 ));
256
257 }
258
259 public function api_check_oney_permissions(WP_REST_Request $request) {
260 $account = $this->generic_get_account($request, PayplugGatewayOney3x::ENABLE_ON_TEST_MODE);
261
262 if(isset($account['httpResponse']['permissions']['can_use_oney']) && $account['httpResponse']['permissions']['can_use_oney']){
263 wp_send_json_success(true);
264 }
265
266 $oney = isset($account['httpResponse']['permissions']['can_use_oney']) ? $account['httpResponse']['permissions']['can_use_oney']: false;
267
268 if(!$oney){
269 $anchor_text = __( 'payplug_oney_error_link', 'payplug' );
270 $anchor_url = "https://portal.payplug.com/login";
271 $anchor = sprintf( ' <a href="%s" target="_blank">%s</a>', $anchor_url, $anchor_text );
272 $message = __( 'payplug_oney_error_description', 'payplug' ) . $anchor;
273 wp_send_json_error(array(
274 "title" => __( 'payplug_oney_error_title', 'payplug' ),
275 "msg" => $message,
276 "close" => __( 'payplug_ok', 'payplug' )
277 ));
278 }
279
280 wp_send_json_success(true);
281 }
282
283 public function api_check_satispay_permissions(WP_REST_Request $request) {
284 $account = $this->generic_get_account($request, Satispay::ENABLE_ON_TEST_MODE);
285
286 $enabled = isset($account['httpResponse']['payment_methods']['satispay']['enabled']) ? $account['httpResponse']['payment_methods']['satispay']['enabled']: false;
287 if(!$enabled){
288 wp_send_json_error(array(
289 "title" => __( 'payplug_enable_feature', 'payplug' ),
290 "msg" => __( 'payplug_satispay_access_error', 'payplug' ),
291 "close" => __( 'payplug_ok', 'payplug' )
292 ));
293 }
294
295 wp_send_json_success($enabled);
296 }
297
298 public function api_check_mybank_permissions(WP_REST_Request $request) {
299 $account = $this->generic_get_account($request, Mybank::ENABLE_ON_TEST_MODE);
300
301 $enabled = isset($account['httpResponse']['payment_methods']['mybank']['enabled']) ? $account['httpResponse']['payment_methods']['mybank']['enabled']: false;
302 if(!$enabled){
303 wp_send_json_error(array(
304 "title" => __( 'payplug_enable_feature', 'payplug' ),
305 "msg" => __( 'payplug_mybank_access_error', 'payplug' ),
306 "close" => __( 'payplug_ok', 'payplug' )
307 ));
308 }
309
310 wp_send_json_success($enabled);
311 }
312
313 public function api_check_sofort_permissions(WP_REST_Request $request) {
314 $account = $this->generic_get_account($request, Sofort::ENABLE_ON_TEST_MODE);
315
316 $enabled = isset($account['httpResponse']['payment_methods']['sofort']['enabled']) ? $account['httpResponse']['payment_methods']['sofort']['enabled']: false;
317 if(!$enabled){
318 wp_send_json_error(array(
319 "title" => __( 'payplug_enable_feature', 'payplug' ),
320 "msg" => __( 'payplug_sofort_access_error', 'payplug' ),
321 "close" => __( 'payplug_ok', 'payplug' )
322 ));
323 }
324
325 wp_send_json_success($enabled);
326 }
327
328 public function api_check_ideal_permissions(WP_REST_Request $request) {
329 $account = $this->generic_get_account($request, Ideal::ENABLE_ON_TEST_MODE);
330
331 $enabled = isset($account['httpResponse']['payment_methods']['ideal']['enabled']) ? $account['httpResponse']['payment_methods']['ideal']['enabled']: false;
332 if(!$enabled){
333 wp_send_json_error(array(
334 "title" => __( 'payplug_enable_feature', 'payplug' ),
335 "msg" => __( 'payplug_ideal_access_error', 'payplug' ),
336 "close" => __( 'payplug_ok', 'payplug' )
337 ));
338 }
339
340 wp_send_json_success($enabled);
341 }
342
343 private function generic_get_account($request, $enable_on_test_mode){
344
345 $data = $request->get_params();
346
347 if( isset($data['env']) && $data['env'] ) {
348 if($enable_on_test_mode){
349 wp_send_json_success(true);
350 }else{
351 $this->optionUnnavailableInTestMode();
352 }
353 }
354
355 $this->accountIsNotValid();
356
357 $live_key = PayplugWoocommerceHelper::get_live_key();
358 if(empty($live_key)){
359 return false;
360 }
361
362 try{
363 $account = Authentication::getAccount(new Payplug($live_key));
364
365 } catch (PayplugException $e){
366 PayplugGateway::log('Error while saving account : ' . $e->getMessage(), 'error');
367 wp_send_json_error(array(
368 "title" => __( 'payplug_enable_feature', 'payplug' ),
369 "msg" => $e->getMessage(),
370 "close" => __( 'payplug_ok', 'payplug' )
371 ));
372 return false;
373 }
374
375 return $account;
376
377 }
378
379 /**
380 * Update PayPlug api keys
381 *&
382
383 * @param array $keys
384 * @param PayplugGateway $payplug_gateway
385 *
386 * @return bool
387 */
388 protected function update_api_keys( $keys, $payplug_gateway ) {
389 if ( empty( $payplug_gateway->settings ) ) {
390 $payplug_gateway->init_settings();
391 }
392
393 $payplug_gateway->settings['payplug_test_key'] = $keys['test'];
394 $payplug_gateway->settings['payplug_live_key'] = $keys['live'];
395 if ( ! empty( $keys['live'] ) ) {
396 $payplug_gateway->settings['mode'] = 'yes';
397 }
398
399 return update_option(
400 $payplug_gateway->get_option_key(),
401 apply_filters(
402 'woocommerce_settings_api_sanitized_fields_' . $payplug_gateway->id,
403 $payplug_gateway->settings
404 ),
405 'yes'
406 );
407 }
408
409 /**
410 *
411 * Ajax paypal login
412 *
413 * @return JSON
414 */
415 public function payplug_login(WP_REST_Request $request) {
416
417 $data = $request->get_params();
418 $email = sanitize_email($data['payplug_email']);
419 $password = base64_decode(wp_unslash($data['payplug_password']));
420 $wp_nonce = $data['_wpnonce'];
421
422 delete_option( 'woocommerce_payplug_settings' );
423 delete_site_option( 'woocommerce_payplug_settings' );
424
425 try {
426 $response = Authentication::getKeysByLogin($email, $password);
427 if (empty($response) || !isset($response)) {
428 http_response_code(401);
429 return wp_send_json_error(array(
430 'message' => __( 'payplug_error_wrong_credentials.', 'payplug' ),
431 ));
432 }
433 $payplug = new PayplugGateway();
434 $form_fields = $payplug->get_form_fields();
435
436 $api_keys = $payplug->retrieve_user_api_keys($email, $password);
437
438 $merchant_id = isset($api_keys['test']) ? $payplug->retrieve_merchant_id($api_keys['test']) : '';
439
440 foreach ($form_fields as $key => $field) {
441 if (in_array($field['type'], ['title', 'login'])) {
442 continue;
443 }
444
445 switch ($key) {
446 case 'enabled':
447 $val = 'yes';
448 break;
449 case 'mode':
450 $val = 'no';
451 break;
452 case 'payplug_test_key':
453 $val = !empty($api_keys['test']) ? esc_attr($api_keys['test']) : null;
454 break;
455 case 'payplug_live_key':
456 $val = !empty($api_keys['live']) ? esc_attr($api_keys['live']) : null;
457 break;
458 case 'payplug_merchant_id':
459 $val = esc_attr($merchant_id);
460 break;
461 case 'email':
462 $val = esc_html($email);
463 break;
464 default:
465 $val = $payplug->get_option($key);
466 }
467
468 $data[$key] = $val;
469 }
470
471 $payplug->set_post_data($data);
472 update_option(
473 $payplug->get_option_key(),
474 apply_filters('woocommerce_settings_api_sanitized_fields_' . $payplug->id, $data)
475 );
476
477 $user = [
478 "logged" => true,
479 "email" => $email,
480 "mode" => PayplugWoocommerceHelper::check_mode() ? 0 : 1
481 ];
482 $wp = [
483 "WP" => [
484 "_wpnonce" => $wp_nonce,
485 ]
486 ];
487
488 return wp_send_json_success( ["settings" => $user + $wp] + ( new Vue )->init() );
489 } catch (HttpException $e) {
490
491 //TODO:: error handler, Authentication::getPermissionsByLogin comes here
492 http_response_code(401);
493 $error = __("payplug_error_wrong_credentials", "payplug");
494 return wp_send_json_error(array('message' => $error));
495
496 }
497 }
498
499 /**
500 *
501 * Ajax payplug initialisation
502 *
503 * @return JSON
504 */
505 public function payplug_init() {
506
507 $wp_nonce = wp_create_nonce();
508
509 $wp = [
510 "logged" => PayplugWoocommerceHelper::user_logged_in(),
511 "mode" => PayplugWoocommerceHelper::check_mode() ? 0 : 1,
512 "WP" => [
513 "_wpnonce" => $wp_nonce,
514 ]
515 ];
516
517 return wp_send_json_success([
518 "settings" => $wp
519 ] + ( new Vue )->init() );
520
521 }
522
523 /**
524 * @return bool|null
525 */
526 public function payplug_logout() {
527
528 $payplug = new PayplugGateway();
529
530 if (PayplugWoocommerceHelper::payplug_logout($payplug)) {
531 $wp = [
532 "logged" => PayplugWoocommerceHelper::user_logged_in(),
533 "mode" => PayplugWoocommerceHelper::check_mode() ? 0 : 1
534 ];
535
536 http_response_code(200);
537 return wp_send_json_success(array(
538 "message" => __('Successfully logged out.', 'payplug'),
539 "status" => ( new Vue )->payplug_section_status(),
540 "settings" => $wp,
541 "subscribe" => ( new Vue )->payplug_section_subscribe() // When Logging out the Status Block needs to be updated
542 ));
543 } else {
544 http_response_code(400);
545 return wp_send_json_error(__('Already logged out.', 'payplug'));
546 }
547
548 }
549
550
551 private function accountIsNotValid(){
552 $live_key = PayplugWoocommerceHelper::get_live_key();
553 if(empty($live_key)){
554 wp_send_json_error(array(
555 "title" => __( 'payplug_enable_feature', 'payplug' ),
556 "msg" => __('Your account does not support LIVE mode at the moment, it must be validated first. If your account has already been validated, please log out and log in again.', 'payplug'),
557 "close" => __( 'payplug_ok', 'payplug' )
558 ));
559 }
560 }
561
562 private function optionUnnavailableInTestMode(){
563 wp_send_json_error(array(
564 "title" => __( 'payplug_enable_feature', 'payplug' ),
565 "msg" => __( 'payplug_unavailable_testmode_description', 'payplug' )
566 ));
567 }
568
569 /**
570 *
571 * Save data from request
572 *
573 * @return null
574 */
575 public function payplug_save_data( WP_REST_Request $request ) {
576
577 $payplug = new PayplugGateway();
578
579 if ($payplug->user_logged_in()) {
580
581 $data = $request->get_params();
582 $options = get_option('woocommerce_payplug_settings', []);
583
584
585 $options['enabled'] = Validator::enabled($data['payplug_enable']);
586 $options['mode'] = Validator::mode($data['payplug_sandbox']);
587
588 //TODO:: add validation for mode
589 $test_mode = $options['mode'] === 'yes' ? false : true;
590
591 $options['title'] = trim(wp_strip_all_tags($data['standard_payment_title']));
592 $options['description'] = trim(wp_strip_all_tags($data['standard_payment_description']));
593 $options['payment_method'] = (Validator::payment_method($data['payplug_embeded'])) ? $data['payplug_embeded'] : $options['payplug_embeded'];
594 $options['oneclick'] = Validator::oneclick($data['enable_one_click']);
595
596 $options['oney'] = Validator::oney($data['enable_oney']);
597 $options['bancontact'] = Validator::genericPaymentGateway($data['enable_bancontact'], "Bancontact", $test_mode);
598
599 $options['apple_pay'] = Validator::genericPaymentGateway($data['enable_applepay'], "Apple Pay", $test_mode);
600 $options['applepay_carriers'] = (!empty($data['applepay_carriers'])) ? $data['applepay_carriers'] : [];
601 $options['applepay_checkout'] = Validator::genericPaymentGateway($data['enable_applepay_checkout'], "Apple Pay Checkout", $test_mode);
602 $options['applepay_cart'] = Validator::genericPaymentGateway($data['enable_applepay_cart'], "Apple Pay Cart", $test_mode);
603
604 Validator::applePayPaymentGatewayOptions($options['apple_pay'], $data['enable_applepay_cart'], $data['enable_applepay_checkout'], $options['applepay_carriers']);
605 if (($options['apple_pay'] === 'yes') && ($options['applepay_checkout'] === 'no') && ($options['applepay_cart'] === 'no')) {
606 $options['applepay_checkout'] = 'yes';
607 }
608
609
610 $options['american_express'] = Validator::genericPaymentGateway($data['enable_american_express'],"American Express", $test_mode);
611 $options['satispay'] = Validator::genericPaymentGateway($data['enable_satispay'], "Satispay", $test_mode);
612 $options['sofort'] = Validator::genericPaymentGateway($data['enable_sofort'], "Sofort", $test_mode);
613 $options['ideal'] = Validator::genericPaymentGateway($data['enable_ideal'], "iDEAL", $test_mode);
614 $options['mybank'] = Validator::genericPaymentGateway($data['enable_mybank'], "Mybank", $test_mode);
615 $options['oney_type'] = (Validator::oney_type($data['payplug_oney'])) ? $data['payplug_oney'] : 'with_fees';
616 $thresholds = (Validator::oney_thresholds($data['oney_min_amounts'], $data['oney_max_amounts']));
617 $options['oney_thresholds_min'] = $thresholds['min'];
618 $options['oney_thresholds_max'] = $thresholds['max'];
619 $options['oney_product_animation'] = Validator::oney_product_animation($data['enable_oney_product_animation']);
620 $options['debug'] = Validator::debug($data['enable_debug']);
621
622 update_option( 'woocommerce_payplug_settings', apply_filters('woocommerce_settings_api_sanitized_fields_payplug', $options) );
623 http_response_code(200);
624
625 wp_send_json_success( array(
626 "title" => null,
627 "msg" => __( 'payplug_save_success_message', 'payplug' ),
628 "close" => __( 'payplug_ok', 'payplug' )
629 ));
630 } else {
631 http_response_code(403);
632 wp_send_json_error("You are not logged in !");
633 }
634
635
636 }
637
638 public function payplug_check_requirements() {
639 wp_send_json_success(array(
640 "status" => ( new Vue )->payplug_section_status()
641 ));
642 }
643
644 public function api_check_integrated_payment(WP_REST_Request $request)
645 {
646
647 $account = $this->generic_get_account($request, true);
648
649 if( ! isset($account['httpResponse']['permissions']['can_use_integrated_payments'])
650 || ! $account['httpResponse']['permissions']['can_use_integrated_payments'] ) {
651 wp_send_json_error(array(
652 "title" => __( 'payplug_enable_feature', 'payplug' ),
653 "msg" => __( 'payplug_integrated_access_error', 'payplug' ),
654 "close" => __( 'payplug_ok', 'payplug' )
655 ));
656 }
657
658 wp_send_json_success(true);
659 return true;
660
661 }
662 }
663