Completed
Pull Request — master (#488)
by Roy
02:13
created
includes/compat/class-wc-stripe-compat.php 2 patches
Doc Comments   +3 added lines, -4 removed lines patch added patch discarded remove patch
@@ -64,7 +64,6 @@  discard block
 block discarded – undo
64 64
 	 * Checks if page is pay for order and change subs payment page.
65 65
 	 *
66 66
 	 * @since 4.0.4
67
-	 * @param object $source_object
68 67
 	 * @return bool
69 68
 	 */
70 69
 	public function is_subs_change_payment() {
@@ -222,7 +221,6 @@  discard block
 block discarded – undo
222 221
 	 * process_subscription_payment function.
223 222
 	 * @param mixed $order
224 223
 	 * @param int $amount (default: 0)
225
-	 * @param string $stripe_token (default: '')
226 224
 	 * @param  bool initial_payment
227 225
 	 */
228 226
 	public function process_subscription_payment( $order = '', $amount = 0 ) {
@@ -267,7 +265,6 @@  discard block
 block discarded – undo
267 265
 	 * @todo refactor to avoid DRY.
268 266
 	 * @param mixed $order
269 267
 	 * @param int $amount (default: 0)
270
-	 * @param string $stripe_token (default: '')
271 268
 	 * @param  bool initial_payment
272 269
 	 */
273 270
 	public function retry_subscription_payment( $order = '', $amount = 0 ) {
@@ -320,7 +317,7 @@  discard block
 block discarded – undo
320 317
 
321 318
 	/**
322 319
 	 * Don't transfer Stripe fee/ID meta to renewal orders.
323
-	 * @param int $resubscribe_order The order created for the customer to resubscribe to the old expired/cancelled subscription
320
+	 * @param integer $renewal_order
324 321
 	 */
325 322
 	public function delete_renewal_meta( $renewal_order ) {
326 323
 		delete_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $renewal_order->id : $renewal_order->get_id() ), 'Stripe Fee' );
@@ -562,6 +559,8 @@  discard block
 block discarded – undo
562 559
 	/**
563 560
 	 * Process the pre-order
564 561
 	 * @param int $order_id
562
+	 * @param boolean $retry
563
+	 * @param boolean $force_save_source
565 564
 	 * @return array
566 565
 	 */
567 566
 	public function process_pre_order( $order_id, $retry, $force_save_source ) {
Please login to merge, or discard this patch.
Spacing   +197 added lines, -197 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
 	/**
@@ -68,7 +68,7 @@  discard block
 block discarded – undo
68 68
 	 * @return bool
69 69
 	 */
70 70
 	public function is_subs_change_payment() {
71
-		return ( isset( $_GET['pay_for_order'] ) && isset( $_GET['change_payment_method'] ) );
71
+		return (isset($_GET['pay_for_order']) && isset($_GET['change_payment_method']));
72 72
 	}
73 73
 
74 74
 	/**
@@ -76,8 +76,8 @@  discard block
 block discarded – undo
76 76
 	 * @param  int  $order_id
77 77
 	 * @return boolean
78 78
 	 */
79
-	public function is_pre_order( $order_id ) {
80
-		return ( class_exists( 'WC_Pre_Orders_Order' ) && WC_Pre_Orders_Order::order_contains_pre_order( $order_id ) );
79
+	public function is_pre_order($order_id) {
80
+		return (class_exists('WC_Pre_Orders_Order') && WC_Pre_Orders_Order::order_contains_pre_order($order_id));
81 81
 	}
82 82
 
83 83
 	/**
@@ -86,27 +86,27 @@  discard block
 block discarded – undo
86 86
 	 * @since 4.0.4
87 87
 	 * @param int $order_id
88 88
 	 */
89
-	public function change_subs_payment_method( $order_id ) {
89
+	public function change_subs_payment_method($order_id) {
90 90
 		try {
91
-			$subscription    = wc_get_order( $order_id );
91
+			$subscription    = wc_get_order($order_id);
92 92
 			$source_object   = $this->get_source_object();
93
-			$prepared_source = $this->prepare_source( $source_object, get_current_user_id(), true );
93
+			$prepared_source = $this->prepare_source($source_object, get_current_user_id(), true);
94 94
 
95 95
 			// Check if we don't allow prepaid credit cards.
96
-			if ( ! apply_filters( 'wc_stripe_allow_prepaid_card', true ) ) {
97
-				if ( $source_object && 'token' === $source_object->object && 'prepaid' === $source_object->card->funding ) {
98
-					$localized_message = __( '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' );
99
-					throw new WC_Stripe_Exception( print_r( $source_object, true ), $localized_message );
96
+			if ( ! apply_filters('wc_stripe_allow_prepaid_card', true)) {
97
+				if ($source_object && 'token' === $source_object->object && 'prepaid' === $source_object->card->funding) {
98
+					$localized_message = __('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');
99
+					throw new WC_Stripe_Exception(print_r($source_object, true), $localized_message);
100 100
 				}
101 101
 			}
102 102
 
103
-			if ( empty( $prepared_source->source ) ) {
104
-				$localized_message = __( 'Payment processing failed. Please retry.', 'woocommerce-gateway-stripe' );
105
-				throw new WC_Stripe_Exception( print_r( $prepared_source, true ), $localized_message );
103
+			if (empty($prepared_source->source)) {
104
+				$localized_message = __('Payment processing failed. Please retry.', 'woocommerce-gateway-stripe');
105
+				throw new WC_Stripe_Exception(print_r($prepared_source, true), $localized_message);
106 106
 			}
107 107
 
108 108
 			// Store source to order meta.
109
-			$this->save_source( $subscription, $prepared_source );
109
+			$this->save_source($subscription, $prepared_source);
110 110
 
111 111
 			/*
112 112
 			 * Check if card 3DS is required or optional with 3DS setting.
@@ -115,41 +115,41 @@  discard block
 block discarded – undo
115 115
 			 * Note that if we need to save source, the original source must be first
116 116
 			 * attached to a customer in Stripe before it can be charged.
117 117
 			 */
118
-			if ( $this->is_3ds_required( $source_object ) ) {
118
+			if ($this->is_3ds_required($source_object)) {
119 119
 				$order    = $subscription->get_parent();
120
-				$response = $this->create_3ds_source( $order, $source_object, $subscription->get_view_order_url() );
120
+				$response = $this->create_3ds_source($order, $source_object, $subscription->get_view_order_url());
121 121
 
122
-				if ( ! empty( $response->error ) ) {
122
+				if ( ! empty($response->error)) {
123 123
 					$localized_message = $response->error->message;
124 124
 
125
-					$order->add_order_note( $localized_message );
125
+					$order->add_order_note($localized_message);
126 126
 
127
-					throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message );
127
+					throw new WC_Stripe_Exception(print_r($response, true), $localized_message);
128 128
 				}
129 129
 
130 130
 				// Update order meta with 3DS source.
131
-				if ( WC_Stripe_Helper::is_pre_30() ) {
132
-					update_post_meta( $order_id, '_stripe_source_id', $response->id );
131
+				if (WC_Stripe_Helper::is_pre_30()) {
132
+					update_post_meta($order_id, '_stripe_source_id', $response->id);
133 133
 				} else {
134
-					$subscription->update_meta_data( '_stripe_source_id', $response->id );
134
+					$subscription->update_meta_data('_stripe_source_id', $response->id);
135 135
 					$subscription->save();
136 136
 				}
137 137
 
138
-				WC_Stripe_Logger::log( 'Info: Redirecting to 3DS...' );
138
+				WC_Stripe_Logger::log('Info: Redirecting to 3DS...');
139 139
 
140 140
 				return array(
141 141
 					'result'   => 'success',
142
-					'redirect' => esc_url_raw( $response->redirect->url ),
142
+					'redirect' => esc_url_raw($response->redirect->url),
143 143
 				);
144 144
 			}
145 145
 
146 146
 			return array(
147 147
 				'result'   => 'success',
148
-				'redirect' => $this->get_return_url( $order ),
148
+				'redirect' => $this->get_return_url($order),
149 149
 			);
150
-		} catch ( WC_Stripe_Exception $e ) {
151
-			wc_add_notice( $e->getLocalizedMessage(), 'error' );
152
-			WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() );
150
+		} catch (WC_Stripe_Exception $e) {
151
+			wc_add_notice($e->getLocalizedMessage(), 'error');
152
+			WC_Stripe_Logger::log('Error: ' . $e->getMessage());
153 153
 		}
154 154
 	}
155 155
 
@@ -158,18 +158,18 @@  discard block
 block discarded – undo
158 158
 	 * @param  int $order_id
159 159
 	 * @return array
160 160
 	 */
161
-	public function process_payment( $order_id, $retry = true, $force_save_source = false ) {
162
-		if ( $this->has_subscription( $order_id ) ) {
163
-			if ( $this->is_subs_change_payment() ) {
164
-				return $this->change_subs_payment_method( $order_id );
161
+	public function process_payment($order_id, $retry = true, $force_save_source = false) {
162
+		if ($this->has_subscription($order_id)) {
163
+			if ($this->is_subs_change_payment()) {
164
+				return $this->change_subs_payment_method($order_id);
165 165
 			}
166 166
 
167 167
 			// Regular payment with force customer enabled
168
-			return parent::process_payment( $order_id, true, true );
169
-		} elseif ( $this->is_pre_order( $order_id ) ) {
170
-			return $this->process_pre_order( $order_id, $retry, $force_save_source );
168
+			return parent::process_payment($order_id, true, true);
169
+		} elseif ($this->is_pre_order($order_id)) {
170
+			return $this->process_pre_order($order_id, $retry, $force_save_source);
171 171
 		} else {
172
-			return parent::process_payment( $order_id, $retry, $force_save_source );
172
+			return parent::process_payment($order_id, $retry, $force_save_source);
173 173
 		}
174 174
 	}
175 175
 
@@ -180,14 +180,14 @@  discard block
 block discarded – undo
180 180
 	 * @param array $metadata
181 181
 	 * @param object $order
182 182
 	 */
183
-	public function add_subscription_meta_data( $metadata, $order ) {
184
-		if ( ! $this->has_subscription( $order->get_id() ) ) {
183
+	public function add_subscription_meta_data($metadata, $order) {
184
+		if ( ! $this->has_subscription($order->get_id())) {
185 185
 			return $metadata;
186 186
 		}
187 187
 
188 188
 		return $metadata += array(
189 189
 			'payment_type'   => 'recurring',
190
-			'site_url'       => esc_url( get_site_url() ),
190
+			'site_url'       => esc_url(get_site_url()),
191 191
 		);
192 192
 	}
193 193
 
@@ -197,24 +197,24 @@  discard block
 block discarded – undo
197 197
 	 * @since 3.1.0
198 198
 	 * @version 4.0.0
199 199
 	 */
200
-	public function save_source( $order, $source ) {
201
-		parent::save_source( $order, $source );
200
+	public function save_source($order, $source) {
201
+		parent::save_source($order, $source);
202 202
 
203 203
 		$order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
204 204
 
205 205
 		// Also store it on the subscriptions being purchased or paid for in the order
206
-		if ( function_exists( 'wcs_order_contains_subscription' ) && wcs_order_contains_subscription( $order_id ) ) {
207
-			$subscriptions = wcs_get_subscriptions_for_order( $order_id );
208
-		} elseif ( function_exists( 'wcs_order_contains_renewal' ) && wcs_order_contains_renewal( $order_id ) ) {
209
-			$subscriptions = wcs_get_subscriptions_for_renewal_order( $order_id );
206
+		if (function_exists('wcs_order_contains_subscription') && wcs_order_contains_subscription($order_id)) {
207
+			$subscriptions = wcs_get_subscriptions_for_order($order_id);
208
+		} elseif (function_exists('wcs_order_contains_renewal') && wcs_order_contains_renewal($order_id)) {
209
+			$subscriptions = wcs_get_subscriptions_for_renewal_order($order_id);
210 210
 		} else {
211 211
 			$subscriptions = array();
212 212
 		}
213 213
 
214
-		foreach ( $subscriptions as $subscription ) {
214
+		foreach ($subscriptions as $subscription) {
215 215
 			$subscription_id = WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id();
216
-			update_post_meta( $subscription_id, '_stripe_customer_id', $source->customer );
217
-			update_post_meta( $subscription_id, '_stripe_source_id', $source->source );
216
+			update_post_meta($subscription_id, '_stripe_customer_id', $source->customer);
217
+			update_post_meta($subscription_id, '_stripe_source_id', $source->source);
218 218
 		}
219 219
 	}
220 220
 
@@ -225,37 +225,37 @@  discard block
 block discarded – undo
225 225
 	 * @param string $stripe_token (default: '')
226 226
 	 * @param  bool initial_payment
227 227
 	 */
228
-	public function process_subscription_payment( $order = '', $amount = 0 ) {
229
-		if ( $amount * 100 < WC_Stripe_Helper::get_minimum_amount() ) {
228
+	public function process_subscription_payment($order = '', $amount = 0) {
229
+		if ($amount * 100 < WC_Stripe_Helper::get_minimum_amount()) {
230 230
 			/* translators: minimum amount */
231
-			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 ) ) );
231
+			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)));
232 232
 		}
233 233
 
234 234
 		$customer_id = WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id();
235 235
 		$order_id    = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
236 236
 
237 237
 		// Get source from order
238
-		$prepared_source = $this->prepare_order_source( $order );
238
+		$prepared_source = $this->prepare_order_source($order);
239 239
 
240 240
 		// Or fail :(
241
-		if ( ! $prepared_source->customer ) {
242
-			return new WP_Error( 'stripe_error', __( 'Customer not found', 'woocommerce-gateway-stripe' ) );
241
+		if ( ! $prepared_source->customer) {
242
+			return new WP_Error('stripe_error', __('Customer not found', 'woocommerce-gateway-stripe'));
243 243
 		}
244 244
 
245
-		WC_Stripe_Logger::log( "Info: Begin processing subscription payment for order {$order_id} for the amount of {$amount}" );
245
+		WC_Stripe_Logger::log("Info: Begin processing subscription payment for order {$order_id} for the amount of {$amount}");
246 246
 
247 247
 		// Make the request
248
-		$request            = $this->generate_payment_request( $order, $prepared_source );
248
+		$request            = $this->generate_payment_request($order, $prepared_source);
249 249
 		$request['capture'] = 'true';
250
-		$request['amount']  = WC_Stripe_Helper::get_stripe_amount( $amount, $request['currency'] );
251
-		$response           = WC_Stripe_API::request( $request );
250
+		$request['amount']  = WC_Stripe_Helper::get_stripe_amount($amount, $request['currency']);
251
+		$response           = WC_Stripe_API::request($request);
252 252
 
253 253
 		// Process valid response
254
-		if ( ! empty( $response->error ) ) {
254
+		if ( ! empty($response->error)) {
255 255
 			return $response; // Default catch all errors.
256 256
 		}
257 257
 
258
-		$this->process_response( $response, $order );
258
+		$this->process_response($response, $order);
259 259
 
260 260
 		return $response;
261 261
 	}
@@ -270,61 +270,61 @@  discard block
 block discarded – undo
270 270
 	 * @param string $stripe_token (default: '')
271 271
 	 * @param  bool initial_payment
272 272
 	 */
273
-	public function retry_subscription_payment( $order = '', $amount = 0 ) {
274
-		if ( $amount * 100 < WC_Stripe_Helper::get_minimum_amount() ) {
273
+	public function retry_subscription_payment($order = '', $amount = 0) {
274
+		if ($amount * 100 < WC_Stripe_Helper::get_minimum_amount()) {
275 275
 			/* translators: minimum amount */
276
-			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 ) ) );
276
+			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)));
277 277
 		}
278 278
 
279 279
 		$customer_id = WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id();
280 280
 		$order_id    = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
281 281
 
282 282
 		// Get source from order
283
-		$prepared_source = $this->prepare_order_source( $order );
283
+		$prepared_source = $this->prepare_order_source($order);
284 284
 
285 285
 		// Or fail :(
286
-		if ( ! $prepared_source->customer ) {
287
-			return new WP_Error( 'stripe_error', __( 'Customer not found', 'woocommerce-gateway-stripe' ) );
286
+		if ( ! $prepared_source->customer) {
287
+			return new WP_Error('stripe_error', __('Customer not found', 'woocommerce-gateway-stripe'));
288 288
 		}
289 289
 
290 290
 		// Passing empty source with charge customer default.
291 291
 		$prepared_source->source = '';
292 292
 
293
-		WC_Stripe_Logger::log( "Info: Begin processing subscription payment for order {$order_id} for the amount of {$amount}" );
293
+		WC_Stripe_Logger::log("Info: Begin processing subscription payment for order {$order_id} for the amount of {$amount}");
294 294
 
295 295
 		// Make the request
296
-		$request             = $this->generate_payment_request( $order, $prepared_source );
296
+		$request             = $this->generate_payment_request($order, $prepared_source);
297 297
 		$request['capture']  = 'true';
298
-		$request['amount']   = WC_Stripe_Helper::get_stripe_amount( $amount, $request['currency'] );
299
-		$response            = WC_Stripe_API::request( $request );
298
+		$request['amount']   = WC_Stripe_Helper::get_stripe_amount($amount, $request['currency']);
299
+		$response            = WC_Stripe_API::request($request);
300 300
 
301
-		if ( ! empty( $response->error ) || is_wp_error( $response ) ) {
301
+		if ( ! empty($response->error) || is_wp_error($response)) {
302 302
 			/* translators: error message */
303
-			$renewal_order->update_status( 'failed', sprintf( __( 'Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe' ), $response->error->message ) );
303
+			$renewal_order->update_status('failed', sprintf(__('Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe'), $response->error->message));
304 304
 		}
305 305
 
306
-		$this->process_response( $response, $order );
306
+		$this->process_response($response, $order);
307 307
 	}
308 308
 
309 309
 	/**
310 310
 	 * Don't transfer Stripe customer/token meta to resubscribe orders.
311 311
 	 * @param int $resubscribe_order The order created for the customer to resubscribe to the old expired/cancelled subscription
312 312
 	 */
313
-	public function delete_resubscribe_meta( $resubscribe_order ) {
314
-		delete_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id() ), '_stripe_customer_id' );
315
-		delete_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id() ), '_stripe_source_id' );
313
+	public function delete_resubscribe_meta($resubscribe_order) {
314
+		delete_post_meta((WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id()), '_stripe_customer_id');
315
+		delete_post_meta((WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id()), '_stripe_source_id');
316 316
 		// For BW compat will remove in future
317
-		delete_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id() ), '_stripe_card_id' );
318
-		$this->delete_renewal_meta( $resubscribe_order );
317
+		delete_post_meta((WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id()), '_stripe_card_id');
318
+		$this->delete_renewal_meta($resubscribe_order);
319 319
 	}
320 320
 
321 321
 	/**
322 322
 	 * Don't transfer Stripe fee/ID meta to renewal orders.
323 323
 	 * @param int $resubscribe_order The order created for the customer to resubscribe to the old expired/cancelled subscription
324 324
 	 */
325
-	public function delete_renewal_meta( $renewal_order ) {
326
-		delete_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $renewal_order->id : $renewal_order->get_id() ), 'Stripe Fee' );
327
-		delete_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $renewal_order->id : $renewal_order->get_id() ), 'Net Revenue From Stripe' );
325
+	public function delete_renewal_meta($renewal_order) {
326
+		delete_post_meta((WC_Stripe_Helper::is_pre_30() ? $renewal_order->id : $renewal_order->get_id()), 'Stripe Fee');
327
+		delete_post_meta((WC_Stripe_Helper::is_pre_30() ? $renewal_order->id : $renewal_order->get_id()), 'Net Revenue From Stripe');
328 328
 		return $renewal_order;
329 329
 	}
330 330
 
@@ -334,21 +334,21 @@  discard block
 block discarded – undo
334 334
 	 * @param $amount_to_charge float The amount to charge.
335 335
 	 * @param $renewal_order WC_Order A WC_Order object created to record the renewal payment.
336 336
 	 */
337
-	public function scheduled_subscription_payment( $amount_to_charge, $renewal_order ) {
338
-		$response = $this->process_subscription_payment( $renewal_order, $amount_to_charge );
337
+	public function scheduled_subscription_payment($amount_to_charge, $renewal_order) {
338
+		$response = $this->process_subscription_payment($renewal_order, $amount_to_charge);
339 339
 
340
-		if ( is_wp_error( $response ) ) {
340
+		if (is_wp_error($response)) {
341 341
 			/* translators: error message */
342
-			$renewal_order->update_status( 'failed', sprintf( __( 'Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe' ), $response->get_error_message() ) );
342
+			$renewal_order->update_status('failed', sprintf(__('Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe'), $response->get_error_message()));
343 343
 		}
344 344
 
345
-		if ( ! empty( $response->error ) ) {
345
+		if ( ! empty($response->error)) {
346 346
 			// This is a very generic error to listen for but worth a retry before total fail.
347
-			if ( isset( $response->error->type ) && 'invalid_request_error' === $response->error->type && apply_filters( 'wc_stripe_use_default_customer_source', true ) ) {
348
-				$this->retry_subscription_payment( $renewal_order, $amount_to_charge );
347
+			if (isset($response->error->type) && 'invalid_request_error' === $response->error->type && apply_filters('wc_stripe_use_default_customer_source', true)) {
348
+				$this->retry_subscription_payment($renewal_order, $amount_to_charge);
349 349
 			} else {
350 350
 				/* translators: error message */
351
-				$renewal_order->update_status( 'failed', sprintf( __( 'Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe' ), $response->error->message ) );
351
+				$renewal_order->update_status('failed', sprintf(__('Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe'), $response->error->message));
352 352
 			}
353 353
 		}
354 354
 	}
@@ -357,20 +357,20 @@  discard block
 block discarded – undo
357 357
 	 * Remove order meta
358 358
 	 * @param  object $order
359 359
 	 */
360
-	public function remove_order_source_before_retry( $order ) {
360
+	public function remove_order_source_before_retry($order) {
361 361
 		$order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
362
-		delete_post_meta( $order_id, '_stripe_source_id' );
362
+		delete_post_meta($order_id, '_stripe_source_id');
363 363
 		// For BW compat will remove in the future.
364
-		delete_post_meta( $order_id, '_stripe_card_id' );
364
+		delete_post_meta($order_id, '_stripe_card_id');
365 365
 	}
366 366
 
367 367
 	/**
368 368
 	 * Remove order meta
369 369
 	 * @param  object $order
370 370
 	 */
371
-	public function remove_order_customer_before_retry( $order ) {
371
+	public function remove_order_customer_before_retry($order) {
372 372
 		$order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
373
-		delete_post_meta( $order_id, '_stripe_customer_id' );
373
+		delete_post_meta($order_id, '_stripe_customer_id');
374 374
 	}
375 375
 
376 376
 	/**
@@ -382,14 +382,14 @@  discard block
 block discarded – undo
382 382
 	 * @param WC_Order $renewal_order The order which recorded the successful payment (to make up for the failed automatic payment).
383 383
 	 * @return void
384 384
 	 */
385
-	public function update_failing_payment_method( $subscription, $renewal_order ) {
386
-		if ( WC_Stripe_Helper::is_pre_30() ) {
387
-			update_post_meta( $subscription->id, '_stripe_customer_id', $renewal_order->stripe_customer_id );
388
-			update_post_meta( $subscription->id, '_stripe_source_id', $renewal_order->stripe_source_id );
385
+	public function update_failing_payment_method($subscription, $renewal_order) {
386
+		if (WC_Stripe_Helper::is_pre_30()) {
387
+			update_post_meta($subscription->id, '_stripe_customer_id', $renewal_order->stripe_customer_id);
388
+			update_post_meta($subscription->id, '_stripe_source_id', $renewal_order->stripe_source_id);
389 389
 
390 390
 		} else {
391
-			update_post_meta( $subscription->get_id(), '_stripe_customer_id', $renewal_order->get_meta( '_stripe_customer_id', true ) );
392
-			update_post_meta( $subscription->get_id(), '_stripe_source_id', $renewal_order->get_meta( '_stripe_source_id', true ) );
391
+			update_post_meta($subscription->get_id(), '_stripe_customer_id', $renewal_order->get_meta('_stripe_customer_id', true));
392
+			update_post_meta($subscription->get_id(), '_stripe_source_id', $renewal_order->get_meta('_stripe_source_id', true));
393 393
 		}
394 394
 	}
395 395
 
@@ -402,21 +402,21 @@  discard block
 block discarded – undo
402 402
 	 * @param WC_Subscription $subscription An instance of a subscription object
403 403
 	 * @return array
404 404
 	 */
405
-	public function add_subscription_payment_meta( $payment_meta, $subscription ) {
406
-		$source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_source_id', true );
405
+	public function add_subscription_payment_meta($payment_meta, $subscription) {
406
+		$source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_source_id', true);
407 407
 
408 408
 		// For BW compat will remove in future.
409
-		if ( empty( $source_id ) ) {
410
-			$source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_card_id', true );
409
+		if (empty($source_id)) {
410
+			$source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_card_id', true);
411 411
 
412 412
 			// Take this opportunity to update the key name.
413
-			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 );
413
+			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);
414 414
 		}
415 415
 
416
-		$payment_meta[ $this->id ] = array(
416
+		$payment_meta[$this->id] = array(
417 417
 			'post_meta' => array(
418 418
 				'_stripe_customer_id' => array(
419
-					'value' => get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_customer_id', true ),
419
+					'value' => get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_customer_id', true),
420 420
 					'label' => 'Stripe Customer ID',
421 421
 				),
422 422
 				'_stripe_source_id' => array(
@@ -439,22 +439,22 @@  discard block
 block discarded – undo
439 439
 	 * @param array $payment_meta associative array of meta data required for automatic payments
440 440
 	 * @return array
441 441
 	 */
442
-	public function validate_subscription_payment_meta( $payment_method_id, $payment_meta ) {
443
-		if ( $this->id === $payment_method_id ) {
442
+	public function validate_subscription_payment_meta($payment_method_id, $payment_meta) {
443
+		if ($this->id === $payment_method_id) {
444 444
 
445
-			if ( ! isset( $payment_meta['post_meta']['_stripe_customer_id']['value'] ) || empty( $payment_meta['post_meta']['_stripe_customer_id']['value'] ) ) {
446
-				throw new Exception( __( 'A "Stripe Customer ID" value is required.', 'woocommerce-gateway-stripe' ) );
447
-			} elseif ( 0 !== strpos( $payment_meta['post_meta']['_stripe_customer_id']['value'], 'cus_' ) ) {
448
-				throw new Exception( __( 'Invalid customer ID. A valid "Stripe Customer ID" must begin with "cus_".', 'woocommerce-gateway-stripe' ) );
445
+			if ( ! isset($payment_meta['post_meta']['_stripe_customer_id']['value']) || empty($payment_meta['post_meta']['_stripe_customer_id']['value'])) {
446
+				throw new Exception(__('A "Stripe Customer ID" value is required.', 'woocommerce-gateway-stripe'));
447
+			} elseif (0 !== strpos($payment_meta['post_meta']['_stripe_customer_id']['value'], 'cus_')) {
448
+				throw new Exception(__('Invalid customer ID. A valid "Stripe Customer ID" must begin with "cus_".', 'woocommerce-gateway-stripe'));
449 449
 			}
450 450
 
451 451
 			if (
452
-				( ! empty( $payment_meta['post_meta']['_stripe_source_id']['value'] )
453
-				&& 0 !== strpos( $payment_meta['post_meta']['_stripe_source_id']['value'], 'card_' ) )
454
-				&& ( ! empty( $payment_meta['post_meta']['_stripe_source_id']['value'] )
455
-				&& 0 !== strpos( $payment_meta['post_meta']['_stripe_source_id']['value'], 'src_' ) ) ) {
452
+				( ! empty($payment_meta['post_meta']['_stripe_source_id']['value'])
453
+				&& 0 !== strpos($payment_meta['post_meta']['_stripe_source_id']['value'], 'card_'))
454
+				&& ( ! empty($payment_meta['post_meta']['_stripe_source_id']['value'])
455
+				&& 0 !== strpos($payment_meta['post_meta']['_stripe_source_id']['value'], 'src_')) ) {
456 456
 
457
-				throw new Exception( __( 'Invalid source ID. A valid source "Stripe Source ID" must begin with "src_" or "card_".', 'woocommerce-gateway-stripe' ) );
457
+				throw new Exception(__('Invalid source ID. A valid source "Stripe Source ID" must begin with "src_" or "card_".', 'woocommerce-gateway-stripe'));
458 458
 			}
459 459
 		}
460 460
 	}
@@ -467,91 +467,91 @@  discard block
 block discarded – undo
467 467
 	 * @param WC_Subscription $subscription the subscription details
468 468
 	 * @return string the subscription payment method
469 469
 	 */
470
-	public function maybe_render_subscription_payment_method( $payment_method_to_display, $subscription ) {
470
+	public function maybe_render_subscription_payment_method($payment_method_to_display, $subscription) {
471 471
 		$customer_user = WC_Stripe_Helper::is_pre_30() ? $subscription->customer_user : $subscription->get_customer_id();
472 472
 
473 473
 		// bail for other payment methods
474
-		if ( ( WC_Stripe_Helper::is_pre_30() ? $subscription->payment_method : $subscription->get_payment_method() ) !== $this->id || ! $customer_user ) {
474
+		if ((WC_Stripe_Helper::is_pre_30() ? $subscription->payment_method : $subscription->get_payment_method()) !== $this->id || ! $customer_user) {
475 475
 			return $payment_method_to_display;
476 476
 		}
477 477
 
478
-		$stripe_source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_source_id', true );
478
+		$stripe_source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_source_id', true);
479 479
 
480 480
 		// For BW compat will remove in future.
481
-		if ( empty( $stripe_source_id ) ) {
482
-			$stripe_source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_card_id', true );
481
+		if (empty($stripe_source_id)) {
482
+			$stripe_source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_card_id', true);
483 483
 
484 484
 			// Take this opportunity to update the key name.
485
-			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 );
485
+			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);
486 486
 		}
487 487
 
488 488
 		$stripe_customer    = new WC_Stripe_Customer();
489
-		$stripe_customer_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_customer_id', true );
489
+		$stripe_customer_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_customer_id', true);
490 490
 
491 491
 		// If we couldn't find a Stripe customer linked to the subscription, fallback to the user meta data.
492
-		if ( ! $stripe_customer_id || ! is_string( $stripe_customer_id ) ) {
492
+		if ( ! $stripe_customer_id || ! is_string($stripe_customer_id)) {
493 493
 			$user_id            = $customer_user;
494
-			$stripe_customer_id = get_user_meta( $user_id, '_stripe_customer_id', true );
495
-			$stripe_source_id   = get_user_meta( $user_id, '_stripe_source_id', true );
494
+			$stripe_customer_id = get_user_meta($user_id, '_stripe_customer_id', true);
495
+			$stripe_source_id   = get_user_meta($user_id, '_stripe_source_id', true);
496 496
 
497 497
 			// For BW compat will remove in future.
498
-			if ( empty( $stripe_source_id ) ) {
499
-				$stripe_source_id = get_user_meta( $user_id, '_stripe_card_id', true );
498
+			if (empty($stripe_source_id)) {
499
+				$stripe_source_id = get_user_meta($user_id, '_stripe_card_id', true);
500 500
 
501 501
 				// Take this opportunity to update the key name.
502
-				update_user_meta( $user_id, '_stripe_source_id', $stripe_source_id );
502
+				update_user_meta($user_id, '_stripe_source_id', $stripe_source_id);
503 503
 			}
504 504
 		}
505 505
 
506 506
 		// If we couldn't find a Stripe customer linked to the account, fallback to the order meta data.
507
-		if ( ( ! $stripe_customer_id || ! is_string( $stripe_customer_id ) ) && false !== $subscription->order ) {
508
-			$stripe_customer_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id() ), '_stripe_customer_id', true );
509
-			$stripe_source_id   = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id() ), '_stripe_source_id', true );
507
+		if (( ! $stripe_customer_id || ! is_string($stripe_customer_id)) && false !== $subscription->order) {
508
+			$stripe_customer_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id()), '_stripe_customer_id', true);
509
+			$stripe_source_id   = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id()), '_stripe_source_id', true);
510 510
 
511 511
 			// For BW compat will remove in future.
512
-			if ( empty( $stripe_source_id ) ) {
513
-				$stripe_source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id() ), '_stripe_card_id', true );
512
+			if (empty($stripe_source_id)) {
513
+				$stripe_source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id()), '_stripe_card_id', true);
514 514
 
515 515
 				// Take this opportunity to update the key name.
516
-				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 );
516
+				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);
517 517
 			}
518 518
 		}
519 519
 
520
-		$stripe_customer->set_id( $stripe_customer_id );
520
+		$stripe_customer->set_id($stripe_customer_id);
521 521
 		$sources = $stripe_customer->get_sources();
522 522
 
523
-		if ( $sources ) {
523
+		if ($sources) {
524 524
 			$found_source = false;
525
-			foreach ( $sources as $source ) {
526
-				if ( isset( $source->type ) && 'card' === $source->type ) {
525
+			foreach ($sources as $source) {
526
+				if (isset($source->type) && 'card' === $source->type) {
527 527
 					$card = $source->card;
528
-				} elseif ( isset( $source->object ) && 'card' === $source->object ) {
528
+				} elseif (isset($source->object) && 'card' === $source->object) {
529 529
 					$card = $source;
530 530
 				}
531 531
 
532
-				if ( $source->id === $stripe_source_id ) {
532
+				if ($source->id === $stripe_source_id) {
533 533
 					$found_source = true;
534 534
 
535
-					if ( $card ) {
535
+					if ($card) {
536 536
 						/* translators: 1) card brand 2) last 4 digits */
537
-						$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 );
537
+						$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);
538 538
 					} else {
539
-						$payment_method_to_display = __( 'N/A', 'woocommerce-gateway-stripe' );
539
+						$payment_method_to_display = __('N/A', 'woocommerce-gateway-stripe');
540 540
 					}
541 541
 					break;
542 542
 				}
543 543
 			}
544 544
 
545
-			if ( ! $found_source ) {
546
-				if ( 'card' === $sources[0]->type ) {
545
+			if ( ! $found_source) {
546
+				if ('card' === $sources[0]->type) {
547 547
 					$card = $sources[0]->card;
548 548
 				}
549 549
 
550
-				if ( $card ) {
550
+				if ($card) {
551 551
 					/* translators: 1) card brand 2) last 4 digits */
552
-					$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 );
552
+					$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);
553 553
 				} else {
554
-					$payment_method_to_display = __( 'N/A', 'woocommerce-gateway-stripe' );
554
+					$payment_method_to_display = __('N/A', 'woocommerce-gateway-stripe');
555 555
 				}
556 556
 			}
557 557
 		}
@@ -564,43 +564,43 @@  discard block
 block discarded – undo
564 564
 	 * @param int $order_id
565 565
 	 * @return array
566 566
 	 */
567
-	public function process_pre_order( $order_id, $retry, $force_save_source ) {
568
-		if ( WC_Pre_Orders_Order::order_requires_payment_tokenization( $order_id ) ) {
567
+	public function process_pre_order($order_id, $retry, $force_save_source) {
568
+		if (WC_Pre_Orders_Order::order_requires_payment_tokenization($order_id)) {
569 569
 			try {
570
-				$order = wc_get_order( $order_id );
570
+				$order = wc_get_order($order_id);
571 571
 
572
-				if ( $order->get_total() * 100 < WC_Stripe_Helper::get_minimum_amount() ) {
572
+				if ($order->get_total() * 100 < WC_Stripe_Helper::get_minimum_amount()) {
573 573
 					/* translators: minimum amount */
574
-					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 ) ) );
574
+					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)));
575 575
 				}
576 576
 
577
-				$source = $this->prepare_source( $this->get_source_object(), get_current_user_id(), true );
577
+				$source = $this->prepare_source($this->get_source_object(), get_current_user_id(), true);
578 578
 
579 579
 				// We need a source on file to continue.
580
-				if ( empty( $source->customer ) || empty( $source->source ) ) {
581
-					throw new Exception( __( 'Unable to store payment details. Please try again.', 'woocommerce-gateway-stripe' ) );
580
+				if (empty($source->customer) || empty($source->source)) {
581
+					throw new Exception(__('Unable to store payment details. Please try again.', 'woocommerce-gateway-stripe'));
582 582
 				}
583 583
 
584 584
 				// Store source to order meta
585
-				$this->save_source( $order, $source );
585
+				$this->save_source($order, $source);
586 586
 
587 587
 				// Remove cart
588 588
 				WC()->cart->empty_cart();
589 589
 
590 590
 				// Is pre ordered!
591
-				WC_Pre_Orders_Order::mark_order_as_pre_ordered( $order );
591
+				WC_Pre_Orders_Order::mark_order_as_pre_ordered($order);
592 592
 
593 593
 				// Return thank you page redirect
594 594
 				return array(
595 595
 					'result'   => 'success',
596
-					'redirect' => $this->get_return_url( $order ),
596
+					'redirect' => $this->get_return_url($order),
597 597
 				);
598
-			} catch ( Exception $e ) {
599
-				wc_add_notice( $e->getMessage(), 'error' );
598
+			} catch (Exception $e) {
599
+				wc_add_notice($e->getMessage(), 'error');
600 600
 				return;
601 601
 			}
602 602
 		} else {
603
-			return parent::process_payment( $order_id, $retry, $force_save_source );
603
+			return parent::process_payment($order_id, $retry, $force_save_source);
604 604
 		}
605 605
 	}
606 606
 
@@ -609,7 +609,7 @@  discard block
 block discarded – undo
609 609
 	 * @param WC_Order $order
610 610
 	 * @return void
611 611
 	 */
612
-	public function process_pre_order_release_payment( $order ) {
612
+	public function process_pre_order_release_payment($order) {
613 613
 		try {
614 614
 			// Define some callbacks if the first attempt fails.
615 615
 			$retry_callbacks = array(
@@ -617,33 +617,33 @@  discard block
 block discarded – undo
617 617
 				'remove_order_customer_before_retry',
618 618
 			);
619 619
 
620
-			while ( 1 ) {
621
-				$source   = $this->prepare_order_source( $order );
622
-				$response = WC_Stripe_API::request( $this->generate_payment_request( $order, $source ) );
620
+			while (1) {
621
+				$source   = $this->prepare_order_source($order);
622
+				$response = WC_Stripe_API::request($this->generate_payment_request($order, $source));
623 623
 
624
-				if ( ! empty( $response->error ) ) {
625
-					if ( 0 === sizeof( $retry_callbacks ) ) {
626
-						throw new Exception( $response->error->message );
624
+				if ( ! empty($response->error)) {
625
+					if (0 === sizeof($retry_callbacks)) {
626
+						throw new Exception($response->error->message);
627 627
 					} else {
628
-						$retry_callback = array_shift( $retry_callbacks );
629
-						call_user_func( array( $this, $retry_callback ), $order );
628
+						$retry_callback = array_shift($retry_callbacks);
629
+						call_user_func(array($this, $retry_callback), $order);
630 630
 					}
631 631
 				} else {
632 632
 					// Successful
633
-					$this->process_response( $response, $order );
633
+					$this->process_response($response, $order);
634 634
 					break;
635 635
 				}
636 636
 			}
637
-		} catch ( Exception $e ) {
637
+		} catch (Exception $e) {
638 638
 			/* translators: error message */
639
-			$order_note = sprintf( __( 'Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe' ), $e->getMessage() );
639
+			$order_note = sprintf(__('Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe'), $e->getMessage());
640 640
 
641 641
 			// Mark order as failed if not already set,
642 642
 			// otherwise, make sure we add the order note so we can detect when someone fails to check out multiple times
643
-			if ( ! $order->has_status( 'failed' ) ) {
644
-				$order->update_status( 'failed', $order_note );
643
+			if ( ! $order->has_status('failed')) {
644
+				$order->update_status('failed', $order_note);
645 645
 			} else {
646
-				$order->add_order_note( $order_note );
646
+				$order->add_order_note($order_note);
647 647
 			}
648 648
 		}
649 649
 	}
Please login to merge, or discard this patch.
includes/class-wc-stripe-order-handler.php 1 patch
Spacing   +172 added lines, -172 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,108 +72,108 @@  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
 			/**
80 80
 			 * First check if the source is chargeable at this time. If not,
81 81
 			 * webhook will take care of it later.
82 82
 			 */
83
-			$source_info = WC_Stripe_API::retrieve( 'sources/' . $source );
83
+			$source_info = WC_Stripe_API::retrieve('sources/' . $source);
84 84
 
85
-			if ( ! empty( $source_info->error ) ) {
86
-				throw new WC_Stripe_Exception( print_r( $source_info, true ), $source_info->error->message );
85
+			if ( ! empty($source_info->error)) {
86
+				throw new WC_Stripe_Exception(print_r($source_info, true), $source_info->error->message);
87 87
 			}
88 88
 
89
-			if ( 'failed' === $source_info->status || 'canceled' === $source_info->status ) {
90
-				throw new WC_Stripe_Exception( print_r( $source_info, true ), __( 'Unable to process this payment, please try again or use alternative method.', 'woocommerce-gateway-stripe' ) );
89
+			if ('failed' === $source_info->status || 'canceled' === $source_info->status) {
90
+				throw new WC_Stripe_Exception(print_r($source_info, true), __('Unable to process this payment, please try again or use alternative method.', 'woocommerce-gateway-stripe'));
91 91
 			}
92 92
 
93 93
 			// If already consumed, then ignore request.
94
-			if ( 'consumed' === $source_info->status ) {
94
+			if ('consumed' === $source_info->status) {
95 95
 				return;
96 96
 			}
97 97
 
98 98
 			// If not chargeable, then ignore request.
99
-			if ( 'chargeable' !== $source_info->status ) {
99
+			if ('chargeable' !== $source_info->status) {
100 100
 				return;
101 101
 			}
102 102
 
103 103
 			// Prep source object.
104 104
 			$source_object           = new stdClass();
105 105
 			$source_object->token_id = '';
106
-			$source_object->customer = $this->get_stripe_customer_id( $order );
106
+			$source_object->customer = $this->get_stripe_customer_id($order);
107 107
 			$source_object->source   = $source_info->id;
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 WC_Stripe_Exception( print_r( $response, true ), $message );
120
+						$order->add_order_note($message);
121
+						throw new WC_Stripe_Exception(print_r($response, true), $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
-					if ( WC_Stripe_Helper::is_pre_30() ) {
128
-						delete_user_meta( $order->customer_user, '_stripe_customer_id' );
129
-						delete_post_meta( $order_id, '_stripe_customer_id' );
126
+				if (preg_match('/No such customer/i', $response->error->message) && $retry) {
127
+					if (WC_Stripe_Helper::is_pre_30()) {
128
+						delete_user_meta($order->customer_user, '_stripe_customer_id');
129
+						delete_post_meta($order_id, '_stripe_customer_id');
130 130
 					} else {
131
-						delete_user_meta( $order->get_customer_id(), '_stripe_customer_id' );
132
-						$order->delete_meta_data( '_stripe_customer_id' );
131
+						delete_user_meta($order->get_customer_id(), '_stripe_customer_id');
132
+						$order->delete_meta_data('_stripe_customer_id');
133 133
 						$order->save();
134 134
 					}
135 135
 
136
-					return $this->process_redirect_payment( $order_id, false );
136
+					return $this->process_redirect_payment($order_id, false);
137 137
 
138
-				} elseif ( preg_match( '/No such token/i', $response->error->message ) && $source_object->token_id ) {
138
+				} elseif (preg_match('/No such token/i', $response->error->message) && $source_object->token_id) {
139 139
 					// Source param wrong? The CARD may have been deleted on stripe's end. Remove token and show message.
140 140
 
141
-					$wc_token = WC_Payment_Tokens::get( $source_object->token_id );
141
+					$wc_token = WC_Payment_Tokens::get($source_object->token_id);
142 142
 					$wc_token->delete();
143
-					$message = __( 'This card is no longer available and has been removed.', 'woocommerce-gateway-stripe' );
144
-					$order->add_order_note( $message );
145
-					throw new WC_Stripe_Exception( print_r( $response, true ), $message );
143
+					$message = __('This card is no longer available and has been removed.', 'woocommerce-gateway-stripe');
144
+					$order->add_order_note($message);
145
+					throw new WC_Stripe_Exception(print_r($response, true), $message);
146 146
 				}
147 147
 
148 148
 				$localized_messages = WC_Stripe_Helper::get_localized_messages();
149 149
 
150
-				if ( 'card_error' === $response->error->type ) {
151
-					$message = isset( $localized_messages[ $response->error->code ] ) ? $localized_messages[ $response->error->code ] : $response->error->message;
150
+				if ('card_error' === $response->error->type) {
151
+					$message = isset($localized_messages[$response->error->code]) ? $localized_messages[$response->error->code] : $response->error->message;
152 152
 				} else {
153
-					$message = isset( $localized_messages[ $response->error->type ] ) ? $localized_messages[ $response->error->type ] : $response->error->message;
153
+					$message = isset($localized_messages[$response->error->type]) ? $localized_messages[$response->error->type] : $response->error->message;
154 154
 				}
155 155
 
156
-				throw new WC_Stripe_Exception( print_r( $response, true ), $message );
156
+				throw new WC_Stripe_Exception(print_r($response, true), $message);
157 157
 			}
158 158
 
159
-			do_action( 'wc_gateway_stripe_process_redirect_payment', $response, $order );
159
+			do_action('wc_gateway_stripe_process_redirect_payment', $response, $order);
160 160
 
161
-			$this->process_response( $response, $order );
161
+			$this->process_response($response, $order);
162 162
 
163
-		} catch ( WC_Stripe_Exception $e ) {
164
-			WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() );
163
+		} catch (WC_Stripe_Exception $e) {
164
+			WC_Stripe_Logger::log('Error: ' . $e->getMessage());
165 165
 
166
-			do_action( 'wc_gateway_stripe_process_redirect_payment_error', $e, $order );
166
+			do_action('wc_gateway_stripe_process_redirect_payment_error', $e, $order);
167 167
 
168 168
 			/* translators: error message */
169
-			$order->update_status( 'failed', sprintf( __( 'Stripe payment failed: %s', 'woocommerce-gateway-stripe' ), $e->getLocalizedMessage() ) );
169
+			$order->update_status('failed', sprintf(__('Stripe payment failed: %s', 'woocommerce-gateway-stripe'), $e->getLocalizedMessage()));
170 170
 
171
-			if ( $order->has_status( array( 'pending', 'failed' ) ) ) {
172
-				$this->send_failed_order_email( $order_id );
171
+			if ($order->has_status(array('pending', 'failed'))) {
172
+				$this->send_failed_order_email($order_id);
173 173
 			}
174 174
 
175
-			wc_add_notice( $e->getLocalizedMessage(), 'error' );
176
-			wp_safe_redirect( wc_get_checkout_url() );
175
+			wc_add_notice($e->getLocalizedMessage(), 'error');
176
+			wp_safe_redirect(wc_get_checkout_url());
177 177
 			exit;
178 178
 		}
179 179
 	}
@@ -185,13 +185,13 @@  discard block
 block discarded – undo
185 185
 	 * @version 4.0.0
186 186
 	 */
187 187
 	public function maybe_process_redirect_order() {
188
-		if ( ! is_order_received_page() || empty( $_GET['client_secret'] ) || empty( $_GET['source'] ) ) {
188
+		if ( ! is_order_received_page() || empty($_GET['client_secret']) || empty($_GET['source'])) {
189 189
 			return;
190 190
 		}
191 191
 
192
-		$order_id = wc_clean( $_GET['order_id'] );
192
+		$order_id = wc_clean($_GET['order_id']);
193 193
 
194
-		$this->process_redirect_payment( $order_id );
194
+		$this->process_redirect_payment($order_id);
195 195
 	}
196 196
 
197 197
 	/**
@@ -201,52 +201,52 @@  discard block
 block discarded – undo
201 201
 	 * @version 4.0.0
202 202
 	 * @param  int $order_id
203 203
 	 */
204
-	public function capture_payment( $order_id ) {
205
-		$order = wc_get_order( $order_id );
204
+	public function capture_payment($order_id) {
205
+		$order = wc_get_order($order_id);
206 206
 
207
-		if ( 'stripe' === ( WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method() ) ) {
208
-			$charge   = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_transaction_id', true ) : $order->get_transaction_id();
209
-			$captured = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_stripe_charge_captured', true ) : $order->get_meta( '_stripe_charge_captured', true );
207
+		if ('stripe' === (WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method())) {
208
+			$charge   = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_transaction_id', true) : $order->get_transaction_id();
209
+			$captured = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_stripe_charge_captured', true) : $order->get_meta('_stripe_charge_captured', true);
210 210
 
211
-			if ( $charge && 'no' === $captured ) {
211
+			if ($charge && 'no' === $captured) {
212 212
 				$order_total = $order->get_total();
213 213
 
214
-				if ( 0 < $order->get_total_refunded() ) {
214
+				if (0 < $order->get_total_refunded()) {
215 215
 					$order_total = $order_total - $order->get_total_refunded();
216 216
 				}
217 217
 
218
-				$result = WC_Stripe_API::request( array(
219
-					'amount'   => WC_Stripe_Helper::get_stripe_amount( $order_total ),
218
+				$result = WC_Stripe_API::request(array(
219
+					'amount'   => WC_Stripe_Helper::get_stripe_amount($order_total),
220 220
 					'expand[]' => 'balance_transaction',
221
-				), 'charges/' . $charge . '/capture' );
221
+				), 'charges/' . $charge . '/capture');
222 222
 
223
-				if ( ! empty( $result->error ) ) {
223
+				if ( ! empty($result->error)) {
224 224
 					/* translators: error message */
225
-					$order->update_status( 'failed', sprintf( __( 'Unable to capture charge! %s', 'woocommerce-gateway-stripe' ), $result->error->message ) );
225
+					$order->update_status('failed', sprintf(__('Unable to capture charge! %s', 'woocommerce-gateway-stripe'), $result->error->message));
226 226
 				} else {
227 227
 					/* translators: transaction id */
228
-					$order->add_order_note( sprintf( __( 'Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe' ), $result->id ) );
229
-					WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, '_stripe_charge_captured', 'yes' ) : $order->update_meta_data( '_stripe_charge_captured', 'yes' );
228
+					$order->add_order_note(sprintf(__('Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe'), $result->id));
229
+					WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, '_stripe_charge_captured', 'yes') : $order->update_meta_data('_stripe_charge_captured', 'yes');
230 230
 
231 231
 					// Store other data such as fees
232
-					WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, '_transaction_id', $result->id ) : $order->set_transaction_id( $result->id );
232
+					WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, '_transaction_id', $result->id) : $order->set_transaction_id($result->id);
233 233
 
234
-					if ( isset( $result->balance_transaction ) && isset( $result->balance_transaction->fee ) ) {
234
+					if (isset($result->balance_transaction) && isset($result->balance_transaction->fee)) {
235 235
 						// Fees and Net needs to both come from Stripe to be accurate as the returned
236 236
 						// values are in the local currency of the Stripe account, not from WC.
237
-						$fee = ! empty( $result->balance_transaction->fee ) ? WC_Stripe_Helper::format_balance_fee( $result->balance_transaction, 'fee' ) : 0;
238
-						$net = ! empty( $result->balance_transaction->net ) ? WC_Stripe_Helper::format_balance_fee( $result->balance_transaction, 'net' ) : 0;
239
-						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 );
240
-						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 );
237
+						$fee = ! empty($result->balance_transaction->fee) ? WC_Stripe_Helper::format_balance_fee($result->balance_transaction, 'fee') : 0;
238
+						$net = ! empty($result->balance_transaction->net) ? WC_Stripe_Helper::format_balance_fee($result->balance_transaction, 'net') : 0;
239
+						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);
240
+						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);
241 241
 					}
242 242
 
243
-					if ( is_callable( array( $order, 'save' ) ) ) {
243
+					if (is_callable(array($order, 'save'))) {
244 244
 						$order->save();
245 245
 					}
246 246
 				}
247 247
 
248 248
 				// This hook fires when admin manually changes order status to processing or completed.
249
-				do_action( 'woocommerce_stripe_process_manual_capture', $order, $result );
249
+				do_action('woocommerce_stripe_process_manual_capture', $order, $result);
250 250
 			}
251 251
 		}
252 252
 	}
@@ -258,32 +258,32 @@  discard block
 block discarded – undo
258 258
 	 * @version 4.0.0
259 259
 	 * @param  int $order_id
260 260
 	 */
261
-	public function cancel_payment( $order_id ) {
262
-		$order = wc_get_order( $order_id );
261
+	public function cancel_payment($order_id) {
262
+		$order = wc_get_order($order_id);
263 263
 
264
-		if ( 'stripe' === ( WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method() ) ) {
265
-			$charge_id = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_transaction_id', true ) : $order->get_transaction_id();
264
+		if ('stripe' === (WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method())) {
265
+			$charge_id = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_transaction_id', true) : $order->get_transaction_id();
266 266
 
267
-			if ( $charge_id ) {
268
-				$result = WC_Stripe_API::request( array(
269
-					'amount' => WC_Stripe_Helper::get_stripe_amount( $order->get_total() ),
270
-				), 'charges/' . $charge_id . '/refund' );
267
+			if ($charge_id) {
268
+				$result = WC_Stripe_API::request(array(
269
+					'amount' => WC_Stripe_Helper::get_stripe_amount($order->get_total()),
270
+				), 'charges/' . $charge_id . '/refund');
271 271
 
272
-				if ( ! empty( $result->error ) ) {
273
-					$order->add_order_note( __( 'Unable to refund charge!', 'woocommerce-gateway-stripe' ) . ' ' . $result->error->message );
272
+				if ( ! empty($result->error)) {
273
+					$order->add_order_note(__('Unable to refund charge!', 'woocommerce-gateway-stripe') . ' ' . $result->error->message);
274 274
 				} else {
275 275
 					/* translators: transaction id */
276
-					$order->add_order_note( sprintf( __( 'Stripe charge refunded (Charge ID: %s)', 'woocommerce-gateway-stripe' ), $result->id ) );
277
-					WC_Stripe_Helper::is_pre_30() ? delete_post_meta( $order_id, '_stripe_charge_captured' ) : $order->delete_meta_data( '_stripe_charge_captured' );
278
-					WC_Stripe_Helper::is_pre_30() ? delete_post_meta( $order_id, '_transaction_id' ) : $order->delete_meta_data( '_stripe_transaction_id' );
276
+					$order->add_order_note(sprintf(__('Stripe charge refunded (Charge ID: %s)', 'woocommerce-gateway-stripe'), $result->id));
277
+					WC_Stripe_Helper::is_pre_30() ? delete_post_meta($order_id, '_stripe_charge_captured') : $order->delete_meta_data('_stripe_charge_captured');
278
+					WC_Stripe_Helper::is_pre_30() ? delete_post_meta($order_id, '_transaction_id') : $order->delete_meta_data('_stripe_transaction_id');
279 279
 
280
-					if ( is_callable( array( $order, 'save' ) ) ) {
280
+					if (is_callable(array($order, 'save'))) {
281 281
 						$order->save();
282 282
 					}
283 283
 				}
284 284
 
285 285
 				// This hook fires when admin manually changes order status to cancel.
286
-				do_action( 'woocommerce_stripe_process_manual_cancel', $order, $result );
286
+				do_action('woocommerce_stripe_process_manual_cancel', $order, $result);
287 287
 			}
288 288
 		}
289 289
 	}
@@ -296,21 +296,21 @@  discard block
 block discarded – undo
296 296
 	 * @param string $field
297 297
 	 * @return string $error_field
298 298
 	 */
299
-	public function normalize_field( $field ) {
299
+	public function normalize_field($field) {
300 300
 		$checkout_fields = WC()->checkout->get_checkout_fields();
301 301
 		$org_str         = array();
302 302
 		$replace_str     = array();
303 303
 
304
-		if ( array_key_exists( $field, $checkout_fields['billing'] ) ) {
305
-			$error_field = __( 'Billing', 'woocommerce-gateway-stripe' ) . ' ' . $checkout_fields['billing'][ $field ]['label'];
306
-		} elseif ( array_key_exists( $field, $checkout_fields['shipping'] ) ) {
307
-			$error_field = __( 'Shipping', 'woocommerce-gateway-stripe' ) . ' ' . $checkout_fields['shipping'][ $field ]['label'];
308
-		} elseif ( array_key_exists( $field, $checkout_fields['order'] ) ) {
309
-			$error_field = $checkout_fields['order'][ $field ]['label'];
310
-		} elseif ( array_key_exists( $field, $checkout_fields['account'] ) ) {
311
-			$error_field = $checkout_fields['account'][ $field ]['label'];
304
+		if (array_key_exists($field, $checkout_fields['billing'])) {
305
+			$error_field = __('Billing', 'woocommerce-gateway-stripe') . ' ' . $checkout_fields['billing'][$field]['label'];
306
+		} elseif (array_key_exists($field, $checkout_fields['shipping'])) {
307
+			$error_field = __('Shipping', 'woocommerce-gateway-stripe') . ' ' . $checkout_fields['shipping'][$field]['label'];
308
+		} elseif (array_key_exists($field, $checkout_fields['order'])) {
309
+			$error_field = $checkout_fields['order'][$field]['label'];
310
+		} elseif (array_key_exists($field, $checkout_fields['account'])) {
311
+			$error_field = $checkout_fields['account'][$field]['label'];
312 312
 		} else {
313
-			$error_field = str_replace( '_', ' ', $field );
313
+			$error_field = str_replace('_', ' ', $field);
314 314
 
315 315
 			$org_str[]     = 'stripe';
316 316
 			$replace_str[] = '';
@@ -325,9 +325,9 @@  discard block
 block discarded – undo
325 325
 			$replace_str[] = 'SOFORT';
326 326
 
327 327
 			$org_str[]     = 'owner';
328
-			$replace_str[] = __( 'Owner', 'woocommerce-gateway-stripe' );
328
+			$replace_str[] = __('Owner', 'woocommerce-gateway-stripe');
329 329
 
330
-			$error_field   = str_replace( $org_str, $replace_str, $error_field );
330
+			$error_field   = str_replace($org_str, $replace_str, $error_field);
331 331
 		}
332 332
 
333 333
 		return $error_field;
@@ -340,138 +340,138 @@  discard block
 block discarded – undo
340 340
 	 * @version 4.0.0
341 341
 	 */
342 342
 	public function validate_checkout() {
343
-		if ( ! wp_verify_nonce( $_POST['nonce'], '_wc_stripe_nonce' ) ) {
344
-			wp_die( __( 'Cheatin&#8217; huh?', 'woocommerce-gateway-stripe' ) );
343
+		if ( ! wp_verify_nonce($_POST['nonce'], '_wc_stripe_nonce')) {
344
+			wp_die(__('Cheatin&#8217; huh?', 'woocommerce-gateway-stripe'));
345 345
 		}
346 346
 
347 347
 		$errors = new WP_Error();
348
-		parse_str( $_POST['required_fields'], $required_fields );
349
-		parse_str( $_POST['all_fields'], $all_fields );
350
-		$source_type = isset( $_POST['source_type'] ) ? wc_clean( $_POST['source_type'] ) : '';
348
+		parse_str($_POST['required_fields'], $required_fields);
349
+		parse_str($_POST['all_fields'], $all_fields);
350
+		$source_type = isset($_POST['source_type']) ? wc_clean($_POST['source_type']) : '';
351 351
 		$validate_shipping_fields = false;
352 352
 		$create_account = false;
353 353
 
354
-		$all_fields      = apply_filters( 'wc_stripe_validate_checkout_all_fields', $all_fields );
355
-		$required_fields = apply_filters( 'wc_stripe_validate_checkout_required_fields', $required_fields );
354
+		$all_fields      = apply_filters('wc_stripe_validate_checkout_all_fields', $all_fields);
355
+		$required_fields = apply_filters('wc_stripe_validate_checkout_required_fields', $required_fields);
356 356
 
357
-		array_walk_recursive( $required_fields, 'wc_clean' );
358
-		array_walk_recursive( $all_fields, 'wc_clean' );
357
+		array_walk_recursive($required_fields, 'wc_clean');
358
+		array_walk_recursive($all_fields, 'wc_clean');
359 359
 
360 360
 		/**
361 361
 		 * If ship to different address checkbox is checked then we need
362 362
 		 * to validate shipping fields too.
363 363
 		 */
364
-		if ( isset( $all_fields['ship_to_different_address'] ) ) {
364
+		if (isset($all_fields['ship_to_different_address'])) {
365 365
 			$validate_shipping_fields = true;
366 366
 		}
367 367
 
368 368
 		// Check if createaccount is checked.
369
-		if ( isset( $all_fields['createaccount'] ) ) {
369
+		if (isset($all_fields['createaccount'])) {
370 370
 			$create_account = true;
371 371
 		}
372 372
 
373 373
 		// Check if required fields are empty.
374
-		foreach ( $required_fields as $field => $field_value ) {
374
+		foreach ($required_fields as $field => $field_value) {
375 375
 			// Check for shipping field.
376
-			if ( preg_match( '/^shipping_/', $field ) && ! $validate_shipping_fields ) {
376
+			if (preg_match('/^shipping_/', $field) && ! $validate_shipping_fields) {
377 377
 				continue;
378 378
 			}
379 379
 
380 380
 			// Check create account name.
381
-			if ( 'account_username' === $field && ! $create_account ) {
381
+			if ('account_username' === $field && ! $create_account) {
382 382
 				continue;
383 383
 			}
384 384
 
385 385
 			// Check create account password.
386
-			if ( 'account_password' === $field && ! $create_account ) {
386
+			if ('account_password' === $field && ! $create_account) {
387 387
 				continue;
388 388
 			}
389 389
 
390
-			if ( empty( $field_value ) || '-1' === $field_value ) {
391
-				$error_field = $this->normalize_field( $field );
390
+			if (empty($field_value) || '-1' === $field_value) {
391
+				$error_field = $this->normalize_field($field);
392 392
 				/* translators: error field name */
393
-				$errors->add( 'validation', sprintf( __( '<strong>%s</strong> cannot be empty', 'woocommerce-gateway-stripe' ), $error_field ) );
393
+				$errors->add('validation', sprintf(__('<strong>%s</strong> cannot be empty', 'woocommerce-gateway-stripe'), $error_field));
394 394
 			}
395 395
 		}
396 396
 
397 397
 		// Check if email is valid format.
398
-		if ( ! empty( $required_fields['billing_email'] ) && ! is_email( $required_fields['billing_email'] ) ) {
399
-			$errors->add( 'validation', __( 'Email is not valid', 'woocommerce-gateway-stripe' ) );
398
+		if ( ! empty($required_fields['billing_email']) && ! is_email($required_fields['billing_email'])) {
399
+			$errors->add('validation', __('Email is not valid', 'woocommerce-gateway-stripe'));
400 400
 		}
401 401
 
402 402
 		// Check if phone number is valid format.
403
-		if ( ! empty( $required_fields['billing_phone'] ) ) {
404
-			$phone = wc_format_phone_number( $required_fields['billing_phone'] );
403
+		if ( ! empty($required_fields['billing_phone'])) {
404
+			$phone = wc_format_phone_number($required_fields['billing_phone']);
405 405
 
406
-			if ( '' !== $phone && ! WC_Validation::is_phone( $phone ) ) {
406
+			if ('' !== $phone && ! WC_Validation::is_phone($phone)) {
407 407
 				/* translators: %s: phone number */
408
-				$errors->add( 'validation', __( 'Please enter a valid phone number.', 'woocommerce-gateway-stripe' ) );
408
+				$errors->add('validation', __('Please enter a valid phone number.', 'woocommerce-gateway-stripe'));
409 409
 			}
410 410
 		}
411 411
 
412 412
 		// Check if postal code is valid format.
413
-		if ( ! empty( $required_fields['billing_postcode'] ) ) {
414
-			$country = isset( $required_fields['billing_country'] ) ? $required_fields['billing_country'] : WC()->customer->get_billing_country();
415
-			$postcode = wc_format_postcode( $required_fields['billing_postcode'], $country );
413
+		if ( ! empty($required_fields['billing_postcode'])) {
414
+			$country = isset($required_fields['billing_country']) ? $required_fields['billing_country'] : WC()->customer->get_billing_country();
415
+			$postcode = wc_format_postcode($required_fields['billing_postcode'], $country);
416 416
 
417
-			if ( '' !== $required_fields['billing_postcode'] && ! WC_Validation::is_postcode( $postcode, $country ) ) {
418
-				$errors->add( 'validation', __( 'Please enter a valid billing postcode / ZIP.', 'woocommerce-gateway-stripe' ) );
417
+			if ('' !== $required_fields['billing_postcode'] && ! WC_Validation::is_postcode($postcode, $country)) {
418
+				$errors->add('validation', __('Please enter a valid billing postcode / ZIP.', 'woocommerce-gateway-stripe'));
419 419
 			}
420 420
 		}
421 421
 
422 422
 		// Don't check this on add payment method page.
423
-		if ( ( isset( $_POST['is_add_payment_page'] ) && 'no' === $_POST['is_add_payment_page'] ) ) {
424
-			if ( empty( $all_fields['woocommerce_checkout_update_totals'] ) && empty( $all_fields['terms'] ) && apply_filters( 'woocommerce_checkout_show_terms', wc_get_page_id( 'terms' ) > 0 ) ) {
425
-				$errors->add( 'terms', __( 'You must accept our Terms &amp; Conditions.', 'woocommerce-gateway-stripe' ) );
423
+		if ((isset($_POST['is_add_payment_page']) && 'no' === $_POST['is_add_payment_page'])) {
424
+			if (empty($all_fields['woocommerce_checkout_update_totals']) && empty($all_fields['terms']) && apply_filters('woocommerce_checkout_show_terms', wc_get_page_id('terms') > 0)) {
425
+				$errors->add('terms', __('You must accept our Terms &amp; Conditions.', 'woocommerce-gateway-stripe'));
426 426
 			}
427 427
 		}
428 428
 
429
-		if ( WC()->cart->needs_shipping() && $validate_shipping_fields ) {
429
+		if (WC()->cart->needs_shipping() && $validate_shipping_fields) {
430 430
 			// Check if postal code is valid format.
431
-			if ( ! empty( $required_fields['shipping_postcode'] ) ) {
432
-				$country = isset( $required_fields['shipping_country'] ) ? $required_fields['shipping_country'] : WC()->customer->get_shipping_country();
433
-				$postcode = wc_format_postcode( $required_fields['shipping_postcode'], $country );
431
+			if ( ! empty($required_fields['shipping_postcode'])) {
432
+				$country = isset($required_fields['shipping_country']) ? $required_fields['shipping_country'] : WC()->customer->get_shipping_country();
433
+				$postcode = wc_format_postcode($required_fields['shipping_postcode'], $country);
434 434
 
435
-				if ( '' !== $required_fields['shipping_postcode'] && ! WC_Validation::is_postcode( $postcode, $country ) ) {
436
-					$errors->add( 'validation', __( 'Please enter a valid shipping postcode / ZIP.', 'woocommerce-gateway-stripe' ) );
435
+				if ('' !== $required_fields['shipping_postcode'] && ! WC_Validation::is_postcode($postcode, $country)) {
436
+					$errors->add('validation', __('Please enter a valid shipping postcode / ZIP.', 'woocommerce-gateway-stripe'));
437 437
 				}
438 438
 			}
439 439
 		}
440 440
 
441
-		if ( WC()->cart->needs_shipping() ) {
441
+		if (WC()->cart->needs_shipping()) {
442 442
 			$shipping_country = WC()->customer->get_shipping_country();
443 443
 
444
-			if ( empty( $shipping_country ) ) {
445
-				$errors->add( 'shipping', __( 'Please enter an address to continue.', 'woocommerce-gateway-stripe' ) );
446
-			} elseif ( ! in_array( WC()->customer->get_shipping_country(), array_keys( WC()->countries->get_shipping_countries() ) ) ) {
444
+			if (empty($shipping_country)) {
445
+				$errors->add('shipping', __('Please enter an address to continue.', 'woocommerce-gateway-stripe'));
446
+			} elseif ( ! in_array(WC()->customer->get_shipping_country(), array_keys(WC()->countries->get_shipping_countries()))) {
447 447
 				/* translators: country name */
448
-				$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() ) );
448
+				$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()));
449 449
 			} else {
450
-				$chosen_shipping_methods = WC()->session->get( 'chosen_shipping_methods' );
450
+				$chosen_shipping_methods = WC()->session->get('chosen_shipping_methods');
451 451
 
452
-				foreach ( WC()->shipping->get_packages() as $i => $package ) {
453
-					if ( ! isset( $chosen_shipping_methods[ $i ], $package['rates'][ $chosen_shipping_methods[ $i ] ] ) ) {
454
-						$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' ) );
452
+				foreach (WC()->shipping->get_packages() as $i => $package) {
453
+					if ( ! isset($chosen_shipping_methods[$i], $package['rates'][$chosen_shipping_methods[$i]])) {
454
+						$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'));
455 455
 					}
456 456
 				}
457 457
 			}
458 458
 		}
459 459
 
460
-		if ( WC()->cart->needs_payment() ) {
460
+		if (WC()->cart->needs_payment()) {
461 461
 			$available_gateways = WC()->payment_gateways->get_available_payment_gateways();
462 462
 
463
-			if ( ! isset( $available_gateways[ $all_fields['payment_method'] ] ) ) {
464
-				$errors->add( 'payment', __( 'Invalid payment method.', 'woocommerce-gateway-stripe' ) );
463
+			if ( ! isset($available_gateways[$all_fields['payment_method']])) {
464
+				$errors->add('payment', __('Invalid payment method.', 'woocommerce-gateway-stripe'));
465 465
 			} else {
466
-				$available_gateways[ $all_fields['payment_method'] ]->validate_fields();
466
+				$available_gateways[$all_fields['payment_method']]->validate_fields();
467 467
 			}
468 468
 		}
469 469
 
470
-		if ( 0 === count( $errors->errors ) ) {
471
-			wp_send_json( 'success' );
470
+		if (0 === count($errors->errors)) {
471
+			wp_send_json('success');
472 472
 		} else {
473
-			foreach ( $errors->get_error_messages() as $message ) {
474
-				wc_add_notice( $message, 'error' );
473
+			foreach ($errors->get_error_messages() as $message) {
474
+				wc_add_notice($message, 'error');
475 475
 			}
476 476
 
477 477
 			$this->send_ajax_failure_response();
@@ -485,9 +485,9 @@  discard block
 block discarded – undo
485 485
 	 * @version 4.0.0
486 486
 	 */
487 487
 	public function send_ajax_failure_response() {
488
-		if ( is_ajax() ) {
488
+		if (is_ajax()) {
489 489
 			// only print notices if not reloading the checkout, otherwise they're lost in the page reload.
490
-			if ( ! isset( WC()->session->reload_checkout ) ) {
490
+			if ( ! isset(WC()->session->reload_checkout)) {
491 491
 				ob_start();
492 492
 				wc_print_notices();
493 493
 				$messages = ob_get_clean();
@@ -495,14 +495,14 @@  discard block
 block discarded – undo
495 495
 
496 496
 			$response = array(
497 497
 				'result'   => 'failure',
498
-				'messages' => isset( $messages ) ? $messages : '',
499
-				'refresh'  => isset( WC()->session->refresh_totals ),
500
-				'reload'   => isset( WC()->session->reload_checkout ),
498
+				'messages' => isset($messages) ? $messages : '',
499
+				'refresh'  => isset(WC()->session->refresh_totals),
500
+				'reload'   => isset(WC()->session->reload_checkout),
501 501
 			);
502 502
 
503
-			unset( WC()->session->refresh_totals, WC()->session->reload_checkout );
503
+			unset(WC()->session->refresh_totals, WC()->session->reload_checkout);
504 504
 
505
-			wp_send_json( $response );
505
+			wp_send_json($response);
506 506
 		}
507 507
 	}
508 508
 }
Please login to merge, or discard this patch.
includes/class-wc-stripe-api.php 1 patch
Spacing   +25 added lines, -25 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,13 +95,13 @@  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
-		if ( 'charges' === $api && 'POST' === $method ) {
104
-			$headers['Idempotency-Key'] = uniqid( 'stripe_' );
103
+		if ('charges' === $api && 'POST' === $method) {
104
+			$headers['Idempotency-Key'] = uniqid('stripe_');
105 105
 		}
106 106
 
107 107
 		$response = wp_safe_remote_post(
@@ -109,17 +109,17 @@  discard block
 block discarded – undo
109 109
 			array(
110 110
 				'method'  => $method,
111 111
 				'headers' => $headers,
112
-				'body'    => apply_filters( 'woocommerce_stripe_request_body', $request, $api ),
112
+				'body'    => apply_filters('woocommerce_stripe_request_body', $request, $api),
113 113
 				'timeout' => 70,
114 114
 			)
115 115
 		);
116 116
 
117
-		if ( is_wp_error( $response ) || empty( $response['body'] ) ) {
118
-			WC_Stripe_Logger::log( 'Error Response: ' . print_r( $response, true ) );
119
-			throw new WC_Stripe_Exception( print_r( $response, true ), __( 'There was a problem connecting to the Stripe API endpoint.', 'woocommerce-gateway-stripe' ) );
117
+		if (is_wp_error($response) || empty($response['body'])) {
118
+			WC_Stripe_Logger::log('Error Response: ' . print_r($response, true));
119
+			throw new WC_Stripe_Exception(print_r($response, true), __('There was a problem connecting to the Stripe API endpoint.', 'woocommerce-gateway-stripe'));
120 120
 		}
121 121
 
122
-		return json_decode( $response['body'] );
122
+		return json_decode($response['body']);
123 123
 	}
124 124
 
125 125
 	/**
@@ -129,8 +129,8 @@  discard block
 block discarded – undo
129 129
 	 * @version 4.0.0
130 130
 	 * @param string $api
131 131
 	 */
132
-	public static function retrieve( $api ) {
133
-		WC_Stripe_Logger::log( "{$api}" );
132
+	public static function retrieve($api) {
133
+		WC_Stripe_Logger::log("{$api}");
134 134
 
135 135
 		$response = wp_safe_remote_get(
136 136
 			self::ENDPOINT . $api,
@@ -141,11 +141,11 @@  discard block
 block discarded – undo
141 141
 			)
142 142
 		);
143 143
 
144
-		if ( is_wp_error( $response ) || empty( $response['body'] ) ) {
145
-			WC_Stripe_Logger::log( 'Error Response: ' . print_r( $response, true ) );
146
-			return new WP_Error( 'stripe_error', __( 'There was a problem connecting to the Stripe API endpoint.', 'woocommerce-gateway-stripe' ) );
144
+		if (is_wp_error($response) || empty($response['body'])) {
145
+			WC_Stripe_Logger::log('Error Response: ' . print_r($response, true));
146
+			return new WP_Error('stripe_error', __('There was a problem connecting to the Stripe API endpoint.', 'woocommerce-gateway-stripe'));
147 147
 		}
148 148
 
149
-		return json_decode( $response['body'] );
149
+		return json_decode($response['body']);
150 150
 	}
151 151
 }
Please login to merge, or discard this patch.
includes/class-wc-stripe-webhook-handler.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
 
@@ -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,80 +134,80 @@  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
 						$localized_message = 'API connection error and retries exhausted.';
158
-						$order->add_order_note( $localized_message );
159
-						throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message );
158
+						$order->add_order_note($localized_message);
159
+						throw new WC_Stripe_Exception(print_r($response, true), $localized_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
-					if ( WC_Stripe_Helper::is_pre_30() ) {
166
-						delete_user_meta( $order->customer_user, '_stripe_customer_id' );
167
-						delete_post_meta( $order_id, '_stripe_customer_id' );
164
+				if (preg_match('/No such customer/i', $response->error->message) && $retry) {
165
+					if (WC_Stripe_Helper::is_pre_30()) {
166
+						delete_user_meta($order->customer_user, '_stripe_customer_id');
167
+						delete_post_meta($order_id, '_stripe_customer_id');
168 168
 					} else {
169
-						delete_user_meta( $order->get_customer_id(), '_stripe_customer_id' );
170
-						$order->delete_meta_data( '_stripe_customer_id' );
169
+						delete_user_meta($order->get_customer_id(), '_stripe_customer_id');
170
+						$order->delete_meta_data('_stripe_customer_id');
171 171
 						$order->save();
172 172
 					}
173 173
 
174
-					return $this->process_payment( $order_id, false );
174
+					return $this->process_payment($order_id, false);
175 175
 
176
-				} elseif ( preg_match( '/No such token/i', $response->error->message ) && $source_object->token_id ) {
176
+				} elseif (preg_match('/No such token/i', $response->error->message) && $source_object->token_id) {
177 177
 					// Source param wrong? The CARD may have been deleted on stripe's end. Remove token and show message.
178
-					$wc_token = WC_Payment_Tokens::get( $source_object->token_id );
178
+					$wc_token = WC_Payment_Tokens::get($source_object->token_id);
179 179
 					$wc_token->delete();
180
-					$message = __( 'This card is no longer available and has been removed.', 'woocommerce-gateway-stripe' );
181
-					$order->add_order_note( $message );
182
-					throw new WC_Stripe_Exception( print_r( $response, true ), $message );
180
+					$message = __('This card is no longer available and has been removed.', 'woocommerce-gateway-stripe');
181
+					$order->add_order_note($message);
182
+					throw new WC_Stripe_Exception(print_r($response, true), $message);
183 183
 				}
184 184
 
185 185
 				$localized_messages = WC_Stripe_Helper::get_localized_messages();
186 186
 
187
-				if ( 'card_error' === $response->error->type ) {
188
-					$localized_message = isset( $localized_messages[ $response->error->code ] ) ? $localized_messages[ $response->error->code ] : $response->error->message;
187
+				if ('card_error' === $response->error->type) {
188
+					$localized_message = isset($localized_messages[$response->error->code]) ? $localized_messages[$response->error->code] : $response->error->message;
189 189
 				} else {
190
-					$localized_message = isset( $localized_messages[ $response->error->type ] ) ? $localized_messages[ $response->error->type ] : $response->error->message;
190
+					$localized_message = isset($localized_messages[$response->error->type]) ? $localized_messages[$response->error->type] : $response->error->message;
191 191
 				}
192 192
 
193
-				$order->add_order_note( $localized_message );
193
+				$order->add_order_note($localized_message);
194 194
 
195
-				throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message );
195
+				throw new WC_Stripe_Exception(print_r($response, true), $localized_message);
196 196
 			}
197 197
 
198
-			do_action( 'wc_gateway_stripe_process_webhook_payment', $response, $order );
198
+			do_action('wc_gateway_stripe_process_webhook_payment', $response, $order);
199 199
 
200
-			$this->process_response( $response, $order );
200
+			$this->process_response($response, $order);
201 201
 
202
-		} catch ( WC_Stripe_Exception $e ) {
203
-			WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() );
202
+		} catch (WC_Stripe_Exception $e) {
203
+			WC_Stripe_Logger::log('Error: ' . $e->getMessage());
204 204
 
205
-			do_action( 'wc_gateway_stripe_process_webhook_payment_error', $e, $order );
205
+			do_action('wc_gateway_stripe_process_webhook_payment_error', $e, $order);
206 206
 
207
-			$statuses = array( 'pending', 'failed' );
207
+			$statuses = array('pending', 'failed');
208 208
 
209
-			if ( $order->has_status( $statuses ) ) {
210
-				$this->send_failed_order_email( $order_id );
209
+			if ($order->has_status($statuses)) {
210
+				$this->send_failed_order_email($order_id);
211 211
 			}
212 212
 		}
213 213
 	}
@@ -221,18 +221,18 @@  discard block
 block discarded – undo
221 221
 	 * @version 4.0.0
222 222
 	 * @param object $notification
223 223
 	 */
224
-	public function process_webhook_dispute( $notification ) {
225
-		$order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->id );
224
+	public function process_webhook_dispute($notification) {
225
+		$order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->id);
226 226
 
227
-		if ( ! $order ) {
228
-			WC_Stripe_Logger::log( 'Could not find order via charge ID: ' . $notification->data->object->id );
227
+		if ( ! $order) {
228
+			WC_Stripe_Logger::log('Could not find order via charge ID: ' . $notification->data->object->id);
229 229
 			return;
230 230
 		}
231 231
 
232
-		$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' ) );
232
+		$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'));
233 233
 
234
-		do_action( 'wc_gateway_stripe_process_webhook_payment_error', $order, $notification );
235
-		$this->send_failed_order_email( $order_id );
234
+		do_action('wc_gateway_stripe_process_webhook_payment_error', $order, $notification);
235
+		$this->send_failed_order_email($order_id);
236 236
 	}
237 237
 
238 238
 	/**
@@ -243,41 +243,41 @@  discard block
 block discarded – undo
243 243
 	 * @version 4.0.0
244 244
 	 * @param object $notification
245 245
 	 */
246
-	public function process_webhook_capture( $notification ) {
247
-		$order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->id );
246
+	public function process_webhook_capture($notification) {
247
+		$order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->id);
248 248
 
249
-		if ( ! $order ) {
250
-			WC_Stripe_Logger::log( 'Could not find order via charge ID: ' . $notification->data->object->id );
249
+		if ( ! $order) {
250
+			WC_Stripe_Logger::log('Could not find order via charge ID: ' . $notification->data->object->id);
251 251
 			return;
252 252
 		}
253 253
 
254 254
 		$order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
255 255
 
256
-		if ( 'stripe' === ( WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method() ) ) {
257
-			$charge   = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_transaction_id', true ) : $order->get_transaction_id();
258
-			$captured = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_stripe_charge_captured', true ) : $order->get_meta( '_stripe_charge_captured', true );
256
+		if ('stripe' === (WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method())) {
257
+			$charge   = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_transaction_id', true) : $order->get_transaction_id();
258
+			$captured = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_stripe_charge_captured', true) : $order->get_meta('_stripe_charge_captured', true);
259 259
 
260
-			if ( $charge && 'no' === $captured ) {
261
-				WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, '_stripe_charge_captured', 'yes' ) : $order->update_meta_data( '_stripe_charge_captured', 'yes' );
260
+			if ($charge && 'no' === $captured) {
261
+				WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, '_stripe_charge_captured', 'yes') : $order->update_meta_data('_stripe_charge_captured', 'yes');
262 262
 
263 263
 				// Store other data such as fees
264
-				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 );
264
+				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);
265 265
 
266
-				if ( isset( $notification->data->object->balance_transaction ) ) {
267
-					$this->update_fees( $order, $notification->data->object->balance_transaction );
266
+				if (isset($notification->data->object->balance_transaction)) {
267
+					$this->update_fees($order, $notification->data->object->balance_transaction);
268 268
 				}
269 269
 
270
-				if ( is_callable( array( $order, 'save' ) ) ) {
270
+				if (is_callable(array($order, 'save'))) {
271 271
 					$order->save();
272 272
 				}
273 273
 
274 274
 				/* translators: transaction id */
275
-				$order->update_status( $order->needs_processing() ? 'processing' : 'completed', sprintf( __( 'Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe' ), $notification->data->object->id ) );
275
+				$order->update_status($order->needs_processing() ? 'processing' : 'completed', sprintf(__('Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe'), $notification->data->object->id));
276 276
 
277 277
 				// Check and see if capture is partial.
278
-				if ( $this->is_partial_capture( $notification ) ) {
279
-					$order->set_total( $this->get_partial_amount_to_charge( $notification ) );
280
-					$order->add_note( __( 'This charge was partially captured via Stripe Dashboard', 'woocommerce-gateway-stripe' ) );
278
+				if ($this->is_partial_capture($notification)) {
279
+					$order->set_total($this->get_partial_amount_to_charge($notification));
280
+					$order->add_note(__('This charge was partially captured via Stripe Dashboard', 'woocommerce-gateway-stripe'));
281 281
 					$order->save();
282 282
 				}
283 283
 			}
@@ -292,38 +292,38 @@  discard block
 block discarded – undo
292 292
 	 * @version 4.0.0
293 293
 	 * @param object $notification
294 294
 	 */
295
-	public function process_webhook_charge_succeeded( $notification ) {
295
+	public function process_webhook_charge_succeeded($notification) {
296 296
 		// The following payment methods are synchronous so does not need to be handle via webhook.
297
-		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 ) ) {
297
+		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)) {
298 298
 			return;
299 299
 		}
300 300
 
301
-		$order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->id );
301
+		$order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->id);
302 302
 
303
-		if ( ! $order ) {
304
-			WC_Stripe_Logger::log( 'Could not find order via charge ID: ' . $notification->data->object->id );
303
+		if ( ! $order) {
304
+			WC_Stripe_Logger::log('Could not find order via charge ID: ' . $notification->data->object->id);
305 305
 			return;
306 306
 		}
307 307
 
308 308
 		$order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
309 309
 
310
-		if ( 'on-hold' !== $order->get_status() ) {
310
+		if ('on-hold' !== $order->get_status()) {
311 311
 			return;
312 312
 		}
313 313
 
314 314
 		// Store other data such as fees
315
-		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 );
315
+		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);
316 316
 
317
-		if ( isset( $notification->data->object->balance_transaction ) ) {
318
-			$this->update_fees( $order, $notification->data->object->balance_transaction );
317
+		if (isset($notification->data->object->balance_transaction)) {
318
+			$this->update_fees($order, $notification->data->object->balance_transaction);
319 319
 		}
320 320
 
321
-		if ( is_callable( array( $order, 'save' ) ) ) {
321
+		if (is_callable(array($order, 'save'))) {
322 322
 			$order->save();
323 323
 		}
324 324
 
325 325
 		/* translators: transaction id */
326
-		$order->update_status( $order->needs_processing() ? 'processing' : 'completed', sprintf( __( 'Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe' ), $notification->data->object->id ) );
326
+		$order->update_status($order->needs_processing() ? 'processing' : 'completed', sprintf(__('Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe'), $notification->data->object->id));
327 327
 	}
328 328
 
329 329
 	/**
@@ -334,23 +334,23 @@  discard block
 block discarded – undo
334 334
 	 * @version 4.0.0
335 335
 	 * @param object $notification
336 336
 	 */
337
-	public function process_webhook_charge_failed( $notification ) {
338
-		$order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->id );
337
+	public function process_webhook_charge_failed($notification) {
338
+		$order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->id);
339 339
 
340
-		if ( ! $order ) {
341
-			WC_Stripe_Logger::log( 'Could not find order via charge ID: ' . $notification->data->object->id );
340
+		if ( ! $order) {
341
+			WC_Stripe_Logger::log('Could not find order via charge ID: ' . $notification->data->object->id);
342 342
 			return;
343 343
 		}
344 344
 
345 345
 		$order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
346 346
 
347
-		if ( 'on-hold' !== $order->get_status() ) {
347
+		if ('on-hold' !== $order->get_status()) {
348 348
 			return;
349 349
 		}
350 350
 
351
-		$order->update_status( 'failed', __( 'This payment failed to clear.', 'woocommerce-gateway-stripe' ) );
351
+		$order->update_status('failed', __('This payment failed to clear.', 'woocommerce-gateway-stripe'));
352 352
 
353
-		do_action( 'wc_gateway_stripe_process_webhook_payment_error', $order, $notification );
353
+		do_action('wc_gateway_stripe_process_webhook_payment_error', $order, $notification);
354 354
 	}
355 355
 
356 356
 	/**
@@ -361,23 +361,23 @@  discard block
 block discarded – undo
361 361
 	 * @version 4.0.0
362 362
 	 * @param object $notification
363 363
 	 */
364
-	public function process_webhook_source_canceled( $notification ) {
365
-		$order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->id );
364
+	public function process_webhook_source_canceled($notification) {
365
+		$order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->id);
366 366
 
367
-		if ( ! $order ) {
368
-			WC_Stripe_Logger::log( 'Could not find order via charge ID: ' . $notification->data->object->id );
367
+		if ( ! $order) {
368
+			WC_Stripe_Logger::log('Could not find order via charge ID: ' . $notification->data->object->id);
369 369
 			return;
370 370
 		}
371 371
 
372 372
 		$order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
373 373
 
374
-		if ( 'on-hold' !== $order->get_status() || 'cancelled' !== $order->get_status() ) {
374
+		if ('on-hold' !== $order->get_status() || 'cancelled' !== $order->get_status()) {
375 375
 			return;
376 376
 		}
377 377
 
378
-		$order->update_status( 'cancelled', __( 'This payment has cancelled.', 'woocommerce-gateway-stripe' ) );
378
+		$order->update_status('cancelled', __('This payment has cancelled.', 'woocommerce-gateway-stripe'));
379 379
 
380
-		do_action( 'wc_gateway_stripe_process_webhook_payment_error', $order, $notification );
380
+		do_action('wc_gateway_stripe_process_webhook_payment_error', $order, $notification);
381 381
 	}
382 382
 
383 383
 	/**
@@ -388,37 +388,37 @@  discard block
 block discarded – undo
388 388
 	 * @version 4.0.0
389 389
 	 * @param object $notification
390 390
 	 */
391
-	public function process_webhook_refund( $notification ) {
392
-		$order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->id );
391
+	public function process_webhook_refund($notification) {
392
+		$order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->id);
393 393
 
394
-		if ( ! $order ) {
395
-			WC_Stripe_Logger::log( 'Could not find order via charge ID: ' . $notification->data->object->id );
394
+		if ( ! $order) {
395
+			WC_Stripe_Logger::log('Could not find order via charge ID: ' . $notification->data->object->id);
396 396
 			return;
397 397
 		}
398 398
 
399 399
 		$order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
400 400
 
401
-		if ( 'stripe' === ( WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method() ) ) {
402
-			$charge    = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_transaction_id', true ) : $order->get_transaction_id();
403
-			$captured  = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_stripe_charge_captured', true ) : $order->get_meta( '_stripe_charge_captured', true );
404
-			$refund_id = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_stripe_refund_id', true ) : $order->get_meta( '_stripe_refund_id', true );
401
+		if ('stripe' === (WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method())) {
402
+			$charge    = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_transaction_id', true) : $order->get_transaction_id();
403
+			$captured  = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_stripe_charge_captured', true) : $order->get_meta('_stripe_charge_captured', true);
404
+			$refund_id = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_stripe_refund_id', true) : $order->get_meta('_stripe_refund_id', true);
405 405
 
406 406
 			// If the refund ID matches, don't continue to prevent double refunding.
407
-			if ( $notification->data->object->refunds->data[0]->id === $refund_id ) {
407
+			if ($notification->data->object->refunds->data[0]->id === $refund_id) {
408 408
 				return;
409 409
 			}
410 410
 
411 411
 			// Only refund captured charge.
412
-			if ( $charge && 'yes' === $captured ) {
412
+			if ($charge && 'yes' === $captured) {
413 413
 				// Create the refund.
414
-				$refund = wc_create_refund( array(
414
+				$refund = wc_create_refund(array(
415 415
 					'order_id'       => $order_id,
416
-					'amount'         => $this->get_refund_amount( $notification ),
417
-					'reason'         => __( 'Refunded via Stripe Dashboard', 'woocommerce-gateway-stripe' ),
418
-				) );
416
+					'amount'         => $this->get_refund_amount($notification),
417
+					'reason'         => __('Refunded via Stripe Dashboard', 'woocommerce-gateway-stripe'),
418
+				));
419 419
 
420
-				if ( is_wp_error( $refund ) ) {
421
-					WC_Stripe_Logger::log( $refund->get_error_message() );
420
+				if (is_wp_error($refund)) {
421
+					WC_Stripe_Logger::log($refund->get_error_message());
422 422
 				}
423 423
 			}
424 424
 		}
@@ -431,7 +431,7 @@  discard block
 block discarded – undo
431 431
 	 * @version 4.0.0
432 432
 	 * @param object $notification
433 433
 	 */
434
-	public function is_partial_capture( $notification ) {
434
+	public function is_partial_capture($notification) {
435 435
 		return 0 < $notification->data->object->amount_refunded;
436 436
 	}
437 437
 
@@ -442,11 +442,11 @@  discard block
 block discarded – undo
442 442
 	 * @version 4.0.0
443 443
 	 * @param object $notification
444 444
 	 */
445
-	public function get_refund_amount( $notification ) {
446
-		if ( $this->is_partial_capture( $notification ) ) {
445
+	public function get_refund_amount($notification) {
446
+		if ($this->is_partial_capture($notification)) {
447 447
 			$amount = $notification->data->object->amount_refunded / 100;
448 448
 
449
-			if ( in_array( strtolower( $notification->data->object->currency ), WC_Stripe_Helper::no_decimal_currencies() ) ) {
449
+			if (in_array(strtolower($notification->data->object->currency), WC_Stripe_Helper::no_decimal_currencies())) {
450 450
 				$amount = $notification->data->object->amount_refunded;
451 451
 			}
452 452
 
@@ -463,12 +463,12 @@  discard block
 block discarded – undo
463 463
 	 * @version 4.0.0
464 464
 	 * @param object $notification
465 465
 	 */
466
-	public function get_partial_amount_to_charge( $notification ) {
467
-		if ( $this->is_partial_capture( $notification ) ) {
468
-			$amount = ( $notification->data->object->amount - $notification->data->object->amount_refunded ) / 100;
466
+	public function get_partial_amount_to_charge($notification) {
467
+		if ($this->is_partial_capture($notification)) {
468
+			$amount = ($notification->data->object->amount - $notification->data->object->amount_refunded) / 100;
469 469
 
470
-			if ( in_array( strtolower( $notification->data->object->currency ), WC_Stripe_Helper::no_decimal_currencies() ) ) {
471
-				$amount = ( $notification->data->object->amount - $notification->data->object->amount_refunded );
470
+			if (in_array(strtolower($notification->data->object->currency), WC_Stripe_Helper::no_decimal_currencies())) {
471
+				$amount = ($notification->data->object->amount - $notification->data->object->amount_refunded);
472 472
 			}
473 473
 
474 474
 			return $amount;
@@ -484,36 +484,36 @@  discard block
 block discarded – undo
484 484
 	 * @version 4.0.0
485 485
 	 * @param string $request_body
486 486
 	 */
487
-	public function process_webhook( $request_body ) {
488
-		$notification = json_decode( $request_body );
487
+	public function process_webhook($request_body) {
488
+		$notification = json_decode($request_body);
489 489
 
490
-		switch ( $notification->type ) {
490
+		switch ($notification->type) {
491 491
 			case 'source.chargeable':
492
-				$this->process_webhook_payment( $notification );
492
+				$this->process_webhook_payment($notification);
493 493
 				break;
494 494
 
495 495
 			case 'source.canceled':
496
-				$this->process_webhook_source_canceled( $notification );
496
+				$this->process_webhook_source_canceled($notification);
497 497
 				break;
498 498
 
499 499
 			case 'charge.succeeded':
500
-				$this->process_webhook_charge_succeeded( $notification );
500
+				$this->process_webhook_charge_succeeded($notification);
501 501
 				break;
502 502
 
503 503
 			case 'charge.failed':
504
-				$this->process_webhook_charge_failed( $notification );
504
+				$this->process_webhook_charge_failed($notification);
505 505
 				break;
506 506
 
507 507
 			case 'charge.captured':
508
-				$this->process_webhook_capture( $notification );
508
+				$this->process_webhook_capture($notification);
509 509
 				break;
510 510
 
511 511
 			case 'charge.dispute.created':
512
-				$this->process_webhook_dispute( $notification );
512
+				$this->process_webhook_dispute($notification);
513 513
 				break;
514 514
 
515 515
 			case 'charge.refunded':
516
-				$this->process_webhook_refund( $notification );
516
+				$this->process_webhook_refund($notification);
517 517
 				break;
518 518
 
519 519
 		}
Please login to merge, or discard this patch.
includes/class-wc-gateway-stripe.php 1 patch
Spacing   +198 added lines, -198 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
 
@@ -112,9 +112,9 @@  discard block
 block discarded – undo
112 112
 	 */
113 113
 	public function __construct() {
114 114
 		$this->id                   = 'stripe';
115
-		$this->method_title         = __( 'Stripe', 'woocommerce-gateway-stripe' );
115
+		$this->method_title         = __('Stripe', 'woocommerce-gateway-stripe');
116 116
 		/* translators: 1) link to Stripe register page 2) link to Stripe api keys page */
117
-		$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' );
117
+		$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');
118 118
 		$this->has_fields           = true;
119 119
 		$this->supports             = array(
120 120
 			'products',
@@ -141,37 +141,37 @@  discard block
 block discarded – undo
141 141
 		$this->init_settings();
142 142
 
143 143
 		// Get setting values.
144
-		$this->title                   = $this->get_option( 'title' );
145
-		$this->description             = $this->get_option( 'description' );
146
-		$this->enabled                 = $this->get_option( 'enabled' );
147
-		$this->testmode                = 'yes' === $this->get_option( 'testmode' );
148
-		$this->inline_cc_form          = 'yes' === $this->get_option( 'inline_cc_form' );
149
-		$this->capture                 = 'yes' === $this->get_option( 'capture', 'yes' );
150
-		$this->statement_descriptor    = WC_Stripe_Helper::clean_statement_descriptor( $this->get_option( 'statement_descriptor' ) );
151
-		$this->three_d_secure          = 'yes' === $this->get_option( 'three_d_secure' );
152
-		$this->stripe_checkout         = 'yes' === $this->get_option( 'stripe_checkout' );
153
-		$this->stripe_checkout_image   = $this->get_option( 'stripe_checkout_image', '' );
154
-		$this->saved_cards             = 'yes' === $this->get_option( 'saved_cards' );
155
-		$this->secret_key              = $this->testmode ? $this->get_option( 'test_secret_key' ) : $this->get_option( 'secret_key' );
156
-		$this->publishable_key         = $this->testmode ? $this->get_option( 'test_publishable_key' ) : $this->get_option( 'publishable_key' );
157
-		$this->bitcoin                 = 'USD' === strtoupper( get_woocommerce_currency() ) && 'yes' === $this->get_option( 'stripe_bitcoin' );
158
-		$this->payment_request         = 'yes' === $this->get_option( 'payment_request', 'yes' );
159
-		$this->apple_pay_domain_set    = 'yes' === $this->get_option( 'apple_pay_domain_set', 'no' );
144
+		$this->title                   = $this->get_option('title');
145
+		$this->description             = $this->get_option('description');
146
+		$this->enabled                 = $this->get_option('enabled');
147
+		$this->testmode                = 'yes' === $this->get_option('testmode');
148
+		$this->inline_cc_form          = 'yes' === $this->get_option('inline_cc_form');
149
+		$this->capture                 = 'yes' === $this->get_option('capture', 'yes');
150
+		$this->statement_descriptor    = WC_Stripe_Helper::clean_statement_descriptor($this->get_option('statement_descriptor'));
151
+		$this->three_d_secure          = 'yes' === $this->get_option('three_d_secure');
152
+		$this->stripe_checkout         = 'yes' === $this->get_option('stripe_checkout');
153
+		$this->stripe_checkout_image   = $this->get_option('stripe_checkout_image', '');
154
+		$this->saved_cards             = 'yes' === $this->get_option('saved_cards');
155
+		$this->secret_key              = $this->testmode ? $this->get_option('test_secret_key') : $this->get_option('secret_key');
156
+		$this->publishable_key         = $this->testmode ? $this->get_option('test_publishable_key') : $this->get_option('publishable_key');
157
+		$this->bitcoin                 = 'USD' === strtoupper(get_woocommerce_currency()) && 'yes' === $this->get_option('stripe_bitcoin');
158
+		$this->payment_request         = 'yes' === $this->get_option('payment_request', 'yes');
159
+		$this->apple_pay_domain_set    = 'yes' === $this->get_option('apple_pay_domain_set', 'no');
160 160
 		$this->apple_pay_verify_notice = '';
161 161
 
162
-		if ( $this->stripe_checkout ) {
163
-			$this->order_button_text = __( 'Continue to payment', 'woocommerce-gateway-stripe' );
162
+		if ($this->stripe_checkout) {
163
+			$this->order_button_text = __('Continue to payment', 'woocommerce-gateway-stripe');
164 164
 		}
165 165
 
166
-		WC_Stripe_API::set_secret_key( $this->secret_key );
166
+		WC_Stripe_API::set_secret_key($this->secret_key);
167 167
 
168 168
 		$this->init_apple_pay();
169 169
 
170 170
 		// Hooks.
171
-		add_action( 'wp_enqueue_scripts', array( $this, 'payment_scripts' ) );
172
-		add_action( 'admin_enqueue_scripts', array( $this, 'admin_scripts' ) );
173
-		add_action( 'admin_notices', array( $this, 'admin_notices' ) );
174
-		add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) );
171
+		add_action('wp_enqueue_scripts', array($this, 'payment_scripts'));
172
+		add_action('admin_enqueue_scripts', array($this, 'admin_scripts'));
173
+		add_action('admin_notices', array($this, 'admin_notices'));
174
+		add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options'));
175 175
 	}
176 176
 
177 177
 	/**
@@ -180,7 +180,7 @@  discard block
 block discarded – undo
180 180
 	 * @since 4.0.2
181 181
 	 */
182 182
 	public function is_available() {
183
-		if ( is_add_payment_method_page() && ! $this->saved_cards ) {
183
+		if (is_add_payment_method_page() && ! $this->saved_cards) {
184 184
 			return false;
185 185
 		}
186 186
 
@@ -203,17 +203,17 @@  discard block
 block discarded – undo
203 203
 		$icons_str .= $icons['amex'];
204 204
 		$icons_str .= $icons['mastercard'];
205 205
 
206
-		if ( 'USD' === get_woocommerce_currency() ) {
206
+		if ('USD' === get_woocommerce_currency()) {
207 207
 			$icons_str .= $icons['discover'];
208 208
 			$icons_str .= $icons['jcb'];
209 209
 			$icons_str .= $icons['diners'];
210 210
 		}
211 211
 
212
-		if ( $this->bitcoin && $this->stripe_checkout ) {
212
+		if ($this->bitcoin && $this->stripe_checkout) {
213 213
 			$icons_str .= $icons['bitcoin'];
214 214
 		}
215 215
 
216
-		return apply_filters( 'woocommerce_gateway_icon', $icons_str, $this->id );
216
+		return apply_filters('woocommerce_gateway_icon', $icons_str, $this->id);
217 217
 	}
218 218
 
219 219
 	/**
@@ -225,9 +225,9 @@  discard block
 block discarded – undo
225 225
 	public function init_apple_pay() {
226 226
 		if (
227 227
 			is_admin() &&
228
-			isset( $_GET['page'] ) && 'wc-settings' === $_GET['page'] &&
229
-			isset( $_GET['tab'] ) && 'checkout' === $_GET['tab'] &&
230
-			isset( $_GET['section'] ) && 'stripe' === $_GET['section'] &&
228
+			isset($_GET['page']) && 'wc-settings' === $_GET['page'] &&
229
+			isset($_GET['tab']) && 'checkout' === $_GET['tab'] &&
230
+			isset($_GET['section']) && 'stripe' === $_GET['section'] &&
231 231
 			$this->payment_request
232 232
 		) {
233 233
 			$this->process_apple_pay_verification();
@@ -241,9 +241,9 @@  discard block
 block discarded – undo
241 241
 	 * @version 3.1.0
242 242
 	 * @param string $secret_key
243 243
 	 */
244
-	private function register_apple_pay_domain( $secret_key = '' ) {
245
-		if ( empty( $secret_key ) ) {
246
-			throw new Exception( __( 'Unable to verify domain - missing secret key.', 'woocommerce-gateway-stripe' ) );
244
+	private function register_apple_pay_domain($secret_key = '') {
245
+		if (empty($secret_key)) {
246
+			throw new Exception(__('Unable to verify domain - missing secret key.', 'woocommerce-gateway-stripe'));
247 247
 		}
248 248
 
249 249
 		$endpoint = 'https://api.stripe.com/v1/apple_pay/domains';
@@ -257,23 +257,23 @@  discard block
 block discarded – undo
257 257
 			'Authorization' => 'Bearer ' . $secret_key,
258 258
 		);
259 259
 
260
-		$response = wp_remote_post( $endpoint, array(
260
+		$response = wp_remote_post($endpoint, array(
261 261
 			'headers' => $headers,
262
-			'body'    => http_build_query( $data ),
263
-		) );
262
+			'body'    => http_build_query($data),
263
+		));
264 264
 
265
-		if ( is_wp_error( $response ) ) {
265
+		if (is_wp_error($response)) {
266 266
 			/* translators: error message */
267
-			throw new Exception( sprintf( __( 'Unable to verify domain - %s', 'woocommerce-gateway-stripe' ), $response->get_error_message() ) );
267
+			throw new Exception(sprintf(__('Unable to verify domain - %s', 'woocommerce-gateway-stripe'), $response->get_error_message()));
268 268
 		}
269 269
 
270
-		if ( 200 !== $response['response']['code'] ) {
271
-			$parsed_response = json_decode( $response['body'] );
270
+		if (200 !== $response['response']['code']) {
271
+			$parsed_response = json_decode($response['body']);
272 272
 
273 273
 			$this->apple_pay_verify_notice = $parsed_response->error->message;
274 274
 
275 275
 			/* translators: error message */
276
-			throw new Exception( sprintf( __( 'Unable to verify domain - %s', 'woocommerce-gateway-stripe' ), $parsed_response->error->message ) );
276
+			throw new Exception(sprintf(__('Unable to verify domain - %s', 'woocommerce-gateway-stripe'), $parsed_response->error->message));
277 277
 		}
278 278
 	}
279 279
 
@@ -284,48 +284,48 @@  discard block
 block discarded – undo
284 284
 	 * @version 3.1.0
285 285
 	 */
286 286
 	public function process_apple_pay_verification() {
287
-		$gateway_settings = get_option( 'woocommerce_stripe_settings', array() );
287
+		$gateway_settings = get_option('woocommerce_stripe_settings', array());
288 288
 
289 289
 		try {
290
-			$path     = untrailingslashit( $_SERVER['DOCUMENT_ROOT'] );
290
+			$path     = untrailingslashit($_SERVER['DOCUMENT_ROOT']);
291 291
 			$dir      = '.well-known';
292 292
 			$file     = 'apple-developer-merchantid-domain-association';
293 293
 			$fullpath = $path . '/' . $dir . '/' . $file;
294 294
 
295
-			if ( ! empty( $gateway_settings['apple_pay_domain_set'] ) && 'yes' === $gateway_settings['apple_pay_domain_set'] && file_exists( $fullpath ) ) {
295
+			if ( ! empty($gateway_settings['apple_pay_domain_set']) && 'yes' === $gateway_settings['apple_pay_domain_set'] && file_exists($fullpath)) {
296 296
 				return;
297 297
 			}
298 298
 
299
-			if ( ! file_exists( $path . '/' . $dir ) ) {
300
-				if ( ! @mkdir( $path . '/' . $dir, 0755 ) ) {
301
-					throw new Exception( __( 'Unable to create domain association folder to domain root.', 'woocommerce-gateway-stripe' ) );
299
+			if ( ! file_exists($path . '/' . $dir)) {
300
+				if ( ! @mkdir($path . '/' . $dir, 0755)) {
301
+					throw new Exception(__('Unable to create domain association folder to domain root.', 'woocommerce-gateway-stripe'));
302 302
 				}
303 303
 			}
304 304
 
305
-			if ( ! file_exists( $fullpath ) ) {
306
-				if ( ! @copy( WC_STRIPE_PLUGIN_PATH . '/' . $file, $fullpath ) ) {
307
-					throw new Exception( __( 'Unable to copy domain association file to domain root.', 'woocommerce-gateway-stripe' ) );
305
+			if ( ! file_exists($fullpath)) {
306
+				if ( ! @copy(WC_STRIPE_PLUGIN_PATH . '/' . $file, $fullpath)) {
307
+					throw new Exception(__('Unable to copy domain association file to domain root.', 'woocommerce-gateway-stripe'));
308 308
 				}
309 309
 			}
310 310
 
311 311
 			// At this point then the domain association folder and file should be available.
312 312
 			// Proceed to verify/and or verify again.
313
-			$this->register_apple_pay_domain( $this->secret_key );
313
+			$this->register_apple_pay_domain($this->secret_key);
314 314
 
315 315
 			// No errors to this point, verification success!
316 316
 			$gateway_settings['apple_pay_domain_set'] = 'yes';
317 317
 			$this->apple_pay_domain_set = true;
318 318
 
319
-			update_option( 'woocommerce_stripe_settings', $gateway_settings );
319
+			update_option('woocommerce_stripe_settings', $gateway_settings);
320 320
 
321
-			WC_Stripe_Logger::log( 'Your domain has been verified with Apple Pay!' );
321
+			WC_Stripe_Logger::log('Your domain has been verified with Apple Pay!');
322 322
 
323
-		} catch ( Exception $e ) {
323
+		} catch (Exception $e) {
324 324
 			$gateway_settings['apple_pay_domain_set'] = 'no';
325 325
 
326
-			update_option( 'woocommerce_stripe_settings', $gateway_settings );
326
+			update_option('woocommerce_stripe_settings', $gateway_settings);
327 327
 
328
-			WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() );
328
+			WC_Stripe_Logger::log('Error: ' . $e->getMessage());
329 329
 		}
330 330
 	}
331 331
 
@@ -333,11 +333,11 @@  discard block
 block discarded – undo
333 333
 	 * Check if SSL is enabled and notify the user
334 334
 	 */
335 335
 	public function admin_notices() {
336
-		if ( 'no' === $this->enabled ) {
336
+		if ('no' === $this->enabled) {
337 337
 			return;
338 338
 		}
339 339
 
340
-		if ( $this->payment_request && ! empty( $this->apple_pay_verify_notice ) ) {
340
+		if ($this->payment_request && ! empty($this->apple_pay_verify_notice)) {
341 341
 			$allowed_html = array(
342 342
 				'a' => array(
343 343
 					'href' => array(),
@@ -345,7 +345,7 @@  discard block
 block discarded – undo
345 345
 				),
346 346
 			);
347 347
 
348
-			echo '<div class="error stripe-apple-pay-message"><p>' . wp_kses( make_clickable( $this->apple_pay_verify_notice ), $allowed_html ) . '</p></div>';
348
+			echo '<div class="error stripe-apple-pay-message"><p>' . wp_kses(make_clickable($this->apple_pay_verify_notice), $allowed_html) . '</p></div>';
349 349
 		}
350 350
 
351 351
 		/**
@@ -353,9 +353,9 @@  discard block
 block discarded – undo
353 353
 		 * when setting screen is displayed. So if domain verification is not set,
354 354
 		 * something went wrong so lets notify user.
355 355
 		 */
356
-		if ( ! empty( $this->secret_key ) && $this->payment_request && ! $this->apple_pay_domain_set ) {
356
+		if ( ! empty($this->secret_key) && $this->payment_request && ! $this->apple_pay_domain_set) {
357 357
 			/* translators: 1) HTML anchor open tag 2) HTML anchor closing tag */
358
-			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>';
358
+			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>';
359 359
 		}
360 360
 	}
361 361
 
@@ -363,7 +363,7 @@  discard block
 block discarded – undo
363 363
 	 * Initialise Gateway Settings Form Fields
364 364
 	 */
365 365
 	public function init_form_fields() {
366
-		$this->form_fields = require( dirname( __FILE__ ) . '/admin/stripe-settings.php' );
366
+		$this->form_fields = require(dirname(__FILE__) . '/admin/stripe-settings.php');
367 367
 	}
368 368
 
369 369
 	/**
@@ -371,59 +371,59 @@  discard block
 block discarded – undo
371 371
 	 */
372 372
 	public function payment_fields() {
373 373
 		$user                 = wp_get_current_user();
374
-		$display_tokenization = $this->supports( 'tokenization' ) && is_checkout() && $this->saved_cards;
374
+		$display_tokenization = $this->supports('tokenization') && is_checkout() && $this->saved_cards;
375 375
 		$total                = WC()->cart->total;
376 376
 		$user_email           = '';
377 377
 
378 378
 		// If paying from order, we need to get total from order not cart.
379
-		if ( isset( $_GET['pay_for_order'] ) && ! empty( $_GET['key'] ) ) {
380
-			$order      = wc_get_order( wc_get_order_id_by_order_key( wc_clean( $_GET['key'] ) ) );
379
+		if (isset($_GET['pay_for_order']) && ! empty($_GET['key'])) {
380
+			$order      = wc_get_order(wc_get_order_id_by_order_key(wc_clean($_GET['key'])));
381 381
 			$total      = $order->get_total();
382 382
 			$user_email = WC_Stripe_Helper::is_pre_30() ? $order->billing_email : $order->get_billing_email();
383 383
 		} else {
384
-			if ( $user->ID ) {
385
-				$user_email = get_user_meta( $user->ID, 'billing_email', true );
384
+			if ($user->ID) {
385
+				$user_email = get_user_meta($user->ID, 'billing_email', true);
386 386
 				$user_email = $user_email ? $user_email : $user->user_email;
387 387
 			}
388 388
 		}
389 389
 
390
-		if ( is_add_payment_method_page() ) {
391
-			$pay_button_text = __( 'Add Card', 'woocommerce-gateway-stripe' );
392
-			$total        = '';
390
+		if (is_add_payment_method_page()) {
391
+			$pay_button_text = __('Add Card', 'woocommerce-gateway-stripe');
392
+			$total = '';
393 393
 		} else {
394 394
 			$pay_button_text = '';
395 395
 		}
396 396
 
397 397
 		echo '<div
398 398
 			id="stripe-payment-data"
399
-			data-panel-label="' . esc_attr( $pay_button_text ) . '"
399
+			data-panel-label="' . esc_attr($pay_button_text) . '"
400 400
 			data-description=""
401
-			data-email="' . esc_attr( $user_email ) . '"
402
-			data-amount="' . esc_attr( WC_Stripe_Helper::get_stripe_amount( $total ) ) . '"
403
-			data-name="' . esc_attr( $this->statement_descriptor ) . '"
404
-			data-currency="' . esc_attr( strtolower( get_woocommerce_currency() ) ) . '"
405
-			data-image="' . esc_attr( $this->stripe_checkout_image ) . '"
406
-			data-bitcoin="' . esc_attr( ( $this->bitcoin && $this->capture ) ? 'true' : 'false' ) . '"
407
-			data-locale="' . esc_attr( apply_filters( 'wc_stripe_checkout_locale', substr( get_locale(), 0, 2 ) ) ) . '"
408
-			data-three-d-secure="' . esc_attr( $this->three_d_secure ? 'true' : 'false' ) . '"
409
-			data-allow-remember-me="' . esc_attr( $this->saved_cards ? 'true' : 'false' ) . '">';
410
-
411
-		if ( $this->description ) {
412
-			if ( $this->testmode ) {
401
+			data-email="' . esc_attr($user_email) . '"
402
+			data-amount="' . esc_attr(WC_Stripe_Helper::get_stripe_amount($total)) . '"
403
+			data-name="' . esc_attr($this->statement_descriptor) . '"
404
+			data-currency="' . esc_attr(strtolower(get_woocommerce_currency())) . '"
405
+			data-image="' . esc_attr($this->stripe_checkout_image) . '"
406
+			data-bitcoin="' . esc_attr(($this->bitcoin && $this->capture) ? 'true' : 'false') . '"
407
+			data-locale="' . esc_attr(apply_filters('wc_stripe_checkout_locale', substr(get_locale(), 0, 2))) . '"
408
+			data-three-d-secure="' . esc_attr($this->three_d_secure ? 'true' : 'false') . '"
409
+			data-allow-remember-me="' . esc_attr($this->saved_cards ? 'true' : 'false') . '">';
410
+
411
+		if ($this->description) {
412
+			if ($this->testmode) {
413 413
 				/* translators: link to Stripe testing page */
414
-				$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' );
415
-				$this->description  = trim( $this->description );
414
+				$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');
415
+				$this->description  = trim($this->description);
416 416
 			}
417
-			echo apply_filters( 'wc_stripe_description', wpautop( wp_kses_post( $this->description ) ) );
417
+			echo apply_filters('wc_stripe_description', wpautop(wp_kses_post($this->description)));
418 418
 		}
419 419
 
420
-		if ( $display_tokenization ) {
420
+		if ($display_tokenization) {
421 421
 			$this->tokenization_script();
422 422
 			$this->saved_payment_methods();
423 423
 		}
424 424
 
425
-		if ( ! $this->stripe_checkout ) {
426
-			if ( apply_filters( 'wc_stripe_use_elements_checkout_form', true ) ) {
425
+		if ( ! $this->stripe_checkout) {
426
+			if (apply_filters('wc_stripe_use_elements_checkout_form', true)) {
427 427
 				$this->elements_form();
428 428
 			} else {
429 429
 				$this->form();
@@ -431,7 +431,7 @@  discard block
 block discarded – undo
431 431
 			}
432 432
 		}
433 433
 
434
-		if ( apply_filters( 'wc_stripe_display_save_payment_method_checkbox', $display_tokenization ) && ! is_add_payment_method_page() && ! isset( $_GET['change_payment_method'] ) ) {
434
+		if (apply_filters('wc_stripe_display_save_payment_method_checkbox', $display_tokenization) && ! is_add_payment_method_page() && ! isset($_GET['change_payment_method'])) {
435 435
 			$this->save_payment_method_checkbox();
436 436
 		}
437 437
 
@@ -446,12 +446,12 @@  discard block
 block discarded – undo
446 446
 	 */
447 447
 	public function elements_form() {
448 448
 		?>
449
-		<fieldset id="wc-<?php echo esc_attr( $this->id ); ?>-cc-form" class="wc-credit-card-form wc-payment-form" style="background:transparent;">
450
-			<?php do_action( 'woocommerce_credit_card_form_start', $this->id ); ?>
449
+		<fieldset id="wc-<?php echo esc_attr($this->id); ?>-cc-form" class="wc-credit-card-form wc-payment-form" style="background:transparent;">
450
+			<?php do_action('woocommerce_credit_card_form_start', $this->id); ?>
451 451
 
452
-			<?php if ( $this->inline_cc_form ) { ?>
452
+			<?php if ($this->inline_cc_form) { ?>
453 453
 				<label for="card-element">
454
-					<?php esc_html_e( 'Credit or debit card', 'woocommerce-gateway-stripe' ); ?>
454
+					<?php esc_html_e('Credit or debit card', 'woocommerce-gateway-stripe'); ?>
455 455
 				</label>
456 456
 
457 457
 				<div id="stripe-card-element" style="background:#fff;padding:0 1em;border:1px solid #ddd;margin:5px 0;padding:10px 5px;">
@@ -459,7 +459,7 @@  discard block
 block discarded – undo
459 459
 				</div>
460 460
 			<?php } else { ?>
461 461
 				<div class="form-row form-row-wide">
462
-					<label><?php _e( 'Card Number', 'woocommerce-gateway-stripe' ); ?> <span class="required">*</span></label>
462
+					<label><?php _e('Card Number', 'woocommerce-gateway-stripe'); ?> <span class="required">*</span></label>
463 463
 
464 464
 					<div id="stripe-card-element" style="background:#fff;padding:0 1em;border:1px solid #ddd;margin:5px 0;padding:10px 5px;">
465 465
 					<!-- a Stripe Element will be inserted here. -->
@@ -467,7 +467,7 @@  discard block
 block discarded – undo
467 467
 				</div>
468 468
 
469 469
 				<div class="form-row form-row-first">
470
-					<label><?php _e( 'Expiry Date', 'woocommerce-gateway-stripe' ); ?> <span class="required">*</span></label>
470
+					<label><?php _e('Expiry Date', 'woocommerce-gateway-stripe'); ?> <span class="required">*</span></label>
471 471
 
472 472
 					<div id="stripe-exp-element" style="background:#fff;padding:0 1em;border:1px solid #ddd;margin:5px 0;padding:10px 5px;">
473 473
 					<!-- a Stripe Element will be inserted here. -->
@@ -475,7 +475,7 @@  discard block
 block discarded – undo
475 475
 				</div>
476 476
 
477 477
 				<div class="form-row form-row-last">
478
-					<label><?php _e( 'Card Code (CVC)', 'woocommerce-gateway-stripe' ); ?> <span class="required">*</span></label>
478
+					<label><?php _e('Card Code (CVC)', 'woocommerce-gateway-stripe'); ?> <span class="required">*</span></label>
479 479
 				<div id="stripe-cvc-element" style="background:#fff;padding:0 1em;border:1px solid #ddd;margin:5px 0;padding:10px 5px;">
480 480
 				<!-- a Stripe Element will be inserted here. -->
481 481
 				</div>
@@ -485,7 +485,7 @@  discard block
 block discarded – undo
485 485
 
486 486
 			<!-- Used to display form errors -->
487 487
 			<div class="stripe-source-errors" role="alert"></div>
488
-			<?php do_action( 'woocommerce_credit_card_form_end', $this->id ); ?>
488
+			<?php do_action('woocommerce_credit_card_form_end', $this->id); ?>
489 489
 			<div class="clear"></div>
490 490
 		</fieldset>
491 491
 		<?php
@@ -498,13 +498,13 @@  discard block
 block discarded – undo
498 498
 	 * @version 3.1.0
499 499
 	 */
500 500
 	public function admin_scripts() {
501
-		if ( 'woocommerce_page_wc-settings' !== get_current_screen()->id ) {
501
+		if ('woocommerce_page_wc-settings' !== get_current_screen()->id) {
502 502
 			return;
503 503
 		}
504 504
 
505
-		$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
505
+		$suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';
506 506
 
507
-		wp_enqueue_script( 'woocommerce_stripe_admin', plugins_url( 'assets/js/stripe-admin' . $suffix . '.js', WC_STRIPE_MAIN_FILE ), array(), WC_STRIPE_VERSION, true );
507
+		wp_enqueue_script('woocommerce_stripe_admin', plugins_url('assets/js/stripe-admin' . $suffix . '.js', WC_STRIPE_MAIN_FILE), array(), WC_STRIPE_VERSION, true);
508 508
 	}
509 509
 
510 510
 	/**
@@ -516,29 +516,29 @@  discard block
 block discarded – undo
516 516
 	 * @version 4.0.0
517 517
 	 */
518 518
 	public function payment_scripts() {
519
-		if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) && ! is_add_payment_method_page() && ! isset( $_GET['change_payment_method'] ) ) {
519
+		if ( ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order']) && ! is_add_payment_method_page() && ! isset($_GET['change_payment_method'])) {
520 520
 			return;
521 521
 		}
522 522
 
523
-		$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
523
+		$suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';
524 524
 
525
-		wp_register_style( 'stripe_paymentfonts', plugins_url( 'assets/css/stripe-paymentfonts.css', WC_STRIPE_MAIN_FILE ), array(), '1.2.5' );
526
-		wp_enqueue_style( 'stripe_paymentfonts' );
527
-		wp_register_script( 'stripe_checkout', 'https://checkout.stripe.com/checkout.js', '', WC_STRIPE_VERSION, true );
528
-		wp_register_script( 'stripev2', 'https://js.stripe.com/v2/', '', '2.0', true );
529
-		wp_register_script( 'stripe', 'https://js.stripe.com/v3/', '', '3.0', true );
530
-		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 );
525
+		wp_register_style('stripe_paymentfonts', plugins_url('assets/css/stripe-paymentfonts.css', WC_STRIPE_MAIN_FILE), array(), '1.2.5');
526
+		wp_enqueue_style('stripe_paymentfonts');
527
+		wp_register_script('stripe_checkout', 'https://checkout.stripe.com/checkout.js', '', WC_STRIPE_VERSION, true);
528
+		wp_register_script('stripev2', 'https://js.stripe.com/v2/', '', '2.0', true);
529
+		wp_register_script('stripe', 'https://js.stripe.com/v3/', '', '3.0', true);
530
+		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);
531 531
 
532 532
 		$stripe_params = array(
533 533
 			'key'                  => $this->publishable_key,
534
-			'i18n_terms'           => __( 'Please accept the terms and conditions first', 'woocommerce-gateway-stripe' ),
535
-			'i18n_required_fields' => __( 'Please fill in required checkout fields first', 'woocommerce-gateway-stripe' ),
534
+			'i18n_terms'           => __('Please accept the terms and conditions first', 'woocommerce-gateway-stripe'),
535
+			'i18n_required_fields' => __('Please fill in required checkout fields first', 'woocommerce-gateway-stripe'),
536 536
 		);
537 537
 
538 538
 		// If we're on the pay page we need to pass stripe.js the address of the order.
539
-		if ( isset( $_GET['pay_for_order'] ) && 'true' === $_GET['pay_for_order'] ) {
540
-			$order_id = wc_get_order_id_by_order_key( urldecode( $_GET['key'] ) );
541
-			$order    = wc_get_order( $order_id );
539
+		if (isset($_GET['pay_for_order']) && 'true' === $_GET['pay_for_order']) {
540
+			$order_id = wc_get_order_id_by_order_key(urldecode($_GET['key']));
541
+			$order    = wc_get_order($order_id);
542 542
 
543 543
 			$stripe_params['billing_first_name'] = WC_Stripe_Helper::is_pre_30() ? $order->billing_first_name : $order->get_billing_first_name();
544 544
 			$stripe_params['billing_last_name']  = WC_Stripe_Helper::is_pre_30() ? $order->billing_last_name : $order->get_billing_last_name();
@@ -550,38 +550,38 @@  discard block
 block discarded – undo
550 550
 			$stripe_params['billing_country']    = WC_Stripe_Helper::is_pre_30() ? $order->billing_country : $order->get_billing_country();
551 551
 		}
552 552
 
553
-		$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' );
554
-		$stripe_params['no_sepa_owner_msg']                       = __( 'Please enter your IBAN account name.', 'woocommerce-gateway-stripe' );
555
-		$stripe_params['no_sepa_iban_msg']                        = __( 'Please enter your IBAN account number.', 'woocommerce-gateway-stripe' );
556
-		$stripe_params['sepa_mandate_notification']               = apply_filters( 'wc_stripe_sepa_mandate_notification', 'email' );
557
-		$stripe_params['allow_prepaid_card']                      = apply_filters( 'wc_stripe_allow_prepaid_card', true ) ? 'yes' : 'no';
553
+		$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');
554
+		$stripe_params['no_sepa_owner_msg']                       = __('Please enter your IBAN account name.', 'woocommerce-gateway-stripe');
555
+		$stripe_params['no_sepa_iban_msg']                        = __('Please enter your IBAN account number.', 'woocommerce-gateway-stripe');
556
+		$stripe_params['sepa_mandate_notification']               = apply_filters('wc_stripe_sepa_mandate_notification', 'email');
557
+		$stripe_params['allow_prepaid_card']                      = apply_filters('wc_stripe_allow_prepaid_card', true) ? 'yes' : 'no';
558 558
 		$stripe_params['inline_cc_form']                          = $this->inline_cc_form ? 'yes' : 'no';
559
-		$stripe_params['stripe_checkout_require_billing_address'] = apply_filters( 'wc_stripe_checkout_require_billing_address', false ) ? 'yes' : 'no';
560
-		$stripe_params['is_checkout']                             = ( is_checkout() && empty( $_GET['pay_for_order'] ) );
559
+		$stripe_params['stripe_checkout_require_billing_address'] = apply_filters('wc_stripe_checkout_require_billing_address', false) ? 'yes' : 'no';
560
+		$stripe_params['is_checkout']                             = (is_checkout() && empty($_GET['pay_for_order']));
561 561
 		$stripe_params['return_url']                              = $this->get_stripe_return_url();
562
-		$stripe_params['ajaxurl']                                 = WC_AJAX::get_endpoint( '%%endpoint%%' );
563
-		$stripe_params['stripe_nonce']                            = wp_create_nonce( '_wc_stripe_nonce' );
562
+		$stripe_params['ajaxurl']                                 = WC_AJAX::get_endpoint('%%endpoint%%');
563
+		$stripe_params['stripe_nonce']                            = wp_create_nonce('_wc_stripe_nonce');
564 564
 		$stripe_params['statement_descriptor']                    = $this->statement_descriptor;
565
-		$stripe_params['use_elements']                            = apply_filters( 'wc_stripe_use_elements_checkout_form', true ) ? 'yes' : 'no';
566
-		$stripe_params['elements_options']                        = apply_filters( 'wc_stripe_elements_options', array() );
565
+		$stripe_params['use_elements']                            = apply_filters('wc_stripe_use_elements_checkout_form', true) ? 'yes' : 'no';
566
+		$stripe_params['elements_options']                        = apply_filters('wc_stripe_elements_options', array());
567 567
 		$stripe_params['is_stripe_checkout']                      = $this->stripe_checkout ? 'yes' : 'no';
568
-		$stripe_params['is_change_payment_page']                  = ( isset( $_GET['pay_for_order'] ) || isset( $_GET['change_payment_method'] ) ) ? 'yes' : 'no';
568
+		$stripe_params['is_change_payment_page']                  = (isset($_GET['pay_for_order']) || isset($_GET['change_payment_method'])) ? 'yes' : 'no';
569 569
 		$stripe_params['is_add_payment_method_page']              = is_add_payment_method_page() ? 'yes' : 'no';
570
-		$stripe_params['elements_styling']                        = apply_filters( 'wc_stripe_elements_styling', false );
571
-		$stripe_params['elements_classes']                        = apply_filters( 'wc_stripe_elements_classes', false );
570
+		$stripe_params['elements_styling']                        = apply_filters('wc_stripe_elements_styling', false);
571
+		$stripe_params['elements_classes']                        = apply_filters('wc_stripe_elements_classes', false);
572 572
 
573 573
 		// merge localized messages to be use in JS
574
-		$stripe_params = array_merge( $stripe_params, WC_Stripe_Helper::get_localized_messages() );
574
+		$stripe_params = array_merge($stripe_params, WC_Stripe_Helper::get_localized_messages());
575 575
 
576
-		wp_localize_script( 'woocommerce_stripe', 'wc_stripe_params', apply_filters( 'wc_stripe_params', $stripe_params ) );
577
-		wp_localize_script( 'woocommerce_stripe_checkout', 'wc_stripe_params', apply_filters( 'wc_stripe_params', $stripe_params ) );
576
+		wp_localize_script('woocommerce_stripe', 'wc_stripe_params', apply_filters('wc_stripe_params', $stripe_params));
577
+		wp_localize_script('woocommerce_stripe_checkout', 'wc_stripe_params', apply_filters('wc_stripe_params', $stripe_params));
578 578
 
579
-		if ( $this->stripe_checkout ) {
580
-			wp_enqueue_script( 'stripe_checkout' );
579
+		if ($this->stripe_checkout) {
580
+			wp_enqueue_script('stripe_checkout');
581 581
 		}
582 582
 
583 583
 		$this->tokenization_script();
584
-		wp_enqueue_script( 'woocommerce_stripe' );
584
+		wp_enqueue_script('woocommerce_stripe');
585 585
 	}
586 586
 
587 587
 	/**
@@ -597,44 +597,44 @@  discard block
 block discarded – undo
597 597
 	 *
598 598
 	 * @return array|void
599 599
 	 */
600
-	public function process_payment( $order_id, $retry = true, $force_save_source = false ) {
600
+	public function process_payment($order_id, $retry = true, $force_save_source = false) {
601 601
 		try {
602
-			$order = wc_get_order( $order_id );
602
+			$order = wc_get_order($order_id);
603 603
 
604 604
 			// This comes from the create account checkbox in the checkout page.
605
-			$create_account = ! empty( $_POST['createaccount'] ) ? true : false;
605
+			$create_account = ! empty($_POST['createaccount']) ? true : false;
606 606
 
607
-			if ( $create_account ) {
607
+			if ($create_account) {
608 608
 				$new_customer_id     = WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id();
609
-				$new_stripe_customer = new WC_Stripe_Customer( $new_customer_id );
609
+				$new_stripe_customer = new WC_Stripe_Customer($new_customer_id);
610 610
 				$new_stripe_customer->create_customer();
611 611
 			}
612 612
 
613 613
 			$source_object   = $this->get_source_object();
614
-			$prepared_source = $this->prepare_source( $source_object, get_current_user_id(), $force_save_source );
614
+			$prepared_source = $this->prepare_source($source_object, get_current_user_id(), $force_save_source);
615 615
 
616 616
 			// Check if we don't allow prepaid credit cards.
617
-			if ( ! apply_filters( 'wc_stripe_allow_prepaid_card', true ) ) {
618
-				if ( $source_object && 'token' === $source_object->object && 'prepaid' === $source_object->card->funding ) {
619
-					$localized_message = __( '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' );
620
-					throw new WC_Stripe_Exception( print_r( $source_object, true ), $localized_message );
617
+			if ( ! apply_filters('wc_stripe_allow_prepaid_card', true)) {
618
+				if ($source_object && 'token' === $source_object->object && 'prepaid' === $source_object->card->funding) {
619
+					$localized_message = __('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');
620
+					throw new WC_Stripe_Exception(print_r($source_object, true), $localized_message);
621 621
 				}
622 622
 			}
623 623
 
624
-			if ( empty( $prepared_source->source ) ) {
625
-				$localized_message = __( 'Payment processing failed. Please retry.', 'woocommerce-gateway-stripe' );
626
-				throw new WC_Stripe_Exception( print_r( $prepared_source, true ), $localized_message );
624
+			if (empty($prepared_source->source)) {
625
+				$localized_message = __('Payment processing failed. Please retry.', 'woocommerce-gateway-stripe');
626
+				throw new WC_Stripe_Exception(print_r($prepared_source, true), $localized_message);
627 627
 			}
628 628
 
629 629
 			// Store source to order meta.
630
-			$this->save_source( $order, $prepared_source );
630
+			$this->save_source($order, $prepared_source);
631 631
 
632 632
 			// Result from Stripe API request.
633 633
 			$response = null;
634 634
 
635
-			if ( $order->get_total() > 0 ) {
635
+			if ($order->get_total() > 0) {
636 636
 				// This will throw exception if not valid.
637
-				$this->validate_minimum_order_amount( $order );
637
+				$this->validate_minimum_order_amount($order);
638 638
 
639 639
 				/*
640 640
 				 * Check if card 3DS is required or optional with 3DS setting.
@@ -643,89 +643,89 @@  discard block
 block discarded – undo
643 643
 				 * Note that if we need to save source, the original source must be first
644 644
 				 * attached to a customer in Stripe before it can be charged.
645 645
 				 */
646
-				if ( $this->is_3ds_required( $source_object ) ) {
647
-					$response = $this->create_3ds_source( $order, $source_object );
646
+				if ($this->is_3ds_required($source_object)) {
647
+					$response = $this->create_3ds_source($order, $source_object);
648 648
 
649
-					if ( ! empty( $response->error ) ) {
649
+					if ( ! empty($response->error)) {
650 650
 						$localized_message = $response->error->message;
651 651
 
652
-						$order->add_order_note( $localized_message );
652
+						$order->add_order_note($localized_message);
653 653
 
654
-						throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message );
654
+						throw new WC_Stripe_Exception(print_r($response, true), $localized_message);
655 655
 					}
656 656
 
657 657
 					// Update order meta with 3DS source.
658
-					if ( WC_Stripe_Helper::is_pre_30() ) {
659
-						update_post_meta( $order_id, '_stripe_source_id', $response->id );
658
+					if (WC_Stripe_Helper::is_pre_30()) {
659
+						update_post_meta($order_id, '_stripe_source_id', $response->id);
660 660
 					} else {
661
-						$order->update_meta_data( '_stripe_source_id', $response->id );
661
+						$order->update_meta_data('_stripe_source_id', $response->id);
662 662
 						$order->save();
663 663
 					}
664 664
 
665
-					WC_Stripe_Logger::log( 'Info: Redirecting to 3DS...' );
665
+					WC_Stripe_Logger::log('Info: Redirecting to 3DS...');
666 666
 
667 667
 					return array(
668 668
 						'result'   => 'success',
669
-						'redirect' => esc_url_raw( $response->redirect->url ),
669
+						'redirect' => esc_url_raw($response->redirect->url),
670 670
 					);
671 671
 				}
672 672
 
673
-				WC_Stripe_Logger::log( "Info: Begin processing payment for order $order_id for the amount of {$order->get_total()}" );
673
+				WC_Stripe_Logger::log("Info: Begin processing payment for order $order_id for the amount of {$order->get_total()}");
674 674
 
675 675
 				// Make the request.
676
-				$response = WC_Stripe_API::request( $this->generate_payment_request( $order, $prepared_source ) );
676
+				$response = WC_Stripe_API::request($this->generate_payment_request($order, $prepared_source));
677 677
 
678
-				if ( ! empty( $response->error ) ) {
678
+				if ( ! empty($response->error)) {
679 679
 					// If it is an API error such connection or server, let's retry.
680
-					if ( 'api_connection_error' === $response->error->type || 'api_error' === $response->error->type ) {
681
-						if ( $retry ) {
682
-							sleep( 5 );
683
-							return $this->process_payment( $order_id, false, $force_save_source );
680
+					if ('api_connection_error' === $response->error->type || 'api_error' === $response->error->type) {
681
+						if ($retry) {
682
+							sleep(5);
683
+							return $this->process_payment($order_id, false, $force_save_source);
684 684
 						} else {
685 685
 							$localized_message = 'API connection error and retries exhausted.';
686
-							$order->add_order_note( $localized_message );
687
-							throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message );
686
+							$order->add_order_note($localized_message);
687
+							throw new WC_Stripe_Exception(print_r($response, true), $localized_message);
688 688
 						}
689 689
 					}
690 690
 
691 691
 					// Customer param wrong? The user may have been deleted on stripe's end. Remove customer_id. Can be retried without.
692
-					if ( preg_match( '/No such customer/i', $response->error->message ) && $retry ) {
693
-						if ( WC_Stripe_Helper::is_pre_30() ) {
694
-							delete_user_meta( $order->customer_user, '_stripe_customer_id' );
695
-							delete_post_meta( $order_id, '_stripe_customer_id' );
692
+					if (preg_match('/No such customer/i', $response->error->message) && $retry) {
693
+						if (WC_Stripe_Helper::is_pre_30()) {
694
+							delete_user_meta($order->customer_user, '_stripe_customer_id');
695
+							delete_post_meta($order_id, '_stripe_customer_id');
696 696
 						} else {
697
-							delete_user_meta( $order->get_customer_id(), '_stripe_customer_id' );
698
-							$order->delete_meta_data( '_stripe_customer_id' );
697
+							delete_user_meta($order->get_customer_id(), '_stripe_customer_id');
698
+							$order->delete_meta_data('_stripe_customer_id');
699 699
 							$order->save();
700 700
 						}
701 701
 
702
-						return $this->process_payment( $order_id, false, $force_save_source );
703
-					} elseif ( preg_match( '/No such token/i', $response->error->message ) && $prepared_source->token_id ) {
702
+						return $this->process_payment($order_id, false, $force_save_source);
703
+					} elseif (preg_match('/No such token/i', $response->error->message) && $prepared_source->token_id) {
704 704
 						// Source param wrong? The CARD may have been deleted on stripe's end. Remove token and show message.
705
-						$wc_token = WC_Payment_Tokens::get( $prepared_source->token_id );
705
+						$wc_token = WC_Payment_Tokens::get($prepared_source->token_id);
706 706
 						$wc_token->delete();
707
-						$localized_message = __( 'This card is no longer available and has been removed.', 'woocommerce-gateway-stripe' );
708
-						$order->add_order_note( $localized_message );
709
-						throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message );
707
+						$localized_message = __('This card is no longer available and has been removed.', 'woocommerce-gateway-stripe');
708
+						$order->add_order_note($localized_message);
709
+						throw new WC_Stripe_Exception(print_r($response, true), $localized_message);
710 710
 					}
711 711
 
712 712
 					$localized_messages = WC_Stripe_Helper::get_localized_messages();
713 713
 
714
-					if ( 'card_error' === $response->error->type ) {
715
-						$localized_message = isset( $localized_messages[ $response->error->code ] ) ? $localized_messages[ $response->error->code ] : $response->error->message;
714
+					if ('card_error' === $response->error->type) {
715
+						$localized_message = isset($localized_messages[$response->error->code]) ? $localized_messages[$response->error->code] : $response->error->message;
716 716
 					} else {
717
-						$localized_message = isset( $localized_messages[ $response->error->type ] ) ? $localized_messages[ $response->error->type ] : $response->error->message;
717
+						$localized_message = isset($localized_messages[$response->error->type]) ? $localized_messages[$response->error->type] : $response->error->message;
718 718
 					}
719 719
 
720
-					$order->add_order_note( $localized_message );
720
+					$order->add_order_note($localized_message);
721 721
 
722
-					throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message );
722
+					throw new WC_Stripe_Exception(print_r($response, true), $localized_message);
723 723
 				}
724 724
 
725
-				do_action( 'wc_gateway_stripe_process_payment', $response, $order );
725
+				do_action('wc_gateway_stripe_process_payment', $response, $order);
726 726
 
727 727
 				// Process valid response.
728
-				$this->process_response( $response, $order );
728
+				$this->process_response($response, $order);
729 729
 			} else {
730 730
 				$order->payment_complete();
731 731
 			}
@@ -736,17 +736,17 @@  discard block
 block discarded – undo
736 736
 			// Return thank you page redirect.
737 737
 			return array(
738 738
 				'result'   => 'success',
739
-				'redirect' => $this->get_return_url( $order ),
739
+				'redirect' => $this->get_return_url($order),
740 740
 			);
741 741
 
742
-		} catch ( WC_Stripe_Exception $e ) {
743
-			wc_add_notice( $e->getLocalizedMessage(), 'error' );
744
-			WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() );
742
+		} catch (WC_Stripe_Exception $e) {
743
+			wc_add_notice($e->getLocalizedMessage(), 'error');
744
+			WC_Stripe_Logger::log('Error: ' . $e->getMessage());
745 745
 
746
-			do_action( 'wc_gateway_stripe_process_payment_error', $e, $order );
746
+			do_action('wc_gateway_stripe_process_payment_error', $e, $order);
747 747
 
748
-			if ( $order->has_status( array( 'pending', 'failed' ) ) ) {
749
-				$this->send_failed_order_email( $order_id );
748
+			if ($order->has_status(array('pending', 'failed'))) {
749
+				$this->send_failed_order_email($order_id);
750 750
 			}
751 751
 
752 752
 			return array(
Please login to merge, or discard this patch.
includes/compat/class-wc-stripe-sepa-compat.php 1 patch
Spacing   +166 added lines, -166 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
 	}
@@ -182,61 +182,61 @@  discard block
 block discarded – undo
182 182
 	 * @param string $stripe_token (default: '')
183 183
 	 * @param  bool initial_payment
184 184
 	 */
185
-	public function retry_subscription_payment( $order = '', $amount = 0 ) {
186
-		if ( $amount * 100 < WC_Stripe_Helper::get_minimum_amount() ) {
185
+	public function retry_subscription_payment($order = '', $amount = 0) {
186
+		if ($amount * 100 < WC_Stripe_Helper::get_minimum_amount()) {
187 187
 			/* translators: minimum amount */
188
-			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 ) ) );
188
+			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)));
189 189
 		}
190 190
 
191 191
 		$customer_id = WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id();
192 192
 		$order_id    = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
193 193
 
194 194
 		// Get source from order
195
-		$prepared_source = $this->prepare_order_source( $order );
195
+		$prepared_source = $this->prepare_order_source($order);
196 196
 
197 197
 		// Or fail :(
198
-		if ( ! $prepared_source->customer ) {
199
-			return new WP_Error( 'stripe_error', __( 'Customer not found', 'woocommerce-gateway-stripe' ) );
198
+		if ( ! $prepared_source->customer) {
199
+			return new WP_Error('stripe_error', __('Customer not found', 'woocommerce-gateway-stripe'));
200 200
 		}
201 201
 
202 202
 		// Passing empty source with charge customer default.
203 203
 		$prepared_source->source = '';
204 204
 
205
-		WC_Stripe_Logger::log( "Info: Begin processing subscription payment for order {$order_id} for the amount of {$amount}" );
205
+		WC_Stripe_Logger::log("Info: Begin processing subscription payment for order {$order_id} for the amount of {$amount}");
206 206
 
207 207
 		// Make the request
208
-		$request             = $this->generate_payment_request( $order, $prepared_source );
208
+		$request             = $this->generate_payment_request($order, $prepared_source);
209 209
 		$request['capture']  = 'true';
210
-		$request['amount']   = WC_Stripe_Helper::get_stripe_amount( $amount, $request['currency'] );
211
-		$response            = WC_Stripe_API::request( $request );
210
+		$request['amount']   = WC_Stripe_Helper::get_stripe_amount($amount, $request['currency']);
211
+		$response            = WC_Stripe_API::request($request);
212 212
 
213
-		if ( ! empty( $response->error ) || is_wp_error( $response ) ) {
213
+		if ( ! empty($response->error) || is_wp_error($response)) {
214 214
 			/* translators: error message */
215
-			$renewal_order->update_status( 'failed', sprintf( __( 'Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe' ), $response->error->message ) );
215
+			$renewal_order->update_status('failed', sprintf(__('Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe'), $response->error->message));
216 216
 		}
217 217
 
218
-		$this->process_response( $response, $order );
218
+		$this->process_response($response, $order);
219 219
 	}
220 220
 
221 221
 	/**
222 222
 	 * Don't transfer Stripe customer/token meta to resubscribe orders.
223 223
 	 * @param int $resubscribe_order The order created for the customer to resubscribe to the old expired/cancelled subscription
224 224
 	 */
225
-	public function delete_resubscribe_meta( $resubscribe_order ) {
226
-		delete_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id() ), '_stripe_customer_id' );
227
-		delete_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id() ), '_stripe_source_id' );
225
+	public function delete_resubscribe_meta($resubscribe_order) {
226
+		delete_post_meta((WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id()), '_stripe_customer_id');
227
+		delete_post_meta((WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id()), '_stripe_source_id');
228 228
 		// For BW compat will remove in future
229
-		delete_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id() ), '_stripe_card_id' );
230
-		$this->delete_renewal_meta( $resubscribe_order );
229
+		delete_post_meta((WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id()), '_stripe_card_id');
230
+		$this->delete_renewal_meta($resubscribe_order);
231 231
 	}
232 232
 
233 233
 	/**
234 234
 	 * Don't transfer Stripe fee/ID meta to renewal orders.
235 235
 	 * @param int $resubscribe_order The order created for the customer to resubscribe to the old expired/cancelled subscription
236 236
 	 */
237
-	public function delete_renewal_meta( $renewal_order ) {
238
-		delete_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $renewal_order->id : $renewal_order->get_id() ), 'Stripe Fee' );
239
-		delete_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $renewal_order->id : $renewal_order->get_id() ), 'Net Revenue From Stripe' );
237
+	public function delete_renewal_meta($renewal_order) {
238
+		delete_post_meta((WC_Stripe_Helper::is_pre_30() ? $renewal_order->id : $renewal_order->get_id()), 'Stripe Fee');
239
+		delete_post_meta((WC_Stripe_Helper::is_pre_30() ? $renewal_order->id : $renewal_order->get_id()), 'Net Revenue From Stripe');
240 240
 		return $renewal_order;
241 241
 	}
242 242
 
@@ -246,21 +246,21 @@  discard block
 block discarded – undo
246 246
 	 * @param $amount_to_charge float The amount to charge.
247 247
 	 * @param $renewal_order WC_Order A WC_Order object created to record the renewal payment.
248 248
 	 */
249
-	public function scheduled_subscription_payment( $amount_to_charge, $renewal_order ) {
250
-		$response = $this->process_subscription_payment( $renewal_order, $amount_to_charge );
249
+	public function scheduled_subscription_payment($amount_to_charge, $renewal_order) {
250
+		$response = $this->process_subscription_payment($renewal_order, $amount_to_charge);
251 251
 
252
-		if ( is_wp_error( $response ) ) {
252
+		if (is_wp_error($response)) {
253 253
 			/* translators: error message */
254
-			$renewal_order->update_status( 'failed', sprintf( __( 'Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe' ), $response->get_error_message() ) );
254
+			$renewal_order->update_status('failed', sprintf(__('Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe'), $response->get_error_message()));
255 255
 		}
256 256
 
257
-		if ( ! empty( $response->error ) ) {
257
+		if ( ! empty($response->error)) {
258 258
 			// This is a very generic error to listen for but worth a retry before total fail.
259
-			if ( isset( $response->error->type ) && 'invalid_request_error' === $response->error->type && apply_filters( 'wc_stripe_use_default_customer_source', true ) ) {
260
-				$this->retry_subscription_payment( $renewal_order, $amount_to_charge );
259
+			if (isset($response->error->type) && 'invalid_request_error' === $response->error->type && apply_filters('wc_stripe_use_default_customer_source', true)) {
260
+				$this->retry_subscription_payment($renewal_order, $amount_to_charge);
261 261
 			} else {
262 262
 				/* translators: error message */
263
-				$renewal_order->update_status( 'failed', sprintf( __( 'Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe' ), $response->error->message ) );
263
+				$renewal_order->update_status('failed', sprintf(__('Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe'), $response->error->message));
264 264
 			}
265 265
 		}
266 266
 	}
@@ -269,20 +269,20 @@  discard block
 block discarded – undo
269 269
 	 * Remove order meta
270 270
 	 * @param  object $order
271 271
 	 */
272
-	public function remove_order_source_before_retry( $order ) {
272
+	public function remove_order_source_before_retry($order) {
273 273
 		$order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
274
-		delete_post_meta( $order_id, '_stripe_source_id' );
274
+		delete_post_meta($order_id, '_stripe_source_id');
275 275
 		// For BW compat will remove in the future.
276
-		delete_post_meta( $order_id, '_stripe_card_id' );
276
+		delete_post_meta($order_id, '_stripe_card_id');
277 277
 	}
278 278
 
279 279
 	/**
280 280
 	 * Remove order meta
281 281
 	 * @param  object $order
282 282
 	 */
283
-	public function remove_order_customer_before_retry( $order ) {
283
+	public function remove_order_customer_before_retry($order) {
284 284
 		$order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
285
-		delete_post_meta( $order_id, '_stripe_customer_id' );
285
+		delete_post_meta($order_id, '_stripe_customer_id');
286 286
 	}
287 287
 
288 288
 	/**
@@ -294,14 +294,14 @@  discard block
 block discarded – undo
294 294
 	 * @param WC_Order $renewal_order The order which recorded the successful payment (to make up for the failed automatic payment).
295 295
 	 * @return void
296 296
 	 */
297
-	public function update_failing_payment_method( $subscription, $renewal_order ) {
298
-		if ( WC_Stripe_Helper::is_pre_30() ) {
299
-			update_post_meta( $subscription->id, '_stripe_customer_id', $renewal_order->stripe_customer_id );
300
-			update_post_meta( $subscription->id, '_stripe_source_id', $renewal_order->stripe_source_id );
297
+	public function update_failing_payment_method($subscription, $renewal_order) {
298
+		if (WC_Stripe_Helper::is_pre_30()) {
299
+			update_post_meta($subscription->id, '_stripe_customer_id', $renewal_order->stripe_customer_id);
300
+			update_post_meta($subscription->id, '_stripe_source_id', $renewal_order->stripe_source_id);
301 301
 
302 302
 		} else {
303
-			update_post_meta( $subscription->get_id(), '_stripe_customer_id', $renewal_order->get_meta( '_stripe_customer_id', true ) );
304
-			update_post_meta( $subscription->get_id(), '_stripe_source_id', $renewal_order->get_meta( '_stripe_source_id', true ) );
303
+			update_post_meta($subscription->get_id(), '_stripe_customer_id', $renewal_order->get_meta('_stripe_customer_id', true));
304
+			update_post_meta($subscription->get_id(), '_stripe_source_id', $renewal_order->get_meta('_stripe_source_id', true));
305 305
 		}
306 306
 	}
307 307
 
@@ -314,21 +314,21 @@  discard block
 block discarded – undo
314 314
 	 * @param WC_Subscription $subscription An instance of a subscription object
315 315
 	 * @return array
316 316
 	 */
317
-	public function add_subscription_payment_meta( $payment_meta, $subscription ) {
318
-		$source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_source_id', true );
317
+	public function add_subscription_payment_meta($payment_meta, $subscription) {
318
+		$source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_source_id', true);
319 319
 
320 320
 		// For BW compat will remove in future.
321
-		if ( empty( $source_id ) ) {
322
-			$source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_card_id', true );
321
+		if (empty($source_id)) {
322
+			$source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_card_id', true);
323 323
 
324 324
 			// Take this opportunity to update the key name.
325
-			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 );
325
+			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);
326 326
 		}
327 327
 
328
-		$payment_meta[ $this->id ] = array(
328
+		$payment_meta[$this->id] = array(
329 329
 			'post_meta' => array(
330 330
 				'_stripe_customer_id' => array(
331
-					'value' => get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_customer_id', true ),
331
+					'value' => get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_customer_id', true),
332 332
 					'label' => 'Stripe Customer ID',
333 333
 				),
334 334
 				'_stripe_source_id' => array(
@@ -349,17 +349,17 @@  discard block
 block discarded – undo
349 349
 	 * @param array $payment_meta associative array of meta data required for automatic payments
350 350
 	 * @return array
351 351
 	 */
352
-	public function validate_subscription_payment_meta( $payment_method_id, $payment_meta ) {
353
-		if ( $this->id === $payment_method_id ) {
352
+	public function validate_subscription_payment_meta($payment_method_id, $payment_meta) {
353
+		if ($this->id === $payment_method_id) {
354 354
 
355
-			if ( ! isset( $payment_meta['post_meta']['_stripe_customer_id']['value'] ) || empty( $payment_meta['post_meta']['_stripe_customer_id']['value'] ) ) {
356
-				throw new Exception( 'A "_stripe_customer_id" value is required.' );
357
-			} elseif ( 0 !== strpos( $payment_meta['post_meta']['_stripe_customer_id']['value'], 'cus_' ) ) {
358
-				throw new Exception( 'Invalid customer ID. A valid "_stripe_customer_id" must begin with "cus_".' );
355
+			if ( ! isset($payment_meta['post_meta']['_stripe_customer_id']['value']) || empty($payment_meta['post_meta']['_stripe_customer_id']['value'])) {
356
+				throw new Exception('A "_stripe_customer_id" value is required.');
357
+			} elseif (0 !== strpos($payment_meta['post_meta']['_stripe_customer_id']['value'], 'cus_')) {
358
+				throw new Exception('Invalid customer ID. A valid "_stripe_customer_id" must begin with "cus_".');
359 359
 			}
360 360
 
361
-			if ( ! isset( $payment_meta['post_meta']['_stripe_source_id']['value'] ) || empty( $payment_meta['post_meta']['_stripe_source_id']['value'] ) ) {
362
-				throw new Exception( 'A "_stripe_source_id" value is required.' );
361
+			if ( ! isset($payment_meta['post_meta']['_stripe_source_id']['value']) || empty($payment_meta['post_meta']['_stripe_source_id']['value'])) {
362
+				throw new Exception('A "_stripe_source_id" value is required.');
363 363
 			}
364 364
 		}
365 365
 	}
@@ -372,89 +372,89 @@  discard block
 block discarded – undo
372 372
 	 * @param WC_Subscription $subscription the subscription details
373 373
 	 * @return string the subscription payment method
374 374
 	 */
375
-	public function maybe_render_subscription_payment_method( $payment_method_to_display, $subscription ) {
375
+	public function maybe_render_subscription_payment_method($payment_method_to_display, $subscription) {
376 376
 		$customer_user = WC_Stripe_Helper::is_pre_30() ? $subscription->customer_user : $subscription->get_customer_id();
377 377
 
378 378
 		// bail for other payment methods
379
-		if ( ( WC_Stripe_Helper::is_pre_30() ? $subscription->payment_method : $subscription->get_payment_method() ) !== $this->id || ! $customer_user ) {
379
+		if ((WC_Stripe_Helper::is_pre_30() ? $subscription->payment_method : $subscription->get_payment_method()) !== $this->id || ! $customer_user) {
380 380
 			return $payment_method_to_display;
381 381
 		}
382 382
 
383
-		$stripe_source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_source_id', true );
383
+		$stripe_source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_source_id', true);
384 384
 
385 385
 		// For BW compat will remove in future.
386
-		if ( empty( $stripe_source_id ) ) {
387
-			$stripe_source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_card_id', true );
386
+		if (empty($stripe_source_id)) {
387
+			$stripe_source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_card_id', true);
388 388
 
389 389
 			// Take this opportunity to update the key name.
390
-			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 );
390
+			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);
391 391
 		}
392 392
 
393 393
 		$stripe_customer    = new WC_Stripe_Customer();
394
-		$stripe_customer_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_customer_id', true );
394
+		$stripe_customer_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_customer_id', true);
395 395
 
396 396
 		// If we couldn't find a Stripe customer linked to the subscription, fallback to the user meta data.
397
-		if ( ! $stripe_customer_id || ! is_string( $stripe_customer_id ) ) {
397
+		if ( ! $stripe_customer_id || ! is_string($stripe_customer_id)) {
398 398
 			$user_id            = $customer_user;
399
-			$stripe_customer_id = get_user_meta( $user_id, '_stripe_customer_id', true );
400
-			$stripe_source_id   = get_user_meta( $user_id, '_stripe_source_id', true );
399
+			$stripe_customer_id = get_user_meta($user_id, '_stripe_customer_id', true);
400
+			$stripe_source_id   = get_user_meta($user_id, '_stripe_source_id', true);
401 401
 
402 402
 			// For BW compat will remove in future.
403
-			if ( empty( $stripe_source_id ) ) {
404
-				$stripe_source_id = get_user_meta( $user_id, '_stripe_card_id', true );
403
+			if (empty($stripe_source_id)) {
404
+				$stripe_source_id = get_user_meta($user_id, '_stripe_card_id', true);
405 405
 
406 406
 				// Take this opportunity to update the key name.
407
-				update_user_meta( $user_id, '_stripe_source_id', $stripe_source_id );
407
+				update_user_meta($user_id, '_stripe_source_id', $stripe_source_id);
408 408
 			}
409 409
 		}
410 410
 
411 411
 		// If we couldn't find a Stripe customer linked to the account, fallback to the order meta data.
412
-		if ( ( ! $stripe_customer_id || ! is_string( $stripe_customer_id ) ) && false !== $subscription->order ) {
413
-			$stripe_customer_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id() ), '_stripe_customer_id', true );
414
-			$stripe_source_id   = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id() ), '_stripe_source_id', true );
412
+		if (( ! $stripe_customer_id || ! is_string($stripe_customer_id)) && false !== $subscription->order) {
413
+			$stripe_customer_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id()), '_stripe_customer_id', true);
414
+			$stripe_source_id   = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id()), '_stripe_source_id', true);
415 415
 
416 416
 			// For BW compat will remove in future.
417
-			if ( empty( $stripe_source_id ) ) {
418
-				$stripe_source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id() ), '_stripe_card_id', true );
417
+			if (empty($stripe_source_id)) {
418
+				$stripe_source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id()), '_stripe_card_id', true);
419 419
 
420 420
 				// Take this opportunity to update the key name.
421
-				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 );
421
+				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);
422 422
 			}
423 423
 		}
424 424
 
425
-		$stripe_customer->set_id( $stripe_customer_id );
425
+		$stripe_customer->set_id($stripe_customer_id);
426 426
 		$sources = $stripe_customer->get_sources();
427 427
 
428
-		if ( $sources ) {
428
+		if ($sources) {
429 429
 			$found_source = false;
430
-			foreach ( $sources as $source ) {
431
-				if ( isset( $source->type ) && 'card' === $source->type ) {
430
+			foreach ($sources as $source) {
431
+				if (isset($source->type) && 'card' === $source->type) {
432 432
 					$card = $source->card;
433 433
 				}
434 434
 
435
-				if ( $source->id === $stripe_source_id ) {
435
+				if ($source->id === $stripe_source_id) {
436 436
 					$found_source = true;
437 437
 
438
-					if ( $card ) {
438
+					if ($card) {
439 439
 						/* translators: 1) card brand 2) last 4 digits */
440
-						$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 );
440
+						$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);
441 441
 					} else {
442
-						$payment_method_to_display = __( 'N/A', 'woocommerce-gateway-stripe' );
442
+						$payment_method_to_display = __('N/A', 'woocommerce-gateway-stripe');
443 443
 					}
444 444
 					break;
445 445
 				}
446 446
 			}
447 447
 
448
-			if ( ! $found_source ) {
449
-				if ( 'card' === $sources[0]->type ) {
448
+			if ( ! $found_source) {
449
+				if ('card' === $sources[0]->type) {
450 450
 					$card = $sources[0]->card;
451 451
 				}
452 452
 
453
-				if ( $card ) {
453
+				if ($card) {
454 454
 					/* translators: 1) card brand 2) last 4 digits */
455
-					$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 );
455
+					$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);
456 456
 				} else {
457
-					$payment_method_to_display = __( 'N/A', 'woocommerce-gateway-stripe' );
457
+					$payment_method_to_display = __('N/A', 'woocommerce-gateway-stripe');
458 458
 				}
459 459
 			}
460 460
 		}
@@ -467,43 +467,43 @@  discard block
 block discarded – undo
467 467
 	 * @param int $order_id
468 468
 	 * @return array
469 469
 	 */
470
-	public function process_pre_order( $order_id, $retry, $force_save_source ) {
471
-		if ( WC_Pre_Orders_Order::order_requires_payment_tokenization( $order_id ) ) {
470
+	public function process_pre_order($order_id, $retry, $force_save_source) {
471
+		if (WC_Pre_Orders_Order::order_requires_payment_tokenization($order_id)) {
472 472
 			try {
473
-				$order = wc_get_order( $order_id );
473
+				$order = wc_get_order($order_id);
474 474
 
475
-				if ( $order->get_total() * 100 < WC_Stripe_Helper::get_minimum_amount() ) {
475
+				if ($order->get_total() * 100 < WC_Stripe_Helper::get_minimum_amount()) {
476 476
 					/* translators: minimum amount */
477
-					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 ) ) );
477
+					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)));
478 478
 				}
479 479
 
480
-				$source = $this->prepare_source( $this->get_source_object(), get_current_user_id(), true );
480
+				$source = $this->prepare_source($this->get_source_object(), get_current_user_id(), true);
481 481
 
482 482
 				// We need a source on file to continue.
483
-				if ( empty( $source->customer ) || empty( $source->source ) ) {
484
-					throw new Exception( __( 'Unable to store payment details. Please try again.', 'woocommerce-gateway-stripe' ) );
483
+				if (empty($source->customer) || empty($source->source)) {
484
+					throw new Exception(__('Unable to store payment details. Please try again.', 'woocommerce-gateway-stripe'));
485 485
 				}
486 486
 
487 487
 				// Store source to order meta
488
-				$this->save_source( $order, $source );
488
+				$this->save_source($order, $source);
489 489
 
490 490
 				// Remove cart
491 491
 				WC()->cart->empty_cart();
492 492
 
493 493
 				// Is pre ordered!
494
-				WC_Pre_Orders_Order::mark_order_as_pre_ordered( $order );
494
+				WC_Pre_Orders_Order::mark_order_as_pre_ordered($order);
495 495
 
496 496
 				// Return thank you page redirect
497 497
 				return array(
498 498
 					'result'   => 'success',
499
-					'redirect' => $this->get_return_url( $order ),
499
+					'redirect' => $this->get_return_url($order),
500 500
 				);
501
-			} catch ( Exception $e ) {
502
-				wc_add_notice( $e->getMessage(), 'error' );
501
+			} catch (Exception $e) {
502
+				wc_add_notice($e->getMessage(), 'error');
503 503
 				return;
504 504
 			}
505 505
 		} else {
506
-			return parent::process_payment( $order_id, $retry, $force_save_source );
506
+			return parent::process_payment($order_id, $retry, $force_save_source);
507 507
 		}
508 508
 	}
509 509
 
@@ -512,7 +512,7 @@  discard block
 block discarded – undo
512 512
 	 * @param WC_Order $order
513 513
 	 * @return void
514 514
 	 */
515
-	public function process_pre_order_release_payment( $order ) {
515
+	public function process_pre_order_release_payment($order) {
516 516
 		try {
517 517
 			// Define some callbacks if the first attempt fails.
518 518
 			$retry_callbacks = array(
@@ -520,33 +520,33 @@  discard block
 block discarded – undo
520 520
 				'remove_order_customer_before_retry',
521 521
 			);
522 522
 
523
-			while ( 1 ) {
524
-				$source   = $this->prepare_order_source( $order );
525
-				$response = WC_Stripe_API::request( $this->generate_payment_request( $order, $source ) );
523
+			while (1) {
524
+				$source   = $this->prepare_order_source($order);
525
+				$response = WC_Stripe_API::request($this->generate_payment_request($order, $source));
526 526
 
527
-				if ( ! empty( $response->error ) ) {
528
-					if ( 0 === sizeof( $retry_callbacks ) ) {
529
-						throw new Exception( $response->error->message );
527
+				if ( ! empty($response->error)) {
528
+					if (0 === sizeof($retry_callbacks)) {
529
+						throw new Exception($response->error->message);
530 530
 					} else {
531
-						$retry_callback = array_shift( $retry_callbacks );
532
-						call_user_func( array( $this, $retry_callback ), $order );
531
+						$retry_callback = array_shift($retry_callbacks);
532
+						call_user_func(array($this, $retry_callback), $order);
533 533
 					}
534 534
 				} else {
535 535
 					// Successful
536
-					$this->process_response( $response, $order );
536
+					$this->process_response($response, $order);
537 537
 					break;
538 538
 				}
539 539
 			}
540
-		} catch ( Exception $e ) {
540
+		} catch (Exception $e) {
541 541
 			/* translators: error message */
542
-			$order_note = sprintf( __( 'Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe' ), $e->getMessage() );
542
+			$order_note = sprintf(__('Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe'), $e->getMessage());
543 543
 
544 544
 			// Mark order as failed if not already set,
545 545
 			// otherwise, make sure we add the order note so we can detect when someone fails to check out multiple times
546
-			if ( ! $order->has_status( 'failed' ) ) {
547
-				$order->update_status( 'failed', $order_note );
546
+			if ( ! $order->has_status('failed')) {
547
+				$order->update_status('failed', $order_note);
548 548
 			} else {
549
-				$order->add_order_note( $order_note );
549
+				$order->add_order_note($order_note);
550 550
 			}
551 551
 		}
552 552
 	}
Please login to merge, or discard this patch.
includes/payment-methods/class-wc-gateway-stripe-bancontact.php 1 patch
Spacing   +77 added lines, -77 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
 
@@ -57,9 +57,9 @@  discard block
 block discarded – undo
57 57
 	 */
58 58
 	public function __construct() {
59 59
 		$this->id                   = 'stripe_bancontact';
60
-		$this->method_title         = __( 'Stripe Bancontact', 'woocommerce-gateway-stripe' );
60
+		$this->method_title         = __('Stripe Bancontact', 'woocommerce-gateway-stripe');
61 61
 		/* translators: link */
62
-		$this->method_description   = sprintf( __( 'All other general Stripe settings can be adjusted <a href="%s">here</a>.', 'woocommerce-gateway-stripe' ), admin_url( 'admin.php?page=wc-settings&tab=checkout&section=stripe' ) );
62
+		$this->method_description   = sprintf(__('All other general Stripe settings can be adjusted <a href="%s">here</a>.', 'woocommerce-gateway-stripe'), admin_url('admin.php?page=wc-settings&tab=checkout&section=stripe'));
63 63
 		$this->supports             = array(
64 64
 			'products',
65 65
 			'refunds',
@@ -71,25 +71,25 @@  discard block
 block discarded – undo
71 71
 		// Load the settings.
72 72
 		$this->init_settings();
73 73
 
74
-		$main_settings              = get_option( 'woocommerce_stripe_settings' );
75
-		$this->title                = $this->get_option( 'title' );
76
-		$this->description          = $this->get_option( 'description' );
77
-		$this->enabled              = $this->get_option( 'enabled' );
78
-		$this->testmode             = ( ! empty( $main_settings['testmode'] ) && 'yes' === $main_settings['testmode'] ) ? true : false;
79
-		$this->saved_cards          = ( ! empty( $main_settings['saved_cards'] ) && 'yes' === $main_settings['saved_cards'] ) ? true : false;
80
-		$this->publishable_key      = ! empty( $main_settings['publishable_key'] ) ? $main_settings['publishable_key'] : '';
81
-		$this->secret_key           = ! empty( $main_settings['secret_key'] ) ? $main_settings['secret_key'] : '';
82
-		$this->statement_descriptor = ! empty( $main_settings['statement_descriptor'] ) ? $main_settings['statement_descriptor'] : '';
83
-
84
-		if ( $this->testmode ) {
85
-			$this->publishable_key = ! empty( $main_settings['test_publishable_key'] ) ? $main_settings['test_publishable_key'] : '';
86
-			$this->secret_key      = ! empty( $main_settings['test_secret_key'] ) ? $main_settings['test_secret_key'] : '';
74
+		$main_settings              = get_option('woocommerce_stripe_settings');
75
+		$this->title                = $this->get_option('title');
76
+		$this->description          = $this->get_option('description');
77
+		$this->enabled              = $this->get_option('enabled');
78
+		$this->testmode             = ( ! empty($main_settings['testmode']) && 'yes' === $main_settings['testmode']) ? true : false;
79
+		$this->saved_cards          = ( ! empty($main_settings['saved_cards']) && 'yes' === $main_settings['saved_cards']) ? true : false;
80
+		$this->publishable_key      = ! empty($main_settings['publishable_key']) ? $main_settings['publishable_key'] : '';
81
+		$this->secret_key           = ! empty($main_settings['secret_key']) ? $main_settings['secret_key'] : '';
82
+		$this->statement_descriptor = ! empty($main_settings['statement_descriptor']) ? $main_settings['statement_descriptor'] : '';
83
+
84
+		if ($this->testmode) {
85
+			$this->publishable_key = ! empty($main_settings['test_publishable_key']) ? $main_settings['test_publishable_key'] : '';
86
+			$this->secret_key      = ! empty($main_settings['test_secret_key']) ? $main_settings['test_secret_key'] : '';
87 87
 		}
88 88
 
89
-		add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) );
90
-		add_action( 'admin_notices', array( $this, 'check_environment' ) );
91
-		add_action( 'admin_head', array( $this, 'remove_admin_notice' ) );
92
-		add_action( 'wp_enqueue_scripts', array( $this, 'payment_scripts' ) );
89
+		add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options'));
90
+		add_action('admin_notices', array($this, 'check_environment'));
91
+		add_action('admin_head', array($this, 'remove_admin_notice'));
92
+		add_action('wp_enqueue_scripts', array($this, 'payment_scripts'));
93 93
 	}
94 94
 
95 95
 	/**
@@ -99,19 +99,19 @@  discard block
 block discarded – undo
99 99
 	 * @version 4.0.0
100 100
 	 */
101 101
 	public function check_environment() {
102
-		if ( ! current_user_can( 'manage_woocommerce' ) ) {
102
+		if ( ! current_user_can('manage_woocommerce')) {
103 103
 			return;
104 104
 		}
105 105
 
106 106
 		$environment_warning = $this->get_environment_warning();
107 107
 
108
-		if ( $environment_warning ) {
109
-			$this->add_admin_notice( 'bad_environment', 'error', $environment_warning );
108
+		if ($environment_warning) {
109
+			$this->add_admin_notice('bad_environment', 'error', $environment_warning);
110 110
 		}
111 111
 
112
-		foreach ( (array) $this->notices as $notice_key => $notice ) {
113
-			echo "<div class='" . esc_attr( $notice['class'] ) . "'><p>";
114
-			echo wp_kses( $notice['message'], array( 'a' => array( 'href' => array() ) ) );
112
+		foreach ((array) $this->notices as $notice_key => $notice) {
113
+			echo "<div class='" . esc_attr($notice['class']) . "'><p>";
114
+			echo wp_kses($notice['message'], array('a' => array('href' => array())));
115 115
 			echo '</p></div>';
116 116
 		}
117 117
 	}
@@ -124,8 +124,8 @@  discard block
 block discarded – undo
124 124
 	 * @version 4.0.0
125 125
 	 */
126 126
 	public function get_environment_warning() {
127
-		if ( 'yes' === $this->enabled && ! in_array( get_woocommerce_currency(), $this->get_supported_currency() ) ) {
128
-			$message = __( 'Bancontact is enabled - it requires store currency to be set to Euros.', 'woocommerce-gateway-stripe' );
127
+		if ('yes' === $this->enabled && ! in_array(get_woocommerce_currency(), $this->get_supported_currency())) {
128
+			$message = __('Bancontact is enabled - it requires store currency to be set to Euros.', 'woocommerce-gateway-stripe');
129 129
 
130 130
 			return $message;
131 131
 		}
@@ -141,9 +141,9 @@  discard block
 block discarded – undo
141 141
 	 * @return array
142 142
 	 */
143 143
 	public function get_supported_currency() {
144
-		return apply_filters( 'wc_stripe_bancontact_supported_currencies', array(
144
+		return apply_filters('wc_stripe_bancontact_supported_currencies', array(
145 145
 			'EUR',
146
-		) );
146
+		));
147 147
 	}
148 148
 
149 149
 	/**
@@ -154,7 +154,7 @@  discard block
 block discarded – undo
154 154
 	 * @return bool
155 155
 	 */
156 156
 	public function is_available() {
157
-		if ( ! in_array( get_woocommerce_currency(), $this->get_supported_currency() ) ) {
157
+		if ( ! in_array(get_woocommerce_currency(), $this->get_supported_currency())) {
158 158
 			return false;
159 159
 		}
160 160
 
@@ -175,7 +175,7 @@  discard block
 block discarded – undo
175 175
 
176 176
 		$icons_str .= $icons['bancontact'];
177 177
 
178
-		return apply_filters( 'woocommerce_gateway_icon', $icons_str, $this->id );
178
+		return apply_filters('woocommerce_gateway_icon', $icons_str, $this->id);
179 179
 	}
180 180
 
181 181
 	/**
@@ -186,19 +186,19 @@  discard block
 block discarded – undo
186 186
 	 * @access public
187 187
 	 */
188 188
 	public function payment_scripts() {
189
-		if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) && ! is_add_payment_method_page() ) {
189
+		if ( ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order']) && ! is_add_payment_method_page()) {
190 190
 			return;
191 191
 		}
192 192
 
193
-		wp_enqueue_style( 'stripe_paymentfonts' );
194
-		wp_enqueue_script( 'woocommerce_stripe' );
193
+		wp_enqueue_style('stripe_paymentfonts');
194
+		wp_enqueue_script('woocommerce_stripe');
195 195
 	}
196 196
 
197 197
 	/**
198 198
 	 * Initialize Gateway Settings Form Fields.
199 199
 	 */
200 200
 	public function init_form_fields() {
201
-		$this->form_fields = require( WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-bancontact-settings.php' );
201
+		$this->form_fields = require(WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-bancontact-settings.php');
202 202
 	}
203 203
 
204 204
 	/**
@@ -209,25 +209,25 @@  discard block
 block discarded – undo
209 209
 		$total = WC()->cart->total;
210 210
 
211 211
 		// If paying from order, we need to get total from order not cart.
212
-		if ( isset( $_GET['pay_for_order'] ) && ! empty( $_GET['key'] ) ) {
213
-			$order = wc_get_order( wc_get_order_id_by_order_key( wc_clean( $_GET['key'] ) ) );
212
+		if (isset($_GET['pay_for_order']) && ! empty($_GET['key'])) {
213
+			$order = wc_get_order(wc_get_order_id_by_order_key(wc_clean($_GET['key'])));
214 214
 			$total = $order->get_total();
215 215
 		}
216 216
 
217
-		if ( is_add_payment_method_page() ) {
218
-			$pay_button_text = __( 'Add Payment', 'woocommerce-gateway-stripe' );
219
-			$total        = '';
217
+		if (is_add_payment_method_page()) {
218
+			$pay_button_text = __('Add Payment', 'woocommerce-gateway-stripe');
219
+			$total = '';
220 220
 		} else {
221 221
 			$pay_button_text = '';
222 222
 		}
223 223
 
224 224
 		echo '<div
225 225
 			id="stripe-bancontact-payment-data"
226
-			data-amount="' . esc_attr( WC_Stripe_Helper::get_stripe_amount( $total ) ) . '"
227
-			data-currency="' . esc_attr( strtolower( get_woocommerce_currency() ) ) . '">';
226
+			data-amount="' . esc_attr(WC_Stripe_Helper::get_stripe_amount($total)) . '"
227
+			data-currency="' . esc_attr(strtolower(get_woocommerce_currency())) . '">';
228 228
 
229
-		if ( $this->description ) {
230
-			echo apply_filters( 'wc_stripe_description', wpautop( wp_kses_post( $this->description ) ) );
229
+		if ($this->description) {
230
+			echo apply_filters('wc_stripe_description', wpautop(wp_kses_post($this->description)));
231 231
 		}
232 232
 
233 233
 		echo '</div>';
@@ -241,25 +241,25 @@  discard block
 block discarded – undo
241 241
 	 * @param object $order
242 242
 	 * @return mixed
243 243
 	 */
244
-	public function create_source( $order ) {
244
+	public function create_source($order) {
245 245
 		$currency                = WC_Stripe_Helper::is_pre_30() ? $order->get_order_currency() : $order->get_currency();
246 246
 		$order_id                = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
247
-		$return_url              = $this->get_stripe_return_url( $order );
247
+		$return_url              = $this->get_stripe_return_url($order);
248 248
 		$post_data               = array();
249
-		$post_data['amount']     = WC_Stripe_Helper::get_stripe_amount( $order->get_total(), $currency );
250
-		$post_data['currency']   = strtolower( $currency );
249
+		$post_data['amount']     = WC_Stripe_Helper::get_stripe_amount($order->get_total(), $currency);
250
+		$post_data['currency']   = strtolower($currency);
251 251
 		$post_data['type']       = 'bancontact';
252
-		$post_data['owner']      = $this->get_owner_details( $order );
253
-		$post_data['redirect']   = array( 'return_url' => $return_url );
254
-		$post_data['bancontact'] = array( 'preferred_language' => substr( get_locale(), 0, 2 ) );
252
+		$post_data['owner']      = $this->get_owner_details($order);
253
+		$post_data['redirect']   = array('return_url' => $return_url);
254
+		$post_data['bancontact'] = array('preferred_language' => substr(get_locale(), 0, 2));
255 255
 
256
-		if ( ! empty( $this->statement_descriptor ) ) {
257
-			$post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor( $this->statement_descriptor );
256
+		if ( ! empty($this->statement_descriptor)) {
257
+			$post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor($this->statement_descriptor);
258 258
 		}
259 259
 
260
-		WC_Stripe_Logger::log( 'Info: Begin creating Bancontact source' );
260
+		WC_Stripe_Logger::log('Info: Begin creating Bancontact source');
261 261
 
262
-		return WC_Stripe_API::request( apply_filters( 'wc_stripe_bancontact_source', $post_data, $order ), 'sources' );
262
+		return WC_Stripe_API::request(apply_filters('wc_stripe_bancontact_source', $post_data, $order), 'sources');
263 263
 	}
264 264
 
265 265
 	/**
@@ -273,51 +273,51 @@  discard block
 block discarded – undo
273 273
 	 *
274 274
 	 * @return array|void
275 275
 	 */
276
-	public function process_payment( $order_id, $retry = true, $force_save_source = false ) {
276
+	public function process_payment($order_id, $retry = true, $force_save_source = false) {
277 277
 		try {
278
-			$order = wc_get_order( $order_id );
278
+			$order = wc_get_order($order_id);
279 279
 
280 280
 			// This will throw exception if not valid.
281
-			$this->validate_minimum_order_amount( $order );
281
+			$this->validate_minimum_order_amount($order);
282 282
 
283 283
 			// This comes from the create account checkbox in the checkout page.
284
-			$create_account = ! empty( $_POST['createaccount'] ) ? true : false;
284
+			$create_account = ! empty($_POST['createaccount']) ? true : false;
285 285
 
286
-			if ( $create_account ) {
286
+			if ($create_account) {
287 287
 				$new_customer_id     = WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id();
288
-				$new_stripe_customer = new WC_Stripe_Customer( $new_customer_id );
288
+				$new_stripe_customer = new WC_Stripe_Customer($new_customer_id);
289 289
 				$new_stripe_customer->create_customer();
290 290
 			}
291 291
 
292
-			$response = $this->create_source( $order );
292
+			$response = $this->create_source($order);
293 293
 
294
-			if ( ! empty( $response->error ) ) {
295
-				$order->add_order_note( $response->error->message );
294
+			if ( ! empty($response->error)) {
295
+				$order->add_order_note($response->error->message);
296 296
 
297
-				throw new WC_Stripe_Exception( print_r( $response, true ), $response->error->message );
297
+				throw new WC_Stripe_Exception(print_r($response, true), $response->error->message);
298 298
 			}
299 299
 
300
-			if ( WC_Stripe_Helper::is_pre_30() ) {
301
-				update_post_meta( $order_id, '_stripe_source_id', $response->id );
300
+			if (WC_Stripe_Helper::is_pre_30()) {
301
+				update_post_meta($order_id, '_stripe_source_id', $response->id);
302 302
 			} else {
303
-				$order->update_meta_data( '_stripe_source_id', $response->id );
303
+				$order->update_meta_data('_stripe_source_id', $response->id);
304 304
 				$order->save();
305 305
 			}
306 306
 
307
-			WC_Stripe_Logger::log( 'Info: Redirecting to Bancontact...' );
307
+			WC_Stripe_Logger::log('Info: Redirecting to Bancontact...');
308 308
 
309 309
 			return array(
310 310
 				'result'   => 'success',
311
-				'redirect' => esc_url_raw( $response->redirect->url ),
311
+				'redirect' => esc_url_raw($response->redirect->url),
312 312
 			);
313
-		} catch ( WC_Stripe_Exception $e ) {
314
-			wc_add_notice( $e->getLocalizedMessage(), 'error' );
315
-			WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() );
313
+		} catch (WC_Stripe_Exception $e) {
314
+			wc_add_notice($e->getLocalizedMessage(), 'error');
315
+			WC_Stripe_Logger::log('Error: ' . $e->getMessage());
316 316
 
317
-			do_action( 'wc_gateway_stripe_process_payment_error', $e, $order );
317
+			do_action('wc_gateway_stripe_process_payment_error', $e, $order);
318 318
 
319
-			if ( $order->has_status( array( 'pending', 'failed' ) ) ) {
320
-				$this->send_failed_order_email( $order_id );
319
+			if ($order->has_status(array('pending', 'failed'))) {
320
+				$this->send_failed_order_email($order_id);
321 321
 			}
322 322
 
323 323
 			return array(
Please login to merge, or discard this patch.
includes/payment-methods/class-wc-gateway-stripe-p24.php 1 patch
Spacing   +74 added lines, -74 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
 
@@ -57,9 +57,9 @@  discard block
 block discarded – undo
57 57
 	 */
58 58
 	public function __construct() {
59 59
 		$this->id                   = 'stripe_p24';
60
-		$this->method_title         = __( 'Stripe P24', 'woocommerce-gateway-stripe' );
60
+		$this->method_title         = __('Stripe P24', 'woocommerce-gateway-stripe');
61 61
 		/* translators: link */
62
-		$this->method_description   = sprintf( __( 'All other general Stripe settings can be adjusted <a href="%s">here</a>.', 'woocommerce-gateway-stripe' ), admin_url( 'admin.php?page=wc-settings&tab=checkout&section=stripe' ) );
62
+		$this->method_description   = sprintf(__('All other general Stripe settings can be adjusted <a href="%s">here</a>.', 'woocommerce-gateway-stripe'), admin_url('admin.php?page=wc-settings&tab=checkout&section=stripe'));
63 63
 		$this->supports             = array(
64 64
 			'products',
65 65
 			'refunds',
@@ -71,25 +71,25 @@  discard block
 block discarded – undo
71 71
 		// Load the settings.
72 72
 		$this->init_settings();
73 73
 
74
-		$main_settings              = get_option( 'woocommerce_stripe_settings' );
75
-		$this->title                = $this->get_option( 'title' );
76
-		$this->description          = $this->get_option( 'description' );
77
-		$this->enabled              = $this->get_option( 'enabled' );
78
-		$this->testmode             = ( ! empty( $main_settings['testmode'] ) && 'yes' === $main_settings['testmode'] ) ? true : false;
79
-		$this->saved_cards          = ( ! empty( $main_settings['saved_cards'] ) && 'yes' === $main_settings['saved_cards'] ) ? true : false;
80
-		$this->publishable_key      = ! empty( $main_settings['publishable_key'] ) ? $main_settings['publishable_key'] : '';
81
-		$this->secret_key           = ! empty( $main_settings['secret_key'] ) ? $main_settings['secret_key'] : '';
82
-		$this->statement_descriptor = ! empty( $main_settings['statement_descriptor'] ) ? $main_settings['statement_descriptor'] : '';
83
-
84
-		if ( $this->testmode ) {
85
-			$this->publishable_key = ! empty( $main_settings['test_publishable_key'] ) ? $main_settings['test_publishable_key'] : '';
86
-			$this->secret_key      = ! empty( $main_settings['test_secret_key'] ) ? $main_settings['test_secret_key'] : '';
74
+		$main_settings              = get_option('woocommerce_stripe_settings');
75
+		$this->title                = $this->get_option('title');
76
+		$this->description          = $this->get_option('description');
77
+		$this->enabled              = $this->get_option('enabled');
78
+		$this->testmode             = ( ! empty($main_settings['testmode']) && 'yes' === $main_settings['testmode']) ? true : false;
79
+		$this->saved_cards          = ( ! empty($main_settings['saved_cards']) && 'yes' === $main_settings['saved_cards']) ? true : false;
80
+		$this->publishable_key      = ! empty($main_settings['publishable_key']) ? $main_settings['publishable_key'] : '';
81
+		$this->secret_key           = ! empty($main_settings['secret_key']) ? $main_settings['secret_key'] : '';
82
+		$this->statement_descriptor = ! empty($main_settings['statement_descriptor']) ? $main_settings['statement_descriptor'] : '';
83
+
84
+		if ($this->testmode) {
85
+			$this->publishable_key = ! empty($main_settings['test_publishable_key']) ? $main_settings['test_publishable_key'] : '';
86
+			$this->secret_key      = ! empty($main_settings['test_secret_key']) ? $main_settings['test_secret_key'] : '';
87 87
 		}
88 88
 
89
-		add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) );
90
-		add_action( 'admin_notices', array( $this, 'check_environment' ) );
91
-		add_action( 'admin_head', array( $this, 'remove_admin_notice' ) );
92
-		add_action( 'wp_enqueue_scripts', array( $this, 'payment_scripts' ) );
89
+		add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options'));
90
+		add_action('admin_notices', array($this, 'check_environment'));
91
+		add_action('admin_head', array($this, 'remove_admin_notice'));
92
+		add_action('wp_enqueue_scripts', array($this, 'payment_scripts'));
93 93
 	}
94 94
 
95 95
 	/**
@@ -99,19 +99,19 @@  discard block
 block discarded – undo
99 99
 	 * @version 4.0.0
100 100
 	 */
101 101
 	public function check_environment() {
102
-		if ( ! current_user_can( 'manage_woocommerce' ) ) {
102
+		if ( ! current_user_can('manage_woocommerce')) {
103 103
 			return;
104 104
 		}
105 105
 
106 106
 		$environment_warning = $this->get_environment_warning();
107 107
 
108
-		if ( $environment_warning ) {
109
-			$this->add_admin_notice( 'bad_environment', 'error', $environment_warning );
108
+		if ($environment_warning) {
109
+			$this->add_admin_notice('bad_environment', 'error', $environment_warning);
110 110
 		}
111 111
 
112
-		foreach ( (array) $this->notices as $notice_key => $notice ) {
113
-			echo "<div class='" . esc_attr( $notice['class'] ) . "'><p>";
114
-			echo wp_kses( $notice['message'], array( 'a' => array( 'href' => array() ) ) );
112
+		foreach ((array) $this->notices as $notice_key => $notice) {
113
+			echo "<div class='" . esc_attr($notice['class']) . "'><p>";
114
+			echo wp_kses($notice['message'], array('a' => array('href' => array())));
115 115
 			echo '</p></div>';
116 116
 		}
117 117
 	}
@@ -124,8 +124,8 @@  discard block
 block discarded – undo
124 124
 	 * @version 4.0.0
125 125
 	 */
126 126
 	public function get_environment_warning() {
127
-		if ( 'yes' === $this->enabled && ! in_array( get_woocommerce_currency(), $this->get_supported_currency() ) ) {
128
-			$message = __( 'P24 is enabled - it requires store currency to be set to Euros or Polish Zloty.', 'woocommerce-gateway-stripe' );
127
+		if ('yes' === $this->enabled && ! in_array(get_woocommerce_currency(), $this->get_supported_currency())) {
128
+			$message = __('P24 is enabled - it requires store currency to be set to Euros or Polish Zloty.', 'woocommerce-gateway-stripe');
129 129
 
130 130
 			return $message;
131 131
 		}
@@ -141,10 +141,10 @@  discard block
 block discarded – undo
141 141
 	 * @return array
142 142
 	 */
143 143
 	public function get_supported_currency() {
144
-		return apply_filters( 'wc_stripe_p24_supported_currencies', array(
144
+		return apply_filters('wc_stripe_p24_supported_currencies', array(
145 145
 			'EUR',
146 146
 			'PLN',
147
-		) );
147
+		));
148 148
 	}
149 149
 
150 150
 	/**
@@ -155,7 +155,7 @@  discard block
 block discarded – undo
155 155
 	 * @return bool
156 156
 	 */
157 157
 	public function is_available() {
158
-		if ( ! in_array( get_woocommerce_currency(), $this->get_supported_currency() ) ) {
158
+		if ( ! in_array(get_woocommerce_currency(), $this->get_supported_currency())) {
159 159
 			return false;
160 160
 		}
161 161
 
@@ -176,7 +176,7 @@  discard block
 block discarded – undo
176 176
 
177 177
 		$icons_str .= $icons['p24'];
178 178
 
179
-		return apply_filters( 'woocommerce_gateway_icon', $icons_str, $this->id );
179
+		return apply_filters('woocommerce_gateway_icon', $icons_str, $this->id);
180 180
 	}
181 181
 
182 182
 	/**
@@ -187,19 +187,19 @@  discard block
 block discarded – undo
187 187
 	 * @access public
188 188
 	 */
189 189
 	public function payment_scripts() {
190
-		if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) && ! is_add_payment_method_page() ) {
190
+		if ( ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order']) && ! is_add_payment_method_page()) {
191 191
 			return;
192 192
 		}
193 193
 
194
-		wp_enqueue_style( 'stripe_paymentfonts' );
195
-		wp_enqueue_script( 'woocommerce_stripe' );
194
+		wp_enqueue_style('stripe_paymentfonts');
195
+		wp_enqueue_script('woocommerce_stripe');
196 196
 	}
197 197
 
198 198
 	/**
199 199
 	 * Initialize Gateway Settings Form Fields.
200 200
 	 */
201 201
 	public function init_form_fields() {
202
-		$this->form_fields = require( WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-p24-settings.php' );
202
+		$this->form_fields = require(WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-p24-settings.php');
203 203
 	}
204 204
 
205 205
 	/**
@@ -210,25 +210,25 @@  discard block
 block discarded – undo
210 210
 		$total                = WC()->cart->total;
211 211
 
212 212
 		// If paying from order, we need to get total from order not cart.
213
-		if ( isset( $_GET['pay_for_order'] ) && ! empty( $_GET['key'] ) ) {
214
-			$order = wc_get_order( wc_get_order_id_by_order_key( wc_clean( $_GET['key'] ) ) );
213
+		if (isset($_GET['pay_for_order']) && ! empty($_GET['key'])) {
214
+			$order = wc_get_order(wc_get_order_id_by_order_key(wc_clean($_GET['key'])));
215 215
 			$total = $order->get_total();
216 216
 		}
217 217
 
218
-		if ( is_add_payment_method_page() ) {
219
-			$pay_button_text = __( 'Add Payment', 'woocommerce-gateway-stripe' );
220
-			$total        = '';
218
+		if (is_add_payment_method_page()) {
219
+			$pay_button_text = __('Add Payment', 'woocommerce-gateway-stripe');
220
+			$total = '';
221 221
 		} else {
222 222
 			$pay_button_text = '';
223 223
 		}
224 224
 
225 225
 		echo '<div
226 226
 			id="stripe-p24-payment-data"
227
-			data-amount="' . esc_attr( WC_Stripe_Helper::get_stripe_amount( $total ) ) . '"
228
-			data-currency="' . esc_attr( strtolower( get_woocommerce_currency() ) ) . '">';
227
+			data-amount="' . esc_attr(WC_Stripe_Helper::get_stripe_amount($total)) . '"
228
+			data-currency="' . esc_attr(strtolower(get_woocommerce_currency())) . '">';
229 229
 
230
-		if ( $this->description ) {
231
-			echo apply_filters( 'wc_stripe_description', wpautop( wp_kses_post( $this->description ) ) );
230
+		if ($this->description) {
231
+			echo apply_filters('wc_stripe_description', wpautop(wp_kses_post($this->description)));
232 232
 		}
233 233
 
234 234
 		echo '</div>';
@@ -242,20 +242,20 @@  discard block
 block discarded – undo
242 242
 	 * @param object $order
243 243
 	 * @return mixed
244 244
 	 */
245
-	public function create_source( $order ) {
245
+	public function create_source($order) {
246 246
 		$currency              = WC_Stripe_Helper::is_pre_30() ? $order->get_order_currency() : $order->get_currency();
247 247
 		$order_id              = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
248
-		$return_url            = $this->get_stripe_return_url( $order );
248
+		$return_url            = $this->get_stripe_return_url($order);
249 249
 		$post_data             = array();
250
-		$post_data['amount']   = WC_Stripe_Helper::get_stripe_amount( $order->get_total(), $currency );
251
-		$post_data['currency'] = strtolower( $currency );
250
+		$post_data['amount']   = WC_Stripe_Helper::get_stripe_amount($order->get_total(), $currency);
251
+		$post_data['currency'] = strtolower($currency);
252 252
 		$post_data['type']     = 'p24';
253
-		$post_data['owner']    = $this->get_owner_details( $order );
254
-		$post_data['redirect'] = array( 'return_url' => $return_url );
253
+		$post_data['owner']    = $this->get_owner_details($order);
254
+		$post_data['redirect'] = array('return_url' => $return_url);
255 255
 
256
-		WC_Stripe_Logger::log( 'Info: Begin creating P24 source' );
256
+		WC_Stripe_Logger::log('Info: Begin creating P24 source');
257 257
 
258
-		return WC_Stripe_API::request( apply_filters( 'wc_stripe_p24_source', $post_data, $order ), 'sources' );
258
+		return WC_Stripe_API::request(apply_filters('wc_stripe_p24_source', $post_data, $order), 'sources');
259 259
 	}
260 260
 
261 261
 	/**
@@ -269,51 +269,51 @@  discard block
 block discarded – undo
269 269
 	 *
270 270
 	 * @return array|void
271 271
 	 */
272
-	public function process_payment( $order_id, $retry = true, $force_save_source = false ) {
272
+	public function process_payment($order_id, $retry = true, $force_save_source = false) {
273 273
 		try {
274
-			$order = wc_get_order( $order_id );
274
+			$order = wc_get_order($order_id);
275 275
 
276 276
 			// This will throw exception if not valid.
277
-			$this->validate_minimum_order_amount( $order );
277
+			$this->validate_minimum_order_amount($order);
278 278
 
279 279
 			// This comes from the create account checkbox in the checkout page.
280
-			$create_account = ! empty( $_POST['createaccount'] ) ? true : false;
280
+			$create_account = ! empty($_POST['createaccount']) ? true : false;
281 281
 
282
-			if ( $create_account ) {
282
+			if ($create_account) {
283 283
 				$new_customer_id     = WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id();
284
-				$new_stripe_customer = new WC_Stripe_Customer( $new_customer_id );
284
+				$new_stripe_customer = new WC_Stripe_Customer($new_customer_id);
285 285
 				$new_stripe_customer->create_customer();
286 286
 			}
287 287
 
288
-			$response = $this->create_source( $order );
288
+			$response = $this->create_source($order);
289 289
 
290
-			if ( ! empty( $response->error ) ) {
291
-				$order->add_order_note( $response->error->message );
290
+			if ( ! empty($response->error)) {
291
+				$order->add_order_note($response->error->message);
292 292
 
293
-				throw new WC_Stripe_Exception( print_r( $response, true ), $response->error->message );
293
+				throw new WC_Stripe_Exception(print_r($response, true), $response->error->message);
294 294
 			}
295 295
 
296
-			if ( WC_Stripe_Helper::is_pre_30() ) {
297
-				update_post_meta( $order_id, '_stripe_source_id', $response->id );
296
+			if (WC_Stripe_Helper::is_pre_30()) {
297
+				update_post_meta($order_id, '_stripe_source_id', $response->id);
298 298
 			} else {
299
-				$order->update_meta_data( '_stripe_source_id', $response->id );
299
+				$order->update_meta_data('_stripe_source_id', $response->id);
300 300
 				$order->save();
301 301
 			}
302 302
 
303
-			WC_Stripe_Logger::log( 'Info: Redirecting to P24...' );
303
+			WC_Stripe_Logger::log('Info: Redirecting to P24...');
304 304
 
305 305
 			return array(
306 306
 				'result'   => 'success',
307
-				'redirect' => esc_url_raw( $response->redirect->url ),
307
+				'redirect' => esc_url_raw($response->redirect->url),
308 308
 			);
309
-		} catch ( WC_Stripe_Exception $e ) {
310
-			wc_add_notice( $e->getLocalizedMessage(), 'error' );
311
-			WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() );
309
+		} catch (WC_Stripe_Exception $e) {
310
+			wc_add_notice($e->getLocalizedMessage(), 'error');
311
+			WC_Stripe_Logger::log('Error: ' . $e->getMessage());
312 312
 
313
-			do_action( 'wc_gateway_stripe_process_payment_error', $e, $order );
313
+			do_action('wc_gateway_stripe_process_payment_error', $e, $order);
314 314
 
315
-			if ( $order->has_status( array( 'pending', 'failed' ) ) ) {
316
-				$this->send_failed_order_email( $order_id );
315
+			if ($order->has_status(array('pending', 'failed'))) {
316
+				$this->send_failed_order_email($order_id);
317 317
 			}
318 318
 
319 319
 			return array(
Please login to merge, or discard this patch.
includes/payment-methods/class-wc-gateway-stripe-alipay.php 1 patch
Spacing   +77 added lines, -77 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
 
@@ -57,9 +57,9 @@  discard block
 block discarded – undo
57 57
 	 */
58 58
 	public function __construct() {
59 59
 		$this->id                   = 'stripe_alipay';
60
-		$this->method_title         = __( 'Stripe Alipay', 'woocommerce-gateway-stripe' );
60
+		$this->method_title         = __('Stripe Alipay', 'woocommerce-gateway-stripe');
61 61
 		/* translators: link */
62
-		$this->method_description   = sprintf( __( 'All other general Stripe settings can be adjusted <a href="%s">here</a>.', 'woocommerce-gateway-stripe' ), admin_url( 'admin.php?page=wc-settings&tab=checkout&section=stripe' ) );
62
+		$this->method_description   = sprintf(__('All other general Stripe settings can be adjusted <a href="%s">here</a>.', 'woocommerce-gateway-stripe'), admin_url('admin.php?page=wc-settings&tab=checkout&section=stripe'));
63 63
 		$this->supports             = array(
64 64
 			'products',
65 65
 			'refunds',
@@ -71,25 +71,25 @@  discard block
 block discarded – undo
71 71
 		// Load the settings.
72 72
 		$this->init_settings();
73 73
 
74
-		$main_settings              = get_option( 'woocommerce_stripe_settings' );
75
-		$this->title                = $this->get_option( 'title' );
76
-		$this->description          = $this->get_option( 'description' );
77
-		$this->enabled              = $this->get_option( 'enabled' );
78
-		$this->testmode             = ( ! empty( $main_settings['testmode'] ) && 'yes' === $main_settings['testmode'] ) ? true : false;
79
-		$this->saved_cards          = ( ! empty( $main_settings['saved_cards'] ) && 'yes' === $main_settings['saved_cards'] ) ? true : false;
80
-		$this->publishable_key      = ! empty( $main_settings['publishable_key'] ) ? $main_settings['publishable_key'] : '';
81
-		$this->secret_key           = ! empty( $main_settings['secret_key'] ) ? $main_settings['secret_key'] : '';
82
-		$this->statement_descriptor = ! empty( $main_settings['statement_descriptor'] ) ? $main_settings['statement_descriptor'] : '';
83
-
84
-		if ( $this->testmode ) {
85
-			$this->publishable_key = ! empty( $main_settings['test_publishable_key'] ) ? $main_settings['test_publishable_key'] : '';
86
-			$this->secret_key      = ! empty( $main_settings['test_secret_key'] ) ? $main_settings['test_secret_key'] : '';
74
+		$main_settings              = get_option('woocommerce_stripe_settings');
75
+		$this->title                = $this->get_option('title');
76
+		$this->description          = $this->get_option('description');
77
+		$this->enabled              = $this->get_option('enabled');
78
+		$this->testmode             = ( ! empty($main_settings['testmode']) && 'yes' === $main_settings['testmode']) ? true : false;
79
+		$this->saved_cards          = ( ! empty($main_settings['saved_cards']) && 'yes' === $main_settings['saved_cards']) ? true : false;
80
+		$this->publishable_key      = ! empty($main_settings['publishable_key']) ? $main_settings['publishable_key'] : '';
81
+		$this->secret_key           = ! empty($main_settings['secret_key']) ? $main_settings['secret_key'] : '';
82
+		$this->statement_descriptor = ! empty($main_settings['statement_descriptor']) ? $main_settings['statement_descriptor'] : '';
83
+
84
+		if ($this->testmode) {
85
+			$this->publishable_key = ! empty($main_settings['test_publishable_key']) ? $main_settings['test_publishable_key'] : '';
86
+			$this->secret_key      = ! empty($main_settings['test_secret_key']) ? $main_settings['test_secret_key'] : '';
87 87
 		}
88 88
 
89
-		add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) );
90
-		add_action( 'admin_notices', array( $this, 'check_environment' ) );
91
-		add_action( 'admin_head', array( $this, 'remove_admin_notice' ) );
92
-		add_action( 'wp_enqueue_scripts', array( $this, 'payment_scripts' ) );
89
+		add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options'));
90
+		add_action('admin_notices', array($this, 'check_environment'));
91
+		add_action('admin_head', array($this, 'remove_admin_notice'));
92
+		add_action('wp_enqueue_scripts', array($this, 'payment_scripts'));
93 93
 	}
94 94
 
95 95
 	/**
@@ -99,19 +99,19 @@  discard block
 block discarded – undo
99 99
 	 * @version 4.0.0
100 100
 	 */
101 101
 	public function check_environment() {
102
-		if ( ! current_user_can( 'manage_woocommerce' ) ) {
102
+		if ( ! current_user_can('manage_woocommerce')) {
103 103
 			return;
104 104
 		}
105 105
 
106 106
 		$environment_warning = $this->get_environment_warning();
107 107
 
108
-		if ( $environment_warning ) {
109
-			$this->add_admin_notice( 'bad_environment', 'error', $environment_warning );
108
+		if ($environment_warning) {
109
+			$this->add_admin_notice('bad_environment', 'error', $environment_warning);
110 110
 		}
111 111
 
112
-		foreach ( (array) $this->notices as $notice_key => $notice ) {
113
-			echo "<div class='" . esc_attr( $notice['class'] ) . "'><p>";
114
-			echo wp_kses( $notice['message'], array( 'a' => array( 'href' => array() ) ) );
112
+		foreach ((array) $this->notices as $notice_key => $notice) {
113
+			echo "<div class='" . esc_attr($notice['class']) . "'><p>";
114
+			echo wp_kses($notice['message'], array('a' => array('href' => array())));
115 115
 			echo '</p></div>';
116 116
 		}
117 117
 	}
@@ -125,10 +125,10 @@  discard block
 block discarded – undo
125 125
 	 */
126 126
 	public function get_environment_warning() {
127 127
 		if (
128
-			'yes' === $this->enabled && ! in_array( get_woocommerce_currency(), $this->get_supported_currency() )
128
+			'yes' === $this->enabled && ! in_array(get_woocommerce_currency(), $this->get_supported_currency())
129 129
 		) {
130 130
 			/* translators: supported currency list */
131
-			$message = sprintf( __( 'Alipay is enabled - it requires store currency to be set to %s', 'woocommerce-gateway-stripe' ), implode( ', ', $this->get_supported_currency() ) );
131
+			$message = sprintf(__('Alipay is enabled - it requires store currency to be set to %s', 'woocommerce-gateway-stripe'), implode(', ', $this->get_supported_currency()));
132 132
 
133 133
 			return $message;
134 134
 		}
@@ -144,7 +144,7 @@  discard block
 block discarded – undo
144 144
 	 * @return array
145 145
 	 */
146 146
 	public function get_supported_currency() {
147
-		return apply_filters( 'wc_stripe_alipay_supported_currencies', array(
147
+		return apply_filters('wc_stripe_alipay_supported_currencies', array(
148 148
 			'EUR',
149 149
 			'AUD',
150 150
 			'CAD',
@@ -154,7 +154,7 @@  discard block
 block discarded – undo
154 154
 			'NZD',
155 155
 			'SGD',
156 156
 			'USD',
157
-		) );
157
+		));
158 158
 	}
159 159
 
160 160
 	/**
@@ -165,7 +165,7 @@  discard block
 block discarded – undo
165 165
 	 * @return bool
166 166
 	 */
167 167
 	public function is_available() {
168
-		if ( ! in_array( get_woocommerce_currency(), $this->get_supported_currency() ) ) {
168
+		if ( ! in_array(get_woocommerce_currency(), $this->get_supported_currency())) {
169 169
 			return false;
170 170
 		}
171 171
 
@@ -186,7 +186,7 @@  discard block
 block discarded – undo
186 186
 
187 187
 		$icons_str .= $icons['alipay'];
188 188
 
189
-		return apply_filters( 'woocommerce_gateway_icon', $icons_str, $this->id );
189
+		return apply_filters('woocommerce_gateway_icon', $icons_str, $this->id);
190 190
 	}
191 191
 
192 192
 	/**
@@ -196,19 +196,19 @@  discard block
 block discarded – undo
196 196
 	 * @version 4.0.0
197 197
 	 */
198 198
 	public function payment_scripts() {
199
-		if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) && ! is_add_payment_method_page() ) {
199
+		if ( ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order']) && ! is_add_payment_method_page()) {
200 200
 			return;
201 201
 		}
202 202
 
203
-		wp_enqueue_style( 'stripe_paymentfonts' );
204
-		wp_enqueue_script( 'woocommerce_stripe' );
203
+		wp_enqueue_style('stripe_paymentfonts');
204
+		wp_enqueue_script('woocommerce_stripe');
205 205
 	}
206 206
 
207 207
 	/**
208 208
 	 * Initialize Gateway Settings Form Fields.
209 209
 	 */
210 210
 	public function init_form_fields() {
211
-		$this->form_fields = require( WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-alipay-settings.php' );
211
+		$this->form_fields = require(WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-alipay-settings.php');
212 212
 	}
213 213
 
214 214
 	/**
@@ -219,25 +219,25 @@  discard block
 block discarded – undo
219 219
 		$total                = WC()->cart->total;
220 220
 
221 221
 		// If paying from order, we need to get total from order not cart.
222
-		if ( isset( $_GET['pay_for_order'] ) && ! empty( $_GET['key'] ) ) {
223
-			$order = wc_get_order( wc_get_order_id_by_order_key( wc_clean( $_GET['key'] ) ) );
222
+		if (isset($_GET['pay_for_order']) && ! empty($_GET['key'])) {
223
+			$order = wc_get_order(wc_get_order_id_by_order_key(wc_clean($_GET['key'])));
224 224
 			$total = $order->get_total();
225 225
 		}
226 226
 
227
-		if ( is_add_payment_method_page() ) {
228
-			$pay_button_text = __( 'Add Payment', 'woocommerce-gateway-stripe' );
229
-			$total        = '';
227
+		if (is_add_payment_method_page()) {
228
+			$pay_button_text = __('Add Payment', 'woocommerce-gateway-stripe');
229
+			$total = '';
230 230
 		} else {
231 231
 			$pay_button_text = '';
232 232
 		}
233 233
 
234 234
 		echo '<div
235 235
 			id="stripe-alipay-payment-data"
236
-			data-amount="' . esc_attr( WC_Stripe_Helper::get_stripe_amount( $total ) ) . '"
237
-			data-currency="' . esc_attr( strtolower( get_woocommerce_currency() ) ) . '">';
236
+			data-amount="' . esc_attr(WC_Stripe_Helper::get_stripe_amount($total)) . '"
237
+			data-currency="' . esc_attr(strtolower(get_woocommerce_currency())) . '">';
238 238
 
239
-		if ( $this->description ) {
240
-			echo apply_filters( 'wc_stripe_description', wpautop( wp_kses_post( $this->description ) ) );
239
+		if ($this->description) {
240
+			echo apply_filters('wc_stripe_description', wpautop(wp_kses_post($this->description)));
241 241
 		}
242 242
 
243 243
 		echo '</div>';
@@ -251,24 +251,24 @@  discard block
 block discarded – undo
251 251
 	 * @param object $order
252 252
 	 * @return mixed
253 253
 	 */
254
-	public function create_source( $order ) {
254
+	public function create_source($order) {
255 255
 		$currency                          = WC_Stripe_Helper::is_pre_30() ? $order->get_order_currency() : $order->get_currency();
256 256
 		$order_id                          = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
257
-		$return_url                        = $this->get_stripe_return_url( $order );
257
+		$return_url                        = $this->get_stripe_return_url($order);
258 258
 		$post_data                         = array();
259
-		$post_data['amount']               = WC_Stripe_Helper::get_stripe_amount( $order->get_total(), $currency );
260
-		$post_data['currency']             = strtolower( $currency );
259
+		$post_data['amount']               = WC_Stripe_Helper::get_stripe_amount($order->get_total(), $currency);
260
+		$post_data['currency']             = strtolower($currency);
261 261
 		$post_data['type']                 = 'alipay';
262
-		$post_data['owner']                = $this->get_owner_details( $order );
263
-		$post_data['redirect']             = array( 'return_url' => $return_url );
262
+		$post_data['owner']                = $this->get_owner_details($order);
263
+		$post_data['redirect']             = array('return_url' => $return_url);
264 264
 
265
-		if ( ! empty( $this->statement_descriptor ) ) {
266
-			$post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor( $this->statement_descriptor );
265
+		if ( ! empty($this->statement_descriptor)) {
266
+			$post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor($this->statement_descriptor);
267 267
 		}
268 268
 
269
-		WC_Stripe_Logger::log( 'Info: Begin creating Alipay source' );
269
+		WC_Stripe_Logger::log('Info: Begin creating Alipay source');
270 270
 
271
-		return WC_Stripe_API::request( apply_filters( 'wc_stripe_alipay_source', $post_data, $order ), 'sources' );
271
+		return WC_Stripe_API::request(apply_filters('wc_stripe_alipay_source', $post_data, $order), 'sources');
272 272
 	}
273 273
 
274 274
 	/**
@@ -282,53 +282,53 @@  discard block
 block discarded – undo
282 282
 	 *
283 283
 	 * @return array|void
284 284
 	 */
285
-	public function process_payment( $order_id, $retry = true, $force_save_save = false ) {
285
+	public function process_payment($order_id, $retry = true, $force_save_save = false) {
286 286
 		try {
287
-			$order = wc_get_order( $order_id );
287
+			$order = wc_get_order($order_id);
288 288
 
289 289
 			// This will throw exception if not valid.
290
-			$this->validate_minimum_order_amount( $order );
290
+			$this->validate_minimum_order_amount($order);
291 291
 
292 292
 			// This comes from the create account checkbox in the checkout page.
293
-			$create_account = ! empty( $_POST['createaccount'] ) ? true : false;
293
+			$create_account = ! empty($_POST['createaccount']) ? true : false;
294 294
 
295
-			if ( $create_account ) {
295
+			if ($create_account) {
296 296
 				$new_customer_id     = WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id();
297
-				$new_stripe_customer = new WC_Stripe_Customer( $new_customer_id );
297
+				$new_stripe_customer = new WC_Stripe_Customer($new_customer_id);
298 298
 				$new_stripe_customer->create_customer();
299 299
 			}
300 300
 
301
-			$response = $this->create_source( $order );
301
+			$response = $this->create_source($order);
302 302
 
303
-			if ( ! empty( $response->error ) ) {
304
-				$order->add_order_note( $response->error->message );
303
+			if ( ! empty($response->error)) {
304
+				$order->add_order_note($response->error->message);
305 305
 
306
-				throw new WC_Stripe_Exception( print_r( $response, true ), $response->error->message );
306
+				throw new WC_Stripe_Exception(print_r($response, true), $response->error->message);
307 307
 			}
308 308
 
309
-			if ( WC_Stripe_Helper::is_pre_30() ) {
310
-				update_post_meta( $order_id, '_stripe_source_id', $response->id );
309
+			if (WC_Stripe_Helper::is_pre_30()) {
310
+				update_post_meta($order_id, '_stripe_source_id', $response->id);
311 311
 			} else {
312
-				$order->update_meta_data( '_stripe_source_id', $response->id );
312
+				$order->update_meta_data('_stripe_source_id', $response->id);
313 313
 				$order->save();
314 314
 			}
315 315
 
316
-			WC_Stripe_Logger::log( 'Info: Redirecting to Alipay...' );
316
+			WC_Stripe_Logger::log('Info: Redirecting to Alipay...');
317 317
 
318 318
 			return array(
319 319
 				'result'   => 'success',
320
-				'redirect' => esc_url_raw( $response->redirect->url ),
320
+				'redirect' => esc_url_raw($response->redirect->url),
321 321
 			);
322
-		} catch ( WC_Stripe_Exception $e ) {
323
-			wc_add_notice( $e->getLocalizedMessage(), 'error' );
324
-			WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() );
322
+		} catch (WC_Stripe_Exception $e) {
323
+			wc_add_notice($e->getLocalizedMessage(), 'error');
324
+			WC_Stripe_Logger::log('Error: ' . $e->getMessage());
325 325
 
326
-			do_action( 'wc_gateway_stripe_process_payment_error', $e, $order );
326
+			do_action('wc_gateway_stripe_process_payment_error', $e, $order);
327 327
 
328
-			$statuses = array( 'pending', 'failed' );
328
+			$statuses = array('pending', 'failed');
329 329
 
330
-			if ( $order->has_status( $statuses ) ) {
331
-				$this->send_failed_order_email( $order_id );
330
+			if ($order->has_status($statuses)) {
331
+				$this->send_failed_order_email($order_id);
332 332
 			}
333 333
 
334 334
 			return array(
Please login to merge, or discard this patch.