Completed
Push — master ( 36b2d8...0f5357 )
by Roy
02:13
created
includes/abstracts/abstract-wc-stripe-payment-gateway.php 1 patch
Spacing   +177 added lines, -178 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
 
@@ -18,11 +18,11 @@  discard block
 block discarded – undo
18 18
 	 * Check if this gateway is enabled
19 19
 	 */
20 20
 	public function is_available() {
21
-		if ( 'yes' === $this->enabled ) {
22
-			if ( ! $this->testmode && is_checkout() && ! is_ssl() ) {
21
+		if ('yes' === $this->enabled) {
22
+			if ( ! $this->testmode && is_checkout() && ! is_ssl()) {
23 23
 				return false;
24 24
 			}
25
-			if ( ! $this->secret_key || ! $this->publishable_key ) {
25
+			if ( ! $this->secret_key || ! $this->publishable_key) {
26 26
 				return false;
27 27
 			}
28 28
 			return true;
@@ -37,8 +37,8 @@  discard block
 block discarded – undo
37 37
 	 * @since 4.0.0
38 38
 	 * @version 4.0.0
39 39
 	 */
40
-	public function add_admin_notice( $slug, $class, $message ) {
41
-		$this->notices[ $slug ] = array(
40
+	public function add_admin_notice($slug, $class, $message) {
41
+		$this->notices[$slug] = array(
42 42
 			'class'   => $class,
43 43
 			'message' => $message,
44 44
 		);
@@ -51,8 +51,8 @@  discard block
 block discarded – undo
51 51
 	 * @version 4.0.0
52 52
 	 */
53 53
 	public function remove_admin_notice() {
54
-		if ( did_action( 'woocommerce_update_options' ) ) {
55
-			remove_action( 'admin_notices', array( $this, 'check_environment' ) );
54
+		if (did_action('woocommerce_update_options')) {
55
+			remove_action('admin_notices', array($this, 'check_environment'));
56 56
 		}
57 57
 	}
58 58
 
@@ -64,7 +64,7 @@  discard block
 block discarded – undo
64 64
 	 * @return array
65 65
 	 */
66 66
 	public function payment_icons() {
67
-		return apply_filters( 'wc_stripe_payment_icons', array(
67
+		return apply_filters('wc_stripe_payment_icons', array(
68 68
 			'visa'       => '<i class="stripe-pf stripe-pf-visa stripe-pf-right" alt="Visa" aria-hidden="true"></i>',
69 69
 			'amex'       => '<i class="stripe-pf stripe-pf-american-express stripe-pf-right" alt="Amex" aria-hidden="true"></i>',
70 70
 			'mastercard' => '<i class="stripe-pf stripe-pf-mastercard stripe-pf-right" alt="Mastercard" aria-hidden="true"></i>',
@@ -81,7 +81,7 @@  discard block
 block discarded – undo
81 81
 			'eps'        => '<i class="stripe-pf stripe-pf-eps stripe-pf-right" alt="EPS" aria-hidden="true"></i>',
82 82
 			'sofort'     => '<i class="stripe-pf stripe-pf-sofort stripe-pf-right" alt="SOFORT" aria-hidden="true"></i>',
83 83
 			'sepa'       => '<i class="stripe-pf stripe-pf-sepa stripe-pf-right" alt="SEPA" aria-hidden="true"></i>',
84
-		) );
84
+		));
85 85
 	}
86 86
 
87 87
 	/**
@@ -92,10 +92,10 @@  discard block
 block discarded – undo
92 92
 	 * @version 4.0.0
93 93
 	 * @param object $order
94 94
 	 */
95
-	public function validate_minimum_order_amount( $order ) {
96
-		if ( $order->get_total() * 100 < WC_Stripe_Helper::get_minimum_amount() ) {
95
+	public function validate_minimum_order_amount($order) {
96
+		if ($order->get_total() * 100 < WC_Stripe_Helper::get_minimum_amount()) {
97 97
 			/* translators: 1) dollar amount */
98
-			throw new WC_Stripe_Exception( 'Did not meet minimum amount', sprintf( __( 'Sorry, the minimum allowed order total is %1$s to use this payment method.', 'woocommerce-gateway-stripe' ), wc_price( WC_Stripe_Helper::get_minimum_amount() / 100 ) ) );
98
+			throw new WC_Stripe_Exception('Did not meet minimum amount', sprintf(__('Sorry, the minimum allowed order total is %1$s to use this payment method.', 'woocommerce-gateway-stripe'), wc_price(WC_Stripe_Helper::get_minimum_amount() / 100)));
99 99
 		}
100 100
 	}
101 101
 
@@ -105,14 +105,14 @@  discard block
 block discarded – undo
105 105
 	 * @since 4.0.0
106 106
 	 * @version 4.0.0
107 107
 	 */
108
-	public function get_transaction_url( $order ) {
109
-		if ( $this->testmode ) {
108
+	public function get_transaction_url($order) {
109
+		if ($this->testmode) {
110 110
 			$this->view_transaction_url = 'https://dashboard.stripe.com/test/payments/%s';
111 111
 		} else {
112 112
 			$this->view_transaction_url = 'https://dashboard.stripe.com/payments/%s';
113 113
 		}
114 114
 
115
-		return parent::get_transaction_url( $order );
115
+		return parent::get_transaction_url($order);
116 116
 	}
117 117
 
118 118
 	/**
@@ -121,15 +121,15 @@  discard block
 block discarded – undo
121 121
 	 * @since 4.0.0
122 122
 	 * @version 4.0.0
123 123
 	 */
124
-	public function get_stripe_customer_id( $order ) {
125
-		$customer = get_user_meta( WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id(), '_stripe_customer_id', true );
124
+	public function get_stripe_customer_id($order) {
125
+		$customer = get_user_meta(WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id(), '_stripe_customer_id', true);
126 126
 
127
-		if ( empty( $customer ) ) {
127
+		if (empty($customer)) {
128 128
 			// Try to get it via the order.
129
-			if ( WC_Stripe_Helper::is_pre_30() ) {
130
-				return get_post_meta( $order->id, '_stripe_customer_id', true );
129
+			if (WC_Stripe_Helper::is_pre_30()) {
130
+				return get_post_meta($order->id, '_stripe_customer_id', true);
131 131
 			} else {
132
-				return $order->get_meta( '_stripe_customer_id', true );
132
+				return $order->get_meta('_stripe_customer_id', true);
133 133
 			}
134 134
 		} else {
135 135
 			return $customer;
@@ -146,9 +146,9 @@  discard block
 block discarded – undo
146 146
 	 * @param object $order
147 147
 	 * @param int $id Stripe session id.
148 148
 	 */
149
-	public function get_stripe_return_url( $order = null, $id = null ) {
150
-		if ( is_object( $order ) ) {
151
-			if ( empty( $id ) ) {
149
+	public function get_stripe_return_url($order = null, $id = null) {
150
+		if (is_object($order)) {
151
+			if (empty($id)) {
152 152
 				$id = uniqid();
153 153
 			}
154 154
 
@@ -159,10 +159,10 @@  discard block
 block discarded – undo
159 159
 				'order_id'       => $order_id,
160 160
 			);
161 161
 
162
-			return esc_url_raw( add_query_arg( $args, $this->get_return_url( $order ) ) );
162
+			return esc_url_raw(add_query_arg($args, $this->get_return_url($order)));
163 163
 		}
164 164
 
165
-		return esc_url_raw( add_query_arg( array( 'utm_nooverride' => '1' ), $this->get_return_url() ) );
165
+		return esc_url_raw(add_query_arg(array('utm_nooverride' => '1'), $this->get_return_url()));
166 166
 	}
167 167
 
168 168
 	/**
@@ -174,27 +174,26 @@  discard block
 block discarded – undo
174 174
 	 * @param  object $source
175 175
 	 * @return array()
176 176
 	 */
177
-	public function generate_payment_request( $order, $source ) {
178
-		$settings                          = get_option( 'woocommerce_stripe_settings', array() );
179
-		$statement_descriptor              = ! empty( $settings['statement_descriptor'] ) ? str_replace( "'", '', $settings['statement_descriptor'] ) : '';
180
-		$capture                           = ! empty( $settings['capture'] ) && 'yes' === $settings['capture'] ? true : false;
177
+	public function generate_payment_request($order, $source) {
178
+		$settings                          = get_option('woocommerce_stripe_settings', array());
179
+		$statement_descriptor              = ! empty($settings['statement_descriptor']) ? str_replace("'", '', $settings['statement_descriptor']) : '';
180
+		$capture                           = ! empty($settings['capture']) && 'yes' === $settings['capture'] ? true : false;
181 181
 		$post_data                         = array();
182
-		$post_data['currency']             = strtolower( WC_Stripe_Helper::is_pre_30() ? $order->get_order_currency() : $order->get_currency() );
183
-		$post_data['amount']               = WC_Stripe_Helper::get_stripe_amount( $order->get_total(), $post_data['currency'] );
182
+		$post_data['currency']             = strtolower(WC_Stripe_Helper::is_pre_30() ? $order->get_order_currency() : $order->get_currency());
183
+		$post_data['amount']               = WC_Stripe_Helper::get_stripe_amount($order->get_total(), $post_data['currency']);
184 184
 		/* translators: 1) blog name 2) order number */
185
-		$post_data['description']          = sprintf( __( '%1$s - Order %2$s', 'woocommerce-gateway-stripe' ), wp_specialchars_decode( get_bloginfo( 'name' ), ENT_QUOTES ), $order->get_order_number() );
185
+		$post_data['description']          = sprintf(__('%1$s - Order %2$s', 'woocommerce-gateway-stripe'), wp_specialchars_decode(get_bloginfo('name'), ENT_QUOTES), $order->get_order_number());
186 186
 		$billing_email      = WC_Stripe_Helper::is_pre_30() ? $order->billing_email : $order->get_billing_email();
187 187
 		$billing_first_name = WC_Stripe_Helper::is_pre_30() ? $order->billing_first_name : $order->get_billing_first_name();
188 188
 		$billing_last_name  = WC_Stripe_Helper::is_pre_30() ? $order->billing_last_name : $order->get_billing_last_name();
189 189
 
190
-		if ( ! empty( $billing_email ) && apply_filters( 'wc_stripe_send_stripe_receipt', false ) ) {
190
+		if ( ! empty($billing_email) && apply_filters('wc_stripe_send_stripe_receipt', false)) {
191 191
 			$post_data['receipt_email'] = $billing_email;
192 192
 		}
193 193
 
194
-		switch ( WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method() ) {
195
-			case 'stripe':
196
-				if ( ! empty( $statement_descriptor ) ) {
197
-					$post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor( $statement_descriptor );
194
+		switch (WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method()) {
195
+			case 'stripe' : if ( ! empty($statement_descriptor)) {
196
+					$post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor($statement_descriptor);
198 197
 				}
199 198
 
200 199
 				$post_data['capture'] = $capture ? 'true' : 'false';
@@ -204,18 +203,18 @@  discard block
 block discarded – undo
204 203
 		$post_data['expand[]'] = 'balance_transaction';
205 204
 
206 205
 		$metadata = array(
207
-			__( 'customer_name', 'woocommerce-gateway-stripe' ) => sanitize_text_field( $billing_first_name ) . ' ' . sanitize_text_field( $billing_last_name ),
208
-			__( 'customer_email', 'woocommerce-gateway-stripe' ) => sanitize_email( $billing_email ),
206
+			__('customer_name', 'woocommerce-gateway-stripe') => sanitize_text_field($billing_first_name) . ' ' . sanitize_text_field($billing_last_name),
207
+			__('customer_email', 'woocommerce-gateway-stripe') => sanitize_email($billing_email),
209 208
 			'order_id' => WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(),
210 209
 		);
211 210
 
212
-		$post_data['metadata'] = apply_filters( 'wc_stripe_payment_metadata', $metadata, $order, $source );
211
+		$post_data['metadata'] = apply_filters('wc_stripe_payment_metadata', $metadata, $order, $source);
213 212
 
214
-		if ( $source->customer ) {
213
+		if ($source->customer) {
215 214
 			$post_data['customer'] = $source->customer;
216 215
 		}
217 216
 
218
-		if ( $source->source ) {
217
+		if ($source->source) {
219 218
 			$post_data['source'] = $source->source;
220 219
 		}
221 220
 
@@ -227,77 +226,77 @@  discard block
 block discarded – undo
227 226
 		 * @param WC_Order $order
228 227
 		 * @param object $source
229 228
 		 */
230
-		return apply_filters( 'wc_stripe_generate_payment_request', $post_data, $order, $source );
229
+		return apply_filters('wc_stripe_generate_payment_request', $post_data, $order, $source);
231 230
 	}
232 231
 
233 232
 	/**
234 233
 	 * Store extra meta data for an order from a Stripe Response.
235 234
 	 */
236
-	public function process_response( $response, $order ) {
237
-		WC_Stripe_Logger::log( 'Processing response: ' . print_r( $response, true ) );
235
+	public function process_response($response, $order) {
236
+		WC_Stripe_Logger::log('Processing response: ' . print_r($response, true));
238 237
 
239 238
 		$order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
240 239
 
241
-		$captured = ( isset( $response->captured ) && $response->captured ) ? 'yes' : 'no';
240
+		$captured = (isset($response->captured) && $response->captured) ? 'yes' : 'no';
242 241
 
243 242
 		// Store charge data
244
-		WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, '_stripe_charge_captured', $captured ) : $order->update_meta_data( '_stripe_charge_captured', $captured );
243
+		WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, '_stripe_charge_captured', $captured) : $order->update_meta_data('_stripe_charge_captured', $captured);
245 244
 
246 245
 		// Store other data such as fees
247
-		if ( isset( $response->balance_transaction ) && isset( $response->balance_transaction->fee ) ) {
246
+		if (isset($response->balance_transaction) && isset($response->balance_transaction->fee)) {
248 247
 			// Fees and Net needs to both come from Stripe to be accurate as the returned
249 248
 			// values are in the local currency of the Stripe account, not from WC.
250
-			$fee = ! empty( $response->balance_transaction->fee ) ? WC_Stripe_Helper::format_balance_fee( $response->balance_transaction, 'fee' ) : 0;
251
-			$net = ! empty( $response->balance_transaction->net ) ? WC_Stripe_Helper::format_balance_fee( $response->balance_transaction, 'net' ) : 0;
252
-			WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, self::META_NAME_FEE, $fee ) : $order->update_meta_data( self::META_NAME_FEE, $fee );
253
-			WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, self::META_NAME_NET, $net ) : $order->update_meta_data( self::META_NAME_NET, $net );
249
+			$fee = ! empty($response->balance_transaction->fee) ? WC_Stripe_Helper::format_balance_fee($response->balance_transaction, 'fee') : 0;
250
+			$net = ! empty($response->balance_transaction->net) ? WC_Stripe_Helper::format_balance_fee($response->balance_transaction, 'net') : 0;
251
+			WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, self::META_NAME_FEE, $fee) : $order->update_meta_data(self::META_NAME_FEE, $fee);
252
+			WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, self::META_NAME_NET, $net) : $order->update_meta_data(self::META_NAME_NET, $net);
254 253
 		}
255 254
 
256
-		if ( 'yes' === $captured ) {
255
+		if ('yes' === $captured) {
257 256
 			/**
258 257
 			 * Charge can be captured but in a pending state. Payment methods
259 258
 			 * that are asynchronous may take couple days to clear. Webhook will
260 259
 			 * take care of the status changes.
261 260
 			 */
262
-			if ( 'pending' === $response->status ) {
263
-				if ( ! wc_string_to_bool( get_post_meta( $order_id, '_order_stock_reduced', true ) ) ) {
264
-					WC_Stripe_Helper::is_pre_30() ? $order->reduce_order_stock() : wc_reduce_stock_levels( $order_id );
261
+			if ('pending' === $response->status) {
262
+				if ( ! wc_string_to_bool(get_post_meta($order_id, '_order_stock_reduced', true))) {
263
+					WC_Stripe_Helper::is_pre_30() ? $order->reduce_order_stock() : wc_reduce_stock_levels($order_id);
265 264
 				}
266 265
 
267
-				WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, '_transaction_id', $response->id, true ) : $order->set_transaction_id( $response->id );
266
+				WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, '_transaction_id', $response->id, true) : $order->set_transaction_id($response->id);
268 267
 				/* translators: transaction id */
269
-				$order->update_status( 'on-hold', sprintf( __( 'Stripe charge awaiting payment: %s.', 'woocommerce-gateway-stripe' ), $response->id ) );
268
+				$order->update_status('on-hold', sprintf(__('Stripe charge awaiting payment: %s.', 'woocommerce-gateway-stripe'), $response->id));
270 269
 			}
271 270
 
272
-			if ( 'succeeded' === $response->status ) {
273
-				$order->payment_complete( $response->id );
271
+			if ('succeeded' === $response->status) {
272
+				$order->payment_complete($response->id);
274 273
 
275 274
 				/* translators: transaction id */
276
-				$message = sprintf( __( 'Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe' ), $response->id );
277
-				$order->add_order_note( $message );
275
+				$message = sprintf(__('Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe'), $response->id);
276
+				$order->add_order_note($message);
278 277
 			}
279 278
 
280
-			if ( 'failed' === $response->status ) {
281
-				$localized_message = __( 'Payment processing failed. Please retry.', 'woocommerce-gateway-stripe' );
282
-				$order->add_order_note( $localized_message );
283
-				throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message );
279
+			if ('failed' === $response->status) {
280
+				$localized_message = __('Payment processing failed. Please retry.', 'woocommerce-gateway-stripe');
281
+				$order->add_order_note($localized_message);
282
+				throw new WC_Stripe_Exception(print_r($response, true), $localized_message);
284 283
 			}
285 284
 		} else {
286
-			WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, '_transaction_id', $response->id, true ) : $order->set_transaction_id( $response->id );
285
+			WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, '_transaction_id', $response->id, true) : $order->set_transaction_id($response->id);
287 286
 
288
-			if ( $order->has_status( array( 'pending', 'failed' ) ) ) {
289
-				WC_Stripe_Helper::is_pre_30() ? $order->reduce_order_stock() : wc_reduce_stock_levels( $order_id );
287
+			if ($order->has_status(array('pending', 'failed'))) {
288
+				WC_Stripe_Helper::is_pre_30() ? $order->reduce_order_stock() : wc_reduce_stock_levels($order_id);
290 289
 			}
291 290
 
292 291
 			/* translators: transaction id */
293
-			$order->update_status( 'on-hold', sprintf( __( 'Stripe charge authorized (Charge ID: %s). Process order to take payment, or cancel to remove the pre-authorization.', 'woocommerce-gateway-stripe' ), $response->id ) );
292
+			$order->update_status('on-hold', sprintf(__('Stripe charge authorized (Charge ID: %s). Process order to take payment, or cancel to remove the pre-authorization.', 'woocommerce-gateway-stripe'), $response->id));
294 293
 		}
295 294
 
296
-		if ( is_callable( array( $order, 'save' ) ) ) {
295
+		if (is_callable(array($order, 'save'))) {
297 296
 			$order->save();
298 297
 		}
299 298
 
300
-		do_action( 'wc_gateway_stripe_process_response', $response, $order );
299
+		do_action('wc_gateway_stripe_process_response', $response, $order);
301 300
 
302 301
 		return $response;
303 302
 	}
@@ -310,10 +309,10 @@  discard block
 block discarded – undo
310 309
 	 * @param int $order_id
311 310
 	 * @return null
312 311
 	 */
313
-	public function send_failed_order_email( $order_id ) {
312
+	public function send_failed_order_email($order_id) {
314 313
 		$emails = WC()->mailer()->get_emails();
315
-		if ( ! empty( $emails ) && ! empty( $order_id ) ) {
316
-			$emails['WC_Email_Failed_Order']->trigger( $order_id );
314
+		if ( ! empty($emails) && ! empty($order_id)) {
315
+			$emails['WC_Email_Failed_Order']->trigger($order_id);
317 316
 		}
318 317
 	}
319 318
 
@@ -325,7 +324,7 @@  discard block
 block discarded – undo
325 324
 	 * @param object $order
326 325
 	 * @return object $details
327 326
 	 */
328
-	public function get_owner_details( $order ) {
327
+	public function get_owner_details($order) {
329 328
 		$billing_first_name = WC_Stripe_Helper::is_pre_30() ? $order->billing_first_name : $order->get_billing_first_name();
330 329
 		$billing_last_name  = WC_Stripe_Helper::is_pre_30() ? $order->billing_last_name : $order->get_billing_last_name();
331 330
 
@@ -336,8 +335,8 @@  discard block
 block discarded – undo
336 335
 
337 336
 		$phone                             = WC_Stripe_Helper::is_pre_30() ? $order->billing_phone : $order->get_billing_phone();
338 337
 
339
-		if ( ! empty( $phone ) ) {
340
-			$details['phone']              = $phone;
338
+		if ( ! empty($phone)) {
339
+			$details['phone'] = $phone;
341 340
 		}
342 341
 
343 342
 		$details['address']['line1']       = WC_Stripe_Helper::is_pre_30() ? $order->billing_address_1 : $order->get_billing_address_1();
@@ -347,7 +346,7 @@  discard block
 block discarded – undo
347 346
 		$details['address']['postal_code'] = WC_Stripe_Helper::is_pre_30() ? $order->billing_postcode : $order->get_billing_postcode();
348 347
 		$details['address']['country']     = WC_Stripe_Helper::is_pre_30() ? $order->billing_country : $order->get_billing_country();
349 348
 
350
-		return (object) apply_filters( 'wc_stripe_owner_details', $details, $order );
349
+		return (object) apply_filters('wc_stripe_owner_details', $details, $order);
351 350
 	}
352 351
 
353 352
 	/**
@@ -356,16 +355,16 @@  discard block
 block discarded – undo
356 355
 	 * @since 4.0.3
357 356
 	 */
358 357
 	public function create_source_object() {
359
-		$source = ! empty( $_POST['stripe_source'] ) ? wc_clean( $_POST['stripe_source'] ) : '';
358
+		$source = ! empty($_POST['stripe_source']) ? wc_clean($_POST['stripe_source']) : '';
360 359
 		
361
-		if ( empty( $source ) ) {
360
+		if (empty($source)) {
362 361
 			return '';
363 362
 		}
364 363
 
365
-		$source_object = WC_Stripe_API::retrieve( 'sources/' . $source );
364
+		$source_object = WC_Stripe_API::retrieve('sources/' . $source);
366 365
 
367
-		if ( ! empty( $source_object->error ) ) {
368
-			throw new WC_Stripe_Exception( print_r( $source_object, true ), $source_object->error->message );
366
+		if ( ! empty($source_object->error)) {
367
+			throw new WC_Stripe_Exception(print_r($source_object, true), $source_object->error->message);
369 368
 		}
370 369
 
371 370
 		return $source_object;
@@ -385,58 +384,58 @@  discard block
 block discarded – undo
385 384
 	 * @throws Exception When card was not added or for and invalid card.
386 385
 	 * @return object
387 386
 	 */
388
-	public function prepare_source( $source_object = '', $user_id, $force_save_source = false ) {
389
-		$customer           = new WC_Stripe_Customer( $user_id );
387
+	public function prepare_source($source_object = '', $user_id, $force_save_source = false) {
388
+		$customer           = new WC_Stripe_Customer($user_id);
390 389
 		$set_customer       = true;
391
-		$force_save_source  = apply_filters( 'wc_stripe_force_save_source', $force_save_source, $customer );
390
+		$force_save_source  = apply_filters('wc_stripe_force_save_source', $force_save_source, $customer);
392 391
 		$source             = '';
393 392
 		$wc_token_id        = false;
394
-		$payment_method     = isset( $_POST['payment_method'] ) ? wc_clean( $_POST['payment_method'] ) : 'stripe';
393
+		$payment_method     = isset($_POST['payment_method']) ? wc_clean($_POST['payment_method']) : 'stripe';
395 394
 
396 395
 		// New CC info was entered and we have a new source to process.
397
-		if ( ! empty( $source_object ) ) {
396
+		if ( ! empty($source_object)) {
398 397
 			// This gets the source object from Stripe.
399 398
 			$source = $source_object;
400 399
 
401 400
 			// This checks to see if customer opted to save the payment method to file.
402
-			$maybe_saved_card = isset( $_POST[ 'wc-' . $payment_method . '-new-payment-method' ] ) && ! empty( $_POST[ 'wc-' . $payment_method . '-new-payment-method' ] );
401
+			$maybe_saved_card = isset($_POST['wc-' . $payment_method . '-new-payment-method']) && ! empty($_POST['wc-' . $payment_method . '-new-payment-method']);
403 402
 
404 403
 			/**
405 404
 			 * This is true if the user wants to store the card to their account.
406 405
 			 * Criteria to save to file is they are logged in, they opted to save or product requirements and the source is
407 406
 			 * actually reusable. Either that or force_save_source is true.
408 407
 			 */
409
-			if ( ( $user_id && $this->saved_cards && $maybe_saved_card && 'reusable' === $source->usage ) || $force_save_source ) {
410
-				$source = $customer->add_source( $source->id );
408
+			if (($user_id && $this->saved_cards && $maybe_saved_card && 'reusable' === $source->usage) || $force_save_source) {
409
+				$source = $customer->add_source($source->id);
411 410
 
412
-				if ( ! empty( $source->error ) ) {
413
-					throw new WC_Stripe_Exception( print_r( $source, true ), $source->error->message );
411
+				if ( ! empty($source->error)) {
412
+					throw new WC_Stripe_Exception(print_r($source, true), $source->error->message);
414 413
 				}
415 414
 			} else {
416 415
 				$source = $source->id;
417 416
 			}
418
-		} elseif ( isset( $_POST[ 'wc-' . $payment_method . '-payment-token' ] ) && 'new' !== $_POST[ 'wc-' . $payment_method . '-payment-token' ] ) {
417
+		} elseif (isset($_POST['wc-' . $payment_method . '-payment-token']) && 'new' !== $_POST['wc-' . $payment_method . '-payment-token']) {
419 418
 			// Use an existing token, and then process the payment
420 419
 
421
-			$wc_token_id = wc_clean( $_POST[ 'wc-' . $payment_method . '-payment-token' ] );
422
-			$wc_token    = WC_Payment_Tokens::get( $wc_token_id );
420
+			$wc_token_id = wc_clean($_POST['wc-' . $payment_method . '-payment-token']);
421
+			$wc_token    = WC_Payment_Tokens::get($wc_token_id);
423 422
 
424
-			if ( ! $wc_token || $wc_token->get_user_id() !== get_current_user_id() ) {
425
-				WC()->session->set( 'refresh_totals', true );
426
-				throw new WC_Stripe_Exception( 'Invalid payment method', __( 'Invalid payment method. Please input a new card number.', 'woocommerce-gateway-stripe' ) );
423
+			if ( ! $wc_token || $wc_token->get_user_id() !== get_current_user_id()) {
424
+				WC()->session->set('refresh_totals', true);
425
+				throw new WC_Stripe_Exception('Invalid payment method', __('Invalid payment method. Please input a new card number.', 'woocommerce-gateway-stripe'));
427 426
 			}
428 427
 
429 428
 			$source = $wc_token->get_token();
430
-		} elseif ( isset( $_POST['stripe_token'] ) && 'new' !== $_POST['stripe_token'] ) {
431
-			$stripe_token     = wc_clean( $_POST['stripe_token'] );
432
-			$maybe_saved_card = isset( $_POST[ 'wc-' . $payment_method . '-new-payment-method' ] ) && ! empty( $_POST[ 'wc-' . $payment_method . '-new-payment-method' ] );
429
+		} elseif (isset($_POST['stripe_token']) && 'new' !== $_POST['stripe_token']) {
430
+			$stripe_token     = wc_clean($_POST['stripe_token']);
431
+			$maybe_saved_card = isset($_POST['wc-' . $payment_method . '-new-payment-method']) && ! empty($_POST['wc-' . $payment_method . '-new-payment-method']);
433 432
 
434 433
 			// This is true if the user wants to store the card to their account.
435
-			if ( ( $user_id && $this->saved_cards && $maybe_saved_card ) || $force_save_source ) {
436
-				$source = $customer->add_source( $stripe_token );
434
+			if (($user_id && $this->saved_cards && $maybe_saved_card) || $force_save_source) {
435
+				$source = $customer->add_source($stripe_token);
437 436
 
438
-				if ( ! empty( $source->error ) ) {
439
-					throw new WC_Stripe_Exception( print_r( $source, true ), $source->error->message );
437
+				if ( ! empty($source->error)) {
438
+					throw new WC_Stripe_Exception(print_r($source, true), $source->error->message);
440 439
 				}
441 440
 			} else {
442 441
 				$set_customer = false;
@@ -444,7 +443,7 @@  discard block
 block discarded – undo
444 443
 			}
445 444
 		}
446 445
 
447
-		if ( ! $set_customer ) {
446
+		if ( ! $set_customer) {
448 447
 			$customer_id = false;
449 448
 		} else {
450 449
 			$customer_id = $customer->get_id() ? $customer->get_id() : false;
@@ -465,27 +464,27 @@  discard block
 block discarded – undo
465 464
 	 * @param WC_Order $order For to which the source applies.
466 465
 	 * @param stdClass $source Source information.
467 466
 	 */
468
-	public function save_source( $order, $source ) {
467
+	public function save_source($order, $source) {
469 468
 		$order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
470 469
 
471 470
 		// Store source in the order.
472
-		if ( $source->customer ) {
473
-			if ( WC_Stripe_Helper::is_pre_30() ) {
474
-				update_post_meta( $order_id, '_stripe_customer_id', $source->customer );
471
+		if ($source->customer) {
472
+			if (WC_Stripe_Helper::is_pre_30()) {
473
+				update_post_meta($order_id, '_stripe_customer_id', $source->customer);
475 474
 			} else {
476
-				$order->update_meta_data( '_stripe_customer_id', $source->customer );
475
+				$order->update_meta_data('_stripe_customer_id', $source->customer);
477 476
 			}
478 477
 		}
479 478
 
480
-		if ( $source->source ) {
481
-			if ( WC_Stripe_Helper::is_pre_30() ) {
482
-				update_post_meta( $order_id, '_stripe_source_id', $source->source );
479
+		if ($source->source) {
480
+			if (WC_Stripe_Helper::is_pre_30()) {
481
+				update_post_meta($order_id, '_stripe_source_id', $source->source);
483 482
 			} else {
484
-				$order->update_meta_data( '_stripe_source_id', $source->source );
483
+				$order->update_meta_data('_stripe_source_id', $source->source);
485 484
 			}
486 485
 		}
487 486
 
488
-		if ( is_callable( array( $order, 'save' ) ) ) {
487
+		if (is_callable(array($order, 'save'))) {
489 488
 			$order->save();
490 489
 		}
491 490
 	}
@@ -503,35 +502,35 @@  discard block
 block discarded – undo
503 502
 	 * @param object $order
504 503
 	 * @return object
505 504
 	 */
506
-	public function prepare_order_source( $order = null ) {
505
+	public function prepare_order_source($order = null) {
507 506
 		$stripe_customer = new WC_Stripe_Customer();
508 507
 		$stripe_source   = false;
509 508
 		$token_id        = false;
510 509
 
511
-		if ( $order ) {
510
+		if ($order) {
512 511
 			$order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
513 512
 
514
-			$stripe_customer_id = get_post_meta( $order_id, '_stripe_customer_id', true );
513
+			$stripe_customer_id = get_post_meta($order_id, '_stripe_customer_id', true);
515 514
 
516
-			if ( $stripe_customer_id ) {
517
-				$stripe_customer->set_id( $stripe_customer_id );
515
+			if ($stripe_customer_id) {
516
+				$stripe_customer->set_id($stripe_customer_id);
518 517
 			}
519 518
 
520
-			$source_id = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_stripe_source_id', true ) : $order->get_meta( '_stripe_source_id', true );
519
+			$source_id = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_stripe_source_id', true) : $order->get_meta('_stripe_source_id', true);
521 520
 
522 521
 			// Since 4.0.0, we changed card to source so we need to account for that.
523
-			if ( empty( $source_id ) ) {
524
-				$source_id = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_stripe_card_id', true ) : $order->get_meta( '_stripe_card_id', true );
522
+			if (empty($source_id)) {
523
+				$source_id = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_stripe_card_id', true) : $order->get_meta('_stripe_card_id', true);
525 524
 
526 525
 				// Take this opportunity to update the key name.
527
-				WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, '_stripe_source_id', $source_id ) : $order->update_meta_data( '_stripe_source_id', $source_id );
526
+				WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, '_stripe_source_id', $source_id) : $order->update_meta_data('_stripe_source_id', $source_id);
528 527
 
529
-				if ( is_callable( array( $order, 'save' ) ) ) {
528
+				if (is_callable(array($order, 'save'))) {
530 529
 					$order->save();
531 530
 				}
532 531
 			}
533 532
 
534
-			if ( $source_id ) {
533
+			if ($source_id) {
535 534
 				$stripe_source = $source_id;
536 535
 			}
537 536
 		}
@@ -552,27 +551,27 @@  discard block
 block discarded – undo
552 551
 	 * @param object $order The order object
553 552
 	 * @param int $balance_transaction_id
554 553
 	 */
555
-	public function update_fees( $order, $balance_transaction_id ) {
554
+	public function update_fees($order, $balance_transaction_id) {
556 555
 		$order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
557 556
 
558
-		$balance_transaction = WC_Stripe_API::retrieve( 'balance/history/' . $balance_transaction_id );
557
+		$balance_transaction = WC_Stripe_API::retrieve('balance/history/' . $balance_transaction_id);
559 558
 
560
-		if ( empty( $balance_transaction->error ) ) {
561
-			if ( isset( $balance_transaction ) && isset( $balance_transaction->fee ) ) {
559
+		if (empty($balance_transaction->error)) {
560
+			if (isset($balance_transaction) && isset($balance_transaction->fee)) {
562 561
 				// Fees and Net needs to both come from Stripe to be accurate as the returned
563 562
 				// values are in the local currency of the Stripe account, not from WC.
564
-				$fee = ! empty( $balance_transaction->fee ) ? WC_Stripe_Helper::format_balance_fee( $balance_transaction, 'fee' ) : 0;
565
-				$net = ! empty( $balance_transaction->net ) ? WC_Stripe_Helper::format_balance_fee( $balance_transaction, 'net' ) : 0;
563
+				$fee = ! empty($balance_transaction->fee) ? WC_Stripe_Helper::format_balance_fee($balance_transaction, 'fee') : 0;
564
+				$net = ! empty($balance_transaction->net) ? WC_Stripe_Helper::format_balance_fee($balance_transaction, 'net') : 0;
566 565
 
567
-				WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, self::META_NAME_FEE, $fee ) : $order->update_meta_data( self::META_NAME_FEE, $fee );
568
-				WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, self::META_NAME_NET, $net ) : $order->update_meta_data( self::META_NAME_NET, $net );
566
+				WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, self::META_NAME_FEE, $fee) : $order->update_meta_data(self::META_NAME_FEE, $fee);
567
+				WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, self::META_NAME_NET, $net) : $order->update_meta_data(self::META_NAME_NET, $net);
569 568
 
570
-				if ( is_callable( array( $order, 'save' ) ) ) {
569
+				if (is_callable(array($order, 'save'))) {
571 570
 					$order->save();
572 571
 				}
573 572
 			}
574 573
 		} else {
575
-			WC_Stripe_Logger::log( "Unable to update fees/net meta for order: {$order_id}" );
574
+			WC_Stripe_Logger::log("Unable to update fees/net meta for order: {$order_id}");
576 575
 		}
577 576
 	}
578 577
 
@@ -585,57 +584,57 @@  discard block
 block discarded – undo
585 584
 	 * @param  float $amount
586 585
 	 * @return bool
587 586
 	 */
588
-	public function process_refund( $order_id, $amount = null, $reason = '' ) {
589
-		$order = wc_get_order( $order_id );
587
+	public function process_refund($order_id, $amount = null, $reason = '') {
588
+		$order = wc_get_order($order_id);
590 589
 
591
-		if ( ! $order || ! $order->get_transaction_id() ) {
590
+		if ( ! $order || ! $order->get_transaction_id()) {
592 591
 			return false;
593 592
 		}
594 593
 
595 594
 		$body = array();
596 595
 
597
-		if ( WC_Stripe_Helper::is_pre_30() ) {
598
-			$order_currency = get_post_meta( $order_id, '_order_currency', true );
596
+		if (WC_Stripe_Helper::is_pre_30()) {
597
+			$order_currency = get_post_meta($order_id, '_order_currency', true);
599 598
 		} else {
600 599
 			$order_currency = $order->get_currency();
601 600
 		}
602 601
 
603
-		if ( ! is_null( $amount ) ) {
604
-			$body['amount'] = WC_Stripe_Helper::get_stripe_amount( $amount, $order_currency );
602
+		if ( ! is_null($amount)) {
603
+			$body['amount'] = WC_Stripe_Helper::get_stripe_amount($amount, $order_currency);
605 604
 		}
606 605
 
607
-		if ( $reason ) {
606
+		if ($reason) {
608 607
 			$body['metadata'] = array(
609 608
 				'reason' => $reason,
610 609
 			);
611 610
 		}
612 611
 
613
-		WC_Stripe_Logger::log( "Info: Beginning refund for order {$order->get_transaction_id()} for the amount of {$amount}" );
612
+		WC_Stripe_Logger::log("Info: Beginning refund for order {$order->get_transaction_id()} for the amount of {$amount}");
614 613
 
615
-		$response = WC_Stripe_API::request( $body, 'charges/' . $order->get_transaction_id() . '/refunds' );
614
+		$response = WC_Stripe_API::request($body, 'charges/' . $order->get_transaction_id() . '/refunds');
616 615
 
617
-		if ( ! empty( $response->error ) ) {
618
-			WC_Stripe_Logger::log( 'Error: ' . $response->error->message );
616
+		if ( ! empty($response->error)) {
617
+			WC_Stripe_Logger::log('Error: ' . $response->error->message);
619 618
 
620 619
 			return $response;
621 620
 
622
-		} elseif ( ! empty( $response->id ) ) {
623
-			WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, '_stripe_refund_id', $response->id ) : $order->update_meta_data( '_stripe_refund_id', $response->id );
621
+		} elseif ( ! empty($response->id)) {
622
+			WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, '_stripe_refund_id', $response->id) : $order->update_meta_data('_stripe_refund_id', $response->id);
624 623
 
625
-			$amount = wc_price( $response->amount / 100 );
624
+			$amount = wc_price($response->amount / 100);
626 625
 
627
-			if ( in_array( strtolower( $order->get_currency() ), WC_Stripe_Helper::no_decimal_currencies() ) ) {
628
-				$amount = wc_price( $response->amount );
626
+			if (in_array(strtolower($order->get_currency()), WC_Stripe_Helper::no_decimal_currencies())) {
627
+				$amount = wc_price($response->amount);
629 628
 			}
630 629
 
631
-			if ( isset( $response->balance_transaction ) ) {
632
-				$this->update_fees( $order, $response->balance_transaction );
630
+			if (isset($response->balance_transaction)) {
631
+				$this->update_fees($order, $response->balance_transaction);
633 632
 			}
634 633
 
635 634
 			/* translators: 1) dollar amount 2) transaction id 3) refund message */
636
-			$refund_message = sprintf( __( 'Refunded %1$s - Refund ID: %2$s - Reason: %3$s', 'woocommerce-gateway-stripe' ), $amount, $response->id, $reason );
637
-			$order->add_order_note( $refund_message );
638
-			WC_Stripe_Logger::log( 'Success: ' . html_entity_decode( strip_tags( $refund_message ) ) );
635
+			$refund_message = sprintf(__('Refunded %1$s - Refund ID: %2$s - Reason: %3$s', 'woocommerce-gateway-stripe'), $amount, $response->id, $reason);
636
+			$order->add_order_note($refund_message);
637
+			WC_Stripe_Logger::log('Success: ' . html_entity_decode(strip_tags($refund_message)));
639 638
 
640 639
 			return true;
641 640
 		}
@@ -650,44 +649,44 @@  discard block
 block discarded – undo
650 649
 	 */
651 650
 	public function add_payment_method() {
652 651
 		$error     = false;
653
-		$error_msg = __( 'There was a problem adding the card.', 'woocommerce-gateway-stripe' );
652
+		$error_msg = __('There was a problem adding the card.', 'woocommerce-gateway-stripe');
654 653
 		$source_id = '';
655 654
 
656
-		if ( empty( $_POST['stripe_source'] ) && empty( $_POST['stripe_token'] ) || ! is_user_logged_in() ) {
655
+		if (empty($_POST['stripe_source']) && empty($_POST['stripe_token']) || ! is_user_logged_in()) {
657 656
 			$error = true;
658 657
 		}
659 658
 
660
-		$stripe_customer = new WC_Stripe_Customer( get_current_user_id() );
659
+		$stripe_customer = new WC_Stripe_Customer(get_current_user_id());
661 660
 
662
-		$source = ! empty( $_POST['stripe_source'] ) ? wc_clean( $_POST['stripe_source'] ) : '';
661
+		$source = ! empty($_POST['stripe_source']) ? wc_clean($_POST['stripe_source']) : '';
663 662
 
664
-		$source_object = WC_Stripe_API::retrieve( 'sources/' . $source );
663
+		$source_object = WC_Stripe_API::retrieve('sources/' . $source);
665 664
 
666
-		if ( isset( $source_object ) ) {
667
-			if ( ! empty( $source_object->error ) ) {
665
+		if (isset($source_object)) {
666
+			if ( ! empty($source_object->error)) {
668 667
 				$error = true;
669 668
 			}
670 669
 
671 670
 			$source_id = $source_object->id;
672
-		} elseif ( isset( $_POST['stripe_token'] ) ) {
673
-			$source_id = wc_clean( $_POST['stripe_token'] );
671
+		} elseif (isset($_POST['stripe_token'])) {
672
+			$source_id = wc_clean($_POST['stripe_token']);
674 673
 		}
675 674
 
676
-		$response = $stripe_customer->add_source( $source_id );
675
+		$response = $stripe_customer->add_source($source_id);
677 676
 
678
-		if ( ! $response || is_wp_error( $response ) || ! empty( $response->error ) ) {
677
+		if ( ! $response || is_wp_error($response) || ! empty($response->error)) {
679 678
 			$error = true;
680 679
 		}
681 680
 
682
-		if ( $error ) {
683
-			wc_add_notice( $error_msg, 'error' );
684
-			WC_Stripe_Logger::log( 'Add payment method Error: ' . $error_msg );
681
+		if ($error) {
682
+			wc_add_notice($error_msg, 'error');
683
+			WC_Stripe_Logger::log('Add payment method Error: ' . $error_msg);
685 684
 			return;
686 685
 		}
687 686
 
688 687
 		return array(
689 688
 			'result'   => 'success',
690
-			'redirect' => wc_get_endpoint_url( 'payment-methods' ),
689
+			'redirect' => wc_get_endpoint_url('payment-methods'),
691 690
 		);
692 691
 	}
693 692
 }
Please login to merge, or discard this patch.
includes/class-wc-gateway-stripe.php 1 patch
Spacing   +203 added lines, -203 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) {
2
+if ( ! defined('ABSPATH')) {
3 3
 	exit;
4 4
 }
5 5
 
@@ -119,9 +119,9 @@  discard block
 block discarded – undo
119 119
 	 */
120 120
 	public function __construct() {
121 121
 		$this->id                   = 'stripe';
122
-		$this->method_title         = __( 'Stripe', 'woocommerce-gateway-stripe' );
122
+		$this->method_title         = __('Stripe', 'woocommerce-gateway-stripe');
123 123
 		/* translators: 1) link to Stripe register page 2) link to Stripe api keys page */
124
-		$this->method_description   = sprintf( __( 'Stripe works by adding payment fields on the checkout and then sending the details to Stripe for verification. <a href="%1$s" target="_blank">Sign up</a> for a Stripe account, and <a href="%2$s" target="_blank">get your Stripe account keys</a>.', 'woocommerce-gateway-stripe' ), 'https://dashboard.stripe.com/register', 'https://dashboard.stripe.com/account/apikeys' );
124
+		$this->method_description   = sprintf(__('Stripe works by adding payment fields on the checkout and then sending the details to Stripe for verification. <a href="%1$s" target="_blank">Sign up</a> for a Stripe account, and <a href="%2$s" target="_blank">get your Stripe account keys</a>.', 'woocommerce-gateway-stripe'), 'https://dashboard.stripe.com/register', 'https://dashboard.stripe.com/account/apikeys');
125 125
 		$this->has_fields           = true;
126 126
 		$this->supports             = array(
127 127
 			'products',
@@ -148,38 +148,38 @@  discard block
 block discarded – undo
148 148
 		$this->init_settings();
149 149
 
150 150
 		// Get setting values.
151
-		$this->title                   = $this->get_option( 'title' );
152
-		$this->description             = $this->get_option( 'description' );
153
-		$this->enabled                 = $this->get_option( 'enabled' );
154
-		$this->testmode                = 'yes' === $this->get_option( 'testmode' );
155
-		$this->inline_cc_form          = 'yes' === $this->get_option( 'inline_cc_form' );
156
-		$this->capture                 = 'yes' === $this->get_option( 'capture', 'yes' );
157
-		$this->statement_descriptor    = WC_Stripe_Helper::clean_statement_descriptor( $this->get_option( 'statement_descriptor' ) );
158
-		$this->three_d_secure          = 'yes' === $this->get_option( 'three_d_secure' );
159
-		$this->stripe_checkout         = 'yes' === $this->get_option( 'stripe_checkout' );
160
-		$this->stripe_checkout_locale  = $this->get_option( 'stripe_checkout_locale' );
161
-		$this->stripe_checkout_image   = $this->get_option( 'stripe_checkout_image', '' );
162
-		$this->saved_cards             = 'yes' === $this->get_option( 'saved_cards' );
163
-		$this->secret_key              = $this->testmode ? $this->get_option( 'test_secret_key' ) : $this->get_option( 'secret_key' );
164
-		$this->publishable_key         = $this->testmode ? $this->get_option( 'test_publishable_key' ) : $this->get_option( 'publishable_key' );
165
-		$this->bitcoin                 = 'USD' === strtoupper( get_woocommerce_currency() ) && 'yes' === $this->get_option( 'stripe_bitcoin' );
166
-		$this->payment_request         = 'yes' === $this->get_option( 'payment_request', 'yes' );
167
-		$this->apple_pay_domain_set    = 'yes' === $this->get_option( 'apple_pay_domain_set', 'no' );
151
+		$this->title                   = $this->get_option('title');
152
+		$this->description             = $this->get_option('description');
153
+		$this->enabled                 = $this->get_option('enabled');
154
+		$this->testmode                = 'yes' === $this->get_option('testmode');
155
+		$this->inline_cc_form          = 'yes' === $this->get_option('inline_cc_form');
156
+		$this->capture                 = 'yes' === $this->get_option('capture', 'yes');
157
+		$this->statement_descriptor    = WC_Stripe_Helper::clean_statement_descriptor($this->get_option('statement_descriptor'));
158
+		$this->three_d_secure          = 'yes' === $this->get_option('three_d_secure');
159
+		$this->stripe_checkout         = 'yes' === $this->get_option('stripe_checkout');
160
+		$this->stripe_checkout_locale  = $this->get_option('stripe_checkout_locale');
161
+		$this->stripe_checkout_image   = $this->get_option('stripe_checkout_image', '');
162
+		$this->saved_cards             = 'yes' === $this->get_option('saved_cards');
163
+		$this->secret_key              = $this->testmode ? $this->get_option('test_secret_key') : $this->get_option('secret_key');
164
+		$this->publishable_key         = $this->testmode ? $this->get_option('test_publishable_key') : $this->get_option('publishable_key');
165
+		$this->bitcoin                 = 'USD' === strtoupper(get_woocommerce_currency()) && 'yes' === $this->get_option('stripe_bitcoin');
166
+		$this->payment_request         = 'yes' === $this->get_option('payment_request', 'yes');
167
+		$this->apple_pay_domain_set    = 'yes' === $this->get_option('apple_pay_domain_set', 'no');
168 168
 		$this->apple_pay_verify_notice = '';
169 169
 
170
-		if ( $this->stripe_checkout ) {
171
-			$this->order_button_text = __( 'Continue to payment', 'woocommerce-gateway-stripe' );
170
+		if ($this->stripe_checkout) {
171
+			$this->order_button_text = __('Continue to payment', 'woocommerce-gateway-stripe');
172 172
 		}
173 173
 
174
-		WC_Stripe_API::set_secret_key( $this->secret_key );
174
+		WC_Stripe_API::set_secret_key($this->secret_key);
175 175
 
176 176
 		$this->init_apple_pay();
177 177
 
178 178
 		// Hooks.
179
-		add_action( 'wp_enqueue_scripts', array( $this, 'payment_scripts' ) );
180
-		add_action( 'admin_enqueue_scripts', array( $this, 'admin_scripts' ) );
181
-		add_action( 'admin_notices', array( $this, 'admin_notices' ) );
182
-		add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) );
179
+		add_action('wp_enqueue_scripts', array($this, 'payment_scripts'));
180
+		add_action('admin_enqueue_scripts', array($this, 'admin_scripts'));
181
+		add_action('admin_notices', array($this, 'admin_notices'));
182
+		add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options'));
183 183
 	}
184 184
 
185 185
 	/**
@@ -188,7 +188,7 @@  discard block
 block discarded – undo
188 188
 	 * @since 4.0.2
189 189
 	 */
190 190
 	public function is_available() {
191
-		if ( is_add_payment_method_page() && ! $this->saved_cards ) {
191
+		if (is_add_payment_method_page() && ! $this->saved_cards) {
192 192
 			return false;
193 193
 		}
194 194
 
@@ -211,17 +211,17 @@  discard block
 block discarded – undo
211 211
 		$icons_str .= $icons['amex'];
212 212
 		$icons_str .= $icons['mastercard'];
213 213
 
214
-		if ( 'USD' === get_woocommerce_currency() ) {
214
+		if ('USD' === get_woocommerce_currency()) {
215 215
 			$icons_str .= $icons['discover'];
216 216
 			$icons_str .= $icons['jcb'];
217 217
 			$icons_str .= $icons['diners'];
218 218
 		}
219 219
 
220
-		if ( $this->bitcoin && $this->stripe_checkout ) {
220
+		if ($this->bitcoin && $this->stripe_checkout) {
221 221
 			$icons_str .= $icons['bitcoin'];
222 222
 		}
223 223
 
224
-		return apply_filters( 'woocommerce_gateway_icon', $icons_str, $this->id );
224
+		return apply_filters('woocommerce_gateway_icon', $icons_str, $this->id);
225 225
 	}
226 226
 
227 227
 	/**
@@ -233,9 +233,9 @@  discard block
 block discarded – undo
233 233
 	public function init_apple_pay() {
234 234
 		if (
235 235
 			is_admin() &&
236
-			isset( $_GET['page'] ) && 'wc-settings' === $_GET['page'] &&
237
-			isset( $_GET['tab'] ) && 'checkout' === $_GET['tab'] &&
238
-			isset( $_GET['section'] ) && 'stripe' === $_GET['section'] &&
236
+			isset($_GET['page']) && 'wc-settings' === $_GET['page'] &&
237
+			isset($_GET['tab']) && 'checkout' === $_GET['tab'] &&
238
+			isset($_GET['section']) && 'stripe' === $_GET['section'] &&
239 239
 			$this->payment_request
240 240
 		) {
241 241
 			$this->process_apple_pay_verification();
@@ -249,9 +249,9 @@  discard block
 block discarded – undo
249 249
 	 * @version 3.1.0
250 250
 	 * @param string $secret_key
251 251
 	 */
252
-	private function register_apple_pay_domain( $secret_key = '' ) {
253
-		if ( empty( $secret_key ) ) {
254
-			throw new Exception( __( 'Unable to verify domain - missing secret key.', 'woocommerce-gateway-stripe' ) );
252
+	private function register_apple_pay_domain($secret_key = '') {
253
+		if (empty($secret_key)) {
254
+			throw new Exception(__('Unable to verify domain - missing secret key.', 'woocommerce-gateway-stripe'));
255 255
 		}
256 256
 
257 257
 		$endpoint = 'https://api.stripe.com/v1/apple_pay/domains';
@@ -265,23 +265,23 @@  discard block
 block discarded – undo
265 265
 			'Authorization' => 'Bearer ' . $secret_key,
266 266
 		);
267 267
 
268
-		$response = wp_remote_post( $endpoint, array(
268
+		$response = wp_remote_post($endpoint, array(
269 269
 			'headers' => $headers,
270
-			'body'    => http_build_query( $data ),
271
-		) );
270
+			'body'    => http_build_query($data),
271
+		));
272 272
 
273
-		if ( is_wp_error( $response ) ) {
273
+		if (is_wp_error($response)) {
274 274
 			/* translators: error message */
275
-			throw new Exception( sprintf( __( 'Unable to verify domain - %s', 'woocommerce-gateway-stripe' ), $response->get_error_message() ) );
275
+			throw new Exception(sprintf(__('Unable to verify domain - %s', 'woocommerce-gateway-stripe'), $response->get_error_message()));
276 276
 		}
277 277
 
278
-		if ( 200 !== $response['response']['code'] ) {
279
-			$parsed_response = json_decode( $response['body'] );
278
+		if (200 !== $response['response']['code']) {
279
+			$parsed_response = json_decode($response['body']);
280 280
 
281 281
 			$this->apple_pay_verify_notice = $parsed_response->error->message;
282 282
 
283 283
 			/* translators: error message */
284
-			throw new Exception( sprintf( __( 'Unable to verify domain - %s', 'woocommerce-gateway-stripe' ), $parsed_response->error->message ) );
284
+			throw new Exception(sprintf(__('Unable to verify domain - %s', 'woocommerce-gateway-stripe'), $parsed_response->error->message));
285 285
 		}
286 286
 	}
287 287
 
@@ -292,48 +292,48 @@  discard block
 block discarded – undo
292 292
 	 * @version 3.1.0
293 293
 	 */
294 294
 	public function process_apple_pay_verification() {
295
-		$gateway_settings = get_option( 'woocommerce_stripe_settings', array() );
295
+		$gateway_settings = get_option('woocommerce_stripe_settings', array());
296 296
 
297 297
 		try {
298
-			$path     = untrailingslashit( $_SERVER['DOCUMENT_ROOT'] );
298
+			$path     = untrailingslashit($_SERVER['DOCUMENT_ROOT']);
299 299
 			$dir      = '.well-known';
300 300
 			$file     = 'apple-developer-merchantid-domain-association';
301 301
 			$fullpath = $path . '/' . $dir . '/' . $file;
302 302
 
303
-			if ( ! empty( $gateway_settings['apple_pay_domain_set'] ) && 'yes' === $gateway_settings['apple_pay_domain_set'] && file_exists( $fullpath ) ) {
303
+			if ( ! empty($gateway_settings['apple_pay_domain_set']) && 'yes' === $gateway_settings['apple_pay_domain_set'] && file_exists($fullpath)) {
304 304
 				return;
305 305
 			}
306 306
 
307
-			if ( ! file_exists( $path . '/' . $dir ) ) {
308
-				if ( ! @mkdir( $path . '/' . $dir, 0755 ) ) {
309
-					throw new Exception( __( 'Unable to create domain association folder to domain root.', 'woocommerce-gateway-stripe' ) );
307
+			if ( ! file_exists($path . '/' . $dir)) {
308
+				if ( ! @mkdir($path . '/' . $dir, 0755)) {
309
+					throw new Exception(__('Unable to create domain association folder to domain root.', 'woocommerce-gateway-stripe'));
310 310
 				}
311 311
 			}
312 312
 
313
-			if ( ! file_exists( $fullpath ) ) {
314
-				if ( ! @copy( WC_STRIPE_PLUGIN_PATH . '/' . $file, $fullpath ) ) {
315
-					throw new Exception( __( 'Unable to copy domain association file to domain root.', 'woocommerce-gateway-stripe' ) );
313
+			if ( ! file_exists($fullpath)) {
314
+				if ( ! @copy(WC_STRIPE_PLUGIN_PATH . '/' . $file, $fullpath)) {
315
+					throw new Exception(__('Unable to copy domain association file to domain root.', 'woocommerce-gateway-stripe'));
316 316
 				}
317 317
 			}
318 318
 
319 319
 			// At this point then the domain association folder and file should be available.
320 320
 			// Proceed to verify/and or verify again.
321
-			$this->register_apple_pay_domain( $this->secret_key );
321
+			$this->register_apple_pay_domain($this->secret_key);
322 322
 
323 323
 			// No errors to this point, verification success!
324 324
 			$gateway_settings['apple_pay_domain_set'] = 'yes';
325 325
 			$this->apple_pay_domain_set = true;
326 326
 
327
-			update_option( 'woocommerce_stripe_settings', $gateway_settings );
327
+			update_option('woocommerce_stripe_settings', $gateway_settings);
328 328
 
329
-			WC_Stripe_Logger::log( 'Your domain has been verified with Apple Pay!' );
329
+			WC_Stripe_Logger::log('Your domain has been verified with Apple Pay!');
330 330
 
331
-		} catch ( Exception $e ) {
331
+		} catch (Exception $e) {
332 332
 			$gateway_settings['apple_pay_domain_set'] = 'no';
333 333
 
334
-			update_option( 'woocommerce_stripe_settings', $gateway_settings );
334
+			update_option('woocommerce_stripe_settings', $gateway_settings);
335 335
 
336
-			WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() );
336
+			WC_Stripe_Logger::log('Error: ' . $e->getMessage());
337 337
 		}
338 338
 	}
339 339
 
@@ -341,11 +341,11 @@  discard block
 block discarded – undo
341 341
 	 * Check if SSL is enabled and notify the user
342 342
 	 */
343 343
 	public function admin_notices() {
344
-		if ( 'no' === $this->enabled ) {
344
+		if ('no' === $this->enabled) {
345 345
 			return;
346 346
 		}
347 347
 
348
-		if ( $this->payment_request && ! empty( $this->apple_pay_verify_notice ) ) {
348
+		if ($this->payment_request && ! empty($this->apple_pay_verify_notice)) {
349 349
 			$allowed_html = array(
350 350
 				'a' => array(
351 351
 					'href' => array(),
@@ -353,7 +353,7 @@  discard block
 block discarded – undo
353 353
 				),
354 354
 			);
355 355
 
356
-			echo '<div class="error stripe-apple-pay-message"><p>' . wp_kses( make_clickable( $this->apple_pay_verify_notice ), $allowed_html ) . '</p></div>';
356
+			echo '<div class="error stripe-apple-pay-message"><p>' . wp_kses(make_clickable($this->apple_pay_verify_notice), $allowed_html) . '</p></div>';
357 357
 		}
358 358
 
359 359
 		/**
@@ -361,9 +361,9 @@  discard block
 block discarded – undo
361 361
 		 * when setting screen is displayed. So if domain verification is not set,
362 362
 		 * something went wrong so lets notify user.
363 363
 		 */
364
-		if ( ! empty( $this->secret_key ) && $this->payment_request && ! $this->apple_pay_domain_set ) {
364
+		if ( ! empty($this->secret_key) && $this->payment_request && ! $this->apple_pay_domain_set) {
365 365
 			/* translators: 1) HTML anchor open tag 2) HTML anchor closing tag */
366
-			echo '<div class="error stripe-apple-pay-message"><p>' . sprintf( __( 'Apple Pay domain verification failed. Please check the %1$slog%2$s to see the issue. (Logging must be enabled to see recorded logs)', 'woocommerce-gateway-stripe' ), '<a href="' . admin_url( 'admin.php?page=wc-status&tab=logs' ) . '">', '</a>' ) . '</p></div>';
366
+			echo '<div class="error stripe-apple-pay-message"><p>' . sprintf(__('Apple Pay domain verification failed. Please check the %1$slog%2$s to see the issue. (Logging must be enabled to see recorded logs)', 'woocommerce-gateway-stripe'), '<a href="' . admin_url('admin.php?page=wc-status&tab=logs') . '">', '</a>') . '</p></div>';
367 367
 		}
368 368
 	}
369 369
 
@@ -371,7 +371,7 @@  discard block
 block discarded – undo
371 371
 	 * Initialise Gateway Settings Form Fields
372 372
 	 */
373 373
 	public function init_form_fields() {
374
-		$this->form_fields = require( dirname( __FILE__ ) . '/admin/stripe-settings.php' );
374
+		$this->form_fields = require(dirname(__FILE__) . '/admin/stripe-settings.php');
375 375
 	}
376 376
 
377 377
 	/**
@@ -379,59 +379,59 @@  discard block
 block discarded – undo
379 379
 	 */
380 380
 	public function payment_fields() {
381 381
 		$user                 = wp_get_current_user();
382
-		$display_tokenization = $this->supports( 'tokenization' ) && is_checkout() && $this->saved_cards;
382
+		$display_tokenization = $this->supports('tokenization') && is_checkout() && $this->saved_cards;
383 383
 		$total                = WC()->cart->total;
384 384
 		$user_email           = '';
385 385
 
386 386
 		// If paying from order, we need to get total from order not cart.
387
-		if ( isset( $_GET['pay_for_order'] ) && ! empty( $_GET['key'] ) ) {
388
-			$order      = wc_get_order( wc_get_order_id_by_order_key( wc_clean( $_GET['key'] ) ) );
387
+		if (isset($_GET['pay_for_order']) && ! empty($_GET['key'])) {
388
+			$order      = wc_get_order(wc_get_order_id_by_order_key(wc_clean($_GET['key'])));
389 389
 			$total      = $order->get_total();
390 390
 			$user_email = WC_Stripe_Helper::is_pre_30() ? $order->billing_email : $order->get_billing_email();
391 391
 		} else {
392
-			if ( $user->ID ) {
393
-				$user_email = get_user_meta( $user->ID, 'billing_email', true );
392
+			if ($user->ID) {
393
+				$user_email = get_user_meta($user->ID, 'billing_email', true);
394 394
 				$user_email = $user_email ? $user_email : $user->user_email;
395 395
 			}
396 396
 		}
397 397
 
398
-		if ( is_add_payment_method_page() ) {
399
-			$pay_button_text = __( 'Add Card', 'woocommerce-gateway-stripe' );
400
-			$total        = '';
398
+		if (is_add_payment_method_page()) {
399
+			$pay_button_text = __('Add Card', 'woocommerce-gateway-stripe');
400
+			$total = '';
401 401
 		} else {
402 402
 			$pay_button_text = '';
403 403
 		}
404 404
 
405 405
 		echo '<div
406 406
 			id="stripe-payment-data"
407
-			data-panel-label="' . esc_attr( $pay_button_text ) . '"
407
+			data-panel-label="' . esc_attr($pay_button_text) . '"
408 408
 			data-description=""
409
-			data-email="' . esc_attr( $user_email ) . '"
410
-			data-amount="' . esc_attr( WC_Stripe_Helper::get_stripe_amount( $total ) ) . '"
411
-			data-name="' . esc_attr( $this->statement_descriptor ) . '"
412
-			data-currency="' . esc_attr( strtolower( get_woocommerce_currency() ) ) . '"
413
-			data-image="' . esc_attr( $this->stripe_checkout_image ) . '"
414
-			data-bitcoin="' . esc_attr( ( $this->bitcoin && $this->capture ) ? 'true' : 'false' ) . '"
415
-			data-locale="' . esc_attr( $this->stripe_checkout_locale ? $this->stripe_checkout_locale : 'en' ) . '"
416
-			data-three-d-secure="' . esc_attr( $this->three_d_secure ? 'true' : 'false' ) . '"
417
-			data-allow-remember-me="' . esc_attr( $this->saved_cards ? 'true' : 'false' ) . '">';
418
-
419
-		if ( $this->description ) {
420
-			if ( $this->testmode ) {
409
+			data-email="' . esc_attr($user_email) . '"
410
+			data-amount="' . esc_attr(WC_Stripe_Helper::get_stripe_amount($total)) . '"
411
+			data-name="' . esc_attr($this->statement_descriptor) . '"
412
+			data-currency="' . esc_attr(strtolower(get_woocommerce_currency())) . '"
413
+			data-image="' . esc_attr($this->stripe_checkout_image) . '"
414
+			data-bitcoin="' . esc_attr(($this->bitcoin && $this->capture) ? 'true' : 'false') . '"
415
+			data-locale="' . esc_attr($this->stripe_checkout_locale ? $this->stripe_checkout_locale : 'en') . '"
416
+			data-three-d-secure="' . esc_attr($this->three_d_secure ? 'true' : 'false') . '"
417
+			data-allow-remember-me="' . esc_attr($this->saved_cards ? 'true' : 'false') . '">';
418
+
419
+		if ($this->description) {
420
+			if ($this->testmode) {
421 421
 				/* translators: link to Stripe testing page */
422
-				$this->description .= ' ' . sprintf( __( 'TEST MODE ENABLED. In test mode, you can use the card number 4242424242424242 with any CVC and a valid expiration date or check the documentation "<a href="%s" target="_blank">Testing Stripe</a>" for more card numbers.', 'woocommerce-gateway-stripe' ), 'https://stripe.com/docs/testing' );
423
-				$this->description  = trim( $this->description );
422
+				$this->description .= ' ' . sprintf(__('TEST MODE ENABLED. In test mode, you can use the card number 4242424242424242 with any CVC and a valid expiration date or check the documentation "<a href="%s" target="_blank">Testing Stripe</a>" for more card numbers.', 'woocommerce-gateway-stripe'), 'https://stripe.com/docs/testing');
423
+				$this->description  = trim($this->description);
424 424
 			}
425
-			echo apply_filters( 'wc_stripe_description', wpautop( wp_kses_post( $this->description ) ) );
425
+			echo apply_filters('wc_stripe_description', wpautop(wp_kses_post($this->description)));
426 426
 		}
427 427
 
428
-		if ( $display_tokenization ) {
428
+		if ($display_tokenization) {
429 429
 			$this->tokenization_script();
430 430
 			$this->saved_payment_methods();
431 431
 		}
432 432
 
433
-		if ( ! $this->stripe_checkout ) {
434
-			if ( apply_filters( 'wc_stripe_use_elements_checkout_form', true ) ) {
433
+		if ( ! $this->stripe_checkout) {
434
+			if (apply_filters('wc_stripe_use_elements_checkout_form', true)) {
435 435
 				$this->elements_form();
436 436
 			} else {
437 437
 				$this->form();
@@ -439,7 +439,7 @@  discard block
 block discarded – undo
439 439
 			}
440 440
 		}
441 441
 
442
-		if ( apply_filters( 'wc_stripe_display_save_payment_method_checkbox', $display_tokenization ) && ! is_add_payment_method_page() && ! isset( $_GET['change_payment_method'] ) ) {
442
+		if (apply_filters('wc_stripe_display_save_payment_method_checkbox', $display_tokenization) && ! is_add_payment_method_page() && ! isset($_GET['change_payment_method'])) {
443 443
 			$this->save_payment_method_checkbox();
444 444
 		}
445 445
 
@@ -454,12 +454,12 @@  discard block
 block discarded – undo
454 454
 	 */
455 455
 	public function elements_form() {
456 456
 		?>
457
-		<fieldset id="wc-<?php echo esc_attr( $this->id ); ?>-cc-form" class="wc-credit-card-form wc-payment-form" style="background:transparent;">
458
-			<?php do_action( 'woocommerce_credit_card_form_start', $this->id ); ?>
457
+		<fieldset id="wc-<?php echo esc_attr($this->id); ?>-cc-form" class="wc-credit-card-form wc-payment-form" style="background:transparent;">
458
+			<?php do_action('woocommerce_credit_card_form_start', $this->id); ?>
459 459
 
460
-			<?php if ( $this->inline_cc_form ) { ?>
460
+			<?php if ($this->inline_cc_form) { ?>
461 461
 				<label for="card-element">
462
-					<?php esc_html_e( 'Credit or debit card', 'woocommerce-gateway-stripe' ); ?>
462
+					<?php esc_html_e('Credit or debit card', 'woocommerce-gateway-stripe'); ?>
463 463
 				</label>
464 464
 
465 465
 				<div id="stripe-card-element" style="background:#fff;padding:0 1em;border:1px solid #ddd;margin:5px 0;padding:10px 5px;">
@@ -467,7 +467,7 @@  discard block
 block discarded – undo
467 467
 				</div>
468 468
 			<?php } else { ?>
469 469
 				<div class="form-row form-row-wide">
470
-					<label><?php _e( 'Card Number', 'woocommerce-gateway-stripe' ); ?><span class="required">*</span></label>
470
+					<label><?php _e('Card Number', 'woocommerce-gateway-stripe'); ?><span class="required">*</span></label>
471 471
 
472 472
 					<div id="stripe-card-element" style="background:#fff;padding:0 1em;border:1px solid #ddd;margin:5px 0;padding:10px 5px;">
473 473
 					<!-- a Stripe Element will be inserted here. -->
@@ -475,7 +475,7 @@  discard block
 block discarded – undo
475 475
 				</div>
476 476
 
477 477
 				<div class="form-row form-row-first">
478
-					<label><?php _e( 'Expiry Date', 'woocommerce-gateway-stripe' ); ?><span class="required">*</span></label>
478
+					<label><?php _e('Expiry Date', 'woocommerce-gateway-stripe'); ?><span class="required">*</span></label>
479 479
 
480 480
 					<div id="stripe-exp-element" style="background:#fff;padding:0 1em;border:1px solid #ddd;margin:5px 0;padding:10px 5px;">
481 481
 					<!-- a Stripe Element will be inserted here. -->
@@ -483,7 +483,7 @@  discard block
 block discarded – undo
483 483
 				</div>
484 484
 
485 485
 				<div class="form-row form-row-last">
486
-					<label><?php _e( 'Card Code (CVC)', 'woocommerce-gateway-stripe' ); ?><span class="required">*</span></label>
486
+					<label><?php _e('Card Code (CVC)', 'woocommerce-gateway-stripe'); ?><span class="required">*</span></label>
487 487
 				<div id="stripe-cvc-element" style="background:#fff;padding:0 1em;border:1px solid #ddd;margin:5px 0;padding:10px 5px;">
488 488
 				<!-- a Stripe Element will be inserted here. -->
489 489
 				</div>
@@ -493,7 +493,7 @@  discard block
 block discarded – undo
493 493
 
494 494
 			<!-- Used to display form errors -->
495 495
 			<div class="stripe-source-errors" role="alert"></div>
496
-			<?php do_action( 'woocommerce_credit_card_form_end', $this->id ); ?>
496
+			<?php do_action('woocommerce_credit_card_form_end', $this->id); ?>
497 497
 			<div class="clear"></div>
498 498
 		</fieldset>
499 499
 		<?php
@@ -506,13 +506,13 @@  discard block
 block discarded – undo
506 506
 	 * @version 3.1.0
507 507
 	 */
508 508
 	public function admin_scripts() {
509
-		if ( 'woocommerce_page_wc-settings' !== get_current_screen()->id ) {
509
+		if ('woocommerce_page_wc-settings' !== get_current_screen()->id) {
510 510
 			return;
511 511
 		}
512 512
 
513
-		$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
513
+		$suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';
514 514
 
515
-		wp_enqueue_script( 'woocommerce_stripe_admin', plugins_url( 'assets/js/stripe-admin' . $suffix . '.js', WC_STRIPE_MAIN_FILE ), array(), WC_STRIPE_VERSION, true );
515
+		wp_enqueue_script('woocommerce_stripe_admin', plugins_url('assets/js/stripe-admin' . $suffix . '.js', WC_STRIPE_MAIN_FILE), array(), WC_STRIPE_VERSION, true);
516 516
 	}
517 517
 
518 518
 	/**
@@ -524,29 +524,29 @@  discard block
 block discarded – undo
524 524
 	 * @version 4.0.0
525 525
 	 */
526 526
 	public function payment_scripts() {
527
-		if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) && ! is_add_payment_method_page() && ! isset( $_GET['change_payment_method'] ) ) {
527
+		if ( ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order']) && ! is_add_payment_method_page() && ! isset($_GET['change_payment_method'])) {
528 528
 			return;
529 529
 		}
530 530
 
531
-		$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
531
+		$suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';
532 532
 
533
-		wp_register_style( 'stripe_paymentfonts', plugins_url( 'assets/css/stripe-paymentfonts.css', WC_STRIPE_MAIN_FILE ), array(), '1.2.5' );
534
-		wp_enqueue_style( 'stripe_paymentfonts' );
535
-		wp_register_script( 'stripe_checkout', 'https://checkout.stripe.com/checkout.js', '', WC_STRIPE_VERSION, true );
536
-		wp_register_script( 'stripev2', 'https://js.stripe.com/v2/', '', '2.0', true );
537
-		wp_register_script( 'stripe', 'https://js.stripe.com/v3/', '', '3.0', true );
538
-		wp_register_script( 'woocommerce_stripe', plugins_url( 'assets/js/stripe' . $suffix . '.js', WC_STRIPE_MAIN_FILE ), array( 'jquery-payment', 'stripev2', 'stripe' ), WC_STRIPE_VERSION, true );
533
+		wp_register_style('stripe_paymentfonts', plugins_url('assets/css/stripe-paymentfonts.css', WC_STRIPE_MAIN_FILE), array(), '1.2.5');
534
+		wp_enqueue_style('stripe_paymentfonts');
535
+		wp_register_script('stripe_checkout', 'https://checkout.stripe.com/checkout.js', '', WC_STRIPE_VERSION, true);
536
+		wp_register_script('stripev2', 'https://js.stripe.com/v2/', '', '2.0', true);
537
+		wp_register_script('stripe', 'https://js.stripe.com/v3/', '', '3.0', true);
538
+		wp_register_script('woocommerce_stripe', plugins_url('assets/js/stripe' . $suffix . '.js', WC_STRIPE_MAIN_FILE), array('jquery-payment', 'stripev2', 'stripe'), WC_STRIPE_VERSION, true);
539 539
 
540 540
 		$stripe_params = array(
541 541
 			'key'                  => $this->publishable_key,
542
-			'i18n_terms'           => __( 'Please accept the terms and conditions first', 'woocommerce-gateway-stripe' ),
543
-			'i18n_required_fields' => __( 'Please fill in required checkout fields first', 'woocommerce-gateway-stripe' ),
542
+			'i18n_terms'           => __('Please accept the terms and conditions first', 'woocommerce-gateway-stripe'),
543
+			'i18n_required_fields' => __('Please fill in required checkout fields first', 'woocommerce-gateway-stripe'),
544 544
 		);
545 545
 
546 546
 		// If we're on the pay page we need to pass stripe.js the address of the order.
547
-		if ( isset( $_GET['pay_for_order'] ) && 'true' === $_GET['pay_for_order'] ) {
548
-			$order_id = wc_get_order_id_by_order_key( urldecode( $_GET['key'] ) );
549
-			$order    = wc_get_order( $order_id );
547
+		if (isset($_GET['pay_for_order']) && 'true' === $_GET['pay_for_order']) {
548
+			$order_id = wc_get_order_id_by_order_key(urldecode($_GET['key']));
549
+			$order    = wc_get_order($order_id);
550 550
 
551 551
 			$stripe_params['billing_first_name'] = WC_Stripe_Helper::is_pre_30() ? $order->billing_first_name : $order->get_billing_first_name();
552 552
 			$stripe_params['billing_last_name']  = WC_Stripe_Helper::is_pre_30() ? $order->billing_last_name : $order->get_billing_last_name();
@@ -558,37 +558,37 @@  discard block
 block discarded – undo
558 558
 			$stripe_params['billing_country']    = WC_Stripe_Helper::is_pre_30() ? $order->billing_country : $order->get_billing_country();
559 559
 		}
560 560
 
561
-		$stripe_params['no_prepaid_card_msg']                     = __( 'Sorry, we\'re not accepting prepaid cards at this time. Your credit card has not been charge. Please try with alternative payment method.', 'woocommerce-gateway-stripe' );
562
-		$stripe_params['no_bank_country_msg']                     = __( 'Please select a country for your bank.', 'woocommerce-gateway-stripe' );
563
-		$stripe_params['no_sepa_owner_msg']                       = __( 'Please enter your IBAN account name.', 'woocommerce-gateway-stripe' );
564
-		$stripe_params['no_sepa_iban_msg']                        = __( 'Please enter your IBAN account number.', 'woocommerce-gateway-stripe' );
565
-		$stripe_params['allow_prepaid_card']                      = apply_filters( 'wc_stripe_allow_prepaid_card', true ) ? 'yes' : 'no';
561
+		$stripe_params['no_prepaid_card_msg']                     = __('Sorry, we\'re not accepting prepaid cards at this time. Your credit card has not been charge. Please try with alternative payment method.', 'woocommerce-gateway-stripe');
562
+		$stripe_params['no_bank_country_msg']                     = __('Please select a country for your bank.', 'woocommerce-gateway-stripe');
563
+		$stripe_params['no_sepa_owner_msg']                       = __('Please enter your IBAN account name.', 'woocommerce-gateway-stripe');
564
+		$stripe_params['no_sepa_iban_msg']                        = __('Please enter your IBAN account number.', 'woocommerce-gateway-stripe');
565
+		$stripe_params['allow_prepaid_card']                      = apply_filters('wc_stripe_allow_prepaid_card', true) ? 'yes' : 'no';
566 566
 		$stripe_params['inline_cc_form']                          = $this->inline_cc_form ? 'yes' : 'no';
567
-		$stripe_params['stripe_checkout_require_billing_address'] = apply_filters( 'wc_stripe_checkout_require_billing_address', false ) ? 'yes' : 'no';
568
-		$stripe_params['is_checkout']                             = ( is_checkout() && empty( $_GET['pay_for_order'] ) );
567
+		$stripe_params['stripe_checkout_require_billing_address'] = apply_filters('wc_stripe_checkout_require_billing_address', false) ? 'yes' : 'no';
568
+		$stripe_params['is_checkout']                             = (is_checkout() && empty($_GET['pay_for_order']));
569 569
 		$stripe_params['return_url']                              = $this->get_stripe_return_url();
570
-		$stripe_params['ajaxurl']                                 = WC_AJAX::get_endpoint( '%%endpoint%%' );
571
-		$stripe_params['stripe_nonce']                            = wp_create_nonce( '_wc_stripe_nonce' );
570
+		$stripe_params['ajaxurl']                                 = WC_AJAX::get_endpoint('%%endpoint%%');
571
+		$stripe_params['stripe_nonce']                            = wp_create_nonce('_wc_stripe_nonce');
572 572
 		$stripe_params['statement_descriptor']                    = $this->statement_descriptor;
573
-		$stripe_params['use_elements']                            = apply_filters( 'wc_stripe_use_elements_checkout_form', true ) ? 'yes' : 'no';
573
+		$stripe_params['use_elements']                            = apply_filters('wc_stripe_use_elements_checkout_form', true) ? 'yes' : 'no';
574 574
 		$stripe_params['is_stripe_checkout']                      = $this->stripe_checkout ? 'yes' : 'no';
575
-		$stripe_params['is_change_payment_page']                  = ( isset( $_GET['pay_for_order'] ) || isset( $_GET['change_payment_method'] ) ) ? 'yes' : 'no';
575
+		$stripe_params['is_change_payment_page']                  = (isset($_GET['pay_for_order']) || isset($_GET['change_payment_method'])) ? 'yes' : 'no';
576 576
 		$stripe_params['is_add_payment_method_page']              = is_add_payment_method_page() ? 'yes' : 'no';
577
-		$stripe_params['elements_styling']                        = apply_filters( 'wc_stripe_elements_styling', false );
578
-		$stripe_params['elements_classes']                        = apply_filters( 'wc_stripe_elements_classes', false );
577
+		$stripe_params['elements_styling']                        = apply_filters('wc_stripe_elements_styling', false);
578
+		$stripe_params['elements_classes']                        = apply_filters('wc_stripe_elements_classes', false);
579 579
 
580 580
 		// merge localized messages to be use in JS
581
-		$stripe_params = array_merge( $stripe_params, WC_Stripe_Helper::get_localized_messages() );
581
+		$stripe_params = array_merge($stripe_params, WC_Stripe_Helper::get_localized_messages());
582 582
 
583
-		wp_localize_script( 'woocommerce_stripe', 'wc_stripe_params', apply_filters( 'wc_stripe_params', $stripe_params ) );
584
-		wp_localize_script( 'woocommerce_stripe_checkout', 'wc_stripe_params', apply_filters( 'wc_stripe_params', $stripe_params ) );
583
+		wp_localize_script('woocommerce_stripe', 'wc_stripe_params', apply_filters('wc_stripe_params', $stripe_params));
584
+		wp_localize_script('woocommerce_stripe_checkout', 'wc_stripe_params', apply_filters('wc_stripe_params', $stripe_params));
585 585
 
586
-		if ( $this->stripe_checkout ) {
587
-			wp_enqueue_script( 'stripe_checkout' );
586
+		if ($this->stripe_checkout) {
587
+			wp_enqueue_script('stripe_checkout');
588 588
 		}
589 589
 
590 590
 		$this->tokenization_script();
591
-		wp_enqueue_script( 'woocommerce_stripe' );
591
+		wp_enqueue_script('woocommerce_stripe');
592 592
 	}
593 593
 
594 594
 	/**
@@ -600,22 +600,22 @@  discard block
 block discarded – undo
600 600
 	 * @param object $source_object
601 601
 	 * @return mixed
602 602
 	 */
603
-	public function create_3ds_source( $order, $source_object ) {
603
+	public function create_3ds_source($order, $source_object) {
604 604
 		$currency                    = WC_Stripe_Helper::is_pre_30() ? $order->get_order_currency() : $order->get_currency();
605 605
 		$order_id                    = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
606
-		$return_url                  = $this->get_stripe_return_url( $order );
606
+		$return_url                  = $this->get_stripe_return_url($order);
607 607
 
608 608
 		$post_data                   = array();
609
-		$post_data['amount']         = WC_Stripe_Helper::get_stripe_amount( $order->get_total(), $currency );
610
-		$post_data['currency']       = strtolower( $currency );
609
+		$post_data['amount']         = WC_Stripe_Helper::get_stripe_amount($order->get_total(), $currency);
610
+		$post_data['currency']       = strtolower($currency);
611 611
 		$post_data['type']           = 'three_d_secure';
612
-		$post_data['owner']          = $this->get_owner_details( $order );
613
-		$post_data['three_d_secure'] = array( 'card' => $source_object->id );
614
-		$post_data['redirect']       = array( 'return_url' => $return_url );
612
+		$post_data['owner']          = $this->get_owner_details($order);
613
+		$post_data['three_d_secure'] = array('card' => $source_object->id);
614
+		$post_data['redirect']       = array('return_url' => $return_url);
615 615
 
616
-		WC_Stripe_Logger::log( 'Info: Begin creating 3DS source' );
616
+		WC_Stripe_Logger::log('Info: Begin creating 3DS source');
617 617
 
618
-		return WC_Stripe_API::request( $post_data, 'sources' );
618
+		return WC_Stripe_API::request($post_data, 'sources');
619 619
 	}
620 620
 
621 621
 	/**
@@ -631,45 +631,45 @@  discard block
 block discarded – undo
631 631
 	 *
632 632
 	 * @return array|void
633 633
 	 */
634
-	public function process_payment( $order_id, $retry = true, $force_save_source = false ) {
634
+	public function process_payment($order_id, $retry = true, $force_save_source = false) {
635 635
 		try {
636
-			$order   = wc_get_order( $order_id );
636
+			$order = wc_get_order($order_id);
637 637
 
638 638
 			// This comes from the create account checkbox in the checkout page.
639
-			$create_account = ! empty( $_POST['createaccount'] ) ? true : false;
639
+			$create_account = ! empty($_POST['createaccount']) ? true : false;
640 640
 
641
-			if ( $create_account ) {
641
+			if ($create_account) {
642 642
 				$new_customer_id     = WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id();
643
-				$new_stripe_customer = new WC_Stripe_Customer( $new_customer_id );
643
+				$new_stripe_customer = new WC_Stripe_Customer($new_customer_id);
644 644
 				$new_stripe_customer->create_customer();
645 645
 			}
646 646
 
647 647
 			$source_object = $this->create_source_object();
648 648
 
649
-			$prepared_source = $this->prepare_source( $source_object, get_current_user_id(), $force_save_source );
649
+			$prepared_source = $this->prepare_source($source_object, get_current_user_id(), $force_save_source);
650 650
 
651 651
 			// Check if we don't allow prepaid credit cards.
652
-			if ( ! apply_filters( 'wc_stripe_allow_prepaid_card', true ) ) {
653
-				if ( $source_object && 'token' === $source_object->object && 'prepaid' === $source_object->card->funding ) {
654
-					$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' );
655
-					throw new WC_Stripe_Exception( print_r( $source_object, true ), $localized_message );
652
+			if ( ! apply_filters('wc_stripe_allow_prepaid_card', true)) {
653
+				if ($source_object && 'token' === $source_object->object && 'prepaid' === $source_object->card->funding) {
654
+					$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');
655
+					throw new WC_Stripe_Exception(print_r($source_object, true), $localized_message);
656 656
 				}
657 657
 			}
658 658
 
659
-			if ( empty( $prepared_source->source ) ) {
660
-				$localized_message = __( 'Payment processing failed. Please retry.', 'woocommerce-gateway-stripe' );
661
-				throw new WC_Stripe_Exception( print_r( $prepared_source, true ), $localized_message );
659
+			if (empty($prepared_source->source)) {
660
+				$localized_message = __('Payment processing failed. Please retry.', 'woocommerce-gateway-stripe');
661
+				throw new WC_Stripe_Exception(print_r($prepared_source, true), $localized_message);
662 662
 			}
663 663
 
664 664
 			// Store source to order meta.
665
-			$this->save_source( $order, $prepared_source );
665
+			$this->save_source($order, $prepared_source);
666 666
 
667 667
 			// Result from Stripe API request.
668 668
 			$response = null;
669 669
 
670
-			if ( $order->get_total() > 0 ) {
670
+			if ($order->get_total() > 0) {
671 671
 				// This will throw exception if not valid.
672
-				$this->validate_minimum_order_amount( $order );
672
+				$this->validate_minimum_order_amount($order);
673 673
 
674 674
 				/**
675 675
 				 * Check if card 3DS is required or optional with 3DS setting.
@@ -678,83 +678,83 @@  discard block
 block discarded – undo
678 678
 				 * Note that if we need to save source, the original source must be first
679 679
 				 * attached to a customer in Stripe before it can be charged.
680 680
 				 */
681
-				if ( ( $source_object && ! empty( $source_object->card ) ) && ( 'card' === $source_object->type && 'required' === $source_object->card->three_d_secure || ( $this->three_d_secure && 'optional' === $source_object->card->three_d_secure ) ) ) {
681
+				if (($source_object && ! empty($source_object->card)) && ('card' === $source_object->type && 'required' === $source_object->card->three_d_secure || ($this->three_d_secure && 'optional' === $source_object->card->three_d_secure))) {
682 682
 
683
-					$response = $this->create_3ds_source( $order, $source_object );
683
+					$response = $this->create_3ds_source($order, $source_object);
684 684
 
685
-					if ( ! empty( $response->error ) ) {
685
+					if ( ! empty($response->error)) {
686 686
 						$localized_message = $response->error->message;
687 687
 
688
-						$order->add_order_note( $localized_message );
688
+						$order->add_order_note($localized_message);
689 689
 
690
-						throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message );
690
+						throw new WC_Stripe_Exception(print_r($response, true), $localized_message);
691 691
 					}
692 692
 
693 693
 					// Update order meta with 3DS source.
694
-					if ( WC_Stripe_Helper::is_pre_30() ) {
695
-						update_post_meta( $order_id, '_stripe_source_id', $response->id );
694
+					if (WC_Stripe_Helper::is_pre_30()) {
695
+						update_post_meta($order_id, '_stripe_source_id', $response->id);
696 696
 					} else {
697
-						$order->update_meta_data( '_stripe_source_id', $response->id );
697
+						$order->update_meta_data('_stripe_source_id', $response->id);
698 698
 						$order->save();
699 699
 					}
700 700
 
701
-					WC_Stripe_Logger::log( 'Info: Redirecting to 3DS...' );
701
+					WC_Stripe_Logger::log('Info: Redirecting to 3DS...');
702 702
 
703 703
 					return array(
704 704
 						'result'   => 'success',
705
-						'redirect' => esc_url_raw( $response->redirect->url ),
705
+						'redirect' => esc_url_raw($response->redirect->url),
706 706
 					);
707 707
 				}
708 708
 
709
-				WC_Stripe_Logger::log( "Info: Begin processing payment for order $order_id for the amount of {$order->get_total()}" );
709
+				WC_Stripe_Logger::log("Info: Begin processing payment for order $order_id for the amount of {$order->get_total()}");
710 710
 
711 711
 				// Make the request.
712
-				$response = WC_Stripe_API::request( $this->generate_payment_request( $order, $prepared_source ) );
712
+				$response = WC_Stripe_API::request($this->generate_payment_request($order, $prepared_source));
713 713
 
714
-				if ( ! empty( $response->error ) ) {
714
+				if ( ! empty($response->error)) {
715 715
 					// If it is an API error such connection or server, let's retry.
716
-					if ( 'api_connection_error' === $response->error->type || 'api_error' === $response->error->type ) {
717
-						if ( $retry ) {
718
-							sleep( 5 );
719
-							return $this->process_payment( $order_id, false, $force_save_source );
716
+					if ('api_connection_error' === $response->error->type || 'api_error' === $response->error->type) {
717
+						if ($retry) {
718
+							sleep(5);
719
+							return $this->process_payment($order_id, false, $force_save_source);
720 720
 						} else {
721 721
 							$localized_message = 'API connection error and retries exhausted.';
722
-							$order->add_order_note( $localized_message );
723
-							throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message );
722
+							$order->add_order_note($localized_message);
723
+							throw new WC_Stripe_Exception(print_r($response, true), $localized_message);
724 724
 						}
725 725
 					}
726 726
 
727 727
 					// Customer param wrong? The user may have been deleted on stripe's end. Remove customer_id. Can be retried without.
728
-					if ( preg_match( '/No such customer/i', $response->error->message ) && $retry ) {
729
-						delete_user_meta( WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id(), '_stripe_customer_id' );
728
+					if (preg_match('/No such customer/i', $response->error->message) && $retry) {
729
+						delete_user_meta(WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id(), '_stripe_customer_id');
730 730
 
731
-						return $this->process_payment( $order_id, false, $force_save_source );
732
-					} elseif ( preg_match( '/No such token/i', $response->error->message ) && $prepared_source->token_id ) {
731
+						return $this->process_payment($order_id, false, $force_save_source);
732
+					} elseif (preg_match('/No such token/i', $response->error->message) && $prepared_source->token_id) {
733 733
 						// Source param wrong? The CARD may have been deleted on stripe's end. Remove token and show message.
734
-						$wc_token = WC_Payment_Tokens::get( $prepared_source->token_id );
734
+						$wc_token = WC_Payment_Tokens::get($prepared_source->token_id);
735 735
 						$wc_token->delete();
736
-						$localized_message = __( 'This card is no longer available and has been removed.', 'woocommerce-gateway-stripe' );
737
-						$order->add_order_note( $localized_message );
738
-						throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message );
736
+						$localized_message = __('This card is no longer available and has been removed.', 'woocommerce-gateway-stripe');
737
+						$order->add_order_note($localized_message);
738
+						throw new WC_Stripe_Exception(print_r($response, true), $localized_message);
739 739
 					}
740 740
 
741 741
 					$localized_messages = WC_Stripe_Helper::get_localized_messages();
742 742
 
743
-					if ( 'card_error' === $response->error->type ) {
744
-						$localized_message = isset( $localized_messages[ $response->error->code ] ) ? $localized_messages[ $response->error->code ] : $response->error->message;
743
+					if ('card_error' === $response->error->type) {
744
+						$localized_message = isset($localized_messages[$response->error->code]) ? $localized_messages[$response->error->code] : $response->error->message;
745 745
 					} else {
746
-						$localized_message = isset( $localized_messages[ $response->error->type ] ) ? $localized_messages[ $response->error->type ] : $response->error->message;
746
+						$localized_message = isset($localized_messages[$response->error->type]) ? $localized_messages[$response->error->type] : $response->error->message;
747 747
 					}
748 748
 
749
-					$order->add_order_note( $localized_message );
749
+					$order->add_order_note($localized_message);
750 750
 
751
-					throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message );
751
+					throw new WC_Stripe_Exception(print_r($response, true), $localized_message);
752 752
 				}
753 753
 
754
-				do_action( 'wc_gateway_stripe_process_payment', $response, $order );
754
+				do_action('wc_gateway_stripe_process_payment', $response, $order);
755 755
 
756 756
 				// Process valid response.
757
-				$this->process_response( $response, $order );
757
+				$this->process_response($response, $order);
758 758
 			} else {
759 759
 				$order->payment_complete();
760 760
 			}
@@ -765,17 +765,17 @@  discard block
 block discarded – undo
765 765
 			// Return thank you page redirect.
766 766
 			return array(
767 767
 				'result'   => 'success',
768
-				'redirect' => $this->get_return_url( $order ),
768
+				'redirect' => $this->get_return_url($order),
769 769
 			);
770 770
 
771
-		} catch ( WC_Stripe_Exception $e ) {
772
-			wc_add_notice( $e->getLocalizedMessage(), 'error' );
773
-			WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() );
771
+		} catch (WC_Stripe_Exception $e) {
772
+			wc_add_notice($e->getLocalizedMessage(), 'error');
773
+			WC_Stripe_Logger::log('Error: ' . $e->getMessage());
774 774
 
775
-			do_action( 'wc_gateway_stripe_process_payment_error', $e, $order );
775
+			do_action('wc_gateway_stripe_process_payment_error', $e, $order);
776 776
 
777
-			if ( $order->has_status( array( 'pending', 'failed' ) ) ) {
778
-				$this->send_failed_order_email( $order_id );
777
+			if ($order->has_status(array('pending', 'failed'))) {
778
+				$this->send_failed_order_email($order_id);
779 779
 			}
780 780
 
781 781
 			return array(
Please login to merge, or discard this patch.
includes/payment-methods/class-wc-gateway-stripe-sepa.php 1 patch
Spacing   +98 added lines, -98 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) {
2
+if ( ! defined('ABSPATH')) {
3 3
 	exit;
4 4
 }
5 5
 
@@ -57,9 +57,9 @@  discard block
 block discarded – undo
57 57
 	 */
58 58
 	public function __construct() {
59 59
 		$this->id                   = 'stripe_sepa';
60
-		$this->method_title         = __( 'Stripe SEPA Direct Debit', 'woocommerce-gateway-stripe' );
60
+		$this->method_title         = __('Stripe SEPA Direct Debit', 'woocommerce-gateway-stripe');
61 61
 		/* translators: link */
62
-		$this->method_description   = sprintf( __( 'All other general Stripe settings can be adjusted <a href="%s">here</a>.', 'woocommerce-gateway-stripe' ), admin_url( 'admin.php?page=wc-settings&tab=checkout&section=stripe' ) );
62
+		$this->method_description   = sprintf(__('All other general Stripe settings can be adjusted <a href="%s">here</a>.', 'woocommerce-gateway-stripe'), admin_url('admin.php?page=wc-settings&tab=checkout&section=stripe'));
63 63
 		$this->supports             = array(
64 64
 			'products',
65 65
 			'refunds',
@@ -84,25 +84,25 @@  discard block
 block discarded – undo
84 84
 		// Load the settings.
85 85
 		$this->init_settings();
86 86
 
87
-		$main_settings              = get_option( 'woocommerce_stripe_settings' );
88
-		$this->title                = $this->get_option( 'title' );
89
-		$this->description          = $this->get_option( 'description' );
90
-		$this->enabled              = $this->get_option( 'enabled' );
91
-		$this->testmode             = ( ! empty( $main_settings['testmode'] ) && 'yes' === $main_settings['testmode'] ) ? true : false;
92
-		$this->saved_cards          = ( ! empty( $main_settings['saved_cards'] ) && 'yes' === $main_settings['saved_cards'] ) ? true : false;
93
-		$this->publishable_key      = ! empty( $main_settings['publishable_key'] ) ? $main_settings['publishable_key'] : '';
94
-		$this->secret_key           = ! empty( $main_settings['secret_key'] ) ? $main_settings['secret_key'] : '';
95
-		$this->statement_descriptor = ! empty( $main_settings['statement_descriptor'] ) ? $main_settings['statement_descriptor'] : '';
96
-
97
-		if ( $this->testmode ) {
98
-			$this->publishable_key = ! empty( $main_settings['test_publishable_key'] ) ? $main_settings['test_publishable_key'] : '';
99
-			$this->secret_key      = ! empty( $main_settings['test_secret_key'] ) ? $main_settings['test_secret_key'] : '';
87
+		$main_settings              = get_option('woocommerce_stripe_settings');
88
+		$this->title                = $this->get_option('title');
89
+		$this->description          = $this->get_option('description');
90
+		$this->enabled              = $this->get_option('enabled');
91
+		$this->testmode             = ( ! empty($main_settings['testmode']) && 'yes' === $main_settings['testmode']) ? true : false;
92
+		$this->saved_cards          = ( ! empty($main_settings['saved_cards']) && 'yes' === $main_settings['saved_cards']) ? true : false;
93
+		$this->publishable_key      = ! empty($main_settings['publishable_key']) ? $main_settings['publishable_key'] : '';
94
+		$this->secret_key           = ! empty($main_settings['secret_key']) ? $main_settings['secret_key'] : '';
95
+		$this->statement_descriptor = ! empty($main_settings['statement_descriptor']) ? $main_settings['statement_descriptor'] : '';
96
+
97
+		if ($this->testmode) {
98
+			$this->publishable_key = ! empty($main_settings['test_publishable_key']) ? $main_settings['test_publishable_key'] : '';
99
+			$this->secret_key      = ! empty($main_settings['test_secret_key']) ? $main_settings['test_secret_key'] : '';
100 100
 		}
101 101
 
102
-		add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) );
103
-		add_action( 'admin_notices', array( $this, 'check_environment' ) );
104
-		add_action( 'admin_head', array( $this, 'remove_admin_notice' ) );
105
-		add_action( 'wp_enqueue_scripts', array( $this, 'payment_scripts' ) );
102
+		add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options'));
103
+		add_action('admin_notices', array($this, 'check_environment'));
104
+		add_action('admin_head', array($this, 'remove_admin_notice'));
105
+		add_action('wp_enqueue_scripts', array($this, 'payment_scripts'));
106 106
 	}
107 107
 
108 108
 	/**
@@ -112,19 +112,19 @@  discard block
 block discarded – undo
112 112
 	 * @version 4.0.0
113 113
 	 */
114 114
 	public function check_environment() {
115
-		if ( ! current_user_can( 'manage_woocommerce' ) ) {
115
+		if ( ! current_user_can('manage_woocommerce')) {
116 116
 			return;
117 117
 		}
118 118
 
119 119
 		$environment_warning = $this->get_environment_warning();
120 120
 
121
-		if ( $environment_warning ) {
122
-			$this->add_admin_notice( 'bad_environment', 'error', $environment_warning );
121
+		if ($environment_warning) {
122
+			$this->add_admin_notice('bad_environment', 'error', $environment_warning);
123 123
 		}
124 124
 
125
-		foreach ( (array) $this->notices as $notice_key => $notice ) {
126
-			echo "<div class='" . esc_attr( $notice['class'] ) . "'><p>";
127
-			echo wp_kses( $notice['message'], array( 'a' => array( 'href' => array() ) ) );
125
+		foreach ((array) $this->notices as $notice_key => $notice) {
126
+			echo "<div class='" . esc_attr($notice['class']) . "'><p>";
127
+			echo wp_kses($notice['message'], array('a' => array('href' => array())));
128 128
 			echo '</p></div>';
129 129
 		}
130 130
 	}
@@ -137,8 +137,8 @@  discard block
 block discarded – undo
137 137
 	 * @version 4.0.0
138 138
 	 */
139 139
 	public function get_environment_warning() {
140
-		if ( 'yes' === $this->enabled && ! in_array( get_woocommerce_currency(), $this->get_supported_currency() ) ) {
141
-			$message = __( 'SEPA is enabled - it requires store currency to be set to Euros.', 'woocommerce-gateway-stripe' );
140
+		if ('yes' === $this->enabled && ! in_array(get_woocommerce_currency(), $this->get_supported_currency())) {
141
+			$message = __('SEPA is enabled - it requires store currency to be set to Euros.', 'woocommerce-gateway-stripe');
142 142
 
143 143
 			return $message;
144 144
 		}
@@ -154,9 +154,9 @@  discard block
 block discarded – undo
154 154
 	 * @return array
155 155
 	 */
156 156
 	public function get_supported_currency() {
157
-		return apply_filters( 'wc_stripe_sepa_supported_currencies', array(
157
+		return apply_filters('wc_stripe_sepa_supported_currencies', array(
158 158
 			'EUR',
159
-		) );
159
+		));
160 160
 	}
161 161
 
162 162
 	/**
@@ -167,11 +167,11 @@  discard block
 block discarded – undo
167 167
 	 * @return bool
168 168
 	 */
169 169
 	public function is_available() {
170
-		if ( ! in_array( get_woocommerce_currency(), $this->get_supported_currency() ) ) {
170
+		if ( ! in_array(get_woocommerce_currency(), $this->get_supported_currency())) {
171 171
 			return false;
172 172
 		}
173 173
 
174
-		if ( is_add_payment_method_page() && ! $this->saved_cards ) {
174
+		if (is_add_payment_method_page() && ! $this->saved_cards) {
175 175
 			return false;
176 176
 		}
177 177
 
@@ -192,7 +192,7 @@  discard block
 block discarded – undo
192 192
 
193 193
 		$icons_str .= $icons['sepa'];
194 194
 
195
-		return apply_filters( 'woocommerce_gateway_icon', $icons_str, $this->id );
195
+		return apply_filters('woocommerce_gateway_icon', $icons_str, $this->id);
196 196
 	}
197 197
 
198 198
 	/**
@@ -203,19 +203,19 @@  discard block
 block discarded – undo
203 203
 	 * @access public
204 204
 	 */
205 205
 	public function payment_scripts() {
206
-		if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) && ! is_add_payment_method_page() ) {
206
+		if ( ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order']) && ! is_add_payment_method_page()) {
207 207
 			return;
208 208
 		}
209 209
 
210
-		wp_enqueue_style( 'stripe_paymentfonts' );
211
-		wp_enqueue_script( 'woocommerce_stripe' );
210
+		wp_enqueue_style('stripe_paymentfonts');
211
+		wp_enqueue_script('woocommerce_stripe');
212 212
 	}
213 213
 
214 214
 	/**
215 215
 	 * Initialize Gateway Settings Form Fields.
216 216
 	 */
217 217
 	public function init_form_fields() {
218
-		$this->form_fields = require( WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-sepa-settings.php' );
218
+		$this->form_fields = require(WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-sepa-settings.php');
219 219
 	}
220 220
 
221 221
 	/**
@@ -227,7 +227,7 @@  discard block
 block discarded – undo
227 227
 	 */
228 228
 	public function mandate_display() {
229 229
 		/* translators: statement descriptor */
230
-		printf( __( 'By providing your IBAN and confirming this payment, you are authorizing %s and Stripe, our payment service provider, to send instructions to your bank to debit your account and your bank to debit your account in accordance with those instructions. You are entitled to a refund from your bank under the terms and conditions of your agreement with your bank. A refund must be claimed within 8 weeks starting from the date on which your account was debited.', 'woocommerce-gateway-stripe' ), WC_Stripe_Helper::clean_statement_descriptor( $this->statement_descriptor ) );
230
+		printf(__('By providing your IBAN and confirming this payment, you are authorizing %s and Stripe, our payment service provider, to send instructions to your bank to debit your account and your bank to debit your account in accordance with those instructions. You are entitled to a refund from your bank under the terms and conditions of your agreement with your bank. A refund must be claimed within 8 weeks starting from the date on which your account was debited.', 'woocommerce-gateway-stripe'), WC_Stripe_Helper::clean_statement_descriptor($this->statement_descriptor));
231 231
 	}
232 232
 
233 233
 	/**
@@ -238,24 +238,24 @@  discard block
 block discarded – undo
238 238
 	 */
239 239
 	public function form() {
240 240
 		?>
241
-		<fieldset id="wc-<?php echo esc_attr( $this->id ); ?>-form" class="wc-payment-form">
242
-			<?php do_action( 'woocommerce_credit_card_form_start', $this->id ); ?>
241
+		<fieldset id="wc-<?php echo esc_attr($this->id); ?>-form" class="wc-payment-form">
242
+			<?php do_action('woocommerce_credit_card_form_start', $this->id); ?>
243 243
 			<p class="wc-stripe-sepa-mandate" style="margin-bottom:40px;"><?php $this->mandate_display(); ?></p>
244 244
 			<p class="form-row form-row-wide validate-required">
245 245
 				<label for="stripe-sepa-owner">
246
-					<?php esc_html_e( 'IBAN Account Name.', 'woocommerce-gateway-stripe' ); ?>
246
+					<?php esc_html_e('IBAN Account Name.', 'woocommerce-gateway-stripe'); ?>
247 247
 				</label>
248 248
 				<input id="stripe-sepa-owner" name="stripe_sepa_owner" value="" style="border:1px solid #ddd;margin:5px 0;padding:10px 5px;background-color:#fff;outline:0;" />
249 249
 			</p>
250 250
 			<p class="form-row form-row-wide validate-required">
251 251
 				<label for="stripe-sepa-iban">
252
-					<?php esc_html_e( 'IBAN Account Number.', 'woocommerce-gateway-stripe' ); ?>
252
+					<?php esc_html_e('IBAN Account Number.', 'woocommerce-gateway-stripe'); ?>
253 253
 				</label>
254 254
 				<input id="stripe-sepa-iban" name="stripe_sepa_iban" value="" style="border:1px solid #ddd;margin:5px 0;padding:10px 5px;background-color:#fff;outline:0;" />
255 255
 			</p>
256 256
 			<!-- Used to display form errors -->
257 257
 			<div class="stripe-source-errors" role="alert"></div>
258
-			<?php do_action( 'woocommerce_credit_card_form_end', $this->id ); ?>
258
+			<?php do_action('woocommerce_credit_card_form_end', $this->id); ?>
259 259
 			<div class="clear"></div>
260 260
 		</fieldset>
261 261
 		<?php
@@ -267,42 +267,42 @@  discard block
 block discarded – undo
267 267
 	public function payment_fields() {
268 268
 		$user                 = wp_get_current_user();
269 269
 		$total                = WC()->cart->total;
270
-		$display_tokenization = $this->supports( 'tokenization' ) && is_checkout() && $this->saved_cards;
270
+		$display_tokenization = $this->supports('tokenization') && is_checkout() && $this->saved_cards;
271 271
 
272 272
 		// If paying from order, we need to get total from order not cart.
273
-		if ( isset( $_GET['pay_for_order'] ) && ! empty( $_GET['key'] ) ) {
274
-			$order = wc_get_order( wc_get_order_id_by_order_key( wc_clean( $_GET['key'] ) ) );
273
+		if (isset($_GET['pay_for_order']) && ! empty($_GET['key'])) {
274
+			$order = wc_get_order(wc_get_order_id_by_order_key(wc_clean($_GET['key'])));
275 275
 			$total = $order->get_total();
276 276
 		}
277 277
 
278
-		if ( is_add_payment_method_page() ) {
279
-			$pay_button_text = __( 'Add Payment', 'woocommerce-gateway-stripe' );
280
-			$total        = '';
278
+		if (is_add_payment_method_page()) {
279
+			$pay_button_text = __('Add Payment', 'woocommerce-gateway-stripe');
280
+			$total = '';
281 281
 		} else {
282 282
 			$pay_button_text = '';
283 283
 		}
284 284
 
285 285
 		echo '<div
286 286
 			id="stripe-sepa_debit-payment-data"
287
-			data-amount="' . esc_attr( WC_Stripe_Helper::get_stripe_amount( $total ) ) . '"
288
-			data-currency="' . esc_attr( strtolower( get_woocommerce_currency() ) ) . '">';
287
+			data-amount="' . esc_attr(WC_Stripe_Helper::get_stripe_amount($total)) . '"
288
+			data-currency="' . esc_attr(strtolower(get_woocommerce_currency())) . '">';
289 289
 
290
-		if ( $this->description ) {
291
-			if ( $this->testmode ) {
292
-				$this->description .= ' ' . __( 'TEST MODE ENABLED. In test mode, you can use IBAN number DE89370400440532013000.', 'woocommerce-gateway-stripe' );
293
-				$this->description  = trim( $this->description );
290
+		if ($this->description) {
291
+			if ($this->testmode) {
292
+				$this->description .= ' ' . __('TEST MODE ENABLED. In test mode, you can use IBAN number DE89370400440532013000.', 'woocommerce-gateway-stripe');
293
+				$this->description  = trim($this->description);
294 294
 			}
295
-			echo apply_filters( 'wc_stripe_description', wpautop( wp_kses_post( $this->description ) ) );
295
+			echo apply_filters('wc_stripe_description', wpautop(wp_kses_post($this->description)));
296 296
 		}
297 297
 
298
-		if ( $display_tokenization ) {
298
+		if ($display_tokenization) {
299 299
 			$this->tokenization_script();
300 300
 			$this->saved_payment_methods();
301 301
 		}
302 302
 
303 303
 		$this->form();
304 304
 
305
-		if ( apply_filters( 'wc_stripe_display_save_payment_method_checkbox', $display_tokenization ) && ! is_add_payment_method_page() && ! isset( $_GET['change_payment_method'] ) ) {
305
+		if (apply_filters('wc_stripe_display_save_payment_method_checkbox', $display_tokenization) && ! is_add_payment_method_page() && ! isset($_GET['change_payment_method'])) {
306 306
 			$this->save_payment_method_checkbox();
307 307
 		}
308 308
 
@@ -320,80 +320,80 @@  discard block
 block discarded – undo
320 320
 	 *
321 321
 	 * @return array|void
322 322
 	 */
323
-	public function process_payment( $order_id, $retry = true, $force_save_source = false ) {
323
+	public function process_payment($order_id, $retry = true, $force_save_source = false) {
324 324
 		try {
325
-			$order = wc_get_order( $order_id );
325
+			$order = wc_get_order($order_id);
326 326
 
327 327
 			// This comes from the create account checkbox in the checkout page.
328
-			$create_account = ! empty( $_POST['createaccount'] ) ? true : false;
328
+			$create_account = ! empty($_POST['createaccount']) ? true : false;
329 329
 
330
-			if ( $create_account ) {
330
+			if ($create_account) {
331 331
 				$new_customer_id     = WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id();
332
-				$new_stripe_customer = new WC_Stripe_Customer( $new_customer_id );
332
+				$new_stripe_customer = new WC_Stripe_Customer($new_customer_id);
333 333
 				$new_stripe_customer->create_customer();
334 334
 			}
335 335
 
336
-			$prepared_source = $this->prepare_source( $this->create_source_object(), get_current_user_id(), $force_save_source );
336
+			$prepared_source = $this->prepare_source($this->create_source_object(), get_current_user_id(), $force_save_source);
337 337
 
338 338
 			// Store source to order meta.
339
-			$this->save_source( $order, $prepared_source );
339
+			$this->save_source($order, $prepared_source);
340 340
 
341 341
 			// Result from Stripe API request.
342 342
 			$response = null;
343 343
 
344
-			if ( $order->get_total() > 0 ) {
344
+			if ($order->get_total() > 0) {
345 345
 				// This will throw exception if not valid.
346
-				$this->validate_minimum_order_amount( $order );
346
+				$this->validate_minimum_order_amount($order);
347 347
 
348
-				WC_Stripe_Logger::log( "Info: Begin processing payment for order $order_id for the amount of {$order->get_total()}" );
348
+				WC_Stripe_Logger::log("Info: Begin processing payment for order $order_id for the amount of {$order->get_total()}");
349 349
 
350 350
 				// Make the request.
351
-				$response = WC_Stripe_API::request( $this->generate_payment_request( $order, $prepared_source ) );
351
+				$response = WC_Stripe_API::request($this->generate_payment_request($order, $prepared_source));
352 352
 
353
-				if ( ! empty( $response->error ) ) {
353
+				if ( ! empty($response->error)) {
354 354
 					// If it is an API error such connection or server, let's retry.
355
-					if ( 'api_connection_error' === $response->error->type || 'api_error' === $response->error->type ) {
356
-						if ( $retry ) {
357
-							sleep( 5 );
358
-							return $this->process_payment( $order_id, false, $force_save_source );
355
+					if ('api_connection_error' === $response->error->type || 'api_error' === $response->error->type) {
356
+						if ($retry) {
357
+							sleep(5);
358
+							return $this->process_payment($order_id, false, $force_save_source);
359 359
 						} else {
360 360
 							$localized_message = 'API connection error and retries exhausted.';
361
-							$order->add_order_note( $localized_message );
362
-							throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message );
361
+							$order->add_order_note($localized_message);
362
+							throw new WC_Stripe_Exception(print_r($response, true), $localized_message);
363 363
 						}
364 364
 					}
365 365
 
366 366
 					// Customer param wrong? The user may have been deleted on stripe's end. Remove customer_id. Can be retried without.
367
-					if ( preg_match( '/No such customer/i', $response->error->message ) && $retry ) {
368
-						delete_user_meta( WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id(), '_stripe_customer_id' );
367
+					if (preg_match('/No such customer/i', $response->error->message) && $retry) {
368
+						delete_user_meta(WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id(), '_stripe_customer_id');
369 369
 
370
-						return $this->process_payment( $order_id, false, $force_save_source );
371
-					} elseif ( preg_match( '/No such token/i', $response->error->message ) && $prepared_source->token_id ) {
370
+						return $this->process_payment($order_id, false, $force_save_source);
371
+					} elseif (preg_match('/No such token/i', $response->error->message) && $prepared_source->token_id) {
372 372
 						// Source param wrong? The CARD may have been deleted on stripe's end. Remove token and show message.
373
-						$wc_token = WC_Payment_Tokens::get( $prepared_source->token_id );
373
+						$wc_token = WC_Payment_Tokens::get($prepared_source->token_id);
374 374
 						$wc_token->delete();
375
-						$localized_message = __( 'This card is no longer available and has been removed.', 'woocommerce-gateway-stripe' );
376
-						$order->add_order_note( $localized_message );
377
-						throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message );
375
+						$localized_message = __('This card is no longer available and has been removed.', 'woocommerce-gateway-stripe');
376
+						$order->add_order_note($localized_message);
377
+						throw new WC_Stripe_Exception(print_r($response, true), $localized_message);
378 378
 					}
379 379
 
380 380
 					$localized_messages = WC_Stripe_Helper::get_localized_messages();
381 381
 
382
-					if ( 'card_error' === $response->error->type ) {
383
-						$localized_message = isset( $localized_messages[ $response->error->code ] ) ? $localized_messages[ $response->error->code ] : $response->error->message;
382
+					if ('card_error' === $response->error->type) {
383
+						$localized_message = isset($localized_messages[$response->error->code]) ? $localized_messages[$response->error->code] : $response->error->message;
384 384
 					} else {
385
-						$localized_message = isset( $localized_messages[ $response->error->type ] ) ? $localized_messages[ $response->error->type ] : $response->error->message;
385
+						$localized_message = isset($localized_messages[$response->error->type]) ? $localized_messages[$response->error->type] : $response->error->message;
386 386
 					}
387 387
 
388
-					$order->add_order_note( $localized_message );
388
+					$order->add_order_note($localized_message);
389 389
 
390
-					throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message );
390
+					throw new WC_Stripe_Exception(print_r($response, true), $localized_message);
391 391
 				}
392 392
 
393
-				do_action( 'wc_gateway_stripe_process_payment', $response, $order );
393
+				do_action('wc_gateway_stripe_process_payment', $response, $order);
394 394
 
395 395
 				// Process valid response.
396
-				$this->process_response( $response, $order );
396
+				$this->process_response($response, $order);
397 397
 			} else {
398 398
 				$order->payment_complete();
399 399
 			}
@@ -404,17 +404,17 @@  discard block
 block discarded – undo
404 404
 			// Return thank you page redirect.
405 405
 			return array(
406 406
 				'result'   => 'success',
407
-				'redirect' => $this->get_return_url( $order ),
407
+				'redirect' => $this->get_return_url($order),
408 408
 			);
409 409
 
410
-		} catch ( WC_Stripe_Exception $e ) {
411
-			wc_add_notice( $e->getLocalizedMessage(), 'error' );
412
-			WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() );
410
+		} catch (WC_Stripe_Exception $e) {
411
+			wc_add_notice($e->getLocalizedMessage(), 'error');
412
+			WC_Stripe_Logger::log('Error: ' . $e->getMessage());
413 413
 
414
-			do_action( 'wc_gateway_stripe_process_payment_error', $e, $order );
414
+			do_action('wc_gateway_stripe_process_payment_error', $e, $order);
415 415
 
416
-			if ( $order->has_status( array( 'pending', 'failed' ) ) ) {
417
-				$this->send_failed_order_email( $order_id );
416
+			if ($order->has_status(array('pending', 'failed'))) {
417
+				$this->send_failed_order_email($order_id);
418 418
 			}
419 419
 
420 420
 			return array(
Please login to merge, or discard this patch.
includes/payment-methods/class-wc-gateway-stripe-bitcoin.php 1 patch
Spacing   +87 added lines, -87 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) {
2
+if ( ! defined('ABSPATH')) {
3 3
 	exit;
4 4
 }
5 5
 
@@ -64,9 +64,9 @@  discard block
 block discarded – undo
64 64
 	 */
65 65
 	public function __construct() {
66 66
 		$this->id                   = 'stripe_bitcoin';
67
-		$this->method_title         = __( 'Stripe Bitcoin', 'woocommerce-gateway-stripe' );
67
+		$this->method_title         = __('Stripe Bitcoin', 'woocommerce-gateway-stripe');
68 68
 		/* translators: link */
69
-		$this->method_description   = sprintf( __( 'All other general Stripe settings can be adjusted <a href="%s">here</a>.', 'woocommerce-gateway-stripe' ), admin_url( 'admin.php?page=wc-settings&tab=checkout&section=stripe' ) );
69
+		$this->method_description   = sprintf(__('All other general Stripe settings can be adjusted <a href="%s">here</a>.', 'woocommerce-gateway-stripe'), admin_url('admin.php?page=wc-settings&tab=checkout&section=stripe'));
70 70
 		$this->supports             = array(
71 71
 			'products',
72 72
 			'refunds',
@@ -78,29 +78,29 @@  discard block
 block discarded – undo
78 78
 		// Load the settings.
79 79
 		$this->init_settings();
80 80
 
81
-		$main_settings              = get_option( 'woocommerce_stripe_settings' );
82
-		$this->title                = $this->get_option( 'title' );
83
-		$this->description          = $this->get_option( 'description' );
84
-		$this->enabled              = $this->get_option( 'enabled' );
85
-		$this->testmode             = ( ! empty( $main_settings['testmode'] ) && 'yes' === $main_settings['testmode'] ) ? true : false;
86
-		$this->saved_cards          = ( ! empty( $main_settings['saved_cards'] ) && 'yes' === $main_settings['saved_cards'] ) ? true : false;
87
-		$this->publishable_key      = ! empty( $main_settings['publishable_key'] ) ? $main_settings['publishable_key'] : '';
88
-		$this->secret_key           = ! empty( $main_settings['secret_key'] ) ? $main_settings['secret_key'] : '';
89
-		$this->statement_descriptor = ! empty( $main_settings['statement_descriptor'] ) ? $main_settings['statement_descriptor'] : '';
90
-
91
-		if ( $this->testmode ) {
92
-			$this->publishable_key = ! empty( $main_settings['test_publishable_key'] ) ? $main_settings['test_publishable_key'] : '';
93
-			$this->secret_key      = ! empty( $main_settings['test_secret_key'] ) ? $main_settings['test_secret_key'] : '';
81
+		$main_settings              = get_option('woocommerce_stripe_settings');
82
+		$this->title                = $this->get_option('title');
83
+		$this->description          = $this->get_option('description');
84
+		$this->enabled              = $this->get_option('enabled');
85
+		$this->testmode             = ( ! empty($main_settings['testmode']) && 'yes' === $main_settings['testmode']) ? true : false;
86
+		$this->saved_cards          = ( ! empty($main_settings['saved_cards']) && 'yes' === $main_settings['saved_cards']) ? true : false;
87
+		$this->publishable_key      = ! empty($main_settings['publishable_key']) ? $main_settings['publishable_key'] : '';
88
+		$this->secret_key           = ! empty($main_settings['secret_key']) ? $main_settings['secret_key'] : '';
89
+		$this->statement_descriptor = ! empty($main_settings['statement_descriptor']) ? $main_settings['statement_descriptor'] : '';
90
+
91
+		if ($this->testmode) {
92
+			$this->publishable_key = ! empty($main_settings['test_publishable_key']) ? $main_settings['test_publishable_key'] : '';
93
+			$this->secret_key      = ! empty($main_settings['test_secret_key']) ? $main_settings['test_secret_key'] : '';
94 94
 		}
95 95
 
96
-		add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) );
97
-		add_action( 'admin_notices', array( $this, 'check_environment' ) );
98
-		add_action( 'admin_head', array( $this, 'remove_admin_notice' ) );
99
-		add_action( 'wp_enqueue_scripts', array( $this, 'payment_scripts' ) );
100
-		add_action( 'woocommerce_thankyou_stripe_bitcoin', array( $this, 'thankyou_page' ) );
96
+		add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options'));
97
+		add_action('admin_notices', array($this, 'check_environment'));
98
+		add_action('admin_head', array($this, 'remove_admin_notice'));
99
+		add_action('wp_enqueue_scripts', array($this, 'payment_scripts'));
100
+		add_action('woocommerce_thankyou_stripe_bitcoin', array($this, 'thankyou_page'));
101 101
 
102 102
 		// Customer Emails
103
-		add_action( 'woocommerce_email_before_order_table', array( $this, 'email_instructions' ), 10, 3 );
103
+		add_action('woocommerce_email_before_order_table', array($this, 'email_instructions'), 10, 3);
104 104
 	}
105 105
 
106 106
 	/**
@@ -110,19 +110,19 @@  discard block
 block discarded – undo
110 110
 	 * @version 4.0.0
111 111
 	 */
112 112
 	public function check_environment() {
113
-		if ( ! current_user_can( 'manage_woocommerce' ) ) {
113
+		if ( ! current_user_can('manage_woocommerce')) {
114 114
 			return;
115 115
 		}
116 116
 
117 117
 		$environment_warning = $this->get_environment_warning();
118 118
 
119
-		if ( $environment_warning ) {
120
-			$this->add_admin_notice( 'bad_environment', 'error', $environment_warning );
119
+		if ($environment_warning) {
120
+			$this->add_admin_notice('bad_environment', 'error', $environment_warning);
121 121
 		}
122 122
 
123
-		foreach ( (array) $this->notices as $notice_key => $notice ) {
124
-			echo "<div class='" . esc_attr( $notice['class'] ) . "'><p>";
125
-			echo wp_kses( $notice['message'], array( 'a' => array( 'href' => array() ) ) );
123
+		foreach ((array) $this->notices as $notice_key => $notice) {
124
+			echo "<div class='" . esc_attr($notice['class']) . "'><p>";
125
+			echo wp_kses($notice['message'], array('a' => array('href' => array())));
126 126
 			echo '</p></div>';
127 127
 		}
128 128
 	}
@@ -135,8 +135,8 @@  discard block
 block discarded – undo
135 135
 	 * @version 4.0.0
136 136
 	 */
137 137
 	public function get_environment_warning() {
138
-		if ( 'yes' === $this->enabled && ! in_array( get_woocommerce_currency(), $this->get_supported_currency() ) ) {
139
-			$message = __( 'Bitcoin is enabled - it requires store currency to be set to USD.', 'woocommerce-gateway-stripe' );
138
+		if ('yes' === $this->enabled && ! in_array(get_woocommerce_currency(), $this->get_supported_currency())) {
139
+			$message = __('Bitcoin is enabled - it requires store currency to be set to USD.', 'woocommerce-gateway-stripe');
140 140
 
141 141
 			return $message;
142 142
 		}
@@ -152,9 +152,9 @@  discard block
 block discarded – undo
152 152
 	 * @return array
153 153
 	 */
154 154
 	public function get_supported_currency() {
155
-		return apply_filters( 'wc_stripe_bitcoin_supported_currencies', array(
155
+		return apply_filters('wc_stripe_bitcoin_supported_currencies', array(
156 156
 			'USD',
157
-		) );
157
+		));
158 158
 	}
159 159
 
160 160
 	/**
@@ -165,7 +165,7 @@  discard block
 block discarded – undo
165 165
 	 * @return bool
166 166
 	 */
167 167
 	public function is_available() {
168
-		if ( ! in_array( get_woocommerce_currency(), $this->get_supported_currency() ) ) {
168
+		if ( ! in_array(get_woocommerce_currency(), $this->get_supported_currency())) {
169 169
 			return false;
170 170
 		}
171 171
 
@@ -186,7 +186,7 @@  discard block
 block discarded – undo
186 186
 
187 187
 		$icons_str .= $icons['bitcoin'];
188 188
 
189
-		return apply_filters( 'woocommerce_gateway_icon', $icons_str, $this->id );
189
+		return apply_filters('woocommerce_gateway_icon', $icons_str, $this->id);
190 190
 	}
191 191
 
192 192
 	/**
@@ -197,19 +197,19 @@  discard block
 block discarded – undo
197 197
 	 * @access public
198 198
 	 */
199 199
 	public function payment_scripts() {
200
-		if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) && ! is_add_payment_method_page() ) {
200
+		if ( ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order']) && ! is_add_payment_method_page()) {
201 201
 			return;
202 202
 		}
203 203
 
204
-		wp_enqueue_style( 'stripe_paymentfonts' );
205
-		wp_enqueue_script( 'woocommerce_stripe' );
204
+		wp_enqueue_style('stripe_paymentfonts');
205
+		wp_enqueue_script('woocommerce_stripe');
206 206
 	}
207 207
 
208 208
 	/**
209 209
 	 * Initialize Gateway Settings Form Fields.
210 210
 	 */
211 211
 	public function init_form_fields() {
212
-		$this->form_fields = require( WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-bitcoin-settings.php' );
212
+		$this->form_fields = require(WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-bitcoin-settings.php');
213 213
 	}
214 214
 
215 215
 	/**
@@ -220,25 +220,25 @@  discard block
 block discarded – undo
220 220
 		$total                = WC()->cart->total;
221 221
 
222 222
 		// If paying from order, we need to get total from order not cart.
223
-		if ( isset( $_GET['pay_for_order'] ) && ! empty( $_GET['key'] ) ) {
224
-			$order = wc_get_order( wc_get_order_id_by_order_key( wc_clean( $_GET['key'] ) ) );
223
+		if (isset($_GET['pay_for_order']) && ! empty($_GET['key'])) {
224
+			$order = wc_get_order(wc_get_order_id_by_order_key(wc_clean($_GET['key'])));
225 225
 			$total = $order->get_total();
226 226
 		}
227 227
 
228
-		if ( is_add_payment_method_page() ) {
229
-			$pay_button_text = __( 'Add Payment', 'woocommerce-gateway-stripe' );
230
-			$total        = '';
228
+		if (is_add_payment_method_page()) {
229
+			$pay_button_text = __('Add Payment', 'woocommerce-gateway-stripe');
230
+			$total = '';
231 231
 		} else {
232 232
 			$pay_button_text = '';
233 233
 		}
234 234
 
235 235
 		echo '<div
236 236
 			id="stripe-bitcoin-payment-data"
237
-			data-amount="' . esc_attr( WC_Stripe_Helper::get_stripe_amount( $total ) ) . '"
238
-			data-currency="' . esc_attr( strtolower( get_woocommerce_currency() ) ) . '">';
237
+			data-amount="' . esc_attr(WC_Stripe_Helper::get_stripe_amount($total)) . '"
238
+			data-currency="' . esc_attr(strtolower(get_woocommerce_currency())) . '">';
239 239
 
240
-		if ( $this->description ) {
241
-			echo apply_filters( 'wc_stripe_description', wpautop( wp_kses_post( $this->description ) ) );
240
+		if ($this->description) {
241
+			echo apply_filters('wc_stripe_description', wpautop(wp_kses_post($this->description)));
242 242
 		}
243 243
 
244 244
 		echo '</div>';
@@ -249,8 +249,8 @@  discard block
 block discarded – undo
249 249
 	 *
250 250
 	 * @param int $order_id
251 251
 	 */
252
-	public function thankyou_page( $order_id ) {
253
-		$this->get_instructions( $order_id );
252
+	public function thankyou_page($order_id) {
253
+		$this->get_instructions($order_id);
254 254
 	}
255 255
 
256 256
 	/**
@@ -262,13 +262,13 @@  discard block
 block discarded – undo
262 262
 	 * @param bool $sent_to_admin
263 263
 	 * @param bool $plain_text
264 264
 	 */
265
-	public function email_instructions( $order, $sent_to_admin, $plain_text = false ) {
265
+	public function email_instructions($order, $sent_to_admin, $plain_text = false) {
266 266
 		$order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
267 267
 
268 268
 		$payment_method = WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method();
269 269
 
270
-		if ( ! $sent_to_admin && 'stripe_bitcoin' === $payment_method && $order->has_status( 'on-hold' ) ) {
271
-			$this->get_instructions( $order_id, $plain_text );
270
+		if ( ! $sent_to_admin && 'stripe_bitcoin' === $payment_method && $order->has_status('on-hold')) {
271
+			$this->get_instructions($order_id, $plain_text);
272 272
 		}
273 273
 	}
274 274
 
@@ -279,38 +279,38 @@  discard block
 block discarded – undo
279 279
 	 * @version 4.0.0
280 280
 	 * @param int $order_id
281 281
 	 */
282
-	public function get_instructions( $order_id, $plain_text = false ) {
283
-		$data = get_post_meta( $order_id, '_stripe_bitcoin', true );
282
+	public function get_instructions($order_id, $plain_text = false) {
283
+		$data = get_post_meta($order_id, '_stripe_bitcoin', true);
284 284
 
285
-		if ( $plain_text ) {
286
-			esc_html_e( 'Please pay the following:', 'woocommerce-gateway-stripe' ) . "\n\n";
285
+		if ($plain_text) {
286
+			esc_html_e('Please pay the following:', 'woocommerce-gateway-stripe') . "\n\n";
287 287
 			echo "=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\n\n";
288
-			esc_html_e( 'Bitcoin Amount:', 'woocommerce-gateway-stripe' ) . "\n\n";
288
+			esc_html_e('Bitcoin Amount:', 'woocommerce-gateway-stripe') . "\n\n";
289 289
 			echo $data['amount'] . "\n\n";
290 290
 			echo "=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\n\n";
291
-			esc_html_e( 'Receiver:', 'woocommerce-gateway-stripe' ) . "\n\n";
291
+			esc_html_e('Receiver:', 'woocommerce-gateway-stripe') . "\n\n";
292 292
 			echo $data['address'] . "\n\n";
293 293
 			echo "=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\n\n";
294
-			esc_html_e( 'URI:', 'woocommerce-gateway-stripe' ) . "\n\n";
294
+			esc_html_e('URI:', 'woocommerce-gateway-stripe') . "\n\n";
295 295
 			echo $data['uri'] . "\n\n";
296 296
 		} else {
297 297
 			?>
298
-			<h3><?php esc_html_e( 'Please pay the following:', 'woocommerce-gateway-stripe' ); ?></h3>
298
+			<h3><?php esc_html_e('Please pay the following:', 'woocommerce-gateway-stripe'); ?></h3>
299 299
 			<ul class="woocommerce-order-overview woocommerce-thankyou-order-details order_details">
300 300
 			<li class="woocommerce-order-overview__order order">
301
-				<?php esc_html_e( 'Bitcoin Amount:', 'woocommerce-gateway-stripe' ); ?>
301
+				<?php esc_html_e('Bitcoin Amount:', 'woocommerce-gateway-stripe'); ?>
302 302
 				<strong><?php echo $data['amount']; ?></strong>
303 303
 			</li>
304 304
 			<li class="woocommerce-order-overview__order order">
305
-				<?php esc_html_e( 'Receiver:', 'woocommerce-gateway-stripe' ); ?>
305
+				<?php esc_html_e('Receiver:', 'woocommerce-gateway-stripe'); ?>
306 306
 				<strong><?php echo $data['address']; ?></strong>
307 307
 			</li>
308 308
 			<li class="woocommerce-order-overview__order order">
309
-				<?php esc_html_e( 'URI:', 'woocommerce-gateway-stripe' ); ?>
309
+				<?php esc_html_e('URI:', 'woocommerce-gateway-stripe'); ?>
310 310
 				<strong>
311 311
 				<?php
312 312
 				/* translators: link */
313
-				printf( __( '<a href="%s">Pay Bitcoin</a>', 'woocommerce-gateway-stripe' ), $data['uri'] );
313
+				printf(__('<a href="%s">Pay Bitcoin</a>', 'woocommerce-gateway-stripe'), $data['uri']);
314 314
 				?>
315 315
 				</strong>
316 316
 			</li>
@@ -327,7 +327,7 @@  discard block
 block discarded – undo
327 327
 	 * @param object $order
328 328
 	 * @param object $source_object
329 329
 	 */
330
-	public function save_instructions( $order, $source_object ) {
330
+	public function save_instructions($order, $source_object) {
331 331
 		$data = array(
332 332
 			'amount'  => $source_object->bitcoin->amount,
333 333
 			'address' => $source_object->bitcoin->address,
@@ -336,7 +336,7 @@  discard block
 block discarded – undo
336 336
 
337 337
 		$order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
338 338
 
339
-		update_post_meta( $order_id, '_stripe_bitcoin', $data );
339
+		update_post_meta($order_id, '_stripe_bitcoin', $data);
340 340
 	}
341 341
 
342 342
 	/**
@@ -350,39 +350,39 @@  discard block
 block discarded – undo
350 350
 	 *
351 351
 	 * @return array|void
352 352
 	 */
353
-	public function process_payment( $order_id, $retry = true, $force_save_source = false ) {
353
+	public function process_payment($order_id, $retry = true, $force_save_source = false) {
354 354
 		try {
355
-			$order = wc_get_order( $order_id );
355
+			$order = wc_get_order($order_id);
356 356
 
357 357
 			// This comes from the create account checkbox in the checkout page.
358
-			$create_account = ! empty( $_POST['createaccount'] ) ? true : false;
358
+			$create_account = ! empty($_POST['createaccount']) ? true : false;
359 359
 
360
-			if ( $create_account ) {
360
+			if ($create_account) {
361 361
 				$new_customer_id     = WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id();
362
-				$new_stripe_customer = new WC_Stripe_Customer( $new_customer_id );
362
+				$new_stripe_customer = new WC_Stripe_Customer($new_customer_id);
363 363
 				$new_stripe_customer->create_customer();
364 364
 			}
365 365
 
366
-			$prepared_source = $this->prepare_source( $this->create_source_object(), get_current_user_id(), $force_save_source );
366
+			$prepared_source = $this->prepare_source($this->create_source_object(), get_current_user_id(), $force_save_source);
367 367
 
368
-			if ( empty( $prepared_source->source ) ) {
369
-				$localized_message = __( 'Payment processing failed. Please retry.', 'woocommerce-gateway-stripe' );
370
-				throw new WC_Stripe_Exception( print_r( $prepared_source, true ), $localized_message );
368
+			if (empty($prepared_source->source)) {
369
+				$localized_message = __('Payment processing failed. Please retry.', 'woocommerce-gateway-stripe');
370
+				throw new WC_Stripe_Exception(print_r($prepared_source, true), $localized_message);
371 371
 			}
372 372
 
373 373
 			// Store source to order meta.
374
-			$this->save_source( $order, $prepared_source );
374
+			$this->save_source($order, $prepared_source);
375 375
 
376 376
 
377 377
 			// This will throw exception if not valid.
378
-			$this->validate_minimum_order_amount( $order );
378
+			$this->validate_minimum_order_amount($order);
379 379
 
380
-			$this->save_instructions( $order, $source_object );
380
+			$this->save_instructions($order, $source_object);
381 381
 
382 382
 			// Mark as on-hold (we're awaiting the payment)
383
-			$order->update_status( 'on-hold', __( 'Awaiting Bitcoin payment', 'woocommerce-gateway-stripe' ) );
383
+			$order->update_status('on-hold', __('Awaiting Bitcoin payment', 'woocommerce-gateway-stripe'));
384 384
 
385
-			wc_reduce_stock_levels( $order_id );
385
+			wc_reduce_stock_levels($order_id);
386 386
 
387 387
 			// Remove cart
388 388
 			WC()->cart->empty_cart();
@@ -390,16 +390,16 @@  discard block
 block discarded – undo
390 390
 			// Return thankyou redirect
391 391
 			return array(
392 392
 				'result'    => 'success',
393
-				'redirect'  => $this->get_return_url( $order ),
393
+				'redirect'  => $this->get_return_url($order),
394 394
 			);
395
-		} catch ( WC_Stripe_Exception $e ) {
396
-			wc_add_notice( $e->getLocalizedMessage(), 'error' );
397
-			WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() );
395
+		} catch (WC_Stripe_Exception $e) {
396
+			wc_add_notice($e->getLocalizedMessage(), 'error');
397
+			WC_Stripe_Logger::log('Error: ' . $e->getMessage());
398 398
 
399
-			do_action( 'wc_gateway_stripe_process_payment_error', $e, $order );
399
+			do_action('wc_gateway_stripe_process_payment_error', $e, $order);
400 400
 
401
-			if ( $order->has_status( array( 'pending', 'failed' ) ) ) {
402
-				$this->send_failed_order_email( $order_id );
401
+			if ($order->has_status(array('pending', 'failed'))) {
402
+				$this->send_failed_order_email($order_id);
403 403
 			}
404 404
 
405 405
 			return array(
Please login to merge, or discard this patch.
includes/compat/class-wc-stripe-compat.php 1 patch
Spacing   +151 added lines, -151 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) {
2
+if ( ! defined('ABSPATH')) {
3 3
 	exit;
4 4
 }
5 5
 
@@ -15,24 +15,24 @@  discard block
 block discarded – undo
15 15
 	public function __construct() {
16 16
 		parent::__construct();
17 17
 
18
-		if ( class_exists( 'WC_Subscriptions_Order' ) ) {
19
-			add_action( 'woocommerce_scheduled_subscription_payment_' . $this->id, array( $this, 'scheduled_subscription_payment' ), 10, 2 );
20
-			add_action( 'wcs_resubscribe_order_created', array( $this, 'delete_resubscribe_meta' ), 10 );
21
-			add_action( 'wcs_renewal_order_created', array( $this, 'delete_renewal_meta' ), 10 );
22
-			add_action( 'woocommerce_subscription_failing_payment_method_updated_stripe', array( $this, 'update_failing_payment_method' ), 10, 2 );
18
+		if (class_exists('WC_Subscriptions_Order')) {
19
+			add_action('woocommerce_scheduled_subscription_payment_' . $this->id, array($this, 'scheduled_subscription_payment'), 10, 2);
20
+			add_action('wcs_resubscribe_order_created', array($this, 'delete_resubscribe_meta'), 10);
21
+			add_action('wcs_renewal_order_created', array($this, 'delete_renewal_meta'), 10);
22
+			add_action('woocommerce_subscription_failing_payment_method_updated_stripe', array($this, 'update_failing_payment_method'), 10, 2);
23 23
 
24 24
 			// display the credit card used for a subscription in the "My Subscriptions" table
25
-			add_filter( 'woocommerce_my_subscriptions_payment_method', array( $this, 'maybe_render_subscription_payment_method' ), 10, 2 );
25
+			add_filter('woocommerce_my_subscriptions_payment_method', array($this, 'maybe_render_subscription_payment_method'), 10, 2);
26 26
 
27 27
 			// allow store managers to manually set Stripe as the payment method on a subscription
28
-			add_filter( 'woocommerce_subscription_payment_meta', array( $this, 'add_subscription_payment_meta' ), 10, 2 );
29
-			add_filter( 'woocommerce_subscription_validate_payment_meta', array( $this, 'validate_subscription_payment_meta' ), 10, 2 );
30
-			add_filter( 'wc_stripe_display_save_payment_method_checkbox', array( $this, 'maybe_hide_save_checkbox' ) );
31
-			add_filter( 'wc_stripe_payment_metadata', array( $this, 'add_subscription_meta_data' ), 10, 2 );
28
+			add_filter('woocommerce_subscription_payment_meta', array($this, 'add_subscription_payment_meta'), 10, 2);
29
+			add_filter('woocommerce_subscription_validate_payment_meta', array($this, 'validate_subscription_payment_meta'), 10, 2);
30
+			add_filter('wc_stripe_display_save_payment_method_checkbox', array($this, 'maybe_hide_save_checkbox'));
31
+			add_filter('wc_stripe_payment_metadata', array($this, 'add_subscription_meta_data'), 10, 2);
32 32
 		}
33 33
 
34
-		if ( class_exists( 'WC_Pre_Orders_Order' ) ) {
35
-			add_action( 'wc_pre_orders_process_pre_order_completion_payment_' . $this->id, array( $this, 'process_pre_order_release_payment' ) );
34
+		if (class_exists('WC_Pre_Orders_Order')) {
35
+			add_action('wc_pre_orders_process_pre_order_completion_payment_' . $this->id, array($this, 'process_pre_order_release_payment'));
36 36
 		}
37 37
 	}
38 38
 
@@ -43,8 +43,8 @@  discard block
 block discarded – undo
43 43
 	 * @since 4.0.0
44 44
 	 * @version 4.0.0
45 45
 	 */
46
-	public function maybe_hide_save_checkbox( $display_tokenization ) {
47
-		if ( WC_Subscriptions_Cart::cart_contains_subscription() ) {
46
+	public function maybe_hide_save_checkbox($display_tokenization) {
47
+		if (WC_Subscriptions_Cart::cart_contains_subscription()) {
48 48
 			return false;
49 49
 		}
50 50
 
@@ -56,8 +56,8 @@  discard block
 block discarded – undo
56 56
 	 * @param  int  $order_id
57 57
 	 * @return boolean
58 58
 	 */
59
-	public function has_subscription( $order_id ) {
60
-		return ( function_exists( 'wcs_order_contains_subscription' ) && ( wcs_order_contains_subscription( $order_id ) || wcs_is_subscription( $order_id ) || wcs_order_contains_renewal( $order_id ) ) );
59
+	public function has_subscription($order_id) {
60
+		return (function_exists('wcs_order_contains_subscription') && (wcs_order_contains_subscription($order_id) || wcs_is_subscription($order_id) || wcs_order_contains_renewal($order_id)));
61 61
 	}
62 62
 
63 63
 	/**
@@ -65,8 +65,8 @@  discard block
 block discarded – undo
65 65
 	 * @param  int  $order_id
66 66
 	 * @return boolean
67 67
 	 */
68
-	protected function is_pre_order( $order_id ) {
69
-		return ( class_exists( 'WC_Pre_Orders_Order' ) && WC_Pre_Orders_Order::order_contains_pre_order( $order_id ) );
68
+	protected function is_pre_order($order_id) {
69
+		return (class_exists('WC_Pre_Orders_Order') && WC_Pre_Orders_Order::order_contains_pre_order($order_id));
70 70
 	}
71 71
 
72 72
 	/**
@@ -74,14 +74,14 @@  discard block
 block discarded – undo
74 74
 	 * @param  int $order_id
75 75
 	 * @return array
76 76
 	 */
77
-	public function process_payment( $order_id, $retry = true, $force_save_source = false ) {
78
-		if ( $this->has_subscription( $order_id ) ) {
77
+	public function process_payment($order_id, $retry = true, $force_save_source = false) {
78
+		if ($this->has_subscription($order_id)) {
79 79
 			// Regular payment with force customer enabled
80
-			return parent::process_payment( $order_id, true, true );
81
-		} elseif ( $this->is_pre_order( $order_id ) ) {
82
-			return $this->process_pre_order( $order_id, $retry, $force_save_source );
80
+			return parent::process_payment($order_id, true, true);
81
+		} elseif ($this->is_pre_order($order_id)) {
82
+			return $this->process_pre_order($order_id, $retry, $force_save_source);
83 83
 		} else {
84
-			return parent::process_payment( $order_id, $retry, $force_save_source );
84
+			return parent::process_payment($order_id, $retry, $force_save_source);
85 85
 		}
86 86
 	}
87 87
 
@@ -92,14 +92,14 @@  discard block
 block discarded – undo
92 92
 	 * @param array $metadata
93 93
 	 * @param object $order
94 94
 	 */
95
-	public function add_subscription_meta_data( $metadata, $order ) {
96
-		if ( ! $this->has_subscription( $order->get_id() ) ) {
95
+	public function add_subscription_meta_data($metadata, $order) {
96
+		if ( ! $this->has_subscription($order->get_id())) {
97 97
 			return $metadata;
98 98
 		}
99 99
 
100 100
 		return $metadata += array(
101 101
 			'payment_type'   => 'recurring',
102
-			'site_url'       => esc_url( get_site_url() ),
102
+			'site_url'       => esc_url(get_site_url()),
103 103
 		);
104 104
 	}
105 105
 
@@ -109,24 +109,24 @@  discard block
 block discarded – undo
109 109
 	 * @since 3.1.0
110 110
 	 * @version 4.0.0
111 111
 	 */
112
-	public function save_source( $order, $source ) {
113
-		parent::save_source( $order, $source );
112
+	public function save_source($order, $source) {
113
+		parent::save_source($order, $source);
114 114
 
115
-		$order_id  = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
115
+		$order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
116 116
 
117 117
 		// Also store it on the subscriptions being purchased or paid for in the order
118
-		if ( function_exists( 'wcs_order_contains_subscription' ) && wcs_order_contains_subscription( $order_id ) ) {
119
-			$subscriptions = wcs_get_subscriptions_for_order( $order_id );
120
-		} elseif ( function_exists( 'wcs_order_contains_renewal' ) && wcs_order_contains_renewal( $order_id ) ) {
121
-			$subscriptions = wcs_get_subscriptions_for_renewal_order( $order_id );
118
+		if (function_exists('wcs_order_contains_subscription') && wcs_order_contains_subscription($order_id)) {
119
+			$subscriptions = wcs_get_subscriptions_for_order($order_id);
120
+		} elseif (function_exists('wcs_order_contains_renewal') && wcs_order_contains_renewal($order_id)) {
121
+			$subscriptions = wcs_get_subscriptions_for_renewal_order($order_id);
122 122
 		} else {
123 123
 			$subscriptions = array();
124 124
 		}
125 125
 
126
-		foreach ( $subscriptions as $subscription ) {
126
+		foreach ($subscriptions as $subscription) {
127 127
 			$subscription_id = WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id();
128
-			update_post_meta( $subscription_id, '_stripe_customer_id', $source->customer );
129
-			update_post_meta( $subscription_id, '_stripe_source_id', $source->source );
128
+			update_post_meta($subscription_id, '_stripe_customer_id', $source->customer);
129
+			update_post_meta($subscription_id, '_stripe_source_id', $source->source);
130 130
 		}
131 131
 	}
132 132
 
@@ -137,37 +137,37 @@  discard block
 block discarded – undo
137 137
 	 * @param string $stripe_token (default: '')
138 138
 	 * @param  bool initial_payment
139 139
 	 */
140
-	public function process_subscription_payment( $order = '', $amount = 0 ) {
141
-		if ( $amount * 100 < WC_Stripe_Helper::get_minimum_amount() ) {
140
+	public function process_subscription_payment($order = '', $amount = 0) {
141
+		if ($amount * 100 < WC_Stripe_Helper::get_minimum_amount()) {
142 142
 			/* translators: minimum amount */
143
-			return new WP_Error( 'stripe_error', sprintf( __( 'Sorry, the minimum allowed order total is %1$s to use this payment method.', 'woocommerce-gateway-stripe' ), wc_price( WC_Stripe_Helper::get_minimum_amount() / 100 ) ) );
143
+			return new WP_Error('stripe_error', sprintf(__('Sorry, the minimum allowed order total is %1$s to use this payment method.', 'woocommerce-gateway-stripe'), wc_price(WC_Stripe_Helper::get_minimum_amount() / 100)));
144 144
 		}
145 145
 
146 146
 		$customer_id = WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id();
147 147
 		$order_id    = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
148 148
 
149 149
 		// Get source from order
150
-		$prepared_source = $this->prepare_order_source( $order );
150
+		$prepared_source = $this->prepare_order_source($order);
151 151
 
152 152
 		// Or fail :(
153
-		if ( ! $prepared_source->customer ) {
154
-			return new WP_Error( 'stripe_error', __( 'Customer not found', 'woocommerce-gateway-stripe' ) );
153
+		if ( ! $prepared_source->customer) {
154
+			return new WP_Error('stripe_error', __('Customer not found', 'woocommerce-gateway-stripe'));
155 155
 		}
156 156
 
157
-		WC_Stripe_Logger::log( "Info: Begin processing subscription payment for order {$order_id} for the amount of {$amount}" );
157
+		WC_Stripe_Logger::log("Info: Begin processing subscription payment for order {$order_id} for the amount of {$amount}");
158 158
 
159 159
 		// Make the request
160
-		$request             = $this->generate_payment_request( $order, $prepared_source );
160
+		$request             = $this->generate_payment_request($order, $prepared_source);
161 161
 		$request['capture']  = 'true';
162
-		$request['amount']   = WC_Stripe_Helper::get_stripe_amount( $amount, $request['currency'] );
163
-		$response            = WC_Stripe_API::request( $request );
162
+		$request['amount']   = WC_Stripe_Helper::get_stripe_amount($amount, $request['currency']);
163
+		$response            = WC_Stripe_API::request($request);
164 164
 
165 165
 		// Process valid response
166
-		if ( ! empty( $response->error ) ) {
166
+		if ( ! empty($response->error)) {
167 167
 			return $response; // Default catch all errors.
168 168
 		}
169 169
 
170
-		$this->process_response( $response, $order );
170
+		$this->process_response($response, $order);
171 171
 
172 172
 		return $response;
173 173
 	}
@@ -176,21 +176,21 @@  discard block
 block discarded – undo
176 176
 	 * Don't transfer Stripe customer/token meta to resubscribe orders.
177 177
 	 * @param int $resubscribe_order The order created for the customer to resubscribe to the old expired/cancelled subscription
178 178
 	 */
179
-	public function delete_resubscribe_meta( $resubscribe_order ) {
180
-		delete_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id() ), '_stripe_customer_id' );
181
-		delete_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id() ), '_stripe_source_id' );
179
+	public function delete_resubscribe_meta($resubscribe_order) {
180
+		delete_post_meta((WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id()), '_stripe_customer_id');
181
+		delete_post_meta((WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id()), '_stripe_source_id');
182 182
 		// For BW compat will remove in future
183
-		delete_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id() ), '_stripe_card_id' );
184
-		$this->delete_renewal_meta( $resubscribe_order );
183
+		delete_post_meta((WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id()), '_stripe_card_id');
184
+		$this->delete_renewal_meta($resubscribe_order);
185 185
 	}
186 186
 
187 187
 	/**
188 188
 	 * Don't transfer Stripe fee/ID meta to renewal orders.
189 189
 	 * @param int $resubscribe_order The order created for the customer to resubscribe to the old expired/cancelled subscription
190 190
 	 */
191
-	public function delete_renewal_meta( $renewal_order ) {
192
-		delete_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $renewal_order->id : $renewal_order->get_id() ), 'Stripe Fee' );
193
-		delete_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $renewal_order->id : $renewal_order->get_id() ), 'Net Revenue From Stripe' );
191
+	public function delete_renewal_meta($renewal_order) {
192
+		delete_post_meta((WC_Stripe_Helper::is_pre_30() ? $renewal_order->id : $renewal_order->get_id()), 'Stripe Fee');
193
+		delete_post_meta((WC_Stripe_Helper::is_pre_30() ? $renewal_order->id : $renewal_order->get_id()), 'Net Revenue From Stripe');
194 194
 		return $renewal_order;
195 195
 	}
196 196
 
@@ -200,17 +200,17 @@  discard block
 block discarded – undo
200 200
 	 * @param $amount_to_charge float The amount to charge.
201 201
 	 * @param $renewal_order WC_Order A WC_Order object created to record the renewal payment.
202 202
 	 */
203
-	public function scheduled_subscription_payment( $amount_to_charge, $renewal_order ) {
204
-		$response = $this->process_subscription_payment( $renewal_order, $amount_to_charge );
203
+	public function scheduled_subscription_payment($amount_to_charge, $renewal_order) {
204
+		$response = $this->process_subscription_payment($renewal_order, $amount_to_charge);
205 205
 
206
-		if ( is_wp_error( $response ) ) {
206
+		if (is_wp_error($response)) {
207 207
 			/* translators: error message */
208
-			$renewal_order->update_status( 'failed', sprintf( __( 'Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe' ), $response->get_error_message() ) );
208
+			$renewal_order->update_status('failed', sprintf(__('Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe'), $response->get_error_message()));
209 209
 		}
210 210
 
211
-		if ( ! empty( $response->error ) ) {
211
+		if ( ! empty($response->error)) {
212 212
 			/* translators: error message */
213
-			$renewal_order->update_status( 'failed', sprintf( __( 'Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe' ), $response->error->message ) );
213
+			$renewal_order->update_status('failed', sprintf(__('Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe'), $response->error->message));
214 214
 		}
215 215
 	}
216 216
 
@@ -218,20 +218,20 @@  discard block
 block discarded – undo
218 218
 	 * Remove order meta
219 219
 	 * @param  object $order
220 220
 	 */
221
-	public function remove_order_source_before_retry( $order ) {
221
+	public function remove_order_source_before_retry($order) {
222 222
 		$order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
223
-		delete_post_meta( $order_id, '_stripe_source_id' );
223
+		delete_post_meta($order_id, '_stripe_source_id');
224 224
 		// For BW compat will remove in the future.
225
-		delete_post_meta( $order_id, '_stripe_card_id' );
225
+		delete_post_meta($order_id, '_stripe_card_id');
226 226
 	}
227 227
 
228 228
 	/**
229 229
 	 * Remove order meta
230 230
 	 * @param  object $order
231 231
 	 */
232
-	public function remove_order_customer_before_retry( $order ) {
232
+	public function remove_order_customer_before_retry($order) {
233 233
 		$order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
234
-		delete_post_meta( $order_id, '_stripe_customer_id' );
234
+		delete_post_meta($order_id, '_stripe_customer_id');
235 235
 	}
236 236
 
237 237
 	/**
@@ -243,14 +243,14 @@  discard block
 block discarded – undo
243 243
 	 * @param WC_Order $renewal_order The order which recorded the successful payment (to make up for the failed automatic payment).
244 244
 	 * @return void
245 245
 	 */
246
-	public function update_failing_payment_method( $subscription, $renewal_order ) {
247
-		if ( WC_Stripe_Helper::is_pre_30() ) {
248
-			update_post_meta( $subscription->id, '_stripe_customer_id', $renewal_order->stripe_customer_id );
249
-			update_post_meta( $subscription->id, '_stripe_source_id', $renewal_order->stripe_source_id );
246
+	public function update_failing_payment_method($subscription, $renewal_order) {
247
+		if (WC_Stripe_Helper::is_pre_30()) {
248
+			update_post_meta($subscription->id, '_stripe_customer_id', $renewal_order->stripe_customer_id);
249
+			update_post_meta($subscription->id, '_stripe_source_id', $renewal_order->stripe_source_id);
250 250
 
251 251
 		} else {
252
-			update_post_meta( $subscription->get_id(), '_stripe_customer_id', $renewal_order->get_meta( '_stripe_customer_id', true ) );
253
-			update_post_meta( $subscription->get_id(), '_stripe_source_id', $renewal_order->get_meta( '_stripe_source_id', true ) );
252
+			update_post_meta($subscription->get_id(), '_stripe_customer_id', $renewal_order->get_meta('_stripe_customer_id', true));
253
+			update_post_meta($subscription->get_id(), '_stripe_source_id', $renewal_order->get_meta('_stripe_source_id', true));
254 254
 		}
255 255
 	}
256 256
 
@@ -263,21 +263,21 @@  discard block
 block discarded – undo
263 263
 	 * @param WC_Subscription $subscription An instance of a subscription object
264 264
 	 * @return array
265 265
 	 */
266
-	public function add_subscription_payment_meta( $payment_meta, $subscription ) {
267
-		$source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_source_id', true );
266
+	public function add_subscription_payment_meta($payment_meta, $subscription) {
267
+		$source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_source_id', true);
268 268
 
269 269
 		// For BW compat will remove in future.
270
-		if ( empty( $source_id ) ) {
271
-			$source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_card_id', true );
270
+		if (empty($source_id)) {
271
+			$source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_card_id', true);
272 272
 
273 273
 			// Take this opportunity to update the key name.
274
-			WC_Stripe_Helper::is_pre_30() ? update_post_meta( $subscription->id, '_stripe_source_id', $source_id ) : update_post_meta( $subscription->get_id(), '_stripe_source_id', $source_id );
274
+			WC_Stripe_Helper::is_pre_30() ? update_post_meta($subscription->id, '_stripe_source_id', $source_id) : update_post_meta($subscription->get_id(), '_stripe_source_id', $source_id);
275 275
 		}
276 276
 
277
-		$payment_meta[ $this->id ] = array(
277
+		$payment_meta[$this->id] = array(
278 278
 			'post_meta' => array(
279 279
 				'_stripe_customer_id' => array(
280
-					'value' => get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_customer_id', true ),
280
+					'value' => get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_customer_id', true),
281 281
 					'label' => 'Stripe Customer ID',
282 282
 				),
283 283
 				'_stripe_source_id' => array(
@@ -299,17 +299,17 @@  discard block
 block discarded – undo
299 299
 	 * @param array $payment_meta associative array of meta data required for automatic payments
300 300
 	 * @return array
301 301
 	 */
302
-	public function validate_subscription_payment_meta( $payment_method_id, $payment_meta ) {
303
-		if ( $this->id === $payment_method_id ) {
302
+	public function validate_subscription_payment_meta($payment_method_id, $payment_meta) {
303
+		if ($this->id === $payment_method_id) {
304 304
 
305
-			if ( ! isset( $payment_meta['post_meta']['_stripe_customer_id']['value'] ) || empty( $payment_meta['post_meta']['_stripe_customer_id']['value'] ) ) {
306
-				throw new Exception( 'A "_stripe_customer_id" value is required.' );
307
-			} elseif ( 0 !== strpos( $payment_meta['post_meta']['_stripe_customer_id']['value'], 'cus_' ) ) {
308
-				throw new Exception( 'Invalid customer ID. A valid "_stripe_customer_id" must begin with "cus_".' );
305
+			if ( ! isset($payment_meta['post_meta']['_stripe_customer_id']['value']) || empty($payment_meta['post_meta']['_stripe_customer_id']['value'])) {
306
+				throw new Exception('A "_stripe_customer_id" value is required.');
307
+			} elseif (0 !== strpos($payment_meta['post_meta']['_stripe_customer_id']['value'], 'cus_')) {
308
+				throw new Exception('Invalid customer ID. A valid "_stripe_customer_id" must begin with "cus_".');
309 309
 			}
310 310
 
311
-			if ( ! isset( $payment_meta['post_meta']['_stripe_source_id']['value'] ) || empty( $payment_meta['post_meta']['_stripe_source_id']['value'] ) ) {
312
-				throw new Exception( 'A "_stripe_source_id" value is required.' );
311
+			if ( ! isset($payment_meta['post_meta']['_stripe_source_id']['value']) || empty($payment_meta['post_meta']['_stripe_source_id']['value'])) {
312
+				throw new Exception('A "_stripe_source_id" value is required.');
313 313
 			}
314 314
 		}
315 315
 	}
@@ -322,89 +322,89 @@  discard block
 block discarded – undo
322 322
 	 * @param WC_Subscription $subscription the subscription details
323 323
 	 * @return string the subscription payment method
324 324
 	 */
325
-	public function maybe_render_subscription_payment_method( $payment_method_to_display, $subscription ) {
325
+	public function maybe_render_subscription_payment_method($payment_method_to_display, $subscription) {
326 326
 		$customer_user = WC_Stripe_Helper::is_pre_30() ? $subscription->customer_user : $subscription->get_customer_id();
327 327
 
328 328
 		// bail for other payment methods
329
-		if ( ( WC_Stripe_Helper::is_pre_30() ? $subscription->payment_method : $subscription->get_payment_method() ) !== $this->id || ! $customer_user ) {
329
+		if ((WC_Stripe_Helper::is_pre_30() ? $subscription->payment_method : $subscription->get_payment_method()) !== $this->id || ! $customer_user) {
330 330
 			return $payment_method_to_display;
331 331
 		}
332 332
 
333
-		$stripe_source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_source_id', true );
333
+		$stripe_source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_source_id', true);
334 334
 
335 335
 		// For BW compat will remove in future.
336
-		if ( empty( $stripe_source_id ) ) {
337
-			$stripe_source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_card_id', true );
336
+		if (empty($stripe_source_id)) {
337
+			$stripe_source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_card_id', true);
338 338
 
339 339
 			// Take this opportunity to update the key name.
340
-			WC_Stripe_Helper::is_pre_30() ? update_post_meta( $subscription->id, '_stripe_source_id', $stripe_source_id ) : update_post_meta( $subscription->get_id(), '_stripe_source_id', $stripe_source_id );
340
+			WC_Stripe_Helper::is_pre_30() ? update_post_meta($subscription->id, '_stripe_source_id', $stripe_source_id) : update_post_meta($subscription->get_id(), '_stripe_source_id', $stripe_source_id);
341 341
 		}
342 342
 
343 343
 		$stripe_customer    = new WC_Stripe_Customer();
344
-		$stripe_customer_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_customer_id', true );
344
+		$stripe_customer_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_customer_id', true);
345 345
 
346 346
 		// If we couldn't find a Stripe customer linked to the subscription, fallback to the user meta data.
347
-		if ( ! $stripe_customer_id || ! is_string( $stripe_customer_id ) ) {
347
+		if ( ! $stripe_customer_id || ! is_string($stripe_customer_id)) {
348 348
 			$user_id            = $customer_user;
349
-			$stripe_customer_id = get_user_meta( $user_id, '_stripe_customer_id', true );
350
-			$stripe_source_id   = get_user_meta( $user_id, '_stripe_source_id', true );
349
+			$stripe_customer_id = get_user_meta($user_id, '_stripe_customer_id', true);
350
+			$stripe_source_id   = get_user_meta($user_id, '_stripe_source_id', true);
351 351
 
352 352
 			// For BW compat will remove in future.
353
-			if ( empty( $stripe_source_id ) ) {
354
-				$stripe_source_id = get_user_meta( $user_id, '_stripe_card_id', true );
353
+			if (empty($stripe_source_id)) {
354
+				$stripe_source_id = get_user_meta($user_id, '_stripe_card_id', true);
355 355
 
356 356
 				// Take this opportunity to update the key name.
357
-				update_user_meta( $user_id, '_stripe_source_id', $stripe_source_id );
357
+				update_user_meta($user_id, '_stripe_source_id', $stripe_source_id);
358 358
 			}
359 359
 		}
360 360
 
361 361
 		// If we couldn't find a Stripe customer linked to the account, fallback to the order meta data.
362
-		if ( ( ! $stripe_customer_id || ! is_string( $stripe_customer_id ) ) && false !== $subscription->order ) {
363
-			$stripe_customer_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id() ), '_stripe_customer_id', true );
364
-			$stripe_source_id   = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id() ), '_stripe_source_id', true );
362
+		if (( ! $stripe_customer_id || ! is_string($stripe_customer_id)) && false !== $subscription->order) {
363
+			$stripe_customer_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id()), '_stripe_customer_id', true);
364
+			$stripe_source_id   = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id()), '_stripe_source_id', true);
365 365
 
366 366
 			// For BW compat will remove in future.
367
-			if ( empty( $stripe_source_id ) ) {
368
-				$stripe_source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id() ), '_stripe_card_id', true );
367
+			if (empty($stripe_source_id)) {
368
+				$stripe_source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id()), '_stripe_card_id', true);
369 369
 
370 370
 				// Take this opportunity to update the key name.
371
-				WC_Stripe_Helper::is_pre_30() ? update_post_meta( $subscription->order->id, '_stripe_source_id', $stripe_source_id ) : update_post_meta( $subscription->get_parent_id(), '_stripe_source_id', $stripe_source_id );
371
+				WC_Stripe_Helper::is_pre_30() ? update_post_meta($subscription->order->id, '_stripe_source_id', $stripe_source_id) : update_post_meta($subscription->get_parent_id(), '_stripe_source_id', $stripe_source_id);
372 372
 			}
373 373
 		}
374 374
 
375
-		$stripe_customer->set_id( $stripe_customer_id );
375
+		$stripe_customer->set_id($stripe_customer_id);
376 376
 		$sources = $stripe_customer->get_sources();
377 377
 
378
-		if ( $sources ) {
378
+		if ($sources) {
379 379
 			$found_source = false;
380
-			foreach ( $sources as $source ) {
381
-				if ( isset( $source->type ) && 'card' === $source->type ) {
380
+			foreach ($sources as $source) {
381
+				if (isset($source->type) && 'card' === $source->type) {
382 382
 					$card = $source->card;
383 383
 				}
384 384
 
385
-				if ( $source->id === $stripe_source_id ) {
385
+				if ($source->id === $stripe_source_id) {
386 386
 					$found_source = true;
387 387
 
388
-					if ( $card ) {
388
+					if ($card) {
389 389
 						/* translators: 1) card brand 2) last 4 digits */
390
-						$payment_method_to_display = sprintf( __( 'Via %1$s card ending in %2$s', 'woocommerce-gateway-stripe' ), ( isset( $card->brand ) ? $card->brand : __( 'N/A', 'woocommerce-gateway-stripe' ) ), $card->last4 );
390
+						$payment_method_to_display = sprintf(__('Via %1$s card ending in %2$s', 'woocommerce-gateway-stripe'), (isset($card->brand) ? $card->brand : __('N/A', 'woocommerce-gateway-stripe')), $card->last4);
391 391
 					} else {
392
-						$payment_method_to_display = __( 'N/A', 'woocommerce-gateway-stripe' );
392
+						$payment_method_to_display = __('N/A', 'woocommerce-gateway-stripe');
393 393
 					}
394 394
 					break;
395 395
 				}
396 396
 			}
397 397
 
398
-			if ( ! $found_source ) {
399
-				if ( 'card' === $sources[0]->type ) {
398
+			if ( ! $found_source) {
399
+				if ('card' === $sources[0]->type) {
400 400
 					$card = $sources[0]->card;
401 401
 				}
402 402
 
403
-				if ( $card ) {
403
+				if ($card) {
404 404
 					/* translators: 1) card brand 2) last 4 digits */
405
-					$payment_method_to_display = sprintf( __( 'Via %1$s card ending in %2$s', 'woocommerce-gateway-stripe' ), ( isset( $card->brand ) ? $card->brand : __( 'N/A', 'woocommerce-gateway-stripe' ) ), $card->last4 );
405
+					$payment_method_to_display = sprintf(__('Via %1$s card ending in %2$s', 'woocommerce-gateway-stripe'), (isset($card->brand) ? $card->brand : __('N/A', 'woocommerce-gateway-stripe')), $card->last4);
406 406
 				} else {
407
-					$payment_method_to_display = __( 'N/A', 'woocommerce-gateway-stripe' );
407
+					$payment_method_to_display = __('N/A', 'woocommerce-gateway-stripe');
408 408
 				}
409 409
 			}
410 410
 		}
@@ -417,43 +417,43 @@  discard block
 block discarded – undo
417 417
 	 * @param int $order_id
418 418
 	 * @return array
419 419
 	 */
420
-	public function process_pre_order( $order_id, $retry, $force_save_source ) {
421
-		if ( WC_Pre_Orders_Order::order_requires_payment_tokenization( $order_id ) ) {
420
+	public function process_pre_order($order_id, $retry, $force_save_source) {
421
+		if (WC_Pre_Orders_Order::order_requires_payment_tokenization($order_id)) {
422 422
 			try {
423
-				$order = wc_get_order( $order_id );
423
+				$order = wc_get_order($order_id);
424 424
 
425
-				if ( $order->get_total() * 100 < WC_Stripe_Helper::get_minimum_amount() ) {
425
+				if ($order->get_total() * 100 < WC_Stripe_Helper::get_minimum_amount()) {
426 426
 					/* translators: minimum amount */
427
-					throw new Exception( sprintf( __( 'Sorry, the minimum allowed order total is %1$s to use this payment method.', 'woocommerce-gateway-stripe' ), wc_price( WC_Stripe_Helper::get_minimum_amount() / 100 ) ) );
427
+					throw new Exception(sprintf(__('Sorry, the minimum allowed order total is %1$s to use this payment method.', 'woocommerce-gateway-stripe'), wc_price(WC_Stripe_Helper::get_minimum_amount() / 100)));
428 428
 				}
429 429
 
430
-				$source = $this->prepare_source( $this->create_source_object(), get_current_user_id(), true );
430
+				$source = $this->prepare_source($this->create_source_object(), get_current_user_id(), true);
431 431
 
432 432
 				// We need a source on file to continue.
433
-				if ( empty( $source->customer ) || empty( $source->source ) ) {
434
-					throw new Exception( __( 'Unable to store payment details. Please try again.', 'woocommerce-gateway-stripe' ) );
433
+				if (empty($source->customer) || empty($source->source)) {
434
+					throw new Exception(__('Unable to store payment details. Please try again.', 'woocommerce-gateway-stripe'));
435 435
 				}
436 436
 
437 437
 				// Store source to order meta
438
-				$this->save_source( $order, $source );
438
+				$this->save_source($order, $source);
439 439
 
440 440
 				// Remove cart
441 441
 				WC()->cart->empty_cart();
442 442
 
443 443
 				// Is pre ordered!
444
-				WC_Pre_Orders_Order::mark_order_as_pre_ordered( $order );
444
+				WC_Pre_Orders_Order::mark_order_as_pre_ordered($order);
445 445
 
446 446
 				// Return thank you page redirect
447 447
 				return array(
448 448
 					'result'   => 'success',
449
-					'redirect' => $this->get_return_url( $order ),
449
+					'redirect' => $this->get_return_url($order),
450 450
 				);
451
-			} catch ( Exception $e ) {
452
-				wc_add_notice( $e->getMessage(), 'error' );
451
+			} catch (Exception $e) {
452
+				wc_add_notice($e->getMessage(), 'error');
453 453
 				return;
454 454
 			}
455 455
 		} else {
456
-			return parent::process_payment( $order_id, $retry, $force_save_source );
456
+			return parent::process_payment($order_id, $retry, $force_save_source);
457 457
 		}
458 458
 	}
459 459
 
@@ -462,7 +462,7 @@  discard block
 block discarded – undo
462 462
 	 * @param WC_Order $order
463 463
 	 * @return void
464 464
 	 */
465
-	public function process_pre_order_release_payment( $order ) {
465
+	public function process_pre_order_release_payment($order) {
466 466
 		try {
467 467
 			// Define some callbacks if the first attempt fails.
468 468
 			$retry_callbacks = array(
@@ -470,33 +470,33 @@  discard block
 block discarded – undo
470 470
 				'remove_order_customer_before_retry',
471 471
 			);
472 472
 
473
-			while ( 1 ) {
474
-				$source   = $this->prepare_order_source( $order );
475
-				$response = WC_Stripe_API::request( $this->generate_payment_request( $order, $source ) );
473
+			while (1) {
474
+				$source   = $this->prepare_order_source($order);
475
+				$response = WC_Stripe_API::request($this->generate_payment_request($order, $source));
476 476
 
477
-				if ( ! empty( $response->error ) ) {
478
-					if ( 0 === sizeof( $retry_callbacks ) ) {
479
-						throw new Exception( $response->error->message );
477
+				if ( ! empty($response->error)) {
478
+					if (0 === sizeof($retry_callbacks)) {
479
+						throw new Exception($response->error->message);
480 480
 					} else {
481
-						$retry_callback = array_shift( $retry_callbacks );
482
-						call_user_func( array( $this, $retry_callback ), $order );
481
+						$retry_callback = array_shift($retry_callbacks);
482
+						call_user_func(array($this, $retry_callback), $order);
483 483
 					}
484 484
 				} else {
485 485
 					// Successful
486
-					$this->process_response( $response, $order );
486
+					$this->process_response($response, $order);
487 487
 					break;
488 488
 				}
489 489
 			}
490
-		} catch ( Exception $e ) {
490
+		} catch (Exception $e) {
491 491
 			/* translators: error message */
492
-			$order_note = sprintf( __( 'Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe' ), $e->getMessage() );
492
+			$order_note = sprintf(__('Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe'), $e->getMessage());
493 493
 
494 494
 			// Mark order as failed if not already set,
495 495
 			// otherwise, make sure we add the order note so we can detect when someone fails to check out multiple times
496
-			if ( ! $order->has_status( 'failed' ) ) {
497
-				$order->update_status( 'failed', $order_note );
496
+			if ( ! $order->has_status('failed')) {
497
+				$order->update_status('failed', $order_note);
498 498
 			} else {
499
-				$order->add_order_note( $order_note );
499
+				$order->add_order_note($order_note);
500 500
 			}
501 501
 		}
502 502
 	}
Please login to merge, or discard this patch.
includes/compat/class-wc-stripe-sepa-compat.php 1 patch
Spacing   +151 added lines, -151 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) {
2
+if ( ! defined('ABSPATH')) {
3 3
 	exit;
4 4
 }
5 5
 
@@ -15,24 +15,24 @@  discard block
 block discarded – undo
15 15
 	public function __construct() {
16 16
 		parent::__construct();
17 17
 
18
-		if ( class_exists( 'WC_Subscriptions_Order' ) ) {
19
-			add_action( 'woocommerce_scheduled_subscription_payment_' . $this->id, array( $this, 'scheduled_subscription_payment' ), 10, 2 );
20
-			add_action( 'wcs_resubscribe_order_created', array( $this, 'delete_resubscribe_meta' ), 10 );
21
-			add_action( 'wcs_renewal_order_created', array( $this, 'delete_renewal_meta' ), 10 );
22
-			add_action( 'woocommerce_subscription_failing_payment_method_updated_stripe', array( $this, 'update_failing_payment_method' ), 10, 2 );
18
+		if (class_exists('WC_Subscriptions_Order')) {
19
+			add_action('woocommerce_scheduled_subscription_payment_' . $this->id, array($this, 'scheduled_subscription_payment'), 10, 2);
20
+			add_action('wcs_resubscribe_order_created', array($this, 'delete_resubscribe_meta'), 10);
21
+			add_action('wcs_renewal_order_created', array($this, 'delete_renewal_meta'), 10);
22
+			add_action('woocommerce_subscription_failing_payment_method_updated_stripe', array($this, 'update_failing_payment_method'), 10, 2);
23 23
 
24 24
 			// display the credit card used for a subscription in the "My Subscriptions" table
25
-			add_filter( 'woocommerce_my_subscriptions_payment_method', array( $this, 'maybe_render_subscription_payment_method' ), 10, 2 );
25
+			add_filter('woocommerce_my_subscriptions_payment_method', array($this, 'maybe_render_subscription_payment_method'), 10, 2);
26 26
 
27 27
 			// allow store managers to manually set Stripe as the payment method on a subscription
28
-			add_filter( 'woocommerce_subscription_payment_meta', array( $this, 'add_subscription_payment_meta' ), 10, 2 );
29
-			add_filter( 'woocommerce_subscription_validate_payment_meta', array( $this, 'validate_subscription_payment_meta' ), 10, 2 );
30
-			add_filter( 'wc_stripe_display_save_payment_method_checkbox', array( $this, 'maybe_hide_save_checkbox' ) );
31
-			add_filter( 'wc_stripe_payment_metadata', array( $this, 'add_subscription_meta_data' ), 10, 2 );
28
+			add_filter('woocommerce_subscription_payment_meta', array($this, 'add_subscription_payment_meta'), 10, 2);
29
+			add_filter('woocommerce_subscription_validate_payment_meta', array($this, 'validate_subscription_payment_meta'), 10, 2);
30
+			add_filter('wc_stripe_display_save_payment_method_checkbox', array($this, 'maybe_hide_save_checkbox'));
31
+			add_filter('wc_stripe_payment_metadata', array($this, 'add_subscription_meta_data'), 10, 2);
32 32
 		}
33 33
 
34
-		if ( class_exists( 'WC_Pre_Orders_Order' ) ) {
35
-			add_action( 'wc_pre_orders_process_pre_order_completion_payment_' . $this->id, array( $this, 'process_pre_order_release_payment' ) );
34
+		if (class_exists('WC_Pre_Orders_Order')) {
35
+			add_action('wc_pre_orders_process_pre_order_completion_payment_' . $this->id, array($this, 'process_pre_order_release_payment'));
36 36
 		}
37 37
 	}
38 38
 
@@ -43,8 +43,8 @@  discard block
 block discarded – undo
43 43
 	 * @since 4.0.0
44 44
 	 * @version 4.0.0
45 45
 	 */
46
-	public function maybe_hide_save_checkbox( $display_tokenization ) {
47
-		if ( WC_Subscriptions_Cart::cart_contains_subscription() ) {
46
+	public function maybe_hide_save_checkbox($display_tokenization) {
47
+		if (WC_Subscriptions_Cart::cart_contains_subscription()) {
48 48
 			return false;
49 49
 		}
50 50
 
@@ -56,8 +56,8 @@  discard block
 block discarded – undo
56 56
 	 * @param  int  $order_id
57 57
 	 * @return boolean
58 58
 	 */
59
-	public function has_subscription( $order_id ) {
60
-		return ( function_exists( 'wcs_order_contains_subscription' ) && ( wcs_order_contains_subscription( $order_id ) || wcs_is_subscription( $order_id ) || wcs_order_contains_renewal( $order_id ) ) );
59
+	public function has_subscription($order_id) {
60
+		return (function_exists('wcs_order_contains_subscription') && (wcs_order_contains_subscription($order_id) || wcs_is_subscription($order_id) || wcs_order_contains_renewal($order_id)));
61 61
 	}
62 62
 
63 63
 	/**
@@ -65,8 +65,8 @@  discard block
 block discarded – undo
65 65
 	 * @param  int  $order_id
66 66
 	 * @return boolean
67 67
 	 */
68
-	protected function is_pre_order( $order_id ) {
69
-		return ( class_exists( 'WC_Pre_Orders_Order' ) && WC_Pre_Orders_Order::order_contains_pre_order( $order_id ) );
68
+	protected function is_pre_order($order_id) {
69
+		return (class_exists('WC_Pre_Orders_Order') && WC_Pre_Orders_Order::order_contains_pre_order($order_id));
70 70
 	}
71 71
 
72 72
 	/**
@@ -74,14 +74,14 @@  discard block
 block discarded – undo
74 74
 	 * @param  int $order_id
75 75
 	 * @return array
76 76
 	 */
77
-	public function process_payment( $order_id, $retry = true, $force_save_source = false ) {
78
-		if ( $this->has_subscription( $order_id ) ) {
77
+	public function process_payment($order_id, $retry = true, $force_save_source = false) {
78
+		if ($this->has_subscription($order_id)) {
79 79
 			// Regular payment with force customer enabled
80
-			return parent::process_payment( $order_id, true, true );
81
-		} elseif ( $this->is_pre_order( $order_id ) ) {
82
-			return $this->process_pre_order( $order_id, $retry, $force_save_source );
80
+			return parent::process_payment($order_id, true, true);
81
+		} elseif ($this->is_pre_order($order_id)) {
82
+			return $this->process_pre_order($order_id, $retry, $force_save_source);
83 83
 		} else {
84
-			return parent::process_payment( $order_id, $retry, $force_save_source );
84
+			return parent::process_payment($order_id, $retry, $force_save_source);
85 85
 		}
86 86
 	}
87 87
 
@@ -92,14 +92,14 @@  discard block
 block discarded – undo
92 92
 	 * @param array $metadata
93 93
 	 * @param object $order
94 94
 	 */
95
-	public function add_subscription_meta_data( $metadata, $order ) {
96
-		if ( ! $this->has_subscription( $order->get_id() ) ) {
95
+	public function add_subscription_meta_data($metadata, $order) {
96
+		if ( ! $this->has_subscription($order->get_id())) {
97 97
 			return $metadata;
98 98
 		}
99 99
 
100 100
 		return $metadata += array(
101 101
 			'payment_type'   => 'recurring',
102
-			'site_url'       => esc_url( get_site_url() ),
102
+			'site_url'       => esc_url(get_site_url()),
103 103
 		);
104 104
 	}
105 105
 
@@ -109,24 +109,24 @@  discard block
 block discarded – undo
109 109
 	 * @since 3.1.0
110 110
 	 * @version 4.0.0
111 111
 	 */
112
-	public function save_source( $order, $source ) {
113
-		parent::save_source( $order, $source );
112
+	public function save_source($order, $source) {
113
+		parent::save_source($order, $source);
114 114
 
115
-		$order_id  = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
115
+		$order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
116 116
 
117 117
 		// Also store it on the subscriptions being purchased or paid for in the order
118
-		if ( function_exists( 'wcs_order_contains_subscription' ) && wcs_order_contains_subscription( $order_id ) ) {
119
-			$subscriptions = wcs_get_subscriptions_for_order( $order_id );
120
-		} elseif ( function_exists( 'wcs_order_contains_renewal' ) && wcs_order_contains_renewal( $order_id ) ) {
121
-			$subscriptions = wcs_get_subscriptions_for_renewal_order( $order_id );
118
+		if (function_exists('wcs_order_contains_subscription') && wcs_order_contains_subscription($order_id)) {
119
+			$subscriptions = wcs_get_subscriptions_for_order($order_id);
120
+		} elseif (function_exists('wcs_order_contains_renewal') && wcs_order_contains_renewal($order_id)) {
121
+			$subscriptions = wcs_get_subscriptions_for_renewal_order($order_id);
122 122
 		} else {
123 123
 			$subscriptions = array();
124 124
 		}
125 125
 
126
-		foreach ( $subscriptions as $subscription ) {
126
+		foreach ($subscriptions as $subscription) {
127 127
 			$subscription_id = WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id();
128
-			update_post_meta( $subscription_id, '_stripe_customer_id', $source->customer );
129
-			update_post_meta( $subscription_id, '_stripe_source_id', $source->source );
128
+			update_post_meta($subscription_id, '_stripe_customer_id', $source->customer);
129
+			update_post_meta($subscription_id, '_stripe_source_id', $source->source);
130 130
 		}
131 131
 	}
132 132
 
@@ -137,37 +137,37 @@  discard block
 block discarded – undo
137 137
 	 * @param string $stripe_token (default: '')
138 138
 	 * @param  bool initial_payment
139 139
 	 */
140
-	public function process_subscription_payment( $order = '', $amount = 0 ) {
141
-		if ( $amount * 100 < WC_Stripe_Helper::get_minimum_amount() ) {
140
+	public function process_subscription_payment($order = '', $amount = 0) {
141
+		if ($amount * 100 < WC_Stripe_Helper::get_minimum_amount()) {
142 142
 			/* translators: minimum amount */
143
-			return new WP_Error( 'stripe_error', sprintf( __( 'Sorry, the minimum allowed order total is %1$s to use this payment method.', 'woocommerce-gateway-stripe' ), wc_price( WC_Stripe_Helper::get_minimum_amount() / 100 ) ) );
143
+			return new WP_Error('stripe_error', sprintf(__('Sorry, the minimum allowed order total is %1$s to use this payment method.', 'woocommerce-gateway-stripe'), wc_price(WC_Stripe_Helper::get_minimum_amount() / 100)));
144 144
 		}
145 145
 
146 146
 		$customer_id = WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id();
147 147
 		$order_id    = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
148 148
 
149 149
 		// Get source from order
150
-		$prepared_source = $this->prepare_order_source( $order );
150
+		$prepared_source = $this->prepare_order_source($order);
151 151
 
152 152
 		// Or fail :(
153
-		if ( ! $prepared_source->customer ) {
154
-			return new WP_Error( 'stripe_error', __( 'Customer not found', 'woocommerce-gateway-stripe' ) );
153
+		if ( ! $prepared_source->customer) {
154
+			return new WP_Error('stripe_error', __('Customer not found', 'woocommerce-gateway-stripe'));
155 155
 		}
156 156
 
157
-		WC_Stripe_Logger::log( "Info: Begin processing subscription payment for order {$order_id} for the amount of {$amount}" );
157
+		WC_Stripe_Logger::log("Info: Begin processing subscription payment for order {$order_id} for the amount of {$amount}");
158 158
 
159 159
 		// Make the request
160
-		$request             = $this->generate_payment_request( $order, $prepared_source );
160
+		$request             = $this->generate_payment_request($order, $prepared_source);
161 161
 		$request['capture']  = 'true';
162
-		$request['amount']   = WC_Stripe_Helper::get_stripe_amount( $amount, $request['currency'] );
163
-		$response            = WC_Stripe_API::request( $request );
162
+		$request['amount']   = WC_Stripe_Helper::get_stripe_amount($amount, $request['currency']);
163
+		$response            = WC_Stripe_API::request($request);
164 164
 
165 165
 		// Process valid response
166
-		if ( ! empty( $response->error ) ) {
166
+		if ( ! empty($response->error)) {
167 167
 			return $response; // Default catch all errors.
168 168
 		}
169 169
 
170
-		$this->process_response( $response, $order );
170
+		$this->process_response($response, $order);
171 171
 
172 172
 		return $response;
173 173
 	}
@@ -176,21 +176,21 @@  discard block
 block discarded – undo
176 176
 	 * Don't transfer Stripe customer/token meta to resubscribe orders.
177 177
 	 * @param int $resubscribe_order The order created for the customer to resubscribe to the old expired/cancelled subscription
178 178
 	 */
179
-	public function delete_resubscribe_meta( $resubscribe_order ) {
180
-		delete_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id() ), '_stripe_customer_id' );
181
-		delete_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id() ), '_stripe_source_id' );
179
+	public function delete_resubscribe_meta($resubscribe_order) {
180
+		delete_post_meta((WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id()), '_stripe_customer_id');
181
+		delete_post_meta((WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id()), '_stripe_source_id');
182 182
 		// For BW compat will remove in future
183
-		delete_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id() ), '_stripe_card_id' );
184
-		$this->delete_renewal_meta( $resubscribe_order );
183
+		delete_post_meta((WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id()), '_stripe_card_id');
184
+		$this->delete_renewal_meta($resubscribe_order);
185 185
 	}
186 186
 
187 187
 	/**
188 188
 	 * Don't transfer Stripe fee/ID meta to renewal orders.
189 189
 	 * @param int $resubscribe_order The order created for the customer to resubscribe to the old expired/cancelled subscription
190 190
 	 */
191
-	public function delete_renewal_meta( $renewal_order ) {
192
-		delete_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $renewal_order->id : $renewal_order->get_id() ), 'Stripe Fee' );
193
-		delete_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $renewal_order->id : $renewal_order->get_id() ), 'Net Revenue From Stripe' );
191
+	public function delete_renewal_meta($renewal_order) {
192
+		delete_post_meta((WC_Stripe_Helper::is_pre_30() ? $renewal_order->id : $renewal_order->get_id()), 'Stripe Fee');
193
+		delete_post_meta((WC_Stripe_Helper::is_pre_30() ? $renewal_order->id : $renewal_order->get_id()), 'Net Revenue From Stripe');
194 194
 		return $renewal_order;
195 195
 	}
196 196
 
@@ -200,17 +200,17 @@  discard block
 block discarded – undo
200 200
 	 * @param $amount_to_charge float The amount to charge.
201 201
 	 * @param $renewal_order WC_Order A WC_Order object created to record the renewal payment.
202 202
 	 */
203
-	public function scheduled_subscription_payment( $amount_to_charge, $renewal_order ) {
204
-		$response = $this->process_subscription_payment( $renewal_order, $amount_to_charge );
203
+	public function scheduled_subscription_payment($amount_to_charge, $renewal_order) {
204
+		$response = $this->process_subscription_payment($renewal_order, $amount_to_charge);
205 205
 
206
-		if ( is_wp_error( $response ) ) {
206
+		if (is_wp_error($response)) {
207 207
 			/* translators: error message */
208
-			$renewal_order->update_status( 'failed', sprintf( __( 'Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe' ), $response->get_error_message() ) );
208
+			$renewal_order->update_status('failed', sprintf(__('Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe'), $response->get_error_message()));
209 209
 		}
210 210
 
211
-		if ( ! empty( $response->error ) ) {
211
+		if ( ! empty($response->error)) {
212 212
 			/* translators: error message */
213
-			$renewal_order->update_status( 'failed', sprintf( __( 'Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe' ), $response->error->message ) );
213
+			$renewal_order->update_status('failed', sprintf(__('Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe'), $response->error->message));
214 214
 		}
215 215
 	}
216 216
 
@@ -218,20 +218,20 @@  discard block
 block discarded – undo
218 218
 	 * Remove order meta
219 219
 	 * @param  object $order
220 220
 	 */
221
-	public function remove_order_source_before_retry( $order ) {
221
+	public function remove_order_source_before_retry($order) {
222 222
 		$order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
223
-		delete_post_meta( $order_id, '_stripe_source_id' );
223
+		delete_post_meta($order_id, '_stripe_source_id');
224 224
 		// For BW compat will remove in the future.
225
-		delete_post_meta( $order_id, '_stripe_card_id' );
225
+		delete_post_meta($order_id, '_stripe_card_id');
226 226
 	}
227 227
 
228 228
 	/**
229 229
 	 * Remove order meta
230 230
 	 * @param  object $order
231 231
 	 */
232
-	public function remove_order_customer_before_retry( $order ) {
232
+	public function remove_order_customer_before_retry($order) {
233 233
 		$order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
234
-		delete_post_meta( $order_id, '_stripe_customer_id' );
234
+		delete_post_meta($order_id, '_stripe_customer_id');
235 235
 	}
236 236
 
237 237
 	/**
@@ -243,14 +243,14 @@  discard block
 block discarded – undo
243 243
 	 * @param WC_Order $renewal_order The order which recorded the successful payment (to make up for the failed automatic payment).
244 244
 	 * @return void
245 245
 	 */
246
-	public function update_failing_payment_method( $subscription, $renewal_order ) {
247
-		if ( WC_Stripe_Helper::is_pre_30() ) {
248
-			update_post_meta( $subscription->id, '_stripe_customer_id', $renewal_order->stripe_customer_id );
249
-			update_post_meta( $subscription->id, '_stripe_source_id', $renewal_order->stripe_source_id );
246
+	public function update_failing_payment_method($subscription, $renewal_order) {
247
+		if (WC_Stripe_Helper::is_pre_30()) {
248
+			update_post_meta($subscription->id, '_stripe_customer_id', $renewal_order->stripe_customer_id);
249
+			update_post_meta($subscription->id, '_stripe_source_id', $renewal_order->stripe_source_id);
250 250
 
251 251
 		} else {
252
-			update_post_meta( $subscription->get_id(), '_stripe_customer_id', $renewal_order->get_meta( '_stripe_customer_id', true ) );
253
-			update_post_meta( $subscription->get_id(), '_stripe_source_id', $renewal_order->get_meta( '_stripe_source_id', true ) );
252
+			update_post_meta($subscription->get_id(), '_stripe_customer_id', $renewal_order->get_meta('_stripe_customer_id', true));
253
+			update_post_meta($subscription->get_id(), '_stripe_source_id', $renewal_order->get_meta('_stripe_source_id', true));
254 254
 		}
255 255
 	}
256 256
 
@@ -263,21 +263,21 @@  discard block
 block discarded – undo
263 263
 	 * @param WC_Subscription $subscription An instance of a subscription object
264 264
 	 * @return array
265 265
 	 */
266
-	public function add_subscription_payment_meta( $payment_meta, $subscription ) {
267
-		$source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_source_id', true );
266
+	public function add_subscription_payment_meta($payment_meta, $subscription) {
267
+		$source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_source_id', true);
268 268
 
269 269
 		// For BW compat will remove in future.
270
-		if ( empty( $source_id ) ) {
271
-			$source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_card_id', true );
270
+		if (empty($source_id)) {
271
+			$source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_card_id', true);
272 272
 
273 273
 			// Take this opportunity to update the key name.
274
-			WC_Stripe_Helper::is_pre_30() ? update_post_meta( $subscription->id, '_stripe_source_id', $source_id ) : update_post_meta( $subscription->get_id(), '_stripe_source_id', $source_id );
274
+			WC_Stripe_Helper::is_pre_30() ? update_post_meta($subscription->id, '_stripe_source_id', $source_id) : update_post_meta($subscription->get_id(), '_stripe_source_id', $source_id);
275 275
 		}
276 276
 
277
-		$payment_meta[ $this->id ] = array(
277
+		$payment_meta[$this->id] = array(
278 278
 			'post_meta' => array(
279 279
 				'_stripe_customer_id' => array(
280
-					'value' => get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_customer_id', true ),
280
+					'value' => get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_customer_id', true),
281 281
 					'label' => 'Stripe Customer ID',
282 282
 				),
283 283
 				'_stripe_source_id' => array(
@@ -298,17 +298,17 @@  discard block
 block discarded – undo
298 298
 	 * @param array $payment_meta associative array of meta data required for automatic payments
299 299
 	 * @return array
300 300
 	 */
301
-	public function validate_subscription_payment_meta( $payment_method_id, $payment_meta ) {
302
-		if ( $this->id === $payment_method_id ) {
301
+	public function validate_subscription_payment_meta($payment_method_id, $payment_meta) {
302
+		if ($this->id === $payment_method_id) {
303 303
 
304
-			if ( ! isset( $payment_meta['post_meta']['_stripe_customer_id']['value'] ) || empty( $payment_meta['post_meta']['_stripe_customer_id']['value'] ) ) {
305
-				throw new Exception( 'A "_stripe_customer_id" value is required.' );
306
-			} elseif ( 0 !== strpos( $payment_meta['post_meta']['_stripe_customer_id']['value'], 'cus_' ) ) {
307
-				throw new Exception( 'Invalid customer ID. A valid "_stripe_customer_id" must begin with "cus_".' );
304
+			if ( ! isset($payment_meta['post_meta']['_stripe_customer_id']['value']) || empty($payment_meta['post_meta']['_stripe_customer_id']['value'])) {
305
+				throw new Exception('A "_stripe_customer_id" value is required.');
306
+			} elseif (0 !== strpos($payment_meta['post_meta']['_stripe_customer_id']['value'], 'cus_')) {
307
+				throw new Exception('Invalid customer ID. A valid "_stripe_customer_id" must begin with "cus_".');
308 308
 			}
309 309
 
310
-			if ( ! isset( $payment_meta['post_meta']['_stripe_source_id']['value'] ) || empty( $payment_meta['post_meta']['_stripe_source_id']['value'] ) ) {
311
-				throw new Exception( 'A "_stripe_source_id" value is required.' );
310
+			if ( ! isset($payment_meta['post_meta']['_stripe_source_id']['value']) || empty($payment_meta['post_meta']['_stripe_source_id']['value'])) {
311
+				throw new Exception('A "_stripe_source_id" value is required.');
312 312
 			}
313 313
 		}
314 314
 	}
@@ -321,89 +321,89 @@  discard block
 block discarded – undo
321 321
 	 * @param WC_Subscription $subscription the subscription details
322 322
 	 * @return string the subscription payment method
323 323
 	 */
324
-	public function maybe_render_subscription_payment_method( $payment_method_to_display, $subscription ) {
324
+	public function maybe_render_subscription_payment_method($payment_method_to_display, $subscription) {
325 325
 		$customer_user = WC_Stripe_Helper::is_pre_30() ? $subscription->customer_user : $subscription->get_customer_id();
326 326
 
327 327
 		// bail for other payment methods
328
-		if ( ( WC_Stripe_Helper::is_pre_30() ? $subscription->payment_method : $subscription->get_payment_method() ) !== $this->id || ! $customer_user ) {
328
+		if ((WC_Stripe_Helper::is_pre_30() ? $subscription->payment_method : $subscription->get_payment_method()) !== $this->id || ! $customer_user) {
329 329
 			return $payment_method_to_display;
330 330
 		}
331 331
 
332
-		$stripe_source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_source_id', true );
332
+		$stripe_source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_source_id', true);
333 333
 
334 334
 		// For BW compat will remove in future.
335
-		if ( empty( $stripe_source_id ) ) {
336
-			$stripe_source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_card_id', true );
335
+		if (empty($stripe_source_id)) {
336
+			$stripe_source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_card_id', true);
337 337
 
338 338
 			// Take this opportunity to update the key name.
339
-			WC_Stripe_Helper::is_pre_30() ? update_post_meta( $subscription->id, '_stripe_source_id', $stripe_source_id ) : update_post_meta( $subscription->get_id(), '_stripe_source_id', $stripe_source_id );
339
+			WC_Stripe_Helper::is_pre_30() ? update_post_meta($subscription->id, '_stripe_source_id', $stripe_source_id) : update_post_meta($subscription->get_id(), '_stripe_source_id', $stripe_source_id);
340 340
 		}
341 341
 
342 342
 		$stripe_customer    = new WC_Stripe_Customer();
343
-		$stripe_customer_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_customer_id', true );
343
+		$stripe_customer_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_customer_id', true);
344 344
 
345 345
 		// If we couldn't find a Stripe customer linked to the subscription, fallback to the user meta data.
346
-		if ( ! $stripe_customer_id || ! is_string( $stripe_customer_id ) ) {
346
+		if ( ! $stripe_customer_id || ! is_string($stripe_customer_id)) {
347 347
 			$user_id            = $customer_user;
348
-			$stripe_customer_id = get_user_meta( $user_id, '_stripe_customer_id', true );
349
-			$stripe_source_id   = get_user_meta( $user_id, '_stripe_source_id', true );
348
+			$stripe_customer_id = get_user_meta($user_id, '_stripe_customer_id', true);
349
+			$stripe_source_id   = get_user_meta($user_id, '_stripe_source_id', true);
350 350
 
351 351
 			// For BW compat will remove in future.
352
-			if ( empty( $stripe_source_id ) ) {
353
-				$stripe_source_id = get_user_meta( $user_id, '_stripe_card_id', true );
352
+			if (empty($stripe_source_id)) {
353
+				$stripe_source_id = get_user_meta($user_id, '_stripe_card_id', true);
354 354
 
355 355
 				// Take this opportunity to update the key name.
356
-				update_user_meta( $user_id, '_stripe_source_id', $stripe_source_id );
356
+				update_user_meta($user_id, '_stripe_source_id', $stripe_source_id);
357 357
 			}
358 358
 		}
359 359
 
360 360
 		// If we couldn't find a Stripe customer linked to the account, fallback to the order meta data.
361
-		if ( ( ! $stripe_customer_id || ! is_string( $stripe_customer_id ) ) && false !== $subscription->order ) {
362
-			$stripe_customer_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id() ), '_stripe_customer_id', true );
363
-			$stripe_source_id   = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id() ), '_stripe_source_id', true );
361
+		if (( ! $stripe_customer_id || ! is_string($stripe_customer_id)) && false !== $subscription->order) {
362
+			$stripe_customer_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id()), '_stripe_customer_id', true);
363
+			$stripe_source_id   = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id()), '_stripe_source_id', true);
364 364
 
365 365
 			// For BW compat will remove in future.
366
-			if ( empty( $stripe_source_id ) ) {
367
-				$stripe_source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id() ), '_stripe_card_id', true );
366
+			if (empty($stripe_source_id)) {
367
+				$stripe_source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id()), '_stripe_card_id', true);
368 368
 
369 369
 				// Take this opportunity to update the key name.
370
-				WC_Stripe_Helper::is_pre_30() ? update_post_meta( $subscription->order->id, '_stripe_source_id', $stripe_source_id ) : update_post_meta( $subscription->get_parent_id(), '_stripe_source_id', $stripe_source_id );
370
+				WC_Stripe_Helper::is_pre_30() ? update_post_meta($subscription->order->id, '_stripe_source_id', $stripe_source_id) : update_post_meta($subscription->get_parent_id(), '_stripe_source_id', $stripe_source_id);
371 371
 			}
372 372
 		}
373 373
 
374
-		$stripe_customer->set_id( $stripe_customer_id );
374
+		$stripe_customer->set_id($stripe_customer_id);
375 375
 		$sources = $stripe_customer->get_sources();
376 376
 
377
-		if ( $sources ) {
377
+		if ($sources) {
378 378
 			$found_source = false;
379
-			foreach ( $sources as $source ) {
380
-				if ( isset( $source->type ) && 'card' === $source->type ) {
379
+			foreach ($sources as $source) {
380
+				if (isset($source->type) && 'card' === $source->type) {
381 381
 					$card = $source->card;
382 382
 				}
383 383
 
384
-				if ( $source->id === $stripe_source_id ) {
384
+				if ($source->id === $stripe_source_id) {
385 385
 					$found_source = true;
386 386
 
387
-					if ( $card ) {
387
+					if ($card) {
388 388
 						/* translators: 1) card brand 2) last 4 digits */
389
-						$payment_method_to_display = sprintf( __( 'Via %1$s card ending in %2$s', 'woocommerce-gateway-stripe' ), ( isset( $card->brand ) ? $card->brand : __( 'N/A', 'woocommerce-gateway-stripe' ) ), $card->last4 );
389
+						$payment_method_to_display = sprintf(__('Via %1$s card ending in %2$s', 'woocommerce-gateway-stripe'), (isset($card->brand) ? $card->brand : __('N/A', 'woocommerce-gateway-stripe')), $card->last4);
390 390
 					} else {
391
-						$payment_method_to_display = __( 'N/A', 'woocommerce-gateway-stripe' );
391
+						$payment_method_to_display = __('N/A', 'woocommerce-gateway-stripe');
392 392
 					}
393 393
 					break;
394 394
 				}
395 395
 			}
396 396
 
397
-			if ( ! $found_source ) {
398
-				if ( 'card' === $sources[0]->type ) {
397
+			if ( ! $found_source) {
398
+				if ('card' === $sources[0]->type) {
399 399
 					$card = $sources[0]->card;
400 400
 				}
401 401
 
402
-				if ( $card ) {
402
+				if ($card) {
403 403
 					/* translators: 1) card brand 2) last 4 digits */
404
-					$payment_method_to_display = sprintf( __( 'Via %1$s card ending in %2$s', 'woocommerce-gateway-stripe' ), ( isset( $card->brand ) ? $card->brand : __( 'N/A', 'woocommerce-gateway-stripe' ) ), $card->last4 );
404
+					$payment_method_to_display = sprintf(__('Via %1$s card ending in %2$s', 'woocommerce-gateway-stripe'), (isset($card->brand) ? $card->brand : __('N/A', 'woocommerce-gateway-stripe')), $card->last4);
405 405
 				} else {
406
-					$payment_method_to_display = __( 'N/A', 'woocommerce-gateway-stripe' );
406
+					$payment_method_to_display = __('N/A', 'woocommerce-gateway-stripe');
407 407
 				}
408 408
 			}
409 409
 		}
@@ -416,43 +416,43 @@  discard block
 block discarded – undo
416 416
 	 * @param int $order_id
417 417
 	 * @return array
418 418
 	 */
419
-	public function process_pre_order( $order_id, $retry, $force_save_source ) {
420
-		if ( WC_Pre_Orders_Order::order_requires_payment_tokenization( $order_id ) ) {
419
+	public function process_pre_order($order_id, $retry, $force_save_source) {
420
+		if (WC_Pre_Orders_Order::order_requires_payment_tokenization($order_id)) {
421 421
 			try {
422
-				$order = wc_get_order( $order_id );
422
+				$order = wc_get_order($order_id);
423 423
 
424
-				if ( $order->get_total() * 100 < WC_Stripe_Helper::get_minimum_amount() ) {
424
+				if ($order->get_total() * 100 < WC_Stripe_Helper::get_minimum_amount()) {
425 425
 					/* translators: minimum amount */
426
-					throw new Exception( sprintf( __( 'Sorry, the minimum allowed order total is %1$s to use this payment method.', 'woocommerce-gateway-stripe' ), wc_price( WC_Stripe_Helper::get_minimum_amount() / 100 ) ) );
426
+					throw new Exception(sprintf(__('Sorry, the minimum allowed order total is %1$s to use this payment method.', 'woocommerce-gateway-stripe'), wc_price(WC_Stripe_Helper::get_minimum_amount() / 100)));
427 427
 				}
428 428
 
429
-				$source = $this->prepare_source( $this->create_source_object(), get_current_user_id(), true );
429
+				$source = $this->prepare_source($this->create_source_object(), get_current_user_id(), true);
430 430
 
431 431
 				// We need a source on file to continue.
432
-				if ( empty( $source->customer ) || empty( $source->source ) ) {
433
-					throw new Exception( __( 'Unable to store payment details. Please try again.', 'woocommerce-gateway-stripe' ) );
432
+				if (empty($source->customer) || empty($source->source)) {
433
+					throw new Exception(__('Unable to store payment details. Please try again.', 'woocommerce-gateway-stripe'));
434 434
 				}
435 435
 
436 436
 				// Store source to order meta
437
-				$this->save_source( $order, $source );
437
+				$this->save_source($order, $source);
438 438
 
439 439
 				// Remove cart
440 440
 				WC()->cart->empty_cart();
441 441
 
442 442
 				// Is pre ordered!
443
-				WC_Pre_Orders_Order::mark_order_as_pre_ordered( $order );
443
+				WC_Pre_Orders_Order::mark_order_as_pre_ordered($order);
444 444
 
445 445
 				// Return thank you page redirect
446 446
 				return array(
447 447
 					'result'   => 'success',
448
-					'redirect' => $this->get_return_url( $order ),
448
+					'redirect' => $this->get_return_url($order),
449 449
 				);
450
-			} catch ( Exception $e ) {
451
-				wc_add_notice( $e->getMessage(), 'error' );
450
+			} catch (Exception $e) {
451
+				wc_add_notice($e->getMessage(), 'error');
452 452
 				return;
453 453
 			}
454 454
 		} else {
455
-			return parent::process_payment( $order_id, $retry, $force_save_source );
455
+			return parent::process_payment($order_id, $retry, $force_save_source);
456 456
 		}
457 457
 	}
458 458
 
@@ -461,7 +461,7 @@  discard block
 block discarded – undo
461 461
 	 * @param WC_Order $order
462 462
 	 * @return void
463 463
 	 */
464
-	public function process_pre_order_release_payment( $order ) {
464
+	public function process_pre_order_release_payment($order) {
465 465
 		try {
466 466
 			// Define some callbacks if the first attempt fails.
467 467
 			$retry_callbacks = array(
@@ -469,33 +469,33 @@  discard block
 block discarded – undo
469 469
 				'remove_order_customer_before_retry',
470 470
 			);
471 471
 
472
-			while ( 1 ) {
473
-				$source   = $this->prepare_order_source( $order );
474
-				$response = WC_Stripe_API::request( $this->generate_payment_request( $order, $source ) );
472
+			while (1) {
473
+				$source   = $this->prepare_order_source($order);
474
+				$response = WC_Stripe_API::request($this->generate_payment_request($order, $source));
475 475
 
476
-				if ( ! empty( $response->error ) ) {
477
-					if ( 0 === sizeof( $retry_callbacks ) ) {
478
-						throw new Exception( $response->error->message );
476
+				if ( ! empty($response->error)) {
477
+					if (0 === sizeof($retry_callbacks)) {
478
+						throw new Exception($response->error->message);
479 479
 					} else {
480
-						$retry_callback = array_shift( $retry_callbacks );
481
-						call_user_func( array( $this, $retry_callback ), $order );
480
+						$retry_callback = array_shift($retry_callbacks);
481
+						call_user_func(array($this, $retry_callback), $order);
482 482
 					}
483 483
 				} else {
484 484
 					// Successful
485
-					$this->process_response( $response, $order );
485
+					$this->process_response($response, $order);
486 486
 					break;
487 487
 				}
488 488
 			}
489
-		} catch ( Exception $e ) {
489
+		} catch (Exception $e) {
490 490
 			/* translators: error message */
491
-			$order_note = sprintf( __( 'Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe' ), $e->getMessage() );
491
+			$order_note = sprintf(__('Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe'), $e->getMessage());
492 492
 
493 493
 			// Mark order as failed if not already set,
494 494
 			// otherwise, make sure we add the order note so we can detect when someone fails to check out multiple times
495
-			if ( ! $order->has_status( 'failed' ) ) {
496
-				$order->update_status( 'failed', $order_note );
495
+			if ( ! $order->has_status('failed')) {
496
+				$order->update_status('failed', $order_note);
497 497
 			} else {
498
-				$order->add_order_note( $order_note );
498
+				$order->add_order_note($order_note);
499 499
 			}
500 500
 		}
501 501
 	}
Please login to merge, or discard this patch.