Completed
Pull Request — master (#1226)
by
unknown
02:02
created
includes/class-wc-stripe-webhook-handler.php 1 patch
Spacing   +228 added lines, -228 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
 
@@ -39,12 +39,12 @@  discard block
 block discarded – undo
39 39
 	 */
40 40
 	public function __construct() {
41 41
 		$this->retry_interval = 2;
42
-		$stripe_settings      = get_option( 'woocommerce_stripe_settings', array() );
43
-		$this->testmode       = ( ! empty( $stripe_settings['testmode'] ) && 'yes' === $stripe_settings['testmode'] ) ? true : false;
44
-		$secret_key           = ( $this->testmode ? 'test_' : '' ) . 'webhook_secret';
45
-		$this->secret         = ! empty( $stripe_settings[ $secret_key ] ) ? $stripe_settings[ $secret_key ] : false;
42
+		$stripe_settings      = get_option('woocommerce_stripe_settings', array());
43
+		$this->testmode       = ( ! empty($stripe_settings['testmode']) && 'yes' === $stripe_settings['testmode']) ? true : false;
44
+		$secret_key           = ($this->testmode ? 'test_' : '') . 'webhook_secret';
45
+		$this->secret         = ! empty($stripe_settings[$secret_key]) ? $stripe_settings[$secret_key] : false;
46 46
 
47
-		add_action( 'woocommerce_api_wc_stripe', array( $this, 'check_for_webhook' ) );
47
+		add_action('woocommerce_api_wc_stripe', array($this, 'check_for_webhook'));
48 48
 	}
49 49
 
50 50
 	/**
@@ -54,24 +54,24 @@  discard block
 block discarded – undo
54 54
 	 * @version 4.0.0
55 55
 	 */
56 56
 	public function check_for_webhook() {
57
-		if ( ( 'POST' !== $_SERVER['REQUEST_METHOD'] )
58
-			|| ! isset( $_GET['wc-api'] )
59
-			|| ( 'wc_stripe' !== $_GET['wc-api'] )
57
+		if (('POST' !== $_SERVER['REQUEST_METHOD'])
58
+			|| ! isset($_GET['wc-api'])
59
+			|| ('wc_stripe' !== $_GET['wc-api'])
60 60
 		) {
61 61
 			return;
62 62
 		}
63 63
 
64
-		$request_body    = file_get_contents( 'php://input' );
65
-		$request_headers = array_change_key_case( $this->get_request_headers(), CASE_UPPER );
64
+		$request_body    = file_get_contents('php://input');
65
+		$request_headers = array_change_key_case($this->get_request_headers(), CASE_UPPER);
66 66
 
67 67
 		// Validate it to make sure it is legit.
68
-		if ( $this->is_valid_request( $request_headers, $request_body ) ) {
69
-			$this->process_webhook( $request_body );
70
-			status_header( 200 );
68
+		if ($this->is_valid_request($request_headers, $request_body)) {
69
+			$this->process_webhook($request_body);
70
+			status_header(200);
71 71
 			exit;
72 72
 		} else {
73
-			WC_Stripe_Logger::log( 'Incoming webhook failed validation: ' . print_r( $request_body, true ) );
74
-			status_header( 400 );
73
+			WC_Stripe_Logger::log('Incoming webhook failed validation: ' . print_r($request_body, true));
74
+			status_header(400);
75 75
 			exit;
76 76
 		}
77 77
 	}
@@ -85,34 +85,34 @@  discard block
 block discarded – undo
85 85
 	 * @param string $request_body The request body from Stripe.
86 86
 	 * @return bool
87 87
 	 */
88
-	public function is_valid_request( $request_headers = null, $request_body = null ) {
89
-		if ( null === $request_headers || null === $request_body ) {
88
+	public function is_valid_request($request_headers = null, $request_body = null) {
89
+		if (null === $request_headers || null === $request_body) {
90 90
 			return false;
91 91
 		}
92 92
 
93
-		if ( ! empty( $request_headers['USER-AGENT'] ) && ! preg_match( '/Stripe/', $request_headers['USER-AGENT'] ) ) {
93
+		if ( ! empty($request_headers['USER-AGENT']) && ! preg_match('/Stripe/', $request_headers['USER-AGENT'])) {
94 94
 			return false;
95 95
 		}
96 96
 
97
-		if ( ! empty( $this->secret ) ) {
97
+		if ( ! empty($this->secret)) {
98 98
 			// Check for a valid signature.
99 99
 			$signature_format = '/^t=(?P<timestamp>\d+)(?P<signatures>(,v\d+=[a-z0-9]+){1,2})$/';
100
-			if ( empty( $request_headers['STRIPE-SIGNATURE'] ) || ! preg_match( $signature_format, $request_headers['STRIPE-SIGNATURE'], $matches ) ) {
100
+			if (empty($request_headers['STRIPE-SIGNATURE']) || ! preg_match($signature_format, $request_headers['STRIPE-SIGNATURE'], $matches)) {
101 101
 				return false;
102 102
 			}
103 103
 
104 104
 			// Verify the timestamp.
105
-			$timestamp = intval( $matches['timestamp'] );
106
-			if ( abs( $timestamp - time() ) > 5 * MINUTE_IN_SECONDS ) {
105
+			$timestamp = intval($matches['timestamp']);
106
+			if (abs($timestamp - time()) > 5 * MINUTE_IN_SECONDS) {
107 107
 				return false;
108 108
 			}
109 109
 
110 110
 			// Generate the expected signature.
111 111
 			$signed_payload     = $timestamp . '.' . $request_body;
112
-			$expected_signature = hash_hmac( 'sha256', $signed_payload, $this->secret );
112
+			$expected_signature = hash_hmac('sha256', $signed_payload, $this->secret);
113 113
 
114 114
 			// Check if the expected signature is present.
115
-			if ( ! preg_match( '/,v\d+=' . preg_quote( $expected_signature, '/' ) . '/', $matches['signatures'] ) ) {
115
+			if ( ! preg_match('/,v\d+=' . preg_quote($expected_signature, '/') . '/', $matches['signatures'])) {
116 116
 				return false;
117 117
 			}
118 118
 		}
@@ -129,12 +129,12 @@  discard block
 block discarded – undo
129 129
 	 * @version 4.0.0
130 130
 	 */
131 131
 	public function get_request_headers() {
132
-		if ( ! function_exists( 'getallheaders' ) ) {
132
+		if ( ! function_exists('getallheaders')) {
133 133
 			$headers = array();
134 134
 
135
-			foreach ( $_SERVER as $name => $value ) {
136
-				if ( 'HTTP_' === substr( $name, 0, 5 ) ) {
137
-					$headers[ str_replace( ' ', '-', ucwords( strtolower( str_replace( '_', ' ', substr( $name, 5 ) ) ) ) ) ] = $value;
135
+			foreach ($_SERVER as $name => $value) {
136
+				if ('HTTP_' === substr($name, 0, 5)) {
137
+					$headers[str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', substr($name, 5)))))] = $value;
138 138
 				}
139 139
 			}
140 140
 
@@ -153,30 +153,30 @@  discard block
 block discarded – undo
153 153
 	 * @param object $notification
154 154
 	 * @param bool $retry
155 155
 	 */
156
-	public function process_webhook_payment( $notification, $retry = true ) {
156
+	public function process_webhook_payment($notification, $retry = true) {
157 157
 		// The following 3 payment methods are synchronous so does not need to be handle via webhook.
158
-		if ( 'card' === $notification->data->object->type || 'sepa_debit' === $notification->data->object->type || 'three_d_secure' === $notification->data->object->type ) {
158
+		if ('card' === $notification->data->object->type || 'sepa_debit' === $notification->data->object->type || 'three_d_secure' === $notification->data->object->type) {
159 159
 			return;
160 160
 		}
161 161
 
162
-		$order = WC_Stripe_Helper::get_order_by_source_id( $notification->data->object->id );
162
+		$order = WC_Stripe_Helper::get_order_by_source_id($notification->data->object->id);
163 163
 
164
-		if ( ! $order ) {
165
-			WC_Stripe_Logger::log( 'Could not find order via source ID: ' . $notification->data->object->id );
164
+		if ( ! $order) {
165
+			WC_Stripe_Logger::log('Could not find order via source ID: ' . $notification->data->object->id);
166 166
 			return;
167 167
 		}
168 168
 
169 169
 		$order_id  = $order->get_id();
170 170
 		$source_id = $notification->data->object->id;
171 171
 
172
-		$is_pending_receiver = ( 'receiver' === $notification->data->object->flow );
172
+		$is_pending_receiver = ('receiver' === $notification->data->object->flow);
173 173
 
174 174
 		try {
175
-			if ( $order->has_status( array( 'processing', 'completed' ) ) ) {
175
+			if ($order->has_status(array('processing', 'completed'))) {
176 176
 				return;
177 177
 			}
178 178
 
179
-			if ( $order->has_status( 'on-hold' ) && ! $is_pending_receiver ) {
179
+			if ($order->has_status('on-hold') && ! $is_pending_receiver) {
180 180
 				return;
181 181
 			}
182 182
 
@@ -184,89 +184,89 @@  discard block
 block discarded – undo
184 184
 			$response = null;
185 185
 
186 186
 			// This will throw exception if not valid.
187
-			$this->validate_minimum_order_amount( $order );
187
+			$this->validate_minimum_order_amount($order);
188 188
 
189
-			WC_Stripe_Logger::log( "Info: (Webhook) Begin processing payment for order $order_id for the amount of {$order->get_total()}" );
189
+			WC_Stripe_Logger::log("Info: (Webhook) Begin processing payment for order $order_id for the amount of {$order->get_total()}");
190 190
 
191 191
 			// Prep source object.
192 192
 			$source_object           = new stdClass();
193 193
 			$source_object->token_id = '';
194
-			$source_object->customer = $this->get_stripe_customer_id( $order );
194
+			$source_object->customer = $this->get_stripe_customer_id($order);
195 195
 			$source_object->source   = $source_id;
196 196
 
197 197
 			// Make the request.
198
-			$response = WC_Stripe_API::request( $this->generate_payment_request( $order, $source_object ), 'charges', 'POST', true );
198
+			$response = WC_Stripe_API::request($this->generate_payment_request($order, $source_object), 'charges', 'POST', true);
199 199
 			$headers  = $response['headers'];
200 200
 			$response = $response['body'];
201 201
 
202
-			if ( ! empty( $response->error ) ) {
202
+			if ( ! empty($response->error)) {
203 203
 				// Customer param wrong? The user may have been deleted on stripe's end. Remove customer_id. Can be retried without.
204
-				if ( $this->is_no_such_customer_error( $response->error ) ) {
205
-					delete_user_option( $order->get_customer_id(), '_stripe_customer_id' );
206
-					$order->delete_meta_data( '_stripe_customer_id' );
204
+				if ($this->is_no_such_customer_error($response->error)) {
205
+					delete_user_option($order->get_customer_id(), '_stripe_customer_id');
206
+					$order->delete_meta_data('_stripe_customer_id');
207 207
 					$order->save();
208 208
 				}
209 209
 
210
-				if ( $this->is_no_such_token_error( $response->error ) && $prepared_source->token_id ) {
210
+				if ($this->is_no_such_token_error($response->error) && $prepared_source->token_id) {
211 211
 					// Source param wrong? The CARD may have been deleted on stripe's end. Remove token and show message.
212
-					$wc_token = WC_Payment_Tokens::get( $prepared_source->token_id );
212
+					$wc_token = WC_Payment_Tokens::get($prepared_source->token_id);
213 213
 					$wc_token->delete();
214
-					$localized_message = __( 'This card is no longer available and has been removed.', 'woocommerce-gateway-stripe' );
215
-					$order->add_order_note( $localized_message );
216
-					throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message );
214
+					$localized_message = __('This card is no longer available and has been removed.', 'woocommerce-gateway-stripe');
215
+					$order->add_order_note($localized_message);
216
+					throw new WC_Stripe_Exception(print_r($response, true), $localized_message);
217 217
 				}
218 218
 
219 219
 				// We want to retry.
220
-				if ( $this->is_retryable_error( $response->error ) ) {
221
-					if ( $retry ) {
220
+				if ($this->is_retryable_error($response->error)) {
221
+					if ($retry) {
222 222
 						// Don't do anymore retries after this.
223
-						if ( 5 <= $this->retry_interval ) {
223
+						if (5 <= $this->retry_interval) {
224 224
 
225
-							return $this->process_webhook_payment( $notification, false );
225
+							return $this->process_webhook_payment($notification, false);
226 226
 						}
227 227
 
228
-						sleep( $this->retry_interval );
228
+						sleep($this->retry_interval);
229 229
 
230 230
 						$this->retry_interval++;
231
-						return $this->process_webhook_payment( $notification, true );
231
+						return $this->process_webhook_payment($notification, true);
232 232
 					} else {
233
-						$localized_message = __( 'Sorry, we are unable to process your payment at this time. Please retry later.', 'woocommerce-gateway-stripe' );
234
-						$order->add_order_note( $localized_message );
235
-						throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message );
233
+						$localized_message = __('Sorry, we are unable to process your payment at this time. Please retry later.', 'woocommerce-gateway-stripe');
234
+						$order->add_order_note($localized_message);
235
+						throw new WC_Stripe_Exception(print_r($response, true), $localized_message);
236 236
 					}
237 237
 				}
238 238
 
239 239
 				$localized_messages = WC_Stripe_Helper::get_localized_messages();
240 240
 
241
-				if ( 'card_error' === $response->error->type ) {
242
-					$localized_message = isset( $localized_messages[ $response->error->code ] ) ? $localized_messages[ $response->error->code ] : $response->error->message;
241
+				if ('card_error' === $response->error->type) {
242
+					$localized_message = isset($localized_messages[$response->error->code]) ? $localized_messages[$response->error->code] : $response->error->message;
243 243
 				} else {
244
-					$localized_message = isset( $localized_messages[ $response->error->type ] ) ? $localized_messages[ $response->error->type ] : $response->error->message;
244
+					$localized_message = isset($localized_messages[$response->error->type]) ? $localized_messages[$response->error->type] : $response->error->message;
245 245
 				}
246 246
 
247
-				$order->add_order_note( $localized_message );
247
+				$order->add_order_note($localized_message);
248 248
 
249
-				throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message );
249
+				throw new WC_Stripe_Exception(print_r($response, true), $localized_message);
250 250
 			}
251 251
 
252 252
 			// To prevent double processing the order on WC side.
253
-			if ( ! $this->is_original_request( $headers ) ) {
253
+			if ( ! $this->is_original_request($headers)) {
254 254
 				return;
255 255
 			}
256 256
 
257
-			do_action( 'wc_gateway_stripe_process_webhook_payment', $response, $order );
257
+			do_action('wc_gateway_stripe_process_webhook_payment', $response, $order);
258 258
 
259
-			$this->process_response( $response, $order );
259
+			$this->process_response($response, $order);
260 260
 
261
-		} catch ( WC_Stripe_Exception $e ) {
262
-			WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() );
261
+		} catch (WC_Stripe_Exception $e) {
262
+			WC_Stripe_Logger::log('Error: ' . $e->getMessage());
263 263
 
264
-			do_action( 'wc_gateway_stripe_process_webhook_payment_error', $order, $notification, $e );
264
+			do_action('wc_gateway_stripe_process_webhook_payment_error', $order, $notification, $e);
265 265
 
266
-			$statuses = array( 'pending', 'failed' );
266
+			$statuses = array('pending', 'failed');
267 267
 
268
-			if ( $order->has_status( $statuses ) ) {
269
-				$this->send_failed_order_email( $order_id );
268
+			if ($order->has_status($statuses)) {
269
+				$this->send_failed_order_email($order_id);
270 270
 			}
271 271
 		}
272 272
 	}
@@ -279,21 +279,21 @@  discard block
 block discarded – undo
279 279
 	 * @since 4.0.0
280 280
 	 * @param object $notification
281 281
 	 */
282
-	public function process_webhook_dispute( $notification ) {
283
-		$order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->charge );
282
+	public function process_webhook_dispute($notification) {
283
+		$order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->charge);
284 284
 
285
-		if ( ! $order ) {
286
-			WC_Stripe_Logger::log( 'Could not find order via charge ID: ' . $notification->data->object->charge );
285
+		if ( ! $order) {
286
+			WC_Stripe_Logger::log('Could not find order via charge ID: ' . $notification->data->object->charge);
287 287
 			return;
288 288
 		}
289 289
 
290 290
 		/* translators: 1) The URL to the order. */
291
-		$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 ) ) );
291
+		$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)));
292 292
 
293
-		do_action( 'wc_gateway_stripe_process_webhook_payment_error', $order, $notification );
293
+		do_action('wc_gateway_stripe_process_webhook_payment_error', $order, $notification);
294 294
 
295 295
 		$order_id = $order->get_id();
296
-		$this->send_failed_order_email( $order_id );
296
+		$this->send_failed_order_email($order_id);
297 297
 	}
298 298
 
299 299
 	/**
@@ -304,43 +304,43 @@  discard block
 block discarded – undo
304 304
 	 * @version 4.0.0
305 305
 	 * @param object $notification
306 306
 	 */
307
-	public function process_webhook_capture( $notification ) {
308
-		$order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->id );
307
+	public function process_webhook_capture($notification) {
308
+		$order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->id);
309 309
 
310
-		if ( ! $order ) {
311
-			WC_Stripe_Logger::log( 'Could not find order via charge ID: ' . $notification->data->object->id );
310
+		if ( ! $order) {
311
+			WC_Stripe_Logger::log('Could not find order via charge ID: ' . $notification->data->object->id);
312 312
 			return;
313 313
 		}
314 314
 
315
-		if ( 'stripe' === $order->get_payment_method() ) {
315
+		if ('stripe' === $order->get_payment_method()) {
316 316
 			$charge   = $order->get_transaction_id();
317
-			$captured = $order->get_meta( '_stripe_charge_captured', true );
317
+			$captured = $order->get_meta('_stripe_charge_captured', true);
318 318
 
319
-			if ( $charge && 'no' === $captured ) {
320
-				$order->update_meta_data( '_stripe_charge_captured', 'yes' );
319
+			if ($charge && 'no' === $captured) {
320
+				$order->update_meta_data('_stripe_charge_captured', 'yes');
321 321
 
322 322
 				// Store other data such as fees
323
-				$order->set_transaction_id( $notification->data->object->id );
323
+				$order->set_transaction_id($notification->data->object->id);
324 324
 
325
-				if ( isset( $notification->data->object->balance_transaction ) ) {
326
-					$this->update_fees( $order, $notification->data->object->balance_transaction );
325
+				if (isset($notification->data->object->balance_transaction)) {
326
+					$this->update_fees($order, $notification->data->object->balance_transaction);
327 327
 				}
328 328
 
329 329
 				// Check and see if capture is partial.
330
-				if ( $this->is_partial_capture( $notification ) ) {
331
-					$partial_amount = $this->get_partial_amount_to_charge( $notification );
332
-					$order->set_total( $partial_amount );
333
-					$this->update_fees( $order, $notification->data->object->refunds->data[0]->balance_transaction );
330
+				if ($this->is_partial_capture($notification)) {
331
+					$partial_amount = $this->get_partial_amount_to_charge($notification);
332
+					$order->set_total($partial_amount);
333
+					$this->update_fees($order, $notification->data->object->refunds->data[0]->balance_transaction);
334 334
 					/* translators: partial captured amount */
335
-					$order->add_order_note( sprintf( __( 'This charge was partially captured via Stripe Dashboard in the amount of: %s', 'woocommerce-gateway-stripe' ), $partial_amount ) );
335
+					$order->add_order_note(sprintf(__('This charge was partially captured via Stripe Dashboard in the amount of: %s', 'woocommerce-gateway-stripe'), $partial_amount));
336 336
 				} else {
337
-					$order->payment_complete( $notification->data->object->id );
337
+					$order->payment_complete($notification->data->object->id);
338 338
 
339 339
 					/* translators: transaction id */
340
-					$order->add_order_note( sprintf( __( 'Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe' ), $notification->data->object->id ) );
340
+					$order->add_order_note(sprintf(__('Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe'), $notification->data->object->id));
341 341
 				}
342 342
 
343
-				if ( is_callable( array( $order, 'save' ) ) ) {
343
+				if (is_callable(array($order, 'save'))) {
344 344
 					$order->save();
345 345
 				}
346 346
 			}
@@ -355,41 +355,41 @@  discard block
 block discarded – undo
355 355
 	 * @version 4.0.0
356 356
 	 * @param object $notification
357 357
 	 */
358
-	public function process_webhook_charge_succeeded( $notification ) {
358
+	public function process_webhook_charge_succeeded($notification) {
359 359
 		// Ignore the notification for charges, created through PaymentIntents.
360
-		if ( isset( $notification->data->object->payment_intent ) && $notification->data->object->payment_intent ) {
360
+		if (isset($notification->data->object->payment_intent) && $notification->data->object->payment_intent) {
361 361
 			return;
362 362
 		}
363 363
 
364 364
 		// The following payment methods are synchronous so does not need to be handle via webhook.
365
-		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 ) ) {
365
+		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)) {
366 366
 			return;
367 367
 		}
368 368
 
369
-		$order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->id );
369
+		$order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->id);
370 370
 
371
-		if ( ! $order ) {
372
-			WC_Stripe_Logger::log( 'Could not find order via charge ID: ' . $notification->data->object->id );
371
+		if ( ! $order) {
372
+			WC_Stripe_Logger::log('Could not find order via charge ID: ' . $notification->data->object->id);
373 373
 			return;
374 374
 		}
375 375
 
376
-		if ( ! $order->has_status( 'on-hold' ) ) {
376
+		if ( ! $order->has_status('on-hold')) {
377 377
 			return;
378 378
 		}
379 379
 
380 380
 		// Store other data such as fees
381
-		$order->set_transaction_id( $notification->data->object->id );
381
+		$order->set_transaction_id($notification->data->object->id);
382 382
 
383
-		if ( isset( $notification->data->object->balance_transaction ) ) {
384
-			$this->update_fees( $order, $notification->data->object->balance_transaction );
383
+		if (isset($notification->data->object->balance_transaction)) {
384
+			$this->update_fees($order, $notification->data->object->balance_transaction);
385 385
 		}
386 386
 
387
-		$order->payment_complete( $notification->data->object->id );
387
+		$order->payment_complete($notification->data->object->id);
388 388
 
389 389
 		/* translators: transaction id */
390
-		$order->add_order_note( sprintf( __( 'Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe' ), $notification->data->object->id ) );
390
+		$order->add_order_note(sprintf(__('Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe'), $notification->data->object->id));
391 391
 
392
-		if ( is_callable( array( $order, 'save' ) ) ) {
392
+		if (is_callable(array($order, 'save'))) {
393 393
 			$order->save();
394 394
 		}
395 395
 	}
@@ -401,22 +401,22 @@  discard block
 block discarded – undo
401 401
 	 * @since 4.1.5 Can handle any fail payments from any methods.
402 402
 	 * @param object $notification
403 403
 	 */
404
-	public function process_webhook_charge_failed( $notification ) {
405
-		$order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->id );
404
+	public function process_webhook_charge_failed($notification) {
405
+		$order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->id);
406 406
 
407
-		if ( ! $order ) {
408
-			WC_Stripe_Logger::log( 'Could not find order via charge ID: ' . $notification->data->object->id );
407
+		if ( ! $order) {
408
+			WC_Stripe_Logger::log('Could not find order via charge ID: ' . $notification->data->object->id);
409 409
 			return;
410 410
 		}
411 411
 
412 412
 		// If order status is already in failed status don't continue.
413
-		if ( $order->has_status( 'failed' ) ) {
413
+		if ($order->has_status('failed')) {
414 414
 			return;
415 415
 		}
416 416
 
417
-		$order->update_status( 'failed', __( 'This payment failed to clear.', 'woocommerce-gateway-stripe' ) );
417
+		$order->update_status('failed', __('This payment failed to clear.', 'woocommerce-gateway-stripe'));
418 418
 
419
-		do_action( 'wc_gateway_stripe_process_webhook_payment_error', $order, $notification );
419
+		do_action('wc_gateway_stripe_process_webhook_payment_error', $order, $notification);
420 420
 	}
421 421
 
422 422
 	/**
@@ -427,30 +427,30 @@  discard block
 block discarded – undo
427 427
 	 * @since 4.1.15 Add check to make sure order is processed by Stripe.
428 428
 	 * @param object $notification
429 429
 	 */
430
-	public function process_webhook_source_canceled( $notification ) {
431
-		$order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->id );
430
+	public function process_webhook_source_canceled($notification) {
431
+		$order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->id);
432 432
 
433 433
 		// If can't find order by charge ID, try source ID.
434
-		if ( ! $order ) {
435
-			$order = WC_Stripe_Helper::get_order_by_source_id( $notification->data->object->id );
434
+		if ( ! $order) {
435
+			$order = WC_Stripe_Helper::get_order_by_source_id($notification->data->object->id);
436 436
 
437
-			if ( ! $order ) {
438
-				WC_Stripe_Logger::log( 'Could not find order via charge/source ID: ' . $notification->data->object->id );
437
+			if ( ! $order) {
438
+				WC_Stripe_Logger::log('Could not find order via charge/source ID: ' . $notification->data->object->id);
439 439
 				return;
440 440
 			}
441 441
 		}
442 442
 
443 443
 		// Don't proceed if payment method isn't Stripe.
444
-		if ( 'stripe' !== $order->get_payment_method() ) {
445
-			WC_Stripe_Logger::log( 'Canceled webhook abort: Order was not processed by Stripe: ' . $order->get_id() );
444
+		if ('stripe' !== $order->get_payment_method()) {
445
+			WC_Stripe_Logger::log('Canceled webhook abort: Order was not processed by Stripe: ' . $order->get_id());
446 446
 			return;
447 447
 		}
448 448
 
449
-		if ( ! $order->has_status( 'cancelled' ) ) {
450
-			$order->update_status( 'cancelled', __( 'This payment has cancelled.', 'woocommerce-gateway-stripe' ) );
449
+		if ( ! $order->has_status('cancelled')) {
450
+			$order->update_status('cancelled', __('This payment has cancelled.', 'woocommerce-gateway-stripe'));
451 451
 		}
452 452
 
453
-		do_action( 'wc_gateway_stripe_process_webhook_payment_error', $order, $notification );
453
+		do_action('wc_gateway_stripe_process_webhook_payment_error', $order, $notification);
454 454
 	}
455 455
 
456 456
 	/**
@@ -460,59 +460,59 @@  discard block
 block discarded – undo
460 460
 	 * @version 4.0.0
461 461
 	 * @param object $notification
462 462
 	 */
463
-	public function process_webhook_refund( $notification ) {
464
-		$order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->id );
463
+	public function process_webhook_refund($notification) {
464
+		$order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->id);
465 465
 
466
-		if ( ! $order ) {
467
-			WC_Stripe_Logger::log( 'Could not find order via charge ID: ' . $notification->data->object->id );
466
+		if ( ! $order) {
467
+			WC_Stripe_Logger::log('Could not find order via charge ID: ' . $notification->data->object->id);
468 468
 			return;
469 469
 		}
470 470
 
471 471
 		$order_id = $order->get_id();
472 472
 
473
-		if ( 'stripe' === $order->get_payment_method() ) {
473
+		if ('stripe' === $order->get_payment_method()) {
474 474
 			$charge    = $order->get_transaction_id();
475
-			$captured  = $order->get_meta( '_stripe_charge_captured', true );
476
-			$refund_id = $order->get_meta( '_stripe_refund_id', true );
475
+			$captured  = $order->get_meta('_stripe_charge_captured', true);
476
+			$refund_id = $order->get_meta('_stripe_refund_id', true);
477 477
 
478 478
 			// If the refund ID matches, don't continue to prevent double refunding.
479
-			if ( $notification->data->object->refunds->data[0]->id === $refund_id ) {
479
+			if ($notification->data->object->refunds->data[0]->id === $refund_id) {
480 480
 				return;
481 481
 			}
482 482
 
483 483
 			// Only refund captured charge.
484
-			if ( $charge ) {
485
-				$reason = ( isset( $captured ) && 'yes' === $captured ) ? __( 'Refunded via Stripe Dashboard', 'woocommerce-gateway-stripe' ) : __( 'Pre-Authorization Released via Stripe Dashboard', 'woocommerce-gateway-stripe' );
484
+			if ($charge) {
485
+				$reason = (isset($captured) && 'yes' === $captured) ? __('Refunded via Stripe Dashboard', 'woocommerce-gateway-stripe') : __('Pre-Authorization Released via Stripe Dashboard', 'woocommerce-gateway-stripe');
486 486
 
487 487
 				// Create the refund.
488 488
 				$refund = wc_create_refund(
489 489
 					array(
490 490
 						'order_id' => $order_id,
491
-						'amount'   => $this->get_refund_amount( $notification ),
491
+						'amount'   => $this->get_refund_amount($notification),
492 492
 						'reason'   => $reason,
493 493
 					)
494 494
 				);
495 495
 
496
-				if ( is_wp_error( $refund ) ) {
497
-					WC_Stripe_Logger::log( $refund->get_error_message() );
496
+				if (is_wp_error($refund)) {
497
+					WC_Stripe_Logger::log($refund->get_error_message());
498 498
 				}
499 499
 
500
-				$order->update_meta_data( '_stripe_refund_id', $notification->data->object->refunds->data[0]->id );
500
+				$order->update_meta_data('_stripe_refund_id', $notification->data->object->refunds->data[0]->id);
501 501
 
502
-				$amount = wc_price( $notification->data->object->refunds->data[0]->amount / 100 );
502
+				$amount = wc_price($notification->data->object->refunds->data[0]->amount / 100);
503 503
 
504
-				if ( in_array( strtolower( $order->get_currency() ), WC_Stripe_Helper::no_decimal_currencies() ) ) {
505
-					$amount = wc_price( $notification->data->object->refunds->data[0]->amount );
504
+				if (in_array(strtolower($order->get_currency()), WC_Stripe_Helper::no_decimal_currencies())) {
505
+					$amount = wc_price($notification->data->object->refunds->data[0]->amount);
506 506
 				}
507 507
 
508
-				if ( isset( $notification->data->object->refunds->data[0]->balance_transaction ) ) {
509
-					$this->update_fees( $order, $notification->data->object->refunds->data[0]->balance_transaction );
508
+				if (isset($notification->data->object->refunds->data[0]->balance_transaction)) {
509
+					$this->update_fees($order, $notification->data->object->refunds->data[0]->balance_transaction);
510 510
 				}
511 511
 
512 512
 				/* translators: 1) dollar amount 2) transaction id 3) refund message */
513
-				$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' );
513
+				$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');
514 514
 
515
-				$order->add_order_note( $refund_message );
515
+				$order->add_order_note($refund_message);
516 516
 			}
517 517
 		}
518 518
 	}
@@ -523,30 +523,30 @@  discard block
 block discarded – undo
523 523
 	 * @since 4.0.6
524 524
 	 * @param object $notification
525 525
 	 */
526
-	public function process_review_opened( $notification ) {
527
-		if ( isset( $notification->data->object->payment_intent ) ) {
528
-			$order = WC_Stripe_Helper::get_order_by_intent_id( $notification->data->object->payment_intent );
526
+	public function process_review_opened($notification) {
527
+		if (isset($notification->data->object->payment_intent)) {
528
+			$order = WC_Stripe_Helper::get_order_by_intent_id($notification->data->object->payment_intent);
529 529
 
530
-			if ( ! $order ) {
531
-				WC_Stripe_Logger::log( '[Review Opened] Could not find order via intent ID: ' . $notification->data->object->payment_intent );
530
+			if ( ! $order) {
531
+				WC_Stripe_Logger::log('[Review Opened] Could not find order via intent ID: ' . $notification->data->object->payment_intent);
532 532
 				return;
533 533
 			}
534 534
 		} else {
535
-			$order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->charge );
535
+			$order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->charge);
536 536
 
537
-			if ( ! $order ) {
538
-				WC_Stripe_Logger::log( '[Review Opened] Could not find order via charge ID: ' . $notification->data->object->charge );
537
+			if ( ! $order) {
538
+				WC_Stripe_Logger::log('[Review Opened] Could not find order via charge ID: ' . $notification->data->object->charge);
539 539
 				return;
540 540
 			}
541 541
 		}
542 542
 
543 543
 		/* translators: 1) The URL to the order. 2) The reason type. */
544
-		$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 );
544
+		$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);
545 545
 
546
-		if ( apply_filters( 'wc_stripe_webhook_review_change_order_status', true, $order, $notification ) ) {
547
-			$order->update_status( 'on-hold', $message );
546
+		if (apply_filters('wc_stripe_webhook_review_change_order_status', true, $order, $notification)) {
547
+			$order->update_status('on-hold', $message);
548 548
 		} else {
549
-			$order->add_order_note( $message );
549
+			$order->add_order_note($message);
550 550
 		}
551 551
 	}
552 552
 
@@ -556,34 +556,34 @@  discard block
 block discarded – undo
556 556
 	 * @since 4.0.6
557 557
 	 * @param object $notification
558 558
 	 */
559
-	public function process_review_closed( $notification ) {
560
-		if ( isset( $notification->data->object->payment_intent ) ) {
561
-			$order = WC_Stripe_Helper::get_order_by_intent_id( $notification->data->object->payment_intent );
559
+	public function process_review_closed($notification) {
560
+		if (isset($notification->data->object->payment_intent)) {
561
+			$order = WC_Stripe_Helper::get_order_by_intent_id($notification->data->object->payment_intent);
562 562
 
563
-			if ( ! $order ) {
564
-				WC_Stripe_Logger::log( '[Review Closed] Could not find order via intent ID: ' . $notification->data->object->payment_intent );
563
+			if ( ! $order) {
564
+				WC_Stripe_Logger::log('[Review Closed] Could not find order via intent ID: ' . $notification->data->object->payment_intent);
565 565
 				return;
566 566
 			}
567 567
 		} else {
568
-			$order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->charge );
568
+			$order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->charge);
569 569
 
570
-			if ( ! $order ) {
571
-				WC_Stripe_Logger::log( '[Review Closed] Could not find order via charge ID: ' . $notification->data->object->charge );
570
+			if ( ! $order) {
571
+				WC_Stripe_Logger::log('[Review Closed] Could not find order via charge ID: ' . $notification->data->object->charge);
572 572
 				return;
573 573
 			}
574 574
 		}
575 575
 
576 576
 		/* translators: 1) The reason type. */
577
-		$message = sprintf( __( 'The opened review for this order is now closed. Reason: (%s)', 'woocommerce-gateway-stripe' ), $notification->data->object->reason );
577
+		$message = sprintf(__('The opened review for this order is now closed. Reason: (%s)', 'woocommerce-gateway-stripe'), $notification->data->object->reason);
578 578
 
579
-		if ( $order->has_status( 'on-hold' ) ) {
580
-			if ( apply_filters( 'wc_stripe_webhook_review_change_order_status', true, $order, $notification ) ) {
581
-				$order->update_status( 'processing', $message );
579
+		if ($order->has_status('on-hold')) {
580
+			if (apply_filters('wc_stripe_webhook_review_change_order_status', true, $order, $notification)) {
581
+				$order->update_status('processing', $message);
582 582
 			} else {
583
-				$order->add_order_note( $message );
583
+				$order->add_order_note($message);
584 584
 			}
585 585
 		} else {
586
-			$order->add_order_note( $message );
586
+			$order->add_order_note($message);
587 587
 		}
588 588
 	}
589 589
 
@@ -594,7 +594,7 @@  discard block
 block discarded – undo
594 594
 	 * @version 4.0.0
595 595
 	 * @param object $notification
596 596
 	 */
597
-	public function is_partial_capture( $notification ) {
597
+	public function is_partial_capture($notification) {
598 598
 		return 0 < $notification->data->object->amount_refunded;
599 599
 	}
600 600
 
@@ -605,11 +605,11 @@  discard block
 block discarded – undo
605 605
 	 * @version 4.0.0
606 606
 	 * @param object $notification
607 607
 	 */
608
-	public function get_refund_amount( $notification ) {
609
-		if ( $this->is_partial_capture( $notification ) ) {
608
+	public function get_refund_amount($notification) {
609
+		if ($this->is_partial_capture($notification)) {
610 610
 			$amount = $notification->data->object->refunds->data[0]->amount / 100;
611 611
 
612
-			if ( in_array( strtolower( $notification->data->object->currency ), WC_Stripe_Helper::no_decimal_currencies() ) ) {
612
+			if (in_array(strtolower($notification->data->object->currency), WC_Stripe_Helper::no_decimal_currencies())) {
613 613
 				$amount = $notification->data->object->refunds->data[0]->amount;
614 614
 			}
615 615
 
@@ -626,12 +626,12 @@  discard block
 block discarded – undo
626 626
 	 * @version 4.0.0
627 627
 	 * @param object $notification
628 628
 	 */
629
-	public function get_partial_amount_to_charge( $notification ) {
630
-		if ( $this->is_partial_capture( $notification ) ) {
631
-			$amount = ( $notification->data->object->amount - $notification->data->object->amount_refunded ) / 100;
629
+	public function get_partial_amount_to_charge($notification) {
630
+		if ($this->is_partial_capture($notification)) {
631
+			$amount = ($notification->data->object->amount - $notification->data->object->amount_refunded) / 100;
632 632
 
633
-			if ( in_array( strtolower( $notification->data->object->currency ), WC_Stripe_Helper::no_decimal_currencies() ) ) {
634
-				$amount = ( $notification->data->object->amount - $notification->data->object->amount_refunded );
633
+			if (in_array(strtolower($notification->data->object->currency), WC_Stripe_Helper::no_decimal_currencies())) {
634
+				$amount = ($notification->data->object->amount - $notification->data->object->amount_refunded);
635 635
 			}
636 636
 
637 637
 			return $amount;
@@ -640,69 +640,69 @@  discard block
 block discarded – undo
640 640
 		return false;
641 641
 	}
642 642
 
643
-	public function process_payment_intent_success( $notification ) {
643
+	public function process_payment_intent_success($notification) {
644 644
 		$intent = $notification->data->object;
645
-		$order = WC_Stripe_Helper::get_order_by_intent_id( $intent->id );
645
+		$order = WC_Stripe_Helper::get_order_by_intent_id($intent->id);
646 646
 
647
-		if ( ! $order ) {
648
-			WC_Stripe_Logger::log( 'Could not find order via intent ID: ' . $intent->id );
647
+		if ( ! $order) {
648
+			WC_Stripe_Logger::log('Could not find order via intent ID: ' . $intent->id);
649 649
 			return;
650 650
 		}
651 651
 
652
-		if ( ! $order->has_status( array( 'pending', 'failed' ) ) ) {
652
+		if ( ! $order->has_status(array('pending', 'failed'))) {
653 653
 			return;
654 654
 		}
655 655
 
656
-		if ( $this->lock_order_payment( $order, $intent ) ) {
656
+		if ($this->lock_order_payment($order, $intent)) {
657 657
 			return;
658 658
 		}
659 659
 
660 660
 		$order_id = $order->get_id();
661
-		if ( 'payment_intent.succeeded' === $notification->type || 'payment_intent.amount_capturable_updated' === $notification->type ) {
662
-			$charge = end( $intent->charges->data );
663
-			WC_Stripe_Logger::log( "Stripe PaymentIntent $intent->id succeeded for order $order_id" );
661
+		if ('payment_intent.succeeded' === $notification->type || 'payment_intent.amount_capturable_updated' === $notification->type) {
662
+			$charge = end($intent->charges->data);
663
+			WC_Stripe_Logger::log("Stripe PaymentIntent $intent->id succeeded for order $order_id");
664 664
 
665
-			do_action( 'wc_gateway_stripe_process_payment', $charge, $order );
665
+			do_action('wc_gateway_stripe_process_payment', $charge, $order);
666 666
 
667 667
 			// Process valid response.
668
-			$this->process_response( $charge, $order );
668
+			$this->process_response($charge, $order);
669 669
 
670 670
 		} else {
671 671
 			$error_message = $intent->last_payment_error ? $intent->last_payment_error->message : "";
672 672
 
673 673
 			/* translators: 1) The error message that was received from Stripe. */
674
-			$order->update_status( 'failed', sprintf( __( 'Stripe SCA authentication failed. Reason: %s', 'woocommerce-gateway-stripe' ), $error_message ) );
674
+			$order->update_status('failed', sprintf(__('Stripe SCA authentication failed. Reason: %s', 'woocommerce-gateway-stripe'), $error_message));
675 675
 
676
-			do_action( 'wc_gateway_stripe_process_webhook_payment_error', $order, $notification );
676
+			do_action('wc_gateway_stripe_process_webhook_payment_error', $order, $notification);
677 677
 
678
-			$this->send_failed_order_email( $order_id );
678
+			$this->send_failed_order_email($order_id);
679 679
 		}
680 680
 
681
-		$this->unlock_order_payment( $order );
681
+		$this->unlock_order_payment($order);
682 682
 	}
683 683
 
684
-	public function process_setup_intent( $notification ) {
684
+	public function process_setup_intent($notification) {
685 685
 		$intent = $notification->data->object;
686
-		$order = WC_Stripe_Helper::get_order_by_setup_intent_id( $intent->id );
686
+		$order = WC_Stripe_Helper::get_order_by_setup_intent_id($intent->id);
687 687
 
688
-		if ( ! $order ) {
689
-			WC_Stripe_Logger::log( 'Could not find order via setup intent ID: ' . $intent->id );
688
+		if ( ! $order) {
689
+			WC_Stripe_Logger::log('Could not find order via setup intent ID: ' . $intent->id);
690 690
 			return;
691 691
 		}
692 692
 
693
-		if ( ! $order->has_status( array( 'pending', 'failed' ) ) ) {
693
+		if ( ! $order->has_status(array('pending', 'failed'))) {
694 694
 			return;
695 695
 		}
696 696
 
697
-		if ( $this->lock_order_payment( $order, $intent ) ) {
697
+		if ($this->lock_order_payment($order, $intent)) {
698 698
 			return;
699 699
 		}
700 700
 
701 701
 		$order_id = $order->get_id();
702
-		if ( 'setup_intent.succeeded' === $notification->type ) {
703
-			WC_Stripe_Logger::log( "Stripe SetupIntent $intent->id succeeded for order $order_id" );
704
-			if ( WC_Stripe_Helper::is_pre_orders_exists() && WC_Pre_Orders_Order::order_contains_pre_order( $order ) ) {
705
-				WC_Pre_Orders_Order::mark_order_as_pre_ordered( $order );
702
+		if ('setup_intent.succeeded' === $notification->type) {
703
+			WC_Stripe_Logger::log("Stripe SetupIntent $intent->id succeeded for order $order_id");
704
+			if (WC_Stripe_Helper::is_pre_orders_exists() && WC_Pre_Orders_Order::order_contains_pre_order($order)) {
705
+				WC_Pre_Orders_Order::mark_order_as_pre_ordered($order);
706 706
 			} else {
707 707
 				$order->payment_complete();
708 708
 			}
@@ -710,12 +710,12 @@  discard block
 block discarded – undo
710 710
 			$error_message = $intent->last_setup_error ? $intent->last_setup_error->message : "";
711 711
 
712 712
 			/* translators: 1) The error message that was received from Stripe. */
713
-			$order->update_status( 'failed', sprintf( __( 'Stripe SCA authentication failed. Reason: %s', 'woocommerce-gateway-stripe' ), $error_message ) );
713
+			$order->update_status('failed', sprintf(__('Stripe SCA authentication failed. Reason: %s', 'woocommerce-gateway-stripe'), $error_message));
714 714
 
715
-			$this->send_failed_order_email( $order_id );
715
+			$this->send_failed_order_email($order_id);
716 716
 		}
717 717
 
718
-		$this->unlock_order_payment( $order );
718
+		$this->unlock_order_payment($order);
719 719
 	}
720 720
 
721 721
 	/**
@@ -725,55 +725,55 @@  discard block
 block discarded – undo
725 725
 	 * @version 4.0.0
726 726
 	 * @param string $request_body
727 727
 	 */
728
-	public function process_webhook( $request_body ) {
729
-		$notification = json_decode( $request_body );
728
+	public function process_webhook($request_body) {
729
+		$notification = json_decode($request_body);
730 730
 
731
-		switch ( $notification->type ) {
731
+		switch ($notification->type) {
732 732
 			case 'source.chargeable':
733
-				$this->process_webhook_payment( $notification );
733
+				$this->process_webhook_payment($notification);
734 734
 				break;
735 735
 
736 736
 			case 'source.canceled':
737
-				$this->process_webhook_source_canceled( $notification );
737
+				$this->process_webhook_source_canceled($notification);
738 738
 				break;
739 739
 
740 740
 			case 'charge.succeeded':
741
-				$this->process_webhook_charge_succeeded( $notification );
741
+				$this->process_webhook_charge_succeeded($notification);
742 742
 				break;
743 743
 
744 744
 			case 'charge.failed':
745
-				$this->process_webhook_charge_failed( $notification );
745
+				$this->process_webhook_charge_failed($notification);
746 746
 				break;
747 747
 
748 748
 			case 'charge.captured':
749
-				$this->process_webhook_capture( $notification );
749
+				$this->process_webhook_capture($notification);
750 750
 				break;
751 751
 
752 752
 			case 'charge.dispute.created':
753
-				$this->process_webhook_dispute( $notification );
753
+				$this->process_webhook_dispute($notification);
754 754
 				break;
755 755
 
756 756
 			case 'charge.refunded':
757
-				$this->process_webhook_refund( $notification );
757
+				$this->process_webhook_refund($notification);
758 758
 				break;
759 759
 
760 760
 			case 'review.opened':
761
-				$this->process_review_opened( $notification );
761
+				$this->process_review_opened($notification);
762 762
 				break;
763 763
 
764 764
 			case 'review.closed':
765
-				$this->process_review_closed( $notification );
765
+				$this->process_review_closed($notification);
766 766
 				break;
767 767
 
768 768
 			case 'payment_intent.succeeded':
769 769
 			case 'payment_intent.payment_failed':
770 770
 			case 'payment_intent.amount_capturable_updated':
771
-				$this->process_payment_intent_success( $notification );
771
+				$this->process_payment_intent_success($notification);
772 772
 				break;
773 773
 
774 774
 			case 'setup_intent.succeeded':
775 775
 			case 'setup_intent.setup_failed':
776
-				$this->process_setup_intent( $notification );
776
+				$this->process_setup_intent($notification);
777 777
 
778 778
 		}
779 779
 	}
Please login to merge, or discard this patch.
includes/class-wc-gateway-stripe.php 1 patch
Spacing   +323 added lines, -323 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) {
2
+if ( ! defined('ABSPATH')) {
3 3
 	exit;
4 4
 }
5 5
 
@@ -85,9 +85,9 @@  discard block
 block discarded – undo
85 85
 	public function __construct() {
86 86
 		$this->retry_interval = 1;
87 87
 		$this->id             = 'stripe';
88
-		$this->method_title   = __( 'Stripe', 'woocommerce-gateway-stripe' );
88
+		$this->method_title   = __('Stripe', 'woocommerce-gateway-stripe');
89 89
 		/* translators: 1) link to Stripe register page 2) link to Stripe api keys page */
90
-		$this->method_description = sprintf( __( 'Stripe works by adding payment fields on the checkout and then sending the details to Stripe for verification. <a href="%1$s" target="_blank">Sign up</a> for a Stripe account, and <a href="%2$s" target="_blank">get your Stripe account keys</a>.', 'woocommerce-gateway-stripe' ), 'https://dashboard.stripe.com/register', 'https://dashboard.stripe.com/account/apikeys' );
90
+		$this->method_description = sprintf(__('Stripe works by adding payment fields on the checkout and then sending the details to Stripe for verification. <a href="%1$s" target="_blank">Sign up</a> for a Stripe account, and <a href="%2$s" target="_blank">get your Stripe account keys</a>.', 'woocommerce-gateway-stripe'), 'https://dashboard.stripe.com/register', 'https://dashboard.stripe.com/account/apikeys');
91 91
 		$this->has_fields         = true;
92 92
 		$this->supports           = array(
93 93
 			'products',
@@ -114,40 +114,40 @@  discard block
 block discarded – undo
114 114
 		$this->init_settings();
115 115
 
116 116
 		// Get setting values.
117
-		$this->title                = $this->get_option( 'title' );
118
-		$this->description          = $this->get_option( 'description' );
119
-		$this->enabled              = $this->get_option( 'enabled' );
120
-		$this->testmode             = 'yes' === $this->get_option( 'testmode' );
121
-		$this->inline_cc_form       = 'yes' === $this->get_option( 'inline_cc_form' );
122
-		$this->capture              = 'yes' === $this->get_option( 'capture', 'yes' );
123
-		$this->statement_descriptor = WC_Stripe_Helper::clean_statement_descriptor( $this->get_option( 'statement_descriptor' ) );
124
-		$this->saved_cards          = 'yes' === $this->get_option( 'saved_cards' );
125
-		$this->secret_key           = $this->testmode ? $this->get_option( 'test_secret_key' ) : $this->get_option( 'secret_key' );
126
-		$this->publishable_key      = $this->testmode ? $this->get_option( 'test_publishable_key' ) : $this->get_option( 'publishable_key' );
127
-		$this->payment_request      = 'yes' === $this->get_option( 'payment_request', 'yes' );
128
-
129
-		WC_Stripe_API::set_secret_key( $this->secret_key );
117
+		$this->title                = $this->get_option('title');
118
+		$this->description          = $this->get_option('description');
119
+		$this->enabled              = $this->get_option('enabled');
120
+		$this->testmode             = 'yes' === $this->get_option('testmode');
121
+		$this->inline_cc_form       = 'yes' === $this->get_option('inline_cc_form');
122
+		$this->capture              = 'yes' === $this->get_option('capture', 'yes');
123
+		$this->statement_descriptor = WC_Stripe_Helper::clean_statement_descriptor($this->get_option('statement_descriptor'));
124
+		$this->saved_cards          = 'yes' === $this->get_option('saved_cards');
125
+		$this->secret_key           = $this->testmode ? $this->get_option('test_secret_key') : $this->get_option('secret_key');
126
+		$this->publishable_key      = $this->testmode ? $this->get_option('test_publishable_key') : $this->get_option('publishable_key');
127
+		$this->payment_request      = 'yes' === $this->get_option('payment_request', 'yes');
128
+
129
+		WC_Stripe_API::set_secret_key($this->secret_key);
130 130
 
131 131
 		// Hooks.
132
-		add_action( 'wp_enqueue_scripts', array( $this, 'payment_scripts' ) );
133
-		add_action( 'admin_enqueue_scripts', array( $this, 'admin_scripts' ) );
134
-		add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) );
135
-		add_action( 'woocommerce_admin_order_totals_after_total', array( $this, 'display_order_fee' ) );
136
-		add_action( 'woocommerce_admin_order_totals_after_total', array( $this, 'display_order_payout' ), 20 );
137
-		add_action( 'woocommerce_customer_save_address', array( $this, 'show_update_card_notice' ), 10, 2 );
138
-		add_filter( 'woocommerce_available_payment_gateways', array( $this, 'prepare_order_pay_page' ) );
139
-		add_action( 'woocommerce_account_view-order_endpoint', array( $this, 'check_intent_status_on_order_page' ), 1 );
140
-		add_filter( 'woocommerce_payment_successful_result', array( $this, 'modify_successful_payment_result' ), 99999, 2 );
141
-		add_action( 'set_logged_in_cookie', array( $this, 'set_cookie_on_current_request' ) );
142
-		add_filter( 'woocommerce_get_checkout_payment_url', array( $this, 'get_checkout_payment_url' ), 10, 2 );
132
+		add_action('wp_enqueue_scripts', array($this, 'payment_scripts'));
133
+		add_action('admin_enqueue_scripts', array($this, 'admin_scripts'));
134
+		add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options'));
135
+		add_action('woocommerce_admin_order_totals_after_total', array($this, 'display_order_fee'));
136
+		add_action('woocommerce_admin_order_totals_after_total', array($this, 'display_order_payout'), 20);
137
+		add_action('woocommerce_customer_save_address', array($this, 'show_update_card_notice'), 10, 2);
138
+		add_filter('woocommerce_available_payment_gateways', array($this, 'prepare_order_pay_page'));
139
+		add_action('woocommerce_account_view-order_endpoint', array($this, 'check_intent_status_on_order_page'), 1);
140
+		add_filter('woocommerce_payment_successful_result', array($this, 'modify_successful_payment_result'), 99999, 2);
141
+		add_action('set_logged_in_cookie', array($this, 'set_cookie_on_current_request'));
142
+		add_filter('woocommerce_get_checkout_payment_url', array($this, 'get_checkout_payment_url'), 10, 2);
143 143
 
144 144
 		// Note: display error is in the parent class.
145
-		add_action( 'admin_notices', array( $this, 'display_errors' ), 9999 );
145
+		add_action('admin_notices', array($this, 'display_errors'), 9999);
146 146
 
147
-		if ( WC_Stripe_Helper::is_pre_orders_exists() ) {
147
+		if (WC_Stripe_Helper::is_pre_orders_exists()) {
148 148
 			$this->pre_orders = new WC_Stripe_Pre_Orders_Compat();
149 149
 
150
-			add_action( 'wc_pre_orders_process_pre_order_completion_payment_' . $this->id, array( $this->pre_orders, 'process_pre_order_release_payment' ) );
150
+			add_action('wc_pre_orders_process_pre_order_completion_payment_' . $this->id, array($this->pre_orders, 'process_pre_order_release_payment'));
151 151
 		}
152 152
 	}
153 153
 
@@ -157,7 +157,7 @@  discard block
 block discarded – undo
157 157
 	 * @since 4.0.2
158 158
 	 */
159 159
 	public function is_available() {
160
-		if ( is_add_payment_method_page() && ! $this->saved_cards ) {
160
+		if (is_add_payment_method_page() && ! $this->saved_cards) {
161 161
 			return false;
162 162
 		}
163 163
 
@@ -171,13 +171,13 @@  discard block
 block discarded – undo
171 171
 	 * @param int    $user_id      The ID of the current user.
172 172
 	 * @param string $load_address The address to load.
173 173
 	 */
174
-	public function show_update_card_notice( $user_id, $load_address ) {
175
-		if ( ! $this->saved_cards || ! WC_Stripe_Payment_Tokens::customer_has_saved_methods( $user_id ) || 'billing' !== $load_address ) {
174
+	public function show_update_card_notice($user_id, $load_address) {
175
+		if ( ! $this->saved_cards || ! WC_Stripe_Payment_Tokens::customer_has_saved_methods($user_id) || 'billing' !== $load_address) {
176 176
 			return;
177 177
 		}
178 178
 
179 179
 		/* translators: 1) Opening anchor tag 2) closing anchor tag */
180
-		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' );
180
+		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');
181 181
 	}
182 182
 
183 183
 	/**
@@ -192,24 +192,24 @@  discard block
 block discarded – undo
192 192
 
193 193
 		$icons_str = '';
194 194
 
195
-		$icons_str .= isset( $icons['visa'] ) ? $icons['visa'] : '';
196
-		$icons_str .= isset( $icons['amex'] ) ? $icons['amex'] : '';
197
-		$icons_str .= isset( $icons['mastercard'] ) ? $icons['mastercard'] : '';
195
+		$icons_str .= isset($icons['visa']) ? $icons['visa'] : '';
196
+		$icons_str .= isset($icons['amex']) ? $icons['amex'] : '';
197
+		$icons_str .= isset($icons['mastercard']) ? $icons['mastercard'] : '';
198 198
 
199
-		if ( 'USD' === get_woocommerce_currency() ) {
200
-			$icons_str .= isset( $icons['discover'] ) ? $icons['discover'] : '';
201
-			$icons_str .= isset( $icons['jcb'] ) ? $icons['jcb'] : '';
202
-			$icons_str .= isset( $icons['diners'] ) ? $icons['diners'] : '';
199
+		if ('USD' === get_woocommerce_currency()) {
200
+			$icons_str .= isset($icons['discover']) ? $icons['discover'] : '';
201
+			$icons_str .= isset($icons['jcb']) ? $icons['jcb'] : '';
202
+			$icons_str .= isset($icons['diners']) ? $icons['diners'] : '';
203 203
 		}
204 204
 
205
-		return apply_filters( 'woocommerce_gateway_icon', $icons_str, $this->id );
205
+		return apply_filters('woocommerce_gateway_icon', $icons_str, $this->id);
206 206
 	}
207 207
 
208 208
 	/**
209 209
 	 * Initialise Gateway Settings Form Fields
210 210
 	 */
211 211
 	public function init_form_fields() {
212
-		$this->form_fields = require( dirname( __FILE__ ) . '/admin/stripe-settings.php' );
212
+		$this->form_fields = require(dirname(__FILE__) . '/admin/stripe-settings.php');
213 213
 	}
214 214
 
215 215
 	/**
@@ -218,27 +218,27 @@  discard block
 block discarded – undo
218 218
 	public function payment_fields() {
219 219
 		global $wp;
220 220
 		$user                 = wp_get_current_user();
221
-		$display_tokenization = $this->supports( 'tokenization' ) && is_checkout() && $this->saved_cards;
221
+		$display_tokenization = $this->supports('tokenization') && is_checkout() && $this->saved_cards;
222 222
 		$total                = WC()->cart->total;
223 223
 		$user_email           = '';
224 224
 		$description          = $this->get_description();
225
-		$description          = ! empty( $description ) ? $description : '';
225
+		$description          = ! empty($description) ? $description : '';
226 226
 		$firstname            = '';
227 227
 		$lastname             = '';
228 228
 
229 229
 		// If paying from order, we need to get total from order not cart.
230
-		if ( isset( $_GET['pay_for_order'] ) && ! empty( $_GET['key'] ) ) { // wpcs: csrf ok.
231
-			$order      = wc_get_order( wc_clean( $wp->query_vars['order-pay'] ) ); // wpcs: csrf ok, sanitization ok.
230
+		if (isset($_GET['pay_for_order']) && ! empty($_GET['key'])) { // wpcs: csrf ok.
231
+			$order      = wc_get_order(wc_clean($wp->query_vars['order-pay'])); // wpcs: csrf ok, sanitization ok.
232 232
 			$total      = $order->get_total();
233 233
 			$user_email = $order->get_billing_email();
234 234
 		} else {
235
-			if ( $user->ID ) {
236
-				$user_email = get_user_meta( $user->ID, 'billing_email', true );
235
+			if ($user->ID) {
236
+				$user_email = get_user_meta($user->ID, 'billing_email', true);
237 237
 				$user_email = $user_email ? $user_email : $user->user_email;
238 238
 			}
239 239
 		}
240 240
 
241
-		if ( is_add_payment_method_page() ) {
241
+		if (is_add_payment_method_page()) {
242 242
 			$firstname       = $user->user_firstname;
243 243
 			$lastname        = $user->user_lastname;
244 244
 		}
@@ -247,33 +247,33 @@  discard block
 block discarded – undo
247 247
 
248 248
 		echo '<div
249 249
 			id="stripe-payment-data"
250
-			data-email="' . esc_attr( $user_email ) . '"
251
-			data-full-name="' . esc_attr( $firstname . ' ' . $lastname ) . '"
252
-			data-currency="' . esc_attr( strtolower( get_woocommerce_currency() ) ) . '"
250
+			data-email="' . esc_attr($user_email) . '"
251
+			data-full-name="' . esc_attr($firstname . ' ' . $lastname) . '"
252
+			data-currency="' . esc_attr(strtolower(get_woocommerce_currency())) . '"
253 253
 		>';
254 254
 
255
-		if ( $this->testmode ) {
255
+		if ($this->testmode) {
256 256
 			/* translators: link to Stripe testing page */
257
-			$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' );
257
+			$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');
258 258
 		}
259 259
 
260
-		$description = trim( $description );
260
+		$description = trim($description);
261 261
 
262
-		echo apply_filters( 'wc_stripe_description', wpautop( wp_kses_post( $description ) ), $this->id ); // wpcs: xss ok.
262
+		echo apply_filters('wc_stripe_description', wpautop(wp_kses_post($description)), $this->id); // wpcs: xss ok.
263 263
 
264
-		if ( $display_tokenization ) {
264
+		if ($display_tokenization) {
265 265
 			$this->tokenization_script();
266 266
 			$this->saved_payment_methods();
267 267
 		}
268 268
 
269 269
 		$this->elements_form();
270 270
 
271
-		if ( apply_filters( 'wc_stripe_display_save_payment_method_checkbox', $display_tokenization ) && ! is_add_payment_method_page() && ! isset( $_GET['change_payment_method'] ) ) { // wpcs: csrf ok.
271
+		if (apply_filters('wc_stripe_display_save_payment_method_checkbox', $display_tokenization) && ! is_add_payment_method_page() && ! isset($_GET['change_payment_method'])) { // wpcs: csrf ok.
272 272
 
273 273
 			$this->save_payment_method_checkbox();
274 274
 		}
275 275
 
276
-		do_action( 'wc_stripe_cards_payment_fields', $this->id );
276
+		do_action('wc_stripe_cards_payment_fields', $this->id);
277 277
 
278 278
 		echo '</div>';
279 279
 
@@ -288,12 +288,12 @@  discard block
 block discarded – undo
288 288
 	 */
289 289
 	public function elements_form() {
290 290
 		?>
291
-		<fieldset id="wc-<?php echo esc_attr( $this->id ); ?>-cc-form" class="wc-credit-card-form wc-payment-form" style="background:transparent;">
292
-			<?php do_action( 'woocommerce_credit_card_form_start', $this->id ); ?>
291
+		<fieldset id="wc-<?php echo esc_attr($this->id); ?>-cc-form" class="wc-credit-card-form wc-payment-form" style="background:transparent;">
292
+			<?php do_action('woocommerce_credit_card_form_start', $this->id); ?>
293 293
 
294
-			<?php if ( $this->inline_cc_form ) { ?>
294
+			<?php if ($this->inline_cc_form) { ?>
295 295
 				<label for="card-element">
296
-					<?php esc_html_e( 'Credit or debit card', 'woocommerce-gateway-stripe' ); ?>
296
+					<?php esc_html_e('Credit or debit card', 'woocommerce-gateway-stripe'); ?>
297 297
 				</label>
298 298
 
299 299
 				<div id="stripe-card-element" class="wc-stripe-elements-field">
@@ -301,7 +301,7 @@  discard block
 block discarded – undo
301 301
 				</div>
302 302
 			<?php } else { ?>
303 303
 				<div class="form-row form-row-wide">
304
-					<label for="stripe-card-element"><?php esc_html_e( 'Card Number', 'woocommerce-gateway-stripe' ); ?> <span class="required">*</span></label>
304
+					<label for="stripe-card-element"><?php esc_html_e('Card Number', 'woocommerce-gateway-stripe'); ?> <span class="required">*</span></label>
305 305
 					<div class="stripe-card-group">
306 306
 						<div id="stripe-card-element" class="wc-stripe-elements-field">
307 307
 						<!-- a Stripe Element will be inserted here. -->
@@ -312,7 +312,7 @@  discard block
 block discarded – undo
312 312
 				</div>
313 313
 
314 314
 				<div class="form-row form-row-first">
315
-					<label for="stripe-exp-element"><?php esc_html_e( 'Expiry Date', 'woocommerce-gateway-stripe' ); ?> <span class="required">*</span></label>
315
+					<label for="stripe-exp-element"><?php esc_html_e('Expiry Date', 'woocommerce-gateway-stripe'); ?> <span class="required">*</span></label>
316 316
 
317 317
 					<div id="stripe-exp-element" class="wc-stripe-elements-field">
318 318
 					<!-- a Stripe Element will be inserted here. -->
@@ -320,7 +320,7 @@  discard block
 block discarded – undo
320 320
 				</div>
321 321
 
322 322
 				<div class="form-row form-row-last">
323
-					<label for="stripe-cvc-element"><?php esc_html_e( 'Card Code (CVC)', 'woocommerce-gateway-stripe' ); ?> <span class="required">*</span></label>
323
+					<label for="stripe-cvc-element"><?php esc_html_e('Card Code (CVC)', 'woocommerce-gateway-stripe'); ?> <span class="required">*</span></label>
324 324
 				<div id="stripe-cvc-element" class="wc-stripe-elements-field">
325 325
 				<!-- a Stripe Element will be inserted here. -->
326 326
 				</div>
@@ -331,7 +331,7 @@  discard block
 block discarded – undo
331 331
 			<!-- Used to display form errors -->
332 332
 			<div class="stripe-source-errors" role="alert"></div>
333 333
 			<br />
334
-			<?php do_action( 'woocommerce_credit_card_form_end', $this->id ); ?>
334
+			<?php do_action('woocommerce_credit_card_form_end', $this->id); ?>
335 335
 			<div class="clear"></div>
336 336
 		</fieldset>
337 337
 		<?php
@@ -344,24 +344,24 @@  discard block
 block discarded – undo
344 344
 	 * @version 3.1.0
345 345
 	 */
346 346
 	public function admin_scripts() {
347
-		if ( 'woocommerce_page_wc-settings' !== get_current_screen()->id ) {
347
+		if ('woocommerce_page_wc-settings' !== get_current_screen()->id) {
348 348
 			return;
349 349
 		}
350 350
 
351
-		$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
351
+		$suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';
352 352
 
353
-		wp_register_script( 'woocommerce_stripe_admin', plugins_url( 'assets/js/stripe-admin' . $suffix . '.js', WC_STRIPE_MAIN_FILE ), array(), WC_STRIPE_VERSION, true );
353
+		wp_register_script('woocommerce_stripe_admin', plugins_url('assets/js/stripe-admin' . $suffix . '.js', WC_STRIPE_MAIN_FILE), array(), WC_STRIPE_VERSION, true);
354 354
 
355 355
 		$params = array(
356 356
 			'time'             => time(),
357 357
 			'i18n_out_of_sync' => wp_kses(
358
-				__( '<strong>Warning:</strong> server time is out of sync with the time on your device. Webhook verification depends on the correct time, so please <strong>check your server time</strong> before setting a webhook secret.', 'woocommerce-gateway-stripe' ),
359
-				array( 'strong' => array() )
358
+				__('<strong>Warning:</strong> server time is out of sync with the time on your device. Webhook verification depends on the correct time, so please <strong>check your server time</strong> before setting a webhook secret.', 'woocommerce-gateway-stripe'),
359
+				array('strong' => array())
360 360
 			),
361 361
 		);
362
-		wp_localize_script( 'woocommerce_stripe_admin', 'wc_stripe_settings_params', $params );
362
+		wp_localize_script('woocommerce_stripe_admin', 'wc_stripe_settings_params', $params);
363 363
 
364
-		wp_enqueue_script( 'woocommerce_stripe_admin' );
364
+		wp_enqueue_script('woocommerce_stripe_admin');
365 365
 	}
366 366
 
367 367
 	/**
@@ -378,54 +378,54 @@  discard block
 block discarded – undo
378 378
 			! is_product()
379 379
 			&& ! is_cart()
380 380
 			&& ! is_checkout()
381
-			&& ! isset( $_GET['pay_for_order'] ) // wpcs: csrf ok.
381
+			&& ! isset($_GET['pay_for_order']) // wpcs: csrf ok.
382 382
 			&& ! is_add_payment_method_page()
383
-			&& ! isset( $_GET['change_payment_method'] ) // wpcs: csrf ok.
384
-			&& ! ( ! empty( get_query_var( 'view-subscription' ) ) && is_callable( 'WCS_Early_Renewal_Manager::is_early_renewal_via_modal_enabled' ) && WCS_Early_Renewal_Manager::is_early_renewal_via_modal_enabled() )
385
-			|| ( is_order_received_page() )
383
+			&& ! isset($_GET['change_payment_method']) // wpcs: csrf ok.
384
+			&& ! ( ! empty(get_query_var('view-subscription')) && is_callable('WCS_Early_Renewal_Manager::is_early_renewal_via_modal_enabled') && WCS_Early_Renewal_Manager::is_early_renewal_via_modal_enabled())
385
+			|| (is_order_received_page())
386 386
 		) {
387 387
 			return;
388 388
 		}
389 389
 
390 390
 		// If Stripe is not enabled bail.
391
-		if ( 'no' === $this->enabled ) {
391
+		if ('no' === $this->enabled) {
392 392
 			return;
393 393
 		}
394 394
 
395 395
 		// If keys are not set bail.
396
-		if ( ! $this->are_keys_set() ) {
397
-			WC_Stripe_Logger::log( 'Keys are not set correctly.' );
396
+		if ( ! $this->are_keys_set()) {
397
+			WC_Stripe_Logger::log('Keys are not set correctly.');
398 398
 			return;
399 399
 		}
400 400
 
401 401
 		// If no SSL bail.
402
-		if ( ! $this->testmode && ! is_ssl() ) {
403
-			WC_Stripe_Logger::log( 'Stripe live mode requires SSL.' );
402
+		if ( ! $this->testmode && ! is_ssl()) {
403
+			WC_Stripe_Logger::log('Stripe live mode requires SSL.');
404 404
 			return;
405 405
 		}
406 406
 
407 407
 		$current_theme = wp_get_theme();
408 408
 
409
-		$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
409
+		$suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';
410 410
 
411
-		wp_register_style( 'stripe_styles', plugins_url( 'assets/css/stripe-styles.css', WC_STRIPE_MAIN_FILE ), array(), WC_STRIPE_VERSION );
412
-		wp_enqueue_style( 'stripe_styles' );
411
+		wp_register_style('stripe_styles', plugins_url('assets/css/stripe-styles.css', WC_STRIPE_MAIN_FILE), array(), WC_STRIPE_VERSION);
412
+		wp_enqueue_style('stripe_styles');
413 413
 
414
-		wp_register_script( 'stripe', 'https://js.stripe.com/v3/', '', '3.0', true );
415
-		wp_register_script( 'woocommerce_stripe', plugins_url( 'assets/js/stripe' . $suffix . '.js', WC_STRIPE_MAIN_FILE ), array( 'jquery-payment', 'stripe' ), WC_STRIPE_VERSION, true );
414
+		wp_register_script('stripe', 'https://js.stripe.com/v3/', '', '3.0', true);
415
+		wp_register_script('woocommerce_stripe', plugins_url('assets/js/stripe' . $suffix . '.js', WC_STRIPE_MAIN_FILE), array('jquery-payment', 'stripe'), WC_STRIPE_VERSION, true);
416 416
 
417 417
 		$stripe_params = array(
418 418
 			'key'                  => $this->publishable_key,
419
-			'i18n_terms'           => __( 'Please accept the terms and conditions first', 'woocommerce-gateway-stripe' ),
420
-			'i18n_required_fields' => __( 'Please fill in required checkout fields first', 'woocommerce-gateway-stripe' ),
419
+			'i18n_terms'           => __('Please accept the terms and conditions first', 'woocommerce-gateway-stripe'),
420
+			'i18n_required_fields' => __('Please fill in required checkout fields first', 'woocommerce-gateway-stripe'),
421 421
 		);
422 422
 
423 423
 		// If we're on the pay page we need to pass stripe.js the address of the order.
424
-		if ( isset( $_GET['pay_for_order'] ) && 'true' === $_GET['pay_for_order'] ) { // wpcs: csrf ok.
425
-			$order_id = wc_clean( $wp->query_vars['order-pay'] ); // wpcs: csrf ok, sanitization ok, xss ok.
426
-			$order    = wc_get_order( $order_id );
424
+		if (isset($_GET['pay_for_order']) && 'true' === $_GET['pay_for_order']) { // wpcs: csrf ok.
425
+			$order_id = wc_clean($wp->query_vars['order-pay']); // wpcs: csrf ok, sanitization ok, xss ok.
426
+			$order    = wc_get_order($order_id);
427 427
 
428
-			if ( is_a( $order, 'WC_Order' ) ) {
428
+			if (is_a($order, 'WC_Order')) {
429 429
 				$stripe_params['billing_first_name'] = $order->get_billing_first_name();
430 430
 				$stripe_params['billing_last_name']  = $order->get_billing_last_name();
431 431
 				$stripe_params['billing_address_1']  = $order->get_billing_address_1();
@@ -440,40 +440,40 @@  discard block
 block discarded – undo
440 440
 		$sepa_elements_options = apply_filters(
441 441
 			'wc_stripe_sepa_elements_options',
442 442
 			array(
443
-				'supportedCountries' => array( 'SEPA' ),
443
+				'supportedCountries' => array('SEPA'),
444 444
 				'placeholderCountry' => WC()->countries->get_base_country(),
445
-				'style'              => array( 'base' => array( 'fontSize' => '15px' ) ),
445
+				'style'              => array('base' => array('fontSize' => '15px')),
446 446
 			)
447 447
 		);
448 448
 
449
-		$stripe_params['no_prepaid_card_msg']       = __( 'Sorry, we\'re not accepting prepaid cards at this time. Your credit card has not been charged. Please try with alternative payment method.', 'woocommerce-gateway-stripe' );
450
-		$stripe_params['no_sepa_owner_msg']         = __( 'Please enter your IBAN account name.', 'woocommerce-gateway-stripe' );
451
-		$stripe_params['no_sepa_iban_msg']          = __( 'Please enter your IBAN account number.', 'woocommerce-gateway-stripe' );
452
-		$stripe_params['payment_intent_error']      = __( 'We couldn\'t initiate the payment. Please try again.', 'woocommerce-gateway-stripe' );
453
-		$stripe_params['sepa_mandate_notification'] = apply_filters( 'wc_stripe_sepa_mandate_notification', 'email' );
454
-		$stripe_params['allow_prepaid_card']        = apply_filters( 'wc_stripe_allow_prepaid_card', true ) ? 'yes' : 'no';
449
+		$stripe_params['no_prepaid_card_msg']       = __('Sorry, we\'re not accepting prepaid cards at this time. Your credit card has not been charged. Please try with alternative payment method.', 'woocommerce-gateway-stripe');
450
+		$stripe_params['no_sepa_owner_msg']         = __('Please enter your IBAN account name.', 'woocommerce-gateway-stripe');
451
+		$stripe_params['no_sepa_iban_msg']          = __('Please enter your IBAN account number.', 'woocommerce-gateway-stripe');
452
+		$stripe_params['payment_intent_error']      = __('We couldn\'t initiate the payment. Please try again.', 'woocommerce-gateway-stripe');
453
+		$stripe_params['sepa_mandate_notification'] = apply_filters('wc_stripe_sepa_mandate_notification', 'email');
454
+		$stripe_params['allow_prepaid_card']        = apply_filters('wc_stripe_allow_prepaid_card', true) ? 'yes' : 'no';
455 455
 		$stripe_params['inline_cc_form']            = $this->inline_cc_form ? 'yes' : 'no';
456
-		$stripe_params['is_checkout']               = ( is_checkout() && empty( $_GET['pay_for_order'] ) ) ? 'yes' : 'no'; // wpcs: csrf ok.
456
+		$stripe_params['is_checkout']               = (is_checkout() && empty($_GET['pay_for_order'])) ? 'yes' : 'no'; // wpcs: csrf ok.
457 457
 		$stripe_params['return_url']                = $this->get_stripe_return_url();
458
-		$stripe_params['ajaxurl']                   = WC_AJAX::get_endpoint( '%%endpoint%%' );
459
-		$stripe_params['stripe_nonce']              = wp_create_nonce( '_wc_stripe_nonce' );
458
+		$stripe_params['ajaxurl']                   = WC_AJAX::get_endpoint('%%endpoint%%');
459
+		$stripe_params['stripe_nonce']              = wp_create_nonce('_wc_stripe_nonce');
460 460
 		$stripe_params['statement_descriptor']      = $this->statement_descriptor;
461
-		$stripe_params['elements_options']          = apply_filters( 'wc_stripe_elements_options', array() );
461
+		$stripe_params['elements_options']          = apply_filters('wc_stripe_elements_options', array());
462 462
 		$stripe_params['sepa_elements_options']     = $sepa_elements_options;
463
-		$stripe_params['invalid_owner_name']        = __( 'Billing First Name and Last Name are required.', 'woocommerce-gateway-stripe' );
464
-		$stripe_params['is_change_payment_page']    = isset( $_GET['change_payment_method'] ) ? 'yes' : 'no'; // wpcs: csrf ok.
465
-		$stripe_params['is_add_payment_page']       = is_wc_endpoint_url( 'add-payment-method' ) ? 'yes' : 'no';
466
-		$stripe_params['is_pay_for_order_page']     = is_wc_endpoint_url( 'order-pay' ) ? 'yes' : 'no';
467
-		$stripe_params['elements_styling']          = apply_filters( 'wc_stripe_elements_styling', false );
468
-		$stripe_params['elements_classes']          = apply_filters( 'wc_stripe_elements_classes', false );
463
+		$stripe_params['invalid_owner_name']        = __('Billing First Name and Last Name are required.', 'woocommerce-gateway-stripe');
464
+		$stripe_params['is_change_payment_page']    = isset($_GET['change_payment_method']) ? 'yes' : 'no'; // wpcs: csrf ok.
465
+		$stripe_params['is_add_payment_page']       = is_wc_endpoint_url('add-payment-method') ? 'yes' : 'no';
466
+		$stripe_params['is_pay_for_order_page']     = is_wc_endpoint_url('order-pay') ? 'yes' : 'no';
467
+		$stripe_params['elements_styling']          = apply_filters('wc_stripe_elements_styling', false);
468
+		$stripe_params['elements_classes']          = apply_filters('wc_stripe_elements_classes', false);
469 469
 
470 470
 		// Merge localized messages to be use in JS.
471
-		$stripe_params = array_merge( $stripe_params, WC_Stripe_Helper::get_localized_messages() );
471
+		$stripe_params = array_merge($stripe_params, WC_Stripe_Helper::get_localized_messages());
472 472
 
473
-		wp_localize_script( 'woocommerce_stripe', 'wc_stripe_params', apply_filters( 'wc_stripe_params', $stripe_params ) );
473
+		wp_localize_script('woocommerce_stripe', 'wc_stripe_params', apply_filters('wc_stripe_params', $stripe_params));
474 474
 
475 475
 		$this->tokenization_script();
476
-		wp_enqueue_script( 'woocommerce_stripe' );
476
+		wp_enqueue_script('woocommerce_stripe');
477 477
 	}
478 478
 
479 479
 	/**
@@ -484,14 +484,14 @@  discard block
 block discarded – undo
484 484
 	 * @param object $prepared_source The object with source details.
485 485
 	 * @throws WC_Stripe_Exception An exception if the card is prepaid, but prepaid cards are not allowed.
486 486
 	 */
487
-	public function maybe_disallow_prepaid_card( $prepared_source ) {
487
+	public function maybe_disallow_prepaid_card($prepared_source) {
488 488
 		// Check if we don't allow prepaid credit cards.
489
-		if ( apply_filters( 'wc_stripe_allow_prepaid_card', true ) || ! $this->is_prepaid_card( $prepared_source->source_object ) ) {
489
+		if (apply_filters('wc_stripe_allow_prepaid_card', true) || ! $this->is_prepaid_card($prepared_source->source_object)) {
490 490
 			return;
491 491
 		}
492 492
 
493
-		$localized_message = __( 'Sorry, we\'re not accepting prepaid cards at this time. Your credit card has not been charged. Please try with alternative payment method.', 'woocommerce-gateway-stripe' );
494
-		throw new WC_Stripe_Exception( print_r( $prepared_source->source_object, true ), $localized_message );
493
+		$localized_message = __('Sorry, we\'re not accepting prepaid cards at this time. Your credit card has not been charged. Please try with alternative payment method.', 'woocommerce-gateway-stripe');
494
+		throw new WC_Stripe_Exception(print_r($prepared_source->source_object, true), $localized_message);
495 495
 	}
496 496
 
497 497
 	/**
@@ -501,10 +501,10 @@  discard block
 block discarded – undo
501 501
 	 * @param  object $prepared_source The source that should be verified.
502 502
 	 * @throws WC_Stripe_Exception     An exception if the source ID is missing.
503 503
 	 */
504
-	public function check_source( $prepared_source ) {
505
-		if ( empty( $prepared_source->source ) ) {
506
-			$localized_message = __( 'Payment processing failed. Please retry.', 'woocommerce-gateway-stripe' );
507
-			throw new WC_Stripe_Exception( print_r( $prepared_source, true ), $localized_message );
504
+	public function check_source($prepared_source) {
505
+		if (empty($prepared_source->source)) {
506
+			$localized_message = __('Payment processing failed. Please retry.', 'woocommerce-gateway-stripe');
507
+			throw new WC_Stripe_Exception(print_r($prepared_source, true), $localized_message);
508 508
 		}
509 509
 	}
510 510
 
@@ -516,13 +516,13 @@  discard block
 block discarded – undo
516 516
 	 * @param WC_Order $order The order those payment is being processed.
517 517
 	 * @return bool           A flag that indicates that the customer does not exist and should be removed.
518 518
 	 */
519
-	public function maybe_remove_non_existent_customer( $error, $order ) {
520
-		if ( ! $this->is_no_such_customer_error( $error ) ) {
519
+	public function maybe_remove_non_existent_customer($error, $order) {
520
+		if ( ! $this->is_no_such_customer_error($error)) {
521 521
 			return false;
522 522
 		}
523 523
 
524
-		delete_user_option( $order->get_customer_id(), '_stripe_customer_id' );
525
-		$order->delete_meta_data( '_stripe_customer_id' );
524
+		delete_user_option($order->get_customer_id(), '_stripe_customer_id');
525
+		$order->delete_meta_data('_stripe_customer_id');
526 526
 		$order->save();
527 527
 
528 528
 		return true;
@@ -537,15 +537,15 @@  discard block
 block discarded – undo
537 537
 	 * @param boolean  $force_save_source Whether the payment source must be saved, like when dealing with a Subscription setup.
538 538
 	 * @return array                      Redirection data for `process_payment`.
539 539
 	 */
540
-	public function complete_free_order( $order, $prepared_source, $force_save_source ) {
541
-		if ( $force_save_source ) {
542
-			$intent_secret = $this->setup_intent( $order, $prepared_source );
540
+	public function complete_free_order($order, $prepared_source, $force_save_source) {
541
+		if ($force_save_source) {
542
+			$intent_secret = $this->setup_intent($order, $prepared_source);
543 543
 
544
-			if ( ! empty( $intent_secret ) ) {
544
+			if ( ! empty($intent_secret)) {
545 545
 				// `get_return_url()` must be called immediately before returning a value.
546 546
 				return array(
547 547
 					'result'              => 'success',
548
-					'redirect'            => $this->get_return_url( $order ),
548
+					'redirect'            => $this->get_return_url($order),
549 549
 					'setup_intent_secret' => $intent_secret,
550 550
 				);
551 551
 			}
@@ -559,7 +559,7 @@  discard block
 block discarded – undo
559 559
 		// Return thank you page redirect.
560 560
 		return array(
561 561
 			'result'   => 'success',
562
-			'redirect' => $this->get_return_url( $order ),
562
+			'redirect' => $this->get_return_url($order),
563 563
 		);
564 564
 	}
565 565
 
@@ -577,81 +577,81 @@  discard block
 block discarded – undo
577 577
 	 * @throws Exception If payment will not be accepted.
578 578
 	 * @return array|void
579 579
 	 */
580
-	public function process_payment( $order_id, $retry = true, $force_save_source = false, $previous_error = false, $use_order_source = false ) {
580
+	public function process_payment($order_id, $retry = true, $force_save_source = false, $previous_error = false, $use_order_source = false) {
581 581
 		try {
582
-			$order = wc_get_order( $order_id );
582
+			$order = wc_get_order($order_id);
583 583
 
584 584
 			// ToDo: `process_pre_order` saves the source to the order for a later payment.
585 585
 			// This might not work well with PaymentIntents.
586
-			if ( $this->maybe_process_pre_orders( $order_id ) ) {
587
-				return $this->pre_orders->process_pre_order( $order_id );
586
+			if ($this->maybe_process_pre_orders($order_id)) {
587
+				return $this->pre_orders->process_pre_order($order_id);
588 588
 			}
589 589
 
590 590
 			// Check whether there is an existing intent.
591
-			$intent = $this->get_intent_from_order( $order );
592
-			if ( isset( $intent->object ) && 'setup_intent' === $intent->object ) {
591
+			$intent = $this->get_intent_from_order($order);
592
+			if (isset($intent->object) && 'setup_intent' === $intent->object) {
593 593
 				$intent = false; // This function can only deal with *payment* intents
594 594
 			}
595 595
 
596 596
 			$stripe_customer_id = null;
597
-			if ( $intent && ! empty( $intent->customer ) ) {
597
+			if ($intent && ! empty($intent->customer)) {
598 598
 				$stripe_customer_id = $intent->customer;
599 599
 			}
600 600
 
601 601
 			// For some payments the source should already be present in the order.
602
-			if ( $use_order_source ) {
603
-				$prepared_source = $this->prepare_order_source( $order );
602
+			if ($use_order_source) {
603
+				$prepared_source = $this->prepare_order_source($order);
604 604
 			} else {
605
-				$prepared_source = $this->prepare_source( get_current_user_id(), $force_save_source, $stripe_customer_id );
605
+				$prepared_source = $this->prepare_source(get_current_user_id(), $force_save_source, $stripe_customer_id);
606 606
 			}
607 607
 
608
-			$this->maybe_disallow_prepaid_card( $prepared_source );
609
-			$this->check_source( $prepared_source );
610
-			$this->save_source_to_order( $order, $prepared_source );
608
+			$this->maybe_disallow_prepaid_card($prepared_source);
609
+			$this->check_source($prepared_source);
610
+			$this->save_source_to_order($order, $prepared_source);
611 611
 
612
-			if ( 0 >= $order->get_total() ) {
613
-				return $this->complete_free_order( $order, $prepared_source, $force_save_source );
612
+			if (0 >= $order->get_total()) {
613
+				return $this->complete_free_order($order, $prepared_source, $force_save_source);
614 614
 			}
615 615
 
616 616
 			// This will throw exception if not valid.
617
-			$this->validate_minimum_order_amount( $order );
617
+			$this->validate_minimum_order_amount($order);
618 618
 
619
-			WC_Stripe_Logger::log( "Info: Begin processing payment for order $order_id for the amount of {$order->get_total()}" );
619
+			WC_Stripe_Logger::log("Info: Begin processing payment for order $order_id for the amount of {$order->get_total()}");
620 620
 
621
-			if ( $intent ) {
622
-				$intent = $this->update_existing_intent( $intent, $order, $prepared_source );
621
+			if ($intent) {
622
+				$intent = $this->update_existing_intent($intent, $order, $prepared_source);
623 623
 			} else {
624
-				$intent = $this->create_intent( $order, $prepared_source );
624
+				$intent = $this->create_intent($order, $prepared_source);
625 625
 			}
626 626
 
627 627
 			// Confirm the intent after locking the order to make sure webhooks will not interfere.
628
-			if ( empty( $intent->error ) ) {
629
-				$this->lock_order_payment( $order, $intent );
630
-				$intent = $this->confirm_intent( $intent, $order, $prepared_source );
628
+			if (empty($intent->error)) {
629
+				$this->lock_order_payment($order, $intent);
630
+				$intent = $this->confirm_intent($intent, $order, $prepared_source);
631 631
 			}
632 632
 
633
-			if ( ! empty( $intent->error ) ) {
634
-				$this->maybe_remove_non_existent_customer( $intent->error, $order );
633
+			if ( ! empty($intent->error)) {
634
+				$this->maybe_remove_non_existent_customer($intent->error, $order);
635 635
 
636 636
 				// We want to retry.
637
-				if ( $this->is_retryable_error( $intent->error ) ) {
638
-					return $this->retry_after_error( $intent, $order, $retry, $force_save_source, $previous_error, $use_order_source );
637
+				if ($this->is_retryable_error($intent->error)) {
638
+					return $this->retry_after_error($intent, $order, $retry, $force_save_source, $previous_error, $use_order_source);
639 639
 				}
640 640
 
641
-				$this->unlock_order_payment( $order );
642
-				$this->throw_localized_message( $intent, $order );
641
+				$this->unlock_order_payment($order);
642
+				$this->throw_localized_message($intent, $order);
643 643
 			}
644 644
 
645
-			if ( ! empty( $intent ) ) {
645
+			if ( ! empty($intent)) {
646 646
 				// Use the last charge within the intent to proceed.
647
-				$response = end( $intent->charges->data );
647
+				$response = end($intent->charges->data);
648 648
 
649 649
 				// If the intent requires a 3DS flow, redirect to it.
650
-				if ( 'requires_action' === $intent->status ) {
651
-					$this->unlock_order_payment( $order );
650
+				if ('requires_action' === $intent->status) {
651
+					$this->unlock_order_payment($order);
652 652
 
653
-					if ( is_wc_endpoint_url( 'order-pay' ) ) {
654
-						$redirect_url = add_query_arg( 'wc-stripe-confirmation', 1, $order->get_checkout_payment_url( false ) );
653
+					if (is_wc_endpoint_url('order-pay')) {
654
+						$redirect_url = add_query_arg('wc-stripe-confirmation', 1, $order->get_checkout_payment_url(false));
655 655
 
656 656
 						return array(
657 657
 							'result'   => 'success',
@@ -666,7 +666,7 @@  discard block
 block discarded – undo
666 666
 
667 667
 						return array(
668 668
 							'result'                => 'success',
669
-							'redirect'              => $this->get_return_url( $order ),
669
+							'redirect'              => $this->get_return_url($order),
670 670
 							'payment_intent_secret' => $intent->client_secret,
671 671
 						);
672 672
 					}
@@ -674,30 +674,30 @@  discard block
 block discarded – undo
674 674
 			}
675 675
 
676 676
 			// Process valid response.
677
-			$this->process_response( $response, $order );
677
+			$this->process_response($response, $order);
678 678
 
679 679
 			// Remove cart.
680
-			if ( isset( WC()->cart ) ) {
680
+			if (isset(WC()->cart)) {
681 681
 				WC()->cart->empty_cart();
682 682
 			}
683 683
 
684 684
 			// Unlock the order.
685
-			$this->unlock_order_payment( $order );
685
+			$this->unlock_order_payment($order);
686 686
 
687 687
 			// Return thank you page redirect.
688 688
 			return array(
689 689
 				'result'   => 'success',
690
-				'redirect' => $this->get_return_url( $order ),
690
+				'redirect' => $this->get_return_url($order),
691 691
 			);
692 692
 
693
-		} catch ( WC_Stripe_Exception $e ) {
694
-			wc_add_notice( $e->getLocalizedMessage(), 'error' );
695
-			WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() );
693
+		} catch (WC_Stripe_Exception $e) {
694
+			wc_add_notice($e->getLocalizedMessage(), 'error');
695
+			WC_Stripe_Logger::log('Error: ' . $e->getMessage());
696 696
 
697
-			do_action( 'wc_gateway_stripe_process_payment_error', $e, $order );
697
+			do_action('wc_gateway_stripe_process_payment_error', $e, $order);
698 698
 
699 699
 			/* translators: error message */
700
-			$order->update_status( 'failed' );
700
+			$order->update_status('failed');
701 701
 
702 702
 			return array(
703 703
 				'result'   => 'fail',
@@ -713,17 +713,17 @@  discard block
 block discarded – undo
713 713
 	 *
714 714
 	 * @param int $order_id The ID of the order.
715 715
 	 */
716
-	public function display_order_fee( $order_id ) {
717
-		if ( apply_filters( 'wc_stripe_hide_display_order_fee', false, $order_id ) ) {
716
+	public function display_order_fee($order_id) {
717
+		if (apply_filters('wc_stripe_hide_display_order_fee', false, $order_id)) {
718 718
 			return;
719 719
 		}
720 720
 
721
-		$order = wc_get_order( $order_id );
721
+		$order = wc_get_order($order_id);
722 722
 
723
-		$fee      = WC_Stripe_Helper::get_stripe_fee( $order );
724
-		$currency = WC_Stripe_Helper::get_stripe_currency( $order );
723
+		$fee      = WC_Stripe_Helper::get_stripe_fee($order);
724
+		$currency = WC_Stripe_Helper::get_stripe_currency($order);
725 725
 
726
-		if ( ! $fee || ! $currency ) {
726
+		if ( ! $fee || ! $currency) {
727 727
 			return;
728 728
 		}
729 729
 
@@ -731,12 +731,12 @@  discard block
 block discarded – undo
731 731
 
732 732
 		<tr>
733 733
 			<td class="label stripe-fee">
734
-				<?php echo wc_help_tip( __( 'This represents the fee Stripe collects for the transaction.', 'woocommerce-gateway-stripe' ) ); // wpcs: xss ok. ?>
735
-				<?php esc_html_e( 'Stripe Fee:', 'woocommerce-gateway-stripe' ); ?>
734
+				<?php echo wc_help_tip(__('This represents the fee Stripe collects for the transaction.', 'woocommerce-gateway-stripe')); // wpcs: xss ok. ?>
735
+				<?php esc_html_e('Stripe Fee:', 'woocommerce-gateway-stripe'); ?>
736 736
 			</td>
737 737
 			<td width="1%"></td>
738 738
 			<td class="total">
739
-				-&nbsp;<?php echo wc_price( $fee, array( 'currency' => $currency ) ); // wpcs: xss ok. ?>
739
+				-&nbsp;<?php echo wc_price($fee, array('currency' => $currency)); // wpcs: xss ok. ?>
740 740
 			</td>
741 741
 		</tr>
742 742
 
@@ -750,17 +750,17 @@  discard block
 block discarded – undo
750 750
 	 *
751 751
 	 * @param int $order_id The ID of the order.
752 752
 	 */
753
-	public function display_order_payout( $order_id ) {
754
-		if ( apply_filters( 'wc_stripe_hide_display_order_payout', false, $order_id ) ) {
753
+	public function display_order_payout($order_id) {
754
+		if (apply_filters('wc_stripe_hide_display_order_payout', false, $order_id)) {
755 755
 			return;
756 756
 		}
757 757
 
758
-		$order = wc_get_order( $order_id );
758
+		$order = wc_get_order($order_id);
759 759
 
760
-		$net      = WC_Stripe_Helper::get_stripe_net( $order );
761
-		$currency = WC_Stripe_Helper::get_stripe_currency( $order );
760
+		$net      = WC_Stripe_Helper::get_stripe_net($order);
761
+		$currency = WC_Stripe_Helper::get_stripe_currency($order);
762 762
 
763
-		if ( ! $net || ! $currency ) {
763
+		if ( ! $net || ! $currency) {
764 764
 			return;
765 765
 		}
766 766
 
@@ -768,12 +768,12 @@  discard block
 block discarded – undo
768 768
 
769 769
 		<tr>
770 770
 			<td class="label stripe-payout">
771
-				<?php echo wc_help_tip( __( 'This represents the net total that will be credited to your Stripe bank account. This may be in the currency that is set in your Stripe account.', 'woocommerce-gateway-stripe' ) ); // wpcs: xss ok. ?>
772
-				<?php esc_html_e( 'Stripe Payout:', 'woocommerce-gateway-stripe' ); ?>
771
+				<?php echo wc_help_tip(__('This represents the net total that will be credited to your Stripe bank account. This may be in the currency that is set in your Stripe account.', 'woocommerce-gateway-stripe')); // wpcs: xss ok. ?>
772
+				<?php esc_html_e('Stripe Payout:', 'woocommerce-gateway-stripe'); ?>
773 773
 			</td>
774 774
 			<td width="1%"></td>
775 775
 			<td class="total">
776
-				<?php echo wc_price( $net, array( 'currency' => $currency ) ); // wpcs: xss ok. ?>
776
+				<?php echo wc_price($net, array('currency' => $currency)); // wpcs: xss ok. ?>
777 777
 			</td>
778 778
 		</tr>
779 779
 
@@ -789,13 +789,13 @@  discard block
 block discarded – undo
789 789
 	 *
790 790
 	 * @return string The localized error message.
791 791
 	 */
792
-	public function get_localized_error_message_from_response( $response ) {
792
+	public function get_localized_error_message_from_response($response) {
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 801
 		return $localized_message;
@@ -809,12 +809,12 @@  discard block
 block discarded – undo
809 809
 	 * @param  WC_Order $order     The order to add a note to.
810 810
 	 * @throws WC_Stripe_Exception An exception with the right message.
811 811
 	 */
812
-	public function throw_localized_message( $response, $order ) {
813
-		$localized_message = $this->get_localized_error_message_from_response( $response );
812
+	public function throw_localized_message($response, $order) {
813
+		$localized_message = $this->get_localized_error_message_from_response($response);
814 814
 
815
-		$order->add_order_note( $localized_message );
815
+		$order->add_order_note($localized_message);
816 816
 
817
-		throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message );
817
+		throw new WC_Stripe_Exception(print_r($response, true), $localized_message);
818 818
 	}
819 819
 
820 820
 	/**
@@ -830,22 +830,22 @@  discard block
 block discarded – undo
830 830
 	 * @throws WC_Stripe_Exception        If the payment is not accepted.
831 831
 	 * @return array|void
832 832
 	 */
833
-	public function retry_after_error( $response, $order, $retry, $force_save_source, $previous_error, $use_order_source ) {
834
-		if ( ! $retry ) {
835
-			$localized_message = __( 'Sorry, we are unable to process your payment at this time. Please retry later.', 'woocommerce-gateway-stripe' );
836
-			$order->add_order_note( $localized_message );
837
-			throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message ); // phpcs:ignore WordPress.PHP.DevelopmentFunctions.
833
+	public function retry_after_error($response, $order, $retry, $force_save_source, $previous_error, $use_order_source) {
834
+		if ( ! $retry) {
835
+			$localized_message = __('Sorry, we are unable to process your payment at this time. Please retry later.', 'woocommerce-gateway-stripe');
836
+			$order->add_order_note($localized_message);
837
+			throw new WC_Stripe_Exception(print_r($response, true), $localized_message); // phpcs:ignore WordPress.PHP.DevelopmentFunctions.
838 838
 		}
839 839
 
840 840
 		// Don't do anymore retries after this.
841
-		if ( 5 <= $this->retry_interval ) {
842
-			return $this->process_payment( $order->get_id(), false, $force_save_source, $response->error, $previous_error );
841
+		if (5 <= $this->retry_interval) {
842
+			return $this->process_payment($order->get_id(), false, $force_save_source, $response->error, $previous_error);
843 843
 		}
844 844
 
845
-		sleep( $this->retry_interval );
845
+		sleep($this->retry_interval);
846 846
 		$this->retry_interval++;
847 847
 
848
-		return $this->process_payment( $order->get_id(), true, $force_save_source, $response->error, $previous_error, $use_order_source );
848
+		return $this->process_payment($order->get_id(), true, $force_save_source, $response->error, $previous_error, $use_order_source);
849 849
 	}
850 850
 
851 851
 	/**
@@ -856,23 +856,23 @@  discard block
 block discarded – undo
856 856
 	 * @param WC_Payment_Gateway[] $gateways A list of all available gateways.
857 857
 	 * @return WC_Payment_Gateway[]          Either the same list or an empty one in the right conditions.
858 858
 	 */
859
-	public function prepare_order_pay_page( $gateways ) {
860
-		if ( ! is_wc_endpoint_url( 'order-pay' ) || ! isset( $_GET['wc-stripe-confirmation'] ) ) { // wpcs: csrf ok.
859
+	public function prepare_order_pay_page($gateways) {
860
+		if ( ! is_wc_endpoint_url('order-pay') || ! isset($_GET['wc-stripe-confirmation'])) { // wpcs: csrf ok.
861 861
 			return $gateways;
862 862
 		}
863 863
 
864 864
 		try {
865 865
 			$this->prepare_intent_for_order_pay_page();
866
-		} catch ( WC_Stripe_Exception $e ) {
866
+		} catch (WC_Stripe_Exception $e) {
867 867
 			// Just show the full order pay page if there was a problem preparing the Payment Intent
868 868
 			return $gateways;
869 869
 		}
870 870
 
871
-		add_filter( 'woocommerce_checkout_show_terms', '__return_false' );
872
-		add_filter( 'woocommerce_pay_order_button_html', '__return_false' );
873
-		add_filter( 'woocommerce_available_payment_gateways', '__return_empty_array' );
874
-		add_filter( 'woocommerce_no_available_payment_methods_message', array( $this, 'change_no_available_methods_message' ) );
875
-		add_action( 'woocommerce_pay_order_after_submit', array( $this, 'render_payment_intent_inputs' ) );
871
+		add_filter('woocommerce_checkout_show_terms', '__return_false');
872
+		add_filter('woocommerce_pay_order_button_html', '__return_false');
873
+		add_filter('woocommerce_available_payment_gateways', '__return_empty_array');
874
+		add_filter('woocommerce_no_available_payment_methods_message', array($this, 'change_no_available_methods_message'));
875
+		add_action('woocommerce_pay_order_after_submit', array($this, 'render_payment_intent_inputs'));
876 876
 
877 877
 		return array();
878 878
 	}
@@ -885,7 +885,7 @@  discard block
 block discarded – undo
885 885
 	 * @return string the new message.
886 886
 	 */
887 887
 	public function change_no_available_methods_message() {
888
-		return wpautop( __( "Almost there!\n\nYour order has already been created, the only thing that still needs to be done is for you to authorize the payment with your bank.", 'woocommerce-gateway-stripe' ) );
888
+		return wpautop(__("Almost there!\n\nYour order has already been created, the only thing that still needs to be done is for you to authorize the payment with your bank.", 'woocommerce-gateway-stripe'));
889 889
 	}
890 890
 
891 891
 	/**
@@ -896,19 +896,19 @@  discard block
 block discarded – undo
896 896
 	 * @throws WC_Stripe_Exception
897 897
 	 * @since 4.3
898 898
 	 */
899
-	public function prepare_intent_for_order_pay_page( $order = null ) {
900
-		if ( ! isset( $order ) || empty( $order ) ) {
901
-			$order = wc_get_order( absint( get_query_var( 'order-pay' ) ) );
899
+	public function prepare_intent_for_order_pay_page($order = null) {
900
+		if ( ! isset($order) || empty($order)) {
901
+			$order = wc_get_order(absint(get_query_var('order-pay')));
902 902
 		}
903
-		$intent = $this->get_intent_from_order( $order );
903
+		$intent = $this->get_intent_from_order($order);
904 904
 
905
-		if ( ! $intent ) {
906
-			throw new WC_Stripe_Exception( 'Payment Intent not found', __( 'Payment Intent not found for order #' . $order->get_id(), 'woocommerce-gateway-stripe' ) );
905
+		if ( ! $intent) {
906
+			throw new WC_Stripe_Exception('Payment Intent not found', __('Payment Intent not found for order #' . $order->get_id(), 'woocommerce-gateway-stripe'));
907 907
 		}
908 908
 
909
-		if ( 'requires_payment_method' === $intent->status && isset( $intent->last_payment_error )
910
-		     && 'authentication_required' === $intent->last_payment_error->code ) {
911
-			$level3_data = $this->get_level3_data_from_order( $order );
909
+		if ('requires_payment_method' === $intent->status && isset($intent->last_payment_error)
910
+		     && 'authentication_required' === $intent->last_payment_error->code) {
911
+			$level3_data = $this->get_level3_data_from_order($order);
912 912
 			$intent      = WC_Stripe_API::request_with_level3_data(
913 913
 				array(
914 914
 					'payment_method' => $intent->last_payment_error->source->id,
@@ -918,8 +918,8 @@  discard block
 block discarded – undo
918 918
 				$order
919 919
 			);
920 920
 
921
-			if ( isset( $intent->error ) ) {
922
-				throw new WC_Stripe_Exception( print_r( $intent, true ), $intent->error->message );
921
+			if (isset($intent->error)) {
922
+				throw new WC_Stripe_Exception(print_r($intent, true), $intent->error->message);
923 923
 			}
924 924
 		}
925 925
 
@@ -934,26 +934,26 @@  discard block
 block discarded – undo
934 934
 	 * @throws WC_Stripe_Exception
935 935
 	 * @since 4.2
936 936
 	 */
937
-	public function render_payment_intent_inputs( $order = null ) {
938
-		if ( ! isset( $order ) || empty( $order ) ) {
939
-			$order = wc_get_order( absint( get_query_var( 'order-pay' ) ) );
937
+	public function render_payment_intent_inputs($order = null) {
938
+		if ( ! isset($order) || empty($order)) {
939
+			$order = wc_get_order(absint(get_query_var('order-pay')));
940 940
 		}
941
-		if ( ! isset( $this->order_pay_intent ) ) {
942
-			$this->prepare_intent_for_order_pay_page( $order );
941
+		if ( ! isset($this->order_pay_intent)) {
942
+			$this->prepare_intent_for_order_pay_page($order);
943 943
 		}
944 944
 
945 945
 		$verification_url = add_query_arg(
946 946
 			array(
947 947
 				'order'            => $order->get_id(),
948
-				'nonce'            => wp_create_nonce( 'wc_stripe_confirm_pi' ),
949
-				'redirect_to'      => rawurlencode( $this->get_return_url( $order ) ),
948
+				'nonce'            => wp_create_nonce('wc_stripe_confirm_pi'),
949
+				'redirect_to'      => rawurlencode($this->get_return_url($order)),
950 950
 				'is_pay_for_order' => true,
951 951
 			),
952
-			WC_AJAX::get_endpoint( 'wc_stripe_verify_intent' )
952
+			WC_AJAX::get_endpoint('wc_stripe_verify_intent')
953 953
 		);
954 954
 
955
-		echo '<input type="hidden" id="stripe-intent-id" value="' . esc_attr( $this->order_pay_intent->client_secret ) . '" />';
956
-		echo '<input type="hidden" id="stripe-intent-return" value="' . esc_attr( $verification_url ) . '" />';
955
+		echo '<input type="hidden" id="stripe-intent-id" value="' . esc_attr($this->order_pay_intent->client_secret) . '" />';
956
+		echo '<input type="hidden" id="stripe-intent-return" value="' . esc_attr($verification_url) . '" />';
957 957
 	}
958 958
 
959 959
 	/**
@@ -963,11 +963,11 @@  discard block
 block discarded – undo
963 963
 	 * @param WC_Payment_Token $token Payment Token.
964 964
 	 * @return string                 Generated payment method HTML
965 965
 	 */
966
-	public function get_saved_payment_method_option_html( $token ) {
967
-		$html          = parent::get_saved_payment_method_option_html( $token );
966
+	public function get_saved_payment_method_option_html($token) {
967
+		$html          = parent::get_saved_payment_method_option_html($token);
968 968
 		$error_wrapper = '<div class="stripe-source-errors" role="alert"></div>';
969 969
 
970
-		return preg_replace( '~</(\w+)>\s*$~', "$error_wrapper</$1>", $html );
970
+		return preg_replace('~</(\w+)>\s*$~', "$error_wrapper</$1>", $html);
971 971
 	}
972 972
 
973 973
 	/**
@@ -977,18 +977,18 @@  discard block
 block discarded – undo
977 977
 	 * @since 4.2.0
978 978
 	 * @param int $order_id The ID that will be used for the thank you page.
979 979
 	 */
980
-	public function check_intent_status_on_order_page( $order_id ) {
981
-		if ( empty( $order_id ) || absint( $order_id ) <= 0 ) {
980
+	public function check_intent_status_on_order_page($order_id) {
981
+		if (empty($order_id) || absint($order_id) <= 0) {
982 982
 			return;
983 983
 		}
984 984
 
985
-		$order = wc_get_order( absint( $order_id ) );
985
+		$order = wc_get_order(absint($order_id));
986 986
 
987
-		if ( ! $order ) {
987
+		if ( ! $order) {
988 988
 			return;
989 989
 		}
990 990
 
991
-		$this->verify_intent_after_checkout( $order );
991
+		$this->verify_intent_after_checkout($order);
992 992
 	}
993 993
 
994 994
 	/**
@@ -1002,8 +1002,8 @@  discard block
 block discarded – undo
1002 1002
 	 * @param int   $order_id The ID of the order which is being paid for.
1003 1003
 	 * @return array
1004 1004
 	 */
1005
-	public function modify_successful_payment_result( $result, $order_id ) {
1006
-		if ( ! isset( $result['payment_intent_secret'] ) && ! isset( $result['setup_intent_secret'] ) ) {
1005
+	public function modify_successful_payment_result($result, $order_id) {
1006
+		if ( ! isset($result['payment_intent_secret']) && ! isset($result['setup_intent_secret'])) {
1007 1007
 			// Only redirects with intents need to be modified.
1008 1008
 			return $result;
1009 1009
 		}
@@ -1012,16 +1012,16 @@  discard block
 block discarded – undo
1012 1012
 		$verification_url = add_query_arg(
1013 1013
 			array(
1014 1014
 				'order'       => $order_id,
1015
-				'nonce'       => wp_create_nonce( 'wc_stripe_confirm_pi' ),
1016
-				'redirect_to' => rawurlencode( $result['redirect'] ),
1015
+				'nonce'       => wp_create_nonce('wc_stripe_confirm_pi'),
1016
+				'redirect_to' => rawurlencode($result['redirect']),
1017 1017
 			),
1018
-			WC_AJAX::get_endpoint( 'wc_stripe_verify_intent' )
1018
+			WC_AJAX::get_endpoint('wc_stripe_verify_intent')
1019 1019
 		);
1020 1020
 
1021
-		if ( isset( $result['payment_intent_secret'] ) ) {
1022
-			$redirect = sprintf( '#confirm-pi-%s:%s', $result['payment_intent_secret'], rawurlencode( $verification_url ) );
1023
-		} else if ( isset( $result['setup_intent_secret'] ) ) {
1024
-			$redirect = sprintf( '#confirm-si-%s:%s', $result['setup_intent_secret'], rawurlencode( $verification_url ) );
1021
+		if (isset($result['payment_intent_secret'])) {
1022
+			$redirect = sprintf('#confirm-pi-%s:%s', $result['payment_intent_secret'], rawurlencode($verification_url));
1023
+		} else if (isset($result['setup_intent_secret'])) {
1024
+			$redirect = sprintf('#confirm-si-%s:%s', $result['setup_intent_secret'], rawurlencode($verification_url));
1025 1025
 		}
1026 1026
 
1027 1027
 		return array(
@@ -1033,8 +1033,8 @@  discard block
 block discarded – undo
1033 1033
 	/**
1034 1034
 	 * Proceed with current request using new login session (to ensure consistent nonce).
1035 1035
 	 */
1036
-	public function set_cookie_on_current_request( $cookie ) {
1037
-		$_COOKIE[ LOGGED_IN_COOKIE ] = $cookie;
1036
+	public function set_cookie_on_current_request($cookie) {
1037
+		$_COOKIE[LOGGED_IN_COOKIE] = $cookie;
1038 1038
 	}
1039 1039
 
1040 1040
 	/**
@@ -1044,48 +1044,48 @@  discard block
 block discarded – undo
1044 1044
 	 * @since 4.2.0
1045 1045
 	 * @param WC_Order $order The order which is in a transitional state.
1046 1046
 	 */
1047
-	public function verify_intent_after_checkout( $order ) {
1047
+	public function verify_intent_after_checkout($order) {
1048 1048
 		$payment_method = $order->get_payment_method();
1049
-		if ( $payment_method !== $this->id ) {
1049
+		if ($payment_method !== $this->id) {
1050 1050
 			// If this is not the payment method, an intent would not be available.
1051 1051
 			return;
1052 1052
 		}
1053 1053
 
1054
-		$intent = $this->get_intent_from_order( $order );
1055
-		if ( ! $intent ) {
1054
+		$intent = $this->get_intent_from_order($order);
1055
+		if ( ! $intent) {
1056 1056
 			// No intent, redirect to the order received page for further actions.
1057 1057
 			return;
1058 1058
 		}
1059 1059
 
1060 1060
 		// A webhook might have modified or locked the order while the intent was retreived. This ensures we are reading the right status.
1061
-		clean_post_cache( $order->get_id() );
1062
-		$order = wc_get_order( $order->get_id() );
1061
+		clean_post_cache($order->get_id());
1062
+		$order = wc_get_order($order->get_id());
1063 1063
 
1064
-		if ( ! $order->has_status( array( 'pending', 'failed' ) ) ) {
1064
+		if ( ! $order->has_status(array('pending', 'failed'))) {
1065 1065
 			// If payment has already been completed, this function is redundant.
1066 1066
 			return;
1067 1067
 		}
1068 1068
 
1069
-		if ( $this->lock_order_payment( $order, $intent ) ) {
1069
+		if ($this->lock_order_payment($order, $intent)) {
1070 1070
 			return;
1071 1071
 		}
1072 1072
 
1073
-		if ( 'setup_intent' === $intent->object && 'succeeded' === $intent->status ) {
1073
+		if ('setup_intent' === $intent->object && 'succeeded' === $intent->status) {
1074 1074
 			WC()->cart->empty_cart();
1075
-			if ( WC_Stripe_Helper::is_pre_orders_exists() && WC_Pre_Orders_Order::order_contains_pre_order( $order ) ) {
1076
-				WC_Pre_Orders_Order::mark_order_as_pre_ordered( $order );
1075
+			if (WC_Stripe_Helper::is_pre_orders_exists() && WC_Pre_Orders_Order::order_contains_pre_order($order)) {
1076
+				WC_Pre_Orders_Order::mark_order_as_pre_ordered($order);
1077 1077
 			} else {
1078 1078
 				$order->payment_complete();
1079 1079
 			}
1080
-		} else if ( 'succeeded' === $intent->status || 'requires_capture' === $intent->status ) {
1080
+		} else if ('succeeded' === $intent->status || 'requires_capture' === $intent->status) {
1081 1081
 			// Proceed with the payment completion.
1082
-			$this->handle_intent_verification_success( $order, $intent );
1083
-		} else if ( 'requires_payment_method' === $intent->status ) {
1082
+			$this->handle_intent_verification_success($order, $intent);
1083
+		} else if ('requires_payment_method' === $intent->status) {
1084 1084
 			// `requires_payment_method` means that SCA got denied for the current payment method.
1085
-			$this->handle_intent_verification_failure( $order, $intent );
1085
+			$this->handle_intent_verification_failure($order, $intent);
1086 1086
 		}
1087 1087
 
1088
-		$this->unlock_order_payment( $order );
1088
+		$this->unlock_order_payment($order);
1089 1089
 	}
1090 1090
 
1091 1091
 	/**
@@ -1095,8 +1095,8 @@  discard block
 block discarded – undo
1095 1095
 	 * @param WC_Order $order The order whose verification succeeded.
1096 1096
 	 * @param stdClass $intent The Payment Intent object.
1097 1097
 	 */
1098
-	protected function handle_intent_verification_success( $order, $intent ) {
1099
-		$this->process_response( end( $intent->charges->data ), $order );
1098
+	protected function handle_intent_verification_success($order, $intent) {
1099
+		$this->process_response(end($intent->charges->data), $order);
1100 1100
 	}
1101 1101
 
1102 1102
 	/**
@@ -1106,8 +1106,8 @@  discard block
 block discarded – undo
1106 1106
 	 * @param WC_Order $order The order whose verification failed.
1107 1107
 	 * @param stdClass $intent The Payment Intent object.
1108 1108
 	 */
1109
-	protected function handle_intent_verification_failure( $order, $intent ) {
1110
-		$this->failed_sca_auth( $order, $intent );
1109
+	protected function handle_intent_verification_failure($order, $intent) {
1110
+		$this->failed_sca_auth($order, $intent);
1111 1111
 	}
1112 1112
 
1113 1113
 	/**
@@ -1117,18 +1117,18 @@  discard block
 block discarded – undo
1117 1117
 	 * @param WC_Order $order  The order which should be checked.
1118 1118
 	 * @param object   $intent The intent, associated with the order.
1119 1119
 	 */
1120
-	public function failed_sca_auth( $order, $intent ) {
1120
+	public function failed_sca_auth($order, $intent) {
1121 1121
 		// If the order has already failed, do not repeat the same message.
1122
-		if ( $order->has_status( 'failed' ) ) {
1122
+		if ($order->has_status('failed')) {
1123 1123
 			return;
1124 1124
 		}
1125 1125
 
1126 1126
 		// Load the right message and update the status.
1127
-		$status_message = isset( $intent->last_payment_error )
1127
+		$status_message = isset($intent->last_payment_error)
1128 1128
 			/* translators: 1) The error message that was received from Stripe. */
1129
-			? sprintf( __( 'Stripe SCA authentication failed. Reason: %s', 'woocommerce-gateway-stripe' ), $intent->last_payment_error->message )
1130
-			: __( 'Stripe SCA authentication failed.', 'woocommerce-gateway-stripe' );
1131
-		$order->update_status( 'failed', $status_message );
1129
+			? sprintf(__('Stripe SCA authentication failed. Reason: %s', 'woocommerce-gateway-stripe'), $intent->last_payment_error->message)
1130
+			: __('Stripe SCA authentication failed.', 'woocommerce-gateway-stripe');
1131
+		$order->update_status('failed', $status_message);
1132 1132
 	}
1133 1133
 
1134 1134
 	/**
@@ -1139,10 +1139,10 @@  discard block
 block discarded – undo
1139 1139
 	 *
1140 1140
 	 * @return string Checkout URL for the given order.
1141 1141
 	 */
1142
-	public function get_checkout_payment_url( $pay_url, $order ) {
1142
+	public function get_checkout_payment_url($pay_url, $order) {
1143 1143
 		global $wp;
1144
-		if ( isset( $_GET['wc-stripe-confirmation'] ) && isset( $wp->query_vars['order-pay'] ) && $wp->query_vars['order-pay'] == $order->get_id() ) {
1145
-			$pay_url = add_query_arg( 'wc-stripe-confirmation', 1, $pay_url );
1144
+		if (isset($_GET['wc-stripe-confirmation']) && isset($wp->query_vars['order-pay']) && $wp->query_vars['order-pay'] == $order->get_id()) {
1145
+			$pay_url = add_query_arg('wc-stripe-confirmation', 1, $pay_url);
1146 1146
 		}
1147 1147
 		return $pay_url;
1148 1148
 	}
@@ -1152,63 +1152,63 @@  discard block
 block discarded – undo
1152 1152
 	 */
1153 1153
 	public function process_admin_options() {
1154 1154
 		// Load all old values before the new settings get saved.
1155
-		$old_publishable_key      = $this->get_option( 'publishable_key' );
1156
-		$old_secret_key           = $this->get_option( 'secret_key' );
1157
-		$old_test_publishable_key = $this->get_option( 'test_publishable_key' );
1158
-		$old_test_secret_key      = $this->get_option( 'test_secret_key' );
1155
+		$old_publishable_key      = $this->get_option('publishable_key');
1156
+		$old_secret_key           = $this->get_option('secret_key');
1157
+		$old_test_publishable_key = $this->get_option('test_publishable_key');
1158
+		$old_test_secret_key      = $this->get_option('test_secret_key');
1159 1159
 
1160 1160
 		parent::process_admin_options();
1161 1161
 
1162 1162
 		// Load all old values after the new settings have been saved.
1163
-		$new_publishable_key      = $this->get_option( 'publishable_key' );
1164
-		$new_secret_key           = $this->get_option( 'secret_key' );
1165
-		$new_test_publishable_key = $this->get_option( 'test_publishable_key' );
1166
-		$new_test_secret_key      = $this->get_option( 'test_secret_key' );
1163
+		$new_publishable_key      = $this->get_option('publishable_key');
1164
+		$new_secret_key           = $this->get_option('secret_key');
1165
+		$new_test_publishable_key = $this->get_option('test_publishable_key');
1166
+		$new_test_secret_key      = $this->get_option('test_secret_key');
1167 1167
 
1168 1168
 		// Checks whether a value has transitioned from a non-empty value to a new one.
1169
-		$has_changed = function( $old_value, $new_value ) {
1170
-			return ! empty( $old_value ) && ( $old_value !== $new_value );
1169
+		$has_changed = function($old_value, $new_value) {
1170
+			return ! empty($old_value) && ($old_value !== $new_value);
1171 1171
 		};
1172 1172
 
1173 1173
 		// Look for updates.
1174 1174
 		if (
1175
-			$has_changed( $old_publishable_key, $new_publishable_key )
1176
-			|| $has_changed( $old_secret_key, $new_secret_key )
1177
-			|| $has_changed( $old_test_publishable_key, $new_test_publishable_key )
1178
-			|| $has_changed( $old_test_secret_key, $new_test_secret_key )
1175
+			$has_changed($old_publishable_key, $new_publishable_key)
1176
+			|| $has_changed($old_secret_key, $new_secret_key)
1177
+			|| $has_changed($old_test_publishable_key, $new_test_publishable_key)
1178
+			|| $has_changed($old_test_secret_key, $new_test_secret_key)
1179 1179
 		) {
1180
-			update_option( 'wc_stripe_show_changed_keys_notice', 'yes' );
1180
+			update_option('wc_stripe_show_changed_keys_notice', 'yes');
1181 1181
 		}
1182 1182
 	}
1183 1183
 
1184
-	public function validate_publishable_key_field( $key, $value ) {
1185
-		$value = $this->validate_text_field( $key, $value );
1186
-		if ( ! empty( $value ) && ! preg_match( '/^pk_live_/', $value ) ) {
1187
-			throw new Exception( __( 'The "Live Publishable Key" should start with "pk_live", enter the correct key.', 'woocommerce-gateway-stripe' ) );
1184
+	public function validate_publishable_key_field($key, $value) {
1185
+		$value = $this->validate_text_field($key, $value);
1186
+		if ( ! empty($value) && ! preg_match('/^pk_live_/', $value)) {
1187
+			throw new Exception(__('The "Live Publishable Key" should start with "pk_live", enter the correct key.', 'woocommerce-gateway-stripe'));
1188 1188
 		}
1189 1189
 		return $value;
1190 1190
 	}
1191 1191
 
1192
-	public function validate_secret_key_field( $key, $value ) {
1193
-		$value = $this->validate_text_field( $key, $value );
1194
-		if ( ! empty( $value ) && ! preg_match( '/^[rs]k_live_/', $value ) ) {
1195
-			throw new Exception( __( 'The "Live Secret Key" should start with "sk_live" or "rk_live", enter the correct key.', 'woocommerce-gateway-stripe' ) );
1192
+	public function validate_secret_key_field($key, $value) {
1193
+		$value = $this->validate_text_field($key, $value);
1194
+		if ( ! empty($value) && ! preg_match('/^[rs]k_live_/', $value)) {
1195
+			throw new Exception(__('The "Live Secret Key" should start with "sk_live" or "rk_live", enter the correct key.', 'woocommerce-gateway-stripe'));
1196 1196
 		}
1197 1197
 		return $value;
1198 1198
 	}
1199 1199
 
1200
-	public function validate_test_publishable_key_field( $key, $value ) {
1201
-		$value = $this->validate_text_field( $key, $value );
1202
-		if ( ! empty( $value ) && ! preg_match( '/^pk_test_/', $value ) ) {
1203
-			throw new Exception( __( 'The "Test Publishable Key" should start with "pk_test", enter the correct key.', 'woocommerce-gateway-stripe' ) );
1200
+	public function validate_test_publishable_key_field($key, $value) {
1201
+		$value = $this->validate_text_field($key, $value);
1202
+		if ( ! empty($value) && ! preg_match('/^pk_test_/', $value)) {
1203
+			throw new Exception(__('The "Test Publishable Key" should start with "pk_test", enter the correct key.', 'woocommerce-gateway-stripe'));
1204 1204
 		}
1205 1205
 		return $value;
1206 1206
 	}
1207 1207
 
1208
-	public function validate_test_secret_key_field( $key, $value ) {
1209
-		$value = $this->validate_text_field( $key, $value );
1210
-		if ( ! empty( $value ) && ! preg_match( '/^[rs]k_test_/', $value ) ) {
1211
-			throw new Exception( __( 'The "Test Secret Key" should start with "sk_test" or "rk_test", enter the correct key.', 'woocommerce-gateway-stripe' ) );
1208
+	public function validate_test_secret_key_field($key, $value) {
1209
+		$value = $this->validate_text_field($key, $value);
1210
+		if ( ! empty($value) && ! preg_match('/^[rs]k_test_/', $value)) {
1211
+			throw new Exception(__('The "Test Secret Key" should start with "sk_test" or "rk_test", enter the correct key.', 'woocommerce-gateway-stripe'));
1212 1212
 		}
1213 1213
 		return $value;
1214 1214
 	}
Please login to merge, or discard this patch.