@@ -6,7 +6,7 @@ discard block |
||
6 | 6 | * @since 3.1.0 |
7 | 7 | */ |
8 | 8 | |
9 | -if ( ! defined( 'ABSPATH' ) ) { |
|
9 | +if ( ! defined('ABSPATH')) { |
|
10 | 10 | exit; |
11 | 11 | } |
12 | 12 | |
@@ -56,35 +56,35 @@ discard block |
||
56 | 56 | * @version 4.0.0 |
57 | 57 | */ |
58 | 58 | public function __construct() { |
59 | - $this->stripe_settings = get_option( 'woocommerce_stripe_settings', array() ); |
|
60 | - $this->testmode = ( ! empty( $this->stripe_settings['testmode'] ) && 'yes' === $this->stripe_settings['testmode'] ) ? true : false; |
|
61 | - $this->publishable_key = ! empty( $this->stripe_settings['publishable_key'] ) ? $this->stripe_settings['publishable_key'] : ''; |
|
62 | - $this->stripe_checkout_enabled = isset( $this->stripe_settings['stripe_checkout'] ) && 'yes' === $this->stripe_settings['stripe_checkout']; |
|
63 | - $this->total_label = ! empty( $this->stripe_settings['statement_descriptor'] ) ? WC_Stripe_Helper::clean_statement_descriptor( $this->stripe_settings['statement_descriptor'] ) : ''; |
|
64 | - |
|
65 | - if ( $this->testmode ) { |
|
66 | - $this->publishable_key = ! empty( $this->stripe_settings['test_publishable_key'] ) ? $this->stripe_settings['test_publishable_key'] : ''; |
|
59 | + $this->stripe_settings = get_option('woocommerce_stripe_settings', array()); |
|
60 | + $this->testmode = ( ! empty($this->stripe_settings['testmode']) && 'yes' === $this->stripe_settings['testmode']) ? true : false; |
|
61 | + $this->publishable_key = ! empty($this->stripe_settings['publishable_key']) ? $this->stripe_settings['publishable_key'] : ''; |
|
62 | + $this->stripe_checkout_enabled = isset($this->stripe_settings['stripe_checkout']) && 'yes' === $this->stripe_settings['stripe_checkout']; |
|
63 | + $this->total_label = ! empty($this->stripe_settings['statement_descriptor']) ? WC_Stripe_Helper::clean_statement_descriptor($this->stripe_settings['statement_descriptor']) : ''; |
|
64 | + |
|
65 | + if ($this->testmode) { |
|
66 | + $this->publishable_key = ! empty($this->stripe_settings['test_publishable_key']) ? $this->stripe_settings['test_publishable_key'] : ''; |
|
67 | 67 | } |
68 | 68 | |
69 | 69 | // If both site title and statement descriptor is not set. Fallback. |
70 | - if ( empty( $this->total_label ) ) { |
|
70 | + if (empty($this->total_label)) { |
|
71 | 71 | $this->total_label = $_SERVER['SERVER_NAME']; |
72 | 72 | } |
73 | 73 | |
74 | - $this->total_label = str_replace( "'", '', $this->total_label ) . apply_filters( 'wc_stripe_payment_request_total_label_suffix', ' (via WooCommerce)' ); |
|
74 | + $this->total_label = str_replace("'", '', $this->total_label) . apply_filters('wc_stripe_payment_request_total_label_suffix', ' (via WooCommerce)'); |
|
75 | 75 | |
76 | 76 | // Checks if Stripe Gateway is enabled. |
77 | - if ( empty( $this->stripe_settings ) || ( isset( $this->stripe_settings['enabled'] ) && 'yes' !== $this->stripe_settings['enabled'] ) ) { |
|
77 | + if (empty($this->stripe_settings) || (isset($this->stripe_settings['enabled']) && 'yes' !== $this->stripe_settings['enabled'])) { |
|
78 | 78 | return; |
79 | 79 | } |
80 | 80 | |
81 | 81 | // Checks if Payment Request is enabled. |
82 | - if ( ! isset( $this->stripe_settings['payment_request'] ) || 'yes' !== $this->stripe_settings['payment_request'] ) { |
|
82 | + if ( ! isset($this->stripe_settings['payment_request']) || 'yes' !== $this->stripe_settings['payment_request']) { |
|
83 | 83 | return; |
84 | 84 | } |
85 | 85 | |
86 | 86 | // Don't load for change payment method page. |
87 | - if ( isset( $_GET['change_payment_method'] ) ) { |
|
87 | + if (isset($_GET['change_payment_method'])) { |
|
88 | 88 | return; |
89 | 89 | } |
90 | 90 | |
@@ -98,41 +98,41 @@ discard block |
||
98 | 98 | * @version 4.0.0 |
99 | 99 | */ |
100 | 100 | protected function init() { |
101 | - add_action( 'wp_enqueue_scripts', array( $this, 'scripts' ) ); |
|
102 | - add_action( 'wp', array( $this, 'set_session' ) ); |
|
101 | + add_action('wp_enqueue_scripts', array($this, 'scripts')); |
|
102 | + add_action('wp', array($this, 'set_session')); |
|
103 | 103 | |
104 | 104 | /* |
105 | 105 | * In order to display the Payment Request button in the correct position, |
106 | 106 | * a new hook was added to WooCommerce 3.0. In older versions of WooCommerce, |
107 | 107 | * CSS is used to position the button. |
108 | 108 | */ |
109 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
110 | - add_action( 'woocommerce_after_add_to_cart_button', array( $this, 'display_payment_request_button_html' ), 1 ); |
|
111 | - add_action( 'woocommerce_after_add_to_cart_button', array( $this, 'display_payment_request_button_separator_html' ), 2 ); |
|
109 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
110 | + add_action('woocommerce_after_add_to_cart_button', array($this, 'display_payment_request_button_html'), 1); |
|
111 | + add_action('woocommerce_after_add_to_cart_button', array($this, 'display_payment_request_button_separator_html'), 2); |
|
112 | 112 | } else { |
113 | - add_action( 'woocommerce_after_add_to_cart_quantity', array( $this, 'display_payment_request_button_html' ), 1 ); |
|
114 | - add_action( 'woocommerce_after_add_to_cart_quantity', array( $this, 'display_payment_request_button_separator_html' ), 2 ); |
|
113 | + add_action('woocommerce_after_add_to_cart_quantity', array($this, 'display_payment_request_button_html'), 1); |
|
114 | + add_action('woocommerce_after_add_to_cart_quantity', array($this, 'display_payment_request_button_separator_html'), 2); |
|
115 | 115 | } |
116 | 116 | |
117 | - add_action( 'woocommerce_proceed_to_checkout', array( $this, 'display_payment_request_button_html' ), 1 ); |
|
118 | - add_action( 'woocommerce_proceed_to_checkout', array( $this, 'display_payment_request_button_separator_html' ), 2 ); |
|
117 | + add_action('woocommerce_proceed_to_checkout', array($this, 'display_payment_request_button_html'), 1); |
|
118 | + add_action('woocommerce_proceed_to_checkout', array($this, 'display_payment_request_button_separator_html'), 2); |
|
119 | 119 | |
120 | - add_action( 'woocommerce_checkout_before_customer_details', array( $this, 'display_payment_request_button_html' ), 1 ); |
|
121 | - add_action( 'woocommerce_checkout_before_customer_details', array( $this, 'display_payment_request_button_separator_html' ), 2 ); |
|
120 | + add_action('woocommerce_checkout_before_customer_details', array($this, 'display_payment_request_button_html'), 1); |
|
121 | + add_action('woocommerce_checkout_before_customer_details', array($this, 'display_payment_request_button_separator_html'), 2); |
|
122 | 122 | |
123 | - add_action( 'wc_ajax_wc_stripe_get_cart_details', array( $this, 'ajax_get_cart_details' ) ); |
|
124 | - add_action( 'wc_ajax_wc_stripe_get_shipping_options', array( $this, 'ajax_get_shipping_options' ) ); |
|
125 | - add_action( 'wc_ajax_wc_stripe_update_shipping_method', array( $this, 'ajax_update_shipping_method' ) ); |
|
126 | - add_action( 'wc_ajax_wc_stripe_create_order', array( $this, 'ajax_create_order' ) ); |
|
127 | - add_action( 'wc_ajax_wc_stripe_add_to_cart', array( $this, 'ajax_add_to_cart' ) ); |
|
128 | - add_action( 'wc_ajax_wc_stripe_get_selected_product_data', array( $this, 'ajax_get_selected_product_data' ) ); |
|
129 | - add_action( 'wc_ajax_wc_stripe_clear_cart', array( $this, 'ajax_clear_cart' ) ); |
|
130 | - add_action( 'wc_ajax_wc_stripe_log_errors', array( $this, 'ajax_log_errors' ) ); |
|
123 | + add_action('wc_ajax_wc_stripe_get_cart_details', array($this, 'ajax_get_cart_details')); |
|
124 | + add_action('wc_ajax_wc_stripe_get_shipping_options', array($this, 'ajax_get_shipping_options')); |
|
125 | + add_action('wc_ajax_wc_stripe_update_shipping_method', array($this, 'ajax_update_shipping_method')); |
|
126 | + add_action('wc_ajax_wc_stripe_create_order', array($this, 'ajax_create_order')); |
|
127 | + add_action('wc_ajax_wc_stripe_add_to_cart', array($this, 'ajax_add_to_cart')); |
|
128 | + add_action('wc_ajax_wc_stripe_get_selected_product_data', array($this, 'ajax_get_selected_product_data')); |
|
129 | + add_action('wc_ajax_wc_stripe_clear_cart', array($this, 'ajax_clear_cart')); |
|
130 | + add_action('wc_ajax_wc_stripe_log_errors', array($this, 'ajax_log_errors')); |
|
131 | 131 | |
132 | - add_filter( 'woocommerce_gateway_title', array( $this, 'filter_gateway_title' ), 10, 2 ); |
|
133 | - add_filter( 'woocommerce_validate_postcode', array( $this, 'postal_code_validation' ), 10, 3 ); |
|
132 | + add_filter('woocommerce_gateway_title', array($this, 'filter_gateway_title'), 10, 2); |
|
133 | + add_filter('woocommerce_validate_postcode', array($this, 'postal_code_validation'), 10, 3); |
|
134 | 134 | |
135 | - add_action( 'woocommerce_checkout_order_processed', array( $this, 'add_order_meta' ), 10, 3 ); |
|
135 | + add_action('woocommerce_checkout_order_processed', array($this, 'add_order_meta'), 10, 3); |
|
136 | 136 | } |
137 | 137 | |
138 | 138 | /** |
@@ -142,11 +142,11 @@ discard block |
||
142 | 142 | * @since 4.0.0 |
143 | 143 | */ |
144 | 144 | public function set_session() { |
145 | - if ( ! is_user_logged_in() ) { |
|
145 | + if ( ! is_user_logged_in()) { |
|
146 | 146 | $wc_session = new WC_Session_Handler(); |
147 | 147 | |
148 | - if ( ! $wc_session->has_session() ) { |
|
149 | - $wc_session->set_customer_session_cookie( true ); |
|
148 | + if ( ! $wc_session->has_session()) { |
|
149 | + $wc_session->set_customer_session_cookie(true); |
|
150 | 150 | } |
151 | 151 | } |
152 | 152 | } |
@@ -159,7 +159,7 @@ discard block |
||
159 | 159 | * @return string |
160 | 160 | */ |
161 | 161 | public function get_button_type() { |
162 | - return isset( $this->stripe_settings['payment_request_button_type'] ) ? $this->stripe_settings['payment_request_button_type'] : 'default'; |
|
162 | + return isset($this->stripe_settings['payment_request_button_type']) ? $this->stripe_settings['payment_request_button_type'] : 'default'; |
|
163 | 163 | } |
164 | 164 | |
165 | 165 | /** |
@@ -170,7 +170,7 @@ discard block |
||
170 | 170 | * @return string |
171 | 171 | */ |
172 | 172 | public function get_button_theme() { |
173 | - return isset( $this->stripe_settings['payment_request_button_theme'] ) ? $this->stripe_settings['payment_request_button_theme'] : 'dark'; |
|
173 | + return isset($this->stripe_settings['payment_request_button_theme']) ? $this->stripe_settings['payment_request_button_theme'] : 'dark'; |
|
174 | 174 | } |
175 | 175 | |
176 | 176 | /** |
@@ -181,7 +181,7 @@ discard block |
||
181 | 181 | * @return string |
182 | 182 | */ |
183 | 183 | public function get_button_height() { |
184 | - return isset( $this->stripe_settings['payment_request_button_height'] ) ? str_replace( 'px', '', $this->stripe_settings['payment_request_button_height'] ) : '64'; |
|
184 | + return isset($this->stripe_settings['payment_request_button_height']) ? str_replace('px', '', $this->stripe_settings['payment_request_button_height']) : '64'; |
|
185 | 185 | } |
186 | 186 | |
187 | 187 | /** |
@@ -191,40 +191,40 @@ discard block |
||
191 | 191 | * @version 4.0.0 |
192 | 192 | */ |
193 | 193 | public function get_product_data() { |
194 | - if ( ! is_product() ) { |
|
194 | + if ( ! is_product()) { |
|
195 | 195 | return false; |
196 | 196 | } |
197 | 197 | |
198 | 198 | global $post; |
199 | 199 | |
200 | - $product = wc_get_product( $post->ID ); |
|
200 | + $product = wc_get_product($post->ID); |
|
201 | 201 | |
202 | 202 | $data = array(); |
203 | 203 | $items = array(); |
204 | 204 | |
205 | 205 | $items[] = array( |
206 | 206 | 'label' => WC_Stripe_Helper::is_pre_30() ? $product->name : $product->get_name(), |
207 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( WC_Stripe_Helper::is_pre_30() ? $product->price : $product->get_price() ), |
|
207 | + 'amount' => WC_Stripe_Helper::get_stripe_amount(WC_Stripe_Helper::is_pre_30() ? $product->price : $product->get_price()), |
|
208 | 208 | ); |
209 | 209 | |
210 | - if ( wc_tax_enabled() ) { |
|
210 | + if (wc_tax_enabled()) { |
|
211 | 211 | $items[] = array( |
212 | - 'label' => __( 'Tax', 'woocommerce-gateway-stripe' ), |
|
212 | + 'label' => __('Tax', 'woocommerce-gateway-stripe'), |
|
213 | 213 | 'amount' => 0, |
214 | 214 | 'pending' => true, |
215 | 215 | ); |
216 | 216 | } |
217 | 217 | |
218 | - if ( wc_shipping_enabled() && $product->needs_shipping() ) { |
|
218 | + if (wc_shipping_enabled() && $product->needs_shipping()) { |
|
219 | 219 | $items[] = array( |
220 | - 'label' => __( 'Shipping', 'woocommerce-gateway-stripe' ), |
|
220 | + 'label' => __('Shipping', 'woocommerce-gateway-stripe'), |
|
221 | 221 | 'amount' => 0, |
222 | 222 | 'pending' => true, |
223 | 223 | ); |
224 | 224 | |
225 | - $data['shippingOptions'] = array( |
|
225 | + $data['shippingOptions'] = array( |
|
226 | 226 | 'id' => 'pending', |
227 | - 'label' => __( 'Pending', 'woocommerce-gateway-stripe' ), |
|
227 | + 'label' => __('Pending', 'woocommerce-gateway-stripe'), |
|
228 | 228 | 'detail' => '', |
229 | 229 | 'amount' => 0, |
230 | 230 | ); |
@@ -233,40 +233,40 @@ discard block |
||
233 | 233 | $data['displayItems'] = $items; |
234 | 234 | $data['total'] = array( |
235 | 235 | 'label' => $this->total_label, |
236 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( WC_Stripe_Helper::is_pre_30() ? $product->price : $product->get_price() ), |
|
236 | + 'amount' => WC_Stripe_Helper::get_stripe_amount(WC_Stripe_Helper::is_pre_30() ? $product->price : $product->get_price()), |
|
237 | 237 | 'pending' => true, |
238 | 238 | ); |
239 | 239 | |
240 | - $data['requestShipping'] = ( wc_shipping_enabled() && $product->needs_shipping() ); |
|
241 | - $data['currency'] = strtolower( get_woocommerce_currency() ); |
|
242 | - $data['country_code'] = substr( get_option( 'woocommerce_default_country' ), 0, 2 ); |
|
240 | + $data['requestShipping'] = (wc_shipping_enabled() && $product->needs_shipping()); |
|
241 | + $data['currency'] = strtolower(get_woocommerce_currency()); |
|
242 | + $data['country_code'] = substr(get_option('woocommerce_default_country'), 0, 2); |
|
243 | 243 | |
244 | - return apply_filters( 'wc_stripe_payment_request_product_data', $data, $product ); |
|
244 | + return apply_filters('wc_stripe_payment_request_product_data', $data, $product); |
|
245 | 245 | } |
246 | 246 | |
247 | 247 | /** |
248 | 248 | * Filters the gateway title to reflect Payment Request type |
249 | 249 | * |
250 | 250 | */ |
251 | - public function filter_gateway_title( $title, $id ) { |
|
251 | + public function filter_gateway_title($title, $id) { |
|
252 | 252 | global $post; |
253 | 253 | |
254 | - if ( ! is_object( $post ) ) { |
|
254 | + if ( ! is_object($post)) { |
|
255 | 255 | return $title; |
256 | 256 | } |
257 | 257 | |
258 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
259 | - $method_title = get_post_meta( $post->ID, '_payment_method_title', true ); |
|
258 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
259 | + $method_title = get_post_meta($post->ID, '_payment_method_title', true); |
|
260 | 260 | } else { |
261 | - $order = wc_get_order( $post->ID ); |
|
262 | - $method_title = is_object( $order ) ? $order->get_payment_method_title() : ''; |
|
261 | + $order = wc_get_order($post->ID); |
|
262 | + $method_title = is_object($order) ? $order->get_payment_method_title() : ''; |
|
263 | 263 | } |
264 | 264 | |
265 | - if ( 'stripe' === $id && ! empty( $method_title ) && 'Apple Pay (Stripe)' === $method_title ) { |
|
265 | + if ('stripe' === $id && ! empty($method_title) && 'Apple Pay (Stripe)' === $method_title) { |
|
266 | 266 | return $method_title; |
267 | 267 | } |
268 | 268 | |
269 | - if ( 'stripe' === $id && ! empty( $method_title ) && 'Chrome Payment Request (Stripe)' === $method_title ) { |
|
269 | + if ('stripe' === $id && ! empty($method_title) && 'Chrome Payment Request (Stripe)' === $method_title) { |
|
270 | 270 | return $method_title; |
271 | 271 | } |
272 | 272 | |
@@ -279,16 +279,16 @@ discard block |
||
279 | 279 | * @since 3.1.4 |
280 | 280 | * @version 4.0.0 |
281 | 281 | */ |
282 | - public function postal_code_validation( $valid, $postcode, $country ) { |
|
282 | + public function postal_code_validation($valid, $postcode, $country) { |
|
283 | 283 | $gateways = WC()->payment_gateways->get_available_payment_gateways(); |
284 | 284 | |
285 | - if ( ! isset( $gateways['stripe'] ) ) { |
|
285 | + if ( ! isset($gateways['stripe'])) { |
|
286 | 286 | return $valid; |
287 | 287 | } |
288 | 288 | |
289 | - $payment_request_type = wc_clean( $_POST['payment_request_type'] ); |
|
289 | + $payment_request_type = wc_clean($_POST['payment_request_type']); |
|
290 | 290 | |
291 | - if ( 'apple_pay' !== $payment_request_type ) { |
|
291 | + if ('apple_pay' !== $payment_request_type) { |
|
292 | 292 | return $valid; |
293 | 293 | } |
294 | 294 | |
@@ -298,7 +298,7 @@ discard block |
||
298 | 298 | * the order and not let it go through. The remedy for now is just to remove this validation. |
299 | 299 | * Note that this only works with shipping providers that don't validate full postal codes. |
300 | 300 | */ |
301 | - if ( 'GB' === $country || 'CA' === $country ) { |
|
301 | + if ('GB' === $country || 'CA' === $country) { |
|
302 | 302 | return true; |
303 | 303 | } |
304 | 304 | |
@@ -314,27 +314,27 @@ discard block |
||
314 | 314 | * @param array $posted_data The posted data from checkout form. |
315 | 315 | * @param object $order |
316 | 316 | */ |
317 | - public function add_order_meta( $order_id, $posted_data, $order ) { |
|
318 | - if ( empty( $_POST['payment_request_type'] ) ) { |
|
317 | + public function add_order_meta($order_id, $posted_data, $order) { |
|
318 | + if (empty($_POST['payment_request_type'])) { |
|
319 | 319 | return; |
320 | 320 | } |
321 | 321 | |
322 | - $payment_request_type = wc_clean( $_POST['payment_request_type'] ); |
|
322 | + $payment_request_type = wc_clean($_POST['payment_request_type']); |
|
323 | 323 | |
324 | - if ( 'apple_pay' === $payment_request_type ) { |
|
325 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
326 | - update_post_meta( $order_id, '_payment_method_title', 'Apple Pay (Stripe)' ); |
|
324 | + if ('apple_pay' === $payment_request_type) { |
|
325 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
326 | + update_post_meta($order_id, '_payment_method_title', 'Apple Pay (Stripe)'); |
|
327 | 327 | } else { |
328 | - $order->set_payment_method_title( 'Apple Pay (Stripe)' ); |
|
328 | + $order->set_payment_method_title('Apple Pay (Stripe)'); |
|
329 | 329 | $order->save(); |
330 | 330 | } |
331 | 331 | } |
332 | 332 | |
333 | - if ( 'payment_request_api' === $payment_request_type ) { |
|
334 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
335 | - update_post_meta( $order_id, '_payment_method_title', 'Chrome Payment Request (Stripe)' ); |
|
333 | + if ('payment_request_api' === $payment_request_type) { |
|
334 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
335 | + update_post_meta($order_id, '_payment_method_title', 'Chrome Payment Request (Stripe)'); |
|
336 | 336 | } else { |
337 | - $order->set_payment_method_title( 'Chrome Payment Request (Stripe)' ); |
|
337 | + $order->set_payment_method_title('Chrome Payment Request (Stripe)'); |
|
338 | 338 | $order->save(); |
339 | 339 | } |
340 | 340 | } |
@@ -348,11 +348,11 @@ discard block |
||
348 | 348 | * @return array |
349 | 349 | */ |
350 | 350 | public function supported_product_types() { |
351 | - return apply_filters( 'wc_stripe_payment_request_supported_types', array( |
|
351 | + return apply_filters('wc_stripe_payment_request_supported_types', array( |
|
352 | 352 | 'simple', |
353 | 353 | 'variable', |
354 | 354 | 'variation', |
355 | - ) ); |
|
355 | + )); |
|
356 | 356 | } |
357 | 357 | |
358 | 358 | /** |
@@ -363,15 +363,15 @@ discard block |
||
363 | 363 | * @return bool |
364 | 364 | */ |
365 | 365 | public function allowed_items_in_cart() { |
366 | - foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) { |
|
367 | - $_product = apply_filters( 'woocommerce_cart_item_product', $cart_item['data'], $cart_item, $cart_item_key ); |
|
366 | + foreach (WC()->cart->get_cart() as $cart_item_key => $cart_item) { |
|
367 | + $_product = apply_filters('woocommerce_cart_item_product', $cart_item['data'], $cart_item, $cart_item_key); |
|
368 | 368 | |
369 | - if ( ! in_array( ( WC_Stripe_Helper::is_pre_30() ? $_product->product_type : $_product->get_type() ), $this->supported_product_types() ) ) { |
|
369 | + if ( ! in_array((WC_Stripe_Helper::is_pre_30() ? $_product->product_type : $_product->get_type()), $this->supported_product_types())) { |
|
370 | 370 | return false; |
371 | 371 | } |
372 | 372 | |
373 | 373 | // Pre Orders compatbility where we don't support charge upon release. |
374 | - if ( class_exists( 'WC_Pre_Orders_Order' ) && WC_Pre_Orders_Cart::cart_contains_pre_order() && WC_Pre_Orders_Product::product_is_charged_upon_release( WC_Pre_Orders_Cart::get_pre_order_product() ) ) { |
|
374 | + if (class_exists('WC_Pre_Orders_Order') && WC_Pre_Orders_Cart::cart_contains_pre_order() && WC_Pre_Orders_Product::product_is_charged_upon_release(WC_Pre_Orders_Cart::get_pre_order_product())) { |
|
375 | 375 | return false; |
376 | 376 | } |
377 | 377 | } |
@@ -386,71 +386,71 @@ discard block |
||
386 | 386 | * @version 4.0.0 |
387 | 387 | */ |
388 | 388 | public function scripts() { |
389 | - if ( ! is_product() && ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) ) { |
|
389 | + if ( ! is_product() && ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order'])) { |
|
390 | 390 | return; |
391 | 391 | } |
392 | 392 | |
393 | - if ( is_product() ) { |
|
393 | + if (is_product()) { |
|
394 | 394 | global $post; |
395 | 395 | |
396 | - $product = wc_get_product( $post->ID ); |
|
396 | + $product = wc_get_product($post->ID); |
|
397 | 397 | |
398 | - if ( ! is_object( $product ) || ! in_array( ( WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type() ), $this->supported_product_types() ) ) { |
|
398 | + if ( ! is_object($product) || ! in_array((WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type()), $this->supported_product_types())) { |
|
399 | 399 | return; |
400 | 400 | } |
401 | 401 | |
402 | - if ( apply_filters( 'wc_stripe_hide_payment_request_on_product_page', false ) ) { |
|
402 | + if (apply_filters('wc_stripe_hide_payment_request_on_product_page', false)) { |
|
403 | 403 | return; |
404 | 404 | } |
405 | 405 | } |
406 | 406 | |
407 | - $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
407 | + $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; |
|
408 | 408 | |
409 | - wp_register_script( 'stripe', 'https://js.stripe.com/v3/', '', '3.0', true ); |
|
410 | - wp_register_script( 'wc_stripe_payment_request', plugins_url( 'assets/js/stripe-payment-request' . $suffix . '.js', WC_STRIPE_MAIN_FILE ), array( 'jquery', 'stripe' ), WC_STRIPE_VERSION, true ); |
|
409 | + wp_register_script('stripe', 'https://js.stripe.com/v3/', '', '3.0', true); |
|
410 | + wp_register_script('wc_stripe_payment_request', plugins_url('assets/js/stripe-payment-request' . $suffix . '.js', WC_STRIPE_MAIN_FILE), array('jquery', 'stripe'), WC_STRIPE_VERSION, true); |
|
411 | 411 | |
412 | 412 | wp_localize_script( |
413 | 413 | 'wc_stripe_payment_request', |
414 | 414 | 'wc_stripe_payment_request_params', |
415 | 415 | array( |
416 | - 'ajax_url' => WC_AJAX::get_endpoint( '%%endpoint%%' ), |
|
416 | + 'ajax_url' => WC_AJAX::get_endpoint('%%endpoint%%'), |
|
417 | 417 | 'stripe' => array( |
418 | 418 | 'key' => $this->publishable_key, |
419 | - 'allow_prepaid_card' => apply_filters( 'wc_stripe_allow_prepaid_card', true ) ? 'yes' : 'no', |
|
419 | + 'allow_prepaid_card' => apply_filters('wc_stripe_allow_prepaid_card', true) ? 'yes' : 'no', |
|
420 | 420 | ), |
421 | 421 | 'nonce' => array( |
422 | - 'payment' => wp_create_nonce( 'wc-stripe-payment-request' ), |
|
423 | - 'shipping' => wp_create_nonce( 'wc-stripe-payment-request-shipping' ), |
|
424 | - 'update_shipping' => wp_create_nonce( 'wc-stripe-update-shipping-method' ), |
|
425 | - 'checkout' => wp_create_nonce( 'woocommerce-process_checkout' ), |
|
426 | - 'add_to_cart' => wp_create_nonce( 'wc-stripe-add-to-cart' ), |
|
427 | - 'get_selected_product_data' => wp_create_nonce( 'wc-stripe-get-selected-product-data' ), |
|
428 | - 'log_errors' => wp_create_nonce( 'wc-stripe-log-errors' ), |
|
429 | - 'clear_cart' => wp_create_nonce( 'wc-stripe-clear-cart' ), |
|
422 | + 'payment' => wp_create_nonce('wc-stripe-payment-request'), |
|
423 | + 'shipping' => wp_create_nonce('wc-stripe-payment-request-shipping'), |
|
424 | + 'update_shipping' => wp_create_nonce('wc-stripe-update-shipping-method'), |
|
425 | + 'checkout' => wp_create_nonce('woocommerce-process_checkout'), |
|
426 | + 'add_to_cart' => wp_create_nonce('wc-stripe-add-to-cart'), |
|
427 | + 'get_selected_product_data' => wp_create_nonce('wc-stripe-get-selected-product-data'), |
|
428 | + 'log_errors' => wp_create_nonce('wc-stripe-log-errors'), |
|
429 | + 'clear_cart' => wp_create_nonce('wc-stripe-clear-cart'), |
|
430 | 430 | ), |
431 | 431 | 'i18n' => array( |
432 | - 'no_prepaid_card' => __( 'Sorry, we\'re not accepting prepaid cards at this time.', 'woocommerce-gateway-stripe' ), |
|
432 | + 'no_prepaid_card' => __('Sorry, we\'re not accepting prepaid cards at this time.', 'woocommerce-gateway-stripe'), |
|
433 | 433 | /* translators: Do not translate the [option] placeholder */ |
434 | - 'unknown_shipping' => __( 'Unknown shipping option "[option]".', 'woocommerce-gateway-stripe' ), |
|
434 | + 'unknown_shipping' => __('Unknown shipping option "[option]".', 'woocommerce-gateway-stripe'), |
|
435 | 435 | ), |
436 | 436 | 'checkout' => array( |
437 | 437 | 'url' => wc_get_checkout_url(), |
438 | - 'currency_code' => strtolower( get_woocommerce_currency() ), |
|
439 | - 'country_code' => substr( get_option( 'woocommerce_default_country' ), 0, 2 ), |
|
438 | + 'currency_code' => strtolower(get_woocommerce_currency()), |
|
439 | + 'country_code' => substr(get_option('woocommerce_default_country'), 0, 2), |
|
440 | 440 | 'needs_shipping' => WC()->cart->needs_shipping() ? 'yes' : 'no', |
441 | 441 | ), |
442 | 442 | 'button' => array( |
443 | 443 | 'type' => $this->get_button_type(), |
444 | 444 | 'theme' => $this->get_button_theme(), |
445 | 445 | 'height' => $this->get_button_height(), |
446 | - 'locale' => substr( get_locale(), 0, 2 ), // Default format is en_US. |
|
446 | + 'locale' => substr(get_locale(), 0, 2), // Default format is en_US. |
|
447 | 447 | ), |
448 | 448 | 'is_product_page' => is_product(), |
449 | 449 | 'product' => $this->get_product_data(), |
450 | 450 | ) |
451 | 451 | ); |
452 | 452 | |
453 | - wp_enqueue_script( 'wc_stripe_payment_request' ); |
|
453 | + wp_enqueue_script('wc_stripe_payment_request'); |
|
454 | 454 | } |
455 | 455 | |
456 | 456 | /** |
@@ -462,39 +462,39 @@ discard block |
||
462 | 462 | public function display_payment_request_button_html() { |
463 | 463 | $gateways = WC()->payment_gateways->get_available_payment_gateways(); |
464 | 464 | |
465 | - if ( ! isset( $gateways['stripe'] ) ) { |
|
465 | + if ( ! isset($gateways['stripe'])) { |
|
466 | 466 | return; |
467 | 467 | } |
468 | 468 | |
469 | - if ( ! is_cart() && ! is_checkout() && ! is_product() && ! isset( $_GET['pay_for_order'] ) ) { |
|
469 | + if ( ! is_cart() && ! is_checkout() && ! is_product() && ! isset($_GET['pay_for_order'])) { |
|
470 | 470 | return; |
471 | 471 | } |
472 | 472 | |
473 | - if ( is_product() && apply_filters( 'wc_stripe_hide_payment_request_on_product_page', false ) ) { |
|
473 | + if (is_product() && apply_filters('wc_stripe_hide_payment_request_on_product_page', false)) { |
|
474 | 474 | return; |
475 | 475 | } |
476 | 476 | |
477 | - if ( is_checkout() && ! apply_filters( 'wc_stripe_show_payment_request_on_checkout', false ) ) { |
|
477 | + if (is_checkout() && ! apply_filters('wc_stripe_show_payment_request_on_checkout', false)) { |
|
478 | 478 | return; |
479 | 479 | } |
480 | 480 | |
481 | - if ( is_product() ) { |
|
481 | + if (is_product()) { |
|
482 | 482 | global $post; |
483 | 483 | |
484 | - $product = wc_get_product( $post->ID ); |
|
484 | + $product = wc_get_product($post->ID); |
|
485 | 485 | |
486 | - if ( ! is_object( $product ) || ! in_array( ( WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type() ), $this->supported_product_types() ) ) { |
|
486 | + if ( ! is_object($product) || ! in_array((WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type()), $this->supported_product_types())) { |
|
487 | 487 | return; |
488 | 488 | } |
489 | 489 | |
490 | 490 | // Pre Orders charge upon release not supported. |
491 | - if ( class_exists( 'WC_Pre_Orders_Order' ) && WC_Pre_Orders_Product::product_is_charged_upon_release( $product ) ) { |
|
492 | - WC_Stripe_Logger::log( 'Pre Order charge upon release is not supported. ( Payment Request button disabled )' ); |
|
491 | + if (class_exists('WC_Pre_Orders_Order') && WC_Pre_Orders_Product::product_is_charged_upon_release($product)) { |
|
492 | + WC_Stripe_Logger::log('Pre Order charge upon release is not supported. ( Payment Request button disabled )'); |
|
493 | 493 | return; |
494 | 494 | } |
495 | 495 | } else { |
496 | - if ( ! $this->allowed_items_in_cart() ) { |
|
497 | - WC_Stripe_Logger::log( 'Items in the cart has unsupported product type ( Payment Request button disabled )' ); |
|
496 | + if ( ! $this->allowed_items_in_cart()) { |
|
497 | + WC_Stripe_Logger::log('Items in the cart has unsupported product type ( Payment Request button disabled )'); |
|
498 | 498 | return; |
499 | 499 | } |
500 | 500 | } |
@@ -516,44 +516,44 @@ discard block |
||
516 | 516 | public function display_payment_request_button_separator_html() { |
517 | 517 | $gateways = WC()->payment_gateways->get_available_payment_gateways(); |
518 | 518 | |
519 | - if ( ! isset( $gateways['stripe'] ) ) { |
|
519 | + if ( ! isset($gateways['stripe'])) { |
|
520 | 520 | return; |
521 | 521 | } |
522 | 522 | |
523 | - if ( ! is_cart() && ! is_checkout() && ! is_product() && ! isset( $_GET['pay_for_order'] ) ) { |
|
523 | + if ( ! is_cart() && ! is_checkout() && ! is_product() && ! isset($_GET['pay_for_order'])) { |
|
524 | 524 | return; |
525 | 525 | } |
526 | 526 | |
527 | - if ( is_product() && apply_filters( 'wc_stripe_hide_payment_request_on_product_page', false ) ) { |
|
527 | + if (is_product() && apply_filters('wc_stripe_hide_payment_request_on_product_page', false)) { |
|
528 | 528 | return; |
529 | 529 | } |
530 | 530 | |
531 | - if ( is_checkout() && ! apply_filters( 'wc_stripe_show_payment_request_on_checkout', false ) ) { |
|
531 | + if (is_checkout() && ! apply_filters('wc_stripe_show_payment_request_on_checkout', false)) { |
|
532 | 532 | return; |
533 | 533 | } |
534 | 534 | |
535 | - if ( is_product() ) { |
|
535 | + if (is_product()) { |
|
536 | 536 | global $post; |
537 | 537 | |
538 | - $product = wc_get_product( $post->ID ); |
|
538 | + $product = wc_get_product($post->ID); |
|
539 | 539 | |
540 | - if ( ! is_object( $product ) || ! in_array( ( WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type() ), $this->supported_product_types() ) ) { |
|
540 | + if ( ! is_object($product) || ! in_array((WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type()), $this->supported_product_types())) { |
|
541 | 541 | return; |
542 | 542 | } |
543 | 543 | |
544 | 544 | // Pre Orders charge upon release not supported. |
545 | - if ( class_exists( 'WC_Pre_Orders_Order' ) && WC_Pre_Orders_Product::product_is_charged_upon_release( $product ) ) { |
|
546 | - WC_Stripe_Logger::log( 'Pre Order charge upon release is not supported. ( Payment Request button disabled )' ); |
|
545 | + if (class_exists('WC_Pre_Orders_Order') && WC_Pre_Orders_Product::product_is_charged_upon_release($product)) { |
|
546 | + WC_Stripe_Logger::log('Pre Order charge upon release is not supported. ( Payment Request button disabled )'); |
|
547 | 547 | return; |
548 | 548 | } |
549 | 549 | } else { |
550 | - if ( ! $this->allowed_items_in_cart() ) { |
|
551 | - WC_Stripe_Logger::log( 'Items in the cart has unsupported product type ( Payment Request button disabled )' ); |
|
550 | + if ( ! $this->allowed_items_in_cart()) { |
|
551 | + WC_Stripe_Logger::log('Items in the cart has unsupported product type ( Payment Request button disabled )'); |
|
552 | 552 | return; |
553 | 553 | } |
554 | 554 | } |
555 | 555 | ?> |
556 | - <p id="wc-stripe-payment-request-button-separator" style="margin-top:1.5em;text-align:center;display:none;">- <?php esc_html_e( 'OR', 'woocommerce-gateway-stripe' ); ?> -</p> |
|
556 | + <p id="wc-stripe-payment-request-button-separator" style="margin-top:1.5em;text-align:center;display:none;">- <?php esc_html_e('OR', 'woocommerce-gateway-stripe'); ?> -</p> |
|
557 | 557 | <?php |
558 | 558 | } |
559 | 559 | |
@@ -564,11 +564,11 @@ discard block |
||
564 | 564 | * @version 4.0.0 |
565 | 565 | */ |
566 | 566 | public function ajax_log_errors() { |
567 | - check_ajax_referer( 'wc-stripe-log-errors', 'security' ); |
|
567 | + check_ajax_referer('wc-stripe-log-errors', 'security'); |
|
568 | 568 | |
569 | - $errors = wc_clean( stripslashes( $_POST['errors'] ) ); |
|
569 | + $errors = wc_clean(stripslashes($_POST['errors'])); |
|
570 | 570 | |
571 | - WC_Stripe_Logger::log( $errors ); |
|
571 | + WC_Stripe_Logger::log($errors); |
|
572 | 572 | |
573 | 573 | exit; |
574 | 574 | } |
@@ -580,7 +580,7 @@ discard block |
||
580 | 580 | * @version 4.0.0 |
581 | 581 | */ |
582 | 582 | public function ajax_clear_cart() { |
583 | - check_ajax_referer( 'wc-stripe-clear-cart', 'security' ); |
|
583 | + check_ajax_referer('wc-stripe-clear-cart', 'security'); |
|
584 | 584 | |
585 | 585 | WC()->cart->empty_cart(); |
586 | 586 | exit; |
@@ -590,10 +590,10 @@ discard block |
||
590 | 590 | * Get cart details. |
591 | 591 | */ |
592 | 592 | public function ajax_get_cart_details() { |
593 | - check_ajax_referer( 'wc-stripe-payment-request', 'security' ); |
|
593 | + check_ajax_referer('wc-stripe-payment-request', 'security'); |
|
594 | 594 | |
595 | - if ( ! defined( 'WOOCOMMERCE_CART' ) ) { |
|
596 | - define( 'WOOCOMMERCE_CART', true ); |
|
595 | + if ( ! defined('WOOCOMMERCE_CART')) { |
|
596 | + define('WOOCOMMERCE_CART', true); |
|
597 | 597 | } |
598 | 598 | |
599 | 599 | WC()->cart->calculate_totals(); |
@@ -604,14 +604,14 @@ discard block |
||
604 | 604 | $data = array( |
605 | 605 | 'shipping_required' => WC()->cart->needs_shipping(), |
606 | 606 | 'order_data' => array( |
607 | - 'currency' => strtolower( $currency ), |
|
608 | - 'country_code' => substr( get_option( 'woocommerce_default_country' ), 0, 2 ), |
|
607 | + 'currency' => strtolower($currency), |
|
608 | + 'country_code' => substr(get_option('woocommerce_default_country'), 0, 2), |
|
609 | 609 | ), |
610 | 610 | ); |
611 | 611 | |
612 | 612 | $data['order_data'] += $this->build_display_items(); |
613 | 613 | |
614 | - wp_send_json( $data ); |
|
614 | + wp_send_json($data); |
|
615 | 615 | } |
616 | 616 | |
617 | 617 | /** |
@@ -622,47 +622,47 @@ discard block |
||
622 | 622 | * @see WC_Shipping::get_packages(). |
623 | 623 | */ |
624 | 624 | public function ajax_get_shipping_options() { |
625 | - check_ajax_referer( 'wc-stripe-payment-request-shipping', 'security' ); |
|
625 | + check_ajax_referer('wc-stripe-payment-request-shipping', 'security'); |
|
626 | 626 | |
627 | 627 | try { |
628 | 628 | // Set the shipping package. |
629 | - $posted = filter_input_array( INPUT_POST, array( |
|
629 | + $posted = filter_input_array(INPUT_POST, array( |
|
630 | 630 | 'country' => FILTER_SANITIZE_STRING, |
631 | 631 | 'state' => FILTER_SANITIZE_STRING, |
632 | 632 | 'postcode' => FILTER_SANITIZE_STRING, |
633 | 633 | 'city' => FILTER_SANITIZE_STRING, |
634 | 634 | 'address' => FILTER_SANITIZE_STRING, |
635 | 635 | 'address_2' => FILTER_SANITIZE_STRING, |
636 | - ) ); |
|
636 | + )); |
|
637 | 637 | |
638 | - $this->calculate_shipping( $posted ); |
|
638 | + $this->calculate_shipping($posted); |
|
639 | 639 | |
640 | 640 | // Set the shipping options. |
641 | 641 | $data = array(); |
642 | 642 | $packages = WC()->shipping->get_packages(); |
643 | 643 | |
644 | - if ( ! empty( $packages ) && WC()->customer->has_calculated_shipping() ) { |
|
645 | - foreach ( $packages as $package_key => $package ) { |
|
646 | - if ( empty( $package['rates'] ) ) { |
|
647 | - throw new Exception( __( 'Unable to find shipping method for address.', 'woocommerce-gateway-stripe' ) ); |
|
644 | + if ( ! empty($packages) && WC()->customer->has_calculated_shipping()) { |
|
645 | + foreach ($packages as $package_key => $package) { |
|
646 | + if (empty($package['rates'])) { |
|
647 | + throw new Exception(__('Unable to find shipping method for address.', 'woocommerce-gateway-stripe')); |
|
648 | 648 | } |
649 | 649 | |
650 | - foreach ( $package['rates'] as $key => $rate ) { |
|
650 | + foreach ($package['rates'] as $key => $rate) { |
|
651 | 651 | $data['shipping_options'][] = array( |
652 | 652 | 'id' => $rate->id, |
653 | 653 | 'label' => $rate->label, |
654 | 654 | 'detail' => '', |
655 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $rate->cost ), |
|
655 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($rate->cost), |
|
656 | 656 | ); |
657 | 657 | } |
658 | 658 | } |
659 | 659 | } else { |
660 | - throw new Exception( __( 'Unable to find shipping method for address.', 'woocommerce-gateway-stripe' ) ); |
|
660 | + throw new Exception(__('Unable to find shipping method for address.', 'woocommerce-gateway-stripe')); |
|
661 | 661 | } |
662 | 662 | |
663 | - if ( isset( $data[0] ) ) { |
|
663 | + if (isset($data[0])) { |
|
664 | 664 | // Auto select the first shipping method. |
665 | - WC()->session->set( 'chosen_shipping_methods', array( $data[0]['id'] ) ); |
|
665 | + WC()->session->set('chosen_shipping_methods', array($data[0]['id'])); |
|
666 | 666 | } |
667 | 667 | |
668 | 668 | WC()->cart->calculate_totals(); |
@@ -670,12 +670,12 @@ discard block |
||
670 | 670 | $data += $this->build_display_items(); |
671 | 671 | $data['result'] = 'success'; |
672 | 672 | |
673 | - wp_send_json( $data ); |
|
674 | - } catch ( Exception $e ) { |
|
673 | + wp_send_json($data); |
|
674 | + } catch (Exception $e) { |
|
675 | 675 | $data += $this->build_display_items(); |
676 | 676 | $data['result'] = 'invalid_shipping_address'; |
677 | 677 | |
678 | - wp_send_json( $data ); |
|
678 | + wp_send_json($data); |
|
679 | 679 | } |
680 | 680 | } |
681 | 681 | |
@@ -683,22 +683,22 @@ discard block |
||
683 | 683 | * Update shipping method. |
684 | 684 | */ |
685 | 685 | public function ajax_update_shipping_method() { |
686 | - check_ajax_referer( 'wc-stripe-update-shipping-method', 'security' ); |
|
686 | + check_ajax_referer('wc-stripe-update-shipping-method', 'security'); |
|
687 | 687 | |
688 | - if ( ! defined( 'WOOCOMMERCE_CART' ) ) { |
|
689 | - define( 'WOOCOMMERCE_CART', true ); |
|
688 | + if ( ! defined('WOOCOMMERCE_CART')) { |
|
689 | + define('WOOCOMMERCE_CART', true); |
|
690 | 690 | } |
691 | 691 | |
692 | - $chosen_shipping_methods = WC()->session->get( 'chosen_shipping_methods' ); |
|
693 | - $shipping_method = filter_input( INPUT_POST, 'shipping_method', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY ); |
|
692 | + $chosen_shipping_methods = WC()->session->get('chosen_shipping_methods'); |
|
693 | + $shipping_method = filter_input(INPUT_POST, 'shipping_method', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY); |
|
694 | 694 | |
695 | - if ( is_array( $shipping_method ) ) { |
|
696 | - foreach ( $shipping_method as $i => $value ) { |
|
697 | - $chosen_shipping_methods[ $i ] = wc_clean( $value ); |
|
695 | + if (is_array($shipping_method)) { |
|
696 | + foreach ($shipping_method as $i => $value) { |
|
697 | + $chosen_shipping_methods[$i] = wc_clean($value); |
|
698 | 698 | } |
699 | 699 | } |
700 | 700 | |
701 | - WC()->session->set( 'chosen_shipping_methods', $chosen_shipping_methods ); |
|
701 | + WC()->session->set('chosen_shipping_methods', $chosen_shipping_methods); |
|
702 | 702 | |
703 | 703 | WC()->cart->calculate_totals(); |
704 | 704 | |
@@ -706,7 +706,7 @@ discard block |
||
706 | 706 | $data += $this->build_display_items(); |
707 | 707 | $data['result'] = 'success'; |
708 | 708 | |
709 | - wp_send_json( $data ); |
|
709 | + wp_send_json($data); |
|
710 | 710 | } |
711 | 711 | |
712 | 712 | /** |
@@ -717,31 +717,31 @@ discard block |
||
717 | 717 | * @return array $data |
718 | 718 | */ |
719 | 719 | public function ajax_get_selected_product_data() { |
720 | - check_ajax_referer( 'wc-stripe-get-selected-product-data', 'security' ); |
|
720 | + check_ajax_referer('wc-stripe-get-selected-product-data', 'security'); |
|
721 | 721 | |
722 | - $product_id = absint( $_POST['product_id'] ); |
|
723 | - $qty = ! isset( $_POST['qty'] ) ? 1 : absint( $_POST['qty'] ); |
|
722 | + $product_id = absint($_POST['product_id']); |
|
723 | + $qty = ! isset($_POST['qty']) ? 1 : absint($_POST['qty']); |
|
724 | 724 | |
725 | - $product = wc_get_product( $product_id ); |
|
725 | + $product = wc_get_product($product_id); |
|
726 | 726 | |
727 | - if ( 'variable' === ( WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type() ) && isset( $_POST['attributes'] ) ) { |
|
728 | - $attributes = array_map( 'wc_clean', $_POST['attributes'] ); |
|
727 | + if ('variable' === (WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type()) && isset($_POST['attributes'])) { |
|
728 | + $attributes = array_map('wc_clean', $_POST['attributes']); |
|
729 | 729 | |
730 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
731 | - $variation_id = $product->get_matching_variation( $attributes ); |
|
730 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
731 | + $variation_id = $product->get_matching_variation($attributes); |
|
732 | 732 | } else { |
733 | - $data_store = WC_Data_Store::load( 'product' ); |
|
734 | - $variation_id = $data_store->find_matching_product_variation( $product, $attributes ); |
|
733 | + $data_store = WC_Data_Store::load('product'); |
|
734 | + $variation_id = $data_store->find_matching_product_variation($product, $attributes); |
|
735 | 735 | } |
736 | 736 | |
737 | - if ( ! empty( $variation_id ) ) { |
|
738 | - $product = wc_get_product( $variation_id ); |
|
737 | + if ( ! empty($variation_id)) { |
|
738 | + $product = wc_get_product($variation_id); |
|
739 | 739 | } |
740 | - } elseif ( 'simple' === ( WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type() ) ) { |
|
741 | - $product = wc_get_product( $product_id ); |
|
740 | + } elseif ('simple' === (WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type())) { |
|
741 | + $product = wc_get_product($product_id); |
|
742 | 742 | } |
743 | 743 | |
744 | - $total = $qty * ( WC_Stripe_Helper::is_pre_30() ? $product->price : $product->get_price() ); |
|
744 | + $total = $qty * (WC_Stripe_Helper::is_pre_30() ? $product->price : $product->get_price()); |
|
745 | 745 | |
746 | 746 | $quantity_label = 1 < $qty ? ' (x' . $qty . ')' : ''; |
747 | 747 | |
@@ -749,28 +749,28 @@ discard block |
||
749 | 749 | $items = array(); |
750 | 750 | |
751 | 751 | $items[] = array( |
752 | - 'label' => ( WC_Stripe_Helper::is_pre_30() ? $product->name : $product->get_name() ) . $quantity_label, |
|
753 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $total ), |
|
752 | + 'label' => (WC_Stripe_Helper::is_pre_30() ? $product->name : $product->get_name()) . $quantity_label, |
|
753 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($total), |
|
754 | 754 | ); |
755 | 755 | |
756 | - if ( wc_tax_enabled() ) { |
|
756 | + if (wc_tax_enabled()) { |
|
757 | 757 | $items[] = array( |
758 | - 'label' => __( 'Tax', 'woocommerce-gateway-stripe' ), |
|
758 | + 'label' => __('Tax', 'woocommerce-gateway-stripe'), |
|
759 | 759 | 'amount' => 0, |
760 | 760 | 'pending' => true, |
761 | 761 | ); |
762 | 762 | } |
763 | 763 | |
764 | - if ( wc_shipping_enabled() && $product->needs_shipping() ) { |
|
764 | + if (wc_shipping_enabled() && $product->needs_shipping()) { |
|
765 | 765 | $items[] = array( |
766 | - 'label' => __( 'Shipping', 'woocommerce-gateway-stripe' ), |
|
766 | + 'label' => __('Shipping', 'woocommerce-gateway-stripe'), |
|
767 | 767 | 'amount' => 0, |
768 | 768 | 'pending' => true, |
769 | 769 | ); |
770 | 770 | |
771 | - $data['shippingOptions'] = array( |
|
771 | + $data['shippingOptions'] = array( |
|
772 | 772 | 'id' => 'pending', |
773 | - 'label' => __( 'Pending', 'woocommerce-gateway-stripe' ), |
|
773 | + 'label' => __('Pending', 'woocommerce-gateway-stripe'), |
|
774 | 774 | 'detail' => '', |
775 | 775 | 'amount' => 0, |
776 | 776 | ); |
@@ -779,15 +779,15 @@ discard block |
||
779 | 779 | $data['displayItems'] = $items; |
780 | 780 | $data['total'] = array( |
781 | 781 | 'label' => $this->total_label, |
782 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $total ), |
|
782 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($total), |
|
783 | 783 | 'pending' => true, |
784 | 784 | ); |
785 | 785 | |
786 | - $data['requestShipping'] = ( wc_shipping_enabled() && $product->needs_shipping() ); |
|
787 | - $data['currency'] = strtolower( get_woocommerce_currency() ); |
|
788 | - $data['country_code'] = substr( get_option( 'woocommerce_default_country' ), 0, 2 ); |
|
786 | + $data['requestShipping'] = (wc_shipping_enabled() && $product->needs_shipping()); |
|
787 | + $data['currency'] = strtolower(get_woocommerce_currency()); |
|
788 | + $data['country_code'] = substr(get_option('woocommerce_default_country'), 0, 2); |
|
789 | 789 | |
790 | - wp_send_json( $data ); |
|
790 | + wp_send_json($data); |
|
791 | 791 | } |
792 | 792 | |
793 | 793 | /** |
@@ -798,37 +798,37 @@ discard block |
||
798 | 798 | * @return array $data |
799 | 799 | */ |
800 | 800 | public function ajax_add_to_cart() { |
801 | - check_ajax_referer( 'wc-stripe-add-to-cart', 'security' ); |
|
801 | + check_ajax_referer('wc-stripe-add-to-cart', 'security'); |
|
802 | 802 | |
803 | - if ( ! defined( 'WOOCOMMERCE_CART' ) ) { |
|
804 | - define( 'WOOCOMMERCE_CART', true ); |
|
803 | + if ( ! defined('WOOCOMMERCE_CART')) { |
|
804 | + define('WOOCOMMERCE_CART', true); |
|
805 | 805 | } |
806 | 806 | |
807 | 807 | WC()->shipping->reset_shipping(); |
808 | 808 | |
809 | - $product_id = absint( $_POST['product_id'] ); |
|
810 | - $qty = ! isset( $_POST['qty'] ) ? 1 : absint( $_POST['qty'] ); |
|
809 | + $product_id = absint($_POST['product_id']); |
|
810 | + $qty = ! isset($_POST['qty']) ? 1 : absint($_POST['qty']); |
|
811 | 811 | |
812 | - $product = wc_get_product( $product_id ); |
|
812 | + $product = wc_get_product($product_id); |
|
813 | 813 | |
814 | 814 | // First empty the cart to prevent wrong calculation. |
815 | 815 | WC()->cart->empty_cart(); |
816 | 816 | |
817 | - if ( 'variable' === ( WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type() ) && isset( $_POST['attributes'] ) ) { |
|
818 | - $attributes = array_map( 'wc_clean', $_POST['attributes'] ); |
|
817 | + if ('variable' === (WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type()) && isset($_POST['attributes'])) { |
|
818 | + $attributes = array_map('wc_clean', $_POST['attributes']); |
|
819 | 819 | |
820 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
821 | - $variation_id = $product->get_matching_variation( $attributes ); |
|
820 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
821 | + $variation_id = $product->get_matching_variation($attributes); |
|
822 | 822 | } else { |
823 | - $data_store = WC_Data_Store::load( 'product' ); |
|
824 | - $variation_id = $data_store->find_matching_product_variation( $product, $attributes ); |
|
823 | + $data_store = WC_Data_Store::load('product'); |
|
824 | + $variation_id = $data_store->find_matching_product_variation($product, $attributes); |
|
825 | 825 | } |
826 | 826 | |
827 | - WC()->cart->add_to_cart( $product->get_id(), $qty, $variation_id, $attributes ); |
|
827 | + WC()->cart->add_to_cart($product->get_id(), $qty, $variation_id, $attributes); |
|
828 | 828 | } |
829 | 829 | |
830 | - if ( 'simple' === ( WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type() ) ) { |
|
831 | - WC()->cart->add_to_cart( $product->get_id(), $qty ); |
|
830 | + if ('simple' === (WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type())) { |
|
831 | + WC()->cart->add_to_cart($product->get_id(), $qty); |
|
832 | 832 | } |
833 | 833 | |
834 | 834 | WC()->cart->calculate_totals(); |
@@ -837,7 +837,7 @@ discard block |
||
837 | 837 | $data += $this->build_display_items(); |
838 | 838 | $data['result'] = 'success'; |
839 | 839 | |
840 | - wp_send_json( $data ); |
|
840 | + wp_send_json($data); |
|
841 | 841 | } |
842 | 842 | |
843 | 843 | /** |
@@ -850,31 +850,31 @@ discard block |
||
850 | 850 | * @version 4.0.0 |
851 | 851 | */ |
852 | 852 | public function normalize_state() { |
853 | - $billing_country = ! empty( $_POST['billing_country'] ) ? wc_clean( $_POST['billing_country'] ) : ''; |
|
854 | - $shipping_country = ! empty( $_POST['shipping_country'] ) ? wc_clean( $_POST['shipping_country'] ) : ''; |
|
855 | - $billing_state = ! empty( $_POST['billing_state'] ) ? wc_clean( $_POST['billing_state'] ) : ''; |
|
856 | - $shipping_state = ! empty( $_POST['shipping_state'] ) ? wc_clean( $_POST['shipping_state'] ) : ''; |
|
853 | + $billing_country = ! empty($_POST['billing_country']) ? wc_clean($_POST['billing_country']) : ''; |
|
854 | + $shipping_country = ! empty($_POST['shipping_country']) ? wc_clean($_POST['shipping_country']) : ''; |
|
855 | + $billing_state = ! empty($_POST['billing_state']) ? wc_clean($_POST['billing_state']) : ''; |
|
856 | + $shipping_state = ! empty($_POST['shipping_state']) ? wc_clean($_POST['shipping_state']) : ''; |
|
857 | 857 | |
858 | - if ( $billing_state && $billing_country ) { |
|
859 | - $valid_states = WC()->countries->get_states( $billing_country ); |
|
858 | + if ($billing_state && $billing_country) { |
|
859 | + $valid_states = WC()->countries->get_states($billing_country); |
|
860 | 860 | |
861 | 861 | // Valid states found for country. |
862 | - if ( ! empty( $valid_states ) && is_array( $valid_states ) && sizeof( $valid_states ) > 0 ) { |
|
863 | - foreach ( $valid_states as $state_abbr => $state ) { |
|
864 | - if ( preg_match( '/' . preg_quote( $state ) . '/i', $billing_state ) ) { |
|
862 | + if ( ! empty($valid_states) && is_array($valid_states) && sizeof($valid_states) > 0) { |
|
863 | + foreach ($valid_states as $state_abbr => $state) { |
|
864 | + if (preg_match('/' . preg_quote($state) . '/i', $billing_state)) { |
|
865 | 865 | $_POST['billing_state'] = $state_abbr; |
866 | 866 | } |
867 | 867 | } |
868 | 868 | } |
869 | 869 | } |
870 | 870 | |
871 | - if ( $shipping_state && $shipping_country ) { |
|
872 | - $valid_states = WC()->countries->get_states( $shipping_country ); |
|
871 | + if ($shipping_state && $shipping_country) { |
|
872 | + $valid_states = WC()->countries->get_states($shipping_country); |
|
873 | 873 | |
874 | 874 | // Valid states found for country. |
875 | - if ( ! empty( $valid_states ) && is_array( $valid_states ) && sizeof( $valid_states ) > 0 ) { |
|
876 | - foreach ( $valid_states as $state_abbr => $state ) { |
|
877 | - if ( preg_match( '/' . preg_quote( $state ) . '/i', $shipping_state ) ) { |
|
875 | + if ( ! empty($valid_states) && is_array($valid_states) && sizeof($valid_states) > 0) { |
|
876 | + foreach ($valid_states as $state_abbr => $state) { |
|
877 | + if (preg_match('/' . preg_quote($state) . '/i', $shipping_state)) { |
|
878 | 878 | $_POST['shipping_state'] = $state_abbr; |
879 | 879 | } |
880 | 880 | } |
@@ -889,19 +889,19 @@ discard block |
||
889 | 889 | * @version 4.0.0 |
890 | 890 | */ |
891 | 891 | public function ajax_create_order() { |
892 | - if ( WC()->cart->is_empty() ) { |
|
893 | - wp_send_json_error( __( 'Empty cart', 'woocommerce-gateway-stripe' ) ); |
|
892 | + if (WC()->cart->is_empty()) { |
|
893 | + wp_send_json_error(__('Empty cart', 'woocommerce-gateway-stripe')); |
|
894 | 894 | } |
895 | 895 | |
896 | - if ( ! defined( 'WOOCOMMERCE_CHECKOUT' ) ) { |
|
897 | - define( 'WOOCOMMERCE_CHECKOUT', true ); |
|
896 | + if ( ! defined('WOOCOMMERCE_CHECKOUT')) { |
|
897 | + define('WOOCOMMERCE_CHECKOUT', true); |
|
898 | 898 | } |
899 | 899 | |
900 | 900 | $this->normalize_state(); |
901 | 901 | |
902 | 902 | WC()->checkout()->process_checkout(); |
903 | 903 | |
904 | - die( 0 ); |
|
904 | + die(0); |
|
905 | 905 | } |
906 | 906 | |
907 | 907 | /** |
@@ -911,7 +911,7 @@ discard block |
||
911 | 911 | * @version 4.0.0 |
912 | 912 | * @param array $address |
913 | 913 | */ |
914 | - protected function calculate_shipping( $address = array() ) { |
|
914 | + protected function calculate_shipping($address = array()) { |
|
915 | 915 | global $states; |
916 | 916 | |
917 | 917 | $country = $address['country']; |
@@ -928,28 +928,28 @@ discard block |
||
928 | 928 | * In some versions of Chrome, state can be a full name. So we need |
929 | 929 | * to convert that to abbreviation as WC is expecting that. |
930 | 930 | */ |
931 | - if ( 2 < strlen( $state ) ) { |
|
932 | - $state = array_search( ucfirst( strtolower( $state ) ), $states[ $country ] ); |
|
931 | + if (2 < strlen($state)) { |
|
932 | + $state = array_search(ucfirst(strtolower($state)), $states[$country]); |
|
933 | 933 | } |
934 | 934 | |
935 | 935 | WC()->shipping->reset_shipping(); |
936 | 936 | |
937 | - if ( $postcode && WC_Validation::is_postcode( $postcode, $country ) ) { |
|
938 | - $postcode = wc_format_postcode( $postcode, $country ); |
|
937 | + if ($postcode && WC_Validation::is_postcode($postcode, $country)) { |
|
938 | + $postcode = wc_format_postcode($postcode, $country); |
|
939 | 939 | } |
940 | 940 | |
941 | - if ( $country ) { |
|
942 | - WC()->customer->set_location( $country, $state, $postcode, $city ); |
|
943 | - WC()->customer->set_shipping_location( $country, $state, $postcode, $city ); |
|
941 | + if ($country) { |
|
942 | + WC()->customer->set_location($country, $state, $postcode, $city); |
|
943 | + WC()->customer->set_shipping_location($country, $state, $postcode, $city); |
|
944 | 944 | } else { |
945 | 945 | WC_Stripe_Helper::is_pre_30() ? WC()->customer->set_to_base() : WC()->customer->set_billing_address_to_base(); |
946 | 946 | WC_Stripe_Helper::is_pre_30() ? WC()->customer->set_shipping_to_base() : WC()->customer->set_shipping_address_to_base(); |
947 | 947 | } |
948 | 948 | |
949 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
950 | - WC()->customer->calculated_shipping( true ); |
|
949 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
950 | + WC()->customer->calculated_shipping(true); |
|
951 | 951 | } else { |
952 | - WC()->customer->set_calculated_shipping( true ); |
|
952 | + WC()->customer->set_calculated_shipping(true); |
|
953 | 953 | WC()->customer->save(); |
954 | 954 | } |
955 | 955 | |
@@ -966,17 +966,17 @@ discard block |
||
966 | 966 | $packages[0]['destination']['address'] = $address_1; |
967 | 967 | $packages[0]['destination']['address_2'] = $address_2; |
968 | 968 | |
969 | - foreach ( WC()->cart->get_cart() as $item ) { |
|
970 | - if ( $item['data']->needs_shipping() ) { |
|
971 | - if ( isset( $item['line_total'] ) ) { |
|
969 | + foreach (WC()->cart->get_cart() as $item) { |
|
970 | + if ($item['data']->needs_shipping()) { |
|
971 | + if (isset($item['line_total'])) { |
|
972 | 972 | $packages[0]['contents_cost'] += $item['line_total']; |
973 | 973 | } |
974 | 974 | } |
975 | 975 | } |
976 | 976 | |
977 | - $packages = apply_filters( 'woocommerce_cart_shipping_packages', $packages ); |
|
977 | + $packages = apply_filters('woocommerce_cart_shipping_packages', $packages); |
|
978 | 978 | |
979 | - WC()->shipping->calculate_shipping( $packages ); |
|
979 | + WC()->shipping->calculate_shipping($packages); |
|
980 | 980 | } |
981 | 981 | |
982 | 982 | /** |
@@ -985,19 +985,19 @@ discard block |
||
985 | 985 | * @since 3.1.0 |
986 | 986 | * @version 4.0.0 |
987 | 987 | */ |
988 | - protected function build_shipping_methods( $shipping_methods ) { |
|
989 | - if ( empty( $shipping_methods ) ) { |
|
988 | + protected function build_shipping_methods($shipping_methods) { |
|
989 | + if (empty($shipping_methods)) { |
|
990 | 990 | return array(); |
991 | 991 | } |
992 | 992 | |
993 | 993 | $shipping = array(); |
994 | 994 | |
995 | - foreach ( $shipping_methods as $method ) { |
|
995 | + foreach ($shipping_methods as $method) { |
|
996 | 996 | $shipping[] = array( |
997 | 997 | 'id' => $method['id'], |
998 | 998 | 'label' => $method['label'], |
999 | 999 | 'detail' => '', |
1000 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $method['amount']['value'] ), |
|
1000 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($method['amount']['value']), |
|
1001 | 1001 | ); |
1002 | 1002 | } |
1003 | 1003 | |
@@ -1011,69 +1011,69 @@ discard block |
||
1011 | 1011 | * @version 4.0.0 |
1012 | 1012 | */ |
1013 | 1013 | protected function build_display_items() { |
1014 | - if ( ! defined( 'WOOCOMMERCE_CART' ) ) { |
|
1015 | - define( 'WOOCOMMERCE_CART', true ); |
|
1014 | + if ( ! defined('WOOCOMMERCE_CART')) { |
|
1015 | + define('WOOCOMMERCE_CART', true); |
|
1016 | 1016 | } |
1017 | 1017 | |
1018 | 1018 | $items = array(); |
1019 | 1019 | $subtotal = 0; |
1020 | 1020 | |
1021 | 1021 | // Default show only subtotal instead of itemization. |
1022 | - if ( ! apply_filters( 'wc_stripe_payment_request_hide_itemization', true ) ) { |
|
1023 | - foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) { |
|
1022 | + if ( ! apply_filters('wc_stripe_payment_request_hide_itemization', true)) { |
|
1023 | + foreach (WC()->cart->get_cart() as $cart_item_key => $cart_item) { |
|
1024 | 1024 | $amount = $cart_item['line_subtotal']; |
1025 | - $subtotal += $cart_item['line_subtotal']; |
|
1025 | + $subtotal += $cart_item['line_subtotal']; |
|
1026 | 1026 | $quantity_label = 1 < $cart_item['quantity'] ? ' (x' . $cart_item['quantity'] . ')' : ''; |
1027 | 1027 | |
1028 | 1028 | $product_name = WC_Stripe_Helper::is_pre_30() ? $cart_item['data']->post->post_title : $cart_item['data']->get_name(); |
1029 | 1029 | |
1030 | 1030 | $item = array( |
1031 | 1031 | 'label' => $product_name . $quantity_label, |
1032 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $amount ), |
|
1032 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($amount), |
|
1033 | 1033 | ); |
1034 | 1034 | |
1035 | 1035 | $items[] = $item; |
1036 | 1036 | } |
1037 | 1037 | } |
1038 | 1038 | |
1039 | - $discounts = wc_format_decimal( WC()->cart->get_cart_discount_total(), WC()->cart->dp ); |
|
1040 | - $tax = wc_format_decimal( WC()->cart->tax_total + WC()->cart->shipping_tax_total, WC()->cart->dp ); |
|
1041 | - $shipping = wc_format_decimal( WC()->cart->shipping_total, WC()->cart->dp ); |
|
1042 | - $items_total = wc_format_decimal( WC()->cart->cart_contents_total, WC()->cart->dp ) + $discounts; |
|
1043 | - $order_total = wc_format_decimal( $items_total + $tax + $shipping - $discounts, WC()->cart->dp ); |
|
1039 | + $discounts = wc_format_decimal(WC()->cart->get_cart_discount_total(), WC()->cart->dp); |
|
1040 | + $tax = wc_format_decimal(WC()->cart->tax_total + WC()->cart->shipping_tax_total, WC()->cart->dp); |
|
1041 | + $shipping = wc_format_decimal(WC()->cart->shipping_total, WC()->cart->dp); |
|
1042 | + $items_total = wc_format_decimal(WC()->cart->cart_contents_total, WC()->cart->dp) + $discounts; |
|
1043 | + $order_total = wc_format_decimal($items_total + $tax + $shipping - $discounts, WC()->cart->dp); |
|
1044 | 1044 | |
1045 | - if ( wc_tax_enabled() ) { |
|
1045 | + if (wc_tax_enabled()) { |
|
1046 | 1046 | $items[] = array( |
1047 | - 'label' => esc_html( __( 'Tax', 'woocommerce-gateway-stripe' ) ), |
|
1048 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $tax ), |
|
1047 | + 'label' => esc_html(__('Tax', 'woocommerce-gateway-stripe')), |
|
1048 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($tax), |
|
1049 | 1049 | ); |
1050 | 1050 | } |
1051 | 1051 | |
1052 | - if ( WC()->cart->needs_shipping() ) { |
|
1052 | + if (WC()->cart->needs_shipping()) { |
|
1053 | 1053 | $items[] = array( |
1054 | - 'label' => esc_html( __( 'Shipping', 'woocommerce-gateway-stripe' ) ), |
|
1055 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $shipping ), |
|
1054 | + 'label' => esc_html(__('Shipping', 'woocommerce-gateway-stripe')), |
|
1055 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($shipping), |
|
1056 | 1056 | ); |
1057 | 1057 | } |
1058 | 1058 | |
1059 | - if ( WC()->cart->has_discount() ) { |
|
1059 | + if (WC()->cart->has_discount()) { |
|
1060 | 1060 | $items[] = array( |
1061 | - 'label' => esc_html( __( 'Discount', 'woocommerce-gateway-stripe' ) ), |
|
1062 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $discounts ), |
|
1061 | + 'label' => esc_html(__('Discount', 'woocommerce-gateway-stripe')), |
|
1062 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($discounts), |
|
1063 | 1063 | ); |
1064 | 1064 | } |
1065 | 1065 | |
1066 | - if ( version_compare( WC_VERSION, '3.2', '<' ) ) { |
|
1066 | + if (version_compare(WC_VERSION, '3.2', '<')) { |
|
1067 | 1067 | $cart_fees = WC()->cart->fees; |
1068 | 1068 | } else { |
1069 | 1069 | $cart_fees = WC()->cart->get_fees(); |
1070 | 1070 | } |
1071 | 1071 | |
1072 | 1072 | // Include fees and taxes as display items. |
1073 | - foreach ( $cart_fees as $key => $fee ) { |
|
1073 | + foreach ($cart_fees as $key => $fee) { |
|
1074 | 1074 | $items[] = array( |
1075 | 1075 | 'label' => $fee->name, |
1076 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $fee->amount ), |
|
1076 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($fee->amount), |
|
1077 | 1077 | ); |
1078 | 1078 | } |
1079 | 1079 | |
@@ -1081,7 +1081,7 @@ discard block |
||
1081 | 1081 | 'displayItems' => $items, |
1082 | 1082 | 'total' => array( |
1083 | 1083 | 'label' => $this->total_label, |
1084 | - 'amount' => max( 0, apply_filters( 'woocommerce_stripe_calculated_total', WC_Stripe_Helper::get_stripe_amount( $order_total ), $order_total, WC()->cart ) ), |
|
1084 | + 'amount' => max(0, apply_filters('woocommerce_stripe_calculated_total', WC_Stripe_Helper::get_stripe_amount($order_total), $order_total, WC()->cart)), |
|
1085 | 1085 | 'pending' => false, |
1086 | 1086 | ), |
1087 | 1087 | ); |