@@ -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,39 +56,39 @@ 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 | |
91 | - add_action( 'woocommerce_init', array( $this, 'init' ), 100 ); |
|
91 | + add_action('woocommerce_init', array($this, 'init'), 100); |
|
92 | 92 | } |
93 | 93 | |
94 | 94 | /** |
@@ -98,40 +98,40 @@ discard block |
||
98 | 98 | * @version 4.0.0 |
99 | 99 | */ |
100 | 100 | public function init() { |
101 | - add_action( 'wp_enqueue_scripts', array( $this, 'scripts' ) ); |
|
101 | + add_action('wp_enqueue_scripts', array($this, 'scripts')); |
|
102 | 102 | |
103 | 103 | /* |
104 | 104 | * In order to display the Payment Request button in the correct position, |
105 | 105 | * a new hook was added to WooCommerce 3.0. In older versions of WooCommerce, |
106 | 106 | * CSS is used to position the button. |
107 | 107 | */ |
108 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
109 | - add_action( 'woocommerce_after_add_to_cart_button', array( $this, 'display_payment_request_button_html' ), 1 ); |
|
110 | - add_action( 'woocommerce_after_add_to_cart_button', array( $this, 'display_payment_request_button_separator_html' ), 2 ); |
|
108 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
109 | + add_action('woocommerce_after_add_to_cart_button', array($this, 'display_payment_request_button_html'), 1); |
|
110 | + add_action('woocommerce_after_add_to_cart_button', array($this, 'display_payment_request_button_separator_html'), 2); |
|
111 | 111 | } else { |
112 | - add_action( 'woocommerce_after_add_to_cart_quantity', array( $this, 'display_payment_request_button_html' ), 1 ); |
|
113 | - add_action( 'woocommerce_after_add_to_cart_quantity', array( $this, 'display_payment_request_button_separator_html' ), 2 ); |
|
112 | + add_action('woocommerce_after_add_to_cart_quantity', array($this, 'display_payment_request_button_html'), 1); |
|
113 | + add_action('woocommerce_after_add_to_cart_quantity', array($this, 'display_payment_request_button_separator_html'), 2); |
|
114 | 114 | } |
115 | 115 | |
116 | - add_action( 'woocommerce_proceed_to_checkout', array( $this, 'display_payment_request_button_html' ), 1 ); |
|
117 | - add_action( 'woocommerce_proceed_to_checkout', array( $this, 'display_payment_request_button_separator_html' ), 2 ); |
|
116 | + add_action('woocommerce_proceed_to_checkout', array($this, 'display_payment_request_button_html'), 1); |
|
117 | + add_action('woocommerce_proceed_to_checkout', array($this, 'display_payment_request_button_separator_html'), 2); |
|
118 | 118 | |
119 | - add_action( 'woocommerce_checkout_before_customer_details', array( $this, 'display_payment_request_button_html' ), 1 ); |
|
120 | - add_action( 'woocommerce_checkout_before_customer_details', array( $this, 'display_payment_request_button_separator_html' ), 2 ); |
|
119 | + add_action('woocommerce_checkout_before_customer_details', array($this, 'display_payment_request_button_html'), 1); |
|
120 | + add_action('woocommerce_checkout_before_customer_details', array($this, 'display_payment_request_button_separator_html'), 2); |
|
121 | 121 | |
122 | - add_action( 'wc_ajax_wc_stripe_get_cart_details', array( $this, 'ajax_get_cart_details' ) ); |
|
123 | - add_action( 'wc_ajax_wc_stripe_get_shipping_options', array( $this, 'ajax_get_shipping_options' ) ); |
|
124 | - add_action( 'wc_ajax_wc_stripe_update_shipping_method', array( $this, 'ajax_update_shipping_method' ) ); |
|
125 | - add_action( 'wc_ajax_wc_stripe_create_order', array( $this, 'ajax_create_order' ) ); |
|
126 | - add_action( 'wc_ajax_wc_stripe_add_to_cart', array( $this, 'ajax_add_to_cart' ) ); |
|
127 | - add_action( 'wc_ajax_wc_stripe_get_selected_product_data', array( $this, 'ajax_get_selected_product_data' ) ); |
|
128 | - add_action( 'wc_ajax_wc_stripe_clear_cart', array( $this, 'ajax_clear_cart' ) ); |
|
129 | - add_action( 'wc_ajax_wc_stripe_log_errors', array( $this, 'ajax_log_errors' ) ); |
|
122 | + add_action('wc_ajax_wc_stripe_get_cart_details', array($this, 'ajax_get_cart_details')); |
|
123 | + add_action('wc_ajax_wc_stripe_get_shipping_options', array($this, 'ajax_get_shipping_options')); |
|
124 | + add_action('wc_ajax_wc_stripe_update_shipping_method', array($this, 'ajax_update_shipping_method')); |
|
125 | + add_action('wc_ajax_wc_stripe_create_order', array($this, 'ajax_create_order')); |
|
126 | + add_action('wc_ajax_wc_stripe_add_to_cart', array($this, 'ajax_add_to_cart')); |
|
127 | + add_action('wc_ajax_wc_stripe_get_selected_product_data', array($this, 'ajax_get_selected_product_data')); |
|
128 | + add_action('wc_ajax_wc_stripe_clear_cart', array($this, 'ajax_clear_cart')); |
|
129 | + add_action('wc_ajax_wc_stripe_log_errors', array($this, 'ajax_log_errors')); |
|
130 | 130 | |
131 | - add_filter( 'woocommerce_gateway_title', array( $this, 'filter_gateway_title' ), 10, 2 ); |
|
132 | - add_filter( 'woocommerce_validate_postcode', array( $this, 'postal_code_validation' ), 10, 3 ); |
|
131 | + add_filter('woocommerce_gateway_title', array($this, 'filter_gateway_title'), 10, 2); |
|
132 | + add_filter('woocommerce_validate_postcode', array($this, 'postal_code_validation'), 10, 3); |
|
133 | 133 | |
134 | - add_action( 'woocommerce_checkout_order_processed', array( $this, 'add_order_meta' ), 10, 3 ); |
|
134 | + add_action('woocommerce_checkout_order_processed', array($this, 'add_order_meta'), 10, 3); |
|
135 | 135 | } |
136 | 136 | |
137 | 137 | /** |
@@ -142,7 +142,7 @@ discard block |
||
142 | 142 | * @return string |
143 | 143 | */ |
144 | 144 | public function get_button_type() { |
145 | - return isset( $this->stripe_settings['payment_request_button_type'] ) ? $this->stripe_settings['payment_request_button_type'] : 'default'; |
|
145 | + return isset($this->stripe_settings['payment_request_button_type']) ? $this->stripe_settings['payment_request_button_type'] : 'default'; |
|
146 | 146 | } |
147 | 147 | |
148 | 148 | /** |
@@ -153,7 +153,7 @@ discard block |
||
153 | 153 | * @return string |
154 | 154 | */ |
155 | 155 | public function get_button_theme() { |
156 | - return isset( $this->stripe_settings['payment_request_button_theme'] ) ? $this->stripe_settings['payment_request_button_theme'] : 'dark'; |
|
156 | + return isset($this->stripe_settings['payment_request_button_theme']) ? $this->stripe_settings['payment_request_button_theme'] : 'dark'; |
|
157 | 157 | } |
158 | 158 | |
159 | 159 | /** |
@@ -164,7 +164,7 @@ discard block |
||
164 | 164 | * @return string |
165 | 165 | */ |
166 | 166 | public function get_button_height() { |
167 | - return isset( $this->stripe_settings['payment_request_button_height'] ) ? str_replace( 'px', '', $this->stripe_settings['payment_request_button_height'] ) : '64'; |
|
167 | + return isset($this->stripe_settings['payment_request_button_height']) ? str_replace('px', '', $this->stripe_settings['payment_request_button_height']) : '64'; |
|
168 | 168 | } |
169 | 169 | |
170 | 170 | /** |
@@ -174,40 +174,40 @@ discard block |
||
174 | 174 | * @version 4.0.0 |
175 | 175 | */ |
176 | 176 | public function get_product_data() { |
177 | - if ( ! is_product() ) { |
|
177 | + if ( ! is_product()) { |
|
178 | 178 | return false; |
179 | 179 | } |
180 | 180 | |
181 | 181 | global $post; |
182 | 182 | |
183 | - $product = wc_get_product( $post->ID ); |
|
183 | + $product = wc_get_product($post->ID); |
|
184 | 184 | |
185 | 185 | $data = array(); |
186 | 186 | $items = array(); |
187 | 187 | |
188 | 188 | $items[] = array( |
189 | 189 | 'label' => WC_Stripe_Helper::is_pre_30() ? $product->name : $product->get_name(), |
190 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( WC_Stripe_Helper::is_pre_30() ? $product->price : $product->get_price() ), |
|
190 | + 'amount' => WC_Stripe_Helper::get_stripe_amount(WC_Stripe_Helper::is_pre_30() ? $product->price : $product->get_price()), |
|
191 | 191 | ); |
192 | 192 | |
193 | - if ( wc_tax_enabled() ) { |
|
193 | + if (wc_tax_enabled()) { |
|
194 | 194 | $items[] = array( |
195 | - 'label' => __( 'Tax', 'woocommerce-gateway-stripe' ), |
|
195 | + 'label' => __('Tax', 'woocommerce-gateway-stripe'), |
|
196 | 196 | 'amount' => 0, |
197 | 197 | 'pending' => true, |
198 | 198 | ); |
199 | 199 | } |
200 | 200 | |
201 | - if ( wc_shipping_enabled() && $product->needs_shipping() ) { |
|
201 | + if (wc_shipping_enabled() && $product->needs_shipping()) { |
|
202 | 202 | $items[] = array( |
203 | - 'label' => __( 'Shipping', 'woocommerce-gateway-stripe' ), |
|
203 | + 'label' => __('Shipping', 'woocommerce-gateway-stripe'), |
|
204 | 204 | 'amount' => 0, |
205 | 205 | 'pending' => true, |
206 | 206 | ); |
207 | 207 | |
208 | - $data['shippingOptions'] = array( |
|
208 | + $data['shippingOptions'] = array( |
|
209 | 209 | 'id' => 'pending', |
210 | - 'label' => __( 'Pending', 'woocommerce-gateway-stripe' ), |
|
210 | + 'label' => __('Pending', 'woocommerce-gateway-stripe'), |
|
211 | 211 | 'detail' => '', |
212 | 212 | 'amount' => 0, |
213 | 213 | ); |
@@ -215,41 +215,41 @@ discard block |
||
215 | 215 | |
216 | 216 | $data['displayItems'] = $items; |
217 | 217 | $data['total'] = array( |
218 | - 'label' => apply_filters( 'wc_stripe_payment_request_total_label', $this->total_label ), |
|
219 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( WC_Stripe_Helper::is_pre_30() ? $product->price : $product->get_price() ), |
|
218 | + 'label' => apply_filters('wc_stripe_payment_request_total_label', $this->total_label), |
|
219 | + 'amount' => WC_Stripe_Helper::get_stripe_amount(WC_Stripe_Helper::is_pre_30() ? $product->price : $product->get_price()), |
|
220 | 220 | 'pending' => true, |
221 | 221 | ); |
222 | 222 | |
223 | - $data['requestShipping'] = ( wc_shipping_enabled() && $product->needs_shipping() ); |
|
224 | - $data['currency'] = strtolower( get_woocommerce_currency() ); |
|
225 | - $data['country_code'] = substr( get_option( 'woocommerce_default_country' ), 0, 2 ); |
|
223 | + $data['requestShipping'] = (wc_shipping_enabled() && $product->needs_shipping()); |
|
224 | + $data['currency'] = strtolower(get_woocommerce_currency()); |
|
225 | + $data['country_code'] = substr(get_option('woocommerce_default_country'), 0, 2); |
|
226 | 226 | |
227 | - return apply_filters( 'wc_stripe_payment_request_product_data', $data, $product ); |
|
227 | + return apply_filters('wc_stripe_payment_request_product_data', $data, $product); |
|
228 | 228 | } |
229 | 229 | |
230 | 230 | /** |
231 | 231 | * Filters the gateway title to reflect Payment Request type |
232 | 232 | * |
233 | 233 | */ |
234 | - public function filter_gateway_title( $title, $id ) { |
|
234 | + public function filter_gateway_title($title, $id) { |
|
235 | 235 | global $post; |
236 | 236 | |
237 | - if ( ! is_object( $post ) ) { |
|
237 | + if ( ! is_object($post)) { |
|
238 | 238 | return $title; |
239 | 239 | } |
240 | 240 | |
241 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
242 | - $method_title = get_post_meta( $post->ID, '_payment_method_title', true ); |
|
241 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
242 | + $method_title = get_post_meta($post->ID, '_payment_method_title', true); |
|
243 | 243 | } else { |
244 | - $order = wc_get_order( $post->ID ); |
|
245 | - $method_title = is_object( $order ) ? $order->get_payment_method_title() : ''; |
|
244 | + $order = wc_get_order($post->ID); |
|
245 | + $method_title = is_object($order) ? $order->get_payment_method_title() : ''; |
|
246 | 246 | } |
247 | 247 | |
248 | - if ( 'stripe' === $id && ! empty( $method_title ) && 'Apple Pay (Stripe)' === $method_title ) { |
|
248 | + if ('stripe' === $id && ! empty($method_title) && 'Apple Pay (Stripe)' === $method_title) { |
|
249 | 249 | return $method_title; |
250 | 250 | } |
251 | 251 | |
252 | - if ( 'stripe' === $id && ! empty( $method_title ) && 'Chrome Payment Request (Stripe)' === $method_title ) { |
|
252 | + if ('stripe' === $id && ! empty($method_title) && 'Chrome Payment Request (Stripe)' === $method_title) { |
|
253 | 253 | return $method_title; |
254 | 254 | } |
255 | 255 | |
@@ -262,16 +262,16 @@ discard block |
||
262 | 262 | * @since 3.1.4 |
263 | 263 | * @version 4.0.0 |
264 | 264 | */ |
265 | - public function postal_code_validation( $valid, $postcode, $country ) { |
|
265 | + public function postal_code_validation($valid, $postcode, $country) { |
|
266 | 266 | $gateways = WC()->payment_gateways->get_available_payment_gateways(); |
267 | 267 | |
268 | - if ( ! isset( $gateways['stripe'] ) ) { |
|
268 | + if ( ! isset($gateways['stripe'])) { |
|
269 | 269 | return $valid; |
270 | 270 | } |
271 | 271 | |
272 | - $payment_request_type = wc_clean( $_POST['payment_request_type'] ); |
|
272 | + $payment_request_type = wc_clean($_POST['payment_request_type']); |
|
273 | 273 | |
274 | - if ( 'apple_pay' !== $payment_request_type ) { |
|
274 | + if ('apple_pay' !== $payment_request_type) { |
|
275 | 275 | return $valid; |
276 | 276 | } |
277 | 277 | |
@@ -281,7 +281,7 @@ discard block |
||
281 | 281 | * the order and not let it go through. The remedy for now is just to remove this validation. |
282 | 282 | * Note that this only works with shipping providers that don't validate full postal codes. |
283 | 283 | */ |
284 | - if ( 'GB' === $country || 'CA' === $country ) { |
|
284 | + if ('GB' === $country || 'CA' === $country) { |
|
285 | 285 | return true; |
286 | 286 | } |
287 | 287 | |
@@ -297,27 +297,27 @@ discard block |
||
297 | 297 | * @param array $posted_data The posted data from checkout form. |
298 | 298 | * @param object $order |
299 | 299 | */ |
300 | - public function add_order_meta( $order_id, $posted_data, $order ) { |
|
301 | - if ( empty( $_POST['payment_request_type'] ) ) { |
|
300 | + public function add_order_meta($order_id, $posted_data, $order) { |
|
301 | + if (empty($_POST['payment_request_type'])) { |
|
302 | 302 | return; |
303 | 303 | } |
304 | 304 | |
305 | - $payment_request_type = wc_clean( $_POST['payment_request_type'] ); |
|
305 | + $payment_request_type = wc_clean($_POST['payment_request_type']); |
|
306 | 306 | |
307 | - if ( 'apple_pay' === $payment_request_type ) { |
|
308 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
309 | - update_post_meta( $order_id, '_payment_method_title', 'Apple Pay (Stripe)' ); |
|
307 | + if ('apple_pay' === $payment_request_type) { |
|
308 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
309 | + update_post_meta($order_id, '_payment_method_title', 'Apple Pay (Stripe)'); |
|
310 | 310 | } else { |
311 | - $order->set_payment_method_title( 'Apple Pay (Stripe)' ); |
|
311 | + $order->set_payment_method_title('Apple Pay (Stripe)'); |
|
312 | 312 | $order->save(); |
313 | 313 | } |
314 | 314 | } |
315 | 315 | |
316 | - if ( 'payment_request_api' === $payment_request_type ) { |
|
317 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
318 | - update_post_meta( $order_id, '_payment_method_title', 'Chrome Payment Request (Stripe)' ); |
|
316 | + if ('payment_request_api' === $payment_request_type) { |
|
317 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
318 | + update_post_meta($order_id, '_payment_method_title', 'Chrome Payment Request (Stripe)'); |
|
319 | 319 | } else { |
320 | - $order->set_payment_method_title( 'Chrome Payment Request (Stripe)' ); |
|
320 | + $order->set_payment_method_title('Chrome Payment Request (Stripe)'); |
|
321 | 321 | $order->save(); |
322 | 322 | } |
323 | 323 | } |
@@ -331,11 +331,11 @@ discard block |
||
331 | 331 | * @return array |
332 | 332 | */ |
333 | 333 | public function supported_product_types() { |
334 | - return apply_filters( 'wc_stripe_payment_request_supported_types', array( |
|
334 | + return apply_filters('wc_stripe_payment_request_supported_types', array( |
|
335 | 335 | 'simple', |
336 | 336 | 'variable', |
337 | 337 | 'variation', |
338 | - ) ); |
|
338 | + )); |
|
339 | 339 | } |
340 | 340 | |
341 | 341 | /** |
@@ -346,15 +346,15 @@ discard block |
||
346 | 346 | * @return bool |
347 | 347 | */ |
348 | 348 | public function allowed_items_in_cart() { |
349 | - foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) { |
|
350 | - $_product = apply_filters( 'woocommerce_cart_item_product', $cart_item['data'], $cart_item, $cart_item_key ); |
|
349 | + foreach (WC()->cart->get_cart() as $cart_item_key => $cart_item) { |
|
350 | + $_product = apply_filters('woocommerce_cart_item_product', $cart_item['data'], $cart_item, $cart_item_key); |
|
351 | 351 | |
352 | - if ( ! in_array( ( WC_Stripe_Helper::is_pre_30() ? $_product->product_type : $_product->get_type() ), $this->supported_product_types() ) ) { |
|
352 | + if ( ! in_array((WC_Stripe_Helper::is_pre_30() ? $_product->product_type : $_product->get_type()), $this->supported_product_types())) { |
|
353 | 353 | return false; |
354 | 354 | } |
355 | 355 | |
356 | 356 | // Pre Orders compatbility where we don't support charge upon release. |
357 | - 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() ) ) { |
|
357 | + 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())) { |
|
358 | 358 | return false; |
359 | 359 | } |
360 | 360 | } |
@@ -369,71 +369,71 @@ discard block |
||
369 | 369 | * @version 4.0.0 |
370 | 370 | */ |
371 | 371 | public function scripts() { |
372 | - if ( ! is_product() && ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) ) { |
|
372 | + if ( ! is_product() && ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order'])) { |
|
373 | 373 | return; |
374 | 374 | } |
375 | 375 | |
376 | - if ( is_product() ) { |
|
376 | + if (is_product()) { |
|
377 | 377 | global $post; |
378 | 378 | |
379 | - $product = wc_get_product( $post->ID ); |
|
379 | + $product = wc_get_product($post->ID); |
|
380 | 380 | |
381 | - if ( ! is_object( $product ) || ! in_array( ( WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type() ), $this->supported_product_types() ) ) { |
|
381 | + if ( ! is_object($product) || ! in_array((WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type()), $this->supported_product_types())) { |
|
382 | 382 | return; |
383 | 383 | } |
384 | 384 | |
385 | - if ( apply_filters( 'wc_stripe_hide_payment_request_on_product_page', false ) ) { |
|
385 | + if (apply_filters('wc_stripe_hide_payment_request_on_product_page', false)) { |
|
386 | 386 | return; |
387 | 387 | } |
388 | 388 | } |
389 | 389 | |
390 | - $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
390 | + $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; |
|
391 | 391 | |
392 | - wp_register_script( 'stripe', 'https://js.stripe.com/v3/', '', '3.0', true ); |
|
393 | - 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 ); |
|
392 | + wp_register_script('stripe', 'https://js.stripe.com/v3/', '', '3.0', true); |
|
393 | + 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); |
|
394 | 394 | |
395 | 395 | wp_localize_script( |
396 | 396 | 'wc_stripe_payment_request', |
397 | 397 | 'wc_stripe_payment_request_params', |
398 | 398 | array( |
399 | - 'ajax_url' => WC_AJAX::get_endpoint( '%%endpoint%%' ), |
|
399 | + 'ajax_url' => WC_AJAX::get_endpoint('%%endpoint%%'), |
|
400 | 400 | 'stripe' => array( |
401 | 401 | 'key' => $this->publishable_key, |
402 | - 'allow_prepaid_card' => apply_filters( 'wc_stripe_allow_prepaid_card', true ) ? 'yes' : 'no', |
|
402 | + 'allow_prepaid_card' => apply_filters('wc_stripe_allow_prepaid_card', true) ? 'yes' : 'no', |
|
403 | 403 | ), |
404 | 404 | 'nonce' => array( |
405 | - 'payment' => wp_create_nonce( 'wc-stripe-payment-request' ), |
|
406 | - 'shipping' => wp_create_nonce( 'wc-stripe-payment-request-shipping' ), |
|
407 | - 'update_shipping' => wp_create_nonce( 'wc-stripe-update-shipping-method' ), |
|
408 | - 'checkout' => wp_create_nonce( 'woocommerce-process_checkout' ), |
|
409 | - 'add_to_cart' => wp_create_nonce( 'wc-stripe-add-to-cart' ), |
|
410 | - 'get_selected_product_data' => wp_create_nonce( 'wc-stripe-get-selected-product-data' ), |
|
411 | - 'log_errors' => wp_create_nonce( 'wc-stripe-log-errors' ), |
|
412 | - 'clear_cart' => wp_create_nonce( 'wc-stripe-clear-cart' ), |
|
405 | + 'payment' => wp_create_nonce('wc-stripe-payment-request'), |
|
406 | + 'shipping' => wp_create_nonce('wc-stripe-payment-request-shipping'), |
|
407 | + 'update_shipping' => wp_create_nonce('wc-stripe-update-shipping-method'), |
|
408 | + 'checkout' => wp_create_nonce('woocommerce-process_checkout'), |
|
409 | + 'add_to_cart' => wp_create_nonce('wc-stripe-add-to-cart'), |
|
410 | + 'get_selected_product_data' => wp_create_nonce('wc-stripe-get-selected-product-data'), |
|
411 | + 'log_errors' => wp_create_nonce('wc-stripe-log-errors'), |
|
412 | + 'clear_cart' => wp_create_nonce('wc-stripe-clear-cart'), |
|
413 | 413 | ), |
414 | 414 | 'i18n' => array( |
415 | - 'no_prepaid_card' => __( 'Sorry, we\'re not accepting prepaid cards at this time.', 'woocommerce-gateway-stripe' ), |
|
415 | + 'no_prepaid_card' => __('Sorry, we\'re not accepting prepaid cards at this time.', 'woocommerce-gateway-stripe'), |
|
416 | 416 | /* translators: Do not translate the [option] placeholder */ |
417 | - 'unknown_shipping' => __( 'Unknown shipping option "[option]".', 'woocommerce-gateway-stripe' ), |
|
417 | + 'unknown_shipping' => __('Unknown shipping option "[option]".', 'woocommerce-gateway-stripe'), |
|
418 | 418 | ), |
419 | 419 | 'checkout' => array( |
420 | 420 | 'url' => wc_get_checkout_url(), |
421 | - 'currency_code' => strtolower( get_woocommerce_currency() ), |
|
422 | - 'country_code' => substr( get_option( 'woocommerce_default_country' ), 0, 2 ), |
|
421 | + 'currency_code' => strtolower(get_woocommerce_currency()), |
|
422 | + 'country_code' => substr(get_option('woocommerce_default_country'), 0, 2), |
|
423 | 423 | 'needs_shipping' => WC()->cart->needs_shipping() ? 'yes' : 'no', |
424 | 424 | ), |
425 | 425 | 'button' => array( |
426 | 426 | 'type' => $this->get_button_type(), |
427 | 427 | 'theme' => $this->get_button_theme(), |
428 | 428 | 'height' => $this->get_button_height(), |
429 | - 'locale' => substr( get_locale(), 0, 2 ), // Default format is en_US. |
|
429 | + 'locale' => substr(get_locale(), 0, 2), // Default format is en_US. |
|
430 | 430 | ), |
431 | 431 | 'is_product_page' => is_product(), |
432 | 432 | 'product' => $this->get_product_data(), |
433 | 433 | ) |
434 | 434 | ); |
435 | 435 | |
436 | - wp_enqueue_script( 'wc_stripe_payment_request' ); |
|
436 | + wp_enqueue_script('wc_stripe_payment_request'); |
|
437 | 437 | } |
438 | 438 | |
439 | 439 | /** |
@@ -445,39 +445,39 @@ discard block |
||
445 | 445 | public function display_payment_request_button_html() { |
446 | 446 | $gateways = WC()->payment_gateways->get_available_payment_gateways(); |
447 | 447 | |
448 | - if ( ! isset( $gateways['stripe'] ) ) { |
|
448 | + if ( ! isset($gateways['stripe'])) { |
|
449 | 449 | return; |
450 | 450 | } |
451 | 451 | |
452 | - if ( ! is_cart() && ! is_checkout() && ! is_product() && ! isset( $_GET['pay_for_order'] ) ) { |
|
452 | + if ( ! is_cart() && ! is_checkout() && ! is_product() && ! isset($_GET['pay_for_order'])) { |
|
453 | 453 | return; |
454 | 454 | } |
455 | 455 | |
456 | - if ( is_product() && apply_filters( 'wc_stripe_hide_payment_request_on_product_page', false ) ) { |
|
456 | + if (is_product() && apply_filters('wc_stripe_hide_payment_request_on_product_page', false)) { |
|
457 | 457 | return; |
458 | 458 | } |
459 | 459 | |
460 | - if ( is_checkout() && ! apply_filters( 'wc_stripe_show_payment_request_on_checkout', false ) ) { |
|
460 | + if (is_checkout() && ! apply_filters('wc_stripe_show_payment_request_on_checkout', false)) { |
|
461 | 461 | return; |
462 | 462 | } |
463 | 463 | |
464 | - if ( is_product() ) { |
|
464 | + if (is_product()) { |
|
465 | 465 | global $post; |
466 | 466 | |
467 | - $product = wc_get_product( $post->ID ); |
|
467 | + $product = wc_get_product($post->ID); |
|
468 | 468 | |
469 | - if ( ! is_object( $product ) || ! in_array( ( WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type() ), $this->supported_product_types() ) ) { |
|
469 | + if ( ! is_object($product) || ! in_array((WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type()), $this->supported_product_types())) { |
|
470 | 470 | return; |
471 | 471 | } |
472 | 472 | |
473 | 473 | // Pre Orders charge upon release not supported. |
474 | - if ( class_exists( 'WC_Pre_Orders_Order' ) && WC_Pre_Orders_Product::product_is_charged_upon_release( $product ) ) { |
|
475 | - WC_Stripe_Logger::log( 'Pre Order charge upon release is not supported. ( Payment Request button disabled )' ); |
|
474 | + if (class_exists('WC_Pre_Orders_Order') && WC_Pre_Orders_Product::product_is_charged_upon_release($product)) { |
|
475 | + WC_Stripe_Logger::log('Pre Order charge upon release is not supported. ( Payment Request button disabled )'); |
|
476 | 476 | return; |
477 | 477 | } |
478 | 478 | } else { |
479 | - if ( ! $this->allowed_items_in_cart() ) { |
|
480 | - WC_Stripe_Logger::log( 'Items in the cart has unsupported product type ( Payment Request button disabled )' ); |
|
479 | + if ( ! $this->allowed_items_in_cart()) { |
|
480 | + WC_Stripe_Logger::log('Items in the cart has unsupported product type ( Payment Request button disabled )'); |
|
481 | 481 | return; |
482 | 482 | } |
483 | 483 | } |
@@ -499,44 +499,44 @@ discard block |
||
499 | 499 | public function display_payment_request_button_separator_html() { |
500 | 500 | $gateways = WC()->payment_gateways->get_available_payment_gateways(); |
501 | 501 | |
502 | - if ( ! isset( $gateways['stripe'] ) ) { |
|
502 | + if ( ! isset($gateways['stripe'])) { |
|
503 | 503 | return; |
504 | 504 | } |
505 | 505 | |
506 | - if ( ! is_cart() && ! is_checkout() && ! is_product() && ! isset( $_GET['pay_for_order'] ) ) { |
|
506 | + if ( ! is_cart() && ! is_checkout() && ! is_product() && ! isset($_GET['pay_for_order'])) { |
|
507 | 507 | return; |
508 | 508 | } |
509 | 509 | |
510 | - if ( is_product() && apply_filters( 'wc_stripe_hide_payment_request_on_product_page', false ) ) { |
|
510 | + if (is_product() && apply_filters('wc_stripe_hide_payment_request_on_product_page', false)) { |
|
511 | 511 | return; |
512 | 512 | } |
513 | 513 | |
514 | - if ( is_checkout() && ! apply_filters( 'wc_stripe_show_payment_request_on_checkout', false ) ) { |
|
514 | + if (is_checkout() && ! apply_filters('wc_stripe_show_payment_request_on_checkout', false)) { |
|
515 | 515 | return; |
516 | 516 | } |
517 | 517 | |
518 | - if ( is_product() ) { |
|
518 | + if (is_product()) { |
|
519 | 519 | global $post; |
520 | 520 | |
521 | - $product = wc_get_product( $post->ID ); |
|
521 | + $product = wc_get_product($post->ID); |
|
522 | 522 | |
523 | - if ( ! is_object( $product ) || ! in_array( ( WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type() ), $this->supported_product_types() ) ) { |
|
523 | + if ( ! is_object($product) || ! in_array((WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type()), $this->supported_product_types())) { |
|
524 | 524 | return; |
525 | 525 | } |
526 | 526 | |
527 | 527 | // Pre Orders charge upon release not supported. |
528 | - if ( class_exists( 'WC_Pre_Orders_Order' ) && WC_Pre_Orders_Product::product_is_charged_upon_release( $product ) ) { |
|
529 | - WC_Stripe_Logger::log( 'Pre Order charge upon release is not supported. ( Payment Request button disabled )' ); |
|
528 | + if (class_exists('WC_Pre_Orders_Order') && WC_Pre_Orders_Product::product_is_charged_upon_release($product)) { |
|
529 | + WC_Stripe_Logger::log('Pre Order charge upon release is not supported. ( Payment Request button disabled )'); |
|
530 | 530 | return; |
531 | 531 | } |
532 | 532 | } else { |
533 | - if ( ! $this->allowed_items_in_cart() ) { |
|
534 | - WC_Stripe_Logger::log( 'Items in the cart has unsupported product type ( Payment Request button disabled )' ); |
|
533 | + if ( ! $this->allowed_items_in_cart()) { |
|
534 | + WC_Stripe_Logger::log('Items in the cart has unsupported product type ( Payment Request button disabled )'); |
|
535 | 535 | return; |
536 | 536 | } |
537 | 537 | } |
538 | 538 | ?> |
539 | - <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> |
|
539 | + <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> |
|
540 | 540 | <?php |
541 | 541 | } |
542 | 542 | |
@@ -547,11 +547,11 @@ discard block |
||
547 | 547 | * @version 4.0.0 |
548 | 548 | */ |
549 | 549 | public function ajax_log_errors() { |
550 | - check_ajax_referer( 'wc-stripe-log-errors', 'security' ); |
|
550 | + check_ajax_referer('wc-stripe-log-errors', 'security'); |
|
551 | 551 | |
552 | - $errors = wc_clean( stripslashes( $_POST['errors'] ) ); |
|
552 | + $errors = wc_clean(stripslashes($_POST['errors'])); |
|
553 | 553 | |
554 | - WC_Stripe_Logger::log( $errors ); |
|
554 | + WC_Stripe_Logger::log($errors); |
|
555 | 555 | |
556 | 556 | exit; |
557 | 557 | } |
@@ -563,7 +563,7 @@ discard block |
||
563 | 563 | * @version 4.0.0 |
564 | 564 | */ |
565 | 565 | public function ajax_clear_cart() { |
566 | - check_ajax_referer( 'wc-stripe-clear-cart', 'security' ); |
|
566 | + check_ajax_referer('wc-stripe-clear-cart', 'security'); |
|
567 | 567 | |
568 | 568 | WC()->cart->empty_cart(); |
569 | 569 | exit; |
@@ -573,10 +573,10 @@ discard block |
||
573 | 573 | * Get cart details. |
574 | 574 | */ |
575 | 575 | public function ajax_get_cart_details() { |
576 | - check_ajax_referer( 'wc-stripe-payment-request', 'security' ); |
|
576 | + check_ajax_referer('wc-stripe-payment-request', 'security'); |
|
577 | 577 | |
578 | - if ( ! defined( 'WOOCOMMERCE_CART' ) ) { |
|
579 | - define( 'WOOCOMMERCE_CART', true ); |
|
578 | + if ( ! defined('WOOCOMMERCE_CART')) { |
|
579 | + define('WOOCOMMERCE_CART', true); |
|
580 | 580 | } |
581 | 581 | |
582 | 582 | WC()->cart->calculate_totals(); |
@@ -587,14 +587,14 @@ discard block |
||
587 | 587 | $data = array( |
588 | 588 | 'shipping_required' => WC()->cart->needs_shipping(), |
589 | 589 | 'order_data' => array( |
590 | - 'currency' => strtolower( $currency ), |
|
591 | - 'country_code' => substr( get_option( 'woocommerce_default_country' ), 0, 2 ), |
|
590 | + 'currency' => strtolower($currency), |
|
591 | + 'country_code' => substr(get_option('woocommerce_default_country'), 0, 2), |
|
592 | 592 | ), |
593 | 593 | ); |
594 | 594 | |
595 | 595 | $data['order_data'] += $this->build_display_items(); |
596 | 596 | |
597 | - wp_send_json( $data ); |
|
597 | + wp_send_json($data); |
|
598 | 598 | } |
599 | 599 | |
600 | 600 | /** |
@@ -605,47 +605,47 @@ discard block |
||
605 | 605 | * @see WC_Shipping::get_packages(). |
606 | 606 | */ |
607 | 607 | public function ajax_get_shipping_options() { |
608 | - check_ajax_referer( 'wc-stripe-payment-request-shipping', 'security' ); |
|
608 | + check_ajax_referer('wc-stripe-payment-request-shipping', 'security'); |
|
609 | 609 | |
610 | 610 | try { |
611 | 611 | // Set the shipping package. |
612 | - $posted = filter_input_array( INPUT_POST, array( |
|
612 | + $posted = filter_input_array(INPUT_POST, array( |
|
613 | 613 | 'country' => FILTER_SANITIZE_STRING, |
614 | 614 | 'state' => FILTER_SANITIZE_STRING, |
615 | 615 | 'postcode' => FILTER_SANITIZE_STRING, |
616 | 616 | 'city' => FILTER_SANITIZE_STRING, |
617 | 617 | 'address' => FILTER_SANITIZE_STRING, |
618 | 618 | 'address_2' => FILTER_SANITIZE_STRING, |
619 | - ) ); |
|
619 | + )); |
|
620 | 620 | |
621 | - $this->calculate_shipping( $posted ); |
|
621 | + $this->calculate_shipping($posted); |
|
622 | 622 | |
623 | 623 | // Set the shipping options. |
624 | 624 | $data = array(); |
625 | 625 | $packages = WC()->shipping->get_packages(); |
626 | 626 | |
627 | - if ( ! empty( $packages ) && WC()->customer->has_calculated_shipping() ) { |
|
628 | - foreach ( $packages as $package_key => $package ) { |
|
629 | - if ( empty( $package['rates'] ) ) { |
|
630 | - throw new Exception( __( 'Unable to find shipping method for address.', 'woocommerce-gateway-stripe' ) ); |
|
627 | + if ( ! empty($packages) && WC()->customer->has_calculated_shipping()) { |
|
628 | + foreach ($packages as $package_key => $package) { |
|
629 | + if (empty($package['rates'])) { |
|
630 | + throw new Exception(__('Unable to find shipping method for address.', 'woocommerce-gateway-stripe')); |
|
631 | 631 | } |
632 | 632 | |
633 | - foreach ( $package['rates'] as $key => $rate ) { |
|
633 | + foreach ($package['rates'] as $key => $rate) { |
|
634 | 634 | $data['shipping_options'][] = array( |
635 | 635 | 'id' => $rate->id, |
636 | 636 | 'label' => $rate->label, |
637 | 637 | 'detail' => '', |
638 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $rate->cost ), |
|
638 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($rate->cost), |
|
639 | 639 | ); |
640 | 640 | } |
641 | 641 | } |
642 | 642 | } else { |
643 | - throw new Exception( __( 'Unable to find shipping method for address.', 'woocommerce-gateway-stripe' ) ); |
|
643 | + throw new Exception(__('Unable to find shipping method for address.', 'woocommerce-gateway-stripe')); |
|
644 | 644 | } |
645 | 645 | |
646 | - if ( isset( $data[0] ) ) { |
|
646 | + if (isset($data[0])) { |
|
647 | 647 | // Auto select the first shipping method. |
648 | - WC()->session->set( 'chosen_shipping_methods', array( $data[0]['id'] ) ); |
|
648 | + WC()->session->set('chosen_shipping_methods', array($data[0]['id'])); |
|
649 | 649 | } |
650 | 650 | |
651 | 651 | WC()->cart->calculate_totals(); |
@@ -653,12 +653,12 @@ discard block |
||
653 | 653 | $data += $this->build_display_items(); |
654 | 654 | $data['result'] = 'success'; |
655 | 655 | |
656 | - wp_send_json( $data ); |
|
657 | - } catch ( Exception $e ) { |
|
656 | + wp_send_json($data); |
|
657 | + } catch (Exception $e) { |
|
658 | 658 | $data += $this->build_display_items(); |
659 | 659 | $data['result'] = 'invalid_shipping_address'; |
660 | 660 | |
661 | - wp_send_json( $data ); |
|
661 | + wp_send_json($data); |
|
662 | 662 | } |
663 | 663 | } |
664 | 664 | |
@@ -666,22 +666,22 @@ discard block |
||
666 | 666 | * Update shipping method. |
667 | 667 | */ |
668 | 668 | public function ajax_update_shipping_method() { |
669 | - check_ajax_referer( 'wc-stripe-update-shipping-method', 'security' ); |
|
669 | + check_ajax_referer('wc-stripe-update-shipping-method', 'security'); |
|
670 | 670 | |
671 | - if ( ! defined( 'WOOCOMMERCE_CART' ) ) { |
|
672 | - define( 'WOOCOMMERCE_CART', true ); |
|
671 | + if ( ! defined('WOOCOMMERCE_CART')) { |
|
672 | + define('WOOCOMMERCE_CART', true); |
|
673 | 673 | } |
674 | 674 | |
675 | - $chosen_shipping_methods = WC()->session->get( 'chosen_shipping_methods' ); |
|
676 | - $shipping_method = filter_input( INPUT_POST, 'shipping_method', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY ); |
|
675 | + $chosen_shipping_methods = WC()->session->get('chosen_shipping_methods'); |
|
676 | + $shipping_method = filter_input(INPUT_POST, 'shipping_method', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY); |
|
677 | 677 | |
678 | - if ( is_array( $shipping_method ) ) { |
|
679 | - foreach ( $shipping_method as $i => $value ) { |
|
680 | - $chosen_shipping_methods[ $i ] = wc_clean( $value ); |
|
678 | + if (is_array($shipping_method)) { |
|
679 | + foreach ($shipping_method as $i => $value) { |
|
680 | + $chosen_shipping_methods[$i] = wc_clean($value); |
|
681 | 681 | } |
682 | 682 | } |
683 | 683 | |
684 | - WC()->session->set( 'chosen_shipping_methods', $chosen_shipping_methods ); |
|
684 | + WC()->session->set('chosen_shipping_methods', $chosen_shipping_methods); |
|
685 | 685 | |
686 | 686 | WC()->cart->calculate_totals(); |
687 | 687 | |
@@ -689,7 +689,7 @@ discard block |
||
689 | 689 | $data += $this->build_display_items(); |
690 | 690 | $data['result'] = 'success'; |
691 | 691 | |
692 | - wp_send_json( $data ); |
|
692 | + wp_send_json($data); |
|
693 | 693 | } |
694 | 694 | |
695 | 695 | /** |
@@ -700,31 +700,31 @@ discard block |
||
700 | 700 | * @return array $data |
701 | 701 | */ |
702 | 702 | public function ajax_get_selected_product_data() { |
703 | - check_ajax_referer( 'wc-stripe-get-selected-product-data', 'security' ); |
|
703 | + check_ajax_referer('wc-stripe-get-selected-product-data', 'security'); |
|
704 | 704 | |
705 | - $product_id = absint( $_POST['product_id'] ); |
|
706 | - $qty = ! isset( $_POST['qty'] ) ? 1 : absint( $_POST['qty'] ); |
|
705 | + $product_id = absint($_POST['product_id']); |
|
706 | + $qty = ! isset($_POST['qty']) ? 1 : absint($_POST['qty']); |
|
707 | 707 | |
708 | - $product = wc_get_product( $product_id ); |
|
708 | + $product = wc_get_product($product_id); |
|
709 | 709 | |
710 | - if ( 'variable' === ( WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type() ) && isset( $_POST['attributes'] ) ) { |
|
711 | - $attributes = array_map( 'wc_clean', $_POST['attributes'] ); |
|
710 | + if ('variable' === (WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type()) && isset($_POST['attributes'])) { |
|
711 | + $attributes = array_map('wc_clean', $_POST['attributes']); |
|
712 | 712 | |
713 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
714 | - $variation_id = $product->get_matching_variation( $attributes ); |
|
713 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
714 | + $variation_id = $product->get_matching_variation($attributes); |
|
715 | 715 | } else { |
716 | - $data_store = WC_Data_Store::load( 'product' ); |
|
717 | - $variation_id = $data_store->find_matching_product_variation( $product, $attributes ); |
|
716 | + $data_store = WC_Data_Store::load('product'); |
|
717 | + $variation_id = $data_store->find_matching_product_variation($product, $attributes); |
|
718 | 718 | } |
719 | 719 | |
720 | - if ( ! empty( $variation_id ) ) { |
|
721 | - $product = wc_get_product( $variation_id ); |
|
720 | + if ( ! empty($variation_id)) { |
|
721 | + $product = wc_get_product($variation_id); |
|
722 | 722 | } |
723 | - } elseif ( 'simple' === ( WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type() ) ) { |
|
724 | - $product = wc_get_product( $product_id ); |
|
723 | + } elseif ('simple' === (WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type())) { |
|
724 | + $product = wc_get_product($product_id); |
|
725 | 725 | } |
726 | 726 | |
727 | - $total = $qty * ( WC_Stripe_Helper::is_pre_30() ? $product->price : $product->get_price() ); |
|
727 | + $total = $qty * (WC_Stripe_Helper::is_pre_30() ? $product->price : $product->get_price()); |
|
728 | 728 | |
729 | 729 | $quantity_label = 1 < $qty ? ' (x' . $qty . ')' : ''; |
730 | 730 | |
@@ -732,28 +732,28 @@ discard block |
||
732 | 732 | $items = array(); |
733 | 733 | |
734 | 734 | $items[] = array( |
735 | - 'label' => ( WC_Stripe_Helper::is_pre_30() ? $product->name : $product->get_name() ) . $quantity_label, |
|
736 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $total ), |
|
735 | + 'label' => (WC_Stripe_Helper::is_pre_30() ? $product->name : $product->get_name()) . $quantity_label, |
|
736 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($total), |
|
737 | 737 | ); |
738 | 738 | |
739 | - if ( wc_tax_enabled() ) { |
|
739 | + if (wc_tax_enabled()) { |
|
740 | 740 | $items[] = array( |
741 | - 'label' => __( 'Tax', 'woocommerce-gateway-stripe' ), |
|
741 | + 'label' => __('Tax', 'woocommerce-gateway-stripe'), |
|
742 | 742 | 'amount' => 0, |
743 | 743 | 'pending' => true, |
744 | 744 | ); |
745 | 745 | } |
746 | 746 | |
747 | - if ( wc_shipping_enabled() && $product->needs_shipping() ) { |
|
747 | + if (wc_shipping_enabled() && $product->needs_shipping()) { |
|
748 | 748 | $items[] = array( |
749 | - 'label' => __( 'Shipping', 'woocommerce-gateway-stripe' ), |
|
749 | + 'label' => __('Shipping', 'woocommerce-gateway-stripe'), |
|
750 | 750 | 'amount' => 0, |
751 | 751 | 'pending' => true, |
752 | 752 | ); |
753 | 753 | |
754 | - $data['shippingOptions'] = array( |
|
754 | + $data['shippingOptions'] = array( |
|
755 | 755 | 'id' => 'pending', |
756 | - 'label' => __( 'Pending', 'woocommerce-gateway-stripe' ), |
|
756 | + 'label' => __('Pending', 'woocommerce-gateway-stripe'), |
|
757 | 757 | 'detail' => '', |
758 | 758 | 'amount' => 0, |
759 | 759 | ); |
@@ -762,15 +762,15 @@ discard block |
||
762 | 762 | $data['displayItems'] = $items; |
763 | 763 | $data['total'] = array( |
764 | 764 | 'label' => $this->total_label, |
765 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $total ), |
|
765 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($total), |
|
766 | 766 | 'pending' => true, |
767 | 767 | ); |
768 | 768 | |
769 | - $data['requestShipping'] = ( wc_shipping_enabled() && $product->needs_shipping() ); |
|
770 | - $data['currency'] = strtolower( get_woocommerce_currency() ); |
|
771 | - $data['country_code'] = substr( get_option( 'woocommerce_default_country' ), 0, 2 ); |
|
769 | + $data['requestShipping'] = (wc_shipping_enabled() && $product->needs_shipping()); |
|
770 | + $data['currency'] = strtolower(get_woocommerce_currency()); |
|
771 | + $data['country_code'] = substr(get_option('woocommerce_default_country'), 0, 2); |
|
772 | 772 | |
773 | - wp_send_json( $data ); |
|
773 | + wp_send_json($data); |
|
774 | 774 | } |
775 | 775 | |
776 | 776 | /** |
@@ -781,37 +781,37 @@ discard block |
||
781 | 781 | * @return array $data |
782 | 782 | */ |
783 | 783 | public function ajax_add_to_cart() { |
784 | - check_ajax_referer( 'wc-stripe-add-to-cart', 'security' ); |
|
784 | + check_ajax_referer('wc-stripe-add-to-cart', 'security'); |
|
785 | 785 | |
786 | - if ( ! defined( 'WOOCOMMERCE_CART' ) ) { |
|
787 | - define( 'WOOCOMMERCE_CART', true ); |
|
786 | + if ( ! defined('WOOCOMMERCE_CART')) { |
|
787 | + define('WOOCOMMERCE_CART', true); |
|
788 | 788 | } |
789 | 789 | |
790 | 790 | WC()->shipping->reset_shipping(); |
791 | 791 | |
792 | - $product_id = absint( $_POST['product_id'] ); |
|
793 | - $qty = ! isset( $_POST['qty'] ) ? 1 : absint( $_POST['qty'] ); |
|
792 | + $product_id = absint($_POST['product_id']); |
|
793 | + $qty = ! isset($_POST['qty']) ? 1 : absint($_POST['qty']); |
|
794 | 794 | |
795 | - $product = wc_get_product( $product_id ); |
|
795 | + $product = wc_get_product($product_id); |
|
796 | 796 | |
797 | 797 | // First empty the cart to prevent wrong calculation. |
798 | 798 | WC()->cart->empty_cart(); |
799 | 799 | |
800 | - if ( 'variable' === ( WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type() ) && isset( $_POST['attributes'] ) ) { |
|
801 | - $attributes = array_map( 'wc_clean', $_POST['attributes'] ); |
|
800 | + if ('variable' === (WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type()) && isset($_POST['attributes'])) { |
|
801 | + $attributes = array_map('wc_clean', $_POST['attributes']); |
|
802 | 802 | |
803 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
804 | - $variation_id = $product->get_matching_variation( $attributes ); |
|
803 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
804 | + $variation_id = $product->get_matching_variation($attributes); |
|
805 | 805 | } else { |
806 | - $data_store = WC_Data_Store::load( 'product' ); |
|
807 | - $variation_id = $data_store->find_matching_product_variation( $product, $attributes ); |
|
806 | + $data_store = WC_Data_Store::load('product'); |
|
807 | + $variation_id = $data_store->find_matching_product_variation($product, $attributes); |
|
808 | 808 | } |
809 | 809 | |
810 | - WC()->cart->add_to_cart( $product->get_id(), $qty, $variation_id, $attributes ); |
|
810 | + WC()->cart->add_to_cart($product->get_id(), $qty, $variation_id, $attributes); |
|
811 | 811 | } |
812 | 812 | |
813 | - if ( 'simple' === ( WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type() ) ) { |
|
814 | - WC()->cart->add_to_cart( $product->get_id(), $qty ); |
|
813 | + if ('simple' === (WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type())) { |
|
814 | + WC()->cart->add_to_cart($product->get_id(), $qty); |
|
815 | 815 | } |
816 | 816 | |
817 | 817 | WC()->cart->calculate_totals(); |
@@ -820,7 +820,7 @@ discard block |
||
820 | 820 | $data += $this->build_display_items(); |
821 | 821 | $data['result'] = 'success'; |
822 | 822 | |
823 | - wp_send_json( $data ); |
|
823 | + wp_send_json($data); |
|
824 | 824 | } |
825 | 825 | |
826 | 826 | /** |
@@ -833,31 +833,31 @@ discard block |
||
833 | 833 | * @version 4.0.0 |
834 | 834 | */ |
835 | 835 | public function normalize_state() { |
836 | - $billing_country = ! empty( $_POST['billing_country'] ) ? wc_clean( $_POST['billing_country'] ) : ''; |
|
837 | - $shipping_country = ! empty( $_POST['shipping_country'] ) ? wc_clean( $_POST['shipping_country'] ) : ''; |
|
838 | - $billing_state = ! empty( $_POST['billing_state'] ) ? wc_clean( $_POST['billing_state'] ) : ''; |
|
839 | - $shipping_state = ! empty( $_POST['shipping_state'] ) ? wc_clean( $_POST['shipping_state'] ) : ''; |
|
836 | + $billing_country = ! empty($_POST['billing_country']) ? wc_clean($_POST['billing_country']) : ''; |
|
837 | + $shipping_country = ! empty($_POST['shipping_country']) ? wc_clean($_POST['shipping_country']) : ''; |
|
838 | + $billing_state = ! empty($_POST['billing_state']) ? wc_clean($_POST['billing_state']) : ''; |
|
839 | + $shipping_state = ! empty($_POST['shipping_state']) ? wc_clean($_POST['shipping_state']) : ''; |
|
840 | 840 | |
841 | - if ( $billing_state && $billing_country ) { |
|
842 | - $valid_states = WC()->countries->get_states( $billing_country ); |
|
841 | + if ($billing_state && $billing_country) { |
|
842 | + $valid_states = WC()->countries->get_states($billing_country); |
|
843 | 843 | |
844 | 844 | // Valid states found for country. |
845 | - if ( ! empty( $valid_states ) && is_array( $valid_states ) && sizeof( $valid_states ) > 0 ) { |
|
846 | - foreach ( $valid_states as $state_abbr => $state ) { |
|
847 | - if ( preg_match( '/' . preg_quote( $state ) . '/i', $billing_state ) ) { |
|
845 | + if ( ! empty($valid_states) && is_array($valid_states) && sizeof($valid_states) > 0) { |
|
846 | + foreach ($valid_states as $state_abbr => $state) { |
|
847 | + if (preg_match('/' . preg_quote($state) . '/i', $billing_state)) { |
|
848 | 848 | $_POST['billing_state'] = $state_abbr; |
849 | 849 | } |
850 | 850 | } |
851 | 851 | } |
852 | 852 | } |
853 | 853 | |
854 | - if ( $shipping_state && $shipping_country ) { |
|
855 | - $valid_states = WC()->countries->get_states( $shipping_country ); |
|
854 | + if ($shipping_state && $shipping_country) { |
|
855 | + $valid_states = WC()->countries->get_states($shipping_country); |
|
856 | 856 | |
857 | 857 | // Valid states found for country. |
858 | - if ( ! empty( $valid_states ) && is_array( $valid_states ) && sizeof( $valid_states ) > 0 ) { |
|
859 | - foreach ( $valid_states as $state_abbr => $state ) { |
|
860 | - if ( preg_match( '/' . preg_quote( $state ) . '/i', $shipping_state ) ) { |
|
858 | + if ( ! empty($valid_states) && is_array($valid_states) && sizeof($valid_states) > 0) { |
|
859 | + foreach ($valid_states as $state_abbr => $state) { |
|
860 | + if (preg_match('/' . preg_quote($state) . '/i', $shipping_state)) { |
|
861 | 861 | $_POST['shipping_state'] = $state_abbr; |
862 | 862 | } |
863 | 863 | } |
@@ -872,19 +872,19 @@ discard block |
||
872 | 872 | * @version 4.0.0 |
873 | 873 | */ |
874 | 874 | public function ajax_create_order() { |
875 | - if ( WC()->cart->is_empty() ) { |
|
876 | - wp_send_json_error( __( 'Empty cart', 'woocommerce-gateway-stripe' ) ); |
|
875 | + if (WC()->cart->is_empty()) { |
|
876 | + wp_send_json_error(__('Empty cart', 'woocommerce-gateway-stripe')); |
|
877 | 877 | } |
878 | 878 | |
879 | - if ( ! defined( 'WOOCOMMERCE_CHECKOUT' ) ) { |
|
880 | - define( 'WOOCOMMERCE_CHECKOUT', true ); |
|
879 | + if ( ! defined('WOOCOMMERCE_CHECKOUT')) { |
|
880 | + define('WOOCOMMERCE_CHECKOUT', true); |
|
881 | 881 | } |
882 | 882 | |
883 | 883 | $this->normalize_state(); |
884 | 884 | |
885 | 885 | WC()->checkout()->process_checkout(); |
886 | 886 | |
887 | - die( 0 ); |
|
887 | + die(0); |
|
888 | 888 | } |
889 | 889 | |
890 | 890 | /** |
@@ -894,7 +894,7 @@ discard block |
||
894 | 894 | * @version 4.0.0 |
895 | 895 | * @param array $address |
896 | 896 | */ |
897 | - protected function calculate_shipping( $address = array() ) { |
|
897 | + protected function calculate_shipping($address = array()) { |
|
898 | 898 | global $states; |
899 | 899 | |
900 | 900 | $country = $address['country']; |
@@ -911,28 +911,28 @@ discard block |
||
911 | 911 | * In some versions of Chrome, state can be a full name. So we need |
912 | 912 | * to convert that to abbreviation as WC is expecting that. |
913 | 913 | */ |
914 | - if ( 2 < strlen( $state ) ) { |
|
915 | - $state = array_search( ucfirst( strtolower( $state ) ), $states[ $country ] ); |
|
914 | + if (2 < strlen($state)) { |
|
915 | + $state = array_search(ucfirst(strtolower($state)), $states[$country]); |
|
916 | 916 | } |
917 | 917 | |
918 | 918 | WC()->shipping->reset_shipping(); |
919 | 919 | |
920 | - if ( $postcode && WC_Validation::is_postcode( $postcode, $country ) ) { |
|
921 | - $postcode = wc_format_postcode( $postcode, $country ); |
|
920 | + if ($postcode && WC_Validation::is_postcode($postcode, $country)) { |
|
921 | + $postcode = wc_format_postcode($postcode, $country); |
|
922 | 922 | } |
923 | 923 | |
924 | - if ( $country ) { |
|
925 | - WC()->customer->set_location( $country, $state, $postcode, $city ); |
|
926 | - WC()->customer->set_shipping_location( $country, $state, $postcode, $city ); |
|
924 | + if ($country) { |
|
925 | + WC()->customer->set_location($country, $state, $postcode, $city); |
|
926 | + WC()->customer->set_shipping_location($country, $state, $postcode, $city); |
|
927 | 927 | } else { |
928 | 928 | WC_Stripe_Helper::is_pre_30() ? WC()->customer->set_to_base() : WC()->customer->set_billing_address_to_base(); |
929 | 929 | WC_Stripe_Helper::is_pre_30() ? WC()->customer->set_shipping_to_base() : WC()->customer->set_shipping_address_to_base(); |
930 | 930 | } |
931 | 931 | |
932 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
933 | - WC()->customer->calculated_shipping( true ); |
|
932 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
933 | + WC()->customer->calculated_shipping(true); |
|
934 | 934 | } else { |
935 | - WC()->customer->set_calculated_shipping( true ); |
|
935 | + WC()->customer->set_calculated_shipping(true); |
|
936 | 936 | WC()->customer->save(); |
937 | 937 | } |
938 | 938 | |
@@ -949,17 +949,17 @@ discard block |
||
949 | 949 | $packages[0]['destination']['address'] = $address_1; |
950 | 950 | $packages[0]['destination']['address_2'] = $address_2; |
951 | 951 | |
952 | - foreach ( WC()->cart->get_cart() as $item ) { |
|
953 | - if ( $item['data']->needs_shipping() ) { |
|
954 | - if ( isset( $item['line_total'] ) ) { |
|
952 | + foreach (WC()->cart->get_cart() as $item) { |
|
953 | + if ($item['data']->needs_shipping()) { |
|
954 | + if (isset($item['line_total'])) { |
|
955 | 955 | $packages[0]['contents_cost'] += $item['line_total']; |
956 | 956 | } |
957 | 957 | } |
958 | 958 | } |
959 | 959 | |
960 | - $packages = apply_filters( 'woocommerce_cart_shipping_packages', $packages ); |
|
960 | + $packages = apply_filters('woocommerce_cart_shipping_packages', $packages); |
|
961 | 961 | |
962 | - WC()->shipping->calculate_shipping( $packages ); |
|
962 | + WC()->shipping->calculate_shipping($packages); |
|
963 | 963 | } |
964 | 964 | |
965 | 965 | /** |
@@ -968,19 +968,19 @@ discard block |
||
968 | 968 | * @since 3.1.0 |
969 | 969 | * @version 4.0.0 |
970 | 970 | */ |
971 | - protected function build_shipping_methods( $shipping_methods ) { |
|
972 | - if ( empty( $shipping_methods ) ) { |
|
971 | + protected function build_shipping_methods($shipping_methods) { |
|
972 | + if (empty($shipping_methods)) { |
|
973 | 973 | return array(); |
974 | 974 | } |
975 | 975 | |
976 | 976 | $shipping = array(); |
977 | 977 | |
978 | - foreach ( $shipping_methods as $method ) { |
|
978 | + foreach ($shipping_methods as $method) { |
|
979 | 979 | $shipping[] = array( |
980 | 980 | 'id' => $method['id'], |
981 | 981 | 'label' => $method['label'], |
982 | 982 | 'detail' => '', |
983 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $method['amount']['value'] ), |
|
983 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($method['amount']['value']), |
|
984 | 984 | ); |
985 | 985 | } |
986 | 986 | |
@@ -994,69 +994,69 @@ discard block |
||
994 | 994 | * @version 4.0.0 |
995 | 995 | */ |
996 | 996 | protected function build_display_items() { |
997 | - if ( ! defined( 'WOOCOMMERCE_CART' ) ) { |
|
998 | - define( 'WOOCOMMERCE_CART', true ); |
|
997 | + if ( ! defined('WOOCOMMERCE_CART')) { |
|
998 | + define('WOOCOMMERCE_CART', true); |
|
999 | 999 | } |
1000 | 1000 | |
1001 | 1001 | $items = array(); |
1002 | 1002 | $subtotal = 0; |
1003 | 1003 | |
1004 | 1004 | // Default show only subtotal instead of itemization. |
1005 | - if ( ! apply_filters( 'wc_stripe_payment_request_hide_itemization', true ) ) { |
|
1006 | - foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) { |
|
1005 | + if ( ! apply_filters('wc_stripe_payment_request_hide_itemization', true)) { |
|
1006 | + foreach (WC()->cart->get_cart() as $cart_item_key => $cart_item) { |
|
1007 | 1007 | $amount = $cart_item['line_subtotal']; |
1008 | - $subtotal += $cart_item['line_subtotal']; |
|
1008 | + $subtotal += $cart_item['line_subtotal']; |
|
1009 | 1009 | $quantity_label = 1 < $cart_item['quantity'] ? ' (x' . $cart_item['quantity'] . ')' : ''; |
1010 | 1010 | |
1011 | 1011 | $product_name = WC_Stripe_Helper::is_pre_30() ? $cart_item['data']->post->post_title : $cart_item['data']->get_name(); |
1012 | 1012 | |
1013 | 1013 | $item = array( |
1014 | 1014 | 'label' => $product_name . $quantity_label, |
1015 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $amount ), |
|
1015 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($amount), |
|
1016 | 1016 | ); |
1017 | 1017 | |
1018 | 1018 | $items[] = $item; |
1019 | 1019 | } |
1020 | 1020 | } |
1021 | 1021 | |
1022 | - $discounts = wc_format_decimal( WC()->cart->get_cart_discount_total(), WC()->cart->dp ); |
|
1023 | - $tax = wc_format_decimal( WC()->cart->tax_total + WC()->cart->shipping_tax_total, WC()->cart->dp ); |
|
1024 | - $shipping = wc_format_decimal( WC()->cart->shipping_total, WC()->cart->dp ); |
|
1025 | - $items_total = wc_format_decimal( WC()->cart->cart_contents_total, WC()->cart->dp ) + $discounts; |
|
1026 | - $order_total = wc_format_decimal( $items_total + $tax + $shipping - $discounts, WC()->cart->dp ); |
|
1022 | + $discounts = wc_format_decimal(WC()->cart->get_cart_discount_total(), WC()->cart->dp); |
|
1023 | + $tax = wc_format_decimal(WC()->cart->tax_total + WC()->cart->shipping_tax_total, WC()->cart->dp); |
|
1024 | + $shipping = wc_format_decimal(WC()->cart->shipping_total, WC()->cart->dp); |
|
1025 | + $items_total = wc_format_decimal(WC()->cart->cart_contents_total, WC()->cart->dp) + $discounts; |
|
1026 | + $order_total = wc_format_decimal($items_total + $tax + $shipping - $discounts, WC()->cart->dp); |
|
1027 | 1027 | |
1028 | - if ( wc_tax_enabled() ) { |
|
1028 | + if (wc_tax_enabled()) { |
|
1029 | 1029 | $items[] = array( |
1030 | - 'label' => esc_html( __( 'Tax', 'woocommerce-gateway-stripe' ) ), |
|
1031 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $tax ), |
|
1030 | + 'label' => esc_html(__('Tax', 'woocommerce-gateway-stripe')), |
|
1031 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($tax), |
|
1032 | 1032 | ); |
1033 | 1033 | } |
1034 | 1034 | |
1035 | - if ( WC()->cart->needs_shipping() ) { |
|
1035 | + if (WC()->cart->needs_shipping()) { |
|
1036 | 1036 | $items[] = array( |
1037 | - 'label' => esc_html( __( 'Shipping', 'woocommerce-gateway-stripe' ) ), |
|
1038 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $shipping ), |
|
1037 | + 'label' => esc_html(__('Shipping', 'woocommerce-gateway-stripe')), |
|
1038 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($shipping), |
|
1039 | 1039 | ); |
1040 | 1040 | } |
1041 | 1041 | |
1042 | - if ( WC()->cart->has_discount() ) { |
|
1042 | + if (WC()->cart->has_discount()) { |
|
1043 | 1043 | $items[] = array( |
1044 | - 'label' => esc_html( __( 'Discount', 'woocommerce-gateway-stripe' ) ), |
|
1045 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $discounts ), |
|
1044 | + 'label' => esc_html(__('Discount', 'woocommerce-gateway-stripe')), |
|
1045 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($discounts), |
|
1046 | 1046 | ); |
1047 | 1047 | } |
1048 | 1048 | |
1049 | - if ( version_compare( WC_VERSION, '3.2', '<' ) ) { |
|
1049 | + if (version_compare(WC_VERSION, '3.2', '<')) { |
|
1050 | 1050 | $cart_fees = WC()->cart->fees; |
1051 | 1051 | } else { |
1052 | 1052 | $cart_fees = WC()->cart->get_fees(); |
1053 | 1053 | } |
1054 | 1054 | |
1055 | 1055 | // Include fees and taxes as display items. |
1056 | - foreach ( $cart_fees as $key => $fee ) { |
|
1056 | + foreach ($cart_fees as $key => $fee) { |
|
1057 | 1057 | $items[] = array( |
1058 | 1058 | 'label' => $fee->name, |
1059 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $fee->amount ), |
|
1059 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($fee->amount), |
|
1060 | 1060 | ); |
1061 | 1061 | } |
1062 | 1062 | |
@@ -1064,7 +1064,7 @@ discard block |
||
1064 | 1064 | 'displayItems' => $items, |
1065 | 1065 | 'total' => array( |
1066 | 1066 | 'label' => $this->total_label, |
1067 | - 'amount' => max( 0, apply_filters( 'woocommerce_stripe_calculated_total', WC_Stripe_Helper::get_stripe_amount( $order_total ), $order_total, WC()->cart ) ), |
|
1067 | + 'amount' => max(0, apply_filters('woocommerce_stripe_calculated_total', WC_Stripe_Helper::get_stripe_amount($order_total), $order_total, WC()->cart)), |
|
1068 | 1068 | 'pending' => false, |
1069 | 1069 | ), |
1070 | 1070 | ); |