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 / Gateway / Blocks / PayplugCreditCard.php

PayplugCreditCard.php in PayPlug for WooCommerce (Official) 2.18.0, at src/Gateway/Blocks/PayplugCreditCard.php

134 lines 6.4 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\Gateway\Blocks;
4
5 use Payplug\PayplugWoocommerce\PayplugWoocommerceHelper;
6
7 class PayplugCreditCard extends PayplugGenericBlock
8 {
9 /**
10 * Payment method name/id/slug.
11 *
12 * @var string
13 */
14 protected $name = 'payplug';
15
16 /**
17 * Returns an associative array of data to be exposed for the payment method's client side.
18 */
19 public function get_payment_method_data()
20 {
21 $data = parent::get_payment_method_data();
22 $data['icon'] = [
23 'src' => ('it_IT' === get_locale()) ?
24 PAYPLUG_GATEWAY_PLUGIN_URL . '/assets/images/checkout/logos_scheme_PostePay.svg' :
25 PAYPLUG_GATEWAY_PLUGIN_URL . '/assets/images/checkout/logos_scheme_CB.svg',
26 'icon_alt' => 'Visa & Mastercard',
27 ];
28 $data['IP'] = false;
29 $data['popup'] = false;
30 $data['payment_method'] = $this->get_name();
31 $data['supports'] = $this->get_supported_features();
32 $data['showSaveOption'] = !empty($this->gateway->save_card) ? $this->gateway->save_card : false;
33 $configuration = $this->get_service('configuration');
34 $embedded_mode = $configuration->get_option('payment_methods.configuration.payplug.embedded_mode');
35 switch ($embedded_mode) {
36 case 'integrated':
37 $data['payplug_integrated_payment_cardHolder_error'] = __('payplug_integrated_payment_cardHolder_error', 'payplug');
38 $data['payplug_integrated_payment_empty'] = __('payplug_integrated_payment_empty', 'payplug');
39 $data['payplug_integrated_payment_your_card'] = __('payplug_integrated_payment_your_card', 'payplug');
40 $data['payplug_integrated_payment_pan_error'] = __('payplug_integrated_payment_pan_error', 'payplug');
41 $data['payplug_integrated_payment_exp_error'] = __('payplug_integrated_payment_exp_error', 'payplug');
42 $data['payplug_integrated_payment_cvv_error'] = __('payplug_integrated_payment_cvv_error', 'payplug');
43 $data['payplug_integrated_payment_error'] = __('payplug_integrated_payment_error', 'payplug');
44 $data['payplug_integrated_payment_transaction_secure'] = __('payplug_integrated_payment_transaction_secure', 'payplug');
45 $data['logo'] = PAYPLUG_GATEWAY_PLUGIN_URL . '/assets/images/integrated/logo-payplug.png';
46 $data['lock'] = PAYPLUG_GATEWAY_PLUGIN_URL . '/assets/images/integrated/lock.svg';
47 $data['payplug_integrated_payment_privacy_policy_url'] = __('payplug_integrated_payment_privacy_policy_url', 'payplug');
48 $data['payplug_integrated_payment_privacy_policy'] = __('payplug_integrated_payment_privacy_policy', 'payplug');
49 $data['payplug_integrated_payment_cardholder'] = __('payplug_integrated_payment_cardholder', 'payplug');
50 $data['payplug_integrated_payment_card_number'] = __('payplug_integrated_payment_card_number', 'payplug');
51 $data['payplug_integrated_payment_expiration_date'] = __('payplug_integrated_payment_expiration_date', 'payplug');
52 $data['payplug_integrated_payment_cvv'] = __('payplug_integrated_payment_cvv', 'payplug');
53 $data['payplug_invalid_form'] = __('payplug_required_fields_error', 'payplug');
54 $data['payplug_create_intent_payment'] = \WC_AJAX::get_endpoint('payplug_create_intent');
55 $data['payplug_integrated_payment_check_payment_url'] = \WC_AJAX::get_endpoint('payplug_check_payment');
56 $data['payplug_integrated_payment_nonce_field'] = wp_nonce_field('woocommerce-process_checkout', 'woocommerce-process-checkout-nonce');
57 $data['wp_nonce'] = wp_create_nonce('woocommerce-process_checkout');
58 $data['mode'] = PayplugWoocommerceHelper::check_mode();
59 $data['IP'] = true;
60 break;
61 case 'popup':
62 $data['popup'] = true;
63 $data['payplug_create_intent_payment'] = \WC_AJAX::get_endpoint('payplug_create_intent');
64 $data['payplug_create_order'] = \WC_AJAX::get_endpoint('payplug_create_order');
65 $data['wp_nonce'] = wp_create_nonce('woocommerce-process_checkout');
66 break;
67 default:
68 break;
69 }
70
71 return $data;
72 }
73
74 /**
75 * Returns an array of scripts/handles to be registered for this payment method.
76 *
77 * @return array
78 */
79 public function get_payment_method_script_handles()
80 {
81 $configuration = $this->get_service('configuration');
82 $embedded_mode = $configuration->get_option('payment_methods.configuration.payplug.embedded_mode');
83 if ('integrated' == $embedded_mode && !is_wc_endpoint_url('order-pay')) {
84 $this->ip_scripts();
85 }
86
87 if ('popup' == $embedded_mode) {
88 $this->popup_scripts();
89 }
90
91 return parent::get_payment_method_script_handles();
92 }
93
94 private function ip_scripts()
95 {
96 wp_enqueue_style('payplugIP', PAYPLUG_GATEWAY_PLUGIN_URL . 'assets/css/payplug-integrated-payments.css', [], PAYPLUG_GATEWAY_VERSION);
97 wp_register_script(
98 'payplug-integrated-payments-api',
99 IP_API,
100 [],
101 'v1.1',
102 true
103 );
104
105 wp_register_script('payplug-domain', PAYPLUG_GATEWAY_PLUGIN_URL . 'assets/js/payplug-domain.js', [], 'v1.0');
106 wp_enqueue_script('payplug-domain');
107
108 wp_enqueue_script('payplug-integrated-payments-api');
109 }
110
111 private function popup_scripts()
112 {
113 wp_register_script('payplug-popup', 'https://api.payplug.com/js/1/form.latest.js', [], null, true);
114 if (isset($_GET['pay_for_order'])) {
115 wp_register_script('payplug-checkout', PAYPLUG_GATEWAY_PLUGIN_URL . 'assets/js/payplug-checkout.js', [
116 'jquery',
117 'payplug-popup',
118 ], PAYPLUG_GATEWAY_VERSION, true);
119 }
120
121 wp_localize_script('payplug-checkout', 'payplug_checkout_params', [
122 'ajax_url' => \WC_AJAX::get_endpoint('payplug_create_order'),
123 'order_review_url' => \WC_AJAX::get_endpoint('payplug_order_review_url'),
124 'nonce' => [
125 'checkout' => wp_create_nonce('woocommerce-process_checkout'),
126 ],
127 'is_embedded' => 'redirect' !== $this->gateway->embedded_mode,
128 ]);
129
130 wp_enqueue_script('payplug-popup');
131 wp_enqueue_script('payplug-checkout');
132 }
133 }
134