Completed
Push — master ( b3f03c...7c87e6 )
by Roy
06:09
created
includes/class-wc-gateway-stripe.php 1 patch
Spacing   +261 added lines, -261 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
 
@@ -120,9 +120,9 @@  discard block
 block discarded – undo
120 120
 	public function __construct() {
121 121
 		$this->retry_interval       = 1;
122 122
 		$this->id                   = 'stripe';
123
-		$this->method_title         = __( 'Stripe', 'woocommerce-gateway-stripe' );
123
+		$this->method_title         = __('Stripe', 'woocommerce-gateway-stripe');
124 124
 		/* translators: 1) link to Stripe register page 2) link to Stripe api keys page */
125
-		$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
+		$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');
126 126
 		$this->has_fields           = true;
127 127
 		$this->supports             = array(
128 128
 			'products',
@@ -149,43 +149,43 @@  discard block
 block discarded – undo
149 149
 		$this->init_settings();
150 150
 
151 151
 		// Get setting values.
152
-		$this->title                       = $this->get_option( 'title' );
153
-		$this->description                 = $this->get_option( 'description' );
154
-		$this->enabled                     = $this->get_option( 'enabled' );
155
-		$this->testmode                    = 'yes' === $this->get_option( 'testmode' );
156
-		$this->inline_cc_form              = 'yes' === $this->get_option( 'inline_cc_form' );
157
-		$this->capture                     = 'yes' === $this->get_option( 'capture', 'yes' );
158
-		$this->statement_descriptor        = WC_Stripe_Helper::clean_statement_descriptor( $this->get_option( 'statement_descriptor' ) );
159
-		$this->three_d_secure              = 'yes' === $this->get_option( 'three_d_secure' );
160
-		$this->stripe_checkout             = 'yes' === $this->get_option( 'stripe_checkout' );
161
-		$this->stripe_checkout_image       = $this->get_option( 'stripe_checkout_image', '' );
162
-		$this->stripe_checkout_description = $this->get_option( 'stripe_checkout_description' );
163
-		$this->saved_cards                 = 'yes' === $this->get_option( 'saved_cards' );
164
-		$this->secret_key                  = $this->testmode ? $this->get_option( 'test_secret_key' ) : $this->get_option( 'secret_key' );
165
-		$this->publishable_key             = $this->testmode ? $this->get_option( 'test_publishable_key' ) : $this->get_option( 'publishable_key' );
166
-		$this->bitcoin                     = 'USD' === strtoupper( get_woocommerce_currency() ) && 'yes' === $this->get_option( 'stripe_bitcoin' );
167
-		$this->payment_request             = 'yes' === $this->get_option( 'payment_request', 'yes' );
168
-
169
-		if ( $this->stripe_checkout ) {
170
-			$this->order_button_text = __( 'Continue to payment', 'woocommerce-gateway-stripe' );
171
-		}
172
-
173
-		WC_Stripe_API::set_secret_key( $this->secret_key );
152
+		$this->title                       = $this->get_option('title');
153
+		$this->description                 = $this->get_option('description');
154
+		$this->enabled                     = $this->get_option('enabled');
155
+		$this->testmode                    = 'yes' === $this->get_option('testmode');
156
+		$this->inline_cc_form              = 'yes' === $this->get_option('inline_cc_form');
157
+		$this->capture                     = 'yes' === $this->get_option('capture', 'yes');
158
+		$this->statement_descriptor        = WC_Stripe_Helper::clean_statement_descriptor($this->get_option('statement_descriptor'));
159
+		$this->three_d_secure              = 'yes' === $this->get_option('three_d_secure');
160
+		$this->stripe_checkout             = 'yes' === $this->get_option('stripe_checkout');
161
+		$this->stripe_checkout_image       = $this->get_option('stripe_checkout_image', '');
162
+		$this->stripe_checkout_description = $this->get_option('stripe_checkout_description');
163
+		$this->saved_cards                 = 'yes' === $this->get_option('saved_cards');
164
+		$this->secret_key                  = $this->testmode ? $this->get_option('test_secret_key') : $this->get_option('secret_key');
165
+		$this->publishable_key             = $this->testmode ? $this->get_option('test_publishable_key') : $this->get_option('publishable_key');
166
+		$this->bitcoin                     = 'USD' === strtoupper(get_woocommerce_currency()) && 'yes' === $this->get_option('stripe_bitcoin');
167
+		$this->payment_request             = 'yes' === $this->get_option('payment_request', 'yes');
168
+
169
+		if ($this->stripe_checkout) {
170
+			$this->order_button_text = __('Continue to payment', 'woocommerce-gateway-stripe');
171
+		}
172
+
173
+		WC_Stripe_API::set_secret_key($this->secret_key);
174 174
 
175 175
 		// Hooks.
176
-		add_action( 'wp_enqueue_scripts', array( $this, 'payment_scripts' ) );
177
-		add_action( 'admin_enqueue_scripts', array( $this, 'admin_scripts' ) );
178
-		add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) );
179
-		add_action( 'woocommerce_admin_order_totals_after_total', array( $this, 'display_order_fee' ), 10, 1 );
180
-		add_action( 'woocommerce_admin_order_totals_after_total', array( $this, 'display_order_payout' ), 20, 1 );
181
-		add_action( 'woocommerce_customer_save_address', array( $this, 'show_update_card_notice' ), 10, 2 );
182
-		add_action( 'woocommerce_receipt_stripe', array( $this, 'stripe_checkout_receipt_page' ) );
183
-		add_action( 'woocommerce_api_' . strtolower( get_class( $this ) ), array( $this, 'stripe_checkout_return_handler' ) );
184
-
185
-		if ( WC_Stripe_Helper::is_pre_orders_exists() ) {
176
+		add_action('wp_enqueue_scripts', array($this, 'payment_scripts'));
177
+		add_action('admin_enqueue_scripts', array($this, 'admin_scripts'));
178
+		add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options'));
179
+		add_action('woocommerce_admin_order_totals_after_total', array($this, 'display_order_fee'), 10, 1);
180
+		add_action('woocommerce_admin_order_totals_after_total', array($this, 'display_order_payout'), 20, 1);
181
+		add_action('woocommerce_customer_save_address', array($this, 'show_update_card_notice'), 10, 2);
182
+		add_action('woocommerce_receipt_stripe', array($this, 'stripe_checkout_receipt_page'));
183
+		add_action('woocommerce_api_' . strtolower(get_class($this)), array($this, 'stripe_checkout_return_handler'));
184
+
185
+		if (WC_Stripe_Helper::is_pre_orders_exists()) {
186 186
 			$this->pre_orders = new WC_Stripe_Pre_Orders_Compat();
187 187
 
188
-			add_action( 'wc_pre_orders_process_pre_order_completion_payment_' . $this->id, array( $this->pre_orders, 'process_pre_order_release_payment' ) );
188
+			add_action('wc_pre_orders_process_pre_order_completion_payment_' . $this->id, array($this->pre_orders, 'process_pre_order_release_payment'));
189 189
 		}
190 190
 	}
191 191
 
@@ -196,7 +196,7 @@  discard block
 block discarded – undo
196 196
 	 * @return bool
197 197
 	 */
198 198
 	public function are_keys_set() {
199
-		if ( empty( $this->secret_key ) || empty( $this->publishable_key ) ) {
199
+		if (empty($this->secret_key) || empty($this->publishable_key)) {
200 200
 			return false;
201 201
 		}
202 202
 
@@ -209,7 +209,7 @@  discard block
 block discarded – undo
209 209
 	 * @since 4.0.2
210 210
 	 */
211 211
 	public function is_available() {
212
-		if ( is_add_payment_method_page() && ! $this->saved_cards ) {
212
+		if (is_add_payment_method_page() && ! $this->saved_cards) {
213 213
 			return false;
214 214
 		}
215 215
 
@@ -223,13 +223,13 @@  discard block
 block discarded – undo
223 223
 	 * @param int $user_id
224 224
 	 * @param array $load_address
225 225
 	 */
226
-	public function show_update_card_notice( $user_id, $load_address ) {
227
-		if ( ! $this->saved_cards || ! WC_Stripe_Payment_Tokens::customer_has_saved_methods( $user_id ) || 'billing' !== $load_address ) {
226
+	public function show_update_card_notice($user_id, $load_address) {
227
+		if ( ! $this->saved_cards || ! WC_Stripe_Payment_Tokens::customer_has_saved_methods($user_id) || 'billing' !== $load_address) {
228 228
 			return;
229 229
 		}
230 230
 
231 231
 		/* translators: 1) Opening anchor tag 2) closing anchor tag */
232
-		wc_add_notice( sprintf( __( 'If your billing address has been changed for saved payment methods, be sure to remove any %1$ssaved payment methods%2$s on file and re-add them.', 'woocommerce-gateway-stripe' ), '<a href="' . esc_url( wc_get_endpoint_url( 'payment-methods' ) ) . '" class="wc-stripe-update-card-notice" style="text-decoration:underline;">', '</a>' ), 'notice' );
232
+		wc_add_notice(sprintf(__('If your billing address has been changed for saved payment methods, be sure to remove any %1$ssaved payment methods%2$s on file and re-add them.', 'woocommerce-gateway-stripe'), '<a href="' . esc_url(wc_get_endpoint_url('payment-methods')) . '" class="wc-stripe-update-card-notice" style="text-decoration:underline;">', '</a>'), 'notice');
233 233
 	}
234 234
 
235 235
 	/**
@@ -248,24 +248,24 @@  discard block
 block discarded – undo
248 248
 		$icons_str .= $icons['amex'];
249 249
 		$icons_str .= $icons['mastercard'];
250 250
 
251
-		if ( 'USD' === get_woocommerce_currency() ) {
251
+		if ('USD' === get_woocommerce_currency()) {
252 252
 			$icons_str .= $icons['discover'];
253 253
 			$icons_str .= $icons['jcb'];
254 254
 			$icons_str .= $icons['diners'];
255 255
 		}
256 256
 
257
-		if ( $this->bitcoin && $this->stripe_checkout ) {
257
+		if ($this->bitcoin && $this->stripe_checkout) {
258 258
 			$icons_str .= $icons['bitcoin'];
259 259
 		}
260 260
 
261
-		return apply_filters( 'woocommerce_gateway_icon', $icons_str, $this->id );
261
+		return apply_filters('woocommerce_gateway_icon', $icons_str, $this->id);
262 262
 	}
263 263
 
264 264
 	/**
265 265
 	 * Initialise Gateway Settings Form Fields
266 266
 	 */
267 267
 	public function init_form_fields() {
268
-		$this->form_fields = require( dirname( __FILE__ ) . '/admin/stripe-settings.php' );
268
+		$this->form_fields = require(dirname(__FILE__) . '/admin/stripe-settings.php');
269 269
 	}
270 270
 
271 271
 	/**
@@ -273,27 +273,27 @@  discard block
 block discarded – undo
273 273
 	 */
274 274
 	public function payment_fields() {
275 275
 		$user                 = wp_get_current_user();
276
-		$display_tokenization = $this->supports( 'tokenization' ) && is_checkout() && $this->saved_cards;
276
+		$display_tokenization = $this->supports('tokenization') && is_checkout() && $this->saved_cards;
277 277
 		$total                = WC()->cart->total;
278 278
 		$user_email           = '';
279 279
 
280 280
 		// If paying from order, we need to get total from order not cart.
281
-		if ( isset( $_GET['pay_for_order'] ) && ! empty( $_GET['key'] ) ) {
282
-			$order      = wc_get_order( wc_get_order_id_by_order_key( wc_clean( $_GET['key'] ) ) );
281
+		if (isset($_GET['pay_for_order']) && ! empty($_GET['key'])) {
282
+			$order      = wc_get_order(wc_get_order_id_by_order_key(wc_clean($_GET['key'])));
283 283
 			$total      = $order->get_total();
284 284
 			$user_email = WC_Stripe_Helper::is_pre_30() ? $order->billing_email : $order->get_billing_email();
285 285
 		} else {
286
-			if ( $user->ID ) {
287
-				$user_email = get_user_meta( $user->ID, 'billing_email', true );
286
+			if ($user->ID) {
287
+				$user_email = get_user_meta($user->ID, 'billing_email', true);
288 288
 				$user_email = $user_email ? $user_email : $user->user_email;
289 289
 			}
290 290
 		}
291 291
 
292
-		if ( is_add_payment_method_page() ) {
293
-			$pay_button_text = __( 'Add Card', 'woocommerce-gateway-stripe' );
292
+		if (is_add_payment_method_page()) {
293
+			$pay_button_text = __('Add Card', 'woocommerce-gateway-stripe');
294 294
 			$total        = '';
295
-		} elseif ( function_exists( 'wcs_order_contains_subscription' ) && isset( $_GET['change_payment_method'] ) ) {
296
-			$pay_button_text = __( 'Change Payment Method', 'woocommerce-gateway-stripe' );
295
+		} elseif (function_exists('wcs_order_contains_subscription') && isset($_GET['change_payment_method'])) {
296
+			$pay_button_text = __('Change Payment Method', 'woocommerce-gateway-stripe');
297 297
 			$total        = '';
298 298
 		} else {
299 299
 			$pay_button_text = '';
@@ -303,45 +303,45 @@  discard block
 block discarded – undo
303 303
 
304 304
 		echo '<div
305 305
 			id="stripe-payment-data"
306
-			data-panel-label="' . esc_attr( $pay_button_text ) . '"
307
-			data-description="' . esc_attr( strip_tags( $this->stripe_checkout_description ) ) . '"
308
-			data-email="' . esc_attr( $user_email ) . '"
309
-			data-verify-zip="' . esc_attr( apply_filters( 'wc_stripe_checkout_verify_zip', false ) ? 'true' : 'false' ) . '"
310
-			data-billing-address="' . esc_attr( apply_filters( 'wc_stripe_checkout_require_billing_address', false ) ? 'true' : 'false' ) . '"
311
-			data-shipping-address="' . esc_attr( apply_filters( 'wc_stripe_checkout_require_shipping_address', false ) ? 'true' : 'false' ) . '" 
312
-			data-amount="' . esc_attr( WC_Stripe_Helper::get_stripe_amount( $total ) ) . '"
313
-			data-name="' . esc_attr( $this->statement_descriptor ) . '"
314
-			data-currency="' . esc_attr( strtolower( get_woocommerce_currency() ) ) . '"
315
-			data-image="' . esc_attr( $this->stripe_checkout_image ) . '"
316
-			data-bitcoin="' . esc_attr( ( $this->bitcoin && $this->capture ) ? 'true' : 'false' ) . '"
317
-			data-locale="' . esc_attr( apply_filters( 'wc_stripe_checkout_locale', $this->get_locale() ) ) . '"
318
-			data-three-d-secure="' . esc_attr( $this->three_d_secure ? 'true' : 'false' ) . '"
319
-			data-allow-remember-me="' . esc_attr( apply_filters( 'wc_stripe_allow_remember_me', true ) ? 'true' : 'false' ) . '">';
320
-
321
-		if ( $this->description ) {
322
-			if ( $this->testmode ) {
306
+			data-panel-label="' . esc_attr($pay_button_text) . '"
307
+			data-description="' . esc_attr(strip_tags($this->stripe_checkout_description)) . '"
308
+			data-email="' . esc_attr($user_email) . '"
309
+			data-verify-zip="' . esc_attr(apply_filters('wc_stripe_checkout_verify_zip', false) ? 'true' : 'false') . '"
310
+			data-billing-address="' . esc_attr(apply_filters('wc_stripe_checkout_require_billing_address', false) ? 'true' : 'false') . '"
311
+			data-shipping-address="' . esc_attr(apply_filters('wc_stripe_checkout_require_shipping_address', false) ? 'true' : 'false') . '" 
312
+			data-amount="' . esc_attr(WC_Stripe_Helper::get_stripe_amount($total)) . '"
313
+			data-name="' . esc_attr($this->statement_descriptor) . '"
314
+			data-currency="' . esc_attr(strtolower(get_woocommerce_currency())) . '"
315
+			data-image="' . esc_attr($this->stripe_checkout_image) . '"
316
+			data-bitcoin="' . esc_attr(($this->bitcoin && $this->capture) ? 'true' : 'false') . '"
317
+			data-locale="' . esc_attr(apply_filters('wc_stripe_checkout_locale', $this->get_locale())) . '"
318
+			data-three-d-secure="' . esc_attr($this->three_d_secure ? 'true' : 'false') . '"
319
+			data-allow-remember-me="' . esc_attr(apply_filters('wc_stripe_allow_remember_me', true) ? 'true' : 'false') . '">';
320
+
321
+		if ($this->description) {
322
+			if ($this->testmode) {
323 323
 				/* translators: link to Stripe testing page */
324
-				$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 <a href="%s" target="_blank">Testing Stripe documentation</a> for more card numbers.', 'woocommerce-gateway-stripe' ), 'https://stripe.com/docs/testing' );
325
-				$this->description  = trim( $this->description );
324
+				$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 <a href="%s" target="_blank">Testing Stripe documentation</a> for more card numbers.', 'woocommerce-gateway-stripe'), 'https://stripe.com/docs/testing');
325
+				$this->description  = trim($this->description);
326 326
 			}
327 327
 
328
-			echo apply_filters( 'wc_stripe_description', wpautop( wp_kses_post( $this->description ) ), $this->id );
328
+			echo apply_filters('wc_stripe_description', wpautop(wp_kses_post($this->description)), $this->id);
329 329
 		}
330 330
 
331
-		if ( $display_tokenization ) {
331
+		if ($display_tokenization) {
332 332
 			$this->tokenization_script();
333 333
 			$this->saved_payment_methods();
334 334
 		}
335 335
 
336
-		if ( ! $this->stripe_checkout ) {
336
+		if ( ! $this->stripe_checkout) {
337 337
 			$this->elements_form();
338 338
 		}
339 339
 
340
-		if ( apply_filters( 'wc_stripe_display_save_payment_method_checkbox', $display_tokenization ) && ! is_add_payment_method_page() && ! isset( $_GET['change_payment_method'] ) ) {
340
+		if (apply_filters('wc_stripe_display_save_payment_method_checkbox', $display_tokenization) && ! is_add_payment_method_page() && ! isset($_GET['change_payment_method'])) {
341 341
 
342
-			if ( ! $this->stripe_checkout ) {
342
+			if ( ! $this->stripe_checkout) {
343 343
 				$this->save_payment_method_checkbox();
344
-			} elseif ( $this->stripe_checkout && isset( $_GET['pay_for_order'] ) && ! empty( $_GET['key'] ) ) {
344
+			} elseif ($this->stripe_checkout && isset($_GET['pay_for_order']) && ! empty($_GET['key'])) {
345 345
 				$this->save_payment_method_checkbox();
346 346
 			}
347 347
 		}
@@ -359,12 +359,12 @@  discard block
 block discarded – undo
359 359
 	 */
360 360
 	public function elements_form() {
361 361
 		?>
362
-		<fieldset id="wc-<?php echo esc_attr( $this->id ); ?>-cc-form" class="wc-credit-card-form wc-payment-form" style="background:transparent;">
363
-			<?php do_action( 'woocommerce_credit_card_form_start', $this->id ); ?>
362
+		<fieldset id="wc-<?php echo esc_attr($this->id); ?>-cc-form" class="wc-credit-card-form wc-payment-form" style="background:transparent;">
363
+			<?php do_action('woocommerce_credit_card_form_start', $this->id); ?>
364 364
 
365
-			<?php if ( $this->inline_cc_form ) { ?>
365
+			<?php if ($this->inline_cc_form) { ?>
366 366
 				<label for="card-element">
367
-					<?php esc_html_e( 'Credit or debit card', 'woocommerce-gateway-stripe' ); ?>
367
+					<?php esc_html_e('Credit or debit card', 'woocommerce-gateway-stripe'); ?>
368 368
 				</label>
369 369
 
370 370
 				<div id="stripe-card-element" style="background:#fff;padding:0 1em;border:1px solid #ddd;margin:5px 0;padding:10px 5px;">
@@ -372,7 +372,7 @@  discard block
 block discarded – undo
372 372
 				</div>
373 373
 			<?php } else { ?>
374 374
 				<div class="form-row form-row-wide">
375
-					<label><?php _e( 'Card Number', 'woocommerce-gateway-stripe' ); ?> <span class="required">*</span></label>
375
+					<label><?php _e('Card Number', 'woocommerce-gateway-stripe'); ?> <span class="required">*</span></label>
376 376
 
377 377
 					<div id="stripe-card-element" style="background:#fff;padding:0 1em;border:1px solid #ddd;margin:5px 0;padding:10px 5px;">
378 378
 					<!-- a Stripe Element will be inserted here. -->
@@ -380,7 +380,7 @@  discard block
 block discarded – undo
380 380
 				</div>
381 381
 
382 382
 				<div class="form-row form-row-first">
383
-					<label><?php _e( 'Expiry Date', 'woocommerce-gateway-stripe' ); ?> <span class="required">*</span></label>
383
+					<label><?php _e('Expiry Date', 'woocommerce-gateway-stripe'); ?> <span class="required">*</span></label>
384 384
 
385 385
 					<div id="stripe-exp-element" style="background:#fff;padding:0 1em;border:1px solid #ddd;margin:5px 0;padding:10px 5px;">
386 386
 					<!-- a Stripe Element will be inserted here. -->
@@ -388,7 +388,7 @@  discard block
 block discarded – undo
388 388
 				</div>
389 389
 
390 390
 				<div class="form-row form-row-last">
391
-					<label><?php _e( 'Card Code (CVC)', 'woocommerce-gateway-stripe' ); ?> <span class="required">*</span></label>
391
+					<label><?php _e('Card Code (CVC)', 'woocommerce-gateway-stripe'); ?> <span class="required">*</span></label>
392 392
 				<div id="stripe-cvc-element" style="background:#fff;padding:0 1em;border:1px solid #ddd;margin:5px 0;padding:10px 5px;">
393 393
 				<!-- a Stripe Element will be inserted here. -->
394 394
 				</div>
@@ -398,7 +398,7 @@  discard block
 block discarded – undo
398 398
 
399 399
 			<!-- Used to display form errors -->
400 400
 			<div class="stripe-source-errors" role="alert"></div>
401
-			<?php do_action( 'woocommerce_credit_card_form_end', $this->id ); ?>
401
+			<?php do_action('woocommerce_credit_card_form_end', $this->id); ?>
402 402
 			<div class="clear"></div>
403 403
 		</fieldset>
404 404
 		<?php
@@ -411,13 +411,13 @@  discard block
 block discarded – undo
411 411
 	 * @version 3.1.0
412 412
 	 */
413 413
 	public function admin_scripts() {
414
-		if ( 'woocommerce_page_wc-settings' !== get_current_screen()->id ) {
414
+		if ('woocommerce_page_wc-settings' !== get_current_screen()->id) {
415 415
 			return;
416 416
 		}
417 417
 
418
-		$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
418
+		$suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';
419 419
 
420
-		wp_enqueue_script( 'woocommerce_stripe_admin', plugins_url( 'assets/js/stripe-admin' . $suffix . '.js', WC_STRIPE_MAIN_FILE ), array(), WC_STRIPE_VERSION, true );
420
+		wp_enqueue_script('woocommerce_stripe_admin', plugins_url('assets/js/stripe-admin' . $suffix . '.js', WC_STRIPE_MAIN_FILE), array(), WC_STRIPE_VERSION, true);
421 421
 	}
422 422
 
423 423
 	/**
@@ -429,44 +429,44 @@  discard block
 block discarded – undo
429 429
 	 * @version 4.0.0
430 430
 	 */
431 431
 	public function payment_scripts() {
432
-		if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) && ! is_add_payment_method_page() && ! isset( $_GET['change_payment_method'] ) ) {
432
+		if ( ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order']) && ! is_add_payment_method_page() && ! isset($_GET['change_payment_method'])) {
433 433
 			return;
434 434
 		}
435 435
 
436 436
 		// If Stripe is not enabled bail.
437
-		if ( 'no' === $this->enabled ) {
437
+		if ('no' === $this->enabled) {
438 438
 			return;
439 439
 		}
440 440
 
441 441
 		// If keys are not set bail.
442
-		if ( ! $this->are_keys_set() ) {
443
-			WC_Stripe_Logger::log( 'Keys are not set correctly.' );
442
+		if ( ! $this->are_keys_set()) {
443
+			WC_Stripe_Logger::log('Keys are not set correctly.');
444 444
 			return;
445 445
 		}
446 446
 
447 447
 		// If no SSL bail.
448
-		if ( ! $this->testmode && ! is_ssl() ) {
449
-			WC_Stripe_Logger::log( 'Stripe live mode requires SSL.' );
448
+		if ( ! $this->testmode && ! is_ssl()) {
449
+			WC_Stripe_Logger::log('Stripe live mode requires SSL.');
450 450
 		}
451 451
 
452
-		$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
452
+		$suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';
453 453
 
454
-		wp_register_style( 'stripe_styles', plugins_url( 'assets/css/stripe-styles.css', WC_STRIPE_MAIN_FILE ), array(), WC_STRIPE_VERSION );
455
-		wp_enqueue_style( 'stripe_styles' );
456
-		wp_register_script( 'stripe_checkout', 'https://checkout.stripe.com/checkout.js', '', WC_STRIPE_VERSION, true );
457
-		wp_register_script( 'stripe', 'https://js.stripe.com/v3/', '', '3.0', true );
458
-		wp_register_script( 'woocommerce_stripe', plugins_url( 'assets/js/stripe' . $suffix . '.js', WC_STRIPE_MAIN_FILE ), array( 'jquery-payment', 'stripe' ), WC_STRIPE_VERSION, true );
454
+		wp_register_style('stripe_styles', plugins_url('assets/css/stripe-styles.css', WC_STRIPE_MAIN_FILE), array(), WC_STRIPE_VERSION);
455
+		wp_enqueue_style('stripe_styles');
456
+		wp_register_script('stripe_checkout', 'https://checkout.stripe.com/checkout.js', '', WC_STRIPE_VERSION, true);
457
+		wp_register_script('stripe', 'https://js.stripe.com/v3/', '', '3.0', true);
458
+		wp_register_script('woocommerce_stripe', plugins_url('assets/js/stripe' . $suffix . '.js', WC_STRIPE_MAIN_FILE), array('jquery-payment', 'stripe'), WC_STRIPE_VERSION, true);
459 459
 
460 460
 		$stripe_params = array(
461 461
 			'key'                  => $this->publishable_key,
462
-			'i18n_terms'           => __( 'Please accept the terms and conditions first', 'woocommerce-gateway-stripe' ),
463
-			'i18n_required_fields' => __( 'Please fill in required checkout fields first', 'woocommerce-gateway-stripe' ),
462
+			'i18n_terms'           => __('Please accept the terms and conditions first', 'woocommerce-gateway-stripe'),
463
+			'i18n_required_fields' => __('Please fill in required checkout fields first', 'woocommerce-gateway-stripe'),
464 464
 		);
465 465
 
466 466
 		// If we're on the pay page we need to pass stripe.js the address of the order.
467
-		if ( isset( $_GET['pay_for_order'] ) && 'true' === $_GET['pay_for_order'] ) {
468
-			$order_id = wc_get_order_id_by_order_key( urldecode( $_GET['key'] ) );
469
-			$order    = wc_get_order( $order_id );
467
+		if (isset($_GET['pay_for_order']) && 'true' === $_GET['pay_for_order']) {
468
+			$order_id = wc_get_order_id_by_order_key(urldecode($_GET['key']));
469
+			$order    = wc_get_order($order_id);
470 470
 
471 471
 			$stripe_params['billing_first_name'] = WC_Stripe_Helper::is_pre_30() ? $order->billing_first_name : $order->get_billing_first_name();
472 472
 			$stripe_params['billing_last_name']  = WC_Stripe_Helper::is_pre_30() ? $order->billing_last_name : $order->get_billing_last_name();
@@ -478,38 +478,38 @@  discard block
 block discarded – undo
478 478
 			$stripe_params['billing_country']    = WC_Stripe_Helper::is_pre_30() ? $order->billing_country : $order->get_billing_country();
479 479
 		}
480 480
 
481
-		$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' );
482
-		$stripe_params['no_sepa_owner_msg']                       = __( 'Please enter your IBAN account name.', 'woocommerce-gateway-stripe' );
483
-		$stripe_params['no_sepa_iban_msg']                        = __( 'Please enter your IBAN account number.', 'woocommerce-gateway-stripe' );
484
-		$stripe_params['sepa_mandate_notification']               = apply_filters( 'wc_stripe_sepa_mandate_notification', 'email' );
485
-		$stripe_params['allow_prepaid_card']                      = apply_filters( 'wc_stripe_allow_prepaid_card', true ) ? 'yes' : 'no';
481
+		$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');
482
+		$stripe_params['no_sepa_owner_msg']                       = __('Please enter your IBAN account name.', 'woocommerce-gateway-stripe');
483
+		$stripe_params['no_sepa_iban_msg']                        = __('Please enter your IBAN account number.', 'woocommerce-gateway-stripe');
484
+		$stripe_params['sepa_mandate_notification']               = apply_filters('wc_stripe_sepa_mandate_notification', 'email');
485
+		$stripe_params['allow_prepaid_card']                      = apply_filters('wc_stripe_allow_prepaid_card', true) ? 'yes' : 'no';
486 486
 		$stripe_params['inline_cc_form']                          = $this->inline_cc_form ? 'yes' : 'no';
487
-		$stripe_params['stripe_checkout_require_billing_address'] = apply_filters( 'wc_stripe_checkout_require_billing_address', false ) ? 'yes' : 'no';
488
-		$stripe_params['is_checkout']                             = ( is_checkout() && empty( $_GET['pay_for_order'] ) ) ? 'yes' : 'no';
487
+		$stripe_params['stripe_checkout_require_billing_address'] = apply_filters('wc_stripe_checkout_require_billing_address', false) ? 'yes' : 'no';
488
+		$stripe_params['is_checkout']                             = (is_checkout() && empty($_GET['pay_for_order'])) ? 'yes' : 'no';
489 489
 		$stripe_params['return_url']                              = $this->get_stripe_return_url();
490
-		$stripe_params['ajaxurl']                                 = WC_AJAX::get_endpoint( '%%endpoint%%' );
491
-		$stripe_params['stripe_nonce']                            = wp_create_nonce( '_wc_stripe_nonce' );
490
+		$stripe_params['ajaxurl']                                 = WC_AJAX::get_endpoint('%%endpoint%%');
491
+		$stripe_params['stripe_nonce']                            = wp_create_nonce('_wc_stripe_nonce');
492 492
 		$stripe_params['statement_descriptor']                    = $this->statement_descriptor;
493
-		$stripe_params['elements_options']                        = apply_filters( 'wc_stripe_elements_options', array() );
493
+		$stripe_params['elements_options']                        = apply_filters('wc_stripe_elements_options', array());
494 494
 		$stripe_params['is_stripe_checkout']                      = $this->stripe_checkout ? 'yes' : 'no';
495
-		$stripe_params['is_change_payment_page']                  = isset( $_GET['change_payment_method'] ) ? 'yes' : 'no';
496
-		$stripe_params['is_add_payment_page']                     = is_wc_endpoint_url( 'add-payment-method' ) ? 'yes' : 'no';
497
-		$stripe_params['is_pay_for_order_page']                   = is_wc_endpoint_url( 'order-pay' ) ? 'yes' : 'no';
498
-		$stripe_params['elements_styling']                        = apply_filters( 'wc_stripe_elements_styling', false );
499
-		$stripe_params['elements_classes']                        = apply_filters( 'wc_stripe_elements_classes', false );
495
+		$stripe_params['is_change_payment_page']                  = isset($_GET['change_payment_method']) ? 'yes' : 'no';
496
+		$stripe_params['is_add_payment_page']                     = is_wc_endpoint_url('add-payment-method') ? 'yes' : 'no';
497
+		$stripe_params['is_pay_for_order_page']                   = is_wc_endpoint_url('order-pay') ? 'yes' : 'no';
498
+		$stripe_params['elements_styling']                        = apply_filters('wc_stripe_elements_styling', false);
499
+		$stripe_params['elements_classes']                        = apply_filters('wc_stripe_elements_classes', false);
500 500
 
501 501
 		// merge localized messages to be use in JS
502
-		$stripe_params = array_merge( $stripe_params, WC_Stripe_Helper::get_localized_messages() );
502
+		$stripe_params = array_merge($stripe_params, WC_Stripe_Helper::get_localized_messages());
503 503
 
504
-		wp_localize_script( 'woocommerce_stripe', 'wc_stripe_params', apply_filters( 'wc_stripe_params', $stripe_params ) );
505
-		wp_localize_script( 'woocommerce_stripe_checkout', 'wc_stripe_params', apply_filters( 'wc_stripe_params', $stripe_params ) );
504
+		wp_localize_script('woocommerce_stripe', 'wc_stripe_params', apply_filters('wc_stripe_params', $stripe_params));
505
+		wp_localize_script('woocommerce_stripe_checkout', 'wc_stripe_params', apply_filters('wc_stripe_params', $stripe_params));
506 506
 
507
-		if ( $this->stripe_checkout ) {
508
-			wp_enqueue_script( 'stripe_checkout' );
507
+		if ($this->stripe_checkout) {
508
+			wp_enqueue_script('stripe_checkout');
509 509
 		}
510 510
 
511 511
 		$this->tokenization_script();
512
-		wp_enqueue_script( 'woocommerce_stripe' );
512
+		wp_enqueue_script('woocommerce_stripe');
513 513
 	}
514 514
 
515 515
 	/**
@@ -517,71 +517,71 @@  discard block
 block discarded – undo
517 517
 	 *
518 518
 	 * @since 4.1.0
519 519
 	 */
520
-	public function stripe_checkout_receipt_page( $order_id ) {
521
-		if ( ! $this->stripe_checkout ) {
520
+	public function stripe_checkout_receipt_page($order_id) {
521
+		if ( ! $this->stripe_checkout) {
522 522
 			return;
523 523
 		}
524 524
 
525 525
 		$user                 = wp_get_current_user();
526 526
 		$total                = WC()->cart->total;
527 527
 		$user_email           = '';
528
-		$display_tokenization = $this->supports( 'tokenization' ) && $this->saved_cards;
528
+		$display_tokenization = $this->supports('tokenization') && $this->saved_cards;
529 529
 
530 530
 		// If paying from order, we need to get total from order not cart.
531
-		if ( ! empty( $_GET['key'] ) ) {
532
-			$order      = wc_get_order( wc_get_order_id_by_order_key( wc_clean( $_GET['key'] ) ) );
531
+		if ( ! empty($_GET['key'])) {
532
+			$order      = wc_get_order(wc_get_order_id_by_order_key(wc_clean($_GET['key'])));
533 533
 			$total      = $order->get_total();
534 534
 			$user_email = WC_Stripe_Helper::is_pre_30() ? $order->billing_email : $order->get_billing_email();
535 535
 		} else {
536
-			if ( $user->ID ) {
537
-				$user_email = get_user_meta( $user->ID, 'billing_email', true );
536
+			if ($user->ID) {
537
+				$user_email = get_user_meta($user->ID, 'billing_email', true);
538 538
 				$user_email = $user_email ? $user_email : $user->user_email;
539 539
 			}
540 540
 		}
541 541
 
542 542
 		ob_start();
543 543
 
544
-		do_action( 'wc_stripe_checkout_receipt_page_before_form' );
544
+		do_action('wc_stripe_checkout_receipt_page_before_form');
545 545
 
546
-		echo '<form method="post" class="woocommerce-checkout" action="' . WC()->api_request_url( get_class( $this ) ) . '">';
546
+		echo '<form method="post" class="woocommerce-checkout" action="' . WC()->api_request_url(get_class($this)) . '">';
547 547
 		echo '<div
548 548
 			id="stripe-payment-data"
549
-			data-panel-label="' . esc_attr( apply_filters( 'wc_stripe_checkout_label', '' ) ) . '"
550
-			data-description="' . esc_attr( strip_tags( $this->stripe_checkout_description ) ) . '"
551
-			data-email="' . esc_attr( $user_email ) . '"
552
-			data-verify-zip="' . esc_attr( apply_filters( 'wc_stripe_checkout_verify_zip', false ) ? 'true' : 'false' ) . '"
553
-			data-billing-address="' . esc_attr( apply_filters( 'wc_stripe_checkout_require_billing_address', false ) ? 'true' : 'false' ) . '"
554
-			data-shipping-address="' . esc_attr( apply_filters( 'wc_stripe_checkout_require_shipping_address', false ) ? 'true' : 'false' ) . '" 
555
-			data-amount="' . esc_attr( WC_Stripe_Helper::get_stripe_amount( $total ) ) . '"
556
-			data-name="' . esc_attr( $this->statement_descriptor ) . '"
557
-			data-currency="' . esc_attr( strtolower( get_woocommerce_currency() ) ) . '"
558
-			data-image="' . esc_attr( $this->stripe_checkout_image ) . '"
559
-			data-bitcoin="' . esc_attr( ( $this->bitcoin && $this->capture ) ? 'true' : 'false' ) . '"
560
-			data-locale="' . esc_attr( apply_filters( 'wc_stripe_checkout_locale', $this->get_locale() ) ) . '"
561
-			data-three-d-secure="' . esc_attr( $this->three_d_secure ? 'true' : 'false' ) . '"
562
-			data-allow-remember-me="' . esc_attr( apply_filters( 'wc_stripe_allow_remember_me', true ) ? 'true' : 'false' ) . '">';
563
-		echo '<input type="hidden" name="order_id" value="' . esc_attr( $order_id ) . '" />';
549
+			data-panel-label="' . esc_attr(apply_filters('wc_stripe_checkout_label', '')) . '"
550
+			data-description="' . esc_attr(strip_tags($this->stripe_checkout_description)) . '"
551
+			data-email="' . esc_attr($user_email) . '"
552
+			data-verify-zip="' . esc_attr(apply_filters('wc_stripe_checkout_verify_zip', false) ? 'true' : 'false') . '"
553
+			data-billing-address="' . esc_attr(apply_filters('wc_stripe_checkout_require_billing_address', false) ? 'true' : 'false') . '"
554
+			data-shipping-address="' . esc_attr(apply_filters('wc_stripe_checkout_require_shipping_address', false) ? 'true' : 'false') . '" 
555
+			data-amount="' . esc_attr(WC_Stripe_Helper::get_stripe_amount($total)) . '"
556
+			data-name="' . esc_attr($this->statement_descriptor) . '"
557
+			data-currency="' . esc_attr(strtolower(get_woocommerce_currency())) . '"
558
+			data-image="' . esc_attr($this->stripe_checkout_image) . '"
559
+			data-bitcoin="' . esc_attr(($this->bitcoin && $this->capture) ? 'true' : 'false') . '"
560
+			data-locale="' . esc_attr(apply_filters('wc_stripe_checkout_locale', $this->get_locale())) . '"
561
+			data-three-d-secure="' . esc_attr($this->three_d_secure ? 'true' : 'false') . '"
562
+			data-allow-remember-me="' . esc_attr(apply_filters('wc_stripe_allow_remember_me', true) ? 'true' : 'false') . '">';
563
+		echo '<input type="hidden" name="order_id" value="' . esc_attr($order_id) . '" />';
564 564
 		echo '<input type="hidden" name="stripe_checkout_order" value="yes" />';
565 565
 
566 566
 		if (
567
-			apply_filters( 'wc_stripe_display_save_payment_method_checkbox', $display_tokenization ) &&
568
-			( ! function_exists( 'wcs_order_contains_subscription' ) || ( function_exists( 'wcs_order_contains_subscription' ) && ! WC_Subscriptions_Cart::cart_contains_subscription() ) ) &&
569
-			( ! WC_Stripe_Helper::is_pre_orders_exists() || ( WC_Stripe_Helper::is_pre_orders_exists() && ! $this->pre_orders->is_pre_order( $order_id ) ) )
567
+			apply_filters('wc_stripe_display_save_payment_method_checkbox', $display_tokenization) &&
568
+			( ! function_exists('wcs_order_contains_subscription') || (function_exists('wcs_order_contains_subscription') && ! WC_Subscriptions_Cart::cart_contains_subscription())) &&
569
+			( ! WC_Stripe_Helper::is_pre_orders_exists() || (WC_Stripe_Helper::is_pre_orders_exists() && ! $this->pre_orders->is_pre_order($order_id)))
570 570
 		) {
571 571
 			$this->save_payment_method_checkbox();
572 572
 		}
573 573
 
574
-		wp_nonce_field( 'stripe-checkout-process', 'stripe_checkout_process_nonce' );
574
+		wp_nonce_field('stripe-checkout-process', 'stripe_checkout_process_nonce');
575 575
 
576
-		do_action( 'wc_stripe_checkout_receipt_page_before_form_submit' );
576
+		do_action('wc_stripe_checkout_receipt_page_before_form_submit');
577 577
 
578
-		echo '<button type="submit" class="wc-stripe-checkout-button">' . __( 'Place Order', 'woocommerce-gateway-stripe' ) . '</button>';
578
+		echo '<button type="submit" class="wc-stripe-checkout-button">' . __('Place Order', 'woocommerce-gateway-stripe') . '</button>';
579 579
 
580
-		do_action( 'wc_stripe_checkout_receipt_page_after_form_submit' );
580
+		do_action('wc_stripe_checkout_receipt_page_after_form_submit');
581 581
 
582 582
 		echo '</form>';
583 583
 
584
-		do_action( 'wc_stripe_checkout_receipt_page_after_form' );
584
+		do_action('wc_stripe_checkout_receipt_page_after_form');
585 585
 
586 586
 		echo '</div>';
587 587
 
@@ -594,32 +594,32 @@  discard block
 block discarded – undo
594 594
 	 * @since 4.1.0
595 595
 	 */
596 596
 	public function stripe_checkout_return_handler() {
597
-		if ( ! $this->stripe_checkout ) {
597
+		if ( ! $this->stripe_checkout) {
598 598
 			return;
599 599
 		}
600 600
 
601
-		if ( ! wp_verify_nonce( $_POST['stripe_checkout_process_nonce'], 'stripe-checkout-process' ) ) {
601
+		if ( ! wp_verify_nonce($_POST['stripe_checkout_process_nonce'], 'stripe-checkout-process')) {
602 602
 			return;
603 603
 		}
604 604
 
605
-		$order_id = wc_clean( $_POST['order_id'] );
606
-		$order    = wc_get_order( $order_id );
605
+		$order_id = wc_clean($_POST['order_id']);
606
+		$order    = wc_get_order($order_id);
607 607
 
608
-		do_action( 'wc_stripe_checkout_return_handler', $order );
608
+		do_action('wc_stripe_checkout_return_handler', $order);
609 609
 
610
-		if ( WC_Stripe_Helper::is_pre_orders_exists() && $this->pre_orders->is_pre_order( $order_id ) && WC_Pre_Orders_Order::order_requires_payment_tokenization( $order_id ) ) {
611
-			$result = $this->pre_orders->process_pre_order( $order_id );
610
+		if (WC_Stripe_Helper::is_pre_orders_exists() && $this->pre_orders->is_pre_order($order_id) && WC_Pre_Orders_Order::order_requires_payment_tokenization($order_id)) {
611
+			$result = $this->pre_orders->process_pre_order($order_id);
612 612
 		} else {
613
-			$result = $this->process_payment( $order_id );
613
+			$result = $this->process_payment($order_id);
614 614
 		}
615 615
 
616
-		if ( 'success' === $result['result'] ) {
617
-			wp_redirect( $result['redirect'] );
616
+		if ('success' === $result['result']) {
617
+			wp_redirect($result['redirect']);
618 618
 			exit;
619 619
 		}
620 620
 
621 621
 		// Redirects back to pay order page.
622
-		wp_safe_redirect( $order->get_checkout_payment_url( true ) );
622
+		wp_safe_redirect($order->get_checkout_payment_url(true));
623 623
 		exit;
624 624
 	}
625 625
 
@@ -632,9 +632,9 @@  discard block
 block discarded – undo
632 632
 	public function maybe_redirect_stripe_checkout() {
633 633
 		return (
634 634
 			$this->stripe_checkout &&
635
-			! isset( $_POST['stripe_checkout_order'] ) &&
635
+			! isset($_POST['stripe_checkout_order']) &&
636 636
 			! $this->is_using_saved_payment_method() &&
637
-			! is_wc_endpoint_url( 'order-pay' )
637
+			! is_wc_endpoint_url('order-pay')
638 638
 		);
639 639
 	}
640 640
 
@@ -652,54 +652,54 @@  discard block
 block discarded – undo
652 652
 	 *
653 653
 	 * @return array|void
654 654
 	 */
655
-	public function process_payment( $order_id, $retry = true, $force_save_source = false, $previous_error = false ) {
655
+	public function process_payment($order_id, $retry = true, $force_save_source = false, $previous_error = false) {
656 656
 		try {
657
-			$order = wc_get_order( $order_id );
657
+			$order = wc_get_order($order_id);
658 658
 
659
-			if ( $this->maybe_redirect_stripe_checkout() ) {
660
-				WC_Stripe_Logger::log( sprintf( 'Redirecting to Stripe Checkout page for order %s', $order_id ) );
659
+			if ($this->maybe_redirect_stripe_checkout()) {
660
+				WC_Stripe_Logger::log(sprintf('Redirecting to Stripe Checkout page for order %s', $order_id));
661 661
 
662 662
 				return array(
663 663
 					'result'   => 'success',
664
-					'redirect' => $order->get_checkout_payment_url( true ),
664
+					'redirect' => $order->get_checkout_payment_url(true),
665 665
 				);
666 666
 			}
667 667
 
668
-			if ( $this->maybe_process_pre_orders( $order_id ) ) {
669
-				return $this->pre_orders->process_pre_order( $order_id );
668
+			if ($this->maybe_process_pre_orders($order_id)) {
669
+				return $this->pre_orders->process_pre_order($order_id);
670 670
 			}
671 671
 
672 672
 			// This comes from the create account checkbox in the checkout page.
673
-			$create_account = ! empty( $_POST['createaccount'] ) ? true : false;
673
+			$create_account = ! empty($_POST['createaccount']) ? true : false;
674 674
 
675
-			if ( $create_account ) {
675
+			if ($create_account) {
676 676
 				$new_customer_id     = WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id();
677
-				$new_stripe_customer = new WC_Stripe_Customer( $new_customer_id );
677
+				$new_stripe_customer = new WC_Stripe_Customer($new_customer_id);
678 678
 				$new_stripe_customer->create_customer();
679 679
 			}
680 680
 
681
-			$prepared_source = $this->prepare_source( get_current_user_id(), $force_save_source );
681
+			$prepared_source = $this->prepare_source(get_current_user_id(), $force_save_source);
682 682
 			$source_object   = $prepared_source->source_object;
683 683
 
684 684
 			// Check if we don't allow prepaid credit cards.
685
-			if ( ! apply_filters( 'wc_stripe_allow_prepaid_card', true ) && $this->is_prepaid_card( $source_object ) ) {
686
-				$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' );
687
-				throw new WC_Stripe_Exception( print_r( $source_object, true ), $localized_message );
685
+			if ( ! apply_filters('wc_stripe_allow_prepaid_card', true) && $this->is_prepaid_card($source_object)) {
686
+				$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');
687
+				throw new WC_Stripe_Exception(print_r($source_object, true), $localized_message);
688 688
 			}
689 689
 
690
-			if ( empty( $prepared_source->source ) ) {
691
-				$localized_message = __( 'Payment processing failed. Please retry.', 'woocommerce-gateway-stripe' );
692
-				throw new WC_Stripe_Exception( print_r( $prepared_source, true ), $localized_message );
690
+			if (empty($prepared_source->source)) {
691
+				$localized_message = __('Payment processing failed. Please retry.', 'woocommerce-gateway-stripe');
692
+				throw new WC_Stripe_Exception(print_r($prepared_source, true), $localized_message);
693 693
 			}
694 694
 
695
-			$this->save_source_to_order( $order, $prepared_source );
695
+			$this->save_source_to_order($order, $prepared_source);
696 696
 
697 697
 			// Result from Stripe API request.
698 698
 			$response = null;
699 699
 
700
-			if ( $order->get_total() > 0 ) {
700
+			if ($order->get_total() > 0) {
701 701
 				// This will throw exception if not valid.
702
-				$this->validate_minimum_order_amount( $order );
702
+				$this->validate_minimum_order_amount($order);
703 703
 
704 704
 				/*
705 705
 				 * Check if card 3DS is required or optional with 3DS setting.
@@ -708,104 +708,104 @@  discard block
 block discarded – undo
708 708
 				 * Note that if we need to save source, the original source must be first
709 709
 				 * attached to a customer in Stripe before it can be charged.
710 710
 				 */
711
-				if ( $this->is_3ds_required( $source_object ) ) {
712
-					$response = $this->create_3ds_source( $order, $source_object );
711
+				if ($this->is_3ds_required($source_object)) {
712
+					$response = $this->create_3ds_source($order, $source_object);
713 713
 
714
-					if ( ! empty( $response->error ) ) {
714
+					if ( ! empty($response->error)) {
715 715
 						$localized_message = $response->error->message;
716 716
 
717
-						$order->add_order_note( $localized_message );
717
+						$order->add_order_note($localized_message);
718 718
 
719
-						throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message );
719
+						throw new WC_Stripe_Exception(print_r($response, true), $localized_message);
720 720
 					}
721 721
 
722 722
 					// Update order meta with 3DS source.
723
-					if ( WC_Stripe_Helper::is_pre_30() ) {
724
-						update_post_meta( $order_id, '_stripe_source_id', $response->id );
723
+					if (WC_Stripe_Helper::is_pre_30()) {
724
+						update_post_meta($order_id, '_stripe_source_id', $response->id);
725 725
 					} else {
726
-						$order->update_meta_data( '_stripe_source_id', $response->id );
726
+						$order->update_meta_data('_stripe_source_id', $response->id);
727 727
 						$order->save();
728 728
 					}
729 729
 
730
-					WC_Stripe_Logger::log( 'Info: Redirecting to 3DS...' );
730
+					WC_Stripe_Logger::log('Info: Redirecting to 3DS...');
731 731
 
732 732
 					return array(
733 733
 						'result'   => 'success',
734
-						'redirect' => esc_url_raw( $response->redirect->url ),
734
+						'redirect' => esc_url_raw($response->redirect->url),
735 735
 					);
736 736
 				}
737 737
 
738
-				WC_Stripe_Logger::log( "Info: Begin processing payment for order $order_id for the amount of {$order->get_total()}" );
738
+				WC_Stripe_Logger::log("Info: Begin processing payment for order $order_id for the amount of {$order->get_total()}");
739 739
 
740 740
 				/* If we're doing a retry and source is chargeable, we need to pass
741 741
 				 * a different idempotency key and retry for success.
742 742
 				 */
743
-				if ( $this->need_update_idempotency_key( $source_object, $previous_error ) ) {
744
-					add_filter( 'wc_stripe_idempotency_key', array( $this, 'change_idempotency_key' ), 10, 2 );
743
+				if ($this->need_update_idempotency_key($source_object, $previous_error)) {
744
+					add_filter('wc_stripe_idempotency_key', array($this, 'change_idempotency_key'), 10, 2);
745 745
 				}
746 746
 
747 747
 				// Make the request.
748
-				$response = WC_Stripe_API::request( $this->generate_payment_request( $order, $prepared_source ) );
748
+				$response = WC_Stripe_API::request($this->generate_payment_request($order, $prepared_source));
749 749
 
750
-				if ( ! empty( $response->error ) ) {
750
+				if ( ! empty($response->error)) {
751 751
 					// Customer param wrong? The user may have been deleted on stripe's end. Remove customer_id. Can be retried without.
752
-					if ( $this->is_no_such_customer_error( $response->error ) ) {
753
-						if ( WC_Stripe_Helper::is_pre_30() ) {
754
-							delete_user_meta( $order->customer_user, '_stripe_customer_id' );
755
-							delete_post_meta( $order_id, '_stripe_customer_id' );
752
+					if ($this->is_no_such_customer_error($response->error)) {
753
+						if (WC_Stripe_Helper::is_pre_30()) {
754
+							delete_user_meta($order->customer_user, '_stripe_customer_id');
755
+							delete_post_meta($order_id, '_stripe_customer_id');
756 756
 						} else {
757
-							delete_user_meta( $order->get_customer_id(), '_stripe_customer_id' );
758
-							$order->delete_meta_data( '_stripe_customer_id' );
757
+							delete_user_meta($order->get_customer_id(), '_stripe_customer_id');
758
+							$order->delete_meta_data('_stripe_customer_id');
759 759
 							$order->save();
760 760
 						}
761 761
 					}
762 762
 
763
-					if ( $this->is_no_such_token_error( $response->error ) && $prepared_source->token_id ) {
763
+					if ($this->is_no_such_token_error($response->error) && $prepared_source->token_id) {
764 764
 						// Source param wrong? The CARD may have been deleted on stripe's end. Remove token and show message.
765
-						$wc_token = WC_Payment_Tokens::get( $prepared_source->token_id );
765
+						$wc_token = WC_Payment_Tokens::get($prepared_source->token_id);
766 766
 						$wc_token->delete();
767
-						$localized_message = __( 'This card is no longer available and has been removed.', 'woocommerce-gateway-stripe' );
768
-						$order->add_order_note( $localized_message );
769
-						throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message );
767
+						$localized_message = __('This card is no longer available and has been removed.', 'woocommerce-gateway-stripe');
768
+						$order->add_order_note($localized_message);
769
+						throw new WC_Stripe_Exception(print_r($response, true), $localized_message);
770 770
 					}
771 771
 
772 772
 					// We want to retry.
773
-					if ( $this->is_retryable_error( $response->error ) ) {
774
-						if ( $retry ) {
773
+					if ($this->is_retryable_error($response->error)) {
774
+						if ($retry) {
775 775
 							// Don't do anymore retries after this.
776
-							if ( 5 <= $this->retry_interval ) {
777
-								return $this->process_payment( $order_id, false, $force_save_source, $response->error );
776
+							if (5 <= $this->retry_interval) {
777
+								return $this->process_payment($order_id, false, $force_save_source, $response->error);
778 778
 							}
779 779
 
780
-							sleep( $this->retry_interval );
780
+							sleep($this->retry_interval);
781 781
 
782 782
 							$this->retry_interval++;
783 783
 
784
-							return $this->process_payment( $order_id, true, $force_save_source, $response->error );
784
+							return $this->process_payment($order_id, true, $force_save_source, $response->error);
785 785
 						} else {
786
-							$localized_message = __( 'Sorry, we are unable to process your payment at this time. Please retry later.', 'woocommerce-gateway-stripe' );
787
-							$order->add_order_note( $localized_message );
788
-							throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message );
786
+							$localized_message = __('Sorry, we are unable to process your payment at this time. Please retry later.', 'woocommerce-gateway-stripe');
787
+							$order->add_order_note($localized_message);
788
+							throw new WC_Stripe_Exception(print_r($response, true), $localized_message);
789 789
 						}
790 790
 					}
791 791
 
792 792
 					$localized_messages = WC_Stripe_Helper::get_localized_messages();
793 793
 
794
-					if ( 'card_error' === $response->error->type ) {
795
-						$localized_message = isset( $localized_messages[ $response->error->code ] ) ? $localized_messages[ $response->error->code ] : $response->error->message;
794
+					if ('card_error' === $response->error->type) {
795
+						$localized_message = isset($localized_messages[$response->error->code]) ? $localized_messages[$response->error->code] : $response->error->message;
796 796
 					} else {
797
-						$localized_message = isset( $localized_messages[ $response->error->type ] ) ? $localized_messages[ $response->error->type ] : $response->error->message;
797
+						$localized_message = isset($localized_messages[$response->error->type]) ? $localized_messages[$response->error->type] : $response->error->message;
798 798
 					}
799 799
 
800
-					$order->add_order_note( $localized_message );
800
+					$order->add_order_note($localized_message);
801 801
 
802
-					throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message );
802
+					throw new WC_Stripe_Exception(print_r($response, true), $localized_message);
803 803
 				}
804 804
 
805
-				do_action( 'wc_gateway_stripe_process_payment', $response, $order );
805
+				do_action('wc_gateway_stripe_process_payment', $response, $order);
806 806
 
807 807
 				// Process valid response.
808
-				$this->process_response( $response, $order );
808
+				$this->process_response($response, $order);
809 809
 			} else {
810 810
 				$order->payment_complete();
811 811
 			}
@@ -816,20 +816,20 @@  discard block
 block discarded – undo
816 816
 			// Return thank you page redirect.
817 817
 			return array(
818 818
 				'result'   => 'success',
819
-				'redirect' => $this->get_return_url( $order ),
819
+				'redirect' => $this->get_return_url($order),
820 820
 			);
821 821
 
822
-		} catch ( WC_Stripe_Exception $e ) {
823
-			wc_add_notice( $e->getLocalizedMessage(), 'error' );
824
-			WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() );
822
+		} catch (WC_Stripe_Exception $e) {
823
+			wc_add_notice($e->getLocalizedMessage(), 'error');
824
+			WC_Stripe_Logger::log('Error: ' . $e->getMessage());
825 825
 
826
-			do_action( 'wc_gateway_stripe_process_payment_error', $e, $order );
826
+			do_action('wc_gateway_stripe_process_payment_error', $e, $order);
827 827
 
828 828
 			/* translators: error message */
829
-			$order->update_status( 'failed' );
829
+			$order->update_status('failed');
830 830
 
831
-			if ( $order->has_status( array( 'pending', 'failed' ) ) ) {
832
-				$this->send_failed_order_email( $order_id );
831
+			if ($order->has_status(array('pending', 'failed'))) {
832
+				$this->send_failed_order_email($order_id);
833 833
 			}
834 834
 
835 835
 			return array(
@@ -846,17 +846,17 @@  discard block
 block discarded – undo
846 846
 	 *
847 847
 	 * @param int $order_id
848 848
 	 */
849
-	public function display_order_fee( $order_id ) {
850
-		if ( apply_filters( 'wc_stripe_hide_display_order_fee', false, $order_id ) ) {
849
+	public function display_order_fee($order_id) {
850
+		if (apply_filters('wc_stripe_hide_display_order_fee', false, $order_id)) {
851 851
 			return;
852 852
 		}
853 853
 
854
-		$order = wc_get_order( $order_id );
854
+		$order = wc_get_order($order_id);
855 855
 
856
-		$fee      = WC_Stripe_Helper::get_stripe_fee( $order );
857
-		$currency = WC_Stripe_Helper::get_stripe_currency( $order );
856
+		$fee      = WC_Stripe_Helper::get_stripe_fee($order);
857
+		$currency = WC_Stripe_Helper::get_stripe_currency($order);
858 858
 
859
-		if ( ! $fee || ! $currency ) {
859
+		if ( ! $fee || ! $currency) {
860 860
 			return;
861 861
 		}
862 862
 
@@ -864,12 +864,12 @@  discard block
 block discarded – undo
864 864
 
865 865
 		<tr>
866 866
 			<td class="label stripe-fee">
867
-				<?php echo wc_help_tip( __( 'This represents the fee Stripe collects for the transaction.', 'woocommerce-gateway-stripe' ) ); ?>
868
-				<?php esc_html_e( 'Stripe Fee:', 'woocommerce-gateway-stripe' ); ?>
867
+				<?php echo wc_help_tip(__('This represents the fee Stripe collects for the transaction.', 'woocommerce-gateway-stripe')); ?>
868
+				<?php esc_html_e('Stripe Fee:', 'woocommerce-gateway-stripe'); ?>
869 869
 			</td>
870 870
 			<td width="1%"></td>
871 871
 			<td class="total">
872
-				-&nbsp;<?php echo wc_price( $fee, array( 'currency' => $currency ) ); ?>
872
+				-&nbsp;<?php echo wc_price($fee, array('currency' => $currency)); ?>
873 873
 			</td>
874 874
 		</tr>
875 875
 
@@ -883,17 +883,17 @@  discard block
 block discarded – undo
883 883
 	 *
884 884
 	 * @param int $order_id
885 885
 	 */
886
-	public function display_order_payout( $order_id ) {
887
-		if ( apply_filters( 'wc_stripe_hide_display_order_payout', false, $order_id ) ) {
886
+	public function display_order_payout($order_id) {
887
+		if (apply_filters('wc_stripe_hide_display_order_payout', false, $order_id)) {
888 888
 			return;
889 889
 		}
890 890
 
891
-		$order = wc_get_order( $order_id );
891
+		$order = wc_get_order($order_id);
892 892
 
893
-		$net      = WC_Stripe_Helper::get_stripe_net( $order );
894
-		$currency = WC_Stripe_Helper::get_stripe_currency( $order );
893
+		$net      = WC_Stripe_Helper::get_stripe_net($order);
894
+		$currency = WC_Stripe_Helper::get_stripe_currency($order);
895 895
 
896
-		if ( ! $net || ! $currency ) {
896
+		if ( ! $net || ! $currency) {
897 897
 			return;
898 898
 		}
899 899
 
@@ -901,12 +901,12 @@  discard block
 block discarded – undo
901 901
 
902 902
 		<tr>
903 903
 			<td class="label stripe-payout">
904
-				<?php echo wc_help_tip( __( 'This represents the net total that will be credited to your Stripe bank account. This may be in the currency that is set in your Stripe account.', 'woocommerce-gateway-stripe' ) ); ?>
905
-				<?php esc_html_e( 'Stripe Payout:', 'woocommerce-gateway-stripe' ); ?>
904
+				<?php echo wc_help_tip(__('This represents the net total that will be credited to your Stripe bank account. This may be in the currency that is set in your Stripe account.', 'woocommerce-gateway-stripe')); ?>
905
+				<?php esc_html_e('Stripe Payout:', 'woocommerce-gateway-stripe'); ?>
906 906
 			</td>
907 907
 			<td width="1%"></td>
908 908
 			<td class="total">
909
-				<?php echo wc_price( $net, array( 'currency' => $currency ) ); ?>
909
+				<?php echo wc_price($net, array('currency' => $currency)); ?>
910 910
 			</td>
911 911
 		</tr>
912 912
 
Please login to merge, or discard this patch.
includes/payment-methods/class-wc-gateway-stripe-bitcoin.php 1 patch
Spacing   +78 added lines, -78 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
 
@@ -64,9 +64,9 @@  discard block
 block discarded – undo
64 64
 	 */
65 65
 	public function __construct() {
66 66
 		$this->id                   = 'stripe_bitcoin';
67
-		$this->method_title         = __( 'Stripe Bitcoin', 'woocommerce-gateway-stripe' );
67
+		$this->method_title         = __('Stripe Bitcoin', 'woocommerce-gateway-stripe');
68 68
 		/* translators: link */
69
-		$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' ) );
69
+		$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'));
70 70
 		$this->supports             = array(
71 71
 			'products',
72 72
 			'refunds',
@@ -78,27 +78,27 @@  discard block
 block discarded – undo
78 78
 		// Load the settings.
79 79
 		$this->init_settings();
80 80
 
81
-		$main_settings              = get_option( 'woocommerce_stripe_settings' );
82
-		$this->title                = $this->get_option( 'title' );
83
-		$this->description          = $this->get_option( 'description' );
84
-		$this->enabled              = $this->get_option( 'enabled' );
85
-		$this->testmode             = ( ! empty( $main_settings['testmode'] ) && 'yes' === $main_settings['testmode'] ) ? true : false;
86
-		$this->saved_cards          = ( ! empty( $main_settings['saved_cards'] ) && 'yes' === $main_settings['saved_cards'] ) ? true : false;
87
-		$this->publishable_key      = ! empty( $main_settings['publishable_key'] ) ? $main_settings['publishable_key'] : '';
88
-		$this->secret_key           = ! empty( $main_settings['secret_key'] ) ? $main_settings['secret_key'] : '';
89
-		$this->statement_descriptor = ! empty( $main_settings['statement_descriptor'] ) ? $main_settings['statement_descriptor'] : '';
90
-
91
-		if ( $this->testmode ) {
92
-			$this->publishable_key = ! empty( $main_settings['test_publishable_key'] ) ? $main_settings['test_publishable_key'] : '';
93
-			$this->secret_key      = ! empty( $main_settings['test_secret_key'] ) ? $main_settings['test_secret_key'] : '';
81
+		$main_settings              = get_option('woocommerce_stripe_settings');
82
+		$this->title                = $this->get_option('title');
83
+		$this->description          = $this->get_option('description');
84
+		$this->enabled              = $this->get_option('enabled');
85
+		$this->testmode             = ( ! empty($main_settings['testmode']) && 'yes' === $main_settings['testmode']) ? true : false;
86
+		$this->saved_cards          = ( ! empty($main_settings['saved_cards']) && 'yes' === $main_settings['saved_cards']) ? true : false;
87
+		$this->publishable_key      = ! empty($main_settings['publishable_key']) ? $main_settings['publishable_key'] : '';
88
+		$this->secret_key           = ! empty($main_settings['secret_key']) ? $main_settings['secret_key'] : '';
89
+		$this->statement_descriptor = ! empty($main_settings['statement_descriptor']) ? $main_settings['statement_descriptor'] : '';
90
+
91
+		if ($this->testmode) {
92
+			$this->publishable_key = ! empty($main_settings['test_publishable_key']) ? $main_settings['test_publishable_key'] : '';
93
+			$this->secret_key      = ! empty($main_settings['test_secret_key']) ? $main_settings['test_secret_key'] : '';
94 94
 		}
95 95
 
96
-		add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) );
97
-		add_action( 'wp_enqueue_scripts', array( $this, 'payment_scripts' ) );
98
-		add_action( 'woocommerce_thankyou_stripe_bitcoin', array( $this, 'thankyou_page' ) );
96
+		add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options'));
97
+		add_action('wp_enqueue_scripts', array($this, 'payment_scripts'));
98
+		add_action('woocommerce_thankyou_stripe_bitcoin', array($this, 'thankyou_page'));
99 99
 
100 100
 		// Customer Emails.
101
-		add_action( 'woocommerce_email_before_order_table', array( $this, 'email_instructions' ), 10, 3 );
101
+		add_action('woocommerce_email_before_order_table', array($this, 'email_instructions'), 10, 3);
102 102
 	}
103 103
 
104 104
 	/**
@@ -109,9 +109,9 @@  discard block
 block discarded – undo
109 109
 	 * @return array
110 110
 	 */
111 111
 	public function get_supported_currency() {
112
-		return apply_filters( 'wc_stripe_bitcoin_supported_currencies', array(
112
+		return apply_filters('wc_stripe_bitcoin_supported_currencies', array(
113 113
 			'USD',
114
-		) );
114
+		));
115 115
 	}
116 116
 
117 117
 	/**
@@ -122,7 +122,7 @@  discard block
 block discarded – undo
122 122
 	 * @return bool
123 123
 	 */
124 124
 	public function is_available() {
125
-		if ( ! in_array( get_woocommerce_currency(), $this->get_supported_currency() ) ) {
125
+		if ( ! in_array(get_woocommerce_currency(), $this->get_supported_currency())) {
126 126
 			return false;
127 127
 		}
128 128
 
@@ -143,7 +143,7 @@  discard block
 block discarded – undo
143 143
 
144 144
 		$icons_str .= $icons['bitcoin'];
145 145
 
146
-		return apply_filters( 'woocommerce_gateway_icon', $icons_str, $this->id );
146
+		return apply_filters('woocommerce_gateway_icon', $icons_str, $this->id);
147 147
 	}
148 148
 
149 149
 	/**
@@ -154,19 +154,19 @@  discard block
 block discarded – undo
154 154
 	 * @access public
155 155
 	 */
156 156
 	public function payment_scripts() {
157
-		if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) && ! is_add_payment_method_page() ) {
157
+		if ( ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order']) && ! is_add_payment_method_page()) {
158 158
 			return;
159 159
 		}
160 160
 
161
-		wp_enqueue_style( 'stripe_styles' );
162
-		wp_enqueue_script( 'woocommerce_stripe' );
161
+		wp_enqueue_style('stripe_styles');
162
+		wp_enqueue_script('woocommerce_stripe');
163 163
 	}
164 164
 
165 165
 	/**
166 166
 	 * Initialize Gateway Settings Form Fields.
167 167
 	 */
168 168
 	public function init_form_fields() {
169
-		$this->form_fields = require( WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-bitcoin-settings.php' );
169
+		$this->form_fields = require(WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-bitcoin-settings.php');
170 170
 	}
171 171
 
172 172
 	/**
@@ -177,25 +177,25 @@  discard block
 block discarded – undo
177 177
 		$total = WC()->cart->total;
178 178
 
179 179
 		// If paying from order, we need to get total from order not cart.
180
-		if ( isset( $_GET['pay_for_order'] ) && ! empty( $_GET['key'] ) ) {
181
-			$order = wc_get_order( wc_get_order_id_by_order_key( wc_clean( $_GET['key'] ) ) );
180
+		if (isset($_GET['pay_for_order']) && ! empty($_GET['key'])) {
181
+			$order = wc_get_order(wc_get_order_id_by_order_key(wc_clean($_GET['key'])));
182 182
 			$total = $order->get_total();
183 183
 		}
184 184
 
185
-		if ( is_add_payment_method_page() ) {
186
-			$pay_button_text = __( 'Add Payment', 'woocommerce-gateway-stripe' );
187
-			$total        = '';
185
+		if (is_add_payment_method_page()) {
186
+			$pay_button_text = __('Add Payment', 'woocommerce-gateway-stripe');
187
+			$total = '';
188 188
 		} else {
189 189
 			$pay_button_text = '';
190 190
 		}
191 191
 
192 192
 		echo '<div
193 193
 			id="stripe-bitcoin-payment-data"
194
-			data-amount="' . esc_attr( WC_Stripe_Helper::get_stripe_amount( $total ) ) . '"
195
-			data-currency="' . esc_attr( strtolower( get_woocommerce_currency() ) ) . '">';
194
+			data-amount="' . esc_attr(WC_Stripe_Helper::get_stripe_amount($total)) . '"
195
+			data-currency="' . esc_attr(strtolower(get_woocommerce_currency())) . '">';
196 196
 
197
-		if ( $this->description ) {
198
-			echo apply_filters( 'wc_stripe_description', wpautop( wp_kses_post( $this->description ) ), $this->id );
197
+		if ($this->description) {
198
+			echo apply_filters('wc_stripe_description', wpautop(wp_kses_post($this->description)), $this->id);
199 199
 		}
200 200
 
201 201
 		echo '</div>';
@@ -206,8 +206,8 @@  discard block
 block discarded – undo
206 206
 	 *
207 207
 	 * @param int $order_id
208 208
 	 */
209
-	public function thankyou_page( $order_id ) {
210
-		$this->get_instructions( $order_id );
209
+	public function thankyou_page($order_id) {
210
+		$this->get_instructions($order_id);
211 211
 	}
212 212
 
213 213
 	/**
@@ -219,15 +219,15 @@  discard block
 block discarded – undo
219 219
 	 * @param bool $sent_to_admin
220 220
 	 * @param bool $plain_text
221 221
 	 */
222
-	public function email_instructions( $order, $sent_to_admin, $plain_text = false ) {
222
+	public function email_instructions($order, $sent_to_admin, $plain_text = false) {
223 223
 		$order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
224 224
 
225 225
 		$payment_method = WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method();
226 226
 
227
-		if ( ! $sent_to_admin && 'stripe_bitcoin' === $payment_method && $order->has_status( 'on-hold' ) ) {
228
-			WC_Stripe_Logger::log( 'Sending bitcoin email for order #' . $order_id );
227
+		if ( ! $sent_to_admin && 'stripe_bitcoin' === $payment_method && $order->has_status('on-hold')) {
228
+			WC_Stripe_Logger::log('Sending bitcoin email for order #' . $order_id);
229 229
 
230
-			$this->get_instructions( $order_id, $plain_text );
230
+			$this->get_instructions($order_id, $plain_text);
231 231
 		}
232 232
 	}
233 233
 
@@ -238,38 +238,38 @@  discard block
 block discarded – undo
238 238
 	 * @version 4.0.0
239 239
 	 * @param int $order_id
240 240
 	 */
241
-	public function get_instructions( $order_id, $plain_text = false ) {
242
-		$data = get_post_meta( $order_id, '_stripe_bitcoin', true );
241
+	public function get_instructions($order_id, $plain_text = false) {
242
+		$data = get_post_meta($order_id, '_stripe_bitcoin', true);
243 243
 
244
-		if ( $plain_text ) {
245
-			esc_html_e( 'Please pay the following:', 'woocommerce-gateway-stripe' ) . "\n\n";
244
+		if ($plain_text) {
245
+			esc_html_e('Please pay the following:', 'woocommerce-gateway-stripe') . "\n\n";
246 246
 			echo "=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\n\n";
247
-			esc_html_e( 'Bitcoin Amount:', 'woocommerce-gateway-stripe' ) . "\n\n";
247
+			esc_html_e('Bitcoin Amount:', 'woocommerce-gateway-stripe') . "\n\n";
248 248
 			echo $data['amount'] . "\n\n";
249 249
 			echo "=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\n\n";
250
-			esc_html_e( 'Receiver:', 'woocommerce-gateway-stripe' ) . "\n\n";
250
+			esc_html_e('Receiver:', 'woocommerce-gateway-stripe') . "\n\n";
251 251
 			echo $data['address'] . "\n\n";
252 252
 			echo "=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\n\n";
253
-			esc_html_e( 'URI:', 'woocommerce-gateway-stripe' ) . "\n\n";
253
+			esc_html_e('URI:', 'woocommerce-gateway-stripe') . "\n\n";
254 254
 			echo $data['uri'] . "\n\n";
255 255
 		} else {
256 256
 			?>
257
-			<h3><?php esc_html_e( 'Please pay the following:', 'woocommerce-gateway-stripe' ); ?></h3>
257
+			<h3><?php esc_html_e('Please pay the following:', 'woocommerce-gateway-stripe'); ?></h3>
258 258
 			<ul class="woocommerce-order-overview woocommerce-thankyou-order-details order_details">
259 259
 			<li class="woocommerce-order-overview__order order">
260
-				<?php esc_html_e( 'Bitcoin Amount:', 'woocommerce-gateway-stripe' ); ?>
260
+				<?php esc_html_e('Bitcoin Amount:', 'woocommerce-gateway-stripe'); ?>
261 261
 				<strong><?php echo $data['amount']; ?></strong>
262 262
 			</li>
263 263
 			<li class="woocommerce-order-overview__order order">
264
-				<?php esc_html_e( 'Receiver:', 'woocommerce-gateway-stripe' ); ?>
264
+				<?php esc_html_e('Receiver:', 'woocommerce-gateway-stripe'); ?>
265 265
 				<strong><?php echo $data['address']; ?></strong>
266 266
 			</li>
267 267
 			<li class="woocommerce-order-overview__order order">
268
-				<?php esc_html_e( 'URI:', 'woocommerce-gateway-stripe' ); ?>
268
+				<?php esc_html_e('URI:', 'woocommerce-gateway-stripe'); ?>
269 269
 				<strong>
270 270
 				<?php
271 271
 				/* translators: link */
272
-				printf( __( '<a href="%s">Pay Bitcoin</a>', 'woocommerce-gateway-stripe' ), $data['uri'] );
272
+				printf(__('<a href="%s">Pay Bitcoin</a>', 'woocommerce-gateway-stripe'), $data['uri']);
273 273
 				?>
274 274
 				</strong>
275 275
 			</li>
@@ -286,7 +286,7 @@  discard block
 block discarded – undo
286 286
 	 * @param object $order
287 287
 	 * @param object $source_object
288 288
 	 */
289
-	public function save_instructions( $order, $source_object ) {
289
+	public function save_instructions($order, $source_object) {
290 290
 		$data = array(
291 291
 			'amount'  => $source_object->bitcoin->amount,
292 292
 			'address' => $source_object->bitcoin->address,
@@ -295,7 +295,7 @@  discard block
 block discarded – undo
295 295
 
296 296
 		$order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
297 297
 
298
-		update_post_meta( $order_id, '_stripe_bitcoin', $data );
298
+		update_post_meta($order_id, '_stripe_bitcoin', $data);
299 299
 	}
300 300
 
301 301
 	/**
@@ -309,37 +309,37 @@  discard block
 block discarded – undo
309 309
 	 *
310 310
 	 * @return array|void
311 311
 	 */
312
-	public function process_payment( $order_id, $retry = true, $force_save_source = false ) {
312
+	public function process_payment($order_id, $retry = true, $force_save_source = false) {
313 313
 		try {
314
-			$order = wc_get_order( $order_id );
314
+			$order = wc_get_order($order_id);
315 315
 
316 316
 			// This comes from the create account checkbox in the checkout page.
317
-			$create_account = ! empty( $_POST['createaccount'] ) ? true : false;
317
+			$create_account = ! empty($_POST['createaccount']) ? true : false;
318 318
 
319
-			if ( $create_account ) {
319
+			if ($create_account) {
320 320
 				$new_customer_id     = WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id();
321
-				$new_stripe_customer = new WC_Stripe_Customer( $new_customer_id );
321
+				$new_stripe_customer = new WC_Stripe_Customer($new_customer_id);
322 322
 				$new_stripe_customer->create_customer();
323 323
 			}
324 324
 
325
-			$prepared_source = $this->prepare_source( get_current_user_id(), $force_save_source );
325
+			$prepared_source = $this->prepare_source(get_current_user_id(), $force_save_source);
326 326
 
327
-			if ( empty( $prepared_source->source ) ) {
328
-				$localized_message = __( 'Payment processing failed. Please retry.', 'woocommerce-gateway-stripe' );
329
-				throw new WC_Stripe_Exception( print_r( $prepared_source, true ), $localized_message );
327
+			if (empty($prepared_source->source)) {
328
+				$localized_message = __('Payment processing failed. Please retry.', 'woocommerce-gateway-stripe');
329
+				throw new WC_Stripe_Exception(print_r($prepared_source, true), $localized_message);
330 330
 			}
331 331
 
332
-			$this->save_source_to_order( $order, $prepared_source );
332
+			$this->save_source_to_order($order, $prepared_source);
333 333
 
334 334
 			// This will throw exception if not valid.
335
-			$this->validate_minimum_order_amount( $order );
335
+			$this->validate_minimum_order_amount($order);
336 336
 
337
-			$this->save_instructions( $order, $this->get_source_object( $prepared_source->source ) );
337
+			$this->save_instructions($order, $this->get_source_object($prepared_source->source));
338 338
 
339 339
 			// Mark as on-hold (we're awaiting the payment).
340
-			$order->update_status( 'on-hold', __( 'Awaiting Bitcoin payment', 'woocommerce-gateway-stripe' ) );
340
+			$order->update_status('on-hold', __('Awaiting Bitcoin payment', 'woocommerce-gateway-stripe'));
341 341
 
342
-			wc_reduce_stock_levels( $order_id );
342
+			wc_reduce_stock_levels($order_id);
343 343
 
344 344
 			// Remove cart.
345 345
 			WC()->cart->empty_cart();
@@ -347,16 +347,16 @@  discard block
 block discarded – undo
347 347
 			// Return thankyou redirect.
348 348
 			return array(
349 349
 				'result'    => 'success',
350
-				'redirect'  => $this->get_return_url( $order ),
350
+				'redirect'  => $this->get_return_url($order),
351 351
 			);
352
-		} catch ( WC_Stripe_Exception $e ) {
353
-			wc_add_notice( $e->getLocalizedMessage(), 'error' );
354
-			WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() );
352
+		} catch (WC_Stripe_Exception $e) {
353
+			wc_add_notice($e->getLocalizedMessage(), 'error');
354
+			WC_Stripe_Logger::log('Error: ' . $e->getMessage());
355 355
 
356
-			do_action( 'wc_gateway_stripe_process_payment_error', $e, $order );
356
+			do_action('wc_gateway_stripe_process_payment_error', $e, $order);
357 357
 
358
-			if ( $order->has_status( array( 'pending', 'failed' ) ) ) {
359
-				$this->send_failed_order_email( $order_id );
358
+			if ($order->has_status(array('pending', 'failed'))) {
359
+				$this->send_failed_order_email($order_id);
360 360
 			}
361 361
 
362 362
 			return array(
Please login to merge, or discard this patch.
includes/payment-methods/class-wc-gateway-stripe-alipay.php 1 patch
Spacing   +67 added lines, -67 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) {
2
+if ( ! defined('ABSPATH')) {
3 3
 	exit;
4 4
 }
5 5
 
@@ -57,9 +57,9 @@  discard block
 block discarded – undo
57 57
 	 */
58 58
 	public function __construct() {
59 59
 		$this->id                   = 'stripe_alipay';
60
-		$this->method_title         = __( 'Stripe Alipay', 'woocommerce-gateway-stripe' );
60
+		$this->method_title         = __('Stripe Alipay', 'woocommerce-gateway-stripe');
61 61
 		/* translators: link */
62
-		$this->method_description   = sprintf( __( 'All other general Stripe settings can be adjusted <a href="%s">here</a>.', 'woocommerce-gateway-stripe' ), admin_url( 'admin.php?page=wc-settings&tab=checkout&section=stripe' ) );
62
+		$this->method_description   = sprintf(__('All other general Stripe settings can be adjusted <a href="%s">here</a>.', 'woocommerce-gateway-stripe'), admin_url('admin.php?page=wc-settings&tab=checkout&section=stripe'));
63 63
 		$this->supports             = array(
64 64
 			'products',
65 65
 			'refunds',
@@ -71,23 +71,23 @@  discard block
 block discarded – undo
71 71
 		// Load the settings.
72 72
 		$this->init_settings();
73 73
 
74
-		$main_settings              = get_option( 'woocommerce_stripe_settings' );
75
-		$this->title                = $this->get_option( 'title' );
76
-		$this->description          = $this->get_option( 'description' );
77
-		$this->enabled              = $this->get_option( 'enabled' );
78
-		$this->testmode             = ( ! empty( $main_settings['testmode'] ) && 'yes' === $main_settings['testmode'] ) ? true : false;
79
-		$this->saved_cards          = ( ! empty( $main_settings['saved_cards'] ) && 'yes' === $main_settings['saved_cards'] ) ? true : false;
80
-		$this->publishable_key      = ! empty( $main_settings['publishable_key'] ) ? $main_settings['publishable_key'] : '';
81
-		$this->secret_key           = ! empty( $main_settings['secret_key'] ) ? $main_settings['secret_key'] : '';
82
-		$this->statement_descriptor = ! empty( $main_settings['statement_descriptor'] ) ? $main_settings['statement_descriptor'] : '';
83
-
84
-		if ( $this->testmode ) {
85
-			$this->publishable_key = ! empty( $main_settings['test_publishable_key'] ) ? $main_settings['test_publishable_key'] : '';
86
-			$this->secret_key      = ! empty( $main_settings['test_secret_key'] ) ? $main_settings['test_secret_key'] : '';
74
+		$main_settings              = get_option('woocommerce_stripe_settings');
75
+		$this->title                = $this->get_option('title');
76
+		$this->description          = $this->get_option('description');
77
+		$this->enabled              = $this->get_option('enabled');
78
+		$this->testmode             = ( ! empty($main_settings['testmode']) && 'yes' === $main_settings['testmode']) ? true : false;
79
+		$this->saved_cards          = ( ! empty($main_settings['saved_cards']) && 'yes' === $main_settings['saved_cards']) ? true : false;
80
+		$this->publishable_key      = ! empty($main_settings['publishable_key']) ? $main_settings['publishable_key'] : '';
81
+		$this->secret_key           = ! empty($main_settings['secret_key']) ? $main_settings['secret_key'] : '';
82
+		$this->statement_descriptor = ! empty($main_settings['statement_descriptor']) ? $main_settings['statement_descriptor'] : '';
83
+
84
+		if ($this->testmode) {
85
+			$this->publishable_key = ! empty($main_settings['test_publishable_key']) ? $main_settings['test_publishable_key'] : '';
86
+			$this->secret_key      = ! empty($main_settings['test_secret_key']) ? $main_settings['test_secret_key'] : '';
87 87
 		}
88 88
 
89
-		add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) );
90
-		add_action( 'wp_enqueue_scripts', array( $this, 'payment_scripts' ) );
89
+		add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options'));
90
+		add_action('wp_enqueue_scripts', array($this, 'payment_scripts'));
91 91
 	}
92 92
 
93 93
 	/**
@@ -98,7 +98,7 @@  discard block
 block discarded – undo
98 98
 	 * @return array
99 99
 	 */
100 100
 	public function get_supported_currency() {
101
-		return apply_filters( 'wc_stripe_alipay_supported_currencies', array(
101
+		return apply_filters('wc_stripe_alipay_supported_currencies', array(
102 102
 			'EUR',
103 103
 			'AUD',
104 104
 			'CAD',
@@ -108,7 +108,7 @@  discard block
 block discarded – undo
108 108
 			'NZD',
109 109
 			'SGD',
110 110
 			'USD',
111
-		) );
111
+		));
112 112
 	}
113 113
 
114 114
 	/**
@@ -119,7 +119,7 @@  discard block
 block discarded – undo
119 119
 	 * @return bool
120 120
 	 */
121 121
 	public function is_available() {
122
-		if ( ! in_array( get_woocommerce_currency(), $this->get_supported_currency() ) ) {
122
+		if ( ! in_array(get_woocommerce_currency(), $this->get_supported_currency())) {
123 123
 			return false;
124 124
 		}
125 125
 
@@ -140,7 +140,7 @@  discard block
 block discarded – undo
140 140
 
141 141
 		$icons_str .= $icons['alipay'];
142 142
 
143
-		return apply_filters( 'woocommerce_gateway_icon', $icons_str, $this->id );
143
+		return apply_filters('woocommerce_gateway_icon', $icons_str, $this->id);
144 144
 	}
145 145
 
146 146
 	/**
@@ -150,19 +150,19 @@  discard block
 block discarded – undo
150 150
 	 * @version 4.0.0
151 151
 	 */
152 152
 	public function payment_scripts() {
153
-		if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) && ! is_add_payment_method_page() ) {
153
+		if ( ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order']) && ! is_add_payment_method_page()) {
154 154
 			return;
155 155
 		}
156 156
 
157
-		wp_enqueue_style( 'stripe_styles' );
158
-		wp_enqueue_script( 'woocommerce_stripe' );
157
+		wp_enqueue_style('stripe_styles');
158
+		wp_enqueue_script('woocommerce_stripe');
159 159
 	}
160 160
 
161 161
 	/**
162 162
 	 * Initialize Gateway Settings Form Fields.
163 163
 	 */
164 164
 	public function init_form_fields() {
165
-		$this->form_fields = require( WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-alipay-settings.php' );
165
+		$this->form_fields = require(WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-alipay-settings.php');
166 166
 	}
167 167
 
168 168
 	/**
@@ -173,25 +173,25 @@  discard block
 block discarded – undo
173 173
 		$total = WC()->cart->total;
174 174
 
175 175
 		// If paying from order, we need to get total from order not cart.
176
-		if ( isset( $_GET['pay_for_order'] ) && ! empty( $_GET['key'] ) ) {
177
-			$order = wc_get_order( wc_get_order_id_by_order_key( wc_clean( $_GET['key'] ) ) );
176
+		if (isset($_GET['pay_for_order']) && ! empty($_GET['key'])) {
177
+			$order = wc_get_order(wc_get_order_id_by_order_key(wc_clean($_GET['key'])));
178 178
 			$total = $order->get_total();
179 179
 		}
180 180
 
181
-		if ( is_add_payment_method_page() ) {
182
-			$pay_button_text = __( 'Add Payment', 'woocommerce-gateway-stripe' );
183
-			$total        = '';
181
+		if (is_add_payment_method_page()) {
182
+			$pay_button_text = __('Add Payment', 'woocommerce-gateway-stripe');
183
+			$total = '';
184 184
 		} else {
185 185
 			$pay_button_text = '';
186 186
 		}
187 187
 
188 188
 		echo '<div
189 189
 			id="stripe-alipay-payment-data"
190
-			data-amount="' . esc_attr( WC_Stripe_Helper::get_stripe_amount( $total ) ) . '"
191
-			data-currency="' . esc_attr( strtolower( get_woocommerce_currency() ) ) . '">';
190
+			data-amount="' . esc_attr(WC_Stripe_Helper::get_stripe_amount($total)) . '"
191
+			data-currency="' . esc_attr(strtolower(get_woocommerce_currency())) . '">';
192 192
 
193
-		if ( $this->description ) {
194
-			echo apply_filters( 'wc_stripe_description', wpautop( wp_kses_post( $this->description ) ), $this->id );
193
+		if ($this->description) {
194
+			echo apply_filters('wc_stripe_description', wpautop(wp_kses_post($this->description)), $this->id);
195 195
 		}
196 196
 
197 197
 		echo '</div>';
@@ -205,24 +205,24 @@  discard block
 block discarded – undo
205 205
 	 * @param object $order
206 206
 	 * @return mixed
207 207
 	 */
208
-	public function create_source( $order ) {
208
+	public function create_source($order) {
209 209
 		$currency              = WC_Stripe_Helper::is_pre_30() ? $order->get_order_currency() : $order->get_currency();
210 210
 		$order_id              = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
211
-		$return_url            = $this->get_stripe_return_url( $order );
211
+		$return_url            = $this->get_stripe_return_url($order);
212 212
 		$post_data             = array();
213
-		$post_data['amount']   = WC_Stripe_Helper::get_stripe_amount( $order->get_total(), $currency );
214
-		$post_data['currency'] = strtolower( $currency );
213
+		$post_data['amount']   = WC_Stripe_Helper::get_stripe_amount($order->get_total(), $currency);
214
+		$post_data['currency'] = strtolower($currency);
215 215
 		$post_data['type']     = 'alipay';
216
-		$post_data['owner']    = $this->get_owner_details( $order );
217
-		$post_data['redirect'] = array( 'return_url' => $return_url );
216
+		$post_data['owner']    = $this->get_owner_details($order);
217
+		$post_data['redirect'] = array('return_url' => $return_url);
218 218
 
219
-		if ( ! empty( $this->statement_descriptor ) ) {
220
-			$post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor( $this->statement_descriptor );
219
+		if ( ! empty($this->statement_descriptor)) {
220
+			$post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor($this->statement_descriptor);
221 221
 		}
222 222
 
223
-		WC_Stripe_Logger::log( 'Info: Begin creating Alipay source' );
223
+		WC_Stripe_Logger::log('Info: Begin creating Alipay source');
224 224
 
225
-		return WC_Stripe_API::request( apply_filters( 'wc_stripe_alipay_source', $post_data, $order ), 'sources' );
225
+		return WC_Stripe_API::request(apply_filters('wc_stripe_alipay_source', $post_data, $order), 'sources');
226 226
 	}
227 227
 
228 228
 	/**
@@ -236,53 +236,53 @@  discard block
 block discarded – undo
236 236
 	 *
237 237
 	 * @return array|void
238 238
 	 */
239
-	public function process_payment( $order_id, $retry = true, $force_save_save = false ) {
239
+	public function process_payment($order_id, $retry = true, $force_save_save = false) {
240 240
 		try {
241
-			$order = wc_get_order( $order_id );
241
+			$order = wc_get_order($order_id);
242 242
 
243 243
 			// This will throw exception if not valid.
244
-			$this->validate_minimum_order_amount( $order );
244
+			$this->validate_minimum_order_amount($order);
245 245
 
246 246
 			// This comes from the create account checkbox in the checkout page.
247
-			$create_account = ! empty( $_POST['createaccount'] ) ? true : false;
247
+			$create_account = ! empty($_POST['createaccount']) ? true : false;
248 248
 
249
-			if ( $create_account ) {
249
+			if ($create_account) {
250 250
 				$new_customer_id     = WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id();
251
-				$new_stripe_customer = new WC_Stripe_Customer( $new_customer_id );
251
+				$new_stripe_customer = new WC_Stripe_Customer($new_customer_id);
252 252
 				$new_stripe_customer->create_customer();
253 253
 			}
254 254
 
255
-			$response = $this->create_source( $order );
255
+			$response = $this->create_source($order);
256 256
 
257
-			if ( ! empty( $response->error ) ) {
258
-				$order->add_order_note( $response->error->message );
257
+			if ( ! empty($response->error)) {
258
+				$order->add_order_note($response->error->message);
259 259
 
260
-				throw new WC_Stripe_Exception( print_r( $response, true ), $response->error->message );
260
+				throw new WC_Stripe_Exception(print_r($response, true), $response->error->message);
261 261
 			}
262 262
 
263
-			if ( WC_Stripe_Helper::is_pre_30() ) {
264
-				update_post_meta( $order_id, '_stripe_source_id', $response->id );
263
+			if (WC_Stripe_Helper::is_pre_30()) {
264
+				update_post_meta($order_id, '_stripe_source_id', $response->id);
265 265
 			} else {
266
-				$order->update_meta_data( '_stripe_source_id', $response->id );
266
+				$order->update_meta_data('_stripe_source_id', $response->id);
267 267
 				$order->save();
268 268
 			}
269 269
 
270
-			WC_Stripe_Logger::log( 'Info: Redirecting to Alipay...' );
270
+			WC_Stripe_Logger::log('Info: Redirecting to Alipay...');
271 271
 
272 272
 			return array(
273 273
 				'result'   => 'success',
274
-				'redirect' => esc_url_raw( $response->redirect->url ),
274
+				'redirect' => esc_url_raw($response->redirect->url),
275 275
 			);
276
-		} catch ( WC_Stripe_Exception $e ) {
277
-			wc_add_notice( $e->getLocalizedMessage(), 'error' );
278
-			WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() );
276
+		} catch (WC_Stripe_Exception $e) {
277
+			wc_add_notice($e->getLocalizedMessage(), 'error');
278
+			WC_Stripe_Logger::log('Error: ' . $e->getMessage());
279 279
 
280
-			do_action( 'wc_gateway_stripe_process_payment_error', $e, $order );
280
+			do_action('wc_gateway_stripe_process_payment_error', $e, $order);
281 281
 
282
-			$statuses = array( 'pending', 'failed' );
282
+			$statuses = array('pending', 'failed');
283 283
 
284
-			if ( $order->has_status( $statuses ) ) {
285
-				$this->send_failed_order_email( $order_id );
284
+			if ($order->has_status($statuses)) {
285
+				$this->send_failed_order_email($order_id);
286 286
 			}
287 287
 
288 288
 			return array(
Please login to merge, or discard this patch.
includes/payment-methods/class-wc-gateway-stripe-eps.php 1 patch
Spacing   +66 added lines, -66 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_eps';
60
-		$this->method_title         = __( 'Stripe EPS', 'woocommerce-gateway-stripe' );
60
+		$this->method_title         = __('Stripe EPS', 'woocommerce-gateway-stripe');
61 61
 		/* translators: link */
62
-		$this->method_description   = sprintf( __( 'All other general Stripe settings can be adjusted <a href="%s">here</a>.', 'woocommerce-gateway-stripe' ), admin_url( 'admin.php?page=wc-settings&tab=checkout&section=stripe' ) );
62
+		$this->method_description   = sprintf(__('All other general Stripe settings can be adjusted <a href="%s">here</a>.', 'woocommerce-gateway-stripe'), admin_url('admin.php?page=wc-settings&tab=checkout&section=stripe'));
63 63
 		$this->supports             = array(
64 64
 			'products',
65 65
 			'refunds',
@@ -71,23 +71,23 @@  discard block
 block discarded – undo
71 71
 		// Load the settings.
72 72
 		$this->init_settings();
73 73
 
74
-		$main_settings              = get_option( 'woocommerce_stripe_settings' );
75
-		$this->title                = $this->get_option( 'title' );
76
-		$this->description          = $this->get_option( 'description' );
77
-		$this->enabled              = $this->get_option( 'enabled' );
78
-		$this->testmode             = ( ! empty( $main_settings['testmode'] ) && 'yes' === $main_settings['testmode'] ) ? true : false;
79
-		$this->saved_cards          = ( ! empty( $main_settings['saved_cards'] ) && 'yes' === $main_settings['saved_cards'] ) ? true : false;
80
-		$this->publishable_key      = ! empty( $main_settings['publishable_key'] ) ? $main_settings['publishable_key'] : '';
81
-		$this->secret_key           = ! empty( $main_settings['secret_key'] ) ? $main_settings['secret_key'] : '';
82
-		$this->statement_descriptor = ! empty( $main_settings['statement_descriptor'] ) ? $main_settings['statement_descriptor'] : '';
83
-
84
-		if ( $this->testmode ) {
85
-			$this->publishable_key = ! empty( $main_settings['test_publishable_key'] ) ? $main_settings['test_publishable_key'] : '';
86
-			$this->secret_key      = ! empty( $main_settings['test_secret_key'] ) ? $main_settings['test_secret_key'] : '';
74
+		$main_settings              = get_option('woocommerce_stripe_settings');
75
+		$this->title                = $this->get_option('title');
76
+		$this->description          = $this->get_option('description');
77
+		$this->enabled              = $this->get_option('enabled');
78
+		$this->testmode             = ( ! empty($main_settings['testmode']) && 'yes' === $main_settings['testmode']) ? true : false;
79
+		$this->saved_cards          = ( ! empty($main_settings['saved_cards']) && 'yes' === $main_settings['saved_cards']) ? true : false;
80
+		$this->publishable_key      = ! empty($main_settings['publishable_key']) ? $main_settings['publishable_key'] : '';
81
+		$this->secret_key           = ! empty($main_settings['secret_key']) ? $main_settings['secret_key'] : '';
82
+		$this->statement_descriptor = ! empty($main_settings['statement_descriptor']) ? $main_settings['statement_descriptor'] : '';
83
+
84
+		if ($this->testmode) {
85
+			$this->publishable_key = ! empty($main_settings['test_publishable_key']) ? $main_settings['test_publishable_key'] : '';
86
+			$this->secret_key      = ! empty($main_settings['test_secret_key']) ? $main_settings['test_secret_key'] : '';
87 87
 		}
88 88
 
89
-		add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) );
90
-		add_action( 'wp_enqueue_scripts', array( $this, 'payment_scripts' ) );
89
+		add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options'));
90
+		add_action('wp_enqueue_scripts', array($this, 'payment_scripts'));
91 91
 	}
92 92
 
93 93
 	/**
@@ -98,9 +98,9 @@  discard block
 block discarded – undo
98 98
 	 * @return array
99 99
 	 */
100 100
 	public function get_supported_currency() {
101
-		return apply_filters( 'wc_stripe_eps_supported_currencies', array(
101
+		return apply_filters('wc_stripe_eps_supported_currencies', array(
102 102
 			'EUR',
103
-		) );
103
+		));
104 104
 	}
105 105
 
106 106
 	/**
@@ -111,7 +111,7 @@  discard block
 block discarded – undo
111 111
 	 * @return bool
112 112
 	 */
113 113
 	public function is_available() {
114
-		if ( ! in_array( get_woocommerce_currency(), $this->get_supported_currency() ) ) {
114
+		if ( ! in_array(get_woocommerce_currency(), $this->get_supported_currency())) {
115 115
 			return false;
116 116
 		}
117 117
 
@@ -132,7 +132,7 @@  discard block
 block discarded – undo
132 132
 
133 133
 		$icons_str .= $icons['eps'];
134 134
 
135
-		return apply_filters( 'woocommerce_gateway_icon', $icons_str, $this->id );
135
+		return apply_filters('woocommerce_gateway_icon', $icons_str, $this->id);
136 136
 	}
137 137
 
138 138
 	/**
@@ -143,19 +143,19 @@  discard block
 block discarded – undo
143 143
 	 * @access public
144 144
 	 */
145 145
 	public function payment_scripts() {
146
-		if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) && ! is_add_payment_method_page() ) {
146
+		if ( ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order']) && ! is_add_payment_method_page()) {
147 147
 			return;
148 148
 		}
149 149
 
150
-		wp_enqueue_style( 'stripe_styles' );
151
-		wp_enqueue_script( 'woocommerce_stripe' );
150
+		wp_enqueue_style('stripe_styles');
151
+		wp_enqueue_script('woocommerce_stripe');
152 152
 	}
153 153
 
154 154
 	/**
155 155
 	 * Initialize Gateway Settings Form Fields.
156 156
 	 */
157 157
 	public function init_form_fields() {
158
-		$this->form_fields = require( WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-eps-settings.php' );
158
+		$this->form_fields = require(WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-eps-settings.php');
159 159
 	}
160 160
 
161 161
 	/**
@@ -166,25 +166,25 @@  discard block
 block discarded – undo
166 166
 		$total = WC()->cart->total;
167 167
 
168 168
 		// If paying from order, we need to get total from order not cart.
169
-		if ( isset( $_GET['pay_for_order'] ) && ! empty( $_GET['key'] ) ) {
170
-			$order = wc_get_order( wc_get_order_id_by_order_key( wc_clean( $_GET['key'] ) ) );
169
+		if (isset($_GET['pay_for_order']) && ! empty($_GET['key'])) {
170
+			$order = wc_get_order(wc_get_order_id_by_order_key(wc_clean($_GET['key'])));
171 171
 			$total = $order->get_total();
172 172
 		}
173 173
 
174
-		if ( is_add_payment_method_page() ) {
175
-			$pay_button_text = __( 'Add Payment', 'woocommerce-gateway-stripe' );
176
-			$total        = '';
174
+		if (is_add_payment_method_page()) {
175
+			$pay_button_text = __('Add Payment', 'woocommerce-gateway-stripe');
176
+			$total = '';
177 177
 		} else {
178 178
 			$pay_button_text = '';
179 179
 		}
180 180
 
181 181
 		echo '<div
182 182
 			id="stripe-eps-payment-data"
183
-			data-amount="' . esc_attr( WC_Stripe_Helper::get_stripe_amount( $total ) ) . '"
184
-			data-currency="' . esc_attr( strtolower( get_woocommerce_currency() ) ) . '">';
183
+			data-amount="' . esc_attr(WC_Stripe_Helper::get_stripe_amount($total)) . '"
184
+			data-currency="' . esc_attr(strtolower(get_woocommerce_currency())) . '">';
185 185
 
186
-		if ( $this->description ) {
187
-			echo apply_filters( 'wc_stripe_description', wpautop( wp_kses_post( $this->description ) ), $this->id );
186
+		if ($this->description) {
187
+			echo apply_filters('wc_stripe_description', wpautop(wp_kses_post($this->description)), $this->id);
188 188
 		}
189 189
 
190 190
 		echo '</div>';
@@ -198,24 +198,24 @@  discard block
 block discarded – undo
198 198
 	 * @param object $order
199 199
 	 * @return mixed
200 200
 	 */
201
-	public function create_source( $order ) {
201
+	public function create_source($order) {
202 202
 		$currency              = WC_Stripe_Helper::is_pre_30() ? $order->get_order_currency() : $order->get_currency();
203 203
 		$order_id              = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
204
-		$return_url            = $this->get_stripe_return_url( $order );
204
+		$return_url            = $this->get_stripe_return_url($order);
205 205
 		$post_data             = array();
206
-		$post_data['amount']   = WC_Stripe_Helper::get_stripe_amount( $order->get_total(), $currency );
207
-		$post_data['currency'] = strtolower( $currency );
206
+		$post_data['amount']   = WC_Stripe_Helper::get_stripe_amount($order->get_total(), $currency);
207
+		$post_data['currency'] = strtolower($currency);
208 208
 		$post_data['type']     = 'eps';
209
-		$post_data['owner']    = $this->get_owner_details( $order );
210
-		$post_data['redirect'] = array( 'return_url' => $return_url );
209
+		$post_data['owner']    = $this->get_owner_details($order);
210
+		$post_data['redirect'] = array('return_url' => $return_url);
211 211
 
212
-		if ( ! empty( $this->statement_descriptor ) ) {
213
-			$post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor( $this->statement_descriptor );
212
+		if ( ! empty($this->statement_descriptor)) {
213
+			$post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor($this->statement_descriptor);
214 214
 		}
215 215
 
216
-		WC_Stripe_Logger::log( 'Info: Begin creating EPS source' );
216
+		WC_Stripe_Logger::log('Info: Begin creating EPS source');
217 217
 
218
-		return WC_Stripe_API::request( $post_data, 'sources' );
218
+		return WC_Stripe_API::request($post_data, 'sources');
219 219
 	}
220 220
 
221 221
 	/**
@@ -229,51 +229,51 @@  discard block
 block discarded – undo
229 229
 	 *
230 230
 	 * @return array|void
231 231
 	 */
232
-	public function process_payment( $order_id, $retry = true, $force_save_source = false ) {
232
+	public function process_payment($order_id, $retry = true, $force_save_source = false) {
233 233
 		try {
234
-			$order = wc_get_order( $order_id );
234
+			$order = wc_get_order($order_id);
235 235
 
236 236
 			// This will throw exception if not valid.
237
-			$this->validate_minimum_order_amount( $order );
237
+			$this->validate_minimum_order_amount($order);
238 238
 
239 239
 			// This comes from the create account checkbox in the checkout page.
240
-			$create_account = ! empty( $_POST['createaccount'] ) ? true : false;
240
+			$create_account = ! empty($_POST['createaccount']) ? true : false;
241 241
 
242
-			if ( $create_account ) {
242
+			if ($create_account) {
243 243
 				$new_customer_id     = WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id();
244
-				$new_stripe_customer = new WC_Stripe_Customer( $new_customer_id );
244
+				$new_stripe_customer = new WC_Stripe_Customer($new_customer_id);
245 245
 				$new_stripe_customer->create_customer();
246 246
 			}
247 247
 
248
-			$response = $this->create_source( $order );
248
+			$response = $this->create_source($order);
249 249
 
250
-			if ( ! empty( $response->error ) ) {
251
-				$order->add_order_note( $response->error->message );
250
+			if ( ! empty($response->error)) {
251
+				$order->add_order_note($response->error->message);
252 252
 
253
-				throw new Exception( $response->error->message );
253
+				throw new Exception($response->error->message);
254 254
 			}
255 255
 
256
-			if ( WC_Stripe_Helper::is_pre_30() ) {
257
-				update_post_meta( $order_id, '_stripe_source_id', $response->id );
256
+			if (WC_Stripe_Helper::is_pre_30()) {
257
+				update_post_meta($order_id, '_stripe_source_id', $response->id);
258 258
 			} else {
259
-				$order->update_meta_data( '_stripe_source_id', $response->id );
259
+				$order->update_meta_data('_stripe_source_id', $response->id);
260 260
 				$order->save();
261 261
 			}
262 262
 
263
-			WC_Stripe_Logger::log( 'Info: Redirecting to EPS...' );
263
+			WC_Stripe_Logger::log('Info: Redirecting to EPS...');
264 264
 
265 265
 			return array(
266 266
 				'result'   => 'success',
267
-				'redirect' => esc_url_raw( $response->redirect->url ),
267
+				'redirect' => esc_url_raw($response->redirect->url),
268 268
 			);
269
-		} catch ( Exception $e ) {
270
-			wc_add_notice( $e->getMessage(), 'error' );
271
-			WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() );
269
+		} catch (Exception $e) {
270
+			wc_add_notice($e->getMessage(), 'error');
271
+			WC_Stripe_Logger::log('Error: ' . $e->getMessage());
272 272
 
273
-			do_action( 'wc_gateway_stripe_process_payment_error', $e, $order );
273
+			do_action('wc_gateway_stripe_process_payment_error', $e, $order);
274 274
 
275
-			if ( $order->has_status( array( 'pending', 'failed' ) ) ) {
276
-				$this->send_failed_order_email( $order_id );
275
+			if ($order->has_status(array('pending', 'failed'))) {
276
+				$this->send_failed_order_email($order_id);
277 277
 			}
278 278
 
279 279
 			return array(
Please login to merge, or discard this patch.
includes/payment-methods/class-wc-gateway-stripe-bancontact.php 1 patch
Spacing   +67 added lines, -67 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) {
2
+if ( ! defined('ABSPATH')) {
3 3
 	exit;
4 4
 }
5 5
 
@@ -57,9 +57,9 @@  discard block
 block discarded – undo
57 57
 	 */
58 58
 	public function __construct() {
59 59
 		$this->id                   = 'stripe_bancontact';
60
-		$this->method_title         = __( 'Stripe Bancontact', 'woocommerce-gateway-stripe' );
60
+		$this->method_title         = __('Stripe Bancontact', 'woocommerce-gateway-stripe');
61 61
 		/* translators: link */
62
-		$this->method_description   = sprintf( __( 'All other general Stripe settings can be adjusted <a href="%s">here</a>.', 'woocommerce-gateway-stripe' ), admin_url( 'admin.php?page=wc-settings&tab=checkout&section=stripe' ) );
62
+		$this->method_description   = sprintf(__('All other general Stripe settings can be adjusted <a href="%s">here</a>.', 'woocommerce-gateway-stripe'), admin_url('admin.php?page=wc-settings&tab=checkout&section=stripe'));
63 63
 		$this->supports             = array(
64 64
 			'products',
65 65
 			'refunds',
@@ -71,23 +71,23 @@  discard block
 block discarded – undo
71 71
 		// Load the settings.
72 72
 		$this->init_settings();
73 73
 
74
-		$main_settings              = get_option( 'woocommerce_stripe_settings' );
75
-		$this->title                = $this->get_option( 'title' );
76
-		$this->description          = $this->get_option( 'description' );
77
-		$this->enabled              = $this->get_option( 'enabled' );
78
-		$this->testmode             = ( ! empty( $main_settings['testmode'] ) && 'yes' === $main_settings['testmode'] ) ? true : false;
79
-		$this->saved_cards          = ( ! empty( $main_settings['saved_cards'] ) && 'yes' === $main_settings['saved_cards'] ) ? true : false;
80
-		$this->publishable_key      = ! empty( $main_settings['publishable_key'] ) ? $main_settings['publishable_key'] : '';
81
-		$this->secret_key           = ! empty( $main_settings['secret_key'] ) ? $main_settings['secret_key'] : '';
82
-		$this->statement_descriptor = ! empty( $main_settings['statement_descriptor'] ) ? $main_settings['statement_descriptor'] : '';
83
-
84
-		if ( $this->testmode ) {
85
-			$this->publishable_key = ! empty( $main_settings['test_publishable_key'] ) ? $main_settings['test_publishable_key'] : '';
86
-			$this->secret_key      = ! empty( $main_settings['test_secret_key'] ) ? $main_settings['test_secret_key'] : '';
74
+		$main_settings              = get_option('woocommerce_stripe_settings');
75
+		$this->title                = $this->get_option('title');
76
+		$this->description          = $this->get_option('description');
77
+		$this->enabled              = $this->get_option('enabled');
78
+		$this->testmode             = ( ! empty($main_settings['testmode']) && 'yes' === $main_settings['testmode']) ? true : false;
79
+		$this->saved_cards          = ( ! empty($main_settings['saved_cards']) && 'yes' === $main_settings['saved_cards']) ? true : false;
80
+		$this->publishable_key      = ! empty($main_settings['publishable_key']) ? $main_settings['publishable_key'] : '';
81
+		$this->secret_key           = ! empty($main_settings['secret_key']) ? $main_settings['secret_key'] : '';
82
+		$this->statement_descriptor = ! empty($main_settings['statement_descriptor']) ? $main_settings['statement_descriptor'] : '';
83
+
84
+		if ($this->testmode) {
85
+			$this->publishable_key = ! empty($main_settings['test_publishable_key']) ? $main_settings['test_publishable_key'] : '';
86
+			$this->secret_key      = ! empty($main_settings['test_secret_key']) ? $main_settings['test_secret_key'] : '';
87 87
 		}
88 88
 
89
-		add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) );
90
-		add_action( 'wp_enqueue_scripts', array( $this, 'payment_scripts' ) );
89
+		add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options'));
90
+		add_action('wp_enqueue_scripts', array($this, 'payment_scripts'));
91 91
 	}
92 92
 
93 93
 	/**
@@ -98,9 +98,9 @@  discard block
 block discarded – undo
98 98
 	 * @return array
99 99
 	 */
100 100
 	public function get_supported_currency() {
101
-		return apply_filters( 'wc_stripe_bancontact_supported_currencies', array(
101
+		return apply_filters('wc_stripe_bancontact_supported_currencies', array(
102 102
 			'EUR',
103
-		) );
103
+		));
104 104
 	}
105 105
 
106 106
 	/**
@@ -111,7 +111,7 @@  discard block
 block discarded – undo
111 111
 	 * @return bool
112 112
 	 */
113 113
 	public function is_available() {
114
-		if ( ! in_array( get_woocommerce_currency(), $this->get_supported_currency() ) ) {
114
+		if ( ! in_array(get_woocommerce_currency(), $this->get_supported_currency())) {
115 115
 			return false;
116 116
 		}
117 117
 
@@ -132,7 +132,7 @@  discard block
 block discarded – undo
132 132
 
133 133
 		$icons_str .= $icons['bancontact'];
134 134
 
135
-		return apply_filters( 'woocommerce_gateway_icon', $icons_str, $this->id );
135
+		return apply_filters('woocommerce_gateway_icon', $icons_str, $this->id);
136 136
 	}
137 137
 
138 138
 	/**
@@ -143,19 +143,19 @@  discard block
 block discarded – undo
143 143
 	 * @access public
144 144
 	 */
145 145
 	public function payment_scripts() {
146
-		if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) && ! is_add_payment_method_page() ) {
146
+		if ( ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order']) && ! is_add_payment_method_page()) {
147 147
 			return;
148 148
 		}
149 149
 
150
-		wp_enqueue_style( 'stripe_styles' );
151
-		wp_enqueue_script( 'woocommerce_stripe' );
150
+		wp_enqueue_style('stripe_styles');
151
+		wp_enqueue_script('woocommerce_stripe');
152 152
 	}
153 153
 
154 154
 	/**
155 155
 	 * Initialize Gateway Settings Form Fields.
156 156
 	 */
157 157
 	public function init_form_fields() {
158
-		$this->form_fields = require( WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-bancontact-settings.php' );
158
+		$this->form_fields = require(WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-bancontact-settings.php');
159 159
 	}
160 160
 
161 161
 	/**
@@ -166,25 +166,25 @@  discard block
 block discarded – undo
166 166
 		$total = WC()->cart->total;
167 167
 
168 168
 		// If paying from order, we need to get total from order not cart.
169
-		if ( isset( $_GET['pay_for_order'] ) && ! empty( $_GET['key'] ) ) {
170
-			$order = wc_get_order( wc_get_order_id_by_order_key( wc_clean( $_GET['key'] ) ) );
169
+		if (isset($_GET['pay_for_order']) && ! empty($_GET['key'])) {
170
+			$order = wc_get_order(wc_get_order_id_by_order_key(wc_clean($_GET['key'])));
171 171
 			$total = $order->get_total();
172 172
 		}
173 173
 
174
-		if ( is_add_payment_method_page() ) {
175
-			$pay_button_text = __( 'Add Payment', 'woocommerce-gateway-stripe' );
176
-			$total        = '';
174
+		if (is_add_payment_method_page()) {
175
+			$pay_button_text = __('Add Payment', 'woocommerce-gateway-stripe');
176
+			$total = '';
177 177
 		} else {
178 178
 			$pay_button_text = '';
179 179
 		}
180 180
 
181 181
 		echo '<div
182 182
 			id="stripe-bancontact-payment-data"
183
-			data-amount="' . esc_attr( WC_Stripe_Helper::get_stripe_amount( $total ) ) . '"
184
-			data-currency="' . esc_attr( strtolower( get_woocommerce_currency() ) ) . '">';
183
+			data-amount="' . esc_attr(WC_Stripe_Helper::get_stripe_amount($total)) . '"
184
+			data-currency="' . esc_attr(strtolower(get_woocommerce_currency())) . '">';
185 185
 
186
-		if ( $this->description ) {
187
-			echo apply_filters( 'wc_stripe_description', wpautop( wp_kses_post( $this->description ) ), $this->id );
186
+		if ($this->description) {
187
+			echo apply_filters('wc_stripe_description', wpautop(wp_kses_post($this->description)), $this->id);
188 188
 		}
189 189
 
190 190
 		echo '</div>';
@@ -198,25 +198,25 @@  discard block
 block discarded – undo
198 198
 	 * @param object $order
199 199
 	 * @return mixed
200 200
 	 */
201
-	public function create_source( $order ) {
201
+	public function create_source($order) {
202 202
 		$currency                = WC_Stripe_Helper::is_pre_30() ? $order->get_order_currency() : $order->get_currency();
203 203
 		$order_id                = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
204
-		$return_url              = $this->get_stripe_return_url( $order );
204
+		$return_url              = $this->get_stripe_return_url($order);
205 205
 		$post_data               = array();
206
-		$post_data['amount']     = WC_Stripe_Helper::get_stripe_amount( $order->get_total(), $currency );
207
-		$post_data['currency']   = strtolower( $currency );
206
+		$post_data['amount']     = WC_Stripe_Helper::get_stripe_amount($order->get_total(), $currency);
207
+		$post_data['currency']   = strtolower($currency);
208 208
 		$post_data['type']       = 'bancontact';
209
-		$post_data['owner']      = $this->get_owner_details( $order );
210
-		$post_data['redirect']   = array( 'return_url' => $return_url );
211
-		$post_data['bancontact'] = array( 'preferred_language' => $this->get_locale() );
209
+		$post_data['owner']      = $this->get_owner_details($order);
210
+		$post_data['redirect']   = array('return_url' => $return_url);
211
+		$post_data['bancontact'] = array('preferred_language' => $this->get_locale());
212 212
 
213
-		if ( ! empty( $this->statement_descriptor ) ) {
214
-			$post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor( $this->statement_descriptor );
213
+		if ( ! empty($this->statement_descriptor)) {
214
+			$post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor($this->statement_descriptor);
215 215
 		}
216 216
 
217
-		WC_Stripe_Logger::log( 'Info: Begin creating Bancontact source' );
217
+		WC_Stripe_Logger::log('Info: Begin creating Bancontact source');
218 218
 
219
-		return WC_Stripe_API::request( apply_filters( 'wc_stripe_bancontact_source', $post_data, $order ), 'sources' );
219
+		return WC_Stripe_API::request(apply_filters('wc_stripe_bancontact_source', $post_data, $order), 'sources');
220 220
 	}
221 221
 
222 222
 	/**
@@ -230,51 +230,51 @@  discard block
 block discarded – undo
230 230
 	 *
231 231
 	 * @return array|void
232 232
 	 */
233
-	public function process_payment( $order_id, $retry = true, $force_save_source = false ) {
233
+	public function process_payment($order_id, $retry = true, $force_save_source = false) {
234 234
 		try {
235
-			$order = wc_get_order( $order_id );
235
+			$order = wc_get_order($order_id);
236 236
 
237 237
 			// This will throw exception if not valid.
238
-			$this->validate_minimum_order_amount( $order );
238
+			$this->validate_minimum_order_amount($order);
239 239
 
240 240
 			// This comes from the create account checkbox in the checkout page.
241
-			$create_account = ! empty( $_POST['createaccount'] ) ? true : false;
241
+			$create_account = ! empty($_POST['createaccount']) ? true : false;
242 242
 
243
-			if ( $create_account ) {
243
+			if ($create_account) {
244 244
 				$new_customer_id     = WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id();
245
-				$new_stripe_customer = new WC_Stripe_Customer( $new_customer_id );
245
+				$new_stripe_customer = new WC_Stripe_Customer($new_customer_id);
246 246
 				$new_stripe_customer->create_customer();
247 247
 			}
248 248
 
249
-			$response = $this->create_source( $order );
249
+			$response = $this->create_source($order);
250 250
 
251
-			if ( ! empty( $response->error ) ) {
252
-				$order->add_order_note( $response->error->message );
251
+			if ( ! empty($response->error)) {
252
+				$order->add_order_note($response->error->message);
253 253
 
254
-				throw new WC_Stripe_Exception( print_r( $response, true ), $response->error->message );
254
+				throw new WC_Stripe_Exception(print_r($response, true), $response->error->message);
255 255
 			}
256 256
 
257
-			if ( WC_Stripe_Helper::is_pre_30() ) {
258
-				update_post_meta( $order_id, '_stripe_source_id', $response->id );
257
+			if (WC_Stripe_Helper::is_pre_30()) {
258
+				update_post_meta($order_id, '_stripe_source_id', $response->id);
259 259
 			} else {
260
-				$order->update_meta_data( '_stripe_source_id', $response->id );
260
+				$order->update_meta_data('_stripe_source_id', $response->id);
261 261
 				$order->save();
262 262
 			}
263 263
 
264
-			WC_Stripe_Logger::log( 'Info: Redirecting to Bancontact...' );
264
+			WC_Stripe_Logger::log('Info: Redirecting to Bancontact...');
265 265
 
266 266
 			return array(
267 267
 				'result'   => 'success',
268
-				'redirect' => esc_url_raw( $response->redirect->url ),
268
+				'redirect' => esc_url_raw($response->redirect->url),
269 269
 			);
270
-		} catch ( WC_Stripe_Exception $e ) {
271
-			wc_add_notice( $e->getLocalizedMessage(), 'error' );
272
-			WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() );
270
+		} catch (WC_Stripe_Exception $e) {
271
+			wc_add_notice($e->getLocalizedMessage(), 'error');
272
+			WC_Stripe_Logger::log('Error: ' . $e->getMessage());
273 273
 
274
-			do_action( 'wc_gateway_stripe_process_payment_error', $e, $order );
274
+			do_action('wc_gateway_stripe_process_payment_error', $e, $order);
275 275
 
276
-			if ( $order->has_status( array( 'pending', 'failed' ) ) ) {
277
-				$this->send_failed_order_email( $order_id );
276
+			if ($order->has_status(array('pending', 'failed'))) {
277
+				$this->send_failed_order_email($order_id);
278 278
 			}
279 279
 
280 280
 			return array(
Please login to merge, or discard this patch.
includes/payment-methods/class-wc-gateway-stripe-sepa.php 1 patch
Spacing   +98 added lines, -98 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
 
@@ -72,9 +72,9 @@  discard block
 block discarded – undo
72 72
 	public function __construct() {
73 73
 		$this->retry_interval       = 1;
74 74
 		$this->id                   = 'stripe_sepa';
75
-		$this->method_title         = __( 'Stripe SEPA Direct Debit', 'woocommerce-gateway-stripe' );
75
+		$this->method_title         = __('Stripe SEPA Direct Debit', 'woocommerce-gateway-stripe');
76 76
 		/* translators: link */
77
-		$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' ) );
77
+		$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'));
78 78
 		$this->supports             = array(
79 79
 			'products',
80 80
 			'refunds',
@@ -99,28 +99,28 @@  discard block
 block discarded – undo
99 99
 		// Load the settings.
100 100
 		$this->init_settings();
101 101
 
102
-		$main_settings              = get_option( 'woocommerce_stripe_settings' );
103
-		$this->title                = $this->get_option( 'title' );
104
-		$this->description          = $this->get_option( 'description' );
105
-		$this->enabled              = $this->get_option( 'enabled' );
106
-		$this->testmode             = ( ! empty( $main_settings['testmode'] ) && 'yes' === $main_settings['testmode'] ) ? true : false;
107
-		$this->saved_cards          = ( ! empty( $main_settings['saved_cards'] ) && 'yes' === $main_settings['saved_cards'] ) ? true : false;
108
-		$this->publishable_key      = ! empty( $main_settings['publishable_key'] ) ? $main_settings['publishable_key'] : '';
109
-		$this->secret_key           = ! empty( $main_settings['secret_key'] ) ? $main_settings['secret_key'] : '';
110
-		$this->statement_descriptor = ! empty( $main_settings['statement_descriptor'] ) ? $main_settings['statement_descriptor'] : '';
111
-
112
-		if ( $this->testmode ) {
113
-			$this->publishable_key = ! empty( $main_settings['test_publishable_key'] ) ? $main_settings['test_publishable_key'] : '';
114
-			$this->secret_key      = ! empty( $main_settings['test_secret_key'] ) ? $main_settings['test_secret_key'] : '';
102
+		$main_settings              = get_option('woocommerce_stripe_settings');
103
+		$this->title                = $this->get_option('title');
104
+		$this->description          = $this->get_option('description');
105
+		$this->enabled              = $this->get_option('enabled');
106
+		$this->testmode             = ( ! empty($main_settings['testmode']) && 'yes' === $main_settings['testmode']) ? true : false;
107
+		$this->saved_cards          = ( ! empty($main_settings['saved_cards']) && 'yes' === $main_settings['saved_cards']) ? true : false;
108
+		$this->publishable_key      = ! empty($main_settings['publishable_key']) ? $main_settings['publishable_key'] : '';
109
+		$this->secret_key           = ! empty($main_settings['secret_key']) ? $main_settings['secret_key'] : '';
110
+		$this->statement_descriptor = ! empty($main_settings['statement_descriptor']) ? $main_settings['statement_descriptor'] : '';
111
+
112
+		if ($this->testmode) {
113
+			$this->publishable_key = ! empty($main_settings['test_publishable_key']) ? $main_settings['test_publishable_key'] : '';
114
+			$this->secret_key      = ! empty($main_settings['test_secret_key']) ? $main_settings['test_secret_key'] : '';
115 115
 		}
116 116
 
117
-		add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) );
118
-		add_action( 'wp_enqueue_scripts', array( $this, 'payment_scripts' ) );
117
+		add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options'));
118
+		add_action('wp_enqueue_scripts', array($this, 'payment_scripts'));
119 119
 
120
-		if ( WC_Stripe_Helper::is_pre_orders_exists() ) {
120
+		if (WC_Stripe_Helper::is_pre_orders_exists()) {
121 121
 			$this->pre_orders = new WC_Stripe_Pre_Orders_Compat();
122 122
 
123
-			add_action( 'wc_pre_orders_process_pre_order_completion_payment_' . $this->id, array( $this->pre_orders, 'process_pre_order_release_payment' ) );
123
+			add_action('wc_pre_orders_process_pre_order_completion_payment_' . $this->id, array($this->pre_orders, 'process_pre_order_release_payment'));
124 124
 		}
125 125
 	}
126 126
 
@@ -132,9 +132,9 @@  discard block
 block discarded – undo
132 132
 	 * @return array
133 133
 	 */
134 134
 	public function get_supported_currency() {
135
-		return apply_filters( 'wc_stripe_sepa_supported_currencies', array(
135
+		return apply_filters('wc_stripe_sepa_supported_currencies', array(
136 136
 			'EUR',
137
-		) );
137
+		));
138 138
 	}
139 139
 
140 140
 	/**
@@ -145,11 +145,11 @@  discard block
 block discarded – undo
145 145
 	 * @return bool
146 146
 	 */
147 147
 	public function is_available() {
148
-		if ( ! in_array( get_woocommerce_currency(), $this->get_supported_currency() ) ) {
148
+		if ( ! in_array(get_woocommerce_currency(), $this->get_supported_currency())) {
149 149
 			return false;
150 150
 		}
151 151
 
152
-		if ( is_add_payment_method_page() && ! $this->saved_cards ) {
152
+		if (is_add_payment_method_page() && ! $this->saved_cards) {
153 153
 			return false;
154 154
 		}
155 155
 
@@ -170,7 +170,7 @@  discard block
 block discarded – undo
170 170
 
171 171
 		$icons_str .= $icons['sepa'];
172 172
 
173
-		return apply_filters( 'woocommerce_gateway_icon', $icons_str, $this->id );
173
+		return apply_filters('woocommerce_gateway_icon', $icons_str, $this->id);
174 174
 	}
175 175
 
176 176
 	/**
@@ -181,19 +181,19 @@  discard block
 block discarded – undo
181 181
 	 * @access public
182 182
 	 */
183 183
 	public function payment_scripts() {
184
-		if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) && ! is_add_payment_method_page() ) {
184
+		if ( ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order']) && ! is_add_payment_method_page()) {
185 185
 			return;
186 186
 		}
187 187
 
188
-		wp_enqueue_style( 'stripe_styles' );
189
-		wp_enqueue_script( 'woocommerce_stripe' );
188
+		wp_enqueue_style('stripe_styles');
189
+		wp_enqueue_script('woocommerce_stripe');
190 190
 	}
191 191
 
192 192
 	/**
193 193
 	 * Initialize Gateway Settings Form Fields.
194 194
 	 */
195 195
 	public function init_form_fields() {
196
-		$this->form_fields = require( WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-sepa-settings.php' );
196
+		$this->form_fields = require(WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-sepa-settings.php');
197 197
 	}
198 198
 
199 199
 	/**
@@ -205,7 +205,7 @@  discard block
 block discarded – undo
205 205
 	 */
206 206
 	public function mandate_display() {
207 207
 		/* translators: statement descriptor */
208
-		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 ) );
208
+		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));
209 209
 	}
210 210
 
211 211
 	/**
@@ -216,24 +216,24 @@  discard block
 block discarded – undo
216 216
 	 */
217 217
 	public function form() {
218 218
 		?>
219
-		<fieldset id="wc-<?php echo esc_attr( $this->id ); ?>-form" class="wc-payment-form">
220
-			<?php do_action( 'woocommerce_credit_card_form_start', $this->id ); ?>
219
+		<fieldset id="wc-<?php echo esc_attr($this->id); ?>-form" class="wc-payment-form">
220
+			<?php do_action('woocommerce_credit_card_form_start', $this->id); ?>
221 221
 			<p class="wc-stripe-sepa-mandate" style="margin-bottom:40px;"><?php $this->mandate_display(); ?></p>
222 222
 			<p class="form-row form-row-wide">
223 223
 				<label for="stripe-sepa-owner">
224
-					<?php esc_html_e( 'IBAN Account Name.', 'woocommerce-gateway-stripe' ); ?> <span class="required">*</span>
224
+					<?php esc_html_e('IBAN Account Name.', 'woocommerce-gateway-stripe'); ?> <span class="required">*</span>
225 225
 				</label>
226 226
 				<input id="stripe-sepa-owner" name="stripe_sepa_owner" value="" style="border:1px solid #ddd;margin:5px 0;padding:10px 5px;background-color:#fff;outline:0;" />
227 227
 			</p>
228 228
 			<p class="form-row form-row-wide">
229 229
 				<label for="stripe-sepa-iban">
230
-					<?php esc_html_e( 'IBAN Account Number.', 'woocommerce-gateway-stripe' ); ?> <span class="required">*</span>
230
+					<?php esc_html_e('IBAN Account Number.', 'woocommerce-gateway-stripe'); ?> <span class="required">*</span>
231 231
 				</label>
232 232
 				<input id="stripe-sepa-iban" name="stripe_sepa_iban" value="" style="border:1px solid #ddd;margin:5px 0;padding:10px 5px;background-color:#fff;outline:0;" />
233 233
 			</p>
234 234
 			<!-- Used to display form errors -->
235 235
 			<div class="stripe-source-errors" role="alert"></div>
236
-			<?php do_action( 'woocommerce_credit_card_form_end', $this->id ); ?>
236
+			<?php do_action('woocommerce_credit_card_form_end', $this->id); ?>
237 237
 			<div class="clear"></div>
238 238
 		</fieldset>
239 239
 		<?php
@@ -245,42 +245,42 @@  discard block
 block discarded – undo
245 245
 	public function payment_fields() {
246 246
 		$user                 = wp_get_current_user();
247 247
 		$total                = WC()->cart->total;
248
-		$display_tokenization = $this->supports( 'tokenization' ) && is_checkout() && $this->saved_cards;
248
+		$display_tokenization = $this->supports('tokenization') && is_checkout() && $this->saved_cards;
249 249
 
250 250
 		// If paying from order, we need to get total from order not cart.
251
-		if ( isset( $_GET['pay_for_order'] ) && ! empty( $_GET['key'] ) ) {
252
-			$order = wc_get_order( wc_get_order_id_by_order_key( wc_clean( $_GET['key'] ) ) );
251
+		if (isset($_GET['pay_for_order']) && ! empty($_GET['key'])) {
252
+			$order = wc_get_order(wc_get_order_id_by_order_key(wc_clean($_GET['key'])));
253 253
 			$total = $order->get_total();
254 254
 		}
255 255
 
256
-		if ( is_add_payment_method_page() ) {
257
-			$pay_button_text = __( 'Add Payment', 'woocommerce-gateway-stripe' );
258
-			$total        = '';
256
+		if (is_add_payment_method_page()) {
257
+			$pay_button_text = __('Add Payment', 'woocommerce-gateway-stripe');
258
+			$total = '';
259 259
 		} else {
260 260
 			$pay_button_text = '';
261 261
 		}
262 262
 
263 263
 		echo '<div
264 264
 			id="stripe-sepa_debit-payment-data"
265
-			data-amount="' . esc_attr( WC_Stripe_Helper::get_stripe_amount( $total ) ) . '"
266
-			data-currency="' . esc_attr( strtolower( get_woocommerce_currency() ) ) . '">';
265
+			data-amount="' . esc_attr(WC_Stripe_Helper::get_stripe_amount($total)) . '"
266
+			data-currency="' . esc_attr(strtolower(get_woocommerce_currency())) . '">';
267 267
 
268
-		if ( $this->description ) {
269
-			if ( $this->testmode ) {
270
-				$this->description .= ' ' . __( 'TEST MODE ENABLED. In test mode, you can use IBAN number DE89370400440532013000.', 'woocommerce-gateway-stripe' );
271
-				$this->description  = trim( $this->description );
268
+		if ($this->description) {
269
+			if ($this->testmode) {
270
+				$this->description .= ' ' . __('TEST MODE ENABLED. In test mode, you can use IBAN number DE89370400440532013000.', 'woocommerce-gateway-stripe');
271
+				$this->description  = trim($this->description);
272 272
 			}
273
-			echo apply_filters( 'wc_stripe_description', wpautop( wp_kses_post( $this->description ) ), $this->id );
273
+			echo apply_filters('wc_stripe_description', wpautop(wp_kses_post($this->description)), $this->id);
274 274
 		}
275 275
 
276
-		if ( $display_tokenization ) {
276
+		if ($display_tokenization) {
277 277
 			$this->tokenization_script();
278 278
 			$this->saved_payment_methods();
279 279
 		}
280 280
 
281 281
 		$this->form();
282 282
 
283
-		if ( apply_filters( 'wc_stripe_display_save_payment_method_checkbox', $display_tokenization ) && ! is_add_payment_method_page() && ! isset( $_GET['change_payment_method'] ) ) {
283
+		if (apply_filters('wc_stripe_display_save_payment_method_checkbox', $display_tokenization) && ! is_add_payment_method_page() && ! isset($_GET['change_payment_method'])) {
284 284
 			$this->save_payment_method_checkbox();
285 285
 		}
286 286
 
@@ -298,99 +298,99 @@  discard block
 block discarded – undo
298 298
 	 *
299 299
 	 * @return array|void
300 300
 	 */
301
-	public function process_payment( $order_id, $retry = true, $force_save_source = false ) {
301
+	public function process_payment($order_id, $retry = true, $force_save_source = false) {
302 302
 		try {
303
-			$order = wc_get_order( $order_id );
303
+			$order = wc_get_order($order_id);
304 304
 
305
-			if ( $this->maybe_process_pre_orders( $order_id ) ) {
306
-				return $this->pre_orders->process_pre_order( $order_id );
305
+			if ($this->maybe_process_pre_orders($order_id)) {
306
+				return $this->pre_orders->process_pre_order($order_id);
307 307
 			}
308 308
 
309 309
 			// This comes from the create account checkbox in the checkout page.
310
-			$create_account = ! empty( $_POST['createaccount'] ) ? true : false;
310
+			$create_account = ! empty($_POST['createaccount']) ? true : false;
311 311
 
312
-			if ( $create_account ) {
312
+			if ($create_account) {
313 313
 				$new_customer_id     = WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id();
314
-				$new_stripe_customer = new WC_Stripe_Customer( $new_customer_id );
314
+				$new_stripe_customer = new WC_Stripe_Customer($new_customer_id);
315 315
 				$new_stripe_customer->create_customer();
316 316
 			}
317 317
 
318
-			$prepared_source = $this->prepare_source( get_current_user_id(), $force_save_source );
318
+			$prepared_source = $this->prepare_source(get_current_user_id(), $force_save_source);
319 319
 
320
-			$this->save_source_to_order( $order, $prepared_source );
320
+			$this->save_source_to_order($order, $prepared_source);
321 321
 
322 322
 			// Result from Stripe API request.
323 323
 			$response = null;
324 324
 
325
-			if ( $order->get_total() > 0 ) {
325
+			if ($order->get_total() > 0) {
326 326
 				// This will throw exception if not valid.
327
-				$this->validate_minimum_order_amount( $order );
327
+				$this->validate_minimum_order_amount($order);
328 328
 
329
-				WC_Stripe_Logger::log( "Info: Begin processing payment for order $order_id for the amount of {$order->get_total()}" );
329
+				WC_Stripe_Logger::log("Info: Begin processing payment for order $order_id for the amount of {$order->get_total()}");
330 330
 
331 331
 				// Make the request.
332
-				$response = WC_Stripe_API::request( $this->generate_payment_request( $order, $prepared_source ) );
332
+				$response = WC_Stripe_API::request($this->generate_payment_request($order, $prepared_source));
333 333
 
334
-				if ( ! empty( $response->error ) ) {
334
+				if ( ! empty($response->error)) {
335 335
 					// Customer param wrong? The user may have been deleted on stripe's end. Remove customer_id. Can be retried without.
336
-					if ( $this->is_no_such_customer_error( $response->error ) ) {
337
-						if ( WC_Stripe_Helper::is_pre_30() ) {
338
-							delete_user_meta( $order->customer_user, '_stripe_customer_id' );
339
-							delete_post_meta( $order_id, '_stripe_customer_id' );
336
+					if ($this->is_no_such_customer_error($response->error)) {
337
+						if (WC_Stripe_Helper::is_pre_30()) {
338
+							delete_user_meta($order->customer_user, '_stripe_customer_id');
339
+							delete_post_meta($order_id, '_stripe_customer_id');
340 340
 						} else {
341
-							delete_user_meta( $order->get_customer_id(), '_stripe_customer_id' );
342
-							$order->delete_meta_data( '_stripe_customer_id' );
341
+							delete_user_meta($order->get_customer_id(), '_stripe_customer_id');
342
+							$order->delete_meta_data('_stripe_customer_id');
343 343
 							$order->save();
344 344
 						}
345 345
 					}
346 346
 
347
-					if ( $this->is_no_such_token_error( $response->error ) && $prepared_source->token_id ) {
347
+					if ($this->is_no_such_token_error($response->error) && $prepared_source->token_id) {
348 348
 						// Source param wrong? The CARD may have been deleted on stripe's end. Remove token and show message.
349
-						$wc_token = WC_Payment_Tokens::get( $prepared_source->token_id );
349
+						$wc_token = WC_Payment_Tokens::get($prepared_source->token_id);
350 350
 						$wc_token->delete();
351
-						$localized_message = __( 'This card is no longer available and has been removed.', 'woocommerce-gateway-stripe' );
352
-						$order->add_order_note( $localized_message );
353
-						throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message );
351
+						$localized_message = __('This card is no longer available and has been removed.', 'woocommerce-gateway-stripe');
352
+						$order->add_order_note($localized_message);
353
+						throw new WC_Stripe_Exception(print_r($response, true), $localized_message);
354 354
 					}
355 355
 
356 356
 					// We want to retry.
357
-					if ( $this->is_retryable_error( $response->error ) ) {
358
-						if ( $retry ) {
357
+					if ($this->is_retryable_error($response->error)) {
358
+						if ($retry) {
359 359
 							// Don't do anymore retries after this.
360
-							if ( 5 <= $this->retry_interval ) {
360
+							if (5 <= $this->retry_interval) {
361 361
 
362
-								return $this->process_payment( $order_id, false, $force_save_source );
362
+								return $this->process_payment($order_id, false, $force_save_source);
363 363
 							}
364 364
 
365
-							sleep( $this->retry_interval );
365
+							sleep($this->retry_interval);
366 366
 
367 367
 							$this->retry_interval++;
368 368
 
369
-							return $this->process_payment( $order_id, true, $force_save_source );
369
+							return $this->process_payment($order_id, true, $force_save_source);
370 370
 						} else {
371
-							$localized_message = __( 'Sorry, we are unable to process your payment at this time. Please retry later.', 'woocommerce-gateway-stripe' );
372
-							$order->add_order_note( $localized_message );
373
-							throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message );
371
+							$localized_message = __('Sorry, we are unable to process your payment at this time. Please retry later.', 'woocommerce-gateway-stripe');
372
+							$order->add_order_note($localized_message);
373
+							throw new WC_Stripe_Exception(print_r($response, true), $localized_message);
374 374
 						}
375 375
 					}
376 376
 
377 377
 					$localized_messages = WC_Stripe_Helper::get_localized_messages();
378 378
 
379
-					if ( 'card_error' === $response->error->type ) {
380
-						$localized_message = isset( $localized_messages[ $response->error->code ] ) ? $localized_messages[ $response->error->code ] : $response->error->message;
379
+					if ('card_error' === $response->error->type) {
380
+						$localized_message = isset($localized_messages[$response->error->code]) ? $localized_messages[$response->error->code] : $response->error->message;
381 381
 					} else {
382
-						$localized_message = isset( $localized_messages[ $response->error->type ] ) ? $localized_messages[ $response->error->type ] : $response->error->message;
382
+						$localized_message = isset($localized_messages[$response->error->type]) ? $localized_messages[$response->error->type] : $response->error->message;
383 383
 					}
384 384
 
385
-					$order->add_order_note( $localized_message );
385
+					$order->add_order_note($localized_message);
386 386
 
387
-					throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message );
387
+					throw new WC_Stripe_Exception(print_r($response, true), $localized_message);
388 388
 				}
389 389
 
390
-				do_action( 'wc_gateway_stripe_process_payment', $response, $order );
390
+				do_action('wc_gateway_stripe_process_payment', $response, $order);
391 391
 
392 392
 				// Process valid response.
393
-				$this->process_response( $response, $order );
393
+				$this->process_response($response, $order);
394 394
 			} else {
395 395
 				$order->payment_complete();
396 396
 			}
@@ -401,17 +401,17 @@  discard block
 block discarded – undo
401 401
 			// Return thank you page redirect.
402 402
 			return array(
403 403
 				'result'   => 'success',
404
-				'redirect' => $this->get_return_url( $order ),
404
+				'redirect' => $this->get_return_url($order),
405 405
 			);
406 406
 
407
-		} catch ( WC_Stripe_Exception $e ) {
408
-			wc_add_notice( $e->getLocalizedMessage(), 'error' );
409
-			WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() );
407
+		} catch (WC_Stripe_Exception $e) {
408
+			wc_add_notice($e->getLocalizedMessage(), 'error');
409
+			WC_Stripe_Logger::log('Error: ' . $e->getMessage());
410 410
 
411
-			do_action( 'wc_gateway_stripe_process_payment_error', $e, $order );
411
+			do_action('wc_gateway_stripe_process_payment_error', $e, $order);
412 412
 
413
-			if ( $order->has_status( array( 'pending', 'failed' ) ) ) {
414
-				$this->send_failed_order_email( $order_id );
413
+			if ($order->has_status(array('pending', 'failed'))) {
414
+				$this->send_failed_order_email($order_id);
415 415
 			}
416 416
 
417 417
 			return array(
Please login to merge, or discard this patch.
includes/payment-methods/class-wc-gateway-stripe-giropay.php 1 patch
Spacing   +66 added lines, -66 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_giropay';
60
-		$this->method_title         = __( 'Stripe Giropay', 'woocommerce-gateway-stripe' );
60
+		$this->method_title         = __('Stripe Giropay', 'woocommerce-gateway-stripe');
61 61
 		/* translators: link */
62
-		$this->method_description   = sprintf( __( 'All other general Stripe settings can be adjusted <a href="%s">here</a>.', 'woocommerce-gateway-stripe' ), admin_url( 'admin.php?page=wc-settings&tab=checkout&section=stripe' ) );
62
+		$this->method_description   = sprintf(__('All other general Stripe settings can be adjusted <a href="%s">here</a>.', 'woocommerce-gateway-stripe'), admin_url('admin.php?page=wc-settings&tab=checkout&section=stripe'));
63 63
 		$this->supports             = array(
64 64
 			'products',
65 65
 			'refunds',
@@ -71,23 +71,23 @@  discard block
 block discarded – undo
71 71
 		// Load the settings.
72 72
 		$this->init_settings();
73 73
 
74
-		$main_settings              = get_option( 'woocommerce_stripe_settings' );
75
-		$this->title                = $this->get_option( 'title' );
76
-		$this->description          = $this->get_option( 'description' );
77
-		$this->enabled              = $this->get_option( 'enabled' );
78
-		$this->testmode             = ( ! empty( $main_settings['testmode'] ) && 'yes' === $main_settings['testmode'] ) ? true : false;
79
-		$this->saved_cards          = ( ! empty( $main_settings['saved_cards'] ) && 'yes' === $main_settings['saved_cards'] ) ? true : false;
80
-		$this->publishable_key      = ! empty( $main_settings['publishable_key'] ) ? $main_settings['publishable_key'] : '';
81
-		$this->secret_key           = ! empty( $main_settings['secret_key'] ) ? $main_settings['secret_key'] : '';
82
-		$this->statement_descriptor = ! empty( $main_settings['statement_descriptor'] ) ? $main_settings['statement_descriptor'] : '';
83
-
84
-		if ( $this->testmode ) {
85
-			$this->publishable_key = ! empty( $main_settings['test_publishable_key'] ) ? $main_settings['test_publishable_key'] : '';
86
-			$this->secret_key      = ! empty( $main_settings['test_secret_key'] ) ? $main_settings['test_secret_key'] : '';
74
+		$main_settings              = get_option('woocommerce_stripe_settings');
75
+		$this->title                = $this->get_option('title');
76
+		$this->description          = $this->get_option('description');
77
+		$this->enabled              = $this->get_option('enabled');
78
+		$this->testmode             = ( ! empty($main_settings['testmode']) && 'yes' === $main_settings['testmode']) ? true : false;
79
+		$this->saved_cards          = ( ! empty($main_settings['saved_cards']) && 'yes' === $main_settings['saved_cards']) ? true : false;
80
+		$this->publishable_key      = ! empty($main_settings['publishable_key']) ? $main_settings['publishable_key'] : '';
81
+		$this->secret_key           = ! empty($main_settings['secret_key']) ? $main_settings['secret_key'] : '';
82
+		$this->statement_descriptor = ! empty($main_settings['statement_descriptor']) ? $main_settings['statement_descriptor'] : '';
83
+
84
+		if ($this->testmode) {
85
+			$this->publishable_key = ! empty($main_settings['test_publishable_key']) ? $main_settings['test_publishable_key'] : '';
86
+			$this->secret_key      = ! empty($main_settings['test_secret_key']) ? $main_settings['test_secret_key'] : '';
87 87
 		}
88 88
 
89
-		add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) );
90
-		add_action( 'wp_enqueue_scripts', array( $this, 'payment_scripts' ) );
89
+		add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options'));
90
+		add_action('wp_enqueue_scripts', array($this, 'payment_scripts'));
91 91
 	}
92 92
 
93 93
 	/**
@@ -98,9 +98,9 @@  discard block
 block discarded – undo
98 98
 	 * @return array
99 99
 	 */
100 100
 	public function get_supported_currency() {
101
-		return apply_filters( 'wc_stripe_giropay_supported_currencies', array(
101
+		return apply_filters('wc_stripe_giropay_supported_currencies', array(
102 102
 			'EUR',
103
-		) );
103
+		));
104 104
 	}
105 105
 
106 106
 	/**
@@ -111,7 +111,7 @@  discard block
 block discarded – undo
111 111
 	 * @return bool
112 112
 	 */
113 113
 	public function is_available() {
114
-		if ( ! in_array( get_woocommerce_currency(), $this->get_supported_currency() ) ) {
114
+		if ( ! in_array(get_woocommerce_currency(), $this->get_supported_currency())) {
115 115
 			return false;
116 116
 		}
117 117
 
@@ -132,7 +132,7 @@  discard block
 block discarded – undo
132 132
 
133 133
 		$icons_str .= $icons['giropay'];
134 134
 
135
-		return apply_filters( 'woocommerce_gateway_icon', $icons_str, $this->id );
135
+		return apply_filters('woocommerce_gateway_icon', $icons_str, $this->id);
136 136
 	}
137 137
 
138 138
 	/**
@@ -143,19 +143,19 @@  discard block
 block discarded – undo
143 143
 	 * @access public
144 144
 	 */
145 145
 	public function payment_scripts() {
146
-		if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) && ! is_add_payment_method_page() ) {
146
+		if ( ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order']) && ! is_add_payment_method_page()) {
147 147
 			return;
148 148
 		}
149 149
 
150
-		wp_enqueue_style( 'stripe_styles' );
151
-		wp_enqueue_script( 'woocommerce_stripe' );
150
+		wp_enqueue_style('stripe_styles');
151
+		wp_enqueue_script('woocommerce_stripe');
152 152
 	}
153 153
 
154 154
 	/**
155 155
 	 * Initialize Gateway Settings Form Fields.
156 156
 	 */
157 157
 	public function init_form_fields() {
158
-		$this->form_fields = require( WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-giropay-settings.php' );
158
+		$this->form_fields = require(WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-giropay-settings.php');
159 159
 	}
160 160
 
161 161
 	/**
@@ -166,25 +166,25 @@  discard block
 block discarded – undo
166 166
 		$total = WC()->cart->total;
167 167
 
168 168
 		// If paying from order, we need to get total from order not cart.
169
-		if ( isset( $_GET['pay_for_order'] ) && ! empty( $_GET['key'] ) ) {
170
-			$order = wc_get_order( wc_get_order_id_by_order_key( wc_clean( $_GET['key'] ) ) );
169
+		if (isset($_GET['pay_for_order']) && ! empty($_GET['key'])) {
170
+			$order = wc_get_order(wc_get_order_id_by_order_key(wc_clean($_GET['key'])));
171 171
 			$total = $order->get_total();
172 172
 		}
173 173
 
174
-		if ( is_add_payment_method_page() ) {
175
-			$pay_button_text = __( 'Add Payment', 'woocommerce-gateway-stripe' );
176
-			$total        = '';
174
+		if (is_add_payment_method_page()) {
175
+			$pay_button_text = __('Add Payment', 'woocommerce-gateway-stripe');
176
+			$total = '';
177 177
 		} else {
178 178
 			$pay_button_text = '';
179 179
 		}
180 180
 
181 181
 		echo '<div
182 182
 			id="stripe-giropay-payment-data"
183
-			data-amount="' . esc_attr( WC_Stripe_Helper::get_stripe_amount( $total ) ) . '"
184
-			data-currency="' . esc_attr( strtolower( get_woocommerce_currency() ) ) . '">';
183
+			data-amount="' . esc_attr(WC_Stripe_Helper::get_stripe_amount($total)) . '"
184
+			data-currency="' . esc_attr(strtolower(get_woocommerce_currency())) . '">';
185 185
 
186
-		if ( $this->description ) {
187
-			echo apply_filters( 'wc_stripe_description', wpautop( wp_kses_post( $this->description ) ), $this->id );
186
+		if ($this->description) {
187
+			echo apply_filters('wc_stripe_description', wpautop(wp_kses_post($this->description)), $this->id);
188 188
 		}
189 189
 
190 190
 		echo '</div>';
@@ -198,24 +198,24 @@  discard block
 block discarded – undo
198 198
 	 * @param object $order
199 199
 	 * @return mixed
200 200
 	 */
201
-	public function create_source( $order ) {
201
+	public function create_source($order) {
202 202
 		$currency              = WC_Stripe_Helper::is_pre_30() ? $order->get_order_currency() : $order->get_currency();
203 203
 		$order_id              = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
204
-		$return_url            = $this->get_stripe_return_url( $order );
204
+		$return_url            = $this->get_stripe_return_url($order);
205 205
 		$post_data             = array();
206
-		$post_data['amount']   = WC_Stripe_Helper::get_stripe_amount( $order->get_total(), $currency );
207
-		$post_data['currency'] = strtolower( $currency );
206
+		$post_data['amount']   = WC_Stripe_Helper::get_stripe_amount($order->get_total(), $currency);
207
+		$post_data['currency'] = strtolower($currency);
208 208
 		$post_data['type']     = 'giropay';
209
-		$post_data['owner']    = $this->get_owner_details( $order );
210
-		$post_data['redirect'] = array( 'return_url' => $return_url );
209
+		$post_data['owner']    = $this->get_owner_details($order);
210
+		$post_data['redirect'] = array('return_url' => $return_url);
211 211
 
212
-		if ( ! empty( $this->statement_descriptor ) ) {
213
-			$post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor( $this->statement_descriptor );
212
+		if ( ! empty($this->statement_descriptor)) {
213
+			$post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor($this->statement_descriptor);
214 214
 		}
215 215
 
216
-		WC_Stripe_Logger::log( 'Info: Begin creating Giropay source' );
216
+		WC_Stripe_Logger::log('Info: Begin creating Giropay source');
217 217
 
218
-		return WC_Stripe_API::request( apply_filters( 'wc_stripe_giropay_source', $post_data, $order ), 'sources' );
218
+		return WC_Stripe_API::request(apply_filters('wc_stripe_giropay_source', $post_data, $order), 'sources');
219 219
 	}
220 220
 
221 221
 	/**
@@ -229,51 +229,51 @@  discard block
 block discarded – undo
229 229
 	 *
230 230
 	 * @return array|void
231 231
 	 */
232
-	public function process_payment( $order_id, $retry = true, $force_save_source = false ) {
232
+	public function process_payment($order_id, $retry = true, $force_save_source = false) {
233 233
 		try {
234
-			$order = wc_get_order( $order_id );
234
+			$order = wc_get_order($order_id);
235 235
 
236 236
 			// This will throw exception if not valid.
237
-			$this->validate_minimum_order_amount( $order );
237
+			$this->validate_minimum_order_amount($order);
238 238
 
239 239
 			// This comes from the create account checkbox in the checkout page.
240
-			$create_account = ! empty( $_POST['createaccount'] ) ? true : false;
240
+			$create_account = ! empty($_POST['createaccount']) ? true : false;
241 241
 
242
-			if ( $create_account ) {
242
+			if ($create_account) {
243 243
 				$new_customer_id     = WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id();
244
-				$new_stripe_customer = new WC_Stripe_Customer( $new_customer_id );
244
+				$new_stripe_customer = new WC_Stripe_Customer($new_customer_id);
245 245
 				$new_stripe_customer->create_customer();
246 246
 			}
247 247
 
248
-			$response = $this->create_source( $order );
248
+			$response = $this->create_source($order);
249 249
 
250
-			if ( ! empty( $response->error ) ) {
251
-				$order->add_order_note( $response->error->message );
250
+			if ( ! empty($response->error)) {
251
+				$order->add_order_note($response->error->message);
252 252
 
253
-				throw new WC_Stripe_Exception( print_r( $response, true ), $response->error->message );
253
+				throw new WC_Stripe_Exception(print_r($response, true), $response->error->message);
254 254
 			}
255 255
 
256
-			if ( WC_Stripe_Helper::is_pre_30() ) {
257
-				update_post_meta( $order_id, '_stripe_source_id', $response->id );
256
+			if (WC_Stripe_Helper::is_pre_30()) {
257
+				update_post_meta($order_id, '_stripe_source_id', $response->id);
258 258
 			} else {
259
-				$order->update_meta_data( '_stripe_source_id', $response->id );
259
+				$order->update_meta_data('_stripe_source_id', $response->id);
260 260
 				$order->save();
261 261
 			}
262 262
 
263
-			WC_Stripe_Logger::log( 'Info: Redirecting to Giropay...' );
263
+			WC_Stripe_Logger::log('Info: Redirecting to Giropay...');
264 264
 
265 265
 			return array(
266 266
 				'result'   => 'success',
267
-				'redirect' => esc_url_raw( $response->redirect->url ),
267
+				'redirect' => esc_url_raw($response->redirect->url),
268 268
 			);
269
-		} catch ( WC_Stripe_Exception $e ) {
270
-			wc_add_notice( $e->getLocalizedMessage(), 'error' );
271
-			WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() );
269
+		} catch (WC_Stripe_Exception $e) {
270
+			wc_add_notice($e->getLocalizedMessage(), 'error');
271
+			WC_Stripe_Logger::log('Error: ' . $e->getMessage());
272 272
 
273
-			do_action( 'wc_gateway_stripe_process_payment_error', $e, $order );
273
+			do_action('wc_gateway_stripe_process_payment_error', $e, $order);
274 274
 
275
-			if ( $order->has_status( array( 'pending', 'failed' ) ) ) {
276
-				$this->send_failed_order_email( $order_id );
275
+			if ($order->has_status(array('pending', 'failed'))) {
276
+				$this->send_failed_order_email($order_id);
277 277
 			}
278 278
 
279 279
 			return array(
Please login to merge, or discard this patch.
includes/payment-methods/class-wc-gateway-stripe-ideal.php 1 patch
Spacing   +66 added lines, -66 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_ideal';
60
-		$this->method_title         = __( 'Stripe iDeal', 'woocommerce-gateway-stripe' );
60
+		$this->method_title         = __('Stripe iDeal', 'woocommerce-gateway-stripe');
61 61
 		/* translators: link */
62
-		$this->method_description   = sprintf( __( 'All other general Stripe settings can be adjusted <a href="%s">here</a>.', 'woocommerce-gateway-stripe' ), admin_url( 'admin.php?page=wc-settings&tab=checkout&section=stripe' ) );
62
+		$this->method_description   = sprintf(__('All other general Stripe settings can be adjusted <a href="%s">here</a>.', 'woocommerce-gateway-stripe'), admin_url('admin.php?page=wc-settings&tab=checkout&section=stripe'));
63 63
 		$this->supports             = array(
64 64
 			'products',
65 65
 			'refunds',
@@ -71,23 +71,23 @@  discard block
 block discarded – undo
71 71
 		// Load the settings.
72 72
 		$this->init_settings();
73 73
 
74
-		$main_settings              = get_option( 'woocommerce_stripe_settings' );
75
-		$this->title                = $this->get_option( 'title' );
76
-		$this->description          = $this->get_option( 'description' );
77
-		$this->enabled              = $this->get_option( 'enabled' );
78
-		$this->testmode             = ( ! empty( $main_settings['testmode'] ) && 'yes' === $main_settings['testmode'] ) ? true : false;
79
-		$this->saved_cards          = ( ! empty( $main_settings['saved_cards'] ) && 'yes' === $main_settings['saved_cards'] ) ? true : false;
80
-		$this->publishable_key      = ! empty( $main_settings['publishable_key'] ) ? $main_settings['publishable_key'] : '';
81
-		$this->secret_key           = ! empty( $main_settings['secret_key'] ) ? $main_settings['secret_key'] : '';
82
-		$this->statement_descriptor = ! empty( $main_settings['statement_descriptor'] ) ? $main_settings['statement_descriptor'] : '';
83
-
84
-		if ( $this->testmode ) {
85
-			$this->publishable_key = ! empty( $main_settings['test_publishable_key'] ) ? $main_settings['test_publishable_key'] : '';
86
-			$this->secret_key      = ! empty( $main_settings['test_secret_key'] ) ? $main_settings['test_secret_key'] : '';
74
+		$main_settings              = get_option('woocommerce_stripe_settings');
75
+		$this->title                = $this->get_option('title');
76
+		$this->description          = $this->get_option('description');
77
+		$this->enabled              = $this->get_option('enabled');
78
+		$this->testmode             = ( ! empty($main_settings['testmode']) && 'yes' === $main_settings['testmode']) ? true : false;
79
+		$this->saved_cards          = ( ! empty($main_settings['saved_cards']) && 'yes' === $main_settings['saved_cards']) ? true : false;
80
+		$this->publishable_key      = ! empty($main_settings['publishable_key']) ? $main_settings['publishable_key'] : '';
81
+		$this->secret_key           = ! empty($main_settings['secret_key']) ? $main_settings['secret_key'] : '';
82
+		$this->statement_descriptor = ! empty($main_settings['statement_descriptor']) ? $main_settings['statement_descriptor'] : '';
83
+
84
+		if ($this->testmode) {
85
+			$this->publishable_key = ! empty($main_settings['test_publishable_key']) ? $main_settings['test_publishable_key'] : '';
86
+			$this->secret_key      = ! empty($main_settings['test_secret_key']) ? $main_settings['test_secret_key'] : '';
87 87
 		}
88 88
 
89
-		add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) );
90
-		add_action( 'wp_enqueue_scripts', array( $this, 'payment_scripts' ) );
89
+		add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options'));
90
+		add_action('wp_enqueue_scripts', array($this, 'payment_scripts'));
91 91
 	}
92 92
 
93 93
 	/**
@@ -98,9 +98,9 @@  discard block
 block discarded – undo
98 98
 	 * @return array
99 99
 	 */
100 100
 	public function get_supported_currency() {
101
-		return apply_filters( 'wc_stripe_ideal_supported_currencies', array(
101
+		return apply_filters('wc_stripe_ideal_supported_currencies', array(
102 102
 			'EUR',
103
-		) );
103
+		));
104 104
 	}
105 105
 
106 106
 	/**
@@ -111,7 +111,7 @@  discard block
 block discarded – undo
111 111
 	 * @return bool
112 112
 	 */
113 113
 	public function is_available() {
114
-		if ( ! in_array( get_woocommerce_currency(), $this->get_supported_currency() ) ) {
114
+		if ( ! in_array(get_woocommerce_currency(), $this->get_supported_currency())) {
115 115
 			return false;
116 116
 		}
117 117
 
@@ -132,7 +132,7 @@  discard block
 block discarded – undo
132 132
 
133 133
 		$icons_str .= $icons['ideal'];
134 134
 
135
-		return apply_filters( 'woocommerce_gateway_icon', $icons_str, $this->id );
135
+		return apply_filters('woocommerce_gateway_icon', $icons_str, $this->id);
136 136
 	}
137 137
 
138 138
 	/**
@@ -143,19 +143,19 @@  discard block
 block discarded – undo
143 143
 	 * @access public
144 144
 	 */
145 145
 	public function payment_scripts() {
146
-		if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) && ! is_add_payment_method_page() ) {
146
+		if ( ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order']) && ! is_add_payment_method_page()) {
147 147
 			return;
148 148
 		}
149 149
 
150
-		wp_enqueue_style( 'stripe_styles' );
151
-		wp_enqueue_script( 'woocommerce_stripe' );
150
+		wp_enqueue_style('stripe_styles');
151
+		wp_enqueue_script('woocommerce_stripe');
152 152
 	}
153 153
 
154 154
 	/**
155 155
 	 * Initialize Gateway Settings Form Fields.
156 156
 	 */
157 157
 	public function init_form_fields() {
158
-		$this->form_fields = require( WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-ideal-settings.php' );
158
+		$this->form_fields = require(WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-ideal-settings.php');
159 159
 	}
160 160
 
161 161
 	/**
@@ -166,25 +166,25 @@  discard block
 block discarded – undo
166 166
 		$total = WC()->cart->total;
167 167
 
168 168
 		// If paying from order, we need to get total from order not cart.
169
-		if ( isset( $_GET['pay_for_order'] ) && ! empty( $_GET['key'] ) ) {
170
-			$order = wc_get_order( wc_get_order_id_by_order_key( wc_clean( $_GET['key'] ) ) );
169
+		if (isset($_GET['pay_for_order']) && ! empty($_GET['key'])) {
170
+			$order = wc_get_order(wc_get_order_id_by_order_key(wc_clean($_GET['key'])));
171 171
 			$total = $order->get_total();
172 172
 		}
173 173
 
174
-		if ( is_add_payment_method_page() ) {
175
-			$pay_button_text = __( 'Add Payment', 'woocommerce-gateway-stripe' );
176
-			$total        = '';
174
+		if (is_add_payment_method_page()) {
175
+			$pay_button_text = __('Add Payment', 'woocommerce-gateway-stripe');
176
+			$total = '';
177 177
 		} else {
178 178
 			$pay_button_text = '';
179 179
 		}
180 180
 
181 181
 		echo '<div
182 182
 			id="stripe-ideal-payment-data"
183
-			data-amount="' . esc_attr( WC_Stripe_Helper::get_stripe_amount( $total ) ) . '"
184
-			data-currency="' . esc_attr( strtolower( get_woocommerce_currency() ) ) . '">';
183
+			data-amount="' . esc_attr(WC_Stripe_Helper::get_stripe_amount($total)) . '"
184
+			data-currency="' . esc_attr(strtolower(get_woocommerce_currency())) . '">';
185 185
 
186
-		if ( $this->description ) {
187
-			echo apply_filters( 'wc_stripe_description', wpautop( wp_kses_post( $this->description ) ), $this->id );
186
+		if ($this->description) {
187
+			echo apply_filters('wc_stripe_description', wpautop(wp_kses_post($this->description)), $this->id);
188 188
 		}
189 189
 
190 190
 		echo '</div>';
@@ -198,24 +198,24 @@  discard block
 block discarded – undo
198 198
 	 * @param object $order
199 199
 	 * @return mixed
200 200
 	 */
201
-	public function create_source( $order ) {
201
+	public function create_source($order) {
202 202
 		$currency              = WC_Stripe_Helper::is_pre_30() ? $order->get_order_currency() : $order->get_currency();
203 203
 		$order_id              = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
204
-		$return_url            = $this->get_stripe_return_url( $order );
204
+		$return_url            = $this->get_stripe_return_url($order);
205 205
 		$post_data             = array();
206
-		$post_data['amount']   = WC_Stripe_Helper::get_stripe_amount( $order->get_total(), $currency );
207
-		$post_data['currency'] = strtolower( $currency );
206
+		$post_data['amount']   = WC_Stripe_Helper::get_stripe_amount($order->get_total(), $currency);
207
+		$post_data['currency'] = strtolower($currency);
208 208
 		$post_data['type']     = 'ideal';
209
-		$post_data['owner']    = $this->get_owner_details( $order );
210
-		$post_data['redirect'] = array( 'return_url' => $return_url );
209
+		$post_data['owner']    = $this->get_owner_details($order);
210
+		$post_data['redirect'] = array('return_url' => $return_url);
211 211
 
212
-		if ( ! empty( $this->statement_descriptor ) ) {
213
-			$post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor( $this->statement_descriptor );
212
+		if ( ! empty($this->statement_descriptor)) {
213
+			$post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor($this->statement_descriptor);
214 214
 		}
215 215
 
216
-		WC_Stripe_Logger::log( 'Info: Begin creating iDeal source' );
216
+		WC_Stripe_Logger::log('Info: Begin creating iDeal source');
217 217
 
218
-		return WC_Stripe_API::request( apply_filters( 'wc_stripe_ideal_source', $post_data, $order ), 'sources' );
218
+		return WC_Stripe_API::request(apply_filters('wc_stripe_ideal_source', $post_data, $order), 'sources');
219 219
 	}
220 220
 
221 221
 	/**
@@ -229,51 +229,51 @@  discard block
 block discarded – undo
229 229
 	 *
230 230
 	 * @return array|void
231 231
 	 */
232
-	public function process_payment( $order_id, $retry = true, $force_save_source = false ) {
232
+	public function process_payment($order_id, $retry = true, $force_save_source = false) {
233 233
 		try {
234
-			$order = wc_get_order( $order_id );
234
+			$order = wc_get_order($order_id);
235 235
 
236 236
 			// This will throw exception if not valid.
237
-			$this->validate_minimum_order_amount( $order );
237
+			$this->validate_minimum_order_amount($order);
238 238
 
239 239
 			// This comes from the create account checkbox in the checkout page.
240
-			$create_account = ! empty( $_POST['createaccount'] ) ? true : false;
240
+			$create_account = ! empty($_POST['createaccount']) ? true : false;
241 241
 
242
-			if ( $create_account ) {
242
+			if ($create_account) {
243 243
 				$new_customer_id     = WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id();
244
-				$new_stripe_customer = new WC_Stripe_Customer( $new_customer_id );
244
+				$new_stripe_customer = new WC_Stripe_Customer($new_customer_id);
245 245
 				$new_stripe_customer->create_customer();
246 246
 			}
247 247
 
248
-			$response = $this->create_source( $order );
248
+			$response = $this->create_source($order);
249 249
 
250
-			if ( ! empty( $response->error ) ) {
251
-				$order->add_order_note( $response->error->message );
250
+			if ( ! empty($response->error)) {
251
+				$order->add_order_note($response->error->message);
252 252
 
253
-				throw new WC_Stripe_Exception( print_r( $response, true ), $response->error->message );
253
+				throw new WC_Stripe_Exception(print_r($response, true), $response->error->message);
254 254
 			}
255 255
 
256
-			if ( WC_Stripe_Helper::is_pre_30() ) {
257
-				update_post_meta( $order_id, '_stripe_source_id', $response->id );
256
+			if (WC_Stripe_Helper::is_pre_30()) {
257
+				update_post_meta($order_id, '_stripe_source_id', $response->id);
258 258
 			} else {
259
-				$order->update_meta_data( '_stripe_source_id', $response->id );
259
+				$order->update_meta_data('_stripe_source_id', $response->id);
260 260
 				$order->save();
261 261
 			}
262 262
 
263
-			WC_Stripe_Logger::log( 'Info: Redirecting to iDeal...' );
263
+			WC_Stripe_Logger::log('Info: Redirecting to iDeal...');
264 264
 
265 265
 			return array(
266 266
 				'result'   => 'success',
267
-				'redirect' => esc_url_raw( $response->redirect->url ),
267
+				'redirect' => esc_url_raw($response->redirect->url),
268 268
 			);
269
-		} catch ( WC_Stripe_Exception $e ) {
270
-			wc_add_notice( $e->getLocalizedMessage(), 'error' );
271
-			WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() );
269
+		} catch (WC_Stripe_Exception $e) {
270
+			wc_add_notice($e->getLocalizedMessage(), 'error');
271
+			WC_Stripe_Logger::log('Error: ' . $e->getMessage());
272 272
 
273
-			do_action( 'wc_gateway_stripe_process_payment_error', $e, $order );
273
+			do_action('wc_gateway_stripe_process_payment_error', $e, $order);
274 274
 
275
-			if ( $order->has_status( array( 'pending', 'failed' ) ) ) {
276
-				$this->send_failed_order_email( $order_id );
275
+			if ($order->has_status(array('pending', 'failed'))) {
276
+				$this->send_failed_order_email($order_id);
277 277
 			}
278 278
 
279 279
 			return array(
Please login to merge, or discard this patch.
includes/payment-methods/class-wc-gateway-stripe-multibanco.php 1 patch
Spacing   +90 added lines, -90 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_multibanco';
60
-		$this->method_title         = __( 'Stripe Multibanco', 'woocommerce-gateway-stripe' );
60
+		$this->method_title         = __('Stripe Multibanco', 'woocommerce-gateway-stripe');
61 61
 		/* translators: link */
62
-		$this->method_description   = sprintf( __( 'All other general Stripe settings can be adjusted <a href="%s">here</a>.', 'woocommerce-gateway-stripe' ), admin_url( 'admin.php?page=wc-settings&tab=checkout&section=stripe' ) );
62
+		$this->method_description   = sprintf(__('All other general Stripe settings can be adjusted <a href="%s">here</a>.', 'woocommerce-gateway-stripe'), admin_url('admin.php?page=wc-settings&tab=checkout&section=stripe'));
63 63
 		$this->supports             = array(
64 64
 			'products',
65 65
 			'refunds',
@@ -71,27 +71,27 @@  discard block
 block discarded – undo
71 71
 		// Load the settings.
72 72
 		$this->init_settings();
73 73
 
74
-		$main_settings              = get_option( 'woocommerce_stripe_settings' );
75
-		$this->title                = $this->get_option( 'title' );
76
-		$this->description          = $this->get_option( 'description' );
77
-		$this->enabled              = $this->get_option( 'enabled' );
78
-		$this->testmode             = ( ! empty( $main_settings['testmode'] ) && 'yes' === $main_settings['testmode'] ) ? true : false;
79
-		$this->saved_cards          = ( ! empty( $main_settings['saved_cards'] ) && 'yes' === $main_settings['saved_cards'] ) ? true : false;
80
-		$this->publishable_key      = ! empty( $main_settings['publishable_key'] ) ? $main_settings['publishable_key'] : '';
81
-		$this->secret_key           = ! empty( $main_settings['secret_key'] ) ? $main_settings['secret_key'] : '';
82
-		$this->statement_descriptor = ! empty( $main_settings['statement_descriptor'] ) ? $main_settings['statement_descriptor'] : '';
83
-
84
-		if ( $this->testmode ) {
85
-			$this->publishable_key = ! empty( $main_settings['test_publishable_key'] ) ? $main_settings['test_publishable_key'] : '';
86
-			$this->secret_key      = ! empty( $main_settings['test_secret_key'] ) ? $main_settings['test_secret_key'] : '';
74
+		$main_settings              = get_option('woocommerce_stripe_settings');
75
+		$this->title                = $this->get_option('title');
76
+		$this->description          = $this->get_option('description');
77
+		$this->enabled              = $this->get_option('enabled');
78
+		$this->testmode             = ( ! empty($main_settings['testmode']) && 'yes' === $main_settings['testmode']) ? true : false;
79
+		$this->saved_cards          = ( ! empty($main_settings['saved_cards']) && 'yes' === $main_settings['saved_cards']) ? true : false;
80
+		$this->publishable_key      = ! empty($main_settings['publishable_key']) ? $main_settings['publishable_key'] : '';
81
+		$this->secret_key           = ! empty($main_settings['secret_key']) ? $main_settings['secret_key'] : '';
82
+		$this->statement_descriptor = ! empty($main_settings['statement_descriptor']) ? $main_settings['statement_descriptor'] : '';
83
+
84
+		if ($this->testmode) {
85
+			$this->publishable_key = ! empty($main_settings['test_publishable_key']) ? $main_settings['test_publishable_key'] : '';
86
+			$this->secret_key      = ! empty($main_settings['test_secret_key']) ? $main_settings['test_secret_key'] : '';
87 87
 		}
88 88
 
89
-		add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) );
90
-		add_action( 'wp_enqueue_scripts', array( $this, 'payment_scripts' ) );
91
-		add_action( 'woocommerce_thankyou_stripe_multibanco', array( $this, 'thankyou_page' ) );
89
+		add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options'));
90
+		add_action('wp_enqueue_scripts', array($this, 'payment_scripts'));
91
+		add_action('woocommerce_thankyou_stripe_multibanco', array($this, 'thankyou_page'));
92 92
 
93 93
 		// Customer Emails
94
-		add_action( 'woocommerce_email_before_order_table', array( $this, 'email_instructions' ), 10, 3 );
94
+		add_action('woocommerce_email_before_order_table', array($this, 'email_instructions'), 10, 3);
95 95
 	}
96 96
 
97 97
 	/**
@@ -102,9 +102,9 @@  discard block
 block discarded – undo
102 102
 	 * @return array
103 103
 	 */
104 104
 	public function get_supported_currency() {
105
-		return apply_filters( 'wc_stripe_multibanco_supported_currencies', array(
105
+		return apply_filters('wc_stripe_multibanco_supported_currencies', array(
106 106
 			'EUR',
107
-		) );
107
+		));
108 108
 	}
109 109
 
110 110
 	/**
@@ -115,7 +115,7 @@  discard block
 block discarded – undo
115 115
 	 * @return bool
116 116
 	 */
117 117
 	public function is_available() {
118
-		if ( ! in_array( get_woocommerce_currency(), $this->get_supported_currency() ) ) {
118
+		if ( ! in_array(get_woocommerce_currency(), $this->get_supported_currency())) {
119 119
 			return false;
120 120
 		}
121 121
 
@@ -136,7 +136,7 @@  discard block
 block discarded – undo
136 136
 
137 137
 		$icons_str .= $icons['multibanco'];
138 138
 
139
-		return apply_filters( 'woocommerce_gateway_icon', $icons_str, $this->id );
139
+		return apply_filters('woocommerce_gateway_icon', $icons_str, $this->id);
140 140
 	}
141 141
 
142 142
 	/**
@@ -147,19 +147,19 @@  discard block
 block discarded – undo
147 147
 	 * @access public
148 148
 	 */
149 149
 	public function payment_scripts() {
150
-		if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) && ! is_add_payment_method_page() ) {
150
+		if ( ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order']) && ! is_add_payment_method_page()) {
151 151
 			return;
152 152
 		}
153 153
 
154
-		wp_enqueue_style( 'stripe_styles' );
155
-		wp_enqueue_script( 'woocommerce_stripe' );
154
+		wp_enqueue_style('stripe_styles');
155
+		wp_enqueue_script('woocommerce_stripe');
156 156
 	}
157 157
 
158 158
 	/**
159 159
 	 * Initialize Gateway Settings Form Fields.
160 160
 	 */
161 161
 	public function init_form_fields() {
162
-		$this->form_fields = require( WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-multibanco-settings.php' );
162
+		$this->form_fields = require(WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-multibanco-settings.php');
163 163
 	}
164 164
 
165 165
 	/**
@@ -170,25 +170,25 @@  discard block
 block discarded – undo
170 170
 		$total = WC()->cart->total;
171 171
 
172 172
 		// If paying from order, we need to get total from order not cart.
173
-		if ( isset( $_GET['pay_for_order'] ) && ! empty( $_GET['key'] ) ) {
174
-			$order = wc_get_order( wc_get_order_id_by_order_key( wc_clean( $_GET['key'] ) ) );
173
+		if (isset($_GET['pay_for_order']) && ! empty($_GET['key'])) {
174
+			$order = wc_get_order(wc_get_order_id_by_order_key(wc_clean($_GET['key'])));
175 175
 			$total = $order->get_total();
176 176
 		}
177 177
 
178
-		if ( is_add_payment_method_page() ) {
179
-			$pay_button_text = __( 'Add Payment', 'woocommerce-gateway-stripe' );
180
-			$total        = '';
178
+		if (is_add_payment_method_page()) {
179
+			$pay_button_text = __('Add Payment', 'woocommerce-gateway-stripe');
180
+			$total = '';
181 181
 		} else {
182 182
 			$pay_button_text = '';
183 183
 		}
184 184
 
185 185
 		echo '<div
186 186
 			id="stripe-multibanco-payment-data"
187
-			data-amount="' . esc_attr( WC_Stripe_Helper::get_stripe_amount( $total ) ) . '"
188
-			data-currency="' . esc_attr( strtolower( get_woocommerce_currency() ) ) . '">';
187
+			data-amount="' . esc_attr(WC_Stripe_Helper::get_stripe_amount($total)) . '"
188
+			data-currency="' . esc_attr(strtolower(get_woocommerce_currency())) . '">';
189 189
 
190
-		if ( $this->description ) {
191
-			echo apply_filters( 'wc_stripe_description', wpautop( wp_kses_post( $this->description ) ), $this->id );
190
+		if ($this->description) {
191
+			echo apply_filters('wc_stripe_description', wpautop(wp_kses_post($this->description)), $this->id);
192 192
 		}
193 193
 
194 194
 		echo '</div>';
@@ -199,8 +199,8 @@  discard block
 block discarded – undo
199 199
 	 *
200 200
 	 * @param int $order_id
201 201
 	 */
202
-	public function thankyou_page( $order_id ) {
203
-		$this->get_instructions( $order_id );
202
+	public function thankyou_page($order_id) {
203
+		$this->get_instructions($order_id);
204 204
 	}
205 205
 
206 206
 	/**
@@ -212,15 +212,15 @@  discard block
 block discarded – undo
212 212
 	 * @param bool $sent_to_admin
213 213
 	 * @param bool $plain_text
214 214
 	 */
215
-	public function email_instructions( $order, $sent_to_admin, $plain_text = false ) {
215
+	public function email_instructions($order, $sent_to_admin, $plain_text = false) {
216 216
 		$order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
217 217
 
218 218
 		$payment_method = WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method();
219 219
 
220
-		if ( ! $sent_to_admin && 'stripe_multibanco' === $payment_method && $order->has_status( 'on-hold' ) ) {
221
-			WC_Stripe_Logger::log( 'Sending multibanco email for order #' . $order_id );
220
+		if ( ! $sent_to_admin && 'stripe_multibanco' === $payment_method && $order->has_status('on-hold')) {
221
+			WC_Stripe_Logger::log('Sending multibanco email for order #' . $order_id);
222 222
 
223
-			$this->get_instructions( $order_id, $plain_text );
223
+			$this->get_instructions($order_id, $plain_text);
224 224
 		}
225 225
 	}
226 226
 
@@ -231,34 +231,34 @@  discard block
 block discarded – undo
231 231
 	 * @version 4.1.0
232 232
 	 * @param int $order_id
233 233
 	 */
234
-	public function get_instructions( $order_id, $plain_text = false ) {
235
-		$data = get_post_meta( $order_id, '_stripe_multibanco', true );
234
+	public function get_instructions($order_id, $plain_text = false) {
235
+		$data = get_post_meta($order_id, '_stripe_multibanco', true);
236 236
 
237
-		if ( $plain_text ) {
238
-			esc_html_e( 'MULTIBANCO INFORMAÇÕES DE ENCOMENDA:', 'woocommerce-gateway-stripe' ) . "\n\n";
237
+		if ($plain_text) {
238
+			esc_html_e('MULTIBANCO INFORMAÇÕES DE ENCOMENDA:', 'woocommerce-gateway-stripe') . "\n\n";
239 239
 			echo "=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\n\n";
240
-			esc_html_e( 'Montante:', 'woocommerce-gateway-stripe' ) . "\n\n";
240
+			esc_html_e('Montante:', 'woocommerce-gateway-stripe') . "\n\n";
241 241
 			echo $data['amount'] . "\n\n";
242 242
 			echo "=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\n\n";
243
-			esc_html_e( 'Entidade:', 'woocommerce-gateway-stripe' ) . "\n\n";
243
+			esc_html_e('Entidade:', 'woocommerce-gateway-stripe') . "\n\n";
244 244
 			echo $data['entity'] . "\n\n";
245 245
 			echo "=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\n\n";
246
-			esc_html_e( 'Referencia:', 'woocommerce-gateway-stripe' ) . "\n\n";
246
+			esc_html_e('Referencia:', 'woocommerce-gateway-stripe') . "\n\n";
247 247
 			echo $data['reference'] . "\n\n";
248 248
 		} else {
249 249
 			?>
250
-			<h3><?php esc_html_e( 'MULTIBANCO INFORMAÇÕES DE ENCOMENDA:', 'woocommerce-gateway-stripe' ); ?></h3>
250
+			<h3><?php esc_html_e('MULTIBANCO INFORMAÇÕES DE ENCOMENDA:', 'woocommerce-gateway-stripe'); ?></h3>
251 251
 			<ul class="woocommerce-order-overview woocommerce-thankyou-order-details order_details">
252 252
 			<li class="woocommerce-order-overview__order order">
253
-				<?php esc_html_e( 'Montante:', 'woocommerce-gateway-stripe' ); ?>
253
+				<?php esc_html_e('Montante:', 'woocommerce-gateway-stripe'); ?>
254 254
 				<strong><?php echo $data['amount']; ?></strong>
255 255
 			</li>
256 256
 			<li class="woocommerce-order-overview__order order">
257
-				<?php esc_html_e( 'Entidade:', 'woocommerce-gateway-stripe' ); ?>
257
+				<?php esc_html_e('Entidade:', 'woocommerce-gateway-stripe'); ?>
258 258
 				<strong><?php echo $data['entity']; ?></strong>
259 259
 			</li>
260 260
 			<li class="woocommerce-order-overview__order order">
261
-				<?php esc_html_e( 'Referencia:', 'woocommerce-gateway-stripe' ); ?>
261
+				<?php esc_html_e('Referencia:', 'woocommerce-gateway-stripe'); ?>
262 262
 				<strong><?php echo $data['reference']; ?></strong>
263 263
 			</li>
264 264
 			</ul>
@@ -274,7 +274,7 @@  discard block
 block discarded – undo
274 274
 	 * @param object $order
275 275
 	 * @param object $source_object
276 276
 	 */
277
-	public function save_instructions( $order, $source_object ) {
277
+	public function save_instructions($order, $source_object) {
278 278
 		$data = array(
279 279
 			'amount'    => $order->get_formatted_order_total(),
280 280
 			'entity'    => $source_object->multibanco->entity,
@@ -283,7 +283,7 @@  discard block
 block discarded – undo
283 283
 
284 284
 		$order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
285 285
 
286
-		update_post_meta( $order_id, '_stripe_multibanco', $data );
286
+		update_post_meta($order_id, '_stripe_multibanco', $data);
287 287
 	}
288 288
 
289 289
 	/**
@@ -294,24 +294,24 @@  discard block
 block discarded – undo
294 294
 	 * @param object $order
295 295
 	 * @return mixed
296 296
 	 */
297
-	public function create_source( $order ) {
297
+	public function create_source($order) {
298 298
 		$currency              = WC_Stripe_Helper::is_pre_30() ? $order->get_order_currency() : $order->get_currency();
299 299
 		$order_id              = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
300
-		$return_url            = $this->get_stripe_return_url( $order );
300
+		$return_url            = $this->get_stripe_return_url($order);
301 301
 		$post_data             = array();
302
-		$post_data['amount']   = WC_Stripe_Helper::get_stripe_amount( $order->get_total(), $currency );
303
-		$post_data['currency'] = strtolower( $currency );
302
+		$post_data['amount']   = WC_Stripe_Helper::get_stripe_amount($order->get_total(), $currency);
303
+		$post_data['currency'] = strtolower($currency);
304 304
 		$post_data['type']     = 'multibanco';
305
-		$post_data['owner']    = $this->get_owner_details( $order );
306
-		$post_data['redirect'] = array( 'return_url' => $return_url );
305
+		$post_data['owner']    = $this->get_owner_details($order);
306
+		$post_data['redirect'] = array('return_url' => $return_url);
307 307
 
308
-		if ( ! empty( $this->statement_descriptor ) ) {
309
-			$post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor( $this->statement_descriptor );
308
+		if ( ! empty($this->statement_descriptor)) {
309
+			$post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor($this->statement_descriptor);
310 310
 		}
311 311
 
312
-		WC_Stripe_Logger::log( 'Info: Begin creating Multibanco source' );
312
+		WC_Stripe_Logger::log('Info: Begin creating Multibanco source');
313 313
 
314
-		return WC_Stripe_API::request( $post_data, 'sources' );
314
+		return WC_Stripe_API::request($post_data, 'sources');
315 315
 	}
316 316
 
317 317
 	/**
@@ -325,62 +325,62 @@  discard block
 block discarded – undo
325 325
 	 *
326 326
 	 * @return array|void
327 327
 	 */
328
-	public function process_payment( $order_id, $retry = true, $force_save_source = false ) {
328
+	public function process_payment($order_id, $retry = true, $force_save_source = false) {
329 329
 		try {
330
-			$order = wc_get_order( $order_id );
330
+			$order = wc_get_order($order_id);
331 331
 
332 332
 			// This will throw exception if not valid.
333
-			$this->validate_minimum_order_amount( $order );
333
+			$this->validate_minimum_order_amount($order);
334 334
 
335 335
 			// This comes from the create account checkbox in the checkout page.
336
-			$create_account = ! empty( $_POST['createaccount'] ) ? true : false;
336
+			$create_account = ! empty($_POST['createaccount']) ? true : false;
337 337
 
338
-			if ( $create_account ) {
338
+			if ($create_account) {
339 339
 				$new_customer_id     = WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id();
340
-				$new_stripe_customer = new WC_Stripe_Customer( $new_customer_id );
340
+				$new_stripe_customer = new WC_Stripe_Customer($new_customer_id);
341 341
 				$new_stripe_customer->create_customer();
342 342
 			}
343 343
 
344
-			$response = $this->create_source( $order );
344
+			$response = $this->create_source($order);
345 345
 
346
-			if ( ! empty( $response->error ) ) {
347
-				$order->add_order_note( $response->error->message );
346
+			if ( ! empty($response->error)) {
347
+				$order->add_order_note($response->error->message);
348 348
 
349
-				throw new Exception( $response->error->message );
349
+				throw new Exception($response->error->message);
350 350
 			}
351 351
 
352
-			if ( WC_Stripe_Helper::is_pre_30() ) {
353
-				update_post_meta( $order_id, '_stripe_source_id', $response->id );
352
+			if (WC_Stripe_Helper::is_pre_30()) {
353
+				update_post_meta($order_id, '_stripe_source_id', $response->id);
354 354
 			} else {
355
-				$order->update_meta_data( '_stripe_source_id', $response->id );
355
+				$order->update_meta_data('_stripe_source_id', $response->id);
356 356
 				$order->save();
357 357
 			}
358 358
 
359
-			$this->save_instructions( $order, $response );
359
+			$this->save_instructions($order, $response);
360 360
 
361 361
 			// Mark as on-hold (we're awaiting the payment)
362
-			$order->update_status( 'on-hold', __( 'Awaiting Multibanco payment', 'woocommerce-gateway-stripe' ) );
362
+			$order->update_status('on-hold', __('Awaiting Multibanco payment', 'woocommerce-gateway-stripe'));
363 363
 
364 364
 			// Reduce stock levels
365
-			wc_reduce_stock_levels( $order_id );
365
+			wc_reduce_stock_levels($order_id);
366 366
 
367 367
 			// Remove cart
368 368
 			WC()->cart->empty_cart();
369 369
 
370
-			WC_Stripe_Logger::log( 'Info: Redirecting to Multibanco...' );
370
+			WC_Stripe_Logger::log('Info: Redirecting to Multibanco...');
371 371
 
372 372
 			return array(
373 373
 				'result'   => 'success',
374
-				'redirect' => esc_url_raw( $response->redirect->url ),
374
+				'redirect' => esc_url_raw($response->redirect->url),
375 375
 			);
376
-		} catch ( Exception $e ) {
377
-			wc_add_notice( $e->getMessage(), 'error' );
378
-			WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() );
376
+		} catch (Exception $e) {
377
+			wc_add_notice($e->getMessage(), 'error');
378
+			WC_Stripe_Logger::log('Error: ' . $e->getMessage());
379 379
 
380
-			do_action( 'wc_gateway_stripe_process_payment_error', $e, $order );
380
+			do_action('wc_gateway_stripe_process_payment_error', $e, $order);
381 381
 
382
-			if ( $order->has_status( array( 'pending', 'failed' ) ) ) {
383
-				$this->send_failed_order_email( $order_id );
382
+			if ($order->has_status(array('pending', 'failed'))) {
383
+				$this->send_failed_order_email($order_id);
384 384
 			}
385 385
 
386 386
 			return array(
Please login to merge, or discard this patch.