@@ -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,43 +98,43 @@ 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 | - if ( apply_filters( 'wc_stripe_show_payment_request_on_checkout', false ) ) { |
|
121 | - add_action( 'woocommerce_checkout_before_customer_details', array( $this, 'display_payment_request_button_html' ), 1 ); |
|
122 | - add_action( 'woocommerce_checkout_before_customer_details', array( $this, 'display_payment_request_button_separator_html' ), 2 ); |
|
120 | + if (apply_filters('wc_stripe_show_payment_request_on_checkout', false)) { |
|
121 | + add_action('woocommerce_checkout_before_customer_details', array($this, 'display_payment_request_button_html'), 1); |
|
122 | + add_action('woocommerce_checkout_before_customer_details', array($this, 'display_payment_request_button_separator_html'), 2); |
|
123 | 123 | } |
124 | 124 | |
125 | - add_action( 'wc_ajax_wc_stripe_get_cart_details', array( $this, 'ajax_get_cart_details' ) ); |
|
126 | - add_action( 'wc_ajax_wc_stripe_get_shipping_options', array( $this, 'ajax_get_shipping_options' ) ); |
|
127 | - add_action( 'wc_ajax_wc_stripe_update_shipping_method', array( $this, 'ajax_update_shipping_method' ) ); |
|
128 | - add_action( 'wc_ajax_wc_stripe_create_order', array( $this, 'ajax_create_order' ) ); |
|
129 | - add_action( 'wc_ajax_wc_stripe_add_to_cart', array( $this, 'ajax_add_to_cart' ) ); |
|
130 | - add_action( 'wc_ajax_wc_stripe_get_selected_product_data', array( $this, 'ajax_get_selected_product_data' ) ); |
|
131 | - add_action( 'wc_ajax_wc_stripe_clear_cart', array( $this, 'ajax_clear_cart' ) ); |
|
132 | - add_action( 'wc_ajax_wc_stripe_log_errors', array( $this, 'ajax_log_errors' ) ); |
|
125 | + add_action('wc_ajax_wc_stripe_get_cart_details', array($this, 'ajax_get_cart_details')); |
|
126 | + add_action('wc_ajax_wc_stripe_get_shipping_options', array($this, 'ajax_get_shipping_options')); |
|
127 | + add_action('wc_ajax_wc_stripe_update_shipping_method', array($this, 'ajax_update_shipping_method')); |
|
128 | + add_action('wc_ajax_wc_stripe_create_order', array($this, 'ajax_create_order')); |
|
129 | + add_action('wc_ajax_wc_stripe_add_to_cart', array($this, 'ajax_add_to_cart')); |
|
130 | + add_action('wc_ajax_wc_stripe_get_selected_product_data', array($this, 'ajax_get_selected_product_data')); |
|
131 | + add_action('wc_ajax_wc_stripe_clear_cart', array($this, 'ajax_clear_cart')); |
|
132 | + add_action('wc_ajax_wc_stripe_log_errors', array($this, 'ajax_log_errors')); |
|
133 | 133 | |
134 | - add_filter( 'woocommerce_gateway_title', array( $this, 'filter_gateway_title' ), 10, 2 ); |
|
135 | - add_filter( 'woocommerce_validate_postcode', array( $this, 'postal_code_validation' ), 10, 3 ); |
|
134 | + add_filter('woocommerce_gateway_title', array($this, 'filter_gateway_title'), 10, 2); |
|
135 | + add_filter('woocommerce_validate_postcode', array($this, 'postal_code_validation'), 10, 3); |
|
136 | 136 | |
137 | - add_action( 'woocommerce_checkout_order_processed', array( $this, 'add_order_meta' ), 10, 3 ); |
|
137 | + add_action('woocommerce_checkout_order_processed', array($this, 'add_order_meta'), 10, 3); |
|
138 | 138 | } |
139 | 139 | |
140 | 140 | /** |
@@ -144,11 +144,11 @@ discard block |
||
144 | 144 | * @since 4.0.0 |
145 | 145 | */ |
146 | 146 | public function set_session() { |
147 | - if ( ! is_user_logged_in() ) { |
|
147 | + if ( ! is_user_logged_in()) { |
|
148 | 148 | $wc_session = new WC_Session_Handler(); |
149 | 149 | |
150 | - if ( ! $wc_session->has_session() ) { |
|
151 | - $wc_session->set_customer_session_cookie( true ); |
|
150 | + if ( ! $wc_session->has_session()) { |
|
151 | + $wc_session->set_customer_session_cookie(true); |
|
152 | 152 | } |
153 | 153 | } |
154 | 154 | } |
@@ -161,7 +161,7 @@ discard block |
||
161 | 161 | * @return string |
162 | 162 | */ |
163 | 163 | public function get_button_type() { |
164 | - return isset( $this->stripe_settings['payment_request_button_type'] ) ? $this->stripe_settings['payment_request_button_type'] : 'default'; |
|
164 | + return isset($this->stripe_settings['payment_request_button_type']) ? $this->stripe_settings['payment_request_button_type'] : 'default'; |
|
165 | 165 | } |
166 | 166 | |
167 | 167 | /** |
@@ -172,7 +172,7 @@ discard block |
||
172 | 172 | * @return string |
173 | 173 | */ |
174 | 174 | public function get_button_theme() { |
175 | - return isset( $this->stripe_settings['payment_request_button_theme'] ) ? $this->stripe_settings['payment_request_button_theme'] : 'dark'; |
|
175 | + return isset($this->stripe_settings['payment_request_button_theme']) ? $this->stripe_settings['payment_request_button_theme'] : 'dark'; |
|
176 | 176 | } |
177 | 177 | |
178 | 178 | /** |
@@ -183,7 +183,7 @@ discard block |
||
183 | 183 | * @return string |
184 | 184 | */ |
185 | 185 | public function get_button_height() { |
186 | - return isset( $this->stripe_settings['payment_request_button_height'] ) ? str_replace( 'px', '', $this->stripe_settings['payment_request_button_height'] ) : '64'; |
|
186 | + return isset($this->stripe_settings['payment_request_button_height']) ? str_replace('px', '', $this->stripe_settings['payment_request_button_height']) : '64'; |
|
187 | 187 | } |
188 | 188 | |
189 | 189 | /** |
@@ -193,40 +193,40 @@ discard block |
||
193 | 193 | * @version 4.0.0 |
194 | 194 | */ |
195 | 195 | public function get_product_data() { |
196 | - if ( ! is_product() ) { |
|
196 | + if ( ! is_product()) { |
|
197 | 197 | return false; |
198 | 198 | } |
199 | 199 | |
200 | 200 | global $post; |
201 | 201 | |
202 | - $product = wc_get_product( $post->ID ); |
|
202 | + $product = wc_get_product($post->ID); |
|
203 | 203 | |
204 | 204 | $data = array(); |
205 | 205 | $items = array(); |
206 | 206 | |
207 | 207 | $items[] = array( |
208 | 208 | 'label' => WC_Stripe_Helper::is_pre_30() ? $product->name : $product->get_name(), |
209 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( WC_Stripe_Helper::is_pre_30() ? $product->price : $product->get_price() ), |
|
209 | + 'amount' => WC_Stripe_Helper::get_stripe_amount(WC_Stripe_Helper::is_pre_30() ? $product->price : $product->get_price()), |
|
210 | 210 | ); |
211 | 211 | |
212 | - if ( wc_tax_enabled() ) { |
|
212 | + if (wc_tax_enabled()) { |
|
213 | 213 | $items[] = array( |
214 | - 'label' => __( 'Tax', 'woocommerce-gateway-stripe' ), |
|
214 | + 'label' => __('Tax', 'woocommerce-gateway-stripe'), |
|
215 | 215 | 'amount' => 0, |
216 | 216 | 'pending' => true, |
217 | 217 | ); |
218 | 218 | } |
219 | 219 | |
220 | - if ( wc_shipping_enabled() && $product->needs_shipping() ) { |
|
220 | + if (wc_shipping_enabled() && $product->needs_shipping()) { |
|
221 | 221 | $items[] = array( |
222 | - 'label' => __( 'Shipping', 'woocommerce-gateway-stripe' ), |
|
222 | + 'label' => __('Shipping', 'woocommerce-gateway-stripe'), |
|
223 | 223 | 'amount' => 0, |
224 | 224 | 'pending' => true, |
225 | 225 | ); |
226 | 226 | |
227 | - $data['shippingOptions'] = array( |
|
227 | + $data['shippingOptions'] = array( |
|
228 | 228 | 'id' => 'pending', |
229 | - 'label' => __( 'Pending', 'woocommerce-gateway-stripe' ), |
|
229 | + 'label' => __('Pending', 'woocommerce-gateway-stripe'), |
|
230 | 230 | 'detail' => '', |
231 | 231 | 'amount' => 0, |
232 | 232 | ); |
@@ -235,13 +235,13 @@ discard block |
||
235 | 235 | $data['displayItems'] = $items; |
236 | 236 | $data['total'] = array( |
237 | 237 | 'label' => $this->total_label, |
238 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( WC_Stripe_Helper::is_pre_30() ? $product->price : $product->get_price() ), |
|
238 | + 'amount' => WC_Stripe_Helper::get_stripe_amount(WC_Stripe_Helper::is_pre_30() ? $product->price : $product->get_price()), |
|
239 | 239 | 'pending' => true, |
240 | 240 | ); |
241 | 241 | |
242 | - $data['requestShipping'] = ( wc_shipping_enabled() && $product->needs_shipping() ); |
|
243 | - $data['currency'] = strtolower( get_woocommerce_currency() ); |
|
244 | - $data['country_code'] = substr( get_option( 'woocommerce_default_country' ), 0, 2 ); |
|
242 | + $data['requestShipping'] = (wc_shipping_enabled() && $product->needs_shipping()); |
|
243 | + $data['currency'] = strtolower(get_woocommerce_currency()); |
|
244 | + $data['country_code'] = substr(get_option('woocommerce_default_country'), 0, 2); |
|
245 | 245 | |
246 | 246 | return $data; |
247 | 247 | } |
@@ -250,25 +250,25 @@ discard block |
||
250 | 250 | * Filters the gateway title to reflect Payment Request type |
251 | 251 | * |
252 | 252 | */ |
253 | - public function filter_gateway_title( $title, $id ) { |
|
253 | + public function filter_gateway_title($title, $id) { |
|
254 | 254 | global $post; |
255 | 255 | |
256 | - if ( ! is_object( $post ) ) { |
|
256 | + if ( ! is_object($post)) { |
|
257 | 257 | return $title; |
258 | 258 | } |
259 | 259 | |
260 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
261 | - $method_title = get_post_meta( $post->ID, '_payment_method_title', true ); |
|
260 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
261 | + $method_title = get_post_meta($post->ID, '_payment_method_title', true); |
|
262 | 262 | } else { |
263 | - $order = wc_get_order( $post->ID ); |
|
264 | - $method_title = is_object( $order ) ? $order->get_payment_method_title() : ''; |
|
263 | + $order = wc_get_order($post->ID); |
|
264 | + $method_title = is_object($order) ? $order->get_payment_method_title() : ''; |
|
265 | 265 | } |
266 | 266 | |
267 | - if ( 'stripe' === $id && ! empty( $method_title ) && 'Apple Pay (Stripe)' === $method_title ) { |
|
267 | + if ('stripe' === $id && ! empty($method_title) && 'Apple Pay (Stripe)' === $method_title) { |
|
268 | 268 | return $method_title; |
269 | 269 | } |
270 | 270 | |
271 | - if ( 'stripe' === $id && ! empty( $method_title ) && 'Chrome Payment Request (Stripe)' === $method_title ) { |
|
271 | + if ('stripe' === $id && ! empty($method_title) && 'Chrome Payment Request (Stripe)' === $method_title) { |
|
272 | 272 | return $method_title; |
273 | 273 | } |
274 | 274 | |
@@ -281,16 +281,16 @@ discard block |
||
281 | 281 | * @since 3.1.4 |
282 | 282 | * @version 4.0.0 |
283 | 283 | */ |
284 | - public function postal_code_validation( $valid, $postcode, $country ) { |
|
284 | + public function postal_code_validation($valid, $postcode, $country) { |
|
285 | 285 | $gateways = WC()->payment_gateways->get_available_payment_gateways(); |
286 | 286 | |
287 | - if ( ! isset( $gateways['stripe'] ) ) { |
|
287 | + if ( ! isset($gateways['stripe'])) { |
|
288 | 288 | return $valid; |
289 | 289 | } |
290 | 290 | |
291 | - $payment_request_type = wc_clean( $_POST['payment_request_type'] ); |
|
291 | + $payment_request_type = wc_clean($_POST['payment_request_type']); |
|
292 | 292 | |
293 | - if ( 'apple_pay' !== $payment_request_type ) { |
|
293 | + if ('apple_pay' !== $payment_request_type) { |
|
294 | 294 | return $valid; |
295 | 295 | } |
296 | 296 | |
@@ -300,7 +300,7 @@ discard block |
||
300 | 300 | * the order and not let it go through. The remedy for now is just to remove this validation. |
301 | 301 | * Note that this only works with shipping providers that don't validate full postal codes. |
302 | 302 | */ |
303 | - if ( 'GB' === $country || 'CA' === $country ) { |
|
303 | + if ('GB' === $country || 'CA' === $country) { |
|
304 | 304 | return true; |
305 | 305 | } |
306 | 306 | |
@@ -316,27 +316,27 @@ discard block |
||
316 | 316 | * @param array $posted_data The posted data from checkout form. |
317 | 317 | * @param object $order |
318 | 318 | */ |
319 | - public function add_order_meta( $order_id, $posted_data, $order ) { |
|
320 | - if ( empty( $_POST['payment_request_type'] ) ) { |
|
319 | + public function add_order_meta($order_id, $posted_data, $order) { |
|
320 | + if (empty($_POST['payment_request_type'])) { |
|
321 | 321 | return; |
322 | 322 | } |
323 | 323 | |
324 | - $payment_request_type = wc_clean( $_POST['payment_request_type'] ); |
|
324 | + $payment_request_type = wc_clean($_POST['payment_request_type']); |
|
325 | 325 | |
326 | - if ( 'apple_pay' === $payment_request_type ) { |
|
327 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
328 | - update_post_meta( $order_id, '_payment_method_title', 'Apple Pay (Stripe)' ); |
|
326 | + if ('apple_pay' === $payment_request_type) { |
|
327 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
328 | + update_post_meta($order_id, '_payment_method_title', 'Apple Pay (Stripe)'); |
|
329 | 329 | } else { |
330 | - $order->set_payment_method_title( 'Apple Pay (Stripe)' ); |
|
330 | + $order->set_payment_method_title('Apple Pay (Stripe)'); |
|
331 | 331 | $order->save(); |
332 | 332 | } |
333 | 333 | } |
334 | 334 | |
335 | - if ( 'payment_request_api' === $payment_request_type ) { |
|
336 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
337 | - update_post_meta( $order_id, '_payment_method_title', 'Chrome Payment Request (Stripe)' ); |
|
335 | + if ('payment_request_api' === $payment_request_type) { |
|
336 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
337 | + update_post_meta($order_id, '_payment_method_title', 'Chrome Payment Request (Stripe)'); |
|
338 | 338 | } else { |
339 | - $order->set_payment_method_title( 'Chrome Payment Request (Stripe)' ); |
|
339 | + $order->set_payment_method_title('Chrome Payment Request (Stripe)'); |
|
340 | 340 | $order->save(); |
341 | 341 | } |
342 | 342 | } |
@@ -350,11 +350,11 @@ discard block |
||
350 | 350 | * @return array |
351 | 351 | */ |
352 | 352 | public function supported_product_types() { |
353 | - return apply_filters( 'wc_stripe_payment_request_supported_types', array( |
|
353 | + return apply_filters('wc_stripe_payment_request_supported_types', array( |
|
354 | 354 | 'simple', |
355 | 355 | 'variable', |
356 | 356 | 'variation', |
357 | - ) ); |
|
357 | + )); |
|
358 | 358 | } |
359 | 359 | |
360 | 360 | /** |
@@ -365,15 +365,15 @@ discard block |
||
365 | 365 | * @return bool |
366 | 366 | */ |
367 | 367 | public function allowed_items_in_cart() { |
368 | - foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) { |
|
369 | - $_product = apply_filters( 'woocommerce_cart_item_product', $cart_item['data'], $cart_item, $cart_item_key ); |
|
368 | + foreach (WC()->cart->get_cart() as $cart_item_key => $cart_item) { |
|
369 | + $_product = apply_filters('woocommerce_cart_item_product', $cart_item['data'], $cart_item, $cart_item_key); |
|
370 | 370 | |
371 | - if ( ! in_array( ( WC_Stripe_Helper::is_pre_30() ? $_product->product_type : $_product->get_type() ), $this->supported_product_types() ) ) { |
|
371 | + if ( ! in_array((WC_Stripe_Helper::is_pre_30() ? $_product->product_type : $_product->get_type()), $this->supported_product_types())) { |
|
372 | 372 | return false; |
373 | 373 | } |
374 | 374 | |
375 | 375 | // Pre Orders compatbility where we don't support charge upon release. |
376 | - 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() ) ) { |
|
376 | + 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())) { |
|
377 | 377 | return false; |
378 | 378 | } |
379 | 379 | } |
@@ -388,71 +388,71 @@ discard block |
||
388 | 388 | * @version 4.0.0 |
389 | 389 | */ |
390 | 390 | public function scripts() { |
391 | - if ( ! is_product() && ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) ) { |
|
391 | + if ( ! is_product() && ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order'])) { |
|
392 | 392 | return; |
393 | 393 | } |
394 | 394 | |
395 | - if ( is_product() ) { |
|
395 | + if (is_product()) { |
|
396 | 396 | global $post; |
397 | 397 | |
398 | - $product = wc_get_product( $post->ID ); |
|
398 | + $product = wc_get_product($post->ID); |
|
399 | 399 | |
400 | - if ( ! is_object( $product ) || ! in_array( ( WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type() ), $this->supported_product_types() ) ) { |
|
400 | + if ( ! is_object($product) || ! in_array((WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type()), $this->supported_product_types())) { |
|
401 | 401 | return; |
402 | 402 | } |
403 | 403 | |
404 | - if ( apply_filters( 'wc_stripe_hide_payment_request_on_product_page', false ) ) { |
|
404 | + if (apply_filters('wc_stripe_hide_payment_request_on_product_page', false)) { |
|
405 | 405 | return; |
406 | 406 | } |
407 | 407 | } |
408 | 408 | |
409 | - $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
409 | + $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; |
|
410 | 410 | |
411 | - wp_register_script( 'stripe', 'https://js.stripe.com/v3/', '', '3.0', true ); |
|
412 | - 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 | + wp_register_script('stripe', 'https://js.stripe.com/v3/', '', '3.0', true); |
|
412 | + 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); |
|
413 | 413 | |
414 | 414 | wp_localize_script( |
415 | 415 | 'wc_stripe_payment_request', |
416 | 416 | 'wc_stripe_payment_request_params', |
417 | 417 | array( |
418 | - 'ajax_url' => WC_AJAX::get_endpoint( '%%endpoint%%' ), |
|
418 | + 'ajax_url' => WC_AJAX::get_endpoint('%%endpoint%%'), |
|
419 | 419 | 'stripe' => array( |
420 | 420 | 'key' => $this->publishable_key, |
421 | - 'allow_prepaid_card' => apply_filters( 'wc_stripe_allow_prepaid_card', true ) ? 'yes' : 'no', |
|
421 | + 'allow_prepaid_card' => apply_filters('wc_stripe_allow_prepaid_card', true) ? 'yes' : 'no', |
|
422 | 422 | ), |
423 | 423 | 'nonce' => array( |
424 | - 'payment' => wp_create_nonce( 'wc-stripe-payment-request' ), |
|
425 | - 'shipping' => wp_create_nonce( 'wc-stripe-payment-request-shipping' ), |
|
426 | - 'update_shipping' => wp_create_nonce( 'wc-stripe-update-shipping-method' ), |
|
427 | - 'checkout' => wp_create_nonce( 'woocommerce-process_checkout' ), |
|
428 | - 'add_to_cart' => wp_create_nonce( 'wc-stripe-add-to-cart' ), |
|
429 | - 'get_selected_product_data' => wp_create_nonce( 'wc-stripe-get-selected-product-data' ), |
|
430 | - 'log_errors' => wp_create_nonce( 'wc-stripe-log-errors' ), |
|
431 | - 'clear_cart' => wp_create_nonce( 'wc-stripe-clear-cart' ), |
|
424 | + 'payment' => wp_create_nonce('wc-stripe-payment-request'), |
|
425 | + 'shipping' => wp_create_nonce('wc-stripe-payment-request-shipping'), |
|
426 | + 'update_shipping' => wp_create_nonce('wc-stripe-update-shipping-method'), |
|
427 | + 'checkout' => wp_create_nonce('woocommerce-process_checkout'), |
|
428 | + 'add_to_cart' => wp_create_nonce('wc-stripe-add-to-cart'), |
|
429 | + 'get_selected_product_data' => wp_create_nonce('wc-stripe-get-selected-product-data'), |
|
430 | + 'log_errors' => wp_create_nonce('wc-stripe-log-errors'), |
|
431 | + 'clear_cart' => wp_create_nonce('wc-stripe-clear-cart'), |
|
432 | 432 | ), |
433 | 433 | 'i18n' => array( |
434 | - 'no_prepaid_card' => __( 'Sorry, we\'re not accepting prepaid cards at this time.', 'woocommerce-gateway-stripe' ), |
|
434 | + 'no_prepaid_card' => __('Sorry, we\'re not accepting prepaid cards at this time.', 'woocommerce-gateway-stripe'), |
|
435 | 435 | /* translators: Do not translate the [option] placeholder */ |
436 | - 'unknown_shipping' => __( 'Unknown shipping option "[option]".', 'woocommerce-gateway-stripe' ), |
|
436 | + 'unknown_shipping' => __('Unknown shipping option "[option]".', 'woocommerce-gateway-stripe'), |
|
437 | 437 | ), |
438 | 438 | 'checkout' => array( |
439 | 439 | 'url' => wc_get_checkout_url(), |
440 | - 'currency_code' => strtolower( get_woocommerce_currency() ), |
|
441 | - 'country_code' => substr( get_option( 'woocommerce_default_country' ), 0, 2 ), |
|
440 | + 'currency_code' => strtolower(get_woocommerce_currency()), |
|
441 | + 'country_code' => substr(get_option('woocommerce_default_country'), 0, 2), |
|
442 | 442 | 'needs_shipping' => WC()->cart->needs_shipping() ? 'yes' : 'no', |
443 | 443 | ), |
444 | 444 | 'button' => array( |
445 | 445 | 'type' => $this->get_button_type(), |
446 | 446 | 'theme' => $this->get_button_theme(), |
447 | 447 | 'height' => $this->get_button_height(), |
448 | - 'locale' => substr( get_locale(), 0, 2 ), // Default format is en_US. |
|
448 | + 'locale' => substr(get_locale(), 0, 2), // Default format is en_US. |
|
449 | 449 | ), |
450 | 450 | 'is_product_page' => is_product(), |
451 | 451 | 'product' => $this->get_product_data(), |
452 | 452 | ) |
453 | 453 | ); |
454 | 454 | |
455 | - wp_enqueue_script( 'wc_stripe_payment_request' ); |
|
455 | + wp_enqueue_script('wc_stripe_payment_request'); |
|
456 | 456 | } |
457 | 457 | |
458 | 458 | /** |
@@ -464,35 +464,35 @@ discard block |
||
464 | 464 | public function display_payment_request_button_html() { |
465 | 465 | $gateways = WC()->payment_gateways->get_available_payment_gateways(); |
466 | 466 | |
467 | - if ( ! isset( $gateways['stripe'] ) ) { |
|
467 | + if ( ! isset($gateways['stripe'])) { |
|
468 | 468 | return; |
469 | 469 | } |
470 | 470 | |
471 | - if ( ! is_cart() && ! is_checkout() && ! is_product() && ! isset( $_GET['pay_for_order'] ) ) { |
|
471 | + if ( ! is_cart() && ! is_checkout() && ! is_product() && ! isset($_GET['pay_for_order'])) { |
|
472 | 472 | return; |
473 | 473 | } |
474 | 474 | |
475 | - if ( is_product() && apply_filters( 'wc_stripe_hide_payment_request_on_product_page', false ) ) { |
|
475 | + if (is_product() && apply_filters('wc_stripe_hide_payment_request_on_product_page', false)) { |
|
476 | 476 | return; |
477 | 477 | } |
478 | 478 | |
479 | - if ( is_product() ) { |
|
479 | + if (is_product()) { |
|
480 | 480 | global $post; |
481 | 481 | |
482 | - $product = wc_get_product( $post->ID ); |
|
482 | + $product = wc_get_product($post->ID); |
|
483 | 483 | |
484 | - if ( ! is_object( $product ) || ! in_array( ( WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type() ), $this->supported_product_types() ) ) { |
|
484 | + if ( ! is_object($product) || ! in_array((WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type()), $this->supported_product_types())) { |
|
485 | 485 | return; |
486 | 486 | } |
487 | 487 | |
488 | 488 | // Pre Orders charge upon release not supported. |
489 | - if ( class_exists( 'WC_Pre_Orders_Order' ) && WC_Pre_Orders_Product::product_is_charged_upon_release( $product ) ) { |
|
490 | - WC_Stripe_Logger::log( 'Pre Order charge upon release is not supported. ( Payment Request button disabled )' ); |
|
489 | + if (class_exists('WC_Pre_Orders_Order') && WC_Pre_Orders_Product::product_is_charged_upon_release($product)) { |
|
490 | + WC_Stripe_Logger::log('Pre Order charge upon release is not supported. ( Payment Request button disabled )'); |
|
491 | 491 | return; |
492 | 492 | } |
493 | 493 | } else { |
494 | - if ( ! $this->allowed_items_in_cart() ) { |
|
495 | - WC_Stripe_Logger::log( 'Items in the cart has unsupported product type ( Payment Request button disabled )' ); |
|
494 | + if ( ! $this->allowed_items_in_cart()) { |
|
495 | + WC_Stripe_Logger::log('Items in the cart has unsupported product type ( Payment Request button disabled )'); |
|
496 | 496 | return; |
497 | 497 | } |
498 | 498 | } |
@@ -514,40 +514,40 @@ discard block |
||
514 | 514 | public function display_payment_request_button_separator_html() { |
515 | 515 | $gateways = WC()->payment_gateways->get_available_payment_gateways(); |
516 | 516 | |
517 | - if ( ! isset( $gateways['stripe'] ) ) { |
|
517 | + if ( ! isset($gateways['stripe'])) { |
|
518 | 518 | return; |
519 | 519 | } |
520 | 520 | |
521 | - if ( ! is_cart() && ! is_checkout() && ! is_product() && ! isset( $_GET['pay_for_order'] ) ) { |
|
521 | + if ( ! is_cart() && ! is_checkout() && ! is_product() && ! isset($_GET['pay_for_order'])) { |
|
522 | 522 | return; |
523 | 523 | } |
524 | 524 | |
525 | - if ( is_product() && apply_filters( 'wc_stripe_hide_payment_request_on_product_page', false ) ) { |
|
525 | + if (is_product() && apply_filters('wc_stripe_hide_payment_request_on_product_page', false)) { |
|
526 | 526 | return; |
527 | 527 | } |
528 | 528 | |
529 | - if ( is_product() ) { |
|
529 | + if (is_product()) { |
|
530 | 530 | global $post; |
531 | 531 | |
532 | - $product = wc_get_product( $post->ID ); |
|
532 | + $product = wc_get_product($post->ID); |
|
533 | 533 | |
534 | - if ( ! is_object( $product ) || ! in_array( ( WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type() ), $this->supported_product_types() ) ) { |
|
534 | + if ( ! is_object($product) || ! in_array((WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type()), $this->supported_product_types())) { |
|
535 | 535 | return; |
536 | 536 | } |
537 | 537 | |
538 | 538 | // Pre Orders charge upon release not supported. |
539 | - if ( class_exists( 'WC_Pre_Orders_Order' ) && WC_Pre_Orders_Product::product_is_charged_upon_release( $product ) ) { |
|
540 | - WC_Stripe_Logger::log( 'Pre Order charge upon release is not supported. ( Payment Request button disabled )' ); |
|
539 | + if (class_exists('WC_Pre_Orders_Order') && WC_Pre_Orders_Product::product_is_charged_upon_release($product)) { |
|
540 | + WC_Stripe_Logger::log('Pre Order charge upon release is not supported. ( Payment Request button disabled )'); |
|
541 | 541 | return; |
542 | 542 | } |
543 | 543 | } else { |
544 | - if ( ! $this->allowed_items_in_cart() ) { |
|
545 | - WC_Stripe_Logger::log( 'Items in the cart has unsupported product type ( Payment Request button disabled )' ); |
|
544 | + if ( ! $this->allowed_items_in_cart()) { |
|
545 | + WC_Stripe_Logger::log('Items in the cart has unsupported product type ( Payment Request button disabled )'); |
|
546 | 546 | return; |
547 | 547 | } |
548 | 548 | } |
549 | 549 | ?> |
550 | - <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> |
|
550 | + <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> |
|
551 | 551 | <?php |
552 | 552 | } |
553 | 553 | |
@@ -558,11 +558,11 @@ discard block |
||
558 | 558 | * @version 4.0.0 |
559 | 559 | */ |
560 | 560 | public function ajax_log_errors() { |
561 | - check_ajax_referer( 'wc-stripe-log-errors', 'security' ); |
|
561 | + check_ajax_referer('wc-stripe-log-errors', 'security'); |
|
562 | 562 | |
563 | - $errors = wc_clean( stripslashes( $_POST['errors'] ) ); |
|
563 | + $errors = wc_clean(stripslashes($_POST['errors'])); |
|
564 | 564 | |
565 | - WC_Stripe_Logger::log( $errors ); |
|
565 | + WC_Stripe_Logger::log($errors); |
|
566 | 566 | |
567 | 567 | exit; |
568 | 568 | } |
@@ -574,7 +574,7 @@ discard block |
||
574 | 574 | * @version 4.0.0 |
575 | 575 | */ |
576 | 576 | public function ajax_clear_cart() { |
577 | - check_ajax_referer( 'wc-stripe-clear-cart', 'security' ); |
|
577 | + check_ajax_referer('wc-stripe-clear-cart', 'security'); |
|
578 | 578 | |
579 | 579 | WC()->cart->empty_cart(); |
580 | 580 | exit; |
@@ -584,10 +584,10 @@ discard block |
||
584 | 584 | * Get cart details. |
585 | 585 | */ |
586 | 586 | public function ajax_get_cart_details() { |
587 | - check_ajax_referer( 'wc-stripe-payment-request', 'security' ); |
|
587 | + check_ajax_referer('wc-stripe-payment-request', 'security'); |
|
588 | 588 | |
589 | - if ( ! defined( 'WOOCOMMERCE_CART' ) ) { |
|
590 | - define( 'WOOCOMMERCE_CART', true ); |
|
589 | + if ( ! defined('WOOCOMMERCE_CART')) { |
|
590 | + define('WOOCOMMERCE_CART', true); |
|
591 | 591 | } |
592 | 592 | |
593 | 593 | WC()->cart->calculate_totals(); |
@@ -598,14 +598,14 @@ discard block |
||
598 | 598 | $data = array( |
599 | 599 | 'shipping_required' => WC()->cart->needs_shipping(), |
600 | 600 | 'order_data' => array( |
601 | - 'currency' => strtolower( $currency ), |
|
602 | - 'country_code' => substr( get_option( 'woocommerce_default_country' ), 0, 2 ), |
|
601 | + 'currency' => strtolower($currency), |
|
602 | + 'country_code' => substr(get_option('woocommerce_default_country'), 0, 2), |
|
603 | 603 | ), |
604 | 604 | ); |
605 | 605 | |
606 | 606 | $data['order_data'] += $this->build_display_items(); |
607 | 607 | |
608 | - wp_send_json( $data ); |
|
608 | + wp_send_json($data); |
|
609 | 609 | } |
610 | 610 | |
611 | 611 | /** |
@@ -616,47 +616,47 @@ discard block |
||
616 | 616 | * @see WC_Shipping::get_packages(). |
617 | 617 | */ |
618 | 618 | public function ajax_get_shipping_options() { |
619 | - check_ajax_referer( 'wc-stripe-payment-request-shipping', 'security' ); |
|
619 | + check_ajax_referer('wc-stripe-payment-request-shipping', 'security'); |
|
620 | 620 | |
621 | 621 | try { |
622 | 622 | // Set the shipping package. |
623 | - $posted = filter_input_array( INPUT_POST, array( |
|
623 | + $posted = filter_input_array(INPUT_POST, array( |
|
624 | 624 | 'country' => FILTER_SANITIZE_STRING, |
625 | 625 | 'state' => FILTER_SANITIZE_STRING, |
626 | 626 | 'postcode' => FILTER_SANITIZE_STRING, |
627 | 627 | 'city' => FILTER_SANITIZE_STRING, |
628 | 628 | 'address' => FILTER_SANITIZE_STRING, |
629 | 629 | 'address_2' => FILTER_SANITIZE_STRING, |
630 | - ) ); |
|
630 | + )); |
|
631 | 631 | |
632 | - $this->calculate_shipping( $posted ); |
|
632 | + $this->calculate_shipping($posted); |
|
633 | 633 | |
634 | 634 | // Set the shipping options. |
635 | 635 | $data = array(); |
636 | 636 | $packages = WC()->shipping->get_packages(); |
637 | 637 | |
638 | - if ( ! empty( $packages ) && WC()->customer->has_calculated_shipping() ) { |
|
639 | - foreach ( $packages as $package_key => $package ) { |
|
640 | - if ( empty( $package['rates'] ) ) { |
|
641 | - throw new Exception( __( 'Unable to find shipping method for address.', 'woocommerce-gateway-stripe' ) ); |
|
638 | + if ( ! empty($packages) && WC()->customer->has_calculated_shipping()) { |
|
639 | + foreach ($packages as $package_key => $package) { |
|
640 | + if (empty($package['rates'])) { |
|
641 | + throw new Exception(__('Unable to find shipping method for address.', 'woocommerce-gateway-stripe')); |
|
642 | 642 | } |
643 | 643 | |
644 | - foreach ( $package['rates'] as $key => $rate ) { |
|
644 | + foreach ($package['rates'] as $key => $rate) { |
|
645 | 645 | $data['shipping_options'][] = array( |
646 | 646 | 'id' => $rate->id, |
647 | 647 | 'label' => $rate->label, |
648 | 648 | 'detail' => '', |
649 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $rate->cost ), |
|
649 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($rate->cost), |
|
650 | 650 | ); |
651 | 651 | } |
652 | 652 | } |
653 | 653 | } else { |
654 | - throw new Exception( __( 'Unable to find shipping method for address.', 'woocommerce-gateway-stripe' ) ); |
|
654 | + throw new Exception(__('Unable to find shipping method for address.', 'woocommerce-gateway-stripe')); |
|
655 | 655 | } |
656 | 656 | |
657 | - if ( isset( $data[0] ) ) { |
|
657 | + if (isset($data[0])) { |
|
658 | 658 | // Auto select the first shipping method. |
659 | - WC()->session->set( 'chosen_shipping_methods', array( $data[0]['id'] ) ); |
|
659 | + WC()->session->set('chosen_shipping_methods', array($data[0]['id'])); |
|
660 | 660 | } |
661 | 661 | |
662 | 662 | WC()->cart->calculate_totals(); |
@@ -664,12 +664,12 @@ discard block |
||
664 | 664 | $data += $this->build_display_items(); |
665 | 665 | $data['result'] = 'success'; |
666 | 666 | |
667 | - wp_send_json( $data ); |
|
668 | - } catch ( Exception $e ) { |
|
667 | + wp_send_json($data); |
|
668 | + } catch (Exception $e) { |
|
669 | 669 | $data += $this->build_display_items(); |
670 | 670 | $data['result'] = 'invalid_shipping_address'; |
671 | 671 | |
672 | - wp_send_json( $data ); |
|
672 | + wp_send_json($data); |
|
673 | 673 | } |
674 | 674 | } |
675 | 675 | |
@@ -677,22 +677,22 @@ discard block |
||
677 | 677 | * Update shipping method. |
678 | 678 | */ |
679 | 679 | public function ajax_update_shipping_method() { |
680 | - check_ajax_referer( 'wc-stripe-update-shipping-method', 'security' ); |
|
680 | + check_ajax_referer('wc-stripe-update-shipping-method', 'security'); |
|
681 | 681 | |
682 | - if ( ! defined( 'WOOCOMMERCE_CART' ) ) { |
|
683 | - define( 'WOOCOMMERCE_CART', true ); |
|
682 | + if ( ! defined('WOOCOMMERCE_CART')) { |
|
683 | + define('WOOCOMMERCE_CART', true); |
|
684 | 684 | } |
685 | 685 | |
686 | - $chosen_shipping_methods = WC()->session->get( 'chosen_shipping_methods' ); |
|
687 | - $shipping_method = filter_input( INPUT_POST, 'shipping_method', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY ); |
|
686 | + $chosen_shipping_methods = WC()->session->get('chosen_shipping_methods'); |
|
687 | + $shipping_method = filter_input(INPUT_POST, 'shipping_method', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY); |
|
688 | 688 | |
689 | - if ( is_array( $shipping_method ) ) { |
|
690 | - foreach ( $shipping_method as $i => $value ) { |
|
691 | - $chosen_shipping_methods[ $i ] = wc_clean( $value ); |
|
689 | + if (is_array($shipping_method)) { |
|
690 | + foreach ($shipping_method as $i => $value) { |
|
691 | + $chosen_shipping_methods[$i] = wc_clean($value); |
|
692 | 692 | } |
693 | 693 | } |
694 | 694 | |
695 | - WC()->session->set( 'chosen_shipping_methods', $chosen_shipping_methods ); |
|
695 | + WC()->session->set('chosen_shipping_methods', $chosen_shipping_methods); |
|
696 | 696 | |
697 | 697 | WC()->cart->calculate_totals(); |
698 | 698 | |
@@ -700,7 +700,7 @@ discard block |
||
700 | 700 | $data += $this->build_display_items(); |
701 | 701 | $data['result'] = 'success'; |
702 | 702 | |
703 | - wp_send_json( $data ); |
|
703 | + wp_send_json($data); |
|
704 | 704 | } |
705 | 705 | |
706 | 706 | /** |
@@ -711,31 +711,31 @@ discard block |
||
711 | 711 | * @return array $data |
712 | 712 | */ |
713 | 713 | public function ajax_get_selected_product_data() { |
714 | - check_ajax_referer( 'wc-stripe-get-selected-product-data', 'security' ); |
|
714 | + check_ajax_referer('wc-stripe-get-selected-product-data', 'security'); |
|
715 | 715 | |
716 | - $product_id = absint( $_POST['product_id'] ); |
|
717 | - $qty = ! isset( $_POST['qty'] ) ? 1 : absint( $_POST['qty'] ); |
|
716 | + $product_id = absint($_POST['product_id']); |
|
717 | + $qty = ! isset($_POST['qty']) ? 1 : absint($_POST['qty']); |
|
718 | 718 | |
719 | - $product = wc_get_product( $product_id ); |
|
719 | + $product = wc_get_product($product_id); |
|
720 | 720 | |
721 | - if ( 'variable' === ( WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type() ) && isset( $_POST['attributes'] ) ) { |
|
722 | - $attributes = array_map( 'wc_clean', $_POST['attributes'] ); |
|
721 | + if ('variable' === (WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type()) && isset($_POST['attributes'])) { |
|
722 | + $attributes = array_map('wc_clean', $_POST['attributes']); |
|
723 | 723 | |
724 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
725 | - $variation_id = $product->get_matching_variation( $attributes ); |
|
724 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
725 | + $variation_id = $product->get_matching_variation($attributes); |
|
726 | 726 | } else { |
727 | - $data_store = WC_Data_Store::load( 'product' ); |
|
728 | - $variation_id = $data_store->find_matching_product_variation( $product, $attributes ); |
|
727 | + $data_store = WC_Data_Store::load('product'); |
|
728 | + $variation_id = $data_store->find_matching_product_variation($product, $attributes); |
|
729 | 729 | } |
730 | 730 | |
731 | - if ( ! empty( $variation_id ) ) { |
|
732 | - $product = wc_get_product( $variation_id ); |
|
731 | + if ( ! empty($variation_id)) { |
|
732 | + $product = wc_get_product($variation_id); |
|
733 | 733 | } |
734 | - } elseif ( 'simple' === ( WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type() ) ) { |
|
735 | - $product = wc_get_product( $product_id ); |
|
734 | + } elseif ('simple' === (WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type())) { |
|
735 | + $product = wc_get_product($product_id); |
|
736 | 736 | } |
737 | 737 | |
738 | - $total = $qty * ( WC_Stripe_Helper::is_pre_30() ? $product->price : $product->get_price() ); |
|
738 | + $total = $qty * (WC_Stripe_Helper::is_pre_30() ? $product->price : $product->get_price()); |
|
739 | 739 | |
740 | 740 | $quantity_label = 1 < $qty ? ' (x' . $qty . ')' : ''; |
741 | 741 | |
@@ -743,28 +743,28 @@ discard block |
||
743 | 743 | $items = array(); |
744 | 744 | |
745 | 745 | $items[] = array( |
746 | - 'label' => ( WC_Stripe_Helper::is_pre_30() ? $product->name : $product->get_name() ) . $quantity_label, |
|
747 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $total ), |
|
746 | + 'label' => (WC_Stripe_Helper::is_pre_30() ? $product->name : $product->get_name()) . $quantity_label, |
|
747 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($total), |
|
748 | 748 | ); |
749 | 749 | |
750 | - if ( wc_tax_enabled() ) { |
|
750 | + if (wc_tax_enabled()) { |
|
751 | 751 | $items[] = array( |
752 | - 'label' => __( 'Tax', 'woocommerce-gateway-stripe' ), |
|
752 | + 'label' => __('Tax', 'woocommerce-gateway-stripe'), |
|
753 | 753 | 'amount' => 0, |
754 | 754 | 'pending' => true, |
755 | 755 | ); |
756 | 756 | } |
757 | 757 | |
758 | - if ( wc_shipping_enabled() && $product->needs_shipping() ) { |
|
758 | + if (wc_shipping_enabled() && $product->needs_shipping()) { |
|
759 | 759 | $items[] = array( |
760 | - 'label' => __( 'Shipping', 'woocommerce-gateway-stripe' ), |
|
760 | + 'label' => __('Shipping', 'woocommerce-gateway-stripe'), |
|
761 | 761 | 'amount' => 0, |
762 | 762 | 'pending' => true, |
763 | 763 | ); |
764 | 764 | |
765 | - $data['shippingOptions'] = array( |
|
765 | + $data['shippingOptions'] = array( |
|
766 | 766 | 'id' => 'pending', |
767 | - 'label' => __( 'Pending', 'woocommerce-gateway-stripe' ), |
|
767 | + 'label' => __('Pending', 'woocommerce-gateway-stripe'), |
|
768 | 768 | 'detail' => '', |
769 | 769 | 'amount' => 0, |
770 | 770 | ); |
@@ -773,15 +773,15 @@ discard block |
||
773 | 773 | $data['displayItems'] = $items; |
774 | 774 | $data['total'] = array( |
775 | 775 | 'label' => $this->total_label, |
776 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $total ), |
|
776 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($total), |
|
777 | 777 | 'pending' => true, |
778 | 778 | ); |
779 | 779 | |
780 | - $data['requestShipping'] = ( wc_shipping_enabled() && $product->needs_shipping() ); |
|
781 | - $data['currency'] = strtolower( get_woocommerce_currency() ); |
|
782 | - $data['country_code'] = substr( get_option( 'woocommerce_default_country' ), 0, 2 ); |
|
780 | + $data['requestShipping'] = (wc_shipping_enabled() && $product->needs_shipping()); |
|
781 | + $data['currency'] = strtolower(get_woocommerce_currency()); |
|
782 | + $data['country_code'] = substr(get_option('woocommerce_default_country'), 0, 2); |
|
783 | 783 | |
784 | - wp_send_json( $data ); |
|
784 | + wp_send_json($data); |
|
785 | 785 | } |
786 | 786 | |
787 | 787 | /** |
@@ -792,37 +792,37 @@ discard block |
||
792 | 792 | * @return array $data |
793 | 793 | */ |
794 | 794 | public function ajax_add_to_cart() { |
795 | - check_ajax_referer( 'wc-stripe-add-to-cart', 'security' ); |
|
795 | + check_ajax_referer('wc-stripe-add-to-cart', 'security'); |
|
796 | 796 | |
797 | - if ( ! defined( 'WOOCOMMERCE_CART' ) ) { |
|
798 | - define( 'WOOCOMMERCE_CART', true ); |
|
797 | + if ( ! defined('WOOCOMMERCE_CART')) { |
|
798 | + define('WOOCOMMERCE_CART', true); |
|
799 | 799 | } |
800 | 800 | |
801 | 801 | WC()->shipping->reset_shipping(); |
802 | 802 | |
803 | - $product_id = absint( $_POST['product_id'] ); |
|
804 | - $qty = ! isset( $_POST['qty'] ) ? 1 : absint( $_POST['qty'] ); |
|
803 | + $product_id = absint($_POST['product_id']); |
|
804 | + $qty = ! isset($_POST['qty']) ? 1 : absint($_POST['qty']); |
|
805 | 805 | |
806 | - $product = wc_get_product( $product_id ); |
|
806 | + $product = wc_get_product($product_id); |
|
807 | 807 | |
808 | 808 | // First empty the cart to prevent wrong calculation. |
809 | 809 | WC()->cart->empty_cart(); |
810 | 810 | |
811 | - if ( 'variable' === ( WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type() ) && isset( $_POST['attributes'] ) ) { |
|
812 | - $attributes = array_map( 'wc_clean', $_POST['attributes'] ); |
|
811 | + if ('variable' === (WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type()) && isset($_POST['attributes'])) { |
|
812 | + $attributes = array_map('wc_clean', $_POST['attributes']); |
|
813 | 813 | |
814 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
815 | - $variation_id = $product->get_matching_variation( $attributes ); |
|
814 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
815 | + $variation_id = $product->get_matching_variation($attributes); |
|
816 | 816 | } else { |
817 | - $data_store = WC_Data_Store::load( 'product' ); |
|
818 | - $variation_id = $data_store->find_matching_product_variation( $product, $attributes ); |
|
817 | + $data_store = WC_Data_Store::load('product'); |
|
818 | + $variation_id = $data_store->find_matching_product_variation($product, $attributes); |
|
819 | 819 | } |
820 | 820 | |
821 | - WC()->cart->add_to_cart( $product->get_id(), $qty, $variation_id, $attributes ); |
|
821 | + WC()->cart->add_to_cart($product->get_id(), $qty, $variation_id, $attributes); |
|
822 | 822 | } |
823 | 823 | |
824 | - if ( 'simple' === ( WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type() ) ) { |
|
825 | - WC()->cart->add_to_cart( $product->get_id(), $qty ); |
|
824 | + if ('simple' === (WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type())) { |
|
825 | + WC()->cart->add_to_cart($product->get_id(), $qty); |
|
826 | 826 | } |
827 | 827 | |
828 | 828 | WC()->cart->calculate_totals(); |
@@ -831,7 +831,7 @@ discard block |
||
831 | 831 | $data += $this->build_display_items(); |
832 | 832 | $data['result'] = 'success'; |
833 | 833 | |
834 | - wp_send_json( $data ); |
|
834 | + wp_send_json($data); |
|
835 | 835 | } |
836 | 836 | |
837 | 837 | /** |
@@ -844,31 +844,31 @@ discard block |
||
844 | 844 | * @version 4.0.0 |
845 | 845 | */ |
846 | 846 | public function normalize_state() { |
847 | - $billing_country = ! empty( $_POST['billing_country'] ) ? wc_clean( $_POST['billing_country'] ) : ''; |
|
848 | - $shipping_country = ! empty( $_POST['shipping_country'] ) ? wc_clean( $_POST['shipping_country'] ) : ''; |
|
849 | - $billing_state = ! empty( $_POST['billing_state'] ) ? wc_clean( $_POST['billing_state'] ) : ''; |
|
850 | - $shipping_state = ! empty( $_POST['shipping_state'] ) ? wc_clean( $_POST['shipping_state'] ) : ''; |
|
847 | + $billing_country = ! empty($_POST['billing_country']) ? wc_clean($_POST['billing_country']) : ''; |
|
848 | + $shipping_country = ! empty($_POST['shipping_country']) ? wc_clean($_POST['shipping_country']) : ''; |
|
849 | + $billing_state = ! empty($_POST['billing_state']) ? wc_clean($_POST['billing_state']) : ''; |
|
850 | + $shipping_state = ! empty($_POST['shipping_state']) ? wc_clean($_POST['shipping_state']) : ''; |
|
851 | 851 | |
852 | - if ( $billing_state && $billing_country ) { |
|
853 | - $valid_states = WC()->countries->get_states( $billing_country ); |
|
852 | + if ($billing_state && $billing_country) { |
|
853 | + $valid_states = WC()->countries->get_states($billing_country); |
|
854 | 854 | |
855 | 855 | // Valid states found for country. |
856 | - if ( ! empty( $valid_states ) && is_array( $valid_states ) && sizeof( $valid_states ) > 0 ) { |
|
857 | - foreach ( $valid_states as $state_abbr => $state ) { |
|
858 | - if ( preg_match( '/' . preg_quote( $state ) . '/i', $billing_state ) ) { |
|
856 | + if ( ! empty($valid_states) && is_array($valid_states) && sizeof($valid_states) > 0) { |
|
857 | + foreach ($valid_states as $state_abbr => $state) { |
|
858 | + if (preg_match('/' . preg_quote($state) . '/i', $billing_state)) { |
|
859 | 859 | $_POST['billing_state'] = $state_abbr; |
860 | 860 | } |
861 | 861 | } |
862 | 862 | } |
863 | 863 | } |
864 | 864 | |
865 | - if ( $shipping_state && $shipping_country ) { |
|
866 | - $valid_states = WC()->countries->get_states( $shipping_country ); |
|
865 | + if ($shipping_state && $shipping_country) { |
|
866 | + $valid_states = WC()->countries->get_states($shipping_country); |
|
867 | 867 | |
868 | 868 | // Valid states found for country. |
869 | - if ( ! empty( $valid_states ) && is_array( $valid_states ) && sizeof( $valid_states ) > 0 ) { |
|
870 | - foreach ( $valid_states as $state_abbr => $state ) { |
|
871 | - if ( preg_match( '/' . preg_quote( $state ) . '/i', $shipping_state ) ) { |
|
869 | + if ( ! empty($valid_states) && is_array($valid_states) && sizeof($valid_states) > 0) { |
|
870 | + foreach ($valid_states as $state_abbr => $state) { |
|
871 | + if (preg_match('/' . preg_quote($state) . '/i', $shipping_state)) { |
|
872 | 872 | $_POST['shipping_state'] = $state_abbr; |
873 | 873 | } |
874 | 874 | } |
@@ -883,19 +883,19 @@ discard block |
||
883 | 883 | * @version 4.0.0 |
884 | 884 | */ |
885 | 885 | public function ajax_create_order() { |
886 | - if ( WC()->cart->is_empty() ) { |
|
887 | - wp_send_json_error( __( 'Empty cart', 'woocommerce-gateway-stripe' ) ); |
|
886 | + if (WC()->cart->is_empty()) { |
|
887 | + wp_send_json_error(__('Empty cart', 'woocommerce-gateway-stripe')); |
|
888 | 888 | } |
889 | 889 | |
890 | - if ( ! defined( 'WOOCOMMERCE_CHECKOUT' ) ) { |
|
891 | - define( 'WOOCOMMERCE_CHECKOUT', true ); |
|
890 | + if ( ! defined('WOOCOMMERCE_CHECKOUT')) { |
|
891 | + define('WOOCOMMERCE_CHECKOUT', true); |
|
892 | 892 | } |
893 | 893 | |
894 | 894 | $this->normalize_state(); |
895 | 895 | |
896 | 896 | WC()->checkout()->process_checkout(); |
897 | 897 | |
898 | - die( 0 ); |
|
898 | + die(0); |
|
899 | 899 | } |
900 | 900 | |
901 | 901 | /** |
@@ -905,7 +905,7 @@ discard block |
||
905 | 905 | * @version 4.0.0 |
906 | 906 | * @param array $address |
907 | 907 | */ |
908 | - protected function calculate_shipping( $address = array() ) { |
|
908 | + protected function calculate_shipping($address = array()) { |
|
909 | 909 | global $states; |
910 | 910 | |
911 | 911 | $country = $address['country']; |
@@ -922,28 +922,28 @@ discard block |
||
922 | 922 | * In some versions of Chrome, state can be a full name. So we need |
923 | 923 | * to convert that to abbreviation as WC is expecting that. |
924 | 924 | */ |
925 | - if ( 2 < strlen( $state ) ) { |
|
926 | - $state = array_search( ucfirst( strtolower( $state ) ), $states[ $country ] ); |
|
925 | + if (2 < strlen($state)) { |
|
926 | + $state = array_search(ucfirst(strtolower($state)), $states[$country]); |
|
927 | 927 | } |
928 | 928 | |
929 | 929 | WC()->shipping->reset_shipping(); |
930 | 930 | |
931 | - if ( $postcode && WC_Validation::is_postcode( $postcode, $country ) ) { |
|
932 | - $postcode = wc_format_postcode( $postcode, $country ); |
|
931 | + if ($postcode && WC_Validation::is_postcode($postcode, $country)) { |
|
932 | + $postcode = wc_format_postcode($postcode, $country); |
|
933 | 933 | } |
934 | 934 | |
935 | - if ( $country ) { |
|
936 | - WC()->customer->set_location( $country, $state, $postcode, $city ); |
|
937 | - WC()->customer->set_shipping_location( $country, $state, $postcode, $city ); |
|
935 | + if ($country) { |
|
936 | + WC()->customer->set_location($country, $state, $postcode, $city); |
|
937 | + WC()->customer->set_shipping_location($country, $state, $postcode, $city); |
|
938 | 938 | } else { |
939 | 939 | WC_Stripe_Helper::is_pre_30() ? WC()->customer->set_to_base() : WC()->customer->set_billing_address_to_base(); |
940 | 940 | WC_Stripe_Helper::is_pre_30() ? WC()->customer->set_shipping_to_base() : WC()->customer->set_shipping_address_to_base(); |
941 | 941 | } |
942 | 942 | |
943 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
944 | - WC()->customer->calculated_shipping( true ); |
|
943 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
944 | + WC()->customer->calculated_shipping(true); |
|
945 | 945 | } else { |
946 | - WC()->customer->set_calculated_shipping( true ); |
|
946 | + WC()->customer->set_calculated_shipping(true); |
|
947 | 947 | WC()->customer->save(); |
948 | 948 | } |
949 | 949 | |
@@ -960,17 +960,17 @@ discard block |
||
960 | 960 | $packages[0]['destination']['address'] = $address_1; |
961 | 961 | $packages[0]['destination']['address_2'] = $address_2; |
962 | 962 | |
963 | - foreach ( WC()->cart->get_cart() as $item ) { |
|
964 | - if ( $item['data']->needs_shipping() ) { |
|
965 | - if ( isset( $item['line_total'] ) ) { |
|
963 | + foreach (WC()->cart->get_cart() as $item) { |
|
964 | + if ($item['data']->needs_shipping()) { |
|
965 | + if (isset($item['line_total'])) { |
|
966 | 966 | $packages[0]['contents_cost'] += $item['line_total']; |
967 | 967 | } |
968 | 968 | } |
969 | 969 | } |
970 | 970 | |
971 | - $packages = apply_filters( 'woocommerce_cart_shipping_packages', $packages ); |
|
971 | + $packages = apply_filters('woocommerce_cart_shipping_packages', $packages); |
|
972 | 972 | |
973 | - WC()->shipping->calculate_shipping( $packages ); |
|
973 | + WC()->shipping->calculate_shipping($packages); |
|
974 | 974 | } |
975 | 975 | |
976 | 976 | /** |
@@ -979,19 +979,19 @@ discard block |
||
979 | 979 | * @since 3.1.0 |
980 | 980 | * @version 4.0.0 |
981 | 981 | */ |
982 | - protected function build_shipping_methods( $shipping_methods ) { |
|
983 | - if ( empty( $shipping_methods ) ) { |
|
982 | + protected function build_shipping_methods($shipping_methods) { |
|
983 | + if (empty($shipping_methods)) { |
|
984 | 984 | return array(); |
985 | 985 | } |
986 | 986 | |
987 | 987 | $shipping = array(); |
988 | 988 | |
989 | - foreach ( $shipping_methods as $method ) { |
|
989 | + foreach ($shipping_methods as $method) { |
|
990 | 990 | $shipping[] = array( |
991 | 991 | 'id' => $method['id'], |
992 | 992 | 'label' => $method['label'], |
993 | 993 | 'detail' => '', |
994 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $method['amount']['value'] ), |
|
994 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($method['amount']['value']), |
|
995 | 995 | ); |
996 | 996 | } |
997 | 997 | |
@@ -1005,69 +1005,69 @@ discard block |
||
1005 | 1005 | * @version 4.0.0 |
1006 | 1006 | */ |
1007 | 1007 | protected function build_display_items() { |
1008 | - if ( ! defined( 'WOOCOMMERCE_CART' ) ) { |
|
1009 | - define( 'WOOCOMMERCE_CART', true ); |
|
1008 | + if ( ! defined('WOOCOMMERCE_CART')) { |
|
1009 | + define('WOOCOMMERCE_CART', true); |
|
1010 | 1010 | } |
1011 | 1011 | |
1012 | 1012 | $items = array(); |
1013 | 1013 | $subtotal = 0; |
1014 | 1014 | |
1015 | 1015 | // Default show only subtotal instead of itemization. |
1016 | - if ( ! apply_filters( 'wc_stripe_payment_request_hide_itemization', true ) ) { |
|
1017 | - foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) { |
|
1016 | + if ( ! apply_filters('wc_stripe_payment_request_hide_itemization', true)) { |
|
1017 | + foreach (WC()->cart->get_cart() as $cart_item_key => $cart_item) { |
|
1018 | 1018 | $amount = $cart_item['line_subtotal']; |
1019 | - $subtotal += $cart_item['line_subtotal']; |
|
1019 | + $subtotal += $cart_item['line_subtotal']; |
|
1020 | 1020 | $quantity_label = 1 < $cart_item['quantity'] ? ' (x' . $cart_item['quantity'] . ')' : ''; |
1021 | 1021 | |
1022 | 1022 | $product_name = WC_Stripe_Helper::is_pre_30() ? $cart_item['data']->post->post_title : $cart_item['data']->get_name(); |
1023 | 1023 | |
1024 | 1024 | $item = array( |
1025 | 1025 | 'label' => $product_name . $quantity_label, |
1026 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $amount ), |
|
1026 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($amount), |
|
1027 | 1027 | ); |
1028 | 1028 | |
1029 | 1029 | $items[] = $item; |
1030 | 1030 | } |
1031 | 1031 | } |
1032 | 1032 | |
1033 | - $discounts = wc_format_decimal( WC()->cart->get_cart_discount_total(), WC()->cart->dp ); |
|
1034 | - $tax = wc_format_decimal( WC()->cart->tax_total + WC()->cart->shipping_tax_total, WC()->cart->dp ); |
|
1035 | - $shipping = wc_format_decimal( WC()->cart->shipping_total, WC()->cart->dp ); |
|
1036 | - $items_total = wc_format_decimal( WC()->cart->cart_contents_total, WC()->cart->dp ) + $discounts; |
|
1037 | - $order_total = wc_format_decimal( $items_total + $tax + $shipping - $discounts, WC()->cart->dp ); |
|
1033 | + $discounts = wc_format_decimal(WC()->cart->get_cart_discount_total(), WC()->cart->dp); |
|
1034 | + $tax = wc_format_decimal(WC()->cart->tax_total + WC()->cart->shipping_tax_total, WC()->cart->dp); |
|
1035 | + $shipping = wc_format_decimal(WC()->cart->shipping_total, WC()->cart->dp); |
|
1036 | + $items_total = wc_format_decimal(WC()->cart->cart_contents_total, WC()->cart->dp) + $discounts; |
|
1037 | + $order_total = wc_format_decimal($items_total + $tax + $shipping - $discounts, WC()->cart->dp); |
|
1038 | 1038 | |
1039 | - if ( wc_tax_enabled() ) { |
|
1039 | + if (wc_tax_enabled()) { |
|
1040 | 1040 | $items[] = array( |
1041 | - 'label' => esc_html( __( 'Tax', 'woocommerce-gateway-stripe' ) ), |
|
1042 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $tax ), |
|
1041 | + 'label' => esc_html(__('Tax', 'woocommerce-gateway-stripe')), |
|
1042 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($tax), |
|
1043 | 1043 | ); |
1044 | 1044 | } |
1045 | 1045 | |
1046 | - if ( WC()->cart->needs_shipping() ) { |
|
1046 | + if (WC()->cart->needs_shipping()) { |
|
1047 | 1047 | $items[] = array( |
1048 | - 'label' => esc_html( __( 'Shipping', 'woocommerce-gateway-stripe' ) ), |
|
1049 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $shipping ), |
|
1048 | + 'label' => esc_html(__('Shipping', 'woocommerce-gateway-stripe')), |
|
1049 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($shipping), |
|
1050 | 1050 | ); |
1051 | 1051 | } |
1052 | 1052 | |
1053 | - if ( WC()->cart->has_discount() ) { |
|
1053 | + if (WC()->cart->has_discount()) { |
|
1054 | 1054 | $items[] = array( |
1055 | - 'label' => esc_html( __( 'Discount', 'woocommerce-gateway-stripe' ) ), |
|
1056 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $discounts ), |
|
1055 | + 'label' => esc_html(__('Discount', 'woocommerce-gateway-stripe')), |
|
1056 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($discounts), |
|
1057 | 1057 | ); |
1058 | 1058 | } |
1059 | 1059 | |
1060 | - if ( version_compare( WC_VERSION, '3.2', '<' ) ) { |
|
1060 | + if (version_compare(WC_VERSION, '3.2', '<')) { |
|
1061 | 1061 | $cart_fees = WC()->cart->fees; |
1062 | 1062 | } else { |
1063 | 1063 | $cart_fees = WC()->cart->get_fees(); |
1064 | 1064 | } |
1065 | 1065 | |
1066 | 1066 | // Include fees and taxes as display items. |
1067 | - foreach ( $cart_fees as $key => $fee ) { |
|
1067 | + foreach ($cart_fees as $key => $fee) { |
|
1068 | 1068 | $items[] = array( |
1069 | 1069 | 'label' => $fee->name, |
1070 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $fee->amount ), |
|
1070 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($fee->amount), |
|
1071 | 1071 | ); |
1072 | 1072 | } |
1073 | 1073 | |
@@ -1075,7 +1075,7 @@ discard block |
||
1075 | 1075 | 'displayItems' => $items, |
1076 | 1076 | 'total' => array( |
1077 | 1077 | 'label' => $this->total_label, |
1078 | - 'amount' => max( 0, apply_filters( 'woocommerce_stripe_calculated_total', WC_Stripe_Helper::get_stripe_amount( $order_total ), $order_total, WC()->cart ) ), |
|
1078 | + 'amount' => max(0, apply_filters('woocommerce_stripe_calculated_total', WC_Stripe_Helper::get_stripe_amount($order_total), $order_total, WC()->cart)), |
|
1079 | 1079 | 'pending' => false, |
1080 | 1080 | ), |
1081 | 1081 | ); |