Completed
Pull Request — master (#1268)
by
unknown
02:30
created
includes/class-wc-stripe-webhook-handler.php 2 patches
Indentation   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -62,8 +62,8 @@
 block discarded – undo
62 62
 	 */
63 63
 	public function check_for_webhook() {
64 64
 		if ( ( 'POST' !== $_SERVER['REQUEST_METHOD'] )
65
-		     || ! isset( $_GET['wc-api'] )
66
-		     || ( 'wc_stripe' !== $_GET['wc-api'] )
65
+			 || ! isset( $_GET['wc-api'] )
66
+			 || ( 'wc_stripe' !== $_GET['wc-api'] )
67 67
 		) {
68 68
 			return;
69 69
 		}
Please login to merge, or discard this patch.
Spacing   +229 added lines, -229 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
 
@@ -46,12 +46,12 @@  discard block
 block discarded – undo
46 46
 	 */
47 47
 	public function __construct() {
48 48
 		$this->retry_interval       = 2;
49
-		$this->stripe_settings     = get_option( 'woocommerce_stripe_settings', array() );
50
-		$this->testmode             = ( ! empty( $this->stripe_settings['testmode'] ) && 'yes' === $this->stripe_settings['testmode'] ) ? true : false;
51
-		$secret_key                 = ( $this->testmode ? 'test_' : '' ) . 'webhook_secret';
52
-		$this->secret               = ! empty( $this->stripe_settings[ $secret_key ] ) ? $this->stripe_settings[ $secret_key ] : false;
49
+		$this->stripe_settings = get_option('woocommerce_stripe_settings', array());
50
+		$this->testmode             = ( ! empty($this->stripe_settings['testmode']) && 'yes' === $this->stripe_settings['testmode']) ? true : false;
51
+		$secret_key                 = ($this->testmode ? 'test_' : '') . 'webhook_secret';
52
+		$this->secret               = ! empty($this->stripe_settings[$secret_key]) ? $this->stripe_settings[$secret_key] : false;
53 53
 
54
-		add_action( 'woocommerce_api_wc_stripe', array( $this, 'check_for_webhook' ) );
54
+		add_action('woocommerce_api_wc_stripe', array($this, 'check_for_webhook'));
55 55
 	}
56 56
 
57 57
 	/**
@@ -61,24 +61,24 @@  discard block
 block discarded – undo
61 61
 	 * @version 4.0.0
62 62
 	 */
63 63
 	public function check_for_webhook() {
64
-		if ( ( 'POST' !== $_SERVER['REQUEST_METHOD'] )
65
-		     || ! isset( $_GET['wc-api'] )
66
-		     || ( 'wc_stripe' !== $_GET['wc-api'] )
64
+		if (('POST' !== $_SERVER['REQUEST_METHOD'])
65
+		     || ! isset($_GET['wc-api'])
66
+		     || ('wc_stripe' !== $_GET['wc-api'])
67 67
 		) {
68 68
 			return;
69 69
 		}
70 70
 
71
-		$request_body    = file_get_contents( 'php://input' );
72
-		$request_headers = array_change_key_case( $this->get_request_headers(), CASE_UPPER );
71
+		$request_body    = file_get_contents('php://input');
72
+		$request_headers = array_change_key_case($this->get_request_headers(), CASE_UPPER);
73 73
 
74 74
 		// Validate it to make sure it is legit.
75
-		if ( $this->is_valid_request( $request_headers, $request_body ) ) {
76
-			$this->process_webhook( $request_body );
77
-			status_header( 200 );
75
+		if ($this->is_valid_request($request_headers, $request_body)) {
76
+			$this->process_webhook($request_body);
77
+			status_header(200);
78 78
 			exit;
79 79
 		} else {
80
-			WC_Stripe_Logger::log( 'Incoming webhook failed validation: ' . print_r( $request_body, true ) );
81
-			status_header( 400 );
80
+			WC_Stripe_Logger::log('Incoming webhook failed validation: ' . print_r($request_body, true));
81
+			status_header(400);
82 82
 			exit;
83 83
 		}
84 84
 	}
@@ -92,36 +92,36 @@  discard block
 block discarded – undo
92 92
 	 * @param string $request_body The request body from Stripe.
93 93
 	 * @return bool
94 94
 	 */
95
-	public function is_valid_request( $request_headers = null, $request_body = null ) {
96
-		if ( null === $request_headers || null === $request_body ) {
95
+	public function is_valid_request($request_headers = null, $request_body = null) {
96
+		if (null === $request_headers || null === $request_body) {
97 97
 			return false;
98 98
 		}
99 99
 
100
-		if( ! empty( $this->stripe_settings['cloudfront_user_agent'] ) ) {
101
-			if ( ! empty( $request_headers['USER-AGENT'] ) && ! preg_match( '/Stripe/', $request_headers['USER-AGENT'] ) ) {
100
+		if ( ! empty($this->stripe_settings['cloudfront_user_agent'])) {
101
+			if ( ! empty($request_headers['USER-AGENT']) && ! preg_match('/Stripe/', $request_headers['USER-AGENT'])) {
102 102
 				return FALSE;
103 103
 			}
104 104
 		}
105 105
 
106
-		if ( ! empty( $this->secret ) ) {
106
+		if ( ! empty($this->secret)) {
107 107
 			// Check for a valid signature.
108 108
 			$signature_format = '/^t=(?P<timestamp>\d+)(?P<signatures>(,v\d+=[a-z0-9]+){1,2})$/';
109
-			if ( empty( $request_headers['STRIPE-SIGNATURE'] ) || ! preg_match( $signature_format, $request_headers['STRIPE-SIGNATURE'], $matches ) ) {
109
+			if (empty($request_headers['STRIPE-SIGNATURE']) || ! preg_match($signature_format, $request_headers['STRIPE-SIGNATURE'], $matches)) {
110 110
 				return false;
111 111
 			}
112 112
 
113 113
 			// Verify the timestamp.
114
-			$timestamp = intval( $matches['timestamp'] );
115
-			if ( abs( $timestamp - time() ) > 5 * MINUTE_IN_SECONDS ) {
114
+			$timestamp = intval($matches['timestamp']);
115
+			if (abs($timestamp - time()) > 5 * MINUTE_IN_SECONDS) {
116 116
 				return;
117 117
 			}
118 118
 
119 119
 			// Generate the expected signature.
120 120
 			$signed_payload     = $timestamp . '.' . $request_body;
121
-			$expected_signature = hash_hmac( 'sha256', $signed_payload, $this->secret );
121
+			$expected_signature = hash_hmac('sha256', $signed_payload, $this->secret);
122 122
 
123 123
 			// Check if the expected signature is present.
124
-			if ( ! preg_match( '/,v\d+=' . preg_quote( $expected_signature, '/' ) . '/', $matches['signatures'] ) ) {
124
+			if ( ! preg_match('/,v\d+=' . preg_quote($expected_signature, '/') . '/', $matches['signatures'])) {
125 125
 				return false;
126 126
 			}
127 127
 		}
@@ -138,12 +138,12 @@  discard block
 block discarded – undo
138 138
 	 * @version 4.0.0
139 139
 	 */
140 140
 	public function get_request_headers() {
141
-		if ( ! function_exists( 'getallheaders' ) ) {
141
+		if ( ! function_exists('getallheaders')) {
142 142
 			$headers = array();
143 143
 
144
-			foreach ( $_SERVER as $name => $value ) {
145
-				if ( 'HTTP_' === substr( $name, 0, 5 ) ) {
146
-					$headers[ str_replace( ' ', '-', ucwords( strtolower( str_replace( '_', ' ', substr( $name, 5 ) ) ) ) ) ] = $value;
144
+			foreach ($_SERVER as $name => $value) {
145
+				if ('HTTP_' === substr($name, 0, 5)) {
146
+					$headers[str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', substr($name, 5)))))] = $value;
147 147
 				}
148 148
 			}
149 149
 
@@ -162,30 +162,30 @@  discard block
 block discarded – undo
162 162
 	 * @param object $notification
163 163
 	 * @param bool $retry
164 164
 	 */
165
-	public function process_webhook_payment( $notification, $retry = true ) {
165
+	public function process_webhook_payment($notification, $retry = true) {
166 166
 		// The following 3 payment methods are synchronous so does not need to be handle via webhook.
167
-		if ( 'card' === $notification->data->object->type || 'sepa_debit' === $notification->data->object->type || 'three_d_secure' === $notification->data->object->type ) {
167
+		if ('card' === $notification->data->object->type || 'sepa_debit' === $notification->data->object->type || 'three_d_secure' === $notification->data->object->type) {
168 168
 			return;
169 169
 		}
170 170
 
171
-		$order = WC_Stripe_Helper::get_order_by_source_id( $notification->data->object->id );
171
+		$order = WC_Stripe_Helper::get_order_by_source_id($notification->data->object->id);
172 172
 
173
-		if ( ! $order ) {
174
-			WC_Stripe_Logger::log( 'Could not find order via source ID: ' . $notification->data->object->id );
173
+		if ( ! $order) {
174
+			WC_Stripe_Logger::log('Could not find order via source ID: ' . $notification->data->object->id);
175 175
 			return;
176 176
 		}
177 177
 
178 178
 		$order_id  = $order->get_id();
179 179
 		$source_id = $notification->data->object->id;
180 180
 
181
-		$is_pending_receiver = ( 'receiver' === $notification->data->object->flow );
181
+		$is_pending_receiver = ('receiver' === $notification->data->object->flow);
182 182
 
183 183
 		try {
184
-			if ( $order->has_status( array( 'processing', 'completed' ) ) ) {
184
+			if ($order->has_status(array('processing', 'completed'))) {
185 185
 				return;
186 186
 			}
187 187
 
188
-			if ( $order->has_status( 'on-hold' ) && ! $is_pending_receiver ) {
188
+			if ($order->has_status('on-hold') && ! $is_pending_receiver) {
189 189
 				return;
190 190
 			}
191 191
 
@@ -193,89 +193,89 @@  discard block
 block discarded – undo
193 193
 			$response = null;
194 194
 
195 195
 			// This will throw exception if not valid.
196
-			$this->validate_minimum_order_amount( $order );
196
+			$this->validate_minimum_order_amount($order);
197 197
 
198
-			WC_Stripe_Logger::log( "Info: (Webhook) Begin processing payment for order $order_id for the amount of {$order->get_total()}" );
198
+			WC_Stripe_Logger::log("Info: (Webhook) Begin processing payment for order $order_id for the amount of {$order->get_total()}");
199 199
 
200 200
 			// Prep source object.
201 201
 			$source_object           = new stdClass();
202 202
 			$source_object->token_id = '';
203
-			$source_object->customer = $this->get_stripe_customer_id( $order );
203
+			$source_object->customer = $this->get_stripe_customer_id($order);
204 204
 			$source_object->source   = $source_id;
205 205
 
206 206
 			// Make the request.
207
-			$response = WC_Stripe_API::request( $this->generate_payment_request( $order, $source_object ), 'charges', 'POST', true );
207
+			$response = WC_Stripe_API::request($this->generate_payment_request($order, $source_object), 'charges', 'POST', true);
208 208
 			$headers  = $response['headers'];
209 209
 			$response = $response['body'];
210 210
 
211
-			if ( ! empty( $response->error ) ) {
211
+			if ( ! empty($response->error)) {
212 212
 				// Customer param wrong? The user may have been deleted on stripe's end. Remove customer_id. Can be retried without.
213
-				if ( $this->is_no_such_customer_error( $response->error ) ) {
214
-					delete_user_option( $order->get_customer_id(), '_stripe_customer_id' );
215
-					$order->delete_meta_data( '_stripe_customer_id' );
213
+				if ($this->is_no_such_customer_error($response->error)) {
214
+					delete_user_option($order->get_customer_id(), '_stripe_customer_id');
215
+					$order->delete_meta_data('_stripe_customer_id');
216 216
 					$order->save();
217 217
 				}
218 218
 
219
-				if ( $this->is_no_such_token_error( $response->error ) && $prepared_source->token_id ) {
219
+				if ($this->is_no_such_token_error($response->error) && $prepared_source->token_id) {
220 220
 					// Source param wrong? The CARD may have been deleted on stripe's end. Remove token and show message.
221
-					$wc_token = WC_Payment_Tokens::get( $prepared_source->token_id );
221
+					$wc_token = WC_Payment_Tokens::get($prepared_source->token_id);
222 222
 					$wc_token->delete();
223
-					$localized_message = __( 'This card is no longer available and has been removed.', 'woocommerce-gateway-stripe' );
224
-					$order->add_order_note( $localized_message );
225
-					throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message );
223
+					$localized_message = __('This card is no longer available and has been removed.', 'woocommerce-gateway-stripe');
224
+					$order->add_order_note($localized_message);
225
+					throw new WC_Stripe_Exception(print_r($response, true), $localized_message);
226 226
 				}
227 227
 
228 228
 				// We want to retry.
229
-				if ( $this->is_retryable_error( $response->error ) ) {
230
-					if ( $retry ) {
229
+				if ($this->is_retryable_error($response->error)) {
230
+					if ($retry) {
231 231
 						// Don't do anymore retries after this.
232
-						if ( 5 <= $this->retry_interval ) {
232
+						if (5 <= $this->retry_interval) {
233 233
 
234
-							return $this->process_webhook_payment( $notification, false );
234
+							return $this->process_webhook_payment($notification, false);
235 235
 						}
236 236
 
237
-						sleep( $this->retry_interval );
237
+						sleep($this->retry_interval);
238 238
 
239 239
 						$this->retry_interval++;
240
-						return $this->process_webhook_payment( $notification, true );
240
+						return $this->process_webhook_payment($notification, true);
241 241
 					} else {
242
-						$localized_message = __( 'Sorry, we are unable to process your payment at this time. Please retry later.', 'woocommerce-gateway-stripe' );
243
-						$order->add_order_note( $localized_message );
244
-						throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message );
242
+						$localized_message = __('Sorry, we are unable to process your payment at this time. Please retry later.', 'woocommerce-gateway-stripe');
243
+						$order->add_order_note($localized_message);
244
+						throw new WC_Stripe_Exception(print_r($response, true), $localized_message);
245 245
 					}
246 246
 				}
247 247
 
248 248
 				$localized_messages = WC_Stripe_Helper::get_localized_messages();
249 249
 
250
-				if ( 'card_error' === $response->error->type ) {
251
-					$localized_message = isset( $localized_messages[ $response->error->code ] ) ? $localized_messages[ $response->error->code ] : $response->error->message;
250
+				if ('card_error' === $response->error->type) {
251
+					$localized_message = isset($localized_messages[$response->error->code]) ? $localized_messages[$response->error->code] : $response->error->message;
252 252
 				} else {
253
-					$localized_message = isset( $localized_messages[ $response->error->type ] ) ? $localized_messages[ $response->error->type ] : $response->error->message;
253
+					$localized_message = isset($localized_messages[$response->error->type]) ? $localized_messages[$response->error->type] : $response->error->message;
254 254
 				}
255 255
 
256
-				$order->add_order_note( $localized_message );
256
+				$order->add_order_note($localized_message);
257 257
 
258
-				throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message );
258
+				throw new WC_Stripe_Exception(print_r($response, true), $localized_message);
259 259
 			}
260 260
 
261 261
 			// To prevent double processing the order on WC side.
262
-			if ( ! $this->is_original_request( $headers ) ) {
262
+			if ( ! $this->is_original_request($headers)) {
263 263
 				return;
264 264
 			}
265 265
 
266
-			do_action( 'wc_gateway_stripe_process_webhook_payment', $response, $order );
266
+			do_action('wc_gateway_stripe_process_webhook_payment', $response, $order);
267 267
 
268
-			$this->process_response( $response, $order );
268
+			$this->process_response($response, $order);
269 269
 
270
-		} catch ( WC_Stripe_Exception $e ) {
271
-			WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() );
270
+		} catch (WC_Stripe_Exception $e) {
271
+			WC_Stripe_Logger::log('Error: ' . $e->getMessage());
272 272
 
273
-			do_action( 'wc_gateway_stripe_process_webhook_payment_error', $order, $notification, $e );
273
+			do_action('wc_gateway_stripe_process_webhook_payment_error', $order, $notification, $e);
274 274
 
275
-			$statuses = array( 'pending', 'failed' );
275
+			$statuses = array('pending', 'failed');
276 276
 
277
-			if ( $order->has_status( $statuses ) ) {
278
-				$this->send_failed_order_email( $order_id );
277
+			if ($order->has_status($statuses)) {
278
+				$this->send_failed_order_email($order_id);
279 279
 			}
280 280
 		}
281 281
 	}
@@ -288,21 +288,21 @@  discard block
 block discarded – undo
288 288
 	 * @since 4.0.0
289 289
 	 * @param object $notification
290 290
 	 */
291
-	public function process_webhook_dispute( $notification ) {
292
-		$order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->charge );
291
+	public function process_webhook_dispute($notification) {
292
+		$order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->charge);
293 293
 
294
-		if ( ! $order ) {
295
-			WC_Stripe_Logger::log( 'Could not find order via charge ID: ' . $notification->data->object->charge );
294
+		if ( ! $order) {
295
+			WC_Stripe_Logger::log('Could not find order via charge ID: ' . $notification->data->object->charge);
296 296
 			return;
297 297
 		}
298 298
 
299 299
 		/* translators: 1) The URL to the order. */
300
-		$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 ) ) );
300
+		$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)));
301 301
 
302
-		do_action( 'wc_gateway_stripe_process_webhook_payment_error', $order, $notification );
302
+		do_action('wc_gateway_stripe_process_webhook_payment_error', $order, $notification);
303 303
 
304 304
 		$order_id = $order->get_id();
305
-		$this->send_failed_order_email( $order_id );
305
+		$this->send_failed_order_email($order_id);
306 306
 	}
307 307
 
308 308
 	/**
@@ -313,43 +313,43 @@  discard block
 block discarded – undo
313 313
 	 * @version 4.0.0
314 314
 	 * @param object $notification
315 315
 	 */
316
-	public function process_webhook_capture( $notification ) {
317
-		$order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->id );
316
+	public function process_webhook_capture($notification) {
317
+		$order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->id);
318 318
 
319
-		if ( ! $order ) {
320
-			WC_Stripe_Logger::log( 'Could not find order via charge ID: ' . $notification->data->object->id );
319
+		if ( ! $order) {
320
+			WC_Stripe_Logger::log('Could not find order via charge ID: ' . $notification->data->object->id);
321 321
 			return;
322 322
 		}
323 323
 
324
-		if ( 'stripe' === $order->get_payment_method() ) {
324
+		if ('stripe' === $order->get_payment_method()) {
325 325
 			$charge   = $order->get_transaction_id();
326
-			$captured = $order->get_meta( '_stripe_charge_captured', true );
326
+			$captured = $order->get_meta('_stripe_charge_captured', true);
327 327
 
328
-			if ( $charge && 'no' === $captured ) {
329
-				$order->update_meta_data( '_stripe_charge_captured', 'yes' );
328
+			if ($charge && 'no' === $captured) {
329
+				$order->update_meta_data('_stripe_charge_captured', 'yes');
330 330
 
331 331
 				// Store other data such as fees
332
-				$order->set_transaction_id( $notification->data->object->id );
332
+				$order->set_transaction_id($notification->data->object->id);
333 333
 
334
-				if ( isset( $notification->data->object->balance_transaction ) ) {
335
-					$this->update_fees( $order, $notification->data->object->balance_transaction );
334
+				if (isset($notification->data->object->balance_transaction)) {
335
+					$this->update_fees($order, $notification->data->object->balance_transaction);
336 336
 				}
337 337
 
338 338
 				// Check and see if capture is partial.
339
-				if ( $this->is_partial_capture( $notification ) ) {
340
-					$partial_amount = $this->get_partial_amount_to_charge( $notification );
341
-					$order->set_total( $partial_amount );
342
-					$this->update_fees( $order, $notification->data->object->refunds->data[0]->balance_transaction );
339
+				if ($this->is_partial_capture($notification)) {
340
+					$partial_amount = $this->get_partial_amount_to_charge($notification);
341
+					$order->set_total($partial_amount);
342
+					$this->update_fees($order, $notification->data->object->refunds->data[0]->balance_transaction);
343 343
 					/* translators: partial captured amount */
344
-					$order->add_order_note( sprintf( __( 'This charge was partially captured via Stripe Dashboard in the amount of: %s', 'woocommerce-gateway-stripe' ), $partial_amount ) );
344
+					$order->add_order_note(sprintf(__('This charge was partially captured via Stripe Dashboard in the amount of: %s', 'woocommerce-gateway-stripe'), $partial_amount));
345 345
 				} else {
346
-					$order->payment_complete( $notification->data->object->id );
346
+					$order->payment_complete($notification->data->object->id);
347 347
 
348 348
 					/* translators: transaction id */
349
-					$order->add_order_note( sprintf( __( 'Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe' ), $notification->data->object->id ) );
349
+					$order->add_order_note(sprintf(__('Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe'), $notification->data->object->id));
350 350
 				}
351 351
 
352
-				if ( is_callable( array( $order, 'save' ) ) ) {
352
+				if (is_callable(array($order, 'save'))) {
353 353
 					$order->save();
354 354
 				}
355 355
 			}
@@ -364,41 +364,41 @@  discard block
 block discarded – undo
364 364
 	 * @version 4.0.0
365 365
 	 * @param object $notification
366 366
 	 */
367
-	public function process_webhook_charge_succeeded( $notification ) {
367
+	public function process_webhook_charge_succeeded($notification) {
368 368
 		// Ignore the notification for charges, created through PaymentIntents.
369
-		if ( isset( $notification->data->object->payment_intent ) && $notification->data->object->payment_intent ) {
369
+		if (isset($notification->data->object->payment_intent) && $notification->data->object->payment_intent) {
370 370
 			return;
371 371
 		}
372 372
 
373 373
 		// The following payment methods are synchronous so does not need to be handle via webhook.
374
-		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 ) ) {
374
+		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)) {
375 375
 			return;
376 376
 		}
377 377
 
378
-		$order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->id );
378
+		$order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->id);
379 379
 
380
-		if ( ! $order ) {
381
-			WC_Stripe_Logger::log( 'Could not find order via charge ID: ' . $notification->data->object->id );
380
+		if ( ! $order) {
381
+			WC_Stripe_Logger::log('Could not find order via charge ID: ' . $notification->data->object->id);
382 382
 			return;
383 383
 		}
384 384
 
385
-		if ( ! $order->has_status( 'on-hold' ) ) {
385
+		if ( ! $order->has_status('on-hold')) {
386 386
 			return;
387 387
 		}
388 388
 
389 389
 		// Store other data such as fees
390
-		$order->set_transaction_id( $notification->data->object->id );
390
+		$order->set_transaction_id($notification->data->object->id);
391 391
 
392
-		if ( isset( $notification->data->object->balance_transaction ) ) {
393
-			$this->update_fees( $order, $notification->data->object->balance_transaction );
392
+		if (isset($notification->data->object->balance_transaction)) {
393
+			$this->update_fees($order, $notification->data->object->balance_transaction);
394 394
 		}
395 395
 
396
-		$order->payment_complete( $notification->data->object->id );
396
+		$order->payment_complete($notification->data->object->id);
397 397
 
398 398
 		/* translators: transaction id */
399
-		$order->add_order_note( sprintf( __( 'Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe' ), $notification->data->object->id ) );
399
+		$order->add_order_note(sprintf(__('Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe'), $notification->data->object->id));
400 400
 
401
-		if ( is_callable( array( $order, 'save' ) ) ) {
401
+		if (is_callable(array($order, 'save'))) {
402 402
 			$order->save();
403 403
 		}
404 404
 	}
@@ -410,22 +410,22 @@  discard block
 block discarded – undo
410 410
 	 * @since 4.1.5 Can handle any fail payments from any methods.
411 411
 	 * @param object $notification
412 412
 	 */
413
-	public function process_webhook_charge_failed( $notification ) {
414
-		$order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->id );
413
+	public function process_webhook_charge_failed($notification) {
414
+		$order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->id);
415 415
 
416
-		if ( ! $order ) {
417
-			WC_Stripe_Logger::log( 'Could not find order via charge ID: ' . $notification->data->object->id );
416
+		if ( ! $order) {
417
+			WC_Stripe_Logger::log('Could not find order via charge ID: ' . $notification->data->object->id);
418 418
 			return;
419 419
 		}
420 420
 
421 421
 		// If order status is already in failed status don't continue.
422
-		if ( $order->has_status( 'failed' ) ) {
422
+		if ($order->has_status('failed')) {
423 423
 			return;
424 424
 		}
425 425
 
426
-		$order->update_status( 'failed', __( 'This payment failed to clear.', 'woocommerce-gateway-stripe' ) );
426
+		$order->update_status('failed', __('This payment failed to clear.', 'woocommerce-gateway-stripe'));
427 427
 
428
-		do_action( 'wc_gateway_stripe_process_webhook_payment_error', $order, $notification );
428
+		do_action('wc_gateway_stripe_process_webhook_payment_error', $order, $notification);
429 429
 	}
430 430
 
431 431
 	/**
@@ -436,30 +436,30 @@  discard block
 block discarded – undo
436 436
 	 * @since 4.1.15 Add check to make sure order is processed by Stripe.
437 437
 	 * @param object $notification
438 438
 	 */
439
-	public function process_webhook_source_canceled( $notification ) {
440
-		$order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->id );
439
+	public function process_webhook_source_canceled($notification) {
440
+		$order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->id);
441 441
 
442 442
 		// If can't find order by charge ID, try source ID.
443
-		if ( ! $order ) {
444
-			$order = WC_Stripe_Helper::get_order_by_source_id( $notification->data->object->id );
443
+		if ( ! $order) {
444
+			$order = WC_Stripe_Helper::get_order_by_source_id($notification->data->object->id);
445 445
 
446
-			if ( ! $order ) {
447
-				WC_Stripe_Logger::log( 'Could not find order via charge/source ID: ' . $notification->data->object->id );
446
+			if ( ! $order) {
447
+				WC_Stripe_Logger::log('Could not find order via charge/source ID: ' . $notification->data->object->id);
448 448
 				return;
449 449
 			}
450 450
 		}
451 451
 
452 452
 		// Don't proceed if payment method isn't Stripe.
453
-		if ( 'stripe' !== $order->get_payment_method() ) {
454
-			WC_Stripe_Logger::log( 'Canceled webhook abort: Order was not processed by Stripe: ' . $order->get_id() );
453
+		if ('stripe' !== $order->get_payment_method()) {
454
+			WC_Stripe_Logger::log('Canceled webhook abort: Order was not processed by Stripe: ' . $order->get_id());
455 455
 			return;
456 456
 		}
457 457
 
458
-		if ( ! $order->has_status( 'cancelled' ) ) {
459
-			$order->update_status( 'cancelled', __( 'This payment has cancelled.', 'woocommerce-gateway-stripe' ) );
458
+		if ( ! $order->has_status('cancelled')) {
459
+			$order->update_status('cancelled', __('This payment has cancelled.', 'woocommerce-gateway-stripe'));
460 460
 		}
461 461
 
462
-		do_action( 'wc_gateway_stripe_process_webhook_payment_error', $order, $notification );
462
+		do_action('wc_gateway_stripe_process_webhook_payment_error', $order, $notification);
463 463
 	}
464 464
 
465 465
 	/**
@@ -469,59 +469,59 @@  discard block
 block discarded – undo
469 469
 	 * @version 4.0.0
470 470
 	 * @param object $notification
471 471
 	 */
472
-	public function process_webhook_refund( $notification ) {
473
-		$order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->id );
472
+	public function process_webhook_refund($notification) {
473
+		$order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->id);
474 474
 
475
-		if ( ! $order ) {
476
-			WC_Stripe_Logger::log( 'Could not find order via charge ID: ' . $notification->data->object->id );
475
+		if ( ! $order) {
476
+			WC_Stripe_Logger::log('Could not find order via charge ID: ' . $notification->data->object->id);
477 477
 			return;
478 478
 		}
479 479
 
480 480
 		$order_id = $order->get_id();
481 481
 
482
-		if ( 'stripe' === $order->get_payment_method() ) {
482
+		if ('stripe' === $order->get_payment_method()) {
483 483
 			$charge    = $order->get_transaction_id();
484
-			$captured  = $order->get_meta( '_stripe_charge_captured', true );
485
-			$refund_id = $order->get_meta( '_stripe_refund_id', true );
484
+			$captured  = $order->get_meta('_stripe_charge_captured', true);
485
+			$refund_id = $order->get_meta('_stripe_refund_id', true);
486 486
 
487 487
 			// If the refund ID matches, don't continue to prevent double refunding.
488
-			if ( $notification->data->object->refunds->data[0]->id === $refund_id ) {
488
+			if ($notification->data->object->refunds->data[0]->id === $refund_id) {
489 489
 				return;
490 490
 			}
491 491
 
492 492
 			// Only refund captured charge.
493
-			if ( $charge ) {
494
-				$reason = ( isset( $captured ) && 'yes' === $captured ) ? __( 'Refunded via Stripe Dashboard', 'woocommerce-gateway-stripe' ) : __( 'Pre-Authorization Released via Stripe Dashboard', 'woocommerce-gateway-stripe' );
493
+			if ($charge) {
494
+				$reason = (isset($captured) && 'yes' === $captured) ? __('Refunded via Stripe Dashboard', 'woocommerce-gateway-stripe') : __('Pre-Authorization Released via Stripe Dashboard', 'woocommerce-gateway-stripe');
495 495
 
496 496
 				// Create the refund.
497 497
 				$refund = wc_create_refund(
498 498
 					array(
499 499
 						'order_id' => $order_id,
500
-						'amount'   => $this->get_refund_amount( $notification ),
500
+						'amount'   => $this->get_refund_amount($notification),
501 501
 						'reason'   => $reason,
502 502
 					)
503 503
 				);
504 504
 
505
-				if ( is_wp_error( $refund ) ) {
506
-					WC_Stripe_Logger::log( $refund->get_error_message() );
505
+				if (is_wp_error($refund)) {
506
+					WC_Stripe_Logger::log($refund->get_error_message());
507 507
 				}
508 508
 
509
-				$order->update_meta_data( '_stripe_refund_id', $notification->data->object->refunds->data[0]->id );
509
+				$order->update_meta_data('_stripe_refund_id', $notification->data->object->refunds->data[0]->id);
510 510
 
511
-				$amount = wc_price( $notification->data->object->refunds->data[0]->amount / 100 );
511
+				$amount = wc_price($notification->data->object->refunds->data[0]->amount / 100);
512 512
 
513
-				if ( in_array( strtolower( $order->get_currency() ), WC_Stripe_Helper::no_decimal_currencies() ) ) {
514
-					$amount = wc_price( $notification->data->object->refunds->data[0]->amount );
513
+				if (in_array(strtolower($order->get_currency()), WC_Stripe_Helper::no_decimal_currencies())) {
514
+					$amount = wc_price($notification->data->object->refunds->data[0]->amount);
515 515
 				}
516 516
 
517
-				if ( isset( $notification->data->object->refunds->data[0]->balance_transaction ) ) {
518
-					$this->update_fees( $order, $notification->data->object->refunds->data[0]->balance_transaction );
517
+				if (isset($notification->data->object->refunds->data[0]->balance_transaction)) {
518
+					$this->update_fees($order, $notification->data->object->refunds->data[0]->balance_transaction);
519 519
 				}
520 520
 
521 521
 				/* translators: 1) dollar amount 2) transaction id 3) refund message */
522
-				$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' );
522
+				$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');
523 523
 
524
-				$order->add_order_note( $refund_message );
524
+				$order->add_order_note($refund_message);
525 525
 			}
526 526
 		}
527 527
 	}
@@ -532,30 +532,30 @@  discard block
 block discarded – undo
532 532
 	 * @since 4.0.6
533 533
 	 * @param object $notification
534 534
 	 */
535
-	public function process_review_opened( $notification ) {
536
-		if ( isset( $notification->data->object->payment_intent ) ) {
537
-			$order = WC_Stripe_Helper::get_order_by_intent_id( $notification->data->object->payment_intent );
535
+	public function process_review_opened($notification) {
536
+		if (isset($notification->data->object->payment_intent)) {
537
+			$order = WC_Stripe_Helper::get_order_by_intent_id($notification->data->object->payment_intent);
538 538
 
539
-			if ( ! $order ) {
540
-				WC_Stripe_Logger::log( '[Review Opened] Could not find order via intent ID: ' . $notification->data->object->payment_intent );
539
+			if ( ! $order) {
540
+				WC_Stripe_Logger::log('[Review Opened] Could not find order via intent ID: ' . $notification->data->object->payment_intent);
541 541
 				return;
542 542
 			}
543 543
 		} else {
544
-			$order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->charge );
544
+			$order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->charge);
545 545
 
546
-			if ( ! $order ) {
547
-				WC_Stripe_Logger::log( '[Review Opened] Could not find order via charge ID: ' . $notification->data->object->charge );
546
+			if ( ! $order) {
547
+				WC_Stripe_Logger::log('[Review Opened] Could not find order via charge ID: ' . $notification->data->object->charge);
548 548
 				return;
549 549
 			}
550 550
 		}
551 551
 
552 552
 		/* translators: 1) The URL to the order. 2) The reason type. */
553
-		$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 );
553
+		$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);
554 554
 
555
-		if ( apply_filters( 'wc_stripe_webhook_review_change_order_status', true, $order, $notification ) ) {
556
-			$order->update_status( 'on-hold', $message );
555
+		if (apply_filters('wc_stripe_webhook_review_change_order_status', true, $order, $notification)) {
556
+			$order->update_status('on-hold', $message);
557 557
 		} else {
558
-			$order->add_order_note( $message );
558
+			$order->add_order_note($message);
559 559
 		}
560 560
 	}
561 561
 
@@ -565,34 +565,34 @@  discard block
 block discarded – undo
565 565
 	 * @since 4.0.6
566 566
 	 * @param object $notification
567 567
 	 */
568
-	public function process_review_closed( $notification ) {
569
-		if ( isset( $notification->data->object->payment_intent ) ) {
570
-			$order = WC_Stripe_Helper::get_order_by_intent_id( $notification->data->object->payment_intent );
568
+	public function process_review_closed($notification) {
569
+		if (isset($notification->data->object->payment_intent)) {
570
+			$order = WC_Stripe_Helper::get_order_by_intent_id($notification->data->object->payment_intent);
571 571
 
572
-			if ( ! $order ) {
573
-				WC_Stripe_Logger::log( '[Review Closed] Could not find order via intent ID: ' . $notification->data->object->payment_intent );
572
+			if ( ! $order) {
573
+				WC_Stripe_Logger::log('[Review Closed] Could not find order via intent ID: ' . $notification->data->object->payment_intent);
574 574
 				return;
575 575
 			}
576 576
 		} else {
577
-			$order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->charge );
577
+			$order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->charge);
578 578
 
579
-			if ( ! $order ) {
580
-				WC_Stripe_Logger::log( '[Review Closed] Could not find order via charge ID: ' . $notification->data->object->charge );
579
+			if ( ! $order) {
580
+				WC_Stripe_Logger::log('[Review Closed] Could not find order via charge ID: ' . $notification->data->object->charge);
581 581
 				return;
582 582
 			}
583 583
 		}
584 584
 
585 585
 		/* translators: 1) The reason type. */
586
-		$message = sprintf( __( 'The opened review for this order is now closed. Reason: (%s)', 'woocommerce-gateway-stripe' ), $notification->data->object->reason );
586
+		$message = sprintf(__('The opened review for this order is now closed. Reason: (%s)', 'woocommerce-gateway-stripe'), $notification->data->object->reason);
587 587
 
588
-		if ( $order->has_status( 'on-hold' ) ) {
589
-			if ( apply_filters( 'wc_stripe_webhook_review_change_order_status', true, $order, $notification ) ) {
590
-				$order->update_status( 'processing', $message );
588
+		if ($order->has_status('on-hold')) {
589
+			if (apply_filters('wc_stripe_webhook_review_change_order_status', true, $order, $notification)) {
590
+				$order->update_status('processing', $message);
591 591
 			} else {
592
-				$order->add_order_note( $message );
592
+				$order->add_order_note($message);
593 593
 			}
594 594
 		} else {
595
-			$order->add_order_note( $message );
595
+			$order->add_order_note($message);
596 596
 		}
597 597
 	}
598 598
 
@@ -603,7 +603,7 @@  discard block
 block discarded – undo
603 603
 	 * @version 4.0.0
604 604
 	 * @param object $notification
605 605
 	 */
606
-	public function is_partial_capture( $notification ) {
606
+	public function is_partial_capture($notification) {
607 607
 		return 0 < $notification->data->object->amount_refunded;
608 608
 	}
609 609
 
@@ -614,11 +614,11 @@  discard block
 block discarded – undo
614 614
 	 * @version 4.0.0
615 615
 	 * @param object $notification
616 616
 	 */
617
-	public function get_refund_amount( $notification ) {
618
-		if ( $this->is_partial_capture( $notification ) ) {
617
+	public function get_refund_amount($notification) {
618
+		if ($this->is_partial_capture($notification)) {
619 619
 			$amount = $notification->data->object->refunds->data[0]->amount / 100;
620 620
 
621
-			if ( in_array( strtolower( $notification->data->object->currency ), WC_Stripe_Helper::no_decimal_currencies() ) ) {
621
+			if (in_array(strtolower($notification->data->object->currency), WC_Stripe_Helper::no_decimal_currencies())) {
622 622
 				$amount = $notification->data->object->refunds->data[0]->amount;
623 623
 			}
624 624
 
@@ -635,12 +635,12 @@  discard block
 block discarded – undo
635 635
 	 * @version 4.0.0
636 636
 	 * @param object $notification
637 637
 	 */
638
-	public function get_partial_amount_to_charge( $notification ) {
639
-		if ( $this->is_partial_capture( $notification ) ) {
640
-			$amount = ( $notification->data->object->amount - $notification->data->object->amount_refunded ) / 100;
638
+	public function get_partial_amount_to_charge($notification) {
639
+		if ($this->is_partial_capture($notification)) {
640
+			$amount = ($notification->data->object->amount - $notification->data->object->amount_refunded) / 100;
641 641
 
642
-			if ( in_array( strtolower( $notification->data->object->currency ), WC_Stripe_Helper::no_decimal_currencies() ) ) {
643
-				$amount = ( $notification->data->object->amount - $notification->data->object->amount_refunded );
642
+			if (in_array(strtolower($notification->data->object->currency), WC_Stripe_Helper::no_decimal_currencies())) {
643
+				$amount = ($notification->data->object->amount - $notification->data->object->amount_refunded);
644 644
 			}
645 645
 
646 646
 			return $amount;
@@ -649,69 +649,69 @@  discard block
 block discarded – undo
649 649
 		return false;
650 650
 	}
651 651
 
652
-	public function process_payment_intent_success( $notification ) {
652
+	public function process_payment_intent_success($notification) {
653 653
 		$intent = $notification->data->object;
654
-		$order = WC_Stripe_Helper::get_order_by_intent_id( $intent->id );
654
+		$order = WC_Stripe_Helper::get_order_by_intent_id($intent->id);
655 655
 
656
-		if ( ! $order ) {
657
-			WC_Stripe_Logger::log( 'Could not find order via intent ID: ' . $intent->id );
656
+		if ( ! $order) {
657
+			WC_Stripe_Logger::log('Could not find order via intent ID: ' . $intent->id);
658 658
 			return;
659 659
 		}
660 660
 
661
-		if ( ! $order->has_status( array( 'pending', 'failed' ) ) ) {
661
+		if ( ! $order->has_status(array('pending', 'failed'))) {
662 662
 			return;
663 663
 		}
664 664
 
665
-		if ( $this->lock_order_payment( $order, $intent ) ) {
665
+		if ($this->lock_order_payment($order, $intent)) {
666 666
 			return;
667 667
 		}
668 668
 
669 669
 		$order_id = $order->get_id();
670
-		if ( 'payment_intent.succeeded' === $notification->type || 'payment_intent.amount_capturable_updated' === $notification->type ) {
671
-			$charge = end( $intent->charges->data );
672
-			WC_Stripe_Logger::log( "Stripe PaymentIntent $intent->id succeeded for order $order_id" );
670
+		if ('payment_intent.succeeded' === $notification->type || 'payment_intent.amount_capturable_updated' === $notification->type) {
671
+			$charge = end($intent->charges->data);
672
+			WC_Stripe_Logger::log("Stripe PaymentIntent $intent->id succeeded for order $order_id");
673 673
 
674
-			do_action( 'wc_gateway_stripe_process_payment', $charge, $order );
674
+			do_action('wc_gateway_stripe_process_payment', $charge, $order);
675 675
 
676 676
 			// Process valid response.
677
-			$this->process_response( $charge, $order );
677
+			$this->process_response($charge, $order);
678 678
 
679 679
 		} else {
680 680
 			$error_message = $intent->last_payment_error ? $intent->last_payment_error->message : "";
681 681
 
682 682
 			/* translators: 1) The error message that was received from Stripe. */
683
-			$order->update_status( 'failed', sprintf( __( 'Stripe SCA authentication failed. Reason: %s', 'woocommerce-gateway-stripe' ), $error_message ) );
683
+			$order->update_status('failed', sprintf(__('Stripe SCA authentication failed. Reason: %s', 'woocommerce-gateway-stripe'), $error_message));
684 684
 
685
-			do_action( 'wc_gateway_stripe_process_webhook_payment_error', $order, $notification );
685
+			do_action('wc_gateway_stripe_process_webhook_payment_error', $order, $notification);
686 686
 
687
-			$this->send_failed_order_email( $order_id );
687
+			$this->send_failed_order_email($order_id);
688 688
 		}
689 689
 
690
-		$this->unlock_order_payment( $order );
690
+		$this->unlock_order_payment($order);
691 691
 	}
692 692
 
693
-	public function process_setup_intent( $notification ) {
693
+	public function process_setup_intent($notification) {
694 694
 		$intent = $notification->data->object;
695
-		$order = WC_Stripe_Helper::get_order_by_setup_intent_id( $intent->id );
695
+		$order = WC_Stripe_Helper::get_order_by_setup_intent_id($intent->id);
696 696
 
697
-		if ( ! $order ) {
698
-			WC_Stripe_Logger::log( 'Could not find order via setup intent ID: ' . $intent->id );
697
+		if ( ! $order) {
698
+			WC_Stripe_Logger::log('Could not find order via setup intent ID: ' . $intent->id);
699 699
 			return;
700 700
 		}
701 701
 
702
-		if ( ! $order->has_status( array( 'pending', 'failed' ) ) ) {
702
+		if ( ! $order->has_status(array('pending', 'failed'))) {
703 703
 			return;
704 704
 		}
705 705
 
706
-		if ( $this->lock_order_payment( $order, $intent ) ) {
706
+		if ($this->lock_order_payment($order, $intent)) {
707 707
 			return;
708 708
 		}
709 709
 
710 710
 		$order_id = $order->get_id();
711
-		if ( 'setup_intent.succeeded' === $notification->type ) {
712
-			WC_Stripe_Logger::log( "Stripe SetupIntent $intent->id succeeded for order $order_id" );
713
-			if ( WC_Stripe_Helper::is_pre_orders_exists() && WC_Pre_Orders_Order::order_contains_pre_order( $order ) ) {
714
-				WC_Pre_Orders_Order::mark_order_as_pre_ordered( $order );
711
+		if ('setup_intent.succeeded' === $notification->type) {
712
+			WC_Stripe_Logger::log("Stripe SetupIntent $intent->id succeeded for order $order_id");
713
+			if (WC_Stripe_Helper::is_pre_orders_exists() && WC_Pre_Orders_Order::order_contains_pre_order($order)) {
714
+				WC_Pre_Orders_Order::mark_order_as_pre_ordered($order);
715 715
 			} else {
716 716
 				$order->payment_complete();
717 717
 			}
@@ -719,12 +719,12 @@  discard block
 block discarded – undo
719 719
 			$error_message = $intent->last_setup_error ? $intent->last_setup_error->message : "";
720 720
 
721 721
 			/* translators: 1) The error message that was received from Stripe. */
722
-			$order->update_status( 'failed', sprintf( __( 'Stripe SCA authentication failed. Reason: %s', 'woocommerce-gateway-stripe' ), $error_message ) );
722
+			$order->update_status('failed', sprintf(__('Stripe SCA authentication failed. Reason: %s', 'woocommerce-gateway-stripe'), $error_message));
723 723
 
724
-			$this->send_failed_order_email( $order_id );
724
+			$this->send_failed_order_email($order_id);
725 725
 		}
726 726
 
727
-		$this->unlock_order_payment( $order );
727
+		$this->unlock_order_payment($order);
728 728
 	}
729 729
 
730 730
 	/**
@@ -734,55 +734,55 @@  discard block
 block discarded – undo
734 734
 	 * @version 4.0.0
735 735
 	 * @param string $request_body
736 736
 	 */
737
-	public function process_webhook( $request_body ) {
738
-		$notification = json_decode( $request_body );
737
+	public function process_webhook($request_body) {
738
+		$notification = json_decode($request_body);
739 739
 
740
-		switch ( $notification->type ) {
740
+		switch ($notification->type) {
741 741
 			case 'source.chargeable':
742
-				$this->process_webhook_payment( $notification );
742
+				$this->process_webhook_payment($notification);
743 743
 				break;
744 744
 
745 745
 			case 'source.canceled':
746
-				$this->process_webhook_source_canceled( $notification );
746
+				$this->process_webhook_source_canceled($notification);
747 747
 				break;
748 748
 
749 749
 			case 'charge.succeeded':
750
-				$this->process_webhook_charge_succeeded( $notification );
750
+				$this->process_webhook_charge_succeeded($notification);
751 751
 				break;
752 752
 
753 753
 			case 'charge.failed':
754
-				$this->process_webhook_charge_failed( $notification );
754
+				$this->process_webhook_charge_failed($notification);
755 755
 				break;
756 756
 
757 757
 			case 'charge.captured':
758
-				$this->process_webhook_capture( $notification );
758
+				$this->process_webhook_capture($notification);
759 759
 				break;
760 760
 
761 761
 			case 'charge.dispute.created':
762
-				$this->process_webhook_dispute( $notification );
762
+				$this->process_webhook_dispute($notification);
763 763
 				break;
764 764
 
765 765
 			case 'charge.refunded':
766
-				$this->process_webhook_refund( $notification );
766
+				$this->process_webhook_refund($notification);
767 767
 				break;
768 768
 
769 769
 			case 'review.opened':
770
-				$this->process_review_opened( $notification );
770
+				$this->process_review_opened($notification);
771 771
 				break;
772 772
 
773 773
 			case 'review.closed':
774
-				$this->process_review_closed( $notification );
774
+				$this->process_review_closed($notification);
775 775
 				break;
776 776
 
777 777
 			case 'payment_intent.succeeded':
778 778
 			case 'payment_intent.payment_failed':
779 779
 			case 'payment_intent.amount_capturable_updated':
780
-				$this->process_payment_intent_success( $notification );
780
+				$this->process_payment_intent_success($notification);
781 781
 				break;
782 782
 
783 783
 			case 'setup_intent.succeeded':
784 784
 			case 'setup_intent.setup_failed':
785
-				$this->process_setup_intent( $notification );
785
+				$this->process_setup_intent($notification);
786 786
 
787 787
 		}
788 788
 	}
Please login to merge, or discard this patch.
includes/admin/stripe-settings.php 1 patch
Spacing   +70 added lines, -70 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) {
2
+if ( ! defined('ABSPATH')) {
3 3
 	exit;
4 4
 }
5 5
 
@@ -7,190 +7,190 @@  discard block
 block discarded – undo
7 7
 	'wc_stripe_settings',
8 8
 	array(
9 9
 		'enabled'                       => array(
10
-			'title'       => __( 'Enable/Disable', 'woocommerce-gateway-stripe' ),
11
-			'label'       => __( 'Enable Stripe', 'woocommerce-gateway-stripe' ),
10
+			'title'       => __('Enable/Disable', 'woocommerce-gateway-stripe'),
11
+			'label'       => __('Enable Stripe', 'woocommerce-gateway-stripe'),
12 12
 			'type'        => 'checkbox',
13 13
 			'description' => '',
14 14
 			'default'     => 'no',
15 15
 		),
16 16
 		'title'                         => array(
17
-			'title'       => __( 'Title', 'woocommerce-gateway-stripe' ),
17
+			'title'       => __('Title', 'woocommerce-gateway-stripe'),
18 18
 			'type'        => 'text',
19
-			'description' => __( 'This controls the title which the user sees during checkout.', 'woocommerce-gateway-stripe' ),
20
-			'default'     => __( 'Credit Card (Stripe)', 'woocommerce-gateway-stripe' ),
19
+			'description' => __('This controls the title which the user sees during checkout.', 'woocommerce-gateway-stripe'),
20
+			'default'     => __('Credit Card (Stripe)', 'woocommerce-gateway-stripe'),
21 21
 			'desc_tip'    => true,
22 22
 		),
23 23
 		'description'                   => array(
24
-			'title'       => __( 'Description', 'woocommerce-gateway-stripe' ),
24
+			'title'       => __('Description', 'woocommerce-gateway-stripe'),
25 25
 			'type'        => 'text',
26
-			'description' => __( 'This controls the description which the user sees during checkout.', 'woocommerce-gateway-stripe' ),
27
-			'default'     => __( 'Pay with your credit card via Stripe.', 'woocommerce-gateway-stripe' ),
26
+			'description' => __('This controls the description which the user sees during checkout.', 'woocommerce-gateway-stripe'),
27
+			'default'     => __('Pay with your credit card via Stripe.', 'woocommerce-gateway-stripe'),
28 28
 			'desc_tip'    => true,
29 29
 		),
30 30
 		'webhook'                       => array(
31
-			'title'       => __( 'Webhook Endpoints', 'woocommerce-gateway-stripe' ),
31
+			'title'       => __('Webhook Endpoints', 'woocommerce-gateway-stripe'),
32 32
 			'type'        => 'title',
33 33
 			/* translators: webhook URL */
34 34
 			'description' => $this->display_admin_settings_webhook_description(),
35 35
 		),
36 36
 		'testmode'                      => array(
37
-			'title'       => __( 'Test mode', 'woocommerce-gateway-stripe' ),
38
-			'label'       => __( 'Enable Test Mode', 'woocommerce-gateway-stripe' ),
37
+			'title'       => __('Test mode', 'woocommerce-gateway-stripe'),
38
+			'label'       => __('Enable Test Mode', 'woocommerce-gateway-stripe'),
39 39
 			'type'        => 'checkbox',
40
-			'description' => __( 'Place the payment gateway in test mode using test API keys.', 'woocommerce-gateway-stripe' ),
40
+			'description' => __('Place the payment gateway in test mode using test API keys.', 'woocommerce-gateway-stripe'),
41 41
 			'default'     => 'yes',
42 42
 			'desc_tip'    => true,
43 43
 		),
44 44
 		'test_publishable_key'          => array(
45
-			'title'       => __( 'Test Publishable Key', 'woocommerce-gateway-stripe' ),
45
+			'title'       => __('Test Publishable Key', 'woocommerce-gateway-stripe'),
46 46
 			'type'        => 'text',
47
-			'description' => __( 'Get your API keys from your stripe account. Invalid values will be rejected. Only values starting with "pk_test_" will be saved.', 'woocommerce-gateway-stripe' ),
47
+			'description' => __('Get your API keys from your stripe account. Invalid values will be rejected. Only values starting with "pk_test_" will be saved.', 'woocommerce-gateway-stripe'),
48 48
 			'default'     => '',
49 49
 			'desc_tip'    => true,
50 50
 		),
51 51
 		'test_secret_key'               => array(
52
-			'title'       => __( 'Test Secret Key', 'woocommerce-gateway-stripe' ),
52
+			'title'       => __('Test Secret Key', 'woocommerce-gateway-stripe'),
53 53
 			'type'        => 'password',
54
-			'description' => __( 'Get your API keys from your stripe account. Invalid values will be rejected. Only values starting with "sk_test_" or "rk_test_" will be saved.', 'woocommerce-gateway-stripe' ),
54
+			'description' => __('Get your API keys from your stripe account. Invalid values will be rejected. Only values starting with "sk_test_" or "rk_test_" will be saved.', 'woocommerce-gateway-stripe'),
55 55
 			'default'     => '',
56 56
 			'desc_tip'    => true,
57 57
 		),
58 58
 		'test_webhook_secret'           => array(
59
-			'title'       => __( 'Test Webhook Secret', 'woocommerce-gateway-stripe' ),
59
+			'title'       => __('Test Webhook Secret', 'woocommerce-gateway-stripe'),
60 60
 			'type'        => 'password',
61
-			'description' => __( 'Get your webhook signing secret from the webhooks section in your stripe account.', 'woocommerce-gateway-stripe' ),
61
+			'description' => __('Get your webhook signing secret from the webhooks section in your stripe account.', 'woocommerce-gateway-stripe'),
62 62
 			'default'     => '',
63 63
 			'desc_tip'    => true,
64 64
 		),
65 65
 		'publishable_key'               => array(
66
-			'title'       => __( 'Live Publishable Key', 'woocommerce-gateway-stripe' ),
66
+			'title'       => __('Live Publishable Key', 'woocommerce-gateway-stripe'),
67 67
 			'type'        => 'text',
68
-			'description' => __( 'Get your API keys from your stripe account. Invalid values will be rejected. Only values starting with "pk_live_" will be saved.', 'woocommerce-gateway-stripe' ),
68
+			'description' => __('Get your API keys from your stripe account. Invalid values will be rejected. Only values starting with "pk_live_" will be saved.', 'woocommerce-gateway-stripe'),
69 69
 			'default'     => '',
70 70
 			'desc_tip'    => true,
71 71
 		),
72 72
 		'secret_key'                    => array(
73
-			'title'       => __( 'Live Secret Key', 'woocommerce-gateway-stripe' ),
73
+			'title'       => __('Live Secret Key', 'woocommerce-gateway-stripe'),
74 74
 			'type'        => 'password',
75
-			'description' => __( 'Get your API keys from your stripe account. Invalid values will be rejected. Only values starting with "sk_live_" or "rk_live_" will be saved.', 'woocommerce-gateway-stripe' ),
75
+			'description' => __('Get your API keys from your stripe account. Invalid values will be rejected. Only values starting with "sk_live_" or "rk_live_" will be saved.', 'woocommerce-gateway-stripe'),
76 76
 			'default'     => '',
77 77
 			'desc_tip'    => true,
78 78
 		),
79 79
 		'webhook_secret'               => array(
80
-			'title'       => __( 'Webhook Secret', 'woocommerce-gateway-stripe' ),
80
+			'title'       => __('Webhook Secret', 'woocommerce-gateway-stripe'),
81 81
 			'type'        => 'password',
82
-			'description' => __( 'Get your webhook signing secret from the webhooks section in your stripe account.', 'woocommerce-gateway-stripe' ),
82
+			'description' => __('Get your webhook signing secret from the webhooks section in your stripe account.', 'woocommerce-gateway-stripe'),
83 83
 			'default'     => '',
84 84
 			'desc_tip'    => true,
85 85
 		),
86 86
 		'inline_cc_form'                => array(
87
-			'title'       => __( 'Inline Credit Card Form', 'woocommerce-gateway-stripe' ),
87
+			'title'       => __('Inline Credit Card Form', 'woocommerce-gateway-stripe'),
88 88
 			'type'        => 'checkbox',
89
-			'description' => __( 'Choose the style you want to show for your credit card form. When unchecked, the credit card form will display separate credit card number field, expiry date field and cvc field.', 'woocommerce-gateway-stripe' ),
89
+			'description' => __('Choose the style you want to show for your credit card form. When unchecked, the credit card form will display separate credit card number field, expiry date field and cvc field.', 'woocommerce-gateway-stripe'),
90 90
 			'default'     => 'no',
91 91
 			'desc_tip'    => true,
92 92
 		),
93 93
 		'statement_descriptor'          => array(
94
-			'title'       => __( 'Statement Descriptor', 'woocommerce-gateway-stripe' ),
94
+			'title'       => __('Statement Descriptor', 'woocommerce-gateway-stripe'),
95 95
 			'type'        => 'text',
96
-			'description' => __( 'Statement descriptors are limited to 22 characters, cannot use the special characters >, <, ", \, \', *, and must not consist solely of numbers. This will appear on your customer\'s statement in capital letters.', 'woocommerce-gateway-stripe' ),
96
+			'description' => __('Statement descriptors are limited to 22 characters, cannot use the special characters >, <, ", \, \', *, and must not consist solely of numbers. This will appear on your customer\'s statement in capital letters.', 'woocommerce-gateway-stripe'),
97 97
 			'default'     => '',
98 98
 			'desc_tip'    => true,
99 99
 		),
100 100
 		'capture'                       => array(
101
-			'title'       => __( 'Capture', 'woocommerce-gateway-stripe' ),
102
-			'label'       => __( 'Capture charge immediately', 'woocommerce-gateway-stripe' ),
101
+			'title'       => __('Capture', 'woocommerce-gateway-stripe'),
102
+			'label'       => __('Capture charge immediately', 'woocommerce-gateway-stripe'),
103 103
 			'type'        => 'checkbox',
104
-			'description' => __( 'Whether or not to immediately capture the charge. When unchecked, the charge issues an authorization and will need to be captured later. Uncaptured charges expire in 7 days.', 'woocommerce-gateway-stripe' ),
104
+			'description' => __('Whether or not to immediately capture the charge. When unchecked, the charge issues an authorization and will need to be captured later. Uncaptured charges expire in 7 days.', 'woocommerce-gateway-stripe'),
105 105
 			'default'     => 'yes',
106 106
 			'desc_tip'    => true,
107 107
 		),
108 108
 		'payment_request'               => array(
109
-			'title'       => __( 'Payment Request Buttons', 'woocommerce-gateway-stripe' ),
109
+			'title'       => __('Payment Request Buttons', 'woocommerce-gateway-stripe'),
110 110
 			/* translators: 1) br tag 2) opening anchor tag 3) closing anchor tag */
111
-			'label'       => sprintf( __( 'Enable Payment Request Buttons. (Apple Pay/Chrome Payment Request API) %1$sBy using Apple Pay, you agree to %2$s and %3$s\'s terms of service.', 'woocommerce-gateway-stripe' ), '<br />', '<a href="https://stripe.com/apple-pay/legal" target="_blank">Stripe</a>', '<a href="https://developer.apple.com/apple-pay/acceptable-use-guidelines-for-websites/" target="_blank">Apple</a>' ),
111
+			'label'       => sprintf(__('Enable Payment Request Buttons. (Apple Pay/Chrome Payment Request API) %1$sBy using Apple Pay, you agree to %2$s and %3$s\'s terms of service.', 'woocommerce-gateway-stripe'), '<br />', '<a href="https://stripe.com/apple-pay/legal" target="_blank">Stripe</a>', '<a href="https://developer.apple.com/apple-pay/acceptable-use-guidelines-for-websites/" target="_blank">Apple</a>'),
112 112
 			'type'        => 'checkbox',
113
-			'description' => __( 'If enabled, users will be able to pay using Apple Pay or Chrome Payment Request if supported by the browser.', 'woocommerce-gateway-stripe' ),
113
+			'description' => __('If enabled, users will be able to pay using Apple Pay or Chrome Payment Request if supported by the browser.', 'woocommerce-gateway-stripe'),
114 114
 			'default'     => 'yes',
115 115
 			'desc_tip'    => true,
116 116
 		),
117 117
 		'payment_request_button_type'   => array(
118
-			'title'       => __( 'Payment Request Button Type', 'woocommerce-gateway-stripe' ),
119
-			'label'       => __( 'Button Type', 'woocommerce-gateway-stripe' ),
118
+			'title'       => __('Payment Request Button Type', 'woocommerce-gateway-stripe'),
119
+			'label'       => __('Button Type', 'woocommerce-gateway-stripe'),
120 120
 			'type'        => 'select',
121
-			'description' => __( 'Select the button type you would like to show.', 'woocommerce-gateway-stripe' ),
121
+			'description' => __('Select the button type you would like to show.', 'woocommerce-gateway-stripe'),
122 122
 			'default'     => 'buy',
123 123
 			'desc_tip'    => true,
124 124
 			'options'     => array(
125
-				'default' => __( 'Default', 'woocommerce-gateway-stripe' ),
126
-				'buy'     => __( 'Buy', 'woocommerce-gateway-stripe' ),
127
-				'donate'  => __( 'Donate', 'woocommerce-gateway-stripe' ),
128
-				'branded' => __( 'Branded', 'woocommerce-gateway-stripe' ),
129
-				'custom'  => __( 'Custom', 'woocommerce-gateway-stripe' ),
125
+				'default' => __('Default', 'woocommerce-gateway-stripe'),
126
+				'buy'     => __('Buy', 'woocommerce-gateway-stripe'),
127
+				'donate'  => __('Donate', 'woocommerce-gateway-stripe'),
128
+				'branded' => __('Branded', 'woocommerce-gateway-stripe'),
129
+				'custom'  => __('Custom', 'woocommerce-gateway-stripe'),
130 130
 			),
131 131
 		),
132 132
 		'payment_request_button_theme'  => array(
133
-			'title'       => __( 'Payment Request Button Theme', 'woocommerce-gateway-stripe' ),
134
-			'label'       => __( 'Button Theme', 'woocommerce-gateway-stripe' ),
133
+			'title'       => __('Payment Request Button Theme', 'woocommerce-gateway-stripe'),
134
+			'label'       => __('Button Theme', 'woocommerce-gateway-stripe'),
135 135
 			'type'        => 'select',
136
-			'description' => __( 'Select the button theme you would like to show.', 'woocommerce-gateway-stripe' ),
136
+			'description' => __('Select the button theme you would like to show.', 'woocommerce-gateway-stripe'),
137 137
 			'default'     => 'dark',
138 138
 			'desc_tip'    => true,
139 139
 			'options'     => array(
140
-				'dark'          => __( 'Dark', 'woocommerce-gateway-stripe' ),
141
-				'light'         => __( 'Light', 'woocommerce-gateway-stripe' ),
142
-				'light-outline' => __( 'Light-Outline', 'woocommerce-gateway-stripe' ),
140
+				'dark'          => __('Dark', 'woocommerce-gateway-stripe'),
141
+				'light'         => __('Light', 'woocommerce-gateway-stripe'),
142
+				'light-outline' => __('Light-Outline', 'woocommerce-gateway-stripe'),
143 143
 			),
144 144
 		),
145 145
 		'payment_request_button_height' => array(
146
-			'title'       => __( 'Payment Request Button Height', 'woocommerce-gateway-stripe' ),
147
-			'label'       => __( 'Button Height', 'woocommerce-gateway-stripe' ),
146
+			'title'       => __('Payment Request Button Height', 'woocommerce-gateway-stripe'),
147
+			'label'       => __('Button Height', 'woocommerce-gateway-stripe'),
148 148
 			'type'        => 'text',
149
-			'description' => __( 'Enter the height you would like the button to be in pixels. Width will always be 100%.', 'woocommerce-gateway-stripe' ),
149
+			'description' => __('Enter the height you would like the button to be in pixels. Width will always be 100%.', 'woocommerce-gateway-stripe'),
150 150
 			'default'     => '44',
151 151
 			'desc_tip'    => true,
152 152
 		),
153 153
 		'payment_request_button_label' => array(
154
-			'title'       => __( 'Payment Request Button Label', 'woocommerce-gateway-stripe' ),
155
-			'label'       => __( 'Button Label', 'woocommerce-gateway-stripe' ),
154
+			'title'       => __('Payment Request Button Label', 'woocommerce-gateway-stripe'),
155
+			'label'       => __('Button Label', 'woocommerce-gateway-stripe'),
156 156
 			'type'        => 'text',
157
-			'description' => __( 'Enter the custom text you would like the button to have.', 'woocommerce-gateway-stripe' ),
158
-			'default'     => __( 'Buy now', 'woocommerce-gateway-stripe' ),
157
+			'description' => __('Enter the custom text you would like the button to have.', 'woocommerce-gateway-stripe'),
158
+			'default'     => __('Buy now', 'woocommerce-gateway-stripe'),
159 159
 			'desc_tip'    => true,
160 160
 		),
161 161
 		'payment_request_button_branded_type' => array(
162
-			'title'       => __( 'Payment Request Branded Button Label Format', 'woocommerce-gateway-stripe' ),
163
-			'label'       => __( 'Branded Button Label Format', 'woocommerce-gateway-stripe' ),
162
+			'title'       => __('Payment Request Branded Button Label Format', 'woocommerce-gateway-stripe'),
163
+			'label'       => __('Branded Button Label Format', 'woocommerce-gateway-stripe'),
164 164
 			'type'        => 'select',
165
-			'description' => __( 'Select the branded button label format.', 'woocommerce-gateway-stripe' ),
165
+			'description' => __('Select the branded button label format.', 'woocommerce-gateway-stripe'),
166 166
 			'default'     => 'long',
167 167
 			'desc_tip'    => true,
168 168
 			'options'     => array(
169
-				'short' => __( 'Logo only', 'woocommerce-gateway-stripe' ),
170
-				'long'  => __( 'Text and logo', 'woocommerce-gateway-stripe' ),
169
+				'short' => __('Logo only', 'woocommerce-gateway-stripe'),
170
+				'long'  => __('Text and logo', 'woocommerce-gateway-stripe'),
171 171
 			),
172 172
 		),
173 173
 		'saved_cards'                   => array(
174
-			'title'       => __( 'Saved Cards', 'woocommerce-gateway-stripe' ),
175
-			'label'       => __( 'Enable Payment via Saved Cards', 'woocommerce-gateway-stripe' ),
174
+			'title'       => __('Saved Cards', 'woocommerce-gateway-stripe'),
175
+			'label'       => __('Enable Payment via Saved Cards', 'woocommerce-gateway-stripe'),
176 176
 			'type'        => 'checkbox',
177
-			'description' => __( 'If enabled, users will be able to pay with a saved card during checkout. Card details are saved on Stripe servers, not on your store.', 'woocommerce-gateway-stripe' ),
177
+			'description' => __('If enabled, users will be able to pay with a saved card during checkout. Card details are saved on Stripe servers, not on your store.', 'woocommerce-gateway-stripe'),
178 178
 			'default'     => 'yes',
179 179
 			'desc_tip'    => true,
180 180
 		),
181 181
 		'logging'                       => array(
182
-			'title'       => __( 'Logging', 'woocommerce-gateway-stripe' ),
183
-			'label'       => __( 'Log debug messages', 'woocommerce-gateway-stripe' ),
182
+			'title'       => __('Logging', 'woocommerce-gateway-stripe'),
183
+			'label'       => __('Log debug messages', 'woocommerce-gateway-stripe'),
184 184
 			'type'        => 'checkbox',
185
-			'description' => __( 'Save debug messages to the WooCommerce System Status log.', 'woocommerce-gateway-stripe' ),
185
+			'description' => __('Save debug messages to the WooCommerce System Status log.', 'woocommerce-gateway-stripe'),
186 186
 			'default'     => 'no',
187 187
 			'desc_tip'    => true,
188 188
 		),
189 189
 		'cloudfront_user_agent'                       => array(
190
-			'title'       => __( 'Cloud Front User Agent', 'woocommerce-gateway-stripe' ),
191
-			'label'       => __( 'Enable Cloud Front User Agent', 'woocommerce-gateway-stripe' ),
190
+			'title'       => __('Cloud Front User Agent', 'woocommerce-gateway-stripe'),
191
+			'label'       => __('Enable Cloud Front User Agent', 'woocommerce-gateway-stripe'),
192 192
 			'type'        => 'checkbox',
193
-			'description' => __( 'Disable check for stripe user agent in webhook handles.', 'woocommerce-gateway-stripe' ),
193
+			'description' => __('Disable check for stripe user agent in webhook handles.', 'woocommerce-gateway-stripe'),
194 194
 			'default'     => 'no',
195 195
 			'desc_tip'    => true,
196 196
 		),
Please login to merge, or discard this patch.