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