Completed
Push — master ( bf7249...8ab9d7 )
by Matty
02:35
created
includes/class-wc-stripe-order-handler.php 1 patch
Spacing   +161 added lines, -161 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
 
@@ -20,12 +20,12 @@  discard block
 block discarded – undo
20 20
 	public function __construct() {
21 21
 		self::$_this = $this;
22 22
 
23
-		add_action( 'wp', array( $this, 'maybe_process_redirect_order' ) );
24
-		add_action( 'woocommerce_order_status_on-hold_to_processing', array( $this, 'capture_payment' ) );
25
-		add_action( 'woocommerce_order_status_on-hold_to_completed', array( $this, 'capture_payment' ) );
26
-		add_action( 'woocommerce_order_status_on-hold_to_cancelled', array( $this, 'cancel_payment' ) );
27
-		add_action( 'woocommerce_order_status_on-hold_to_refunded', array( $this, 'cancel_payment' ) );
28
-		add_action( 'wc_ajax_wc_stripe_validate_checkout', array( $this, 'validate_checkout' ) );
23
+		add_action('wp', array($this, 'maybe_process_redirect_order'));
24
+		add_action('woocommerce_order_status_on-hold_to_processing', array($this, 'capture_payment'));
25
+		add_action('woocommerce_order_status_on-hold_to_completed', array($this, 'capture_payment'));
26
+		add_action('woocommerce_order_status_on-hold_to_cancelled', array($this, 'cancel_payment'));
27
+		add_action('woocommerce_order_status_on-hold_to_refunded', array($this, 'cancel_payment'));
28
+		add_action('wc_ajax_wc_stripe_validate_checkout', array($this, 'validate_checkout'));
29 29
 	}
30 30
 
31 31
 	/**
@@ -46,25 +46,25 @@  discard block
 block discarded – undo
46 46
 	 * @since 4.0.0
47 47
 	 * @version 4.0.0
48 48
 	 */
49
-	public function process_redirect_payment( $order_id, $retry = true ) {
49
+	public function process_redirect_payment($order_id, $retry = true) {
50 50
 		try {
51
-			$source = wc_clean( $_GET['source'] );
51
+			$source = wc_clean($_GET['source']);
52 52
 
53
-			if ( empty( $source ) ) {
53
+			if (empty($source)) {
54 54
 				return;
55 55
 			}
56 56
 
57
-			if ( empty( $order_id ) ) {
57
+			if (empty($order_id)) {
58 58
 				return;
59 59
 			}
60 60
 
61
-			$order = wc_get_order( $order_id );
61
+			$order = wc_get_order($order_id);
62 62
 
63
-			if ( ! is_object( $order ) ) {
63
+			if ( ! is_object($order)) {
64 64
 				return;
65 65
 			}
66 66
 
67
-			if ( 'processing' === $order->get_status() || 'completed' === $order->get_status() || 'on-hold' === $order->get_status() ) {
67
+			if ('processing' === $order->get_status() || 'completed' === $order->get_status() || 'on-hold' === $order->get_status()) {
68 68
 				return;
69 69
 			}
70 70
 
@@ -72,97 +72,97 @@  discard block
 block discarded – undo
72 72
 			$response = null;
73 73
 
74 74
 			// This will throw exception if not valid.
75
-			$this->validate_minimum_order_amount( $order );
75
+			$this->validate_minimum_order_amount($order);
76 76
 
77
-			WC_Stripe_Logger::log( "Info: (Redirect) Begin processing payment for order $order_id for the amount of {$order->get_total()}" );
77
+			WC_Stripe_Logger::log("Info: (Redirect) Begin processing payment for order $order_id for the amount of {$order->get_total()}");
78 78
 
79 79
 			// Prep source object.
80 80
 			$source_object           = new stdClass();
81 81
 			$source_object->token_id = '';
82
-			$source_object->customer = $this->get_stripe_customer_id( $order );
82
+			$source_object->customer = $this->get_stripe_customer_id($order);
83 83
 			$source_object->source   = $source;
84 84
 
85 85
 			/**
86 86
 			 * First check if the source is chargeable at this time. If not,
87 87
 			 * webhook will take care of it later.
88 88
 			 */
89
-			$source_info = WC_Stripe_API::retrieve( 'sources/' . $source );
89
+			$source_info = WC_Stripe_API::retrieve('sources/' . $source);
90 90
 
91
-			if ( ! empty( $source_info->error ) ) {
92
-				throw new Exception( $source_info->error->message );
91
+			if ( ! empty($source_info->error)) {
92
+				throw new Exception($source_info->error->message);
93 93
 			}
94 94
 
95
-			if ( 'failed' === $source_info->status || 'canceled' === $source_info->status ) {
96
-				throw new Exception( __( 'Unable to process this payment, please try again or use alternative method.', 'woocommerce-gateway-stripe' ) );
95
+			if ('failed' === $source_info->status || 'canceled' === $source_info->status) {
96
+				throw new Exception(__('Unable to process this payment, please try again or use alternative method.', 'woocommerce-gateway-stripe'));
97 97
 			}
98 98
 
99 99
 			// If already consumed, then ignore request.
100
-			if ( 'consumed' === $source_info->status ) {
100
+			if ('consumed' === $source_info->status) {
101 101
 				return;
102 102
 			}
103 103
 
104 104
 			// If not chargeable, then ignore request.
105
-			if ( 'chargeable' !== $source_info->status ) {
105
+			if ('chargeable' !== $source_info->status) {
106 106
 				return;
107 107
 			}
108 108
 
109 109
 			// Make the request.
110
-			$response = WC_Stripe_API::request( $this->generate_payment_request( $order, $source_object ) );
110
+			$response = WC_Stripe_API::request($this->generate_payment_request($order, $source_object));
111 111
 
112
-			if ( ! empty( $response->error ) ) {
112
+			if ( ! empty($response->error)) {
113 113
 				// If it is an API error such connection or server, let's retry.
114
-				if ( 'api_connection_error' === $response->error->type || 'api_error' === $response->error->type ) {
115
-					if ( $retry ) {
116
-						sleep( 5 );
117
-						return $this->process_redirect_payment( $order_id, false );
114
+				if ('api_connection_error' === $response->error->type || 'api_error' === $response->error->type) {
115
+					if ($retry) {
116
+						sleep(5);
117
+						return $this->process_redirect_payment($order_id, false);
118 118
 					} else {
119 119
 						$message = 'API connection error and retries exhausted.';
120
-						$order->add_order_note( $message );
121
-						throw new Exception( $message );
120
+						$order->add_order_note($message);
121
+						throw new Exception($message);
122 122
 					}
123 123
 				}
124 124
 
125 125
 				// Customer param wrong? The user may have been deleted on stripe's end. Remove customer_id. Can be retried without.
126
-				if ( preg_match( '/No such customer/i', $response->error->message ) && $retry ) {
127
-					delete_user_meta( WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id(), '_stripe_customer_id' );
126
+				if (preg_match('/No such customer/i', $response->error->message) && $retry) {
127
+					delete_user_meta(WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id(), '_stripe_customer_id');
128 128
 
129
-					return $this->process_redirect_payment( $order_id, false );
129
+					return $this->process_redirect_payment($order_id, false);
130 130
 
131
-				} elseif ( preg_match( '/No such token/i', $response->error->message ) && $source_object->token_id ) {
131
+				} elseif (preg_match('/No such token/i', $response->error->message) && $source_object->token_id) {
132 132
 					// Source param wrong? The CARD may have been deleted on stripe's end. Remove token and show message.
133 133
 
134
-					$wc_token = WC_Payment_Tokens::get( $source_object->token_id );
134
+					$wc_token = WC_Payment_Tokens::get($source_object->token_id);
135 135
 					$wc_token->delete();
136
-					$message = __( 'This card is no longer available and has been removed.', 'woocommerce-gateway-stripe' );
137
-					$order->add_order_note( $message );
138
-					throw new Exception( $message );
136
+					$message = __('This card is no longer available and has been removed.', 'woocommerce-gateway-stripe');
137
+					$order->add_order_note($message);
138
+					throw new Exception($message);
139 139
 				}
140 140
 
141 141
 				$localized_messages = WC_Stripe_Helper::get_localized_messages();
142 142
 
143
-				$message = isset( $localized_messages[ $response->error->type ] ) ? $localized_messages[ $response->error->type ] : $response->error->message;
143
+				$message = isset($localized_messages[$response->error->type]) ? $localized_messages[$response->error->type] : $response->error->message;
144 144
 
145
-				throw new Exception( $message );
145
+				throw new Exception($message);
146 146
 			}
147 147
 
148
-			do_action( 'wc_gateway_stripe_process_redirect_payment', $response, $order );
148
+			do_action('wc_gateway_stripe_process_redirect_payment', $response, $order);
149 149
 
150
-			$this->process_response( $response, $order );
150
+			$this->process_response($response, $order);
151 151
 
152
-		} catch ( Exception $e ) {
153
-			WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() );
152
+		} catch (Exception $e) {
153
+			WC_Stripe_Logger::log('Error: ' . $e->getMessage());
154 154
 
155
-			do_action( 'wc_gateway_stripe_process_redirect_payment_error', $e, $order );
155
+			do_action('wc_gateway_stripe_process_redirect_payment_error', $e, $order);
156 156
 
157 157
 			/* translators: error message */
158
-			$order->update_status( 'failed', sprintf( __( 'Stripe payment failed: %s', 'woocommerce-gateway-stripe' ), $e->getMessage() ) );
158
+			$order->update_status('failed', sprintf(__('Stripe payment failed: %s', 'woocommerce-gateway-stripe'), $e->getMessage()));
159 159
 
160
-			if ( $order->has_status( array( 'pending', 'failed' ) ) ) {
161
-				$this->send_failed_order_email( $order_id );
160
+			if ($order->has_status(array('pending', 'failed'))) {
161
+				$this->send_failed_order_email($order_id);
162 162
 			}
163 163
 
164
-			wc_add_notice( $e->getMessage(), 'error' );
165
-			wp_safe_redirect( wc_get_checkout_url() );
164
+			wc_add_notice($e->getMessage(), 'error');
165
+			wp_safe_redirect(wc_get_checkout_url());
166 166
 			exit;
167 167
 		}
168 168
 	}
@@ -174,13 +174,13 @@  discard block
 block discarded – undo
174 174
 	 * @version 4.0.0
175 175
 	 */
176 176
 	public function maybe_process_redirect_order() {
177
-		if ( ! is_order_received_page() || empty( $_GET['client_secret'] ) || empty( $_GET['source'] ) ) {
177
+		if ( ! is_order_received_page() || empty($_GET['client_secret']) || empty($_GET['source'])) {
178 178
 			return;
179 179
 		}
180 180
 
181
-		$order_id = wc_clean( $_GET['order_id'] );
181
+		$order_id = wc_clean($_GET['order_id']);
182 182
 
183
-		$this->process_redirect_payment( $order_id );
183
+		$this->process_redirect_payment($order_id);
184 184
 	}
185 185
 
186 186
 	/**
@@ -190,52 +190,52 @@  discard block
 block discarded – undo
190 190
 	 * @version 4.0.0
191 191
 	 * @param  int $order_id
192 192
 	 */
193
-	public function capture_payment( $order_id ) {
194
-		$order = wc_get_order( $order_id );
193
+	public function capture_payment($order_id) {
194
+		$order = wc_get_order($order_id);
195 195
 
196
-		if ( 'stripe' === ( WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method() ) ) {
197
-			$charge   = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_transaction_id', true ) : $order->get_transaction_id();
198
-			$captured = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_stripe_charge_captured', true ) : $order->get_meta( '_stripe_charge_captured', true );
196
+		if ('stripe' === (WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method())) {
197
+			$charge   = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_transaction_id', true) : $order->get_transaction_id();
198
+			$captured = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_stripe_charge_captured', true) : $order->get_meta('_stripe_charge_captured', true);
199 199
 
200
-			if ( $charge && 'no' === $captured ) {
200
+			if ($charge && 'no' === $captured) {
201 201
 				$order_total = $order->get_total();
202 202
 
203
-				if ( 0 < $order->get_total_refunded() ) {
203
+				if (0 < $order->get_total_refunded()) {
204 204
 					$order_total = $order_total - $order->get_total_refunded();
205 205
 				}
206 206
 
207
-				$result = WC_Stripe_API::request( array(
208
-					'amount'   => WC_Stripe_Helper::get_stripe_amount( $order_total ),
207
+				$result = WC_Stripe_API::request(array(
208
+					'amount'   => WC_Stripe_Helper::get_stripe_amount($order_total),
209 209
 					'expand[]' => 'balance_transaction',
210
-				), 'charges/' . $charge . '/capture' );
210
+				), 'charges/' . $charge . '/capture');
211 211
 
212
-				if ( ! empty( $result->error ) ) {
212
+				if ( ! empty($result->error)) {
213 213
 					/* translators: error message */
214
-					$order->update_status( 'failed', sprintf( __( 'Unable to capture charge! %s', 'woocommerce-gateway-stripe' ), $result->error->message ) );
214
+					$order->update_status('failed', sprintf(__('Unable to capture charge! %s', 'woocommerce-gateway-stripe'), $result->error->message));
215 215
 				} else {
216 216
 					/* translators: transaction id */
217
-					$order->add_order_note( sprintf( __( 'Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe' ), $result->id ) );
218
-					WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, '_stripe_charge_captured', 'yes' ) : $order->update_meta_data( '_stripe_charge_captured', 'yes' );
217
+					$order->add_order_note(sprintf(__('Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe'), $result->id));
218
+					WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, '_stripe_charge_captured', 'yes') : $order->update_meta_data('_stripe_charge_captured', 'yes');
219 219
 
220 220
 					// Store other data such as fees
221
-					WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, '_transaction_id', $result->id ) : $order->set_transaction_id( $result->id );
221
+					WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, '_transaction_id', $result->id) : $order->set_transaction_id($result->id);
222 222
 
223
-					if ( isset( $result->balance_transaction ) && isset( $result->balance_transaction->fee ) ) {
223
+					if (isset($result->balance_transaction) && isset($result->balance_transaction->fee)) {
224 224
 						// Fees and Net needs to both come from Stripe to be accurate as the returned
225 225
 						// values are in the local currency of the Stripe account, not from WC.
226
-						$fee = ! empty( $result->balance_transaction->fee ) ? WC_Stripe_Helper::format_balance_fee( $result->balance_transaction, 'fee' ) : 0;
227
-						$net = ! empty( $result->balance_transaction->net ) ? WC_Stripe_Helper::format_balance_fee( $result->balance_transaction, 'net' ) : 0;
228
-						WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, parent::META_NAME_FEE, $fee ) : $order->update_meta_data( parent::META_NAME_FEE, $fee );
229
-						WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, parent::META_NAME_NET, $net ) : $order->update_meta_data( parent::META_NAME_NET, $net );
226
+						$fee = ! empty($result->balance_transaction->fee) ? WC_Stripe_Helper::format_balance_fee($result->balance_transaction, 'fee') : 0;
227
+						$net = ! empty($result->balance_transaction->net) ? WC_Stripe_Helper::format_balance_fee($result->balance_transaction, 'net') : 0;
228
+						WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, parent::META_NAME_FEE, $fee) : $order->update_meta_data(parent::META_NAME_FEE, $fee);
229
+						WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, parent::META_NAME_NET, $net) : $order->update_meta_data(parent::META_NAME_NET, $net);
230 230
 					}
231 231
 
232
-					if ( is_callable( array( $order, 'save' ) ) ) {
232
+					if (is_callable(array($order, 'save'))) {
233 233
 						$order->save();
234 234
 					}
235 235
 				}
236 236
 
237 237
 				// This hook fires when admin manually changes order status to processing or completed.
238
-				do_action( 'woocommerce_stripe_process_manual_capture', $order, $result );
238
+				do_action('woocommerce_stripe_process_manual_capture', $order, $result);
239 239
 			}
240 240
 		}
241 241
 	}
@@ -247,32 +247,32 @@  discard block
 block discarded – undo
247 247
 	 * @version 4.0.0
248 248
 	 * @param  int $order_id
249 249
 	 */
250
-	public function cancel_payment( $order_id ) {
251
-		$order = wc_get_order( $order_id );
250
+	public function cancel_payment($order_id) {
251
+		$order = wc_get_order($order_id);
252 252
 
253
-		if ( 'stripe' === ( WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method() ) ) {
254
-			$charge_id = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_transaction_id', true ) : $order->get_transaction_id();
253
+		if ('stripe' === (WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method())) {
254
+			$charge_id = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_transaction_id', true) : $order->get_transaction_id();
255 255
 
256
-			if ( $charge_id ) {
257
-				$result = WC_Stripe_API::request( array(
258
-					'amount' => WC_Stripe_Helper::get_stripe_amount( $order->get_total() ),
259
-				), 'charges/' . $charge_id . '/refund' );
256
+			if ($charge_id) {
257
+				$result = WC_Stripe_API::request(array(
258
+					'amount' => WC_Stripe_Helper::get_stripe_amount($order->get_total()),
259
+				), 'charges/' . $charge_id . '/refund');
260 260
 
261
-				if ( ! empty( $result->error ) ) {
262
-					$order->add_order_note( __( 'Unable to refund charge!', 'woocommerce-gateway-stripe' ) . ' ' . $result->error->message );
261
+				if ( ! empty($result->error)) {
262
+					$order->add_order_note(__('Unable to refund charge!', 'woocommerce-gateway-stripe') . ' ' . $result->error->message);
263 263
 				} else {
264 264
 					/* translators: transaction id */
265
-					$order->add_order_note( sprintf( __( 'Stripe charge refunded (Charge ID: %s)', 'woocommerce-gateway-stripe' ), $result->id ) );
266
-					WC_Stripe_Helper::is_pre_30() ? delete_post_meta( $order_id, '_stripe_charge_captured' ) : $order->delete_meta_data( '_stripe_charge_captured' );
267
-					WC_Stripe_Helper::is_pre_30() ? delete_post_meta( $order_id, '_transaction_id' ) : $order->delete_meta_data( '_stripe_transaction_id' );
265
+					$order->add_order_note(sprintf(__('Stripe charge refunded (Charge ID: %s)', 'woocommerce-gateway-stripe'), $result->id));
266
+					WC_Stripe_Helper::is_pre_30() ? delete_post_meta($order_id, '_stripe_charge_captured') : $order->delete_meta_data('_stripe_charge_captured');
267
+					WC_Stripe_Helper::is_pre_30() ? delete_post_meta($order_id, '_transaction_id') : $order->delete_meta_data('_stripe_transaction_id');
268 268
 
269
-					if ( is_callable( array( $order, 'save' ) ) ) {
269
+					if (is_callable(array($order, 'save'))) {
270 270
 						$order->save();
271 271
 					}
272 272
 				}
273 273
 
274 274
 				// This hook fires when admin manually changes order status to cancel.
275
-				do_action( 'woocommerce_stripe_process_manual_cancel', $order, $result );
275
+				do_action('woocommerce_stripe_process_manual_cancel', $order, $result);
276 276
 			}
277 277
 		}
278 278
 	}
@@ -285,8 +285,8 @@  discard block
 block discarded – undo
285 285
 	 * @param string $field
286 286
 	 * @return string $error_field
287 287
 	 */
288
-	public function normalize_field( $field ) {
289
-		$error_field = ucfirst( str_replace( '_', ' ', $field ) );
288
+	public function normalize_field($field) {
289
+		$error_field = ucfirst(str_replace('_', ' ', $field));
290 290
 
291 291
 		$org_str     = array();
292 292
 		$replace_str = array();
@@ -303,7 +303,7 @@  discard block
 block discarded – undo
303 303
 		$org_str[]     = 'sofort';
304 304
 		$replace_str[] = 'SOFORT';
305 305
 
306
-		return str_replace( $org_str, $replace_str, $error_field );
306
+		return str_replace($org_str, $replace_str, $error_field);
307 307
 	}
308 308
 
309 309
 	/**
@@ -313,151 +313,151 @@  discard block
 block discarded – undo
313 313
 	 * @version 4.0.0
314 314
 	 */
315 315
 	public function validate_checkout() {
316
-		if ( ! wp_verify_nonce( $_POST['nonce'], '_wc_stripe_nonce' ) ) {
317
-			wp_die( __( 'Cheatin&#8217; huh?', 'woocommerce-gateway-stripe' ) );
316
+		if ( ! wp_verify_nonce($_POST['nonce'], '_wc_stripe_nonce')) {
317
+			wp_die(__('Cheatin&#8217; huh?', 'woocommerce-gateway-stripe'));
318 318
 		}
319 319
 
320 320
 		$errors = new WP_Error();
321
-		parse_str( $_POST['required_fields'], $required_fields );
322
-		parse_str( $_POST['all_fields'], $all_fields );
323
-		$source_type = isset( $_POST['source_type'] ) ? wc_clean( $_POST['source_type'] ) : '';
321
+		parse_str($_POST['required_fields'], $required_fields);
322
+		parse_str($_POST['all_fields'], $all_fields);
323
+		$source_type = isset($_POST['source_type']) ? wc_clean($_POST['source_type']) : '';
324 324
 		$validate_shipping_fields = false;
325 325
 		$create_account = false;
326 326
 
327
-		array_walk_recursive( $required_fields, 'wc_clean' );
328
-		array_walk_recursive( $all_fields, 'wc_clean' );
327
+		array_walk_recursive($required_fields, 'wc_clean');
328
+		array_walk_recursive($all_fields, 'wc_clean');
329 329
 
330 330
 		// Remove unneeded required fields depending on source type.
331
-		if ( 'stripe_sepa' !== $source_type ) {
332
-			unset( $required_fields['stripe_sepa_owner'] );
333
-			unset( $required_fields['stripe_sepa_iban'] );
331
+		if ('stripe_sepa' !== $source_type) {
332
+			unset($required_fields['stripe_sepa_owner']);
333
+			unset($required_fields['stripe_sepa_iban']);
334 334
 		}
335 335
 
336
-		if ( 'stripe_sofort' !== $source_type ) {
337
-			unset( $required_fields['stripe_sofort_bank_country'] );
336
+		if ('stripe_sofort' !== $source_type) {
337
+			unset($required_fields['stripe_sofort_bank_country']);
338 338
 		}
339 339
 
340 340
 		/**
341 341
 		 * If ship to different address checkbox is checked then we need
342 342
 		 * to validate shipping fields too.
343 343
 		 */
344
-		if ( isset( $all_fields['ship_to_different_address'] ) ) {
344
+		if (isset($all_fields['ship_to_different_address'])) {
345 345
 			$validate_shipping_fields = true;
346 346
 		}
347 347
 
348 348
 		// Check if createaccount is checked.
349
-		if ( isset( $all_fields['createaccount'] ) ) {
349
+		if (isset($all_fields['createaccount'])) {
350 350
 			$create_account = true;
351 351
 		}
352 352
 
353 353
 		// Check if required fields are empty.
354
-		foreach ( $required_fields as $field => $field_value ) {
354
+		foreach ($required_fields as $field => $field_value) {
355 355
 			// Check for shipping field.
356
-			if ( preg_match( '/^shipping_/', $field ) && ! $validate_shipping_fields ) {
356
+			if (preg_match('/^shipping_/', $field) && ! $validate_shipping_fields) {
357 357
 				continue;
358 358
 			}
359 359
 
360 360
 			// Check create account name.
361
-			if ( 'account_username' === $field && ! $create_account ) {
361
+			if ('account_username' === $field && ! $create_account) {
362 362
 				continue;
363 363
 			}
364 364
 
365 365
 			// Check create account password.
366
-			if ( 'account_password' === $field && ! $create_account ) {
366
+			if ('account_password' === $field && ! $create_account) {
367 367
 				continue;
368 368
 			}
369 369
 
370 370
 			// Check if is SEPA.
371
-			if ( 'stripe_sepa' !== $source_type && 'stripe_sepa_owner' === $field ) {
371
+			if ('stripe_sepa' !== $source_type && 'stripe_sepa_owner' === $field) {
372 372
 				continue;
373 373
 			}
374 374
 
375
-			if ( 'stripe_sepa' !== $source_type && 'stripe_sepa_iban' === $field ) {
375
+			if ('stripe_sepa' !== $source_type && 'stripe_sepa_iban' === $field) {
376 376
 				$continue;
377 377
 			}
378 378
 
379
-			if ( empty( $field_value ) || '-1' === $field_value ) {
380
-				$error_field = $this->normalize_field( $field );
379
+			if (empty($field_value) || '-1' === $field_value) {
380
+				$error_field = $this->normalize_field($field);
381 381
 				/* translators: error field name */
382
-				$errors->add( 'validation', sprintf( __( '%s cannot be empty', 'woocommerce-gateway-stripe' ), $error_field ) );
382
+				$errors->add('validation', sprintf(__('%s cannot be empty', 'woocommerce-gateway-stripe'), $error_field));
383 383
 			}
384 384
 		}
385 385
 
386 386
 		// Check if email is valid format.
387
-		if ( ! empty( $required_fields['billing_email'] ) && ! is_email( $required_fields['billing_email'] ) ) {
388
-			$errors->add( 'validation', __( 'Email is not valid', 'woocommerce-gateway-stripe' ) );
387
+		if ( ! empty($required_fields['billing_email']) && ! is_email($required_fields['billing_email'])) {
388
+			$errors->add('validation', __('Email is not valid', 'woocommerce-gateway-stripe'));
389 389
 		}
390 390
 
391 391
 		// Check if phone number is valid format.
392
-		if ( ! empty( $required_fields['billing_phone'] ) ) {
393
-			$phone = wc_format_phone_number( $required_fields['billing_phone'] );
392
+		if ( ! empty($required_fields['billing_phone'])) {
393
+			$phone = wc_format_phone_number($required_fields['billing_phone']);
394 394
 
395
-			if ( '' !== $phone && ! WC_Validation::is_phone( $phone ) ) {
395
+			if ('' !== $phone && ! WC_Validation::is_phone($phone)) {
396 396
 				/* translators: %s: phone number */
397
-				$errors->add( 'validation', __( 'Please enter a valid phone number.', 'woocommerce-gateway-stripe' ) );
397
+				$errors->add('validation', __('Please enter a valid phone number.', 'woocommerce-gateway-stripe'));
398 398
 			}
399 399
 		}
400 400
 
401 401
 		// Check if postal code is valid format.
402
-		if ( ! empty( $required_fields['billing_postcode'] ) ) {
403
-			$country = isset( $required_fields['billing_country'] ) ? $required_fields['billing_country'] : WC()->customer->get_billing_country();
404
-			$postcode = wc_format_postcode( $required_fields['billing_postcode'], $country );
402
+		if ( ! empty($required_fields['billing_postcode'])) {
403
+			$country = isset($required_fields['billing_country']) ? $required_fields['billing_country'] : WC()->customer->get_billing_country();
404
+			$postcode = wc_format_postcode($required_fields['billing_postcode'], $country);
405 405
 
406
-			if ( '' !== $required_fields['billing_postcode'] && ! WC_Validation::is_postcode( $postcode, $country ) ) {
407
-				$errors->add( 'validation', __( 'Please enter a valid billing postcode / ZIP.', 'woocommerce-gateway-stripe' ) );
406
+			if ('' !== $required_fields['billing_postcode'] && ! WC_Validation::is_postcode($postcode, $country)) {
407
+				$errors->add('validation', __('Please enter a valid billing postcode / ZIP.', 'woocommerce-gateway-stripe'));
408 408
 			}
409 409
 		}
410 410
 
411
-		if ( empty( $all_fields['woocommerce_checkout_update_totals'] ) && empty( $all_fields['terms'] ) && apply_filters( 'woocommerce_checkout_show_terms', wc_get_page_id( 'terms' ) > 0 ) ) {
412
-			$errors->add( 'terms', __( 'You must accept our Terms &amp; Conditions.', 'woocommerce-gateway-stripe' ) );
411
+		if (empty($all_fields['woocommerce_checkout_update_totals']) && empty($all_fields['terms']) && apply_filters('woocommerce_checkout_show_terms', wc_get_page_id('terms') > 0)) {
412
+			$errors->add('terms', __('You must accept our Terms &amp; Conditions.', 'woocommerce-gateway-stripe'));
413 413
 		}
414 414
 
415
-		if ( WC()->cart->needs_shipping() && $validate_shipping_fields ) {
415
+		if (WC()->cart->needs_shipping() && $validate_shipping_fields) {
416 416
 			// Check if postal code is valid format.
417
-			if ( ! empty( $required_fields['shipping_postcode'] ) ) {
418
-				$country = isset( $required_fields['shipping_country'] ) ? $required_fields['shipping_country'] : WC()->customer->get_shipping_country();
419
-				$postcode = wc_format_postcode( $required_fields['shipping_postcode'], $country );
417
+			if ( ! empty($required_fields['shipping_postcode'])) {
418
+				$country = isset($required_fields['shipping_country']) ? $required_fields['shipping_country'] : WC()->customer->get_shipping_country();
419
+				$postcode = wc_format_postcode($required_fields['shipping_postcode'], $country);
420 420
 
421
-				if ( '' !== $required_fields['shipping_postcode'] && ! WC_Validation::is_postcode( $postcode, $country ) ) {
422
-					$errors->add( 'validation', __( 'Please enter a valid shipping postcode / ZIP.', 'woocommerce-gateway-stripe' ) );
421
+				if ('' !== $required_fields['shipping_postcode'] && ! WC_Validation::is_postcode($postcode, $country)) {
422
+					$errors->add('validation', __('Please enter a valid shipping postcode / ZIP.', 'woocommerce-gateway-stripe'));
423 423
 				}
424 424
 			}
425 425
 		}
426 426
 
427
-		if ( WC()->cart->needs_shipping() ) {
427
+		if (WC()->cart->needs_shipping()) {
428 428
 			$shipping_country = WC()->customer->get_shipping_country();
429 429
 
430
-			if ( empty( $shipping_country ) ) {
431
-				$errors->add( 'shipping', __( 'Please enter an address to continue.', 'woocommerce-gateway-stripe' ) );
432
-			} elseif ( ! in_array( WC()->customer->get_shipping_country(), array_keys( WC()->countries->get_shipping_countries() ) ) ) {
430
+			if (empty($shipping_country)) {
431
+				$errors->add('shipping', __('Please enter an address to continue.', 'woocommerce-gateway-stripe'));
432
+			} elseif ( ! in_array(WC()->customer->get_shipping_country(), array_keys(WC()->countries->get_shipping_countries()))) {
433 433
 				/* translators: country name */
434
-				$errors->add( 'shipping', sprintf( __( 'Unfortunately <strong>we do not ship %s</strong>. Please enter an alternative shipping address.', 'woocommerce-gateway-stripe' ), WC()->countries->shipping_to_prefix() . ' ' . WC()->customer->get_shipping_country() ) );
434
+				$errors->add('shipping', sprintf(__('Unfortunately <strong>we do not ship %s</strong>. Please enter an alternative shipping address.', 'woocommerce-gateway-stripe'), WC()->countries->shipping_to_prefix() . ' ' . WC()->customer->get_shipping_country()));
435 435
 			} else {
436
-				$chosen_shipping_methods = WC()->session->get( 'chosen_shipping_methods' );
436
+				$chosen_shipping_methods = WC()->session->get('chosen_shipping_methods');
437 437
 
438
-				foreach ( WC()->shipping->get_packages() as $i => $package ) {
439
-					if ( ! isset( $chosen_shipping_methods[ $i ], $package['rates'][ $chosen_shipping_methods[ $i ] ] ) ) {
440
-						$errors->add( 'shipping', __( 'No shipping method has been selected. Please double check your address, or contact us if you need any help.', 'woocommerce-gateway-stripe' ) );
438
+				foreach (WC()->shipping->get_packages() as $i => $package) {
439
+					if ( ! isset($chosen_shipping_methods[$i], $package['rates'][$chosen_shipping_methods[$i]])) {
440
+						$errors->add('shipping', __('No shipping method has been selected. Please double check your address, or contact us if you need any help.', 'woocommerce-gateway-stripe'));
441 441
 					}
442 442
 				}
443 443
 			}
444 444
 		}
445 445
 
446
-		if ( WC()->cart->needs_payment() ) {
446
+		if (WC()->cart->needs_payment()) {
447 447
 			$available_gateways = WC()->payment_gateways->get_available_payment_gateways();
448 448
 
449
-			if ( ! isset( $available_gateways[ $all_fields['payment_method'] ] ) ) {
450
-				$errors->add( 'payment', __( 'Invalid payment method.', 'woocommerce-gateway-stripe' ) );
449
+			if ( ! isset($available_gateways[$all_fields['payment_method']])) {
450
+				$errors->add('payment', __('Invalid payment method.', 'woocommerce-gateway-stripe'));
451 451
 			} else {
452
-				$available_gateways[ $all_fields['payment_method'] ]->validate_fields();
452
+				$available_gateways[$all_fields['payment_method']]->validate_fields();
453 453
 			}
454 454
 		}
455 455
 
456
-		if ( 0 === count( $errors->errors ) ) {
457
-			wp_send_json( 'success' );
456
+		if (0 === count($errors->errors)) {
457
+			wp_send_json('success');
458 458
 		} else {
459
-			foreach ( $errors->get_error_messages() as $message ) {
460
-				wc_add_notice( $message, 'error' );
459
+			foreach ($errors->get_error_messages() as $message) {
460
+				wc_add_notice($message, 'error');
461 461
 			}
462 462
 
463 463
 			$this->send_ajax_failure_response();
@@ -471,9 +471,9 @@  discard block
 block discarded – undo
471 471
 	 * @version 4.0.0
472 472
 	 */
473 473
 	public function send_ajax_failure_response() {
474
-		if ( is_ajax() ) {
474
+		if (is_ajax()) {
475 475
 			// only print notices if not reloading the checkout, otherwise they're lost in the page reload.
476
-			if ( ! isset( WC()->session->reload_checkout ) ) {
476
+			if ( ! isset(WC()->session->reload_checkout)) {
477 477
 				ob_start();
478 478
 				wc_print_notices();
479 479
 				$messages = ob_get_clean();
@@ -481,14 +481,14 @@  discard block
 block discarded – undo
481 481
 
482 482
 			$response = array(
483 483
 				'result'   => 'failure',
484
-				'messages' => isset( $messages ) ? $messages : '',
485
-				'refresh'  => isset( WC()->session->refresh_totals ),
486
-				'reload'   => isset( WC()->session->reload_checkout ),
484
+				'messages' => isset($messages) ? $messages : '',
485
+				'refresh'  => isset(WC()->session->refresh_totals),
486
+				'reload'   => isset(WC()->session->reload_checkout),
487 487
 			);
488 488
 
489
-			unset( WC()->session->refresh_totals, WC()->session->reload_checkout );
489
+			unset(WC()->session->refresh_totals, WC()->session->reload_checkout);
490 490
 
491
-			wp_send_json( $response );
491
+			wp_send_json($response);
492 492
 		}
493 493
 	}
494 494
 }
Please login to merge, or discard this patch.
includes/class-wc-stripe-helper.php 1 patch
Spacing   +46 added lines, -46 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
 
@@ -17,15 +17,15 @@  discard block
 block discarded – undo
17 17
 	 *
18 18
 	 * @return float|int
19 19
 	 */
20
-	public static function get_stripe_amount( $total, $currency = '' ) {
21
-		if ( ! $currency ) {
20
+	public static function get_stripe_amount($total, $currency = '') {
21
+		if ( ! $currency) {
22 22
 			$currency = get_woocommerce_currency();
23 23
 		}
24 24
 
25
-		if ( in_array( strtolower( $currency ), self::no_decimal_currencies() ) ) {
26
-			return absint( $total );
25
+		if (in_array(strtolower($currency), self::no_decimal_currencies())) {
26
+			return absint($total);
27 27
 		} else {
28
-			return absint( wc_format_decimal( ( (float) $total * 100 ), wc_get_price_decimals() ) ); // In cents.
28
+			return absint(wc_format_decimal(((float) $total * 100), wc_get_price_decimals())); // In cents.
29 29
 		}
30 30
 	}
31 31
 
@@ -37,20 +37,20 @@  discard block
 block discarded – undo
37 37
 	 * @return array
38 38
 	 */
39 39
 	public static function get_localized_messages() {
40
-		return apply_filters( 'wc_stripe_localized_messages', array(
41
-			'invalid_number'        => __( 'The card number is not a valid credit card number.', 'woocommerce-gateway-stripe' ),
42
-			'invalid_expiry_month'  => __( 'The card\'s expiration month is invalid.', 'woocommerce-gateway-stripe' ),
43
-			'invalid_expiry_year'   => __( 'The card\'s expiration year is invalid.', 'woocommerce-gateway-stripe' ),
44
-			'invalid_cvc'           => __( 'The card\'s security code is invalid.', 'woocommerce-gateway-stripe' ),
45
-			'incorrect_number'      => __( 'The card number is incorrect.', 'woocommerce-gateway-stripe' ),
46
-			'expired_card'          => __( 'The card has expired.', 'woocommerce-gateway-stripe' ),
47
-			'incorrect_cvc'         => __( 'The card\'s security code is incorrect.', 'woocommerce-gateway-stripe' ),
48
-			'incorrect_zip'         => __( 'The card\'s zip code failed validation.', 'woocommerce-gateway-stripe' ),
49
-			'card_declined'         => __( 'The card was declined.', 'woocommerce-gateway-stripe' ),
50
-			'missing'               => __( 'There is no card on a customer that is being charged.', 'woocommerce-gateway-stripe' ),
51
-			'processing_error'      => __( 'An error occurred while processing the card.', 'woocommerce-gateway-stripe' ),
52
-			'invalid_request_error' => __( 'Could not find payment information. Please try with another payment method.', 'woocommerce-gateway-stripe' ),
53
-		) );
40
+		return apply_filters('wc_stripe_localized_messages', array(
41
+			'invalid_number'        => __('The card number is not a valid credit card number.', 'woocommerce-gateway-stripe'),
42
+			'invalid_expiry_month'  => __('The card\'s expiration month is invalid.', 'woocommerce-gateway-stripe'),
43
+			'invalid_expiry_year'   => __('The card\'s expiration year is invalid.', 'woocommerce-gateway-stripe'),
44
+			'invalid_cvc'           => __('The card\'s security code is invalid.', 'woocommerce-gateway-stripe'),
45
+			'incorrect_number'      => __('The card number is incorrect.', 'woocommerce-gateway-stripe'),
46
+			'expired_card'          => __('The card has expired.', 'woocommerce-gateway-stripe'),
47
+			'incorrect_cvc'         => __('The card\'s security code is incorrect.', 'woocommerce-gateway-stripe'),
48
+			'incorrect_zip'         => __('The card\'s zip code failed validation.', 'woocommerce-gateway-stripe'),
49
+			'card_declined'         => __('The card was declined.', 'woocommerce-gateway-stripe'),
50
+			'missing'               => __('There is no card on a customer that is being charged.', 'woocommerce-gateway-stripe'),
51
+			'processing_error'      => __('An error occurred while processing the card.', 'woocommerce-gateway-stripe'),
52
+			'invalid_request_error' => __('Could not find payment information. Please try with another payment method.', 'woocommerce-gateway-stripe'),
53
+		));
54 54
 	}
55 55
 
56 56
 	/**
@@ -87,24 +87,24 @@  discard block
 block discarded – undo
87 87
 	 * @param string $type Type of number to format
88 88
 	 * @return string
89 89
 	 */
90
-	public static function format_balance_fee( $balance_transaction, $type = 'fee' ) {
91
-		if ( ! is_object( $balance_transaction ) ) {
90
+	public static function format_balance_fee($balance_transaction, $type = 'fee') {
91
+		if ( ! is_object($balance_transaction)) {
92 92
 			return;
93 93
 		}
94 94
 
95
-		if ( in_array( strtolower( $balance_transaction->currency ), self::no_decimal_currencies() ) ) {
96
-			if ( 'fee' === $type ) {
95
+		if (in_array(strtolower($balance_transaction->currency), self::no_decimal_currencies())) {
96
+			if ('fee' === $type) {
97 97
 				return $balance_transaction->fee;
98 98
 			}
99 99
 
100 100
 			return $balance_transaction->net;
101 101
 		}
102 102
 
103
-		if ( 'fee' === $type ) {
104
-			return number_format( $balance_transaction->fee / 100, 2, '.', '' );
103
+		if ('fee' === $type) {
104
+			return number_format($balance_transaction->fee / 100, 2, '.', '');
105 105
 		}
106 106
 
107
-		return number_format( $balance_transaction->net / 100, 2, '.', '' );
107
+		return number_format($balance_transaction->net / 100, 2, '.', '');
108 108
 	}
109 109
 
110 110
 	/**
@@ -112,7 +112,7 @@  discard block
 block discarded – undo
112 112
 	 */
113 113
 	public static function get_minimum_amount() {
114 114
 		// Check order amount
115
-		switch ( get_woocommerce_currency() ) {
115
+		switch (get_woocommerce_currency()) {
116 116
 			case 'USD':
117 117
 			case 'CAD':
118 118
 			case 'EUR':
@@ -157,14 +157,14 @@  discard block
 block discarded – undo
157 157
 	 * @param string $method The payment method to get the settings from.
158 158
 	 * @param string $setting The name of the setting to get.
159 159
 	 */
160
-	public static function get_settings( $method = null, $setting = null ) {
161
-		$all_settings = null === $method ? get_option( 'woocommerce_stripe_settings', array() ) : get_option( 'woocommerce_stripe_' . $method . '_settings', array() );
160
+	public static function get_settings($method = null, $setting = null) {
161
+		$all_settings = null === $method ? get_option('woocommerce_stripe_settings', array()) : get_option('woocommerce_stripe_' . $method . '_settings', array());
162 162
 
163
-		if ( null === $setting ) {
163
+		if (null === $setting) {
164 164
 			return $all_settings;
165 165
 		}
166 166
 
167
-		return isset( $all_settings[ $setting ] ) ? $all_settings[ $setting ] : '';
167
+		return isset($all_settings[$setting]) ? $all_settings[$setting] : '';
168 168
 	}
169 169
 
170 170
 	/**
@@ -175,7 +175,7 @@  discard block
 block discarded – undo
175 175
 	 * @return bool
176 176
 	 */
177 177
 	public static function is_pre_30() {
178
-		return version_compare( WC_VERSION, '3.0.0', '<' );
178
+		return version_compare(WC_VERSION, '3.0.0', '<');
179 179
 	}
180 180
 
181 181
 	/**
@@ -188,7 +188,7 @@  discard block
 block discarded – undo
188 188
 	 * @return string
189 189
 	 */
190 190
 	public static function get_webhook_url() {
191
-		return add_query_arg( 'wc-api', 'wc_stripe', trailingslashit( get_home_url() ) );
191
+		return add_query_arg('wc-api', 'wc_stripe', trailingslashit(get_home_url()));
192 192
 	}
193 193
 
194 194
 	/**
@@ -198,13 +198,13 @@  discard block
 block discarded – undo
198 198
 	 * @version 4.0.0
199 199
 	 * @param string $source_id
200 200
 	 */
201
-	public static function get_order_by_source_id( $source_id ) {
201
+	public static function get_order_by_source_id($source_id) {
202 202
 		global $wpdb;
203 203
 
204
-		$order_id = $wpdb->get_var( $wpdb->prepare( "SELECT DISTINCT ID FROM $wpdb->posts as posts LEFT JOIN $wpdb->postmeta as meta ON posts.ID = meta.post_id WHERE meta.meta_value = %s", $source_id ) );
204
+		$order_id = $wpdb->get_var($wpdb->prepare("SELECT DISTINCT ID FROM $wpdb->posts as posts LEFT JOIN $wpdb->postmeta as meta ON posts.ID = meta.post_id WHERE meta.meta_value = %s", $source_id));
205 205
 
206
-		if ( ! empty( $order_id ) ) {
207
-			return wc_get_order( $order_id );
206
+		if ( ! empty($order_id)) {
207
+			return wc_get_order($order_id);
208 208
 		}
209 209
 
210 210
 		return false;
@@ -217,13 +217,13 @@  discard block
 block discarded – undo
217 217
 	 * @version 4.0.0
218 218
 	 * @param string $charge_id
219 219
 	 */
220
-	public static function get_order_by_charge_id( $charge_id ) {
220
+	public static function get_order_by_charge_id($charge_id) {
221 221
 		global $wpdb;
222 222
 
223
-		$order_id = $wpdb->get_var( $wpdb->prepare( "SELECT DISTINCT ID FROM $wpdb->posts as posts LEFT JOIN $wpdb->postmeta as meta ON posts.ID = meta.post_id WHERE meta.meta_value = %s", $charge_id ) );
223
+		$order_id = $wpdb->get_var($wpdb->prepare("SELECT DISTINCT ID FROM $wpdb->posts as posts LEFT JOIN $wpdb->postmeta as meta ON posts.ID = meta.post_id WHERE meta.meta_value = %s", $charge_id));
224 224
 
225
-		if ( ! empty( $order_id ) ) {
226
-			return wc_get_order( $order_id );
225
+		if ( ! empty($order_id)) {
226
+			return wc_get_order($order_id);
227 227
 		}
228 228
 
229 229
 		return false;
@@ -239,13 +239,13 @@  discard block
 block discarded – undo
239 239
 	 * @param string $statement_descriptor
240 240
 	 * @return string $statement_descriptor Sanitized statement descriptor
241 241
 	 */
242
-	public static function clean_statement_descriptor( $statement_descriptor = '' ) {
243
-		$disallowed_characters = array( '<', '>', '"', "'" );
242
+	public static function clean_statement_descriptor($statement_descriptor = '') {
243
+		$disallowed_characters = array('<', '>', '"', "'");
244 244
 
245 245
 		// Remove special characters.
246
-		$statement_descriptor = str_replace( $disallowed_characters, '', $statement_descriptor );
246
+		$statement_descriptor = str_replace($disallowed_characters, '', $statement_descriptor);
247 247
 
248
-		$statement_descriptor = substr( trim( $statement_descriptor ), 0, 22 );
248
+		$statement_descriptor = substr(trim($statement_descriptor), 0, 22);
249 249
 
250 250
 		return $statement_descriptor;
251 251
 	}
Please login to merge, or discard this patch.
includes/class-wc-stripe-sepa-payment-token.php 1 patch
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3
-if ( ! defined( 'ABSPATH' ) ) {
3
+if ( ! defined('ABSPATH')) {
4 4
 	exit; // Exit if accessed directly
5 5
 }
6 6
 
@@ -35,10 +35,10 @@  discard block
 block discarded – undo
35 35
 	 * @param  string $deprecated Deprecated since WooCommerce 3.0
36 36
 	 * @return string
37 37
 	 */
38
-	public function get_display_name( $deprecated = '' ) {
38
+	public function get_display_name($deprecated = '') {
39 39
 		$display = sprintf(
40 40
 			/* translators: last 4 digits of IBAN account */
41
-			__( 'SEPA IBAN ending in %s', 'woocommerce-gateway-stripe' ),
41
+			__('SEPA IBAN ending in %s', 'woocommerce-gateway-stripe'),
42 42
 			$this->get_last4()
43 43
 		);
44 44
 
@@ -66,11 +66,11 @@  discard block
 block discarded – undo
66 66
 	 * @return boolean True if the passed data is valid
67 67
 	 */
68 68
 	public function validate() {
69
-		if ( false === parent::validate() ) {
69
+		if (false === parent::validate()) {
70 70
 			return false;
71 71
 		}
72 72
 
73
-		if ( ! $this->get_last4( 'edit' ) ) {
73
+		if ( ! $this->get_last4('edit')) {
74 74
 			return false;
75 75
 		}
76 76
 
@@ -85,8 +85,8 @@  discard block
 block discarded – undo
85 85
 	 * @param  string $context
86 86
 	 * @return string Last 4 digits
87 87
 	 */
88
-	public function get_last4( $context = 'view' ) {
89
-		return $this->get_prop( 'last4', $context );
88
+	public function get_last4($context = 'view') {
89
+		return $this->get_prop('last4', $context);
90 90
 	}
91 91
 
92 92
 	/**
@@ -95,7 +95,7 @@  discard block
 block discarded – undo
95 95
 	 * @version 4.0.0
96 96
 	 * @param string $last4
97 97
 	 */
98
-	public function set_last4( $last4 ) {
99
-		$this->set_prop( 'last4', $last4 );
98
+	public function set_last4($last4) {
99
+		$this->set_prop('last4', $last4);
100 100
 	}
101 101
 }
Please login to merge, or discard this patch.
includes/abstracts/abstract-wc-stripe-payment-gateway.php 1 patch
Spacing   +168 added lines, -169 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,10 +64,10 @@  discard block
 block discarded – undo
64 64
 	 * @version 4.0.0
65 65
 	 * @param object $order
66 66
 	 */
67
-	public function validate_minimum_order_amount( $order ) {
68
-		if ( $order->get_total() * 100 < WC_Stripe_Helper::get_minimum_amount() ) {
67
+	public function validate_minimum_order_amount($order) {
68
+		if ($order->get_total() * 100 < WC_Stripe_Helper::get_minimum_amount()) {
69 69
 			/* translators: 1) dollar amount */
70
-			throw new Exception( sprintf( __( 'Sorry, the minimum allowed order total is %1$s to use this payment method.', 'woocommerce-gateway-stripe' ), wc_price( WC_Stripe_Helper::get_minimum_amount() / 100 ) ) );
70
+			throw new Exception(sprintf(__('Sorry, the minimum allowed order total is %1$s to use this payment method.', 'woocommerce-gateway-stripe'), wc_price(WC_Stripe_Helper::get_minimum_amount() / 100)));
71 71
 		}
72 72
 	}
73 73
 
@@ -77,14 +77,14 @@  discard block
 block discarded – undo
77 77
 	 * @since 4.0.0
78 78
 	 * @version 4.0.0
79 79
 	 */
80
-	public function get_transaction_url( $order ) {
81
-		if ( $this->testmode ) {
80
+	public function get_transaction_url($order) {
81
+		if ($this->testmode) {
82 82
 			$this->view_transaction_url = 'https://dashboard.stripe.com/test/payments/%s';
83 83
 		} else {
84 84
 			$this->view_transaction_url = 'https://dashboard.stripe.com/payments/%s';
85 85
 		}
86 86
 
87
-		return parent::get_transaction_url( $order );
87
+		return parent::get_transaction_url($order);
88 88
 	}
89 89
 
90 90
 	/**
@@ -93,15 +93,15 @@  discard block
 block discarded – undo
93 93
 	 * @since 4.0.0
94 94
 	 * @version 4.0.0
95 95
 	 */
96
-	public function get_stripe_customer_id( $order ) {
97
-		$customer = get_user_meta( WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id(), '_stripe_customer_id', true );
96
+	public function get_stripe_customer_id($order) {
97
+		$customer = get_user_meta(WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id(), '_stripe_customer_id', true);
98 98
 
99
-		if ( empty( $customer ) ) {
99
+		if (empty($customer)) {
100 100
 			// Try to get it via the order.
101
-			if ( WC_Stripe_Helper::is_pre_30() ) {
102
-				return get_post_meta( $order->id, '_stripe_customer_id', true );
101
+			if (WC_Stripe_Helper::is_pre_30()) {
102
+				return get_post_meta($order->id, '_stripe_customer_id', true);
103 103
 			} else {
104
-				return $order->get_meta( '_stripe_customer_id', true );
104
+				return $order->get_meta('_stripe_customer_id', true);
105 105
 			}
106 106
 		} else {
107 107
 			return $customer;
@@ -118,9 +118,9 @@  discard block
 block discarded – undo
118 118
 	 * @param object $order
119 119
 	 * @param int $id Stripe session id.
120 120
 	 */
121
-	public function get_stripe_return_url( $order = null, $id = null ) {
122
-		if ( is_object( $order ) ) {
123
-			if ( empty( $id ) ) {
121
+	public function get_stripe_return_url($order = null, $id = null) {
122
+		if (is_object($order)) {
123
+			if (empty($id)) {
124 124
 				$id = uniqid();
125 125
 			}
126 126
 
@@ -131,10 +131,10 @@  discard block
 block discarded – undo
131 131
 				'order_id'       => $order_id,
132 132
 			);
133 133
 
134
-			return esc_url_raw( add_query_arg( $args, $this->get_return_url( $order ) ) );
134
+			return esc_url_raw(add_query_arg($args, $this->get_return_url($order)));
135 135
 		}
136 136
 
137
-		return esc_url_raw( add_query_arg( array( 'utm_nooverride' => '1' ), $this->get_return_url() ) );
137
+		return esc_url_raw(add_query_arg(array('utm_nooverride' => '1'), $this->get_return_url()));
138 138
 	}
139 139
 
140 140
 	/**
@@ -146,48 +146,47 @@  discard block
 block discarded – undo
146 146
 	 * @param  object $source
147 147
 	 * @return array()
148 148
 	 */
149
-	public function generate_payment_request( $order, $source ) {
150
-		$settings                          = get_option( 'woocommerce_stripe_settings', array() );
151
-		$statement_descriptor              = ! empty( $settings['statement_descriptor'] ) ? str_replace( "'", '', $settings['statement_descriptor'] ) : '';
152
-		$capture                           = ! empty( $settings['capture'] ) && 'yes' === $settings['capture'] ? true : false;
149
+	public function generate_payment_request($order, $source) {
150
+		$settings                          = get_option('woocommerce_stripe_settings', array());
151
+		$statement_descriptor              = ! empty($settings['statement_descriptor']) ? str_replace("'", '', $settings['statement_descriptor']) : '';
152
+		$capture                           = ! empty($settings['capture']) && 'yes' === $settings['capture'] ? true : false;
153 153
 		$post_data                         = array();
154
-		$post_data['currency']             = strtolower( WC_Stripe_Helper::is_pre_30() ? $order->get_order_currency() : $order->get_currency() );
155
-		$post_data['amount']               = WC_Stripe_Helper::get_stripe_amount( $order->get_total(), $post_data['currency'] );
154
+		$post_data['currency']             = strtolower(WC_Stripe_Helper::is_pre_30() ? $order->get_order_currency() : $order->get_currency());
155
+		$post_data['amount']               = WC_Stripe_Helper::get_stripe_amount($order->get_total(), $post_data['currency']);
156 156
 		/* translators: 1) blog name 2) order number */
157
-		$post_data['description']          = sprintf( __( '%1$s - Order %2$s', 'woocommerce-gateway-stripe' ), wp_specialchars_decode( get_bloginfo( 'name' ), ENT_QUOTES ), $order->get_order_number() );
157
+		$post_data['description']          = sprintf(__('%1$s - Order %2$s', 'woocommerce-gateway-stripe'), wp_specialchars_decode(get_bloginfo('name'), ENT_QUOTES), $order->get_order_number());
158 158
 		$billing_email      = WC_Stripe_Helper::is_pre_30() ? $order->billing_email : $order->get_billing_email();
159 159
 		$billing_first_name = WC_Stripe_Helper::is_pre_30() ? $order->billing_first_name : $order->get_billing_first_name();
160 160
 		$billing_last_name  = WC_Stripe_Helper::is_pre_30() ? $order->billing_last_name : $order->get_billing_last_name();
161 161
 
162
-		if ( ! empty( $billing_email ) && apply_filters( 'wc_stripe_send_stripe_receipt', false ) ) {
162
+		if ( ! empty($billing_email) && apply_filters('wc_stripe_send_stripe_receipt', false)) {
163 163
 			$post_data['receipt_email'] = $billing_email;
164 164
 		}
165 165
 
166
-		switch ( WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method() ) {
167
-			case 'stripe':
168
-				if ( ! empty( $statement_descriptor ) ) {
169
-					$post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor( $statement_descriptor );
166
+		switch (WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method()) {
167
+			case 'stripe' : if ( ! empty($statement_descriptor)) {
168
+					$post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor($statement_descriptor);
170 169
 				}
171 170
 
172
-				$post_data['capture']              = $capture ? 'true' : 'false';
171
+				$post_data['capture'] = $capture ? 'true' : 'false';
173 172
 				break;
174 173
 		}
175 174
 
176 175
 		$post_data['expand[]'] = 'balance_transaction';
177 176
 
178 177
 		$metadata = array(
179
-			__( 'customer_name', 'woocommerce-gateway-stripe' ) => sanitize_text_field( $billing_first_name ) . ' ' . sanitize_text_field( $billing_last_name ),
180
-			__( 'customer_email', 'woocommerce-gateway-stripe' ) => sanitize_email( $billing_email ),
178
+			__('customer_name', 'woocommerce-gateway-stripe') => sanitize_text_field($billing_first_name) . ' ' . sanitize_text_field($billing_last_name),
179
+			__('customer_email', 'woocommerce-gateway-stripe') => sanitize_email($billing_email),
181 180
 			'order_id' => WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(),
182 181
 		);
183 182
 
184
-		$post_data['metadata'] = apply_filters( 'wc_stripe_payment_metadata', $metadata, $order, $source );
183
+		$post_data['metadata'] = apply_filters('wc_stripe_payment_metadata', $metadata, $order, $source);
185 184
 
186
-		if ( $source->customer ) {
185
+		if ($source->customer) {
187 186
 			$post_data['customer'] = $source->customer;
188 187
 		}
189 188
 
190
-		if ( $source->source ) {
189
+		if ($source->source) {
191 190
 			$post_data['source'] = $source->source;
192 191
 		}
193 192
 
@@ -199,75 +198,75 @@  discard block
 block discarded – undo
199 198
 		 * @param WC_Order $order
200 199
 		 * @param object $source
201 200
 		 */
202
-		return apply_filters( 'wc_stripe_generate_payment_request', $post_data, $order, $source );
201
+		return apply_filters('wc_stripe_generate_payment_request', $post_data, $order, $source);
203 202
 	}
204 203
 
205 204
 	/**
206 205
 	 * Store extra meta data for an order from a Stripe Response.
207 206
 	 */
208
-	public function process_response( $response, $order ) {
209
-		WC_Stripe_Logger::log( 'Processing response: ' . print_r( $response, true ) );
207
+	public function process_response($response, $order) {
208
+		WC_Stripe_Logger::log('Processing response: ' . print_r($response, true));
210 209
 
211 210
 		$order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
212 211
 
213 212
 		// Store charge data
214
-		WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, '_stripe_charge_captured', $response->captured ? 'yes' : 'no' ) : $order->update_meta_data( '_stripe_charge_captured', $response->captured ? 'yes' : 'no' );
213
+		WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, '_stripe_charge_captured', $response->captured ? 'yes' : 'no') : $order->update_meta_data('_stripe_charge_captured', $response->captured ? 'yes' : 'no');
215 214
 
216 215
 		// Store other data such as fees
217
-		if ( isset( $response->balance_transaction ) && isset( $response->balance_transaction->fee ) ) {
216
+		if (isset($response->balance_transaction) && isset($response->balance_transaction->fee)) {
218 217
 			// Fees and Net needs to both come from Stripe to be accurate as the returned
219 218
 			// values are in the local currency of the Stripe account, not from WC.
220
-			$fee = ! empty( $response->balance_transaction->fee ) ? WC_Stripe_Helper::format_balance_fee( $response->balance_transaction, 'fee' ) : 0;
221
-			$net = ! empty( $response->balance_transaction->net ) ? WC_Stripe_Helper::format_balance_fee( $response->balance_transaction, 'net' ) : 0;
222
-			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 );
223
-			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 );
219
+			$fee = ! empty($response->balance_transaction->fee) ? WC_Stripe_Helper::format_balance_fee($response->balance_transaction, 'fee') : 0;
220
+			$net = ! empty($response->balance_transaction->net) ? WC_Stripe_Helper::format_balance_fee($response->balance_transaction, 'net') : 0;
221
+			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);
222
+			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);
224 223
 		}
225 224
 
226
-		if ( $response->captured ) {
225
+		if ($response->captured) {
227 226
 			/**
228 227
 			 * Charge can be captured but in a pending state. Payment methods
229 228
 			 * that are asynchronous may take couple days to clear. Webhook will
230 229
 			 * take care of the status changes.
231 230
 			 */
232
-			if ( 'pending' === $response->status ) {
233
-				if ( ! wc_string_to_bool( get_post_meta( $order_id, '_order_stock_reduced', true ) ) ) {
234
-					WC_Stripe_Helper::is_pre_30() ? $order->reduce_order_stock() : wc_reduce_stock_levels( $order_id );
231
+			if ('pending' === $response->status) {
232
+				if ( ! wc_string_to_bool(get_post_meta($order_id, '_order_stock_reduced', true))) {
233
+					WC_Stripe_Helper::is_pre_30() ? $order->reduce_order_stock() : wc_reduce_stock_levels($order_id);
235 234
 				}
236 235
 
237
-				WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, '_transaction_id', $response->id, true ) : $order->set_transaction_id( $response->id );
236
+				WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, '_transaction_id', $response->id, true) : $order->set_transaction_id($response->id);
238 237
 				/* translators: transaction id */
239
-				$order->update_status( 'on-hold', sprintf( __( 'Stripe charge awaiting payment: %s.', 'woocommerce-gateway-stripe' ), $response->id ) );
238
+				$order->update_status('on-hold', sprintf(__('Stripe charge awaiting payment: %s.', 'woocommerce-gateway-stripe'), $response->id));
240 239
 			}
241 240
 
242
-			if ( 'succeeded' === $response->status ) {
243
-				$order->payment_complete( $response->id );
241
+			if ('succeeded' === $response->status) {
242
+				$order->payment_complete($response->id);
244 243
 
245 244
 				/* translators: transaction id */
246
-				$message = sprintf( __( 'Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe' ), $response->id );
247
-				$order->add_order_note( $message );
245
+				$message = sprintf(__('Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe'), $response->id);
246
+				$order->add_order_note($message);
248 247
 			}
249 248
 
250
-			if ( 'failed' === $response->status ) {
251
-				$error_msg = __( 'Payment processing failed. Please retry.', 'woocommerce-gateway-stripe' );
252
-				$order->add_order_note( $error_msg );
253
-				throw new Exception( $error_msg );
249
+			if ('failed' === $response->status) {
250
+				$error_msg = __('Payment processing failed. Please retry.', 'woocommerce-gateway-stripe');
251
+				$order->add_order_note($error_msg);
252
+				throw new Exception($error_msg);
254 253
 			}
255 254
 		} else {
256
-			WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, '_transaction_id', $response->id, true ) : $order->set_transaction_id( $response->id );
255
+			WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, '_transaction_id', $response->id, true) : $order->set_transaction_id($response->id);
257 256
 
258
-			if ( $order->has_status( array( 'pending', 'failed' ) ) ) {
259
-				WC_Stripe_Helper::is_pre_30() ? $order->reduce_order_stock() : wc_reduce_stock_levels( $order_id );
257
+			if ($order->has_status(array('pending', 'failed'))) {
258
+				WC_Stripe_Helper::is_pre_30() ? $order->reduce_order_stock() : wc_reduce_stock_levels($order_id);
260 259
 			}
261 260
 
262 261
 			/* translators: transaction id */
263
-			$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 ) );
262
+			$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));
264 263
 		}
265 264
 
266
-		if ( is_callable( array( $order, 'save' ) ) ) {
265
+		if (is_callable(array($order, 'save'))) {
267 266
 			$order->save();
268 267
 		}
269 268
 
270
-		do_action( 'wc_gateway_stripe_process_response', $response, $order );
269
+		do_action('wc_gateway_stripe_process_response', $response, $order);
271 270
 
272 271
 		return $response;
273 272
 	}
@@ -280,10 +279,10 @@  discard block
 block discarded – undo
280 279
 	 * @param int $order_id
281 280
 	 * @return null
282 281
 	 */
283
-	public function send_failed_order_email( $order_id ) {
282
+	public function send_failed_order_email($order_id) {
284 283
 		$emails = WC()->mailer()->get_emails();
285
-		if ( ! empty( $emails ) && ! empty( $order_id ) ) {
286
-			$emails['WC_Email_Failed_Order']->trigger( $order_id );
284
+		if ( ! empty($emails) && ! empty($order_id)) {
285
+			$emails['WC_Email_Failed_Order']->trigger($order_id);
287 286
 		}
288 287
 	}
289 288
 
@@ -295,7 +294,7 @@  discard block
 block discarded – undo
295 294
 	 * @param object $order
296 295
 	 * @return object $details
297 296
 	 */
298
-	public function get_owner_details( $order ) {
297
+	public function get_owner_details($order) {
299 298
 		$billing_first_name = WC_Stripe_Helper::is_pre_30() ? $order->billing_first_name : $order->get_billing_first_name();
300 299
 		$billing_last_name  = WC_Stripe_Helper::is_pre_30() ? $order->billing_last_name : $order->get_billing_last_name();
301 300
 
@@ -306,8 +305,8 @@  discard block
 block discarded – undo
306 305
 
307 306
 		$phone                             = WC_Stripe_Helper::is_pre_30() ? $order->billing_phone : $order->get_billing_phone();
308 307
 
309
-		if ( ! empty( $phone ) ) {
310
-			$details['phone']              = $phone;
308
+		if ( ! empty($phone)) {
309
+			$details['phone'] = $phone;
311 310
 		}
312 311
 
313 312
 		$details['address']['line1']       = WC_Stripe_Helper::is_pre_30() ? $order->billing_address_1 : $order->get_billing_address_1();
@@ -317,7 +316,7 @@  discard block
 block discarded – undo
317 316
 		$details['address']['postal_code'] = WC_Stripe_Helper::is_pre_30() ? $order->billing_postcode : $order->get_billing_postcode();
318 317
 		$details['address']['country']     = WC_Stripe_Helper::is_pre_30() ? $order->billing_country : $order->get_billing_country();
319 318
 
320
-		return (object) apply_filters( 'wc_stripe_owner_details', $details, $order );
319
+		return (object) apply_filters('wc_stripe_owner_details', $details, $order);
321 320
 	}
322 321
 
323 322
 	/**
@@ -333,58 +332,58 @@  discard block
 block discarded – undo
333 332
 	 * @throws Exception When card was not added or for and invalid card.
334 333
 	 * @return object
335 334
 	 */
336
-	public function prepare_source( $user_id, $force_save_source = false ) {
337
-		$customer           = new WC_Stripe_Customer( $user_id );
335
+	public function prepare_source($user_id, $force_save_source = false) {
336
+		$customer           = new WC_Stripe_Customer($user_id);
338 337
 		$set_customer       = true;
339
-		$force_save_source  = apply_filters( 'wc_stripe_force_save_source', $force_save_source, $customer );
338
+		$force_save_source  = apply_filters('wc_stripe_force_save_source', $force_save_source, $customer);
340 339
 		$source             = '';
341 340
 		$wc_token_id        = false;
342
-		$payment_method     = isset( $_POST['payment_method'] ) ? wc_clean( $_POST['payment_method'] ) : 'stripe';
341
+		$payment_method     = isset($_POST['payment_method']) ? wc_clean($_POST['payment_method']) : 'stripe';
343 342
 
344 343
 		// New CC info was entered and we have a new source to process.
345
-		if ( ! empty( $_POST['stripe_source'] ) ) {
344
+		if ( ! empty($_POST['stripe_source'])) {
346 345
 			// This gets the source object from Stripe.
347
-			$source = json_decode( wc_clean( stripslashes( $_POST['stripe_source'] ) ) );
346
+			$source = json_decode(wc_clean(stripslashes($_POST['stripe_source'])));
348 347
 
349 348
 			// This checks to see if customer opted to save the payment method to file.
350
-			$maybe_saved_card = isset( $_POST[ 'wc-' . $payment_method . '-new-payment-method' ] ) && ! empty( $_POST[ 'wc-' . $payment_method . '-new-payment-method' ] );
349
+			$maybe_saved_card = isset($_POST['wc-' . $payment_method . '-new-payment-method']) && ! empty($_POST['wc-' . $payment_method . '-new-payment-method']);
351 350
 
352 351
 			/**
353 352
 			 * This is true if the user wants to store the card to their account.
354 353
 			 * Criteria to save to file is they are logged in, they opted to save or product requirements and the source is
355 354
 			 * actually reusable. Either that or force_save_source is true.
356 355
 			 */
357
-			if ( ( $user_id && $this->saved_cards && $maybe_saved_card && 'reusable' === $source->usage ) || $force_save_source ) {
358
-				$source = $customer->add_source( $source->id );
356
+			if (($user_id && $this->saved_cards && $maybe_saved_card && 'reusable' === $source->usage) || $force_save_source) {
357
+				$source = $customer->add_source($source->id);
359 358
 
360
-				if ( ! empty( $source->error ) ) {
361
-					throw new Exception( $source->error->message );
359
+				if ( ! empty($source->error)) {
360
+					throw new Exception($source->error->message);
362 361
 				}
363 362
 			} else {
364 363
 				$source = $source->id;
365 364
 			}
366
-		} elseif ( isset( $_POST[ 'wc-' . $payment_method . '-payment-token' ] ) && 'new' !== $_POST[ 'wc-' . $payment_method . '-payment-token' ] ) {
365
+		} elseif (isset($_POST['wc-' . $payment_method . '-payment-token']) && 'new' !== $_POST['wc-' . $payment_method . '-payment-token']) {
367 366
 			// Use an existing token, and then process the payment
368 367
 
369
-			$wc_token_id = wc_clean( $_POST[ 'wc-' . $payment_method . '-payment-token' ] );
370
-			$wc_token    = WC_Payment_Tokens::get( $wc_token_id );
368
+			$wc_token_id = wc_clean($_POST['wc-' . $payment_method . '-payment-token']);
369
+			$wc_token    = WC_Payment_Tokens::get($wc_token_id);
371 370
 
372
-			if ( ! $wc_token || $wc_token->get_user_id() !== get_current_user_id() ) {
373
-				WC()->session->set( 'refresh_totals', true );
374
-				throw new Exception( __( 'Invalid payment method. Please input a new card number.', 'woocommerce-gateway-stripe' ) );
371
+			if ( ! $wc_token || $wc_token->get_user_id() !== get_current_user_id()) {
372
+				WC()->session->set('refresh_totals', true);
373
+				throw new Exception(__('Invalid payment method. Please input a new card number.', 'woocommerce-gateway-stripe'));
375 374
 			}
376 375
 
377 376
 			$source = $wc_token->get_token();
378
-		} elseif ( isset( $_POST['stripe_token'] ) && 'new' !== $_POST['stripe_token'] ) {
379
-			$stripe_token     = wc_clean( $_POST['stripe_token'] );
380
-			$maybe_saved_card = isset( $_POST[ 'wc-' . $payment_method . '-new-payment-method' ] ) && ! empty( $_POST[ 'wc-' . $payment_method . '-new-payment-method' ] );
377
+		} elseif (isset($_POST['stripe_token']) && 'new' !== $_POST['stripe_token']) {
378
+			$stripe_token     = wc_clean($_POST['stripe_token']);
379
+			$maybe_saved_card = isset($_POST['wc-' . $payment_method . '-new-payment-method']) && ! empty($_POST['wc-' . $payment_method . '-new-payment-method']);
381 380
 
382 381
 			// This is true if the user wants to store the card to their account.
383
-			if ( ( $user_id && $this->saved_cards && $maybe_saved_card ) || $force_save_source ) {
384
-				$source = $customer->add_source( $stripe_token );
382
+			if (($user_id && $this->saved_cards && $maybe_saved_card) || $force_save_source) {
383
+				$source = $customer->add_source($stripe_token);
385 384
 
386
-				if ( ! empty( $source->error ) ) {
387
-					throw new Exception( $source->error->message );
385
+				if ( ! empty($source->error)) {
386
+					throw new Exception($source->error->message);
388 387
 				}
389 388
 			} else {
390 389
 				$set_customer = false;
@@ -392,7 +391,7 @@  discard block
 block discarded – undo
392 391
 			}
393 392
 		}
394 393
 
395
-		if ( ! $set_customer ) {
394
+		if ( ! $set_customer) {
396 395
 			$customer_id = false;
397 396
 		} else {
398 397
 			$customer_id = $customer->get_id() ? $customer->get_id() : false;
@@ -413,27 +412,27 @@  discard block
 block discarded – undo
413 412
 	 * @param WC_Order $order For to which the source applies.
414 413
 	 * @param stdClass $source Source information.
415 414
 	 */
416
-	public function save_source( $order, $source ) {
415
+	public function save_source($order, $source) {
417 416
 		$order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
418 417
 
419 418
 		// Store source in the order.
420
-		if ( $source->customer ) {
421
-			if ( WC_Stripe_Helper::is_pre_30() ) {
422
-				update_post_meta( $order_id, '_stripe_customer_id', $source->customer );
419
+		if ($source->customer) {
420
+			if (WC_Stripe_Helper::is_pre_30()) {
421
+				update_post_meta($order_id, '_stripe_customer_id', $source->customer);
423 422
 			} else {
424
-				$order->update_meta_data( '_stripe_customer_id', $source->customer );
423
+				$order->update_meta_data('_stripe_customer_id', $source->customer);
425 424
 			}
426 425
 		}
427 426
 
428
-		if ( $source->source ) {
429
-			if ( WC_Stripe_Helper::is_pre_30() ) {
430
-				update_post_meta( $order_id, '_stripe_source_id', $source->source );
427
+		if ($source->source) {
428
+			if (WC_Stripe_Helper::is_pre_30()) {
429
+				update_post_meta($order_id, '_stripe_source_id', $source->source);
431 430
 			} else {
432
-				$order->update_meta_data( '_stripe_source_id', $source->source );
431
+				$order->update_meta_data('_stripe_source_id', $source->source);
433 432
 			}
434 433
 		}
435 434
 
436
-		if ( is_callable( array( $order, 'save' ) ) ) {
435
+		if (is_callable(array($order, 'save'))) {
437 436
 			$order->save();
438 437
 		}
439 438
 	}
@@ -451,35 +450,35 @@  discard block
 block discarded – undo
451 450
 	 * @param object $order
452 451
 	 * @return object
453 452
 	 */
454
-	public function prepare_order_source( $order = null ) {
453
+	public function prepare_order_source($order = null) {
455 454
 		$stripe_customer = new WC_Stripe_Customer();
456 455
 		$stripe_source   = false;
457 456
 		$token_id        = false;
458 457
 
459
-		if ( $order ) {
458
+		if ($order) {
460 459
 			$order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
461 460
 
462
-			$stripe_customer_id = get_post_meta( $order_id, '_stripe_customer_id', true );
461
+			$stripe_customer_id = get_post_meta($order_id, '_stripe_customer_id', true);
463 462
 
464
-			if ( $stripe_customer_id ) {
465
-				$stripe_customer->set_id( $stripe_customer_id );
463
+			if ($stripe_customer_id) {
464
+				$stripe_customer->set_id($stripe_customer_id);
466 465
 			}
467 466
 
468
-			$source_id = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_stripe_source_id', true ) : $order->get_meta( '_stripe_source_id', true );
467
+			$source_id = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_stripe_source_id', true) : $order->get_meta('_stripe_source_id', true);
469 468
 
470 469
 			// Since 4.0.0, we changed card to source so we need to account for that.
471
-			if ( empty( $source_id ) ) {
472
-				$source_id = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_stripe_card_id', true ) : $order->get_meta( '_stripe_card_id', true );
470
+			if (empty($source_id)) {
471
+				$source_id = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_stripe_card_id', true) : $order->get_meta('_stripe_card_id', true);
473 472
 
474 473
 				// Take this opportunity to update the key name.
475
-				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 );
474
+				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);
476 475
 
477
-				if ( is_callable( array( $order, 'save' ) ) ) {
476
+				if (is_callable(array($order, 'save'))) {
478 477
 					$order->save();
479 478
 				}
480 479
 			}
481 480
 
482
-			if ( $source_id ) {
481
+			if ($source_id) {
483 482
 				$stripe_source = $source_id;
484 483
 			}
485 484
 		}
@@ -500,27 +499,27 @@  discard block
 block discarded – undo
500 499
 	 * @param object $order The order object
501 500
 	 * @param int $balance_transaction_id
502 501
 	 */
503
-	public function update_fees( $order, $balance_transaction_id ) {
502
+	public function update_fees($order, $balance_transaction_id) {
504 503
 		$order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
505 504
 
506
-		$balance_transaction = WC_Stripe_API::retrieve( 'balance/history/' . $balance_transaction_id );
505
+		$balance_transaction = WC_Stripe_API::retrieve('balance/history/' . $balance_transaction_id);
507 506
 
508
-		if ( empty( $balance_transaction->error ) ) {
509
-			if ( isset( $balance_transaction ) && isset( $balance_transaction->fee ) ) {
507
+		if (empty($balance_transaction->error)) {
508
+			if (isset($balance_transaction) && isset($balance_transaction->fee)) {
510 509
 				// Fees and Net needs to both come from Stripe to be accurate as the returned
511 510
 				// values are in the local currency of the Stripe account, not from WC.
512
-				$fee = ! empty( $balance_transaction->fee ) ? WC_Stripe_Helper::format_balance_fee( $balance_transaction, 'fee' ) : 0;
513
-				$net = ! empty( $balance_transaction->net ) ? WC_Stripe_Helper::format_balance_fee( $balance_transaction, 'net' ) : 0;
511
+				$fee = ! empty($balance_transaction->fee) ? WC_Stripe_Helper::format_balance_fee($balance_transaction, 'fee') : 0;
512
+				$net = ! empty($balance_transaction->net) ? WC_Stripe_Helper::format_balance_fee($balance_transaction, 'net') : 0;
514 513
 
515
-				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 );
516
-				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 );
514
+				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);
515
+				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);
517 516
 
518
-				if ( is_callable( array( $order, 'save' ) ) ) {
517
+				if (is_callable(array($order, 'save'))) {
519 518
 					$order->save();
520 519
 				}
521 520
 			}
522 521
 		} else {
523
-			WC_Stripe_Logger::log( "Unable to update fees/net meta for order: {$order_id}" );
522
+			WC_Stripe_Logger::log("Unable to update fees/net meta for order: {$order_id}");
524 523
 		}
525 524
 	}
526 525
 
@@ -533,53 +532,53 @@  discard block
 block discarded – undo
533 532
 	 * @param  float $amount
534 533
 	 * @return bool
535 534
 	 */
536
-	public function process_refund( $order_id, $amount = null, $reason = '' ) {
537
-		$order = wc_get_order( $order_id );
535
+	public function process_refund($order_id, $amount = null, $reason = '') {
536
+		$order = wc_get_order($order_id);
538 537
 
539
-		if ( ! $order || ! $order->get_transaction_id() ) {
538
+		if ( ! $order || ! $order->get_transaction_id()) {
540 539
 			return false;
541 540
 		}
542 541
 
543 542
 		$body = array();
544 543
 
545
-		if ( WC_Stripe_Helper::is_pre_30() ) {
546
-			$order_currency = get_post_meta( $order_id, '_order_currency', true );
544
+		if (WC_Stripe_Helper::is_pre_30()) {
545
+			$order_currency = get_post_meta($order_id, '_order_currency', true);
547 546
 		} else {
548 547
 			$order_currency = $order->get_currency();
549 548
 		}
550 549
 
551
-		if ( ! is_null( $amount ) ) {
552
-			$body['amount'] = WC_Stripe_Helper::get_stripe_amount( $amount, $order_currency );
550
+		if ( ! is_null($amount)) {
551
+			$body['amount'] = WC_Stripe_Helper::get_stripe_amount($amount, $order_currency);
553 552
 		}
554 553
 
555
-		if ( $reason ) {
554
+		if ($reason) {
556 555
 			$body['metadata'] = array(
557 556
 				'reason' => $reason,
558 557
 			);
559 558
 		}
560 559
 
561
-		WC_Stripe_Logger::log( "Info: Beginning refund for order {$order->get_transaction_id()} for the amount of {$amount}" );
560
+		WC_Stripe_Logger::log("Info: Beginning refund for order {$order->get_transaction_id()} for the amount of {$amount}");
562 561
 
563
-		$response = WC_Stripe_API::request( $body, 'charges/' . $order->get_transaction_id() . '/refunds' );
562
+		$response = WC_Stripe_API::request($body, 'charges/' . $order->get_transaction_id() . '/refunds');
564 563
 
565
-		if ( ! empty( $response->error ) ) {
566
-			WC_Stripe_Logger::log( 'Error: ' . $response->error->message );
564
+		if ( ! empty($response->error)) {
565
+			WC_Stripe_Logger::log('Error: ' . $response->error->message);
567 566
 			return $response;
568
-		} elseif ( ! empty( $response->id ) ) {
569
-			$amount = wc_price( $response->amount / 100 );
567
+		} elseif ( ! empty($response->id)) {
568
+			$amount = wc_price($response->amount / 100);
570 569
 
571
-			if ( in_array( strtolower( $order->get_currency() ), WC_Stripe_Helper::no_decimal_currencies() ) ) {
572
-				$amount = wc_price( $response->amount );
570
+			if (in_array(strtolower($order->get_currency()), WC_Stripe_Helper::no_decimal_currencies())) {
571
+				$amount = wc_price($response->amount);
573 572
 			}
574 573
 
575
-			if ( isset( $response->balance_transaction ) ) {
576
-				$this->update_fees( $order, $response->balance_transaction );
574
+			if (isset($response->balance_transaction)) {
575
+				$this->update_fees($order, $response->balance_transaction);
577 576
 			}
578 577
 
579 578
 			/* translators: 1) dollar amount 2) transaction id 3) refund message */
580
-			$refund_message = sprintf( __( 'Refunded %1$s - Refund ID: %2$s - Reason: %3$s', 'woocommerce-gateway-stripe' ), $amount, $response->id, $reason );
581
-			$order->add_order_note( $refund_message );
582
-			WC_Stripe_Logger::log( 'Success: ' . html_entity_decode( strip_tags( $refund_message ) ) );
579
+			$refund_message = sprintf(__('Refunded %1$s - Refund ID: %2$s - Reason: %3$s', 'woocommerce-gateway-stripe'), $amount, $response->id, $reason);
580
+			$order->add_order_note($refund_message);
581
+			WC_Stripe_Logger::log('Success: ' . html_entity_decode(strip_tags($refund_message)));
583 582
 
584 583
 			return true;
585 584
 		}
@@ -594,41 +593,41 @@  discard block
 block discarded – undo
594 593
 	 */
595 594
 	public function add_payment_method() {
596 595
 		$error     = false;
597
-		$error_msg = __( 'There was a problem adding the card.', 'woocommerce-gateway-stripe' );
596
+		$error_msg = __('There was a problem adding the card.', 'woocommerce-gateway-stripe');
598 597
 		$source_id = '';
599 598
 
600
-		if ( empty( $_POST['stripe_source'] ) && empty( $_POST['stripe_token'] ) || ! is_user_logged_in() ) {
599
+		if (empty($_POST['stripe_source']) && empty($_POST['stripe_token']) || ! is_user_logged_in()) {
601 600
 			$error = true;
602 601
 		}
603 602
 
604
-		$stripe_customer = new WC_Stripe_Customer( get_current_user_id() );
603
+		$stripe_customer = new WC_Stripe_Customer(get_current_user_id());
605 604
 
606
-		if ( isset( $_POST['stripe_source'] ) ) {
607
-			$source = json_decode( wc_clean( stripslashes( $_POST['stripe_source'] ) ) );
605
+		if (isset($_POST['stripe_source'])) {
606
+			$source = json_decode(wc_clean(stripslashes($_POST['stripe_source'])));
608 607
 
609
-			if ( ! empty( $source->error ) ) {
608
+			if ( ! empty($source->error)) {
610 609
 				$error = true;
611 610
 			}
612 611
 
613 612
 			$source_id = $source->id;
614
-		} elseif ( isset( $_POST['stripe_token'] ) ) {
615
-			$source_id = wc_clean( $_POST['stripe_token'] );
613
+		} elseif (isset($_POST['stripe_token'])) {
614
+			$source_id = wc_clean($_POST['stripe_token']);
616 615
 		}
617 616
 
618
-		$response = $stripe_customer->add_source( $source_id );
617
+		$response = $stripe_customer->add_source($source_id);
619 618
 
620
-		if ( ! $response || is_wp_error( $response ) || ! empty( $response->error ) ) {
619
+		if ( ! $response || is_wp_error($response) || ! empty($response->error)) {
621 620
 			$error = true;
622 621
 		}
623 622
 
624
-		if ( $error ) {
625
-			wc_add_notice( $error_msg, 'error' );
623
+		if ($error) {
624
+			wc_add_notice($error_msg, 'error');
626 625
 			return;
627 626
 		}
628 627
 
629 628
 		return array(
630 629
 			'result'   => 'success',
631
-			'redirect' => wc_get_endpoint_url( 'payment-methods' ),
630
+			'redirect' => wc_get_endpoint_url('payment-methods'),
632 631
 		);
633 632
 	}
634 633
 }
Please login to merge, or discard this patch.
includes/compat/class-wc-stripe-compat.php 1 patch
Spacing   +147 added lines, -147 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) {
2
+if ( ! defined('ABSPATH')) {
3 3
 	exit;
4 4
 }
5 5
 
@@ -15,24 +15,24 @@  discard block
 block discarded – undo
15 15
 	public function __construct() {
16 16
 		parent::__construct();
17 17
 
18
-		if ( class_exists( 'WC_Subscriptions_Order' ) ) {
19
-			add_action( 'woocommerce_scheduled_subscription_payment_' . $this->id, array( $this, 'scheduled_subscription_payment' ), 10, 2 );
20
-			add_action( 'wcs_resubscribe_order_created', array( $this, 'delete_resubscribe_meta' ), 10 );
21
-			add_action( 'wcs_renewal_order_created', array( $this, 'delete_renewal_meta' ), 10 );
22
-			add_action( 'woocommerce_subscription_failing_payment_method_updated_stripe', array( $this, 'update_failing_payment_method' ), 10, 2 );
18
+		if (class_exists('WC_Subscriptions_Order')) {
19
+			add_action('woocommerce_scheduled_subscription_payment_' . $this->id, array($this, 'scheduled_subscription_payment'), 10, 2);
20
+			add_action('wcs_resubscribe_order_created', array($this, 'delete_resubscribe_meta'), 10);
21
+			add_action('wcs_renewal_order_created', array($this, 'delete_renewal_meta'), 10);
22
+			add_action('woocommerce_subscription_failing_payment_method_updated_stripe', array($this, 'update_failing_payment_method'), 10, 2);
23 23
 
24 24
 			// display the credit card used for a subscription in the "My Subscriptions" table
25
-			add_filter( 'woocommerce_my_subscriptions_payment_method', array( $this, 'maybe_render_subscription_payment_method' ), 10, 2 );
25
+			add_filter('woocommerce_my_subscriptions_payment_method', array($this, 'maybe_render_subscription_payment_method'), 10, 2);
26 26
 
27 27
 			// allow store managers to manually set Stripe as the payment method on a subscription
28
-			add_filter( 'woocommerce_subscription_payment_meta', array( $this, 'add_subscription_payment_meta' ), 10, 2 );
29
-			add_filter( 'woocommerce_subscription_validate_payment_meta', array( $this, 'validate_subscription_payment_meta' ), 10, 2 );
30
-			add_filter( 'wc_stripe_display_save_payment_method_checkbox', array( $this, 'maybe_hide_save_checkbox' ) );
31
-			add_filter( 'wc_stripe_payment_metadata', array( $this, 'add_subscription_meta_data' ), 10, 2 );
28
+			add_filter('woocommerce_subscription_payment_meta', array($this, 'add_subscription_payment_meta'), 10, 2);
29
+			add_filter('woocommerce_subscription_validate_payment_meta', array($this, 'validate_subscription_payment_meta'), 10, 2);
30
+			add_filter('wc_stripe_display_save_payment_method_checkbox', array($this, 'maybe_hide_save_checkbox'));
31
+			add_filter('wc_stripe_payment_metadata', array($this, 'add_subscription_meta_data'), 10, 2);
32 32
 		}
33 33
 
34
-		if ( class_exists( 'WC_Pre_Orders_Order' ) ) {
35
-			add_action( 'wc_pre_orders_process_pre_order_completion_payment_' . $this->id, array( $this, 'process_pre_order_release_payment' ) );
34
+		if (class_exists('WC_Pre_Orders_Order')) {
35
+			add_action('wc_pre_orders_process_pre_order_completion_payment_' . $this->id, array($this, 'process_pre_order_release_payment'));
36 36
 		}
37 37
 	}
38 38
 
@@ -43,8 +43,8 @@  discard block
 block discarded – undo
43 43
 	 * @since 4.0.0
44 44
 	 * @version 4.0.0
45 45
 	 */
46
-	public function maybe_hide_save_checkbox( $display_tokenization ) {
47
-		if ( WC_Subscriptions_Cart::cart_contains_subscription() ) {
46
+	public function maybe_hide_save_checkbox($display_tokenization) {
47
+		if (WC_Subscriptions_Cart::cart_contains_subscription()) {
48 48
 			return false;
49 49
 		}
50 50
 
@@ -56,8 +56,8 @@  discard block
 block discarded – undo
56 56
 	 * @param  int  $order_id
57 57
 	 * @return boolean
58 58
 	 */
59
-	public function has_subscription( $order_id ) {
60
-		return ( function_exists( 'wcs_order_contains_subscription' ) && ( wcs_order_contains_subscription( $order_id ) || wcs_is_subscription( $order_id ) || wcs_order_contains_renewal( $order_id ) ) );
59
+	public function has_subscription($order_id) {
60
+		return (function_exists('wcs_order_contains_subscription') && (wcs_order_contains_subscription($order_id) || wcs_is_subscription($order_id) || wcs_order_contains_renewal($order_id)));
61 61
 	}
62 62
 
63 63
 	/**
@@ -65,8 +65,8 @@  discard block
 block discarded – undo
65 65
 	 * @param  int  $order_id
66 66
 	 * @return boolean
67 67
 	 */
68
-	protected function is_pre_order( $order_id ) {
69
-		return ( class_exists( 'WC_Pre_Orders_Order' ) && WC_Pre_Orders_Order::order_contains_pre_order( $order_id ) );
68
+	protected function is_pre_order($order_id) {
69
+		return (class_exists('WC_Pre_Orders_Order') && WC_Pre_Orders_Order::order_contains_pre_order($order_id));
70 70
 	}
71 71
 
72 72
 	/**
@@ -74,14 +74,14 @@  discard block
 block discarded – undo
74 74
 	 * @param  int $order_id
75 75
 	 * @return array
76 76
 	 */
77
-	public function process_payment( $order_id, $retry = true, $force_save_source = false ) {
78
-		if ( $this->has_subscription( $order_id ) ) {
77
+	public function process_payment($order_id, $retry = true, $force_save_source = false) {
78
+		if ($this->has_subscription($order_id)) {
79 79
 			// Regular payment with force customer enabled
80
-			return parent::process_payment( $order_id, true, true );
81
-		} elseif ( $this->is_pre_order( $order_id ) ) {
82
-			return $this->process_pre_order( $order_id, $retry, $force_save_source );
80
+			return parent::process_payment($order_id, true, true);
81
+		} elseif ($this->is_pre_order($order_id)) {
82
+			return $this->process_pre_order($order_id, $retry, $force_save_source);
83 83
 		} else {
84
-			return parent::process_payment( $order_id, $retry, $force_save_source );
84
+			return parent::process_payment($order_id, $retry, $force_save_source);
85 85
 		}
86 86
 	}
87 87
 
@@ -92,14 +92,14 @@  discard block
 block discarded – undo
92 92
 	 * @param array $metadata
93 93
 	 * @param object $order
94 94
 	 */
95
-	public function add_subscription_meta_data( $metadata, $order ) {
96
-		if ( ! $this->has_subscription( $order->get_id() ) ) {
95
+	public function add_subscription_meta_data($metadata, $order) {
96
+		if ( ! $this->has_subscription($order->get_id())) {
97 97
 			return $metadata;
98 98
 		}
99 99
 
100 100
 		return $metadata += array(
101 101
 			'payment_type'   => 'recurring',
102
-			'site_url'       => esc_url( get_site_url() ),
102
+			'site_url'       => esc_url(get_site_url()),
103 103
 		);
104 104
 	}
105 105
 
@@ -109,24 +109,24 @@  discard block
 block discarded – undo
109 109
 	 * @since 3.1.0
110 110
 	 * @version 4.0.0
111 111
 	 */
112
-	public function save_source( $order, $source ) {
113
-		parent::save_source( $order, $source );
112
+	public function save_source($order, $source) {
113
+		parent::save_source($order, $source);
114 114
 
115
-		$order_id  = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
115
+		$order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
116 116
 
117 117
 		// Also store it on the subscriptions being purchased or paid for in the order
118
-		if ( function_exists( 'wcs_order_contains_subscription' ) && wcs_order_contains_subscription( $order_id ) ) {
119
-			$subscriptions = wcs_get_subscriptions_for_order( $order_id );
120
-		} elseif ( function_exists( 'wcs_order_contains_renewal' ) && wcs_order_contains_renewal( $order_id ) ) {
121
-			$subscriptions = wcs_get_subscriptions_for_renewal_order( $order_id );
118
+		if (function_exists('wcs_order_contains_subscription') && wcs_order_contains_subscription($order_id)) {
119
+			$subscriptions = wcs_get_subscriptions_for_order($order_id);
120
+		} elseif (function_exists('wcs_order_contains_renewal') && wcs_order_contains_renewal($order_id)) {
121
+			$subscriptions = wcs_get_subscriptions_for_renewal_order($order_id);
122 122
 		} else {
123 123
 			$subscriptions = array();
124 124
 		}
125 125
 
126
-		foreach ( $subscriptions as $subscription ) {
126
+		foreach ($subscriptions as $subscription) {
127 127
 			$subscription_id = WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id();
128
-			update_post_meta( $subscription_id, '_stripe_customer_id', $source->customer );
129
-			update_post_meta( $subscription_id, '_stripe_source_id', $source->source );
128
+			update_post_meta($subscription_id, '_stripe_customer_id', $source->customer);
129
+			update_post_meta($subscription_id, '_stripe_source_id', $source->source);
130 130
 		}
131 131
 	}
132 132
 
@@ -137,37 +137,37 @@  discard block
 block discarded – undo
137 137
 	 * @param string $stripe_token (default: '')
138 138
 	 * @param  bool initial_payment
139 139
 	 */
140
-	public function process_subscription_payment( $order = '', $amount = 0 ) {
141
-		if ( $amount * 100 < WC_Stripe_Helper::get_minimum_amount() ) {
140
+	public function process_subscription_payment($order = '', $amount = 0) {
141
+		if ($amount * 100 < WC_Stripe_Helper::get_minimum_amount()) {
142 142
 			/* translators: minimum amount */
143
-			return new WP_Error( 'stripe_error', sprintf( __( 'Sorry, the minimum allowed order total is %1$s to use this payment method.', 'woocommerce-gateway-stripe' ), wc_price( WC_Stripe_Helper::get_minimum_amount() / 100 ) ) );
143
+			return new WP_Error('stripe_error', sprintf(__('Sorry, the minimum allowed order total is %1$s to use this payment method.', 'woocommerce-gateway-stripe'), wc_price(WC_Stripe_Helper::get_minimum_amount() / 100)));
144 144
 		}
145 145
 
146 146
 		$customer_id = WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id();
147 147
 		$order_id    = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
148 148
 
149 149
 		// Get source from order
150
-		$prepared_source = $this->prepare_order_source( $order );
150
+		$prepared_source = $this->prepare_order_source($order);
151 151
 
152 152
 		// Or fail :(
153
-		if ( ! $prepared_source->customer ) {
154
-			return new WP_Error( 'stripe_error', __( 'Customer not found', 'woocommerce-gateway-stripe' ) );
153
+		if ( ! $prepared_source->customer) {
154
+			return new WP_Error('stripe_error', __('Customer not found', 'woocommerce-gateway-stripe'));
155 155
 		}
156 156
 
157
-		WC_Stripe_Logger::log( "Info: Begin processing subscription payment for order {$order_id} for the amount of {$amount}" );
157
+		WC_Stripe_Logger::log("Info: Begin processing subscription payment for order {$order_id} for the amount of {$amount}");
158 158
 
159 159
 		// Make the request
160
-		$request             = $this->generate_payment_request( $order, $prepared_source );
160
+		$request             = $this->generate_payment_request($order, $prepared_source);
161 161
 		$request['capture']  = 'true';
162
-		$request['amount']   = WC_Stripe_Helper::get_stripe_amount( $amount, $request['currency'] );
163
-		$response            = WC_Stripe_API::request( $request );
162
+		$request['amount']   = WC_Stripe_Helper::get_stripe_amount($amount, $request['currency']);
163
+		$response            = WC_Stripe_API::request($request);
164 164
 
165 165
 		// Process valid response
166
-		if ( ! empty( $response->error ) ) {
166
+		if ( ! empty($response->error)) {
167 167
 			return $response; // Default catch all errors.
168 168
 		}
169 169
 
170
-		$this->process_response( $response, $order );
170
+		$this->process_response($response, $order);
171 171
 
172 172
 		return $response;
173 173
 	}
@@ -176,21 +176,21 @@  discard block
 block discarded – undo
176 176
 	 * Don't transfer Stripe customer/token meta to resubscribe orders.
177 177
 	 * @param int $resubscribe_order The order created for the customer to resubscribe to the old expired/cancelled subscription
178 178
 	 */
179
-	public function delete_resubscribe_meta( $resubscribe_order ) {
180
-		delete_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id() ), '_stripe_customer_id' );
181
-		delete_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id() ), '_stripe_source_id' );
179
+	public function delete_resubscribe_meta($resubscribe_order) {
180
+		delete_post_meta((WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id()), '_stripe_customer_id');
181
+		delete_post_meta((WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id()), '_stripe_source_id');
182 182
 		// For BW compat will remove in future
183
-		delete_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id() ), '_stripe_card_id' );
184
-		$this->delete_renewal_meta( $resubscribe_order );
183
+		delete_post_meta((WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id()), '_stripe_card_id');
184
+		$this->delete_renewal_meta($resubscribe_order);
185 185
 	}
186 186
 
187 187
 	/**
188 188
 	 * Don't transfer Stripe fee/ID meta to renewal orders.
189 189
 	 * @param int $resubscribe_order The order created for the customer to resubscribe to the old expired/cancelled subscription
190 190
 	 */
191
-	public function delete_renewal_meta( $renewal_order ) {
192
-		delete_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $renewal_order->id : $renewal_order->get_id() ), 'Stripe Fee' );
193
-		delete_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $renewal_order->id : $renewal_order->get_id() ), 'Net Revenue From Stripe' );
191
+	public function delete_renewal_meta($renewal_order) {
192
+		delete_post_meta((WC_Stripe_Helper::is_pre_30() ? $renewal_order->id : $renewal_order->get_id()), 'Stripe Fee');
193
+		delete_post_meta((WC_Stripe_Helper::is_pre_30() ? $renewal_order->id : $renewal_order->get_id()), 'Net Revenue From Stripe');
194 194
 		return $renewal_order;
195 195
 	}
196 196
 
@@ -200,17 +200,17 @@  discard block
 block discarded – undo
200 200
 	 * @param $amount_to_charge float The amount to charge.
201 201
 	 * @param $renewal_order WC_Order A WC_Order object created to record the renewal payment.
202 202
 	 */
203
-	public function scheduled_subscription_payment( $amount_to_charge, $renewal_order ) {
204
-		$response = $this->process_subscription_payment( $renewal_order, $amount_to_charge );
203
+	public function scheduled_subscription_payment($amount_to_charge, $renewal_order) {
204
+		$response = $this->process_subscription_payment($renewal_order, $amount_to_charge);
205 205
 
206
-		if ( is_wp_error( $response ) ) {
206
+		if (is_wp_error($response)) {
207 207
 			/* translators: error message */
208
-			$renewal_order->update_status( 'failed', sprintf( __( 'Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe' ), $response->get_error_message() ) );
208
+			$renewal_order->update_status('failed', sprintf(__('Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe'), $response->get_error_message()));
209 209
 		}
210 210
 
211
-		if ( ! empty( $response->error ) ) {
211
+		if ( ! empty($response->error)) {
212 212
 			/* translators: error message */
213
-			$renewal_order->update_status( 'failed', sprintf( __( 'Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe' ), $response->error->message ) );
213
+			$renewal_order->update_status('failed', sprintf(__('Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe'), $response->error->message));
214 214
 		}
215 215
 	}
216 216
 
@@ -218,20 +218,20 @@  discard block
 block discarded – undo
218 218
 	 * Remove order meta
219 219
 	 * @param  object $order
220 220
 	 */
221
-	public function remove_order_source_before_retry( $order ) {
221
+	public function remove_order_source_before_retry($order) {
222 222
 		$order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
223
-		delete_post_meta( $order_id, '_stripe_source_id' );
223
+		delete_post_meta($order_id, '_stripe_source_id');
224 224
 		// For BW compat will remove in the future.
225
-		delete_post_meta( $order_id, '_stripe_card_id' );
225
+		delete_post_meta($order_id, '_stripe_card_id');
226 226
 	}
227 227
 
228 228
 	/**
229 229
 	 * Remove order meta
230 230
 	 * @param  object $order
231 231
 	 */
232
-	public function remove_order_customer_before_retry( $order ) {
232
+	public function remove_order_customer_before_retry($order) {
233 233
 		$order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
234
-		delete_post_meta( $order_id, '_stripe_customer_id' );
234
+		delete_post_meta($order_id, '_stripe_customer_id');
235 235
 	}
236 236
 
237 237
 	/**
@@ -243,14 +243,14 @@  discard block
 block discarded – undo
243 243
 	 * @param WC_Order $renewal_order The order which recorded the successful payment (to make up for the failed automatic payment).
244 244
 	 * @return void
245 245
 	 */
246
-	public function update_failing_payment_method( $subscription, $renewal_order ) {
247
-		if ( WC_Stripe_Helper::is_pre_30() ) {
248
-			update_post_meta( $subscription->id, '_stripe_customer_id', $renewal_order->stripe_customer_id );
249
-			update_post_meta( $subscription->id, '_stripe_source_id', $renewal_order->stripe_source_id );
246
+	public function update_failing_payment_method($subscription, $renewal_order) {
247
+		if (WC_Stripe_Helper::is_pre_30()) {
248
+			update_post_meta($subscription->id, '_stripe_customer_id', $renewal_order->stripe_customer_id);
249
+			update_post_meta($subscription->id, '_stripe_source_id', $renewal_order->stripe_source_id);
250 250
 
251 251
 		} else {
252
-			update_post_meta( $subscription->get_id(), '_stripe_customer_id', $renewal_order->get_meta( '_stripe_customer_id', true ) );
253
-			update_post_meta( $subscription->get_id(), '_stripe_source_id', $renewal_order->get_meta( '_stripe_source_id', true ) );
252
+			update_post_meta($subscription->get_id(), '_stripe_customer_id', $renewal_order->get_meta('_stripe_customer_id', true));
253
+			update_post_meta($subscription->get_id(), '_stripe_source_id', $renewal_order->get_meta('_stripe_source_id', true));
254 254
 		}
255 255
 	}
256 256
 
@@ -263,21 +263,21 @@  discard block
 block discarded – undo
263 263
 	 * @param WC_Subscription $subscription An instance of a subscription object
264 264
 	 * @return array
265 265
 	 */
266
-	public function add_subscription_payment_meta( $payment_meta, $subscription ) {
267
-		$source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_source_id', true );
266
+	public function add_subscription_payment_meta($payment_meta, $subscription) {
267
+		$source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_source_id', true);
268 268
 
269 269
 		// For BW compat will remove in future.
270
-		if ( empty( $source_id ) ) {
271
-			$source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_card_id', true );
270
+		if (empty($source_id)) {
271
+			$source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_card_id', true);
272 272
 
273 273
 			// Take this opportunity to update the key name.
274
-			WC_Stripe_Helper::is_pre_30() ? update_post_meta( $subscription->id, '_stripe_source_id', $source_id ) : update_post_meta( $subscription->get_id(), '_stripe_source_id', $source_id );
274
+			WC_Stripe_Helper::is_pre_30() ? update_post_meta($subscription->id, '_stripe_source_id', $source_id) : update_post_meta($subscription->get_id(), '_stripe_source_id', $source_id);
275 275
 		}
276 276
 
277
-		$payment_meta[ $this->id ] = array(
277
+		$payment_meta[$this->id] = array(
278 278
 			'post_meta' => array(
279 279
 				'_stripe_customer_id' => array(
280
-					'value' => get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_customer_id', true ),
280
+					'value' => get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_customer_id', true),
281 281
 					'label' => 'Stripe Customer ID',
282 282
 				),
283 283
 				'_stripe_source_id' => array(
@@ -299,17 +299,17 @@  discard block
 block discarded – undo
299 299
 	 * @param array $payment_meta associative array of meta data required for automatic payments
300 300
 	 * @return array
301 301
 	 */
302
-	public function validate_subscription_payment_meta( $payment_method_id, $payment_meta ) {
303
-		if ( $this->id === $payment_method_id ) {
302
+	public function validate_subscription_payment_meta($payment_method_id, $payment_meta) {
303
+		if ($this->id === $payment_method_id) {
304 304
 
305
-			if ( ! isset( $payment_meta['post_meta']['_stripe_customer_id']['value'] ) || empty( $payment_meta['post_meta']['_stripe_customer_id']['value'] ) ) {
306
-				throw new Exception( 'A "_stripe_customer_id" value is required.' );
307
-			} elseif ( 0 !== strpos( $payment_meta['post_meta']['_stripe_customer_id']['value'], 'cus_' ) ) {
308
-				throw new Exception( 'Invalid customer ID. A valid "_stripe_customer_id" must begin with "cus_".' );
305
+			if ( ! isset($payment_meta['post_meta']['_stripe_customer_id']['value']) || empty($payment_meta['post_meta']['_stripe_customer_id']['value'])) {
306
+				throw new Exception('A "_stripe_customer_id" value is required.');
307
+			} elseif (0 !== strpos($payment_meta['post_meta']['_stripe_customer_id']['value'], 'cus_')) {
308
+				throw new Exception('Invalid customer ID. A valid "_stripe_customer_id" must begin with "cus_".');
309 309
 			}
310 310
 
311
-			if ( ! isset( $payment_meta['post_meta']['_stripe_source_id']['value'] ) || empty( $payment_meta['post_meta']['_stripe_source_id']['value'] ) ) {
312
-				throw new Exception( 'A "_stripe_source_id" value is required.' );
311
+			if ( ! isset($payment_meta['post_meta']['_stripe_source_id']['value']) || empty($payment_meta['post_meta']['_stripe_source_id']['value'])) {
312
+				throw new Exception('A "_stripe_source_id" value is required.');
313 313
 			}
314 314
 		}
315 315
 	}
@@ -322,81 +322,81 @@  discard block
 block discarded – undo
322 322
 	 * @param WC_Subscription $subscription the subscription details
323 323
 	 * @return string the subscription payment method
324 324
 	 */
325
-	public function maybe_render_subscription_payment_method( $payment_method_to_display, $subscription ) {
325
+	public function maybe_render_subscription_payment_method($payment_method_to_display, $subscription) {
326 326
 		$customer_user = WC_Stripe_Helper::is_pre_30() ? $subscription->customer_user : $subscription->get_customer_id();
327 327
 
328 328
 		// bail for other payment methods
329
-		if ( ( WC_Stripe_Helper::is_pre_30() ? $subscription->payment_method : $subscription->get_payment_method() ) !== $this->id || ! $customer_user ) {
329
+		if ((WC_Stripe_Helper::is_pre_30() ? $subscription->payment_method : $subscription->get_payment_method()) !== $this->id || ! $customer_user) {
330 330
 			return $payment_method_to_display;
331 331
 		}
332 332
 
333
-		$stripe_source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_source_id', true );
333
+		$stripe_source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_source_id', true);
334 334
 
335 335
 		// For BW compat will remove in future.
336
-		if ( empty( $stripe_source_id ) ) {
337
-			$stripe_source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_card_id', true );
336
+		if (empty($stripe_source_id)) {
337
+			$stripe_source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_card_id', true);
338 338
 
339 339
 			// Take this opportunity to update the key name.
340
-			WC_Stripe_Helper::is_pre_30() ? update_post_meta( $subscription->id, '_stripe_source_id', $stripe_source_id ) : update_post_meta( $subscription->get_id(), '_stripe_source_id', $stripe_source_id );
340
+			WC_Stripe_Helper::is_pre_30() ? update_post_meta($subscription->id, '_stripe_source_id', $stripe_source_id) : update_post_meta($subscription->get_id(), '_stripe_source_id', $stripe_source_id);
341 341
 		}
342 342
 
343 343
 		$stripe_customer    = new WC_Stripe_Customer();
344
-		$stripe_customer_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_customer_id', true );
344
+		$stripe_customer_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_customer_id', true);
345 345
 
346 346
 		// If we couldn't find a Stripe customer linked to the subscription, fallback to the user meta data.
347
-		if ( ! $stripe_customer_id || ! is_string( $stripe_customer_id ) ) {
347
+		if ( ! $stripe_customer_id || ! is_string($stripe_customer_id)) {
348 348
 			$user_id            = $customer_user;
349
-			$stripe_customer_id = get_user_meta( $user_id, '_stripe_customer_id', true );
350
-			$stripe_source_id   = get_user_meta( $user_id, '_stripe_source_id', true );
349
+			$stripe_customer_id = get_user_meta($user_id, '_stripe_customer_id', true);
350
+			$stripe_source_id   = get_user_meta($user_id, '_stripe_source_id', true);
351 351
 
352 352
 			// For BW compat will remove in future.
353
-			if ( empty( $stripe_source_id ) ) {
354
-				$stripe_source_id = get_user_meta( $user_id, '_stripe_card_id', true );
353
+			if (empty($stripe_source_id)) {
354
+				$stripe_source_id = get_user_meta($user_id, '_stripe_card_id', true);
355 355
 
356 356
 				// Take this opportunity to update the key name.
357
-				update_user_meta( $user_id, '_stripe_source_id', $stripe_source_id );
357
+				update_user_meta($user_id, '_stripe_source_id', $stripe_source_id);
358 358
 			}
359 359
 		}
360 360
 
361 361
 		// If we couldn't find a Stripe customer linked to the account, fallback to the order meta data.
362
-		if ( ( ! $stripe_customer_id || ! is_string( $stripe_customer_id ) ) && false !== $subscription->order ) {
363
-			$stripe_customer_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id() ), '_stripe_customer_id', true );
364
-			$stripe_source_id   = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id() ), '_stripe_source_id', true );
362
+		if (( ! $stripe_customer_id || ! is_string($stripe_customer_id)) && false !== $subscription->order) {
363
+			$stripe_customer_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id()), '_stripe_customer_id', true);
364
+			$stripe_source_id   = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id()), '_stripe_source_id', true);
365 365
 
366 366
 			// For BW compat will remove in future.
367
-			if ( empty( $stripe_source_id ) ) {
368
-				$stripe_source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id() ), '_stripe_card_id', true );
367
+			if (empty($stripe_source_id)) {
368
+				$stripe_source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id()), '_stripe_card_id', true);
369 369
 
370 370
 				// Take this opportunity to update the key name.
371
-				WC_Stripe_Helper::is_pre_30() ? update_post_meta( $subscription->order->id, '_stripe_source_id', $stripe_source_id ) : update_post_meta( $subscription->get_parent_id(), '_stripe_source_id', $stripe_source_id );
371
+				WC_Stripe_Helper::is_pre_30() ? update_post_meta($subscription->order->id, '_stripe_source_id', $stripe_source_id) : update_post_meta($subscription->get_parent_id(), '_stripe_source_id', $stripe_source_id);
372 372
 			}
373 373
 		}
374 374
 
375
-		$stripe_customer->set_id( $stripe_customer_id );
375
+		$stripe_customer->set_id($stripe_customer_id);
376 376
 		$sources = $stripe_customer->get_sources();
377 377
 
378
-		if ( $sources ) {
378
+		if ($sources) {
379 379
 			$found_source = false;
380
-			foreach ( $sources as $source ) {
381
-				if ( isset( $source->type ) && 'card' === $source->type ) {
380
+			foreach ($sources as $source) {
381
+				if (isset($source->type) && 'card' === $source->type) {
382 382
 					$card = $source->card;
383 383
 				}
384 384
 
385
-				if ( $source->id === $stripe_source_id ) {
385
+				if ($source->id === $stripe_source_id) {
386 386
 					$found_source = true;
387 387
 					/* translators: 1) card brand 2) last 4 digits */
388
-					$payment_method_to_display = sprintf( __( 'Via %1$s card ending in %2$s', 'woocommerce-gateway-stripe' ), ( isset( $card->brand ) ? $card->brand : __( 'N/A', 'woocommerce-gateway-stripe' ) ), $card->last4 );
388
+					$payment_method_to_display = sprintf(__('Via %1$s card ending in %2$s', 'woocommerce-gateway-stripe'), (isset($card->brand) ? $card->brand : __('N/A', 'woocommerce-gateway-stripe')), $card->last4);
389 389
 					break;
390 390
 				}
391 391
 			}
392 392
 
393
-			if ( ! $found_source ) {
394
-				if ( 'card' === $sources[0]->type ) {
393
+			if ( ! $found_source) {
394
+				if ('card' === $sources[0]->type) {
395 395
 					$card = $sources[0]->card;
396 396
 				}
397 397
 
398 398
 				/* translators: 1) card brand 2) last 4 digits */
399
-				$payment_method_to_display = sprintf( __( 'Via %1$s card ending in %2$s', 'woocommerce-gateway-stripe' ), ( isset( $card->brand ) ? $card->brand : __( 'N/A', 'woocommerce-gateway-stripe' ) ), $card->last4 );
399
+				$payment_method_to_display = sprintf(__('Via %1$s card ending in %2$s', 'woocommerce-gateway-stripe'), (isset($card->brand) ? $card->brand : __('N/A', 'woocommerce-gateway-stripe')), $card->last4);
400 400
 			}
401 401
 		}
402 402
 
@@ -408,43 +408,43 @@  discard block
 block discarded – undo
408 408
 	 * @param int $order_id
409 409
 	 * @return array
410 410
 	 */
411
-	public function process_pre_order( $order_id, $retry, $force_save_source ) {
412
-		if ( WC_Pre_Orders_Order::order_requires_payment_tokenization( $order_id ) ) {
411
+	public function process_pre_order($order_id, $retry, $force_save_source) {
412
+		if (WC_Pre_Orders_Order::order_requires_payment_tokenization($order_id)) {
413 413
 			try {
414
-				$order = wc_get_order( $order_id );
414
+				$order = wc_get_order($order_id);
415 415
 
416
-				if ( $order->get_total() * 100 < WC_Stripe_Helper::get_minimum_amount() ) {
416
+				if ($order->get_total() * 100 < WC_Stripe_Helper::get_minimum_amount()) {
417 417
 					/* translators: minimum amount */
418
-					throw new Exception( sprintf( __( 'Sorry, the minimum allowed order total is %1$s to use this payment method.', 'woocommerce-gateway-stripe' ), wc_price( WC_Stripe_Helper::get_minimum_amount() / 100 ) ) );
418
+					throw new Exception(sprintf(__('Sorry, the minimum allowed order total is %1$s to use this payment method.', 'woocommerce-gateway-stripe'), wc_price(WC_Stripe_Helper::get_minimum_amount() / 100)));
419 419
 				}
420 420
 
421
-				$source = $this->prepare_source( get_current_user_id(), true );
421
+				$source = $this->prepare_source(get_current_user_id(), true);
422 422
 
423 423
 				// We need a source on file to continue.
424
-				if ( empty( $source->customer ) || empty( $source->source ) ) {
425
-					throw new Exception( __( 'Unable to store payment details. Please try again.', 'woocommerce-gateway-stripe' ) );
424
+				if (empty($source->customer) || empty($source->source)) {
425
+					throw new Exception(__('Unable to store payment details. Please try again.', 'woocommerce-gateway-stripe'));
426 426
 				}
427 427
 
428 428
 				// Store source to order meta
429
-				$this->save_source( $order, $source );
429
+				$this->save_source($order, $source);
430 430
 
431 431
 				// Remove cart
432 432
 				WC()->cart->empty_cart();
433 433
 
434 434
 				// Is pre ordered!
435
-				WC_Pre_Orders_Order::mark_order_as_pre_ordered( $order );
435
+				WC_Pre_Orders_Order::mark_order_as_pre_ordered($order);
436 436
 
437 437
 				// Return thank you page redirect
438 438
 				return array(
439 439
 					'result'   => 'success',
440
-					'redirect' => $this->get_return_url( $order ),
440
+					'redirect' => $this->get_return_url($order),
441 441
 				);
442
-			} catch ( Exception $e ) {
443
-				wc_add_notice( $e->getMessage(), 'error' );
442
+			} catch (Exception $e) {
443
+				wc_add_notice($e->getMessage(), 'error');
444 444
 				return;
445 445
 			}
446 446
 		} else {
447
-			return parent::process_payment( $order_id, $retry, $force_save_source );
447
+			return parent::process_payment($order_id, $retry, $force_save_source);
448 448
 		}
449 449
 	}
450 450
 
@@ -453,7 +453,7 @@  discard block
 block discarded – undo
453 453
 	 * @param WC_Order $order
454 454
 	 * @return void
455 455
 	 */
456
-	public function process_pre_order_release_payment( $order ) {
456
+	public function process_pre_order_release_payment($order) {
457 457
 		try {
458 458
 			// Define some callbacks if the first attempt fails.
459 459
 			$retry_callbacks = array(
@@ -461,33 +461,33 @@  discard block
 block discarded – undo
461 461
 				'remove_order_customer_before_retry',
462 462
 			);
463 463
 
464
-			while ( 1 ) {
465
-				$source   = $this->prepare_order_source( $order );
466
-				$response = WC_Stripe_API::request( $this->generate_payment_request( $order, $source ) );
464
+			while (1) {
465
+				$source   = $this->prepare_order_source($order);
466
+				$response = WC_Stripe_API::request($this->generate_payment_request($order, $source));
467 467
 
468
-				if ( ! empty( $response->error ) ) {
469
-					if ( 0 === sizeof( $retry_callbacks ) ) {
470
-						throw new Exception( $response->error->message );
468
+				if ( ! empty($response->error)) {
469
+					if (0 === sizeof($retry_callbacks)) {
470
+						throw new Exception($response->error->message);
471 471
 					} else {
472
-						$retry_callback = array_shift( $retry_callbacks );
473
-						call_user_func( array( $this, $retry_callback ), $order );
472
+						$retry_callback = array_shift($retry_callbacks);
473
+						call_user_func(array($this, $retry_callback), $order);
474 474
 					}
475 475
 				} else {
476 476
 					// Successful
477
-					$this->process_response( $response, $order );
477
+					$this->process_response($response, $order);
478 478
 					break;
479 479
 				}
480 480
 			}
481
-		} catch ( Exception $e ) {
481
+		} catch (Exception $e) {
482 482
 			/* translators: error message */
483
-			$order_note = sprintf( __( 'Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe' ), $e->getMessage() );
483
+			$order_note = sprintf(__('Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe'), $e->getMessage());
484 484
 
485 485
 			// Mark order as failed if not already set,
486 486
 			// otherwise, make sure we add the order note so we can detect when someone fails to check out multiple times
487
-			if ( ! $order->has_status( 'failed' ) ) {
488
-				$order->update_status( 'failed', $order_note );
487
+			if ( ! $order->has_status('failed')) {
488
+				$order->update_status('failed', $order_note);
489 489
 			} else {
490
-				$order->add_order_note( $order_note );
490
+				$order->add_order_note($order_note);
491 491
 			}
492 492
 		}
493 493
 	}
Please login to merge, or discard this patch.
includes/class-wc-stripe-payment-tokens.php 1 patch
Spacing   +57 added lines, -57 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,11 +21,11 @@  discard block
 block discarded – undo
21 21
 	public function __construct() {
22 22
 		self::$_this = $this;
23 23
 
24
-		add_filter( 'woocommerce_get_customer_payment_tokens', array( $this, 'woocommerce_get_customer_payment_tokens' ), 10, 3 );
25
-		add_filter( 'woocommerce_payment_methods_list_item', array( $this, 'get_account_saved_payment_methods_list_item_sepa' ), 10, 2 );
26
-		add_filter( 'woocommerce_get_credit_card_type_label', array( $this, 'normalize_sepa_label' ) );
27
-		add_action( 'woocommerce_payment_token_deleted', array( $this, 'woocommerce_payment_token_deleted' ), 10, 2 );
28
-		add_action( 'woocommerce_payment_token_set_default', array( $this, 'woocommerce_payment_token_set_default' ) );
24
+		add_filter('woocommerce_get_customer_payment_tokens', array($this, 'woocommerce_get_customer_payment_tokens'), 10, 3);
25
+		add_filter('woocommerce_payment_methods_list_item', array($this, 'get_account_saved_payment_methods_list_item_sepa'), 10, 2);
26
+		add_filter('woocommerce_get_credit_card_type_label', array($this, 'normalize_sepa_label'));
27
+		add_action('woocommerce_payment_token_deleted', array($this, 'woocommerce_payment_token_deleted'), 10, 2);
28
+		add_action('woocommerce_payment_token_set_default', array($this, 'woocommerce_payment_token_set_default'));
29 29
 	}
30 30
 
31 31
 	/**
@@ -46,8 +46,8 @@  discard block
 block discarded – undo
46 46
 	 * @param string $label
47 47
 	 * @return string $label
48 48
 	 */
49
-	public function normalize_sepa_label( $label ) {
50
-		if ( 'sepa iban' === strtolower( $label ) ) {
49
+	public function normalize_sepa_label($label) {
50
+		if ('sepa iban' === strtolower($label)) {
51 51
 			return 'SEPA IBAN';
52 52
 		}
53 53
 
@@ -62,67 +62,67 @@  discard block
 block discarded – undo
62 62
 	 * @param array $tokens
63 63
 	 * @return array
64 64
 	 */
65
-	public function woocommerce_get_customer_payment_tokens( $tokens = array(), $customer_id, $gateway_id ) {
66
-		if ( is_user_logged_in() && class_exists( 'WC_Payment_Token_CC' ) ) {
65
+	public function woocommerce_get_customer_payment_tokens($tokens = array(), $customer_id, $gateway_id) {
66
+		if (is_user_logged_in() && class_exists('WC_Payment_Token_CC')) {
67 67
 			$stored_tokens = array();
68 68
 
69
-			foreach ( $tokens as $token ) {
69
+			foreach ($tokens as $token) {
70 70
 				$stored_tokens[] = $token->get_token();
71 71
 			}
72 72
 
73
-			if ( 'stripe' === $gateway_id ) {
74
-				$stripe_customer = new WC_Stripe_Customer( $customer_id );
73
+			if ('stripe' === $gateway_id) {
74
+				$stripe_customer = new WC_Stripe_Customer($customer_id);
75 75
 				$stripe_sources  = $stripe_customer->get_sources();
76 76
 
77
-				foreach ( $stripe_sources as $source ) {
78
-					if ( isset( $source->type ) && 'card' === $source->type ) {
79
-						if ( ! in_array( $source->id, $stored_tokens ) ) {
77
+				foreach ($stripe_sources as $source) {
78
+					if (isset($source->type) && 'card' === $source->type) {
79
+						if ( ! in_array($source->id, $stored_tokens)) {
80 80
 							$token = new WC_Payment_Token_CC();
81
-							$token->set_token( $source->id );
82
-							$token->set_gateway_id( 'stripe' );
83
-
84
-							if ( 'source' === $source->object && 'card' === $source->type ) {
85
-								$token->set_card_type( strtolower( $source->card->brand ) );
86
-								$token->set_last4( $source->card->last4 );
87
-								$token->set_expiry_month( $source->card->exp_month );
88
-								$token->set_expiry_year( $source->card->exp_year );
81
+							$token->set_token($source->id);
82
+							$token->set_gateway_id('stripe');
83
+
84
+							if ('source' === $source->object && 'card' === $source->type) {
85
+								$token->set_card_type(strtolower($source->card->brand));
86
+								$token->set_last4($source->card->last4);
87
+								$token->set_expiry_month($source->card->exp_month);
88
+								$token->set_expiry_year($source->card->exp_year);
89 89
 							}
90 90
 
91
-							$token->set_user_id( $customer_id );
91
+							$token->set_user_id($customer_id);
92 92
 							$token->save();
93
-							$tokens[ $token->get_id() ] = $token;
93
+							$tokens[$token->get_id()] = $token;
94 94
 						}
95 95
 					} else {
96
-						if ( ! in_array( $source->id, $stored_tokens ) && 'card' === $source->object ) {
96
+						if ( ! in_array($source->id, $stored_tokens) && 'card' === $source->object) {
97 97
 							$token = new WC_Payment_Token_CC();
98
-							$token->set_token( $source->id );
99
-							$token->set_gateway_id( 'stripe' );
100
-							$token->set_card_type( strtolower( $source->brand ) );
101
-							$token->set_last4( $source->last4 );
102
-							$token->set_expiry_month( $source->exp_month );
103
-							$token->set_expiry_year( $source->exp_year );
104
-							$token->set_user_id( $customer_id );
98
+							$token->set_token($source->id);
99
+							$token->set_gateway_id('stripe');
100
+							$token->set_card_type(strtolower($source->brand));
101
+							$token->set_last4($source->last4);
102
+							$token->set_expiry_month($source->exp_month);
103
+							$token->set_expiry_year($source->exp_year);
104
+							$token->set_user_id($customer_id);
105 105
 							$token->save();
106
-							$tokens[ $token->get_id() ] = $token;
106
+							$tokens[$token->get_id()] = $token;
107 107
 						}
108 108
 					}
109 109
 				}
110 110
 			}
111 111
 
112
-			if ( 'stripe_sepa' === $gateway_id ) {
113
-				$stripe_customer = new WC_Stripe_Customer( $customer_id );
112
+			if ('stripe_sepa' === $gateway_id) {
113
+				$stripe_customer = new WC_Stripe_Customer($customer_id);
114 114
 				$stripe_sources  = $stripe_customer->get_sources();
115 115
 
116
-				foreach ( $stripe_sources as $source ) {
117
-					if ( isset( $source->type ) && 'sepa_debit' === $source->type ) {
118
-						if ( ! in_array( $source->id, $stored_tokens ) ) {
116
+				foreach ($stripe_sources as $source) {
117
+					if (isset($source->type) && 'sepa_debit' === $source->type) {
118
+						if ( ! in_array($source->id, $stored_tokens)) {
119 119
 							$token = new WC_Payment_Token_SEPA();
120
-							$token->set_token( $source->id );
121
-							$token->set_gateway_id( 'stripe_sepa' );
122
-							$token->set_last4( $source->sepa_debit->last4 );
123
-							$token->set_user_id( $customer_id );
120
+							$token->set_token($source->id);
121
+							$token->set_gateway_id('stripe_sepa');
122
+							$token->set_last4($source->sepa_debit->last4);
123
+							$token->set_user_id($customer_id);
124 124
 							$token->save();
125
-							$tokens[ $token->get_id() ] = $token;
125
+							$tokens[$token->get_id()] = $token;
126 126
 						}
127 127
 					}
128 128
 				}
@@ -141,13 +141,13 @@  discard block
 block discarded – undo
141 141
 	 * @param  WC_Payment_Token $payment_token The payment token associated with this method entry
142 142
 	 * @return array                           Filtered item
143 143
 	 */
144
-	public function get_account_saved_payment_methods_list_item_sepa( $item, $payment_token ) {
145
-		if ( 'sepa' !== strtolower( $payment_token->get_type() ) ) {
144
+	public function get_account_saved_payment_methods_list_item_sepa($item, $payment_token) {
145
+		if ('sepa' !== strtolower($payment_token->get_type())) {
146 146
 			return $item;
147 147
 		}
148 148
 
149 149
 		$item['method']['last4'] = $payment_token->get_last4();
150
-		$item['method']['brand'] = esc_html__( 'SEPA IBAN', 'woocommerce-gateway-stripe' );
150
+		$item['method']['brand'] = esc_html__('SEPA IBAN', 'woocommerce-gateway-stripe');
151 151
 
152 152
 		return $item;
153 153
 	}
@@ -158,10 +158,10 @@  discard block
 block discarded – undo
158 158
 	 * @since 3.1.0
159 159
 	 * @version 4.0.0
160 160
 	 */
161
-	public function woocommerce_payment_token_deleted( $token_id, $token ) {
162
-		if ( 'stripe' === $token->get_gateway_id() || 'stripe_sepa' === $token->get_gateway_id() ) {
163
-			$stripe_customer = new WC_Stripe_Customer( get_current_user_id() );
164
-			$stripe_customer->delete_source( $token->get_token() );
161
+	public function woocommerce_payment_token_deleted($token_id, $token) {
162
+		if ('stripe' === $token->get_gateway_id() || 'stripe_sepa' === $token->get_gateway_id()) {
163
+			$stripe_customer = new WC_Stripe_Customer(get_current_user_id());
164
+			$stripe_customer->delete_source($token->get_token());
165 165
 		}
166 166
 	}
167 167
 
@@ -171,12 +171,12 @@  discard block
 block discarded – undo
171 171
 	 * @since 3.1.0
172 172
 	 * @version 4.0.0
173 173
 	 */
174
-	public function woocommerce_payment_token_set_default( $token_id ) {
175
-		$token = WC_Payment_Tokens::get( $token_id );
174
+	public function woocommerce_payment_token_set_default($token_id) {
175
+		$token = WC_Payment_Tokens::get($token_id);
176 176
 
177
-		if ( 'stripe' === $token->get_gateway_id() || 'stripe_sepa' === $token->get_gateway_id() ) {
178
-			$stripe_customer = new WC_Stripe_Customer( get_current_user_id() );
179
-			$stripe_customer->set_default_source( $token->get_token() );
177
+		if ('stripe' === $token->get_gateway_id() || 'stripe_sepa' === $token->get_gateway_id()) {
178
+			$stripe_customer = new WC_Stripe_Customer(get_current_user_id());
179
+			$stripe_customer->set_default_source($token->get_token());
180 180
 		}
181 181
 	}
182 182
 }
Please login to merge, or discard this patch.
includes/class-wc-stripe-api.php 1 patch
Spacing   +26 added lines, -26 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
 
@@ -26,7 +26,7 @@  discard block
 block discarded – undo
26 26
 	 * Set secret API Key.
27 27
 	 * @param string $key
28 28
 	 */
29
-	public static function set_secret_key( $secret_key ) {
29
+	public static function set_secret_key($secret_key) {
30 30
 		self::$secret_key = $secret_key;
31 31
 	}
32 32
 
@@ -35,11 +35,11 @@  discard block
 block discarded – undo
35 35
 	 * @return string
36 36
 	 */
37 37
 	public static function get_secret_key() {
38
-		if ( ! self::$secret_key ) {
39
-			$options = get_option( 'woocommerce_stripe_settings' );
38
+		if ( ! self::$secret_key) {
39
+			$options = get_option('woocommerce_stripe_settings');
40 40
 
41
-			if ( isset( $options['testmode'], $options['secret_key'], $options['test_secret_key'] ) ) {
42
-				self::set_secret_key( 'yes' === $options['testmode'] ? $options['test_secret_key'] : $options['secret_key'] );
41
+			if (isset($options['testmode'], $options['secret_key'], $options['test_secret_key'])) {
42
+				self::set_secret_key('yes' === $options['testmode'] ? $options['test_secret_key'] : $options['secret_key']);
43 43
 			}
44 44
 		}
45 45
 		return self::$secret_key;
@@ -78,12 +78,12 @@  discard block
 block discarded – undo
78 78
 		$user_agent = self::get_user_agent();
79 79
 		$app_info   = $user_agent['application'];
80 80
 
81
-		return apply_filters( 'woocommerce_stripe_request_headers', array(
82
-			'Authorization'              => 'Basic ' . base64_encode( self::get_secret_key() . ':' ),
81
+		return apply_filters('woocommerce_stripe_request_headers', array(
82
+			'Authorization'              => 'Basic ' . base64_encode(self::get_secret_key() . ':'),
83 83
 			'Stripe-Version'             => self::STRIPE_API_VERSION,
84 84
 			'User-Agent'                 => $app_info['name'] . '/' . $app_info['version'] . ' (' . $app_info['url'] . ')',
85
-			'X-Stripe-Client-User-Agent' => json_encode( $user_agent ),
86
-		) );
85
+			'X-Stripe-Client-User-Agent' => json_encode($user_agent),
86
+		));
87 87
 	}
88 88
 
89 89
 	/**
@@ -95,15 +95,15 @@  discard block
 block discarded – undo
95 95
 	 * @param string $api
96 96
 	 * @return array|WP_Error
97 97
 	 */
98
-	public static function request( $request, $api = 'charges', $method = 'POST' ) {
99
-		WC_Stripe_Logger::log( "{$api} request: " . print_r( $request, true ) );
98
+	public static function request($request, $api = 'charges', $method = 'POST') {
99
+		WC_Stripe_Logger::log("{$api} request: " . print_r($request, true));
100 100
 
101 101
 		$headers = self::get_headers();
102 102
 
103
-		$customer = ! empty( $request['customer'] ) ? $request['customer'] : '';
104
-		$source   = ! empty( $request['source'] ) ? $request['source'] : $customer;
103
+		$customer = ! empty($request['customer']) ? $request['customer'] : '';
104
+		$source   = ! empty($request['source']) ? $request['source'] : $customer;
105 105
 
106
-		if ( 'charges' === $api && 'POST' === $method ) {
106
+		if ('charges' === $api && 'POST' === $method) {
107 107
 			$headers['Idempotency-Key'] = $request['metadata']['order_id'] . '-' . $source;
108 108
 		}
109 109
 
@@ -112,17 +112,17 @@  discard block
 block discarded – undo
112 112
 			array(
113 113
 				'method'  => $method,
114 114
 				'headers' => $headers,
115
-				'body'    => apply_filters( 'woocommerce_stripe_request_body', $request, $api ),
115
+				'body'    => apply_filters('woocommerce_stripe_request_body', $request, $api),
116 116
 				'timeout' => 70,
117 117
 			)
118 118
 		);
119 119
 
120
-		if ( is_wp_error( $response ) || empty( $response['body'] ) ) {
121
-			WC_Stripe_Logger::log( 'Error Response: ' . print_r( $response, true ) );
122
-			throw new Exception( __( 'There was a problem connecting to the Stripe API endpoint.', 'woocommerce-gateway-stripe' ) );
120
+		if (is_wp_error($response) || empty($response['body'])) {
121
+			WC_Stripe_Logger::log('Error Response: ' . print_r($response, true));
122
+			throw new Exception(__('There was a problem connecting to the Stripe API endpoint.', 'woocommerce-gateway-stripe'));
123 123
 		}
124 124
 
125
-		return json_decode( $response['body'] );
125
+		return json_decode($response['body']);
126 126
 	}
127 127
 
128 128
 	/**
@@ -132,8 +132,8 @@  discard block
 block discarded – undo
132 132
 	 * @version 4.0.0
133 133
 	 * @param string $api
134 134
 	 */
135
-	public static function retrieve( $api ) {
136
-		WC_Stripe_Logger::log( "{$api}" );
135
+	public static function retrieve($api) {
136
+		WC_Stripe_Logger::log("{$api}");
137 137
 
138 138
 		$ua = self::get_user_agent();
139 139
 
@@ -146,11 +146,11 @@  discard block
 block discarded – undo
146 146
 			)
147 147
 		);
148 148
 
149
-		if ( is_wp_error( $response ) || empty( $response['body'] ) ) {
150
-			WC_Stripe_Logger::log( 'Error Response: ' . print_r( $response, true ) );
151
-			return new WP_Error( 'stripe_error', __( 'There was a problem connecting to the Stripe API endpoint.', 'woocommerce-gateway-stripe' ) );
149
+		if (is_wp_error($response) || empty($response['body'])) {
150
+			WC_Stripe_Logger::log('Error Response: ' . print_r($response, true));
151
+			return new WP_Error('stripe_error', __('There was a problem connecting to the Stripe API endpoint.', 'woocommerce-gateway-stripe'));
152 152
 		}
153 153
 
154
-		return json_decode( $response['body'] );
154
+		return json_decode($response['body']);
155 155
 	}
156 156
 }
Please login to merge, or discard this patch.
includes/class-wc-gateway-stripe.php 1 patch
Spacing   +201 added lines, -201 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
 
@@ -119,9 +119,9 @@  discard block
 block discarded – undo
119 119
 	 */
120 120
 	public function __construct() {
121 121
 		$this->id                   = 'stripe';
122
-		$this->method_title         = __( 'Stripe', 'woocommerce-gateway-stripe' );
122
+		$this->method_title         = __('Stripe', 'woocommerce-gateway-stripe');
123 123
 		/* translators: 1) link to Stripe register page 2) link to Stripe api keys page */
124
-		$this->method_description   = sprintf( __( 'Stripe works by adding payment fields on the checkout and then sending the details to Stripe for verification. <a href="%1$s" target="_blank">Sign up</a> for a Stripe account, and <a href="%2$s" target="_blank">get your Stripe account keys</a>.', 'woocommerce-gateway-stripe' ), 'https://dashboard.stripe.com/register', 'https://dashboard.stripe.com/account/apikeys' );
124
+		$this->method_description   = sprintf(__('Stripe works by adding payment fields on the checkout and then sending the details to Stripe for verification. <a href="%1$s" target="_blank">Sign up</a> for a Stripe account, and <a href="%2$s" target="_blank">get your Stripe account keys</a>.', 'woocommerce-gateway-stripe'), 'https://dashboard.stripe.com/register', 'https://dashboard.stripe.com/account/apikeys');
125 125
 		$this->has_fields           = true;
126 126
 		$this->supports             = array(
127 127
 			'products',
@@ -148,38 +148,38 @@  discard block
 block discarded – undo
148 148
 		$this->init_settings();
149 149
 
150 150
 		// Get setting values.
151
-		$this->title                   = $this->get_option( 'title' );
152
-		$this->description             = $this->get_option( 'description' );
153
-		$this->enabled                 = $this->get_option( 'enabled' );
154
-		$this->testmode                = 'yes' === $this->get_option( 'testmode' );
155
-		$this->inline_cc_form          = 'yes' === $this->get_option( 'inline_cc_form' );
156
-		$this->capture                 = 'yes' === $this->get_option( 'capture', 'yes' );
157
-		$this->statement_descriptor    = WC_Stripe_Helper::clean_statement_descriptor( $this->get_option( 'statement_descriptor' ) );
158
-		$this->three_d_secure          = 'yes' === $this->get_option( 'three_d_secure' );
159
-		$this->stripe_checkout         = 'yes' === $this->get_option( 'stripe_checkout' );
160
-		$this->stripe_checkout_locale  = $this->get_option( 'stripe_checkout_locale' );
161
-		$this->stripe_checkout_image   = $this->get_option( 'stripe_checkout_image', '' );
162
-		$this->saved_cards             = 'yes' === $this->get_option( 'saved_cards' );
163
-		$this->secret_key              = $this->testmode ? $this->get_option( 'test_secret_key' ) : $this->get_option( 'secret_key' );
164
-		$this->publishable_key         = $this->testmode ? $this->get_option( 'test_publishable_key' ) : $this->get_option( 'publishable_key' );
165
-		$this->bitcoin                 = 'USD' === strtoupper( get_woocommerce_currency() ) && 'yes' === $this->get_option( 'stripe_bitcoin' );
166
-		$this->payment_request         = 'yes' === $this->get_option( 'payment_request', 'yes' );
167
-		$this->apple_pay_domain_set    = 'yes' === $this->get_option( 'apple_pay_domain_set', 'no' );
151
+		$this->title                   = $this->get_option('title');
152
+		$this->description             = $this->get_option('description');
153
+		$this->enabled                 = $this->get_option('enabled');
154
+		$this->testmode                = 'yes' === $this->get_option('testmode');
155
+		$this->inline_cc_form          = 'yes' === $this->get_option('inline_cc_form');
156
+		$this->capture                 = 'yes' === $this->get_option('capture', 'yes');
157
+		$this->statement_descriptor    = WC_Stripe_Helper::clean_statement_descriptor($this->get_option('statement_descriptor'));
158
+		$this->three_d_secure          = 'yes' === $this->get_option('three_d_secure');
159
+		$this->stripe_checkout         = 'yes' === $this->get_option('stripe_checkout');
160
+		$this->stripe_checkout_locale  = $this->get_option('stripe_checkout_locale');
161
+		$this->stripe_checkout_image   = $this->get_option('stripe_checkout_image', '');
162
+		$this->saved_cards             = 'yes' === $this->get_option('saved_cards');
163
+		$this->secret_key              = $this->testmode ? $this->get_option('test_secret_key') : $this->get_option('secret_key');
164
+		$this->publishable_key         = $this->testmode ? $this->get_option('test_publishable_key') : $this->get_option('publishable_key');
165
+		$this->bitcoin                 = 'USD' === strtoupper(get_woocommerce_currency()) && 'yes' === $this->get_option('stripe_bitcoin');
166
+		$this->payment_request         = 'yes' === $this->get_option('payment_request', 'yes');
167
+		$this->apple_pay_domain_set    = 'yes' === $this->get_option('apple_pay_domain_set', 'no');
168 168
 		$this->apple_pay_verify_notice = '';
169 169
 
170
-		if ( $this->stripe_checkout ) {
171
-			$this->order_button_text = __( 'Continue to payment', 'woocommerce-gateway-stripe' );
170
+		if ($this->stripe_checkout) {
171
+			$this->order_button_text = __('Continue to payment', 'woocommerce-gateway-stripe');
172 172
 		}
173 173
 
174
-		WC_Stripe_API::set_secret_key( $this->secret_key );
174
+		WC_Stripe_API::set_secret_key($this->secret_key);
175 175
 
176 176
 		$this->init_apple_pay();
177 177
 
178 178
 		// Hooks.
179
-		add_action( 'wp_enqueue_scripts', array( $this, 'payment_scripts' ) );
180
-		add_action( 'admin_enqueue_scripts', array( $this, 'admin_scripts' ) );
181
-		add_action( 'admin_notices', array( $this, 'admin_notices' ) );
182
-		add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) );
179
+		add_action('wp_enqueue_scripts', array($this, 'payment_scripts'));
180
+		add_action('admin_enqueue_scripts', array($this, 'admin_scripts'));
181
+		add_action('admin_notices', array($this, 'admin_notices'));
182
+		add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options'));
183 183
 	}
184 184
 
185 185
 	/**
@@ -190,7 +190,7 @@  discard block
 block discarded – undo
190 190
 	 * @return array
191 191
 	 */
192 192
 	public function payment_icons() {
193
-		return apply_filters( 'wc_stripe_payment_icons', array(
193
+		return apply_filters('wc_stripe_payment_icons', array(
194 194
 			'visa'       => '<i class="stripe-pf stripe-pf-visa stripe-pf-right" alt="Visa" aria-hidden="true"></i>',
195 195
 			'amex'       => '<i class="stripe-pf stripe-pf-american-express stripe-pf-right" alt="Amex" aria-hidden="true"></i>',
196 196
 			'mastercard' => '<i class="stripe-pf stripe-pf-mastercard stripe-pf-right" alt="Mastercard" aria-hidden="true"></i>',
@@ -207,7 +207,7 @@  discard block
 block discarded – undo
207 207
 			'eps'        => '<i class="stripe-pf stripe-pf-eps stripe-pf-right" alt="EPS" aria-hidden="true"></i>',
208 208
 			'sofort'     => '<i class="stripe-pf stripe-pf-sofort stripe-pf-right" alt="SOFORT" aria-hidden="true"></i>',
209 209
 			'sepa'       => '<i class="stripe-pf stripe-pf-sepa stripe-pf-right" alt="SEPA" aria-hidden="true"></i>',
210
-		) );
210
+		));
211 211
 	}
212 212
 
213 213
 	/**
@@ -226,17 +226,17 @@  discard block
 block discarded – undo
226 226
 		$icons_str .= $icons['amex'];
227 227
 		$icons_str .= $icons['mastercard'];
228 228
 
229
-		if ( 'USD' === get_woocommerce_currency() ) {
229
+		if ('USD' === get_woocommerce_currency()) {
230 230
 			$icons_str .= $icons['discover'];
231 231
 			$icons_str .= $icons['jcb'];
232 232
 			$icons_str .= $icons['diners'];
233 233
 		}
234 234
 
235
-		if ( $this->bitcoin && $this->stripe_checkout ) {
235
+		if ($this->bitcoin && $this->stripe_checkout) {
236 236
 			$icons_str .= $icons['bitcoin'];
237 237
 		}
238 238
 
239
-		return apply_filters( 'woocommerce_gateway_icon', $icons_str, $this->id );
239
+		return apply_filters('woocommerce_gateway_icon', $icons_str, $this->id);
240 240
 	}
241 241
 
242 242
 	/**
@@ -248,9 +248,9 @@  discard block
 block discarded – undo
248 248
 	public function init_apple_pay() {
249 249
 		if (
250 250
 			is_admin() &&
251
-			isset( $_GET['page'] ) && 'wc-settings' === $_GET['page'] &&
252
-			isset( $_GET['tab'] ) && 'checkout' === $_GET['tab'] &&
253
-			isset( $_GET['section'] ) && 'stripe' === $_GET['section'] &&
251
+			isset($_GET['page']) && 'wc-settings' === $_GET['page'] &&
252
+			isset($_GET['tab']) && 'checkout' === $_GET['tab'] &&
253
+			isset($_GET['section']) && 'stripe' === $_GET['section'] &&
254 254
 			$this->payment_request
255 255
 		) {
256 256
 			$this->process_apple_pay_verification();
@@ -264,9 +264,9 @@  discard block
 block discarded – undo
264 264
 	 * @version 3.1.0
265 265
 	 * @param string $secret_key
266 266
 	 */
267
-	private function register_apple_pay_domain( $secret_key = '' ) {
268
-		if ( empty( $secret_key ) ) {
269
-			throw new Exception( __( 'Unable to verify domain - missing secret key.', 'woocommerce-gateway-stripe' ) );
267
+	private function register_apple_pay_domain($secret_key = '') {
268
+		if (empty($secret_key)) {
269
+			throw new Exception(__('Unable to verify domain - missing secret key.', 'woocommerce-gateway-stripe'));
270 270
 		}
271 271
 
272 272
 		$endpoint = 'https://api.stripe.com/v1/apple_pay/domains';
@@ -280,23 +280,23 @@  discard block
 block discarded – undo
280 280
 			'Authorization' => 'Bearer ' . $secret_key,
281 281
 		);
282 282
 
283
-		$response = wp_remote_post( $endpoint, array(
283
+		$response = wp_remote_post($endpoint, array(
284 284
 			'headers' => $headers,
285
-			'body'    => http_build_query( $data ),
286
-		) );
285
+			'body'    => http_build_query($data),
286
+		));
287 287
 
288
-		if ( is_wp_error( $response ) ) {
288
+		if (is_wp_error($response)) {
289 289
 			/* translators: error message */
290
-			throw new Exception( sprintf( __( 'Unable to verify domain - %s', 'woocommerce-gateway-stripe' ), $response->get_error_message() ) );
290
+			throw new Exception(sprintf(__('Unable to verify domain - %s', 'woocommerce-gateway-stripe'), $response->get_error_message()));
291 291
 		}
292 292
 
293
-		if ( 200 !== $response['response']['code'] ) {
294
-			$parsed_response = json_decode( $response['body'] );
293
+		if (200 !== $response['response']['code']) {
294
+			$parsed_response = json_decode($response['body']);
295 295
 
296 296
 			$this->apple_pay_verify_notice = $parsed_response->error->message;
297 297
 
298 298
 			/* translators: error message */
299
-			throw new Exception( sprintf( __( 'Unable to verify domain - %s', 'woocommerce-gateway-stripe' ), $parsed_response->error->message ) );
299
+			throw new Exception(sprintf(__('Unable to verify domain - %s', 'woocommerce-gateway-stripe'), $parsed_response->error->message));
300 300
 		}
301 301
 	}
302 302
 
@@ -307,48 +307,48 @@  discard block
 block discarded – undo
307 307
 	 * @version 3.1.0
308 308
 	 */
309 309
 	public function process_apple_pay_verification() {
310
-		$gateway_settings = get_option( 'woocommerce_stripe_settings', array() );
310
+		$gateway_settings = get_option('woocommerce_stripe_settings', array());
311 311
 
312 312
 		try {
313
-			$path     = untrailingslashit( $_SERVER['DOCUMENT_ROOT'] );
313
+			$path     = untrailingslashit($_SERVER['DOCUMENT_ROOT']);
314 314
 			$dir      = '.well-known';
315 315
 			$file     = 'apple-developer-merchantid-domain-association';
316 316
 			$fullpath = $path . '/' . $dir . '/' . $file;
317 317
 
318
-			if ( ! empty( $gateway_settings['apple_pay_domain_set'] ) && 'yes' === $gateway_settings['apple_pay_domain_set'] && file_exists( $fullpath ) ) {
318
+			if ( ! empty($gateway_settings['apple_pay_domain_set']) && 'yes' === $gateway_settings['apple_pay_domain_set'] && file_exists($fullpath)) {
319 319
 				return;
320 320
 			}
321 321
 
322
-			if ( ! file_exists( $path . '/' . $dir ) ) {
323
-				if ( ! @mkdir( $path . '/' . $dir, 0755 ) ) {
324
-					throw new Exception( __( 'Unable to create domain association folder to domain root.', 'woocommerce-gateway-stripe' ) );
322
+			if ( ! file_exists($path . '/' . $dir)) {
323
+				if ( ! @mkdir($path . '/' . $dir, 0755)) {
324
+					throw new Exception(__('Unable to create domain association folder to domain root.', 'woocommerce-gateway-stripe'));
325 325
 				}
326 326
 			}
327 327
 
328
-			if ( ! file_exists( $fullpath ) ) {
329
-				if ( ! @copy( WC_STRIPE_PLUGIN_PATH . '/' . $file, $fullpath ) ) {
330
-					throw new Exception( __( 'Unable to copy domain association file to domain root.', 'woocommerce-gateway-stripe' ) );
328
+			if ( ! file_exists($fullpath)) {
329
+				if ( ! @copy(WC_STRIPE_PLUGIN_PATH . '/' . $file, $fullpath)) {
330
+					throw new Exception(__('Unable to copy domain association file to domain root.', 'woocommerce-gateway-stripe'));
331 331
 				}
332 332
 			}
333 333
 
334 334
 			// At this point then the domain association folder and file should be available.
335 335
 			// Proceed to verify/and or verify again.
336
-			$this->register_apple_pay_domain( $this->secret_key );
336
+			$this->register_apple_pay_domain($this->secret_key);
337 337
 
338 338
 			// No errors to this point, verification success!
339 339
 			$gateway_settings['apple_pay_domain_set'] = 'yes';
340 340
 			$this->apple_pay_domain_set = true;
341 341
 
342
-			update_option( 'woocommerce_stripe_settings', $gateway_settings );
342
+			update_option('woocommerce_stripe_settings', $gateway_settings);
343 343
 
344
-			WC_Stripe_Logger::log( 'Your domain has been verified with Apple Pay!' );
344
+			WC_Stripe_Logger::log('Your domain has been verified with Apple Pay!');
345 345
 
346
-		} catch ( Exception $e ) {
346
+		} catch (Exception $e) {
347 347
 			$gateway_settings['apple_pay_domain_set'] = 'no';
348 348
 
349
-			update_option( 'woocommerce_stripe_settings', $gateway_settings );
349
+			update_option('woocommerce_stripe_settings', $gateway_settings);
350 350
 
351
-			WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() );
351
+			WC_Stripe_Logger::log('Error: ' . $e->getMessage());
352 352
 		}
353 353
 	}
354 354
 
@@ -356,11 +356,11 @@  discard block
 block discarded – undo
356 356
 	 * Check if SSL is enabled and notify the user
357 357
 	 */
358 358
 	public function admin_notices() {
359
-		if ( 'no' === $this->enabled ) {
359
+		if ('no' === $this->enabled) {
360 360
 			return;
361 361
 		}
362 362
 
363
-		if ( $this->payment_request && ! empty( $this->apple_pay_verify_notice ) ) {
363
+		if ($this->payment_request && ! empty($this->apple_pay_verify_notice)) {
364 364
 			$allowed_html = array(
365 365
 				'a' => array(
366 366
 					'href' => array(),
@@ -368,7 +368,7 @@  discard block
 block discarded – undo
368 368
 				),
369 369
 			);
370 370
 
371
-			echo '<div class="error stripe-apple-pay-message"><p>' . wp_kses( make_clickable( $this->apple_pay_verify_notice ), $allowed_html ) . '</p></div>';
371
+			echo '<div class="error stripe-apple-pay-message"><p>' . wp_kses(make_clickable($this->apple_pay_verify_notice), $allowed_html) . '</p></div>';
372 372
 		}
373 373
 
374 374
 		/**
@@ -376,9 +376,9 @@  discard block
 block discarded – undo
376 376
 		 * when setting screen is displayed. So if domain verification is not set,
377 377
 		 * something went wrong so lets notify user.
378 378
 		 */
379
-		if ( ! empty( $this->secret_key ) && $this->payment_request && ! $this->apple_pay_domain_set ) {
379
+		if ( ! empty($this->secret_key) && $this->payment_request && ! $this->apple_pay_domain_set) {
380 380
 			/* translators: 1) HTML anchor open tag 2) HTML anchor closing tag */
381
-			echo '<div class="error stripe-apple-pay-message"><p>' . sprintf( __( 'Apple Pay domain verification failed. Please check the %1$slog%2$s to see the issue. (Logging must be enabled to see recorded logs)', 'woocommerce-gateway-stripe' ), '<a href="' . admin_url( 'admin.php?page=wc-status&tab=logs' ) . '">', '</a>' ) . '</p></div>';
381
+			echo '<div class="error stripe-apple-pay-message"><p>' . sprintf(__('Apple Pay domain verification failed. Please check the %1$slog%2$s to see the issue. (Logging must be enabled to see recorded logs)', 'woocommerce-gateway-stripe'), '<a href="' . admin_url('admin.php?page=wc-status&tab=logs') . '">', '</a>') . '</p></div>';
382 382
 		}
383 383
 	}
384 384
 
@@ -386,7 +386,7 @@  discard block
 block discarded – undo
386 386
 	 * Initialise Gateway Settings Form Fields
387 387
 	 */
388 388
 	public function init_form_fields() {
389
-		$this->form_fields = require( dirname( __FILE__ ) . '/admin/stripe-settings.php' );
389
+		$this->form_fields = require(dirname(__FILE__) . '/admin/stripe-settings.php');
390 390
 	}
391 391
 
392 392
 	/**
@@ -394,59 +394,59 @@  discard block
 block discarded – undo
394 394
 	 */
395 395
 	public function payment_fields() {
396 396
 		$user                 = wp_get_current_user();
397
-		$display_tokenization = $this->supports( 'tokenization' ) && is_checkout() && $this->saved_cards;
397
+		$display_tokenization = $this->supports('tokenization') && is_checkout() && $this->saved_cards;
398 398
 		$total                = WC()->cart->total;
399 399
 		$user_email           = '';
400 400
 
401 401
 		// If paying from order, we need to get total from order not cart.
402
-		if ( isset( $_GET['pay_for_order'] ) && ! empty( $_GET['key'] ) ) {
403
-			$order      = wc_get_order( wc_get_order_id_by_order_key( wc_clean( $_GET['key'] ) ) );
402
+		if (isset($_GET['pay_for_order']) && ! empty($_GET['key'])) {
403
+			$order      = wc_get_order(wc_get_order_id_by_order_key(wc_clean($_GET['key'])));
404 404
 			$total      = $order->get_total();
405 405
 			$user_email = WC_Stripe_Helper::is_pre_30() ? $order->billing_email : $order->get_billing_email();
406 406
 		} else {
407
-			if ( $user->ID ) {
408
-				$user_email = get_user_meta( $user->ID, 'billing_email', true );
407
+			if ($user->ID) {
408
+				$user_email = get_user_meta($user->ID, 'billing_email', true);
409 409
 				$user_email = $user_email ? $user_email : $user->user_email;
410 410
 			}
411 411
 		}
412 412
 
413
-		if ( is_add_payment_method_page() ) {
414
-			$pay_button_text = __( 'Add Card', 'woocommerce-gateway-stripe' );
415
-			$total        = '';
413
+		if (is_add_payment_method_page()) {
414
+			$pay_button_text = __('Add Card', 'woocommerce-gateway-stripe');
415
+			$total = '';
416 416
 		} else {
417 417
 			$pay_button_text = '';
418 418
 		}
419 419
 
420 420
 		echo '<div
421 421
 			id="stripe-payment-data"
422
-			data-panel-label="' . esc_attr( $pay_button_text ) . '"
422
+			data-panel-label="' . esc_attr($pay_button_text) . '"
423 423
 			data-description=""
424
-			data-email="' . esc_attr( $user_email ) . '"
425
-			data-amount="' . esc_attr( WC_Stripe_Helper::get_stripe_amount( $total ) ) . '"
426
-			data-name="' . esc_attr( $this->statement_descriptor ) . '"
427
-			data-currency="' . esc_attr( strtolower( get_woocommerce_currency() ) ) . '"
428
-			data-image="' . esc_attr( $this->stripe_checkout_image ) . '"
429
-			data-bitcoin="' . esc_attr( $this->bitcoin ? 'true' : 'false' ) . '"
430
-			data-locale="' . esc_attr( $this->stripe_checkout_locale ? $this->stripe_checkout_locale : 'en' ) . '"
431
-			data-three-d-secure="' . esc_attr( $this->three_d_secure ? 'true' : 'false' ) . '"
432
-			data-allow-remember-me="' . esc_attr( $this->saved_cards ? 'true' : 'false' ) . '">';
433
-
434
-		if ( $this->description ) {
435
-			if ( $this->testmode ) {
424
+			data-email="' . esc_attr($user_email) . '"
425
+			data-amount="' . esc_attr(WC_Stripe_Helper::get_stripe_amount($total)) . '"
426
+			data-name="' . esc_attr($this->statement_descriptor) . '"
427
+			data-currency="' . esc_attr(strtolower(get_woocommerce_currency())) . '"
428
+			data-image="' . esc_attr($this->stripe_checkout_image) . '"
429
+			data-bitcoin="' . esc_attr($this->bitcoin ? 'true' : 'false') . '"
430
+			data-locale="' . esc_attr($this->stripe_checkout_locale ? $this->stripe_checkout_locale : 'en') . '"
431
+			data-three-d-secure="' . esc_attr($this->three_d_secure ? 'true' : 'false') . '"
432
+			data-allow-remember-me="' . esc_attr($this->saved_cards ? 'true' : 'false') . '">';
433
+
434
+		if ($this->description) {
435
+			if ($this->testmode) {
436 436
 				/* translators: link to Stripe testing page */
437
-				$this->description .= ' ' . sprintf( __( 'TEST MODE ENABLED. In test mode, you can use the card number 4242424242424242 with any CVC and a valid expiration date or check the documentation "<a href="%s" target="_blank">Testing Stripe</a>" for more card numbers.', 'woocommerce-gateway-stripe' ), 'https://stripe.com/docs/testing' );
438
-				$this->description  = trim( $this->description );
437
+				$this->description .= ' ' . sprintf(__('TEST MODE ENABLED. In test mode, you can use the card number 4242424242424242 with any CVC and a valid expiration date or check the documentation "<a href="%s" target="_blank">Testing Stripe</a>" for more card numbers.', 'woocommerce-gateway-stripe'), 'https://stripe.com/docs/testing');
438
+				$this->description  = trim($this->description);
439 439
 			}
440
-			echo apply_filters( 'wc_stripe_description', wpautop( wp_kses_post( $this->description ) ) );
440
+			echo apply_filters('wc_stripe_description', wpautop(wp_kses_post($this->description)));
441 441
 		}
442 442
 
443
-		if ( $display_tokenization ) {
443
+		if ($display_tokenization) {
444 444
 			$this->tokenization_script();
445 445
 			$this->saved_payment_methods();
446 446
 		}
447 447
 
448
-		if ( ! $this->stripe_checkout ) {
449
-			if ( apply_filters( 'wc_stripe_use_elements_checkout_form', true ) ) {
448
+		if ( ! $this->stripe_checkout) {
449
+			if (apply_filters('wc_stripe_use_elements_checkout_form', true)) {
450 450
 				$this->elements_form();
451 451
 			} else {
452 452
 				$this->form();
@@ -454,7 +454,7 @@  discard block
 block discarded – undo
454 454
 			}
455 455
 		}
456 456
 
457
-		if ( apply_filters( 'wc_stripe_display_save_payment_method_checkbox', $display_tokenization ) && ! is_add_payment_method_page() && ! isset( $_GET['change_payment_method'] ) ) {
457
+		if (apply_filters('wc_stripe_display_save_payment_method_checkbox', $display_tokenization) && ! is_add_payment_method_page() && ! isset($_GET['change_payment_method'])) {
458 458
 			$this->save_payment_method_checkbox();
459 459
 		}
460 460
 
@@ -469,13 +469,13 @@  discard block
 block discarded – undo
469 469
 	 */
470 470
 	public function elements_form() {
471 471
 		?>
472
-		<fieldset id="wc-<?php echo esc_attr( $this->id ); ?>-cc-form" class="wc-credit-card-form wc-payment-form" style="background:transparent;">
473
-			<?php do_action( 'woocommerce_credit_card_form_start', $this->id ); ?>
472
+		<fieldset id="wc-<?php echo esc_attr($this->id); ?>-cc-form" class="wc-credit-card-form wc-payment-form" style="background:transparent;">
473
+			<?php do_action('woocommerce_credit_card_form_start', $this->id); ?>
474 474
 			<label for="card-element">
475
-				<?php esc_html_e( 'Credit or debit card', 'woocommerce-gateway-stripe' ); ?>
475
+				<?php esc_html_e('Credit or debit card', 'woocommerce-gateway-stripe'); ?>
476 476
 			</label>
477 477
 
478
-			<?php if ( $this->inline_cc_form ) { ?>
478
+			<?php if ($this->inline_cc_form) { ?>
479 479
 				<div id="stripe-card-element" style="background:#f2f2f2;padding:0 1em;box-shadow:inset 0 1px 1px rgba(0,0,0,.125);margin:5px 0;padding:10px 5px;">
480 480
 				<!-- a Stripe Element will be inserted here. -->
481 481
 				</div>
@@ -494,7 +494,7 @@  discard block
 block discarded – undo
494 494
 
495 495
 			<!-- Used to display form errors -->
496 496
 			<div class="stripe-source-errors" role="alert"></div>
497
-			<?php do_action( 'woocommerce_credit_card_form_end', $this->id ); ?>
497
+			<?php do_action('woocommerce_credit_card_form_end', $this->id); ?>
498 498
 			<div class="clear"></div>
499 499
 		</fieldset>
500 500
 		<?php
@@ -507,13 +507,13 @@  discard block
 block discarded – undo
507 507
 	 * @version 3.1.0
508 508
 	 */
509 509
 	public function admin_scripts() {
510
-		if ( 'woocommerce_page_wc-settings' !== get_current_screen()->id ) {
510
+		if ('woocommerce_page_wc-settings' !== get_current_screen()->id) {
511 511
 			return;
512 512
 		}
513 513
 
514
-		$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
514
+		$suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';
515 515
 
516
-		wp_enqueue_script( 'woocommerce_stripe_admin', plugins_url( 'assets/js/stripe-admin' . $suffix . '.js', WC_STRIPE_MAIN_FILE ), array(), WC_STRIPE_VERSION, true );
516
+		wp_enqueue_script('woocommerce_stripe_admin', plugins_url('assets/js/stripe-admin' . $suffix . '.js', WC_STRIPE_MAIN_FILE), array(), WC_STRIPE_VERSION, true);
517 517
 	}
518 518
 
519 519
 	/**
@@ -525,29 +525,29 @@  discard block
 block discarded – undo
525 525
 	 * @version 4.0.0
526 526
 	 */
527 527
 	public function payment_scripts() {
528
-		if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) && ! is_add_payment_method_page() && ! isset( $_GET['change_payment_method'] ) ) {
528
+		if ( ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order']) && ! is_add_payment_method_page() && ! isset($_GET['change_payment_method'])) {
529 529
 			return;
530 530
 		}
531 531
 
532
-		$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
532
+		$suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';
533 533
 
534
-		wp_register_style( 'stripe_paymentfonts', plugins_url( 'assets/css/stripe-paymentfonts.css', WC_STRIPE_MAIN_FILE ), array(), '1.2.5' );
535
-		wp_enqueue_style( 'stripe_paymentfonts' );
536
-		wp_register_script( 'stripe_checkout', 'https://checkout.stripe.com/checkout.js', '', WC_STRIPE_VERSION, true );
537
-		wp_register_script( 'stripev2', 'https://js.stripe.com/v2/', '', '2.0', true );
538
-		wp_register_script( 'stripe', 'https://js.stripe.com/v3/', '', '3.0', true );
539
-		wp_register_script( 'woocommerce_stripe', plugins_url( 'assets/js/stripe' . $suffix . '.js', WC_STRIPE_MAIN_FILE ), array( 'jquery-payment', 'stripev2', 'stripe' ), WC_STRIPE_VERSION, true );
534
+		wp_register_style('stripe_paymentfonts', plugins_url('assets/css/stripe-paymentfonts.css', WC_STRIPE_MAIN_FILE), array(), '1.2.5');
535
+		wp_enqueue_style('stripe_paymentfonts');
536
+		wp_register_script('stripe_checkout', 'https://checkout.stripe.com/checkout.js', '', WC_STRIPE_VERSION, true);
537
+		wp_register_script('stripev2', 'https://js.stripe.com/v2/', '', '2.0', true);
538
+		wp_register_script('stripe', 'https://js.stripe.com/v3/', '', '3.0', true);
539
+		wp_register_script('woocommerce_stripe', plugins_url('assets/js/stripe' . $suffix . '.js', WC_STRIPE_MAIN_FILE), array('jquery-payment', 'stripev2', 'stripe'), WC_STRIPE_VERSION, true);
540 540
 
541 541
 		$stripe_params = array(
542 542
 			'key'                  => $this->publishable_key,
543
-			'i18n_terms'           => __( 'Please accept the terms and conditions first', 'woocommerce-gateway-stripe' ),
544
-			'i18n_required_fields' => __( 'Please fill in required checkout fields first', 'woocommerce-gateway-stripe' ),
543
+			'i18n_terms'           => __('Please accept the terms and conditions first', 'woocommerce-gateway-stripe'),
544
+			'i18n_required_fields' => __('Please fill in required checkout fields first', 'woocommerce-gateway-stripe'),
545 545
 		);
546 546
 
547 547
 		// If we're on the pay page we need to pass stripe.js the address of the order.
548
-		if ( isset( $_GET['pay_for_order'] ) && 'true' === $_GET['pay_for_order'] ) {
549
-			$order_id = wc_get_order_id_by_order_key( urldecode( $_GET['key'] ) );
550
-			$order    = wc_get_order( $order_id );
548
+		if (isset($_GET['pay_for_order']) && 'true' === $_GET['pay_for_order']) {
549
+			$order_id = wc_get_order_id_by_order_key(urldecode($_GET['key']));
550
+			$order    = wc_get_order($order_id);
551 551
 
552 552
 			$stripe_params['billing_first_name'] = WC_Stripe_Helper::is_pre_30() ? $order->billing_first_name : $order->get_billing_first_name();
553 553
 			$stripe_params['billing_last_name']  = WC_Stripe_Helper::is_pre_30() ? $order->billing_last_name : $order->get_billing_last_name();
@@ -559,36 +559,36 @@  discard block
 block discarded – undo
559 559
 			$stripe_params['billing_country']    = WC_Stripe_Helper::is_pre_30() ? $order->billing_country : $order->get_billing_country();
560 560
 		}
561 561
 
562
-		$stripe_params['no_prepaid_card_msg']                     = __( 'Sorry, we\'re not accepting prepaid cards at this time. Your credit card has not been charge. Please try with alternative payment method.', 'woocommerce-gateway-stripe' );
563
-		$stripe_params['no_bank_country_msg']                     = __( 'Please select a country for your bank.', 'woocommerce-gateway-stripe' );
564
-		$stripe_params['no_sepa_owner_msg']                       = __( 'Please enter your IBAN account name.', 'woocommerce-gateway-stripe' );
565
-		$stripe_params['no_sepa_iban_msg']                        = __( 'Please enter your IBAN account number.', 'woocommerce-gateway-stripe' );
566
-		$stripe_params['allow_prepaid_card']                      = apply_filters( 'wc_stripe_allow_prepaid_card', true ) ? 'yes' : 'no';
562
+		$stripe_params['no_prepaid_card_msg']                     = __('Sorry, we\'re not accepting prepaid cards at this time. Your credit card has not been charge. Please try with alternative payment method.', 'woocommerce-gateway-stripe');
563
+		$stripe_params['no_bank_country_msg']                     = __('Please select a country for your bank.', 'woocommerce-gateway-stripe');
564
+		$stripe_params['no_sepa_owner_msg']                       = __('Please enter your IBAN account name.', 'woocommerce-gateway-stripe');
565
+		$stripe_params['no_sepa_iban_msg']                        = __('Please enter your IBAN account number.', 'woocommerce-gateway-stripe');
566
+		$stripe_params['allow_prepaid_card']                      = apply_filters('wc_stripe_allow_prepaid_card', true) ? 'yes' : 'no';
567 567
 		$stripe_params['inline_cc_form']                          = $this->inline_cc_form ? 'yes' : 'no';
568
-		$stripe_params['stripe_checkout_require_billing_address'] = apply_filters( 'wc_stripe_checkout_require_billing_address', false ) ? 'yes' : 'no';
569
-		$stripe_params['is_checkout']                             = ( is_checkout() && empty( $_GET['pay_for_order'] ) );
568
+		$stripe_params['stripe_checkout_require_billing_address'] = apply_filters('wc_stripe_checkout_require_billing_address', false) ? 'yes' : 'no';
569
+		$stripe_params['is_checkout']                             = (is_checkout() && empty($_GET['pay_for_order']));
570 570
 		$stripe_params['return_url']                              = $this->get_stripe_return_url();
571
-		$stripe_params['ajaxurl']                                 = WC_AJAX::get_endpoint( '%%endpoint%%' );
572
-		$stripe_params['stripe_nonce']                            = wp_create_nonce( '_wc_stripe_nonce' );
571
+		$stripe_params['ajaxurl']                                 = WC_AJAX::get_endpoint('%%endpoint%%');
572
+		$stripe_params['stripe_nonce']                            = wp_create_nonce('_wc_stripe_nonce');
573 573
 		$stripe_params['statement_descriptor']                    = $this->statement_descriptor;
574
-		$stripe_params['use_elements']                            = apply_filters( 'wc_stripe_use_elements_checkout_form', true ) ? 'yes' : 'no';
574
+		$stripe_params['use_elements']                            = apply_filters('wc_stripe_use_elements_checkout_form', true) ? 'yes' : 'no';
575 575
 		$stripe_params['is_stripe_checkout']                      = $this->stripe_checkout ? 'yes' : 'no';
576
-		$stripe_params['is_change_payment_page']                  = ( isset( $_GET['pay_for_order'] ) || isset( $_GET['change_payment_method'] ) ) ? 'yes' : 'no';
577
-		$stripe_params['elements_styling']                        = apply_filters( 'wc_stripe_elements_styling', false );
578
-		$stripe_params['elements_classes']                        = apply_filters( 'wc_stripe_elements_classes', false );
576
+		$stripe_params['is_change_payment_page']                  = (isset($_GET['pay_for_order']) || isset($_GET['change_payment_method'])) ? 'yes' : 'no';
577
+		$stripe_params['elements_styling']                        = apply_filters('wc_stripe_elements_styling', false);
578
+		$stripe_params['elements_classes']                        = apply_filters('wc_stripe_elements_classes', false);
579 579
 
580 580
 		// merge localized messages to be use in JS
581
-		$stripe_params = array_merge( $stripe_params, WC_Stripe_Helper::get_localized_messages() );
581
+		$stripe_params = array_merge($stripe_params, WC_Stripe_Helper::get_localized_messages());
582 582
 
583
-		wp_localize_script( 'woocommerce_stripe', 'wc_stripe_params', apply_filters( 'wc_stripe_params', $stripe_params ) );
584
-		wp_localize_script( 'woocommerce_stripe_checkout', 'wc_stripe_params', apply_filters( 'wc_stripe_params', $stripe_params ) );
583
+		wp_localize_script('woocommerce_stripe', 'wc_stripe_params', apply_filters('wc_stripe_params', $stripe_params));
584
+		wp_localize_script('woocommerce_stripe_checkout', 'wc_stripe_params', apply_filters('wc_stripe_params', $stripe_params));
585 585
 
586
-		if ( $this->stripe_checkout ) {
587
-			wp_enqueue_script( 'stripe_checkout' );
586
+		if ($this->stripe_checkout) {
587
+			wp_enqueue_script('stripe_checkout');
588 588
 		}
589 589
 
590 590
 		$this->tokenization_script();
591
-		wp_enqueue_script( 'woocommerce_stripe' );
591
+		wp_enqueue_script('woocommerce_stripe');
592 592
 	}
593 593
 
594 594
 	/**
@@ -600,22 +600,22 @@  discard block
 block discarded – undo
600 600
 	 * @param object $source_object
601 601
 	 * @return mixed
602 602
 	 */
603
-	public function create_3ds_source( $order, $source_object ) {
603
+	public function create_3ds_source($order, $source_object) {
604 604
 		$currency                    = WC_Stripe_Helper::is_pre_30() ? $order->get_order_currency() : $order->get_currency();
605 605
 		$order_id                    = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
606
-		$return_url                  = $this->get_stripe_return_url( $order );
606
+		$return_url                  = $this->get_stripe_return_url($order);
607 607
 
608 608
 		$post_data                   = array();
609
-		$post_data['amount']         = WC_Stripe_Helper::get_stripe_amount( $order->get_total(), $currency );
610
-		$post_data['currency']       = strtolower( $currency );
609
+		$post_data['amount']         = WC_Stripe_Helper::get_stripe_amount($order->get_total(), $currency);
610
+		$post_data['currency']       = strtolower($currency);
611 611
 		$post_data['type']           = 'three_d_secure';
612
-		$post_data['owner']          = $this->get_owner_details( $order );
613
-		$post_data['three_d_secure'] = array( 'card' => $source_object->id );
614
-		$post_data['redirect']       = array( 'return_url' => $return_url );
612
+		$post_data['owner']          = $this->get_owner_details($order);
613
+		$post_data['three_d_secure'] = array('card' => $source_object->id);
614
+		$post_data['redirect']       = array('return_url' => $return_url);
615 615
 
616
-		WC_Stripe_Logger::log( 'Info: Begin creating 3DS source' );
616
+		WC_Stripe_Logger::log('Info: Begin creating 3DS source');
617 617
 
618
-		return WC_Stripe_API::request( $post_data, 'sources' );
618
+		return WC_Stripe_API::request($post_data, 'sources');
619 619
 	}
620 620
 
621 621
 	/**
@@ -631,46 +631,46 @@  discard block
 block discarded – undo
631 631
 	 *
632 632
 	 * @return array|void
633 633
 	 */
634
-	public function process_payment( $order_id, $retry = true, $force_save_source = false ) {
634
+	public function process_payment($order_id, $retry = true, $force_save_source = false) {
635 635
 		try {
636
-			$order          = wc_get_order( $order_id );
637
-			$source_object  = ! empty( $_POST['stripe_source'] ) ? json_decode( wc_clean( stripslashes( $_POST['stripe_source'] ) ) ) : false;
636
+			$order          = wc_get_order($order_id);
637
+			$source_object  = ! empty($_POST['stripe_source']) ? json_decode(wc_clean(stripslashes($_POST['stripe_source']))) : false;
638 638
 
639 639
 			// This comes from the create account checkbox in the checkout page.
640
-			$create_account = ! empty( $_POST['createaccount'] ) ? true : false;
640
+			$create_account = ! empty($_POST['createaccount']) ? true : false;
641 641
 
642
-			if ( $create_account ) {
642
+			if ($create_account) {
643 643
 				$new_customer_id     = WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id();
644
-				$new_stripe_customer = new WC_Stripe_Customer( $new_customer_id );
644
+				$new_stripe_customer = new WC_Stripe_Customer($new_customer_id);
645 645
 				$new_stripe_customer->create_customer();
646 646
 			}
647 647
 
648
-			$prepared_source = $this->prepare_source( get_current_user_id(), $force_save_source );
648
+			$prepared_source = $this->prepare_source(get_current_user_id(), $force_save_source);
649 649
 
650 650
 			// Check if we don't allow prepaid credit cards.
651
-			if ( ! apply_filters( 'wc_stripe_allow_prepaid_card', true ) ) {
652
-				$stripe_checkout_object = ! empty( $_POST['stripe_checkout_object'] ) ? json_decode( wc_clean( stripslashes( $_POST['stripe_checkout_object'] ) ) ) : false;
651
+			if ( ! apply_filters('wc_stripe_allow_prepaid_card', true)) {
652
+				$stripe_checkout_object = ! empty($_POST['stripe_checkout_object']) ? json_decode(wc_clean(stripslashes($_POST['stripe_checkout_object']))) : false;
653 653
 
654
-				if ( $stripe_checkout_object && 'token' === $stripe_checkout_object->object && 'prepaid' === $stripe_checkout_object->card->funding ) {
655
-					$error_msg = __( 'Sorry, we\'re not accepting prepaid cards at this time. Your credit card has not been charge. Please try with alternative payment method.', 'woocommerce-gateway-stripe' );
656
-					throw new Exception( $error_msg );
654
+				if ($stripe_checkout_object && 'token' === $stripe_checkout_object->object && 'prepaid' === $stripe_checkout_object->card->funding) {
655
+					$error_msg = __('Sorry, we\'re not accepting prepaid cards at this time. Your credit card has not been charge. Please try with alternative payment method.', 'woocommerce-gateway-stripe');
656
+					throw new Exception($error_msg);
657 657
 				}
658 658
 			}
659 659
 
660
-			if ( empty( $prepared_source->source ) ) {
661
-				$error_msg = __( 'Payment processing failed. Please retry.', 'woocommerce-gateway-stripe' );
662
-				throw new Exception( $error_msg );
660
+			if (empty($prepared_source->source)) {
661
+				$error_msg = __('Payment processing failed. Please retry.', 'woocommerce-gateway-stripe');
662
+				throw new Exception($error_msg);
663 663
 			}
664 664
 
665 665
 			// Store source to order meta.
666
-			$this->save_source( $order, $prepared_source );
666
+			$this->save_source($order, $prepared_source);
667 667
 
668 668
 			// Result from Stripe API request.
669 669
 			$response = null;
670 670
 
671
-			if ( $order->get_total() > 0 ) {
671
+			if ($order->get_total() > 0) {
672 672
 				// This will throw exception if not valid.
673
-				$this->validate_minimum_order_amount( $order );
673
+				$this->validate_minimum_order_amount($order);
674 674
 
675 675
 				/**
676 676
 				 * Check if card 3DS is required or optional with 3DS setting.
@@ -679,79 +679,79 @@  discard block
 block discarded – undo
679 679
 				 * Note that if we need to save source, the original source must be first
680 680
 				 * attached to a customer in Stripe before it can be charged.
681 681
 				 */
682
-				if ( $source_object && ( 'card' === $source_object->type && 'required' === $source_object->card->three_d_secure || ( $this->three_d_secure && 'optional' === $source_object->card->three_d_secure ) ) ) {
682
+				if ($source_object && ('card' === $source_object->type && 'required' === $source_object->card->three_d_secure || ($this->three_d_secure && 'optional' === $source_object->card->three_d_secure))) {
683 683
 
684
-					$response = $this->create_3ds_source( $order, $source_object );
684
+					$response = $this->create_3ds_source($order, $source_object);
685 685
 
686
-					if ( ! empty( $response->error ) ) {
686
+					if ( ! empty($response->error)) {
687 687
 						$message = $response->error->message;
688 688
 
689
-						$order->add_order_note( $message );
689
+						$order->add_order_note($message);
690 690
 
691
-						throw new Exception( $message );
691
+						throw new Exception($message);
692 692
 					}
693 693
 
694 694
 					// Update order meta with 3DS source.
695
-					if ( WC_Stripe_Helper::is_pre_30() ) {
696
-						update_post_meta( $order_id, '_stripe_source_id', $response->id );
695
+					if (WC_Stripe_Helper::is_pre_30()) {
696
+						update_post_meta($order_id, '_stripe_source_id', $response->id);
697 697
 					} else {
698
-						$order->update_meta_data( '_stripe_source_id', $response->id );
698
+						$order->update_meta_data('_stripe_source_id', $response->id);
699 699
 						$order->save();
700 700
 					}
701 701
 
702
-					WC_Stripe_Logger::log( 'Info: Redirecting to 3DS...' );
702
+					WC_Stripe_Logger::log('Info: Redirecting to 3DS...');
703 703
 
704 704
 					return array(
705 705
 						'result'   => 'success',
706
-						'redirect' => esc_url_raw( $response->redirect->url ),
706
+						'redirect' => esc_url_raw($response->redirect->url),
707 707
 					);
708 708
 				}
709 709
 
710
-				WC_Stripe_Logger::log( "Info: Begin processing payment for order $order_id for the amount of {$order->get_total()}" );
710
+				WC_Stripe_Logger::log("Info: Begin processing payment for order $order_id for the amount of {$order->get_total()}");
711 711
 
712 712
 				// Make the request.
713
-				$response = WC_Stripe_API::request( $this->generate_payment_request( $order, $prepared_source ) );
713
+				$response = WC_Stripe_API::request($this->generate_payment_request($order, $prepared_source));
714 714
 
715
-				if ( ! empty( $response->error ) ) {
715
+				if ( ! empty($response->error)) {
716 716
 					// If it is an API error such connection or server, let's retry.
717
-					if ( 'api_connection_error' === $response->error->type || 'api_error' === $response->error->type ) {
718
-						if ( $retry ) {
719
-							sleep( 5 );
720
-							return $this->process_payment( $order_id, false, $force_save_source );
717
+					if ('api_connection_error' === $response->error->type || 'api_error' === $response->error->type) {
718
+						if ($retry) {
719
+							sleep(5);
720
+							return $this->process_payment($order_id, false, $force_save_source);
721 721
 						} else {
722 722
 							$message = 'API connection error and retries exhausted.';
723
-							$order->add_order_note( $message );
724
-							throw new Exception( $message );
723
+							$order->add_order_note($message);
724
+							throw new Exception($message);
725 725
 						}
726 726
 					}
727 727
 
728 728
 					// Customer param wrong? The user may have been deleted on stripe's end. Remove customer_id. Can be retried without.
729
-					if ( preg_match( '/No such customer/i', $response->error->message ) && $retry ) {
730
-						delete_user_meta( WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id(), '_stripe_customer_id' );
729
+					if (preg_match('/No such customer/i', $response->error->message) && $retry) {
730
+						delete_user_meta(WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id(), '_stripe_customer_id');
731 731
 
732
-						return $this->process_payment( $order_id, false, $force_save_source );
733
-					} elseif ( preg_match( '/No such token/i', $response->error->message ) && $prepared_source->token_id ) {
732
+						return $this->process_payment($order_id, false, $force_save_source);
733
+					} elseif (preg_match('/No such token/i', $response->error->message) && $prepared_source->token_id) {
734 734
 						// Source param wrong? The CARD may have been deleted on stripe's end. Remove token and show message.
735
-						$wc_token = WC_Payment_Tokens::get( $prepared_source->token_id );
735
+						$wc_token = WC_Payment_Tokens::get($prepared_source->token_id);
736 736
 						$wc_token->delete();
737
-						$message = __( 'This card is no longer available and has been removed.', 'woocommerce-gateway-stripe' );
738
-						$order->add_order_note( $message );
739
-						throw new Exception( $message );
737
+						$message = __('This card is no longer available and has been removed.', 'woocommerce-gateway-stripe');
738
+						$order->add_order_note($message);
739
+						throw new Exception($message);
740 740
 					}
741 741
 
742 742
 					$localized_messages = WC_Stripe_Helper::get_localized_messages();
743 743
 
744
-					$message = isset( $localized_messages[ $response->error->type ] ) ? $localized_messages[ $response->error->type ] : $response->error->message;
744
+					$message = isset($localized_messages[$response->error->type]) ? $localized_messages[$response->error->type] : $response->error->message;
745 745
 
746
-					$order->add_order_note( $message );
746
+					$order->add_order_note($message);
747 747
 
748
-					throw new Exception( $message );
748
+					throw new Exception($message);
749 749
 				}
750 750
 
751
-				do_action( 'wc_gateway_stripe_process_payment', $response, $order );
751
+				do_action('wc_gateway_stripe_process_payment', $response, $order);
752 752
 
753 753
 				// Process valid response.
754
-				$this->process_response( $response, $order );
754
+				$this->process_response($response, $order);
755 755
 			} else {
756 756
 				$order->payment_complete();
757 757
 			}
@@ -762,17 +762,17 @@  discard block
 block discarded – undo
762 762
 			// Return thank you page redirect.
763 763
 			return array(
764 764
 				'result'   => 'success',
765
-				'redirect' => $this->get_return_url( $order ),
765
+				'redirect' => $this->get_return_url($order),
766 766
 			);
767 767
 
768
-		} catch ( Exception $e ) {
769
-			wc_add_notice( $e->getMessage(), 'error' );
770
-			WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() );
768
+		} catch (Exception $e) {
769
+			wc_add_notice($e->getMessage(), 'error');
770
+			WC_Stripe_Logger::log('Error: ' . $e->getMessage());
771 771
 
772
-			do_action( 'wc_gateway_stripe_process_payment_error', $e, $order );
772
+			do_action('wc_gateway_stripe_process_payment_error', $e, $order);
773 773
 
774
-			if ( $order->has_status( array( 'pending', 'failed' ) ) ) {
775
-				$this->send_failed_order_email( $order_id );
774
+			if ($order->has_status(array('pending', 'failed'))) {
775
+				$this->send_failed_order_email($order_id);
776 776
 			}
777 777
 
778 778
 			return array(
Please login to merge, or discard this patch.
includes/class-wc-stripe-webhook-handler.php 1 patch
Spacing   +139 added lines, -139 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) {
2
+if ( ! defined('ABSPATH')) {
3 3
 	exit;
4 4
 }
5 5
 
@@ -17,7 +17,7 @@  discard block
 block discarded – undo
17 17
 	 * @version 4.0.0
18 18
 	 */
19 19
 	public function __construct() {
20
-		add_action( 'woocommerce_api_wc_stripe', array( $this, 'check_for_webhook' ) );
20
+		add_action('woocommerce_api_wc_stripe', array($this, 'check_for_webhook'));
21 21
 	}
22 22
 
23 23
 	/**
@@ -27,24 +27,24 @@  discard block
 block discarded – undo
27 27
 	 * @version 4.0.0
28 28
 	 */
29 29
 	public function check_for_webhook() {
30
-		if ( ( 'POST' !== $_SERVER['REQUEST_METHOD'] )
31
-			|| ! isset( $_GET['wc-api'] )
32
-			|| ( 'wc_stripe' !== $_GET['wc-api'] )
30
+		if (('POST' !== $_SERVER['REQUEST_METHOD'])
31
+			|| ! isset($_GET['wc-api'])
32
+			|| ('wc_stripe' !== $_GET['wc-api'])
33 33
 		) {
34 34
 			return;
35 35
 		}
36 36
 
37
-		$request_body    = file_get_contents( 'php://input' );
38
-		$request_headers = array_change_key_case( $this->get_request_headers(), CASE_UPPER );
37
+		$request_body    = file_get_contents('php://input');
38
+		$request_headers = array_change_key_case($this->get_request_headers(), CASE_UPPER);
39 39
 
40 40
 		// Validate it to make sure it is legit.
41
-		if ( $this->is_valid_request( $request_headers, $request_body ) ) {
42
-			$this->process_webhook( $request_body );
43
-			status_header( 200 );
41
+		if ($this->is_valid_request($request_headers, $request_body)) {
42
+			$this->process_webhook($request_body);
43
+			status_header(200);
44 44
 			exit;
45 45
 		} else {
46
-			WC_Stripe_Logger::log( 'Incoming webhook failed validation: ' . print_r( $request_body, true ) );
47
-			status_header( 400 );
46
+			WC_Stripe_Logger::log('Incoming webhook failed validation: ' . print_r($request_body, true));
47
+			status_header(400);
48 48
 			exit;
49 49
 		}
50 50
 	}
@@ -59,12 +59,12 @@  discard block
 block discarded – undo
59 59
 	 * @param string $request_body The request body from Stripe.
60 60
 	 * @return bool
61 61
 	 */
62
-	public function is_valid_request( $request_headers = null, $request_body = null ) {
63
-		if ( null === $request_headers || null === $request_body ) {
62
+	public function is_valid_request($request_headers = null, $request_body = null) {
63
+		if (null === $request_headers || null === $request_body) {
64 64
 			return false;
65 65
 		}
66 66
 
67
-		if ( ! empty( $request_headers['USER-AGENT'] ) && ! preg_match( '/Stripe/', $request_headers['USER-AGENT'] ) ) {
67
+		if ( ! empty($request_headers['USER-AGENT']) && ! preg_match('/Stripe/', $request_headers['USER-AGENT'])) {
68 68
 			return false;
69 69
 		}
70 70
 
@@ -80,11 +80,11 @@  discard block
 block discarded – undo
80 80
 	 * @version 4.0.0
81 81
 	 */
82 82
 	public function get_request_headers() {
83
-		if ( ! function_exists( 'getallheaders' ) ) {
83
+		if ( ! function_exists('getallheaders')) {
84 84
 			$headers = [];
85
-			foreach ( $_SERVER as $name => $value ) {
86
-				if ( 'HTTP_' === substr( $name, 0, 5 ) ) {
87
-					$headers[ str_replace( ' ', '-', ucwords( strtolower( str_replace( '_', ' ', substr( $name, 5 ) ) ) ) ) ] = $value;
85
+			foreach ($_SERVER as $name => $value) {
86
+				if ('HTTP_' === substr($name, 0, 5)) {
87
+					$headers[str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', substr($name, 5)))))] = $value;
88 88
 				}
89 89
 			}
90 90
 
@@ -103,30 +103,30 @@  discard block
 block discarded – undo
103 103
 	 * @param object $notification
104 104
 	 * @param bool $retry
105 105
 	 */
106
-	public function process_webhook_payment( $notification, $retry = true ) {
106
+	public function process_webhook_payment($notification, $retry = true) {
107 107
 		// The following 2 payment methods are synchronous so does not need to be handle via webhook.
108
-		if ( 'card' === $notification->data->object->type || 'sepa_debit' === $notification->data->object->type ) {
108
+		if ('card' === $notification->data->object->type || 'sepa_debit' === $notification->data->object->type) {
109 109
 			return;
110 110
 		}
111 111
 
112
-		$order = WC_Stripe_Helper::get_order_by_source_id( $notification->data->object->id );
112
+		$order = WC_Stripe_Helper::get_order_by_source_id($notification->data->object->id);
113 113
 
114
-		if ( ! $order ) {
115
-			WC_Stripe_Logger::log( 'Could not find order via source ID: ' . $notification->data->object->id );
114
+		if ( ! $order) {
115
+			WC_Stripe_Logger::log('Could not find order via source ID: ' . $notification->data->object->id);
116 116
 			return;
117 117
 		}
118 118
 
119 119
 		$order_id  = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
120 120
 		$source_id = $notification->data->object->id;
121 121
 
122
-		$is_pending_receiver = ( 'receiver' === $notification->data->object->flow );
122
+		$is_pending_receiver = ('receiver' === $notification->data->object->flow);
123 123
 
124 124
 		try {
125
-			if ( 'processing' === $order->get_status() || 'completed' === $order->get_status() ) {
125
+			if ('processing' === $order->get_status() || 'completed' === $order->get_status()) {
126 126
 				return;
127 127
 			}
128 128
 
129
-			if ( 'on-hold' === $order->get_status() && ! $is_pending_receiver ) {
129
+			if ('on-hold' === $order->get_status() && ! $is_pending_receiver) {
130 130
 				return;
131 131
 			}
132 132
 
@@ -134,69 +134,69 @@  discard block
 block discarded – undo
134 134
 			$response = null;
135 135
 
136 136
 			// This will throw exception if not valid.
137
-			$this->validate_minimum_order_amount( $order );
137
+			$this->validate_minimum_order_amount($order);
138 138
 
139
-			WC_Stripe_Logger::log( "Info: (Webhook) Begin processing payment for order $order_id for the amount of {$order->get_total()}" );
139
+			WC_Stripe_Logger::log("Info: (Webhook) Begin processing payment for order $order_id for the amount of {$order->get_total()}");
140 140
 
141 141
 			// Prep source object.
142 142
 			$source_object           = new stdClass();
143 143
 			$source_object->token_id = '';
144
-			$source_object->customer = $this->get_stripe_customer_id( $order );
144
+			$source_object->customer = $this->get_stripe_customer_id($order);
145 145
 			$source_object->source   = $source_id;
146 146
 
147 147
 			// Make the request.
148
-			$response = WC_Stripe_API::request( $this->generate_payment_request( $order, $source_object ) );
148
+			$response = WC_Stripe_API::request($this->generate_payment_request($order, $source_object));
149 149
 
150
-			if ( ! empty( $response->error ) ) {
150
+			if ( ! empty($response->error)) {
151 151
 				// If it is an API error such connection or server, let's retry.
152
-				if ( 'api_connection_error' === $response->error->type || 'api_error' === $response->error->type ) {
153
-					if ( $retry ) {
154
-						sleep( 5 );
155
-						return $this->process_payment( $order_id, false );
152
+				if ('api_connection_error' === $response->error->type || 'api_error' === $response->error->type) {
153
+					if ($retry) {
154
+						sleep(5);
155
+						return $this->process_payment($order_id, false);
156 156
 					} else {
157 157
 						$message = 'API connection error and retries exhausted.';
158
-						$order->add_order_note( $message );
159
-						throw new Exception( $message );
158
+						$order->add_order_note($message);
159
+						throw new Exception($message);
160 160
 					}
161 161
 				}
162 162
 
163 163
 				// Customer param wrong? The user may have been deleted on stripe's end. Remove customer_id. Can be retried without.
164
-				if ( preg_match( '/No such customer/i', $response->error->message ) && $retry ) {
165
-					delete_user_meta( WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id(), '_stripe_customer_id' );
164
+				if (preg_match('/No such customer/i', $response->error->message) && $retry) {
165
+					delete_user_meta(WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id(), '_stripe_customer_id');
166 166
 
167
-					return $this->process_payment( $order_id, false );
167
+					return $this->process_payment($order_id, false);
168 168
 
169
-				} elseif ( preg_match( '/No such token/i', $response->error->message ) && $source_object->token_id ) {
169
+				} elseif (preg_match('/No such token/i', $response->error->message) && $source_object->token_id) {
170 170
 					// Source param wrong? The CARD may have been deleted on stripe's end. Remove token and show message.
171
-					$wc_token = WC_Payment_Tokens::get( $source_object->token_id );
171
+					$wc_token = WC_Payment_Tokens::get($source_object->token_id);
172 172
 					$wc_token->delete();
173
-					$message = __( 'This card is no longer available and has been removed.', 'woocommerce-gateway-stripe' );
174
-					$order->add_order_note( $message );
175
-					throw new Exception( $message );
173
+					$message = __('This card is no longer available and has been removed.', 'woocommerce-gateway-stripe');
174
+					$order->add_order_note($message);
175
+					throw new Exception($message);
176 176
 				}
177 177
 
178 178
 				$localized_messages = WC_Stripe_Helper::get_localized_messages();
179 179
 
180
-				$message = isset( $localized_messages[ $response->error->type ] ) ? $localized_messages[ $response->error->type ] : $response->error->message;
180
+				$message = isset($localized_messages[$response->error->type]) ? $localized_messages[$response->error->type] : $response->error->message;
181 181
 
182
-				$order->add_order_note( $message );
182
+				$order->add_order_note($message);
183 183
 
184
-				throw new Exception( $message );
184
+				throw new Exception($message);
185 185
 			}
186 186
 
187
-			do_action( 'wc_gateway_stripe_process_webhook_payment', $response, $order );
187
+			do_action('wc_gateway_stripe_process_webhook_payment', $response, $order);
188 188
 
189
-			$this->process_response( $response, $order );
189
+			$this->process_response($response, $order);
190 190
 
191
-		} catch ( Exception $e ) {
192
-			WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() );
191
+		} catch (Exception $e) {
192
+			WC_Stripe_Logger::log('Error: ' . $e->getMessage());
193 193
 
194
-			do_action( 'wc_gateway_stripe_process_webhook_payment_error', $e, $order );
194
+			do_action('wc_gateway_stripe_process_webhook_payment_error', $e, $order);
195 195
 
196
-			$statuses = array( 'pending', 'failed' );
196
+			$statuses = array('pending', 'failed');
197 197
 
198
-			if ( $order->has_status( $statuses ) ) {
199
-				$this->send_failed_order_email( $order_id );
198
+			if ($order->has_status($statuses)) {
199
+				$this->send_failed_order_email($order_id);
200 200
 			}
201 201
 		}
202 202
 	}
@@ -210,18 +210,18 @@  discard block
 block discarded – undo
210 210
 	 * @version 4.0.0
211 211
 	 * @param object $notification
212 212
 	 */
213
-	public function process_webhook_dispute( $notification ) {
214
-		$order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->id );
213
+	public function process_webhook_dispute($notification) {
214
+		$order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->id);
215 215
 
216
-		if ( ! $order ) {
217
-			WC_Stripe_Logger::log( 'Could not find order via charge ID: ' . $notification->data->object->id );
216
+		if ( ! $order) {
217
+			WC_Stripe_Logger::log('Could not find order via charge ID: ' . $notification->data->object->id);
218 218
 			return;
219 219
 		}
220 220
 
221
-		$order->update_status( 'on-hold', __( 'A dispute was created for this order. Response is needed. Please go to your Stripe Dashboard to review this dispute.', 'woocommerce-gateway-stripe' ) );
221
+		$order->update_status('on-hold', __('A dispute was created for this order. Response is needed. Please go to your Stripe Dashboard to review this dispute.', 'woocommerce-gateway-stripe'));
222 222
 
223
-		do_action( 'wc_gateway_stripe_process_webhook_payment_error', $order, $notification );
224
-		$this->send_failed_order_email( $order_id );
223
+		do_action('wc_gateway_stripe_process_webhook_payment_error', $order, $notification);
224
+		$this->send_failed_order_email($order_id);
225 225
 	}
226 226
 
227 227
 	/**
@@ -232,41 +232,41 @@  discard block
 block discarded – undo
232 232
 	 * @version 4.0.0
233 233
 	 * @param object $notification
234 234
 	 */
235
-	public function process_webhook_capture( $notification ) {
236
-		$order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->id );
235
+	public function process_webhook_capture($notification) {
236
+		$order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->id);
237 237
 
238
-		if ( ! $order ) {
239
-			WC_Stripe_Logger::log( 'Could not find order via charge ID: ' . $notification->data->object->id );
238
+		if ( ! $order) {
239
+			WC_Stripe_Logger::log('Could not find order via charge ID: ' . $notification->data->object->id);
240 240
 			return;
241 241
 		}
242 242
 
243 243
 		$order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
244 244
 
245
-		if ( 'stripe' === ( WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method() ) ) {
246
-			$charge   = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_transaction_id', true ) : $order->get_transaction_id();
247
-			$captured = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_stripe_charge_captured', true ) : $order->get_meta( '_stripe_charge_captured', true );
245
+		if ('stripe' === (WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method())) {
246
+			$charge   = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_transaction_id', true) : $order->get_transaction_id();
247
+			$captured = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_stripe_charge_captured', true) : $order->get_meta('_stripe_charge_captured', true);
248 248
 
249
-			if ( $charge && 'no' === $captured ) {
250
-				WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, '_stripe_charge_captured', 'yes' ) : $order->update_meta_data( '_stripe_charge_captured', 'yes' );
249
+			if ($charge && 'no' === $captured) {
250
+				WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, '_stripe_charge_captured', 'yes') : $order->update_meta_data('_stripe_charge_captured', 'yes');
251 251
 
252 252
 				// Store other data such as fees
253
-				WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, '_transaction_id', $notification->data->object->id ) : $order->set_transaction_id( $notification->data->object->id );
253
+				WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, '_transaction_id', $notification->data->object->id) : $order->set_transaction_id($notification->data->object->id);
254 254
 
255
-				if ( isset( $notification->data->object->balance_transaction ) ) {
256
-					$this->update_fees( $order, $notification->data->object->balance_transaction );
255
+				if (isset($notification->data->object->balance_transaction)) {
256
+					$this->update_fees($order, $notification->data->object->balance_transaction);
257 257
 				}
258 258
 
259
-				if ( is_callable( array( $order, 'save' ) ) ) {
259
+				if (is_callable(array($order, 'save'))) {
260 260
 					$order->save();
261 261
 				}
262 262
 
263 263
 				/* translators: transaction id */
264
-				$order->update_status( $order->needs_processing() ? 'processing' : 'completed', sprintf( __( 'Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe' ), $notification->data->object->id ) );
264
+				$order->update_status($order->needs_processing() ? 'processing' : 'completed', sprintf(__('Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe'), $notification->data->object->id));
265 265
 
266 266
 				// Check and see if capture is partial.
267
-				if ( $this->is_partial_capture( $notification ) ) {
268
-					$order->set_total( $this->get_partial_amount_to_charge( $notification ) );
269
-					$order->add_note( __( 'This charge was partially captured via Stripe Dashboard', 'woocommerce-gateway-stripe' ) );
267
+				if ($this->is_partial_capture($notification)) {
268
+					$order->set_total($this->get_partial_amount_to_charge($notification));
269
+					$order->add_note(__('This charge was partially captured via Stripe Dashboard', 'woocommerce-gateway-stripe'));
270 270
 					$order->save();
271 271
 				}
272 272
 			}
@@ -281,38 +281,38 @@  discard block
 block discarded – undo
281 281
 	 * @version 4.0.0
282 282
 	 * @param object $notification
283 283
 	 */
284
-	public function process_webhook_charge_succeeded( $notification ) {
284
+	public function process_webhook_charge_succeeded($notification) {
285 285
 		// The following payment methods are synchronous so does not need to be handle via webhook.
286
-		if ( ( isset( $notification->data->object->source->type ) && 'card' === $notification->data->object->source->type ) || ( isset( $notification->data->object->source->type ) && 'three_d_secure' === $notification->data->object->source->type ) ) {
286
+		if ((isset($notification->data->object->source->type) && 'card' === $notification->data->object->source->type) || (isset($notification->data->object->source->type) && 'three_d_secure' === $notification->data->object->source->type)) {
287 287
 			return;
288 288
 		}
289 289
 
290
-		$order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->id );
290
+		$order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->id);
291 291
 
292
-		if ( ! $order ) {
293
-			WC_Stripe_Logger::log( 'Could not find order via charge ID: ' . $notification->data->object->id );
292
+		if ( ! $order) {
293
+			WC_Stripe_Logger::log('Could not find order via charge ID: ' . $notification->data->object->id);
294 294
 			return;
295 295
 		}
296 296
 
297 297
 		$order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
298 298
 
299
-		if ( 'on-hold' !== $order->get_status() ) {
299
+		if ('on-hold' !== $order->get_status()) {
300 300
 			return;
301 301
 		}
302 302
 
303 303
 		// Store other data such as fees
304
-		WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, '_transaction_id', $notification->data->object->id ) : $order->set_transaction_id( $notification->data->object->id );
304
+		WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, '_transaction_id', $notification->data->object->id) : $order->set_transaction_id($notification->data->object->id);
305 305
 
306
-		if ( isset( $notification->data->object->balance_transaction ) ) {
307
-			$this->update_fees( $order, $notification->data->object->balance_transaction );
306
+		if (isset($notification->data->object->balance_transaction)) {
307
+			$this->update_fees($order, $notification->data->object->balance_transaction);
308 308
 		}
309 309
 
310
-		if ( is_callable( array( $order, 'save' ) ) ) {
310
+		if (is_callable(array($order, 'save'))) {
311 311
 			$order->save();
312 312
 		}
313 313
 
314 314
 		/* translators: transaction id */
315
-		$order->update_status( $order->needs_processing() ? 'processing' : 'completed', sprintf( __( 'Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe' ), $notification->data->object->id ) );
315
+		$order->update_status($order->needs_processing() ? 'processing' : 'completed', sprintf(__('Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe'), $notification->data->object->id));
316 316
 	}
317 317
 
318 318
 	/**
@@ -323,23 +323,23 @@  discard block
 block discarded – undo
323 323
 	 * @version 4.0.0
324 324
 	 * @param object $notification
325 325
 	 */
326
-	public function process_webhook_charge_failed( $notification ) {
327
-		$order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->id );
326
+	public function process_webhook_charge_failed($notification) {
327
+		$order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->id);
328 328
 
329
-		if ( ! $order ) {
330
-			WC_Stripe_Logger::log( 'Could not find order via charge ID: ' . $notification->data->object->id );
329
+		if ( ! $order) {
330
+			WC_Stripe_Logger::log('Could not find order via charge ID: ' . $notification->data->object->id);
331 331
 			return;
332 332
 		}
333 333
 
334 334
 		$order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
335 335
 
336
-		if ( 'on-hold' !== $order->get_status() ) {
336
+		if ('on-hold' !== $order->get_status()) {
337 337
 			return;
338 338
 		}
339 339
 
340
-		$order->update_status( 'failed', __( 'This payment failed to clear.', 'woocommerce-gateway-stripe' ) );
340
+		$order->update_status('failed', __('This payment failed to clear.', 'woocommerce-gateway-stripe'));
341 341
 
342
-		do_action( 'wc_gateway_stripe_process_webhook_payment_error', $order, $notification );
342
+		do_action('wc_gateway_stripe_process_webhook_payment_error', $order, $notification);
343 343
 	}
344 344
 
345 345
 	/**
@@ -350,23 +350,23 @@  discard block
 block discarded – undo
350 350
 	 * @version 4.0.0
351 351
 	 * @param object $notification
352 352
 	 */
353
-	public function process_webhook_source_canceled( $notification ) {
354
-		$order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->id );
353
+	public function process_webhook_source_canceled($notification) {
354
+		$order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->id);
355 355
 
356
-		if ( ! $order ) {
357
-			WC_Stripe_Logger::log( 'Could not find order via charge ID: ' . $notification->data->object->id );
356
+		if ( ! $order) {
357
+			WC_Stripe_Logger::log('Could not find order via charge ID: ' . $notification->data->object->id);
358 358
 			return;
359 359
 		}
360 360
 
361 361
 		$order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
362 362
 
363
-		if ( 'on-hold' !== $order->get_status() || 'cancelled' !== $order->get_status() ) {
363
+		if ('on-hold' !== $order->get_status() || 'cancelled' !== $order->get_status()) {
364 364
 			return;
365 365
 		}
366 366
 
367
-		$order->update_status( 'cancelled', __( 'This payment has cancelled.', 'woocommerce-gateway-stripe' ) );
367
+		$order->update_status('cancelled', __('This payment has cancelled.', 'woocommerce-gateway-stripe'));
368 368
 
369
-		do_action( 'wc_gateway_stripe_process_webhook_payment_error', $order, $notification );
369
+		do_action('wc_gateway_stripe_process_webhook_payment_error', $order, $notification);
370 370
 	}
371 371
 
372 372
 	/**
@@ -377,31 +377,31 @@  discard block
 block discarded – undo
377 377
 	 * @version 4.0.0
378 378
 	 * @param object $notification
379 379
 	 */
380
-	public function process_webhook_refund( $notification ) {
381
-		$order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->id );
380
+	public function process_webhook_refund($notification) {
381
+		$order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->id);
382 382
 
383
-		if ( ! $order ) {
384
-			WC_Stripe_Logger::log( 'Could not find order via charge ID: ' . $notification->data->object->id );
383
+		if ( ! $order) {
384
+			WC_Stripe_Logger::log('Could not find order via charge ID: ' . $notification->data->object->id);
385 385
 			return;
386 386
 		}
387 387
 
388 388
 		$order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
389 389
 
390
-		if ( 'stripe' === ( WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method() ) ) {
391
-			$charge   = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_transaction_id', true ) : $order->get_transaction_id();
392
-			$captured = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_stripe_charge_captured', true ) : $order->get_meta( '_stripe_charge_captured', true );
390
+		if ('stripe' === (WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method())) {
391
+			$charge   = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_transaction_id', true) : $order->get_transaction_id();
392
+			$captured = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_stripe_charge_captured', true) : $order->get_meta('_stripe_charge_captured', true);
393 393
 
394 394
 			// Only refund captured charge.
395
-			if ( $charge && 'yes' === $captured ) {
395
+			if ($charge && 'yes' === $captured) {
396 396
 				// Create the refund.
397
-				$refund = wc_create_refund( array(
397
+				$refund = wc_create_refund(array(
398 398
 					'order_id'       => $order_id,
399
-					'amount'         => $this->get_refund_amount( $notification ),
400
-					'reason'         => __( 'Refunded via Stripe Dashboard', 'woocommerce-gateway-stripe' ),
401
-				) );
399
+					'amount'         => $this->get_refund_amount($notification),
400
+					'reason'         => __('Refunded via Stripe Dashboard', 'woocommerce-gateway-stripe'),
401
+				));
402 402
 
403
-				if ( is_wp_error( $refund ) ) {
404
-					WC_Stripe_Logger::log( $refund->get_error_message() );
403
+				if (is_wp_error($refund)) {
404
+					WC_Stripe_Logger::log($refund->get_error_message());
405 405
 				}
406 406
 			}
407 407
 		}
@@ -414,7 +414,7 @@  discard block
 block discarded – undo
414 414
 	 * @version 4.0.0
415 415
 	 * @param object $notification
416 416
 	 */
417
-	public function is_partial_capture( $notification ) {
417
+	public function is_partial_capture($notification) {
418 418
 		return 0 < $notification->data->object->amount_refunded;
419 419
 	}
420 420
 
@@ -425,11 +425,11 @@  discard block
 block discarded – undo
425 425
 	 * @version 4.0.0
426 426
 	 * @param object $notification
427 427
 	 */
428
-	public function get_refund_amount( $notification ) {
429
-		if ( $this->is_partial_capture( $notification ) ) {
428
+	public function get_refund_amount($notification) {
429
+		if ($this->is_partial_capture($notification)) {
430 430
 			$amount = $notification->data->object->amount_refunded / 100;
431 431
 
432
-			if ( in_array( strtolower( $notification->data->object->currency ), WC_Stripe_Helper::no_decimal_currencies() ) ) {
432
+			if (in_array(strtolower($notification->data->object->currency), WC_Stripe_Helper::no_decimal_currencies())) {
433 433
 				$amount = $notification->data->object->amount_refunded;
434 434
 			}
435 435
 
@@ -446,12 +446,12 @@  discard block
 block discarded – undo
446 446
 	 * @version 4.0.0
447 447
 	 * @param object $notification
448 448
 	 */
449
-	public function get_partial_amount_to_charge( $notification ) {
450
-		if ( $this->is_partial_capture( $notification ) ) {
451
-			$amount = ( $notification->data->object->amount - $notification->data->object->amount_refunded ) / 100;
449
+	public function get_partial_amount_to_charge($notification) {
450
+		if ($this->is_partial_capture($notification)) {
451
+			$amount = ($notification->data->object->amount - $notification->data->object->amount_refunded) / 100;
452 452
 
453
-			if ( in_array( strtolower( $notification->data->object->currency ), WC_Stripe_Helper::no_decimal_currencies() ) ) {
454
-				$amount = ( $notification->data->object->amount - $notification->data->object->amount_refunded );
453
+			if (in_array(strtolower($notification->data->object->currency), WC_Stripe_Helper::no_decimal_currencies())) {
454
+				$amount = ($notification->data->object->amount - $notification->data->object->amount_refunded);
455 455
 			}
456 456
 
457 457
 			return $amount;
@@ -467,36 +467,36 @@  discard block
 block discarded – undo
467 467
 	 * @version 4.0.0
468 468
 	 * @param string $request_body
469 469
 	 */
470
-	public function process_webhook( $request_body ) {
471
-		$notification = json_decode( $request_body );
470
+	public function process_webhook($request_body) {
471
+		$notification = json_decode($request_body);
472 472
 
473
-		switch ( $notification->type ) {
473
+		switch ($notification->type) {
474 474
 			case 'source.chargeable':
475
-				$this->process_webhook_payment( $notification );
475
+				$this->process_webhook_payment($notification);
476 476
 				break;
477 477
 
478 478
 			case 'source.canceled':
479
-				$this->process_webhook_source_canceled( $notification );
479
+				$this->process_webhook_source_canceled($notification);
480 480
 				break;
481 481
 
482 482
 			case 'charge.succeeded':
483
-				$this->process_webhook_charge_succeeded( $notification );
483
+				$this->process_webhook_charge_succeeded($notification);
484 484
 				break;
485 485
 
486 486
 			case 'charge.failed':
487
-				$this->process_webhook_charge_failed( $notification );
487
+				$this->process_webhook_charge_failed($notification);
488 488
 				break;
489 489
 
490 490
 			case 'charge.captured':
491
-				$this->process_webhook_capture( $notification );
491
+				$this->process_webhook_capture($notification);
492 492
 				break;
493 493
 
494 494
 			case 'charge.dispute.created':
495
-				$this->process_webhook_dispute( $notification );
495
+				$this->process_webhook_dispute($notification);
496 496
 				break;
497 497
 
498 498
 			case 'charge.refunded':
499
-				$this->process_webhook_refund( $notification );
499
+				$this->process_webhook_refund($notification);
500 500
 				break;
501 501
 
502 502
 		}
Please login to merge, or discard this patch.