Completed
Push — master ( 6b3970...b3f03c )
by Roy
04:23
created
includes/class-wc-gateway-stripe.php 1 patch
Spacing   +262 added lines, -262 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
 
@@ -120,9 +120,9 @@  discard block
 block discarded – undo
120 120
 	public function __construct() {
121 121
 		$this->retry_interval       = 1;
122 122
 		$this->id                   = 'stripe';
123
-		$this->method_title         = __( 'Stripe', 'woocommerce-gateway-stripe' );
123
+		$this->method_title         = __('Stripe', 'woocommerce-gateway-stripe');
124 124
 		/* translators: 1) link to Stripe register page 2) link to Stripe api keys page */
125
-		$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' );
125
+		$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');
126 126
 		$this->has_fields           = true;
127 127
 		$this->supports             = array(
128 128
 			'products',
@@ -149,43 +149,43 @@  discard block
 block discarded – undo
149 149
 		$this->init_settings();
150 150
 
151 151
 		// Get setting values.
152
-		$this->title                       = $this->get_option( 'title' );
153
-		$this->description                 = $this->get_option( 'description' );
154
-		$this->enabled                     = $this->get_option( 'enabled' );
155
-		$this->testmode                    = 'yes' === $this->get_option( 'testmode' );
156
-		$this->inline_cc_form              = 'yes' === $this->get_option( 'inline_cc_form' );
157
-		$this->capture                     = 'yes' === $this->get_option( 'capture', 'yes' );
158
-		$this->statement_descriptor        = WC_Stripe_Helper::clean_statement_descriptor( $this->get_option( 'statement_descriptor' ) );
159
-		$this->three_d_secure              = 'yes' === $this->get_option( 'three_d_secure' );
160
-		$this->stripe_checkout             = 'yes' === $this->get_option( 'stripe_checkout' );
161
-		$this->stripe_checkout_image       = $this->get_option( 'stripe_checkout_image', '' );
162
-		$this->stripe_checkout_description = $this->get_option( 'stripe_checkout_description' );
163
-		$this->saved_cards                 = 'yes' === $this->get_option( 'saved_cards' );
164
-		$this->secret_key                  = $this->testmode ? $this->get_option( 'test_secret_key' ) : $this->get_option( 'secret_key' );
165
-		$this->publishable_key             = $this->testmode ? $this->get_option( 'test_publishable_key' ) : $this->get_option( 'publishable_key' );
166
-		$this->bitcoin                     = 'USD' === strtoupper( get_woocommerce_currency() ) && 'yes' === $this->get_option( 'stripe_bitcoin' );
167
-		$this->payment_request             = 'yes' === $this->get_option( 'payment_request', 'yes' );
168
-
169
-		if ( $this->stripe_checkout ) {
170
-			$this->order_button_text = __( 'Continue to payment', 'woocommerce-gateway-stripe' );
171
-		}
172
-
173
-		WC_Stripe_API::set_secret_key( $this->secret_key );
152
+		$this->title                       = $this->get_option('title');
153
+		$this->description                 = $this->get_option('description');
154
+		$this->enabled                     = $this->get_option('enabled');
155
+		$this->testmode                    = 'yes' === $this->get_option('testmode');
156
+		$this->inline_cc_form              = 'yes' === $this->get_option('inline_cc_form');
157
+		$this->capture                     = 'yes' === $this->get_option('capture', 'yes');
158
+		$this->statement_descriptor        = WC_Stripe_Helper::clean_statement_descriptor($this->get_option('statement_descriptor'));
159
+		$this->three_d_secure              = 'yes' === $this->get_option('three_d_secure');
160
+		$this->stripe_checkout             = 'yes' === $this->get_option('stripe_checkout');
161
+		$this->stripe_checkout_image       = $this->get_option('stripe_checkout_image', '');
162
+		$this->stripe_checkout_description = $this->get_option('stripe_checkout_description');
163
+		$this->saved_cards                 = 'yes' === $this->get_option('saved_cards');
164
+		$this->secret_key                  = $this->testmode ? $this->get_option('test_secret_key') : $this->get_option('secret_key');
165
+		$this->publishable_key             = $this->testmode ? $this->get_option('test_publishable_key') : $this->get_option('publishable_key');
166
+		$this->bitcoin                     = 'USD' === strtoupper(get_woocommerce_currency()) && 'yes' === $this->get_option('stripe_bitcoin');
167
+		$this->payment_request             = 'yes' === $this->get_option('payment_request', 'yes');
168
+
169
+		if ($this->stripe_checkout) {
170
+			$this->order_button_text = __('Continue to payment', 'woocommerce-gateway-stripe');
171
+		}
172
+
173
+		WC_Stripe_API::set_secret_key($this->secret_key);
174 174
 
175 175
 		// Hooks.
176
-		add_action( 'wp_enqueue_scripts', array( $this, 'payment_scripts' ) );
177
-		add_action( 'admin_enqueue_scripts', array( $this, 'admin_scripts' ) );
178
-		add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) );
179
-		add_action( 'woocommerce_admin_order_totals_after_total', array( $this, 'display_order_fee' ), 10, 1 );
180
-		add_action( 'woocommerce_admin_order_totals_after_total', array( $this, 'display_order_payout' ), 20, 1 );
181
-		add_action( 'woocommerce_customer_save_address', array( $this, 'show_update_card_notice' ), 10, 2 );
182
-		add_action( 'woocommerce_receipt_stripe', array( $this, 'stripe_checkout_receipt_page' ) );
183
-		add_action( 'woocommerce_api_' . strtolower( get_class( $this ) ), array( $this, 'stripe_checkout_return_handler' ) );
184
-
185
-		if ( WC_Stripe_Helper::is_pre_orders_exists() ) {
176
+		add_action('wp_enqueue_scripts', array($this, 'payment_scripts'));
177
+		add_action('admin_enqueue_scripts', array($this, 'admin_scripts'));
178
+		add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options'));
179
+		add_action('woocommerce_admin_order_totals_after_total', array($this, 'display_order_fee'), 10, 1);
180
+		add_action('woocommerce_admin_order_totals_after_total', array($this, 'display_order_payout'), 20, 1);
181
+		add_action('woocommerce_customer_save_address', array($this, 'show_update_card_notice'), 10, 2);
182
+		add_action('woocommerce_receipt_stripe', array($this, 'stripe_checkout_receipt_page'));
183
+		add_action('woocommerce_api_' . strtolower(get_class($this)), array($this, 'stripe_checkout_return_handler'));
184
+
185
+		if (WC_Stripe_Helper::is_pre_orders_exists()) {
186 186
 			$this->pre_orders = new WC_Stripe_Pre_Orders_Compat();
187 187
 
188
-			add_action( 'wc_pre_orders_process_pre_order_completion_payment_' . $this->id, array( $this->pre_orders, 'process_pre_order_release_payment' ) );
188
+			add_action('wc_pre_orders_process_pre_order_completion_payment_' . $this->id, array($this->pre_orders, 'process_pre_order_release_payment'));
189 189
 		}
190 190
 	}
191 191
 
@@ -196,7 +196,7 @@  discard block
 block discarded – undo
196 196
 	 * @return bool
197 197
 	 */
198 198
 	public function are_keys_set() {
199
-		if ( empty( $this->secret_key ) || empty( $this->publishable_key ) ) {
199
+		if (empty($this->secret_key) || empty($this->publishable_key)) {
200 200
 			return false;
201 201
 		}
202 202
 
@@ -209,7 +209,7 @@  discard block
 block discarded – undo
209 209
 	 * @since 4.0.2
210 210
 	 */
211 211
 	public function is_available() {
212
-		if ( is_add_payment_method_page() && ! $this->saved_cards ) {
212
+		if (is_add_payment_method_page() && ! $this->saved_cards) {
213 213
 			return false;
214 214
 		}
215 215
 
@@ -223,13 +223,13 @@  discard block
 block discarded – undo
223 223
 	 * @param int $user_id
224 224
 	 * @param array $load_address
225 225
 	 */
226
-	public function show_update_card_notice( $user_id, $load_address ) {
227
-		if ( ! $this->saved_cards || ! WC_Stripe_Payment_Tokens::customer_has_saved_methods( $user_id ) || 'billing' !== $load_address ) {
226
+	public function show_update_card_notice($user_id, $load_address) {
227
+		if ( ! $this->saved_cards || ! WC_Stripe_Payment_Tokens::customer_has_saved_methods($user_id) || 'billing' !== $load_address) {
228 228
 			return;
229 229
 		}
230 230
 
231 231
 		/* translators: 1) Opening anchor tag 2) closing anchor tag */
232
-		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' );
232
+		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');
233 233
 	}
234 234
 
235 235
 	/**
@@ -248,24 +248,24 @@  discard block
 block discarded – undo
248 248
 		$icons_str .= $icons['amex'];
249 249
 		$icons_str .= $icons['mastercard'];
250 250
 
251
-		if ( 'USD' === get_woocommerce_currency() ) {
251
+		if ('USD' === get_woocommerce_currency()) {
252 252
 			$icons_str .= $icons['discover'];
253 253
 			$icons_str .= $icons['jcb'];
254 254
 			$icons_str .= $icons['diners'];
255 255
 		}
256 256
 
257
-		if ( $this->bitcoin && $this->stripe_checkout ) {
257
+		if ($this->bitcoin && $this->stripe_checkout) {
258 258
 			$icons_str .= $icons['bitcoin'];
259 259
 		}
260 260
 
261
-		return apply_filters( 'woocommerce_gateway_icon', $icons_str, $this->id );
261
+		return apply_filters('woocommerce_gateway_icon', $icons_str, $this->id);
262 262
 	}
263 263
 
264 264
 	/**
265 265
 	 * Initialise Gateway Settings Form Fields
266 266
 	 */
267 267
 	public function init_form_fields() {
268
-		$this->form_fields = require( dirname( __FILE__ ) . '/admin/stripe-settings.php' );
268
+		$this->form_fields = require(dirname(__FILE__) . '/admin/stripe-settings.php');
269 269
 	}
270 270
 
271 271
 	/**
@@ -273,27 +273,27 @@  discard block
 block discarded – undo
273 273
 	 */
274 274
 	public function payment_fields() {
275 275
 		$user                 = wp_get_current_user();
276
-		$display_tokenization = $this->supports( 'tokenization' ) && is_checkout() && $this->saved_cards;
276
+		$display_tokenization = $this->supports('tokenization') && is_checkout() && $this->saved_cards;
277 277
 		$total                = WC()->cart->total;
278 278
 		$user_email           = '';
279 279
 
280 280
 		// If paying from order, we need to get total from order not cart.
281
-		if ( isset( $_GET['pay_for_order'] ) && ! empty( $_GET['key'] ) ) {
282
-			$order      = wc_get_order( wc_get_order_id_by_order_key( wc_clean( $_GET['key'] ) ) );
281
+		if (isset($_GET['pay_for_order']) && ! empty($_GET['key'])) {
282
+			$order      = wc_get_order(wc_get_order_id_by_order_key(wc_clean($_GET['key'])));
283 283
 			$total      = $order->get_total();
284 284
 			$user_email = WC_Stripe_Helper::is_pre_30() ? $order->billing_email : $order->get_billing_email();
285 285
 		} else {
286
-			if ( $user->ID ) {
287
-				$user_email = get_user_meta( $user->ID, 'billing_email', true );
286
+			if ($user->ID) {
287
+				$user_email = get_user_meta($user->ID, 'billing_email', true);
288 288
 				$user_email = $user_email ? $user_email : $user->user_email;
289 289
 			}
290 290
 		}
291 291
 
292
-		if ( is_add_payment_method_page() ) {
293
-			$pay_button_text = __( 'Add Card', 'woocommerce-gateway-stripe' );
292
+		if (is_add_payment_method_page()) {
293
+			$pay_button_text = __('Add Card', 'woocommerce-gateway-stripe');
294 294
 			$total        = '';
295
-		} elseif ( function_exists( 'wcs_order_contains_subscription' ) && isset( $_GET['change_payment_method'] ) ) {
296
-			$pay_button_text = __( 'Change Payment Method', 'woocommerce-gateway-stripe' );
295
+		} elseif (function_exists('wcs_order_contains_subscription') && isset($_GET['change_payment_method'])) {
296
+			$pay_button_text = __('Change Payment Method', 'woocommerce-gateway-stripe');
297 297
 			$total        = '';
298 298
 		} else {
299 299
 			$pay_button_text = '';
@@ -303,45 +303,45 @@  discard block
 block discarded – undo
303 303
 
304 304
 		echo '<div
305 305
 			id="stripe-payment-data"
306
-			data-panel-label="' . esc_attr( $pay_button_text ) . '"
307
-			data-description="' . esc_attr( strip_tags( $this->stripe_checkout_description ) ) . '"
308
-			data-email="' . esc_attr( $user_email ) . '"
309
-			data-verify-zip="' . esc_attr( apply_filters( 'wc_stripe_checkout_verify_zip', false ) ? 'true' : 'false' ) . '"
310
-			data-billing-address="' . esc_attr( apply_filters( 'wc_stripe_checkout_require_billing_address', false ) ? 'true' : 'false' ) . '"
311
-			data-shipping-address="' . esc_attr( apply_filters( 'wc_stripe_checkout_require_shipping_address', false ) ? 'true' : 'false' ) . '" 
312
-			data-amount="' . esc_attr( WC_Stripe_Helper::get_stripe_amount( $total ) ) . '"
313
-			data-name="' . esc_attr( $this->statement_descriptor ) . '"
314
-			data-currency="' . esc_attr( strtolower( get_woocommerce_currency() ) ) . '"
315
-			data-image="' . esc_attr( $this->stripe_checkout_image ) . '"
316
-			data-bitcoin="' . esc_attr( ( $this->bitcoin && $this->capture ) ? 'true' : 'false' ) . '"
317
-			data-locale="' . esc_attr( apply_filters( 'wc_stripe_checkout_locale', $this->get_locale() ) ) . '"
318
-			data-three-d-secure="' . esc_attr( $this->three_d_secure ? 'true' : 'false' ) . '"
319
-			data-allow-remember-me="' . esc_attr( apply_filters( 'wc_stripe_allow_remember_me', true ) ? 'true' : 'false' ) . '">';
320
-
321
-		if ( $this->description ) {
322
-			if ( $this->testmode ) {
306
+			data-panel-label="' . esc_attr($pay_button_text) . '"
307
+			data-description="' . esc_attr(strip_tags($this->stripe_checkout_description)) . '"
308
+			data-email="' . esc_attr($user_email) . '"
309
+			data-verify-zip="' . esc_attr(apply_filters('wc_stripe_checkout_verify_zip', false) ? 'true' : 'false') . '"
310
+			data-billing-address="' . esc_attr(apply_filters('wc_stripe_checkout_require_billing_address', false) ? 'true' : 'false') . '"
311
+			data-shipping-address="' . esc_attr(apply_filters('wc_stripe_checkout_require_shipping_address', false) ? 'true' : 'false') . '" 
312
+			data-amount="' . esc_attr(WC_Stripe_Helper::get_stripe_amount($total)) . '"
313
+			data-name="' . esc_attr($this->statement_descriptor) . '"
314
+			data-currency="' . esc_attr(strtolower(get_woocommerce_currency())) . '"
315
+			data-image="' . esc_attr($this->stripe_checkout_image) . '"
316
+			data-bitcoin="' . esc_attr(($this->bitcoin && $this->capture) ? 'true' : 'false') . '"
317
+			data-locale="' . esc_attr(apply_filters('wc_stripe_checkout_locale', $this->get_locale())) . '"
318
+			data-three-d-secure="' . esc_attr($this->three_d_secure ? 'true' : 'false') . '"
319
+			data-allow-remember-me="' . esc_attr(apply_filters('wc_stripe_allow_remember_me', true) ? 'true' : 'false') . '">';
320
+
321
+		if ($this->description) {
322
+			if ($this->testmode) {
323 323
 				/* translators: link to Stripe testing page */
324
-				$this->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' );
325
-				$this->description  = trim( $this->description );
324
+				$this->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');
325
+				$this->description  = trim($this->description);
326 326
 			}
327 327
 
328
-			echo apply_filters( 'wc_stripe_description', wpautop( wp_kses_post( $this->description ) ) );
328
+			echo apply_filters('wc_stripe_description', wpautop(wp_kses_post($this->description)));
329 329
 		}
330 330
 
331
-		if ( $display_tokenization ) {
331
+		if ($display_tokenization) {
332 332
 			$this->tokenization_script();
333 333
 			$this->saved_payment_methods();
334 334
 		}
335 335
 
336
-		if ( ! $this->stripe_checkout ) {
336
+		if ( ! $this->stripe_checkout) {
337 337
 			$this->elements_form();
338 338
 		}
339 339
 
340
-		if ( apply_filters( 'wc_stripe_display_save_payment_method_checkbox', $display_tokenization ) && ! is_add_payment_method_page() && ! isset( $_GET['change_payment_method'] ) ) {
340
+		if (apply_filters('wc_stripe_display_save_payment_method_checkbox', $display_tokenization) && ! is_add_payment_method_page() && ! isset($_GET['change_payment_method'])) {
341 341
 
342
-			if ( ! $this->stripe_checkout ) {
342
+			if ( ! $this->stripe_checkout) {
343 343
 				$this->save_payment_method_checkbox();
344
-			} elseif ( $this->stripe_checkout && isset( $_GET['pay_for_order'] ) && ! empty( $_GET['key'] ) ) {
344
+			} elseif ($this->stripe_checkout && isset($_GET['pay_for_order']) && ! empty($_GET['key'])) {
345 345
 				$this->save_payment_method_checkbox();
346 346
 			}
347 347
 		}
@@ -359,12 +359,12 @@  discard block
 block discarded – undo
359 359
 	 */
360 360
 	public function elements_form() {
361 361
 		?>
362
-		<fieldset id="wc-<?php echo esc_attr( $this->id ); ?>-cc-form" class="wc-credit-card-form wc-payment-form" style="background:transparent;">
363
-			<?php do_action( 'woocommerce_credit_card_form_start', $this->id ); ?>
362
+		<fieldset id="wc-<?php echo esc_attr($this->id); ?>-cc-form" class="wc-credit-card-form wc-payment-form" style="background:transparent;">
363
+			<?php do_action('woocommerce_credit_card_form_start', $this->id); ?>
364 364
 
365
-			<?php if ( $this->inline_cc_form ) { ?>
365
+			<?php if ($this->inline_cc_form) { ?>
366 366
 				<label for="card-element">
367
-					<?php esc_html_e( 'Credit or debit card', 'woocommerce-gateway-stripe' ); ?>
367
+					<?php esc_html_e('Credit or debit card', 'woocommerce-gateway-stripe'); ?>
368 368
 				</label>
369 369
 
370 370
 				<div id="stripe-card-element" style="background:#fff;padding:0 1em;border:1px solid #ddd;margin:5px 0;padding:10px 5px;">
@@ -372,7 +372,7 @@  discard block
 block discarded – undo
372 372
 				</div>
373 373
 			<?php } else { ?>
374 374
 				<div class="form-row form-row-wide">
375
-					<label><?php _e( 'Card Number', 'woocommerce-gateway-stripe' ); ?> <span class="required">*</span></label>
375
+					<label><?php _e('Card Number', 'woocommerce-gateway-stripe'); ?> <span class="required">*</span></label>
376 376
 
377 377
 					<div id="stripe-card-element" style="background:#fff;padding:0 1em;border:1px solid #ddd;margin:5px 0;padding:10px 5px;">
378 378
 					<!-- a Stripe Element will be inserted here. -->
@@ -380,7 +380,7 @@  discard block
 block discarded – undo
380 380
 				</div>
381 381
 
382 382
 				<div class="form-row form-row-first">
383
-					<label><?php _e( 'Expiry Date', 'woocommerce-gateway-stripe' ); ?> <span class="required">*</span></label>
383
+					<label><?php _e('Expiry Date', 'woocommerce-gateway-stripe'); ?> <span class="required">*</span></label>
384 384
 
385 385
 					<div id="stripe-exp-element" style="background:#fff;padding:0 1em;border:1px solid #ddd;margin:5px 0;padding:10px 5px;">
386 386
 					<!-- a Stripe Element will be inserted here. -->
@@ -388,7 +388,7 @@  discard block
 block discarded – undo
388 388
 				</div>
389 389
 
390 390
 				<div class="form-row form-row-last">
391
-					<label><?php _e( 'Card Code (CVC)', 'woocommerce-gateway-stripe' ); ?> <span class="required">*</span></label>
391
+					<label><?php _e('Card Code (CVC)', 'woocommerce-gateway-stripe'); ?> <span class="required">*</span></label>
392 392
 				<div id="stripe-cvc-element" style="background:#fff;padding:0 1em;border:1px solid #ddd;margin:5px 0;padding:10px 5px;">
393 393
 				<!-- a Stripe Element will be inserted here. -->
394 394
 				</div>
@@ -398,7 +398,7 @@  discard block
 block discarded – undo
398 398
 
399 399
 			<!-- Used to display form errors -->
400 400
 			<div class="stripe-source-errors" role="alert"></div>
401
-			<?php do_action( 'woocommerce_credit_card_form_end', $this->id ); ?>
401
+			<?php do_action('woocommerce_credit_card_form_end', $this->id); ?>
402 402
 			<div class="clear"></div>
403 403
 		</fieldset>
404 404
 		<?php
@@ -411,13 +411,13 @@  discard block
 block discarded – undo
411 411
 	 * @version 3.1.0
412 412
 	 */
413 413
 	public function admin_scripts() {
414
-		if ( 'woocommerce_page_wc-settings' !== get_current_screen()->id ) {
414
+		if ('woocommerce_page_wc-settings' !== get_current_screen()->id) {
415 415
 			return;
416 416
 		}
417 417
 
418
-		$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
418
+		$suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';
419 419
 
420
-		wp_enqueue_script( 'woocommerce_stripe_admin', plugins_url( 'assets/js/stripe-admin' . $suffix . '.js', WC_STRIPE_MAIN_FILE ), array(), WC_STRIPE_VERSION, true );
420
+		wp_enqueue_script('woocommerce_stripe_admin', plugins_url('assets/js/stripe-admin' . $suffix . '.js', WC_STRIPE_MAIN_FILE), array(), WC_STRIPE_VERSION, true);
421 421
 	}
422 422
 
423 423
 	/**
@@ -429,44 +429,44 @@  discard block
 block discarded – undo
429 429
 	 * @version 4.0.0
430 430
 	 */
431 431
 	public function payment_scripts() {
432
-		if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) && ! is_add_payment_method_page() && ! isset( $_GET['change_payment_method'] ) ) {
432
+		if ( ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order']) && ! is_add_payment_method_page() && ! isset($_GET['change_payment_method'])) {
433 433
 			return;
434 434
 		}
435 435
 
436 436
 		// If Stripe is not enabled bail.
437
-		if ( 'no' === $this->enabled ) {
437
+		if ('no' === $this->enabled) {
438 438
 			return;
439 439
 		}
440 440
 
441 441
 		// If keys are not set bail.
442
-		if ( ! $this->are_keys_set() ) {
443
-			WC_Stripe_Logger::log( 'Keys are not set correctly.' );
442
+		if ( ! $this->are_keys_set()) {
443
+			WC_Stripe_Logger::log('Keys are not set correctly.');
444 444
 			return;
445 445
 		}
446 446
 
447 447
 		// If no SSL bail.
448
-		if ( ! $this->testmode && ! is_ssl() ) {
449
-			WC_Stripe_Logger::log( 'Stripe live mode requires SSL.' );
448
+		if ( ! $this->testmode && ! is_ssl()) {
449
+			WC_Stripe_Logger::log('Stripe live mode requires SSL.');
450 450
 		}
451 451
 
452
-		$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
452
+		$suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';
453 453
 
454
-		wp_register_style( 'stripe_styles', plugins_url( 'assets/css/stripe-styles.css', WC_STRIPE_MAIN_FILE ), array(), WC_STRIPE_VERSION );
455
-		wp_enqueue_style( 'stripe_styles' );
456
-		wp_register_script( 'stripe_checkout', 'https://checkout.stripe.com/checkout.js', '', WC_STRIPE_VERSION, true );
457
-		wp_register_script( 'stripe', 'https://js.stripe.com/v3/', '', '3.0', true );
458
-		wp_register_script( 'woocommerce_stripe', plugins_url( 'assets/js/stripe' . $suffix . '.js', WC_STRIPE_MAIN_FILE ), array( 'jquery-payment', 'stripe' ), WC_STRIPE_VERSION, true );
454
+		wp_register_style('stripe_styles', plugins_url('assets/css/stripe-styles.css', WC_STRIPE_MAIN_FILE), array(), WC_STRIPE_VERSION);
455
+		wp_enqueue_style('stripe_styles');
456
+		wp_register_script('stripe_checkout', 'https://checkout.stripe.com/checkout.js', '', WC_STRIPE_VERSION, true);
457
+		wp_register_script('stripe', 'https://js.stripe.com/v3/', '', '3.0', true);
458
+		wp_register_script('woocommerce_stripe', plugins_url('assets/js/stripe' . $suffix . '.js', WC_STRIPE_MAIN_FILE), array('jquery-payment', 'stripe'), WC_STRIPE_VERSION, true);
459 459
 
460 460
 		$stripe_params = array(
461 461
 			'key'                  => $this->publishable_key,
462
-			'i18n_terms'           => __( 'Please accept the terms and conditions first', 'woocommerce-gateway-stripe' ),
463
-			'i18n_required_fields' => __( 'Please fill in required checkout fields first', 'woocommerce-gateway-stripe' ),
462
+			'i18n_terms'           => __('Please accept the terms and conditions first', 'woocommerce-gateway-stripe'),
463
+			'i18n_required_fields' => __('Please fill in required checkout fields first', 'woocommerce-gateway-stripe'),
464 464
 		);
465 465
 
466 466
 		// If we're on the pay page we need to pass stripe.js the address of the order.
467
-		if ( isset( $_GET['pay_for_order'] ) && 'true' === $_GET['pay_for_order'] ) {
468
-			$order_id = wc_get_order_id_by_order_key( urldecode( $_GET['key'] ) );
469
-			$order    = wc_get_order( $order_id );
467
+		if (isset($_GET['pay_for_order']) && 'true' === $_GET['pay_for_order']) {
468
+			$order_id = wc_get_order_id_by_order_key(urldecode($_GET['key']));
469
+			$order    = wc_get_order($order_id);
470 470
 
471 471
 			$stripe_params['billing_first_name'] = WC_Stripe_Helper::is_pre_30() ? $order->billing_first_name : $order->get_billing_first_name();
472 472
 			$stripe_params['billing_last_name']  = WC_Stripe_Helper::is_pre_30() ? $order->billing_last_name : $order->get_billing_last_name();
@@ -478,39 +478,39 @@  discard block
 block discarded – undo
478 478
 			$stripe_params['billing_country']    = WC_Stripe_Helper::is_pre_30() ? $order->billing_country : $order->get_billing_country();
479 479
 		}
480 480
 
481
-		$stripe_params['no_prepaid_card_msg']                     = __( 'Sorry, we\'re not accepting prepaid cards at this time. Your credit card has not been charge. Please try with alternative payment method.', 'woocommerce-gateway-stripe' );
482
-		$stripe_params['no_sepa_owner_msg']                       = __( 'Please enter your IBAN account name.', 'woocommerce-gateway-stripe' );
483
-		$stripe_params['no_sepa_iban_msg']                        = __( 'Please enter your IBAN account number.', 'woocommerce-gateway-stripe' );
484
-		$stripe_params['sepa_mandate_notification']               = apply_filters( 'wc_stripe_sepa_mandate_notification', 'email' );
485
-		$stripe_params['allow_prepaid_card']                      = apply_filters( 'wc_stripe_allow_prepaid_card', true ) ? 'yes' : 'no';
481
+		$stripe_params['no_prepaid_card_msg']                     = __('Sorry, we\'re not accepting prepaid cards at this time. Your credit card has not been charge. Please try with alternative payment method.', 'woocommerce-gateway-stripe');
482
+		$stripe_params['no_sepa_owner_msg']                       = __('Please enter your IBAN account name.', 'woocommerce-gateway-stripe');
483
+		$stripe_params['no_sepa_iban_msg']                        = __('Please enter your IBAN account number.', 'woocommerce-gateway-stripe');
484
+		$stripe_params['sepa_mandate_notification']               = apply_filters('wc_stripe_sepa_mandate_notification', 'email');
485
+		$stripe_params['allow_prepaid_card']                      = apply_filters('wc_stripe_allow_prepaid_card', true) ? 'yes' : 'no';
486 486
 		$stripe_params['inline_cc_form']                          = $this->inline_cc_form ? 'yes' : 'no';
487
-		$stripe_params['stripe_checkout_require_billing_address'] = apply_filters( 'wc_stripe_checkout_require_billing_address', false ) ? 'yes' : 'no';
488
-		$stripe_params['is_checkout']                             = ( is_checkout() && empty( $_GET['pay_for_order'] ) ) ? 'yes' : 'no';
487
+		$stripe_params['stripe_checkout_require_billing_address'] = apply_filters('wc_stripe_checkout_require_billing_address', false) ? 'yes' : 'no';
488
+		$stripe_params['is_checkout']                             = (is_checkout() && empty($_GET['pay_for_order'])) ? 'yes' : 'no';
489 489
 		$stripe_params['return_url']                              = $this->get_stripe_return_url();
490
-		$stripe_params['ajaxurl']                                 = WC_AJAX::get_endpoint( '%%endpoint%%' );
491
-		$stripe_params['stripe_nonce']                            = wp_create_nonce( '_wc_stripe_nonce' );
490
+		$stripe_params['ajaxurl']                                 = WC_AJAX::get_endpoint('%%endpoint%%');
491
+		$stripe_params['stripe_nonce']                            = wp_create_nonce('_wc_stripe_nonce');
492 492
 		$stripe_params['statement_descriptor']                    = $this->statement_descriptor;
493
-		$stripe_params['elements_options']                        = apply_filters( 'wc_stripe_elements_options', array() );
493
+		$stripe_params['elements_options']                        = apply_filters('wc_stripe_elements_options', array());
494 494
 		$stripe_params['is_stripe_checkout']                      = $this->stripe_checkout ? 'yes' : 'no';
495
-		$stripe_params['is_change_payment_page']                  = isset( $_GET['change_payment_method'] ) ? 'yes' : 'no';
496
-		$stripe_params['is_add_payment_page']                     = is_wc_endpoint_url( 'add-payment-method' ) ? 'yes' : 'no';
497
-		$stripe_params['is_pay_for_order_page']                   = is_wc_endpoint_url( 'order-pay' ) ? 'yes' : 'no';
498
-		$stripe_params['validate_modal_checkout']                 = apply_filters( 'wc_stripe_validate_modal_checkout', false ) ? 'yes' : 'no';
499
-		$stripe_params['elements_styling']                        = apply_filters( 'wc_stripe_elements_styling', false );
500
-		$stripe_params['elements_classes']                        = apply_filters( 'wc_stripe_elements_classes', false );
495
+		$stripe_params['is_change_payment_page']                  = isset($_GET['change_payment_method']) ? 'yes' : 'no';
496
+		$stripe_params['is_add_payment_page']                     = is_wc_endpoint_url('add-payment-method') ? 'yes' : 'no';
497
+		$stripe_params['is_pay_for_order_page']                   = is_wc_endpoint_url('order-pay') ? 'yes' : 'no';
498
+		$stripe_params['validate_modal_checkout']                 = apply_filters('wc_stripe_validate_modal_checkout', false) ? 'yes' : 'no';
499
+		$stripe_params['elements_styling']                        = apply_filters('wc_stripe_elements_styling', false);
500
+		$stripe_params['elements_classes']                        = apply_filters('wc_stripe_elements_classes', false);
501 501
 
502 502
 		// merge localized messages to be use in JS
503
-		$stripe_params = array_merge( $stripe_params, WC_Stripe_Helper::get_localized_messages() );
503
+		$stripe_params = array_merge($stripe_params, WC_Stripe_Helper::get_localized_messages());
504 504
 
505
-		wp_localize_script( 'woocommerce_stripe', 'wc_stripe_params', apply_filters( 'wc_stripe_params', $stripe_params ) );
506
-		wp_localize_script( 'woocommerce_stripe_checkout', 'wc_stripe_params', apply_filters( 'wc_stripe_params', $stripe_params ) );
505
+		wp_localize_script('woocommerce_stripe', 'wc_stripe_params', apply_filters('wc_stripe_params', $stripe_params));
506
+		wp_localize_script('woocommerce_stripe_checkout', 'wc_stripe_params', apply_filters('wc_stripe_params', $stripe_params));
507 507
 
508
-		if ( $this->stripe_checkout ) {
509
-			wp_enqueue_script( 'stripe_checkout' );
508
+		if ($this->stripe_checkout) {
509
+			wp_enqueue_script('stripe_checkout');
510 510
 		}
511 511
 
512 512
 		$this->tokenization_script();
513
-		wp_enqueue_script( 'woocommerce_stripe' );
513
+		wp_enqueue_script('woocommerce_stripe');
514 514
 	}
515 515
 
516 516
 	/**
@@ -518,71 +518,71 @@  discard block
 block discarded – undo
518 518
 	 *
519 519
 	 * @since 4.1.0
520 520
 	 */
521
-	public function stripe_checkout_receipt_page( $order_id ) {
522
-		if ( ! $this->stripe_checkout ) {
521
+	public function stripe_checkout_receipt_page($order_id) {
522
+		if ( ! $this->stripe_checkout) {
523 523
 			return;
524 524
 		}
525 525
 
526 526
 		$user                 = wp_get_current_user();
527 527
 		$total                = WC()->cart->total;
528 528
 		$user_email           = '';
529
-		$display_tokenization = $this->supports( 'tokenization' ) && $this->saved_cards;
529
+		$display_tokenization = $this->supports('tokenization') && $this->saved_cards;
530 530
 
531 531
 		// If paying from order, we need to get total from order not cart.
532
-		if ( ! empty( $_GET['key'] ) ) {
533
-			$order      = wc_get_order( wc_get_order_id_by_order_key( wc_clean( $_GET['key'] ) ) );
532
+		if ( ! empty($_GET['key'])) {
533
+			$order      = wc_get_order(wc_get_order_id_by_order_key(wc_clean($_GET['key'])));
534 534
 			$total      = $order->get_total();
535 535
 			$user_email = WC_Stripe_Helper::is_pre_30() ? $order->billing_email : $order->get_billing_email();
536 536
 		} else {
537
-			if ( $user->ID ) {
538
-				$user_email = get_user_meta( $user->ID, 'billing_email', true );
537
+			if ($user->ID) {
538
+				$user_email = get_user_meta($user->ID, 'billing_email', true);
539 539
 				$user_email = $user_email ? $user_email : $user->user_email;
540 540
 			}
541 541
 		}
542 542
 
543 543
 		ob_start();
544 544
 
545
-		do_action( 'wc_stripe_checkout_receipt_page_before_form' );
545
+		do_action('wc_stripe_checkout_receipt_page_before_form');
546 546
 
547
-		echo '<form method="post" class="woocommerce-checkout" action="' . WC()->api_request_url( get_class( $this ) ) . '">';
547
+		echo '<form method="post" class="woocommerce-checkout" action="' . WC()->api_request_url(get_class($this)) . '">';
548 548
 		echo '<div
549 549
 			id="stripe-payment-data"
550
-			data-panel-label="' . esc_attr( apply_filters( 'wc_stripe_checkout_label', '' ) ) . '"
551
-			data-description="' . esc_attr( strip_tags( $this->stripe_checkout_description ) ) . '"
552
-			data-email="' . esc_attr( $user_email ) . '"
553
-			data-verify-zip="' . esc_attr( apply_filters( 'wc_stripe_checkout_verify_zip', false ) ? 'true' : 'false' ) . '"
554
-			data-billing-address="' . esc_attr( apply_filters( 'wc_stripe_checkout_require_billing_address', false ) ? 'true' : 'false' ) . '"
555
-			data-shipping-address="' . esc_attr( apply_filters( 'wc_stripe_checkout_require_shipping_address', false ) ? 'true' : 'false' ) . '" 
556
-			data-amount="' . esc_attr( WC_Stripe_Helper::get_stripe_amount( $total ) ) . '"
557
-			data-name="' . esc_attr( $this->statement_descriptor ) . '"
558
-			data-currency="' . esc_attr( strtolower( get_woocommerce_currency() ) ) . '"
559
-			data-image="' . esc_attr( $this->stripe_checkout_image ) . '"
560
-			data-bitcoin="' . esc_attr( ( $this->bitcoin && $this->capture ) ? 'true' : 'false' ) . '"
561
-			data-locale="' . esc_attr( apply_filters( 'wc_stripe_checkout_locale', $this->get_locale() ) ) . '"
562
-			data-three-d-secure="' . esc_attr( $this->three_d_secure ? 'true' : 'false' ) . '"
563
-			data-allow-remember-me="' . esc_attr( apply_filters( 'wc_stripe_allow_remember_me', true ) ? 'true' : 'false' ) . '">';
564
-		echo '<input type="hidden" name="order_id" value="' . esc_attr( $order_id ) . '" />';
550
+			data-panel-label="' . esc_attr(apply_filters('wc_stripe_checkout_label', '')) . '"
551
+			data-description="' . esc_attr(strip_tags($this->stripe_checkout_description)) . '"
552
+			data-email="' . esc_attr($user_email) . '"
553
+			data-verify-zip="' . esc_attr(apply_filters('wc_stripe_checkout_verify_zip', false) ? 'true' : 'false') . '"
554
+			data-billing-address="' . esc_attr(apply_filters('wc_stripe_checkout_require_billing_address', false) ? 'true' : 'false') . '"
555
+			data-shipping-address="' . esc_attr(apply_filters('wc_stripe_checkout_require_shipping_address', false) ? 'true' : 'false') . '" 
556
+			data-amount="' . esc_attr(WC_Stripe_Helper::get_stripe_amount($total)) . '"
557
+			data-name="' . esc_attr($this->statement_descriptor) . '"
558
+			data-currency="' . esc_attr(strtolower(get_woocommerce_currency())) . '"
559
+			data-image="' . esc_attr($this->stripe_checkout_image) . '"
560
+			data-bitcoin="' . esc_attr(($this->bitcoin && $this->capture) ? 'true' : 'false') . '"
561
+			data-locale="' . esc_attr(apply_filters('wc_stripe_checkout_locale', $this->get_locale())) . '"
562
+			data-three-d-secure="' . esc_attr($this->three_d_secure ? 'true' : 'false') . '"
563
+			data-allow-remember-me="' . esc_attr(apply_filters('wc_stripe_allow_remember_me', true) ? 'true' : 'false') . '">';
564
+		echo '<input type="hidden" name="order_id" value="' . esc_attr($order_id) . '" />';
565 565
 		echo '<input type="hidden" name="stripe_checkout_order" value="yes" />';
566 566
 
567 567
 		if (
568
-			apply_filters( 'wc_stripe_display_save_payment_method_checkbox', $display_tokenization ) &&
569
-			( ! function_exists( 'wcs_order_contains_subscription' ) || ( function_exists( 'wcs_order_contains_subscription' ) && ! WC_Subscriptions_Cart::cart_contains_subscription() ) ) &&
570
-			( ! WC_Stripe_Helper::is_pre_orders_exists() || ( WC_Stripe_Helper::is_pre_orders_exists() && ! $this->pre_orders->is_pre_order( $order_id ) ) )
568
+			apply_filters('wc_stripe_display_save_payment_method_checkbox', $display_tokenization) &&
569
+			( ! function_exists('wcs_order_contains_subscription') || (function_exists('wcs_order_contains_subscription') && ! WC_Subscriptions_Cart::cart_contains_subscription())) &&
570
+			( ! WC_Stripe_Helper::is_pre_orders_exists() || (WC_Stripe_Helper::is_pre_orders_exists() && ! $this->pre_orders->is_pre_order($order_id)))
571 571
 		) {
572 572
 			$this->save_payment_method_checkbox();
573 573
 		}
574 574
 
575
-		wp_nonce_field( 'stripe-checkout-process', 'stripe_checkout_process_nonce' );
575
+		wp_nonce_field('stripe-checkout-process', 'stripe_checkout_process_nonce');
576 576
 
577
-		do_action( 'wc_stripe_checkout_receipt_page_before_form_submit' );
577
+		do_action('wc_stripe_checkout_receipt_page_before_form_submit');
578 578
 
579
-		echo '<button type="submit" class="wc-stripe-checkout-button">' . __( 'Place Order', 'woocommerce-gateway-stripe' ) . '</button>';
579
+		echo '<button type="submit" class="wc-stripe-checkout-button">' . __('Place Order', 'woocommerce-gateway-stripe') . '</button>';
580 580
 
581
-		do_action( 'wc_stripe_checkout_receipt_page_after_form_submit' );
581
+		do_action('wc_stripe_checkout_receipt_page_after_form_submit');
582 582
 
583 583
 		echo '</form>';
584 584
 
585
-		do_action( 'wc_stripe_checkout_receipt_page_after_form' );
585
+		do_action('wc_stripe_checkout_receipt_page_after_form');
586 586
 
587 587
 		echo '</div>';
588 588
 
@@ -595,32 +595,32 @@  discard block
 block discarded – undo
595 595
 	 * @since 4.1.0
596 596
 	 */
597 597
 	public function stripe_checkout_return_handler() {
598
-		if ( ! $this->stripe_checkout ) {
598
+		if ( ! $this->stripe_checkout) {
599 599
 			return;
600 600
 		}
601 601
 
602
-		if ( ! wp_verify_nonce( $_POST['stripe_checkout_process_nonce'], 'stripe-checkout-process' ) ) {
602
+		if ( ! wp_verify_nonce($_POST['stripe_checkout_process_nonce'], 'stripe-checkout-process')) {
603 603
 			return;
604 604
 		}
605 605
 
606
-		$order_id = wc_clean( $_POST['order_id'] );
607
-		$order    = wc_get_order( $order_id );
606
+		$order_id = wc_clean($_POST['order_id']);
607
+		$order    = wc_get_order($order_id);
608 608
 
609
-		do_action( 'wc_stripe_checkout_return_handler', $order );
609
+		do_action('wc_stripe_checkout_return_handler', $order);
610 610
 
611
-		if ( WC_Stripe_Helper::is_pre_orders_exists() && $this->pre_orders->is_pre_order( $order_id ) && WC_Pre_Orders_Order::order_requires_payment_tokenization( $order_id ) ) {
612
-			$result = $this->pre_orders->process_pre_order( $order_id );
611
+		if (WC_Stripe_Helper::is_pre_orders_exists() && $this->pre_orders->is_pre_order($order_id) && WC_Pre_Orders_Order::order_requires_payment_tokenization($order_id)) {
612
+			$result = $this->pre_orders->process_pre_order($order_id);
613 613
 		} else {
614
-			$result = $this->process_payment( $order_id );
614
+			$result = $this->process_payment($order_id);
615 615
 		}
616 616
 
617
-		if ( 'success' === $result['result'] ) {
618
-			wp_redirect( $result['redirect'] );
617
+		if ('success' === $result['result']) {
618
+			wp_redirect($result['redirect']);
619 619
 			exit;
620 620
 		}
621 621
 
622 622
 		// Redirects back to pay order page.
623
-		wp_safe_redirect( $order->get_checkout_payment_url( true ) );
623
+		wp_safe_redirect($order->get_checkout_payment_url(true));
624 624
 		exit;
625 625
 	}
626 626
 
@@ -633,9 +633,9 @@  discard block
 block discarded – undo
633 633
 	public function maybe_redirect_stripe_checkout() {
634 634
 		return (
635 635
 			$this->stripe_checkout &&
636
-			! isset( $_POST['stripe_checkout_order'] ) &&
636
+			! isset($_POST['stripe_checkout_order']) &&
637 637
 			! $this->is_using_saved_payment_method() &&
638
-			! is_wc_endpoint_url( 'order-pay' )
638
+			! is_wc_endpoint_url('order-pay')
639 639
 		);
640 640
 	}
641 641
 
@@ -653,54 +653,54 @@  discard block
 block discarded – undo
653 653
 	 *
654 654
 	 * @return array|void
655 655
 	 */
656
-	public function process_payment( $order_id, $retry = true, $force_save_source = false, $previous_error = false ) {
656
+	public function process_payment($order_id, $retry = true, $force_save_source = false, $previous_error = false) {
657 657
 		try {
658
-			$order = wc_get_order( $order_id );
658
+			$order = wc_get_order($order_id);
659 659
 
660
-			if ( $this->maybe_redirect_stripe_checkout() ) {
661
-				WC_Stripe_Logger::log( sprintf( 'Redirecting to Stripe Checkout page for order %s', $order_id ) );
660
+			if ($this->maybe_redirect_stripe_checkout()) {
661
+				WC_Stripe_Logger::log(sprintf('Redirecting to Stripe Checkout page for order %s', $order_id));
662 662
 
663 663
 				return array(
664 664
 					'result'   => 'success',
665
-					'redirect' => $order->get_checkout_payment_url( true ),
665
+					'redirect' => $order->get_checkout_payment_url(true),
666 666
 				);
667 667
 			}
668 668
 
669
-			if ( $this->maybe_process_pre_orders( $order_id ) ) {
670
-				return $this->pre_orders->process_pre_order( $order_id );
669
+			if ($this->maybe_process_pre_orders($order_id)) {
670
+				return $this->pre_orders->process_pre_order($order_id);
671 671
 			}
672 672
 
673 673
 			// This comes from the create account checkbox in the checkout page.
674
-			$create_account = ! empty( $_POST['createaccount'] ) ? true : false;
674
+			$create_account = ! empty($_POST['createaccount']) ? true : false;
675 675
 
676
-			if ( $create_account ) {
676
+			if ($create_account) {
677 677
 				$new_customer_id     = WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id();
678
-				$new_stripe_customer = new WC_Stripe_Customer( $new_customer_id );
678
+				$new_stripe_customer = new WC_Stripe_Customer($new_customer_id);
679 679
 				$new_stripe_customer->create_customer();
680 680
 			}
681 681
 
682
-			$prepared_source = $this->prepare_source( get_current_user_id(), $force_save_source );
682
+			$prepared_source = $this->prepare_source(get_current_user_id(), $force_save_source);
683 683
 			$source_object   = $prepared_source->source_object;
684 684
 
685 685
 			// Check if we don't allow prepaid credit cards.
686
-			if ( ! apply_filters( 'wc_stripe_allow_prepaid_card', true ) && $this->is_prepaid_card( $source_object ) ) {
687
-				$localized_message = __( 'Sorry, we\'re not accepting prepaid cards at this time. Your credit card has not been charge. Please try with alternative payment method.', 'woocommerce-gateway-stripe' );
688
-				throw new WC_Stripe_Exception( print_r( $source_object, true ), $localized_message );
686
+			if ( ! apply_filters('wc_stripe_allow_prepaid_card', true) && $this->is_prepaid_card($source_object)) {
687
+				$localized_message = __('Sorry, we\'re not accepting prepaid cards at this time. Your credit card has not been charge. Please try with alternative payment method.', 'woocommerce-gateway-stripe');
688
+				throw new WC_Stripe_Exception(print_r($source_object, true), $localized_message);
689 689
 			}
690 690
 
691
-			if ( empty( $prepared_source->source ) ) {
692
-				$localized_message = __( 'Payment processing failed. Please retry.', 'woocommerce-gateway-stripe' );
693
-				throw new WC_Stripe_Exception( print_r( $prepared_source, true ), $localized_message );
691
+			if (empty($prepared_source->source)) {
692
+				$localized_message = __('Payment processing failed. Please retry.', 'woocommerce-gateway-stripe');
693
+				throw new WC_Stripe_Exception(print_r($prepared_source, true), $localized_message);
694 694
 			}
695 695
 
696
-			$this->save_source_to_order( $order, $prepared_source );
696
+			$this->save_source_to_order($order, $prepared_source);
697 697
 
698 698
 			// Result from Stripe API request.
699 699
 			$response = null;
700 700
 
701
-			if ( $order->get_total() > 0 ) {
701
+			if ($order->get_total() > 0) {
702 702
 				// This will throw exception if not valid.
703
-				$this->validate_minimum_order_amount( $order );
703
+				$this->validate_minimum_order_amount($order);
704 704
 
705 705
 				/*
706 706
 				 * Check if card 3DS is required or optional with 3DS setting.
@@ -709,104 +709,104 @@  discard block
 block discarded – undo
709 709
 				 * Note that if we need to save source, the original source must be first
710 710
 				 * attached to a customer in Stripe before it can be charged.
711 711
 				 */
712
-				if ( $this->is_3ds_required( $source_object ) ) {
713
-					$response = $this->create_3ds_source( $order, $source_object );
712
+				if ($this->is_3ds_required($source_object)) {
713
+					$response = $this->create_3ds_source($order, $source_object);
714 714
 
715
-					if ( ! empty( $response->error ) ) {
715
+					if ( ! empty($response->error)) {
716 716
 						$localized_message = $response->error->message;
717 717
 
718
-						$order->add_order_note( $localized_message );
718
+						$order->add_order_note($localized_message);
719 719
 
720
-						throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message );
720
+						throw new WC_Stripe_Exception(print_r($response, true), $localized_message);
721 721
 					}
722 722
 
723 723
 					// Update order meta with 3DS source.
724
-					if ( WC_Stripe_Helper::is_pre_30() ) {
725
-						update_post_meta( $order_id, '_stripe_source_id', $response->id );
724
+					if (WC_Stripe_Helper::is_pre_30()) {
725
+						update_post_meta($order_id, '_stripe_source_id', $response->id);
726 726
 					} else {
727
-						$order->update_meta_data( '_stripe_source_id', $response->id );
727
+						$order->update_meta_data('_stripe_source_id', $response->id);
728 728
 						$order->save();
729 729
 					}
730 730
 
731
-					WC_Stripe_Logger::log( 'Info: Redirecting to 3DS...' );
731
+					WC_Stripe_Logger::log('Info: Redirecting to 3DS...');
732 732
 
733 733
 					return array(
734 734
 						'result'   => 'success',
735
-						'redirect' => esc_url_raw( $response->redirect->url ),
735
+						'redirect' => esc_url_raw($response->redirect->url),
736 736
 					);
737 737
 				}
738 738
 
739
-				WC_Stripe_Logger::log( "Info: Begin processing payment for order $order_id for the amount of {$order->get_total()}" );
739
+				WC_Stripe_Logger::log("Info: Begin processing payment for order $order_id for the amount of {$order->get_total()}");
740 740
 
741 741
 				/* If we're doing a retry and source is chargeable, we need to pass
742 742
 				 * a different idempotency key and retry for success.
743 743
 				 */
744
-				if ( $this->need_update_idempotency_key( $source_object, $previous_error ) ) {
745
-					add_filter( 'wc_stripe_idempotency_key', array( $this, 'change_idempotency_key' ), 10, 2 );
744
+				if ($this->need_update_idempotency_key($source_object, $previous_error)) {
745
+					add_filter('wc_stripe_idempotency_key', array($this, 'change_idempotency_key'), 10, 2);
746 746
 				}
747 747
 
748 748
 				// Make the request.
749
-				$response = WC_Stripe_API::request( $this->generate_payment_request( $order, $prepared_source ) );
749
+				$response = WC_Stripe_API::request($this->generate_payment_request($order, $prepared_source));
750 750
 
751
-				if ( ! empty( $response->error ) ) {
751
+				if ( ! empty($response->error)) {
752 752
 					// Customer param wrong? The user may have been deleted on stripe's end. Remove customer_id. Can be retried without.
753
-					if ( $this->is_no_such_customer_error( $response->error ) ) {
754
-						if ( WC_Stripe_Helper::is_pre_30() ) {
755
-							delete_user_meta( $order->customer_user, '_stripe_customer_id' );
756
-							delete_post_meta( $order_id, '_stripe_customer_id' );
753
+					if ($this->is_no_such_customer_error($response->error)) {
754
+						if (WC_Stripe_Helper::is_pre_30()) {
755
+							delete_user_meta($order->customer_user, '_stripe_customer_id');
756
+							delete_post_meta($order_id, '_stripe_customer_id');
757 757
 						} else {
758
-							delete_user_meta( $order->get_customer_id(), '_stripe_customer_id' );
759
-							$order->delete_meta_data( '_stripe_customer_id' );
758
+							delete_user_meta($order->get_customer_id(), '_stripe_customer_id');
759
+							$order->delete_meta_data('_stripe_customer_id');
760 760
 							$order->save();
761 761
 						}
762 762
 					}
763 763
 
764
-					if ( $this->is_no_such_token_error( $response->error ) && $prepared_source->token_id ) {
764
+					if ($this->is_no_such_token_error($response->error) && $prepared_source->token_id) {
765 765
 						// Source param wrong? The CARD may have been deleted on stripe's end. Remove token and show message.
766
-						$wc_token = WC_Payment_Tokens::get( $prepared_source->token_id );
766
+						$wc_token = WC_Payment_Tokens::get($prepared_source->token_id);
767 767
 						$wc_token->delete();
768
-						$localized_message = __( 'This card is no longer available and has been removed.', 'woocommerce-gateway-stripe' );
769
-						$order->add_order_note( $localized_message );
770
-						throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message );
768
+						$localized_message = __('This card is no longer available and has been removed.', 'woocommerce-gateway-stripe');
769
+						$order->add_order_note($localized_message);
770
+						throw new WC_Stripe_Exception(print_r($response, true), $localized_message);
771 771
 					}
772 772
 
773 773
 					// We want to retry.
774
-					if ( $this->is_retryable_error( $response->error ) ) {
775
-						if ( $retry ) {
774
+					if ($this->is_retryable_error($response->error)) {
775
+						if ($retry) {
776 776
 							// Don't do anymore retries after this.
777
-							if ( 5 <= $this->retry_interval ) {
778
-								return $this->process_payment( $order_id, false, $force_save_source, $response->error );
777
+							if (5 <= $this->retry_interval) {
778
+								return $this->process_payment($order_id, false, $force_save_source, $response->error);
779 779
 							}
780 780
 
781
-							sleep( $this->retry_interval );
781
+							sleep($this->retry_interval);
782 782
 
783 783
 							$this->retry_interval++;
784 784
 
785
-							return $this->process_payment( $order_id, true, $force_save_source, $response->error );
785
+							return $this->process_payment($order_id, true, $force_save_source, $response->error);
786 786
 						} else {
787
-							$localized_message = __( 'Sorry, we are unable to process your payment at this time. Please retry later.', 'woocommerce-gateway-stripe' );
788
-							$order->add_order_note( $localized_message );
789
-							throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message );
787
+							$localized_message = __('Sorry, we are unable to process your payment at this time. Please retry later.', 'woocommerce-gateway-stripe');
788
+							$order->add_order_note($localized_message);
789
+							throw new WC_Stripe_Exception(print_r($response, true), $localized_message);
790 790
 						}
791 791
 					}
792 792
 
793 793
 					$localized_messages = WC_Stripe_Helper::get_localized_messages();
794 794
 
795
-					if ( 'card_error' === $response->error->type ) {
796
-						$localized_message = isset( $localized_messages[ $response->error->code ] ) ? $localized_messages[ $response->error->code ] : $response->error->message;
795
+					if ('card_error' === $response->error->type) {
796
+						$localized_message = isset($localized_messages[$response->error->code]) ? $localized_messages[$response->error->code] : $response->error->message;
797 797
 					} else {
798
-						$localized_message = isset( $localized_messages[ $response->error->type ] ) ? $localized_messages[ $response->error->type ] : $response->error->message;
798
+						$localized_message = isset($localized_messages[$response->error->type]) ? $localized_messages[$response->error->type] : $response->error->message;
799 799
 					}
800 800
 
801
-					$order->add_order_note( $localized_message );
801
+					$order->add_order_note($localized_message);
802 802
 
803
-					throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message );
803
+					throw new WC_Stripe_Exception(print_r($response, true), $localized_message);
804 804
 				}
805 805
 
806
-				do_action( 'wc_gateway_stripe_process_payment', $response, $order );
806
+				do_action('wc_gateway_stripe_process_payment', $response, $order);
807 807
 
808 808
 				// Process valid response.
809
-				$this->process_response( $response, $order );
809
+				$this->process_response($response, $order);
810 810
 			} else {
811 811
 				$order->payment_complete();
812 812
 			}
@@ -817,20 +817,20 @@  discard block
 block discarded – undo
817 817
 			// Return thank you page redirect.
818 818
 			return array(
819 819
 				'result'   => 'success',
820
-				'redirect' => $this->get_return_url( $order ),
820
+				'redirect' => $this->get_return_url($order),
821 821
 			);
822 822
 
823
-		} catch ( WC_Stripe_Exception $e ) {
824
-			wc_add_notice( $e->getLocalizedMessage(), 'error' );
825
-			WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() );
823
+		} catch (WC_Stripe_Exception $e) {
824
+			wc_add_notice($e->getLocalizedMessage(), 'error');
825
+			WC_Stripe_Logger::log('Error: ' . $e->getMessage());
826 826
 
827
-			do_action( 'wc_gateway_stripe_process_payment_error', $e, $order );
827
+			do_action('wc_gateway_stripe_process_payment_error', $e, $order);
828 828
 
829 829
 			/* translators: error message */
830
-			$order->update_status( 'failed' );
830
+			$order->update_status('failed');
831 831
 
832
-			if ( $order->has_status( array( 'pending', 'failed' ) ) ) {
833
-				$this->send_failed_order_email( $order_id );
832
+			if ($order->has_status(array('pending', 'failed'))) {
833
+				$this->send_failed_order_email($order_id);
834 834
 			}
835 835
 
836 836
 			return array(
@@ -847,17 +847,17 @@  discard block
 block discarded – undo
847 847
 	 *
848 848
 	 * @param int $order_id
849 849
 	 */
850
-	public function display_order_fee( $order_id ) {
851
-		if ( apply_filters( 'wc_stripe_hide_display_order_fee', false, $order_id ) ) {
850
+	public function display_order_fee($order_id) {
851
+		if (apply_filters('wc_stripe_hide_display_order_fee', false, $order_id)) {
852 852
 			return;
853 853
 		}
854 854
 
855
-		$order = wc_get_order( $order_id );
855
+		$order = wc_get_order($order_id);
856 856
 
857
-		$fee      = WC_Stripe_Helper::get_stripe_fee( $order );
858
-		$currency = WC_Stripe_Helper::get_stripe_currency( $order );
857
+		$fee      = WC_Stripe_Helper::get_stripe_fee($order);
858
+		$currency = WC_Stripe_Helper::get_stripe_currency($order);
859 859
 
860
-		if ( ! $fee || ! $currency ) {
860
+		if ( ! $fee || ! $currency) {
861 861
 			return;
862 862
 		}
863 863
 
@@ -865,12 +865,12 @@  discard block
 block discarded – undo
865 865
 
866 866
 		<tr>
867 867
 			<td class="label stripe-fee">
868
-				<?php echo wc_help_tip( __( 'This represents the fee Stripe collects for the transaction.', 'woocommerce-gateway-stripe' ) ); ?>
869
-				<?php esc_html_e( 'Stripe Fee:', 'woocommerce-gateway-stripe' ); ?>
868
+				<?php echo wc_help_tip(__('This represents the fee Stripe collects for the transaction.', 'woocommerce-gateway-stripe')); ?>
869
+				<?php esc_html_e('Stripe Fee:', 'woocommerce-gateway-stripe'); ?>
870 870
 			</td>
871 871
 			<td width="1%"></td>
872 872
 			<td class="total">
873
-				-&nbsp;<?php echo wc_price( $fee, array( 'currency' => $currency ) ); ?>
873
+				-&nbsp;<?php echo wc_price($fee, array('currency' => $currency)); ?>
874 874
 			</td>
875 875
 		</tr>
876 876
 
@@ -884,17 +884,17 @@  discard block
 block discarded – undo
884 884
 	 *
885 885
 	 * @param int $order_id
886 886
 	 */
887
-	public function display_order_payout( $order_id ) {
888
-		if ( apply_filters( 'wc_stripe_hide_display_order_payout', false, $order_id ) ) {
887
+	public function display_order_payout($order_id) {
888
+		if (apply_filters('wc_stripe_hide_display_order_payout', false, $order_id)) {
889 889
 			return;
890 890
 		}
891 891
 
892
-		$order = wc_get_order( $order_id );
892
+		$order = wc_get_order($order_id);
893 893
 
894
-		$net      = WC_Stripe_Helper::get_stripe_net( $order );
895
-		$currency = WC_Stripe_Helper::get_stripe_currency( $order );
894
+		$net      = WC_Stripe_Helper::get_stripe_net($order);
895
+		$currency = WC_Stripe_Helper::get_stripe_currency($order);
896 896
 
897
-		if ( ! $net || ! $currency ) {
897
+		if ( ! $net || ! $currency) {
898 898
 			return;
899 899
 		}
900 900
 
@@ -902,12 +902,12 @@  discard block
 block discarded – undo
902 902
 
903 903
 		<tr>
904 904
 			<td class="label stripe-payout">
905
-				<?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' ) ); ?>
906
-				<?php esc_html_e( 'Stripe Payout:', 'woocommerce-gateway-stripe' ); ?>
905
+				<?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')); ?>
906
+				<?php esc_html_e('Stripe Payout:', 'woocommerce-gateway-stripe'); ?>
907 907
 			</td>
908 908
 			<td width="1%"></td>
909 909
 			<td class="total">
910
-				<?php echo wc_price( $net, array( 'currency' => $currency ) ); ?>
910
+				<?php echo wc_price($net, array('currency' => $currency)); ?>
911 911
 			</td>
912 912
 		</tr>
913 913
 
Please login to merge, or discard this patch.
woocommerce-gateway-stripe.php 1 patch
Spacing   +92 added lines, -92 removed lines patch added patch discarded remove patch
@@ -15,20 +15,20 @@  discard block
 block discarded – undo
15 15
  *
16 16
  */
17 17
 
18
-if ( ! defined( 'ABSPATH' ) ) {
18
+if ( ! defined('ABSPATH')) {
19 19
 	exit;
20 20
 }
21 21
 
22
-if ( ! class_exists( 'WC_Stripe' ) ) :
22
+if ( ! class_exists('WC_Stripe')) :
23 23
 	/**
24 24
 	 * Required minimums and constants
25 25
 	 */
26
-	define( 'WC_STRIPE_VERSION', '4.1.0' );
27
-	define( 'WC_STRIPE_MIN_PHP_VER', '5.6.0' );
28
-	define( 'WC_STRIPE_MIN_WC_VER', '2.6.0' );
29
-	define( 'WC_STRIPE_MAIN_FILE', __FILE__ );
30
-	define( 'WC_STRIPE_PLUGIN_URL', untrailingslashit( plugins_url( basename( plugin_dir_path( __FILE__ ) ), basename( __FILE__ ) ) ) );
31
-	define( 'WC_STRIPE_PLUGIN_PATH', untrailingslashit( plugin_dir_path( __FILE__ ) ) );
26
+	define('WC_STRIPE_VERSION', '4.1.0');
27
+	define('WC_STRIPE_MIN_PHP_VER', '5.6.0');
28
+	define('WC_STRIPE_MIN_WC_VER', '2.6.0');
29
+	define('WC_STRIPE_MAIN_FILE', __FILE__);
30
+	define('WC_STRIPE_PLUGIN_URL', untrailingslashit(plugins_url(basename(plugin_dir_path(__FILE__)), basename(__FILE__))));
31
+	define('WC_STRIPE_PLUGIN_PATH', untrailingslashit(plugin_dir_path(__FILE__)));
32 32
 
33 33
 	class WC_Stripe {
34 34
 
@@ -48,7 +48,7 @@  discard block
 block discarded – undo
48 48
 		 * @return Singleton The *Singleton* instance.
49 49
 		 */
50 50
 		public static function get_instance() {
51
-			if ( null === self::$instance ) {
51
+			if (null === self::$instance) {
52 52
 				self::$instance = new self();
53 53
 			}
54 54
 			return self::$instance;
@@ -75,8 +75,8 @@  discard block
 block discarded – undo
75 75
 		 * *Singleton* via the `new` operator from outside of this class.
76 76
 		 */
77 77
 		private function __construct() {
78
-			add_action( 'admin_init', array( $this, 'install' ) );
79
-			add_action( 'plugins_loaded', array( $this, 'init' ) );
78
+			add_action('admin_init', array($this, 'install'));
79
+			add_action('plugins_loaded', array($this, 'init'));
80 80
 		}
81 81
 
82 82
 		/**
@@ -86,51 +86,51 @@  discard block
 block discarded – undo
86 86
 		 * @version 4.0.0
87 87
 		 */
88 88
 		public function init() {
89
-			require_once( dirname( __FILE__ ) . '/includes/class-wc-stripe-exception.php' );
90
-			require_once( dirname( __FILE__ ) . '/includes/class-wc-stripe-logger.php' );
91
-			require_once( dirname( __FILE__ ) . '/includes/class-wc-stripe-helper.php' );
92
-			include_once( dirname( __FILE__ ) . '/includes/class-wc-stripe-api.php' );
89
+			require_once(dirname(__FILE__) . '/includes/class-wc-stripe-exception.php');
90
+			require_once(dirname(__FILE__) . '/includes/class-wc-stripe-logger.php');
91
+			require_once(dirname(__FILE__) . '/includes/class-wc-stripe-helper.php');
92
+			include_once(dirname(__FILE__) . '/includes/class-wc-stripe-api.php');
93 93
 
94 94
 			// Don't hook anything else in the plugin if we're in an incompatible environment.
95
-			if ( $this->get_environment_warning() && is_plugin_active( plugin_basename( __FILE__ ) ) ) {
95
+			if ($this->get_environment_warning() && is_plugin_active(plugin_basename(__FILE__))) {
96 96
 				return;
97 97
 			}
98 98
 
99
-			load_plugin_textdomain( 'woocommerce-gateway-stripe', false, plugin_basename( dirname( __FILE__ ) ) . '/languages' );
100
-
101
-			require_once( dirname( __FILE__ ) . '/includes/abstracts/abstract-wc-stripe-payment-gateway.php' );
102
-			require_once( dirname( __FILE__ ) . '/includes/class-wc-stripe-webhook-handler.php' );
103
-			require_once( dirname( __FILE__ ) . '/includes/class-wc-stripe-sepa-payment-token.php' );
104
-			require_once( dirname( __FILE__ ) . '/includes/class-wc-stripe-apple-pay-registration.php' );
105
-			require_once( dirname( __FILE__ ) . '/includes/compat/class-wc-stripe-pre-orders-compat.php' );
106
-			require_once( dirname( __FILE__ ) . '/includes/class-wc-gateway-stripe.php' );
107
-			require_once( dirname( __FILE__ ) . '/includes/payment-methods/class-wc-gateway-stripe-bancontact.php' );
108
-			require_once( dirname( __FILE__ ) . '/includes/payment-methods/class-wc-gateway-stripe-sofort.php' );
109
-			require_once( dirname( __FILE__ ) . '/includes/payment-methods/class-wc-gateway-stripe-giropay.php' );
110
-			require_once( dirname( __FILE__ ) . '/includes/payment-methods/class-wc-gateway-stripe-eps.php' );
111
-			require_once( dirname( __FILE__ ) . '/includes/payment-methods/class-wc-gateway-stripe-ideal.php' );
112
-			require_once( dirname( __FILE__ ) . '/includes/payment-methods/class-wc-gateway-stripe-p24.php' );
113
-			require_once( dirname( __FILE__ ) . '/includes/payment-methods/class-wc-gateway-stripe-alipay.php' );
114
-			require_once( dirname( __FILE__ ) . '/includes/payment-methods/class-wc-gateway-stripe-sepa.php' );
115
-			require_once( dirname( __FILE__ ) . '/includes/payment-methods/class-wc-gateway-stripe-bitcoin.php' );
116
-			require_once( dirname( __FILE__ ) . '/includes/payment-methods/class-wc-gateway-stripe-multibanco.php' );
117
-			require_once( dirname( __FILE__ ) . '/includes/payment-methods/class-wc-stripe-payment-request.php' );
118
-			require_once( dirname( __FILE__ ) . '/includes/compat/class-wc-stripe-subs-compat.php' );
119
-			require_once( dirname( __FILE__ ) . '/includes/compat/class-wc-stripe-sepa-subs-compat.php' );
120
-			require_once( dirname( __FILE__ ) . '/includes/class-wc-stripe-order-handler.php' );
121
-			require_once( dirname( __FILE__ ) . '/includes/class-wc-stripe-payment-tokens.php' );
122
-			require_once( dirname( __FILE__ ) . '/includes/class-wc-stripe-customer.php' );
123
-
124
-			if ( is_admin() ) {
125
-				require_once( dirname( __FILE__ ) . '/includes/admin/class-wc-stripe-admin-notices.php' );
99
+			load_plugin_textdomain('woocommerce-gateway-stripe', false, plugin_basename(dirname(__FILE__)) . '/languages');
100
+
101
+			require_once(dirname(__FILE__) . '/includes/abstracts/abstract-wc-stripe-payment-gateway.php');
102
+			require_once(dirname(__FILE__) . '/includes/class-wc-stripe-webhook-handler.php');
103
+			require_once(dirname(__FILE__) . '/includes/class-wc-stripe-sepa-payment-token.php');
104
+			require_once(dirname(__FILE__) . '/includes/class-wc-stripe-apple-pay-registration.php');
105
+			require_once(dirname(__FILE__) . '/includes/compat/class-wc-stripe-pre-orders-compat.php');
106
+			require_once(dirname(__FILE__) . '/includes/class-wc-gateway-stripe.php');
107
+			require_once(dirname(__FILE__) . '/includes/payment-methods/class-wc-gateway-stripe-bancontact.php');
108
+			require_once(dirname(__FILE__) . '/includes/payment-methods/class-wc-gateway-stripe-sofort.php');
109
+			require_once(dirname(__FILE__) . '/includes/payment-methods/class-wc-gateway-stripe-giropay.php');
110
+			require_once(dirname(__FILE__) . '/includes/payment-methods/class-wc-gateway-stripe-eps.php');
111
+			require_once(dirname(__FILE__) . '/includes/payment-methods/class-wc-gateway-stripe-ideal.php');
112
+			require_once(dirname(__FILE__) . '/includes/payment-methods/class-wc-gateway-stripe-p24.php');
113
+			require_once(dirname(__FILE__) . '/includes/payment-methods/class-wc-gateway-stripe-alipay.php');
114
+			require_once(dirname(__FILE__) . '/includes/payment-methods/class-wc-gateway-stripe-sepa.php');
115
+			require_once(dirname(__FILE__) . '/includes/payment-methods/class-wc-gateway-stripe-bitcoin.php');
116
+			require_once(dirname(__FILE__) . '/includes/payment-methods/class-wc-gateway-stripe-multibanco.php');
117
+			require_once(dirname(__FILE__) . '/includes/payment-methods/class-wc-stripe-payment-request.php');
118
+			require_once(dirname(__FILE__) . '/includes/compat/class-wc-stripe-subs-compat.php');
119
+			require_once(dirname(__FILE__) . '/includes/compat/class-wc-stripe-sepa-subs-compat.php');
120
+			require_once(dirname(__FILE__) . '/includes/class-wc-stripe-order-handler.php');
121
+			require_once(dirname(__FILE__) . '/includes/class-wc-stripe-payment-tokens.php');
122
+			require_once(dirname(__FILE__) . '/includes/class-wc-stripe-customer.php');
123
+
124
+			if (is_admin()) {
125
+				require_once(dirname(__FILE__) . '/includes/admin/class-wc-stripe-admin-notices.php');
126 126
 			}
127 127
 
128 128
 			// REMOVE IN THE FUTURE.
129
-			require_once( dirname( __FILE__ ) . '/includes/deprecated/class-wc-stripe-apple-pay.php' );
129
+			require_once(dirname(__FILE__) . '/includes/deprecated/class-wc-stripe-apple-pay.php');
130 130
 
131
-			add_filter( 'woocommerce_payment_gateways', array( $this, 'add_gateways' ) );
132
-			add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), array( $this, 'plugin_action_links' ) );
133
-			add_filter( 'woocommerce_get_sections_checkout', array( $this, 'filter_gateway_order_admin' ) );
131
+			add_filter('woocommerce_payment_gateways', array($this, 'add_gateways'));
132
+			add_filter('plugin_action_links_' . plugin_basename(__FILE__), array($this, 'plugin_action_links'));
133
+			add_filter('woocommerce_get_sections_checkout', array($this, 'filter_gateway_order_admin'));
134 134
 		}
135 135
 
136 136
 		/**
@@ -142,26 +142,26 @@  discard block
 block discarded – undo
142 142
 		 * @version 4.0.0
143 143
 		 */
144 144
 		public function get_environment_warning() {
145
-			if ( version_compare( phpversion(), WC_STRIPE_MIN_PHP_VER, '<' ) ) {
145
+			if (version_compare(phpversion(), WC_STRIPE_MIN_PHP_VER, '<')) {
146 146
 				/* translators: 1) int version 2) int version */
147
-				$message = __( 'WooCommerce Stripe - The minimum PHP version required for this plugin is %1$s. You are running %2$s.', 'woocommerce-gateway-stripe' );
147
+				$message = __('WooCommerce Stripe - The minimum PHP version required for this plugin is %1$s. You are running %2$s.', 'woocommerce-gateway-stripe');
148 148
 
149
-				return sprintf( $message, WC_STRIPE_MIN_PHP_VER, phpversion() );
149
+				return sprintf($message, WC_STRIPE_MIN_PHP_VER, phpversion());
150 150
 			}
151 151
 
152
-			if ( ! defined( 'WC_VERSION' ) ) {
153
-				return __( 'WooCommerce Stripe requires WooCommerce to be activated to work.', 'woocommerce-gateway-stripe' );
152
+			if ( ! defined('WC_VERSION')) {
153
+				return __('WooCommerce Stripe requires WooCommerce to be activated to work.', 'woocommerce-gateway-stripe');
154 154
 			}
155 155
 
156
-			if ( version_compare( WC_VERSION, WC_STRIPE_MIN_WC_VER, '<' ) ) {
156
+			if (version_compare(WC_VERSION, WC_STRIPE_MIN_WC_VER, '<')) {
157 157
 				/* translators: 1) int version 2) int version */
158
-				$message = __( 'WooCommerce Stripe - The minimum WooCommerce version required for this plugin is %1$s. You are running %2$s.', 'woocommerce-gateway-stripe' );
158
+				$message = __('WooCommerce Stripe - The minimum WooCommerce version required for this plugin is %1$s. You are running %2$s.', 'woocommerce-gateway-stripe');
159 159
 
160
-				return sprintf( $message, WC_STRIPE_MIN_WC_VER, WC_VERSION );
160
+				return sprintf($message, WC_STRIPE_MIN_WC_VER, WC_VERSION);
161 161
 			}
162 162
 
163
-			if ( ! function_exists( 'curl_init' ) ) {
164
-				return __( 'WooCommerce Stripe - cURL is not installed.', 'woocommerce-gateway-stripe' );
163
+			if ( ! function_exists('curl_init')) {
164
+				return __('WooCommerce Stripe - cURL is not installed.', 'woocommerce-gateway-stripe');
165 165
 			}
166 166
 
167 167
 			return false;
@@ -174,8 +174,8 @@  discard block
 block discarded – undo
174 174
 		 * @version 4.0.0
175 175
 		 */
176 176
 		public function update_plugin_version() {
177
-			delete_option( 'wc_stripe_version' );
178
-			update_option( 'wc_stripe_version', WC_STRIPE_VERSION );
177
+			delete_option('wc_stripe_version');
178
+			update_option('wc_stripe_version', WC_STRIPE_VERSION);
179 179
 		}
180 180
 
181 181
 		/**
@@ -185,11 +185,11 @@  discard block
 block discarded – undo
185 185
 		 * @version 3.1.0
186 186
 		 */
187 187
 		public function install() {
188
-			if ( ! defined( 'IFRAME_REQUEST' ) && ( WC_STRIPE_VERSION !== get_option( 'wc_stripe_version' ) ) ) {
189
-				do_action( 'woocommerce_stripe_updated' );
188
+			if ( ! defined('IFRAME_REQUEST') && (WC_STRIPE_VERSION !== get_option('wc_stripe_version'))) {
189
+				do_action('woocommerce_stripe_updated');
190 190
 
191
-				if ( ! defined( 'WC_STRIPE_INSTALLING' ) ) {
192
-					define( 'WC_STRIPE_INSTALLING', true );
191
+				if ( ! defined('WC_STRIPE_INSTALLING')) {
192
+					define('WC_STRIPE_INSTALLING', true);
193 193
 				}
194 194
 
195 195
 				$this->update_plugin_version();
@@ -202,13 +202,13 @@  discard block
 block discarded – undo
202 202
 		 * @since 1.0.0
203 203
 		 * @version 4.0.0
204 204
 		 */
205
-		public function plugin_action_links( $links ) {
205
+		public function plugin_action_links($links) {
206 206
 			$plugin_links = array(
207
-				'<a href="admin.php?page=wc-settings&tab=checkout&section=stripe">' . esc_html__( 'Settings', 'woocommerce-gateway-stripe' ) . '</a>',
208
-				'<a href="https://docs.woocommerce.com/document/stripe/">' . esc_html__( 'Docs', 'woocommerce-gateway-stripe' ) . '</a>',
209
-				'<a href="https://woocommerce.com/contact-us/">' . esc_html__( 'Support', 'woocommerce-gateway-stripe' ) . '</a>',
207
+				'<a href="admin.php?page=wc-settings&tab=checkout&section=stripe">' . esc_html__('Settings', 'woocommerce-gateway-stripe') . '</a>',
208
+				'<a href="https://docs.woocommerce.com/document/stripe/">' . esc_html__('Docs', 'woocommerce-gateway-stripe') . '</a>',
209
+				'<a href="https://woocommerce.com/contact-us/">' . esc_html__('Support', 'woocommerce-gateway-stripe') . '</a>',
210 210
 			);
211
-			return array_merge( $plugin_links, $links );
211
+			return array_merge($plugin_links, $links);
212 212
 		}
213 213
 
214 214
 		/**
@@ -217,8 +217,8 @@  discard block
 block discarded – undo
217 217
 		 * @since 1.0.0
218 218
 		 * @version 4.0.0
219 219
 		 */
220
-		public function add_gateways( $methods ) {
221
-			if ( class_exists( 'WC_Subscriptions_Order' ) && function_exists( 'wcs_create_renewal_order' ) ) {
220
+		public function add_gateways($methods) {
221
+			if (class_exists('WC_Subscriptions_Order') && function_exists('wcs_create_renewal_order')) {
222 222
 				$methods[] = 'WC_Stripe_Subs_Compat';
223 223
 				$methods[] = 'WC_Stripe_Sepa_Subs_Compat';
224 224
 			} else {
@@ -245,30 +245,30 @@  discard block
 block discarded – undo
245 245
 		 * @since 4.0.0
246 246
 		 * @version 4.0.0
247 247
 		 */
248
-		public function filter_gateway_order_admin( $sections ) {
249
-			unset( $sections['stripe'] );
250
-			unset( $sections['stripe_bancontact'] );
251
-			unset( $sections['stripe_sofort'] );
252
-			unset( $sections['stripe_giropay'] );
253
-			unset( $sections['stripe_eps'] );
254
-			unset( $sections['stripe_ideal'] );
255
-			unset( $sections['stripe_p24'] );
256
-			unset( $sections['stripe_alipay'] );
257
-			unset( $sections['stripe_sepa'] );
258
-			unset( $sections['stripe_bitcoin'] );
259
-			unset( $sections['stripe_multibanco'] );
248
+		public function filter_gateway_order_admin($sections) {
249
+			unset($sections['stripe']);
250
+			unset($sections['stripe_bancontact']);
251
+			unset($sections['stripe_sofort']);
252
+			unset($sections['stripe_giropay']);
253
+			unset($sections['stripe_eps']);
254
+			unset($sections['stripe_ideal']);
255
+			unset($sections['stripe_p24']);
256
+			unset($sections['stripe_alipay']);
257
+			unset($sections['stripe_sepa']);
258
+			unset($sections['stripe_bitcoin']);
259
+			unset($sections['stripe_multibanco']);
260 260
 
261 261
 			$sections['stripe']            = 'Stripe';
262
-			$sections['stripe_bancontact'] = __( 'Stripe Bancontact', 'woocommerce-gateway-stripe' );
263
-			$sections['stripe_sofort']     = __( 'Stripe SOFORT', 'woocommerce-gateway-stripe' );
264
-			$sections['stripe_giropay']    = __( 'Stripe Giropay', 'woocommerce-gateway-stripe' );
265
-			$sections['stripe_eps']        = __( 'Stripe EPS', 'woocommerce-gateway-stripe' );
266
-			$sections['stripe_ideal']      = __( 'Stripe iDeal', 'woocommerce-gateway-stripe' );
267
-			$sections['stripe_p24']        = __( 'Stripe P24', 'woocommerce-gateway-stripe' );
268
-			$sections['stripe_alipay']     = __( 'Stripe Alipay', 'woocommerce-gateway-stripe' );
269
-			$sections['stripe_sepa']       = __( 'Stripe SEPA Direct Debit', 'woocommerce-gateway-stripe' );
270
-			$sections['stripe_bitcoin']    = __( 'Stripe Bitcoin', 'woocommerce-gateway-stripe' );
271
-			$sections['stripe_multibanco'] = __( 'Stripe Multibanco', 'woocommerce-gateway-stripe' );
262
+			$sections['stripe_bancontact'] = __('Stripe Bancontact', 'woocommerce-gateway-stripe');
263
+			$sections['stripe_sofort']     = __('Stripe SOFORT', 'woocommerce-gateway-stripe');
264
+			$sections['stripe_giropay']    = __('Stripe Giropay', 'woocommerce-gateway-stripe');
265
+			$sections['stripe_eps']        = __('Stripe EPS', 'woocommerce-gateway-stripe');
266
+			$sections['stripe_ideal']      = __('Stripe iDeal', 'woocommerce-gateway-stripe');
267
+			$sections['stripe_p24']        = __('Stripe P24', 'woocommerce-gateway-stripe');
268
+			$sections['stripe_alipay']     = __('Stripe Alipay', 'woocommerce-gateway-stripe');
269
+			$sections['stripe_sepa']       = __('Stripe SEPA Direct Debit', 'woocommerce-gateway-stripe');
270
+			$sections['stripe_bitcoin']    = __('Stripe Bitcoin', 'woocommerce-gateway-stripe');
271
+			$sections['stripe_multibanco'] = __('Stripe Multibanco', 'woocommerce-gateway-stripe');
272 272
 
273 273
 			return $sections;
274 274
 		}
Please login to merge, or discard this patch.
includes/class-wc-stripe-webhook-handler.php 1 patch
Spacing   +180 added lines, -180 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
 
@@ -32,9 +32,9 @@  discard block
 block discarded – undo
32 32
 	 */
33 33
 	public function __construct() {
34 34
 		$this->retry_interval = 2;
35
-		$stripe_settings      = get_option( 'woocommerce_stripe_settings', array() );
36
-		$this->testmode       = ( ! empty( $stripe_settings['testmode'] ) && 'yes' === $stripe_settings['testmode'] ) ? true : false;
37
-		add_action( 'woocommerce_api_wc_stripe', array( $this, 'check_for_webhook' ) );
35
+		$stripe_settings      = get_option('woocommerce_stripe_settings', array());
36
+		$this->testmode       = ( ! empty($stripe_settings['testmode']) && 'yes' === $stripe_settings['testmode']) ? true : false;
37
+		add_action('woocommerce_api_wc_stripe', array($this, 'check_for_webhook'));
38 38
 	}
39 39
 
40 40
 	/**
@@ -44,24 +44,24 @@  discard block
 block discarded – undo
44 44
 	 * @version 4.0.0
45 45
 	 */
46 46
 	public function check_for_webhook() {
47
-		if ( ( 'POST' !== $_SERVER['REQUEST_METHOD'] )
48
-			|| ! isset( $_GET['wc-api'] )
49
-			|| ( 'wc_stripe' !== $_GET['wc-api'] )
47
+		if (('POST' !== $_SERVER['REQUEST_METHOD'])
48
+			|| ! isset($_GET['wc-api'])
49
+			|| ('wc_stripe' !== $_GET['wc-api'])
50 50
 		) {
51 51
 			return;
52 52
 		}
53 53
 
54
-		$request_body    = file_get_contents( 'php://input' );
55
-		$request_headers = array_change_key_case( $this->get_request_headers(), CASE_UPPER );
54
+		$request_body    = file_get_contents('php://input');
55
+		$request_headers = array_change_key_case($this->get_request_headers(), CASE_UPPER);
56 56
 
57 57
 		// Validate it to make sure it is legit.
58
-		if ( $this->is_valid_request( $request_headers, $request_body ) ) {
59
-			$this->process_webhook( $request_body );
60
-			status_header( 200 );
58
+		if ($this->is_valid_request($request_headers, $request_body)) {
59
+			$this->process_webhook($request_body);
60
+			status_header(200);
61 61
 			exit;
62 62
 		} else {
63
-			WC_Stripe_Logger::log( 'Incoming webhook failed validation: ' . print_r( $request_body, true ) );
64
-			status_header( 400 );
63
+			WC_Stripe_Logger::log('Incoming webhook failed validation: ' . print_r($request_body, true));
64
+			status_header(400);
65 65
 			exit;
66 66
 		}
67 67
 	}
@@ -76,12 +76,12 @@  discard block
 block discarded – undo
76 76
 	 * @param string $request_body The request body from Stripe.
77 77
 	 * @return bool
78 78
 	 */
79
-	public function is_valid_request( $request_headers = null, $request_body = null ) {
80
-		if ( null === $request_headers || null === $request_body ) {
79
+	public function is_valid_request($request_headers = null, $request_body = null) {
80
+		if (null === $request_headers || null === $request_body) {
81 81
 			return false;
82 82
 		}
83 83
 
84
-		if ( ! empty( $request_headers['USER-AGENT'] ) && ! preg_match( '/Stripe/', $request_headers['USER-AGENT'] ) ) {
84
+		if ( ! empty($request_headers['USER-AGENT']) && ! preg_match('/Stripe/', $request_headers['USER-AGENT'])) {
85 85
 			return false;
86 86
 		}
87 87
 
@@ -97,11 +97,11 @@  discard block
 block discarded – undo
97 97
 	 * @version 4.0.0
98 98
 	 */
99 99
 	public function get_request_headers() {
100
-		if ( ! function_exists( 'getallheaders' ) ) {
100
+		if ( ! function_exists('getallheaders')) {
101 101
 			$headers = [];
102
-			foreach ( $_SERVER as $name => $value ) {
103
-				if ( 'HTTP_' === substr( $name, 0, 5 ) ) {
104
-					$headers[ str_replace( ' ', '-', ucwords( strtolower( str_replace( '_', ' ', substr( $name, 5 ) ) ) ) ) ] = $value;
102
+			foreach ($_SERVER as $name => $value) {
103
+				if ('HTTP_' === substr($name, 0, 5)) {
104
+					$headers[str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', substr($name, 5)))))] = $value;
105 105
 				}
106 106
 			}
107 107
 
@@ -120,30 +120,30 @@  discard block
 block discarded – undo
120 120
 	 * @param object $notification
121 121
 	 * @param bool $retry
122 122
 	 */
123
-	public function process_webhook_payment( $notification, $retry = true ) {
123
+	public function process_webhook_payment($notification, $retry = true) {
124 124
 		// The following 2 payment methods are synchronous so does not need to be handle via webhook.
125
-		if ( 'card' === $notification->data->object->type || 'sepa_debit' === $notification->data->object->type ) {
125
+		if ('card' === $notification->data->object->type || 'sepa_debit' === $notification->data->object->type) {
126 126
 			return;
127 127
 		}
128 128
 
129
-		$order = WC_Stripe_Helper::get_order_by_source_id( $notification->data->object->id );
129
+		$order = WC_Stripe_Helper::get_order_by_source_id($notification->data->object->id);
130 130
 
131
-		if ( ! $order ) {
132
-			WC_Stripe_Logger::log( 'Could not find order via source ID: ' . $notification->data->object->id );
131
+		if ( ! $order) {
132
+			WC_Stripe_Logger::log('Could not find order via source ID: ' . $notification->data->object->id);
133 133
 			return;
134 134
 		}
135 135
 
136 136
 		$order_id  = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
137 137
 		$source_id = $notification->data->object->id;
138 138
 
139
-		$is_pending_receiver = ( 'receiver' === $notification->data->object->flow );
139
+		$is_pending_receiver = ('receiver' === $notification->data->object->flow);
140 140
 
141 141
 		try {
142
-			if ( 'processing' === $order->get_status() || 'completed' === $order->get_status() ) {
142
+			if ('processing' === $order->get_status() || 'completed' === $order->get_status()) {
143 143
 				return;
144 144
 			}
145 145
 
146
-			if ( 'on-hold' === $order->get_status() && ! $is_pending_receiver ) {
146
+			if ('on-hold' === $order->get_status() && ! $is_pending_receiver) {
147 147
 				return;
148 148
 			}
149 149
 
@@ -151,94 +151,94 @@  discard block
 block discarded – undo
151 151
 			$response = null;
152 152
 
153 153
 			// This will throw exception if not valid.
154
-			$this->validate_minimum_order_amount( $order );
154
+			$this->validate_minimum_order_amount($order);
155 155
 
156
-			WC_Stripe_Logger::log( "Info: (Webhook) Begin processing payment for order $order_id for the amount of {$order->get_total()}" );
156
+			WC_Stripe_Logger::log("Info: (Webhook) Begin processing payment for order $order_id for the amount of {$order->get_total()}");
157 157
 
158 158
 			// Prep source object.
159 159
 			$source_object           = new stdClass();
160 160
 			$source_object->token_id = '';
161
-			$source_object->customer = $this->get_stripe_customer_id( $order );
161
+			$source_object->customer = $this->get_stripe_customer_id($order);
162 162
 			$source_object->source   = $source_id;
163 163
 
164 164
 			// Make the request.
165
-			$response = WC_Stripe_API::request( $this->generate_payment_request( $order, $source_object ), 'charges', 'POST', true );
165
+			$response = WC_Stripe_API::request($this->generate_payment_request($order, $source_object), 'charges', 'POST', true);
166 166
 			$headers  = $response['headers'];
167 167
 			$response = $response['body'];
168 168
 
169
-			if ( ! empty( $response->error ) ) {
169
+			if ( ! empty($response->error)) {
170 170
 				// Customer param wrong? The user may have been deleted on stripe's end. Remove customer_id. Can be retried without.
171
-				if ( $this->is_no_such_customer_error( $response->error ) ) {
172
-					if ( WC_Stripe_Helper::is_pre_30() ) {
173
-						delete_user_meta( $order->customer_user, '_stripe_customer_id' );
174
-						delete_post_meta( $order_id, '_stripe_customer_id' );
171
+				if ($this->is_no_such_customer_error($response->error)) {
172
+					if (WC_Stripe_Helper::is_pre_30()) {
173
+						delete_user_meta($order->customer_user, '_stripe_customer_id');
174
+						delete_post_meta($order_id, '_stripe_customer_id');
175 175
 					} else {
176
-						delete_user_meta( $order->get_customer_id(), '_stripe_customer_id' );
177
-						$order->delete_meta_data( '_stripe_customer_id' );
176
+						delete_user_meta($order->get_customer_id(), '_stripe_customer_id');
177
+						$order->delete_meta_data('_stripe_customer_id');
178 178
 						$order->save();
179 179
 					}
180 180
 				}
181 181
 
182
-				if ( $this->is_no_such_token_error( $response->error ) && $prepared_source->token_id ) {
182
+				if ($this->is_no_such_token_error($response->error) && $prepared_source->token_id) {
183 183
 					// Source param wrong? The CARD may have been deleted on stripe's end. Remove token and show message.
184
-					$wc_token = WC_Payment_Tokens::get( $prepared_source->token_id );
184
+					$wc_token = WC_Payment_Tokens::get($prepared_source->token_id);
185 185
 					$wc_token->delete();
186
-					$localized_message = __( 'This card is no longer available and has been removed.', 'woocommerce-gateway-stripe' );
187
-					$order->add_order_note( $localized_message );
188
-					throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message );
186
+					$localized_message = __('This card is no longer available and has been removed.', 'woocommerce-gateway-stripe');
187
+					$order->add_order_note($localized_message);
188
+					throw new WC_Stripe_Exception(print_r($response, true), $localized_message);
189 189
 				}
190 190
 
191 191
 				// We want to retry.
192
-				if ( $this->is_retryable_error( $response->error ) ) {
193
-					if ( $retry ) {
192
+				if ($this->is_retryable_error($response->error)) {
193
+					if ($retry) {
194 194
 						// Don't do anymore retries after this.
195
-						if ( 5 <= $this->retry_interval ) {
195
+						if (5 <= $this->retry_interval) {
196 196
 
197
-							return $this->process_webhook_payment( $notification, false );
197
+							return $this->process_webhook_payment($notification, false);
198 198
 						}
199 199
 
200
-						sleep( $this->retry_interval );
200
+						sleep($this->retry_interval);
201 201
 
202 202
 						$this->retry_interval++;
203
-						return $this->process_webhook_payment( $notification, true );
203
+						return $this->process_webhook_payment($notification, true);
204 204
 					} else {
205
-						$localized_message = __( 'Sorry, we are unable to process your payment at this time. Please retry later.', 'woocommerce-gateway-stripe' );
206
-						$order->add_order_note( $localized_message );
207
-						throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message );
205
+						$localized_message = __('Sorry, we are unable to process your payment at this time. Please retry later.', 'woocommerce-gateway-stripe');
206
+						$order->add_order_note($localized_message);
207
+						throw new WC_Stripe_Exception(print_r($response, true), $localized_message);
208 208
 					}
209 209
 				}
210 210
 
211 211
 				$localized_messages = WC_Stripe_Helper::get_localized_messages();
212 212
 
213
-				if ( 'card_error' === $response->error->type ) {
214
-					$localized_message = isset( $localized_messages[ $response->error->code ] ) ? $localized_messages[ $response->error->code ] : $response->error->message;
213
+				if ('card_error' === $response->error->type) {
214
+					$localized_message = isset($localized_messages[$response->error->code]) ? $localized_messages[$response->error->code] : $response->error->message;
215 215
 				} else {
216
-					$localized_message = isset( $localized_messages[ $response->error->type ] ) ? $localized_messages[ $response->error->type ] : $response->error->message;
216
+					$localized_message = isset($localized_messages[$response->error->type]) ? $localized_messages[$response->error->type] : $response->error->message;
217 217
 				}
218 218
 
219
-				$order->add_order_note( $localized_message );
219
+				$order->add_order_note($localized_message);
220 220
 
221
-				throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message );
221
+				throw new WC_Stripe_Exception(print_r($response, true), $localized_message);
222 222
 			}
223 223
 
224 224
 			// To prevent double processing the order on WC side.
225
-			if ( ! $this->is_original_request( $headers ) ) {
225
+			if ( ! $this->is_original_request($headers)) {
226 226
 				return;
227 227
 			}
228 228
 
229
-			do_action( 'wc_gateway_stripe_process_webhook_payment', $response, $order );
229
+			do_action('wc_gateway_stripe_process_webhook_payment', $response, $order);
230 230
 
231
-			$this->process_response( $response, $order );
231
+			$this->process_response($response, $order);
232 232
 
233
-		} catch ( WC_Stripe_Exception $e ) {
234
-			WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() );
233
+		} catch (WC_Stripe_Exception $e) {
234
+			WC_Stripe_Logger::log('Error: ' . $e->getMessage());
235 235
 
236
-			do_action( 'wc_gateway_stripe_process_webhook_payment_error', $order, $notification, $e );
236
+			do_action('wc_gateway_stripe_process_webhook_payment_error', $order, $notification, $e);
237 237
 
238
-			$statuses = array( 'pending', 'failed' );
238
+			$statuses = array('pending', 'failed');
239 239
 
240
-			if ( $order->has_status( $statuses ) ) {
241
-				$this->send_failed_order_email( $order_id );
240
+			if ($order->has_status($statuses)) {
241
+				$this->send_failed_order_email($order_id);
242 242
 			}
243 243
 		}
244 244
 	}
@@ -251,21 +251,21 @@  discard block
 block discarded – undo
251 251
 	 * @since 4.0.0
252 252
 	 * @param object $notification
253 253
 	 */
254
-	public function process_webhook_dispute( $notification ) {
255
-		$order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->charge );
254
+	public function process_webhook_dispute($notification) {
255
+		$order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->charge);
256 256
 
257
-		if ( ! $order ) {
258
-			WC_Stripe_Logger::log( 'Could not find order via charge ID: ' . $notification->data->object->charge );
257
+		if ( ! $order) {
258
+			WC_Stripe_Logger::log('Could not find order via charge ID: ' . $notification->data->object->charge);
259 259
 			return;
260 260
 		}
261 261
 
262 262
 		/* translators: 1) The URL to the order. */
263
-		$order->update_status( 'on-hold', sprintf( __( 'A dispute was created for this order. Response is needed. Please go to your <a href="%s" title="Stripe Dashboard" target="_blank">Stripe Dashboard</a> to review this dispute.', 'woocommerce-gateway-stripe' ), $this->get_transaction_url( $order ) ) );
263
+		$order->update_status('on-hold', sprintf(__('A dispute was created for this order. Response is needed. Please go to your <a href="%s" title="Stripe Dashboard" target="_blank">Stripe Dashboard</a> to review this dispute.', 'woocommerce-gateway-stripe'), $this->get_transaction_url($order)));
264 264
 
265
-		do_action( 'wc_gateway_stripe_process_webhook_payment_error', $order, $notification );
265
+		do_action('wc_gateway_stripe_process_webhook_payment_error', $order, $notification);
266 266
 
267 267
 		$order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
268
-		$this->send_failed_order_email( $order_id );
268
+		$this->send_failed_order_email($order_id);
269 269
 	}
270 270
 
271 271
 	/**
@@ -276,41 +276,41 @@  discard block
 block discarded – undo
276 276
 	 * @version 4.0.0
277 277
 	 * @param object $notification
278 278
 	 */
279
-	public function process_webhook_capture( $notification ) {
280
-		$order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->id );
279
+	public function process_webhook_capture($notification) {
280
+		$order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->id);
281 281
 
282
-		if ( ! $order ) {
283
-			WC_Stripe_Logger::log( 'Could not find order via charge ID: ' . $notification->data->object->id );
282
+		if ( ! $order) {
283
+			WC_Stripe_Logger::log('Could not find order via charge ID: ' . $notification->data->object->id);
284 284
 			return;
285 285
 		}
286 286
 
287 287
 		$order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
288 288
 
289
-		if ( 'stripe' === ( WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method() ) ) {
290
-			$charge   = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_transaction_id', true ) : $order->get_transaction_id();
291
-			$captured = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_stripe_charge_captured', true ) : $order->get_meta( '_stripe_charge_captured', true );
289
+		if ('stripe' === (WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method())) {
290
+			$charge   = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_transaction_id', true) : $order->get_transaction_id();
291
+			$captured = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_stripe_charge_captured', true) : $order->get_meta('_stripe_charge_captured', true);
292 292
 
293
-			if ( $charge && 'no' === $captured ) {
294
-				WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, '_stripe_charge_captured', 'yes' ) : $order->update_meta_data( '_stripe_charge_captured', 'yes' );
293
+			if ($charge && 'no' === $captured) {
294
+				WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, '_stripe_charge_captured', 'yes') : $order->update_meta_data('_stripe_charge_captured', 'yes');
295 295
 
296 296
 				// Store other data such as fees
297
-				WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, '_transaction_id', $notification->data->object->id ) : $order->set_transaction_id( $notification->data->object->id );
297
+				WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, '_transaction_id', $notification->data->object->id) : $order->set_transaction_id($notification->data->object->id);
298 298
 
299
-				if ( isset( $notification->data->object->balance_transaction ) ) {
300
-					$this->update_fees( $order, $notification->data->object->balance_transaction );
299
+				if (isset($notification->data->object->balance_transaction)) {
300
+					$this->update_fees($order, $notification->data->object->balance_transaction);
301 301
 				}
302 302
 
303
-				if ( is_callable( array( $order, 'save' ) ) ) {
303
+				if (is_callable(array($order, 'save'))) {
304 304
 					$order->save();
305 305
 				}
306 306
 
307 307
 				/* translators: transaction id */
308
-				$order->update_status( $order->needs_processing() ? 'processing' : 'completed', sprintf( __( 'Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe' ), $notification->data->object->id ) );
308
+				$order->update_status($order->needs_processing() ? 'processing' : 'completed', sprintf(__('Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe'), $notification->data->object->id));
309 309
 
310 310
 				// Check and see if capture is partial.
311
-				if ( $this->is_partial_capture( $notification ) ) {
312
-					$order->set_total( $this->get_partial_amount_to_charge( $notification ) );
313
-					$order->add_order_note( __( 'This charge was partially captured via Stripe Dashboard', 'woocommerce-gateway-stripe' ) );
311
+				if ($this->is_partial_capture($notification)) {
312
+					$order->set_total($this->get_partial_amount_to_charge($notification));
313
+					$order->add_order_note(__('This charge was partially captured via Stripe Dashboard', 'woocommerce-gateway-stripe'));
314 314
 					$order->save();
315 315
 				}
316 316
 			}
@@ -325,38 +325,38 @@  discard block
 block discarded – undo
325 325
 	 * @version 4.0.0
326 326
 	 * @param object $notification
327 327
 	 */
328
-	public function process_webhook_charge_succeeded( $notification ) {
328
+	public function process_webhook_charge_succeeded($notification) {
329 329
 		// The following payment methods are synchronous so does not need to be handle via webhook.
330
-		if ( ( isset( $notification->data->object->source->type ) && 'card' === $notification->data->object->source->type ) || ( isset( $notification->data->object->source->type ) && 'three_d_secure' === $notification->data->object->source->type ) ) {
330
+		if ((isset($notification->data->object->source->type) && 'card' === $notification->data->object->source->type) || (isset($notification->data->object->source->type) && 'three_d_secure' === $notification->data->object->source->type)) {
331 331
 			return;
332 332
 		}
333 333
 
334
-		$order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->id );
334
+		$order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->id);
335 335
 
336
-		if ( ! $order ) {
337
-			WC_Stripe_Logger::log( 'Could not find order via charge ID: ' . $notification->data->object->id );
336
+		if ( ! $order) {
337
+			WC_Stripe_Logger::log('Could not find order via charge ID: ' . $notification->data->object->id);
338 338
 			return;
339 339
 		}
340 340
 
341 341
 		$order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
342 342
 
343
-		if ( 'on-hold' !== $order->get_status() ) {
343
+		if ('on-hold' !== $order->get_status()) {
344 344
 			return;
345 345
 		}
346 346
 
347 347
 		// Store other data such as fees
348
-		WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, '_transaction_id', $notification->data->object->id ) : $order->set_transaction_id( $notification->data->object->id );
348
+		WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, '_transaction_id', $notification->data->object->id) : $order->set_transaction_id($notification->data->object->id);
349 349
 
350
-		if ( isset( $notification->data->object->balance_transaction ) ) {
351
-			$this->update_fees( $order, $notification->data->object->balance_transaction );
350
+		if (isset($notification->data->object->balance_transaction)) {
351
+			$this->update_fees($order, $notification->data->object->balance_transaction);
352 352
 		}
353 353
 
354
-		if ( is_callable( array( $order, 'save' ) ) ) {
354
+		if (is_callable(array($order, 'save'))) {
355 355
 			$order->save();
356 356
 		}
357 357
 
358 358
 		/* translators: transaction id */
359
-		$order->update_status( $order->needs_processing() ? 'processing' : 'completed', sprintf( __( 'Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe' ), $notification->data->object->id ) );
359
+		$order->update_status($order->needs_processing() ? 'processing' : 'completed', sprintf(__('Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe'), $notification->data->object->id));
360 360
 	}
361 361
 
362 362
 	/**
@@ -367,23 +367,23 @@  discard block
 block discarded – undo
367 367
 	 * @version 4.0.0
368 368
 	 * @param object $notification
369 369
 	 */
370
-	public function process_webhook_charge_failed( $notification ) {
371
-		$order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->id );
370
+	public function process_webhook_charge_failed($notification) {
371
+		$order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->id);
372 372
 
373
-		if ( ! $order ) {
374
-			WC_Stripe_Logger::log( 'Could not find order via charge ID: ' . $notification->data->object->id );
373
+		if ( ! $order) {
374
+			WC_Stripe_Logger::log('Could not find order via charge ID: ' . $notification->data->object->id);
375 375
 			return;
376 376
 		}
377 377
 
378 378
 		$order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
379 379
 
380
-		if ( 'on-hold' !== $order->get_status() ) {
380
+		if ('on-hold' !== $order->get_status()) {
381 381
 			return;
382 382
 		}
383 383
 
384
-		$order->update_status( 'failed', __( 'This payment failed to clear.', 'woocommerce-gateway-stripe' ) );
384
+		$order->update_status('failed', __('This payment failed to clear.', 'woocommerce-gateway-stripe'));
385 385
 
386
-		do_action( 'wc_gateway_stripe_process_webhook_payment_error', $order, $notification );
386
+		do_action('wc_gateway_stripe_process_webhook_payment_error', $order, $notification);
387 387
 	}
388 388
 
389 389
 	/**
@@ -394,23 +394,23 @@  discard block
 block discarded – undo
394 394
 	 * @version 4.0.0
395 395
 	 * @param object $notification
396 396
 	 */
397
-	public function process_webhook_source_canceled( $notification ) {
398
-		$order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->id );
397
+	public function process_webhook_source_canceled($notification) {
398
+		$order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->id);
399 399
 
400
-		if ( ! $order ) {
401
-			WC_Stripe_Logger::log( 'Could not find order via charge ID: ' . $notification->data->object->id );
400
+		if ( ! $order) {
401
+			WC_Stripe_Logger::log('Could not find order via charge ID: ' . $notification->data->object->id);
402 402
 			return;
403 403
 		}
404 404
 
405 405
 		$order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
406 406
 
407
-		if ( 'on-hold' !== $order->get_status() || 'cancelled' !== $order->get_status() ) {
407
+		if ('on-hold' !== $order->get_status() || 'cancelled' !== $order->get_status()) {
408 408
 			return;
409 409
 		}
410 410
 
411
-		$order->update_status( 'cancelled', __( 'This payment has cancelled.', 'woocommerce-gateway-stripe' ) );
411
+		$order->update_status('cancelled', __('This payment has cancelled.', 'woocommerce-gateway-stripe'));
412 412
 
413
-		do_action( 'wc_gateway_stripe_process_webhook_payment_error', $order, $notification );
413
+		do_action('wc_gateway_stripe_process_webhook_payment_error', $order, $notification);
414 414
 	}
415 415
 
416 416
 	/**
@@ -420,57 +420,57 @@  discard block
 block discarded – undo
420 420
 	 * @version 4.0.0
421 421
 	 * @param object $notification
422 422
 	 */
423
-	public function process_webhook_refund( $notification ) {
424
-		$order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->id );
423
+	public function process_webhook_refund($notification) {
424
+		$order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->id);
425 425
 
426
-		if ( ! $order ) {
427
-			WC_Stripe_Logger::log( 'Could not find order via charge ID: ' . $notification->data->object->id );
426
+		if ( ! $order) {
427
+			WC_Stripe_Logger::log('Could not find order via charge ID: ' . $notification->data->object->id);
428 428
 			return;
429 429
 		}
430 430
 
431 431
 		$order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
432 432
 
433
-		if ( 'stripe' === ( WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method() ) ) {
434
-			$charge    = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_transaction_id', true ) : $order->get_transaction_id();
435
-			$captured  = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_stripe_charge_captured', true ) : $order->get_meta( '_stripe_charge_captured', true );
436
-			$refund_id = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_stripe_refund_id', true ) : $order->get_meta( '_stripe_refund_id', true );
433
+		if ('stripe' === (WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method())) {
434
+			$charge    = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_transaction_id', true) : $order->get_transaction_id();
435
+			$captured  = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_stripe_charge_captured', true) : $order->get_meta('_stripe_charge_captured', true);
436
+			$refund_id = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_stripe_refund_id', true) : $order->get_meta('_stripe_refund_id', true);
437 437
 
438 438
 			// If the refund ID matches, don't continue to prevent double refunding.
439
-			if ( $notification->data->object->refunds->data[0]->id === $refund_id ) {
439
+			if ($notification->data->object->refunds->data[0]->id === $refund_id) {
440 440
 				return;
441 441
 			}
442 442
 
443 443
 			// Only refund captured charge.
444
-			if ( $charge ) {
445
-				$reason = ( isset( $captured ) && 'yes' === $captured ) ? __( 'Refunded via Stripe Dashboard', 'woocommerce-gateway-stripe' ) : __( 'Pre-Authorization Released via Stripe Dashboard', 'woocommerce-gateway-stripe' );
444
+			if ($charge) {
445
+				$reason = (isset($captured) && 'yes' === $captured) ? __('Refunded via Stripe Dashboard', 'woocommerce-gateway-stripe') : __('Pre-Authorization Released via Stripe Dashboard', 'woocommerce-gateway-stripe');
446 446
 
447 447
 				// Create the refund.
448
-				$refund = wc_create_refund( array(
448
+				$refund = wc_create_refund(array(
449 449
 					'order_id' => $order_id,
450
-					'amount'   => $this->get_refund_amount( $notification ),
450
+					'amount'   => $this->get_refund_amount($notification),
451 451
 					'reason'   => $reason,
452
-				) );
452
+				));
453 453
 
454
-				if ( is_wp_error( $refund ) ) {
455
-					WC_Stripe_Logger::log( $refund->get_error_message() );
454
+				if (is_wp_error($refund)) {
455
+					WC_Stripe_Logger::log($refund->get_error_message());
456 456
 				}
457 457
 
458
-				WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, '_stripe_refund_id', $notification->data->object->refunds->data[0]->id ) : $order->update_meta_data( '_stripe_refund_id', $notification->data->object->refunds->data[0]->id );
458
+				WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, '_stripe_refund_id', $notification->data->object->refunds->data[0]->id) : $order->update_meta_data('_stripe_refund_id', $notification->data->object->refunds->data[0]->id);
459 459
 
460
-				$amount = wc_price( $notification->data->object->refunds->data[0]->amount / 100 );
460
+				$amount = wc_price($notification->data->object->refunds->data[0]->amount / 100);
461 461
 
462
-				if ( in_array( strtolower( $order->get_currency() ), WC_Stripe_Helper::no_decimal_currencies() ) ) {
463
-					$amount = wc_price( $notification->data->object->refunds->data[0]->amount );
462
+				if (in_array(strtolower($order->get_currency()), WC_Stripe_Helper::no_decimal_currencies())) {
463
+					$amount = wc_price($notification->data->object->refunds->data[0]->amount);
464 464
 				}
465 465
 
466
-				if ( isset( $notification->data->object->refunds->data[0]->balance_transaction ) ) {
467
-					$this->update_fees( $order, $notification->data->object->refunds->data[0]->balance_transaction );
466
+				if (isset($notification->data->object->refunds->data[0]->balance_transaction)) {
467
+					$this->update_fees($order, $notification->data->object->refunds->data[0]->balance_transaction);
468 468
 				}
469 469
 
470 470
 				/* translators: 1) dollar amount 2) transaction id 3) refund message */
471
-				$refund_message = ( isset( $captured ) && 'yes' === $captured ) ? sprintf( __( 'Refunded %1$s - Refund ID: %2$s - %3$s', 'woocommerce-gateway-stripe' ), $amount, $notification->data->object->refunds->data[0]->id, $reason ) : __( 'Pre-Authorization Released via Stripe Dashboard', 'woocommerce-gateway-stripe' );
471
+				$refund_message = (isset($captured) && 'yes' === $captured) ? sprintf(__('Refunded %1$s - Refund ID: %2$s - %3$s', 'woocommerce-gateway-stripe'), $amount, $notification->data->object->refunds->data[0]->id, $reason) : __('Pre-Authorization Released via Stripe Dashboard', 'woocommerce-gateway-stripe');
472 472
 
473
-				$order->add_order_note( $refund_message );
473
+				$order->add_order_note($refund_message);
474 474
 			}
475 475
 		}
476 476
 	}
@@ -481,21 +481,21 @@  discard block
 block discarded – undo
481 481
 	 * @since 4.0.6
482 482
 	 * @param object $notification
483 483
 	 */
484
-	public function process_review_opened( $notification ) {
485
-		$order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->charge );
484
+	public function process_review_opened($notification) {
485
+		$order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->charge);
486 486
 
487
-		if ( ! $order ) {
488
-			WC_Stripe_Logger::log( 'Could not find order via charge ID: ' . $notification->data->object->charge );
487
+		if ( ! $order) {
488
+			WC_Stripe_Logger::log('Could not find order via charge ID: ' . $notification->data->object->charge);
489 489
 			return;
490 490
 		}
491 491
 
492 492
 		/* translators: 1) The URL to the order. 2) The reason type. */
493
-		$message = sprintf( __( 'A review has been opened for this order. Action is needed. Please go to your <a href="%1$s" title="Stripe Dashboard" target="_blank">Stripe Dashboard</a> to review the issue. Reason: (%2$s)', 'woocommerce-gateway-stripe' ), $this->get_transaction_url( $order ), $notification->data->object->reason );
493
+		$message = sprintf(__('A review has been opened for this order. Action is needed. Please go to your <a href="%1$s" title="Stripe Dashboard" target="_blank">Stripe Dashboard</a> to review the issue. Reason: (%2$s)', 'woocommerce-gateway-stripe'), $this->get_transaction_url($order), $notification->data->object->reason);
494 494
 
495
-		if ( apply_filters( 'wc_stripe_webhook_review_change_order_status', true, $order, $notification ) ) {
496
-			$order->update_status( 'on-hold', $message );
495
+		if (apply_filters('wc_stripe_webhook_review_change_order_status', true, $order, $notification)) {
496
+			$order->update_status('on-hold', $message);
497 497
 		} else {
498
-			$order->add_order_note( $message );
498
+			$order->add_order_note($message);
499 499
 		}
500 500
 	}
501 501
 
@@ -505,25 +505,25 @@  discard block
 block discarded – undo
505 505
 	 * @since 4.0.6
506 506
 	 * @param object $notification
507 507
 	 */
508
-	public function process_review_closed( $notification ) {
509
-		$order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->charge );
508
+	public function process_review_closed($notification) {
509
+		$order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->charge);
510 510
 
511
-		if ( ! $order ) {
512
-			WC_Stripe_Logger::log( 'Could not find order via charge ID: ' . $notification->data->object->charge );
511
+		if ( ! $order) {
512
+			WC_Stripe_Logger::log('Could not find order via charge ID: ' . $notification->data->object->charge);
513 513
 			return;
514 514
 		}
515 515
 
516 516
 		/* translators: 1) The reason type. */
517
-		$message = sprintf( __( 'The opened review for this order is now closed. Reason: (%s)', 'woocommerce-gateway-stripe' ), $notification->data->object->reason );
517
+		$message = sprintf(__('The opened review for this order is now closed. Reason: (%s)', 'woocommerce-gateway-stripe'), $notification->data->object->reason);
518 518
 
519
-		if ( 'on-hold' === $order->get_status() ) {
520
-			if ( apply_filters( 'wc_stripe_webhook_review_change_order_status', true, $order, $notification ) ) {
521
-				$order->update_status( 'processing', $message );
519
+		if ('on-hold' === $order->get_status()) {
520
+			if (apply_filters('wc_stripe_webhook_review_change_order_status', true, $order, $notification)) {
521
+				$order->update_status('processing', $message);
522 522
 			} else {
523
-				$order->add_order_note( $message );
523
+				$order->add_order_note($message);
524 524
 			}
525 525
 		} else {
526
-			$order->add_order_note( $message );
526
+			$order->add_order_note($message);
527 527
 		}
528 528
 	}
529 529
 
@@ -534,7 +534,7 @@  discard block
 block discarded – undo
534 534
 	 * @version 4.0.0
535 535
 	 * @param object $notification
536 536
 	 */
537
-	public function is_partial_capture( $notification ) {
537
+	public function is_partial_capture($notification) {
538 538
 		return 0 < $notification->data->object->amount_refunded;
539 539
 	}
540 540
 
@@ -545,11 +545,11 @@  discard block
 block discarded – undo
545 545
 	 * @version 4.0.0
546 546
 	 * @param object $notification
547 547
 	 */
548
-	public function get_refund_amount( $notification ) {
549
-		if ( $this->is_partial_capture( $notification ) ) {
548
+	public function get_refund_amount($notification) {
549
+		if ($this->is_partial_capture($notification)) {
550 550
 			$amount = $notification->data->object->refunds->data[0]->amount / 100;
551 551
 
552
-			if ( in_array( strtolower( $notification->data->object->currency ), WC_Stripe_Helper::no_decimal_currencies() ) ) {
552
+			if (in_array(strtolower($notification->data->object->currency), WC_Stripe_Helper::no_decimal_currencies())) {
553 553
 				$amount = $notification->data->object->refunds->data[0]->amount;
554 554
 			}
555 555
 
@@ -566,12 +566,12 @@  discard block
 block discarded – undo
566 566
 	 * @version 4.0.0
567 567
 	 * @param object $notification
568 568
 	 */
569
-	public function get_partial_amount_to_charge( $notification ) {
570
-		if ( $this->is_partial_capture( $notification ) ) {
571
-			$amount = ( $notification->data->object->amount - $notification->data->object->amount_refunded ) / 100;
569
+	public function get_partial_amount_to_charge($notification) {
570
+		if ($this->is_partial_capture($notification)) {
571
+			$amount = ($notification->data->object->amount - $notification->data->object->amount_refunded) / 100;
572 572
 
573
-			if ( in_array( strtolower( $notification->data->object->currency ), WC_Stripe_Helper::no_decimal_currencies() ) ) {
574
-				$amount = ( $notification->data->object->amount - $notification->data->object->amount_refunded );
573
+			if (in_array(strtolower($notification->data->object->currency), WC_Stripe_Helper::no_decimal_currencies())) {
574
+				$amount = ($notification->data->object->amount - $notification->data->object->amount_refunded);
575 575
 			}
576 576
 
577 577
 			return $amount;
@@ -587,44 +587,44 @@  discard block
 block discarded – undo
587 587
 	 * @version 4.0.0
588 588
 	 * @param string $request_body
589 589
 	 */
590
-	public function process_webhook( $request_body ) {
591
-		$notification = json_decode( $request_body );
590
+	public function process_webhook($request_body) {
591
+		$notification = json_decode($request_body);
592 592
 
593
-		switch ( $notification->type ) {
593
+		switch ($notification->type) {
594 594
 			case 'source.chargeable':
595
-				$this->process_webhook_payment( $notification );
595
+				$this->process_webhook_payment($notification);
596 596
 				break;
597 597
 
598 598
 			case 'source.canceled':
599
-				$this->process_webhook_source_canceled( $notification );
599
+				$this->process_webhook_source_canceled($notification);
600 600
 				break;
601 601
 
602 602
 			case 'charge.succeeded':
603
-				$this->process_webhook_charge_succeeded( $notification );
603
+				$this->process_webhook_charge_succeeded($notification);
604 604
 				break;
605 605
 
606 606
 			case 'charge.failed':
607
-				$this->process_webhook_charge_failed( $notification );
607
+				$this->process_webhook_charge_failed($notification);
608 608
 				break;
609 609
 
610 610
 			case 'charge.captured':
611
-				$this->process_webhook_capture( $notification );
611
+				$this->process_webhook_capture($notification);
612 612
 				break;
613 613
 
614 614
 			case 'charge.dispute.created':
615
-				$this->process_webhook_dispute( $notification );
615
+				$this->process_webhook_dispute($notification);
616 616
 				break;
617 617
 
618 618
 			case 'charge.refunded':
619
-				$this->process_webhook_refund( $notification );
619
+				$this->process_webhook_refund($notification);
620 620
 				break;
621 621
 
622 622
 			case 'review.opened':
623
-				$this->process_review_opened( $notification );
623
+				$this->process_review_opened($notification);
624 624
 				break;
625 625
 
626 626
 			case 'review.closed':
627
-				$this->process_review_closed( $notification );
627
+				$this->process_review_closed($notification);
628 628
 				break;
629 629
 
630 630
 		}
Please login to merge, or discard this patch.