PluginProbe
PayPlug for WooCommerce (Official) / 3.1.0
PayPlug for WooCommerce (Official) v3.1.0
3.1.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 All 102 releases
payplug / src / Admin / Vue / PaymentMethods.php

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

627 lines 25.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\Vue;
4
5 use Payplug\PayplugWoocommerce\Gateway\PPRO\Scalapay;
6 use Payplug\PayplugWoocommerce\PayplugWoocommerceHelper;
7 use Payplug\PayplugWoocommerce\Traits\ServiceGetter;
8
9 class PaymentMethods
10 {
11 use ServiceGetter;
12
13 private $configuration;
14
15 public function __construct($options)
16 {
17 $this->configuration = $this->get_service('configuration');
18 }
19
20 /**
21 * @param $active
22 *
23 * @return array
24 */
25 public function payment_method_standard()
26 {
27 $method = [
28 'redirect' => false,
29 'popup' => false,
30 'integrated' => false,
31 ];
32
33 $embedded_mode = $this->configuration->get_option('payment_methods.configuration.payplug.embedded_mode');
34 $method[$embedded_mode] = true;
35
36 $active = $this->configuration->get_option('payment_methods.configuration.payplug.active');
37
38 return [
39 'type' => 'payment_method',
40 'name' => 'standard',
41 'title' => __('payplug_section_standard_payment_title', 'payplug'),
42 'image' => esc_url(PAYPLUG_GATEWAY_PLUGIN_URL . 'assets/images/standard.svg'),
43 'checked' => $active,
44 'available_test_mode' => true,
45 'descriptions' => [
46 'live' => [
47 'description' => __('payplug_section_standard_payment_description', 'payplug'),
48 'advanced_options' => __('payplug_section_standard_payment_advanced_options_label', 'payplug'),
49 ],
50 'sandbox' => [
51 'description' => __('payplug_section_standard_payment_description', 'payplug'),
52 'advanced_options' => __('payplug_section_standard_payment_advanced_options_label', 'payplug'),
53 ],
54 ],
55 'options' => [
56 $this->title_field(),
57 $this->description_field(),
58 $this->embeded_option($method),
59 $this->standard_warning_message(),
60 $this->one_click_option(),
61 ],
62 ];
63 }
64
65 private function description_field()
66 {
67 $description = $this->configuration->get_option('payment_methods.configuration.payplug.description');
68
69 return [
70 'type' => 'payment_option',
71 'sub_type' => 'input',
72 'name' => 'standard_payment_description',
73 'title' => __('payplug_standard_payment_description_title', 'payplug'),
74 'value' => $description,
75 'descriptions' => [
76 'live' => [
77 'description' => __('payplug_standard_payment_description_description', 'payplug'),
78 'placeholder' => __('payplug_standard_payment_description_placeholder', 'payplug'),
79 ],
80 'sandbox' => [
81 'description' => __('payplug_standard_payment_description_description', 'payplug'),
82 'placeholder' => __('payplug_standard_payment_description_placeholder', 'payplug'),
83 ],
84 ],
85 ];
86 }
87
88 private function title_field()
89 {
90 $title = $this->configuration->get_option('payment_methods.configuration.payplug.title');
91 $title = $title ? $title : __('payplug_standard_payment_title_placeholder', 'payplug');
92
93 return [
94 'type' => 'payment_option',
95 'sub_type' => 'input',
96 'name' => 'standard_payment_title',
97 'title' => __('payplug_standard_payment_title_title', 'payplug'),
98 'value' => $title,
99 'descriptions' => [
100 'live' => [
101 'description' => __('payplug_standard_payment_title_description', 'payplug'),
102 'placeholder' => __('payplug_standard_payment_title_placeholder', 'payplug'),
103 ],
104 'sandbox' => [
105 'description' => __('payplug_standard_payment_title_description', 'payplug'),
106 'placeholder' => __('payplug_standard_payment_title_placeholder', 'payplug'),
107 ],
108 ],
109 ];
110 }
111
112 /**
113 * @param $active
114 *
115 * @return array|bool[]|false[]
116 */
117 public function standard_warning_message($active = null)
118 {
119 $arr = [
120 'type' => 'warning_message',
121 'sub_type' => 'warning',
122 'name' => 'warning_message',
123 'payment_method' => 'integrated',
124 'description' => __('payplug_section_standard_ip_warning', 'payplug'),
125 ];
126
127 return $arr;
128 }
129
130 /**
131 * @param $active
132 *
133 * @return array|bool[]|false[]
134 */
135 public function one_click_option($active = null)
136 {
137 $option = [
138 'checked' => $this->configuration->get_option('payment_methods.configuration.payplug.save_card'),
139 'type' => 'payment_option',
140 'sub_type' => 'switch',
141 'name' => 'one_click',
142 'title' => __('payplug_section_one_click_option_title', 'payplug'),
143 'descriptions' => [
144 'live' => [
145 'description' => __('payplug_section_one_click_option_description', 'payplug'),
146 'link_know_more' => Component::link(
147 __('payplug_know_more_label', 'payplug'),
148 'https://support.payplug.com/hc/en-gb/articles/4409698334098',
149 '_blank'
150 ),
151 ],
152 'sandbox' => [
153 'description' => __('payplug_section_one_click_option_description', 'payplug'),
154 'link_know_more' => Component::link(
155 __('payplug_know_more_label', 'payplug'),
156 'https://support.payplug.com/hc/en-gb/articles/4409698334098',
157 '_blank'
158 ),
159 ],
160 ],
161 ];
162
163 return $option;
164 }
165
166 /**
167 * @return array
168 */
169 public function embeded_option($method)
170 {
171 $options = [
172 [
173 'name' => 'payplug_embedded',
174 'label' => __('payplug_section_standard_payment_option_integrated_label', 'payplug'),
175 'value' => 'integrated',
176 'checked' => $method['integrated'],
177 ],
178 [
179 'name' => 'payplug_embedded',
180 'label' => __('payplug_section_standard_payment_option_popup_label', 'payplug'),
181 'value' => 'popup',
182 'checked' => $method['popup'],
183 ],
184 [
185 'name' => 'payplug_embedded',
186 'label' => __('payplug_section_standard_payment_option_redirected_label', 'payplug'),
187 'value' => 'redirect',
188 'checked' => $method['redirect'],
189 ],
190 ];
191
192 return [
193 'type' => 'payment_option',
194 'sub_type' => 'IOptions',
195 'name' => 'embeded',
196 'title' => __('payplug_section_standard_payment_option_title', 'payplug'),
197 'descriptions' => [
198 'live' => [
199 'description_redirect' => __('payplug_section_standard_payment_redirected_description', 'payplug'),
200 'description_popup' => __('payplug_section_standard_payment_popup_description', 'payplug'),
201 'description_integrated' => __('payplug_section_standard_payment_integrated_description', 'payplug'),
202 'link_know_more' => Component::link(
203 __('payplug_know_more_label', 'payplug'),
204 __('payplug_embeded_option_url', 'payplug'),
205 '_blank'
206 ),
207 ],
208 'sandbox' => [
209 'description_redirect' => __('payplug_section_standard_payment_redirected_description', 'payplug'),
210 'description_popup' => __('payplug_section_standard_payment_popup_description', 'payplug'),
211 'description_integrated' => __('payplug_section_standard_payment_integrated_description', 'payplug'),
212 'link_know_more' => Component::link(
213 __('payplug_know_more_label', 'payplug'),
214 __('payplug_embeded_option_url', 'payplug'),
215 '_blank'
216 ),
217 ],
218 ],
219 'options' => $options,
220 ];
221 }
222
223 /**
224 * @param $active
225 *
226 * @return array
227 */
228 public static function payment_method_applepay($active, $options, $carriers = [])
229 {
230 $display = json_decode($options['payment_methods']['configuration']['apple_pay']['display'], true);
231 $checkout = (bool) $display['checkout'];
232 $cart = (bool) $display['cart'];
233 $product = (bool) $display['product'];
234
235 if ($active === true && !$checkout && !$cart) {
236 $checkout = true;
237 }
238
239 return [
240 'type' => 'payment_method',
241 'name' => 'applepay',
242 'title' => __('payplug_section_applepay_payment_title', 'payplug'),
243 'image' => esc_url(PAYPLUG_GATEWAY_PLUGIN_URL . 'assets/images/applepay.svg'),
244 'checked' => $active,
245 'available_test_mode' => false,
246 'descriptions' => [
247 'live' => [
248 'description' => __('payplug_section_applepay_payment_description', 'payplug'),
249 'link_know_more' => Component::link(__('payplug_know_more_label', 'payplug'), __('payplug_applepay_more_url', 'payplug'), '_blank'),
250 ],
251 'sandbox' => [
252 'description' => __('payplug_applepay_unavailable_testmode_description', 'payplug'),
253 'link_know_more' => Component::link(__('payplug_know_more_label', 'payplug'), __('payplug_applepay_more_url', 'payplug'), '_blank'),
254 ],
255 ],
256 'options' =>
257 [
258 [
259 'type' => 'payment_option',
260 'sub_type' => 'IOptions',
261 'name' => 'applepay_display',
262 'title' => __('applepay_display_choice_title', 'payplug'),
263 'options' =>
264 [
265 [
266 'name' => 'applepay_checkout',
267 'title' => __('applepay_display_checkout', 'payplug'),
268 'image_url' => esc_url(PAYPLUG_GATEWAY_PLUGIN_URL . 'assets/images/cart/applepay_checkout.svg'),
269 'label' => __('applepay_display_checkout', 'payplug'),
270 'value' => 'checkout',
271 'switch' => true,
272 'checked' => $checkout || ($active && !$cart),
273 ],
274 [
275 'name' => 'applepay_cart',
276 'title' => __('applepay_display_cart', 'payplug'),
277 'image_url' => esc_url(PAYPLUG_GATEWAY_PLUGIN_URL . 'assets/images/cart/applepay_cart.svg'),
278 'label' => __('applepay_display_cart', 'payplug'),
279 'value' => 'cart',
280 'switch' => true,
281 'checked' => $cart,
282 ],
283 [
284 'name' => 'applepay_product',
285 'title' => __('applepay_display_product', 'payplug'),
286 'image_url' => esc_url(PAYPLUG_GATEWAY_PLUGIN_URL . 'assets/images/cart/applepay_cart.svg'),
287 'label' => __('applepay_display_product', 'payplug'),
288 'value' => 'product',
289 'switch' => true,
290 'checked' => $product,
291 ],
292 ],
293 'carriers' =>
294 [
295 'title' => __('applepay_active_carriers_title', 'payplug'),
296 'alert' => __('applepay_active_carriers_alert', 'payplug'),
297 'descriptions' => [
298 'live' => [
299 'description' => __('applepay_active_carriers_description', 'payplug'),
300 'description_bold' => __('applepay_active_carriers_description_bold', 'payplug'),
301 'description_warning' => __('applepay_active_carriers_description_warning', 'payplug'),
302 ],
303 'sandbox' => [],
304 ],
305 'instructions' => __('applepay_active_carriers_instructions', 'payplug'),
306 'carriers_list' => PayplugWoocommerceHelper::available_shipping_methods($carriers),
307
308 ],
309 ],
310 ],
311 ];
312 }
313
314 /**
315 * @param $active
316 *
317 * @return array
318 */
319 public static function payment_method_bancontact($active = false)
320 {
321 return [
322 'type' => 'payment_method',
323 'name' => 'bancontact',
324 'title' => __('payplug_section_bancontact_payment_title', 'payplug'),
325 'image' => esc_url(PAYPLUG_GATEWAY_PLUGIN_URL . 'assets/images/bancontact.svg'),
326 'checked' => $active,
327 'available_test_mode' => false,
328 'descriptions' => [
329 'live' => [
330 'description' => __('payplug_section_bancontact_payment_description', 'payplug'),
331 'link_know_more' => Component::link(__('payplug_know_more_label', 'payplug'), __('payplug_bancontact_more_url', 'payplug'), '_blank'),
332 ],
333 'sandbox' => [
334 'description' => __('payplug_bancontact_unavailable_testmode_description', 'payplug'),
335 'link_know_more' => Component::link(__('payplug_know_more_label', 'payplug'), __('payplug_bancontact_more_url', 'payplug'), '_blank'),
336 ],
337 ],
338 ];
339 }
340
341 /**
342 * @param $active
343 *
344 * @return array
345 */
346 public static function payment_method_amex($active = false)
347 {
348 return [
349 'type' => 'payment_method',
350 'name' => 'american_express',
351 'title' => __('payplug_section_american_express_payment_title', 'payplug'),
352 'image' => esc_url(PAYPLUG_GATEWAY_PLUGIN_URL . 'assets/images/Amex_logo_color.svg'),
353 'checked' => $active,
354 'available_test_mode' => false,
355 'descriptions' => [
356 'live' => [
357 'description' => __('payplug_section_american_express_payment_description', 'payplug'),
358 'link_know_more' => Component::link(__('payplug_know_more_label', 'payplug'), __('payplug_amex_more_url', 'payplug'), '_blank'),
359 ],
360 'sandbox' => [
361 'description' => __('payplug_amex_unavailable_testmode_description', 'payplug'),
362 'link_know_more' => Component::link(__('payplug_know_more_label', 'payplug'), __('payplug_amex_more_url', 'payplug'), '_blank'),
363 ],
364 ],
365 ];
366 }
367
368 /**
369 * @param $active
370 *
371 * @return array
372 */
373 public static function payment_method_satispay($active = false)
374 {
375 return [
376 'type' => 'payment_method',
377 'name' => 'satispay',
378 'title' => __('payplug_satispay_activate', 'payplug'),
379 'image' => esc_url(PAYPLUG_GATEWAY_PLUGIN_URL . '/assets/images/checkout/satispay.svg'),
380 'checked' => $active,
381 'available_test_mode' => false,
382 'descriptions' => [
383 'live' => [
384 'description' => __('payplug_section_satispay_payment_description', 'payplug'),
385 'link_know_more' => Component::link(__('payplug_know_more_label', 'payplug'), __('payplug_satispay_more_url', 'payplug'), '_blank'),
386 ],
387 'sandbox' => [
388 'description' => __('payplug_satispay_unavailable_testmode_description', 'payplug'),
389 'link_know_more' => Component::link(__('payplug_know_more_label', 'payplug'), __('payplug_satispay_more_url', 'payplug'), '_blank'),
390 ],
391 ],
392 'options' => [
393 self::get_allowed_countries('satispay'),
394 ],
395 ];
396 }
397
398 /**
399 * @param $active
400 *
401 * @return array
402 */
403 public static function payment_method_mybank($active = false)
404 {
405 return [
406 'type' => 'payment_method',
407 'name' => 'mybank',
408 'title' => __('payplug_mybank_activate', 'payplug'),
409 'image' => esc_url(PAYPLUG_GATEWAY_PLUGIN_URL . '/assets/images/checkout/mybank.svg'),
410 'checked' => $active,
411 'available_test_mode' => false,
412 'descriptions' => [
413 'live' => [
414 'description' => __('payplug_section_mybank_payment_description', 'payplug'),
415 'link_know_more' => Component::link(__('payplug_know_more_label', 'payplug'), __('payplug_mybank_more_url', 'payplug'), '_blank'),
416 ],
417 'sandbox' => [
418 'description' => __('payplug_mybank_unavailable_testmode_description', 'payplug'),
419 'link_know_more' => Component::link(__('payplug_know_more_label', 'payplug'), __('payplug_mybank_more_url', 'payplug'), '_blank'),
420 ],
421 ],
422 'options' => [
423 self::get_allowed_countries('mybank'),
424 ],
425 ];
426 }
427
428 /**
429 * @param $active
430 *
431 * @return array
432 */
433 public static function payment_method_ideal($active = false)
434 {
435 return [
436 'type' => 'payment_method',
437 'name' => 'ideal',
438 'title' => __('payplug_ideal_activate', 'payplug'),
439 'image' => esc_url(PAYPLUG_GATEWAY_PLUGIN_URL . '/assets/images/checkout/ideal.svg'),
440 'checked' => $active,
441 'available_test_mode' => false,
442 'descriptions' => [
443 'live' => [
444 'description' => __('payplug_section_ideal_payment_description', 'payplug'),
445 'link_know_more' => Component::link(__('payplug_know_more_label', 'payplug'), __('payplug_ideal_more_url', 'payplug'), '_blank'),
446 ],
447 'sandbox' => [
448 'description' => __('payplug_ideal_unavailable_testmode_description', 'payplug'),
449 'link_know_more' => Component::link(__('payplug_know_more_label', 'payplug'), __('payplug_ideal_more_url', 'payplug'), '_blank'),
450 ],
451 ],
452 'options' => [
453 self::get_allowed_countries('ideal'),
454 ],
455 ];
456 }
457
458 /**
459 * @param $active
460 *
461 * @return array
462 */
463 public static function payment_method_wero($active = false)
464 {
465 return [
466 'type' => 'payment_method',
467 'name' => 'wero',
468 'title' => __('payplug_wero_activate', 'payplug'),
469 'image' => esc_url(PAYPLUG_GATEWAY_PLUGIN_URL . '/assets/images/checkout/wero.svg'),
470 'checked' => $active,
471 'available_test_mode' => false,
472 'descriptions' => [
473 'live' => [
474 'description' => __('payplug_section_wero_payment_description', 'payplug'),
475 'link_know_more' => Component::link(__('payplug_know_more_label', 'payplug'), __('payplug_wero_more_url', 'payplug'), '_blank'),
476 ],
477 'sandbox' => [
478 'description' => __('payplug_wero_unavailable_testmode_description', 'payplug'),
479 'link_know_more' => Component::link(__('payplug_know_more_label', 'payplug'), __('payplug_wero_more_url', 'payplug'), '_blank'),
480 ],
481 ],
482 'options' => [
483 self::get_allowed_countries('wero'),
484 ],
485 ];
486 }
487
488 /**
489 * @param $active
490 *
491 * @return array
492 */
493 public static function payment_method_bizum($active = false)
494 {
495 return [
496 'type' => 'payment_method',
497 'name' => 'bizum',
498 'title' => __('payplug_bizum_activate', 'payplug'),
499 'image' => esc_url(PAYPLUG_GATEWAY_PLUGIN_URL . '/assets/images/checkout/bizum.svg'),
500 'checked' => $active,
501 'available_test_mode' => false,
502 'descriptions' => [
503 'live' => [
504 'description' => __('payplug_section_bizum_payment_description', 'payplug'),
505 'link_know_more' => Component::link(__('payplug_know_more_label', 'payplug'), __('payplug_bizum_more_url', 'payplug'), '_blank'),
506 ],
507 'sandbox' => [
508 'description' => __('payplug_bizum_unavailable_testmode_description', 'payplug'),
509 'link_know_more' => Component::link(__('payplug_know_more_label', 'payplug'), __('payplug_bizum_more_url', 'payplug'), '_blank'),
510 ],
511 ],
512 'options' => [
513 self::get_allowed_countries('bizum'),
514 ],
515 ];
516 }
517
518 /**
519 * @param $active
520 * @param $config payment_methods.configuration.scalapay options (active/custom_amounts/default_amounts)
521 * @param $api_amounts payment_methods.permissions.scalapay.amounts - the account's live PayPlug-authorized
522 * bounds, JSON-encoded {"min":{"EUR":n},"max":{"EUR":n}} (see AccountGateway::map())
523 *
524 * @return array
525 */
526 public static function payment_method_scalapay($active = false, $config = [], $api_amounts = '{}')
527 {
528 return [
529 'type' => 'payment_method',
530 'name' => 'scalapay',
531 'title' => __('payplug_scalapay_activate', 'payplug'),
532 'image' => esc_url(PAYPLUG_GATEWAY_PLUGIN_URL . '/assets/images/checkout/scalapay.svg'),
533 'checked' => $active,
534 'available_test_mode' => false,
535 'descriptions' => [
536 'live' => [
537 'description' => __('payplug_section_scalapay_payment_description', 'payplug'),
538 'link_know_more' => Component::link(__('payplug_know_more_label', 'payplug'), __('payplug_scalapay_more_url', 'payplug'), '_blank'),
539 ],
540 'sandbox' => [
541 'description' => __('payplug_scalapay_unavailable_testmode_description', 'payplug'),
542 'link_know_more' => Component::link(__('payplug_know_more_label', 'payplug'), __('payplug_scalapay_more_url', 'payplug'), '_blank'),
543 ],
544 ],
545 'options' => [
546 self::get_allowed_countries('scalapay'),
547 ],
548 'advanced_options' => [
549 self::scalapay_thresholds_option($config, $api_amounts),
550 ],
551 ];
552 }
553
554 /**
555 * @return array
556 */
557 private static function scalapay_thresholds_option($config, $api_amounts)
558 {
559 // Shared with Scalapay::check_gateway()'s checkout-time enforcement, so the BO
560 // display and the actual gating logic can't silently drift apart.
561 [$min, $max] = Scalapay::effective_bounds($config, $api_amounts);
562
563 // The widget's client-side validation ceiling is always the account's raw
564 // authorized range (matching the save-time validator), not the merchant's own
565 // possibly-narrower custom choice.
566 [$authorized_min, $authorized_max] = Scalapay::authorized_bounds($config, $api_amounts);
567
568 // Convert cents to euros for display
569 $min = $min / 100;
570 $max = $max / 100;
571 $authorized_min = $authorized_min / 100;
572 $authorized_max = $authorized_max / 100;
573
574 return [
575 'name' => 'thresholds',
576 'image_url' => esc_url(PAYPLUG_GATEWAY_PLUGIN_URL . 'assets/images/thresholds.svg'),
577 'title' => __('payplug_thresholds_scalapay_title', 'payplug'),
578 'descriptions' => [
579 'description' => __('payplug_thresholds_scalapay_description', 'payplug'),
580 'min_amount' => [
581 'name' => 'scalapay_min_amounts',
582 'value' => $min,
583 'placeholder' => $min,
584 'default' => $authorized_min,
585 ],
586 'inter' => __('and', 'payplug'),
587 'max_amount' => [
588 'name' => 'scalapay_max_amounts',
589 'value' => $max,
590 'placeholder' => $max,
591 'default' => $authorized_max,
592 ],
593 'error' => [
594 'text' => __('payplug_thresholds_scalapay_error_msg', 'payplug'),
595 'maxtext' => __('payplug_thresholds_scalapay_error_maxtext_msg', 'payplug'),
596 'mintext' => __('payplug_thresholds_scalapay_error_mintext_msg', 'payplug'),
597 ],
598 ],
599 'switch' => false,
600 ];
601 }
602
603 /**
604 * @param $id
605 *
606 * @return false|string
607 */
608 private static function get_allowed_countries($id)
609 {
610 $account = PayplugWoocommerceHelper::get_account_data_from_options();
611
612 if (empty($account['payment_methods'][$id])) {
613 return false;
614 }
615
616 $arr = [
617 'type' => 'info_message',
618 'sub_type' => 'text',
619 'name' => 'allowed_countries',
620 'payment_method' => $id,
621 'description' => trim(sprintf(__('payplug_payment_gateways_country_permissions', 'payplug'), ucfirst($id))) . implode(', ', $account['payment_methods'][$id]['allowed_countries']) . '.',
622 ];
623
624 return $arr;
625 }
626 }
627