Completed
Push — master ( 1979c4...c84ee7 )
by Roy
02:10
created
includes/class-wc-stripe-order-handler.php 1 patch
Spacing   +171 added lines, -171 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
 
@@ -23,12 +23,12 @@  discard block
 block discarded – undo
23 23
 
24 24
 		$this->retry_interval = 2;
25 25
 
26
-		add_action( 'wp', array( $this, 'maybe_process_redirect_order' ) );
27
-		add_action( 'woocommerce_order_status_on-hold_to_processing', array( $this, 'capture_payment' ) );
28
-		add_action( 'woocommerce_order_status_on-hold_to_completed', array( $this, 'capture_payment' ) );
29
-		add_action( 'woocommerce_order_status_on-hold_to_cancelled', array( $this, 'cancel_payment' ) );
30
-		add_action( 'woocommerce_order_status_on-hold_to_refunded', array( $this, 'cancel_payment' ) );
31
-		add_action( 'wc_ajax_wc_stripe_validate_checkout', array( $this, 'validate_checkout' ) );
26
+		add_action('wp', array($this, 'maybe_process_redirect_order'));
27
+		add_action('woocommerce_order_status_on-hold_to_processing', array($this, 'capture_payment'));
28
+		add_action('woocommerce_order_status_on-hold_to_completed', array($this, 'capture_payment'));
29
+		add_action('woocommerce_order_status_on-hold_to_cancelled', array($this, 'cancel_payment'));
30
+		add_action('woocommerce_order_status_on-hold_to_refunded', array($this, 'cancel_payment'));
31
+		add_action('wc_ajax_wc_stripe_validate_checkout', array($this, 'validate_checkout'));
32 32
 	}
33 33
 
34 34
 	/**
@@ -49,25 +49,25 @@  discard block
 block discarded – undo
49 49
 	 * @since 4.0.0
50 50
 	 * @version 4.0.0
51 51
 	 */
52
-	public function process_redirect_payment( $order_id, $retry = true ) {
52
+	public function process_redirect_payment($order_id, $retry = true) {
53 53
 		try {
54
-			$source = wc_clean( $_GET['source'] );
54
+			$source = wc_clean($_GET['source']);
55 55
 
56
-			if ( empty( $source ) ) {
56
+			if (empty($source)) {
57 57
 				return;
58 58
 			}
59 59
 
60
-			if ( empty( $order_id ) ) {
60
+			if (empty($order_id)) {
61 61
 				return;
62 62
 			}
63 63
 
64
-			$order = wc_get_order( $order_id );
64
+			$order = wc_get_order($order_id);
65 65
 
66
-			if ( ! is_object( $order ) ) {
66
+			if ( ! is_object($order)) {
67 67
 				return;
68 68
 			}
69 69
 
70
-			if ( 'processing' === $order->get_status() || 'completed' === $order->get_status() || 'on-hold' === $order->get_status() ) {
70
+			if ('processing' === $order->get_status() || 'completed' === $order->get_status() || 'on-hold' === $order->get_status()) {
71 71
 				return;
72 72
 			}
73 73
 
@@ -75,127 +75,127 @@  discard block
 block discarded – undo
75 75
 			$response = null;
76 76
 
77 77
 			// This will throw exception if not valid.
78
-			$this->validate_minimum_order_amount( $order );
78
+			$this->validate_minimum_order_amount($order);
79 79
 
80
-			WC_Stripe_Logger::log( "Info: (Redirect) Begin processing payment for order $order_id for the amount of {$order->get_total()}" );
80
+			WC_Stripe_Logger::log("Info: (Redirect) Begin processing payment for order $order_id for the amount of {$order->get_total()}");
81 81
 
82 82
 			/**
83 83
 			 * First check if the source is chargeable at this time. If not,
84 84
 			 * webhook will take care of it later.
85 85
 			 */
86
-			$source_info = WC_Stripe_API::retrieve( 'sources/' . $source );
86
+			$source_info = WC_Stripe_API::retrieve('sources/' . $source);
87 87
 
88
-			if ( ! empty( $source_info->error ) ) {
89
-				throw new WC_Stripe_Exception( print_r( $source_info, true ), $source_info->error->message );
88
+			if ( ! empty($source_info->error)) {
89
+				throw new WC_Stripe_Exception(print_r($source_info, true), $source_info->error->message);
90 90
 			}
91 91
 
92
-			if ( 'failed' === $source_info->status || 'canceled' === $source_info->status ) {
93
-				throw new WC_Stripe_Exception( print_r( $source_info, true ), __( 'Unable to process this payment, please try again or use alternative method.', 'woocommerce-gateway-stripe' ) );
92
+			if ('failed' === $source_info->status || 'canceled' === $source_info->status) {
93
+				throw new WC_Stripe_Exception(print_r($source_info, true), __('Unable to process this payment, please try again or use alternative method.', 'woocommerce-gateway-stripe'));
94 94
 			}
95 95
 
96 96
 			// If already consumed, then ignore request.
97
-			if ( 'consumed' === $source_info->status ) {
97
+			if ('consumed' === $source_info->status) {
98 98
 				return;
99 99
 			}
100 100
 
101 101
 			// If not chargeable, then ignore request.
102
-			if ( 'chargeable' !== $source_info->status ) {
102
+			if ('chargeable' !== $source_info->status) {
103 103
 				return;
104 104
 			}
105 105
 
106 106
 			// Prep source object.
107 107
 			$source_object           = new stdClass();
108 108
 			$source_object->token_id = '';
109
-			$source_object->customer = $this->get_stripe_customer_id( $order );
109
+			$source_object->customer = $this->get_stripe_customer_id($order);
110 110
 			$source_object->source   = $source_info->id;
111 111
 
112 112
 			// Make the request.
113
-			$response = WC_Stripe_API::request( $this->generate_payment_request( $order, $source_object ) );
113
+			$response = WC_Stripe_API::request($this->generate_payment_request($order, $source_object));
114 114
 
115
-			if ( ! empty( $response->error ) ) {
115
+			if ( ! empty($response->error)) {
116 116
 				// If it is an API error such connection or server, let's retry.
117
-				if ( 'api_connection_error' === $response->error->type || 'api_error' === $response->error->type ) {
118
-					if ( $retry ) {
119
-						sleep( 5 );
120
-						return $this->process_redirect_payment( $order_id, false );
117
+				if ('api_connection_error' === $response->error->type || 'api_error' === $response->error->type) {
118
+					if ($retry) {
119
+						sleep(5);
120
+						return $this->process_redirect_payment($order_id, false);
121 121
 					} else {
122
-						$localized_message = __( 'API connection error and retries exhausted.', 'woocommerce-gateway-stripe' );
123
-						$order->add_order_note( $localized_message );
124
-						throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message );
122
+						$localized_message = __('API connection error and retries exhausted.', 'woocommerce-gateway-stripe');
123
+						$order->add_order_note($localized_message);
124
+						throw new WC_Stripe_Exception(print_r($response, true), $localized_message);
125 125
 					}
126 126
 				}
127 127
 
128 128
 				// We want to retry.
129
-				if ( $this->is_retryable_error( $response->error ) ) {
130
-					if ( $retry ) {
129
+				if ($this->is_retryable_error($response->error)) {
130
+					if ($retry) {
131 131
 						// Don't do anymore retries after this.
132
-						if ( 5 <= $this->retry_interval ) {
133
-							return $this->process_redirect_payment( $order_id, false );
132
+						if (5 <= $this->retry_interval) {
133
+							return $this->process_redirect_payment($order_id, false);
134 134
 						}
135 135
 
136
-						sleep( $this->retry_interval );
136
+						sleep($this->retry_interval);
137 137
 
138 138
 						$this->retry_interval++;
139
-						return $this->process_redirect_payment( $order_id, true );
139
+						return $this->process_redirect_payment($order_id, true);
140 140
 					} else {
141
-						$localized_message = __( 'On going requests error and retries exhausted.', 'woocommerce-gateway-stripe' );
142
-						$order->add_order_note( $localized_message );
143
-						throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message );
141
+						$localized_message = __('On going requests error and retries exhausted.', 'woocommerce-gateway-stripe');
142
+						$order->add_order_note($localized_message);
143
+						throw new WC_Stripe_Exception(print_r($response, true), $localized_message);
144 144
 					}
145 145
 				}
146 146
 
147 147
 				// Customer param wrong? The user may have been deleted on stripe's end. Remove customer_id. Can be retried without.
148
-				if ( preg_match( '/No such customer/i', $response->error->message ) && $retry ) {
149
-					if ( WC_Stripe_Helper::is_pre_30() ) {
150
-						delete_user_meta( $order->customer_user, '_stripe_customer_id' );
151
-						delete_post_meta( $order_id, '_stripe_customer_id' );
148
+				if (preg_match('/No such customer/i', $response->error->message) && $retry) {
149
+					if (WC_Stripe_Helper::is_pre_30()) {
150
+						delete_user_meta($order->customer_user, '_stripe_customer_id');
151
+						delete_post_meta($order_id, '_stripe_customer_id');
152 152
 					} else {
153
-						delete_user_meta( $order->get_customer_id(), '_stripe_customer_id' );
154
-						$order->delete_meta_data( '_stripe_customer_id' );
153
+						delete_user_meta($order->get_customer_id(), '_stripe_customer_id');
154
+						$order->delete_meta_data('_stripe_customer_id');
155 155
 						$order->save();
156 156
 					}
157 157
 
158
-					return $this->process_redirect_payment( $order_id, false );
158
+					return $this->process_redirect_payment($order_id, false);
159 159
 
160
-				} elseif ( preg_match( '/No such token/i', $response->error->message ) && $source_object->token_id ) {
160
+				} elseif (preg_match('/No such token/i', $response->error->message) && $source_object->token_id) {
161 161
 					// Source param wrong? The CARD may have been deleted on stripe's end. Remove token and show message.
162 162
 
163
-					$wc_token = WC_Payment_Tokens::get( $source_object->token_id );
163
+					$wc_token = WC_Payment_Tokens::get($source_object->token_id);
164 164
 					$wc_token->delete();
165
-					$message = __( 'This card is no longer available and has been removed.', 'woocommerce-gateway-stripe' );
166
-					$order->add_order_note( $message );
167
-					throw new WC_Stripe_Exception( print_r( $response, true ), $message );
165
+					$message = __('This card is no longer available and has been removed.', 'woocommerce-gateway-stripe');
166
+					$order->add_order_note($message);
167
+					throw new WC_Stripe_Exception(print_r($response, true), $message);
168 168
 				}
169 169
 
170 170
 				$localized_messages = WC_Stripe_Helper::get_localized_messages();
171 171
 
172
-				if ( 'card_error' === $response->error->type ) {
173
-					$message = isset( $localized_messages[ $response->error->code ] ) ? $localized_messages[ $response->error->code ] : $response->error->message;
172
+				if ('card_error' === $response->error->type) {
173
+					$message = isset($localized_messages[$response->error->code]) ? $localized_messages[$response->error->code] : $response->error->message;
174 174
 				} else {
175
-					$message = isset( $localized_messages[ $response->error->type ] ) ? $localized_messages[ $response->error->type ] : $response->error->message;
175
+					$message = isset($localized_messages[$response->error->type]) ? $localized_messages[$response->error->type] : $response->error->message;
176 176
 				}
177 177
 
178
-				throw new WC_Stripe_Exception( print_r( $response, true ), $message );
178
+				throw new WC_Stripe_Exception(print_r($response, true), $message);
179 179
 			}
180 180
 
181
-			do_action( 'wc_gateway_stripe_process_redirect_payment', $response, $order );
181
+			do_action('wc_gateway_stripe_process_redirect_payment', $response, $order);
182 182
 
183
-			$this->process_response( $response, $order );
183
+			$this->process_response($response, $order);
184 184
 
185
-		} catch ( WC_Stripe_Exception $e ) {
186
-			WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() );
185
+		} catch (WC_Stripe_Exception $e) {
186
+			WC_Stripe_Logger::log('Error: ' . $e->getMessage());
187 187
 
188
-			do_action( 'wc_gateway_stripe_process_redirect_payment_error', $e, $order );
188
+			do_action('wc_gateway_stripe_process_redirect_payment_error', $e, $order);
189 189
 
190 190
 			/* translators: error message */
191
-			$order->update_status( 'failed', sprintf( __( 'Stripe payment failed: %s', 'woocommerce-gateway-stripe' ), $e->getLocalizedMessage() ) );
191
+			$order->update_status('failed', sprintf(__('Stripe payment failed: %s', 'woocommerce-gateway-stripe'), $e->getLocalizedMessage()));
192 192
 
193
-			if ( $order->has_status( array( 'pending', 'failed' ) ) ) {
194
-				$this->send_failed_order_email( $order_id );
193
+			if ($order->has_status(array('pending', 'failed'))) {
194
+				$this->send_failed_order_email($order_id);
195 195
 			}
196 196
 
197
-			wc_add_notice( $e->getLocalizedMessage(), 'error' );
198
-			wp_safe_redirect( wc_get_checkout_url() );
197
+			wc_add_notice($e->getLocalizedMessage(), 'error');
198
+			wp_safe_redirect(wc_get_checkout_url());
199 199
 			exit;
200 200
 		}
201 201
 	}
@@ -207,13 +207,13 @@  discard block
 block discarded – undo
207 207
 	 * @version 4.0.0
208 208
 	 */
209 209
 	public function maybe_process_redirect_order() {
210
-		if ( ! is_order_received_page() || empty( $_GET['client_secret'] ) || empty( $_GET['source'] ) ) {
210
+		if ( ! is_order_received_page() || empty($_GET['client_secret']) || empty($_GET['source'])) {
211 211
 			return;
212 212
 		}
213 213
 
214
-		$order_id = wc_clean( $_GET['order_id'] );
214
+		$order_id = wc_clean($_GET['order_id']);
215 215
 
216
-		$this->process_redirect_payment( $order_id );
216
+		$this->process_redirect_payment($order_id);
217 217
 	}
218 218
 
219 219
 	/**
@@ -223,52 +223,52 @@  discard block
 block discarded – undo
223 223
 	 * @version 4.0.0
224 224
 	 * @param  int $order_id
225 225
 	 */
226
-	public function capture_payment( $order_id ) {
227
-		$order = wc_get_order( $order_id );
226
+	public function capture_payment($order_id) {
227
+		$order = wc_get_order($order_id);
228 228
 
229
-		if ( 'stripe' === ( WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method() ) ) {
230
-			$charge   = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_transaction_id', true ) : $order->get_transaction_id();
231
-			$captured = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_stripe_charge_captured', true ) : $order->get_meta( '_stripe_charge_captured', true );
229
+		if ('stripe' === (WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method())) {
230
+			$charge   = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_transaction_id', true) : $order->get_transaction_id();
231
+			$captured = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_stripe_charge_captured', true) : $order->get_meta('_stripe_charge_captured', true);
232 232
 
233
-			if ( $charge && 'no' === $captured ) {
233
+			if ($charge && 'no' === $captured) {
234 234
 				$order_total = $order->get_total();
235 235
 
236
-				if ( 0 < $order->get_total_refunded() ) {
236
+				if (0 < $order->get_total_refunded()) {
237 237
 					$order_total = $order_total - $order->get_total_refunded();
238 238
 				}
239 239
 
240
-				$result = WC_Stripe_API::request( array(
241
-					'amount'   => WC_Stripe_Helper::get_stripe_amount( $order_total ),
240
+				$result = WC_Stripe_API::request(array(
241
+					'amount'   => WC_Stripe_Helper::get_stripe_amount($order_total),
242 242
 					'expand[]' => 'balance_transaction',
243
-				), 'charges/' . $charge . '/capture' );
243
+				), 'charges/' . $charge . '/capture');
244 244
 
245
-				if ( ! empty( $result->error ) ) {
245
+				if ( ! empty($result->error)) {
246 246
 					/* translators: error message */
247
-					$order->update_status( 'failed', sprintf( __( 'Unable to capture charge! %s', 'woocommerce-gateway-stripe' ), $result->error->message ) );
247
+					$order->update_status('failed', sprintf(__('Unable to capture charge! %s', 'woocommerce-gateway-stripe'), $result->error->message));
248 248
 				} else {
249 249
 					/* translators: transaction id */
250
-					$order->add_order_note( sprintf( __( 'Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe' ), $result->id ) );
251
-					WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, '_stripe_charge_captured', 'yes' ) : $order->update_meta_data( '_stripe_charge_captured', 'yes' );
250
+					$order->add_order_note(sprintf(__('Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe'), $result->id));
251
+					WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, '_stripe_charge_captured', 'yes') : $order->update_meta_data('_stripe_charge_captured', 'yes');
252 252
 
253 253
 					// Store other data such as fees
254
-					WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, '_transaction_id', $result->id ) : $order->set_transaction_id( $result->id );
254
+					WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, '_transaction_id', $result->id) : $order->set_transaction_id($result->id);
255 255
 
256
-					if ( isset( $result->balance_transaction ) && isset( $result->balance_transaction->fee ) ) {
256
+					if (isset($result->balance_transaction) && isset($result->balance_transaction->fee)) {
257 257
 						// Fees and Net needs to both come from Stripe to be accurate as the returned
258 258
 						// values are in the local currency of the Stripe account, not from WC.
259
-						$fee = ! empty( $result->balance_transaction->fee ) ? WC_Stripe_Helper::format_balance_fee( $result->balance_transaction, 'fee' ) : 0;
260
-						$net = ! empty( $result->balance_transaction->net ) ? WC_Stripe_Helper::format_balance_fee( $result->balance_transaction, 'net' ) : 0;
261
-						WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, parent::META_NAME_FEE, $fee ) : $order->update_meta_data( parent::META_NAME_FEE, $fee );
262
-						WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, parent::META_NAME_NET, $net ) : $order->update_meta_data( parent::META_NAME_NET, $net );
259
+						$fee = ! empty($result->balance_transaction->fee) ? WC_Stripe_Helper::format_balance_fee($result->balance_transaction, 'fee') : 0;
260
+						$net = ! empty($result->balance_transaction->net) ? WC_Stripe_Helper::format_balance_fee($result->balance_transaction, 'net') : 0;
261
+						WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, parent::META_NAME_FEE, $fee) : $order->update_meta_data(parent::META_NAME_FEE, $fee);
262
+						WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, parent::META_NAME_NET, $net) : $order->update_meta_data(parent::META_NAME_NET, $net);
263 263
 					}
264 264
 
265
-					if ( is_callable( array( $order, 'save' ) ) ) {
265
+					if (is_callable(array($order, 'save'))) {
266 266
 						$order->save();
267 267
 					}
268 268
 				}
269 269
 
270 270
 				// This hook fires when admin manually changes order status to processing or completed.
271
-				do_action( 'woocommerce_stripe_process_manual_capture', $order, $result );
271
+				do_action('woocommerce_stripe_process_manual_capture', $order, $result);
272 272
 			}
273 273
 		}
274 274
 	}
@@ -280,14 +280,14 @@  discard block
 block discarded – undo
280 280
 	 * @version 4.0.0
281 281
 	 * @param  int $order_id
282 282
 	 */
283
-	public function cancel_payment( $order_id ) {
284
-		$order = wc_get_order( $order_id );
283
+	public function cancel_payment($order_id) {
284
+		$order = wc_get_order($order_id);
285 285
 
286
-		if ( 'stripe' === ( WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method() ) ) {
287
-			$this->process_refund( $order_id );
286
+		if ('stripe' === (WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method())) {
287
+			$this->process_refund($order_id);
288 288
 
289 289
 			// This hook fires when admin manually changes order status to cancel.
290
-			do_action( 'woocommerce_stripe_process_manual_cancel', $order );
290
+			do_action('woocommerce_stripe_process_manual_cancel', $order);
291 291
 		}
292 292
 	}
293 293
 
@@ -299,21 +299,21 @@  discard block
 block discarded – undo
299 299
 	 * @param string $field
300 300
 	 * @return string $error_field
301 301
 	 */
302
-	public function normalize_field( $field ) {
302
+	public function normalize_field($field) {
303 303
 		$checkout_fields = WC()->checkout->get_checkout_fields();
304 304
 		$org_str         = array();
305 305
 		$replace_str     = array();
306 306
 
307
-		if ( array_key_exists( $field, $checkout_fields['billing'] ) ) {
308
-			$error_field = __( 'Billing', 'woocommerce-gateway-stripe' ) . ' ' . $checkout_fields['billing'][ $field ]['label'];
309
-		} elseif ( array_key_exists( $field, $checkout_fields['shipping'] ) ) {
310
-			$error_field = __( 'Shipping', 'woocommerce-gateway-stripe' ) . ' ' . $checkout_fields['shipping'][ $field ]['label'];
311
-		} elseif ( array_key_exists( $field, $checkout_fields['order'] ) ) {
312
-			$error_field = $checkout_fields['order'][ $field ]['label'];
313
-		} elseif ( array_key_exists( $field, $checkout_fields['account'] ) ) {
314
-			$error_field = $checkout_fields['account'][ $field ]['label'];
307
+		if (array_key_exists($field, $checkout_fields['billing'])) {
308
+			$error_field = __('Billing', 'woocommerce-gateway-stripe') . ' ' . $checkout_fields['billing'][$field]['label'];
309
+		} elseif (array_key_exists($field, $checkout_fields['shipping'])) {
310
+			$error_field = __('Shipping', 'woocommerce-gateway-stripe') . ' ' . $checkout_fields['shipping'][$field]['label'];
311
+		} elseif (array_key_exists($field, $checkout_fields['order'])) {
312
+			$error_field = $checkout_fields['order'][$field]['label'];
313
+		} elseif (array_key_exists($field, $checkout_fields['account'])) {
314
+			$error_field = $checkout_fields['account'][$field]['label'];
315 315
 		} else {
316
-			$error_field = str_replace( '_', ' ', $field );
316
+			$error_field = str_replace('_', ' ', $field);
317 317
 
318 318
 			$org_str[]     = 'stripe';
319 319
 			$replace_str[] = '';
@@ -328,9 +328,9 @@  discard block
 block discarded – undo
328 328
 			$replace_str[] = 'SOFORT';
329 329
 
330 330
 			$org_str[]     = 'owner';
331
-			$replace_str[] = __( 'Owner', 'woocommerce-gateway-stripe' );
331
+			$replace_str[] = __('Owner', 'woocommerce-gateway-stripe');
332 332
 
333
-			$error_field   = str_replace( $org_str, $replace_str, $error_field );
333
+			$error_field   = str_replace($org_str, $replace_str, $error_field);
334 334
 		}
335 335
 
336 336
 		return $error_field;
@@ -343,135 +343,135 @@  discard block
 block discarded – undo
343 343
 	 * @version 4.0.0
344 344
 	 */
345 345
 	public function validate_checkout() {
346
-		if ( ! wp_verify_nonce( $_POST['nonce'], '_wc_stripe_nonce' ) ) {
347
-			wp_die( __( 'Cheatin&#8217; huh?', 'woocommerce-gateway-stripe' ) );
346
+		if ( ! wp_verify_nonce($_POST['nonce'], '_wc_stripe_nonce')) {
347
+			wp_die(__('Cheatin&#8217; huh?', 'woocommerce-gateway-stripe'));
348 348
 		}
349 349
 
350
-		parse_str( $_POST['required_fields'], $required_fields );
351
-		parse_str( $_POST['all_fields'], $all_fields );
350
+		parse_str($_POST['required_fields'], $required_fields);
351
+		parse_str($_POST['all_fields'], $all_fields);
352 352
 		$validate_shipping_fields = false;
353 353
 		$create_account           = false;
354 354
 		$errors                   = new WP_Error();
355
-		$all_fields               = apply_filters( 'wc_stripe_validate_checkout_all_fields', $all_fields );
356
-		$required_fields          = apply_filters( 'wc_stripe_validate_checkout_required_fields', $required_fields );
355
+		$all_fields               = apply_filters('wc_stripe_validate_checkout_all_fields', $all_fields);
356
+		$required_fields          = apply_filters('wc_stripe_validate_checkout_required_fields', $required_fields);
357 357
 
358
-		array_walk_recursive( $required_fields, 'wc_clean' );
359
-		array_walk_recursive( $all_fields, 'wc_clean' );
358
+		array_walk_recursive($required_fields, 'wc_clean');
359
+		array_walk_recursive($all_fields, 'wc_clean');
360 360
 
361 361
 		/**
362 362
 		 * If ship to different address checkbox is checked then we need
363 363
 		 * to validate shipping fields too.
364 364
 		 */
365
-		if ( isset( $all_fields['ship_to_different_address'] ) ) {
365
+		if (isset($all_fields['ship_to_different_address'])) {
366 366
 			$validate_shipping_fields = true;
367 367
 		}
368 368
 
369 369
 		// Check if createaccount is checked.
370
-		if ( isset( $all_fields['createaccount'] ) ) {
370
+		if (isset($all_fields['createaccount'])) {
371 371
 			$create_account = true;
372 372
 		}
373 373
 
374 374
 		// Check if required fields are empty.
375
-		foreach ( $required_fields as $field => $field_value ) {
375
+		foreach ($required_fields as $field => $field_value) {
376 376
 			// Check for shipping field.
377
-			if ( preg_match( '/^shipping_/', $field ) && ! $validate_shipping_fields ) {
377
+			if (preg_match('/^shipping_/', $field) && ! $validate_shipping_fields) {
378 378
 				continue;
379 379
 			}
380 380
 
381 381
 			// Check create account name.
382
-			if ( 'account_username' === $field && ! $create_account ) {
382
+			if ('account_username' === $field && ! $create_account) {
383 383
 				continue;
384 384
 			}
385 385
 
386 386
 			// Check create account password.
387
-			if ( 'account_password' === $field && ! $create_account ) {
387
+			if ('account_password' === $field && ! $create_account) {
388 388
 				continue;
389 389
 			}
390 390
 
391
-			if ( empty( $field_value ) || '-1' === $field_value ) {
392
-				$error_field = $this->normalize_field( $field );
391
+			if (empty($field_value) || '-1' === $field_value) {
392
+				$error_field = $this->normalize_field($field);
393 393
 				/* translators: error field name */
394
-				$errors->add( 'validation', sprintf( __( '<strong>%s</strong> cannot be empty', 'woocommerce-gateway-stripe' ), $error_field ) );
394
+				$errors->add('validation', sprintf(__('<strong>%s</strong> cannot be empty', 'woocommerce-gateway-stripe'), $error_field));
395 395
 			}
396 396
 		}
397 397
 
398 398
 		// Check if email is valid format.
399
-		if ( ! empty( $required_fields['billing_email'] ) && ! is_email( $required_fields['billing_email'] ) ) {
400
-			$errors->add( 'validation', __( '<strong>Billing Email</strong> is not valid', 'woocommerce-gateway-stripe' ) );
399
+		if ( ! empty($required_fields['billing_email']) && ! is_email($required_fields['billing_email'])) {
400
+			$errors->add('validation', __('<strong>Billing Email</strong> is not valid', 'woocommerce-gateway-stripe'));
401 401
 		}
402 402
 
403 403
 		// Check if phone number is valid format.
404
-		if ( ! empty( $required_fields['billing_phone'] ) ) {
405
-			$phone = wc_format_phone_number( $required_fields['billing_phone'] );
404
+		if ( ! empty($required_fields['billing_phone'])) {
405
+			$phone = wc_format_phone_number($required_fields['billing_phone']);
406 406
 
407
-			if ( '' !== $phone && ! WC_Validation::is_phone( $phone ) ) {
407
+			if ('' !== $phone && ! WC_Validation::is_phone($phone)) {
408 408
 				/* translators: %s: phone number */
409
-				$errors->add( 'validation', __( 'Please enter a valid phone number.', 'woocommerce-gateway-stripe' ) );
409
+				$errors->add('validation', __('Please enter a valid phone number.', 'woocommerce-gateway-stripe'));
410 410
 			}
411 411
 		}
412 412
 
413 413
 		// Check if postal code is valid format.
414
-		if ( ! empty( $required_fields['billing_postcode'] ) ) {
415
-			$country = isset( $required_fields['billing_country'] ) ? $required_fields['billing_country'] : WC()->customer->get_billing_country();
416
-			$postcode = wc_format_postcode( $required_fields['billing_postcode'], $country );
414
+		if ( ! empty($required_fields['billing_postcode'])) {
415
+			$country = isset($required_fields['billing_country']) ? $required_fields['billing_country'] : WC()->customer->get_billing_country();
416
+			$postcode = wc_format_postcode($required_fields['billing_postcode'], $country);
417 417
 
418
-			if ( '' !== $required_fields['billing_postcode'] && ! WC_Validation::is_postcode( $postcode, $country ) ) {
419
-				$errors->add( 'validation', __( 'Please enter a valid billing postcode / ZIP.', 'woocommerce-gateway-stripe' ) );
418
+			if ('' !== $required_fields['billing_postcode'] && ! WC_Validation::is_postcode($postcode, $country)) {
419
+				$errors->add('validation', __('Please enter a valid billing postcode / ZIP.', 'woocommerce-gateway-stripe'));
420 420
 			}
421 421
 		}
422 422
 
423
-		if ( WC()->cart->needs_shipping() && $validate_shipping_fields ) {
423
+		if (WC()->cart->needs_shipping() && $validate_shipping_fields) {
424 424
 			// Check if postal code is valid format.
425
-			if ( ! empty( $required_fields['shipping_postcode'] ) ) {
426
-				$country = isset( $required_fields['shipping_country'] ) ? $required_fields['shipping_country'] : WC()->customer->get_shipping_country();
427
-				$postcode = wc_format_postcode( $required_fields['shipping_postcode'], $country );
425
+			if ( ! empty($required_fields['shipping_postcode'])) {
426
+				$country = isset($required_fields['shipping_country']) ? $required_fields['shipping_country'] : WC()->customer->get_shipping_country();
427
+				$postcode = wc_format_postcode($required_fields['shipping_postcode'], $country);
428 428
 
429
-				if ( '' !== $required_fields['shipping_postcode'] && ! WC_Validation::is_postcode( $postcode, $country ) ) {
430
-					$errors->add( 'validation', __( 'Please enter a valid shipping postcode / ZIP.', 'woocommerce-gateway-stripe' ) );
429
+				if ('' !== $required_fields['shipping_postcode'] && ! WC_Validation::is_postcode($postcode, $country)) {
430
+					$errors->add('validation', __('Please enter a valid shipping postcode / ZIP.', 'woocommerce-gateway-stripe'));
431 431
 				}
432 432
 			}
433 433
 		}
434 434
 
435
-		if ( WC()->cart->needs_shipping() ) {
435
+		if (WC()->cart->needs_shipping()) {
436 436
 			$shipping_country = WC()->customer->get_shipping_country();
437 437
 
438
-			if ( empty( $shipping_country ) ) {
439
-				$errors->add( 'shipping', __( 'Please enter an address to continue.', 'woocommerce-gateway-stripe' ) );
440
-			} elseif ( ! in_array( WC()->customer->get_shipping_country(), array_keys( WC()->countries->get_shipping_countries() ) ) ) {
438
+			if (empty($shipping_country)) {
439
+				$errors->add('shipping', __('Please enter an address to continue.', 'woocommerce-gateway-stripe'));
440
+			} elseif ( ! in_array(WC()->customer->get_shipping_country(), array_keys(WC()->countries->get_shipping_countries()))) {
441 441
 				/* translators: country name */
442
-				$errors->add( 'shipping', sprintf( __( 'Unfortunately <strong>we do not ship %s</strong>. Please enter an alternative shipping address.', 'woocommerce-gateway-stripe' ), WC()->countries->shipping_to_prefix() . ' ' . WC()->customer->get_shipping_country() ) );
442
+				$errors->add('shipping', sprintf(__('Unfortunately <strong>we do not ship %s</strong>. Please enter an alternative shipping address.', 'woocommerce-gateway-stripe'), WC()->countries->shipping_to_prefix() . ' ' . WC()->customer->get_shipping_country()));
443 443
 			} else {
444
-				$chosen_shipping_methods = WC()->session->get( 'chosen_shipping_methods' );
444
+				$chosen_shipping_methods = WC()->session->get('chosen_shipping_methods');
445 445
 
446
-				foreach ( WC()->shipping->get_packages() as $i => $package ) {
447
-					if ( ! isset( $chosen_shipping_methods[ $i ], $package['rates'][ $chosen_shipping_methods[ $i ] ] ) ) {
448
-						$errors->add( 'shipping', __( 'No shipping method has been selected. Please double check your address, or contact us if you need any help.', 'woocommerce-gateway-stripe' ) );
446
+				foreach (WC()->shipping->get_packages() as $i => $package) {
447
+					if ( ! isset($chosen_shipping_methods[$i], $package['rates'][$chosen_shipping_methods[$i]])) {
448
+						$errors->add('shipping', __('No shipping method has been selected. Please double check your address, or contact us if you need any help.', 'woocommerce-gateway-stripe'));
449 449
 					}
450 450
 				}
451 451
 			}
452 452
 		}
453 453
 
454
-		if ( WC()->cart->needs_payment() ) {
454
+		if (WC()->cart->needs_payment()) {
455 455
 			$available_gateways = WC()->payment_gateways->get_available_payment_gateways();
456 456
 
457
-			if ( ! isset( $available_gateways[ $all_fields['payment_method'] ] ) ) {
458
-				$errors->add( 'payment', __( 'Invalid payment method.', 'woocommerce-gateway-stripe' ) );
457
+			if ( ! isset($available_gateways[$all_fields['payment_method']])) {
458
+				$errors->add('payment', __('Invalid payment method.', 'woocommerce-gateway-stripe'));
459 459
 			} else {
460
-				$available_gateways[ $all_fields['payment_method'] ]->validate_fields();
460
+				$available_gateways[$all_fields['payment_method']]->validate_fields();
461 461
 			}
462 462
 		}
463 463
 
464
-		if ( empty( $all_fields['woocommerce_checkout_update_totals'] ) && empty( $all_fields['terms'] ) && apply_filters( 'woocommerce_checkout_show_terms', wc_get_page_id( 'terms' ) > 0 ) ) {
465
-			$errors->add( 'terms', __( 'You must accept our Terms &amp; Conditions.', 'woocommerce-gateway-stripe' ) );
464
+		if (empty($all_fields['woocommerce_checkout_update_totals']) && empty($all_fields['terms']) && apply_filters('woocommerce_checkout_show_terms', wc_get_page_id('terms') > 0)) {
465
+			$errors->add('terms', __('You must accept our Terms &amp; Conditions.', 'woocommerce-gateway-stripe'));
466 466
 		}
467 467
 
468
-		do_action( 'wc_stripe_validate_checkout', $required_fields, $all_fields, $errors );
468
+		do_action('wc_stripe_validate_checkout', $required_fields, $all_fields, $errors);
469 469
 
470
-		if ( 0 === count( $errors->errors ) ) {
471
-			wp_send_json( 'success' );
470
+		if (0 === count($errors->errors)) {
471
+			wp_send_json('success');
472 472
 		} else {
473
-			foreach ( $errors->get_error_messages() as $message ) {
474
-				wc_add_notice( $message, 'error' );
473
+			foreach ($errors->get_error_messages() as $message) {
474
+				wc_add_notice($message, 'error');
475 475
 			}
476 476
 
477 477
 			$this->send_ajax_failure_response();
@@ -485,9 +485,9 @@  discard block
 block discarded – undo
485 485
 	 * @version 4.0.0
486 486
 	 */
487 487
 	public function send_ajax_failure_response() {
488
-		if ( is_ajax() ) {
488
+		if (is_ajax()) {
489 489
 			// only print notices if not reloading the checkout, otherwise they're lost in the page reload.
490
-			if ( ! isset( WC()->session->reload_checkout ) ) {
490
+			if ( ! isset(WC()->session->reload_checkout)) {
491 491
 				ob_start();
492 492
 				wc_print_notices();
493 493
 				$messages = ob_get_clean();
@@ -495,14 +495,14 @@  discard block
 block discarded – undo
495 495
 
496 496
 			$response = array(
497 497
 				'result'   => 'failure',
498
-				'messages' => isset( $messages ) ? $messages : '',
499
-				'refresh'  => isset( WC()->session->refresh_totals ),
500
-				'reload'   => isset( WC()->session->reload_checkout ),
498
+				'messages' => isset($messages) ? $messages : '',
499
+				'refresh'  => isset(WC()->session->refresh_totals),
500
+				'reload'   => isset(WC()->session->reload_checkout),
501 501
 			);
502 502
 
503
-			unset( WC()->session->refresh_totals, WC()->session->reload_checkout );
503
+			unset(WC()->session->refresh_totals, WC()->session->reload_checkout);
504 504
 
505
-			wp_send_json( $response );
505
+			wp_send_json($response);
506 506
 		}
507 507
 	}
508 508
 }
Please login to merge, or discard this patch.
includes/payment-methods/class-wc-stripe-payment-request.php 2 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -104,7 +104,7 @@
 block discarded – undo
104 104
 	 * Get this instance.
105 105
 	 *
106 106
 	 * @since 4.0.6
107
-	 * @return class
107
+	 * @return WC_Stripe_Payment_Request
108 108
 	 */
109 109
 	public static function instance() {
110 110
 		return self::$_this;
Please login to merge, or discard this patch.
Spacing   +279 added lines, -279 removed lines patch added patch discarded remove patch
@@ -6,7 +6,7 @@  discard block
 block discarded – undo
6 6
  * @since   4.0.0
7 7
  */
8 8
 
9
-if ( ! defined( 'ABSPATH' ) ) {
9
+if ( ! defined('ABSPATH')) {
10 10
 	exit;
11 11
 }
12 12
 
@@ -64,39 +64,39 @@  discard block
 block discarded – undo
64 64
 	 */
65 65
 	public function __construct() {
66 66
 		self::$_this                   = $this;
67
-		$this->stripe_settings         = get_option( 'woocommerce_stripe_settings', array() );
68
-		$this->testmode                = ( ! empty( $this->stripe_settings['testmode'] ) && 'yes' === $this->stripe_settings['testmode'] ) ? true : false;
69
-		$this->publishable_key         = ! empty( $this->stripe_settings['publishable_key'] ) ? $this->stripe_settings['publishable_key'] : '';
70
-		$this->stripe_checkout_enabled = isset( $this->stripe_settings['stripe_checkout'] ) && 'yes' === $this->stripe_settings['stripe_checkout'];
71
-		$this->total_label             = ! empty( $this->stripe_settings['statement_descriptor'] ) ? WC_Stripe_Helper::clean_statement_descriptor( $this->stripe_settings['statement_descriptor'] ) : '';
72
-
73
-		if ( $this->testmode ) {
74
-			$this->publishable_key = ! empty( $this->stripe_settings['test_publishable_key'] ) ? $this->stripe_settings['test_publishable_key'] : '';
67
+		$this->stripe_settings         = get_option('woocommerce_stripe_settings', array());
68
+		$this->testmode                = ( ! empty($this->stripe_settings['testmode']) && 'yes' === $this->stripe_settings['testmode']) ? true : false;
69
+		$this->publishable_key         = ! empty($this->stripe_settings['publishable_key']) ? $this->stripe_settings['publishable_key'] : '';
70
+		$this->stripe_checkout_enabled = isset($this->stripe_settings['stripe_checkout']) && 'yes' === $this->stripe_settings['stripe_checkout'];
71
+		$this->total_label             = ! empty($this->stripe_settings['statement_descriptor']) ? WC_Stripe_Helper::clean_statement_descriptor($this->stripe_settings['statement_descriptor']) : '';
72
+
73
+		if ($this->testmode) {
74
+			$this->publishable_key = ! empty($this->stripe_settings['test_publishable_key']) ? $this->stripe_settings['test_publishable_key'] : '';
75 75
 		}
76 76
 
77 77
 		// If both site title and statement descriptor is not set. Fallback.
78
-		if ( empty( $this->total_label ) ) {
78
+		if (empty($this->total_label)) {
79 79
 			$this->total_label = $_SERVER['SERVER_NAME'];
80 80
 		}
81 81
 
82
-		$this->total_label = str_replace( "'", '', $this->total_label ) . apply_filters( 'wc_stripe_payment_request_total_label_suffix', ' (via WooCommerce)' );
82
+		$this->total_label = str_replace("'", '', $this->total_label) . apply_filters('wc_stripe_payment_request_total_label_suffix', ' (via WooCommerce)');
83 83
 
84 84
 		// Checks if Stripe Gateway is enabled.
85
-		if ( empty( $this->stripe_settings ) || ( isset( $this->stripe_settings['enabled'] ) && 'yes' !== $this->stripe_settings['enabled'] ) ) {
85
+		if (empty($this->stripe_settings) || (isset($this->stripe_settings['enabled']) && 'yes' !== $this->stripe_settings['enabled'])) {
86 86
 			return;
87 87
 		}
88 88
 
89 89
 		// Checks if Payment Request is enabled.
90
-		if ( ! isset( $this->stripe_settings['payment_request'] ) || 'yes' !== $this->stripe_settings['payment_request'] ) {
90
+		if ( ! isset($this->stripe_settings['payment_request']) || 'yes' !== $this->stripe_settings['payment_request']) {
91 91
 			return;
92 92
 		}
93 93
 
94 94
 		// Don't load for change payment method page.
95
-		if ( isset( $_GET['change_payment_method'] ) ) {
95
+		if (isset($_GET['change_payment_method'])) {
96 96
 			return;
97 97
 		}
98 98
 
99
-		add_action( 'woocommerce_init', array( $this, 'set_session' ) );
99
+		add_action('woocommerce_init', array($this, 'set_session'));
100 100
 		$this->init();
101 101
 	}
102 102
 
@@ -117,15 +117,15 @@  discard block
 block discarded – undo
117 117
 	 * @since 4.0.0
118 118
 	 */
119 119
 	public function set_session() {
120
-		if ( ! is_user_logged_in() ) {
120
+		if ( ! is_user_logged_in()) {
121 121
 			$wc_session = new WC_Session_Handler();
122 122
 
123
-			if ( version_compare( WC_VERSION, '3.3', '>=' ) ) {
123
+			if (version_compare(WC_VERSION, '3.3', '>=')) {
124 124
 				$wc_session->init();
125 125
 			}
126 126
 
127
-			if ( ! $wc_session->has_session() ) {
128
-				$wc_session->set_customer_session_cookie( true );
127
+			if ( ! $wc_session->has_session()) {
128
+				$wc_session->set_customer_session_cookie(true);
129 129
 			}
130 130
 		}
131 131
 	}
@@ -137,40 +137,40 @@  discard block
 block discarded – undo
137 137
 	 * @version 4.0.0
138 138
 	 */
139 139
 	public function init() {
140
-		add_action( 'wp_enqueue_scripts', array( $this, 'scripts' ) );
140
+		add_action('wp_enqueue_scripts', array($this, 'scripts'));
141 141
 
142 142
 		/*
143 143
 		 * In order to display the Payment Request button in the correct position,
144 144
 		 * a new hook was added to WooCommerce 3.0. In older versions of WooCommerce,
145 145
 		 * CSS is used to position the button.
146 146
 		 */
147
-		if ( WC_Stripe_Helper::is_pre_30() ) {
148
-			add_action( 'woocommerce_after_add_to_cart_button', array( $this, 'display_payment_request_button_html' ), 1 );
149
-			add_action( 'woocommerce_after_add_to_cart_button', array( $this, 'display_payment_request_button_separator_html' ), 2 );
147
+		if (WC_Stripe_Helper::is_pre_30()) {
148
+			add_action('woocommerce_after_add_to_cart_button', array($this, 'display_payment_request_button_html'), 1);
149
+			add_action('woocommerce_after_add_to_cart_button', array($this, 'display_payment_request_button_separator_html'), 2);
150 150
 		} else {
151
-			add_action( 'woocommerce_after_add_to_cart_quantity', array( $this, 'display_payment_request_button_html' ), 1 );
152
-			add_action( 'woocommerce_after_add_to_cart_quantity', array( $this, 'display_payment_request_button_separator_html' ), 2 );
151
+			add_action('woocommerce_after_add_to_cart_quantity', array($this, 'display_payment_request_button_html'), 1);
152
+			add_action('woocommerce_after_add_to_cart_quantity', array($this, 'display_payment_request_button_separator_html'), 2);
153 153
 		}
154 154
 
155
-		add_action( 'woocommerce_proceed_to_checkout', array( $this, 'display_payment_request_button_html' ), 1 );
156
-		add_action( 'woocommerce_proceed_to_checkout', array( $this, 'display_payment_request_button_separator_html' ), 2 );
155
+		add_action('woocommerce_proceed_to_checkout', array($this, 'display_payment_request_button_html'), 1);
156
+		add_action('woocommerce_proceed_to_checkout', array($this, 'display_payment_request_button_separator_html'), 2);
157 157
 
158
-		add_action( 'woocommerce_checkout_before_customer_details', array( $this, 'display_payment_request_button_html' ), 1 );
159
-		add_action( 'woocommerce_checkout_before_customer_details', array( $this, 'display_payment_request_button_separator_html' ), 2 );
158
+		add_action('woocommerce_checkout_before_customer_details', array($this, 'display_payment_request_button_html'), 1);
159
+		add_action('woocommerce_checkout_before_customer_details', array($this, 'display_payment_request_button_separator_html'), 2);
160 160
 
161
-		add_action( 'wc_ajax_wc_stripe_get_cart_details', array( $this, 'ajax_get_cart_details' ) );
162
-		add_action( 'wc_ajax_wc_stripe_get_shipping_options', array( $this, 'ajax_get_shipping_options' ) );
163
-		add_action( 'wc_ajax_wc_stripe_update_shipping_method', array( $this, 'ajax_update_shipping_method' ) );
164
-		add_action( 'wc_ajax_wc_stripe_create_order', array( $this, 'ajax_create_order' ) );
165
-		add_action( 'wc_ajax_wc_stripe_add_to_cart', array( $this, 'ajax_add_to_cart' ) );
166
-		add_action( 'wc_ajax_wc_stripe_get_selected_product_data', array( $this, 'ajax_get_selected_product_data' ) );
167
-		add_action( 'wc_ajax_wc_stripe_clear_cart', array( $this, 'ajax_clear_cart' ) );
168
-		add_action( 'wc_ajax_wc_stripe_log_errors', array( $this, 'ajax_log_errors' ) );
161
+		add_action('wc_ajax_wc_stripe_get_cart_details', array($this, 'ajax_get_cart_details'));
162
+		add_action('wc_ajax_wc_stripe_get_shipping_options', array($this, 'ajax_get_shipping_options'));
163
+		add_action('wc_ajax_wc_stripe_update_shipping_method', array($this, 'ajax_update_shipping_method'));
164
+		add_action('wc_ajax_wc_stripe_create_order', array($this, 'ajax_create_order'));
165
+		add_action('wc_ajax_wc_stripe_add_to_cart', array($this, 'ajax_add_to_cart'));
166
+		add_action('wc_ajax_wc_stripe_get_selected_product_data', array($this, 'ajax_get_selected_product_data'));
167
+		add_action('wc_ajax_wc_stripe_clear_cart', array($this, 'ajax_clear_cart'));
168
+		add_action('wc_ajax_wc_stripe_log_errors', array($this, 'ajax_log_errors'));
169 169
 
170
-		add_filter( 'woocommerce_gateway_title', array( $this, 'filter_gateway_title' ), 10, 2 );
171
-		add_filter( 'woocommerce_validate_postcode', array( $this, 'postal_code_validation' ), 10, 3 );
170
+		add_filter('woocommerce_gateway_title', array($this, 'filter_gateway_title'), 10, 2);
171
+		add_filter('woocommerce_validate_postcode', array($this, 'postal_code_validation'), 10, 3);
172 172
 
173
-		add_action( 'woocommerce_checkout_order_processed', array( $this, 'add_order_meta' ), 10, 2 );
173
+		add_action('woocommerce_checkout_order_processed', array($this, 'add_order_meta'), 10, 2);
174 174
 	}
175 175
 
176 176
 	/**
@@ -181,7 +181,7 @@  discard block
 block discarded – undo
181 181
 	 * @return string
182 182
 	 */
183 183
 	public function get_button_type() {
184
-		return isset( $this->stripe_settings['payment_request_button_type'] ) ? $this->stripe_settings['payment_request_button_type'] : 'default';
184
+		return isset($this->stripe_settings['payment_request_button_type']) ? $this->stripe_settings['payment_request_button_type'] : 'default';
185 185
 	}
186 186
 
187 187
 	/**
@@ -192,7 +192,7 @@  discard block
 block discarded – undo
192 192
 	 * @return string
193 193
 	 */
194 194
 	public function get_button_theme() {
195
-		return isset( $this->stripe_settings['payment_request_button_theme'] ) ? $this->stripe_settings['payment_request_button_theme'] : 'dark';
195
+		return isset($this->stripe_settings['payment_request_button_theme']) ? $this->stripe_settings['payment_request_button_theme'] : 'dark';
196 196
 	}
197 197
 
198 198
 	/**
@@ -203,7 +203,7 @@  discard block
 block discarded – undo
203 203
 	 * @return string
204 204
 	 */
205 205
 	public function get_button_height() {
206
-		return isset( $this->stripe_settings['payment_request_button_height'] ) ? str_replace( 'px', '', $this->stripe_settings['payment_request_button_height'] ) : '64';
206
+		return isset($this->stripe_settings['payment_request_button_height']) ? str_replace('px', '', $this->stripe_settings['payment_request_button_height']) : '64';
207 207
 	}
208 208
 
209 209
 	/**
@@ -213,40 +213,40 @@  discard block
 block discarded – undo
213 213
 	 * @version 4.0.0
214 214
 	 */
215 215
 	public function get_product_data() {
216
-		if ( ! is_product() ) {
216
+		if ( ! is_product()) {
217 217
 			return false;
218 218
 		}
219 219
 
220 220
 		global $post;
221 221
 
222
-		$product = wc_get_product( $post->ID );
222
+		$product = wc_get_product($post->ID);
223 223
 
224 224
 		$data  = array();
225 225
 		$items = array();
226 226
 
227 227
 		$items[] = array(
228 228
 			'label'  => WC_Stripe_Helper::is_pre_30() ? $product->name : $product->get_name(),
229
-			'amount' => WC_Stripe_Helper::get_stripe_amount( WC_Stripe_Helper::is_pre_30() ? $product->price : $product->get_price() ),
229
+			'amount' => WC_Stripe_Helper::get_stripe_amount(WC_Stripe_Helper::is_pre_30() ? $product->price : $product->get_price()),
230 230
 		);
231 231
 
232
-		if ( wc_tax_enabled() ) {
232
+		if (wc_tax_enabled()) {
233 233
 			$items[] = array(
234
-				'label'   => __( 'Tax', 'woocommerce-gateway-stripe' ),
234
+				'label'   => __('Tax', 'woocommerce-gateway-stripe'),
235 235
 				'amount'  => 0,
236 236
 				'pending' => true,
237 237
 			);
238 238
 		}
239 239
 
240
-		if ( wc_shipping_enabled() && $product->needs_shipping() ) {
240
+		if (wc_shipping_enabled() && $product->needs_shipping()) {
241 241
 			$items[] = array(
242
-				'label'   => __( 'Shipping', 'woocommerce-gateway-stripe' ),
242
+				'label'   => __('Shipping', 'woocommerce-gateway-stripe'),
243 243
 				'amount'  => 0,
244 244
 				'pending' => true,
245 245
 			);
246 246
 
247
-			$data['shippingOptions']  = array(
247
+			$data['shippingOptions'] = array(
248 248
 				'id'     => 'pending',
249
-				'label'  => __( 'Pending', 'woocommerce-gateway-stripe' ),
249
+				'label'  => __('Pending', 'woocommerce-gateway-stripe'),
250 250
 				'detail' => '',
251 251
 				'amount' => 0,
252 252
 			);
@@ -254,41 +254,41 @@  discard block
 block discarded – undo
254 254
 
255 255
 		$data['displayItems'] = $items;
256 256
 		$data['total'] = array(
257
-			'label'   => apply_filters( 'wc_stripe_payment_request_total_label', $this->total_label ),
258
-			'amount'  => WC_Stripe_Helper::get_stripe_amount( WC_Stripe_Helper::is_pre_30() ? $product->price : $product->get_price() ),
257
+			'label'   => apply_filters('wc_stripe_payment_request_total_label', $this->total_label),
258
+			'amount'  => WC_Stripe_Helper::get_stripe_amount(WC_Stripe_Helper::is_pre_30() ? $product->price : $product->get_price()),
259 259
 			'pending' => true,
260 260
 		);
261 261
 
262
-		$data['requestShipping'] = ( wc_shipping_enabled() && $product->needs_shipping() );
263
-		$data['currency']        = strtolower( get_woocommerce_currency() );
264
-		$data['country_code']    = substr( get_option( 'woocommerce_default_country' ), 0, 2 );
262
+		$data['requestShipping'] = (wc_shipping_enabled() && $product->needs_shipping());
263
+		$data['currency']        = strtolower(get_woocommerce_currency());
264
+		$data['country_code']    = substr(get_option('woocommerce_default_country'), 0, 2);
265 265
 
266
-		return apply_filters( 'wc_stripe_payment_request_product_data', $data, $product );
266
+		return apply_filters('wc_stripe_payment_request_product_data', $data, $product);
267 267
 	}
268 268
 
269 269
 	/**
270 270
 	 * Filters the gateway title to reflect Payment Request type
271 271
 	 *
272 272
 	 */
273
-	public function filter_gateway_title( $title, $id ) {
273
+	public function filter_gateway_title($title, $id) {
274 274
 		global $post;
275 275
 
276
-		if ( ! is_object( $post ) ) {
276
+		if ( ! is_object($post)) {
277 277
 			return $title;
278 278
 		}
279 279
 
280
-		if ( WC_Stripe_Helper::is_pre_30() ) {
281
-			$method_title = get_post_meta( $post->ID, '_payment_method_title', true );
280
+		if (WC_Stripe_Helper::is_pre_30()) {
281
+			$method_title = get_post_meta($post->ID, '_payment_method_title', true);
282 282
 		} else {
283
-			$order        = wc_get_order( $post->ID );
284
-			$method_title = is_object( $order ) ? $order->get_payment_method_title() : '';
283
+			$order        = wc_get_order($post->ID);
284
+			$method_title = is_object($order) ? $order->get_payment_method_title() : '';
285 285
 		}
286 286
 
287
-		if ( 'stripe' === $id && ! empty( $method_title ) && 'Apple Pay (Stripe)' === $method_title ) {
287
+		if ('stripe' === $id && ! empty($method_title) && 'Apple Pay (Stripe)' === $method_title) {
288 288
 			return $method_title;
289 289
 		}
290 290
 
291
-		if ( 'stripe' === $id && ! empty( $method_title ) && 'Chrome Payment Request (Stripe)' === $method_title ) {
291
+		if ('stripe' === $id && ! empty($method_title) && 'Chrome Payment Request (Stripe)' === $method_title) {
292 292
 			return $method_title;
293 293
 		}
294 294
 
@@ -301,16 +301,16 @@  discard block
 block discarded – undo
301 301
 	 * @since 3.1.4
302 302
 	 * @version 4.0.0
303 303
 	 */
304
-	public function postal_code_validation( $valid, $postcode, $country ) {
304
+	public function postal_code_validation($valid, $postcode, $country) {
305 305
 		$gateways = WC()->payment_gateways->get_available_payment_gateways();
306 306
 
307
-		if ( ! isset( $gateways['stripe'] ) ) {
307
+		if ( ! isset($gateways['stripe'])) {
308 308
 			return $valid;
309 309
 		}
310 310
 
311
-		$payment_request_type = isset( $_POST['payment_request_type'] ) ? wc_clean( $_POST['payment_request_type'] ) : '';
311
+		$payment_request_type = isset($_POST['payment_request_type']) ? wc_clean($_POST['payment_request_type']) : '';
312 312
 
313
-		if ( 'apple_pay' !== $payment_request_type ) {
313
+		if ('apple_pay' !== $payment_request_type) {
314 314
 			return $valid;
315 315
 		}
316 316
 
@@ -320,7 +320,7 @@  discard block
 block discarded – undo
320 320
 		 * the order and not let it go through. The remedy for now is just to remove this validation.
321 321
 		 * Note that this only works with shipping providers that don't validate full postal codes.
322 322
 		 */
323
-		if ( 'GB' === $country || 'CA' === $country ) {
323
+		if ('GB' === $country || 'CA' === $country) {
324 324
 			return true;
325 325
 		}
326 326
 
@@ -335,29 +335,29 @@  discard block
 block discarded – undo
335 335
 	 * @param int $order_id
336 336
 	 * @param array $posted_data The posted data from checkout form.
337 337
 	 */
338
-	public function add_order_meta( $order_id, $posted_data ) {
339
-		if ( empty( $_POST['payment_request_type'] ) ) {
338
+	public function add_order_meta($order_id, $posted_data) {
339
+		if (empty($_POST['payment_request_type'])) {
340 340
 			return;
341 341
 		}
342 342
 
343
-		$order = wc_get_order( $order_id );
343
+		$order = wc_get_order($order_id);
344 344
 
345
-		$payment_request_type = wc_clean( $_POST['payment_request_type'] );
345
+		$payment_request_type = wc_clean($_POST['payment_request_type']);
346 346
 
347
-		if ( 'apple_pay' === $payment_request_type ) {
348
-			if ( WC_Stripe_Helper::is_pre_30() ) {
349
-				update_post_meta( $order_id, '_payment_method_title', 'Apple Pay (Stripe)' );
347
+		if ('apple_pay' === $payment_request_type) {
348
+			if (WC_Stripe_Helper::is_pre_30()) {
349
+				update_post_meta($order_id, '_payment_method_title', 'Apple Pay (Stripe)');
350 350
 			} else {
351
-				$order->set_payment_method_title( 'Apple Pay (Stripe)' );
351
+				$order->set_payment_method_title('Apple Pay (Stripe)');
352 352
 				$order->save();
353 353
 			}
354 354
 		}
355 355
 
356
-		if ( 'payment_request_api' === $payment_request_type ) {
357
-			if ( WC_Stripe_Helper::is_pre_30() ) {
358
-				update_post_meta( $order_id, '_payment_method_title', 'Chrome Payment Request (Stripe)' );
356
+		if ('payment_request_api' === $payment_request_type) {
357
+			if (WC_Stripe_Helper::is_pre_30()) {
358
+				update_post_meta($order_id, '_payment_method_title', 'Chrome Payment Request (Stripe)');
359 359
 			} else {
360
-				$order->set_payment_method_title( 'Chrome Payment Request (Stripe)' );
360
+				$order->set_payment_method_title('Chrome Payment Request (Stripe)');
361 361
 				$order->save();
362 362
 			}
363 363
 		}
@@ -371,11 +371,11 @@  discard block
 block discarded – undo
371 371
 	 * @return array
372 372
 	 */
373 373
 	public function supported_product_types() {
374
-		return apply_filters( 'wc_stripe_payment_request_supported_types', array(
374
+		return apply_filters('wc_stripe_payment_request_supported_types', array(
375 375
 			'simple',
376 376
 			'variable',
377 377
 			'variation',
378
-		) );
378
+		));
379 379
 	}
380 380
 
381 381
 	/**
@@ -386,15 +386,15 @@  discard block
 block discarded – undo
386 386
 	 * @return bool
387 387
 	 */
388 388
 	public function allowed_items_in_cart() {
389
-		foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {
390
-			$_product = apply_filters( 'woocommerce_cart_item_product', $cart_item['data'], $cart_item, $cart_item_key );
389
+		foreach (WC()->cart->get_cart() as $cart_item_key => $cart_item) {
390
+			$_product = apply_filters('woocommerce_cart_item_product', $cart_item['data'], $cart_item, $cart_item_key);
391 391
 
392
-			if ( ! in_array( ( WC_Stripe_Helper::is_pre_30() ? $_product->product_type : $_product->get_type() ), $this->supported_product_types() ) ) {
392
+			if ( ! in_array((WC_Stripe_Helper::is_pre_30() ? $_product->product_type : $_product->get_type()), $this->supported_product_types())) {
393 393
 				return false;
394 394
 			}
395 395
 
396 396
 			// Pre Orders compatbility where we don't support charge upon release.
397
-			if ( class_exists( 'WC_Pre_Orders_Order' ) && WC_Pre_Orders_Cart::cart_contains_pre_order() && WC_Pre_Orders_Product::product_is_charged_upon_release( WC_Pre_Orders_Cart::get_pre_order_product() ) ) {
397
+			if (class_exists('WC_Pre_Orders_Order') && WC_Pre_Orders_Cart::cart_contains_pre_order() && WC_Pre_Orders_Product::product_is_charged_upon_release(WC_Pre_Orders_Cart::get_pre_order_product())) {
398 398
 				return false;
399 399
 			}
400 400
 		}
@@ -409,71 +409,71 @@  discard block
 block discarded – undo
409 409
 	 * @version 4.0.0
410 410
 	 */
411 411
 	public function scripts() {
412
-		if ( ! is_product() && ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) ) {
412
+		if ( ! is_product() && ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order'])) {
413 413
 			return;
414 414
 		}
415 415
 
416
-		if ( is_product() ) {
416
+		if (is_product()) {
417 417
 			global $post;
418 418
 
419
-			$product = wc_get_product( $post->ID );
419
+			$product = wc_get_product($post->ID);
420 420
 
421
-			if ( ! is_object( $product ) || ! in_array( ( WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type() ), $this->supported_product_types() ) ) {
421
+			if ( ! is_object($product) || ! in_array((WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type()), $this->supported_product_types())) {
422 422
 				return;
423 423
 			}
424 424
 
425
-			if ( apply_filters( 'wc_stripe_hide_payment_request_on_product_page', false ) ) {
425
+			if (apply_filters('wc_stripe_hide_payment_request_on_product_page', false)) {
426 426
 				return;
427 427
 			}
428 428
 		}
429 429
 
430
-		$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
430
+		$suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';
431 431
 
432
-		wp_register_script( 'stripe', 'https://js.stripe.com/v3/', '', '3.0', true );
433
-		wp_register_script( 'wc_stripe_payment_request', plugins_url( 'assets/js/stripe-payment-request' . $suffix . '.js', WC_STRIPE_MAIN_FILE ), array( 'jquery', 'stripe' ), WC_STRIPE_VERSION, true );
432
+		wp_register_script('stripe', 'https://js.stripe.com/v3/', '', '3.0', true);
433
+		wp_register_script('wc_stripe_payment_request', plugins_url('assets/js/stripe-payment-request' . $suffix . '.js', WC_STRIPE_MAIN_FILE), array('jquery', 'stripe'), WC_STRIPE_VERSION, true);
434 434
 
435 435
 		wp_localize_script(
436 436
 			'wc_stripe_payment_request',
437 437
 			'wc_stripe_payment_request_params',
438 438
 			array(
439
-				'ajax_url' => WC_AJAX::get_endpoint( '%%endpoint%%' ),
439
+				'ajax_url' => WC_AJAX::get_endpoint('%%endpoint%%'),
440 440
 				'stripe'   => array(
441 441
 					'key'                => $this->publishable_key,
442
-					'allow_prepaid_card' => apply_filters( 'wc_stripe_allow_prepaid_card', true ) ? 'yes' : 'no',
442
+					'allow_prepaid_card' => apply_filters('wc_stripe_allow_prepaid_card', true) ? 'yes' : 'no',
443 443
 				),
444 444
 				'nonce'    => array(
445
-					'payment'                        => wp_create_nonce( 'wc-stripe-payment-request' ),
446
-					'shipping'                       => wp_create_nonce( 'wc-stripe-payment-request-shipping' ),
447
-					'update_shipping'                => wp_create_nonce( 'wc-stripe-update-shipping-method' ),
448
-					'checkout'                       => wp_create_nonce( 'woocommerce-process_checkout' ),
449
-					'add_to_cart'                    => wp_create_nonce( 'wc-stripe-add-to-cart' ),
450
-					'get_selected_product_data'      => wp_create_nonce( 'wc-stripe-get-selected-product-data' ),
451
-					'log_errors'                     => wp_create_nonce( 'wc-stripe-log-errors' ),
452
-					'clear_cart'                     => wp_create_nonce( 'wc-stripe-clear-cart' ),
445
+					'payment'                        => wp_create_nonce('wc-stripe-payment-request'),
446
+					'shipping'                       => wp_create_nonce('wc-stripe-payment-request-shipping'),
447
+					'update_shipping'                => wp_create_nonce('wc-stripe-update-shipping-method'),
448
+					'checkout'                       => wp_create_nonce('woocommerce-process_checkout'),
449
+					'add_to_cart'                    => wp_create_nonce('wc-stripe-add-to-cart'),
450
+					'get_selected_product_data'      => wp_create_nonce('wc-stripe-get-selected-product-data'),
451
+					'log_errors'                     => wp_create_nonce('wc-stripe-log-errors'),
452
+					'clear_cart'                     => wp_create_nonce('wc-stripe-clear-cart'),
453 453
 				),
454 454
 				'i18n'     => array(
455
-					'no_prepaid_card'  => __( 'Sorry, we\'re not accepting prepaid cards at this time.', 'woocommerce-gateway-stripe' ),
455
+					'no_prepaid_card'  => __('Sorry, we\'re not accepting prepaid cards at this time.', 'woocommerce-gateway-stripe'),
456 456
 					/* translators: Do not translate the [option] placeholder */
457
-					'unknown_shipping' => __( 'Unknown shipping option "[option]".', 'woocommerce-gateway-stripe' ),
457
+					'unknown_shipping' => __('Unknown shipping option "[option]".', 'woocommerce-gateway-stripe'),
458 458
 				),
459 459
 				'checkout' => array(
460 460
 					'url'            => wc_get_checkout_url(),
461
-					'currency_code'  => strtolower( get_woocommerce_currency() ),
462
-					'country_code'   => substr( get_option( 'woocommerce_default_country' ), 0, 2 ),
461
+					'currency_code'  => strtolower(get_woocommerce_currency()),
462
+					'country_code'   => substr(get_option('woocommerce_default_country'), 0, 2),
463 463
 					'needs_shipping' => WC()->cart->needs_shipping() ? 'yes' : 'no',
464 464
 				),
465 465
 				'button' => array(
466 466
 					'type'   => $this->get_button_type(),
467 467
 					'theme'  => $this->get_button_theme(),
468 468
 					'height' => $this->get_button_height(),
469
-					'locale' => substr( get_locale(), 0, 2 ), // Default format is en_US.
469
+					'locale' => substr(get_locale(), 0, 2), // Default format is en_US.
470 470
 				),
471 471
 				'is_product_page' => is_product(),
472 472
 				'product'         => $this->get_product_data(),
473 473
 			)
474 474
 		);
475 475
 
476
-		wp_enqueue_script( 'wc_stripe_payment_request' );
476
+		wp_enqueue_script('wc_stripe_payment_request');
477 477
 	}
478 478
 
479 479
 	/**
@@ -485,39 +485,39 @@  discard block
 block discarded – undo
485 485
 	public function display_payment_request_button_html() {
486 486
 		$gateways = WC()->payment_gateways->get_available_payment_gateways();
487 487
 
488
-		if ( ! isset( $gateways['stripe'] ) ) {
488
+		if ( ! isset($gateways['stripe'])) {
489 489
 			return;
490 490
 		}
491 491
 
492
-		if ( ! is_cart() && ! is_checkout() && ! is_product() && ! isset( $_GET['pay_for_order'] ) ) {
492
+		if ( ! is_cart() && ! is_checkout() && ! is_product() && ! isset($_GET['pay_for_order'])) {
493 493
 			return;
494 494
 		}
495 495
 
496
-		if ( is_product() && apply_filters( 'wc_stripe_hide_payment_request_on_product_page', false ) ) {
496
+		if (is_product() && apply_filters('wc_stripe_hide_payment_request_on_product_page', false)) {
497 497
 			return;
498 498
 		}
499 499
 
500
-		if ( is_checkout() && ! apply_filters( 'wc_stripe_show_payment_request_on_checkout', false ) ) {
500
+		if (is_checkout() && ! apply_filters('wc_stripe_show_payment_request_on_checkout', false)) {
501 501
 			return;
502 502
 		}
503 503
 
504
-		if ( is_product() ) {
504
+		if (is_product()) {
505 505
 			global $post;
506 506
 
507
-			$product = wc_get_product( $post->ID );
507
+			$product = wc_get_product($post->ID);
508 508
 
509
-			if ( ! is_object( $product ) || ! in_array( ( WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type() ), $this->supported_product_types() ) ) {
509
+			if ( ! is_object($product) || ! in_array((WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type()), $this->supported_product_types())) {
510 510
 				return;
511 511
 			}
512 512
 
513 513
 			// Pre Orders charge upon release not supported.
514
-			if ( class_exists( 'WC_Pre_Orders_Order' ) && WC_Pre_Orders_Product::product_is_charged_upon_release( $product ) ) {
515
-				WC_Stripe_Logger::log( 'Pre Order charge upon release is not supported. ( Payment Request button disabled )' );
514
+			if (class_exists('WC_Pre_Orders_Order') && WC_Pre_Orders_Product::product_is_charged_upon_release($product)) {
515
+				WC_Stripe_Logger::log('Pre Order charge upon release is not supported. ( Payment Request button disabled )');
516 516
 				return;
517 517
 			}
518 518
 		} else {
519
-			if ( ! $this->allowed_items_in_cart() ) {
520
-				WC_Stripe_Logger::log( 'Items in the cart has unsupported product type ( Payment Request button disabled )' );
519
+			if ( ! $this->allowed_items_in_cart()) {
520
+				WC_Stripe_Logger::log('Items in the cart has unsupported product type ( Payment Request button disabled )');
521 521
 				return;
522 522
 			}
523 523
 		}
@@ -539,44 +539,44 @@  discard block
 block discarded – undo
539 539
 	public function display_payment_request_button_separator_html() {
540 540
 		$gateways = WC()->payment_gateways->get_available_payment_gateways();
541 541
 
542
-		if ( ! isset( $gateways['stripe'] ) ) {
542
+		if ( ! isset($gateways['stripe'])) {
543 543
 			return;
544 544
 		}
545 545
 
546
-		if ( ! is_cart() && ! is_checkout() && ! is_product() && ! isset( $_GET['pay_for_order'] ) ) {
546
+		if ( ! is_cart() && ! is_checkout() && ! is_product() && ! isset($_GET['pay_for_order'])) {
547 547
 			return;
548 548
 		}
549 549
 
550
-		if ( is_product() && apply_filters( 'wc_stripe_hide_payment_request_on_product_page', false ) ) {
550
+		if (is_product() && apply_filters('wc_stripe_hide_payment_request_on_product_page', false)) {
551 551
 			return;
552 552
 		}
553 553
 
554
-		if ( is_checkout() && ! apply_filters( 'wc_stripe_show_payment_request_on_checkout', false ) ) {
554
+		if (is_checkout() && ! apply_filters('wc_stripe_show_payment_request_on_checkout', false)) {
555 555
 			return;
556 556
 		}
557 557
 
558
-		if ( is_product() ) {
558
+		if (is_product()) {
559 559
 			global $post;
560 560
 
561
-			$product = wc_get_product( $post->ID );
561
+			$product = wc_get_product($post->ID);
562 562
 
563
-			if ( ! is_object( $product ) || ! in_array( ( WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type() ), $this->supported_product_types() ) ) {
563
+			if ( ! is_object($product) || ! in_array((WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type()), $this->supported_product_types())) {
564 564
 				return;
565 565
 			}
566 566
 
567 567
 			// Pre Orders charge upon release not supported.
568
-			if ( class_exists( 'WC_Pre_Orders_Order' ) && WC_Pre_Orders_Product::product_is_charged_upon_release( $product ) ) {
569
-				WC_Stripe_Logger::log( 'Pre Order charge upon release is not supported. ( Payment Request button disabled )' );
568
+			if (class_exists('WC_Pre_Orders_Order') && WC_Pre_Orders_Product::product_is_charged_upon_release($product)) {
569
+				WC_Stripe_Logger::log('Pre Order charge upon release is not supported. ( Payment Request button disabled )');
570 570
 				return;
571 571
 			}
572 572
 		} else {
573
-			if ( ! $this->allowed_items_in_cart() ) {
574
-				WC_Stripe_Logger::log( 'Items in the cart has unsupported product type ( Payment Request button disabled )' );
573
+			if ( ! $this->allowed_items_in_cart()) {
574
+				WC_Stripe_Logger::log('Items in the cart has unsupported product type ( Payment Request button disabled )');
575 575
 				return;
576 576
 			}
577 577
 		}
578 578
 		?>
579
-		<p id="wc-stripe-payment-request-button-separator" style="margin-top:1.5em;text-align:center;display:none;">- <?php esc_html_e( 'OR', 'woocommerce-gateway-stripe' ); ?> -</p>
579
+		<p id="wc-stripe-payment-request-button-separator" style="margin-top:1.5em;text-align:center;display:none;">- <?php esc_html_e('OR', 'woocommerce-gateway-stripe'); ?> -</p>
580 580
 		<?php
581 581
 	}
582 582
 
@@ -587,11 +587,11 @@  discard block
 block discarded – undo
587 587
 	 * @version 4.0.0
588 588
 	 */
589 589
 	public function ajax_log_errors() {
590
-		check_ajax_referer( 'wc-stripe-log-errors', 'security' );
590
+		check_ajax_referer('wc-stripe-log-errors', 'security');
591 591
 
592
-		$errors = wc_clean( stripslashes( $_POST['errors'] ) );
592
+		$errors = wc_clean(stripslashes($_POST['errors']));
593 593
 
594
-		WC_Stripe_Logger::log( $errors );
594
+		WC_Stripe_Logger::log($errors);
595 595
 
596 596
 		exit;
597 597
 	}
@@ -603,7 +603,7 @@  discard block
 block discarded – undo
603 603
 	 * @version 4.0.0
604 604
 	 */
605 605
 	public function ajax_clear_cart() {
606
-		check_ajax_referer( 'wc-stripe-clear-cart', 'security' );
606
+		check_ajax_referer('wc-stripe-clear-cart', 'security');
607 607
 
608 608
 		WC()->cart->empty_cart();
609 609
 		exit;
@@ -613,10 +613,10 @@  discard block
 block discarded – undo
613 613
 	 * Get cart details.
614 614
 	 */
615 615
 	public function ajax_get_cart_details() {
616
-		check_ajax_referer( 'wc-stripe-payment-request', 'security' );
616
+		check_ajax_referer('wc-stripe-payment-request', 'security');
617 617
 
618
-		if ( ! defined( 'WOOCOMMERCE_CART' ) ) {
619
-			define( 'WOOCOMMERCE_CART', true );
618
+		if ( ! defined('WOOCOMMERCE_CART')) {
619
+			define('WOOCOMMERCE_CART', true);
620 620
 		}
621 621
 
622 622
 		WC()->cart->calculate_totals();
@@ -627,14 +627,14 @@  discard block
 block discarded – undo
627 627
 		$data = array(
628 628
 			'shipping_required' => WC()->cart->needs_shipping(),
629 629
 			'order_data'        => array(
630
-				'currency'        => strtolower( $currency ),
631
-				'country_code'    => substr( get_option( 'woocommerce_default_country' ), 0, 2 ),
630
+				'currency'        => strtolower($currency),
631
+				'country_code'    => substr(get_option('woocommerce_default_country'), 0, 2),
632 632
 			),
633 633
 		);
634 634
 
635 635
 		$data['order_data'] += $this->build_display_items();
636 636
 
637
-		wp_send_json( $data );
637
+		wp_send_json($data);
638 638
 	}
639 639
 
640 640
 	/**
@@ -645,47 +645,47 @@  discard block
 block discarded – undo
645 645
 	 * @see WC_Shipping::get_packages().
646 646
 	 */
647 647
 	public function ajax_get_shipping_options() {
648
-		check_ajax_referer( 'wc-stripe-payment-request-shipping', 'security' );
648
+		check_ajax_referer('wc-stripe-payment-request-shipping', 'security');
649 649
 
650 650
 		try {
651 651
 			// Set the shipping package.
652
-			$posted = filter_input_array( INPUT_POST, array(
652
+			$posted = filter_input_array(INPUT_POST, array(
653 653
 				'country'   => FILTER_SANITIZE_STRING,
654 654
 				'state'     => FILTER_SANITIZE_STRING,
655 655
 				'postcode'  => FILTER_SANITIZE_STRING,
656 656
 				'city'      => FILTER_SANITIZE_STRING,
657 657
 				'address'   => FILTER_SANITIZE_STRING,
658 658
 				'address_2' => FILTER_SANITIZE_STRING,
659
-			) );
659
+			));
660 660
 
661
-			$this->calculate_shipping( $posted );
661
+			$this->calculate_shipping($posted);
662 662
 
663 663
 			// Set the shipping options.
664 664
 			$data     = array();
665 665
 			$packages = WC()->shipping->get_packages();
666 666
 
667
-			if ( ! empty( $packages ) && WC()->customer->has_calculated_shipping() ) {
668
-				foreach ( $packages as $package_key => $package ) {
669
-					if ( empty( $package['rates'] ) ) {
670
-						throw new Exception( __( 'Unable to find shipping method for address.', 'woocommerce-gateway-stripe' ) );
667
+			if ( ! empty($packages) && WC()->customer->has_calculated_shipping()) {
668
+				foreach ($packages as $package_key => $package) {
669
+					if (empty($package['rates'])) {
670
+						throw new Exception(__('Unable to find shipping method for address.', 'woocommerce-gateway-stripe'));
671 671
 					}
672 672
 
673
-					foreach ( $package['rates'] as $key => $rate ) {
673
+					foreach ($package['rates'] as $key => $rate) {
674 674
 						$data['shipping_options'][] = array(
675 675
 							'id'       => $rate->id,
676 676
 							'label'    => $rate->label,
677 677
 							'detail'   => '',
678
-							'amount'   => WC_Stripe_Helper::get_stripe_amount( $rate->cost ),
678
+							'amount'   => WC_Stripe_Helper::get_stripe_amount($rate->cost),
679 679
 						);
680 680
 					}
681 681
 				}
682 682
 			} else {
683
-				throw new Exception( __( 'Unable to find shipping method for address.', 'woocommerce-gateway-stripe' ) );
683
+				throw new Exception(__('Unable to find shipping method for address.', 'woocommerce-gateway-stripe'));
684 684
 			}
685 685
 
686
-			if ( isset( $data[0] ) ) {
686
+			if (isset($data[0])) {
687 687
 				// Auto select the first shipping method.
688
-				WC()->session->set( 'chosen_shipping_methods', array( $data[0]['id'] ) );
688
+				WC()->session->set('chosen_shipping_methods', array($data[0]['id']));
689 689
 			}
690 690
 
691 691
 			WC()->cart->calculate_totals();
@@ -693,12 +693,12 @@  discard block
 block discarded – undo
693 693
 			$data += $this->build_display_items();
694 694
 			$data['result'] = 'success';
695 695
 
696
-			wp_send_json( $data );
697
-		} catch ( Exception $e ) {
696
+			wp_send_json($data);
697
+		} catch (Exception $e) {
698 698
 			$data += $this->build_display_items();
699 699
 			$data['result'] = 'invalid_shipping_address';
700 700
 
701
-			wp_send_json( $data );
701
+			wp_send_json($data);
702 702
 		}
703 703
 	}
704 704
 
@@ -706,22 +706,22 @@  discard block
 block discarded – undo
706 706
 	 * Update shipping method.
707 707
 	 */
708 708
 	public function ajax_update_shipping_method() {
709
-		check_ajax_referer( 'wc-stripe-update-shipping-method', 'security' );
709
+		check_ajax_referer('wc-stripe-update-shipping-method', 'security');
710 710
 
711
-		if ( ! defined( 'WOOCOMMERCE_CART' ) ) {
712
-			define( 'WOOCOMMERCE_CART', true );
711
+		if ( ! defined('WOOCOMMERCE_CART')) {
712
+			define('WOOCOMMERCE_CART', true);
713 713
 		}
714 714
 
715
-		$chosen_shipping_methods = WC()->session->get( 'chosen_shipping_methods' );
716
-		$shipping_method         = filter_input( INPUT_POST, 'shipping_method', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY );
715
+		$chosen_shipping_methods = WC()->session->get('chosen_shipping_methods');
716
+		$shipping_method         = filter_input(INPUT_POST, 'shipping_method', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY);
717 717
 
718
-		if ( is_array( $shipping_method ) ) {
719
-			foreach ( $shipping_method as $i => $value ) {
720
-				$chosen_shipping_methods[ $i ] = wc_clean( $value );
718
+		if (is_array($shipping_method)) {
719
+			foreach ($shipping_method as $i => $value) {
720
+				$chosen_shipping_methods[$i] = wc_clean($value);
721 721
 			}
722 722
 		}
723 723
 
724
-		WC()->session->set( 'chosen_shipping_methods', $chosen_shipping_methods );
724
+		WC()->session->set('chosen_shipping_methods', $chosen_shipping_methods);
725 725
 
726 726
 		WC()->cart->calculate_totals();
727 727
 
@@ -729,7 +729,7 @@  discard block
 block discarded – undo
729 729
 		$data += $this->build_display_items();
730 730
 		$data['result'] = 'success';
731 731
 
732
-		wp_send_json( $data );
732
+		wp_send_json($data);
733 733
 	}
734 734
 
735 735
 	/**
@@ -740,31 +740,31 @@  discard block
 block discarded – undo
740 740
 	 * @return array $data
741 741
 	 */
742 742
 	public function ajax_get_selected_product_data() {
743
-		check_ajax_referer( 'wc-stripe-get-selected-product-data', 'security' );
743
+		check_ajax_referer('wc-stripe-get-selected-product-data', 'security');
744 744
 
745
-		$product_id = absint( $_POST['product_id'] );
746
-		$qty = ! isset( $_POST['qty'] ) ? 1 : absint( $_POST['qty'] );
745
+		$product_id = absint($_POST['product_id']);
746
+		$qty = ! isset($_POST['qty']) ? 1 : absint($_POST['qty']);
747 747
 
748
-		$product = wc_get_product( $product_id );
748
+		$product = wc_get_product($product_id);
749 749
 
750
-		if ( 'variable' === ( WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type() ) && isset( $_POST['attributes'] ) ) {
751
-			$attributes = array_map( 'wc_clean', $_POST['attributes'] );
750
+		if ('variable' === (WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type()) && isset($_POST['attributes'])) {
751
+			$attributes = array_map('wc_clean', $_POST['attributes']);
752 752
 
753
-			if ( WC_Stripe_Helper::is_pre_30() ) {
754
-				$variation_id = $product->get_matching_variation( $attributes );
753
+			if (WC_Stripe_Helper::is_pre_30()) {
754
+				$variation_id = $product->get_matching_variation($attributes);
755 755
 			} else {
756
-				$data_store = WC_Data_Store::load( 'product' );
757
-				$variation_id = $data_store->find_matching_product_variation( $product, $attributes );
756
+				$data_store = WC_Data_Store::load('product');
757
+				$variation_id = $data_store->find_matching_product_variation($product, $attributes);
758 758
 			}
759 759
 
760
-			if ( ! empty( $variation_id ) ) {
761
-				$product = wc_get_product( $variation_id );
760
+			if ( ! empty($variation_id)) {
761
+				$product = wc_get_product($variation_id);
762 762
 			}
763
-		} elseif ( 'simple' === ( WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type() ) ) {
764
-			$product = wc_get_product( $product_id );
763
+		} elseif ('simple' === (WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type())) {
764
+			$product = wc_get_product($product_id);
765 765
 		}
766 766
 
767
-		$total = $qty * ( WC_Stripe_Helper::is_pre_30() ? $product->price : $product->get_price() );
767
+		$total = $qty * (WC_Stripe_Helper::is_pre_30() ? $product->price : $product->get_price());
768 768
 
769 769
 		$quantity_label = 1 < $qty ? ' (x' . $qty . ')' : '';
770 770
 
@@ -772,28 +772,28 @@  discard block
 block discarded – undo
772 772
 		$items = array();
773 773
 
774 774
 		$items[] = array(
775
-			'label'  => ( WC_Stripe_Helper::is_pre_30() ? $product->name : $product->get_name() ) . $quantity_label,
776
-			'amount' => WC_Stripe_Helper::get_stripe_amount( $total ),
775
+			'label'  => (WC_Stripe_Helper::is_pre_30() ? $product->name : $product->get_name()) . $quantity_label,
776
+			'amount' => WC_Stripe_Helper::get_stripe_amount($total),
777 777
 		);
778 778
 
779
-		if ( wc_tax_enabled() ) {
779
+		if (wc_tax_enabled()) {
780 780
 			$items[] = array(
781
-				'label'   => __( 'Tax', 'woocommerce-gateway-stripe' ),
781
+				'label'   => __('Tax', 'woocommerce-gateway-stripe'),
782 782
 				'amount'  => 0,
783 783
 				'pending' => true,
784 784
 			);
785 785
 		}
786 786
 
787
-		if ( wc_shipping_enabled() && $product->needs_shipping() ) {
787
+		if (wc_shipping_enabled() && $product->needs_shipping()) {
788 788
 			$items[] = array(
789
-				'label'   => __( 'Shipping', 'woocommerce-gateway-stripe' ),
789
+				'label'   => __('Shipping', 'woocommerce-gateway-stripe'),
790 790
 				'amount'  => 0,
791 791
 				'pending' => true,
792 792
 			);
793 793
 
794
-			$data['shippingOptions']  = array(
794
+			$data['shippingOptions'] = array(
795 795
 				'id'     => 'pending',
796
-				'label'  => __( 'Pending', 'woocommerce-gateway-stripe' ),
796
+				'label'  => __('Pending', 'woocommerce-gateway-stripe'),
797 797
 				'detail' => '',
798 798
 				'amount' => 0,
799 799
 			);
@@ -802,15 +802,15 @@  discard block
 block discarded – undo
802 802
 		$data['displayItems'] = $items;
803 803
 		$data['total'] = array(
804 804
 			'label'   => $this->total_label,
805
-			'amount'  => WC_Stripe_Helper::get_stripe_amount( $total ),
805
+			'amount'  => WC_Stripe_Helper::get_stripe_amount($total),
806 806
 			'pending' => true,
807 807
 		);
808 808
 
809
-		$data['requestShipping'] = ( wc_shipping_enabled() && $product->needs_shipping() );
810
-		$data['currency']        = strtolower( get_woocommerce_currency() );
811
-		$data['country_code']    = substr( get_option( 'woocommerce_default_country' ), 0, 2 );
809
+		$data['requestShipping'] = (wc_shipping_enabled() && $product->needs_shipping());
810
+		$data['currency']        = strtolower(get_woocommerce_currency());
811
+		$data['country_code']    = substr(get_option('woocommerce_default_country'), 0, 2);
812 812
 
813
-		wp_send_json( $data );
813
+		wp_send_json($data);
814 814
 	}
815 815
 
816 816
 	/**
@@ -821,37 +821,37 @@  discard block
 block discarded – undo
821 821
 	 * @return array $data
822 822
 	 */
823 823
 	public function ajax_add_to_cart() {
824
-		check_ajax_referer( 'wc-stripe-add-to-cart', 'security' );
824
+		check_ajax_referer('wc-stripe-add-to-cart', 'security');
825 825
 
826
-		if ( ! defined( 'WOOCOMMERCE_CART' ) ) {
827
-			define( 'WOOCOMMERCE_CART', true );
826
+		if ( ! defined('WOOCOMMERCE_CART')) {
827
+			define('WOOCOMMERCE_CART', true);
828 828
 		}
829 829
 
830 830
 		WC()->shipping->reset_shipping();
831 831
 
832
-		$product_id = absint( $_POST['product_id'] );
833
-		$qty = ! isset( $_POST['qty'] ) ? 1 : absint( $_POST['qty'] );
832
+		$product_id = absint($_POST['product_id']);
833
+		$qty = ! isset($_POST['qty']) ? 1 : absint($_POST['qty']);
834 834
 
835
-		$product = wc_get_product( $product_id );
835
+		$product = wc_get_product($product_id);
836 836
 
837 837
 		// First empty the cart to prevent wrong calculation.
838 838
 		WC()->cart->empty_cart();
839 839
 
840
-		if ( 'variable' === ( WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type() ) && isset( $_POST['attributes'] ) ) {
841
-			$attributes = array_map( 'wc_clean', $_POST['attributes'] );
840
+		if ('variable' === (WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type()) && isset($_POST['attributes'])) {
841
+			$attributes = array_map('wc_clean', $_POST['attributes']);
842 842
 
843
-			if ( WC_Stripe_Helper::is_pre_30() ) {
844
-				$variation_id = $product->get_matching_variation( $attributes );
843
+			if (WC_Stripe_Helper::is_pre_30()) {
844
+				$variation_id = $product->get_matching_variation($attributes);
845 845
 			} else {
846
-				$data_store = WC_Data_Store::load( 'product' );
847
-				$variation_id = $data_store->find_matching_product_variation( $product, $attributes );
846
+				$data_store = WC_Data_Store::load('product');
847
+				$variation_id = $data_store->find_matching_product_variation($product, $attributes);
848 848
 			}
849 849
 
850
-			WC()->cart->add_to_cart( $product->get_id(), $qty, $variation_id, $attributes );
850
+			WC()->cart->add_to_cart($product->get_id(), $qty, $variation_id, $attributes);
851 851
 		}
852 852
 
853
-		if ( 'simple' === ( WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type() ) ) {
854
-			WC()->cart->add_to_cart( $product->get_id(), $qty );
853
+		if ('simple' === (WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type())) {
854
+			WC()->cart->add_to_cart($product->get_id(), $qty);
855 855
 		}
856 856
 
857 857
 		WC()->cart->calculate_totals();
@@ -860,7 +860,7 @@  discard block
 block discarded – undo
860 860
 		$data += $this->build_display_items();
861 861
 		$data['result'] = 'success';
862 862
 
863
-		wp_send_json( $data );
863
+		wp_send_json($data);
864 864
 	}
865 865
 
866 866
 	/**
@@ -873,31 +873,31 @@  discard block
 block discarded – undo
873 873
 	 * @version 4.0.0
874 874
 	 */
875 875
 	public function normalize_state() {
876
-		$billing_country  = ! empty( $_POST['billing_country'] ) ? wc_clean( $_POST['billing_country'] ) : '';
877
-		$shipping_country = ! empty( $_POST['shipping_country'] ) ? wc_clean( $_POST['shipping_country'] ) : '';
878
-		$billing_state    = ! empty( $_POST['billing_state'] ) ? wc_clean( $_POST['billing_state'] ) : '';
879
-		$shipping_state   = ! empty( $_POST['shipping_state'] ) ? wc_clean( $_POST['shipping_state'] ) : '';
876
+		$billing_country  = ! empty($_POST['billing_country']) ? wc_clean($_POST['billing_country']) : '';
877
+		$shipping_country = ! empty($_POST['shipping_country']) ? wc_clean($_POST['shipping_country']) : '';
878
+		$billing_state    = ! empty($_POST['billing_state']) ? wc_clean($_POST['billing_state']) : '';
879
+		$shipping_state   = ! empty($_POST['shipping_state']) ? wc_clean($_POST['shipping_state']) : '';
880 880
 
881
-		if ( $billing_state && $billing_country ) {
882
-			$valid_states = WC()->countries->get_states( $billing_country );
881
+		if ($billing_state && $billing_country) {
882
+			$valid_states = WC()->countries->get_states($billing_country);
883 883
 
884 884
 			// Valid states found for country.
885
-			if ( ! empty( $valid_states ) && is_array( $valid_states ) && sizeof( $valid_states ) > 0 ) {
886
-				foreach ( $valid_states as $state_abbr => $state ) {
887
-					if ( preg_match( '/' . preg_quote( $state ) . '/i', $billing_state ) ) {
885
+			if ( ! empty($valid_states) && is_array($valid_states) && sizeof($valid_states) > 0) {
886
+				foreach ($valid_states as $state_abbr => $state) {
887
+					if (preg_match('/' . preg_quote($state) . '/i', $billing_state)) {
888 888
 						$_POST['billing_state'] = $state_abbr;
889 889
 					}
890 890
 				}
891 891
 			}
892 892
 		}
893 893
 
894
-		if ( $shipping_state && $shipping_country ) {
895
-			$valid_states = WC()->countries->get_states( $shipping_country );
894
+		if ($shipping_state && $shipping_country) {
895
+			$valid_states = WC()->countries->get_states($shipping_country);
896 896
 
897 897
 			// Valid states found for country.
898
-			if ( ! empty( $valid_states ) && is_array( $valid_states ) && sizeof( $valid_states ) > 0 ) {
899
-				foreach ( $valid_states as $state_abbr => $state ) {
900
-					if ( preg_match( '/' . preg_quote( $state ) . '/i', $shipping_state ) ) {
898
+			if ( ! empty($valid_states) && is_array($valid_states) && sizeof($valid_states) > 0) {
899
+				foreach ($valid_states as $state_abbr => $state) {
900
+					if (preg_match('/' . preg_quote($state) . '/i', $shipping_state)) {
901 901
 						$_POST['shipping_state'] = $state_abbr;
902 902
 					}
903 903
 				}
@@ -912,19 +912,19 @@  discard block
 block discarded – undo
912 912
 	 * @version 4.0.0
913 913
 	 */
914 914
 	public function ajax_create_order() {
915
-		if ( WC()->cart->is_empty() ) {
916
-			wp_send_json_error( __( 'Empty cart', 'woocommerce-gateway-stripe' ) );
915
+		if (WC()->cart->is_empty()) {
916
+			wp_send_json_error(__('Empty cart', 'woocommerce-gateway-stripe'));
917 917
 		}
918 918
 
919
-		if ( ! defined( 'WOOCOMMERCE_CHECKOUT' ) ) {
920
-			define( 'WOOCOMMERCE_CHECKOUT', true );
919
+		if ( ! defined('WOOCOMMERCE_CHECKOUT')) {
920
+			define('WOOCOMMERCE_CHECKOUT', true);
921 921
 		}
922 922
 
923 923
 		$this->normalize_state();
924 924
 
925 925
 		WC()->checkout()->process_checkout();
926 926
 
927
-		die( 0 );
927
+		die(0);
928 928
 	}
929 929
 
930 930
 	/**
@@ -934,7 +934,7 @@  discard block
 block discarded – undo
934 934
 	 * @version 4.0.0
935 935
 	 * @param array $address
936 936
 	 */
937
-	protected function calculate_shipping( $address = array() ) {
937
+	protected function calculate_shipping($address = array()) {
938 938
 		global $states;
939 939
 
940 940
 		$country   = $address['country'];
@@ -951,28 +951,28 @@  discard block
 block discarded – undo
951 951
 		 * In some versions of Chrome, state can be a full name. So we need
952 952
 		 * to convert that to abbreviation as WC is expecting that.
953 953
 		 */
954
-		if ( 2 < strlen( $state ) ) {
955
-			$state = array_search( ucfirst( strtolower( $state ) ), $states[ $country ] );
954
+		if (2 < strlen($state)) {
955
+			$state = array_search(ucfirst(strtolower($state)), $states[$country]);
956 956
 		}
957 957
 
958 958
 		WC()->shipping->reset_shipping();
959 959
 
960
-		if ( $postcode && WC_Validation::is_postcode( $postcode, $country ) ) {
961
-			$postcode = wc_format_postcode( $postcode, $country );
960
+		if ($postcode && WC_Validation::is_postcode($postcode, $country)) {
961
+			$postcode = wc_format_postcode($postcode, $country);
962 962
 		}
963 963
 
964
-		if ( $country ) {
965
-			WC()->customer->set_location( $country, $state, $postcode, $city );
966
-			WC()->customer->set_shipping_location( $country, $state, $postcode, $city );
964
+		if ($country) {
965
+			WC()->customer->set_location($country, $state, $postcode, $city);
966
+			WC()->customer->set_shipping_location($country, $state, $postcode, $city);
967 967
 		} else {
968 968
 			WC_Stripe_Helper::is_pre_30() ? WC()->customer->set_to_base() : WC()->customer->set_billing_address_to_base();
969 969
 			WC_Stripe_Helper::is_pre_30() ? WC()->customer->set_shipping_to_base() : WC()->customer->set_shipping_address_to_base();
970 970
 		}
971 971
 
972
-		if ( WC_Stripe_Helper::is_pre_30() ) {
973
-			WC()->customer->calculated_shipping( true );
972
+		if (WC_Stripe_Helper::is_pre_30()) {
973
+			WC()->customer->calculated_shipping(true);
974 974
 		} else {
975
-			WC()->customer->set_calculated_shipping( true );
975
+			WC()->customer->set_calculated_shipping(true);
976 976
 			WC()->customer->save();
977 977
 		}
978 978
 
@@ -989,17 +989,17 @@  discard block
 block discarded – undo
989 989
 		$packages[0]['destination']['address']   = $address_1;
990 990
 		$packages[0]['destination']['address_2'] = $address_2;
991 991
 
992
-		foreach ( WC()->cart->get_cart() as $item ) {
993
-			if ( $item['data']->needs_shipping() ) {
994
-				if ( isset( $item['line_total'] ) ) {
992
+		foreach (WC()->cart->get_cart() as $item) {
993
+			if ($item['data']->needs_shipping()) {
994
+				if (isset($item['line_total'])) {
995 995
 					$packages[0]['contents_cost'] += $item['line_total'];
996 996
 				}
997 997
 			}
998 998
 		}
999 999
 
1000
-		$packages = apply_filters( 'woocommerce_cart_shipping_packages', $packages );
1000
+		$packages = apply_filters('woocommerce_cart_shipping_packages', $packages);
1001 1001
 
1002
-		WC()->shipping->calculate_shipping( $packages );
1002
+		WC()->shipping->calculate_shipping($packages);
1003 1003
 	}
1004 1004
 
1005 1005
 	/**
@@ -1008,19 +1008,19 @@  discard block
 block discarded – undo
1008 1008
 	 * @since 3.1.0
1009 1009
 	 * @version 4.0.0
1010 1010
 	 */
1011
-	protected function build_shipping_methods( $shipping_methods ) {
1012
-		if ( empty( $shipping_methods ) ) {
1011
+	protected function build_shipping_methods($shipping_methods) {
1012
+		if (empty($shipping_methods)) {
1013 1013
 			return array();
1014 1014
 		}
1015 1015
 
1016 1016
 		$shipping = array();
1017 1017
 
1018
-		foreach ( $shipping_methods as $method ) {
1018
+		foreach ($shipping_methods as $method) {
1019 1019
 			$shipping[] = array(
1020 1020
 				'id'         => $method['id'],
1021 1021
 				'label'      => $method['label'],
1022 1022
 				'detail'     => '',
1023
-				'amount'     => WC_Stripe_Helper::get_stripe_amount( $method['amount']['value'] ),
1023
+				'amount'     => WC_Stripe_Helper::get_stripe_amount($method['amount']['value']),
1024 1024
 			);
1025 1025
 		}
1026 1026
 
@@ -1034,69 +1034,69 @@  discard block
 block discarded – undo
1034 1034
 	 * @version 4.0.0
1035 1035
 	 */
1036 1036
 	protected function build_display_items() {
1037
-		if ( ! defined( 'WOOCOMMERCE_CART' ) ) {
1038
-			define( 'WOOCOMMERCE_CART', true );
1037
+		if ( ! defined('WOOCOMMERCE_CART')) {
1038
+			define('WOOCOMMERCE_CART', true);
1039 1039
 		}
1040 1040
 
1041 1041
 		$items    = array();
1042 1042
 		$subtotal = 0;
1043 1043
 
1044 1044
 		// Default show only subtotal instead of itemization.
1045
-		if ( ! apply_filters( 'wc_stripe_payment_request_hide_itemization', true ) ) {
1046
-			foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {
1045
+		if ( ! apply_filters('wc_stripe_payment_request_hide_itemization', true)) {
1046
+			foreach (WC()->cart->get_cart() as $cart_item_key => $cart_item) {
1047 1047
 				$amount         = $cart_item['line_subtotal'];
1048
-				$subtotal       += $cart_item['line_subtotal'];
1048
+				$subtotal += $cart_item['line_subtotal'];
1049 1049
 				$quantity_label = 1 < $cart_item['quantity'] ? ' (x' . $cart_item['quantity'] . ')' : '';
1050 1050
 
1051 1051
 				$product_name = WC_Stripe_Helper::is_pre_30() ? $cart_item['data']->post->post_title : $cart_item['data']->get_name();
1052 1052
 
1053 1053
 				$item = array(
1054 1054
 					'label'  => $product_name . $quantity_label,
1055
-					'amount' => WC_Stripe_Helper::get_stripe_amount( $amount ),
1055
+					'amount' => WC_Stripe_Helper::get_stripe_amount($amount),
1056 1056
 				);
1057 1057
 
1058 1058
 				$items[] = $item;
1059 1059
 			}
1060 1060
 		}
1061 1061
 
1062
-		$discounts   = wc_format_decimal( WC()->cart->get_cart_discount_total(), WC()->cart->dp );
1063
-		$tax         = wc_format_decimal( WC()->cart->tax_total + WC()->cart->shipping_tax_total, WC()->cart->dp );
1064
-		$shipping    = wc_format_decimal( WC()->cart->shipping_total, WC()->cart->dp );
1065
-		$items_total = wc_format_decimal( WC()->cart->cart_contents_total, WC()->cart->dp ) + $discounts;
1066
-		$order_total = wc_format_decimal( $items_total + $tax + $shipping - $discounts, WC()->cart->dp );
1062
+		$discounts   = wc_format_decimal(WC()->cart->get_cart_discount_total(), WC()->cart->dp);
1063
+		$tax         = wc_format_decimal(WC()->cart->tax_total + WC()->cart->shipping_tax_total, WC()->cart->dp);
1064
+		$shipping    = wc_format_decimal(WC()->cart->shipping_total, WC()->cart->dp);
1065
+		$items_total = wc_format_decimal(WC()->cart->cart_contents_total, WC()->cart->dp) + $discounts;
1066
+		$order_total = wc_format_decimal($items_total + $tax + $shipping - $discounts, WC()->cart->dp);
1067 1067
 
1068
-		if ( wc_tax_enabled() ) {
1068
+		if (wc_tax_enabled()) {
1069 1069
 			$items[] = array(
1070
-				'label'  => esc_html( __( 'Tax', 'woocommerce-gateway-stripe' ) ),
1071
-				'amount' => WC_Stripe_Helper::get_stripe_amount( $tax ),
1070
+				'label'  => esc_html(__('Tax', 'woocommerce-gateway-stripe')),
1071
+				'amount' => WC_Stripe_Helper::get_stripe_amount($tax),
1072 1072
 			);
1073 1073
 		}
1074 1074
 
1075
-		if ( WC()->cart->needs_shipping() ) {
1075
+		if (WC()->cart->needs_shipping()) {
1076 1076
 			$items[] = array(
1077
-				'label'  => esc_html( __( 'Shipping', 'woocommerce-gateway-stripe' ) ),
1078
-				'amount' => WC_Stripe_Helper::get_stripe_amount( $shipping ),
1077
+				'label'  => esc_html(__('Shipping', 'woocommerce-gateway-stripe')),
1078
+				'amount' => WC_Stripe_Helper::get_stripe_amount($shipping),
1079 1079
 			);
1080 1080
 		}
1081 1081
 
1082
-		if ( WC()->cart->has_discount() ) {
1082
+		if (WC()->cart->has_discount()) {
1083 1083
 			$items[] = array(
1084
-				'label'  => esc_html( __( 'Discount', 'woocommerce-gateway-stripe' ) ),
1085
-				'amount' => WC_Stripe_Helper::get_stripe_amount( $discounts ),
1084
+				'label'  => esc_html(__('Discount', 'woocommerce-gateway-stripe')),
1085
+				'amount' => WC_Stripe_Helper::get_stripe_amount($discounts),
1086 1086
 			);
1087 1087
 		}
1088 1088
 
1089
-		if ( version_compare( WC_VERSION, '3.2', '<' ) ) {
1089
+		if (version_compare(WC_VERSION, '3.2', '<')) {
1090 1090
 			$cart_fees = WC()->cart->fees;
1091 1091
 		} else {
1092 1092
 			$cart_fees = WC()->cart->get_fees();
1093 1093
 		}
1094 1094
 
1095 1095
 		// Include fees and taxes as display items.
1096
-		foreach ( $cart_fees as $key => $fee ) {
1096
+		foreach ($cart_fees as $key => $fee) {
1097 1097
 			$items[] = array(
1098 1098
 				'label'  => $fee->name,
1099
-				'amount' => WC_Stripe_Helper::get_stripe_amount( $fee->amount ),
1099
+				'amount' => WC_Stripe_Helper::get_stripe_amount($fee->amount),
1100 1100
 			);
1101 1101
 		}
1102 1102
 
@@ -1104,7 +1104,7 @@  discard block
 block discarded – undo
1104 1104
 			'displayItems' => $items,
1105 1105
 			'total'      => array(
1106 1106
 				'label'   => $this->total_label,
1107
-				'amount'  => max( 0, apply_filters( 'woocommerce_stripe_calculated_total', WC_Stripe_Helper::get_stripe_amount( $order_total ), $order_total, WC()->cart ) ),
1107
+				'amount'  => max(0, apply_filters('woocommerce_stripe_calculated_total', WC_Stripe_Helper::get_stripe_amount($order_total), $order_total, WC()->cart)),
1108 1108
 				'pending' => false,
1109 1109
 			),
1110 1110
 		);
Please login to merge, or discard this patch.
includes/class-wc-stripe-apple-pay-registration.php 1 patch
Spacing   +45 added lines, -45 removed lines patch added patch discarded remove patch
@@ -5,7 +5,7 @@  discard block
 block discarded – undo
5 5
  * @since 4.0.6
6 6
  */
7 7
 
8
-if ( ! defined( 'ABSPATH' ) ) {
8
+if ( ! defined('ABSPATH')) {
9 9
 	exit;
10 10
 }
11 11
 
@@ -60,16 +60,16 @@  discard block
 block discarded – undo
60 60
 	public $apple_pay_verify_notice;
61 61
 
62 62
 	public function __construct() {
63
-		$this->stripe_settings         = get_option( 'woocommerce_stripe_settings', array() );
64
-		$this->stripe_enabled          = $this->get_option( 'enabled' );
65
-		$this->payment_request         = 'yes' === $this->get_option( 'payment_request', 'yes' );
66
-		$this->apple_pay_domain_set    = 'yes' === $this->get_option( 'apple_pay_domain_set', 'no' );
63
+		$this->stripe_settings         = get_option('woocommerce_stripe_settings', array());
64
+		$this->stripe_enabled          = $this->get_option('enabled');
65
+		$this->payment_request         = 'yes' === $this->get_option('payment_request', 'yes');
66
+		$this->apple_pay_domain_set    = 'yes' === $this->get_option('apple_pay_domain_set', 'no');
67 67
 		$this->apple_pay_verify_notice = '';
68
-		$this->testmode                = 'yes' === $this->get_option( 'testmode', 'no' );
69
-		$this->secret_key              = $this->testmode ? $this->get_option( 'test_secret_key' ) : $this->get_option( 'secret_key' );
68
+		$this->testmode                = 'yes' === $this->get_option('testmode', 'no');
69
+		$this->secret_key              = $this->testmode ? $this->get_option('test_secret_key') : $this->get_option('secret_key');
70 70
 		$this->init_apple_pay();
71 71
 
72
-		add_action( 'admin_notices', array( $this, 'admin_notices' ) );
72
+		add_action('admin_notices', array($this, 'admin_notices'));
73 73
 	}
74 74
 
75 75
 	/**
@@ -80,13 +80,13 @@  discard block
 block discarded – undo
80 80
 	 * @param string default
81 81
 	 * @return string $setting_value
82 82
 	 */
83
-	public function get_option( $setting = '', $default = '' ) {
84
-		if ( empty( $this->stripe_settings ) ) {
83
+	public function get_option($setting = '', $default = '') {
84
+		if (empty($this->stripe_settings)) {
85 85
 			return $default;
86 86
 		}
87 87
 
88
-		if ( ! empty( $this->stripe_settings[ $setting ] ) ) {
89
-			return $this->stripe_settings[ $setting ];
88
+		if ( ! empty($this->stripe_settings[$setting])) {
89
+			return $this->stripe_settings[$setting];
90 90
 		}
91 91
 		
92 92
 		return $default;
@@ -101,9 +101,9 @@  discard block
 block discarded – undo
101 101
 	public function init_apple_pay() {
102 102
 		if (
103 103
 			is_admin() &&
104
-			isset( $_GET['page'] ) && 'wc-settings' === $_GET['page'] &&
105
-			isset( $_GET['tab'] ) && 'checkout' === $_GET['tab'] &&
106
-			isset( $_GET['section'] ) && 'stripe' === $_GET['section'] &&
104
+			isset($_GET['page']) && 'wc-settings' === $_GET['page'] &&
105
+			isset($_GET['tab']) && 'checkout' === $_GET['tab'] &&
106
+			isset($_GET['section']) && 'stripe' === $_GET['section'] &&
107 107
 			$this->payment_request
108 108
 		) {
109 109
 			$this->process_apple_pay_verification();
@@ -117,9 +117,9 @@  discard block
 block discarded – undo
117 117
 	 * @version 3.1.0
118 118
 	 * @param string $secret_key
119 119
 	 */
120
-	private function register_apple_pay_domain( $secret_key = '' ) {
121
-		if ( empty( $secret_key ) ) {
122
-			throw new Exception( __( 'Unable to verify domain - missing secret key.', 'woocommerce-gateway-stripe' ) );
120
+	private function register_apple_pay_domain($secret_key = '') {
121
+		if (empty($secret_key)) {
122
+			throw new Exception(__('Unable to verify domain - missing secret key.', 'woocommerce-gateway-stripe'));
123 123
 		}
124 124
 
125 125
 		$endpoint = 'https://api.stripe.com/v1/apple_pay/domains';
@@ -133,23 +133,23 @@  discard block
 block discarded – undo
133 133
 			'Authorization' => 'Bearer ' . $secret_key,
134 134
 		);
135 135
 
136
-		$response = wp_remote_post( $endpoint, array(
136
+		$response = wp_remote_post($endpoint, array(
137 137
 			'headers' => $headers,
138
-			'body'    => http_build_query( $data ),
139
-		) );
138
+			'body'    => http_build_query($data),
139
+		));
140 140
 
141
-		if ( is_wp_error( $response ) ) {
141
+		if (is_wp_error($response)) {
142 142
 			/* translators: error message */
143
-			throw new Exception( sprintf( __( 'Unable to verify domain - %s', 'woocommerce-gateway-stripe' ), $response->get_error_message() ) );
143
+			throw new Exception(sprintf(__('Unable to verify domain - %s', 'woocommerce-gateway-stripe'), $response->get_error_message()));
144 144
 		}
145 145
 
146
-		if ( 200 !== $response['response']['code'] ) {
147
-			$parsed_response = json_decode( $response['body'] );
146
+		if (200 !== $response['response']['code']) {
147
+			$parsed_response = json_decode($response['body']);
148 148
 
149 149
 			$this->apple_pay_verify_notice = $parsed_response->error->message;
150 150
 
151 151
 			/* translators: error message */
152
-			throw new Exception( sprintf( __( 'Unable to verify domain - %s', 'woocommerce-gateway-stripe' ), $parsed_response->error->message ) );
152
+			throw new Exception(sprintf(__('Unable to verify domain - %s', 'woocommerce-gateway-stripe'), $parsed_response->error->message));
153 153
 		}
154 154
 	}
155 155
 
@@ -161,45 +161,45 @@  discard block
 block discarded – undo
161 161
 	 */
162 162
 	public function process_apple_pay_verification() {
163 163
 		try {
164
-			$path     = untrailingslashit( $_SERVER['DOCUMENT_ROOT'] );
164
+			$path     = untrailingslashit($_SERVER['DOCUMENT_ROOT']);
165 165
 			$dir      = '.well-known';
166 166
 			$file     = 'apple-developer-merchantid-domain-association';
167 167
 			$fullpath = $path . '/' . $dir . '/' . $file;
168 168
 
169
-			if ( $this->apple_pay_domain_set && file_exists( $fullpath ) ) {
169
+			if ($this->apple_pay_domain_set && file_exists($fullpath)) {
170 170
 				return;
171 171
 			}
172 172
 
173
-			if ( ! file_exists( $path . '/' . $dir ) ) {
174
-				if ( ! @mkdir( $path . '/' . $dir, 0755 ) ) { // @codingStandardsIgnoreLine
175
-					throw new Exception( __( 'Unable to create domain association folder to domain root.', 'woocommerce-gateway-stripe' ) );
173
+			if ( ! file_exists($path . '/' . $dir)) {
174
+				if ( ! @mkdir($path . '/' . $dir, 0755)) { // @codingStandardsIgnoreLine
175
+					throw new Exception(__('Unable to create domain association folder to domain root.', 'woocommerce-gateway-stripe'));
176 176
 				}
177 177
 			}
178 178
 
179
-			if ( ! file_exists( $fullpath ) ) {
180
-				if ( ! @copy( WC_STRIPE_PLUGIN_PATH . '/' . $file, $fullpath ) ) { // @codingStandardsIgnoreLine
181
-					throw new Exception( __( 'Unable to copy domain association file to domain root.', 'woocommerce-gateway-stripe' ) );
179
+			if ( ! file_exists($fullpath)) {
180
+				if ( ! @copy(WC_STRIPE_PLUGIN_PATH . '/' . $file, $fullpath)) { // @codingStandardsIgnoreLine
181
+					throw new Exception(__('Unable to copy domain association file to domain root.', 'woocommerce-gateway-stripe'));
182 182
 				}
183 183
 			}
184 184
 
185 185
 			// At this point then the domain association folder and file should be available.
186 186
 			// Proceed to verify/and or verify again.
187
-			$this->register_apple_pay_domain( $this->secret_key );
187
+			$this->register_apple_pay_domain($this->secret_key);
188 188
 
189 189
 			// No errors to this point, verification success!
190 190
 			$this->stripe_settings['apple_pay_domain_set'] = 'yes';
191 191
 			$this->apple_pay_domain_set = true;
192 192
 
193
-			update_option( 'woocommerce_stripe_settings', $this->stripe_settings );
193
+			update_option('woocommerce_stripe_settings', $this->stripe_settings);
194 194
 
195
-			WC_Stripe_Logger::log( 'Your domain has been verified with Apple Pay!' );
195
+			WC_Stripe_Logger::log('Your domain has been verified with Apple Pay!');
196 196
 
197
-		} catch ( Exception $e ) {
197
+		} catch (Exception $e) {
198 198
 			$this->stripe_settings['apple_pay_domain_set'] = 'no';
199 199
 
200
-			update_option( 'woocommerce_stripe_settings', $this->stripe_settings );
200
+			update_option('woocommerce_stripe_settings', $this->stripe_settings);
201 201
 
202
-			WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() );
202
+			WC_Stripe_Logger::log('Error: ' . $e->getMessage());
203 203
 		}
204 204
 	}
205 205
 
@@ -209,11 +209,11 @@  discard block
 block discarded – undo
209 209
 	 * @since 4.0.6
210 210
 	 */
211 211
 	public function admin_notices() {
212
-		if ( ! $this->stripe_enabled  ) {
212
+		if ( ! $this->stripe_enabled) {
213 213
 			return;
214 214
 		}
215 215
 
216
-		if ( $this->payment_request && ! empty( $this->apple_pay_verify_notice ) ) {
216
+		if ($this->payment_request && ! empty($this->apple_pay_verify_notice)) {
217 217
 			$allowed_html = array(
218 218
 				'a' => array(
219 219
 					'href' => array(),
@@ -221,7 +221,7 @@  discard block
 block discarded – undo
221 221
 				),
222 222
 			);
223 223
 
224
-			echo '<div class="error stripe-apple-pay-message"><p>' . wp_kses( make_clickable( $this->apple_pay_verify_notice ), $allowed_html ) . '</p></div>';
224
+			echo '<div class="error stripe-apple-pay-message"><p>' . wp_kses(make_clickable($this->apple_pay_verify_notice), $allowed_html) . '</p></div>';
225 225
 		}
226 226
 
227 227
 		/**
@@ -229,9 +229,9 @@  discard block
 block discarded – undo
229 229
 		 * when setting screen is displayed. So if domain verification is not set,
230 230
 		 * something went wrong so lets notify user.
231 231
 		 */
232
-		if ( ! empty( $this->secret_key ) && $this->payment_request && ! $this->apple_pay_domain_set ) {
232
+		if ( ! empty($this->secret_key) && $this->payment_request && ! $this->apple_pay_domain_set) {
233 233
 			/* translators: 1) HTML anchor open tag 2) HTML anchor closing tag */
234
-			echo '<div class="error stripe-apple-pay-message"><p>' . sprintf( __( 'Apple Pay domain verification failed. Please check the %1$slog%2$s to see the issue. (Logging must be enabled to see recorded logs)', 'woocommerce-gateway-stripe' ), '<a href="' . admin_url( 'admin.php?page=wc-status&tab=logs' ) . '">', '</a>' ) . '</p></div>';
234
+			echo '<div class="error stripe-apple-pay-message"><p>' . sprintf(__('Apple Pay domain verification failed. Please check the %1$slog%2$s to see the issue. (Logging must be enabled to see recorded logs)', 'woocommerce-gateway-stripe'), '<a href="' . admin_url('admin.php?page=wc-status&tab=logs') . '">', '</a>') . '</p></div>';
235 235
 		}
236 236
 	}
237 237
 }
Please login to merge, or discard this patch.
includes/compat/class-wc-stripe-compat.php 1 patch
Spacing   +184 added lines, -184 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
 
@@ -15,23 +15,23 @@  discard block
 block discarded – undo
15 15
 	public function __construct() {
16 16
 		parent::__construct();
17 17
 
18
-		if ( class_exists( 'WC_Subscriptions_Order' ) ) {
19
-			add_action( 'woocommerce_scheduled_subscription_payment_' . $this->id, array( $this, 'scheduled_subscription_payment' ), 10, 2 );
20
-			add_action( 'wcs_resubscribe_order_created', array( $this, 'delete_resubscribe_meta' ), 10 );
21
-			add_action( 'wcs_renewal_order_created', array( $this, 'delete_renewal_meta' ), 10 );
22
-			add_action( 'woocommerce_subscription_failing_payment_method_updated_stripe', array( $this, 'update_failing_payment_method' ), 10, 2 );
18
+		if (class_exists('WC_Subscriptions_Order')) {
19
+			add_action('woocommerce_scheduled_subscription_payment_' . $this->id, array($this, 'scheduled_subscription_payment'), 10, 2);
20
+			add_action('wcs_resubscribe_order_created', array($this, 'delete_resubscribe_meta'), 10);
21
+			add_action('wcs_renewal_order_created', array($this, 'delete_renewal_meta'), 10);
22
+			add_action('woocommerce_subscription_failing_payment_method_updated_stripe', array($this, 'update_failing_payment_method'), 10, 2);
23 23
 
24 24
 			// display the credit card used for a subscription in the "My Subscriptions" table
25
-			add_filter( 'woocommerce_my_subscriptions_payment_method', array( $this, 'maybe_render_subscription_payment_method' ), 10, 2 );
25
+			add_filter('woocommerce_my_subscriptions_payment_method', array($this, 'maybe_render_subscription_payment_method'), 10, 2);
26 26
 
27 27
 			// allow store managers to manually set Stripe as the payment method on a subscription
28
-			add_filter( 'woocommerce_subscription_payment_meta', array( $this, 'add_subscription_payment_meta' ), 10, 2 );
29
-			add_filter( 'woocommerce_subscription_validate_payment_meta', array( $this, 'validate_subscription_payment_meta' ), 10, 2 );
30
-			add_filter( 'wc_stripe_display_save_payment_method_checkbox', array( $this, 'maybe_hide_save_checkbox' ) );
28
+			add_filter('woocommerce_subscription_payment_meta', array($this, 'add_subscription_payment_meta'), 10, 2);
29
+			add_filter('woocommerce_subscription_validate_payment_meta', array($this, 'validate_subscription_payment_meta'), 10, 2);
30
+			add_filter('wc_stripe_display_save_payment_method_checkbox', array($this, 'maybe_hide_save_checkbox'));
31 31
 		}
32 32
 
33
-		if ( class_exists( 'WC_Pre_Orders_Order' ) ) {
34
-			add_action( 'wc_pre_orders_process_pre_order_completion_payment_' . $this->id, array( $this, 'process_pre_order_release_payment' ) );
33
+		if (class_exists('WC_Pre_Orders_Order')) {
34
+			add_action('wc_pre_orders_process_pre_order_completion_payment_' . $this->id, array($this, 'process_pre_order_release_payment'));
35 35
 		}
36 36
 	}
37 37
 
@@ -42,8 +42,8 @@  discard block
 block discarded – undo
42 42
 	 * @since 4.0.0
43 43
 	 * @version 4.0.0
44 44
 	 */
45
-	public function maybe_hide_save_checkbox( $display_tokenization ) {
46
-		if ( WC_Subscriptions_Cart::cart_contains_subscription() ) {
45
+	public function maybe_hide_save_checkbox($display_tokenization) {
46
+		if (WC_Subscriptions_Cart::cart_contains_subscription()) {
47 47
 			return false;
48 48
 		}
49 49
 
@@ -55,8 +55,8 @@  discard block
 block discarded – undo
55 55
 	 * @param  int  $order_id
56 56
 	 * @return boolean
57 57
 	 */
58
-	public function has_subscription( $order_id ) {
59
-		return ( function_exists( 'wcs_order_contains_subscription' ) && ( wcs_order_contains_subscription( $order_id ) || wcs_is_subscription( $order_id ) || wcs_order_contains_renewal( $order_id ) ) );
58
+	public function has_subscription($order_id) {
59
+		return (function_exists('wcs_order_contains_subscription') && (wcs_order_contains_subscription($order_id) || wcs_is_subscription($order_id) || wcs_order_contains_renewal($order_id)));
60 60
 	}
61 61
 
62 62
 	/**
@@ -66,7 +66,7 @@  discard block
 block discarded – undo
66 66
 	 * @return bool
67 67
 	 */
68 68
 	public function is_subs_change_payment() {
69
-		return ( isset( $_GET['pay_for_order'] ) && isset( $_GET['change_payment_method'] ) );
69
+		return (isset($_GET['pay_for_order']) && isset($_GET['change_payment_method']));
70 70
 	}
71 71
 
72 72
 	/**
@@ -74,8 +74,8 @@  discard block
 block discarded – undo
74 74
 	 * @param  int  $order_id
75 75
 	 * @return boolean
76 76
 	 */
77
-	public function is_pre_order( $order_id ) {
78
-		return ( class_exists( 'WC_Pre_Orders_Order' ) && WC_Pre_Orders_Order::order_contains_pre_order( $order_id ) );
77
+	public function is_pre_order($order_id) {
78
+		return (class_exists('WC_Pre_Orders_Order') && WC_Pre_Orders_Order::order_contains_pre_order($order_id));
79 79
 	}
80 80
 
81 81
 	/**
@@ -84,26 +84,26 @@  discard block
 block discarded – undo
84 84
 	 * @since 4.0.4
85 85
 	 * @param int $order_id
86 86
 	 */
87
-	public function change_subs_payment_method( $order_id ) {
87
+	public function change_subs_payment_method($order_id) {
88 88
 		try {
89
-			$subscription    = wc_get_order( $order_id );
89
+			$subscription    = wc_get_order($order_id);
90 90
 			$source_object   = $this->get_source_object();
91
-			$prepared_source = $this->prepare_source( $source_object, get_current_user_id(), true );
91
+			$prepared_source = $this->prepare_source($source_object, get_current_user_id(), true);
92 92
 
93 93
 			// Check if we don't allow prepaid credit cards.
94
-			if ( ! apply_filters( 'wc_stripe_allow_prepaid_card', true ) ) {
95
-				if ( $source_object && 'token' === $source_object->object && 'prepaid' === $source_object->card->funding ) {
96
-					$localized_message = __( 'Sorry, we\'re not accepting prepaid cards at this time. Your credit card has not been charge. Please try with alternative payment method.', 'woocommerce-gateway-stripe' );
97
-					throw new WC_Stripe_Exception( print_r( $source_object, true ), $localized_message );
94
+			if ( ! apply_filters('wc_stripe_allow_prepaid_card', true)) {
95
+				if ($source_object && 'token' === $source_object->object && 'prepaid' === $source_object->card->funding) {
96
+					$localized_message = __('Sorry, we\'re not accepting prepaid cards at this time. Your credit card has not been charge. Please try with alternative payment method.', 'woocommerce-gateway-stripe');
97
+					throw new WC_Stripe_Exception(print_r($source_object, true), $localized_message);
98 98
 				}
99 99
 			}
100 100
 
101
-			if ( empty( $prepared_source->source ) ) {
102
-				$localized_message = __( 'Payment processing failed. Please retry.', 'woocommerce-gateway-stripe' );
103
-				throw new WC_Stripe_Exception( print_r( $prepared_source, true ), $localized_message );
101
+			if (empty($prepared_source->source)) {
102
+				$localized_message = __('Payment processing failed. Please retry.', 'woocommerce-gateway-stripe');
103
+				throw new WC_Stripe_Exception(print_r($prepared_source, true), $localized_message);
104 104
 			}
105 105
 
106
-			$this->save_source_to_order( $subscription, $prepared_source );
106
+			$this->save_source_to_order($subscription, $prepared_source);
107 107
 
108 108
 			/*
109 109
 			 * Check if card 3DS is required or optional with 3DS setting.
@@ -112,41 +112,41 @@  discard block
 block discarded – undo
112 112
 			 * Note that if we need to save source, the original source must be first
113 113
 			 * attached to a customer in Stripe before it can be charged.
114 114
 			 */
115
-			if ( $this->is_3ds_required( $source_object ) ) {
115
+			if ($this->is_3ds_required($source_object)) {
116 116
 				$order    = $subscription->get_parent();
117
-				$response = $this->create_3ds_source( $order, $source_object, $subscription->get_view_order_url() );
117
+				$response = $this->create_3ds_source($order, $source_object, $subscription->get_view_order_url());
118 118
 
119
-				if ( ! empty( $response->error ) ) {
119
+				if ( ! empty($response->error)) {
120 120
 					$localized_message = $response->error->message;
121 121
 
122
-					$order->add_order_note( $localized_message );
122
+					$order->add_order_note($localized_message);
123 123
 
124
-					throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message );
124
+					throw new WC_Stripe_Exception(print_r($response, true), $localized_message);
125 125
 				}
126 126
 
127 127
 				// Update order meta with 3DS source.
128
-				if ( WC_Stripe_Helper::is_pre_30() ) {
129
-					update_post_meta( $order_id, '_stripe_source_id', $response->id );
128
+				if (WC_Stripe_Helper::is_pre_30()) {
129
+					update_post_meta($order_id, '_stripe_source_id', $response->id);
130 130
 				} else {
131
-					$subscription->update_meta_data( '_stripe_source_id', $response->id );
131
+					$subscription->update_meta_data('_stripe_source_id', $response->id);
132 132
 					$subscription->save();
133 133
 				}
134 134
 
135
-				WC_Stripe_Logger::log( 'Info: Redirecting to 3DS...' );
135
+				WC_Stripe_Logger::log('Info: Redirecting to 3DS...');
136 136
 
137 137
 				return array(
138 138
 					'result'   => 'success',
139
-					'redirect' => esc_url_raw( $response->redirect->url ),
139
+					'redirect' => esc_url_raw($response->redirect->url),
140 140
 				);
141 141
 			}
142 142
 
143 143
 			return array(
144 144
 				'result'   => 'success',
145
-				'redirect' => $this->get_return_url( $subscription ),
145
+				'redirect' => $this->get_return_url($subscription),
146 146
 			);
147
-		} catch ( WC_Stripe_Exception $e ) {
148
-			wc_add_notice( $e->getLocalizedMessage(), 'error' );
149
-			WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() );
147
+		} catch (WC_Stripe_Exception $e) {
148
+			wc_add_notice($e->getLocalizedMessage(), 'error');
149
+			WC_Stripe_Logger::log('Error: ' . $e->getMessage());
150 150
 		}
151 151
 	}
152 152
 
@@ -155,18 +155,18 @@  discard block
 block discarded – undo
155 155
 	 * @param  int $order_id
156 156
 	 * @return array
157 157
 	 */
158
-	public function process_payment( $order_id, $retry = true, $force_save_source = false ) {
159
-		if ( $this->has_subscription( $order_id ) ) {
160
-			if ( $this->is_subs_change_payment() ) {
161
-				return $this->change_subs_payment_method( $order_id );
158
+	public function process_payment($order_id, $retry = true, $force_save_source = false) {
159
+		if ($this->has_subscription($order_id)) {
160
+			if ($this->is_subs_change_payment()) {
161
+				return $this->change_subs_payment_method($order_id);
162 162
 			}
163 163
 
164 164
 			// Regular payment with force customer enabled
165
-			return parent::process_payment( $order_id, true, true );
166
-		} elseif ( $this->is_pre_order( $order_id ) ) {
167
-			return $this->process_pre_order( $order_id, $retry, $force_save_source );
165
+			return parent::process_payment($order_id, true, true);
166
+		} elseif ($this->is_pre_order($order_id)) {
167
+			return $this->process_pre_order($order_id, $retry, $force_save_source);
168 168
 		} else {
169
-			return parent::process_payment( $order_id, $retry, $force_save_source );
169
+			return parent::process_payment($order_id, $retry, $force_save_source);
170 170
 		}
171 171
 	}
172 172
 
@@ -176,24 +176,24 @@  discard block
 block discarded – undo
176 176
 	 * @since 3.1.0
177 177
 	 * @version 4.0.0
178 178
 	 */
179
-	public function save_source_to_order( $order, $source ) {
180
-		parent::save_source_to_order( $order, $source );
179
+	public function save_source_to_order($order, $source) {
180
+		parent::save_source_to_order($order, $source);
181 181
 
182 182
 		$order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
183 183
 
184 184
 		// Also store it on the subscriptions being purchased or paid for in the order
185
-		if ( function_exists( 'wcs_order_contains_subscription' ) && wcs_order_contains_subscription( $order_id ) ) {
186
-			$subscriptions = wcs_get_subscriptions_for_order( $order_id );
187
-		} elseif ( function_exists( 'wcs_order_contains_renewal' ) && wcs_order_contains_renewal( $order_id ) ) {
188
-			$subscriptions = wcs_get_subscriptions_for_renewal_order( $order_id );
185
+		if (function_exists('wcs_order_contains_subscription') && wcs_order_contains_subscription($order_id)) {
186
+			$subscriptions = wcs_get_subscriptions_for_order($order_id);
187
+		} elseif (function_exists('wcs_order_contains_renewal') && wcs_order_contains_renewal($order_id)) {
188
+			$subscriptions = wcs_get_subscriptions_for_renewal_order($order_id);
189 189
 		} else {
190 190
 			$subscriptions = array();
191 191
 		}
192 192
 
193
-		foreach ( $subscriptions as $subscription ) {
193
+		foreach ($subscriptions as $subscription) {
194 194
 			$subscription_id = WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id();
195
-			update_post_meta( $subscription_id, '_stripe_customer_id', $source->customer );
196
-			update_post_meta( $subscription_id, '_stripe_source_id', $source->source );
195
+			update_post_meta($subscription_id, '_stripe_customer_id', $source->customer);
196
+			update_post_meta($subscription_id, '_stripe_source_id', $source->source);
197 197
 		}
198 198
 	}
199 199
 
@@ -206,45 +206,45 @@  discard block
 block discarded – undo
206 206
 	 * @param mixed $renewal_order
207 207
 	 * @param bool $is_retry Is this a retry process.
208 208
 	 */
209
-	public function process_subscription_payment( $amount = 0.0, $renewal_order, $is_retry = false ) {
210
-		if ( $amount * 100 < WC_Stripe_Helper::get_minimum_amount() ) {
209
+	public function process_subscription_payment($amount = 0.0, $renewal_order, $is_retry = false) {
210
+		if ($amount * 100 < WC_Stripe_Helper::get_minimum_amount()) {
211 211
 			/* translators: minimum amount */
212
-			return new WP_Error( 'stripe_error', sprintf( __( 'Sorry, the minimum allowed order total is %1$s to use this payment method.', 'woocommerce-gateway-stripe' ), wc_price( WC_Stripe_Helper::get_minimum_amount() / 100 ) ) );
212
+			return new WP_Error('stripe_error', sprintf(__('Sorry, the minimum allowed order total is %1$s to use this payment method.', 'woocommerce-gateway-stripe'), wc_price(WC_Stripe_Helper::get_minimum_amount() / 100)));
213 213
 		}
214 214
 
215 215
 		$order_id = WC_Stripe_Helper::is_pre_30() ? $renewal_order->id : $renewal_order->get_id();
216 216
 
217 217
 		// Get source from order
218
-		$prepared_source = $this->prepare_order_source( $renewal_order );
218
+		$prepared_source = $this->prepare_order_source($renewal_order);
219 219
 
220
-		if ( ! $prepared_source->customer ) {
221
-			return new WP_Error( 'stripe_error', __( 'Customer not found', 'woocommerce-gateway-stripe' ) );
220
+		if ( ! $prepared_source->customer) {
221
+			return new WP_Error('stripe_error', __('Customer not found', 'woocommerce-gateway-stripe'));
222 222
 		}
223 223
 
224
-		WC_Stripe_Logger::log( "Info: Begin processing subscription payment for order {$order_id} for the amount of {$amount}" );
224
+		WC_Stripe_Logger::log("Info: Begin processing subscription payment for order {$order_id} for the amount of {$amount}");
225 225
 
226
-		if ( $is_retry ) {
226
+		if ($is_retry) {
227 227
 			// Passing empty source with charge customer default.
228 228
 			$prepared_source->source = '';
229 229
 		}
230 230
 
231
-		$request            = $this->generate_payment_request( $renewal_order, $prepared_source );
231
+		$request            = $this->generate_payment_request($renewal_order, $prepared_source);
232 232
 		$request['capture'] = 'true';
233
-		$request['amount']  = WC_Stripe_Helper::get_stripe_amount( $amount, $request['currency'] );
234
-		$response           = WC_Stripe_API::request( $request );
233
+		$request['amount']  = WC_Stripe_Helper::get_stripe_amount($amount, $request['currency']);
234
+		$response           = WC_Stripe_API::request($request);
235 235
 
236
-		if ( ! empty( $response->error ) || is_wp_error( $response ) ) {
237
-			if ( $is_retry ) {
236
+		if ( ! empty($response->error) || is_wp_error($response)) {
237
+			if ($is_retry) {
238 238
 				/* translators: error message */
239
-				$renewal_order->update_status( 'failed', sprintf( __( 'Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe' ), $response->error->message ) );
239
+				$renewal_order->update_status('failed', sprintf(__('Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe'), $response->error->message));
240 240
 			}
241 241
 
242 242
 			return $response; // Default catch all errors.
243 243
 		}
244 244
 
245
-		$this->process_response( $response, $renewal_order );
245
+		$this->process_response($response, $renewal_order);
246 246
 
247
-		if ( ! $is_retry ) {
247
+		if ( ! $is_retry) {
248 248
 			return $response;
249 249
 		}
250 250
 	}
@@ -253,21 +253,21 @@  discard block
 block discarded – undo
253 253
 	 * Don't transfer Stripe customer/token meta to resubscribe orders.
254 254
 	 * @param int $resubscribe_order The order created for the customer to resubscribe to the old expired/cancelled subscription
255 255
 	 */
256
-	public function delete_resubscribe_meta( $resubscribe_order ) {
257
-		delete_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id() ), '_stripe_customer_id' );
258
-		delete_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id() ), '_stripe_source_id' );
256
+	public function delete_resubscribe_meta($resubscribe_order) {
257
+		delete_post_meta((WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id()), '_stripe_customer_id');
258
+		delete_post_meta((WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id()), '_stripe_source_id');
259 259
 		// For BW compat will remove in future
260
-		delete_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id() ), '_stripe_card_id' );
261
-		$this->delete_renewal_meta( $resubscribe_order );
260
+		delete_post_meta((WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id()), '_stripe_card_id');
261
+		$this->delete_renewal_meta($resubscribe_order);
262 262
 	}
263 263
 
264 264
 	/**
265 265
 	 * Don't transfer Stripe fee/ID meta to renewal orders.
266 266
 	 * @param int $resubscribe_order The order created for the customer to resubscribe to the old expired/cancelled subscription
267 267
 	 */
268
-	public function delete_renewal_meta( $renewal_order ) {
269
-		delete_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $renewal_order->id : $renewal_order->get_id() ), 'Stripe Fee' );
270
-		delete_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $renewal_order->id : $renewal_order->get_id() ), 'Net Revenue From Stripe' );
268
+	public function delete_renewal_meta($renewal_order) {
269
+		delete_post_meta((WC_Stripe_Helper::is_pre_30() ? $renewal_order->id : $renewal_order->get_id()), 'Stripe Fee');
270
+		delete_post_meta((WC_Stripe_Helper::is_pre_30() ? $renewal_order->id : $renewal_order->get_id()), 'Net Revenue From Stripe');
271 271
 		return $renewal_order;
272 272
 	}
273 273
 
@@ -277,21 +277,21 @@  discard block
 block discarded – undo
277 277
 	 * @param $amount_to_charge float The amount to charge.
278 278
 	 * @param $renewal_order WC_Order A WC_Order object created to record the renewal payment.
279 279
 	 */
280
-	public function scheduled_subscription_payment( $amount_to_charge, $renewal_order ) {
281
-		$response = $this->process_subscription_payment( $amount_to_charge, $renewal_order );
280
+	public function scheduled_subscription_payment($amount_to_charge, $renewal_order) {
281
+		$response = $this->process_subscription_payment($amount_to_charge, $renewal_order);
282 282
 
283
-		if ( is_wp_error( $response ) ) {
283
+		if (is_wp_error($response)) {
284 284
 			/* translators: error message */
285
-			$renewal_order->update_status( 'failed', sprintf( __( 'Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe' ), $response->get_error_message() ) );
285
+			$renewal_order->update_status('failed', sprintf(__('Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe'), $response->get_error_message()));
286 286
 		}
287 287
 
288
-		if ( ! empty( $response->error ) ) {
288
+		if ( ! empty($response->error)) {
289 289
 			// This is a very generic error to listen for but worth a retry before total fail.
290
-			if ( isset( $response->error->type ) && 'invalid_request_error' === $response->error->type && apply_filters( 'wc_stripe_use_default_customer_source', true ) ) {
291
-				$this->process_subscription_payment( $amount_to_charge, $renewal_order, true );
290
+			if (isset($response->error->type) && 'invalid_request_error' === $response->error->type && apply_filters('wc_stripe_use_default_customer_source', true)) {
291
+				$this->process_subscription_payment($amount_to_charge, $renewal_order, true);
292 292
 			} else {
293 293
 				/* translators: error message */
294
-				$renewal_order->update_status( 'failed', sprintf( __( 'Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe' ), $response->error->message ) );
294
+				$renewal_order->update_status('failed', sprintf(__('Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe'), $response->error->message));
295 295
 			}
296 296
 		}
297 297
 	}
@@ -300,20 +300,20 @@  discard block
 block discarded – undo
300 300
 	 * Remove order meta
301 301
 	 * @param object $order
302 302
 	 */
303
-	public function remove_order_source_before_retry( $order ) {
303
+	public function remove_order_source_before_retry($order) {
304 304
 		$order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
305
-		delete_post_meta( $order_id, '_stripe_source_id' );
305
+		delete_post_meta($order_id, '_stripe_source_id');
306 306
 		// For BW compat will remove in the future.
307
-		delete_post_meta( $order_id, '_stripe_card_id' );
307
+		delete_post_meta($order_id, '_stripe_card_id');
308 308
 	}
309 309
 
310 310
 	/**
311 311
 	 * Remove order meta
312 312
 	 * @param  object $order
313 313
 	 */
314
-	public function remove_order_customer_before_retry( $order ) {
314
+	public function remove_order_customer_before_retry($order) {
315 315
 		$order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
316
-		delete_post_meta( $order_id, '_stripe_customer_id' );
316
+		delete_post_meta($order_id, '_stripe_customer_id');
317 317
 	}
318 318
 
319 319
 	/**
@@ -325,14 +325,14 @@  discard block
 block discarded – undo
325 325
 	 * @param WC_Order $renewal_order The order which recorded the successful payment (to make up for the failed automatic payment).
326 326
 	 * @return void
327 327
 	 */
328
-	public function update_failing_payment_method( $subscription, $renewal_order ) {
329
-		if ( WC_Stripe_Helper::is_pre_30() ) {
330
-			update_post_meta( $subscription->id, '_stripe_customer_id', $renewal_order->stripe_customer_id );
331
-			update_post_meta( $subscription->id, '_stripe_source_id', $renewal_order->stripe_source_id );
328
+	public function update_failing_payment_method($subscription, $renewal_order) {
329
+		if (WC_Stripe_Helper::is_pre_30()) {
330
+			update_post_meta($subscription->id, '_stripe_customer_id', $renewal_order->stripe_customer_id);
331
+			update_post_meta($subscription->id, '_stripe_source_id', $renewal_order->stripe_source_id);
332 332
 
333 333
 		} else {
334
-			update_post_meta( $subscription->get_id(), '_stripe_customer_id', $renewal_order->get_meta( '_stripe_customer_id', true ) );
335
-			update_post_meta( $subscription->get_id(), '_stripe_source_id', $renewal_order->get_meta( '_stripe_source_id', true ) );
334
+			update_post_meta($subscription->get_id(), '_stripe_customer_id', $renewal_order->get_meta('_stripe_customer_id', true));
335
+			update_post_meta($subscription->get_id(), '_stripe_source_id', $renewal_order->get_meta('_stripe_source_id', true));
336 336
 		}
337 337
 	}
338 338
 
@@ -345,21 +345,21 @@  discard block
 block discarded – undo
345 345
 	 * @param WC_Subscription $subscription An instance of a subscription object
346 346
 	 * @return array
347 347
 	 */
348
-	public function add_subscription_payment_meta( $payment_meta, $subscription ) {
349
-		$source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_source_id', true );
348
+	public function add_subscription_payment_meta($payment_meta, $subscription) {
349
+		$source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_source_id', true);
350 350
 
351 351
 		// For BW compat will remove in future.
352
-		if ( empty( $source_id ) ) {
353
-			$source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_card_id', true );
352
+		if (empty($source_id)) {
353
+			$source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_card_id', true);
354 354
 
355 355
 			// Take this opportunity to update the key name.
356
-			WC_Stripe_Helper::is_pre_30() ? update_post_meta( $subscription->id, '_stripe_source_id', $source_id ) : update_post_meta( $subscription->get_id(), '_stripe_source_id', $source_id );
356
+			WC_Stripe_Helper::is_pre_30() ? update_post_meta($subscription->id, '_stripe_source_id', $source_id) : update_post_meta($subscription->get_id(), '_stripe_source_id', $source_id);
357 357
 		}
358 358
 
359
-		$payment_meta[ $this->id ] = array(
359
+		$payment_meta[$this->id] = array(
360 360
 			'post_meta' => array(
361 361
 				'_stripe_customer_id' => array(
362
-					'value' => get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_customer_id', true ),
362
+					'value' => get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_customer_id', true),
363 363
 					'label' => 'Stripe Customer ID',
364 364
 				),
365 365
 				'_stripe_source_id' => array(
@@ -382,22 +382,22 @@  discard block
 block discarded – undo
382 382
 	 * @param array $payment_meta associative array of meta data required for automatic payments
383 383
 	 * @return array
384 384
 	 */
385
-	public function validate_subscription_payment_meta( $payment_method_id, $payment_meta ) {
386
-		if ( $this->id === $payment_method_id ) {
385
+	public function validate_subscription_payment_meta($payment_method_id, $payment_meta) {
386
+		if ($this->id === $payment_method_id) {
387 387
 
388
-			if ( ! isset( $payment_meta['post_meta']['_stripe_customer_id']['value'] ) || empty( $payment_meta['post_meta']['_stripe_customer_id']['value'] ) ) {
389
-				throw new Exception( __( 'A "Stripe Customer ID" value is required.', 'woocommerce-gateway-stripe' ) );
390
-			} elseif ( 0 !== strpos( $payment_meta['post_meta']['_stripe_customer_id']['value'], 'cus_' ) ) {
391
-				throw new Exception( __( 'Invalid customer ID. A valid "Stripe Customer ID" must begin with "cus_".', 'woocommerce-gateway-stripe' ) );
388
+			if ( ! isset($payment_meta['post_meta']['_stripe_customer_id']['value']) || empty($payment_meta['post_meta']['_stripe_customer_id']['value'])) {
389
+				throw new Exception(__('A "Stripe Customer ID" value is required.', 'woocommerce-gateway-stripe'));
390
+			} elseif (0 !== strpos($payment_meta['post_meta']['_stripe_customer_id']['value'], 'cus_')) {
391
+				throw new Exception(__('Invalid customer ID. A valid "Stripe Customer ID" must begin with "cus_".', 'woocommerce-gateway-stripe'));
392 392
 			}
393 393
 
394 394
 			if (
395
-				( ! empty( $payment_meta['post_meta']['_stripe_source_id']['value'] )
396
-				&& 0 !== strpos( $payment_meta['post_meta']['_stripe_source_id']['value'], 'card_' ) )
397
-				&& ( ! empty( $payment_meta['post_meta']['_stripe_source_id']['value'] )
398
-				&& 0 !== strpos( $payment_meta['post_meta']['_stripe_source_id']['value'], 'src_' ) ) ) {
395
+				( ! empty($payment_meta['post_meta']['_stripe_source_id']['value'])
396
+				&& 0 !== strpos($payment_meta['post_meta']['_stripe_source_id']['value'], 'card_'))
397
+				&& ( ! empty($payment_meta['post_meta']['_stripe_source_id']['value'])
398
+				&& 0 !== strpos($payment_meta['post_meta']['_stripe_source_id']['value'], 'src_')) ) {
399 399
 
400
-				throw new Exception( __( 'Invalid source ID. A valid source "Stripe Source ID" must begin with "src_" or "card_".', 'woocommerce-gateway-stripe' ) );
400
+				throw new Exception(__('Invalid source ID. A valid source "Stripe Source ID" must begin with "src_" or "card_".', 'woocommerce-gateway-stripe'));
401 401
 			}
402 402
 		}
403 403
 	}
@@ -410,91 +410,91 @@  discard block
 block discarded – undo
410 410
 	 * @param WC_Subscription $subscription the subscription details
411 411
 	 * @return string the subscription payment method
412 412
 	 */
413
-	public function maybe_render_subscription_payment_method( $payment_method_to_display, $subscription ) {
413
+	public function maybe_render_subscription_payment_method($payment_method_to_display, $subscription) {
414 414
 		$customer_user = WC_Stripe_Helper::is_pre_30() ? $subscription->customer_user : $subscription->get_customer_id();
415 415
 
416 416
 		// bail for other payment methods
417
-		if ( ( WC_Stripe_Helper::is_pre_30() ? $subscription->payment_method : $subscription->get_payment_method() ) !== $this->id || ! $customer_user ) {
417
+		if ((WC_Stripe_Helper::is_pre_30() ? $subscription->payment_method : $subscription->get_payment_method()) !== $this->id || ! $customer_user) {
418 418
 			return $payment_method_to_display;
419 419
 		}
420 420
 
421
-		$stripe_source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_source_id', true );
421
+		$stripe_source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_source_id', true);
422 422
 
423 423
 		// For BW compat will remove in future.
424
-		if ( empty( $stripe_source_id ) ) {
425
-			$stripe_source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_card_id', true );
424
+		if (empty($stripe_source_id)) {
425
+			$stripe_source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_card_id', true);
426 426
 
427 427
 			// Take this opportunity to update the key name.
428
-			WC_Stripe_Helper::is_pre_30() ? update_post_meta( $subscription->id, '_stripe_source_id', $stripe_source_id ) : update_post_meta( $subscription->get_id(), '_stripe_source_id', $stripe_source_id );
428
+			WC_Stripe_Helper::is_pre_30() ? update_post_meta($subscription->id, '_stripe_source_id', $stripe_source_id) : update_post_meta($subscription->get_id(), '_stripe_source_id', $stripe_source_id);
429 429
 		}
430 430
 
431 431
 		$stripe_customer    = new WC_Stripe_Customer();
432
-		$stripe_customer_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_customer_id', true );
432
+		$stripe_customer_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_customer_id', true);
433 433
 
434 434
 		// If we couldn't find a Stripe customer linked to the subscription, fallback to the user meta data.
435
-		if ( ! $stripe_customer_id || ! is_string( $stripe_customer_id ) ) {
435
+		if ( ! $stripe_customer_id || ! is_string($stripe_customer_id)) {
436 436
 			$user_id            = $customer_user;
437
-			$stripe_customer_id = get_user_meta( $user_id, '_stripe_customer_id', true );
438
-			$stripe_source_id   = get_user_meta( $user_id, '_stripe_source_id', true );
437
+			$stripe_customer_id = get_user_meta($user_id, '_stripe_customer_id', true);
438
+			$stripe_source_id   = get_user_meta($user_id, '_stripe_source_id', true);
439 439
 
440 440
 			// For BW compat will remove in future.
441
-			if ( empty( $stripe_source_id ) ) {
442
-				$stripe_source_id = get_user_meta( $user_id, '_stripe_card_id', true );
441
+			if (empty($stripe_source_id)) {
442
+				$stripe_source_id = get_user_meta($user_id, '_stripe_card_id', true);
443 443
 
444 444
 				// Take this opportunity to update the key name.
445
-				update_user_meta( $user_id, '_stripe_source_id', $stripe_source_id );
445
+				update_user_meta($user_id, '_stripe_source_id', $stripe_source_id);
446 446
 			}
447 447
 		}
448 448
 
449 449
 		// If we couldn't find a Stripe customer linked to the account, fallback to the order meta data.
450
-		if ( ( ! $stripe_customer_id || ! is_string( $stripe_customer_id ) ) && false !== $subscription->order ) {
451
-			$stripe_customer_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id() ), '_stripe_customer_id', true );
452
-			$stripe_source_id   = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id() ), '_stripe_source_id', true );
450
+		if (( ! $stripe_customer_id || ! is_string($stripe_customer_id)) && false !== $subscription->order) {
451
+			$stripe_customer_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id()), '_stripe_customer_id', true);
452
+			$stripe_source_id   = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id()), '_stripe_source_id', true);
453 453
 
454 454
 			// For BW compat will remove in future.
455
-			if ( empty( $stripe_source_id ) ) {
456
-				$stripe_source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id() ), '_stripe_card_id', true );
455
+			if (empty($stripe_source_id)) {
456
+				$stripe_source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id()), '_stripe_card_id', true);
457 457
 
458 458
 				// Take this opportunity to update the key name.
459
-				WC_Stripe_Helper::is_pre_30() ? update_post_meta( $subscription->order->id, '_stripe_source_id', $stripe_source_id ) : update_post_meta( $subscription->get_parent_id(), '_stripe_source_id', $stripe_source_id );
459
+				WC_Stripe_Helper::is_pre_30() ? update_post_meta($subscription->order->id, '_stripe_source_id', $stripe_source_id) : update_post_meta($subscription->get_parent_id(), '_stripe_source_id', $stripe_source_id);
460 460
 			}
461 461
 		}
462 462
 
463
-		$stripe_customer->set_id( $stripe_customer_id );
463
+		$stripe_customer->set_id($stripe_customer_id);
464 464
 		$sources = $stripe_customer->get_sources();
465 465
 
466
-		if ( $sources ) {
466
+		if ($sources) {
467 467
 			$found_source = false;
468
-			foreach ( $sources as $source ) {
469
-				if ( isset( $source->type ) && 'card' === $source->type ) {
468
+			foreach ($sources as $source) {
469
+				if (isset($source->type) && 'card' === $source->type) {
470 470
 					$card = $source->card;
471
-				} elseif ( isset( $source->object ) && 'card' === $source->object ) {
471
+				} elseif (isset($source->object) && 'card' === $source->object) {
472 472
 					$card = $source;
473 473
 				}
474 474
 
475
-				if ( $source->id === $stripe_source_id ) {
475
+				if ($source->id === $stripe_source_id) {
476 476
 					$found_source = true;
477 477
 
478
-					if ( $card ) {
478
+					if ($card) {
479 479
 						/* translators: 1) card brand 2) last 4 digits */
480
-						$payment_method_to_display = sprintf( __( 'Via %1$s card ending in %2$s', 'woocommerce-gateway-stripe' ), ( isset( $card->brand ) ? $card->brand : __( 'N/A', 'woocommerce-gateway-stripe' ) ), $card->last4 );
480
+						$payment_method_to_display = sprintf(__('Via %1$s card ending in %2$s', 'woocommerce-gateway-stripe'), (isset($card->brand) ? $card->brand : __('N/A', 'woocommerce-gateway-stripe')), $card->last4);
481 481
 					} else {
482
-						$payment_method_to_display = __( 'N/A', 'woocommerce-gateway-stripe' );
482
+						$payment_method_to_display = __('N/A', 'woocommerce-gateway-stripe');
483 483
 					}
484 484
 					break;
485 485
 				}
486 486
 			}
487 487
 
488
-			if ( ! $found_source ) {
489
-				if ( 'card' === $sources[0]->type ) {
488
+			if ( ! $found_source) {
489
+				if ('card' === $sources[0]->type) {
490 490
 					$card = $sources[0]->card;
491 491
 				}
492 492
 
493
-				if ( $card ) {
493
+				if ($card) {
494 494
 					/* translators: 1) card brand 2) last 4 digits */
495
-					$payment_method_to_display = sprintf( __( 'Via %1$s card ending in %2$s', 'woocommerce-gateway-stripe' ), ( isset( $card->brand ) ? $card->brand : __( 'N/A', 'woocommerce-gateway-stripe' ) ), $card->last4 );
495
+					$payment_method_to_display = sprintf(__('Via %1$s card ending in %2$s', 'woocommerce-gateway-stripe'), (isset($card->brand) ? $card->brand : __('N/A', 'woocommerce-gateway-stripe')), $card->last4);
496 496
 				} else {
497
-					$payment_method_to_display = __( 'N/A', 'woocommerce-gateway-stripe' );
497
+					$payment_method_to_display = __('N/A', 'woocommerce-gateway-stripe');
498 498
 				}
499 499
 			}
500 500
 		}
@@ -507,42 +507,42 @@  discard block
 block discarded – undo
507 507
 	 * @param int $order_id
508 508
 	 * @return array
509 509
 	 */
510
-	public function process_pre_order( $order_id, $retry, $force_save_source ) {
511
-		if ( WC_Pre_Orders_Order::order_requires_payment_tokenization( $order_id ) ) {
510
+	public function process_pre_order($order_id, $retry, $force_save_source) {
511
+		if (WC_Pre_Orders_Order::order_requires_payment_tokenization($order_id)) {
512 512
 			try {
513
-				$order = wc_get_order( $order_id );
513
+				$order = wc_get_order($order_id);
514 514
 
515
-				if ( $order->get_total() * 100 < WC_Stripe_Helper::get_minimum_amount() ) {
515
+				if ($order->get_total() * 100 < WC_Stripe_Helper::get_minimum_amount()) {
516 516
 					/* translators: minimum amount */
517
-					throw new Exception( sprintf( __( 'Sorry, the minimum allowed order total is %1$s to use this payment method.', 'woocommerce-gateway-stripe' ), wc_price( WC_Stripe_Helper::get_minimum_amount() / 100 ) ) );
517
+					throw new Exception(sprintf(__('Sorry, the minimum allowed order total is %1$s to use this payment method.', 'woocommerce-gateway-stripe'), wc_price(WC_Stripe_Helper::get_minimum_amount() / 100)));
518 518
 				}
519 519
 
520
-				$source = $this->prepare_source( $this->get_source_object(), get_current_user_id(), true );
520
+				$source = $this->prepare_source($this->get_source_object(), get_current_user_id(), true);
521 521
 
522 522
 				// We need a source on file to continue.
523
-				if ( empty( $source->customer ) || empty( $source->source ) ) {
524
-					throw new Exception( __( 'Unable to store payment details. Please try again.', 'woocommerce-gateway-stripe' ) );
523
+				if (empty($source->customer) || empty($source->source)) {
524
+					throw new Exception(__('Unable to store payment details. Please try again.', 'woocommerce-gateway-stripe'));
525 525
 				}
526 526
 
527
-				$this->save_source_to_order( $order, $source );
527
+				$this->save_source_to_order($order, $source);
528 528
 
529 529
 				// Remove cart
530 530
 				WC()->cart->empty_cart();
531 531
 
532 532
 				// Is pre ordered!
533
-				WC_Pre_Orders_Order::mark_order_as_pre_ordered( $order );
533
+				WC_Pre_Orders_Order::mark_order_as_pre_ordered($order);
534 534
 
535 535
 				// Return thank you page redirect
536 536
 				return array(
537 537
 					'result'   => 'success',
538
-					'redirect' => $this->get_return_url( $order ),
538
+					'redirect' => $this->get_return_url($order),
539 539
 				);
540
-			} catch ( Exception $e ) {
541
-				wc_add_notice( $e->getMessage(), 'error' );
540
+			} catch (Exception $e) {
541
+				wc_add_notice($e->getMessage(), 'error');
542 542
 				return;
543 543
 			}
544 544
 		} else {
545
-			return parent::process_payment( $order_id, $retry, $force_save_source );
545
+			return parent::process_payment($order_id, $retry, $force_save_source);
546 546
 		}
547 547
 	}
548 548
 
@@ -551,7 +551,7 @@  discard block
 block discarded – undo
551 551
 	 * @param WC_Order $order
552 552
 	 * @return void
553 553
 	 */
554
-	public function process_pre_order_release_payment( $order ) {
554
+	public function process_pre_order_release_payment($order) {
555 555
 		try {
556 556
 			// Define some callbacks if the first attempt fails.
557 557
 			$retry_callbacks = array(
@@ -559,33 +559,33 @@  discard block
 block discarded – undo
559 559
 				'remove_order_customer_before_retry',
560 560
 			);
561 561
 
562
-			while ( 1 ) {
563
-				$source   = $this->prepare_order_source( $order );
564
-				$response = WC_Stripe_API::request( $this->generate_payment_request( $order, $source ) );
562
+			while (1) {
563
+				$source   = $this->prepare_order_source($order);
564
+				$response = WC_Stripe_API::request($this->generate_payment_request($order, $source));
565 565
 
566
-				if ( ! empty( $response->error ) ) {
567
-					if ( 0 === sizeof( $retry_callbacks ) ) {
568
-						throw new Exception( $response->error->message );
566
+				if ( ! empty($response->error)) {
567
+					if (0 === sizeof($retry_callbacks)) {
568
+						throw new Exception($response->error->message);
569 569
 					} else {
570
-						$retry_callback = array_shift( $retry_callbacks );
571
-						call_user_func( array( $this, $retry_callback ), $order );
570
+						$retry_callback = array_shift($retry_callbacks);
571
+						call_user_func(array($this, $retry_callback), $order);
572 572
 					}
573 573
 				} else {
574 574
 					// Successful
575
-					$this->process_response( $response, $order );
575
+					$this->process_response($response, $order);
576 576
 					break;
577 577
 				}
578 578
 			}
579
-		} catch ( Exception $e ) {
579
+		} catch (Exception $e) {
580 580
 			/* translators: error message */
581
-			$order_note = sprintf( __( 'Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe' ), $e->getMessage() );
581
+			$order_note = sprintf(__('Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe'), $e->getMessage());
582 582
 
583 583
 			// Mark order as failed if not already set,
584 584
 			// otherwise, make sure we add the order note so we can detect when someone fails to check out multiple times
585
-			if ( ! $order->has_status( 'failed' ) ) {
586
-				$order->update_status( 'failed', $order_note );
585
+			if ( ! $order->has_status('failed')) {
586
+				$order->update_status('failed', $order_note);
587 587
 			} else {
588
-				$order->add_order_note( $order_note );
588
+				$order->add_order_note($order_note);
589 589
 			}
590 590
 		}
591 591
 	}
Please login to merge, or discard this patch.
includes/class-wc-gateway-stripe.php 1 patch
Spacing   +175 added lines, -175 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
 
@@ -101,9 +101,9 @@  discard block
 block discarded – undo
101 101
 	public function __construct() {
102 102
 		$this->retry_interval       = 2;
103 103
 		$this->id                   = 'stripe';
104
-		$this->method_title         = __( 'Stripe', 'woocommerce-gateway-stripe' );
104
+		$this->method_title         = __('Stripe', 'woocommerce-gateway-stripe');
105 105
 		/* translators: 1) link to Stripe register page 2) link to Stripe api keys page */
106
-		$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' );
106
+		$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');
107 107
 		$this->has_fields           = true;
108 108
 		$this->supports             = array(
109 109
 			'products',
@@ -130,32 +130,32 @@  discard block
 block discarded – undo
130 130
 		$this->init_settings();
131 131
 
132 132
 		// Get setting values.
133
-		$this->title                   = $this->get_option( 'title' );
134
-		$this->description             = $this->get_option( 'description' );
135
-		$this->enabled                 = $this->get_option( 'enabled' );
136
-		$this->testmode                = 'yes' === $this->get_option( 'testmode' );
137
-		$this->inline_cc_form          = 'yes' === $this->get_option( 'inline_cc_form' );
138
-		$this->capture                 = 'yes' === $this->get_option( 'capture', 'yes' );
139
-		$this->statement_descriptor    = WC_Stripe_Helper::clean_statement_descriptor( $this->get_option( 'statement_descriptor' ) );
140
-		$this->three_d_secure          = 'yes' === $this->get_option( 'three_d_secure' );
141
-		$this->stripe_checkout         = 'yes' === $this->get_option( 'stripe_checkout' );
142
-		$this->stripe_checkout_image   = $this->get_option( 'stripe_checkout_image', '' );
143
-		$this->saved_cards             = 'yes' === $this->get_option( 'saved_cards' );
144
-		$this->secret_key              = $this->testmode ? $this->get_option( 'test_secret_key' ) : $this->get_option( 'secret_key' );
145
-		$this->publishable_key         = $this->testmode ? $this->get_option( 'test_publishable_key' ) : $this->get_option( 'publishable_key' );
146
-		$this->bitcoin                 = 'USD' === strtoupper( get_woocommerce_currency() ) && 'yes' === $this->get_option( 'stripe_bitcoin' );
147
-		$this->payment_request         = 'yes' === $this->get_option( 'payment_request', 'yes' );
148
-
149
-		if ( $this->stripe_checkout ) {
150
-			$this->order_button_text = __( 'Continue to payment', 'woocommerce-gateway-stripe' );
133
+		$this->title                   = $this->get_option('title');
134
+		$this->description             = $this->get_option('description');
135
+		$this->enabled                 = $this->get_option('enabled');
136
+		$this->testmode                = 'yes' === $this->get_option('testmode');
137
+		$this->inline_cc_form          = 'yes' === $this->get_option('inline_cc_form');
138
+		$this->capture                 = 'yes' === $this->get_option('capture', 'yes');
139
+		$this->statement_descriptor    = WC_Stripe_Helper::clean_statement_descriptor($this->get_option('statement_descriptor'));
140
+		$this->three_d_secure          = 'yes' === $this->get_option('three_d_secure');
141
+		$this->stripe_checkout         = 'yes' === $this->get_option('stripe_checkout');
142
+		$this->stripe_checkout_image   = $this->get_option('stripe_checkout_image', '');
143
+		$this->saved_cards             = 'yes' === $this->get_option('saved_cards');
144
+		$this->secret_key              = $this->testmode ? $this->get_option('test_secret_key') : $this->get_option('secret_key');
145
+		$this->publishable_key         = $this->testmode ? $this->get_option('test_publishable_key') : $this->get_option('publishable_key');
146
+		$this->bitcoin                 = 'USD' === strtoupper(get_woocommerce_currency()) && 'yes' === $this->get_option('stripe_bitcoin');
147
+		$this->payment_request         = 'yes' === $this->get_option('payment_request', 'yes');
148
+
149
+		if ($this->stripe_checkout) {
150
+			$this->order_button_text = __('Continue to payment', 'woocommerce-gateway-stripe');
151 151
 		}
152 152
 
153
-		WC_Stripe_API::set_secret_key( $this->secret_key );
153
+		WC_Stripe_API::set_secret_key($this->secret_key);
154 154
 
155 155
 		// Hooks.
156
-		add_action( 'wp_enqueue_scripts', array( $this, 'payment_scripts' ) );
157
-		add_action( 'admin_enqueue_scripts', array( $this, 'admin_scripts' ) );
158
-		add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) );
156
+		add_action('wp_enqueue_scripts', array($this, 'payment_scripts'));
157
+		add_action('admin_enqueue_scripts', array($this, 'admin_scripts'));
158
+		add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options'));
159 159
 	}
160 160
 
161 161
 	/**
@@ -164,7 +164,7 @@  discard block
 block discarded – undo
164 164
 	 * @since 4.0.2
165 165
 	 */
166 166
 	public function is_available() {
167
-		if ( is_add_payment_method_page() && ! $this->saved_cards ) {
167
+		if (is_add_payment_method_page() && ! $this->saved_cards) {
168 168
 			return false;
169 169
 		}
170 170
 
@@ -187,24 +187,24 @@  discard block
 block discarded – undo
187 187
 		$icons_str .= $icons['amex'];
188 188
 		$icons_str .= $icons['mastercard'];
189 189
 
190
-		if ( 'USD' === get_woocommerce_currency() ) {
190
+		if ('USD' === get_woocommerce_currency()) {
191 191
 			$icons_str .= $icons['discover'];
192 192
 			$icons_str .= $icons['jcb'];
193 193
 			$icons_str .= $icons['diners'];
194 194
 		}
195 195
 
196
-		if ( $this->bitcoin && $this->stripe_checkout ) {
196
+		if ($this->bitcoin && $this->stripe_checkout) {
197 197
 			$icons_str .= $icons['bitcoin'];
198 198
 		}
199 199
 
200
-		return apply_filters( 'woocommerce_gateway_icon', $icons_str, $this->id );
200
+		return apply_filters('woocommerce_gateway_icon', $icons_str, $this->id);
201 201
 	}
202 202
 
203 203
 	/**
204 204
 	 * Initialise Gateway Settings Form Fields
205 205
 	 */
206 206
 	public function init_form_fields() {
207
-		$this->form_fields = require( dirname( __FILE__ ) . '/admin/stripe-settings.php' );
207
+		$this->form_fields = require(dirname(__FILE__) . '/admin/stripe-settings.php');
208 208
 	}
209 209
 
210 210
 	/**
@@ -212,68 +212,68 @@  discard block
 block discarded – undo
212 212
 	 */
213 213
 	public function payment_fields() {
214 214
 		$user                 = wp_get_current_user();
215
-		$display_tokenization = $this->supports( 'tokenization' ) && is_checkout() && $this->saved_cards;
215
+		$display_tokenization = $this->supports('tokenization') && is_checkout() && $this->saved_cards;
216 216
 		$total                = WC()->cart->total;
217 217
 		$user_email           = '';
218 218
 
219 219
 		// If paying from order, we need to get total from order not cart.
220
-		if ( isset( $_GET['pay_for_order'] ) && ! empty( $_GET['key'] ) ) {
221
-			$order      = wc_get_order( wc_get_order_id_by_order_key( wc_clean( $_GET['key'] ) ) );
220
+		if (isset($_GET['pay_for_order']) && ! empty($_GET['key'])) {
221
+			$order      = wc_get_order(wc_get_order_id_by_order_key(wc_clean($_GET['key'])));
222 222
 			$total      = $order->get_total();
223 223
 			$user_email = WC_Stripe_Helper::is_pre_30() ? $order->billing_email : $order->get_billing_email();
224 224
 		} else {
225
-			if ( $user->ID ) {
226
-				$user_email = get_user_meta( $user->ID, 'billing_email', true );
225
+			if ($user->ID) {
226
+				$user_email = get_user_meta($user->ID, 'billing_email', true);
227 227
 				$user_email = $user_email ? $user_email : $user->user_email;
228 228
 			}
229 229
 		}
230 230
 
231
-		if ( is_add_payment_method_page() ) {
232
-			$pay_button_text = __( 'Add Card', 'woocommerce-gateway-stripe' );
233
-			$total        = '';
231
+		if (is_add_payment_method_page()) {
232
+			$pay_button_text = __('Add Card', 'woocommerce-gateway-stripe');
233
+			$total = '';
234 234
 		} else {
235 235
 			$pay_button_text = '';
236 236
 		}
237 237
 
238 238
 		echo '<div
239 239
 			id="stripe-payment-data"
240
-			data-panel-label="' . esc_attr( $pay_button_text ) . '"
240
+			data-panel-label="' . esc_attr($pay_button_text) . '"
241 241
 			data-description=""
242
-			data-email="' . esc_attr( $user_email ) . '"
243
-			data-amount="' . esc_attr( WC_Stripe_Helper::get_stripe_amount( $total ) ) . '"
244
-			data-name="' . esc_attr( $this->statement_descriptor ) . '"
245
-			data-currency="' . esc_attr( strtolower( get_woocommerce_currency() ) ) . '"
246
-			data-image="' . esc_attr( $this->stripe_checkout_image ) . '"
247
-			data-bitcoin="' . esc_attr( ( $this->bitcoin && $this->capture ) ? 'true' : 'false' ) . '"
248
-			data-locale="' . esc_attr( apply_filters( 'wc_stripe_checkout_locale', substr( get_locale(), 0, 2 ) ) ) . '"
249
-			data-three-d-secure="' . esc_attr( $this->three_d_secure ? 'true' : 'false' ) . '"
250
-			data-allow-remember-me="' . esc_attr( $this->saved_cards ? 'true' : 'false' ) . '">';
251
-
252
-		if ( $this->description ) {
253
-			if ( $this->testmode ) {
242
+			data-email="' . esc_attr($user_email) . '"
243
+			data-amount="' . esc_attr(WC_Stripe_Helper::get_stripe_amount($total)) . '"
244
+			data-name="' . esc_attr($this->statement_descriptor) . '"
245
+			data-currency="' . esc_attr(strtolower(get_woocommerce_currency())) . '"
246
+			data-image="' . esc_attr($this->stripe_checkout_image) . '"
247
+			data-bitcoin="' . esc_attr(($this->bitcoin && $this->capture) ? 'true' : 'false') . '"
248
+			data-locale="' . esc_attr(apply_filters('wc_stripe_checkout_locale', substr(get_locale(), 0, 2))) . '"
249
+			data-three-d-secure="' . esc_attr($this->three_d_secure ? 'true' : 'false') . '"
250
+			data-allow-remember-me="' . esc_attr($this->saved_cards ? 'true' : 'false') . '">';
251
+
252
+		if ($this->description) {
253
+			if ($this->testmode) {
254 254
 				/* translators: link to Stripe testing page */
255
-				$this->description .= ' ' . sprintf( __( 'TEST MODE ENABLED. In test mode, you can use the card number 4242424242424242 with any CVC and a valid expiration date or check the documentation "<a href="%s" target="_blank">Testing Stripe</a>" for more card numbers.', 'woocommerce-gateway-stripe' ), 'https://stripe.com/docs/testing' );
256
-				$this->description  = trim( $this->description );
255
+				$this->description .= ' ' . sprintf(__('TEST MODE ENABLED. In test mode, you can use the card number 4242424242424242 with any CVC and a valid expiration date or check the documentation "<a href="%s" target="_blank">Testing Stripe</a>" for more card numbers.', 'woocommerce-gateway-stripe'), 'https://stripe.com/docs/testing');
256
+				$this->description  = trim($this->description);
257 257
 			}
258
-			echo apply_filters( 'wc_stripe_description', wpautop( wp_kses_post( $this->description ) ) );
258
+			echo apply_filters('wc_stripe_description', wpautop(wp_kses_post($this->description)));
259 259
 		}
260 260
 
261
-		if ( $display_tokenization ) {
261
+		if ($display_tokenization) {
262 262
 			$this->tokenization_script();
263 263
 			$this->saved_payment_methods();
264 264
 		}
265 265
 
266
-		if ( ! $this->stripe_checkout ) {
267
-			if ( apply_filters( 'wc_stripe_use_elements_checkout_form', true ) ) {
266
+		if ( ! $this->stripe_checkout) {
267
+			if (apply_filters('wc_stripe_use_elements_checkout_form', true)) {
268 268
 				$this->elements_form();
269 269
 			} else {
270
-				WC_Stripe_Logger::log( 'DEPRECATED! Since version 4.0. Stripe Elements is used. This legacy credit card form will be removed by version 4.1!' );
270
+				WC_Stripe_Logger::log('DEPRECATED! Since version 4.0. Stripe Elements is used. This legacy credit card form will be removed by version 4.1!');
271 271
 				$this->form();
272 272
 				echo '<div class="stripe-source-errors" role="alert"></div>';
273 273
 			}
274 274
 		}
275 275
 
276
-		if ( apply_filters( 'wc_stripe_display_save_payment_method_checkbox', $display_tokenization ) && ! is_add_payment_method_page() && ! isset( $_GET['change_payment_method'] ) ) {
276
+		if (apply_filters('wc_stripe_display_save_payment_method_checkbox', $display_tokenization) && ! is_add_payment_method_page() && ! isset($_GET['change_payment_method'])) {
277 277
 			$this->save_payment_method_checkbox();
278 278
 		}
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" style="background:#fff;padding:0 1em;border:1px solid #ddd;margin:5px 0;padding:10px 5px;">
@@ -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><?php _e( 'Card Number', 'woocommerce-gateway-stripe' ); ?> <span class="required">*</span></label>
304
+					<label><?php _e('Card Number', 'woocommerce-gateway-stripe'); ?> <span class="required">*</span></label>
305 305
 
306 306
 					<div id="stripe-card-element" style="background:#fff;padding:0 1em;border:1px solid #ddd;margin:5px 0;padding:10px 5px;">
307 307
 					<!-- a Stripe Element will be inserted here. -->
@@ -309,7 +309,7 @@  discard block
 block discarded – undo
309 309
 				</div>
310 310
 
311 311
 				<div class="form-row form-row-first">
312
-					<label><?php _e( 'Expiry Date', 'woocommerce-gateway-stripe' ); ?> <span class="required">*</span></label>
312
+					<label><?php _e('Expiry Date', 'woocommerce-gateway-stripe'); ?> <span class="required">*</span></label>
313 313
 
314 314
 					<div id="stripe-exp-element" style="background:#fff;padding:0 1em;border:1px solid #ddd;margin:5px 0;padding:10px 5px;">
315 315
 					<!-- a Stripe Element will be inserted here. -->
@@ -317,7 +317,7 @@  discard block
 block discarded – undo
317 317
 				</div>
318 318
 
319 319
 				<div class="form-row form-row-last">
320
-					<label><?php _e( 'Card Code (CVC)', 'woocommerce-gateway-stripe' ); ?> <span class="required">*</span></label>
320
+					<label><?php _e('Card Code (CVC)', 'woocommerce-gateway-stripe'); ?> <span class="required">*</span></label>
321 321
 				<div id="stripe-cvc-element" style="background:#fff;padding:0 1em;border:1px solid #ddd;margin:5px 0;padding:10px 5px;">
322 322
 				<!-- a Stripe Element will be inserted here. -->
323 323
 				</div>
@@ -327,7 +327,7 @@  discard block
 block discarded – undo
327 327
 
328 328
 			<!-- Used to display form errors -->
329 329
 			<div class="stripe-source-errors" role="alert"></div>
330
-			<?php do_action( 'woocommerce_credit_card_form_end', $this->id ); ?>
330
+			<?php do_action('woocommerce_credit_card_form_end', $this->id); ?>
331 331
 			<div class="clear"></div>
332 332
 		</fieldset>
333 333
 		<?php
@@ -340,13 +340,13 @@  discard block
 block discarded – undo
340 340
 	 * @version 3.1.0
341 341
 	 */
342 342
 	public function admin_scripts() {
343
-		if ( 'woocommerce_page_wc-settings' !== get_current_screen()->id ) {
343
+		if ('woocommerce_page_wc-settings' !== get_current_screen()->id) {
344 344
 			return;
345 345
 		}
346 346
 
347
-		$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
347
+		$suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';
348 348
 
349
-		wp_enqueue_script( 'woocommerce_stripe_admin', plugins_url( 'assets/js/stripe-admin' . $suffix . '.js', WC_STRIPE_MAIN_FILE ), array(), WC_STRIPE_VERSION, true );
349
+		wp_enqueue_script('woocommerce_stripe_admin', plugins_url('assets/js/stripe-admin' . $suffix . '.js', WC_STRIPE_MAIN_FILE), array(), WC_STRIPE_VERSION, true);
350 350
 	}
351 351
 
352 352
 	/**
@@ -358,33 +358,33 @@  discard block
 block discarded – undo
358 358
 	 * @version 4.0.0
359 359
 	 */
360 360
 	public function payment_scripts() {
361
-		if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) && ! is_add_payment_method_page() && ! isset( $_GET['change_payment_method'] ) ) {
361
+		if ( ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order']) && ! is_add_payment_method_page() && ! isset($_GET['change_payment_method'])) {
362 362
 			return;
363 363
 		}
364 364
 
365
-		if ( 'no' === $this->enabled ) {
365
+		if ('no' === $this->enabled) {
366 366
 			return;
367 367
 		}
368 368
 
369
-		$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
369
+		$suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';
370 370
 
371
-		wp_register_style( 'stripe_paymentfonts', plugins_url( 'assets/css/stripe-paymentfonts.css', WC_STRIPE_MAIN_FILE ), array(), '1.2.5' );
372
-		wp_enqueue_style( 'stripe_paymentfonts' );
373
-		wp_register_script( 'stripe_checkout', 'https://checkout.stripe.com/checkout.js', '', WC_STRIPE_VERSION, true );
374
-		wp_register_script( 'stripev2', 'https://js.stripe.com/v2/', '', '2.0', true );
375
-		wp_register_script( 'stripe', 'https://js.stripe.com/v3/', '', '3.0', true );
376
-		wp_register_script( 'woocommerce_stripe', plugins_url( 'assets/js/stripe' . $suffix . '.js', WC_STRIPE_MAIN_FILE ), array( 'jquery-payment', 'stripev2', 'stripe' ), WC_STRIPE_VERSION, true );
371
+		wp_register_style('stripe_paymentfonts', plugins_url('assets/css/stripe-paymentfonts.css', WC_STRIPE_MAIN_FILE), array(), '1.2.5');
372
+		wp_enqueue_style('stripe_paymentfonts');
373
+		wp_register_script('stripe_checkout', 'https://checkout.stripe.com/checkout.js', '', WC_STRIPE_VERSION, true);
374
+		wp_register_script('stripev2', 'https://js.stripe.com/v2/', '', '2.0', true);
375
+		wp_register_script('stripe', 'https://js.stripe.com/v3/', '', '3.0', true);
376
+		wp_register_script('woocommerce_stripe', plugins_url('assets/js/stripe' . $suffix . '.js', WC_STRIPE_MAIN_FILE), array('jquery-payment', 'stripev2', 'stripe'), WC_STRIPE_VERSION, true);
377 377
 
378 378
 		$stripe_params = array(
379 379
 			'key'                  => $this->publishable_key,
380
-			'i18n_terms'           => __( 'Please accept the terms and conditions first', 'woocommerce-gateway-stripe' ),
381
-			'i18n_required_fields' => __( 'Please fill in required checkout fields first', 'woocommerce-gateway-stripe' ),
380
+			'i18n_terms'           => __('Please accept the terms and conditions first', 'woocommerce-gateway-stripe'),
381
+			'i18n_required_fields' => __('Please fill in required checkout fields first', 'woocommerce-gateway-stripe'),
382 382
 		);
383 383
 
384 384
 		// If we're on the pay page we need to pass stripe.js the address of the order.
385
-		if ( isset( $_GET['pay_for_order'] ) && 'true' === $_GET['pay_for_order'] ) {
386
-			$order_id = wc_get_order_id_by_order_key( urldecode( $_GET['key'] ) );
387
-			$order    = wc_get_order( $order_id );
385
+		if (isset($_GET['pay_for_order']) && 'true' === $_GET['pay_for_order']) {
386
+			$order_id = wc_get_order_id_by_order_key(urldecode($_GET['key']));
387
+			$order    = wc_get_order($order_id);
388 388
 
389 389
 			$stripe_params['billing_first_name'] = WC_Stripe_Helper::is_pre_30() ? $order->billing_first_name : $order->get_billing_first_name();
390 390
 			$stripe_params['billing_last_name']  = WC_Stripe_Helper::is_pre_30() ? $order->billing_last_name : $order->get_billing_last_name();
@@ -396,38 +396,38 @@  discard block
 block discarded – undo
396 396
 			$stripe_params['billing_country']    = WC_Stripe_Helper::is_pre_30() ? $order->billing_country : $order->get_billing_country();
397 397
 		}
398 398
 
399
-		$stripe_params['no_prepaid_card_msg']                     = __( 'Sorry, we\'re not accepting prepaid cards at this time. Your credit card has not been charge. Please try with alternative payment method.', 'woocommerce-gateway-stripe' );
400
-		$stripe_params['no_sepa_owner_msg']                       = __( 'Please enter your IBAN account name.', 'woocommerce-gateway-stripe' );
401
-		$stripe_params['no_sepa_iban_msg']                        = __( 'Please enter your IBAN account number.', 'woocommerce-gateway-stripe' );
402
-		$stripe_params['sepa_mandate_notification']               = apply_filters( 'wc_stripe_sepa_mandate_notification', 'email' );
403
-		$stripe_params['allow_prepaid_card']                      = apply_filters( 'wc_stripe_allow_prepaid_card', true ) ? 'yes' : 'no';
399
+		$stripe_params['no_prepaid_card_msg']                     = __('Sorry, we\'re not accepting prepaid cards at this time. Your credit card has not been charge. Please try with alternative payment method.', 'woocommerce-gateway-stripe');
400
+		$stripe_params['no_sepa_owner_msg']                       = __('Please enter your IBAN account name.', 'woocommerce-gateway-stripe');
401
+		$stripe_params['no_sepa_iban_msg']                        = __('Please enter your IBAN account number.', 'woocommerce-gateway-stripe');
402
+		$stripe_params['sepa_mandate_notification']               = apply_filters('wc_stripe_sepa_mandate_notification', 'email');
403
+		$stripe_params['allow_prepaid_card']                      = apply_filters('wc_stripe_allow_prepaid_card', true) ? 'yes' : 'no';
404 404
 		$stripe_params['inline_cc_form']                          = $this->inline_cc_form ? 'yes' : 'no';
405
-		$stripe_params['stripe_checkout_require_billing_address'] = apply_filters( 'wc_stripe_checkout_require_billing_address', false ) ? 'yes' : 'no';
406
-		$stripe_params['is_checkout']                             = ( is_checkout() && empty( $_GET['pay_for_order'] ) );
405
+		$stripe_params['stripe_checkout_require_billing_address'] = apply_filters('wc_stripe_checkout_require_billing_address', false) ? 'yes' : 'no';
406
+		$stripe_params['is_checkout']                             = (is_checkout() && empty($_GET['pay_for_order']));
407 407
 		$stripe_params['return_url']                              = $this->get_stripe_return_url();
408
-		$stripe_params['ajaxurl']                                 = WC_AJAX::get_endpoint( '%%endpoint%%' );
409
-		$stripe_params['stripe_nonce']                            = wp_create_nonce( '_wc_stripe_nonce' );
408
+		$stripe_params['ajaxurl']                                 = WC_AJAX::get_endpoint('%%endpoint%%');
409
+		$stripe_params['stripe_nonce']                            = wp_create_nonce('_wc_stripe_nonce');
410 410
 		$stripe_params['statement_descriptor']                    = $this->statement_descriptor;
411
-		$stripe_params['use_elements']                            = apply_filters( 'wc_stripe_use_elements_checkout_form', true ) ? 'yes' : 'no';
412
-		$stripe_params['elements_options']                        = apply_filters( 'wc_stripe_elements_options', array() );
411
+		$stripe_params['use_elements']                            = apply_filters('wc_stripe_use_elements_checkout_form', true) ? 'yes' : 'no';
412
+		$stripe_params['elements_options']                        = apply_filters('wc_stripe_elements_options', array());
413 413
 		$stripe_params['is_stripe_checkout']                      = $this->stripe_checkout ? 'yes' : 'no';
414
-		$stripe_params['is_change_payment_page']                  = isset( $_GET['change_payment_method'] ) ? 'yes' : 'no';
415
-		$stripe_params['validate_modal_checkout']                 = apply_filters( 'wc_stripe_validate_model_checkout', true ) ? 'yes' : 'no';
416
-		$stripe_params['elements_styling']                        = apply_filters( 'wc_stripe_elements_styling', false );
417
-		$stripe_params['elements_classes']                        = apply_filters( 'wc_stripe_elements_classes', false );
414
+		$stripe_params['is_change_payment_page']                  = isset($_GET['change_payment_method']) ? 'yes' : 'no';
415
+		$stripe_params['validate_modal_checkout']                 = apply_filters('wc_stripe_validate_model_checkout', true) ? 'yes' : 'no';
416
+		$stripe_params['elements_styling']                        = apply_filters('wc_stripe_elements_styling', false);
417
+		$stripe_params['elements_classes']                        = apply_filters('wc_stripe_elements_classes', false);
418 418
 
419 419
 		// merge localized messages to be use in JS
420
-		$stripe_params = array_merge( $stripe_params, WC_Stripe_Helper::get_localized_messages() );
420
+		$stripe_params = array_merge($stripe_params, WC_Stripe_Helper::get_localized_messages());
421 421
 
422
-		wp_localize_script( 'woocommerce_stripe', 'wc_stripe_params', apply_filters( 'wc_stripe_params', $stripe_params ) );
423
-		wp_localize_script( 'woocommerce_stripe_checkout', 'wc_stripe_params', apply_filters( 'wc_stripe_params', $stripe_params ) );
422
+		wp_localize_script('woocommerce_stripe', 'wc_stripe_params', apply_filters('wc_stripe_params', $stripe_params));
423
+		wp_localize_script('woocommerce_stripe_checkout', 'wc_stripe_params', apply_filters('wc_stripe_params', $stripe_params));
424 424
 
425
-		if ( $this->stripe_checkout ) {
426
-			wp_enqueue_script( 'stripe_checkout' );
425
+		if ($this->stripe_checkout) {
426
+			wp_enqueue_script('stripe_checkout');
427 427
 		}
428 428
 
429 429
 		$this->tokenization_script();
430
-		wp_enqueue_script( 'woocommerce_stripe' );
430
+		wp_enqueue_script('woocommerce_stripe');
431 431
 	}
432 432
 
433 433
 	/**
@@ -443,43 +443,43 @@  discard block
 block discarded – undo
443 443
 	 *
444 444
 	 * @return array|void
445 445
 	 */
446
-	public function process_payment( $order_id, $retry = true, $force_save_source = false ) {
446
+	public function process_payment($order_id, $retry = true, $force_save_source = false) {
447 447
 		try {
448
-			$order = wc_get_order( $order_id );
448
+			$order = wc_get_order($order_id);
449 449
 
450 450
 			// This comes from the create account checkbox in the checkout page.
451
-			$create_account = ! empty( $_POST['createaccount'] ) ? true : false;
451
+			$create_account = ! empty($_POST['createaccount']) ? true : false;
452 452
 
453
-			if ( $create_account ) {
453
+			if ($create_account) {
454 454
 				$new_customer_id     = WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id();
455
-				$new_stripe_customer = new WC_Stripe_Customer( $new_customer_id );
455
+				$new_stripe_customer = new WC_Stripe_Customer($new_customer_id);
456 456
 				$new_stripe_customer->create_customer();
457 457
 			}
458 458
 
459 459
 			$source_object   = $this->get_source_object();
460
-			$prepared_source = $this->prepare_source( $source_object, get_current_user_id(), $force_save_source );
460
+			$prepared_source = $this->prepare_source($source_object, get_current_user_id(), $force_save_source);
461 461
 
462 462
 			// Check if we don't allow prepaid credit cards.
463
-			if ( ! apply_filters( 'wc_stripe_allow_prepaid_card', true ) ) {
464
-				if ( $source_object && 'token' === $source_object->object && 'prepaid' === $source_object->card->funding ) {
465
-					$localized_message = __( 'Sorry, we\'re not accepting prepaid cards at this time. Your credit card has not been charge. Please try with alternative payment method.', 'woocommerce-gateway-stripe' );
466
-					throw new WC_Stripe_Exception( print_r( $source_object, true ), $localized_message );
463
+			if ( ! apply_filters('wc_stripe_allow_prepaid_card', true)) {
464
+				if ($source_object && 'token' === $source_object->object && 'prepaid' === $source_object->card->funding) {
465
+					$localized_message = __('Sorry, we\'re not accepting prepaid cards at this time. Your credit card has not been charge. Please try with alternative payment method.', 'woocommerce-gateway-stripe');
466
+					throw new WC_Stripe_Exception(print_r($source_object, true), $localized_message);
467 467
 				}
468 468
 			}
469 469
 
470
-			if ( empty( $prepared_source->source ) ) {
471
-				$localized_message = __( 'Payment processing failed. Please retry.', 'woocommerce-gateway-stripe' );
472
-				throw new WC_Stripe_Exception( print_r( $prepared_source, true ), $localized_message );
470
+			if (empty($prepared_source->source)) {
471
+				$localized_message = __('Payment processing failed. Please retry.', 'woocommerce-gateway-stripe');
472
+				throw new WC_Stripe_Exception(print_r($prepared_source, true), $localized_message);
473 473
 			}
474 474
 
475
-			$this->save_source_to_order( $order, $prepared_source );
475
+			$this->save_source_to_order($order, $prepared_source);
476 476
 
477 477
 			// Result from Stripe API request.
478 478
 			$response = null;
479 479
 
480
-			if ( $order->get_total() > 0 ) {
480
+			if ($order->get_total() > 0) {
481 481
 				// This will throw exception if not valid.
482
-				$this->validate_minimum_order_amount( $order );
482
+				$this->validate_minimum_order_amount($order);
483 483
 
484 484
 				/*
485 485
 				 * Check if card 3DS is required or optional with 3DS setting.
@@ -488,109 +488,109 @@  discard block
 block discarded – undo
488 488
 				 * Note that if we need to save source, the original source must be first
489 489
 				 * attached to a customer in Stripe before it can be charged.
490 490
 				 */
491
-				if ( $this->is_3ds_required( $source_object ) ) {
492
-					$response = $this->create_3ds_source( $order, $source_object );
491
+				if ($this->is_3ds_required($source_object)) {
492
+					$response = $this->create_3ds_source($order, $source_object);
493 493
 
494
-					if ( ! empty( $response->error ) ) {
494
+					if ( ! empty($response->error)) {
495 495
 						$localized_message = $response->error->message;
496 496
 
497
-						$order->add_order_note( $localized_message );
497
+						$order->add_order_note($localized_message);
498 498
 
499
-						throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message );
499
+						throw new WC_Stripe_Exception(print_r($response, true), $localized_message);
500 500
 					}
501 501
 
502 502
 					// Update order meta with 3DS source.
503
-					if ( WC_Stripe_Helper::is_pre_30() ) {
504
-						update_post_meta( $order_id, '_stripe_source_id', $response->id );
503
+					if (WC_Stripe_Helper::is_pre_30()) {
504
+						update_post_meta($order_id, '_stripe_source_id', $response->id);
505 505
 					} else {
506
-						$order->update_meta_data( '_stripe_source_id', $response->id );
506
+						$order->update_meta_data('_stripe_source_id', $response->id);
507 507
 						$order->save();
508 508
 					}
509 509
 
510
-					WC_Stripe_Logger::log( 'Info: Redirecting to 3DS...' );
510
+					WC_Stripe_Logger::log('Info: Redirecting to 3DS...');
511 511
 
512 512
 					return array(
513 513
 						'result'   => 'success',
514
-						'redirect' => esc_url_raw( $response->redirect->url ),
514
+						'redirect' => esc_url_raw($response->redirect->url),
515 515
 					);
516 516
 				}
517 517
 
518
-				WC_Stripe_Logger::log( "Info: Begin processing payment for order $order_id for the amount of {$order->get_total()}" );
518
+				WC_Stripe_Logger::log("Info: Begin processing payment for order $order_id for the amount of {$order->get_total()}");
519 519
 
520 520
 				// Make the request.
521
-				$response = WC_Stripe_API::request( $this->generate_payment_request( $order, $prepared_source ) );
521
+				$response = WC_Stripe_API::request($this->generate_payment_request($order, $prepared_source));
522 522
 
523
-				if ( ! empty( $response->error ) ) {
523
+				if ( ! empty($response->error)) {
524 524
 					// If it is an API error such connection or server, let's retry.
525
-					if ( 'api_connection_error' === $response->error->type || 'api_error' === $response->error->type ) {
526
-						if ( $retry ) {
527
-							sleep( 5 );
528
-							return $this->process_payment( $order_id, false, $force_save_source );
525
+					if ('api_connection_error' === $response->error->type || 'api_error' === $response->error->type) {
526
+						if ($retry) {
527
+							sleep(5);
528
+							return $this->process_payment($order_id, false, $force_save_source);
529 529
 						} else {
530 530
 							$localized_message = 'API connection error and retries exhausted.';
531
-							$order->add_order_note( $localized_message );
532
-							throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message );
531
+							$order->add_order_note($localized_message);
532
+							throw new WC_Stripe_Exception(print_r($response, true), $localized_message);
533 533
 						}
534 534
 					}
535 535
 
536 536
 					// We want to retry.
537
-					if ( $this->is_retryable_error( $response->error ) ) {
538
-						if ( $retry ) {
537
+					if ($this->is_retryable_error($response->error)) {
538
+						if ($retry) {
539 539
 							// Don't do anymore retries after this.
540
-							if ( 5 <= $this->retry_interval ) {
540
+							if (5 <= $this->retry_interval) {
541 541
 
542
-								return $this->process_payment( $order_id, false, $force_save_source );
542
+								return $this->process_payment($order_id, false, $force_save_source);
543 543
 							}
544 544
 
545
-							sleep( $this->retry_interval );
545
+							sleep($this->retry_interval);
546 546
 
547 547
 							$this->retry_interval++;
548
-							return $this->process_payment( $order_id, true, $force_save_source );
548
+							return $this->process_payment($order_id, true, $force_save_source);
549 549
 						} else {
550
-							$localized_message = __( 'On going requests error and retries exhausted.', 'woocommerce-gateway-stripe' );
551
-							$order->add_order_note( $localized_message );
552
-							throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message );
550
+							$localized_message = __('On going requests error and retries exhausted.', 'woocommerce-gateway-stripe');
551
+							$order->add_order_note($localized_message);
552
+							throw new WC_Stripe_Exception(print_r($response, true), $localized_message);
553 553
 						}
554 554
 					}
555 555
 
556 556
 					// Customer param wrong? The user may have been deleted on stripe's end. Remove customer_id. Can be retried without.
557
-					if ( preg_match( '/No such customer/i', $response->error->message ) && $retry ) {
558
-						if ( WC_Stripe_Helper::is_pre_30() ) {
559
-							delete_user_meta( $order->customer_user, '_stripe_customer_id' );
560
-							delete_post_meta( $order_id, '_stripe_customer_id' );
557
+					if (preg_match('/No such customer/i', $response->error->message) && $retry) {
558
+						if (WC_Stripe_Helper::is_pre_30()) {
559
+							delete_user_meta($order->customer_user, '_stripe_customer_id');
560
+							delete_post_meta($order_id, '_stripe_customer_id');
561 561
 						} else {
562
-							delete_user_meta( $order->get_customer_id(), '_stripe_customer_id' );
563
-							$order->delete_meta_data( '_stripe_customer_id' );
562
+							delete_user_meta($order->get_customer_id(), '_stripe_customer_id');
563
+							$order->delete_meta_data('_stripe_customer_id');
564 564
 							$order->save();
565 565
 						}
566 566
 
567
-						return $this->process_payment( $order_id, false, $force_save_source );
568
-					} elseif ( preg_match( '/No such token/i', $response->error->message ) && $prepared_source->token_id ) {
567
+						return $this->process_payment($order_id, false, $force_save_source);
568
+					} elseif (preg_match('/No such token/i', $response->error->message) && $prepared_source->token_id) {
569 569
 						// Source param wrong? The CARD may have been deleted on stripe's end. Remove token and show message.
570
-						$wc_token = WC_Payment_Tokens::get( $prepared_source->token_id );
570
+						$wc_token = WC_Payment_Tokens::get($prepared_source->token_id);
571 571
 						$wc_token->delete();
572
-						$localized_message = __( 'This card is no longer available and has been removed.', 'woocommerce-gateway-stripe' );
573
-						$order->add_order_note( $localized_message );
574
-						throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message );
572
+						$localized_message = __('This card is no longer available and has been removed.', 'woocommerce-gateway-stripe');
573
+						$order->add_order_note($localized_message);
574
+						throw new WC_Stripe_Exception(print_r($response, true), $localized_message);
575 575
 					}
576 576
 
577 577
 					$localized_messages = WC_Stripe_Helper::get_localized_messages();
578 578
 
579
-					if ( 'card_error' === $response->error->type ) {
580
-						$localized_message = isset( $localized_messages[ $response->error->code ] ) ? $localized_messages[ $response->error->code ] : $response->error->message;
579
+					if ('card_error' === $response->error->type) {
580
+						$localized_message = isset($localized_messages[$response->error->code]) ? $localized_messages[$response->error->code] : $response->error->message;
581 581
 					} else {
582
-						$localized_message = isset( $localized_messages[ $response->error->type ] ) ? $localized_messages[ $response->error->type ] : $response->error->message;
582
+						$localized_message = isset($localized_messages[$response->error->type]) ? $localized_messages[$response->error->type] : $response->error->message;
583 583
 					}
584 584
 
585
-					$order->add_order_note( $localized_message );
585
+					$order->add_order_note($localized_message);
586 586
 
587
-					throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message );
587
+					throw new WC_Stripe_Exception(print_r($response, true), $localized_message);
588 588
 				}
589 589
 
590
-				do_action( 'wc_gateway_stripe_process_payment', $response, $order );
590
+				do_action('wc_gateway_stripe_process_payment', $response, $order);
591 591
 
592 592
 				// Process valid response.
593
-				$this->process_response( $response, $order );
593
+				$this->process_response($response, $order);
594 594
 			} else {
595 595
 				$order->payment_complete();
596 596
 			}
@@ -601,17 +601,17 @@  discard block
 block discarded – undo
601 601
 			// Return thank you page redirect.
602 602
 			return array(
603 603
 				'result'   => 'success',
604
-				'redirect' => $this->get_return_url( $order ),
604
+				'redirect' => $this->get_return_url($order),
605 605
 			);
606 606
 
607
-		} catch ( WC_Stripe_Exception $e ) {
608
-			wc_add_notice( $e->getLocalizedMessage(), 'error' );
609
-			WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() );
607
+		} catch (WC_Stripe_Exception $e) {
608
+			wc_add_notice($e->getLocalizedMessage(), 'error');
609
+			WC_Stripe_Logger::log('Error: ' . $e->getMessage());
610 610
 
611
-			do_action( 'wc_gateway_stripe_process_payment_error', $e, $order );
611
+			do_action('wc_gateway_stripe_process_payment_error', $e, $order);
612 612
 
613
-			if ( $order->has_status( array( 'pending', 'failed' ) ) ) {
614
-				$this->send_failed_order_email( $order_id );
613
+			if ($order->has_status(array('pending', 'failed'))) {
614
+				$this->send_failed_order_email($order_id);
615 615
 			}
616 616
 
617 617
 			return array(
Please login to merge, or discard this patch.
includes/abstracts/abstract-wc-stripe-payment-gateway.php 1 patch
Spacing   +205 added lines, -206 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
 
@@ -21,7 +21,7 @@  discard block
 block discarded – undo
21 21
 	 * @since 4.0.5
22 22
 	 * @param array $error
23 23
 	 */
24
-	public function is_retryable_error( $error ) {
24
+	public function is_retryable_error($error) {
25 25
 		return (
26 26
 			'invalid_request_error' === $error->type ||
27 27
 			'idempotency_error' === $error->type ||
@@ -33,11 +33,11 @@  discard block
 block discarded – undo
33 33
 	 * Check if this gateway is enabled
34 34
 	 */
35 35
 	public function is_available() {
36
-		if ( 'yes' === $this->enabled ) {
37
-			if ( ! $this->testmode && is_checkout() && ! is_ssl() ) {
36
+		if ('yes' === $this->enabled) {
37
+			if ( ! $this->testmode && is_checkout() && ! is_ssl()) {
38 38
 				return false;
39 39
 			}
40
-			if ( ! $this->secret_key || ! $this->publishable_key ) {
40
+			if ( ! $this->secret_key || ! $this->publishable_key) {
41 41
 				return false;
42 42
 			}
43 43
 			return true;
@@ -52,8 +52,8 @@  discard block
 block discarded – undo
52 52
 	 * @since 4.0.0
53 53
 	 * @version 4.0.0
54 54
 	 */
55
-	public function add_admin_notice( $slug, $class, $message ) {
56
-		$this->notices[ $slug ] = array(
55
+	public function add_admin_notice($slug, $class, $message) {
56
+		$this->notices[$slug] = array(
57 57
 			'class'   => $class,
58 58
 			'message' => $message,
59 59
 		);
@@ -66,8 +66,8 @@  discard block
 block discarded – undo
66 66
 	 * @version 4.0.0
67 67
 	 */
68 68
 	public function remove_admin_notice() {
69
-		if ( did_action( 'woocommerce_update_options' ) ) {
70
-			remove_action( 'admin_notices', array( $this, 'check_environment' ) );
69
+		if (did_action('woocommerce_update_options')) {
70
+			remove_action('admin_notices', array($this, 'check_environment'));
71 71
 		}
72 72
 	}
73 73
 
@@ -79,7 +79,7 @@  discard block
 block discarded – undo
79 79
 	 * @return array
80 80
 	 */
81 81
 	public function payment_icons() {
82
-		return apply_filters( 'wc_stripe_payment_icons', array(
82
+		return apply_filters('wc_stripe_payment_icons', array(
83 83
 			'visa'       => '<i class="stripe-pf stripe-pf-visa stripe-pf-right" alt="Visa" aria-hidden="true"></i>',
84 84
 			'amex'       => '<i class="stripe-pf stripe-pf-american-express stripe-pf-right" alt="Amex" aria-hidden="true"></i>',
85 85
 			'mastercard' => '<i class="stripe-pf stripe-pf-mastercard stripe-pf-right" alt="Mastercard" aria-hidden="true"></i>',
@@ -96,7 +96,7 @@  discard block
 block discarded – undo
96 96
 			'eps'        => '<i class="stripe-pf stripe-pf-eps stripe-pf-right" alt="EPS" aria-hidden="true"></i>',
97 97
 			'sofort'     => '<i class="stripe-pf stripe-pf-sofort stripe-pf-right" alt="SOFORT" aria-hidden="true"></i>',
98 98
 			'sepa'       => '<i class="stripe-pf stripe-pf-sepa stripe-pf-right" alt="SEPA" aria-hidden="true"></i>',
99
-		) );
99
+		));
100 100
 	}
101 101
 
102 102
 	/**
@@ -107,10 +107,10 @@  discard block
 block discarded – undo
107 107
 	 * @version 4.0.0
108 108
 	 * @param object $order
109 109
 	 */
110
-	public function validate_minimum_order_amount( $order ) {
111
-		if ( $order->get_total() * 100 < WC_Stripe_Helper::get_minimum_amount() ) {
110
+	public function validate_minimum_order_amount($order) {
111
+		if ($order->get_total() * 100 < WC_Stripe_Helper::get_minimum_amount()) {
112 112
 			/* translators: 1) dollar amount */
113
-			throw new WC_Stripe_Exception( 'Did not meet minimum amount', sprintf( __( 'Sorry, the minimum allowed order total is %1$s to use this payment method.', 'woocommerce-gateway-stripe' ), wc_price( WC_Stripe_Helper::get_minimum_amount() / 100 ) ) );
113
+			throw new WC_Stripe_Exception('Did not meet minimum amount', sprintf(__('Sorry, the minimum allowed order total is %1$s to use this payment method.', 'woocommerce-gateway-stripe'), wc_price(WC_Stripe_Helper::get_minimum_amount() / 100)));
114 114
 		}
115 115
 	}
116 116
 
@@ -120,14 +120,14 @@  discard block
 block discarded – undo
120 120
 	 * @since 4.0.0
121 121
 	 * @version 4.0.0
122 122
 	 */
123
-	public function get_transaction_url( $order ) {
124
-		if ( $this->testmode ) {
123
+	public function get_transaction_url($order) {
124
+		if ($this->testmode) {
125 125
 			$this->view_transaction_url = 'https://dashboard.stripe.com/test/payments/%s';
126 126
 		} else {
127 127
 			$this->view_transaction_url = 'https://dashboard.stripe.com/payments/%s';
128 128
 		}
129 129
 
130
-		return parent::get_transaction_url( $order );
130
+		return parent::get_transaction_url($order);
131 131
 	}
132 132
 
133 133
 	/**
@@ -136,15 +136,15 @@  discard block
 block discarded – undo
136 136
 	 * @since 4.0.0
137 137
 	 * @version 4.0.0
138 138
 	 */
139
-	public function get_stripe_customer_id( $order ) {
140
-		$customer = get_user_meta( WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id(), '_stripe_customer_id', true );
139
+	public function get_stripe_customer_id($order) {
140
+		$customer = get_user_meta(WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id(), '_stripe_customer_id', true);
141 141
 
142
-		if ( empty( $customer ) ) {
142
+		if (empty($customer)) {
143 143
 			// Try to get it via the order.
144
-			if ( WC_Stripe_Helper::is_pre_30() ) {
145
-				return get_post_meta( $order->id, '_stripe_customer_id', true );
144
+			if (WC_Stripe_Helper::is_pre_30()) {
145
+				return get_post_meta($order->id, '_stripe_customer_id', true);
146 146
 			} else {
147
-				return $order->get_meta( '_stripe_customer_id', true );
147
+				return $order->get_meta('_stripe_customer_id', true);
148 148
 			}
149 149
 		} else {
150 150
 			return $customer;
@@ -161,9 +161,9 @@  discard block
 block discarded – undo
161 161
 	 * @param object $order
162 162
 	 * @param int $id Stripe session id.
163 163
 	 */
164
-	public function get_stripe_return_url( $order = null, $id = null ) {
165
-		if ( is_object( $order ) ) {
166
-			if ( empty( $id ) ) {
164
+	public function get_stripe_return_url($order = null, $id = null) {
165
+		if (is_object($order)) {
166
+			if (empty($id)) {
167 167
 				$id = uniqid();
168 168
 			}
169 169
 
@@ -174,10 +174,10 @@  discard block
 block discarded – undo
174 174
 				'order_id'       => $order_id,
175 175
 			);
176 176
 
177
-			return esc_url_raw( add_query_arg( $args, $this->get_return_url( $order ) ) );
177
+			return esc_url_raw(add_query_arg($args, $this->get_return_url($order)));
178 178
 		}
179 179
 
180
-		return esc_url_raw( add_query_arg( array( 'utm_nooverride' => '1' ), $this->get_return_url() ) );
180
+		return esc_url_raw(add_query_arg(array('utm_nooverride' => '1'), $this->get_return_url()));
181 181
 	}
182 182
 
183 183
 	/**
@@ -185,8 +185,8 @@  discard block
 block discarded – undo
185 185
 	 * @param  int  $order_id
186 186
 	 * @return boolean
187 187
 	 */
188
-	public function has_subscription( $order_id ) {
189
-		return ( function_exists( 'wcs_order_contains_subscription' ) && ( wcs_order_contains_subscription( $order_id ) || wcs_is_subscription( $order_id ) || wcs_order_contains_renewal( $order_id ) ) );
188
+	public function has_subscription($order_id) {
189
+		return (function_exists('wcs_order_contains_subscription') && (wcs_order_contains_subscription($order_id) || wcs_is_subscription($order_id) || wcs_order_contains_renewal($order_id)));
190 190
 	}
191 191
 
192 192
 	/**
@@ -198,34 +198,33 @@  discard block
 block discarded – undo
198 198
 	 * @param  object $source
199 199
 	 * @return array()
200 200
 	 */
201
-	public function generate_payment_request( $order, $source ) {
202
-		$settings                          = get_option( 'woocommerce_stripe_settings', array() );
203
-		$statement_descriptor              = ! empty( $settings['statement_descriptor'] ) ? str_replace( "'", '', $settings['statement_descriptor'] ) : '';
204
-		$capture                           = ! empty( $settings['capture'] ) && 'yes' === $settings['capture'] ? true : false;
201
+	public function generate_payment_request($order, $source) {
202
+		$settings                          = get_option('woocommerce_stripe_settings', array());
203
+		$statement_descriptor              = ! empty($settings['statement_descriptor']) ? str_replace("'", '', $settings['statement_descriptor']) : '';
204
+		$capture                           = ! empty($settings['capture']) && 'yes' === $settings['capture'] ? true : false;
205 205
 		$post_data                         = array();
206
-		$post_data['currency']             = strtolower( WC_Stripe_Helper::is_pre_30() ? $order->get_order_currency() : $order->get_currency() );
207
-		$post_data['amount']               = WC_Stripe_Helper::get_stripe_amount( $order->get_total(), $post_data['currency'] );
206
+		$post_data['currency']             = strtolower(WC_Stripe_Helper::is_pre_30() ? $order->get_order_currency() : $order->get_currency());
207
+		$post_data['amount']               = WC_Stripe_Helper::get_stripe_amount($order->get_total(), $post_data['currency']);
208 208
 		/* translators: 1) blog name 2) order number */
209
-		$post_data['description']          = sprintf( __( '%1$s - Order %2$s', 'woocommerce-gateway-stripe' ), wp_specialchars_decode( get_bloginfo( 'name' ), ENT_QUOTES ), $order->get_order_number() );
209
+		$post_data['description']          = sprintf(__('%1$s - Order %2$s', 'woocommerce-gateway-stripe'), wp_specialchars_decode(get_bloginfo('name'), ENT_QUOTES), $order->get_order_number());
210 210
 		$billing_email      = WC_Stripe_Helper::is_pre_30() ? $order->billing_email : $order->get_billing_email();
211 211
 		$billing_first_name = WC_Stripe_Helper::is_pre_30() ? $order->billing_first_name : $order->get_billing_first_name();
212 212
 		$billing_last_name  = WC_Stripe_Helper::is_pre_30() ? $order->billing_last_name : $order->get_billing_last_name();
213 213
 
214
-		if ( ! empty( $billing_email ) && apply_filters( 'wc_stripe_send_stripe_receipt', false ) ) {
214
+		if ( ! empty($billing_email) && apply_filters('wc_stripe_send_stripe_receipt', false)) {
215 215
 			$post_data['receipt_email'] = $billing_email;
216 216
 		}
217 217
 
218
-		switch ( WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method() ) {
219
-			case 'stripe':
220
-				if ( ! empty( $statement_descriptor ) ) {
221
-					$post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor( $statement_descriptor );
218
+		switch (WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method()) {
219
+			case 'stripe' : if ( ! empty($statement_descriptor)) {
220
+					$post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor($statement_descriptor);
222 221
 				}
223 222
 
224 223
 				$post_data['capture'] = $capture ? 'true' : 'false';
225 224
 				break;
226 225
 			case 'stripe_sepa':
227
-				if ( ! empty( $statement_descriptor ) ) {
228
-					$post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor( $statement_descriptor );
226
+				if ( ! empty($statement_descriptor)) {
227
+					$post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor($statement_descriptor);
229 228
 				}
230 229
 				break;
231 230
 		}
@@ -233,25 +232,25 @@  discard block
 block discarded – undo
233 232
 		$post_data['expand[]'] = 'balance_transaction';
234 233
 
235 234
 		$metadata = array(
236
-			__( 'customer_name', 'woocommerce-gateway-stripe' ) => sanitize_text_field( $billing_first_name ) . ' ' . sanitize_text_field( $billing_last_name ),
237
-			__( 'customer_email', 'woocommerce-gateway-stripe' ) => sanitize_email( $billing_email ),
235
+			__('customer_name', 'woocommerce-gateway-stripe') => sanitize_text_field($billing_first_name) . ' ' . sanitize_text_field($billing_last_name),
236
+			__('customer_email', 'woocommerce-gateway-stripe') => sanitize_email($billing_email),
238 237
 			'order_id' => WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(),
239 238
 		);
240 239
 
241
-		if ( $this->has_subscription( WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id() ) ) {
240
+		if ($this->has_subscription(WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id())) {
242 241
 			$metadata += array(
243 242
 				'payment_type' => 'recurring',
244
-				'site_url'     => esc_url( get_site_url() ),
243
+				'site_url'     => esc_url(get_site_url()),
245 244
 			);
246 245
 		}
247 246
 
248
-		$post_data['metadata'] = apply_filters( 'wc_stripe_payment_metadata', $metadata, $order, $source );
247
+		$post_data['metadata'] = apply_filters('wc_stripe_payment_metadata', $metadata, $order, $source);
249 248
 
250
-		if ( $source->customer ) {
249
+		if ($source->customer) {
251 250
 			$post_data['customer'] = $source->customer;
252 251
 		}
253 252
 
254
-		if ( $source->source ) {
253
+		if ($source->source) {
255 254
 			$post_data['source'] = $source->source;
256 255
 		}
257 256
 
@@ -263,79 +262,79 @@  discard block
 block discarded – undo
263 262
 		 * @param WC_Order $order
264 263
 		 * @param object $source
265 264
 		 */
266
-		return apply_filters( 'wc_stripe_generate_payment_request', $post_data, $order, $source );
265
+		return apply_filters('wc_stripe_generate_payment_request', $post_data, $order, $source);
267 266
 	}
268 267
 
269 268
 	/**
270 269
 	 * Store extra meta data for an order from a Stripe Response.
271 270
 	 */
272
-	public function process_response( $response, $order ) {
273
-		WC_Stripe_Logger::log( 'Processing response: ' . print_r( $response, true ) );
271
+	public function process_response($response, $order) {
272
+		WC_Stripe_Logger::log('Processing response: ' . print_r($response, true));
274 273
 
275 274
 		$order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
276 275
 
277
-		$captured = ( isset( $response->captured ) && $response->captured ) ? 'yes' : 'no';
276
+		$captured = (isset($response->captured) && $response->captured) ? 'yes' : 'no';
278 277
 
279 278
 		// Store charge data
280
-		WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, '_stripe_charge_captured', $captured ) : $order->update_meta_data( '_stripe_charge_captured', $captured );
279
+		WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, '_stripe_charge_captured', $captured) : $order->update_meta_data('_stripe_charge_captured', $captured);
281 280
 
282 281
 		// Store other data such as fees
283
-		if ( isset( $response->balance_transaction ) && isset( $response->balance_transaction->fee ) ) {
282
+		if (isset($response->balance_transaction) && isset($response->balance_transaction->fee)) {
284 283
 			// Fees and Net needs to both come from Stripe to be accurate as the returned
285 284
 			// values are in the local currency of the Stripe account, not from WC.
286
-			$fee = ! empty( $response->balance_transaction->fee ) ? WC_Stripe_Helper::format_balance_fee( $response->balance_transaction, 'fee' ) : 0;
287
-			$net = ! empty( $response->balance_transaction->net ) ? WC_Stripe_Helper::format_balance_fee( $response->balance_transaction, 'net' ) : 0;
288
-			WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, self::META_NAME_FEE, $fee ) : $order->update_meta_data( self::META_NAME_FEE, $fee );
289
-			WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, self::META_NAME_NET, $net ) : $order->update_meta_data( self::META_NAME_NET, $net );
285
+			$fee = ! empty($response->balance_transaction->fee) ? WC_Stripe_Helper::format_balance_fee($response->balance_transaction, 'fee') : 0;
286
+			$net = ! empty($response->balance_transaction->net) ? WC_Stripe_Helper::format_balance_fee($response->balance_transaction, 'net') : 0;
287
+			WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, self::META_NAME_FEE, $fee) : $order->update_meta_data(self::META_NAME_FEE, $fee);
288
+			WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, self::META_NAME_NET, $net) : $order->update_meta_data(self::META_NAME_NET, $net);
290 289
 		}
291 290
 
292
-		if ( 'yes' === $captured ) {
291
+		if ('yes' === $captured) {
293 292
 			/**
294 293
 			 * Charge can be captured but in a pending state. Payment methods
295 294
 			 * that are asynchronous may take couple days to clear. Webhook will
296 295
 			 * take care of the status changes.
297 296
 			 */
298
-			if ( 'pending' === $response->status ) {
299
-				$order_stock_reduced = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_order_stock_reduced', true ) : $order->get_meta( '_order_stock_reduced', true );
297
+			if ('pending' === $response->status) {
298
+				$order_stock_reduced = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_order_stock_reduced', true) : $order->get_meta('_order_stock_reduced', true);
300 299
 
301
-				if ( ! $order_stock_reduced ) {
302
-					WC_Stripe_Helper::is_pre_30() ? $order->reduce_order_stock() : wc_reduce_stock_levels( $order_id );
300
+				if ( ! $order_stock_reduced) {
301
+					WC_Stripe_Helper::is_pre_30() ? $order->reduce_order_stock() : wc_reduce_stock_levels($order_id);
303 302
 				}
304 303
 
305
-				WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, '_transaction_id', $response->id ) : $order->set_transaction_id( $response->id );
304
+				WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, '_transaction_id', $response->id) : $order->set_transaction_id($response->id);
306 305
 				/* translators: transaction id */
307
-				$order->update_status( 'on-hold', sprintf( __( 'Stripe charge awaiting payment: %s.', 'woocommerce-gateway-stripe' ), $response->id ) );
306
+				$order->update_status('on-hold', sprintf(__('Stripe charge awaiting payment: %s.', 'woocommerce-gateway-stripe'), $response->id));
308 307
 			}
309 308
 
310
-			if ( 'succeeded' === $response->status ) {
311
-				$order->payment_complete( $response->id );
309
+			if ('succeeded' === $response->status) {
310
+				$order->payment_complete($response->id);
312 311
 
313 312
 				/* translators: transaction id */
314
-				$message = sprintf( __( 'Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe' ), $response->id );
315
-				$order->add_order_note( $message );
313
+				$message = sprintf(__('Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe'), $response->id);
314
+				$order->add_order_note($message);
316 315
 			}
317 316
 
318
-			if ( 'failed' === $response->status ) {
319
-				$localized_message = __( 'Payment processing failed. Please retry.', 'woocommerce-gateway-stripe' );
320
-				$order->add_order_note( $localized_message );
321
-				throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message );
317
+			if ('failed' === $response->status) {
318
+				$localized_message = __('Payment processing failed. Please retry.', 'woocommerce-gateway-stripe');
319
+				$order->add_order_note($localized_message);
320
+				throw new WC_Stripe_Exception(print_r($response, true), $localized_message);
322 321
 			}
323 322
 		} else {
324
-			WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, '_transaction_id', $response->id ) : $order->set_transaction_id( $response->id );
323
+			WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, '_transaction_id', $response->id) : $order->set_transaction_id($response->id);
325 324
 
326
-			if ( $order->has_status( array( 'pending', 'failed' ) ) ) {
327
-				WC_Stripe_Helper::is_pre_30() ? $order->reduce_order_stock() : wc_reduce_stock_levels( $order_id );
325
+			if ($order->has_status(array('pending', 'failed'))) {
326
+				WC_Stripe_Helper::is_pre_30() ? $order->reduce_order_stock() : wc_reduce_stock_levels($order_id);
328 327
 			}
329 328
 
330 329
 			/* translators: transaction id */
331
-			$order->update_status( 'on-hold', sprintf( __( 'Stripe charge authorized (Charge ID: %s). Process order to take payment, or cancel to remove the pre-authorization.', 'woocommerce-gateway-stripe' ), $response->id ) );
330
+			$order->update_status('on-hold', sprintf(__('Stripe charge authorized (Charge ID: %s). Process order to take payment, or cancel to remove the pre-authorization.', 'woocommerce-gateway-stripe'), $response->id));
332 331
 		}
333 332
 
334
-		if ( is_callable( array( $order, 'save' ) ) ) {
333
+		if (is_callable(array($order, 'save'))) {
335 334
 			$order->save();
336 335
 		}
337 336
 
338
-		do_action( 'wc_gateway_stripe_process_response', $response, $order );
337
+		do_action('wc_gateway_stripe_process_response', $response, $order);
339 338
 
340 339
 		return $response;
341 340
 	}
@@ -348,10 +347,10 @@  discard block
 block discarded – undo
348 347
 	 * @param int $order_id
349 348
 	 * @return null
350 349
 	 */
351
-	public function send_failed_order_email( $order_id ) {
350
+	public function send_failed_order_email($order_id) {
352 351
 		$emails = WC()->mailer()->get_emails();
353
-		if ( ! empty( $emails ) && ! empty( $order_id ) ) {
354
-			$emails['WC_Email_Failed_Order']->trigger( $order_id );
352
+		if ( ! empty($emails) && ! empty($order_id)) {
353
+			$emails['WC_Email_Failed_Order']->trigger($order_id);
355 354
 		}
356 355
 	}
357 356
 
@@ -363,7 +362,7 @@  discard block
 block discarded – undo
363 362
 	 * @param object $order
364 363
 	 * @return object $details
365 364
 	 */
366
-	public function get_owner_details( $order ) {
365
+	public function get_owner_details($order) {
367 366
 		$billing_first_name = WC_Stripe_Helper::is_pre_30() ? $order->billing_first_name : $order->get_billing_first_name();
368 367
 		$billing_last_name  = WC_Stripe_Helper::is_pre_30() ? $order->billing_last_name : $order->get_billing_last_name();
369 368
 
@@ -374,8 +373,8 @@  discard block
 block discarded – undo
374 373
 
375 374
 		$phone                             = WC_Stripe_Helper::is_pre_30() ? $order->billing_phone : $order->get_billing_phone();
376 375
 
377
-		if ( ! empty( $phone ) ) {
378
-			$details['phone']              = $phone;
376
+		if ( ! empty($phone)) {
377
+			$details['phone'] = $phone;
379 378
 		}
380 379
 
381 380
 		$details['address']['line1']       = WC_Stripe_Helper::is_pre_30() ? $order->billing_address_1 : $order->get_billing_address_1();
@@ -385,7 +384,7 @@  discard block
 block discarded – undo
385 384
 		$details['address']['postal_code'] = WC_Stripe_Helper::is_pre_30() ? $order->billing_postcode : $order->get_billing_postcode();
386 385
 		$details['address']['country']     = WC_Stripe_Helper::is_pre_30() ? $order->billing_country : $order->get_billing_country();
387 386
 
388
-		return (object) apply_filters( 'wc_stripe_owner_details', $details, $order );
387
+		return (object) apply_filters('wc_stripe_owner_details', $details, $order);
389 388
 	}
390 389
 
391 390
 	/**
@@ -394,16 +393,16 @@  discard block
 block discarded – undo
394 393
 	 * @since 4.0.3
395 394
 	 */
396 395
 	public function get_source_object() {
397
-		$source = ! empty( $_POST['stripe_source'] ) ? wc_clean( $_POST['stripe_source'] ) : '';
396
+		$source = ! empty($_POST['stripe_source']) ? wc_clean($_POST['stripe_source']) : '';
398 397
 
399
-		if ( empty( $source ) ) {
398
+		if (empty($source)) {
400 399
 			return '';
401 400
 		}
402 401
 
403
-		$source_object = WC_Stripe_API::retrieve( 'sources/' . $source );
402
+		$source_object = WC_Stripe_API::retrieve('sources/' . $source);
404 403
 
405
-		if ( ! empty( $source_object->error ) ) {
406
-			throw new WC_Stripe_Exception( print_r( $source_object, true ), $source_object->error->message );
404
+		if ( ! empty($source_object->error)) {
405
+			throw new WC_Stripe_Exception(print_r($source_object, true), $source_object->error->message);
407 406
 		}
408 407
 
409 408
 		return $source_object;
@@ -416,11 +415,11 @@  discard block
 block discarded – undo
416 415
 	 * @param object $source_object
417 416
 	 * @return bool
418 417
 	 */
419
-	public function is_3ds_required( $source_object ) {
418
+	public function is_3ds_required($source_object) {
420 419
 		return (
421
-			$source_object && ! empty( $source_object->card ) ) &&
422
-			( 'card' === $source_object->type && 'required' === $source_object->card->three_d_secure ||
423
-			( $this->three_d_secure && 'optional' === $source_object->card->three_d_secure )
420
+			$source_object && ! empty($source_object->card) ) &&
421
+			('card' === $source_object->type && 'required' === $source_object->card->three_d_secure ||
422
+			($this->three_d_secure && 'optional' === $source_object->card->three_d_secure)
424 423
 		);
425 424
 	}
426 425
 
@@ -431,8 +430,8 @@  discard block
 block discarded – undo
431 430
 	 * @param object $source_object
432 431
 	 * @return bool
433 432
 	 */
434
-	public function is_3ds_card( $source_object ) {
435
-		return ( $source_object && 'three_d_secure' === $source_object->type );
433
+	public function is_3ds_card($source_object) {
434
+		return ($source_object && 'three_d_secure' === $source_object->type);
436 435
 	}
437 436
 
438 437
 	/**
@@ -445,22 +444,22 @@  discard block
 block discarded – undo
445 444
 	 * @param string $return_url
446 445
 	 * @return mixed
447 446
 	 */
448
-	public function create_3ds_source( $order, $source_object, $return_url = '' ) {
447
+	public function create_3ds_source($order, $source_object, $return_url = '') {
449 448
 		$currency                    = WC_Stripe_Helper::is_pre_30() ? $order->get_order_currency() : $order->get_currency();
450 449
 		$order_id                    = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
451
-		$return_url                  = empty( $return_url ) ? $this->get_stripe_return_url( $order ) : $return_url;
450
+		$return_url                  = empty($return_url) ? $this->get_stripe_return_url($order) : $return_url;
452 451
 
453 452
 		$post_data                   = array();
454
-		$post_data['amount']         = WC_Stripe_Helper::get_stripe_amount( $order->get_total(), $currency );
455
-		$post_data['currency']       = strtolower( $currency );
453
+		$post_data['amount']         = WC_Stripe_Helper::get_stripe_amount($order->get_total(), $currency);
454
+		$post_data['currency']       = strtolower($currency);
456 455
 		$post_data['type']           = 'three_d_secure';
457
-		$post_data['owner']          = $this->get_owner_details( $order );
458
-		$post_data['three_d_secure'] = array( 'card' => $source_object->id );
459
-		$post_data['redirect']       = array( 'return_url' => $return_url );
456
+		$post_data['owner']          = $this->get_owner_details($order);
457
+		$post_data['three_d_secure'] = array('card' => $source_object->id);
458
+		$post_data['redirect']       = array('return_url' => $return_url);
460 459
 
461
-		WC_Stripe_Logger::log( 'Info: Begin creating 3DS source...' );
460
+		WC_Stripe_Logger::log('Info: Begin creating 3DS source...');
462 461
 
463
-		return WC_Stripe_API::request( apply_filters( 'wc_stripe_3ds_source', $post_data, $order ), 'sources' );
462
+		return WC_Stripe_API::request(apply_filters('wc_stripe_3ds_source', $post_data, $order), 'sources');
464 463
 	}
465 464
 
466 465
 	/**
@@ -477,54 +476,54 @@  discard block
 block discarded – undo
477 476
 	 * @throws Exception When card was not added or for and invalid card.
478 477
 	 * @return object
479 478
 	 */
480
-	public function prepare_source( $source_object = '', $user_id, $force_save_source = false ) {
481
-		$customer           = new WC_Stripe_Customer( $user_id );
479
+	public function prepare_source($source_object = '', $user_id, $force_save_source = false) {
480
+		$customer           = new WC_Stripe_Customer($user_id);
482 481
 		$set_customer       = true;
483
-		$force_save_source  = apply_filters( 'wc_stripe_force_save_source', $force_save_source, $customer );
482
+		$force_save_source  = apply_filters('wc_stripe_force_save_source', $force_save_source, $customer);
484 483
 		$source_id          = '';
485 484
 		$wc_token_id        = false;
486
-		$payment_method     = isset( $_POST['payment_method'] ) ? wc_clean( $_POST['payment_method'] ) : 'stripe';
485
+		$payment_method     = isset($_POST['payment_method']) ? wc_clean($_POST['payment_method']) : 'stripe';
487 486
 
488 487
 		// New CC info was entered and we have a new source to process.
489
-		if ( ! empty( $source_object ) ) {
488
+		if ( ! empty($source_object)) {
490 489
 			$source_id = $source_object->id;
491 490
 
492 491
 			// This checks to see if customer opted to save the payment method to file.
493
-			$maybe_saved_card = isset( $_POST[ 'wc-' . $payment_method . '-new-payment-method' ] ) && ! empty( $_POST[ 'wc-' . $payment_method . '-new-payment-method' ] );
492
+			$maybe_saved_card = isset($_POST['wc-' . $payment_method . '-new-payment-method']) && ! empty($_POST['wc-' . $payment_method . '-new-payment-method']);
494 493
 
495 494
 			/**
496 495
 			 * This is true if the user wants to store the card to their account.
497 496
 			 * Criteria to save to file is they are logged in, they opted to save or product requirements and the source is
498 497
 			 * actually reusable. Either that or force_save_source is true.
499 498
 			 */
500
-			if ( ( $user_id && $this->saved_cards && $maybe_saved_card && 'reusable' === $source_object->usage ) || $force_save_source ) {
501
-				$response = $customer->add_source( $source_object->id );
499
+			if (($user_id && $this->saved_cards && $maybe_saved_card && 'reusable' === $source_object->usage) || $force_save_source) {
500
+				$response = $customer->add_source($source_object->id);
502 501
 
503
-				if ( ! empty( $response->error ) ) {
504
-					throw new WC_Stripe_Exception( print_r( $response, true ), $response->error->message );
502
+				if ( ! empty($response->error)) {
503
+					throw new WC_Stripe_Exception(print_r($response, true), $response->error->message);
505 504
 				}
506 505
 			}
507
-		} elseif ( isset( $_POST[ 'wc-' . $payment_method . '-payment-token' ] ) && 'new' !== $_POST[ 'wc-' . $payment_method . '-payment-token' ] ) {
506
+		} elseif (isset($_POST['wc-' . $payment_method . '-payment-token']) && 'new' !== $_POST['wc-' . $payment_method . '-payment-token']) {
508 507
 			// Use an existing token, and then process the payment
509
-			$wc_token_id = wc_clean( $_POST[ 'wc-' . $payment_method . '-payment-token' ] );
510
-			$wc_token    = WC_Payment_Tokens::get( $wc_token_id );
508
+			$wc_token_id = wc_clean($_POST['wc-' . $payment_method . '-payment-token']);
509
+			$wc_token    = WC_Payment_Tokens::get($wc_token_id);
511 510
 
512
-			if ( ! $wc_token || $wc_token->get_user_id() !== get_current_user_id() ) {
513
-				WC()->session->set( 'refresh_totals', true );
514
-				throw new WC_Stripe_Exception( 'Invalid payment method', __( 'Invalid payment method. Please input a new card number.', 'woocommerce-gateway-stripe' ) );
511
+			if ( ! $wc_token || $wc_token->get_user_id() !== get_current_user_id()) {
512
+				WC()->session->set('refresh_totals', true);
513
+				throw new WC_Stripe_Exception('Invalid payment method', __('Invalid payment method. Please input a new card number.', 'woocommerce-gateway-stripe'));
515 514
 			}
516 515
 
517 516
 			$source_id = $wc_token->get_token();
518
-		} elseif ( isset( $_POST['stripe_token'] ) && 'new' !== $_POST['stripe_token'] ) {
519
-			$stripe_token     = wc_clean( $_POST['stripe_token'] );
520
-			$maybe_saved_card = isset( $_POST[ 'wc-' . $payment_method . '-new-payment-method' ] ) && ! empty( $_POST[ 'wc-' . $payment_method . '-new-payment-method' ] );
517
+		} elseif (isset($_POST['stripe_token']) && 'new' !== $_POST['stripe_token']) {
518
+			$stripe_token     = wc_clean($_POST['stripe_token']);
519
+			$maybe_saved_card = isset($_POST['wc-' . $payment_method . '-new-payment-method']) && ! empty($_POST['wc-' . $payment_method . '-new-payment-method']);
521 520
 
522 521
 			// This is true if the user wants to store the card to their account.
523
-			if ( ( $user_id && $this->saved_cards && $maybe_saved_card ) || $force_save_source ) {
524
-				$response = $customer->add_source( $stripe_token );
522
+			if (($user_id && $this->saved_cards && $maybe_saved_card) || $force_save_source) {
523
+				$response = $customer->add_source($stripe_token);
525 524
 
526
-				if ( ! empty( $response->error ) ) {
527
-					throw new WC_Stripe_Exception( print_r( $response, true ), $response->error->message );
525
+				if ( ! empty($response->error)) {
526
+					throw new WC_Stripe_Exception(print_r($response, true), $response->error->message);
528 527
 				}
529 528
 			} else {
530 529
 				$set_customer = false;
@@ -532,7 +531,7 @@  discard block
 block discarded – undo
532 531
 			}
533 532
 		}
534 533
 
535
-		if ( ! $set_customer ) {
534
+		if ( ! $set_customer) {
536 535
 			$customer_id = false;
537 536
 		} else {
538 537
 			$customer_id = $customer->get_id() ? $customer->get_id() : false;
@@ -558,37 +557,37 @@  discard block
 block discarded – undo
558 557
 	 * @param object $order
559 558
 	 * @return object
560 559
 	 */
561
-	public function prepare_order_source( $order = null ) {
560
+	public function prepare_order_source($order = null) {
562 561
 		$stripe_customer = new WC_Stripe_Customer();
563 562
 		$stripe_source   = false;
564 563
 		$token_id        = false;
565 564
 
566
-		if ( $order ) {
565
+		if ($order) {
567 566
 			$order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
568 567
 
569
-			$stripe_customer_id = get_post_meta( $order_id, '_stripe_customer_id', true );
568
+			$stripe_customer_id = get_post_meta($order_id, '_stripe_customer_id', true);
570 569
 
571
-			if ( $stripe_customer_id ) {
572
-				$stripe_customer->set_id( $stripe_customer_id );
570
+			if ($stripe_customer_id) {
571
+				$stripe_customer->set_id($stripe_customer_id);
573 572
 			}
574 573
 
575
-			$source_id = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_stripe_source_id', true ) : $order->get_meta( '_stripe_source_id', true );
574
+			$source_id = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_stripe_source_id', true) : $order->get_meta('_stripe_source_id', true);
576 575
 
577 576
 			// Since 4.0.0, we changed card to source so we need to account for that.
578
-			if ( empty( $source_id ) ) {
579
-				$source_id = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_stripe_card_id', true ) : $order->get_meta( '_stripe_card_id', true );
577
+			if (empty($source_id)) {
578
+				$source_id = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_stripe_card_id', true) : $order->get_meta('_stripe_card_id', true);
580 579
 
581 580
 				// Take this opportunity to update the key name.
582
-				WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, '_stripe_source_id', $source_id ) : $order->update_meta_data( '_stripe_source_id', $source_id );
581
+				WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, '_stripe_source_id', $source_id) : $order->update_meta_data('_stripe_source_id', $source_id);
583 582
 
584
-				if ( is_callable( array( $order, 'save' ) ) ) {
583
+				if (is_callable(array($order, 'save'))) {
585 584
 					$order->save();
586 585
 				}
587 586
 			}
588 587
 
589
-			if ( $source_id ) {
588
+			if ($source_id) {
590 589
 				$stripe_source = $source_id;
591
-			} elseif ( apply_filters( 'wc_stripe_use_default_customer_source', true ) ) {
590
+			} elseif (apply_filters('wc_stripe_use_default_customer_source', true)) {
592 591
 				/*
593 592
 				 * We can attempt to charge the customer's default source
594 593
 				 * by sending empty source id.
@@ -612,27 +611,27 @@  discard block
 block discarded – undo
612 611
 	 * @param WC_Order $order For to which the source applies.
613 612
 	 * @param stdClass $source Source information.
614 613
 	 */
615
-	public function save_source_to_order( $order, $source ) {
614
+	public function save_source_to_order($order, $source) {
616 615
 		$order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
617 616
 
618 617
 		// Store source in the order.
619
-		if ( $source->customer ) {
620
-			if ( WC_Stripe_Helper::is_pre_30() ) {
621
-				update_post_meta( $order_id, '_stripe_customer_id', $source->customer );
618
+		if ($source->customer) {
619
+			if (WC_Stripe_Helper::is_pre_30()) {
620
+				update_post_meta($order_id, '_stripe_customer_id', $source->customer);
622 621
 			} else {
623
-				$order->update_meta_data( '_stripe_customer_id', $source->customer );
622
+				$order->update_meta_data('_stripe_customer_id', $source->customer);
624 623
 			}
625 624
 		}
626 625
 
627
-		if ( $source->source ) {
628
-			if ( WC_Stripe_Helper::is_pre_30() ) {
629
-				update_post_meta( $order_id, '_stripe_source_id', $source->source );
626
+		if ($source->source) {
627
+			if (WC_Stripe_Helper::is_pre_30()) {
628
+				update_post_meta($order_id, '_stripe_source_id', $source->source);
630 629
 			} else {
631
-				$order->update_meta_data( '_stripe_source_id', $source->source );
630
+				$order->update_meta_data('_stripe_source_id', $source->source);
632 631
 			}
633 632
 		}
634 633
 
635
-		if ( is_callable( array( $order, 'save' ) ) ) {
634
+		if (is_callable(array($order, 'save'))) {
636 635
 			$order->save();
637 636
 		}
638 637
 	}
@@ -646,27 +645,27 @@  discard block
 block discarded – undo
646 645
 	 * @param object $order The order object
647 646
 	 * @param int $balance_transaction_id
648 647
 	 */
649
-	public function update_fees( $order, $balance_transaction_id ) {
648
+	public function update_fees($order, $balance_transaction_id) {
650 649
 		$order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
651 650
 
652
-		$balance_transaction = WC_Stripe_API::retrieve( 'balance/history/' . $balance_transaction_id );
651
+		$balance_transaction = WC_Stripe_API::retrieve('balance/history/' . $balance_transaction_id);
653 652
 
654
-		if ( empty( $balance_transaction->error ) ) {
655
-			if ( isset( $balance_transaction ) && isset( $balance_transaction->fee ) ) {
653
+		if (empty($balance_transaction->error)) {
654
+			if (isset($balance_transaction) && isset($balance_transaction->fee)) {
656 655
 				// Fees and Net needs to both come from Stripe to be accurate as the returned
657 656
 				// values are in the local currency of the Stripe account, not from WC.
658
-				$fee = ! empty( $balance_transaction->fee ) ? WC_Stripe_Helper::format_balance_fee( $balance_transaction, 'fee' ) : 0;
659
-				$net = ! empty( $balance_transaction->net ) ? WC_Stripe_Helper::format_balance_fee( $balance_transaction, 'net' ) : 0;
657
+				$fee = ! empty($balance_transaction->fee) ? WC_Stripe_Helper::format_balance_fee($balance_transaction, 'fee') : 0;
658
+				$net = ! empty($balance_transaction->net) ? WC_Stripe_Helper::format_balance_fee($balance_transaction, 'net') : 0;
660 659
 
661
-				WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, self::META_NAME_FEE, $fee ) : $order->update_meta_data( self::META_NAME_FEE, $fee );
662
-				WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, self::META_NAME_NET, $net ) : $order->update_meta_data( self::META_NAME_NET, $net );
660
+				WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, self::META_NAME_FEE, $fee) : $order->update_meta_data(self::META_NAME_FEE, $fee);
661
+				WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, self::META_NAME_NET, $net) : $order->update_meta_data(self::META_NAME_NET, $net);
663 662
 
664
-				if ( is_callable( array( $order, 'save' ) ) ) {
663
+				if (is_callable(array($order, 'save'))) {
665 664
 					$order->save();
666 665
 				}
667 666
 			}
668 667
 		} else {
669
-			WC_Stripe_Logger::log( "Unable to update fees/net meta for order: {$order_id}" );
668
+			WC_Stripe_Logger::log("Unable to update fees/net meta for order: {$order_id}");
670 669
 		}
671 670
 	}
672 671
 
@@ -679,33 +678,33 @@  discard block
 block discarded – undo
679 678
 	 * @param  float $amount
680 679
 	 * @return bool
681 680
 	 */
682
-	public function process_refund( $order_id, $amount = null, $reason = '' ) {
683
-		$order = wc_get_order( $order_id );
681
+	public function process_refund($order_id, $amount = null, $reason = '') {
682
+		$order = wc_get_order($order_id);
684 683
 
685
-		if ( ! $order || ! $order->get_transaction_id() ) {
684
+		if ( ! $order || ! $order->get_transaction_id()) {
686 685
 			return false;
687 686
 		}
688 687
 
689 688
 		$request = array();
690 689
 
691
-		if ( WC_Stripe_Helper::is_pre_30() ) {
692
-			$order_currency = get_post_meta( $order_id, '_order_currency', true );
693
-			$captured       = get_post_meta( $order_id, '_stripe_charge_captured', true );
690
+		if (WC_Stripe_Helper::is_pre_30()) {
691
+			$order_currency = get_post_meta($order_id, '_order_currency', true);
692
+			$captured       = get_post_meta($order_id, '_stripe_charge_captured', true);
694 693
 		} else {
695 694
 			$order_currency = $order->get_currency();
696
-			$captured       = $order->get_meta( '_stripe_charge_captured', true );
695
+			$captured       = $order->get_meta('_stripe_charge_captured', true);
697 696
 		}
698 697
 
699
-		if ( ! is_null( $amount ) ) {
700
-			$request['amount'] = WC_Stripe_Helper::get_stripe_amount( $amount, $order_currency );
698
+		if ( ! is_null($amount)) {
699
+			$request['amount'] = WC_Stripe_Helper::get_stripe_amount($amount, $order_currency);
701 700
 		}
702 701
 
703 702
 		// If order is only authorized, don't pass amount.
704
-		if ( 'yes' !== $captured ) {
705
-			unset( $request['amount'] );
703
+		if ('yes' !== $captured) {
704
+			unset($request['amount']);
706 705
 		}
707 706
 
708
-		if ( $reason ) {
707
+		if ($reason) {
709 708
 			$request['metadata'] = array(
710 709
 				'reason' => $reason,
711 710
 			);
@@ -713,33 +712,33 @@  discard block
 block discarded – undo
713 712
 
714 713
 		$request['charge'] = $order->get_transaction_id();
715 714
 
716
-		WC_Stripe_Logger::log( "Info: Beginning refund for order {$order->get_transaction_id()} for the amount of {$amount}" );
715
+		WC_Stripe_Logger::log("Info: Beginning refund for order {$order->get_transaction_id()} for the amount of {$amount}");
717 716
 
718
-		$response = WC_Stripe_API::request( $request, 'refunds' );
717
+		$response = WC_Stripe_API::request($request, 'refunds');
719 718
 
720
-		if ( ! empty( $response->error ) ) {
721
-			WC_Stripe_Logger::log( 'Error: ' . $response->error->message );
719
+		if ( ! empty($response->error)) {
720
+			WC_Stripe_Logger::log('Error: ' . $response->error->message);
722 721
 
723 722
 			return $response;
724 723
 
725
-		} elseif ( ! empty( $response->id ) ) {
726
-			WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, '_stripe_refund_id', $response->id ) : $order->update_meta_data( '_stripe_refund_id', $response->id );
724
+		} elseif ( ! empty($response->id)) {
725
+			WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, '_stripe_refund_id', $response->id) : $order->update_meta_data('_stripe_refund_id', $response->id);
727 726
 
728
-			$amount = wc_price( $response->amount / 100 );
727
+			$amount = wc_price($response->amount / 100);
729 728
 
730
-			if ( in_array( strtolower( $order->get_currency() ), WC_Stripe_Helper::no_decimal_currencies() ) ) {
731
-				$amount = wc_price( $response->amount );
729
+			if (in_array(strtolower($order->get_currency()), WC_Stripe_Helper::no_decimal_currencies())) {
730
+				$amount = wc_price($response->amount);
732 731
 			}
733 732
 
734
-			if ( isset( $response->balance_transaction ) ) {
735
-				$this->update_fees( $order, $response->balance_transaction );
733
+			if (isset($response->balance_transaction)) {
734
+				$this->update_fees($order, $response->balance_transaction);
736 735
 			}
737 736
 
738 737
 			/* translators: 1) dollar amount 2) transaction id 3) refund message */
739
-			$refund_message = ( isset( $captured ) && 'yes' === $captured ) ? sprintf( __( 'Refunded %1$s - Refund ID: %2$s - Reason: %3$s', 'woocommerce-gateway-stripe' ), $amount, $response->id, $reason ) : __( 'Pre-Authorization Released', 'woocommerce-gateway-stripe' );
738
+			$refund_message = (isset($captured) && 'yes' === $captured) ? sprintf(__('Refunded %1$s - Refund ID: %2$s - Reason: %3$s', 'woocommerce-gateway-stripe'), $amount, $response->id, $reason) : __('Pre-Authorization Released', 'woocommerce-gateway-stripe');
740 739
 
741
-			$order->add_order_note( $refund_message );
742
-			WC_Stripe_Logger::log( 'Success: ' . html_entity_decode( strip_tags( $refund_message ) ) );
740
+			$order->add_order_note($refund_message);
741
+			WC_Stripe_Logger::log('Success: ' . html_entity_decode(strip_tags($refund_message)));
743 742
 
744 743
 			return true;
745 744
 		}
@@ -754,44 +753,44 @@  discard block
 block discarded – undo
754 753
 	 */
755 754
 	public function add_payment_method() {
756 755
 		$error     = false;
757
-		$error_msg = __( 'There was a problem adding the card.', 'woocommerce-gateway-stripe' );
756
+		$error_msg = __('There was a problem adding the card.', 'woocommerce-gateway-stripe');
758 757
 		$source_id = '';
759 758
 
760
-		if ( empty( $_POST['stripe_source'] ) && empty( $_POST['stripe_token'] ) || ! is_user_logged_in() ) {
759
+		if (empty($_POST['stripe_source']) && empty($_POST['stripe_token']) || ! is_user_logged_in()) {
761 760
 			$error = true;
762 761
 		}
763 762
 
764
-		$stripe_customer = new WC_Stripe_Customer( get_current_user_id() );
763
+		$stripe_customer = new WC_Stripe_Customer(get_current_user_id());
765 764
 
766
-		$source = ! empty( $_POST['stripe_source'] ) ? wc_clean( $_POST['stripe_source'] ) : '';
765
+		$source = ! empty($_POST['stripe_source']) ? wc_clean($_POST['stripe_source']) : '';
767 766
 
768
-		$source_object = WC_Stripe_API::retrieve( 'sources/' . $source );
767
+		$source_object = WC_Stripe_API::retrieve('sources/' . $source);
769 768
 
770
-		if ( isset( $source_object ) ) {
771
-			if ( ! empty( $source_object->error ) ) {
769
+		if (isset($source_object)) {
770
+			if ( ! empty($source_object->error)) {
772 771
 				$error = true;
773 772
 			}
774 773
 
775 774
 			$source_id = $source_object->id;
776
-		} elseif ( isset( $_POST['stripe_token'] ) ) {
777
-			$source_id = wc_clean( $_POST['stripe_token'] );
775
+		} elseif (isset($_POST['stripe_token'])) {
776
+			$source_id = wc_clean($_POST['stripe_token']);
778 777
 		}
779 778
 
780
-		$response = $stripe_customer->add_source( $source_id );
779
+		$response = $stripe_customer->add_source($source_id);
781 780
 
782
-		if ( ! $response || is_wp_error( $response ) || ! empty( $response->error ) ) {
781
+		if ( ! $response || is_wp_error($response) || ! empty($response->error)) {
783 782
 			$error = true;
784 783
 		}
785 784
 
786
-		if ( $error ) {
787
-			wc_add_notice( $error_msg, 'error' );
788
-			WC_Stripe_Logger::log( 'Add payment method Error: ' . $error_msg );
785
+		if ($error) {
786
+			wc_add_notice($error_msg, 'error');
787
+			WC_Stripe_Logger::log('Add payment method Error: ' . $error_msg);
789 788
 			return;
790 789
 		}
791 790
 
792 791
 		return array(
793 792
 			'result'   => 'success',
794
-			'redirect' => wc_get_endpoint_url( 'payment-methods' ),
793
+			'redirect' => wc_get_endpoint_url('payment-methods'),
795 794
 		);
796 795
 	}
797 796
 }
Please login to merge, or discard this patch.
woocommerce-gateway-stripe.php 1 patch
Spacing   +130 added lines, -130 removed lines patch added patch discarded remove patch
@@ -15,20 +15,20 @@  discard block
 block discarded – undo
15 15
  *
16 16
  */
17 17
 
18
-if ( ! defined( 'ABSPATH' ) ) {
18
+if ( ! defined('ABSPATH')) {
19 19
 	exit;
20 20
 }
21 21
 
22
-if ( ! class_exists( 'WC_Stripe' ) ) :
22
+if ( ! class_exists('WC_Stripe')) :
23 23
 	/**
24 24
 	 * Required minimums and constants
25 25
 	 */
26
-	define( 'WC_STRIPE_VERSION', '4.0.5' );
27
-	define( 'WC_STRIPE_MIN_PHP_VER', '5.6.0' );
28
-	define( 'WC_STRIPE_MIN_WC_VER', '2.6.0' );
29
-	define( 'WC_STRIPE_MAIN_FILE', __FILE__ );
30
-	define( 'WC_STRIPE_PLUGIN_URL', untrailingslashit( plugins_url( basename( plugin_dir_path( __FILE__ ) ), basename( __FILE__ ) ) ) );
31
-	define( 'WC_STRIPE_PLUGIN_PATH', untrailingslashit( plugin_dir_path( __FILE__ ) ) );
26
+	define('WC_STRIPE_VERSION', '4.0.5');
27
+	define('WC_STRIPE_MIN_PHP_VER', '5.6.0');
28
+	define('WC_STRIPE_MIN_WC_VER', '2.6.0');
29
+	define('WC_STRIPE_MAIN_FILE', __FILE__);
30
+	define('WC_STRIPE_PLUGIN_URL', untrailingslashit(plugins_url(basename(plugin_dir_path(__FILE__)), basename(__FILE__))));
31
+	define('WC_STRIPE_PLUGIN_PATH', untrailingslashit(plugin_dir_path(__FILE__)));
32 32
 
33 33
 	class WC_Stripe {
34 34
 
@@ -48,7 +48,7 @@  discard block
 block discarded – undo
48 48
 		 * @return Singleton The *Singleton* instance.
49 49
 		 */
50 50
 		public static function get_instance() {
51
-			if ( null === self::$instance ) {
51
+			if (null === self::$instance) {
52 52
 				self::$instance = new self();
53 53
 			}
54 54
 			return self::$instance;
@@ -81,10 +81,10 @@  discard block
 block discarded – undo
81 81
 		 * *Singleton* via the `new` operator from outside of this class.
82 82
 		 */
83 83
 		private function __construct() {
84
-			add_action( 'admin_init', array( $this, 'check_environment' ) );
85
-			add_action( 'admin_notices', array( $this, 'admin_notices' ), 15 );
86
-			add_action( 'plugins_loaded', array( $this, 'init' ) );
87
-			add_action( 'wp_loaded', array( $this, 'hide_notices' ) );
84
+			add_action('admin_init', array($this, 'check_environment'));
85
+			add_action('admin_notices', array($this, 'admin_notices'), 15);
86
+			add_action('plugins_loaded', array($this, 'init'));
87
+			add_action('wp_loaded', array($this, 'hide_notices'));
88 88
 		}
89 89
 
90 90
 		/**
@@ -94,44 +94,44 @@  discard block
 block discarded – undo
94 94
 		 * @version 4.0.0
95 95
 		 */
96 96
 		public function init() {
97
-			require_once( dirname( __FILE__ ) . '/includes/class-wc-stripe-exception.php' );
98
-			require_once( dirname( __FILE__ ) . '/includes/class-wc-stripe-logger.php' );
99
-			require_once( dirname( __FILE__ ) . '/includes/class-wc-stripe-helper.php' );
100
-			include_once( dirname( __FILE__ ) . '/includes/class-wc-stripe-api.php' );
97
+			require_once(dirname(__FILE__) . '/includes/class-wc-stripe-exception.php');
98
+			require_once(dirname(__FILE__) . '/includes/class-wc-stripe-logger.php');
99
+			require_once(dirname(__FILE__) . '/includes/class-wc-stripe-helper.php');
100
+			include_once(dirname(__FILE__) . '/includes/class-wc-stripe-api.php');
101 101
 
102 102
 			// Don't hook anything else in the plugin if we're in an incompatible environment
103
-			if ( self::get_environment_warning() ) {
103
+			if (self::get_environment_warning()) {
104 104
 				return;
105 105
 			}
106 106
 
107
-			load_plugin_textdomain( 'woocommerce-gateway-stripe', false, plugin_basename( dirname( __FILE__ ) ) . '/languages' );
108
-
109
-			require_once( dirname( __FILE__ ) . '/includes/abstracts/abstract-wc-stripe-payment-gateway.php' );
110
-			require_once( dirname( __FILE__ ) . '/includes/class-wc-stripe-webhook-handler.php' );
111
-			require_once( dirname( __FILE__ ) . '/includes/class-wc-stripe-sepa-payment-token.php' );
112
-			require_once( dirname( __FILE__ ) . '/includes/class-wc-stripe-apple-pay-registration.php' );
113
-			require_once( dirname( __FILE__ ) . '/includes/class-wc-gateway-stripe.php' );
114
-			require_once( dirname( __FILE__ ) . '/includes/payment-methods/class-wc-gateway-stripe-bancontact.php' );
115
-			require_once( dirname( __FILE__ ) . '/includes/payment-methods/class-wc-gateway-stripe-sofort.php' );
116
-			require_once( dirname( __FILE__ ) . '/includes/payment-methods/class-wc-gateway-stripe-giropay.php' );
117
-			require_once( dirname( __FILE__ ) . '/includes/payment-methods/class-wc-gateway-stripe-ideal.php' );
118
-			require_once( dirname( __FILE__ ) . '/includes/payment-methods/class-wc-gateway-stripe-p24.php' );
119
-			require_once( dirname( __FILE__ ) . '/includes/payment-methods/class-wc-gateway-stripe-alipay.php' );
120
-			require_once( dirname( __FILE__ ) . '/includes/payment-methods/class-wc-gateway-stripe-sepa.php' );
121
-			require_once( dirname( __FILE__ ) . '/includes/payment-methods/class-wc-gateway-stripe-bitcoin.php' );
122
-			require_once( dirname( __FILE__ ) . '/includes/payment-methods/class-wc-stripe-payment-request.php' );
123
-			require_once( dirname( __FILE__ ) . '/includes/compat/class-wc-stripe-compat.php' );
124
-			require_once( dirname( __FILE__ ) . '/includes/compat/class-wc-stripe-sepa-compat.php' );
125
-			require_once( dirname( __FILE__ ) . '/includes/class-wc-stripe-order-handler.php' );
126
-			require_once( dirname( __FILE__ ) . '/includes/class-wc-stripe-payment-tokens.php' );
127
-			require_once( dirname( __FILE__ ) . '/includes/class-wc-stripe-customer.php' );
107
+			load_plugin_textdomain('woocommerce-gateway-stripe', false, plugin_basename(dirname(__FILE__)) . '/languages');
108
+
109
+			require_once(dirname(__FILE__) . '/includes/abstracts/abstract-wc-stripe-payment-gateway.php');
110
+			require_once(dirname(__FILE__) . '/includes/class-wc-stripe-webhook-handler.php');
111
+			require_once(dirname(__FILE__) . '/includes/class-wc-stripe-sepa-payment-token.php');
112
+			require_once(dirname(__FILE__) . '/includes/class-wc-stripe-apple-pay-registration.php');
113
+			require_once(dirname(__FILE__) . '/includes/class-wc-gateway-stripe.php');
114
+			require_once(dirname(__FILE__) . '/includes/payment-methods/class-wc-gateway-stripe-bancontact.php');
115
+			require_once(dirname(__FILE__) . '/includes/payment-methods/class-wc-gateway-stripe-sofort.php');
116
+			require_once(dirname(__FILE__) . '/includes/payment-methods/class-wc-gateway-stripe-giropay.php');
117
+			require_once(dirname(__FILE__) . '/includes/payment-methods/class-wc-gateway-stripe-ideal.php');
118
+			require_once(dirname(__FILE__) . '/includes/payment-methods/class-wc-gateway-stripe-p24.php');
119
+			require_once(dirname(__FILE__) . '/includes/payment-methods/class-wc-gateway-stripe-alipay.php');
120
+			require_once(dirname(__FILE__) . '/includes/payment-methods/class-wc-gateway-stripe-sepa.php');
121
+			require_once(dirname(__FILE__) . '/includes/payment-methods/class-wc-gateway-stripe-bitcoin.php');
122
+			require_once(dirname(__FILE__) . '/includes/payment-methods/class-wc-stripe-payment-request.php');
123
+			require_once(dirname(__FILE__) . '/includes/compat/class-wc-stripe-compat.php');
124
+			require_once(dirname(__FILE__) . '/includes/compat/class-wc-stripe-sepa-compat.php');
125
+			require_once(dirname(__FILE__) . '/includes/class-wc-stripe-order-handler.php');
126
+			require_once(dirname(__FILE__) . '/includes/class-wc-stripe-payment-tokens.php');
127
+			require_once(dirname(__FILE__) . '/includes/class-wc-stripe-customer.php');
128 128
 
129 129
 			// REMOVE IN THE FUTURE.
130
-			require_once( dirname( __FILE__ ) . '/includes/deprecated/class-wc-stripe-apple-pay.php' );
130
+			require_once(dirname(__FILE__) . '/includes/deprecated/class-wc-stripe-apple-pay.php');
131 131
 
132
-			add_filter( 'woocommerce_payment_gateways', array( $this, 'add_gateways' ) );
133
-			add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), array( $this, 'plugin_action_links' ) );
134
-			add_filter( 'woocommerce_get_sections_checkout', array( $this, 'filter_gateway_order_admin' ) );
132
+			add_filter('woocommerce_payment_gateways', array($this, 'add_gateways'));
133
+			add_filter('plugin_action_links_' . plugin_basename(__FILE__), array($this, 'plugin_action_links'));
134
+			add_filter('woocommerce_get_sections_checkout', array($this, 'filter_gateway_order_admin'));
135 135
 		}
136 136
 
137 137
 		/**
@@ -141,23 +141,23 @@  discard block
 block discarded – undo
141 141
 		 * @version 4.0.0
142 142
 		 */
143 143
 		public function hide_notices() {
144
-			if ( isset( $_GET['wc-stripe-hide-notice'] ) && isset( $_GET['_wc_stripe_notice_nonce'] ) ) {
145
-				if ( ! wp_verify_nonce( $_GET['_wc_stripe_notice_nonce'], 'wc_stripe_hide_notices_nonce' ) ) {
146
-					wp_die( __( 'Action failed. Please refresh the page and retry.', 'woocommerce-gateway-stripe' ) );
144
+			if (isset($_GET['wc-stripe-hide-notice']) && isset($_GET['_wc_stripe_notice_nonce'])) {
145
+				if ( ! wp_verify_nonce($_GET['_wc_stripe_notice_nonce'], 'wc_stripe_hide_notices_nonce')) {
146
+					wp_die(__('Action failed. Please refresh the page and retry.', 'woocommerce-gateway-stripe'));
147 147
 				}
148 148
 
149
-				if ( ! current_user_can( 'manage_woocommerce' ) ) {
150
-					wp_die( __( 'Cheatin&#8217; huh?', 'woocommerce-gateway-stripe' ) );
149
+				if ( ! current_user_can('manage_woocommerce')) {
150
+					wp_die(__('Cheatin&#8217; huh?', 'woocommerce-gateway-stripe'));
151 151
 				}
152 152
 
153
-				$notice = wc_clean( $_GET['wc-stripe-hide-notice'] );
153
+				$notice = wc_clean($_GET['wc-stripe-hide-notice']);
154 154
 
155
-				switch ( $notice ) {
155
+				switch ($notice) {
156 156
 					case 'ssl':
157
-						update_option( 'wc_stripe_show_ssl_notice', 'no' );
157
+						update_option('wc_stripe_show_ssl_notice', 'no');
158 158
 						break;
159 159
 					case 'keys':
160
-						update_option( 'wc_stripe_show_keys_notice', 'no' );
160
+						update_option('wc_stripe_show_keys_notice', 'no');
161 161
 						break;
162 162
 				}
163 163
 			}
@@ -169,8 +169,8 @@  discard block
 block discarded – undo
169 169
 		 * @since 1.0.0
170 170
 		 * @version 4.0.0
171 171
 		 */
172
-		public function add_admin_notice( $slug, $class, $message, $dismissible = false ) {
173
-			$this->notices[ $slug ] = array(
172
+		public function add_admin_notice($slug, $class, $message, $dismissible = false) {
173
+			$this->notices[$slug] = array(
174 174
 				'class'       => $class,
175 175
 				'message'     => $message,
176 176
 				'dismissible' => $dismissible,
@@ -184,21 +184,21 @@  discard block
 block discarded – undo
184 184
 		 * @version 4.0.0
185 185
 		 */
186 186
 		public function admin_notices() {
187
-			if ( ! current_user_can( 'manage_woocommerce' ) ) {
187
+			if ( ! current_user_can('manage_woocommerce')) {
188 188
 				return;
189 189
 			}
190 190
 
191
-			foreach ( (array) $this->notices as $notice_key => $notice ) {
192
-				echo '<div class="' . esc_attr( $notice['class'] ) . '" style="position:relative;">';
191
+			foreach ((array) $this->notices as $notice_key => $notice) {
192
+				echo '<div class="' . esc_attr($notice['class']) . '" style="position:relative;">';
193 193
 
194
-				if ( $notice['dismissible'] ) {
194
+				if ($notice['dismissible']) {
195 195
 				?>
196
-					<a href="<?php echo esc_url( wp_nonce_url( add_query_arg( 'wc-stripe-hide-notice', $notice_key ), 'wc_stripe_hide_notices_nonce', '_wc_stripe_notice_nonce' ) ); ?>" class="woocommerce-message-close notice-dismiss" style="position:absolute;right:1px;padding:9px;text-decoration:none;"></a>
196
+					<a href="<?php echo esc_url(wp_nonce_url(add_query_arg('wc-stripe-hide-notice', $notice_key), 'wc_stripe_hide_notices_nonce', '_wc_stripe_notice_nonce')); ?>" class="woocommerce-message-close notice-dismiss" style="position:absolute;right:1px;padding:9px;text-decoration:none;"></a>
197 197
 				<?php
198 198
 				}
199 199
 
200 200
 				echo '<p>';
201
-				echo wp_kses( $notice['message'], array( 'a' => array( 'href' => array() ) ) );
201
+				echo wp_kses($notice['message'], array('a' => array('href' => array())));
202 202
 				echo '</p></div>';
203 203
 			}
204 204
 		}
@@ -211,26 +211,26 @@  discard block
 block discarded – undo
211 211
 		 * @version 4.0.0
212 212
 		 */
213 213
 		public function get_environment_warning() {
214
-			if ( version_compare( phpversion(), WC_STRIPE_MIN_PHP_VER, '<' ) ) {
214
+			if (version_compare(phpversion(), WC_STRIPE_MIN_PHP_VER, '<')) {
215 215
 				/* translators: 1) int version 2) int version */
216
-				$message = __( 'WooCommerce Stripe - The minimum PHP version required for this plugin is %1$s. You are running %2$s.', 'woocommerce-gateway-stripe' );
216
+				$message = __('WooCommerce Stripe - The minimum PHP version required for this plugin is %1$s. You are running %2$s.', 'woocommerce-gateway-stripe');
217 217
 
218
-				return sprintf( $message, WC_STRIPE_MIN_PHP_VER, phpversion() );
218
+				return sprintf($message, WC_STRIPE_MIN_PHP_VER, phpversion());
219 219
 			}
220 220
 
221
-			if ( ! defined( 'WC_VERSION' ) ) {
222
-				return __( 'WooCommerce Stripe requires WooCommerce to be activated to work.', 'woocommerce-gateway-stripe' );
221
+			if ( ! defined('WC_VERSION')) {
222
+				return __('WooCommerce Stripe requires WooCommerce to be activated to work.', 'woocommerce-gateway-stripe');
223 223
 			}
224 224
 
225
-			if ( version_compare( WC_VERSION, WC_STRIPE_MIN_WC_VER, '<' ) ) {
225
+			if (version_compare(WC_VERSION, WC_STRIPE_MIN_WC_VER, '<')) {
226 226
 				/* translators: 1) int version 2) int version */
227
-				$message = __( 'WooCommerce Stripe - The minimum WooCommerce version required for this plugin is %1$s. You are running %2$s.', 'woocommerce-gateway-stripe' );
227
+				$message = __('WooCommerce Stripe - The minimum WooCommerce version required for this plugin is %1$s. You are running %2$s.', 'woocommerce-gateway-stripe');
228 228
 
229
-				return sprintf( $message, WC_STRIPE_MIN_WC_VER, WC_VERSION );
229
+				return sprintf($message, WC_STRIPE_MIN_WC_VER, WC_VERSION);
230 230
 			}
231 231
 
232
-			if ( ! function_exists( 'curl_init' ) ) {
233
-				return __( 'WooCommerce Stripe - cURL is not installed.', 'woocommerce-gateway-stripe' );
232
+			if ( ! function_exists('curl_init')) {
233
+				return __('WooCommerce Stripe - cURL is not installed.', 'woocommerce-gateway-stripe');
234 234
 			}
235 235
 
236 236
 			return false;
@@ -244,11 +244,11 @@  discard block
 block discarded – undo
244 244
 		 * @return string Setting link
245 245
 		 */
246 246
 		public function get_setting_link() {
247
-			$use_id_as_section = function_exists( 'WC' ) ? version_compare( WC()->version, '2.6', '>=' ) : false;
247
+			$use_id_as_section = function_exists('WC') ? version_compare(WC()->version, '2.6', '>=') : false;
248 248
 
249
-			$section_slug = $use_id_as_section ? 'stripe' : strtolower( 'WC_Gateway_Stripe' );
249
+			$section_slug = $use_id_as_section ? 'stripe' : strtolower('WC_Gateway_Stripe');
250 250
 
251
-			return admin_url( 'admin.php?page=wc-settings&tab=checkout&section=' . $section_slug );
251
+			return admin_url('admin.php?page=wc-settings&tab=checkout&section=' . $section_slug);
252 252
 		}
253 253
 
254 254
 		/**
@@ -259,65 +259,65 @@  discard block
 block discarded – undo
259 259
 		 * @version 4.0.0
260 260
 		 */
261 261
 		public function check_environment() {
262
-			if ( ! defined( 'IFRAME_REQUEST' ) && ( WC_STRIPE_VERSION !== get_option( 'wc_stripe_version' ) ) ) {
262
+			if ( ! defined('IFRAME_REQUEST') && (WC_STRIPE_VERSION !== get_option('wc_stripe_version'))) {
263 263
 				$this->install();
264 264
 
265
-				do_action( 'woocommerce_stripe_updated' );
265
+				do_action('woocommerce_stripe_updated');
266 266
 			}
267 267
 
268 268
 			$environment_warning = $this->get_environment_warning();
269 269
 
270
-			if ( $environment_warning && is_plugin_active( plugin_basename( __FILE__ ) ) ) {
271
-				$this->add_admin_notice( 'bad_environment', 'error', $environment_warning );
270
+			if ($environment_warning && is_plugin_active(plugin_basename(__FILE__))) {
271
+				$this->add_admin_notice('bad_environment', 'error', $environment_warning);
272 272
 			}
273 273
 
274
-			$show_ssl_notice  = get_option( 'wc_stripe_show_ssl_notice' );
275
-			$show_keys_notice = get_option( 'wc_stripe_show_keys_notice' );
276
-			$options          = get_option( 'woocommerce_stripe_settings' );
277
-			$testmode         = ( isset( $options['testmode'] ) && 'yes' === $options['testmode'] ) ? true : false;
278
-			$test_pub_key     = isset( $options['test_publishable_key'] ) ? $options['test_publishable_key'] : '';
279
-			$test_secret_key  = isset( $options['test_secret_key'] ) ? $options['test_secret_key'] : '';
280
-			$live_pub_key     = isset( $options['publishable_key'] ) ? $options['publishable_key'] : '';
281
-			$live_secret_key  = isset( $options['secret_key'] ) ? $options['secret_key'] : '';
274
+			$show_ssl_notice  = get_option('wc_stripe_show_ssl_notice');
275
+			$show_keys_notice = get_option('wc_stripe_show_keys_notice');
276
+			$options          = get_option('woocommerce_stripe_settings');
277
+			$testmode         = (isset($options['testmode']) && 'yes' === $options['testmode']) ? true : false;
278
+			$test_pub_key     = isset($options['test_publishable_key']) ? $options['test_publishable_key'] : '';
279
+			$test_secret_key  = isset($options['test_secret_key']) ? $options['test_secret_key'] : '';
280
+			$live_pub_key     = isset($options['publishable_key']) ? $options['publishable_key'] : '';
281
+			$live_secret_key  = isset($options['secret_key']) ? $options['secret_key'] : '';
282 282
 
283
-			if ( isset( $options['enabled'] ) && 'yes' === $options['enabled'] && empty( $show_keys_notice ) ) {
284
-				$secret  = WC_Stripe_API::get_secret_key();
283
+			if (isset($options['enabled']) && 'yes' === $options['enabled'] && empty($show_keys_notice)) {
284
+				$secret = WC_Stripe_API::get_secret_key();
285 285
 
286
-				if ( empty( $secret ) && ! ( isset( $_GET['page'], $_GET['section'] ) && 'wc-settings' === $_GET['page'] && 'stripe' === $_GET['section'] ) ) {
286
+				if (empty($secret) && ! (isset($_GET['page'], $_GET['section']) && 'wc-settings' === $_GET['page'] && 'stripe' === $_GET['section'])) {
287 287
 					$setting_link = $this->get_setting_link();
288 288
 					/* translators: 1) link */
289
-					$this->add_admin_notice( 'keys', 'notice notice-warning', sprintf( __( 'Stripe is almost ready. To get started, <a href="%s">set your Stripe account keys</a>.', 'woocommerce-gateway-stripe' ), $setting_link ), true );
289
+					$this->add_admin_notice('keys', 'notice notice-warning', sprintf(__('Stripe is almost ready. To get started, <a href="%s">set your Stripe account keys</a>.', 'woocommerce-gateway-stripe'), $setting_link), true);
290 290
 				}
291 291
 
292 292
 				// Check if keys are entered properly per live/test mode.
293
-				if ( $testmode ) {
293
+				if ($testmode) {
294 294
 					if (
295
-						! empty( $test_pub_key ) && ! preg_match( '/^pk_test_/', $test_pub_key )
296
-						|| ( ! empty( $test_secret_key ) && ! preg_match( '/^sk_test_/', $test_secret_key )
297
-						&& ! empty( $test_secret_key ) && ! preg_match( '/^rk_test_/', $test_secret_key ) ) )
295
+						! empty($test_pub_key) && ! preg_match('/^pk_test_/', $test_pub_key)
296
+						|| ( ! empty($test_secret_key) && ! preg_match('/^sk_test_/', $test_secret_key)
297
+						&& ! empty($test_secret_key) && ! preg_match('/^rk_test_/', $test_secret_key)) )
298 298
 					{
299 299
 						$setting_link = $this->get_setting_link();
300 300
 						/* translators: 1) link */
301
-						$this->add_admin_notice( 'keys', 'notice notice-error', sprintf( __( 'Stripe is in test mode however your test keys may not be valid. Test keys start with pk_test and sk_test or rk_test. Please go to your settings and, <a href="%s">set your Stripe account keys</a>.', 'woocommerce-gateway-stripe' ), $setting_link ), true );
301
+						$this->add_admin_notice('keys', 'notice notice-error', sprintf(__('Stripe is in test mode however your test keys may not be valid. Test keys start with pk_test and sk_test or rk_test. Please go to your settings and, <a href="%s">set your Stripe account keys</a>.', 'woocommerce-gateway-stripe'), $setting_link), true);
302 302
 					}
303 303
 				} else {
304 304
 					if (
305
-						! empty( $live_pub_key ) && ! preg_match( '/^pk_live_/', $live_pub_key )
306
-						|| ( ! empty( $live_secret_key ) && ! preg_match( '/^sk_live_/', $live_secret_key )
307
-						&& ! empty( $live_secret_key ) && ! preg_match( '/^rk_live_/', $live_secret_key ) ) )
305
+						! empty($live_pub_key) && ! preg_match('/^pk_live_/', $live_pub_key)
306
+						|| ( ! empty($live_secret_key) && ! preg_match('/^sk_live_/', $live_secret_key)
307
+						&& ! empty($live_secret_key) && ! preg_match('/^rk_live_/', $live_secret_key)) )
308 308
 					{
309 309
 						$setting_link = $this->get_setting_link();
310 310
 						/* translators: 1) link */
311
-						$this->add_admin_notice( 'keys', 'notice notice-error', sprintf( __( 'Stripe is in live mode however your test keys may not be valid. Live keys start with pk_live and sk_live or rk_live. Please go to your settings and, <a href="%s">set your Stripe account keys</a>.', 'woocommerce-gateway-stripe' ), $setting_link ), true );
311
+						$this->add_admin_notice('keys', 'notice notice-error', sprintf(__('Stripe is in live mode however your test keys may not be valid. Live keys start with pk_live and sk_live or rk_live. Please go to your settings and, <a href="%s">set your Stripe account keys</a>.', 'woocommerce-gateway-stripe'), $setting_link), true);
312 312
 					}
313 313
 				}
314 314
 			}
315 315
 
316
-			if ( empty( $show_ssl_notice ) && isset( $options['enabled'] ) && 'yes' === $options['enabled'] ) {
316
+			if (empty($show_ssl_notice) && isset($options['enabled']) && 'yes' === $options['enabled']) {
317 317
 				// Show message if enabled and FORCE SSL is disabled and WordpressHTTPS plugin is not detected.
318
-				if ( ( function_exists( 'wc_site_is_https' ) && ! wc_site_is_https() ) && ( 'no' === get_option( 'woocommerce_force_ssl_checkout' ) && ! class_exists( 'WordPressHTTPS' ) ) ) {
318
+				if ((function_exists('wc_site_is_https') && ! wc_site_is_https()) && ('no' === get_option('woocommerce_force_ssl_checkout') && ! class_exists('WordPressHTTPS'))) {
319 319
 					/* translators: 1) link 2) link */
320
-					$this->add_admin_notice( 'ssl', 'notice notice-warning', sprintf( __( 'Stripe is enabled, but the <a href="%1$s">force SSL option</a> is disabled; your checkout may not be secure! Please enable SSL and ensure your server has a valid <a href="%2$s" target="_blank">SSL certificate</a> - Stripe will only work in test mode.', 'woocommerce-gateway-stripe' ), admin_url( 'admin.php?page=wc-settings&tab=checkout' ), 'https://en.wikipedia.org/wiki/Transport_Layer_Security' ), true );
320
+					$this->add_admin_notice('ssl', 'notice notice-warning', sprintf(__('Stripe is enabled, but the <a href="%1$s">force SSL option</a> is disabled; your checkout may not be secure! Please enable SSL and ensure your server has a valid <a href="%2$s" target="_blank">SSL certificate</a> - Stripe will only work in test mode.', 'woocommerce-gateway-stripe'), admin_url('admin.php?page=wc-settings&tab=checkout'), 'https://en.wikipedia.org/wiki/Transport_Layer_Security'), true);
321 321
 				}
322 322
 			}
323 323
 		}
@@ -329,8 +329,8 @@  discard block
 block discarded – undo
329 329
 		 * @version 4.0.0
330 330
 		 */
331 331
 		public function update_plugin_version() {
332
-			delete_option( 'wc_stripe_version' );
333
-			update_option( 'wc_stripe_version', WC_STRIPE_VERSION );
332
+			delete_option('wc_stripe_version');
333
+			update_option('wc_stripe_version', WC_STRIPE_VERSION);
334 334
 		}
335 335
 
336 336
 		/**
@@ -340,8 +340,8 @@  discard block
 block discarded – undo
340 340
 		 * @version 3.1.0
341 341
 		 */
342 342
 		public function install() {
343
-			if ( ! defined( 'WC_STRIPE_INSTALLING' ) ) {
344
-				define( 'WC_STRIPE_INSTALLING', true );
343
+			if ( ! defined('WC_STRIPE_INSTALLING')) {
344
+				define('WC_STRIPE_INSTALLING', true);
345 345
 			}
346 346
 
347 347
 			$this->update_plugin_version();
@@ -353,13 +353,13 @@  discard block
 block discarded – undo
353 353
 		 * @since 1.0.0
354 354
 		 * @version 4.0.0
355 355
 		 */
356
-		public function plugin_action_links( $links ) {
356
+		public function plugin_action_links($links) {
357 357
 			$plugin_links = array(
358
-				'<a href="admin.php?page=wc-settings&tab=checkout&section=stripe">' . esc_html__( 'Settings', 'woocommerce-gateway-stripe' ) . '</a>',
359
-				'<a href="https://docs.woocommerce.com/document/stripe/">' . esc_html__( 'Docs', 'woocommerce-gateway-stripe' ) . '</a>',
360
-				'<a href="https://woocommerce.com/contact-us/">' . esc_html__( 'Support', 'woocommerce-gateway-stripe' ) . '</a>',
358
+				'<a href="admin.php?page=wc-settings&tab=checkout&section=stripe">' . esc_html__('Settings', 'woocommerce-gateway-stripe') . '</a>',
359
+				'<a href="https://docs.woocommerce.com/document/stripe/">' . esc_html__('Docs', 'woocommerce-gateway-stripe') . '</a>',
360
+				'<a href="https://woocommerce.com/contact-us/">' . esc_html__('Support', 'woocommerce-gateway-stripe') . '</a>',
361 361
 			);
362
-			return array_merge( $plugin_links, $links );
362
+			return array_merge($plugin_links, $links);
363 363
 		}
364 364
 
365 365
 		/**
@@ -368,8 +368,8 @@  discard block
 block discarded – undo
368 368
 		 * @since 1.0.0
369 369
 		 * @version 4.0.0
370 370
 		 */
371
-		public function add_gateways( $methods ) {
372
-			if ( class_exists( 'WC_Subscriptions_Order' ) && function_exists( 'wcs_create_renewal_order' ) || class_exists( 'WC_Pre_Orders_Order' ) ) {
371
+		public function add_gateways($methods) {
372
+			if (class_exists('WC_Subscriptions_Order') && function_exists('wcs_create_renewal_order') || class_exists('WC_Pre_Orders_Order')) {
373 373
 				$methods[] = 'WC_Stripe_Compat';
374 374
 				$methods[] = 'WC_Stripe_Sepa_Compat';
375 375
 			} else {
@@ -394,26 +394,26 @@  discard block
 block discarded – undo
394 394
 		 * @since 4.0.0
395 395
 		 * @version 4.0.0
396 396
 		 */
397
-		public function filter_gateway_order_admin( $sections ) {
398
-			unset( $sections['stripe'] );
399
-			unset( $sections['stripe_bancontact'] );
400
-			unset( $sections['stripe_sofort'] );
401
-			unset( $sections['stripe_giropay'] );
402
-			unset( $sections['stripe_ideal'] );
403
-			unset( $sections['stripe_p24'] );
404
-			unset( $sections['stripe_alipay'] );
405
-			unset( $sections['stripe_sepa'] );
406
-			unset( $sections['stripe_bitcoin'] );
397
+		public function filter_gateway_order_admin($sections) {
398
+			unset($sections['stripe']);
399
+			unset($sections['stripe_bancontact']);
400
+			unset($sections['stripe_sofort']);
401
+			unset($sections['stripe_giropay']);
402
+			unset($sections['stripe_ideal']);
403
+			unset($sections['stripe_p24']);
404
+			unset($sections['stripe_alipay']);
405
+			unset($sections['stripe_sepa']);
406
+			unset($sections['stripe_bitcoin']);
407 407
 
408 408
 			$sections['stripe']            = 'Stripe';
409
-			$sections['stripe_bancontact'] = __( 'Stripe Bancontact', 'woocommerce-gateway-stripe' );
410
-			$sections['stripe_sofort']     = __( 'Stripe SOFORT', 'woocommerce-gateway-stripe' );
411
-			$sections['stripe_giropay']    = __( 'Stripe Giropay', 'woocommerce-gateway-stripe' );
412
-			$sections['stripe_ideal']      = __( 'Stripe iDeal', 'woocommerce-gateway-stripe' );
413
-			$sections['stripe_p24']        = __( 'Stripe P24', 'woocommerce-gateway-stripe' );
414
-			$sections['stripe_alipay']     = __( 'Stripe Alipay', 'woocommerce-gateway-stripe' );
415
-			$sections['stripe_sepa']       = __( 'Stripe SEPA Direct Debit', 'woocommerce-gateway-stripe' );
416
-			$sections['stripe_bitcoin']    = __( 'Stripe Bitcoin', 'woocommerce-gateway-stripe' );
409
+			$sections['stripe_bancontact'] = __('Stripe Bancontact', 'woocommerce-gateway-stripe');
410
+			$sections['stripe_sofort']     = __('Stripe SOFORT', 'woocommerce-gateway-stripe');
411
+			$sections['stripe_giropay']    = __('Stripe Giropay', 'woocommerce-gateway-stripe');
412
+			$sections['stripe_ideal']      = __('Stripe iDeal', 'woocommerce-gateway-stripe');
413
+			$sections['stripe_p24']        = __('Stripe P24', 'woocommerce-gateway-stripe');
414
+			$sections['stripe_alipay']     = __('Stripe Alipay', 'woocommerce-gateway-stripe');
415
+			$sections['stripe_sepa']       = __('Stripe SEPA Direct Debit', 'woocommerce-gateway-stripe');
416
+			$sections['stripe_bitcoin']    = __('Stripe Bitcoin', 'woocommerce-gateway-stripe');
417 417
 
418 418
 			return $sections;
419 419
 		}
Please login to merge, or discard this patch.