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