Completed
Push — master ( e4283c...272f75 )
by Roy
02:12
created
includes/class-wc-stripe-order-handler.php 1 patch
Spacing   +175 added lines, -175 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) {
2
+if ( ! defined('ABSPATH')) {
3 3
 	exit;
4 4
 }
5 5
 
@@ -20,12 +20,12 @@  discard block
 block discarded – undo
20 20
 	public function __construct() {
21 21
 		self::$_this = $this;
22 22
 
23
-		add_action( 'wp', array( $this, 'maybe_process_redirect_order' ) );
24
-		add_action( 'woocommerce_order_status_on-hold_to_processing', array( $this, 'capture_payment' ) );
25
-		add_action( 'woocommerce_order_status_on-hold_to_completed', array( $this, 'capture_payment' ) );
26
-		add_action( 'woocommerce_order_status_on-hold_to_cancelled', array( $this, 'cancel_payment' ) );
27
-		add_action( 'woocommerce_order_status_on-hold_to_refunded', array( $this, 'cancel_payment' ) );
28
-		add_action( 'wc_ajax_wc_stripe_validate_checkout', array( $this, 'validate_checkout' ) );
23
+		add_action('wp', array($this, 'maybe_process_redirect_order'));
24
+		add_action('woocommerce_order_status_on-hold_to_processing', array($this, 'capture_payment'));
25
+		add_action('woocommerce_order_status_on-hold_to_completed', array($this, 'capture_payment'));
26
+		add_action('woocommerce_order_status_on-hold_to_cancelled', array($this, 'cancel_payment'));
27
+		add_action('woocommerce_order_status_on-hold_to_refunded', array($this, 'cancel_payment'));
28
+		add_action('wc_ajax_wc_stripe_validate_checkout', array($this, 'validate_checkout'));
29 29
 	}
30 30
 
31 31
 	/**
@@ -46,25 +46,25 @@  discard block
 block discarded – undo
46 46
 	 * @since 4.0.0
47 47
 	 * @version 4.0.0
48 48
 	 */
49
-	public function process_redirect_payment( $order_id, $retry = true ) {
49
+	public function process_redirect_payment($order_id, $retry = true) {
50 50
 		try {
51
-			$source = wc_clean( $_GET['source'] );
51
+			$source = wc_clean($_GET['source']);
52 52
 
53
-			if ( empty( $source ) ) {
53
+			if (empty($source)) {
54 54
 				return;
55 55
 			}
56 56
 
57
-			if ( empty( $order_id ) ) {
57
+			if (empty($order_id)) {
58 58
 				return;
59 59
 			}
60 60
 
61
-			$order = wc_get_order( $order_id );
61
+			$order = wc_get_order($order_id);
62 62
 
63
-			if ( ! is_object( $order ) ) {
63
+			if ( ! is_object($order)) {
64 64
 				return;
65 65
 			}
66 66
 
67
-			if ( 'processing' === $order->get_status() || 'completed' === $order->get_status() || 'on-hold' === $order->get_status() ) {
67
+			if ('processing' === $order->get_status() || 'completed' === $order->get_status() || 'on-hold' === $order->get_status()) {
68 68
 				return;
69 69
 			}
70 70
 
@@ -72,101 +72,101 @@  discard block
 block discarded – undo
72 72
 			$response = null;
73 73
 
74 74
 			// This will throw exception if not valid.
75
-			$this->validate_minimum_order_amount( $order );
75
+			$this->validate_minimum_order_amount($order);
76 76
 
77
-			WC_Stripe_Logger::log( "Info: (Redirect) Begin processing payment for order $order_id for the amount of {$order->get_total()}" );
77
+			WC_Stripe_Logger::log("Info: (Redirect) Begin processing payment for order $order_id for the amount of {$order->get_total()}");
78 78
 
79 79
 			// Prep source object.
80 80
 			$source_object           = new stdClass();
81 81
 			$source_object->token_id = '';
82
-			$source_object->customer = $this->get_stripe_customer_id( $order );
82
+			$source_object->customer = $this->get_stripe_customer_id($order);
83 83
 			$source_object->source   = $source;
84 84
 
85 85
 			/**
86 86
 			 * First check if the source is chargeable at this time. If not,
87 87
 			 * webhook will take care of it later.
88 88
 			 */
89
-			$source_info = WC_Stripe_API::retrieve( 'sources/' . $source );
89
+			$source_info = WC_Stripe_API::retrieve('sources/' . $source);
90 90
 
91
-			if ( ! empty( $source_info->error ) ) {
92
-				throw new WC_Stripe_Exception( print_r( $source_info, true ), $source_info->error->message );
91
+			if ( ! empty($source_info->error)) {
92
+				throw new WC_Stripe_Exception(print_r($source_info, true), $source_info->error->message);
93 93
 			}
94 94
 
95
-			if ( 'failed' === $source_info->status || 'canceled' === $source_info->status ) {
96
-				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' ) );
95
+			if ('failed' === $source_info->status || 'canceled' === $source_info->status) {
96
+				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'));
97 97
 			}
98 98
 
99 99
 			// If already consumed, then ignore request.
100
-			if ( 'consumed' === $source_info->status ) {
100
+			if ('consumed' === $source_info->status) {
101 101
 				return;
102 102
 			}
103 103
 
104 104
 			// If not chargeable, then ignore request.
105
-			if ( 'chargeable' !== $source_info->status ) {
105
+			if ('chargeable' !== $source_info->status) {
106 106
 				return;
107 107
 			}
108 108
 
109 109
 			// Make the request.
110
-			$response = WC_Stripe_API::request( $this->generate_payment_request( $order, $source_object ) );
110
+			$response = WC_Stripe_API::request($this->generate_payment_request($order, $source_object));
111 111
 
112
-			if ( ! empty( $response->error ) ) {
112
+			if ( ! empty($response->error)) {
113 113
 				// If it is an API error such connection or server, let's retry.
114
-				if ( 'api_connection_error' === $response->error->type || 'api_error' === $response->error->type ) {
115
-					if ( $retry ) {
116
-						sleep( 5 );
117
-						return $this->process_redirect_payment( $order_id, false );
114
+				if ('api_connection_error' === $response->error->type || 'api_error' === $response->error->type) {
115
+					if ($retry) {
116
+						sleep(5);
117
+						return $this->process_redirect_payment($order_id, false);
118 118
 					} else {
119 119
 						$message = 'API connection error and retries exhausted.';
120
-						$order->add_order_note( $message );
121
-						throw new WC_Stripe_Exception( print_r( $response, true ), $message );
120
+						$order->add_order_note($message);
121
+						throw new WC_Stripe_Exception(print_r($response, true), $message);
122 122
 					}
123 123
 				}
124 124
 
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
-					delete_user_meta( WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id(), '_stripe_customer_id' );
126
+				if (preg_match('/No such customer/i', $response->error->message) && $retry) {
127
+					delete_user_meta(WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id(), '_stripe_customer_id');
128 128
 
129
-					return $this->process_redirect_payment( $order_id, false );
129
+					return $this->process_redirect_payment($order_id, false);
130 130
 
131
-				} elseif ( preg_match( '/No such token/i', $response->error->message ) && $source_object->token_id ) {
131
+				} elseif (preg_match('/No such token/i', $response->error->message) && $source_object->token_id) {
132 132
 					// Source param wrong? The CARD may have been deleted on stripe's end. Remove token and show message.
133 133
 
134
-					$wc_token = WC_Payment_Tokens::get( $source_object->token_id );
134
+					$wc_token = WC_Payment_Tokens::get($source_object->token_id);
135 135
 					$wc_token->delete();
136
-					$message = __( 'This card is no longer available and has been removed.', 'woocommerce-gateway-stripe' );
137
-					$order->add_order_note( $message );
138
-					throw new WC_Stripe_Exception( print_r( $response, true ), $message );
136
+					$message = __('This card is no longer available and has been removed.', 'woocommerce-gateway-stripe');
137
+					$order->add_order_note($message);
138
+					throw new WC_Stripe_Exception(print_r($response, true), $message);
139 139
 				}
140 140
 
141 141
 				$localized_messages = WC_Stripe_Helper::get_localized_messages();
142 142
 
143
-				if ( 'card_error' === $response->error->type ) {
144
-					$message = isset( $localized_messages[ $response->error->code ] ) ? $localized_messages[ $response->error->code ] : $response->error->message;
143
+				if ('card_error' === $response->error->type) {
144
+					$message = isset($localized_messages[$response->error->code]) ? $localized_messages[$response->error->code] : $response->error->message;
145 145
 				} else {
146
-					$message = isset( $localized_messages[ $response->error->type ] ) ? $localized_messages[ $response->error->type ] : $response->error->message;
146
+					$message = isset($localized_messages[$response->error->type]) ? $localized_messages[$response->error->type] : $response->error->message;
147 147
 				}
148 148
 
149
-				throw new WC_Stripe_Exception( print_r( $response, true ), $message );
149
+				throw new WC_Stripe_Exception(print_r($response, true), $message);
150 150
 			}
151 151
 
152
-			do_action( 'wc_gateway_stripe_process_redirect_payment', $response, $order );
152
+			do_action('wc_gateway_stripe_process_redirect_payment', $response, $order);
153 153
 
154
-			$this->process_response( $response, $order );
154
+			$this->process_response($response, $order);
155 155
 
156
-		} catch ( WC_Stripe_Exception $e ) {
157
-			WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() );
156
+		} catch (WC_Stripe_Exception $e) {
157
+			WC_Stripe_Logger::log('Error: ' . $e->getMessage());
158 158
 
159
-			do_action( 'wc_gateway_stripe_process_redirect_payment_error', $e, $order );
159
+			do_action('wc_gateway_stripe_process_redirect_payment_error', $e, $order);
160 160
 
161 161
 			/* translators: error message */
162
-			$order->update_status( 'failed', sprintf( __( 'Stripe payment failed: %s', 'woocommerce-gateway-stripe' ), $e->getLocalizedMessage() ) );
162
+			$order->update_status('failed', sprintf(__('Stripe payment failed: %s', 'woocommerce-gateway-stripe'), $e->getLocalizedMessage()));
163 163
 
164
-			if ( $order->has_status( array( 'pending', 'failed' ) ) ) {
165
-				$this->send_failed_order_email( $order_id );
164
+			if ($order->has_status(array('pending', 'failed'))) {
165
+				$this->send_failed_order_email($order_id);
166 166
 			}
167 167
 
168
-			wc_add_notice( $e->getLocalizedMessage(), 'error' );
169
-			wp_safe_redirect( wc_get_checkout_url() );
168
+			wc_add_notice($e->getLocalizedMessage(), 'error');
169
+			wp_safe_redirect(wc_get_checkout_url());
170 170
 			exit;
171 171
 		}
172 172
 	}
@@ -178,13 +178,13 @@  discard block
 block discarded – undo
178 178
 	 * @version 4.0.0
179 179
 	 */
180 180
 	public function maybe_process_redirect_order() {
181
-		if ( ! is_order_received_page() || empty( $_GET['client_secret'] ) || empty( $_GET['source'] ) ) {
181
+		if ( ! is_order_received_page() || empty($_GET['client_secret']) || empty($_GET['source'])) {
182 182
 			return;
183 183
 		}
184 184
 
185
-		$order_id = wc_clean( $_GET['order_id'] );
185
+		$order_id = wc_clean($_GET['order_id']);
186 186
 
187
-		$this->process_redirect_payment( $order_id );
187
+		$this->process_redirect_payment($order_id);
188 188
 	}
189 189
 
190 190
 	/**
@@ -194,52 +194,52 @@  discard block
 block discarded – undo
194 194
 	 * @version 4.0.0
195 195
 	 * @param  int $order_id
196 196
 	 */
197
-	public function capture_payment( $order_id ) {
198
-		$order = wc_get_order( $order_id );
197
+	public function capture_payment($order_id) {
198
+		$order = wc_get_order($order_id);
199 199
 
200
-		if ( 'stripe' === ( WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method() ) ) {
201
-			$charge   = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_transaction_id', true ) : $order->get_transaction_id();
202
-			$captured = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_stripe_charge_captured', true ) : $order->get_meta( '_stripe_charge_captured', true );
200
+		if ('stripe' === (WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method())) {
201
+			$charge   = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_transaction_id', true) : $order->get_transaction_id();
202
+			$captured = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_stripe_charge_captured', true) : $order->get_meta('_stripe_charge_captured', true);
203 203
 
204
-			if ( $charge && 'no' === $captured ) {
204
+			if ($charge && 'no' === $captured) {
205 205
 				$order_total = $order->get_total();
206 206
 
207
-				if ( 0 < $order->get_total_refunded() ) {
207
+				if (0 < $order->get_total_refunded()) {
208 208
 					$order_total = $order_total - $order->get_total_refunded();
209 209
 				}
210 210
 
211
-				$result = WC_Stripe_API::request( array(
212
-					'amount'   => WC_Stripe_Helper::get_stripe_amount( $order_total ),
211
+				$result = WC_Stripe_API::request(array(
212
+					'amount'   => WC_Stripe_Helper::get_stripe_amount($order_total),
213 213
 					'expand[]' => 'balance_transaction',
214
-				), 'charges/' . $charge . '/capture' );
214
+				), 'charges/' . $charge . '/capture');
215 215
 
216
-				if ( ! empty( $result->error ) ) {
216
+				if ( ! empty($result->error)) {
217 217
 					/* translators: error message */
218
-					$order->update_status( 'failed', sprintf( __( 'Unable to capture charge! %s', 'woocommerce-gateway-stripe' ), $result->error->message ) );
218
+					$order->update_status('failed', sprintf(__('Unable to capture charge! %s', 'woocommerce-gateway-stripe'), $result->error->message));
219 219
 				} else {
220 220
 					/* translators: transaction id */
221
-					$order->add_order_note( sprintf( __( 'Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe' ), $result->id ) );
222
-					WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, '_stripe_charge_captured', 'yes' ) : $order->update_meta_data( '_stripe_charge_captured', 'yes' );
221
+					$order->add_order_note(sprintf(__('Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe'), $result->id));
222
+					WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, '_stripe_charge_captured', 'yes') : $order->update_meta_data('_stripe_charge_captured', 'yes');
223 223
 
224 224
 					// Store other data such as fees
225
-					WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, '_transaction_id', $result->id ) : $order->set_transaction_id( $result->id );
225
+					WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, '_transaction_id', $result->id) : $order->set_transaction_id($result->id);
226 226
 
227
-					if ( isset( $result->balance_transaction ) && isset( $result->balance_transaction->fee ) ) {
227
+					if (isset($result->balance_transaction) && isset($result->balance_transaction->fee)) {
228 228
 						// Fees and Net needs to both come from Stripe to be accurate as the returned
229 229
 						// values are in the local currency of the Stripe account, not from WC.
230
-						$fee = ! empty( $result->balance_transaction->fee ) ? WC_Stripe_Helper::format_balance_fee( $result->balance_transaction, 'fee' ) : 0;
231
-						$net = ! empty( $result->balance_transaction->net ) ? WC_Stripe_Helper::format_balance_fee( $result->balance_transaction, 'net' ) : 0;
232
-						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 );
233
-						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 );
230
+						$fee = ! empty($result->balance_transaction->fee) ? WC_Stripe_Helper::format_balance_fee($result->balance_transaction, 'fee') : 0;
231
+						$net = ! empty($result->balance_transaction->net) ? WC_Stripe_Helper::format_balance_fee($result->balance_transaction, 'net') : 0;
232
+						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);
233
+						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);
234 234
 					}
235 235
 
236
-					if ( is_callable( array( $order, 'save' ) ) ) {
236
+					if (is_callable(array($order, 'save'))) {
237 237
 						$order->save();
238 238
 					}
239 239
 				}
240 240
 
241 241
 				// This hook fires when admin manually changes order status to processing or completed.
242
-				do_action( 'woocommerce_stripe_process_manual_capture', $order, $result );
242
+				do_action('woocommerce_stripe_process_manual_capture', $order, $result);
243 243
 			}
244 244
 		}
245 245
 	}
@@ -251,32 +251,32 @@  discard block
 block discarded – undo
251 251
 	 * @version 4.0.0
252 252
 	 * @param  int $order_id
253 253
 	 */
254
-	public function cancel_payment( $order_id ) {
255
-		$order = wc_get_order( $order_id );
254
+	public function cancel_payment($order_id) {
255
+		$order = wc_get_order($order_id);
256 256
 
257
-		if ( 'stripe' === ( WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method() ) ) {
258
-			$charge_id = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_transaction_id', true ) : $order->get_transaction_id();
257
+		if ('stripe' === (WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method())) {
258
+			$charge_id = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_transaction_id', true) : $order->get_transaction_id();
259 259
 
260
-			if ( $charge_id ) {
261
-				$result = WC_Stripe_API::request( array(
262
-					'amount' => WC_Stripe_Helper::get_stripe_amount( $order->get_total() ),
263
-				), 'charges/' . $charge_id . '/refund' );
260
+			if ($charge_id) {
261
+				$result = WC_Stripe_API::request(array(
262
+					'amount' => WC_Stripe_Helper::get_stripe_amount($order->get_total()),
263
+				), 'charges/' . $charge_id . '/refund');
264 264
 
265
-				if ( ! empty( $result->error ) ) {
266
-					$order->add_order_note( __( 'Unable to refund charge!', 'woocommerce-gateway-stripe' ) . ' ' . $result->error->message );
265
+				if ( ! empty($result->error)) {
266
+					$order->add_order_note(__('Unable to refund charge!', 'woocommerce-gateway-stripe') . ' ' . $result->error->message);
267 267
 				} else {
268 268
 					/* translators: transaction id */
269
-					$order->add_order_note( sprintf( __( 'Stripe charge refunded (Charge ID: %s)', 'woocommerce-gateway-stripe' ), $result->id ) );
270
-					WC_Stripe_Helper::is_pre_30() ? delete_post_meta( $order_id, '_stripe_charge_captured' ) : $order->delete_meta_data( '_stripe_charge_captured' );
271
-					WC_Stripe_Helper::is_pre_30() ? delete_post_meta( $order_id, '_transaction_id' ) : $order->delete_meta_data( '_stripe_transaction_id' );
269
+					$order->add_order_note(sprintf(__('Stripe charge refunded (Charge ID: %s)', 'woocommerce-gateway-stripe'), $result->id));
270
+					WC_Stripe_Helper::is_pre_30() ? delete_post_meta($order_id, '_stripe_charge_captured') : $order->delete_meta_data('_stripe_charge_captured');
271
+					WC_Stripe_Helper::is_pre_30() ? delete_post_meta($order_id, '_transaction_id') : $order->delete_meta_data('_stripe_transaction_id');
272 272
 
273
-					if ( is_callable( array( $order, 'save' ) ) ) {
273
+					if (is_callable(array($order, 'save'))) {
274 274
 						$order->save();
275 275
 					}
276 276
 				}
277 277
 
278 278
 				// This hook fires when admin manually changes order status to cancel.
279
-				do_action( 'woocommerce_stripe_process_manual_cancel', $order, $result );
279
+				do_action('woocommerce_stripe_process_manual_cancel', $order, $result);
280 280
 			}
281 281
 		}
282 282
 	}
@@ -289,21 +289,21 @@  discard block
 block discarded – undo
289 289
 	 * @param string $field
290 290
 	 * @return string $error_field
291 291
 	 */
292
-	public function normalize_field( $field ) {
292
+	public function normalize_field($field) {
293 293
 		$checkout_fields = WC()->checkout->get_checkout_fields();
294 294
 		$org_str         = array();
295 295
 		$replace_str     = array();
296 296
 
297
-		if ( array_key_exists( $field, $checkout_fields['billing'] ) ) {
298
-			$error_field = __( 'Billing', 'woocommerce-gateway-stripe' ) . ' ' . $checkout_fields['billing'][ $field ]['label'];
299
-		} elseif ( array_key_exists( $field, $checkout_fields['shipping'] ) ) {
300
-			$error_field = __( 'Shipping', 'woocommerce-gateway-stripe' ) . ' ' . $checkout_fields['shipping'][ $field ]['label'];
301
-		} elseif ( array_key_exists( $field, $checkout_fields['order'] ) ) {
302
-			$error_field = $checkout_fields['order'][ $field ]['label'];
303
-		} elseif ( array_key_exists( $field, $checkout_fields['account'] ) ) {
304
-			$error_field = $checkout_fields['account'][ $field ]['label'];
297
+		if (array_key_exists($field, $checkout_fields['billing'])) {
298
+			$error_field = __('Billing', 'woocommerce-gateway-stripe') . ' ' . $checkout_fields['billing'][$field]['label'];
299
+		} elseif (array_key_exists($field, $checkout_fields['shipping'])) {
300
+			$error_field = __('Shipping', 'woocommerce-gateway-stripe') . ' ' . $checkout_fields['shipping'][$field]['label'];
301
+		} elseif (array_key_exists($field, $checkout_fields['order'])) {
302
+			$error_field = $checkout_fields['order'][$field]['label'];
303
+		} elseif (array_key_exists($field, $checkout_fields['account'])) {
304
+			$error_field = $checkout_fields['account'][$field]['label'];
305 305
 		} else {
306
-			$error_field = str_replace( '_', ' ', $field );
306
+			$error_field = str_replace('_', ' ', $field);
307 307
 
308 308
 			$org_str[]     = 'stripe';
309 309
 			$replace_str[] = '';
@@ -318,9 +318,9 @@  discard block
 block discarded – undo
318 318
 			$replace_str[] = 'SOFORT';
319 319
 
320 320
 			$org_str[]     = 'owner';
321
-			$replace_str[] = __( 'Owner', 'woocommerce-gateway-stripe' );
321
+			$replace_str[] = __('Owner', 'woocommerce-gateway-stripe');
322 322
 
323
-			$error_field   = str_replace( $org_str, $replace_str, $error_field );
323
+			$error_field   = str_replace($org_str, $replace_str, $error_field);
324 324
 		}
325 325
 
326 326
 		return $error_field;
@@ -333,157 +333,157 @@  discard block
 block discarded – undo
333 333
 	 * @version 4.0.0
334 334
 	 */
335 335
 	public function validate_checkout() {
336
-		if ( ! wp_verify_nonce( $_POST['nonce'], '_wc_stripe_nonce' ) ) {
337
-			wp_die( __( 'Cheatin&#8217; huh?', 'woocommerce-gateway-stripe' ) );
336
+		if ( ! wp_verify_nonce($_POST['nonce'], '_wc_stripe_nonce')) {
337
+			wp_die(__('Cheatin&#8217; huh?', 'woocommerce-gateway-stripe'));
338 338
 		}
339 339
 
340 340
 		$errors = new WP_Error();
341
-		parse_str( $_POST['required_fields'], $required_fields );
342
-		parse_str( $_POST['all_fields'], $all_fields );
343
-		$source_type = isset( $_POST['source_type'] ) ? wc_clean( $_POST['source_type'] ) : '';
341
+		parse_str($_POST['required_fields'], $required_fields);
342
+		parse_str($_POST['all_fields'], $all_fields);
343
+		$source_type = isset($_POST['source_type']) ? wc_clean($_POST['source_type']) : '';
344 344
 		$validate_shipping_fields = false;
345 345
 		$create_account = false;
346 346
 
347
-		$all_fields      = apply_filters( 'wc_stripe_validate_checkout_all_fields', $all_fields );
348
-		$required_fields = apply_filters( 'wc_stripe_validate_checkout_required_fields', $required_fields );
347
+		$all_fields      = apply_filters('wc_stripe_validate_checkout_all_fields', $all_fields);
348
+		$required_fields = apply_filters('wc_stripe_validate_checkout_required_fields', $required_fields);
349 349
 
350
-		array_walk_recursive( $required_fields, 'wc_clean' );
351
-		array_walk_recursive( $all_fields, 'wc_clean' );
350
+		array_walk_recursive($required_fields, 'wc_clean');
351
+		array_walk_recursive($all_fields, 'wc_clean');
352 352
 
353 353
 		// Remove unneeded required fields depending on source type.
354
-		if ( 'stripe_sepa' !== $source_type ) {
355
-			unset( $required_fields['stripe_sepa_owner'] );
356
-			unset( $required_fields['stripe_sepa_iban'] );
354
+		if ('stripe_sepa' !== $source_type) {
355
+			unset($required_fields['stripe_sepa_owner']);
356
+			unset($required_fields['stripe_sepa_iban']);
357 357
 		}
358 358
 
359
-		if ( 'stripe_sofort' !== $source_type ) {
360
-			unset( $required_fields['stripe_sofort_bank_country'] );
359
+		if ('stripe_sofort' !== $source_type) {
360
+			unset($required_fields['stripe_sofort_bank_country']);
361 361
 		}
362 362
 
363 363
 		/**
364 364
 		 * If ship to different address checkbox is checked then we need
365 365
 		 * to validate shipping fields too.
366 366
 		 */
367
-		if ( isset( $all_fields['ship_to_different_address'] ) ) {
367
+		if (isset($all_fields['ship_to_different_address'])) {
368 368
 			$validate_shipping_fields = true;
369 369
 		}
370 370
 
371 371
 		// Check if createaccount is checked.
372
-		if ( isset( $all_fields['createaccount'] ) ) {
372
+		if (isset($all_fields['createaccount'])) {
373 373
 			$create_account = true;
374 374
 		}
375 375
 
376 376
 		// Check if required fields are empty.
377
-		foreach ( $required_fields as $field => $field_value ) {
377
+		foreach ($required_fields as $field => $field_value) {
378 378
 			// Check for shipping field.
379
-			if ( preg_match( '/^shipping_/', $field ) && ! $validate_shipping_fields ) {
379
+			if (preg_match('/^shipping_/', $field) && ! $validate_shipping_fields) {
380 380
 				continue;
381 381
 			}
382 382
 
383 383
 			// Check create account name.
384
-			if ( 'account_username' === $field && ! $create_account ) {
384
+			if ('account_username' === $field && ! $create_account) {
385 385
 				continue;
386 386
 			}
387 387
 
388 388
 			// Check create account password.
389
-			if ( 'account_password' === $field && ! $create_account ) {
389
+			if ('account_password' === $field && ! $create_account) {
390 390
 				continue;
391 391
 			}
392 392
 
393 393
 			// Check if is SEPA.
394
-			if ( 'stripe_sepa' !== $source_type && 'stripe_sepa_owner' === $field ) {
394
+			if ('stripe_sepa' !== $source_type && 'stripe_sepa_owner' === $field) {
395 395
 				continue;
396 396
 			}
397 397
 
398
-			if ( 'stripe_sepa' !== $source_type && 'stripe_sepa_iban' === $field ) {
398
+			if ('stripe_sepa' !== $source_type && 'stripe_sepa_iban' === $field) {
399 399
 				$continue;
400 400
 			}
401 401
 
402
-			if ( empty( $field_value ) || '-1' === $field_value ) {
403
-				$error_field = $this->normalize_field( $field );
402
+			if (empty($field_value) || '-1' === $field_value) {
403
+				$error_field = $this->normalize_field($field);
404 404
 				/* translators: error field name */
405
-				$errors->add( 'validation', sprintf( __( '<strong>%s</strong> cannot be empty', 'woocommerce-gateway-stripe' ), $error_field ) );
405
+				$errors->add('validation', sprintf(__('<strong>%s</strong> cannot be empty', 'woocommerce-gateway-stripe'), $error_field));
406 406
 			}
407 407
 		}
408 408
 
409 409
 		// Check if email is valid format.
410
-		if ( ! empty( $required_fields['billing_email'] ) && ! is_email( $required_fields['billing_email'] ) ) {
411
-			$errors->add( 'validation', __( 'Email is not valid', 'woocommerce-gateway-stripe' ) );
410
+		if ( ! empty($required_fields['billing_email']) && ! is_email($required_fields['billing_email'])) {
411
+			$errors->add('validation', __('Email is not valid', 'woocommerce-gateway-stripe'));
412 412
 		}
413 413
 
414 414
 		// Check if phone number is valid format.
415
-		if ( ! empty( $required_fields['billing_phone'] ) ) {
416
-			$phone = wc_format_phone_number( $required_fields['billing_phone'] );
415
+		if ( ! empty($required_fields['billing_phone'])) {
416
+			$phone = wc_format_phone_number($required_fields['billing_phone']);
417 417
 
418
-			if ( '' !== $phone && ! WC_Validation::is_phone( $phone ) ) {
418
+			if ('' !== $phone && ! WC_Validation::is_phone($phone)) {
419 419
 				/* translators: %s: phone number */
420
-				$errors->add( 'validation', __( 'Please enter a valid phone number.', 'woocommerce-gateway-stripe' ) );
420
+				$errors->add('validation', __('Please enter a valid phone number.', 'woocommerce-gateway-stripe'));
421 421
 			}
422 422
 		}
423 423
 
424 424
 		// Check if postal code is valid format.
425
-		if ( ! empty( $required_fields['billing_postcode'] ) ) {
426
-			$country = isset( $required_fields['billing_country'] ) ? $required_fields['billing_country'] : WC()->customer->get_billing_country();
427
-			$postcode = wc_format_postcode( $required_fields['billing_postcode'], $country );
425
+		if ( ! empty($required_fields['billing_postcode'])) {
426
+			$country = isset($required_fields['billing_country']) ? $required_fields['billing_country'] : WC()->customer->get_billing_country();
427
+			$postcode = wc_format_postcode($required_fields['billing_postcode'], $country);
428 428
 
429
-			if ( '' !== $required_fields['billing_postcode'] && ! WC_Validation::is_postcode( $postcode, $country ) ) {
430
-				$errors->add( 'validation', __( 'Please enter a valid billing postcode / ZIP.', 'woocommerce-gateway-stripe' ) );
429
+			if ('' !== $required_fields['billing_postcode'] && ! WC_Validation::is_postcode($postcode, $country)) {
430
+				$errors->add('validation', __('Please enter a valid billing postcode / ZIP.', 'woocommerce-gateway-stripe'));
431 431
 			}
432 432
 		}
433 433
 
434 434
 		// Don't check this on add payment method page.
435
-		if ( ( isset( $_POST['is_add_payment_page'] ) && 'no' === $_POST['is_add_payment_page'] ) ) {
436
-			if ( empty( $all_fields['woocommerce_checkout_update_totals'] ) && empty( $all_fields['terms'] ) && apply_filters( 'woocommerce_checkout_show_terms', wc_get_page_id( 'terms' ) > 0 ) ) {
437
-				$errors->add( 'terms', __( 'You must accept our Terms &amp; Conditions.', 'woocommerce-gateway-stripe' ) );
435
+		if ((isset($_POST['is_add_payment_page']) && 'no' === $_POST['is_add_payment_page'])) {
436
+			if (empty($all_fields['woocommerce_checkout_update_totals']) && empty($all_fields['terms']) && apply_filters('woocommerce_checkout_show_terms', wc_get_page_id('terms') > 0)) {
437
+				$errors->add('terms', __('You must accept our Terms &amp; Conditions.', 'woocommerce-gateway-stripe'));
438 438
 			}
439 439
 		}
440 440
 
441
-		if ( WC()->cart->needs_shipping() && $validate_shipping_fields ) {
441
+		if (WC()->cart->needs_shipping() && $validate_shipping_fields) {
442 442
 			// Check if postal code is valid format.
443
-			if ( ! empty( $required_fields['shipping_postcode'] ) ) {
444
-				$country = isset( $required_fields['shipping_country'] ) ? $required_fields['shipping_country'] : WC()->customer->get_shipping_country();
445
-				$postcode = wc_format_postcode( $required_fields['shipping_postcode'], $country );
443
+			if ( ! empty($required_fields['shipping_postcode'])) {
444
+				$country = isset($required_fields['shipping_country']) ? $required_fields['shipping_country'] : WC()->customer->get_shipping_country();
445
+				$postcode = wc_format_postcode($required_fields['shipping_postcode'], $country);
446 446
 
447
-				if ( '' !== $required_fields['shipping_postcode'] && ! WC_Validation::is_postcode( $postcode, $country ) ) {
448
-					$errors->add( 'validation', __( 'Please enter a valid shipping postcode / ZIP.', 'woocommerce-gateway-stripe' ) );
447
+				if ('' !== $required_fields['shipping_postcode'] && ! WC_Validation::is_postcode($postcode, $country)) {
448
+					$errors->add('validation', __('Please enter a valid shipping postcode / ZIP.', 'woocommerce-gateway-stripe'));
449 449
 				}
450 450
 			}
451 451
 		}
452 452
 
453
-		if ( WC()->cart->needs_shipping() ) {
453
+		if (WC()->cart->needs_shipping()) {
454 454
 			$shipping_country = WC()->customer->get_shipping_country();
455 455
 
456
-			if ( empty( $shipping_country ) ) {
457
-				$errors->add( 'shipping', __( 'Please enter an address to continue.', 'woocommerce-gateway-stripe' ) );
458
-			} elseif ( ! in_array( WC()->customer->get_shipping_country(), array_keys( WC()->countries->get_shipping_countries() ) ) ) {
456
+			if (empty($shipping_country)) {
457
+				$errors->add('shipping', __('Please enter an address to continue.', 'woocommerce-gateway-stripe'));
458
+			} elseif ( ! in_array(WC()->customer->get_shipping_country(), array_keys(WC()->countries->get_shipping_countries()))) {
459 459
 				/* translators: country name */
460
-				$errors->add( 'shipping', sprintf( __( 'Unfortunately <strong>we do not ship %s</strong>. Please enter an alternative shipping address.', 'woocommerce-gateway-stripe' ), WC()->countries->shipping_to_prefix() . ' ' . WC()->customer->get_shipping_country() ) );
460
+				$errors->add('shipping', sprintf(__('Unfortunately <strong>we do not ship %s</strong>. Please enter an alternative shipping address.', 'woocommerce-gateway-stripe'), WC()->countries->shipping_to_prefix() . ' ' . WC()->customer->get_shipping_country()));
461 461
 			} else {
462
-				$chosen_shipping_methods = WC()->session->get( 'chosen_shipping_methods' );
462
+				$chosen_shipping_methods = WC()->session->get('chosen_shipping_methods');
463 463
 
464
-				foreach ( WC()->shipping->get_packages() as $i => $package ) {
465
-					if ( ! isset( $chosen_shipping_methods[ $i ], $package['rates'][ $chosen_shipping_methods[ $i ] ] ) ) {
466
-						$errors->add( 'shipping', __( 'No shipping method has been selected. Please double check your address, or contact us if you need any help.', 'woocommerce-gateway-stripe' ) );
464
+				foreach (WC()->shipping->get_packages() as $i => $package) {
465
+					if ( ! isset($chosen_shipping_methods[$i], $package['rates'][$chosen_shipping_methods[$i]])) {
466
+						$errors->add('shipping', __('No shipping method has been selected. Please double check your address, or contact us if you need any help.', 'woocommerce-gateway-stripe'));
467 467
 					}
468 468
 				}
469 469
 			}
470 470
 		}
471 471
 
472
-		if ( WC()->cart->needs_payment() ) {
472
+		if (WC()->cart->needs_payment()) {
473 473
 			$available_gateways = WC()->payment_gateways->get_available_payment_gateways();
474 474
 
475
-			if ( ! isset( $available_gateways[ $all_fields['payment_method'] ] ) ) {
476
-				$errors->add( 'payment', __( 'Invalid payment method.', 'woocommerce-gateway-stripe' ) );
475
+			if ( ! isset($available_gateways[$all_fields['payment_method']])) {
476
+				$errors->add('payment', __('Invalid payment method.', 'woocommerce-gateway-stripe'));
477 477
 			} else {
478
-				$available_gateways[ $all_fields['payment_method'] ]->validate_fields();
478
+				$available_gateways[$all_fields['payment_method']]->validate_fields();
479 479
 			}
480 480
 		}
481 481
 
482
-		if ( 0 === count( $errors->errors ) ) {
483
-			wp_send_json( 'success' );
482
+		if (0 === count($errors->errors)) {
483
+			wp_send_json('success');
484 484
 		} else {
485
-			foreach ( $errors->get_error_messages() as $message ) {
486
-				wc_add_notice( $message, 'error' );
485
+			foreach ($errors->get_error_messages() as $message) {
486
+				wc_add_notice($message, 'error');
487 487
 			}
488 488
 
489 489
 			$this->send_ajax_failure_response();
@@ -497,9 +497,9 @@  discard block
 block discarded – undo
497 497
 	 * @version 4.0.0
498 498
 	 */
499 499
 	public function send_ajax_failure_response() {
500
-		if ( is_ajax() ) {
500
+		if (is_ajax()) {
501 501
 			// only print notices if not reloading the checkout, otherwise they're lost in the page reload.
502
-			if ( ! isset( WC()->session->reload_checkout ) ) {
502
+			if ( ! isset(WC()->session->reload_checkout)) {
503 503
 				ob_start();
504 504
 				wc_print_notices();
505 505
 				$messages = ob_get_clean();
@@ -507,14 +507,14 @@  discard block
 block discarded – undo
507 507
 
508 508
 			$response = array(
509 509
 				'result'   => 'failure',
510
-				'messages' => isset( $messages ) ? $messages : '',
511
-				'refresh'  => isset( WC()->session->refresh_totals ),
512
-				'reload'   => isset( WC()->session->reload_checkout ),
510
+				'messages' => isset($messages) ? $messages : '',
511
+				'refresh'  => isset(WC()->session->refresh_totals),
512
+				'reload'   => isset(WC()->session->reload_checkout),
513 513
 			);
514 514
 
515
-			unset( WC()->session->refresh_totals, WC()->session->reload_checkout );
515
+			unset(WC()->session->refresh_totals, WC()->session->reload_checkout);
516 516
 
517
-			wp_send_json( $response );
517
+			wp_send_json($response);
518 518
 		}
519 519
 	}
520 520
 }
Please login to merge, or discard this patch.
includes/admin/stripe-settings.php 1 patch
Spacing   +80 added lines, -80 removed lines patch added patch discarded remove patch
@@ -1,207 +1,207 @@
 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.' ),
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.'),
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_checkout_locale' => array(
112
-			'title'       => __( 'Stripe Checkout locale', 'woocommerce-gateway-stripe' ),
112
+			'title'       => __('Stripe Checkout locale', 'woocommerce-gateway-stripe'),
113 113
 			'type'        => 'select',
114 114
 			'class'       => 'wc-enhanced-select',
115
-			'description' => __( 'Language to display in Stripe Checkout modal. Specify Auto to display Checkout in the user\'s preferred language, if available. English will be used by default.', 'woocommerce-gateway-stripe' ),
115
+			'description' => __('Language to display in Stripe Checkout modal. Specify Auto to display Checkout in the user\'s preferred language, if available. English will be used by default.', 'woocommerce-gateway-stripe'),
116 116
 			'default'     => 'en',
117 117
 			'desc_tip'    => true,
118 118
 			'options'     => array(
119
-				'auto' => __( 'Auto', 'woocommerce-gateway-stripe' ),
120
-				'zh'   => __( 'Simplified Chinese', 'woocommerce-gateway-stripe' ),
121
-				'da'   => __( 'Danish', 'woocommerce-gateway-stripe' ),
122
-				'nl'   => __( 'Dutch', 'woocommerce-gateway-stripe' ),
123
-				'en'   => __( 'English', 'woocommerce-gateway-stripe' ),
124
-				'fi'   => __( 'Finnish', 'woocommerce-gateway-stripe' ),
125
-				'fr'   => __( 'French', 'woocommerce-gateway-stripe' ),
126
-				'de'   => __( 'German', 'woocommerce-gateway-stripe' ),
127
-				'it'   => __( 'Italian', 'woocommerce-gateway-stripe' ),
128
-				'ja'   => __( 'Japanese', 'woocommerce-gateway-stripe' ),
129
-				'no'   => __( 'Norwegian', 'woocommerce-gateway-stripe' ),
130
-				'es'   => __( 'Spanish', 'woocommerce-gateway-stripe' ),
131
-				'sv'   => __( 'Swedish', 'woocommerce-gateway-stripe' ),
119
+				'auto' => __('Auto', 'woocommerce-gateway-stripe'),
120
+				'zh'   => __('Simplified Chinese', 'woocommerce-gateway-stripe'),
121
+				'da'   => __('Danish', 'woocommerce-gateway-stripe'),
122
+				'nl'   => __('Dutch', 'woocommerce-gateway-stripe'),
123
+				'en'   => __('English', 'woocommerce-gateway-stripe'),
124
+				'fi'   => __('Finnish', 'woocommerce-gateway-stripe'),
125
+				'fr'   => __('French', 'woocommerce-gateway-stripe'),
126
+				'de'   => __('German', 'woocommerce-gateway-stripe'),
127
+				'it'   => __('Italian', 'woocommerce-gateway-stripe'),
128
+				'ja'   => __('Japanese', 'woocommerce-gateway-stripe'),
129
+				'no'   => __('Norwegian', 'woocommerce-gateway-stripe'),
130
+				'es'   => __('Spanish', 'woocommerce-gateway-stripe'),
131
+				'sv'   => __('Swedish', 'woocommerce-gateway-stripe'),
132 132
 			),
133 133
 		),
134 134
 		'stripe_bitcoin' => array(
135
-			'title'       => __( 'Bitcoin Currency', 'woocommerce-gateway-stripe' ),
136
-			'label'       => __( 'Enable Bitcoin Currency', 'woocommerce-gateway-stripe' ),
135
+			'title'       => __('Bitcoin Currency', 'woocommerce-gateway-stripe'),
136
+			'label'       => __('Enable Bitcoin Currency', 'woocommerce-gateway-stripe'),
137 137
 			'type'        => 'checkbox',
138
-			'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' ),
138
+			'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'),
139 139
 			'default'     => 'no',
140 140
 			'desc_tip'    => true,
141 141
 		),
142 142
 		'stripe_checkout_image' => array(
143
-			'title'       => __( 'Stripe Checkout Image', 'woocommerce-gateway-stripe' ),
144
-			'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' ),
143
+			'title'       => __('Stripe Checkout Image', 'woocommerce-gateway-stripe'),
144
+			'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'),
145 145
 			'type'        => 'text',
146 146
 			'default'     => '',
147 147
 			'desc_tip'    => true,
148 148
 		),
149 149
 		'payment_request' => array(
150
-			'title'       => __( 'Payment Request Buttons', 'woocommerce-gateway-stripe' ),
150
+			'title'       => __('Payment Request Buttons', 'woocommerce-gateway-stripe'),
151 151
 			/* translators: 1) br tag 2) opening anchor tag 3) closing anchor tag */
152
-			'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>' ),
152
+			'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>'),
153 153
 			'type'        => 'checkbox',
154
-			'description' => __( 'If enabled, users will be able to pay using Apple Pay or Chrome Payment Request if supported by the browser.', 'woocommerce-gateway-stripe' ),
154
+			'description' => __('If enabled, users will be able to pay using Apple Pay or Chrome Payment Request if supported by the browser.', 'woocommerce-gateway-stripe'),
155 155
 			'default'     => 'yes',
156 156
 			'desc_tip'    => true,
157 157
 		),
158 158
 		'payment_request_button_type' => array(
159
-			'title'       => __( 'Payment Request Button Type', 'woocommerce-gateway-stripe' ),
160
-			'label'       => __( 'Button Type', 'woocommerce-gateway-stripe' ),
159
+			'title'       => __('Payment Request Button Type', 'woocommerce-gateway-stripe'),
160
+			'label'       => __('Button Type', 'woocommerce-gateway-stripe'),
161 161
 			'type'        => 'select',
162
-			'description' => __( 'Select the button type you would like to show.', 'woocommerce-gateway-stripe' ),
162
+			'description' => __('Select the button type you would like to show.', 'woocommerce-gateway-stripe'),
163 163
 			'default'     => 'buy',
164 164
 			'desc_tip'    => true,
165 165
 			'options'     => array(
166
-				'default' => __( 'Default', 'woocommerce-gateway-stripe' ),
167
-				'buy'     => __( 'Buy', 'woocommerce-gateway-stripe' ),
168
-				'donate'  => __( 'Donate', 'woocommerce-gateway-stripe' ),
166
+				'default' => __('Default', 'woocommerce-gateway-stripe'),
167
+				'buy'     => __('Buy', 'woocommerce-gateway-stripe'),
168
+				'donate'  => __('Donate', 'woocommerce-gateway-stripe'),
169 169
 			),
170 170
 		),
171 171
 		'payment_request_button_theme' => array(
172
-			'title'       => __( 'Payment Request Button Theme', 'woocommerce-gateway-stripe' ),
173
-			'label'       => __( 'Button Theme', 'woocommerce-gateway-stripe' ),
172
+			'title'       => __('Payment Request Button Theme', 'woocommerce-gateway-stripe'),
173
+			'label'       => __('Button Theme', 'woocommerce-gateway-stripe'),
174 174
 			'type'        => 'select',
175
-			'description' => __( 'Select the button theme you would like to show.', 'woocommerce-gateway-stripe' ),
175
+			'description' => __('Select the button theme you would like to show.', 'woocommerce-gateway-stripe'),
176 176
 			'default'     => 'dark',
177 177
 			'desc_tip'    => true,
178 178
 			'options'     => array(
179
-				'dark'          => __( 'Dark', 'woocommerce-gateway-stripe' ),
180
-				'light'         => __( 'Light', 'woocommerce-gateway-stripe' ),
181
-				'light-outline' => __( 'Light-Outline', 'woocommerce-gateway-stripe' ),
179
+				'dark'          => __('Dark', 'woocommerce-gateway-stripe'),
180
+				'light'         => __('Light', 'woocommerce-gateway-stripe'),
181
+				'light-outline' => __('Light-Outline', 'woocommerce-gateway-stripe'),
182 182
 			),
183 183
 		),
184 184
 		'payment_request_button_height' => array(
185
-			'title'       => __( 'Payment Request Button Height', 'woocommerce-gateway-stripe' ),
186
-			'label'       => __( 'Button Height', 'woocommerce-gateway-stripe' ),
185
+			'title'       => __('Payment Request Button Height', 'woocommerce-gateway-stripe'),
186
+			'label'       => __('Button Height', 'woocommerce-gateway-stripe'),
187 187
 			'type'        => 'text',
188
-			'description' => __( 'Enter the height you would like the button to be in pixels. Width will always be 100%.', 'woocommerce-gateway-stripe' ),
188
+			'description' => __('Enter the height you would like the button to be in pixels. Width will always be 100%.', 'woocommerce-gateway-stripe'),
189 189
 			'default'     => '44',
190 190
 			'desc_tip'    => true,
191 191
 		),
192 192
 		'saved_cards' => array(
193
-			'title'       => __( 'Saved Cards', 'woocommerce-gateway-stripe' ),
194
-			'label'       => __( 'Enable Payment via Saved Cards', 'woocommerce-gateway-stripe' ),
193
+			'title'       => __('Saved Cards', 'woocommerce-gateway-stripe'),
194
+			'label'       => __('Enable Payment via Saved Cards', 'woocommerce-gateway-stripe'),
195 195
 			'type'        => 'checkbox',
196
-			'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' ),
196
+			'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'),
197 197
 			'default'     => 'no',
198 198
 			'desc_tip'    => true,
199 199
 		),
200 200
 		'logging' => array(
201
-			'title'       => __( 'Logging', 'woocommerce-gateway-stripe' ),
202
-			'label'       => __( 'Log debug messages', 'woocommerce-gateway-stripe' ),
201
+			'title'       => __('Logging', 'woocommerce-gateway-stripe'),
202
+			'label'       => __('Log debug messages', 'woocommerce-gateway-stripe'),
203 203
 			'type'        => 'checkbox',
204
-			'description' => __( 'Save debug messages to the WooCommerce System Status log.', 'woocommerce-gateway-stripe' ),
204
+			'description' => __('Save debug messages to the WooCommerce System Status log.', 'woocommerce-gateway-stripe'),
205 205
 			'default'     => 'no',
206 206
 			'desc_tip'    => true,
207 207
 		),
Please login to merge, or discard this patch.
includes/payment-methods/class-wc-gateway-stripe-sepa.php 1 patch
Spacing   +98 added lines, -98 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
 
@@ -57,9 +57,9 @@  discard block
 block discarded – undo
57 57
 	 */
58 58
 	public function __construct() {
59 59
 		$this->id                   = 'stripe_sepa';
60
-		$this->method_title         = __( 'Stripe SEPA Direct Debit', 'woocommerce-gateway-stripe' );
60
+		$this->method_title         = __('Stripe SEPA Direct Debit', 'woocommerce-gateway-stripe');
61 61
 		/* translators: link */
62
-		$this->method_description   = sprintf( __( 'All other general Stripe settings can be adjusted <a href="%s">here</a>.', 'woocommerce-gateway-stripe' ), admin_url( 'admin.php?page=wc-settings&tab=checkout&section=stripe' ) );
62
+		$this->method_description   = sprintf(__('All other general Stripe settings can be adjusted <a href="%s">here</a>.', 'woocommerce-gateway-stripe'), admin_url('admin.php?page=wc-settings&tab=checkout&section=stripe'));
63 63
 		$this->supports             = array(
64 64
 			'products',
65 65
 			'refunds',
@@ -84,25 +84,25 @@  discard block
 block discarded – undo
84 84
 		// Load the settings.
85 85
 		$this->init_settings();
86 86
 
87
-		$main_settings              = get_option( 'woocommerce_stripe_settings' );
88
-		$this->title                = $this->get_option( 'title' );
89
-		$this->description          = $this->get_option( 'description' );
90
-		$this->enabled              = $this->get_option( 'enabled' );
91
-		$this->testmode             = ( ! empty( $main_settings['testmode'] ) && 'yes' === $main_settings['testmode'] ) ? true : false;
92
-		$this->saved_cards          = ( ! empty( $main_settings['saved_cards'] ) && 'yes' === $main_settings['saved_cards'] ) ? true : false;
93
-		$this->publishable_key      = ! empty( $main_settings['publishable_key'] ) ? $main_settings['publishable_key'] : '';
94
-		$this->secret_key           = ! empty( $main_settings['secret_key'] ) ? $main_settings['secret_key'] : '';
95
-		$this->statement_descriptor = ! empty( $main_settings['statement_descriptor'] ) ? $main_settings['statement_descriptor'] : '';
96
-
97
-		if ( $this->testmode ) {
98
-			$this->publishable_key = ! empty( $main_settings['test_publishable_key'] ) ? $main_settings['test_publishable_key'] : '';
99
-			$this->secret_key      = ! empty( $main_settings['test_secret_key'] ) ? $main_settings['test_secret_key'] : '';
87
+		$main_settings              = get_option('woocommerce_stripe_settings');
88
+		$this->title                = $this->get_option('title');
89
+		$this->description          = $this->get_option('description');
90
+		$this->enabled              = $this->get_option('enabled');
91
+		$this->testmode             = ( ! empty($main_settings['testmode']) && 'yes' === $main_settings['testmode']) ? true : false;
92
+		$this->saved_cards          = ( ! empty($main_settings['saved_cards']) && 'yes' === $main_settings['saved_cards']) ? true : false;
93
+		$this->publishable_key      = ! empty($main_settings['publishable_key']) ? $main_settings['publishable_key'] : '';
94
+		$this->secret_key           = ! empty($main_settings['secret_key']) ? $main_settings['secret_key'] : '';
95
+		$this->statement_descriptor = ! empty($main_settings['statement_descriptor']) ? $main_settings['statement_descriptor'] : '';
96
+
97
+		if ($this->testmode) {
98
+			$this->publishable_key = ! empty($main_settings['test_publishable_key']) ? $main_settings['test_publishable_key'] : '';
99
+			$this->secret_key      = ! empty($main_settings['test_secret_key']) ? $main_settings['test_secret_key'] : '';
100 100
 		}
101 101
 
102
-		add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) );
103
-		add_action( 'admin_notices', array( $this, 'check_environment' ) );
104
-		add_action( 'admin_head', array( $this, 'remove_admin_notice' ) );
105
-		add_action( 'wp_enqueue_scripts', array( $this, 'payment_scripts' ) );
102
+		add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options'));
103
+		add_action('admin_notices', array($this, 'check_environment'));
104
+		add_action('admin_head', array($this, 'remove_admin_notice'));
105
+		add_action('wp_enqueue_scripts', array($this, 'payment_scripts'));
106 106
 	}
107 107
 
108 108
 	/**
@@ -112,19 +112,19 @@  discard block
 block discarded – undo
112 112
 	 * @version 4.0.0
113 113
 	 */
114 114
 	public function check_environment() {
115
-		if ( ! current_user_can( 'manage_woocommerce' ) ) {
115
+		if ( ! current_user_can('manage_woocommerce')) {
116 116
 			return;
117 117
 		}
118 118
 
119 119
 		$environment_warning = $this->get_environment_warning();
120 120
 
121
-		if ( $environment_warning ) {
122
-			$this->add_admin_notice( 'bad_environment', 'error', $environment_warning );
121
+		if ($environment_warning) {
122
+			$this->add_admin_notice('bad_environment', 'error', $environment_warning);
123 123
 		}
124 124
 
125
-		foreach ( (array) $this->notices as $notice_key => $notice ) {
126
-			echo "<div class='" . esc_attr( $notice['class'] ) . "'><p>";
127
-			echo wp_kses( $notice['message'], array( 'a' => array( 'href' => array() ) ) );
125
+		foreach ((array) $this->notices as $notice_key => $notice) {
126
+			echo "<div class='" . esc_attr($notice['class']) . "'><p>";
127
+			echo wp_kses($notice['message'], array('a' => array('href' => array())));
128 128
 			echo '</p></div>';
129 129
 		}
130 130
 	}
@@ -137,8 +137,8 @@  discard block
 block discarded – undo
137 137
 	 * @version 4.0.0
138 138
 	 */
139 139
 	public function get_environment_warning() {
140
-		if ( 'yes' === $this->enabled && ! in_array( get_woocommerce_currency(), $this->get_supported_currency() ) ) {
141
-			$message = __( 'SEPA is enabled - it requires store currency to be set to Euros.', 'woocommerce-gateway-stripe' );
140
+		if ('yes' === $this->enabled && ! in_array(get_woocommerce_currency(), $this->get_supported_currency())) {
141
+			$message = __('SEPA is enabled - it requires store currency to be set to Euros.', 'woocommerce-gateway-stripe');
142 142
 
143 143
 			return $message;
144 144
 		}
@@ -154,9 +154,9 @@  discard block
 block discarded – undo
154 154
 	 * @return array
155 155
 	 */
156 156
 	public function get_supported_currency() {
157
-		return apply_filters( 'wc_stripe_sepa_supported_currencies', array(
157
+		return apply_filters('wc_stripe_sepa_supported_currencies', array(
158 158
 			'EUR',
159
-		) );
159
+		));
160 160
 	}
161 161
 
162 162
 	/**
@@ -167,11 +167,11 @@  discard block
 block discarded – undo
167 167
 	 * @return bool
168 168
 	 */
169 169
 	public function is_available() {
170
-		if ( ! in_array( get_woocommerce_currency(), $this->get_supported_currency() ) ) {
170
+		if ( ! in_array(get_woocommerce_currency(), $this->get_supported_currency())) {
171 171
 			return false;
172 172
 		}
173 173
 
174
-		if ( is_add_payment_method_page() && ! $this->saved_cards ) {
174
+		if (is_add_payment_method_page() && ! $this->saved_cards) {
175 175
 			return false;
176 176
 		}
177 177
 
@@ -192,7 +192,7 @@  discard block
 block discarded – undo
192 192
 
193 193
 		$icons_str .= $icons['sepa'];
194 194
 
195
-		return apply_filters( 'woocommerce_gateway_icon', $icons_str, $this->id );
195
+		return apply_filters('woocommerce_gateway_icon', $icons_str, $this->id);
196 196
 	}
197 197
 
198 198
 	/**
@@ -203,19 +203,19 @@  discard block
 block discarded – undo
203 203
 	 * @access public
204 204
 	 */
205 205
 	public function payment_scripts() {
206
-		if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) && ! is_add_payment_method_page() ) {
206
+		if ( ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order']) && ! is_add_payment_method_page()) {
207 207
 			return;
208 208
 		}
209 209
 
210
-		wp_enqueue_style( 'stripe_paymentfonts' );
211
-		wp_enqueue_script( 'woocommerce_stripe' );
210
+		wp_enqueue_style('stripe_paymentfonts');
211
+		wp_enqueue_script('woocommerce_stripe');
212 212
 	}
213 213
 
214 214
 	/**
215 215
 	 * Initialize Gateway Settings Form Fields.
216 216
 	 */
217 217
 	public function init_form_fields() {
218
-		$this->form_fields = require( WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-sepa-settings.php' );
218
+		$this->form_fields = require(WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-sepa-settings.php');
219 219
 	}
220 220
 
221 221
 	/**
@@ -227,7 +227,7 @@  discard block
 block discarded – undo
227 227
 	 */
228 228
 	public function mandate_display() {
229 229
 		/* translators: statement descriptor */
230
-		printf( __( 'By providing your IBAN and confirming this payment, you are authorizing %s and Stripe, our payment service provider, to send instructions to your bank to debit your account and your bank to debit your account in accordance with those instructions. You are entitled to a refund from your bank under the terms and conditions of your agreement with your bank. A refund must be claimed within 8 weeks starting from the date on which your account was debited.', 'woocommerce-gateway-stripe' ), WC_Stripe_Helper::clean_statement_descriptor( $this->statement_descriptor ) );
230
+		printf(__('By providing your IBAN and confirming this payment, you are authorizing %s and Stripe, our payment service provider, to send instructions to your bank to debit your account and your bank to debit your account in accordance with those instructions. You are entitled to a refund from your bank under the terms and conditions of your agreement with your bank. A refund must be claimed within 8 weeks starting from the date on which your account was debited.', 'woocommerce-gateway-stripe'), WC_Stripe_Helper::clean_statement_descriptor($this->statement_descriptor));
231 231
 	}
232 232
 
233 233
 	/**
@@ -238,24 +238,24 @@  discard block
 block discarded – undo
238 238
 	 */
239 239
 	public function form() {
240 240
 		?>
241
-		<fieldset id="wc-<?php echo esc_attr( $this->id ); ?>-form" class="wc-payment-form">
242
-			<?php do_action( 'woocommerce_credit_card_form_start', $this->id ); ?>
241
+		<fieldset id="wc-<?php echo esc_attr($this->id); ?>-form" class="wc-payment-form">
242
+			<?php do_action('woocommerce_credit_card_form_start', $this->id); ?>
243 243
 			<p class="wc-stripe-sepa-mandate" style="margin-bottom:40px;"><?php $this->mandate_display(); ?></p>
244 244
 			<p class="form-row form-row-wide validate-required">
245 245
 				<label for="stripe-sepa-owner">
246
-					<?php esc_html_e( 'IBAN Account Name.', 'woocommerce-gateway-stripe' ); ?>
246
+					<?php esc_html_e('IBAN Account Name.', 'woocommerce-gateway-stripe'); ?>
247 247
 				</label>
248 248
 				<input id="stripe-sepa-owner" name="stripe_sepa_owner" value="" style="border:1px solid #ddd;margin:5px 0;padding:10px 5px;background-color:#fff;outline:0;" />
249 249
 			</p>
250 250
 			<p class="form-row form-row-wide validate-required">
251 251
 				<label for="stripe-sepa-iban">
252
-					<?php esc_html_e( 'IBAN Account Number.', 'woocommerce-gateway-stripe' ); ?>
252
+					<?php esc_html_e('IBAN Account Number.', 'woocommerce-gateway-stripe'); ?>
253 253
 				</label>
254 254
 				<input id="stripe-sepa-iban" name="stripe_sepa_iban" value="" style="border:1px solid #ddd;margin:5px 0;padding:10px 5px;background-color:#fff;outline:0;" />
255 255
 			</p>
256 256
 			<!-- Used to display form errors -->
257 257
 			<div class="stripe-source-errors" role="alert"></div>
258
-			<?php do_action( 'woocommerce_credit_card_form_end', $this->id ); ?>
258
+			<?php do_action('woocommerce_credit_card_form_end', $this->id); ?>
259 259
 			<div class="clear"></div>
260 260
 		</fieldset>
261 261
 		<?php
@@ -267,42 +267,42 @@  discard block
 block discarded – undo
267 267
 	public function payment_fields() {
268 268
 		$user                 = wp_get_current_user();
269 269
 		$total                = WC()->cart->total;
270
-		$display_tokenization = $this->supports( 'tokenization' ) && is_checkout() && $this->saved_cards;
270
+		$display_tokenization = $this->supports('tokenization') && is_checkout() && $this->saved_cards;
271 271
 
272 272
 		// If paying from order, we need to get total from order not cart.
273
-		if ( isset( $_GET['pay_for_order'] ) && ! empty( $_GET['key'] ) ) {
274
-			$order = wc_get_order( wc_get_order_id_by_order_key( wc_clean( $_GET['key'] ) ) );
273
+		if (isset($_GET['pay_for_order']) && ! empty($_GET['key'])) {
274
+			$order = wc_get_order(wc_get_order_id_by_order_key(wc_clean($_GET['key'])));
275 275
 			$total = $order->get_total();
276 276
 		}
277 277
 
278
-		if ( is_add_payment_method_page() ) {
279
-			$pay_button_text = __( 'Add Payment', 'woocommerce-gateway-stripe' );
280
-			$total        = '';
278
+		if (is_add_payment_method_page()) {
279
+			$pay_button_text = __('Add Payment', 'woocommerce-gateway-stripe');
280
+			$total = '';
281 281
 		} else {
282 282
 			$pay_button_text = '';
283 283
 		}
284 284
 
285 285
 		echo '<div
286 286
 			id="stripe-sepa_debit-payment-data"
287
-			data-amount="' . esc_attr( WC_Stripe_Helper::get_stripe_amount( $total ) ) . '"
288
-			data-currency="' . esc_attr( strtolower( get_woocommerce_currency() ) ) . '">';
287
+			data-amount="' . esc_attr(WC_Stripe_Helper::get_stripe_amount($total)) . '"
288
+			data-currency="' . esc_attr(strtolower(get_woocommerce_currency())) . '">';
289 289
 
290
-		if ( $this->description ) {
291
-			if ( $this->testmode ) {
292
-				$this->description .= ' ' . __( 'TEST MODE ENABLED. In test mode, you can use IBAN number DE89370400440532013000.', 'woocommerce-gateway-stripe' );
293
-				$this->description  = trim( $this->description );
290
+		if ($this->description) {
291
+			if ($this->testmode) {
292
+				$this->description .= ' ' . __('TEST MODE ENABLED. In test mode, you can use IBAN number DE89370400440532013000.', 'woocommerce-gateway-stripe');
293
+				$this->description  = trim($this->description);
294 294
 			}
295
-			echo apply_filters( 'wc_stripe_description', wpautop( wp_kses_post( $this->description ) ) );
295
+			echo apply_filters('wc_stripe_description', wpautop(wp_kses_post($this->description)));
296 296
 		}
297 297
 
298
-		if ( $display_tokenization ) {
298
+		if ($display_tokenization) {
299 299
 			$this->tokenization_script();
300 300
 			$this->saved_payment_methods();
301 301
 		}
302 302
 
303 303
 		$this->form();
304 304
 
305
-		if ( apply_filters( 'wc_stripe_display_save_payment_method_checkbox', $display_tokenization ) && ! is_add_payment_method_page() && ! isset( $_GET['change_payment_method'] ) ) {
305
+		if (apply_filters('wc_stripe_display_save_payment_method_checkbox', $display_tokenization) && ! is_add_payment_method_page() && ! isset($_GET['change_payment_method'])) {
306 306
 			$this->save_payment_method_checkbox();
307 307
 		}
308 308
 
@@ -320,80 +320,80 @@  discard block
 block discarded – undo
320 320
 	 *
321 321
 	 * @return array|void
322 322
 	 */
323
-	public function process_payment( $order_id, $retry = true, $force_save_source = false ) {
323
+	public function process_payment($order_id, $retry = true, $force_save_source = false) {
324 324
 		try {
325
-			$order = wc_get_order( $order_id );
325
+			$order = wc_get_order($order_id);
326 326
 
327 327
 			// This comes from the create account checkbox in the checkout page.
328
-			$create_account = ! empty( $_POST['createaccount'] ) ? true : false;
328
+			$create_account = ! empty($_POST['createaccount']) ? true : false;
329 329
 
330
-			if ( $create_account ) {
330
+			if ($create_account) {
331 331
 				$new_customer_id     = WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id();
332
-				$new_stripe_customer = new WC_Stripe_Customer( $new_customer_id );
332
+				$new_stripe_customer = new WC_Stripe_Customer($new_customer_id);
333 333
 				$new_stripe_customer->create_customer();
334 334
 			}
335 335
 
336
-			$prepared_source = $this->prepare_source( $this->create_source_object(), get_current_user_id(), $force_save_source );
336
+			$prepared_source = $this->prepare_source($this->create_source_object(), get_current_user_id(), $force_save_source);
337 337
 
338 338
 			// Store source to order meta.
339
-			$this->save_source( $order, $prepared_source );
339
+			$this->save_source($order, $prepared_source);
340 340
 
341 341
 			// Result from Stripe API request.
342 342
 			$response = null;
343 343
 
344
-			if ( $order->get_total() > 0 ) {
344
+			if ($order->get_total() > 0) {
345 345
 				// This will throw exception if not valid.
346
-				$this->validate_minimum_order_amount( $order );
346
+				$this->validate_minimum_order_amount($order);
347 347
 
348
-				WC_Stripe_Logger::log( "Info: Begin processing payment for order $order_id for the amount of {$order->get_total()}" );
348
+				WC_Stripe_Logger::log("Info: Begin processing payment for order $order_id for the amount of {$order->get_total()}");
349 349
 
350 350
 				// Make the request.
351
-				$response = WC_Stripe_API::request( $this->generate_payment_request( $order, $prepared_source ) );
351
+				$response = WC_Stripe_API::request($this->generate_payment_request($order, $prepared_source));
352 352
 
353
-				if ( ! empty( $response->error ) ) {
353
+				if ( ! empty($response->error)) {
354 354
 					// If it is an API error such connection or server, let's retry.
355
-					if ( 'api_connection_error' === $response->error->type || 'api_error' === $response->error->type ) {
356
-						if ( $retry ) {
357
-							sleep( 5 );
358
-							return $this->process_payment( $order_id, false, $force_save_source );
355
+					if ('api_connection_error' === $response->error->type || 'api_error' === $response->error->type) {
356
+						if ($retry) {
357
+							sleep(5);
358
+							return $this->process_payment($order_id, false, $force_save_source);
359 359
 						} else {
360 360
 							$localized_message = 'API connection error and retries exhausted.';
361
-							$order->add_order_note( $localized_message );
362
-							throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message );
361
+							$order->add_order_note($localized_message);
362
+							throw new WC_Stripe_Exception(print_r($response, true), $localized_message);
363 363
 						}
364 364
 					}
365 365
 
366 366
 					// Customer param wrong? The user may have been deleted on stripe's end. Remove customer_id. Can be retried without.
367
-					if ( preg_match( '/No such customer/i', $response->error->message ) && $retry ) {
368
-						delete_user_meta( WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id(), '_stripe_customer_id' );
367
+					if (preg_match('/No such customer/i', $response->error->message) && $retry) {
368
+						delete_user_meta(WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id(), '_stripe_customer_id');
369 369
 
370
-						return $this->process_payment( $order_id, false, $force_save_source );
371
-					} elseif ( preg_match( '/No such token/i', $response->error->message ) && $prepared_source->token_id ) {
370
+						return $this->process_payment($order_id, false, $force_save_source);
371
+					} elseif (preg_match('/No such token/i', $response->error->message) && $prepared_source->token_id) {
372 372
 						// Source param wrong? The CARD may have been deleted on stripe's end. Remove token and show message.
373
-						$wc_token = WC_Payment_Tokens::get( $prepared_source->token_id );
373
+						$wc_token = WC_Payment_Tokens::get($prepared_source->token_id);
374 374
 						$wc_token->delete();
375
-						$localized_message = __( 'This card is no longer available and has been removed.', 'woocommerce-gateway-stripe' );
376
-						$order->add_order_note( $localized_message );
377
-						throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message );
375
+						$localized_message = __('This card is no longer available and has been removed.', 'woocommerce-gateway-stripe');
376
+						$order->add_order_note($localized_message);
377
+						throw new WC_Stripe_Exception(print_r($response, true), $localized_message);
378 378
 					}
379 379
 
380 380
 					$localized_messages = WC_Stripe_Helper::get_localized_messages();
381 381
 
382
-					if ( 'card_error' === $response->error->type ) {
383
-						$localized_message = isset( $localized_messages[ $response->error->code ] ) ? $localized_messages[ $response->error->code ] : $response->error->message;
382
+					if ('card_error' === $response->error->type) {
383
+						$localized_message = isset($localized_messages[$response->error->code]) ? $localized_messages[$response->error->code] : $response->error->message;
384 384
 					} else {
385
-						$localized_message = isset( $localized_messages[ $response->error->type ] ) ? $localized_messages[ $response->error->type ] : $response->error->message;
385
+						$localized_message = isset($localized_messages[$response->error->type]) ? $localized_messages[$response->error->type] : $response->error->message;
386 386
 					}
387 387
 
388
-					$order->add_order_note( $localized_message );
388
+					$order->add_order_note($localized_message);
389 389
 
390
-					throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message );
390
+					throw new WC_Stripe_Exception(print_r($response, true), $localized_message);
391 391
 				}
392 392
 
393
-				do_action( 'wc_gateway_stripe_process_payment', $response, $order );
393
+				do_action('wc_gateway_stripe_process_payment', $response, $order);
394 394
 
395 395
 				// Process valid response.
396
-				$this->process_response( $response, $order );
396
+				$this->process_response($response, $order);
397 397
 			} else {
398 398
 				$order->payment_complete();
399 399
 			}
@@ -404,17 +404,17 @@  discard block
 block discarded – undo
404 404
 			// Return thank you page redirect.
405 405
 			return array(
406 406
 				'result'   => 'success',
407
-				'redirect' => $this->get_return_url( $order ),
407
+				'redirect' => $this->get_return_url($order),
408 408
 			);
409 409
 
410
-		} catch ( WC_Stripe_Exception $e ) {
411
-			wc_add_notice( $e->getLocalizedMessage(), 'error' );
412
-			WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() );
410
+		} catch (WC_Stripe_Exception $e) {
411
+			wc_add_notice($e->getLocalizedMessage(), 'error');
412
+			WC_Stripe_Logger::log('Error: ' . $e->getMessage());
413 413
 
414
-			do_action( 'wc_gateway_stripe_process_payment_error', $e, $order );
414
+			do_action('wc_gateway_stripe_process_payment_error', $e, $order);
415 415
 
416
-			if ( $order->has_status( array( 'pending', 'failed' ) ) ) {
417
-				$this->send_failed_order_email( $order_id );
416
+			if ($order->has_status(array('pending', 'failed'))) {
417
+				$this->send_failed_order_email($order_id);
418 418
 			}
419 419
 
420 420
 			return array(
Please login to merge, or discard this patch.
includes/payment-methods/class-wc-gateway-stripe-bitcoin.php 1 patch
Spacing   +87 added lines, -87 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
 
@@ -64,9 +64,9 @@  discard block
 block discarded – undo
64 64
 	 */
65 65
 	public function __construct() {
66 66
 		$this->id                   = 'stripe_bitcoin';
67
-		$this->method_title         = __( 'Stripe Bitcoin', 'woocommerce-gateway-stripe' );
67
+		$this->method_title         = __('Stripe Bitcoin', 'woocommerce-gateway-stripe');
68 68
 		/* translators: link */
69
-		$this->method_description   = sprintf( __( 'All other general Stripe settings can be adjusted <a href="%s">here</a>.', 'woocommerce-gateway-stripe' ), admin_url( 'admin.php?page=wc-settings&tab=checkout&section=stripe' ) );
69
+		$this->method_description   = sprintf(__('All other general Stripe settings can be adjusted <a href="%s">here</a>.', 'woocommerce-gateway-stripe'), admin_url('admin.php?page=wc-settings&tab=checkout&section=stripe'));
70 70
 		$this->supports             = array(
71 71
 			'products',
72 72
 			'refunds',
@@ -78,29 +78,29 @@  discard block
 block discarded – undo
78 78
 		// Load the settings.
79 79
 		$this->init_settings();
80 80
 
81
-		$main_settings              = get_option( 'woocommerce_stripe_settings' );
82
-		$this->title                = $this->get_option( 'title' );
83
-		$this->description          = $this->get_option( 'description' );
84
-		$this->enabled              = $this->get_option( 'enabled' );
85
-		$this->testmode             = ( ! empty( $main_settings['testmode'] ) && 'yes' === $main_settings['testmode'] ) ? true : false;
86
-		$this->saved_cards          = ( ! empty( $main_settings['saved_cards'] ) && 'yes' === $main_settings['saved_cards'] ) ? true : false;
87
-		$this->publishable_key      = ! empty( $main_settings['publishable_key'] ) ? $main_settings['publishable_key'] : '';
88
-		$this->secret_key           = ! empty( $main_settings['secret_key'] ) ? $main_settings['secret_key'] : '';
89
-		$this->statement_descriptor = ! empty( $main_settings['statement_descriptor'] ) ? $main_settings['statement_descriptor'] : '';
90
-
91
-		if ( $this->testmode ) {
92
-			$this->publishable_key = ! empty( $main_settings['test_publishable_key'] ) ? $main_settings['test_publishable_key'] : '';
93
-			$this->secret_key      = ! empty( $main_settings['test_secret_key'] ) ? $main_settings['test_secret_key'] : '';
81
+		$main_settings              = get_option('woocommerce_stripe_settings');
82
+		$this->title                = $this->get_option('title');
83
+		$this->description          = $this->get_option('description');
84
+		$this->enabled              = $this->get_option('enabled');
85
+		$this->testmode             = ( ! empty($main_settings['testmode']) && 'yes' === $main_settings['testmode']) ? true : false;
86
+		$this->saved_cards          = ( ! empty($main_settings['saved_cards']) && 'yes' === $main_settings['saved_cards']) ? true : false;
87
+		$this->publishable_key      = ! empty($main_settings['publishable_key']) ? $main_settings['publishable_key'] : '';
88
+		$this->secret_key           = ! empty($main_settings['secret_key']) ? $main_settings['secret_key'] : '';
89
+		$this->statement_descriptor = ! empty($main_settings['statement_descriptor']) ? $main_settings['statement_descriptor'] : '';
90
+
91
+		if ($this->testmode) {
92
+			$this->publishable_key = ! empty($main_settings['test_publishable_key']) ? $main_settings['test_publishable_key'] : '';
93
+			$this->secret_key      = ! empty($main_settings['test_secret_key']) ? $main_settings['test_secret_key'] : '';
94 94
 		}
95 95
 
96
-		add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) );
97
-		add_action( 'admin_notices', array( $this, 'check_environment' ) );
98
-		add_action( 'admin_head', array( $this, 'remove_admin_notice' ) );
99
-		add_action( 'wp_enqueue_scripts', array( $this, 'payment_scripts' ) );
100
-		add_action( 'woocommerce_thankyou_stripe_bitcoin', array( $this, 'thankyou_page' ) );
96
+		add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options'));
97
+		add_action('admin_notices', array($this, 'check_environment'));
98
+		add_action('admin_head', array($this, 'remove_admin_notice'));
99
+		add_action('wp_enqueue_scripts', array($this, 'payment_scripts'));
100
+		add_action('woocommerce_thankyou_stripe_bitcoin', array($this, 'thankyou_page'));
101 101
 
102 102
 		// Customer Emails
103
-		add_action( 'woocommerce_email_before_order_table', array( $this, 'email_instructions' ), 10, 3 );
103
+		add_action('woocommerce_email_before_order_table', array($this, 'email_instructions'), 10, 3);
104 104
 	}
105 105
 
106 106
 	/**
@@ -110,19 +110,19 @@  discard block
 block discarded – undo
110 110
 	 * @version 4.0.0
111 111
 	 */
112 112
 	public function check_environment() {
113
-		if ( ! current_user_can( 'manage_woocommerce' ) ) {
113
+		if ( ! current_user_can('manage_woocommerce')) {
114 114
 			return;
115 115
 		}
116 116
 
117 117
 		$environment_warning = $this->get_environment_warning();
118 118
 
119
-		if ( $environment_warning ) {
120
-			$this->add_admin_notice( 'bad_environment', 'error', $environment_warning );
119
+		if ($environment_warning) {
120
+			$this->add_admin_notice('bad_environment', 'error', $environment_warning);
121 121
 		}
122 122
 
123
-		foreach ( (array) $this->notices as $notice_key => $notice ) {
124
-			echo "<div class='" . esc_attr( $notice['class'] ) . "'><p>";
125
-			echo wp_kses( $notice['message'], array( 'a' => array( 'href' => array() ) ) );
123
+		foreach ((array) $this->notices as $notice_key => $notice) {
124
+			echo "<div class='" . esc_attr($notice['class']) . "'><p>";
125
+			echo wp_kses($notice['message'], array('a' => array('href' => array())));
126 126
 			echo '</p></div>';
127 127
 		}
128 128
 	}
@@ -135,8 +135,8 @@  discard block
 block discarded – undo
135 135
 	 * @version 4.0.0
136 136
 	 */
137 137
 	public function get_environment_warning() {
138
-		if ( 'yes' === $this->enabled && ! in_array( get_woocommerce_currency(), $this->get_supported_currency() ) ) {
139
-			$message = __( 'Bitcoin is enabled - it requires store currency to be set to USD.', 'woocommerce-gateway-stripe' );
138
+		if ('yes' === $this->enabled && ! in_array(get_woocommerce_currency(), $this->get_supported_currency())) {
139
+			$message = __('Bitcoin is enabled - it requires store currency to be set to USD.', 'woocommerce-gateway-stripe');
140 140
 
141 141
 			return $message;
142 142
 		}
@@ -152,9 +152,9 @@  discard block
 block discarded – undo
152 152
 	 * @return array
153 153
 	 */
154 154
 	public function get_supported_currency() {
155
-		return apply_filters( 'wc_stripe_bitcoin_supported_currencies', array(
155
+		return apply_filters('wc_stripe_bitcoin_supported_currencies', array(
156 156
 			'USD',
157
-		) );
157
+		));
158 158
 	}
159 159
 
160 160
 	/**
@@ -165,7 +165,7 @@  discard block
 block discarded – undo
165 165
 	 * @return bool
166 166
 	 */
167 167
 	public function is_available() {
168
-		if ( ! in_array( get_woocommerce_currency(), $this->get_supported_currency() ) ) {
168
+		if ( ! in_array(get_woocommerce_currency(), $this->get_supported_currency())) {
169 169
 			return false;
170 170
 		}
171 171
 
@@ -186,7 +186,7 @@  discard block
 block discarded – undo
186 186
 
187 187
 		$icons_str .= $icons['bitcoin'];
188 188
 
189
-		return apply_filters( 'woocommerce_gateway_icon', $icons_str, $this->id );
189
+		return apply_filters('woocommerce_gateway_icon', $icons_str, $this->id);
190 190
 	}
191 191
 
192 192
 	/**
@@ -197,19 +197,19 @@  discard block
 block discarded – undo
197 197
 	 * @access public
198 198
 	 */
199 199
 	public function payment_scripts() {
200
-		if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) && ! is_add_payment_method_page() ) {
200
+		if ( ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order']) && ! is_add_payment_method_page()) {
201 201
 			return;
202 202
 		}
203 203
 
204
-		wp_enqueue_style( 'stripe_paymentfonts' );
205
-		wp_enqueue_script( 'woocommerce_stripe' );
204
+		wp_enqueue_style('stripe_paymentfonts');
205
+		wp_enqueue_script('woocommerce_stripe');
206 206
 	}
207 207
 
208 208
 	/**
209 209
 	 * Initialize Gateway Settings Form Fields.
210 210
 	 */
211 211
 	public function init_form_fields() {
212
-		$this->form_fields = require( WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-bitcoin-settings.php' );
212
+		$this->form_fields = require(WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-bitcoin-settings.php');
213 213
 	}
214 214
 
215 215
 	/**
@@ -220,25 +220,25 @@  discard block
 block discarded – undo
220 220
 		$total                = WC()->cart->total;
221 221
 
222 222
 		// If paying from order, we need to get total from order not cart.
223
-		if ( isset( $_GET['pay_for_order'] ) && ! empty( $_GET['key'] ) ) {
224
-			$order = wc_get_order( wc_get_order_id_by_order_key( wc_clean( $_GET['key'] ) ) );
223
+		if (isset($_GET['pay_for_order']) && ! empty($_GET['key'])) {
224
+			$order = wc_get_order(wc_get_order_id_by_order_key(wc_clean($_GET['key'])));
225 225
 			$total = $order->get_total();
226 226
 		}
227 227
 
228
-		if ( is_add_payment_method_page() ) {
229
-			$pay_button_text = __( 'Add Payment', 'woocommerce-gateway-stripe' );
230
-			$total        = '';
228
+		if (is_add_payment_method_page()) {
229
+			$pay_button_text = __('Add Payment', 'woocommerce-gateway-stripe');
230
+			$total = '';
231 231
 		} else {
232 232
 			$pay_button_text = '';
233 233
 		}
234 234
 
235 235
 		echo '<div
236 236
 			id="stripe-bitcoin-payment-data"
237
-			data-amount="' . esc_attr( WC_Stripe_Helper::get_stripe_amount( $total ) ) . '"
238
-			data-currency="' . esc_attr( strtolower( get_woocommerce_currency() ) ) . '">';
237
+			data-amount="' . esc_attr(WC_Stripe_Helper::get_stripe_amount($total)) . '"
238
+			data-currency="' . esc_attr(strtolower(get_woocommerce_currency())) . '">';
239 239
 
240
-		if ( $this->description ) {
241
-			echo apply_filters( 'wc_stripe_description', wpautop( wp_kses_post( $this->description ) ) );
240
+		if ($this->description) {
241
+			echo apply_filters('wc_stripe_description', wpautop(wp_kses_post($this->description)));
242 242
 		}
243 243
 
244 244
 		echo '</div>';
@@ -249,8 +249,8 @@  discard block
 block discarded – undo
249 249
 	 *
250 250
 	 * @param int $order_id
251 251
 	 */
252
-	public function thankyou_page( $order_id ) {
253
-		$this->get_instructions( $order_id );
252
+	public function thankyou_page($order_id) {
253
+		$this->get_instructions($order_id);
254 254
 	}
255 255
 
256 256
 	/**
@@ -262,13 +262,13 @@  discard block
 block discarded – undo
262 262
 	 * @param bool $sent_to_admin
263 263
 	 * @param bool $plain_text
264 264
 	 */
265
-	public function email_instructions( $order, $sent_to_admin, $plain_text = false ) {
265
+	public function email_instructions($order, $sent_to_admin, $plain_text = false) {
266 266
 		$order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
267 267
 
268 268
 		$payment_method = WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method();
269 269
 
270
-		if ( ! $sent_to_admin && 'stripe_bitcoin' === $payment_method && $order->has_status( 'on-hold' ) ) {
271
-			$this->get_instructions( $order_id, $plain_text );
270
+		if ( ! $sent_to_admin && 'stripe_bitcoin' === $payment_method && $order->has_status('on-hold')) {
271
+			$this->get_instructions($order_id, $plain_text);
272 272
 		}
273 273
 	}
274 274
 
@@ -279,38 +279,38 @@  discard block
 block discarded – undo
279 279
 	 * @version 4.0.0
280 280
 	 * @param int $order_id
281 281
 	 */
282
-	public function get_instructions( $order_id, $plain_text = false ) {
283
-		$data = get_post_meta( $order_id, '_stripe_bitcoin', true );
282
+	public function get_instructions($order_id, $plain_text = false) {
283
+		$data = get_post_meta($order_id, '_stripe_bitcoin', true);
284 284
 
285
-		if ( $plain_text ) {
286
-			esc_html_e( 'Please pay the following:', 'woocommerce-gateway-stripe' ) . "\n\n";
285
+		if ($plain_text) {
286
+			esc_html_e('Please pay the following:', 'woocommerce-gateway-stripe') . "\n\n";
287 287
 			echo "=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\n\n";
288
-			esc_html_e( 'Bitcoin Amount:', 'woocommerce-gateway-stripe' ) . "\n\n";
288
+			esc_html_e('Bitcoin Amount:', 'woocommerce-gateway-stripe') . "\n\n";
289 289
 			echo $data['amount'] . "\n\n";
290 290
 			echo "=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\n\n";
291
-			esc_html_e( 'Receiver:', 'woocommerce-gateway-stripe' ) . "\n\n";
291
+			esc_html_e('Receiver:', 'woocommerce-gateway-stripe') . "\n\n";
292 292
 			echo $data['address'] . "\n\n";
293 293
 			echo "=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\n\n";
294
-			esc_html_e( 'URI:', 'woocommerce-gateway-stripe' ) . "\n\n";
294
+			esc_html_e('URI:', 'woocommerce-gateway-stripe') . "\n\n";
295 295
 			echo $data['uri'] . "\n\n";
296 296
 		} else {
297 297
 			?>
298
-			<h3><?php esc_html_e( 'Please pay the following:', 'woocommerce-gateway-stripe' ); ?></h3>
298
+			<h3><?php esc_html_e('Please pay the following:', 'woocommerce-gateway-stripe'); ?></h3>
299 299
 			<ul class="woocommerce-order-overview woocommerce-thankyou-order-details order_details">
300 300
 			<li class="woocommerce-order-overview__order order">
301
-				<?php esc_html_e( 'Bitcoin Amount:', 'woocommerce-gateway-stripe' ); ?>
301
+				<?php esc_html_e('Bitcoin Amount:', 'woocommerce-gateway-stripe'); ?>
302 302
 				<strong><?php echo $data['amount']; ?></strong>
303 303
 			</li>
304 304
 			<li class="woocommerce-order-overview__order order">
305
-				<?php esc_html_e( 'Receiver:', 'woocommerce-gateway-stripe' ); ?>
305
+				<?php esc_html_e('Receiver:', 'woocommerce-gateway-stripe'); ?>
306 306
 				<strong><?php echo $data['address']; ?></strong>
307 307
 			</li>
308 308
 			<li class="woocommerce-order-overview__order order">
309
-				<?php esc_html_e( 'URI:', 'woocommerce-gateway-stripe' ); ?>
309
+				<?php esc_html_e('URI:', 'woocommerce-gateway-stripe'); ?>
310 310
 				<strong>
311 311
 				<?php
312 312
 				/* translators: link */
313
-				printf( __( '<a href="%s">Pay Bitcoin</a>', 'woocommerce-gateway-stripe' ), $data['uri'] );
313
+				printf(__('<a href="%s">Pay Bitcoin</a>', 'woocommerce-gateway-stripe'), $data['uri']);
314 314
 				?>
315 315
 				</strong>
316 316
 			</li>
@@ -327,7 +327,7 @@  discard block
 block discarded – undo
327 327
 	 * @param object $order
328 328
 	 * @param object $source_object
329 329
 	 */
330
-	public function save_instructions( $order, $source_object ) {
330
+	public function save_instructions($order, $source_object) {
331 331
 		$data = array(
332 332
 			'amount'  => $source_object->bitcoin->amount,
333 333
 			'address' => $source_object->bitcoin->address,
@@ -336,7 +336,7 @@  discard block
 block discarded – undo
336 336
 
337 337
 		$order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
338 338
 
339
-		update_post_meta( $order_id, '_stripe_bitcoin', $data );
339
+		update_post_meta($order_id, '_stripe_bitcoin', $data);
340 340
 	}
341 341
 
342 342
 	/**
@@ -350,39 +350,39 @@  discard block
 block discarded – undo
350 350
 	 *
351 351
 	 * @return array|void
352 352
 	 */
353
-	public function process_payment( $order_id, $retry = true, $force_save_source = false ) {
353
+	public function process_payment($order_id, $retry = true, $force_save_source = false) {
354 354
 		try {
355
-			$order = wc_get_order( $order_id );
355
+			$order = wc_get_order($order_id);
356 356
 
357 357
 			// This comes from the create account checkbox in the checkout page.
358
-			$create_account = ! empty( $_POST['createaccount'] ) ? true : false;
358
+			$create_account = ! empty($_POST['createaccount']) ? true : false;
359 359
 
360
-			if ( $create_account ) {
360
+			if ($create_account) {
361 361
 				$new_customer_id     = WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id();
362
-				$new_stripe_customer = new WC_Stripe_Customer( $new_customer_id );
362
+				$new_stripe_customer = new WC_Stripe_Customer($new_customer_id);
363 363
 				$new_stripe_customer->create_customer();
364 364
 			}
365 365
 
366
-			$prepared_source = $this->prepare_source( $this->create_source_object(), get_current_user_id(), $force_save_source );
366
+			$prepared_source = $this->prepare_source($this->create_source_object(), get_current_user_id(), $force_save_source);
367 367
 
368
-			if ( empty( $prepared_source->source ) ) {
369
-				$localized_message = __( 'Payment processing failed. Please retry.', 'woocommerce-gateway-stripe' );
370
-				throw new WC_Stripe_Exception( print_r( $prepared_source, true ), $localized_message );
368
+			if (empty($prepared_source->source)) {
369
+				$localized_message = __('Payment processing failed. Please retry.', 'woocommerce-gateway-stripe');
370
+				throw new WC_Stripe_Exception(print_r($prepared_source, true), $localized_message);
371 371
 			}
372 372
 
373 373
 			// Store source to order meta.
374
-			$this->save_source( $order, $prepared_source );
374
+			$this->save_source($order, $prepared_source);
375 375
 
376 376
 
377 377
 			// This will throw exception if not valid.
378
-			$this->validate_minimum_order_amount( $order );
378
+			$this->validate_minimum_order_amount($order);
379 379
 
380
-			$this->save_instructions( $order, $this->create_source_object() );
380
+			$this->save_instructions($order, $this->create_source_object());
381 381
 
382 382
 			// Mark as on-hold (we're awaiting the payment)
383
-			$order->update_status( 'on-hold', __( 'Awaiting Bitcoin payment', 'woocommerce-gateway-stripe' ) );
383
+			$order->update_status('on-hold', __('Awaiting Bitcoin payment', 'woocommerce-gateway-stripe'));
384 384
 
385
-			wc_reduce_stock_levels( $order_id );
385
+			wc_reduce_stock_levels($order_id);
386 386
 
387 387
 			// Remove cart
388 388
 			WC()->cart->empty_cart();
@@ -390,16 +390,16 @@  discard block
 block discarded – undo
390 390
 			// Return thankyou redirect
391 391
 			return array(
392 392
 				'result'    => 'success',
393
-				'redirect'  => $this->get_return_url( $order ),
393
+				'redirect'  => $this->get_return_url($order),
394 394
 			);
395
-		} catch ( WC_Stripe_Exception $e ) {
396
-			wc_add_notice( $e->getLocalizedMessage(), 'error' );
397
-			WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() );
395
+		} catch (WC_Stripe_Exception $e) {
396
+			wc_add_notice($e->getLocalizedMessage(), 'error');
397
+			WC_Stripe_Logger::log('Error: ' . $e->getMessage());
398 398
 
399
-			do_action( 'wc_gateway_stripe_process_payment_error', $e, $order );
399
+			do_action('wc_gateway_stripe_process_payment_error', $e, $order);
400 400
 
401
-			if ( $order->has_status( array( 'pending', 'failed' ) ) ) {
402
-				$this->send_failed_order_email( $order_id );
401
+			if ($order->has_status(array('pending', 'failed'))) {
402
+				$this->send_failed_order_email($order_id);
403 403
 			}
404 404
 
405 405
 			return array(
Please login to merge, or discard this patch.
includes/class-wc-gateway-stripe.php 1 patch
Spacing   +204 added lines, -204 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
 
@@ -119,9 +119,9 @@  discard block
 block discarded – undo
119 119
 	 */
120 120
 	public function __construct() {
121 121
 		$this->id                   = 'stripe';
122
-		$this->method_title         = __( 'Stripe', 'woocommerce-gateway-stripe' );
122
+		$this->method_title         = __('Stripe', 'woocommerce-gateway-stripe');
123 123
 		/* translators: 1) link to Stripe register page 2) link to Stripe api keys page */
124
-		$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' );
124
+		$this->method_description   = sprintf(__('Stripe works by adding payment fields on the checkout and then sending the details to Stripe for verification. <a href="%1$s" target="_blank">Sign up</a> for a Stripe account, and <a href="%2$s" target="_blank">get your Stripe account keys</a>.', 'woocommerce-gateway-stripe'), 'https://dashboard.stripe.com/register', 'https://dashboard.stripe.com/account/apikeys');
125 125
 		$this->has_fields           = true;
126 126
 		$this->supports             = array(
127 127
 			'products',
@@ -148,38 +148,38 @@  discard block
 block discarded – undo
148 148
 		$this->init_settings();
149 149
 
150 150
 		// Get setting values.
151
-		$this->title                   = $this->get_option( 'title' );
152
-		$this->description             = $this->get_option( 'description' );
153
-		$this->enabled                 = $this->get_option( 'enabled' );
154
-		$this->testmode                = 'yes' === $this->get_option( 'testmode' );
155
-		$this->inline_cc_form          = 'yes' === $this->get_option( 'inline_cc_form' );
156
-		$this->capture                 = 'yes' === $this->get_option( 'capture', 'yes' );
157
-		$this->statement_descriptor    = WC_Stripe_Helper::clean_statement_descriptor( $this->get_option( 'statement_descriptor' ) );
158
-		$this->three_d_secure          = 'yes' === $this->get_option( 'three_d_secure' );
159
-		$this->stripe_checkout         = 'yes' === $this->get_option( 'stripe_checkout' );
160
-		$this->stripe_checkout_locale  = $this->get_option( 'stripe_checkout_locale' );
161
-		$this->stripe_checkout_image   = $this->get_option( 'stripe_checkout_image', '' );
162
-		$this->saved_cards             = 'yes' === $this->get_option( 'saved_cards' );
163
-		$this->secret_key              = $this->testmode ? $this->get_option( 'test_secret_key' ) : $this->get_option( 'secret_key' );
164
-		$this->publishable_key         = $this->testmode ? $this->get_option( 'test_publishable_key' ) : $this->get_option( 'publishable_key' );
165
-		$this->bitcoin                 = 'USD' === strtoupper( get_woocommerce_currency() ) && 'yes' === $this->get_option( 'stripe_bitcoin' );
166
-		$this->payment_request         = 'yes' === $this->get_option( 'payment_request', 'yes' );
167
-		$this->apple_pay_domain_set    = 'yes' === $this->get_option( 'apple_pay_domain_set', 'no' );
151
+		$this->title                   = $this->get_option('title');
152
+		$this->description             = $this->get_option('description');
153
+		$this->enabled                 = $this->get_option('enabled');
154
+		$this->testmode                = 'yes' === $this->get_option('testmode');
155
+		$this->inline_cc_form          = 'yes' === $this->get_option('inline_cc_form');
156
+		$this->capture                 = 'yes' === $this->get_option('capture', 'yes');
157
+		$this->statement_descriptor    = WC_Stripe_Helper::clean_statement_descriptor($this->get_option('statement_descriptor'));
158
+		$this->three_d_secure          = 'yes' === $this->get_option('three_d_secure');
159
+		$this->stripe_checkout         = 'yes' === $this->get_option('stripe_checkout');
160
+		$this->stripe_checkout_locale  = $this->get_option('stripe_checkout_locale');
161
+		$this->stripe_checkout_image   = $this->get_option('stripe_checkout_image', '');
162
+		$this->saved_cards             = 'yes' === $this->get_option('saved_cards');
163
+		$this->secret_key              = $this->testmode ? $this->get_option('test_secret_key') : $this->get_option('secret_key');
164
+		$this->publishable_key         = $this->testmode ? $this->get_option('test_publishable_key') : $this->get_option('publishable_key');
165
+		$this->bitcoin                 = 'USD' === strtoupper(get_woocommerce_currency()) && 'yes' === $this->get_option('stripe_bitcoin');
166
+		$this->payment_request         = 'yes' === $this->get_option('payment_request', 'yes');
167
+		$this->apple_pay_domain_set    = 'yes' === $this->get_option('apple_pay_domain_set', 'no');
168 168
 		$this->apple_pay_verify_notice = '';
169 169
 
170
-		if ( $this->stripe_checkout ) {
171
-			$this->order_button_text = __( 'Continue to payment', 'woocommerce-gateway-stripe' );
170
+		if ($this->stripe_checkout) {
171
+			$this->order_button_text = __('Continue to payment', 'woocommerce-gateway-stripe');
172 172
 		}
173 173
 
174
-		WC_Stripe_API::set_secret_key( $this->secret_key );
174
+		WC_Stripe_API::set_secret_key($this->secret_key);
175 175
 
176 176
 		$this->init_apple_pay();
177 177
 
178 178
 		// Hooks.
179
-		add_action( 'wp_enqueue_scripts', array( $this, 'payment_scripts' ) );
180
-		add_action( 'admin_enqueue_scripts', array( $this, 'admin_scripts' ) );
181
-		add_action( 'admin_notices', array( $this, 'admin_notices' ) );
182
-		add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) );
179
+		add_action('wp_enqueue_scripts', array($this, 'payment_scripts'));
180
+		add_action('admin_enqueue_scripts', array($this, 'admin_scripts'));
181
+		add_action('admin_notices', array($this, 'admin_notices'));
182
+		add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options'));
183 183
 	}
184 184
 
185 185
 	/**
@@ -188,7 +188,7 @@  discard block
 block discarded – undo
188 188
 	 * @since 4.0.2
189 189
 	 */
190 190
 	public function is_available() {
191
-		if ( is_add_payment_method_page() && ! $this->saved_cards ) {
191
+		if (is_add_payment_method_page() && ! $this->saved_cards) {
192 192
 			return false;
193 193
 		}
194 194
 
@@ -211,17 +211,17 @@  discard block
 block discarded – undo
211 211
 		$icons_str .= $icons['amex'];
212 212
 		$icons_str .= $icons['mastercard'];
213 213
 
214
-		if ( 'USD' === get_woocommerce_currency() ) {
214
+		if ('USD' === get_woocommerce_currency()) {
215 215
 			$icons_str .= $icons['discover'];
216 216
 			$icons_str .= $icons['jcb'];
217 217
 			$icons_str .= $icons['diners'];
218 218
 		}
219 219
 
220
-		if ( $this->bitcoin && $this->stripe_checkout ) {
220
+		if ($this->bitcoin && $this->stripe_checkout) {
221 221
 			$icons_str .= $icons['bitcoin'];
222 222
 		}
223 223
 
224
-		return apply_filters( 'woocommerce_gateway_icon', $icons_str, $this->id );
224
+		return apply_filters('woocommerce_gateway_icon', $icons_str, $this->id);
225 225
 	}
226 226
 
227 227
 	/**
@@ -233,9 +233,9 @@  discard block
 block discarded – undo
233 233
 	public function init_apple_pay() {
234 234
 		if (
235 235
 			is_admin() &&
236
-			isset( $_GET['page'] ) && 'wc-settings' === $_GET['page'] &&
237
-			isset( $_GET['tab'] ) && 'checkout' === $_GET['tab'] &&
238
-			isset( $_GET['section'] ) && 'stripe' === $_GET['section'] &&
236
+			isset($_GET['page']) && 'wc-settings' === $_GET['page'] &&
237
+			isset($_GET['tab']) && 'checkout' === $_GET['tab'] &&
238
+			isset($_GET['section']) && 'stripe' === $_GET['section'] &&
239 239
 			$this->payment_request
240 240
 		) {
241 241
 			$this->process_apple_pay_verification();
@@ -249,9 +249,9 @@  discard block
 block discarded – undo
249 249
 	 * @version 3.1.0
250 250
 	 * @param string $secret_key
251 251
 	 */
252
-	private function register_apple_pay_domain( $secret_key = '' ) {
253
-		if ( empty( $secret_key ) ) {
254
-			throw new Exception( __( 'Unable to verify domain - missing secret key.', 'woocommerce-gateway-stripe' ) );
252
+	private function register_apple_pay_domain($secret_key = '') {
253
+		if (empty($secret_key)) {
254
+			throw new Exception(__('Unable to verify domain - missing secret key.', 'woocommerce-gateway-stripe'));
255 255
 		}
256 256
 
257 257
 		$endpoint = 'https://api.stripe.com/v1/apple_pay/domains';
@@ -265,23 +265,23 @@  discard block
 block discarded – undo
265 265
 			'Authorization' => 'Bearer ' . $secret_key,
266 266
 		);
267 267
 
268
-		$response = wp_remote_post( $endpoint, array(
268
+		$response = wp_remote_post($endpoint, array(
269 269
 			'headers' => $headers,
270
-			'body'    => http_build_query( $data ),
271
-		) );
270
+			'body'    => http_build_query($data),
271
+		));
272 272
 
273
-		if ( is_wp_error( $response ) ) {
273
+		if (is_wp_error($response)) {
274 274
 			/* translators: error message */
275
-			throw new Exception( sprintf( __( 'Unable to verify domain - %s', 'woocommerce-gateway-stripe' ), $response->get_error_message() ) );
275
+			throw new Exception(sprintf(__('Unable to verify domain - %s', 'woocommerce-gateway-stripe'), $response->get_error_message()));
276 276
 		}
277 277
 
278
-		if ( 200 !== $response['response']['code'] ) {
279
-			$parsed_response = json_decode( $response['body'] );
278
+		if (200 !== $response['response']['code']) {
279
+			$parsed_response = json_decode($response['body']);
280 280
 
281 281
 			$this->apple_pay_verify_notice = $parsed_response->error->message;
282 282
 
283 283
 			/* translators: error message */
284
-			throw new Exception( sprintf( __( 'Unable to verify domain - %s', 'woocommerce-gateway-stripe' ), $parsed_response->error->message ) );
284
+			throw new Exception(sprintf(__('Unable to verify domain - %s', 'woocommerce-gateway-stripe'), $parsed_response->error->message));
285 285
 		}
286 286
 	}
287 287
 
@@ -292,48 +292,48 @@  discard block
 block discarded – undo
292 292
 	 * @version 3.1.0
293 293
 	 */
294 294
 	public function process_apple_pay_verification() {
295
-		$gateway_settings = get_option( 'woocommerce_stripe_settings', array() );
295
+		$gateway_settings = get_option('woocommerce_stripe_settings', array());
296 296
 
297 297
 		try {
298
-			$path     = untrailingslashit( $_SERVER['DOCUMENT_ROOT'] );
298
+			$path     = untrailingslashit($_SERVER['DOCUMENT_ROOT']);
299 299
 			$dir      = '.well-known';
300 300
 			$file     = 'apple-developer-merchantid-domain-association';
301 301
 			$fullpath = $path . '/' . $dir . '/' . $file;
302 302
 
303
-			if ( ! empty( $gateway_settings['apple_pay_domain_set'] ) && 'yes' === $gateway_settings['apple_pay_domain_set'] && file_exists( $fullpath ) ) {
303
+			if ( ! empty($gateway_settings['apple_pay_domain_set']) && 'yes' === $gateway_settings['apple_pay_domain_set'] && file_exists($fullpath)) {
304 304
 				return;
305 305
 			}
306 306
 
307
-			if ( ! file_exists( $path . '/' . $dir ) ) {
308
-				if ( ! @mkdir( $path . '/' . $dir, 0755 ) ) {
309
-					throw new Exception( __( 'Unable to create domain association folder to domain root.', 'woocommerce-gateway-stripe' ) );
307
+			if ( ! file_exists($path . '/' . $dir)) {
308
+				if ( ! @mkdir($path . '/' . $dir, 0755)) {
309
+					throw new Exception(__('Unable to create domain association folder to domain root.', 'woocommerce-gateway-stripe'));
310 310
 				}
311 311
 			}
312 312
 
313
-			if ( ! file_exists( $fullpath ) ) {
314
-				if ( ! @copy( WC_STRIPE_PLUGIN_PATH . '/' . $file, $fullpath ) ) {
315
-					throw new Exception( __( 'Unable to copy domain association file to domain root.', 'woocommerce-gateway-stripe' ) );
313
+			if ( ! file_exists($fullpath)) {
314
+				if ( ! @copy(WC_STRIPE_PLUGIN_PATH . '/' . $file, $fullpath)) {
315
+					throw new Exception(__('Unable to copy domain association file to domain root.', 'woocommerce-gateway-stripe'));
316 316
 				}
317 317
 			}
318 318
 
319 319
 			// At this point then the domain association folder and file should be available.
320 320
 			// Proceed to verify/and or verify again.
321
-			$this->register_apple_pay_domain( $this->secret_key );
321
+			$this->register_apple_pay_domain($this->secret_key);
322 322
 
323 323
 			// No errors to this point, verification success!
324 324
 			$gateway_settings['apple_pay_domain_set'] = 'yes';
325 325
 			$this->apple_pay_domain_set = true;
326 326
 
327
-			update_option( 'woocommerce_stripe_settings', $gateway_settings );
327
+			update_option('woocommerce_stripe_settings', $gateway_settings);
328 328
 
329
-			WC_Stripe_Logger::log( 'Your domain has been verified with Apple Pay!' );
329
+			WC_Stripe_Logger::log('Your domain has been verified with Apple Pay!');
330 330
 
331
-		} catch ( Exception $e ) {
331
+		} catch (Exception $e) {
332 332
 			$gateway_settings['apple_pay_domain_set'] = 'no';
333 333
 
334
-			update_option( 'woocommerce_stripe_settings', $gateway_settings );
334
+			update_option('woocommerce_stripe_settings', $gateway_settings);
335 335
 
336
-			WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() );
336
+			WC_Stripe_Logger::log('Error: ' . $e->getMessage());
337 337
 		}
338 338
 	}
339 339
 
@@ -341,11 +341,11 @@  discard block
 block discarded – undo
341 341
 	 * Check if SSL is enabled and notify the user
342 342
 	 */
343 343
 	public function admin_notices() {
344
-		if ( 'no' === $this->enabled ) {
344
+		if ('no' === $this->enabled) {
345 345
 			return;
346 346
 		}
347 347
 
348
-		if ( $this->payment_request && ! empty( $this->apple_pay_verify_notice ) ) {
348
+		if ($this->payment_request && ! empty($this->apple_pay_verify_notice)) {
349 349
 			$allowed_html = array(
350 350
 				'a' => array(
351 351
 					'href' => array(),
@@ -353,7 +353,7 @@  discard block
 block discarded – undo
353 353
 				),
354 354
 			);
355 355
 
356
-			echo '<div class="error stripe-apple-pay-message"><p>' . wp_kses( make_clickable( $this->apple_pay_verify_notice ), $allowed_html ) . '</p></div>';
356
+			echo '<div class="error stripe-apple-pay-message"><p>' . wp_kses(make_clickable($this->apple_pay_verify_notice), $allowed_html) . '</p></div>';
357 357
 		}
358 358
 
359 359
 		/**
@@ -361,9 +361,9 @@  discard block
 block discarded – undo
361 361
 		 * when setting screen is displayed. So if domain verification is not set,
362 362
 		 * something went wrong so lets notify user.
363 363
 		 */
364
-		if ( ! empty( $this->secret_key ) && $this->payment_request && ! $this->apple_pay_domain_set ) {
364
+		if ( ! empty($this->secret_key) && $this->payment_request && ! $this->apple_pay_domain_set) {
365 365
 			/* translators: 1) HTML anchor open tag 2) HTML anchor closing tag */
366
-			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>';
366
+			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>';
367 367
 		}
368 368
 	}
369 369
 
@@ -371,7 +371,7 @@  discard block
 block discarded – undo
371 371
 	 * Initialise Gateway Settings Form Fields
372 372
 	 */
373 373
 	public function init_form_fields() {
374
-		$this->form_fields = require( dirname( __FILE__ ) . '/admin/stripe-settings.php' );
374
+		$this->form_fields = require(dirname(__FILE__) . '/admin/stripe-settings.php');
375 375
 	}
376 376
 
377 377
 	/**
@@ -379,59 +379,59 @@  discard block
 block discarded – undo
379 379
 	 */
380 380
 	public function payment_fields() {
381 381
 		$user                 = wp_get_current_user();
382
-		$display_tokenization = $this->supports( 'tokenization' ) && is_checkout() && $this->saved_cards;
382
+		$display_tokenization = $this->supports('tokenization') && is_checkout() && $this->saved_cards;
383 383
 		$total                = WC()->cart->total;
384 384
 		$user_email           = '';
385 385
 
386 386
 		// If paying from order, we need to get total from order not cart.
387
-		if ( isset( $_GET['pay_for_order'] ) && ! empty( $_GET['key'] ) ) {
388
-			$order      = wc_get_order( wc_get_order_id_by_order_key( wc_clean( $_GET['key'] ) ) );
387
+		if (isset($_GET['pay_for_order']) && ! empty($_GET['key'])) {
388
+			$order      = wc_get_order(wc_get_order_id_by_order_key(wc_clean($_GET['key'])));
389 389
 			$total      = $order->get_total();
390 390
 			$user_email = WC_Stripe_Helper::is_pre_30() ? $order->billing_email : $order->get_billing_email();
391 391
 		} else {
392
-			if ( $user->ID ) {
393
-				$user_email = get_user_meta( $user->ID, 'billing_email', true );
392
+			if ($user->ID) {
393
+				$user_email = get_user_meta($user->ID, 'billing_email', true);
394 394
 				$user_email = $user_email ? $user_email : $user->user_email;
395 395
 			}
396 396
 		}
397 397
 
398
-		if ( is_add_payment_method_page() ) {
399
-			$pay_button_text = __( 'Add Card', 'woocommerce-gateway-stripe' );
400
-			$total        = '';
398
+		if (is_add_payment_method_page()) {
399
+			$pay_button_text = __('Add Card', 'woocommerce-gateway-stripe');
400
+			$total = '';
401 401
 		} else {
402 402
 			$pay_button_text = '';
403 403
 		}
404 404
 
405 405
 		echo '<div
406 406
 			id="stripe-payment-data"
407
-			data-panel-label="' . esc_attr( $pay_button_text ) . '"
407
+			data-panel-label="' . esc_attr($pay_button_text) . '"
408 408
 			data-description=""
409
-			data-email="' . esc_attr( $user_email ) . '"
410
-			data-amount="' . esc_attr( WC_Stripe_Helper::get_stripe_amount( $total ) ) . '"
411
-			data-name="' . esc_attr( $this->statement_descriptor ) . '"
412
-			data-currency="' . esc_attr( strtolower( get_woocommerce_currency() ) ) . '"
413
-			data-image="' . esc_attr( $this->stripe_checkout_image ) . '"
414
-			data-bitcoin="' . esc_attr( ( $this->bitcoin && $this->capture ) ? 'true' : 'false' ) . '"
415
-			data-locale="' . esc_attr( $this->stripe_checkout_locale ? $this->stripe_checkout_locale : 'en' ) . '"
416
-			data-three-d-secure="' . esc_attr( $this->three_d_secure ? 'true' : 'false' ) . '"
417
-			data-allow-remember-me="' . esc_attr( $this->saved_cards ? 'true' : 'false' ) . '">';
418
-
419
-		if ( $this->description ) {
420
-			if ( $this->testmode ) {
409
+			data-email="' . esc_attr($user_email) . '"
410
+			data-amount="' . esc_attr(WC_Stripe_Helper::get_stripe_amount($total)) . '"
411
+			data-name="' . esc_attr($this->statement_descriptor) . '"
412
+			data-currency="' . esc_attr(strtolower(get_woocommerce_currency())) . '"
413
+			data-image="' . esc_attr($this->stripe_checkout_image) . '"
414
+			data-bitcoin="' . esc_attr(($this->bitcoin && $this->capture) ? 'true' : 'false') . '"
415
+			data-locale="' . esc_attr($this->stripe_checkout_locale ? $this->stripe_checkout_locale : 'en') . '"
416
+			data-three-d-secure="' . esc_attr($this->three_d_secure ? 'true' : 'false') . '"
417
+			data-allow-remember-me="' . esc_attr($this->saved_cards ? 'true' : 'false') . '">';
418
+
419
+		if ($this->description) {
420
+			if ($this->testmode) {
421 421
 				/* translators: link to Stripe testing page */
422
-				$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' );
423
-				$this->description  = trim( $this->description );
422
+				$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');
423
+				$this->description  = trim($this->description);
424 424
 			}
425
-			echo apply_filters( 'wc_stripe_description', wpautop( wp_kses_post( $this->description ) ) );
425
+			echo apply_filters('wc_stripe_description', wpautop(wp_kses_post($this->description)));
426 426
 		}
427 427
 
428
-		if ( $display_tokenization ) {
428
+		if ($display_tokenization) {
429 429
 			$this->tokenization_script();
430 430
 			$this->saved_payment_methods();
431 431
 		}
432 432
 
433
-		if ( ! $this->stripe_checkout ) {
434
-			if ( apply_filters( 'wc_stripe_use_elements_checkout_form', true ) ) {
433
+		if ( ! $this->stripe_checkout) {
434
+			if (apply_filters('wc_stripe_use_elements_checkout_form', true)) {
435 435
 				$this->elements_form();
436 436
 			} else {
437 437
 				$this->form();
@@ -439,7 +439,7 @@  discard block
 block discarded – undo
439 439
 			}
440 440
 		}
441 441
 
442
-		if ( apply_filters( 'wc_stripe_display_save_payment_method_checkbox', $display_tokenization ) && ! is_add_payment_method_page() && ! isset( $_GET['change_payment_method'] ) ) {
442
+		if (apply_filters('wc_stripe_display_save_payment_method_checkbox', $display_tokenization) && ! is_add_payment_method_page() && ! isset($_GET['change_payment_method'])) {
443 443
 			$this->save_payment_method_checkbox();
444 444
 		}
445 445
 
@@ -454,12 +454,12 @@  discard block
 block discarded – undo
454 454
 	 */
455 455
 	public function elements_form() {
456 456
 		?>
457
-		<fieldset id="wc-<?php echo esc_attr( $this->id ); ?>-cc-form" class="wc-credit-card-form wc-payment-form" style="background:transparent;">
458
-			<?php do_action( 'woocommerce_credit_card_form_start', $this->id ); ?>
457
+		<fieldset id="wc-<?php echo esc_attr($this->id); ?>-cc-form" class="wc-credit-card-form wc-payment-form" style="background:transparent;">
458
+			<?php do_action('woocommerce_credit_card_form_start', $this->id); ?>
459 459
 
460
-			<?php if ( $this->inline_cc_form ) { ?>
460
+			<?php if ($this->inline_cc_form) { ?>
461 461
 				<label for="card-element">
462
-					<?php esc_html_e( 'Credit or debit card', 'woocommerce-gateway-stripe' ); ?>
462
+					<?php esc_html_e('Credit or debit card', 'woocommerce-gateway-stripe'); ?>
463 463
 				</label>
464 464
 
465 465
 				<div id="stripe-card-element" style="background:#fff;padding:0 1em;border:1px solid #ddd;margin:5px 0;padding:10px 5px;">
@@ -467,7 +467,7 @@  discard block
 block discarded – undo
467 467
 				</div>
468 468
 			<?php } else { ?>
469 469
 				<div class="form-row form-row-wide">
470
-					<label><?php _e( 'Card Number', 'woocommerce-gateway-stripe' ); ?> <span class="required">*</span></label>
470
+					<label><?php _e('Card Number', 'woocommerce-gateway-stripe'); ?> <span class="required">*</span></label>
471 471
 
472 472
 					<div id="stripe-card-element" style="background:#fff;padding:0 1em;border:1px solid #ddd;margin:5px 0;padding:10px 5px;">
473 473
 					<!-- a Stripe Element will be inserted here. -->
@@ -475,7 +475,7 @@  discard block
 block discarded – undo
475 475
 				</div>
476 476
 
477 477
 				<div class="form-row form-row-first">
478
-					<label><?php _e( 'Expiry Date', 'woocommerce-gateway-stripe' ); ?> <span class="required">*</span></label>
478
+					<label><?php _e('Expiry Date', 'woocommerce-gateway-stripe'); ?> <span class="required">*</span></label>
479 479
 
480 480
 					<div id="stripe-exp-element" style="background:#fff;padding:0 1em;border:1px solid #ddd;margin:5px 0;padding:10px 5px;">
481 481
 					<!-- a Stripe Element will be inserted here. -->
@@ -483,7 +483,7 @@  discard block
 block discarded – undo
483 483
 				</div>
484 484
 
485 485
 				<div class="form-row form-row-last">
486
-					<label><?php _e( 'Card Code (CVC)', 'woocommerce-gateway-stripe' ); ?> <span class="required">*</span></label>
486
+					<label><?php _e('Card Code (CVC)', 'woocommerce-gateway-stripe'); ?> <span class="required">*</span></label>
487 487
 				<div id="stripe-cvc-element" style="background:#fff;padding:0 1em;border:1px solid #ddd;margin:5px 0;padding:10px 5px;">
488 488
 				<!-- a Stripe Element will be inserted here. -->
489 489
 				</div>
@@ -493,7 +493,7 @@  discard block
 block discarded – undo
493 493
 
494 494
 			<!-- Used to display form errors -->
495 495
 			<div class="stripe-source-errors" role="alert"></div>
496
-			<?php do_action( 'woocommerce_credit_card_form_end', $this->id ); ?>
496
+			<?php do_action('woocommerce_credit_card_form_end', $this->id); ?>
497 497
 			<div class="clear"></div>
498 498
 		</fieldset>
499 499
 		<?php
@@ -506,13 +506,13 @@  discard block
 block discarded – undo
506 506
 	 * @version 3.1.0
507 507
 	 */
508 508
 	public function admin_scripts() {
509
-		if ( 'woocommerce_page_wc-settings' !== get_current_screen()->id ) {
509
+		if ('woocommerce_page_wc-settings' !== get_current_screen()->id) {
510 510
 			return;
511 511
 		}
512 512
 
513
-		$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
513
+		$suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';
514 514
 
515
-		wp_enqueue_script( 'woocommerce_stripe_admin', plugins_url( 'assets/js/stripe-admin' . $suffix . '.js', WC_STRIPE_MAIN_FILE ), array(), WC_STRIPE_VERSION, true );
515
+		wp_enqueue_script('woocommerce_stripe_admin', plugins_url('assets/js/stripe-admin' . $suffix . '.js', WC_STRIPE_MAIN_FILE), array(), WC_STRIPE_VERSION, true);
516 516
 	}
517 517
 
518 518
 	/**
@@ -524,29 +524,29 @@  discard block
 block discarded – undo
524 524
 	 * @version 4.0.0
525 525
 	 */
526 526
 	public function payment_scripts() {
527
-		if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) && ! is_add_payment_method_page() && ! isset( $_GET['change_payment_method'] ) ) {
527
+		if ( ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order']) && ! is_add_payment_method_page() && ! isset($_GET['change_payment_method'])) {
528 528
 			return;
529 529
 		}
530 530
 
531
-		$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
531
+		$suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';
532 532
 
533
-		wp_register_style( 'stripe_paymentfonts', plugins_url( 'assets/css/stripe-paymentfonts.css', WC_STRIPE_MAIN_FILE ), array(), '1.2.5' );
534
-		wp_enqueue_style( 'stripe_paymentfonts' );
535
-		wp_register_script( 'stripe_checkout', 'https://checkout.stripe.com/checkout.js', '', WC_STRIPE_VERSION, true );
536
-		wp_register_script( 'stripev2', 'https://js.stripe.com/v2/', '', '2.0', true );
537
-		wp_register_script( 'stripe', 'https://js.stripe.com/v3/', '', '3.0', true );
538
-		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 );
533
+		wp_register_style('stripe_paymentfonts', plugins_url('assets/css/stripe-paymentfonts.css', WC_STRIPE_MAIN_FILE), array(), '1.2.5');
534
+		wp_enqueue_style('stripe_paymentfonts');
535
+		wp_register_script('stripe_checkout', 'https://checkout.stripe.com/checkout.js', '', WC_STRIPE_VERSION, true);
536
+		wp_register_script('stripev2', 'https://js.stripe.com/v2/', '', '2.0', true);
537
+		wp_register_script('stripe', 'https://js.stripe.com/v3/', '', '3.0', true);
538
+		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);
539 539
 
540 540
 		$stripe_params = array(
541 541
 			'key'                  => $this->publishable_key,
542
-			'i18n_terms'           => __( 'Please accept the terms and conditions first', 'woocommerce-gateway-stripe' ),
543
-			'i18n_required_fields' => __( 'Please fill in required checkout fields first', 'woocommerce-gateway-stripe' ),
542
+			'i18n_terms'           => __('Please accept the terms and conditions first', 'woocommerce-gateway-stripe'),
543
+			'i18n_required_fields' => __('Please fill in required checkout fields first', 'woocommerce-gateway-stripe'),
544 544
 		);
545 545
 
546 546
 		// If we're on the pay page we need to pass stripe.js the address of the order.
547
-		if ( isset( $_GET['pay_for_order'] ) && 'true' === $_GET['pay_for_order'] ) {
548
-			$order_id = wc_get_order_id_by_order_key( urldecode( $_GET['key'] ) );
549
-			$order    = wc_get_order( $order_id );
547
+		if (isset($_GET['pay_for_order']) && 'true' === $_GET['pay_for_order']) {
548
+			$order_id = wc_get_order_id_by_order_key(urldecode($_GET['key']));
549
+			$order    = wc_get_order($order_id);
550 550
 
551 551
 			$stripe_params['billing_first_name'] = WC_Stripe_Helper::is_pre_30() ? $order->billing_first_name : $order->get_billing_first_name();
552 552
 			$stripe_params['billing_last_name']  = WC_Stripe_Helper::is_pre_30() ? $order->billing_last_name : $order->get_billing_last_name();
@@ -558,38 +558,38 @@  discard block
 block discarded – undo
558 558
 			$stripe_params['billing_country']    = WC_Stripe_Helper::is_pre_30() ? $order->billing_country : $order->get_billing_country();
559 559
 		}
560 560
 
561
-		$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' );
562
-		$stripe_params['no_bank_country_msg']                     = __( 'Please select a country for your bank.', 'woocommerce-gateway-stripe' );
563
-		$stripe_params['no_sepa_owner_msg']                       = __( 'Please enter your IBAN account name.', 'woocommerce-gateway-stripe' );
564
-		$stripe_params['no_sepa_iban_msg']                        = __( 'Please enter your IBAN account number.', 'woocommerce-gateway-stripe' );
565
-		$stripe_params['sepa_mandate_notification']               = apply_filters( 'wc_stripe_sepa_mandate_notification', 'email' );
566
-		$stripe_params['allow_prepaid_card']                      = apply_filters( 'wc_stripe_allow_prepaid_card', true ) ? 'yes' : 'no';
561
+		$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');
562
+		$stripe_params['no_bank_country_msg']                     = __('Please select a country for your bank.', 'woocommerce-gateway-stripe');
563
+		$stripe_params['no_sepa_owner_msg']                       = __('Please enter your IBAN account name.', 'woocommerce-gateway-stripe');
564
+		$stripe_params['no_sepa_iban_msg']                        = __('Please enter your IBAN account number.', 'woocommerce-gateway-stripe');
565
+		$stripe_params['sepa_mandate_notification']               = apply_filters('wc_stripe_sepa_mandate_notification', 'email');
566
+		$stripe_params['allow_prepaid_card']                      = apply_filters('wc_stripe_allow_prepaid_card', true) ? 'yes' : 'no';
567 567
 		$stripe_params['inline_cc_form']                          = $this->inline_cc_form ? 'yes' : 'no';
568
-		$stripe_params['stripe_checkout_require_billing_address'] = apply_filters( 'wc_stripe_checkout_require_billing_address', false ) ? 'yes' : 'no';
569
-		$stripe_params['is_checkout']                             = ( is_checkout() && empty( $_GET['pay_for_order'] ) );
568
+		$stripe_params['stripe_checkout_require_billing_address'] = apply_filters('wc_stripe_checkout_require_billing_address', false) ? 'yes' : 'no';
569
+		$stripe_params['is_checkout']                             = (is_checkout() && empty($_GET['pay_for_order']));
570 570
 		$stripe_params['return_url']                              = $this->get_stripe_return_url();
571
-		$stripe_params['ajaxurl']                                 = WC_AJAX::get_endpoint( '%%endpoint%%' );
572
-		$stripe_params['stripe_nonce']                            = wp_create_nonce( '_wc_stripe_nonce' );
571
+		$stripe_params['ajaxurl']                                 = WC_AJAX::get_endpoint('%%endpoint%%');
572
+		$stripe_params['stripe_nonce']                            = wp_create_nonce('_wc_stripe_nonce');
573 573
 		$stripe_params['statement_descriptor']                    = $this->statement_descriptor;
574
-		$stripe_params['use_elements']                            = apply_filters( 'wc_stripe_use_elements_checkout_form', true ) ? 'yes' : 'no';
574
+		$stripe_params['use_elements']                            = apply_filters('wc_stripe_use_elements_checkout_form', true) ? 'yes' : 'no';
575 575
 		$stripe_params['is_stripe_checkout']                      = $this->stripe_checkout ? 'yes' : 'no';
576
-		$stripe_params['is_change_payment_page']                  = ( isset( $_GET['pay_for_order'] ) || isset( $_GET['change_payment_method'] ) ) ? 'yes' : 'no';
576
+		$stripe_params['is_change_payment_page']                  = (isset($_GET['pay_for_order']) || isset($_GET['change_payment_method'])) ? 'yes' : 'no';
577 577
 		$stripe_params['is_add_payment_method_page']              = is_add_payment_method_page() ? 'yes' : 'no';
578
-		$stripe_params['elements_styling']                        = apply_filters( 'wc_stripe_elements_styling', false );
579
-		$stripe_params['elements_classes']                        = apply_filters( 'wc_stripe_elements_classes', false );
578
+		$stripe_params['elements_styling']                        = apply_filters('wc_stripe_elements_styling', false);
579
+		$stripe_params['elements_classes']                        = apply_filters('wc_stripe_elements_classes', false);
580 580
 
581 581
 		// merge localized messages to be use in JS
582
-		$stripe_params = array_merge( $stripe_params, WC_Stripe_Helper::get_localized_messages() );
582
+		$stripe_params = array_merge($stripe_params, WC_Stripe_Helper::get_localized_messages());
583 583
 
584
-		wp_localize_script( 'woocommerce_stripe', 'wc_stripe_params', apply_filters( 'wc_stripe_params', $stripe_params ) );
585
-		wp_localize_script( 'woocommerce_stripe_checkout', 'wc_stripe_params', apply_filters( 'wc_stripe_params', $stripe_params ) );
584
+		wp_localize_script('woocommerce_stripe', 'wc_stripe_params', apply_filters('wc_stripe_params', $stripe_params));
585
+		wp_localize_script('woocommerce_stripe_checkout', 'wc_stripe_params', apply_filters('wc_stripe_params', $stripe_params));
586 586
 
587
-		if ( $this->stripe_checkout ) {
588
-			wp_enqueue_script( 'stripe_checkout' );
587
+		if ($this->stripe_checkout) {
588
+			wp_enqueue_script('stripe_checkout');
589 589
 		}
590 590
 
591 591
 		$this->tokenization_script();
592
-		wp_enqueue_script( 'woocommerce_stripe' );
592
+		wp_enqueue_script('woocommerce_stripe');
593 593
 	}
594 594
 
595 595
 	/**
@@ -601,22 +601,22 @@  discard block
 block discarded – undo
601 601
 	 * @param object $source_object
602 602
 	 * @return mixed
603 603
 	 */
604
-	public function create_3ds_source( $order, $source_object ) {
604
+	public function create_3ds_source($order, $source_object) {
605 605
 		$currency                    = WC_Stripe_Helper::is_pre_30() ? $order->get_order_currency() : $order->get_currency();
606 606
 		$order_id                    = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
607
-		$return_url                  = $this->get_stripe_return_url( $order );
607
+		$return_url                  = $this->get_stripe_return_url($order);
608 608
 
609 609
 		$post_data                   = array();
610
-		$post_data['amount']         = WC_Stripe_Helper::get_stripe_amount( $order->get_total(), $currency );
611
-		$post_data['currency']       = strtolower( $currency );
610
+		$post_data['amount']         = WC_Stripe_Helper::get_stripe_amount($order->get_total(), $currency);
611
+		$post_data['currency']       = strtolower($currency);
612 612
 		$post_data['type']           = 'three_d_secure';
613
-		$post_data['owner']          = $this->get_owner_details( $order );
614
-		$post_data['three_d_secure'] = array( 'card' => $source_object->id );
615
-		$post_data['redirect']       = array( 'return_url' => $return_url );
613
+		$post_data['owner']          = $this->get_owner_details($order);
614
+		$post_data['three_d_secure'] = array('card' => $source_object->id);
615
+		$post_data['redirect']       = array('return_url' => $return_url);
616 616
 
617
-		WC_Stripe_Logger::log( 'Info: Begin creating 3DS source' );
617
+		WC_Stripe_Logger::log('Info: Begin creating 3DS source');
618 618
 
619
-		return WC_Stripe_API::request( $post_data, 'sources' );
619
+		return WC_Stripe_API::request($post_data, 'sources');
620 620
 	}
621 621
 
622 622
 	/**
@@ -632,45 +632,45 @@  discard block
 block discarded – undo
632 632
 	 *
633 633
 	 * @return array|void
634 634
 	 */
635
-	public function process_payment( $order_id, $retry = true, $force_save_source = false ) {
635
+	public function process_payment($order_id, $retry = true, $force_save_source = false) {
636 636
 		try {
637
-			$order   = wc_get_order( $order_id );
637
+			$order = wc_get_order($order_id);
638 638
 
639 639
 			// This comes from the create account checkbox in the checkout page.
640
-			$create_account = ! empty( $_POST['createaccount'] ) ? true : false;
640
+			$create_account = ! empty($_POST['createaccount']) ? true : false;
641 641
 
642
-			if ( $create_account ) {
642
+			if ($create_account) {
643 643
 				$new_customer_id     = WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id();
644
-				$new_stripe_customer = new WC_Stripe_Customer( $new_customer_id );
644
+				$new_stripe_customer = new WC_Stripe_Customer($new_customer_id);
645 645
 				$new_stripe_customer->create_customer();
646 646
 			}
647 647
 
648 648
 			$source_object = $this->create_source_object();
649 649
 
650
-			$prepared_source = $this->prepare_source( $source_object, get_current_user_id(), $force_save_source );
650
+			$prepared_source = $this->prepare_source($source_object, get_current_user_id(), $force_save_source);
651 651
 
652 652
 			// Check if we don't allow prepaid credit cards.
653
-			if ( ! apply_filters( 'wc_stripe_allow_prepaid_card', true ) ) {
654
-				if ( $source_object && 'token' === $source_object->object && 'prepaid' === $source_object->card->funding ) {
655
-					$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' );
656
-					throw new WC_Stripe_Exception( print_r( $source_object, true ), $localized_message );
653
+			if ( ! apply_filters('wc_stripe_allow_prepaid_card', true)) {
654
+				if ($source_object && 'token' === $source_object->object && 'prepaid' === $source_object->card->funding) {
655
+					$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');
656
+					throw new WC_Stripe_Exception(print_r($source_object, true), $localized_message);
657 657
 				}
658 658
 			}
659 659
 
660
-			if ( empty( $prepared_source->source ) ) {
661
-				$localized_message = __( 'Payment processing failed. Please retry.', 'woocommerce-gateway-stripe' );
662
-				throw new WC_Stripe_Exception( print_r( $prepared_source, true ), $localized_message );
660
+			if (empty($prepared_source->source)) {
661
+				$localized_message = __('Payment processing failed. Please retry.', 'woocommerce-gateway-stripe');
662
+				throw new WC_Stripe_Exception(print_r($prepared_source, true), $localized_message);
663 663
 			}
664 664
 
665 665
 			// Store source to order meta.
666
-			$this->save_source( $order, $prepared_source );
666
+			$this->save_source($order, $prepared_source);
667 667
 
668 668
 			// Result from Stripe API request.
669 669
 			$response = null;
670 670
 
671
-			if ( $order->get_total() > 0 ) {
671
+			if ($order->get_total() > 0) {
672 672
 				// This will throw exception if not valid.
673
-				$this->validate_minimum_order_amount( $order );
673
+				$this->validate_minimum_order_amount($order);
674 674
 
675 675
 				/**
676 676
 				 * Check if card 3DS is required or optional with 3DS setting.
@@ -679,83 +679,83 @@  discard block
 block discarded – undo
679 679
 				 * Note that if we need to save source, the original source must be first
680 680
 				 * attached to a customer in Stripe before it can be charged.
681 681
 				 */
682
-				if ( ( $source_object && ! empty( $source_object->card ) ) && ( 'card' === $source_object->type && 'required' === $source_object->card->three_d_secure || ( $this->three_d_secure && 'optional' === $source_object->card->three_d_secure ) ) ) {
682
+				if (($source_object && ! empty($source_object->card)) && ('card' === $source_object->type && 'required' === $source_object->card->three_d_secure || ($this->three_d_secure && 'optional' === $source_object->card->three_d_secure))) {
683 683
 
684
-					$response = $this->create_3ds_source( $order, $source_object );
684
+					$response = $this->create_3ds_source($order, $source_object);
685 685
 
686
-					if ( ! empty( $response->error ) ) {
686
+					if ( ! empty($response->error)) {
687 687
 						$localized_message = $response->error->message;
688 688
 
689
-						$order->add_order_note( $localized_message );
689
+						$order->add_order_note($localized_message);
690 690
 
691
-						throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message );
691
+						throw new WC_Stripe_Exception(print_r($response, true), $localized_message);
692 692
 					}
693 693
 
694 694
 					// Update order meta with 3DS source.
695
-					if ( WC_Stripe_Helper::is_pre_30() ) {
696
-						update_post_meta( $order_id, '_stripe_source_id', $response->id );
695
+					if (WC_Stripe_Helper::is_pre_30()) {
696
+						update_post_meta($order_id, '_stripe_source_id', $response->id);
697 697
 					} else {
698
-						$order->update_meta_data( '_stripe_source_id', $response->id );
698
+						$order->update_meta_data('_stripe_source_id', $response->id);
699 699
 						$order->save();
700 700
 					}
701 701
 
702
-					WC_Stripe_Logger::log( 'Info: Redirecting to 3DS...' );
702
+					WC_Stripe_Logger::log('Info: Redirecting to 3DS...');
703 703
 
704 704
 					return array(
705 705
 						'result'   => 'success',
706
-						'redirect' => esc_url_raw( $response->redirect->url ),
706
+						'redirect' => esc_url_raw($response->redirect->url),
707 707
 					);
708 708
 				}
709 709
 
710
-				WC_Stripe_Logger::log( "Info: Begin processing payment for order $order_id for the amount of {$order->get_total()}" );
710
+				WC_Stripe_Logger::log("Info: Begin processing payment for order $order_id for the amount of {$order->get_total()}");
711 711
 
712 712
 				// Make the request.
713
-				$response = WC_Stripe_API::request( $this->generate_payment_request( $order, $prepared_source ) );
713
+				$response = WC_Stripe_API::request($this->generate_payment_request($order, $prepared_source));
714 714
 
715
-				if ( ! empty( $response->error ) ) {
715
+				if ( ! empty($response->error)) {
716 716
 					// If it is an API error such connection or server, let's retry.
717
-					if ( 'api_connection_error' === $response->error->type || 'api_error' === $response->error->type ) {
718
-						if ( $retry ) {
719
-							sleep( 5 );
720
-							return $this->process_payment( $order_id, false, $force_save_source );
717
+					if ('api_connection_error' === $response->error->type || 'api_error' === $response->error->type) {
718
+						if ($retry) {
719
+							sleep(5);
720
+							return $this->process_payment($order_id, false, $force_save_source);
721 721
 						} else {
722 722
 							$localized_message = 'API connection error and retries exhausted.';
723
-							$order->add_order_note( $localized_message );
724
-							throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message );
723
+							$order->add_order_note($localized_message);
724
+							throw new WC_Stripe_Exception(print_r($response, true), $localized_message);
725 725
 						}
726 726
 					}
727 727
 
728 728
 					// Customer param wrong? The user may have been deleted on stripe's end. Remove customer_id. Can be retried without.
729
-					if ( preg_match( '/No such customer/i', $response->error->message ) && $retry ) {
730
-						delete_user_meta( WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id(), '_stripe_customer_id' );
729
+					if (preg_match('/No such customer/i', $response->error->message) && $retry) {
730
+						delete_user_meta(WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id(), '_stripe_customer_id');
731 731
 
732
-						return $this->process_payment( $order_id, false, $force_save_source );
733
-					} elseif ( preg_match( '/No such token/i', $response->error->message ) && $prepared_source->token_id ) {
732
+						return $this->process_payment($order_id, false, $force_save_source);
733
+					} elseif (preg_match('/No such token/i', $response->error->message) && $prepared_source->token_id) {
734 734
 						// Source param wrong? The CARD may have been deleted on stripe's end. Remove token and show message.
735
-						$wc_token = WC_Payment_Tokens::get( $prepared_source->token_id );
735
+						$wc_token = WC_Payment_Tokens::get($prepared_source->token_id);
736 736
 						$wc_token->delete();
737
-						$localized_message = __( 'This card is no longer available and has been removed.', 'woocommerce-gateway-stripe' );
738
-						$order->add_order_note( $localized_message );
739
-						throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message );
737
+						$localized_message = __('This card is no longer available and has been removed.', 'woocommerce-gateway-stripe');
738
+						$order->add_order_note($localized_message);
739
+						throw new WC_Stripe_Exception(print_r($response, true), $localized_message);
740 740
 					}
741 741
 
742 742
 					$localized_messages = WC_Stripe_Helper::get_localized_messages();
743 743
 
744
-					if ( 'card_error' === $response->error->type ) {
745
-						$localized_message = isset( $localized_messages[ $response->error->code ] ) ? $localized_messages[ $response->error->code ] : $response->error->message;
744
+					if ('card_error' === $response->error->type) {
745
+						$localized_message = isset($localized_messages[$response->error->code]) ? $localized_messages[$response->error->code] : $response->error->message;
746 746
 					} else {
747
-						$localized_message = isset( $localized_messages[ $response->error->type ] ) ? $localized_messages[ $response->error->type ] : $response->error->message;
747
+						$localized_message = isset($localized_messages[$response->error->type]) ? $localized_messages[$response->error->type] : $response->error->message;
748 748
 					}
749 749
 
750
-					$order->add_order_note( $localized_message );
750
+					$order->add_order_note($localized_message);
751 751
 
752
-					throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message );
752
+					throw new WC_Stripe_Exception(print_r($response, true), $localized_message);
753 753
 				}
754 754
 
755
-				do_action( 'wc_gateway_stripe_process_payment', $response, $order );
755
+				do_action('wc_gateway_stripe_process_payment', $response, $order);
756 756
 
757 757
 				// Process valid response.
758
-				$this->process_response( $response, $order );
758
+				$this->process_response($response, $order);
759 759
 			} else {
760 760
 				$order->payment_complete();
761 761
 			}
@@ -766,17 +766,17 @@  discard block
 block discarded – undo
766 766
 			// Return thank you page redirect.
767 767
 			return array(
768 768
 				'result'   => 'success',
769
-				'redirect' => $this->get_return_url( $order ),
769
+				'redirect' => $this->get_return_url($order),
770 770
 			);
771 771
 
772
-		} catch ( WC_Stripe_Exception $e ) {
773
-			wc_add_notice( $e->getLocalizedMessage(), 'error' );
774
-			WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() );
772
+		} catch (WC_Stripe_Exception $e) {
773
+			wc_add_notice($e->getLocalizedMessage(), 'error');
774
+			WC_Stripe_Logger::log('Error: ' . $e->getMessage());
775 775
 
776
-			do_action( 'wc_gateway_stripe_process_payment_error', $e, $order );
776
+			do_action('wc_gateway_stripe_process_payment_error', $e, $order);
777 777
 
778
-			if ( $order->has_status( array( 'pending', 'failed' ) ) ) {
779
-				$this->send_failed_order_email( $order_id );
778
+			if ($order->has_status(array('pending', 'failed'))) {
779
+				$this->send_failed_order_email($order_id);
780 780
 			}
781 781
 
782 782
 			return array(
Please login to merge, or discard this patch.
includes/payment-methods/class-wc-stripe-payment-request.php 1 patch
Spacing   +274 added lines, -274 removed lines patch added patch discarded remove patch
@@ -6,7 +6,7 @@  discard block
 block discarded – undo
6 6
  * @since   3.1.0
7 7
  */
8 8
 
9
-if ( ! defined( 'ABSPATH' ) ) {
9
+if ( ! defined('ABSPATH')) {
10 10
 	exit;
11 11
 }
12 12
 
@@ -56,35 +56,35 @@  discard block
 block discarded – undo
56 56
 	 * @version 4.0.0
57 57
 	 */
58 58
 	public function __construct() {
59
-		$this->stripe_settings         = get_option( 'woocommerce_stripe_settings', array() );
60
-		$this->testmode                = ( ! empty( $this->stripe_settings['testmode'] ) && 'yes' === $this->stripe_settings['testmode'] ) ? true : false;
61
-		$this->publishable_key         = ! empty( $this->stripe_settings['publishable_key'] ) ? $this->stripe_settings['publishable_key'] : '';
62
-		$this->stripe_checkout_enabled = isset( $this->stripe_settings['stripe_checkout'] ) && 'yes' === $this->stripe_settings['stripe_checkout'];
63
-		$this->total_label             = ! empty( $this->stripe_settings['statement_descriptor'] ) ? WC_Stripe_Helper::clean_statement_descriptor( $this->stripe_settings['statement_descriptor'] ) : '';
64
-
65
-		if ( $this->testmode ) {
66
-			$this->publishable_key = ! empty( $this->stripe_settings['test_publishable_key'] ) ? $this->stripe_settings['test_publishable_key'] : '';
59
+		$this->stripe_settings         = get_option('woocommerce_stripe_settings', array());
60
+		$this->testmode                = ( ! empty($this->stripe_settings['testmode']) && 'yes' === $this->stripe_settings['testmode']) ? true : false;
61
+		$this->publishable_key         = ! empty($this->stripe_settings['publishable_key']) ? $this->stripe_settings['publishable_key'] : '';
62
+		$this->stripe_checkout_enabled = isset($this->stripe_settings['stripe_checkout']) && 'yes' === $this->stripe_settings['stripe_checkout'];
63
+		$this->total_label             = ! empty($this->stripe_settings['statement_descriptor']) ? WC_Stripe_Helper::clean_statement_descriptor($this->stripe_settings['statement_descriptor']) : '';
64
+
65
+		if ($this->testmode) {
66
+			$this->publishable_key = ! empty($this->stripe_settings['test_publishable_key']) ? $this->stripe_settings['test_publishable_key'] : '';
67 67
 		}
68 68
 
69 69
 		// If both site title and statement descriptor is not set. Fallback.
70
-		if ( empty( $this->total_label ) ) {
70
+		if (empty($this->total_label)) {
71 71
 			$this->total_label = $_SERVER['SERVER_NAME'];
72 72
 		}
73 73
 
74
-		$this->total_label = str_replace( "'", '', $this->total_label ) . apply_filters( 'wc_stripe_payment_request_total_label_suffix', ' (via WooCommerce)' );
74
+		$this->total_label = str_replace("'", '', $this->total_label) . apply_filters('wc_stripe_payment_request_total_label_suffix', ' (via WooCommerce)');
75 75
 
76 76
 		// Checks if Stripe Gateway is enabled.
77
-		if ( empty( $this->stripe_settings ) || ( isset( $this->stripe_settings['enabled'] ) && 'yes' !== $this->stripe_settings['enabled'] ) ) {
77
+		if (empty($this->stripe_settings) || (isset($this->stripe_settings['enabled']) && 'yes' !== $this->stripe_settings['enabled'])) {
78 78
 			return;
79 79
 		}
80 80
 
81 81
 		// Checks if Payment Request is enabled.
82
-		if ( ! isset( $this->stripe_settings['payment_request'] ) || 'yes' !== $this->stripe_settings['payment_request'] ) {
82
+		if ( ! isset($this->stripe_settings['payment_request']) || 'yes' !== $this->stripe_settings['payment_request']) {
83 83
 			return;
84 84
 		}
85 85
 
86 86
 		// Don't load for change payment method page.
87
-		if ( isset( $_GET['change_payment_method'] ) ) {
87
+		if (isset($_GET['change_payment_method'])) {
88 88
 			return;
89 89
 		}
90 90
 
@@ -98,43 +98,43 @@  discard block
 block discarded – undo
98 98
 	 * @version 4.0.0
99 99
 	 */
100 100
 	protected function init() {
101
-		add_action( 'wp_enqueue_scripts', array( $this, 'scripts' ) );
102
-		add_action( 'wp', array( $this, 'set_session' ) );
101
+		add_action('wp_enqueue_scripts', array($this, 'scripts'));
102
+		add_action('wp', array($this, 'set_session'));
103 103
 
104 104
 		/*
105 105
 		 * In order to display the Payment Request button in the correct position,
106 106
 		 * a new hook was added to WooCommerce 3.0. In older versions of WooCommerce,
107 107
 		 * CSS is used to position the button.
108 108
 		 */
109
-		if ( WC_Stripe_Helper::is_pre_30() ) {
110
-			add_action( 'woocommerce_after_add_to_cart_button', array( $this, 'display_payment_request_button_html' ), 1 );
111
-			add_action( 'woocommerce_after_add_to_cart_button', array( $this, 'display_payment_request_button_separator_html' ), 2 );
109
+		if (WC_Stripe_Helper::is_pre_30()) {
110
+			add_action('woocommerce_after_add_to_cart_button', array($this, 'display_payment_request_button_html'), 1);
111
+			add_action('woocommerce_after_add_to_cart_button', array($this, 'display_payment_request_button_separator_html'), 2);
112 112
 		} else {
113
-			add_action( 'woocommerce_after_add_to_cart_quantity', array( $this, 'display_payment_request_button_html' ), 1 );
114
-			add_action( 'woocommerce_after_add_to_cart_quantity', array( $this, 'display_payment_request_button_separator_html' ), 2 );
113
+			add_action('woocommerce_after_add_to_cart_quantity', array($this, 'display_payment_request_button_html'), 1);
114
+			add_action('woocommerce_after_add_to_cart_quantity', array($this, 'display_payment_request_button_separator_html'), 2);
115 115
 		}
116 116
 
117
-		add_action( 'woocommerce_proceed_to_checkout', array( $this, 'display_payment_request_button_html' ), 1 );
118
-		add_action( 'woocommerce_proceed_to_checkout', array( $this, 'display_payment_request_button_separator_html' ), 2 );
117
+		add_action('woocommerce_proceed_to_checkout', array($this, 'display_payment_request_button_html'), 1);
118
+		add_action('woocommerce_proceed_to_checkout', array($this, 'display_payment_request_button_separator_html'), 2);
119 119
 
120
-		if ( apply_filters( 'wc_stripe_show_payment_request_on_checkout', false ) ) {
121
-			add_action( 'woocommerce_checkout_before_customer_details', array( $this, 'display_payment_request_button_html' ), 1 );
122
-			add_action( 'woocommerce_checkout_before_customer_details', array( $this, 'display_payment_request_button_separator_html' ), 2 );
120
+		if (apply_filters('wc_stripe_show_payment_request_on_checkout', false)) {
121
+			add_action('woocommerce_checkout_before_customer_details', array($this, 'display_payment_request_button_html'), 1);
122
+			add_action('woocommerce_checkout_before_customer_details', array($this, 'display_payment_request_button_separator_html'), 2);
123 123
 		}
124 124
 
125
-		add_action( 'wc_ajax_wc_stripe_get_cart_details', array( $this, 'ajax_get_cart_details' ) );
126
-		add_action( 'wc_ajax_wc_stripe_get_shipping_options', array( $this, 'ajax_get_shipping_options' ) );
127
-		add_action( 'wc_ajax_wc_stripe_update_shipping_method', array( $this, 'ajax_update_shipping_method' ) );
128
-		add_action( 'wc_ajax_wc_stripe_create_order', array( $this, 'ajax_create_order' ) );
129
-		add_action( 'wc_ajax_wc_stripe_add_to_cart', array( $this, 'ajax_add_to_cart' ) );
130
-		add_action( 'wc_ajax_wc_stripe_get_selected_product_data', array( $this, 'ajax_get_selected_product_data' ) );
131
-		add_action( 'wc_ajax_wc_stripe_clear_cart', array( $this, 'ajax_clear_cart' ) );
132
-		add_action( 'wc_ajax_wc_stripe_log_errors', array( $this, 'ajax_log_errors' ) );
125
+		add_action('wc_ajax_wc_stripe_get_cart_details', array($this, 'ajax_get_cart_details'));
126
+		add_action('wc_ajax_wc_stripe_get_shipping_options', array($this, 'ajax_get_shipping_options'));
127
+		add_action('wc_ajax_wc_stripe_update_shipping_method', array($this, 'ajax_update_shipping_method'));
128
+		add_action('wc_ajax_wc_stripe_create_order', array($this, 'ajax_create_order'));
129
+		add_action('wc_ajax_wc_stripe_add_to_cart', array($this, 'ajax_add_to_cart'));
130
+		add_action('wc_ajax_wc_stripe_get_selected_product_data', array($this, 'ajax_get_selected_product_data'));
131
+		add_action('wc_ajax_wc_stripe_clear_cart', array($this, 'ajax_clear_cart'));
132
+		add_action('wc_ajax_wc_stripe_log_errors', array($this, 'ajax_log_errors'));
133 133
 
134
-		add_filter( 'woocommerce_gateway_title', array( $this, 'filter_gateway_title' ), 10, 2 );
135
-		add_filter( 'woocommerce_validate_postcode', array( $this, 'postal_code_validation' ), 10, 3 );
134
+		add_filter('woocommerce_gateway_title', array($this, 'filter_gateway_title'), 10, 2);
135
+		add_filter('woocommerce_validate_postcode', array($this, 'postal_code_validation'), 10, 3);
136 136
 
137
-		add_action( 'woocommerce_checkout_order_processed', array( $this, 'add_order_meta' ), 10, 3 );
137
+		add_action('woocommerce_checkout_order_processed', array($this, 'add_order_meta'), 10, 3);
138 138
 	}
139 139
 
140 140
 	/**
@@ -144,11 +144,11 @@  discard block
 block discarded – undo
144 144
 	 * @since 4.0.0
145 145
 	 */
146 146
 	public function set_session() {
147
-		if ( ! is_user_logged_in() ) {
147
+		if ( ! is_user_logged_in()) {
148 148
 			$wc_session = new WC_Session_Handler();
149 149
 
150
-			if ( ! $wc_session->has_session() ) {
151
-				$wc_session->set_customer_session_cookie( true );
150
+			if ( ! $wc_session->has_session()) {
151
+				$wc_session->set_customer_session_cookie(true);
152 152
 			}
153 153
 		}
154 154
 	}
@@ -161,7 +161,7 @@  discard block
 block discarded – undo
161 161
 	 * @return string
162 162
 	 */
163 163
 	public function get_button_type() {
164
-		return isset( $this->stripe_settings['payment_request_button_type'] ) ? $this->stripe_settings['payment_request_button_type'] : 'default';
164
+		return isset($this->stripe_settings['payment_request_button_type']) ? $this->stripe_settings['payment_request_button_type'] : 'default';
165 165
 	}
166 166
 
167 167
 	/**
@@ -172,7 +172,7 @@  discard block
 block discarded – undo
172 172
 	 * @return string
173 173
 	 */
174 174
 	public function get_button_theme() {
175
-		return isset( $this->stripe_settings['payment_request_button_theme'] ) ? $this->stripe_settings['payment_request_button_theme'] : 'dark';
175
+		return isset($this->stripe_settings['payment_request_button_theme']) ? $this->stripe_settings['payment_request_button_theme'] : 'dark';
176 176
 	}
177 177
 
178 178
 	/**
@@ -183,7 +183,7 @@  discard block
 block discarded – undo
183 183
 	 * @return string
184 184
 	 */
185 185
 	public function get_button_height() {
186
-		return isset( $this->stripe_settings['payment_request_button_height'] ) ? str_replace( 'px', '', $this->stripe_settings['payment_request_button_height'] ) : '64';
186
+		return isset($this->stripe_settings['payment_request_button_height']) ? str_replace('px', '', $this->stripe_settings['payment_request_button_height']) : '64';
187 187
 	}
188 188
 
189 189
 	/**
@@ -193,40 +193,40 @@  discard block
 block discarded – undo
193 193
 	 * @version 4.0.0
194 194
 	 */
195 195
 	public function get_product_data() {
196
-		if ( ! is_product() ) {
196
+		if ( ! is_product()) {
197 197
 			return false;
198 198
 		}
199 199
 
200 200
 		global $post;
201 201
 
202
-		$product = wc_get_product( $post->ID );
202
+		$product = wc_get_product($post->ID);
203 203
 
204 204
 		$data  = array();
205 205
 		$items = array();
206 206
 
207 207
 		$items[] = array(
208 208
 			'label'  => WC_Stripe_Helper::is_pre_30() ? $product->name : $product->get_name(),
209
-			'amount' => WC_Stripe_Helper::get_stripe_amount( WC_Stripe_Helper::is_pre_30() ? $product->price : $product->get_price() ),
209
+			'amount' => WC_Stripe_Helper::get_stripe_amount(WC_Stripe_Helper::is_pre_30() ? $product->price : $product->get_price()),
210 210
 		);
211 211
 
212
-		if ( wc_tax_enabled() ) {
212
+		if (wc_tax_enabled()) {
213 213
 			$items[] = array(
214
-				'label'   => __( 'Tax', 'woocommerce-gateway-stripe' ),
214
+				'label'   => __('Tax', 'woocommerce-gateway-stripe'),
215 215
 				'amount'  => 0,
216 216
 				'pending' => true,
217 217
 			);
218 218
 		}
219 219
 
220
-		if ( wc_shipping_enabled() && $product->needs_shipping() ) {
220
+		if (wc_shipping_enabled() && $product->needs_shipping()) {
221 221
 			$items[] = array(
222
-				'label'   => __( 'Shipping', 'woocommerce-gateway-stripe' ),
222
+				'label'   => __('Shipping', 'woocommerce-gateway-stripe'),
223 223
 				'amount'  => 0,
224 224
 				'pending' => true,
225 225
 			);
226 226
 
227
-			$data['shippingOptions']  = array(
227
+			$data['shippingOptions'] = array(
228 228
 				'id'     => 'pending',
229
-				'label'  => __( 'Pending', 'woocommerce-gateway-stripe' ),
229
+				'label'  => __('Pending', 'woocommerce-gateway-stripe'),
230 230
 				'detail' => '',
231 231
 				'amount' => 0,
232 232
 			);
@@ -235,13 +235,13 @@  discard block
 block discarded – undo
235 235
 		$data['displayItems'] = $items;
236 236
 		$data['total'] = array(
237 237
 			'label'   => $this->total_label,
238
-			'amount'  => WC_Stripe_Helper::get_stripe_amount( WC_Stripe_Helper::is_pre_30() ? $product->price : $product->get_price() ),
238
+			'amount'  => WC_Stripe_Helper::get_stripe_amount(WC_Stripe_Helper::is_pre_30() ? $product->price : $product->get_price()),
239 239
 			'pending' => true,
240 240
 		);
241 241
 
242
-		$data['requestShipping'] = ( wc_shipping_enabled() && $product->needs_shipping() );
243
-		$data['currency']        = strtolower( get_woocommerce_currency() );
244
-		$data['country_code']    = substr( get_option( 'woocommerce_default_country' ), 0, 2 );
242
+		$data['requestShipping'] = (wc_shipping_enabled() && $product->needs_shipping());
243
+		$data['currency']        = strtolower(get_woocommerce_currency());
244
+		$data['country_code']    = substr(get_option('woocommerce_default_country'), 0, 2);
245 245
 
246 246
 		return $data;
247 247
 	}
@@ -250,25 +250,25 @@  discard block
 block discarded – undo
250 250
 	 * Filters the gateway title to reflect Payment Request type
251 251
 	 *
252 252
 	 */
253
-	public function filter_gateway_title( $title, $id ) {
253
+	public function filter_gateway_title($title, $id) {
254 254
 		global $post;
255 255
 
256
-		if ( ! is_object( $post ) ) {
256
+		if ( ! is_object($post)) {
257 257
 			return $title;
258 258
 		}
259 259
 
260
-		if ( WC_Stripe_Helper::is_pre_30() ) {
261
-			$method_title = get_post_meta( $post->ID, '_payment_method_title', true );
260
+		if (WC_Stripe_Helper::is_pre_30()) {
261
+			$method_title = get_post_meta($post->ID, '_payment_method_title', true);
262 262
 		} else {
263
-			$order        = wc_get_order( $post->ID );
264
-			$method_title = is_object( $order ) ? $order->get_payment_method_title() : '';
263
+			$order        = wc_get_order($post->ID);
264
+			$method_title = is_object($order) ? $order->get_payment_method_title() : '';
265 265
 		}
266 266
 
267
-		if ( 'stripe' === $id && ! empty( $method_title ) && 'Apple Pay (Stripe)' === $method_title ) {
267
+		if ('stripe' === $id && ! empty($method_title) && 'Apple Pay (Stripe)' === $method_title) {
268 268
 			return $method_title;
269 269
 		}
270 270
 
271
-		if ( 'stripe' === $id && ! empty( $method_title ) && 'Chrome Payment Request (Stripe)' === $method_title ) {
271
+		if ('stripe' === $id && ! empty($method_title) && 'Chrome Payment Request (Stripe)' === $method_title) {
272 272
 			return $method_title;
273 273
 		}
274 274
 
@@ -281,16 +281,16 @@  discard block
 block discarded – undo
281 281
 	 * @since 3.1.4
282 282
 	 * @version 4.0.0
283 283
 	 */
284
-	public function postal_code_validation( $valid, $postcode, $country ) {
284
+	public function postal_code_validation($valid, $postcode, $country) {
285 285
 		$gateways = WC()->payment_gateways->get_available_payment_gateways();
286 286
 
287
-		if ( ! isset( $gateways['stripe'] ) ) {
287
+		if ( ! isset($gateways['stripe'])) {
288 288
 			return $valid;
289 289
 		}
290 290
 
291
-		$payment_request_type = wc_clean( $_POST['payment_request_type'] );
291
+		$payment_request_type = wc_clean($_POST['payment_request_type']);
292 292
 
293
-		if ( 'apple_pay' !== $payment_request_type ) {
293
+		if ('apple_pay' !== $payment_request_type) {
294 294
 			return $valid;
295 295
 		}
296 296
 
@@ -300,7 +300,7 @@  discard block
 block discarded – undo
300 300
 		 * the order and not let it go through. The remedy for now is just to remove this validation.
301 301
 		 * Note that this only works with shipping providers that don't validate full postal codes.
302 302
 		 */
303
-		if ( 'GB' === $country || 'CA' === $country ) {
303
+		if ('GB' === $country || 'CA' === $country) {
304 304
 			return true;
305 305
 		}
306 306
 
@@ -316,27 +316,27 @@  discard block
 block discarded – undo
316 316
 	 * @param array $posted_data The posted data from checkout form.
317 317
 	 * @param object $order
318 318
 	 */
319
-	public function add_order_meta( $order_id, $posted_data, $order ) {
320
-		if ( empty( $_POST['payment_request_type'] ) ) {
319
+	public function add_order_meta($order_id, $posted_data, $order) {
320
+		if (empty($_POST['payment_request_type'])) {
321 321
 			return;
322 322
 		}
323 323
 
324
-		$payment_request_type = wc_clean( $_POST['payment_request_type'] );
324
+		$payment_request_type = wc_clean($_POST['payment_request_type']);
325 325
 
326
-		if ( 'apple_pay' === $payment_request_type ) {
327
-			if ( WC_Stripe_Helper::is_pre_30() ) {
328
-				update_post_meta( $order_id, '_payment_method_title', 'Apple Pay (Stripe)' );
326
+		if ('apple_pay' === $payment_request_type) {
327
+			if (WC_Stripe_Helper::is_pre_30()) {
328
+				update_post_meta($order_id, '_payment_method_title', 'Apple Pay (Stripe)');
329 329
 			} else {
330
-				$order->set_payment_method_title( 'Apple Pay (Stripe)' );
330
+				$order->set_payment_method_title('Apple Pay (Stripe)');
331 331
 				$order->save();
332 332
 			}
333 333
 		}
334 334
 
335
-		if ( 'payment_request_api' === $payment_request_type ) {
336
-			if ( WC_Stripe_Helper::is_pre_30() ) {
337
-				update_post_meta( $order_id, '_payment_method_title', 'Chrome Payment Request (Stripe)' );
335
+		if ('payment_request_api' === $payment_request_type) {
336
+			if (WC_Stripe_Helper::is_pre_30()) {
337
+				update_post_meta($order_id, '_payment_method_title', 'Chrome Payment Request (Stripe)');
338 338
 			} else {
339
-				$order->set_payment_method_title( 'Chrome Payment Request (Stripe)' );
339
+				$order->set_payment_method_title('Chrome Payment Request (Stripe)');
340 340
 				$order->save();
341 341
 			}
342 342
 		}
@@ -350,11 +350,11 @@  discard block
 block discarded – undo
350 350
 	 * @return array
351 351
 	 */
352 352
 	public function supported_product_types() {
353
-		return apply_filters( 'wc_stripe_payment_request_supported_types', array(
353
+		return apply_filters('wc_stripe_payment_request_supported_types', array(
354 354
 			'simple',
355 355
 			'variable',
356 356
 			'variation',
357
-		) );
357
+		));
358 358
 	}
359 359
 
360 360
 	/**
@@ -365,15 +365,15 @@  discard block
 block discarded – undo
365 365
 	 * @return bool
366 366
 	 */
367 367
 	public function allowed_items_in_cart() {
368
-		foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {
369
-			$_product = apply_filters( 'woocommerce_cart_item_product', $cart_item['data'], $cart_item, $cart_item_key );
368
+		foreach (WC()->cart->get_cart() as $cart_item_key => $cart_item) {
369
+			$_product = apply_filters('woocommerce_cart_item_product', $cart_item['data'], $cart_item, $cart_item_key);
370 370
 
371
-			if ( ! in_array( ( WC_Stripe_Helper::is_pre_30() ? $_product->product_type : $_product->get_type() ), $this->supported_product_types() ) ) {
371
+			if ( ! in_array((WC_Stripe_Helper::is_pre_30() ? $_product->product_type : $_product->get_type()), $this->supported_product_types())) {
372 372
 				return false;
373 373
 			}
374 374
 
375 375
 			// Pre Orders compatbility where we don't support charge upon release.
376
-			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() ) ) {
376
+			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())) {
377 377
 				return false;
378 378
 			}
379 379
 		}
@@ -388,71 +388,71 @@  discard block
 block discarded – undo
388 388
 	 * @version 4.0.0
389 389
 	 */
390 390
 	public function scripts() {
391
-		if ( ! is_product() && ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) ) {
391
+		if ( ! is_product() && ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order'])) {
392 392
 			return;
393 393
 		}
394 394
 
395
-		if ( is_product() ) {
395
+		if (is_product()) {
396 396
 			global $post;
397 397
 
398
-			$product = wc_get_product( $post->ID );
398
+			$product = wc_get_product($post->ID);
399 399
 
400
-			if ( ! is_object( $product ) || ! in_array( ( WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type() ), $this->supported_product_types() ) ) {
400
+			if ( ! is_object($product) || ! in_array((WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type()), $this->supported_product_types())) {
401 401
 				return;
402 402
 			}
403 403
 
404
-			if ( apply_filters( 'wc_stripe_hide_payment_request_on_product_page', false ) ) {
404
+			if (apply_filters('wc_stripe_hide_payment_request_on_product_page', false)) {
405 405
 				return;
406 406
 			}
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_script( 'stripe', 'https://js.stripe.com/v3/', '', '3.0', true );
412
-		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 );
411
+		wp_register_script('stripe', 'https://js.stripe.com/v3/', '', '3.0', true);
412
+		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);
413 413
 
414 414
 		wp_localize_script(
415 415
 			'wc_stripe_payment_request',
416 416
 			'wc_stripe_payment_request_params',
417 417
 			array(
418
-				'ajax_url' => WC_AJAX::get_endpoint( '%%endpoint%%' ),
418
+				'ajax_url' => WC_AJAX::get_endpoint('%%endpoint%%'),
419 419
 				'stripe'   => array(
420 420
 					'key'                => $this->publishable_key,
421
-					'allow_prepaid_card' => apply_filters( 'wc_stripe_allow_prepaid_card', true ) ? 'yes' : 'no',
421
+					'allow_prepaid_card' => apply_filters('wc_stripe_allow_prepaid_card', true) ? 'yes' : 'no',
422 422
 				),
423 423
 				'nonce'    => array(
424
-					'payment'                        => wp_create_nonce( 'wc-stripe-payment-request' ),
425
-					'shipping'                       => wp_create_nonce( 'wc-stripe-payment-request-shipping' ),
426
-					'update_shipping'                => wp_create_nonce( 'wc-stripe-update-shipping-method' ),
427
-					'checkout'                       => wp_create_nonce( 'woocommerce-process_checkout' ),
428
-					'add_to_cart'                    => wp_create_nonce( 'wc-stripe-add-to-cart' ),
429
-					'get_selected_product_data'      => wp_create_nonce( 'wc-stripe-get-selected-product-data' ),
430
-					'log_errors'                     => wp_create_nonce( 'wc-stripe-log-errors' ),
431
-					'clear_cart'                     => wp_create_nonce( 'wc-stripe-clear-cart' ),
424
+					'payment'                        => wp_create_nonce('wc-stripe-payment-request'),
425
+					'shipping'                       => wp_create_nonce('wc-stripe-payment-request-shipping'),
426
+					'update_shipping'                => wp_create_nonce('wc-stripe-update-shipping-method'),
427
+					'checkout'                       => wp_create_nonce('woocommerce-process_checkout'),
428
+					'add_to_cart'                    => wp_create_nonce('wc-stripe-add-to-cart'),
429
+					'get_selected_product_data'      => wp_create_nonce('wc-stripe-get-selected-product-data'),
430
+					'log_errors'                     => wp_create_nonce('wc-stripe-log-errors'),
431
+					'clear_cart'                     => wp_create_nonce('wc-stripe-clear-cart'),
432 432
 				),
433 433
 				'i18n'     => array(
434
-					'no_prepaid_card'  => __( 'Sorry, we\'re not accepting prepaid cards at this time.', 'woocommerce-gateway-stripe' ),
434
+					'no_prepaid_card'  => __('Sorry, we\'re not accepting prepaid cards at this time.', 'woocommerce-gateway-stripe'),
435 435
 					/* translators: Do not translate the [option] placeholder */
436
-					'unknown_shipping' => __( 'Unknown shipping option "[option]".', 'woocommerce-gateway-stripe' ),
436
+					'unknown_shipping' => __('Unknown shipping option "[option]".', 'woocommerce-gateway-stripe'),
437 437
 				),
438 438
 				'checkout' => array(
439 439
 					'url'            => wc_get_checkout_url(),
440
-					'currency_code'  => strtolower( get_woocommerce_currency() ),
441
-					'country_code'   => substr( get_option( 'woocommerce_default_country' ), 0, 2 ),
440
+					'currency_code'  => strtolower(get_woocommerce_currency()),
441
+					'country_code'   => substr(get_option('woocommerce_default_country'), 0, 2),
442 442
 					'needs_shipping' => WC()->cart->needs_shipping() ? 'yes' : 'no',
443 443
 				),
444 444
 				'button' => array(
445 445
 					'type'   => $this->get_button_type(),
446 446
 					'theme'  => $this->get_button_theme(),
447 447
 					'height' => $this->get_button_height(),
448
-					'locale' => substr( get_locale(), 0, 2 ), // Default format is en_US.
448
+					'locale' => substr(get_locale(), 0, 2), // Default format is en_US.
449 449
 				),
450 450
 				'is_product_page' => is_product(),
451 451
 				'product'         => $this->get_product_data(),
452 452
 			)
453 453
 		);
454 454
 
455
-		wp_enqueue_script( 'wc_stripe_payment_request' );
455
+		wp_enqueue_script('wc_stripe_payment_request');
456 456
 	}
457 457
 
458 458
 	/**
@@ -464,35 +464,35 @@  discard block
 block discarded – undo
464 464
 	public function display_payment_request_button_html() {
465 465
 		$gateways = WC()->payment_gateways->get_available_payment_gateways();
466 466
 
467
-		if ( ! isset( $gateways['stripe'] ) ) {
467
+		if ( ! isset($gateways['stripe'])) {
468 468
 			return;
469 469
 		}
470 470
 
471
-		if ( ! is_cart() && ! is_checkout() && ! is_product() && ! isset( $_GET['pay_for_order'] ) ) {
471
+		if ( ! is_cart() && ! is_checkout() && ! is_product() && ! isset($_GET['pay_for_order'])) {
472 472
 			return;
473 473
 		}
474 474
 
475
-		if ( is_product() && apply_filters( 'wc_stripe_hide_payment_request_on_product_page', false ) ) {
475
+		if (is_product() && apply_filters('wc_stripe_hide_payment_request_on_product_page', false)) {
476 476
 			return;
477 477
 		}
478 478
 
479
-		if ( is_product() ) {
479
+		if (is_product()) {
480 480
 			global $post;
481 481
 
482
-			$product = wc_get_product( $post->ID );
482
+			$product = wc_get_product($post->ID);
483 483
 
484
-			if ( ! is_object( $product ) || ! in_array( ( WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type() ), $this->supported_product_types() ) ) {
484
+			if ( ! is_object($product) || ! in_array((WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type()), $this->supported_product_types())) {
485 485
 				return;
486 486
 			}
487 487
 
488 488
 			// Pre Orders charge upon release not supported.
489
-			if ( class_exists( 'WC_Pre_Orders_Order' ) && WC_Pre_Orders_Product::product_is_charged_upon_release( $product ) ) {
490
-				WC_Stripe_Logger::log( 'Pre Order charge upon release is not supported. ( Payment Request button disabled )' );
489
+			if (class_exists('WC_Pre_Orders_Order') && WC_Pre_Orders_Product::product_is_charged_upon_release($product)) {
490
+				WC_Stripe_Logger::log('Pre Order charge upon release is not supported. ( Payment Request button disabled )');
491 491
 				return;
492 492
 			}
493 493
 		} else {
494
-			if ( ! $this->allowed_items_in_cart() ) {
495
-				WC_Stripe_Logger::log( 'Items in the cart has unsupported product type ( Payment Request button disabled )' );
494
+			if ( ! $this->allowed_items_in_cart()) {
495
+				WC_Stripe_Logger::log('Items in the cart has unsupported product type ( Payment Request button disabled )');
496 496
 				return;
497 497
 			}
498 498
 		}
@@ -514,40 +514,40 @@  discard block
 block discarded – undo
514 514
 	public function display_payment_request_button_separator_html() {
515 515
 		$gateways = WC()->payment_gateways->get_available_payment_gateways();
516 516
 
517
-		if ( ! isset( $gateways['stripe'] ) ) {
517
+		if ( ! isset($gateways['stripe'])) {
518 518
 			return;
519 519
 		}
520 520
 
521
-		if ( ! is_cart() && ! is_checkout() && ! is_product() && ! isset( $_GET['pay_for_order'] ) ) {
521
+		if ( ! is_cart() && ! is_checkout() && ! is_product() && ! isset($_GET['pay_for_order'])) {
522 522
 			return;
523 523
 		}
524 524
 
525
-		if ( is_product() && apply_filters( 'wc_stripe_hide_payment_request_on_product_page', false ) ) {
525
+		if (is_product() && apply_filters('wc_stripe_hide_payment_request_on_product_page', false)) {
526 526
 			return;
527 527
 		}
528 528
 
529
-		if ( is_product() ) {
529
+		if (is_product()) {
530 530
 			global $post;
531 531
 
532
-			$product = wc_get_product( $post->ID );
532
+			$product = wc_get_product($post->ID);
533 533
 
534
-			if ( ! is_object( $product ) || ! in_array( ( WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type() ), $this->supported_product_types() ) ) {
534
+			if ( ! is_object($product) || ! in_array((WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type()), $this->supported_product_types())) {
535 535
 				return;
536 536
 			}
537 537
 
538 538
 			// Pre Orders charge upon release not supported.
539
-			if ( class_exists( 'WC_Pre_Orders_Order' ) && WC_Pre_Orders_Product::product_is_charged_upon_release( $product ) ) {
540
-				WC_Stripe_Logger::log( 'Pre Order charge upon release is not supported. ( Payment Request button disabled )' );
539
+			if (class_exists('WC_Pre_Orders_Order') && WC_Pre_Orders_Product::product_is_charged_upon_release($product)) {
540
+				WC_Stripe_Logger::log('Pre Order charge upon release is not supported. ( Payment Request button disabled )');
541 541
 				return;
542 542
 			}
543 543
 		} else {
544
-			if ( ! $this->allowed_items_in_cart() ) {
545
-				WC_Stripe_Logger::log( 'Items in the cart has unsupported product type ( Payment Request button disabled )' );
544
+			if ( ! $this->allowed_items_in_cart()) {
545
+				WC_Stripe_Logger::log('Items in the cart has unsupported product type ( Payment Request button disabled )');
546 546
 				return;
547 547
 			}
548 548
 		}
549 549
 		?>
550
-		<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>
550
+		<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>
551 551
 		<?php
552 552
 	}
553 553
 
@@ -558,11 +558,11 @@  discard block
 block discarded – undo
558 558
 	 * @version 4.0.0
559 559
 	 */
560 560
 	public function ajax_log_errors() {
561
-		check_ajax_referer( 'wc-stripe-log-errors', 'security' );
561
+		check_ajax_referer('wc-stripe-log-errors', 'security');
562 562
 
563
-		$errors = wc_clean( stripslashes( $_POST['errors'] ) );
563
+		$errors = wc_clean(stripslashes($_POST['errors']));
564 564
 
565
-		WC_Stripe_Logger::log( $errors );
565
+		WC_Stripe_Logger::log($errors);
566 566
 
567 567
 		exit;
568 568
 	}
@@ -574,7 +574,7 @@  discard block
 block discarded – undo
574 574
 	 * @version 4.0.0
575 575
 	 */
576 576
 	public function ajax_clear_cart() {
577
-		check_ajax_referer( 'wc-stripe-clear-cart', 'security' );
577
+		check_ajax_referer('wc-stripe-clear-cart', 'security');
578 578
 
579 579
 		WC()->cart->empty_cart();
580 580
 		exit;
@@ -584,10 +584,10 @@  discard block
 block discarded – undo
584 584
 	 * Get cart details.
585 585
 	 */
586 586
 	public function ajax_get_cart_details() {
587
-		check_ajax_referer( 'wc-stripe-payment-request', 'security' );
587
+		check_ajax_referer('wc-stripe-payment-request', 'security');
588 588
 
589
-		if ( ! defined( 'WOOCOMMERCE_CART' ) ) {
590
-			define( 'WOOCOMMERCE_CART', true );
589
+		if ( ! defined('WOOCOMMERCE_CART')) {
590
+			define('WOOCOMMERCE_CART', true);
591 591
 		}
592 592
 
593 593
 		WC()->cart->calculate_totals();
@@ -598,14 +598,14 @@  discard block
 block discarded – undo
598 598
 		$data = array(
599 599
 			'shipping_required' => WC()->cart->needs_shipping(),
600 600
 			'order_data'        => array(
601
-				'currency'        => strtolower( $currency ),
602
-				'country_code'    => substr( get_option( 'woocommerce_default_country' ), 0, 2 ),
601
+				'currency'        => strtolower($currency),
602
+				'country_code'    => substr(get_option('woocommerce_default_country'), 0, 2),
603 603
 			),
604 604
 		);
605 605
 
606 606
 		$data['order_data'] += $this->build_display_items();
607 607
 
608
-		wp_send_json( $data );
608
+		wp_send_json($data);
609 609
 	}
610 610
 
611 611
 	/**
@@ -616,47 +616,47 @@  discard block
 block discarded – undo
616 616
 	 * @see WC_Shipping::get_packages().
617 617
 	 */
618 618
 	public function ajax_get_shipping_options() {
619
-		check_ajax_referer( 'wc-stripe-payment-request-shipping', 'security' );
619
+		check_ajax_referer('wc-stripe-payment-request-shipping', 'security');
620 620
 
621 621
 		try {
622 622
 			// Set the shipping package.
623
-			$posted = filter_input_array( INPUT_POST, array(
623
+			$posted = filter_input_array(INPUT_POST, array(
624 624
 				'country'   => FILTER_SANITIZE_STRING,
625 625
 				'state'     => FILTER_SANITIZE_STRING,
626 626
 				'postcode'  => FILTER_SANITIZE_STRING,
627 627
 				'city'      => FILTER_SANITIZE_STRING,
628 628
 				'address'   => FILTER_SANITIZE_STRING,
629 629
 				'address_2' => FILTER_SANITIZE_STRING,
630
-			) );
630
+			));
631 631
 
632
-			$this->calculate_shipping( $posted );
632
+			$this->calculate_shipping($posted);
633 633
 
634 634
 			// Set the shipping options.
635 635
 			$data     = array();
636 636
 			$packages = WC()->shipping->get_packages();
637 637
 
638
-			if ( ! empty( $packages ) && WC()->customer->has_calculated_shipping() ) {
639
-				foreach ( $packages as $package_key => $package ) {
640
-					if ( empty( $package['rates'] ) ) {
641
-						throw new Exception( __( 'Unable to find shipping method for address.', 'woocommerce-gateway-stripe' ) );
638
+			if ( ! empty($packages) && WC()->customer->has_calculated_shipping()) {
639
+				foreach ($packages as $package_key => $package) {
640
+					if (empty($package['rates'])) {
641
+						throw new Exception(__('Unable to find shipping method for address.', 'woocommerce-gateway-stripe'));
642 642
 					}
643 643
 
644
-					foreach ( $package['rates'] as $key => $rate ) {
644
+					foreach ($package['rates'] as $key => $rate) {
645 645
 						$data['shipping_options'][] = array(
646 646
 							'id'       => $rate->id,
647 647
 							'label'    => $rate->label,
648 648
 							'detail'   => '',
649
-							'amount'   => WC_Stripe_Helper::get_stripe_amount( $rate->cost ),
649
+							'amount'   => WC_Stripe_Helper::get_stripe_amount($rate->cost),
650 650
 						);
651 651
 					}
652 652
 				}
653 653
 			} else {
654
-				throw new Exception( __( 'Unable to find shipping method for address.', 'woocommerce-gateway-stripe' ) );
654
+				throw new Exception(__('Unable to find shipping method for address.', 'woocommerce-gateway-stripe'));
655 655
 			}
656 656
 
657
-			if ( isset( $data[0] ) ) {
657
+			if (isset($data[0])) {
658 658
 				// Auto select the first shipping method.
659
-				WC()->session->set( 'chosen_shipping_methods', array( $data[0]['id'] ) );
659
+				WC()->session->set('chosen_shipping_methods', array($data[0]['id']));
660 660
 			}
661 661
 
662 662
 			WC()->cart->calculate_totals();
@@ -664,12 +664,12 @@  discard block
 block discarded – undo
664 664
 			$data += $this->build_display_items();
665 665
 			$data['result'] = 'success';
666 666
 
667
-			wp_send_json( $data );
668
-		} catch ( Exception $e ) {
667
+			wp_send_json($data);
668
+		} catch (Exception $e) {
669 669
 			$data += $this->build_display_items();
670 670
 			$data['result'] = 'invalid_shipping_address';
671 671
 
672
-			wp_send_json( $data );
672
+			wp_send_json($data);
673 673
 		}
674 674
 	}
675 675
 
@@ -677,22 +677,22 @@  discard block
 block discarded – undo
677 677
 	 * Update shipping method.
678 678
 	 */
679 679
 	public function ajax_update_shipping_method() {
680
-		check_ajax_referer( 'wc-stripe-update-shipping-method', 'security' );
680
+		check_ajax_referer('wc-stripe-update-shipping-method', 'security');
681 681
 
682
-		if ( ! defined( 'WOOCOMMERCE_CART' ) ) {
683
-			define( 'WOOCOMMERCE_CART', true );
682
+		if ( ! defined('WOOCOMMERCE_CART')) {
683
+			define('WOOCOMMERCE_CART', true);
684 684
 		}
685 685
 
686
-		$chosen_shipping_methods = WC()->session->get( 'chosen_shipping_methods' );
687
-		$shipping_method         = filter_input( INPUT_POST, 'shipping_method', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY );
686
+		$chosen_shipping_methods = WC()->session->get('chosen_shipping_methods');
687
+		$shipping_method         = filter_input(INPUT_POST, 'shipping_method', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY);
688 688
 
689
-		if ( is_array( $shipping_method ) ) {
690
-			foreach ( $shipping_method as $i => $value ) {
691
-				$chosen_shipping_methods[ $i ] = wc_clean( $value );
689
+		if (is_array($shipping_method)) {
690
+			foreach ($shipping_method as $i => $value) {
691
+				$chosen_shipping_methods[$i] = wc_clean($value);
692 692
 			}
693 693
 		}
694 694
 
695
-		WC()->session->set( 'chosen_shipping_methods', $chosen_shipping_methods );
695
+		WC()->session->set('chosen_shipping_methods', $chosen_shipping_methods);
696 696
 
697 697
 		WC()->cart->calculate_totals();
698 698
 
@@ -700,7 +700,7 @@  discard block
 block discarded – undo
700 700
 		$data += $this->build_display_items();
701 701
 		$data['result'] = 'success';
702 702
 
703
-		wp_send_json( $data );
703
+		wp_send_json($data);
704 704
 	}
705 705
 
706 706
 	/**
@@ -711,31 +711,31 @@  discard block
 block discarded – undo
711 711
 	 * @return array $data
712 712
 	 */
713 713
 	public function ajax_get_selected_product_data() {
714
-		check_ajax_referer( 'wc-stripe-get-selected-product-data', 'security' );
714
+		check_ajax_referer('wc-stripe-get-selected-product-data', 'security');
715 715
 
716
-		$product_id = absint( $_POST['product_id'] );
717
-		$qty = ! isset( $_POST['qty'] ) ? 1 : absint( $_POST['qty'] );
716
+		$product_id = absint($_POST['product_id']);
717
+		$qty = ! isset($_POST['qty']) ? 1 : absint($_POST['qty']);
718 718
 
719
-		$product = wc_get_product( $product_id );
719
+		$product = wc_get_product($product_id);
720 720
 
721
-		if ( 'variable' === ( WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type() ) && isset( $_POST['attributes'] ) ) {
722
-			$attributes = array_map( 'wc_clean', $_POST['attributes'] );
721
+		if ('variable' === (WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type()) && isset($_POST['attributes'])) {
722
+			$attributes = array_map('wc_clean', $_POST['attributes']);
723 723
 
724
-			if ( WC_Stripe_Helper::is_pre_30() ) {
725
-				$variation_id = $product->get_matching_variation( $attributes );
724
+			if (WC_Stripe_Helper::is_pre_30()) {
725
+				$variation_id = $product->get_matching_variation($attributes);
726 726
 			} else {
727
-				$data_store = WC_Data_Store::load( 'product' );
728
-				$variation_id = $data_store->find_matching_product_variation( $product, $attributes );
727
+				$data_store = WC_Data_Store::load('product');
728
+				$variation_id = $data_store->find_matching_product_variation($product, $attributes);
729 729
 			}
730 730
 
731
-			if ( ! empty( $variation_id ) ) {
732
-				$product = wc_get_product( $variation_id );
731
+			if ( ! empty($variation_id)) {
732
+				$product = wc_get_product($variation_id);
733 733
 			}
734
-		} elseif ( 'simple' === ( WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type() ) ) {
735
-			$product = wc_get_product( $product_id );
734
+		} elseif ('simple' === (WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type())) {
735
+			$product = wc_get_product($product_id);
736 736
 		}
737 737
 
738
-		$total = $qty * ( WC_Stripe_Helper::is_pre_30() ? $product->price : $product->get_price() );
738
+		$total = $qty * (WC_Stripe_Helper::is_pre_30() ? $product->price : $product->get_price());
739 739
 
740 740
 		$quantity_label = 1 < $qty ? ' (x' . $qty . ')' : '';
741 741
 
@@ -743,28 +743,28 @@  discard block
 block discarded – undo
743 743
 		$items = array();
744 744
 
745 745
 		$items[] = array(
746
-			'label'  => ( WC_Stripe_Helper::is_pre_30() ? $product->name : $product->get_name() ) . $quantity_label,
747
-			'amount' => WC_Stripe_Helper::get_stripe_amount( $total ),
746
+			'label'  => (WC_Stripe_Helper::is_pre_30() ? $product->name : $product->get_name()) . $quantity_label,
747
+			'amount' => WC_Stripe_Helper::get_stripe_amount($total),
748 748
 		);
749 749
 
750
-		if ( wc_tax_enabled() ) {
750
+		if (wc_tax_enabled()) {
751 751
 			$items[] = array(
752
-				'label'   => __( 'Tax', 'woocommerce-gateway-stripe' ),
752
+				'label'   => __('Tax', 'woocommerce-gateway-stripe'),
753 753
 				'amount'  => 0,
754 754
 				'pending' => true,
755 755
 			);
756 756
 		}
757 757
 
758
-		if ( wc_shipping_enabled() && $product->needs_shipping() ) {
758
+		if (wc_shipping_enabled() && $product->needs_shipping()) {
759 759
 			$items[] = array(
760
-				'label'   => __( 'Shipping', 'woocommerce-gateway-stripe' ),
760
+				'label'   => __('Shipping', 'woocommerce-gateway-stripe'),
761 761
 				'amount'  => 0,
762 762
 				'pending' => true,
763 763
 			);
764 764
 
765
-			$data['shippingOptions']  = array(
765
+			$data['shippingOptions'] = array(
766 766
 				'id'     => 'pending',
767
-				'label'  => __( 'Pending', 'woocommerce-gateway-stripe' ),
767
+				'label'  => __('Pending', 'woocommerce-gateway-stripe'),
768 768
 				'detail' => '',
769 769
 				'amount' => 0,
770 770
 			);
@@ -773,15 +773,15 @@  discard block
 block discarded – undo
773 773
 		$data['displayItems'] = $items;
774 774
 		$data['total'] = array(
775 775
 			'label'   => $this->total_label,
776
-			'amount'  => WC_Stripe_Helper::get_stripe_amount( $total ),
776
+			'amount'  => WC_Stripe_Helper::get_stripe_amount($total),
777 777
 			'pending' => true,
778 778
 		);
779 779
 
780
-		$data['requestShipping'] = ( wc_shipping_enabled() && $product->needs_shipping() );
781
-		$data['currency']        = strtolower( get_woocommerce_currency() );
782
-		$data['country_code']    = substr( get_option( 'woocommerce_default_country' ), 0, 2 );
780
+		$data['requestShipping'] = (wc_shipping_enabled() && $product->needs_shipping());
781
+		$data['currency']        = strtolower(get_woocommerce_currency());
782
+		$data['country_code']    = substr(get_option('woocommerce_default_country'), 0, 2);
783 783
 
784
-		wp_send_json( $data );
784
+		wp_send_json($data);
785 785
 	}
786 786
 
787 787
 	/**
@@ -792,37 +792,37 @@  discard block
 block discarded – undo
792 792
 	 * @return array $data
793 793
 	 */
794 794
 	public function ajax_add_to_cart() {
795
-		check_ajax_referer( 'wc-stripe-add-to-cart', 'security' );
795
+		check_ajax_referer('wc-stripe-add-to-cart', 'security');
796 796
 
797
-		if ( ! defined( 'WOOCOMMERCE_CART' ) ) {
798
-			define( 'WOOCOMMERCE_CART', true );
797
+		if ( ! defined('WOOCOMMERCE_CART')) {
798
+			define('WOOCOMMERCE_CART', true);
799 799
 		}
800 800
 
801 801
 		WC()->shipping->reset_shipping();
802 802
 
803
-		$product_id = absint( $_POST['product_id'] );
804
-		$qty = ! isset( $_POST['qty'] ) ? 1 : absint( $_POST['qty'] );
803
+		$product_id = absint($_POST['product_id']);
804
+		$qty = ! isset($_POST['qty']) ? 1 : absint($_POST['qty']);
805 805
 
806
-		$product = wc_get_product( $product_id );
806
+		$product = wc_get_product($product_id);
807 807
 
808 808
 		// First empty the cart to prevent wrong calculation.
809 809
 		WC()->cart->empty_cart();
810 810
 
811
-		if ( 'variable' === ( WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type() ) && isset( $_POST['attributes'] ) ) {
812
-			$attributes = array_map( 'wc_clean', $_POST['attributes'] );
811
+		if ('variable' === (WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type()) && isset($_POST['attributes'])) {
812
+			$attributes = array_map('wc_clean', $_POST['attributes']);
813 813
 
814
-			if ( WC_Stripe_Helper::is_pre_30() ) {
815
-				$variation_id = $product->get_matching_variation( $attributes );
814
+			if (WC_Stripe_Helper::is_pre_30()) {
815
+				$variation_id = $product->get_matching_variation($attributes);
816 816
 			} else {
817
-				$data_store = WC_Data_Store::load( 'product' );
818
-				$variation_id = $data_store->find_matching_product_variation( $product, $attributes );
817
+				$data_store = WC_Data_Store::load('product');
818
+				$variation_id = $data_store->find_matching_product_variation($product, $attributes);
819 819
 			}
820 820
 
821
-			WC()->cart->add_to_cart( $product->get_id(), $qty, $variation_id, $attributes );
821
+			WC()->cart->add_to_cart($product->get_id(), $qty, $variation_id, $attributes);
822 822
 		}
823 823
 
824
-		if ( 'simple' === ( WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type() ) ) {
825
-			WC()->cart->add_to_cart( $product->get_id(), $qty );
824
+		if ('simple' === (WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type())) {
825
+			WC()->cart->add_to_cart($product->get_id(), $qty);
826 826
 		}
827 827
 
828 828
 		WC()->cart->calculate_totals();
@@ -831,7 +831,7 @@  discard block
 block discarded – undo
831 831
 		$data += $this->build_display_items();
832 832
 		$data['result'] = 'success';
833 833
 
834
-		wp_send_json( $data );
834
+		wp_send_json($data);
835 835
 	}
836 836
 
837 837
 	/**
@@ -844,31 +844,31 @@  discard block
 block discarded – undo
844 844
 	 * @version 4.0.0
845 845
 	 */
846 846
 	public function normalize_state() {
847
-		$billing_country  = ! empty( $_POST['billing_country'] ) ? wc_clean( $_POST['billing_country'] ) : '';
848
-		$shipping_country = ! empty( $_POST['shipping_country'] ) ? wc_clean( $_POST['shipping_country'] ) : '';
849
-		$billing_state    = ! empty( $_POST['billing_state'] ) ? wc_clean( $_POST['billing_state'] ) : '';
850
-		$shipping_state   = ! empty( $_POST['shipping_state'] ) ? wc_clean( $_POST['shipping_state'] ) : '';
847
+		$billing_country  = ! empty($_POST['billing_country']) ? wc_clean($_POST['billing_country']) : '';
848
+		$shipping_country = ! empty($_POST['shipping_country']) ? wc_clean($_POST['shipping_country']) : '';
849
+		$billing_state    = ! empty($_POST['billing_state']) ? wc_clean($_POST['billing_state']) : '';
850
+		$shipping_state   = ! empty($_POST['shipping_state']) ? wc_clean($_POST['shipping_state']) : '';
851 851
 
852
-		if ( $billing_state && $billing_country ) {
853
-			$valid_states = WC()->countries->get_states( $billing_country );
852
+		if ($billing_state && $billing_country) {
853
+			$valid_states = WC()->countries->get_states($billing_country);
854 854
 
855 855
 			// Valid states found for country.
856
-			if ( ! empty( $valid_states ) && is_array( $valid_states ) && sizeof( $valid_states ) > 0 ) {
857
-				foreach ( $valid_states as $state_abbr => $state ) {
858
-					if ( preg_match( '/' . preg_quote( $state ) . '/i', $billing_state ) ) {
856
+			if ( ! empty($valid_states) && is_array($valid_states) && sizeof($valid_states) > 0) {
857
+				foreach ($valid_states as $state_abbr => $state) {
858
+					if (preg_match('/' . preg_quote($state) . '/i', $billing_state)) {
859 859
 						$_POST['billing_state'] = $state_abbr;
860 860
 					}
861 861
 				}
862 862
 			}
863 863
 		}
864 864
 
865
-		if ( $shipping_state && $shipping_country ) {
866
-			$valid_states = WC()->countries->get_states( $shipping_country );
865
+		if ($shipping_state && $shipping_country) {
866
+			$valid_states = WC()->countries->get_states($shipping_country);
867 867
 
868 868
 			// Valid states found for country.
869
-			if ( ! empty( $valid_states ) && is_array( $valid_states ) && sizeof( $valid_states ) > 0 ) {
870
-				foreach ( $valid_states as $state_abbr => $state ) {
871
-					if ( preg_match( '/' . preg_quote( $state ) . '/i', $shipping_state ) ) {
869
+			if ( ! empty($valid_states) && is_array($valid_states) && sizeof($valid_states) > 0) {
870
+				foreach ($valid_states as $state_abbr => $state) {
871
+					if (preg_match('/' . preg_quote($state) . '/i', $shipping_state)) {
872 872
 						$_POST['shipping_state'] = $state_abbr;
873 873
 					}
874 874
 				}
@@ -883,19 +883,19 @@  discard block
 block discarded – undo
883 883
 	 * @version 4.0.0
884 884
 	 */
885 885
 	public function ajax_create_order() {
886
-		if ( WC()->cart->is_empty() ) {
887
-			wp_send_json_error( __( 'Empty cart', 'woocommerce-gateway-stripe' ) );
886
+		if (WC()->cart->is_empty()) {
887
+			wp_send_json_error(__('Empty cart', 'woocommerce-gateway-stripe'));
888 888
 		}
889 889
 
890
-		if ( ! defined( 'WOOCOMMERCE_CHECKOUT' ) ) {
891
-			define( 'WOOCOMMERCE_CHECKOUT', true );
890
+		if ( ! defined('WOOCOMMERCE_CHECKOUT')) {
891
+			define('WOOCOMMERCE_CHECKOUT', true);
892 892
 		}
893 893
 
894 894
 		$this->normalize_state();
895 895
 
896 896
 		WC()->checkout()->process_checkout();
897 897
 
898
-		die( 0 );
898
+		die(0);
899 899
 	}
900 900
 
901 901
 	/**
@@ -905,7 +905,7 @@  discard block
 block discarded – undo
905 905
 	 * @version 4.0.0
906 906
 	 * @param array $address
907 907
 	 */
908
-	protected function calculate_shipping( $address = array() ) {
908
+	protected function calculate_shipping($address = array()) {
909 909
 		global $states;
910 910
 
911 911
 		$country   = $address['country'];
@@ -922,28 +922,28 @@  discard block
 block discarded – undo
922 922
 		 * In some versions of Chrome, state can be a full name. So we need
923 923
 		 * to convert that to abbreviation as WC is expecting that.
924 924
 		 */
925
-		if ( 2 < strlen( $state ) ) {
926
-			$state = array_search( ucfirst( strtolower( $state ) ), $states[ $country ] );
925
+		if (2 < strlen($state)) {
926
+			$state = array_search(ucfirst(strtolower($state)), $states[$country]);
927 927
 		}
928 928
 
929 929
 		WC()->shipping->reset_shipping();
930 930
 
931
-		if ( $postcode && WC_Validation::is_postcode( $postcode, $country ) ) {
932
-			$postcode = wc_format_postcode( $postcode, $country );
931
+		if ($postcode && WC_Validation::is_postcode($postcode, $country)) {
932
+			$postcode = wc_format_postcode($postcode, $country);
933 933
 		}
934 934
 
935
-		if ( $country ) {
936
-			WC()->customer->set_location( $country, $state, $postcode, $city );
937
-			WC()->customer->set_shipping_location( $country, $state, $postcode, $city );
935
+		if ($country) {
936
+			WC()->customer->set_location($country, $state, $postcode, $city);
937
+			WC()->customer->set_shipping_location($country, $state, $postcode, $city);
938 938
 		} else {
939 939
 			WC_Stripe_Helper::is_pre_30() ? WC()->customer->set_to_base() : WC()->customer->set_billing_address_to_base();
940 940
 			WC_Stripe_Helper::is_pre_30() ? WC()->customer->set_shipping_to_base() : WC()->customer->set_shipping_address_to_base();
941 941
 		}
942 942
 
943
-		if ( WC_Stripe_Helper::is_pre_30() ) {
944
-			WC()->customer->calculated_shipping( true );
943
+		if (WC_Stripe_Helper::is_pre_30()) {
944
+			WC()->customer->calculated_shipping(true);
945 945
 		} else {
946
-			WC()->customer->set_calculated_shipping( true );
946
+			WC()->customer->set_calculated_shipping(true);
947 947
 			WC()->customer->save();
948 948
 		}
949 949
 
@@ -960,17 +960,17 @@  discard block
 block discarded – undo
960 960
 		$packages[0]['destination']['address']   = $address_1;
961 961
 		$packages[0]['destination']['address_2'] = $address_2;
962 962
 
963
-		foreach ( WC()->cart->get_cart() as $item ) {
964
-			if ( $item['data']->needs_shipping() ) {
965
-				if ( isset( $item['line_total'] ) ) {
963
+		foreach (WC()->cart->get_cart() as $item) {
964
+			if ($item['data']->needs_shipping()) {
965
+				if (isset($item['line_total'])) {
966 966
 					$packages[0]['contents_cost'] += $item['line_total'];
967 967
 				}
968 968
 			}
969 969
 		}
970 970
 
971
-		$packages = apply_filters( 'woocommerce_cart_shipping_packages', $packages );
971
+		$packages = apply_filters('woocommerce_cart_shipping_packages', $packages);
972 972
 
973
-		WC()->shipping->calculate_shipping( $packages );
973
+		WC()->shipping->calculate_shipping($packages);
974 974
 	}
975 975
 
976 976
 	/**
@@ -979,19 +979,19 @@  discard block
 block discarded – undo
979 979
 	 * @since 3.1.0
980 980
 	 * @version 4.0.0
981 981
 	 */
982
-	protected function build_shipping_methods( $shipping_methods ) {
983
-		if ( empty( $shipping_methods ) ) {
982
+	protected function build_shipping_methods($shipping_methods) {
983
+		if (empty($shipping_methods)) {
984 984
 			return array();
985 985
 		}
986 986
 
987 987
 		$shipping = array();
988 988
 
989
-		foreach ( $shipping_methods as $method ) {
989
+		foreach ($shipping_methods as $method) {
990 990
 			$shipping[] = array(
991 991
 				'id'         => $method['id'],
992 992
 				'label'      => $method['label'],
993 993
 				'detail'     => '',
994
-				'amount'     => WC_Stripe_Helper::get_stripe_amount( $method['amount']['value'] ),
994
+				'amount'     => WC_Stripe_Helper::get_stripe_amount($method['amount']['value']),
995 995
 			);
996 996
 		}
997 997
 
@@ -1005,69 +1005,69 @@  discard block
 block discarded – undo
1005 1005
 	 * @version 4.0.0
1006 1006
 	 */
1007 1007
 	protected function build_display_items() {
1008
-		if ( ! defined( 'WOOCOMMERCE_CART' ) ) {
1009
-			define( 'WOOCOMMERCE_CART', true );
1008
+		if ( ! defined('WOOCOMMERCE_CART')) {
1009
+			define('WOOCOMMERCE_CART', true);
1010 1010
 		}
1011 1011
 
1012 1012
 		$items    = array();
1013 1013
 		$subtotal = 0;
1014 1014
 
1015 1015
 		// Default show only subtotal instead of itemization.
1016
-		if ( ! apply_filters( 'wc_stripe_payment_request_hide_itemization', true ) ) {
1017
-			foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {
1016
+		if ( ! apply_filters('wc_stripe_payment_request_hide_itemization', true)) {
1017
+			foreach (WC()->cart->get_cart() as $cart_item_key => $cart_item) {
1018 1018
 				$amount         = $cart_item['line_subtotal'];
1019
-				$subtotal       += $cart_item['line_subtotal'];
1019
+				$subtotal += $cart_item['line_subtotal'];
1020 1020
 				$quantity_label = 1 < $cart_item['quantity'] ? ' (x' . $cart_item['quantity'] . ')' : '';
1021 1021
 
1022 1022
 				$product_name = WC_Stripe_Helper::is_pre_30() ? $cart_item['data']->post->post_title : $cart_item['data']->get_name();
1023 1023
 
1024 1024
 				$item = array(
1025 1025
 					'label'  => $product_name . $quantity_label,
1026
-					'amount' => WC_Stripe_Helper::get_stripe_amount( $amount ),
1026
+					'amount' => WC_Stripe_Helper::get_stripe_amount($amount),
1027 1027
 				);
1028 1028
 
1029 1029
 				$items[] = $item;
1030 1030
 			}
1031 1031
 		}
1032 1032
 
1033
-		$discounts   = wc_format_decimal( WC()->cart->get_cart_discount_total(), WC()->cart->dp );
1034
-		$tax         = wc_format_decimal( WC()->cart->tax_total + WC()->cart->shipping_tax_total, WC()->cart->dp );
1035
-		$shipping    = wc_format_decimal( WC()->cart->shipping_total, WC()->cart->dp );
1036
-		$items_total = wc_format_decimal( WC()->cart->cart_contents_total, WC()->cart->dp ) + $discounts;
1037
-		$order_total = wc_format_decimal( $items_total + $tax + $shipping - $discounts, WC()->cart->dp );
1033
+		$discounts   = wc_format_decimal(WC()->cart->get_cart_discount_total(), WC()->cart->dp);
1034
+		$tax         = wc_format_decimal(WC()->cart->tax_total + WC()->cart->shipping_tax_total, WC()->cart->dp);
1035
+		$shipping    = wc_format_decimal(WC()->cart->shipping_total, WC()->cart->dp);
1036
+		$items_total = wc_format_decimal(WC()->cart->cart_contents_total, WC()->cart->dp) + $discounts;
1037
+		$order_total = wc_format_decimal($items_total + $tax + $shipping - $discounts, WC()->cart->dp);
1038 1038
 
1039
-		if ( wc_tax_enabled() ) {
1039
+		if (wc_tax_enabled()) {
1040 1040
 			$items[] = array(
1041
-				'label'  => esc_html( __( 'Tax', 'woocommerce-gateway-stripe' ) ),
1042
-				'amount' => WC_Stripe_Helper::get_stripe_amount( $tax ),
1041
+				'label'  => esc_html(__('Tax', 'woocommerce-gateway-stripe')),
1042
+				'amount' => WC_Stripe_Helper::get_stripe_amount($tax),
1043 1043
 			);
1044 1044
 		}
1045 1045
 
1046
-		if ( WC()->cart->needs_shipping() ) {
1046
+		if (WC()->cart->needs_shipping()) {
1047 1047
 			$items[] = array(
1048
-				'label'  => esc_html( __( 'Shipping', 'woocommerce-gateway-stripe' ) ),
1049
-				'amount' => WC_Stripe_Helper::get_stripe_amount( $shipping ),
1048
+				'label'  => esc_html(__('Shipping', 'woocommerce-gateway-stripe')),
1049
+				'amount' => WC_Stripe_Helper::get_stripe_amount($shipping),
1050 1050
 			);
1051 1051
 		}
1052 1052
 
1053
-		if ( WC()->cart->has_discount() ) {
1053
+		if (WC()->cart->has_discount()) {
1054 1054
 			$items[] = array(
1055
-				'label'  => esc_html( __( 'Discount', 'woocommerce-gateway-stripe' ) ),
1056
-				'amount' => WC_Stripe_Helper::get_stripe_amount( $discounts ),
1055
+				'label'  => esc_html(__('Discount', 'woocommerce-gateway-stripe')),
1056
+				'amount' => WC_Stripe_Helper::get_stripe_amount($discounts),
1057 1057
 			);
1058 1058
 		}
1059 1059
 
1060
-		if ( version_compare( WC_VERSION, '3.2', '<' ) ) {
1060
+		if (version_compare(WC_VERSION, '3.2', '<')) {
1061 1061
 			$cart_fees = WC()->cart->fees;
1062 1062
 		} else {
1063 1063
 			$cart_fees = WC()->cart->get_fees();
1064 1064
 		}
1065 1065
 
1066 1066
 		// Include fees and taxes as display items.
1067
-		foreach ( $cart_fees as $key => $fee ) {
1067
+		foreach ($cart_fees as $key => $fee) {
1068 1068
 			$items[] = array(
1069 1069
 				'label'  => $fee->name,
1070
-				'amount' => WC_Stripe_Helper::get_stripe_amount( $fee->amount ),
1070
+				'amount' => WC_Stripe_Helper::get_stripe_amount($fee->amount),
1071 1071
 			);
1072 1072
 		}
1073 1073
 
@@ -1075,7 +1075,7 @@  discard block
 block discarded – undo
1075 1075
 			'displayItems' => $items,
1076 1076
 			'total'      => array(
1077 1077
 				'label'   => $this->total_label,
1078
-				'amount'  => max( 0, apply_filters( 'woocommerce_stripe_calculated_total', WC_Stripe_Helper::get_stripe_amount( $order_total ), $order_total, WC()->cart ) ),
1078
+				'amount'  => max(0, apply_filters('woocommerce_stripe_calculated_total', WC_Stripe_Helper::get_stripe_amount($order_total), $order_total, WC()->cart)),
1079 1079
 				'pending' => false,
1080 1080
 			),
1081 1081
 		);
Please login to merge, or discard this patch.