Completed
Pull Request — master (#541)
by Roy
02:10
created
includes/payment-methods/class-wc-gateway-stripe-bitcoin.php 1 patch
Spacing   +91 added lines, -91 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
 	}
@@ -136,12 +136,12 @@  discard block
 block discarded – undo
136 136
 	 */
137 137
 	public function get_environment_warning() {
138 138
 		// Add deprecated notice to logs.
139
-		if ( 'yes' === $this->enabled ) {
140
-			WC_Stripe_Logger::log( 'DEPRECATED! Stripe will no longer support Bitcoin and will cease to function on April 23, 2018. Please plan accordingly.' );
139
+		if ('yes' === $this->enabled) {
140
+			WC_Stripe_Logger::log('DEPRECATED! Stripe will no longer support Bitcoin and will cease to function on April 23, 2018. Please plan accordingly.');
141 141
 		}
142 142
 
143
-		if ( 'yes' === $this->enabled && ! in_array( get_woocommerce_currency(), $this->get_supported_currency() ) ) {
144
-			$message = __( 'Bitcoin is enabled - it requires store currency to be set to USD.', 'woocommerce-gateway-stripe' );
143
+		if ('yes' === $this->enabled && ! in_array(get_woocommerce_currency(), $this->get_supported_currency())) {
144
+			$message = __('Bitcoin is enabled - it requires store currency to be set to USD.', 'woocommerce-gateway-stripe');
145 145
 
146 146
 			return $message;
147 147
 		}
@@ -157,9 +157,9 @@  discard block
 block discarded – undo
157 157
 	 * @return array
158 158
 	 */
159 159
 	public function get_supported_currency() {
160
-		return apply_filters( 'wc_stripe_bitcoin_supported_currencies', array(
160
+		return apply_filters('wc_stripe_bitcoin_supported_currencies', array(
161 161
 			'USD',
162
-		) );
162
+		));
163 163
 	}
164 164
 
165 165
 	/**
@@ -170,7 +170,7 @@  discard block
 block discarded – undo
170 170
 	 * @return bool
171 171
 	 */
172 172
 	public function is_available() {
173
-		if ( ! in_array( get_woocommerce_currency(), $this->get_supported_currency() ) ) {
173
+		if ( ! in_array(get_woocommerce_currency(), $this->get_supported_currency())) {
174 174
 			return false;
175 175
 		}
176 176
 
@@ -191,7 +191,7 @@  discard block
 block discarded – undo
191 191
 
192 192
 		$icons_str .= $icons['bitcoin'];
193 193
 
194
-		return apply_filters( 'woocommerce_gateway_icon', $icons_str, $this->id );
194
+		return apply_filters('woocommerce_gateway_icon', $icons_str, $this->id);
195 195
 	}
196 196
 
197 197
 	/**
@@ -202,19 +202,19 @@  discard block
 block discarded – undo
202 202
 	 * @access public
203 203
 	 */
204 204
 	public function payment_scripts() {
205
-		if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) && ! is_add_payment_method_page() ) {
205
+		if ( ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order']) && ! is_add_payment_method_page()) {
206 206
 			return;
207 207
 		}
208 208
 
209
-		wp_enqueue_style( 'stripe_paymentfonts' );
210
-		wp_enqueue_script( 'woocommerce_stripe' );
209
+		wp_enqueue_style('stripe_paymentfonts');
210
+		wp_enqueue_script('woocommerce_stripe');
211 211
 	}
212 212
 
213 213
 	/**
214 214
 	 * Initialize Gateway Settings Form Fields.
215 215
 	 */
216 216
 	public function init_form_fields() {
217
-		$this->form_fields = require( WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-bitcoin-settings.php' );
217
+		$this->form_fields = require(WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-bitcoin-settings.php');
218 218
 	}
219 219
 
220 220
 	/**
@@ -225,25 +225,25 @@  discard block
 block discarded – undo
225 225
 		$total                = WC()->cart->total;
226 226
 
227 227
 		// If paying from order, we need to get total from order not cart.
228
-		if ( isset( $_GET['pay_for_order'] ) && ! empty( $_GET['key'] ) ) {
229
-			$order = wc_get_order( wc_get_order_id_by_order_key( wc_clean( $_GET['key'] ) ) );
228
+		if (isset($_GET['pay_for_order']) && ! empty($_GET['key'])) {
229
+			$order = wc_get_order(wc_get_order_id_by_order_key(wc_clean($_GET['key'])));
230 230
 			$total = $order->get_total();
231 231
 		}
232 232
 
233
-		if ( is_add_payment_method_page() ) {
234
-			$pay_button_text = __( 'Add Payment', 'woocommerce-gateway-stripe' );
235
-			$total        = '';
233
+		if (is_add_payment_method_page()) {
234
+			$pay_button_text = __('Add Payment', 'woocommerce-gateway-stripe');
235
+			$total = '';
236 236
 		} else {
237 237
 			$pay_button_text = '';
238 238
 		}
239 239
 
240 240
 		echo '<div
241 241
 			id="stripe-bitcoin-payment-data"
242
-			data-amount="' . esc_attr( WC_Stripe_Helper::get_stripe_amount( $total ) ) . '"
243
-			data-currency="' . esc_attr( strtolower( get_woocommerce_currency() ) ) . '">';
242
+			data-amount="' . esc_attr(WC_Stripe_Helper::get_stripe_amount($total)) . '"
243
+			data-currency="' . esc_attr(strtolower(get_woocommerce_currency())) . '">';
244 244
 
245
-		if ( $this->description ) {
246
-			echo apply_filters( 'wc_stripe_description', wpautop( wp_kses_post( $this->description ) ) );
245
+		if ($this->description) {
246
+			echo apply_filters('wc_stripe_description', wpautop(wp_kses_post($this->description)));
247 247
 		}
248 248
 
249 249
 		echo '</div>';
@@ -254,8 +254,8 @@  discard block
 block discarded – undo
254 254
 	 *
255 255
 	 * @param int $order_id
256 256
 	 */
257
-	public function thankyou_page( $order_id ) {
258
-		$this->get_instructions( $order_id );
257
+	public function thankyou_page($order_id) {
258
+		$this->get_instructions($order_id);
259 259
 	}
260 260
 
261 261
 	/**
@@ -267,13 +267,13 @@  discard block
 block discarded – undo
267 267
 	 * @param bool $sent_to_admin
268 268
 	 * @param bool $plain_text
269 269
 	 */
270
-	public function email_instructions( $order, $sent_to_admin, $plain_text = false ) {
270
+	public function email_instructions($order, $sent_to_admin, $plain_text = false) {
271 271
 		$order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
272 272
 
273 273
 		$payment_method = WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method();
274 274
 
275
-		if ( ! $sent_to_admin && 'stripe_bitcoin' === $payment_method && $order->has_status( 'on-hold' ) ) {
276
-			$this->get_instructions( $order_id, $plain_text );
275
+		if ( ! $sent_to_admin && 'stripe_bitcoin' === $payment_method && $order->has_status('on-hold')) {
276
+			$this->get_instructions($order_id, $plain_text);
277 277
 		}
278 278
 	}
279 279
 
@@ -284,38 +284,38 @@  discard block
 block discarded – undo
284 284
 	 * @version 4.0.0
285 285
 	 * @param int $order_id
286 286
 	 */
287
-	public function get_instructions( $order_id, $plain_text = false ) {
288
-		$data = get_post_meta( $order_id, '_stripe_bitcoin', true );
287
+	public function get_instructions($order_id, $plain_text = false) {
288
+		$data = get_post_meta($order_id, '_stripe_bitcoin', true);
289 289
 
290
-		if ( $plain_text ) {
291
-			esc_html_e( 'Please pay the following:', 'woocommerce-gateway-stripe' ) . "\n\n";
290
+		if ($plain_text) {
291
+			esc_html_e('Please pay the following:', 'woocommerce-gateway-stripe') . "\n\n";
292 292
 			echo "=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\n\n";
293
-			esc_html_e( 'Bitcoin Amount:', 'woocommerce-gateway-stripe' ) . "\n\n";
293
+			esc_html_e('Bitcoin Amount:', 'woocommerce-gateway-stripe') . "\n\n";
294 294
 			echo $data['amount'] . "\n\n";
295 295
 			echo "=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\n\n";
296
-			esc_html_e( 'Receiver:', 'woocommerce-gateway-stripe' ) . "\n\n";
296
+			esc_html_e('Receiver:', 'woocommerce-gateway-stripe') . "\n\n";
297 297
 			echo $data['address'] . "\n\n";
298 298
 			echo "=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\n\n";
299
-			esc_html_e( 'URI:', 'woocommerce-gateway-stripe' ) . "\n\n";
299
+			esc_html_e('URI:', 'woocommerce-gateway-stripe') . "\n\n";
300 300
 			echo $data['uri'] . "\n\n";
301 301
 		} else {
302 302
 			?>
303
-			<h3><?php esc_html_e( 'Please pay the following:', 'woocommerce-gateway-stripe' ); ?></h3>
303
+			<h3><?php esc_html_e('Please pay the following:', 'woocommerce-gateway-stripe'); ?></h3>
304 304
 			<ul class="woocommerce-order-overview woocommerce-thankyou-order-details order_details">
305 305
 			<li class="woocommerce-order-overview__order order">
306
-				<?php esc_html_e( 'Bitcoin Amount:', 'woocommerce-gateway-stripe' ); ?>
306
+				<?php esc_html_e('Bitcoin Amount:', 'woocommerce-gateway-stripe'); ?>
307 307
 				<strong><?php echo $data['amount']; ?></strong>
308 308
 			</li>
309 309
 			<li class="woocommerce-order-overview__order order">
310
-				<?php esc_html_e( 'Receiver:', 'woocommerce-gateway-stripe' ); ?>
310
+				<?php esc_html_e('Receiver:', 'woocommerce-gateway-stripe'); ?>
311 311
 				<strong><?php echo $data['address']; ?></strong>
312 312
 			</li>
313 313
 			<li class="woocommerce-order-overview__order order">
314
-				<?php esc_html_e( 'URI:', 'woocommerce-gateway-stripe' ); ?>
314
+				<?php esc_html_e('URI:', 'woocommerce-gateway-stripe'); ?>
315 315
 				<strong>
316 316
 				<?php
317 317
 				/* translators: link */
318
-				printf( __( '<a href="%s">Pay Bitcoin</a>', 'woocommerce-gateway-stripe' ), $data['uri'] );
318
+				printf(__('<a href="%s">Pay Bitcoin</a>', 'woocommerce-gateway-stripe'), $data['uri']);
319 319
 				?>
320 320
 				</strong>
321 321
 			</li>
@@ -332,7 +332,7 @@  discard block
 block discarded – undo
332 332
 	 * @param object $order
333 333
 	 * @param object $source_object
334 334
 	 */
335
-	public function save_instructions( $order, $source_object ) {
335
+	public function save_instructions($order, $source_object) {
336 336
 		$data = array(
337 337
 			'amount'  => $source_object->bitcoin->amount,
338 338
 			'address' => $source_object->bitcoin->address,
@@ -341,7 +341,7 @@  discard block
 block discarded – undo
341 341
 
342 342
 		$order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
343 343
 
344
-		update_post_meta( $order_id, '_stripe_bitcoin', $data );
344
+		update_post_meta($order_id, '_stripe_bitcoin', $data);
345 345
 	}
346 346
 
347 347
 	/**
@@ -355,39 +355,39 @@  discard block
 block discarded – undo
355 355
 	 *
356 356
 	 * @return array|void
357 357
 	 */
358
-	public function process_payment( $order_id, $retry = true, $force_save_source = false ) {
358
+	public function process_payment($order_id, $retry = true, $force_save_source = false) {
359 359
 		try {
360
-			$order = wc_get_order( $order_id );
360
+			$order = wc_get_order($order_id);
361 361
 
362 362
 			// This comes from the create account checkbox in the checkout page.
363
-			$create_account = ! empty( $_POST['createaccount'] ) ? true : false;
363
+			$create_account = ! empty($_POST['createaccount']) ? true : false;
364 364
 
365
-			if ( $create_account ) {
365
+			if ($create_account) {
366 366
 				$new_customer_id     = WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id();
367
-				$new_stripe_customer = new WC_Stripe_Customer( $new_customer_id );
367
+				$new_stripe_customer = new WC_Stripe_Customer($new_customer_id);
368 368
 				$new_stripe_customer->create_customer();
369 369
 			}
370 370
 
371
-			$source_id       = ! empty( $_POST['stripe_source'] ) ? wc_clean( $_POST['stripe_source'] ) : '';
372
-			$prepared_source = $this->prepare_source( $this->get_source_object( $source_id ), get_current_user_id(), $force_save_source );
371
+			$source_id       = ! empty($_POST['stripe_source']) ? wc_clean($_POST['stripe_source']) : '';
372
+			$prepared_source = $this->prepare_source($this->get_source_object($source_id), get_current_user_id(), $force_save_source);
373 373
 
374
-			if ( empty( $prepared_source->source ) ) {
375
-				$localized_message = __( 'Payment processing failed. Please retry.', 'woocommerce-gateway-stripe' );
376
-				throw new WC_Stripe_Exception( print_r( $prepared_source, true ), $localized_message );
374
+			if (empty($prepared_source->source)) {
375
+				$localized_message = __('Payment processing failed. Please retry.', 'woocommerce-gateway-stripe');
376
+				throw new WC_Stripe_Exception(print_r($prepared_source, true), $localized_message);
377 377
 			}
378 378
 
379
-			$this->save_source_to_order( $order, $prepared_source );
379
+			$this->save_source_to_order($order, $prepared_source);
380 380
 
381 381
 			// This will throw exception if not valid.
382
-			$this->validate_minimum_order_amount( $order );
382
+			$this->validate_minimum_order_amount($order);
383 383
 
384
-			$source_id = ! empty( $_POST['stripe_source'] ) ? wc_clean( $_POST['stripe_source'] ) : '';
385
-			$this->save_instructions( $order, $this->get_source_object( $source_id ) );
384
+			$source_id = ! empty($_POST['stripe_source']) ? wc_clean($_POST['stripe_source']) : '';
385
+			$this->save_instructions($order, $this->get_source_object($source_id));
386 386
 
387 387
 			// Mark as on-hold (we're awaiting the payment).
388
-			$order->update_status( 'on-hold', __( 'Awaiting Bitcoin payment', 'woocommerce-gateway-stripe' ) );
388
+			$order->update_status('on-hold', __('Awaiting Bitcoin payment', 'woocommerce-gateway-stripe'));
389 389
 
390
-			wc_reduce_stock_levels( $order_id );
390
+			wc_reduce_stock_levels($order_id);
391 391
 
392 392
 			// Remove cart.
393 393
 			WC()->cart->empty_cart();
@@ -395,16 +395,16 @@  discard block
 block discarded – undo
395 395
 			// Return thankyou redirect.
396 396
 			return array(
397 397
 				'result'    => 'success',
398
-				'redirect'  => $this->get_return_url( $order ),
398
+				'redirect'  => $this->get_return_url($order),
399 399
 			);
400
-		} catch ( WC_Stripe_Exception $e ) {
401
-			wc_add_notice( $e->getLocalizedMessage(), 'error' );
402
-			WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() );
400
+		} catch (WC_Stripe_Exception $e) {
401
+			wc_add_notice($e->getLocalizedMessage(), 'error');
402
+			WC_Stripe_Logger::log('Error: ' . $e->getMessage());
403 403
 
404
-			do_action( 'wc_gateway_stripe_process_payment_error', $e, $order );
404
+			do_action('wc_gateway_stripe_process_payment_error', $e, $order);
405 405
 
406
-			if ( $order->has_status( array( 'pending', 'failed' ) ) ) {
407
-				$this->send_failed_order_email( $order_id );
406
+			if ($order->has_status(array('pending', 'failed'))) {
407
+				$this->send_failed_order_email($order_id);
408 408
 			}
409 409
 
410 410
 			return array(
Please login to merge, or discard this patch.
includes/class-wc-stripe-order-handler.php 1 patch
Spacing   +173 added lines, -173 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) {
2
+if ( ! defined('ABSPATH')) {
3 3
 	exit;
4 4
 }
5 5
 
@@ -23,12 +23,12 @@  discard block
 block discarded – undo
23 23
 
24 24
 		$this->retry_interval = 2;
25 25
 
26
-		add_action( 'wp', array( $this, 'maybe_process_redirect_order' ) );
27
-		add_action( 'woocommerce_order_status_on-hold_to_processing', array( $this, 'capture_payment' ) );
28
-		add_action( 'woocommerce_order_status_on-hold_to_completed', array( $this, 'capture_payment' ) );
29
-		add_action( 'woocommerce_order_status_on-hold_to_cancelled', array( $this, 'cancel_payment' ) );
30
-		add_action( 'woocommerce_order_status_on-hold_to_refunded', array( $this, 'cancel_payment' ) );
31
-		add_action( 'wc_ajax_wc_stripe_validate_checkout', array( $this, 'validate_checkout' ) );
26
+		add_action('wp', array($this, 'maybe_process_redirect_order'));
27
+		add_action('woocommerce_order_status_on-hold_to_processing', array($this, 'capture_payment'));
28
+		add_action('woocommerce_order_status_on-hold_to_completed', array($this, 'capture_payment'));
29
+		add_action('woocommerce_order_status_on-hold_to_cancelled', array($this, 'cancel_payment'));
30
+		add_action('woocommerce_order_status_on-hold_to_refunded', array($this, 'cancel_payment'));
31
+		add_action('wc_ajax_wc_stripe_validate_checkout', array($this, 'validate_checkout'));
32 32
 	}
33 33
 
34 34
 	/**
@@ -49,25 +49,25 @@  discard block
 block discarded – undo
49 49
 	 * @since 4.0.0
50 50
 	 * @version 4.0.0
51 51
 	 */
52
-	public function process_redirect_payment( $order_id, $retry = true ) {
52
+	public function process_redirect_payment($order_id, $retry = true) {
53 53
 		try {
54
-			$source = wc_clean( $_GET['source'] );
54
+			$source = wc_clean($_GET['source']);
55 55
 
56
-			if ( empty( $source ) ) {
56
+			if (empty($source)) {
57 57
 				return;
58 58
 			}
59 59
 
60
-			if ( empty( $order_id ) ) {
60
+			if (empty($order_id)) {
61 61
 				return;
62 62
 			}
63 63
 
64
-			$order = wc_get_order( $order_id );
64
+			$order = wc_get_order($order_id);
65 65
 
66
-			if ( ! is_object( $order ) ) {
66
+			if ( ! is_object($order)) {
67 67
 				return;
68 68
 			}
69 69
 
70
-			if ( 'processing' === $order->get_status() || 'completed' === $order->get_status() || 'on-hold' === $order->get_status() ) {
70
+			if ('processing' === $order->get_status() || 'completed' === $order->get_status() || 'on-hold' === $order->get_status()) {
71 71
 				return;
72 72
 			}
73 73
 
@@ -75,134 +75,134 @@  discard block
 block discarded – undo
75 75
 			$response = null;
76 76
 
77 77
 			// This will throw exception if not valid.
78
-			$this->validate_minimum_order_amount( $order );
78
+			$this->validate_minimum_order_amount($order);
79 79
 
80
-			WC_Stripe_Logger::log( "Info: (Redirect) Begin processing payment for order $order_id for the amount of {$order->get_total()}" );
80
+			WC_Stripe_Logger::log("Info: (Redirect) Begin processing payment for order $order_id for the amount of {$order->get_total()}");
81 81
 
82 82
 			/**
83 83
 			 * First check if the source is chargeable at this time. If not,
84 84
 			 * webhook will take care of it later.
85 85
 			 */
86
-			$source_info = WC_Stripe_API::retrieve( 'sources/' . $source );
86
+			$source_info = WC_Stripe_API::retrieve('sources/' . $source);
87 87
 
88
-			if ( ! empty( $source_info->error ) ) {
89
-				throw new WC_Stripe_Exception( print_r( $source_info, true ), $source_info->error->message );
88
+			if ( ! empty($source_info->error)) {
89
+				throw new WC_Stripe_Exception(print_r($source_info, true), $source_info->error->message);
90 90
 			}
91 91
 
92
-			if ( 'failed' === $source_info->status || 'canceled' === $source_info->status ) {
93
-				throw new WC_Stripe_Exception( print_r( $source_info, true ), __( 'Unable to process this payment, please try again or use alternative method.', 'woocommerce-gateway-stripe' ) );
92
+			if ('failed' === $source_info->status || 'canceled' === $source_info->status) {
93
+				throw new WC_Stripe_Exception(print_r($source_info, true), __('Unable to process this payment, please try again or use alternative method.', 'woocommerce-gateway-stripe'));
94 94
 			}
95 95
 
96 96
 			// If already consumed, then ignore request.
97
-			if ( 'consumed' === $source_info->status ) {
97
+			if ('consumed' === $source_info->status) {
98 98
 				return;
99 99
 			}
100 100
 
101 101
 			// If not chargeable, then ignore request.
102
-			if ( 'chargeable' !== $source_info->status ) {
102
+			if ('chargeable' !== $source_info->status) {
103 103
 				return;
104 104
 			}
105 105
 
106 106
 			// Prep source object.
107 107
 			$source_object           = new stdClass();
108 108
 			$source_object->token_id = '';
109
-			$source_object->customer = $this->get_stripe_customer_id( $order );
109
+			$source_object->customer = $this->get_stripe_customer_id($order);
110 110
 			$source_object->source   = $source_info->id;
111 111
 
112 112
 			/* If we're doing a retry and source is chargeable, we need to pass
113 113
 			 * a different idempotency key and retry for success.
114 114
 			 */
115
-			if ( 2 < $this->retry_interval && 'chargeable' === $source_info->status ) {
116
-				add_filter( 'wc_stripe_idempotency_key', array( $this, 'change_idempotency_key' ), 10, 2 );
115
+			if (2 < $this->retry_interval && 'chargeable' === $source_info->status) {
116
+				add_filter('wc_stripe_idempotency_key', array($this, 'change_idempotency_key'), 10, 2);
117 117
 			}
118 118
 
119 119
 			// Make the request.
120
-			$response = WC_Stripe_API::request( $this->generate_payment_request( $order, $source_object ) );
120
+			$response = WC_Stripe_API::request($this->generate_payment_request($order, $source_object));
121 121
 
122
-			if ( ! empty( $response->error ) ) {
122
+			if ( ! empty($response->error)) {
123 123
 				// If it is an API error such connection or server, let's retry.
124
-				if ( 'api_connection_error' === $response->error->type || 'api_error' === $response->error->type ) {
125
-					if ( $retry ) {
126
-						sleep( 5 );
127
-						return $this->process_redirect_payment( $order_id, false );
124
+				if ('api_connection_error' === $response->error->type || 'api_error' === $response->error->type) {
125
+					if ($retry) {
126
+						sleep(5);
127
+						return $this->process_redirect_payment($order_id, false);
128 128
 					} else {
129
-						$localized_message = __( 'API connection error and retries exhausted.', 'woocommerce-gateway-stripe' );
130
-						$order->add_order_note( $localized_message );
131
-						throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message );
129
+						$localized_message = __('API connection error and retries exhausted.', 'woocommerce-gateway-stripe');
130
+						$order->add_order_note($localized_message);
131
+						throw new WC_Stripe_Exception(print_r($response, true), $localized_message);
132 132
 					}
133 133
 				}
134 134
 
135 135
 				// We want to retry.
136
-				if ( $this->is_retryable_error( $response->error ) ) {
137
-					if ( $retry ) {
136
+				if ($this->is_retryable_error($response->error)) {
137
+					if ($retry) {
138 138
 						// Don't do anymore retries after this.
139
-						if ( 5 <= $this->retry_interval ) {
140
-							return $this->process_redirect_payment( $order_id, false );
139
+						if (5 <= $this->retry_interval) {
140
+							return $this->process_redirect_payment($order_id, false);
141 141
 						}
142 142
 
143
-						sleep( $this->retry_interval );
143
+						sleep($this->retry_interval);
144 144
 
145 145
 						$this->retry_interval++;
146
-						return $this->process_redirect_payment( $order_id, true );
146
+						return $this->process_redirect_payment($order_id, true);
147 147
 					} else {
148
-						$localized_message = __( 'On going requests error and retries exhausted.', 'woocommerce-gateway-stripe' );
149
-						$order->add_order_note( $localized_message );
150
-						throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message );
148
+						$localized_message = __('On going requests error and retries exhausted.', 'woocommerce-gateway-stripe');
149
+						$order->add_order_note($localized_message);
150
+						throw new WC_Stripe_Exception(print_r($response, true), $localized_message);
151 151
 					}
152 152
 				}
153 153
 
154 154
 				// Customer param wrong? The user may have been deleted on stripe's end. Remove customer_id. Can be retried without.
155
-				if ( preg_match( '/No such customer/i', $response->error->message ) && $retry ) {
156
-					if ( WC_Stripe_Helper::is_pre_30() ) {
157
-						delete_user_meta( $order->customer_user, '_stripe_customer_id' );
158
-						delete_post_meta( $order_id, '_stripe_customer_id' );
155
+				if (preg_match('/No such customer/i', $response->error->message) && $retry) {
156
+					if (WC_Stripe_Helper::is_pre_30()) {
157
+						delete_user_meta($order->customer_user, '_stripe_customer_id');
158
+						delete_post_meta($order_id, '_stripe_customer_id');
159 159
 					} else {
160
-						delete_user_meta( $order->get_customer_id(), '_stripe_customer_id' );
161
-						$order->delete_meta_data( '_stripe_customer_id' );
160
+						delete_user_meta($order->get_customer_id(), '_stripe_customer_id');
161
+						$order->delete_meta_data('_stripe_customer_id');
162 162
 						$order->save();
163 163
 					}
164 164
 
165
-					return $this->process_redirect_payment( $order_id, false );
165
+					return $this->process_redirect_payment($order_id, false);
166 166
 
167
-				} elseif ( preg_match( '/No such token/i', $response->error->message ) && $source_object->token_id ) {
167
+				} elseif (preg_match('/No such token/i', $response->error->message) && $source_object->token_id) {
168 168
 					// Source param wrong? The CARD may have been deleted on stripe's end. Remove token and show message.
169 169
 
170
-					$wc_token = WC_Payment_Tokens::get( $source_object->token_id );
170
+					$wc_token = WC_Payment_Tokens::get($source_object->token_id);
171 171
 					$wc_token->delete();
172
-					$message = __( 'This card is no longer available and has been removed.', 'woocommerce-gateway-stripe' );
173
-					$order->add_order_note( $message );
174
-					throw new WC_Stripe_Exception( print_r( $response, true ), $message );
172
+					$message = __('This card is no longer available and has been removed.', 'woocommerce-gateway-stripe');
173
+					$order->add_order_note($message);
174
+					throw new WC_Stripe_Exception(print_r($response, true), $message);
175 175
 				}
176 176
 
177 177
 				$localized_messages = WC_Stripe_Helper::get_localized_messages();
178 178
 
179
-				if ( 'card_error' === $response->error->type ) {
180
-					$message = isset( $localized_messages[ $response->error->code ] ) ? $localized_messages[ $response->error->code ] : $response->error->message;
179
+				if ('card_error' === $response->error->type) {
180
+					$message = isset($localized_messages[$response->error->code]) ? $localized_messages[$response->error->code] : $response->error->message;
181 181
 				} else {
182
-					$message = isset( $localized_messages[ $response->error->type ] ) ? $localized_messages[ $response->error->type ] : $response->error->message;
182
+					$message = isset($localized_messages[$response->error->type]) ? $localized_messages[$response->error->type] : $response->error->message;
183 183
 				}
184 184
 
185
-				throw new WC_Stripe_Exception( print_r( $response, true ), $message );
185
+				throw new WC_Stripe_Exception(print_r($response, true), $message);
186 186
 			}
187 187
 
188
-			do_action( 'wc_gateway_stripe_process_redirect_payment', $response, $order );
188
+			do_action('wc_gateway_stripe_process_redirect_payment', $response, $order);
189 189
 
190
-			$this->process_response( $response, $order );
190
+			$this->process_response($response, $order);
191 191
 
192
-		} catch ( WC_Stripe_Exception $e ) {
193
-			WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() );
192
+		} catch (WC_Stripe_Exception $e) {
193
+			WC_Stripe_Logger::log('Error: ' . $e->getMessage());
194 194
 
195
-			do_action( 'wc_gateway_stripe_process_redirect_payment_error', $e, $order );
195
+			do_action('wc_gateway_stripe_process_redirect_payment_error', $e, $order);
196 196
 
197 197
 			/* translators: error message */
198
-			$order->update_status( 'failed', sprintf( __( 'Stripe payment failed: %s', 'woocommerce-gateway-stripe' ), $e->getLocalizedMessage() ) );
198
+			$order->update_status('failed', sprintf(__('Stripe payment failed: %s', 'woocommerce-gateway-stripe'), $e->getLocalizedMessage()));
199 199
 
200
-			if ( $order->has_status( array( 'pending', 'failed' ) ) ) {
201
-				$this->send_failed_order_email( $order_id );
200
+			if ($order->has_status(array('pending', 'failed'))) {
201
+				$this->send_failed_order_email($order_id);
202 202
 			}
203 203
 
204
-			wc_add_notice( $e->getLocalizedMessage(), 'error' );
205
-			wp_safe_redirect( wc_get_checkout_url() );
204
+			wc_add_notice($e->getLocalizedMessage(), 'error');
205
+			wp_safe_redirect(wc_get_checkout_url());
206 206
 			exit;
207 207
 		}
208 208
 	}
@@ -214,13 +214,13 @@  discard block
 block discarded – undo
214 214
 	 * @version 4.0.0
215 215
 	 */
216 216
 	public function maybe_process_redirect_order() {
217
-		if ( ! is_order_received_page() || empty( $_GET['client_secret'] ) || empty( $_GET['source'] ) ) {
217
+		if ( ! is_order_received_page() || empty($_GET['client_secret']) || empty($_GET['source'])) {
218 218
 			return;
219 219
 		}
220 220
 
221
-		$order_id = wc_clean( $_GET['order_id'] );
221
+		$order_id = wc_clean($_GET['order_id']);
222 222
 
223
-		$this->process_redirect_payment( $order_id );
223
+		$this->process_redirect_payment($order_id);
224 224
 	}
225 225
 
226 226
 	/**
@@ -230,52 +230,52 @@  discard block
 block discarded – undo
230 230
 	 * @version 4.0.0
231 231
 	 * @param  int $order_id
232 232
 	 */
233
-	public function capture_payment( $order_id ) {
234
-		$order = wc_get_order( $order_id );
233
+	public function capture_payment($order_id) {
234
+		$order = wc_get_order($order_id);
235 235
 
236
-		if ( 'stripe' === ( WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method() ) ) {
237
-			$charge   = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_transaction_id', true ) : $order->get_transaction_id();
238
-			$captured = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_stripe_charge_captured', true ) : $order->get_meta( '_stripe_charge_captured', true );
236
+		if ('stripe' === (WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method())) {
237
+			$charge   = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_transaction_id', true) : $order->get_transaction_id();
238
+			$captured = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_stripe_charge_captured', true) : $order->get_meta('_stripe_charge_captured', true);
239 239
 
240
-			if ( $charge && 'no' === $captured ) {
240
+			if ($charge && 'no' === $captured) {
241 241
 				$order_total = $order->get_total();
242 242
 
243
-				if ( 0 < $order->get_total_refunded() ) {
243
+				if (0 < $order->get_total_refunded()) {
244 244
 					$order_total = $order_total - $order->get_total_refunded();
245 245
 				}
246 246
 
247
-				$result = WC_Stripe_API::request( array(
248
-					'amount'   => WC_Stripe_Helper::get_stripe_amount( $order_total ),
247
+				$result = WC_Stripe_API::request(array(
248
+					'amount'   => WC_Stripe_Helper::get_stripe_amount($order_total),
249 249
 					'expand[]' => 'balance_transaction',
250
-				), 'charges/' . $charge . '/capture' );
250
+				), 'charges/' . $charge . '/capture');
251 251
 
252
-				if ( ! empty( $result->error ) ) {
252
+				if ( ! empty($result->error)) {
253 253
 					/* translators: error message */
254
-					$order->update_status( 'failed', sprintf( __( 'Unable to capture charge! %s', 'woocommerce-gateway-stripe' ), $result->error->message ) );
254
+					$order->update_status('failed', sprintf(__('Unable to capture charge! %s', 'woocommerce-gateway-stripe'), $result->error->message));
255 255
 				} else {
256 256
 					/* translators: transaction id */
257
-					$order->add_order_note( sprintf( __( 'Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe' ), $result->id ) );
258
-					WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, '_stripe_charge_captured', 'yes' ) : $order->update_meta_data( '_stripe_charge_captured', 'yes' );
257
+					$order->add_order_note(sprintf(__('Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe'), $result->id));
258
+					WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, '_stripe_charge_captured', 'yes') : $order->update_meta_data('_stripe_charge_captured', 'yes');
259 259
 
260 260
 					// Store other data such as fees
261
-					WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, '_transaction_id', $result->id ) : $order->set_transaction_id( $result->id );
261
+					WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, '_transaction_id', $result->id) : $order->set_transaction_id($result->id);
262 262
 
263
-					if ( isset( $result->balance_transaction ) && isset( $result->balance_transaction->fee ) ) {
263
+					if (isset($result->balance_transaction) && isset($result->balance_transaction->fee)) {
264 264
 						// Fees and Net needs to both come from Stripe to be accurate as the returned
265 265
 						// values are in the local currency of the Stripe account, not from WC.
266
-						$fee = ! empty( $result->balance_transaction->fee ) ? WC_Stripe_Helper::format_balance_fee( $result->balance_transaction, 'fee' ) : 0;
267
-						$net = ! empty( $result->balance_transaction->net ) ? WC_Stripe_Helper::format_balance_fee( $result->balance_transaction, 'net' ) : 0;
268
-						WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, parent::META_NAME_FEE, $fee ) : $order->update_meta_data( parent::META_NAME_FEE, $fee );
269
-						WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, parent::META_NAME_NET, $net ) : $order->update_meta_data( parent::META_NAME_NET, $net );
266
+						$fee = ! empty($result->balance_transaction->fee) ? WC_Stripe_Helper::format_balance_fee($result->balance_transaction, 'fee') : 0;
267
+						$net = ! empty($result->balance_transaction->net) ? WC_Stripe_Helper::format_balance_fee($result->balance_transaction, 'net') : 0;
268
+						WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, parent::META_NAME_FEE, $fee) : $order->update_meta_data(parent::META_NAME_FEE, $fee);
269
+						WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, parent::META_NAME_NET, $net) : $order->update_meta_data(parent::META_NAME_NET, $net);
270 270
 					}
271 271
 
272
-					if ( is_callable( array( $order, 'save' ) ) ) {
272
+					if (is_callable(array($order, 'save'))) {
273 273
 						$order->save();
274 274
 					}
275 275
 				}
276 276
 
277 277
 				// This hook fires when admin manually changes order status to processing or completed.
278
-				do_action( 'woocommerce_stripe_process_manual_capture', $order, $result );
278
+				do_action('woocommerce_stripe_process_manual_capture', $order, $result);
279 279
 			}
280 280
 		}
281 281
 	}
@@ -287,14 +287,14 @@  discard block
 block discarded – undo
287 287
 	 * @version 4.0.0
288 288
 	 * @param  int $order_id
289 289
 	 */
290
-	public function cancel_payment( $order_id ) {
291
-		$order = wc_get_order( $order_id );
290
+	public function cancel_payment($order_id) {
291
+		$order = wc_get_order($order_id);
292 292
 
293
-		if ( 'stripe' === ( WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method() ) ) {
294
-			$this->process_refund( $order_id );
293
+		if ('stripe' === (WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method())) {
294
+			$this->process_refund($order_id);
295 295
 
296 296
 			// This hook fires when admin manually changes order status to cancel.
297
-			do_action( 'woocommerce_stripe_process_manual_cancel', $order );
297
+			do_action('woocommerce_stripe_process_manual_cancel', $order);
298 298
 		}
299 299
 	}
300 300
 
@@ -306,21 +306,21 @@  discard block
 block discarded – undo
306 306
 	 * @param string $field
307 307
 	 * @return string $error_field
308 308
 	 */
309
-	public function normalize_field( $field ) {
309
+	public function normalize_field($field) {
310 310
 		$checkout_fields = WC()->checkout->get_checkout_fields();
311 311
 		$org_str         = array();
312 312
 		$replace_str     = array();
313 313
 
314
-		if ( array_key_exists( $field, $checkout_fields['billing'] ) ) {
315
-			$error_field = __( 'Billing', 'woocommerce-gateway-stripe' ) . ' ' . $checkout_fields['billing'][ $field ]['label'];
316
-		} elseif ( array_key_exists( $field, $checkout_fields['shipping'] ) ) {
317
-			$error_field = __( 'Shipping', 'woocommerce-gateway-stripe' ) . ' ' . $checkout_fields['shipping'][ $field ]['label'];
318
-		} elseif ( array_key_exists( $field, $checkout_fields['order'] ) ) {
319
-			$error_field = $checkout_fields['order'][ $field ]['label'];
320
-		} elseif ( array_key_exists( $field, $checkout_fields['account'] ) ) {
321
-			$error_field = $checkout_fields['account'][ $field ]['label'];
314
+		if (array_key_exists($field, $checkout_fields['billing'])) {
315
+			$error_field = __('Billing', 'woocommerce-gateway-stripe') . ' ' . $checkout_fields['billing'][$field]['label'];
316
+		} elseif (array_key_exists($field, $checkout_fields['shipping'])) {
317
+			$error_field = __('Shipping', 'woocommerce-gateway-stripe') . ' ' . $checkout_fields['shipping'][$field]['label'];
318
+		} elseif (array_key_exists($field, $checkout_fields['order'])) {
319
+			$error_field = $checkout_fields['order'][$field]['label'];
320
+		} elseif (array_key_exists($field, $checkout_fields['account'])) {
321
+			$error_field = $checkout_fields['account'][$field]['label'];
322 322
 		} else {
323
-			$error_field = str_replace( '_', ' ', $field );
323
+			$error_field = str_replace('_', ' ', $field);
324 324
 
325 325
 			$org_str[]     = 'stripe';
326 326
 			$replace_str[] = '';
@@ -335,9 +335,9 @@  discard block
 block discarded – undo
335 335
 			$replace_str[] = 'SOFORT';
336 336
 
337 337
 			$org_str[]     = 'owner';
338
-			$replace_str[] = __( 'Owner', 'woocommerce-gateway-stripe' );
338
+			$replace_str[] = __('Owner', 'woocommerce-gateway-stripe');
339 339
 
340
-			$error_field   = str_replace( $org_str, $replace_str, $error_field );
340
+			$error_field   = str_replace($org_str, $replace_str, $error_field);
341 341
 		}
342 342
 
343 343
 		return $error_field;
@@ -350,135 +350,135 @@  discard block
 block discarded – undo
350 350
 	 * @version 4.0.0
351 351
 	 */
352 352
 	public function validate_checkout() {
353
-		if ( ! wp_verify_nonce( $_POST['nonce'], '_wc_stripe_nonce' ) ) {
354
-			wp_die( __( 'Cheatin&#8217; huh?', 'woocommerce-gateway-stripe' ) );
353
+		if ( ! wp_verify_nonce($_POST['nonce'], '_wc_stripe_nonce')) {
354
+			wp_die(__('Cheatin&#8217; huh?', 'woocommerce-gateway-stripe'));
355 355
 		}
356 356
 
357
-		parse_str( $_POST['required_fields'], $required_fields );
358
-		parse_str( $_POST['all_fields'], $all_fields );
357
+		parse_str($_POST['required_fields'], $required_fields);
358
+		parse_str($_POST['all_fields'], $all_fields);
359 359
 		$validate_shipping_fields = false;
360 360
 		$create_account           = false;
361 361
 		$errors                   = new WP_Error();
362
-		$all_fields               = apply_filters( 'wc_stripe_validate_checkout_all_fields', $all_fields );
363
-		$required_fields          = apply_filters( 'wc_stripe_validate_checkout_required_fields', $required_fields );
362
+		$all_fields               = apply_filters('wc_stripe_validate_checkout_all_fields', $all_fields);
363
+		$required_fields          = apply_filters('wc_stripe_validate_checkout_required_fields', $required_fields);
364 364
 
365
-		array_walk_recursive( $required_fields, 'wc_clean' );
366
-		array_walk_recursive( $all_fields, 'wc_clean' );
365
+		array_walk_recursive($required_fields, 'wc_clean');
366
+		array_walk_recursive($all_fields, 'wc_clean');
367 367
 
368 368
 		/**
369 369
 		 * If ship to different address checkbox is checked then we need
370 370
 		 * to validate shipping fields too.
371 371
 		 */
372
-		if ( isset( $all_fields['ship_to_different_address'] ) ) {
372
+		if (isset($all_fields['ship_to_different_address'])) {
373 373
 			$validate_shipping_fields = true;
374 374
 		}
375 375
 
376 376
 		// Check if createaccount is checked.
377
-		if ( isset( $all_fields['createaccount'] ) ) {
377
+		if (isset($all_fields['createaccount'])) {
378 378
 			$create_account = true;
379 379
 		}
380 380
 
381 381
 		// Check if required fields are empty.
382
-		foreach ( $required_fields as $field => $field_value ) {
382
+		foreach ($required_fields as $field => $field_value) {
383 383
 			// Check for shipping field.
384
-			if ( preg_match( '/^shipping_/', $field ) && ! $validate_shipping_fields ) {
384
+			if (preg_match('/^shipping_/', $field) && ! $validate_shipping_fields) {
385 385
 				continue;
386 386
 			}
387 387
 
388 388
 			// Check create account name.
389
-			if ( 'account_username' === $field && ! $create_account ) {
389
+			if ('account_username' === $field && ! $create_account) {
390 390
 				continue;
391 391
 			}
392 392
 
393 393
 			// Check create account password.
394
-			if ( 'account_password' === $field && ! $create_account ) {
394
+			if ('account_password' === $field && ! $create_account) {
395 395
 				continue;
396 396
 			}
397 397
 
398
-			if ( empty( $field_value ) || '-1' === $field_value ) {
399
-				$error_field = $this->normalize_field( $field );
398
+			if (empty($field_value) || '-1' === $field_value) {
399
+				$error_field = $this->normalize_field($field);
400 400
 				/* translators: error field name */
401
-				$errors->add( 'validation', sprintf( __( '<strong>%s</strong> cannot be empty', 'woocommerce-gateway-stripe' ), $error_field ) );
401
+				$errors->add('validation', sprintf(__('<strong>%s</strong> cannot be empty', 'woocommerce-gateway-stripe'), $error_field));
402 402
 			}
403 403
 		}
404 404
 
405 405
 		// Check if email is valid format.
406
-		if ( ! empty( $required_fields['billing_email'] ) && ! is_email( $required_fields['billing_email'] ) ) {
407
-			$errors->add( 'validation', __( '<strong>Billing Email</strong> is not valid', 'woocommerce-gateway-stripe' ) );
406
+		if ( ! empty($required_fields['billing_email']) && ! is_email($required_fields['billing_email'])) {
407
+			$errors->add('validation', __('<strong>Billing Email</strong> is not valid', 'woocommerce-gateway-stripe'));
408 408
 		}
409 409
 
410 410
 		// Check if phone number is valid format.
411
-		if ( ! empty( $required_fields['billing_phone'] ) ) {
412
-			$phone = wc_format_phone_number( $required_fields['billing_phone'] );
411
+		if ( ! empty($required_fields['billing_phone'])) {
412
+			$phone = wc_format_phone_number($required_fields['billing_phone']);
413 413
 
414
-			if ( '' !== $phone && ! WC_Validation::is_phone( $phone ) ) {
414
+			if ('' !== $phone && ! WC_Validation::is_phone($phone)) {
415 415
 				/* translators: %s: phone number */
416
-				$errors->add( 'validation', __( 'Please enter a valid phone number.', 'woocommerce-gateway-stripe' ) );
416
+				$errors->add('validation', __('Please enter a valid phone number.', 'woocommerce-gateway-stripe'));
417 417
 			}
418 418
 		}
419 419
 
420 420
 		// Check if postal code is valid format.
421
-		if ( ! empty( $required_fields['billing_postcode'] ) ) {
422
-			$country = isset( $required_fields['billing_country'] ) ? $required_fields['billing_country'] : WC()->customer->get_billing_country();
423
-			$postcode = wc_format_postcode( $required_fields['billing_postcode'], $country );
421
+		if ( ! empty($required_fields['billing_postcode'])) {
422
+			$country = isset($required_fields['billing_country']) ? $required_fields['billing_country'] : WC()->customer->get_billing_country();
423
+			$postcode = wc_format_postcode($required_fields['billing_postcode'], $country);
424 424
 
425
-			if ( '' !== $required_fields['billing_postcode'] && ! WC_Validation::is_postcode( $postcode, $country ) ) {
426
-				$errors->add( 'validation', __( 'Please enter a valid billing postcode / ZIP.', 'woocommerce-gateway-stripe' ) );
425
+			if ('' !== $required_fields['billing_postcode'] && ! WC_Validation::is_postcode($postcode, $country)) {
426
+				$errors->add('validation', __('Please enter a valid billing postcode / ZIP.', 'woocommerce-gateway-stripe'));
427 427
 			}
428 428
 		}
429 429
 
430
-		if ( WC()->cart->needs_shipping() && $validate_shipping_fields ) {
430
+		if (WC()->cart->needs_shipping() && $validate_shipping_fields) {
431 431
 			// Check if postal code is valid format.
432
-			if ( ! empty( $required_fields['shipping_postcode'] ) ) {
433
-				$country = isset( $required_fields['shipping_country'] ) ? $required_fields['shipping_country'] : WC()->customer->get_shipping_country();
434
-				$postcode = wc_format_postcode( $required_fields['shipping_postcode'], $country );
432
+			if ( ! empty($required_fields['shipping_postcode'])) {
433
+				$country = isset($required_fields['shipping_country']) ? $required_fields['shipping_country'] : WC()->customer->get_shipping_country();
434
+				$postcode = wc_format_postcode($required_fields['shipping_postcode'], $country);
435 435
 
436
-				if ( '' !== $required_fields['shipping_postcode'] && ! WC_Validation::is_postcode( $postcode, $country ) ) {
437
-					$errors->add( 'validation', __( 'Please enter a valid shipping postcode / ZIP.', 'woocommerce-gateway-stripe' ) );
436
+				if ('' !== $required_fields['shipping_postcode'] && ! WC_Validation::is_postcode($postcode, $country)) {
437
+					$errors->add('validation', __('Please enter a valid shipping postcode / ZIP.', 'woocommerce-gateway-stripe'));
438 438
 				}
439 439
 			}
440 440
 		}
441 441
 
442
-		if ( WC()->cart->needs_shipping() ) {
442
+		if (WC()->cart->needs_shipping()) {
443 443
 			$shipping_country = WC()->customer->get_shipping_country();
444 444
 
445
-			if ( empty( $shipping_country ) ) {
446
-				$errors->add( 'shipping', __( 'Please enter an address to continue.', 'woocommerce-gateway-stripe' ) );
447
-			} elseif ( ! in_array( WC()->customer->get_shipping_country(), array_keys( WC()->countries->get_shipping_countries() ) ) ) {
445
+			if (empty($shipping_country)) {
446
+				$errors->add('shipping', __('Please enter an address to continue.', 'woocommerce-gateway-stripe'));
447
+			} elseif ( ! in_array(WC()->customer->get_shipping_country(), array_keys(WC()->countries->get_shipping_countries()))) {
448 448
 				/* translators: country name */
449
-				$errors->add( 'shipping', sprintf( __( 'Unfortunately <strong>we do not ship %s</strong>. Please enter an alternative shipping address.', 'woocommerce-gateway-stripe' ), WC()->countries->shipping_to_prefix() . ' ' . WC()->customer->get_shipping_country() ) );
449
+				$errors->add('shipping', sprintf(__('Unfortunately <strong>we do not ship %s</strong>. Please enter an alternative shipping address.', 'woocommerce-gateway-stripe'), WC()->countries->shipping_to_prefix() . ' ' . WC()->customer->get_shipping_country()));
450 450
 			} else {
451
-				$chosen_shipping_methods = WC()->session->get( 'chosen_shipping_methods' );
451
+				$chosen_shipping_methods = WC()->session->get('chosen_shipping_methods');
452 452
 
453
-				foreach ( WC()->shipping->get_packages() as $i => $package ) {
454
-					if ( ! isset( $chosen_shipping_methods[ $i ], $package['rates'][ $chosen_shipping_methods[ $i ] ] ) ) {
455
-						$errors->add( 'shipping', __( 'No shipping method has been selected. Please double check your address, or contact us if you need any help.', 'woocommerce-gateway-stripe' ) );
453
+				foreach (WC()->shipping->get_packages() as $i => $package) {
454
+					if ( ! isset($chosen_shipping_methods[$i], $package['rates'][$chosen_shipping_methods[$i]])) {
455
+						$errors->add('shipping', __('No shipping method has been selected. Please double check your address, or contact us if you need any help.', 'woocommerce-gateway-stripe'));
456 456
 					}
457 457
 				}
458 458
 			}
459 459
 		}
460 460
 
461
-		if ( WC()->cart->needs_payment() ) {
461
+		if (WC()->cart->needs_payment()) {
462 462
 			$available_gateways = WC()->payment_gateways->get_available_payment_gateways();
463 463
 
464
-			if ( ! isset( $available_gateways[ $all_fields['payment_method'] ] ) ) {
465
-				$errors->add( 'payment', __( 'Invalid payment method.', 'woocommerce-gateway-stripe' ) );
464
+			if ( ! isset($available_gateways[$all_fields['payment_method']])) {
465
+				$errors->add('payment', __('Invalid payment method.', 'woocommerce-gateway-stripe'));
466 466
 			} else {
467
-				$available_gateways[ $all_fields['payment_method'] ]->validate_fields();
467
+				$available_gateways[$all_fields['payment_method']]->validate_fields();
468 468
 			}
469 469
 		}
470 470
 
471
-		if ( empty( $all_fields['woocommerce_checkout_update_totals'] ) && empty( $all_fields['terms'] ) && apply_filters( 'woocommerce_checkout_show_terms', wc_get_page_id( 'terms' ) > 0 ) ) {
472
-			$errors->add( 'terms', __( 'You must accept our Terms &amp; Conditions.', 'woocommerce-gateway-stripe' ) );
471
+		if (empty($all_fields['woocommerce_checkout_update_totals']) && empty($all_fields['terms']) && apply_filters('woocommerce_checkout_show_terms', wc_get_page_id('terms') > 0)) {
472
+			$errors->add('terms', __('You must accept our Terms &amp; Conditions.', 'woocommerce-gateway-stripe'));
473 473
 		}
474 474
 
475
-		do_action( 'wc_stripe_validate_checkout', $required_fields, $all_fields, $errors );
475
+		do_action('wc_stripe_validate_checkout', $required_fields, $all_fields, $errors);
476 476
 
477
-		if ( 0 === count( $errors->errors ) ) {
478
-			wp_send_json( 'success' );
477
+		if (0 === count($errors->errors)) {
478
+			wp_send_json('success');
479 479
 		} else {
480
-			foreach ( $errors->get_error_messages() as $message ) {
481
-				wc_add_notice( $message, 'error' );
480
+			foreach ($errors->get_error_messages() as $message) {
481
+				wc_add_notice($message, 'error');
482 482
 			}
483 483
 
484 484
 			$this->send_ajax_failure_response();
@@ -492,9 +492,9 @@  discard block
 block discarded – undo
492 492
 	 * @version 4.0.0
493 493
 	 */
494 494
 	public function send_ajax_failure_response() {
495
-		if ( is_ajax() ) {
495
+		if (is_ajax()) {
496 496
 			// only print notices if not reloading the checkout, otherwise they're lost in the page reload.
497
-			if ( ! isset( WC()->session->reload_checkout ) ) {
497
+			if ( ! isset(WC()->session->reload_checkout)) {
498 498
 				ob_start();
499 499
 				wc_print_notices();
500 500
 				$messages = ob_get_clean();
@@ -502,14 +502,14 @@  discard block
 block discarded – undo
502 502
 
503 503
 			$response = array(
504 504
 				'result'   => 'failure',
505
-				'messages' => isset( $messages ) ? $messages : '',
506
-				'refresh'  => isset( WC()->session->refresh_totals ),
507
-				'reload'   => isset( WC()->session->reload_checkout ),
505
+				'messages' => isset($messages) ? $messages : '',
506
+				'refresh'  => isset(WC()->session->refresh_totals),
507
+				'reload'   => isset(WC()->session->reload_checkout),
508 508
 			);
509 509
 
510
-			unset( WC()->session->refresh_totals, WC()->session->reload_checkout );
510
+			unset(WC()->session->refresh_totals, WC()->session->reload_checkout);
511 511
 
512
-			wp_send_json( $response );
512
+			wp_send_json($response);
513 513
 		}
514 514
 	}
515 515
 }
Please login to merge, or discard this patch.
includes/abstracts/abstract-wc-stripe-payment-gateway.php 1 patch
Spacing   +212 added lines, -213 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) {
2
+if ( ! defined('ABSPATH')) {
3 3
 	exit;
4 4
 }
5 5
 
@@ -21,7 +21,7 @@  discard block
 block discarded – undo
21 21
 	 * @since 4.0.5
22 22
 	 * @param array $error
23 23
 	 */
24
-	public function is_retryable_error( $error ) {
24
+	public function is_retryable_error($error) {
25 25
 		return (
26 26
 			'invalid_request_error' === $error->type ||
27 27
 			'idempotency_error' === $error->type ||
@@ -33,11 +33,11 @@  discard block
 block discarded – undo
33 33
 	 * Check if this gateway is enabled
34 34
 	 */
35 35
 	public function is_available() {
36
-		if ( 'yes' === $this->enabled ) {
37
-			if ( ! $this->testmode && is_checkout() && ! is_ssl() ) {
36
+		if ('yes' === $this->enabled) {
37
+			if ( ! $this->testmode && is_checkout() && ! is_ssl()) {
38 38
 				return false;
39 39
 			}
40
-			if ( ! $this->secret_key || ! $this->publishable_key ) {
40
+			if ( ! $this->secret_key || ! $this->publishable_key) {
41 41
 				return false;
42 42
 			}
43 43
 			return true;
@@ -52,8 +52,8 @@  discard block
 block discarded – undo
52 52
 	 * @since 4.0.0
53 53
 	 * @version 4.0.0
54 54
 	 */
55
-	public function add_admin_notice( $slug, $class, $message ) {
56
-		$this->notices[ $slug ] = array(
55
+	public function add_admin_notice($slug, $class, $message) {
56
+		$this->notices[$slug] = array(
57 57
 			'class'   => $class,
58 58
 			'message' => $message,
59 59
 		);
@@ -66,8 +66,8 @@  discard block
 block discarded – undo
66 66
 	 * @version 4.0.0
67 67
 	 */
68 68
 	public function remove_admin_notice() {
69
-		if ( did_action( 'woocommerce_update_options' ) ) {
70
-			remove_action( 'admin_notices', array( $this, 'check_environment' ) );
69
+		if (did_action('woocommerce_update_options')) {
70
+			remove_action('admin_notices', array($this, 'check_environment'));
71 71
 		}
72 72
 	}
73 73
 
@@ -79,7 +79,7 @@  discard block
 block discarded – undo
79 79
 	 * @return array
80 80
 	 */
81 81
 	public function payment_icons() {
82
-		return apply_filters( 'wc_stripe_payment_icons', array(
82
+		return apply_filters('wc_stripe_payment_icons', array(
83 83
 			'visa'       => '<i class="stripe-pf stripe-pf-visa stripe-pf-right" alt="Visa" aria-hidden="true"></i>',
84 84
 			'amex'       => '<i class="stripe-pf stripe-pf-american-express stripe-pf-right" alt="Amex" aria-hidden="true"></i>',
85 85
 			'mastercard' => '<i class="stripe-pf stripe-pf-mastercard stripe-pf-right" alt="Mastercard" aria-hidden="true"></i>',
@@ -96,7 +96,7 @@  discard block
 block discarded – undo
96 96
 			'eps'        => '<i class="stripe-pf stripe-pf-eps stripe-pf-right" alt="EPS" aria-hidden="true"></i>',
97 97
 			'sofort'     => '<i class="stripe-pf stripe-pf-sofort stripe-pf-right" alt="SOFORT" aria-hidden="true"></i>',
98 98
 			'sepa'       => '<i class="stripe-pf stripe-pf-sepa stripe-pf-right" alt="SEPA" aria-hidden="true"></i>',
99
-		) );
99
+		));
100 100
 	}
101 101
 
102 102
 	/**
@@ -107,10 +107,10 @@  discard block
 block discarded – undo
107 107
 	 * @version 4.0.0
108 108
 	 * @param object $order
109 109
 	 */
110
-	public function validate_minimum_order_amount( $order ) {
111
-		if ( $order->get_total() * 100 < WC_Stripe_Helper::get_minimum_amount() ) {
110
+	public function validate_minimum_order_amount($order) {
111
+		if ($order->get_total() * 100 < WC_Stripe_Helper::get_minimum_amount()) {
112 112
 			/* translators: 1) dollar amount */
113
-			throw new WC_Stripe_Exception( 'Did not meet minimum amount', sprintf( __( 'Sorry, the minimum allowed order total is %1$s to use this payment method.', 'woocommerce-gateway-stripe' ), wc_price( WC_Stripe_Helper::get_minimum_amount() / 100 ) ) );
113
+			throw new WC_Stripe_Exception('Did not meet minimum amount', sprintf(__('Sorry, the minimum allowed order total is %1$s to use this payment method.', 'woocommerce-gateway-stripe'), wc_price(WC_Stripe_Helper::get_minimum_amount() / 100)));
114 114
 		}
115 115
 	}
116 116
 
@@ -120,14 +120,14 @@  discard block
 block discarded – undo
120 120
 	 * @since 4.0.0
121 121
 	 * @version 4.0.0
122 122
 	 */
123
-	public function get_transaction_url( $order ) {
124
-		if ( $this->testmode ) {
123
+	public function get_transaction_url($order) {
124
+		if ($this->testmode) {
125 125
 			$this->view_transaction_url = 'https://dashboard.stripe.com/test/payments/%s';
126 126
 		} else {
127 127
 			$this->view_transaction_url = 'https://dashboard.stripe.com/payments/%s';
128 128
 		}
129 129
 
130
-		return parent::get_transaction_url( $order );
130
+		return parent::get_transaction_url($order);
131 131
 	}
132 132
 
133 133
 	/**
@@ -136,15 +136,15 @@  discard block
 block discarded – undo
136 136
 	 * @since 4.0.0
137 137
 	 * @version 4.0.0
138 138
 	 */
139
-	public function get_stripe_customer_id( $order ) {
140
-		$customer = get_user_meta( WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id(), '_stripe_customer_id', true );
139
+	public function get_stripe_customer_id($order) {
140
+		$customer = get_user_meta(WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id(), '_stripe_customer_id', true);
141 141
 
142
-		if ( empty( $customer ) ) {
142
+		if (empty($customer)) {
143 143
 			// Try to get it via the order.
144
-			if ( WC_Stripe_Helper::is_pre_30() ) {
145
-				return get_post_meta( $order->id, '_stripe_customer_id', true );
144
+			if (WC_Stripe_Helper::is_pre_30()) {
145
+				return get_post_meta($order->id, '_stripe_customer_id', true);
146 146
 			} else {
147
-				return $order->get_meta( '_stripe_customer_id', true );
147
+				return $order->get_meta('_stripe_customer_id', true);
148 148
 			}
149 149
 		} else {
150 150
 			return $customer;
@@ -161,9 +161,9 @@  discard block
 block discarded – undo
161 161
 	 * @param object $order
162 162
 	 * @param int $id Stripe session id.
163 163
 	 */
164
-	public function get_stripe_return_url( $order = null, $id = null ) {
165
-		if ( is_object( $order ) ) {
166
-			if ( empty( $id ) ) {
164
+	public function get_stripe_return_url($order = null, $id = null) {
165
+		if (is_object($order)) {
166
+			if (empty($id)) {
167 167
 				$id = uniqid();
168 168
 			}
169 169
 
@@ -174,10 +174,10 @@  discard block
 block discarded – undo
174 174
 				'order_id'       => $order_id,
175 175
 			);
176 176
 
177
-			return esc_url_raw( add_query_arg( $args, $this->get_return_url( $order ) ) );
177
+			return esc_url_raw(add_query_arg($args, $this->get_return_url($order)));
178 178
 		}
179 179
 
180
-		return esc_url_raw( add_query_arg( array( 'utm_nooverride' => '1' ), $this->get_return_url() ) );
180
+		return esc_url_raw(add_query_arg(array('utm_nooverride' => '1'), $this->get_return_url()));
181 181
 	}
182 182
 
183 183
 	/**
@@ -185,8 +185,8 @@  discard block
 block discarded – undo
185 185
 	 * @param  int  $order_id
186 186
 	 * @return boolean
187 187
 	 */
188
-	public function has_subscription( $order_id ) {
189
-		return ( function_exists( 'wcs_order_contains_subscription' ) && ( wcs_order_contains_subscription( $order_id ) || wcs_is_subscription( $order_id ) || wcs_order_contains_renewal( $order_id ) ) );
188
+	public function has_subscription($order_id) {
189
+		return (function_exists('wcs_order_contains_subscription') && (wcs_order_contains_subscription($order_id) || wcs_is_subscription($order_id) || wcs_order_contains_renewal($order_id)));
190 190
 	}
191 191
 
192 192
 	/**
@@ -198,34 +198,33 @@  discard block
 block discarded – undo
198 198
 	 * @param  object $source
199 199
 	 * @return array()
200 200
 	 */
201
-	public function generate_payment_request( $order, $source ) {
202
-		$settings                          = get_option( 'woocommerce_stripe_settings', array() );
203
-		$statement_descriptor              = ! empty( $settings['statement_descriptor'] ) ? str_replace( "'", '', $settings['statement_descriptor'] ) : '';
204
-		$capture                           = ! empty( $settings['capture'] ) && 'yes' === $settings['capture'] ? true : false;
201
+	public function generate_payment_request($order, $source) {
202
+		$settings                          = get_option('woocommerce_stripe_settings', array());
203
+		$statement_descriptor              = ! empty($settings['statement_descriptor']) ? str_replace("'", '', $settings['statement_descriptor']) : '';
204
+		$capture                           = ! empty($settings['capture']) && 'yes' === $settings['capture'] ? true : false;
205 205
 		$post_data                         = array();
206
-		$post_data['currency']             = strtolower( WC_Stripe_Helper::is_pre_30() ? $order->get_order_currency() : $order->get_currency() );
207
-		$post_data['amount']               = WC_Stripe_Helper::get_stripe_amount( $order->get_total(), $post_data['currency'] );
206
+		$post_data['currency']             = strtolower(WC_Stripe_Helper::is_pre_30() ? $order->get_order_currency() : $order->get_currency());
207
+		$post_data['amount']               = WC_Stripe_Helper::get_stripe_amount($order->get_total(), $post_data['currency']);
208 208
 		/* translators: 1) blog name 2) order number */
209
-		$post_data['description']          = sprintf( __( '%1$s - Order %2$s', 'woocommerce-gateway-stripe' ), wp_specialchars_decode( get_bloginfo( 'name' ), ENT_QUOTES ), $order->get_order_number() );
209
+		$post_data['description']          = sprintf(__('%1$s - Order %2$s', 'woocommerce-gateway-stripe'), wp_specialchars_decode(get_bloginfo('name'), ENT_QUOTES), $order->get_order_number());
210 210
 		$billing_email      = WC_Stripe_Helper::is_pre_30() ? $order->billing_email : $order->get_billing_email();
211 211
 		$billing_first_name = WC_Stripe_Helper::is_pre_30() ? $order->billing_first_name : $order->get_billing_first_name();
212 212
 		$billing_last_name  = WC_Stripe_Helper::is_pre_30() ? $order->billing_last_name : $order->get_billing_last_name();
213 213
 
214
-		if ( ! empty( $billing_email ) && apply_filters( 'wc_stripe_send_stripe_receipt', false ) ) {
214
+		if ( ! empty($billing_email) && apply_filters('wc_stripe_send_stripe_receipt', false)) {
215 215
 			$post_data['receipt_email'] = $billing_email;
216 216
 		}
217 217
 
218
-		switch ( WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method() ) {
219
-			case 'stripe':
220
-				if ( ! empty( $statement_descriptor ) ) {
221
-					$post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor( $statement_descriptor );
218
+		switch (WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method()) {
219
+			case 'stripe' : if ( ! empty($statement_descriptor)) {
220
+					$post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor($statement_descriptor);
222 221
 				}
223 222
 
224 223
 				$post_data['capture'] = $capture ? 'true' : 'false';
225 224
 				break;
226 225
 			case 'stripe_sepa':
227
-				if ( ! empty( $statement_descriptor ) ) {
228
-					$post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor( $statement_descriptor );
226
+				if ( ! empty($statement_descriptor)) {
227
+					$post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor($statement_descriptor);
229 228
 				}
230 229
 				break;
231 230
 		}
@@ -233,25 +232,25 @@  discard block
 block discarded – undo
233 232
 		$post_data['expand[]'] = 'balance_transaction';
234 233
 
235 234
 		$metadata = array(
236
-			__( 'customer_name', 'woocommerce-gateway-stripe' ) => sanitize_text_field( $billing_first_name ) . ' ' . sanitize_text_field( $billing_last_name ),
237
-			__( 'customer_email', 'woocommerce-gateway-stripe' ) => sanitize_email( $billing_email ),
235
+			__('customer_name', 'woocommerce-gateway-stripe') => sanitize_text_field($billing_first_name) . ' ' . sanitize_text_field($billing_last_name),
236
+			__('customer_email', 'woocommerce-gateway-stripe') => sanitize_email($billing_email),
238 237
 			'order_id' => WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(),
239 238
 		);
240 239
 
241
-		if ( $this->has_subscription( WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id() ) ) {
240
+		if ($this->has_subscription(WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id())) {
242 241
 			$metadata += array(
243 242
 				'payment_type' => 'recurring',
244
-				'site_url'     => esc_url( get_site_url() ),
243
+				'site_url'     => esc_url(get_site_url()),
245 244
 			);
246 245
 		}
247 246
 
248
-		$post_data['metadata'] = apply_filters( 'wc_stripe_payment_metadata', $metadata, $order, $source );
247
+		$post_data['metadata'] = apply_filters('wc_stripe_payment_metadata', $metadata, $order, $source);
249 248
 
250
-		if ( $source->customer ) {
249
+		if ($source->customer) {
251 250
 			$post_data['customer'] = $source->customer;
252 251
 		}
253 252
 
254
-		if ( $source->source ) {
253
+		if ($source->source) {
255 254
 			$post_data['source'] = $source->source;
256 255
 		}
257 256
 
@@ -263,79 +262,79 @@  discard block
 block discarded – undo
263 262
 		 * @param WC_Order $order
264 263
 		 * @param object $source
265 264
 		 */
266
-		return apply_filters( 'wc_stripe_generate_payment_request', $post_data, $order, $source );
265
+		return apply_filters('wc_stripe_generate_payment_request', $post_data, $order, $source);
267 266
 	}
268 267
 
269 268
 	/**
270 269
 	 * Store extra meta data for an order from a Stripe Response.
271 270
 	 */
272
-	public function process_response( $response, $order ) {
273
-		WC_Stripe_Logger::log( 'Processing response: ' . print_r( $response, true ) );
271
+	public function process_response($response, $order) {
272
+		WC_Stripe_Logger::log('Processing response: ' . print_r($response, true));
274 273
 
275 274
 		$order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
276 275
 
277
-		$captured = ( isset( $response->captured ) && $response->captured ) ? 'yes' : 'no';
276
+		$captured = (isset($response->captured) && $response->captured) ? 'yes' : 'no';
278 277
 
279 278
 		// Store charge data.
280
-		WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, '_stripe_charge_captured', $captured ) : $order->update_meta_data( '_stripe_charge_captured', $captured );
279
+		WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, '_stripe_charge_captured', $captured) : $order->update_meta_data('_stripe_charge_captured', $captured);
281 280
 
282 281
 		// Store other data such as fees.
283
-		if ( isset( $response->balance_transaction ) && isset( $response->balance_transaction->fee ) ) {
282
+		if (isset($response->balance_transaction) && isset($response->balance_transaction->fee)) {
284 283
 			// Fees and Net needs to both come from Stripe to be accurate as the returned
285 284
 			// values are in the local currency of the Stripe account, not from WC.
286
-			$fee = ! empty( $response->balance_transaction->fee ) ? WC_Stripe_Helper::format_balance_fee( $response->balance_transaction, 'fee' ) : 0;
287
-			$net = ! empty( $response->balance_transaction->net ) ? WC_Stripe_Helper::format_balance_fee( $response->balance_transaction, 'net' ) : 0;
288
-			WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, self::META_NAME_FEE, $fee ) : $order->update_meta_data( self::META_NAME_FEE, $fee );
289
-			WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, self::META_NAME_NET, $net ) : $order->update_meta_data( self::META_NAME_NET, $net );
285
+			$fee = ! empty($response->balance_transaction->fee) ? WC_Stripe_Helper::format_balance_fee($response->balance_transaction, 'fee') : 0;
286
+			$net = ! empty($response->balance_transaction->net) ? WC_Stripe_Helper::format_balance_fee($response->balance_transaction, 'net') : 0;
287
+			WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, self::META_NAME_FEE, $fee) : $order->update_meta_data(self::META_NAME_FEE, $fee);
288
+			WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, self::META_NAME_NET, $net) : $order->update_meta_data(self::META_NAME_NET, $net);
290 289
 		}
291 290
 
292
-		if ( 'yes' === $captured ) {
291
+		if ('yes' === $captured) {
293 292
 			/**
294 293
 			 * Charge can be captured but in a pending state. Payment methods
295 294
 			 * that are asynchronous may take couple days to clear. Webhook will
296 295
 			 * take care of the status changes.
297 296
 			 */
298
-			if ( 'pending' === $response->status ) {
299
-				$order_stock_reduced = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_order_stock_reduced', true ) : $order->get_meta( '_order_stock_reduced', true );
297
+			if ('pending' === $response->status) {
298
+				$order_stock_reduced = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_order_stock_reduced', true) : $order->get_meta('_order_stock_reduced', true);
300 299
 
301
-				if ( ! $order_stock_reduced ) {
302
-					WC_Stripe_Helper::is_pre_30() ? $order->reduce_order_stock() : wc_reduce_stock_levels( $order_id );
300
+				if ( ! $order_stock_reduced) {
301
+					WC_Stripe_Helper::is_pre_30() ? $order->reduce_order_stock() : wc_reduce_stock_levels($order_id);
303 302
 				}
304 303
 
305
-				WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, '_transaction_id', $response->id ) : $order->set_transaction_id( $response->id );
304
+				WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, '_transaction_id', $response->id) : $order->set_transaction_id($response->id);
306 305
 				/* translators: transaction id */
307
-				$order->update_status( 'on-hold', sprintf( __( 'Stripe charge awaiting payment: %s.', 'woocommerce-gateway-stripe' ), $response->id ) );
306
+				$order->update_status('on-hold', sprintf(__('Stripe charge awaiting payment: %s.', 'woocommerce-gateway-stripe'), $response->id));
308 307
 			}
309 308
 
310
-			if ( 'succeeded' === $response->status ) {
311
-				$order->payment_complete( $response->id );
309
+			if ('succeeded' === $response->status) {
310
+				$order->payment_complete($response->id);
312 311
 
313 312
 				/* translators: transaction id */
314
-				$message = sprintf( __( 'Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe' ), $response->id );
315
-				$order->add_order_note( $message );
313
+				$message = sprintf(__('Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe'), $response->id);
314
+				$order->add_order_note($message);
316 315
 			}
317 316
 
318
-			if ( 'failed' === $response->status ) {
319
-				$localized_message = __( 'Payment processing failed. Please retry.', 'woocommerce-gateway-stripe' );
320
-				$order->add_order_note( $localized_message );
321
-				throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message );
317
+			if ('failed' === $response->status) {
318
+				$localized_message = __('Payment processing failed. Please retry.', 'woocommerce-gateway-stripe');
319
+				$order->add_order_note($localized_message);
320
+				throw new WC_Stripe_Exception(print_r($response, true), $localized_message);
322 321
 			}
323 322
 		} else {
324
-			WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, '_transaction_id', $response->id ) : $order->set_transaction_id( $response->id );
323
+			WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, '_transaction_id', $response->id) : $order->set_transaction_id($response->id);
325 324
 
326
-			if ( $order->has_status( array( 'pending', 'failed' ) ) ) {
327
-				WC_Stripe_Helper::is_pre_30() ? $order->reduce_order_stock() : wc_reduce_stock_levels( $order_id );
325
+			if ($order->has_status(array('pending', 'failed'))) {
326
+				WC_Stripe_Helper::is_pre_30() ? $order->reduce_order_stock() : wc_reduce_stock_levels($order_id);
328 327
 			}
329 328
 
330 329
 			/* translators: transaction id */
331
-			$order->update_status( 'on-hold', sprintf( __( 'Stripe charge authorized (Charge ID: %s). Process order to take payment, or cancel to remove the pre-authorization.', 'woocommerce-gateway-stripe' ), $response->id ) );
330
+			$order->update_status('on-hold', sprintf(__('Stripe charge authorized (Charge ID: %s). Process order to take payment, or cancel to remove the pre-authorization.', 'woocommerce-gateway-stripe'), $response->id));
332 331
 		}
333 332
 
334
-		if ( is_callable( array( $order, 'save' ) ) ) {
333
+		if (is_callable(array($order, 'save'))) {
335 334
 			$order->save();
336 335
 		}
337 336
 
338
-		do_action( 'wc_gateway_stripe_process_response', $response, $order );
337
+		do_action('wc_gateway_stripe_process_response', $response, $order);
339 338
 
340 339
 		return $response;
341 340
 	}
@@ -348,10 +347,10 @@  discard block
 block discarded – undo
348 347
 	 * @param int $order_id
349 348
 	 * @return null
350 349
 	 */
351
-	public function send_failed_order_email( $order_id ) {
350
+	public function send_failed_order_email($order_id) {
352 351
 		$emails = WC()->mailer()->get_emails();
353
-		if ( ! empty( $emails ) && ! empty( $order_id ) ) {
354
-			$emails['WC_Email_Failed_Order']->trigger( $order_id );
352
+		if ( ! empty($emails) && ! empty($order_id)) {
353
+			$emails['WC_Email_Failed_Order']->trigger($order_id);
355 354
 		}
356 355
 	}
357 356
 
@@ -363,7 +362,7 @@  discard block
 block discarded – undo
363 362
 	 * @param object $order
364 363
 	 * @return object $details
365 364
 	 */
366
-	public function get_owner_details( $order ) {
365
+	public function get_owner_details($order) {
367 366
 		$billing_first_name = WC_Stripe_Helper::is_pre_30() ? $order->billing_first_name : $order->get_billing_first_name();
368 367
 		$billing_last_name  = WC_Stripe_Helper::is_pre_30() ? $order->billing_last_name : $order->get_billing_last_name();
369 368
 
@@ -374,8 +373,8 @@  discard block
 block discarded – undo
374 373
 
375 374
 		$phone                             = WC_Stripe_Helper::is_pre_30() ? $order->billing_phone : $order->get_billing_phone();
376 375
 
377
-		if ( ! empty( $phone ) ) {
378
-			$details['phone']              = $phone;
376
+		if ( ! empty($phone)) {
377
+			$details['phone'] = $phone;
379 378
 		}
380 379
 
381 380
 		$details['address']['line1']       = WC_Stripe_Helper::is_pre_30() ? $order->billing_address_1 : $order->get_billing_address_1();
@@ -385,7 +384,7 @@  discard block
 block discarded – undo
385 384
 		$details['address']['postal_code'] = WC_Stripe_Helper::is_pre_30() ? $order->billing_postcode : $order->get_billing_postcode();
386 385
 		$details['address']['country']     = WC_Stripe_Helper::is_pre_30() ? $order->billing_country : $order->get_billing_country();
387 386
 
388
-		return (object) apply_filters( 'wc_stripe_owner_details', $details, $order );
387
+		return (object) apply_filters('wc_stripe_owner_details', $details, $order);
389 388
 	}
390 389
 
391 390
 	/**
@@ -393,15 +392,15 @@  discard block
 block discarded – undo
393 392
 	 *
394 393
 	 * @since 4.0.3
395 394
 	 */
396
-	public function get_source_object( $source_id = '' ) {
397
-		if ( empty( $source_id ) ) {
395
+	public function get_source_object($source_id = '') {
396
+		if (empty($source_id)) {
398 397
 			return '';
399 398
 		}
400 399
 
401
-		$source_object = WC_Stripe_API::retrieve( 'sources/' . $source_id );
400
+		$source_object = WC_Stripe_API::retrieve('sources/' . $source_id);
402 401
 
403
-		if ( ! empty( $source_object->error ) ) {
404
-			throw new WC_Stripe_Exception( print_r( $source_object, true ), $source_object->error->message );
402
+		if ( ! empty($source_object->error)) {
403
+			throw new WC_Stripe_Exception(print_r($source_object, true), $source_object->error->message);
405 404
 		}
406 405
 
407 406
 		return $source_object;
@@ -414,11 +413,11 @@  discard block
 block discarded – undo
414 413
 	 * @param object $source_object
415 414
 	 * @return bool
416 415
 	 */
417
-	public function is_3ds_required( $source_object ) {
416
+	public function is_3ds_required($source_object) {
418 417
 		return (
419
-			$source_object && ! empty( $source_object->card ) ) &&
420
-			( 'card' === $source_object->type && 'required' === $source_object->card->three_d_secure ||
421
-			( $this->three_d_secure && 'optional' === $source_object->card->three_d_secure )
418
+			$source_object && ! empty($source_object->card) ) &&
419
+			('card' === $source_object->type && 'required' === $source_object->card->three_d_secure ||
420
+			($this->three_d_secure && 'optional' === $source_object->card->three_d_secure)
422 421
 		);
423 422
 	}
424 423
 
@@ -429,8 +428,8 @@  discard block
 block discarded – undo
429 428
 	 * @param object $source_object
430 429
 	 * @return bool
431 430
 	 */
432
-	public function is_3ds_card( $source_object ) {
433
-		return ( $source_object && 'three_d_secure' === $source_object->type );
431
+	public function is_3ds_card($source_object) {
432
+		return ($source_object && 'three_d_secure' === $source_object->type);
434 433
 	}
435 434
 
436 435
 	/**
@@ -443,22 +442,22 @@  discard block
 block discarded – undo
443 442
 	 * @param string $return_url
444 443
 	 * @return mixed
445 444
 	 */
446
-	public function create_3ds_source( $order, $source_object, $return_url = '' ) {
445
+	public function create_3ds_source($order, $source_object, $return_url = '') {
447 446
 		$currency                    = WC_Stripe_Helper::is_pre_30() ? $order->get_order_currency() : $order->get_currency();
448 447
 		$order_id                    = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
449
-		$return_url                  = empty( $return_url ) ? $this->get_stripe_return_url( $order ) : $return_url;
448
+		$return_url                  = empty($return_url) ? $this->get_stripe_return_url($order) : $return_url;
450 449
 
451 450
 		$post_data                   = array();
452
-		$post_data['amount']         = WC_Stripe_Helper::get_stripe_amount( $order->get_total(), $currency );
453
-		$post_data['currency']       = strtolower( $currency );
451
+		$post_data['amount']         = WC_Stripe_Helper::get_stripe_amount($order->get_total(), $currency);
452
+		$post_data['currency']       = strtolower($currency);
454 453
 		$post_data['type']           = 'three_d_secure';
455
-		$post_data['owner']          = $this->get_owner_details( $order );
456
-		$post_data['three_d_secure'] = array( 'card' => $source_object->id );
457
-		$post_data['redirect']       = array( 'return_url' => $return_url );
454
+		$post_data['owner']          = $this->get_owner_details($order);
455
+		$post_data['three_d_secure'] = array('card' => $source_object->id);
456
+		$post_data['redirect']       = array('return_url' => $return_url);
458 457
 
459
-		WC_Stripe_Logger::log( 'Info: Begin creating 3DS source...' );
458
+		WC_Stripe_Logger::log('Info: Begin creating 3DS source...');
460 459
 
461
-		return WC_Stripe_API::request( apply_filters( 'wc_stripe_3ds_source', $post_data, $order ), 'sources' );
460
+		return WC_Stripe_API::request(apply_filters('wc_stripe_3ds_source', $post_data, $order), 'sources');
462 461
 	}
463 462
 
464 463
 	/**
@@ -475,54 +474,54 @@  discard block
 block discarded – undo
475 474
 	 * @throws Exception When card was not added or for and invalid card.
476 475
 	 * @return object
477 476
 	 */
478
-	public function prepare_source( $source_object = '', $user_id, $force_save_source = false ) {
479
-		$customer           = new WC_Stripe_Customer( $user_id );
477
+	public function prepare_source($source_object = '', $user_id, $force_save_source = false) {
478
+		$customer           = new WC_Stripe_Customer($user_id);
480 479
 		$set_customer       = true;
481
-		$force_save_source  = apply_filters( 'wc_stripe_force_save_source', $force_save_source, $customer );
480
+		$force_save_source  = apply_filters('wc_stripe_force_save_source', $force_save_source, $customer);
482 481
 		$source_id          = '';
483 482
 		$wc_token_id        = false;
484
-		$payment_method     = isset( $_POST['payment_method'] ) ? wc_clean( $_POST['payment_method'] ) : 'stripe';
483
+		$payment_method     = isset($_POST['payment_method']) ? wc_clean($_POST['payment_method']) : 'stripe';
485 484
 
486 485
 		// New CC info was entered and we have a new source to process.
487
-		if ( ! empty( $source_object ) ) {
486
+		if ( ! empty($source_object)) {
488 487
 			$source_id = $source_object->id;
489 488
 
490 489
 			// This checks to see if customer opted to save the payment method to file.
491
-			$maybe_saved_card = isset( $_POST[ 'wc-' . $payment_method . '-new-payment-method' ] ) && ! empty( $_POST[ 'wc-' . $payment_method . '-new-payment-method' ] );
490
+			$maybe_saved_card = isset($_POST['wc-' . $payment_method . '-new-payment-method']) && ! empty($_POST['wc-' . $payment_method . '-new-payment-method']);
492 491
 
493 492
 			/**
494 493
 			 * This is true if the user wants to store the card to their account.
495 494
 			 * Criteria to save to file is they are logged in, they opted to save or product requirements and the source is
496 495
 			 * actually reusable. Either that or force_save_source is true.
497 496
 			 */
498
-			if ( ( $user_id && $this->saved_cards && $maybe_saved_card && 'reusable' === $source_object->usage ) || $force_save_source ) {
499
-				$response = $customer->add_source( $source_object->id );
497
+			if (($user_id && $this->saved_cards && $maybe_saved_card && 'reusable' === $source_object->usage) || $force_save_source) {
498
+				$response = $customer->add_source($source_object->id);
500 499
 
501
-				if ( ! empty( $response->error ) ) {
502
-					throw new WC_Stripe_Exception( print_r( $response, true ), $response->error->message );
500
+				if ( ! empty($response->error)) {
501
+					throw new WC_Stripe_Exception(print_r($response, true), $response->error->message);
503 502
 				}
504 503
 			}
505
-		} elseif ( isset( $_POST[ 'wc-' . $payment_method . '-payment-token' ] ) && 'new' !== $_POST[ 'wc-' . $payment_method . '-payment-token' ] ) {
504
+		} elseif (isset($_POST['wc-' . $payment_method . '-payment-token']) && 'new' !== $_POST['wc-' . $payment_method . '-payment-token']) {
506 505
 			// Use an existing token, and then process the payment.
507
-			$wc_token_id = wc_clean( $_POST[ 'wc-' . $payment_method . '-payment-token' ] );
508
-			$wc_token    = WC_Payment_Tokens::get( $wc_token_id );
506
+			$wc_token_id = wc_clean($_POST['wc-' . $payment_method . '-payment-token']);
507
+			$wc_token    = WC_Payment_Tokens::get($wc_token_id);
509 508
 
510
-			if ( ! $wc_token || $wc_token->get_user_id() !== get_current_user_id() ) {
511
-				WC()->session->set( 'refresh_totals', true );
512
-				throw new WC_Stripe_Exception( 'Invalid payment method', __( 'Invalid payment method. Please input a new card number.', 'woocommerce-gateway-stripe' ) );
509
+			if ( ! $wc_token || $wc_token->get_user_id() !== get_current_user_id()) {
510
+				WC()->session->set('refresh_totals', true);
511
+				throw new WC_Stripe_Exception('Invalid payment method', __('Invalid payment method. Please input a new card number.', 'woocommerce-gateway-stripe'));
513 512
 			}
514 513
 
515 514
 			$source_id = $wc_token->get_token();
516
-		} elseif ( isset( $_POST['stripe_token'] ) && 'new' !== $_POST['stripe_token'] ) {
517
-			$stripe_token     = wc_clean( $_POST['stripe_token'] );
518
-			$maybe_saved_card = isset( $_POST[ 'wc-' . $payment_method . '-new-payment-method' ] ) && ! empty( $_POST[ 'wc-' . $payment_method . '-new-payment-method' ] );
515
+		} elseif (isset($_POST['stripe_token']) && 'new' !== $_POST['stripe_token']) {
516
+			$stripe_token     = wc_clean($_POST['stripe_token']);
517
+			$maybe_saved_card = isset($_POST['wc-' . $payment_method . '-new-payment-method']) && ! empty($_POST['wc-' . $payment_method . '-new-payment-method']);
519 518
 
520 519
 			// This is true if the user wants to store the card to their account.
521
-			if ( ( $user_id && $this->saved_cards && $maybe_saved_card ) || $force_save_source ) {
522
-				$response = $customer->add_source( $stripe_token );
520
+			if (($user_id && $this->saved_cards && $maybe_saved_card) || $force_save_source) {
521
+				$response = $customer->add_source($stripe_token);
523 522
 
524
-				if ( ! empty( $response->error ) ) {
525
-					throw new WC_Stripe_Exception( print_r( $response, true ), $response->error->message );
523
+				if ( ! empty($response->error)) {
524
+					throw new WC_Stripe_Exception(print_r($response, true), $response->error->message);
526 525
 				}
527 526
 			} else {
528 527
 				$set_customer = false;
@@ -530,7 +529,7 @@  discard block
 block discarded – undo
530 529
 			}
531 530
 		}
532 531
 
533
-		if ( ! $set_customer ) {
532
+		if ( ! $set_customer) {
534 533
 			$customer_id = false;
535 534
 		} else {
536 535
 			$customer_id = $customer->get_id() ? $customer->get_id() : false;
@@ -556,37 +555,37 @@  discard block
 block discarded – undo
556 555
 	 * @param object $order
557 556
 	 * @return object
558 557
 	 */
559
-	public function prepare_order_source( $order = null ) {
558
+	public function prepare_order_source($order = null) {
560 559
 		$stripe_customer = new WC_Stripe_Customer();
561 560
 		$stripe_source   = false;
562 561
 		$token_id        = false;
563 562
 
564
-		if ( $order ) {
563
+		if ($order) {
565 564
 			$order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
566 565
 
567
-			$stripe_customer_id = get_post_meta( $order_id, '_stripe_customer_id', true );
566
+			$stripe_customer_id = get_post_meta($order_id, '_stripe_customer_id', true);
568 567
 
569
-			if ( $stripe_customer_id ) {
570
-				$stripe_customer->set_id( $stripe_customer_id );
568
+			if ($stripe_customer_id) {
569
+				$stripe_customer->set_id($stripe_customer_id);
571 570
 			}
572 571
 
573
-			$source_id = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_stripe_source_id', true ) : $order->get_meta( '_stripe_source_id', true );
572
+			$source_id = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_stripe_source_id', true) : $order->get_meta('_stripe_source_id', true);
574 573
 
575 574
 			// Since 4.0.0, we changed card to source so we need to account for that.
576
-			if ( empty( $source_id ) ) {
577
-				$source_id = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_stripe_card_id', true ) : $order->get_meta( '_stripe_card_id', true );
575
+			if (empty($source_id)) {
576
+				$source_id = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_stripe_card_id', true) : $order->get_meta('_stripe_card_id', true);
578 577
 
579 578
 				// Take this opportunity to update the key name.
580
-				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 );
579
+				WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, '_stripe_source_id', $source_id) : $order->update_meta_data('_stripe_source_id', $source_id);
581 580
 
582
-				if ( is_callable( array( $order, 'save' ) ) ) {
581
+				if (is_callable(array($order, 'save'))) {
583 582
 					$order->save();
584 583
 				}
585 584
 			}
586 585
 
587
-			if ( $source_id ) {
586
+			if ($source_id) {
588 587
 				$stripe_source = $source_id;
589
-			} elseif ( apply_filters( 'wc_stripe_use_default_customer_source', true ) ) {
588
+			} elseif (apply_filters('wc_stripe_use_default_customer_source', true)) {
590 589
 				/*
591 590
 				 * We can attempt to charge the customer's default source
592 591
 				 * by sending empty source id.
@@ -610,27 +609,27 @@  discard block
 block discarded – undo
610 609
 	 * @param WC_Order $order For to which the source applies.
611 610
 	 * @param stdClass $source Source information.
612 611
 	 */
613
-	public function save_source_to_order( $order, $source ) {
612
+	public function save_source_to_order($order, $source) {
614 613
 		$order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
615 614
 
616 615
 		// Store source in the order.
617
-		if ( $source->customer ) {
618
-			if ( WC_Stripe_Helper::is_pre_30() ) {
619
-				update_post_meta( $order_id, '_stripe_customer_id', $source->customer );
616
+		if ($source->customer) {
617
+			if (WC_Stripe_Helper::is_pre_30()) {
618
+				update_post_meta($order_id, '_stripe_customer_id', $source->customer);
620 619
 			} else {
621
-				$order->update_meta_data( '_stripe_customer_id', $source->customer );
620
+				$order->update_meta_data('_stripe_customer_id', $source->customer);
622 621
 			}
623 622
 		}
624 623
 
625
-		if ( $source->source ) {
626
-			if ( WC_Stripe_Helper::is_pre_30() ) {
627
-				update_post_meta( $order_id, '_stripe_source_id', $source->source );
624
+		if ($source->source) {
625
+			if (WC_Stripe_Helper::is_pre_30()) {
626
+				update_post_meta($order_id, '_stripe_source_id', $source->source);
628 627
 			} else {
629
-				$order->update_meta_data( '_stripe_source_id', $source->source );
628
+				$order->update_meta_data('_stripe_source_id', $source->source);
630 629
 			}
631 630
 		}
632 631
 
633
-		if ( is_callable( array( $order, 'save' ) ) ) {
632
+		if (is_callable(array($order, 'save'))) {
634 633
 			$order->save();
635 634
 		}
636 635
 	}
@@ -644,35 +643,35 @@  discard block
 block discarded – undo
644 643
 	 * @param object $order The order object
645 644
 	 * @param int $balance_transaction_id
646 645
 	 */
647
-	public function update_fees( $order, $balance_transaction_id ) {
646
+	public function update_fees($order, $balance_transaction_id) {
648 647
 		$order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
649 648
 
650
-		$balance_transaction = WC_Stripe_API::retrieve( 'balance/history/' . $balance_transaction_id );
649
+		$balance_transaction = WC_Stripe_API::retrieve('balance/history/' . $balance_transaction_id);
651 650
 
652
-		if ( empty( $balance_transaction->error ) ) {
653
-			if ( isset( $balance_transaction ) && isset( $balance_transaction->fee ) ) {
651
+		if (empty($balance_transaction->error)) {
652
+			if (isset($balance_transaction) && isset($balance_transaction->fee)) {
654 653
 				// Fees and Net needs to both come from Stripe to be accurate as the returned
655 654
 				// values are in the local currency of the Stripe account, not from WC.
656
-				$fee_refund = ! empty( $balance_transaction->fee ) ? WC_Stripe_Helper::format_balance_fee( $balance_transaction, 'fee' ) : 0;
657
-				$net_refund = ! empty( $balance_transaction->net ) ? WC_Stripe_Helper::format_balance_fee( $balance_transaction, 'net' ) : 0;
655
+				$fee_refund = ! empty($balance_transaction->fee) ? WC_Stripe_Helper::format_balance_fee($balance_transaction, 'fee') : 0;
656
+				$net_refund = ! empty($balance_transaction->net) ? WC_Stripe_Helper::format_balance_fee($balance_transaction, 'net') : 0;
658 657
 
659 658
 				// Current data fee & net.
660
-				$fee_current = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, self::META_NAME_FEE, true ) : $order->get_meta( self::META_NAME_FEE, true );
661
-				$net_current = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, self::META_NAME_NET, true ) : $order->get_meta( self::META_NAME_NET, true );
659
+				$fee_current = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, self::META_NAME_FEE, true) : $order->get_meta(self::META_NAME_FEE, true);
660
+				$net_current = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, self::META_NAME_NET, true) : $order->get_meta(self::META_NAME_NET, true);
662 661
 
663 662
 				// Calculation.
664 663
 				$fee = $fee_current + $fee_refund;
665 664
 				$net = $net_current + $net_refund;
666 665
 
667
-				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 );
668
-				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 );
666
+				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);
667
+				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);
669 668
 
670
-				if ( is_callable( array( $order, 'save' ) ) ) {
669
+				if (is_callable(array($order, 'save'))) {
671 670
 					$order->save();
672 671
 				}
673 672
 			}
674 673
 		} else {
675
-			WC_Stripe_Logger::log( "Unable to update fees/net meta for order: {$order_id}" );
674
+			WC_Stripe_Logger::log("Unable to update fees/net meta for order: {$order_id}");
676 675
 		}
677 676
 	}
678 677
 
@@ -685,33 +684,33 @@  discard block
 block discarded – undo
685 684
 	 * @param  float $amount
686 685
 	 * @return bool
687 686
 	 */
688
-	public function process_refund( $order_id, $amount = null, $reason = '' ) {
689
-		$order = wc_get_order( $order_id );
687
+	public function process_refund($order_id, $amount = null, $reason = '') {
688
+		$order = wc_get_order($order_id);
690 689
 
691
-		if ( ! $order || ! $order->get_transaction_id() ) {
690
+		if ( ! $order || ! $order->get_transaction_id()) {
692 691
 			return false;
693 692
 		}
694 693
 
695 694
 		$request = array();
696 695
 
697
-		if ( WC_Stripe_Helper::is_pre_30() ) {
698
-			$order_currency = get_post_meta( $order_id, '_order_currency', true );
699
-			$captured       = get_post_meta( $order_id, '_stripe_charge_captured', true );
696
+		if (WC_Stripe_Helper::is_pre_30()) {
697
+			$order_currency = get_post_meta($order_id, '_order_currency', true);
698
+			$captured       = get_post_meta($order_id, '_stripe_charge_captured', true);
700 699
 		} else {
701 700
 			$order_currency = $order->get_currency();
702
-			$captured       = $order->get_meta( '_stripe_charge_captured', true );
701
+			$captured       = $order->get_meta('_stripe_charge_captured', true);
703 702
 		}
704 703
 
705
-		if ( ! is_null( $amount ) ) {
706
-			$request['amount'] = WC_Stripe_Helper::get_stripe_amount( $amount, $order_currency );
704
+		if ( ! is_null($amount)) {
705
+			$request['amount'] = WC_Stripe_Helper::get_stripe_amount($amount, $order_currency);
707 706
 		}
708 707
 
709 708
 		// If order is only authorized, don't pass amount.
710
-		if ( 'yes' !== $captured ) {
711
-			unset( $request['amount'] );
709
+		if ('yes' !== $captured) {
710
+			unset($request['amount']);
712 711
 		}
713 712
 
714
-		if ( $reason ) {
713
+		if ($reason) {
715 714
 			$request['metadata'] = array(
716 715
 				'reason' => $reason,
717 716
 			);
@@ -719,33 +718,33 @@  discard block
 block discarded – undo
719 718
 
720 719
 		$request['charge'] = $order->get_transaction_id();
721 720
 
722
-		WC_Stripe_Logger::log( "Info: Beginning refund for order {$order->get_transaction_id()} for the amount of {$amount}" );
721
+		WC_Stripe_Logger::log("Info: Beginning refund for order {$order->get_transaction_id()} for the amount of {$amount}");
723 722
 
724
-		$response = WC_Stripe_API::request( $request, 'refunds' );
723
+		$response = WC_Stripe_API::request($request, 'refunds');
725 724
 
726
-		if ( ! empty( $response->error ) ) {
727
-			WC_Stripe_Logger::log( 'Error: ' . $response->error->message );
725
+		if ( ! empty($response->error)) {
726
+			WC_Stripe_Logger::log('Error: ' . $response->error->message);
728 727
 
729 728
 			return $response;
730 729
 
731
-		} elseif ( ! empty( $response->id ) ) {
732
-			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 );
730
+		} elseif ( ! empty($response->id)) {
731
+			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);
733 732
 
734
-			$amount = wc_price( $response->amount / 100 );
733
+			$amount = wc_price($response->amount / 100);
735 734
 
736
-			if ( in_array( strtolower( $order->get_currency() ), WC_Stripe_Helper::no_decimal_currencies() ) ) {
737
-				$amount = wc_price( $response->amount );
735
+			if (in_array(strtolower($order->get_currency()), WC_Stripe_Helper::no_decimal_currencies())) {
736
+				$amount = wc_price($response->amount);
738 737
 			}
739 738
 
740
-			if ( isset( $response->balance_transaction ) ) {
741
-				$this->update_fees( $order, $response->balance_transaction );
739
+			if (isset($response->balance_transaction)) {
740
+				$this->update_fees($order, $response->balance_transaction);
742 741
 			}
743 742
 
744 743
 			/* translators: 1) dollar amount 2) transaction id 3) refund message */
745
-			$refund_message = ( isset( $captured ) && 'yes' === $captured ) ? sprintf( __( 'Refunded %1$s - Refund ID: %2$s - Reason: %3$s', 'woocommerce-gateway-stripe' ), $amount, $response->id, $reason ) : __( 'Pre-Authorization Released', 'woocommerce-gateway-stripe' );
744
+			$refund_message = (isset($captured) && 'yes' === $captured) ? sprintf(__('Refunded %1$s - Refund ID: %2$s - Reason: %3$s', 'woocommerce-gateway-stripe'), $amount, $response->id, $reason) : __('Pre-Authorization Released', 'woocommerce-gateway-stripe');
746 745
 
747
-			$order->add_order_note( $refund_message );
748
-			WC_Stripe_Logger::log( 'Success: ' . html_entity_decode( strip_tags( $refund_message ) ) );
746
+			$order->add_order_note($refund_message);
747
+			WC_Stripe_Logger::log('Success: ' . html_entity_decode(strip_tags($refund_message)));
749 748
 
750 749
 			return true;
751 750
 		}
@@ -760,44 +759,44 @@  discard block
 block discarded – undo
760 759
 	 */
761 760
 	public function add_payment_method() {
762 761
 		$error     = false;
763
-		$error_msg = __( 'There was a problem adding the card.', 'woocommerce-gateway-stripe' );
762
+		$error_msg = __('There was a problem adding the card.', 'woocommerce-gateway-stripe');
764 763
 		$source_id = '';
765 764
 
766
-		if ( empty( $_POST['stripe_source'] ) && empty( $_POST['stripe_token'] ) || ! is_user_logged_in() ) {
765
+		if (empty($_POST['stripe_source']) && empty($_POST['stripe_token']) || ! is_user_logged_in()) {
767 766
 			$error = true;
768 767
 		}
769 768
 
770
-		$stripe_customer = new WC_Stripe_Customer( get_current_user_id() );
769
+		$stripe_customer = new WC_Stripe_Customer(get_current_user_id());
771 770
 
772
-		$source = ! empty( $_POST['stripe_source'] ) ? wc_clean( $_POST['stripe_source'] ) : '';
771
+		$source = ! empty($_POST['stripe_source']) ? wc_clean($_POST['stripe_source']) : '';
773 772
 
774
-		$source_object = WC_Stripe_API::retrieve( 'sources/' . $source );
773
+		$source_object = WC_Stripe_API::retrieve('sources/' . $source);
775 774
 
776
-		if ( isset( $source_object ) ) {
777
-			if ( ! empty( $source_object->error ) ) {
775
+		if (isset($source_object)) {
776
+			if ( ! empty($source_object->error)) {
778 777
 				$error = true;
779 778
 			}
780 779
 
781 780
 			$source_id = $source_object->id;
782
-		} elseif ( isset( $_POST['stripe_token'] ) ) {
783
-			$source_id = wc_clean( $_POST['stripe_token'] );
781
+		} elseif (isset($_POST['stripe_token'])) {
782
+			$source_id = wc_clean($_POST['stripe_token']);
784 783
 		}
785 784
 
786
-		$response = $stripe_customer->add_source( $source_id );
785
+		$response = $stripe_customer->add_source($source_id);
787 786
 
788
-		if ( ! $response || is_wp_error( $response ) || ! empty( $response->error ) ) {
787
+		if ( ! $response || is_wp_error($response) || ! empty($response->error)) {
789 788
 			$error = true;
790 789
 		}
791 790
 
792
-		if ( $error ) {
793
-			wc_add_notice( $error_msg, 'error' );
794
-			WC_Stripe_Logger::log( 'Add payment method Error: ' . $error_msg );
791
+		if ($error) {
792
+			wc_add_notice($error_msg, 'error');
793
+			WC_Stripe_Logger::log('Add payment method Error: ' . $error_msg);
795 794
 			return;
796 795
 		}
797 796
 
798 797
 		return array(
799 798
 			'result'   => 'success',
800
-			'redirect' => wc_get_endpoint_url( 'payment-methods' ),
799
+			'redirect' => wc_get_endpoint_url('payment-methods'),
801 800
 		);
802 801
 	}
803 802
 
@@ -814,10 +813,10 @@  discard block
 block discarded – undo
814 813
 		 * Stripe expects Norwegian to only be passed NO.
815 814
 		 * But WP has different dialects.
816 815
 		 */
817
-		if ( 'NO' === substr( $locale, 3, 2 ) ) {
816
+		if ('NO' === substr($locale, 3, 2)) {
818 817
 			$locale = 'no';
819 818
 		} else {
820
-			$locale = substr( get_locale(), 0, 2 );
819
+			$locale = substr(get_locale(), 0, 2);
821 820
 		}
822 821
 
823 822
 		return $locale;
@@ -831,9 +830,9 @@  discard block
 block discarded – undo
831 830
 	 * @param string $idempotency_key
832 831
 	 * @param array $request
833 832
 	 */
834
-	public function change_idempotency_key( $idempotency_key, $request ) {
835
-		$customer = ! empty( $request['customer'] ) ? $request['customer'] : '';
836
-		$source   = ! empty( $request['source'] ) ? $request['source'] : $customer;
833
+	public function change_idempotency_key($idempotency_key, $request) {
834
+		$customer = ! empty($request['customer']) ? $request['customer'] : '';
835
+		$source   = ! empty($request['source']) ? $request['source'] : $customer;
837 836
 		$count    = $this->retry_interval - 1;
838 837
 
839 838
 		return $request['metadata']['order_id'] . '-' . $count . '-' . $source;
Please login to merge, or discard this patch.
includes/compat/class-wc-stripe-compat.php 1 patch
Spacing   +187 added lines, -187 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) {
2
+if ( ! defined('ABSPATH')) {
3 3
 	exit;
4 4
 }
5 5
 
@@ -15,23 +15,23 @@  discard block
 block discarded – undo
15 15
 	public function __construct() {
16 16
 		parent::__construct();
17 17
 
18
-		if ( class_exists( 'WC_Subscriptions_Order' ) ) {
19
-			add_action( 'woocommerce_scheduled_subscription_payment_' . $this->id, array( $this, 'scheduled_subscription_payment' ), 10, 2 );
20
-			add_action( 'wcs_resubscribe_order_created', array( $this, 'delete_resubscribe_meta' ), 10 );
21
-			add_action( 'wcs_renewal_order_created', array( $this, 'delete_renewal_meta' ), 10 );
22
-			add_action( 'woocommerce_subscription_failing_payment_method_updated_stripe', array( $this, 'update_failing_payment_method' ), 10, 2 );
18
+		if (class_exists('WC_Subscriptions_Order')) {
19
+			add_action('woocommerce_scheduled_subscription_payment_' . $this->id, array($this, 'scheduled_subscription_payment'), 10, 2);
20
+			add_action('wcs_resubscribe_order_created', array($this, 'delete_resubscribe_meta'), 10);
21
+			add_action('wcs_renewal_order_created', array($this, 'delete_renewal_meta'), 10);
22
+			add_action('woocommerce_subscription_failing_payment_method_updated_stripe', array($this, 'update_failing_payment_method'), 10, 2);
23 23
 
24 24
 			// display the credit card used for a subscription in the "My Subscriptions" table
25
-			add_filter( 'woocommerce_my_subscriptions_payment_method', array( $this, 'maybe_render_subscription_payment_method' ), 10, 2 );
25
+			add_filter('woocommerce_my_subscriptions_payment_method', array($this, 'maybe_render_subscription_payment_method'), 10, 2);
26 26
 
27 27
 			// allow store managers to manually set Stripe as the payment method on a subscription
28
-			add_filter( 'woocommerce_subscription_payment_meta', array( $this, 'add_subscription_payment_meta' ), 10, 2 );
29
-			add_filter( 'woocommerce_subscription_validate_payment_meta', array( $this, 'validate_subscription_payment_meta' ), 10, 2 );
30
-			add_filter( 'wc_stripe_display_save_payment_method_checkbox', array( $this, 'maybe_hide_save_checkbox' ) );
28
+			add_filter('woocommerce_subscription_payment_meta', array($this, 'add_subscription_payment_meta'), 10, 2);
29
+			add_filter('woocommerce_subscription_validate_payment_meta', array($this, 'validate_subscription_payment_meta'), 10, 2);
30
+			add_filter('wc_stripe_display_save_payment_method_checkbox', array($this, 'maybe_hide_save_checkbox'));
31 31
 		}
32 32
 
33
-		if ( class_exists( 'WC_Pre_Orders_Order' ) ) {
34
-			add_action( 'wc_pre_orders_process_pre_order_completion_payment_' . $this->id, array( $this, 'process_pre_order_release_payment' ) );
33
+		if (class_exists('WC_Pre_Orders_Order')) {
34
+			add_action('wc_pre_orders_process_pre_order_completion_payment_' . $this->id, array($this, 'process_pre_order_release_payment'));
35 35
 		}
36 36
 	}
37 37
 
@@ -42,8 +42,8 @@  discard block
 block discarded – undo
42 42
 	 * @since 4.0.0
43 43
 	 * @version 4.0.0
44 44
 	 */
45
-	public function maybe_hide_save_checkbox( $display_tokenization ) {
46
-		if ( WC_Subscriptions_Cart::cart_contains_subscription() ) {
45
+	public function maybe_hide_save_checkbox($display_tokenization) {
46
+		if (WC_Subscriptions_Cart::cart_contains_subscription()) {
47 47
 			return false;
48 48
 		}
49 49
 
@@ -55,8 +55,8 @@  discard block
 block discarded – undo
55 55
 	 * @param  int  $order_id
56 56
 	 * @return boolean
57 57
 	 */
58
-	public function has_subscription( $order_id ) {
59
-		return ( function_exists( 'wcs_order_contains_subscription' ) && ( wcs_order_contains_subscription( $order_id ) || wcs_is_subscription( $order_id ) || wcs_order_contains_renewal( $order_id ) ) );
58
+	public function has_subscription($order_id) {
59
+		return (function_exists('wcs_order_contains_subscription') && (wcs_order_contains_subscription($order_id) || wcs_is_subscription($order_id) || wcs_order_contains_renewal($order_id)));
60 60
 	}
61 61
 
62 62
 	/**
@@ -66,7 +66,7 @@  discard block
 block discarded – undo
66 66
 	 * @return bool
67 67
 	 */
68 68
 	public function is_subs_change_payment() {
69
-		return ( isset( $_GET['pay_for_order'] ) && isset( $_GET['change_payment_method'] ) );
69
+		return (isset($_GET['pay_for_order']) && isset($_GET['change_payment_method']));
70 70
 	}
71 71
 
72 72
 	/**
@@ -74,8 +74,8 @@  discard block
 block discarded – undo
74 74
 	 * @param  int  $order_id
75 75
 	 * @return boolean
76 76
 	 */
77
-	public function is_pre_order( $order_id ) {
78
-		return ( class_exists( 'WC_Pre_Orders_Order' ) && WC_Pre_Orders_Order::order_contains_pre_order( $order_id ) );
77
+	public function is_pre_order($order_id) {
78
+		return (class_exists('WC_Pre_Orders_Order') && WC_Pre_Orders_Order::order_contains_pre_order($order_id));
79 79
 	}
80 80
 
81 81
 	/**
@@ -84,27 +84,27 @@  discard block
 block discarded – undo
84 84
 	 * @since 4.0.4
85 85
 	 * @param int $order_id
86 86
 	 */
87
-	public function change_subs_payment_method( $order_id ) {
87
+	public function change_subs_payment_method($order_id) {
88 88
 		try {
89
-			$subscription    = wc_get_order( $order_id );
90
-			$source_id       = ! empty( $_POST['stripe_source'] ) ? wc_clean( $_POST['stripe_source'] ) : '';
91
-			$source_object   = $this->get_source_object( $source_id );
92
-			$prepared_source = $this->prepare_source( $source_object, get_current_user_id(), true );
89
+			$subscription    = wc_get_order($order_id);
90
+			$source_id       = ! empty($_POST['stripe_source']) ? wc_clean($_POST['stripe_source']) : '';
91
+			$source_object   = $this->get_source_object($source_id);
92
+			$prepared_source = $this->prepare_source($source_object, get_current_user_id(), true);
93 93
 
94 94
 			// Check if we don't allow prepaid credit cards.
95
-			if ( ! apply_filters( 'wc_stripe_allow_prepaid_card', true ) ) {
96
-				if ( $source_object && 'token' === $source_object->object && 'prepaid' === $source_object->card->funding ) {
97
-					$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' );
98
-					throw new WC_Stripe_Exception( print_r( $source_object, true ), $localized_message );
95
+			if ( ! apply_filters('wc_stripe_allow_prepaid_card', true)) {
96
+				if ($source_object && 'token' === $source_object->object && 'prepaid' === $source_object->card->funding) {
97
+					$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');
98
+					throw new WC_Stripe_Exception(print_r($source_object, true), $localized_message);
99 99
 				}
100 100
 			}
101 101
 
102
-			if ( empty( $prepared_source->source ) ) {
103
-				$localized_message = __( 'Payment processing failed. Please retry.', 'woocommerce-gateway-stripe' );
104
-				throw new WC_Stripe_Exception( print_r( $prepared_source, true ), $localized_message );
102
+			if (empty($prepared_source->source)) {
103
+				$localized_message = __('Payment processing failed. Please retry.', 'woocommerce-gateway-stripe');
104
+				throw new WC_Stripe_Exception(print_r($prepared_source, true), $localized_message);
105 105
 			}
106 106
 
107
-			$this->save_source_to_order( $subscription, $prepared_source );
107
+			$this->save_source_to_order($subscription, $prepared_source);
108 108
 
109 109
 			/*
110 110
 			 * Check if card 3DS is required or optional with 3DS setting.
@@ -113,41 +113,41 @@  discard block
 block discarded – undo
113 113
 			 * Note that if we need to save source, the original source must be first
114 114
 			 * attached to a customer in Stripe before it can be charged.
115 115
 			 */
116
-			if ( $this->is_3ds_required( $source_object ) ) {
116
+			if ($this->is_3ds_required($source_object)) {
117 117
 				$order    = $subscription->get_parent();
118
-				$response = $this->create_3ds_source( $order, $source_object, $subscription->get_view_order_url() );
118
+				$response = $this->create_3ds_source($order, $source_object, $subscription->get_view_order_url());
119 119
 
120
-				if ( ! empty( $response->error ) ) {
120
+				if ( ! empty($response->error)) {
121 121
 					$localized_message = $response->error->message;
122 122
 
123
-					$order->add_order_note( $localized_message );
123
+					$order->add_order_note($localized_message);
124 124
 
125
-					throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message );
125
+					throw new WC_Stripe_Exception(print_r($response, true), $localized_message);
126 126
 				}
127 127
 
128 128
 				// Update order meta with 3DS source.
129
-				if ( WC_Stripe_Helper::is_pre_30() ) {
130
-					update_post_meta( $order_id, '_stripe_source_id', $response->id );
129
+				if (WC_Stripe_Helper::is_pre_30()) {
130
+					update_post_meta($order_id, '_stripe_source_id', $response->id);
131 131
 				} else {
132
-					$subscription->update_meta_data( '_stripe_source_id', $response->id );
132
+					$subscription->update_meta_data('_stripe_source_id', $response->id);
133 133
 					$subscription->save();
134 134
 				}
135 135
 
136
-				WC_Stripe_Logger::log( 'Info: Redirecting to 3DS...' );
136
+				WC_Stripe_Logger::log('Info: Redirecting to 3DS...');
137 137
 
138 138
 				return array(
139 139
 					'result'   => 'success',
140
-					'redirect' => esc_url_raw( $response->redirect->url ),
140
+					'redirect' => esc_url_raw($response->redirect->url),
141 141
 				);
142 142
 			}
143 143
 
144 144
 			return array(
145 145
 				'result'   => 'success',
146
-				'redirect' => $this->get_return_url( $subscription ),
146
+				'redirect' => $this->get_return_url($subscription),
147 147
 			);
148
-		} catch ( WC_Stripe_Exception $e ) {
149
-			wc_add_notice( $e->getLocalizedMessage(), 'error' );
150
-			WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() );
148
+		} catch (WC_Stripe_Exception $e) {
149
+			wc_add_notice($e->getLocalizedMessage(), 'error');
150
+			WC_Stripe_Logger::log('Error: ' . $e->getMessage());
151 151
 		}
152 152
 	}
153 153
 
@@ -156,18 +156,18 @@  discard block
 block discarded – undo
156 156
 	 * @param  int $order_id
157 157
 	 * @return array
158 158
 	 */
159
-	public function process_payment( $order_id, $retry = true, $force_save_source = false ) {
160
-		if ( $this->has_subscription( $order_id ) ) {
161
-			if ( $this->is_subs_change_payment() ) {
162
-				return $this->change_subs_payment_method( $order_id );
159
+	public function process_payment($order_id, $retry = true, $force_save_source = false) {
160
+		if ($this->has_subscription($order_id)) {
161
+			if ($this->is_subs_change_payment()) {
162
+				return $this->change_subs_payment_method($order_id);
163 163
 			}
164 164
 
165 165
 			// Regular payment with force customer enabled
166
-			return parent::process_payment( $order_id, true, true );
167
-		} elseif ( $this->is_pre_order( $order_id ) ) {
168
-			return $this->process_pre_order( $order_id, $retry, $force_save_source );
166
+			return parent::process_payment($order_id, true, true);
167
+		} elseif ($this->is_pre_order($order_id)) {
168
+			return $this->process_pre_order($order_id, $retry, $force_save_source);
169 169
 		} else {
170
-			return parent::process_payment( $order_id, $retry, $force_save_source );
170
+			return parent::process_payment($order_id, $retry, $force_save_source);
171 171
 		}
172 172
 	}
173 173
 
@@ -177,24 +177,24 @@  discard block
 block discarded – undo
177 177
 	 * @since 3.1.0
178 178
 	 * @version 4.0.0
179 179
 	 */
180
-	public function save_source_to_order( $order, $source ) {
181
-		parent::save_source_to_order( $order, $source );
180
+	public function save_source_to_order($order, $source) {
181
+		parent::save_source_to_order($order, $source);
182 182
 
183 183
 		$order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
184 184
 
185 185
 		// Also store it on the subscriptions being purchased or paid for in the order
186
-		if ( function_exists( 'wcs_order_contains_subscription' ) && wcs_order_contains_subscription( $order_id ) ) {
187
-			$subscriptions = wcs_get_subscriptions_for_order( $order_id );
188
-		} elseif ( function_exists( 'wcs_order_contains_renewal' ) && wcs_order_contains_renewal( $order_id ) ) {
189
-			$subscriptions = wcs_get_subscriptions_for_renewal_order( $order_id );
186
+		if (function_exists('wcs_order_contains_subscription') && wcs_order_contains_subscription($order_id)) {
187
+			$subscriptions = wcs_get_subscriptions_for_order($order_id);
188
+		} elseif (function_exists('wcs_order_contains_renewal') && wcs_order_contains_renewal($order_id)) {
189
+			$subscriptions = wcs_get_subscriptions_for_renewal_order($order_id);
190 190
 		} else {
191 191
 			$subscriptions = array();
192 192
 		}
193 193
 
194
-		foreach ( $subscriptions as $subscription ) {
194
+		foreach ($subscriptions as $subscription) {
195 195
 			$subscription_id = WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id();
196
-			update_post_meta( $subscription_id, '_stripe_customer_id', $source->customer );
197
-			update_post_meta( $subscription_id, '_stripe_source_id', $source->source );
196
+			update_post_meta($subscription_id, '_stripe_customer_id', $source->customer);
197
+			update_post_meta($subscription_id, '_stripe_source_id', $source->source);
198 198
 		}
199 199
 	}
200 200
 
@@ -207,45 +207,45 @@  discard block
 block discarded – undo
207 207
 	 * @param mixed $renewal_order
208 208
 	 * @param bool $is_retry Is this a retry process.
209 209
 	 */
210
-	public function process_subscription_payment( $amount = 0.0, $renewal_order, $is_retry = false ) {
211
-		if ( $amount * 100 < WC_Stripe_Helper::get_minimum_amount() ) {
210
+	public function process_subscription_payment($amount = 0.0, $renewal_order, $is_retry = false) {
211
+		if ($amount * 100 < WC_Stripe_Helper::get_minimum_amount()) {
212 212
 			/* translators: minimum amount */
213
-			return new WP_Error( 'stripe_error', sprintf( __( 'Sorry, the minimum allowed order total is %1$s to use this payment method.', 'woocommerce-gateway-stripe' ), wc_price( WC_Stripe_Helper::get_minimum_amount() / 100 ) ) );
213
+			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)));
214 214
 		}
215 215
 
216 216
 		$order_id = WC_Stripe_Helper::is_pre_30() ? $renewal_order->id : $renewal_order->get_id();
217 217
 
218 218
 		// Get source from order
219
-		$prepared_source = $this->prepare_order_source( $renewal_order );
219
+		$prepared_source = $this->prepare_order_source($renewal_order);
220 220
 
221
-		if ( ! $prepared_source->customer ) {
222
-			return new WP_Error( 'stripe_error', __( 'Customer not found', 'woocommerce-gateway-stripe' ) );
221
+		if ( ! $prepared_source->customer) {
222
+			return new WP_Error('stripe_error', __('Customer not found', 'woocommerce-gateway-stripe'));
223 223
 		}
224 224
 
225
-		WC_Stripe_Logger::log( "Info: Begin processing subscription payment for order {$order_id} for the amount of {$amount}" );
225
+		WC_Stripe_Logger::log("Info: Begin processing subscription payment for order {$order_id} for the amount of {$amount}");
226 226
 
227
-		if ( $is_retry ) {
227
+		if ($is_retry) {
228 228
 			// Passing empty source with charge customer default.
229 229
 			$prepared_source->source = '';
230 230
 		}
231 231
 
232
-		$request            = $this->generate_payment_request( $renewal_order, $prepared_source );
232
+		$request            = $this->generate_payment_request($renewal_order, $prepared_source);
233 233
 		$request['capture'] = 'true';
234
-		$request['amount']  = WC_Stripe_Helper::get_stripe_amount( $amount, $request['currency'] );
235
-		$response           = WC_Stripe_API::request( $request );
234
+		$request['amount']  = WC_Stripe_Helper::get_stripe_amount($amount, $request['currency']);
235
+		$response           = WC_Stripe_API::request($request);
236 236
 
237
-		if ( ! empty( $response->error ) || is_wp_error( $response ) ) {
238
-			if ( $is_retry ) {
237
+		if ( ! empty($response->error) || is_wp_error($response)) {
238
+			if ($is_retry) {
239 239
 				/* translators: error message */
240
-				$renewal_order->update_status( 'failed', sprintf( __( 'Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe' ), $response->error->message ) );
240
+				$renewal_order->update_status('failed', sprintf(__('Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe'), $response->error->message));
241 241
 			}
242 242
 
243 243
 			return $response; // Default catch all errors.
244 244
 		}
245 245
 
246
-		$this->process_response( $response, $renewal_order );
246
+		$this->process_response($response, $renewal_order);
247 247
 
248
-		if ( ! $is_retry ) {
248
+		if ( ! $is_retry) {
249 249
 			return $response;
250 250
 		}
251 251
 	}
@@ -254,21 +254,21 @@  discard block
 block discarded – undo
254 254
 	 * Don't transfer Stripe customer/token meta to resubscribe orders.
255 255
 	 * @param int $resubscribe_order The order created for the customer to resubscribe to the old expired/cancelled subscription
256 256
 	 */
257
-	public function delete_resubscribe_meta( $resubscribe_order ) {
258
-		delete_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id() ), '_stripe_customer_id' );
259
-		delete_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id() ), '_stripe_source_id' );
257
+	public function delete_resubscribe_meta($resubscribe_order) {
258
+		delete_post_meta((WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id()), '_stripe_customer_id');
259
+		delete_post_meta((WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id()), '_stripe_source_id');
260 260
 		// For BW compat will remove in future
261
-		delete_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id() ), '_stripe_card_id' );
262
-		$this->delete_renewal_meta( $resubscribe_order );
261
+		delete_post_meta((WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id()), '_stripe_card_id');
262
+		$this->delete_renewal_meta($resubscribe_order);
263 263
 	}
264 264
 
265 265
 	/**
266 266
 	 * Don't transfer Stripe fee/ID meta to renewal orders.
267 267
 	 * @param int $resubscribe_order The order created for the customer to resubscribe to the old expired/cancelled subscription
268 268
 	 */
269
-	public function delete_renewal_meta( $renewal_order ) {
270
-		delete_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $renewal_order->id : $renewal_order->get_id() ), 'Stripe Fee' );
271
-		delete_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $renewal_order->id : $renewal_order->get_id() ), 'Net Revenue From Stripe' );
269
+	public function delete_renewal_meta($renewal_order) {
270
+		delete_post_meta((WC_Stripe_Helper::is_pre_30() ? $renewal_order->id : $renewal_order->get_id()), 'Stripe Fee');
271
+		delete_post_meta((WC_Stripe_Helper::is_pre_30() ? $renewal_order->id : $renewal_order->get_id()), 'Net Revenue From Stripe');
272 272
 		return $renewal_order;
273 273
 	}
274 274
 
@@ -278,21 +278,21 @@  discard block
 block discarded – undo
278 278
 	 * @param $amount_to_charge float The amount to charge.
279 279
 	 * @param $renewal_order WC_Order A WC_Order object created to record the renewal payment.
280 280
 	 */
281
-	public function scheduled_subscription_payment( $amount_to_charge, $renewal_order ) {
282
-		$response = $this->process_subscription_payment( $amount_to_charge, $renewal_order );
281
+	public function scheduled_subscription_payment($amount_to_charge, $renewal_order) {
282
+		$response = $this->process_subscription_payment($amount_to_charge, $renewal_order);
283 283
 
284
-		if ( is_wp_error( $response ) ) {
284
+		if (is_wp_error($response)) {
285 285
 			/* translators: error message */
286
-			$renewal_order->update_status( 'failed', sprintf( __( 'Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe' ), $response->get_error_message() ) );
286
+			$renewal_order->update_status('failed', sprintf(__('Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe'), $response->get_error_message()));
287 287
 		}
288 288
 
289
-		if ( ! empty( $response->error ) ) {
289
+		if ( ! empty($response->error)) {
290 290
 			// This is a very generic error to listen for but worth a retry before total fail.
291
-			if ( isset( $response->error->type ) && 'invalid_request_error' === $response->error->type && apply_filters( 'wc_stripe_use_default_customer_source', true ) ) {
292
-				$this->process_subscription_payment( $amount_to_charge, $renewal_order, true );
291
+			if (isset($response->error->type) && 'invalid_request_error' === $response->error->type && apply_filters('wc_stripe_use_default_customer_source', true)) {
292
+				$this->process_subscription_payment($amount_to_charge, $renewal_order, true);
293 293
 			} else {
294 294
 				/* translators: error message */
295
-				$renewal_order->update_status( 'failed', sprintf( __( 'Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe' ), $response->error->message ) );
295
+				$renewal_order->update_status('failed', sprintf(__('Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe'), $response->error->message));
296 296
 			}
297 297
 		}
298 298
 	}
@@ -301,20 +301,20 @@  discard block
 block discarded – undo
301 301
 	 * Remove order meta
302 302
 	 * @param object $order
303 303
 	 */
304
-	public function remove_order_source_before_retry( $order ) {
304
+	public function remove_order_source_before_retry($order) {
305 305
 		$order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
306
-		delete_post_meta( $order_id, '_stripe_source_id' );
306
+		delete_post_meta($order_id, '_stripe_source_id');
307 307
 		// For BW compat will remove in the future.
308
-		delete_post_meta( $order_id, '_stripe_card_id' );
308
+		delete_post_meta($order_id, '_stripe_card_id');
309 309
 	}
310 310
 
311 311
 	/**
312 312
 	 * Remove order meta
313 313
 	 * @param  object $order
314 314
 	 */
315
-	public function remove_order_customer_before_retry( $order ) {
315
+	public function remove_order_customer_before_retry($order) {
316 316
 		$order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
317
-		delete_post_meta( $order_id, '_stripe_customer_id' );
317
+		delete_post_meta($order_id, '_stripe_customer_id');
318 318
 	}
319 319
 
320 320
 	/**
@@ -326,14 +326,14 @@  discard block
 block discarded – undo
326 326
 	 * @param WC_Order $renewal_order The order which recorded the successful payment (to make up for the failed automatic payment).
327 327
 	 * @return void
328 328
 	 */
329
-	public function update_failing_payment_method( $subscription, $renewal_order ) {
330
-		if ( WC_Stripe_Helper::is_pre_30() ) {
331
-			update_post_meta( $subscription->id, '_stripe_customer_id', $renewal_order->stripe_customer_id );
332
-			update_post_meta( $subscription->id, '_stripe_source_id', $renewal_order->stripe_source_id );
329
+	public function update_failing_payment_method($subscription, $renewal_order) {
330
+		if (WC_Stripe_Helper::is_pre_30()) {
331
+			update_post_meta($subscription->id, '_stripe_customer_id', $renewal_order->stripe_customer_id);
332
+			update_post_meta($subscription->id, '_stripe_source_id', $renewal_order->stripe_source_id);
333 333
 
334 334
 		} else {
335
-			update_post_meta( $subscription->get_id(), '_stripe_customer_id', $renewal_order->get_meta( '_stripe_customer_id', true ) );
336
-			update_post_meta( $subscription->get_id(), '_stripe_source_id', $renewal_order->get_meta( '_stripe_source_id', true ) );
335
+			update_post_meta($subscription->get_id(), '_stripe_customer_id', $renewal_order->get_meta('_stripe_customer_id', true));
336
+			update_post_meta($subscription->get_id(), '_stripe_source_id', $renewal_order->get_meta('_stripe_source_id', true));
337 337
 		}
338 338
 	}
339 339
 
@@ -346,21 +346,21 @@  discard block
 block discarded – undo
346 346
 	 * @param WC_Subscription $subscription An instance of a subscription object
347 347
 	 * @return array
348 348
 	 */
349
-	public function add_subscription_payment_meta( $payment_meta, $subscription ) {
350
-		$source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_source_id', true );
349
+	public function add_subscription_payment_meta($payment_meta, $subscription) {
350
+		$source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_source_id', true);
351 351
 
352 352
 		// For BW compat will remove in future.
353
-		if ( empty( $source_id ) ) {
354
-			$source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_card_id', true );
353
+		if (empty($source_id)) {
354
+			$source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_card_id', true);
355 355
 
356 356
 			// Take this opportunity to update the key name.
357
-			WC_Stripe_Helper::is_pre_30() ? update_post_meta( $subscription->id, '_stripe_source_id', $source_id ) : update_post_meta( $subscription->get_id(), '_stripe_source_id', $source_id );
357
+			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);
358 358
 		}
359 359
 
360
-		$payment_meta[ $this->id ] = array(
360
+		$payment_meta[$this->id] = array(
361 361
 			'post_meta' => array(
362 362
 				'_stripe_customer_id' => array(
363
-					'value' => get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_customer_id', true ),
363
+					'value' => get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_customer_id', true),
364 364
 					'label' => 'Stripe Customer ID',
365 365
 				),
366 366
 				'_stripe_source_id' => array(
@@ -383,22 +383,22 @@  discard block
 block discarded – undo
383 383
 	 * @param array $payment_meta associative array of meta data required for automatic payments
384 384
 	 * @return array
385 385
 	 */
386
-	public function validate_subscription_payment_meta( $payment_method_id, $payment_meta ) {
387
-		if ( $this->id === $payment_method_id ) {
386
+	public function validate_subscription_payment_meta($payment_method_id, $payment_meta) {
387
+		if ($this->id === $payment_method_id) {
388 388
 
389
-			if ( ! isset( $payment_meta['post_meta']['_stripe_customer_id']['value'] ) || empty( $payment_meta['post_meta']['_stripe_customer_id']['value'] ) ) {
390
-				throw new Exception( __( 'A "Stripe Customer ID" value is required.', 'woocommerce-gateway-stripe' ) );
391
-			} elseif ( 0 !== strpos( $payment_meta['post_meta']['_stripe_customer_id']['value'], 'cus_' ) ) {
392
-				throw new Exception( __( 'Invalid customer ID. A valid "Stripe Customer ID" must begin with "cus_".', 'woocommerce-gateway-stripe' ) );
389
+			if ( ! isset($payment_meta['post_meta']['_stripe_customer_id']['value']) || empty($payment_meta['post_meta']['_stripe_customer_id']['value'])) {
390
+				throw new Exception(__('A "Stripe Customer ID" value is required.', 'woocommerce-gateway-stripe'));
391
+			} elseif (0 !== strpos($payment_meta['post_meta']['_stripe_customer_id']['value'], 'cus_')) {
392
+				throw new Exception(__('Invalid customer ID. A valid "Stripe Customer ID" must begin with "cus_".', 'woocommerce-gateway-stripe'));
393 393
 			}
394 394
 
395 395
 			if (
396
-				( ! empty( $payment_meta['post_meta']['_stripe_source_id']['value'] )
397
-				&& 0 !== strpos( $payment_meta['post_meta']['_stripe_source_id']['value'], 'card_' ) )
398
-				&& ( ! empty( $payment_meta['post_meta']['_stripe_source_id']['value'] )
399
-				&& 0 !== strpos( $payment_meta['post_meta']['_stripe_source_id']['value'], 'src_' ) ) ) {
396
+				( ! empty($payment_meta['post_meta']['_stripe_source_id']['value'])
397
+				&& 0 !== strpos($payment_meta['post_meta']['_stripe_source_id']['value'], 'card_'))
398
+				&& ( ! empty($payment_meta['post_meta']['_stripe_source_id']['value'])
399
+				&& 0 !== strpos($payment_meta['post_meta']['_stripe_source_id']['value'], 'src_')) ) {
400 400
 
401
-				throw new Exception( __( 'Invalid source ID. A valid source "Stripe Source ID" must begin with "src_" or "card_".', 'woocommerce-gateway-stripe' ) );
401
+				throw new Exception(__('Invalid source ID. A valid source "Stripe Source ID" must begin with "src_" or "card_".', 'woocommerce-gateway-stripe'));
402 402
 			}
403 403
 		}
404 404
 	}
@@ -411,91 +411,91 @@  discard block
 block discarded – undo
411 411
 	 * @param WC_Subscription $subscription the subscription details
412 412
 	 * @return string the subscription payment method
413 413
 	 */
414
-	public function maybe_render_subscription_payment_method( $payment_method_to_display, $subscription ) {
414
+	public function maybe_render_subscription_payment_method($payment_method_to_display, $subscription) {
415 415
 		$customer_user = WC_Stripe_Helper::is_pre_30() ? $subscription->customer_user : $subscription->get_customer_id();
416 416
 
417 417
 		// bail for other payment methods
418
-		if ( ( WC_Stripe_Helper::is_pre_30() ? $subscription->payment_method : $subscription->get_payment_method() ) !== $this->id || ! $customer_user ) {
418
+		if ((WC_Stripe_Helper::is_pre_30() ? $subscription->payment_method : $subscription->get_payment_method()) !== $this->id || ! $customer_user) {
419 419
 			return $payment_method_to_display;
420 420
 		}
421 421
 
422
-		$stripe_source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_source_id', true );
422
+		$stripe_source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_source_id', true);
423 423
 
424 424
 		// For BW compat will remove in future.
425
-		if ( empty( $stripe_source_id ) ) {
426
-			$stripe_source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_card_id', true );
425
+		if (empty($stripe_source_id)) {
426
+			$stripe_source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_card_id', true);
427 427
 
428 428
 			// Take this opportunity to update the key name.
429
-			WC_Stripe_Helper::is_pre_30() ? update_post_meta( $subscription->id, '_stripe_source_id', $stripe_source_id ) : update_post_meta( $subscription->get_id(), '_stripe_source_id', $stripe_source_id );
429
+			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);
430 430
 		}
431 431
 
432 432
 		$stripe_customer    = new WC_Stripe_Customer();
433
-		$stripe_customer_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_customer_id', true );
433
+		$stripe_customer_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_customer_id', true);
434 434
 
435 435
 		// If we couldn't find a Stripe customer linked to the subscription, fallback to the user meta data.
436
-		if ( ! $stripe_customer_id || ! is_string( $stripe_customer_id ) ) {
436
+		if ( ! $stripe_customer_id || ! is_string($stripe_customer_id)) {
437 437
 			$user_id            = $customer_user;
438
-			$stripe_customer_id = get_user_meta( $user_id, '_stripe_customer_id', true );
439
-			$stripe_source_id   = get_user_meta( $user_id, '_stripe_source_id', true );
438
+			$stripe_customer_id = get_user_meta($user_id, '_stripe_customer_id', true);
439
+			$stripe_source_id   = get_user_meta($user_id, '_stripe_source_id', true);
440 440
 
441 441
 			// For BW compat will remove in future.
442
-			if ( empty( $stripe_source_id ) ) {
443
-				$stripe_source_id = get_user_meta( $user_id, '_stripe_card_id', true );
442
+			if (empty($stripe_source_id)) {
443
+				$stripe_source_id = get_user_meta($user_id, '_stripe_card_id', true);
444 444
 
445 445
 				// Take this opportunity to update the key name.
446
-				update_user_meta( $user_id, '_stripe_source_id', $stripe_source_id );
446
+				update_user_meta($user_id, '_stripe_source_id', $stripe_source_id);
447 447
 			}
448 448
 		}
449 449
 
450 450
 		// If we couldn't find a Stripe customer linked to the account, fallback to the order meta data.
451
-		if ( ( ! $stripe_customer_id || ! is_string( $stripe_customer_id ) ) && false !== $subscription->order ) {
452
-			$stripe_customer_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id() ), '_stripe_customer_id', true );
453
-			$stripe_source_id   = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id() ), '_stripe_source_id', true );
451
+		if (( ! $stripe_customer_id || ! is_string($stripe_customer_id)) && false !== $subscription->order) {
452
+			$stripe_customer_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id()), '_stripe_customer_id', true);
453
+			$stripe_source_id   = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id()), '_stripe_source_id', true);
454 454
 
455 455
 			// For BW compat will remove in future.
456
-			if ( empty( $stripe_source_id ) ) {
457
-				$stripe_source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id() ), '_stripe_card_id', true );
456
+			if (empty($stripe_source_id)) {
457
+				$stripe_source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id()), '_stripe_card_id', true);
458 458
 
459 459
 				// Take this opportunity to update the key name.
460
-				WC_Stripe_Helper::is_pre_30() ? update_post_meta( $subscription->order->id, '_stripe_source_id', $stripe_source_id ) : update_post_meta( $subscription->get_parent_id(), '_stripe_source_id', $stripe_source_id );
460
+				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);
461 461
 			}
462 462
 		}
463 463
 
464
-		$stripe_customer->set_id( $stripe_customer_id );
464
+		$stripe_customer->set_id($stripe_customer_id);
465 465
 		$sources = $stripe_customer->get_sources();
466 466
 
467
-		if ( $sources ) {
467
+		if ($sources) {
468 468
 			$found_source = false;
469
-			foreach ( $sources as $source ) {
470
-				if ( isset( $source->type ) && 'card' === $source->type ) {
469
+			foreach ($sources as $source) {
470
+				if (isset($source->type) && 'card' === $source->type) {
471 471
 					$card = $source->card;
472
-				} elseif ( isset( $source->object ) && 'card' === $source->object ) {
472
+				} elseif (isset($source->object) && 'card' === $source->object) {
473 473
 					$card = $source;
474 474
 				}
475 475
 
476
-				if ( $source->id === $stripe_source_id ) {
476
+				if ($source->id === $stripe_source_id) {
477 477
 					$found_source = true;
478 478
 
479
-					if ( $card ) {
479
+					if ($card) {
480 480
 						/* translators: 1) card brand 2) last 4 digits */
481
-						$payment_method_to_display = sprintf( __( 'Via %1$s card ending in %2$s', 'woocommerce-gateway-stripe' ), ( isset( $card->brand ) ? $card->brand : __( 'N/A', 'woocommerce-gateway-stripe' ) ), $card->last4 );
481
+						$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);
482 482
 					} else {
483
-						$payment_method_to_display = __( 'N/A', 'woocommerce-gateway-stripe' );
483
+						$payment_method_to_display = __('N/A', 'woocommerce-gateway-stripe');
484 484
 					}
485 485
 					break;
486 486
 				}
487 487
 			}
488 488
 
489
-			if ( ! $found_source ) {
490
-				if ( 'card' === $sources[0]->type ) {
489
+			if ( ! $found_source) {
490
+				if ('card' === $sources[0]->type) {
491 491
 					$card = $sources[0]->card;
492 492
 				}
493 493
 
494
-				if ( $card ) {
494
+				if ($card) {
495 495
 					/* translators: 1) card brand 2) last 4 digits */
496
-					$payment_method_to_display = sprintf( __( 'Via %1$s card ending in %2$s', 'woocommerce-gateway-stripe' ), ( isset( $card->brand ) ? $card->brand : __( 'N/A', 'woocommerce-gateway-stripe' ) ), $card->last4 );
496
+					$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);
497 497
 				} else {
498
-					$payment_method_to_display = __( 'N/A', 'woocommerce-gateway-stripe' );
498
+					$payment_method_to_display = __('N/A', 'woocommerce-gateway-stripe');
499 499
 				}
500 500
 			}
501 501
 		}
@@ -508,43 +508,43 @@  discard block
 block discarded – undo
508 508
 	 * @param int $order_id
509 509
 	 * @return array
510 510
 	 */
511
-	public function process_pre_order( $order_id, $retry, $force_save_source ) {
512
-		if ( WC_Pre_Orders_Order::order_requires_payment_tokenization( $order_id ) ) {
511
+	public function process_pre_order($order_id, $retry, $force_save_source) {
512
+		if (WC_Pre_Orders_Order::order_requires_payment_tokenization($order_id)) {
513 513
 			try {
514
-				$order = wc_get_order( $order_id );
514
+				$order = wc_get_order($order_id);
515 515
 
516
-				if ( $order->get_total() * 100 < WC_Stripe_Helper::get_minimum_amount() ) {
516
+				if ($order->get_total() * 100 < WC_Stripe_Helper::get_minimum_amount()) {
517 517
 					/* translators: minimum amount */
518
-					throw new Exception( sprintf( __( 'Sorry, the minimum allowed order total is %1$s to use this payment method.', 'woocommerce-gateway-stripe' ), wc_price( WC_Stripe_Helper::get_minimum_amount() / 100 ) ) );
518
+					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)));
519 519
 				}
520 520
 
521
-				$source_id       = ! empty( $_POST['stripe_source'] ) ? wc_clean( $_POST['stripe_source'] ) : '';
522
-				$source          = $this->prepare_source( $this->get_source_object( $source_id ), get_current_user_id(), true );
521
+				$source_id       = ! empty($_POST['stripe_source']) ? wc_clean($_POST['stripe_source']) : '';
522
+				$source          = $this->prepare_source($this->get_source_object($source_id), get_current_user_id(), true);
523 523
 
524 524
 				// We need a source on file to continue.
525
-				if ( empty( $source->customer ) || empty( $source->source ) ) {
526
-					throw new Exception( __( 'Unable to store payment details. Please try again.', 'woocommerce-gateway-stripe' ) );
525
+				if (empty($source->customer) || empty($source->source)) {
526
+					throw new Exception(__('Unable to store payment details. Please try again.', 'woocommerce-gateway-stripe'));
527 527
 				}
528 528
 
529
-				$this->save_source_to_order( $order, $source );
529
+				$this->save_source_to_order($order, $source);
530 530
 
531 531
 				// Remove cart
532 532
 				WC()->cart->empty_cart();
533 533
 
534 534
 				// Is pre ordered!
535
-				WC_Pre_Orders_Order::mark_order_as_pre_ordered( $order );
535
+				WC_Pre_Orders_Order::mark_order_as_pre_ordered($order);
536 536
 
537 537
 				// Return thank you page redirect
538 538
 				return array(
539 539
 					'result'   => 'success',
540
-					'redirect' => $this->get_return_url( $order ),
540
+					'redirect' => $this->get_return_url($order),
541 541
 				);
542
-			} catch ( Exception $e ) {
543
-				wc_add_notice( $e->getMessage(), 'error' );
542
+			} catch (Exception $e) {
543
+				wc_add_notice($e->getMessage(), 'error');
544 544
 				return;
545 545
 			}
546 546
 		} else {
547
-			return parent::process_payment( $order_id, $retry, $force_save_source );
547
+			return parent::process_payment($order_id, $retry, $force_save_source);
548 548
 		}
549 549
 	}
550 550
 
@@ -553,7 +553,7 @@  discard block
 block discarded – undo
553 553
 	 * @param WC_Order $order
554 554
 	 * @return void
555 555
 	 */
556
-	public function process_pre_order_release_payment( $order ) {
556
+	public function process_pre_order_release_payment($order) {
557 557
 		try {
558 558
 			// Define some callbacks if the first attempt fails.
559 559
 			$retry_callbacks = array(
@@ -561,33 +561,33 @@  discard block
 block discarded – undo
561 561
 				'remove_order_customer_before_retry',
562 562
 			);
563 563
 
564
-			while ( 1 ) {
565
-				$source   = $this->prepare_order_source( $order );
566
-				$response = WC_Stripe_API::request( $this->generate_payment_request( $order, $source ) );
564
+			while (1) {
565
+				$source   = $this->prepare_order_source($order);
566
+				$response = WC_Stripe_API::request($this->generate_payment_request($order, $source));
567 567
 
568
-				if ( ! empty( $response->error ) ) {
569
-					if ( 0 === sizeof( $retry_callbacks ) ) {
570
-						throw new Exception( $response->error->message );
568
+				if ( ! empty($response->error)) {
569
+					if (0 === sizeof($retry_callbacks)) {
570
+						throw new Exception($response->error->message);
571 571
 					} else {
572
-						$retry_callback = array_shift( $retry_callbacks );
573
-						call_user_func( array( $this, $retry_callback ), $order );
572
+						$retry_callback = array_shift($retry_callbacks);
573
+						call_user_func(array($this, $retry_callback), $order);
574 574
 					}
575 575
 				} else {
576 576
 					// Successful
577
-					$this->process_response( $response, $order );
577
+					$this->process_response($response, $order);
578 578
 					break;
579 579
 				}
580 580
 			}
581
-		} catch ( Exception $e ) {
581
+		} catch (Exception $e) {
582 582
 			/* translators: error message */
583
-			$order_note = sprintf( __( 'Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe' ), $e->getMessage() );
583
+			$order_note = sprintf(__('Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe'), $e->getMessage());
584 584
 
585 585
 			// Mark order as failed if not already set,
586 586
 			// otherwise, make sure we add the order note so we can detect when someone fails to check out multiple times
587
-			if ( ! $order->has_status( 'failed' ) ) {
588
-				$order->update_status( 'failed', $order_note );
587
+			if ( ! $order->has_status('failed')) {
588
+				$order->update_status('failed', $order_note);
589 589
 			} else {
590
-				$order->add_order_note( $order_note );
590
+				$order->add_order_note($order_note);
591 591
 			}
592 592
 		}
593 593
 	}
Please login to merge, or discard this patch.
includes/compat/class-wc-stripe-sepa-compat.php 1 patch
Spacing   +161 added lines, -161 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( WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id() ) ) {
95
+	public function add_subscription_meta_data($metadata, $order) {
96
+		if ( ! $this->has_subscription(WC_Stripe_Helper::is_pre_30() ? $order->id : $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_to_order( $order, $source ) {
113
-		parent::save_source_to_order( $order, $source );
112
+	public function save_source_to_order($order, $source) {
113
+		parent::save_source_to_order($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
 
@@ -139,45 +139,45 @@  discard block
 block discarded – undo
139 139
 	 * @param mixed $renewal_order
140 140
 	 * @param bool $is_retry Is this a retry process.
141 141
 	 */
142
-	public function process_subscription_payment( $amount = 0.0, $renewal_order, $is_retry = false ) {
143
-		if ( $amount * 100 < WC_Stripe_Helper::get_minimum_amount() ) {
142
+	public function process_subscription_payment($amount = 0.0, $renewal_order, $is_retry = false) {
143
+		if ($amount * 100 < WC_Stripe_Helper::get_minimum_amount()) {
144 144
 			/* translators: minimum amount */
145
-			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 ) ) );
145
+			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)));
146 146
 		}
147 147
 
148 148
 		$order_id = WC_Stripe_Helper::is_pre_30() ? $renewal_order->id : $renewal_order->get_id();
149 149
 
150 150
 		// Get source from order.
151
-		$prepared_source = $this->prepare_order_source( $renewal_order );
151
+		$prepared_source = $this->prepare_order_source($renewal_order);
152 152
 
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
-		if ( $is_retry ) {
159
+		if ($is_retry) {
160 160
 			// Passing empty source with charge customer default.
161 161
 			$prepared_source->source = '';
162 162
 		}
163 163
 
164
-		$request            = $this->generate_payment_request( $renewal_order, $prepared_source );
164
+		$request            = $this->generate_payment_request($renewal_order, $prepared_source);
165 165
 		$request['capture'] = 'true';
166
-		$request['amount']  = WC_Stripe_Helper::get_stripe_amount( $amount, $request['currency'] );
167
-		$response           = WC_Stripe_API::request( $request );
166
+		$request['amount']  = WC_Stripe_Helper::get_stripe_amount($amount, $request['currency']);
167
+		$response           = WC_Stripe_API::request($request);
168 168
 
169
-		if ( ! empty( $response->error ) || is_wp_error( $response ) ) {
170
-			if ( $is_retry ) {
169
+		if ( ! empty($response->error) || is_wp_error($response)) {
170
+			if ($is_retry) {
171 171
 				/* translators: error message */
172
-				$renewal_order->update_status( 'failed', sprintf( __( 'Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe' ), $response->error->message ) );
172
+				$renewal_order->update_status('failed', sprintf(__('Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe'), $response->error->message));
173 173
 			}
174 174
 
175 175
 			return $response; // Default catch all errors.
176 176
 		}
177 177
 
178
-		$this->process_response( $response, $renewal_order );
178
+		$this->process_response($response, $renewal_order);
179 179
 
180
-		if ( ! $is_retry ) {
180
+		if ( ! $is_retry) {
181 181
 			return $response;
182 182
 		}
183 183
 	}
@@ -186,21 +186,21 @@  discard block
 block discarded – undo
186 186
 	 * Don't transfer Stripe customer/token meta to resubscribe orders.
187 187
 	 * @param int $resubscribe_order The order created for the customer to resubscribe to the old expired/cancelled subscription
188 188
 	 */
189
-	public function delete_resubscribe_meta( $resubscribe_order ) {
190
-		delete_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id() ), '_stripe_customer_id' );
191
-		delete_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id() ), '_stripe_source_id' );
189
+	public function delete_resubscribe_meta($resubscribe_order) {
190
+		delete_post_meta((WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id()), '_stripe_customer_id');
191
+		delete_post_meta((WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id()), '_stripe_source_id');
192 192
 		// For BW compat will remove in future
193
-		delete_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id() ), '_stripe_card_id' );
194
-		$this->delete_renewal_meta( $resubscribe_order );
193
+		delete_post_meta((WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id()), '_stripe_card_id');
194
+		$this->delete_renewal_meta($resubscribe_order);
195 195
 	}
196 196
 
197 197
 	/**
198 198
 	 * Don't transfer Stripe fee/ID meta to renewal orders.
199 199
 	 * @param int $resubscribe_order The order created for the customer to resubscribe to the old expired/cancelled subscription
200 200
 	 */
201
-	public function delete_renewal_meta( $renewal_order ) {
202
-		delete_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $renewal_order->id : $renewal_order->get_id() ), 'Stripe Fee' );
203
-		delete_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $renewal_order->id : $renewal_order->get_id() ), 'Net Revenue From Stripe' );
201
+	public function delete_renewal_meta($renewal_order) {
202
+		delete_post_meta((WC_Stripe_Helper::is_pre_30() ? $renewal_order->id : $renewal_order->get_id()), 'Stripe Fee');
203
+		delete_post_meta((WC_Stripe_Helper::is_pre_30() ? $renewal_order->id : $renewal_order->get_id()), 'Net Revenue From Stripe');
204 204
 		return $renewal_order;
205 205
 	}
206 206
 
@@ -210,21 +210,21 @@  discard block
 block discarded – undo
210 210
 	 * @param $amount_to_charge float The amount to charge.
211 211
 	 * @param $renewal_order WC_Order A WC_Order object created to record the renewal payment.
212 212
 	 */
213
-	public function scheduled_subscription_payment( $amount_to_charge, $renewal_order ) {
214
-		$response = $this->process_subscription_payment( $amount_to_charge, $renewal_order );
213
+	public function scheduled_subscription_payment($amount_to_charge, $renewal_order) {
214
+		$response = $this->process_subscription_payment($amount_to_charge, $renewal_order);
215 215
 
216
-		if ( is_wp_error( $response ) ) {
216
+		if (is_wp_error($response)) {
217 217
 			/* translators: error message */
218
-			$renewal_order->update_status( 'failed', sprintf( __( 'Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe' ), $response->get_error_message() ) );
218
+			$renewal_order->update_status('failed', sprintf(__('Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe'), $response->get_error_message()));
219 219
 		}
220 220
 
221
-		if ( ! empty( $response->error ) ) {
221
+		if ( ! empty($response->error)) {
222 222
 			// This is a very generic error to listen for but worth a retry before total fail.
223
-			if ( isset( $response->error->type ) && 'invalid_request_error' === $response->error->type && apply_filters( 'wc_stripe_use_default_customer_source', true ) ) {
224
-				$this->process_subscription_payment( $amount_to_charge, $renewal_order, true );
223
+			if (isset($response->error->type) && 'invalid_request_error' === $response->error->type && apply_filters('wc_stripe_use_default_customer_source', true)) {
224
+				$this->process_subscription_payment($amount_to_charge, $renewal_order, true);
225 225
 			} else {
226 226
 				/* translators: error message */
227
-				$renewal_order->update_status( 'failed', sprintf( __( 'Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe' ), $response->error->message ) );
227
+				$renewal_order->update_status('failed', sprintf(__('Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe'), $response->error->message));
228 228
 			}
229 229
 		}
230 230
 	}
@@ -233,20 +233,20 @@  discard block
 block discarded – undo
233 233
 	 * Remove order meta
234 234
 	 * @param  object $order
235 235
 	 */
236
-	public function remove_order_source_before_retry( $order ) {
236
+	public function remove_order_source_before_retry($order) {
237 237
 		$order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
238
-		delete_post_meta( $order_id, '_stripe_source_id' );
238
+		delete_post_meta($order_id, '_stripe_source_id');
239 239
 		// For BW compat will remove in the future.
240
-		delete_post_meta( $order_id, '_stripe_card_id' );
240
+		delete_post_meta($order_id, '_stripe_card_id');
241 241
 	}
242 242
 
243 243
 	/**
244 244
 	 * Remove order meta
245 245
 	 * @param object $order
246 246
 	 */
247
-	public function remove_order_customer_before_retry( $order ) {
247
+	public function remove_order_customer_before_retry($order) {
248 248
 		$order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
249
-		delete_post_meta( $order_id, '_stripe_customer_id' );
249
+		delete_post_meta($order_id, '_stripe_customer_id');
250 250
 	}
251 251
 
252 252
 	/**
@@ -258,14 +258,14 @@  discard block
 block discarded – undo
258 258
 	 * @param WC_Order $renewal_order The order which recorded the successful payment (to make up for the failed automatic payment).
259 259
 	 * @return void
260 260
 	 */
261
-	public function update_failing_payment_method( $subscription, $renewal_order ) {
262
-		if ( WC_Stripe_Helper::is_pre_30() ) {
263
-			update_post_meta( $subscription->id, '_stripe_customer_id', $renewal_order->stripe_customer_id );
264
-			update_post_meta( $subscription->id, '_stripe_source_id', $renewal_order->stripe_source_id );
261
+	public function update_failing_payment_method($subscription, $renewal_order) {
262
+		if (WC_Stripe_Helper::is_pre_30()) {
263
+			update_post_meta($subscription->id, '_stripe_customer_id', $renewal_order->stripe_customer_id);
264
+			update_post_meta($subscription->id, '_stripe_source_id', $renewal_order->stripe_source_id);
265 265
 
266 266
 		} else {
267
-			update_post_meta( $subscription->get_id(), '_stripe_customer_id', $renewal_order->get_meta( '_stripe_customer_id', true ) );
268
-			update_post_meta( $subscription->get_id(), '_stripe_source_id', $renewal_order->get_meta( '_stripe_source_id', true ) );
267
+			update_post_meta($subscription->get_id(), '_stripe_customer_id', $renewal_order->get_meta('_stripe_customer_id', true));
268
+			update_post_meta($subscription->get_id(), '_stripe_source_id', $renewal_order->get_meta('_stripe_source_id', true));
269 269
 		}
270 270
 	}
271 271
 
@@ -278,21 +278,21 @@  discard block
 block discarded – undo
278 278
 	 * @param WC_Subscription $subscription An instance of a subscription object
279 279
 	 * @return array
280 280
 	 */
281
-	public function add_subscription_payment_meta( $payment_meta, $subscription ) {
282
-		$source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_source_id', true );
281
+	public function add_subscription_payment_meta($payment_meta, $subscription) {
282
+		$source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_source_id', true);
283 283
 
284 284
 		// For BW compat will remove in future.
285
-		if ( empty( $source_id ) ) {
286
-			$source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_card_id', true );
285
+		if (empty($source_id)) {
286
+			$source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_card_id', true);
287 287
 
288 288
 			// Take this opportunity to update the key name.
289
-			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 );
289
+			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);
290 290
 		}
291 291
 
292
-		$payment_meta[ $this->id ] = array(
292
+		$payment_meta[$this->id] = array(
293 293
 			'post_meta' => array(
294 294
 				'_stripe_customer_id' => array(
295
-					'value' => get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_customer_id', true ),
295
+					'value' => get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_customer_id', true),
296 296
 					'label' => 'Stripe Customer ID',
297 297
 				),
298 298
 				'_stripe_source_id' => array(
@@ -313,22 +313,22 @@  discard block
 block discarded – undo
313 313
 	 * @param array $payment_meta associative array of meta data required for automatic payments
314 314
 	 * @return array
315 315
 	 */
316
-	public function validate_subscription_payment_meta( $payment_method_id, $payment_meta ) {
317
-		if ( $this->id === $payment_method_id ) {
316
+	public function validate_subscription_payment_meta($payment_method_id, $payment_meta) {
317
+		if ($this->id === $payment_method_id) {
318 318
 
319
-			if ( ! isset( $payment_meta['post_meta']['_stripe_customer_id']['value'] ) || empty( $payment_meta['post_meta']['_stripe_customer_id']['value'] ) ) {
320
-				throw new Exception( __( 'A "Stripe Customer ID" value is required.', 'woocommerce-gateway-stripe' ) );
321
-			} elseif ( 0 !== strpos( $payment_meta['post_meta']['_stripe_customer_id']['value'], 'cus_' ) ) {
322
-				throw new Exception( __( 'Invalid customer ID. A valid "Stripe Customer ID" must begin with "cus_".', 'woocommerce-gateway-stripe' ) );
319
+			if ( ! isset($payment_meta['post_meta']['_stripe_customer_id']['value']) || empty($payment_meta['post_meta']['_stripe_customer_id']['value'])) {
320
+				throw new Exception(__('A "Stripe Customer ID" value is required.', 'woocommerce-gateway-stripe'));
321
+			} elseif (0 !== strpos($payment_meta['post_meta']['_stripe_customer_id']['value'], 'cus_')) {
322
+				throw new Exception(__('Invalid customer ID. A valid "Stripe Customer ID" must begin with "cus_".', 'woocommerce-gateway-stripe'));
323 323
 			}
324 324
 
325 325
 			if (
326
-				( ! empty( $payment_meta['post_meta']['_stripe_source_id']['value'] )
327
-				&& 0 !== strpos( $payment_meta['post_meta']['_stripe_source_id']['value'], 'card_' ) )
328
-				&& ( ! empty( $payment_meta['post_meta']['_stripe_source_id']['value'] )
329
-				&& 0 !== strpos( $payment_meta['post_meta']['_stripe_source_id']['value'], 'src_' ) ) ) {
326
+				( ! empty($payment_meta['post_meta']['_stripe_source_id']['value'])
327
+				&& 0 !== strpos($payment_meta['post_meta']['_stripe_source_id']['value'], 'card_'))
328
+				&& ( ! empty($payment_meta['post_meta']['_stripe_source_id']['value'])
329
+				&& 0 !== strpos($payment_meta['post_meta']['_stripe_source_id']['value'], 'src_')) ) {
330 330
 
331
-				throw new Exception( __( 'Invalid source ID. A valid source "Stripe Source ID" must begin with "src_" or "card_".', 'woocommerce-gateway-stripe' ) );
331
+				throw new Exception(__('Invalid source ID. A valid source "Stripe Source ID" must begin with "src_" or "card_".', 'woocommerce-gateway-stripe'));
332 332
 			}
333 333
 		}
334 334
 	}
@@ -341,89 +341,89 @@  discard block
 block discarded – undo
341 341
 	 * @param WC_Subscription $subscription the subscription details
342 342
 	 * @return string the subscription payment method
343 343
 	 */
344
-	public function maybe_render_subscription_payment_method( $payment_method_to_display, $subscription ) {
344
+	public function maybe_render_subscription_payment_method($payment_method_to_display, $subscription) {
345 345
 		$customer_user = WC_Stripe_Helper::is_pre_30() ? $subscription->customer_user : $subscription->get_customer_id();
346 346
 
347 347
 		// bail for other payment methods
348
-		if ( ( WC_Stripe_Helper::is_pre_30() ? $subscription->payment_method : $subscription->get_payment_method() ) !== $this->id || ! $customer_user ) {
348
+		if ((WC_Stripe_Helper::is_pre_30() ? $subscription->payment_method : $subscription->get_payment_method()) !== $this->id || ! $customer_user) {
349 349
 			return $payment_method_to_display;
350 350
 		}
351 351
 
352
-		$stripe_source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_source_id', true );
352
+		$stripe_source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_source_id', true);
353 353
 
354 354
 		// For BW compat will remove in future.
355
-		if ( empty( $stripe_source_id ) ) {
356
-			$stripe_source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_card_id', true );
355
+		if (empty($stripe_source_id)) {
356
+			$stripe_source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_card_id', true);
357 357
 
358 358
 			// Take this opportunity to update the key name.
359
-			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 );
359
+			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);
360 360
 		}
361 361
 
362 362
 		$stripe_customer    = new WC_Stripe_Customer();
363
-		$stripe_customer_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_customer_id', true );
363
+		$stripe_customer_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_customer_id', true);
364 364
 
365 365
 		// If we couldn't find a Stripe customer linked to the subscription, fallback to the user meta data.
366
-		if ( ! $stripe_customer_id || ! is_string( $stripe_customer_id ) ) {
366
+		if ( ! $stripe_customer_id || ! is_string($stripe_customer_id)) {
367 367
 			$user_id            = $customer_user;
368
-			$stripe_customer_id = get_user_meta( $user_id, '_stripe_customer_id', true );
369
-			$stripe_source_id   = get_user_meta( $user_id, '_stripe_source_id', true );
368
+			$stripe_customer_id = get_user_meta($user_id, '_stripe_customer_id', true);
369
+			$stripe_source_id   = get_user_meta($user_id, '_stripe_source_id', true);
370 370
 
371 371
 			// For BW compat will remove in future.
372
-			if ( empty( $stripe_source_id ) ) {
373
-				$stripe_source_id = get_user_meta( $user_id, '_stripe_card_id', true );
372
+			if (empty($stripe_source_id)) {
373
+				$stripe_source_id = get_user_meta($user_id, '_stripe_card_id', true);
374 374
 
375 375
 				// Take this opportunity to update the key name.
376
-				update_user_meta( $user_id, '_stripe_source_id', $stripe_source_id );
376
+				update_user_meta($user_id, '_stripe_source_id', $stripe_source_id);
377 377
 			}
378 378
 		}
379 379
 
380 380
 		// If we couldn't find a Stripe customer linked to the account, fallback to the order meta data.
381
-		if ( ( ! $stripe_customer_id || ! is_string( $stripe_customer_id ) ) && false !== $subscription->order ) {
382
-			$stripe_customer_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id() ), '_stripe_customer_id', true );
383
-			$stripe_source_id   = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id() ), '_stripe_source_id', true );
381
+		if (( ! $stripe_customer_id || ! is_string($stripe_customer_id)) && false !== $subscription->order) {
382
+			$stripe_customer_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id()), '_stripe_customer_id', true);
383
+			$stripe_source_id   = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id()), '_stripe_source_id', true);
384 384
 
385 385
 			// For BW compat will remove in future.
386
-			if ( empty( $stripe_source_id ) ) {
387
-				$stripe_source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id() ), '_stripe_card_id', true );
386
+			if (empty($stripe_source_id)) {
387
+				$stripe_source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id()), '_stripe_card_id', true);
388 388
 
389 389
 				// Take this opportunity to update the key name.
390
-				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 );
390
+				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);
391 391
 			}
392 392
 		}
393 393
 
394
-		$stripe_customer->set_id( $stripe_customer_id );
394
+		$stripe_customer->set_id($stripe_customer_id);
395 395
 		$sources = $stripe_customer->get_sources();
396 396
 
397
-		if ( $sources ) {
397
+		if ($sources) {
398 398
 			$found_source = false;
399
-			foreach ( $sources as $source ) {
400
-				if ( isset( $source->type ) && 'card' === $source->type ) {
399
+			foreach ($sources as $source) {
400
+				if (isset($source->type) && 'card' === $source->type) {
401 401
 					$card = $source->card;
402 402
 				}
403 403
 
404
-				if ( $source->id === $stripe_source_id ) {
404
+				if ($source->id === $stripe_source_id) {
405 405
 					$found_source = true;
406 406
 
407
-					if ( $card ) {
407
+					if ($card) {
408 408
 						/* translators: 1) card brand 2) last 4 digits */
409
-						$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 );
409
+						$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);
410 410
 					} else {
411
-						$payment_method_to_display = __( 'N/A', 'woocommerce-gateway-stripe' );
411
+						$payment_method_to_display = __('N/A', 'woocommerce-gateway-stripe');
412 412
 					}
413 413
 					break;
414 414
 				}
415 415
 			}
416 416
 
417
-			if ( ! $found_source ) {
418
-				if ( 'card' === $sources[0]->type ) {
417
+			if ( ! $found_source) {
418
+				if ('card' === $sources[0]->type) {
419 419
 					$card = $sources[0]->card;
420 420
 				}
421 421
 
422
-				if ( $card ) {
422
+				if ($card) {
423 423
 					/* translators: 1) card brand 2) last 4 digits */
424
-					$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 );
424
+					$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);
425 425
 				} else {
426
-					$payment_method_to_display = __( 'N/A', 'woocommerce-gateway-stripe' );
426
+					$payment_method_to_display = __('N/A', 'woocommerce-gateway-stripe');
427 427
 				}
428 428
 			}
429 429
 		}
@@ -436,43 +436,43 @@  discard block
 block discarded – undo
436 436
 	 * @param int $order_id
437 437
 	 * @return array
438 438
 	 */
439
-	public function process_pre_order( $order_id, $retry, $force_save_source ) {
440
-		if ( WC_Pre_Orders_Order::order_requires_payment_tokenization( $order_id ) ) {
439
+	public function process_pre_order($order_id, $retry, $force_save_source) {
440
+		if (WC_Pre_Orders_Order::order_requires_payment_tokenization($order_id)) {
441 441
 			try {
442
-				$order = wc_get_order( $order_id );
442
+				$order = wc_get_order($order_id);
443 443
 
444
-				if ( $order->get_total() * 100 < WC_Stripe_Helper::get_minimum_amount() ) {
444
+				if ($order->get_total() * 100 < WC_Stripe_Helper::get_minimum_amount()) {
445 445
 					/* translators: minimum amount */
446
-					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 ) ) );
446
+					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)));
447 447
 				}
448 448
 
449
-				$source_id = ! empty( $_POST['stripe_source'] ) ? wc_clean( $_POST['stripe_source'] ) : '';
450
-				$source    = $this->prepare_source( $this->get_source_object( $source_id ), get_current_user_id(), true );
449
+				$source_id = ! empty($_POST['stripe_source']) ? wc_clean($_POST['stripe_source']) : '';
450
+				$source    = $this->prepare_source($this->get_source_object($source_id), get_current_user_id(), true);
451 451
 
452 452
 				// We need a source on file to continue.
453
-				if ( empty( $source->customer ) || empty( $source->source ) ) {
454
-					throw new Exception( __( 'Unable to store payment details. Please try again.', 'woocommerce-gateway-stripe' ) );
453
+				if (empty($source->customer) || empty($source->source)) {
454
+					throw new Exception(__('Unable to store payment details. Please try again.', 'woocommerce-gateway-stripe'));
455 455
 				}
456 456
 
457
-				$this->save_source_to_order( $order, $source );
457
+				$this->save_source_to_order($order, $source);
458 458
 
459 459
 				// Remove cart
460 460
 				WC()->cart->empty_cart();
461 461
 
462 462
 				// Is pre ordered!
463
-				WC_Pre_Orders_Order::mark_order_as_pre_ordered( $order );
463
+				WC_Pre_Orders_Order::mark_order_as_pre_ordered($order);
464 464
 
465 465
 				// Return thank you page redirect
466 466
 				return array(
467 467
 					'result'   => 'success',
468
-					'redirect' => $this->get_return_url( $order ),
468
+					'redirect' => $this->get_return_url($order),
469 469
 				);
470
-			} catch ( Exception $e ) {
471
-				wc_add_notice( $e->getMessage(), 'error' );
470
+			} catch (Exception $e) {
471
+				wc_add_notice($e->getMessage(), 'error');
472 472
 				return;
473 473
 			}
474 474
 		} else {
475
-			return parent::process_payment( $order_id, $retry, $force_save_source );
475
+			return parent::process_payment($order_id, $retry, $force_save_source);
476 476
 		}
477 477
 	}
478 478
 
@@ -481,7 +481,7 @@  discard block
 block discarded – undo
481 481
 	 * @param WC_Order $order
482 482
 	 * @return void
483 483
 	 */
484
-	public function process_pre_order_release_payment( $order ) {
484
+	public function process_pre_order_release_payment($order) {
485 485
 		try {
486 486
 			// Define some callbacks if the first attempt fails.
487 487
 			$retry_callbacks = array(
@@ -489,33 +489,33 @@  discard block
 block discarded – undo
489 489
 				'remove_order_customer_before_retry',
490 490
 			);
491 491
 
492
-			while ( 1 ) {
493
-				$source   = $this->prepare_order_source( $order );
494
-				$response = WC_Stripe_API::request( $this->generate_payment_request( $order, $source ) );
492
+			while (1) {
493
+				$source   = $this->prepare_order_source($order);
494
+				$response = WC_Stripe_API::request($this->generate_payment_request($order, $source));
495 495
 
496
-				if ( ! empty( $response->error ) ) {
497
-					if ( 0 === sizeof( $retry_callbacks ) ) {
498
-						throw new Exception( $response->error->message );
496
+				if ( ! empty($response->error)) {
497
+					if (0 === sizeof($retry_callbacks)) {
498
+						throw new Exception($response->error->message);
499 499
 					} else {
500
-						$retry_callback = array_shift( $retry_callbacks );
501
-						call_user_func( array( $this, $retry_callback ), $order );
500
+						$retry_callback = array_shift($retry_callbacks);
501
+						call_user_func(array($this, $retry_callback), $order);
502 502
 					}
503 503
 				} else {
504 504
 					// Successful
505
-					$this->process_response( $response, $order );
505
+					$this->process_response($response, $order);
506 506
 					break;
507 507
 				}
508 508
 			}
509
-		} catch ( Exception $e ) {
509
+		} catch (Exception $e) {
510 510
 			/* translators: error message */
511
-			$order_note = sprintf( __( 'Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe' ), $e->getMessage() );
511
+			$order_note = sprintf(__('Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe'), $e->getMessage());
512 512
 
513 513
 			// Mark order as failed if not already set,
514 514
 			// otherwise, make sure we add the order note so we can detect when someone fails to check out multiple times
515
-			if ( ! $order->has_status( 'failed' ) ) {
516
-				$order->update_status( 'failed', $order_note );
515
+			if ( ! $order->has_status('failed')) {
516
+				$order->update_status('failed', $order_note);
517 517
 			} else {
518
-				$order->add_order_note( $order_note );
518
+				$order->add_order_note($order_note);
519 519
 			}
520 520
 		}
521 521
 	}
Please login to merge, or discard this patch.
includes/class-wc-gateway-stripe.php 1 patch
Spacing   +186 added lines, -186 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
 
@@ -106,9 +106,9 @@  discard block
 block discarded – undo
106 106
 	public function __construct() {
107 107
 		$this->retry_interval       = 2;
108 108
 		$this->id                   = 'stripe';
109
-		$this->method_title         = __( 'Stripe', 'woocommerce-gateway-stripe' );
109
+		$this->method_title         = __('Stripe', 'woocommerce-gateway-stripe');
110 110
 		/* translators: 1) link to Stripe register page 2) link to Stripe api keys page */
111
-		$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' );
111
+		$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');
112 112
 		$this->has_fields           = true;
113 113
 		$this->supports             = array(
114 114
 			'products',
@@ -135,32 +135,32 @@  discard block
 block discarded – undo
135 135
 		$this->init_settings();
136 136
 
137 137
 		// Get setting values.
138
-		$this->title                   = $this->get_option( 'title' );
139
-		$this->description             = $this->get_option( 'description' );
140
-		$this->enabled                 = $this->get_option( 'enabled' );
141
-		$this->testmode                = 'yes' === $this->get_option( 'testmode' );
142
-		$this->inline_cc_form          = 'yes' === $this->get_option( 'inline_cc_form' );
143
-		$this->capture                 = 'yes' === $this->get_option( 'capture', 'yes' );
144
-		$this->statement_descriptor    = WC_Stripe_Helper::clean_statement_descriptor( $this->get_option( 'statement_descriptor' ) );
145
-		$this->three_d_secure          = 'yes' === $this->get_option( 'three_d_secure' );
146
-		$this->stripe_checkout         = 'yes' === $this->get_option( 'stripe_checkout' );
147
-		$this->stripe_checkout_image   = $this->get_option( 'stripe_checkout_image', '' );
148
-		$this->saved_cards             = 'yes' === $this->get_option( 'saved_cards' );
149
-		$this->secret_key              = $this->testmode ? $this->get_option( 'test_secret_key' ) : $this->get_option( 'secret_key' );
150
-		$this->publishable_key         = $this->testmode ? $this->get_option( 'test_publishable_key' ) : $this->get_option( 'publishable_key' );
151
-		$this->bitcoin                 = 'USD' === strtoupper( get_woocommerce_currency() ) && 'yes' === $this->get_option( 'stripe_bitcoin' );
152
-		$this->payment_request         = 'yes' === $this->get_option( 'payment_request', 'yes' );
153
-
154
-		if ( $this->stripe_checkout ) {
155
-			$this->order_button_text = __( 'Continue to payment', 'woocommerce-gateway-stripe' );
138
+		$this->title                   = $this->get_option('title');
139
+		$this->description             = $this->get_option('description');
140
+		$this->enabled                 = $this->get_option('enabled');
141
+		$this->testmode                = 'yes' === $this->get_option('testmode');
142
+		$this->inline_cc_form          = 'yes' === $this->get_option('inline_cc_form');
143
+		$this->capture                 = 'yes' === $this->get_option('capture', 'yes');
144
+		$this->statement_descriptor    = WC_Stripe_Helper::clean_statement_descriptor($this->get_option('statement_descriptor'));
145
+		$this->three_d_secure          = 'yes' === $this->get_option('three_d_secure');
146
+		$this->stripe_checkout         = 'yes' === $this->get_option('stripe_checkout');
147
+		$this->stripe_checkout_image   = $this->get_option('stripe_checkout_image', '');
148
+		$this->saved_cards             = 'yes' === $this->get_option('saved_cards');
149
+		$this->secret_key              = $this->testmode ? $this->get_option('test_secret_key') : $this->get_option('secret_key');
150
+		$this->publishable_key         = $this->testmode ? $this->get_option('test_publishable_key') : $this->get_option('publishable_key');
151
+		$this->bitcoin                 = 'USD' === strtoupper(get_woocommerce_currency()) && 'yes' === $this->get_option('stripe_bitcoin');
152
+		$this->payment_request         = 'yes' === $this->get_option('payment_request', 'yes');
153
+
154
+		if ($this->stripe_checkout) {
155
+			$this->order_button_text = __('Continue to payment', 'woocommerce-gateway-stripe');
156 156
 		}
157 157
 
158
-		WC_Stripe_API::set_secret_key( $this->secret_key );
158
+		WC_Stripe_API::set_secret_key($this->secret_key);
159 159
 
160 160
 		// Hooks.
161
-		add_action( 'wp_enqueue_scripts', array( $this, 'payment_scripts' ) );
162
-		add_action( 'admin_enqueue_scripts', array( $this, 'admin_scripts' ) );
163
-		add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) );
161
+		add_action('wp_enqueue_scripts', array($this, 'payment_scripts'));
162
+		add_action('admin_enqueue_scripts', array($this, 'admin_scripts'));
163
+		add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options'));
164 164
 	}
165 165
 
166 166
 	/**
@@ -170,7 +170,7 @@  discard block
 block discarded – undo
170 170
 	 * @return bool
171 171
 	 */
172 172
 	public function are_keys_set() {
173
-		if ( empty( $this->secret_key ) || empty( $this->publishable_key ) ) {
173
+		if (empty($this->secret_key) || empty($this->publishable_key)) {
174 174
 			return false;
175 175
 		}
176 176
 
@@ -183,7 +183,7 @@  discard block
 block discarded – undo
183 183
 	 * @since 4.0.2
184 184
 	 */
185 185
 	public function is_available() {
186
-		if ( is_add_payment_method_page() && ! $this->saved_cards ) {
186
+		if (is_add_payment_method_page() && ! $this->saved_cards) {
187 187
 			return false;
188 188
 		}
189 189
 
@@ -206,24 +206,24 @@  discard block
 block discarded – undo
206 206
 		$icons_str .= $icons['amex'];
207 207
 		$icons_str .= $icons['mastercard'];
208 208
 
209
-		if ( 'USD' === get_woocommerce_currency() ) {
209
+		if ('USD' === get_woocommerce_currency()) {
210 210
 			$icons_str .= $icons['discover'];
211 211
 			$icons_str .= $icons['jcb'];
212 212
 			$icons_str .= $icons['diners'];
213 213
 		}
214 214
 
215
-		if ( $this->bitcoin && $this->stripe_checkout ) {
215
+		if ($this->bitcoin && $this->stripe_checkout) {
216 216
 			$icons_str .= $icons['bitcoin'];
217 217
 		}
218 218
 
219
-		return apply_filters( 'woocommerce_gateway_icon', $icons_str, $this->id );
219
+		return apply_filters('woocommerce_gateway_icon', $icons_str, $this->id);
220 220
 	}
221 221
 
222 222
 	/**
223 223
 	 * Initialise Gateway Settings Form Fields
224 224
 	 */
225 225
 	public function init_form_fields() {
226
-		$this->form_fields = require( dirname( __FILE__ ) . '/admin/stripe-settings.php' );
226
+		$this->form_fields = require(dirname(__FILE__) . '/admin/stripe-settings.php');
227 227
 	}
228 228
 
229 229
 	/**
@@ -231,68 +231,68 @@  discard block
 block discarded – undo
231 231
 	 */
232 232
 	public function payment_fields() {
233 233
 		$user                 = wp_get_current_user();
234
-		$display_tokenization = $this->supports( 'tokenization' ) && is_checkout() && $this->saved_cards;
234
+		$display_tokenization = $this->supports('tokenization') && is_checkout() && $this->saved_cards;
235 235
 		$total                = WC()->cart->total;
236 236
 		$user_email           = '';
237 237
 
238 238
 		// If paying from order, we need to get total from order not cart.
239
-		if ( isset( $_GET['pay_for_order'] ) && ! empty( $_GET['key'] ) ) {
240
-			$order      = wc_get_order( wc_get_order_id_by_order_key( wc_clean( $_GET['key'] ) ) );
239
+		if (isset($_GET['pay_for_order']) && ! empty($_GET['key'])) {
240
+			$order      = wc_get_order(wc_get_order_id_by_order_key(wc_clean($_GET['key'])));
241 241
 			$total      = $order->get_total();
242 242
 			$user_email = WC_Stripe_Helper::is_pre_30() ? $order->billing_email : $order->get_billing_email();
243 243
 		} else {
244
-			if ( $user->ID ) {
245
-				$user_email = get_user_meta( $user->ID, 'billing_email', true );
244
+			if ($user->ID) {
245
+				$user_email = get_user_meta($user->ID, 'billing_email', true);
246 246
 				$user_email = $user_email ? $user_email : $user->user_email;
247 247
 			}
248 248
 		}
249 249
 
250
-		if ( is_add_payment_method_page() ) {
251
-			$pay_button_text = __( 'Add Card', 'woocommerce-gateway-stripe' );
252
-			$total        = '';
250
+		if (is_add_payment_method_page()) {
251
+			$pay_button_text = __('Add Card', 'woocommerce-gateway-stripe');
252
+			$total = '';
253 253
 		} else {
254 254
 			$pay_button_text = '';
255 255
 		}
256 256
 
257 257
 		echo '<div
258 258
 			id="stripe-payment-data"
259
-			data-panel-label="' . esc_attr( $pay_button_text ) . '"
259
+			data-panel-label="' . esc_attr($pay_button_text) . '"
260 260
 			data-description=""
261
-			data-email="' . esc_attr( $user_email ) . '"
262
-			data-amount="' . esc_attr( WC_Stripe_Helper::get_stripe_amount( $total ) ) . '"
263
-			data-name="' . esc_attr( $this->statement_descriptor ) . '"
264
-			data-currency="' . esc_attr( strtolower( get_woocommerce_currency() ) ) . '"
265
-			data-image="' . esc_attr( $this->stripe_checkout_image ) . '"
266
-			data-bitcoin="' . esc_attr( ( $this->bitcoin && $this->capture ) ? 'true' : 'false' ) . '"
267
-			data-locale="' . esc_attr( apply_filters( 'wc_stripe_checkout_locale', $this->get_locale() ) ) . '"
268
-			data-three-d-secure="' . esc_attr( $this->three_d_secure ? 'true' : 'false' ) . '"
269
-			data-allow-remember-me="' . esc_attr( $this->saved_cards ? 'true' : 'false' ) . '">';
270
-
271
-		if ( $this->description ) {
272
-			if ( $this->testmode ) {
261
+			data-email="' . esc_attr($user_email) . '"
262
+			data-amount="' . esc_attr(WC_Stripe_Helper::get_stripe_amount($total)) . '"
263
+			data-name="' . esc_attr($this->statement_descriptor) . '"
264
+			data-currency="' . esc_attr(strtolower(get_woocommerce_currency())) . '"
265
+			data-image="' . esc_attr($this->stripe_checkout_image) . '"
266
+			data-bitcoin="' . esc_attr(($this->bitcoin && $this->capture) ? 'true' : 'false') . '"
267
+			data-locale="' . esc_attr(apply_filters('wc_stripe_checkout_locale', $this->get_locale())) . '"
268
+			data-three-d-secure="' . esc_attr($this->three_d_secure ? 'true' : 'false') . '"
269
+			data-allow-remember-me="' . esc_attr($this->saved_cards ? 'true' : 'false') . '">';
270
+
271
+		if ($this->description) {
272
+			if ($this->testmode) {
273 273
 				/* translators: link to Stripe testing page */
274
-				$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' );
275
-				$this->description  = trim( $this->description );
274
+				$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');
275
+				$this->description  = trim($this->description);
276 276
 			}
277
-			echo apply_filters( 'wc_stripe_description', wpautop( wp_kses_post( $this->description ) ) );
277
+			echo apply_filters('wc_stripe_description', wpautop(wp_kses_post($this->description)));
278 278
 		}
279 279
 
280
-		if ( $display_tokenization ) {
280
+		if ($display_tokenization) {
281 281
 			$this->tokenization_script();
282 282
 			$this->saved_payment_methods();
283 283
 		}
284 284
 
285
-		if ( ! $this->stripe_checkout ) {
286
-			if ( apply_filters( 'wc_stripe_use_elements_checkout_form', true ) ) {
285
+		if ( ! $this->stripe_checkout) {
286
+			if (apply_filters('wc_stripe_use_elements_checkout_form', true)) {
287 287
 				$this->elements_form();
288 288
 			} else {
289
-				WC_Stripe_Logger::log( 'DEPRECATED! Since version 4.0. Stripe Elements is used. This legacy credit card form will be removed by version 5.0!' );
289
+				WC_Stripe_Logger::log('DEPRECATED! Since version 4.0. Stripe Elements is used. This legacy credit card form will be removed by version 5.0!');
290 290
 				$this->form();
291 291
 				echo '<div class="stripe-source-errors" role="alert"></div>';
292 292
 			}
293 293
 		}
294 294
 
295
-		if ( apply_filters( 'wc_stripe_display_save_payment_method_checkbox', $display_tokenization ) && ! is_add_payment_method_page() && ! isset( $_GET['change_payment_method'] ) ) {
295
+		if (apply_filters('wc_stripe_display_save_payment_method_checkbox', $display_tokenization) && ! is_add_payment_method_page() && ! isset($_GET['change_payment_method'])) {
296 296
 			$this->save_payment_method_checkbox();
297 297
 		}
298 298
 
@@ -307,12 +307,12 @@  discard block
 block discarded – undo
307 307
 	 */
308 308
 	public function elements_form() {
309 309
 		?>
310
-		<fieldset id="wc-<?php echo esc_attr( $this->id ); ?>-cc-form" class="wc-credit-card-form wc-payment-form" style="background:transparent;">
311
-			<?php do_action( 'woocommerce_credit_card_form_start', $this->id ); ?>
310
+		<fieldset id="wc-<?php echo esc_attr($this->id); ?>-cc-form" class="wc-credit-card-form wc-payment-form" style="background:transparent;">
311
+			<?php do_action('woocommerce_credit_card_form_start', $this->id); ?>
312 312
 
313
-			<?php if ( $this->inline_cc_form ) { ?>
313
+			<?php if ($this->inline_cc_form) { ?>
314 314
 				<label for="card-element">
315
-					<?php esc_html_e( 'Credit or debit card', 'woocommerce-gateway-stripe' ); ?>
315
+					<?php esc_html_e('Credit or debit card', 'woocommerce-gateway-stripe'); ?>
316 316
 				</label>
317 317
 
318 318
 				<div id="stripe-card-element" style="background:#fff;padding:0 1em;border:1px solid #ddd;margin:5px 0;padding:10px 5px;">
@@ -320,7 +320,7 @@  discard block
 block discarded – undo
320 320
 				</div>
321 321
 			<?php } else { ?>
322 322
 				<div class="form-row form-row-wide">
323
-					<label><?php _e( 'Card Number', 'woocommerce-gateway-stripe' ); ?> <span class="required">*</span></label>
323
+					<label><?php _e('Card Number', 'woocommerce-gateway-stripe'); ?> <span class="required">*</span></label>
324 324
 
325 325
 					<div id="stripe-card-element" style="background:#fff;padding:0 1em;border:1px solid #ddd;margin:5px 0;padding:10px 5px;">
326 326
 					<!-- a Stripe Element will be inserted here. -->
@@ -328,7 +328,7 @@  discard block
 block discarded – undo
328 328
 				</div>
329 329
 
330 330
 				<div class="form-row form-row-first">
331
-					<label><?php _e( 'Expiry Date', 'woocommerce-gateway-stripe' ); ?> <span class="required">*</span></label>
331
+					<label><?php _e('Expiry Date', 'woocommerce-gateway-stripe'); ?> <span class="required">*</span></label>
332 332
 
333 333
 					<div id="stripe-exp-element" style="background:#fff;padding:0 1em;border:1px solid #ddd;margin:5px 0;padding:10px 5px;">
334 334
 					<!-- a Stripe Element will be inserted here. -->
@@ -336,7 +336,7 @@  discard block
 block discarded – undo
336 336
 				</div>
337 337
 
338 338
 				<div class="form-row form-row-last">
339
-					<label><?php _e( 'Card Code (CVC)', 'woocommerce-gateway-stripe' ); ?> <span class="required">*</span></label>
339
+					<label><?php _e('Card Code (CVC)', 'woocommerce-gateway-stripe'); ?> <span class="required">*</span></label>
340 340
 				<div id="stripe-cvc-element" style="background:#fff;padding:0 1em;border:1px solid #ddd;margin:5px 0;padding:10px 5px;">
341 341
 				<!-- a Stripe Element will be inserted here. -->
342 342
 				</div>
@@ -346,7 +346,7 @@  discard block
 block discarded – undo
346 346
 
347 347
 			<!-- Used to display form errors -->
348 348
 			<div class="stripe-source-errors" role="alert"></div>
349
-			<?php do_action( 'woocommerce_credit_card_form_end', $this->id ); ?>
349
+			<?php do_action('woocommerce_credit_card_form_end', $this->id); ?>
350 350
 			<div class="clear"></div>
351 351
 		</fieldset>
352 352
 		<?php
@@ -359,13 +359,13 @@  discard block
 block discarded – undo
359 359
 	 * @version 3.1.0
360 360
 	 */
361 361
 	public function admin_scripts() {
362
-		if ( 'woocommerce_page_wc-settings' !== get_current_screen()->id ) {
362
+		if ('woocommerce_page_wc-settings' !== get_current_screen()->id) {
363 363
 			return;
364 364
 		}
365 365
 
366
-		$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
366
+		$suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';
367 367
 
368
-		wp_enqueue_script( 'woocommerce_stripe_admin', plugins_url( 'assets/js/stripe-admin' . $suffix . '.js', WC_STRIPE_MAIN_FILE ), array(), WC_STRIPE_VERSION, true );
368
+		wp_enqueue_script('woocommerce_stripe_admin', plugins_url('assets/js/stripe-admin' . $suffix . '.js', WC_STRIPE_MAIN_FILE), array(), WC_STRIPE_VERSION, true);
369 369
 	}
370 370
 
371 371
 	/**
@@ -377,46 +377,46 @@  discard block
 block discarded – undo
377 377
 	 * @version 4.0.0
378 378
 	 */
379 379
 	public function payment_scripts() {
380
-		if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) && ! is_add_payment_method_page() && ! isset( $_GET['change_payment_method'] ) ) {
380
+		if ( ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order']) && ! is_add_payment_method_page() && ! isset($_GET['change_payment_method'])) {
381 381
 			return;
382 382
 		}
383 383
 
384 384
 		// If Stripe is not enabled bail.
385
-		if ( 'no' === $this->enabled ) {
385
+		if ('no' === $this->enabled) {
386 386
 			return;
387 387
 		}
388 388
 
389 389
 		// If keys are not set bail.
390
-		if ( ! $this->are_keys_set() ) {
391
-			WC_Stripe_Logger::log( 'Keys are not set correctly.' );
390
+		if ( ! $this->are_keys_set()) {
391
+			WC_Stripe_Logger::log('Keys are not set correctly.');
392 392
 			return;
393 393
 		}
394 394
 
395 395
 		// If no SSL bail.
396
-		if ( ! $this->testmode && ! is_ssl() ) {
397
-			WC_Stripe_Logger::log( 'Stripe requires SSL.' );
396
+		if ( ! $this->testmode && ! is_ssl()) {
397
+			WC_Stripe_Logger::log('Stripe requires SSL.');
398 398
 			return;
399 399
 		}
400 400
 
401
-		$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
401
+		$suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';
402 402
 
403
-		wp_register_style( 'stripe_paymentfonts', plugins_url( 'assets/css/stripe-paymentfonts.css', WC_STRIPE_MAIN_FILE ), array(), '1.2.5' );
404
-		wp_enqueue_style( 'stripe_paymentfonts' );
405
-		wp_register_script( 'stripe_checkout', 'https://checkout.stripe.com/checkout.js', '', WC_STRIPE_VERSION, true );
406
-		wp_register_script( 'stripev2', 'https://js.stripe.com/v2/', '', '2.0', true );
407
-		wp_register_script( 'stripe', 'https://js.stripe.com/v3/', '', '3.0', true );
408
-		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 );
403
+		wp_register_style('stripe_paymentfonts', plugins_url('assets/css/stripe-paymentfonts.css', WC_STRIPE_MAIN_FILE), array(), '1.2.5');
404
+		wp_enqueue_style('stripe_paymentfonts');
405
+		wp_register_script('stripe_checkout', 'https://checkout.stripe.com/checkout.js', '', WC_STRIPE_VERSION, true);
406
+		wp_register_script('stripev2', 'https://js.stripe.com/v2/', '', '2.0', true);
407
+		wp_register_script('stripe', 'https://js.stripe.com/v3/', '', '3.0', true);
408
+		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);
409 409
 
410 410
 		$stripe_params = array(
411 411
 			'key'                  => $this->publishable_key,
412
-			'i18n_terms'           => __( 'Please accept the terms and conditions first', 'woocommerce-gateway-stripe' ),
413
-			'i18n_required_fields' => __( 'Please fill in required checkout fields first', 'woocommerce-gateway-stripe' ),
412
+			'i18n_terms'           => __('Please accept the terms and conditions first', 'woocommerce-gateway-stripe'),
413
+			'i18n_required_fields' => __('Please fill in required checkout fields first', 'woocommerce-gateway-stripe'),
414 414
 		);
415 415
 
416 416
 		// If we're on the pay page we need to pass stripe.js the address of the order.
417
-		if ( isset( $_GET['pay_for_order'] ) && 'true' === $_GET['pay_for_order'] ) {
418
-			$order_id = wc_get_order_id_by_order_key( urldecode( $_GET['key'] ) );
419
-			$order    = wc_get_order( $order_id );
417
+		if (isset($_GET['pay_for_order']) && 'true' === $_GET['pay_for_order']) {
418
+			$order_id = wc_get_order_id_by_order_key(urldecode($_GET['key']));
419
+			$order    = wc_get_order($order_id);
420 420
 
421 421
 			$stripe_params['billing_first_name'] = WC_Stripe_Helper::is_pre_30() ? $order->billing_first_name : $order->get_billing_first_name();
422 422
 			$stripe_params['billing_last_name']  = WC_Stripe_Helper::is_pre_30() ? $order->billing_last_name : $order->get_billing_last_name();
@@ -428,38 +428,38 @@  discard block
 block discarded – undo
428 428
 			$stripe_params['billing_country']    = WC_Stripe_Helper::is_pre_30() ? $order->billing_country : $order->get_billing_country();
429 429
 		}
430 430
 
431
-		$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' );
432
-		$stripe_params['no_sepa_owner_msg']                       = __( 'Please enter your IBAN account name.', 'woocommerce-gateway-stripe' );
433
-		$stripe_params['no_sepa_iban_msg']                        = __( 'Please enter your IBAN account number.', 'woocommerce-gateway-stripe' );
434
-		$stripe_params['sepa_mandate_notification']               = apply_filters( 'wc_stripe_sepa_mandate_notification', 'email' );
435
-		$stripe_params['allow_prepaid_card']                      = apply_filters( 'wc_stripe_allow_prepaid_card', true ) ? 'yes' : 'no';
431
+		$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');
432
+		$stripe_params['no_sepa_owner_msg']                       = __('Please enter your IBAN account name.', 'woocommerce-gateway-stripe');
433
+		$stripe_params['no_sepa_iban_msg']                        = __('Please enter your IBAN account number.', 'woocommerce-gateway-stripe');
434
+		$stripe_params['sepa_mandate_notification']               = apply_filters('wc_stripe_sepa_mandate_notification', 'email');
435
+		$stripe_params['allow_prepaid_card']                      = apply_filters('wc_stripe_allow_prepaid_card', true) ? 'yes' : 'no';
436 436
 		$stripe_params['inline_cc_form']                          = $this->inline_cc_form ? 'yes' : 'no';
437
-		$stripe_params['stripe_checkout_require_billing_address'] = apply_filters( 'wc_stripe_checkout_require_billing_address', false ) ? 'yes' : 'no';
438
-		$stripe_params['is_checkout']                             = ( is_checkout() && empty( $_GET['pay_for_order'] ) );
437
+		$stripe_params['stripe_checkout_require_billing_address'] = apply_filters('wc_stripe_checkout_require_billing_address', false) ? 'yes' : 'no';
438
+		$stripe_params['is_checkout']                             = (is_checkout() && empty($_GET['pay_for_order']));
439 439
 		$stripe_params['return_url']                              = $this->get_stripe_return_url();
440
-		$stripe_params['ajaxurl']                                 = WC_AJAX::get_endpoint( '%%endpoint%%' );
441
-		$stripe_params['stripe_nonce']                            = wp_create_nonce( '_wc_stripe_nonce' );
440
+		$stripe_params['ajaxurl']                                 = WC_AJAX::get_endpoint('%%endpoint%%');
441
+		$stripe_params['stripe_nonce']                            = wp_create_nonce('_wc_stripe_nonce');
442 442
 		$stripe_params['statement_descriptor']                    = $this->statement_descriptor;
443
-		$stripe_params['use_elements']                            = apply_filters( 'wc_stripe_use_elements_checkout_form', true ) ? 'yes' : 'no';
444
-		$stripe_params['elements_options']                        = apply_filters( 'wc_stripe_elements_options', array() );
443
+		$stripe_params['use_elements']                            = apply_filters('wc_stripe_use_elements_checkout_form', true) ? 'yes' : 'no';
444
+		$stripe_params['elements_options']                        = apply_filters('wc_stripe_elements_options', array());
445 445
 		$stripe_params['is_stripe_checkout']                      = $this->stripe_checkout ? 'yes' : 'no';
446
-		$stripe_params['is_change_payment_page']                  = isset( $_GET['change_payment_method'] ) ? 'yes' : 'no';
447
-		$stripe_params['validate_modal_checkout']                 = apply_filters( 'wc_stripe_validate_model_checkout', true ) ? 'yes' : 'no';
448
-		$stripe_params['elements_styling']                        = apply_filters( 'wc_stripe_elements_styling', false );
449
-		$stripe_params['elements_classes']                        = apply_filters( 'wc_stripe_elements_classes', false );
446
+		$stripe_params['is_change_payment_page']                  = isset($_GET['change_payment_method']) ? 'yes' : 'no';
447
+		$stripe_params['validate_modal_checkout']                 = apply_filters('wc_stripe_validate_model_checkout', true) ? 'yes' : 'no';
448
+		$stripe_params['elements_styling']                        = apply_filters('wc_stripe_elements_styling', false);
449
+		$stripe_params['elements_classes']                        = apply_filters('wc_stripe_elements_classes', false);
450 450
 
451 451
 		// merge localized messages to be use in JS
452
-		$stripe_params = array_merge( $stripe_params, WC_Stripe_Helper::get_localized_messages() );
452
+		$stripe_params = array_merge($stripe_params, WC_Stripe_Helper::get_localized_messages());
453 453
 
454
-		wp_localize_script( 'woocommerce_stripe', 'wc_stripe_params', apply_filters( 'wc_stripe_params', $stripe_params ) );
455
-		wp_localize_script( 'woocommerce_stripe_checkout', 'wc_stripe_params', apply_filters( 'wc_stripe_params', $stripe_params ) );
454
+		wp_localize_script('woocommerce_stripe', 'wc_stripe_params', apply_filters('wc_stripe_params', $stripe_params));
455
+		wp_localize_script('woocommerce_stripe_checkout', 'wc_stripe_params', apply_filters('wc_stripe_params', $stripe_params));
456 456
 
457
-		if ( $this->stripe_checkout ) {
458
-			wp_enqueue_script( 'stripe_checkout' );
457
+		if ($this->stripe_checkout) {
458
+			wp_enqueue_script('stripe_checkout');
459 459
 		}
460 460
 
461 461
 		$this->tokenization_script();
462
-		wp_enqueue_script( 'woocommerce_stripe' );
462
+		wp_enqueue_script('woocommerce_stripe');
463 463
 	}
464 464
 
465 465
 	/**
@@ -475,44 +475,44 @@  discard block
 block discarded – undo
475 475
 	 *
476 476
 	 * @return array|void
477 477
 	 */
478
-	public function process_payment( $order_id, $retry = true, $force_save_source = false ) {
478
+	public function process_payment($order_id, $retry = true, $force_save_source = false) {
479 479
 		try {
480
-			$order = wc_get_order( $order_id );
480
+			$order = wc_get_order($order_id);
481 481
 
482 482
 			// This comes from the create account checkbox in the checkout page.
483
-			$create_account = ! empty( $_POST['createaccount'] ) ? true : false;
483
+			$create_account = ! empty($_POST['createaccount']) ? true : false;
484 484
 
485
-			if ( $create_account ) {
485
+			if ($create_account) {
486 486
 				$new_customer_id     = WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id();
487
-				$new_stripe_customer = new WC_Stripe_Customer( $new_customer_id );
487
+				$new_stripe_customer = new WC_Stripe_Customer($new_customer_id);
488 488
 				$new_stripe_customer->create_customer();
489 489
 			}
490 490
 
491
-			$source_id       = ! empty( $_POST['stripe_source'] ) ? wc_clean( $_POST['stripe_source'] ) : '';
492
-			$source_object   = $this->get_source_object( $source_id );
493
-			$prepared_source = $this->prepare_source( $source_object, get_current_user_id(), $force_save_source );
491
+			$source_id       = ! empty($_POST['stripe_source']) ? wc_clean($_POST['stripe_source']) : '';
492
+			$source_object   = $this->get_source_object($source_id);
493
+			$prepared_source = $this->prepare_source($source_object, get_current_user_id(), $force_save_source);
494 494
 
495 495
 			// Check if we don't allow prepaid credit cards.
496
-			if ( ! apply_filters( 'wc_stripe_allow_prepaid_card', true ) ) {
497
-				if ( $source_object && 'token' === $source_object->object && 'prepaid' === $source_object->card->funding ) {
498
-					$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' );
499
-					throw new WC_Stripe_Exception( print_r( $source_object, true ), $localized_message );
496
+			if ( ! apply_filters('wc_stripe_allow_prepaid_card', true)) {
497
+				if ($source_object && 'token' === $source_object->object && 'prepaid' === $source_object->card->funding) {
498
+					$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');
499
+					throw new WC_Stripe_Exception(print_r($source_object, true), $localized_message);
500 500
 				}
501 501
 			}
502 502
 
503
-			if ( empty( $prepared_source->source ) ) {
504
-				$localized_message = __( 'Payment processing failed. Please retry.', 'woocommerce-gateway-stripe' );
505
-				throw new WC_Stripe_Exception( print_r( $prepared_source, true ), $localized_message );
503
+			if (empty($prepared_source->source)) {
504
+				$localized_message = __('Payment processing failed. Please retry.', 'woocommerce-gateway-stripe');
505
+				throw new WC_Stripe_Exception(print_r($prepared_source, true), $localized_message);
506 506
 			}
507 507
 
508
-			$this->save_source_to_order( $order, $prepared_source );
508
+			$this->save_source_to_order($order, $prepared_source);
509 509
 
510 510
 			// Result from Stripe API request.
511 511
 			$response = null;
512 512
 
513
-			if ( $order->get_total() > 0 ) {
513
+			if ($order->get_total() > 0) {
514 514
 				// This will throw exception if not valid.
515
-				$this->validate_minimum_order_amount( $order );
515
+				$this->validate_minimum_order_amount($order);
516 516
 
517 517
 				/*
518 518
 				 * Check if card 3DS is required or optional with 3DS setting.
@@ -521,121 +521,121 @@  discard block
 block discarded – undo
521 521
 				 * Note that if we need to save source, the original source must be first
522 522
 				 * attached to a customer in Stripe before it can be charged.
523 523
 				 */
524
-				if ( $this->is_3ds_required( $source_object ) ) {
525
-					$response = $this->create_3ds_source( $order, $source_object );
524
+				if ($this->is_3ds_required($source_object)) {
525
+					$response = $this->create_3ds_source($order, $source_object);
526 526
 
527
-					if ( ! empty( $response->error ) ) {
527
+					if ( ! empty($response->error)) {
528 528
 						$localized_message = $response->error->message;
529 529
 
530
-						$order->add_order_note( $localized_message );
530
+						$order->add_order_note($localized_message);
531 531
 
532
-						throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message );
532
+						throw new WC_Stripe_Exception(print_r($response, true), $localized_message);
533 533
 					}
534 534
 
535 535
 					// Update order meta with 3DS source.
536
-					if ( WC_Stripe_Helper::is_pre_30() ) {
537
-						update_post_meta( $order_id, '_stripe_source_id', $response->id );
536
+					if (WC_Stripe_Helper::is_pre_30()) {
537
+						update_post_meta($order_id, '_stripe_source_id', $response->id);
538 538
 					} else {
539
-						$order->update_meta_data( '_stripe_source_id', $response->id );
539
+						$order->update_meta_data('_stripe_source_id', $response->id);
540 540
 						$order->save();
541 541
 					}
542 542
 
543
-					WC_Stripe_Logger::log( 'Info: Redirecting to 3DS...' );
543
+					WC_Stripe_Logger::log('Info: Redirecting to 3DS...');
544 544
 
545 545
 					return array(
546 546
 						'result'   => 'success',
547
-						'redirect' => esc_url_raw( $response->redirect->url ),
547
+						'redirect' => esc_url_raw($response->redirect->url),
548 548
 					);
549 549
 				}
550 550
 
551
-				WC_Stripe_Logger::log( "Info: Begin processing payment for order $order_id for the amount of {$order->get_total()}" );
551
+				WC_Stripe_Logger::log("Info: Begin processing payment for order $order_id for the amount of {$order->get_total()}");
552 552
 
553
-				if ( ! $source_object ) {
554
-					$source_object = $this->get_source_object( $prepared_source->source );
553
+				if ( ! $source_object) {
554
+					$source_object = $this->get_source_object($prepared_source->source);
555 555
 				}
556 556
 
557 557
 				/* If we're doing a retry and source is chargeable, we need to pass
558 558
 				 * a different idempotency key and retry for success.
559 559
 				 */
560
-				if ( 2 < $this->retry_interval && 'chargeable' === $source_object->status ) {
561
-					add_filter( 'wc_stripe_idempotency_key', array( $this, 'change_idempotency_key' ), 10, 2 );
560
+				if (2 < $this->retry_interval && 'chargeable' === $source_object->status) {
561
+					add_filter('wc_stripe_idempotency_key', array($this, 'change_idempotency_key'), 10, 2);
562 562
 				}
563 563
 
564 564
 				// Make the request.
565
-				$response = WC_Stripe_API::request( $this->generate_payment_request( $order, $prepared_source ) );
565
+				$response = WC_Stripe_API::request($this->generate_payment_request($order, $prepared_source));
566 566
 
567
-				if ( ! empty( $response->error ) ) {
567
+				if ( ! empty($response->error)) {
568 568
 					// If it is an API error such connection or server, let's retry.
569
-					if ( 'api_connection_error' === $response->error->type || 'api_error' === $response->error->type ) {
570
-						if ( $retry ) {
571
-							sleep( 5 );
572
-							return $this->process_payment( $order_id, false, $force_save_source );
569
+					if ('api_connection_error' === $response->error->type || 'api_error' === $response->error->type) {
570
+						if ($retry) {
571
+							sleep(5);
572
+							return $this->process_payment($order_id, false, $force_save_source);
573 573
 						} else {
574 574
 							$localized_message = 'API connection error and retries exhausted.';
575
-							$order->add_order_note( $localized_message );
576
-							throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message );
575
+							$order->add_order_note($localized_message);
576
+							throw new WC_Stripe_Exception(print_r($response, true), $localized_message);
577 577
 						}
578 578
 					}
579 579
 
580 580
 					// We want to retry.
581
-					if ( $this->is_retryable_error( $response->error ) ) {
582
-						if ( $retry ) {
581
+					if ($this->is_retryable_error($response->error)) {
582
+						if ($retry) {
583 583
 							// Don't do anymore retries after this.
584
-							if ( 5 <= $this->retry_interval ) {
584
+							if (5 <= $this->retry_interval) {
585 585
 
586
-								return $this->process_payment( $order_id, false, $force_save_source );
586
+								return $this->process_payment($order_id, false, $force_save_source);
587 587
 							}
588 588
 
589
-							sleep( $this->retry_interval );
589
+							sleep($this->retry_interval);
590 590
 
591 591
 							$this->retry_interval++;
592 592
 
593
-							return $this->process_payment( $order_id, true, $force_save_source );
593
+							return $this->process_payment($order_id, true, $force_save_source);
594 594
 						} else {
595
-							$localized_message = __( 'On going requests error and retries exhausted.', 'woocommerce-gateway-stripe' );
596
-							$order->add_order_note( $localized_message );
597
-							throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message );
595
+							$localized_message = __('On going requests error and retries exhausted.', 'woocommerce-gateway-stripe');
596
+							$order->add_order_note($localized_message);
597
+							throw new WC_Stripe_Exception(print_r($response, true), $localized_message);
598 598
 						}
599 599
 					}
600 600
 
601 601
 					// Customer param wrong? The user may have been deleted on stripe's end. Remove customer_id. Can be retried without.
602
-					if ( preg_match( '/No such customer/i', $response->error->message ) && $retry ) {
603
-						if ( WC_Stripe_Helper::is_pre_30() ) {
604
-							delete_user_meta( $order->customer_user, '_stripe_customer_id' );
605
-							delete_post_meta( $order_id, '_stripe_customer_id' );
602
+					if (preg_match('/No such customer/i', $response->error->message) && $retry) {
603
+						if (WC_Stripe_Helper::is_pre_30()) {
604
+							delete_user_meta($order->customer_user, '_stripe_customer_id');
605
+							delete_post_meta($order_id, '_stripe_customer_id');
606 606
 						} else {
607
-							delete_user_meta( $order->get_customer_id(), '_stripe_customer_id' );
608
-							$order->delete_meta_data( '_stripe_customer_id' );
607
+							delete_user_meta($order->get_customer_id(), '_stripe_customer_id');
608
+							$order->delete_meta_data('_stripe_customer_id');
609 609
 							$order->save();
610 610
 						}
611 611
 
612
-						return $this->process_payment( $order_id, false, $force_save_source );
613
-					} elseif ( preg_match( '/No such token/i', $response->error->message ) && $prepared_source->token_id ) {
612
+						return $this->process_payment($order_id, false, $force_save_source);
613
+					} elseif (preg_match('/No such token/i', $response->error->message) && $prepared_source->token_id) {
614 614
 						// Source param wrong? The CARD may have been deleted on stripe's end. Remove token and show message.
615
-						$wc_token = WC_Payment_Tokens::get( $prepared_source->token_id );
615
+						$wc_token = WC_Payment_Tokens::get($prepared_source->token_id);
616 616
 						$wc_token->delete();
617
-						$localized_message = __( 'This card is no longer available and has been removed.', 'woocommerce-gateway-stripe' );
618
-						$order->add_order_note( $localized_message );
619
-						throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message );
617
+						$localized_message = __('This card is no longer available and has been removed.', 'woocommerce-gateway-stripe');
618
+						$order->add_order_note($localized_message);
619
+						throw new WC_Stripe_Exception(print_r($response, true), $localized_message);
620 620
 					}
621 621
 
622 622
 					$localized_messages = WC_Stripe_Helper::get_localized_messages();
623 623
 
624
-					if ( 'card_error' === $response->error->type ) {
625
-						$localized_message = isset( $localized_messages[ $response->error->code ] ) ? $localized_messages[ $response->error->code ] : $response->error->message;
624
+					if ('card_error' === $response->error->type) {
625
+						$localized_message = isset($localized_messages[$response->error->code]) ? $localized_messages[$response->error->code] : $response->error->message;
626 626
 					} else {
627
-						$localized_message = isset( $localized_messages[ $response->error->type ] ) ? $localized_messages[ $response->error->type ] : $response->error->message;
627
+						$localized_message = isset($localized_messages[$response->error->type]) ? $localized_messages[$response->error->type] : $response->error->message;
628 628
 					}
629 629
 
630
-					$order->add_order_note( $localized_message );
630
+					$order->add_order_note($localized_message);
631 631
 
632
-					throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message );
632
+					throw new WC_Stripe_Exception(print_r($response, true), $localized_message);
633 633
 				}
634 634
 
635
-				do_action( 'wc_gateway_stripe_process_payment', $response, $order );
635
+				do_action('wc_gateway_stripe_process_payment', $response, $order);
636 636
 
637 637
 				// Process valid response.
638
-				$this->process_response( $response, $order );
638
+				$this->process_response($response, $order);
639 639
 			} else {
640 640
 				$order->payment_complete();
641 641
 			}
@@ -646,17 +646,17 @@  discard block
 block discarded – undo
646 646
 			// Return thank you page redirect.
647 647
 			return array(
648 648
 				'result'   => 'success',
649
-				'redirect' => $this->get_return_url( $order ),
649
+				'redirect' => $this->get_return_url($order),
650 650
 			);
651 651
 
652
-		} catch ( WC_Stripe_Exception $e ) {
653
-			wc_add_notice( $e->getLocalizedMessage(), 'error' );
654
-			WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() );
652
+		} catch (WC_Stripe_Exception $e) {
653
+			wc_add_notice($e->getLocalizedMessage(), 'error');
654
+			WC_Stripe_Logger::log('Error: ' . $e->getMessage());
655 655
 
656
-			do_action( 'wc_gateway_stripe_process_payment_error', $e, $order );
656
+			do_action('wc_gateway_stripe_process_payment_error', $e, $order);
657 657
 
658
-			if ( $order->has_status( array( 'pending', 'failed' ) ) ) {
659
-				$this->send_failed_order_email( $order_id );
658
+			if ($order->has_status(array('pending', 'failed'))) {
659
+				$this->send_failed_order_email($order_id);
660 660
 			}
661 661
 
662 662
 			return array(
Please login to merge, or discard this patch.
includes/class-wc-stripe-api.php 1 patch
Spacing   +27 added lines, -27 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
 
@@ -26,7 +26,7 @@  discard block
 block discarded – undo
26 26
 	 * Set secret API Key.
27 27
 	 * @param string $key
28 28
 	 */
29
-	public static function set_secret_key( $secret_key ) {
29
+	public static function set_secret_key($secret_key) {
30 30
 		self::$secret_key = $secret_key;
31 31
 	}
32 32
 
@@ -35,11 +35,11 @@  discard block
 block discarded – undo
35 35
 	 * @return string
36 36
 	 */
37 37
 	public static function get_secret_key() {
38
-		if ( ! self::$secret_key ) {
39
-			$options = get_option( 'woocommerce_stripe_settings' );
38
+		if ( ! self::$secret_key) {
39
+			$options = get_option('woocommerce_stripe_settings');
40 40
 
41
-			if ( isset( $options['testmode'], $options['secret_key'], $options['test_secret_key'] ) ) {
42
-				self::set_secret_key( 'yes' === $options['testmode'] ? $options['test_secret_key'] : $options['secret_key'] );
41
+			if (isset($options['testmode'], $options['secret_key'], $options['test_secret_key'])) {
42
+				self::set_secret_key('yes' === $options['testmode'] ? $options['test_secret_key'] : $options['secret_key']);
43 43
 			}
44 44
 		}
45 45
 		return self::$secret_key;
@@ -78,12 +78,12 @@  discard block
 block discarded – undo
78 78
 		$user_agent = self::get_user_agent();
79 79
 		$app_info   = $user_agent['application'];
80 80
 
81
-		return apply_filters( 'woocommerce_stripe_request_headers', array(
82
-			'Authorization'              => 'Basic ' . base64_encode( self::get_secret_key() . ':' ),
81
+		return apply_filters('woocommerce_stripe_request_headers', array(
82
+			'Authorization'              => 'Basic ' . base64_encode(self::get_secret_key() . ':'),
83 83
 			'Stripe-Version'             => self::STRIPE_API_VERSION,
84 84
 			'User-Agent'                 => $app_info['name'] . '/' . $app_info['version'] . ' (' . $app_info['url'] . ')',
85
-			'X-Stripe-Client-User-Agent' => json_encode( $user_agent ),
86
-		) );
85
+			'X-Stripe-Client-User-Agent' => json_encode($user_agent),
86
+		));
87 87
 	}
88 88
 
89 89
 	/**
@@ -95,16 +95,16 @@  discard block
 block discarded – undo
95 95
 	 * @param string $api
96 96
 	 * @return array|WP_Error
97 97
 	 */
98
-	public static function request( $request, $api = 'charges', $method = 'POST' ) {
99
-		WC_Stripe_Logger::log( "{$api} request: " . print_r( $request, true ) );
98
+	public static function request($request, $api = 'charges', $method = 'POST') {
99
+		WC_Stripe_Logger::log("{$api} request: " . print_r($request, true));
100 100
 
101 101
 		$headers = self::get_headers();
102 102
 
103
-		if ( 'charges' === $api && 'POST' === $method ) {
104
-			$customer = ! empty( $request['customer'] ) ? $request['customer'] : '';
105
-			$source   = ! empty( $request['source'] ) ? $request['source'] : $customer;
103
+		if ('charges' === $api && 'POST' === $method) {
104
+			$customer = ! empty($request['customer']) ? $request['customer'] : '';
105
+			$source   = ! empty($request['source']) ? $request['source'] : $customer;
106 106
 
107
-			$headers['Idempotency-Key'] = apply_filters( 'wc_stripe_idempotency_key', $request['metadata']['order_id'] . '-' . $source, $request );
107
+			$headers['Idempotency-Key'] = apply_filters('wc_stripe_idempotency_key', $request['metadata']['order_id'] . '-' . $source, $request);
108 108
 		}
109 109
 
110 110
 		$response = wp_safe_remote_post(
@@ -112,17 +112,17 @@  discard block
 block discarded – undo
112 112
 			array(
113 113
 				'method'  => $method,
114 114
 				'headers' => $headers,
115
-				'body'    => apply_filters( 'woocommerce_stripe_request_body', $request, $api ),
115
+				'body'    => apply_filters('woocommerce_stripe_request_body', $request, $api),
116 116
 				'timeout' => 70,
117 117
 			)
118 118
 		);
119 119
 
120
-		if ( is_wp_error( $response ) || empty( $response['body'] ) ) {
121
-			WC_Stripe_Logger::log( 'Error Response: ' . print_r( $response, true ) );
122
-			throw new WC_Stripe_Exception( print_r( $response, true ), __( 'There was a problem connecting to the Stripe API endpoint.', 'woocommerce-gateway-stripe' ) );
120
+		if (is_wp_error($response) || empty($response['body'])) {
121
+			WC_Stripe_Logger::log('Error Response: ' . print_r($response, true));
122
+			throw new WC_Stripe_Exception(print_r($response, true), __('There was a problem connecting to the Stripe API endpoint.', 'woocommerce-gateway-stripe'));
123 123
 		}
124 124
 
125
-		return json_decode( $response['body'] );
125
+		return json_decode($response['body']);
126 126
 	}
127 127
 
128 128
 	/**
@@ -132,8 +132,8 @@  discard block
 block discarded – undo
132 132
 	 * @version 4.0.0
133 133
 	 * @param string $api
134 134
 	 */
135
-	public static function retrieve( $api ) {
136
-		WC_Stripe_Logger::log( "{$api}" );
135
+	public static function retrieve($api) {
136
+		WC_Stripe_Logger::log("{$api}");
137 137
 
138 138
 		$response = wp_safe_remote_get(
139 139
 			self::ENDPOINT . $api,
@@ -144,11 +144,11 @@  discard block
 block discarded – undo
144 144
 			)
145 145
 		);
146 146
 
147
-		if ( is_wp_error( $response ) || empty( $response['body'] ) ) {
148
-			WC_Stripe_Logger::log( 'Error Response: ' . print_r( $response, true ) );
149
-			return new WP_Error( 'stripe_error', __( 'There was a problem connecting to the Stripe API endpoint.', 'woocommerce-gateway-stripe' ) );
147
+		if (is_wp_error($response) || empty($response['body'])) {
148
+			WC_Stripe_Logger::log('Error Response: ' . print_r($response, true));
149
+			return new WP_Error('stripe_error', __('There was a problem connecting to the Stripe API endpoint.', 'woocommerce-gateway-stripe'));
150 150
 		}
151 151
 
152
-		return json_decode( $response['body'] );
152
+		return json_decode($response['body']);
153 153
 	}
154 154
 }
Please login to merge, or discard this patch.