Completed
Pull Request — master (#867)
by Radoslav
02:32
created
includes/class-wc-gateway-stripe.php 1 patch
Spacing   +268 added lines, -268 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) {
2
+if ( ! defined('ABSPATH')) {
3 3
 	exit;
4 4
 }
5 5
 
@@ -85,9 +85,9 @@  discard block
 block discarded – undo
85 85
 	public function __construct() {
86 86
 		$this->retry_interval = 1;
87 87
 		$this->id             = 'stripe';
88
-		$this->method_title   = __( 'Stripe', 'woocommerce-gateway-stripe' );
88
+		$this->method_title   = __('Stripe', 'woocommerce-gateway-stripe');
89 89
 		/* translators: 1) link to Stripe register page 2) link to Stripe api keys page */
90
-		$this->method_description = sprintf( __( 'Stripe works by adding payment fields on the checkout and then sending the details to Stripe for verification. <a href="%1$s" target="_blank">Sign up</a> for a Stripe account, and <a href="%2$s" target="_blank">get your Stripe account keys</a>.', 'woocommerce-gateway-stripe' ), 'https://dashboard.stripe.com/register', 'https://dashboard.stripe.com/account/apikeys' );
90
+		$this->method_description = sprintf(__('Stripe works by adding payment fields on the checkout and then sending the details to Stripe for verification. <a href="%1$s" target="_blank">Sign up</a> for a Stripe account, and <a href="%2$s" target="_blank">get your Stripe account keys</a>.', 'woocommerce-gateway-stripe'), 'https://dashboard.stripe.com/register', 'https://dashboard.stripe.com/account/apikeys');
91 91
 		$this->has_fields         = true;
92 92
 		$this->supports           = array(
93 93
 			'products',
@@ -114,35 +114,35 @@  discard block
 block discarded – undo
114 114
 		$this->init_settings();
115 115
 
116 116
 		// Get setting values.
117
-		$this->title                = $this->get_option( 'title' );
118
-		$this->description          = $this->get_option( 'description' );
119
-		$this->enabled              = $this->get_option( 'enabled' );
120
-		$this->testmode             = 'yes' === $this->get_option( 'testmode' );
121
-		$this->inline_cc_form       = 'yes' === $this->get_option( 'inline_cc_form' );
122
-		$this->capture              = 'yes' === $this->get_option( 'capture', 'yes' );
123
-		$this->statement_descriptor = WC_Stripe_Helper::clean_statement_descriptor( $this->get_option( 'statement_descriptor' ) );
124
-		$this->saved_cards          = 'yes' === $this->get_option( 'saved_cards' );
125
-		$this->secret_key           = $this->testmode ? $this->get_option( 'test_secret_key' ) : $this->get_option( 'secret_key' );
126
-		$this->publishable_key      = $this->testmode ? $this->get_option( 'test_publishable_key' ) : $this->get_option( 'publishable_key' );
127
-		$this->payment_request      = 'yes' === $this->get_option( 'payment_request', 'yes' );
128
-
129
-		WC_Stripe_API::set_secret_key( $this->secret_key );
117
+		$this->title                = $this->get_option('title');
118
+		$this->description          = $this->get_option('description');
119
+		$this->enabled              = $this->get_option('enabled');
120
+		$this->testmode             = 'yes' === $this->get_option('testmode');
121
+		$this->inline_cc_form       = 'yes' === $this->get_option('inline_cc_form');
122
+		$this->capture              = 'yes' === $this->get_option('capture', 'yes');
123
+		$this->statement_descriptor = WC_Stripe_Helper::clean_statement_descriptor($this->get_option('statement_descriptor'));
124
+		$this->saved_cards          = 'yes' === $this->get_option('saved_cards');
125
+		$this->secret_key           = $this->testmode ? $this->get_option('test_secret_key') : $this->get_option('secret_key');
126
+		$this->publishable_key      = $this->testmode ? $this->get_option('test_publishable_key') : $this->get_option('publishable_key');
127
+		$this->payment_request      = 'yes' === $this->get_option('payment_request', 'yes');
128
+
129
+		WC_Stripe_API::set_secret_key($this->secret_key);
130 130
 
131 131
 		// Hooks.
132
-		add_action( 'wp_enqueue_scripts', array( $this, 'payment_scripts' ) );
133
-		add_action( 'admin_enqueue_scripts', array( $this, 'admin_scripts' ) );
134
-		add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) );
135
-		add_action( 'woocommerce_admin_order_totals_after_total', array( $this, 'display_order_fee' ) );
136
-		add_action( 'woocommerce_admin_order_totals_after_total', array( $this, 'display_order_payout' ), 20 );
137
-		add_action( 'woocommerce_customer_save_address', array( $this, 'show_update_card_notice' ), 10, 2 );
138
-		add_filter( 'woocommerce_available_payment_gateways', array( $this, 'prepare_order_pay_page' ) );
139
-		add_action( 'woocommerce_account_view-order_endpoint', array( $this, 'check_intent_status_on_order_page' ), 1 );
140
-		add_filter( 'woocommerce_payment_successful_result', array( $this, 'modify_successful_payment_result' ), 99999, 2 );
141
-
142
-		if ( WC_Stripe_Helper::is_pre_orders_exists() ) {
132
+		add_action('wp_enqueue_scripts', array($this, 'payment_scripts'));
133
+		add_action('admin_enqueue_scripts', array($this, 'admin_scripts'));
134
+		add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options'));
135
+		add_action('woocommerce_admin_order_totals_after_total', array($this, 'display_order_fee'));
136
+		add_action('woocommerce_admin_order_totals_after_total', array($this, 'display_order_payout'), 20);
137
+		add_action('woocommerce_customer_save_address', array($this, 'show_update_card_notice'), 10, 2);
138
+		add_filter('woocommerce_available_payment_gateways', array($this, 'prepare_order_pay_page'));
139
+		add_action('woocommerce_account_view-order_endpoint', array($this, 'check_intent_status_on_order_page'), 1);
140
+		add_filter('woocommerce_payment_successful_result', array($this, 'modify_successful_payment_result'), 99999, 2);
141
+
142
+		if (WC_Stripe_Helper::is_pre_orders_exists()) {
143 143
 			$this->pre_orders = new WC_Stripe_Pre_Orders_Compat();
144 144
 
145
-			add_action( 'wc_pre_orders_process_pre_order_completion_payment_' . $this->id, array( $this->pre_orders, 'process_pre_order_release_payment' ) );
145
+			add_action('wc_pre_orders_process_pre_order_completion_payment_' . $this->id, array($this->pre_orders, 'process_pre_order_release_payment'));
146 146
 		}
147 147
 	}
148 148
 
@@ -153,7 +153,7 @@  discard block
 block discarded – undo
153 153
 	 * @return bool
154 154
 	 */
155 155
 	public function are_keys_set() {
156
-		if ( empty( $this->secret_key ) || empty( $this->publishable_key ) ) {
156
+		if (empty($this->secret_key) || empty($this->publishable_key)) {
157 157
 			return false;
158 158
 		}
159 159
 
@@ -166,7 +166,7 @@  discard block
 block discarded – undo
166 166
 	 * @since 4.0.2
167 167
 	 */
168 168
 	public function is_available() {
169
-		if ( is_add_payment_method_page() && ! $this->saved_cards ) {
169
+		if (is_add_payment_method_page() && ! $this->saved_cards) {
170 170
 			return false;
171 171
 		}
172 172
 
@@ -180,13 +180,13 @@  discard block
 block discarded – undo
180 180
 	 * @param int    $user_id      The ID of the current user.
181 181
 	 * @param string $load_address The address to load.
182 182
 	 */
183
-	public function show_update_card_notice( $user_id, $load_address ) {
184
-		if ( ! $this->saved_cards || ! WC_Stripe_Payment_Tokens::customer_has_saved_methods( $user_id ) || 'billing' !== $load_address ) {
183
+	public function show_update_card_notice($user_id, $load_address) {
184
+		if ( ! $this->saved_cards || ! WC_Stripe_Payment_Tokens::customer_has_saved_methods($user_id) || 'billing' !== $load_address) {
185 185
 			return;
186 186
 		}
187 187
 
188 188
 		/* translators: 1) Opening anchor tag 2) closing anchor tag */
189
-		wc_add_notice( sprintf( __( 'If your billing address has been changed for saved payment methods, be sure to remove any %1$ssaved payment methods%2$s on file and re-add them.', 'woocommerce-gateway-stripe' ), '<a href="' . esc_url( wc_get_endpoint_url( 'payment-methods' ) ) . '" class="wc-stripe-update-card-notice" style="text-decoration:underline;">', '</a>' ), 'notice' );
189
+		wc_add_notice(sprintf(__('If your billing address has been changed for saved payment methods, be sure to remove any %1$ssaved payment methods%2$s on file and re-add them.', 'woocommerce-gateway-stripe'), '<a href="' . esc_url(wc_get_endpoint_url('payment-methods')) . '" class="wc-stripe-update-card-notice" style="text-decoration:underline;">', '</a>'), 'notice');
190 190
 	}
191 191
 
192 192
 	/**
@@ -201,31 +201,31 @@  discard block
 block discarded – undo
201 201
 
202 202
 		$icons_str = '';
203 203
 
204
-		$icons_str .= isset( $icons['visa'] ) ? $icons['visa'] : '';
205
-		$icons_str .= isset( $icons['amex'] ) ? $icons['amex'] : '';
206
-		$icons_str .= isset( $icons['mastercard'] ) ? $icons['mastercard'] : '';
204
+		$icons_str .= isset($icons['visa']) ? $icons['visa'] : '';
205
+		$icons_str .= isset($icons['amex']) ? $icons['amex'] : '';
206
+		$icons_str .= isset($icons['mastercard']) ? $icons['mastercard'] : '';
207 207
 
208
-		if ( 'USD' === get_woocommerce_currency() ) {
209
-			$icons_str .= isset( $icons['discover'] ) ? $icons['discover'] : '';
210
-			$icons_str .= isset( $icons['jcb'] ) ? $icons['jcb'] : '';
211
-			$icons_str .= isset( $icons['diners'] ) ? $icons['diners'] : '';
208
+		if ('USD' === get_woocommerce_currency()) {
209
+			$icons_str .= isset($icons['discover']) ? $icons['discover'] : '';
210
+			$icons_str .= isset($icons['jcb']) ? $icons['jcb'] : '';
211
+			$icons_str .= isset($icons['diners']) ? $icons['diners'] : '';
212 212
 		}
213 213
 
214
-		return apply_filters( 'woocommerce_gateway_icon', $icons_str, $this->id );
214
+		return apply_filters('woocommerce_gateway_icon', $icons_str, $this->id);
215 215
 	}
216 216
 
217 217
 	/**
218 218
 	 * Initialise Gateway Settings Form Fields
219 219
 	 */
220 220
 	public function init_form_fields() {
221
-		$this->form_fields = require( dirname( __FILE__ ) . '/admin/stripe-settings.php' );
221
+		$this->form_fields = require(dirname(__FILE__) . '/admin/stripe-settings.php');
222 222
 
223
-		if ( 'yes' === $this->get_option( 'three_d_secure' ) ) {
224
-			if ( isset( $_REQUEST['stripe_dismiss_3ds'] ) && wp_verify_nonce( $_REQUEST['stripe_dismiss_3ds'], 'no-3ds' ) ) { // wpcs: sanitization ok.
225
-				$this->update_option( '3ds_setting_notice_dismissed', true );
223
+		if ('yes' === $this->get_option('three_d_secure')) {
224
+			if (isset($_REQUEST['stripe_dismiss_3ds']) && wp_verify_nonce($_REQUEST['stripe_dismiss_3ds'], 'no-3ds')) { // wpcs: sanitization ok.
225
+				$this->update_option('3ds_setting_notice_dismissed', true);
226 226
 			}
227 227
 
228
-			add_action( 'admin_notices', array( $this, 'display_three_d_secure_notice' ) );
228
+			add_action('admin_notices', array($this, 'display_three_d_secure_notice'));
229 229
 		}
230 230
 	}
231 231
 
@@ -234,34 +234,34 @@  discard block
 block discarded – undo
234 234
 	 */
235 235
 	public function payment_fields() {
236 236
 		$user                 = wp_get_current_user();
237
-		$display_tokenization = $this->supports( 'tokenization' ) && is_checkout() && $this->saved_cards;
237
+		$display_tokenization = $this->supports('tokenization') && is_checkout() && $this->saved_cards;
238 238
 		$total                = WC()->cart->total;
239 239
 		$user_email           = '';
240 240
 		$description          = $this->get_description();
241
-		$description          = ! empty( $description ) ? $description : '';
241
+		$description          = ! empty($description) ? $description : '';
242 242
 		$firstname            = '';
243 243
 		$lastname             = '';
244 244
 
245 245
 		// If paying from order, we need to get total from order not cart.
246
-		if ( isset( $_GET['pay_for_order'] ) && ! empty( $_GET['key'] ) ) { // wpcs: csrf ok.
247
-			$order      = wc_get_order( wc_get_order_id_by_order_key( wc_clean( $_GET['key'] ) ) ); // wpcs: csrf ok, sanitization ok.
246
+		if (isset($_GET['pay_for_order']) && ! empty($_GET['key'])) { // wpcs: csrf ok.
247
+			$order      = wc_get_order(wc_get_order_id_by_order_key(wc_clean($_GET['key']))); // wpcs: csrf ok, sanitization ok.
248 248
 			$total      = $order->get_total();
249
-			$user_email = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->billing_email : $order->get_billing_email();
249
+			$user_email = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->billing_email : $order->get_billing_email();
250 250
 		} else {
251
-			if ( $user->ID ) {
252
-				$user_email = get_user_meta( $user->ID, 'billing_email', true );
251
+			if ($user->ID) {
252
+				$user_email = get_user_meta($user->ID, 'billing_email', true);
253 253
 				$user_email = $user_email ? $user_email : $user->user_email;
254 254
 			}
255 255
 		}
256 256
 
257
-		if ( is_add_payment_method_page() ) {
258
-			$pay_button_text = __( 'Add Card', 'woocommerce-gateway-stripe' );
257
+		if (is_add_payment_method_page()) {
258
+			$pay_button_text = __('Add Card', 'woocommerce-gateway-stripe');
259 259
 			$total           = '';
260 260
 			$firstname       = $user->user_firstname;
261 261
 			$lastname        = $user->user_lastname;
262 262
 
263
-		} elseif ( function_exists( 'wcs_order_contains_subscription' ) && isset( $_GET['change_payment_method'] ) ) { // wpcs: csrf ok.
264
-			$pay_button_text = __( 'Change Payment Method', 'woocommerce-gateway-stripe' );
263
+		} elseif (function_exists('wcs_order_contains_subscription') && isset($_GET['change_payment_method'])) { // wpcs: csrf ok.
264
+			$pay_button_text = __('Change Payment Method', 'woocommerce-gateway-stripe');
265 265
 			$total           = '';
266 266
 		} else {
267 267
 			$pay_button_text = '';
@@ -271,37 +271,37 @@  discard block
 block discarded – undo
271 271
 
272 272
 		echo '<div
273 273
 			id="stripe-payment-data"
274
-			data-panel-label="' . esc_attr( $pay_button_text ) . '"
275
-			data-email="' . esc_attr( $user_email ) . '"
276
-			data-amount="' . esc_attr( WC_Stripe_Helper::get_stripe_amount( $total ) ) . '"
277
-			data-name="' . esc_attr( $this->statement_descriptor ) . '"
278
-			data-full-name="' . esc_attr( $firstname . ' ' . $lastname ) . '"
279
-			data-currency="' . esc_attr( strtolower( get_woocommerce_currency() ) ) . '"
280
-			data-allow-remember-me="' . esc_attr( apply_filters( 'wc_stripe_allow_remember_me', true ) ? 'true' : 'false' ) . '"
274
+			data-panel-label="' . esc_attr($pay_button_text) . '"
275
+			data-email="' . esc_attr($user_email) . '"
276
+			data-amount="' . esc_attr(WC_Stripe_Helper::get_stripe_amount($total)) . '"
277
+			data-name="' . esc_attr($this->statement_descriptor) . '"
278
+			data-full-name="' . esc_attr($firstname . ' ' . $lastname) . '"
279
+			data-currency="' . esc_attr(strtolower(get_woocommerce_currency())) . '"
280
+			data-allow-remember-me="' . esc_attr(apply_filters('wc_stripe_allow_remember_me', true) ? 'true' : 'false') . '"
281 281
 		>';
282 282
 
283
-		if ( $this->testmode ) {
283
+		if ($this->testmode) {
284 284
 			/* translators: link to Stripe testing page */
285
-			$description .= ' ' . sprintf( __( 'TEST MODE ENABLED. In test mode, you can use the card number 4242424242424242 with any CVC and a valid expiration date or check the <a href="%s" target="_blank">Testing Stripe documentation</a> for more card numbers.', 'woocommerce-gateway-stripe' ), 'https://stripe.com/docs/testing' );
285
+			$description .= ' ' . sprintf(__('TEST MODE ENABLED. In test mode, you can use the card number 4242424242424242 with any CVC and a valid expiration date or check the <a href="%s" target="_blank">Testing Stripe documentation</a> for more card numbers.', 'woocommerce-gateway-stripe'), 'https://stripe.com/docs/testing');
286 286
 		}
287 287
 
288
-		$description = trim( $description );
288
+		$description = trim($description);
289 289
 
290
-		echo apply_filters( 'wc_stripe_description', wpautop( wp_kses_post( $description ) ), $this->id ); // wpcs: xss ok.
290
+		echo apply_filters('wc_stripe_description', wpautop(wp_kses_post($description)), $this->id); // wpcs: xss ok.
291 291
 
292
-		if ( $display_tokenization ) {
292
+		if ($display_tokenization) {
293 293
 			$this->tokenization_script();
294 294
 			$this->saved_payment_methods();
295 295
 		}
296 296
 
297 297
 		$this->elements_form();
298 298
 
299
-		if ( apply_filters( 'wc_stripe_display_save_payment_method_checkbox', $display_tokenization ) && ! is_add_payment_method_page() && ! isset( $_GET['change_payment_method'] ) ) { // wpcs: csrf ok.
299
+		if (apply_filters('wc_stripe_display_save_payment_method_checkbox', $display_tokenization) && ! is_add_payment_method_page() && ! isset($_GET['change_payment_method'])) { // wpcs: csrf ok.
300 300
 
301 301
 			$this->save_payment_method_checkbox();
302 302
 		}
303 303
 
304
-		do_action( 'wc_stripe_cards_payment_fields', $this->id );
304
+		do_action('wc_stripe_cards_payment_fields', $this->id);
305 305
 
306 306
 		echo '</div>';
307 307
 
@@ -316,12 +316,12 @@  discard block
 block discarded – undo
316 316
 	 */
317 317
 	public function elements_form() {
318 318
 		?>
319
-		<fieldset id="wc-<?php echo esc_attr( $this->id ); ?>-cc-form" class="wc-credit-card-form wc-payment-form" style="background:transparent;">
320
-			<?php do_action( 'woocommerce_credit_card_form_start', $this->id ); ?>
319
+		<fieldset id="wc-<?php echo esc_attr($this->id); ?>-cc-form" class="wc-credit-card-form wc-payment-form" style="background:transparent;">
320
+			<?php do_action('woocommerce_credit_card_form_start', $this->id); ?>
321 321
 
322
-			<?php if ( $this->inline_cc_form ) { ?>
322
+			<?php if ($this->inline_cc_form) { ?>
323 323
 				<label for="card-element">
324
-					<?php esc_html_e( 'Credit or debit card', 'woocommerce-gateway-stripe' ); ?>
324
+					<?php esc_html_e('Credit or debit card', 'woocommerce-gateway-stripe'); ?>
325 325
 				</label>
326 326
 
327 327
 				<div id="stripe-card-element" class="wc-stripe-elements-field">
@@ -329,7 +329,7 @@  discard block
 block discarded – undo
329 329
 				</div>
330 330
 			<?php } else { ?>
331 331
 				<div class="form-row form-row-wide">
332
-					<label for="stripe-card-element"><?php esc_html_e( 'Card Number', 'woocommerce-gateway-stripe' ); ?> <span class="required">*</span></label>
332
+					<label for="stripe-card-element"><?php esc_html_e('Card Number', 'woocommerce-gateway-stripe'); ?> <span class="required">*</span></label>
333 333
 					<div class="stripe-card-group">
334 334
 						<div id="stripe-card-element" class="wc-stripe-elements-field">
335 335
 						<!-- a Stripe Element will be inserted here. -->
@@ -340,7 +340,7 @@  discard block
 block discarded – undo
340 340
 				</div>
341 341
 
342 342
 				<div class="form-row form-row-first">
343
-					<label for="stripe-exp-element"><?php esc_html_e( 'Expiry Date', 'woocommerce-gateway-stripe' ); ?> <span class="required">*</span></label>
343
+					<label for="stripe-exp-element"><?php esc_html_e('Expiry Date', 'woocommerce-gateway-stripe'); ?> <span class="required">*</span></label>
344 344
 
345 345
 					<div id="stripe-exp-element" class="wc-stripe-elements-field">
346 346
 					<!-- a Stripe Element will be inserted here. -->
@@ -348,7 +348,7 @@  discard block
 block discarded – undo
348 348
 				</div>
349 349
 
350 350
 				<div class="form-row form-row-last">
351
-					<label for="stripe-cvc-element"><?php esc_html_e( 'Card Code (CVC)', 'woocommerce-gateway-stripe' ); ?> <span class="required">*</span></label>
351
+					<label for="stripe-cvc-element"><?php esc_html_e('Card Code (CVC)', 'woocommerce-gateway-stripe'); ?> <span class="required">*</span></label>
352 352
 				<div id="stripe-cvc-element" class="wc-stripe-elements-field">
353 353
 				<!-- a Stripe Element will be inserted here. -->
354 354
 				</div>
@@ -359,7 +359,7 @@  discard block
 block discarded – undo
359 359
 			<!-- Used to display form errors -->
360 360
 			<div class="stripe-source-errors" role="alert"></div>
361 361
 			<br />
362
-			<?php do_action( 'woocommerce_credit_card_form_end', $this->id ); ?>
362
+			<?php do_action('woocommerce_credit_card_form_end', $this->id); ?>
363 363
 			<div class="clear"></div>
364 364
 		</fieldset>
365 365
 		<?php
@@ -372,13 +372,13 @@  discard block
 block discarded – undo
372 372
 	 * @version 3.1.0
373 373
 	 */
374 374
 	public function admin_scripts() {
375
-		if ( 'woocommerce_page_wc-settings' !== get_current_screen()->id ) {
375
+		if ('woocommerce_page_wc-settings' !== get_current_screen()->id) {
376 376
 			return;
377 377
 		}
378 378
 
379
-		$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
379
+		$suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';
380 380
 
381
-		wp_enqueue_script( 'woocommerce_stripe_admin', plugins_url( 'assets/js/stripe-admin' . $suffix . '.js', WC_STRIPE_MAIN_FILE ), array(), WC_STRIPE_VERSION, true );
381
+		wp_enqueue_script('woocommerce_stripe_admin', plugins_url('assets/js/stripe-admin' . $suffix . '.js', WC_STRIPE_MAIN_FILE), array(), WC_STRIPE_VERSION, true);
382 382
 	}
383 383
 
384 384
 	/**
@@ -390,97 +390,97 @@  discard block
 block discarded – undo
390 390
 	 * @version 4.0.0
391 391
 	 */
392 392
 	public function payment_scripts() {
393
-		if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) && ! is_add_payment_method_page() && ! isset( $_GET['change_payment_method'] ) ) { // wpcs: csrf ok.
393
+		if ( ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order']) && ! is_add_payment_method_page() && ! isset($_GET['change_payment_method'])) { // wpcs: csrf ok.
394 394
 			return;
395 395
 		}
396 396
 
397 397
 		// If Stripe is not enabled bail.
398
-		if ( 'no' === $this->enabled ) {
398
+		if ('no' === $this->enabled) {
399 399
 			return;
400 400
 		}
401 401
 
402 402
 		// If keys are not set bail.
403
-		if ( ! $this->are_keys_set() ) {
404
-			WC_Stripe_Logger::log( 'Keys are not set correctly.' );
403
+		if ( ! $this->are_keys_set()) {
404
+			WC_Stripe_Logger::log('Keys are not set correctly.');
405 405
 			return;
406 406
 		}
407 407
 
408 408
 		// If no SSL bail.
409
-		if ( ! $this->testmode && ! is_ssl() ) {
410
-			WC_Stripe_Logger::log( 'Stripe live mode requires SSL.' );
409
+		if ( ! $this->testmode && ! is_ssl()) {
410
+			WC_Stripe_Logger::log('Stripe live mode requires SSL.');
411 411
 			return;
412 412
 		}
413 413
 
414 414
 		$current_theme = wp_get_theme();
415 415
 
416
-		$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
416
+		$suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';
417 417
 
418
-		wp_register_style( 'stripe_styles', plugins_url( 'assets/css/stripe-styles.css', WC_STRIPE_MAIN_FILE ), array(), WC_STRIPE_VERSION );
419
-		wp_enqueue_style( 'stripe_styles' );
418
+		wp_register_style('stripe_styles', plugins_url('assets/css/stripe-styles.css', WC_STRIPE_MAIN_FILE), array(), WC_STRIPE_VERSION);
419
+		wp_enqueue_style('stripe_styles');
420 420
 
421
-		wp_register_script( 'stripe', 'https://js.stripe.com/v3/', '', '3.0', true );
422
-		wp_register_script( 'woocommerce_stripe', plugins_url( 'assets/js/stripe' . $suffix . '.js', WC_STRIPE_MAIN_FILE ), array( 'jquery-payment', 'stripe' ), WC_STRIPE_VERSION, true );
421
+		wp_register_script('stripe', 'https://js.stripe.com/v3/', '', '3.0', true);
422
+		wp_register_script('woocommerce_stripe', plugins_url('assets/js/stripe' . $suffix . '.js', WC_STRIPE_MAIN_FILE), array('jquery-payment', 'stripe'), WC_STRIPE_VERSION, true);
423 423
 
424 424
 		$stripe_params = array(
425 425
 			'key'                  => $this->publishable_key,
426
-			'i18n_terms'           => __( 'Please accept the terms and conditions first', 'woocommerce-gateway-stripe' ),
427
-			'i18n_required_fields' => __( 'Please fill in required checkout fields first', 'woocommerce-gateway-stripe' ),
426
+			'i18n_terms'           => __('Please accept the terms and conditions first', 'woocommerce-gateway-stripe'),
427
+			'i18n_required_fields' => __('Please fill in required checkout fields first', 'woocommerce-gateway-stripe'),
428 428
 		);
429 429
 
430 430
 		// If we're on the pay page we need to pass stripe.js the address of the order.
431
-		if ( isset( $_GET['pay_for_order'] ) && 'true' === $_GET['pay_for_order'] ) { // wpcs: csrf ok.
432
-			$order_id = wc_get_order_id_by_order_key( urldecode( $_GET['key'] ) ); // wpcs: csrf ok, sanitization ok, xss ok.
433
-			$order    = wc_get_order( $order_id );
434
-
435
-			if ( is_a( $order, 'WC_Order' ) ) {
436
-				$stripe_params['billing_first_name'] = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->billing_first_name : $order->get_billing_first_name();
437
-				$stripe_params['billing_last_name']  = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->billing_last_name : $order->get_billing_last_name();
438
-				$stripe_params['billing_address_1']  = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->billing_address_1 : $order->get_billing_address_1();
439
-				$stripe_params['billing_address_2']  = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->billing_address_2 : $order->get_billing_address_2();
440
-				$stripe_params['billing_state']      = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->billing_state : $order->get_billing_state();
441
-				$stripe_params['billing_city']       = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->billing_city : $order->get_billing_city();
442
-				$stripe_params['billing_postcode']   = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->billing_postcode : $order->get_billing_postcode();
443
-				$stripe_params['billing_country']    = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->billing_country : $order->get_billing_country();
431
+		if (isset($_GET['pay_for_order']) && 'true' === $_GET['pay_for_order']) { // wpcs: csrf ok.
432
+			$order_id = wc_get_order_id_by_order_key(urldecode($_GET['key'])); // wpcs: csrf ok, sanitization ok, xss ok.
433
+			$order    = wc_get_order($order_id);
434
+
435
+			if (is_a($order, 'WC_Order')) {
436
+				$stripe_params['billing_first_name'] = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->billing_first_name : $order->get_billing_first_name();
437
+				$stripe_params['billing_last_name']  = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->billing_last_name : $order->get_billing_last_name();
438
+				$stripe_params['billing_address_1']  = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->billing_address_1 : $order->get_billing_address_1();
439
+				$stripe_params['billing_address_2']  = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->billing_address_2 : $order->get_billing_address_2();
440
+				$stripe_params['billing_state']      = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->billing_state : $order->get_billing_state();
441
+				$stripe_params['billing_city']       = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->billing_city : $order->get_billing_city();
442
+				$stripe_params['billing_postcode']   = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->billing_postcode : $order->get_billing_postcode();
443
+				$stripe_params['billing_country']    = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->billing_country : $order->get_billing_country();
444 444
 			}
445 445
 		}
446 446
 
447 447
 		$sepa_elements_options = apply_filters(
448 448
 			'wc_stripe_sepa_elements_options',
449 449
 			array(
450
-				'supportedCountries' => array( 'SEPA' ),
450
+				'supportedCountries' => array('SEPA'),
451 451
 				'placeholderCountry' => WC()->countries->get_base_country(),
452
-				'style'              => array( 'base' => array( 'fontSize' => '15px' ) ),
452
+				'style'              => array('base' => array('fontSize' => '15px')),
453 453
 			)
454 454
 		);
455 455
 
456
-		$stripe_params['no_prepaid_card_msg']       = __( 'Sorry, we\'re not accepting prepaid cards at this time. Your credit card has not been charged. Please try with alternative payment method.', 'woocommerce-gateway-stripe' );
457
-		$stripe_params['no_sepa_owner_msg']         = __( 'Please enter your IBAN account name.', 'woocommerce-gateway-stripe' );
458
-		$stripe_params['no_sepa_iban_msg']          = __( 'Please enter your IBAN account number.', 'woocommerce-gateway-stripe' );
459
-		$stripe_params['payment_intent_error']      = __( 'We couldn\'t initiate the payment. Please try again.', 'woocommerce-gateway-stripe' );
460
-		$stripe_params['sepa_mandate_notification'] = apply_filters( 'wc_stripe_sepa_mandate_notification', 'email' );
461
-		$stripe_params['allow_prepaid_card']        = apply_filters( 'wc_stripe_allow_prepaid_card', true ) ? 'yes' : 'no';
456
+		$stripe_params['no_prepaid_card_msg']       = __('Sorry, we\'re not accepting prepaid cards at this time. Your credit card has not been charged. Please try with alternative payment method.', 'woocommerce-gateway-stripe');
457
+		$stripe_params['no_sepa_owner_msg']         = __('Please enter your IBAN account name.', 'woocommerce-gateway-stripe');
458
+		$stripe_params['no_sepa_iban_msg']          = __('Please enter your IBAN account number.', 'woocommerce-gateway-stripe');
459
+		$stripe_params['payment_intent_error']      = __('We couldn\'t initiate the payment. Please try again.', 'woocommerce-gateway-stripe');
460
+		$stripe_params['sepa_mandate_notification'] = apply_filters('wc_stripe_sepa_mandate_notification', 'email');
461
+		$stripe_params['allow_prepaid_card']        = apply_filters('wc_stripe_allow_prepaid_card', true) ? 'yes' : 'no';
462 462
 		$stripe_params['inline_cc_form']            = $this->inline_cc_form ? 'yes' : 'no';
463
-		$stripe_params['is_checkout']               = ( is_checkout() && empty( $_GET['pay_for_order'] ) ) ? 'yes' : 'no'; // wpcs: csrf ok.
463
+		$stripe_params['is_checkout']               = (is_checkout() && empty($_GET['pay_for_order'])) ? 'yes' : 'no'; // wpcs: csrf ok.
464 464
 		$stripe_params['return_url']                = $this->get_stripe_return_url();
465
-		$stripe_params['ajaxurl']                   = WC_AJAX::get_endpoint( '%%endpoint%%' );
466
-		$stripe_params['stripe_nonce']              = wp_create_nonce( '_wc_stripe_nonce' );
465
+		$stripe_params['ajaxurl']                   = WC_AJAX::get_endpoint('%%endpoint%%');
466
+		$stripe_params['stripe_nonce']              = wp_create_nonce('_wc_stripe_nonce');
467 467
 		$stripe_params['statement_descriptor']      = $this->statement_descriptor;
468
-		$stripe_params['elements_options']          = apply_filters( 'wc_stripe_elements_options', array() );
468
+		$stripe_params['elements_options']          = apply_filters('wc_stripe_elements_options', array());
469 469
 		$stripe_params['sepa_elements_options']     = $sepa_elements_options;
470
-		$stripe_params['invalid_owner_name']        = __( 'Billing First Name and Last Name are required.', 'woocommerce-gateway-stripe' );
471
-		$stripe_params['is_change_payment_page']    = isset( $_GET['change_payment_method'] ) ? 'yes' : 'no'; // wpcs: csrf ok.
472
-		$stripe_params['is_add_payment_page']       = is_wc_endpoint_url( 'add-payment-method' ) ? 'yes' : 'no';
473
-		$stripe_params['is_pay_for_order_page']     = is_wc_endpoint_url( 'order-pay' ) ? 'yes' : 'no';
474
-		$stripe_params['elements_styling']          = apply_filters( 'wc_stripe_elements_styling', false );
475
-		$stripe_params['elements_classes']          = apply_filters( 'wc_stripe_elements_classes', false );
470
+		$stripe_params['invalid_owner_name']        = __('Billing First Name and Last Name are required.', 'woocommerce-gateway-stripe');
471
+		$stripe_params['is_change_payment_page']    = isset($_GET['change_payment_method']) ? 'yes' : 'no'; // wpcs: csrf ok.
472
+		$stripe_params['is_add_payment_page']       = is_wc_endpoint_url('add-payment-method') ? 'yes' : 'no';
473
+		$stripe_params['is_pay_for_order_page']     = is_wc_endpoint_url('order-pay') ? 'yes' : 'no';
474
+		$stripe_params['elements_styling']          = apply_filters('wc_stripe_elements_styling', false);
475
+		$stripe_params['elements_classes']          = apply_filters('wc_stripe_elements_classes', false);
476 476
 
477 477
 		// Merge localized messages to be use in JS.
478
-		$stripe_params = array_merge( $stripe_params, WC_Stripe_Helper::get_localized_messages() );
478
+		$stripe_params = array_merge($stripe_params, WC_Stripe_Helper::get_localized_messages());
479 479
 
480
-		wp_localize_script( 'woocommerce_stripe', 'wc_stripe_params', apply_filters( 'wc_stripe_params', $stripe_params ) );
480
+		wp_localize_script('woocommerce_stripe', 'wc_stripe_params', apply_filters('wc_stripe_params', $stripe_params));
481 481
 
482 482
 		$this->tokenization_script();
483
-		wp_enqueue_script( 'woocommerce_stripe' );
483
+		wp_enqueue_script('woocommerce_stripe');
484 484
 	}
485 485
 
486 486
 	/**
@@ -489,14 +489,14 @@  discard block
 block discarded – undo
489 489
 	 * @since 4.2.0
490 490
 	 * @param WC_Order $order The order that is being created.
491 491
 	 */
492
-	public function maybe_create_customer( $order ) {
492
+	public function maybe_create_customer($order) {
493 493
 		// This comes from the create account checkbox in the checkout page.
494
-		if ( empty( $_POST['createaccount'] ) ) { // wpcs: csrf ok.
494
+		if (empty($_POST['createaccount'])) { // wpcs: csrf ok.
495 495
 			return;
496 496
 		}
497 497
 
498
-		$new_customer_id     = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->customer_user : $order->get_customer_id();
499
-		$new_stripe_customer = new WC_Stripe_Customer( $new_customer_id );
498
+		$new_customer_id     = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->customer_user : $order->get_customer_id();
499
+		$new_stripe_customer = new WC_Stripe_Customer($new_customer_id);
500 500
 		$new_stripe_customer->create_customer();
501 501
 	}
502 502
 
@@ -508,14 +508,14 @@  discard block
 block discarded – undo
508 508
 	 * @param object $prepared_source The object with source details.
509 509
 	 * @throws WC_Stripe_Exception An exception if the card is prepaid, but prepaid cards are not allowed.
510 510
 	 */
511
-	public function maybe_disallow_prepaid_card( $prepared_source ) {
511
+	public function maybe_disallow_prepaid_card($prepared_source) {
512 512
 		// Check if we don't allow prepaid credit cards.
513
-		if ( apply_filters( 'wc_stripe_allow_prepaid_card', true ) || ! $this->is_prepaid_card( $prepared_source->source_object ) ) {
513
+		if (apply_filters('wc_stripe_allow_prepaid_card', true) || ! $this->is_prepaid_card($prepared_source->source_object)) {
514 514
 			return;
515 515
 		}
516 516
 
517
-		$localized_message = __( 'Sorry, we\'re not accepting prepaid cards at this time. Your credit card has not been charged. Please try with alternative payment method.', 'woocommerce-gateway-stripe' );
518
-		throw new WC_Stripe_Exception( print_r( $prepared_source->source_object, true ), $localized_message );
517
+		$localized_message = __('Sorry, we\'re not accepting prepaid cards at this time. Your credit card has not been charged. Please try with alternative payment method.', 'woocommerce-gateway-stripe');
518
+		throw new WC_Stripe_Exception(print_r($prepared_source->source_object, true), $localized_message);
519 519
 	}
520 520
 
521 521
 	/**
@@ -525,10 +525,10 @@  discard block
 block discarded – undo
525 525
 	 * @param  object $prepared_source The source that should be verified.
526 526
 	 * @throws WC_Stripe_Exception     An exception if the source ID is missing.
527 527
 	 */
528
-	public function check_source( $prepared_source ) {
529
-		if ( empty( $prepared_source->source ) ) {
530
-			$localized_message = __( 'Payment processing failed. Please retry.', 'woocommerce-gateway-stripe' );
531
-			throw new WC_Stripe_Exception( print_r( $prepared_source, true ), $localized_message );
528
+	public function check_source($prepared_source) {
529
+		if (empty($prepared_source->source)) {
530
+			$localized_message = __('Payment processing failed. Please retry.', 'woocommerce-gateway-stripe');
531
+			throw new WC_Stripe_Exception(print_r($prepared_source, true), $localized_message);
532 532
 		}
533 533
 	}
534 534
 
@@ -540,17 +540,17 @@  discard block
 block discarded – undo
540 540
 	 * @param WC_Order $order The order those payment is being processed.
541 541
 	 * @return bool           A flag that indicates that the customer does not exist and should be removed.
542 542
 	 */
543
-	public function maybe_remove_non_existent_customer( $error, $order ) {
544
-		if ( ! $this->is_no_such_customer_error( $error ) ) {
543
+	public function maybe_remove_non_existent_customer($error, $order) {
544
+		if ( ! $this->is_no_such_customer_error($error)) {
545 545
 			return false;
546 546
 		}
547 547
 
548
-		if ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ) {
549
-			delete_user_meta( $order->customer_user, '_stripe_customer_id' );
550
-			delete_post_meta( $order->get_id(), '_stripe_customer_id' );
548
+		if (WC_Stripe_Helper::is_wc_lt('3.0')) {
549
+			delete_user_meta($order->customer_user, '_stripe_customer_id');
550
+			delete_post_meta($order->get_id(), '_stripe_customer_id');
551 551
 		} else {
552
-			delete_user_meta( $order->get_customer_id(), '_stripe_customer_id' );
553
-			$order->delete_meta_data( '_stripe_customer_id' );
552
+			delete_user_meta($order->get_customer_id(), '_stripe_customer_id');
553
+			$order->delete_meta_data('_stripe_customer_id');
554 554
 			$order->save();
555 555
 		}
556 556
 
@@ -564,7 +564,7 @@  discard block
 block discarded – undo
564 564
 	 * @param WC_Order $order The order to complete.
565 565
 	 * @return array          Redirection data for `process_payment`.
566 566
 	 */
567
-	public function complete_free_order( $order ) {
567
+	public function complete_free_order($order) {
568 568
 		$order->payment_complete();
569 569
 
570 570
 		// Remove cart.
@@ -573,7 +573,7 @@  discard block
 block discarded – undo
573 573
 		// Return thank you page redirect.
574 574
 		return array(
575 575
 			'result'   => 'success',
576
-			'redirect' => $this->get_return_url( $order ),
576
+			'redirect' => $this->get_return_url($order),
577 577
 		);
578 578
 	}
579 579
 
@@ -590,60 +590,60 @@  discard block
 block discarded – undo
590 590
 	 * @throws Exception If payment will not be accepted.
591 591
 	 * @return array|void
592 592
 	 */
593
-	public function process_payment( $order_id, $retry = true, $force_save_source = false, $previous_error = false ) {
593
+	public function process_payment($order_id, $retry = true, $force_save_source = false, $previous_error = false) {
594 594
 		try {
595
-			$order = wc_get_order( $order_id );
595
+			$order = wc_get_order($order_id);
596 596
 
597 597
 			// ToDo: `process_pre_order` saves the source to the order for a later payment.
598 598
 			// This might not work well with PaymentIntents.
599
-			if ( $this->maybe_process_pre_orders( $order_id ) ) {
600
-				return $this->pre_orders->process_pre_order( $order_id );
599
+			if ($this->maybe_process_pre_orders($order_id)) {
600
+				return $this->pre_orders->process_pre_order($order_id);
601 601
 			}
602 602
 
603
-			$this->maybe_create_customer( $order );
603
+			$this->maybe_create_customer($order);
604 604
 
605
-			$prepared_source = $this->prepare_source( get_current_user_id(), $force_save_source );
605
+			$prepared_source = $this->prepare_source(get_current_user_id(), $force_save_source);
606 606
 
607
-			$this->maybe_disallow_prepaid_card( $prepared_source );
608
-			$this->check_source( $prepared_source );
609
-			$this->save_source_to_order( $order, $prepared_source );
607
+			$this->maybe_disallow_prepaid_card($prepared_source);
608
+			$this->check_source($prepared_source);
609
+			$this->save_source_to_order($order, $prepared_source);
610 610
 
611
-			if ( 0 >= $order->get_total() ) {
612
-				return $this->complete_free_order( $order );
611
+			if (0 >= $order->get_total()) {
612
+				return $this->complete_free_order($order);
613 613
 			}
614 614
 
615 615
 			// This will throw exception if not valid.
616
-			$this->validate_minimum_order_amount( $order );
616
+			$this->validate_minimum_order_amount($order);
617 617
 
618
-			WC_Stripe_Logger::log( "Info: Begin processing payment for order $order_id for the amount of {$order->get_total()}" );
618
+			WC_Stripe_Logger::log("Info: Begin processing payment for order $order_id for the amount of {$order->get_total()}");
619 619
 
620
-			$intent = $this->get_intent_from_order( $order );
621
-			if ( $intent ) {
622
-				$intent = $this->update_existing_intent( $intent, $order, $prepared_source );
620
+			$intent = $this->get_intent_from_order($order);
621
+			if ($intent) {
622
+				$intent = $this->update_existing_intent($intent, $order, $prepared_source);
623 623
 			} else {
624
-				$intent   = $this->create_and_confirm_intent( $order, $prepared_source );
624
+				$intent   = $this->create_and_confirm_intent($order, $prepared_source);
625 625
 				$response = $intent;
626 626
 			}
627 627
 
628
-			if ( ! empty( $response->error ) ) {
629
-				$this->maybe_remove_non_existent_customer( $response->error, $order );
628
+			if ( ! empty($response->error)) {
629
+				$this->maybe_remove_non_existent_customer($response->error, $order);
630 630
 
631 631
 				// We want to retry.
632
-				if ( $this->is_retryable_error( $response->error ) ) {
633
-					return $this->retry_after_error( $response, $order, $retry, $force_save_source, $previous_error );
632
+				if ($this->is_retryable_error($response->error)) {
633
+					return $this->retry_after_error($response, $order, $retry, $force_save_source, $previous_error);
634 634
 				}
635 635
 
636
-				$this->throw_localized_message( $response, $order );
636
+				$this->throw_localized_message($response, $order);
637 637
 			}
638 638
 
639
-			if ( ! empty( $intent ) ) {
639
+			if ( ! empty($intent)) {
640 640
 				// Use the last charge within the intent to proceed.
641
-				$response = end( $intent->charges->data );
641
+				$response = end($intent->charges->data);
642 642
 
643 643
 				// If the intent requires a 3DS flow, redirect to it.
644
-				if ( 'requires_action' === $intent->status ) {
645
-					if ( is_wc_endpoint_url( 'order-pay' ) ) {
646
-						$redirect_url = add_query_arg( 'wc-stripe-confirmation', 1, $order->get_checkout_payment_url( false ) );
644
+				if ('requires_action' === $intent->status) {
645
+					if (is_wc_endpoint_url('order-pay')) {
646
+						$redirect_url = add_query_arg('wc-stripe-confirmation', 1, $order->get_checkout_payment_url(false));
647 647
 
648 648
 						return array(
649 649
 							'result'   => 'success',
@@ -658,7 +658,7 @@  discard block
 block discarded – undo
658 658
 
659 659
 						return array(
660 660
 							'result'           => 'success',
661
-							'redirect'         => $this->get_return_url( $order ),
661
+							'redirect'         => $this->get_return_url($order),
662 662
 							'intent_secret'    => $intent->client_secret,
663 663
 						);
664 664
 					}
@@ -666,7 +666,7 @@  discard block
 block discarded – undo
666 666
 			}
667 667
 
668 668
 			// Process valid response.
669
-			$this->process_response( $response, $order );
669
+			$this->process_response($response, $order);
670 670
 
671 671
 			// Remove cart.
672 672
 			WC()->cart->empty_cart();
@@ -674,17 +674,17 @@  discard block
 block discarded – undo
674 674
 			// Return thank you page redirect.
675 675
 			return array(
676 676
 				'result'   => 'success',
677
-				'redirect' => $this->get_return_url( $order ),
677
+				'redirect' => $this->get_return_url($order),
678 678
 			);
679 679
 
680
-		} catch ( WC_Stripe_Exception $e ) {
681
-			wc_add_notice( $e->getLocalizedMessage(), 'error' );
682
-			WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() );
680
+		} catch (WC_Stripe_Exception $e) {
681
+			wc_add_notice($e->getLocalizedMessage(), 'error');
682
+			WC_Stripe_Logger::log('Error: ' . $e->getMessage());
683 683
 
684
-			do_action( 'wc_gateway_stripe_process_payment_error', $e, $order );
684
+			do_action('wc_gateway_stripe_process_payment_error', $e, $order);
685 685
 
686 686
 			/* translators: error message */
687
-			$order->update_status( 'failed' );
687
+			$order->update_status('failed');
688 688
 
689 689
 			return array(
690 690
 				'result'   => 'fail',
@@ -700,17 +700,17 @@  discard block
 block discarded – undo
700 700
 	 *
701 701
 	 * @param int $order_id The ID of the order.
702 702
 	 */
703
-	public function display_order_fee( $order_id ) {
704
-		if ( apply_filters( 'wc_stripe_hide_display_order_fee', false, $order_id ) ) {
703
+	public function display_order_fee($order_id) {
704
+		if (apply_filters('wc_stripe_hide_display_order_fee', false, $order_id)) {
705 705
 			return;
706 706
 		}
707 707
 
708
-		$order = wc_get_order( $order_id );
708
+		$order = wc_get_order($order_id);
709 709
 
710
-		$fee      = WC_Stripe_Helper::get_stripe_fee( $order );
711
-		$currency = WC_Stripe_Helper::get_stripe_currency( $order );
710
+		$fee      = WC_Stripe_Helper::get_stripe_fee($order);
711
+		$currency = WC_Stripe_Helper::get_stripe_currency($order);
712 712
 
713
-		if ( ! $fee || ! $currency ) {
713
+		if ( ! $fee || ! $currency) {
714 714
 			return;
715 715
 		}
716 716
 
@@ -718,12 +718,12 @@  discard block
 block discarded – undo
718 718
 
719 719
 		<tr>
720 720
 			<td class="label stripe-fee">
721
-				<?php echo wc_help_tip( __( 'This represents the fee Stripe collects for the transaction.', 'woocommerce-gateway-stripe' ) ); // wpcs: xss ok. ?>
722
-				<?php esc_html_e( 'Stripe Fee:', 'woocommerce-gateway-stripe' ); ?>
721
+				<?php echo wc_help_tip(__('This represents the fee Stripe collects for the transaction.', 'woocommerce-gateway-stripe')); // wpcs: xss ok. ?>
722
+				<?php esc_html_e('Stripe Fee:', 'woocommerce-gateway-stripe'); ?>
723 723
 			</td>
724 724
 			<td width="1%"></td>
725 725
 			<td class="total">
726
-				-&nbsp;<?php echo wc_price( $fee, array( 'currency' => $currency ) ); // wpcs: xss ok. ?>
726
+				-&nbsp;<?php echo wc_price($fee, array('currency' => $currency)); // wpcs: xss ok. ?>
727 727
 			</td>
728 728
 		</tr>
729 729
 
@@ -737,17 +737,17 @@  discard block
 block discarded – undo
737 737
 	 *
738 738
 	 * @param int $order_id The ID of the order.
739 739
 	 */
740
-	public function display_order_payout( $order_id ) {
741
-		if ( apply_filters( 'wc_stripe_hide_display_order_payout', false, $order_id ) ) {
740
+	public function display_order_payout($order_id) {
741
+		if (apply_filters('wc_stripe_hide_display_order_payout', false, $order_id)) {
742 742
 			return;
743 743
 		}
744 744
 
745
-		$order = wc_get_order( $order_id );
745
+		$order = wc_get_order($order_id);
746 746
 
747
-		$net      = WC_Stripe_Helper::get_stripe_net( $order );
748
-		$currency = WC_Stripe_Helper::get_stripe_currency( $order );
747
+		$net      = WC_Stripe_Helper::get_stripe_net($order);
748
+		$currency = WC_Stripe_Helper::get_stripe_currency($order);
749 749
 
750
-		if ( ! $net || ! $currency ) {
750
+		if ( ! $net || ! $currency) {
751 751
 			return;
752 752
 		}
753 753
 
@@ -755,12 +755,12 @@  discard block
 block discarded – undo
755 755
 
756 756
 		<tr>
757 757
 			<td class="label stripe-payout">
758
-				<?php echo wc_help_tip( __( 'This represents the net total that will be credited to your Stripe bank account. This may be in the currency that is set in your Stripe account.', 'woocommerce-gateway-stripe' ) ); // wpcs: xss ok. ?>
759
-				<?php esc_html_e( 'Stripe Payout:', 'woocommerce-gateway-stripe' ); ?>
758
+				<?php echo wc_help_tip(__('This represents the net total that will be credited to your Stripe bank account. This may be in the currency that is set in your Stripe account.', 'woocommerce-gateway-stripe')); // wpcs: xss ok. ?>
759
+				<?php esc_html_e('Stripe Payout:', 'woocommerce-gateway-stripe'); ?>
760 760
 			</td>
761 761
 			<td width="1%"></td>
762 762
 			<td class="total">
763
-				<?php echo wc_price( $net, array( 'currency' => $currency ) ); // wpcs: xss ok. ?>
763
+				<?php echo wc_price($net, array('currency' => $currency)); // wpcs: xss ok. ?>
764 764
 			</td>
765 765
 		</tr>
766 766
 
@@ -773,16 +773,16 @@  discard block
 block discarded – undo
773 773
 	 * @since 4.2.0
774 774
 	 */
775 775
 	public function display_three_d_secure_notice() {
776
-		if ( $this->get_option( '3ds_setting_notice_dismissed' ) ) {
776
+		if ($this->get_option('3ds_setting_notice_dismissed')) {
777 777
 			return;
778 778
 		}
779 779
 		?>
780
-		<div data-nonce="<?php echo esc_attr( wp_create_nonce( 'no-3ds' ) ); ?>" class="notice notice-warning is-dismissible wc-stripe-3ds-missing">
780
+		<div data-nonce="<?php echo esc_attr(wp_create_nonce('no-3ds')); ?>" class="notice notice-warning is-dismissible wc-stripe-3ds-missing">
781 781
 			<p>
782 782
 				<?php
783 783
 				$url = 'https://stripe.com/docs/payments/dynamic-3ds';
784 784
 				/* translators: 1) A URL that explains Stripe Radar. */
785
-				$message = __( '<strong>WooCommerce Stripe Gateway:</strong> We see that you had the "Require 3D secure when applicable" setting turned on. This setting is not available here anymore, because it is now replaced by Stripe Radar. You can learn more about it <a href="%s">here</a>.', 'woocommerce-gateway-stripe' );
785
+				$message = __('<strong>WooCommerce Stripe Gateway:</strong> We see that you had the "Require 3D secure when applicable" setting turned on. This setting is not available here anymore, because it is now replaced by Stripe Radar. You can learn more about it <a href="%s">here</a>.', 'woocommerce-gateway-stripe');
786 786
 
787 787
 				$allowed_tags = array(
788 788
 					'strong' => array(),
@@ -790,7 +790,7 @@  discard block
 block discarded – undo
790 790
 						'href' => array(),
791 791
 					),
792 792
 				);
793
-				printf( wp_kses( $message, $allowed_tags ), esc_url( $url ) );
793
+				printf(wp_kses($message, $allowed_tags), esc_url($url));
794 794
 				?>
795 795
 			</p>
796 796
 		</div>
@@ -805,18 +805,18 @@  discard block
 block discarded – undo
805 805
 	 * @param  WC_Order $order     The order to add a note to.
806 806
 	 * @throws WC_Stripe_Exception An exception with the right message.
807 807
 	 */
808
-	public function throw_localized_message( $response, $order ) {
808
+	public function throw_localized_message($response, $order) {
809 809
 		$localized_messages = WC_Stripe_Helper::get_localized_messages();
810 810
 
811
-		if ( 'card_error' === $response->error->type ) {
812
-			$localized_message = isset( $localized_messages[ $response->error->code ] ) ? $localized_messages[ $response->error->code ] : $response->error->message;
811
+		if ('card_error' === $response->error->type) {
812
+			$localized_message = isset($localized_messages[$response->error->code]) ? $localized_messages[$response->error->code] : $response->error->message;
813 813
 		} else {
814
-			$localized_message = isset( $localized_messages[ $response->error->type ] ) ? $localized_messages[ $response->error->type ] : $response->error->message;
814
+			$localized_message = isset($localized_messages[$response->error->type]) ? $localized_messages[$response->error->type] : $response->error->message;
815 815
 		}
816 816
 
817
-		$order->add_order_note( $localized_message );
817
+		$order->add_order_note($localized_message);
818 818
 
819
-		throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message );
819
+		throw new WC_Stripe_Exception(print_r($response, true), $localized_message);
820 820
 	}
821 821
 
822 822
 	/**
@@ -831,22 +831,22 @@  discard block
 block discarded – undo
831 831
 	 * @throws WC_Stripe_Exception        If the payment is not accepted.
832 832
 	 * @return array|void
833 833
 	 */
834
-	public function retry_after_error( $response, $order, $retry, $force_save_source, $previous_error ) {
835
-		if ( ! $retry ) {
836
-			$localized_message = __( 'Sorry, we are unable to process your payment at this time. Please retry later.', 'woocommerce-gateway-stripe' );
837
-			$order->add_order_note( $localized_message );
838
-			throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message ); // phpcs:ignore WordPress.PHP.DevelopmentFunctions.
834
+	public function retry_after_error($response, $order, $retry, $force_save_source, $previous_error) {
835
+		if ( ! $retry) {
836
+			$localized_message = __('Sorry, we are unable to process your payment at this time. Please retry later.', 'woocommerce-gateway-stripe');
837
+			$order->add_order_note($localized_message);
838
+			throw new WC_Stripe_Exception(print_r($response, true), $localized_message); // phpcs:ignore WordPress.PHP.DevelopmentFunctions.
839 839
 		}
840 840
 
841 841
 		// Don't do anymore retries after this.
842
-		if ( 5 <= $this->retry_interval ) {
843
-			return $this->process_payment( $order->get_id(), false, $force_save_source, $response->error, $previous_error );
842
+		if (5 <= $this->retry_interval) {
843
+			return $this->process_payment($order->get_id(), false, $force_save_source, $response->error, $previous_error);
844 844
 		}
845 845
 
846
-		sleep( $this->retry_interval );
846
+		sleep($this->retry_interval);
847 847
 		$this->retry_interval++;
848 848
 
849
-		return $this->process_payment( $order->get_id(), true, $force_save_source, $response->error, $previous_error );
849
+		return $this->process_payment($order->get_id(), true, $force_save_source, $response->error, $previous_error);
850 850
 	}
851 851
 
852 852
 	/**
@@ -857,16 +857,16 @@  discard block
 block discarded – undo
857 857
 	 * @param WC_Payment_Gateway[] $gateways A list of all available gateways.
858 858
 	 * @return WC_Payment_Gateway[]          Either the same list or an empty one in the right conditions.
859 859
 	 */
860
-	public function prepare_order_pay_page( $gateways ) {
861
-		if ( ! is_wc_endpoint_url( 'order-pay' ) || ! isset( $_GET['wc-stripe-confirmation'] ) ) { // wpcs: csrf ok.
860
+	public function prepare_order_pay_page($gateways) {
861
+		if ( ! is_wc_endpoint_url('order-pay') || ! isset($_GET['wc-stripe-confirmation'])) { // wpcs: csrf ok.
862 862
 			return $gateways;
863 863
 		}
864 864
 
865
-		add_filter( 'woocommerce_checkout_show_terms', '__return_false' );
866
-		add_filter( 'woocommerce_pay_order_button_html', '__return_false' );
867
-		add_filter( 'woocommerce_available_payment_gateways', array( $this, '__return_empty_array' ) );
868
-		add_filter( 'woocommerce_no_available_payment_methods_message', array( $this, 'change_no_available_methods_message' ) );
869
-		add_action( 'woocommerce_pay_order_after_submit', array( $this, 'render_payment_intent_inputs' ) );
865
+		add_filter('woocommerce_checkout_show_terms', '__return_false');
866
+		add_filter('woocommerce_pay_order_button_html', '__return_false');
867
+		add_filter('woocommerce_available_payment_gateways', array($this, '__return_empty_array'));
868
+		add_filter('woocommerce_no_available_payment_methods_message', array($this, 'change_no_available_methods_message'));
869
+		add_action('woocommerce_pay_order_after_submit', array($this, 'render_payment_intent_inputs'));
870 870
 
871 871
 		return array();
872 872
 	}
@@ -879,7 +879,7 @@  discard block
 block discarded – undo
879 879
 	 * @return string the new message.
880 880
 	 */
881 881
 	public function change_no_available_methods_message() {
882
-		return wpautop( __( "Almost there!\n\nYour order has already been created, the only thing that still needs to be done is for you to authorize the payment with your bank.", 'woocommerce-gateway-stripe' ) );
882
+		return wpautop(__("Almost there!\n\nYour order has already been created, the only thing that still needs to be done is for you to authorize the payment with your bank.", 'woocommerce-gateway-stripe'));
883 883
 	}
884 884
 
885 885
 	/**
@@ -888,21 +888,21 @@  discard block
 block discarded – undo
888 888
 	 * @since 4.2
889 889
 	 */
890 890
 	public function render_payment_intent_inputs() {
891
-		$order     = wc_get_order( absint( get_query_var( 'order-pay' ) ) );
892
-		$intent    = $this->get_intent_from_order( $order );
891
+		$order     = wc_get_order(absint(get_query_var('order-pay')));
892
+		$intent    = $this->get_intent_from_order($order);
893 893
 
894 894
 		$verification_url = add_query_arg(
895 895
 			array(
896 896
 				'order'            => $order->get_id(),
897
-				'nonce'            => wp_create_nonce( 'wc_stripe_confirm_pi' ),
898
-				'redirect_to'      => rawurlencode( $this->get_return_url( $order ) ),
897
+				'nonce'            => wp_create_nonce('wc_stripe_confirm_pi'),
898
+				'redirect_to'      => rawurlencode($this->get_return_url($order)),
899 899
 				'is_pay_for_order' => true,
900 900
 			),
901
-			WC_AJAX::get_endpoint( 'wc_stripe_verify_intent' )
901
+			WC_AJAX::get_endpoint('wc_stripe_verify_intent')
902 902
 		);
903 903
 
904
-		echo '<input type="hidden" id="stripe-intent-id" value="' . esc_attr( $intent->client_secret ) . '" />';
905
-		echo '<input type="hidden" id="stripe-intent-return" value="' . esc_attr( $verification_url ) . '" />';
904
+		echo '<input type="hidden" id="stripe-intent-id" value="' . esc_attr($intent->client_secret) . '" />';
905
+		echo '<input type="hidden" id="stripe-intent-return" value="' . esc_attr($verification_url) . '" />';
906 906
 	}
907 907
 
908 908
 	/**
@@ -912,11 +912,11 @@  discard block
 block discarded – undo
912 912
 	 * @param WC_Payment_Token $token Payment Token.
913 913
 	 * @return string                 Generated payment method HTML
914 914
 	 */
915
-	public function get_saved_payment_method_option_html( $token ) {
916
-		$html          = parent::get_saved_payment_method_option_html( $token );
915
+	public function get_saved_payment_method_option_html($token) {
916
+		$html          = parent::get_saved_payment_method_option_html($token);
917 917
 		$error_wrapper = '<div class="stripe-source-errors" role="alert"></div>';
918 918
 
919
-		return preg_replace( '~</(\w+)>\s*$~', "$error_wrapper</$1>", $html );
919
+		return preg_replace('~</(\w+)>\s*$~', "$error_wrapper</$1>", $html);
920 920
 	}
921 921
 
922 922
 	/**
@@ -926,13 +926,13 @@  discard block
 block discarded – undo
926 926
 	 * @since 4.2.0
927 927
 	 * @param int $order_id The ID that will be used for the thank you page.
928 928
 	 */
929
-	public function check_intent_status_on_order_page( $order_id ) {
930
-		if ( empty( $order_id ) || absint( $order_id ) <= 0 ) {
929
+	public function check_intent_status_on_order_page($order_id) {
930
+		if (empty($order_id) || absint($order_id) <= 0) {
931 931
 			return;
932 932
 		}
933 933
 
934
-		$order = wc_get_order( absint( $order_id ) );
935
-		$this->verify_intent_after_checkout( $order );
934
+		$order = wc_get_order(absint($order_id));
935
+		$this->verify_intent_after_checkout($order);
936 936
 	}
937 937
 
938 938
 	/**
@@ -946,9 +946,9 @@  discard block
 block discarded – undo
946 946
 	 * @param int   $order_id The ID of the order which is being paid for.
947 947
 	 * @return array
948 948
 	 */
949
-	public function modify_successful_payment_result( $result, $order_id ) {
949
+	public function modify_successful_payment_result($result, $order_id) {
950 950
 		// Only redirects with intents need to be modified.
951
-		if ( ! isset( $result['intent_secret'] ) ) {
951
+		if ( ! isset($result['intent_secret'])) {
952 952
 			return $result;
953 953
 		}
954 954
 
@@ -956,14 +956,14 @@  discard block
 block discarded – undo
956 956
 		$verification_url = add_query_arg(
957 957
 			array(
958 958
 				'order'       => $order_id,
959
-				'nonce'       => wp_create_nonce( 'wc_stripe_confirm_pi' ),
960
-				'redirect_to' => rawurlencode( $result['redirect'] ),
959
+				'nonce'       => wp_create_nonce('wc_stripe_confirm_pi'),
960
+				'redirect_to' => rawurlencode($result['redirect']),
961 961
 			),
962
-			WC_AJAX::get_endpoint( 'wc_stripe_verify_intent' )
962
+			WC_AJAX::get_endpoint('wc_stripe_verify_intent')
963 963
 		);
964 964
 
965 965
 		// Combine into a hash.
966
-		$redirect = sprintf( '#confirm-pi-%s:%s', $result['intent_secret'], rawurlencode( $verification_url ) );
966
+		$redirect = sprintf('#confirm-pi-%s:%s', $result['intent_secret'], rawurlencode($verification_url));
967 967
 
968 968
 		return array(
969 969
 			'result'   => 'success',
@@ -978,36 +978,36 @@  discard block
 block discarded – undo
978 978
 	 * @since 4.2.0
979 979
 	 * @param WC_Order $order The order which is in a transitional state.
980 980
 	 */
981
-	public function verify_intent_after_checkout( $order ) {
982
-		if ( 'pending' !== $order->get_status() && 'failed' !== $order->get_status() ) {
981
+	public function verify_intent_after_checkout($order) {
982
+		if ('pending' !== $order->get_status() && 'failed' !== $order->get_status()) {
983 983
 			// If payment has already been completed, this function is redundant.
984 984
 			return;
985 985
 		}
986 986
 
987
-		if ( $order->get_payment_method() !== $this->id ) {
987
+		if ($order->get_payment_method() !== $this->id) {
988 988
 			// If this is not the payment method, an intent would not be available.
989 989
 			return;
990 990
 		}
991 991
 
992
-		$intent = $this->get_intent_from_order( $order );
993
-		if ( ! $intent ) {
992
+		$intent = $this->get_intent_from_order($order);
993
+		if ( ! $intent) {
994 994
 			// No intent, redirect to the order received page for further actions.
995 995
 			return;
996 996
 		}
997 997
 
998
-		if ( $this->lock_order_payment( $order, $intent ) ) {
998
+		if ($this->lock_order_payment($order, $intent)) {
999 999
 			return;
1000 1000
 		}
1001 1001
 
1002
-		if ( 'succeeded' === $intent->status ) {
1002
+		if ('succeeded' === $intent->status) {
1003 1003
 			// Proceed with the payment completion.
1004
-			$this->process_response( end( $intent->charges->data ), $order );
1005
-		} else if ( 'requires_payment_method' === $intent->status ) {
1004
+			$this->process_response(end($intent->charges->data), $order);
1005
+		} else if ('requires_payment_method' === $intent->status) {
1006 1006
 			// `requires_payment_method` means that SCA got denied for the current payment method.
1007
-			$this->failed_sca_auth( $order, $intent );
1007
+			$this->failed_sca_auth($order, $intent);
1008 1008
 		}
1009 1009
 
1010
-		$this->unlock_order_payment( $order );
1010
+		$this->unlock_order_payment($order);
1011 1011
 	}
1012 1012
 
1013 1013
 	/**
@@ -1017,19 +1017,19 @@  discard block
 block discarded – undo
1017 1017
 	 * @param WC_Order $order  The order which should be checked.
1018 1018
 	 * @param object   $intent The intent, associated with the order.
1019 1019
 	 */
1020
-	public function failed_sca_auth( $order, $intent ) {
1020
+	public function failed_sca_auth($order, $intent) {
1021 1021
 		// If the order has already failed, do not repeat the same message.
1022
-		if ( 'failed' === $order->get_status() ) {
1022
+		if ('failed' === $order->get_status()) {
1023 1023
 			return;
1024 1024
 		}
1025 1025
 
1026 1026
 		// Load the right message and update the status.
1027
-		$status_message = ( $intent->last_payment_error )
1027
+		$status_message = ($intent->last_payment_error)
1028 1028
 			/* translators: 1) The error message that was received from Stripe. */
1029
-			? sprintf( __( 'Stripe SCA authentication failed. Reason: %s', 'woocommerce-gateway-stripe' ), $intent->last_payment_error->message )
1030
-			: __( 'Stripe SCA authentication failed.', 'woocommerce-gateway-stripe' );
1031
-		$order->update_status( 'failed', $status_message );
1029
+			? sprintf(__('Stripe SCA authentication failed. Reason: %s', 'woocommerce-gateway-stripe'), $intent->last_payment_error->message)
1030
+			: __('Stripe SCA authentication failed.', 'woocommerce-gateway-stripe');
1031
+		$order->update_status('failed', $status_message);
1032 1032
 
1033
-		$this->send_failed_order_email( $order->get_id() );
1033
+		$this->send_failed_order_email($order->get_id());
1034 1034
 	}
1035 1035
 }
Please login to merge, or discard this patch.
includes/admin/stripe-settings.php 1 patch
Spacing   +52 added lines, -52 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) {
2
+if ( ! defined('ABSPATH')) {
3 3
 	exit;
4 4
 }
5 5
 
@@ -7,146 +7,146 @@  discard block
 block discarded – undo
7 7
 	'wc_stripe_settings',
8 8
 	array(
9 9
 		'enabled'                       => array(
10
-			'title'       => __( 'Enable/Disable', 'woocommerce-gateway-stripe' ),
11
-			'label'       => __( 'Enable Stripe', 'woocommerce-gateway-stripe' ),
10
+			'title'       => __('Enable/Disable', 'woocommerce-gateway-stripe'),
11
+			'label'       => __('Enable Stripe', 'woocommerce-gateway-stripe'),
12 12
 			'type'        => 'checkbox',
13 13
 			'description' => '',
14 14
 			'default'     => 'no',
15 15
 		),
16 16
 		'title'                         => array(
17
-			'title'       => __( 'Title', 'woocommerce-gateway-stripe' ),
17
+			'title'       => __('Title', 'woocommerce-gateway-stripe'),
18 18
 			'type'        => 'text',
19
-			'description' => __( 'This controls the title which the user sees during checkout.', 'woocommerce-gateway-stripe' ),
20
-			'default'     => __( 'Credit Card (Stripe)', 'woocommerce-gateway-stripe' ),
19
+			'description' => __('This controls the title which the user sees during checkout.', 'woocommerce-gateway-stripe'),
20
+			'default'     => __('Credit Card (Stripe)', 'woocommerce-gateway-stripe'),
21 21
 			'desc_tip'    => true,
22 22
 		),
23 23
 		'description'                   => array(
24
-			'title'       => __( 'Description', 'woocommerce-gateway-stripe' ),
24
+			'title'       => __('Description', 'woocommerce-gateway-stripe'),
25 25
 			'type'        => 'text',
26
-			'description' => __( 'This controls the description which the user sees during checkout.', 'woocommerce-gateway-stripe' ),
27
-			'default'     => __( 'Pay with your credit card via Stripe.', 'woocommerce-gateway-stripe' ),
26
+			'description' => __('This controls the description which the user sees during checkout.', 'woocommerce-gateway-stripe'),
27
+			'default'     => __('Pay with your credit card via Stripe.', 'woocommerce-gateway-stripe'),
28 28
 			'desc_tip'    => true,
29 29
 		),
30 30
 		'webhook'                       => array(
31
-			'title'       => __( 'Webhook Endpoints', 'woocommerce-gateway-stripe' ),
31
+			'title'       => __('Webhook Endpoints', 'woocommerce-gateway-stripe'),
32 32
 			'type'        => 'title',
33 33
 			/* translators: webhook URL */
34 34
 			'description' => $this->display_admin_settings_webhook_description(),
35 35
 		),
36 36
 		'testmode'                      => array(
37
-			'title'       => __( 'Test mode', 'woocommerce-gateway-stripe' ),
38
-			'label'       => __( 'Enable Test Mode', 'woocommerce-gateway-stripe' ),
37
+			'title'       => __('Test mode', 'woocommerce-gateway-stripe'),
38
+			'label'       => __('Enable Test Mode', 'woocommerce-gateway-stripe'),
39 39
 			'type'        => 'checkbox',
40
-			'description' => __( 'Place the payment gateway in test mode using test API keys.', 'woocommerce-gateway-stripe' ),
40
+			'description' => __('Place the payment gateway in test mode using test API keys.', 'woocommerce-gateway-stripe'),
41 41
 			'default'     => 'yes',
42 42
 			'desc_tip'    => true,
43 43
 		),
44 44
 		'test_publishable_key'          => array(
45
-			'title'       => __( 'Test Publishable Key', 'woocommerce-gateway-stripe' ),
45
+			'title'       => __('Test Publishable Key', 'woocommerce-gateway-stripe'),
46 46
 			'type'        => 'password',
47
-			'description' => __( 'Get your API keys from your stripe account.', 'woocommerce-gateway-stripe' ),
47
+			'description' => __('Get your API keys from your stripe account.', 'woocommerce-gateway-stripe'),
48 48
 			'default'     => '',
49 49
 			'desc_tip'    => true,
50 50
 		),
51 51
 		'test_secret_key'               => array(
52
-			'title'       => __( 'Test Secret Key', 'woocommerce-gateway-stripe' ),
52
+			'title'       => __('Test Secret Key', 'woocommerce-gateway-stripe'),
53 53
 			'type'        => 'password',
54
-			'description' => __( 'Get your API keys from your stripe account.', 'woocommerce-gateway-stripe' ),
54
+			'description' => __('Get your API keys from your stripe account.', 'woocommerce-gateway-stripe'),
55 55
 			'default'     => '',
56 56
 			'desc_tip'    => true,
57 57
 		),
58 58
 		'publishable_key'               => array(
59
-			'title'       => __( 'Live Publishable Key', 'woocommerce-gateway-stripe' ),
59
+			'title'       => __('Live Publishable Key', 'woocommerce-gateway-stripe'),
60 60
 			'type'        => 'password',
61
-			'description' => __( 'Get your API keys from your stripe account.', 'woocommerce-gateway-stripe' ),
61
+			'description' => __('Get your API keys from your stripe account.', 'woocommerce-gateway-stripe'),
62 62
 			'default'     => '',
63 63
 			'desc_tip'    => true,
64 64
 		),
65 65
 		'secret_key'                    => array(
66
-			'title'       => __( 'Live Secret Key', 'woocommerce-gateway-stripe' ),
66
+			'title'       => __('Live Secret Key', 'woocommerce-gateway-stripe'),
67 67
 			'type'        => 'password',
68
-			'description' => __( 'Get your API keys from your stripe account.', 'woocommerce-gateway-stripe' ),
68
+			'description' => __('Get your API keys from your stripe account.', 'woocommerce-gateway-stripe'),
69 69
 			'default'     => '',
70 70
 			'desc_tip'    => true,
71 71
 		),
72 72
 		'inline_cc_form'                => array(
73
-			'title'       => __( 'Inline Credit Card Form', 'woocommerce-gateway-stripe' ),
73
+			'title'       => __('Inline Credit Card Form', 'woocommerce-gateway-stripe'),
74 74
 			'type'        => 'checkbox',
75
-			'description' => __( 'Choose the style you want to show for your credit card form. When unchecked, the credit card form will display separate credit card number field, expiry date field and cvc field.', 'woocommerce-gateway-stripe' ),
75
+			'description' => __('Choose the style you want to show for your credit card form. When unchecked, the credit card form will display separate credit card number field, expiry date field and cvc field.', 'woocommerce-gateway-stripe'),
76 76
 			'default'     => 'no',
77 77
 			'desc_tip'    => true,
78 78
 		),
79 79
 		'statement_descriptor'          => array(
80
-			'title'       => __( 'Statement Descriptor', 'woocommerce-gateway-stripe' ),
80
+			'title'       => __('Statement Descriptor', 'woocommerce-gateway-stripe'),
81 81
 			'type'        => 'text',
82
-			'description' => __( 'Statement descriptors are limited to 22 characters, cannot use the special characters >, <, ", \, \', *, and must not consist solely of numbers. This will appear on your customer\'s statement in capital letters.', 'woocommerce-gateway-stripe' ),
82
+			'description' => __('Statement descriptors are limited to 22 characters, cannot use the special characters >, <, ", \, \', *, and must not consist solely of numbers. This will appear on your customer\'s statement in capital letters.', 'woocommerce-gateway-stripe'),
83 83
 			'default'     => '',
84 84
 			'desc_tip'    => true,
85 85
 		),
86 86
 		'capture'                       => array(
87
-			'title'       => __( 'Capture', 'woocommerce-gateway-stripe' ),
88
-			'label'       => __( 'Capture charge immediately', 'woocommerce-gateway-stripe' ),
87
+			'title'       => __('Capture', 'woocommerce-gateway-stripe'),
88
+			'label'       => __('Capture charge immediately', 'woocommerce-gateway-stripe'),
89 89
 			'type'        => 'checkbox',
90
-			'description' => __( 'Whether or not to immediately capture the charge. When unchecked, the charge issues an authorization and will need to be captured later. Uncaptured charges expire in 7 days.', 'woocommerce-gateway-stripe' ),
90
+			'description' => __('Whether or not to immediately capture the charge. When unchecked, the charge issues an authorization and will need to be captured later. Uncaptured charges expire in 7 days.', 'woocommerce-gateway-stripe'),
91 91
 			'default'     => 'yes',
92 92
 			'desc_tip'    => true,
93 93
 		),
94 94
 		'payment_request'               => array(
95
-			'title'       => __( 'Payment Request Buttons', 'woocommerce-gateway-stripe' ),
95
+			'title'       => __('Payment Request Buttons', 'woocommerce-gateway-stripe'),
96 96
 			/* translators: 1) br tag 2) opening anchor tag 3) closing anchor tag */
97
-			'label'       => sprintf( __( 'Enable Payment Request Buttons. (Apple Pay/Chrome Payment Request API) %1$sBy using Apple Pay, you agree to %2$s and %3$s\'s terms of service.', 'woocommerce-gateway-stripe' ), '<br />', '<a href="https://stripe.com/apple-pay/legal" target="_blank">Stripe</a>', '<a href="https://developer.apple.com/apple-pay/acceptable-use-guidelines-for-websites/" target="_blank">Apple</a>' ),
97
+			'label'       => sprintf(__('Enable Payment Request Buttons. (Apple Pay/Chrome Payment Request API) %1$sBy using Apple Pay, you agree to %2$s and %3$s\'s terms of service.', 'woocommerce-gateway-stripe'), '<br />', '<a href="https://stripe.com/apple-pay/legal" target="_blank">Stripe</a>', '<a href="https://developer.apple.com/apple-pay/acceptable-use-guidelines-for-websites/" target="_blank">Apple</a>'),
98 98
 			'type'        => 'checkbox',
99
-			'description' => __( 'If enabled, users will be able to pay using Apple Pay or Chrome Payment Request if supported by the browser.', 'woocommerce-gateway-stripe' ),
99
+			'description' => __('If enabled, users will be able to pay using Apple Pay or Chrome Payment Request if supported by the browser.', 'woocommerce-gateway-stripe'),
100 100
 			'default'     => 'yes',
101 101
 			'desc_tip'    => true,
102 102
 		),
103 103
 		'payment_request_button_type'   => array(
104
-			'title'       => __( 'Payment Request Button Type', 'woocommerce-gateway-stripe' ),
105
-			'label'       => __( 'Button Type', 'woocommerce-gateway-stripe' ),
104
+			'title'       => __('Payment Request Button Type', 'woocommerce-gateway-stripe'),
105
+			'label'       => __('Button Type', 'woocommerce-gateway-stripe'),
106 106
 			'type'        => 'select',
107
-			'description' => __( 'Select the button type you would like to show.', 'woocommerce-gateway-stripe' ),
107
+			'description' => __('Select the button type you would like to show.', 'woocommerce-gateway-stripe'),
108 108
 			'default'     => 'buy',
109 109
 			'desc_tip'    => true,
110 110
 			'options'     => array(
111
-				'default' => __( 'Default', 'woocommerce-gateway-stripe' ),
112
-				'buy'     => __( 'Buy', 'woocommerce-gateway-stripe' ),
113
-				'donate'  => __( 'Donate', 'woocommerce-gateway-stripe' ),
111
+				'default' => __('Default', 'woocommerce-gateway-stripe'),
112
+				'buy'     => __('Buy', 'woocommerce-gateway-stripe'),
113
+				'donate'  => __('Donate', 'woocommerce-gateway-stripe'),
114 114
 			),
115 115
 		),
116 116
 		'payment_request_button_theme'  => array(
117
-			'title'       => __( 'Payment Request Button Theme', 'woocommerce-gateway-stripe' ),
118
-			'label'       => __( 'Button Theme', 'woocommerce-gateway-stripe' ),
117
+			'title'       => __('Payment Request Button Theme', 'woocommerce-gateway-stripe'),
118
+			'label'       => __('Button Theme', 'woocommerce-gateway-stripe'),
119 119
 			'type'        => 'select',
120
-			'description' => __( 'Select the button theme you would like to show.', 'woocommerce-gateway-stripe' ),
120
+			'description' => __('Select the button theme you would like to show.', 'woocommerce-gateway-stripe'),
121 121
 			'default'     => 'dark',
122 122
 			'desc_tip'    => true,
123 123
 			'options'     => array(
124
-				'dark'          => __( 'Dark', 'woocommerce-gateway-stripe' ),
125
-				'light'         => __( 'Light', 'woocommerce-gateway-stripe' ),
126
-				'light-outline' => __( 'Light-Outline', 'woocommerce-gateway-stripe' ),
124
+				'dark'          => __('Dark', 'woocommerce-gateway-stripe'),
125
+				'light'         => __('Light', 'woocommerce-gateway-stripe'),
126
+				'light-outline' => __('Light-Outline', 'woocommerce-gateway-stripe'),
127 127
 			),
128 128
 		),
129 129
 		'payment_request_button_height' => array(
130
-			'title'       => __( 'Payment Request Button Height', 'woocommerce-gateway-stripe' ),
131
-			'label'       => __( 'Button Height', 'woocommerce-gateway-stripe' ),
130
+			'title'       => __('Payment Request Button Height', 'woocommerce-gateway-stripe'),
131
+			'label'       => __('Button Height', 'woocommerce-gateway-stripe'),
132 132
 			'type'        => 'text',
133
-			'description' => __( 'Enter the height you would like the button to be in pixels. Width will always be 100%.', 'woocommerce-gateway-stripe' ),
133
+			'description' => __('Enter the height you would like the button to be in pixels. Width will always be 100%.', 'woocommerce-gateway-stripe'),
134 134
 			'default'     => '44',
135 135
 			'desc_tip'    => true,
136 136
 		),
137 137
 		'saved_cards'                   => array(
138
-			'title'       => __( 'Saved Cards', 'woocommerce-gateway-stripe' ),
139
-			'label'       => __( 'Enable Payment via Saved Cards', 'woocommerce-gateway-stripe' ),
138
+			'title'       => __('Saved Cards', 'woocommerce-gateway-stripe'),
139
+			'label'       => __('Enable Payment via Saved Cards', 'woocommerce-gateway-stripe'),
140 140
 			'type'        => 'checkbox',
141
-			'description' => __( 'If enabled, users will be able to pay with a saved card during checkout. Card details are saved on Stripe servers, not on your store.', 'woocommerce-gateway-stripe' ),
141
+			'description' => __('If enabled, users will be able to pay with a saved card during checkout. Card details are saved on Stripe servers, not on your store.', 'woocommerce-gateway-stripe'),
142 142
 			'default'     => 'yes',
143 143
 			'desc_tip'    => true,
144 144
 		),
145 145
 		'logging'                       => array(
146
-			'title'       => __( 'Logging', 'woocommerce-gateway-stripe' ),
147
-			'label'       => __( 'Log debug messages', 'woocommerce-gateway-stripe' ),
146
+			'title'       => __('Logging', 'woocommerce-gateway-stripe'),
147
+			'label'       => __('Log debug messages', 'woocommerce-gateway-stripe'),
148 148
 			'type'        => 'checkbox',
149
-			'description' => __( 'Save debug messages to the WooCommerce System Status log.', 'woocommerce-gateway-stripe' ),
149
+			'description' => __('Save debug messages to the WooCommerce System Status log.', 'woocommerce-gateway-stripe'),
150 150
 			'default'     => 'no',
151 151
 			'desc_tip'    => true,
152 152
 		),
Please login to merge, or discard this patch.
includes/payment-methods/class-wc-stripe-payment-request.php 1 patch
Spacing   +297 added lines, -297 removed lines patch added patch discarded remove patch
@@ -6,7 +6,7 @@  discard block
 block discarded – undo
6 6
  * @since   4.0.0
7 7
  */
8 8
 
9
-if ( ! defined( 'ABSPATH' ) ) {
9
+if ( ! defined('ABSPATH')) {
10 10
 	exit;
11 11
 }
12 12
 
@@ -64,41 +64,41 @@  discard block
 block discarded – undo
64 64
 	 */
65 65
 	public function __construct() {
66 66
 		self::$_this            = $this;
67
-		$this->stripe_settings  = get_option( 'woocommerce_stripe_settings', array() );
68
-		$this->testmode         = ( ! empty( $this->stripe_settings['testmode'] ) && 'yes' === $this->stripe_settings['testmode'] ) ? true : false;
69
-		$this->publishable_key  = ! empty( $this->stripe_settings['publishable_key'] ) ? $this->stripe_settings['publishable_key'] : '';
70
-		$this->secret_key       = ! empty( $this->stripe_settings['secret_key'] ) ? $this->stripe_settings['secret_key'] : '';
71
-		$this->total_label      = ! empty( $this->stripe_settings['statement_descriptor'] ) ? WC_Stripe_Helper::clean_statement_descriptor( $this->stripe_settings['statement_descriptor'] ) : '';
67
+		$this->stripe_settings  = get_option('woocommerce_stripe_settings', array());
68
+		$this->testmode         = ( ! empty($this->stripe_settings['testmode']) && 'yes' === $this->stripe_settings['testmode']) ? true : false;
69
+		$this->publishable_key  = ! empty($this->stripe_settings['publishable_key']) ? $this->stripe_settings['publishable_key'] : '';
70
+		$this->secret_key       = ! empty($this->stripe_settings['secret_key']) ? $this->stripe_settings['secret_key'] : '';
71
+		$this->total_label      = ! empty($this->stripe_settings['statement_descriptor']) ? WC_Stripe_Helper::clean_statement_descriptor($this->stripe_settings['statement_descriptor']) : '';
72 72
 
73
-		if ( $this->testmode ) {
74
-			$this->publishable_key = ! empty( $this->stripe_settings['test_publishable_key'] ) ? $this->stripe_settings['test_publishable_key'] : '';
75
-			$this->secret_key      = ! empty( $this->stripe_settings['test_secret_key'] ) ? $this->stripe_settings['test_secret_key'] : '';
73
+		if ($this->testmode) {
74
+			$this->publishable_key = ! empty($this->stripe_settings['test_publishable_key']) ? $this->stripe_settings['test_publishable_key'] : '';
75
+			$this->secret_key      = ! empty($this->stripe_settings['test_secret_key']) ? $this->stripe_settings['test_secret_key'] : '';
76 76
 		}
77 77
 
78
-		$this->total_label = str_replace( "'", '', $this->total_label ) . apply_filters( 'wc_stripe_payment_request_total_label_suffix', ' (via WooCommerce)' );
78
+		$this->total_label = str_replace("'", '', $this->total_label) . apply_filters('wc_stripe_payment_request_total_label_suffix', ' (via WooCommerce)');
79 79
 
80 80
 		// Checks if Stripe Gateway is enabled.
81
-		if ( empty( $this->stripe_settings ) || ( isset( $this->stripe_settings['enabled'] ) && 'yes' !== $this->stripe_settings['enabled'] ) ) {
81
+		if (empty($this->stripe_settings) || (isset($this->stripe_settings['enabled']) && 'yes' !== $this->stripe_settings['enabled'])) {
82 82
 			return;
83 83
 		}
84 84
 
85 85
 		// Checks if Payment Request is enabled.
86
-		if ( ! isset( $this->stripe_settings['payment_request'] ) || 'yes' !== $this->stripe_settings['payment_request'] ) {
86
+		if ( ! isset($this->stripe_settings['payment_request']) || 'yes' !== $this->stripe_settings['payment_request']) {
87 87
 			return;
88 88
 		}
89 89
 
90 90
 		// Don't load for change payment method page.
91
-		if ( isset( $_GET['change_payment_method'] ) ) {
91
+		if (isset($_GET['change_payment_method'])) {
92 92
 			return;
93 93
 		}
94 94
 
95
-		$wc_default_country = substr( get_option( 'woocommerce_default_country' ), 0, 2 );
95
+		$wc_default_country = substr(get_option('woocommerce_default_country'), 0, 2);
96 96
 
97
-		if ( ! in_array( $wc_default_country, $this->get_stripe_supported_countries() ) ) {
97
+		if ( ! in_array($wc_default_country, $this->get_stripe_supported_countries())) {
98 98
 			return;
99 99
 		}
100 100
 
101
-		add_action( 'template_redirect', array( $this, 'set_session' ) );
101
+		add_action('template_redirect', array($this, 'set_session'));
102 102
 		$this->init();
103 103
 	}
104 104
 
@@ -109,7 +109,7 @@  discard block
 block discarded – undo
109 109
 	 * @return array The list of countries.
110 110
 	 */
111 111
 	public function get_stripe_supported_countries() {
112
-		return apply_filters( 'wc_stripe_supported_countries', array( 'AT', 'AU', 'BE', 'BR', 'CA', 'CH', 'DE', 'DK', 'EE', 'ES', 'FI', 'FR', 'GB', 'HK', 'IE', 'IN', 'IT', 'JP', 'LT', 'LU', 'LV', 'MX', 'NL', 'NZ', 'NO', 'PH', 'PL', 'PR', 'PT', 'RO', 'SE', 'SG', 'SK', 'US' ) );
112
+		return apply_filters('wc_stripe_supported_countries', array('AT', 'AU', 'BE', 'BR', 'CA', 'CH', 'DE', 'DK', 'EE', 'ES', 'FI', 'FR', 'GB', 'HK', 'IE', 'IN', 'IT', 'JP', 'LT', 'LU', 'LV', 'MX', 'NL', 'NZ', 'NO', 'PH', 'PL', 'PR', 'PT', 'RO', 'SE', 'SG', 'SK', 'US'));
113 113
 	}
114 114
 
115 115
 	/**
@@ -119,7 +119,7 @@  discard block
 block discarded – undo
119 119
 	 * @return bool
120 120
 	 */
121 121
 	public function are_keys_set() {
122
-		if ( empty( $this->secret_key ) || empty( $this->publishable_key ) ) {
122
+		if (empty($this->secret_key) || empty($this->publishable_key)) {
123 123
 			return false;
124 124
 		}
125 125
 
@@ -143,18 +143,18 @@  discard block
 block discarded – undo
143 143
 	 * @since 4.0.0
144 144
 	 */
145 145
 	public function set_session() {
146
-		if ( ! is_product() || ( isset( WC()->session ) && WC()->session->has_session() ) ) {
146
+		if ( ! is_product() || (isset(WC()->session) && WC()->session->has_session())) {
147 147
 			return;
148 148
 		}
149 149
 
150
-		$session_class = apply_filters( 'woocommerce_session_handler', 'WC_Session_Handler' );
150
+		$session_class = apply_filters('woocommerce_session_handler', 'WC_Session_Handler');
151 151
 		$wc_session    = new $session_class();
152 152
 
153
-		if ( version_compare( WC_VERSION, '3.3', '>=' ) ) {
153
+		if (version_compare(WC_VERSION, '3.3', '>=')) {
154 154
 			$wc_session->init();
155 155
 		}
156 156
 
157
-		$wc_session->set_customer_session_cookie( true );
157
+		$wc_session->set_customer_session_cookie(true);
158 158
 	}
159 159
 
160 160
 	/**
@@ -164,40 +164,40 @@  discard block
 block discarded – undo
164 164
 	 * @version 4.0.0
165 165
 	 */
166 166
 	public function init() {
167
-		add_action( 'wp_enqueue_scripts', array( $this, 'scripts' ) );
167
+		add_action('wp_enqueue_scripts', array($this, 'scripts'));
168 168
 
169 169
 		/*
170 170
 		 * In order to display the Payment Request button in the correct position,
171 171
 		 * a new hook was added to WooCommerce 3.0. In older versions of WooCommerce,
172 172
 		 * CSS is used to position the button.
173 173
 		 */
174
-		if ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ) {
175
-			add_action( 'woocommerce_after_add_to_cart_button', array( $this, 'display_payment_request_button_html' ), 1 );
176
-			add_action( 'woocommerce_after_add_to_cart_button', array( $this, 'display_payment_request_button_separator_html' ), 2 );
174
+		if (WC_Stripe_Helper::is_wc_lt('3.0')) {
175
+			add_action('woocommerce_after_add_to_cart_button', array($this, 'display_payment_request_button_html'), 1);
176
+			add_action('woocommerce_after_add_to_cart_button', array($this, 'display_payment_request_button_separator_html'), 2);
177 177
 		} else {
178
-			add_action( 'woocommerce_after_add_to_cart_quantity', array( $this, 'display_payment_request_button_html' ), 1 );
179
-			add_action( 'woocommerce_after_add_to_cart_quantity', array( $this, 'display_payment_request_button_separator_html' ), 2 );
178
+			add_action('woocommerce_after_add_to_cart_quantity', array($this, 'display_payment_request_button_html'), 1);
179
+			add_action('woocommerce_after_add_to_cart_quantity', array($this, 'display_payment_request_button_separator_html'), 2);
180 180
 		}
181 181
 
182
-		add_action( 'woocommerce_proceed_to_checkout', array( $this, 'display_payment_request_button_html' ), 1 );
183
-		add_action( 'woocommerce_proceed_to_checkout', array( $this, 'display_payment_request_button_separator_html' ), 2 );
182
+		add_action('woocommerce_proceed_to_checkout', array($this, 'display_payment_request_button_html'), 1);
183
+		add_action('woocommerce_proceed_to_checkout', array($this, 'display_payment_request_button_separator_html'), 2);
184 184
 
185
-		add_action( 'woocommerce_checkout_before_customer_details', array( $this, 'display_payment_request_button_html' ), 1 );
186
-		add_action( 'woocommerce_checkout_before_customer_details', array( $this, 'display_payment_request_button_separator_html' ), 2 );
185
+		add_action('woocommerce_checkout_before_customer_details', array($this, 'display_payment_request_button_html'), 1);
186
+		add_action('woocommerce_checkout_before_customer_details', array($this, 'display_payment_request_button_separator_html'), 2);
187 187
 
188
-		add_action( 'wc_ajax_wc_stripe_get_cart_details', array( $this, 'ajax_get_cart_details' ) );
189
-		add_action( 'wc_ajax_wc_stripe_get_shipping_options', array( $this, 'ajax_get_shipping_options' ) );
190
-		add_action( 'wc_ajax_wc_stripe_update_shipping_method', array( $this, 'ajax_update_shipping_method' ) );
191
-		add_action( 'wc_ajax_wc_stripe_create_order', array( $this, 'ajax_create_order' ) );
192
-		add_action( 'wc_ajax_wc_stripe_add_to_cart', array( $this, 'ajax_add_to_cart' ) );
193
-		add_action( 'wc_ajax_wc_stripe_get_selected_product_data', array( $this, 'ajax_get_selected_product_data' ) );
194
-		add_action( 'wc_ajax_wc_stripe_clear_cart', array( $this, 'ajax_clear_cart' ) );
195
-		add_action( 'wc_ajax_wc_stripe_log_errors', array( $this, 'ajax_log_errors' ) );
188
+		add_action('wc_ajax_wc_stripe_get_cart_details', array($this, 'ajax_get_cart_details'));
189
+		add_action('wc_ajax_wc_stripe_get_shipping_options', array($this, 'ajax_get_shipping_options'));
190
+		add_action('wc_ajax_wc_stripe_update_shipping_method', array($this, 'ajax_update_shipping_method'));
191
+		add_action('wc_ajax_wc_stripe_create_order', array($this, 'ajax_create_order'));
192
+		add_action('wc_ajax_wc_stripe_add_to_cart', array($this, 'ajax_add_to_cart'));
193
+		add_action('wc_ajax_wc_stripe_get_selected_product_data', array($this, 'ajax_get_selected_product_data'));
194
+		add_action('wc_ajax_wc_stripe_clear_cart', array($this, 'ajax_clear_cart'));
195
+		add_action('wc_ajax_wc_stripe_log_errors', array($this, 'ajax_log_errors'));
196 196
 
197
-		add_filter( 'woocommerce_gateway_title', array( $this, 'filter_gateway_title' ), 10, 2 );
198
-		add_filter( 'woocommerce_validate_postcode', array( $this, 'postal_code_validation' ), 10, 3 );
197
+		add_filter('woocommerce_gateway_title', array($this, 'filter_gateway_title'), 10, 2);
198
+		add_filter('woocommerce_validate_postcode', array($this, 'postal_code_validation'), 10, 3);
199 199
 
200
-		add_action( 'woocommerce_checkout_order_processed', array( $this, 'add_order_meta' ), 10, 2 );
200
+		add_action('woocommerce_checkout_order_processed', array($this, 'add_order_meta'), 10, 2);
201 201
 	}
202 202
 
203 203
 	/**
@@ -208,7 +208,7 @@  discard block
 block discarded – undo
208 208
 	 * @return string
209 209
 	 */
210 210
 	public function get_button_type() {
211
-		return isset( $this->stripe_settings['payment_request_button_type'] ) ? $this->stripe_settings['payment_request_button_type'] : 'default';
211
+		return isset($this->stripe_settings['payment_request_button_type']) ? $this->stripe_settings['payment_request_button_type'] : 'default';
212 212
 	}
213 213
 
214 214
 	/**
@@ -219,7 +219,7 @@  discard block
 block discarded – undo
219 219
 	 * @return string
220 220
 	 */
221 221
 	public function get_button_theme() {
222
-		return isset( $this->stripe_settings['payment_request_button_theme'] ) ? $this->stripe_settings['payment_request_button_theme'] : 'dark';
222
+		return isset($this->stripe_settings['payment_request_button_theme']) ? $this->stripe_settings['payment_request_button_theme'] : 'dark';
223 223
 	}
224 224
 
225 225
 	/**
@@ -230,7 +230,7 @@  discard block
 block discarded – undo
230 230
 	 * @return string
231 231
 	 */
232 232
 	public function get_button_height() {
233
-		return isset( $this->stripe_settings['payment_request_button_height'] ) ? str_replace( 'px', '', $this->stripe_settings['payment_request_button_height'] ) : '64';
233
+		return isset($this->stripe_settings['payment_request_button_height']) ? str_replace('px', '', $this->stripe_settings['payment_request_button_height']) : '64';
234 234
 	}
235 235
 
236 236
 	/**
@@ -240,40 +240,40 @@  discard block
 block discarded – undo
240 240
 	 * @version 4.0.0
241 241
 	 */
242 242
 	public function get_product_data() {
243
-		if ( ! is_product() ) {
243
+		if ( ! is_product()) {
244 244
 			return false;
245 245
 		}
246 246
 
247 247
 		global $post;
248 248
 
249
-		$product = wc_get_product( $post->ID );
249
+		$product = wc_get_product($post->ID);
250 250
 
251 251
 		$data  = array();
252 252
 		$items = array();
253 253
 
254 254
 		$items[] = array(
255
-			'label'  => WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $product->name : $product->get_name(),
256
-			'amount' => WC_Stripe_Helper::get_stripe_amount( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $product->price : $product->get_price() ),
255
+			'label'  => WC_Stripe_Helper::is_wc_lt('3.0') ? $product->name : $product->get_name(),
256
+			'amount' => WC_Stripe_Helper::get_stripe_amount(WC_Stripe_Helper::is_wc_lt('3.0') ? $product->price : $product->get_price()),
257 257
 		);
258 258
 
259
-		if ( wc_tax_enabled() ) {
259
+		if (wc_tax_enabled()) {
260 260
 			$items[] = array(
261
-				'label'   => __( 'Tax', 'woocommerce-gateway-stripe' ),
261
+				'label'   => __('Tax', 'woocommerce-gateway-stripe'),
262 262
 				'amount'  => 0,
263 263
 				'pending' => true,
264 264
 			);
265 265
 		}
266 266
 
267
-		if ( wc_shipping_enabled() && $product->needs_shipping() ) {
267
+		if (wc_shipping_enabled() && $product->needs_shipping()) {
268 268
 			$items[] = array(
269
-				'label'   => __( 'Shipping', 'woocommerce-gateway-stripe' ),
269
+				'label'   => __('Shipping', 'woocommerce-gateway-stripe'),
270 270
 				'amount'  => 0,
271 271
 				'pending' => true,
272 272
 			);
273 273
 
274 274
 			$data['shippingOptions'] = array(
275 275
 				'id'     => 'pending',
276
-				'label'  => __( 'Pending', 'woocommerce-gateway-stripe' ),
276
+				'label'  => __('Pending', 'woocommerce-gateway-stripe'),
277 277
 				'detail' => '',
278 278
 				'amount' => 0,
279 279
 			);
@@ -281,41 +281,41 @@  discard block
 block discarded – undo
281 281
 
282 282
 		$data['displayItems'] = $items;
283 283
 		$data['total']        = array(
284
-			'label'   => apply_filters( 'wc_stripe_payment_request_total_label', $this->total_label ),
285
-			'amount'  => WC_Stripe_Helper::get_stripe_amount( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $product->price : $product->get_price() ),
284
+			'label'   => apply_filters('wc_stripe_payment_request_total_label', $this->total_label),
285
+			'amount'  => WC_Stripe_Helper::get_stripe_amount(WC_Stripe_Helper::is_wc_lt('3.0') ? $product->price : $product->get_price()),
286 286
 			'pending' => true,
287 287
 		);
288 288
 
289
-		$data['requestShipping'] = ( wc_shipping_enabled() && $product->needs_shipping() );
290
-		$data['currency']        = strtolower( get_woocommerce_currency() );
291
-		$data['country_code']    = substr( get_option( 'woocommerce_default_country' ), 0, 2 );
289
+		$data['requestShipping'] = (wc_shipping_enabled() && $product->needs_shipping());
290
+		$data['currency']        = strtolower(get_woocommerce_currency());
291
+		$data['country_code']    = substr(get_option('woocommerce_default_country'), 0, 2);
292 292
 
293
-		return apply_filters( 'wc_stripe_payment_request_product_data', $data, $product );
293
+		return apply_filters('wc_stripe_payment_request_product_data', $data, $product);
294 294
 	}
295 295
 
296 296
 	/**
297 297
 	 * Filters the gateway title to reflect Payment Request type
298 298
 	 *
299 299
 	 */
300
-	public function filter_gateway_title( $title, $id ) {
300
+	public function filter_gateway_title($title, $id) {
301 301
 		global $post;
302 302
 
303
-		if ( ! is_object( $post ) ) {
303
+		if ( ! is_object($post)) {
304 304
 			return $title;
305 305
 		}
306 306
 
307
-		if ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ) {
308
-			$method_title = get_post_meta( $post->ID, '_payment_method_title', true );
307
+		if (WC_Stripe_Helper::is_wc_lt('3.0')) {
308
+			$method_title = get_post_meta($post->ID, '_payment_method_title', true);
309 309
 		} else {
310
-			$order        = wc_get_order( $post->ID );
311
-			$method_title = is_object( $order ) ? $order->get_payment_method_title() : '';
310
+			$order        = wc_get_order($post->ID);
311
+			$method_title = is_object($order) ? $order->get_payment_method_title() : '';
312 312
 		}
313 313
 
314
-		if ( 'stripe' === $id && ! empty( $method_title ) && 'Apple Pay (Stripe)' === $method_title ) {
314
+		if ('stripe' === $id && ! empty($method_title) && 'Apple Pay (Stripe)' === $method_title) {
315 315
 			return $method_title;
316 316
 		}
317 317
 
318
-		if ( 'stripe' === $id && ! empty( $method_title ) && 'Chrome Payment Request (Stripe)' === $method_title ) {
318
+		if ('stripe' === $id && ! empty($method_title) && 'Chrome Payment Request (Stripe)' === $method_title) {
319 319
 			return $method_title;
320 320
 		}
321 321
 
@@ -328,16 +328,16 @@  discard block
 block discarded – undo
328 328
 	 * @since 3.1.4
329 329
 	 * @version 4.0.0
330 330
 	 */
331
-	public function postal_code_validation( $valid, $postcode, $country ) {
331
+	public function postal_code_validation($valid, $postcode, $country) {
332 332
 		$gateways = WC()->payment_gateways->get_available_payment_gateways();
333 333
 
334
-		if ( ! isset( $gateways['stripe'] ) ) {
334
+		if ( ! isset($gateways['stripe'])) {
335 335
 			return $valid;
336 336
 		}
337 337
 
338
-		$payment_request_type = isset( $_POST['payment_request_type'] ) ? wc_clean( $_POST['payment_request_type'] ) : '';
338
+		$payment_request_type = isset($_POST['payment_request_type']) ? wc_clean($_POST['payment_request_type']) : '';
339 339
 
340
-		if ( 'apple_pay' !== $payment_request_type ) {
340
+		if ('apple_pay' !== $payment_request_type) {
341 341
 			return $valid;
342 342
 		}
343 343
 
@@ -347,7 +347,7 @@  discard block
 block discarded – undo
347 347
 		 * the order and not let it go through. The remedy for now is just to remove this validation.
348 348
 		 * Note that this only works with shipping providers that don't validate full postal codes.
349 349
 		 */
350
-		if ( 'GB' === $country || 'CA' === $country ) {
350
+		if ('GB' === $country || 'CA' === $country) {
351 351
 			return true;
352 352
 		}
353 353
 
@@ -362,29 +362,29 @@  discard block
 block discarded – undo
362 362
 	 * @param int $order_id
363 363
 	 * @param array $posted_data The posted data from checkout form.
364 364
 	 */
365
-	public function add_order_meta( $order_id, $posted_data ) {
366
-		if ( empty( $_POST['payment_request_type'] ) ) {
365
+	public function add_order_meta($order_id, $posted_data) {
366
+		if (empty($_POST['payment_request_type'])) {
367 367
 			return;
368 368
 		}
369 369
 
370
-		$order = wc_get_order( $order_id );
370
+		$order = wc_get_order($order_id);
371 371
 
372
-		$payment_request_type = wc_clean( $_POST['payment_request_type'] );
372
+		$payment_request_type = wc_clean($_POST['payment_request_type']);
373 373
 
374
-		if ( 'apple_pay' === $payment_request_type ) {
375
-			if ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ) {
376
-				update_post_meta( $order_id, '_payment_method_title', 'Apple Pay (Stripe)' );
374
+		if ('apple_pay' === $payment_request_type) {
375
+			if (WC_Stripe_Helper::is_wc_lt('3.0')) {
376
+				update_post_meta($order_id, '_payment_method_title', 'Apple Pay (Stripe)');
377 377
 			} else {
378
-				$order->set_payment_method_title( 'Apple Pay (Stripe)' );
378
+				$order->set_payment_method_title('Apple Pay (Stripe)');
379 379
 				$order->save();
380 380
 			}
381 381
 		}
382 382
 
383
-		if ( 'payment_request_api' === $payment_request_type ) {
384
-			if ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ) {
385
-				update_post_meta( $order_id, '_payment_method_title', 'Chrome Payment Request (Stripe)' );
383
+		if ('payment_request_api' === $payment_request_type) {
384
+			if (WC_Stripe_Helper::is_wc_lt('3.0')) {
385
+				update_post_meta($order_id, '_payment_method_title', 'Chrome Payment Request (Stripe)');
386 386
 			} else {
387
-				$order->set_payment_method_title( 'Chrome Payment Request (Stripe)' );
387
+				$order->set_payment_method_title('Chrome Payment Request (Stripe)');
388 388
 				$order->save();
389 389
 			}
390 390
 		}
@@ -421,15 +421,15 @@  discard block
 block discarded – undo
421 421
 	 * @return bool
422 422
 	 */
423 423
 	public function allowed_items_in_cart() {
424
-		foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {
425
-			$_product = apply_filters( 'woocommerce_cart_item_product', $cart_item['data'], $cart_item, $cart_item_key );
424
+		foreach (WC()->cart->get_cart() as $cart_item_key => $cart_item) {
425
+			$_product = apply_filters('woocommerce_cart_item_product', $cart_item['data'], $cart_item, $cart_item_key);
426 426
 
427
-			if ( ! in_array( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $_product->product_type : $_product->get_type() ), $this->supported_product_types() ) ) {
427
+			if ( ! in_array((WC_Stripe_Helper::is_wc_lt('3.0') ? $_product->product_type : $_product->get_type()), $this->supported_product_types())) {
428 428
 				return false;
429 429
 			}
430 430
 
431 431
 			// Pre Orders compatbility where we don't support charge upon release.
432
-			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() ) ) {
432
+			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())) {
433 433
 				return false;
434 434
 			}
435 435
 		}
@@ -445,80 +445,80 @@  discard block
 block discarded – undo
445 445
 	 */
446 446
 	public function scripts() {
447 447
 		// If keys are not set bail.
448
-		if ( ! $this->are_keys_set() ) {
449
-			WC_Stripe_Logger::log( 'Keys are not set correctly.' );
448
+		if ( ! $this->are_keys_set()) {
449
+			WC_Stripe_Logger::log('Keys are not set correctly.');
450 450
 			return;
451 451
 		}
452 452
 
453 453
 		// If no SSL bail.
454
-		if ( ! $this->testmode && ! is_ssl() ) {
455
-			WC_Stripe_Logger::log( 'Stripe Payment Request live mode requires SSL.' );
454
+		if ( ! $this->testmode && ! is_ssl()) {
455
+			WC_Stripe_Logger::log('Stripe Payment Request live mode requires SSL.');
456 456
 			return;
457 457
 		}
458 458
 
459
-		if ( ! is_product() && ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) ) {
459
+		if ( ! is_product() && ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order'])) {
460 460
 			return;
461 461
 		}
462 462
 
463
-		if ( is_product() ) {
463
+		if (is_product()) {
464 464
 			global $post;
465 465
 
466
-			$product = wc_get_product( $post->ID );
466
+			$product = wc_get_product($post->ID);
467 467
 
468
-			if ( ! is_object( $product ) || ! in_array( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $product->product_type : $product->get_type() ), $this->supported_product_types() ) ) {
468
+			if ( ! is_object($product) || ! in_array((WC_Stripe_Helper::is_wc_lt('3.0') ? $product->product_type : $product->get_type()), $this->supported_product_types())) {
469 469
 				return;
470 470
 			}
471 471
 
472
-			if ( apply_filters( 'wc_stripe_hide_payment_request_on_product_page', false, $post ) ) {
472
+			if (apply_filters('wc_stripe_hide_payment_request_on_product_page', false, $post)) {
473 473
 				return;
474 474
 			}
475 475
 		}
476 476
 
477
-		$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
477
+		$suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';
478 478
 
479 479
 		$stripe_params = array(
480
-			'ajax_url'        => WC_AJAX::get_endpoint( '%%endpoint%%' ),
480
+			'ajax_url'        => WC_AJAX::get_endpoint('%%endpoint%%'),
481 481
 			'stripe'          => array(
482 482
 				'key'                => $this->publishable_key,
483
-				'allow_prepaid_card' => apply_filters( 'wc_stripe_allow_prepaid_card', true ) ? 'yes' : 'no',
483
+				'allow_prepaid_card' => apply_filters('wc_stripe_allow_prepaid_card', true) ? 'yes' : 'no',
484 484
 			),
485 485
 			'nonce'           => array(
486
-				'payment'                   => wp_create_nonce( 'wc-stripe-payment-request' ),
487
-				'shipping'                  => wp_create_nonce( 'wc-stripe-payment-request-shipping' ),
488
-				'update_shipping'           => wp_create_nonce( 'wc-stripe-update-shipping-method' ),
489
-				'checkout'                  => wp_create_nonce( 'woocommerce-process_checkout' ),
490
-				'add_to_cart'               => wp_create_nonce( 'wc-stripe-add-to-cart' ),
491
-				'get_selected_product_data' => wp_create_nonce( 'wc-stripe-get-selected-product-data' ),
492
-				'log_errors'                => wp_create_nonce( 'wc-stripe-log-errors' ),
493
-				'clear_cart'                => wp_create_nonce( 'wc-stripe-clear-cart' ),
486
+				'payment'                   => wp_create_nonce('wc-stripe-payment-request'),
487
+				'shipping'                  => wp_create_nonce('wc-stripe-payment-request-shipping'),
488
+				'update_shipping'           => wp_create_nonce('wc-stripe-update-shipping-method'),
489
+				'checkout'                  => wp_create_nonce('woocommerce-process_checkout'),
490
+				'add_to_cart'               => wp_create_nonce('wc-stripe-add-to-cart'),
491
+				'get_selected_product_data' => wp_create_nonce('wc-stripe-get-selected-product-data'),
492
+				'log_errors'                => wp_create_nonce('wc-stripe-log-errors'),
493
+				'clear_cart'                => wp_create_nonce('wc-stripe-clear-cart'),
494 494
 			),
495 495
 			'i18n'            => array(
496
-				'no_prepaid_card'  => __( 'Sorry, we\'re not accepting prepaid cards at this time.', 'woocommerce-gateway-stripe' ),
496
+				'no_prepaid_card'  => __('Sorry, we\'re not accepting prepaid cards at this time.', 'woocommerce-gateway-stripe'),
497 497
 				/* translators: Do not translate the [option] placeholder */
498
-				'unknown_shipping' => __( 'Unknown shipping option "[option]".', 'woocommerce-gateway-stripe' ),
498
+				'unknown_shipping' => __('Unknown shipping option "[option]".', 'woocommerce-gateway-stripe'),
499 499
 			),
500 500
 			'checkout'        => array(
501 501
 				'url'            => wc_get_checkout_url(),
502
-				'currency_code'  => strtolower( get_woocommerce_currency() ),
503
-				'country_code'   => substr( get_option( 'woocommerce_default_country' ), 0, 2 ),
502
+				'currency_code'  => strtolower(get_woocommerce_currency()),
503
+				'country_code'   => substr(get_option('woocommerce_default_country'), 0, 2),
504 504
 				'needs_shipping' => WC()->cart->needs_shipping() ? 'yes' : 'no',
505 505
 			),
506 506
 			'button'          => array(
507 507
 				'type'   => $this->get_button_type(),
508 508
 				'theme'  => $this->get_button_theme(),
509 509
 				'height' => $this->get_button_height(),
510
-				'locale' => apply_filters( 'wc_stripe_payment_request_button_locale', substr( get_locale(), 0, 2 ) ), // Default format is en_US.
510
+				'locale' => apply_filters('wc_stripe_payment_request_button_locale', substr(get_locale(), 0, 2)), // Default format is en_US.
511 511
 			),
512 512
 			'is_product_page' => is_product(),
513 513
 			'product'         => $this->get_product_data(),
514 514
 		);
515 515
 
516
-		wp_register_script( 'stripe', 'https://js.stripe.com/v3/', '', '3.0', true );
517
-		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 );
516
+		wp_register_script('stripe', 'https://js.stripe.com/v3/', '', '3.0', true);
517
+		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);
518 518
 
519
-		wp_localize_script( 'wc_stripe_payment_request', 'wc_stripe_payment_request_params', apply_filters( 'wc_stripe_payment_request_params', $stripe_params ) );
519
+		wp_localize_script('wc_stripe_payment_request', 'wc_stripe_payment_request_params', apply_filters('wc_stripe_payment_request_params', $stripe_params));
520 520
 
521
-		wp_enqueue_script( 'wc_stripe_payment_request' );
521
+		wp_enqueue_script('wc_stripe_payment_request');
522 522
 	}
523 523
 
524 524
 	/**
@@ -532,37 +532,37 @@  discard block
 block discarded – undo
532 532
 
533 533
 		$gateways = WC()->payment_gateways->get_available_payment_gateways();
534 534
 
535
-		if ( ! isset( $gateways['stripe'] ) ) {
535
+		if ( ! isset($gateways['stripe'])) {
536 536
 			return;
537 537
 		}
538 538
 
539
-		if ( ! is_cart() && ! is_checkout() && ! is_product() && ! isset( $_GET['pay_for_order'] ) ) {
539
+		if ( ! is_cart() && ! is_checkout() && ! is_product() && ! isset($_GET['pay_for_order'])) {
540 540
 			return;
541 541
 		}
542 542
 
543
-		if ( is_product() && apply_filters( 'wc_stripe_hide_payment_request_on_product_page', false, $post ) ) {
543
+		if (is_product() && apply_filters('wc_stripe_hide_payment_request_on_product_page', false, $post)) {
544 544
 			return;
545 545
 		}
546 546
 
547
-		if ( is_checkout() && ! apply_filters( 'wc_stripe_show_payment_request_on_checkout', false, $post ) ) {
547
+		if (is_checkout() && ! apply_filters('wc_stripe_show_payment_request_on_checkout', false, $post)) {
548 548
 			return;
549 549
 		}
550 550
 
551
-		if ( is_product() ) {
552
-			$product = wc_get_product( $post->ID );
551
+		if (is_product()) {
552
+			$product = wc_get_product($post->ID);
553 553
 
554
-			if ( ! is_object( $product ) || ! in_array( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $product->product_type : $product->get_type() ), $this->supported_product_types() ) ) {
554
+			if ( ! is_object($product) || ! in_array((WC_Stripe_Helper::is_wc_lt('3.0') ? $product->product_type : $product->get_type()), $this->supported_product_types())) {
555 555
 				return;
556 556
 			}
557 557
 
558 558
 			// Pre Orders charge upon release not supported.
559
-			if ( class_exists( 'WC_Pre_Orders_Order' ) && WC_Pre_Orders_Product::product_is_charged_upon_release( $product ) ) {
560
-				WC_Stripe_Logger::log( 'Pre Order charge upon release is not supported. ( Payment Request button disabled )' );
559
+			if (class_exists('WC_Pre_Orders_Order') && WC_Pre_Orders_Product::product_is_charged_upon_release($product)) {
560
+				WC_Stripe_Logger::log('Pre Order charge upon release is not supported. ( Payment Request button disabled )');
561 561
 				return;
562 562
 			}
563 563
 		} else {
564
-			if ( ! $this->allowed_items_in_cart() ) {
565
-				WC_Stripe_Logger::log( 'Items in the cart has unsupported product type ( Payment Request button disabled )' );
564
+			if ( ! $this->allowed_items_in_cart()) {
565
+				WC_Stripe_Logger::log('Items in the cart has unsupported product type ( Payment Request button disabled )');
566 566
 				return;
567 567
 			}
568 568
 		}
@@ -586,42 +586,42 @@  discard block
 block discarded – undo
586 586
 
587 587
 		$gateways = WC()->payment_gateways->get_available_payment_gateways();
588 588
 
589
-		if ( ! isset( $gateways['stripe'] ) ) {
589
+		if ( ! isset($gateways['stripe'])) {
590 590
 			return;
591 591
 		}
592 592
 
593
-		if ( ! is_cart() && ! is_checkout() && ! is_product() && ! isset( $_GET['pay_for_order'] ) ) {
593
+		if ( ! is_cart() && ! is_checkout() && ! is_product() && ! isset($_GET['pay_for_order'])) {
594 594
 			return;
595 595
 		}
596 596
 
597
-		if ( is_product() && apply_filters( 'wc_stripe_hide_payment_request_on_product_page', false, $post ) ) {
597
+		if (is_product() && apply_filters('wc_stripe_hide_payment_request_on_product_page', false, $post)) {
598 598
 			return;
599 599
 		}
600 600
 
601
-		if ( is_checkout() && ! apply_filters( 'wc_stripe_show_payment_request_on_checkout', false, $post ) ) {
601
+		if (is_checkout() && ! apply_filters('wc_stripe_show_payment_request_on_checkout', false, $post)) {
602 602
 			return;
603 603
 		}
604 604
 
605
-		if ( is_product() ) {
606
-			$product = wc_get_product( $post->ID );
605
+		if (is_product()) {
606
+			$product = wc_get_product($post->ID);
607 607
 
608
-			if ( ! is_object( $product ) || ! in_array( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $product->product_type : $product->get_type() ), $this->supported_product_types() ) ) {
608
+			if ( ! is_object($product) || ! in_array((WC_Stripe_Helper::is_wc_lt('3.0') ? $product->product_type : $product->get_type()), $this->supported_product_types())) {
609 609
 				return;
610 610
 			}
611 611
 
612 612
 			// Pre Orders charge upon release not supported.
613
-			if ( class_exists( 'WC_Pre_Orders_Order' ) && WC_Pre_Orders_Product::product_is_charged_upon_release( $product ) ) {
614
-				WC_Stripe_Logger::log( 'Pre Order charge upon release is not supported. ( Payment Request button disabled )' );
613
+			if (class_exists('WC_Pre_Orders_Order') && WC_Pre_Orders_Product::product_is_charged_upon_release($product)) {
614
+				WC_Stripe_Logger::log('Pre Order charge upon release is not supported. ( Payment Request button disabled )');
615 615
 				return;
616 616
 			}
617 617
 		} else {
618
-			if ( ! $this->allowed_items_in_cart() ) {
619
-				WC_Stripe_Logger::log( 'Items in the cart has unsupported product type ( Payment Request button disabled )' );
618
+			if ( ! $this->allowed_items_in_cart()) {
619
+				WC_Stripe_Logger::log('Items in the cart has unsupported product type ( Payment Request button disabled )');
620 620
 				return;
621 621
 			}
622 622
 		}
623 623
 		?>
624
-		<p id="wc-stripe-payment-request-button-separator" style="margin-top:1.5em;text-align:center;display:none;">&mdash; <?php esc_html_e( 'OR', 'woocommerce-gateway-stripe' ); ?> &mdash;</p>
624
+		<p id="wc-stripe-payment-request-button-separator" style="margin-top:1.5em;text-align:center;display:none;">&mdash; <?php esc_html_e('OR', 'woocommerce-gateway-stripe'); ?> &mdash;</p>
625 625
 		<?php
626 626
 	}
627 627
 
@@ -632,11 +632,11 @@  discard block
 block discarded – undo
632 632
 	 * @version 4.0.0
633 633
 	 */
634 634
 	public function ajax_log_errors() {
635
-		check_ajax_referer( 'wc-stripe-log-errors', 'security' );
635
+		check_ajax_referer('wc-stripe-log-errors', 'security');
636 636
 
637
-		$errors = wc_clean( stripslashes( $_POST['errors'] ) );
637
+		$errors = wc_clean(stripslashes($_POST['errors']));
638 638
 
639
-		WC_Stripe_Logger::log( $errors );
639
+		WC_Stripe_Logger::log($errors);
640 640
 
641 641
 		exit;
642 642
 	}
@@ -648,7 +648,7 @@  discard block
 block discarded – undo
648 648
 	 * @version 4.0.0
649 649
 	 */
650 650
 	public function ajax_clear_cart() {
651
-		check_ajax_referer( 'wc-stripe-clear-cart', 'security' );
651
+		check_ajax_referer('wc-stripe-clear-cart', 'security');
652 652
 
653 653
 		WC()->cart->empty_cart();
654 654
 		exit;
@@ -658,10 +658,10 @@  discard block
 block discarded – undo
658 658
 	 * Get cart details.
659 659
 	 */
660 660
 	public function ajax_get_cart_details() {
661
-		check_ajax_referer( 'wc-stripe-payment-request', 'security' );
661
+		check_ajax_referer('wc-stripe-payment-request', 'security');
662 662
 
663
-		if ( ! defined( 'WOOCOMMERCE_CART' ) ) {
664
-			define( 'WOOCOMMERCE_CART', true );
663
+		if ( ! defined('WOOCOMMERCE_CART')) {
664
+			define('WOOCOMMERCE_CART', true);
665 665
 		}
666 666
 
667 667
 		WC()->cart->calculate_totals();
@@ -672,14 +672,14 @@  discard block
 block discarded – undo
672 672
 		$data = array(
673 673
 			'shipping_required' => WC()->cart->needs_shipping(),
674 674
 			'order_data'        => array(
675
-				'currency'     => strtolower( $currency ),
676
-				'country_code' => substr( get_option( 'woocommerce_default_country' ), 0, 2 ),
675
+				'currency'     => strtolower($currency),
676
+				'country_code' => substr(get_option('woocommerce_default_country'), 0, 2),
677 677
 			),
678 678
 		);
679 679
 
680 680
 		$data['order_data'] += $this->build_display_items();
681 681
 
682
-		wp_send_json( $data );
682
+		wp_send_json($data);
683 683
 	}
684 684
 
685 685
 	/**
@@ -690,7 +690,7 @@  discard block
 block discarded – undo
690 690
 	 * @see WC_Shipping::get_packages().
691 691
 	 */
692 692
 	public function ajax_get_shipping_options() {
693
-		check_ajax_referer( 'wc-stripe-payment-request-shipping', 'security' );
693
+		check_ajax_referer('wc-stripe-payment-request-shipping', 'security');
694 694
 
695 695
 		try {
696 696
 			// Set the shipping package.
@@ -706,34 +706,34 @@  discard block
 block discarded – undo
706 706
 				)
707 707
 			);
708 708
 
709
-			$this->calculate_shipping( apply_filters( 'wc_stripe_payment_request_shipping_posted_values', $posted ) );
709
+			$this->calculate_shipping(apply_filters('wc_stripe_payment_request_shipping_posted_values', $posted));
710 710
 
711 711
 			// Set the shipping options.
712 712
 			$data     = array();
713 713
 			$packages = WC()->shipping->get_packages();
714 714
 
715
-			if ( ! empty( $packages ) && WC()->customer->has_calculated_shipping() ) {
716
-				foreach ( $packages as $package_key => $package ) {
717
-					if ( empty( $package['rates'] ) ) {
718
-						throw new Exception( __( 'Unable to find shipping method for address.', 'woocommerce-gateway-stripe' ) );
715
+			if ( ! empty($packages) && WC()->customer->has_calculated_shipping()) {
716
+				foreach ($packages as $package_key => $package) {
717
+					if (empty($package['rates'])) {
718
+						throw new Exception(__('Unable to find shipping method for address.', 'woocommerce-gateway-stripe'));
719 719
 					}
720 720
 
721
-					foreach ( $package['rates'] as $key => $rate ) {
721
+					foreach ($package['rates'] as $key => $rate) {
722 722
 						$data['shipping_options'][] = array(
723 723
 							'id'     => $rate->id,
724 724
 							'label'  => $rate->label,
725 725
 							'detail' => '',
726
-							'amount' => WC_Stripe_Helper::get_stripe_amount( $rate->cost ),
726
+							'amount' => WC_Stripe_Helper::get_stripe_amount($rate->cost),
727 727
 						);
728 728
 					}
729 729
 				}
730 730
 			} else {
731
-				throw new Exception( __( 'Unable to find shipping method for address.', 'woocommerce-gateway-stripe' ) );
731
+				throw new Exception(__('Unable to find shipping method for address.', 'woocommerce-gateway-stripe'));
732 732
 			}
733 733
 
734
-			if ( isset( $data[0] ) ) {
734
+			if (isset($data[0])) {
735 735
 				// Auto select the first shipping method.
736
-				WC()->session->set( 'chosen_shipping_methods', array( $data[0]['id'] ) );
736
+				WC()->session->set('chosen_shipping_methods', array($data[0]['id']));
737 737
 			}
738 738
 
739 739
 			WC()->cart->calculate_totals();
@@ -741,12 +741,12 @@  discard block
 block discarded – undo
741 741
 			$data          += $this->build_display_items();
742 742
 			$data['result'] = 'success';
743 743
 
744
-			wp_send_json( $data );
745
-		} catch ( Exception $e ) {
744
+			wp_send_json($data);
745
+		} catch (Exception $e) {
746 746
 			$data          += $this->build_display_items();
747 747
 			$data['result'] = 'invalid_shipping_address';
748 748
 
749
-			wp_send_json( $data );
749
+			wp_send_json($data);
750 750
 		}
751 751
 	}
752 752
 
@@ -754,22 +754,22 @@  discard block
 block discarded – undo
754 754
 	 * Update shipping method.
755 755
 	 */
756 756
 	public function ajax_update_shipping_method() {
757
-		check_ajax_referer( 'wc-stripe-update-shipping-method', 'security' );
757
+		check_ajax_referer('wc-stripe-update-shipping-method', 'security');
758 758
 
759
-		if ( ! defined( 'WOOCOMMERCE_CART' ) ) {
760
-			define( 'WOOCOMMERCE_CART', true );
759
+		if ( ! defined('WOOCOMMERCE_CART')) {
760
+			define('WOOCOMMERCE_CART', true);
761 761
 		}
762 762
 
763
-		$chosen_shipping_methods = WC()->session->get( 'chosen_shipping_methods' );
764
-		$shipping_method         = filter_input( INPUT_POST, 'shipping_method', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY );
763
+		$chosen_shipping_methods = WC()->session->get('chosen_shipping_methods');
764
+		$shipping_method         = filter_input(INPUT_POST, 'shipping_method', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY);
765 765
 
766
-		if ( is_array( $shipping_method ) ) {
767
-			foreach ( $shipping_method as $i => $value ) {
768
-				$chosen_shipping_methods[ $i ] = wc_clean( $value );
766
+		if (is_array($shipping_method)) {
767
+			foreach ($shipping_method as $i => $value) {
768
+				$chosen_shipping_methods[$i] = wc_clean($value);
769 769
 			}
770 770
 		}
771 771
 
772
-		WC()->session->set( 'chosen_shipping_methods', $chosen_shipping_methods );
772
+		WC()->session->set('chosen_shipping_methods', $chosen_shipping_methods);
773 773
 
774 774
 		WC()->cart->calculate_totals();
775 775
 
@@ -777,7 +777,7 @@  discard block
 block discarded – undo
777 777
 		$data          += $this->build_display_items();
778 778
 		$data['result'] = 'success';
779 779
 
780
-		wp_send_json( $data );
780
+		wp_send_json($data);
781 781
 	}
782 782
 
783 783
 	/**
@@ -788,46 +788,46 @@  discard block
 block discarded – undo
788 788
 	 * @return array $data
789 789
 	 */
790 790
 	public function ajax_get_selected_product_data() {
791
-		check_ajax_referer( 'wc-stripe-get-selected-product-data', 'security' );
791
+		check_ajax_referer('wc-stripe-get-selected-product-data', 'security');
792 792
 
793 793
 		try {
794
-			$product_id   = absint( $_POST['product_id'] );
795
-			$qty          = ! isset( $_POST['qty'] ) ? 1 : apply_filters( 'woocommerce_add_to_cart_quantity', absint( $_POST['qty'] ), $product_id );
796
-			$product      = wc_get_product( $product_id );
794
+			$product_id   = absint($_POST['product_id']);
795
+			$qty          = ! isset($_POST['qty']) ? 1 : apply_filters('woocommerce_add_to_cart_quantity', absint($_POST['qty']), $product_id);
796
+			$product      = wc_get_product($product_id);
797 797
 			$variation_id = null;
798 798
 
799
-			if ( ! is_a( $product, 'WC_Product' ) ) {
800
-				throw new Exception( sprintf( __( 'Product with the ID (%d) cannot be found.', 'woocommerce-gateway-stripe' ), $product_id ) );
799
+			if ( ! is_a($product, 'WC_Product')) {
800
+				throw new Exception(sprintf(__('Product with the ID (%d) cannot be found.', 'woocommerce-gateway-stripe'), $product_id));
801 801
 			}
802 802
 
803
-			if ( 'variable' === ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $product->product_type : $product->get_type() ) && isset( $_POST['attributes'] ) ) {
804
-				$attributes = array_map( 'wc_clean', $_POST['attributes'] );
803
+			if ('variable' === (WC_Stripe_Helper::is_wc_lt('3.0') ? $product->product_type : $product->get_type()) && isset($_POST['attributes'])) {
804
+				$attributes = array_map('wc_clean', $_POST['attributes']);
805 805
 
806
-				if ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ) {
807
-					$variation_id = $product->get_matching_variation( $attributes );
806
+				if (WC_Stripe_Helper::is_wc_lt('3.0')) {
807
+					$variation_id = $product->get_matching_variation($attributes);
808 808
 				} else {
809
-					$data_store   = WC_Data_Store::load( 'product' );
810
-					$variation_id = $data_store->find_matching_product_variation( $product, $attributes );
809
+					$data_store   = WC_Data_Store::load('product');
810
+					$variation_id = $data_store->find_matching_product_variation($product, $attributes);
811 811
 				}
812 812
 
813
-				if ( ! empty( $variation_id ) ) {
814
-					$product = wc_get_product( $variation_id );
813
+				if ( ! empty($variation_id)) {
814
+					$product = wc_get_product($variation_id);
815 815
 				}
816
-			} elseif ( 'simple' === ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $product->product_type : $product->get_type() ) ) {
817
-				$product = wc_get_product( $product_id );
816
+			} elseif ('simple' === (WC_Stripe_Helper::is_wc_lt('3.0') ? $product->product_type : $product->get_type())) {
817
+				$product = wc_get_product($product_id);
818 818
 			}
819 819
 
820 820
 			// Force quantity to 1 if sold individually and check for existing item in cart.
821
-			if ( $product->is_sold_individually() ) {
822
-				$qty = apply_filters( 'wc_stripe_payment_request_add_to_cart_sold_individually_quantity', 1, $qty, $product_id, $variation_id );
821
+			if ($product->is_sold_individually()) {
822
+				$qty = apply_filters('wc_stripe_payment_request_add_to_cart_sold_individually_quantity', 1, $qty, $product_id, $variation_id);
823 823
 			}
824 824
 
825
-			if ( ! $product->has_enough_stock( $qty ) ) {
825
+			if ( ! $product->has_enough_stock($qty)) {
826 826
 				/* translators: 1: product name 2: quantity in stock */
827
-				throw new Exception( sprintf( __( 'You cannot add that amount of "%1$s"; to the cart because there is not enough stock (%2$s remaining).', 'woocommerce-gateway-stripe' ), $product->get_name(), wc_format_stock_quantity_for_display( $product->get_stock_quantity(), $product ) ) );
827
+				throw new Exception(sprintf(__('You cannot add that amount of "%1$s"; to the cart because there is not enough stock (%2$s remaining).', 'woocommerce-gateway-stripe'), $product->get_name(), wc_format_stock_quantity_for_display($product->get_stock_quantity(), $product)));
828 828
 			}
829 829
 
830
-			$total = $qty * ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $product->price : $product->get_price() );
830
+			$total = $qty * (WC_Stripe_Helper::is_wc_lt('3.0') ? $product->price : $product->get_price());
831 831
 
832 832
 			$quantity_label = 1 < $qty ? ' (x' . $qty . ')' : '';
833 833
 
@@ -835,28 +835,28 @@  discard block
 block discarded – undo
835 835
 			$items = array();
836 836
 
837 837
 			$items[] = array(
838
-				'label'  => ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $product->name : $product->get_name() ) . $quantity_label,
839
-				'amount' => WC_Stripe_Helper::get_stripe_amount( $total ),
838
+				'label'  => (WC_Stripe_Helper::is_wc_lt('3.0') ? $product->name : $product->get_name()) . $quantity_label,
839
+				'amount' => WC_Stripe_Helper::get_stripe_amount($total),
840 840
 			);
841 841
 
842
-			if ( wc_tax_enabled() ) {
842
+			if (wc_tax_enabled()) {
843 843
 				$items[] = array(
844
-					'label'   => __( 'Tax', 'woocommerce-gateway-stripe' ),
844
+					'label'   => __('Tax', 'woocommerce-gateway-stripe'),
845 845
 					'amount'  => 0,
846 846
 					'pending' => true,
847 847
 				);
848 848
 			}
849 849
 
850
-			if ( wc_shipping_enabled() && $product->needs_shipping() ) {
850
+			if (wc_shipping_enabled() && $product->needs_shipping()) {
851 851
 				$items[] = array(
852
-					'label'   => __( 'Shipping', 'woocommerce-gateway-stripe' ),
852
+					'label'   => __('Shipping', 'woocommerce-gateway-stripe'),
853 853
 					'amount'  => 0,
854 854
 					'pending' => true,
855 855
 				);
856 856
 
857 857
 				$data['shippingOptions'] = array(
858 858
 					'id'     => 'pending',
859
-					'label'  => __( 'Pending', 'woocommerce-gateway-stripe' ),
859
+					'label'  => __('Pending', 'woocommerce-gateway-stripe'),
860 860
 					'detail' => '',
861 861
 					'amount' => 0,
862 862
 				);
@@ -865,17 +865,17 @@  discard block
 block discarded – undo
865 865
 			$data['displayItems'] = $items;
866 866
 			$data['total']        = array(
867 867
 				'label'   => $this->total_label,
868
-				'amount'  => WC_Stripe_Helper::get_stripe_amount( $total ),
868
+				'amount'  => WC_Stripe_Helper::get_stripe_amount($total),
869 869
 				'pending' => true,
870 870
 			);
871 871
 
872
-			$data['requestShipping'] = ( wc_shipping_enabled() && $product->needs_shipping() );
873
-			$data['currency']        = strtolower( get_woocommerce_currency() );
874
-			$data['country_code']    = substr( get_option( 'woocommerce_default_country' ), 0, 2 );
872
+			$data['requestShipping'] = (wc_shipping_enabled() && $product->needs_shipping());
873
+			$data['currency']        = strtolower(get_woocommerce_currency());
874
+			$data['country_code']    = substr(get_option('woocommerce_default_country'), 0, 2);
875 875
 
876
-			wp_send_json( $data );
877
-		} catch ( Exception $e ) {
878
-			wp_send_json( array( 'error' => wp_strip_all_tags( $e->getMessage() ) ) );
876
+			wp_send_json($data);
877
+		} catch (Exception $e) {
878
+			wp_send_json(array('error' => wp_strip_all_tags($e->getMessage())));
879 879
 		}
880 880
 	}
881 881
 
@@ -887,36 +887,36 @@  discard block
 block discarded – undo
887 887
 	 * @return array $data
888 888
 	 */
889 889
 	public function ajax_add_to_cart() {
890
-		check_ajax_referer( 'wc-stripe-add-to-cart', 'security' );
890
+		check_ajax_referer('wc-stripe-add-to-cart', 'security');
891 891
 
892
-		if ( ! defined( 'WOOCOMMERCE_CART' ) ) {
893
-			define( 'WOOCOMMERCE_CART', true );
892
+		if ( ! defined('WOOCOMMERCE_CART')) {
893
+			define('WOOCOMMERCE_CART', true);
894 894
 		}
895 895
 
896 896
 		WC()->shipping->reset_shipping();
897 897
 
898
-		$product_id = absint( $_POST['product_id'] );
899
-		$qty        = ! isset( $_POST['qty'] ) ? 1 : absint( $_POST['qty'] );
900
-		$product    = wc_get_product( $product_id );
898
+		$product_id = absint($_POST['product_id']);
899
+		$qty        = ! isset($_POST['qty']) ? 1 : absint($_POST['qty']);
900
+		$product    = wc_get_product($product_id);
901 901
 
902 902
 		// First empty the cart to prevent wrong calculation.
903 903
 		WC()->cart->empty_cart();
904 904
 
905
-		if ( 'variable' === ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $product->product_type : $product->get_type() ) && isset( $_POST['attributes'] ) ) {
906
-			$attributes = array_map( 'wc_clean', $_POST['attributes'] );
905
+		if ('variable' === (WC_Stripe_Helper::is_wc_lt('3.0') ? $product->product_type : $product->get_type()) && isset($_POST['attributes'])) {
906
+			$attributes = array_map('wc_clean', $_POST['attributes']);
907 907
 
908
-			if ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ) {
909
-				$variation_id = $product->get_matching_variation( $attributes );
908
+			if (WC_Stripe_Helper::is_wc_lt('3.0')) {
909
+				$variation_id = $product->get_matching_variation($attributes);
910 910
 			} else {
911
-				$data_store   = WC_Data_Store::load( 'product' );
912
-				$variation_id = $data_store->find_matching_product_variation( $product, $attributes );
911
+				$data_store   = WC_Data_Store::load('product');
912
+				$variation_id = $data_store->find_matching_product_variation($product, $attributes);
913 913
 			}
914 914
 
915
-			WC()->cart->add_to_cart( $product->get_id(), $qty, $variation_id, $attributes );
915
+			WC()->cart->add_to_cart($product->get_id(), $qty, $variation_id, $attributes);
916 916
 		}
917 917
 
918
-		if ( 'simple' === ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $product->product_type : $product->get_type() ) ) {
919
-			WC()->cart->add_to_cart( $product->get_id(), $qty );
918
+		if ('simple' === (WC_Stripe_Helper::is_wc_lt('3.0') ? $product->product_type : $product->get_type())) {
919
+			WC()->cart->add_to_cart($product->get_id(), $qty);
920 920
 		}
921 921
 
922 922
 		WC()->cart->calculate_totals();
@@ -925,7 +925,7 @@  discard block
 block discarded – undo
925 925
 		$data          += $this->build_display_items();
926 926
 		$data['result'] = 'success';
927 927
 
928
-		wp_send_json( $data );
928
+		wp_send_json($data);
929 929
 	}
930 930
 
931 931
 	/**
@@ -938,31 +938,31 @@  discard block
 block discarded – undo
938 938
 	 * @version 4.0.0
939 939
 	 */
940 940
 	public function normalize_state() {
941
-		$billing_country  = ! empty( $_POST['billing_country'] ) ? wc_clean( $_POST['billing_country'] ) : '';
942
-		$shipping_country = ! empty( $_POST['shipping_country'] ) ? wc_clean( $_POST['shipping_country'] ) : '';
943
-		$billing_state    = ! empty( $_POST['billing_state'] ) ? wc_clean( $_POST['billing_state'] ) : '';
944
-		$shipping_state   = ! empty( $_POST['shipping_state'] ) ? wc_clean( $_POST['shipping_state'] ) : '';
941
+		$billing_country  = ! empty($_POST['billing_country']) ? wc_clean($_POST['billing_country']) : '';
942
+		$shipping_country = ! empty($_POST['shipping_country']) ? wc_clean($_POST['shipping_country']) : '';
943
+		$billing_state    = ! empty($_POST['billing_state']) ? wc_clean($_POST['billing_state']) : '';
944
+		$shipping_state   = ! empty($_POST['shipping_state']) ? wc_clean($_POST['shipping_state']) : '';
945 945
 
946
-		if ( $billing_state && $billing_country ) {
947
-			$valid_states = WC()->countries->get_states( $billing_country );
946
+		if ($billing_state && $billing_country) {
947
+			$valid_states = WC()->countries->get_states($billing_country);
948 948
 
949 949
 			// Valid states found for country.
950
-			if ( ! empty( $valid_states ) && is_array( $valid_states ) && sizeof( $valid_states ) > 0 ) {
951
-				foreach ( $valid_states as $state_abbr => $state ) {
952
-					if ( preg_match( '/' . preg_quote( $state ) . '/i', $billing_state ) ) {
950
+			if ( ! empty($valid_states) && is_array($valid_states) && sizeof($valid_states) > 0) {
951
+				foreach ($valid_states as $state_abbr => $state) {
952
+					if (preg_match('/' . preg_quote($state) . '/i', $billing_state)) {
953 953
 						$_POST['billing_state'] = $state_abbr;
954 954
 					}
955 955
 				}
956 956
 			}
957 957
 		}
958 958
 
959
-		if ( $shipping_state && $shipping_country ) {
960
-			$valid_states = WC()->countries->get_states( $shipping_country );
959
+		if ($shipping_state && $shipping_country) {
960
+			$valid_states = WC()->countries->get_states($shipping_country);
961 961
 
962 962
 			// Valid states found for country.
963
-			if ( ! empty( $valid_states ) && is_array( $valid_states ) && sizeof( $valid_states ) > 0 ) {
964
-				foreach ( $valid_states as $state_abbr => $state ) {
965
-					if ( preg_match( '/' . preg_quote( $state ) . '/i', $shipping_state ) ) {
963
+			if ( ! empty($valid_states) && is_array($valid_states) && sizeof($valid_states) > 0) {
964
+				foreach ($valid_states as $state_abbr => $state) {
965
+					if (preg_match('/' . preg_quote($state) . '/i', $shipping_state)) {
966 966
 						$_POST['shipping_state'] = $state_abbr;
967 967
 					}
968 968
 				}
@@ -977,19 +977,19 @@  discard block
 block discarded – undo
977 977
 	 * @version 4.0.0
978 978
 	 */
979 979
 	public function ajax_create_order() {
980
-		if ( WC()->cart->is_empty() ) {
981
-			wp_send_json_error( __( 'Empty cart', 'woocommerce-gateway-stripe' ) );
980
+		if (WC()->cart->is_empty()) {
981
+			wp_send_json_error(__('Empty cart', 'woocommerce-gateway-stripe'));
982 982
 		}
983 983
 
984
-		if ( ! defined( 'WOOCOMMERCE_CHECKOUT' ) ) {
985
-			define( 'WOOCOMMERCE_CHECKOUT', true );
984
+		if ( ! defined('WOOCOMMERCE_CHECKOUT')) {
985
+			define('WOOCOMMERCE_CHECKOUT', true);
986 986
 		}
987 987
 
988 988
 		$this->normalize_state();
989 989
 
990 990
 		WC()->checkout()->process_checkout();
991 991
 
992
-		die( 0 );
992
+		die(0);
993 993
 	}
994 994
 
995 995
 	/**
@@ -999,41 +999,41 @@  discard block
 block discarded – undo
999 999
 	 * @version 4.0.0
1000 1000
 	 * @param array $address
1001 1001
 	 */
1002
-	protected function calculate_shipping( $address = array() ) {
1002
+	protected function calculate_shipping($address = array()) {
1003 1003
 		$country   = $address['country'];
1004 1004
 		$state     = $address['state'];
1005 1005
 		$postcode  = $address['postcode'];
1006 1006
 		$city      = $address['city'];
1007 1007
 		$address_1 = $address['address'];
1008 1008
 		$address_2 = $address['address_2'];
1009
-		$wc_states = WC()->countries->get_states( $country );
1009
+		$wc_states = WC()->countries->get_states($country);
1010 1010
 
1011 1011
 		/**
1012 1012
 		 * In some versions of Chrome, state can be a full name. So we need
1013 1013
 		 * to convert that to abbreviation as WC is expecting that.
1014 1014
 		 */
1015
-		if ( 2 < strlen( $state ) && ! empty( $wc_states ) ) {
1016
-			$state = array_search( ucwords( strtolower( $state ) ), $wc_states, true );
1015
+		if (2 < strlen($state) && ! empty($wc_states)) {
1016
+			$state = array_search(ucwords(strtolower($state)), $wc_states, true);
1017 1017
 		}
1018 1018
 
1019 1019
 		WC()->shipping->reset_shipping();
1020 1020
 
1021
-		if ( $postcode && WC_Validation::is_postcode( $postcode, $country ) ) {
1022
-			$postcode = wc_format_postcode( $postcode, $country );
1021
+		if ($postcode && WC_Validation::is_postcode($postcode, $country)) {
1022
+			$postcode = wc_format_postcode($postcode, $country);
1023 1023
 		}
1024 1024
 
1025
-		if ( $country ) {
1026
-			WC()->customer->set_location( $country, $state, $postcode, $city );
1027
-			WC()->customer->set_shipping_location( $country, $state, $postcode, $city );
1025
+		if ($country) {
1026
+			WC()->customer->set_location($country, $state, $postcode, $city);
1027
+			WC()->customer->set_shipping_location($country, $state, $postcode, $city);
1028 1028
 		} else {
1029
-			WC_Stripe_Helper::is_wc_lt( '3.0' ) ? WC()->customer->set_to_base() : WC()->customer->set_billing_address_to_base();
1030
-			WC_Stripe_Helper::is_wc_lt( '3.0' ) ? WC()->customer->set_shipping_to_base() : WC()->customer->set_shipping_address_to_base();
1029
+			WC_Stripe_Helper::is_wc_lt('3.0') ? WC()->customer->set_to_base() : WC()->customer->set_billing_address_to_base();
1030
+			WC_Stripe_Helper::is_wc_lt('3.0') ? WC()->customer->set_shipping_to_base() : WC()->customer->set_shipping_address_to_base();
1031 1031
 		}
1032 1032
 
1033
-		if ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ) {
1034
-			WC()->customer->calculated_shipping( true );
1033
+		if (WC_Stripe_Helper::is_wc_lt('3.0')) {
1034
+			WC()->customer->calculated_shipping(true);
1035 1035
 		} else {
1036
-			WC()->customer->set_calculated_shipping( true );
1036
+			WC()->customer->set_calculated_shipping(true);
1037 1037
 			WC()->customer->save();
1038 1038
 		}
1039 1039
 
@@ -1050,17 +1050,17 @@  discard block
 block discarded – undo
1050 1050
 		$packages[0]['destination']['address']   = $address_1;
1051 1051
 		$packages[0]['destination']['address_2'] = $address_2;
1052 1052
 
1053
-		foreach ( WC()->cart->get_cart() as $item ) {
1054
-			if ( $item['data']->needs_shipping() ) {
1055
-				if ( isset( $item['line_total'] ) ) {
1053
+		foreach (WC()->cart->get_cart() as $item) {
1054
+			if ($item['data']->needs_shipping()) {
1055
+				if (isset($item['line_total'])) {
1056 1056
 					$packages[0]['contents_cost'] += $item['line_total'];
1057 1057
 				}
1058 1058
 			}
1059 1059
 		}
1060 1060
 
1061
-		$packages = apply_filters( 'woocommerce_cart_shipping_packages', $packages );
1061
+		$packages = apply_filters('woocommerce_cart_shipping_packages', $packages);
1062 1062
 
1063
-		WC()->shipping->calculate_shipping( $packages );
1063
+		WC()->shipping->calculate_shipping($packages);
1064 1064
 	}
1065 1065
 
1066 1066
 	/**
@@ -1069,19 +1069,19 @@  discard block
 block discarded – undo
1069 1069
 	 * @since 3.1.0
1070 1070
 	 * @version 4.0.0
1071 1071
 	 */
1072
-	protected function build_shipping_methods( $shipping_methods ) {
1073
-		if ( empty( $shipping_methods ) ) {
1072
+	protected function build_shipping_methods($shipping_methods) {
1073
+		if (empty($shipping_methods)) {
1074 1074
 			return array();
1075 1075
 		}
1076 1076
 
1077 1077
 		$shipping = array();
1078 1078
 
1079
-		foreach ( $shipping_methods as $method ) {
1079
+		foreach ($shipping_methods as $method) {
1080 1080
 			$shipping[] = array(
1081 1081
 				'id'     => $method['id'],
1082 1082
 				'label'  => $method['label'],
1083 1083
 				'detail' => '',
1084
-				'amount' => WC_Stripe_Helper::get_stripe_amount( $method['amount']['value'] ),
1084
+				'amount' => WC_Stripe_Helper::get_stripe_amount($method['amount']['value']),
1085 1085
 			);
1086 1086
 		}
1087 1087
 
@@ -1095,8 +1095,8 @@  discard block
 block discarded – undo
1095 1095
 	 * @version 4.0.0
1096 1096
 	 */
1097 1097
 	protected function build_display_items() {
1098
-		if ( ! defined( 'WOOCOMMERCE_CART' ) ) {
1099
-			define( 'WOOCOMMERCE_CART', true );
1098
+		if ( ! defined('WOOCOMMERCE_CART')) {
1099
+			define('WOOCOMMERCE_CART', true);
1100 1100
 		}
1101 1101
 
1102 1102
 		$items     = array();
@@ -1104,71 +1104,71 @@  discard block
 block discarded – undo
1104 1104
 		$discounts = 0;
1105 1105
 
1106 1106
 		// Default show only subtotal instead of itemization.
1107
-		if ( ! apply_filters( 'wc_stripe_payment_request_hide_itemization', true ) ) {
1108
-			foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {
1107
+		if ( ! apply_filters('wc_stripe_payment_request_hide_itemization', true)) {
1108
+			foreach (WC()->cart->get_cart() as $cart_item_key => $cart_item) {
1109 1109
 				$amount         = $cart_item['line_subtotal'];
1110 1110
 				$subtotal      += $cart_item['line_subtotal'];
1111 1111
 				$quantity_label = 1 < $cart_item['quantity'] ? ' (x' . $cart_item['quantity'] . ')' : '';
1112 1112
 
1113
-				$product_name = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $cart_item['data']->post->post_title : $cart_item['data']->get_name();
1113
+				$product_name = WC_Stripe_Helper::is_wc_lt('3.0') ? $cart_item['data']->post->post_title : $cart_item['data']->get_name();
1114 1114
 
1115 1115
 				$item = array(
1116 1116
 					'label'  => $product_name . $quantity_label,
1117
-					'amount' => WC_Stripe_Helper::get_stripe_amount( $amount ),
1117
+					'amount' => WC_Stripe_Helper::get_stripe_amount($amount),
1118 1118
 				);
1119 1119
 
1120 1120
 				$items[] = $item;
1121 1121
 			}
1122 1122
 		}
1123 1123
 
1124
-		if ( version_compare( WC_VERSION, '3.2', '<' ) ) {
1125
-			$discounts = wc_format_decimal( WC()->cart->get_cart_discount_total(), WC()->cart->dp );
1124
+		if (version_compare(WC_VERSION, '3.2', '<')) {
1125
+			$discounts = wc_format_decimal(WC()->cart->get_cart_discount_total(), WC()->cart->dp);
1126 1126
 		} else {
1127
-			$applied_coupons = array_values( WC()->cart->get_coupon_discount_totals() );
1127
+			$applied_coupons = array_values(WC()->cart->get_coupon_discount_totals());
1128 1128
 
1129
-			foreach ( $applied_coupons as $amount ) {
1129
+			foreach ($applied_coupons as $amount) {
1130 1130
 				$discounts += (float) $amount;
1131 1131
 			}
1132 1132
 		}
1133 1133
 
1134
-		$discounts   = wc_format_decimal( $discounts, WC()->cart->dp );
1135
-		$tax         = wc_format_decimal( WC()->cart->tax_total + WC()->cart->shipping_tax_total, WC()->cart->dp );
1136
-		$shipping    = wc_format_decimal( WC()->cart->shipping_total, WC()->cart->dp );
1137
-		$items_total = wc_format_decimal( WC()->cart->cart_contents_total, WC()->cart->dp ) + $discounts;
1138
-		$order_total = version_compare( WC_VERSION, '3.2', '<' ) ? wc_format_decimal( $items_total + $tax + $shipping - $discounts, WC()->cart->dp ) : WC()->cart->get_total( false );
1134
+		$discounts   = wc_format_decimal($discounts, WC()->cart->dp);
1135
+		$tax         = wc_format_decimal(WC()->cart->tax_total + WC()->cart->shipping_tax_total, WC()->cart->dp);
1136
+		$shipping    = wc_format_decimal(WC()->cart->shipping_total, WC()->cart->dp);
1137
+		$items_total = wc_format_decimal(WC()->cart->cart_contents_total, WC()->cart->dp) + $discounts;
1138
+		$order_total = version_compare(WC_VERSION, '3.2', '<') ? wc_format_decimal($items_total + $tax + $shipping - $discounts, WC()->cart->dp) : WC()->cart->get_total(false);
1139 1139
 
1140
-		if ( wc_tax_enabled() ) {
1140
+		if (wc_tax_enabled()) {
1141 1141
 			$items[] = array(
1142
-				'label'  => esc_html( __( 'Tax', 'woocommerce-gateway-stripe' ) ),
1143
-				'amount' => WC_Stripe_Helper::get_stripe_amount( $tax ),
1142
+				'label'  => esc_html(__('Tax', 'woocommerce-gateway-stripe')),
1143
+				'amount' => WC_Stripe_Helper::get_stripe_amount($tax),
1144 1144
 			);
1145 1145
 		}
1146 1146
 
1147
-		if ( WC()->cart->needs_shipping() ) {
1147
+		if (WC()->cart->needs_shipping()) {
1148 1148
 			$items[] = array(
1149
-				'label'  => esc_html( __( 'Shipping', 'woocommerce-gateway-stripe' ) ),
1150
-				'amount' => WC_Stripe_Helper::get_stripe_amount( $shipping ),
1149
+				'label'  => esc_html(__('Shipping', 'woocommerce-gateway-stripe')),
1150
+				'amount' => WC_Stripe_Helper::get_stripe_amount($shipping),
1151 1151
 			);
1152 1152
 		}
1153 1153
 
1154
-		if ( WC()->cart->has_discount() ) {
1154
+		if (WC()->cart->has_discount()) {
1155 1155
 			$items[] = array(
1156
-				'label'  => esc_html( __( 'Discount', 'woocommerce-gateway-stripe' ) ),
1157
-				'amount' => WC_Stripe_Helper::get_stripe_amount( $discounts ),
1156
+				'label'  => esc_html(__('Discount', 'woocommerce-gateway-stripe')),
1157
+				'amount' => WC_Stripe_Helper::get_stripe_amount($discounts),
1158 1158
 			);
1159 1159
 		}
1160 1160
 
1161
-		if ( version_compare( WC_VERSION, '3.2', '<' ) ) {
1161
+		if (version_compare(WC_VERSION, '3.2', '<')) {
1162 1162
 			$cart_fees = WC()->cart->fees;
1163 1163
 		} else {
1164 1164
 			$cart_fees = WC()->cart->get_fees();
1165 1165
 		}
1166 1166
 
1167 1167
 		// Include fees and taxes as display items.
1168
-		foreach ( $cart_fees as $key => $fee ) {
1168
+		foreach ($cart_fees as $key => $fee) {
1169 1169
 			$items[] = array(
1170 1170
 				'label'  => $fee->name,
1171
-				'amount' => WC_Stripe_Helper::get_stripe_amount( $fee->amount ),
1171
+				'amount' => WC_Stripe_Helper::get_stripe_amount($fee->amount),
1172 1172
 			);
1173 1173
 		}
1174 1174
 
@@ -1176,7 +1176,7 @@  discard block
 block discarded – undo
1176 1176
 			'displayItems' => $items,
1177 1177
 			'total'        => array(
1178 1178
 				'label'   => $this->total_label,
1179
-				'amount'  => max( 0, apply_filters( 'woocommerce_stripe_calculated_total', WC_Stripe_Helper::get_stripe_amount( $order_total ), $order_total, WC()->cart ) ),
1179
+				'amount'  => max(0, apply_filters('woocommerce_stripe_calculated_total', WC_Stripe_Helper::get_stripe_amount($order_total), $order_total, WC()->cart)),
1180 1180
 				'pending' => false,
1181 1181
 			),
1182 1182
 		);
Please login to merge, or discard this patch.