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