Completed
Push — master ( e8a2f0...8d4fd8 )
by Roy
02:22
created
includes/payment-methods/class-wc-stripe-payment-request.php 1 patch
Spacing   +279 added lines, -279 removed lines patch added patch discarded remove patch
@@ -6,7 +6,7 @@  discard block
 block discarded – undo
6 6
  * @since   3.1.0
7 7
  */
8 8
 
9
-if ( ! defined( 'ABSPATH' ) ) {
9
+if ( ! defined('ABSPATH')) {
10 10
 	exit;
11 11
 }
12 12
 
@@ -56,39 +56,39 @@  discard block
 block discarded – undo
56 56
 	 * @version 4.0.0
57 57
 	 */
58 58
 	public function __construct() {
59
-		$this->stripe_settings         = get_option( 'woocommerce_stripe_settings', array() );
60
-		$this->testmode                = ( ! empty( $this->stripe_settings['testmode'] ) && 'yes' === $this->stripe_settings['testmode'] ) ? true : false;
61
-		$this->publishable_key         = ! empty( $this->stripe_settings['publishable_key'] ) ? $this->stripe_settings['publishable_key'] : '';
62
-		$this->stripe_checkout_enabled = isset( $this->stripe_settings['stripe_checkout'] ) && 'yes' === $this->stripe_settings['stripe_checkout'];
63
-		$this->total_label             = ! empty( $this->stripe_settings['statement_descriptor'] ) ? WC_Stripe_Helper::clean_statement_descriptor( $this->stripe_settings['statement_descriptor'] ) : '';
64
-
65
-		if ( $this->testmode ) {
66
-			$this->publishable_key = ! empty( $this->stripe_settings['test_publishable_key'] ) ? $this->stripe_settings['test_publishable_key'] : '';
59
+		$this->stripe_settings         = get_option('woocommerce_stripe_settings', array());
60
+		$this->testmode                = ( ! empty($this->stripe_settings['testmode']) && 'yes' === $this->stripe_settings['testmode']) ? true : false;
61
+		$this->publishable_key         = ! empty($this->stripe_settings['publishable_key']) ? $this->stripe_settings['publishable_key'] : '';
62
+		$this->stripe_checkout_enabled = isset($this->stripe_settings['stripe_checkout']) && 'yes' === $this->stripe_settings['stripe_checkout'];
63
+		$this->total_label             = ! empty($this->stripe_settings['statement_descriptor']) ? WC_Stripe_Helper::clean_statement_descriptor($this->stripe_settings['statement_descriptor']) : '';
64
+
65
+		if ($this->testmode) {
66
+			$this->publishable_key = ! empty($this->stripe_settings['test_publishable_key']) ? $this->stripe_settings['test_publishable_key'] : '';
67 67
 		}
68 68
 
69 69
 		// If both site title and statement descriptor is not set. Fallback.
70
-		if ( empty( $this->total_label ) ) {
70
+		if (empty($this->total_label)) {
71 71
 			$this->total_label = $_SERVER['SERVER_NAME'];
72 72
 		}
73 73
 
74
-		$this->total_label = str_replace( "'", '', $this->total_label ) . apply_filters( 'wc_stripe_payment_request_total_label_suffix', ' (via WooCommerce)' );
74
+		$this->total_label = str_replace("'", '', $this->total_label) . apply_filters('wc_stripe_payment_request_total_label_suffix', ' (via WooCommerce)');
75 75
 
76 76
 		// Checks if Stripe Gateway is enabled.
77
-		if ( empty( $this->stripe_settings ) || ( isset( $this->stripe_settings['enabled'] ) && 'yes' !== $this->stripe_settings['enabled'] ) ) {
77
+		if (empty($this->stripe_settings) || (isset($this->stripe_settings['enabled']) && 'yes' !== $this->stripe_settings['enabled'])) {
78 78
 			return;
79 79
 		}
80 80
 
81 81
 		// Checks if Payment Request is enabled.
82
-		if ( ! isset( $this->stripe_settings['payment_request'] ) || 'yes' !== $this->stripe_settings['payment_request'] ) {
82
+		if ( ! isset($this->stripe_settings['payment_request']) || 'yes' !== $this->stripe_settings['payment_request']) {
83 83
 			return;
84 84
 		}
85 85
 
86 86
 		// Don't load for change payment method page.
87
-		if ( isset( $_GET['change_payment_method'] ) ) {
87
+		if (isset($_GET['change_payment_method'])) {
88 88
 			return;
89 89
 		}
90 90
 
91
-		add_action( 'woocommerce_init', array( $this, 'set_session' ) );
91
+		add_action('woocommerce_init', array($this, 'set_session'));
92 92
 		$this->init();
93 93
 	}
94 94
 
@@ -99,15 +99,15 @@  discard block
 block discarded – undo
99 99
 	 * @since 4.0.0
100 100
 	 */
101 101
 	public function set_session() {
102
-		if ( ! is_user_logged_in() ) {
102
+		if ( ! is_user_logged_in()) {
103 103
 			$wc_session = new WC_Session_Handler();
104 104
 
105
-			if ( version_compare( WC_VERSION, '3.3', '>=' ) ) {
105
+			if (version_compare(WC_VERSION, '3.3', '>=')) {
106 106
 				$wc_session->init();
107 107
 			}
108 108
 
109
-			if ( ! $wc_session->has_session() ) {
110
-				$wc_session->set_customer_session_cookie( true );
109
+			if ( ! $wc_session->has_session()) {
110
+				$wc_session->set_customer_session_cookie(true);
111 111
 			}
112 112
 		}
113 113
 	}
@@ -119,40 +119,40 @@  discard block
 block discarded – undo
119 119
 	 * @version 4.0.0
120 120
 	 */
121 121
 	public function init() {
122
-		add_action( 'wp_enqueue_scripts', array( $this, 'scripts' ) );
122
+		add_action('wp_enqueue_scripts', array($this, 'scripts'));
123 123
 
124 124
 		/*
125 125
 		 * In order to display the Payment Request button in the correct position,
126 126
 		 * a new hook was added to WooCommerce 3.0. In older versions of WooCommerce,
127 127
 		 * CSS is used to position the button.
128 128
 		 */
129
-		if ( WC_Stripe_Helper::is_pre_30() ) {
130
-			add_action( 'woocommerce_after_add_to_cart_button', array( $this, 'display_payment_request_button_html' ), 1 );
131
-			add_action( 'woocommerce_after_add_to_cart_button', array( $this, 'display_payment_request_button_separator_html' ), 2 );
129
+		if (WC_Stripe_Helper::is_pre_30()) {
130
+			add_action('woocommerce_after_add_to_cart_button', array($this, 'display_payment_request_button_html'), 1);
131
+			add_action('woocommerce_after_add_to_cart_button', array($this, 'display_payment_request_button_separator_html'), 2);
132 132
 		} else {
133
-			add_action( 'woocommerce_after_add_to_cart_quantity', array( $this, 'display_payment_request_button_html' ), 1 );
134
-			add_action( 'woocommerce_after_add_to_cart_quantity', array( $this, 'display_payment_request_button_separator_html' ), 2 );
133
+			add_action('woocommerce_after_add_to_cart_quantity', array($this, 'display_payment_request_button_html'), 1);
134
+			add_action('woocommerce_after_add_to_cart_quantity', array($this, 'display_payment_request_button_separator_html'), 2);
135 135
 		}
136 136
 
137
-		add_action( 'woocommerce_proceed_to_checkout', array( $this, 'display_payment_request_button_html' ), 1 );
138
-		add_action( 'woocommerce_proceed_to_checkout', array( $this, 'display_payment_request_button_separator_html' ), 2 );
137
+		add_action('woocommerce_proceed_to_checkout', array($this, 'display_payment_request_button_html'), 1);
138
+		add_action('woocommerce_proceed_to_checkout', array($this, 'display_payment_request_button_separator_html'), 2);
139 139
 
140
-		add_action( 'woocommerce_checkout_before_customer_details', array( $this, 'display_payment_request_button_html' ), 1 );
141
-		add_action( 'woocommerce_checkout_before_customer_details', array( $this, 'display_payment_request_button_separator_html' ), 2 );
140
+		add_action('woocommerce_checkout_before_customer_details', array($this, 'display_payment_request_button_html'), 1);
141
+		add_action('woocommerce_checkout_before_customer_details', array($this, 'display_payment_request_button_separator_html'), 2);
142 142
 
143
-		add_action( 'wc_ajax_wc_stripe_get_cart_details', array( $this, 'ajax_get_cart_details' ) );
144
-		add_action( 'wc_ajax_wc_stripe_get_shipping_options', array( $this, 'ajax_get_shipping_options' ) );
145
-		add_action( 'wc_ajax_wc_stripe_update_shipping_method', array( $this, 'ajax_update_shipping_method' ) );
146
-		add_action( 'wc_ajax_wc_stripe_create_order', array( $this, 'ajax_create_order' ) );
147
-		add_action( 'wc_ajax_wc_stripe_add_to_cart', array( $this, 'ajax_add_to_cart' ) );
148
-		add_action( 'wc_ajax_wc_stripe_get_selected_product_data', array( $this, 'ajax_get_selected_product_data' ) );
149
-		add_action( 'wc_ajax_wc_stripe_clear_cart', array( $this, 'ajax_clear_cart' ) );
150
-		add_action( 'wc_ajax_wc_stripe_log_errors', array( $this, 'ajax_log_errors' ) );
143
+		add_action('wc_ajax_wc_stripe_get_cart_details', array($this, 'ajax_get_cart_details'));
144
+		add_action('wc_ajax_wc_stripe_get_shipping_options', array($this, 'ajax_get_shipping_options'));
145
+		add_action('wc_ajax_wc_stripe_update_shipping_method', array($this, 'ajax_update_shipping_method'));
146
+		add_action('wc_ajax_wc_stripe_create_order', array($this, 'ajax_create_order'));
147
+		add_action('wc_ajax_wc_stripe_add_to_cart', array($this, 'ajax_add_to_cart'));
148
+		add_action('wc_ajax_wc_stripe_get_selected_product_data', array($this, 'ajax_get_selected_product_data'));
149
+		add_action('wc_ajax_wc_stripe_clear_cart', array($this, 'ajax_clear_cart'));
150
+		add_action('wc_ajax_wc_stripe_log_errors', array($this, 'ajax_log_errors'));
151 151
 
152
-		add_filter( 'woocommerce_gateway_title', array( $this, 'filter_gateway_title' ), 10, 2 );
153
-		add_filter( 'woocommerce_validate_postcode', array( $this, 'postal_code_validation' ), 10, 3 );
152
+		add_filter('woocommerce_gateway_title', array($this, 'filter_gateway_title'), 10, 2);
153
+		add_filter('woocommerce_validate_postcode', array($this, 'postal_code_validation'), 10, 3);
154 154
 
155
-		add_action( 'woocommerce_checkout_order_processed', array( $this, 'add_order_meta' ), 10, 2 );
155
+		add_action('woocommerce_checkout_order_processed', array($this, 'add_order_meta'), 10, 2);
156 156
 	}
157 157
 
158 158
 	/**
@@ -163,7 +163,7 @@  discard block
 block discarded – undo
163 163
 	 * @return string
164 164
 	 */
165 165
 	public function get_button_type() {
166
-		return isset( $this->stripe_settings['payment_request_button_type'] ) ? $this->stripe_settings['payment_request_button_type'] : 'default';
166
+		return isset($this->stripe_settings['payment_request_button_type']) ? $this->stripe_settings['payment_request_button_type'] : 'default';
167 167
 	}
168 168
 
169 169
 	/**
@@ -174,7 +174,7 @@  discard block
 block discarded – undo
174 174
 	 * @return string
175 175
 	 */
176 176
 	public function get_button_theme() {
177
-		return isset( $this->stripe_settings['payment_request_button_theme'] ) ? $this->stripe_settings['payment_request_button_theme'] : 'dark';
177
+		return isset($this->stripe_settings['payment_request_button_theme']) ? $this->stripe_settings['payment_request_button_theme'] : 'dark';
178 178
 	}
179 179
 
180 180
 	/**
@@ -185,7 +185,7 @@  discard block
 block discarded – undo
185 185
 	 * @return string
186 186
 	 */
187 187
 	public function get_button_height() {
188
-		return isset( $this->stripe_settings['payment_request_button_height'] ) ? str_replace( 'px', '', $this->stripe_settings['payment_request_button_height'] ) : '64';
188
+		return isset($this->stripe_settings['payment_request_button_height']) ? str_replace('px', '', $this->stripe_settings['payment_request_button_height']) : '64';
189 189
 	}
190 190
 
191 191
 	/**
@@ -195,40 +195,40 @@  discard block
 block discarded – undo
195 195
 	 * @version 4.0.0
196 196
 	 */
197 197
 	public function get_product_data() {
198
-		if ( ! is_product() ) {
198
+		if ( ! is_product()) {
199 199
 			return false;
200 200
 		}
201 201
 
202 202
 		global $post;
203 203
 
204
-		$product = wc_get_product( $post->ID );
204
+		$product = wc_get_product($post->ID);
205 205
 
206 206
 		$data  = array();
207 207
 		$items = array();
208 208
 
209 209
 		$items[] = array(
210 210
 			'label'  => WC_Stripe_Helper::is_pre_30() ? $product->name : $product->get_name(),
211
-			'amount' => WC_Stripe_Helper::get_stripe_amount( WC_Stripe_Helper::is_pre_30() ? $product->price : $product->get_price() ),
211
+			'amount' => WC_Stripe_Helper::get_stripe_amount(WC_Stripe_Helper::is_pre_30() ? $product->price : $product->get_price()),
212 212
 		);
213 213
 
214
-		if ( wc_tax_enabled() ) {
214
+		if (wc_tax_enabled()) {
215 215
 			$items[] = array(
216
-				'label'   => __( 'Tax', 'woocommerce-gateway-stripe' ),
216
+				'label'   => __('Tax', 'woocommerce-gateway-stripe'),
217 217
 				'amount'  => 0,
218 218
 				'pending' => true,
219 219
 			);
220 220
 		}
221 221
 
222
-		if ( wc_shipping_enabled() && $product->needs_shipping() ) {
222
+		if (wc_shipping_enabled() && $product->needs_shipping()) {
223 223
 			$items[] = array(
224
-				'label'   => __( 'Shipping', 'woocommerce-gateway-stripe' ),
224
+				'label'   => __('Shipping', 'woocommerce-gateway-stripe'),
225 225
 				'amount'  => 0,
226 226
 				'pending' => true,
227 227
 			);
228 228
 
229
-			$data['shippingOptions']  = array(
229
+			$data['shippingOptions'] = array(
230 230
 				'id'     => 'pending',
231
-				'label'  => __( 'Pending', 'woocommerce-gateway-stripe' ),
231
+				'label'  => __('Pending', 'woocommerce-gateway-stripe'),
232 232
 				'detail' => '',
233 233
 				'amount' => 0,
234 234
 			);
@@ -236,41 +236,41 @@  discard block
 block discarded – undo
236 236
 
237 237
 		$data['displayItems'] = $items;
238 238
 		$data['total'] = array(
239
-			'label'   => apply_filters( 'wc_stripe_payment_request_total_label', $this->total_label ),
240
-			'amount'  => WC_Stripe_Helper::get_stripe_amount( WC_Stripe_Helper::is_pre_30() ? $product->price : $product->get_price() ),
239
+			'label'   => apply_filters('wc_stripe_payment_request_total_label', $this->total_label),
240
+			'amount'  => WC_Stripe_Helper::get_stripe_amount(WC_Stripe_Helper::is_pre_30() ? $product->price : $product->get_price()),
241 241
 			'pending' => true,
242 242
 		);
243 243
 
244
-		$data['requestShipping'] = ( wc_shipping_enabled() && $product->needs_shipping() );
245
-		$data['currency']        = strtolower( get_woocommerce_currency() );
246
-		$data['country_code']    = substr( get_option( 'woocommerce_default_country' ), 0, 2 );
244
+		$data['requestShipping'] = (wc_shipping_enabled() && $product->needs_shipping());
245
+		$data['currency']        = strtolower(get_woocommerce_currency());
246
+		$data['country_code']    = substr(get_option('woocommerce_default_country'), 0, 2);
247 247
 
248
-		return apply_filters( 'wc_stripe_payment_request_product_data', $data, $product );
248
+		return apply_filters('wc_stripe_payment_request_product_data', $data, $product);
249 249
 	}
250 250
 
251 251
 	/**
252 252
 	 * Filters the gateway title to reflect Payment Request type
253 253
 	 *
254 254
 	 */
255
-	public function filter_gateway_title( $title, $id ) {
255
+	public function filter_gateway_title($title, $id) {
256 256
 		global $post;
257 257
 
258
-		if ( ! is_object( $post ) ) {
258
+		if ( ! is_object($post)) {
259 259
 			return $title;
260 260
 		}
261 261
 
262
-		if ( WC_Stripe_Helper::is_pre_30() ) {
263
-			$method_title = get_post_meta( $post->ID, '_payment_method_title', true );
262
+		if (WC_Stripe_Helper::is_pre_30()) {
263
+			$method_title = get_post_meta($post->ID, '_payment_method_title', true);
264 264
 		} else {
265
-			$order        = wc_get_order( $post->ID );
266
-			$method_title = is_object( $order ) ? $order->get_payment_method_title() : '';
265
+			$order        = wc_get_order($post->ID);
266
+			$method_title = is_object($order) ? $order->get_payment_method_title() : '';
267 267
 		}
268 268
 
269
-		if ( 'stripe' === $id && ! empty( $method_title ) && 'Apple Pay (Stripe)' === $method_title ) {
269
+		if ('stripe' === $id && ! empty($method_title) && 'Apple Pay (Stripe)' === $method_title) {
270 270
 			return $method_title;
271 271
 		}
272 272
 
273
-		if ( 'stripe' === $id && ! empty( $method_title ) && 'Chrome Payment Request (Stripe)' === $method_title ) {
273
+		if ('stripe' === $id && ! empty($method_title) && 'Chrome Payment Request (Stripe)' === $method_title) {
274 274
 			return $method_title;
275 275
 		}
276 276
 
@@ -283,16 +283,16 @@  discard block
 block discarded – undo
283 283
 	 * @since 3.1.4
284 284
 	 * @version 4.0.0
285 285
 	 */
286
-	public function postal_code_validation( $valid, $postcode, $country ) {
286
+	public function postal_code_validation($valid, $postcode, $country) {
287 287
 		$gateways = WC()->payment_gateways->get_available_payment_gateways();
288 288
 
289
-		if ( ! isset( $gateways['stripe'] ) ) {
289
+		if ( ! isset($gateways['stripe'])) {
290 290
 			return $valid;
291 291
 		}
292 292
 
293
-		$payment_request_type = isset( $_POST['payment_request_type'] ) ? wc_clean( $_POST['payment_request_type'] ) : '';
293
+		$payment_request_type = isset($_POST['payment_request_type']) ? wc_clean($_POST['payment_request_type']) : '';
294 294
 
295
-		if ( 'apple_pay' !== $payment_request_type ) {
295
+		if ('apple_pay' !== $payment_request_type) {
296 296
 			return $valid;
297 297
 		}
298 298
 
@@ -302,7 +302,7 @@  discard block
 block discarded – undo
302 302
 		 * the order and not let it go through. The remedy for now is just to remove this validation.
303 303
 		 * Note that this only works with shipping providers that don't validate full postal codes.
304 304
 		 */
305
-		if ( 'GB' === $country || 'CA' === $country ) {
305
+		if ('GB' === $country || 'CA' === $country) {
306 306
 			return true;
307 307
 		}
308 308
 
@@ -317,29 +317,29 @@  discard block
 block discarded – undo
317 317
 	 * @param int $order_id
318 318
 	 * @param array $posted_data The posted data from checkout form.
319 319
 	 */
320
-	public function add_order_meta( $order_id, $posted_data ) {
321
-		if ( empty( $_POST['payment_request_type'] ) ) {
320
+	public function add_order_meta($order_id, $posted_data) {
321
+		if (empty($_POST['payment_request_type'])) {
322 322
 			return;
323 323
 		}
324 324
 
325
-		$order = wc_get_order( $order_id );
325
+		$order = wc_get_order($order_id);
326 326
 
327
-		$payment_request_type = wc_clean( $_POST['payment_request_type'] );
327
+		$payment_request_type = wc_clean($_POST['payment_request_type']);
328 328
 
329
-		if ( 'apple_pay' === $payment_request_type ) {
330
-			if ( WC_Stripe_Helper::is_pre_30() ) {
331
-				update_post_meta( $order_id, '_payment_method_title', 'Apple Pay (Stripe)' );
329
+		if ('apple_pay' === $payment_request_type) {
330
+			if (WC_Stripe_Helper::is_pre_30()) {
331
+				update_post_meta($order_id, '_payment_method_title', 'Apple Pay (Stripe)');
332 332
 			} else {
333
-				$order->set_payment_method_title( 'Apple Pay (Stripe)' );
333
+				$order->set_payment_method_title('Apple Pay (Stripe)');
334 334
 				$order->save();
335 335
 			}
336 336
 		}
337 337
 
338
-		if ( 'payment_request_api' === $payment_request_type ) {
339
-			if ( WC_Stripe_Helper::is_pre_30() ) {
340
-				update_post_meta( $order_id, '_payment_method_title', 'Chrome Payment Request (Stripe)' );
338
+		if ('payment_request_api' === $payment_request_type) {
339
+			if (WC_Stripe_Helper::is_pre_30()) {
340
+				update_post_meta($order_id, '_payment_method_title', 'Chrome Payment Request (Stripe)');
341 341
 			} else {
342
-				$order->set_payment_method_title( 'Chrome Payment Request (Stripe)' );
342
+				$order->set_payment_method_title('Chrome Payment Request (Stripe)');
343 343
 				$order->save();
344 344
 			}
345 345
 		}
@@ -353,11 +353,11 @@  discard block
 block discarded – undo
353 353
 	 * @return array
354 354
 	 */
355 355
 	public function supported_product_types() {
356
-		return apply_filters( 'wc_stripe_payment_request_supported_types', array(
356
+		return apply_filters('wc_stripe_payment_request_supported_types', array(
357 357
 			'simple',
358 358
 			'variable',
359 359
 			'variation',
360
-		) );
360
+		));
361 361
 	}
362 362
 
363 363
 	/**
@@ -368,15 +368,15 @@  discard block
 block discarded – undo
368 368
 	 * @return bool
369 369
 	 */
370 370
 	public function allowed_items_in_cart() {
371
-		foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {
372
-			$_product = apply_filters( 'woocommerce_cart_item_product', $cart_item['data'], $cart_item, $cart_item_key );
371
+		foreach (WC()->cart->get_cart() as $cart_item_key => $cart_item) {
372
+			$_product = apply_filters('woocommerce_cart_item_product', $cart_item['data'], $cart_item, $cart_item_key);
373 373
 
374
-			if ( ! in_array( ( WC_Stripe_Helper::is_pre_30() ? $_product->product_type : $_product->get_type() ), $this->supported_product_types() ) ) {
374
+			if ( ! in_array((WC_Stripe_Helper::is_pre_30() ? $_product->product_type : $_product->get_type()), $this->supported_product_types())) {
375 375
 				return false;
376 376
 			}
377 377
 
378 378
 			// Pre Orders compatbility where we don't support charge upon release.
379
-			if ( class_exists( 'WC_Pre_Orders_Order' ) && WC_Pre_Orders_Cart::cart_contains_pre_order() && WC_Pre_Orders_Product::product_is_charged_upon_release( WC_Pre_Orders_Cart::get_pre_order_product() ) ) {
379
+			if (class_exists('WC_Pre_Orders_Order') && WC_Pre_Orders_Cart::cart_contains_pre_order() && WC_Pre_Orders_Product::product_is_charged_upon_release(WC_Pre_Orders_Cart::get_pre_order_product())) {
380 380
 				return false;
381 381
 			}
382 382
 		}
@@ -391,71 +391,71 @@  discard block
 block discarded – undo
391 391
 	 * @version 4.0.0
392 392
 	 */
393 393
 	public function scripts() {
394
-		if ( ! is_product() && ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) ) {
394
+		if ( ! is_product() && ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order'])) {
395 395
 			return;
396 396
 		}
397 397
 
398
-		if ( is_product() ) {
398
+		if (is_product()) {
399 399
 			global $post;
400 400
 
401
-			$product = wc_get_product( $post->ID );
401
+			$product = wc_get_product($post->ID);
402 402
 
403
-			if ( ! is_object( $product ) || ! in_array( ( WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type() ), $this->supported_product_types() ) ) {
403
+			if ( ! is_object($product) || ! in_array((WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type()), $this->supported_product_types())) {
404 404
 				return;
405 405
 			}
406 406
 
407
-			if ( apply_filters( 'wc_stripe_hide_payment_request_on_product_page', false ) ) {
407
+			if (apply_filters('wc_stripe_hide_payment_request_on_product_page', false)) {
408 408
 				return;
409 409
 			}
410 410
 		}
411 411
 
412
-		$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
412
+		$suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';
413 413
 
414
-		wp_register_script( 'stripe', 'https://js.stripe.com/v3/', '', '3.0', true );
415
-		wp_register_script( 'wc_stripe_payment_request', plugins_url( 'assets/js/stripe-payment-request' . $suffix . '.js', WC_STRIPE_MAIN_FILE ), array( 'jquery', 'stripe' ), WC_STRIPE_VERSION, true );
414
+		wp_register_script('stripe', 'https://js.stripe.com/v3/', '', '3.0', true);
415
+		wp_register_script('wc_stripe_payment_request', plugins_url('assets/js/stripe-payment-request' . $suffix . '.js', WC_STRIPE_MAIN_FILE), array('jquery', 'stripe'), WC_STRIPE_VERSION, true);
416 416
 
417 417
 		wp_localize_script(
418 418
 			'wc_stripe_payment_request',
419 419
 			'wc_stripe_payment_request_params',
420 420
 			array(
421
-				'ajax_url' => WC_AJAX::get_endpoint( '%%endpoint%%' ),
421
+				'ajax_url' => WC_AJAX::get_endpoint('%%endpoint%%'),
422 422
 				'stripe'   => array(
423 423
 					'key'                => $this->publishable_key,
424
-					'allow_prepaid_card' => apply_filters( 'wc_stripe_allow_prepaid_card', true ) ? 'yes' : 'no',
424
+					'allow_prepaid_card' => apply_filters('wc_stripe_allow_prepaid_card', true) ? 'yes' : 'no',
425 425
 				),
426 426
 				'nonce'    => array(
427
-					'payment'                        => wp_create_nonce( 'wc-stripe-payment-request' ),
428
-					'shipping'                       => wp_create_nonce( 'wc-stripe-payment-request-shipping' ),
429
-					'update_shipping'                => wp_create_nonce( 'wc-stripe-update-shipping-method' ),
430
-					'checkout'                       => wp_create_nonce( 'woocommerce-process_checkout' ),
431
-					'add_to_cart'                    => wp_create_nonce( 'wc-stripe-add-to-cart' ),
432
-					'get_selected_product_data'      => wp_create_nonce( 'wc-stripe-get-selected-product-data' ),
433
-					'log_errors'                     => wp_create_nonce( 'wc-stripe-log-errors' ),
434
-					'clear_cart'                     => wp_create_nonce( 'wc-stripe-clear-cart' ),
427
+					'payment'                        => wp_create_nonce('wc-stripe-payment-request'),
428
+					'shipping'                       => wp_create_nonce('wc-stripe-payment-request-shipping'),
429
+					'update_shipping'                => wp_create_nonce('wc-stripe-update-shipping-method'),
430
+					'checkout'                       => wp_create_nonce('woocommerce-process_checkout'),
431
+					'add_to_cart'                    => wp_create_nonce('wc-stripe-add-to-cart'),
432
+					'get_selected_product_data'      => wp_create_nonce('wc-stripe-get-selected-product-data'),
433
+					'log_errors'                     => wp_create_nonce('wc-stripe-log-errors'),
434
+					'clear_cart'                     => wp_create_nonce('wc-stripe-clear-cart'),
435 435
 				),
436 436
 				'i18n'     => array(
437
-					'no_prepaid_card'  => __( 'Sorry, we\'re not accepting prepaid cards at this time.', 'woocommerce-gateway-stripe' ),
437
+					'no_prepaid_card'  => __('Sorry, we\'re not accepting prepaid cards at this time.', 'woocommerce-gateway-stripe'),
438 438
 					/* translators: Do not translate the [option] placeholder */
439
-					'unknown_shipping' => __( 'Unknown shipping option "[option]".', 'woocommerce-gateway-stripe' ),
439
+					'unknown_shipping' => __('Unknown shipping option "[option]".', 'woocommerce-gateway-stripe'),
440 440
 				),
441 441
 				'checkout' => array(
442 442
 					'url'            => wc_get_checkout_url(),
443
-					'currency_code'  => strtolower( get_woocommerce_currency() ),
444
-					'country_code'   => substr( get_option( 'woocommerce_default_country' ), 0, 2 ),
443
+					'currency_code'  => strtolower(get_woocommerce_currency()),
444
+					'country_code'   => substr(get_option('woocommerce_default_country'), 0, 2),
445 445
 					'needs_shipping' => WC()->cart->needs_shipping() ? 'yes' : 'no',
446 446
 				),
447 447
 				'button' => array(
448 448
 					'type'   => $this->get_button_type(),
449 449
 					'theme'  => $this->get_button_theme(),
450 450
 					'height' => $this->get_button_height(),
451
-					'locale' => substr( get_locale(), 0, 2 ), // Default format is en_US.
451
+					'locale' => substr(get_locale(), 0, 2), // Default format is en_US.
452 452
 				),
453 453
 				'is_product_page' => is_product(),
454 454
 				'product'         => $this->get_product_data(),
455 455
 			)
456 456
 		);
457 457
 
458
-		wp_enqueue_script( 'wc_stripe_payment_request' );
458
+		wp_enqueue_script('wc_stripe_payment_request');
459 459
 	}
460 460
 
461 461
 	/**
@@ -467,39 +467,39 @@  discard block
 block discarded – undo
467 467
 	public function display_payment_request_button_html() {
468 468
 		$gateways = WC()->payment_gateways->get_available_payment_gateways();
469 469
 
470
-		if ( ! isset( $gateways['stripe'] ) ) {
470
+		if ( ! isset($gateways['stripe'])) {
471 471
 			return;
472 472
 		}
473 473
 
474
-		if ( ! is_cart() && ! is_checkout() && ! is_product() && ! isset( $_GET['pay_for_order'] ) ) {
474
+		if ( ! is_cart() && ! is_checkout() && ! is_product() && ! isset($_GET['pay_for_order'])) {
475 475
 			return;
476 476
 		}
477 477
 
478
-		if ( is_product() && apply_filters( 'wc_stripe_hide_payment_request_on_product_page', false ) ) {
478
+		if (is_product() && apply_filters('wc_stripe_hide_payment_request_on_product_page', false)) {
479 479
 			return;
480 480
 		}
481 481
 
482
-		if ( is_checkout() && ! apply_filters( 'wc_stripe_show_payment_request_on_checkout', false ) ) {
482
+		if (is_checkout() && ! apply_filters('wc_stripe_show_payment_request_on_checkout', false)) {
483 483
 			return;
484 484
 		}
485 485
 
486
-		if ( is_product() ) {
486
+		if (is_product()) {
487 487
 			global $post;
488 488
 
489
-			$product = wc_get_product( $post->ID );
489
+			$product = wc_get_product($post->ID);
490 490
 
491
-			if ( ! is_object( $product ) || ! in_array( ( WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type() ), $this->supported_product_types() ) ) {
491
+			if ( ! is_object($product) || ! in_array((WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type()), $this->supported_product_types())) {
492 492
 				return;
493 493
 			}
494 494
 
495 495
 			// Pre Orders charge upon release not supported.
496
-			if ( class_exists( 'WC_Pre_Orders_Order' ) && WC_Pre_Orders_Product::product_is_charged_upon_release( $product ) ) {
497
-				WC_Stripe_Logger::log( 'Pre Order charge upon release is not supported. ( Payment Request button disabled )' );
496
+			if (class_exists('WC_Pre_Orders_Order') && WC_Pre_Orders_Product::product_is_charged_upon_release($product)) {
497
+				WC_Stripe_Logger::log('Pre Order charge upon release is not supported. ( Payment Request button disabled )');
498 498
 				return;
499 499
 			}
500 500
 		} else {
501
-			if ( ! $this->allowed_items_in_cart() ) {
502
-				WC_Stripe_Logger::log( 'Items in the cart has unsupported product type ( Payment Request button disabled )' );
501
+			if ( ! $this->allowed_items_in_cart()) {
502
+				WC_Stripe_Logger::log('Items in the cart has unsupported product type ( Payment Request button disabled )');
503 503
 				return;
504 504
 			}
505 505
 		}
@@ -521,44 +521,44 @@  discard block
 block discarded – undo
521 521
 	public function display_payment_request_button_separator_html() {
522 522
 		$gateways = WC()->payment_gateways->get_available_payment_gateways();
523 523
 
524
-		if ( ! isset( $gateways['stripe'] ) ) {
524
+		if ( ! isset($gateways['stripe'])) {
525 525
 			return;
526 526
 		}
527 527
 
528
-		if ( ! is_cart() && ! is_checkout() && ! is_product() && ! isset( $_GET['pay_for_order'] ) ) {
528
+		if ( ! is_cart() && ! is_checkout() && ! is_product() && ! isset($_GET['pay_for_order'])) {
529 529
 			return;
530 530
 		}
531 531
 
532
-		if ( is_product() && apply_filters( 'wc_stripe_hide_payment_request_on_product_page', false ) ) {
532
+		if (is_product() && apply_filters('wc_stripe_hide_payment_request_on_product_page', false)) {
533 533
 			return;
534 534
 		}
535 535
 
536
-		if ( is_checkout() && ! apply_filters( 'wc_stripe_show_payment_request_on_checkout', false ) ) {
536
+		if (is_checkout() && ! apply_filters('wc_stripe_show_payment_request_on_checkout', false)) {
537 537
 			return;
538 538
 		}
539 539
 
540
-		if ( is_product() ) {
540
+		if (is_product()) {
541 541
 			global $post;
542 542
 
543
-			$product = wc_get_product( $post->ID );
543
+			$product = wc_get_product($post->ID);
544 544
 
545
-			if ( ! is_object( $product ) || ! in_array( ( WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type() ), $this->supported_product_types() ) ) {
545
+			if ( ! is_object($product) || ! in_array((WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type()), $this->supported_product_types())) {
546 546
 				return;
547 547
 			}
548 548
 
549 549
 			// Pre Orders charge upon release not supported.
550
-			if ( class_exists( 'WC_Pre_Orders_Order' ) && WC_Pre_Orders_Product::product_is_charged_upon_release( $product ) ) {
551
-				WC_Stripe_Logger::log( 'Pre Order charge upon release is not supported. ( Payment Request button disabled )' );
550
+			if (class_exists('WC_Pre_Orders_Order') && WC_Pre_Orders_Product::product_is_charged_upon_release($product)) {
551
+				WC_Stripe_Logger::log('Pre Order charge upon release is not supported. ( Payment Request button disabled )');
552 552
 				return;
553 553
 			}
554 554
 		} else {
555
-			if ( ! $this->allowed_items_in_cart() ) {
556
-				WC_Stripe_Logger::log( 'Items in the cart has unsupported product type ( Payment Request button disabled )' );
555
+			if ( ! $this->allowed_items_in_cart()) {
556
+				WC_Stripe_Logger::log('Items in the cart has unsupported product type ( Payment Request button disabled )');
557 557
 				return;
558 558
 			}
559 559
 		}
560 560
 		?>
561
-		<p id="wc-stripe-payment-request-button-separator" style="margin-top:1.5em;text-align:center;display:none;">- <?php esc_html_e( 'OR', 'woocommerce-gateway-stripe' ); ?> -</p>
561
+		<p id="wc-stripe-payment-request-button-separator" style="margin-top:1.5em;text-align:center;display:none;">- <?php esc_html_e('OR', 'woocommerce-gateway-stripe'); ?> -</p>
562 562
 		<?php
563 563
 	}
564 564
 
@@ -569,11 +569,11 @@  discard block
 block discarded – undo
569 569
 	 * @version 4.0.0
570 570
 	 */
571 571
 	public function ajax_log_errors() {
572
-		check_ajax_referer( 'wc-stripe-log-errors', 'security' );
572
+		check_ajax_referer('wc-stripe-log-errors', 'security');
573 573
 
574
-		$errors = wc_clean( stripslashes( $_POST['errors'] ) );
574
+		$errors = wc_clean(stripslashes($_POST['errors']));
575 575
 
576
-		WC_Stripe_Logger::log( $errors );
576
+		WC_Stripe_Logger::log($errors);
577 577
 
578 578
 		exit;
579 579
 	}
@@ -585,7 +585,7 @@  discard block
 block discarded – undo
585 585
 	 * @version 4.0.0
586 586
 	 */
587 587
 	public function ajax_clear_cart() {
588
-		check_ajax_referer( 'wc-stripe-clear-cart', 'security' );
588
+		check_ajax_referer('wc-stripe-clear-cart', 'security');
589 589
 
590 590
 		WC()->cart->empty_cart();
591 591
 		exit;
@@ -595,10 +595,10 @@  discard block
 block discarded – undo
595 595
 	 * Get cart details.
596 596
 	 */
597 597
 	public function ajax_get_cart_details() {
598
-		check_ajax_referer( 'wc-stripe-payment-request', 'security' );
598
+		check_ajax_referer('wc-stripe-payment-request', 'security');
599 599
 
600
-		if ( ! defined( 'WOOCOMMERCE_CART' ) ) {
601
-			define( 'WOOCOMMERCE_CART', true );
600
+		if ( ! defined('WOOCOMMERCE_CART')) {
601
+			define('WOOCOMMERCE_CART', true);
602 602
 		}
603 603
 
604 604
 		WC()->cart->calculate_totals();
@@ -609,14 +609,14 @@  discard block
 block discarded – undo
609 609
 		$data = array(
610 610
 			'shipping_required' => WC()->cart->needs_shipping(),
611 611
 			'order_data'        => array(
612
-				'currency'        => strtolower( $currency ),
613
-				'country_code'    => substr( get_option( 'woocommerce_default_country' ), 0, 2 ),
612
+				'currency'        => strtolower($currency),
613
+				'country_code'    => substr(get_option('woocommerce_default_country'), 0, 2),
614 614
 			),
615 615
 		);
616 616
 
617 617
 		$data['order_data'] += $this->build_display_items();
618 618
 
619
-		wp_send_json( $data );
619
+		wp_send_json($data);
620 620
 	}
621 621
 
622 622
 	/**
@@ -627,47 +627,47 @@  discard block
 block discarded – undo
627 627
 	 * @see WC_Shipping::get_packages().
628 628
 	 */
629 629
 	public function ajax_get_shipping_options() {
630
-		check_ajax_referer( 'wc-stripe-payment-request-shipping', 'security' );
630
+		check_ajax_referer('wc-stripe-payment-request-shipping', 'security');
631 631
 
632 632
 		try {
633 633
 			// Set the shipping package.
634
-			$posted = filter_input_array( INPUT_POST, array(
634
+			$posted = filter_input_array(INPUT_POST, array(
635 635
 				'country'   => FILTER_SANITIZE_STRING,
636 636
 				'state'     => FILTER_SANITIZE_STRING,
637 637
 				'postcode'  => FILTER_SANITIZE_STRING,
638 638
 				'city'      => FILTER_SANITIZE_STRING,
639 639
 				'address'   => FILTER_SANITIZE_STRING,
640 640
 				'address_2' => FILTER_SANITIZE_STRING,
641
-			) );
641
+			));
642 642
 
643
-			$this->calculate_shipping( $posted );
643
+			$this->calculate_shipping($posted);
644 644
 
645 645
 			// Set the shipping options.
646 646
 			$data     = array();
647 647
 			$packages = WC()->shipping->get_packages();
648 648
 
649
-			if ( ! empty( $packages ) && WC()->customer->has_calculated_shipping() ) {
650
-				foreach ( $packages as $package_key => $package ) {
651
-					if ( empty( $package['rates'] ) ) {
652
-						throw new Exception( __( 'Unable to find shipping method for address.', 'woocommerce-gateway-stripe' ) );
649
+			if ( ! empty($packages) && WC()->customer->has_calculated_shipping()) {
650
+				foreach ($packages as $package_key => $package) {
651
+					if (empty($package['rates'])) {
652
+						throw new Exception(__('Unable to find shipping method for address.', 'woocommerce-gateway-stripe'));
653 653
 					}
654 654
 
655
-					foreach ( $package['rates'] as $key => $rate ) {
655
+					foreach ($package['rates'] as $key => $rate) {
656 656
 						$data['shipping_options'][] = array(
657 657
 							'id'       => $rate->id,
658 658
 							'label'    => $rate->label,
659 659
 							'detail'   => '',
660
-							'amount'   => WC_Stripe_Helper::get_stripe_amount( $rate->cost ),
660
+							'amount'   => WC_Stripe_Helper::get_stripe_amount($rate->cost),
661 661
 						);
662 662
 					}
663 663
 				}
664 664
 			} else {
665
-				throw new Exception( __( 'Unable to find shipping method for address.', 'woocommerce-gateway-stripe' ) );
665
+				throw new Exception(__('Unable to find shipping method for address.', 'woocommerce-gateway-stripe'));
666 666
 			}
667 667
 
668
-			if ( isset( $data[0] ) ) {
668
+			if (isset($data[0])) {
669 669
 				// Auto select the first shipping method.
670
-				WC()->session->set( 'chosen_shipping_methods', array( $data[0]['id'] ) );
670
+				WC()->session->set('chosen_shipping_methods', array($data[0]['id']));
671 671
 			}
672 672
 
673 673
 			WC()->cart->calculate_totals();
@@ -675,12 +675,12 @@  discard block
 block discarded – undo
675 675
 			$data += $this->build_display_items();
676 676
 			$data['result'] = 'success';
677 677
 
678
-			wp_send_json( $data );
679
-		} catch ( Exception $e ) {
678
+			wp_send_json($data);
679
+		} catch (Exception $e) {
680 680
 			$data += $this->build_display_items();
681 681
 			$data['result'] = 'invalid_shipping_address';
682 682
 
683
-			wp_send_json( $data );
683
+			wp_send_json($data);
684 684
 		}
685 685
 	}
686 686
 
@@ -688,22 +688,22 @@  discard block
 block discarded – undo
688 688
 	 * Update shipping method.
689 689
 	 */
690 690
 	public function ajax_update_shipping_method() {
691
-		check_ajax_referer( 'wc-stripe-update-shipping-method', 'security' );
691
+		check_ajax_referer('wc-stripe-update-shipping-method', 'security');
692 692
 
693
-		if ( ! defined( 'WOOCOMMERCE_CART' ) ) {
694
-			define( 'WOOCOMMERCE_CART', true );
693
+		if ( ! defined('WOOCOMMERCE_CART')) {
694
+			define('WOOCOMMERCE_CART', true);
695 695
 		}
696 696
 
697
-		$chosen_shipping_methods = WC()->session->get( 'chosen_shipping_methods' );
698
-		$shipping_method         = filter_input( INPUT_POST, 'shipping_method', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY );
697
+		$chosen_shipping_methods = WC()->session->get('chosen_shipping_methods');
698
+		$shipping_method         = filter_input(INPUT_POST, 'shipping_method', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY);
699 699
 
700
-		if ( is_array( $shipping_method ) ) {
701
-			foreach ( $shipping_method as $i => $value ) {
702
-				$chosen_shipping_methods[ $i ] = wc_clean( $value );
700
+		if (is_array($shipping_method)) {
701
+			foreach ($shipping_method as $i => $value) {
702
+				$chosen_shipping_methods[$i] = wc_clean($value);
703 703
 			}
704 704
 		}
705 705
 
706
-		WC()->session->set( 'chosen_shipping_methods', $chosen_shipping_methods );
706
+		WC()->session->set('chosen_shipping_methods', $chosen_shipping_methods);
707 707
 
708 708
 		WC()->cart->calculate_totals();
709 709
 
@@ -711,7 +711,7 @@  discard block
 block discarded – undo
711 711
 		$data += $this->build_display_items();
712 712
 		$data['result'] = 'success';
713 713
 
714
-		wp_send_json( $data );
714
+		wp_send_json($data);
715 715
 	}
716 716
 
717 717
 	/**
@@ -722,31 +722,31 @@  discard block
 block discarded – undo
722 722
 	 * @return array $data
723 723
 	 */
724 724
 	public function ajax_get_selected_product_data() {
725
-		check_ajax_referer( 'wc-stripe-get-selected-product-data', 'security' );
725
+		check_ajax_referer('wc-stripe-get-selected-product-data', 'security');
726 726
 
727
-		$product_id = absint( $_POST['product_id'] );
728
-		$qty = ! isset( $_POST['qty'] ) ? 1 : absint( $_POST['qty'] );
727
+		$product_id = absint($_POST['product_id']);
728
+		$qty = ! isset($_POST['qty']) ? 1 : absint($_POST['qty']);
729 729
 
730
-		$product = wc_get_product( $product_id );
730
+		$product = wc_get_product($product_id);
731 731
 
732
-		if ( 'variable' === ( WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type() ) && isset( $_POST['attributes'] ) ) {
733
-			$attributes = array_map( 'wc_clean', $_POST['attributes'] );
732
+		if ('variable' === (WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type()) && isset($_POST['attributes'])) {
733
+			$attributes = array_map('wc_clean', $_POST['attributes']);
734 734
 
735
-			if ( WC_Stripe_Helper::is_pre_30() ) {
736
-				$variation_id = $product->get_matching_variation( $attributes );
735
+			if (WC_Stripe_Helper::is_pre_30()) {
736
+				$variation_id = $product->get_matching_variation($attributes);
737 737
 			} else {
738
-				$data_store = WC_Data_Store::load( 'product' );
739
-				$variation_id = $data_store->find_matching_product_variation( $product, $attributes );
738
+				$data_store = WC_Data_Store::load('product');
739
+				$variation_id = $data_store->find_matching_product_variation($product, $attributes);
740 740
 			}
741 741
 
742
-			if ( ! empty( $variation_id ) ) {
743
-				$product = wc_get_product( $variation_id );
742
+			if ( ! empty($variation_id)) {
743
+				$product = wc_get_product($variation_id);
744 744
 			}
745
-		} elseif ( 'simple' === ( WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type() ) ) {
746
-			$product = wc_get_product( $product_id );
745
+		} elseif ('simple' === (WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type())) {
746
+			$product = wc_get_product($product_id);
747 747
 		}
748 748
 
749
-		$total = $qty * ( WC_Stripe_Helper::is_pre_30() ? $product->price : $product->get_price() );
749
+		$total = $qty * (WC_Stripe_Helper::is_pre_30() ? $product->price : $product->get_price());
750 750
 
751 751
 		$quantity_label = 1 < $qty ? ' (x' . $qty . ')' : '';
752 752
 
@@ -754,28 +754,28 @@  discard block
 block discarded – undo
754 754
 		$items = array();
755 755
 
756 756
 		$items[] = array(
757
-			'label'  => ( WC_Stripe_Helper::is_pre_30() ? $product->name : $product->get_name() ) . $quantity_label,
758
-			'amount' => WC_Stripe_Helper::get_stripe_amount( $total ),
757
+			'label'  => (WC_Stripe_Helper::is_pre_30() ? $product->name : $product->get_name()) . $quantity_label,
758
+			'amount' => WC_Stripe_Helper::get_stripe_amount($total),
759 759
 		);
760 760
 
761
-		if ( wc_tax_enabled() ) {
761
+		if (wc_tax_enabled()) {
762 762
 			$items[] = array(
763
-				'label'   => __( 'Tax', 'woocommerce-gateway-stripe' ),
763
+				'label'   => __('Tax', 'woocommerce-gateway-stripe'),
764 764
 				'amount'  => 0,
765 765
 				'pending' => true,
766 766
 			);
767 767
 		}
768 768
 
769
-		if ( wc_shipping_enabled() && $product->needs_shipping() ) {
769
+		if (wc_shipping_enabled() && $product->needs_shipping()) {
770 770
 			$items[] = array(
771
-				'label'   => __( 'Shipping', 'woocommerce-gateway-stripe' ),
771
+				'label'   => __('Shipping', 'woocommerce-gateway-stripe'),
772 772
 				'amount'  => 0,
773 773
 				'pending' => true,
774 774
 			);
775 775
 
776
-			$data['shippingOptions']  = array(
776
+			$data['shippingOptions'] = array(
777 777
 				'id'     => 'pending',
778
-				'label'  => __( 'Pending', 'woocommerce-gateway-stripe' ),
778
+				'label'  => __('Pending', 'woocommerce-gateway-stripe'),
779 779
 				'detail' => '',
780 780
 				'amount' => 0,
781 781
 			);
@@ -784,15 +784,15 @@  discard block
 block discarded – undo
784 784
 		$data['displayItems'] = $items;
785 785
 		$data['total'] = array(
786 786
 			'label'   => $this->total_label,
787
-			'amount'  => WC_Stripe_Helper::get_stripe_amount( $total ),
787
+			'amount'  => WC_Stripe_Helper::get_stripe_amount($total),
788 788
 			'pending' => true,
789 789
 		);
790 790
 
791
-		$data['requestShipping'] = ( wc_shipping_enabled() && $product->needs_shipping() );
792
-		$data['currency']        = strtolower( get_woocommerce_currency() );
793
-		$data['country_code']    = substr( get_option( 'woocommerce_default_country' ), 0, 2 );
791
+		$data['requestShipping'] = (wc_shipping_enabled() && $product->needs_shipping());
792
+		$data['currency']        = strtolower(get_woocommerce_currency());
793
+		$data['country_code']    = substr(get_option('woocommerce_default_country'), 0, 2);
794 794
 
795
-		wp_send_json( $data );
795
+		wp_send_json($data);
796 796
 	}
797 797
 
798 798
 	/**
@@ -803,37 +803,37 @@  discard block
 block discarded – undo
803 803
 	 * @return array $data
804 804
 	 */
805 805
 	public function ajax_add_to_cart() {
806
-		check_ajax_referer( 'wc-stripe-add-to-cart', 'security' );
806
+		check_ajax_referer('wc-stripe-add-to-cart', 'security');
807 807
 
808
-		if ( ! defined( 'WOOCOMMERCE_CART' ) ) {
809
-			define( 'WOOCOMMERCE_CART', true );
808
+		if ( ! defined('WOOCOMMERCE_CART')) {
809
+			define('WOOCOMMERCE_CART', true);
810 810
 		}
811 811
 
812 812
 		WC()->shipping->reset_shipping();
813 813
 
814
-		$product_id = absint( $_POST['product_id'] );
815
-		$qty = ! isset( $_POST['qty'] ) ? 1 : absint( $_POST['qty'] );
814
+		$product_id = absint($_POST['product_id']);
815
+		$qty = ! isset($_POST['qty']) ? 1 : absint($_POST['qty']);
816 816
 
817
-		$product = wc_get_product( $product_id );
817
+		$product = wc_get_product($product_id);
818 818
 
819 819
 		// First empty the cart to prevent wrong calculation.
820 820
 		WC()->cart->empty_cart();
821 821
 
822
-		if ( 'variable' === ( WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type() ) && isset( $_POST['attributes'] ) ) {
823
-			$attributes = array_map( 'wc_clean', $_POST['attributes'] );
822
+		if ('variable' === (WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type()) && isset($_POST['attributes'])) {
823
+			$attributes = array_map('wc_clean', $_POST['attributes']);
824 824
 
825
-			if ( WC_Stripe_Helper::is_pre_30() ) {
826
-				$variation_id = $product->get_matching_variation( $attributes );
825
+			if (WC_Stripe_Helper::is_pre_30()) {
826
+				$variation_id = $product->get_matching_variation($attributes);
827 827
 			} else {
828
-				$data_store = WC_Data_Store::load( 'product' );
829
-				$variation_id = $data_store->find_matching_product_variation( $product, $attributes );
828
+				$data_store = WC_Data_Store::load('product');
829
+				$variation_id = $data_store->find_matching_product_variation($product, $attributes);
830 830
 			}
831 831
 
832
-			WC()->cart->add_to_cart( $product->get_id(), $qty, $variation_id, $attributes );
832
+			WC()->cart->add_to_cart($product->get_id(), $qty, $variation_id, $attributes);
833 833
 		}
834 834
 
835
-		if ( 'simple' === ( WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type() ) ) {
836
-			WC()->cart->add_to_cart( $product->get_id(), $qty );
835
+		if ('simple' === (WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type())) {
836
+			WC()->cart->add_to_cart($product->get_id(), $qty);
837 837
 		}
838 838
 
839 839
 		WC()->cart->calculate_totals();
@@ -842,7 +842,7 @@  discard block
 block discarded – undo
842 842
 		$data += $this->build_display_items();
843 843
 		$data['result'] = 'success';
844 844
 
845
-		wp_send_json( $data );
845
+		wp_send_json($data);
846 846
 	}
847 847
 
848 848
 	/**
@@ -855,31 +855,31 @@  discard block
 block discarded – undo
855 855
 	 * @version 4.0.0
856 856
 	 */
857 857
 	public function normalize_state() {
858
-		$billing_country  = ! empty( $_POST['billing_country'] ) ? wc_clean( $_POST['billing_country'] ) : '';
859
-		$shipping_country = ! empty( $_POST['shipping_country'] ) ? wc_clean( $_POST['shipping_country'] ) : '';
860
-		$billing_state    = ! empty( $_POST['billing_state'] ) ? wc_clean( $_POST['billing_state'] ) : '';
861
-		$shipping_state   = ! empty( $_POST['shipping_state'] ) ? wc_clean( $_POST['shipping_state'] ) : '';
858
+		$billing_country  = ! empty($_POST['billing_country']) ? wc_clean($_POST['billing_country']) : '';
859
+		$shipping_country = ! empty($_POST['shipping_country']) ? wc_clean($_POST['shipping_country']) : '';
860
+		$billing_state    = ! empty($_POST['billing_state']) ? wc_clean($_POST['billing_state']) : '';
861
+		$shipping_state   = ! empty($_POST['shipping_state']) ? wc_clean($_POST['shipping_state']) : '';
862 862
 
863
-		if ( $billing_state && $billing_country ) {
864
-			$valid_states = WC()->countries->get_states( $billing_country );
863
+		if ($billing_state && $billing_country) {
864
+			$valid_states = WC()->countries->get_states($billing_country);
865 865
 
866 866
 			// Valid states found for country.
867
-			if ( ! empty( $valid_states ) && is_array( $valid_states ) && sizeof( $valid_states ) > 0 ) {
868
-				foreach ( $valid_states as $state_abbr => $state ) {
869
-					if ( preg_match( '/' . preg_quote( $state ) . '/i', $billing_state ) ) {
867
+			if ( ! empty($valid_states) && is_array($valid_states) && sizeof($valid_states) > 0) {
868
+				foreach ($valid_states as $state_abbr => $state) {
869
+					if (preg_match('/' . preg_quote($state) . '/i', $billing_state)) {
870 870
 						$_POST['billing_state'] = $state_abbr;
871 871
 					}
872 872
 				}
873 873
 			}
874 874
 		}
875 875
 
876
-		if ( $shipping_state && $shipping_country ) {
877
-			$valid_states = WC()->countries->get_states( $shipping_country );
876
+		if ($shipping_state && $shipping_country) {
877
+			$valid_states = WC()->countries->get_states($shipping_country);
878 878
 
879 879
 			// Valid states found for country.
880
-			if ( ! empty( $valid_states ) && is_array( $valid_states ) && sizeof( $valid_states ) > 0 ) {
881
-				foreach ( $valid_states as $state_abbr => $state ) {
882
-					if ( preg_match( '/' . preg_quote( $state ) . '/i', $shipping_state ) ) {
880
+			if ( ! empty($valid_states) && is_array($valid_states) && sizeof($valid_states) > 0) {
881
+				foreach ($valid_states as $state_abbr => $state) {
882
+					if (preg_match('/' . preg_quote($state) . '/i', $shipping_state)) {
883 883
 						$_POST['shipping_state'] = $state_abbr;
884 884
 					}
885 885
 				}
@@ -894,19 +894,19 @@  discard block
 block discarded – undo
894 894
 	 * @version 4.0.0
895 895
 	 */
896 896
 	public function ajax_create_order() {
897
-		if ( WC()->cart->is_empty() ) {
898
-			wp_send_json_error( __( 'Empty cart', 'woocommerce-gateway-stripe' ) );
897
+		if (WC()->cart->is_empty()) {
898
+			wp_send_json_error(__('Empty cart', 'woocommerce-gateway-stripe'));
899 899
 		}
900 900
 
901
-		if ( ! defined( 'WOOCOMMERCE_CHECKOUT' ) ) {
902
-			define( 'WOOCOMMERCE_CHECKOUT', true );
901
+		if ( ! defined('WOOCOMMERCE_CHECKOUT')) {
902
+			define('WOOCOMMERCE_CHECKOUT', true);
903 903
 		}
904 904
 
905 905
 		$this->normalize_state();
906 906
 
907 907
 		WC()->checkout()->process_checkout();
908 908
 
909
-		die( 0 );
909
+		die(0);
910 910
 	}
911 911
 
912 912
 	/**
@@ -916,7 +916,7 @@  discard block
 block discarded – undo
916 916
 	 * @version 4.0.0
917 917
 	 * @param array $address
918 918
 	 */
919
-	protected function calculate_shipping( $address = array() ) {
919
+	protected function calculate_shipping($address = array()) {
920 920
 		global $states;
921 921
 
922 922
 		$country   = $address['country'];
@@ -933,28 +933,28 @@  discard block
 block discarded – undo
933 933
 		 * In some versions of Chrome, state can be a full name. So we need
934 934
 		 * to convert that to abbreviation as WC is expecting that.
935 935
 		 */
936
-		if ( 2 < strlen( $state ) ) {
937
-			$state = array_search( ucfirst( strtolower( $state ) ), $states[ $country ] );
936
+		if (2 < strlen($state)) {
937
+			$state = array_search(ucfirst(strtolower($state)), $states[$country]);
938 938
 		}
939 939
 
940 940
 		WC()->shipping->reset_shipping();
941 941
 
942
-		if ( $postcode && WC_Validation::is_postcode( $postcode, $country ) ) {
943
-			$postcode = wc_format_postcode( $postcode, $country );
942
+		if ($postcode && WC_Validation::is_postcode($postcode, $country)) {
943
+			$postcode = wc_format_postcode($postcode, $country);
944 944
 		}
945 945
 
946
-		if ( $country ) {
947
-			WC()->customer->set_location( $country, $state, $postcode, $city );
948
-			WC()->customer->set_shipping_location( $country, $state, $postcode, $city );
946
+		if ($country) {
947
+			WC()->customer->set_location($country, $state, $postcode, $city);
948
+			WC()->customer->set_shipping_location($country, $state, $postcode, $city);
949 949
 		} else {
950 950
 			WC_Stripe_Helper::is_pre_30() ? WC()->customer->set_to_base() : WC()->customer->set_billing_address_to_base();
951 951
 			WC_Stripe_Helper::is_pre_30() ? WC()->customer->set_shipping_to_base() : WC()->customer->set_shipping_address_to_base();
952 952
 		}
953 953
 
954
-		if ( WC_Stripe_Helper::is_pre_30() ) {
955
-			WC()->customer->calculated_shipping( true );
954
+		if (WC_Stripe_Helper::is_pre_30()) {
955
+			WC()->customer->calculated_shipping(true);
956 956
 		} else {
957
-			WC()->customer->set_calculated_shipping( true );
957
+			WC()->customer->set_calculated_shipping(true);
958 958
 			WC()->customer->save();
959 959
 		}
960 960
 
@@ -971,17 +971,17 @@  discard block
 block discarded – undo
971 971
 		$packages[0]['destination']['address']   = $address_1;
972 972
 		$packages[0]['destination']['address_2'] = $address_2;
973 973
 
974
-		foreach ( WC()->cart->get_cart() as $item ) {
975
-			if ( $item['data']->needs_shipping() ) {
976
-				if ( isset( $item['line_total'] ) ) {
974
+		foreach (WC()->cart->get_cart() as $item) {
975
+			if ($item['data']->needs_shipping()) {
976
+				if (isset($item['line_total'])) {
977 977
 					$packages[0]['contents_cost'] += $item['line_total'];
978 978
 				}
979 979
 			}
980 980
 		}
981 981
 
982
-		$packages = apply_filters( 'woocommerce_cart_shipping_packages', $packages );
982
+		$packages = apply_filters('woocommerce_cart_shipping_packages', $packages);
983 983
 
984
-		WC()->shipping->calculate_shipping( $packages );
984
+		WC()->shipping->calculate_shipping($packages);
985 985
 	}
986 986
 
987 987
 	/**
@@ -990,19 +990,19 @@  discard block
 block discarded – undo
990 990
 	 * @since 3.1.0
991 991
 	 * @version 4.0.0
992 992
 	 */
993
-	protected function build_shipping_methods( $shipping_methods ) {
994
-		if ( empty( $shipping_methods ) ) {
993
+	protected function build_shipping_methods($shipping_methods) {
994
+		if (empty($shipping_methods)) {
995 995
 			return array();
996 996
 		}
997 997
 
998 998
 		$shipping = array();
999 999
 
1000
-		foreach ( $shipping_methods as $method ) {
1000
+		foreach ($shipping_methods as $method) {
1001 1001
 			$shipping[] = array(
1002 1002
 				'id'         => $method['id'],
1003 1003
 				'label'      => $method['label'],
1004 1004
 				'detail'     => '',
1005
-				'amount'     => WC_Stripe_Helper::get_stripe_amount( $method['amount']['value'] ),
1005
+				'amount'     => WC_Stripe_Helper::get_stripe_amount($method['amount']['value']),
1006 1006
 			);
1007 1007
 		}
1008 1008
 
@@ -1016,69 +1016,69 @@  discard block
 block discarded – undo
1016 1016
 	 * @version 4.0.0
1017 1017
 	 */
1018 1018
 	protected function build_display_items() {
1019
-		if ( ! defined( 'WOOCOMMERCE_CART' ) ) {
1020
-			define( 'WOOCOMMERCE_CART', true );
1019
+		if ( ! defined('WOOCOMMERCE_CART')) {
1020
+			define('WOOCOMMERCE_CART', true);
1021 1021
 		}
1022 1022
 
1023 1023
 		$items    = array();
1024 1024
 		$subtotal = 0;
1025 1025
 
1026 1026
 		// Default show only subtotal instead of itemization.
1027
-		if ( ! apply_filters( 'wc_stripe_payment_request_hide_itemization', true ) ) {
1028
-			foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {
1027
+		if ( ! apply_filters('wc_stripe_payment_request_hide_itemization', true)) {
1028
+			foreach (WC()->cart->get_cart() as $cart_item_key => $cart_item) {
1029 1029
 				$amount         = $cart_item['line_subtotal'];
1030
-				$subtotal       += $cart_item['line_subtotal'];
1030
+				$subtotal += $cart_item['line_subtotal'];
1031 1031
 				$quantity_label = 1 < $cart_item['quantity'] ? ' (x' . $cart_item['quantity'] . ')' : '';
1032 1032
 
1033 1033
 				$product_name = WC_Stripe_Helper::is_pre_30() ? $cart_item['data']->post->post_title : $cart_item['data']->get_name();
1034 1034
 
1035 1035
 				$item = array(
1036 1036
 					'label'  => $product_name . $quantity_label,
1037
-					'amount' => WC_Stripe_Helper::get_stripe_amount( $amount ),
1037
+					'amount' => WC_Stripe_Helper::get_stripe_amount($amount),
1038 1038
 				);
1039 1039
 
1040 1040
 				$items[] = $item;
1041 1041
 			}
1042 1042
 		}
1043 1043
 
1044
-		$discounts   = wc_format_decimal( WC()->cart->get_cart_discount_total(), WC()->cart->dp );
1045
-		$tax         = wc_format_decimal( WC()->cart->tax_total + WC()->cart->shipping_tax_total, WC()->cart->dp );
1046
-		$shipping    = wc_format_decimal( WC()->cart->shipping_total, WC()->cart->dp );
1047
-		$items_total = wc_format_decimal( WC()->cart->cart_contents_total, WC()->cart->dp ) + $discounts;
1048
-		$order_total = wc_format_decimal( $items_total + $tax + $shipping - $discounts, WC()->cart->dp );
1044
+		$discounts   = wc_format_decimal(WC()->cart->get_cart_discount_total(), WC()->cart->dp);
1045
+		$tax         = wc_format_decimal(WC()->cart->tax_total + WC()->cart->shipping_tax_total, WC()->cart->dp);
1046
+		$shipping    = wc_format_decimal(WC()->cart->shipping_total, WC()->cart->dp);
1047
+		$items_total = wc_format_decimal(WC()->cart->cart_contents_total, WC()->cart->dp) + $discounts;
1048
+		$order_total = wc_format_decimal($items_total + $tax + $shipping - $discounts, WC()->cart->dp);
1049 1049
 
1050
-		if ( wc_tax_enabled() ) {
1050
+		if (wc_tax_enabled()) {
1051 1051
 			$items[] = array(
1052
-				'label'  => esc_html( __( 'Tax', 'woocommerce-gateway-stripe' ) ),
1053
-				'amount' => WC_Stripe_Helper::get_stripe_amount( $tax ),
1052
+				'label'  => esc_html(__('Tax', 'woocommerce-gateway-stripe')),
1053
+				'amount' => WC_Stripe_Helper::get_stripe_amount($tax),
1054 1054
 			);
1055 1055
 		}
1056 1056
 
1057
-		if ( WC()->cart->needs_shipping() ) {
1057
+		if (WC()->cart->needs_shipping()) {
1058 1058
 			$items[] = array(
1059
-				'label'  => esc_html( __( 'Shipping', 'woocommerce-gateway-stripe' ) ),
1060
-				'amount' => WC_Stripe_Helper::get_stripe_amount( $shipping ),
1059
+				'label'  => esc_html(__('Shipping', 'woocommerce-gateway-stripe')),
1060
+				'amount' => WC_Stripe_Helper::get_stripe_amount($shipping),
1061 1061
 			);
1062 1062
 		}
1063 1063
 
1064
-		if ( WC()->cart->has_discount() ) {
1064
+		if (WC()->cart->has_discount()) {
1065 1065
 			$items[] = array(
1066
-				'label'  => esc_html( __( 'Discount', 'woocommerce-gateway-stripe' ) ),
1067
-				'amount' => WC_Stripe_Helper::get_stripe_amount( $discounts ),
1066
+				'label'  => esc_html(__('Discount', 'woocommerce-gateway-stripe')),
1067
+				'amount' => WC_Stripe_Helper::get_stripe_amount($discounts),
1068 1068
 			);
1069 1069
 		}
1070 1070
 
1071
-		if ( version_compare( WC_VERSION, '3.2', '<' ) ) {
1071
+		if (version_compare(WC_VERSION, '3.2', '<')) {
1072 1072
 			$cart_fees = WC()->cart->fees;
1073 1073
 		} else {
1074 1074
 			$cart_fees = WC()->cart->get_fees();
1075 1075
 		}
1076 1076
 
1077 1077
 		// Include fees and taxes as display items.
1078
-		foreach ( $cart_fees as $key => $fee ) {
1078
+		foreach ($cart_fees as $key => $fee) {
1079 1079
 			$items[] = array(
1080 1080
 				'label'  => $fee->name,
1081
-				'amount' => WC_Stripe_Helper::get_stripe_amount( $fee->amount ),
1081
+				'amount' => WC_Stripe_Helper::get_stripe_amount($fee->amount),
1082 1082
 			);
1083 1083
 		}
1084 1084
 
@@ -1086,7 +1086,7 @@  discard block
 block discarded – undo
1086 1086
 			'displayItems' => $items,
1087 1087
 			'total'      => array(
1088 1088
 				'label'   => $this->total_label,
1089
-				'amount'  => max( 0, apply_filters( 'woocommerce_stripe_calculated_total', WC_Stripe_Helper::get_stripe_amount( $order_total ), $order_total, WC()->cart ) ),
1089
+				'amount'  => max(0, apply_filters('woocommerce_stripe_calculated_total', WC_Stripe_Helper::get_stripe_amount($order_total), $order_total, WC()->cart)),
1090 1090
 				'pending' => false,
1091 1091
 			),
1092 1092
 		);
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
 
@@ -23,12 +23,12 @@  discard block
 block discarded – undo
23 23
 
24 24
 		$this->retry_interval = 2;
25 25
 
26
-		add_action( 'wp', array( $this, 'maybe_process_redirect_order' ) );
27
-		add_action( 'woocommerce_order_status_on-hold_to_processing', array( $this, 'capture_payment' ) );
28
-		add_action( 'woocommerce_order_status_on-hold_to_completed', array( $this, 'capture_payment' ) );
29
-		add_action( 'woocommerce_order_status_on-hold_to_cancelled', array( $this, 'cancel_payment' ) );
30
-		add_action( 'woocommerce_order_status_on-hold_to_refunded', array( $this, 'cancel_payment' ) );
31
-		add_action( 'wc_ajax_wc_stripe_validate_checkout', array( $this, 'validate_checkout' ) );
26
+		add_action('wp', array($this, 'maybe_process_redirect_order'));
27
+		add_action('woocommerce_order_status_on-hold_to_processing', array($this, 'capture_payment'));
28
+		add_action('woocommerce_order_status_on-hold_to_completed', array($this, 'capture_payment'));
29
+		add_action('woocommerce_order_status_on-hold_to_cancelled', array($this, 'cancel_payment'));
30
+		add_action('woocommerce_order_status_on-hold_to_refunded', array($this, 'cancel_payment'));
31
+		add_action('wc_ajax_wc_stripe_validate_checkout', array($this, 'validate_checkout'));
32 32
 	}
33 33
 
34 34
 	/**
@@ -49,25 +49,25 @@  discard block
 block discarded – undo
49 49
 	 * @since 4.0.0
50 50
 	 * @version 4.0.0
51 51
 	 */
52
-	public function process_redirect_payment( $order_id, $retry = true ) {
52
+	public function process_redirect_payment($order_id, $retry = true) {
53 53
 		try {
54
-			$source = wc_clean( $_GET['source'] );
54
+			$source = wc_clean($_GET['source']);
55 55
 
56
-			if ( empty( $source ) ) {
56
+			if (empty($source)) {
57 57
 				return;
58 58
 			}
59 59
 
60
-			if ( empty( $order_id ) ) {
60
+			if (empty($order_id)) {
61 61
 				return;
62 62
 			}
63 63
 
64
-			$order = wc_get_order( $order_id );
64
+			$order = wc_get_order($order_id);
65 65
 
66
-			if ( ! is_object( $order ) ) {
66
+			if ( ! is_object($order)) {
67 67
 				return;
68 68
 			}
69 69
 
70
-			if ( 'processing' === $order->get_status() || 'completed' === $order->get_status() || 'on-hold' === $order->get_status() ) {
70
+			if ('processing' === $order->get_status() || 'completed' === $order->get_status() || 'on-hold' === $order->get_status()) {
71 71
 				return;
72 72
 			}
73 73
 
@@ -75,127 +75,127 @@  discard block
 block discarded – undo
75 75
 			$response = null;
76 76
 
77 77
 			// This will throw exception if not valid.
78
-			$this->validate_minimum_order_amount( $order );
78
+			$this->validate_minimum_order_amount($order);
79 79
 
80
-			WC_Stripe_Logger::log( "Info: (Redirect) Begin processing payment for order $order_id for the amount of {$order->get_total()}" );
80
+			WC_Stripe_Logger::log("Info: (Redirect) Begin processing payment for order $order_id for the amount of {$order->get_total()}");
81 81
 
82 82
 			/**
83 83
 			 * First check if the source is chargeable at this time. If not,
84 84
 			 * webhook will take care of it later.
85 85
 			 */
86
-			$source_info = WC_Stripe_API::retrieve( 'sources/' . $source );
86
+			$source_info = WC_Stripe_API::retrieve('sources/' . $source);
87 87
 
88
-			if ( ! empty( $source_info->error ) ) {
89
-				throw new WC_Stripe_Exception( print_r( $source_info, true ), $source_info->error->message );
88
+			if ( ! empty($source_info->error)) {
89
+				throw new WC_Stripe_Exception(print_r($source_info, true), $source_info->error->message);
90 90
 			}
91 91
 
92
-			if ( 'failed' === $source_info->status || 'canceled' === $source_info->status ) {
93
-				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' ) );
92
+			if ('failed' === $source_info->status || 'canceled' === $source_info->status) {
93
+				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'));
94 94
 			}
95 95
 
96 96
 			// If already consumed, then ignore request.
97
-			if ( 'consumed' === $source_info->status ) {
97
+			if ('consumed' === $source_info->status) {
98 98
 				return;
99 99
 			}
100 100
 
101 101
 			// If not chargeable, then ignore request.
102
-			if ( 'chargeable' !== $source_info->status ) {
102
+			if ('chargeable' !== $source_info->status) {
103 103
 				return;
104 104
 			}
105 105
 
106 106
 			// Prep source object.
107 107
 			$source_object           = new stdClass();
108 108
 			$source_object->token_id = '';
109
-			$source_object->customer = $this->get_stripe_customer_id( $order );
109
+			$source_object->customer = $this->get_stripe_customer_id($order);
110 110
 			$source_object->source   = $source_info->id;
111 111
 
112 112
 			// Make the request.
113
-			$response = WC_Stripe_API::request( $this->generate_payment_request( $order, $source_object ) );
113
+			$response = WC_Stripe_API::request($this->generate_payment_request($order, $source_object));
114 114
 
115
-			if ( ! empty( $response->error ) ) {
115
+			if ( ! empty($response->error)) {
116 116
 				// If it is an API error such connection or server, let's retry.
117
-				if ( 'api_connection_error' === $response->error->type || 'api_error' === $response->error->type ) {
118
-					if ( $retry ) {
119
-						sleep( 5 );
120
-						return $this->process_redirect_payment( $order_id, false );
117
+				if ('api_connection_error' === $response->error->type || 'api_error' === $response->error->type) {
118
+					if ($retry) {
119
+						sleep(5);
120
+						return $this->process_redirect_payment($order_id, false);
121 121
 					} else {
122
-						$localized_message = __( 'API connection error and retries exhausted.', 'woocommerce-gateway-stripe' );
123
-						$order->add_order_note( $localized_message );
124
-						throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message );
122
+						$localized_message = __('API connection error and retries exhausted.', 'woocommerce-gateway-stripe');
123
+						$order->add_order_note($localized_message);
124
+						throw new WC_Stripe_Exception(print_r($response, true), $localized_message);
125 125
 					}
126 126
 				}
127 127
 
128 128
 				// We want to retry.
129
-				if ( $this->is_retryable_error( $response->error ) ) {
130
-					if ( $retry ) {
129
+				if ($this->is_retryable_error($response->error)) {
130
+					if ($retry) {
131 131
 						// Don't do anymore retries after this.
132
-						if ( 5 <= $this->retry_interval ) {
133
-							return $this->process_redirect_payment( $order_id, false );
132
+						if (5 <= $this->retry_interval) {
133
+							return $this->process_redirect_payment($order_id, false);
134 134
 						}
135 135
 
136
-						sleep( $this->retry_interval );
136
+						sleep($this->retry_interval);
137 137
 
138 138
 						$this->retry_interval++;
139
-						return $this->process_redirect_payment( $order_id, true );
139
+						return $this->process_redirect_payment($order_id, true);
140 140
 					} else {
141
-						$localized_message = __( 'On going requests error and retries exhausted.', 'woocommerce-gateway-stripe' );
142
-						$order->add_order_note( $localized_message );
143
-						throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message );
141
+						$localized_message = __('On going requests error and retries exhausted.', 'woocommerce-gateway-stripe');
142
+						$order->add_order_note($localized_message);
143
+						throw new WC_Stripe_Exception(print_r($response, true), $localized_message);
144 144
 					}
145 145
 				}
146 146
 
147 147
 				// Customer param wrong? The user may have been deleted on stripe's end. Remove customer_id. Can be retried without.
148
-				if ( preg_match( '/No such customer/i', $response->error->message ) && $retry ) {
149
-					if ( WC_Stripe_Helper::is_pre_30() ) {
150
-						delete_user_meta( $order->customer_user, '_stripe_customer_id' );
151
-						delete_post_meta( $order_id, '_stripe_customer_id' );
148
+				if (preg_match('/No such customer/i', $response->error->message) && $retry) {
149
+					if (WC_Stripe_Helper::is_pre_30()) {
150
+						delete_user_meta($order->customer_user, '_stripe_customer_id');
151
+						delete_post_meta($order_id, '_stripe_customer_id');
152 152
 					} else {
153
-						delete_user_meta( $order->get_customer_id(), '_stripe_customer_id' );
154
-						$order->delete_meta_data( '_stripe_customer_id' );
153
+						delete_user_meta($order->get_customer_id(), '_stripe_customer_id');
154
+						$order->delete_meta_data('_stripe_customer_id');
155 155
 						$order->save();
156 156
 					}
157 157
 
158
-					return $this->process_redirect_payment( $order_id, false );
158
+					return $this->process_redirect_payment($order_id, false);
159 159
 
160
-				} elseif ( preg_match( '/No such token/i', $response->error->message ) && $source_object->token_id ) {
160
+				} elseif (preg_match('/No such token/i', $response->error->message) && $source_object->token_id) {
161 161
 					// Source param wrong? The CARD may have been deleted on stripe's end. Remove token and show message.
162 162
 
163
-					$wc_token = WC_Payment_Tokens::get( $source_object->token_id );
163
+					$wc_token = WC_Payment_Tokens::get($source_object->token_id);
164 164
 					$wc_token->delete();
165
-					$message = __( 'This card is no longer available and has been removed.', 'woocommerce-gateway-stripe' );
166
-					$order->add_order_note( $message );
167
-					throw new WC_Stripe_Exception( print_r( $response, true ), $message );
165
+					$message = __('This card is no longer available and has been removed.', 'woocommerce-gateway-stripe');
166
+					$order->add_order_note($message);
167
+					throw new WC_Stripe_Exception(print_r($response, true), $message);
168 168
 				}
169 169
 
170 170
 				$localized_messages = WC_Stripe_Helper::get_localized_messages();
171 171
 
172
-				if ( 'card_error' === $response->error->type ) {
173
-					$message = isset( $localized_messages[ $response->error->code ] ) ? $localized_messages[ $response->error->code ] : $response->error->message;
172
+				if ('card_error' === $response->error->type) {
173
+					$message = isset($localized_messages[$response->error->code]) ? $localized_messages[$response->error->code] : $response->error->message;
174 174
 				} else {
175
-					$message = isset( $localized_messages[ $response->error->type ] ) ? $localized_messages[ $response->error->type ] : $response->error->message;
175
+					$message = isset($localized_messages[$response->error->type]) ? $localized_messages[$response->error->type] : $response->error->message;
176 176
 				}
177 177
 
178
-				throw new WC_Stripe_Exception( print_r( $response, true ), $message );
178
+				throw new WC_Stripe_Exception(print_r($response, true), $message);
179 179
 			}
180 180
 
181
-			do_action( 'wc_gateway_stripe_process_redirect_payment', $response, $order );
181
+			do_action('wc_gateway_stripe_process_redirect_payment', $response, $order);
182 182
 
183
-			$this->process_response( $response, $order );
183
+			$this->process_response($response, $order);
184 184
 
185
-		} catch ( WC_Stripe_Exception $e ) {
186
-			WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() );
185
+		} catch (WC_Stripe_Exception $e) {
186
+			WC_Stripe_Logger::log('Error: ' . $e->getMessage());
187 187
 
188
-			do_action( 'wc_gateway_stripe_process_redirect_payment_error', $e, $order );
188
+			do_action('wc_gateway_stripe_process_redirect_payment_error', $e, $order);
189 189
 
190 190
 			/* translators: error message */
191
-			$order->update_status( 'failed', sprintf( __( 'Stripe payment failed: %s', 'woocommerce-gateway-stripe' ), $e->getLocalizedMessage() ) );
191
+			$order->update_status('failed', sprintf(__('Stripe payment failed: %s', 'woocommerce-gateway-stripe'), $e->getLocalizedMessage()));
192 192
 
193
-			if ( $order->has_status( array( 'pending', 'failed' ) ) ) {
194
-				$this->send_failed_order_email( $order_id );
193
+			if ($order->has_status(array('pending', 'failed'))) {
194
+				$this->send_failed_order_email($order_id);
195 195
 			}
196 196
 
197
-			wc_add_notice( $e->getLocalizedMessage(), 'error' );
198
-			wp_safe_redirect( wc_get_checkout_url() );
197
+			wc_add_notice($e->getLocalizedMessage(), 'error');
198
+			wp_safe_redirect(wc_get_checkout_url());
199 199
 			exit;
200 200
 		}
201 201
 	}
@@ -207,13 +207,13 @@  discard block
 block discarded – undo
207 207
 	 * @version 4.0.0
208 208
 	 */
209 209
 	public function maybe_process_redirect_order() {
210
-		if ( ! is_order_received_page() || empty( $_GET['client_secret'] ) || empty( $_GET['source'] ) ) {
210
+		if ( ! is_order_received_page() || empty($_GET['client_secret']) || empty($_GET['source'])) {
211 211
 			return;
212 212
 		}
213 213
 
214
-		$order_id = wc_clean( $_GET['order_id'] );
214
+		$order_id = wc_clean($_GET['order_id']);
215 215
 
216
-		$this->process_redirect_payment( $order_id );
216
+		$this->process_redirect_payment($order_id);
217 217
 	}
218 218
 
219 219
 	/**
@@ -223,52 +223,52 @@  discard block
 block discarded – undo
223 223
 	 * @version 4.0.0
224 224
 	 * @param  int $order_id
225 225
 	 */
226
-	public function capture_payment( $order_id ) {
227
-		$order = wc_get_order( $order_id );
226
+	public function capture_payment($order_id) {
227
+		$order = wc_get_order($order_id);
228 228
 
229
-		if ( 'stripe' === ( WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method() ) ) {
230
-			$charge   = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_transaction_id', true ) : $order->get_transaction_id();
231
-			$captured = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_stripe_charge_captured', true ) : $order->get_meta( '_stripe_charge_captured', true );
229
+		if ('stripe' === (WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method())) {
230
+			$charge   = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_transaction_id', true) : $order->get_transaction_id();
231
+			$captured = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_stripe_charge_captured', true) : $order->get_meta('_stripe_charge_captured', true);
232 232
 
233
-			if ( $charge && 'no' === $captured ) {
233
+			if ($charge && 'no' === $captured) {
234 234
 				$order_total = $order->get_total();
235 235
 
236
-				if ( 0 < $order->get_total_refunded() ) {
236
+				if (0 < $order->get_total_refunded()) {
237 237
 					$order_total = $order_total - $order->get_total_refunded();
238 238
 				}
239 239
 
240
-				$result = WC_Stripe_API::request( array(
241
-					'amount'   => WC_Stripe_Helper::get_stripe_amount( $order_total ),
240
+				$result = WC_Stripe_API::request(array(
241
+					'amount'   => WC_Stripe_Helper::get_stripe_amount($order_total),
242 242
 					'expand[]' => 'balance_transaction',
243
-				), 'charges/' . $charge . '/capture' );
243
+				), 'charges/' . $charge . '/capture');
244 244
 
245
-				if ( ! empty( $result->error ) ) {
245
+				if ( ! empty($result->error)) {
246 246
 					/* translators: error message */
247
-					$order->update_status( 'failed', sprintf( __( 'Unable to capture charge! %s', 'woocommerce-gateway-stripe' ), $result->error->message ) );
247
+					$order->update_status('failed', sprintf(__('Unable to capture charge! %s', 'woocommerce-gateway-stripe'), $result->error->message));
248 248
 				} else {
249 249
 					/* translators: transaction id */
250
-					$order->add_order_note( sprintf( __( 'Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe' ), $result->id ) );
251
-					WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, '_stripe_charge_captured', 'yes' ) : $order->update_meta_data( '_stripe_charge_captured', 'yes' );
250
+					$order->add_order_note(sprintf(__('Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe'), $result->id));
251
+					WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, '_stripe_charge_captured', 'yes') : $order->update_meta_data('_stripe_charge_captured', 'yes');
252 252
 
253 253
 					// Store other data such as fees
254
-					WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, '_transaction_id', $result->id ) : $order->set_transaction_id( $result->id );
254
+					WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, '_transaction_id', $result->id) : $order->set_transaction_id($result->id);
255 255
 
256
-					if ( isset( $result->balance_transaction ) && isset( $result->balance_transaction->fee ) ) {
256
+					if (isset($result->balance_transaction) && isset($result->balance_transaction->fee)) {
257 257
 						// Fees and Net needs to both come from Stripe to be accurate as the returned
258 258
 						// values are in the local currency of the Stripe account, not from WC.
259
-						$fee = ! empty( $result->balance_transaction->fee ) ? WC_Stripe_Helper::format_balance_fee( $result->balance_transaction, 'fee' ) : 0;
260
-						$net = ! empty( $result->balance_transaction->net ) ? WC_Stripe_Helper::format_balance_fee( $result->balance_transaction, 'net' ) : 0;
261
-						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 );
262
-						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 );
259
+						$fee = ! empty($result->balance_transaction->fee) ? WC_Stripe_Helper::format_balance_fee($result->balance_transaction, 'fee') : 0;
260
+						$net = ! empty($result->balance_transaction->net) ? WC_Stripe_Helper::format_balance_fee($result->balance_transaction, 'net') : 0;
261
+						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);
262
+						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);
263 263
 					}
264 264
 
265
-					if ( is_callable( array( $order, 'save' ) ) ) {
265
+					if (is_callable(array($order, 'save'))) {
266 266
 						$order->save();
267 267
 					}
268 268
 				}
269 269
 
270 270
 				// This hook fires when admin manually changes order status to processing or completed.
271
-				do_action( 'woocommerce_stripe_process_manual_capture', $order, $result );
271
+				do_action('woocommerce_stripe_process_manual_capture', $order, $result);
272 272
 			}
273 273
 		}
274 274
 	}
@@ -280,14 +280,14 @@  discard block
 block discarded – undo
280 280
 	 * @version 4.0.0
281 281
 	 * @param  int $order_id
282 282
 	 */
283
-	public function cancel_payment( $order_id ) {
284
-		$order = wc_get_order( $order_id );
283
+	public function cancel_payment($order_id) {
284
+		$order = wc_get_order($order_id);
285 285
 
286
-		if ( 'stripe' === ( WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method() ) ) {
287
-			$this->process_refund( $order_id );
286
+		if ('stripe' === (WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method())) {
287
+			$this->process_refund($order_id);
288 288
 
289 289
 			// This hook fires when admin manually changes order status to cancel.
290
-			do_action( 'woocommerce_stripe_process_manual_cancel', $order );
290
+			do_action('woocommerce_stripe_process_manual_cancel', $order);
291 291
 		}
292 292
 	}
293 293
 
@@ -299,21 +299,21 @@  discard block
 block discarded – undo
299 299
 	 * @param string $field
300 300
 	 * @return string $error_field
301 301
 	 */
302
-	public function normalize_field( $field ) {
302
+	public function normalize_field($field) {
303 303
 		$checkout_fields = WC()->checkout->get_checkout_fields();
304 304
 		$org_str         = array();
305 305
 		$replace_str     = array();
306 306
 
307
-		if ( array_key_exists( $field, $checkout_fields['billing'] ) ) {
308
-			$error_field = __( 'Billing', 'woocommerce-gateway-stripe' ) . ' ' . $checkout_fields['billing'][ $field ]['label'];
309
-		} elseif ( array_key_exists( $field, $checkout_fields['shipping'] ) ) {
310
-			$error_field = __( 'Shipping', 'woocommerce-gateway-stripe' ) . ' ' . $checkout_fields['shipping'][ $field ]['label'];
311
-		} elseif ( array_key_exists( $field, $checkout_fields['order'] ) ) {
312
-			$error_field = $checkout_fields['order'][ $field ]['label'];
313
-		} elseif ( array_key_exists( $field, $checkout_fields['account'] ) ) {
314
-			$error_field = $checkout_fields['account'][ $field ]['label'];
307
+		if (array_key_exists($field, $checkout_fields['billing'])) {
308
+			$error_field = __('Billing', 'woocommerce-gateway-stripe') . ' ' . $checkout_fields['billing'][$field]['label'];
309
+		} elseif (array_key_exists($field, $checkout_fields['shipping'])) {
310
+			$error_field = __('Shipping', 'woocommerce-gateway-stripe') . ' ' . $checkout_fields['shipping'][$field]['label'];
311
+		} elseif (array_key_exists($field, $checkout_fields['order'])) {
312
+			$error_field = $checkout_fields['order'][$field]['label'];
313
+		} elseif (array_key_exists($field, $checkout_fields['account'])) {
314
+			$error_field = $checkout_fields['account'][$field]['label'];
315 315
 		} else {
316
-			$error_field = str_replace( '_', ' ', $field );
316
+			$error_field = str_replace('_', ' ', $field);
317 317
 
318 318
 			$org_str[]     = 'stripe';
319 319
 			$replace_str[] = '';
@@ -328,9 +328,9 @@  discard block
 block discarded – undo
328 328
 			$replace_str[] = 'SOFORT';
329 329
 
330 330
 			$org_str[]     = 'owner';
331
-			$replace_str[] = __( 'Owner', 'woocommerce-gateway-stripe' );
331
+			$replace_str[] = __('Owner', 'woocommerce-gateway-stripe');
332 332
 
333
-			$error_field   = str_replace( $org_str, $replace_str, $error_field );
333
+			$error_field   = str_replace($org_str, $replace_str, $error_field);
334 334
 		}
335 335
 
336 336
 		return $error_field;
@@ -343,138 +343,138 @@  discard block
 block discarded – undo
343 343
 	 * @version 4.0.0
344 344
 	 */
345 345
 	public function validate_checkout() {
346
-		if ( ! wp_verify_nonce( $_POST['nonce'], '_wc_stripe_nonce' ) ) {
347
-			wp_die( __( 'Cheatin&#8217; huh?', 'woocommerce-gateway-stripe' ) );
346
+		if ( ! wp_verify_nonce($_POST['nonce'], '_wc_stripe_nonce')) {
347
+			wp_die(__('Cheatin&#8217; huh?', 'woocommerce-gateway-stripe'));
348 348
 		}
349 349
 
350 350
 		$errors = new WP_Error();
351
-		parse_str( $_POST['required_fields'], $required_fields );
352
-		parse_str( $_POST['all_fields'], $all_fields );
353
-		$source_type = isset( $_POST['source_type'] ) ? wc_clean( $_POST['source_type'] ) : '';
351
+		parse_str($_POST['required_fields'], $required_fields);
352
+		parse_str($_POST['all_fields'], $all_fields);
353
+		$source_type = isset($_POST['source_type']) ? wc_clean($_POST['source_type']) : '';
354 354
 		$validate_shipping_fields = false;
355 355
 		$create_account = false;
356 356
 
357
-		$all_fields      = apply_filters( 'wc_stripe_validate_checkout_all_fields', $all_fields );
358
-		$required_fields = apply_filters( 'wc_stripe_validate_checkout_required_fields', $required_fields );
357
+		$all_fields      = apply_filters('wc_stripe_validate_checkout_all_fields', $all_fields);
358
+		$required_fields = apply_filters('wc_stripe_validate_checkout_required_fields', $required_fields);
359 359
 
360
-		array_walk_recursive( $required_fields, 'wc_clean' );
361
-		array_walk_recursive( $all_fields, 'wc_clean' );
360
+		array_walk_recursive($required_fields, 'wc_clean');
361
+		array_walk_recursive($all_fields, 'wc_clean');
362 362
 
363 363
 		/**
364 364
 		 * If ship to different address checkbox is checked then we need
365 365
 		 * to validate shipping fields too.
366 366
 		 */
367
-		if ( isset( $all_fields['ship_to_different_address'] ) ) {
367
+		if (isset($all_fields['ship_to_different_address'])) {
368 368
 			$validate_shipping_fields = true;
369 369
 		}
370 370
 
371 371
 		// Check if createaccount is checked.
372
-		if ( isset( $all_fields['createaccount'] ) ) {
372
+		if (isset($all_fields['createaccount'])) {
373 373
 			$create_account = true;
374 374
 		}
375 375
 
376 376
 		// Check if required fields are empty.
377
-		foreach ( $required_fields as $field => $field_value ) {
377
+		foreach ($required_fields as $field => $field_value) {
378 378
 			// Check for shipping field.
379
-			if ( preg_match( '/^shipping_/', $field ) && ! $validate_shipping_fields ) {
379
+			if (preg_match('/^shipping_/', $field) && ! $validate_shipping_fields) {
380 380
 				continue;
381 381
 			}
382 382
 
383 383
 			// Check create account name.
384
-			if ( 'account_username' === $field && ! $create_account ) {
384
+			if ('account_username' === $field && ! $create_account) {
385 385
 				continue;
386 386
 			}
387 387
 
388 388
 			// Check create account password.
389
-			if ( 'account_password' === $field && ! $create_account ) {
389
+			if ('account_password' === $field && ! $create_account) {
390 390
 				continue;
391 391
 			}
392 392
 
393
-			if ( empty( $field_value ) || '-1' === $field_value ) {
394
-				$error_field = $this->normalize_field( $field );
393
+			if (empty($field_value) || '-1' === $field_value) {
394
+				$error_field = $this->normalize_field($field);
395 395
 				/* translators: error field name */
396
-				$errors->add( 'validation', sprintf( __( '<strong>%s</strong> cannot be empty', 'woocommerce-gateway-stripe' ), $error_field ) );
396
+				$errors->add('validation', sprintf(__('<strong>%s</strong> cannot be empty', 'woocommerce-gateway-stripe'), $error_field));
397 397
 			}
398 398
 		}
399 399
 
400 400
 		// Check if email is valid format.
401
-		if ( ! empty( $required_fields['billing_email'] ) && ! is_email( $required_fields['billing_email'] ) ) {
402
-			$errors->add( 'validation', __( 'Email is not valid', 'woocommerce-gateway-stripe' ) );
401
+		if ( ! empty($required_fields['billing_email']) && ! is_email($required_fields['billing_email'])) {
402
+			$errors->add('validation', __('Email is not valid', 'woocommerce-gateway-stripe'));
403 403
 		}
404 404
 
405 405
 		// Check if phone number is valid format.
406
-		if ( ! empty( $required_fields['billing_phone'] ) ) {
407
-			$phone = wc_format_phone_number( $required_fields['billing_phone'] );
406
+		if ( ! empty($required_fields['billing_phone'])) {
407
+			$phone = wc_format_phone_number($required_fields['billing_phone']);
408 408
 
409
-			if ( '' !== $phone && ! WC_Validation::is_phone( $phone ) ) {
409
+			if ('' !== $phone && ! WC_Validation::is_phone($phone)) {
410 410
 				/* translators: %s: phone number */
411
-				$errors->add( 'validation', __( 'Please enter a valid phone number.', 'woocommerce-gateway-stripe' ) );
411
+				$errors->add('validation', __('Please enter a valid phone number.', 'woocommerce-gateway-stripe'));
412 412
 			}
413 413
 		}
414 414
 
415 415
 		// Check if postal code is valid format.
416
-		if ( ! empty( $required_fields['billing_postcode'] ) ) {
417
-			$country = isset( $required_fields['billing_country'] ) ? $required_fields['billing_country'] : WC()->customer->get_billing_country();
418
-			$postcode = wc_format_postcode( $required_fields['billing_postcode'], $country );
416
+		if ( ! empty($required_fields['billing_postcode'])) {
417
+			$country = isset($required_fields['billing_country']) ? $required_fields['billing_country'] : WC()->customer->get_billing_country();
418
+			$postcode = wc_format_postcode($required_fields['billing_postcode'], $country);
419 419
 
420
-			if ( '' !== $required_fields['billing_postcode'] && ! WC_Validation::is_postcode( $postcode, $country ) ) {
421
-				$errors->add( 'validation', __( 'Please enter a valid billing postcode / ZIP.', 'woocommerce-gateway-stripe' ) );
420
+			if ('' !== $required_fields['billing_postcode'] && ! WC_Validation::is_postcode($postcode, $country)) {
421
+				$errors->add('validation', __('Please enter a valid billing postcode / ZIP.', 'woocommerce-gateway-stripe'));
422 422
 			}
423 423
 		}
424 424
 
425 425
 		// Don't check this on add payment method page.
426
-		if ( ( isset( $_POST['is_add_payment_page'] ) && 'no' === $_POST['is_add_payment_page'] ) ) {
427
-			if ( empty( $all_fields['woocommerce_checkout_update_totals'] ) && empty( $all_fields['terms'] ) && apply_filters( 'woocommerce_checkout_show_terms', wc_get_page_id( 'terms' ) > 0 ) ) {
428
-				$errors->add( 'terms', __( 'You must accept our Terms &amp; Conditions.', 'woocommerce-gateway-stripe' ) );
426
+		if ((isset($_POST['is_add_payment_page']) && 'no' === $_POST['is_add_payment_page'])) {
427
+			if (empty($all_fields['woocommerce_checkout_update_totals']) && empty($all_fields['terms']) && apply_filters('woocommerce_checkout_show_terms', wc_get_page_id('terms') > 0)) {
428
+				$errors->add('terms', __('You must accept our Terms &amp; Conditions.', 'woocommerce-gateway-stripe'));
429 429
 			}
430 430
 		}
431 431
 
432
-		if ( WC()->cart->needs_shipping() && $validate_shipping_fields ) {
432
+		if (WC()->cart->needs_shipping() && $validate_shipping_fields) {
433 433
 			// Check if postal code is valid format.
434
-			if ( ! empty( $required_fields['shipping_postcode'] ) ) {
435
-				$country = isset( $required_fields['shipping_country'] ) ? $required_fields['shipping_country'] : WC()->customer->get_shipping_country();
436
-				$postcode = wc_format_postcode( $required_fields['shipping_postcode'], $country );
434
+			if ( ! empty($required_fields['shipping_postcode'])) {
435
+				$country = isset($required_fields['shipping_country']) ? $required_fields['shipping_country'] : WC()->customer->get_shipping_country();
436
+				$postcode = wc_format_postcode($required_fields['shipping_postcode'], $country);
437 437
 
438
-				if ( '' !== $required_fields['shipping_postcode'] && ! WC_Validation::is_postcode( $postcode, $country ) ) {
439
-					$errors->add( 'validation', __( 'Please enter a valid shipping postcode / ZIP.', 'woocommerce-gateway-stripe' ) );
438
+				if ('' !== $required_fields['shipping_postcode'] && ! WC_Validation::is_postcode($postcode, $country)) {
439
+					$errors->add('validation', __('Please enter a valid shipping postcode / ZIP.', 'woocommerce-gateway-stripe'));
440 440
 				}
441 441
 			}
442 442
 		}
443 443
 
444
-		if ( WC()->cart->needs_shipping() ) {
444
+		if (WC()->cart->needs_shipping()) {
445 445
 			$shipping_country = WC()->customer->get_shipping_country();
446 446
 
447
-			if ( empty( $shipping_country ) ) {
448
-				$errors->add( 'shipping', __( 'Please enter an address to continue.', 'woocommerce-gateway-stripe' ) );
449
-			} elseif ( ! in_array( WC()->customer->get_shipping_country(), array_keys( WC()->countries->get_shipping_countries() ) ) ) {
447
+			if (empty($shipping_country)) {
448
+				$errors->add('shipping', __('Please enter an address to continue.', 'woocommerce-gateway-stripe'));
449
+			} elseif ( ! in_array(WC()->customer->get_shipping_country(), array_keys(WC()->countries->get_shipping_countries()))) {
450 450
 				/* translators: country name */
451
-				$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() ) );
451
+				$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()));
452 452
 			} else {
453
-				$chosen_shipping_methods = WC()->session->get( 'chosen_shipping_methods' );
453
+				$chosen_shipping_methods = WC()->session->get('chosen_shipping_methods');
454 454
 
455
-				foreach ( WC()->shipping->get_packages() as $i => $package ) {
456
-					if ( ! isset( $chosen_shipping_methods[ $i ], $package['rates'][ $chosen_shipping_methods[ $i ] ] ) ) {
457
-						$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
+				foreach (WC()->shipping->get_packages() as $i => $package) {
456
+					if ( ! isset($chosen_shipping_methods[$i], $package['rates'][$chosen_shipping_methods[$i]])) {
457
+						$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'));
458 458
 					}
459 459
 				}
460 460
 			}
461 461
 		}
462 462
 
463
-		if ( WC()->cart->needs_payment() ) {
463
+		if (WC()->cart->needs_payment()) {
464 464
 			$available_gateways = WC()->payment_gateways->get_available_payment_gateways();
465 465
 
466
-			if ( ! isset( $available_gateways[ $all_fields['payment_method'] ] ) ) {
467
-				$errors->add( 'payment', __( 'Invalid payment method.', 'woocommerce-gateway-stripe' ) );
466
+			if ( ! isset($available_gateways[$all_fields['payment_method']])) {
467
+				$errors->add('payment', __('Invalid payment method.', 'woocommerce-gateway-stripe'));
468 468
 			} else {
469
-				$available_gateways[ $all_fields['payment_method'] ]->validate_fields();
469
+				$available_gateways[$all_fields['payment_method']]->validate_fields();
470 470
 			}
471 471
 		}
472 472
 
473
-		if ( 0 === count( $errors->errors ) ) {
474
-			wp_send_json( 'success' );
473
+		if (0 === count($errors->errors)) {
474
+			wp_send_json('success');
475 475
 		} else {
476
-			foreach ( $errors->get_error_messages() as $message ) {
477
-				wc_add_notice( $message, 'error' );
476
+			foreach ($errors->get_error_messages() as $message) {
477
+				wc_add_notice($message, 'error');
478 478
 			}
479 479
 
480 480
 			$this->send_ajax_failure_response();
@@ -488,9 +488,9 @@  discard block
 block discarded – undo
488 488
 	 * @version 4.0.0
489 489
 	 */
490 490
 	public function send_ajax_failure_response() {
491
-		if ( is_ajax() ) {
491
+		if (is_ajax()) {
492 492
 			// only print notices if not reloading the checkout, otherwise they're lost in the page reload.
493
-			if ( ! isset( WC()->session->reload_checkout ) ) {
493
+			if ( ! isset(WC()->session->reload_checkout)) {
494 494
 				ob_start();
495 495
 				wc_print_notices();
496 496
 				$messages = ob_get_clean();
@@ -498,14 +498,14 @@  discard block
 block discarded – undo
498 498
 
499 499
 			$response = array(
500 500
 				'result'   => 'failure',
501
-				'messages' => isset( $messages ) ? $messages : '',
502
-				'refresh'  => isset( WC()->session->refresh_totals ),
503
-				'reload'   => isset( WC()->session->reload_checkout ),
501
+				'messages' => isset($messages) ? $messages : '',
502
+				'refresh'  => isset(WC()->session->refresh_totals),
503
+				'reload'   => isset(WC()->session->reload_checkout),
504 504
 			);
505 505
 
506
-			unset( WC()->session->refresh_totals, WC()->session->reload_checkout );
506
+			unset(WC()->session->refresh_totals, WC()->session->reload_checkout);
507 507
 
508
-			wp_send_json( $response );
508
+			wp_send_json($response);
509 509
 		}
510 510
 	}
511 511
 }
Please login to merge, or discard this patch.
includes/class-wc-stripe-webhook-handler.php 1 patch
Spacing   +157 added lines, -157 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,7 +20,7 @@  discard block
 block discarded – undo
20 20
 	 */
21 21
 	public function __construct() {
22 22
 		$this->retry_interval = 2;
23
-		add_action( 'woocommerce_api_wc_stripe', array( $this, 'check_for_webhook' ) );
23
+		add_action('woocommerce_api_wc_stripe', array($this, 'check_for_webhook'));
24 24
 	}
25 25
 
26 26
 	/**
@@ -30,24 +30,24 @@  discard block
 block discarded – undo
30 30
 	 * @version 4.0.0
31 31
 	 */
32 32
 	public function check_for_webhook() {
33
-		if ( ( 'POST' !== $_SERVER['REQUEST_METHOD'] )
34
-			|| ! isset( $_GET['wc-api'] )
35
-			|| ( 'wc_stripe' !== $_GET['wc-api'] )
33
+		if (('POST' !== $_SERVER['REQUEST_METHOD'])
34
+			|| ! isset($_GET['wc-api'])
35
+			|| ('wc_stripe' !== $_GET['wc-api'])
36 36
 		) {
37 37
 			return;
38 38
 		}
39 39
 
40
-		$request_body    = file_get_contents( 'php://input' );
41
-		$request_headers = array_change_key_case( $this->get_request_headers(), CASE_UPPER );
40
+		$request_body    = file_get_contents('php://input');
41
+		$request_headers = array_change_key_case($this->get_request_headers(), CASE_UPPER);
42 42
 
43 43
 		// Validate it to make sure it is legit.
44
-		if ( $this->is_valid_request( $request_headers, $request_body ) ) {
45
-			$this->process_webhook( $request_body );
46
-			status_header( 200 );
44
+		if ($this->is_valid_request($request_headers, $request_body)) {
45
+			$this->process_webhook($request_body);
46
+			status_header(200);
47 47
 			exit;
48 48
 		} else {
49
-			WC_Stripe_Logger::log( 'Incoming webhook failed validation: ' . print_r( $request_body, true ) );
50
-			status_header( 400 );
49
+			WC_Stripe_Logger::log('Incoming webhook failed validation: ' . print_r($request_body, true));
50
+			status_header(400);
51 51
 			exit;
52 52
 		}
53 53
 	}
@@ -62,12 +62,12 @@  discard block
 block discarded – undo
62 62
 	 * @param string $request_body The request body from Stripe.
63 63
 	 * @return bool
64 64
 	 */
65
-	public function is_valid_request( $request_headers = null, $request_body = null ) {
66
-		if ( null === $request_headers || null === $request_body ) {
65
+	public function is_valid_request($request_headers = null, $request_body = null) {
66
+		if (null === $request_headers || null === $request_body) {
67 67
 			return false;
68 68
 		}
69 69
 
70
-		if ( ! empty( $request_headers['USER-AGENT'] ) && ! preg_match( '/Stripe/', $request_headers['USER-AGENT'] ) ) {
70
+		if ( ! empty($request_headers['USER-AGENT']) && ! preg_match('/Stripe/', $request_headers['USER-AGENT'])) {
71 71
 			return false;
72 72
 		}
73 73
 
@@ -83,11 +83,11 @@  discard block
 block discarded – undo
83 83
 	 * @version 4.0.0
84 84
 	 */
85 85
 	public function get_request_headers() {
86
-		if ( ! function_exists( 'getallheaders' ) ) {
86
+		if ( ! function_exists('getallheaders')) {
87 87
 			$headers = [];
88
-			foreach ( $_SERVER as $name => $value ) {
89
-				if ( 'HTTP_' === substr( $name, 0, 5 ) ) {
90
-					$headers[ str_replace( ' ', '-', ucwords( strtolower( str_replace( '_', ' ', substr( $name, 5 ) ) ) ) ) ] = $value;
88
+			foreach ($_SERVER as $name => $value) {
89
+				if ('HTTP_' === substr($name, 0, 5)) {
90
+					$headers[str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', substr($name, 5)))))] = $value;
91 91
 				}
92 92
 			}
93 93
 
@@ -106,30 +106,30 @@  discard block
 block discarded – undo
106 106
 	 * @param object $notification
107 107
 	 * @param bool $retry
108 108
 	 */
109
-	public function process_webhook_payment( $notification, $retry = true ) {
109
+	public function process_webhook_payment($notification, $retry = true) {
110 110
 		// The following 2 payment methods are synchronous so does not need to be handle via webhook.
111
-		if ( 'card' === $notification->data->object->type || 'sepa_debit' === $notification->data->object->type ) {
111
+		if ('card' === $notification->data->object->type || 'sepa_debit' === $notification->data->object->type) {
112 112
 			return;
113 113
 		}
114 114
 
115
-		$order = WC_Stripe_Helper::get_order_by_source_id( $notification->data->object->id );
115
+		$order = WC_Stripe_Helper::get_order_by_source_id($notification->data->object->id);
116 116
 
117
-		if ( ! $order ) {
118
-			WC_Stripe_Logger::log( 'Could not find order via source ID: ' . $notification->data->object->id );
117
+		if ( ! $order) {
118
+			WC_Stripe_Logger::log('Could not find order via source ID: ' . $notification->data->object->id);
119 119
 			return;
120 120
 		}
121 121
 
122 122
 		$order_id  = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
123 123
 		$source_id = $notification->data->object->id;
124 124
 
125
-		$is_pending_receiver = ( 'receiver' === $notification->data->object->flow );
125
+		$is_pending_receiver = ('receiver' === $notification->data->object->flow);
126 126
 
127 127
 		try {
128
-			if ( 'processing' === $order->get_status() || 'completed' === $order->get_status() ) {
128
+			if ('processing' === $order->get_status() || 'completed' === $order->get_status()) {
129 129
 				return;
130 130
 			}
131 131
 
132
-			if ( 'on-hold' === $order->get_status() && ! $is_pending_receiver ) {
132
+			if ('on-hold' === $order->get_status() && ! $is_pending_receiver) {
133 133
 				return;
134 134
 			}
135 135
 
@@ -137,100 +137,100 @@  discard block
 block discarded – undo
137 137
 			$response = null;
138 138
 
139 139
 			// This will throw exception if not valid.
140
-			$this->validate_minimum_order_amount( $order );
140
+			$this->validate_minimum_order_amount($order);
141 141
 
142
-			WC_Stripe_Logger::log( "Info: (Webhook) Begin processing payment for order $order_id for the amount of {$order->get_total()}" );
142
+			WC_Stripe_Logger::log("Info: (Webhook) Begin processing payment for order $order_id for the amount of {$order->get_total()}");
143 143
 
144 144
 			// Prep source object.
145 145
 			$source_object           = new stdClass();
146 146
 			$source_object->token_id = '';
147
-			$source_object->customer = $this->get_stripe_customer_id( $order );
147
+			$source_object->customer = $this->get_stripe_customer_id($order);
148 148
 			$source_object->source   = $source_id;
149 149
 
150 150
 			// Make the request.
151
-			$response = WC_Stripe_API::request( $this->generate_payment_request( $order, $source_object ) );
151
+			$response = WC_Stripe_API::request($this->generate_payment_request($order, $source_object));
152 152
 
153
-			if ( ! empty( $response->error ) ) {
153
+			if ( ! empty($response->error)) {
154 154
 				// If it is an API error such connection or server, let's retry.
155
-				if ( 'api_connection_error' === $response->error->type || 'api_error' === $response->error->type ) {
156
-					if ( $retry ) {
157
-						sleep( 5 );
158
-						return $this->process_webhook_payment( $notification, false );
155
+				if ('api_connection_error' === $response->error->type || 'api_error' === $response->error->type) {
156
+					if ($retry) {
157
+						sleep(5);
158
+						return $this->process_webhook_payment($notification, false);
159 159
 					} else {
160 160
 						$localized_message = 'API connection error and retries exhausted.';
161
-						$order->add_order_note( $localized_message );
162
-						throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message );
161
+						$order->add_order_note($localized_message);
162
+						throw new WC_Stripe_Exception(print_r($response, true), $localized_message);
163 163
 					}
164 164
 				}
165 165
 
166 166
 				// We want to retry.
167
-				if ( $this->is_retryable_error( $response->error ) ) {
168
-					if ( $retry ) {
167
+				if ($this->is_retryable_error($response->error)) {
168
+					if ($retry) {
169 169
 						// Don't do anymore retries after this.
170
-						if ( 5 <= $this->retry_interval ) {
170
+						if (5 <= $this->retry_interval) {
171 171
 
172
-							return $this->process_webhook_payment( $notification, false );
172
+							return $this->process_webhook_payment($notification, false);
173 173
 						}
174 174
 
175
-						sleep( $this->retry_interval );
175
+						sleep($this->retry_interval);
176 176
 
177 177
 						$this->retry_interval++;
178
-						return $this->process_webhook_payment( $notification, true );
178
+						return $this->process_webhook_payment($notification, true);
179 179
 					} else {
180
-						$localized_message = __( 'On going requests error and retries exhausted.', 'woocommerce-gateway-stripe' );
181
-						$order->add_order_note( $localized_message );
182
-						throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message );
180
+						$localized_message = __('On going requests error and retries exhausted.', 'woocommerce-gateway-stripe');
181
+						$order->add_order_note($localized_message);
182
+						throw new WC_Stripe_Exception(print_r($response, true), $localized_message);
183 183
 					}
184 184
 				}
185 185
 
186 186
 				// Customer param wrong? The user may have been deleted on stripe's end. Remove customer_id. Can be retried without.
187
-				if ( preg_match( '/No such customer/i', $response->error->message ) && $retry ) {
188
-					if ( WC_Stripe_Helper::is_pre_30() ) {
189
-						delete_user_meta( $order->customer_user, '_stripe_customer_id' );
190
-						delete_post_meta( $order_id, '_stripe_customer_id' );
187
+				if (preg_match('/No such customer/i', $response->error->message) && $retry) {
188
+					if (WC_Stripe_Helper::is_pre_30()) {
189
+						delete_user_meta($order->customer_user, '_stripe_customer_id');
190
+						delete_post_meta($order_id, '_stripe_customer_id');
191 191
 					} else {
192
-						delete_user_meta( $order->get_customer_id(), '_stripe_customer_id' );
193
-						$order->delete_meta_data( '_stripe_customer_id' );
192
+						delete_user_meta($order->get_customer_id(), '_stripe_customer_id');
193
+						$order->delete_meta_data('_stripe_customer_id');
194 194
 						$order->save();
195 195
 					}
196 196
 
197
-					return $this->process_webhook_payment( $notification, false );
197
+					return $this->process_webhook_payment($notification, false);
198 198
 
199
-				} elseif ( preg_match( '/No such token/i', $response->error->message ) && $source_object->token_id ) {
199
+				} elseif (preg_match('/No such token/i', $response->error->message) && $source_object->token_id) {
200 200
 					// Source param wrong? The CARD may have been deleted on stripe's end. Remove token and show message.
201
-					$wc_token = WC_Payment_Tokens::get( $source_object->token_id );
201
+					$wc_token = WC_Payment_Tokens::get($source_object->token_id);
202 202
 					$wc_token->delete();
203
-					$message = __( 'This card is no longer available and has been removed.', 'woocommerce-gateway-stripe' );
204
-					$order->add_order_note( $message );
205
-					throw new WC_Stripe_Exception( print_r( $response, true ), $message );
203
+					$message = __('This card is no longer available and has been removed.', 'woocommerce-gateway-stripe');
204
+					$order->add_order_note($message);
205
+					throw new WC_Stripe_Exception(print_r($response, true), $message);
206 206
 				}
207 207
 
208 208
 				$localized_messages = WC_Stripe_Helper::get_localized_messages();
209 209
 
210
-				if ( 'card_error' === $response->error->type ) {
211
-					$localized_message = isset( $localized_messages[ $response->error->code ] ) ? $localized_messages[ $response->error->code ] : $response->error->message;
210
+				if ('card_error' === $response->error->type) {
211
+					$localized_message = isset($localized_messages[$response->error->code]) ? $localized_messages[$response->error->code] : $response->error->message;
212 212
 				} else {
213
-					$localized_message = isset( $localized_messages[ $response->error->type ] ) ? $localized_messages[ $response->error->type ] : $response->error->message;
213
+					$localized_message = isset($localized_messages[$response->error->type]) ? $localized_messages[$response->error->type] : $response->error->message;
214 214
 				}
215 215
 
216
-				$order->add_order_note( $localized_message );
216
+				$order->add_order_note($localized_message);
217 217
 
218
-				throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message );
218
+				throw new WC_Stripe_Exception(print_r($response, true), $localized_message);
219 219
 			}
220 220
 
221
-			do_action( 'wc_gateway_stripe_process_webhook_payment', $response, $order );
221
+			do_action('wc_gateway_stripe_process_webhook_payment', $response, $order);
222 222
 
223
-			$this->process_response( $response, $order );
223
+			$this->process_response($response, $order);
224 224
 
225
-		} catch ( WC_Stripe_Exception $e ) {
226
-			WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() );
225
+		} catch (WC_Stripe_Exception $e) {
226
+			WC_Stripe_Logger::log('Error: ' . $e->getMessage());
227 227
 
228
-			do_action( 'wc_gateway_stripe_process_webhook_payment_error', $e, $order );
228
+			do_action('wc_gateway_stripe_process_webhook_payment_error', $e, $order);
229 229
 
230
-			$statuses = array( 'pending', 'failed' );
230
+			$statuses = array('pending', 'failed');
231 231
 
232
-			if ( $order->has_status( $statuses ) ) {
233
-				$this->send_failed_order_email( $order_id );
232
+			if ($order->has_status($statuses)) {
233
+				$this->send_failed_order_email($order_id);
234 234
 			}
235 235
 		}
236 236
 	}
@@ -243,20 +243,20 @@  discard block
 block discarded – undo
243 243
 	 * @since 4.0.0
244 244
 	 * @param object $notification
245 245
 	 */
246
-	public function process_webhook_dispute( $notification ) {
247
-		$order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->charge );
246
+	public function process_webhook_dispute($notification) {
247
+		$order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->charge);
248 248
 
249
-		if ( ! $order ) {
250
-			WC_Stripe_Logger::log( 'Could not find order via charge ID: ' . $notification->data->object->charge );
249
+		if ( ! $order) {
250
+			WC_Stripe_Logger::log('Could not find order via charge ID: ' . $notification->data->object->charge);
251 251
 			return;
252 252
 		}
253 253
 
254
-		$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' ) );
254
+		$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'));
255 255
 
256
-		do_action( 'wc_gateway_stripe_process_webhook_payment_error', $order, $notification );
256
+		do_action('wc_gateway_stripe_process_webhook_payment_error', $order, $notification);
257 257
 
258 258
 		$order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
259
-		$this->send_failed_order_email( $order_id );
259
+		$this->send_failed_order_email($order_id);
260 260
 	}
261 261
 
262 262
 	/**
@@ -267,41 +267,41 @@  discard block
 block discarded – undo
267 267
 	 * @version 4.0.0
268 268
 	 * @param object $notification
269 269
 	 */
270
-	public function process_webhook_capture( $notification ) {
271
-		$order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->id );
270
+	public function process_webhook_capture($notification) {
271
+		$order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->id);
272 272
 
273
-		if ( ! $order ) {
274
-			WC_Stripe_Logger::log( 'Could not find order via charge ID: ' . $notification->data->object->id );
273
+		if ( ! $order) {
274
+			WC_Stripe_Logger::log('Could not find order via charge ID: ' . $notification->data->object->id);
275 275
 			return;
276 276
 		}
277 277
 
278 278
 		$order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
279 279
 
280
-		if ( 'stripe' === ( WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method() ) ) {
281
-			$charge   = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_transaction_id', true ) : $order->get_transaction_id();
282
-			$captured = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_stripe_charge_captured', true ) : $order->get_meta( '_stripe_charge_captured', true );
280
+		if ('stripe' === (WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method())) {
281
+			$charge   = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_transaction_id', true) : $order->get_transaction_id();
282
+			$captured = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_stripe_charge_captured', true) : $order->get_meta('_stripe_charge_captured', true);
283 283
 
284
-			if ( $charge && 'no' === $captured ) {
285
-				WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, '_stripe_charge_captured', 'yes' ) : $order->update_meta_data( '_stripe_charge_captured', 'yes' );
284
+			if ($charge && 'no' === $captured) {
285
+				WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, '_stripe_charge_captured', 'yes') : $order->update_meta_data('_stripe_charge_captured', 'yes');
286 286
 
287 287
 				// Store other data such as fees
288
-				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 );
288
+				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);
289 289
 
290
-				if ( isset( $notification->data->object->balance_transaction ) ) {
291
-					$this->update_fees( $order, $notification->data->object->balance_transaction );
290
+				if (isset($notification->data->object->balance_transaction)) {
291
+					$this->update_fees($order, $notification->data->object->balance_transaction);
292 292
 				}
293 293
 
294
-				if ( is_callable( array( $order, 'save' ) ) ) {
294
+				if (is_callable(array($order, 'save'))) {
295 295
 					$order->save();
296 296
 				}
297 297
 
298 298
 				/* translators: transaction id */
299
-				$order->update_status( $order->needs_processing() ? 'processing' : 'completed', sprintf( __( 'Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe' ), $notification->data->object->id ) );
299
+				$order->update_status($order->needs_processing() ? 'processing' : 'completed', sprintf(__('Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe'), $notification->data->object->id));
300 300
 
301 301
 				// Check and see if capture is partial.
302
-				if ( $this->is_partial_capture( $notification ) ) {
303
-					$order->set_total( $this->get_partial_amount_to_charge( $notification ) );
304
-					$order->add_note( __( 'This charge was partially captured via Stripe Dashboard', 'woocommerce-gateway-stripe' ) );
302
+				if ($this->is_partial_capture($notification)) {
303
+					$order->set_total($this->get_partial_amount_to_charge($notification));
304
+					$order->add_note(__('This charge was partially captured via Stripe Dashboard', 'woocommerce-gateway-stripe'));
305 305
 					$order->save();
306 306
 				}
307 307
 			}
@@ -316,38 +316,38 @@  discard block
 block discarded – undo
316 316
 	 * @version 4.0.0
317 317
 	 * @param object $notification
318 318
 	 */
319
-	public function process_webhook_charge_succeeded( $notification ) {
319
+	public function process_webhook_charge_succeeded($notification) {
320 320
 		// The following payment methods are synchronous so does not need to be handle via webhook.
321
-		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 ) ) {
321
+		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)) {
322 322
 			return;
323 323
 		}
324 324
 
325
-		$order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->id );
325
+		$order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->id);
326 326
 
327
-		if ( ! $order ) {
328
-			WC_Stripe_Logger::log( 'Could not find order via charge ID: ' . $notification->data->object->id );
327
+		if ( ! $order) {
328
+			WC_Stripe_Logger::log('Could not find order via charge ID: ' . $notification->data->object->id);
329 329
 			return;
330 330
 		}
331 331
 
332 332
 		$order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
333 333
 
334
-		if ( 'on-hold' !== $order->get_status() ) {
334
+		if ('on-hold' !== $order->get_status()) {
335 335
 			return;
336 336
 		}
337 337
 
338 338
 		// Store other data such as fees
339
-		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 );
339
+		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);
340 340
 
341
-		if ( isset( $notification->data->object->balance_transaction ) ) {
342
-			$this->update_fees( $order, $notification->data->object->balance_transaction );
341
+		if (isset($notification->data->object->balance_transaction)) {
342
+			$this->update_fees($order, $notification->data->object->balance_transaction);
343 343
 		}
344 344
 
345
-		if ( is_callable( array( $order, 'save' ) ) ) {
345
+		if (is_callable(array($order, 'save'))) {
346 346
 			$order->save();
347 347
 		}
348 348
 
349 349
 		/* translators: transaction id */
350
-		$order->update_status( $order->needs_processing() ? 'processing' : 'completed', sprintf( __( 'Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe' ), $notification->data->object->id ) );
350
+		$order->update_status($order->needs_processing() ? 'processing' : 'completed', sprintf(__('Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe'), $notification->data->object->id));
351 351
 	}
352 352
 
353 353
 	/**
@@ -358,23 +358,23 @@  discard block
 block discarded – undo
358 358
 	 * @version 4.0.0
359 359
 	 * @param object $notification
360 360
 	 */
361
-	public function process_webhook_charge_failed( $notification ) {
362
-		$order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->id );
361
+	public function process_webhook_charge_failed($notification) {
362
+		$order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->id);
363 363
 
364
-		if ( ! $order ) {
365
-			WC_Stripe_Logger::log( 'Could not find order via charge ID: ' . $notification->data->object->id );
364
+		if ( ! $order) {
365
+			WC_Stripe_Logger::log('Could not find order via charge ID: ' . $notification->data->object->id);
366 366
 			return;
367 367
 		}
368 368
 
369 369
 		$order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
370 370
 
371
-		if ( 'on-hold' !== $order->get_status() ) {
371
+		if ('on-hold' !== $order->get_status()) {
372 372
 			return;
373 373
 		}
374 374
 
375
-		$order->update_status( 'failed', __( 'This payment failed to clear.', 'woocommerce-gateway-stripe' ) );
375
+		$order->update_status('failed', __('This payment failed to clear.', 'woocommerce-gateway-stripe'));
376 376
 
377
-		do_action( 'wc_gateway_stripe_process_webhook_payment_error', $order, $notification );
377
+		do_action('wc_gateway_stripe_process_webhook_payment_error', $order, $notification);
378 378
 	}
379 379
 
380 380
 	/**
@@ -385,23 +385,23 @@  discard block
 block discarded – undo
385 385
 	 * @version 4.0.0
386 386
 	 * @param object $notification
387 387
 	 */
388
-	public function process_webhook_source_canceled( $notification ) {
389
-		$order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->id );
388
+	public function process_webhook_source_canceled($notification) {
389
+		$order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->id);
390 390
 
391
-		if ( ! $order ) {
392
-			WC_Stripe_Logger::log( 'Could not find order via charge ID: ' . $notification->data->object->id );
391
+		if ( ! $order) {
392
+			WC_Stripe_Logger::log('Could not find order via charge ID: ' . $notification->data->object->id);
393 393
 			return;
394 394
 		}
395 395
 
396 396
 		$order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
397 397
 
398
-		if ( 'on-hold' !== $order->get_status() || 'cancelled' !== $order->get_status() ) {
398
+		if ('on-hold' !== $order->get_status() || 'cancelled' !== $order->get_status()) {
399 399
 			return;
400 400
 		}
401 401
 
402
-		$order->update_status( 'cancelled', __( 'This payment has cancelled.', 'woocommerce-gateway-stripe' ) );
402
+		$order->update_status('cancelled', __('This payment has cancelled.', 'woocommerce-gateway-stripe'));
403 403
 
404
-		do_action( 'wc_gateway_stripe_process_webhook_payment_error', $order, $notification );
404
+		do_action('wc_gateway_stripe_process_webhook_payment_error', $order, $notification);
405 405
 	}
406 406
 
407 407
 	/**
@@ -412,42 +412,42 @@  discard block
 block discarded – undo
412 412
 	 * @version 4.0.0
413 413
 	 * @param object $notification
414 414
 	 */
415
-	public function process_webhook_refund( $notification ) {
416
-		$order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->id );
415
+	public function process_webhook_refund($notification) {
416
+		$order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->id);
417 417
 
418
-		if ( ! $order ) {
419
-			WC_Stripe_Logger::log( 'Could not find order via charge ID: ' . $notification->data->object->id );
418
+		if ( ! $order) {
419
+			WC_Stripe_Logger::log('Could not find order via charge ID: ' . $notification->data->object->id);
420 420
 			return;
421 421
 		}
422 422
 
423 423
 		$order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
424 424
 
425
-		if ( 'stripe' === ( WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method() ) ) {
426
-			$charge    = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_transaction_id', true ) : $order->get_transaction_id();
427
-			$captured  = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_stripe_charge_captured', true ) : $order->get_meta( '_stripe_charge_captured', true );
428
-			$refund_id = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_stripe_refund_id', true ) : $order->get_meta( '_stripe_refund_id', true );
425
+		if ('stripe' === (WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method())) {
426
+			$charge    = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_transaction_id', true) : $order->get_transaction_id();
427
+			$captured  = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_stripe_charge_captured', true) : $order->get_meta('_stripe_charge_captured', true);
428
+			$refund_id = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_stripe_refund_id', true) : $order->get_meta('_stripe_refund_id', true);
429 429
 
430 430
 			// If the refund ID matches, don't continue to prevent double refunding.
431
-			if ( $notification->data->object->refunds->data[0]->id === $refund_id ) {
431
+			if ($notification->data->object->refunds->data[0]->id === $refund_id) {
432 432
 				return;
433 433
 			}
434 434
 
435 435
 			// Only refund captured charge.
436
-			if ( $charge ) {
437
-				$reason = ( isset( $captured ) && 'yes' === $captured ) ? __( 'Refunded via Stripe Dashboard', 'woocommerce-gateway-stripe' ) : __( 'Pre-Authorization Released via Stripe Dashboard', 'woocommerce-gateway-stripe' );
436
+			if ($charge) {
437
+				$reason = (isset($captured) && 'yes' === $captured) ? __('Refunded via Stripe Dashboard', 'woocommerce-gateway-stripe') : __('Pre-Authorization Released via Stripe Dashboard', 'woocommerce-gateway-stripe');
438 438
 
439 439
 				// Create the refund.
440
-				$refund = wc_create_refund( array(
440
+				$refund = wc_create_refund(array(
441 441
 					'order_id'       => $order_id,
442
-					'amount'         => $this->get_refund_amount( $notification ),
442
+					'amount'         => $this->get_refund_amount($notification),
443 443
 					'reason'         => $reason,
444
-				) );
444
+				));
445 445
 
446
-				if ( is_wp_error( $refund ) ) {
447
-					WC_Stripe_Logger::log( $refund->get_error_message() );
446
+				if (is_wp_error($refund)) {
447
+					WC_Stripe_Logger::log($refund->get_error_message());
448 448
 				}
449 449
 
450
-				$order->add_order_note( $reason );
450
+				$order->add_order_note($reason);
451 451
 			}
452 452
 		}
453 453
 	}
@@ -459,7 +459,7 @@  discard block
 block discarded – undo
459 459
 	 * @version 4.0.0
460 460
 	 * @param object $notification
461 461
 	 */
462
-	public function is_partial_capture( $notification ) {
462
+	public function is_partial_capture($notification) {
463 463
 		return 0 < $notification->data->object->amount_refunded;
464 464
 	}
465 465
 
@@ -470,11 +470,11 @@  discard block
 block discarded – undo
470 470
 	 * @version 4.0.0
471 471
 	 * @param object $notification
472 472
 	 */
473
-	public function get_refund_amount( $notification ) {
474
-		if ( $this->is_partial_capture( $notification ) ) {
473
+	public function get_refund_amount($notification) {
474
+		if ($this->is_partial_capture($notification)) {
475 475
 			$amount = $notification->data->object->amount_refunded / 100;
476 476
 
477
-			if ( in_array( strtolower( $notification->data->object->currency ), WC_Stripe_Helper::no_decimal_currencies() ) ) {
477
+			if (in_array(strtolower($notification->data->object->currency), WC_Stripe_Helper::no_decimal_currencies())) {
478 478
 				$amount = $notification->data->object->amount_refunded;
479 479
 			}
480 480
 
@@ -491,12 +491,12 @@  discard block
 block discarded – undo
491 491
 	 * @version 4.0.0
492 492
 	 * @param object $notification
493 493
 	 */
494
-	public function get_partial_amount_to_charge( $notification ) {
495
-		if ( $this->is_partial_capture( $notification ) ) {
496
-			$amount = ( $notification->data->object->amount - $notification->data->object->amount_refunded ) / 100;
494
+	public function get_partial_amount_to_charge($notification) {
495
+		if ($this->is_partial_capture($notification)) {
496
+			$amount = ($notification->data->object->amount - $notification->data->object->amount_refunded) / 100;
497 497
 
498
-			if ( in_array( strtolower( $notification->data->object->currency ), WC_Stripe_Helper::no_decimal_currencies() ) ) {
499
-				$amount = ( $notification->data->object->amount - $notification->data->object->amount_refunded );
498
+			if (in_array(strtolower($notification->data->object->currency), WC_Stripe_Helper::no_decimal_currencies())) {
499
+				$amount = ($notification->data->object->amount - $notification->data->object->amount_refunded);
500 500
 			}
501 501
 
502 502
 			return $amount;
@@ -512,36 +512,36 @@  discard block
 block discarded – undo
512 512
 	 * @version 4.0.0
513 513
 	 * @param string $request_body
514 514
 	 */
515
-	public function process_webhook( $request_body ) {
516
-		$notification = json_decode( $request_body );
515
+	public function process_webhook($request_body) {
516
+		$notification = json_decode($request_body);
517 517
 
518
-		switch ( $notification->type ) {
518
+		switch ($notification->type) {
519 519
 			case 'source.chargeable':
520
-				$this->process_webhook_payment( $notification );
520
+				$this->process_webhook_payment($notification);
521 521
 				break;
522 522
 
523 523
 			case 'source.canceled':
524
-				$this->process_webhook_source_canceled( $notification );
524
+				$this->process_webhook_source_canceled($notification);
525 525
 				break;
526 526
 
527 527
 			case 'charge.succeeded':
528
-				$this->process_webhook_charge_succeeded( $notification );
528
+				$this->process_webhook_charge_succeeded($notification);
529 529
 				break;
530 530
 
531 531
 			case 'charge.failed':
532
-				$this->process_webhook_charge_failed( $notification );
532
+				$this->process_webhook_charge_failed($notification);
533 533
 				break;
534 534
 
535 535
 			case 'charge.captured':
536
-				$this->process_webhook_capture( $notification );
536
+				$this->process_webhook_capture($notification);
537 537
 				break;
538 538
 
539 539
 			case 'charge.dispute.created':
540
-				$this->process_webhook_dispute( $notification );
540
+				$this->process_webhook_dispute($notification);
541 541
 				break;
542 542
 
543 543
 			case 'charge.refunded':
544
-				$this->process_webhook_refund( $notification );
544
+				$this->process_webhook_refund($notification);
545 545
 				break;
546 546
 
547 547
 		}
Please login to merge, or discard this patch.
includes/class-wc-stripe-customer.php 2 patches
Doc Comments   -1 removed lines patch added patch discarded remove patch
@@ -213,7 +213,6 @@
 block discarded – undo
213 213
 	/**
214 214
 	 * Get a customers saved sources using their Stripe ID.
215 215
 	 *
216
-	 * @param  string $customer_id
217 216
 	 * @return array
218 217
 	 */
219 218
 	public function get_sources() {
Please login to merge, or discard this patch.
Spacing   +79 added lines, -79 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
 
@@ -32,10 +32,10 @@  discard block
 block discarded – undo
32 32
 	 * Constructor
33 33
 	 * @param int $user_id The WP user ID
34 34
 	 */
35
-	public function __construct( $user_id = 0 ) {
36
-		if ( $user_id ) {
37
-			$this->set_user_id( $user_id );
38
-			$this->set_id( get_user_meta( $user_id, '_stripe_customer_id', true ) );
35
+	public function __construct($user_id = 0) {
36
+		if ($user_id) {
37
+			$this->set_user_id($user_id);
38
+			$this->set_id(get_user_meta($user_id, '_stripe_customer_id', true));
39 39
 		}
40 40
 	}
41 41
 
@@ -51,8 +51,8 @@  discard block
 block discarded – undo
51 51
 	 * Set Stripe customer ID.
52 52
 	 * @param [type] $id [description]
53 53
 	 */
54
-	public function set_id( $id ) {
55
-		$this->id = wc_clean( $id );
54
+	public function set_id($id) {
55
+		$this->id = wc_clean($id);
56 56
 	}
57 57
 
58 58
 	/**
@@ -60,15 +60,15 @@  discard block
 block discarded – undo
60 60
 	 * @return int
61 61
 	 */
62 62
 	public function get_user_id() {
63
-		return absint( $this->user_id );
63
+		return absint($this->user_id);
64 64
 	}
65 65
 
66 66
 	/**
67 67
 	 * Set User ID used by WordPress.
68 68
 	 * @param int $user_id
69 69
 	 */
70
-	public function set_user_id( $user_id ) {
71
-		$this->user_id = absint( $user_id );
70
+	public function set_user_id($user_id) {
71
+		$this->user_id = absint($user_id);
72 72
 	}
73 73
 
74 74
 	/**
@@ -76,13 +76,13 @@  discard block
 block discarded – undo
76 76
 	 * @return WP_User
77 77
 	 */
78 78
 	protected function get_user() {
79
-		return $this->get_user_id() ? get_user_by( 'id', $this->get_user_id() ) : false;
79
+		return $this->get_user_id() ? get_user_by('id', $this->get_user_id()) : false;
80 80
 	}
81 81
 
82 82
 	/**
83 83
 	 * Store data from the Stripe API about this customer
84 84
 	 */
85
-	public function set_customer_data( $data ) {
85
+	public function set_customer_data($data) {
86 86
 		$this->customer_data = $data;
87 87
 	}
88 88
 
@@ -91,13 +91,13 @@  discard block
 block discarded – undo
91 91
 	 * @param array $args
92 92
 	 * @return WP_Error|int
93 93
 	 */
94
-	public function create_customer( $args = array() ) {
95
-		$billing_email = isset( $_POST['billing_email'] ) ? filter_var( $_POST['billing_email'], FILTER_SANITIZE_EMAIL ) : '';
94
+	public function create_customer($args = array()) {
95
+		$billing_email = isset($_POST['billing_email']) ? filter_var($_POST['billing_email'], FILTER_SANITIZE_EMAIL) : '';
96 96
 		$user = $this->get_user();
97 97
 
98
-		if ( $user ) {
99
-			$billing_first_name = get_user_meta( $user->ID, 'billing_first_name', true );
100
-			$billing_last_name  = get_user_meta( $user->ID, 'billing_last_name', true );
98
+		if ($user) {
99
+			$billing_first_name = get_user_meta($user->ID, 'billing_first_name', true);
100
+			$billing_last_name  = get_user_meta($user->ID, 'billing_last_name', true);
101 101
 
102 102
 			$defaults = array(
103 103
 				'email'       => $user->user_email,
@@ -112,24 +112,24 @@  discard block
 block discarded – undo
112 112
 
113 113
 		$metadata = array();
114 114
 
115
-		$defaults['metadata'] = apply_filters( 'wc_stripe_customer_metadata', $metadata, $user );
115
+		$defaults['metadata'] = apply_filters('wc_stripe_customer_metadata', $metadata, $user);
116 116
 
117
-		$args     = wp_parse_args( $args, $defaults );
118
-		$response = WC_Stripe_API::request( apply_filters( 'wc_stripe_create_customer_args', $args ), 'customers' );
117
+		$args     = wp_parse_args($args, $defaults);
118
+		$response = WC_Stripe_API::request(apply_filters('wc_stripe_create_customer_args', $args), 'customers');
119 119
 
120
-		if ( ! empty( $response->error ) ) {
121
-			throw new WC_Stripe_Exception( print_r( $response, true ), $response->error->message );
120
+		if ( ! empty($response->error)) {
121
+			throw new WC_Stripe_Exception(print_r($response, true), $response->error->message);
122 122
 		}
123 123
 
124
-		$this->set_id( $response->id );
124
+		$this->set_id($response->id);
125 125
 		$this->clear_cache();
126
-		$this->set_customer_data( $response );
126
+		$this->set_customer_data($response);
127 127
 
128
-		if ( $this->get_user_id() ) {
129
-			update_user_meta( $this->get_user_id(), '_stripe_customer_id', $response->id );
128
+		if ($this->get_user_id()) {
129
+			update_user_meta($this->get_user_id(), '_stripe_customer_id', $response->id);
130 130
 		}
131 131
 
132
-		do_action( 'woocommerce_stripe_add_customer', $args, $response );
132
+		do_action('woocommerce_stripe_add_customer', $args, $response);
133 133
 
134 134
 		return $response->id;
135 135
 	}
@@ -140,72 +140,72 @@  discard block
 block discarded – undo
140 140
 	 * @param bool $retry
141 141
 	 * @return WP_Error|int
142 142
 	 */
143
-	public function add_source( $source_id, $retry = true ) {
144
-		if ( ! $this->get_id() ) {
145
-			$this->set_id( $this->create_customer() );
143
+	public function add_source($source_id, $retry = true) {
144
+		if ( ! $this->get_id()) {
145
+			$this->set_id($this->create_customer());
146 146
 		}
147 147
 
148
-		$response = WC_Stripe_API::request( array(
148
+		$response = WC_Stripe_API::request(array(
149 149
 			'source' => $source_id,
150
-		), 'customers/' . $this->get_id() . '/sources' );
150
+		), 'customers/' . $this->get_id() . '/sources');
151 151
 
152
-		if ( ! empty( $response->error ) ) {
152
+		if ( ! empty($response->error)) {
153 153
 			// It is possible the WC user once was linked to a customer on Stripe
154 154
 			// but no longer exists. Instead of failing, lets try to create a
155 155
 			// new customer.
156
-			if ( preg_match( '/No such customer/i', $response->error->message ) ) {
157
-				delete_user_meta( $this->get_user_id(), '_stripe_customer_id' );
156
+			if (preg_match('/No such customer/i', $response->error->message)) {
157
+				delete_user_meta($this->get_user_id(), '_stripe_customer_id');
158 158
 				$this->create_customer();
159
-				return $this->add_source( $source_id, false );
159
+				return $this->add_source($source_id, false);
160 160
 			} else {
161 161
 				return $response;
162 162
 			}
163
-		} elseif ( empty( $response->id ) ) {
164
-			return new WP_Error( 'error', __( 'Unable to add payment source.', 'woocommerce-gateway-stripe' ) );
163
+		} elseif (empty($response->id)) {
164
+			return new WP_Error('error', __('Unable to add payment source.', 'woocommerce-gateway-stripe'));
165 165
 		}
166 166
 
167 167
 		// Add token to WooCommerce.
168
-		if ( $this->get_user_id() && class_exists( 'WC_Payment_Token_CC' ) ) {
169
-			if ( ! empty( $response->type ) ) {
170
-				switch ( $response->type ) {
168
+		if ($this->get_user_id() && class_exists('WC_Payment_Token_CC')) {
169
+			if ( ! empty($response->type)) {
170
+				switch ($response->type) {
171 171
 					case 'alipay':
172 172
 						break;
173 173
 					case 'sepa_debit':
174 174
 						$wc_token = new WC_Payment_Token_SEPA();
175
-						$wc_token->set_token( $response->id );
176
-						$wc_token->set_gateway_id( 'stripe_sepa' );
177
-						$wc_token->set_last4( $response->sepa_debit->last4 );
175
+						$wc_token->set_token($response->id);
176
+						$wc_token->set_gateway_id('stripe_sepa');
177
+						$wc_token->set_last4($response->sepa_debit->last4);
178 178
 						break;
179 179
 					default:
180
-						if ( 'source' === $response->object && 'card' === $response->type ) {
180
+						if ('source' === $response->object && 'card' === $response->type) {
181 181
 							$wc_token = new WC_Payment_Token_CC();
182
-							$wc_token->set_token( $response->id );
183
-							$wc_token->set_gateway_id( 'stripe' );
184
-							$wc_token->set_card_type( strtolower( $response->card->brand ) );
185
-							$wc_token->set_last4( $response->card->last4 );
186
-							$wc_token->set_expiry_month( $response->card->exp_month );
187
-							$wc_token->set_expiry_year( $response->card->exp_year );
182
+							$wc_token->set_token($response->id);
183
+							$wc_token->set_gateway_id('stripe');
184
+							$wc_token->set_card_type(strtolower($response->card->brand));
185
+							$wc_token->set_last4($response->card->last4);
186
+							$wc_token->set_expiry_month($response->card->exp_month);
187
+							$wc_token->set_expiry_year($response->card->exp_year);
188 188
 						}
189 189
 						break;
190 190
 				}
191 191
 			} else {
192 192
 				// Legacy.
193 193
 				$wc_token = new WC_Payment_Token_CC();
194
-				$wc_token->set_token( $response->id );
195
-				$wc_token->set_gateway_id( 'stripe' );
196
-				$wc_token->set_card_type( strtolower( $response->brand ) );
197
-				$wc_token->set_last4( $response->last4 );
198
-				$wc_token->set_expiry_month( $response->exp_month );
199
-				$wc_token->set_expiry_year( $response->exp_year );
194
+				$wc_token->set_token($response->id);
195
+				$wc_token->set_gateway_id('stripe');
196
+				$wc_token->set_card_type(strtolower($response->brand));
197
+				$wc_token->set_last4($response->last4);
198
+				$wc_token->set_expiry_month($response->exp_month);
199
+				$wc_token->set_expiry_year($response->exp_year);
200 200
 			}
201 201
 
202
-			$wc_token->set_user_id( $this->get_user_id() );
202
+			$wc_token->set_user_id($this->get_user_id());
203 203
 			$wc_token->save();
204 204
 		}
205 205
 
206 206
 		$this->clear_cache();
207 207
 
208
-		do_action( 'woocommerce_stripe_add_source', $this->get_id(), $wc_token, $response, $source_id );
208
+		do_action('woocommerce_stripe_add_source', $this->get_id(), $wc_token, $response, $source_id);
209 209
 
210 210
 		return $response->id;
211 211
 	}
@@ -217,42 +217,42 @@  discard block
 block discarded – undo
217 217
 	 * @return array
218 218
 	 */
219 219
 	public function get_sources() {
220
-		if ( ! $this->get_id() ) {
220
+		if ( ! $this->get_id()) {
221 221
 			return array();
222 222
 		}
223 223
 
224
-		$sources = get_transient( 'stripe_sources_' . $this->get_id() );
224
+		$sources = get_transient('stripe_sources_' . $this->get_id());
225 225
 
226
-		$response = WC_Stripe_API::request( array(
226
+		$response = WC_Stripe_API::request(array(
227 227
 			'limit'       => 100,
228
-		), 'customers/' . $this->get_id() . '/sources', 'GET' );
228
+		), 'customers/' . $this->get_id() . '/sources', 'GET');
229 229
 
230
-		if ( ! empty( $response->error ) ) {
230
+		if ( ! empty($response->error)) {
231 231
 			return array();
232 232
 		}
233 233
 
234
-		if ( is_array( $response->data ) ) {
234
+		if (is_array($response->data)) {
235 235
 			$sources = $response->data;
236 236
 		}
237 237
 
238
-		return empty( $sources ) ? array() : $sources;
238
+		return empty($sources) ? array() : $sources;
239 239
 	}
240 240
 
241 241
 	/**
242 242
 	 * Delete a source from stripe.
243 243
 	 * @param string $source_id
244 244
 	 */
245
-	public function delete_source( $source_id ) {
246
-		if ( ! $this->get_id() ) {
245
+	public function delete_source($source_id) {
246
+		if ( ! $this->get_id()) {
247 247
 			return false;
248 248
 		}
249 249
 
250
-		$response = WC_Stripe_API::request( array(), 'customers/' . $this->get_id() . '/sources/' . sanitize_text_field( $source_id ), 'DELETE' );
250
+		$response = WC_Stripe_API::request(array(), 'customers/' . $this->get_id() . '/sources/' . sanitize_text_field($source_id), 'DELETE');
251 251
 
252 252
 		$this->clear_cache();
253 253
 
254
-		if ( empty( $response->error ) ) {
255
-			do_action( 'wc_stripe_delete_source', $this->get_id(), $response );
254
+		if (empty($response->error)) {
255
+			do_action('wc_stripe_delete_source', $this->get_id(), $response);
256 256
 
257 257
 			return true;
258 258
 		}
@@ -264,15 +264,15 @@  discard block
 block discarded – undo
264 264
 	 * Set default source in Stripe
265 265
 	 * @param string $source_id
266 266
 	 */
267
-	public function set_default_source( $source_id ) {
268
-		$response = WC_Stripe_API::request( array(
269
-			'default_source' => sanitize_text_field( $source_id ),
270
-		), 'customers/' . $this->get_id(), 'POST' );
267
+	public function set_default_source($source_id) {
268
+		$response = WC_Stripe_API::request(array(
269
+			'default_source' => sanitize_text_field($source_id),
270
+		), 'customers/' . $this->get_id(), 'POST');
271 271
 
272 272
 		$this->clear_cache();
273 273
 
274
-		if ( empty( $response->error ) ) {
275
-			do_action( 'wc_stripe_set_default_source', $this->get_id(), $response );
274
+		if (empty($response->error)) {
275
+			do_action('wc_stripe_set_default_source', $this->get_id(), $response);
276 276
 
277 277
 			return true;
278 278
 		}
@@ -284,8 +284,8 @@  discard block
 block discarded – undo
284 284
 	 * Deletes caches for this users cards.
285 285
 	 */
286 286
 	public function clear_cache() {
287
-		delete_transient( 'stripe_sources_' . $this->get_id() );
288
-		delete_transient( 'stripe_customer_' . $this->get_id() );
287
+		delete_transient('stripe_sources_' . $this->get_id());
288
+		delete_transient('stripe_customer_' . $this->get_id());
289 289
 		$this->customer_data = array();
290 290
 	}
291 291
 }
Please login to merge, or discard this patch.
includes/admin/stripe-settings.php 1 patch
Spacing   +65 added lines, -65 removed lines patch added patch discarded remove patch
@@ -1,184 +1,184 @@
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) {
2
+if ( ! defined('ABSPATH')) {
3 3
 	exit;
4 4
 }
5 5
 
6 6
 $webhook_url = WC_Stripe_Helper::get_webhook_url();
7 7
 
8
-return apply_filters( 'wc_stripe_settings',
8
+return apply_filters('wc_stripe_settings',
9 9
 	array(
10 10
 		'enabled' => array(
11
-			'title'       => __( 'Enable/Disable', 'woocommerce-gateway-stripe' ),
12
-			'label'       => __( 'Enable Stripe', 'woocommerce-gateway-stripe' ),
11
+			'title'       => __('Enable/Disable', 'woocommerce-gateway-stripe'),
12
+			'label'       => __('Enable Stripe', 'woocommerce-gateway-stripe'),
13 13
 			'type'        => 'checkbox',
14 14
 			'description' => '',
15 15
 			'default'     => 'no',
16 16
 		),
17 17
 		'title' => array(
18
-			'title'       => __( 'Title', 'woocommerce-gateway-stripe' ),
18
+			'title'       => __('Title', 'woocommerce-gateway-stripe'),
19 19
 			'type'        => 'text',
20
-			'description' => __( 'This controls the title which the user sees during checkout.', 'woocommerce-gateway-stripe' ),
21
-			'default'     => __( 'Credit Card (Stripe)', 'woocommerce-gateway-stripe' ),
20
+			'description' => __('This controls the title which the user sees during checkout.', 'woocommerce-gateway-stripe'),
21
+			'default'     => __('Credit Card (Stripe)', 'woocommerce-gateway-stripe'),
22 22
 			'desc_tip'    => true,
23 23
 		),
24 24
 		'description' => array(
25
-			'title'       => __( 'Description', 'woocommerce-gateway-stripe' ),
25
+			'title'       => __('Description', 'woocommerce-gateway-stripe'),
26 26
 			'type'        => 'text',
27
-			'description' => __( 'This controls the description which the user sees during checkout.', 'woocommerce-gateway-stripe' ),
28
-			'default'     => __( 'Pay with your credit card via Stripe.', 'woocommerce-gateway-stripe' ),
27
+			'description' => __('This controls the description which the user sees during checkout.', 'woocommerce-gateway-stripe'),
28
+			'default'     => __('Pay with your credit card via Stripe.', 'woocommerce-gateway-stripe'),
29 29
 			'desc_tip'    => true,
30 30
 		),
31 31
 		'webhook' => array(
32
-			'title'       => __( 'Webhook Endpoints', 'woocommerce-gateway-stripe' ),
32
+			'title'       => __('Webhook Endpoints', 'woocommerce-gateway-stripe'),
33 33
 			'type'        => 'title',
34 34
 			/* translators: webhook URL */
35
-			'description' => sprintf( __( 'You must add the webhook endpoint <strong style="background-color:#ddd;">&nbsp;&nbsp;%s&nbsp;&nbsp;</strong> to your Stripe Account Settings <a href="https://dashboard.stripe.com/account/webhooks" target="_blank">Here</a> so you can receive notifications on the charge statuses.', 'woocommerce-gateway-stripe' ), $webhook_url ),
35
+			'description' => sprintf(__('You must add the webhook endpoint <strong style="background-color:#ddd;">&nbsp;&nbsp;%s&nbsp;&nbsp;</strong> to your Stripe Account Settings <a href="https://dashboard.stripe.com/account/webhooks" target="_blank">Here</a> so you can receive notifications on the charge statuses.', 'woocommerce-gateway-stripe'), $webhook_url),
36 36
 		),
37 37
 		'testmode' => array(
38
-			'title'       => __( 'Test mode', 'woocommerce-gateway-stripe' ),
39
-			'label'       => __( 'Enable Test Mode', 'woocommerce-gateway-stripe' ),
38
+			'title'       => __('Test mode', 'woocommerce-gateway-stripe'),
39
+			'label'       => __('Enable Test Mode', 'woocommerce-gateway-stripe'),
40 40
 			'type'        => 'checkbox',
41
-			'description' => __( 'Place the payment gateway in test mode using test API keys.', 'woocommerce-gateway-stripe' ),
41
+			'description' => __('Place the payment gateway in test mode using test API keys.', 'woocommerce-gateway-stripe'),
42 42
 			'default'     => 'yes',
43 43
 			'desc_tip'    => true,
44 44
 		),
45 45
 		'test_publishable_key' => array(
46
-			'title'       => __( 'Test Publishable Key', 'woocommerce-gateway-stripe' ),
46
+			'title'       => __('Test Publishable Key', 'woocommerce-gateway-stripe'),
47 47
 			'type'        => 'password',
48
-			'description' => __( 'Get your API keys from your stripe account.', 'woocommerce-gateway-stripe' ),
48
+			'description' => __('Get your API keys from your stripe account.', 'woocommerce-gateway-stripe'),
49 49
 			'default'     => '',
50 50
 			'desc_tip'    => true,
51 51
 		),
52 52
 		'test_secret_key' => array(
53
-			'title'       => __( 'Test Secret Key', 'woocommerce-gateway-stripe' ),
53
+			'title'       => __('Test Secret Key', 'woocommerce-gateway-stripe'),
54 54
 			'type'        => 'password',
55
-			'description' => __( 'Get your API keys from your stripe account.', 'woocommerce-gateway-stripe' ),
55
+			'description' => __('Get your API keys from your stripe account.', 'woocommerce-gateway-stripe'),
56 56
 			'default'     => '',
57 57
 			'desc_tip'    => true,
58 58
 		),
59 59
 		'publishable_key' => array(
60
-			'title'       => __( 'Live Publishable Key', 'woocommerce-gateway-stripe' ),
60
+			'title'       => __('Live Publishable Key', 'woocommerce-gateway-stripe'),
61 61
 			'type'        => 'password',
62
-			'description' => __( 'Get your API keys from your stripe account.', 'woocommerce-gateway-stripe' ),
62
+			'description' => __('Get your API keys from your stripe account.', 'woocommerce-gateway-stripe'),
63 63
 			'default'     => '',
64 64
 			'desc_tip'    => true,
65 65
 		),
66 66
 		'secret_key' => array(
67
-			'title'       => __( 'Live Secret Key', 'woocommerce-gateway-stripe' ),
67
+			'title'       => __('Live Secret Key', 'woocommerce-gateway-stripe'),
68 68
 			'type'        => 'password',
69
-			'description' => __( 'Get your API keys from your stripe account.', 'woocommerce-gateway-stripe' ),
69
+			'description' => __('Get your API keys from your stripe account.', 'woocommerce-gateway-stripe'),
70 70
 			'default'     => '',
71 71
 			'desc_tip'    => true,
72 72
 		),
73 73
 		'inline_cc_form' => array(
74
-			'title'       => __( 'Inline Credit Card Form', 'woocommerce-gateway-stripe' ),
74
+			'title'       => __('Inline Credit Card Form', 'woocommerce-gateway-stripe'),
75 75
 			'type'        => 'checkbox',
76
-			'description' => __( 'Choose the style you want to show for your credit card form. When unchecked, the credit card form will display separate credit card number field, expiry date field and cvc field.', 'woocommerce-gateway-stripe' ),
76
+			'description' => __('Choose the style you want to show for your credit card form. When unchecked, the credit card form will display separate credit card number field, expiry date field and cvc field.', 'woocommerce-gateway-stripe'),
77 77
 			'default'     => 'no',
78 78
 			'desc_tip'    => true,
79 79
 		),
80 80
 		'statement_descriptor' => array(
81
-			'title'       => __( 'Statement Descriptor', 'woocommerce-gateway-stripe' ),
81
+			'title'       => __('Statement Descriptor', 'woocommerce-gateway-stripe'),
82 82
 			'type'        => 'text',
83
-			'description' => __( 'This may be up to 22 characters. The statement description must contain at least one letter, may not include ><"\' characters, and will appear on your customer\'s statement in capital letters.', 'woocommerce-gateway-stripe' ),
83
+			'description' => __('This may be up to 22 characters. The statement description must contain at least one letter, may not include ><"\' characters, and will appear on your customer\'s statement in capital letters.', 'woocommerce-gateway-stripe'),
84 84
 			'default'     => '',
85 85
 			'desc_tip'    => true,
86 86
 		),
87 87
 		'capture' => array(
88
-			'title'       => __( 'Capture', 'woocommerce-gateway-stripe' ),
89
-			'label'       => __( 'Capture charge immediately', 'woocommerce-gateway-stripe' ),
88
+			'title'       => __('Capture', 'woocommerce-gateway-stripe'),
89
+			'label'       => __('Capture charge immediately', 'woocommerce-gateway-stripe'),
90 90
 			'type'        => 'checkbox',
91
-			'description' => __( 'Whether or not to immediately capture the charge. When unchecked, the charge issues an authorization and will need to be captured later. Uncaptured charges expire in 7 days.', 'woocommerce-gateway-stripe' ),
91
+			'description' => __('Whether or not to immediately capture the charge. When unchecked, the charge issues an authorization and will need to be captured later. Uncaptured charges expire in 7 days.', 'woocommerce-gateway-stripe'),
92 92
 			'default'     => 'yes',
93 93
 			'desc_tip'    => true,
94 94
 		),
95 95
 		'three_d_secure' => array(
96
-			'title'       => __( '3D Secure', 'woocommerce-gateway-stripe' ),
97
-			'label'       => __( 'Require 3D Secure when applicable', 'woocommerce-gateway-stripe' ),
96
+			'title'       => __('3D Secure', 'woocommerce-gateway-stripe'),
97
+			'label'       => __('Require 3D Secure when applicable', 'woocommerce-gateway-stripe'),
98 98
 			'type'        => 'checkbox',
99
-			'description' => __( 'Some payment methods have 3D Secure feature. This is an extra security layer for your store. Choose how to handle payments when 3D Secure is optional. Enabling would require customers to use 3D Secure when optional.', 'woocommerce-gateway-stripe' ),
99
+			'description' => __('Some payment methods have 3D Secure feature. This is an extra security layer for your store. Choose how to handle payments when 3D Secure is optional. Enabling would require customers to use 3D Secure when optional.', 'woocommerce-gateway-stripe'),
100 100
 			'default'     => 'no',
101 101
 			'desc_tip'    => true,
102 102
 		),
103 103
 		'stripe_checkout' => array(
104
-			'title'       => __( 'Stripe Checkout', 'woocommerce-gateway-stripe' ),
105
-			'label'       => __( 'Enable Stripe Checkout', 'woocommerce-gateway-stripe' ),
104
+			'title'       => __('Stripe Checkout', 'woocommerce-gateway-stripe'),
105
+			'label'       => __('Enable Stripe Checkout', 'woocommerce-gateway-stripe'),
106 106
 			'type'        => 'checkbox',
107
-			'description' => __( 'If enabled, this option shows a "pay" button and modal credit card form on the checkout, instead of credit card fields directly on the page.', 'woocommerce-gateway-stripe' ),
107
+			'description' => __('If enabled, this option shows a "pay" button and modal credit card form on the checkout, instead of credit card fields directly on the page.', 'woocommerce-gateway-stripe'),
108 108
 			'default'     => 'no',
109 109
 			'desc_tip'    => true,
110 110
 		),
111 111
 		'stripe_bitcoin' => array(
112
-			'title'       => __( 'Bitcoin Currency', 'woocommerce-gateway-stripe' ),
113
-			'label'       => __( 'Enable Bitcoin Currency', 'woocommerce-gateway-stripe' ),
112
+			'title'       => __('Bitcoin Currency', 'woocommerce-gateway-stripe'),
113
+			'label'       => __('Enable Bitcoin Currency', 'woocommerce-gateway-stripe'),
114 114
 			'type'        => 'checkbox',
115
-			'description' => __( 'If enabled, an option to accept bitcoin will show on the checkout modal. Note: Stripe Checkout needs to be enabled and store currency must be set to USD.', 'woocommerce-gateway-stripe' ),
115
+			'description' => __('If enabled, an option to accept bitcoin will show on the checkout modal. Note: Stripe Checkout needs to be enabled and store currency must be set to USD.', 'woocommerce-gateway-stripe'),
116 116
 			'default'     => 'no',
117 117
 			'desc_tip'    => true,
118 118
 		),
119 119
 		'stripe_checkout_image' => array(
120
-			'title'       => __( 'Stripe Checkout Image', 'woocommerce-gateway-stripe' ),
121
-			'description' => __( 'Optionally enter the URL to a 128x128px image of your brand or product. e.g. <code>https://yoursite.com/wp-content/uploads/2013/09/yourimage.jpg</code>', 'woocommerce-gateway-stripe' ),
120
+			'title'       => __('Stripe Checkout Image', 'woocommerce-gateway-stripe'),
121
+			'description' => __('Optionally enter the URL to a 128x128px image of your brand or product. e.g. <code>https://yoursite.com/wp-content/uploads/2013/09/yourimage.jpg</code>', 'woocommerce-gateway-stripe'),
122 122
 			'type'        => 'text',
123 123
 			'default'     => '',
124 124
 			'desc_tip'    => true,
125 125
 		),
126 126
 		'payment_request' => array(
127
-			'title'       => __( 'Payment Request Buttons', 'woocommerce-gateway-stripe' ),
127
+			'title'       => __('Payment Request Buttons', 'woocommerce-gateway-stripe'),
128 128
 			/* translators: 1) br tag 2) opening anchor tag 3) closing anchor tag */
129
-			'label'       => sprintf( __( 'Enable Payment Request Buttons. (Apple Pay/Chrome Payment Request API) %1$sBy using Apple Pay, you agree to %2$s and %3$s\'s terms of service.', 'woocommerce-gateway-stripe' ), '<br />', '<a href="https://stripe.com/apple-pay/legal" target="_blank">Stripe</a>', '<a href="https://developer.apple.com/apple-pay/acceptable-use-guidelines-for-websites/" target="_blank">Apple</a>' ),
129
+			'label'       => sprintf(__('Enable Payment Request Buttons. (Apple Pay/Chrome Payment Request API) %1$sBy using Apple Pay, you agree to %2$s and %3$s\'s terms of service.', 'woocommerce-gateway-stripe'), '<br />', '<a href="https://stripe.com/apple-pay/legal" target="_blank">Stripe</a>', '<a href="https://developer.apple.com/apple-pay/acceptable-use-guidelines-for-websites/" target="_blank">Apple</a>'),
130 130
 			'type'        => 'checkbox',
131
-			'description' => __( 'If enabled, users will be able to pay using Apple Pay or Chrome Payment Request if supported by the browser.', 'woocommerce-gateway-stripe' ),
131
+			'description' => __('If enabled, users will be able to pay using Apple Pay or Chrome Payment Request if supported by the browser.', 'woocommerce-gateway-stripe'),
132 132
 			'default'     => 'yes',
133 133
 			'desc_tip'    => true,
134 134
 		),
135 135
 		'payment_request_button_type' => array(
136
-			'title'       => __( 'Payment Request Button Type', 'woocommerce-gateway-stripe' ),
137
-			'label'       => __( 'Button Type', 'woocommerce-gateway-stripe' ),
136
+			'title'       => __('Payment Request Button Type', 'woocommerce-gateway-stripe'),
137
+			'label'       => __('Button Type', 'woocommerce-gateway-stripe'),
138 138
 			'type'        => 'select',
139
-			'description' => __( 'Select the button type you would like to show.', 'woocommerce-gateway-stripe' ),
139
+			'description' => __('Select the button type you would like to show.', 'woocommerce-gateway-stripe'),
140 140
 			'default'     => 'buy',
141 141
 			'desc_tip'    => true,
142 142
 			'options'     => array(
143
-				'default' => __( 'Default', 'woocommerce-gateway-stripe' ),
144
-				'buy'     => __( 'Buy', 'woocommerce-gateway-stripe' ),
145
-				'donate'  => __( 'Donate', 'woocommerce-gateway-stripe' ),
143
+				'default' => __('Default', 'woocommerce-gateway-stripe'),
144
+				'buy'     => __('Buy', 'woocommerce-gateway-stripe'),
145
+				'donate'  => __('Donate', 'woocommerce-gateway-stripe'),
146 146
 			),
147 147
 		),
148 148
 		'payment_request_button_theme' => array(
149
-			'title'       => __( 'Payment Request Button Theme', 'woocommerce-gateway-stripe' ),
150
-			'label'       => __( 'Button Theme', 'woocommerce-gateway-stripe' ),
149
+			'title'       => __('Payment Request Button Theme', 'woocommerce-gateway-stripe'),
150
+			'label'       => __('Button Theme', 'woocommerce-gateway-stripe'),
151 151
 			'type'        => 'select',
152
-			'description' => __( 'Select the button theme you would like to show.', 'woocommerce-gateway-stripe' ),
152
+			'description' => __('Select the button theme you would like to show.', 'woocommerce-gateway-stripe'),
153 153
 			'default'     => 'dark',
154 154
 			'desc_tip'    => true,
155 155
 			'options'     => array(
156
-				'dark'          => __( 'Dark', 'woocommerce-gateway-stripe' ),
157
-				'light'         => __( 'Light', 'woocommerce-gateway-stripe' ),
158
-				'light-outline' => __( 'Light-Outline', 'woocommerce-gateway-stripe' ),
156
+				'dark'          => __('Dark', 'woocommerce-gateway-stripe'),
157
+				'light'         => __('Light', 'woocommerce-gateway-stripe'),
158
+				'light-outline' => __('Light-Outline', 'woocommerce-gateway-stripe'),
159 159
 			),
160 160
 		),
161 161
 		'payment_request_button_height' => array(
162
-			'title'       => __( 'Payment Request Button Height', 'woocommerce-gateway-stripe' ),
163
-			'label'       => __( 'Button Height', 'woocommerce-gateway-stripe' ),
162
+			'title'       => __('Payment Request Button Height', 'woocommerce-gateway-stripe'),
163
+			'label'       => __('Button Height', 'woocommerce-gateway-stripe'),
164 164
 			'type'        => 'text',
165
-			'description' => __( 'Enter the height you would like the button to be in pixels. Width will always be 100%.', 'woocommerce-gateway-stripe' ),
165
+			'description' => __('Enter the height you would like the button to be in pixels. Width will always be 100%.', 'woocommerce-gateway-stripe'),
166 166
 			'default'     => '44',
167 167
 			'desc_tip'    => true,
168 168
 		),
169 169
 		'saved_cards' => array(
170
-			'title'       => __( 'Saved Cards', 'woocommerce-gateway-stripe' ),
171
-			'label'       => __( 'Enable Payment via Saved Cards', 'woocommerce-gateway-stripe' ),
170
+			'title'       => __('Saved Cards', 'woocommerce-gateway-stripe'),
171
+			'label'       => __('Enable Payment via Saved Cards', 'woocommerce-gateway-stripe'),
172 172
 			'type'        => 'checkbox',
173
-			'description' => __( 'If enabled, users will be able to pay with a saved card during checkout. Card details are saved on Stripe servers, not on your store.', 'woocommerce-gateway-stripe' ),
173
+			'description' => __('If enabled, users will be able to pay with a saved card during checkout. Card details are saved on Stripe servers, not on your store.', 'woocommerce-gateway-stripe'),
174 174
 			'default'     => 'no',
175 175
 			'desc_tip'    => true,
176 176
 		),
177 177
 		'logging' => array(
178
-			'title'       => __( 'Logging', 'woocommerce-gateway-stripe' ),
179
-			'label'       => __( 'Log debug messages', 'woocommerce-gateway-stripe' ),
178
+			'title'       => __('Logging', 'woocommerce-gateway-stripe'),
179
+			'label'       => __('Log debug messages', 'woocommerce-gateway-stripe'),
180 180
 			'type'        => 'checkbox',
181
-			'description' => __( 'Save debug messages to the WooCommerce System Status log.', 'woocommerce-gateway-stripe' ),
181
+			'description' => __('Save debug messages to the WooCommerce System Status log.', 'woocommerce-gateway-stripe'),
182 182
 			'default'     => 'no',
183 183
 			'desc_tip'    => true,
184 184
 		),
Please login to merge, or discard this patch.
includes/class-wc-gateway-stripe.php 1 patch
Spacing   +207 added lines, -207 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
 
@@ -115,9 +115,9 @@  discard block
 block discarded – undo
115 115
 	public function __construct() {
116 116
 		$this->retry_interval       = 2;
117 117
 		$this->id                   = 'stripe';
118
-		$this->method_title         = __( 'Stripe', 'woocommerce-gateway-stripe' );
118
+		$this->method_title         = __('Stripe', 'woocommerce-gateway-stripe');
119 119
 		/* translators: 1) link to Stripe register page 2) link to Stripe api keys page */
120
-		$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' );
120
+		$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');
121 121
 		$this->has_fields           = true;
122 122
 		$this->supports             = array(
123 123
 			'products',
@@ -144,37 +144,37 @@  discard block
 block discarded – undo
144 144
 		$this->init_settings();
145 145
 
146 146
 		// Get setting values.
147
-		$this->title                   = $this->get_option( 'title' );
148
-		$this->description             = $this->get_option( 'description' );
149
-		$this->enabled                 = $this->get_option( 'enabled' );
150
-		$this->testmode                = 'yes' === $this->get_option( 'testmode' );
151
-		$this->inline_cc_form          = 'yes' === $this->get_option( 'inline_cc_form' );
152
-		$this->capture                 = 'yes' === $this->get_option( 'capture', 'yes' );
153
-		$this->statement_descriptor    = WC_Stripe_Helper::clean_statement_descriptor( $this->get_option( 'statement_descriptor' ) );
154
-		$this->three_d_secure          = 'yes' === $this->get_option( 'three_d_secure' );
155
-		$this->stripe_checkout         = 'yes' === $this->get_option( 'stripe_checkout' );
156
-		$this->stripe_checkout_image   = $this->get_option( 'stripe_checkout_image', '' );
157
-		$this->saved_cards             = 'yes' === $this->get_option( 'saved_cards' );
158
-		$this->secret_key              = $this->testmode ? $this->get_option( 'test_secret_key' ) : $this->get_option( 'secret_key' );
159
-		$this->publishable_key         = $this->testmode ? $this->get_option( 'test_publishable_key' ) : $this->get_option( 'publishable_key' );
160
-		$this->bitcoin                 = 'USD' === strtoupper( get_woocommerce_currency() ) && 'yes' === $this->get_option( 'stripe_bitcoin' );
161
-		$this->payment_request         = 'yes' === $this->get_option( 'payment_request', 'yes' );
162
-		$this->apple_pay_domain_set    = 'yes' === $this->get_option( 'apple_pay_domain_set', 'no' );
147
+		$this->title                   = $this->get_option('title');
148
+		$this->description             = $this->get_option('description');
149
+		$this->enabled                 = $this->get_option('enabled');
150
+		$this->testmode                = 'yes' === $this->get_option('testmode');
151
+		$this->inline_cc_form          = 'yes' === $this->get_option('inline_cc_form');
152
+		$this->capture                 = 'yes' === $this->get_option('capture', 'yes');
153
+		$this->statement_descriptor    = WC_Stripe_Helper::clean_statement_descriptor($this->get_option('statement_descriptor'));
154
+		$this->three_d_secure          = 'yes' === $this->get_option('three_d_secure');
155
+		$this->stripe_checkout         = 'yes' === $this->get_option('stripe_checkout');
156
+		$this->stripe_checkout_image   = $this->get_option('stripe_checkout_image', '');
157
+		$this->saved_cards             = 'yes' === $this->get_option('saved_cards');
158
+		$this->secret_key              = $this->testmode ? $this->get_option('test_secret_key') : $this->get_option('secret_key');
159
+		$this->publishable_key         = $this->testmode ? $this->get_option('test_publishable_key') : $this->get_option('publishable_key');
160
+		$this->bitcoin                 = 'USD' === strtoupper(get_woocommerce_currency()) && 'yes' === $this->get_option('stripe_bitcoin');
161
+		$this->payment_request         = 'yes' === $this->get_option('payment_request', 'yes');
162
+		$this->apple_pay_domain_set    = 'yes' === $this->get_option('apple_pay_domain_set', 'no');
163 163
 		$this->apple_pay_verify_notice = '';
164 164
 
165
-		if ( $this->stripe_checkout ) {
166
-			$this->order_button_text = __( 'Continue to payment', 'woocommerce-gateway-stripe' );
165
+		if ($this->stripe_checkout) {
166
+			$this->order_button_text = __('Continue to payment', 'woocommerce-gateway-stripe');
167 167
 		}
168 168
 
169
-		WC_Stripe_API::set_secret_key( $this->secret_key );
169
+		WC_Stripe_API::set_secret_key($this->secret_key);
170 170
 
171 171
 		$this->init_apple_pay();
172 172
 
173 173
 		// Hooks.
174
-		add_action( 'wp_enqueue_scripts', array( $this, 'payment_scripts' ) );
175
-		add_action( 'admin_enqueue_scripts', array( $this, 'admin_scripts' ) );
176
-		add_action( 'admin_notices', array( $this, 'admin_notices' ) );
177
-		add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) );
174
+		add_action('wp_enqueue_scripts', array($this, 'payment_scripts'));
175
+		add_action('admin_enqueue_scripts', array($this, 'admin_scripts'));
176
+		add_action('admin_notices', array($this, 'admin_notices'));
177
+		add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options'));
178 178
 	}
179 179
 
180 180
 	/**
@@ -183,7 +183,7 @@  discard block
 block discarded – undo
183 183
 	 * @since 4.0.2
184 184
 	 */
185 185
 	public function is_available() {
186
-		if ( is_add_payment_method_page() && ! $this->saved_cards ) {
186
+		if (is_add_payment_method_page() && ! $this->saved_cards) {
187 187
 			return false;
188 188
 		}
189 189
 
@@ -206,17 +206,17 @@  discard block
 block discarded – undo
206 206
 		$icons_str .= $icons['amex'];
207 207
 		$icons_str .= $icons['mastercard'];
208 208
 
209
-		if ( 'USD' === get_woocommerce_currency() ) {
209
+		if ('USD' === get_woocommerce_currency()) {
210 210
 			$icons_str .= $icons['discover'];
211 211
 			$icons_str .= $icons['jcb'];
212 212
 			$icons_str .= $icons['diners'];
213 213
 		}
214 214
 
215
-		if ( $this->bitcoin && $this->stripe_checkout ) {
215
+		if ($this->bitcoin && $this->stripe_checkout) {
216 216
 			$icons_str .= $icons['bitcoin'];
217 217
 		}
218 218
 
219
-		return apply_filters( 'woocommerce_gateway_icon', $icons_str, $this->id );
219
+		return apply_filters('woocommerce_gateway_icon', $icons_str, $this->id);
220 220
 	}
221 221
 
222 222
 	/**
@@ -228,9 +228,9 @@  discard block
 block discarded – undo
228 228
 	public function init_apple_pay() {
229 229
 		if (
230 230
 			is_admin() &&
231
-			isset( $_GET['page'] ) && 'wc-settings' === $_GET['page'] &&
232
-			isset( $_GET['tab'] ) && 'checkout' === $_GET['tab'] &&
233
-			isset( $_GET['section'] ) && 'stripe' === $_GET['section'] &&
231
+			isset($_GET['page']) && 'wc-settings' === $_GET['page'] &&
232
+			isset($_GET['tab']) && 'checkout' === $_GET['tab'] &&
233
+			isset($_GET['section']) && 'stripe' === $_GET['section'] &&
234 234
 			$this->payment_request
235 235
 		) {
236 236
 			$this->process_apple_pay_verification();
@@ -244,9 +244,9 @@  discard block
 block discarded – undo
244 244
 	 * @version 3.1.0
245 245
 	 * @param string $secret_key
246 246
 	 */
247
-	private function register_apple_pay_domain( $secret_key = '' ) {
248
-		if ( empty( $secret_key ) ) {
249
-			throw new Exception( __( 'Unable to verify domain - missing secret key.', 'woocommerce-gateway-stripe' ) );
247
+	private function register_apple_pay_domain($secret_key = '') {
248
+		if (empty($secret_key)) {
249
+			throw new Exception(__('Unable to verify domain - missing secret key.', 'woocommerce-gateway-stripe'));
250 250
 		}
251 251
 
252 252
 		$endpoint = 'https://api.stripe.com/v1/apple_pay/domains';
@@ -260,23 +260,23 @@  discard block
 block discarded – undo
260 260
 			'Authorization' => 'Bearer ' . $secret_key,
261 261
 		);
262 262
 
263
-		$response = wp_remote_post( $endpoint, array(
263
+		$response = wp_remote_post($endpoint, array(
264 264
 			'headers' => $headers,
265
-			'body'    => http_build_query( $data ),
266
-		) );
265
+			'body'    => http_build_query($data),
266
+		));
267 267
 
268
-		if ( is_wp_error( $response ) ) {
268
+		if (is_wp_error($response)) {
269 269
 			/* translators: error message */
270
-			throw new Exception( sprintf( __( 'Unable to verify domain - %s', 'woocommerce-gateway-stripe' ), $response->get_error_message() ) );
270
+			throw new Exception(sprintf(__('Unable to verify domain - %s', 'woocommerce-gateway-stripe'), $response->get_error_message()));
271 271
 		}
272 272
 
273
-		if ( 200 !== $response['response']['code'] ) {
274
-			$parsed_response = json_decode( $response['body'] );
273
+		if (200 !== $response['response']['code']) {
274
+			$parsed_response = json_decode($response['body']);
275 275
 
276 276
 			$this->apple_pay_verify_notice = $parsed_response->error->message;
277 277
 
278 278
 			/* translators: error message */
279
-			throw new Exception( sprintf( __( 'Unable to verify domain - %s', 'woocommerce-gateway-stripe' ), $parsed_response->error->message ) );
279
+			throw new Exception(sprintf(__('Unable to verify domain - %s', 'woocommerce-gateway-stripe'), $parsed_response->error->message));
280 280
 		}
281 281
 	}
282 282
 
@@ -287,48 +287,48 @@  discard block
 block discarded – undo
287 287
 	 * @version 3.1.0
288 288
 	 */
289 289
 	public function process_apple_pay_verification() {
290
-		$gateway_settings = get_option( 'woocommerce_stripe_settings', array() );
290
+		$gateway_settings = get_option('woocommerce_stripe_settings', array());
291 291
 
292 292
 		try {
293
-			$path     = untrailingslashit( $_SERVER['DOCUMENT_ROOT'] );
293
+			$path     = untrailingslashit($_SERVER['DOCUMENT_ROOT']);
294 294
 			$dir      = '.well-known';
295 295
 			$file     = 'apple-developer-merchantid-domain-association';
296 296
 			$fullpath = $path . '/' . $dir . '/' . $file;
297 297
 
298
-			if ( ! empty( $gateway_settings['apple_pay_domain_set'] ) && 'yes' === $gateway_settings['apple_pay_domain_set'] && file_exists( $fullpath ) ) {
298
+			if ( ! empty($gateway_settings['apple_pay_domain_set']) && 'yes' === $gateway_settings['apple_pay_domain_set'] && file_exists($fullpath)) {
299 299
 				return;
300 300
 			}
301 301
 
302
-			if ( ! file_exists( $path . '/' . $dir ) ) {
303
-				if ( ! @mkdir( $path . '/' . $dir, 0755 ) ) {
304
-					throw new Exception( __( 'Unable to create domain association folder to domain root.', 'woocommerce-gateway-stripe' ) );
302
+			if ( ! file_exists($path . '/' . $dir)) {
303
+				if ( ! @mkdir($path . '/' . $dir, 0755)) {
304
+					throw new Exception(__('Unable to create domain association folder to domain root.', 'woocommerce-gateway-stripe'));
305 305
 				}
306 306
 			}
307 307
 
308
-			if ( ! file_exists( $fullpath ) ) {
309
-				if ( ! @copy( WC_STRIPE_PLUGIN_PATH . '/' . $file, $fullpath ) ) {
310
-					throw new Exception( __( 'Unable to copy domain association file to domain root.', 'woocommerce-gateway-stripe' ) );
308
+			if ( ! file_exists($fullpath)) {
309
+				if ( ! @copy(WC_STRIPE_PLUGIN_PATH . '/' . $file, $fullpath)) {
310
+					throw new Exception(__('Unable to copy domain association file to domain root.', 'woocommerce-gateway-stripe'));
311 311
 				}
312 312
 			}
313 313
 
314 314
 			// At this point then the domain association folder and file should be available.
315 315
 			// Proceed to verify/and or verify again.
316
-			$this->register_apple_pay_domain( $this->secret_key );
316
+			$this->register_apple_pay_domain($this->secret_key);
317 317
 
318 318
 			// No errors to this point, verification success!
319 319
 			$gateway_settings['apple_pay_domain_set'] = 'yes';
320 320
 			$this->apple_pay_domain_set = true;
321 321
 
322
-			update_option( 'woocommerce_stripe_settings', $gateway_settings );
322
+			update_option('woocommerce_stripe_settings', $gateway_settings);
323 323
 
324
-			WC_Stripe_Logger::log( 'Your domain has been verified with Apple Pay!' );
324
+			WC_Stripe_Logger::log('Your domain has been verified with Apple Pay!');
325 325
 
326
-		} catch ( Exception $e ) {
326
+		} catch (Exception $e) {
327 327
 			$gateway_settings['apple_pay_domain_set'] = 'no';
328 328
 
329
-			update_option( 'woocommerce_stripe_settings', $gateway_settings );
329
+			update_option('woocommerce_stripe_settings', $gateway_settings);
330 330
 
331
-			WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() );
331
+			WC_Stripe_Logger::log('Error: ' . $e->getMessage());
332 332
 		}
333 333
 	}
334 334
 
@@ -336,11 +336,11 @@  discard block
 block discarded – undo
336 336
 	 * Check if SSL is enabled and notify the user
337 337
 	 */
338 338
 	public function admin_notices() {
339
-		if ( 'no' === $this->enabled ) {
339
+		if ('no' === $this->enabled) {
340 340
 			return;
341 341
 		}
342 342
 
343
-		if ( $this->payment_request && ! empty( $this->apple_pay_verify_notice ) ) {
343
+		if ($this->payment_request && ! empty($this->apple_pay_verify_notice)) {
344 344
 			$allowed_html = array(
345 345
 				'a' => array(
346 346
 					'href' => array(),
@@ -348,7 +348,7 @@  discard block
 block discarded – undo
348 348
 				),
349 349
 			);
350 350
 
351
-			echo '<div class="error stripe-apple-pay-message"><p>' . wp_kses( make_clickable( $this->apple_pay_verify_notice ), $allowed_html ) . '</p></div>';
351
+			echo '<div class="error stripe-apple-pay-message"><p>' . wp_kses(make_clickable($this->apple_pay_verify_notice), $allowed_html) . '</p></div>';
352 352
 		}
353 353
 
354 354
 		/**
@@ -356,9 +356,9 @@  discard block
 block discarded – undo
356 356
 		 * when setting screen is displayed. So if domain verification is not set,
357 357
 		 * something went wrong so lets notify user.
358 358
 		 */
359
-		if ( ! empty( $this->secret_key ) && $this->payment_request && ! $this->apple_pay_domain_set ) {
359
+		if ( ! empty($this->secret_key) && $this->payment_request && ! $this->apple_pay_domain_set) {
360 360
 			/* translators: 1) HTML anchor open tag 2) HTML anchor closing tag */
361
-			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>';
361
+			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>';
362 362
 		}
363 363
 	}
364 364
 
@@ -366,7 +366,7 @@  discard block
 block discarded – undo
366 366
 	 * Initialise Gateway Settings Form Fields
367 367
 	 */
368 368
 	public function init_form_fields() {
369
-		$this->form_fields = require( dirname( __FILE__ ) . '/admin/stripe-settings.php' );
369
+		$this->form_fields = require(dirname(__FILE__) . '/admin/stripe-settings.php');
370 370
 	}
371 371
 
372 372
 	/**
@@ -374,59 +374,59 @@  discard block
 block discarded – undo
374 374
 	 */
375 375
 	public function payment_fields() {
376 376
 		$user                 = wp_get_current_user();
377
-		$display_tokenization = $this->supports( 'tokenization' ) && is_checkout() && $this->saved_cards;
377
+		$display_tokenization = $this->supports('tokenization') && is_checkout() && $this->saved_cards;
378 378
 		$total                = WC()->cart->total;
379 379
 		$user_email           = '';
380 380
 
381 381
 		// If paying from order, we need to get total from order not cart.
382
-		if ( isset( $_GET['pay_for_order'] ) && ! empty( $_GET['key'] ) ) {
383
-			$order      = wc_get_order( wc_get_order_id_by_order_key( wc_clean( $_GET['key'] ) ) );
382
+		if (isset($_GET['pay_for_order']) && ! empty($_GET['key'])) {
383
+			$order      = wc_get_order(wc_get_order_id_by_order_key(wc_clean($_GET['key'])));
384 384
 			$total      = $order->get_total();
385 385
 			$user_email = WC_Stripe_Helper::is_pre_30() ? $order->billing_email : $order->get_billing_email();
386 386
 		} else {
387
-			if ( $user->ID ) {
388
-				$user_email = get_user_meta( $user->ID, 'billing_email', true );
387
+			if ($user->ID) {
388
+				$user_email = get_user_meta($user->ID, 'billing_email', true);
389 389
 				$user_email = $user_email ? $user_email : $user->user_email;
390 390
 			}
391 391
 		}
392 392
 
393
-		if ( is_add_payment_method_page() ) {
394
-			$pay_button_text = __( 'Add Card', 'woocommerce-gateway-stripe' );
395
-			$total        = '';
393
+		if (is_add_payment_method_page()) {
394
+			$pay_button_text = __('Add Card', 'woocommerce-gateway-stripe');
395
+			$total = '';
396 396
 		} else {
397 397
 			$pay_button_text = '';
398 398
 		}
399 399
 
400 400
 		echo '<div
401 401
 			id="stripe-payment-data"
402
-			data-panel-label="' . esc_attr( $pay_button_text ) . '"
402
+			data-panel-label="' . esc_attr($pay_button_text) . '"
403 403
 			data-description=""
404
-			data-email="' . esc_attr( $user_email ) . '"
405
-			data-amount="' . esc_attr( WC_Stripe_Helper::get_stripe_amount( $total ) ) . '"
406
-			data-name="' . esc_attr( $this->statement_descriptor ) . '"
407
-			data-currency="' . esc_attr( strtolower( get_woocommerce_currency() ) ) . '"
408
-			data-image="' . esc_attr( $this->stripe_checkout_image ) . '"
409
-			data-bitcoin="' . esc_attr( ( $this->bitcoin && $this->capture ) ? 'true' : 'false' ) . '"
410
-			data-locale="' . esc_attr( apply_filters( 'wc_stripe_checkout_locale', substr( get_locale(), 0, 2 ) ) ) . '"
411
-			data-three-d-secure="' . esc_attr( $this->three_d_secure ? 'true' : 'false' ) . '"
412
-			data-allow-remember-me="' . esc_attr( $this->saved_cards ? 'true' : 'false' ) . '">';
413
-
414
-		if ( $this->description ) {
415
-			if ( $this->testmode ) {
404
+			data-email="' . esc_attr($user_email) . '"
405
+			data-amount="' . esc_attr(WC_Stripe_Helper::get_stripe_amount($total)) . '"
406
+			data-name="' . esc_attr($this->statement_descriptor) . '"
407
+			data-currency="' . esc_attr(strtolower(get_woocommerce_currency())) . '"
408
+			data-image="' . esc_attr($this->stripe_checkout_image) . '"
409
+			data-bitcoin="' . esc_attr(($this->bitcoin && $this->capture) ? 'true' : 'false') . '"
410
+			data-locale="' . esc_attr(apply_filters('wc_stripe_checkout_locale', substr(get_locale(), 0, 2))) . '"
411
+			data-three-d-secure="' . esc_attr($this->three_d_secure ? 'true' : 'false') . '"
412
+			data-allow-remember-me="' . esc_attr($this->saved_cards ? 'true' : 'false') . '">';
413
+
414
+		if ($this->description) {
415
+			if ($this->testmode) {
416 416
 				/* translators: link to Stripe testing page */
417
-				$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' );
418
-				$this->description  = trim( $this->description );
417
+				$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');
418
+				$this->description  = trim($this->description);
419 419
 			}
420
-			echo apply_filters( 'wc_stripe_description', wpautop( wp_kses_post( $this->description ) ) );
420
+			echo apply_filters('wc_stripe_description', wpautop(wp_kses_post($this->description)));
421 421
 		}
422 422
 
423
-		if ( $display_tokenization ) {
423
+		if ($display_tokenization) {
424 424
 			$this->tokenization_script();
425 425
 			$this->saved_payment_methods();
426 426
 		}
427 427
 
428
-		if ( ! $this->stripe_checkout ) {
429
-			if ( apply_filters( 'wc_stripe_use_elements_checkout_form', true ) ) {
428
+		if ( ! $this->stripe_checkout) {
429
+			if (apply_filters('wc_stripe_use_elements_checkout_form', true)) {
430 430
 				$this->elements_form();
431 431
 			} else {
432 432
 				$this->form();
@@ -434,7 +434,7 @@  discard block
 block discarded – undo
434 434
 			}
435 435
 		}
436 436
 
437
-		if ( apply_filters( 'wc_stripe_display_save_payment_method_checkbox', $display_tokenization ) && ! is_add_payment_method_page() && ! isset( $_GET['change_payment_method'] ) ) {
437
+		if (apply_filters('wc_stripe_display_save_payment_method_checkbox', $display_tokenization) && ! is_add_payment_method_page() && ! isset($_GET['change_payment_method'])) {
438 438
 			$this->save_payment_method_checkbox();
439 439
 		}
440 440
 
@@ -449,12 +449,12 @@  discard block
 block discarded – undo
449 449
 	 */
450 450
 	public function elements_form() {
451 451
 		?>
452
-		<fieldset id="wc-<?php echo esc_attr( $this->id ); ?>-cc-form" class="wc-credit-card-form wc-payment-form" style="background:transparent;">
453
-			<?php do_action( 'woocommerce_credit_card_form_start', $this->id ); ?>
452
+		<fieldset id="wc-<?php echo esc_attr($this->id); ?>-cc-form" class="wc-credit-card-form wc-payment-form" style="background:transparent;">
453
+			<?php do_action('woocommerce_credit_card_form_start', $this->id); ?>
454 454
 
455
-			<?php if ( $this->inline_cc_form ) { ?>
455
+			<?php if ($this->inline_cc_form) { ?>
456 456
 				<label for="card-element">
457
-					<?php esc_html_e( 'Credit or debit card', 'woocommerce-gateway-stripe' ); ?>
457
+					<?php esc_html_e('Credit or debit card', 'woocommerce-gateway-stripe'); ?>
458 458
 				</label>
459 459
 
460 460
 				<div id="stripe-card-element" style="background:#fff;padding:0 1em;border:1px solid #ddd;margin:5px 0;padding:10px 5px;">
@@ -462,7 +462,7 @@  discard block
 block discarded – undo
462 462
 				</div>
463 463
 			<?php } else { ?>
464 464
 				<div class="form-row form-row-wide">
465
-					<label><?php _e( 'Card Number', 'woocommerce-gateway-stripe' ); ?> <span class="required">*</span></label>
465
+					<label><?php _e('Card Number', 'woocommerce-gateway-stripe'); ?> <span class="required">*</span></label>
466 466
 
467 467
 					<div id="stripe-card-element" style="background:#fff;padding:0 1em;border:1px solid #ddd;margin:5px 0;padding:10px 5px;">
468 468
 					<!-- a Stripe Element will be inserted here. -->
@@ -470,7 +470,7 @@  discard block
 block discarded – undo
470 470
 				</div>
471 471
 
472 472
 				<div class="form-row form-row-first">
473
-					<label><?php _e( 'Expiry Date', 'woocommerce-gateway-stripe' ); ?> <span class="required">*</span></label>
473
+					<label><?php _e('Expiry Date', 'woocommerce-gateway-stripe'); ?> <span class="required">*</span></label>
474 474
 
475 475
 					<div id="stripe-exp-element" style="background:#fff;padding:0 1em;border:1px solid #ddd;margin:5px 0;padding:10px 5px;">
476 476
 					<!-- a Stripe Element will be inserted here. -->
@@ -478,7 +478,7 @@  discard block
 block discarded – undo
478 478
 				</div>
479 479
 
480 480
 				<div class="form-row form-row-last">
481
-					<label><?php _e( 'Card Code (CVC)', 'woocommerce-gateway-stripe' ); ?> <span class="required">*</span></label>
481
+					<label><?php _e('Card Code (CVC)', 'woocommerce-gateway-stripe'); ?> <span class="required">*</span></label>
482 482
 				<div id="stripe-cvc-element" style="background:#fff;padding:0 1em;border:1px solid #ddd;margin:5px 0;padding:10px 5px;">
483 483
 				<!-- a Stripe Element will be inserted here. -->
484 484
 				</div>
@@ -488,7 +488,7 @@  discard block
 block discarded – undo
488 488
 
489 489
 			<!-- Used to display form errors -->
490 490
 			<div class="stripe-source-errors" role="alert"></div>
491
-			<?php do_action( 'woocommerce_credit_card_form_end', $this->id ); ?>
491
+			<?php do_action('woocommerce_credit_card_form_end', $this->id); ?>
492 492
 			<div class="clear"></div>
493 493
 		</fieldset>
494 494
 		<?php
@@ -501,13 +501,13 @@  discard block
 block discarded – undo
501 501
 	 * @version 3.1.0
502 502
 	 */
503 503
 	public function admin_scripts() {
504
-		if ( 'woocommerce_page_wc-settings' !== get_current_screen()->id ) {
504
+		if ('woocommerce_page_wc-settings' !== get_current_screen()->id) {
505 505
 			return;
506 506
 		}
507 507
 
508
-		$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
508
+		$suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';
509 509
 
510
-		wp_enqueue_script( 'woocommerce_stripe_admin', plugins_url( 'assets/js/stripe-admin' . $suffix . '.js', WC_STRIPE_MAIN_FILE ), array(), WC_STRIPE_VERSION, true );
510
+		wp_enqueue_script('woocommerce_stripe_admin', plugins_url('assets/js/stripe-admin' . $suffix . '.js', WC_STRIPE_MAIN_FILE), array(), WC_STRIPE_VERSION, true);
511 511
 	}
512 512
 
513 513
 	/**
@@ -519,29 +519,29 @@  discard block
 block discarded – undo
519 519
 	 * @version 4.0.0
520 520
 	 */
521 521
 	public function payment_scripts() {
522
-		if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) && ! is_add_payment_method_page() && ! isset( $_GET['change_payment_method'] ) ) {
522
+		if ( ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order']) && ! is_add_payment_method_page() && ! isset($_GET['change_payment_method'])) {
523 523
 			return;
524 524
 		}
525 525
 
526
-		$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
526
+		$suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';
527 527
 
528
-		wp_register_style( 'stripe_paymentfonts', plugins_url( 'assets/css/stripe-paymentfonts.css', WC_STRIPE_MAIN_FILE ), array(), '1.2.5' );
529
-		wp_enqueue_style( 'stripe_paymentfonts' );
530
-		wp_register_script( 'stripe_checkout', 'https://checkout.stripe.com/checkout.js', '', WC_STRIPE_VERSION, true );
531
-		wp_register_script( 'stripev2', 'https://js.stripe.com/v2/', '', '2.0', true );
532
-		wp_register_script( 'stripe', 'https://js.stripe.com/v3/', '', '3.0', true );
533
-		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 );
528
+		wp_register_style('stripe_paymentfonts', plugins_url('assets/css/stripe-paymentfonts.css', WC_STRIPE_MAIN_FILE), array(), '1.2.5');
529
+		wp_enqueue_style('stripe_paymentfonts');
530
+		wp_register_script('stripe_checkout', 'https://checkout.stripe.com/checkout.js', '', WC_STRIPE_VERSION, true);
531
+		wp_register_script('stripev2', 'https://js.stripe.com/v2/', '', '2.0', true);
532
+		wp_register_script('stripe', 'https://js.stripe.com/v3/', '', '3.0', true);
533
+		wp_register_script('woocommerce_stripe', plugins_url('assets/js/stripe' . $suffix . '.js', WC_STRIPE_MAIN_FILE), array('jquery-payment', 'stripev2', 'stripe'), WC_STRIPE_VERSION, true);
534 534
 
535 535
 		$stripe_params = array(
536 536
 			'key'                  => $this->publishable_key,
537
-			'i18n_terms'           => __( 'Please accept the terms and conditions first', 'woocommerce-gateway-stripe' ),
538
-			'i18n_required_fields' => __( 'Please fill in required checkout fields first', 'woocommerce-gateway-stripe' ),
537
+			'i18n_terms'           => __('Please accept the terms and conditions first', 'woocommerce-gateway-stripe'),
538
+			'i18n_required_fields' => __('Please fill in required checkout fields first', 'woocommerce-gateway-stripe'),
539 539
 		);
540 540
 
541 541
 		// If we're on the pay page we need to pass stripe.js the address of the order.
542
-		if ( isset( $_GET['pay_for_order'] ) && 'true' === $_GET['pay_for_order'] ) {
543
-			$order_id = wc_get_order_id_by_order_key( urldecode( $_GET['key'] ) );
544
-			$order    = wc_get_order( $order_id );
542
+		if (isset($_GET['pay_for_order']) && 'true' === $_GET['pay_for_order']) {
543
+			$order_id = wc_get_order_id_by_order_key(urldecode($_GET['key']));
544
+			$order    = wc_get_order($order_id);
545 545
 
546 546
 			$stripe_params['billing_first_name'] = WC_Stripe_Helper::is_pre_30() ? $order->billing_first_name : $order->get_billing_first_name();
547 547
 			$stripe_params['billing_last_name']  = WC_Stripe_Helper::is_pre_30() ? $order->billing_last_name : $order->get_billing_last_name();
@@ -553,38 +553,38 @@  discard block
 block discarded – undo
553 553
 			$stripe_params['billing_country']    = WC_Stripe_Helper::is_pre_30() ? $order->billing_country : $order->get_billing_country();
554 554
 		}
555 555
 
556
-		$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' );
557
-		$stripe_params['no_sepa_owner_msg']                       = __( 'Please enter your IBAN account name.', 'woocommerce-gateway-stripe' );
558
-		$stripe_params['no_sepa_iban_msg']                        = __( 'Please enter your IBAN account number.', 'woocommerce-gateway-stripe' );
559
-		$stripe_params['sepa_mandate_notification']               = apply_filters( 'wc_stripe_sepa_mandate_notification', 'email' );
560
-		$stripe_params['allow_prepaid_card']                      = apply_filters( 'wc_stripe_allow_prepaid_card', true ) ? 'yes' : 'no';
556
+		$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');
557
+		$stripe_params['no_sepa_owner_msg']                       = __('Please enter your IBAN account name.', 'woocommerce-gateway-stripe');
558
+		$stripe_params['no_sepa_iban_msg']                        = __('Please enter your IBAN account number.', 'woocommerce-gateway-stripe');
559
+		$stripe_params['sepa_mandate_notification']               = apply_filters('wc_stripe_sepa_mandate_notification', 'email');
560
+		$stripe_params['allow_prepaid_card']                      = apply_filters('wc_stripe_allow_prepaid_card', true) ? 'yes' : 'no';
561 561
 		$stripe_params['inline_cc_form']                          = $this->inline_cc_form ? 'yes' : 'no';
562
-		$stripe_params['stripe_checkout_require_billing_address'] = apply_filters( 'wc_stripe_checkout_require_billing_address', false ) ? 'yes' : 'no';
563
-		$stripe_params['is_checkout']                             = ( is_checkout() && empty( $_GET['pay_for_order'] ) );
562
+		$stripe_params['stripe_checkout_require_billing_address'] = apply_filters('wc_stripe_checkout_require_billing_address', false) ? 'yes' : 'no';
563
+		$stripe_params['is_checkout']                             = (is_checkout() && empty($_GET['pay_for_order']));
564 564
 		$stripe_params['return_url']                              = $this->get_stripe_return_url();
565
-		$stripe_params['ajaxurl']                                 = WC_AJAX::get_endpoint( '%%endpoint%%' );
566
-		$stripe_params['stripe_nonce']                            = wp_create_nonce( '_wc_stripe_nonce' );
565
+		$stripe_params['ajaxurl']                                 = WC_AJAX::get_endpoint('%%endpoint%%');
566
+		$stripe_params['stripe_nonce']                            = wp_create_nonce('_wc_stripe_nonce');
567 567
 		$stripe_params['statement_descriptor']                    = $this->statement_descriptor;
568
-		$stripe_params['use_elements']                            = apply_filters( 'wc_stripe_use_elements_checkout_form', true ) ? 'yes' : 'no';
569
-		$stripe_params['elements_options']                        = apply_filters( 'wc_stripe_elements_options', array() );
568
+		$stripe_params['use_elements']                            = apply_filters('wc_stripe_use_elements_checkout_form', true) ? 'yes' : 'no';
569
+		$stripe_params['elements_options']                        = apply_filters('wc_stripe_elements_options', array());
570 570
 		$stripe_params['is_stripe_checkout']                      = $this->stripe_checkout ? 'yes' : 'no';
571
-		$stripe_params['is_change_payment_page']                  = ( isset( $_GET['pay_for_order'] ) || isset( $_GET['change_payment_method'] ) ) ? 'yes' : 'no';
571
+		$stripe_params['is_change_payment_page']                  = (isset($_GET['pay_for_order']) || isset($_GET['change_payment_method'])) ? 'yes' : 'no';
572 572
 		$stripe_params['is_add_payment_method_page']              = is_add_payment_method_page() ? 'yes' : 'no';
573
-		$stripe_params['elements_styling']                        = apply_filters( 'wc_stripe_elements_styling', false );
574
-		$stripe_params['elements_classes']                        = apply_filters( 'wc_stripe_elements_classes', false );
573
+		$stripe_params['elements_styling']                        = apply_filters('wc_stripe_elements_styling', false);
574
+		$stripe_params['elements_classes']                        = apply_filters('wc_stripe_elements_classes', false);
575 575
 
576 576
 		// merge localized messages to be use in JS
577
-		$stripe_params = array_merge( $stripe_params, WC_Stripe_Helper::get_localized_messages() );
577
+		$stripe_params = array_merge($stripe_params, WC_Stripe_Helper::get_localized_messages());
578 578
 
579
-		wp_localize_script( 'woocommerce_stripe', 'wc_stripe_params', apply_filters( 'wc_stripe_params', $stripe_params ) );
580
-		wp_localize_script( 'woocommerce_stripe_checkout', 'wc_stripe_params', apply_filters( 'wc_stripe_params', $stripe_params ) );
579
+		wp_localize_script('woocommerce_stripe', 'wc_stripe_params', apply_filters('wc_stripe_params', $stripe_params));
580
+		wp_localize_script('woocommerce_stripe_checkout', 'wc_stripe_params', apply_filters('wc_stripe_params', $stripe_params));
581 581
 
582
-		if ( $this->stripe_checkout ) {
583
-			wp_enqueue_script( 'stripe_checkout' );
582
+		if ($this->stripe_checkout) {
583
+			wp_enqueue_script('stripe_checkout');
584 584
 		}
585 585
 
586 586
 		$this->tokenization_script();
587
-		wp_enqueue_script( 'woocommerce_stripe' );
587
+		wp_enqueue_script('woocommerce_stripe');
588 588
 	}
589 589
 
590 590
 	/**
@@ -600,43 +600,43 @@  discard block
 block discarded – undo
600 600
 	 *
601 601
 	 * @return array|void
602 602
 	 */
603
-	public function process_payment( $order_id, $retry = true, $force_save_source = false ) {
603
+	public function process_payment($order_id, $retry = true, $force_save_source = false) {
604 604
 		try {
605
-			$order = wc_get_order( $order_id );
605
+			$order = wc_get_order($order_id);
606 606
 
607 607
 			// This comes from the create account checkbox in the checkout page.
608
-			$create_account = ! empty( $_POST['createaccount'] ) ? true : false;
608
+			$create_account = ! empty($_POST['createaccount']) ? true : false;
609 609
 
610
-			if ( $create_account ) {
610
+			if ($create_account) {
611 611
 				$new_customer_id     = WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id();
612
-				$new_stripe_customer = new WC_Stripe_Customer( $new_customer_id );
612
+				$new_stripe_customer = new WC_Stripe_Customer($new_customer_id);
613 613
 				$new_stripe_customer->create_customer();
614 614
 			}
615 615
 
616 616
 			$source_object   = $this->get_source_object();
617
-			$prepared_source = $this->prepare_source( $source_object, get_current_user_id(), $force_save_source );
617
+			$prepared_source = $this->prepare_source($source_object, get_current_user_id(), $force_save_source);
618 618
 
619 619
 			// Check if we don't allow prepaid credit cards.
620
-			if ( ! apply_filters( 'wc_stripe_allow_prepaid_card', true ) ) {
621
-				if ( $source_object && 'token' === $source_object->object && 'prepaid' === $source_object->card->funding ) {
622
-					$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' );
623
-					throw new WC_Stripe_Exception( print_r( $source_object, true ), $localized_message );
620
+			if ( ! apply_filters('wc_stripe_allow_prepaid_card', true)) {
621
+				if ($source_object && 'token' === $source_object->object && 'prepaid' === $source_object->card->funding) {
622
+					$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');
623
+					throw new WC_Stripe_Exception(print_r($source_object, true), $localized_message);
624 624
 				}
625 625
 			}
626 626
 
627
-			if ( empty( $prepared_source->source ) ) {
628
-				$localized_message = __( 'Payment processing failed. Please retry.', 'woocommerce-gateway-stripe' );
629
-				throw new WC_Stripe_Exception( print_r( $prepared_source, true ), $localized_message );
627
+			if (empty($prepared_source->source)) {
628
+				$localized_message = __('Payment processing failed. Please retry.', 'woocommerce-gateway-stripe');
629
+				throw new WC_Stripe_Exception(print_r($prepared_source, true), $localized_message);
630 630
 			}
631 631
 
632
-			$this->save_source_to_order( $order, $prepared_source );
632
+			$this->save_source_to_order($order, $prepared_source);
633 633
 
634 634
 			// Result from Stripe API request.
635 635
 			$response = null;
636 636
 
637
-			if ( $order->get_total() > 0 ) {
637
+			if ($order->get_total() > 0) {
638 638
 				// This will throw exception if not valid.
639
-				$this->validate_minimum_order_amount( $order );
639
+				$this->validate_minimum_order_amount($order);
640 640
 
641 641
 				/*
642 642
 				 * Check if card 3DS is required or optional with 3DS setting.
@@ -645,109 +645,109 @@  discard block
 block discarded – undo
645 645
 				 * Note that if we need to save source, the original source must be first
646 646
 				 * attached to a customer in Stripe before it can be charged.
647 647
 				 */
648
-				if ( $this->is_3ds_required( $source_object ) ) {
649
-					$response = $this->create_3ds_source( $order, $source_object );
648
+				if ($this->is_3ds_required($source_object)) {
649
+					$response = $this->create_3ds_source($order, $source_object);
650 650
 
651
-					if ( ! empty( $response->error ) ) {
651
+					if ( ! empty($response->error)) {
652 652
 						$localized_message = $response->error->message;
653 653
 
654
-						$order->add_order_note( $localized_message );
654
+						$order->add_order_note($localized_message);
655 655
 
656
-						throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message );
656
+						throw new WC_Stripe_Exception(print_r($response, true), $localized_message);
657 657
 					}
658 658
 
659 659
 					// Update order meta with 3DS source.
660
-					if ( WC_Stripe_Helper::is_pre_30() ) {
661
-						update_post_meta( $order_id, '_stripe_source_id', $response->id );
660
+					if (WC_Stripe_Helper::is_pre_30()) {
661
+						update_post_meta($order_id, '_stripe_source_id', $response->id);
662 662
 					} else {
663
-						$order->update_meta_data( '_stripe_source_id', $response->id );
663
+						$order->update_meta_data('_stripe_source_id', $response->id);
664 664
 						$order->save();
665 665
 					}
666 666
 
667
-					WC_Stripe_Logger::log( 'Info: Redirecting to 3DS...' );
667
+					WC_Stripe_Logger::log('Info: Redirecting to 3DS...');
668 668
 
669 669
 					return array(
670 670
 						'result'   => 'success',
671
-						'redirect' => esc_url_raw( $response->redirect->url ),
671
+						'redirect' => esc_url_raw($response->redirect->url),
672 672
 					);
673 673
 				}
674 674
 
675
-				WC_Stripe_Logger::log( "Info: Begin processing payment for order $order_id for the amount of {$order->get_total()}" );
675
+				WC_Stripe_Logger::log("Info: Begin processing payment for order $order_id for the amount of {$order->get_total()}");
676 676
 
677 677
 				// Make the request.
678
-				$response = WC_Stripe_API::request( $this->generate_payment_request( $order, $prepared_source ) );
678
+				$response = WC_Stripe_API::request($this->generate_payment_request($order, $prepared_source));
679 679
 
680
-				if ( ! empty( $response->error ) ) {
680
+				if ( ! empty($response->error)) {
681 681
 					// If it is an API error such connection or server, let's retry.
682
-					if ( 'api_connection_error' === $response->error->type || 'api_error' === $response->error->type ) {
683
-						if ( $retry ) {
684
-							sleep( 5 );
685
-							return $this->process_payment( $order_id, false, $force_save_source );
682
+					if ('api_connection_error' === $response->error->type || 'api_error' === $response->error->type) {
683
+						if ($retry) {
684
+							sleep(5);
685
+							return $this->process_payment($order_id, false, $force_save_source);
686 686
 						} else {
687 687
 							$localized_message = 'API connection error and retries exhausted.';
688
-							$order->add_order_note( $localized_message );
689
-							throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message );
688
+							$order->add_order_note($localized_message);
689
+							throw new WC_Stripe_Exception(print_r($response, true), $localized_message);
690 690
 						}
691 691
 					}
692 692
 
693 693
 					// We want to retry.
694
-					if ( $this->is_retryable_error( $response->error ) ) {
695
-						if ( $retry ) {
694
+					if ($this->is_retryable_error($response->error)) {
695
+						if ($retry) {
696 696
 							// Don't do anymore retries after this.
697
-							if ( 5 <= $this->retry_interval ) {
697
+							if (5 <= $this->retry_interval) {
698 698
 
699
-								return $this->process_payment( $order_id, false, $force_save_source );
699
+								return $this->process_payment($order_id, false, $force_save_source);
700 700
 							}
701 701
 
702
-							sleep( $this->retry_interval );
702
+							sleep($this->retry_interval);
703 703
 
704 704
 							$this->retry_interval++;
705
-							return $this->process_payment( $order_id, true, $force_save_source );
705
+							return $this->process_payment($order_id, true, $force_save_source);
706 706
 						} else {
707
-							$localized_message = __( 'On going requests error and retries exhausted.', '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 = __('On going requests error and retries exhausted.', '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
 
713 713
 					// Customer param wrong? The user may have been deleted on stripe's end. Remove customer_id. Can be retried without.
714
-					if ( preg_match( '/No such customer/i', $response->error->message ) && $retry ) {
715
-						if ( WC_Stripe_Helper::is_pre_30() ) {
716
-							delete_user_meta( $order->customer_user, '_stripe_customer_id' );
717
-							delete_post_meta( $order_id, '_stripe_customer_id' );
714
+					if (preg_match('/No such customer/i', $response->error->message) && $retry) {
715
+						if (WC_Stripe_Helper::is_pre_30()) {
716
+							delete_user_meta($order->customer_user, '_stripe_customer_id');
717
+							delete_post_meta($order_id, '_stripe_customer_id');
718 718
 						} else {
719
-							delete_user_meta( $order->get_customer_id(), '_stripe_customer_id' );
720
-							$order->delete_meta_data( '_stripe_customer_id' );
719
+							delete_user_meta($order->get_customer_id(), '_stripe_customer_id');
720
+							$order->delete_meta_data('_stripe_customer_id');
721 721
 							$order->save();
722 722
 						}
723 723
 
724
-						return $this->process_payment( $order_id, false, $force_save_source );
725
-					} elseif ( preg_match( '/No such token/i', $response->error->message ) && $prepared_source->token_id ) {
724
+						return $this->process_payment($order_id, false, $force_save_source);
725
+					} elseif (preg_match('/No such token/i', $response->error->message) && $prepared_source->token_id) {
726 726
 						// Source param wrong? The CARD may have been deleted on stripe's end. Remove token and show message.
727
-						$wc_token = WC_Payment_Tokens::get( $prepared_source->token_id );
727
+						$wc_token = WC_Payment_Tokens::get($prepared_source->token_id);
728 728
 						$wc_token->delete();
729
-						$localized_message = __( 'This card is no longer available and has been removed.', 'woocommerce-gateway-stripe' );
730
-						$order->add_order_note( $localized_message );
731
-						throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message );
729
+						$localized_message = __('This card is no longer available and has been removed.', 'woocommerce-gateway-stripe');
730
+						$order->add_order_note($localized_message);
731
+						throw new WC_Stripe_Exception(print_r($response, true), $localized_message);
732 732
 					}
733 733
 
734 734
 					$localized_messages = WC_Stripe_Helper::get_localized_messages();
735 735
 
736
-					if ( 'card_error' === $response->error->type ) {
737
-						$localized_message = isset( $localized_messages[ $response->error->code ] ) ? $localized_messages[ $response->error->code ] : $response->error->message;
736
+					if ('card_error' === $response->error->type) {
737
+						$localized_message = isset($localized_messages[$response->error->code]) ? $localized_messages[$response->error->code] : $response->error->message;
738 738
 					} else {
739
-						$localized_message = isset( $localized_messages[ $response->error->type ] ) ? $localized_messages[ $response->error->type ] : $response->error->message;
739
+						$localized_message = isset($localized_messages[$response->error->type]) ? $localized_messages[$response->error->type] : $response->error->message;
740 740
 					}
741 741
 
742
-					$order->add_order_note( $localized_message );
742
+					$order->add_order_note($localized_message);
743 743
 
744
-					throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message );
744
+					throw new WC_Stripe_Exception(print_r($response, true), $localized_message);
745 745
 				}
746 746
 
747
-				do_action( 'wc_gateway_stripe_process_payment', $response, $order );
747
+				do_action('wc_gateway_stripe_process_payment', $response, $order);
748 748
 
749 749
 				// Process valid response.
750
-				$this->process_response( $response, $order );
750
+				$this->process_response($response, $order);
751 751
 			} else {
752 752
 				$order->payment_complete();
753 753
 			}
@@ -758,17 +758,17 @@  discard block
 block discarded – undo
758 758
 			// Return thank you page redirect.
759 759
 			return array(
760 760
 				'result'   => 'success',
761
-				'redirect' => $this->get_return_url( $order ),
761
+				'redirect' => $this->get_return_url($order),
762 762
 			);
763 763
 
764
-		} catch ( WC_Stripe_Exception $e ) {
765
-			wc_add_notice( $e->getLocalizedMessage(), 'error' );
766
-			WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() );
764
+		} catch (WC_Stripe_Exception $e) {
765
+			wc_add_notice($e->getLocalizedMessage(), 'error');
766
+			WC_Stripe_Logger::log('Error: ' . $e->getMessage());
767 767
 
768
-			do_action( 'wc_gateway_stripe_process_payment_error', $e, $order );
768
+			do_action('wc_gateway_stripe_process_payment_error', $e, $order);
769 769
 
770
-			if ( $order->has_status( array( 'pending', 'failed' ) ) ) {
771
-				$this->send_failed_order_email( $order_id );
770
+			if ($order->has_status(array('pending', 'failed'))) {
771
+				$this->send_failed_order_email($order_id);
772 772
 			}
773 773
 
774 774
 			return array(
Please login to merge, or discard this patch.