PluginProbe
PayPlug for WooCommerce (Official) / 3.0.0
PayPlug for WooCommerce (Official) v3.0.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) 3.0.0, at src/Gateway/Blocks/PayplugCreditCard.php

142 lines 7.1 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 // Order-pay always has a real, existing order (the one being repaid) - a regular
36 // checkout's order isn't created until the place-order submission itself (see
37 // wc-payplug-integratedPayment-blocks.js / wc-payplug-popup-blocks.js for why that
38 // matters here). Used by both the 'integrated' and 'popup' embedded modes below.
39 $data['is_order_pay'] = is_wc_endpoint_url('order-pay');
40 $data['order_pay_id'] = $data['is_order_pay'] ? (int) get_query_var('order-pay') : 0;
41 $data['order_pay_key'] = $data['is_order_pay'] ? wc_clean(wp_unslash($_GET['key'] ?? '')) : '';
42 switch ($embedded_mode) {
43 case 'integrated':
44 $data['payplug_integrated_payment_cardHolder_error'] = __('payplug_integrated_payment_cardHolder_error', 'payplug');
45 $data['payplug_integrated_payment_empty'] = __('payplug_integrated_payment_empty', 'payplug');
46 $data['payplug_integrated_payment_your_card'] = __('payplug_integrated_payment_your_card', 'payplug');
47 $data['payplug_integrated_payment_pan_error'] = __('payplug_integrated_payment_pan_error', 'payplug');
48 $data['payplug_integrated_payment_exp_error'] = __('payplug_integrated_payment_exp_error', 'payplug');
49 $data['payplug_integrated_payment_cvv_error'] = __('payplug_integrated_payment_cvv_error', 'payplug');
50 $data['payplug_integrated_payment_error'] = __('payplug_integrated_payment_error', 'payplug');
51 $data['payplug_integrated_payment_transaction_secure'] = __('payplug_integrated_payment_transaction_secure', 'payplug');
52 $data['logo'] = PAYPLUG_GATEWAY_PLUGIN_URL . '/assets/images/integrated/logo-payplug.png';
53 $data['lock'] = PAYPLUG_GATEWAY_PLUGIN_URL . '/assets/images/integrated/lock.svg';
54 $data['payplug_integrated_payment_privacy_policy_url'] = __('payplug_integrated_payment_privacy_policy_url', 'payplug');
55 $data['payplug_integrated_payment_privacy_policy'] = __('payplug_integrated_payment_privacy_policy', 'payplug');
56 $data['payplug_integrated_payment_cardholder'] = __('payplug_integrated_payment_cardholder', 'payplug');
57 $data['payplug_integrated_payment_card_number'] = __('payplug_integrated_payment_card_number', 'payplug');
58 $data['payplug_integrated_payment_expiration_date'] = __('payplug_integrated_payment_expiration_date', 'payplug');
59 $data['payplug_integrated_payment_cvv'] = __('payplug_integrated_payment_cvv', 'payplug');
60 $data['payplug_invalid_form'] = __('payplug_required_fields_error', 'payplug');
61 $data['payplug_create_intent_payment'] = \WC_AJAX::get_endpoint('payplug_create_intent');
62 $data['payplug_integrated_payment_check_payment_url'] = \WC_AJAX::get_endpoint('payplug_check_payment');
63 $data['payplug_integrated_payment_nonce_field'] = wp_nonce_field('woocommerce-process_checkout', 'woocommerce-process-checkout-nonce');
64 $data['wp_nonce'] = wp_create_nonce('woocommerce-process_checkout');
65 $data['mode'] = PayplugWoocommerceHelper::check_mode();
66 $data['secureDomain'] = PayplugWoocommerceHelper::get_secure_domain();
67 $data['IP'] = true;
68 break;
69 case 'popup':
70 $data['popup'] = true;
71 $data['payplug_create_intent_payment'] = \WC_AJAX::get_endpoint('payplug_create_intent');
72 $data['payplug_create_order'] = \WC_AJAX::get_endpoint('payplug_create_order');
73 $data['wp_nonce'] = wp_create_nonce('woocommerce-process_checkout');
74 break;
75 default:
76 break;
77 }
78
79 return $data;
80 }
81
82 /**
83 * Returns an array of scripts/handles to be registered for this payment method.
84 *
85 * @return array
86 */
87 public function get_payment_method_script_handles()
88 {
89 $configuration = $this->get_service('configuration');
90 $embedded_mode = $configuration->get_option('payment_methods.configuration.payplug.embedded_mode');
91 if ('integrated' == $embedded_mode && !is_wc_endpoint_url('order-pay')) {
92 $this->ip_scripts();
93 }
94
95 if ('popup' == $embedded_mode) {
96 $this->popup_scripts();
97 }
98
99 return parent::get_payment_method_script_handles();
100 }
101
102 private function ip_scripts(): void
103 {
104 wp_enqueue_style('payplugIP', PAYPLUG_GATEWAY_PLUGIN_URL . 'assets/css/payplug-integrated-payments.css', [], PAYPLUG_GATEWAY_VERSION);
105 wp_register_script(
106 'payplug-integrated-payments-api',
107 IP_API,
108 [],
109 'v1.1',
110 true
111 );
112
113 wp_register_script('payplug-domain', PAYPLUG_GATEWAY_PLUGIN_URL . 'assets/js/payplug-domain.js', [], 'v1.0');
114 wp_enqueue_script('payplug-domain');
115
116 wp_enqueue_script('payplug-integrated-payments-api');
117 }
118
119 private function popup_scripts(): void
120 {
121 wp_register_script('payplug-popup', 'https://api.payplug.com/js/1/form.latest.js', [], null, true);
122 if (isset($_GET['pay_for_order'])) {
123 wp_register_script('payplug-checkout', PAYPLUG_GATEWAY_PLUGIN_URL . 'assets/js/payplug-checkout.js', [
124 'jquery',
125 'payplug-popup',
126 ], PAYPLUG_GATEWAY_VERSION, true);
127 }
128
129 wp_localize_script('payplug-checkout', 'payplug_checkout_params', [
130 'ajax_url' => \WC_AJAX::get_endpoint('payplug_create_order'),
131 'order_review_url' => \WC_AJAX::get_endpoint('payplug_order_review_url'),
132 'nonce' => [
133 'checkout' => wp_create_nonce('woocommerce-process_checkout'),
134 ],
135 'is_embedded' => 'redirect' !== $this->gateway->embedded_mode,
136 ]);
137
138 wp_enqueue_script('payplug-popup');
139 wp_enqueue_script('payplug-checkout');
140 }
141 }
142