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