PluginProbe
PayPlug for WooCommerce (Official) / 2.10.0
PayPlug for WooCommerce (Official) v2.10.0
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.10.0, at src/Admin/Vue.php

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