Completed
Push — master ( c1ff6b...717fdd )
by Roy
02:07
created
includes/class-wc-stripe-order-handler.php 1 patch
Spacing   +97 added lines, -97 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 = 1;
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,129 +75,129 @@  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
 			/* If we're doing a retry and source is chargeable, we need to pass
113 113
 			 * a different idempotency key and retry for success.
114 114
 			 */
115
-			if ( 1 < $this->retry_interval && 'chargeable' === $source_info->status ) {
116
-				add_filter( 'wc_stripe_idempotency_key', array( $this, 'change_idempotency_key' ), 10, 2 );
115
+			if (1 < $this->retry_interval && 'chargeable' === $source_info->status) {
116
+				add_filter('wc_stripe_idempotency_key', array($this, 'change_idempotency_key'), 10, 2);
117 117
 			}
118 118
 
119 119
 			// Make the request.
120
-			$response = WC_Stripe_API::request( $this->generate_payment_request( $order, $source_object ), 'charges', 'POST', true );
120
+			$response = WC_Stripe_API::request($this->generate_payment_request($order, $source_object), 'charges', 'POST', true);
121 121
 			$headers  = $response['headers'];
122 122
 			$response = $response['body'];
123 123
 
124
-			if ( ! empty( $response->error ) ) {
124
+			if ( ! empty($response->error)) {
125 125
 				// Customer param wrong? The user may have been deleted on stripe's end. Remove customer_id. Can be retried without.
126
-				if ( preg_match( '/No such customer/i', $response->error->message ) && $retry ) {
127
-					if ( WC_Stripe_Helper::is_pre_30() ) {
128
-						delete_user_meta( $order->customer_user, '_stripe_customer_id' );
129
-						delete_post_meta( $order_id, '_stripe_customer_id' );
126
+				if (preg_match('/No such customer/i', $response->error->message) && $retry) {
127
+					if (WC_Stripe_Helper::is_pre_30()) {
128
+						delete_user_meta($order->customer_user, '_stripe_customer_id');
129
+						delete_post_meta($order_id, '_stripe_customer_id');
130 130
 					} else {
131
-						delete_user_meta( $order->get_customer_id(), '_stripe_customer_id' );
132
-						$order->delete_meta_data( '_stripe_customer_id' );
131
+						delete_user_meta($order->get_customer_id(), '_stripe_customer_id');
132
+						$order->delete_meta_data('_stripe_customer_id');
133 133
 						$order->save();
134 134
 					}
135 135
 
136
-					return $this->process_redirect_payment( $order_id, false );
136
+					return $this->process_redirect_payment($order_id, false);
137 137
 
138
-				} elseif ( preg_match( '/No such token/i', $response->error->message ) && $source_object->token_id ) {
138
+				} elseif (preg_match('/No such token/i', $response->error->message) && $source_object->token_id) {
139 139
 					// Source param wrong? The CARD may have been deleted on stripe's end. Remove token and show message.
140 140
 
141
-					$wc_token = WC_Payment_Tokens::get( $source_object->token_id );
141
+					$wc_token = WC_Payment_Tokens::get($source_object->token_id);
142 142
 					$wc_token->delete();
143
-					$message = __( 'This card is no longer available and has been removed.', 'woocommerce-gateway-stripe' );
144
-					$order->add_order_note( $message );
145
-					throw new WC_Stripe_Exception( print_r( $response, true ), $message );
143
+					$message = __('This card is no longer available and has been removed.', 'woocommerce-gateway-stripe');
144
+					$order->add_order_note($message);
145
+					throw new WC_Stripe_Exception(print_r($response, true), $message);
146 146
 				}
147 147
 
148 148
 				// We want to retry.
149
-				if ( $this->is_retryable_error( $response->error ) ) {
150
-					if ( $retry ) {
149
+				if ($this->is_retryable_error($response->error)) {
150
+					if ($retry) {
151 151
 						// Don't do anymore retries after this.
152
-						if ( 5 <= $this->retry_interval ) {
153
-							return $this->process_redirect_payment( $order_id, false );
152
+						if (5 <= $this->retry_interval) {
153
+							return $this->process_redirect_payment($order_id, false);
154 154
 						}
155 155
 
156
-						sleep( $this->retry_interval );
156
+						sleep($this->retry_interval);
157 157
 
158 158
 						$this->retry_interval++;
159
-						return $this->process_redirect_payment( $order_id, true );
159
+						return $this->process_redirect_payment($order_id, true);
160 160
 					} else {
161
-						$localized_message = __( 'On going requests error and retries exhausted.', 'woocommerce-gateway-stripe' );
162
-						$order->add_order_note( $localized_message );
163
-						throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message );
161
+						$localized_message = __('On going requests error and retries exhausted.', 'woocommerce-gateway-stripe');
162
+						$order->add_order_note($localized_message);
163
+						throw new WC_Stripe_Exception(print_r($response, true), $localized_message);
164 164
 					}
165 165
 				}
166 166
 
167 167
 				$localized_messages = WC_Stripe_Helper::get_localized_messages();
168 168
 
169
-				if ( 'card_error' === $response->error->type ) {
170
-					$message = isset( $localized_messages[ $response->error->code ] ) ? $localized_messages[ $response->error->code ] : $response->error->message;
169
+				if ('card_error' === $response->error->type) {
170
+					$message = isset($localized_messages[$response->error->code]) ? $localized_messages[$response->error->code] : $response->error->message;
171 171
 				} else {
172
-					$message = isset( $localized_messages[ $response->error->type ] ) ? $localized_messages[ $response->error->type ] : $response->error->message;
172
+					$message = isset($localized_messages[$response->error->type]) ? $localized_messages[$response->error->type] : $response->error->message;
173 173
 				}
174 174
 
175
-				throw new WC_Stripe_Exception( print_r( $response, true ), $message );
175
+				throw new WC_Stripe_Exception(print_r($response, true), $message);
176 176
 			}
177 177
 
178 178
 			// To prevent double processing the order on WC side.
179
-			if ( ! $this->is_original_request( $headers ) ) {
179
+			if ( ! $this->is_original_request($headers)) {
180 180
 				return;
181 181
 			}
182 182
 
183
-			do_action( 'wc_gateway_stripe_process_redirect_payment', $response, $order );
183
+			do_action('wc_gateway_stripe_process_redirect_payment', $response, $order);
184 184
 
185
-			$this->process_response( $response, $order );
185
+			$this->process_response($response, $order);
186 186
 
187
-		} catch ( WC_Stripe_Exception $e ) {
188
-			WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() );
187
+		} catch (WC_Stripe_Exception $e) {
188
+			WC_Stripe_Logger::log('Error: ' . $e->getMessage());
189 189
 
190
-			do_action( 'wc_gateway_stripe_process_redirect_payment_error', $e, $order );
190
+			do_action('wc_gateway_stripe_process_redirect_payment_error', $e, $order);
191 191
 
192 192
 			/* translators: error message */
193
-			$order->update_status( 'failed', sprintf( __( 'Stripe payment failed: %s', 'woocommerce-gateway-stripe' ), $e->getLocalizedMessage() ) );
193
+			$order->update_status('failed', sprintf(__('Stripe payment failed: %s', 'woocommerce-gateway-stripe'), $e->getLocalizedMessage()));
194 194
 
195
-			if ( $order->has_status( array( 'pending', 'failed' ) ) ) {
196
-				$this->send_failed_order_email( $order_id );
195
+			if ($order->has_status(array('pending', 'failed'))) {
196
+				$this->send_failed_order_email($order_id);
197 197
 			}
198 198
 
199
-			wc_add_notice( $e->getLocalizedMessage(), 'error' );
200
-			wp_safe_redirect( wc_get_checkout_url() );
199
+			wc_add_notice($e->getLocalizedMessage(), 'error');
200
+			wp_safe_redirect(wc_get_checkout_url());
201 201
 			exit;
202 202
 		}
203 203
 	}
@@ -209,13 +209,13 @@  discard block
 block discarded – undo
209 209
 	 * @version 4.0.0
210 210
 	 */
211 211
 	public function maybe_process_redirect_order() {
212
-		if ( ! is_order_received_page() || empty( $_GET['client_secret'] ) || empty( $_GET['source'] ) ) {
212
+		if ( ! is_order_received_page() || empty($_GET['client_secret']) || empty($_GET['source'])) {
213 213
 			return;
214 214
 		}
215 215
 
216
-		$order_id = wc_clean( $_GET['order_id'] );
216
+		$order_id = wc_clean($_GET['order_id']);
217 217
 
218
-		$this->process_redirect_payment( $order_id );
218
+		$this->process_redirect_payment($order_id);
219 219
 	}
220 220
 
221 221
 	/**
@@ -225,52 +225,52 @@  discard block
 block discarded – undo
225 225
 	 * @version 4.0.0
226 226
 	 * @param  int $order_id
227 227
 	 */
228
-	public function capture_payment( $order_id ) {
229
-		$order = wc_get_order( $order_id );
228
+	public function capture_payment($order_id) {
229
+		$order = wc_get_order($order_id);
230 230
 
231
-		if ( 'stripe' === ( WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method() ) ) {
232
-			$charge   = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_transaction_id', true ) : $order->get_transaction_id();
233
-			$captured = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_stripe_charge_captured', true ) : $order->get_meta( '_stripe_charge_captured', true );
231
+		if ('stripe' === (WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method())) {
232
+			$charge   = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_transaction_id', true) : $order->get_transaction_id();
233
+			$captured = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_stripe_charge_captured', true) : $order->get_meta('_stripe_charge_captured', true);
234 234
 
235
-			if ( $charge && 'no' === $captured ) {
235
+			if ($charge && 'no' === $captured) {
236 236
 				$order_total = $order->get_total();
237 237
 
238
-				if ( 0 < $order->get_total_refunded() ) {
238
+				if (0 < $order->get_total_refunded()) {
239 239
 					$order_total = $order_total - $order->get_total_refunded();
240 240
 				}
241 241
 
242
-				$result = WC_Stripe_API::request( array(
243
-					'amount'   => WC_Stripe_Helper::get_stripe_amount( $order_total ),
242
+				$result = WC_Stripe_API::request(array(
243
+					'amount'   => WC_Stripe_Helper::get_stripe_amount($order_total),
244 244
 					'expand[]' => 'balance_transaction',
245
-				), 'charges/' . $charge . '/capture' );
245
+				), 'charges/' . $charge . '/capture');
246 246
 
247
-				if ( ! empty( $result->error ) ) {
247
+				if ( ! empty($result->error)) {
248 248
 					/* translators: error message */
249
-					$order->update_status( 'failed', sprintf( __( 'Unable to capture charge! %s', 'woocommerce-gateway-stripe' ), $result->error->message ) );
249
+					$order->update_status('failed', sprintf(__('Unable to capture charge! %s', 'woocommerce-gateway-stripe'), $result->error->message));
250 250
 				} else {
251 251
 					/* translators: transaction id */
252
-					$order->add_order_note( sprintf( __( 'Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe' ), $result->id ) );
253
-					WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, '_stripe_charge_captured', 'yes' ) : $order->update_meta_data( '_stripe_charge_captured', 'yes' );
252
+					$order->add_order_note(sprintf(__('Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe'), $result->id));
253
+					WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, '_stripe_charge_captured', 'yes') : $order->update_meta_data('_stripe_charge_captured', 'yes');
254 254
 
255 255
 					// Store other data such as fees
256
-					WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, '_transaction_id', $result->id ) : $order->set_transaction_id( $result->id );
256
+					WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, '_transaction_id', $result->id) : $order->set_transaction_id($result->id);
257 257
 
258
-					if ( isset( $result->balance_transaction ) && isset( $result->balance_transaction->fee ) ) {
258
+					if (isset($result->balance_transaction) && isset($result->balance_transaction->fee)) {
259 259
 						// Fees and Net needs to both come from Stripe to be accurate as the returned
260 260
 						// values are in the local currency of the Stripe account, not from WC.
261
-						$fee = ! empty( $result->balance_transaction->fee ) ? WC_Stripe_Helper::format_balance_fee( $result->balance_transaction, 'fee' ) : 0;
262
-						$net = ! empty( $result->balance_transaction->net ) ? WC_Stripe_Helper::format_balance_fee( $result->balance_transaction, 'net' ) : 0;
263
-						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 );
264
-						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 );
261
+						$fee = ! empty($result->balance_transaction->fee) ? WC_Stripe_Helper::format_balance_fee($result->balance_transaction, 'fee') : 0;
262
+						$net = ! empty($result->balance_transaction->net) ? WC_Stripe_Helper::format_balance_fee($result->balance_transaction, 'net') : 0;
263
+						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);
264
+						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);
265 265
 					}
266 266
 
267
-					if ( is_callable( array( $order, 'save' ) ) ) {
267
+					if (is_callable(array($order, 'save'))) {
268 268
 						$order->save();
269 269
 					}
270 270
 				}
271 271
 
272 272
 				// This hook fires when admin manually changes order status to processing or completed.
273
-				do_action( 'woocommerce_stripe_process_manual_capture', $order, $result );
273
+				do_action('woocommerce_stripe_process_manual_capture', $order, $result);
274 274
 			}
275 275
 		}
276 276
 	}
@@ -282,14 +282,14 @@  discard block
 block discarded – undo
282 282
 	 * @version 4.0.0
283 283
 	 * @param  int $order_id
284 284
 	 */
285
-	public function cancel_payment( $order_id ) {
286
-		$order = wc_get_order( $order_id );
285
+	public function cancel_payment($order_id) {
286
+		$order = wc_get_order($order_id);
287 287
 
288
-		if ( 'stripe' === ( WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method() ) ) {
289
-			$this->process_refund( $order_id );
288
+		if ('stripe' === (WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method())) {
289
+			$this->process_refund($order_id);
290 290
 
291 291
 			// This hook fires when admin manually changes order status to cancel.
292
-			do_action( 'woocommerce_stripe_process_manual_cancel', $order );
292
+			do_action('woocommerce_stripe_process_manual_cancel', $order);
293 293
 		}
294 294
 	}
295 295
 
@@ -300,8 +300,8 @@  discard block
 block discarded – undo
300 300
 	 * @version 4.0.0
301 301
 	 */
302 302
 	public function validate_checkout() {
303
-		if ( ! wp_verify_nonce( $_POST['nonce'], '_wc_stripe_nonce' ) ) {
304
-			wp_die( __( 'Cheatin&#8217; huh?', 'woocommerce-gateway-stripe' ) );
303
+		if ( ! wp_verify_nonce($_POST['nonce'], '_wc_stripe_nonce')) {
304
+			wp_die(__('Cheatin&#8217; huh?', 'woocommerce-gateway-stripe'));
305 305
 		}
306 306
 
307 307
 		/*
@@ -309,7 +309,7 @@  discard block
 block discarded – undo
309 309
 		 * i.e. wp_send_json( 'success' ); // On successful validation.
310 310
 		 * i.e. For errors follow WC https://github.com/woocommerce/woocommerce/blob/master/includes/class-wc-checkout.php#L918-L938
311 311
 		 */
312
-		do_action( 'wc_stripe_validate_modal_checkout_action', $_POST['required_fields'], $_POST['all_fields'] );
312
+		do_action('wc_stripe_validate_modal_checkout_action', $_POST['required_fields'], $_POST['all_fields']);
313 313
 	}
314 314
 }
315 315
 
Please login to merge, or discard this patch.
includes/class-wc-stripe-apple-pay-registration.php 1 patch
Spacing   +46 added lines, -46 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,21 +60,21 @@  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
 
71
-		if ( empty( $this->stripe_settings ) ) {
71
+		if (empty($this->stripe_settings)) {
72 72
 			return;
73 73
 		}
74 74
 
75 75
 		$this->init_apple_pay();
76 76
 
77
-		add_action( 'admin_notices', array( $this, 'admin_notices' ) );
77
+		add_action('admin_notices', array($this, 'admin_notices'));
78 78
 	}
79 79
 
80 80
 	/**
@@ -85,13 +85,13 @@  discard block
 block discarded – undo
85 85
 	 * @param string default
86 86
 	 * @return string $setting_value
87 87
 	 */
88
-	public function get_option( $setting = '', $default = '' ) {
89
-		if ( empty( $this->stripe_settings ) ) {
88
+	public function get_option($setting = '', $default = '') {
89
+		if (empty($this->stripe_settings)) {
90 90
 			return $default;
91 91
 		}
92 92
 
93
-		if ( ! empty( $this->stripe_settings[ $setting ] ) ) {
94
-			return $this->stripe_settings[ $setting ];
93
+		if ( ! empty($this->stripe_settings[$setting])) {
94
+			return $this->stripe_settings[$setting];
95 95
 		}
96 96
 
97 97
 		return $default;
@@ -106,9 +106,9 @@  discard block
 block discarded – undo
106 106
 	public function init_apple_pay() {
107 107
 		if (
108 108
 			is_admin() &&
109
-			isset( $_GET['page'] ) && 'wc-settings' === $_GET['page'] &&
110
-			isset( $_GET['tab'] ) && 'checkout' === $_GET['tab'] &&
111
-			isset( $_GET['section'] ) && 'stripe' === $_GET['section'] &&
109
+			isset($_GET['page']) && 'wc-settings' === $_GET['page'] &&
110
+			isset($_GET['tab']) && 'checkout' === $_GET['tab'] &&
111
+			isset($_GET['section']) && 'stripe' === $_GET['section'] &&
112 112
 			$this->payment_request
113 113
 		) {
114 114
 			$this->process_apple_pay_verification();
@@ -122,9 +122,9 @@  discard block
 block discarded – undo
122 122
 	 * @version 3.1.0
123 123
 	 * @param string $secret_key
124 124
 	 */
125
-	private function register_apple_pay_domain( $secret_key = '' ) {
126
-		if ( empty( $secret_key ) ) {
127
-			throw new Exception( __( 'Unable to verify domain - missing secret key.', 'woocommerce-gateway-stripe' ) );
125
+	private function register_apple_pay_domain($secret_key = '') {
126
+		if (empty($secret_key)) {
127
+			throw new Exception(__('Unable to verify domain - missing secret key.', 'woocommerce-gateway-stripe'));
128 128
 		}
129 129
 
130 130
 		$endpoint = 'https://api.stripe.com/v1/apple_pay/domains';
@@ -138,23 +138,23 @@  discard block
 block discarded – undo
138 138
 			'Authorization' => 'Bearer ' . $secret_key,
139 139
 		);
140 140
 
141
-		$response = wp_remote_post( $endpoint, array(
141
+		$response = wp_remote_post($endpoint, array(
142 142
 			'headers' => $headers,
143
-			'body'    => http_build_query( $data ),
144
-		) );
143
+			'body'    => http_build_query($data),
144
+		));
145 145
 
146
-		if ( is_wp_error( $response ) ) {
146
+		if (is_wp_error($response)) {
147 147
 			/* translators: error message */
148
-			throw new Exception( sprintf( __( 'Unable to verify domain - %s', 'woocommerce-gateway-stripe' ), $response->get_error_message() ) );
148
+			throw new Exception(sprintf(__('Unable to verify domain - %s', 'woocommerce-gateway-stripe'), $response->get_error_message()));
149 149
 		}
150 150
 
151
-		if ( 200 !== $response['response']['code'] ) {
152
-			$parsed_response = json_decode( $response['body'] );
151
+		if (200 !== $response['response']['code']) {
152
+			$parsed_response = json_decode($response['body']);
153 153
 
154 154
 			$this->apple_pay_verify_notice = $parsed_response->error->message;
155 155
 
156 156
 			/* translators: error message */
157
-			throw new Exception( sprintf( __( 'Unable to verify domain - %s', 'woocommerce-gateway-stripe' ), $parsed_response->error->message ) );
157
+			throw new Exception(sprintf(__('Unable to verify domain - %s', 'woocommerce-gateway-stripe'), $parsed_response->error->message));
158 158
 		}
159 159
 	}
160 160
 
@@ -166,45 +166,45 @@  discard block
 block discarded – undo
166 166
 	 */
167 167
 	public function process_apple_pay_verification() {
168 168
 		try {
169
-			$path     = untrailingslashit( $_SERVER['DOCUMENT_ROOT'] );
169
+			$path     = untrailingslashit($_SERVER['DOCUMENT_ROOT']);
170 170
 			$dir      = '.well-known';
171 171
 			$file     = 'apple-developer-merchantid-domain-association';
172 172
 			$fullpath = $path . '/' . $dir . '/' . $file;
173 173
 
174
-			if ( $this->apple_pay_domain_set && file_exists( $fullpath ) ) {
174
+			if ($this->apple_pay_domain_set && file_exists($fullpath)) {
175 175
 				return;
176 176
 			}
177 177
 
178
-			if ( ! file_exists( $path . '/' . $dir ) ) {
179
-				if ( ! @mkdir( $path . '/' . $dir, 0755 ) ) { // @codingStandardsIgnoreLine
180
-					throw new Exception( __( 'Unable to create domain association folder to domain root.', 'woocommerce-gateway-stripe' ) );
178
+			if ( ! file_exists($path . '/' . $dir)) {
179
+				if ( ! @mkdir($path . '/' . $dir, 0755)) { // @codingStandardsIgnoreLine
180
+					throw new Exception(__('Unable to create domain association folder to domain root.', 'woocommerce-gateway-stripe'));
181 181
 				}
182 182
 			}
183 183
 
184
-			if ( ! file_exists( $fullpath ) ) {
185
-				if ( ! @copy( WC_STRIPE_PLUGIN_PATH . '/' . $file, $fullpath ) ) { // @codingStandardsIgnoreLine
186
-					throw new Exception( __( 'Unable to copy domain association file to domain root.', 'woocommerce-gateway-stripe' ) );
184
+			if ( ! file_exists($fullpath)) {
185
+				if ( ! @copy(WC_STRIPE_PLUGIN_PATH . '/' . $file, $fullpath)) { // @codingStandardsIgnoreLine
186
+					throw new Exception(__('Unable to copy domain association file to domain root.', 'woocommerce-gateway-stripe'));
187 187
 				}
188 188
 			}
189 189
 
190 190
 			// At this point then the domain association folder and file should be available.
191 191
 			// Proceed to verify/and or verify again.
192
-			$this->register_apple_pay_domain( $this->secret_key );
192
+			$this->register_apple_pay_domain($this->secret_key);
193 193
 
194 194
 			// No errors to this point, verification success!
195 195
 			$this->stripe_settings['apple_pay_domain_set'] = 'yes';
196 196
 			$this->apple_pay_domain_set = true;
197 197
 
198
-			update_option( 'woocommerce_stripe_settings', $this->stripe_settings );
198
+			update_option('woocommerce_stripe_settings', $this->stripe_settings);
199 199
 
200
-			WC_Stripe_Logger::log( 'Your domain has been verified with Apple Pay!' );
200
+			WC_Stripe_Logger::log('Your domain has been verified with Apple Pay!');
201 201
 
202
-		} catch ( Exception $e ) {
202
+		} catch (Exception $e) {
203 203
 			$this->stripe_settings['apple_pay_domain_set'] = 'no';
204 204
 
205
-			update_option( 'woocommerce_stripe_settings', $this->stripe_settings );
205
+			update_option('woocommerce_stripe_settings', $this->stripe_settings);
206 206
 
207
-			WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() );
207
+			WC_Stripe_Logger::log('Error: ' . $e->getMessage());
208 208
 		}
209 209
 	}
210 210
 
@@ -214,11 +214,11 @@  discard block
 block discarded – undo
214 214
 	 * @since 4.0.6
215 215
 	 */
216 216
 	public function admin_notices() {
217
-		if ( ! $this->stripe_enabled ) {
217
+		if ( ! $this->stripe_enabled) {
218 218
 			return;
219 219
 		}
220 220
 
221
-		if ( $this->payment_request && ! empty( $this->apple_pay_verify_notice ) ) {
221
+		if ($this->payment_request && ! empty($this->apple_pay_verify_notice)) {
222 222
 			$allowed_html = array(
223 223
 				'a' => array(
224 224
 					'href' => array(),
@@ -226,7 +226,7 @@  discard block
 block discarded – undo
226 226
 				),
227 227
 			);
228 228
 
229
-			echo '<div class="error stripe-apple-pay-message"><p>' . wp_kses( make_clickable( $this->apple_pay_verify_notice ), $allowed_html ) . '</p></div>';
229
+			echo '<div class="error stripe-apple-pay-message"><p>' . wp_kses(make_clickable($this->apple_pay_verify_notice), $allowed_html) . '</p></div>';
230 230
 		}
231 231
 
232 232
 		/**
@@ -234,9 +234,9 @@  discard block
 block discarded – undo
234 234
 		 * when setting screen is displayed. So if domain verification is not set,
235 235
 		 * something went wrong so lets notify user.
236 236
 		 */
237
-		if ( ! empty( $this->secret_key ) && $this->payment_request && ! $this->apple_pay_domain_set ) {
237
+		if ( ! empty($this->secret_key) && $this->payment_request && ! $this->apple_pay_domain_set) {
238 238
 			/* translators: 1) HTML anchor open tag 2) HTML anchor closing tag */
239
-			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>';
239
+			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>';
240 240
 		}
241 241
 	}
242 242
 }
Please login to merge, or discard this patch.
includes/admin/stripe-settings.php 1 patch
Spacing   +67 added lines, -67 removed lines patch added patch discarded remove patch
@@ -1,191 +1,191 @@
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) {
2
+if ( ! defined('ABSPATH')) {
3 3
 	exit;
4 4
 }
5 5
 
6 6
 $webhook_url = WC_Stripe_Helper::get_webhook_url();
7 7
 
8
-return apply_filters( 'wc_stripe_settings',
8
+return apply_filters('wc_stripe_settings',
9 9
 	array(
10 10
 		'enabled' => array(
11
-			'title'       => __( 'Enable/Disable', 'woocommerce-gateway-stripe' ),
12
-			'label'       => __( 'Enable Stripe', 'woocommerce-gateway-stripe' ),
11
+			'title'       => __('Enable/Disable', 'woocommerce-gateway-stripe'),
12
+			'label'       => __('Enable Stripe', 'woocommerce-gateway-stripe'),
13 13
 			'type'        => 'checkbox',
14 14
 			'description' => '',
15 15
 			'default'     => 'no',
16 16
 		),
17 17
 		'title' => array(
18
-			'title'       => __( 'Title', 'woocommerce-gateway-stripe' ),
18
+			'title'       => __('Title', 'woocommerce-gateway-stripe'),
19 19
 			'type'        => 'text',
20
-			'description' => __( 'This controls the title which the user sees during checkout.', 'woocommerce-gateway-stripe' ),
21
-			'default'     => __( 'Credit Card (Stripe)', 'woocommerce-gateway-stripe' ),
20
+			'description' => __('This controls the title which the user sees during checkout.', 'woocommerce-gateway-stripe'),
21
+			'default'     => __('Credit Card (Stripe)', 'woocommerce-gateway-stripe'),
22 22
 			'desc_tip'    => true,
23 23
 		),
24 24
 		'description' => array(
25
-			'title'       => __( 'Description', 'woocommerce-gateway-stripe' ),
25
+			'title'       => __('Description', 'woocommerce-gateway-stripe'),
26 26
 			'type'        => 'text',
27
-			'description' => __( 'This controls the description which the user sees during checkout.', 'woocommerce-gateway-stripe' ),
28
-			'default'     => __( 'Pay with your credit card via Stripe.', 'woocommerce-gateway-stripe' ),
27
+			'description' => __('This controls the description which the user sees during checkout.', 'woocommerce-gateway-stripe'),
28
+			'default'     => __('Pay with your credit card via Stripe.', 'woocommerce-gateway-stripe'),
29 29
 			'desc_tip'    => true,
30 30
 		),
31 31
 		'webhook' => array(
32
-			'title'       => __( 'Webhook Endpoints', 'woocommerce-gateway-stripe' ),
32
+			'title'       => __('Webhook Endpoints', 'woocommerce-gateway-stripe'),
33 33
 			'type'        => 'title',
34 34
 			/* translators: webhook URL */
35
-			'description' => sprintf( __( 'You must add the webhook endpoint <strong style="background-color:#ddd;">&nbsp;&nbsp;%s&nbsp;&nbsp;</strong> to your Stripe Account Settings <a href="https://dashboard.stripe.com/account/webhooks" target="_blank">Here</a> so you can receive notifications on the charge statuses.', 'woocommerce-gateway-stripe' ), $webhook_url ),
35
+			'description' => sprintf(__('You must add the webhook endpoint <strong style="background-color:#ddd;">&nbsp;&nbsp;%s&nbsp;&nbsp;</strong> to your Stripe Account Settings <a href="https://dashboard.stripe.com/account/webhooks" target="_blank">Here</a> so you can receive notifications on the charge statuses.', 'woocommerce-gateway-stripe'), $webhook_url),
36 36
 		),
37 37
 		'testmode' => array(
38
-			'title'       => __( 'Test mode', 'woocommerce-gateway-stripe' ),
39
-			'label'       => __( 'Enable Test Mode', 'woocommerce-gateway-stripe' ),
38
+			'title'       => __('Test mode', 'woocommerce-gateway-stripe'),
39
+			'label'       => __('Enable Test Mode', 'woocommerce-gateway-stripe'),
40 40
 			'type'        => 'checkbox',
41
-			'description' => __( 'Place the payment gateway in test mode using test API keys.', 'woocommerce-gateway-stripe' ),
41
+			'description' => __('Place the payment gateway in test mode using test API keys.', 'woocommerce-gateway-stripe'),
42 42
 			'default'     => 'yes',
43 43
 			'desc_tip'    => true,
44 44
 		),
45 45
 		'test_publishable_key' => array(
46
-			'title'       => __( 'Test Publishable Key', 'woocommerce-gateway-stripe' ),
46
+			'title'       => __('Test Publishable Key', 'woocommerce-gateway-stripe'),
47 47
 			'type'        => 'password',
48
-			'description' => __( 'Get your API keys from your stripe account.', 'woocommerce-gateway-stripe' ),
48
+			'description' => __('Get your API keys from your stripe account.', 'woocommerce-gateway-stripe'),
49 49
 			'default'     => '',
50 50
 			'desc_tip'    => true,
51 51
 		),
52 52
 		'test_secret_key' => array(
53
-			'title'       => __( 'Test Secret Key', 'woocommerce-gateway-stripe' ),
53
+			'title'       => __('Test Secret Key', 'woocommerce-gateway-stripe'),
54 54
 			'type'        => 'password',
55
-			'description' => __( 'Get your API keys from your stripe account.', 'woocommerce-gateway-stripe' ),
55
+			'description' => __('Get your API keys from your stripe account.', 'woocommerce-gateway-stripe'),
56 56
 			'default'     => '',
57 57
 			'desc_tip'    => true,
58 58
 		),
59 59
 		'publishable_key' => array(
60
-			'title'       => __( 'Live Publishable Key', 'woocommerce-gateway-stripe' ),
60
+			'title'       => __('Live Publishable Key', 'woocommerce-gateway-stripe'),
61 61
 			'type'        => 'password',
62
-			'description' => __( 'Get your API keys from your stripe account.', 'woocommerce-gateway-stripe' ),
62
+			'description' => __('Get your API keys from your stripe account.', 'woocommerce-gateway-stripe'),
63 63
 			'default'     => '',
64 64
 			'desc_tip'    => true,
65 65
 		),
66 66
 		'secret_key' => array(
67
-			'title'       => __( 'Live Secret Key', 'woocommerce-gateway-stripe' ),
67
+			'title'       => __('Live Secret Key', 'woocommerce-gateway-stripe'),
68 68
 			'type'        => 'password',
69
-			'description' => __( 'Get your API keys from your stripe account.', 'woocommerce-gateway-stripe' ),
69
+			'description' => __('Get your API keys from your stripe account.', 'woocommerce-gateway-stripe'),
70 70
 			'default'     => '',
71 71
 			'desc_tip'    => true,
72 72
 		),
73 73
 		'inline_cc_form' => array(
74
-			'title'       => __( 'Inline Credit Card Form', 'woocommerce-gateway-stripe' ),
74
+			'title'       => __('Inline Credit Card Form', 'woocommerce-gateway-stripe'),
75 75
 			'type'        => 'checkbox',
76
-			'description' => __( 'Choose the style you want to show for your credit card form. When unchecked, the credit card form will display separate credit card number field, expiry date field and cvc field.', 'woocommerce-gateway-stripe' ),
76
+			'description' => __('Choose the style you want to show for your credit card form. When unchecked, the credit card form will display separate credit card number field, expiry date field and cvc field.', 'woocommerce-gateway-stripe'),
77 77
 			'default'     => 'no',
78 78
 			'desc_tip'    => true,
79 79
 		),
80 80
 		'statement_descriptor' => array(
81
-			'title'       => __( 'Statement Descriptor', 'woocommerce-gateway-stripe' ),
81
+			'title'       => __('Statement Descriptor', 'woocommerce-gateway-stripe'),
82 82
 			'type'        => 'text',
83
-			'description' => __( 'This may be up to 22 characters. The statement description must contain at least one letter, may not include ><"\' characters, and will appear on your customer\'s statement in capital letters.', 'woocommerce-gateway-stripe' ),
83
+			'description' => __('This may be up to 22 characters. The statement description must contain at least one letter, may not include ><"\' characters, and will appear on your customer\'s statement in capital letters.', 'woocommerce-gateway-stripe'),
84 84
 			'default'     => '',
85 85
 			'desc_tip'    => true,
86 86
 		),
87 87
 		'capture' => array(
88
-			'title'       => __( 'Capture', 'woocommerce-gateway-stripe' ),
89
-			'label'       => __( 'Capture charge immediately', 'woocommerce-gateway-stripe' ),
88
+			'title'       => __('Capture', 'woocommerce-gateway-stripe'),
89
+			'label'       => __('Capture charge immediately', 'woocommerce-gateway-stripe'),
90 90
 			'type'        => 'checkbox',
91
-			'description' => __( 'Whether or not to immediately capture the charge. When unchecked, the charge issues an authorization and will need to be captured later. Uncaptured charges expire in 7 days.', 'woocommerce-gateway-stripe' ),
91
+			'description' => __('Whether or not to immediately capture the charge. When unchecked, the charge issues an authorization and will need to be captured later. Uncaptured charges expire in 7 days.', 'woocommerce-gateway-stripe'),
92 92
 			'default'     => 'yes',
93 93
 			'desc_tip'    => true,
94 94
 		),
95 95
 		'three_d_secure' => array(
96
-			'title'       => __( '3D Secure', 'woocommerce-gateway-stripe' ),
97
-			'label'       => __( 'Require 3D Secure when applicable', 'woocommerce-gateway-stripe' ),
96
+			'title'       => __('3D Secure', 'woocommerce-gateway-stripe'),
97
+			'label'       => __('Require 3D Secure when applicable', 'woocommerce-gateway-stripe'),
98 98
 			'type'        => 'checkbox',
99
-			'description' => __( 'Some payment methods have 3D Secure feature. This is an extra security layer for your store. Choose how to handle payments when 3D Secure is optional. Enabling would require customers to use 3D Secure when optional.', 'woocommerce-gateway-stripe' ),
99
+			'description' => __('Some payment methods have 3D Secure feature. This is an extra security layer for your store. Choose how to handle payments when 3D Secure is optional. Enabling would require customers to use 3D Secure when optional.', 'woocommerce-gateway-stripe'),
100 100
 			'default'     => 'no',
101 101
 			'desc_tip'    => true,
102 102
 		),
103 103
 		'stripe_checkout' => array(
104
-			'title'       => __( 'Stripe Checkout', 'woocommerce-gateway-stripe' ),
105
-			'label'       => __( 'Enable Stripe Checkout', 'woocommerce-gateway-stripe' ),
104
+			'title'       => __('Stripe Checkout', 'woocommerce-gateway-stripe'),
105
+			'label'       => __('Enable Stripe Checkout', 'woocommerce-gateway-stripe'),
106 106
 			'type'        => 'checkbox',
107
-			'description' => __( 'If enabled, this option shows a "pay" button and modal credit card form on the checkout, instead of credit card fields directly on the page.', 'woocommerce-gateway-stripe' ),
107
+			'description' => __('If enabled, this option shows a "pay" button and modal credit card form on the checkout, instead of credit card fields directly on the page.', 'woocommerce-gateway-stripe'),
108 108
 			'default'     => 'no',
109 109
 			'desc_tip'    => true,
110 110
 		),
111 111
 		'stripe_bitcoin' => array(
112
-			'title'       => __( 'Bitcoin Currency', 'woocommerce-gateway-stripe' ),
113
-			'label'       => __( 'Enable Bitcoin Currency', 'woocommerce-gateway-stripe' ),
112
+			'title'       => __('Bitcoin Currency', 'woocommerce-gateway-stripe'),
113
+			'label'       => __('Enable Bitcoin Currency', 'woocommerce-gateway-stripe'),
114 114
 			'type'        => 'checkbox',
115
-			'description' => __( 'If enabled, an option to accept bitcoin will show on the checkout modal. Note: Stripe Checkout needs to be enabled and store currency must be set to USD.', 'woocommerce-gateway-stripe' ),
115
+			'description' => __('If enabled, an option to accept bitcoin will show on the checkout modal. Note: Stripe Checkout needs to be enabled and store currency must be set to USD.', 'woocommerce-gateway-stripe'),
116 116
 			'default'     => 'no',
117 117
 			'desc_tip'    => true,
118 118
 		),
119 119
 		'stripe_checkout_image' => array(
120
-			'title'       => __( 'Stripe Checkout Image', 'woocommerce-gateway-stripe' ),
121
-			'description' => __( 'Optionally enter the URL to a 128x128px image of your brand or product. e.g. <code>https://yoursite.com/wp-content/uploads/2013/09/yourimage.jpg</code>', 'woocommerce-gateway-stripe' ),
120
+			'title'       => __('Stripe Checkout Image', 'woocommerce-gateway-stripe'),
121
+			'description' => __('Optionally enter the URL to a 128x128px image of your brand or product. e.g. <code>https://yoursite.com/wp-content/uploads/2013/09/yourimage.jpg</code>', 'woocommerce-gateway-stripe'),
122 122
 			'type'        => 'text',
123 123
 			'default'     => '',
124 124
 			'desc_tip'    => true,
125 125
 		),
126 126
 		'stripe_checkout_description' => array(
127
-			'title'       => __( 'Stripe Checkout Description', 'woocommerce-gateway-stripe' ),
127
+			'title'       => __('Stripe Checkout Description', 'woocommerce-gateway-stripe'),
128 128
 			'type'        => 'text',
129
-			'description' => __( 'Shows a description of your store on Stripe Modal Checkout.', 'woocommerce-gateway-stripe' ),
129
+			'description' => __('Shows a description of your store on Stripe Modal Checkout.', 'woocommerce-gateway-stripe'),
130 130
 			'default'     => '',
131 131
 			'desc_tip'    => true,
132 132
 		),
133 133
 		'payment_request' => array(
134
-			'title'       => __( 'Payment Request Buttons', 'woocommerce-gateway-stripe' ),
134
+			'title'       => __('Payment Request Buttons', 'woocommerce-gateway-stripe'),
135 135
 			/* translators: 1) br tag 2) opening anchor tag 3) closing anchor tag */
136
-			'label'       => sprintf( __( 'Enable Payment Request Buttons. (Apple Pay/Chrome Payment Request API) %1$sBy using Apple Pay, you agree to %2$s and %3$s\'s terms of service.', 'woocommerce-gateway-stripe' ), '<br />', '<a href="https://stripe.com/apple-pay/legal" target="_blank">Stripe</a>', '<a href="https://developer.apple.com/apple-pay/acceptable-use-guidelines-for-websites/" target="_blank">Apple</a>' ),
136
+			'label'       => sprintf(__('Enable Payment Request Buttons. (Apple Pay/Chrome Payment Request API) %1$sBy using Apple Pay, you agree to %2$s and %3$s\'s terms of service.', 'woocommerce-gateway-stripe'), '<br />', '<a href="https://stripe.com/apple-pay/legal" target="_blank">Stripe</a>', '<a href="https://developer.apple.com/apple-pay/acceptable-use-guidelines-for-websites/" target="_blank">Apple</a>'),
137 137
 			'type'        => 'checkbox',
138
-			'description' => __( 'If enabled, users will be able to pay using Apple Pay or Chrome Payment Request if supported by the browser.', 'woocommerce-gateway-stripe' ),
138
+			'description' => __('If enabled, users will be able to pay using Apple Pay or Chrome Payment Request if supported by the browser.', 'woocommerce-gateway-stripe'),
139 139
 			'default'     => 'yes',
140 140
 			'desc_tip'    => true,
141 141
 		),
142 142
 		'payment_request_button_type' => array(
143
-			'title'       => __( 'Payment Request Button Type', 'woocommerce-gateway-stripe' ),
144
-			'label'       => __( 'Button Type', 'woocommerce-gateway-stripe' ),
143
+			'title'       => __('Payment Request Button Type', 'woocommerce-gateway-stripe'),
144
+			'label'       => __('Button Type', 'woocommerce-gateway-stripe'),
145 145
 			'type'        => 'select',
146
-			'description' => __( 'Select the button type you would like to show.', 'woocommerce-gateway-stripe' ),
146
+			'description' => __('Select the button type you would like to show.', 'woocommerce-gateway-stripe'),
147 147
 			'default'     => 'buy',
148 148
 			'desc_tip'    => true,
149 149
 			'options'     => array(
150
-				'default' => __( 'Default', 'woocommerce-gateway-stripe' ),
151
-				'buy'     => __( 'Buy', 'woocommerce-gateway-stripe' ),
152
-				'donate'  => __( 'Donate', 'woocommerce-gateway-stripe' ),
150
+				'default' => __('Default', 'woocommerce-gateway-stripe'),
151
+				'buy'     => __('Buy', 'woocommerce-gateway-stripe'),
152
+				'donate'  => __('Donate', 'woocommerce-gateway-stripe'),
153 153
 			),
154 154
 		),
155 155
 		'payment_request_button_theme' => array(
156
-			'title'       => __( 'Payment Request Button Theme', 'woocommerce-gateway-stripe' ),
157
-			'label'       => __( 'Button Theme', 'woocommerce-gateway-stripe' ),
156
+			'title'       => __('Payment Request Button Theme', 'woocommerce-gateway-stripe'),
157
+			'label'       => __('Button Theme', 'woocommerce-gateway-stripe'),
158 158
 			'type'        => 'select',
159
-			'description' => __( 'Select the button theme you would like to show.', 'woocommerce-gateway-stripe' ),
159
+			'description' => __('Select the button theme you would like to show.', 'woocommerce-gateway-stripe'),
160 160
 			'default'     => 'dark',
161 161
 			'desc_tip'    => true,
162 162
 			'options'     => array(
163
-				'dark'          => __( 'Dark', 'woocommerce-gateway-stripe' ),
164
-				'light'         => __( 'Light', 'woocommerce-gateway-stripe' ),
165
-				'light-outline' => __( 'Light-Outline', 'woocommerce-gateway-stripe' ),
163
+				'dark'          => __('Dark', 'woocommerce-gateway-stripe'),
164
+				'light'         => __('Light', 'woocommerce-gateway-stripe'),
165
+				'light-outline' => __('Light-Outline', 'woocommerce-gateway-stripe'),
166 166
 			),
167 167
 		),
168 168
 		'payment_request_button_height' => array(
169
-			'title'       => __( 'Payment Request Button Height', 'woocommerce-gateway-stripe' ),
170
-			'label'       => __( 'Button Height', 'woocommerce-gateway-stripe' ),
169
+			'title'       => __('Payment Request Button Height', 'woocommerce-gateway-stripe'),
170
+			'label'       => __('Button Height', 'woocommerce-gateway-stripe'),
171 171
 			'type'        => 'text',
172
-			'description' => __( 'Enter the height you would like the button to be in pixels. Width will always be 100%.', 'woocommerce-gateway-stripe' ),
172
+			'description' => __('Enter the height you would like the button to be in pixels. Width will always be 100%.', 'woocommerce-gateway-stripe'),
173 173
 			'default'     => '44',
174 174
 			'desc_tip'    => true,
175 175
 		),
176 176
 		'saved_cards' => array(
177
-			'title'       => __( 'Saved Cards', 'woocommerce-gateway-stripe' ),
178
-			'label'       => __( 'Enable Payment via Saved Cards', 'woocommerce-gateway-stripe' ),
177
+			'title'       => __('Saved Cards', 'woocommerce-gateway-stripe'),
178
+			'label'       => __('Enable Payment via Saved Cards', 'woocommerce-gateway-stripe'),
179 179
 			'type'        => 'checkbox',
180
-			'description' => __( 'If enabled, users will be able to pay with a saved card during checkout. Card details are saved on Stripe servers, not on your store.', 'woocommerce-gateway-stripe' ),
180
+			'description' => __('If enabled, users will be able to pay with a saved card during checkout. Card details are saved on Stripe servers, not on your store.', 'woocommerce-gateway-stripe'),
181 181
 			'default'     => 'no',
182 182
 			'desc_tip'    => true,
183 183
 		),
184 184
 		'logging' => array(
185
-			'title'       => __( 'Logging', 'woocommerce-gateway-stripe' ),
186
-			'label'       => __( 'Log debug messages', 'woocommerce-gateway-stripe' ),
185
+			'title'       => __('Logging', 'woocommerce-gateway-stripe'),
186
+			'label'       => __('Log debug messages', 'woocommerce-gateway-stripe'),
187 187
 			'type'        => 'checkbox',
188
-			'description' => __( 'Save debug messages to the WooCommerce System Status log.', 'woocommerce-gateway-stripe' ),
188
+			'description' => __('Save debug messages to the WooCommerce System Status log.', 'woocommerce-gateway-stripe'),
189 189
 			'default'     => 'no',
190 190
 			'desc_tip'    => true,
191 191
 		),
Please login to merge, or discard this patch.
includes/class-wc-gateway-stripe.php 1 patch
Spacing   +179 added lines, -179 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
 
@@ -113,9 +113,9 @@  discard block
 block discarded – undo
113 113
 	public function __construct() {
114 114
 		$this->retry_interval       = 1;
115 115
 		$this->id                   = 'stripe';
116
-		$this->method_title         = __( 'Stripe', 'woocommerce-gateway-stripe' );
116
+		$this->method_title         = __('Stripe', 'woocommerce-gateway-stripe');
117 117
 		/* translators: 1) link to Stripe register page 2) link to Stripe api keys page */
118
-		$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' );
118
+		$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');
119 119
 		$this->has_fields           = true;
120 120
 		$this->supports             = array(
121 121
 			'products',
@@ -142,33 +142,33 @@  discard block
 block discarded – undo
142 142
 		$this->init_settings();
143 143
 
144 144
 		// Get setting values.
145
-		$this->title                       = $this->get_option( 'title' );
146
-		$this->description                 = $this->get_option( 'description' );
147
-		$this->enabled                     = $this->get_option( 'enabled' );
148
-		$this->testmode                    = 'yes' === $this->get_option( 'testmode' );
149
-		$this->inline_cc_form              = 'yes' === $this->get_option( 'inline_cc_form' );
150
-		$this->capture                     = 'yes' === $this->get_option( 'capture', 'yes' );
151
-		$this->statement_descriptor        = WC_Stripe_Helper::clean_statement_descriptor( $this->get_option( 'statement_descriptor' ) );
152
-		$this->three_d_secure              = 'yes' === $this->get_option( 'three_d_secure' );
153
-		$this->stripe_checkout             = 'yes' === $this->get_option( 'stripe_checkout' );
154
-		$this->stripe_checkout_image       = $this->get_option( 'stripe_checkout_image', '' );
155
-		$this->stripe_checkout_description = $this->get_option( 'stripe_checkout_description' );
156
-		$this->saved_cards                 = 'yes' === $this->get_option( 'saved_cards' );
157
-		$this->secret_key                  = $this->testmode ? $this->get_option( 'test_secret_key' ) : $this->get_option( 'secret_key' );
158
-		$this->publishable_key             = $this->testmode ? $this->get_option( 'test_publishable_key' ) : $this->get_option( 'publishable_key' );
159
-		$this->bitcoin                     = 'USD' === strtoupper( get_woocommerce_currency() ) && 'yes' === $this->get_option( 'stripe_bitcoin' );
160
-		$this->payment_request             = 'yes' === $this->get_option( 'payment_request', 'yes' );
161
-
162
-		if ( $this->stripe_checkout ) {
163
-			$this->order_button_text = __( 'Continue to payment', 'woocommerce-gateway-stripe' );
145
+		$this->title                       = $this->get_option('title');
146
+		$this->description                 = $this->get_option('description');
147
+		$this->enabled                     = $this->get_option('enabled');
148
+		$this->testmode                    = 'yes' === $this->get_option('testmode');
149
+		$this->inline_cc_form              = 'yes' === $this->get_option('inline_cc_form');
150
+		$this->capture                     = 'yes' === $this->get_option('capture', 'yes');
151
+		$this->statement_descriptor        = WC_Stripe_Helper::clean_statement_descriptor($this->get_option('statement_descriptor'));
152
+		$this->three_d_secure              = 'yes' === $this->get_option('three_d_secure');
153
+		$this->stripe_checkout             = 'yes' === $this->get_option('stripe_checkout');
154
+		$this->stripe_checkout_image       = $this->get_option('stripe_checkout_image', '');
155
+		$this->stripe_checkout_description = $this->get_option('stripe_checkout_description');
156
+		$this->saved_cards                 = 'yes' === $this->get_option('saved_cards');
157
+		$this->secret_key                  = $this->testmode ? $this->get_option('test_secret_key') : $this->get_option('secret_key');
158
+		$this->publishable_key             = $this->testmode ? $this->get_option('test_publishable_key') : $this->get_option('publishable_key');
159
+		$this->bitcoin                     = 'USD' === strtoupper(get_woocommerce_currency()) && 'yes' === $this->get_option('stripe_bitcoin');
160
+		$this->payment_request             = 'yes' === $this->get_option('payment_request', 'yes');
161
+
162
+		if ($this->stripe_checkout) {
163
+			$this->order_button_text = __('Continue to payment', 'woocommerce-gateway-stripe');
164 164
 		}
165 165
 
166
-		WC_Stripe_API::set_secret_key( $this->secret_key );
166
+		WC_Stripe_API::set_secret_key($this->secret_key);
167 167
 
168 168
 		// Hooks.
169
-		add_action( 'wp_enqueue_scripts', array( $this, 'payment_scripts' ) );
170
-		add_action( 'admin_enqueue_scripts', array( $this, 'admin_scripts' ) );
171
-		add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) );
169
+		add_action('wp_enqueue_scripts', array($this, 'payment_scripts'));
170
+		add_action('admin_enqueue_scripts', array($this, 'admin_scripts'));
171
+		add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options'));
172 172
 	}
173 173
 
174 174
 	/**
@@ -178,7 +178,7 @@  discard block
 block discarded – undo
178 178
 	 * @return bool
179 179
 	 */
180 180
 	public function are_keys_set() {
181
-		if ( empty( $this->secret_key ) || empty( $this->publishable_key ) ) {
181
+		if (empty($this->secret_key) || empty($this->publishable_key)) {
182 182
 			return false;
183 183
 		}
184 184
 
@@ -191,7 +191,7 @@  discard block
 block discarded – undo
191 191
 	 * @since 4.0.2
192 192
 	 */
193 193
 	public function is_available() {
194
-		if ( is_add_payment_method_page() && ! $this->saved_cards ) {
194
+		if (is_add_payment_method_page() && ! $this->saved_cards) {
195 195
 			return false;
196 196
 		}
197 197
 
@@ -214,24 +214,24 @@  discard block
 block discarded – undo
214 214
 		$icons_str .= $icons['amex'];
215 215
 		$icons_str .= $icons['mastercard'];
216 216
 
217
-		if ( 'USD' === get_woocommerce_currency() ) {
217
+		if ('USD' === get_woocommerce_currency()) {
218 218
 			$icons_str .= $icons['discover'];
219 219
 			$icons_str .= $icons['jcb'];
220 220
 			$icons_str .= $icons['diners'];
221 221
 		}
222 222
 
223
-		if ( $this->bitcoin && $this->stripe_checkout ) {
223
+		if ($this->bitcoin && $this->stripe_checkout) {
224 224
 			$icons_str .= $icons['bitcoin'];
225 225
 		}
226 226
 
227
-		return apply_filters( 'woocommerce_gateway_icon', $icons_str, $this->id );
227
+		return apply_filters('woocommerce_gateway_icon', $icons_str, $this->id);
228 228
 	}
229 229
 
230 230
 	/**
231 231
 	 * Initialise Gateway Settings Form Fields
232 232
 	 */
233 233
 	public function init_form_fields() {
234
-		$this->form_fields = require( dirname( __FILE__ ) . '/admin/stripe-settings.php' );
234
+		$this->form_fields = require(dirname(__FILE__) . '/admin/stripe-settings.php');
235 235
 	}
236 236
 
237 237
 	/**
@@ -239,68 +239,68 @@  discard block
 block discarded – undo
239 239
 	 */
240 240
 	public function payment_fields() {
241 241
 		$user                 = wp_get_current_user();
242
-		$display_tokenization = $this->supports( 'tokenization' ) && is_checkout() && $this->saved_cards;
242
+		$display_tokenization = $this->supports('tokenization') && is_checkout() && $this->saved_cards;
243 243
 		$total                = WC()->cart->total;
244 244
 		$user_email           = '';
245 245
 
246 246
 		// If paying from order, we need to get total from order not cart.
247
-		if ( isset( $_GET['pay_for_order'] ) && ! empty( $_GET['key'] ) ) {
248
-			$order      = wc_get_order( wc_get_order_id_by_order_key( wc_clean( $_GET['key'] ) ) );
247
+		if (isset($_GET['pay_for_order']) && ! empty($_GET['key'])) {
248
+			$order      = wc_get_order(wc_get_order_id_by_order_key(wc_clean($_GET['key'])));
249 249
 			$total      = $order->get_total();
250 250
 			$user_email = WC_Stripe_Helper::is_pre_30() ? $order->billing_email : $order->get_billing_email();
251 251
 		} else {
252
-			if ( $user->ID ) {
253
-				$user_email = get_user_meta( $user->ID, 'billing_email', true );
252
+			if ($user->ID) {
253
+				$user_email = get_user_meta($user->ID, 'billing_email', true);
254 254
 				$user_email = $user_email ? $user_email : $user->user_email;
255 255
 			}
256 256
 		}
257 257
 
258
-		if ( is_add_payment_method_page() ) {
259
-			$pay_button_text = __( 'Add Card', 'woocommerce-gateway-stripe' );
260
-			$total        = '';
258
+		if (is_add_payment_method_page()) {
259
+			$pay_button_text = __('Add Card', 'woocommerce-gateway-stripe');
260
+			$total = '';
261 261
 		} else {
262 262
 			$pay_button_text = '';
263 263
 		}
264 264
 
265 265
 		echo '<div
266 266
 			id="stripe-payment-data"
267
-			data-panel-label="' . esc_attr( $pay_button_text ) . '"
268
-			data-description="'. esc_attr( strip_tags( $this->stripe_checkout_description ) ) . '"
269
-			data-email="' . esc_attr( $user_email ) . '"
270
-			data-amount="' . esc_attr( WC_Stripe_Helper::get_stripe_amount( $total ) ) . '"
271
-			data-name="' . esc_attr( $this->statement_descriptor ) . '"
272
-			data-currency="' . esc_attr( strtolower( get_woocommerce_currency() ) ) . '"
273
-			data-image="' . esc_attr( $this->stripe_checkout_image ) . '"
274
-			data-bitcoin="' . esc_attr( ( $this->bitcoin && $this->capture ) ? 'true' : 'false' ) . '"
275
-			data-locale="' . esc_attr( apply_filters( 'wc_stripe_checkout_locale', $this->get_locale() ) ) . '"
276
-			data-three-d-secure="' . esc_attr( $this->three_d_secure ? 'true' : 'false' ) . '"
277
-			data-allow-remember-me="' . esc_attr( $this->saved_cards ? 'true' : 'false' ) . '">';
278
-
279
-		if ( $this->description ) {
280
-			if ( $this->testmode ) {
267
+			data-panel-label="' . esc_attr($pay_button_text) . '"
268
+			data-description="'. esc_attr(strip_tags($this->stripe_checkout_description)) . '"
269
+			data-email="' . esc_attr($user_email) . '"
270
+			data-amount="' . esc_attr(WC_Stripe_Helper::get_stripe_amount($total)) . '"
271
+			data-name="' . esc_attr($this->statement_descriptor) . '"
272
+			data-currency="' . esc_attr(strtolower(get_woocommerce_currency())) . '"
273
+			data-image="' . esc_attr($this->stripe_checkout_image) . '"
274
+			data-bitcoin="' . esc_attr(($this->bitcoin && $this->capture) ? 'true' : 'false') . '"
275
+			data-locale="' . esc_attr(apply_filters('wc_stripe_checkout_locale', $this->get_locale())) . '"
276
+			data-three-d-secure="' . esc_attr($this->three_d_secure ? 'true' : 'false') . '"
277
+			data-allow-remember-me="' . esc_attr($this->saved_cards ? 'true' : 'false') . '">';
278
+
279
+		if ($this->description) {
280
+			if ($this->testmode) {
281 281
 				/* translators: link to Stripe testing page */
282
-				$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' );
283
-				$this->description  = trim( $this->description );
282
+				$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');
283
+				$this->description  = trim($this->description);
284 284
 			}
285
-			echo apply_filters( 'wc_stripe_description', wpautop( wp_kses_post( $this->description ) ) );
285
+			echo apply_filters('wc_stripe_description', wpautop(wp_kses_post($this->description)));
286 286
 		}
287 287
 
288
-		if ( $display_tokenization ) {
288
+		if ($display_tokenization) {
289 289
 			$this->tokenization_script();
290 290
 			$this->saved_payment_methods();
291 291
 		}
292 292
 
293
-		if ( ! $this->stripe_checkout ) {
294
-			if ( apply_filters( 'wc_stripe_use_elements_checkout_form', true ) ) {
293
+		if ( ! $this->stripe_checkout) {
294
+			if (apply_filters('wc_stripe_use_elements_checkout_form', true)) {
295 295
 				$this->elements_form();
296 296
 			} else {
297
-				WC_Stripe_Logger::log( 'DEPRECATED! Since version 4.0. Stripe Elements is used. This legacy credit card form will be removed by version 5.0!' );
297
+				WC_Stripe_Logger::log('DEPRECATED! Since version 4.0. Stripe Elements is used. This legacy credit card form will be removed by version 5.0!');
298 298
 				$this->form();
299 299
 				echo '<div class="stripe-source-errors" role="alert"></div>';
300 300
 			}
301 301
 		}
302 302
 
303
-		if ( apply_filters( 'wc_stripe_display_save_payment_method_checkbox', $display_tokenization ) && ! is_add_payment_method_page() && ! isset( $_GET['change_payment_method'] ) ) {
303
+		if (apply_filters('wc_stripe_display_save_payment_method_checkbox', $display_tokenization) && ! is_add_payment_method_page() && ! isset($_GET['change_payment_method'])) {
304 304
 			$this->save_payment_method_checkbox();
305 305
 		}
306 306
 
@@ -315,12 +315,12 @@  discard block
 block discarded – undo
315 315
 	 */
316 316
 	public function elements_form() {
317 317
 		?>
318
-		<fieldset id="wc-<?php echo esc_attr( $this->id ); ?>-cc-form" class="wc-credit-card-form wc-payment-form" style="background:transparent;">
319
-			<?php do_action( 'woocommerce_credit_card_form_start', $this->id ); ?>
318
+		<fieldset id="wc-<?php echo esc_attr($this->id); ?>-cc-form" class="wc-credit-card-form wc-payment-form" style="background:transparent;">
319
+			<?php do_action('woocommerce_credit_card_form_start', $this->id); ?>
320 320
 
321
-			<?php if ( $this->inline_cc_form ) { ?>
321
+			<?php if ($this->inline_cc_form) { ?>
322 322
 				<label for="card-element">
323
-					<?php esc_html_e( 'Credit or debit card', 'woocommerce-gateway-stripe' ); ?>
323
+					<?php esc_html_e('Credit or debit card', 'woocommerce-gateway-stripe'); ?>
324 324
 				</label>
325 325
 
326 326
 				<div id="stripe-card-element" style="background:#fff;padding:0 1em;border:1px solid #ddd;margin:5px 0;padding:10px 5px;">
@@ -328,7 +328,7 @@  discard block
 block discarded – undo
328 328
 				</div>
329 329
 			<?php } else { ?>
330 330
 				<div class="form-row form-row-wide">
331
-					<label><?php _e( 'Card Number', 'woocommerce-gateway-stripe' ); ?> <span class="required">*</span></label>
331
+					<label><?php _e('Card Number', 'woocommerce-gateway-stripe'); ?> <span class="required">*</span></label>
332 332
 
333 333
 					<div id="stripe-card-element" style="background:#fff;padding:0 1em;border:1px solid #ddd;margin:5px 0;padding:10px 5px;">
334 334
 					<!-- a Stripe Element will be inserted here. -->
@@ -336,7 +336,7 @@  discard block
 block discarded – undo
336 336
 				</div>
337 337
 
338 338
 				<div class="form-row form-row-first">
339
-					<label><?php _e( 'Expiry Date', 'woocommerce-gateway-stripe' ); ?> <span class="required">*</span></label>
339
+					<label><?php _e('Expiry Date', 'woocommerce-gateway-stripe'); ?> <span class="required">*</span></label>
340 340
 
341 341
 					<div id="stripe-exp-element" style="background:#fff;padding:0 1em;border:1px solid #ddd;margin:5px 0;padding:10px 5px;">
342 342
 					<!-- a Stripe Element will be inserted here. -->
@@ -344,7 +344,7 @@  discard block
 block discarded – undo
344 344
 				</div>
345 345
 
346 346
 				<div class="form-row form-row-last">
347
-					<label><?php _e( 'Card Code (CVC)', 'woocommerce-gateway-stripe' ); ?> <span class="required">*</span></label>
347
+					<label><?php _e('Card Code (CVC)', 'woocommerce-gateway-stripe'); ?> <span class="required">*</span></label>
348 348
 				<div id="stripe-cvc-element" style="background:#fff;padding:0 1em;border:1px solid #ddd;margin:5px 0;padding:10px 5px;">
349 349
 				<!-- a Stripe Element will be inserted here. -->
350 350
 				</div>
@@ -354,7 +354,7 @@  discard block
 block discarded – undo
354 354
 
355 355
 			<!-- Used to display form errors -->
356 356
 			<div class="stripe-source-errors" role="alert"></div>
357
-			<?php do_action( 'woocommerce_credit_card_form_end', $this->id ); ?>
357
+			<?php do_action('woocommerce_credit_card_form_end', $this->id); ?>
358 358
 			<div class="clear"></div>
359 359
 		</fieldset>
360 360
 		<?php
@@ -367,13 +367,13 @@  discard block
 block discarded – undo
367 367
 	 * @version 3.1.0
368 368
 	 */
369 369
 	public function admin_scripts() {
370
-		if ( 'woocommerce_page_wc-settings' !== get_current_screen()->id ) {
370
+		if ('woocommerce_page_wc-settings' !== get_current_screen()->id) {
371 371
 			return;
372 372
 		}
373 373
 
374
-		$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
374
+		$suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';
375 375
 
376
-		wp_enqueue_script( 'woocommerce_stripe_admin', plugins_url( 'assets/js/stripe-admin' . $suffix . '.js', WC_STRIPE_MAIN_FILE ), array(), WC_STRIPE_VERSION, true );
376
+		wp_enqueue_script('woocommerce_stripe_admin', plugins_url('assets/js/stripe-admin' . $suffix . '.js', WC_STRIPE_MAIN_FILE), array(), WC_STRIPE_VERSION, true);
377 377
 	}
378 378
 
379 379
 	/**
@@ -385,46 +385,46 @@  discard block
 block discarded – undo
385 385
 	 * @version 4.0.0
386 386
 	 */
387 387
 	public function payment_scripts() {
388
-		if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) && ! is_add_payment_method_page() && ! isset( $_GET['change_payment_method'] ) ) {
388
+		if ( ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order']) && ! is_add_payment_method_page() && ! isset($_GET['change_payment_method'])) {
389 389
 			return;
390 390
 		}
391 391
 
392 392
 		// If Stripe is not enabled bail.
393
-		if ( 'no' === $this->enabled ) {
393
+		if ('no' === $this->enabled) {
394 394
 			return;
395 395
 		}
396 396
 
397 397
 		// If keys are not set bail.
398
-		if ( ! $this->are_keys_set() ) {
399
-			WC_Stripe_Logger::log( 'Keys are not set correctly.' );
398
+		if ( ! $this->are_keys_set()) {
399
+			WC_Stripe_Logger::log('Keys are not set correctly.');
400 400
 			return;
401 401
 		}
402 402
 
403 403
 		// If no SSL bail.
404
-		if ( ! $this->testmode && ! is_ssl() ) {
405
-			WC_Stripe_Logger::log( 'Stripe requires SSL.' );
404
+		if ( ! $this->testmode && ! is_ssl()) {
405
+			WC_Stripe_Logger::log('Stripe requires SSL.');
406 406
 			return;
407 407
 		}
408 408
 
409
-		$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
409
+		$suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';
410 410
 
411
-		wp_register_style( 'stripe_paymentfonts', plugins_url( 'assets/css/stripe-paymentfonts.css', WC_STRIPE_MAIN_FILE ), array(), '1.2.5' );
412
-		wp_enqueue_style( 'stripe_paymentfonts' );
413
-		wp_register_script( 'stripe_checkout', 'https://checkout.stripe.com/checkout.js', '', WC_STRIPE_VERSION, true );
414
-		wp_register_script( 'stripev2', 'https://js.stripe.com/v2/', '', '2.0', true );
415
-		wp_register_script( 'stripe', 'https://js.stripe.com/v3/', '', '3.0', true );
416
-		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 );
411
+		wp_register_style('stripe_paymentfonts', plugins_url('assets/css/stripe-paymentfonts.css', WC_STRIPE_MAIN_FILE), array(), '1.2.5');
412
+		wp_enqueue_style('stripe_paymentfonts');
413
+		wp_register_script('stripe_checkout', 'https://checkout.stripe.com/checkout.js', '', WC_STRIPE_VERSION, true);
414
+		wp_register_script('stripev2', 'https://js.stripe.com/v2/', '', '2.0', true);
415
+		wp_register_script('stripe', 'https://js.stripe.com/v3/', '', '3.0', true);
416
+		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);
417 417
 
418 418
 		$stripe_params = array(
419 419
 			'key'                  => $this->publishable_key,
420
-			'i18n_terms'           => __( 'Please accept the terms and conditions first', 'woocommerce-gateway-stripe' ),
421
-			'i18n_required_fields' => __( 'Please fill in required checkout fields first', 'woocommerce-gateway-stripe' ),
420
+			'i18n_terms'           => __('Please accept the terms and conditions first', 'woocommerce-gateway-stripe'),
421
+			'i18n_required_fields' => __('Please fill in required checkout fields first', 'woocommerce-gateway-stripe'),
422 422
 		);
423 423
 
424 424
 		// If we're on the pay page we need to pass stripe.js the address of the order.
425
-		if ( isset( $_GET['pay_for_order'] ) && 'true' === $_GET['pay_for_order'] ) {
426
-			$order_id = wc_get_order_id_by_order_key( urldecode( $_GET['key'] ) );
427
-			$order    = wc_get_order( $order_id );
425
+		if (isset($_GET['pay_for_order']) && 'true' === $_GET['pay_for_order']) {
426
+			$order_id = wc_get_order_id_by_order_key(urldecode($_GET['key']));
427
+			$order    = wc_get_order($order_id);
428 428
 
429 429
 			$stripe_params['billing_first_name'] = WC_Stripe_Helper::is_pre_30() ? $order->billing_first_name : $order->get_billing_first_name();
430 430
 			$stripe_params['billing_last_name']  = WC_Stripe_Helper::is_pre_30() ? $order->billing_last_name : $order->get_billing_last_name();
@@ -436,39 +436,39 @@  discard block
 block discarded – undo
436 436
 			$stripe_params['billing_country']    = WC_Stripe_Helper::is_pre_30() ? $order->billing_country : $order->get_billing_country();
437 437
 		}
438 438
 
439
-		$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' );
440
-		$stripe_params['no_sepa_owner_msg']                       = __( 'Please enter your IBAN account name.', 'woocommerce-gateway-stripe' );
441
-		$stripe_params['no_sepa_iban_msg']                        = __( 'Please enter your IBAN account number.', 'woocommerce-gateway-stripe' );
442
-		$stripe_params['sepa_mandate_notification']               = apply_filters( 'wc_stripe_sepa_mandate_notification', 'email' );
443
-		$stripe_params['allow_prepaid_card']                      = apply_filters( 'wc_stripe_allow_prepaid_card', true ) ? 'yes' : 'no';
439
+		$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');
440
+		$stripe_params['no_sepa_owner_msg']                       = __('Please enter your IBAN account name.', 'woocommerce-gateway-stripe');
441
+		$stripe_params['no_sepa_iban_msg']                        = __('Please enter your IBAN account number.', 'woocommerce-gateway-stripe');
442
+		$stripe_params['sepa_mandate_notification']               = apply_filters('wc_stripe_sepa_mandate_notification', 'email');
443
+		$stripe_params['allow_prepaid_card']                      = apply_filters('wc_stripe_allow_prepaid_card', true) ? 'yes' : 'no';
444 444
 		$stripe_params['inline_cc_form']                          = $this->inline_cc_form ? 'yes' : 'no';
445
-		$stripe_params['stripe_checkout_require_billing_address'] = apply_filters( 'wc_stripe_checkout_require_billing_address', false ) ? 'yes' : 'no';
446
-		$stripe_params['is_checkout']                             = ( is_checkout() && empty( $_GET['pay_for_order'] ) ) ? 'yes' : 'no';
445
+		$stripe_params['stripe_checkout_require_billing_address'] = apply_filters('wc_stripe_checkout_require_billing_address', false) ? 'yes' : 'no';
446
+		$stripe_params['is_checkout']                             = (is_checkout() && empty($_GET['pay_for_order'])) ? 'yes' : 'no';
447 447
 		$stripe_params['return_url']                              = $this->get_stripe_return_url();
448
-		$stripe_params['ajaxurl']                                 = WC_AJAX::get_endpoint( '%%endpoint%%' );
449
-		$stripe_params['stripe_nonce']                            = wp_create_nonce( '_wc_stripe_nonce' );
448
+		$stripe_params['ajaxurl']                                 = WC_AJAX::get_endpoint('%%endpoint%%');
449
+		$stripe_params['stripe_nonce']                            = wp_create_nonce('_wc_stripe_nonce');
450 450
 		$stripe_params['statement_descriptor']                    = $this->statement_descriptor;
451
-		$stripe_params['use_elements']                            = apply_filters( 'wc_stripe_use_elements_checkout_form', true ) ? 'yes' : 'no';
452
-		$stripe_params['elements_options']                        = apply_filters( 'wc_stripe_elements_options', array() );
451
+		$stripe_params['use_elements']                            = apply_filters('wc_stripe_use_elements_checkout_form', true) ? 'yes' : 'no';
452
+		$stripe_params['elements_options']                        = apply_filters('wc_stripe_elements_options', array());
453 453
 		$stripe_params['is_stripe_checkout']                      = $this->stripe_checkout ? 'yes' : 'no';
454
-		$stripe_params['is_change_payment_page']                  = isset( $_GET['change_payment_method'] ) ? 'yes' : 'no';
455
-		$stripe_params['is_pay_for_order_page']                   = isset( $_GET['pay_for_order'] ) ? 'yes' : 'no';
456
-		$stripe_params['validate_modal_checkout']                 = apply_filters( 'wc_stripe_validate_modal_checkout', false ) ? 'yes' : 'no';
457
-		$stripe_params['elements_styling']                        = apply_filters( 'wc_stripe_elements_styling', false );
458
-		$stripe_params['elements_classes']                        = apply_filters( 'wc_stripe_elements_classes', false );
454
+		$stripe_params['is_change_payment_page']                  = isset($_GET['change_payment_method']) ? 'yes' : 'no';
455
+		$stripe_params['is_pay_for_order_page']                   = isset($_GET['pay_for_order']) ? 'yes' : 'no';
456
+		$stripe_params['validate_modal_checkout']                 = apply_filters('wc_stripe_validate_modal_checkout', false) ? 'yes' : 'no';
457
+		$stripe_params['elements_styling']                        = apply_filters('wc_stripe_elements_styling', false);
458
+		$stripe_params['elements_classes']                        = apply_filters('wc_stripe_elements_classes', false);
459 459
 
460 460
 		// merge localized messages to be use in JS
461
-		$stripe_params = array_merge( $stripe_params, WC_Stripe_Helper::get_localized_messages() );
461
+		$stripe_params = array_merge($stripe_params, WC_Stripe_Helper::get_localized_messages());
462 462
 
463
-		wp_localize_script( 'woocommerce_stripe', 'wc_stripe_params', apply_filters( 'wc_stripe_params', $stripe_params ) );
464
-		wp_localize_script( 'woocommerce_stripe_checkout', 'wc_stripe_params', apply_filters( 'wc_stripe_params', $stripe_params ) );
463
+		wp_localize_script('woocommerce_stripe', 'wc_stripe_params', apply_filters('wc_stripe_params', $stripe_params));
464
+		wp_localize_script('woocommerce_stripe_checkout', 'wc_stripe_params', apply_filters('wc_stripe_params', $stripe_params));
465 465
 
466
-		if ( $this->stripe_checkout ) {
467
-			wp_enqueue_script( 'stripe_checkout' );
466
+		if ($this->stripe_checkout) {
467
+			wp_enqueue_script('stripe_checkout');
468 468
 		}
469 469
 
470 470
 		$this->tokenization_script();
471
-		wp_enqueue_script( 'woocommerce_stripe' );
471
+		wp_enqueue_script('woocommerce_stripe');
472 472
 	}
473 473
 
474 474
 	/**
@@ -484,41 +484,41 @@  discard block
 block discarded – undo
484 484
 	 *
485 485
 	 * @return array|void
486 486
 	 */
487
-	public function process_payment( $order_id, $retry = true, $force_save_source = false ) {
487
+	public function process_payment($order_id, $retry = true, $force_save_source = false) {
488 488
 		try {
489
-			$order = wc_get_order( $order_id );
489
+			$order = wc_get_order($order_id);
490 490
 
491 491
 			// This comes from the create account checkbox in the checkout page.
492
-			$create_account = ! empty( $_POST['createaccount'] ) ? true : false;
492
+			$create_account = ! empty($_POST['createaccount']) ? true : false;
493 493
 
494
-			if ( $create_account ) {
494
+			if ($create_account) {
495 495
 				$new_customer_id     = WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id();
496
-				$new_stripe_customer = new WC_Stripe_Customer( $new_customer_id );
496
+				$new_stripe_customer = new WC_Stripe_Customer($new_customer_id);
497 497
 				$new_stripe_customer->create_customer();
498 498
 			}
499 499
 
500
-			$prepared_source = $this->prepare_source( get_current_user_id(), $force_save_source );
500
+			$prepared_source = $this->prepare_source(get_current_user_id(), $force_save_source);
501 501
 			$source_object   = $prepared_source->source_object;
502 502
 
503 503
 			// Check if we don't allow prepaid credit cards.
504
-			if ( ! apply_filters( 'wc_stripe_allow_prepaid_card', true ) && $this->is_prepaid_card( $source_object ) ) {
505
-				$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' );
506
-				throw new WC_Stripe_Exception( print_r( $source_object, true ), $localized_message );
504
+			if ( ! apply_filters('wc_stripe_allow_prepaid_card', true) && $this->is_prepaid_card($source_object)) {
505
+				$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');
506
+				throw new WC_Stripe_Exception(print_r($source_object, true), $localized_message);
507 507
 			}
508 508
 
509
-			if ( empty( $prepared_source->source ) ) {
510
-				$localized_message = __( 'Payment processing failed. Please retry.', 'woocommerce-gateway-stripe' );
511
-				throw new WC_Stripe_Exception( print_r( $prepared_source, true ), $localized_message );
509
+			if (empty($prepared_source->source)) {
510
+				$localized_message = __('Payment processing failed. Please retry.', 'woocommerce-gateway-stripe');
511
+				throw new WC_Stripe_Exception(print_r($prepared_source, true), $localized_message);
512 512
 			}
513 513
 
514
-			$this->save_source_to_order( $order, $prepared_source );
514
+			$this->save_source_to_order($order, $prepared_source);
515 515
 
516 516
 			// Result from Stripe API request.
517 517
 			$response = null;
518 518
 
519
-			if ( $order->get_total() > 0 ) {
519
+			if ($order->get_total() > 0) {
520 520
 				// This will throw exception if not valid.
521
-				$this->validate_minimum_order_amount( $order );
521
+				$this->validate_minimum_order_amount($order);
522 522
 
523 523
 				/*
524 524
 				 * Check if card 3DS is required or optional with 3DS setting.
@@ -527,105 +527,105 @@  discard block
 block discarded – undo
527 527
 				 * Note that if we need to save source, the original source must be first
528 528
 				 * attached to a customer in Stripe before it can be charged.
529 529
 				 */
530
-				if ( $this->is_3ds_required( $source_object ) ) {
531
-					$response = $this->create_3ds_source( $order, $source_object );
530
+				if ($this->is_3ds_required($source_object)) {
531
+					$response = $this->create_3ds_source($order, $source_object);
532 532
 
533
-					if ( ! empty( $response->error ) ) {
533
+					if ( ! empty($response->error)) {
534 534
 						$localized_message = $response->error->message;
535 535
 
536
-						$order->add_order_note( $localized_message );
536
+						$order->add_order_note($localized_message);
537 537
 
538
-						throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message );
538
+						throw new WC_Stripe_Exception(print_r($response, true), $localized_message);
539 539
 					}
540 540
 
541 541
 					// Update order meta with 3DS source.
542
-					if ( WC_Stripe_Helper::is_pre_30() ) {
543
-						update_post_meta( $order_id, '_stripe_source_id', $response->id );
542
+					if (WC_Stripe_Helper::is_pre_30()) {
543
+						update_post_meta($order_id, '_stripe_source_id', $response->id);
544 544
 					} else {
545
-						$order->update_meta_data( '_stripe_source_id', $response->id );
545
+						$order->update_meta_data('_stripe_source_id', $response->id);
546 546
 						$order->save();
547 547
 					}
548 548
 
549
-					WC_Stripe_Logger::log( 'Info: Redirecting to 3DS...' );
549
+					WC_Stripe_Logger::log('Info: Redirecting to 3DS...');
550 550
 
551 551
 					return array(
552 552
 						'result'   => 'success',
553
-						'redirect' => esc_url_raw( $response->redirect->url ),
553
+						'redirect' => esc_url_raw($response->redirect->url),
554 554
 					);
555 555
 				}
556 556
 
557
-				WC_Stripe_Logger::log( "Info: Begin processing payment for order $order_id for the amount of {$order->get_total()}" );
557
+				WC_Stripe_Logger::log("Info: Begin processing payment for order $order_id for the amount of {$order->get_total()}");
558 558
 
559 559
 				/* If we're doing a retry and source is chargeable, we need to pass
560 560
 				 * a different idempotency key and retry for success.
561 561
 				 */
562
-				if ( 1 < $this->retry_interval && ! empty( $source_object ) && 'chargeable' === $source_object->status ) {
563
-					add_filter( 'wc_stripe_idempotency_key', array( $this, 'change_idempotency_key' ), 10, 2 );
562
+				if (1 < $this->retry_interval && ! empty($source_object) && 'chargeable' === $source_object->status) {
563
+					add_filter('wc_stripe_idempotency_key', array($this, 'change_idempotency_key'), 10, 2);
564 564
 				}
565 565
 
566 566
 				// Make the request.
567
-				$response = WC_Stripe_API::request( $this->generate_payment_request( $order, $prepared_source ) );
567
+				$response = WC_Stripe_API::request($this->generate_payment_request($order, $prepared_source));
568 568
 
569
-				if ( ! empty( $response->error ) ) {
569
+				if ( ! empty($response->error)) {
570 570
 					// Customer param wrong? The user may have been deleted on stripe's end. Remove customer_id. Can be retried without.
571
-					if ( preg_match( '/No such customer/i', $response->error->message ) && $retry ) {
572
-						if ( WC_Stripe_Helper::is_pre_30() ) {
573
-							delete_user_meta( $order->customer_user, '_stripe_customer_id' );
574
-							delete_post_meta( $order_id, '_stripe_customer_id' );
571
+					if (preg_match('/No such customer/i', $response->error->message) && $retry) {
572
+						if (WC_Stripe_Helper::is_pre_30()) {
573
+							delete_user_meta($order->customer_user, '_stripe_customer_id');
574
+							delete_post_meta($order_id, '_stripe_customer_id');
575 575
 						} else {
576
-							delete_user_meta( $order->get_customer_id(), '_stripe_customer_id' );
577
-							$order->delete_meta_data( '_stripe_customer_id' );
576
+							delete_user_meta($order->get_customer_id(), '_stripe_customer_id');
577
+							$order->delete_meta_data('_stripe_customer_id');
578 578
 							$order->save();
579 579
 						}
580 580
 
581
-						return $this->process_payment( $order_id, false, $force_save_source );
582
-					} elseif ( preg_match( '/No such token/i', $response->error->message ) && $prepared_source->token_id ) {
581
+						return $this->process_payment($order_id, false, $force_save_source);
582
+					} elseif (preg_match('/No such token/i', $response->error->message) && $prepared_source->token_id) {
583 583
 						// Source param wrong? The CARD may have been deleted on stripe's end. Remove token and show message.
584
-						$wc_token = WC_Payment_Tokens::get( $prepared_source->token_id );
584
+						$wc_token = WC_Payment_Tokens::get($prepared_source->token_id);
585 585
 						$wc_token->delete();
586
-						$localized_message = __( 'This card is no longer available and has been removed.', 'woocommerce-gateway-stripe' );
587
-						$order->add_order_note( $localized_message );
588
-						throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message );
586
+						$localized_message = __('This card is no longer available and has been removed.', 'woocommerce-gateway-stripe');
587
+						$order->add_order_note($localized_message);
588
+						throw new WC_Stripe_Exception(print_r($response, true), $localized_message);
589 589
 					}
590 590
 
591 591
 					// We want to retry.
592
-					if ( $this->is_retryable_error( $response->error ) ) {
593
-						if ( $retry ) {
592
+					if ($this->is_retryable_error($response->error)) {
593
+						if ($retry) {
594 594
 							// Don't do anymore retries after this.
595
-							if ( 5 <= $this->retry_interval ) {
595
+							if (5 <= $this->retry_interval) {
596 596
 
597
-								return $this->process_payment( $order_id, false, $force_save_source );
597
+								return $this->process_payment($order_id, false, $force_save_source);
598 598
 							}
599 599
 
600
-							sleep( $this->retry_interval );
600
+							sleep($this->retry_interval);
601 601
 
602 602
 							$this->retry_interval++;
603 603
 
604
-							return $this->process_payment( $order_id, true, $force_save_source );
604
+							return $this->process_payment($order_id, true, $force_save_source);
605 605
 						} else {
606
-							$localized_message = __( 'On going requests error and retries exhausted.', 'woocommerce-gateway-stripe' );
607
-							$order->add_order_note( $localized_message );
608
-							throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message );
606
+							$localized_message = __('On going requests error and retries exhausted.', 'woocommerce-gateway-stripe');
607
+							$order->add_order_note($localized_message);
608
+							throw new WC_Stripe_Exception(print_r($response, true), $localized_message);
609 609
 						}
610 610
 					}
611 611
 
612 612
 					$localized_messages = WC_Stripe_Helper::get_localized_messages();
613 613
 
614
-					if ( 'card_error' === $response->error->type ) {
615
-						$localized_message = isset( $localized_messages[ $response->error->code ] ) ? $localized_messages[ $response->error->code ] : $response->error->message;
614
+					if ('card_error' === $response->error->type) {
615
+						$localized_message = isset($localized_messages[$response->error->code]) ? $localized_messages[$response->error->code] : $response->error->message;
616 616
 					} else {
617
-						$localized_message = isset( $localized_messages[ $response->error->type ] ) ? $localized_messages[ $response->error->type ] : $response->error->message;
617
+						$localized_message = isset($localized_messages[$response->error->type]) ? $localized_messages[$response->error->type] : $response->error->message;
618 618
 					}
619 619
 
620
-					$order->add_order_note( $localized_message );
620
+					$order->add_order_note($localized_message);
621 621
 
622
-					throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message );
622
+					throw new WC_Stripe_Exception(print_r($response, true), $localized_message);
623 623
 				}
624 624
 
625
-				do_action( 'wc_gateway_stripe_process_payment', $response, $order );
625
+				do_action('wc_gateway_stripe_process_payment', $response, $order);
626 626
 
627 627
 				// Process valid response.
628
-				$this->process_response( $response, $order );
628
+				$this->process_response($response, $order);
629 629
 			} else {
630 630
 				$order->payment_complete();
631 631
 			}
@@ -636,20 +636,20 @@  discard block
 block discarded – undo
636 636
 			// Return thank you page redirect.
637 637
 			return array(
638 638
 				'result'   => 'success',
639
-				'redirect' => $this->get_return_url( $order ),
639
+				'redirect' => $this->get_return_url($order),
640 640
 			);
641 641
 
642
-		} catch ( WC_Stripe_Exception $e ) {
643
-			wc_add_notice( $e->getLocalizedMessage(), 'error' );
644
-			WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() );
642
+		} catch (WC_Stripe_Exception $e) {
643
+			wc_add_notice($e->getLocalizedMessage(), 'error');
644
+			WC_Stripe_Logger::log('Error: ' . $e->getMessage());
645 645
 
646
-			do_action( 'wc_gateway_stripe_process_payment_error', $e, $order );
646
+			do_action('wc_gateway_stripe_process_payment_error', $e, $order);
647 647
 
648 648
 			/* translators: error message */
649
-			$order->update_status( 'failed' );
649
+			$order->update_status('failed');
650 650
 
651
-			if ( $order->has_status( array( 'pending', 'failed' ) ) ) {
652
-				$this->send_failed_order_email( $order_id );
651
+			if ($order->has_status(array('pending', 'failed'))) {
652
+				$this->send_failed_order_email($order_id);
653 653
 			}
654 654
 
655 655
 			return array(
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.7' );
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.7');
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.
includes/abstracts/abstract-wc-stripe-payment-gateway.php 1 patch
Spacing   +220 added lines, -221 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 ||
@@ -35,11 +35,11 @@  discard block
 block discarded – undo
35 35
 	 * Check if this gateway is enabled
36 36
 	 */
37 37
 	public function is_available() {
38
-		if ( 'yes' === $this->enabled ) {
39
-			if ( ! $this->testmode && is_checkout() && ! is_ssl() ) {
38
+		if ('yes' === $this->enabled) {
39
+			if ( ! $this->testmode && is_checkout() && ! is_ssl()) {
40 40
 				return false;
41 41
 			}
42
-			if ( ! $this->secret_key || ! $this->publishable_key ) {
42
+			if ( ! $this->secret_key || ! $this->publishable_key) {
43 43
 				return false;
44 44
 			}
45 45
 			return true;
@@ -54,8 +54,8 @@  discard block
 block discarded – undo
54 54
 	 * @since 4.0.0
55 55
 	 * @version 4.0.0
56 56
 	 */
57
-	public function add_admin_notice( $slug, $class, $message ) {
58
-		$this->notices[ $slug ] = array(
57
+	public function add_admin_notice($slug, $class, $message) {
58
+		$this->notices[$slug] = array(
59 59
 			'class'   => $class,
60 60
 			'message' => $message,
61 61
 		);
@@ -68,8 +68,8 @@  discard block
 block discarded – undo
68 68
 	 * @version 4.0.0
69 69
 	 */
70 70
 	public function remove_admin_notice() {
71
-		if ( did_action( 'woocommerce_update_options' ) ) {
72
-			remove_action( 'admin_notices', array( $this, 'check_environment' ) );
71
+		if (did_action('woocommerce_update_options')) {
72
+			remove_action('admin_notices', array($this, 'check_environment'));
73 73
 		}
74 74
 	}
75 75
 
@@ -81,7 +81,7 @@  discard block
 block discarded – undo
81 81
 	 * @return array
82 82
 	 */
83 83
 	public function payment_icons() {
84
-		return apply_filters( 'wc_stripe_payment_icons', array(
84
+		return apply_filters('wc_stripe_payment_icons', array(
85 85
 			'visa'       => '<i class="stripe-pf stripe-pf-visa stripe-pf-right" alt="Visa" aria-hidden="true"></i>',
86 86
 			'amex'       => '<i class="stripe-pf stripe-pf-american-express stripe-pf-right" alt="Amex" aria-hidden="true"></i>',
87 87
 			'mastercard' => '<i class="stripe-pf stripe-pf-mastercard stripe-pf-right" alt="Mastercard" aria-hidden="true"></i>',
@@ -98,7 +98,7 @@  discard block
 block discarded – undo
98 98
 			'eps'        => '<i class="stripe-pf stripe-pf-eps stripe-pf-right" alt="EPS" aria-hidden="true"></i>',
99 99
 			'sofort'     => '<i class="stripe-pf stripe-pf-sofort stripe-pf-right" alt="SOFORT" aria-hidden="true"></i>',
100 100
 			'sepa'       => '<i class="stripe-pf stripe-pf-sepa stripe-pf-right" alt="SEPA" aria-hidden="true"></i>',
101
-		) );
101
+		));
102 102
 	}
103 103
 
104 104
 	/**
@@ -109,10 +109,10 @@  discard block
 block discarded – undo
109 109
 	 * @version 4.0.0
110 110
 	 * @param object $order
111 111
 	 */
112
-	public function validate_minimum_order_amount( $order ) {
113
-		if ( $order->get_total() * 100 < WC_Stripe_Helper::get_minimum_amount() ) {
112
+	public function validate_minimum_order_amount($order) {
113
+		if ($order->get_total() * 100 < WC_Stripe_Helper::get_minimum_amount()) {
114 114
 			/* translators: 1) dollar amount */
115
-			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 ) ) );
115
+			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)));
116 116
 		}
117 117
 	}
118 118
 
@@ -122,14 +122,14 @@  discard block
 block discarded – undo
122 122
 	 * @since 4.0.0
123 123
 	 * @version 4.0.0
124 124
 	 */
125
-	public function get_transaction_url( $order ) {
126
-		if ( $this->testmode ) {
125
+	public function get_transaction_url($order) {
126
+		if ($this->testmode) {
127 127
 			$this->view_transaction_url = 'https://dashboard.stripe.com/test/payments/%s';
128 128
 		} else {
129 129
 			$this->view_transaction_url = 'https://dashboard.stripe.com/payments/%s';
130 130
 		}
131 131
 
132
-		return parent::get_transaction_url( $order );
132
+		return parent::get_transaction_url($order);
133 133
 	}
134 134
 
135 135
 	/**
@@ -138,15 +138,15 @@  discard block
 block discarded – undo
138 138
 	 * @since 4.0.0
139 139
 	 * @version 4.0.0
140 140
 	 */
141
-	public function get_stripe_customer_id( $order ) {
142
-		$customer = get_user_meta( WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id(), '_stripe_customer_id', true );
141
+	public function get_stripe_customer_id($order) {
142
+		$customer = get_user_meta(WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id(), '_stripe_customer_id', true);
143 143
 
144
-		if ( empty( $customer ) ) {
144
+		if (empty($customer)) {
145 145
 			// Try to get it via the order.
146
-			if ( WC_Stripe_Helper::is_pre_30() ) {
147
-				return get_post_meta( $order->id, '_stripe_customer_id', true );
146
+			if (WC_Stripe_Helper::is_pre_30()) {
147
+				return get_post_meta($order->id, '_stripe_customer_id', true);
148 148
 			} else {
149
-				return $order->get_meta( '_stripe_customer_id', true );
149
+				return $order->get_meta('_stripe_customer_id', true);
150 150
 			}
151 151
 		} else {
152 152
 			return $customer;
@@ -163,9 +163,9 @@  discard block
 block discarded – undo
163 163
 	 * @param object $order
164 164
 	 * @param int $id Stripe session id.
165 165
 	 */
166
-	public function get_stripe_return_url( $order = null, $id = null ) {
167
-		if ( is_object( $order ) ) {
168
-			if ( empty( $id ) ) {
166
+	public function get_stripe_return_url($order = null, $id = null) {
167
+		if (is_object($order)) {
168
+			if (empty($id)) {
169 169
 				$id = uniqid();
170 170
 			}
171 171
 
@@ -176,10 +176,10 @@  discard block
 block discarded – undo
176 176
 				'order_id'       => $order_id,
177 177
 			);
178 178
 
179
-			return esc_url_raw( add_query_arg( $args, $this->get_return_url( $order ) ) );
179
+			return esc_url_raw(add_query_arg($args, $this->get_return_url($order)));
180 180
 		}
181 181
 
182
-		return esc_url_raw( add_query_arg( array( 'utm_nooverride' => '1' ), $this->get_return_url() ) );
182
+		return esc_url_raw(add_query_arg(array('utm_nooverride' => '1'), $this->get_return_url()));
183 183
 	}
184 184
 
185 185
 	/**
@@ -187,8 +187,8 @@  discard block
 block discarded – undo
187 187
 	 * @param  int  $order_id
188 188
 	 * @return boolean
189 189
 	 */
190
-	public function has_subscription( $order_id ) {
191
-		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
+	public function has_subscription($order_id) {
191
+		return (function_exists('wcs_order_contains_subscription') && (wcs_order_contains_subscription($order_id) || wcs_is_subscription($order_id) || wcs_order_contains_renewal($order_id)));
192 192
 	}
193 193
 
194 194
 	/**
@@ -200,34 +200,33 @@  discard block
 block discarded – undo
200 200
 	 * @param  object $prepared_source
201 201
 	 * @return array()
202 202
 	 */
203
-	public function generate_payment_request( $order, $prepared_source ) {
204
-		$settings                          = get_option( 'woocommerce_stripe_settings', array() );
205
-		$statement_descriptor              = ! empty( $settings['statement_descriptor'] ) ? str_replace( "'", '', $settings['statement_descriptor'] ) : '';
206
-		$capture                           = ! empty( $settings['capture'] ) && 'yes' === $settings['capture'] ? true : false;
203
+	public function generate_payment_request($order, $prepared_source) {
204
+		$settings                          = get_option('woocommerce_stripe_settings', array());
205
+		$statement_descriptor              = ! empty($settings['statement_descriptor']) ? str_replace("'", '', $settings['statement_descriptor']) : '';
206
+		$capture                           = ! empty($settings['capture']) && 'yes' === $settings['capture'] ? true : false;
207 207
 		$post_data                         = array();
208
-		$post_data['currency']             = strtolower( WC_Stripe_Helper::is_pre_30() ? $order->get_order_currency() : $order->get_currency() );
209
-		$post_data['amount']               = WC_Stripe_Helper::get_stripe_amount( $order->get_total(), $post_data['currency'] );
208
+		$post_data['currency']             = strtolower(WC_Stripe_Helper::is_pre_30() ? $order->get_order_currency() : $order->get_currency());
209
+		$post_data['amount']               = WC_Stripe_Helper::get_stripe_amount($order->get_total(), $post_data['currency']);
210 210
 		/* translators: 1) blog name 2) order number */
211
-		$post_data['description']          = sprintf( __( '%1$s - Order %2$s', 'woocommerce-gateway-stripe' ), wp_specialchars_decode( get_bloginfo( 'name' ), ENT_QUOTES ), $order->get_order_number() );
211
+		$post_data['description']          = sprintf(__('%1$s - Order %2$s', 'woocommerce-gateway-stripe'), wp_specialchars_decode(get_bloginfo('name'), ENT_QUOTES), $order->get_order_number());
212 212
 		$billing_email      = WC_Stripe_Helper::is_pre_30() ? $order->billing_email : $order->get_billing_email();
213 213
 		$billing_first_name = WC_Stripe_Helper::is_pre_30() ? $order->billing_first_name : $order->get_billing_first_name();
214 214
 		$billing_last_name  = WC_Stripe_Helper::is_pre_30() ? $order->billing_last_name : $order->get_billing_last_name();
215 215
 
216
-		if ( ! empty( $billing_email ) && apply_filters( 'wc_stripe_send_stripe_receipt', false ) ) {
216
+		if ( ! empty($billing_email) && apply_filters('wc_stripe_send_stripe_receipt', false)) {
217 217
 			$post_data['receipt_email'] = $billing_email;
218 218
 		}
219 219
 
220
-		switch ( WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method() ) {
221
-			case 'stripe':
222
-				if ( ! empty( $statement_descriptor ) ) {
223
-					$post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor( $statement_descriptor );
220
+		switch (WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method()) {
221
+			case 'stripe' : if ( ! empty($statement_descriptor)) {
222
+					$post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor($statement_descriptor);
224 223
 				}
225 224
 
226 225
 				$post_data['capture'] = $capture ? 'true' : 'false';
227 226
 				break;
228 227
 			case 'stripe_sepa':
229
-				if ( ! empty( $statement_descriptor ) ) {
230
-					$post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor( $statement_descriptor );
228
+				if ( ! empty($statement_descriptor)) {
229
+					$post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor($statement_descriptor);
231 230
 				}
232 231
 				break;
233 232
 		}
@@ -235,25 +234,25 @@  discard block
 block discarded – undo
235 234
 		$post_data['expand[]'] = 'balance_transaction';
236 235
 
237 236
 		$metadata = array(
238
-			__( 'customer_name', 'woocommerce-gateway-stripe' ) => sanitize_text_field( $billing_first_name ) . ' ' . sanitize_text_field( $billing_last_name ),
239
-			__( 'customer_email', 'woocommerce-gateway-stripe' ) => sanitize_email( $billing_email ),
237
+			__('customer_name', 'woocommerce-gateway-stripe') => sanitize_text_field($billing_first_name) . ' ' . sanitize_text_field($billing_last_name),
238
+			__('customer_email', 'woocommerce-gateway-stripe') => sanitize_email($billing_email),
240 239
 			'order_id' => WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(),
241 240
 		);
242 241
 
243
-		if ( $this->has_subscription( WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id() ) ) {
242
+		if ($this->has_subscription(WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id())) {
244 243
 			$metadata += array(
245 244
 				'payment_type' => 'recurring',
246
-				'site_url'     => esc_url( get_site_url() ),
245
+				'site_url'     => esc_url(get_site_url()),
247 246
 			);
248 247
 		}
249 248
 
250
-		$post_data['metadata'] = apply_filters( 'wc_stripe_payment_metadata', $metadata, $order, $prepared_source );
249
+		$post_data['metadata'] = apply_filters('wc_stripe_payment_metadata', $metadata, $order, $prepared_source);
251 250
 
252
-		if ( $prepared_source->customer ) {
251
+		if ($prepared_source->customer) {
253 252
 			$post_data['customer'] = $prepared_source->customer;
254 253
 		}
255 254
 
256
-		if ( $prepared_source->source ) {
255
+		if ($prepared_source->source) {
257 256
 			$post_data['source'] = $prepared_source->source;
258 257
 		}
259 258
 
@@ -265,79 +264,79 @@  discard block
 block discarded – undo
265 264
 		 * @param WC_Order $order
266 265
 		 * @param object $source
267 266
 		 */
268
-		return apply_filters( 'wc_stripe_generate_payment_request', $post_data, $order, $prepared_source );
267
+		return apply_filters('wc_stripe_generate_payment_request', $post_data, $order, $prepared_source);
269 268
 	}
270 269
 
271 270
 	/**
272 271
 	 * Store extra meta data for an order from a Stripe Response.
273 272
 	 */
274
-	public function process_response( $response, $order ) {
275
-		WC_Stripe_Logger::log( 'Processing response: ' . print_r( $response, true ) );
273
+	public function process_response($response, $order) {
274
+		WC_Stripe_Logger::log('Processing response: ' . print_r($response, true));
276 275
 
277 276
 		$order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
278 277
 
279
-		$captured = ( isset( $response->captured ) && $response->captured ) ? 'yes' : 'no';
278
+		$captured = (isset($response->captured) && $response->captured) ? 'yes' : 'no';
280 279
 
281 280
 		// Store charge data.
282
-		WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, '_stripe_charge_captured', $captured ) : $order->update_meta_data( '_stripe_charge_captured', $captured );
281
+		WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, '_stripe_charge_captured', $captured) : $order->update_meta_data('_stripe_charge_captured', $captured);
283 282
 
284 283
 		// Store other data such as fees.
285
-		if ( isset( $response->balance_transaction ) && isset( $response->balance_transaction->fee ) ) {
284
+		if (isset($response->balance_transaction) && isset($response->balance_transaction->fee)) {
286 285
 			// Fees and Net needs to both come from Stripe to be accurate as the returned
287 286
 			// values are in the local currency of the Stripe account, not from WC.
288
-			$fee = ! empty( $response->balance_transaction->fee ) ? WC_Stripe_Helper::format_balance_fee( $response->balance_transaction, 'fee' ) : 0;
289
-			$net = ! empty( $response->balance_transaction->net ) ? WC_Stripe_Helper::format_balance_fee( $response->balance_transaction, 'net' ) : 0;
290
-			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 );
291
-			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 );
287
+			$fee = ! empty($response->balance_transaction->fee) ? WC_Stripe_Helper::format_balance_fee($response->balance_transaction, 'fee') : 0;
288
+			$net = ! empty($response->balance_transaction->net) ? WC_Stripe_Helper::format_balance_fee($response->balance_transaction, 'net') : 0;
289
+			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);
290
+			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);
292 291
 		}
293 292
 
294
-		if ( 'yes' === $captured ) {
293
+		if ('yes' === $captured) {
295 294
 			/**
296 295
 			 * Charge can be captured but in a pending state. Payment methods
297 296
 			 * that are asynchronous may take couple days to clear. Webhook will
298 297
 			 * take care of the status changes.
299 298
 			 */
300
-			if ( 'pending' === $response->status ) {
301
-				$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 );
299
+			if ('pending' === $response->status) {
300
+				$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);
302 301
 
303
-				if ( ! $order_stock_reduced ) {
304
-					WC_Stripe_Helper::is_pre_30() ? $order->reduce_order_stock() : wc_reduce_stock_levels( $order_id );
302
+				if ( ! $order_stock_reduced) {
303
+					WC_Stripe_Helper::is_pre_30() ? $order->reduce_order_stock() : wc_reduce_stock_levels($order_id);
305 304
 				}
306 305
 
307
-				WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, '_transaction_id', $response->id ) : $order->set_transaction_id( $response->id );
306
+				WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, '_transaction_id', $response->id) : $order->set_transaction_id($response->id);
308 307
 				/* translators: transaction id */
309
-				$order->update_status( 'on-hold', sprintf( __( 'Stripe charge awaiting payment: %s.', 'woocommerce-gateway-stripe' ), $response->id ) );
308
+				$order->update_status('on-hold', sprintf(__('Stripe charge awaiting payment: %s.', 'woocommerce-gateway-stripe'), $response->id));
310 309
 			}
311 310
 
312
-			if ( 'succeeded' === $response->status ) {
313
-				$order->payment_complete( $response->id );
311
+			if ('succeeded' === $response->status) {
312
+				$order->payment_complete($response->id);
314 313
 
315 314
 				/* translators: transaction id */
316
-				$message = sprintf( __( 'Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe' ), $response->id );
317
-				$order->add_order_note( $message );
315
+				$message = sprintf(__('Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe'), $response->id);
316
+				$order->add_order_note($message);
318 317
 			}
319 318
 
320
-			if ( 'failed' === $response->status ) {
321
-				$localized_message = __( 'Payment processing failed. Please retry.', 'woocommerce-gateway-stripe' );
322
-				$order->add_order_note( $localized_message );
323
-				throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message );
319
+			if ('failed' === $response->status) {
320
+				$localized_message = __('Payment processing failed. Please retry.', 'woocommerce-gateway-stripe');
321
+				$order->add_order_note($localized_message);
322
+				throw new WC_Stripe_Exception(print_r($response, true), $localized_message);
324 323
 			}
325 324
 		} else {
326
-			WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, '_transaction_id', $response->id ) : $order->set_transaction_id( $response->id );
325
+			WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, '_transaction_id', $response->id) : $order->set_transaction_id($response->id);
327 326
 
328
-			if ( $order->has_status( array( 'pending', 'failed' ) ) ) {
329
-				WC_Stripe_Helper::is_pre_30() ? $order->reduce_order_stock() : wc_reduce_stock_levels( $order_id );
327
+			if ($order->has_status(array('pending', 'failed'))) {
328
+				WC_Stripe_Helper::is_pre_30() ? $order->reduce_order_stock() : wc_reduce_stock_levels($order_id);
330 329
 			}
331 330
 
332 331
 			/* translators: transaction id */
333
-			$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
+			$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));
334 333
 		}
335 334
 
336
-		if ( is_callable( array( $order, 'save' ) ) ) {
335
+		if (is_callable(array($order, 'save'))) {
337 336
 			$order->save();
338 337
 		}
339 338
 
340
-		do_action( 'wc_gateway_stripe_process_response', $response, $order );
339
+		do_action('wc_gateway_stripe_process_response', $response, $order);
341 340
 
342 341
 		return $response;
343 342
 	}
@@ -350,10 +349,10 @@  discard block
 block discarded – undo
350 349
 	 * @param int $order_id
351 350
 	 * @return null
352 351
 	 */
353
-	public function send_failed_order_email( $order_id ) {
352
+	public function send_failed_order_email($order_id) {
354 353
 		$emails = WC()->mailer()->get_emails();
355
-		if ( ! empty( $emails ) && ! empty( $order_id ) ) {
356
-			$emails['WC_Email_Failed_Order']->trigger( $order_id );
354
+		if ( ! empty($emails) && ! empty($order_id)) {
355
+			$emails['WC_Email_Failed_Order']->trigger($order_id);
357 356
 		}
358 357
 	}
359 358
 
@@ -365,7 +364,7 @@  discard block
 block discarded – undo
365 364
 	 * @param object $order
366 365
 	 * @return object $details
367 366
 	 */
368
-	public function get_owner_details( $order ) {
367
+	public function get_owner_details($order) {
369 368
 		$billing_first_name = WC_Stripe_Helper::is_pre_30() ? $order->billing_first_name : $order->get_billing_first_name();
370 369
 		$billing_last_name  = WC_Stripe_Helper::is_pre_30() ? $order->billing_last_name : $order->get_billing_last_name();
371 370
 
@@ -376,8 +375,8 @@  discard block
 block discarded – undo
376 375
 
377 376
 		$phone                             = WC_Stripe_Helper::is_pre_30() ? $order->billing_phone : $order->get_billing_phone();
378 377
 
379
-		if ( ! empty( $phone ) ) {
380
-			$details['phone']              = $phone;
378
+		if ( ! empty($phone)) {
379
+			$details['phone'] = $phone;
381 380
 		}
382 381
 
383 382
 		$details['address']['line1']       = WC_Stripe_Helper::is_pre_30() ? $order->billing_address_1 : $order->get_billing_address_1();
@@ -387,7 +386,7 @@  discard block
 block discarded – undo
387 386
 		$details['address']['postal_code'] = WC_Stripe_Helper::is_pre_30() ? $order->billing_postcode : $order->get_billing_postcode();
388 387
 		$details['address']['country']     = WC_Stripe_Helper::is_pre_30() ? $order->billing_country : $order->get_billing_country();
389 388
 
390
-		return (object) apply_filters( 'wc_stripe_owner_details', $details, $order );
389
+		return (object) apply_filters('wc_stripe_owner_details', $details, $order);
391 390
 	}
392 391
 
393 392
 	/**
@@ -396,15 +395,15 @@  discard block
 block discarded – undo
396 395
 	 * @since 4.0.3
397 396
 	 * @param string $source_id The source ID to get source object for.
398 397
 	 */
399
-	public function get_source_object( $source_id = '' ) {
400
-		if ( empty( $source_id ) ) {
398
+	public function get_source_object($source_id = '') {
399
+		if (empty($source_id)) {
401 400
 			return '';
402 401
 		}
403 402
 
404
-		$source_object = WC_Stripe_API::retrieve( 'sources/' . $source_id );
403
+		$source_object = WC_Stripe_API::retrieve('sources/' . $source_id);
405 404
 
406
-		if ( ! empty( $source_object->error ) ) {
407
-			throw new WC_Stripe_Exception( print_r( $source_object, true ), $source_object->error->message );
405
+		if ( ! empty($source_object->error)) {
406
+			throw new WC_Stripe_Exception(print_r($source_object, true), $source_object->error->message);
408 407
 		}
409 408
 
410 409
 		return $source_object;
@@ -417,11 +416,11 @@  discard block
 block discarded – undo
417 416
 	 * @param object $source_object
418 417
 	 * @return bool
419 418
 	 */
420
-	public function is_3ds_required( $source_object ) {
419
+	public function is_3ds_required($source_object) {
421 420
 		return (
422
-			$source_object && ! empty( $source_object->card ) ) &&
423
-			( 'card' === $source_object->type && 'required' === $source_object->card->three_d_secure ||
424
-			( $this->three_d_secure && 'optional' === $source_object->card->three_d_secure )
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)
425 424
 		);
426 425
 	}
427 426
 
@@ -432,8 +431,8 @@  discard block
 block discarded – undo
432 431
 	 * @param object $source_object
433 432
 	 * @return bool
434 433
 	 */
435
-	public function is_3ds_card( $source_object ) {
436
-		return ( $source_object && 'three_d_secure' === $source_object->type );
434
+	public function is_3ds_card($source_object) {
435
+		return ($source_object && 'three_d_secure' === $source_object->type);
437 436
 	}
438 437
 
439 438
 	/**
@@ -443,8 +442,8 @@  discard block
 block discarded – undo
443 442
 	 * @param object $source_object
444 443
 	 * @return bool
445 444
 	 */
446
-	public function is_prepaid_card( $source_object ) {
447
-		return ( $source_object && 'token' === $source_object->object && 'prepaid' === $source_object->card->funding );
445
+	public function is_prepaid_card($source_object) {
446
+		return ($source_object && 'token' === $source_object->object && 'prepaid' === $source_object->card->funding);
448 447
 	}
449 448
 
450 449
 	/**
@@ -457,22 +456,22 @@  discard block
 block discarded – undo
457 456
 	 * @param string $return_url
458 457
 	 * @return mixed
459 458
 	 */
460
-	public function create_3ds_source( $order, $source_object, $return_url = '' ) {
459
+	public function create_3ds_source($order, $source_object, $return_url = '') {
461 460
 		$currency                    = WC_Stripe_Helper::is_pre_30() ? $order->get_order_currency() : $order->get_currency();
462 461
 		$order_id                    = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
463
-		$return_url                  = empty( $return_url ) ? $this->get_stripe_return_url( $order ) : $return_url;
462
+		$return_url                  = empty($return_url) ? $this->get_stripe_return_url($order) : $return_url;
464 463
 
465 464
 		$post_data                   = array();
466
-		$post_data['amount']         = WC_Stripe_Helper::get_stripe_amount( $order->get_total(), $currency );
467
-		$post_data['currency']       = strtolower( $currency );
465
+		$post_data['amount']         = WC_Stripe_Helper::get_stripe_amount($order->get_total(), $currency);
466
+		$post_data['currency']       = strtolower($currency);
468 467
 		$post_data['type']           = 'three_d_secure';
469
-		$post_data['owner']          = $this->get_owner_details( $order );
470
-		$post_data['three_d_secure'] = array( 'card' => $source_object->id );
471
-		$post_data['redirect']       = array( 'return_url' => $return_url );
468
+		$post_data['owner']          = $this->get_owner_details($order);
469
+		$post_data['three_d_secure'] = array('card' => $source_object->id);
470
+		$post_data['redirect']       = array('return_url' => $return_url);
472 471
 
473
-		WC_Stripe_Logger::log( 'Info: Begin creating 3DS source...' );
472
+		WC_Stripe_Logger::log('Info: Begin creating 3DS source...');
474 473
 
475
-		return WC_Stripe_API::request( apply_filters( 'wc_stripe_3ds_source', $post_data, $order ), 'sources' );
474
+		return WC_Stripe_API::request(apply_filters('wc_stripe_3ds_source', $post_data, $order), 'sources');
476 475
 	}
477 476
 
478 477
 	/**
@@ -488,58 +487,58 @@  discard block
 block discarded – undo
488 487
 	 * @throws Exception When card was not added or for and invalid card.
489 488
 	 * @return object
490 489
 	 */
491
-	public function prepare_source( $user_id, $force_save_source = false ) {
492
-		$customer           = new WC_Stripe_Customer( $user_id );
490
+	public function prepare_source($user_id, $force_save_source = false) {
491
+		$customer           = new WC_Stripe_Customer($user_id);
493 492
 		$set_customer       = true;
494
-		$force_save_source  = apply_filters( 'wc_stripe_force_save_source', $force_save_source, $customer );
493
+		$force_save_source  = apply_filters('wc_stripe_force_save_source', $force_save_source, $customer);
495 494
 		$source_object      = '';
496 495
 		$source_id          = '';
497 496
 		$wc_token_id        = false;
498
-		$payment_method     = isset( $_POST['payment_method'] ) ? wc_clean( $_POST['payment_method'] ) : 'stripe';
497
+		$payment_method     = isset($_POST['payment_method']) ? wc_clean($_POST['payment_method']) : 'stripe';
499 498
 		$is_token           = false;
500 499
 
501 500
 		// New CC info was entered and we have a new source to process.
502
-		if ( ! empty( $_POST['stripe_source'] ) ) {
503
-			$source_object = self::get_source_object( wc_clean( $_POST['stripe_source'] ) );
501
+		if ( ! empty($_POST['stripe_source'])) {
502
+			$source_object = self::get_source_object(wc_clean($_POST['stripe_source']));
504 503
 			$source_id     = $source_object->id;
505 504
 
506 505
 			// This checks to see if customer opted to save the payment method to file.
507
-			$maybe_saved_card = isset( $_POST[ 'wc-' . $payment_method . '-new-payment-method' ] ) && ! empty( $_POST[ 'wc-' . $payment_method . '-new-payment-method' ] );
506
+			$maybe_saved_card = isset($_POST['wc-' . $payment_method . '-new-payment-method']) && ! empty($_POST['wc-' . $payment_method . '-new-payment-method']);
508 507
 
509 508
 			/**
510 509
 			 * This is true if the user wants to store the card to their account.
511 510
 			 * Criteria to save to file is they are logged in, they opted to save or product requirements and the source is
512 511
 			 * actually reusable. Either that or force_save_source is true.
513 512
 			 */
514
-			if ( ( $user_id && $this->saved_cards && $maybe_saved_card && 'reusable' === $source_object->usage ) || $force_save_source ) {
515
-				$response = $customer->add_source( $source_object->id );
513
+			if (($user_id && $this->saved_cards && $maybe_saved_card && 'reusable' === $source_object->usage) || $force_save_source) {
514
+				$response = $customer->add_source($source_object->id);
516 515
 
517
-				if ( ! empty( $response->error ) ) {
518
-					throw new WC_Stripe_Exception( print_r( $response, true ), $response->error->message );
516
+				if ( ! empty($response->error)) {
517
+					throw new WC_Stripe_Exception(print_r($response, true), $response->error->message);
519 518
 				}
520 519
 			}
521
-		} elseif ( isset( $_POST[ 'wc-' . $payment_method . '-payment-token' ] ) && 'new' !== $_POST[ 'wc-' . $payment_method . '-payment-token' ] ) {
520
+		} elseif (isset($_POST['wc-' . $payment_method . '-payment-token']) && 'new' !== $_POST['wc-' . $payment_method . '-payment-token']) {
522 521
 			// Use an existing token, and then process the payment.
523
-			$wc_token_id = wc_clean( $_POST[ 'wc-' . $payment_method . '-payment-token' ] );
524
-			$wc_token    = WC_Payment_Tokens::get( $wc_token_id );
522
+			$wc_token_id = wc_clean($_POST['wc-' . $payment_method . '-payment-token']);
523
+			$wc_token    = WC_Payment_Tokens::get($wc_token_id);
525 524
 
526
-			if ( ! $wc_token || $wc_token->get_user_id() !== get_current_user_id() ) {
527
-				WC()->session->set( 'refresh_totals', true );
528
-				throw new WC_Stripe_Exception( 'Invalid payment method', __( 'Invalid payment method. Please input a new card number.', 'woocommerce-gateway-stripe' ) );
525
+			if ( ! $wc_token || $wc_token->get_user_id() !== get_current_user_id()) {
526
+				WC()->session->set('refresh_totals', true);
527
+				throw new WC_Stripe_Exception('Invalid payment method', __('Invalid payment method. Please input a new card number.', 'woocommerce-gateway-stripe'));
529 528
 			}
530 529
 
531 530
 			$source_id = $wc_token->get_token();
532 531
 			$is_token  = true;
533
-		} elseif ( isset( $_POST['stripe_token'] ) && 'new' !== $_POST['stripe_token'] ) {
534
-			$stripe_token     = wc_clean( $_POST['stripe_token'] );
535
-			$maybe_saved_card = isset( $_POST[ 'wc-' . $payment_method . '-new-payment-method' ] ) && ! empty( $_POST[ 'wc-' . $payment_method . '-new-payment-method' ] );
532
+		} elseif (isset($_POST['stripe_token']) && 'new' !== $_POST['stripe_token']) {
533
+			$stripe_token     = wc_clean($_POST['stripe_token']);
534
+			$maybe_saved_card = isset($_POST['wc-' . $payment_method . '-new-payment-method']) && ! empty($_POST['wc-' . $payment_method . '-new-payment-method']);
536 535
 
537 536
 			// This is true if the user wants to store the card to their account.
538
-			if ( ( $user_id && $this->saved_cards && $maybe_saved_card ) || $force_save_source ) {
539
-				$response = $customer->add_source( $stripe_token );
537
+			if (($user_id && $this->saved_cards && $maybe_saved_card) || $force_save_source) {
538
+				$response = $customer->add_source($stripe_token);
540 539
 
541
-				if ( ! empty( $response->error ) ) {
542
-					throw new WC_Stripe_Exception( print_r( $response, true ), $response->error->message );
540
+				if ( ! empty($response->error)) {
541
+					throw new WC_Stripe_Exception(print_r($response, true), $response->error->message);
543 542
 				}
544 543
 			} else {
545 544
 				$set_customer = false;
@@ -548,14 +547,14 @@  discard block
 block discarded – undo
548 547
 			}
549 548
 		}
550 549
 
551
-		if ( ! $set_customer ) {
550
+		if ( ! $set_customer) {
552 551
 			$customer_id = false;
553 552
 		} else {
554 553
 			$customer_id = $customer->get_id() ? $customer->get_id() : false;
555 554
 		}
556 555
 
557
-		if ( empty( $source_object ) && ! $is_token ) {
558
-			$source_object = self::get_source_object( $source_id );
556
+		if (empty($source_object) && ! $is_token) {
557
+			$source_object = self::get_source_object($source_id);
559 558
 		}
560 559
 
561 560
 		return (object) array(
@@ -579,37 +578,37 @@  discard block
 block discarded – undo
579 578
 	 * @param object $order
580 579
 	 * @return object
581 580
 	 */
582
-	public function prepare_order_source( $order = null ) {
581
+	public function prepare_order_source($order = null) {
583 582
 		$stripe_customer = new WC_Stripe_Customer();
584 583
 		$stripe_source   = false;
585 584
 		$token_id        = false;
586 585
 
587
-		if ( $order ) {
586
+		if ($order) {
588 587
 			$order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
589 588
 
590
-			$stripe_customer_id = get_post_meta( $order_id, '_stripe_customer_id', true );
589
+			$stripe_customer_id = get_post_meta($order_id, '_stripe_customer_id', true);
591 590
 
592
-			if ( $stripe_customer_id ) {
593
-				$stripe_customer->set_id( $stripe_customer_id );
591
+			if ($stripe_customer_id) {
592
+				$stripe_customer->set_id($stripe_customer_id);
594 593
 			}
595 594
 
596
-			$source_id = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_stripe_source_id', true ) : $order->get_meta( '_stripe_source_id', true );
595
+			$source_id = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_stripe_source_id', true) : $order->get_meta('_stripe_source_id', true);
597 596
 
598 597
 			// Since 4.0.0, we changed card to source so we need to account for that.
599
-			if ( empty( $source_id ) ) {
600
-				$source_id = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_stripe_card_id', true ) : $order->get_meta( '_stripe_card_id', true );
598
+			if (empty($source_id)) {
599
+				$source_id = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_stripe_card_id', true) : $order->get_meta('_stripe_card_id', true);
601 600
 
602 601
 				// Take this opportunity to update the key name.
603
-				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 );
602
+				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);
604 603
 
605
-				if ( is_callable( array( $order, 'save' ) ) ) {
604
+				if (is_callable(array($order, 'save'))) {
606 605
 					$order->save();
607 606
 				}
608 607
 			}
609 608
 
610
-			if ( $source_id ) {
609
+			if ($source_id) {
611 610
 				$stripe_source = $source_id;
612
-			} elseif ( apply_filters( 'wc_stripe_use_default_customer_source', true ) ) {
611
+			} elseif (apply_filters('wc_stripe_use_default_customer_source', true)) {
613 612
 				/*
614 613
 				 * We can attempt to charge the customer's default source
615 614
 				 * by sending empty source id.
@@ -633,27 +632,27 @@  discard block
 block discarded – undo
633 632
 	 * @param WC_Order $order For to which the source applies.
634 633
 	 * @param stdClass $source Source information.
635 634
 	 */
636
-	public function save_source_to_order( $order, $source ) {
635
+	public function save_source_to_order($order, $source) {
637 636
 		$order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
638 637
 
639 638
 		// Store source in the order.
640
-		if ( $source->customer ) {
641
-			if ( WC_Stripe_Helper::is_pre_30() ) {
642
-				update_post_meta( $order_id, '_stripe_customer_id', $source->customer );
639
+		if ($source->customer) {
640
+			if (WC_Stripe_Helper::is_pre_30()) {
641
+				update_post_meta($order_id, '_stripe_customer_id', $source->customer);
643 642
 			} else {
644
-				$order->update_meta_data( '_stripe_customer_id', $source->customer );
643
+				$order->update_meta_data('_stripe_customer_id', $source->customer);
645 644
 			}
646 645
 		}
647 646
 
648
-		if ( $source->source ) {
649
-			if ( WC_Stripe_Helper::is_pre_30() ) {
650
-				update_post_meta( $order_id, '_stripe_source_id', $source->source );
647
+		if ($source->source) {
648
+			if (WC_Stripe_Helper::is_pre_30()) {
649
+				update_post_meta($order_id, '_stripe_source_id', $source->source);
651 650
 			} else {
652
-				$order->update_meta_data( '_stripe_source_id', $source->source );
651
+				$order->update_meta_data('_stripe_source_id', $source->source);
653 652
 			}
654 653
 		}
655 654
 
656
-		if ( is_callable( array( $order, 'save' ) ) ) {
655
+		if (is_callable(array($order, 'save'))) {
657 656
 			$order->save();
658 657
 		}
659 658
 	}
@@ -667,35 +666,35 @@  discard block
 block discarded – undo
667 666
 	 * @param object $order The order object
668 667
 	 * @param int $balance_transaction_id
669 668
 	 */
670
-	public function update_fees( $order, $balance_transaction_id ) {
669
+	public function update_fees($order, $balance_transaction_id) {
671 670
 		$order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
672 671
 
673
-		$balance_transaction = WC_Stripe_API::retrieve( 'balance/history/' . $balance_transaction_id );
672
+		$balance_transaction = WC_Stripe_API::retrieve('balance/history/' . $balance_transaction_id);
674 673
 
675
-		if ( empty( $balance_transaction->error ) ) {
676
-			if ( isset( $balance_transaction ) && isset( $balance_transaction->fee ) ) {
674
+		if (empty($balance_transaction->error)) {
675
+			if (isset($balance_transaction) && isset($balance_transaction->fee)) {
677 676
 				// Fees and Net needs to both come from Stripe to be accurate as the returned
678 677
 				// values are in the local currency of the Stripe account, not from WC.
679
-				$fee_refund = ! empty( $balance_transaction->fee ) ? WC_Stripe_Helper::format_balance_fee( $balance_transaction, 'fee' ) : 0;
680
-				$net_refund = ! empty( $balance_transaction->net ) ? WC_Stripe_Helper::format_balance_fee( $balance_transaction, 'net' ) : 0;
678
+				$fee_refund = ! empty($balance_transaction->fee) ? WC_Stripe_Helper::format_balance_fee($balance_transaction, 'fee') : 0;
679
+				$net_refund = ! empty($balance_transaction->net) ? WC_Stripe_Helper::format_balance_fee($balance_transaction, 'net') : 0;
681 680
 
682 681
 				// Current data fee & net.
683
-				$fee_current = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, self::META_NAME_FEE, true ) : $order->get_meta( self::META_NAME_FEE, true );
684
-				$net_current = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, self::META_NAME_NET, true ) : $order->get_meta( self::META_NAME_NET, true );
682
+				$fee_current = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, self::META_NAME_FEE, true) : $order->get_meta(self::META_NAME_FEE, true);
683
+				$net_current = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, self::META_NAME_NET, true) : $order->get_meta(self::META_NAME_NET, true);
685 684
 
686 685
 				// Calculation.
687 686
 				$fee = (float) $fee_current + (float) $fee_refund;
688 687
 				$net = (float) $net_current + (float) $net_refund;
689 688
 
690
-				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 );
691
-				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 );
689
+				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);
690
+				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);
692 691
 
693
-				if ( is_callable( array( $order, 'save' ) ) ) {
692
+				if (is_callable(array($order, 'save'))) {
694 693
 					$order->save();
695 694
 				}
696 695
 			}
697 696
 		} else {
698
-			WC_Stripe_Logger::log( "Unable to update fees/net meta for order: {$order_id}" );
697
+			WC_Stripe_Logger::log("Unable to update fees/net meta for order: {$order_id}");
699 698
 		}
700 699
 	}
701 700
 
@@ -708,33 +707,33 @@  discard block
 block discarded – undo
708 707
 	 * @param  float $amount
709 708
 	 * @return bool
710 709
 	 */
711
-	public function process_refund( $order_id, $amount = null, $reason = '' ) {
712
-		$order = wc_get_order( $order_id );
710
+	public function process_refund($order_id, $amount = null, $reason = '') {
711
+		$order = wc_get_order($order_id);
713 712
 
714
-		if ( ! $order || ! $order->get_transaction_id() ) {
713
+		if ( ! $order || ! $order->get_transaction_id()) {
715 714
 			return false;
716 715
 		}
717 716
 
718 717
 		$request = array();
719 718
 
720
-		if ( WC_Stripe_Helper::is_pre_30() ) {
721
-			$order_currency = get_post_meta( $order_id, '_order_currency', true );
722
-			$captured       = get_post_meta( $order_id, '_stripe_charge_captured', true );
719
+		if (WC_Stripe_Helper::is_pre_30()) {
720
+			$order_currency = get_post_meta($order_id, '_order_currency', true);
721
+			$captured       = get_post_meta($order_id, '_stripe_charge_captured', true);
723 722
 		} else {
724 723
 			$order_currency = $order->get_currency();
725
-			$captured       = $order->get_meta( '_stripe_charge_captured', true );
724
+			$captured       = $order->get_meta('_stripe_charge_captured', true);
726 725
 		}
727 726
 
728
-		if ( ! is_null( $amount ) ) {
729
-			$request['amount'] = WC_Stripe_Helper::get_stripe_amount( $amount, $order_currency );
727
+		if ( ! is_null($amount)) {
728
+			$request['amount'] = WC_Stripe_Helper::get_stripe_amount($amount, $order_currency);
730 729
 		}
731 730
 
732 731
 		// If order is only authorized, don't pass amount.
733
-		if ( 'yes' !== $captured ) {
734
-			unset( $request['amount'] );
732
+		if ('yes' !== $captured) {
733
+			unset($request['amount']);
735 734
 		}
736 735
 
737
-		if ( $reason ) {
736
+		if ($reason) {
738 737
 			$request['metadata'] = array(
739 738
 				'reason' => $reason,
740 739
 			);
@@ -742,35 +741,35 @@  discard block
 block discarded – undo
742 741
 
743 742
 		$request['charge'] = $order->get_transaction_id();
744 743
 
745
-		WC_Stripe_Logger::log( "Info: Beginning refund for order {$order->get_transaction_id()} for the amount of {$amount}" );
744
+		WC_Stripe_Logger::log("Info: Beginning refund for order {$order->get_transaction_id()} for the amount of {$amount}");
746 745
 
747
-		$request = apply_filters( 'wc_stripe_refund_request', $request, $order );
746
+		$request = apply_filters('wc_stripe_refund_request', $request, $order);
748 747
 
749
-		$response = WC_Stripe_API::request( $request, 'refunds' );
748
+		$response = WC_Stripe_API::request($request, 'refunds');
750 749
 
751
-		if ( ! empty( $response->error ) ) {
752
-			WC_Stripe_Logger::log( 'Error: ' . $response->error->message );
750
+		if ( ! empty($response->error)) {
751
+			WC_Stripe_Logger::log('Error: ' . $response->error->message);
753 752
 
754 753
 			return $response;
755 754
 
756
-		} elseif ( ! empty( $response->id ) ) {
757
-			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 );
755
+		} elseif ( ! empty($response->id)) {
756
+			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);
758 757
 
759
-			$amount = wc_price( $response->amount / 100 );
758
+			$amount = wc_price($response->amount / 100);
760 759
 
761
-			if ( in_array( strtolower( $order->get_currency() ), WC_Stripe_Helper::no_decimal_currencies() ) ) {
762
-				$amount = wc_price( $response->amount );
760
+			if (in_array(strtolower($order->get_currency()), WC_Stripe_Helper::no_decimal_currencies())) {
761
+				$amount = wc_price($response->amount);
763 762
 			}
764 763
 
765
-			if ( isset( $response->balance_transaction ) ) {
766
-				$this->update_fees( $order, $response->balance_transaction );
764
+			if (isset($response->balance_transaction)) {
765
+				$this->update_fees($order, $response->balance_transaction);
767 766
 			}
768 767
 
769 768
 			/* translators: 1) dollar amount 2) transaction id 3) refund message */
770
-			$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' );
769
+			$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');
771 770
 
772
-			$order->add_order_note( $refund_message );
773
-			WC_Stripe_Logger::log( 'Success: ' . html_entity_decode( strip_tags( $refund_message ) ) );
771
+			$order->add_order_note($refund_message);
772
+			WC_Stripe_Logger::log('Success: ' . html_entity_decode(strip_tags($refund_message)));
774 773
 
775 774
 			return true;
776 775
 		}
@@ -785,44 +784,44 @@  discard block
 block discarded – undo
785 784
 	 */
786 785
 	public function add_payment_method() {
787 786
 		$error     = false;
788
-		$error_msg = __( 'There was a problem adding the card.', 'woocommerce-gateway-stripe' );
787
+		$error_msg = __('There was a problem adding the card.', 'woocommerce-gateway-stripe');
789 788
 		$source_id = '';
790 789
 
791
-		if ( empty( $_POST['stripe_source'] ) && empty( $_POST['stripe_token'] ) || ! is_user_logged_in() ) {
790
+		if (empty($_POST['stripe_source']) && empty($_POST['stripe_token']) || ! is_user_logged_in()) {
792 791
 			$error = true;
793 792
 		}
794 793
 
795
-		$stripe_customer = new WC_Stripe_Customer( get_current_user_id() );
794
+		$stripe_customer = new WC_Stripe_Customer(get_current_user_id());
796 795
 
797
-		$source = ! empty( $_POST['stripe_source'] ) ? wc_clean( $_POST['stripe_source'] ) : '';
796
+		$source = ! empty($_POST['stripe_source']) ? wc_clean($_POST['stripe_source']) : '';
798 797
 
799
-		$source_object = WC_Stripe_API::retrieve( 'sources/' . $source );
798
+		$source_object = WC_Stripe_API::retrieve('sources/' . $source);
800 799
 
801
-		if ( isset( $source_object ) ) {
802
-			if ( ! empty( $source_object->error ) ) {
800
+		if (isset($source_object)) {
801
+			if ( ! empty($source_object->error)) {
803 802
 				$error = true;
804 803
 			}
805 804
 
806 805
 			$source_id = $source_object->id;
807
-		} elseif ( isset( $_POST['stripe_token'] ) ) {
808
-			$source_id = wc_clean( $_POST['stripe_token'] );
806
+		} elseif (isset($_POST['stripe_token'])) {
807
+			$source_id = wc_clean($_POST['stripe_token']);
809 808
 		}
810 809
 
811
-		$response = $stripe_customer->add_source( $source_id );
810
+		$response = $stripe_customer->add_source($source_id);
812 811
 
813
-		if ( ! $response || is_wp_error( $response ) || ! empty( $response->error ) ) {
812
+		if ( ! $response || is_wp_error($response) || ! empty($response->error)) {
814 813
 			$error = true;
815 814
 		}
816 815
 
817
-		if ( $error ) {
818
-			wc_add_notice( $error_msg, 'error' );
819
-			WC_Stripe_Logger::log( 'Add payment method Error: ' . $error_msg );
816
+		if ($error) {
817
+			wc_add_notice($error_msg, 'error');
818
+			WC_Stripe_Logger::log('Add payment method Error: ' . $error_msg);
820 819
 			return;
821 820
 		}
822 821
 
823 822
 		return array(
824 823
 			'result'   => 'success',
825
-			'redirect' => wc_get_endpoint_url( 'payment-methods' ),
824
+			'redirect' => wc_get_endpoint_url('payment-methods'),
826 825
 		);
827 826
 	}
828 827
 
@@ -839,10 +838,10 @@  discard block
 block discarded – undo
839 838
 		 * Stripe expects Norwegian to only be passed NO.
840 839
 		 * But WP has different dialects.
841 840
 		 */
842
-		if ( 'NO' === substr( $locale, 3, 2 ) ) {
841
+		if ('NO' === substr($locale, 3, 2)) {
843 842
 			$locale = 'no';
844 843
 		} else {
845
-			$locale = substr( get_locale(), 0, 2 );
844
+			$locale = substr(get_locale(), 0, 2);
846 845
 		}
847 846
 
848 847
 		return $locale;
@@ -856,9 +855,9 @@  discard block
 block discarded – undo
856 855
 	 * @param string $idempotency_key
857 856
 	 * @param array $request
858 857
 	 */
859
-	public function change_idempotency_key( $idempotency_key, $request ) {
860
-		$customer = ! empty( $request['customer'] ) ? $request['customer'] : '';
861
-		$source   = ! empty( $request['source'] ) ? $request['source'] : $customer;
858
+	public function change_idempotency_key($idempotency_key, $request) {
859
+		$customer = ! empty($request['customer']) ? $request['customer'] : '';
860
+		$source   = ! empty($request['source']) ? $request['source'] : $customer;
862 861
 		$count    = $this->retry_interval;
863 862
 
864 863
 		return $request['metadata']['order_id'] . '-' . $count . '-' . $source;
@@ -872,8 +871,8 @@  discard block
 block discarded – undo
872 871
 	 * @since 4.0.6
873 872
 	 * @param array $headers
874 873
 	 */
875
-	public function is_original_request( $headers ) {
876
-		if ( $headers['original-request'] === $headers['request-id'] ) {
874
+	public function is_original_request($headers) {
875
+		if ($headers['original-request'] === $headers['request-id']) {
877 876
 			return true;
878 877
 		}
879 878
 
Please login to merge, or discard this patch.
includes/payment-methods/class-wc-stripe-payment-request.php 1 patch
Spacing   +285 added lines, -285 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
 
@@ -71,36 +71,36 @@  discard block
 block discarded – undo
71 71
 	 */
72 72
 	public function __construct() {
73 73
 		self::$_this                   = $this;
74
-		$this->stripe_settings         = get_option( 'woocommerce_stripe_settings', array() );
75
-		$this->testmode                = ( ! empty( $this->stripe_settings['testmode'] ) && 'yes' === $this->stripe_settings['testmode'] ) ? true : false;
76
-		$this->publishable_key         = ! empty( $this->stripe_settings['publishable_key'] ) ? $this->stripe_settings['publishable_key'] : '';
77
-		$this->secret_key              = ! empty( $this->stripe_settings['secret_key'] ) ? $this->stripe_settings['secret_key'] : '';
78
-		$this->stripe_checkout_enabled = isset( $this->stripe_settings['stripe_checkout'] ) && 'yes' === $this->stripe_settings['stripe_checkout'];
79
-		$this->total_label             = ! empty( $this->stripe_settings['statement_descriptor'] ) ? WC_Stripe_Helper::clean_statement_descriptor( $this->stripe_settings['statement_descriptor'] ) : '';
74
+		$this->stripe_settings         = get_option('woocommerce_stripe_settings', array());
75
+		$this->testmode                = ( ! empty($this->stripe_settings['testmode']) && 'yes' === $this->stripe_settings['testmode']) ? true : false;
76
+		$this->publishable_key         = ! empty($this->stripe_settings['publishable_key']) ? $this->stripe_settings['publishable_key'] : '';
77
+		$this->secret_key              = ! empty($this->stripe_settings['secret_key']) ? $this->stripe_settings['secret_key'] : '';
78
+		$this->stripe_checkout_enabled = isset($this->stripe_settings['stripe_checkout']) && 'yes' === $this->stripe_settings['stripe_checkout'];
79
+		$this->total_label             = ! empty($this->stripe_settings['statement_descriptor']) ? WC_Stripe_Helper::clean_statement_descriptor($this->stripe_settings['statement_descriptor']) : '';
80 80
 
81
-		if ( $this->testmode ) {
82
-			$this->publishable_key = ! empty( $this->stripe_settings['test_publishable_key'] ) ? $this->stripe_settings['test_publishable_key'] : '';
83
-			$this->secret_key      = ! empty( $this->stripe_settings['test_secret_key'] ) ? $this->stripe_settings['test_secret_key'] : '';
81
+		if ($this->testmode) {
82
+			$this->publishable_key = ! empty($this->stripe_settings['test_publishable_key']) ? $this->stripe_settings['test_publishable_key'] : '';
83
+			$this->secret_key      = ! empty($this->stripe_settings['test_secret_key']) ? $this->stripe_settings['test_secret_key'] : '';
84 84
 		}
85 85
 
86
-		$this->total_label = str_replace( "'", '', $this->total_label ) . apply_filters( 'wc_stripe_payment_request_total_label_suffix', ' (via WooCommerce)' );
86
+		$this->total_label = str_replace("'", '', $this->total_label) . apply_filters('wc_stripe_payment_request_total_label_suffix', ' (via WooCommerce)');
87 87
 
88 88
 		// Checks if Stripe Gateway is enabled.
89
-		if ( empty( $this->stripe_settings ) || ( isset( $this->stripe_settings['enabled'] ) && 'yes' !== $this->stripe_settings['enabled'] ) ) {
89
+		if (empty($this->stripe_settings) || (isset($this->stripe_settings['enabled']) && 'yes' !== $this->stripe_settings['enabled'])) {
90 90
 			return;
91 91
 		}
92 92
 
93 93
 		// Checks if Payment Request is enabled.
94
-		if ( ! isset( $this->stripe_settings['payment_request'] ) || 'yes' !== $this->stripe_settings['payment_request'] ) {
94
+		if ( ! isset($this->stripe_settings['payment_request']) || 'yes' !== $this->stripe_settings['payment_request']) {
95 95
 			return;
96 96
 		}
97 97
 
98 98
 		// Don't load for change payment method page.
99
-		if ( isset( $_GET['change_payment_method'] ) ) {
99
+		if (isset($_GET['change_payment_method'])) {
100 100
 			return;
101 101
 		}
102 102
 
103
-		add_action( 'template_redirect', array( $this, 'set_session' ) );
103
+		add_action('template_redirect', array($this, 'set_session'));
104 104
 		$this->init();
105 105
 	}
106 106
 
@@ -111,7 +111,7 @@  discard block
 block discarded – undo
111 111
 	 * @return bool
112 112
 	 */
113 113
 	public function are_keys_set() {
114
-		if ( empty( $this->secret_key ) || empty( $this->publishable_key ) ) {
114
+		if (empty($this->secret_key) || empty($this->publishable_key)) {
115 115
 			return false;
116 116
 		}
117 117
 
@@ -135,19 +135,19 @@  discard block
 block discarded – undo
135 135
 	 * @since 4.0.0
136 136
 	 */
137 137
 	public function set_session() {
138
-		if ( ! is_product() ) {
138
+		if ( ! is_product()) {
139 139
 			return;
140 140
 		}
141 141
 
142
-		if ( ! is_user_logged_in() ) {
142
+		if ( ! is_user_logged_in()) {
143 143
 			$wc_session = new WC_Session_Handler();
144 144
 
145
-			if ( version_compare( WC_VERSION, '3.3', '>=' ) ) {
145
+			if (version_compare(WC_VERSION, '3.3', '>=')) {
146 146
 				$wc_session->init();
147 147
 			}
148 148
 
149
-			if ( ! $wc_session->has_session() ) {
150
-				$wc_session->set_customer_session_cookie( true );
149
+			if ( ! $wc_session->has_session()) {
150
+				$wc_session->set_customer_session_cookie(true);
151 151
 			}
152 152
 		}
153 153
 	}
@@ -159,40 +159,40 @@  discard block
 block discarded – undo
159 159
 	 * @version 4.0.0
160 160
 	 */
161 161
 	public function init() {
162
-		add_action( 'wp_enqueue_scripts', array( $this, 'scripts' ) );
162
+		add_action('wp_enqueue_scripts', array($this, 'scripts'));
163 163
 
164 164
 		/*
165 165
 		 * In order to display the Payment Request button in the correct position,
166 166
 		 * a new hook was added to WooCommerce 3.0. In older versions of WooCommerce,
167 167
 		 * CSS is used to position the button.
168 168
 		 */
169
-		if ( WC_Stripe_Helper::is_pre_30() ) {
170
-			add_action( 'woocommerce_after_add_to_cart_button', array( $this, 'display_payment_request_button_html' ), 1 );
171
-			add_action( 'woocommerce_after_add_to_cart_button', array( $this, 'display_payment_request_button_separator_html' ), 2 );
169
+		if (WC_Stripe_Helper::is_pre_30()) {
170
+			add_action('woocommerce_after_add_to_cart_button', array($this, 'display_payment_request_button_html'), 1);
171
+			add_action('woocommerce_after_add_to_cart_button', array($this, 'display_payment_request_button_separator_html'), 2);
172 172
 		} else {
173
-			add_action( 'woocommerce_after_add_to_cart_quantity', array( $this, 'display_payment_request_button_html' ), 1 );
174
-			add_action( 'woocommerce_after_add_to_cart_quantity', array( $this, 'display_payment_request_button_separator_html' ), 2 );
173
+			add_action('woocommerce_after_add_to_cart_quantity', array($this, 'display_payment_request_button_html'), 1);
174
+			add_action('woocommerce_after_add_to_cart_quantity', array($this, 'display_payment_request_button_separator_html'), 2);
175 175
 		}
176 176
 
177
-		add_action( 'woocommerce_proceed_to_checkout', array( $this, 'display_payment_request_button_html' ), 1 );
178
-		add_action( 'woocommerce_proceed_to_checkout', array( $this, 'display_payment_request_button_separator_html' ), 2 );
177
+		add_action('woocommerce_proceed_to_checkout', array($this, 'display_payment_request_button_html'), 1);
178
+		add_action('woocommerce_proceed_to_checkout', array($this, 'display_payment_request_button_separator_html'), 2);
179 179
 
180
-		add_action( 'woocommerce_checkout_before_customer_details', array( $this, 'display_payment_request_button_html' ), 1 );
181
-		add_action( 'woocommerce_checkout_before_customer_details', array( $this, 'display_payment_request_button_separator_html' ), 2 );
180
+		add_action('woocommerce_checkout_before_customer_details', array($this, 'display_payment_request_button_html'), 1);
181
+		add_action('woocommerce_checkout_before_customer_details', array($this, 'display_payment_request_button_separator_html'), 2);
182 182
 
183
-		add_action( 'wc_ajax_wc_stripe_get_cart_details', array( $this, 'ajax_get_cart_details' ) );
184
-		add_action( 'wc_ajax_wc_stripe_get_shipping_options', array( $this, 'ajax_get_shipping_options' ) );
185
-		add_action( 'wc_ajax_wc_stripe_update_shipping_method', array( $this, 'ajax_update_shipping_method' ) );
186
-		add_action( 'wc_ajax_wc_stripe_create_order', array( $this, 'ajax_create_order' ) );
187
-		add_action( 'wc_ajax_wc_stripe_add_to_cart', array( $this, 'ajax_add_to_cart' ) );
188
-		add_action( 'wc_ajax_wc_stripe_get_selected_product_data', array( $this, 'ajax_get_selected_product_data' ) );
189
-		add_action( 'wc_ajax_wc_stripe_clear_cart', array( $this, 'ajax_clear_cart' ) );
190
-		add_action( 'wc_ajax_wc_stripe_log_errors', array( $this, 'ajax_log_errors' ) );
183
+		add_action('wc_ajax_wc_stripe_get_cart_details', array($this, 'ajax_get_cart_details'));
184
+		add_action('wc_ajax_wc_stripe_get_shipping_options', array($this, 'ajax_get_shipping_options'));
185
+		add_action('wc_ajax_wc_stripe_update_shipping_method', array($this, 'ajax_update_shipping_method'));
186
+		add_action('wc_ajax_wc_stripe_create_order', array($this, 'ajax_create_order'));
187
+		add_action('wc_ajax_wc_stripe_add_to_cart', array($this, 'ajax_add_to_cart'));
188
+		add_action('wc_ajax_wc_stripe_get_selected_product_data', array($this, 'ajax_get_selected_product_data'));
189
+		add_action('wc_ajax_wc_stripe_clear_cart', array($this, 'ajax_clear_cart'));
190
+		add_action('wc_ajax_wc_stripe_log_errors', array($this, 'ajax_log_errors'));
191 191
 
192
-		add_filter( 'woocommerce_gateway_title', array( $this, 'filter_gateway_title' ), 10, 2 );
193
-		add_filter( 'woocommerce_validate_postcode', array( $this, 'postal_code_validation' ), 10, 3 );
192
+		add_filter('woocommerce_gateway_title', array($this, 'filter_gateway_title'), 10, 2);
193
+		add_filter('woocommerce_validate_postcode', array($this, 'postal_code_validation'), 10, 3);
194 194
 
195
-		add_action( 'woocommerce_checkout_order_processed', array( $this, 'add_order_meta' ), 10, 2 );
195
+		add_action('woocommerce_checkout_order_processed', array($this, 'add_order_meta'), 10, 2);
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_type() {
206
-		return isset( $this->stripe_settings['payment_request_button_type'] ) ? $this->stripe_settings['payment_request_button_type'] : 'default';
206
+		return isset($this->stripe_settings['payment_request_button_type']) ? $this->stripe_settings['payment_request_button_type'] : 'default';
207 207
 	}
208 208
 
209 209
 	/**
@@ -214,7 +214,7 @@  discard block
 block discarded – undo
214 214
 	 * @return string
215 215
 	 */
216 216
 	public function get_button_theme() {
217
-		return isset( $this->stripe_settings['payment_request_button_theme'] ) ? $this->stripe_settings['payment_request_button_theme'] : 'dark';
217
+		return isset($this->stripe_settings['payment_request_button_theme']) ? $this->stripe_settings['payment_request_button_theme'] : 'dark';
218 218
 	}
219 219
 
220 220
 	/**
@@ -225,7 +225,7 @@  discard block
 block discarded – undo
225 225
 	 * @return string
226 226
 	 */
227 227
 	public function get_button_height() {
228
-		return isset( $this->stripe_settings['payment_request_button_height'] ) ? str_replace( 'px', '', $this->stripe_settings['payment_request_button_height'] ) : '64';
228
+		return isset($this->stripe_settings['payment_request_button_height']) ? str_replace('px', '', $this->stripe_settings['payment_request_button_height']) : '64';
229 229
 	}
230 230
 
231 231
 	/**
@@ -235,40 +235,40 @@  discard block
 block discarded – undo
235 235
 	 * @version 4.0.0
236 236
 	 */
237 237
 	public function get_product_data() {
238
-		if ( ! is_product() ) {
238
+		if ( ! is_product()) {
239 239
 			return false;
240 240
 		}
241 241
 
242 242
 		global $post;
243 243
 
244
-		$product = wc_get_product( $post->ID );
244
+		$product = wc_get_product($post->ID);
245 245
 
246 246
 		$data  = array();
247 247
 		$items = array();
248 248
 
249 249
 		$items[] = array(
250 250
 			'label'  => WC_Stripe_Helper::is_pre_30() ? $product->name : $product->get_name(),
251
-			'amount' => WC_Stripe_Helper::get_stripe_amount( WC_Stripe_Helper::is_pre_30() ? $product->price : $product->get_price() ),
251
+			'amount' => WC_Stripe_Helper::get_stripe_amount(WC_Stripe_Helper::is_pre_30() ? $product->price : $product->get_price()),
252 252
 		);
253 253
 
254
-		if ( wc_tax_enabled() ) {
254
+		if (wc_tax_enabled()) {
255 255
 			$items[] = array(
256
-				'label'   => __( 'Tax', 'woocommerce-gateway-stripe' ),
256
+				'label'   => __('Tax', 'woocommerce-gateway-stripe'),
257 257
 				'amount'  => 0,
258 258
 				'pending' => true,
259 259
 			);
260 260
 		}
261 261
 
262
-		if ( wc_shipping_enabled() && $product->needs_shipping() ) {
262
+		if (wc_shipping_enabled() && $product->needs_shipping()) {
263 263
 			$items[] = array(
264
-				'label'   => __( 'Shipping', 'woocommerce-gateway-stripe' ),
264
+				'label'   => __('Shipping', 'woocommerce-gateway-stripe'),
265 265
 				'amount'  => 0,
266 266
 				'pending' => true,
267 267
 			);
268 268
 
269
-			$data['shippingOptions']  = array(
269
+			$data['shippingOptions'] = array(
270 270
 				'id'     => 'pending',
271
-				'label'  => __( 'Pending', 'woocommerce-gateway-stripe' ),
271
+				'label'  => __('Pending', 'woocommerce-gateway-stripe'),
272 272
 				'detail' => '',
273 273
 				'amount' => 0,
274 274
 			);
@@ -276,41 +276,41 @@  discard block
 block discarded – undo
276 276
 
277 277
 		$data['displayItems'] = $items;
278 278
 		$data['total'] = array(
279
-			'label'   => apply_filters( 'wc_stripe_payment_request_total_label', $this->total_label ),
280
-			'amount'  => WC_Stripe_Helper::get_stripe_amount( WC_Stripe_Helper::is_pre_30() ? $product->price : $product->get_price() ),
279
+			'label'   => apply_filters('wc_stripe_payment_request_total_label', $this->total_label),
280
+			'amount'  => WC_Stripe_Helper::get_stripe_amount(WC_Stripe_Helper::is_pre_30() ? $product->price : $product->get_price()),
281 281
 			'pending' => true,
282 282
 		);
283 283
 
284
-		$data['requestShipping'] = ( wc_shipping_enabled() && $product->needs_shipping() );
285
-		$data['currency']        = strtolower( get_woocommerce_currency() );
286
-		$data['country_code']    = substr( get_option( 'woocommerce_default_country' ), 0, 2 );
284
+		$data['requestShipping'] = (wc_shipping_enabled() && $product->needs_shipping());
285
+		$data['currency']        = strtolower(get_woocommerce_currency());
286
+		$data['country_code']    = substr(get_option('woocommerce_default_country'), 0, 2);
287 287
 
288
-		return apply_filters( 'wc_stripe_payment_request_product_data', $data, $product );
288
+		return apply_filters('wc_stripe_payment_request_product_data', $data, $product);
289 289
 	}
290 290
 
291 291
 	/**
292 292
 	 * Filters the gateway title to reflect Payment Request type
293 293
 	 *
294 294
 	 */
295
-	public function filter_gateway_title( $title, $id ) {
295
+	public function filter_gateway_title($title, $id) {
296 296
 		global $post;
297 297
 
298
-		if ( ! is_object( $post ) ) {
298
+		if ( ! is_object($post)) {
299 299
 			return $title;
300 300
 		}
301 301
 
302
-		if ( WC_Stripe_Helper::is_pre_30() ) {
303
-			$method_title = get_post_meta( $post->ID, '_payment_method_title', true );
302
+		if (WC_Stripe_Helper::is_pre_30()) {
303
+			$method_title = get_post_meta($post->ID, '_payment_method_title', true);
304 304
 		} else {
305
-			$order        = wc_get_order( $post->ID );
306
-			$method_title = is_object( $order ) ? $order->get_payment_method_title() : '';
305
+			$order        = wc_get_order($post->ID);
306
+			$method_title = is_object($order) ? $order->get_payment_method_title() : '';
307 307
 		}
308 308
 
309
-		if ( 'stripe' === $id && ! empty( $method_title ) && 'Apple Pay (Stripe)' === $method_title ) {
309
+		if ('stripe' === $id && ! empty($method_title) && 'Apple Pay (Stripe)' === $method_title) {
310 310
 			return $method_title;
311 311
 		}
312 312
 
313
-		if ( 'stripe' === $id && ! empty( $method_title ) && 'Chrome Payment Request (Stripe)' === $method_title ) {
313
+		if ('stripe' === $id && ! empty($method_title) && 'Chrome Payment Request (Stripe)' === $method_title) {
314 314
 			return $method_title;
315 315
 		}
316 316
 
@@ -323,16 +323,16 @@  discard block
 block discarded – undo
323 323
 	 * @since 3.1.4
324 324
 	 * @version 4.0.0
325 325
 	 */
326
-	public function postal_code_validation( $valid, $postcode, $country ) {
326
+	public function postal_code_validation($valid, $postcode, $country) {
327 327
 		$gateways = WC()->payment_gateways->get_available_payment_gateways();
328 328
 
329
-		if ( ! isset( $gateways['stripe'] ) ) {
329
+		if ( ! isset($gateways['stripe'])) {
330 330
 			return $valid;
331 331
 		}
332 332
 
333
-		$payment_request_type = isset( $_POST['payment_request_type'] ) ? wc_clean( $_POST['payment_request_type'] ) : '';
333
+		$payment_request_type = isset($_POST['payment_request_type']) ? wc_clean($_POST['payment_request_type']) : '';
334 334
 
335
-		if ( 'apple_pay' !== $payment_request_type ) {
335
+		if ('apple_pay' !== $payment_request_type) {
336 336
 			return $valid;
337 337
 		}
338 338
 
@@ -342,7 +342,7 @@  discard block
 block discarded – undo
342 342
 		 * the order and not let it go through. The remedy for now is just to remove this validation.
343 343
 		 * Note that this only works with shipping providers that don't validate full postal codes.
344 344
 		 */
345
-		if ( 'GB' === $country || 'CA' === $country ) {
345
+		if ('GB' === $country || 'CA' === $country) {
346 346
 			return true;
347 347
 		}
348 348
 
@@ -357,29 +357,29 @@  discard block
 block discarded – undo
357 357
 	 * @param int $order_id
358 358
 	 * @param array $posted_data The posted data from checkout form.
359 359
 	 */
360
-	public function add_order_meta( $order_id, $posted_data ) {
361
-		if ( empty( $_POST['payment_request_type'] ) ) {
360
+	public function add_order_meta($order_id, $posted_data) {
361
+		if (empty($_POST['payment_request_type'])) {
362 362
 			return;
363 363
 		}
364 364
 
365
-		$order = wc_get_order( $order_id );
365
+		$order = wc_get_order($order_id);
366 366
 
367
-		$payment_request_type = wc_clean( $_POST['payment_request_type'] );
367
+		$payment_request_type = wc_clean($_POST['payment_request_type']);
368 368
 
369
-		if ( 'apple_pay' === $payment_request_type ) {
370
-			if ( WC_Stripe_Helper::is_pre_30() ) {
371
-				update_post_meta( $order_id, '_payment_method_title', 'Apple Pay (Stripe)' );
369
+		if ('apple_pay' === $payment_request_type) {
370
+			if (WC_Stripe_Helper::is_pre_30()) {
371
+				update_post_meta($order_id, '_payment_method_title', 'Apple Pay (Stripe)');
372 372
 			} else {
373
-				$order->set_payment_method_title( 'Apple Pay (Stripe)' );
373
+				$order->set_payment_method_title('Apple Pay (Stripe)');
374 374
 				$order->save();
375 375
 			}
376 376
 		}
377 377
 
378
-		if ( 'payment_request_api' === $payment_request_type ) {
379
-			if ( WC_Stripe_Helper::is_pre_30() ) {
380
-				update_post_meta( $order_id, '_payment_method_title', 'Chrome Payment Request (Stripe)' );
378
+		if ('payment_request_api' === $payment_request_type) {
379
+			if (WC_Stripe_Helper::is_pre_30()) {
380
+				update_post_meta($order_id, '_payment_method_title', 'Chrome Payment Request (Stripe)');
381 381
 			} else {
382
-				$order->set_payment_method_title( 'Chrome Payment Request (Stripe)' );
382
+				$order->set_payment_method_title('Chrome Payment Request (Stripe)');
383 383
 				$order->save();
384 384
 			}
385 385
 		}
@@ -393,11 +393,11 @@  discard block
 block discarded – undo
393 393
 	 * @return array
394 394
 	 */
395 395
 	public function supported_product_types() {
396
-		return apply_filters( 'wc_stripe_payment_request_supported_types', array(
396
+		return apply_filters('wc_stripe_payment_request_supported_types', array(
397 397
 			'simple',
398 398
 			'variable',
399 399
 			'variation',
400
-		) );
400
+		));
401 401
 	}
402 402
 
403 403
 	/**
@@ -408,15 +408,15 @@  discard block
 block discarded – undo
408 408
 	 * @return bool
409 409
 	 */
410 410
 	public function allowed_items_in_cart() {
411
-		foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {
412
-			$_product = apply_filters( 'woocommerce_cart_item_product', $cart_item['data'], $cart_item, $cart_item_key );
411
+		foreach (WC()->cart->get_cart() as $cart_item_key => $cart_item) {
412
+			$_product = apply_filters('woocommerce_cart_item_product', $cart_item['data'], $cart_item, $cart_item_key);
413 413
 
414
-			if ( ! in_array( ( WC_Stripe_Helper::is_pre_30() ? $_product->product_type : $_product->get_type() ), $this->supported_product_types() ) ) {
414
+			if ( ! in_array((WC_Stripe_Helper::is_pre_30() ? $_product->product_type : $_product->get_type()), $this->supported_product_types())) {
415 415
 				return false;
416 416
 			}
417 417
 
418 418
 			// Pre Orders compatbility where we don't support charge upon release.
419
-			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() ) ) {
419
+			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())) {
420 420
 				return false;
421 421
 			}
422 422
 		}
@@ -432,82 +432,82 @@  discard block
 block discarded – undo
432 432
 	 */
433 433
 	public function scripts() {
434 434
 		// If keys are not set bail.
435
-		if ( ! $this->are_keys_set() ) {
436
-			WC_Stripe_Logger::log( 'Keys are not set correctly.' );
435
+		if ( ! $this->are_keys_set()) {
436
+			WC_Stripe_Logger::log('Keys are not set correctly.');
437 437
 			return;
438 438
 		}
439 439
 
440 440
 		// If no SSL bail.
441
-		if ( ! $this->testmode && ! is_ssl() ) {
442
-			WC_Stripe_Logger::log( 'Stripe requires SSL.' );
441
+		if ( ! $this->testmode && ! is_ssl()) {
442
+			WC_Stripe_Logger::log('Stripe requires SSL.');
443 443
 			return;
444 444
 		}
445 445
 
446
-		if ( ! is_product() && ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) ) {
446
+		if ( ! is_product() && ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order'])) {
447 447
 			return;
448 448
 		}
449 449
 
450
-		if ( is_product() ) {
450
+		if (is_product()) {
451 451
 			global $post;
452 452
 
453
-			$product = wc_get_product( $post->ID );
453
+			$product = wc_get_product($post->ID);
454 454
 
455
-			if ( ! is_object( $product ) || ! in_array( ( WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type() ), $this->supported_product_types() ) ) {
455
+			if ( ! is_object($product) || ! in_array((WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type()), $this->supported_product_types())) {
456 456
 				return;
457 457
 			}
458 458
 
459
-			if ( apply_filters( 'wc_stripe_hide_payment_request_on_product_page', false ) ) {
459
+			if (apply_filters('wc_stripe_hide_payment_request_on_product_page', false)) {
460 460
 				return;
461 461
 			}
462 462
 		}
463 463
 
464
-		$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
464
+		$suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';
465 465
 
466
-		wp_register_script( 'stripe', 'https://js.stripe.com/v3/', '', '3.0', true );
467
-		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 );
466
+		wp_register_script('stripe', 'https://js.stripe.com/v3/', '', '3.0', true);
467
+		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);
468 468
 
469 469
 		wp_localize_script(
470 470
 			'wc_stripe_payment_request',
471 471
 			'wc_stripe_payment_request_params',
472 472
 			array(
473
-				'ajax_url' => WC_AJAX::get_endpoint( '%%endpoint%%' ),
473
+				'ajax_url' => WC_AJAX::get_endpoint('%%endpoint%%'),
474 474
 				'stripe'   => array(
475 475
 					'key'                => $this->publishable_key,
476
-					'allow_prepaid_card' => apply_filters( 'wc_stripe_allow_prepaid_card', true ) ? 'yes' : 'no',
476
+					'allow_prepaid_card' => apply_filters('wc_stripe_allow_prepaid_card', true) ? 'yes' : 'no',
477 477
 				),
478 478
 				'nonce'    => array(
479
-					'payment'                        => wp_create_nonce( 'wc-stripe-payment-request' ),
480
-					'shipping'                       => wp_create_nonce( 'wc-stripe-payment-request-shipping' ),
481
-					'update_shipping'                => wp_create_nonce( 'wc-stripe-update-shipping-method' ),
482
-					'checkout'                       => wp_create_nonce( 'woocommerce-process_checkout' ),
483
-					'add_to_cart'                    => wp_create_nonce( 'wc-stripe-add-to-cart' ),
484
-					'get_selected_product_data'      => wp_create_nonce( 'wc-stripe-get-selected-product-data' ),
485
-					'log_errors'                     => wp_create_nonce( 'wc-stripe-log-errors' ),
486
-					'clear_cart'                     => wp_create_nonce( 'wc-stripe-clear-cart' ),
479
+					'payment'                        => wp_create_nonce('wc-stripe-payment-request'),
480
+					'shipping'                       => wp_create_nonce('wc-stripe-payment-request-shipping'),
481
+					'update_shipping'                => wp_create_nonce('wc-stripe-update-shipping-method'),
482
+					'checkout'                       => wp_create_nonce('woocommerce-process_checkout'),
483
+					'add_to_cart'                    => wp_create_nonce('wc-stripe-add-to-cart'),
484
+					'get_selected_product_data'      => wp_create_nonce('wc-stripe-get-selected-product-data'),
485
+					'log_errors'                     => wp_create_nonce('wc-stripe-log-errors'),
486
+					'clear_cart'                     => wp_create_nonce('wc-stripe-clear-cart'),
487 487
 				),
488 488
 				'i18n'     => array(
489
-					'no_prepaid_card'  => __( 'Sorry, we\'re not accepting prepaid cards at this time.', 'woocommerce-gateway-stripe' ),
489
+					'no_prepaid_card'  => __('Sorry, we\'re not accepting prepaid cards at this time.', 'woocommerce-gateway-stripe'),
490 490
 					/* translators: Do not translate the [option] placeholder */
491
-					'unknown_shipping' => __( 'Unknown shipping option "[option]".', 'woocommerce-gateway-stripe' ),
491
+					'unknown_shipping' => __('Unknown shipping option "[option]".', 'woocommerce-gateway-stripe'),
492 492
 				),
493 493
 				'checkout' => array(
494 494
 					'url'            => wc_get_checkout_url(),
495
-					'currency_code'  => strtolower( get_woocommerce_currency() ),
496
-					'country_code'   => substr( get_option( 'woocommerce_default_country' ), 0, 2 ),
495
+					'currency_code'  => strtolower(get_woocommerce_currency()),
496
+					'country_code'   => substr(get_option('woocommerce_default_country'), 0, 2),
497 497
 					'needs_shipping' => WC()->cart->needs_shipping() ? 'yes' : 'no',
498 498
 				),
499 499
 				'button' => array(
500 500
 					'type'   => $this->get_button_type(),
501 501
 					'theme'  => $this->get_button_theme(),
502 502
 					'height' => $this->get_button_height(),
503
-					'locale' => substr( get_locale(), 0, 2 ), // Default format is en_US.
503
+					'locale' => substr(get_locale(), 0, 2), // Default format is en_US.
504 504
 				),
505 505
 				'is_product_page' => is_product(),
506 506
 				'product'         => $this->get_product_data(),
507 507
 			)
508 508
 		);
509 509
 
510
-		wp_enqueue_script( 'wc_stripe_payment_request' );
510
+		wp_enqueue_script('wc_stripe_payment_request');
511 511
 	}
512 512
 
513 513
 	/**
@@ -519,39 +519,39 @@  discard block
 block discarded – undo
519 519
 	public function display_payment_request_button_html() {
520 520
 		$gateways = WC()->payment_gateways->get_available_payment_gateways();
521 521
 
522
-		if ( ! isset( $gateways['stripe'] ) ) {
522
+		if ( ! isset($gateways['stripe'])) {
523 523
 			return;
524 524
 		}
525 525
 
526
-		if ( ! is_cart() && ! is_checkout() && ! is_product() && ! isset( $_GET['pay_for_order'] ) ) {
526
+		if ( ! is_cart() && ! is_checkout() && ! is_product() && ! isset($_GET['pay_for_order'])) {
527 527
 			return;
528 528
 		}
529 529
 
530
-		if ( is_product() && apply_filters( 'wc_stripe_hide_payment_request_on_product_page', false ) ) {
530
+		if (is_product() && apply_filters('wc_stripe_hide_payment_request_on_product_page', false)) {
531 531
 			return;
532 532
 		}
533 533
 
534
-		if ( is_checkout() && ! apply_filters( 'wc_stripe_show_payment_request_on_checkout', false ) ) {
534
+		if (is_checkout() && ! apply_filters('wc_stripe_show_payment_request_on_checkout', false)) {
535 535
 			return;
536 536
 		}
537 537
 
538
-		if ( is_product() ) {
538
+		if (is_product()) {
539 539
 			global $post;
540 540
 
541
-			$product = wc_get_product( $post->ID );
541
+			$product = wc_get_product($post->ID);
542 542
 
543
-			if ( ! is_object( $product ) || ! in_array( ( WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type() ), $this->supported_product_types() ) ) {
543
+			if ( ! is_object($product) || ! in_array((WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type()), $this->supported_product_types())) {
544 544
 				return;
545 545
 			}
546 546
 
547 547
 			// Pre Orders charge upon release not supported.
548
-			if ( class_exists( 'WC_Pre_Orders_Order' ) && WC_Pre_Orders_Product::product_is_charged_upon_release( $product ) ) {
549
-				WC_Stripe_Logger::log( 'Pre Order charge upon release is not supported. ( Payment Request button disabled )' );
548
+			if (class_exists('WC_Pre_Orders_Order') && WC_Pre_Orders_Product::product_is_charged_upon_release($product)) {
549
+				WC_Stripe_Logger::log('Pre Order charge upon release is not supported. ( Payment Request button disabled )');
550 550
 				return;
551 551
 			}
552 552
 		} else {
553
-			if ( ! $this->allowed_items_in_cart() ) {
554
-				WC_Stripe_Logger::log( 'Items in the cart has unsupported product type ( Payment Request button disabled )' );
553
+			if ( ! $this->allowed_items_in_cart()) {
554
+				WC_Stripe_Logger::log('Items in the cart has unsupported product type ( Payment Request button disabled )');
555 555
 				return;
556 556
 			}
557 557
 		}
@@ -573,44 +573,44 @@  discard block
 block discarded – undo
573 573
 	public function display_payment_request_button_separator_html() {
574 574
 		$gateways = WC()->payment_gateways->get_available_payment_gateways();
575 575
 
576
-		if ( ! isset( $gateways['stripe'] ) ) {
576
+		if ( ! isset($gateways['stripe'])) {
577 577
 			return;
578 578
 		}
579 579
 
580
-		if ( ! is_cart() && ! is_checkout() && ! is_product() && ! isset( $_GET['pay_for_order'] ) ) {
580
+		if ( ! is_cart() && ! is_checkout() && ! is_product() && ! isset($_GET['pay_for_order'])) {
581 581
 			return;
582 582
 		}
583 583
 
584
-		if ( is_product() && apply_filters( 'wc_stripe_hide_payment_request_on_product_page', false ) ) {
584
+		if (is_product() && apply_filters('wc_stripe_hide_payment_request_on_product_page', false)) {
585 585
 			return;
586 586
 		}
587 587
 
588
-		if ( is_checkout() && ! apply_filters( 'wc_stripe_show_payment_request_on_checkout', false ) ) {
588
+		if (is_checkout() && ! apply_filters('wc_stripe_show_payment_request_on_checkout', false)) {
589 589
 			return;
590 590
 		}
591 591
 
592
-		if ( is_product() ) {
592
+		if (is_product()) {
593 593
 			global $post;
594 594
 
595
-			$product = wc_get_product( $post->ID );
595
+			$product = wc_get_product($post->ID);
596 596
 
597
-			if ( ! is_object( $product ) || ! in_array( ( WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type() ), $this->supported_product_types() ) ) {
597
+			if ( ! is_object($product) || ! in_array((WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type()), $this->supported_product_types())) {
598 598
 				return;
599 599
 			}
600 600
 
601 601
 			// Pre Orders charge upon release not supported.
602
-			if ( class_exists( 'WC_Pre_Orders_Order' ) && WC_Pre_Orders_Product::product_is_charged_upon_release( $product ) ) {
603
-				WC_Stripe_Logger::log( 'Pre Order charge upon release is not supported. ( Payment Request button disabled )' );
602
+			if (class_exists('WC_Pre_Orders_Order') && WC_Pre_Orders_Product::product_is_charged_upon_release($product)) {
603
+				WC_Stripe_Logger::log('Pre Order charge upon release is not supported. ( Payment Request button disabled )');
604 604
 				return;
605 605
 			}
606 606
 		} else {
607
-			if ( ! $this->allowed_items_in_cart() ) {
608
-				WC_Stripe_Logger::log( 'Items in the cart has unsupported product type ( Payment Request button disabled )' );
607
+			if ( ! $this->allowed_items_in_cart()) {
608
+				WC_Stripe_Logger::log('Items in the cart has unsupported product type ( Payment Request button disabled )');
609 609
 				return;
610 610
 			}
611 611
 		}
612 612
 		?>
613
-		<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>
613
+		<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>
614 614
 		<?php
615 615
 	}
616 616
 
@@ -621,11 +621,11 @@  discard block
 block discarded – undo
621 621
 	 * @version 4.0.0
622 622
 	 */
623 623
 	public function ajax_log_errors() {
624
-		check_ajax_referer( 'wc-stripe-log-errors', 'security' );
624
+		check_ajax_referer('wc-stripe-log-errors', 'security');
625 625
 
626
-		$errors = wc_clean( stripslashes( $_POST['errors'] ) );
626
+		$errors = wc_clean(stripslashes($_POST['errors']));
627 627
 
628
-		WC_Stripe_Logger::log( $errors );
628
+		WC_Stripe_Logger::log($errors);
629 629
 
630 630
 		exit;
631 631
 	}
@@ -637,7 +637,7 @@  discard block
 block discarded – undo
637 637
 	 * @version 4.0.0
638 638
 	 */
639 639
 	public function ajax_clear_cart() {
640
-		check_ajax_referer( 'wc-stripe-clear-cart', 'security' );
640
+		check_ajax_referer('wc-stripe-clear-cart', 'security');
641 641
 
642 642
 		WC()->cart->empty_cart();
643 643
 		exit;
@@ -647,10 +647,10 @@  discard block
 block discarded – undo
647 647
 	 * Get cart details.
648 648
 	 */
649 649
 	public function ajax_get_cart_details() {
650
-		check_ajax_referer( 'wc-stripe-payment-request', 'security' );
650
+		check_ajax_referer('wc-stripe-payment-request', 'security');
651 651
 
652
-		if ( ! defined( 'WOOCOMMERCE_CART' ) ) {
653
-			define( 'WOOCOMMERCE_CART', true );
652
+		if ( ! defined('WOOCOMMERCE_CART')) {
653
+			define('WOOCOMMERCE_CART', true);
654 654
 		}
655 655
 
656 656
 		WC()->cart->calculate_totals();
@@ -661,14 +661,14 @@  discard block
 block discarded – undo
661 661
 		$data = array(
662 662
 			'shipping_required' => WC()->cart->needs_shipping(),
663 663
 			'order_data'        => array(
664
-				'currency'        => strtolower( $currency ),
665
-				'country_code'    => substr( get_option( 'woocommerce_default_country' ), 0, 2 ),
664
+				'currency'        => strtolower($currency),
665
+				'country_code'    => substr(get_option('woocommerce_default_country'), 0, 2),
666 666
 			),
667 667
 		);
668 668
 
669 669
 		$data['order_data'] += $this->build_display_items();
670 670
 
671
-		wp_send_json( $data );
671
+		wp_send_json($data);
672 672
 	}
673 673
 
674 674
 	/**
@@ -679,47 +679,47 @@  discard block
 block discarded – undo
679 679
 	 * @see WC_Shipping::get_packages().
680 680
 	 */
681 681
 	public function ajax_get_shipping_options() {
682
-		check_ajax_referer( 'wc-stripe-payment-request-shipping', 'security' );
682
+		check_ajax_referer('wc-stripe-payment-request-shipping', 'security');
683 683
 
684 684
 		try {
685 685
 			// Set the shipping package.
686
-			$posted = filter_input_array( INPUT_POST, array(
686
+			$posted = filter_input_array(INPUT_POST, array(
687 687
 				'country'   => FILTER_SANITIZE_STRING,
688 688
 				'state'     => FILTER_SANITIZE_STRING,
689 689
 				'postcode'  => FILTER_SANITIZE_STRING,
690 690
 				'city'      => FILTER_SANITIZE_STRING,
691 691
 				'address'   => FILTER_SANITIZE_STRING,
692 692
 				'address_2' => FILTER_SANITIZE_STRING,
693
-			) );
693
+			));
694 694
 
695
-			$this->calculate_shipping( $posted );
695
+			$this->calculate_shipping($posted);
696 696
 
697 697
 			// Set the shipping options.
698 698
 			$data     = array();
699 699
 			$packages = WC()->shipping->get_packages();
700 700
 
701
-			if ( ! empty( $packages ) && WC()->customer->has_calculated_shipping() ) {
702
-				foreach ( $packages as $package_key => $package ) {
703
-					if ( empty( $package['rates'] ) ) {
704
-						throw new Exception( __( 'Unable to find shipping method for address.', 'woocommerce-gateway-stripe' ) );
701
+			if ( ! empty($packages) && WC()->customer->has_calculated_shipping()) {
702
+				foreach ($packages as $package_key => $package) {
703
+					if (empty($package['rates'])) {
704
+						throw new Exception(__('Unable to find shipping method for address.', 'woocommerce-gateway-stripe'));
705 705
 					}
706 706
 
707
-					foreach ( $package['rates'] as $key => $rate ) {
707
+					foreach ($package['rates'] as $key => $rate) {
708 708
 						$data['shipping_options'][] = array(
709 709
 							'id'       => $rate->id,
710 710
 							'label'    => $rate->label,
711 711
 							'detail'   => '',
712
-							'amount'   => WC_Stripe_Helper::get_stripe_amount( $rate->cost ),
712
+							'amount'   => WC_Stripe_Helper::get_stripe_amount($rate->cost),
713 713
 						);
714 714
 					}
715 715
 				}
716 716
 			} else {
717
-				throw new Exception( __( 'Unable to find shipping method for address.', 'woocommerce-gateway-stripe' ) );
717
+				throw new Exception(__('Unable to find shipping method for address.', 'woocommerce-gateway-stripe'));
718 718
 			}
719 719
 
720
-			if ( isset( $data[0] ) ) {
720
+			if (isset($data[0])) {
721 721
 				// Auto select the first shipping method.
722
-				WC()->session->set( 'chosen_shipping_methods', array( $data[0]['id'] ) );
722
+				WC()->session->set('chosen_shipping_methods', array($data[0]['id']));
723 723
 			}
724 724
 
725 725
 			WC()->cart->calculate_totals();
@@ -727,12 +727,12 @@  discard block
 block discarded – undo
727 727
 			$data += $this->build_display_items();
728 728
 			$data['result'] = 'success';
729 729
 
730
-			wp_send_json( $data );
731
-		} catch ( Exception $e ) {
730
+			wp_send_json($data);
731
+		} catch (Exception $e) {
732 732
 			$data += $this->build_display_items();
733 733
 			$data['result'] = 'invalid_shipping_address';
734 734
 
735
-			wp_send_json( $data );
735
+			wp_send_json($data);
736 736
 		}
737 737
 	}
738 738
 
@@ -740,22 +740,22 @@  discard block
 block discarded – undo
740 740
 	 * Update shipping method.
741 741
 	 */
742 742
 	public function ajax_update_shipping_method() {
743
-		check_ajax_referer( 'wc-stripe-update-shipping-method', 'security' );
743
+		check_ajax_referer('wc-stripe-update-shipping-method', 'security');
744 744
 
745
-		if ( ! defined( 'WOOCOMMERCE_CART' ) ) {
746
-			define( 'WOOCOMMERCE_CART', true );
745
+		if ( ! defined('WOOCOMMERCE_CART')) {
746
+			define('WOOCOMMERCE_CART', true);
747 747
 		}
748 748
 
749
-		$chosen_shipping_methods = WC()->session->get( 'chosen_shipping_methods' );
750
-		$shipping_method         = filter_input( INPUT_POST, 'shipping_method', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY );
749
+		$chosen_shipping_methods = WC()->session->get('chosen_shipping_methods');
750
+		$shipping_method         = filter_input(INPUT_POST, 'shipping_method', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY);
751 751
 
752
-		if ( is_array( $shipping_method ) ) {
753
-			foreach ( $shipping_method as $i => $value ) {
754
-				$chosen_shipping_methods[ $i ] = wc_clean( $value );
752
+		if (is_array($shipping_method)) {
753
+			foreach ($shipping_method as $i => $value) {
754
+				$chosen_shipping_methods[$i] = wc_clean($value);
755 755
 			}
756 756
 		}
757 757
 
758
-		WC()->session->set( 'chosen_shipping_methods', $chosen_shipping_methods );
758
+		WC()->session->set('chosen_shipping_methods', $chosen_shipping_methods);
759 759
 
760 760
 		WC()->cart->calculate_totals();
761 761
 
@@ -763,7 +763,7 @@  discard block
 block discarded – undo
763 763
 		$data += $this->build_display_items();
764 764
 		$data['result'] = 'success';
765 765
 
766
-		wp_send_json( $data );
766
+		wp_send_json($data);
767 767
 	}
768 768
 
769 769
 	/**
@@ -774,31 +774,31 @@  discard block
 block discarded – undo
774 774
 	 * @return array $data
775 775
 	 */
776 776
 	public function ajax_get_selected_product_data() {
777
-		check_ajax_referer( 'wc-stripe-get-selected-product-data', 'security' );
777
+		check_ajax_referer('wc-stripe-get-selected-product-data', 'security');
778 778
 
779
-		$product_id = absint( $_POST['product_id'] );
780
-		$qty = ! isset( $_POST['qty'] ) ? 1 : absint( $_POST['qty'] );
779
+		$product_id = absint($_POST['product_id']);
780
+		$qty = ! isset($_POST['qty']) ? 1 : absint($_POST['qty']);
781 781
 
782
-		$product = wc_get_product( $product_id );
782
+		$product = wc_get_product($product_id);
783 783
 
784
-		if ( 'variable' === ( WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type() ) && isset( $_POST['attributes'] ) ) {
785
-			$attributes = array_map( 'wc_clean', $_POST['attributes'] );
784
+		if ('variable' === (WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type()) && isset($_POST['attributes'])) {
785
+			$attributes = array_map('wc_clean', $_POST['attributes']);
786 786
 
787
-			if ( WC_Stripe_Helper::is_pre_30() ) {
788
-				$variation_id = $product->get_matching_variation( $attributes );
787
+			if (WC_Stripe_Helper::is_pre_30()) {
788
+				$variation_id = $product->get_matching_variation($attributes);
789 789
 			} else {
790
-				$data_store = WC_Data_Store::load( 'product' );
791
-				$variation_id = $data_store->find_matching_product_variation( $product, $attributes );
790
+				$data_store = WC_Data_Store::load('product');
791
+				$variation_id = $data_store->find_matching_product_variation($product, $attributes);
792 792
 			}
793 793
 
794
-			if ( ! empty( $variation_id ) ) {
795
-				$product = wc_get_product( $variation_id );
794
+			if ( ! empty($variation_id)) {
795
+				$product = wc_get_product($variation_id);
796 796
 			}
797
-		} elseif ( 'simple' === ( WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type() ) ) {
798
-			$product = wc_get_product( $product_id );
797
+		} elseif ('simple' === (WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type())) {
798
+			$product = wc_get_product($product_id);
799 799
 		}
800 800
 
801
-		$total = $qty * ( WC_Stripe_Helper::is_pre_30() ? $product->price : $product->get_price() );
801
+		$total = $qty * (WC_Stripe_Helper::is_pre_30() ? $product->price : $product->get_price());
802 802
 
803 803
 		$quantity_label = 1 < $qty ? ' (x' . $qty . ')' : '';
804 804
 
@@ -806,28 +806,28 @@  discard block
 block discarded – undo
806 806
 		$items = array();
807 807
 
808 808
 		$items[] = array(
809
-			'label'  => ( WC_Stripe_Helper::is_pre_30() ? $product->name : $product->get_name() ) . $quantity_label,
810
-			'amount' => WC_Stripe_Helper::get_stripe_amount( $total ),
809
+			'label'  => (WC_Stripe_Helper::is_pre_30() ? $product->name : $product->get_name()) . $quantity_label,
810
+			'amount' => WC_Stripe_Helper::get_stripe_amount($total),
811 811
 		);
812 812
 
813
-		if ( wc_tax_enabled() ) {
813
+		if (wc_tax_enabled()) {
814 814
 			$items[] = array(
815
-				'label'   => __( 'Tax', 'woocommerce-gateway-stripe' ),
815
+				'label'   => __('Tax', 'woocommerce-gateway-stripe'),
816 816
 				'amount'  => 0,
817 817
 				'pending' => true,
818 818
 			);
819 819
 		}
820 820
 
821
-		if ( wc_shipping_enabled() && $product->needs_shipping() ) {
821
+		if (wc_shipping_enabled() && $product->needs_shipping()) {
822 822
 			$items[] = array(
823
-				'label'   => __( 'Shipping', 'woocommerce-gateway-stripe' ),
823
+				'label'   => __('Shipping', 'woocommerce-gateway-stripe'),
824 824
 				'amount'  => 0,
825 825
 				'pending' => true,
826 826
 			);
827 827
 
828
-			$data['shippingOptions']  = array(
828
+			$data['shippingOptions'] = array(
829 829
 				'id'     => 'pending',
830
-				'label'  => __( 'Pending', 'woocommerce-gateway-stripe' ),
830
+				'label'  => __('Pending', 'woocommerce-gateway-stripe'),
831 831
 				'detail' => '',
832 832
 				'amount' => 0,
833 833
 			);
@@ -836,15 +836,15 @@  discard block
 block discarded – undo
836 836
 		$data['displayItems'] = $items;
837 837
 		$data['total'] = array(
838 838
 			'label'   => $this->total_label,
839
-			'amount'  => WC_Stripe_Helper::get_stripe_amount( $total ),
839
+			'amount'  => WC_Stripe_Helper::get_stripe_amount($total),
840 840
 			'pending' => true,
841 841
 		);
842 842
 
843
-		$data['requestShipping'] = ( wc_shipping_enabled() && $product->needs_shipping() );
844
-		$data['currency']        = strtolower( get_woocommerce_currency() );
845
-		$data['country_code']    = substr( get_option( 'woocommerce_default_country' ), 0, 2 );
843
+		$data['requestShipping'] = (wc_shipping_enabled() && $product->needs_shipping());
844
+		$data['currency']        = strtolower(get_woocommerce_currency());
845
+		$data['country_code']    = substr(get_option('woocommerce_default_country'), 0, 2);
846 846
 
847
-		wp_send_json( $data );
847
+		wp_send_json($data);
848 848
 	}
849 849
 
850 850
 	/**
@@ -855,37 +855,37 @@  discard block
 block discarded – undo
855 855
 	 * @return array $data
856 856
 	 */
857 857
 	public function ajax_add_to_cart() {
858
-		check_ajax_referer( 'wc-stripe-add-to-cart', 'security' );
858
+		check_ajax_referer('wc-stripe-add-to-cart', 'security');
859 859
 
860
-		if ( ! defined( 'WOOCOMMERCE_CART' ) ) {
861
-			define( 'WOOCOMMERCE_CART', true );
860
+		if ( ! defined('WOOCOMMERCE_CART')) {
861
+			define('WOOCOMMERCE_CART', true);
862 862
 		}
863 863
 
864 864
 		WC()->shipping->reset_shipping();
865 865
 
866
-		$product_id = absint( $_POST['product_id'] );
867
-		$qty = ! isset( $_POST['qty'] ) ? 1 : absint( $_POST['qty'] );
866
+		$product_id = absint($_POST['product_id']);
867
+		$qty = ! isset($_POST['qty']) ? 1 : absint($_POST['qty']);
868 868
 
869
-		$product = wc_get_product( $product_id );
869
+		$product = wc_get_product($product_id);
870 870
 
871 871
 		// First empty the cart to prevent wrong calculation.
872 872
 		WC()->cart->empty_cart();
873 873
 
874
-		if ( 'variable' === ( WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type() ) && isset( $_POST['attributes'] ) ) {
875
-			$attributes = array_map( 'wc_clean', $_POST['attributes'] );
874
+		if ('variable' === (WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type()) && isset($_POST['attributes'])) {
875
+			$attributes = array_map('wc_clean', $_POST['attributes']);
876 876
 
877
-			if ( WC_Stripe_Helper::is_pre_30() ) {
878
-				$variation_id = $product->get_matching_variation( $attributes );
877
+			if (WC_Stripe_Helper::is_pre_30()) {
878
+				$variation_id = $product->get_matching_variation($attributes);
879 879
 			} else {
880
-				$data_store = WC_Data_Store::load( 'product' );
881
-				$variation_id = $data_store->find_matching_product_variation( $product, $attributes );
880
+				$data_store = WC_Data_Store::load('product');
881
+				$variation_id = $data_store->find_matching_product_variation($product, $attributes);
882 882
 			}
883 883
 
884
-			WC()->cart->add_to_cart( $product->get_id(), $qty, $variation_id, $attributes );
884
+			WC()->cart->add_to_cart($product->get_id(), $qty, $variation_id, $attributes);
885 885
 		}
886 886
 
887
-		if ( 'simple' === ( WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type() ) ) {
888
-			WC()->cart->add_to_cart( $product->get_id(), $qty );
887
+		if ('simple' === (WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type())) {
888
+			WC()->cart->add_to_cart($product->get_id(), $qty);
889 889
 		}
890 890
 
891 891
 		WC()->cart->calculate_totals();
@@ -894,7 +894,7 @@  discard block
 block discarded – undo
894 894
 		$data += $this->build_display_items();
895 895
 		$data['result'] = 'success';
896 896
 
897
-		wp_send_json( $data );
897
+		wp_send_json($data);
898 898
 	}
899 899
 
900 900
 	/**
@@ -907,31 +907,31 @@  discard block
 block discarded – undo
907 907
 	 * @version 4.0.0
908 908
 	 */
909 909
 	public function normalize_state() {
910
-		$billing_country  = ! empty( $_POST['billing_country'] ) ? wc_clean( $_POST['billing_country'] ) : '';
911
-		$shipping_country = ! empty( $_POST['shipping_country'] ) ? wc_clean( $_POST['shipping_country'] ) : '';
912
-		$billing_state    = ! empty( $_POST['billing_state'] ) ? wc_clean( $_POST['billing_state'] ) : '';
913
-		$shipping_state   = ! empty( $_POST['shipping_state'] ) ? wc_clean( $_POST['shipping_state'] ) : '';
910
+		$billing_country  = ! empty($_POST['billing_country']) ? wc_clean($_POST['billing_country']) : '';
911
+		$shipping_country = ! empty($_POST['shipping_country']) ? wc_clean($_POST['shipping_country']) : '';
912
+		$billing_state    = ! empty($_POST['billing_state']) ? wc_clean($_POST['billing_state']) : '';
913
+		$shipping_state   = ! empty($_POST['shipping_state']) ? wc_clean($_POST['shipping_state']) : '';
914 914
 
915
-		if ( $billing_state && $billing_country ) {
916
-			$valid_states = WC()->countries->get_states( $billing_country );
915
+		if ($billing_state && $billing_country) {
916
+			$valid_states = WC()->countries->get_states($billing_country);
917 917
 
918 918
 			// Valid states found for country.
919
-			if ( ! empty( $valid_states ) && is_array( $valid_states ) && sizeof( $valid_states ) > 0 ) {
920
-				foreach ( $valid_states as $state_abbr => $state ) {
921
-					if ( preg_match( '/' . preg_quote( $state ) . '/i', $billing_state ) ) {
919
+			if ( ! empty($valid_states) && is_array($valid_states) && sizeof($valid_states) > 0) {
920
+				foreach ($valid_states as $state_abbr => $state) {
921
+					if (preg_match('/' . preg_quote($state) . '/i', $billing_state)) {
922 922
 						$_POST['billing_state'] = $state_abbr;
923 923
 					}
924 924
 				}
925 925
 			}
926 926
 		}
927 927
 
928
-		if ( $shipping_state && $shipping_country ) {
929
-			$valid_states = WC()->countries->get_states( $shipping_country );
928
+		if ($shipping_state && $shipping_country) {
929
+			$valid_states = WC()->countries->get_states($shipping_country);
930 930
 
931 931
 			// Valid states found for country.
932
-			if ( ! empty( $valid_states ) && is_array( $valid_states ) && sizeof( $valid_states ) > 0 ) {
933
-				foreach ( $valid_states as $state_abbr => $state ) {
934
-					if ( preg_match( '/' . preg_quote( $state ) . '/i', $shipping_state ) ) {
932
+			if ( ! empty($valid_states) && is_array($valid_states) && sizeof($valid_states) > 0) {
933
+				foreach ($valid_states as $state_abbr => $state) {
934
+					if (preg_match('/' . preg_quote($state) . '/i', $shipping_state)) {
935 935
 						$_POST['shipping_state'] = $state_abbr;
936 936
 					}
937 937
 				}
@@ -946,19 +946,19 @@  discard block
 block discarded – undo
946 946
 	 * @version 4.0.0
947 947
 	 */
948 948
 	public function ajax_create_order() {
949
-		if ( WC()->cart->is_empty() ) {
950
-			wp_send_json_error( __( 'Empty cart', 'woocommerce-gateway-stripe' ) );
949
+		if (WC()->cart->is_empty()) {
950
+			wp_send_json_error(__('Empty cart', 'woocommerce-gateway-stripe'));
951 951
 		}
952 952
 
953
-		if ( ! defined( 'WOOCOMMERCE_CHECKOUT' ) ) {
954
-			define( 'WOOCOMMERCE_CHECKOUT', true );
953
+		if ( ! defined('WOOCOMMERCE_CHECKOUT')) {
954
+			define('WOOCOMMERCE_CHECKOUT', true);
955 955
 		}
956 956
 
957 957
 		$this->normalize_state();
958 958
 
959 959
 		WC()->checkout()->process_checkout();
960 960
 
961
-		die( 0 );
961
+		die(0);
962 962
 	}
963 963
 
964 964
 	/**
@@ -968,7 +968,7 @@  discard block
 block discarded – undo
968 968
 	 * @version 4.0.0
969 969
 	 * @param array $address
970 970
 	 */
971
-	protected function calculate_shipping( $address = array() ) {
971
+	protected function calculate_shipping($address = array()) {
972 972
 		global $states;
973 973
 
974 974
 		$country   = $address['country'];
@@ -985,28 +985,28 @@  discard block
 block discarded – undo
985 985
 		 * In some versions of Chrome, state can be a full name. So we need
986 986
 		 * to convert that to abbreviation as WC is expecting that.
987 987
 		 */
988
-		if ( 2 < strlen( $state ) ) {
989
-			$state = array_search( ucfirst( strtolower( $state ) ), $states[ $country ] );
988
+		if (2 < strlen($state)) {
989
+			$state = array_search(ucfirst(strtolower($state)), $states[$country]);
990 990
 		}
991 991
 
992 992
 		WC()->shipping->reset_shipping();
993 993
 
994
-		if ( $postcode && WC_Validation::is_postcode( $postcode, $country ) ) {
995
-			$postcode = wc_format_postcode( $postcode, $country );
994
+		if ($postcode && WC_Validation::is_postcode($postcode, $country)) {
995
+			$postcode = wc_format_postcode($postcode, $country);
996 996
 		}
997 997
 
998
-		if ( $country ) {
999
-			WC()->customer->set_location( $country, $state, $postcode, $city );
1000
-			WC()->customer->set_shipping_location( $country, $state, $postcode, $city );
998
+		if ($country) {
999
+			WC()->customer->set_location($country, $state, $postcode, $city);
1000
+			WC()->customer->set_shipping_location($country, $state, $postcode, $city);
1001 1001
 		} else {
1002 1002
 			WC_Stripe_Helper::is_pre_30() ? WC()->customer->set_to_base() : WC()->customer->set_billing_address_to_base();
1003 1003
 			WC_Stripe_Helper::is_pre_30() ? WC()->customer->set_shipping_to_base() : WC()->customer->set_shipping_address_to_base();
1004 1004
 		}
1005 1005
 
1006
-		if ( WC_Stripe_Helper::is_pre_30() ) {
1007
-			WC()->customer->calculated_shipping( true );
1006
+		if (WC_Stripe_Helper::is_pre_30()) {
1007
+			WC()->customer->calculated_shipping(true);
1008 1008
 		} else {
1009
-			WC()->customer->set_calculated_shipping( true );
1009
+			WC()->customer->set_calculated_shipping(true);
1010 1010
 			WC()->customer->save();
1011 1011
 		}
1012 1012
 
@@ -1023,17 +1023,17 @@  discard block
 block discarded – undo
1023 1023
 		$packages[0]['destination']['address']   = $address_1;
1024 1024
 		$packages[0]['destination']['address_2'] = $address_2;
1025 1025
 
1026
-		foreach ( WC()->cart->get_cart() as $item ) {
1027
-			if ( $item['data']->needs_shipping() ) {
1028
-				if ( isset( $item['line_total'] ) ) {
1026
+		foreach (WC()->cart->get_cart() as $item) {
1027
+			if ($item['data']->needs_shipping()) {
1028
+				if (isset($item['line_total'])) {
1029 1029
 					$packages[0]['contents_cost'] += $item['line_total'];
1030 1030
 				}
1031 1031
 			}
1032 1032
 		}
1033 1033
 
1034
-		$packages = apply_filters( 'woocommerce_cart_shipping_packages', $packages );
1034
+		$packages = apply_filters('woocommerce_cart_shipping_packages', $packages);
1035 1035
 
1036
-		WC()->shipping->calculate_shipping( $packages );
1036
+		WC()->shipping->calculate_shipping($packages);
1037 1037
 	}
1038 1038
 
1039 1039
 	/**
@@ -1042,19 +1042,19 @@  discard block
 block discarded – undo
1042 1042
 	 * @since 3.1.0
1043 1043
 	 * @version 4.0.0
1044 1044
 	 */
1045
-	protected function build_shipping_methods( $shipping_methods ) {
1046
-		if ( empty( $shipping_methods ) ) {
1045
+	protected function build_shipping_methods($shipping_methods) {
1046
+		if (empty($shipping_methods)) {
1047 1047
 			return array();
1048 1048
 		}
1049 1049
 
1050 1050
 		$shipping = array();
1051 1051
 
1052
-		foreach ( $shipping_methods as $method ) {
1052
+		foreach ($shipping_methods as $method) {
1053 1053
 			$shipping[] = array(
1054 1054
 				'id'         => $method['id'],
1055 1055
 				'label'      => $method['label'],
1056 1056
 				'detail'     => '',
1057
-				'amount'     => WC_Stripe_Helper::get_stripe_amount( $method['amount']['value'] ),
1057
+				'amount'     => WC_Stripe_Helper::get_stripe_amount($method['amount']['value']),
1058 1058
 			);
1059 1059
 		}
1060 1060
 
@@ -1068,69 +1068,69 @@  discard block
 block discarded – undo
1068 1068
 	 * @version 4.0.0
1069 1069
 	 */
1070 1070
 	protected function build_display_items() {
1071
-		if ( ! defined( 'WOOCOMMERCE_CART' ) ) {
1072
-			define( 'WOOCOMMERCE_CART', true );
1071
+		if ( ! defined('WOOCOMMERCE_CART')) {
1072
+			define('WOOCOMMERCE_CART', true);
1073 1073
 		}
1074 1074
 
1075 1075
 		$items    = array();
1076 1076
 		$subtotal = 0;
1077 1077
 
1078 1078
 		// Default show only subtotal instead of itemization.
1079
-		if ( ! apply_filters( 'wc_stripe_payment_request_hide_itemization', true ) ) {
1080
-			foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {
1079
+		if ( ! apply_filters('wc_stripe_payment_request_hide_itemization', true)) {
1080
+			foreach (WC()->cart->get_cart() as $cart_item_key => $cart_item) {
1081 1081
 				$amount         = $cart_item['line_subtotal'];
1082
-				$subtotal       += $cart_item['line_subtotal'];
1082
+				$subtotal += $cart_item['line_subtotal'];
1083 1083
 				$quantity_label = 1 < $cart_item['quantity'] ? ' (x' . $cart_item['quantity'] . ')' : '';
1084 1084
 
1085 1085
 				$product_name = WC_Stripe_Helper::is_pre_30() ? $cart_item['data']->post->post_title : $cart_item['data']->get_name();
1086 1086
 
1087 1087
 				$item = array(
1088 1088
 					'label'  => $product_name . $quantity_label,
1089
-					'amount' => WC_Stripe_Helper::get_stripe_amount( $amount ),
1089
+					'amount' => WC_Stripe_Helper::get_stripe_amount($amount),
1090 1090
 				);
1091 1091
 
1092 1092
 				$items[] = $item;
1093 1093
 			}
1094 1094
 		}
1095 1095
 
1096
-		$discounts   = wc_format_decimal( WC()->cart->get_cart_discount_total(), WC()->cart->dp );
1097
-		$tax         = wc_format_decimal( WC()->cart->tax_total + WC()->cart->shipping_tax_total, WC()->cart->dp );
1098
-		$shipping    = wc_format_decimal( WC()->cart->shipping_total, WC()->cart->dp );
1099
-		$items_total = wc_format_decimal( WC()->cart->cart_contents_total, WC()->cart->dp ) + $discounts;
1100
-		$order_total = wc_format_decimal( $items_total + $tax + $shipping - $discounts, WC()->cart->dp );
1096
+		$discounts   = wc_format_decimal(WC()->cart->get_cart_discount_total(), WC()->cart->dp);
1097
+		$tax         = wc_format_decimal(WC()->cart->tax_total + WC()->cart->shipping_tax_total, WC()->cart->dp);
1098
+		$shipping    = wc_format_decimal(WC()->cart->shipping_total, WC()->cart->dp);
1099
+		$items_total = wc_format_decimal(WC()->cart->cart_contents_total, WC()->cart->dp) + $discounts;
1100
+		$order_total = wc_format_decimal($items_total + $tax + $shipping - $discounts, WC()->cart->dp);
1101 1101
 
1102
-		if ( wc_tax_enabled() ) {
1102
+		if (wc_tax_enabled()) {
1103 1103
 			$items[] = array(
1104
-				'label'  => esc_html( __( 'Tax', 'woocommerce-gateway-stripe' ) ),
1105
-				'amount' => WC_Stripe_Helper::get_stripe_amount( $tax ),
1104
+				'label'  => esc_html(__('Tax', 'woocommerce-gateway-stripe')),
1105
+				'amount' => WC_Stripe_Helper::get_stripe_amount($tax),
1106 1106
 			);
1107 1107
 		}
1108 1108
 
1109
-		if ( WC()->cart->needs_shipping() ) {
1109
+		if (WC()->cart->needs_shipping()) {
1110 1110
 			$items[] = array(
1111
-				'label'  => esc_html( __( 'Shipping', 'woocommerce-gateway-stripe' ) ),
1112
-				'amount' => WC_Stripe_Helper::get_stripe_amount( $shipping ),
1111
+				'label'  => esc_html(__('Shipping', 'woocommerce-gateway-stripe')),
1112
+				'amount' => WC_Stripe_Helper::get_stripe_amount($shipping),
1113 1113
 			);
1114 1114
 		}
1115 1115
 
1116
-		if ( WC()->cart->has_discount() ) {
1116
+		if (WC()->cart->has_discount()) {
1117 1117
 			$items[] = array(
1118
-				'label'  => esc_html( __( 'Discount', 'woocommerce-gateway-stripe' ) ),
1119
-				'amount' => WC_Stripe_Helper::get_stripe_amount( $discounts ),
1118
+				'label'  => esc_html(__('Discount', 'woocommerce-gateway-stripe')),
1119
+				'amount' => WC_Stripe_Helper::get_stripe_amount($discounts),
1120 1120
 			);
1121 1121
 		}
1122 1122
 
1123
-		if ( version_compare( WC_VERSION, '3.2', '<' ) ) {
1123
+		if (version_compare(WC_VERSION, '3.2', '<')) {
1124 1124
 			$cart_fees = WC()->cart->fees;
1125 1125
 		} else {
1126 1126
 			$cart_fees = WC()->cart->get_fees();
1127 1127
 		}
1128 1128
 
1129 1129
 		// Include fees and taxes as display items.
1130
-		foreach ( $cart_fees as $key => $fee ) {
1130
+		foreach ($cart_fees as $key => $fee) {
1131 1131
 			$items[] = array(
1132 1132
 				'label'  => $fee->name,
1133
-				'amount' => WC_Stripe_Helper::get_stripe_amount( $fee->amount ),
1133
+				'amount' => WC_Stripe_Helper::get_stripe_amount($fee->amount),
1134 1134
 			);
1135 1135
 		}
1136 1136
 
@@ -1138,7 +1138,7 @@  discard block
 block discarded – undo
1138 1138
 			'displayItems' => $items,
1139 1139
 			'total'      => array(
1140 1140
 				'label'   => $this->total_label,
1141
-				'amount'  => max( 0, apply_filters( 'woocommerce_stripe_calculated_total', WC_Stripe_Helper::get_stripe_amount( $order_total ), $order_total, WC()->cart ) ),
1141
+				'amount'  => max(0, apply_filters('woocommerce_stripe_calculated_total', WC_Stripe_Helper::get_stripe_amount($order_total), $order_total, WC()->cart)),
1142 1142
 				'pending' => false,
1143 1143
 			),
1144 1144
 		);
Please login to merge, or discard this patch.