@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if ( ! defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | 5 | |
@@ -103,29 +103,29 @@ discard block |
||
103 | 103 | public function __construct() { |
104 | 104 | self::$_this = $this; |
105 | 105 | |
106 | - $gateway_settings = get_option( 'woocommerce_stripe_settings', '' ); |
|
106 | + $gateway_settings = get_option('woocommerce_stripe_settings', ''); |
|
107 | 107 | |
108 | - $this->statement_descriptor = ! empty( $gateway_settings['statement_descriptor'] ) ? $gateway_settings['statement_descriptor'] : wp_specialchars_decode( get_bloginfo( 'name' ), ENT_QUOTES ); |
|
108 | + $this->statement_descriptor = ! empty($gateway_settings['statement_descriptor']) ? $gateway_settings['statement_descriptor'] : wp_specialchars_decode(get_bloginfo('name'), ENT_QUOTES); |
|
109 | 109 | |
110 | 110 | // If both site title and statement descriptor is not set. Fallback. |
111 | - if ( empty( $this->statement_descriptor ) ) { |
|
111 | + if (empty($this->statement_descriptor)) { |
|
112 | 112 | $this->statement_descriptor = $_SERVER['SERVER_NAME']; |
113 | 113 | } |
114 | 114 | |
115 | 115 | $this->dp = wc_get_price_decimals(); |
116 | - $this->enabled = ( ! empty( $gateway_settings['enabled'] ) && 'yes' === $gateway_settings['enabled'] ) ? true : false; |
|
117 | - $this->testmode = ( ! empty( $gateway_settings['testmode'] ) && 'yes' === $gateway_settings['testmode'] ) ? true : false; |
|
118 | - $this->capture = ( ! empty( $gateway_settings['capture'] ) && 'yes' === $gateway_settings['capture'] ) ? true : false; |
|
119 | - $this->saved_cards = ( ! empty( $gateway_settings['saved_cards'] ) && 'yes' === $gateway_settings['saved_cards'] ) ? true : false; |
|
120 | - $this->apple_pay = ( ! empty( $gateway_settings['apple_pay'] ) && 'yes' === $gateway_settings['apple_pay'] ) ? true : false; |
|
121 | - $this->apple_pay_button = ! empty( $gateway_settings['apple_pay_button'] ) ? $gateway_settings['apple_pay_button'] : 'black'; |
|
122 | - $this->apple_pay_button_lang = ! empty( $gateway_settings['apple_pay_button_lang'] ) ? $gateway_settings['apple_pay_button_lang'] : 'en'; |
|
123 | - $this->logging = ( ! empty( $gateway_settings['logging'] ) && 'yes' === $gateway_settings['logging'] ) ? true : false; |
|
124 | - $this->publishable_key = ! empty( $gateway_settings['publishable_key'] ) ? $gateway_settings['publishable_key'] : ''; |
|
116 | + $this->enabled = ( ! empty($gateway_settings['enabled']) && 'yes' === $gateway_settings['enabled']) ? true : false; |
|
117 | + $this->testmode = ( ! empty($gateway_settings['testmode']) && 'yes' === $gateway_settings['testmode']) ? true : false; |
|
118 | + $this->capture = ( ! empty($gateway_settings['capture']) && 'yes' === $gateway_settings['capture']) ? true : false; |
|
119 | + $this->saved_cards = ( ! empty($gateway_settings['saved_cards']) && 'yes' === $gateway_settings['saved_cards']) ? true : false; |
|
120 | + $this->apple_pay = ( ! empty($gateway_settings['apple_pay']) && 'yes' === $gateway_settings['apple_pay']) ? true : false; |
|
121 | + $this->apple_pay_button = ! empty($gateway_settings['apple_pay_button']) ? $gateway_settings['apple_pay_button'] : 'black'; |
|
122 | + $this->apple_pay_button_lang = ! empty($gateway_settings['apple_pay_button_lang']) ? $gateway_settings['apple_pay_button_lang'] : 'en'; |
|
123 | + $this->logging = ( ! empty($gateway_settings['logging']) && 'yes' === $gateway_settings['logging']) ? true : false; |
|
124 | + $this->publishable_key = ! empty($gateway_settings['publishable_key']) ? $gateway_settings['publishable_key'] : ''; |
|
125 | 125 | $this->is_shipping_enabled = $this->is_shipping_enabled(); |
126 | 126 | |
127 | - if ( $this->testmode ) { |
|
128 | - $this->publishable_key = ! empty( $gateway_settings['test_publishable_key'] ) ? $gateway_settings['test_publishable_key'] : ''; |
|
127 | + if ($this->testmode) { |
|
128 | + $this->publishable_key = ! empty($gateway_settings['test_publishable_key']) ? $gateway_settings['test_publishable_key'] : ''; |
|
129 | 129 | } |
130 | 130 | |
131 | 131 | $this->init(); |
@@ -144,53 +144,53 @@ discard block |
||
144 | 144 | */ |
145 | 145 | public function init() { |
146 | 146 | // If Apple Pay is not enabled no need to proceed further. |
147 | - if ( ! $this->apple_pay ) { |
|
147 | + if ( ! $this->apple_pay) { |
|
148 | 148 | return; |
149 | 149 | } |
150 | 150 | |
151 | - add_action( 'wp_enqueue_scripts', array( $this, 'cart_scripts' ) ); |
|
152 | - add_action( 'wp_enqueue_scripts', array( $this, 'single_scripts' ) ); |
|
151 | + add_action('wp_enqueue_scripts', array($this, 'cart_scripts')); |
|
152 | + add_action('wp_enqueue_scripts', array($this, 'single_scripts')); |
|
153 | 153 | |
154 | 154 | /** |
155 | 155 | * In order to display the Apple Pay button in the correct position, |
156 | 156 | * a new hook was added to WooCommerce 3.0. In older versions of WooCommerce, |
157 | 157 | * CSS is used to position the button. |
158 | 158 | */ |
159 | - if ( version_compare( WC_VERSION, '3.0.0', '<' ) ) { |
|
160 | - add_action( 'woocommerce_after_add_to_cart_button', array( $this, 'display_apple_pay_button' ), 1 ); |
|
159 | + if (version_compare(WC_VERSION, '3.0.0', '<')) { |
|
160 | + add_action('woocommerce_after_add_to_cart_button', array($this, 'display_apple_pay_button'), 1); |
|
161 | 161 | } else { |
162 | - add_action( 'woocommerce_after_add_to_cart_quantity', array( $this, 'display_apple_pay_button' ), 1 ); |
|
162 | + add_action('woocommerce_after_add_to_cart_quantity', array($this, 'display_apple_pay_button'), 1); |
|
163 | 163 | } |
164 | 164 | |
165 | - add_action( 'woocommerce_proceed_to_checkout', array( $this, 'display_apple_pay_button' ), 1 ); |
|
166 | - add_action( 'woocommerce_proceed_to_checkout', array( $this, 'display_apple_pay_separator_html' ), 2 ); |
|
167 | - add_action( 'woocommerce_checkout_before_customer_details', array( $this, 'display_apple_pay_button' ), 1 ); |
|
168 | - add_action( 'woocommerce_checkout_before_customer_details', array( $this, 'display_apple_pay_separator_html' ), 2 ); |
|
169 | - add_action( 'wc_ajax_wc_stripe_log_apple_pay_errors', array( $this, 'log_apple_pay_errors' ) ); |
|
170 | - add_action( 'wc_ajax_wc_stripe_apple_pay', array( $this, 'process_apple_pay' ) ); |
|
171 | - add_action( 'wc_ajax_wc_stripe_generate_apple_pay_cart', array( $this, 'generate_apple_pay_cart' ) ); |
|
172 | - add_action( 'wc_ajax_wc_stripe_apple_pay_clear_cart', array( $this, 'clear_cart' ) ); |
|
173 | - add_action( 'wc_ajax_wc_stripe_generate_apple_pay_single', array( $this, 'generate_apple_pay_single' ) ); |
|
174 | - add_action( 'wc_ajax_wc_stripe_apple_pay_get_shipping_methods', array( $this, 'get_shipping_methods' ) ); |
|
175 | - add_action( 'wc_ajax_wc_stripe_apple_pay_update_shipping_method', array( $this, 'update_shipping_method' ) ); |
|
176 | - add_filter( 'woocommerce_gateway_title', array( $this, 'filter_gateway_title' ), 10, 2 ); |
|
177 | - add_filter( 'woocommerce_validate_postcode', array( $this, 'postal_code_validation' ), 10, 3 ); |
|
165 | + add_action('woocommerce_proceed_to_checkout', array($this, 'display_apple_pay_button'), 1); |
|
166 | + add_action('woocommerce_proceed_to_checkout', array($this, 'display_apple_pay_separator_html'), 2); |
|
167 | + add_action('woocommerce_checkout_before_customer_details', array($this, 'display_apple_pay_button'), 1); |
|
168 | + add_action('woocommerce_checkout_before_customer_details', array($this, 'display_apple_pay_separator_html'), 2); |
|
169 | + add_action('wc_ajax_wc_stripe_log_apple_pay_errors', array($this, 'log_apple_pay_errors')); |
|
170 | + add_action('wc_ajax_wc_stripe_apple_pay', array($this, 'process_apple_pay')); |
|
171 | + add_action('wc_ajax_wc_stripe_generate_apple_pay_cart', array($this, 'generate_apple_pay_cart')); |
|
172 | + add_action('wc_ajax_wc_stripe_apple_pay_clear_cart', array($this, 'clear_cart')); |
|
173 | + add_action('wc_ajax_wc_stripe_generate_apple_pay_single', array($this, 'generate_apple_pay_single')); |
|
174 | + add_action('wc_ajax_wc_stripe_apple_pay_get_shipping_methods', array($this, 'get_shipping_methods')); |
|
175 | + add_action('wc_ajax_wc_stripe_apple_pay_update_shipping_method', array($this, 'update_shipping_method')); |
|
176 | + add_filter('woocommerce_gateway_title', array($this, 'filter_gateway_title'), 10, 2); |
|
177 | + add_filter('woocommerce_validate_postcode', array($this, 'postal_code_validation'), 10, 3); |
|
178 | 178 | } |
179 | 179 | |
180 | 180 | /** |
181 | 181 | * Filters the gateway title to reflect Apple Pay. |
182 | 182 | * |
183 | 183 | */ |
184 | - public function filter_gateway_title( $title, $id ) { |
|
184 | + public function filter_gateway_title($title, $id) { |
|
185 | 185 | global $post; |
186 | 186 | |
187 | - if ( ! is_object( $post ) ) { |
|
187 | + if ( ! is_object($post)) { |
|
188 | 188 | return $title; |
189 | 189 | } |
190 | 190 | |
191 | - $method_title = get_post_meta( $post->ID, '_payment_method_title', true ); |
|
191 | + $method_title = get_post_meta($post->ID, '_payment_method_title', true); |
|
192 | 192 | |
193 | - if ( 'stripe' === $id && ! empty( $method_title ) && 'Apple Pay (Stripe)' === $method_title ) { |
|
193 | + if ('stripe' === $id && ! empty($method_title) && 'Apple Pay (Stripe)' === $method_title) { |
|
194 | 194 | return $method_title; |
195 | 195 | } |
196 | 196 | |
@@ -204,13 +204,13 @@ discard block |
||
204 | 204 | * @version 3.1.4 |
205 | 205 | */ |
206 | 206 | public function log_apple_pay_errors() { |
207 | - if ( ! wp_verify_nonce( $_POST['nonce'], '_wc_stripe_apple_pay_nonce' ) && ! wp_verify_nonce( $_POST['nonce'], '_wc_stripe_apple_pay_cart_nonce' ) ) { |
|
208 | - wp_die( __( 'Cheatin’ huh?', 'woocommerce-gateway-stripe' ) ); |
|
207 | + if ( ! wp_verify_nonce($_POST['nonce'], '_wc_stripe_apple_pay_nonce') && ! wp_verify_nonce($_POST['nonce'], '_wc_stripe_apple_pay_cart_nonce')) { |
|
208 | + wp_die(__('Cheatin’ huh?', 'woocommerce-gateway-stripe')); |
|
209 | 209 | } |
210 | 210 | |
211 | - $errors = wc_clean( stripslashes( $_POST['errors'] ) ); |
|
211 | + $errors = wc_clean(stripslashes($_POST['errors'])); |
|
212 | 212 | |
213 | - $this->log( $errors ); |
|
213 | + $this->log($errors); |
|
214 | 214 | |
215 | 215 | exit; |
216 | 216 | } |
@@ -221,10 +221,10 @@ discard block |
||
221 | 221 | * @since 3.1.4 |
222 | 222 | * @version 3.1.4 |
223 | 223 | */ |
224 | - public function postal_code_validation( $valid, $postcode, $country ) { |
|
224 | + public function postal_code_validation($valid, $postcode, $country) { |
|
225 | 225 | $gateways = WC()->payment_gateways->get_available_payment_gateways(); |
226 | 226 | |
227 | - if ( ! $this->apple_pay || ! isset( $gateways['stripe'] ) ) { |
|
227 | + if ( ! $this->apple_pay || ! isset($gateways['stripe'])) { |
|
228 | 228 | return $valid; |
229 | 229 | } |
230 | 230 | |
@@ -233,7 +233,7 @@ discard block |
||
233 | 233 | * when passing it back from the shippingcontactselected object. This causes WC to invalidate |
234 | 234 | * the order and not let it go through. The remedy for now is just to remove this validation. |
235 | 235 | */ |
236 | - if ( 'GB' === $country || 'CA' === $country ) { |
|
236 | + if ('GB' === $country || 'CA' === $country) { |
|
237 | 237 | return true; |
238 | 238 | } |
239 | 239 | |
@@ -248,9 +248,9 @@ discard block |
||
248 | 248 | * @return bool |
249 | 249 | */ |
250 | 250 | public function is_shipping_enabled() { |
251 | - $shipping_enabled = get_option( 'woocommerce_ship_to_countries', '' ); |
|
251 | + $shipping_enabled = get_option('woocommerce_ship_to_countries', ''); |
|
252 | 252 | |
253 | - if ( 'disabled' === $shipping_enabled ) { |
|
253 | + if ('disabled' === $shipping_enabled) { |
|
254 | 254 | return false; |
255 | 255 | } |
256 | 256 | |
@@ -264,42 +264,42 @@ discard block |
||
264 | 264 | * @version 3.1.4 |
265 | 265 | */ |
266 | 266 | public function single_scripts() { |
267 | - if ( ! is_single() ) { |
|
267 | + if ( ! is_single()) { |
|
268 | 268 | return; |
269 | 269 | } |
270 | 270 | |
271 | 271 | global $post; |
272 | 272 | |
273 | - $product = wc_get_product( $post->ID ); |
|
273 | + $product = wc_get_product($post->ID); |
|
274 | 274 | |
275 | - if ( ! is_object( $product ) || ! in_array( ( version_compare( WC_VERSION, '3.0.0', '<' ) ? $product->product_type : $product->get_type() ), $this->supported_product_types() ) ) { |
|
275 | + if ( ! is_object($product) || ! in_array((version_compare(WC_VERSION, '3.0.0', '<') ? $product->product_type : $product->get_type()), $this->supported_product_types())) { |
|
276 | 276 | return; |
277 | 277 | } |
278 | 278 | |
279 | - $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
279 | + $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; |
|
280 | 280 | |
281 | - wp_enqueue_style( 'stripe_apple_pay', plugins_url( 'assets/css/stripe-apple-pay.css', WC_STRIPE_MAIN_FILE ), array(), WC_STRIPE_VERSION ); |
|
281 | + wp_enqueue_style('stripe_apple_pay', plugins_url('assets/css/stripe-apple-pay.css', WC_STRIPE_MAIN_FILE), array(), WC_STRIPE_VERSION); |
|
282 | 282 | |
283 | - wp_enqueue_script( 'stripe', 'https://js.stripe.com/v2/', '', '1.0', true ); |
|
284 | - wp_enqueue_script( 'woocommerce_stripe_apple_pay_single', plugins_url( 'assets/js/stripe-apple-pay-single' . $suffix . '.js', WC_STRIPE_MAIN_FILE ), array( 'stripe' ), WC_STRIPE_VERSION, true ); |
|
283 | + wp_enqueue_script('stripe', 'https://js.stripe.com/v2/', '', '1.0', true); |
|
284 | + wp_enqueue_script('woocommerce_stripe_apple_pay_single', plugins_url('assets/js/stripe-apple-pay-single' . $suffix . '.js', WC_STRIPE_MAIN_FILE), array('stripe'), WC_STRIPE_VERSION, true); |
|
285 | 285 | |
286 | 286 | $stripe_params = array( |
287 | 287 | 'key' => $this->publishable_key, |
288 | 288 | 'currency_code' => get_woocommerce_currency(), |
289 | - 'country_code' => substr( get_option( 'woocommerce_default_country' ), 0, 2 ), |
|
289 | + 'country_code' => substr(get_option('woocommerce_default_country'), 0, 2), |
|
290 | 290 | 'label' => $this->statement_descriptor . ' (via WooCommerce)', |
291 | - 'ajaxurl' => WC_AJAX::get_endpoint( '%%endpoint%%' ), |
|
292 | - 'stripe_apple_pay_nonce' => wp_create_nonce( '_wc_stripe_apple_pay_nonce' ), |
|
293 | - 'stripe_apple_pay_cart_nonce' => wp_create_nonce( '_wc_stripe_apple_pay_cart_nonce' ), |
|
294 | - 'stripe_apple_pay_get_shipping_methods_nonce' => wp_create_nonce( '_wc_stripe_apple_pay_get_shipping_methods_nonce' ), |
|
295 | - 'stripe_apple_pay_update_shipping_method_nonce' => wp_create_nonce( '_wc_stripe_apple_pay_update_shipping_method_nonce' ), |
|
296 | - 'needs_shipping' => ( $product->needs_shipping() && $this->is_shipping_enabled ) ? 'yes' : 'no', |
|
291 | + 'ajaxurl' => WC_AJAX::get_endpoint('%%endpoint%%'), |
|
292 | + 'stripe_apple_pay_nonce' => wp_create_nonce('_wc_stripe_apple_pay_nonce'), |
|
293 | + 'stripe_apple_pay_cart_nonce' => wp_create_nonce('_wc_stripe_apple_pay_cart_nonce'), |
|
294 | + 'stripe_apple_pay_get_shipping_methods_nonce' => wp_create_nonce('_wc_stripe_apple_pay_get_shipping_methods_nonce'), |
|
295 | + 'stripe_apple_pay_update_shipping_method_nonce' => wp_create_nonce('_wc_stripe_apple_pay_update_shipping_method_nonce'), |
|
296 | + 'needs_shipping' => ($product->needs_shipping() && $this->is_shipping_enabled) ? 'yes' : 'no', |
|
297 | 297 | 'i18n' => array( |
298 | - 'sub_total' => __( 'Sub-Total', 'woocommerce-gateway-stripe' ), |
|
298 | + 'sub_total' => __('Sub-Total', 'woocommerce-gateway-stripe'), |
|
299 | 299 | ), |
300 | 300 | ); |
301 | 301 | |
302 | - wp_localize_script( 'woocommerce_stripe_apple_pay_single', 'wc_stripe_apple_pay_single_params', apply_filters( 'wc_stripe_apple_pay_single_params', $stripe_params ) ); |
|
302 | + wp_localize_script('woocommerce_stripe_apple_pay_single', 'wc_stripe_apple_pay_single_params', apply_filters('wc_stripe_apple_pay_single_params', $stripe_params)); |
|
303 | 303 | } |
304 | 304 | |
305 | 305 | /** |
@@ -309,32 +309,32 @@ discard block |
||
309 | 309 | * @version 3.1.0 |
310 | 310 | */ |
311 | 311 | public function cart_scripts() { |
312 | - if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) ) { |
|
312 | + if ( ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order'])) { |
|
313 | 313 | return; |
314 | 314 | } |
315 | 315 | |
316 | - $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
316 | + $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; |
|
317 | 317 | |
318 | - wp_enqueue_style( 'stripe_apple_pay', plugins_url( 'assets/css/stripe-apple-pay.css', WC_STRIPE_MAIN_FILE ), array(), WC_STRIPE_VERSION ); |
|
318 | + wp_enqueue_style('stripe_apple_pay', plugins_url('assets/css/stripe-apple-pay.css', WC_STRIPE_MAIN_FILE), array(), WC_STRIPE_VERSION); |
|
319 | 319 | |
320 | - wp_enqueue_script( 'stripe', 'https://js.stripe.com/v2/', '', '1.0', true ); |
|
321 | - wp_enqueue_script( 'woocommerce_stripe_apple_pay', plugins_url( 'assets/js/stripe-apple-pay' . $suffix . '.js', WC_STRIPE_MAIN_FILE ), array( 'stripe' ), WC_STRIPE_VERSION, true ); |
|
320 | + wp_enqueue_script('stripe', 'https://js.stripe.com/v2/', '', '1.0', true); |
|
321 | + wp_enqueue_script('woocommerce_stripe_apple_pay', plugins_url('assets/js/stripe-apple-pay' . $suffix . '.js', WC_STRIPE_MAIN_FILE), array('stripe'), WC_STRIPE_VERSION, true); |
|
322 | 322 | |
323 | 323 | $stripe_params = array( |
324 | 324 | 'key' => $this->publishable_key, |
325 | 325 | 'currency_code' => get_woocommerce_currency(), |
326 | - 'country_code' => substr( get_option( 'woocommerce_default_country' ), 0, 2 ), |
|
326 | + 'country_code' => substr(get_option('woocommerce_default_country'), 0, 2), |
|
327 | 327 | 'label' => $this->statement_descriptor . ' (via WooCommerce)', |
328 | - 'ajaxurl' => WC_AJAX::get_endpoint( '%%endpoint%%' ), |
|
329 | - 'stripe_apple_pay_nonce' => wp_create_nonce( '_wc_stripe_apple_pay_nonce' ), |
|
330 | - 'stripe_apple_pay_cart_nonce' => wp_create_nonce( '_wc_stripe_apple_pay_cart_nonce' ), |
|
331 | - 'stripe_apple_pay_get_shipping_methods_nonce' => wp_create_nonce( '_wc_stripe_apple_pay_get_shipping_methods_nonce' ), |
|
332 | - 'stripe_apple_pay_update_shipping_method_nonce' => wp_create_nonce( '_wc_stripe_apple_pay_update_shipping_method_nonce' ), |
|
333 | - 'needs_shipping' => ( WC()->cart->needs_shipping() && $this->is_shipping_enabled ) ? 'yes' : 'no', |
|
328 | + 'ajaxurl' => WC_AJAX::get_endpoint('%%endpoint%%'), |
|
329 | + 'stripe_apple_pay_nonce' => wp_create_nonce('_wc_stripe_apple_pay_nonce'), |
|
330 | + 'stripe_apple_pay_cart_nonce' => wp_create_nonce('_wc_stripe_apple_pay_cart_nonce'), |
|
331 | + 'stripe_apple_pay_get_shipping_methods_nonce' => wp_create_nonce('_wc_stripe_apple_pay_get_shipping_methods_nonce'), |
|
332 | + 'stripe_apple_pay_update_shipping_method_nonce' => wp_create_nonce('_wc_stripe_apple_pay_update_shipping_method_nonce'), |
|
333 | + 'needs_shipping' => (WC()->cart->needs_shipping() && $this->is_shipping_enabled) ? 'yes' : 'no', |
|
334 | 334 | 'is_cart_page' => is_cart() ? 'yes' : 'no', |
335 | 335 | ); |
336 | 336 | |
337 | - wp_localize_script( 'woocommerce_stripe_apple_pay', 'wc_stripe_apple_pay_params', apply_filters( 'wc_stripe_apple_pay_params', $stripe_params ) ); |
|
337 | + wp_localize_script('woocommerce_stripe_apple_pay', 'wc_stripe_apple_pay_params', apply_filters('wc_stripe_apple_pay_params', $stripe_params)); |
|
338 | 338 | } |
339 | 339 | |
340 | 340 | /** |
@@ -345,11 +345,11 @@ discard block |
||
345 | 345 | * @return array |
346 | 346 | */ |
347 | 347 | public function supported_product_types() { |
348 | - return apply_filters( 'wc_stripe_apple_pay_supported_types', array( |
|
348 | + return apply_filters('wc_stripe_apple_pay_supported_types', array( |
|
349 | 349 | 'simple', |
350 | 350 | 'variable', |
351 | 351 | 'variation', |
352 | - ) ); |
|
352 | + )); |
|
353 | 353 | } |
354 | 354 | |
355 | 355 | /** |
@@ -361,10 +361,10 @@ discard block |
||
361 | 361 | * @return bool |
362 | 362 | */ |
363 | 363 | public function allowed_items_in_cart() { |
364 | - foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) { |
|
365 | - $_product = apply_filters( 'woocommerce_cart_item_product', $cart_item['data'], $cart_item, $cart_item_key ); |
|
364 | + foreach (WC()->cart->get_cart() as $cart_item_key => $cart_item) { |
|
365 | + $_product = apply_filters('woocommerce_cart_item_product', $cart_item['data'], $cart_item, $cart_item_key); |
|
366 | 366 | |
367 | - if ( ! in_array( ( version_compare( WC_VERSION, '3.0.0', '<' ) ? $_product->product_type : $_product->get_type() ), $this->supported_product_types() ) ) { |
|
367 | + if ( ! in_array((version_compare(WC_VERSION, '3.0.0', '<') ? $_product->product_type : $_product->get_type()), $this->supported_product_types())) { |
|
368 | 368 | return false; |
369 | 369 | } |
370 | 370 | } |
@@ -385,29 +385,29 @@ discard block |
||
385 | 385 | * In order for the Apple Pay button to show on product detail page, |
386 | 386 | * Apple Pay must be enabled and Stripe gateway must be enabled. |
387 | 387 | */ |
388 | - if ( ! $this->apple_pay || ! isset( $gateways['stripe'] ) ) { |
|
389 | - $this->log( 'Apple Pay not enabled or Stripe is not an available gateway ( Apple Pay button disabled )' ); |
|
388 | + if ( ! $this->apple_pay || ! isset($gateways['stripe'])) { |
|
389 | + $this->log('Apple Pay not enabled or Stripe is not an available gateway ( Apple Pay button disabled )'); |
|
390 | 390 | return; |
391 | 391 | } |
392 | 392 | |
393 | - if ( is_single() ) { |
|
393 | + if (is_single()) { |
|
394 | 394 | global $post; |
395 | 395 | |
396 | - $product = wc_get_product( $post->ID ); |
|
396 | + $product = wc_get_product($post->ID); |
|
397 | 397 | |
398 | - if ( ! is_object( $product ) || ! in_array( ( version_compare( WC_VERSION, '3.0.0', '<' ) ? $product->product_type : $product->get_type() ), $this->supported_product_types() ) ) { |
|
398 | + if ( ! is_object($product) || ! in_array((version_compare(WC_VERSION, '3.0.0', '<') ? $product->product_type : $product->get_type()), $this->supported_product_types())) { |
|
399 | 399 | return; |
400 | 400 | } |
401 | 401 | } else { |
402 | - if ( ! $this->allowed_items_in_cart() ) { |
|
403 | - $this->log( 'Items in the cart has unsupported product type ( Apple Pay button disabled )' ); |
|
402 | + if ( ! $this->allowed_items_in_cart()) { |
|
403 | + $this->log('Items in the cart has unsupported product type ( Apple Pay button disabled )'); |
|
404 | 404 | return; |
405 | 405 | } |
406 | 406 | } |
407 | 407 | |
408 | 408 | ?> |
409 | 409 | <div class="apple-pay-button-wrapper"> |
410 | - <button class="apple-pay-button" lang="<?php echo esc_attr( $this->apple_pay_button_lang ); ?>" style="-webkit-appearance: -apple-pay-button; -apple-pay-button-type: buy; -apple-pay-button-style: <?php echo esc_attr( $this->apple_pay_button ); ?>;" alt="<?php esc_attr_e( 'Buy with Apple Pay', 'woocommerce-gateway-stripe' ); ?>"></button> |
|
410 | + <button class="apple-pay-button" lang="<?php echo esc_attr($this->apple_pay_button_lang); ?>" style="-webkit-appearance: -apple-pay-button; -apple-pay-button-type: buy; -apple-pay-button-style: <?php echo esc_attr($this->apple_pay_button); ?>;" alt="<?php esc_attr_e('Buy with Apple Pay', 'woocommerce-gateway-stripe'); ?>"></button> |
|
411 | 411 | </div> |
412 | 412 | <?php |
413 | 413 | } |
@@ -425,17 +425,17 @@ discard block |
||
425 | 425 | * In order for the Apple Pay button to show on cart page, |
426 | 426 | * Apple Pay must be enabled and Stripe gateway must be enabled. |
427 | 427 | */ |
428 | - if ( ! $this->apple_pay || ! isset( $gateways['stripe'] ) ) { |
|
429 | - $this->log( 'Apple Pay not enabled or Stripe is not an available gateway ( Apple Pay button disabled )' ); |
|
428 | + if ( ! $this->apple_pay || ! isset($gateways['stripe'])) { |
|
429 | + $this->log('Apple Pay not enabled or Stripe is not an available gateway ( Apple Pay button disabled )'); |
|
430 | 430 | return; |
431 | 431 | } |
432 | 432 | |
433 | - if ( ! $this->allowed_items_in_cart() ) { |
|
434 | - $this->log( 'Items in the cart has unsupported product type ( Apple Pay button disabled )' ); |
|
433 | + if ( ! $this->allowed_items_in_cart()) { |
|
434 | + $this->log('Items in the cart has unsupported product type ( Apple Pay button disabled )'); |
|
435 | 435 | return; |
436 | 436 | } |
437 | 437 | ?> |
438 | - <p class="apple-pay-button-checkout-separator">- <?php esc_html_e( 'Or', 'woocommerce-gateway-stripe' ); ?> -</p> |
|
438 | + <p class="apple-pay-button-checkout-separator">- <?php esc_html_e('Or', 'woocommerce-gateway-stripe'); ?> -</p> |
|
439 | 439 | <?php |
440 | 440 | } |
441 | 441 | |
@@ -446,45 +446,45 @@ discard block |
||
446 | 446 | * @version 3.1.0 |
447 | 447 | */ |
448 | 448 | public function generate_apple_pay_single() { |
449 | - if ( ! wp_verify_nonce( $_POST['nonce'], '_wc_stripe_apple_pay_cart_nonce' ) ) { |
|
450 | - wp_die( __( 'Cheatin’ huh?', 'woocommerce-gateway-stripe' ) ); |
|
449 | + if ( ! wp_verify_nonce($_POST['nonce'], '_wc_stripe_apple_pay_cart_nonce')) { |
|
450 | + wp_die(__('Cheatin’ huh?', 'woocommerce-gateway-stripe')); |
|
451 | 451 | } |
452 | 452 | |
453 | - if ( ! defined( 'WOOCOMMERCE_CART' ) ) { |
|
454 | - define( 'WOOCOMMERCE_CART', true ); |
|
453 | + if ( ! defined('WOOCOMMERCE_CART')) { |
|
454 | + define('WOOCOMMERCE_CART', true); |
|
455 | 455 | } |
456 | 456 | |
457 | 457 | WC()->shipping->reset_shipping(); |
458 | 458 | |
459 | 459 | global $post; |
460 | 460 | |
461 | - $product = wc_get_product( $post->ID ); |
|
462 | - $qty = ! isset( $_POST['qty'] ) ? 1 : absint( $_POST['qty'] ); |
|
461 | + $product = wc_get_product($post->ID); |
|
462 | + $qty = ! isset($_POST['qty']) ? 1 : absint($_POST['qty']); |
|
463 | 463 | |
464 | 464 | /** |
465 | 465 | * If this page is single product page, we need to simulate |
466 | 466 | * adding the product to the cart taken account if it is a |
467 | 467 | * simple or variable product. |
468 | 468 | */ |
469 | - if ( is_single() ) { |
|
469 | + if (is_single()) { |
|
470 | 470 | // First empty the cart to prevent wrong calculation. |
471 | 471 | WC()->cart->empty_cart(); |
472 | 472 | |
473 | - if ( 'variable' === ( version_compare( WC_VERSION, '3.0.0', '<' ) ? $product->product_type : $product->get_type() ) && isset( $_POST['attributes'] ) ) { |
|
474 | - $attributes = array_map( 'wc_clean', $_POST['attributes'] ); |
|
473 | + if ('variable' === (version_compare(WC_VERSION, '3.0.0', '<') ? $product->product_type : $product->get_type()) && isset($_POST['attributes'])) { |
|
474 | + $attributes = array_map('wc_clean', $_POST['attributes']); |
|
475 | 475 | |
476 | - if ( version_compare( WC_VERSION, '3.0.0', '<' ) ) { |
|
477 | - $variation_id = $product->get_matching_variation( $attributes ); |
|
476 | + if (version_compare(WC_VERSION, '3.0.0', '<')) { |
|
477 | + $variation_id = $product->get_matching_variation($attributes); |
|
478 | 478 | } else { |
479 | - $data_store = WC_Data_Store::load( 'product' ); |
|
480 | - $variation_id = $data_store->find_matching_product_variation( $product, $attributes ); |
|
479 | + $data_store = WC_Data_Store::load('product'); |
|
480 | + $variation_id = $data_store->find_matching_product_variation($product, $attributes); |
|
481 | 481 | } |
482 | 482 | |
483 | - WC()->cart->add_to_cart( $product->get_id(), $qty, $variation_id, $attributes ); |
|
483 | + WC()->cart->add_to_cart($product->get_id(), $qty, $variation_id, $attributes); |
|
484 | 484 | } |
485 | 485 | |
486 | - if ( 'simple' === ( version_compare( WC_VERSION, '3.0.0', '<' ) ? $product->product_type : $product->get_type() ) ) { |
|
487 | - WC()->cart->add_to_cart( $product->get_id(), $qty ); |
|
486 | + if ('simple' === (version_compare(WC_VERSION, '3.0.0', '<') ? $product->product_type : $product->get_type())) { |
|
487 | + WC()->cart->add_to_cart($product->get_id(), $qty); |
|
488 | 488 | } |
489 | 489 | } |
490 | 490 | |
@@ -492,7 +492,7 @@ discard block |
||
492 | 492 | |
493 | 493 | $build_items = $this->build_line_items(); |
494 | 494 | |
495 | - wp_send_json( array( 'line_items' => $build_items['line_items'], 'total' => $build_items['total'] ) ); |
|
495 | + wp_send_json(array('line_items' => $build_items['line_items'], 'total' => $build_items['total'])); |
|
496 | 496 | } |
497 | 497 | |
498 | 498 | /** |
@@ -502,13 +502,13 @@ discard block |
||
502 | 502 | * @version 3.1.0 |
503 | 503 | */ |
504 | 504 | public function generate_apple_pay_cart() { |
505 | - if ( ! wp_verify_nonce( $_POST['nonce'], '_wc_stripe_apple_pay_cart_nonce' ) ) { |
|
506 | - wp_die( __( 'Cheatin’ huh?', 'woocommerce-gateway-stripe' ) ); |
|
505 | + if ( ! wp_verify_nonce($_POST['nonce'], '_wc_stripe_apple_pay_cart_nonce')) { |
|
506 | + wp_die(__('Cheatin’ huh?', 'woocommerce-gateway-stripe')); |
|
507 | 507 | } |
508 | 508 | |
509 | 509 | $build_items = $this->build_line_items(); |
510 | 510 | |
511 | - wp_send_json( array( 'line_items' => $build_items['line_items'], 'total' => $build_items['total'] ) ); |
|
511 | + wp_send_json(array('line_items' => $build_items['line_items'], 'total' => $build_items['total'])); |
|
512 | 512 | } |
513 | 513 | |
514 | 514 | /** |
@@ -529,29 +529,29 @@ discard block |
||
529 | 529 | * @version 3.1.0 |
530 | 530 | * @param array $address |
531 | 531 | */ |
532 | - public function calculate_shipping( $address = array() ) { |
|
533 | - $country = strtoupper( $address['countryCode'] ); |
|
534 | - $state = strtoupper( $address['administrativeArea'] ); |
|
532 | + public function calculate_shipping($address = array()) { |
|
533 | + $country = strtoupper($address['countryCode']); |
|
534 | + $state = strtoupper($address['administrativeArea']); |
|
535 | 535 | $postcode = $address['postalCode']; |
536 | 536 | $city = $address['locality']; |
537 | 537 | |
538 | 538 | WC()->shipping->reset_shipping(); |
539 | 539 | |
540 | - if ( $postcode && ! WC_Validation::is_postcode( $postcode, $country ) ) { |
|
541 | - throw new Exception( __( 'Please enter a valid postcode/ZIP.', 'woocommerce-gateway-stripe' ) ); |
|
542 | - } elseif ( $postcode ) { |
|
543 | - $postcode = wc_format_postcode( $postcode, $country ); |
|
540 | + if ($postcode && ! WC_Validation::is_postcode($postcode, $country)) { |
|
541 | + throw new Exception(__('Please enter a valid postcode/ZIP.', 'woocommerce-gateway-stripe')); |
|
542 | + } elseif ($postcode) { |
|
543 | + $postcode = wc_format_postcode($postcode, $country); |
|
544 | 544 | } |
545 | 545 | |
546 | - if ( $country ) { |
|
547 | - WC()->customer->set_location( $country, $state, $postcode, $city ); |
|
548 | - WC()->customer->set_shipping_location( $country, $state, $postcode, $city ); |
|
546 | + if ($country) { |
|
547 | + WC()->customer->set_location($country, $state, $postcode, $city); |
|
548 | + WC()->customer->set_shipping_location($country, $state, $postcode, $city); |
|
549 | 549 | } else { |
550 | 550 | WC()->customer->set_to_base(); |
551 | 551 | WC()->customer->set_shipping_to_base(); |
552 | 552 | } |
553 | 553 | |
554 | - version_compare( WC_VERSION, '3.0', '<' ) ? WC()->customer->calculated_shipping( true ) : WC()->customer->set_calculated_shipping( true ); |
|
554 | + version_compare(WC_VERSION, '3.0', '<') ? WC()->customer->calculated_shipping(true) : WC()->customer->set_calculated_shipping(true); |
|
555 | 555 | |
556 | 556 | WC()->customer->save(); |
557 | 557 | |
@@ -575,17 +575,17 @@ discard block |
||
575 | 575 | $packages[0]['destination']['postcode'] = $postcode; |
576 | 576 | $packages[0]['destination']['city'] = $city; |
577 | 577 | |
578 | - foreach ( WC()->cart->get_cart() as $item ) { |
|
579 | - if ( $item['data']->needs_shipping() ) { |
|
580 | - if ( isset( $item['line_total'] ) ) { |
|
578 | + foreach (WC()->cart->get_cart() as $item) { |
|
579 | + if ($item['data']->needs_shipping()) { |
|
580 | + if (isset($item['line_total'])) { |
|
581 | 581 | $packages[0]['contents_cost'] += $item['line_total']; |
582 | 582 | } |
583 | 583 | } |
584 | 584 | } |
585 | 585 | |
586 | - $packages = apply_filters( 'woocommerce_cart_shipping_packages', $packages ); |
|
586 | + $packages = apply_filters('woocommerce_cart_shipping_packages', $packages); |
|
587 | 587 | |
588 | - WC()->shipping->calculate_shipping( $packages ); |
|
588 | + WC()->shipping->calculate_shipping($packages); |
|
589 | 589 | } |
590 | 590 | |
591 | 591 | /** |
@@ -595,18 +595,18 @@ discard block |
||
595 | 595 | * @version 3.1.0 |
596 | 596 | */ |
597 | 597 | public function get_shipping_methods() { |
598 | - if ( ! wp_verify_nonce( $_POST['nonce'], '_wc_stripe_apple_pay_get_shipping_methods_nonce' ) ) { |
|
599 | - wp_die( __( 'Cheatin’ huh?', 'woocommerce-gateway-stripe' ) ); |
|
598 | + if ( ! wp_verify_nonce($_POST['nonce'], '_wc_stripe_apple_pay_get_shipping_methods_nonce')) { |
|
599 | + wp_die(__('Cheatin’ huh?', 'woocommerce-gateway-stripe')); |
|
600 | 600 | } |
601 | 601 | |
602 | - if ( ! defined( 'WOOCOMMERCE_CART' ) ) { |
|
603 | - define( 'WOOCOMMERCE_CART', true ); |
|
602 | + if ( ! defined('WOOCOMMERCE_CART')) { |
|
603 | + define('WOOCOMMERCE_CART', true); |
|
604 | 604 | } |
605 | 605 | |
606 | 606 | try { |
607 | - $address = array_map( 'wc_clean', $_POST['address'] ); |
|
607 | + $address = array_map('wc_clean', $_POST['address']); |
|
608 | 608 | |
609 | - $this->calculate_shipping( $address ); |
|
609 | + $this->calculate_shipping($address); |
|
610 | 610 | |
611 | 611 | // Set the shipping options. |
612 | 612 | $currency = get_woocommerce_currency(); |
@@ -614,13 +614,13 @@ discard block |
||
614 | 614 | |
615 | 615 | $packages = WC()->shipping->get_packages(); |
616 | 616 | |
617 | - if ( ! empty( $packages ) && WC()->customer->has_calculated_shipping() ) { |
|
618 | - foreach ( $packages as $package_key => $package ) { |
|
619 | - if ( empty( $package['rates'] ) ) { |
|
620 | - throw new Exception( __( 'Unable to find shipping method for address.', 'woocommerce-gateway-stripe' ) ); |
|
617 | + if ( ! empty($packages) && WC()->customer->has_calculated_shipping()) { |
|
618 | + foreach ($packages as $package_key => $package) { |
|
619 | + if (empty($package['rates'])) { |
|
620 | + throw new Exception(__('Unable to find shipping method for address.', 'woocommerce-gateway-stripe')); |
|
621 | 621 | } |
622 | 622 | |
623 | - foreach ( $package['rates'] as $key => $rate ) { |
|
623 | + foreach ($package['rates'] as $key => $rate) { |
|
624 | 624 | $data[] = array( |
625 | 625 | 'id' => $rate->id, |
626 | 626 | 'label' => $rate->label, |
@@ -634,19 +634,19 @@ discard block |
||
634 | 634 | } |
635 | 635 | |
636 | 636 | // Auto select the first shipping method. |
637 | - WC()->session->set( 'chosen_shipping_methods', array( $data[0]['id'] ) ); |
|
637 | + WC()->session->set('chosen_shipping_methods', array($data[0]['id'])); |
|
638 | 638 | |
639 | 639 | WC()->cart->calculate_totals(); |
640 | 640 | |
641 | 641 | $build_items = $this->build_line_items(); |
642 | 642 | |
643 | - wp_send_json( array( 'success' => 'true', 'shipping_methods' => $this->build_shipping_methods( $data ), 'line_items' => $build_items['line_items'], 'total' => $build_items['total'] ) ); |
|
643 | + wp_send_json(array('success' => 'true', 'shipping_methods' => $this->build_shipping_methods($data), 'line_items' => $build_items['line_items'], 'total' => $build_items['total'])); |
|
644 | 644 | } else { |
645 | - throw new Exception( __( 'Unable to find shipping method for address.', 'woocommerce-gateway-stripe' ) ); |
|
645 | + throw new Exception(__('Unable to find shipping method for address.', 'woocommerce-gateway-stripe')); |
|
646 | 646 | } |
647 | - } catch ( Exception $e ) { |
|
647 | + } catch (Exception $e) { |
|
648 | 648 | $build_items = $this->build_line_items(); |
649 | - wp_send_json( array( 'success' => 'false', 'shipping_methods' => array(), 'line_items' => $build_items['line_items'], 'total' => $build_items['total'] ) ); |
|
649 | + wp_send_json(array('success' => 'false', 'shipping_methods' => array(), 'line_items' => $build_items['line_items'], 'total' => $build_items['total'])); |
|
650 | 650 | } |
651 | 651 | } |
652 | 652 | |
@@ -657,22 +657,22 @@ discard block |
||
657 | 657 | * @version 3.1.0 |
658 | 658 | */ |
659 | 659 | public function update_shipping_method() { |
660 | - if ( ! defined( 'WOOCOMMERCE_CART' ) ) { |
|
661 | - define( 'WOOCOMMERCE_CART', true ); |
|
660 | + if ( ! defined('WOOCOMMERCE_CART')) { |
|
661 | + define('WOOCOMMERCE_CART', true); |
|
662 | 662 | } |
663 | 663 | |
664 | - if ( ! wp_verify_nonce( $_POST['nonce'], '_wc_stripe_apple_pay_update_shipping_method_nonce' ) ) { |
|
665 | - wp_die( __( 'Cheatin’ huh?', 'woocommerce-gateway-stripe' ) ); |
|
664 | + if ( ! wp_verify_nonce($_POST['nonce'], '_wc_stripe_apple_pay_update_shipping_method_nonce')) { |
|
665 | + wp_die(__('Cheatin’ huh?', 'woocommerce-gateway-stripe')); |
|
666 | 666 | } |
667 | 667 | |
668 | - $selected_shipping_method = array_map( 'wc_clean', $_POST['selected_shipping_method'] ); |
|
668 | + $selected_shipping_method = array_map('wc_clean', $_POST['selected_shipping_method']); |
|
669 | 669 | |
670 | - WC()->session->set( 'chosen_shipping_methods', array( $selected_shipping_method['identifier'] ) ); |
|
670 | + WC()->session->set('chosen_shipping_methods', array($selected_shipping_method['identifier'])); |
|
671 | 671 | |
672 | 672 | WC()->cart->calculate_totals(); |
673 | 673 | |
674 | 674 | $build_items = $this->build_line_items(); |
675 | - wp_send_json( array( 'success' => 'true', 'line_items' => $build_items['line_items'], 'total' => $build_items['total'] ) ); |
|
675 | + wp_send_json(array('success' => 'true', 'line_items' => $build_items['line_items'], 'total' => $build_items['total'])); |
|
676 | 676 | } |
677 | 677 | |
678 | 678 | /** |
@@ -683,37 +683,37 @@ discard block |
||
683 | 683 | * @version 3.1.0 |
684 | 684 | */ |
685 | 685 | public function process_apple_pay() { |
686 | - if ( ! wp_verify_nonce( $_POST['nonce'], '_wc_stripe_apple_pay_nonce' ) ) { |
|
687 | - wp_die( __( 'Cheatin’ huh?', 'woocommerce-gateway-stripe' ) ); |
|
686 | + if ( ! wp_verify_nonce($_POST['nonce'], '_wc_stripe_apple_pay_nonce')) { |
|
687 | + wp_die(__('Cheatin’ huh?', 'woocommerce-gateway-stripe')); |
|
688 | 688 | } |
689 | 689 | |
690 | 690 | try { |
691 | - $result = array_map( 'wc_clean', $_POST['result'] ); |
|
691 | + $result = array_map('wc_clean', $_POST['result']); |
|
692 | 692 | |
693 | - $order = $this->create_order( $result ); |
|
693 | + $order = $this->create_order($result); |
|
694 | 694 | |
695 | - $order_id = version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->id : $order->get_id(); |
|
695 | + $order_id = version_compare(WC_VERSION, '3.0.0', '<') ? $order->id : $order->get_id(); |
|
696 | 696 | |
697 | 697 | // Handle payment. |
698 | - if ( $order->get_total() > 0 ) { |
|
698 | + if ($order->get_total() > 0) { |
|
699 | 699 | |
700 | - if ( $order->get_total() * 100 < WC_Stripe::get_minimum_amount() ) { |
|
701 | - return new WP_Error( 'stripe_error', sprintf( __( 'Sorry, the minimum allowed order total is %1$s to use this payment method.', 'woocommerce-gateway-stripe' ), wc_price( WC_Stripe::get_minimum_amount() / 100 ) ) ); |
|
700 | + if ($order->get_total() * 100 < WC_Stripe::get_minimum_amount()) { |
|
701 | + return new WP_Error('stripe_error', sprintf(__('Sorry, the minimum allowed order total is %1$s to use this payment method.', 'woocommerce-gateway-stripe'), wc_price(WC_Stripe::get_minimum_amount() / 100))); |
|
702 | 702 | } |
703 | 703 | |
704 | - $this->log( "Info: Begin processing payment for order {$order_id} for the amount of {$order->get_total()}" ); |
|
704 | + $this->log("Info: Begin processing payment for order {$order_id} for the amount of {$order->get_total()}"); |
|
705 | 705 | |
706 | 706 | // Make the request. |
707 | - $response = WC_Stripe_API::request( $this->generate_payment_request( $order, $result['token']['id'] ) ); |
|
707 | + $response = WC_Stripe_API::request($this->generate_payment_request($order, $result['token']['id'])); |
|
708 | 708 | |
709 | - if ( is_wp_error( $response ) ) { |
|
709 | + if (is_wp_error($response)) { |
|
710 | 710 | $localized_messages = $this->get_localized_messages(); |
711 | 711 | |
712 | - throw new Exception( ( isset( $localized_messages[ $response->get_error_code() ] ) ? $localized_messages[ $response->get_error_code() ] : $response->get_error_message() ) ); |
|
712 | + throw new Exception((isset($localized_messages[$response->get_error_code()]) ? $localized_messages[$response->get_error_code()] : $response->get_error_message())); |
|
713 | 713 | } |
714 | 714 | |
715 | 715 | // Process valid response. |
716 | - $this->process_response( $response, $order ); |
|
716 | + $this->process_response($response, $order); |
|
717 | 717 | } else { |
718 | 718 | $order->payment_complete(); |
719 | 719 | } |
@@ -721,24 +721,24 @@ discard block |
||
721 | 721 | // Remove cart. |
722 | 722 | WC()->cart->empty_cart(); |
723 | 723 | |
724 | - update_post_meta( $order_id, '_customer_user', get_current_user_id() ); |
|
725 | - update_post_meta( $order_id, '_payment_method_title', 'Apple Pay (Stripe)' ); |
|
724 | + update_post_meta($order_id, '_customer_user', get_current_user_id()); |
|
725 | + update_post_meta($order_id, '_payment_method_title', 'Apple Pay (Stripe)'); |
|
726 | 726 | |
727 | 727 | // Return thank you page redirect. |
728 | - wp_send_json( array( |
|
728 | + wp_send_json(array( |
|
729 | 729 | 'success' => 'true', |
730 | - 'redirect' => $this->get_return_url( $order ), |
|
731 | - ) ); |
|
730 | + 'redirect' => $this->get_return_url($order), |
|
731 | + )); |
|
732 | 732 | |
733 | - } catch ( Exception $e ) { |
|
734 | - WC()->session->set( 'refresh_totals', true ); |
|
735 | - $this->log( sprintf( __( 'Error: %s', 'woocommerce-gateway-stripe' ), $e->getMessage() ) ); |
|
733 | + } catch (Exception $e) { |
|
734 | + WC()->session->set('refresh_totals', true); |
|
735 | + $this->log(sprintf(__('Error: %s', 'woocommerce-gateway-stripe'), $e->getMessage())); |
|
736 | 736 | |
737 | - if ( is_object( $order ) && isset( $order_id ) && $order->has_status( array( 'pending', 'failed' ) ) ) { |
|
738 | - $this->send_failed_order_email( $order_id ); |
|
737 | + if (is_object($order) && isset($order_id) && $order->has_status(array('pending', 'failed'))) { |
|
738 | + $this->send_failed_order_email($order_id); |
|
739 | 739 | } |
740 | 740 | |
741 | - wp_send_json( array( 'success' => 'false', 'msg' => $e->getMessage() ) ); |
|
741 | + wp_send_json(array('success' => 'false', 'msg' => $e->getMessage())); |
|
742 | 742 | } |
743 | 743 | } |
744 | 744 | |
@@ -748,16 +748,16 @@ discard block |
||
748 | 748 | * @param string $source token |
749 | 749 | * @return array() |
750 | 750 | */ |
751 | - protected function generate_payment_request( $order, $source ) { |
|
751 | + protected function generate_payment_request($order, $source) { |
|
752 | 752 | $post_data = array(); |
753 | - $post_data['currency'] = strtolower( version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->get_order_currency() : $order->get_currency() ); |
|
754 | - $post_data['amount'] = $this->get_stripe_amount( $order->get_total(), $post_data['currency'] ); |
|
755 | - $post_data['description'] = sprintf( __( '%1$s - Order %2$s', 'woocommerce-gateway-stripe' ), $this->statement_descriptor, $order->get_order_number() ); |
|
753 | + $post_data['currency'] = strtolower(version_compare(WC_VERSION, '3.0.0', '<') ? $order->get_order_currency() : $order->get_currency()); |
|
754 | + $post_data['amount'] = $this->get_stripe_amount($order->get_total(), $post_data['currency']); |
|
755 | + $post_data['description'] = sprintf(__('%1$s - Order %2$s', 'woocommerce-gateway-stripe'), $this->statement_descriptor, $order->get_order_number()); |
|
756 | 756 | $post_data['capture'] = $this->capture ? 'true' : 'false'; |
757 | 757 | |
758 | - $billing_email = version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->billing_email : $order->get_billing_email(); |
|
758 | + $billing_email = version_compare(WC_VERSION, '3.0.0', '<') ? $order->billing_email : $order->get_billing_email(); |
|
759 | 759 | |
760 | - if ( ! empty( $billing_email ) && apply_filters( 'wc_stripe_send_stripe_receipt', false ) ) { |
|
760 | + if ( ! empty($billing_email) && apply_filters('wc_stripe_send_stripe_receipt', false)) { |
|
761 | 761 | $post_data['receipt_email'] = $billing_email; |
762 | 762 | } |
763 | 763 | |
@@ -772,7 +772,7 @@ discard block |
||
772 | 772 | * @param WC_Order $order |
773 | 773 | * @param object $source |
774 | 774 | */ |
775 | - return apply_filters( 'wc_stripe_generate_payment_request', $post_data, $order ); |
|
775 | + return apply_filters('wc_stripe_generate_payment_request', $post_data, $order); |
|
776 | 776 | } |
777 | 777 | |
778 | 778 | /** |
@@ -781,14 +781,14 @@ discard block |
||
781 | 781 | * @since 3.1.0 |
782 | 782 | * @version 3.1.0 |
783 | 783 | */ |
784 | - public function build_shipping_methods( $shipping_methods ) { |
|
785 | - if ( empty( $shipping_methods ) ) { |
|
784 | + public function build_shipping_methods($shipping_methods) { |
|
785 | + if (empty($shipping_methods)) { |
|
786 | 786 | return array(); |
787 | 787 | } |
788 | 788 | |
789 | 789 | $shipping = array(); |
790 | 790 | |
791 | - foreach ( $shipping_methods as $method ) { |
|
791 | + foreach ($shipping_methods as $method) { |
|
792 | 792 | $shipping[] = array( |
793 | 793 | 'label' => $method['label'], |
794 | 794 | 'detail' => '', |
@@ -807,70 +807,70 @@ discard block |
||
807 | 807 | * @version 3.2.0 |
808 | 808 | */ |
809 | 809 | public function build_line_items() { |
810 | - if ( ! defined( 'WOOCOMMERCE_CART' ) ) { |
|
811 | - define( 'WOOCOMMERCE_CART', true ); |
|
810 | + if ( ! defined('WOOCOMMERCE_CART')) { |
|
811 | + define('WOOCOMMERCE_CART', true); |
|
812 | 812 | } |
813 | 813 | |
814 | 814 | $items = array(); |
815 | 815 | $subtotal = 0; |
816 | 816 | |
817 | - foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) { |
|
818 | - $amount = wc_format_decimal( $cart_item['line_subtotal'], $this->dp ); |
|
819 | - $subtotal += $cart_item['line_subtotal']; |
|
817 | + foreach (WC()->cart->get_cart() as $cart_item_key => $cart_item) { |
|
818 | + $amount = wc_format_decimal($cart_item['line_subtotal'], $this->dp); |
|
819 | + $subtotal += $cart_item['line_subtotal']; |
|
820 | 820 | $quantity_label = 1 < $cart_item['quantity'] ? ' (x' . $cart_item['quantity'] . ')' : ''; |
821 | 821 | |
822 | - $product_name = version_compare( WC_VERSION, '3.0', '<' ) ? $cart_item['data']->post->post_title : $cart_item['data']->get_name(); |
|
822 | + $product_name = version_compare(WC_VERSION, '3.0', '<') ? $cart_item['data']->post->post_title : $cart_item['data']->get_name(); |
|
823 | 823 | |
824 | 824 | $item = array( |
825 | 825 | 'type' => 'final', |
826 | 826 | 'label' => $product_name . $quantity_label, |
827 | - 'amount' => wc_format_decimal( $amount, $this->dp ), |
|
827 | + 'amount' => wc_format_decimal($amount, $this->dp), |
|
828 | 828 | ); |
829 | 829 | |
830 | 830 | $items[] = $item; |
831 | 831 | } |
832 | 832 | |
833 | 833 | // Default show only subtotal instead of itemization. |
834 | - if ( apply_filters( 'wc_stripe_apple_pay_disable_itemization', true ) ) { |
|
834 | + if (apply_filters('wc_stripe_apple_pay_disable_itemization', true)) { |
|
835 | 835 | $items = array(); |
836 | 836 | $items[] = array( |
837 | 837 | 'type' => 'final', |
838 | - 'label' => esc_html( __( 'Sub-Total', 'woocommerce-gateway-stripe' ) ), |
|
839 | - 'amount' => wc_format_decimal( $subtotal, $decimals ), |
|
838 | + 'label' => esc_html(__('Sub-Total', 'woocommerce-gateway-stripe')), |
|
839 | + 'amount' => wc_format_decimal($subtotal, $decimals), |
|
840 | 840 | ); |
841 | 841 | } |
842 | 842 | |
843 | - $discounts = wc_format_decimal( WC()->cart->get_cart_discount_total(), $this->dp ); |
|
844 | - $tax = wc_format_decimal( WC()->cart->tax_total + WC()->cart->shipping_tax_total, $this->dp ); |
|
845 | - $shipping = wc_format_decimal( WC()->cart->shipping_total, $this->dp ); |
|
846 | - $item_total = wc_format_decimal( WC()->cart->cart_contents_total, $this->dp ) + $discounts; |
|
847 | - $order_total = wc_format_decimal( $item_total + $tax + $shipping, $this->dp ); |
|
843 | + $discounts = wc_format_decimal(WC()->cart->get_cart_discount_total(), $this->dp); |
|
844 | + $tax = wc_format_decimal(WC()->cart->tax_total + WC()->cart->shipping_tax_total, $this->dp); |
|
845 | + $shipping = wc_format_decimal(WC()->cart->shipping_total, $this->dp); |
|
846 | + $item_total = wc_format_decimal(WC()->cart->cart_contents_total, $this->dp) + $discounts; |
|
847 | + $order_total = wc_format_decimal($item_total + $tax + $shipping, $this->dp); |
|
848 | 848 | |
849 | - if ( wc_tax_enabled() ) { |
|
849 | + if (wc_tax_enabled()) { |
|
850 | 850 | $items[] = array( |
851 | 851 | 'type' => 'final', |
852 | - 'label' => esc_html( __( 'Tax', 'woocommerce-gateway-stripe' ) ), |
|
852 | + 'label' => esc_html(__('Tax', 'woocommerce-gateway-stripe')), |
|
853 | 853 | 'amount' => $tax, |
854 | 854 | ); |
855 | 855 | } |
856 | 856 | |
857 | - if ( WC()->cart->needs_shipping() && $this->is_shipping_enabled ) { |
|
857 | + if (WC()->cart->needs_shipping() && $this->is_shipping_enabled) { |
|
858 | 858 | $items[] = array( |
859 | 859 | 'type' => 'final', |
860 | - 'label' => esc_html( __( 'Shipping', 'woocommerce-gateway-stripe' ) ), |
|
860 | + 'label' => esc_html(__('Shipping', 'woocommerce-gateway-stripe')), |
|
861 | 861 | 'amount' => $shipping, |
862 | 862 | ); |
863 | 863 | } |
864 | 864 | |
865 | - if ( WC()->cart->has_discount() ) { |
|
865 | + if (WC()->cart->has_discount()) { |
|
866 | 866 | $items[] = array( |
867 | 867 | 'type' => 'final', |
868 | - 'label' => esc_html( __( 'Discount', 'woocommerce-gateway-stripe' ) ), |
|
868 | + 'label' => esc_html(__('Discount', 'woocommerce-gateway-stripe')), |
|
869 | 869 | 'amount' => '-' . $discounts, |
870 | 870 | ); |
871 | 871 | } |
872 | 872 | |
873 | - return array( 'line_items' => $items, 'total' => $order_total ); |
|
873 | + return array('line_items' => $items, 'total' => $order_total); |
|
874 | 874 | } |
875 | 875 | |
876 | 876 | /** |
@@ -881,28 +881,28 @@ discard block |
||
881 | 881 | * @param array $data |
882 | 882 | * @return object $order |
883 | 883 | */ |
884 | - public function create_order( $data = array() ) { |
|
885 | - if ( empty( $data ) ) { |
|
886 | - throw new Exception( sprintf( __( 'Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe' ), 520 ) ); |
|
884 | + public function create_order($data = array()) { |
|
885 | + if (empty($data)) { |
|
886 | + throw new Exception(sprintf(__('Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe'), 520)); |
|
887 | 887 | } |
888 | 888 | |
889 | - if ( ! defined( 'WOOCOMMERCE_CART' ) ) { |
|
890 | - define( 'WOOCOMMERCE_CART', true ); |
|
889 | + if ( ! defined('WOOCOMMERCE_CART')) { |
|
890 | + define('WOOCOMMERCE_CART', true); |
|
891 | 891 | } |
892 | 892 | |
893 | 893 | $order = wc_create_order(); |
894 | - $order_id = version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->id : $order->get_id(); |
|
894 | + $order_id = version_compare(WC_VERSION, '3.0.0', '<') ? $order->id : $order->get_id(); |
|
895 | 895 | |
896 | - if ( is_wp_error( $order ) ) { |
|
897 | - throw new Exception( sprintf( __( 'Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe' ), 520 ) ); |
|
898 | - } elseif ( false === $order ) { |
|
899 | - throw new Exception( sprintf( __( 'Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe' ), 521 ) ); |
|
896 | + if (is_wp_error($order)) { |
|
897 | + throw new Exception(sprintf(__('Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe'), 520)); |
|
898 | + } elseif (false === $order) { |
|
899 | + throw new Exception(sprintf(__('Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe'), 521)); |
|
900 | 900 | } else { |
901 | - do_action( 'woocommerce_new_order', $order_id ); |
|
901 | + do_action('woocommerce_new_order', $order_id); |
|
902 | 902 | } |
903 | 903 | |
904 | 904 | // Store the line items to the new/resumed order |
905 | - foreach ( WC()->cart->get_cart() as $cart_item_key => $values ) { |
|
905 | + foreach (WC()->cart->get_cart() as $cart_item_key => $values) { |
|
906 | 906 | $item_id = $order->add_product( |
907 | 907 | $values['data'], |
908 | 908 | $values['quantity'], |
@@ -918,25 +918,25 @@ discard block |
||
918 | 918 | ) |
919 | 919 | ); |
920 | 920 | |
921 | - if ( ! $item_id ) { |
|
922 | - throw new Exception( sprintf( __( 'Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe' ), 525 ) ); |
|
921 | + if ( ! $item_id) { |
|
922 | + throw new Exception(sprintf(__('Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe'), 525)); |
|
923 | 923 | } |
924 | 924 | |
925 | 925 | // Allow plugins to add order item meta |
926 | - if ( version_compare( WC_VERSION, '3.0', '<' ) ) { |
|
927 | - do_action( 'woocommerce_add_order_item_meta', $item_id, $values, $cart_item_key ); |
|
926 | + if (version_compare(WC_VERSION, '3.0', '<')) { |
|
927 | + do_action('woocommerce_add_order_item_meta', $item_id, $values, $cart_item_key); |
|
928 | 928 | } else { |
929 | - do_action( 'woocommerce_new_order_item', $item_id, wc_get_product( $item_id ), $order->get_id() ); |
|
929 | + do_action('woocommerce_new_order_item', $item_id, wc_get_product($item_id), $order->get_id()); |
|
930 | 930 | } |
931 | 931 | } |
932 | 932 | |
933 | 933 | // Store fees |
934 | - foreach ( WC()->cart->get_fees() as $fee_key => $fee ) { |
|
935 | - if ( version_compare( WC_VERSION, '3.0', '<' ) ) { |
|
936 | - $item_id = $order->add_fee( $fee ); |
|
934 | + foreach (WC()->cart->get_fees() as $fee_key => $fee) { |
|
935 | + if (version_compare(WC_VERSION, '3.0', '<')) { |
|
936 | + $item_id = $order->add_fee($fee); |
|
937 | 937 | } else { |
938 | 938 | $item = new WC_Order_Item_Fee(); |
939 | - $item->set_props( array( |
|
939 | + $item->set_props(array( |
|
940 | 940 | 'name' => $fee->name, |
941 | 941 | 'tax_class' => $fee->taxable ? $fee->tax_class : 0, |
942 | 942 | 'total' => $fee->amount, |
@@ -945,79 +945,79 @@ discard block |
||
945 | 945 | 'total' => $fee->tax_data, |
946 | 946 | ), |
947 | 947 | 'order_id' => $order->get_id(), |
948 | - ) ); |
|
948 | + )); |
|
949 | 949 | $item_id = $item->save(); |
950 | - $order->add_item( $item ); |
|
950 | + $order->add_item($item); |
|
951 | 951 | } |
952 | 952 | |
953 | - if ( ! $item_id ) { |
|
954 | - throw new Exception( sprintf( __( 'Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe' ), 526 ) ); |
|
953 | + if ( ! $item_id) { |
|
954 | + throw new Exception(sprintf(__('Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe'), 526)); |
|
955 | 955 | } |
956 | 956 | |
957 | 957 | // Allow plugins to add order item meta to fees |
958 | - if ( version_compare( WC_VERSION, '3.0', '<' ) ) { |
|
959 | - do_action( 'woocommerce_add_order_fee_meta', $order_id, $item_id, $fee, $fee_key ); |
|
958 | + if (version_compare(WC_VERSION, '3.0', '<')) { |
|
959 | + do_action('woocommerce_add_order_fee_meta', $order_id, $item_id, $fee, $fee_key); |
|
960 | 960 | } else { |
961 | - do_action( 'woocommerce_new_order_item', $item_id, $fee, $order->get_id() ); |
|
961 | + do_action('woocommerce_new_order_item', $item_id, $fee, $order->get_id()); |
|
962 | 962 | } |
963 | 963 | } |
964 | 964 | |
965 | 965 | // Store tax rows |
966 | - foreach ( array_keys( WC()->cart->taxes + WC()->cart->shipping_taxes ) as $tax_rate_id ) { |
|
967 | - $tax_amount = WC()->cart->get_tax_amount( $tax_rate_id ); |
|
968 | - $shipping_tax_amount = WC()->cart->get_shipping_tax_amount( $tax_rate_id ); |
|
966 | + foreach (array_keys(WC()->cart->taxes + WC()->cart->shipping_taxes) as $tax_rate_id) { |
|
967 | + $tax_amount = WC()->cart->get_tax_amount($tax_rate_id); |
|
968 | + $shipping_tax_amount = WC()->cart->get_shipping_tax_amount($tax_rate_id); |
|
969 | 969 | |
970 | - if ( version_compare( WC_VERSION, '3.0', '<' ) ) { |
|
971 | - $item_id = $order->add_tax( $tax_rate_id, $tax_amount, $shipping_tax_amount ); |
|
970 | + if (version_compare(WC_VERSION, '3.0', '<')) { |
|
971 | + $item_id = $order->add_tax($tax_rate_id, $tax_amount, $shipping_tax_amount); |
|
972 | 972 | } else { |
973 | 973 | $item = new WC_Order_Item_Tax(); |
974 | - $item->set_props( array( |
|
974 | + $item->set_props(array( |
|
975 | 975 | 'rate_id' => $tax_rate_id, |
976 | 976 | 'tax_total' => $tax_amount, |
977 | 977 | 'shipping_tax_total' => $shipping_tax_amount, |
978 | - ) ); |
|
979 | - $item->set_rate( $tax_rate_id ); |
|
980 | - $item->set_order_id( $order->get_id() ); |
|
978 | + )); |
|
979 | + $item->set_rate($tax_rate_id); |
|
980 | + $item->set_order_id($order->get_id()); |
|
981 | 981 | $item_id = $item->save(); |
982 | - $order->add_item( $item ); |
|
982 | + $order->add_item($item); |
|
983 | 983 | } |
984 | 984 | |
985 | - if ( $tax_rate_id && ! $item_id && apply_filters( 'woocommerce_cart_remove_taxes_zero_rate_id', 'zero-rated' ) !== $tax_rate_id ) { |
|
986 | - throw new Exception( sprintf( __( 'Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe' ), 528 ) ); |
|
985 | + if ($tax_rate_id && ! $item_id && apply_filters('woocommerce_cart_remove_taxes_zero_rate_id', 'zero-rated') !== $tax_rate_id) { |
|
986 | + throw new Exception(sprintf(__('Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe'), 528)); |
|
987 | 987 | } |
988 | 988 | } |
989 | 989 | |
990 | 990 | // Store coupons |
991 | - $discount = WC()->cart->get_coupon_discount_amount( $code ); |
|
992 | - $discount_tax = WC()->cart->get_coupon_discount_tax_amount( $code ); |
|
991 | + $discount = WC()->cart->get_coupon_discount_amount($code); |
|
992 | + $discount_tax = WC()->cart->get_coupon_discount_tax_amount($code); |
|
993 | 993 | |
994 | - foreach ( WC()->cart->get_coupons() as $code => $coupon ) { |
|
995 | - if ( version_compare( WC_VERSION, '3.0', '<' ) ) { |
|
996 | - $coupon_id = $order->add_coupon( $code, $discount, $discount_tax ); |
|
994 | + foreach (WC()->cart->get_coupons() as $code => $coupon) { |
|
995 | + if (version_compare(WC_VERSION, '3.0', '<')) { |
|
996 | + $coupon_id = $order->add_coupon($code, $discount, $discount_tax); |
|
997 | 997 | } else { |
998 | 998 | $item = new WC_Order_Item_Coupon(); |
999 | - $item->set_props( array( |
|
999 | + $item->set_props(array( |
|
1000 | 1000 | 'code' => $code, |
1001 | 1001 | 'discount' => $discount, |
1002 | 1002 | 'discount_tax' => $discount_tax, |
1003 | 1003 | 'order_id' => $order->get_id(), |
1004 | - ) ); |
|
1004 | + )); |
|
1005 | 1005 | $coupon_id = $item->save(); |
1006 | - $order->add_item( $item ); |
|
1006 | + $order->add_item($item); |
|
1007 | 1007 | } |
1008 | 1008 | |
1009 | - if ( ! $coupon_id ) { |
|
1010 | - throw new Exception( sprintf( __( 'Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe' ), 529 ) ); |
|
1009 | + if ( ! $coupon_id) { |
|
1010 | + throw new Exception(sprintf(__('Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe'), 529)); |
|
1011 | 1011 | } |
1012 | 1012 | } |
1013 | 1013 | |
1014 | 1014 | // Billing address |
1015 | 1015 | $billing_address = array(); |
1016 | - if ( ! empty( $data['token']['card'] ) ) { |
|
1016 | + if ( ! empty($data['token']['card'])) { |
|
1017 | 1017 | // Name from Stripe is a full name string. |
1018 | - $name = explode( ' ', $data['token']['card']['name'] ); |
|
1019 | - $lastname = array_pop( $name ); |
|
1020 | - $firstname = implode( ' ', $name ); |
|
1018 | + $name = explode(' ', $data['token']['card']['name']); |
|
1019 | + $lastname = array_pop($name); |
|
1020 | + $firstname = implode(' ', $name); |
|
1021 | 1021 | $billing_address['first_name'] = $firstname; |
1022 | 1022 | $billing_address['last_name'] = $lastname; |
1023 | 1023 | $billing_address['email'] = $data['shippingContact']['emailAddress']; |
@@ -1032,7 +1032,7 @@ discard block |
||
1032 | 1032 | |
1033 | 1033 | // Shipping address. |
1034 | 1034 | $shipping_address = array(); |
1035 | - if ( WC()->cart->needs_shipping() && $this->is_shipping_enabled && ! empty( $data['shippingContact'] ) ) { |
|
1035 | + if (WC()->cart->needs_shipping() && $this->is_shipping_enabled && ! empty($data['shippingContact'])) { |
|
1036 | 1036 | $shipping_address['first_name'] = $data['shippingContact']['givenName']; |
1037 | 1037 | $shipping_address['last_name'] = $data['shippingContact']['familyName']; |
1038 | 1038 | $shipping_address['email'] = $data['shippingContact']['emailAddress']; |
@@ -1043,7 +1043,7 @@ discard block |
||
1043 | 1043 | $shipping_address['city'] = $data['shippingContact']['locality']; |
1044 | 1044 | $shipping_address['state'] = $data['shippingContact']['administrativeArea']; |
1045 | 1045 | $shipping_address['postcode'] = $data['shippingContact']['postalCode']; |
1046 | - } elseif ( ! empty( $data['shippingContact'] ) ) { |
|
1046 | + } elseif ( ! empty($data['shippingContact'])) { |
|
1047 | 1047 | $shipping_address['first_name'] = $firstname; |
1048 | 1048 | $shipping_address['last_name'] = $lastname; |
1049 | 1049 | $shipping_address['email'] = $data['shippingContact']['emailAddress']; |
@@ -1056,33 +1056,33 @@ discard block |
||
1056 | 1056 | $shipping_address['postcode'] = $data['token']['card']['address_zip']; |
1057 | 1057 | } |
1058 | 1058 | |
1059 | - $order->set_address( $billing_address, 'billing' ); |
|
1060 | - $order->set_address( $shipping_address, 'shipping' ); |
|
1059 | + $order->set_address($billing_address, 'billing'); |
|
1060 | + $order->set_address($shipping_address, 'shipping'); |
|
1061 | 1061 | |
1062 | - WC()->shipping->calculate_shipping( WC()->cart->get_shipping_packages() ); |
|
1062 | + WC()->shipping->calculate_shipping(WC()->cart->get_shipping_packages()); |
|
1063 | 1063 | |
1064 | 1064 | // Get the rate object selected by user. |
1065 | - foreach ( WC()->shipping->get_packages() as $package_key => $package ) { |
|
1066 | - foreach ( $package['rates'] as $key => $rate ) { |
|
1065 | + foreach (WC()->shipping->get_packages() as $package_key => $package) { |
|
1066 | + foreach ($package['rates'] as $key => $rate) { |
|
1067 | 1067 | // Loop through user chosen shipping methods. |
1068 | - foreach ( WC()->session->get( 'chosen_shipping_methods' ) as $method ) { |
|
1069 | - if ( $method === $key ) { |
|
1070 | - if ( version_compare( WC_VERSION, '3.0', '<' ) ) { |
|
1071 | - $order->add_shipping( $rate ); |
|
1068 | + foreach (WC()->session->get('chosen_shipping_methods') as $method) { |
|
1069 | + if ($method === $key) { |
|
1070 | + if (version_compare(WC_VERSION, '3.0', '<')) { |
|
1071 | + $order->add_shipping($rate); |
|
1072 | 1072 | } else { |
1073 | 1073 | $item = new WC_Order_Item_Shipping(); |
1074 | - $item->set_props( array( |
|
1074 | + $item->set_props(array( |
|
1075 | 1075 | 'method_title' => $rate->label, |
1076 | 1076 | 'method_id' => $rate->id, |
1077 | - 'total' => wc_format_decimal( $rate->cost ), |
|
1077 | + 'total' => wc_format_decimal($rate->cost), |
|
1078 | 1078 | 'taxes' => $rate->taxes, |
1079 | 1079 | 'order_id' => $order->get_id(), |
1080 | - ) ); |
|
1081 | - foreach ( $rate->get_meta_data() as $key => $value ) { |
|
1082 | - $item->add_meta_data( $key, $value, true ); |
|
1080 | + )); |
|
1081 | + foreach ($rate->get_meta_data() as $key => $value) { |
|
1082 | + $item->add_meta_data($key, $value, true); |
|
1083 | 1083 | } |
1084 | 1084 | $item->save(); |
1085 | - $order->add_item( $item ); |
|
1085 | + $order->add_item($item); |
|
1086 | 1086 | } |
1087 | 1087 | } |
1088 | 1088 | } |
@@ -1090,37 +1090,37 @@ discard block |
||
1090 | 1090 | } |
1091 | 1091 | |
1092 | 1092 | $available_gateways = WC()->payment_gateways->get_available_payment_gateways(); |
1093 | - $order->set_payment_method( $available_gateways['stripe'] ); |
|
1093 | + $order->set_payment_method($available_gateways['stripe']); |
|
1094 | 1094 | WC()->cart->calculate_totals(); |
1095 | 1095 | |
1096 | - if ( version_compare( WC_VERSION, '3.0', '<' ) ) { |
|
1097 | - $order->set_total( WC()->cart->shipping_total, 'shipping' ); |
|
1098 | - $order->set_total( WC()->cart->get_cart_discount_total(), 'cart_discount' ); |
|
1099 | - $order->set_total( WC()->cart->get_cart_discount_tax_total(), 'cart_discount_tax' ); |
|
1100 | - $order->set_total( WC()->cart->tax_total, 'tax' ); |
|
1101 | - $order->set_total( WC()->cart->shipping_tax_total, 'shipping_tax' ); |
|
1102 | - $order->set_total( WC()->cart->total ); |
|
1096 | + if (version_compare(WC_VERSION, '3.0', '<')) { |
|
1097 | + $order->set_total(WC()->cart->shipping_total, 'shipping'); |
|
1098 | + $order->set_total(WC()->cart->get_cart_discount_total(), 'cart_discount'); |
|
1099 | + $order->set_total(WC()->cart->get_cart_discount_tax_total(), 'cart_discount_tax'); |
|
1100 | + $order->set_total(WC()->cart->tax_total, 'tax'); |
|
1101 | + $order->set_total(WC()->cart->shipping_tax_total, 'shipping_tax'); |
|
1102 | + $order->set_total(WC()->cart->total); |
|
1103 | 1103 | } else { |
1104 | - $order->set_shipping_total( WC()->cart->shipping_total ); |
|
1105 | - $order->set_discount_total( WC()->cart->get_cart_discount_total() ); |
|
1106 | - $order->set_discount_tax( WC()->cart->get_cart_discount_tax_total() ); |
|
1107 | - $order->set_cart_tax( WC()->cart->tax_total ); |
|
1108 | - $order->set_shipping_tax( WC()->cart->shipping_tax_total ); |
|
1109 | - |
|
1110 | - $discounts = wc_format_decimal( WC()->cart->get_cart_discount_total(), $this->dp ); |
|
1111 | - $tax = wc_format_decimal( WC()->cart->tax_total + WC()->cart->shipping_tax_total, $this->dp ); |
|
1112 | - $shipping = wc_format_decimal( WC()->cart->shipping_total, $this->dp ); |
|
1113 | - $item_total = wc_format_decimal( WC()->cart->cart_contents_total, $this->dp ) + $discounts; |
|
1114 | - $order_total = wc_format_decimal( $item_total + $tax + $shipping, $decimals ); |
|
1115 | - |
|
1116 | - $order->set_total( $order_total ); |
|
1104 | + $order->set_shipping_total(WC()->cart->shipping_total); |
|
1105 | + $order->set_discount_total(WC()->cart->get_cart_discount_total()); |
|
1106 | + $order->set_discount_tax(WC()->cart->get_cart_discount_tax_total()); |
|
1107 | + $order->set_cart_tax(WC()->cart->tax_total); |
|
1108 | + $order->set_shipping_tax(WC()->cart->shipping_tax_total); |
|
1109 | + |
|
1110 | + $discounts = wc_format_decimal(WC()->cart->get_cart_discount_total(), $this->dp); |
|
1111 | + $tax = wc_format_decimal(WC()->cart->tax_total + WC()->cart->shipping_tax_total, $this->dp); |
|
1112 | + $shipping = wc_format_decimal(WC()->cart->shipping_total, $this->dp); |
|
1113 | + $item_total = wc_format_decimal(WC()->cart->cart_contents_total, $this->dp) + $discounts; |
|
1114 | + $order_total = wc_format_decimal($item_total + $tax + $shipping, $decimals); |
|
1115 | + |
|
1116 | + $order->set_total($order_total); |
|
1117 | 1117 | $order->save(); |
1118 | 1118 | } |
1119 | 1119 | |
1120 | 1120 | // If we got here, the order was created without problems! |
1121 | - wc_transaction_query( 'commit' ); |
|
1121 | + wc_transaction_query('commit'); |
|
1122 | 1122 | |
1123 | - do_action( 'woocommerce_checkout_update_order_meta', $order_id, array() ); |
|
1123 | + do_action('woocommerce_checkout_update_order_meta', $order_id, array()); |
|
1124 | 1124 | |
1125 | 1125 | return $order; |
1126 | 1126 | } |
@@ -1133,9 +1133,9 @@ discard block |
||
1133 | 1133 | * |
1134 | 1134 | * @param string $message |
1135 | 1135 | */ |
1136 | - public function log( $message ) { |
|
1137 | - if ( $this->logging ) { |
|
1138 | - WC_Stripe::log( 'Apple Pay: ' . $message ); |
|
1136 | + public function log($message) { |
|
1137 | + if ($this->logging) { |
|
1138 | + WC_Stripe::log('Apple Pay: ' . $message); |
|
1139 | 1139 | } |
1140 | 1140 | } |
1141 | 1141 | } |