Completed
Push — master ( 221f5c...f6a70b )
by Roy
02:11
created
includes/abstracts/abstract-wc-stripe-payment-gateway.php 1 patch
Spacing   +199 added lines, -200 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,11 +18,11 @@  discard block
 block discarded – undo
18 18
 	 * Check if this gateway is enabled
19 19
 	 */
20 20
 	public function is_available() {
21
-		if ( 'yes' === $this->enabled ) {
22
-			if ( ! $this->testmode && is_checkout() && ! is_ssl() ) {
21
+		if ('yes' === $this->enabled) {
22
+			if ( ! $this->testmode && is_checkout() && ! is_ssl()) {
23 23
 				return false;
24 24
 			}
25
-			if ( ! $this->secret_key || ! $this->publishable_key ) {
25
+			if ( ! $this->secret_key || ! $this->publishable_key) {
26 26
 				return false;
27 27
 			}
28 28
 			return true;
@@ -37,8 +37,8 @@  discard block
 block discarded – undo
37 37
 	 * @since 4.0.0
38 38
 	 * @version 4.0.0
39 39
 	 */
40
-	public function add_admin_notice( $slug, $class, $message ) {
41
-		$this->notices[ $slug ] = array(
40
+	public function add_admin_notice($slug, $class, $message) {
41
+		$this->notices[$slug] = array(
42 42
 			'class'   => $class,
43 43
 			'message' => $message,
44 44
 		);
@@ -51,8 +51,8 @@  discard block
 block discarded – undo
51 51
 	 * @version 4.0.0
52 52
 	 */
53 53
 	public function remove_admin_notice() {
54
-		if ( did_action( 'woocommerce_update_options' ) ) {
55
-			remove_action( 'admin_notices', array( $this, 'check_environment' ) );
54
+		if (did_action('woocommerce_update_options')) {
55
+			remove_action('admin_notices', array($this, 'check_environment'));
56 56
 		}
57 57
 	}
58 58
 
@@ -64,7 +64,7 @@  discard block
 block discarded – undo
64 64
 	 * @return array
65 65
 	 */
66 66
 	public function payment_icons() {
67
-		return apply_filters( 'wc_stripe_payment_icons', array(
67
+		return apply_filters('wc_stripe_payment_icons', array(
68 68
 			'visa'       => '<i class="stripe-pf stripe-pf-visa stripe-pf-right" alt="Visa" aria-hidden="true"></i>',
69 69
 			'amex'       => '<i class="stripe-pf stripe-pf-american-express stripe-pf-right" alt="Amex" aria-hidden="true"></i>',
70 70
 			'mastercard' => '<i class="stripe-pf stripe-pf-mastercard stripe-pf-right" alt="Mastercard" aria-hidden="true"></i>',
@@ -81,7 +81,7 @@  discard block
 block discarded – undo
81 81
 			'eps'        => '<i class="stripe-pf stripe-pf-eps stripe-pf-right" alt="EPS" aria-hidden="true"></i>',
82 82
 			'sofort'     => '<i class="stripe-pf stripe-pf-sofort stripe-pf-right" alt="SOFORT" aria-hidden="true"></i>',
83 83
 			'sepa'       => '<i class="stripe-pf stripe-pf-sepa stripe-pf-right" alt="SEPA" aria-hidden="true"></i>',
84
-		) );
84
+		));
85 85
 	}
86 86
 
87 87
 	/**
@@ -92,10 +92,10 @@  discard block
 block discarded – undo
92 92
 	 * @version 4.0.0
93 93
 	 * @param object $order
94 94
 	 */
95
-	public function validate_minimum_order_amount( $order ) {
96
-		if ( $order->get_total() * 100 < WC_Stripe_Helper::get_minimum_amount() ) {
95
+	public function validate_minimum_order_amount($order) {
96
+		if ($order->get_total() * 100 < WC_Stripe_Helper::get_minimum_amount()) {
97 97
 			/* translators: 1) dollar amount */
98
-			throw new WC_Stripe_Exception( 'Did not meet minimum amount', sprintf( __( 'Sorry, the minimum allowed order total is %1$s to use this payment method.', 'woocommerce-gateway-stripe' ), wc_price( WC_Stripe_Helper::get_minimum_amount() / 100 ) ) );
98
+			throw new WC_Stripe_Exception('Did not meet minimum amount', sprintf(__('Sorry, the minimum allowed order total is %1$s to use this payment method.', 'woocommerce-gateway-stripe'), wc_price(WC_Stripe_Helper::get_minimum_amount() / 100)));
99 99
 		}
100 100
 	}
101 101
 
@@ -105,14 +105,14 @@  discard block
 block discarded – undo
105 105
 	 * @since 4.0.0
106 106
 	 * @version 4.0.0
107 107
 	 */
108
-	public function get_transaction_url( $order ) {
109
-		if ( $this->testmode ) {
108
+	public function get_transaction_url($order) {
109
+		if ($this->testmode) {
110 110
 			$this->view_transaction_url = 'https://dashboard.stripe.com/test/payments/%s';
111 111
 		} else {
112 112
 			$this->view_transaction_url = 'https://dashboard.stripe.com/payments/%s';
113 113
 		}
114 114
 
115
-		return parent::get_transaction_url( $order );
115
+		return parent::get_transaction_url($order);
116 116
 	}
117 117
 
118 118
 	/**
@@ -121,15 +121,15 @@  discard block
 block discarded – undo
121 121
 	 * @since 4.0.0
122 122
 	 * @version 4.0.0
123 123
 	 */
124
-	public function get_stripe_customer_id( $order ) {
125
-		$customer = get_user_meta( WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id(), '_stripe_customer_id', true );
124
+	public function get_stripe_customer_id($order) {
125
+		$customer = get_user_meta(WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id(), '_stripe_customer_id', true);
126 126
 
127
-		if ( empty( $customer ) ) {
127
+		if (empty($customer)) {
128 128
 			// Try to get it via the order.
129
-			if ( WC_Stripe_Helper::is_pre_30() ) {
130
-				return get_post_meta( $order->id, '_stripe_customer_id', true );
129
+			if (WC_Stripe_Helper::is_pre_30()) {
130
+				return get_post_meta($order->id, '_stripe_customer_id', true);
131 131
 			} else {
132
-				return $order->get_meta( '_stripe_customer_id', true );
132
+				return $order->get_meta('_stripe_customer_id', true);
133 133
 			}
134 134
 		} else {
135 135
 			return $customer;
@@ -146,9 +146,9 @@  discard block
 block discarded – undo
146 146
 	 * @param object $order
147 147
 	 * @param int $id Stripe session id.
148 148
 	 */
149
-	public function get_stripe_return_url( $order = null, $id = null ) {
150
-		if ( is_object( $order ) ) {
151
-			if ( empty( $id ) ) {
149
+	public function get_stripe_return_url($order = null, $id = null) {
150
+		if (is_object($order)) {
151
+			if (empty($id)) {
152 152
 				$id = uniqid();
153 153
 			}
154 154
 
@@ -159,10 +159,10 @@  discard block
 block discarded – undo
159 159
 				'order_id'       => $order_id,
160 160
 			);
161 161
 
162
-			return esc_url_raw( add_query_arg( $args, $this->get_return_url( $order ) ) );
162
+			return esc_url_raw(add_query_arg($args, $this->get_return_url($order)));
163 163
 		}
164 164
 
165
-		return esc_url_raw( add_query_arg( array( 'utm_nooverride' => '1' ), $this->get_return_url() ) );
165
+		return esc_url_raw(add_query_arg(array('utm_nooverride' => '1'), $this->get_return_url()));
166 166
 	}
167 167
 
168 168
 	/**
@@ -174,34 +174,33 @@  discard block
 block discarded – undo
174 174
 	 * @param  object $source
175 175
 	 * @return array()
176 176
 	 */
177
-	public function generate_payment_request( $order, $source ) {
178
-		$settings                          = get_option( 'woocommerce_stripe_settings', array() );
179
-		$statement_descriptor              = ! empty( $settings['statement_descriptor'] ) ? str_replace( "'", '', $settings['statement_descriptor'] ) : '';
180
-		$capture                           = ! empty( $settings['capture'] ) && 'yes' === $settings['capture'] ? true : false;
177
+	public function generate_payment_request($order, $source) {
178
+		$settings                          = get_option('woocommerce_stripe_settings', array());
179
+		$statement_descriptor              = ! empty($settings['statement_descriptor']) ? str_replace("'", '', $settings['statement_descriptor']) : '';
180
+		$capture                           = ! empty($settings['capture']) && 'yes' === $settings['capture'] ? true : false;
181 181
 		$post_data                         = array();
182
-		$post_data['currency']             = strtolower( WC_Stripe_Helper::is_pre_30() ? $order->get_order_currency() : $order->get_currency() );
183
-		$post_data['amount']               = WC_Stripe_Helper::get_stripe_amount( $order->get_total(), $post_data['currency'] );
182
+		$post_data['currency']             = strtolower(WC_Stripe_Helper::is_pre_30() ? $order->get_order_currency() : $order->get_currency());
183
+		$post_data['amount']               = WC_Stripe_Helper::get_stripe_amount($order->get_total(), $post_data['currency']);
184 184
 		/* translators: 1) blog name 2) order number */
185
-		$post_data['description']          = sprintf( __( '%1$s - Order %2$s', 'woocommerce-gateway-stripe' ), wp_specialchars_decode( get_bloginfo( 'name' ), ENT_QUOTES ), $order->get_order_number() );
185
+		$post_data['description']          = sprintf(__('%1$s - Order %2$s', 'woocommerce-gateway-stripe'), wp_specialchars_decode(get_bloginfo('name'), ENT_QUOTES), $order->get_order_number());
186 186
 		$billing_email      = WC_Stripe_Helper::is_pre_30() ? $order->billing_email : $order->get_billing_email();
187 187
 		$billing_first_name = WC_Stripe_Helper::is_pre_30() ? $order->billing_first_name : $order->get_billing_first_name();
188 188
 		$billing_last_name  = WC_Stripe_Helper::is_pre_30() ? $order->billing_last_name : $order->get_billing_last_name();
189 189
 
190
-		if ( ! empty( $billing_email ) && apply_filters( 'wc_stripe_send_stripe_receipt', false ) ) {
190
+		if ( ! empty($billing_email) && apply_filters('wc_stripe_send_stripe_receipt', false)) {
191 191
 			$post_data['receipt_email'] = $billing_email;
192 192
 		}
193 193
 
194
-		switch ( WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method() ) {
195
-			case 'stripe':
196
-				if ( ! empty( $statement_descriptor ) ) {
197
-					$post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor( $statement_descriptor );
194
+		switch (WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method()) {
195
+			case 'stripe' : if ( ! empty($statement_descriptor)) {
196
+					$post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor($statement_descriptor);
198 197
 				}
199 198
 
200 199
 				$post_data['capture'] = $capture ? 'true' : 'false';
201 200
 				break;
202 201
 			case 'stripe_sepa':
203
-				if ( ! empty( $statement_descriptor ) ) {
204
-					$post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor( $statement_descriptor );
202
+				if ( ! empty($statement_descriptor)) {
203
+					$post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor($statement_descriptor);
205 204
 				}
206 205
 				break;
207 206
 		}
@@ -209,18 +208,18 @@  discard block
 block discarded – undo
209 208
 		$post_data['expand[]'] = 'balance_transaction';
210 209
 
211 210
 		$metadata = array(
212
-			__( 'customer_name', 'woocommerce-gateway-stripe' ) => sanitize_text_field( $billing_first_name ) . ' ' . sanitize_text_field( $billing_last_name ),
213
-			__( 'customer_email', 'woocommerce-gateway-stripe' ) => sanitize_email( $billing_email ),
211
+			__('customer_name', 'woocommerce-gateway-stripe') => sanitize_text_field($billing_first_name) . ' ' . sanitize_text_field($billing_last_name),
212
+			__('customer_email', 'woocommerce-gateway-stripe') => sanitize_email($billing_email),
214 213
 			'order_id' => WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(),
215 214
 		);
216 215
 
217
-		$post_data['metadata'] = apply_filters( 'wc_stripe_payment_metadata', $metadata, $order, $source );
216
+		$post_data['metadata'] = apply_filters('wc_stripe_payment_metadata', $metadata, $order, $source);
218 217
 
219
-		if ( $source->customer ) {
218
+		if ($source->customer) {
220 219
 			$post_data['customer'] = $source->customer;
221 220
 		}
222 221
 
223
-		if ( $source->source ) {
222
+		if ($source->source) {
224 223
 			$post_data['source'] = $source->source;
225 224
 		}
226 225
 
@@ -232,77 +231,77 @@  discard block
 block discarded – undo
232 231
 		 * @param WC_Order $order
233 232
 		 * @param object $source
234 233
 		 */
235
-		return apply_filters( 'wc_stripe_generate_payment_request', $post_data, $order, $source );
234
+		return apply_filters('wc_stripe_generate_payment_request', $post_data, $order, $source);
236 235
 	}
237 236
 
238 237
 	/**
239 238
 	 * Store extra meta data for an order from a Stripe Response.
240 239
 	 */
241
-	public function process_response( $response, $order ) {
242
-		WC_Stripe_Logger::log( 'Processing response: ' . print_r( $response, true ) );
240
+	public function process_response($response, $order) {
241
+		WC_Stripe_Logger::log('Processing response: ' . print_r($response, true));
243 242
 
244 243
 		$order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
245 244
 
246
-		$captured = ( isset( $response->captured ) && $response->captured ) ? 'yes' : 'no';
245
+		$captured = (isset($response->captured) && $response->captured) ? 'yes' : 'no';
247 246
 
248 247
 		// Store charge data
249
-		WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, '_stripe_charge_captured', $captured ) : $order->update_meta_data( '_stripe_charge_captured', $captured );
248
+		WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, '_stripe_charge_captured', $captured) : $order->update_meta_data('_stripe_charge_captured', $captured);
250 249
 
251 250
 		// Store other data such as fees
252
-		if ( isset( $response->balance_transaction ) && isset( $response->balance_transaction->fee ) ) {
251
+		if (isset($response->balance_transaction) && isset($response->balance_transaction->fee)) {
253 252
 			// Fees and Net needs to both come from Stripe to be accurate as the returned
254 253
 			// values are in the local currency of the Stripe account, not from WC.
255
-			$fee = ! empty( $response->balance_transaction->fee ) ? WC_Stripe_Helper::format_balance_fee( $response->balance_transaction, 'fee' ) : 0;
256
-			$net = ! empty( $response->balance_transaction->net ) ? WC_Stripe_Helper::format_balance_fee( $response->balance_transaction, 'net' ) : 0;
257
-			WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, self::META_NAME_FEE, $fee ) : $order->update_meta_data( self::META_NAME_FEE, $fee );
258
-			WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, self::META_NAME_NET, $net ) : $order->update_meta_data( self::META_NAME_NET, $net );
254
+			$fee = ! empty($response->balance_transaction->fee) ? WC_Stripe_Helper::format_balance_fee($response->balance_transaction, 'fee') : 0;
255
+			$net = ! empty($response->balance_transaction->net) ? WC_Stripe_Helper::format_balance_fee($response->balance_transaction, 'net') : 0;
256
+			WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, self::META_NAME_FEE, $fee) : $order->update_meta_data(self::META_NAME_FEE, $fee);
257
+			WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, self::META_NAME_NET, $net) : $order->update_meta_data(self::META_NAME_NET, $net);
259 258
 		}
260 259
 
261
-		if ( 'yes' === $captured ) {
260
+		if ('yes' === $captured) {
262 261
 			/**
263 262
 			 * Charge can be captured but in a pending state. Payment methods
264 263
 			 * that are asynchronous may take couple days to clear. Webhook will
265 264
 			 * take care of the status changes.
266 265
 			 */
267
-			if ( 'pending' === $response->status ) {
268
-				if ( ! wc_string_to_bool( get_post_meta( $order_id, '_order_stock_reduced', true ) ) ) {
269
-					WC_Stripe_Helper::is_pre_30() ? $order->reduce_order_stock() : wc_reduce_stock_levels( $order_id );
266
+			if ('pending' === $response->status) {
267
+				if ( ! wc_string_to_bool(get_post_meta($order_id, '_order_stock_reduced', true))) {
268
+					WC_Stripe_Helper::is_pre_30() ? $order->reduce_order_stock() : wc_reduce_stock_levels($order_id);
270 269
 				}
271 270
 
272
-				WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, '_transaction_id', $response->id ) : $order->set_transaction_id( $response->id );
271
+				WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, '_transaction_id', $response->id) : $order->set_transaction_id($response->id);
273 272
 				/* translators: transaction id */
274
-				$order->update_status( 'on-hold', sprintf( __( 'Stripe charge awaiting payment: %s.', 'woocommerce-gateway-stripe' ), $response->id ) );
273
+				$order->update_status('on-hold', sprintf(__('Stripe charge awaiting payment: %s.', 'woocommerce-gateway-stripe'), $response->id));
275 274
 			}
276 275
 
277
-			if ( 'succeeded' === $response->status ) {
278
-				$order->payment_complete( $response->id );
276
+			if ('succeeded' === $response->status) {
277
+				$order->payment_complete($response->id);
279 278
 
280 279
 				/* translators: transaction id */
281
-				$message = sprintf( __( 'Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe' ), $response->id );
282
-				$order->add_order_note( $message );
280
+				$message = sprintf(__('Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe'), $response->id);
281
+				$order->add_order_note($message);
283 282
 			}
284 283
 
285
-			if ( 'failed' === $response->status ) {
286
-				$localized_message = __( 'Payment processing failed. Please retry.', 'woocommerce-gateway-stripe' );
287
-				$order->add_order_note( $localized_message );
288
-				throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message );
284
+			if ('failed' === $response->status) {
285
+				$localized_message = __('Payment processing failed. Please retry.', 'woocommerce-gateway-stripe');
286
+				$order->add_order_note($localized_message);
287
+				throw new WC_Stripe_Exception(print_r($response, true), $localized_message);
289 288
 			}
290 289
 		} else {
291
-			WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, '_transaction_id', $response->id ) : $order->set_transaction_id( $response->id );
290
+			WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, '_transaction_id', $response->id) : $order->set_transaction_id($response->id);
292 291
 
293
-			if ( $order->has_status( array( 'pending', 'failed' ) ) ) {
294
-				WC_Stripe_Helper::is_pre_30() ? $order->reduce_order_stock() : wc_reduce_stock_levels( $order_id );
292
+			if ($order->has_status(array('pending', 'failed'))) {
293
+				WC_Stripe_Helper::is_pre_30() ? $order->reduce_order_stock() : wc_reduce_stock_levels($order_id);
295 294
 			}
296 295
 
297 296
 			/* translators: transaction id */
298
-			$order->update_status( 'on-hold', sprintf( __( 'Stripe charge authorized (Charge ID: %s). Process order to take payment, or cancel to remove the pre-authorization.', 'woocommerce-gateway-stripe' ), $response->id ) );
297
+			$order->update_status('on-hold', sprintf(__('Stripe charge authorized (Charge ID: %s). Process order to take payment, or cancel to remove the pre-authorization.', 'woocommerce-gateway-stripe'), $response->id));
299 298
 		}
300 299
 
301
-		if ( is_callable( array( $order, 'save' ) ) ) {
300
+		if (is_callable(array($order, 'save'))) {
302 301
 			$order->save();
303 302
 		}
304 303
 
305
-		do_action( 'wc_gateway_stripe_process_response', $response, $order );
304
+		do_action('wc_gateway_stripe_process_response', $response, $order);
306 305
 
307 306
 		return $response;
308 307
 	}
@@ -315,10 +314,10 @@  discard block
 block discarded – undo
315 314
 	 * @param int $order_id
316 315
 	 * @return null
317 316
 	 */
318
-	public function send_failed_order_email( $order_id ) {
317
+	public function send_failed_order_email($order_id) {
319 318
 		$emails = WC()->mailer()->get_emails();
320
-		if ( ! empty( $emails ) && ! empty( $order_id ) ) {
321
-			$emails['WC_Email_Failed_Order']->trigger( $order_id );
319
+		if ( ! empty($emails) && ! empty($order_id)) {
320
+			$emails['WC_Email_Failed_Order']->trigger($order_id);
322 321
 		}
323 322
 	}
324 323
 
@@ -330,7 +329,7 @@  discard block
 block discarded – undo
330 329
 	 * @param object $order
331 330
 	 * @return object $details
332 331
 	 */
333
-	public function get_owner_details( $order ) {
332
+	public function get_owner_details($order) {
334 333
 		$billing_first_name = WC_Stripe_Helper::is_pre_30() ? $order->billing_first_name : $order->get_billing_first_name();
335 334
 		$billing_last_name  = WC_Stripe_Helper::is_pre_30() ? $order->billing_last_name : $order->get_billing_last_name();
336 335
 
@@ -341,8 +340,8 @@  discard block
 block discarded – undo
341 340
 
342 341
 		$phone                             = WC_Stripe_Helper::is_pre_30() ? $order->billing_phone : $order->get_billing_phone();
343 342
 
344
-		if ( ! empty( $phone ) ) {
345
-			$details['phone']              = $phone;
343
+		if ( ! empty($phone)) {
344
+			$details['phone'] = $phone;
346 345
 		}
347 346
 
348 347
 		$details['address']['line1']       = WC_Stripe_Helper::is_pre_30() ? $order->billing_address_1 : $order->get_billing_address_1();
@@ -352,7 +351,7 @@  discard block
 block discarded – undo
352 351
 		$details['address']['postal_code'] = WC_Stripe_Helper::is_pre_30() ? $order->billing_postcode : $order->get_billing_postcode();
353 352
 		$details['address']['country']     = WC_Stripe_Helper::is_pre_30() ? $order->billing_country : $order->get_billing_country();
354 353
 
355
-		return (object) apply_filters( 'wc_stripe_owner_details', $details, $order );
354
+		return (object) apply_filters('wc_stripe_owner_details', $details, $order);
356 355
 	}
357 356
 
358 357
 	/**
@@ -361,16 +360,16 @@  discard block
 block discarded – undo
361 360
 	 * @since 4.0.3
362 361
 	 */
363 362
 	public function get_source_object() {
364
-		$source = ! empty( $_POST['stripe_source'] ) ? wc_clean( $_POST['stripe_source'] ) : '';
363
+		$source = ! empty($_POST['stripe_source']) ? wc_clean($_POST['stripe_source']) : '';
365 364
 
366
-		if ( empty( $source ) ) {
365
+		if (empty($source)) {
367 366
 			return '';
368 367
 		}
369 368
 
370
-		$source_object = WC_Stripe_API::retrieve( 'sources/' . $source );
369
+		$source_object = WC_Stripe_API::retrieve('sources/' . $source);
371 370
 
372
-		if ( ! empty( $source_object->error ) ) {
373
-			throw new WC_Stripe_Exception( print_r( $source_object, true ), $source_object->error->message );
371
+		if ( ! empty($source_object->error)) {
372
+			throw new WC_Stripe_Exception(print_r($source_object, true), $source_object->error->message);
374 373
 		}
375 374
 
376 375
 		return $source_object;
@@ -383,11 +382,11 @@  discard block
 block discarded – undo
383 382
 	 * @param object $source_object
384 383
 	 * @return bool
385 384
 	 */
386
-	public function is_3ds_required( $source_object ) {
385
+	public function is_3ds_required($source_object) {
387 386
 		return (
388
-			$source_object && ! empty( $source_object->card ) ) &&
389
-			( 'card' === $source_object->type && 'required' === $source_object->card->three_d_secure ||
390
-			( $this->three_d_secure && 'optional' === $source_object->card->three_d_secure )
387
+			$source_object && ! empty($source_object->card) ) &&
388
+			('card' === $source_object->type && 'required' === $source_object->card->three_d_secure ||
389
+			($this->three_d_secure && 'optional' === $source_object->card->three_d_secure)
391 390
 		);
392 391
 	}
393 392
 
@@ -398,8 +397,8 @@  discard block
 block discarded – undo
398 397
 	 * @param object $source_object
399 398
 	 * @return bool
400 399
 	 */
401
-	public function is_3ds_card( $source_object ) {
402
-		return ( $source_object && 'three_d_secure' === $source_object->type );
400
+	public function is_3ds_card($source_object) {
401
+		return ($source_object && 'three_d_secure' === $source_object->type);
403 402
 	}
404 403
 
405 404
 	/**
@@ -412,22 +411,22 @@  discard block
 block discarded – undo
412 411
 	 * @param string $return_url
413 412
 	 * @return mixed
414 413
 	 */
415
-	public function create_3ds_source( $order, $source_object, $return_url = '' ) {
414
+	public function create_3ds_source($order, $source_object, $return_url = '') {
416 415
 		$currency                    = WC_Stripe_Helper::is_pre_30() ? $order->get_order_currency() : $order->get_currency();
417 416
 		$order_id                    = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
418
-		$return_url                  = empty( $return_url ) ? $this->get_stripe_return_url( $order ) : $return_url;
417
+		$return_url                  = empty($return_url) ? $this->get_stripe_return_url($order) : $return_url;
419 418
 
420 419
 		$post_data                   = array();
421
-		$post_data['amount']         = WC_Stripe_Helper::get_stripe_amount( $order->get_total(), $currency );
422
-		$post_data['currency']       = strtolower( $currency );
420
+		$post_data['amount']         = WC_Stripe_Helper::get_stripe_amount($order->get_total(), $currency);
421
+		$post_data['currency']       = strtolower($currency);
423 422
 		$post_data['type']           = 'three_d_secure';
424
-		$post_data['owner']          = $this->get_owner_details( $order );
425
-		$post_data['three_d_secure'] = array( 'card' => $source_object->id );
426
-		$post_data['redirect']       = array( 'return_url' => $return_url );
423
+		$post_data['owner']          = $this->get_owner_details($order);
424
+		$post_data['three_d_secure'] = array('card' => $source_object->id);
425
+		$post_data['redirect']       = array('return_url' => $return_url);
427 426
 
428
-		WC_Stripe_Logger::log( 'Info: Begin creating 3DS source...' );
427
+		WC_Stripe_Logger::log('Info: Begin creating 3DS source...');
429 428
 
430
-		return WC_Stripe_API::request( apply_filters( 'wc_stripe_3ds_source', $post_data, $order ), 'sources' );
429
+		return WC_Stripe_API::request(apply_filters('wc_stripe_3ds_source', $post_data, $order), 'sources');
431 430
 	}
432 431
 
433 432
 	/**
@@ -444,54 +443,54 @@  discard block
 block discarded – undo
444 443
 	 * @throws Exception When card was not added or for and invalid card.
445 444
 	 * @return object
446 445
 	 */
447
-	public function prepare_source( $source_object = '', $user_id, $force_save_source = false ) {
448
-		$customer           = new WC_Stripe_Customer( $user_id );
446
+	public function prepare_source($source_object = '', $user_id, $force_save_source = false) {
447
+		$customer           = new WC_Stripe_Customer($user_id);
449 448
 		$set_customer       = true;
450
-		$force_save_source  = apply_filters( 'wc_stripe_force_save_source', $force_save_source, $customer );
449
+		$force_save_source  = apply_filters('wc_stripe_force_save_source', $force_save_source, $customer);
451 450
 		$source_id          = '';
452 451
 		$wc_token_id        = false;
453
-		$payment_method     = isset( $_POST['payment_method'] ) ? wc_clean( $_POST['payment_method'] ) : 'stripe';
452
+		$payment_method     = isset($_POST['payment_method']) ? wc_clean($_POST['payment_method']) : 'stripe';
454 453
 
455 454
 		// New CC info was entered and we have a new source to process.
456
-		if ( ! empty( $source_object ) ) {
455
+		if ( ! empty($source_object)) {
457 456
 			$source_id = $source_object->id;
458 457
 
459 458
 			// This checks to see if customer opted to save the payment method to file.
460
-			$maybe_saved_card = isset( $_POST[ 'wc-' . $payment_method . '-new-payment-method' ] ) && ! empty( $_POST[ 'wc-' . $payment_method . '-new-payment-method' ] );
459
+			$maybe_saved_card = isset($_POST['wc-' . $payment_method . '-new-payment-method']) && ! empty($_POST['wc-' . $payment_method . '-new-payment-method']);
461 460
 
462 461
 			/**
463 462
 			 * This is true if the user wants to store the card to their account.
464 463
 			 * Criteria to save to file is they are logged in, they opted to save or product requirements and the source is
465 464
 			 * actually reusable. Either that or force_save_source is true.
466 465
 			 */
467
-			if ( ( $user_id && $this->saved_cards && $maybe_saved_card && 'reusable' === $source_object->usage ) || $force_save_source ) {
468
-				$response = $customer->add_source( $source_object->id );
466
+			if (($user_id && $this->saved_cards && $maybe_saved_card && 'reusable' === $source_object->usage) || $force_save_source) {
467
+				$response = $customer->add_source($source_object->id);
469 468
 
470
-				if ( ! empty( $response->error ) ) {
471
-					throw new WC_Stripe_Exception( print_r( $response, true ), $response->error->message );
469
+				if ( ! empty($response->error)) {
470
+					throw new WC_Stripe_Exception(print_r($response, true), $response->error->message);
472 471
 				}
473 472
 			}
474
-		} elseif ( isset( $_POST[ 'wc-' . $payment_method . '-payment-token' ] ) && 'new' !== $_POST[ 'wc-' . $payment_method . '-payment-token' ] ) {
473
+		} elseif (isset($_POST['wc-' . $payment_method . '-payment-token']) && 'new' !== $_POST['wc-' . $payment_method . '-payment-token']) {
475 474
 			// Use an existing token, and then process the payment
476
-			$wc_token_id = wc_clean( $_POST[ 'wc-' . $payment_method . '-payment-token' ] );
477
-			$wc_token    = WC_Payment_Tokens::get( $wc_token_id );
475
+			$wc_token_id = wc_clean($_POST['wc-' . $payment_method . '-payment-token']);
476
+			$wc_token    = WC_Payment_Tokens::get($wc_token_id);
478 477
 
479
-			if ( ! $wc_token || $wc_token->get_user_id() !== get_current_user_id() ) {
480
-				WC()->session->set( 'refresh_totals', true );
481
-				throw new WC_Stripe_Exception( 'Invalid payment method', __( 'Invalid payment method. Please input a new card number.', 'woocommerce-gateway-stripe' ) );
478
+			if ( ! $wc_token || $wc_token->get_user_id() !== get_current_user_id()) {
479
+				WC()->session->set('refresh_totals', true);
480
+				throw new WC_Stripe_Exception('Invalid payment method', __('Invalid payment method. Please input a new card number.', 'woocommerce-gateway-stripe'));
482 481
 			}
483 482
 
484 483
 			$source_id = $wc_token->get_token();
485
-		} elseif ( isset( $_POST['stripe_token'] ) && 'new' !== $_POST['stripe_token'] ) {
486
-			$stripe_token     = wc_clean( $_POST['stripe_token'] );
487
-			$maybe_saved_card = isset( $_POST[ 'wc-' . $payment_method . '-new-payment-method' ] ) && ! empty( $_POST[ 'wc-' . $payment_method . '-new-payment-method' ] );
484
+		} elseif (isset($_POST['stripe_token']) && 'new' !== $_POST['stripe_token']) {
485
+			$stripe_token     = wc_clean($_POST['stripe_token']);
486
+			$maybe_saved_card = isset($_POST['wc-' . $payment_method . '-new-payment-method']) && ! empty($_POST['wc-' . $payment_method . '-new-payment-method']);
488 487
 
489 488
 			// This is true if the user wants to store the card to their account.
490
-			if ( ( $user_id && $this->saved_cards && $maybe_saved_card ) || $force_save_source ) {
491
-				$response = $customer->add_source( $stripe_token );
489
+			if (($user_id && $this->saved_cards && $maybe_saved_card) || $force_save_source) {
490
+				$response = $customer->add_source($stripe_token);
492 491
 
493
-				if ( ! empty( $response->error ) ) {
494
-					throw new WC_Stripe_Exception( print_r( $response, true ), $response->error->message );
492
+				if ( ! empty($response->error)) {
493
+					throw new WC_Stripe_Exception(print_r($response, true), $response->error->message);
495 494
 				}
496 495
 			} else {
497 496
 				$set_customer = false;
@@ -499,7 +498,7 @@  discard block
 block discarded – undo
499 498
 			}
500 499
 		}
501 500
 
502
-		if ( ! $set_customer ) {
501
+		if ( ! $set_customer) {
503 502
 			$customer_id = false;
504 503
 		} else {
505 504
 			$customer_id = $customer->get_id() ? $customer->get_id() : false;
@@ -525,37 +524,37 @@  discard block
 block discarded – undo
525 524
 	 * @param object $order
526 525
 	 * @return object
527 526
 	 */
528
-	public function prepare_order_source( $order = null ) {
527
+	public function prepare_order_source($order = null) {
529 528
 		$stripe_customer = new WC_Stripe_Customer();
530 529
 		$stripe_source   = false;
531 530
 		$token_id        = false;
532 531
 
533
-		if ( $order ) {
532
+		if ($order) {
534 533
 			$order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
535 534
 
536
-			$stripe_customer_id = get_post_meta( $order_id, '_stripe_customer_id', true );
535
+			$stripe_customer_id = get_post_meta($order_id, '_stripe_customer_id', true);
537 536
 
538
-			if ( $stripe_customer_id ) {
539
-				$stripe_customer->set_id( $stripe_customer_id );
537
+			if ($stripe_customer_id) {
538
+				$stripe_customer->set_id($stripe_customer_id);
540 539
 			}
541 540
 
542
-			$source_id = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_stripe_source_id', true ) : $order->get_meta( '_stripe_source_id', true );
541
+			$source_id = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_stripe_source_id', true) : $order->get_meta('_stripe_source_id', true);
543 542
 
544 543
 			// Since 4.0.0, we changed card to source so we need to account for that.
545
-			if ( empty( $source_id ) ) {
546
-				$source_id = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_stripe_card_id', true ) : $order->get_meta( '_stripe_card_id', true );
544
+			if (empty($source_id)) {
545
+				$source_id = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_stripe_card_id', true) : $order->get_meta('_stripe_card_id', true);
547 546
 
548 547
 				// Take this opportunity to update the key name.
549
-				WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, '_stripe_source_id', $source_id ) : $order->update_meta_data( '_stripe_source_id', $source_id );
548
+				WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, '_stripe_source_id', $source_id) : $order->update_meta_data('_stripe_source_id', $source_id);
550 549
 
551
-				if ( is_callable( array( $order, 'save' ) ) ) {
550
+				if (is_callable(array($order, 'save'))) {
552 551
 					$order->save();
553 552
 				}
554 553
 			}
555 554
 
556
-			if ( $source_id ) {
555
+			if ($source_id) {
557 556
 				$stripe_source = $source_id;
558
-			} elseif ( apply_filters( 'wc_stripe_use_default_customer_source', true ) ) {
557
+			} elseif (apply_filters('wc_stripe_use_default_customer_source', true)) {
559 558
 				/*
560 559
 				 * We can attempt to charge the customer's default source
561 560
 				 * by sending empty source id.
@@ -579,27 +578,27 @@  discard block
 block discarded – undo
579 578
 	 * @param WC_Order $order For to which the source applies.
580 579
 	 * @param stdClass $source Source information.
581 580
 	 */
582
-	public function save_source_to_order( $order, $source ) {
581
+	public function save_source_to_order($order, $source) {
583 582
 		$order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
584 583
 
585 584
 		// Store source in the order.
586
-		if ( $source->customer ) {
587
-			if ( WC_Stripe_Helper::is_pre_30() ) {
588
-				update_post_meta( $order_id, '_stripe_customer_id', $source->customer );
585
+		if ($source->customer) {
586
+			if (WC_Stripe_Helper::is_pre_30()) {
587
+				update_post_meta($order_id, '_stripe_customer_id', $source->customer);
589 588
 			} else {
590
-				$order->update_meta_data( '_stripe_customer_id', $source->customer );
589
+				$order->update_meta_data('_stripe_customer_id', $source->customer);
591 590
 			}
592 591
 		}
593 592
 
594
-		if ( $source->source ) {
595
-			if ( WC_Stripe_Helper::is_pre_30() ) {
596
-				update_post_meta( $order_id, '_stripe_source_id', $source->source );
593
+		if ($source->source) {
594
+			if (WC_Stripe_Helper::is_pre_30()) {
595
+				update_post_meta($order_id, '_stripe_source_id', $source->source);
597 596
 			} else {
598
-				$order->update_meta_data( '_stripe_source_id', $source->source );
597
+				$order->update_meta_data('_stripe_source_id', $source->source);
599 598
 			}
600 599
 		}
601 600
 
602
-		if ( is_callable( array( $order, 'save' ) ) ) {
601
+		if (is_callable(array($order, 'save'))) {
603 602
 			$order->save();
604 603
 		}
605 604
 	}
@@ -613,27 +612,27 @@  discard block
 block discarded – undo
613 612
 	 * @param object $order The order object
614 613
 	 * @param int $balance_transaction_id
615 614
 	 */
616
-	public function update_fees( $order, $balance_transaction_id ) {
615
+	public function update_fees($order, $balance_transaction_id) {
617 616
 		$order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
618 617
 
619
-		$balance_transaction = WC_Stripe_API::retrieve( 'balance/history/' . $balance_transaction_id );
618
+		$balance_transaction = WC_Stripe_API::retrieve('balance/history/' . $balance_transaction_id);
620 619
 
621
-		if ( empty( $balance_transaction->error ) ) {
622
-			if ( isset( $balance_transaction ) && isset( $balance_transaction->fee ) ) {
620
+		if (empty($balance_transaction->error)) {
621
+			if (isset($balance_transaction) && isset($balance_transaction->fee)) {
623 622
 				// Fees and Net needs to both come from Stripe to be accurate as the returned
624 623
 				// values are in the local currency of the Stripe account, not from WC.
625
-				$fee = ! empty( $balance_transaction->fee ) ? WC_Stripe_Helper::format_balance_fee( $balance_transaction, 'fee' ) : 0;
626
-				$net = ! empty( $balance_transaction->net ) ? WC_Stripe_Helper::format_balance_fee( $balance_transaction, 'net' ) : 0;
624
+				$fee = ! empty($balance_transaction->fee) ? WC_Stripe_Helper::format_balance_fee($balance_transaction, 'fee') : 0;
625
+				$net = ! empty($balance_transaction->net) ? WC_Stripe_Helper::format_balance_fee($balance_transaction, 'net') : 0;
627 626
 
628
-				WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, self::META_NAME_FEE, $fee ) : $order->update_meta_data( self::META_NAME_FEE, $fee );
629
-				WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, self::META_NAME_NET, $net ) : $order->update_meta_data( self::META_NAME_NET, $net );
627
+				WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, self::META_NAME_FEE, $fee) : $order->update_meta_data(self::META_NAME_FEE, $fee);
628
+				WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, self::META_NAME_NET, $net) : $order->update_meta_data(self::META_NAME_NET, $net);
630 629
 
631
-				if ( is_callable( array( $order, 'save' ) ) ) {
630
+				if (is_callable(array($order, 'save'))) {
632 631
 					$order->save();
633 632
 				}
634 633
 			}
635 634
 		} else {
636
-			WC_Stripe_Logger::log( "Unable to update fees/net meta for order: {$order_id}" );
635
+			WC_Stripe_Logger::log("Unable to update fees/net meta for order: {$order_id}");
637 636
 		}
638 637
 	}
639 638
 
@@ -646,33 +645,33 @@  discard block
 block discarded – undo
646 645
 	 * @param  float $amount
647 646
 	 * @return bool
648 647
 	 */
649
-	public function process_refund( $order_id, $amount = null, $reason = '' ) {
650
-		$order = wc_get_order( $order_id );
648
+	public function process_refund($order_id, $amount = null, $reason = '') {
649
+		$order = wc_get_order($order_id);
651 650
 
652
-		if ( ! $order || ! $order->get_transaction_id() ) {
651
+		if ( ! $order || ! $order->get_transaction_id()) {
653 652
 			return false;
654 653
 		}
655 654
 
656 655
 		$request = array();
657 656
 
658
-		if ( WC_Stripe_Helper::is_pre_30() ) {
659
-			$order_currency = get_post_meta( $order_id, '_order_currency', true );
660
-			$captured       = get_post_meta( $order_id, '_stripe_charge_captured', true );
657
+		if (WC_Stripe_Helper::is_pre_30()) {
658
+			$order_currency = get_post_meta($order_id, '_order_currency', true);
659
+			$captured       = get_post_meta($order_id, '_stripe_charge_captured', true);
661 660
 		} else {
662 661
 			$order_currency = $order->get_currency();
663
-			$captured       = $order->get_meta( '_stripe_charge_captured', true );
662
+			$captured       = $order->get_meta('_stripe_charge_captured', true);
664 663
 		}
665 664
 
666
-		if ( ! is_null( $amount ) ) {
667
-			$request['amount'] = WC_Stripe_Helper::get_stripe_amount( $amount, $order_currency );
665
+		if ( ! is_null($amount)) {
666
+			$request['amount'] = WC_Stripe_Helper::get_stripe_amount($amount, $order_currency);
668 667
 		}
669 668
 
670 669
 		// If order is only authorized, don't pass amount.
671
-		if ( 'yes' !== $captured ) {
672
-			unset( $request['amount'] );
670
+		if ('yes' !== $captured) {
671
+			unset($request['amount']);
673 672
 		}
674 673
 
675
-		if ( $reason ) {
674
+		if ($reason) {
676 675
 			$request['metadata'] = array(
677 676
 				'reason' => $reason,
678 677
 			);
@@ -680,33 +679,33 @@  discard block
 block discarded – undo
680 679
 
681 680
 		$request['charge'] = $order->get_transaction_id();
682 681
 
683
-		WC_Stripe_Logger::log( "Info: Beginning refund for order {$order->get_transaction_id()} for the amount of {$amount}" );
682
+		WC_Stripe_Logger::log("Info: Beginning refund for order {$order->get_transaction_id()} for the amount of {$amount}");
684 683
 
685
-		$response = WC_Stripe_API::request( $request, 'refunds' );
684
+		$response = WC_Stripe_API::request($request, 'refunds');
686 685
 
687
-		if ( ! empty( $response->error ) ) {
688
-			WC_Stripe_Logger::log( 'Error: ' . $response->error->message );
686
+		if ( ! empty($response->error)) {
687
+			WC_Stripe_Logger::log('Error: ' . $response->error->message);
689 688
 
690 689
 			return $response;
691 690
 
692
-		} elseif ( ! empty( $response->id ) ) {
693
-			WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, '_stripe_refund_id', $response->id ) : $order->update_meta_data( '_stripe_refund_id', $response->id );
691
+		} elseif ( ! empty($response->id)) {
692
+			WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, '_stripe_refund_id', $response->id) : $order->update_meta_data('_stripe_refund_id', $response->id);
694 693
 
695
-			$amount = wc_price( $response->amount / 100 );
694
+			$amount = wc_price($response->amount / 100);
696 695
 
697
-			if ( in_array( strtolower( $order->get_currency() ), WC_Stripe_Helper::no_decimal_currencies() ) ) {
698
-				$amount = wc_price( $response->amount );
696
+			if (in_array(strtolower($order->get_currency()), WC_Stripe_Helper::no_decimal_currencies())) {
697
+				$amount = wc_price($response->amount);
699 698
 			}
700 699
 
701
-			if ( isset( $response->balance_transaction ) ) {
702
-				$this->update_fees( $order, $response->balance_transaction );
700
+			if (isset($response->balance_transaction)) {
701
+				$this->update_fees($order, $response->balance_transaction);
703 702
 			}
704 703
 
705 704
 			/* translators: 1) dollar amount 2) transaction id 3) refund message */
706
-			$refund_message = ( isset( $captured ) && 'yes' === $captured ) ? sprintf( __( 'Refunded %1$s - Refund ID: %2$s - Reason: %3$s', 'woocommerce-gateway-stripe' ), $amount, $response->id, $reason ) : __( 'Pre-Authorization Released', 'woocommerce-gateway-stripe' );
705
+			$refund_message = (isset($captured) && 'yes' === $captured) ? sprintf(__('Refunded %1$s - Refund ID: %2$s - Reason: %3$s', 'woocommerce-gateway-stripe'), $amount, $response->id, $reason) : __('Pre-Authorization Released', 'woocommerce-gateway-stripe');
707 706
 
708
-			$order->add_order_note( $refund_message );
709
-			WC_Stripe_Logger::log( 'Success: ' . html_entity_decode( strip_tags( $refund_message ) ) );
707
+			$order->add_order_note($refund_message);
708
+			WC_Stripe_Logger::log('Success: ' . html_entity_decode(strip_tags($refund_message)));
710 709
 
711 710
 			return true;
712 711
 		}
@@ -721,44 +720,44 @@  discard block
 block discarded – undo
721 720
 	 */
722 721
 	public function add_payment_method() {
723 722
 		$error     = false;
724
-		$error_msg = __( 'There was a problem adding the card.', 'woocommerce-gateway-stripe' );
723
+		$error_msg = __('There was a problem adding the card.', 'woocommerce-gateway-stripe');
725 724
 		$source_id = '';
726 725
 
727
-		if ( empty( $_POST['stripe_source'] ) && empty( $_POST['stripe_token'] ) || ! is_user_logged_in() ) {
726
+		if (empty($_POST['stripe_source']) && empty($_POST['stripe_token']) || ! is_user_logged_in()) {
728 727
 			$error = true;
729 728
 		}
730 729
 
731
-		$stripe_customer = new WC_Stripe_Customer( get_current_user_id() );
730
+		$stripe_customer = new WC_Stripe_Customer(get_current_user_id());
732 731
 
733
-		$source = ! empty( $_POST['stripe_source'] ) ? wc_clean( $_POST['stripe_source'] ) : '';
732
+		$source = ! empty($_POST['stripe_source']) ? wc_clean($_POST['stripe_source']) : '';
734 733
 
735
-		$source_object = WC_Stripe_API::retrieve( 'sources/' . $source );
734
+		$source_object = WC_Stripe_API::retrieve('sources/' . $source);
736 735
 
737
-		if ( isset( $source_object ) ) {
738
-			if ( ! empty( $source_object->error ) ) {
736
+		if (isset($source_object)) {
737
+			if ( ! empty($source_object->error)) {
739 738
 				$error = true;
740 739
 			}
741 740
 
742 741
 			$source_id = $source_object->id;
743
-		} elseif ( isset( $_POST['stripe_token'] ) ) {
744
-			$source_id = wc_clean( $_POST['stripe_token'] );
742
+		} elseif (isset($_POST['stripe_token'])) {
743
+			$source_id = wc_clean($_POST['stripe_token']);
745 744
 		}
746 745
 
747
-		$response = $stripe_customer->add_source( $source_id );
746
+		$response = $stripe_customer->add_source($source_id);
748 747
 
749
-		if ( ! $response || is_wp_error( $response ) || ! empty( $response->error ) ) {
748
+		if ( ! $response || is_wp_error($response) || ! empty($response->error)) {
750 749
 			$error = true;
751 750
 		}
752 751
 
753
-		if ( $error ) {
754
-			wc_add_notice( $error_msg, 'error' );
755
-			WC_Stripe_Logger::log( 'Add payment method Error: ' . $error_msg );
752
+		if ($error) {
753
+			wc_add_notice($error_msg, 'error');
754
+			WC_Stripe_Logger::log('Add payment method Error: ' . $error_msg);
756 755
 			return;
757 756
 		}
758 757
 
759 758
 		return array(
760 759
 			'result'   => 'success',
761
-			'redirect' => wc_get_endpoint_url( 'payment-methods' ),
760
+			'redirect' => wc_get_endpoint_url('payment-methods'),
762 761
 		);
763 762
 	}
764 763
 }
Please login to merge, or discard this patch.