Completed
Push — master ( 988dc8...dbe449 )
by Roy
05:30
created
includes/compat/class-wc-stripe-compat.php 1 patch
Spacing   +183 added lines, -183 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,24 +84,24 @@  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
-			$prepared_source = $this->prepare_source( get_current_user_id(), true );
89
+			$subscription    = wc_get_order($order_id);
90
+			$prepared_source = $this->prepare_source(get_current_user_id(), true);
91 91
 			$source_object   = $prepared_source->source_object;
92 92
 
93 93
 			// Check if we don't allow prepaid credit cards.
94
-			if ( ! apply_filters( 'wc_stripe_allow_prepaid_card', true ) && $this->is_prepaid_card( $source_object ) ) {
95
-				$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' );
96
-				throw new WC_Stripe_Exception( print_r( $source_object, true ), $localized_message );
94
+			if ( ! apply_filters('wc_stripe_allow_prepaid_card', true) && $this->is_prepaid_card($source_object)) {
95
+				$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');
96
+				throw new WC_Stripe_Exception(print_r($source_object, true), $localized_message);
97 97
 			}
98 98
 
99
-			if ( empty( $prepared_source->source ) ) {
100
-				$localized_message = __( 'Payment processing failed. Please retry.', 'woocommerce-gateway-stripe' );
101
-				throw new WC_Stripe_Exception( print_r( $prepared_source, true ), $localized_message );
99
+			if (empty($prepared_source->source)) {
100
+				$localized_message = __('Payment processing failed. Please retry.', 'woocommerce-gateway-stripe');
101
+				throw new WC_Stripe_Exception(print_r($prepared_source, true), $localized_message);
102 102
 			}
103 103
 
104
-			$this->save_source_to_order( $subscription, $prepared_source );
104
+			$this->save_source_to_order($subscription, $prepared_source);
105 105
 
106 106
 			/*
107 107
 			 * Check if card 3DS is required or optional with 3DS setting.
@@ -110,41 +110,41 @@  discard block
 block discarded – undo
110 110
 			 * Note that if we need to save source, the original source must be first
111 111
 			 * attached to a customer in Stripe before it can be charged.
112 112
 			 */
113
-			if ( $this->is_3ds_required( $source_object ) ) {
113
+			if ($this->is_3ds_required($source_object)) {
114 114
 				$order    = $subscription->get_parent();
115
-				$response = $this->create_3ds_source( $order, $source_object, $subscription->get_view_order_url() );
115
+				$response = $this->create_3ds_source($order, $source_object, $subscription->get_view_order_url());
116 116
 
117
-				if ( ! empty( $response->error ) ) {
117
+				if ( ! empty($response->error)) {
118 118
 					$localized_message = $response->error->message;
119 119
 
120
-					$order->add_order_note( $localized_message );
120
+					$order->add_order_note($localized_message);
121 121
 
122
-					throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message );
122
+					throw new WC_Stripe_Exception(print_r($response, true), $localized_message);
123 123
 				}
124 124
 
125 125
 				// Update order meta with 3DS source.
126
-				if ( WC_Stripe_Helper::is_pre_30() ) {
127
-					update_post_meta( $order_id, '_stripe_source_id', $response->id );
126
+				if (WC_Stripe_Helper::is_pre_30()) {
127
+					update_post_meta($order_id, '_stripe_source_id', $response->id);
128 128
 				} else {
129
-					$subscription->update_meta_data( '_stripe_source_id', $response->id );
129
+					$subscription->update_meta_data('_stripe_source_id', $response->id);
130 130
 					$subscription->save();
131 131
 				}
132 132
 
133
-				WC_Stripe_Logger::log( 'Info: Redirecting to 3DS...' );
133
+				WC_Stripe_Logger::log('Info: Redirecting to 3DS...');
134 134
 
135 135
 				return array(
136 136
 					'result'   => 'success',
137
-					'redirect' => esc_url_raw( $response->redirect->url ),
137
+					'redirect' => esc_url_raw($response->redirect->url),
138 138
 				);
139 139
 			}
140 140
 
141 141
 			return array(
142 142
 				'result'   => 'success',
143
-				'redirect' => $this->get_return_url( $subscription ),
143
+				'redirect' => $this->get_return_url($subscription),
144 144
 			);
145
-		} catch ( WC_Stripe_Exception $e ) {
146
-			wc_add_notice( $e->getLocalizedMessage(), 'error' );
147
-			WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() );
145
+		} catch (WC_Stripe_Exception $e) {
146
+			wc_add_notice($e->getLocalizedMessage(), 'error');
147
+			WC_Stripe_Logger::log('Error: ' . $e->getMessage());
148 148
 		}
149 149
 	}
150 150
 
@@ -153,18 +153,18 @@  discard block
 block discarded – undo
153 153
 	 * @param  int $order_id
154 154
 	 * @return array
155 155
 	 */
156
-	public function process_payment( $order_id, $retry = true, $force_save_source = false ) {
157
-		if ( $this->has_subscription( $order_id ) ) {
158
-			if ( $this->is_subs_change_payment() ) {
159
-				return $this->change_subs_payment_method( $order_id );
156
+	public function process_payment($order_id, $retry = true, $force_save_source = false) {
157
+		if ($this->has_subscription($order_id)) {
158
+			if ($this->is_subs_change_payment()) {
159
+				return $this->change_subs_payment_method($order_id);
160 160
 			}
161 161
 
162 162
 			// Regular payment with force customer enabled
163
-			return parent::process_payment( $order_id, true, true );
164
-		} elseif ( $this->is_pre_order( $order_id ) ) {
165
-			return $this->process_pre_order( $order_id, $retry, $force_save_source );
163
+			return parent::process_payment($order_id, true, true);
164
+		} elseif ($this->is_pre_order($order_id)) {
165
+			return $this->process_pre_order($order_id, $retry, $force_save_source);
166 166
 		} else {
167
-			return parent::process_payment( $order_id, $retry, $force_save_source );
167
+			return parent::process_payment($order_id, $retry, $force_save_source);
168 168
 		}
169 169
 	}
170 170
 
@@ -174,24 +174,24 @@  discard block
 block discarded – undo
174 174
 	 * @since 3.1.0
175 175
 	 * @version 4.0.0
176 176
 	 */
177
-	public function save_source_to_order( $order, $source ) {
178
-		parent::save_source_to_order( $order, $source );
177
+	public function save_source_to_order($order, $source) {
178
+		parent::save_source_to_order($order, $source);
179 179
 
180 180
 		$order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
181 181
 
182 182
 		// Also store it on the subscriptions being purchased or paid for in the order
183
-		if ( function_exists( 'wcs_order_contains_subscription' ) && wcs_order_contains_subscription( $order_id ) ) {
184
-			$subscriptions = wcs_get_subscriptions_for_order( $order_id );
185
-		} elseif ( function_exists( 'wcs_order_contains_renewal' ) && wcs_order_contains_renewal( $order_id ) ) {
186
-			$subscriptions = wcs_get_subscriptions_for_renewal_order( $order_id );
183
+		if (function_exists('wcs_order_contains_subscription') && wcs_order_contains_subscription($order_id)) {
184
+			$subscriptions = wcs_get_subscriptions_for_order($order_id);
185
+		} elseif (function_exists('wcs_order_contains_renewal') && wcs_order_contains_renewal($order_id)) {
186
+			$subscriptions = wcs_get_subscriptions_for_renewal_order($order_id);
187 187
 		} else {
188 188
 			$subscriptions = array();
189 189
 		}
190 190
 
191
-		foreach ( $subscriptions as $subscription ) {
191
+		foreach ($subscriptions as $subscription) {
192 192
 			$subscription_id = WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id();
193
-			update_post_meta( $subscription_id, '_stripe_customer_id', $source->customer );
194
-			update_post_meta( $subscription_id, '_stripe_source_id', $source->source );
193
+			update_post_meta($subscription_id, '_stripe_customer_id', $source->customer);
194
+			update_post_meta($subscription_id, '_stripe_source_id', $source->source);
195 195
 		}
196 196
 	}
197 197
 
@@ -204,45 +204,45 @@  discard block
 block discarded – undo
204 204
 	 * @param mixed $renewal_order
205 205
 	 * @param bool $is_retry Is this a retry process.
206 206
 	 */
207
-	public function process_subscription_payment( $amount = 0.0, $renewal_order, $is_retry = false ) {
208
-		if ( $amount * 100 < WC_Stripe_Helper::get_minimum_amount() ) {
207
+	public function process_subscription_payment($amount = 0.0, $renewal_order, $is_retry = false) {
208
+		if ($amount * 100 < WC_Stripe_Helper::get_minimum_amount()) {
209 209
 			/* translators: minimum amount */
210
-			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 ) ) );
210
+			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)));
211 211
 		}
212 212
 
213 213
 		$order_id = WC_Stripe_Helper::is_pre_30() ? $renewal_order->id : $renewal_order->get_id();
214 214
 
215 215
 		// Get source from order
216
-		$prepared_source = $this->prepare_order_source( $renewal_order );
216
+		$prepared_source = $this->prepare_order_source($renewal_order);
217 217
 
218
-		if ( ! $prepared_source->customer ) {
219
-			return new WP_Error( 'stripe_error', __( 'Customer not found', 'woocommerce-gateway-stripe' ) );
218
+		if ( ! $prepared_source->customer) {
219
+			return new WP_Error('stripe_error', __('Customer not found', 'woocommerce-gateway-stripe'));
220 220
 		}
221 221
 
222
-		WC_Stripe_Logger::log( "Info: Begin processing subscription payment for order {$order_id} for the amount of {$amount}" );
222
+		WC_Stripe_Logger::log("Info: Begin processing subscription payment for order {$order_id} for the amount of {$amount}");
223 223
 
224
-		if ( $is_retry ) {
224
+		if ($is_retry) {
225 225
 			// Passing empty source with charge customer default.
226 226
 			$prepared_source->source = '';
227 227
 		}
228 228
 
229
-		$request            = $this->generate_payment_request( $renewal_order, $prepared_source );
229
+		$request            = $this->generate_payment_request($renewal_order, $prepared_source);
230 230
 		$request['capture'] = 'true';
231
-		$request['amount']  = WC_Stripe_Helper::get_stripe_amount( $amount, $request['currency'] );
232
-		$response           = WC_Stripe_API::request( $request );
231
+		$request['amount']  = WC_Stripe_Helper::get_stripe_amount($amount, $request['currency']);
232
+		$response           = WC_Stripe_API::request($request);
233 233
 
234
-		if ( ! empty( $response->error ) || is_wp_error( $response ) ) {
235
-			if ( $is_retry ) {
234
+		if ( ! empty($response->error) || is_wp_error($response)) {
235
+			if ($is_retry) {
236 236
 				/* translators: error message */
237
-				$renewal_order->update_status( 'failed', sprintf( __( 'Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe' ), $response->error->message ) );
237
+				$renewal_order->update_status('failed', sprintf(__('Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe'), $response->error->message));
238 238
 			}
239 239
 
240 240
 			return $response; // Default catch all errors.
241 241
 		}
242 242
 
243
-		$this->process_response( $response, $renewal_order );
243
+		$this->process_response($response, $renewal_order);
244 244
 
245
-		if ( ! $is_retry ) {
245
+		if ( ! $is_retry) {
246 246
 			return $response;
247 247
 		}
248 248
 	}
@@ -251,21 +251,21 @@  discard block
 block discarded – undo
251 251
 	 * Don't transfer Stripe customer/token meta to resubscribe orders.
252 252
 	 * @param int $resubscribe_order The order created for the customer to resubscribe to the old expired/cancelled subscription
253 253
 	 */
254
-	public function delete_resubscribe_meta( $resubscribe_order ) {
255
-		delete_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id() ), '_stripe_customer_id' );
256
-		delete_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id() ), '_stripe_source_id' );
254
+	public function delete_resubscribe_meta($resubscribe_order) {
255
+		delete_post_meta((WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id()), '_stripe_customer_id');
256
+		delete_post_meta((WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id()), '_stripe_source_id');
257 257
 		// For BW compat will remove in future
258
-		delete_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id() ), '_stripe_card_id' );
259
-		$this->delete_renewal_meta( $resubscribe_order );
258
+		delete_post_meta((WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id()), '_stripe_card_id');
259
+		$this->delete_renewal_meta($resubscribe_order);
260 260
 	}
261 261
 
262 262
 	/**
263 263
 	 * Don't transfer Stripe fee/ID meta to renewal orders.
264 264
 	 * @param int $resubscribe_order The order created for the customer to resubscribe to the old expired/cancelled subscription
265 265
 	 */
266
-	public function delete_renewal_meta( $renewal_order ) {
267
-		delete_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $renewal_order->id : $renewal_order->get_id() ), 'Stripe Fee' );
268
-		delete_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $renewal_order->id : $renewal_order->get_id() ), 'Net Revenue From Stripe' );
266
+	public function delete_renewal_meta($renewal_order) {
267
+		delete_post_meta((WC_Stripe_Helper::is_pre_30() ? $renewal_order->id : $renewal_order->get_id()), 'Stripe Fee');
268
+		delete_post_meta((WC_Stripe_Helper::is_pre_30() ? $renewal_order->id : $renewal_order->get_id()), 'Net Revenue From Stripe');
269 269
 		return $renewal_order;
270 270
 	}
271 271
 
@@ -275,21 +275,21 @@  discard block
 block discarded – undo
275 275
 	 * @param $amount_to_charge float The amount to charge.
276 276
 	 * @param $renewal_order WC_Order A WC_Order object created to record the renewal payment.
277 277
 	 */
278
-	public function scheduled_subscription_payment( $amount_to_charge, $renewal_order ) {
279
-		$response = $this->process_subscription_payment( $amount_to_charge, $renewal_order );
278
+	public function scheduled_subscription_payment($amount_to_charge, $renewal_order) {
279
+		$response = $this->process_subscription_payment($amount_to_charge, $renewal_order);
280 280
 
281
-		if ( is_wp_error( $response ) ) {
281
+		if (is_wp_error($response)) {
282 282
 			/* translators: error message */
283
-			$renewal_order->update_status( 'failed', sprintf( __( 'Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe' ), $response->get_error_message() ) );
283
+			$renewal_order->update_status('failed', sprintf(__('Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe'), $response->get_error_message()));
284 284
 		}
285 285
 
286
-		if ( ! empty( $response->error ) ) {
286
+		if ( ! empty($response->error)) {
287 287
 			// This is a very generic error to listen for but worth a retry before total fail.
288
-			if ( isset( $response->error->type ) && 'invalid_request_error' === $response->error->type && apply_filters( 'wc_stripe_use_default_customer_source', true ) ) {
289
-				$this->process_subscription_payment( $amount_to_charge, $renewal_order, true );
288
+			if (isset($response->error->type) && 'invalid_request_error' === $response->error->type && apply_filters('wc_stripe_use_default_customer_source', true)) {
289
+				$this->process_subscription_payment($amount_to_charge, $renewal_order, true);
290 290
 			} else {
291 291
 				/* translators: error message */
292
-				$renewal_order->update_status( 'failed', sprintf( __( 'Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe' ), $response->error->message ) );
292
+				$renewal_order->update_status('failed', sprintf(__('Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe'), $response->error->message));
293 293
 			}
294 294
 		}
295 295
 	}
@@ -298,20 +298,20 @@  discard block
 block discarded – undo
298 298
 	 * Remove order meta
299 299
 	 * @param object $order
300 300
 	 */
301
-	public function remove_order_source_before_retry( $order ) {
301
+	public function remove_order_source_before_retry($order) {
302 302
 		$order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
303
-		delete_post_meta( $order_id, '_stripe_source_id' );
303
+		delete_post_meta($order_id, '_stripe_source_id');
304 304
 		// For BW compat will remove in the future.
305
-		delete_post_meta( $order_id, '_stripe_card_id' );
305
+		delete_post_meta($order_id, '_stripe_card_id');
306 306
 	}
307 307
 
308 308
 	/**
309 309
 	 * Remove order meta
310 310
 	 * @param  object $order
311 311
 	 */
312
-	public function remove_order_customer_before_retry( $order ) {
312
+	public function remove_order_customer_before_retry($order) {
313 313
 		$order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
314
-		delete_post_meta( $order_id, '_stripe_customer_id' );
314
+		delete_post_meta($order_id, '_stripe_customer_id');
315 315
 	}
316 316
 
317 317
 	/**
@@ -323,14 +323,14 @@  discard block
 block discarded – undo
323 323
 	 * @param WC_Order $renewal_order The order which recorded the successful payment (to make up for the failed automatic payment).
324 324
 	 * @return void
325 325
 	 */
326
-	public function update_failing_payment_method( $subscription, $renewal_order ) {
327
-		if ( WC_Stripe_Helper::is_pre_30() ) {
328
-			update_post_meta( $subscription->id, '_stripe_customer_id', $renewal_order->stripe_customer_id );
329
-			update_post_meta( $subscription->id, '_stripe_source_id', $renewal_order->stripe_source_id );
326
+	public function update_failing_payment_method($subscription, $renewal_order) {
327
+		if (WC_Stripe_Helper::is_pre_30()) {
328
+			update_post_meta($subscription->id, '_stripe_customer_id', $renewal_order->stripe_customer_id);
329
+			update_post_meta($subscription->id, '_stripe_source_id', $renewal_order->stripe_source_id);
330 330
 
331 331
 		} else {
332
-			update_post_meta( $subscription->get_id(), '_stripe_customer_id', $renewal_order->get_meta( '_stripe_customer_id', true ) );
333
-			update_post_meta( $subscription->get_id(), '_stripe_source_id', $renewal_order->get_meta( '_stripe_source_id', true ) );
332
+			update_post_meta($subscription->get_id(), '_stripe_customer_id', $renewal_order->get_meta('_stripe_customer_id', true));
333
+			update_post_meta($subscription->get_id(), '_stripe_source_id', $renewal_order->get_meta('_stripe_source_id', true));
334 334
 		}
335 335
 	}
336 336
 
@@ -343,21 +343,21 @@  discard block
 block discarded – undo
343 343
 	 * @param WC_Subscription $subscription An instance of a subscription object
344 344
 	 * @return array
345 345
 	 */
346
-	public function add_subscription_payment_meta( $payment_meta, $subscription ) {
347
-		$source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_source_id', true );
346
+	public function add_subscription_payment_meta($payment_meta, $subscription) {
347
+		$source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_source_id', true);
348 348
 
349 349
 		// For BW compat will remove in future.
350
-		if ( empty( $source_id ) ) {
351
-			$source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_card_id', true );
350
+		if (empty($source_id)) {
351
+			$source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_card_id', true);
352 352
 
353 353
 			// Take this opportunity to update the key name.
354
-			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 );
354
+			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);
355 355
 		}
356 356
 
357
-		$payment_meta[ $this->id ] = array(
357
+		$payment_meta[$this->id] = array(
358 358
 			'post_meta' => array(
359 359
 				'_stripe_customer_id' => array(
360
-					'value' => get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_customer_id', true ),
360
+					'value' => get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_customer_id', true),
361 361
 					'label' => 'Stripe Customer ID',
362 362
 				),
363 363
 				'_stripe_source_id' => array(
@@ -380,22 +380,22 @@  discard block
 block discarded – undo
380 380
 	 * @param array $payment_meta associative array of meta data required for automatic payments
381 381
 	 * @return array
382 382
 	 */
383
-	public function validate_subscription_payment_meta( $payment_method_id, $payment_meta ) {
384
-		if ( $this->id === $payment_method_id ) {
383
+	public function validate_subscription_payment_meta($payment_method_id, $payment_meta) {
384
+		if ($this->id === $payment_method_id) {
385 385
 
386
-			if ( ! isset( $payment_meta['post_meta']['_stripe_customer_id']['value'] ) || empty( $payment_meta['post_meta']['_stripe_customer_id']['value'] ) ) {
387
-				throw new Exception( __( 'A "Stripe Customer ID" value is required.', 'woocommerce-gateway-stripe' ) );
388
-			} elseif ( 0 !== strpos( $payment_meta['post_meta']['_stripe_customer_id']['value'], 'cus_' ) ) {
389
-				throw new Exception( __( 'Invalid customer ID. A valid "Stripe Customer ID" must begin with "cus_".', 'woocommerce-gateway-stripe' ) );
386
+			if ( ! isset($payment_meta['post_meta']['_stripe_customer_id']['value']) || empty($payment_meta['post_meta']['_stripe_customer_id']['value'])) {
387
+				throw new Exception(__('A "Stripe Customer ID" value is required.', 'woocommerce-gateway-stripe'));
388
+			} elseif (0 !== strpos($payment_meta['post_meta']['_stripe_customer_id']['value'], 'cus_')) {
389
+				throw new Exception(__('Invalid customer ID. A valid "Stripe Customer ID" must begin with "cus_".', 'woocommerce-gateway-stripe'));
390 390
 			}
391 391
 
392 392
 			if (
393
-				( ! empty( $payment_meta['post_meta']['_stripe_source_id']['value'] )
394
-				&& 0 !== strpos( $payment_meta['post_meta']['_stripe_source_id']['value'], 'card_' ) )
395
-				&& ( ! empty( $payment_meta['post_meta']['_stripe_source_id']['value'] )
396
-				&& 0 !== strpos( $payment_meta['post_meta']['_stripe_source_id']['value'], 'src_' ) ) ) {
393
+				( ! empty($payment_meta['post_meta']['_stripe_source_id']['value'])
394
+				&& 0 !== strpos($payment_meta['post_meta']['_stripe_source_id']['value'], 'card_'))
395
+				&& ( ! empty($payment_meta['post_meta']['_stripe_source_id']['value'])
396
+				&& 0 !== strpos($payment_meta['post_meta']['_stripe_source_id']['value'], 'src_')) ) {
397 397
 
398
-				throw new Exception( __( 'Invalid source ID. A valid source "Stripe Source ID" must begin with "src_" or "card_".', 'woocommerce-gateway-stripe' ) );
398
+				throw new Exception(__('Invalid source ID. A valid source "Stripe Source ID" must begin with "src_" or "card_".', 'woocommerce-gateway-stripe'));
399 399
 			}
400 400
 		}
401 401
 	}
@@ -408,92 +408,92 @@  discard block
 block discarded – undo
408 408
 	 * @param WC_Subscription $subscription the subscription details
409 409
 	 * @return string the subscription payment method
410 410
 	 */
411
-	public function maybe_render_subscription_payment_method( $payment_method_to_display, $subscription ) {
411
+	public function maybe_render_subscription_payment_method($payment_method_to_display, $subscription) {
412 412
 		$customer_user = WC_Stripe_Helper::is_pre_30() ? $subscription->customer_user : $subscription->get_customer_id();
413 413
 
414 414
 		// bail for other payment methods
415
-		if ( ( WC_Stripe_Helper::is_pre_30() ? $subscription->payment_method : $subscription->get_payment_method() ) !== $this->id || ! $customer_user ) {
415
+		if ((WC_Stripe_Helper::is_pre_30() ? $subscription->payment_method : $subscription->get_payment_method()) !== $this->id || ! $customer_user) {
416 416
 			return $payment_method_to_display;
417 417
 		}
418 418
 
419
-		$stripe_source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_source_id', true );
419
+		$stripe_source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_source_id', true);
420 420
 
421 421
 		// For BW compat will remove in future.
422
-		if ( empty( $stripe_source_id ) ) {
423
-			$stripe_source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_card_id', true );
422
+		if (empty($stripe_source_id)) {
423
+			$stripe_source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_card_id', true);
424 424
 
425 425
 			// Take this opportunity to update the key name.
426
-			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 );
426
+			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);
427 427
 		}
428 428
 
429 429
 		$stripe_customer    = new WC_Stripe_Customer();
430
-		$stripe_customer_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_customer_id', true );
430
+		$stripe_customer_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_customer_id', true);
431 431
 
432 432
 		// If we couldn't find a Stripe customer linked to the subscription, fallback to the user meta data.
433
-		if ( ! $stripe_customer_id || ! is_string( $stripe_customer_id ) ) {
433
+		if ( ! $stripe_customer_id || ! is_string($stripe_customer_id)) {
434 434
 			$user_id            = $customer_user;
435
-			$stripe_customer_id = get_user_meta( $user_id, '_stripe_customer_id', true );
436
-			$stripe_source_id   = get_user_meta( $user_id, '_stripe_source_id', true );
435
+			$stripe_customer_id = get_user_meta($user_id, '_stripe_customer_id', true);
436
+			$stripe_source_id   = get_user_meta($user_id, '_stripe_source_id', true);
437 437
 
438 438
 			// For BW compat will remove in future.
439
-			if ( empty( $stripe_source_id ) ) {
440
-				$stripe_source_id = get_user_meta( $user_id, '_stripe_card_id', true );
439
+			if (empty($stripe_source_id)) {
440
+				$stripe_source_id = get_user_meta($user_id, '_stripe_card_id', true);
441 441
 
442 442
 				// Take this opportunity to update the key name.
443
-				update_user_meta( $user_id, '_stripe_source_id', $stripe_source_id );
443
+				update_user_meta($user_id, '_stripe_source_id', $stripe_source_id);
444 444
 			}
445 445
 		}
446 446
 
447 447
 		// If we couldn't find a Stripe customer linked to the account, fallback to the order meta data.
448
-		if ( ( ! $stripe_customer_id || ! is_string( $stripe_customer_id ) ) && false !== $subscription->order ) {
449
-			$stripe_customer_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id() ), '_stripe_customer_id', true );
450
-			$stripe_source_id   = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id() ), '_stripe_source_id', true );
448
+		if (( ! $stripe_customer_id || ! is_string($stripe_customer_id)) && false !== $subscription->order) {
449
+			$stripe_customer_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id()), '_stripe_customer_id', true);
450
+			$stripe_source_id   = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id()), '_stripe_source_id', true);
451 451
 
452 452
 			// For BW compat will remove in future.
453
-			if ( empty( $stripe_source_id ) ) {
454
-				$stripe_source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id() ), '_stripe_card_id', true );
453
+			if (empty($stripe_source_id)) {
454
+				$stripe_source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id()), '_stripe_card_id', true);
455 455
 
456 456
 				// Take this opportunity to update the key name.
457
-				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 );
457
+				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);
458 458
 			}
459 459
 		}
460 460
 
461
-		$stripe_customer->set_id( $stripe_customer_id );
461
+		$stripe_customer->set_id($stripe_customer_id);
462 462
 		$sources = $stripe_customer->get_sources();
463 463
 
464
-		if ( $sources ) {
464
+		if ($sources) {
465 465
 			$card         = false;
466 466
 			$found_source = false;
467
-			foreach ( $sources as $source ) {
468
-				if ( isset( $source->type ) && 'card' === $source->type ) {
467
+			foreach ($sources as $source) {
468
+				if (isset($source->type) && 'card' === $source->type) {
469 469
 					$card = $source->card;
470
-				} elseif ( isset( $source->object ) && 'card' === $source->object ) {
470
+				} elseif (isset($source->object) && 'card' === $source->object) {
471 471
 					$card = $source;
472 472
 				}
473 473
 
474
-				if ( $source->id === $stripe_source_id ) {
474
+				if ($source->id === $stripe_source_id) {
475 475
 					$found_source = true;
476 476
 
477
-					if ( $card ) {
477
+					if ($card) {
478 478
 						/* translators: 1) card brand 2) last 4 digits */
479
-						$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 );
479
+						$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);
480 480
 					} else {
481
-						$payment_method_to_display = __( 'N/A', 'woocommerce-gateway-stripe' );
481
+						$payment_method_to_display = __('N/A', 'woocommerce-gateway-stripe');
482 482
 					}
483 483
 					break;
484 484
 				}
485 485
 			}
486 486
 
487
-			if ( ! $found_source ) {
488
-				if ( 'card' === $sources[0]->type ) {
487
+			if ( ! $found_source) {
488
+				if ('card' === $sources[0]->type) {
489 489
 					$card = $sources[0]->card;
490 490
 				}
491 491
 
492
-				if ( $card ) {
492
+				if ($card) {
493 493
 					/* translators: 1) card brand 2) last 4 digits */
494
-					$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 );
494
+					$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);
495 495
 				} else {
496
-					$payment_method_to_display = __( 'N/A', 'woocommerce-gateway-stripe' );
496
+					$payment_method_to_display = __('N/A', 'woocommerce-gateway-stripe');
497 497
 				}
498 498
 			}
499 499
 		}
@@ -506,42 +506,42 @@  discard block
 block discarded – undo
506 506
 	 * @param int $order_id
507 507
 	 * @return array
508 508
 	 */
509
-	public function process_pre_order( $order_id, $retry, $force_save_source ) {
510
-		if ( WC_Pre_Orders_Order::order_requires_payment_tokenization( $order_id ) ) {
509
+	public function process_pre_order($order_id, $retry, $force_save_source) {
510
+		if (WC_Pre_Orders_Order::order_requires_payment_tokenization($order_id)) {
511 511
 			try {
512
-				$order = wc_get_order( $order_id );
512
+				$order = wc_get_order($order_id);
513 513
 
514
-				if ( $order->get_total() * 100 < WC_Stripe_Helper::get_minimum_amount() ) {
514
+				if ($order->get_total() * 100 < WC_Stripe_Helper::get_minimum_amount()) {
515 515
 					/* translators: minimum amount */
516
-					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 ) ) );
516
+					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)));
517 517
 				}
518 518
 
519
-				$prepared_source = $this->prepare_source( get_current_user_id(), true );
519
+				$prepared_source = $this->prepare_source(get_current_user_id(), true);
520 520
 
521 521
 				// We need a source on file to continue.
522
-				if ( empty( $prepared_source->customer ) || empty( $prepared_source->source ) ) {
523
-					throw new Exception( __( 'Unable to store payment details. Please try again.', 'woocommerce-gateway-stripe' ) );
522
+				if (empty($prepared_source->customer) || empty($prepared_source->source)) {
523
+					throw new Exception(__('Unable to store payment details. Please try again.', 'woocommerce-gateway-stripe'));
524 524
 				}
525 525
 
526
-				$this->save_source_to_order( $order, $prepared_source );
526
+				$this->save_source_to_order($order, $prepared_source);
527 527
 
528 528
 				// Remove cart
529 529
 				WC()->cart->empty_cart();
530 530
 
531 531
 				// Is pre ordered!
532
-				WC_Pre_Orders_Order::mark_order_as_pre_ordered( $order );
532
+				WC_Pre_Orders_Order::mark_order_as_pre_ordered($order);
533 533
 
534 534
 				// Return thank you page redirect
535 535
 				return array(
536 536
 					'result'   => 'success',
537
-					'redirect' => $this->get_return_url( $order ),
537
+					'redirect' => $this->get_return_url($order),
538 538
 				);
539
-			} catch ( Exception $e ) {
540
-				wc_add_notice( $e->getMessage(), 'error' );
539
+			} catch (Exception $e) {
540
+				wc_add_notice($e->getMessage(), 'error');
541 541
 				return;
542 542
 			}
543 543
 		} else {
544
-			return parent::process_payment( $order_id, $retry, $force_save_source );
544
+			return parent::process_payment($order_id, $retry, $force_save_source);
545 545
 		}
546 546
 	}
547 547
 
@@ -550,7 +550,7 @@  discard block
 block discarded – undo
550 550
 	 * @param WC_Order $order
551 551
 	 * @return void
552 552
 	 */
553
-	public function process_pre_order_release_payment( $order ) {
553
+	public function process_pre_order_release_payment($order) {
554 554
 		try {
555 555
 			// Define some callbacks if the first attempt fails.
556 556
 			$retry_callbacks = array(
@@ -558,33 +558,33 @@  discard block
 block discarded – undo
558 558
 				'remove_order_customer_before_retry',
559 559
 			);
560 560
 
561
-			while ( 1 ) {
562
-				$source   = $this->prepare_order_source( $order );
563
-				$response = WC_Stripe_API::request( $this->generate_payment_request( $order, $source ) );
561
+			while (1) {
562
+				$source   = $this->prepare_order_source($order);
563
+				$response = WC_Stripe_API::request($this->generate_payment_request($order, $source));
564 564
 
565
-				if ( ! empty( $response->error ) ) {
566
-					if ( 0 === sizeof( $retry_callbacks ) ) {
567
-						throw new Exception( $response->error->message );
565
+				if ( ! empty($response->error)) {
566
+					if (0 === sizeof($retry_callbacks)) {
567
+						throw new Exception($response->error->message);
568 568
 					} else {
569
-						$retry_callback = array_shift( $retry_callbacks );
570
-						call_user_func( array( $this, $retry_callback ), $order );
569
+						$retry_callback = array_shift($retry_callbacks);
570
+						call_user_func(array($this, $retry_callback), $order);
571 571
 					}
572 572
 				} else {
573 573
 					// Successful
574
-					$this->process_response( $response, $order );
574
+					$this->process_response($response, $order);
575 575
 					break;
576 576
 				}
577 577
 			}
578
-		} catch ( Exception $e ) {
578
+		} catch (Exception $e) {
579 579
 			/* translators: error message */
580
-			$order_note = sprintf( __( 'Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe' ), $e->getMessage() );
580
+			$order_note = sprintf(__('Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe'), $e->getMessage());
581 581
 
582 582
 			// Mark order as failed if not already set,
583 583
 			// otherwise, make sure we add the order note so we can detect when someone fails to check out multiple times
584
-			if ( ! $order->has_status( 'failed' ) ) {
585
-				$order->update_status( 'failed', $order_note );
584
+			if ( ! $order->has_status('failed')) {
585
+				$order->update_status('failed', $order_note);
586 586
 			} else {
587
-				$order->add_order_note( $order_note );
587
+				$order->add_order_note($order_note);
588 588
 			}
589 589
 		}
590 590
 	}
Please login to merge, or discard this patch.
includes/compat/class-wc-stripe-sepa-compat.php 1 patch
Spacing   +154 added lines, -154 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,69 +341,69 @@  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 ) {
398
-			foreach ( $sources as $source ) {
399
-				if ( $source->id === $stripe_source_id ) {
397
+		if ($sources) {
398
+			foreach ($sources as $source) {
399
+				if ($source->id === $stripe_source_id) {
400 400
 					$found_source = true;
401 401
 
402
-					if ( $source->sepa_debit ) {
402
+					if ($source->sepa_debit) {
403 403
 						/* translators: 1) last 4 digits of SEPA Direct Debit */
404
-						$payment_method_to_display = sprintf( __( 'Via SEPA Direct Debit ending in %1$s', 'woocommerce-gateway-stripe' ), $source->sepa_debit->last4 );
404
+						$payment_method_to_display = sprintf(__('Via SEPA Direct Debit ending in %1$s', 'woocommerce-gateway-stripe'), $source->sepa_debit->last4);
405 405
 					} else {
406
-						$payment_method_to_display = __( 'N/A', 'woocommerce-gateway-stripe' );
406
+						$payment_method_to_display = __('N/A', 'woocommerce-gateway-stripe');
407 407
 					}
408 408
 					break;
409 409
 				}
@@ -418,42 +418,42 @@  discard block
 block discarded – undo
418 418
 	 * @param int $order_id
419 419
 	 * @return array
420 420
 	 */
421
-	public function process_pre_order( $order_id, $retry, $force_save_source ) {
422
-		if ( WC_Pre_Orders_Order::order_requires_payment_tokenization( $order_id ) ) {
421
+	public function process_pre_order($order_id, $retry, $force_save_source) {
422
+		if (WC_Pre_Orders_Order::order_requires_payment_tokenization($order_id)) {
423 423
 			try {
424
-				$order = wc_get_order( $order_id );
424
+				$order = wc_get_order($order_id);
425 425
 
426
-				if ( $order->get_total() * 100 < WC_Stripe_Helper::get_minimum_amount() ) {
426
+				if ($order->get_total() * 100 < WC_Stripe_Helper::get_minimum_amount()) {
427 427
 					/* translators: minimum amount */
428
-					throw new Exception( sprintf( __( 'Sorry, the minimum allowed order total is %1$s to use this payment method.', 'woocommerce-gateway-stripe' ), wc_price( WC_Stripe_Helper::get_minimum_amount() / 100 ) ) );
428
+					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)));
429 429
 				}
430 430
 
431
-				$prepared_source = $this->prepare_source( get_current_user_id(), true );
431
+				$prepared_source = $this->prepare_source(get_current_user_id(), true);
432 432
 
433 433
 				// We need a source on file to continue.
434
-				if ( empty( $prepared_source->customer ) || empty( $prepared_source->source ) ) {
435
-					throw new Exception( __( 'Unable to store payment details. Please try again.', 'woocommerce-gateway-stripe' ) );
434
+				if (empty($prepared_source->customer) || empty($prepared_source->source)) {
435
+					throw new Exception(__('Unable to store payment details. Please try again.', 'woocommerce-gateway-stripe'));
436 436
 				}
437 437
 
438
-				$this->save_source_to_order( $order, $prepared_source );
438
+				$this->save_source_to_order($order, $prepared_source);
439 439
 
440 440
 				// Remove cart
441 441
 				WC()->cart->empty_cart();
442 442
 
443 443
 				// Is pre ordered!
444
-				WC_Pre_Orders_Order::mark_order_as_pre_ordered( $order );
444
+				WC_Pre_Orders_Order::mark_order_as_pre_ordered($order);
445 445
 
446 446
 				// Return thank you page redirect
447 447
 				return array(
448 448
 					'result'   => 'success',
449
-					'redirect' => $this->get_return_url( $order ),
449
+					'redirect' => $this->get_return_url($order),
450 450
 				);
451
-			} catch ( Exception $e ) {
452
-				wc_add_notice( $e->getMessage(), 'error' );
451
+			} catch (Exception $e) {
452
+				wc_add_notice($e->getMessage(), 'error');
453 453
 				return;
454 454
 			}
455 455
 		} else {
456
-			return parent::process_payment( $order_id, $retry, $force_save_source );
456
+			return parent::process_payment($order_id, $retry, $force_save_source);
457 457
 		}
458 458
 	}
459 459
 
@@ -462,7 +462,7 @@  discard block
 block discarded – undo
462 462
 	 * @param WC_Order $order
463 463
 	 * @return void
464 464
 	 */
465
-	public function process_pre_order_release_payment( $order ) {
465
+	public function process_pre_order_release_payment($order) {
466 466
 		try {
467 467
 			// Define some callbacks if the first attempt fails.
468 468
 			$retry_callbacks = array(
@@ -470,33 +470,33 @@  discard block
 block discarded – undo
470 470
 				'remove_order_customer_before_retry',
471 471
 			);
472 472
 
473
-			while ( 1 ) {
474
-				$source   = $this->prepare_order_source( $order );
475
-				$response = WC_Stripe_API::request( $this->generate_payment_request( $order, $source ) );
473
+			while (1) {
474
+				$source   = $this->prepare_order_source($order);
475
+				$response = WC_Stripe_API::request($this->generate_payment_request($order, $source));
476 476
 
477
-				if ( ! empty( $response->error ) ) {
478
-					if ( 0 === sizeof( $retry_callbacks ) ) {
479
-						throw new Exception( $response->error->message );
477
+				if ( ! empty($response->error)) {
478
+					if (0 === sizeof($retry_callbacks)) {
479
+						throw new Exception($response->error->message);
480 480
 					} else {
481
-						$retry_callback = array_shift( $retry_callbacks );
482
-						call_user_func( array( $this, $retry_callback ), $order );
481
+						$retry_callback = array_shift($retry_callbacks);
482
+						call_user_func(array($this, $retry_callback), $order);
483 483
 					}
484 484
 				} else {
485 485
 					// Successful
486
-					$this->process_response( $response, $order );
486
+					$this->process_response($response, $order);
487 487
 					break;
488 488
 				}
489 489
 			}
490
-		} catch ( Exception $e ) {
490
+		} catch (Exception $e) {
491 491
 			/* translators: error message */
492
-			$order_note = sprintf( __( 'Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe' ), $e->getMessage() );
492
+			$order_note = sprintf(__('Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe'), $e->getMessage());
493 493
 
494 494
 			// Mark order as failed if not already set,
495 495
 			// otherwise, make sure we add the order note so we can detect when someone fails to check out multiple times
496
-			if ( ! $order->has_status( 'failed' ) ) {
497
-				$order->update_status( 'failed', $order_note );
496
+			if ( ! $order->has_status('failed')) {
497
+				$order->update_status('failed', $order_note);
498 498
 			} else {
499
-				$order->add_order_note( $order_note );
499
+				$order->add_order_note($order_note);
500 500
 			}
501 501
 		}
502 502
 	}
Please login to merge, or discard this patch.