Completed
Push — master ( ee5959...d2c6b4 )
by Roy
05:49 queued 01:07
created
includes/compat/class-wc-stripe-compat.php 1 patch
Spacing   +197 added lines, -197 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
 	/**
@@ -67,7 +67,7 @@  discard block
 block discarded – undo
67 67
 	 * @return bool
68 68
 	 */
69 69
 	public function is_subs_change_payment() {
70
-		return ( isset( $_GET['pay_for_order'] ) && isset( $_GET['change_payment_method'] ) );
70
+		return (isset($_GET['pay_for_order']) && isset($_GET['change_payment_method']));
71 71
 	}
72 72
 
73 73
 	/**
@@ -75,8 +75,8 @@  discard block
 block discarded – undo
75 75
 	 * @param  int  $order_id
76 76
 	 * @return boolean
77 77
 	 */
78
-	public function is_pre_order( $order_id ) {
79
-		return ( class_exists( 'WC_Pre_Orders_Order' ) && WC_Pre_Orders_Order::order_contains_pre_order( $order_id ) );
78
+	public function is_pre_order($order_id) {
79
+		return (class_exists('WC_Pre_Orders_Order') && WC_Pre_Orders_Order::order_contains_pre_order($order_id));
80 80
 	}
81 81
 
82 82
 	/**
@@ -85,27 +85,27 @@  discard block
 block discarded – undo
85 85
 	 * @since 4.0.4
86 86
 	 * @param int $order_id
87 87
 	 */
88
-	public function change_subs_payment_method( $order_id ) {
88
+	public function change_subs_payment_method($order_id) {
89 89
 		try {
90
-			$subscription    = wc_get_order( $order_id );
90
+			$subscription    = wc_get_order($order_id);
91 91
 			$source_object   = $this->get_source_object();
92
-			$prepared_source = $this->prepare_source( $source_object, get_current_user_id(), true );
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 107
 			// Store source to order meta.
108
-			$this->save_source( $subscription, $prepared_source );
108
+			$this->save_source($subscription, $prepared_source);
109 109
 
110 110
 			/*
111 111
 			 * Check if card 3DS is required or optional with 3DS setting.
@@ -114,41 +114,41 @@  discard block
 block discarded – undo
114 114
 			 * Note that if we need to save source, the original source must be first
115 115
 			 * attached to a customer in Stripe before it can be charged.
116 116
 			 */
117
-			if ( $this->is_3ds_required( $source_object ) ) {
117
+			if ($this->is_3ds_required($source_object)) {
118 118
 				$order    = $subscription->get_parent();
119
-				$response = $this->create_3ds_source( $order, $source_object, $subscription->get_view_order_url() );
119
+				$response = $this->create_3ds_source($order, $source_object, $subscription->get_view_order_url());
120 120
 
121
-				if ( ! empty( $response->error ) ) {
121
+				if ( ! empty($response->error)) {
122 122
 					$localized_message = $response->error->message;
123 123
 
124
-					$order->add_order_note( $localized_message );
124
+					$order->add_order_note($localized_message);
125 125
 
126
-					throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message );
126
+					throw new WC_Stripe_Exception(print_r($response, true), $localized_message);
127 127
 				}
128 128
 
129 129
 				// Update order meta with 3DS source.
130
-				if ( WC_Stripe_Helper::is_pre_30() ) {
131
-					update_post_meta( $order_id, '_stripe_source_id', $response->id );
130
+				if (WC_Stripe_Helper::is_pre_30()) {
131
+					update_post_meta($order_id, '_stripe_source_id', $response->id);
132 132
 				} else {
133
-					$subscription->update_meta_data( '_stripe_source_id', $response->id );
133
+					$subscription->update_meta_data('_stripe_source_id', $response->id);
134 134
 					$subscription->save();
135 135
 				}
136 136
 
137
-				WC_Stripe_Logger::log( 'Info: Redirecting to 3DS...' );
137
+				WC_Stripe_Logger::log('Info: Redirecting to 3DS...');
138 138
 
139 139
 				return array(
140 140
 					'result'   => 'success',
141
-					'redirect' => esc_url_raw( $response->redirect->url ),
141
+					'redirect' => esc_url_raw($response->redirect->url),
142 142
 				);
143 143
 			}
144 144
 
145 145
 			return array(
146 146
 				'result'   => 'success',
147
-				'redirect' => $this->get_return_url( $subscription ),
147
+				'redirect' => $this->get_return_url($subscription),
148 148
 			);
149
-		} catch ( WC_Stripe_Exception $e ) {
150
-			wc_add_notice( $e->getLocalizedMessage(), 'error' );
151
-			WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() );
149
+		} catch (WC_Stripe_Exception $e) {
150
+			wc_add_notice($e->getLocalizedMessage(), 'error');
151
+			WC_Stripe_Logger::log('Error: ' . $e->getMessage());
152 152
 		}
153 153
 	}
154 154
 
@@ -157,18 +157,18 @@  discard block
 block discarded – undo
157 157
 	 * @param  int $order_id
158 158
 	 * @return array
159 159
 	 */
160
-	public function process_payment( $order_id, $retry = true, $force_save_source = false ) {
161
-		if ( $this->has_subscription( $order_id ) ) {
162
-			if ( $this->is_subs_change_payment() ) {
163
-				return $this->change_subs_payment_method( $order_id );
160
+	public function process_payment($order_id, $retry = true, $force_save_source = false) {
161
+		if ($this->has_subscription($order_id)) {
162
+			if ($this->is_subs_change_payment()) {
163
+				return $this->change_subs_payment_method($order_id);
164 164
 			}
165 165
 
166 166
 			// Regular payment with force customer enabled
167
-			return parent::process_payment( $order_id, true, true );
168
-		} elseif ( $this->is_pre_order( $order_id ) ) {
169
-			return $this->process_pre_order( $order_id, $retry, $force_save_source );
167
+			return parent::process_payment($order_id, true, true);
168
+		} elseif ($this->is_pre_order($order_id)) {
169
+			return $this->process_pre_order($order_id, $retry, $force_save_source);
170 170
 		} else {
171
-			return parent::process_payment( $order_id, $retry, $force_save_source );
171
+			return parent::process_payment($order_id, $retry, $force_save_source);
172 172
 		}
173 173
 	}
174 174
 
@@ -179,14 +179,14 @@  discard block
 block discarded – undo
179 179
 	 * @param array $metadata
180 180
 	 * @param object $order
181 181
 	 */
182
-	public function add_subscription_meta_data( $metadata, $order ) {
183
-		if ( ! $this->has_subscription( $order->get_id() ) ) {
182
+	public function add_subscription_meta_data($metadata, $order) {
183
+		if ( ! $this->has_subscription($order->get_id())) {
184 184
 			return $metadata;
185 185
 		}
186 186
 
187 187
 		return $metadata += array(
188 188
 			'payment_type'   => 'recurring',
189
-			'site_url'       => esc_url( get_site_url() ),
189
+			'site_url'       => esc_url(get_site_url()),
190 190
 		);
191 191
 	}
192 192
 
@@ -196,24 +196,24 @@  discard block
 block discarded – undo
196 196
 	 * @since 3.1.0
197 197
 	 * @version 4.0.0
198 198
 	 */
199
-	public function save_source( $order, $source ) {
200
-		parent::save_source( $order, $source );
199
+	public function save_source($order, $source) {
200
+		parent::save_source($order, $source);
201 201
 
202 202
 		$order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
203 203
 
204 204
 		// Also store it on the subscriptions being purchased or paid for in the order
205
-		if ( function_exists( 'wcs_order_contains_subscription' ) && wcs_order_contains_subscription( $order_id ) ) {
206
-			$subscriptions = wcs_get_subscriptions_for_order( $order_id );
207
-		} elseif ( function_exists( 'wcs_order_contains_renewal' ) && wcs_order_contains_renewal( $order_id ) ) {
208
-			$subscriptions = wcs_get_subscriptions_for_renewal_order( $order_id );
205
+		if (function_exists('wcs_order_contains_subscription') && wcs_order_contains_subscription($order_id)) {
206
+			$subscriptions = wcs_get_subscriptions_for_order($order_id);
207
+		} elseif (function_exists('wcs_order_contains_renewal') && wcs_order_contains_renewal($order_id)) {
208
+			$subscriptions = wcs_get_subscriptions_for_renewal_order($order_id);
209 209
 		} else {
210 210
 			$subscriptions = array();
211 211
 		}
212 212
 
213
-		foreach ( $subscriptions as $subscription ) {
213
+		foreach ($subscriptions as $subscription) {
214 214
 			$subscription_id = WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id();
215
-			update_post_meta( $subscription_id, '_stripe_customer_id', $source->customer );
216
-			update_post_meta( $subscription_id, '_stripe_source_id', $source->source );
215
+			update_post_meta($subscription_id, '_stripe_customer_id', $source->customer);
216
+			update_post_meta($subscription_id, '_stripe_source_id', $source->source);
217 217
 		}
218 218
 	}
219 219
 
@@ -223,35 +223,35 @@  discard block
 block discarded – undo
223 223
 	 * @param mixed $renewal_order
224 224
 	 * @param  bool initial_payment
225 225
 	 */
226
-	public function process_subscription_payment( $amount = 0.0, $renewal_order ) {
227
-		if ( $amount * 100 < WC_Stripe_Helper::get_minimum_amount() ) {
226
+	public function process_subscription_payment($amount = 0.0, $renewal_order) {
227
+		if ($amount * 100 < WC_Stripe_Helper::get_minimum_amount()) {
228 228
 			/* translators: minimum amount */
229
-			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 ) ) );
229
+			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)));
230 230
 		}
231 231
 
232 232
 		$order_id = WC_Stripe_Helper::is_pre_30() ? $renewal_order->id : $renewal_order->get_id();
233 233
 
234 234
 		// Get source from order
235
-		$prepared_source = $this->prepare_order_source( $renewal_order );
235
+		$prepared_source = $this->prepare_order_source($renewal_order);
236 236
 
237
-		if ( ! $prepared_source->customer ) {
238
-			return new WP_Error( 'stripe_error', __( 'Customer not found', 'woocommerce-gateway-stripe' ) );
237
+		if ( ! $prepared_source->customer) {
238
+			return new WP_Error('stripe_error', __('Customer not found', 'woocommerce-gateway-stripe'));
239 239
 		}
240 240
 
241
-		WC_Stripe_Logger::log( "Info: Begin processing subscription payment for order {$order_id} for the amount of {$amount}" );
241
+		WC_Stripe_Logger::log("Info: Begin processing subscription payment for order {$order_id} for the amount of {$amount}");
242 242
 
243 243
 		// Make the request
244
-		$request            = $this->generate_payment_request( $renewal_order, $prepared_source );
244
+		$request            = $this->generate_payment_request($renewal_order, $prepared_source);
245 245
 		$request['capture'] = 'true';
246
-		$request['amount']  = WC_Stripe_Helper::get_stripe_amount( $amount, $request['currency'] );
247
-		$response           = WC_Stripe_API::request( $request );
246
+		$request['amount']  = WC_Stripe_Helper::get_stripe_amount($amount, $request['currency']);
247
+		$response           = WC_Stripe_API::request($request);
248 248
 
249 249
 		// Process valid response
250
-		if ( ! empty( $response->error ) ) {
250
+		if ( ! empty($response->error)) {
251 251
 			return $response; // Default catch all errors.
252 252
 		}
253 253
 
254
-		$this->process_response( $response, $renewal_order );
254
+		$this->process_response($response, $renewal_order);
255 255
 
256 256
 		return $response;
257 257
 	}
@@ -265,59 +265,59 @@  discard block
 block discarded – undo
265 265
 	 * @param mixed $renewal_order
266 266
 	 * @param  bool initial_payment
267 267
 	 */
268
-	public function retry_subscription_payment( $amount = 0.0, $renewal_order ) {
269
-		if ( $amount * 100 < WC_Stripe_Helper::get_minimum_amount() ) {
268
+	public function retry_subscription_payment($amount = 0.0, $renewal_order) {
269
+		if ($amount * 100 < WC_Stripe_Helper::get_minimum_amount()) {
270 270
 			/* translators: minimum amount */
271
-			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 ) ) );
271
+			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)));
272 272
 		}
273 273
 
274 274
 		$order_id = WC_Stripe_Helper::is_pre_30() ? $renewal_order->id : $renewal_order->get_id();
275 275
 
276 276
 		// Get source from order
277
-		$prepared_source = $this->prepare_order_source( $renewal_order );
277
+		$prepared_source = $this->prepare_order_source($renewal_order);
278 278
 
279
-		if ( ! $prepared_source->customer ) {
280
-			return new WP_Error( 'stripe_error', __( 'Customer not found', 'woocommerce-gateway-stripe' ) );
279
+		if ( ! $prepared_source->customer) {
280
+			return new WP_Error('stripe_error', __('Customer not found', 'woocommerce-gateway-stripe'));
281 281
 		}
282 282
 
283 283
 		// Passing empty source with charge customer default.
284 284
 		$prepared_source->source = '';
285 285
 
286
-		WC_Stripe_Logger::log( "Info: Begin processing subscription payment for order {$order_id} for the amount of {$amount}" );
286
+		WC_Stripe_Logger::log("Info: Begin processing subscription payment for order {$order_id} for the amount of {$amount}");
287 287
 
288 288
 		// Make the request
289
-		$request             = $this->generate_payment_request( $renewal_order, $prepared_source );
289
+		$request             = $this->generate_payment_request($renewal_order, $prepared_source);
290 290
 		$request['capture']  = 'true';
291
-		$request['amount']   = WC_Stripe_Helper::get_stripe_amount( $amount, $request['currency'] );
292
-		$response            = WC_Stripe_API::request( $request );
291
+		$request['amount']   = WC_Stripe_Helper::get_stripe_amount($amount, $request['currency']);
292
+		$response            = WC_Stripe_API::request($request);
293 293
 
294
-		if ( ! empty( $response->error ) || is_wp_error( $response ) ) {
294
+		if ( ! empty($response->error) || is_wp_error($response)) {
295 295
 			/* translators: error message */
296
-			$renewal_order->update_status( 'failed', sprintf( __( 'Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe' ), $response->error->message ) );
296
+			$renewal_order->update_status('failed', sprintf(__('Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe'), $response->error->message));
297 297
 		}
298 298
 
299
-		$this->process_response( $response, $renewal_order );
299
+		$this->process_response($response, $renewal_order);
300 300
 	}
301 301
 
302 302
 	/**
303 303
 	 * Don't transfer Stripe customer/token meta to resubscribe orders.
304 304
 	 * @param int $resubscribe_order The order created for the customer to resubscribe to the old expired/cancelled subscription
305 305
 	 */
306
-	public function delete_resubscribe_meta( $resubscribe_order ) {
307
-		delete_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id() ), '_stripe_customer_id' );
308
-		delete_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id() ), '_stripe_source_id' );
306
+	public function delete_resubscribe_meta($resubscribe_order) {
307
+		delete_post_meta((WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id()), '_stripe_customer_id');
308
+		delete_post_meta((WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id()), '_stripe_source_id');
309 309
 		// For BW compat will remove in future
310
-		delete_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id() ), '_stripe_card_id' );
311
-		$this->delete_renewal_meta( $resubscribe_order );
310
+		delete_post_meta((WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id()), '_stripe_card_id');
311
+		$this->delete_renewal_meta($resubscribe_order);
312 312
 	}
313 313
 
314 314
 	/**
315 315
 	 * Don't transfer Stripe fee/ID meta to renewal orders.
316 316
 	 * @param int $resubscribe_order The order created for the customer to resubscribe to the old expired/cancelled subscription
317 317
 	 */
318
-	public function delete_renewal_meta( $renewal_order ) {
319
-		delete_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $renewal_order->id : $renewal_order->get_id() ), 'Stripe Fee' );
320
-		delete_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $renewal_order->id : $renewal_order->get_id() ), 'Net Revenue From Stripe' );
318
+	public function delete_renewal_meta($renewal_order) {
319
+		delete_post_meta((WC_Stripe_Helper::is_pre_30() ? $renewal_order->id : $renewal_order->get_id()), 'Stripe Fee');
320
+		delete_post_meta((WC_Stripe_Helper::is_pre_30() ? $renewal_order->id : $renewal_order->get_id()), 'Net Revenue From Stripe');
321 321
 		return $renewal_order;
322 322
 	}
323 323
 
@@ -327,21 +327,21 @@  discard block
 block discarded – undo
327 327
 	 * @param $amount_to_charge float The amount to charge.
328 328
 	 * @param $renewal_order WC_Order A WC_Order object created to record the renewal payment.
329 329
 	 */
330
-	public function scheduled_subscription_payment( $amount_to_charge, $renewal_order ) {
331
-		$response = $this->process_subscription_payment( $amount_to_charge, $renewal_order );
330
+	public function scheduled_subscription_payment($amount_to_charge, $renewal_order) {
331
+		$response = $this->process_subscription_payment($amount_to_charge, $renewal_order);
332 332
 
333
-		if ( is_wp_error( $response ) ) {
333
+		if (is_wp_error($response)) {
334 334
 			/* translators: error message */
335
-			$renewal_order->update_status( 'failed', sprintf( __( 'Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe' ), $response->get_error_message() ) );
335
+			$renewal_order->update_status('failed', sprintf(__('Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe'), $response->get_error_message()));
336 336
 		}
337 337
 
338
-		if ( ! empty( $response->error ) ) {
338
+		if ( ! empty($response->error)) {
339 339
 			// This is a very generic error to listen for but worth a retry before total fail.
340
-			if ( isset( $response->error->type ) && 'invalid_request_error' === $response->error->type && apply_filters( 'wc_stripe_use_default_customer_source', true ) ) {
341
-				$this->retry_subscription_payment( $amount_to_charge, $renewal_order );
340
+			if (isset($response->error->type) && 'invalid_request_error' === $response->error->type && apply_filters('wc_stripe_use_default_customer_source', true)) {
341
+				$this->retry_subscription_payment($amount_to_charge, $renewal_order);
342 342
 			} else {
343 343
 				/* translators: error message */
344
-				$renewal_order->update_status( 'failed', sprintf( __( 'Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe' ), $response->error->message ) );
344
+				$renewal_order->update_status('failed', sprintf(__('Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe'), $response->error->message));
345 345
 			}
346 346
 		}
347 347
 	}
@@ -350,20 +350,20 @@  discard block
 block discarded – undo
350 350
 	 * Remove order meta
351 351
 	 * @param object $order
352 352
 	 */
353
-	public function remove_order_source_before_retry( $order ) {
353
+	public function remove_order_source_before_retry($order) {
354 354
 		$order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
355
-		delete_post_meta( $order_id, '_stripe_source_id' );
355
+		delete_post_meta($order_id, '_stripe_source_id');
356 356
 		// For BW compat will remove in the future.
357
-		delete_post_meta( $order_id, '_stripe_card_id' );
357
+		delete_post_meta($order_id, '_stripe_card_id');
358 358
 	}
359 359
 
360 360
 	/**
361 361
 	 * Remove order meta
362 362
 	 * @param  object $order
363 363
 	 */
364
-	public function remove_order_customer_before_retry( $order ) {
364
+	public function remove_order_customer_before_retry($order) {
365 365
 		$order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
366
-		delete_post_meta( $order_id, '_stripe_customer_id' );
366
+		delete_post_meta($order_id, '_stripe_customer_id');
367 367
 	}
368 368
 
369 369
 	/**
@@ -375,14 +375,14 @@  discard block
 block discarded – undo
375 375
 	 * @param WC_Order $renewal_order The order which recorded the successful payment (to make up for the failed automatic payment).
376 376
 	 * @return void
377 377
 	 */
378
-	public function update_failing_payment_method( $subscription, $renewal_order ) {
379
-		if ( WC_Stripe_Helper::is_pre_30() ) {
380
-			update_post_meta( $subscription->id, '_stripe_customer_id', $renewal_order->stripe_customer_id );
381
-			update_post_meta( $subscription->id, '_stripe_source_id', $renewal_order->stripe_source_id );
378
+	public function update_failing_payment_method($subscription, $renewal_order) {
379
+		if (WC_Stripe_Helper::is_pre_30()) {
380
+			update_post_meta($subscription->id, '_stripe_customer_id', $renewal_order->stripe_customer_id);
381
+			update_post_meta($subscription->id, '_stripe_source_id', $renewal_order->stripe_source_id);
382 382
 
383 383
 		} else {
384
-			update_post_meta( $subscription->get_id(), '_stripe_customer_id', $renewal_order->get_meta( '_stripe_customer_id', true ) );
385
-			update_post_meta( $subscription->get_id(), '_stripe_source_id', $renewal_order->get_meta( '_stripe_source_id', true ) );
384
+			update_post_meta($subscription->get_id(), '_stripe_customer_id', $renewal_order->get_meta('_stripe_customer_id', true));
385
+			update_post_meta($subscription->get_id(), '_stripe_source_id', $renewal_order->get_meta('_stripe_source_id', true));
386 386
 		}
387 387
 	}
388 388
 
@@ -395,21 +395,21 @@  discard block
 block discarded – undo
395 395
 	 * @param WC_Subscription $subscription An instance of a subscription object
396 396
 	 * @return array
397 397
 	 */
398
-	public function add_subscription_payment_meta( $payment_meta, $subscription ) {
399
-		$source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_source_id', true );
398
+	public function add_subscription_payment_meta($payment_meta, $subscription) {
399
+		$source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_source_id', true);
400 400
 
401 401
 		// For BW compat will remove in future.
402
-		if ( empty( $source_id ) ) {
403
-			$source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_card_id', true );
402
+		if (empty($source_id)) {
403
+			$source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_card_id', true);
404 404
 
405 405
 			// Take this opportunity to update the key name.
406
-			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 );
406
+			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);
407 407
 		}
408 408
 
409
-		$payment_meta[ $this->id ] = array(
409
+		$payment_meta[$this->id] = array(
410 410
 			'post_meta' => array(
411 411
 				'_stripe_customer_id' => array(
412
-					'value' => get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_customer_id', true ),
412
+					'value' => get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_customer_id', true),
413 413
 					'label' => 'Stripe Customer ID',
414 414
 				),
415 415
 				'_stripe_source_id' => array(
@@ -432,22 +432,22 @@  discard block
 block discarded – undo
432 432
 	 * @param array $payment_meta associative array of meta data required for automatic payments
433 433
 	 * @return array
434 434
 	 */
435
-	public function validate_subscription_payment_meta( $payment_method_id, $payment_meta ) {
436
-		if ( $this->id === $payment_method_id ) {
435
+	public function validate_subscription_payment_meta($payment_method_id, $payment_meta) {
436
+		if ($this->id === $payment_method_id) {
437 437
 
438
-			if ( ! isset( $payment_meta['post_meta']['_stripe_customer_id']['value'] ) || empty( $payment_meta['post_meta']['_stripe_customer_id']['value'] ) ) {
439
-				throw new Exception( __( 'A "Stripe Customer ID" value is required.', 'woocommerce-gateway-stripe' ) );
440
-			} elseif ( 0 !== strpos( $payment_meta['post_meta']['_stripe_customer_id']['value'], 'cus_' ) ) {
441
-				throw new Exception( __( 'Invalid customer ID. A valid "Stripe Customer ID" must begin with "cus_".', 'woocommerce-gateway-stripe' ) );
438
+			if ( ! isset($payment_meta['post_meta']['_stripe_customer_id']['value']) || empty($payment_meta['post_meta']['_stripe_customer_id']['value'])) {
439
+				throw new Exception(__('A "Stripe Customer ID" value is required.', 'woocommerce-gateway-stripe'));
440
+			} elseif (0 !== strpos($payment_meta['post_meta']['_stripe_customer_id']['value'], 'cus_')) {
441
+				throw new Exception(__('Invalid customer ID. A valid "Stripe Customer ID" must begin with "cus_".', 'woocommerce-gateway-stripe'));
442 442
 			}
443 443
 
444 444
 			if (
445
-				( ! empty( $payment_meta['post_meta']['_stripe_source_id']['value'] )
446
-				&& 0 !== strpos( $payment_meta['post_meta']['_stripe_source_id']['value'], 'card_' ) )
447
-				&& ( ! empty( $payment_meta['post_meta']['_stripe_source_id']['value'] )
448
-				&& 0 !== strpos( $payment_meta['post_meta']['_stripe_source_id']['value'], 'src_' ) ) ) {
445
+				( ! empty($payment_meta['post_meta']['_stripe_source_id']['value'])
446
+				&& 0 !== strpos($payment_meta['post_meta']['_stripe_source_id']['value'], 'card_'))
447
+				&& ( ! empty($payment_meta['post_meta']['_stripe_source_id']['value'])
448
+				&& 0 !== strpos($payment_meta['post_meta']['_stripe_source_id']['value'], 'src_')) ) {
449 449
 
450
-				throw new Exception( __( 'Invalid source ID. A valid source "Stripe Source ID" must begin with "src_" or "card_".', 'woocommerce-gateway-stripe' ) );
450
+				throw new Exception(__('Invalid source ID. A valid source "Stripe Source ID" must begin with "src_" or "card_".', 'woocommerce-gateway-stripe'));
451 451
 			}
452 452
 		}
453 453
 	}
@@ -460,91 +460,91 @@  discard block
 block discarded – undo
460 460
 	 * @param WC_Subscription $subscription the subscription details
461 461
 	 * @return string the subscription payment method
462 462
 	 */
463
-	public function maybe_render_subscription_payment_method( $payment_method_to_display, $subscription ) {
463
+	public function maybe_render_subscription_payment_method($payment_method_to_display, $subscription) {
464 464
 		$customer_user = WC_Stripe_Helper::is_pre_30() ? $subscription->customer_user : $subscription->get_customer_id();
465 465
 
466 466
 		// bail for other payment methods
467
-		if ( ( WC_Stripe_Helper::is_pre_30() ? $subscription->payment_method : $subscription->get_payment_method() ) !== $this->id || ! $customer_user ) {
467
+		if ((WC_Stripe_Helper::is_pre_30() ? $subscription->payment_method : $subscription->get_payment_method()) !== $this->id || ! $customer_user) {
468 468
 			return $payment_method_to_display;
469 469
 		}
470 470
 
471
-		$stripe_source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_source_id', true );
471
+		$stripe_source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_source_id', true);
472 472
 
473 473
 		// For BW compat will remove in future.
474
-		if ( empty( $stripe_source_id ) ) {
475
-			$stripe_source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_card_id', true );
474
+		if (empty($stripe_source_id)) {
475
+			$stripe_source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_card_id', true);
476 476
 
477 477
 			// Take this opportunity to update the key name.
478
-			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 );
478
+			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);
479 479
 		}
480 480
 
481 481
 		$stripe_customer    = new WC_Stripe_Customer();
482
-		$stripe_customer_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_customer_id', true );
482
+		$stripe_customer_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_customer_id', true);
483 483
 
484 484
 		// If we couldn't find a Stripe customer linked to the subscription, fallback to the user meta data.
485
-		if ( ! $stripe_customer_id || ! is_string( $stripe_customer_id ) ) {
485
+		if ( ! $stripe_customer_id || ! is_string($stripe_customer_id)) {
486 486
 			$user_id            = $customer_user;
487
-			$stripe_customer_id = get_user_meta( $user_id, '_stripe_customer_id', true );
488
-			$stripe_source_id   = get_user_meta( $user_id, '_stripe_source_id', true );
487
+			$stripe_customer_id = get_user_meta($user_id, '_stripe_customer_id', true);
488
+			$stripe_source_id   = get_user_meta($user_id, '_stripe_source_id', true);
489 489
 
490 490
 			// For BW compat will remove in future.
491
-			if ( empty( $stripe_source_id ) ) {
492
-				$stripe_source_id = get_user_meta( $user_id, '_stripe_card_id', true );
491
+			if (empty($stripe_source_id)) {
492
+				$stripe_source_id = get_user_meta($user_id, '_stripe_card_id', true);
493 493
 
494 494
 				// Take this opportunity to update the key name.
495
-				update_user_meta( $user_id, '_stripe_source_id', $stripe_source_id );
495
+				update_user_meta($user_id, '_stripe_source_id', $stripe_source_id);
496 496
 			}
497 497
 		}
498 498
 
499 499
 		// If we couldn't find a Stripe customer linked to the account, fallback to the order meta data.
500
-		if ( ( ! $stripe_customer_id || ! is_string( $stripe_customer_id ) ) && false !== $subscription->order ) {
501
-			$stripe_customer_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id() ), '_stripe_customer_id', true );
502
-			$stripe_source_id   = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id() ), '_stripe_source_id', true );
500
+		if (( ! $stripe_customer_id || ! is_string($stripe_customer_id)) && false !== $subscription->order) {
501
+			$stripe_customer_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id()), '_stripe_customer_id', true);
502
+			$stripe_source_id   = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id()), '_stripe_source_id', true);
503 503
 
504 504
 			// For BW compat will remove in future.
505
-			if ( empty( $stripe_source_id ) ) {
506
-				$stripe_source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id() ), '_stripe_card_id', true );
505
+			if (empty($stripe_source_id)) {
506
+				$stripe_source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id()), '_stripe_card_id', true);
507 507
 
508 508
 				// Take this opportunity to update the key name.
509
-				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 );
509
+				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);
510 510
 			}
511 511
 		}
512 512
 
513
-		$stripe_customer->set_id( $stripe_customer_id );
513
+		$stripe_customer->set_id($stripe_customer_id);
514 514
 		$sources = $stripe_customer->get_sources();
515 515
 
516
-		if ( $sources ) {
516
+		if ($sources) {
517 517
 			$found_source = false;
518
-			foreach ( $sources as $source ) {
519
-				if ( isset( $source->type ) && 'card' === $source->type ) {
518
+			foreach ($sources as $source) {
519
+				if (isset($source->type) && 'card' === $source->type) {
520 520
 					$card = $source->card;
521
-				} elseif ( isset( $source->object ) && 'card' === $source->object ) {
521
+				} elseif (isset($source->object) && 'card' === $source->object) {
522 522
 					$card = $source;
523 523
 				}
524 524
 
525
-				if ( $source->id === $stripe_source_id ) {
525
+				if ($source->id === $stripe_source_id) {
526 526
 					$found_source = true;
527 527
 
528
-					if ( $card ) {
528
+					if ($card) {
529 529
 						/* translators: 1) card brand 2) last 4 digits */
530
-						$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 );
530
+						$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);
531 531
 					} else {
532
-						$payment_method_to_display = __( 'N/A', 'woocommerce-gateway-stripe' );
532
+						$payment_method_to_display = __('N/A', 'woocommerce-gateway-stripe');
533 533
 					}
534 534
 					break;
535 535
 				}
536 536
 			}
537 537
 
538
-			if ( ! $found_source ) {
539
-				if ( 'card' === $sources[0]->type ) {
538
+			if ( ! $found_source) {
539
+				if ('card' === $sources[0]->type) {
540 540
 					$card = $sources[0]->card;
541 541
 				}
542 542
 
543
-				if ( $card ) {
543
+				if ($card) {
544 544
 					/* translators: 1) card brand 2) last 4 digits */
545
-					$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 );
545
+					$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);
546 546
 				} else {
547
-					$payment_method_to_display = __( 'N/A', 'woocommerce-gateway-stripe' );
547
+					$payment_method_to_display = __('N/A', 'woocommerce-gateway-stripe');
548 548
 				}
549 549
 			}
550 550
 		}
@@ -557,43 +557,43 @@  discard block
 block discarded – undo
557 557
 	 * @param int $order_id
558 558
 	 * @return array
559 559
 	 */
560
-	public function process_pre_order( $order_id, $retry, $force_save_source ) {
561
-		if ( WC_Pre_Orders_Order::order_requires_payment_tokenization( $order_id ) ) {
560
+	public function process_pre_order($order_id, $retry, $force_save_source) {
561
+		if (WC_Pre_Orders_Order::order_requires_payment_tokenization($order_id)) {
562 562
 			try {
563
-				$order = wc_get_order( $order_id );
563
+				$order = wc_get_order($order_id);
564 564
 
565
-				if ( $order->get_total() * 100 < WC_Stripe_Helper::get_minimum_amount() ) {
565
+				if ($order->get_total() * 100 < WC_Stripe_Helper::get_minimum_amount()) {
566 566
 					/* translators: minimum amount */
567
-					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 ) ) );
567
+					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)));
568 568
 				}
569 569
 
570
-				$source = $this->prepare_source( $this->get_source_object(), get_current_user_id(), true );
570
+				$source = $this->prepare_source($this->get_source_object(), get_current_user_id(), true);
571 571
 
572 572
 				// We need a source on file to continue.
573
-				if ( empty( $source->customer ) || empty( $source->source ) ) {
574
-					throw new Exception( __( 'Unable to store payment details. Please try again.', 'woocommerce-gateway-stripe' ) );
573
+				if (empty($source->customer) || empty($source->source)) {
574
+					throw new Exception(__('Unable to store payment details. Please try again.', 'woocommerce-gateway-stripe'));
575 575
 				}
576 576
 
577 577
 				// Store source to order meta
578
-				$this->save_source( $order, $source );
578
+				$this->save_source($order, $source);
579 579
 
580 580
 				// Remove cart
581 581
 				WC()->cart->empty_cart();
582 582
 
583 583
 				// Is pre ordered!
584
-				WC_Pre_Orders_Order::mark_order_as_pre_ordered( $order );
584
+				WC_Pre_Orders_Order::mark_order_as_pre_ordered($order);
585 585
 
586 586
 				// Return thank you page redirect
587 587
 				return array(
588 588
 					'result'   => 'success',
589
-					'redirect' => $this->get_return_url( $order ),
589
+					'redirect' => $this->get_return_url($order),
590 590
 				);
591
-			} catch ( Exception $e ) {
592
-				wc_add_notice( $e->getMessage(), 'error' );
591
+			} catch (Exception $e) {
592
+				wc_add_notice($e->getMessage(), 'error');
593 593
 				return;
594 594
 			}
595 595
 		} else {
596
-			return parent::process_payment( $order_id, $retry, $force_save_source );
596
+			return parent::process_payment($order_id, $retry, $force_save_source);
597 597
 		}
598 598
 	}
599 599
 
@@ -602,7 +602,7 @@  discard block
 block discarded – undo
602 602
 	 * @param WC_Order $order
603 603
 	 * @return void
604 604
 	 */
605
-	public function process_pre_order_release_payment( $order ) {
605
+	public function process_pre_order_release_payment($order) {
606 606
 		try {
607 607
 			// Define some callbacks if the first attempt fails.
608 608
 			$retry_callbacks = array(
@@ -610,33 +610,33 @@  discard block
 block discarded – undo
610 610
 				'remove_order_customer_before_retry',
611 611
 			);
612 612
 
613
-			while ( 1 ) {
614
-				$source   = $this->prepare_order_source( $order );
615
-				$response = WC_Stripe_API::request( $this->generate_payment_request( $order, $source ) );
613
+			while (1) {
614
+				$source   = $this->prepare_order_source($order);
615
+				$response = WC_Stripe_API::request($this->generate_payment_request($order, $source));
616 616
 
617
-				if ( ! empty( $response->error ) ) {
618
-					if ( 0 === sizeof( $retry_callbacks ) ) {
619
-						throw new Exception( $response->error->message );
617
+				if ( ! empty($response->error)) {
618
+					if (0 === sizeof($retry_callbacks)) {
619
+						throw new Exception($response->error->message);
620 620
 					} else {
621
-						$retry_callback = array_shift( $retry_callbacks );
622
-						call_user_func( array( $this, $retry_callback ), $order );
621
+						$retry_callback = array_shift($retry_callbacks);
622
+						call_user_func(array($this, $retry_callback), $order);
623 623
 					}
624 624
 				} else {
625 625
 					// Successful
626
-					$this->process_response( $response, $order );
626
+					$this->process_response($response, $order);
627 627
 					break;
628 628
 				}
629 629
 			}
630
-		} catch ( Exception $e ) {
630
+		} catch (Exception $e) {
631 631
 			/* translators: error message */
632
-			$order_note = sprintf( __( 'Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe' ), $e->getMessage() );
632
+			$order_note = sprintf(__('Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe'), $e->getMessage());
633 633
 
634 634
 			// Mark order as failed if not already set,
635 635
 			// otherwise, make sure we add the order note so we can detect when someone fails to check out multiple times
636
-			if ( ! $order->has_status( 'failed' ) ) {
637
-				$order->update_status( 'failed', $order_note );
636
+			if ( ! $order->has_status('failed')) {
637
+				$order->update_status('failed', $order_note);
638 638
 			} else {
639
-				$order->add_order_note( $order_note );
639
+				$order->add_order_note($order_note);
640 640
 			}
641 641
 		}
642 642
 	}
Please login to merge, or discard this patch.
includes/compat/class-wc-stripe-sepa-compat.php 1 patch
Spacing   +166 added lines, -166 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) {
2
+if ( ! defined('ABSPATH')) {
3 3
 	exit;
4 4
 }
5 5
 
@@ -15,24 +15,24 @@  discard block
 block discarded – undo
15 15
 	public function __construct() {
16 16
 		parent::__construct();
17 17
 
18
-		if ( class_exists( 'WC_Subscriptions_Order' ) ) {
19
-			add_action( 'woocommerce_scheduled_subscription_payment_' . $this->id, array( $this, 'scheduled_subscription_payment' ), 10, 2 );
20
-			add_action( 'wcs_resubscribe_order_created', array( $this, 'delete_resubscribe_meta' ), 10 );
21
-			add_action( 'wcs_renewal_order_created', array( $this, 'delete_renewal_meta' ), 10 );
22
-			add_action( 'woocommerce_subscription_failing_payment_method_updated_stripe', array( $this, 'update_failing_payment_method' ), 10, 2 );
18
+		if (class_exists('WC_Subscriptions_Order')) {
19
+			add_action('woocommerce_scheduled_subscription_payment_' . $this->id, array($this, 'scheduled_subscription_payment'), 10, 2);
20
+			add_action('wcs_resubscribe_order_created', array($this, 'delete_resubscribe_meta'), 10);
21
+			add_action('wcs_renewal_order_created', array($this, 'delete_renewal_meta'), 10);
22
+			add_action('woocommerce_subscription_failing_payment_method_updated_stripe', array($this, 'update_failing_payment_method'), 10, 2);
23 23
 
24 24
 			// display the credit card used for a subscription in the "My Subscriptions" table
25
-			add_filter( 'woocommerce_my_subscriptions_payment_method', array( $this, 'maybe_render_subscription_payment_method' ), 10, 2 );
25
+			add_filter('woocommerce_my_subscriptions_payment_method', array($this, 'maybe_render_subscription_payment_method'), 10, 2);
26 26
 
27 27
 			// allow store managers to manually set Stripe as the payment method on a subscription
28
-			add_filter( 'woocommerce_subscription_payment_meta', array( $this, 'add_subscription_payment_meta' ), 10, 2 );
29
-			add_filter( 'woocommerce_subscription_validate_payment_meta', array( $this, 'validate_subscription_payment_meta' ), 10, 2 );
30
-			add_filter( 'wc_stripe_display_save_payment_method_checkbox', array( $this, 'maybe_hide_save_checkbox' ) );
31
-			add_filter( 'wc_stripe_payment_metadata', array( $this, 'add_subscription_meta_data' ), 10, 2 );
28
+			add_filter('woocommerce_subscription_payment_meta', array($this, 'add_subscription_payment_meta'), 10, 2);
29
+			add_filter('woocommerce_subscription_validate_payment_meta', array($this, 'validate_subscription_payment_meta'), 10, 2);
30
+			add_filter('wc_stripe_display_save_payment_method_checkbox', array($this, 'maybe_hide_save_checkbox'));
31
+			add_filter('wc_stripe_payment_metadata', array($this, 'add_subscription_meta_data'), 10, 2);
32 32
 		}
33 33
 
34
-		if ( class_exists( 'WC_Pre_Orders_Order' ) ) {
35
-			add_action( 'wc_pre_orders_process_pre_order_completion_payment_' . $this->id, array( $this, 'process_pre_order_release_payment' ) );
34
+		if (class_exists('WC_Pre_Orders_Order')) {
35
+			add_action('wc_pre_orders_process_pre_order_completion_payment_' . $this->id, array($this, 'process_pre_order_release_payment'));
36 36
 		}
37 37
 	}
38 38
 
@@ -43,8 +43,8 @@  discard block
 block discarded – undo
43 43
 	 * @since 4.0.0
44 44
 	 * @version 4.0.0
45 45
 	 */
46
-	public function maybe_hide_save_checkbox( $display_tokenization ) {
47
-		if ( WC_Subscriptions_Cart::cart_contains_subscription() ) {
46
+	public function maybe_hide_save_checkbox($display_tokenization) {
47
+		if (WC_Subscriptions_Cart::cart_contains_subscription()) {
48 48
 			return false;
49 49
 		}
50 50
 
@@ -56,8 +56,8 @@  discard block
 block discarded – undo
56 56
 	 * @param  int  $order_id
57 57
 	 * @return boolean
58 58
 	 */
59
-	public function has_subscription( $order_id ) {
60
-		return ( function_exists( 'wcs_order_contains_subscription' ) && ( wcs_order_contains_subscription( $order_id ) || wcs_is_subscription( $order_id ) || wcs_order_contains_renewal( $order_id ) ) );
59
+	public function has_subscription($order_id) {
60
+		return (function_exists('wcs_order_contains_subscription') && (wcs_order_contains_subscription($order_id) || wcs_is_subscription($order_id) || wcs_order_contains_renewal($order_id)));
61 61
 	}
62 62
 
63 63
 	/**
@@ -65,8 +65,8 @@  discard block
 block discarded – undo
65 65
 	 * @param  int  $order_id
66 66
 	 * @return boolean
67 67
 	 */
68
-	protected function is_pre_order( $order_id ) {
69
-		return ( class_exists( 'WC_Pre_Orders_Order' ) && WC_Pre_Orders_Order::order_contains_pre_order( $order_id ) );
68
+	protected function is_pre_order($order_id) {
69
+		return (class_exists('WC_Pre_Orders_Order') && WC_Pre_Orders_Order::order_contains_pre_order($order_id));
70 70
 	}
71 71
 
72 72
 	/**
@@ -74,14 +74,14 @@  discard block
 block discarded – undo
74 74
 	 * @param  int $order_id
75 75
 	 * @return array
76 76
 	 */
77
-	public function process_payment( $order_id, $retry = true, $force_save_source = false ) {
78
-		if ( $this->has_subscription( $order_id ) ) {
77
+	public function process_payment($order_id, $retry = true, $force_save_source = false) {
78
+		if ($this->has_subscription($order_id)) {
79 79
 			// Regular payment with force customer enabled
80
-			return parent::process_payment( $order_id, true, true );
81
-		} elseif ( $this->is_pre_order( $order_id ) ) {
82
-			return $this->process_pre_order( $order_id, $retry, $force_save_source );
80
+			return parent::process_payment($order_id, true, true);
81
+		} elseif ($this->is_pre_order($order_id)) {
82
+			return $this->process_pre_order($order_id, $retry, $force_save_source);
83 83
 		} else {
84
-			return parent::process_payment( $order_id, $retry, $force_save_source );
84
+			return parent::process_payment($order_id, $retry, $force_save_source);
85 85
 		}
86 86
 	}
87 87
 
@@ -92,14 +92,14 @@  discard block
 block discarded – undo
92 92
 	 * @param array $metadata
93 93
 	 * @param object $order
94 94
 	 */
95
-	public function add_subscription_meta_data( $metadata, $order ) {
96
-		if ( ! $this->has_subscription( $order->get_id() ) ) {
95
+	public function add_subscription_meta_data($metadata, $order) {
96
+		if ( ! $this->has_subscription($order->get_id())) {
97 97
 			return $metadata;
98 98
 		}
99 99
 
100 100
 		return $metadata += array(
101 101
 			'payment_type'   => 'recurring',
102
-			'site_url'       => esc_url( get_site_url() ),
102
+			'site_url'       => esc_url(get_site_url()),
103 103
 		);
104 104
 	}
105 105
 
@@ -109,24 +109,24 @@  discard block
 block discarded – undo
109 109
 	 * @since 3.1.0
110 110
 	 * @version 4.0.0
111 111
 	 */
112
-	public function save_source( $order, $source ) {
113
-		parent::save_source( $order, $source );
112
+	public function save_source($order, $source) {
113
+		parent::save_source($order, $source);
114 114
 
115
-		$order_id  = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
115
+		$order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
116 116
 
117 117
 		// Also store it on the subscriptions being purchased or paid for in the order
118
-		if ( function_exists( 'wcs_order_contains_subscription' ) && wcs_order_contains_subscription( $order_id ) ) {
119
-			$subscriptions = wcs_get_subscriptions_for_order( $order_id );
120
-		} elseif ( function_exists( 'wcs_order_contains_renewal' ) && wcs_order_contains_renewal( $order_id ) ) {
121
-			$subscriptions = wcs_get_subscriptions_for_renewal_order( $order_id );
118
+		if (function_exists('wcs_order_contains_subscription') && wcs_order_contains_subscription($order_id)) {
119
+			$subscriptions = wcs_get_subscriptions_for_order($order_id);
120
+		} elseif (function_exists('wcs_order_contains_renewal') && wcs_order_contains_renewal($order_id)) {
121
+			$subscriptions = wcs_get_subscriptions_for_renewal_order($order_id);
122 122
 		} else {
123 123
 			$subscriptions = array();
124 124
 		}
125 125
 
126
-		foreach ( $subscriptions as $subscription ) {
126
+		foreach ($subscriptions as $subscription) {
127 127
 			$subscription_id = WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id();
128
-			update_post_meta( $subscription_id, '_stripe_customer_id', $source->customer );
129
-			update_post_meta( $subscription_id, '_stripe_source_id', $source->source );
128
+			update_post_meta($subscription_id, '_stripe_customer_id', $source->customer);
129
+			update_post_meta($subscription_id, '_stripe_source_id', $source->source);
130 130
 		}
131 131
 	}
132 132
 
@@ -136,35 +136,35 @@  discard block
 block discarded – undo
136 136
 	 * @param mixed $renewal_order
137 137
 	 * @param  bool initial_payment
138 138
 	 */
139
-	public function process_subscription_payment( $amount = 0.0, $renewal_order ) {
140
-		if ( $amount * 100 < WC_Stripe_Helper::get_minimum_amount() ) {
139
+	public function process_subscription_payment($amount = 0.0, $renewal_order) {
140
+		if ($amount * 100 < WC_Stripe_Helper::get_minimum_amount()) {
141 141
 			/* translators: minimum amount */
142
-			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 ) ) );
142
+			return new WP_Error('stripe_error', sprintf(__('Sorry, the minimum allowed order total is %1$s to use this payment method.', 'woocommerce-gateway-stripe'), wc_price(WC_Stripe_Helper::get_minimum_amount() / 100)));
143 143
 		}
144 144
 
145 145
 		$order_id = WC_Stripe_Helper::is_pre_30() ? $renewal_order->id : $renewal_order->get_id();
146 146
 
147 147
 		// Get source from order
148
-		$prepared_source = $this->prepare_order_source( $renewal_order );
148
+		$prepared_source = $this->prepare_order_source($renewal_order);
149 149
 
150
-		if ( ! $prepared_source->customer ) {
151
-			return new WP_Error( 'stripe_error', __( 'Customer not found', 'woocommerce-gateway-stripe' ) );
150
+		if ( ! $prepared_source->customer) {
151
+			return new WP_Error('stripe_error', __('Customer not found', 'woocommerce-gateway-stripe'));
152 152
 		}
153 153
 
154
-		WC_Stripe_Logger::log( "Info: Begin processing subscription payment for order {$order_id} for the amount of {$amount}" );
154
+		WC_Stripe_Logger::log("Info: Begin processing subscription payment for order {$order_id} for the amount of {$amount}");
155 155
 
156 156
 		// Make the request
157
-		$request             = $this->generate_payment_request( $renewal_order, $prepared_source );
157
+		$request             = $this->generate_payment_request($renewal_order, $prepared_source);
158 158
 		$request['capture']  = 'true';
159
-		$request['amount']   = WC_Stripe_Helper::get_stripe_amount( $amount, $request['currency'] );
160
-		$response            = WC_Stripe_API::request( $request );
159
+		$request['amount']   = WC_Stripe_Helper::get_stripe_amount($amount, $request['currency']);
160
+		$response            = WC_Stripe_API::request($request);
161 161
 
162 162
 		// Process valid response
163
-		if ( ! empty( $response->error ) ) {
163
+		if ( ! empty($response->error)) {
164 164
 			return $response; // Default catch all errors.
165 165
 		}
166 166
 
167
-		$this->process_response( $response, $renewal_order );
167
+		$this->process_response($response, $renewal_order);
168 168
 
169 169
 		return $response;
170 170
 	}
@@ -178,59 +178,59 @@  discard block
 block discarded – undo
178 178
 	 * @param mixed $renewal_order
179 179
 	 * @param bool initial_payment
180 180
 	 */
181
-	public function retry_subscription_payment( $amount = 0.0, $renewal_order ) {
182
-		if ( $amount * 100 < WC_Stripe_Helper::get_minimum_amount() ) {
181
+	public function retry_subscription_payment($amount = 0.0, $renewal_order) {
182
+		if ($amount * 100 < WC_Stripe_Helper::get_minimum_amount()) {
183 183
 			/* translators: minimum amount */
184
-			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 ) ) );
184
+			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)));
185 185
 		}
186 186
 
187 187
 		$order_id = WC_Stripe_Helper::is_pre_30() ? $renewal_order->id : $renewal_order->get_id();
188 188
 
189 189
 		// Get source from order
190
-		$prepared_source = $this->prepare_order_source( $renewal_order );
190
+		$prepared_source = $this->prepare_order_source($renewal_order);
191 191
 
192
-		if ( ! $prepared_source->customer ) {
193
-			return new WP_Error( 'stripe_error', __( 'Customer not found', 'woocommerce-gateway-stripe' ) );
192
+		if ( ! $prepared_source->customer) {
193
+			return new WP_Error('stripe_error', __('Customer not found', 'woocommerce-gateway-stripe'));
194 194
 		}
195 195
 
196 196
 		// Passing empty source with charge customer default.
197 197
 		$prepared_source->source = '';
198 198
 
199
-		WC_Stripe_Logger::log( "Info: Begin processing subscription payment for order {$order_id} for the amount of {$amount}" );
199
+		WC_Stripe_Logger::log("Info: Begin processing subscription payment for order {$order_id} for the amount of {$amount}");
200 200
 
201 201
 		// Make the request
202
-		$request             = $this->generate_payment_request( $renewal_order, $prepared_source );
202
+		$request             = $this->generate_payment_request($renewal_order, $prepared_source);
203 203
 		$request['capture']  = 'true';
204
-		$request['amount']   = WC_Stripe_Helper::get_stripe_amount( $amount, $request['currency'] );
205
-		$response            = WC_Stripe_API::request( $request );
204
+		$request['amount']   = WC_Stripe_Helper::get_stripe_amount($amount, $request['currency']);
205
+		$response            = WC_Stripe_API::request($request);
206 206
 
207
-		if ( ! empty( $response->error ) || is_wp_error( $response ) ) {
207
+		if ( ! empty($response->error) || is_wp_error($response)) {
208 208
 			/* translators: error message */
209
-			$renewal_order->update_status( 'failed', sprintf( __( 'Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe' ), $response->error->message ) );
209
+			$renewal_order->update_status('failed', sprintf(__('Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe'), $response->error->message));
210 210
 		}
211 211
 
212
-		$this->process_response( $response, $renewal_order );
212
+		$this->process_response($response, $renewal_order);
213 213
 	}
214 214
 
215 215
 	/**
216 216
 	 * Don't transfer Stripe customer/token meta to resubscribe orders.
217 217
 	 * @param int $resubscribe_order The order created for the customer to resubscribe to the old expired/cancelled subscription
218 218
 	 */
219
-	public function delete_resubscribe_meta( $resubscribe_order ) {
220
-		delete_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id() ), '_stripe_customer_id' );
221
-		delete_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id() ), '_stripe_source_id' );
219
+	public function delete_resubscribe_meta($resubscribe_order) {
220
+		delete_post_meta((WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id()), '_stripe_customer_id');
221
+		delete_post_meta((WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id()), '_stripe_source_id');
222 222
 		// For BW compat will remove in future
223
-		delete_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id() ), '_stripe_card_id' );
224
-		$this->delete_renewal_meta( $resubscribe_order );
223
+		delete_post_meta((WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id()), '_stripe_card_id');
224
+		$this->delete_renewal_meta($resubscribe_order);
225 225
 	}
226 226
 
227 227
 	/**
228 228
 	 * Don't transfer Stripe fee/ID meta to renewal orders.
229 229
 	 * @param int $resubscribe_order The order created for the customer to resubscribe to the old expired/cancelled subscription
230 230
 	 */
231
-	public function delete_renewal_meta( $renewal_order ) {
232
-		delete_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $renewal_order->id : $renewal_order->get_id() ), 'Stripe Fee' );
233
-		delete_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $renewal_order->id : $renewal_order->get_id() ), 'Net Revenue From Stripe' );
231
+	public function delete_renewal_meta($renewal_order) {
232
+		delete_post_meta((WC_Stripe_Helper::is_pre_30() ? $renewal_order->id : $renewal_order->get_id()), 'Stripe Fee');
233
+		delete_post_meta((WC_Stripe_Helper::is_pre_30() ? $renewal_order->id : $renewal_order->get_id()), 'Net Revenue From Stripe');
234 234
 		return $renewal_order;
235 235
 	}
236 236
 
@@ -240,21 +240,21 @@  discard block
 block discarded – undo
240 240
 	 * @param $amount_to_charge float The amount to charge.
241 241
 	 * @param $renewal_order WC_Order A WC_Order object created to record the renewal payment.
242 242
 	 */
243
-	public function scheduled_subscription_payment( $amount_to_charge, $renewal_order ) {
244
-		$response = $this->process_subscription_payment( $amount_to_charge, $renewal_order );
243
+	public function scheduled_subscription_payment($amount_to_charge, $renewal_order) {
244
+		$response = $this->process_subscription_payment($amount_to_charge, $renewal_order);
245 245
 
246
-		if ( is_wp_error( $response ) ) {
246
+		if (is_wp_error($response)) {
247 247
 			/* translators: error message */
248
-			$renewal_order->update_status( 'failed', sprintf( __( 'Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe' ), $response->get_error_message() ) );
248
+			$renewal_order->update_status('failed', sprintf(__('Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe'), $response->get_error_message()));
249 249
 		}
250 250
 
251
-		if ( ! empty( $response->error ) ) {
251
+		if ( ! empty($response->error)) {
252 252
 			// This is a very generic error to listen for but worth a retry before total fail.
253
-			if ( isset( $response->error->type ) && 'invalid_request_error' === $response->error->type && apply_filters( 'wc_stripe_use_default_customer_source', true ) ) {
254
-				$this->retry_subscription_payment( $amount_to_charge, $renewal_order );
253
+			if (isset($response->error->type) && 'invalid_request_error' === $response->error->type && apply_filters('wc_stripe_use_default_customer_source', true)) {
254
+				$this->retry_subscription_payment($amount_to_charge, $renewal_order);
255 255
 			} else {
256 256
 				/* translators: error message */
257
-				$renewal_order->update_status( 'failed', sprintf( __( 'Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe' ), $response->error->message ) );
257
+				$renewal_order->update_status('failed', sprintf(__('Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe'), $response->error->message));
258 258
 			}
259 259
 		}
260 260
 	}
@@ -263,20 +263,20 @@  discard block
 block discarded – undo
263 263
 	 * Remove order meta
264 264
 	 * @param  object $order
265 265
 	 */
266
-	public function remove_order_source_before_retry( $order ) {
266
+	public function remove_order_source_before_retry($order) {
267 267
 		$order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
268
-		delete_post_meta( $order_id, '_stripe_source_id' );
268
+		delete_post_meta($order_id, '_stripe_source_id');
269 269
 		// For BW compat will remove in the future.
270
-		delete_post_meta( $order_id, '_stripe_card_id' );
270
+		delete_post_meta($order_id, '_stripe_card_id');
271 271
 	}
272 272
 
273 273
 	/**
274 274
 	 * Remove order meta
275 275
 	 * @param object $order
276 276
 	 */
277
-	public function remove_order_customer_before_retry( $order ) {
277
+	public function remove_order_customer_before_retry($order) {
278 278
 		$order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
279
-		delete_post_meta( $order_id, '_stripe_customer_id' );
279
+		delete_post_meta($order_id, '_stripe_customer_id');
280 280
 	}
281 281
 
282 282
 	/**
@@ -288,14 +288,14 @@  discard block
 block discarded – undo
288 288
 	 * @param WC_Order $renewal_order The order which recorded the successful payment (to make up for the failed automatic payment).
289 289
 	 * @return void
290 290
 	 */
291
-	public function update_failing_payment_method( $subscription, $renewal_order ) {
292
-		if ( WC_Stripe_Helper::is_pre_30() ) {
293
-			update_post_meta( $subscription->id, '_stripe_customer_id', $renewal_order->stripe_customer_id );
294
-			update_post_meta( $subscription->id, '_stripe_source_id', $renewal_order->stripe_source_id );
291
+	public function update_failing_payment_method($subscription, $renewal_order) {
292
+		if (WC_Stripe_Helper::is_pre_30()) {
293
+			update_post_meta($subscription->id, '_stripe_customer_id', $renewal_order->stripe_customer_id);
294
+			update_post_meta($subscription->id, '_stripe_source_id', $renewal_order->stripe_source_id);
295 295
 
296 296
 		} else {
297
-			update_post_meta( $subscription->get_id(), '_stripe_customer_id', $renewal_order->get_meta( '_stripe_customer_id', true ) );
298
-			update_post_meta( $subscription->get_id(), '_stripe_source_id', $renewal_order->get_meta( '_stripe_source_id', true ) );
297
+			update_post_meta($subscription->get_id(), '_stripe_customer_id', $renewal_order->get_meta('_stripe_customer_id', true));
298
+			update_post_meta($subscription->get_id(), '_stripe_source_id', $renewal_order->get_meta('_stripe_source_id', true));
299 299
 		}
300 300
 	}
301 301
 
@@ -308,21 +308,21 @@  discard block
 block discarded – undo
308 308
 	 * @param WC_Subscription $subscription An instance of a subscription object
309 309
 	 * @return array
310 310
 	 */
311
-	public function add_subscription_payment_meta( $payment_meta, $subscription ) {
312
-		$source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_source_id', true );
311
+	public function add_subscription_payment_meta($payment_meta, $subscription) {
312
+		$source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_source_id', true);
313 313
 
314 314
 		// For BW compat will remove in future.
315
-		if ( empty( $source_id ) ) {
316
-			$source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_card_id', true );
315
+		if (empty($source_id)) {
316
+			$source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_card_id', true);
317 317
 
318 318
 			// Take this opportunity to update the key name.
319
-			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 );
319
+			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);
320 320
 		}
321 321
 
322
-		$payment_meta[ $this->id ] = array(
322
+		$payment_meta[$this->id] = array(
323 323
 			'post_meta' => array(
324 324
 				'_stripe_customer_id' => array(
325
-					'value' => get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_customer_id', true ),
325
+					'value' => get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_customer_id', true),
326 326
 					'label' => 'Stripe Customer ID',
327 327
 				),
328 328
 				'_stripe_source_id' => array(
@@ -343,17 +343,17 @@  discard block
 block discarded – undo
343 343
 	 * @param array $payment_meta associative array of meta data required for automatic payments
344 344
 	 * @return array
345 345
 	 */
346
-	public function validate_subscription_payment_meta( $payment_method_id, $payment_meta ) {
347
-		if ( $this->id === $payment_method_id ) {
346
+	public function validate_subscription_payment_meta($payment_method_id, $payment_meta) {
347
+		if ($this->id === $payment_method_id) {
348 348
 
349
-			if ( ! isset( $payment_meta['post_meta']['_stripe_customer_id']['value'] ) || empty( $payment_meta['post_meta']['_stripe_customer_id']['value'] ) ) {
350
-				throw new Exception( 'A "_stripe_customer_id" value is required.' );
351
-			} elseif ( 0 !== strpos( $payment_meta['post_meta']['_stripe_customer_id']['value'], 'cus_' ) ) {
352
-				throw new Exception( 'Invalid customer ID. A valid "_stripe_customer_id" must begin with "cus_".' );
349
+			if ( ! isset($payment_meta['post_meta']['_stripe_customer_id']['value']) || empty($payment_meta['post_meta']['_stripe_customer_id']['value'])) {
350
+				throw new Exception('A "_stripe_customer_id" value is required.');
351
+			} elseif (0 !== strpos($payment_meta['post_meta']['_stripe_customer_id']['value'], 'cus_')) {
352
+				throw new Exception('Invalid customer ID. A valid "_stripe_customer_id" must begin with "cus_".');
353 353
 			}
354 354
 
355
-			if ( ! isset( $payment_meta['post_meta']['_stripe_source_id']['value'] ) || empty( $payment_meta['post_meta']['_stripe_source_id']['value'] ) ) {
356
-				throw new Exception( 'A "_stripe_source_id" value is required.' );
355
+			if ( ! isset($payment_meta['post_meta']['_stripe_source_id']['value']) || empty($payment_meta['post_meta']['_stripe_source_id']['value'])) {
356
+				throw new Exception('A "_stripe_source_id" value is required.');
357 357
 			}
358 358
 		}
359 359
 	}
@@ -366,89 +366,89 @@  discard block
 block discarded – undo
366 366
 	 * @param WC_Subscription $subscription the subscription details
367 367
 	 * @return string the subscription payment method
368 368
 	 */
369
-	public function maybe_render_subscription_payment_method( $payment_method_to_display, $subscription ) {
369
+	public function maybe_render_subscription_payment_method($payment_method_to_display, $subscription) {
370 370
 		$customer_user = WC_Stripe_Helper::is_pre_30() ? $subscription->customer_user : $subscription->get_customer_id();
371 371
 
372 372
 		// bail for other payment methods
373
-		if ( ( WC_Stripe_Helper::is_pre_30() ? $subscription->payment_method : $subscription->get_payment_method() ) !== $this->id || ! $customer_user ) {
373
+		if ((WC_Stripe_Helper::is_pre_30() ? $subscription->payment_method : $subscription->get_payment_method()) !== $this->id || ! $customer_user) {
374 374
 			return $payment_method_to_display;
375 375
 		}
376 376
 
377
-		$stripe_source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_source_id', true );
377
+		$stripe_source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_source_id', true);
378 378
 
379 379
 		// For BW compat will remove in future.
380
-		if ( empty( $stripe_source_id ) ) {
381
-			$stripe_source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_card_id', true );
380
+		if (empty($stripe_source_id)) {
381
+			$stripe_source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_card_id', true);
382 382
 
383 383
 			// Take this opportunity to update the key name.
384
-			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 );
384
+			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);
385 385
 		}
386 386
 
387 387
 		$stripe_customer    = new WC_Stripe_Customer();
388
-		$stripe_customer_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_customer_id', true );
388
+		$stripe_customer_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_customer_id', true);
389 389
 
390 390
 		// If we couldn't find a Stripe customer linked to the subscription, fallback to the user meta data.
391
-		if ( ! $stripe_customer_id || ! is_string( $stripe_customer_id ) ) {
391
+		if ( ! $stripe_customer_id || ! is_string($stripe_customer_id)) {
392 392
 			$user_id            = $customer_user;
393
-			$stripe_customer_id = get_user_meta( $user_id, '_stripe_customer_id', true );
394
-			$stripe_source_id   = get_user_meta( $user_id, '_stripe_source_id', true );
393
+			$stripe_customer_id = get_user_meta($user_id, '_stripe_customer_id', true);
394
+			$stripe_source_id   = get_user_meta($user_id, '_stripe_source_id', true);
395 395
 
396 396
 			// For BW compat will remove in future.
397
-			if ( empty( $stripe_source_id ) ) {
398
-				$stripe_source_id = get_user_meta( $user_id, '_stripe_card_id', true );
397
+			if (empty($stripe_source_id)) {
398
+				$stripe_source_id = get_user_meta($user_id, '_stripe_card_id', true);
399 399
 
400 400
 				// Take this opportunity to update the key name.
401
-				update_user_meta( $user_id, '_stripe_source_id', $stripe_source_id );
401
+				update_user_meta($user_id, '_stripe_source_id', $stripe_source_id);
402 402
 			}
403 403
 		}
404 404
 
405 405
 		// If we couldn't find a Stripe customer linked to the account, fallback to the order meta data.
406
-		if ( ( ! $stripe_customer_id || ! is_string( $stripe_customer_id ) ) && false !== $subscription->order ) {
407
-			$stripe_customer_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id() ), '_stripe_customer_id', true );
408
-			$stripe_source_id   = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id() ), '_stripe_source_id', true );
406
+		if (( ! $stripe_customer_id || ! is_string($stripe_customer_id)) && false !== $subscription->order) {
407
+			$stripe_customer_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id()), '_stripe_customer_id', true);
408
+			$stripe_source_id   = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id()), '_stripe_source_id', true);
409 409
 
410 410
 			// For BW compat will remove in future.
411
-			if ( empty( $stripe_source_id ) ) {
412
-				$stripe_source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id() ), '_stripe_card_id', true );
411
+			if (empty($stripe_source_id)) {
412
+				$stripe_source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id()), '_stripe_card_id', true);
413 413
 
414 414
 				// Take this opportunity to update the key name.
415
-				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 );
415
+				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);
416 416
 			}
417 417
 		}
418 418
 
419
-		$stripe_customer->set_id( $stripe_customer_id );
419
+		$stripe_customer->set_id($stripe_customer_id);
420 420
 		$sources = $stripe_customer->get_sources();
421 421
 
422
-		if ( $sources ) {
422
+		if ($sources) {
423 423
 			$found_source = false;
424
-			foreach ( $sources as $source ) {
425
-				if ( isset( $source->type ) && 'card' === $source->type ) {
424
+			foreach ($sources as $source) {
425
+				if (isset($source->type) && 'card' === $source->type) {
426 426
 					$card = $source->card;
427 427
 				}
428 428
 
429
-				if ( $source->id === $stripe_source_id ) {
429
+				if ($source->id === $stripe_source_id) {
430 430
 					$found_source = true;
431 431
 
432
-					if ( $card ) {
432
+					if ($card) {
433 433
 						/* translators: 1) card brand 2) last 4 digits */
434
-						$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 );
434
+						$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);
435 435
 					} else {
436
-						$payment_method_to_display = __( 'N/A', 'woocommerce-gateway-stripe' );
436
+						$payment_method_to_display = __('N/A', 'woocommerce-gateway-stripe');
437 437
 					}
438 438
 					break;
439 439
 				}
440 440
 			}
441 441
 
442
-			if ( ! $found_source ) {
443
-				if ( 'card' === $sources[0]->type ) {
442
+			if ( ! $found_source) {
443
+				if ('card' === $sources[0]->type) {
444 444
 					$card = $sources[0]->card;
445 445
 				}
446 446
 
447
-				if ( $card ) {
447
+				if ($card) {
448 448
 					/* translators: 1) card brand 2) last 4 digits */
449
-					$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 );
449
+					$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);
450 450
 				} else {
451
-					$payment_method_to_display = __( 'N/A', 'woocommerce-gateway-stripe' );
451
+					$payment_method_to_display = __('N/A', 'woocommerce-gateway-stripe');
452 452
 				}
453 453
 			}
454 454
 		}
@@ -461,43 +461,43 @@  discard block
 block discarded – undo
461 461
 	 * @param int $order_id
462 462
 	 * @return array
463 463
 	 */
464
-	public function process_pre_order( $order_id, $retry, $force_save_source ) {
465
-		if ( WC_Pre_Orders_Order::order_requires_payment_tokenization( $order_id ) ) {
464
+	public function process_pre_order($order_id, $retry, $force_save_source) {
465
+		if (WC_Pre_Orders_Order::order_requires_payment_tokenization($order_id)) {
466 466
 			try {
467
-				$order = wc_get_order( $order_id );
467
+				$order = wc_get_order($order_id);
468 468
 
469
-				if ( $order->get_total() * 100 < WC_Stripe_Helper::get_minimum_amount() ) {
469
+				if ($order->get_total() * 100 < WC_Stripe_Helper::get_minimum_amount()) {
470 470
 					/* translators: minimum amount */
471
-					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 ) ) );
471
+					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)));
472 472
 				}
473 473
 
474
-				$source = $this->prepare_source( $this->get_source_object(), get_current_user_id(), true );
474
+				$source = $this->prepare_source($this->get_source_object(), get_current_user_id(), true);
475 475
 
476 476
 				// We need a source on file to continue.
477
-				if ( empty( $source->customer ) || empty( $source->source ) ) {
478
-					throw new Exception( __( 'Unable to store payment details. Please try again.', 'woocommerce-gateway-stripe' ) );
477
+				if (empty($source->customer) || empty($source->source)) {
478
+					throw new Exception(__('Unable to store payment details. Please try again.', 'woocommerce-gateway-stripe'));
479 479
 				}
480 480
 
481 481
 				// Store source to order meta
482
-				$this->save_source( $order, $source );
482
+				$this->save_source($order, $source);
483 483
 
484 484
 				// Remove cart
485 485
 				WC()->cart->empty_cart();
486 486
 
487 487
 				// Is pre ordered!
488
-				WC_Pre_Orders_Order::mark_order_as_pre_ordered( $order );
488
+				WC_Pre_Orders_Order::mark_order_as_pre_ordered($order);
489 489
 
490 490
 				// Return thank you page redirect
491 491
 				return array(
492 492
 					'result'   => 'success',
493
-					'redirect' => $this->get_return_url( $order ),
493
+					'redirect' => $this->get_return_url($order),
494 494
 				);
495
-			} catch ( Exception $e ) {
496
-				wc_add_notice( $e->getMessage(), 'error' );
495
+			} catch (Exception $e) {
496
+				wc_add_notice($e->getMessage(), 'error');
497 497
 				return;
498 498
 			}
499 499
 		} else {
500
-			return parent::process_payment( $order_id, $retry, $force_save_source );
500
+			return parent::process_payment($order_id, $retry, $force_save_source);
501 501
 		}
502 502
 	}
503 503
 
@@ -506,7 +506,7 @@  discard block
 block discarded – undo
506 506
 	 * @param WC_Order $order
507 507
 	 * @return void
508 508
 	 */
509
-	public function process_pre_order_release_payment( $order ) {
509
+	public function process_pre_order_release_payment($order) {
510 510
 		try {
511 511
 			// Define some callbacks if the first attempt fails.
512 512
 			$retry_callbacks = array(
@@ -514,33 +514,33 @@  discard block
 block discarded – undo
514 514
 				'remove_order_customer_before_retry',
515 515
 			);
516 516
 
517
-			while ( 1 ) {
518
-				$source   = $this->prepare_order_source( $order );
519
-				$response = WC_Stripe_API::request( $this->generate_payment_request( $order, $source ) );
517
+			while (1) {
518
+				$source   = $this->prepare_order_source($order);
519
+				$response = WC_Stripe_API::request($this->generate_payment_request($order, $source));
520 520
 
521
-				if ( ! empty( $response->error ) ) {
522
-					if ( 0 === sizeof( $retry_callbacks ) ) {
523
-						throw new Exception( $response->error->message );
521
+				if ( ! empty($response->error)) {
522
+					if (0 === sizeof($retry_callbacks)) {
523
+						throw new Exception($response->error->message);
524 524
 					} else {
525
-						$retry_callback = array_shift( $retry_callbacks );
526
-						call_user_func( array( $this, $retry_callback ), $order );
525
+						$retry_callback = array_shift($retry_callbacks);
526
+						call_user_func(array($this, $retry_callback), $order);
527 527
 					}
528 528
 				} else {
529 529
 					// Successful
530
-					$this->process_response( $response, $order );
530
+					$this->process_response($response, $order);
531 531
 					break;
532 532
 				}
533 533
 			}
534
-		} catch ( Exception $e ) {
534
+		} catch (Exception $e) {
535 535
 			/* translators: error message */
536
-			$order_note = sprintf( __( 'Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe' ), $e->getMessage() );
536
+			$order_note = sprintf(__('Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe'), $e->getMessage());
537 537
 
538 538
 			// Mark order as failed if not already set,
539 539
 			// otherwise, make sure we add the order note so we can detect when someone fails to check out multiple times
540
-			if ( ! $order->has_status( 'failed' ) ) {
541
-				$order->update_status( 'failed', $order_note );
540
+			if ( ! $order->has_status('failed')) {
541
+				$order->update_status('failed', $order_note);
542 542
 			} else {
543
-				$order->add_order_note( $order_note );
543
+				$order->add_order_note($order_note);
544 544
 			}
545 545
 		}
546 546
 	}
Please login to merge, or discard this patch.