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 / Vue.php

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

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