@@ -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 ); ?>;display:none;" 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); ?>;display:none;" 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,56 +446,56 @@ 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 | // Allow other product types to add to cart. |
491 | - do_action( 'woocommerce_add_to_apple_cart', $product, $qty ); |
|
491 | + do_action('woocommerce_add_to_apple_cart', $product, $qty); |
|
492 | 492 | } |
493 | 493 | |
494 | 494 | WC()->cart->calculate_totals(); |
495 | 495 | |
496 | 496 | $build_items = $this->build_line_items(); |
497 | 497 | |
498 | - wp_send_json( array( 'line_items' => $build_items['line_items'], 'total' => $build_items['total'] ) ); |
|
498 | + wp_send_json(array('line_items' => $build_items['line_items'], 'total' => $build_items['total'])); |
|
499 | 499 | } |
500 | 500 | |
501 | 501 | /** |
@@ -505,13 +505,13 @@ discard block |
||
505 | 505 | * @version 3.1.0 |
506 | 506 | */ |
507 | 507 | public function generate_apple_pay_cart() { |
508 | - if ( ! wp_verify_nonce( $_POST['nonce'], '_wc_stripe_apple_pay_cart_nonce' ) ) { |
|
509 | - wp_die( __( 'Cheatin’ huh?', 'woocommerce-gateway-stripe' ) ); |
|
508 | + if ( ! wp_verify_nonce($_POST['nonce'], '_wc_stripe_apple_pay_cart_nonce')) { |
|
509 | + wp_die(__('Cheatin’ huh?', 'woocommerce-gateway-stripe')); |
|
510 | 510 | } |
511 | 511 | |
512 | 512 | $build_items = $this->build_line_items(); |
513 | 513 | |
514 | - wp_send_json( array( 'line_items' => $build_items['line_items'], 'total' => $build_items['total'] ) ); |
|
514 | + wp_send_json(array('line_items' => $build_items['line_items'], 'total' => $build_items['total'])); |
|
515 | 515 | } |
516 | 516 | |
517 | 517 | /** |
@@ -532,32 +532,32 @@ discard block |
||
532 | 532 | * @version 3.1.0 |
533 | 533 | * @param array $address |
534 | 534 | */ |
535 | - public function calculate_shipping( $address = array() ) { |
|
536 | - $country = strtoupper( $address['countryCode'] ); |
|
537 | - $state = strtoupper( $address['administrativeArea'] ); |
|
535 | + public function calculate_shipping($address = array()) { |
|
536 | + $country = strtoupper($address['countryCode']); |
|
537 | + $state = strtoupper($address['administrativeArea']); |
|
538 | 538 | $postcode = $address['postalCode']; |
539 | 539 | $city = $address['locality']; |
540 | 540 | |
541 | 541 | WC()->shipping->reset_shipping(); |
542 | 542 | |
543 | - if ( $postcode && ! WC_Validation::is_postcode( $postcode, $country ) ) { |
|
544 | - throw new Exception( __( 'Please enter a valid postcode/ZIP.', 'woocommerce-gateway-stripe' ) ); |
|
545 | - } elseif ( $postcode ) { |
|
546 | - $postcode = wc_format_postcode( $postcode, $country ); |
|
543 | + if ($postcode && ! WC_Validation::is_postcode($postcode, $country)) { |
|
544 | + throw new Exception(__('Please enter a valid postcode/ZIP.', 'woocommerce-gateway-stripe')); |
|
545 | + } elseif ($postcode) { |
|
546 | + $postcode = wc_format_postcode($postcode, $country); |
|
547 | 547 | } |
548 | 548 | |
549 | - if ( $country ) { |
|
550 | - WC()->customer->set_location( $country, $state, $postcode, $city ); |
|
551 | - WC()->customer->set_shipping_location( $country, $state, $postcode, $city ); |
|
549 | + if ($country) { |
|
550 | + WC()->customer->set_location($country, $state, $postcode, $city); |
|
551 | + WC()->customer->set_shipping_location($country, $state, $postcode, $city); |
|
552 | 552 | } else { |
553 | 553 | WC()->customer->set_to_base(); |
554 | 554 | WC()->customer->set_shipping_to_base(); |
555 | 555 | } |
556 | 556 | |
557 | - if ( version_compare( WC_VERSION, '3.0', '<' ) ) { |
|
558 | - WC()->customer->calculated_shipping( true ); |
|
557 | + if (version_compare(WC_VERSION, '3.0', '<')) { |
|
558 | + WC()->customer->calculated_shipping(true); |
|
559 | 559 | } else { |
560 | - WC()->customer->set_calculated_shipping( true ); |
|
560 | + WC()->customer->set_calculated_shipping(true); |
|
561 | 561 | WC()->customer->save(); |
562 | 562 | } |
563 | 563 | |
@@ -581,17 +581,17 @@ discard block |
||
581 | 581 | $packages[0]['destination']['postcode'] = $postcode; |
582 | 582 | $packages[0]['destination']['city'] = $city; |
583 | 583 | |
584 | - foreach ( WC()->cart->get_cart() as $item ) { |
|
585 | - if ( $item['data']->needs_shipping() ) { |
|
586 | - if ( isset( $item['line_total'] ) ) { |
|
584 | + foreach (WC()->cart->get_cart() as $item) { |
|
585 | + if ($item['data']->needs_shipping()) { |
|
586 | + if (isset($item['line_total'])) { |
|
587 | 587 | $packages[0]['contents_cost'] += $item['line_total']; |
588 | 588 | } |
589 | 589 | } |
590 | 590 | } |
591 | 591 | |
592 | - $packages = apply_filters( 'woocommerce_cart_shipping_packages', $packages ); |
|
592 | + $packages = apply_filters('woocommerce_cart_shipping_packages', $packages); |
|
593 | 593 | |
594 | - WC()->shipping->calculate_shipping( $packages ); |
|
594 | + WC()->shipping->calculate_shipping($packages); |
|
595 | 595 | } |
596 | 596 | |
597 | 597 | /** |
@@ -601,18 +601,18 @@ discard block |
||
601 | 601 | * @version 3.1.0 |
602 | 602 | */ |
603 | 603 | public function get_shipping_methods() { |
604 | - if ( ! wp_verify_nonce( $_POST['nonce'], '_wc_stripe_apple_pay_get_shipping_methods_nonce' ) ) { |
|
605 | - wp_die( __( 'Cheatin’ huh?', 'woocommerce-gateway-stripe' ) ); |
|
604 | + if ( ! wp_verify_nonce($_POST['nonce'], '_wc_stripe_apple_pay_get_shipping_methods_nonce')) { |
|
605 | + wp_die(__('Cheatin’ huh?', 'woocommerce-gateway-stripe')); |
|
606 | 606 | } |
607 | 607 | |
608 | - if ( ! defined( 'WOOCOMMERCE_CART' ) ) { |
|
609 | - define( 'WOOCOMMERCE_CART', true ); |
|
608 | + if ( ! defined('WOOCOMMERCE_CART')) { |
|
609 | + define('WOOCOMMERCE_CART', true); |
|
610 | 610 | } |
611 | 611 | |
612 | 612 | try { |
613 | - $address = array_map( 'wc_clean', $_POST['address'] ); |
|
613 | + $address = array_map('wc_clean', $_POST['address']); |
|
614 | 614 | |
615 | - $this->calculate_shipping( $address ); |
|
615 | + $this->calculate_shipping($address); |
|
616 | 616 | |
617 | 617 | // Set the shipping options. |
618 | 618 | $currency = get_woocommerce_currency(); |
@@ -620,13 +620,13 @@ discard block |
||
620 | 620 | |
621 | 621 | $packages = WC()->shipping->get_packages(); |
622 | 622 | |
623 | - if ( ! empty( $packages ) && WC()->customer->has_calculated_shipping() ) { |
|
624 | - foreach ( $packages as $package_key => $package ) { |
|
625 | - if ( empty( $package['rates'] ) ) { |
|
626 | - throw new Exception( __( 'Unable to find shipping method for address.', 'woocommerce-gateway-stripe' ) ); |
|
623 | + if ( ! empty($packages) && WC()->customer->has_calculated_shipping()) { |
|
624 | + foreach ($packages as $package_key => $package) { |
|
625 | + if (empty($package['rates'])) { |
|
626 | + throw new Exception(__('Unable to find shipping method for address.', 'woocommerce-gateway-stripe')); |
|
627 | 627 | } |
628 | 628 | |
629 | - foreach ( $package['rates'] as $key => $rate ) { |
|
629 | + foreach ($package['rates'] as $key => $rate) { |
|
630 | 630 | $data[] = array( |
631 | 631 | 'id' => $rate->id, |
632 | 632 | 'label' => $rate->label, |
@@ -640,19 +640,19 @@ discard block |
||
640 | 640 | } |
641 | 641 | |
642 | 642 | // Auto select the first shipping method. |
643 | - WC()->session->set( 'chosen_shipping_methods', array( $data[0]['id'] ) ); |
|
643 | + WC()->session->set('chosen_shipping_methods', array($data[0]['id'])); |
|
644 | 644 | |
645 | 645 | WC()->cart->calculate_totals(); |
646 | 646 | |
647 | 647 | $build_items = $this->build_line_items(); |
648 | 648 | |
649 | - wp_send_json( array( 'success' => 'true', 'shipping_methods' => $this->build_shipping_methods( $data ), 'line_items' => $build_items['line_items'], 'total' => $build_items['total'] ) ); |
|
649 | + wp_send_json(array('success' => 'true', 'shipping_methods' => $this->build_shipping_methods($data), 'line_items' => $build_items['line_items'], 'total' => $build_items['total'])); |
|
650 | 650 | } else { |
651 | - throw new Exception( __( 'Unable to find shipping method for address.', 'woocommerce-gateway-stripe' ) ); |
|
651 | + throw new Exception(__('Unable to find shipping method for address.', 'woocommerce-gateway-stripe')); |
|
652 | 652 | } |
653 | - } catch ( Exception $e ) { |
|
653 | + } catch (Exception $e) { |
|
654 | 654 | $build_items = $this->build_line_items(); |
655 | - wp_send_json( array( 'success' => 'false', 'shipping_methods' => array(), 'line_items' => $build_items['line_items'], 'total' => $build_items['total'] ) ); |
|
655 | + wp_send_json(array('success' => 'false', 'shipping_methods' => array(), 'line_items' => $build_items['line_items'], 'total' => $build_items['total'])); |
|
656 | 656 | } |
657 | 657 | } |
658 | 658 | |
@@ -663,22 +663,22 @@ discard block |
||
663 | 663 | * @version 3.1.0 |
664 | 664 | */ |
665 | 665 | public function update_shipping_method() { |
666 | - if ( ! defined( 'WOOCOMMERCE_CART' ) ) { |
|
667 | - define( 'WOOCOMMERCE_CART', true ); |
|
666 | + if ( ! defined('WOOCOMMERCE_CART')) { |
|
667 | + define('WOOCOMMERCE_CART', true); |
|
668 | 668 | } |
669 | 669 | |
670 | - if ( ! wp_verify_nonce( $_POST['nonce'], '_wc_stripe_apple_pay_update_shipping_method_nonce' ) ) { |
|
671 | - wp_die( __( 'Cheatin’ huh?', 'woocommerce-gateway-stripe' ) ); |
|
670 | + if ( ! wp_verify_nonce($_POST['nonce'], '_wc_stripe_apple_pay_update_shipping_method_nonce')) { |
|
671 | + wp_die(__('Cheatin’ huh?', 'woocommerce-gateway-stripe')); |
|
672 | 672 | } |
673 | 673 | |
674 | - $selected_shipping_method = array_map( 'wc_clean', $_POST['selected_shipping_method'] ); |
|
674 | + $selected_shipping_method = array_map('wc_clean', $_POST['selected_shipping_method']); |
|
675 | 675 | |
676 | - WC()->session->set( 'chosen_shipping_methods', array( $selected_shipping_method['identifier'] ) ); |
|
676 | + WC()->session->set('chosen_shipping_methods', array($selected_shipping_method['identifier'])); |
|
677 | 677 | |
678 | 678 | WC()->cart->calculate_totals(); |
679 | 679 | |
680 | 680 | $build_items = $this->build_line_items(); |
681 | - wp_send_json( array( 'success' => 'true', 'line_items' => $build_items['line_items'], 'total' => $build_items['total'] ) ); |
|
681 | + wp_send_json(array('success' => 'true', 'line_items' => $build_items['line_items'], 'total' => $build_items['total'])); |
|
682 | 682 | } |
683 | 683 | |
684 | 684 | /** |
@@ -689,37 +689,37 @@ discard block |
||
689 | 689 | * @version 3.1.0 |
690 | 690 | */ |
691 | 691 | public function process_apple_pay() { |
692 | - if ( ! wp_verify_nonce( $_POST['nonce'], '_wc_stripe_apple_pay_nonce' ) ) { |
|
693 | - wp_die( __( 'Cheatin’ huh?', 'woocommerce-gateway-stripe' ) ); |
|
692 | + if ( ! wp_verify_nonce($_POST['nonce'], '_wc_stripe_apple_pay_nonce')) { |
|
693 | + wp_die(__('Cheatin’ huh?', 'woocommerce-gateway-stripe')); |
|
694 | 694 | } |
695 | 695 | |
696 | 696 | try { |
697 | - $result = array_map( 'wc_clean', $_POST['result'] ); |
|
697 | + $result = array_map('wc_clean', $_POST['result']); |
|
698 | 698 | |
699 | - $order = $this->create_order( $result ); |
|
699 | + $order = $this->create_order($result); |
|
700 | 700 | |
701 | - $order_id = version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->id : $order->get_id(); |
|
701 | + $order_id = version_compare(WC_VERSION, '3.0.0', '<') ? $order->id : $order->get_id(); |
|
702 | 702 | |
703 | 703 | // Handle payment. |
704 | - if ( $order->get_total() > 0 ) { |
|
704 | + if ($order->get_total() > 0) { |
|
705 | 705 | |
706 | - if ( $order->get_total() * 100 < WC_Stripe::get_minimum_amount() ) { |
|
707 | - 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 ) ) ); |
|
706 | + if ($order->get_total() * 100 < WC_Stripe::get_minimum_amount()) { |
|
707 | + 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))); |
|
708 | 708 | } |
709 | 709 | |
710 | - $this->log( "Info: Begin processing payment for order {$order_id} for the amount of {$order->get_total()}" ); |
|
710 | + $this->log("Info: Begin processing payment for order {$order_id} for the amount of {$order->get_total()}"); |
|
711 | 711 | |
712 | 712 | // Make the request. |
713 | - $response = WC_Stripe_API::request( $this->generate_payment_request( $order, $result['token']['id'] ) ); |
|
713 | + $response = WC_Stripe_API::request($this->generate_payment_request($order, $result['token']['id'])); |
|
714 | 714 | |
715 | - if ( is_wp_error( $response ) ) { |
|
715 | + if (is_wp_error($response)) { |
|
716 | 716 | $localized_messages = $this->get_localized_messages(); |
717 | 717 | |
718 | - throw new Exception( ( isset( $localized_messages[ $response->get_error_code() ] ) ? $localized_messages[ $response->get_error_code() ] : $response->get_error_message() ) ); |
|
718 | + throw new Exception((isset($localized_messages[$response->get_error_code()]) ? $localized_messages[$response->get_error_code()] : $response->get_error_message())); |
|
719 | 719 | } |
720 | 720 | |
721 | 721 | // Process valid response. |
722 | - $this->process_response( $response, $order ); |
|
722 | + $this->process_response($response, $order); |
|
723 | 723 | } else { |
724 | 724 | $order->payment_complete(); |
725 | 725 | } |
@@ -727,24 +727,24 @@ discard block |
||
727 | 727 | // Remove cart. |
728 | 728 | WC()->cart->empty_cart(); |
729 | 729 | |
730 | - update_post_meta( $order_id, '_customer_user', get_current_user_id() ); |
|
731 | - update_post_meta( $order_id, '_payment_method_title', 'Apple Pay (Stripe)' ); |
|
730 | + update_post_meta($order_id, '_customer_user', get_current_user_id()); |
|
731 | + update_post_meta($order_id, '_payment_method_title', 'Apple Pay (Stripe)'); |
|
732 | 732 | |
733 | 733 | // Return thank you page redirect. |
734 | - wp_send_json( array( |
|
734 | + wp_send_json(array( |
|
735 | 735 | 'success' => 'true', |
736 | - 'redirect' => $this->get_return_url( $order ), |
|
737 | - ) ); |
|
736 | + 'redirect' => $this->get_return_url($order), |
|
737 | + )); |
|
738 | 738 | |
739 | - } catch ( Exception $e ) { |
|
740 | - WC()->session->set( 'refresh_totals', true ); |
|
741 | - $this->log( sprintf( __( 'Error: %s', 'woocommerce-gateway-stripe' ), $e->getMessage() ) ); |
|
739 | + } catch (Exception $e) { |
|
740 | + WC()->session->set('refresh_totals', true); |
|
741 | + $this->log(sprintf(__('Error: %s', 'woocommerce-gateway-stripe'), $e->getMessage())); |
|
742 | 742 | |
743 | - if ( is_object( $order ) && isset( $order_id ) && $order->has_status( array( 'pending', 'failed' ) ) ) { |
|
744 | - $this->send_failed_order_email( $order_id ); |
|
743 | + if (is_object($order) && isset($order_id) && $order->has_status(array('pending', 'failed'))) { |
|
744 | + $this->send_failed_order_email($order_id); |
|
745 | 745 | } |
746 | 746 | |
747 | - wp_send_json( array( 'success' => 'false', 'msg' => $e->getMessage() ) ); |
|
747 | + wp_send_json(array('success' => 'false', 'msg' => $e->getMessage())); |
|
748 | 748 | } |
749 | 749 | } |
750 | 750 | |
@@ -754,16 +754,16 @@ discard block |
||
754 | 754 | * @param string $source token |
755 | 755 | * @return array() |
756 | 756 | */ |
757 | - protected function generate_payment_request( $order, $source ) { |
|
757 | + protected function generate_payment_request($order, $source) { |
|
758 | 758 | $post_data = array(); |
759 | - $post_data['currency'] = strtolower( version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->get_order_currency() : $order->get_currency() ); |
|
760 | - $post_data['amount'] = $this->get_stripe_amount( $order->get_total(), $post_data['currency'] ); |
|
761 | - $post_data['description'] = sprintf( __( '%1$s - Order %2$s', 'woocommerce-gateway-stripe' ), $this->statement_descriptor, $order->get_order_number() ); |
|
759 | + $post_data['currency'] = strtolower(version_compare(WC_VERSION, '3.0.0', '<') ? $order->get_order_currency() : $order->get_currency()); |
|
760 | + $post_data['amount'] = $this->get_stripe_amount($order->get_total(), $post_data['currency']); |
|
761 | + $post_data['description'] = sprintf(__('%1$s - Order %2$s', 'woocommerce-gateway-stripe'), $this->statement_descriptor, $order->get_order_number()); |
|
762 | 762 | $post_data['capture'] = $this->capture ? 'true' : 'false'; |
763 | 763 | |
764 | - $billing_email = version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->billing_email : $order->get_billing_email(); |
|
764 | + $billing_email = version_compare(WC_VERSION, '3.0.0', '<') ? $order->billing_email : $order->get_billing_email(); |
|
765 | 765 | |
766 | - if ( ! empty( $billing_email ) && apply_filters( 'wc_stripe_send_stripe_receipt', false ) ) { |
|
766 | + if ( ! empty($billing_email) && apply_filters('wc_stripe_send_stripe_receipt', false)) { |
|
767 | 767 | $post_data['receipt_email'] = $billing_email; |
768 | 768 | } |
769 | 769 | |
@@ -778,7 +778,7 @@ discard block |
||
778 | 778 | * @param WC_Order $order |
779 | 779 | * @param object $source |
780 | 780 | */ |
781 | - return apply_filters( 'wc_stripe_generate_payment_request', $post_data, $order ); |
|
781 | + return apply_filters('wc_stripe_generate_payment_request', $post_data, $order); |
|
782 | 782 | } |
783 | 783 | |
784 | 784 | /** |
@@ -787,14 +787,14 @@ discard block |
||
787 | 787 | * @since 3.1.0 |
788 | 788 | * @version 3.1.0 |
789 | 789 | */ |
790 | - public function build_shipping_methods( $shipping_methods ) { |
|
791 | - if ( empty( $shipping_methods ) ) { |
|
790 | + public function build_shipping_methods($shipping_methods) { |
|
791 | + if (empty($shipping_methods)) { |
|
792 | 792 | return array(); |
793 | 793 | } |
794 | 794 | |
795 | 795 | $shipping = array(); |
796 | 796 | |
797 | - foreach ( $shipping_methods as $method ) { |
|
797 | + foreach ($shipping_methods as $method) { |
|
798 | 798 | $shipping[] = array( |
799 | 799 | 'label' => $method['label'], |
800 | 800 | 'detail' => '', |
@@ -813,70 +813,70 @@ discard block |
||
813 | 813 | * @version 3.2.0 |
814 | 814 | */ |
815 | 815 | public function build_line_items() { |
816 | - if ( ! defined( 'WOOCOMMERCE_CART' ) ) { |
|
817 | - define( 'WOOCOMMERCE_CART', true ); |
|
816 | + if ( ! defined('WOOCOMMERCE_CART')) { |
|
817 | + define('WOOCOMMERCE_CART', true); |
|
818 | 818 | } |
819 | 819 | |
820 | 820 | $items = array(); |
821 | 821 | $subtotal = 0; |
822 | 822 | |
823 | - foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) { |
|
824 | - $amount = wc_format_decimal( $cart_item['line_subtotal'], $this->dp ); |
|
825 | - $subtotal += $cart_item['line_subtotal']; |
|
823 | + foreach (WC()->cart->get_cart() as $cart_item_key => $cart_item) { |
|
824 | + $amount = wc_format_decimal($cart_item['line_subtotal'], $this->dp); |
|
825 | + $subtotal += $cart_item['line_subtotal']; |
|
826 | 826 | $quantity_label = 1 < $cart_item['quantity'] ? ' (x' . $cart_item['quantity'] . ')' : ''; |
827 | 827 | |
828 | - $product_name = version_compare( WC_VERSION, '3.0', '<' ) ? $cart_item['data']->post->post_title : $cart_item['data']->get_name(); |
|
828 | + $product_name = version_compare(WC_VERSION, '3.0', '<') ? $cart_item['data']->post->post_title : $cart_item['data']->get_name(); |
|
829 | 829 | |
830 | 830 | $item = array( |
831 | 831 | 'type' => 'final', |
832 | 832 | 'label' => $product_name . $quantity_label, |
833 | - 'amount' => wc_format_decimal( $amount, $this->dp ), |
|
833 | + 'amount' => wc_format_decimal($amount, $this->dp), |
|
834 | 834 | ); |
835 | 835 | |
836 | 836 | $items[] = $item; |
837 | 837 | } |
838 | 838 | |
839 | 839 | // Default show only subtotal instead of itemization. |
840 | - if ( apply_filters( 'wc_stripe_apple_pay_disable_itemization', true ) ) { |
|
840 | + if (apply_filters('wc_stripe_apple_pay_disable_itemization', true)) { |
|
841 | 841 | $items = array(); |
842 | 842 | $items[] = array( |
843 | 843 | 'type' => 'final', |
844 | - 'label' => esc_html( __( 'Sub-Total', 'woocommerce-gateway-stripe' ) ), |
|
845 | - 'amount' => wc_format_decimal( $subtotal, $this->dp ), |
|
844 | + 'label' => esc_html(__('Sub-Total', 'woocommerce-gateway-stripe')), |
|
845 | + 'amount' => wc_format_decimal($subtotal, $this->dp), |
|
846 | 846 | ); |
847 | 847 | } |
848 | 848 | |
849 | - $discounts = wc_format_decimal( WC()->cart->get_cart_discount_total(), $this->dp ); |
|
850 | - $tax = wc_format_decimal( WC()->cart->tax_total + WC()->cart->shipping_tax_total, $this->dp ); |
|
851 | - $shipping = wc_format_decimal( WC()->cart->shipping_total, $this->dp ); |
|
852 | - $item_total = wc_format_decimal( WC()->cart->cart_contents_total, $this->dp ) + $discounts; |
|
853 | - $order_total = wc_format_decimal( $item_total + $tax + $shipping - $discounts, $this->dp ); |
|
849 | + $discounts = wc_format_decimal(WC()->cart->get_cart_discount_total(), $this->dp); |
|
850 | + $tax = wc_format_decimal(WC()->cart->tax_total + WC()->cart->shipping_tax_total, $this->dp); |
|
851 | + $shipping = wc_format_decimal(WC()->cart->shipping_total, $this->dp); |
|
852 | + $item_total = wc_format_decimal(WC()->cart->cart_contents_total, $this->dp) + $discounts; |
|
853 | + $order_total = wc_format_decimal($item_total + $tax + $shipping - $discounts, $this->dp); |
|
854 | 854 | |
855 | - if ( wc_tax_enabled() ) { |
|
855 | + if (wc_tax_enabled()) { |
|
856 | 856 | $items[] = array( |
857 | 857 | 'type' => 'final', |
858 | - 'label' => esc_html( __( 'Tax', 'woocommerce-gateway-stripe' ) ), |
|
858 | + 'label' => esc_html(__('Tax', 'woocommerce-gateway-stripe')), |
|
859 | 859 | 'amount' => $tax, |
860 | 860 | ); |
861 | 861 | } |
862 | 862 | |
863 | - if ( WC()->cart->needs_shipping() && $this->is_shipping_enabled ) { |
|
863 | + if (WC()->cart->needs_shipping() && $this->is_shipping_enabled) { |
|
864 | 864 | $items[] = array( |
865 | 865 | 'type' => 'final', |
866 | - 'label' => esc_html( __( 'Shipping', 'woocommerce-gateway-stripe' ) ), |
|
866 | + 'label' => esc_html(__('Shipping', 'woocommerce-gateway-stripe')), |
|
867 | 867 | 'amount' => $shipping, |
868 | 868 | ); |
869 | 869 | } |
870 | 870 | |
871 | - if ( WC()->cart->has_discount() ) { |
|
871 | + if (WC()->cart->has_discount()) { |
|
872 | 872 | $items[] = array( |
873 | 873 | 'type' => 'final', |
874 | - 'label' => esc_html( __( 'Discount', 'woocommerce-gateway-stripe' ) ), |
|
874 | + 'label' => esc_html(__('Discount', 'woocommerce-gateway-stripe')), |
|
875 | 875 | 'amount' => '-' . $discounts, |
876 | 876 | ); |
877 | 877 | } |
878 | 878 | |
879 | - return array( 'line_items' => $items, 'total' => $order_total ); |
|
879 | + return array('line_items' => $items, 'total' => $order_total); |
|
880 | 880 | } |
881 | 881 | |
882 | 882 | /** |
@@ -887,28 +887,28 @@ discard block |
||
887 | 887 | * @param array $data |
888 | 888 | * @return object $order |
889 | 889 | */ |
890 | - public function create_order( $data = array() ) { |
|
891 | - if ( empty( $data ) ) { |
|
892 | - throw new Exception( sprintf( __( 'Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe' ), 520 ) ); |
|
890 | + public function create_order($data = array()) { |
|
891 | + if (empty($data)) { |
|
892 | + throw new Exception(sprintf(__('Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe'), 520)); |
|
893 | 893 | } |
894 | 894 | |
895 | - if ( ! defined( 'WOOCOMMERCE_CART' ) ) { |
|
896 | - define( 'WOOCOMMERCE_CART', true ); |
|
895 | + if ( ! defined('WOOCOMMERCE_CART')) { |
|
896 | + define('WOOCOMMERCE_CART', true); |
|
897 | 897 | } |
898 | 898 | |
899 | 899 | $order = wc_create_order(); |
900 | - $order_id = version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->id : $order->get_id(); |
|
900 | + $order_id = version_compare(WC_VERSION, '3.0.0', '<') ? $order->id : $order->get_id(); |
|
901 | 901 | |
902 | - if ( is_wp_error( $order ) ) { |
|
903 | - throw new Exception( sprintf( __( 'Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe' ), 520 ) ); |
|
904 | - } elseif ( false === $order ) { |
|
905 | - throw new Exception( sprintf( __( 'Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe' ), 521 ) ); |
|
902 | + if (is_wp_error($order)) { |
|
903 | + throw new Exception(sprintf(__('Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe'), 520)); |
|
904 | + } elseif (false === $order) { |
|
905 | + throw new Exception(sprintf(__('Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe'), 521)); |
|
906 | 906 | } else { |
907 | - do_action( 'woocommerce_new_order', $order_id ); |
|
907 | + do_action('woocommerce_new_order', $order_id); |
|
908 | 908 | } |
909 | 909 | |
910 | 910 | // Store the line items to the new/resumed order |
911 | - foreach ( WC()->cart->get_cart() as $cart_item_key => $values ) { |
|
911 | + foreach (WC()->cart->get_cart() as $cart_item_key => $values) { |
|
912 | 912 | $item_id = $order->add_product( |
913 | 913 | $values['data'], |
914 | 914 | $values['quantity'], |
@@ -924,27 +924,27 @@ discard block |
||
924 | 924 | ) |
925 | 925 | ); |
926 | 926 | |
927 | - if ( ! $item_id ) { |
|
928 | - throw new Exception( sprintf( __( 'Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe' ), 525 ) ); |
|
927 | + if ( ! $item_id) { |
|
928 | + throw new Exception(sprintf(__('Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe'), 525)); |
|
929 | 929 | } |
930 | 930 | |
931 | 931 | // Allow plugins to add order item meta |
932 | - if ( version_compare( WC_VERSION, '3.0', '<' ) ) { |
|
933 | - do_action( 'woocommerce_add_order_item_meta', $item_id, $values, $cart_item_key ); |
|
932 | + if (version_compare(WC_VERSION, '3.0', '<')) { |
|
933 | + do_action('woocommerce_add_order_item_meta', $item_id, $values, $cart_item_key); |
|
934 | 934 | } else { |
935 | - $item = WC_Order_Factory::get_order_item( $item_id ); |
|
935 | + $item = WC_Order_Factory::get_order_item($item_id); |
|
936 | 936 | |
937 | - do_action( 'woocommerce_new_order_item', $item_id, $item, $order->get_id() ); |
|
937 | + do_action('woocommerce_new_order_item', $item_id, $item, $order->get_id()); |
|
938 | 938 | } |
939 | 939 | } |
940 | 940 | |
941 | 941 | // Store fees |
942 | - foreach ( WC()->cart->get_fees() as $fee_key => $fee ) { |
|
943 | - if ( version_compare( WC_VERSION, '3.0', '<' ) ) { |
|
944 | - $item_id = $order->add_fee( $fee ); |
|
942 | + foreach (WC()->cart->get_fees() as $fee_key => $fee) { |
|
943 | + if (version_compare(WC_VERSION, '3.0', '<')) { |
|
944 | + $item_id = $order->add_fee($fee); |
|
945 | 945 | } else { |
946 | 946 | $item = new WC_Order_Item_Fee(); |
947 | - $item->set_props( array( |
|
947 | + $item->set_props(array( |
|
948 | 948 | 'name' => $fee->name, |
949 | 949 | 'tax_class' => $fee->taxable ? $fee->tax_class : 0, |
950 | 950 | 'total' => $fee->amount, |
@@ -953,79 +953,79 @@ discard block |
||
953 | 953 | 'total' => $fee->tax_data, |
954 | 954 | ), |
955 | 955 | 'order_id' => $order->get_id(), |
956 | - ) ); |
|
956 | + )); |
|
957 | 957 | $item_id = $item->save(); |
958 | - $order->add_item( $item ); |
|
958 | + $order->add_item($item); |
|
959 | 959 | } |
960 | 960 | |
961 | - if ( ! $item_id ) { |
|
962 | - throw new Exception( sprintf( __( 'Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe' ), 526 ) ); |
|
961 | + if ( ! $item_id) { |
|
962 | + throw new Exception(sprintf(__('Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe'), 526)); |
|
963 | 963 | } |
964 | 964 | |
965 | 965 | // Allow plugins to add order item meta to fees |
966 | - if ( version_compare( WC_VERSION, '3.0', '<' ) ) { |
|
967 | - do_action( 'woocommerce_add_order_fee_meta', $order_id, $item_id, $fee, $fee_key ); |
|
966 | + if (version_compare(WC_VERSION, '3.0', '<')) { |
|
967 | + do_action('woocommerce_add_order_fee_meta', $order_id, $item_id, $fee, $fee_key); |
|
968 | 968 | } else { |
969 | - do_action( 'woocommerce_new_order_item', $item_id, $fee, $order->get_id() ); |
|
969 | + do_action('woocommerce_new_order_item', $item_id, $fee, $order->get_id()); |
|
970 | 970 | } |
971 | 971 | } |
972 | 972 | |
973 | 973 | // Store tax rows |
974 | - foreach ( array_keys( WC()->cart->taxes + WC()->cart->shipping_taxes ) as $tax_rate_id ) { |
|
975 | - $tax_amount = WC()->cart->get_tax_amount( $tax_rate_id ); |
|
976 | - $shipping_tax_amount = WC()->cart->get_shipping_tax_amount( $tax_rate_id ); |
|
974 | + foreach (array_keys(WC()->cart->taxes + WC()->cart->shipping_taxes) as $tax_rate_id) { |
|
975 | + $tax_amount = WC()->cart->get_tax_amount($tax_rate_id); |
|
976 | + $shipping_tax_amount = WC()->cart->get_shipping_tax_amount($tax_rate_id); |
|
977 | 977 | |
978 | - if ( version_compare( WC_VERSION, '3.0', '<' ) ) { |
|
979 | - $item_id = $order->add_tax( $tax_rate_id, $tax_amount, $shipping_tax_amount ); |
|
978 | + if (version_compare(WC_VERSION, '3.0', '<')) { |
|
979 | + $item_id = $order->add_tax($tax_rate_id, $tax_amount, $shipping_tax_amount); |
|
980 | 980 | } else { |
981 | 981 | $item = new WC_Order_Item_Tax(); |
982 | - $item->set_props( array( |
|
982 | + $item->set_props(array( |
|
983 | 983 | 'rate_id' => $tax_rate_id, |
984 | 984 | 'tax_total' => $tax_amount, |
985 | 985 | 'shipping_tax_total' => $shipping_tax_amount, |
986 | - ) ); |
|
987 | - $item->set_rate( $tax_rate_id ); |
|
988 | - $item->set_order_id( $order->get_id() ); |
|
986 | + )); |
|
987 | + $item->set_rate($tax_rate_id); |
|
988 | + $item->set_order_id($order->get_id()); |
|
989 | 989 | $item_id = $item->save(); |
990 | - $order->add_item( $item ); |
|
990 | + $order->add_item($item); |
|
991 | 991 | } |
992 | 992 | |
993 | - if ( $tax_rate_id && ! $item_id && apply_filters( 'woocommerce_cart_remove_taxes_zero_rate_id', 'zero-rated' ) !== $tax_rate_id ) { |
|
994 | - throw new Exception( sprintf( __( 'Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe' ), 528 ) ); |
|
993 | + if ($tax_rate_id && ! $item_id && apply_filters('woocommerce_cart_remove_taxes_zero_rate_id', 'zero-rated') !== $tax_rate_id) { |
|
994 | + throw new Exception(sprintf(__('Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe'), 528)); |
|
995 | 995 | } |
996 | 996 | } |
997 | 997 | |
998 | 998 | // Store coupons |
999 | - $discount = WC()->cart->get_coupon_discount_amount( $code ); |
|
1000 | - $discount_tax = WC()->cart->get_coupon_discount_tax_amount( $code ); |
|
999 | + $discount = WC()->cart->get_coupon_discount_amount($code); |
|
1000 | + $discount_tax = WC()->cart->get_coupon_discount_tax_amount($code); |
|
1001 | 1001 | |
1002 | - foreach ( WC()->cart->get_coupons() as $code => $coupon ) { |
|
1003 | - if ( version_compare( WC_VERSION, '3.0', '<' ) ) { |
|
1004 | - $coupon_id = $order->add_coupon( $code, $discount, $discount_tax ); |
|
1002 | + foreach (WC()->cart->get_coupons() as $code => $coupon) { |
|
1003 | + if (version_compare(WC_VERSION, '3.0', '<')) { |
|
1004 | + $coupon_id = $order->add_coupon($code, $discount, $discount_tax); |
|
1005 | 1005 | } else { |
1006 | 1006 | $item = new WC_Order_Item_Coupon(); |
1007 | - $item->set_props( array( |
|
1007 | + $item->set_props(array( |
|
1008 | 1008 | 'code' => $code, |
1009 | 1009 | 'discount' => $discount, |
1010 | 1010 | 'discount_tax' => $discount_tax, |
1011 | 1011 | 'order_id' => $order->get_id(), |
1012 | - ) ); |
|
1012 | + )); |
|
1013 | 1013 | $coupon_id = $item->save(); |
1014 | - $order->add_item( $item ); |
|
1014 | + $order->add_item($item); |
|
1015 | 1015 | } |
1016 | 1016 | |
1017 | - if ( ! $coupon_id ) { |
|
1018 | - throw new Exception( sprintf( __( 'Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe' ), 529 ) ); |
|
1017 | + if ( ! $coupon_id) { |
|
1018 | + throw new Exception(sprintf(__('Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe'), 529)); |
|
1019 | 1019 | } |
1020 | 1020 | } |
1021 | 1021 | |
1022 | 1022 | // Billing address |
1023 | 1023 | $billing_address = array(); |
1024 | - if ( ! empty( $data['token']['card'] ) ) { |
|
1024 | + if ( ! empty($data['token']['card'])) { |
|
1025 | 1025 | // Name from Stripe is a full name string. |
1026 | - $name = explode( ' ', $data['token']['card']['name'] ); |
|
1027 | - $lastname = array_pop( $name ); |
|
1028 | - $firstname = implode( ' ', $name ); |
|
1026 | + $name = explode(' ', $data['token']['card']['name']); |
|
1027 | + $lastname = array_pop($name); |
|
1028 | + $firstname = implode(' ', $name); |
|
1029 | 1029 | $billing_address['first_name'] = $firstname; |
1030 | 1030 | $billing_address['last_name'] = $lastname; |
1031 | 1031 | $billing_address['email'] = $data['shippingContact']['emailAddress']; |
@@ -1040,7 +1040,7 @@ discard block |
||
1040 | 1040 | |
1041 | 1041 | // Shipping address. |
1042 | 1042 | $shipping_address = array(); |
1043 | - if ( WC()->cart->needs_shipping() && $this->is_shipping_enabled && ! empty( $data['shippingContact'] ) ) { |
|
1043 | + if (WC()->cart->needs_shipping() && $this->is_shipping_enabled && ! empty($data['shippingContact'])) { |
|
1044 | 1044 | $shipping_address['first_name'] = $data['shippingContact']['givenName']; |
1045 | 1045 | $shipping_address['last_name'] = $data['shippingContact']['familyName']; |
1046 | 1046 | $shipping_address['email'] = $data['shippingContact']['emailAddress']; |
@@ -1051,7 +1051,7 @@ discard block |
||
1051 | 1051 | $shipping_address['city'] = $data['shippingContact']['locality']; |
1052 | 1052 | $shipping_address['state'] = $data['shippingContact']['administrativeArea']; |
1053 | 1053 | $shipping_address['postcode'] = $data['shippingContact']['postalCode']; |
1054 | - } elseif ( ! empty( $data['shippingContact'] ) ) { |
|
1054 | + } elseif ( ! empty($data['shippingContact'])) { |
|
1055 | 1055 | $shipping_address['first_name'] = $firstname; |
1056 | 1056 | $shipping_address['last_name'] = $lastname; |
1057 | 1057 | $shipping_address['email'] = $data['shippingContact']['emailAddress']; |
@@ -1064,33 +1064,33 @@ discard block |
||
1064 | 1064 | $shipping_address['postcode'] = $data['token']['card']['address_zip']; |
1065 | 1065 | } |
1066 | 1066 | |
1067 | - $order->set_address( $billing_address, 'billing' ); |
|
1068 | - $order->set_address( $shipping_address, 'shipping' ); |
|
1067 | + $order->set_address($billing_address, 'billing'); |
|
1068 | + $order->set_address($shipping_address, 'shipping'); |
|
1069 | 1069 | |
1070 | - WC()->shipping->calculate_shipping( WC()->cart->get_shipping_packages() ); |
|
1070 | + WC()->shipping->calculate_shipping(WC()->cart->get_shipping_packages()); |
|
1071 | 1071 | |
1072 | 1072 | // Get the rate object selected by user. |
1073 | - foreach ( WC()->shipping->get_packages() as $package_key => $package ) { |
|
1074 | - foreach ( $package['rates'] as $key => $rate ) { |
|
1073 | + foreach (WC()->shipping->get_packages() as $package_key => $package) { |
|
1074 | + foreach ($package['rates'] as $key => $rate) { |
|
1075 | 1075 | // Loop through user chosen shipping methods. |
1076 | - foreach ( WC()->session->get( 'chosen_shipping_methods' ) as $method ) { |
|
1077 | - if ( $method === $key ) { |
|
1078 | - if ( version_compare( WC_VERSION, '3.0', '<' ) ) { |
|
1079 | - $order->add_shipping( $rate ); |
|
1076 | + foreach (WC()->session->get('chosen_shipping_methods') as $method) { |
|
1077 | + if ($method === $key) { |
|
1078 | + if (version_compare(WC_VERSION, '3.0', '<')) { |
|
1079 | + $order->add_shipping($rate); |
|
1080 | 1080 | } else { |
1081 | 1081 | $item = new WC_Order_Item_Shipping(); |
1082 | - $item->set_props( array( |
|
1082 | + $item->set_props(array( |
|
1083 | 1083 | 'method_title' => $rate->label, |
1084 | 1084 | 'method_id' => $rate->id, |
1085 | - 'total' => wc_format_decimal( $rate->cost ), |
|
1085 | + 'total' => wc_format_decimal($rate->cost), |
|
1086 | 1086 | 'taxes' => $rate->taxes, |
1087 | 1087 | 'order_id' => $order->get_id(), |
1088 | - ) ); |
|
1089 | - foreach ( $rate->get_meta_data() as $key => $value ) { |
|
1090 | - $item->add_meta_data( $key, $value, true ); |
|
1088 | + )); |
|
1089 | + foreach ($rate->get_meta_data() as $key => $value) { |
|
1090 | + $item->add_meta_data($key, $value, true); |
|
1091 | 1091 | } |
1092 | 1092 | $item->save(); |
1093 | - $order->add_item( $item ); |
|
1093 | + $order->add_item($item); |
|
1094 | 1094 | } |
1095 | 1095 | } |
1096 | 1096 | } |
@@ -1098,37 +1098,37 @@ discard block |
||
1098 | 1098 | } |
1099 | 1099 | |
1100 | 1100 | $available_gateways = WC()->payment_gateways->get_available_payment_gateways(); |
1101 | - $order->set_payment_method( $available_gateways['stripe'] ); |
|
1101 | + $order->set_payment_method($available_gateways['stripe']); |
|
1102 | 1102 | WC()->cart->calculate_totals(); |
1103 | 1103 | |
1104 | - if ( version_compare( WC_VERSION, '3.0', '<' ) ) { |
|
1105 | - $order->set_total( WC()->cart->shipping_total, 'shipping' ); |
|
1106 | - $order->set_total( WC()->cart->get_cart_discount_total(), 'cart_discount' ); |
|
1107 | - $order->set_total( WC()->cart->get_cart_discount_tax_total(), 'cart_discount_tax' ); |
|
1108 | - $order->set_total( WC()->cart->tax_total, 'tax' ); |
|
1109 | - $order->set_total( WC()->cart->shipping_tax_total, 'shipping_tax' ); |
|
1110 | - $order->set_total( WC()->cart->total ); |
|
1104 | + if (version_compare(WC_VERSION, '3.0', '<')) { |
|
1105 | + $order->set_total(WC()->cart->shipping_total, 'shipping'); |
|
1106 | + $order->set_total(WC()->cart->get_cart_discount_total(), 'cart_discount'); |
|
1107 | + $order->set_total(WC()->cart->get_cart_discount_tax_total(), 'cart_discount_tax'); |
|
1108 | + $order->set_total(WC()->cart->tax_total, 'tax'); |
|
1109 | + $order->set_total(WC()->cart->shipping_tax_total, 'shipping_tax'); |
|
1110 | + $order->set_total(WC()->cart->total); |
|
1111 | 1111 | } else { |
1112 | - $order->set_shipping_total( WC()->cart->shipping_total ); |
|
1113 | - $order->set_discount_total( WC()->cart->get_cart_discount_total() ); |
|
1114 | - $order->set_discount_tax( WC()->cart->get_cart_discount_tax_total() ); |
|
1115 | - $order->set_cart_tax( WC()->cart->tax_total ); |
|
1116 | - $order->set_shipping_tax( WC()->cart->shipping_tax_total ); |
|
1117 | - |
|
1118 | - $discounts = wc_format_decimal( WC()->cart->get_cart_discount_total(), $this->dp ); |
|
1119 | - $tax = wc_format_decimal( WC()->cart->tax_total + WC()->cart->shipping_tax_total, $this->dp ); |
|
1120 | - $shipping = wc_format_decimal( WC()->cart->shipping_total, $this->dp ); |
|
1121 | - $item_total = wc_format_decimal( WC()->cart->cart_contents_total, $this->dp ) + $discounts; |
|
1122 | - $order_total = wc_format_decimal( $item_total + $tax + $shipping - $discounts, $this->dp ); |
|
1123 | - |
|
1124 | - $order->set_total( $order_total ); |
|
1112 | + $order->set_shipping_total(WC()->cart->shipping_total); |
|
1113 | + $order->set_discount_total(WC()->cart->get_cart_discount_total()); |
|
1114 | + $order->set_discount_tax(WC()->cart->get_cart_discount_tax_total()); |
|
1115 | + $order->set_cart_tax(WC()->cart->tax_total); |
|
1116 | + $order->set_shipping_tax(WC()->cart->shipping_tax_total); |
|
1117 | + |
|
1118 | + $discounts = wc_format_decimal(WC()->cart->get_cart_discount_total(), $this->dp); |
|
1119 | + $tax = wc_format_decimal(WC()->cart->tax_total + WC()->cart->shipping_tax_total, $this->dp); |
|
1120 | + $shipping = wc_format_decimal(WC()->cart->shipping_total, $this->dp); |
|
1121 | + $item_total = wc_format_decimal(WC()->cart->cart_contents_total, $this->dp) + $discounts; |
|
1122 | + $order_total = wc_format_decimal($item_total + $tax + $shipping - $discounts, $this->dp); |
|
1123 | + |
|
1124 | + $order->set_total($order_total); |
|
1125 | 1125 | $order->save(); |
1126 | 1126 | } |
1127 | 1127 | |
1128 | 1128 | // If we got here, the order was created without problems! |
1129 | - wc_transaction_query( 'commit' ); |
|
1129 | + wc_transaction_query('commit'); |
|
1130 | 1130 | |
1131 | - do_action( 'woocommerce_checkout_update_order_meta', $order_id, array() ); |
|
1131 | + do_action('woocommerce_checkout_update_order_meta', $order_id, array()); |
|
1132 | 1132 | |
1133 | 1133 | return $order; |
1134 | 1134 | } |
@@ -1141,9 +1141,9 @@ discard block |
||
1141 | 1141 | * |
1142 | 1142 | * @param string $message |
1143 | 1143 | */ |
1144 | - public function log( $message ) { |
|
1145 | - if ( $this->logging ) { |
|
1146 | - WC_Stripe::log( 'Apple Pay: ' . $message ); |
|
1144 | + public function log($message) { |
|
1145 | + if ($this->logging) { |
|
1146 | + WC_Stripe::log('Apple Pay: ' . $message); |
|
1147 | 1147 | } |
1148 | 1148 | } |
1149 | 1149 | } |