Completed
Pull Request — master (#237)
by Roy
02:36
created
includes/class-wc-gateway-stripe-addons.php 1 patch
Spacing   +139 added lines, -139 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
 
@@ -16,22 +16,22 @@  discard block
 block discarded – undo
16 16
 	public function __construct() {
17 17
 		parent::__construct();
18 18
 
19
-		if ( class_exists( 'WC_Subscriptions_Order' ) ) {
20
-			add_action( 'woocommerce_scheduled_subscription_payment_' . $this->id, array( $this, 'scheduled_subscription_payment' ), 10, 2 );
21
-			add_action( 'wcs_resubscribe_order_created', array( $this, 'delete_resubscribe_meta' ), 10 );
22
-			add_action( 'wcs_renewal_order_created', array( $this, 'delete_renewal_meta' ), 10 );
23
-			add_action( 'woocommerce_subscription_failing_payment_method_updated_stripe', array( $this, 'update_failing_payment_method' ), 10, 2 );
19
+		if (class_exists('WC_Subscriptions_Order')) {
20
+			add_action('woocommerce_scheduled_subscription_payment_' . $this->id, array($this, 'scheduled_subscription_payment'), 10, 2);
21
+			add_action('wcs_resubscribe_order_created', array($this, 'delete_resubscribe_meta'), 10);
22
+			add_action('wcs_renewal_order_created', array($this, 'delete_renewal_meta'), 10);
23
+			add_action('woocommerce_subscription_failing_payment_method_updated_stripe', array($this, 'update_failing_payment_method'), 10, 2);
24 24
 
25 25
 			// display the credit card used for a subscription in the "My Subscriptions" table
26
-			add_filter( 'woocommerce_my_subscriptions_payment_method', array( $this, 'maybe_render_subscription_payment_method' ), 10, 2 );
26
+			add_filter('woocommerce_my_subscriptions_payment_method', array($this, 'maybe_render_subscription_payment_method'), 10, 2);
27 27
 
28 28
 			// allow store managers to manually set Stripe as the payment method on a subscription
29
-			add_filter( 'woocommerce_subscription_payment_meta', array( $this, 'add_subscription_payment_meta' ), 10, 2 );
30
-			add_filter( 'woocommerce_subscription_validate_payment_meta', array( $this, 'validate_subscription_payment_meta' ), 10, 2 );
29
+			add_filter('woocommerce_subscription_payment_meta', array($this, 'add_subscription_payment_meta'), 10, 2);
30
+			add_filter('woocommerce_subscription_validate_payment_meta', array($this, 'validate_subscription_payment_meta'), 10, 2);
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
 
@@ -40,8 +40,8 @@  discard block
 block discarded – undo
40 40
 	 * @param  int  $order_id
41 41
 	 * @return boolean
42 42
 	 */
43
-	protected function is_subscription( $order_id ) {
44
-		return ( function_exists( 'wcs_order_contains_subscription' ) && ( wcs_order_contains_subscription( $order_id ) || wcs_is_subscription( $order_id ) || wcs_order_contains_renewal( $order_id ) ) );
43
+	protected function is_subscription($order_id) {
44
+		return (function_exists('wcs_order_contains_subscription') && (wcs_order_contains_subscription($order_id) || wcs_is_subscription($order_id) || wcs_order_contains_renewal($order_id)));
45 45
 	}
46 46
 
47 47
 	/**
@@ -49,8 +49,8 @@  discard block
 block discarded – undo
49 49
 	 * @param  int  $order_id
50 50
 	 * @return boolean
51 51
 	 */
52
-	protected function is_pre_order( $order_id ) {
53
-		return ( class_exists( 'WC_Pre_Orders_Order' ) && WC_Pre_Orders_Order::order_contains_pre_order( $order_id ) );
52
+	protected function is_pre_order($order_id) {
53
+		return (class_exists('WC_Pre_Orders_Order') && WC_Pre_Orders_Order::order_contains_pre_order($order_id));
54 54
 	}
55 55
 
56 56
 	/**
@@ -58,41 +58,41 @@  discard block
 block discarded – undo
58 58
 	 * @param  int $order_id
59 59
 	 * @return array
60 60
 	 */
61
-	public function process_payment( $order_id, $retry = true, $force_customer = false ) {
62
-		if ( $this->is_subscription( $order_id ) ) {
61
+	public function process_payment($order_id, $retry = true, $force_customer = false) {
62
+		if ($this->is_subscription($order_id)) {
63 63
 			// Regular payment with force customer enabled
64
-			return parent::process_payment( $order_id, true, true );
64
+			return parent::process_payment($order_id, true, true);
65 65
 
66
-		} elseif ( $this->is_pre_order( $order_id ) ) {
67
-			return $this->process_pre_order( $order_id, $retry, $force_customer );
66
+		} elseif ($this->is_pre_order($order_id)) {
67
+			return $this->process_pre_order($order_id, $retry, $force_customer);
68 68
 
69 69
 		} else {
70
-			return parent::process_payment( $order_id, $retry, $force_customer );
70
+			return parent::process_payment($order_id, $retry, $force_customer);
71 71
 		}
72 72
 	}
73 73
 
74 74
 	/**
75 75
 	 * Updates other subscription sources.
76 76
 	 */
77
-	protected function save_source( $order, $source ) {
78
-		parent::save_source( $order, $source );
77
+	protected function save_source($order, $source) {
78
+		parent::save_source($order, $source);
79 79
 
80
-		$wc_pre_30 = version_compare( WC_VERSION, '3.0.0', '<' );
80
+		$wc_pre_30 = version_compare(WC_VERSION, '3.0.0', '<');
81 81
 		$order_id  = $wc_pre_30 ? $order->id : $order->get_id();
82 82
 
83 83
 		// Also store it on the subscriptions being purchased or paid for in the order
84
-		if ( function_exists( 'wcs_order_contains_subscription' ) && wcs_order_contains_subscription( $order_id ) ) {
85
-			$subscriptions = wcs_get_subscriptions_for_order( $order_id );
86
-		} elseif ( function_exists( 'wcs_order_contains_renewal' ) && wcs_order_contains_renewal( $order_id ) ) {
87
-			$subscriptions = wcs_get_subscriptions_for_renewal_order( $order_id );
84
+		if (function_exists('wcs_order_contains_subscription') && wcs_order_contains_subscription($order_id)) {
85
+			$subscriptions = wcs_get_subscriptions_for_order($order_id);
86
+		} elseif (function_exists('wcs_order_contains_renewal') && wcs_order_contains_renewal($order_id)) {
87
+			$subscriptions = wcs_get_subscriptions_for_renewal_order($order_id);
88 88
 		} else {
89 89
 			$subscriptions = array();
90 90
 		}
91 91
 
92
-		foreach ( $subscriptions as $subscription ) {
92
+		foreach ($subscriptions as $subscription) {
93 93
 			$subscription_id = $wc_pre_30 ? $subscription->id : $subscription->get_id();
94
-			update_post_meta( $subscription_id, '_stripe_customer_id', $source->customer );
95
-			update_post_meta( $subscription_id, '_stripe_card_id', $source->source );
94
+			update_post_meta($subscription_id, '_stripe_customer_id', $source->customer);
95
+			update_post_meta($subscription_id, '_stripe_card_id', $source->source);
96 96
 		}
97 97
 	}
98 98
 
@@ -104,13 +104,13 @@  discard block
 block discarded – undo
104 104
 	 * @param object $order
105 105
 	 * @param object $source
106 106
 	 */
107
-	public function filter_subscription_payment_request( $order, $source ) {
108
-		$request             = $this->generate_payment_request( $order, $source );
107
+	public function filter_subscription_payment_request($order, $source) {
108
+		$request             = $this->generate_payment_request($order, $source);
109 109
 		$request['capture']  = 'true';
110
-		$request['amount']   = $this->get_stripe_amount( $amount, $request['currency'] );
110
+		$request['amount']   = $this->get_stripe_amount($amount, $request['currency']);
111 111
 		$request['metadata'] = array(
112 112
 			'payment_type'   => 'recurring',
113
-			'site_url'       => esc_url( get_site_url() ),
113
+			'site_url'       => esc_url(get_site_url()),
114 114
 		);
115 115
 
116 116
 		return $request;
@@ -123,53 +123,53 @@  discard block
 block discarded – undo
123 123
 	 * @param string $stripe_token (default: '')
124 124
 	 * @param  bool initial_payment
125 125
 	 */
126
-	public function process_subscription_payment( $order = '', $amount = 0 ) {
127
-		if ( $amount * 100 < WC_Stripe::get_minimum_amount() ) {
128
-			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::get_minimum_amount() / 100 ) ) );
126
+	public function process_subscription_payment($order = '', $amount = 0) {
127
+		if ($amount * 100 < WC_Stripe::get_minimum_amount()) {
128
+			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::get_minimum_amount() / 100)));
129 129
 		}
130 130
 
131 131
 		// Get source from order
132
-		$source = $this->get_order_source( $order );
132
+		$source = $this->get_order_source($order);
133 133
 
134 134
 		// If no order source was defined, use user source instead.
135
-		if ( ! $source->customer ) {
136
-			$source = $this->get_source( $order->customer_user );
135
+		if ( ! $source->customer) {
136
+			$source = $this->get_source($order->customer_user);
137 137
 		}
138 138
 
139 139
 		// Or fail :(
140
-		if ( ! $source->customer ) {
141
-			return new WP_Error( 'stripe_error', __( 'Customer not found', 'woocommerce-gateway-stripe' ) );
140
+		if ( ! $source->customer) {
141
+			return new WP_Error('stripe_error', __('Customer not found', 'woocommerce-gateway-stripe'));
142 142
 		}
143 143
 
144
-		$order_id = version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->id : $order->get_id();
145
-		$this->log( "Info: Begin processing subscription payment for order {$order_id} for the amount of {$amount}" );
144
+		$order_id = version_compare(WC_VERSION, '3.0.0', '<') ? $order->id : $order->get_id();
145
+		$this->log("Info: Begin processing subscription payment for order {$order_id} for the amount of {$amount}");
146 146
 
147 147
 		// Make the request
148
-		$request             = $this->generate_payment_request( $order, $source );
148
+		$request             = $this->generate_payment_request($order, $source);
149 149
 		$request['capture']  = 'true';
150
-		$request['amount']   = $this->get_stripe_amount( $amount, $request['currency'] );
150
+		$request['amount']   = $this->get_stripe_amount($amount, $request['currency']);
151 151
 		$request['metadata'] = array(
152 152
 			'payment_type'   => 'recurring',
153
-			'site_url'       => esc_url( get_site_url() ),
153
+			'site_url'       => esc_url(get_site_url()),
154 154
 		);
155
-		$response            = WC_Stripe_API::request( $request );
155
+		$response = WC_Stripe_API::request($request);
156 156
 
157 157
 		// Process valid response
158
-		if ( is_wp_error( $response ) ) {
159
-			if ( 'missing' === $response->get_error_code() ) {
158
+		if (is_wp_error($response)) {
159
+			if ('missing' === $response->get_error_code()) {
160 160
 				// If we can't link customer to a card, we try to charge by customer ID.
161
-				$request             = $this->generate_payment_request( $order, $this->get_source( $order->customer_user ) );
161
+				$request             = $this->generate_payment_request($order, $this->get_source($order->customer_user));
162 162
 				$request['capture']  = 'true';
163
-				$request['amount']   = $this->get_stripe_amount( $amount, $request['currency'] );
163
+				$request['amount']   = $this->get_stripe_amount($amount, $request['currency']);
164 164
 				$request['metadata'] = array(
165 165
 					'payment_type'   => 'recurring',
166
-					'site_url'       => esc_url( get_site_url() ),
166
+					'site_url'       => esc_url(get_site_url()),
167 167
 				);
168
-				$response          = WC_Stripe_API::request( $request );
168
+				$response = WC_Stripe_API::request($request);
169 169
 			}
170 170
 		}
171 171
 
172
-		$this->process_response( $response, $order );
172
+		$this->process_response($response, $order);
173 173
 
174 174
 		return $response;
175 175
 	}
@@ -179,42 +179,42 @@  discard block
 block discarded – undo
179 179
 	 * @param int $order_id
180 180
 	 * @return array
181 181
 	 */
182
-	public function process_pre_order( $order_id, $retry, $force_customer ) {
183
-		if ( WC_Pre_Orders_Order::order_requires_payment_tokenization( $order_id ) ) {
182
+	public function process_pre_order($order_id, $retry, $force_customer) {
183
+		if (WC_Pre_Orders_Order::order_requires_payment_tokenization($order_id)) {
184 184
 			try {
185
-				$order = wc_get_order( $order_id );
185
+				$order = wc_get_order($order_id);
186 186
 
187
-				if ( $order->get_total() * 100 < WC_Stripe::get_minimum_amount() ) {
188
-					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::get_minimum_amount() / 100 ) ) );
187
+				if ($order->get_total() * 100 < WC_Stripe::get_minimum_amount()) {
188
+					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::get_minimum_amount() / 100)));
189 189
 				}
190 190
 
191
-				$source = $this->get_source( get_current_user_id(), true );
191
+				$source = $this->get_source(get_current_user_id(), true);
192 192
 
193 193
 				// We need a source on file to continue.
194
-				if ( empty( $source->customer ) || empty( $source->source ) ) {
195
-					throw new Exception( __( 'Unable to store payment details. Please try again.', 'woocommerce-gateway-stripe' ) );
194
+				if (empty($source->customer) || empty($source->source)) {
195
+					throw new Exception(__('Unable to store payment details. Please try again.', 'woocommerce-gateway-stripe'));
196 196
 				}
197 197
 
198 198
 				// Store source to order meta
199
-				$this->save_source( $order, $source );
199
+				$this->save_source($order, $source);
200 200
 
201 201
 				// Remove cart
202 202
 				WC()->cart->empty_cart();
203 203
 
204 204
 				// Is pre ordered!
205
-				WC_Pre_Orders_Order::mark_order_as_pre_ordered( $order );
205
+				WC_Pre_Orders_Order::mark_order_as_pre_ordered($order);
206 206
 
207 207
 				// Return thank you page redirect
208 208
 				return array(
209 209
 					'result'   => 'success',
210
-					'redirect' => $this->get_return_url( $order ),
210
+					'redirect' => $this->get_return_url($order),
211 211
 				);
212
-			} catch ( Exception $e ) {
213
-				wc_add_notice( $e->getMessage(), 'error' );
212
+			} catch (Exception $e) {
213
+				wc_add_notice($e->getMessage(), 'error');
214 214
 				return;
215 215
 			}
216 216
 		} else {
217
-			return parent::process_payment( $order_id, $retry, $force_customer );
217
+			return parent::process_payment($order_id, $retry, $force_customer);
218 218
 		}
219 219
 	}
220 220
 
@@ -223,7 +223,7 @@  discard block
 block discarded – undo
223 223
 	 * @param WC_Order $order
224 224
 	 * @return void
225 225
 	 */
226
-	public function process_pre_order_release_payment( $order ) {
226
+	public function process_pre_order_release_payment($order) {
227 227
 		try {
228 228
 			// Define some callbacks if the first attempt fails.
229 229
 			$retry_callbacks = array(
@@ -231,32 +231,32 @@  discard block
 block discarded – undo
231 231
 				'remove_order_customer_before_retry',
232 232
 			);
233 233
 
234
-			while ( 1 ) {
235
-				$source   = $this->get_order_source( $order );
236
-				$response = WC_Stripe_API::request( $this->generate_payment_request( $order, $source ) );
234
+			while (1) {
235
+				$source   = $this->get_order_source($order);
236
+				$response = WC_Stripe_API::request($this->generate_payment_request($order, $source));
237 237
 
238
-				if ( is_wp_error( $response ) ) {
239
-					if ( 0 === sizeof( $retry_callbacks ) ) {
240
-						throw new Exception( $response->get_error_message() );
238
+				if (is_wp_error($response)) {
239
+					if (0 === sizeof($retry_callbacks)) {
240
+						throw new Exception($response->get_error_message());
241 241
 					} else {
242
-						$retry_callback = array_shift( $retry_callbacks );
243
-						call_user_func( array( $this, $retry_callback ), $order );
242
+						$retry_callback = array_shift($retry_callbacks);
243
+						call_user_func(array($this, $retry_callback), $order);
244 244
 					}
245 245
 				} else {
246 246
 					// Successful
247
-					$this->process_response( $response, $order );
247
+					$this->process_response($response, $order);
248 248
 					break;
249 249
 				}
250 250
 			}
251
-		} catch ( Exception $e ) {
252
-			$order_note = sprintf( __( 'Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe' ), $e->getMessage() );
251
+		} catch (Exception $e) {
252
+			$order_note = sprintf(__('Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe'), $e->getMessage());
253 253
 
254 254
 			// Mark order as failed if not already set,
255 255
 			// otherwise, make sure we add the order note so we can detect when someone fails to check out multiple times
256
-			if ( ! $order->has_status( 'failed' ) ) {
257
-				$order->update_status( 'failed', $order_note );
256
+			if ( ! $order->has_status('failed')) {
257
+				$order->update_status('failed', $order_note);
258 258
 			} else {
259
-				$order->add_order_note( $order_note );
259
+				$order->add_order_note($order_note);
260 260
 			}
261 261
 		}
262 262
 	}
@@ -265,20 +265,20 @@  discard block
 block discarded – undo
265 265
 	 * Don't transfer Stripe customer/token meta to resubscribe orders.
266 266
 	 * @param int $resubscribe_order The order created for the customer to resubscribe to the old expired/cancelled subscription
267 267
 	 */
268
-	public function delete_resubscribe_meta( $resubscribe_order ) {
269
-		delete_post_meta( $resubscribe_order->id, '_stripe_customer_id' );
270
-		delete_post_meta( $resubscribe_order->id, '_stripe_card_id' );
271
-		$this->delete_renewal_meta( $resubscribe_order );
268
+	public function delete_resubscribe_meta($resubscribe_order) {
269
+		delete_post_meta($resubscribe_order->id, '_stripe_customer_id');
270
+		delete_post_meta($resubscribe_order->id, '_stripe_card_id');
271
+		$this->delete_renewal_meta($resubscribe_order);
272 272
 	}
273 273
 
274 274
 	/**
275 275
 	 * Don't transfer Stripe fee/ID meta to renewal orders.
276 276
 	 * @param int $resubscribe_order The order created for the customer to resubscribe to the old expired/cancelled subscription
277 277
 	 */
278
-	public function delete_renewal_meta( $renewal_order ) {
279
-		delete_post_meta( $renewal_order->id, 'Stripe Fee' );
280
-		delete_post_meta( $renewal_order->id, 'Net Revenue From Stripe' );
281
-		delete_post_meta( $renewal_order->id, 'Stripe Payment ID' );
278
+	public function delete_renewal_meta($renewal_order) {
279
+		delete_post_meta($renewal_order->id, 'Stripe Fee');
280
+		delete_post_meta($renewal_order->id, 'Net Revenue From Stripe');
281
+		delete_post_meta($renewal_order->id, 'Stripe Payment ID');
282 282
 		return $renewal_order;
283 283
 	}
284 284
 
@@ -288,11 +288,11 @@  discard block
 block discarded – undo
288 288
 	 * @param $amount_to_charge float The amount to charge.
289 289
 	 * @param $renewal_order WC_Order A WC_Order object created to record the renewal payment.
290 290
 	 */
291
-	public function scheduled_subscription_payment( $amount_to_charge, $renewal_order ) {
292
-		$response = $this->process_subscription_payment( $renewal_order, $amount_to_charge );
291
+	public function scheduled_subscription_payment($amount_to_charge, $renewal_order) {
292
+		$response = $this->process_subscription_payment($renewal_order, $amount_to_charge);
293 293
 
294
-		if ( is_wp_error( $response ) ) {
295
-			$renewal_order->update_status( 'failed', sprintf( __( 'Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe' ), $response->get_error_message() ) );
294
+		if (is_wp_error($response)) {
295
+			$renewal_order->update_status('failed', sprintf(__('Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe'), $response->get_error_message()));
296 296
 		}
297 297
 	}
298 298
 
@@ -300,18 +300,18 @@  discard block
 block discarded – undo
300 300
 	 * Remove order meta
301 301
 	 * @param  object $order
302 302
 	 */
303
-	public function remove_order_source_before_retry( $order ) {
304
-		$order_id = version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->id : $order->get_id();
305
-		delete_post_meta( $order_id, '_stripe_card_id' );
303
+	public function remove_order_source_before_retry($order) {
304
+		$order_id = version_compare(WC_VERSION, '3.0.0', '<') ? $order->id : $order->get_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 ) {
313
-		$order_id = version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->id : $order->get_id();
314
-		delete_post_meta( $order_id, '_stripe_customer_id' );
312
+	public function remove_order_customer_before_retry($order) {
313
+		$order_id = version_compare(WC_VERSION, '3.0.0', '<') ? $order->id : $order->get_id();
314
+		delete_post_meta($order_id, '_stripe_customer_id');
315 315
 	}
316 316
 
317 317
 	/**
@@ -323,9 +323,9 @@  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
-		update_post_meta( $subscription->id, '_stripe_customer_id', $renewal_order->stripe_customer_id );
328
-		update_post_meta( $subscription->id, '_stripe_card_id', $renewal_order->stripe_card_id );
326
+	public function update_failing_payment_method($subscription, $renewal_order) {
327
+		update_post_meta($subscription->id, '_stripe_customer_id', $renewal_order->stripe_customer_id);
328
+		update_post_meta($subscription->id, '_stripe_card_id', $renewal_order->stripe_card_id);
329 329
 	}
330 330
 
331 331
 	/**
@@ -337,15 +337,15 @@  discard block
 block discarded – undo
337 337
 	 * @param WC_Subscription $subscription An instance of a subscription object
338 338
 	 * @return array
339 339
 	 */
340
-	public function add_subscription_payment_meta( $payment_meta, $subscription ) {
341
-		$payment_meta[ $this->id ] = array(
340
+	public function add_subscription_payment_meta($payment_meta, $subscription) {
341
+		$payment_meta[$this->id] = array(
342 342
 			'post_meta' => array(
343 343
 				'_stripe_customer_id' => array(
344
-					'value' => get_post_meta( $subscription->id, '_stripe_customer_id', true ),
344
+					'value' => get_post_meta($subscription->id, '_stripe_customer_id', true),
345 345
 					'label' => 'Stripe Customer ID',
346 346
 				),
347 347
 				'_stripe_card_id' => array(
348
-					'value' => get_post_meta( $subscription->id, '_stripe_card_id', true ),
348
+					'value' => get_post_meta($subscription->id, '_stripe_card_id', true),
349 349
 					'label' => 'Stripe Card ID',
350 350
 				),
351 351
 			),
@@ -362,17 +362,17 @@  discard block
 block discarded – undo
362 362
 	 * @param array $payment_meta associative array of meta data required for automatic payments
363 363
 	 * @return array
364 364
 	 */
365
-	public function validate_subscription_payment_meta( $payment_method_id, $payment_meta ) {
366
-		if ( $this->id === $payment_method_id ) {
365
+	public function validate_subscription_payment_meta($payment_method_id, $payment_meta) {
366
+		if ($this->id === $payment_method_id) {
367 367
 
368
-			if ( ! isset( $payment_meta['post_meta']['_stripe_customer_id']['value'] ) || empty( $payment_meta['post_meta']['_stripe_customer_id']['value'] ) ) {
369
-				throw new Exception( 'A "_stripe_customer_id" value is required.' );
370
-			} elseif ( 0 !== strpos( $payment_meta['post_meta']['_stripe_customer_id']['value'], 'cus_' ) ) {
371
-				throw new Exception( 'Invalid customer ID. A valid "_stripe_customer_id" must begin with "cus_".' );
368
+			if ( ! isset($payment_meta['post_meta']['_stripe_customer_id']['value']) || empty($payment_meta['post_meta']['_stripe_customer_id']['value'])) {
369
+				throw new Exception('A "_stripe_customer_id" value is required.');
370
+			} elseif (0 !== strpos($payment_meta['post_meta']['_stripe_customer_id']['value'], 'cus_')) {
371
+				throw new Exception('Invalid customer ID. A valid "_stripe_customer_id" must begin with "cus_".');
372 372
 			}
373 373
 
374
-			if ( ! empty( $payment_meta['post_meta']['_stripe_card_id']['value'] ) && 0 !== strpos( $payment_meta['post_meta']['_stripe_card_id']['value'], 'card_' ) ) {
375
-				throw new Exception( 'Invalid card ID. A valid "_stripe_card_id" must begin with "card_".' );
374
+			if ( ! empty($payment_meta['post_meta']['_stripe_card_id']['value']) && 0 !== strpos($payment_meta['post_meta']['_stripe_card_id']['value'], 'card_')) {
375
+				throw new Exception('Invalid card ID. A valid "_stripe_card_id" must begin with "card_".');
376 376
 			}
377 377
 		}
378 378
 	}
@@ -385,43 +385,43 @@  discard block
 block discarded – undo
385 385
 	 * @param WC_Subscription $subscription the subscription details
386 386
 	 * @return string the subscription payment method
387 387
 	 */
388
-	public function maybe_render_subscription_payment_method( $payment_method_to_display, $subscription ) {
388
+	public function maybe_render_subscription_payment_method($payment_method_to_display, $subscription) {
389 389
 		// bail for other payment methods
390
-		if ( $this->id !== $subscription->payment_method || ! $subscription->customer_user ) {
390
+		if ($this->id !== $subscription->payment_method || ! $subscription->customer_user) {
391 391
 			return $payment_method_to_display;
392 392
 		}
393 393
 
394 394
 		$stripe_customer    = new WC_Stripe_Customer();
395
-		$stripe_customer_id = get_post_meta( $subscription->id, '_stripe_customer_id', true );
396
-		$stripe_card_id     = get_post_meta( $subscription->id, '_stripe_card_id', true );
395
+		$stripe_customer_id = get_post_meta($subscription->id, '_stripe_customer_id', true);
396
+		$stripe_card_id     = get_post_meta($subscription->id, '_stripe_card_id', true);
397 397
 
398 398
 		// If we couldn't find a Stripe customer linked to the subscription, fallback to the user meta data.
399
-		if ( ! $stripe_customer_id || ! is_string( $stripe_customer_id ) ) {
399
+		if ( ! $stripe_customer_id || ! is_string($stripe_customer_id)) {
400 400
 			$user_id            = $subscription->customer_user;
401
-			$stripe_customer_id = get_user_meta( $user_id, '_stripe_customer_id', true );
402
-			$stripe_card_id     = get_user_meta( $user_id, '_stripe_card_id', true );
401
+			$stripe_customer_id = get_user_meta($user_id, '_stripe_customer_id', true);
402
+			$stripe_card_id     = get_user_meta($user_id, '_stripe_card_id', true);
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( $subscription->order->id, '_stripe_customer_id', true );
408
-			$stripe_card_id     = get_post_meta( $subscription->order->id, '_stripe_card_id', true );
406
+		if (( ! $stripe_customer_id || ! is_string($stripe_customer_id)) && false !== $subscription->order) {
407
+			$stripe_customer_id = get_post_meta($subscription->order->id, '_stripe_customer_id', true);
408
+			$stripe_card_id     = get_post_meta($subscription->order->id, '_stripe_card_id', true);
409 409
 		}
410 410
 
411
-		$stripe_customer->set_id( $stripe_customer_id );
411
+		$stripe_customer->set_id($stripe_customer_id);
412 412
 		$cards = $stripe_customer->get_cards();
413 413
 
414
-		if ( $cards ) {
414
+		if ($cards) {
415 415
 			$found_card = false;
416
-			foreach ( $cards as $card ) {
417
-				if ( $card->id === $stripe_card_id ) {
416
+			foreach ($cards as $card) {
417
+				if ($card->id === $stripe_card_id) {
418 418
 					$found_card                = true;
419
-					$payment_method_to_display = sprintf( __( 'Via %1$s card ending in %2$s', 'woocommerce-gateway-stripe' ), ( isset( $card->type ) ? $card->type : $card->brand ), $card->last4 );
419
+					$payment_method_to_display = sprintf(__('Via %1$s card ending in %2$s', 'woocommerce-gateway-stripe'), (isset($card->type) ? $card->type : $card->brand), $card->last4);
420 420
 					break;
421 421
 				}
422 422
 			}
423
-			if ( ! $found_card ) {
424
-				$payment_method_to_display = sprintf( __( 'Via %1$s card ending in %2$s', 'woocommerce-gateway-stripe' ), ( isset( $cards[0]->type ) ? $cards[0]->type : $cards[0]->brand ), $cards[0]->last4 );
423
+			if ( ! $found_card) {
424
+				$payment_method_to_display = sprintf(__('Via %1$s card ending in %2$s', 'woocommerce-gateway-stripe'), (isset($cards[0]->type) ? $cards[0]->type : $cards[0]->brand), $cards[0]->last4);
425 425
 			}
426 426
 		}
427 427
 
@@ -436,11 +436,11 @@  discard block
 block discarded – undo
436 436
 	 *
437 437
 	 * @param string $message
438 438
 	 */
439
-	public function log( $message ) {
440
-		$options = get_option( 'woocommerce_stripe_settings' );
439
+	public function log($message) {
440
+		$options = get_option('woocommerce_stripe_settings');
441 441
 
442
-		if ( 'yes' === $options['logging'] ) {
443
-			WC_Stripe::log( $message );
442
+		if ('yes' === $options['logging']) {
443
+			WC_Stripe::log($message);
444 444
 		}
445 445
 	}
446 446
 }
Please login to merge, or discard this patch.