@@ -309,7 +309,7 @@ |
||
309 | 309 | * |
310 | 310 | * @since 3.1.0 |
311 | 311 | * @version 3.1.0 |
312 | - * @return array |
|
312 | + * @return string[] |
|
313 | 313 | */ |
314 | 314 | public function supported_product_types() { |
315 | 315 | return array( |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if ( ! defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | 5 | |
@@ -89,27 +89,27 @@ discard block |
||
89 | 89 | public function __construct() { |
90 | 90 | self::$_this = $this; |
91 | 91 | |
92 | - $gateway_settings = get_option( 'woocommerce_stripe_settings', '' ); |
|
92 | + $gateway_settings = get_option('woocommerce_stripe_settings', ''); |
|
93 | 93 | |
94 | - $this->statement_descriptor = ! empty( $gateway_settings['statement_descriptor'] ) ? $gateway_settings['statement_descriptor'] : wp_specialchars_decode( get_bloginfo( 'name' ), ENT_QUOTES ); |
|
94 | + $this->statement_descriptor = ! empty($gateway_settings['statement_descriptor']) ? $gateway_settings['statement_descriptor'] : wp_specialchars_decode(get_bloginfo('name'), ENT_QUOTES); |
|
95 | 95 | |
96 | 96 | // If both site title and statement descriptor is not set. Fallback. |
97 | - if ( empty( $this->statement_descriptor ) ) { |
|
97 | + if (empty($this->statement_descriptor)) { |
|
98 | 98 | $this->statement_descriptor = $_SERVER['SERVER_NAME']; |
99 | 99 | } |
100 | 100 | |
101 | - $this->enabled = ( ! empty( $gateway_settings['enabled'] ) && 'yes' === $gateway_settings['enabled'] ) ? true : false; |
|
102 | - $this->testmode = ( ! empty( $gateway_settings['testmode'] ) && 'yes' === $gateway_settings['testmode'] ) ? true : false; |
|
103 | - $this->capture = ( ! empty( $gateway_settings['capture'] ) && 'yes' === $gateway_settings['capture'] ) ? true : false; |
|
104 | - $this->saved_cards = ( ! empty( $gateway_settings['saved_cards'] ) && 'yes' === $gateway_settings['saved_cards'] ) ? true : false; |
|
105 | - $this->apple_pay = ( ! empty( $gateway_settings['apple_pay'] ) && 'yes' === $gateway_settings['apple_pay'] ) ? true : false; |
|
106 | - $this->apple_pay_button = ! empty( $gateway_settings['apple_pay_button'] ) ? $gateway_settings['apple_pay_button'] : 'black'; |
|
107 | - $this->apple_pay_button_lang = ! empty( $gateway_settings['apple_pay_button_lang'] ) ? $gateway_settings['apple_pay_button_lang'] : 'en'; |
|
108 | - $this->logging = ( ! empty( $gateway_settings['logging'] ) && 'yes' === $gateway_settings['logging'] ) ? true : false; |
|
109 | - $this->publishable_key = ! empty( $gateway_settings['publishable_key'] ) ? $gateway_settings['publishable_key'] : ''; |
|
110 | - |
|
111 | - if ( $this->testmode ) { |
|
112 | - $this->publishable_key = ! empty( $gateway_settings['test_publishable_key'] ) ? $gateway_settings['test_publishable_key'] : ''; |
|
101 | + $this->enabled = ( ! empty($gateway_settings['enabled']) && 'yes' === $gateway_settings['enabled']) ? true : false; |
|
102 | + $this->testmode = ( ! empty($gateway_settings['testmode']) && 'yes' === $gateway_settings['testmode']) ? true : false; |
|
103 | + $this->capture = ( ! empty($gateway_settings['capture']) && 'yes' === $gateway_settings['capture']) ? true : false; |
|
104 | + $this->saved_cards = ( ! empty($gateway_settings['saved_cards']) && 'yes' === $gateway_settings['saved_cards']) ? true : false; |
|
105 | + $this->apple_pay = ( ! empty($gateway_settings['apple_pay']) && 'yes' === $gateway_settings['apple_pay']) ? true : false; |
|
106 | + $this->apple_pay_button = ! empty($gateway_settings['apple_pay_button']) ? $gateway_settings['apple_pay_button'] : 'black'; |
|
107 | + $this->apple_pay_button_lang = ! empty($gateway_settings['apple_pay_button_lang']) ? $gateway_settings['apple_pay_button_lang'] : 'en'; |
|
108 | + $this->logging = ( ! empty($gateway_settings['logging']) && 'yes' === $gateway_settings['logging']) ? true : false; |
|
109 | + $this->publishable_key = ! empty($gateway_settings['publishable_key']) ? $gateway_settings['publishable_key'] : ''; |
|
110 | + |
|
111 | + if ($this->testmode) { |
|
112 | + $this->publishable_key = ! empty($gateway_settings['test_publishable_key']) ? $gateway_settings['test_publishable_key'] : ''; |
|
113 | 113 | } |
114 | 114 | |
115 | 115 | $this->init(); |
@@ -128,53 +128,53 @@ discard block |
||
128 | 128 | */ |
129 | 129 | public function init() { |
130 | 130 | // If Apple Pay is not enabled no need to proceed further. |
131 | - if ( ! $this->apple_pay ) { |
|
131 | + if ( ! $this->apple_pay) { |
|
132 | 132 | return; |
133 | 133 | } |
134 | 134 | |
135 | - add_action( 'wp_enqueue_scripts', array( $this, 'cart_scripts' ) ); |
|
136 | - add_action( 'wp_enqueue_scripts', array( $this, 'single_scripts' ) ); |
|
135 | + add_action('wp_enqueue_scripts', array($this, 'cart_scripts')); |
|
136 | + add_action('wp_enqueue_scripts', array($this, 'single_scripts')); |
|
137 | 137 | |
138 | 138 | /** |
139 | 139 | * In order to display the Apple Pay button in the correct position, |
140 | 140 | * a new hook was added to WooCommerce 3.0. In older versions of WooCommerce, |
141 | 141 | * CSS is used to position the button. |
142 | 142 | */ |
143 | - if ( version_compare( WC_VERSION, '3.0.0', '<' ) ) { |
|
144 | - add_action( 'woocommerce_after_add_to_cart_button', array( $this, 'display_apple_pay_button' ), 1 ); |
|
143 | + if (version_compare(WC_VERSION, '3.0.0', '<')) { |
|
144 | + add_action('woocommerce_after_add_to_cart_button', array($this, 'display_apple_pay_button'), 1); |
|
145 | 145 | } else { |
146 | - add_action( 'woocommerce_after_add_to_cart_quantity', array( $this, 'display_apple_pay_button' ), 1 ); |
|
146 | + add_action('woocommerce_after_add_to_cart_quantity', array($this, 'display_apple_pay_button'), 1); |
|
147 | 147 | } |
148 | 148 | |
149 | - add_action( 'woocommerce_proceed_to_checkout', array( $this, 'display_apple_pay_button' ), 1 ); |
|
150 | - add_action( 'woocommerce_proceed_to_checkout', array( $this, 'display_apple_pay_separator_html' ), 2 ); |
|
151 | - add_action( 'woocommerce_checkout_before_customer_details', array( $this, 'display_apple_pay_button' ), 1 ); |
|
152 | - add_action( 'woocommerce_checkout_before_customer_details', array( $this, 'display_apple_pay_separator_html' ), 2 ); |
|
153 | - add_action( 'wc_ajax_wc_stripe_log_apple_pay_errors', array( $this, 'log_apple_pay_errors' ) ); |
|
154 | - add_action( 'wc_ajax_wc_stripe_apple_pay', array( $this, 'process_apple_pay' ) ); |
|
155 | - add_action( 'wc_ajax_wc_stripe_generate_apple_pay_cart', array( $this, 'generate_apple_pay_cart' ) ); |
|
156 | - add_action( 'wc_ajax_wc_stripe_apple_pay_clear_cart', array( $this, 'clear_cart' ) ); |
|
157 | - add_action( 'wc_ajax_wc_stripe_generate_apple_pay_single', array( $this, 'generate_apple_pay_single' ) ); |
|
158 | - add_action( 'wc_ajax_wc_stripe_apple_pay_get_shipping_methods', array( $this, 'get_shipping_methods' ) ); |
|
159 | - add_action( 'wc_ajax_wc_stripe_apple_pay_update_shipping_method', array( $this, 'update_shipping_method' ) ); |
|
160 | - add_filter( 'woocommerce_gateway_title', array( $this, 'filter_gateway_title' ), 10, 2 ); |
|
161 | - add_filter( 'woocommerce_validate_postcode', array( $this, 'postal_code_validation' ), 10, 3 ); |
|
149 | + add_action('woocommerce_proceed_to_checkout', array($this, 'display_apple_pay_button'), 1); |
|
150 | + add_action('woocommerce_proceed_to_checkout', array($this, 'display_apple_pay_separator_html'), 2); |
|
151 | + add_action('woocommerce_checkout_before_customer_details', array($this, 'display_apple_pay_button'), 1); |
|
152 | + add_action('woocommerce_checkout_before_customer_details', array($this, 'display_apple_pay_separator_html'), 2); |
|
153 | + add_action('wc_ajax_wc_stripe_log_apple_pay_errors', array($this, 'log_apple_pay_errors')); |
|
154 | + add_action('wc_ajax_wc_stripe_apple_pay', array($this, 'process_apple_pay')); |
|
155 | + add_action('wc_ajax_wc_stripe_generate_apple_pay_cart', array($this, 'generate_apple_pay_cart')); |
|
156 | + add_action('wc_ajax_wc_stripe_apple_pay_clear_cart', array($this, 'clear_cart')); |
|
157 | + add_action('wc_ajax_wc_stripe_generate_apple_pay_single', array($this, 'generate_apple_pay_single')); |
|
158 | + add_action('wc_ajax_wc_stripe_apple_pay_get_shipping_methods', array($this, 'get_shipping_methods')); |
|
159 | + add_action('wc_ajax_wc_stripe_apple_pay_update_shipping_method', array($this, 'update_shipping_method')); |
|
160 | + add_filter('woocommerce_gateway_title', array($this, 'filter_gateway_title'), 10, 2); |
|
161 | + add_filter('woocommerce_validate_postcode', array($this, 'postal_code_validation'), 10, 3); |
|
162 | 162 | } |
163 | 163 | |
164 | 164 | /** |
165 | 165 | * Filters the gateway title to reflect Apple Pay. |
166 | 166 | * |
167 | 167 | */ |
168 | - public function filter_gateway_title( $title, $id ) { |
|
168 | + public function filter_gateway_title($title, $id) { |
|
169 | 169 | global $post; |
170 | 170 | |
171 | - if ( ! is_object( $post ) ) { |
|
171 | + if ( ! is_object($post)) { |
|
172 | 172 | return $title; |
173 | 173 | } |
174 | 174 | |
175 | - $method_title = get_post_meta( $post->ID, '_payment_method_title', true ); |
|
175 | + $method_title = get_post_meta($post->ID, '_payment_method_title', true); |
|
176 | 176 | |
177 | - if ( 'stripe' === $id && ! empty( $method_title ) && 'Apple Pay (Stripe)' === $method_title ) { |
|
177 | + if ('stripe' === $id && ! empty($method_title) && 'Apple Pay (Stripe)' === $method_title) { |
|
178 | 178 | return $method_title; |
179 | 179 | } |
180 | 180 | |
@@ -188,13 +188,13 @@ discard block |
||
188 | 188 | * @version 3.1.4 |
189 | 189 | */ |
190 | 190 | public function log_apple_pay_errors() { |
191 | - if ( ! wp_verify_nonce( $_POST['nonce'], '_wc_stripe_apple_pay_nonce' ) && ! wp_verify_nonce( $_POST['nonce'], '_wc_stripe_apple_pay_cart_nonce' ) ) { |
|
192 | - wp_die( __( 'Cheatin’ huh?', 'woocommerce-gateway-stripe' ) ); |
|
191 | + if ( ! wp_verify_nonce($_POST['nonce'], '_wc_stripe_apple_pay_nonce') && ! wp_verify_nonce($_POST['nonce'], '_wc_stripe_apple_pay_cart_nonce')) { |
|
192 | + wp_die(__('Cheatin’ huh?', 'woocommerce-gateway-stripe')); |
|
193 | 193 | } |
194 | 194 | |
195 | - $errors = wc_clean( stripslashes( $_POST['errors'] ) ); |
|
195 | + $errors = wc_clean(stripslashes($_POST['errors'])); |
|
196 | 196 | |
197 | - $this->log( $errors ); |
|
197 | + $this->log($errors); |
|
198 | 198 | |
199 | 199 | exit; |
200 | 200 | } |
@@ -205,10 +205,10 @@ discard block |
||
205 | 205 | * @since 3.1.4 |
206 | 206 | * @version 3.1.4 |
207 | 207 | */ |
208 | - public function postal_code_validation( $valid, $postcode, $country ) { |
|
208 | + public function postal_code_validation($valid, $postcode, $country) { |
|
209 | 209 | $gateways = WC()->payment_gateways->get_available_payment_gateways(); |
210 | 210 | |
211 | - if ( ! $this->apple_pay || ! isset( $gateways['stripe'] ) ) { |
|
211 | + if ( ! $this->apple_pay || ! isset($gateways['stripe'])) { |
|
212 | 212 | return $valid; |
213 | 213 | } |
214 | 214 | |
@@ -217,7 +217,7 @@ discard block |
||
217 | 217 | * when passing it back from the shippingcontactselected object. This causes WC to invalidate |
218 | 218 | * the order and not let it go through. The remedy for now is just to remove this validation. |
219 | 219 | */ |
220 | - if ( 'GB' === $country || 'CA' === $country ) { |
|
220 | + if ('GB' === $country || 'CA' === $country) { |
|
221 | 221 | return true; |
222 | 222 | } |
223 | 223 | |
@@ -231,28 +231,28 @@ discard block |
||
231 | 231 | * @version 3.1.4 |
232 | 232 | */ |
233 | 233 | public function single_scripts() { |
234 | - if ( ! is_single() ) { |
|
234 | + if ( ! is_single()) { |
|
235 | 235 | return; |
236 | 236 | } |
237 | 237 | |
238 | 238 | global $post; |
239 | 239 | |
240 | - $product = wc_get_product( $post->ID ); |
|
240 | + $product = wc_get_product($post->ID); |
|
241 | 241 | |
242 | - if ( ! is_object( $product ) || ! in_array( ( version_compare( WC_VERSION, '3.0.0', '<' ) ? $product->product_type : $product->get_type() ), $this->supported_product_types() ) ) { |
|
242 | + if ( ! is_object($product) || ! in_array((version_compare(WC_VERSION, '3.0.0', '<') ? $product->product_type : $product->get_type()), $this->supported_product_types())) { |
|
243 | 243 | return; |
244 | 244 | } |
245 | 245 | |
246 | - $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
246 | + $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; |
|
247 | 247 | |
248 | - wp_enqueue_style( 'stripe_apple_pay', plugins_url( 'assets/css/stripe-apple-pay.css', WC_STRIPE_MAIN_FILE ), array(), WC_STRIPE_VERSION ); |
|
248 | + wp_enqueue_style('stripe_apple_pay', plugins_url('assets/css/stripe-apple-pay.css', WC_STRIPE_MAIN_FILE), array(), WC_STRIPE_VERSION); |
|
249 | 249 | |
250 | - wp_enqueue_script( 'stripe', 'https://js.stripe.com/v2/', '', '1.0', true ); |
|
251 | - 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 ); |
|
250 | + wp_enqueue_script('stripe', 'https://js.stripe.com/v2/', '', '1.0', true); |
|
251 | + 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); |
|
252 | 252 | |
253 | - $shipping_enabled = get_option( 'woocommerce_ship_to_countries', '' ); |
|
253 | + $shipping_enabled = get_option('woocommerce_ship_to_countries', ''); |
|
254 | 254 | |
255 | - if ( '' === $shipping_enabled || 'disabled' === $shipping_enabled ) { |
|
255 | + if ('' === $shipping_enabled || 'disabled' === $shipping_enabled) { |
|
256 | 256 | $shipping_enabled = false; |
257 | 257 | } else { |
258 | 258 | $shipping_enabled = true; |
@@ -261,20 +261,20 @@ discard block |
||
261 | 261 | $stripe_params = array( |
262 | 262 | 'key' => $this->publishable_key, |
263 | 263 | 'currency_code' => get_woocommerce_currency(), |
264 | - 'country_code' => substr( get_option( 'woocommerce_default_country' ), 0, 2 ), |
|
264 | + 'country_code' => substr(get_option('woocommerce_default_country'), 0, 2), |
|
265 | 265 | 'label' => $this->statement_descriptor, |
266 | - 'ajaxurl' => WC_AJAX::get_endpoint( '%%endpoint%%' ), |
|
267 | - 'stripe_apple_pay_nonce' => wp_create_nonce( '_wc_stripe_apple_pay_nonce' ), |
|
268 | - 'stripe_apple_pay_cart_nonce' => wp_create_nonce( '_wc_stripe_apple_pay_cart_nonce' ), |
|
269 | - 'stripe_apple_pay_get_shipping_methods_nonce' => wp_create_nonce( '_wc_stripe_apple_pay_get_shipping_methods_nonce' ), |
|
270 | - 'stripe_apple_pay_update_shipping_method_nonce' => wp_create_nonce( '_wc_stripe_apple_pay_update_shipping_method_nonce' ), |
|
271 | - 'needs_shipping' => ( $product->needs_shipping() && $shipping_enabled ) ? 'yes' : 'no', |
|
266 | + 'ajaxurl' => WC_AJAX::get_endpoint('%%endpoint%%'), |
|
267 | + 'stripe_apple_pay_nonce' => wp_create_nonce('_wc_stripe_apple_pay_nonce'), |
|
268 | + 'stripe_apple_pay_cart_nonce' => wp_create_nonce('_wc_stripe_apple_pay_cart_nonce'), |
|
269 | + 'stripe_apple_pay_get_shipping_methods_nonce' => wp_create_nonce('_wc_stripe_apple_pay_get_shipping_methods_nonce'), |
|
270 | + 'stripe_apple_pay_update_shipping_method_nonce' => wp_create_nonce('_wc_stripe_apple_pay_update_shipping_method_nonce'), |
|
271 | + 'needs_shipping' => ($product->needs_shipping() && $shipping_enabled) ? 'yes' : 'no', |
|
272 | 272 | 'i18n' => array( |
273 | - 'sub_total' => __( 'Sub-Total', 'woocommerce-gateway-stripe' ), |
|
273 | + 'sub_total' => __('Sub-Total', 'woocommerce-gateway-stripe'), |
|
274 | 274 | ), |
275 | 275 | ); |
276 | 276 | |
277 | - wp_localize_script( 'woocommerce_stripe_apple_pay_single', 'wc_stripe_apple_pay_single_params', apply_filters( 'wc_stripe_apple_pay_single_params', $stripe_params ) ); |
|
277 | + wp_localize_script('woocommerce_stripe_apple_pay_single', 'wc_stripe_apple_pay_single_params', apply_filters('wc_stripe_apple_pay_single_params', $stripe_params)); |
|
278 | 278 | } |
279 | 279 | |
280 | 280 | /** |
@@ -284,32 +284,32 @@ discard block |
||
284 | 284 | * @version 3.1.0 |
285 | 285 | */ |
286 | 286 | public function cart_scripts() { |
287 | - if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) ) { |
|
287 | + if ( ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order'])) { |
|
288 | 288 | return; |
289 | 289 | } |
290 | 290 | |
291 | - $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
291 | + $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; |
|
292 | 292 | |
293 | - wp_enqueue_style( 'stripe_apple_pay', plugins_url( 'assets/css/stripe-apple-pay.css', WC_STRIPE_MAIN_FILE ), array(), WC_STRIPE_VERSION ); |
|
293 | + wp_enqueue_style('stripe_apple_pay', plugins_url('assets/css/stripe-apple-pay.css', WC_STRIPE_MAIN_FILE), array(), WC_STRIPE_VERSION); |
|
294 | 294 | |
295 | - wp_enqueue_script( 'stripe', 'https://js.stripe.com/v2/', '', '1.0', true ); |
|
296 | - 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 ); |
|
295 | + wp_enqueue_script('stripe', 'https://js.stripe.com/v2/', '', '1.0', true); |
|
296 | + 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); |
|
297 | 297 | |
298 | 298 | $stripe_params = array( |
299 | 299 | 'key' => $this->publishable_key, |
300 | 300 | 'currency_code' => get_woocommerce_currency(), |
301 | - 'country_code' => substr( get_option( 'woocommerce_default_country' ), 0, 2 ), |
|
301 | + 'country_code' => substr(get_option('woocommerce_default_country'), 0, 2), |
|
302 | 302 | 'label' => $this->statement_descriptor, |
303 | - 'ajaxurl' => WC_AJAX::get_endpoint( '%%endpoint%%' ), |
|
304 | - 'stripe_apple_pay_nonce' => wp_create_nonce( '_wc_stripe_apple_pay_nonce' ), |
|
305 | - 'stripe_apple_pay_cart_nonce' => wp_create_nonce( '_wc_stripe_apple_pay_cart_nonce' ), |
|
306 | - 'stripe_apple_pay_get_shipping_methods_nonce' => wp_create_nonce( '_wc_stripe_apple_pay_get_shipping_methods_nonce' ), |
|
307 | - 'stripe_apple_pay_update_shipping_method_nonce' => wp_create_nonce( '_wc_stripe_apple_pay_update_shipping_method_nonce' ), |
|
303 | + 'ajaxurl' => WC_AJAX::get_endpoint('%%endpoint%%'), |
|
304 | + 'stripe_apple_pay_nonce' => wp_create_nonce('_wc_stripe_apple_pay_nonce'), |
|
305 | + 'stripe_apple_pay_cart_nonce' => wp_create_nonce('_wc_stripe_apple_pay_cart_nonce'), |
|
306 | + 'stripe_apple_pay_get_shipping_methods_nonce' => wp_create_nonce('_wc_stripe_apple_pay_get_shipping_methods_nonce'), |
|
307 | + 'stripe_apple_pay_update_shipping_method_nonce' => wp_create_nonce('_wc_stripe_apple_pay_update_shipping_method_nonce'), |
|
308 | 308 | 'needs_shipping' => WC()->cart->needs_shipping() ? 'yes' : 'no', |
309 | 309 | 'is_cart_page' => is_cart() ? 'yes' : 'no', |
310 | 310 | ); |
311 | 311 | |
312 | - wp_localize_script( 'woocommerce_stripe_apple_pay', 'wc_stripe_apple_pay_params', apply_filters( 'wc_stripe_apple_pay_params', $stripe_params ) ); |
|
312 | + wp_localize_script('woocommerce_stripe_apple_pay', 'wc_stripe_apple_pay_params', apply_filters('wc_stripe_apple_pay_params', $stripe_params)); |
|
313 | 313 | } |
314 | 314 | |
315 | 315 | /** |
@@ -336,10 +336,10 @@ discard block |
||
336 | 336 | * @return bool |
337 | 337 | */ |
338 | 338 | public function allowed_items_in_cart() { |
339 | - foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) { |
|
340 | - $_product = apply_filters( 'woocommerce_cart_item_product', $cart_item['data'], $cart_item, $cart_item_key ); |
|
339 | + foreach (WC()->cart->get_cart() as $cart_item_key => $cart_item) { |
|
340 | + $_product = apply_filters('woocommerce_cart_item_product', $cart_item['data'], $cart_item, $cart_item_key); |
|
341 | 341 | |
342 | - if ( ! in_array( ( version_compare( WC_VERSION, '3.0.0', '<' ) ? $_product->product_type : $_product->get_type() ), $this->supported_product_types() ) ) { |
|
342 | + if ( ! in_array((version_compare(WC_VERSION, '3.0.0', '<') ? $_product->product_type : $_product->get_type()), $this->supported_product_types())) { |
|
343 | 343 | return false; |
344 | 344 | } |
345 | 345 | } |
@@ -360,29 +360,29 @@ discard block |
||
360 | 360 | * In order for the Apple Pay button to show on product detail page, |
361 | 361 | * Apple Pay must be enabled and Stripe gateway must be enabled. |
362 | 362 | */ |
363 | - if ( ! $this->apple_pay || ! isset( $gateways['stripe'] ) ) { |
|
364 | - $this->log( 'Apple Pay not enabled or Stripe is not an available gateway ( Apple Pay button disabled )' ); |
|
363 | + if ( ! $this->apple_pay || ! isset($gateways['stripe'])) { |
|
364 | + $this->log('Apple Pay not enabled or Stripe is not an available gateway ( Apple Pay button disabled )'); |
|
365 | 365 | return; |
366 | 366 | } |
367 | 367 | |
368 | - if ( is_single() ) { |
|
368 | + if (is_single()) { |
|
369 | 369 | global $post; |
370 | 370 | |
371 | - $product = wc_get_product( $post->ID ); |
|
371 | + $product = wc_get_product($post->ID); |
|
372 | 372 | |
373 | - if ( ! is_object( $product ) || ! in_array( ( version_compare( WC_VERSION, '3.0.0', '<' ) ? $product->product_type : $product->get_type() ), $this->supported_product_types() ) ) { |
|
373 | + if ( ! is_object($product) || ! in_array((version_compare(WC_VERSION, '3.0.0', '<') ? $product->product_type : $product->get_type()), $this->supported_product_types())) { |
|
374 | 374 | return; |
375 | 375 | } |
376 | 376 | } else { |
377 | - if ( ! $this->allowed_items_in_cart() ) { |
|
378 | - $this->log( 'Items in the cart has unsupported product type ( Apple Pay button disabled )' ); |
|
377 | + if ( ! $this->allowed_items_in_cart()) { |
|
378 | + $this->log('Items in the cart has unsupported product type ( Apple Pay button disabled )'); |
|
379 | 379 | return; |
380 | 380 | } |
381 | 381 | } |
382 | 382 | |
383 | 383 | ?> |
384 | 384 | <div class="apple-pay-button-wrapper"> |
385 | - <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 ); ?>;"></button> |
|
385 | + <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); ?>;"></button> |
|
386 | 386 | </div> |
387 | 387 | <?php |
388 | 388 | } |
@@ -400,17 +400,17 @@ discard block |
||
400 | 400 | * In order for the Apple Pay button to show on cart page, |
401 | 401 | * Apple Pay must be enabled and Stripe gateway must be enabled. |
402 | 402 | */ |
403 | - if ( ! $this->apple_pay || ! isset( $gateways['stripe'] ) ) { |
|
404 | - $this->log( 'Apple Pay not enabled or Stripe is not an available gateway ( Apple Pay button disabled )' ); |
|
403 | + if ( ! $this->apple_pay || ! isset($gateways['stripe'])) { |
|
404 | + $this->log('Apple Pay not enabled or Stripe is not an available gateway ( Apple Pay button disabled )'); |
|
405 | 405 | return; |
406 | 406 | } |
407 | 407 | |
408 | - if ( ! $this->allowed_items_in_cart() ) { |
|
409 | - $this->log( 'Items in the cart has unsupported product type ( Apple Pay button disabled )' ); |
|
408 | + if ( ! $this->allowed_items_in_cart()) { |
|
409 | + $this->log('Items in the cart has unsupported product type ( Apple Pay button disabled )'); |
|
410 | 410 | return; |
411 | 411 | } |
412 | 412 | ?> |
413 | - <p class="apple-pay-button-checkout-separator">- <?php esc_html_e( 'Or', 'woocommerce-gateway-stripe' ); ?> -</p> |
|
413 | + <p class="apple-pay-button-checkout-separator">- <?php esc_html_e('Or', 'woocommerce-gateway-stripe'); ?> -</p> |
|
414 | 414 | <?php |
415 | 415 | } |
416 | 416 | |
@@ -421,51 +421,51 @@ discard block |
||
421 | 421 | * @version 3.1.0 |
422 | 422 | */ |
423 | 423 | public function generate_apple_pay_single() { |
424 | - if ( ! wp_verify_nonce( $_POST['nonce'], '_wc_stripe_apple_pay_cart_nonce' ) ) { |
|
425 | - wp_die( __( 'Cheatin’ huh?', 'woocommerce-gateway-stripe' ) ); |
|
424 | + if ( ! wp_verify_nonce($_POST['nonce'], '_wc_stripe_apple_pay_cart_nonce')) { |
|
425 | + wp_die(__('Cheatin’ huh?', 'woocommerce-gateway-stripe')); |
|
426 | 426 | } |
427 | 427 | |
428 | - if ( ! defined( 'WOOCOMMERCE_CART' ) ) { |
|
429 | - define( 'WOOCOMMERCE_CART', true ); |
|
428 | + if ( ! defined('WOOCOMMERCE_CART')) { |
|
429 | + define('WOOCOMMERCE_CART', true); |
|
430 | 430 | } |
431 | 431 | |
432 | 432 | WC()->shipping->reset_shipping(); |
433 | 433 | |
434 | 434 | global $post; |
435 | 435 | |
436 | - $product = wc_get_product( $post->ID ); |
|
437 | - $qty = ! isset( $_POST['qty'] ) ? 1 : absint( $_POST['qty'] ); |
|
436 | + $product = wc_get_product($post->ID); |
|
437 | + $qty = ! isset($_POST['qty']) ? 1 : absint($_POST['qty']); |
|
438 | 438 | |
439 | 439 | /** |
440 | 440 | * If this page is single product page, we need to simulate |
441 | 441 | * adding the product to the cart taken account if it is a |
442 | 442 | * simple or variable product. |
443 | 443 | */ |
444 | - if ( is_single() ) { |
|
444 | + if (is_single()) { |
|
445 | 445 | // First empty the cart to prevent wrong calculation. |
446 | 446 | WC()->cart->empty_cart(); |
447 | 447 | |
448 | - if ( 'variable' === ( version_compare( WC_VERSION, '3.0.0', '<' ) ? $product->product_type : $product->get_type() ) && isset( $_POST['attributes'] ) ) { |
|
449 | - $attributes = array_map( 'wc_clean', $_POST['attributes'] ); |
|
448 | + if ('variable' === (version_compare(WC_VERSION, '3.0.0', '<') ? $product->product_type : $product->get_type()) && isset($_POST['attributes'])) { |
|
449 | + $attributes = array_map('wc_clean', $_POST['attributes']); |
|
450 | 450 | |
451 | - if ( version_compare( WC_VERSION, '3.0.0', '<' ) ) { |
|
452 | - $variation_id = $product->get_matching_variation( $attributes ); |
|
451 | + if (version_compare(WC_VERSION, '3.0.0', '<')) { |
|
452 | + $variation_id = $product->get_matching_variation($attributes); |
|
453 | 453 | } else { |
454 | - $data_store = WC_Data_Store::load( 'product' ); |
|
455 | - $variation_id = $data_store->find_matching_product_variation( $product, $attributes ); |
|
454 | + $data_store = WC_Data_Store::load('product'); |
|
455 | + $variation_id = $data_store->find_matching_product_variation($product, $attributes); |
|
456 | 456 | } |
457 | 457 | |
458 | - WC()->cart->add_to_cart( $product->get_id(), $qty, $variation_id, $attributes ); |
|
458 | + WC()->cart->add_to_cart($product->get_id(), $qty, $variation_id, $attributes); |
|
459 | 459 | } |
460 | 460 | |
461 | - if ( 'simple' === ( version_compare( WC_VERSION, '3.0.0', '<' ) ? $product->product_type : $product->get_type() ) ) { |
|
462 | - WC()->cart->add_to_cart( $product->get_id(), $qty ); |
|
461 | + if ('simple' === (version_compare(WC_VERSION, '3.0.0', '<') ? $product->product_type : $product->get_type())) { |
|
462 | + WC()->cart->add_to_cart($product->get_id(), $qty); |
|
463 | 463 | } |
464 | 464 | } |
465 | 465 | |
466 | 466 | WC()->cart->calculate_totals(); |
467 | 467 | |
468 | - wp_send_json( array( 'line_items' => $this->build_line_items(), 'total' => WC()->cart->total ) ); |
|
468 | + wp_send_json(array('line_items' => $this->build_line_items(), 'total' => WC()->cart->total)); |
|
469 | 469 | } |
470 | 470 | |
471 | 471 | /** |
@@ -475,11 +475,11 @@ discard block |
||
475 | 475 | * @version 3.1.0 |
476 | 476 | */ |
477 | 477 | public function generate_apple_pay_cart() { |
478 | - if ( ! wp_verify_nonce( $_POST['nonce'], '_wc_stripe_apple_pay_cart_nonce' ) ) { |
|
479 | - wp_die( __( 'Cheatin’ huh?', 'woocommerce-gateway-stripe' ) ); |
|
478 | + if ( ! wp_verify_nonce($_POST['nonce'], '_wc_stripe_apple_pay_cart_nonce')) { |
|
479 | + wp_die(__('Cheatin’ huh?', 'woocommerce-gateway-stripe')); |
|
480 | 480 | } |
481 | 481 | |
482 | - wp_send_json( array( 'line_items' => $this->build_line_items(), 'total' => WC()->cart->total ) ); |
|
482 | + wp_send_json(array('line_items' => $this->build_line_items(), 'total' => WC()->cart->total)); |
|
483 | 483 | } |
484 | 484 | |
485 | 485 | /** |
@@ -500,29 +500,29 @@ discard block |
||
500 | 500 | * @version 3.1.0 |
501 | 501 | * @param array $address |
502 | 502 | */ |
503 | - public function calculate_shipping( $address = array() ) { |
|
504 | - $country = strtoupper( $address['countryCode'] ); |
|
505 | - $state = strtoupper( $address['administrativeArea'] ); |
|
503 | + public function calculate_shipping($address = array()) { |
|
504 | + $country = strtoupper($address['countryCode']); |
|
505 | + $state = strtoupper($address['administrativeArea']); |
|
506 | 506 | $postcode = $address['postalCode']; |
507 | 507 | $city = $address['locality']; |
508 | 508 | |
509 | 509 | WC()->shipping->reset_shipping(); |
510 | 510 | |
511 | - if ( $postcode && ! WC_Validation::is_postcode( $postcode, $country ) ) { |
|
512 | - throw new Exception( __( 'Please enter a valid postcode/ZIP.', 'woocommerce-gateway-stripe' ) ); |
|
513 | - } elseif ( $postcode ) { |
|
514 | - $postcode = wc_format_postcode( $postcode, $country ); |
|
511 | + if ($postcode && ! WC_Validation::is_postcode($postcode, $country)) { |
|
512 | + throw new Exception(__('Please enter a valid postcode/ZIP.', 'woocommerce-gateway-stripe')); |
|
513 | + } elseif ($postcode) { |
|
514 | + $postcode = wc_format_postcode($postcode, $country); |
|
515 | 515 | } |
516 | 516 | |
517 | - if ( $country ) { |
|
518 | - WC()->customer->set_location( $country, $state, $postcode, $city ); |
|
519 | - WC()->customer->set_shipping_location( $country, $state, $postcode, $city ); |
|
517 | + if ($country) { |
|
518 | + WC()->customer->set_location($country, $state, $postcode, $city); |
|
519 | + WC()->customer->set_shipping_location($country, $state, $postcode, $city); |
|
520 | 520 | } else { |
521 | 521 | WC()->customer->set_to_base(); |
522 | 522 | WC()->customer->set_shipping_to_base(); |
523 | 523 | } |
524 | 524 | |
525 | - WC()->customer->calculated_shipping( true ); |
|
525 | + WC()->customer->calculated_shipping(true); |
|
526 | 526 | |
527 | 527 | /** |
528 | 528 | * Set the shipping package. |
@@ -544,17 +544,17 @@ discard block |
||
544 | 544 | $packages[0]['destination']['postcode'] = $postcode; |
545 | 545 | $packages[0]['destination']['city'] = $city; |
546 | 546 | |
547 | - foreach ( WC()->cart->get_cart() as $item ) { |
|
548 | - if ( $item['data']->needs_shipping() ) { |
|
549 | - if ( isset( $item['line_total'] ) ) { |
|
547 | + foreach (WC()->cart->get_cart() as $item) { |
|
548 | + if ($item['data']->needs_shipping()) { |
|
549 | + if (isset($item['line_total'])) { |
|
550 | 550 | $packages[0]['contents_cost'] += $item['line_total']; |
551 | 551 | } |
552 | 552 | } |
553 | 553 | } |
554 | 554 | |
555 | - $packages = apply_filters( 'woocommerce_cart_shipping_packages', $packages ); |
|
555 | + $packages = apply_filters('woocommerce_cart_shipping_packages', $packages); |
|
556 | 556 | |
557 | - WC()->shipping->calculate_shipping( $packages ); |
|
557 | + WC()->shipping->calculate_shipping($packages); |
|
558 | 558 | } |
559 | 559 | |
560 | 560 | /** |
@@ -564,18 +564,18 @@ discard block |
||
564 | 564 | * @version 3.1.0 |
565 | 565 | */ |
566 | 566 | public function get_shipping_methods() { |
567 | - if ( ! wp_verify_nonce( $_POST['nonce'], '_wc_stripe_apple_pay_get_shipping_methods_nonce' ) ) { |
|
568 | - wp_die( __( 'Cheatin’ huh?', 'woocommerce-gateway-stripe' ) ); |
|
567 | + if ( ! wp_verify_nonce($_POST['nonce'], '_wc_stripe_apple_pay_get_shipping_methods_nonce')) { |
|
568 | + wp_die(__('Cheatin’ huh?', 'woocommerce-gateway-stripe')); |
|
569 | 569 | } |
570 | 570 | |
571 | - if ( ! defined( 'WOOCOMMERCE_CART' ) ) { |
|
572 | - define( 'WOOCOMMERCE_CART', true ); |
|
571 | + if ( ! defined('WOOCOMMERCE_CART')) { |
|
572 | + define('WOOCOMMERCE_CART', true); |
|
573 | 573 | } |
574 | 574 | |
575 | 575 | try { |
576 | - $address = array_map( 'wc_clean', $_POST['address'] ); |
|
576 | + $address = array_map('wc_clean', $_POST['address']); |
|
577 | 577 | |
578 | - $this->calculate_shipping( $address ); |
|
578 | + $this->calculate_shipping($address); |
|
579 | 579 | |
580 | 580 | // Set the shipping options. |
581 | 581 | $currency = get_woocommerce_currency(); |
@@ -583,13 +583,13 @@ discard block |
||
583 | 583 | |
584 | 584 | $packages = WC()->shipping->get_packages(); |
585 | 585 | |
586 | - if ( ! empty( $packages ) && WC()->customer->has_calculated_shipping() ) { |
|
587 | - foreach ( $packages as $package_key => $package ) { |
|
588 | - if ( empty( $package['rates'] ) ) { |
|
589 | - throw new Exception( __( 'Unable to find shipping method for address.', 'woocommerce-gateway-stripe' ) ); |
|
586 | + if ( ! empty($packages) && WC()->customer->has_calculated_shipping()) { |
|
587 | + foreach ($packages as $package_key => $package) { |
|
588 | + if (empty($package['rates'])) { |
|
589 | + throw new Exception(__('Unable to find shipping method for address.', 'woocommerce-gateway-stripe')); |
|
590 | 590 | } |
591 | 591 | |
592 | - foreach ( $package['rates'] as $key => $rate ) { |
|
592 | + foreach ($package['rates'] as $key => $rate) { |
|
593 | 593 | $data[] = array( |
594 | 594 | 'id' => $rate->id, |
595 | 595 | 'label' => $rate->label, |
@@ -603,16 +603,16 @@ discard block |
||
603 | 603 | } |
604 | 604 | |
605 | 605 | // Auto select the first shipping method. |
606 | - WC()->session->set( 'chosen_shipping_methods', array( $data[0]['id'] ) ); |
|
606 | + WC()->session->set('chosen_shipping_methods', array($data[0]['id'])); |
|
607 | 607 | |
608 | 608 | WC()->cart->calculate_totals(); |
609 | 609 | |
610 | - wp_send_json( array( 'success' => 'true', 'shipping_methods' => $this->build_shipping_methods( $data ), 'line_items' => $this->build_line_items(), 'total' => WC()->cart->total ) ); |
|
610 | + wp_send_json(array('success' => 'true', 'shipping_methods' => $this->build_shipping_methods($data), 'line_items' => $this->build_line_items(), 'total' => WC()->cart->total)); |
|
611 | 611 | } else { |
612 | - throw new Exception( __( 'Unable to find shipping method for address.', 'woocommerce-gateway-stripe' ) ); |
|
612 | + throw new Exception(__('Unable to find shipping method for address.', 'woocommerce-gateway-stripe')); |
|
613 | 613 | } |
614 | - } catch ( Exception $e ) { |
|
615 | - wp_send_json( array( 'success' => 'false', 'shipping_methods' => array(), 'line_items' => $this->build_line_items(), 'total' => WC()->cart->total ) ); |
|
614 | + } catch (Exception $e) { |
|
615 | + wp_send_json(array('success' => 'false', 'shipping_methods' => array(), 'line_items' => $this->build_line_items(), 'total' => WC()->cart->total)); |
|
616 | 616 | } |
617 | 617 | } |
618 | 618 | |
@@ -623,29 +623,29 @@ discard block |
||
623 | 623 | * @version 3.1.0 |
624 | 624 | */ |
625 | 625 | public function update_shipping_method() { |
626 | - if ( ! defined( 'WOOCOMMERCE_CART' ) ) { |
|
627 | - define( 'WOOCOMMERCE_CART', true ); |
|
626 | + if ( ! defined('WOOCOMMERCE_CART')) { |
|
627 | + define('WOOCOMMERCE_CART', true); |
|
628 | 628 | } |
629 | 629 | |
630 | - if ( ! wp_verify_nonce( $_POST['nonce'], '_wc_stripe_apple_pay_update_shipping_method_nonce' ) ) { |
|
631 | - wp_die( __( 'Cheatin’ huh?', 'woocommerce-gateway-stripe' ) ); |
|
630 | + if ( ! wp_verify_nonce($_POST['nonce'], '_wc_stripe_apple_pay_update_shipping_method_nonce')) { |
|
631 | + wp_die(__('Cheatin’ huh?', 'woocommerce-gateway-stripe')); |
|
632 | 632 | } |
633 | 633 | |
634 | - $selected_shipping_method = array_map( 'wc_clean', $_POST['selected_shipping_method'] ); |
|
634 | + $selected_shipping_method = array_map('wc_clean', $_POST['selected_shipping_method']); |
|
635 | 635 | |
636 | - WC()->session->set( 'chosen_shipping_methods', array( $selected_shipping_method['identifier'] ) ); |
|
636 | + WC()->session->set('chosen_shipping_methods', array($selected_shipping_method['identifier'])); |
|
637 | 637 | |
638 | 638 | WC()->cart->calculate_totals(); |
639 | 639 | |
640 | 640 | // Send back the new cart total. |
641 | 641 | $currency = get_woocommerce_currency(); |
642 | - $tax_total = max( 0, round( WC()->cart->tax_total + WC()->cart->shipping_tax_total, WC()->cart->dp ) ); |
|
642 | + $tax_total = max(0, round(WC()->cart->tax_total + WC()->cart->shipping_tax_total, WC()->cart->dp)); |
|
643 | 643 | $data = array( |
644 | 644 | 'total' => WC()->cart->total, |
645 | 645 | ); |
646 | 646 | |
647 | 647 | // Include fees and taxes as displayItems. |
648 | - foreach ( WC()->cart->fees as $key => $fee ) { |
|
648 | + foreach (WC()->cart->fees as $key => $fee) { |
|
649 | 649 | $data['items'][] = array( |
650 | 650 | 'label' => $fee->name, |
651 | 651 | 'amount' => array( |
@@ -654,9 +654,9 @@ discard block |
||
654 | 654 | ), |
655 | 655 | ); |
656 | 656 | } |
657 | - if ( 0 < $tax_total ) { |
|
657 | + if (0 < $tax_total) { |
|
658 | 658 | $data['items'][] = array( |
659 | - 'label' => __( 'Tax', 'woocommerce-gateway-stripe' ), |
|
659 | + 'label' => __('Tax', 'woocommerce-gateway-stripe'), |
|
660 | 660 | 'amount' => array( |
661 | 661 | 'currency' => $currency, |
662 | 662 | 'value' => $tax_total, |
@@ -664,7 +664,7 @@ discard block |
||
664 | 664 | ); |
665 | 665 | } |
666 | 666 | |
667 | - wp_send_json( array( 'success' => 'true', 'line_items' => $this->build_line_items(), 'total' => WC()->cart->total ) ); |
|
667 | + wp_send_json(array('success' => 'true', 'line_items' => $this->build_line_items(), 'total' => WC()->cart->total)); |
|
668 | 668 | } |
669 | 669 | |
670 | 670 | /** |
@@ -675,37 +675,37 @@ discard block |
||
675 | 675 | * @version 3.1.0 |
676 | 676 | */ |
677 | 677 | public function process_apple_pay() { |
678 | - if ( ! wp_verify_nonce( $_POST['nonce'], '_wc_stripe_apple_pay_nonce' ) ) { |
|
679 | - wp_die( __( 'Cheatin’ huh?', 'woocommerce-gateway-stripe' ) ); |
|
678 | + if ( ! wp_verify_nonce($_POST['nonce'], '_wc_stripe_apple_pay_nonce')) { |
|
679 | + wp_die(__('Cheatin’ huh?', 'woocommerce-gateway-stripe')); |
|
680 | 680 | } |
681 | 681 | |
682 | 682 | try { |
683 | - $result = array_map( 'wc_clean', $_POST['result'] ); |
|
683 | + $result = array_map('wc_clean', $_POST['result']); |
|
684 | 684 | |
685 | - $order = $this->create_order( $result ); |
|
685 | + $order = $this->create_order($result); |
|
686 | 686 | |
687 | - $order_id = version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->id : $order->get_id(); |
|
687 | + $order_id = version_compare(WC_VERSION, '3.0.0', '<') ? $order->id : $order->get_id(); |
|
688 | 688 | |
689 | 689 | // Handle payment. |
690 | - if ( $order->get_total() > 0 ) { |
|
690 | + if ($order->get_total() > 0) { |
|
691 | 691 | |
692 | - if ( $order->get_total() * 100 < WC_Stripe::get_minimum_amount() ) { |
|
693 | - 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 ) ) ); |
|
692 | + if ($order->get_total() * 100 < WC_Stripe::get_minimum_amount()) { |
|
693 | + 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))); |
|
694 | 694 | } |
695 | 695 | |
696 | - $this->log( "Info: Begin processing payment for order {$order_id} for the amount of {$order->get_total()}" ); |
|
696 | + $this->log("Info: Begin processing payment for order {$order_id} for the amount of {$order->get_total()}"); |
|
697 | 697 | |
698 | 698 | // Make the request. |
699 | - $response = WC_Stripe_API::request( $this->generate_payment_request( $order, $result['token']['id'] ) ); |
|
699 | + $response = WC_Stripe_API::request($this->generate_payment_request($order, $result['token']['id'])); |
|
700 | 700 | |
701 | - if ( is_wp_error( $response ) ) { |
|
701 | + if (is_wp_error($response)) { |
|
702 | 702 | $localized_messages = $this->get_localized_messages(); |
703 | 703 | |
704 | - throw new Exception( ( isset( $localized_messages[ $response->get_error_code() ] ) ? $localized_messages[ $response->get_error_code() ] : $response->get_error_message() ) ); |
|
704 | + throw new Exception((isset($localized_messages[$response->get_error_code()]) ? $localized_messages[$response->get_error_code()] : $response->get_error_message())); |
|
705 | 705 | } |
706 | 706 | |
707 | 707 | // Process valid response. |
708 | - $this->process_response( $response, $order ); |
|
708 | + $this->process_response($response, $order); |
|
709 | 709 | } else { |
710 | 710 | $order->payment_complete(); |
711 | 711 | } |
@@ -713,24 +713,24 @@ discard block |
||
713 | 713 | // Remove cart. |
714 | 714 | WC()->cart->empty_cart(); |
715 | 715 | |
716 | - update_post_meta( $order_id, '_customer_user', get_current_user_id() ); |
|
717 | - update_post_meta( $order_id, '_payment_method_title', 'Apple Pay (Stripe)' ); |
|
716 | + update_post_meta($order_id, '_customer_user', get_current_user_id()); |
|
717 | + update_post_meta($order_id, '_payment_method_title', 'Apple Pay (Stripe)'); |
|
718 | 718 | |
719 | 719 | // Return thank you page redirect. |
720 | - wp_send_json( array( |
|
720 | + wp_send_json(array( |
|
721 | 721 | 'success' => 'true', |
722 | - 'redirect' => $this->get_return_url( $order ), |
|
723 | - ) ); |
|
722 | + 'redirect' => $this->get_return_url($order), |
|
723 | + )); |
|
724 | 724 | |
725 | - } catch ( Exception $e ) { |
|
726 | - WC()->session->set( 'refresh_totals', true ); |
|
727 | - $this->log( sprintf( __( 'Error: %s', 'woocommerce-gateway-stripe' ), $e->getMessage() ) ); |
|
725 | + } catch (Exception $e) { |
|
726 | + WC()->session->set('refresh_totals', true); |
|
727 | + $this->log(sprintf(__('Error: %s', 'woocommerce-gateway-stripe'), $e->getMessage())); |
|
728 | 728 | |
729 | - if ( is_object( $order ) && isset( $order_id ) && $order->has_status( array( 'pending', 'failed' ) ) ) { |
|
730 | - $this->send_failed_order_email( $order_id ); |
|
729 | + if (is_object($order) && isset($order_id) && $order->has_status(array('pending', 'failed'))) { |
|
730 | + $this->send_failed_order_email($order_id); |
|
731 | 731 | } |
732 | 732 | |
733 | - wp_send_json( array( 'success' => 'false', 'msg' => $e->getMessage() ) ); |
|
733 | + wp_send_json(array('success' => 'false', 'msg' => $e->getMessage())); |
|
734 | 734 | } |
735 | 735 | } |
736 | 736 | |
@@ -740,16 +740,16 @@ discard block |
||
740 | 740 | * @param string $source token |
741 | 741 | * @return array() |
742 | 742 | */ |
743 | - protected function generate_payment_request( $order, $source ) { |
|
743 | + protected function generate_payment_request($order, $source) { |
|
744 | 744 | $post_data = array(); |
745 | - $post_data['currency'] = strtolower( version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->get_order_currency() : $order->get_currency() ); |
|
746 | - $post_data['amount'] = $this->get_stripe_amount( $order->get_total(), $post_data['currency'] ); |
|
747 | - $post_data['description'] = sprintf( __( '%1$s - Order %2$s', 'woocommerce-gateway-stripe' ), $this->statement_descriptor, $order->get_order_number() ); |
|
745 | + $post_data['currency'] = strtolower(version_compare(WC_VERSION, '3.0.0', '<') ? $order->get_order_currency() : $order->get_currency()); |
|
746 | + $post_data['amount'] = $this->get_stripe_amount($order->get_total(), $post_data['currency']); |
|
747 | + $post_data['description'] = sprintf(__('%1$s - Order %2$s', 'woocommerce-gateway-stripe'), $this->statement_descriptor, $order->get_order_number()); |
|
748 | 748 | $post_data['capture'] = $this->capture ? 'true' : 'false'; |
749 | 749 | |
750 | - $billing_email = version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->billing_email : $order->get_billing_email(); |
|
750 | + $billing_email = version_compare(WC_VERSION, '3.0.0', '<') ? $order->billing_email : $order->get_billing_email(); |
|
751 | 751 | |
752 | - if ( ! empty( $billing_email ) && apply_filters( 'wc_stripe_send_stripe_receipt', false ) ) { |
|
752 | + if ( ! empty($billing_email) && apply_filters('wc_stripe_send_stripe_receipt', false)) { |
|
753 | 753 | $post_data['receipt_email'] = $billing_email; |
754 | 754 | } |
755 | 755 | |
@@ -764,7 +764,7 @@ discard block |
||
764 | 764 | * @param WC_Order $order |
765 | 765 | * @param object $source |
766 | 766 | */ |
767 | - return apply_filters( 'wc_stripe_generate_payment_request', $post_data, $order ); |
|
767 | + return apply_filters('wc_stripe_generate_payment_request', $post_data, $order); |
|
768 | 768 | } |
769 | 769 | |
770 | 770 | /** |
@@ -773,14 +773,14 @@ discard block |
||
773 | 773 | * @since 3.1.0 |
774 | 774 | * @version 3.1.0 |
775 | 775 | */ |
776 | - public function build_shipping_methods( $shipping_methods ) { |
|
777 | - if ( empty( $shipping_methods ) ) { |
|
776 | + public function build_shipping_methods($shipping_methods) { |
|
777 | + if (empty($shipping_methods)) { |
|
778 | 778 | return array(); |
779 | 779 | } |
780 | 780 | |
781 | 781 | $shipping = array(); |
782 | 782 | |
783 | - foreach ( $shipping_methods as $method ) { |
|
783 | + foreach ($shipping_methods as $method) { |
|
784 | 784 | $shipping[] = array( |
785 | 785 | 'label' => $method['label'], |
786 | 786 | 'detail' => '', |
@@ -799,65 +799,65 @@ discard block |
||
799 | 799 | * @version 3.1.0 |
800 | 800 | */ |
801 | 801 | public function build_line_items() { |
802 | - if ( ! defined( 'WOOCOMMERCE_CART' ) ) { |
|
803 | - define( 'WOOCOMMERCE_CART', true ); |
|
802 | + if ( ! defined('WOOCOMMERCE_CART')) { |
|
803 | + define('WOOCOMMERCE_CART', true); |
|
804 | 804 | } |
805 | 805 | |
806 | - $decimals = apply_filters( 'wc_stripe_apple_pay_decimals', 2 ); |
|
806 | + $decimals = apply_filters('wc_stripe_apple_pay_decimals', 2); |
|
807 | 807 | |
808 | 808 | $items = array(); |
809 | 809 | $subtotal = 0; |
810 | 810 | |
811 | - foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) { |
|
812 | - $amount = wc_format_decimal( $cart_item['line_subtotal'], $decimals ); |
|
813 | - $subtotal += $cart_item['line_subtotal']; |
|
811 | + foreach (WC()->cart->get_cart() as $cart_item_key => $cart_item) { |
|
812 | + $amount = wc_format_decimal($cart_item['line_subtotal'], $decimals); |
|
813 | + $subtotal += $cart_item['line_subtotal']; |
|
814 | 814 | $quantity_label = 1 < $cart_item['quantity'] ? ' (x' . $cart_item['quantity'] . ')' : ''; |
815 | 815 | |
816 | 816 | $item = array( |
817 | 817 | 'type' => 'final', |
818 | 818 | 'label' => $cart_item['data']->post->post_title . $quantity_label, |
819 | - 'amount' => wc_format_decimal( $amount, $decimals ), |
|
819 | + 'amount' => wc_format_decimal($amount, $decimals), |
|
820 | 820 | ); |
821 | 821 | |
822 | 822 | $items[] = $item; |
823 | 823 | } |
824 | 824 | |
825 | 825 | // Default show only subtotal instead of itemization. |
826 | - if ( apply_filters( 'wc_stripe_apple_pay_disable_itemization', true ) ) { |
|
826 | + if (apply_filters('wc_stripe_apple_pay_disable_itemization', true)) { |
|
827 | 827 | $items = array(); |
828 | 828 | $items[] = array( |
829 | 829 | 'type' => 'final', |
830 | - 'label' => esc_html( __( 'Sub-Total', 'woocommerce-gateway-stripe' ) ), |
|
831 | - 'amount' => wc_format_decimal( $subtotal, $decimals ), |
|
830 | + 'label' => esc_html(__('Sub-Total', 'woocommerce-gateway-stripe')), |
|
831 | + 'amount' => wc_format_decimal($subtotal, $decimals), |
|
832 | 832 | ); |
833 | 833 | } |
834 | 834 | |
835 | - $discounts = wc_format_decimal( WC()->cart->get_cart_discount_total(), $decimals ); |
|
836 | - $tax = wc_format_decimal( WC()->cart->tax_total + WC()->cart->shipping_tax_total, $decimals ); |
|
837 | - $shipping = wc_format_decimal( WC()->cart->shipping_total, $decimals ); |
|
838 | - $item_total = wc_format_decimal( WC()->cart->cart_contents_total, $decimals ) + $discounts; |
|
839 | - $order_total = wc_format_decimal( $item_total + $tax + $shipping, $decimals ); |
|
835 | + $discounts = wc_format_decimal(WC()->cart->get_cart_discount_total(), $decimals); |
|
836 | + $tax = wc_format_decimal(WC()->cart->tax_total + WC()->cart->shipping_tax_total, $decimals); |
|
837 | + $shipping = wc_format_decimal(WC()->cart->shipping_total, $decimals); |
|
838 | + $item_total = wc_format_decimal(WC()->cart->cart_contents_total, $decimals) + $discounts; |
|
839 | + $order_total = wc_format_decimal($item_total + $tax + $shipping, $decimals); |
|
840 | 840 | |
841 | - if ( wc_tax_enabled() ) { |
|
841 | + if (wc_tax_enabled()) { |
|
842 | 842 | $items[] = array( |
843 | 843 | 'type' => 'final', |
844 | - 'label' => esc_html( __( 'Tax', 'woocommerce-gateway-stripe' ) ), |
|
844 | + 'label' => esc_html(__('Tax', 'woocommerce-gateway-stripe')), |
|
845 | 845 | 'amount' => $tax, |
846 | 846 | ); |
847 | 847 | } |
848 | 848 | |
849 | - if ( WC()->cart->needs_shipping() ) { |
|
849 | + if (WC()->cart->needs_shipping()) { |
|
850 | 850 | $items[] = array( |
851 | 851 | 'type' => 'final', |
852 | - 'label' => esc_html( __( 'Shipping', 'woocommerce-gateway-stripe' ) ), |
|
852 | + 'label' => esc_html(__('Shipping', 'woocommerce-gateway-stripe')), |
|
853 | 853 | 'amount' => $shipping, |
854 | 854 | ); |
855 | 855 | } |
856 | 856 | |
857 | - if ( WC()->cart->has_discount() ) { |
|
857 | + if (WC()->cart->has_discount()) { |
|
858 | 858 | $items[] = array( |
859 | 859 | 'type' => 'final', |
860 | - 'label' => esc_html( __( 'Discount', 'woocommerce-gateway-stripe' ) ), |
|
860 | + 'label' => esc_html(__('Discount', 'woocommerce-gateway-stripe')), |
|
861 | 861 | 'amount' => '-' . $discounts, |
862 | 862 | ); |
863 | 863 | } |
@@ -873,24 +873,24 @@ discard block |
||
873 | 873 | * @param array $data |
874 | 874 | * @return object $order |
875 | 875 | */ |
876 | - public function create_order( $data = array() ) { |
|
877 | - if ( empty( $data ) ) { |
|
878 | - throw new Exception( sprintf( __( 'Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe' ), 520 ) ); |
|
876 | + public function create_order($data = array()) { |
|
877 | + if (empty($data)) { |
|
878 | + throw new Exception(sprintf(__('Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe'), 520)); |
|
879 | 879 | } |
880 | 880 | |
881 | 881 | $order = wc_create_order(); |
882 | - $order_id = version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->id : $order->get_id(); |
|
882 | + $order_id = version_compare(WC_VERSION, '3.0.0', '<') ? $order->id : $order->get_id(); |
|
883 | 883 | |
884 | - if ( is_wp_error( $order ) ) { |
|
885 | - throw new Exception( sprintf( __( 'Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe' ), 520 ) ); |
|
886 | - } elseif ( false === $order ) { |
|
887 | - throw new Exception( sprintf( __( 'Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe' ), 521 ) ); |
|
884 | + if (is_wp_error($order)) { |
|
885 | + throw new Exception(sprintf(__('Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe'), 520)); |
|
886 | + } elseif (false === $order) { |
|
887 | + throw new Exception(sprintf(__('Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe'), 521)); |
|
888 | 888 | } else { |
889 | - do_action( 'woocommerce_new_order', $order_id ); |
|
889 | + do_action('woocommerce_new_order', $order_id); |
|
890 | 890 | } |
891 | 891 | |
892 | 892 | // Store the line items to the new/resumed order |
893 | - foreach ( WC()->cart->get_cart() as $cart_item_key => $values ) { |
|
893 | + foreach (WC()->cart->get_cart() as $cart_item_key => $values) { |
|
894 | 894 | $item_id = $order->add_product( |
895 | 895 | $values['data'], |
896 | 896 | $values['quantity'], |
@@ -906,25 +906,25 @@ discard block |
||
906 | 906 | ) |
907 | 907 | ); |
908 | 908 | |
909 | - if ( ! $item_id ) { |
|
910 | - throw new Exception( sprintf( __( 'Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe' ), 525 ) ); |
|
909 | + if ( ! $item_id) { |
|
910 | + throw new Exception(sprintf(__('Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe'), 525)); |
|
911 | 911 | } |
912 | 912 | |
913 | 913 | // Allow plugins to add order item meta |
914 | - if ( version_compare( WC_VERSION, '3.0', '<' ) ) { |
|
915 | - do_action( 'woocommerce_add_order_item_meta', $item_id, $values, $cart_item_key ); |
|
914 | + if (version_compare(WC_VERSION, '3.0', '<')) { |
|
915 | + do_action('woocommerce_add_order_item_meta', $item_id, $values, $cart_item_key); |
|
916 | 916 | } else { |
917 | - do_action( 'woocommerce_new_order_item', $item_id, wc_get_product( $item_id ), $order->get_id() ); |
|
917 | + do_action('woocommerce_new_order_item', $item_id, wc_get_product($item_id), $order->get_id()); |
|
918 | 918 | } |
919 | 919 | } |
920 | 920 | |
921 | 921 | // Store fees |
922 | - foreach ( WC()->cart->get_fees() as $fee_key => $fee ) { |
|
923 | - if ( version_compare( WC_VERSION, '3.0', '<' ) ) { |
|
924 | - $item_id = $order->add_fee( $fee ); |
|
922 | + foreach (WC()->cart->get_fees() as $fee_key => $fee) { |
|
923 | + if (version_compare(WC_VERSION, '3.0', '<')) { |
|
924 | + $item_id = $order->add_fee($fee); |
|
925 | 925 | } else { |
926 | 926 | $item = new WC_Order_Item_Fee(); |
927 | - $item->set_props( array( |
|
927 | + $item->set_props(array( |
|
928 | 928 | 'name' => $fee->name, |
929 | 929 | 'tax_class' => $fee->taxable ? $fee->tax_class : 0, |
930 | 930 | 'total' => $fee->amount, |
@@ -933,79 +933,79 @@ discard block |
||
933 | 933 | 'total' => $fee->tax_data, |
934 | 934 | ), |
935 | 935 | 'order_id' => $order->get_id(), |
936 | - ) ); |
|
936 | + )); |
|
937 | 937 | $item_id = $item->save(); |
938 | - $order->add_item( $item ); |
|
938 | + $order->add_item($item); |
|
939 | 939 | } |
940 | 940 | |
941 | - if ( ! $item_id ) { |
|
942 | - throw new Exception( sprintf( __( 'Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe' ), 526 ) ); |
|
941 | + if ( ! $item_id) { |
|
942 | + throw new Exception(sprintf(__('Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe'), 526)); |
|
943 | 943 | } |
944 | 944 | |
945 | 945 | // Allow plugins to add order item meta to fees |
946 | - if ( version_compare( WC_VERSION, '3.0', '<' ) ) { |
|
947 | - do_action( 'woocommerce_add_order_fee_meta', $order_id, $item_id, $fee, $fee_key ); |
|
946 | + if (version_compare(WC_VERSION, '3.0', '<')) { |
|
947 | + do_action('woocommerce_add_order_fee_meta', $order_id, $item_id, $fee, $fee_key); |
|
948 | 948 | } else { |
949 | - do_action( 'woocommerce_new_order_item', $item_id, $fee, $order->get_id() ); |
|
949 | + do_action('woocommerce_new_order_item', $item_id, $fee, $order->get_id()); |
|
950 | 950 | } |
951 | 951 | } |
952 | 952 | |
953 | 953 | // Store tax rows |
954 | - foreach ( array_keys( WC()->cart->taxes + WC()->cart->shipping_taxes ) as $tax_rate_id ) { |
|
955 | - $tax_amount = WC()->cart->get_tax_amount( $tax_rate_id ); |
|
956 | - $shipping_tax_amount = WC()->cart->get_shipping_tax_amount( $tax_rate_id ); |
|
954 | + foreach (array_keys(WC()->cart->taxes + WC()->cart->shipping_taxes) as $tax_rate_id) { |
|
955 | + $tax_amount = WC()->cart->get_tax_amount($tax_rate_id); |
|
956 | + $shipping_tax_amount = WC()->cart->get_shipping_tax_amount($tax_rate_id); |
|
957 | 957 | |
958 | - if ( version_compare( WC_VERSION, '3.0', '<' ) ) { |
|
959 | - $item_id = $order->add_tax( $tax_rate_id, $tax_amount, $shipping_tax_amount ); |
|
958 | + if (version_compare(WC_VERSION, '3.0', '<')) { |
|
959 | + $item_id = $order->add_tax($tax_rate_id, $tax_amount, $shipping_tax_amount); |
|
960 | 960 | } else { |
961 | 961 | $item = new WC_Order_Item_Tax(); |
962 | - $item->set_props( array( |
|
962 | + $item->set_props(array( |
|
963 | 963 | 'rate_id' => $tax_rate_id, |
964 | 964 | 'tax_total' => $tax_amount, |
965 | 965 | 'shipping_tax_total' => $shipping_tax_amount, |
966 | - ) ); |
|
967 | - $item->set_rate( $tax_rate_id ); |
|
968 | - $item->set_order_id( $order->get_id() ); |
|
966 | + )); |
|
967 | + $item->set_rate($tax_rate_id); |
|
968 | + $item->set_order_id($order->get_id()); |
|
969 | 969 | $item_id = $item->save(); |
970 | - $order->add_item( $item ); |
|
970 | + $order->add_item($item); |
|
971 | 971 | } |
972 | 972 | |
973 | - if ( $tax_rate_id && ! $item_id && apply_filters( 'woocommerce_cart_remove_taxes_zero_rate_id', 'zero-rated' ) !== $tax_rate_id ) { |
|
974 | - throw new Exception( sprintf( __( 'Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe' ), 528 ) ); |
|
973 | + if ($tax_rate_id && ! $item_id && apply_filters('woocommerce_cart_remove_taxes_zero_rate_id', 'zero-rated') !== $tax_rate_id) { |
|
974 | + throw new Exception(sprintf(__('Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe'), 528)); |
|
975 | 975 | } |
976 | 976 | } |
977 | 977 | |
978 | 978 | // Store coupons |
979 | - $discount = WC()->cart->get_coupon_discount_amount( $code ); |
|
980 | - $discount_tax = WC()->cart->get_coupon_discount_tax_amount( $code ); |
|
979 | + $discount = WC()->cart->get_coupon_discount_amount($code); |
|
980 | + $discount_tax = WC()->cart->get_coupon_discount_tax_amount($code); |
|
981 | 981 | |
982 | - foreach ( WC()->cart->get_coupons() as $code => $coupon ) { |
|
983 | - if ( version_compare( WC_VERSION, '3.0', '<' ) ) { |
|
984 | - $coupon_id = $order->add_coupon( $code, $discount, $discount_tax ); |
|
982 | + foreach (WC()->cart->get_coupons() as $code => $coupon) { |
|
983 | + if (version_compare(WC_VERSION, '3.0', '<')) { |
|
984 | + $coupon_id = $order->add_coupon($code, $discount, $discount_tax); |
|
985 | 985 | } else { |
986 | 986 | $item = new WC_Order_Item_Coupon(); |
987 | - $item->set_props( array( |
|
987 | + $item->set_props(array( |
|
988 | 988 | 'code' => $code, |
989 | 989 | 'discount' => $discount, |
990 | 990 | 'discount_tax' => $discount_tax, |
991 | 991 | 'order_id' => $order->get_id(), |
992 | - ) ); |
|
992 | + )); |
|
993 | 993 | $coupon_id = $item->save(); |
994 | - $order->add_item( $item ); |
|
994 | + $order->add_item($item); |
|
995 | 995 | } |
996 | 996 | |
997 | - if ( ! $coupon_id ) { |
|
998 | - throw new Exception( sprintf( __( 'Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe' ), 529 ) ); |
|
997 | + if ( ! $coupon_id) { |
|
998 | + throw new Exception(sprintf(__('Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe'), 529)); |
|
999 | 999 | } |
1000 | 1000 | } |
1001 | 1001 | |
1002 | 1002 | // Billing address |
1003 | 1003 | $billing_address = array(); |
1004 | - if ( ! empty( $data['token']['card'] ) ) { |
|
1004 | + if ( ! empty($data['token']['card'])) { |
|
1005 | 1005 | // Name from Stripe is a full name string. |
1006 | - $name = explode( ' ', $data['token']['card']['name'] ); |
|
1007 | - $lastname = array_pop( $name ); |
|
1008 | - $firstname = implode( ' ', $name ); |
|
1006 | + $name = explode(' ', $data['token']['card']['name']); |
|
1007 | + $lastname = array_pop($name); |
|
1008 | + $firstname = implode(' ', $name); |
|
1009 | 1009 | $billing_address['first_name'] = $firstname; |
1010 | 1010 | $billing_address['last_name'] = $lastname; |
1011 | 1011 | $billing_address['email'] = $data['shippingContact']['emailAddress']; |
@@ -1020,7 +1020,7 @@ discard block |
||
1020 | 1020 | |
1021 | 1021 | // Shipping address. |
1022 | 1022 | $shipping_address = array(); |
1023 | - if ( WC()->cart->needs_shipping() && ! empty( $data['shippingContact'] ) ) { |
|
1023 | + if (WC()->cart->needs_shipping() && ! empty($data['shippingContact'])) { |
|
1024 | 1024 | $shipping_address['first_name'] = $data['shippingContact']['givenName']; |
1025 | 1025 | $shipping_address['last_name'] = $data['shippingContact']['familyName']; |
1026 | 1026 | $shipping_address['email'] = $data['shippingContact']['emailAddress']; |
@@ -1031,7 +1031,7 @@ discard block |
||
1031 | 1031 | $shipping_address['city'] = $data['shippingContact']['locality']; |
1032 | 1032 | $shipping_address['state'] = $data['shippingContact']['administrativeArea']; |
1033 | 1033 | $shipping_address['postcode'] = $data['shippingContact']['postalCode']; |
1034 | - } elseif ( ! empty( $data['shippingContact'] ) ) { |
|
1034 | + } elseif ( ! empty($data['shippingContact'])) { |
|
1035 | 1035 | $shipping_address['first_name'] = $firstname; |
1036 | 1036 | $shipping_address['last_name'] = $lastname; |
1037 | 1037 | $shipping_address['email'] = $data['shippingContact']['emailAddress']; |
@@ -1044,33 +1044,33 @@ discard block |
||
1044 | 1044 | $shipping_address['postcode'] = $data['token']['card']['address_zip']; |
1045 | 1045 | } |
1046 | 1046 | |
1047 | - $order->set_address( $billing_address, 'billing' ); |
|
1048 | - $order->set_address( $shipping_address, 'shipping' ); |
|
1047 | + $order->set_address($billing_address, 'billing'); |
|
1048 | + $order->set_address($shipping_address, 'shipping'); |
|
1049 | 1049 | |
1050 | - WC()->shipping->calculate_shipping( WC()->cart->get_shipping_packages() ); |
|
1050 | + WC()->shipping->calculate_shipping(WC()->cart->get_shipping_packages()); |
|
1051 | 1051 | |
1052 | 1052 | // Get the rate object selected by user. |
1053 | - foreach ( WC()->shipping->get_packages() as $package_key => $package ) { |
|
1054 | - foreach ( $package['rates'] as $key => $rate ) { |
|
1053 | + foreach (WC()->shipping->get_packages() as $package_key => $package) { |
|
1054 | + foreach ($package['rates'] as $key => $rate) { |
|
1055 | 1055 | // Loop through user chosen shipping methods. |
1056 | - foreach ( WC()->session->get( 'chosen_shipping_methods' ) as $method ) { |
|
1057 | - if ( $method === $key ) { |
|
1058 | - if ( version_compare( WC_VERSION, '3.0', '<' ) ) { |
|
1059 | - $order->add_shipping( $rate ); |
|
1056 | + foreach (WC()->session->get('chosen_shipping_methods') as $method) { |
|
1057 | + if ($method === $key) { |
|
1058 | + if (version_compare(WC_VERSION, '3.0', '<')) { |
|
1059 | + $order->add_shipping($rate); |
|
1060 | 1060 | } else { |
1061 | 1061 | $item = new WC_Order_Item_Shipping(); |
1062 | - $item->set_props( array( |
|
1062 | + $item->set_props(array( |
|
1063 | 1063 | 'method_title' => $rate->label, |
1064 | 1064 | 'method_id' => $rate->id, |
1065 | - 'total' => wc_format_decimal( $rate->cost ), |
|
1065 | + 'total' => wc_format_decimal($rate->cost), |
|
1066 | 1066 | 'taxes' => $rate->taxes, |
1067 | 1067 | 'order_id' => $order->get_id(), |
1068 | - ) ); |
|
1069 | - foreach ( $rate->get_meta_data() as $key => $value ) { |
|
1070 | - $item->add_meta_data( $key, $value, true ); |
|
1068 | + )); |
|
1069 | + foreach ($rate->get_meta_data() as $key => $value) { |
|
1070 | + $item->add_meta_data($key, $value, true); |
|
1071 | 1071 | } |
1072 | 1072 | $item->save(); |
1073 | - $order->add_item( $item ); |
|
1073 | + $order->add_item($item); |
|
1074 | 1074 | } |
1075 | 1075 | } |
1076 | 1076 | } |
@@ -1078,16 +1078,16 @@ discard block |
||
1078 | 1078 | } |
1079 | 1079 | |
1080 | 1080 | $available_gateways = WC()->payment_gateways->get_available_payment_gateways(); |
1081 | - $order->set_payment_method( $available_gateways['stripe'] ); |
|
1082 | - $order->set_total( WC()->cart->shipping_total, 'shipping' ); |
|
1083 | - $order->set_total( WC()->cart->get_cart_discount_total(), 'cart_discount' ); |
|
1084 | - $order->set_total( WC()->cart->get_cart_discount_tax_total(), 'cart_discount_tax' ); |
|
1085 | - $order->set_total( WC()->cart->tax_total, 'tax' ); |
|
1086 | - $order->set_total( WC()->cart->shipping_tax_total, 'shipping_tax' ); |
|
1087 | - $order->set_total( WC()->cart->total ); |
|
1081 | + $order->set_payment_method($available_gateways['stripe']); |
|
1082 | + $order->set_total(WC()->cart->shipping_total, 'shipping'); |
|
1083 | + $order->set_total(WC()->cart->get_cart_discount_total(), 'cart_discount'); |
|
1084 | + $order->set_total(WC()->cart->get_cart_discount_tax_total(), 'cart_discount_tax'); |
|
1085 | + $order->set_total(WC()->cart->tax_total, 'tax'); |
|
1086 | + $order->set_total(WC()->cart->shipping_tax_total, 'shipping_tax'); |
|
1087 | + $order->set_total(WC()->cart->total); |
|
1088 | 1088 | |
1089 | 1089 | // If we got here, the order was created without problems! |
1090 | - wc_transaction_query( 'commit' ); |
|
1090 | + wc_transaction_query('commit'); |
|
1091 | 1091 | |
1092 | 1092 | return $order; |
1093 | 1093 | } |
@@ -1100,9 +1100,9 @@ discard block |
||
1100 | 1100 | * |
1101 | 1101 | * @param string $message |
1102 | 1102 | */ |
1103 | - public function log( $message ) { |
|
1104 | - if ( $this->logging ) { |
|
1105 | - WC_Stripe::log( 'Apple Pay: ' . $message ); |
|
1103 | + public function log($message) { |
|
1104 | + if ($this->logging) { |
|
1105 | + WC_Stripe::log('Apple Pay: ' . $message); |
|
1106 | 1106 | } |
1107 | 1107 | } |
1108 | 1108 | } |