PluginProbe
PayPlug for WooCommerce (Official) / 2.6.3
PayPlug for WooCommerce (Official) v2.6.3
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 / Vue.php

Vue.php in PayPlug for WooCommerce (Official) 2.6.3, at src/Admin/Vue.php

509 lines 18.3 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
6 use Payplug\PayplugWoocommerce\Admin\Vue\Component;
7 use Payplug\PayplugWoocommerce\Admin\Vue\PaymentMethods;
8 use Payplug\PayplugWoocommerce\Controller\ApplePay;
9 use Payplug\PayplugWoocommerce\Gateway\PayplugGateway;
10 use Payplug\PayplugWoocommerce\Gateway\PayplugGatewayRequirements;
11 use Payplug\PayplugWoocommerce\PayplugWoocommerceHelper;
12
13 /**
14 * PayPlug admin Vue.js dashboard handler.
15 *
16 * @package Payplug\PayplugWoocommerce\Admin
17 */
18 class Vue {
19
20 /**
21 * @return array
22 */
23 public function init() {
24
25 if ( PayplugWoocommerceHelper::user_logged_in() ) {
26 $header = $this->payplug_section_header();
27 $logged = $this->payplug_section_logged();
28 $payplug = (new PayplugGateway());
29
30 //TODO:: use the same get_option everywhere on the BO
31 $payplug_wooc_settings = get_option( 'woocommerce_payplug_settings', [] );
32
33 //TODO:: since we're making the call update all the values
34 if (!empty($payplug_wooc_settings["payplug_live_key"])) {
35 $payplug_wooc_settings['can_use_integrated_payments'] = (new Ajax())->check_integrated_payment( $payplug_wooc_settings["payplug_live_key"] );
36 } else {
37 $payplug_wooc_settings['can_use_integrated_payments'] = false;
38 }
39
40 update_option( 'woocommerce_payplug_settings', apply_filters('woocommerce_settings_api_sanitized_fields_payplug', $payplug_wooc_settings) );
41
42 if ((empty($payplug_wooc_settings['oney_thresholds_default_min'])) && (empty($payplug_wooc_settings['oney_thresholds_default_max']))) {
43
44 $payplug_wooc_settings['oney_thresholds_default_min'] = $payplug->min_oney_price;
45 $payplug_wooc_settings['oney_thresholds_default_max'] = $payplug->max_oney_price;
46
47 update_option( 'woocommerce_payplug_settings', apply_filters('woocommerce_settings_api_sanitized_fields_payplug',$payplug_wooc_settings ) );
48 }
49
50 unset($payplug_wooc_settings["payplug_live_key"]);
51 unset($payplug_wooc_settings["payplug_test_key"]);
52 unset($payplug_wooc_settings["payplug_password"]);
53 unset($payplug_wooc_settings["payplug_merchant_id"]);
54
55 return [
56 "payplug_wooc_settings" => $payplug_wooc_settings,
57 "header" => $header,
58 "login" => $this->payplug_section_login(),
59 "logged" => $logged,
60 "payment_methods" => $this->payplug_section_payment_methods($payplug_wooc_settings),
61 "payment_paylater" => $this->payplug_section_paylater($payplug_wooc_settings),
62 "status" => $this->payplug_section_status($payplug_wooc_settings),
63 "footer" => $this->payplug_section_footer(),
64 ];
65 }
66
67 return [
68 "header" => $this->payplug_section_header(),
69 "login" => $this->payplug_section_login(),
70 "subscribe" => $this->payplug_section_subscribe(),
71 "payment_methods" => $this->payplug_section_payment_methods(),
72 "payment_paylater" => $this->payplug_section_paylater(),
73 "status" => $this->payplug_section_status(),
74 "footer" => $this->payplug_section_footer(),
75 ];
76 }
77
78 /**
79 * @return array
80 */
81 public function payplug_section_logged() {
82
83 $inactive = false;
84 if( empty(PayplugWoocommerceHelper::get_live_key()) ){
85 $inactive = true;
86 }
87
88 return [
89 "title" => __( 'payplug_section_logged_title', 'payplug' ),
90 "descriptions" => [
91 "live" => [
92 "description" => __( 'payplug_section_logged_description', 'payplug' ),
93 "logout" => __( 'payplug_section_logged_logout', 'payplug' ),
94 "mode" => __( 'payplug_section_logged_mode', 'payplug' ),
95 "mode_description" => __( 'payplug_section_logged_live_description', 'payplug' ),
96 "link_learn_more" => [
97 "text" => __( 'payplug_learn_more', 'payplug' ),
98 "url" => __( 'payplug_mode_learn_more_url', 'payplug' ),
99 "target" => "_blank"
100 ],
101 "link_access_portal" => [
102 "text" => __( 'payplug_section_logged_link_access_portal', 'payplug' ),
103 "url" => "https://portal.payplug.com/",
104 "target" => "_blank"
105 ],
106 ],
107 "sandbox" => [
108 "description" => __( 'payplug_section_logged_description', 'payplug' ),
109 "logout" => __( 'payplug_section_logged_logout', 'payplug' ),
110 "mode" => __( 'payplug_section_logged_mode', 'payplug' ),
111 "mode_description" => __( 'payplug_section_logged_test_description', 'payplug' ),
112 "link_learn_more" => [
113 "text" => __( 'payplug_learn_more', 'payplug' ),
114 "url" => __( 'payplug_mode_learn_more_url', 'payplug' ),
115 "target" => "_blank"
116 ],
117 "link_access_portal" => [
118 "text" => __( 'payplug_section_logged_link_access_portal', 'payplug' ),
119 "url" => "https://portal.payplug.com/",
120 "target" => "_blank"
121 ],
122 ]
123 ],
124 "options" => [
125 [
126 "name" => "payplug_sandbox",
127 "label" => "Test",
128 "value" => 1, //test
129 "checked" => !PayplugWoocommerceHelper::check_mode()
130 ],
131 [
132 "name" => "payplug_sandbox",
133 "label" => "Live",
134 "value" => 0, //live
135 "checked" => PayplugWoocommerceHelper::check_mode()
136 ]
137 ],
138 "inactive_modal" => [
139 "inactive" => $inactive,
140 "title" => __( 'payplug_live_mode', 'payplug' ),
141 "description" => __( 'payplug_section_logged_modal_description', 'payplug' ),
142 "password_label" => __( 'payplug_section_login_password_label', 'payplug' ),
143 "cancel" => __( 'payplug_cancel', 'payplug' ),
144 "ok" => __( 'payplug_ok', 'payplug' ),
145 ],
146 "inactive_account" => [
147 "warning" => [
148 "title" => __( 'payplug_inactive_account_warning_title', 'payplug' ),
149 "description" => __( 'payplug_inactive_account_warning_description1', 'payplug' ) .
150 __( 'payplug_inactive_account_warning_description2', 'payplug' ) .
151 __( 'payplug_inactive_account_warning_description3', 'payplug' ),
152 ],
153 "error" => [
154 "title" => __( 'payplug_inactive_account_error_title', 'payplug' ),
155 "description" => __( 'payplug_inactive_account_error_description', 'payplug' ),
156 ]
157 ],
158 ];
159 }
160
161 /**
162 * @return array[]
163 */
164 public function payplug_section_login() {
165
166 $login = [
167 "name" => "generalLogin",
168 "title" => __( 'payplug_section_logged_title', 'payplug' ),
169 "descriptions" => [
170 "live" => [
171 "description" => __( 'payplug_section_login_description', 'payplug' ),
172 "not_registered" => __( 'payplug_section_login_not_registered', 'payplug' ),
173 "connect" => __( 'payplug_section_login_connect', 'payplug' ),
174 "email_label" => __( 'payplug_section_login_email_label', 'payplug' ),
175 "email_placeholder" => __( 'payplug_section_login_email_label', 'payplug' ),
176 "password_label" => __( 'payplug_section_login_password_label', 'payplug' ),
177 "password_placeholder" => __( 'payplug_section_login_password_label', 'payplug' ),
178 "link_forgot_password" => [
179 "text" => __( 'payplug_section_login_forgot_password', 'payplug' ),
180 "url" => "https://portal.payplug.com/forgot_password",
181 "target" => "_blank"
182 ],
183 ],
184 "sandbox" => [
185 "description" => __( 'payplug_section_login_description', 'payplug' ),
186 "not_registered" => __( 'payplug_section_login_not_registered', 'payplug' ),
187 "connect" => __( 'payplug_section_login_connect', 'payplug' ),
188 "email_label" => __( 'payplug_section_login_email_label', 'payplug' ),
189 "email_placeholder" => __( 'payplug_section_login_email_label', 'payplug' ),
190 "password_label" => __( 'payplug_section_login_password_label', 'payplug' ),
191 "password_placeholder" => __( 'payplug_section_login_password_label', 'payplug' ),
192 "link_forgot_password" => [
193 "text" => __( 'payplug_section_login_forgot_password', 'payplug' ),
194 "url" => "https://portal.payplug.com/forgot_password",
195 "target" => "_blank"
196 ],
197 ]
198 ]
199 ];
200
201 return $login;
202 }
203
204 /**
205 * @return array
206 */
207 public function payplug_section_subscribe() {
208 return [
209 "name" => "generalSubscribe",
210 "title" => __( 'payplug_section_logged_title', 'payplug' ),
211 "descriptions" => [
212 "live" => [
213 "description" => __( 'payplug_section_subscribe_description', 'payplug' ),
214 "link_create_account" => [
215 "text" => __( 'payplug_section_subscribe_link_create_account', 'payplug' ),
216 "url" => "https://portal.payplug.com/signup",
217 "target" => "_blank"
218 ],
219 "content_description" => __( 'payplug_section_subscribe_content_description', 'payplug' ),
220 "already_have_account" => __( 'payplug_section_subscribe_already_have_account', 'payplug' ),
221 ],
222 "sandbox" => [
223 "description" => __( 'payplug_section_subscribe_description', 'payplug' ),
224 "link_create_account" => [
225 "text" => __( 'payplug_section_subscribe_link_create_account', 'payplug' ),
226 "url" => "https://portal.payplug.com/signup",
227 "target" => "_blank"
228 ],
229 "content_description" => __( 'payplug_section_subscribe_content_description', 'payplug' ),
230 "already_have_account" => __( 'payplug_section_subscribe_already_have_account', 'payplug' ),
231 ]
232 ]
233 ];
234 }
235
236 /**
237 * @return array
238 */
239 public function payplug_section_header() {
240 $enable = ( !empty( get_option( 'woocommerce_payplug_settings', [] )['enabled'] ) && get_option( 'woocommerce_payplug_settings', [] )['enabled'] === "yes") ? true : false;
241 $enable = $enable && $this->payplug_requirements();
242 $disabled = !$this->payplug_requirements();
243
244 return [
245 "title" => __( 'payplug_section_header_title', 'payplug' ),
246 "descriptions" => [
247 "live" => [
248 "description" => __( 'payplug_section_header_live_description', 'payplug' ),
249 "plugin_version" => PAYPLUG_GATEWAY_VERSION
250 ],
251 "sandbox" => [
252 "description" => __( 'payplug_section_header_test_description', 'payplug' ),
253 "plugin_version" => PAYPLUG_GATEWAY_VERSION
254 ],
255 ],
256 "options" => [
257 "type" => "select",
258 "name" => "payplug_enable",
259 "disabled" => $disabled,
260 "options" => [
261 [
262 "value" => 1,
263 "label" => __( 'payplug_section_header_enable_label', 'payplug' ),
264 "checked" => $enable === true ? true : false
265 ],
266 [
267 "value" => 0,
268 "label" => __( 'payplug_section_header_disable_label', 'payplug' ),
269 "checked" => $enable === false ? true : false
270 ]
271 ]
272 ]
273 ];
274
275 }
276
277 /**
278 * @return array
279 */
280 public function payplug_section_payment_methods($options = array()) {
281
282 $section = [
283 "name" => "paymentMethodsBlock",
284 "title" => __( 'payplug_section_payment_methods_title', 'payplug' ),
285 "descriptions" => [
286 "live" => [
287 "description" => __( 'payplug_section_payment_methods_description', 'payplug' ),
288 ],
289 "sandbox" => [
290 "description" => __( 'payplug_section_payment_methods_description', 'payplug' ),
291 ]
292 ],
293 "options" => [
294 (new PaymentMethods())->payment_method_standard(),
295 PaymentMethods::payment_method_amex(!empty($options) && $options['american_express'] === 'yes'),
296 PaymentMethods::payment_method_applepay(!empty($options) && $options['apple_pay'] === 'yes'),
297 PaymentMethods::payment_method_bancontact(!empty($options) && $options['bancontact'] === 'yes'),
298 PaymentMethods::payment_method_satispay(!empty($options) && $options['satispay'] === 'yes'),
299 PaymentMethods::payment_method_mybank(!empty($options) && $options['mybank'] === 'yes'),
300 PaymentMethods::payment_method_sofort(!empty($options) && $options['sofort'] === 'yes'),
301 PaymentMethods::payment_method_giropay(!empty($options) && $options['giropay'] === 'yes'),
302 PaymentMethods::payment_method_ideal(!empty($options) && $options['ideal'] === 'yes'),
303
304 ]
305 ];
306
307 return $section;
308 }
309
310 /**
311 * @param $active
312 *
313 * @return array
314 */
315 public function payplug_section_paylater($options = array() ) {
316
317 $max = !empty($options['oney_thresholds_max']) ? $options['oney_thresholds_max'] : 3000;
318 $min = !empty($options['oney_thresholds_min']) ? $options['oney_thresholds_min'] : 100;
319 $product_page = !empty($options['oney_product_animation']) && $options['oney_product_animation'] === 'yes' ? true : false;
320
321 $section = [
322 "name" => "paymentMethodsBlock",
323 "title" => __( 'payplug_section_paylater_title', 'payplug' ),
324 "descriptions" => [
325 "live" => [
326 "description" => __( 'payplug_section_paylater_description', 'payplug' ),
327 ],
328 "sandbox" => [
329 "description" => __( 'payplug_section_paylater_description', 'payplug' ),
330 ]
331 ],
332 "options" => [
333 "name" => "oney",
334 "title" => __( 'payplug_section_oney_title', 'payplug' ),
335 "image" => esc_url( PAYPLUG_GATEWAY_PLUGIN_URL . 'assets/images/lg-oney.png' ),
336 "checked" => !empty($options) && $options['oney'] === 'yes',
337 "descriptions" => [
338 "live" => [
339 "description" => __( 'payplug_section_paylater_description_oney', 'payplug' ),
340 "link_know_more" => Component::link(__( 'payplug_know_more_label', 'payplug' ), "https://support.payplug.com/hc/fr/articles/4408142346002", "_blank"),
341 ],
342 "sandbox" => [
343 "description" => __( 'payplug_section_paylater_description_oney', 'payplug' ),
344 "link_know_more" => Component::link(__( 'payplug_know_more_label', 'payplug' ), "https://support.payplug.com/hc/fr/articles/4408142346002", "_blank"),
345 ],
346 "advanced" => [
347 "description" => __( 'payplug_advanced_settings', 'payplug' ),""
348 ]
349 ],
350 "options" => [
351 [
352 "name" => "payplug_oney_type",
353 "className" => "_paylaterLabel",
354 "label" => __( 'payplug_label_with_fees', 'payplug' ),
355 "subText" => __( 'payplug_text_with_fees', 'payplug' ),
356 "value" => "with_fees",
357 "checked" => !empty($options) && $options['oney_type'] === 'with_fees',
358 ],
359 [
360 "name" => "payplug_oney_type",
361 "className" => "_paylaterLabel",
362 "label" => __( 'payplug_label_without_fees', 'payplug' ),
363 "subText" => __( 'payplug_text_without_fees', 'payplug' ),
364 "value" => "without_fees",
365 "checked" => !empty($options) && $options['oney_type'] === 'without_fees',
366 ]
367 ],
368 "advanced_options" => [
369 $this->thresholds_option($max, $min),
370 $this->show_oney_popup_product($product_page)
371 ]
372 ]
373 ];
374
375 return $section;
376 }
377
378 /**
379 * @return array
380 */
381 public function thresholds_option($max, $min) {
382
383 $thresholds = [
384 "name" => "thresholds",
385 "image_url" => esc_url( PAYPLUG_GATEWAY_PLUGIN_URL . 'assets/images/thresholds.svg' ),
386 "title" => __( 'payplug_thresholds_oney_title', 'payplug' ),
387 "descriptions" => [
388 "description" => __( 'payplug_thresholds_oney_description', 'payplug' ),
389 "min_amount" => [
390 "name" => "oney_min_amounts",
391 "value" => $min,
392 "placeholder" => $min,
393 "default" => get_option( 'woocommerce_payplug_settings', [] )['oney_thresholds_default_min']
394 ],
395 "inter" => __( 'and', 'payplug' ),
396 "max_amount" => [
397 "name" => "oney_max_amounts",
398 "value" => $max,
399 "placeholder" => $max,
400 "default" => get_option( 'woocommerce_payplug_settings', [] )['oney_thresholds_default_max']
401 ],
402 "error" => [
403 "text" => __( 'payplug_thresholds_error_msg', 'payplug' ),
404 "maxtext" => __('payplug_thresholds_error_maxtext_msg', 'payplug'),
405 "mintext" => __('payplug_thresholds_error_mintext_msg', 'payplug'),
406 ]
407 ],
408 "switch" => false
409 ];
410
411 return $thresholds;
412 }
413
414 /**
415 * @param $active
416 *
417 * @return array
418 */
419 public function show_oney_popup_product($active = false) {
420 return [
421 "name" => "oney_product_animation",
422 "image_url" => esc_url( PAYPLUG_GATEWAY_PLUGIN_URL . 'assets/images/product.svg' ),
423 "title" => __( 'display_the_oney_installments_pop_up_on_the_product_page', 'payplug' ),
424 "descriptions" => [[
425 "description" => __( 'payplug_oney_product_page_description', 'payplug' ),
426 "link_know_more" => Component::link(__( 'payplug_know_more_label', 'payplug' ), "https://support.payplug.com/hc/fr/articles/4408142346002", "_blank")
427 ]],
428 "switch" => true,
429 "checked" => $active
430 ];
431 }
432
433
434 /**
435 * @return array
436 */
437 public function payplug_section_status( $options = [] ) {
438 $payplug_requirements = new PayplugGatewayRequirements(new PayplugGateway());
439 $checked = !empty($options['debug']) && $options['debug'] === 'yes' ? true : false;
440
441 $status = [
442 "error" => !$this->payplug_requirements(),
443 "title" => __("payplug_section_status_title", "payplug"),
444 "descriptions" => [
445 "live" => [
446 "description" => __("payplug_section_status_description", "payplug"),
447 "errorMessage" => __("payplug_section_status_errorMessage", "payplug"),
448 "check" => __("payplug_section_status_check", "payplug"),
449 "check_success" => __("payplug_section_status_check_success", "payplug"),
450 ],
451 "sandbox" => [
452 "description" => __("payplug_section_status_description", "payplug"),
453 "errorMessage" => __("payplug_section_status_errorMessage", "payplug"),
454 "check" => __("payplug_section_status_check", "payplug"),
455 "check_success" => __("payplug_section_status_check_success", "payplug"),
456 ]
457 ],
458 "requirements" => [
459 $payplug_requirements->curl_requirement(),
460 $payplug_requirements->php_requirement(),
461 $payplug_requirements->openssl_requirement(),
462 $payplug_requirements->currency_requirement(), //MISSING THIS MESSAGES
463 $payplug_requirements->account_requirement(),
464 ],
465 "debug" => [
466 "live" => [
467 "title" => __("payplug_section_status_debug_label", "payplug"),
468 "description" => __("payplug_section_status_debug_description", "payplug"),
469 ],
470 "sandbox" => [
471 "title" => __("payplug_section_status_debug_label", "payplug"),
472 "description" => __("payplug_section_status_debug_description", "payplug"),
473 ]
474 ],
475 "enable_debug_check" => $checked
476 ];
477
478 return $status;
479 }
480
481 /**
482 * check if there's any requirement missing
483 * @return bool
484 */
485 private function payplug_requirements() {
486 $payplug_requirements = new PayplugGatewayRequirements(new PayplugGateway());
487 return $payplug_requirements->satisfy_requirements();
488 }
489
490 /**
491 * @return array
492 */
493 public function payplug_section_footer( ) {
494 return [
495 "save_changes_text" => __("payplug_save_changes_text", "payplug"),
496 "description" => [
497 __("payplug_section_help_description1", "payplug"),
498 __("payplug_section_help_description2", "payplug")
499 ],
500 "link_help" => Component::link(
501 __( 'payplug_section_help_link_help_text', 'payplug' ),
502 __( 'payplug_section_help_link_help_url', 'payplug' ),
503 "_blank"
504 ),
505 ];
506 }
507
508 }
509