Completed
Push — master ( 57ddc9...4065b6 )
by Roy
04:18
created
includes/class-wc-gateway-stripe.php 1 patch
Spacing   +180 added lines, -180 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
 
@@ -101,9 +101,9 @@  discard block
 block discarded – undo
101 101
 	public function __construct() {
102 102
 		$this->retry_interval       = 2;
103 103
 		$this->id                   = 'stripe';
104
-		$this->method_title         = __( 'Stripe', 'woocommerce-gateway-stripe' );
104
+		$this->method_title         = __('Stripe', 'woocommerce-gateway-stripe');
105 105
 		/* translators: 1) link to Stripe register page 2) link to Stripe api keys page */
106
-		$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' );
106
+		$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');
107 107
 		$this->has_fields           = true;
108 108
 		$this->supports             = array(
109 109
 			'products',
@@ -130,32 +130,32 @@  discard block
 block discarded – undo
130 130
 		$this->init_settings();
131 131
 
132 132
 		// Get setting values.
133
-		$this->title                   = $this->get_option( 'title' );
134
-		$this->description             = $this->get_option( 'description' );
135
-		$this->enabled                 = $this->get_option( 'enabled' );
136
-		$this->testmode                = 'yes' === $this->get_option( 'testmode' );
137
-		$this->inline_cc_form          = 'yes' === $this->get_option( 'inline_cc_form' );
138
-		$this->capture                 = 'yes' === $this->get_option( 'capture', 'yes' );
139
-		$this->statement_descriptor    = WC_Stripe_Helper::clean_statement_descriptor( $this->get_option( 'statement_descriptor' ) );
140
-		$this->three_d_secure          = 'yes' === $this->get_option( 'three_d_secure' );
141
-		$this->stripe_checkout         = 'yes' === $this->get_option( 'stripe_checkout' );
142
-		$this->stripe_checkout_image   = $this->get_option( 'stripe_checkout_image', '' );
143
-		$this->saved_cards             = 'yes' === $this->get_option( 'saved_cards' );
144
-		$this->secret_key              = $this->testmode ? $this->get_option( 'test_secret_key' ) : $this->get_option( 'secret_key' );
145
-		$this->publishable_key         = $this->testmode ? $this->get_option( 'test_publishable_key' ) : $this->get_option( 'publishable_key' );
146
-		$this->bitcoin                 = 'USD' === strtoupper( get_woocommerce_currency() ) && 'yes' === $this->get_option( 'stripe_bitcoin' );
147
-		$this->payment_request         = 'yes' === $this->get_option( 'payment_request', 'yes' );
148
-
149
-		if ( $this->stripe_checkout ) {
150
-			$this->order_button_text = __( 'Continue to payment', 'woocommerce-gateway-stripe' );
133
+		$this->title                   = $this->get_option('title');
134
+		$this->description             = $this->get_option('description');
135
+		$this->enabled                 = $this->get_option('enabled');
136
+		$this->testmode                = 'yes' === $this->get_option('testmode');
137
+		$this->inline_cc_form          = 'yes' === $this->get_option('inline_cc_form');
138
+		$this->capture                 = 'yes' === $this->get_option('capture', 'yes');
139
+		$this->statement_descriptor    = WC_Stripe_Helper::clean_statement_descriptor($this->get_option('statement_descriptor'));
140
+		$this->three_d_secure          = 'yes' === $this->get_option('three_d_secure');
141
+		$this->stripe_checkout         = 'yes' === $this->get_option('stripe_checkout');
142
+		$this->stripe_checkout_image   = $this->get_option('stripe_checkout_image', '');
143
+		$this->saved_cards             = 'yes' === $this->get_option('saved_cards');
144
+		$this->secret_key              = $this->testmode ? $this->get_option('test_secret_key') : $this->get_option('secret_key');
145
+		$this->publishable_key         = $this->testmode ? $this->get_option('test_publishable_key') : $this->get_option('publishable_key');
146
+		$this->bitcoin                 = 'USD' === strtoupper(get_woocommerce_currency()) && 'yes' === $this->get_option('stripe_bitcoin');
147
+		$this->payment_request         = 'yes' === $this->get_option('payment_request', 'yes');
148
+
149
+		if ($this->stripe_checkout) {
150
+			$this->order_button_text = __('Continue to payment', 'woocommerce-gateway-stripe');
151 151
 		}
152 152
 
153
-		WC_Stripe_API::set_secret_key( $this->secret_key );
153
+		WC_Stripe_API::set_secret_key($this->secret_key);
154 154
 
155 155
 		// Hooks.
156
-		add_action( 'wp_enqueue_scripts', array( $this, 'payment_scripts' ) );
157
-		add_action( 'admin_enqueue_scripts', array( $this, 'admin_scripts' ) );
158
-		add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) );
156
+		add_action('wp_enqueue_scripts', array($this, 'payment_scripts'));
157
+		add_action('admin_enqueue_scripts', array($this, 'admin_scripts'));
158
+		add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options'));
159 159
 	}
160 160
 
161 161
 	/**
@@ -165,7 +165,7 @@  discard block
 block discarded – undo
165 165
 	 * @return bool
166 166
 	 */
167 167
 	public function are_keys_set() {
168
-		if ( empty( $this->secret_key ) || empty( $this->publishable_key ) ) {
168
+		if (empty($this->secret_key) || empty($this->publishable_key)) {
169 169
 			return false;
170 170
 		}
171 171
 
@@ -178,7 +178,7 @@  discard block
 block discarded – undo
178 178
 	 * @since 4.0.2
179 179
 	 */
180 180
 	public function is_available() {
181
-		if ( is_add_payment_method_page() && ! $this->saved_cards ) {
181
+		if (is_add_payment_method_page() && ! $this->saved_cards) {
182 182
 			return false;
183 183
 		}
184 184
 
@@ -201,24 +201,24 @@  discard block
 block discarded – undo
201 201
 		$icons_str .= $icons['amex'];
202 202
 		$icons_str .= $icons['mastercard'];
203 203
 
204
-		if ( 'USD' === get_woocommerce_currency() ) {
204
+		if ('USD' === get_woocommerce_currency()) {
205 205
 			$icons_str .= $icons['discover'];
206 206
 			$icons_str .= $icons['jcb'];
207 207
 			$icons_str .= $icons['diners'];
208 208
 		}
209 209
 
210
-		if ( $this->bitcoin && $this->stripe_checkout ) {
210
+		if ($this->bitcoin && $this->stripe_checkout) {
211 211
 			$icons_str .= $icons['bitcoin'];
212 212
 		}
213 213
 
214
-		return apply_filters( 'woocommerce_gateway_icon', $icons_str, $this->id );
214
+		return apply_filters('woocommerce_gateway_icon', $icons_str, $this->id);
215 215
 	}
216 216
 
217 217
 	/**
218 218
 	 * Initialise Gateway Settings Form Fields
219 219
 	 */
220 220
 	public function init_form_fields() {
221
-		$this->form_fields = require( dirname( __FILE__ ) . '/admin/stripe-settings.php' );
221
+		$this->form_fields = require(dirname(__FILE__) . '/admin/stripe-settings.php');
222 222
 	}
223 223
 
224 224
 	/**
@@ -226,68 +226,68 @@  discard block
 block discarded – undo
226 226
 	 */
227 227
 	public function payment_fields() {
228 228
 		$user                 = wp_get_current_user();
229
-		$display_tokenization = $this->supports( 'tokenization' ) && is_checkout() && $this->saved_cards;
229
+		$display_tokenization = $this->supports('tokenization') && is_checkout() && $this->saved_cards;
230 230
 		$total                = WC()->cart->total;
231 231
 		$user_email           = '';
232 232
 
233 233
 		// If paying from order, we need to get total from order not cart.
234
-		if ( isset( $_GET['pay_for_order'] ) && ! empty( $_GET['key'] ) ) {
235
-			$order      = wc_get_order( wc_get_order_id_by_order_key( wc_clean( $_GET['key'] ) ) );
234
+		if (isset($_GET['pay_for_order']) && ! empty($_GET['key'])) {
235
+			$order      = wc_get_order(wc_get_order_id_by_order_key(wc_clean($_GET['key'])));
236 236
 			$total      = $order->get_total();
237 237
 			$user_email = WC_Stripe_Helper::is_pre_30() ? $order->billing_email : $order->get_billing_email();
238 238
 		} else {
239
-			if ( $user->ID ) {
240
-				$user_email = get_user_meta( $user->ID, 'billing_email', true );
239
+			if ($user->ID) {
240
+				$user_email = get_user_meta($user->ID, 'billing_email', true);
241 241
 				$user_email = $user_email ? $user_email : $user->user_email;
242 242
 			}
243 243
 		}
244 244
 
245
-		if ( is_add_payment_method_page() ) {
246
-			$pay_button_text = __( 'Add Card', 'woocommerce-gateway-stripe' );
247
-			$total        = '';
245
+		if (is_add_payment_method_page()) {
246
+			$pay_button_text = __('Add Card', 'woocommerce-gateway-stripe');
247
+			$total = '';
248 248
 		} else {
249 249
 			$pay_button_text = '';
250 250
 		}
251 251
 
252 252
 		echo '<div
253 253
 			id="stripe-payment-data"
254
-			data-panel-label="' . esc_attr( $pay_button_text ) . '"
254
+			data-panel-label="' . esc_attr($pay_button_text) . '"
255 255
 			data-description=""
256
-			data-email="' . esc_attr( $user_email ) . '"
257
-			data-amount="' . esc_attr( WC_Stripe_Helper::get_stripe_amount( $total ) ) . '"
258
-			data-name="' . esc_attr( $this->statement_descriptor ) . '"
259
-			data-currency="' . esc_attr( strtolower( get_woocommerce_currency() ) ) . '"
260
-			data-image="' . esc_attr( $this->stripe_checkout_image ) . '"
261
-			data-bitcoin="' . esc_attr( ( $this->bitcoin && $this->capture ) ? 'true' : 'false' ) . '"
262
-			data-locale="' . esc_attr( apply_filters( 'wc_stripe_checkout_locale', $this->get_locale() ) ) . '"
263
-			data-three-d-secure="' . esc_attr( $this->three_d_secure ? 'true' : 'false' ) . '"
264
-			data-allow-remember-me="' . esc_attr( $this->saved_cards ? 'true' : 'false' ) . '">';
265
-
266
-		if ( $this->description ) {
267
-			if ( $this->testmode ) {
256
+			data-email="' . esc_attr($user_email) . '"
257
+			data-amount="' . esc_attr(WC_Stripe_Helper::get_stripe_amount($total)) . '"
258
+			data-name="' . esc_attr($this->statement_descriptor) . '"
259
+			data-currency="' . esc_attr(strtolower(get_woocommerce_currency())) . '"
260
+			data-image="' . esc_attr($this->stripe_checkout_image) . '"
261
+			data-bitcoin="' . esc_attr(($this->bitcoin && $this->capture) ? 'true' : 'false') . '"
262
+			data-locale="' . esc_attr(apply_filters('wc_stripe_checkout_locale', $this->get_locale())) . '"
263
+			data-three-d-secure="' . esc_attr($this->three_d_secure ? 'true' : 'false') . '"
264
+			data-allow-remember-me="' . esc_attr($this->saved_cards ? 'true' : 'false') . '">';
265
+
266
+		if ($this->description) {
267
+			if ($this->testmode) {
268 268
 				/* translators: link to Stripe testing page */
269
-				$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' );
270
-				$this->description  = trim( $this->description );
269
+				$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');
270
+				$this->description  = trim($this->description);
271 271
 			}
272
-			echo apply_filters( 'wc_stripe_description', wpautop( wp_kses_post( $this->description ) ) );
272
+			echo apply_filters('wc_stripe_description', wpautop(wp_kses_post($this->description)));
273 273
 		}
274 274
 
275
-		if ( $display_tokenization ) {
275
+		if ($display_tokenization) {
276 276
 			$this->tokenization_script();
277 277
 			$this->saved_payment_methods();
278 278
 		}
279 279
 
280
-		if ( ! $this->stripe_checkout ) {
281
-			if ( apply_filters( 'wc_stripe_use_elements_checkout_form', true ) ) {
280
+		if ( ! $this->stripe_checkout) {
281
+			if (apply_filters('wc_stripe_use_elements_checkout_form', true)) {
282 282
 				$this->elements_form();
283 283
 			} else {
284
-				WC_Stripe_Logger::log( 'DEPRECATED! Since version 4.0. Stripe Elements is used. This legacy credit card form will be removed by version 5.0!' );
284
+				WC_Stripe_Logger::log('DEPRECATED! Since version 4.0. Stripe Elements is used. This legacy credit card form will be removed by version 5.0!');
285 285
 				$this->form();
286 286
 				echo '<div class="stripe-source-errors" role="alert"></div>';
287 287
 			}
288 288
 		}
289 289
 
290
-		if ( apply_filters( 'wc_stripe_display_save_payment_method_checkbox', $display_tokenization ) && ! is_add_payment_method_page() && ! isset( $_GET['change_payment_method'] ) ) {
290
+		if (apply_filters('wc_stripe_display_save_payment_method_checkbox', $display_tokenization) && ! is_add_payment_method_page() && ! isset($_GET['change_payment_method'])) {
291 291
 			$this->save_payment_method_checkbox();
292 292
 		}
293 293
 
@@ -302,12 +302,12 @@  discard block
 block discarded – undo
302 302
 	 */
303 303
 	public function elements_form() {
304 304
 		?>
305
-		<fieldset id="wc-<?php echo esc_attr( $this->id ); ?>-cc-form" class="wc-credit-card-form wc-payment-form" style="background:transparent;">
306
-			<?php do_action( 'woocommerce_credit_card_form_start', $this->id ); ?>
305
+		<fieldset id="wc-<?php echo esc_attr($this->id); ?>-cc-form" class="wc-credit-card-form wc-payment-form" style="background:transparent;">
306
+			<?php do_action('woocommerce_credit_card_form_start', $this->id); ?>
307 307
 
308
-			<?php if ( $this->inline_cc_form ) { ?>
308
+			<?php if ($this->inline_cc_form) { ?>
309 309
 				<label for="card-element">
310
-					<?php esc_html_e( 'Credit or debit card', 'woocommerce-gateway-stripe' ); ?>
310
+					<?php esc_html_e('Credit or debit card', 'woocommerce-gateway-stripe'); ?>
311 311
 				</label>
312 312
 
313 313
 				<div id="stripe-card-element" style="background:#fff;padding:0 1em;border:1px solid #ddd;margin:5px 0;padding:10px 5px;">
@@ -315,7 +315,7 @@  discard block
 block discarded – undo
315 315
 				</div>
316 316
 			<?php } else { ?>
317 317
 				<div class="form-row form-row-wide">
318
-					<label><?php _e( 'Card Number', 'woocommerce-gateway-stripe' ); ?> <span class="required">*</span></label>
318
+					<label><?php _e('Card Number', 'woocommerce-gateway-stripe'); ?> <span class="required">*</span></label>
319 319
 
320 320
 					<div id="stripe-card-element" style="background:#fff;padding:0 1em;border:1px solid #ddd;margin:5px 0;padding:10px 5px;">
321 321
 					<!-- a Stripe Element will be inserted here. -->
@@ -323,7 +323,7 @@  discard block
 block discarded – undo
323 323
 				</div>
324 324
 
325 325
 				<div class="form-row form-row-first">
326
-					<label><?php _e( 'Expiry Date', 'woocommerce-gateway-stripe' ); ?> <span class="required">*</span></label>
326
+					<label><?php _e('Expiry Date', 'woocommerce-gateway-stripe'); ?> <span class="required">*</span></label>
327 327
 
328 328
 					<div id="stripe-exp-element" style="background:#fff;padding:0 1em;border:1px solid #ddd;margin:5px 0;padding:10px 5px;">
329 329
 					<!-- a Stripe Element will be inserted here. -->
@@ -331,7 +331,7 @@  discard block
 block discarded – undo
331 331
 				</div>
332 332
 
333 333
 				<div class="form-row form-row-last">
334
-					<label><?php _e( 'Card Code (CVC)', 'woocommerce-gateway-stripe' ); ?> <span class="required">*</span></label>
334
+					<label><?php _e('Card Code (CVC)', 'woocommerce-gateway-stripe'); ?> <span class="required">*</span></label>
335 335
 				<div id="stripe-cvc-element" style="background:#fff;padding:0 1em;border:1px solid #ddd;margin:5px 0;padding:10px 5px;">
336 336
 				<!-- a Stripe Element will be inserted here. -->
337 337
 				</div>
@@ -341,7 +341,7 @@  discard block
 block discarded – undo
341 341
 
342 342
 			<!-- Used to display form errors -->
343 343
 			<div class="stripe-source-errors" role="alert"></div>
344
-			<?php do_action( 'woocommerce_credit_card_form_end', $this->id ); ?>
344
+			<?php do_action('woocommerce_credit_card_form_end', $this->id); ?>
345 345
 			<div class="clear"></div>
346 346
 		</fieldset>
347 347
 		<?php
@@ -354,13 +354,13 @@  discard block
 block discarded – undo
354 354
 	 * @version 3.1.0
355 355
 	 */
356 356
 	public function admin_scripts() {
357
-		if ( 'woocommerce_page_wc-settings' !== get_current_screen()->id ) {
357
+		if ('woocommerce_page_wc-settings' !== get_current_screen()->id) {
358 358
 			return;
359 359
 		}
360 360
 
361
-		$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
361
+		$suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';
362 362
 
363
-		wp_enqueue_script( 'woocommerce_stripe_admin', plugins_url( 'assets/js/stripe-admin' . $suffix . '.js', WC_STRIPE_MAIN_FILE ), array(), WC_STRIPE_VERSION, true );
363
+		wp_enqueue_script('woocommerce_stripe_admin', plugins_url('assets/js/stripe-admin' . $suffix . '.js', WC_STRIPE_MAIN_FILE), array(), WC_STRIPE_VERSION, true);
364 364
 	}
365 365
 
366 366
 	/**
@@ -372,46 +372,46 @@  discard block
 block discarded – undo
372 372
 	 * @version 4.0.0
373 373
 	 */
374 374
 	public function payment_scripts() {
375
-		if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) && ! is_add_payment_method_page() && ! isset( $_GET['change_payment_method'] ) ) {
375
+		if ( ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order']) && ! is_add_payment_method_page() && ! isset($_GET['change_payment_method'])) {
376 376
 			return;
377 377
 		}
378 378
 
379 379
 		// If Stripe is not enabled bail.
380
-		if ( 'no' === $this->enabled ) {
380
+		if ('no' === $this->enabled) {
381 381
 			return;
382 382
 		}
383 383
 
384 384
 		// If keys are not set bail.
385
-		if ( ! $this->are_keys_set() ) {
386
-			WC_Stripe_Logger::log( 'Keys are not set correctly.' );
385
+		if ( ! $this->are_keys_set()) {
386
+			WC_Stripe_Logger::log('Keys are not set correctly.');
387 387
 			return;
388 388
 		}
389 389
 
390 390
 		// If no SSL bail.
391
-		if ( ! $this->testmode && ! is_ssl() ) {
392
-			WC_Stripe_Logger::log( 'Stripe requires SSL.' );
391
+		if ( ! $this->testmode && ! is_ssl()) {
392
+			WC_Stripe_Logger::log('Stripe requires SSL.');
393 393
 			return;
394 394
 		}
395 395
 
396
-		$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
396
+		$suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';
397 397
 
398
-		wp_register_style( 'stripe_paymentfonts', plugins_url( 'assets/css/stripe-paymentfonts.css', WC_STRIPE_MAIN_FILE ), array(), '1.2.5' );
399
-		wp_enqueue_style( 'stripe_paymentfonts' );
400
-		wp_register_script( 'stripe_checkout', 'https://checkout.stripe.com/checkout.js', '', WC_STRIPE_VERSION, true );
401
-		wp_register_script( 'stripev2', 'https://js.stripe.com/v2/', '', '2.0', true );
402
-		wp_register_script( 'stripe', 'https://js.stripe.com/v3/', '', '3.0', true );
403
-		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 );
398
+		wp_register_style('stripe_paymentfonts', plugins_url('assets/css/stripe-paymentfonts.css', WC_STRIPE_MAIN_FILE), array(), '1.2.5');
399
+		wp_enqueue_style('stripe_paymentfonts');
400
+		wp_register_script('stripe_checkout', 'https://checkout.stripe.com/checkout.js', '', WC_STRIPE_VERSION, true);
401
+		wp_register_script('stripev2', 'https://js.stripe.com/v2/', '', '2.0', true);
402
+		wp_register_script('stripe', 'https://js.stripe.com/v3/', '', '3.0', true);
403
+		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);
404 404
 
405 405
 		$stripe_params = array(
406 406
 			'key'                  => $this->publishable_key,
407
-			'i18n_terms'           => __( 'Please accept the terms and conditions first', 'woocommerce-gateway-stripe' ),
408
-			'i18n_required_fields' => __( 'Please fill in required checkout fields first', 'woocommerce-gateway-stripe' ),
407
+			'i18n_terms'           => __('Please accept the terms and conditions first', 'woocommerce-gateway-stripe'),
408
+			'i18n_required_fields' => __('Please fill in required checkout fields first', 'woocommerce-gateway-stripe'),
409 409
 		);
410 410
 
411 411
 		// If we're on the pay page we need to pass stripe.js the address of the order.
412
-		if ( isset( $_GET['pay_for_order'] ) && 'true' === $_GET['pay_for_order'] ) {
413
-			$order_id = wc_get_order_id_by_order_key( urldecode( $_GET['key'] ) );
414
-			$order    = wc_get_order( $order_id );
412
+		if (isset($_GET['pay_for_order']) && 'true' === $_GET['pay_for_order']) {
413
+			$order_id = wc_get_order_id_by_order_key(urldecode($_GET['key']));
414
+			$order    = wc_get_order($order_id);
415 415
 
416 416
 			$stripe_params['billing_first_name'] = WC_Stripe_Helper::is_pre_30() ? $order->billing_first_name : $order->get_billing_first_name();
417 417
 			$stripe_params['billing_last_name']  = WC_Stripe_Helper::is_pre_30() ? $order->billing_last_name : $order->get_billing_last_name();
@@ -423,38 +423,38 @@  discard block
 block discarded – undo
423 423
 			$stripe_params['billing_country']    = WC_Stripe_Helper::is_pre_30() ? $order->billing_country : $order->get_billing_country();
424 424
 		}
425 425
 
426
-		$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' );
427
-		$stripe_params['no_sepa_owner_msg']                       = __( 'Please enter your IBAN account name.', 'woocommerce-gateway-stripe' );
428
-		$stripe_params['no_sepa_iban_msg']                        = __( 'Please enter your IBAN account number.', 'woocommerce-gateway-stripe' );
429
-		$stripe_params['sepa_mandate_notification']               = apply_filters( 'wc_stripe_sepa_mandate_notification', 'email' );
430
-		$stripe_params['allow_prepaid_card']                      = apply_filters( 'wc_stripe_allow_prepaid_card', true ) ? 'yes' : 'no';
426
+		$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');
427
+		$stripe_params['no_sepa_owner_msg']                       = __('Please enter your IBAN account name.', 'woocommerce-gateway-stripe');
428
+		$stripe_params['no_sepa_iban_msg']                        = __('Please enter your IBAN account number.', 'woocommerce-gateway-stripe');
429
+		$stripe_params['sepa_mandate_notification']               = apply_filters('wc_stripe_sepa_mandate_notification', 'email');
430
+		$stripe_params['allow_prepaid_card']                      = apply_filters('wc_stripe_allow_prepaid_card', true) ? 'yes' : 'no';
431 431
 		$stripe_params['inline_cc_form']                          = $this->inline_cc_form ? 'yes' : 'no';
432
-		$stripe_params['stripe_checkout_require_billing_address'] = apply_filters( 'wc_stripe_checkout_require_billing_address', false ) ? 'yes' : 'no';
433
-		$stripe_params['is_checkout']                             = ( is_checkout() && empty( $_GET['pay_for_order'] ) );
432
+		$stripe_params['stripe_checkout_require_billing_address'] = apply_filters('wc_stripe_checkout_require_billing_address', false) ? 'yes' : 'no';
433
+		$stripe_params['is_checkout']                             = (is_checkout() && empty($_GET['pay_for_order']));
434 434
 		$stripe_params['return_url']                              = $this->get_stripe_return_url();
435
-		$stripe_params['ajaxurl']                                 = WC_AJAX::get_endpoint( '%%endpoint%%' );
436
-		$stripe_params['stripe_nonce']                            = wp_create_nonce( '_wc_stripe_nonce' );
435
+		$stripe_params['ajaxurl']                                 = WC_AJAX::get_endpoint('%%endpoint%%');
436
+		$stripe_params['stripe_nonce']                            = wp_create_nonce('_wc_stripe_nonce');
437 437
 		$stripe_params['statement_descriptor']                    = $this->statement_descriptor;
438
-		$stripe_params['use_elements']                            = apply_filters( 'wc_stripe_use_elements_checkout_form', true ) ? 'yes' : 'no';
439
-		$stripe_params['elements_options']                        = apply_filters( 'wc_stripe_elements_options', array() );
438
+		$stripe_params['use_elements']                            = apply_filters('wc_stripe_use_elements_checkout_form', true) ? 'yes' : 'no';
439
+		$stripe_params['elements_options']                        = apply_filters('wc_stripe_elements_options', array());
440 440
 		$stripe_params['is_stripe_checkout']                      = $this->stripe_checkout ? 'yes' : 'no';
441
-		$stripe_params['is_change_payment_page']                  = isset( $_GET['change_payment_method'] ) ? 'yes' : 'no';
442
-		$stripe_params['validate_modal_checkout']                 = apply_filters( 'wc_stripe_validate_model_checkout', true ) ? 'yes' : 'no';
443
-		$stripe_params['elements_styling']                        = apply_filters( 'wc_stripe_elements_styling', false );
444
-		$stripe_params['elements_classes']                        = apply_filters( 'wc_stripe_elements_classes', false );
441
+		$stripe_params['is_change_payment_page']                  = isset($_GET['change_payment_method']) ? 'yes' : 'no';
442
+		$stripe_params['validate_modal_checkout']                 = apply_filters('wc_stripe_validate_model_checkout', true) ? 'yes' : 'no';
443
+		$stripe_params['elements_styling']                        = apply_filters('wc_stripe_elements_styling', false);
444
+		$stripe_params['elements_classes']                        = apply_filters('wc_stripe_elements_classes', false);
445 445
 
446 446
 		// merge localized messages to be use in JS
447
-		$stripe_params = array_merge( $stripe_params, WC_Stripe_Helper::get_localized_messages() );
447
+		$stripe_params = array_merge($stripe_params, WC_Stripe_Helper::get_localized_messages());
448 448
 
449
-		wp_localize_script( 'woocommerce_stripe', 'wc_stripe_params', apply_filters( 'wc_stripe_params', $stripe_params ) );
450
-		wp_localize_script( 'woocommerce_stripe_checkout', 'wc_stripe_params', apply_filters( 'wc_stripe_params', $stripe_params ) );
449
+		wp_localize_script('woocommerce_stripe', 'wc_stripe_params', apply_filters('wc_stripe_params', $stripe_params));
450
+		wp_localize_script('woocommerce_stripe_checkout', 'wc_stripe_params', apply_filters('wc_stripe_params', $stripe_params));
451 451
 
452
-		if ( $this->stripe_checkout ) {
453
-			wp_enqueue_script( 'stripe_checkout' );
452
+		if ($this->stripe_checkout) {
453
+			wp_enqueue_script('stripe_checkout');
454 454
 		}
455 455
 
456 456
 		$this->tokenization_script();
457
-		wp_enqueue_script( 'woocommerce_stripe' );
457
+		wp_enqueue_script('woocommerce_stripe');
458 458
 	}
459 459
 
460 460
 	/**
@@ -470,43 +470,43 @@  discard block
 block discarded – undo
470 470
 	 *
471 471
 	 * @return array|void
472 472
 	 */
473
-	public function process_payment( $order_id, $retry = true, $force_save_source = false ) {
473
+	public function process_payment($order_id, $retry = true, $force_save_source = false) {
474 474
 		try {
475
-			$order = wc_get_order( $order_id );
475
+			$order = wc_get_order($order_id);
476 476
 
477 477
 			// This comes from the create account checkbox in the checkout page.
478
-			$create_account = ! empty( $_POST['createaccount'] ) ? true : false;
478
+			$create_account = ! empty($_POST['createaccount']) ? true : false;
479 479
 
480
-			if ( $create_account ) {
480
+			if ($create_account) {
481 481
 				$new_customer_id     = WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id();
482
-				$new_stripe_customer = new WC_Stripe_Customer( $new_customer_id );
482
+				$new_stripe_customer = new WC_Stripe_Customer($new_customer_id);
483 483
 				$new_stripe_customer->create_customer();
484 484
 			}
485 485
 
486 486
 			$source_object   = $this->get_source_object();
487
-			$prepared_source = $this->prepare_source( $source_object, get_current_user_id(), $force_save_source );
487
+			$prepared_source = $this->prepare_source($source_object, get_current_user_id(), $force_save_source);
488 488
 
489 489
 			// Check if we don't allow prepaid credit cards.
490
-			if ( ! apply_filters( 'wc_stripe_allow_prepaid_card', true ) ) {
491
-				if ( $source_object && 'token' === $source_object->object && 'prepaid' === $source_object->card->funding ) {
492
-					$localized_message = __( 'Sorry, we\'re not accepting prepaid cards at this time. Your credit card has not been charge. Please try with alternative payment method.', 'woocommerce-gateway-stripe' );
493
-					throw new WC_Stripe_Exception( print_r( $source_object, true ), $localized_message );
490
+			if ( ! apply_filters('wc_stripe_allow_prepaid_card', true)) {
491
+				if ($source_object && 'token' === $source_object->object && 'prepaid' === $source_object->card->funding) {
492
+					$localized_message = __('Sorry, we\'re not accepting prepaid cards at this time. Your credit card has not been charge. Please try with alternative payment method.', 'woocommerce-gateway-stripe');
493
+					throw new WC_Stripe_Exception(print_r($source_object, true), $localized_message);
494 494
 				}
495 495
 			}
496 496
 
497
-			if ( empty( $prepared_source->source ) ) {
498
-				$localized_message = __( 'Payment processing failed. Please retry.', 'woocommerce-gateway-stripe' );
499
-				throw new WC_Stripe_Exception( print_r( $prepared_source, true ), $localized_message );
497
+			if (empty($prepared_source->source)) {
498
+				$localized_message = __('Payment processing failed. Please retry.', 'woocommerce-gateway-stripe');
499
+				throw new WC_Stripe_Exception(print_r($prepared_source, true), $localized_message);
500 500
 			}
501 501
 
502
-			$this->save_source_to_order( $order, $prepared_source );
502
+			$this->save_source_to_order($order, $prepared_source);
503 503
 
504 504
 			// Result from Stripe API request.
505 505
 			$response = null;
506 506
 
507
-			if ( $order->get_total() > 0 ) {
507
+			if ($order->get_total() > 0) {
508 508
 				// This will throw exception if not valid.
509
-				$this->validate_minimum_order_amount( $order );
509
+				$this->validate_minimum_order_amount($order);
510 510
 
511 511
 				/*
512 512
 				 * Check if card 3DS is required or optional with 3DS setting.
@@ -515,109 +515,109 @@  discard block
 block discarded – undo
515 515
 				 * Note that if we need to save source, the original source must be first
516 516
 				 * attached to a customer in Stripe before it can be charged.
517 517
 				 */
518
-				if ( $this->is_3ds_required( $source_object ) ) {
519
-					$response = $this->create_3ds_source( $order, $source_object );
518
+				if ($this->is_3ds_required($source_object)) {
519
+					$response = $this->create_3ds_source($order, $source_object);
520 520
 
521
-					if ( ! empty( $response->error ) ) {
521
+					if ( ! empty($response->error)) {
522 522
 						$localized_message = $response->error->message;
523 523
 
524
-						$order->add_order_note( $localized_message );
524
+						$order->add_order_note($localized_message);
525 525
 
526
-						throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message );
526
+						throw new WC_Stripe_Exception(print_r($response, true), $localized_message);
527 527
 					}
528 528
 
529 529
 					// Update order meta with 3DS source.
530
-					if ( WC_Stripe_Helper::is_pre_30() ) {
531
-						update_post_meta( $order_id, '_stripe_source_id', $response->id );
530
+					if (WC_Stripe_Helper::is_pre_30()) {
531
+						update_post_meta($order_id, '_stripe_source_id', $response->id);
532 532
 					} else {
533
-						$order->update_meta_data( '_stripe_source_id', $response->id );
533
+						$order->update_meta_data('_stripe_source_id', $response->id);
534 534
 						$order->save();
535 535
 					}
536 536
 
537
-					WC_Stripe_Logger::log( 'Info: Redirecting to 3DS...' );
537
+					WC_Stripe_Logger::log('Info: Redirecting to 3DS...');
538 538
 
539 539
 					return array(
540 540
 						'result'   => 'success',
541
-						'redirect' => esc_url_raw( $response->redirect->url ),
541
+						'redirect' => esc_url_raw($response->redirect->url),
542 542
 					);
543 543
 				}
544 544
 
545
-				WC_Stripe_Logger::log( "Info: Begin processing payment for order $order_id for the amount of {$order->get_total()}" );
545
+				WC_Stripe_Logger::log("Info: Begin processing payment for order $order_id for the amount of {$order->get_total()}");
546 546
 
547 547
 				// Make the request.
548
-				$response = WC_Stripe_API::request( $this->generate_payment_request( $order, $prepared_source ) );
548
+				$response = WC_Stripe_API::request($this->generate_payment_request($order, $prepared_source));
549 549
 
550
-				if ( ! empty( $response->error ) ) {
550
+				if ( ! empty($response->error)) {
551 551
 					// If it is an API error such connection or server, let's retry.
552
-					if ( 'api_connection_error' === $response->error->type || 'api_error' === $response->error->type ) {
553
-						if ( $retry ) {
554
-							sleep( 5 );
555
-							return $this->process_payment( $order_id, false, $force_save_source );
552
+					if ('api_connection_error' === $response->error->type || 'api_error' === $response->error->type) {
553
+						if ($retry) {
554
+							sleep(5);
555
+							return $this->process_payment($order_id, false, $force_save_source);
556 556
 						} else {
557 557
 							$localized_message = 'API connection error and retries exhausted.';
558
-							$order->add_order_note( $localized_message );
559
-							throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message );
558
+							$order->add_order_note($localized_message);
559
+							throw new WC_Stripe_Exception(print_r($response, true), $localized_message);
560 560
 						}
561 561
 					}
562 562
 
563 563
 					// We want to retry.
564
-					if ( $this->is_retryable_error( $response->error ) ) {
565
-						if ( $retry ) {
564
+					if ($this->is_retryable_error($response->error)) {
565
+						if ($retry) {
566 566
 							// Don't do anymore retries after this.
567
-							if ( 5 <= $this->retry_interval ) {
567
+							if (5 <= $this->retry_interval) {
568 568
 
569
-								return $this->process_payment( $order_id, false, $force_save_source );
569
+								return $this->process_payment($order_id, false, $force_save_source);
570 570
 							}
571 571
 
572
-							sleep( $this->retry_interval );
572
+							sleep($this->retry_interval);
573 573
 
574 574
 							$this->retry_interval++;
575
-							return $this->process_payment( $order_id, true, $force_save_source );
575
+							return $this->process_payment($order_id, true, $force_save_source);
576 576
 						} else {
577
-							$localized_message = __( 'On going requests error and retries exhausted.', 'woocommerce-gateway-stripe' );
578
-							$order->add_order_note( $localized_message );
579
-							throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message );
577
+							$localized_message = __('On going requests error and retries exhausted.', 'woocommerce-gateway-stripe');
578
+							$order->add_order_note($localized_message);
579
+							throw new WC_Stripe_Exception(print_r($response, true), $localized_message);
580 580
 						}
581 581
 					}
582 582
 
583 583
 					// Customer param wrong? The user may have been deleted on stripe's end. Remove customer_id. Can be retried without.
584
-					if ( preg_match( '/No such customer/i', $response->error->message ) && $retry ) {
585
-						if ( WC_Stripe_Helper::is_pre_30() ) {
586
-							delete_user_meta( $order->customer_user, '_stripe_customer_id' );
587
-							delete_post_meta( $order_id, '_stripe_customer_id' );
584
+					if (preg_match('/No such customer/i', $response->error->message) && $retry) {
585
+						if (WC_Stripe_Helper::is_pre_30()) {
586
+							delete_user_meta($order->customer_user, '_stripe_customer_id');
587
+							delete_post_meta($order_id, '_stripe_customer_id');
588 588
 						} else {
589
-							delete_user_meta( $order->get_customer_id(), '_stripe_customer_id' );
590
-							$order->delete_meta_data( '_stripe_customer_id' );
589
+							delete_user_meta($order->get_customer_id(), '_stripe_customer_id');
590
+							$order->delete_meta_data('_stripe_customer_id');
591 591
 							$order->save();
592 592
 						}
593 593
 
594
-						return $this->process_payment( $order_id, false, $force_save_source );
595
-					} elseif ( preg_match( '/No such token/i', $response->error->message ) && $prepared_source->token_id ) {
594
+						return $this->process_payment($order_id, false, $force_save_source);
595
+					} elseif (preg_match('/No such token/i', $response->error->message) && $prepared_source->token_id) {
596 596
 						// Source param wrong? The CARD may have been deleted on stripe's end. Remove token and show message.
597
-						$wc_token = WC_Payment_Tokens::get( $prepared_source->token_id );
597
+						$wc_token = WC_Payment_Tokens::get($prepared_source->token_id);
598 598
 						$wc_token->delete();
599
-						$localized_message = __( 'This card is no longer available and has been removed.', 'woocommerce-gateway-stripe' );
600
-						$order->add_order_note( $localized_message );
601
-						throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message );
599
+						$localized_message = __('This card is no longer available and has been removed.', 'woocommerce-gateway-stripe');
600
+						$order->add_order_note($localized_message);
601
+						throw new WC_Stripe_Exception(print_r($response, true), $localized_message);
602 602
 					}
603 603
 
604 604
 					$localized_messages = WC_Stripe_Helper::get_localized_messages();
605 605
 
606
-					if ( 'card_error' === $response->error->type ) {
607
-						$localized_message = isset( $localized_messages[ $response->error->code ] ) ? $localized_messages[ $response->error->code ] : $response->error->message;
606
+					if ('card_error' === $response->error->type) {
607
+						$localized_message = isset($localized_messages[$response->error->code]) ? $localized_messages[$response->error->code] : $response->error->message;
608 608
 					} else {
609
-						$localized_message = isset( $localized_messages[ $response->error->type ] ) ? $localized_messages[ $response->error->type ] : $response->error->message;
609
+						$localized_message = isset($localized_messages[$response->error->type]) ? $localized_messages[$response->error->type] : $response->error->message;
610 610
 					}
611 611
 
612
-					$order->add_order_note( $localized_message );
612
+					$order->add_order_note($localized_message);
613 613
 
614
-					throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message );
614
+					throw new WC_Stripe_Exception(print_r($response, true), $localized_message);
615 615
 				}
616 616
 
617
-				do_action( 'wc_gateway_stripe_process_payment', $response, $order );
617
+				do_action('wc_gateway_stripe_process_payment', $response, $order);
618 618
 
619 619
 				// Process valid response.
620
-				$this->process_response( $response, $order );
620
+				$this->process_response($response, $order);
621 621
 			} else {
622 622
 				$order->payment_complete();
623 623
 			}
@@ -628,17 +628,17 @@  discard block
 block discarded – undo
628 628
 			// Return thank you page redirect.
629 629
 			return array(
630 630
 				'result'   => 'success',
631
-				'redirect' => $this->get_return_url( $order ),
631
+				'redirect' => $this->get_return_url($order),
632 632
 			);
633 633
 
634
-		} catch ( WC_Stripe_Exception $e ) {
635
-			wc_add_notice( $e->getLocalizedMessage(), 'error' );
636
-			WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() );
634
+		} catch (WC_Stripe_Exception $e) {
635
+			wc_add_notice($e->getLocalizedMessage(), 'error');
636
+			WC_Stripe_Logger::log('Error: ' . $e->getMessage());
637 637
 
638
-			do_action( 'wc_gateway_stripe_process_payment_error', $e, $order );
638
+			do_action('wc_gateway_stripe_process_payment_error', $e, $order);
639 639
 
640
-			if ( $order->has_status( array( 'pending', 'failed' ) ) ) {
641
-				$this->send_failed_order_email( $order_id );
640
+			if ($order->has_status(array('pending', 'failed'))) {
641
+				$this->send_failed_order_email($order_id);
642 642
 			}
643 643
 
644 644
 			return array(
Please login to merge, or discard this patch.
includes/deprecated/class-wc-stripe-apple-pay.php 1 patch
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -1,12 +1,12 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) {
2
+if ( ! defined('ABSPATH')) {
3 3
 	exit;
4 4
 }
5 5
 
6 6
 /**
7 7
  * DEPRECATED DO NOT USE!!
8 8
  */
9
-if ( ! class_exists( 'WC_Stripe_Apple_Pay' ) ) {
9
+if ( ! class_exists('WC_Stripe_Apple_Pay')) {
10 10
 	class WC_Stripe_Apple_Pay {
11 11
 		/**
12 12
 		 * This Instance.
@@ -20,15 +20,15 @@  discard block
 block discarded – undo
20 20
 		}
21 21
 
22 22
 		public static function instance() {
23
-			WC_Stripe_Logger::log( 'DEPRECATED! WC_Stripe_Apple_Pay class has been hard deprecated. Please remove any code that references this class or instance. This class will be removed by version 5.0' );
23
+			WC_Stripe_Logger::log('DEPRECATED! WC_Stripe_Apple_Pay class has been hard deprecated. Please remove any code that references this class or instance. This class will be removed by version 5.0');
24 24
 			return self::$_this;
25 25
 		}
26 26
 
27
-		public function __get( $var ) {
27
+		public function __get($var) {
28 28
 			return null;
29 29
 		}
30 30
 
31
-		public function __call( $name, $arguments ) {
31
+		public function __call($name, $arguments) {
32 32
 			return null;
33 33
 		}
34 34
 	}
Please login to merge, or discard this patch.