Completed
Push — master ( 717fdd...29d315 )
by Roy
02:50
created
includes/abstracts/abstract-wc-stripe-payment-gateway.php 1 patch
Spacing   +223 added lines, -224 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
 
@@ -21,7 +21,7 @@  discard block
 block discarded – undo
21 21
 	 * @since 4.0.5
22 22
 	 * @param array $error
23 23
 	 */
24
-	public function is_retryable_error( $error ) {
24
+	public function is_retryable_error($error) {
25 25
 		return (
26 26
 			'invalid_request_error' === $error->type ||
27 27
 			'idempotency_error' === $error->type ||
@@ -35,11 +35,11 @@  discard block
 block discarded – undo
35 35
 	 * Check if this gateway is enabled
36 36
 	 */
37 37
 	public function is_available() {
38
-		if ( 'yes' === $this->enabled ) {
39
-			if ( ! $this->testmode && is_checkout() && ! is_ssl() ) {
38
+		if ('yes' === $this->enabled) {
39
+			if ( ! $this->testmode && is_checkout() && ! is_ssl()) {
40 40
 				return false;
41 41
 			}
42
-			if ( ! $this->secret_key || ! $this->publishable_key ) {
42
+			if ( ! $this->secret_key || ! $this->publishable_key) {
43 43
 				return false;
44 44
 			}
45 45
 			return true;
@@ -54,8 +54,8 @@  discard block
 block discarded – undo
54 54
 	 * @since 4.0.0
55 55
 	 * @version 4.0.0
56 56
 	 */
57
-	public function add_admin_notice( $slug, $class, $message ) {
58
-		$this->notices[ $slug ] = array(
57
+	public function add_admin_notice($slug, $class, $message) {
58
+		$this->notices[$slug] = array(
59 59
 			'class'   => $class,
60 60
 			'message' => $message,
61 61
 		);
@@ -68,8 +68,8 @@  discard block
 block discarded – undo
68 68
 	 * @version 4.0.0
69 69
 	 */
70 70
 	public function remove_admin_notice() {
71
-		if ( did_action( 'woocommerce_update_options' ) ) {
72
-			remove_action( 'admin_notices', array( $this, 'check_environment' ) );
71
+		if (did_action('woocommerce_update_options')) {
72
+			remove_action('admin_notices', array($this, 'check_environment'));
73 73
 		}
74 74
 	}
75 75
 
@@ -81,7 +81,7 @@  discard block
 block discarded – undo
81 81
 	 * @return array
82 82
 	 */
83 83
 	public function payment_icons() {
84
-		return apply_filters( 'wc_stripe_payment_icons', array(
84
+		return apply_filters('wc_stripe_payment_icons', array(
85 85
 			'visa'       => '<i class="stripe-pf stripe-pf-visa stripe-pf-right" alt="Visa" aria-hidden="true"></i>',
86 86
 			'amex'       => '<i class="stripe-pf stripe-pf-american-express stripe-pf-right" alt="Amex" aria-hidden="true"></i>',
87 87
 			'mastercard' => '<i class="stripe-pf stripe-pf-mastercard stripe-pf-right" alt="Mastercard" aria-hidden="true"></i>',
@@ -98,7 +98,7 @@  discard block
 block discarded – undo
98 98
 			'eps'        => '<i class="stripe-pf stripe-pf-eps stripe-pf-right" alt="EPS" aria-hidden="true"></i>',
99 99
 			'sofort'     => '<i class="stripe-pf stripe-pf-sofort stripe-pf-right" alt="SOFORT" aria-hidden="true"></i>',
100 100
 			'sepa'       => '<i class="stripe-pf stripe-pf-sepa stripe-pf-right" alt="SEPA" aria-hidden="true"></i>',
101
-		) );
101
+		));
102 102
 	}
103 103
 
104 104
 	/**
@@ -109,10 +109,10 @@  discard block
 block discarded – undo
109 109
 	 * @version 4.0.0
110 110
 	 * @param object $order
111 111
 	 */
112
-	public function validate_minimum_order_amount( $order ) {
113
-		if ( $order->get_total() * 100 < WC_Stripe_Helper::get_minimum_amount() ) {
112
+	public function validate_minimum_order_amount($order) {
113
+		if ($order->get_total() * 100 < WC_Stripe_Helper::get_minimum_amount()) {
114 114
 			/* translators: 1) dollar amount */
115
-			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 ) ) );
115
+			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)));
116 116
 		}
117 117
 	}
118 118
 
@@ -122,14 +122,14 @@  discard block
 block discarded – undo
122 122
 	 * @since 4.0.0
123 123
 	 * @version 4.0.0
124 124
 	 */
125
-	public function get_transaction_url( $order ) {
126
-		if ( $this->testmode ) {
125
+	public function get_transaction_url($order) {
126
+		if ($this->testmode) {
127 127
 			$this->view_transaction_url = 'https://dashboard.stripe.com/test/payments/%s';
128 128
 		} else {
129 129
 			$this->view_transaction_url = 'https://dashboard.stripe.com/payments/%s';
130 130
 		}
131 131
 
132
-		return parent::get_transaction_url( $order );
132
+		return parent::get_transaction_url($order);
133 133
 	}
134 134
 
135 135
 	/**
@@ -138,15 +138,15 @@  discard block
 block discarded – undo
138 138
 	 * @since 4.0.0
139 139
 	 * @version 4.0.0
140 140
 	 */
141
-	public function get_stripe_customer_id( $order ) {
142
-		$customer = get_user_meta( WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id(), '_stripe_customer_id', true );
141
+	public function get_stripe_customer_id($order) {
142
+		$customer = get_user_meta(WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id(), '_stripe_customer_id', true);
143 143
 
144
-		if ( empty( $customer ) ) {
144
+		if (empty($customer)) {
145 145
 			// Try to get it via the order.
146
-			if ( WC_Stripe_Helper::is_pre_30() ) {
147
-				return get_post_meta( $order->id, '_stripe_customer_id', true );
146
+			if (WC_Stripe_Helper::is_pre_30()) {
147
+				return get_post_meta($order->id, '_stripe_customer_id', true);
148 148
 			} else {
149
-				return $order->get_meta( '_stripe_customer_id', true );
149
+				return $order->get_meta('_stripe_customer_id', true);
150 150
 			}
151 151
 		} else {
152 152
 			return $customer;
@@ -163,9 +163,9 @@  discard block
 block discarded – undo
163 163
 	 * @param object $order
164 164
 	 * @param int $id Stripe session id.
165 165
 	 */
166
-	public function get_stripe_return_url( $order = null, $id = null ) {
167
-		if ( is_object( $order ) ) {
168
-			if ( empty( $id ) ) {
166
+	public function get_stripe_return_url($order = null, $id = null) {
167
+		if (is_object($order)) {
168
+			if (empty($id)) {
169 169
 				$id = uniqid();
170 170
 			}
171 171
 
@@ -176,10 +176,10 @@  discard block
 block discarded – undo
176 176
 				'order_id'       => $order_id,
177 177
 			);
178 178
 
179
-			return esc_url_raw( add_query_arg( $args, $this->get_return_url( $order ) ) );
179
+			return esc_url_raw(add_query_arg($args, $this->get_return_url($order)));
180 180
 		}
181 181
 
182
-		return esc_url_raw( add_query_arg( array( 'utm_nooverride' => '1' ), $this->get_return_url() ) );
182
+		return esc_url_raw(add_query_arg(array('utm_nooverride' => '1'), $this->get_return_url()));
183 183
 	}
184 184
 
185 185
 	/**
@@ -187,8 +187,8 @@  discard block
 block discarded – undo
187 187
 	 * @param  int  $order_id
188 188
 	 * @return boolean
189 189
 	 */
190
-	public function has_subscription( $order_id ) {
191
-		return ( function_exists( 'wcs_order_contains_subscription' ) && ( wcs_order_contains_subscription( $order_id ) || wcs_is_subscription( $order_id ) || wcs_order_contains_renewal( $order_id ) ) );
190
+	public function has_subscription($order_id) {
191
+		return (function_exists('wcs_order_contains_subscription') && (wcs_order_contains_subscription($order_id) || wcs_is_subscription($order_id) || wcs_order_contains_renewal($order_id)));
192 192
 	}
193 193
 
194 194
 	/**
@@ -200,34 +200,33 @@  discard block
 block discarded – undo
200 200
 	 * @param  object $prepared_source
201 201
 	 * @return array()
202 202
 	 */
203
-	public function generate_payment_request( $order, $prepared_source ) {
204
-		$settings                          = get_option( 'woocommerce_stripe_settings', array() );
205
-		$statement_descriptor              = ! empty( $settings['statement_descriptor'] ) ? str_replace( "'", '', $settings['statement_descriptor'] ) : '';
206
-		$capture                           = ! empty( $settings['capture'] ) && 'yes' === $settings['capture'] ? true : false;
203
+	public function generate_payment_request($order, $prepared_source) {
204
+		$settings                          = get_option('woocommerce_stripe_settings', array());
205
+		$statement_descriptor              = ! empty($settings['statement_descriptor']) ? str_replace("'", '', $settings['statement_descriptor']) : '';
206
+		$capture                           = ! empty($settings['capture']) && 'yes' === $settings['capture'] ? true : false;
207 207
 		$post_data                         = array();
208
-		$post_data['currency']             = strtolower( WC_Stripe_Helper::is_pre_30() ? $order->get_order_currency() : $order->get_currency() );
209
-		$post_data['amount']               = WC_Stripe_Helper::get_stripe_amount( $order->get_total(), $post_data['currency'] );
208
+		$post_data['currency']             = strtolower(WC_Stripe_Helper::is_pre_30() ? $order->get_order_currency() : $order->get_currency());
209
+		$post_data['amount']               = WC_Stripe_Helper::get_stripe_amount($order->get_total(), $post_data['currency']);
210 210
 		/* translators: 1) blog name 2) order number */
211
-		$post_data['description']          = sprintf( __( '%1$s - Order %2$s', 'woocommerce-gateway-stripe' ), wp_specialchars_decode( get_bloginfo( 'name' ), ENT_QUOTES ), $order->get_order_number() );
211
+		$post_data['description']          = sprintf(__('%1$s - Order %2$s', 'woocommerce-gateway-stripe'), wp_specialchars_decode(get_bloginfo('name'), ENT_QUOTES), $order->get_order_number());
212 212
 		$billing_email      = WC_Stripe_Helper::is_pre_30() ? $order->billing_email : $order->get_billing_email();
213 213
 		$billing_first_name = WC_Stripe_Helper::is_pre_30() ? $order->billing_first_name : $order->get_billing_first_name();
214 214
 		$billing_last_name  = WC_Stripe_Helper::is_pre_30() ? $order->billing_last_name : $order->get_billing_last_name();
215 215
 
216
-		if ( ! empty( $billing_email ) && apply_filters( 'wc_stripe_send_stripe_receipt', false ) ) {
216
+		if ( ! empty($billing_email) && apply_filters('wc_stripe_send_stripe_receipt', false)) {
217 217
 			$post_data['receipt_email'] = $billing_email;
218 218
 		}
219 219
 
220
-		switch ( WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method() ) {
221
-			case 'stripe':
222
-				if ( ! empty( $statement_descriptor ) ) {
223
-					$post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor( $statement_descriptor );
220
+		switch (WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method()) {
221
+			case 'stripe' : if ( ! empty($statement_descriptor)) {
222
+					$post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor($statement_descriptor);
224 223
 				}
225 224
 
226 225
 				$post_data['capture'] = $capture ? 'true' : 'false';
227 226
 				break;
228 227
 			case 'stripe_sepa':
229
-				if ( ! empty( $statement_descriptor ) ) {
230
-					$post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor( $statement_descriptor );
228
+				if ( ! empty($statement_descriptor)) {
229
+					$post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor($statement_descriptor);
231 230
 				}
232 231
 				break;
233 232
 		}
@@ -235,25 +234,25 @@  discard block
 block discarded – undo
235 234
 		$post_data['expand[]'] = 'balance_transaction';
236 235
 
237 236
 		$metadata = array(
238
-			__( 'customer_name', 'woocommerce-gateway-stripe' ) => sanitize_text_field( $billing_first_name ) . ' ' . sanitize_text_field( $billing_last_name ),
239
-			__( 'customer_email', 'woocommerce-gateway-stripe' ) => sanitize_email( $billing_email ),
237
+			__('customer_name', 'woocommerce-gateway-stripe') => sanitize_text_field($billing_first_name) . ' ' . sanitize_text_field($billing_last_name),
238
+			__('customer_email', 'woocommerce-gateway-stripe') => sanitize_email($billing_email),
240 239
 			'order_id' => WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(),
241 240
 		);
242 241
 
243
-		if ( $this->has_subscription( WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id() ) ) {
242
+		if ($this->has_subscription(WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id())) {
244 243
 			$metadata += array(
245 244
 				'payment_type' => 'recurring',
246
-				'site_url'     => esc_url( get_site_url() ),
245
+				'site_url'     => esc_url(get_site_url()),
247 246
 			);
248 247
 		}
249 248
 
250
-		$post_data['metadata'] = apply_filters( 'wc_stripe_payment_metadata', $metadata, $order, $prepared_source );
249
+		$post_data['metadata'] = apply_filters('wc_stripe_payment_metadata', $metadata, $order, $prepared_source);
251 250
 
252
-		if ( $prepared_source->customer ) {
251
+		if ($prepared_source->customer) {
253 252
 			$post_data['customer'] = $prepared_source->customer;
254 253
 		}
255 254
 
256
-		if ( $prepared_source->source ) {
255
+		if ($prepared_source->source) {
257 256
 			$post_data['source'] = $prepared_source->source;
258 257
 		}
259 258
 
@@ -265,79 +264,79 @@  discard block
 block discarded – undo
265 264
 		 * @param WC_Order $order
266 265
 		 * @param object $source
267 266
 		 */
268
-		return apply_filters( 'wc_stripe_generate_payment_request', $post_data, $order, $prepared_source );
267
+		return apply_filters('wc_stripe_generate_payment_request', $post_data, $order, $prepared_source);
269 268
 	}
270 269
 
271 270
 	/**
272 271
 	 * Store extra meta data for an order from a Stripe Response.
273 272
 	 */
274
-	public function process_response( $response, $order ) {
275
-		WC_Stripe_Logger::log( 'Processing response: ' . print_r( $response, true ) );
273
+	public function process_response($response, $order) {
274
+		WC_Stripe_Logger::log('Processing response: ' . print_r($response, true));
276 275
 
277 276
 		$order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
278 277
 
279
-		$captured = ( isset( $response->captured ) && $response->captured ) ? 'yes' : 'no';
278
+		$captured = (isset($response->captured) && $response->captured) ? 'yes' : 'no';
280 279
 
281 280
 		// Store charge data.
282
-		WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, '_stripe_charge_captured', $captured ) : $order->update_meta_data( '_stripe_charge_captured', $captured );
281
+		WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, '_stripe_charge_captured', $captured) : $order->update_meta_data('_stripe_charge_captured', $captured);
283 282
 
284 283
 		// Store other data such as fees.
285
-		if ( isset( $response->balance_transaction ) && isset( $response->balance_transaction->fee ) ) {
284
+		if (isset($response->balance_transaction) && isset($response->balance_transaction->fee)) {
286 285
 			// Fees and Net needs to both come from Stripe to be accurate as the returned
287 286
 			// values are in the local currency of the Stripe account, not from WC.
288
-			$fee = ! empty( $response->balance_transaction->fee ) ? WC_Stripe_Helper::format_balance_fee( $response->balance_transaction, 'fee' ) : 0;
289
-			$net = ! empty( $response->balance_transaction->net ) ? WC_Stripe_Helper::format_balance_fee( $response->balance_transaction, 'net' ) : 0;
290
-			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 );
291
-			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 );
287
+			$fee = ! empty($response->balance_transaction->fee) ? WC_Stripe_Helper::format_balance_fee($response->balance_transaction, 'fee') : 0;
288
+			$net = ! empty($response->balance_transaction->net) ? WC_Stripe_Helper::format_balance_fee($response->balance_transaction, 'net') : 0;
289
+			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);
290
+			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);
292 291
 		}
293 292
 
294
-		if ( 'yes' === $captured ) {
293
+		if ('yes' === $captured) {
295 294
 			/**
296 295
 			 * Charge can be captured but in a pending state. Payment methods
297 296
 			 * that are asynchronous may take couple days to clear. Webhook will
298 297
 			 * take care of the status changes.
299 298
 			 */
300
-			if ( 'pending' === $response->status ) {
301
-				$order_stock_reduced = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_order_stock_reduced', true ) : $order->get_meta( '_order_stock_reduced', true );
299
+			if ('pending' === $response->status) {
300
+				$order_stock_reduced = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_order_stock_reduced', true) : $order->get_meta('_order_stock_reduced', true);
302 301
 
303
-				if ( ! $order_stock_reduced ) {
304
-					WC_Stripe_Helper::is_pre_30() ? $order->reduce_order_stock() : wc_reduce_stock_levels( $order_id );
302
+				if ( ! $order_stock_reduced) {
303
+					WC_Stripe_Helper::is_pre_30() ? $order->reduce_order_stock() : wc_reduce_stock_levels($order_id);
305 304
 				}
306 305
 
307
-				WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, '_transaction_id', $response->id ) : $order->set_transaction_id( $response->id );
306
+				WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, '_transaction_id', $response->id) : $order->set_transaction_id($response->id);
308 307
 				/* translators: transaction id */
309
-				$order->update_status( 'on-hold', sprintf( __( 'Stripe charge awaiting payment: %s.', 'woocommerce-gateway-stripe' ), $response->id ) );
308
+				$order->update_status('on-hold', sprintf(__('Stripe charge awaiting payment: %s.', 'woocommerce-gateway-stripe'), $response->id));
310 309
 			}
311 310
 
312
-			if ( 'succeeded' === $response->status ) {
313
-				$order->payment_complete( $response->id );
311
+			if ('succeeded' === $response->status) {
312
+				$order->payment_complete($response->id);
314 313
 
315 314
 				/* translators: transaction id */
316
-				$message = sprintf( __( 'Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe' ), $response->id );
317
-				$order->add_order_note( $message );
315
+				$message = sprintf(__('Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe'), $response->id);
316
+				$order->add_order_note($message);
318 317
 			}
319 318
 
320
-			if ( 'failed' === $response->status ) {
321
-				$localized_message = __( 'Payment processing failed. Please retry.', 'woocommerce-gateway-stripe' );
322
-				$order->add_order_note( $localized_message );
323
-				throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message );
319
+			if ('failed' === $response->status) {
320
+				$localized_message = __('Payment processing failed. Please retry.', 'woocommerce-gateway-stripe');
321
+				$order->add_order_note($localized_message);
322
+				throw new WC_Stripe_Exception(print_r($response, true), $localized_message);
324 323
 			}
325 324
 		} else {
326
-			WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, '_transaction_id', $response->id ) : $order->set_transaction_id( $response->id );
325
+			WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, '_transaction_id', $response->id) : $order->set_transaction_id($response->id);
327 326
 
328
-			if ( $order->has_status( array( 'pending', 'failed' ) ) ) {
329
-				WC_Stripe_Helper::is_pre_30() ? $order->reduce_order_stock() : wc_reduce_stock_levels( $order_id );
327
+			if ($order->has_status(array('pending', 'failed'))) {
328
+				WC_Stripe_Helper::is_pre_30() ? $order->reduce_order_stock() : wc_reduce_stock_levels($order_id);
330 329
 			}
331 330
 
332 331
 			/* translators: transaction id */
333
-			$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 ) );
332
+			$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));
334 333
 		}
335 334
 
336
-		if ( is_callable( array( $order, 'save' ) ) ) {
335
+		if (is_callable(array($order, 'save'))) {
337 336
 			$order->save();
338 337
 		}
339 338
 
340
-		do_action( 'wc_gateway_stripe_process_response', $response, $order );
339
+		do_action('wc_gateway_stripe_process_response', $response, $order);
341 340
 
342 341
 		return $response;
343 342
 	}
@@ -350,10 +349,10 @@  discard block
 block discarded – undo
350 349
 	 * @param int $order_id
351 350
 	 * @return null
352 351
 	 */
353
-	public function send_failed_order_email( $order_id ) {
352
+	public function send_failed_order_email($order_id) {
354 353
 		$emails = WC()->mailer()->get_emails();
355
-		if ( ! empty( $emails ) && ! empty( $order_id ) ) {
356
-			$emails['WC_Email_Failed_Order']->trigger( $order_id );
354
+		if ( ! empty($emails) && ! empty($order_id)) {
355
+			$emails['WC_Email_Failed_Order']->trigger($order_id);
357 356
 		}
358 357
 	}
359 358
 
@@ -365,7 +364,7 @@  discard block
 block discarded – undo
365 364
 	 * @param object $order
366 365
 	 * @return object $details
367 366
 	 */
368
-	public function get_owner_details( $order ) {
367
+	public function get_owner_details($order) {
369 368
 		$billing_first_name = WC_Stripe_Helper::is_pre_30() ? $order->billing_first_name : $order->get_billing_first_name();
370 369
 		$billing_last_name  = WC_Stripe_Helper::is_pre_30() ? $order->billing_last_name : $order->get_billing_last_name();
371 370
 
@@ -376,8 +375,8 @@  discard block
 block discarded – undo
376 375
 
377 376
 		$phone                             = WC_Stripe_Helper::is_pre_30() ? $order->billing_phone : $order->get_billing_phone();
378 377
 
379
-		if ( ! empty( $phone ) ) {
380
-			$details['phone']              = $phone;
378
+		if ( ! empty($phone)) {
379
+			$details['phone'] = $phone;
381 380
 		}
382 381
 
383 382
 		$details['address']['line1']       = WC_Stripe_Helper::is_pre_30() ? $order->billing_address_1 : $order->get_billing_address_1();
@@ -387,7 +386,7 @@  discard block
 block discarded – undo
387 386
 		$details['address']['postal_code'] = WC_Stripe_Helper::is_pre_30() ? $order->billing_postcode : $order->get_billing_postcode();
388 387
 		$details['address']['country']     = WC_Stripe_Helper::is_pre_30() ? $order->billing_country : $order->get_billing_country();
389 388
 
390
-		return (object) apply_filters( 'wc_stripe_owner_details', $details, $order );
389
+		return (object) apply_filters('wc_stripe_owner_details', $details, $order);
391 390
 	}
392 391
 
393 392
 	/**
@@ -396,15 +395,15 @@  discard block
 block discarded – undo
396 395
 	 * @since 4.0.3
397 396
 	 * @param string $source_id The source ID to get source object for.
398 397
 	 */
399
-	public function get_source_object( $source_id = '' ) {
400
-		if ( empty( $source_id ) ) {
398
+	public function get_source_object($source_id = '') {
399
+		if (empty($source_id)) {
401 400
 			return '';
402 401
 		}
403 402
 
404
-		$source_object = WC_Stripe_API::retrieve( 'sources/' . $source_id );
403
+		$source_object = WC_Stripe_API::retrieve('sources/' . $source_id);
405 404
 
406
-		if ( ! empty( $source_object->error ) ) {
407
-			throw new WC_Stripe_Exception( print_r( $source_object, true ), $source_object->error->message );
405
+		if ( ! empty($source_object->error)) {
406
+			throw new WC_Stripe_Exception(print_r($source_object, true), $source_object->error->message);
408 407
 		}
409 408
 
410 409
 		return $source_object;
@@ -417,11 +416,11 @@  discard block
 block discarded – undo
417 416
 	 * @param object $source_object
418 417
 	 * @return bool
419 418
 	 */
420
-	public function is_3ds_required( $source_object ) {
419
+	public function is_3ds_required($source_object) {
421 420
 		return (
422
-			$source_object && ! empty( $source_object->card ) ) &&
423
-			( 'card' === $source_object->type && 'required' === $source_object->card->three_d_secure ||
424
-			( $this->three_d_secure && 'optional' === $source_object->card->three_d_secure )
421
+			$source_object && ! empty($source_object->card) ) &&
422
+			('card' === $source_object->type && 'required' === $source_object->card->three_d_secure ||
423
+			($this->three_d_secure && 'optional' === $source_object->card->three_d_secure)
425 424
 		);
426 425
 	}
427 426
 
@@ -432,8 +431,8 @@  discard block
 block discarded – undo
432 431
 	 * @param object $source_object
433 432
 	 * @return bool
434 433
 	 */
435
-	public function is_3ds_card( $source_object ) {
436
-		return ( $source_object && 'three_d_secure' === $source_object->type );
434
+	public function is_3ds_card($source_object) {
435
+		return ($source_object && 'three_d_secure' === $source_object->type);
437 436
 	}
438 437
 
439 438
 	/**
@@ -443,8 +442,8 @@  discard block
 block discarded – undo
443 442
 	 * @param object $source_object
444 443
 	 * @return bool
445 444
 	 */
446
-	public function is_prepaid_card( $source_object ) {
447
-		return ( $source_object && 'token' === $source_object->object && 'prepaid' === $source_object->card->funding );
445
+	public function is_prepaid_card($source_object) {
446
+		return ($source_object && 'token' === $source_object->object && 'prepaid' === $source_object->card->funding);
448 447
 	}
449 448
 
450 449
 	/**
@@ -454,8 +453,8 @@  discard block
 block discarded – undo
454 453
 	 * @param string $source_id
455 454
 	 * @return bool
456 455
 	 */
457
-	public function is_type_legacy_card( $source_id ) {
458
-		return ( preg_match( '/^card_/', $source_id ) );
456
+	public function is_type_legacy_card($source_id) {
457
+		return (preg_match('/^card_/', $source_id));
459 458
 	}
460 459
 
461 460
 	/**
@@ -468,22 +467,22 @@  discard block
 block discarded – undo
468 467
 	 * @param string $return_url
469 468
 	 * @return mixed
470 469
 	 */
471
-	public function create_3ds_source( $order, $source_object, $return_url = '' ) {
470
+	public function create_3ds_source($order, $source_object, $return_url = '') {
472 471
 		$currency                    = WC_Stripe_Helper::is_pre_30() ? $order->get_order_currency() : $order->get_currency();
473 472
 		$order_id                    = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
474
-		$return_url                  = empty( $return_url ) ? $this->get_stripe_return_url( $order ) : $return_url;
473
+		$return_url                  = empty($return_url) ? $this->get_stripe_return_url($order) : $return_url;
475 474
 
476 475
 		$post_data                   = array();
477
-		$post_data['amount']         = WC_Stripe_Helper::get_stripe_amount( $order->get_total(), $currency );
478
-		$post_data['currency']       = strtolower( $currency );
476
+		$post_data['amount']         = WC_Stripe_Helper::get_stripe_amount($order->get_total(), $currency);
477
+		$post_data['currency']       = strtolower($currency);
479 478
 		$post_data['type']           = 'three_d_secure';
480
-		$post_data['owner']          = $this->get_owner_details( $order );
481
-		$post_data['three_d_secure'] = array( 'card' => $source_object->id );
482
-		$post_data['redirect']       = array( 'return_url' => $return_url );
479
+		$post_data['owner']          = $this->get_owner_details($order);
480
+		$post_data['three_d_secure'] = array('card' => $source_object->id);
481
+		$post_data['redirect']       = array('return_url' => $return_url);
483 482
 
484
-		WC_Stripe_Logger::log( 'Info: Begin creating 3DS source...' );
483
+		WC_Stripe_Logger::log('Info: Begin creating 3DS source...');
485 484
 
486
-		return WC_Stripe_API::request( apply_filters( 'wc_stripe_3ds_source', $post_data, $order ), 'sources' );
485
+		return WC_Stripe_API::request(apply_filters('wc_stripe_3ds_source', $post_data, $order), 'sources');
487 486
 	}
488 487
 
489 488
 	/**
@@ -499,61 +498,61 @@  discard block
 block discarded – undo
499 498
 	 * @throws Exception When card was not added or for and invalid card.
500 499
 	 * @return object
501 500
 	 */
502
-	public function prepare_source( $user_id, $force_save_source = false ) {
503
-		$customer           = new WC_Stripe_Customer( $user_id );
501
+	public function prepare_source($user_id, $force_save_source = false) {
502
+		$customer           = new WC_Stripe_Customer($user_id);
504 503
 		$set_customer       = true;
505
-		$force_save_source  = apply_filters( 'wc_stripe_force_save_source', $force_save_source, $customer );
504
+		$force_save_source  = apply_filters('wc_stripe_force_save_source', $force_save_source, $customer);
506 505
 		$source_object      = '';
507 506
 		$source_id          = '';
508 507
 		$wc_token_id        = false;
509
-		$payment_method     = isset( $_POST['payment_method'] ) ? wc_clean( $_POST['payment_method'] ) : 'stripe';
508
+		$payment_method     = isset($_POST['payment_method']) ? wc_clean($_POST['payment_method']) : 'stripe';
510 509
 		$is_token           = false;
511 510
 
512 511
 		// New CC info was entered and we have a new source to process.
513
-		if ( ! empty( $_POST['stripe_source'] ) ) {
514
-			$source_object = self::get_source_object( wc_clean( $_POST['stripe_source'] ) );
512
+		if ( ! empty($_POST['stripe_source'])) {
513
+			$source_object = self::get_source_object(wc_clean($_POST['stripe_source']));
515 514
 			$source_id     = $source_object->id;
516 515
 
517 516
 			// This checks to see if customer opted to save the payment method to file.
518
-			$maybe_saved_card = isset( $_POST[ 'wc-' . $payment_method . '-new-payment-method' ] ) && ! empty( $_POST[ 'wc-' . $payment_method . '-new-payment-method' ] );
517
+			$maybe_saved_card = isset($_POST['wc-' . $payment_method . '-new-payment-method']) && ! empty($_POST['wc-' . $payment_method . '-new-payment-method']);
519 518
 
520 519
 			/**
521 520
 			 * This is true if the user wants to store the card to their account.
522 521
 			 * Criteria to save to file is they are logged in, they opted to save or product requirements and the source is
523 522
 			 * actually reusable. Either that or force_save_source is true.
524 523
 			 */
525
-			if ( ( $user_id && $this->saved_cards && $maybe_saved_card && 'reusable' === $source_object->usage ) || $force_save_source ) {
526
-				$response = $customer->add_source( $source_object->id );
524
+			if (($user_id && $this->saved_cards && $maybe_saved_card && 'reusable' === $source_object->usage) || $force_save_source) {
525
+				$response = $customer->add_source($source_object->id);
527 526
 
528
-				if ( ! empty( $response->error ) ) {
529
-					throw new WC_Stripe_Exception( print_r( $response, true ), $response->error->message );
527
+				if ( ! empty($response->error)) {
528
+					throw new WC_Stripe_Exception(print_r($response, true), $response->error->message);
530 529
 				}
531 530
 			}
532
-		} elseif ( isset( $_POST[ 'wc-' . $payment_method . '-payment-token' ] ) && 'new' !== $_POST[ 'wc-' . $payment_method . '-payment-token' ] ) {
531
+		} elseif (isset($_POST['wc-' . $payment_method . '-payment-token']) && 'new' !== $_POST['wc-' . $payment_method . '-payment-token']) {
533 532
 			// Use an existing token, and then process the payment.
534
-			$wc_token_id = wc_clean( $_POST[ 'wc-' . $payment_method . '-payment-token' ] );
535
-			$wc_token    = WC_Payment_Tokens::get( $wc_token_id );
533
+			$wc_token_id = wc_clean($_POST['wc-' . $payment_method . '-payment-token']);
534
+			$wc_token    = WC_Payment_Tokens::get($wc_token_id);
536 535
 
537
-			if ( ! $wc_token || $wc_token->get_user_id() !== get_current_user_id() ) {
538
-				WC()->session->set( 'refresh_totals', true );
539
-				throw new WC_Stripe_Exception( 'Invalid payment method', __( 'Invalid payment method. Please input a new card number.', 'woocommerce-gateway-stripe' ) );
536
+			if ( ! $wc_token || $wc_token->get_user_id() !== get_current_user_id()) {
537
+				WC()->session->set('refresh_totals', true);
538
+				throw new WC_Stripe_Exception('Invalid payment method', __('Invalid payment method. Please input a new card number.', 'woocommerce-gateway-stripe'));
540 539
 			}
541 540
 
542 541
 			$source_id = $wc_token->get_token();
543 542
 
544
-			if ( $this->is_type_legacy_card( $source_id ) ) {
543
+			if ($this->is_type_legacy_card($source_id)) {
545 544
 				$is_token = true;
546 545
 			}
547
-		} elseif ( isset( $_POST['stripe_token'] ) && 'new' !== $_POST['stripe_token'] ) {
548
-			$stripe_token     = wc_clean( $_POST['stripe_token'] );
549
-			$maybe_saved_card = isset( $_POST[ 'wc-' . $payment_method . '-new-payment-method' ] ) && ! empty( $_POST[ 'wc-' . $payment_method . '-new-payment-method' ] );
546
+		} elseif (isset($_POST['stripe_token']) && 'new' !== $_POST['stripe_token']) {
547
+			$stripe_token     = wc_clean($_POST['stripe_token']);
548
+			$maybe_saved_card = isset($_POST['wc-' . $payment_method . '-new-payment-method']) && ! empty($_POST['wc-' . $payment_method . '-new-payment-method']);
550 549
 
551 550
 			// This is true if the user wants to store the card to their account.
552
-			if ( ( $user_id && $this->saved_cards && $maybe_saved_card ) || $force_save_source ) {
553
-				$response = $customer->add_source( $stripe_token );
551
+			if (($user_id && $this->saved_cards && $maybe_saved_card) || $force_save_source) {
552
+				$response = $customer->add_source($stripe_token);
554 553
 
555
-				if ( ! empty( $response->error ) ) {
556
-					throw new WC_Stripe_Exception( print_r( $response, true ), $response->error->message );
554
+				if ( ! empty($response->error)) {
555
+					throw new WC_Stripe_Exception(print_r($response, true), $response->error->message);
557 556
 				}
558 557
 			} else {
559 558
 				$set_customer = false;
@@ -562,14 +561,14 @@  discard block
 block discarded – undo
562 561
 			}
563 562
 		}
564 563
 
565
-		if ( ! $set_customer ) {
564
+		if ( ! $set_customer) {
566 565
 			$customer_id = false;
567 566
 		} else {
568 567
 			$customer_id = $customer->get_id() ? $customer->get_id() : false;
569 568
 		}
570 569
 
571
-		if ( empty( $source_object ) && ! $is_token ) {
572
-			$source_object = self::get_source_object( $source_id );
570
+		if (empty($source_object) && ! $is_token) {
571
+			$source_object = self::get_source_object($source_id);
573 572
 		}
574 573
 
575 574
 		return (object) array(
@@ -593,37 +592,37 @@  discard block
 block discarded – undo
593 592
 	 * @param object $order
594 593
 	 * @return object
595 594
 	 */
596
-	public function prepare_order_source( $order = null ) {
595
+	public function prepare_order_source($order = null) {
597 596
 		$stripe_customer = new WC_Stripe_Customer();
598 597
 		$stripe_source   = false;
599 598
 		$token_id        = false;
600 599
 
601
-		if ( $order ) {
600
+		if ($order) {
602 601
 			$order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
603 602
 
604
-			$stripe_customer_id = get_post_meta( $order_id, '_stripe_customer_id', true );
603
+			$stripe_customer_id = get_post_meta($order_id, '_stripe_customer_id', true);
605 604
 
606
-			if ( $stripe_customer_id ) {
607
-				$stripe_customer->set_id( $stripe_customer_id );
605
+			if ($stripe_customer_id) {
606
+				$stripe_customer->set_id($stripe_customer_id);
608 607
 			}
609 608
 
610
-			$source_id = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_stripe_source_id', true ) : $order->get_meta( '_stripe_source_id', true );
609
+			$source_id = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_stripe_source_id', true) : $order->get_meta('_stripe_source_id', true);
611 610
 
612 611
 			// Since 4.0.0, we changed card to source so we need to account for that.
613
-			if ( empty( $source_id ) ) {
614
-				$source_id = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_stripe_card_id', true ) : $order->get_meta( '_stripe_card_id', true );
612
+			if (empty($source_id)) {
613
+				$source_id = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_stripe_card_id', true) : $order->get_meta('_stripe_card_id', true);
615 614
 
616 615
 				// Take this opportunity to update the key name.
617
-				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 );
616
+				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);
618 617
 
619
-				if ( is_callable( array( $order, 'save' ) ) ) {
618
+				if (is_callable(array($order, 'save'))) {
620 619
 					$order->save();
621 620
 				}
622 621
 			}
623 622
 
624
-			if ( $source_id ) {
623
+			if ($source_id) {
625 624
 				$stripe_source = $source_id;
626
-			} elseif ( apply_filters( 'wc_stripe_use_default_customer_source', true ) ) {
625
+			} elseif (apply_filters('wc_stripe_use_default_customer_source', true)) {
627 626
 				/*
628 627
 				 * We can attempt to charge the customer's default source
629 628
 				 * by sending empty source id.
@@ -647,27 +646,27 @@  discard block
 block discarded – undo
647 646
 	 * @param WC_Order $order For to which the source applies.
648 647
 	 * @param stdClass $source Source information.
649 648
 	 */
650
-	public function save_source_to_order( $order, $source ) {
649
+	public function save_source_to_order($order, $source) {
651 650
 		$order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
652 651
 
653 652
 		// Store source in the order.
654
-		if ( $source->customer ) {
655
-			if ( WC_Stripe_Helper::is_pre_30() ) {
656
-				update_post_meta( $order_id, '_stripe_customer_id', $source->customer );
653
+		if ($source->customer) {
654
+			if (WC_Stripe_Helper::is_pre_30()) {
655
+				update_post_meta($order_id, '_stripe_customer_id', $source->customer);
657 656
 			} else {
658
-				$order->update_meta_data( '_stripe_customer_id', $source->customer );
657
+				$order->update_meta_data('_stripe_customer_id', $source->customer);
659 658
 			}
660 659
 		}
661 660
 
662
-		if ( $source->source ) {
663
-			if ( WC_Stripe_Helper::is_pre_30() ) {
664
-				update_post_meta( $order_id, '_stripe_source_id', $source->source );
661
+		if ($source->source) {
662
+			if (WC_Stripe_Helper::is_pre_30()) {
663
+				update_post_meta($order_id, '_stripe_source_id', $source->source);
665 664
 			} else {
666
-				$order->update_meta_data( '_stripe_source_id', $source->source );
665
+				$order->update_meta_data('_stripe_source_id', $source->source);
667 666
 			}
668 667
 		}
669 668
 
670
-		if ( is_callable( array( $order, 'save' ) ) ) {
669
+		if (is_callable(array($order, 'save'))) {
671 670
 			$order->save();
672 671
 		}
673 672
 	}
@@ -681,35 +680,35 @@  discard block
 block discarded – undo
681 680
 	 * @param object $order The order object
682 681
 	 * @param int $balance_transaction_id
683 682
 	 */
684
-	public function update_fees( $order, $balance_transaction_id ) {
683
+	public function update_fees($order, $balance_transaction_id) {
685 684
 		$order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
686 685
 
687
-		$balance_transaction = WC_Stripe_API::retrieve( 'balance/history/' . $balance_transaction_id );
686
+		$balance_transaction = WC_Stripe_API::retrieve('balance/history/' . $balance_transaction_id);
688 687
 
689
-		if ( empty( $balance_transaction->error ) ) {
690
-			if ( isset( $balance_transaction ) && isset( $balance_transaction->fee ) ) {
688
+		if (empty($balance_transaction->error)) {
689
+			if (isset($balance_transaction) && isset($balance_transaction->fee)) {
691 690
 				// Fees and Net needs to both come from Stripe to be accurate as the returned
692 691
 				// values are in the local currency of the Stripe account, not from WC.
693
-				$fee_refund = ! empty( $balance_transaction->fee ) ? WC_Stripe_Helper::format_balance_fee( $balance_transaction, 'fee' ) : 0;
694
-				$net_refund = ! empty( $balance_transaction->net ) ? WC_Stripe_Helper::format_balance_fee( $balance_transaction, 'net' ) : 0;
692
+				$fee_refund = ! empty($balance_transaction->fee) ? WC_Stripe_Helper::format_balance_fee($balance_transaction, 'fee') : 0;
693
+				$net_refund = ! empty($balance_transaction->net) ? WC_Stripe_Helper::format_balance_fee($balance_transaction, 'net') : 0;
695 694
 
696 695
 				// Current data fee & net.
697
-				$fee_current = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, self::META_NAME_FEE, true ) : $order->get_meta( self::META_NAME_FEE, true );
698
-				$net_current = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, self::META_NAME_NET, true ) : $order->get_meta( self::META_NAME_NET, true );
696
+				$fee_current = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, self::META_NAME_FEE, true) : $order->get_meta(self::META_NAME_FEE, true);
697
+				$net_current = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, self::META_NAME_NET, true) : $order->get_meta(self::META_NAME_NET, true);
699 698
 
700 699
 				// Calculation.
701 700
 				$fee = (float) $fee_current + (float) $fee_refund;
702 701
 				$net = (float) $net_current + (float) $net_refund;
703 702
 
704
-				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 );
705
-				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 );
703
+				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);
704
+				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);
706 705
 
707
-				if ( is_callable( array( $order, 'save' ) ) ) {
706
+				if (is_callable(array($order, 'save'))) {
708 707
 					$order->save();
709 708
 				}
710 709
 			}
711 710
 		} else {
712
-			WC_Stripe_Logger::log( "Unable to update fees/net meta for order: {$order_id}" );
711
+			WC_Stripe_Logger::log("Unable to update fees/net meta for order: {$order_id}");
713 712
 		}
714 713
 	}
715 714
 
@@ -722,33 +721,33 @@  discard block
 block discarded – undo
722 721
 	 * @param  float $amount
723 722
 	 * @return bool
724 723
 	 */
725
-	public function process_refund( $order_id, $amount = null, $reason = '' ) {
726
-		$order = wc_get_order( $order_id );
724
+	public function process_refund($order_id, $amount = null, $reason = '') {
725
+		$order = wc_get_order($order_id);
727 726
 
728
-		if ( ! $order || ! $order->get_transaction_id() ) {
727
+		if ( ! $order || ! $order->get_transaction_id()) {
729 728
 			return false;
730 729
 		}
731 730
 
732 731
 		$request = array();
733 732
 
734
-		if ( WC_Stripe_Helper::is_pre_30() ) {
735
-			$order_currency = get_post_meta( $order_id, '_order_currency', true );
736
-			$captured       = get_post_meta( $order_id, '_stripe_charge_captured', true );
733
+		if (WC_Stripe_Helper::is_pre_30()) {
734
+			$order_currency = get_post_meta($order_id, '_order_currency', true);
735
+			$captured       = get_post_meta($order_id, '_stripe_charge_captured', true);
737 736
 		} else {
738 737
 			$order_currency = $order->get_currency();
739
-			$captured       = $order->get_meta( '_stripe_charge_captured', true );
738
+			$captured       = $order->get_meta('_stripe_charge_captured', true);
740 739
 		}
741 740
 
742
-		if ( ! is_null( $amount ) ) {
743
-			$request['amount'] = WC_Stripe_Helper::get_stripe_amount( $amount, $order_currency );
741
+		if ( ! is_null($amount)) {
742
+			$request['amount'] = WC_Stripe_Helper::get_stripe_amount($amount, $order_currency);
744 743
 		}
745 744
 
746 745
 		// If order is only authorized, don't pass amount.
747
-		if ( 'yes' !== $captured ) {
748
-			unset( $request['amount'] );
746
+		if ('yes' !== $captured) {
747
+			unset($request['amount']);
749 748
 		}
750 749
 
751
-		if ( $reason ) {
750
+		if ($reason) {
752 751
 			$request['metadata'] = array(
753 752
 				'reason' => $reason,
754 753
 			);
@@ -756,35 +755,35 @@  discard block
 block discarded – undo
756 755
 
757 756
 		$request['charge'] = $order->get_transaction_id();
758 757
 
759
-		WC_Stripe_Logger::log( "Info: Beginning refund for order {$order->get_transaction_id()} for the amount of {$amount}" );
758
+		WC_Stripe_Logger::log("Info: Beginning refund for order {$order->get_transaction_id()} for the amount of {$amount}");
760 759
 
761
-		$request = apply_filters( 'wc_stripe_refund_request', $request, $order );
760
+		$request = apply_filters('wc_stripe_refund_request', $request, $order);
762 761
 
763
-		$response = WC_Stripe_API::request( $request, 'refunds' );
762
+		$response = WC_Stripe_API::request($request, 'refunds');
764 763
 
765
-		if ( ! empty( $response->error ) ) {
766
-			WC_Stripe_Logger::log( 'Error: ' . $response->error->message );
764
+		if ( ! empty($response->error)) {
765
+			WC_Stripe_Logger::log('Error: ' . $response->error->message);
767 766
 
768 767
 			return $response;
769 768
 
770
-		} elseif ( ! empty( $response->id ) ) {
771
-			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 );
769
+		} elseif ( ! empty($response->id)) {
770
+			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);
772 771
 
773
-			$amount = wc_price( $response->amount / 100 );
772
+			$amount = wc_price($response->amount / 100);
774 773
 
775
-			if ( in_array( strtolower( $order->get_currency() ), WC_Stripe_Helper::no_decimal_currencies() ) ) {
776
-				$amount = wc_price( $response->amount );
774
+			if (in_array(strtolower($order->get_currency()), WC_Stripe_Helper::no_decimal_currencies())) {
775
+				$amount = wc_price($response->amount);
777 776
 			}
778 777
 
779
-			if ( isset( $response->balance_transaction ) ) {
780
-				$this->update_fees( $order, $response->balance_transaction );
778
+			if (isset($response->balance_transaction)) {
779
+				$this->update_fees($order, $response->balance_transaction);
781 780
 			}
782 781
 
783 782
 			/* translators: 1) dollar amount 2) transaction id 3) refund message */
784
-			$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' );
783
+			$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');
785 784
 
786
-			$order->add_order_note( $refund_message );
787
-			WC_Stripe_Logger::log( 'Success: ' . html_entity_decode( strip_tags( $refund_message ) ) );
785
+			$order->add_order_note($refund_message);
786
+			WC_Stripe_Logger::log('Success: ' . html_entity_decode(strip_tags($refund_message)));
788 787
 
789 788
 			return true;
790 789
 		}
@@ -799,44 +798,44 @@  discard block
 block discarded – undo
799 798
 	 */
800 799
 	public function add_payment_method() {
801 800
 		$error     = false;
802
-		$error_msg = __( 'There was a problem adding the card.', 'woocommerce-gateway-stripe' );
801
+		$error_msg = __('There was a problem adding the card.', 'woocommerce-gateway-stripe');
803 802
 		$source_id = '';
804 803
 
805
-		if ( empty( $_POST['stripe_source'] ) && empty( $_POST['stripe_token'] ) || ! is_user_logged_in() ) {
804
+		if (empty($_POST['stripe_source']) && empty($_POST['stripe_token']) || ! is_user_logged_in()) {
806 805
 			$error = true;
807 806
 		}
808 807
 
809
-		$stripe_customer = new WC_Stripe_Customer( get_current_user_id() );
808
+		$stripe_customer = new WC_Stripe_Customer(get_current_user_id());
810 809
 
811
-		$source = ! empty( $_POST['stripe_source'] ) ? wc_clean( $_POST['stripe_source'] ) : '';
810
+		$source = ! empty($_POST['stripe_source']) ? wc_clean($_POST['stripe_source']) : '';
812 811
 
813
-		$source_object = WC_Stripe_API::retrieve( 'sources/' . $source );
812
+		$source_object = WC_Stripe_API::retrieve('sources/' . $source);
814 813
 
815
-		if ( isset( $source_object ) ) {
816
-			if ( ! empty( $source_object->error ) ) {
814
+		if (isset($source_object)) {
815
+			if ( ! empty($source_object->error)) {
817 816
 				$error = true;
818 817
 			}
819 818
 
820 819
 			$source_id = $source_object->id;
821
-		} elseif ( isset( $_POST['stripe_token'] ) ) {
822
-			$source_id = wc_clean( $_POST['stripe_token'] );
820
+		} elseif (isset($_POST['stripe_token'])) {
821
+			$source_id = wc_clean($_POST['stripe_token']);
823 822
 		}
824 823
 
825
-		$response = $stripe_customer->add_source( $source_id );
824
+		$response = $stripe_customer->add_source($source_id);
826 825
 
827
-		if ( ! $response || is_wp_error( $response ) || ! empty( $response->error ) ) {
826
+		if ( ! $response || is_wp_error($response) || ! empty($response->error)) {
828 827
 			$error = true;
829 828
 		}
830 829
 
831
-		if ( $error ) {
832
-			wc_add_notice( $error_msg, 'error' );
833
-			WC_Stripe_Logger::log( 'Add payment method Error: ' . $error_msg );
830
+		if ($error) {
831
+			wc_add_notice($error_msg, 'error');
832
+			WC_Stripe_Logger::log('Add payment method Error: ' . $error_msg);
834 833
 			return;
835 834
 		}
836 835
 
837 836
 		return array(
838 837
 			'result'   => 'success',
839
-			'redirect' => wc_get_endpoint_url( 'payment-methods' ),
838
+			'redirect' => wc_get_endpoint_url('payment-methods'),
840 839
 		);
841 840
 	}
842 841
 
@@ -853,10 +852,10 @@  discard block
 block discarded – undo
853 852
 		 * Stripe expects Norwegian to only be passed NO.
854 853
 		 * But WP has different dialects.
855 854
 		 */
856
-		if ( 'NO' === substr( $locale, 3, 2 ) ) {
855
+		if ('NO' === substr($locale, 3, 2)) {
857 856
 			$locale = 'no';
858 857
 		} else {
859
-			$locale = substr( get_locale(), 0, 2 );
858
+			$locale = substr(get_locale(), 0, 2);
860 859
 		}
861 860
 
862 861
 		return $locale;
@@ -870,9 +869,9 @@  discard block
 block discarded – undo
870 869
 	 * @param string $idempotency_key
871 870
 	 * @param array $request
872 871
 	 */
873
-	public function change_idempotency_key( $idempotency_key, $request ) {
874
-		$customer = ! empty( $request['customer'] ) ? $request['customer'] : '';
875
-		$source   = ! empty( $request['source'] ) ? $request['source'] : $customer;
872
+	public function change_idempotency_key($idempotency_key, $request) {
873
+		$customer = ! empty($request['customer']) ? $request['customer'] : '';
874
+		$source   = ! empty($request['source']) ? $request['source'] : $customer;
876 875
 		$count    = $this->retry_interval;
877 876
 
878 877
 		return $request['metadata']['order_id'] . '-' . $count . '-' . $source;
@@ -886,8 +885,8 @@  discard block
 block discarded – undo
886 885
 	 * @since 4.0.6
887 886
 	 * @param array $headers
888 887
 	 */
889
-	public function is_original_request( $headers ) {
890
-		if ( $headers['original-request'] === $headers['request-id'] ) {
888
+	public function is_original_request($headers) {
889
+		if ($headers['original-request'] === $headers['request-id']) {
891 890
 			return true;
892 891
 		}
893 892
 
Please login to merge, or discard this patch.