PluginProbe
PayPlug for WooCommerce (Official) / 2.18.0
PayPlug for WooCommerce (Official) v2.18.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 / PaymentMethods.php

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

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