Completed
Push — master ( 8f896b...177e14 )
by Roy
02:13
created
includes/class-wc-gateway-stripe.php 1 patch
Spacing   +175 added lines, -175 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) {
2
+if ( ! defined('ABSPATH')) {
3 3
 	exit;
4 4
 }
5 5
 
@@ -101,9 +101,9 @@  discard block
 block discarded – undo
101 101
 	public function __construct() {
102 102
 		$this->retry_interval       = 2;
103 103
 		$this->id                   = 'stripe';
104
-		$this->method_title         = __( 'Stripe', 'woocommerce-gateway-stripe' );
104
+		$this->method_title         = __('Stripe', 'woocommerce-gateway-stripe');
105 105
 		/* translators: 1) link to Stripe register page 2) link to Stripe api keys page */
106
-		$this->method_description   = sprintf( __( 'Stripe works by adding payment fields on the checkout and then sending the details to Stripe for verification. <a href="%1$s" target="_blank">Sign up</a> for a Stripe account, and <a href="%2$s" target="_blank">get your Stripe account keys</a>.', 'woocommerce-gateway-stripe' ), 'https://dashboard.stripe.com/register', 'https://dashboard.stripe.com/account/apikeys' );
106
+		$this->method_description   = sprintf(__('Stripe works by adding payment fields on the checkout and then sending the details to Stripe for verification. <a href="%1$s" target="_blank">Sign up</a> for a Stripe account, and <a href="%2$s" target="_blank">get your Stripe account keys</a>.', 'woocommerce-gateway-stripe'), 'https://dashboard.stripe.com/register', 'https://dashboard.stripe.com/account/apikeys');
107 107
 		$this->has_fields           = true;
108 108
 		$this->supports             = array(
109 109
 			'products',
@@ -130,32 +130,32 @@  discard block
 block discarded – undo
130 130
 		$this->init_settings();
131 131
 
132 132
 		// Get setting values.
133
-		$this->title                   = $this->get_option( 'title' );
134
-		$this->description             = $this->get_option( 'description' );
135
-		$this->enabled                 = $this->get_option( 'enabled' );
136
-		$this->testmode                = 'yes' === $this->get_option( 'testmode' );
137
-		$this->inline_cc_form          = 'yes' === $this->get_option( 'inline_cc_form' );
138
-		$this->capture                 = 'yes' === $this->get_option( 'capture', 'yes' );
139
-		$this->statement_descriptor    = WC_Stripe_Helper::clean_statement_descriptor( $this->get_option( 'statement_descriptor' ) );
140
-		$this->three_d_secure          = 'yes' === $this->get_option( 'three_d_secure' );
141
-		$this->stripe_checkout         = 'yes' === $this->get_option( 'stripe_checkout' );
142
-		$this->stripe_checkout_image   = $this->get_option( 'stripe_checkout_image', '' );
143
-		$this->saved_cards             = 'yes' === $this->get_option( 'saved_cards' );
144
-		$this->secret_key              = $this->testmode ? $this->get_option( 'test_secret_key' ) : $this->get_option( 'secret_key' );
145
-		$this->publishable_key         = $this->testmode ? $this->get_option( 'test_publishable_key' ) : $this->get_option( 'publishable_key' );
146
-		$this->bitcoin                 = 'USD' === strtoupper( get_woocommerce_currency() ) && 'yes' === $this->get_option( 'stripe_bitcoin' );
147
-		$this->payment_request         = 'yes' === $this->get_option( 'payment_request', 'yes' );
148
-
149
-		if ( $this->stripe_checkout ) {
150
-			$this->order_button_text = __( 'Continue to payment', 'woocommerce-gateway-stripe' );
133
+		$this->title                   = $this->get_option('title');
134
+		$this->description             = $this->get_option('description');
135
+		$this->enabled                 = $this->get_option('enabled');
136
+		$this->testmode                = 'yes' === $this->get_option('testmode');
137
+		$this->inline_cc_form          = 'yes' === $this->get_option('inline_cc_form');
138
+		$this->capture                 = 'yes' === $this->get_option('capture', 'yes');
139
+		$this->statement_descriptor    = WC_Stripe_Helper::clean_statement_descriptor($this->get_option('statement_descriptor'));
140
+		$this->three_d_secure          = 'yes' === $this->get_option('three_d_secure');
141
+		$this->stripe_checkout         = 'yes' === $this->get_option('stripe_checkout');
142
+		$this->stripe_checkout_image   = $this->get_option('stripe_checkout_image', '');
143
+		$this->saved_cards             = 'yes' === $this->get_option('saved_cards');
144
+		$this->secret_key              = $this->testmode ? $this->get_option('test_secret_key') : $this->get_option('secret_key');
145
+		$this->publishable_key         = $this->testmode ? $this->get_option('test_publishable_key') : $this->get_option('publishable_key');
146
+		$this->bitcoin                 = 'USD' === strtoupper(get_woocommerce_currency()) && 'yes' === $this->get_option('stripe_bitcoin');
147
+		$this->payment_request         = 'yes' === $this->get_option('payment_request', 'yes');
148
+
149
+		if ($this->stripe_checkout) {
150
+			$this->order_button_text = __('Continue to payment', 'woocommerce-gateway-stripe');
151 151
 		}
152 152
 
153
-		WC_Stripe_API::set_secret_key( $this->secret_key );
153
+		WC_Stripe_API::set_secret_key($this->secret_key);
154 154
 
155 155
 		// Hooks.
156
-		add_action( 'wp_enqueue_scripts', array( $this, 'payment_scripts' ) );
157
-		add_action( 'admin_enqueue_scripts', array( $this, 'admin_scripts' ) );
158
-		add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) );
156
+		add_action('wp_enqueue_scripts', array($this, 'payment_scripts'));
157
+		add_action('admin_enqueue_scripts', array($this, 'admin_scripts'));
158
+		add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options'));
159 159
 	}
160 160
 
161 161
 	/**
@@ -164,7 +164,7 @@  discard block
 block discarded – undo
164 164
 	 * @since 4.0.2
165 165
 	 */
166 166
 	public function is_available() {
167
-		if ( is_add_payment_method_page() && ! $this->saved_cards ) {
167
+		if (is_add_payment_method_page() && ! $this->saved_cards) {
168 168
 			return false;
169 169
 		}
170 170
 
@@ -187,24 +187,24 @@  discard block
 block discarded – undo
187 187
 		$icons_str .= $icons['amex'];
188 188
 		$icons_str .= $icons['mastercard'];
189 189
 
190
-		if ( 'USD' === get_woocommerce_currency() ) {
190
+		if ('USD' === get_woocommerce_currency()) {
191 191
 			$icons_str .= $icons['discover'];
192 192
 			$icons_str .= $icons['jcb'];
193 193
 			$icons_str .= $icons['diners'];
194 194
 		}
195 195
 
196
-		if ( $this->bitcoin && $this->stripe_checkout ) {
196
+		if ($this->bitcoin && $this->stripe_checkout) {
197 197
 			$icons_str .= $icons['bitcoin'];
198 198
 		}
199 199
 
200
-		return apply_filters( 'woocommerce_gateway_icon', $icons_str, $this->id );
200
+		return apply_filters('woocommerce_gateway_icon', $icons_str, $this->id);
201 201
 	}
202 202
 
203 203
 	/**
204 204
 	 * Initialise Gateway Settings Form Fields
205 205
 	 */
206 206
 	public function init_form_fields() {
207
-		$this->form_fields = require( dirname( __FILE__ ) . '/admin/stripe-settings.php' );
207
+		$this->form_fields = require(dirname(__FILE__) . '/admin/stripe-settings.php');
208 208
 	}
209 209
 
210 210
 	/**
@@ -212,68 +212,68 @@  discard block
 block discarded – undo
212 212
 	 */
213 213
 	public function payment_fields() {
214 214
 		$user                 = wp_get_current_user();
215
-		$display_tokenization = $this->supports( 'tokenization' ) && is_checkout() && $this->saved_cards;
215
+		$display_tokenization = $this->supports('tokenization') && is_checkout() && $this->saved_cards;
216 216
 		$total                = WC()->cart->total;
217 217
 		$user_email           = '';
218 218
 
219 219
 		// If paying from order, we need to get total from order not cart.
220
-		if ( isset( $_GET['pay_for_order'] ) && ! empty( $_GET['key'] ) ) {
221
-			$order      = wc_get_order( wc_get_order_id_by_order_key( wc_clean( $_GET['key'] ) ) );
220
+		if (isset($_GET['pay_for_order']) && ! empty($_GET['key'])) {
221
+			$order      = wc_get_order(wc_get_order_id_by_order_key(wc_clean($_GET['key'])));
222 222
 			$total      = $order->get_total();
223 223
 			$user_email = WC_Stripe_Helper::is_pre_30() ? $order->billing_email : $order->get_billing_email();
224 224
 		} else {
225
-			if ( $user->ID ) {
226
-				$user_email = get_user_meta( $user->ID, 'billing_email', true );
225
+			if ($user->ID) {
226
+				$user_email = get_user_meta($user->ID, 'billing_email', true);
227 227
 				$user_email = $user_email ? $user_email : $user->user_email;
228 228
 			}
229 229
 		}
230 230
 
231
-		if ( is_add_payment_method_page() ) {
232
-			$pay_button_text = __( 'Add Card', 'woocommerce-gateway-stripe' );
233
-			$total        = '';
231
+		if (is_add_payment_method_page()) {
232
+			$pay_button_text = __('Add Card', 'woocommerce-gateway-stripe');
233
+			$total = '';
234 234
 		} else {
235 235
 			$pay_button_text = '';
236 236
 		}
237 237
 
238 238
 		echo '<div
239 239
 			id="stripe-payment-data"
240
-			data-panel-label="' . esc_attr( $pay_button_text ) . '"
240
+			data-panel-label="' . esc_attr($pay_button_text) . '"
241 241
 			data-description=""
242
-			data-email="' . esc_attr( $user_email ) . '"
243
-			data-amount="' . esc_attr( WC_Stripe_Helper::get_stripe_amount( $total ) ) . '"
244
-			data-name="' . esc_attr( $this->statement_descriptor ) . '"
245
-			data-currency="' . esc_attr( strtolower( get_woocommerce_currency() ) ) . '"
246
-			data-image="' . esc_attr( $this->stripe_checkout_image ) . '"
247
-			data-bitcoin="' . esc_attr( ( $this->bitcoin && $this->capture ) ? 'true' : 'false' ) . '"
248
-			data-locale="' . esc_attr( apply_filters( 'wc_stripe_checkout_locale', $this->get_locale() ) ) . '"
249
-			data-three-d-secure="' . esc_attr( $this->three_d_secure ? 'true' : 'false' ) . '"
250
-			data-allow-remember-me="' . esc_attr( $this->saved_cards ? 'true' : 'false' ) . '">';
251
-
252
-		if ( $this->description ) {
253
-			if ( $this->testmode ) {
242
+			data-email="' . esc_attr($user_email) . '"
243
+			data-amount="' . esc_attr(WC_Stripe_Helper::get_stripe_amount($total)) . '"
244
+			data-name="' . esc_attr($this->statement_descriptor) . '"
245
+			data-currency="' . esc_attr(strtolower(get_woocommerce_currency())) . '"
246
+			data-image="' . esc_attr($this->stripe_checkout_image) . '"
247
+			data-bitcoin="' . esc_attr(($this->bitcoin && $this->capture) ? 'true' : 'false') . '"
248
+			data-locale="' . esc_attr(apply_filters('wc_stripe_checkout_locale', $this->get_locale())) . '"
249
+			data-three-d-secure="' . esc_attr($this->three_d_secure ? 'true' : 'false') . '"
250
+			data-allow-remember-me="' . esc_attr($this->saved_cards ? 'true' : 'false') . '">';
251
+
252
+		if ($this->description) {
253
+			if ($this->testmode) {
254 254
 				/* translators: link to Stripe testing page */
255
-				$this->description .= ' ' . sprintf( __( 'TEST MODE ENABLED. In test mode, you can use the card number 4242424242424242 with any CVC and a valid expiration date or check the documentation "<a href="%s" target="_blank">Testing Stripe</a>" for more card numbers.', 'woocommerce-gateway-stripe' ), 'https://stripe.com/docs/testing' );
256
-				$this->description  = trim( $this->description );
255
+				$this->description .= ' ' . sprintf(__('TEST MODE ENABLED. In test mode, you can use the card number 4242424242424242 with any CVC and a valid expiration date or check the documentation "<a href="%s" target="_blank">Testing Stripe</a>" for more card numbers.', 'woocommerce-gateway-stripe'), 'https://stripe.com/docs/testing');
256
+				$this->description  = trim($this->description);
257 257
 			}
258
-			echo apply_filters( 'wc_stripe_description', wpautop( wp_kses_post( $this->description ) ) );
258
+			echo apply_filters('wc_stripe_description', wpautop(wp_kses_post($this->description)));
259 259
 		}
260 260
 
261
-		if ( $display_tokenization ) {
261
+		if ($display_tokenization) {
262 262
 			$this->tokenization_script();
263 263
 			$this->saved_payment_methods();
264 264
 		}
265 265
 
266
-		if ( ! $this->stripe_checkout ) {
267
-			if ( apply_filters( 'wc_stripe_use_elements_checkout_form', true ) ) {
266
+		if ( ! $this->stripe_checkout) {
267
+			if (apply_filters('wc_stripe_use_elements_checkout_form', true)) {
268 268
 				$this->elements_form();
269 269
 			} else {
270
-				WC_Stripe_Logger::log( 'DEPRECATED! Since version 4.0. Stripe Elements is used. This legacy credit card form will be removed by version 4.1!' );
270
+				WC_Stripe_Logger::log('DEPRECATED! Since version 4.0. Stripe Elements is used. This legacy credit card form will be removed by version 4.1!');
271 271
 				$this->form();
272 272
 				echo '<div class="stripe-source-errors" role="alert"></div>';
273 273
 			}
274 274
 		}
275 275
 
276
-		if ( apply_filters( 'wc_stripe_display_save_payment_method_checkbox', $display_tokenization ) && ! is_add_payment_method_page() && ! isset( $_GET['change_payment_method'] ) ) {
276
+		if (apply_filters('wc_stripe_display_save_payment_method_checkbox', $display_tokenization) && ! is_add_payment_method_page() && ! isset($_GET['change_payment_method'])) {
277 277
 			$this->save_payment_method_checkbox();
278 278
 		}
279 279
 
@@ -288,12 +288,12 @@  discard block
 block discarded – undo
288 288
 	 */
289 289
 	public function elements_form() {
290 290
 		?>
291
-		<fieldset id="wc-<?php echo esc_attr( $this->id ); ?>-cc-form" class="wc-credit-card-form wc-payment-form" style="background:transparent;">
292
-			<?php do_action( 'woocommerce_credit_card_form_start', $this->id ); ?>
291
+		<fieldset id="wc-<?php echo esc_attr($this->id); ?>-cc-form" class="wc-credit-card-form wc-payment-form" style="background:transparent;">
292
+			<?php do_action('woocommerce_credit_card_form_start', $this->id); ?>
293 293
 
294
-			<?php if ( $this->inline_cc_form ) { ?>
294
+			<?php if ($this->inline_cc_form) { ?>
295 295
 				<label for="card-element">
296
-					<?php esc_html_e( 'Credit or debit card', 'woocommerce-gateway-stripe' ); ?>
296
+					<?php esc_html_e('Credit or debit card', 'woocommerce-gateway-stripe'); ?>
297 297
 				</label>
298 298
 
299 299
 				<div id="stripe-card-element" style="background:#fff;padding:0 1em;border:1px solid #ddd;margin:5px 0;padding:10px 5px;">
@@ -301,7 +301,7 @@  discard block
 block discarded – undo
301 301
 				</div>
302 302
 			<?php } else { ?>
303 303
 				<div class="form-row form-row-wide">
304
-					<label><?php _e( 'Card Number', 'woocommerce-gateway-stripe' ); ?> <span class="required">*</span></label>
304
+					<label><?php _e('Card Number', 'woocommerce-gateway-stripe'); ?> <span class="required">*</span></label>
305 305
 
306 306
 					<div id="stripe-card-element" style="background:#fff;padding:0 1em;border:1px solid #ddd;margin:5px 0;padding:10px 5px;">
307 307
 					<!-- a Stripe Element will be inserted here. -->
@@ -309,7 +309,7 @@  discard block
 block discarded – undo
309 309
 				</div>
310 310
 
311 311
 				<div class="form-row form-row-first">
312
-					<label><?php _e( 'Expiry Date', 'woocommerce-gateway-stripe' ); ?> <span class="required">*</span></label>
312
+					<label><?php _e('Expiry Date', 'woocommerce-gateway-stripe'); ?> <span class="required">*</span></label>
313 313
 
314 314
 					<div id="stripe-exp-element" style="background:#fff;padding:0 1em;border:1px solid #ddd;margin:5px 0;padding:10px 5px;">
315 315
 					<!-- a Stripe Element will be inserted here. -->
@@ -317,7 +317,7 @@  discard block
 block discarded – undo
317 317
 				</div>
318 318
 
319 319
 				<div class="form-row form-row-last">
320
-					<label><?php _e( 'Card Code (CVC)', 'woocommerce-gateway-stripe' ); ?> <span class="required">*</span></label>
320
+					<label><?php _e('Card Code (CVC)', 'woocommerce-gateway-stripe'); ?> <span class="required">*</span></label>
321 321
 				<div id="stripe-cvc-element" style="background:#fff;padding:0 1em;border:1px solid #ddd;margin:5px 0;padding:10px 5px;">
322 322
 				<!-- a Stripe Element will be inserted here. -->
323 323
 				</div>
@@ -327,7 +327,7 @@  discard block
 block discarded – undo
327 327
 
328 328
 			<!-- Used to display form errors -->
329 329
 			<div class="stripe-source-errors" role="alert"></div>
330
-			<?php do_action( 'woocommerce_credit_card_form_end', $this->id ); ?>
330
+			<?php do_action('woocommerce_credit_card_form_end', $this->id); ?>
331 331
 			<div class="clear"></div>
332 332
 		</fieldset>
333 333
 		<?php
@@ -340,13 +340,13 @@  discard block
 block discarded – undo
340 340
 	 * @version 3.1.0
341 341
 	 */
342 342
 	public function admin_scripts() {
343
-		if ( 'woocommerce_page_wc-settings' !== get_current_screen()->id ) {
343
+		if ('woocommerce_page_wc-settings' !== get_current_screen()->id) {
344 344
 			return;
345 345
 		}
346 346
 
347
-		$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
347
+		$suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';
348 348
 
349
-		wp_enqueue_script( 'woocommerce_stripe_admin', plugins_url( 'assets/js/stripe-admin' . $suffix . '.js', WC_STRIPE_MAIN_FILE ), array(), WC_STRIPE_VERSION, true );
349
+		wp_enqueue_script('woocommerce_stripe_admin', plugins_url('assets/js/stripe-admin' . $suffix . '.js', WC_STRIPE_MAIN_FILE), array(), WC_STRIPE_VERSION, true);
350 350
 	}
351 351
 
352 352
 	/**
@@ -358,33 +358,33 @@  discard block
 block discarded – undo
358 358
 	 * @version 4.0.0
359 359
 	 */
360 360
 	public function payment_scripts() {
361
-		if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) && ! is_add_payment_method_page() && ! isset( $_GET['change_payment_method'] ) ) {
361
+		if ( ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order']) && ! is_add_payment_method_page() && ! isset($_GET['change_payment_method'])) {
362 362
 			return;
363 363
 		}
364 364
 
365
-		if ( 'no' === $this->enabled ) {
365
+		if ('no' === $this->enabled) {
366 366
 			return;
367 367
 		}
368 368
 
369
-		$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
369
+		$suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';
370 370
 
371
-		wp_register_style( 'stripe_paymentfonts', plugins_url( 'assets/css/stripe-paymentfonts.css', WC_STRIPE_MAIN_FILE ), array(), '1.2.5' );
372
-		wp_enqueue_style( 'stripe_paymentfonts' );
373
-		wp_register_script( 'stripe_checkout', 'https://checkout.stripe.com/checkout.js', '', WC_STRIPE_VERSION, true );
374
-		wp_register_script( 'stripev2', 'https://js.stripe.com/v2/', '', '2.0', true );
375
-		wp_register_script( 'stripe', 'https://js.stripe.com/v3/', '', '3.0', true );
376
-		wp_register_script( 'woocommerce_stripe', plugins_url( 'assets/js/stripe' . $suffix . '.js', WC_STRIPE_MAIN_FILE ), array( 'jquery-payment', 'stripev2', 'stripe' ), WC_STRIPE_VERSION, true );
371
+		wp_register_style('stripe_paymentfonts', plugins_url('assets/css/stripe-paymentfonts.css', WC_STRIPE_MAIN_FILE), array(), '1.2.5');
372
+		wp_enqueue_style('stripe_paymentfonts');
373
+		wp_register_script('stripe_checkout', 'https://checkout.stripe.com/checkout.js', '', WC_STRIPE_VERSION, true);
374
+		wp_register_script('stripev2', 'https://js.stripe.com/v2/', '', '2.0', true);
375
+		wp_register_script('stripe', 'https://js.stripe.com/v3/', '', '3.0', true);
376
+		wp_register_script('woocommerce_stripe', plugins_url('assets/js/stripe' . $suffix . '.js', WC_STRIPE_MAIN_FILE), array('jquery-payment', 'stripev2', 'stripe'), WC_STRIPE_VERSION, true);
377 377
 
378 378
 		$stripe_params = array(
379 379
 			'key'                  => $this->publishable_key,
380
-			'i18n_terms'           => __( 'Please accept the terms and conditions first', 'woocommerce-gateway-stripe' ),
381
-			'i18n_required_fields' => __( 'Please fill in required checkout fields first', 'woocommerce-gateway-stripe' ),
380
+			'i18n_terms'           => __('Please accept the terms and conditions first', 'woocommerce-gateway-stripe'),
381
+			'i18n_required_fields' => __('Please fill in required checkout fields first', 'woocommerce-gateway-stripe'),
382 382
 		);
383 383
 
384 384
 		// If we're on the pay page we need to pass stripe.js the address of the order.
385
-		if ( isset( $_GET['pay_for_order'] ) && 'true' === $_GET['pay_for_order'] ) {
386
-			$order_id = wc_get_order_id_by_order_key( urldecode( $_GET['key'] ) );
387
-			$order    = wc_get_order( $order_id );
385
+		if (isset($_GET['pay_for_order']) && 'true' === $_GET['pay_for_order']) {
386
+			$order_id = wc_get_order_id_by_order_key(urldecode($_GET['key']));
387
+			$order    = wc_get_order($order_id);
388 388
 
389 389
 			$stripe_params['billing_first_name'] = WC_Stripe_Helper::is_pre_30() ? $order->billing_first_name : $order->get_billing_first_name();
390 390
 			$stripe_params['billing_last_name']  = WC_Stripe_Helper::is_pre_30() ? $order->billing_last_name : $order->get_billing_last_name();
@@ -396,38 +396,38 @@  discard block
 block discarded – undo
396 396
 			$stripe_params['billing_country']    = WC_Stripe_Helper::is_pre_30() ? $order->billing_country : $order->get_billing_country();
397 397
 		}
398 398
 
399
-		$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' );
400
-		$stripe_params['no_sepa_owner_msg']                       = __( 'Please enter your IBAN account name.', 'woocommerce-gateway-stripe' );
401
-		$stripe_params['no_sepa_iban_msg']                        = __( 'Please enter your IBAN account number.', 'woocommerce-gateway-stripe' );
402
-		$stripe_params['sepa_mandate_notification']               = apply_filters( 'wc_stripe_sepa_mandate_notification', 'email' );
403
-		$stripe_params['allow_prepaid_card']                      = apply_filters( 'wc_stripe_allow_prepaid_card', true ) ? 'yes' : 'no';
399
+		$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');
400
+		$stripe_params['no_sepa_owner_msg']                       = __('Please enter your IBAN account name.', 'woocommerce-gateway-stripe');
401
+		$stripe_params['no_sepa_iban_msg']                        = __('Please enter your IBAN account number.', 'woocommerce-gateway-stripe');
402
+		$stripe_params['sepa_mandate_notification']               = apply_filters('wc_stripe_sepa_mandate_notification', 'email');
403
+		$stripe_params['allow_prepaid_card']                      = apply_filters('wc_stripe_allow_prepaid_card', true) ? 'yes' : 'no';
404 404
 		$stripe_params['inline_cc_form']                          = $this->inline_cc_form ? 'yes' : 'no';
405
-		$stripe_params['stripe_checkout_require_billing_address'] = apply_filters( 'wc_stripe_checkout_require_billing_address', false ) ? 'yes' : 'no';
406
-		$stripe_params['is_checkout']                             = ( is_checkout() && empty( $_GET['pay_for_order'] ) );
405
+		$stripe_params['stripe_checkout_require_billing_address'] = apply_filters('wc_stripe_checkout_require_billing_address', false) ? 'yes' : 'no';
406
+		$stripe_params['is_checkout']                             = (is_checkout() && empty($_GET['pay_for_order']));
407 407
 		$stripe_params['return_url']                              = $this->get_stripe_return_url();
408
-		$stripe_params['ajaxurl']                                 = WC_AJAX::get_endpoint( '%%endpoint%%' );
409
-		$stripe_params['stripe_nonce']                            = wp_create_nonce( '_wc_stripe_nonce' );
408
+		$stripe_params['ajaxurl']                                 = WC_AJAX::get_endpoint('%%endpoint%%');
409
+		$stripe_params['stripe_nonce']                            = wp_create_nonce('_wc_stripe_nonce');
410 410
 		$stripe_params['statement_descriptor']                    = $this->statement_descriptor;
411
-		$stripe_params['use_elements']                            = apply_filters( 'wc_stripe_use_elements_checkout_form', true ) ? 'yes' : 'no';
412
-		$stripe_params['elements_options']                        = apply_filters( 'wc_stripe_elements_options', array() );
411
+		$stripe_params['use_elements']                            = apply_filters('wc_stripe_use_elements_checkout_form', true) ? 'yes' : 'no';
412
+		$stripe_params['elements_options']                        = apply_filters('wc_stripe_elements_options', array());
413 413
 		$stripe_params['is_stripe_checkout']                      = $this->stripe_checkout ? 'yes' : 'no';
414
-		$stripe_params['is_change_payment_page']                  = isset( $_GET['change_payment_method'] ) ? 'yes' : 'no';
415
-		$stripe_params['validate_modal_checkout']                 = apply_filters( 'wc_stripe_validate_model_checkout', true ) ? 'yes' : 'no';
416
-		$stripe_params['elements_styling']                        = apply_filters( 'wc_stripe_elements_styling', false );
417
-		$stripe_params['elements_classes']                        = apply_filters( 'wc_stripe_elements_classes', false );
414
+		$stripe_params['is_change_payment_page']                  = isset($_GET['change_payment_method']) ? 'yes' : 'no';
415
+		$stripe_params['validate_modal_checkout']                 = apply_filters('wc_stripe_validate_model_checkout', true) ? 'yes' : 'no';
416
+		$stripe_params['elements_styling']                        = apply_filters('wc_stripe_elements_styling', false);
417
+		$stripe_params['elements_classes']                        = apply_filters('wc_stripe_elements_classes', false);
418 418
 
419 419
 		// merge localized messages to be use in JS
420
-		$stripe_params = array_merge( $stripe_params, WC_Stripe_Helper::get_localized_messages() );
420
+		$stripe_params = array_merge($stripe_params, WC_Stripe_Helper::get_localized_messages());
421 421
 
422
-		wp_localize_script( 'woocommerce_stripe', 'wc_stripe_params', apply_filters( 'wc_stripe_params', $stripe_params ) );
423
-		wp_localize_script( 'woocommerce_stripe_checkout', 'wc_stripe_params', apply_filters( 'wc_stripe_params', $stripe_params ) );
422
+		wp_localize_script('woocommerce_stripe', 'wc_stripe_params', apply_filters('wc_stripe_params', $stripe_params));
423
+		wp_localize_script('woocommerce_stripe_checkout', 'wc_stripe_params', apply_filters('wc_stripe_params', $stripe_params));
424 424
 
425
-		if ( $this->stripe_checkout ) {
426
-			wp_enqueue_script( 'stripe_checkout' );
425
+		if ($this->stripe_checkout) {
426
+			wp_enqueue_script('stripe_checkout');
427 427
 		}
428 428
 
429 429
 		$this->tokenization_script();
430
-		wp_enqueue_script( 'woocommerce_stripe' );
430
+		wp_enqueue_script('woocommerce_stripe');
431 431
 	}
432 432
 
433 433
 	/**
@@ -443,43 +443,43 @@  discard block
 block discarded – undo
443 443
 	 *
444 444
 	 * @return array|void
445 445
 	 */
446
-	public function process_payment( $order_id, $retry = true, $force_save_source = false ) {
446
+	public function process_payment($order_id, $retry = true, $force_save_source = false) {
447 447
 		try {
448
-			$order = wc_get_order( $order_id );
448
+			$order = wc_get_order($order_id);
449 449
 
450 450
 			// This comes from the create account checkbox in the checkout page.
451
-			$create_account = ! empty( $_POST['createaccount'] ) ? true : false;
451
+			$create_account = ! empty($_POST['createaccount']) ? true : false;
452 452
 
453
-			if ( $create_account ) {
453
+			if ($create_account) {
454 454
 				$new_customer_id     = WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id();
455
-				$new_stripe_customer = new WC_Stripe_Customer( $new_customer_id );
455
+				$new_stripe_customer = new WC_Stripe_Customer($new_customer_id);
456 456
 				$new_stripe_customer->create_customer();
457 457
 			}
458 458
 
459 459
 			$source_object   = $this->get_source_object();
460
-			$prepared_source = $this->prepare_source( $source_object, get_current_user_id(), $force_save_source );
460
+			$prepared_source = $this->prepare_source($source_object, get_current_user_id(), $force_save_source);
461 461
 
462 462
 			// Check if we don't allow prepaid credit cards.
463
-			if ( ! apply_filters( 'wc_stripe_allow_prepaid_card', true ) ) {
464
-				if ( $source_object && 'token' === $source_object->object && 'prepaid' === $source_object->card->funding ) {
465
-					$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' );
466
-					throw new WC_Stripe_Exception( print_r( $source_object, true ), $localized_message );
463
+			if ( ! apply_filters('wc_stripe_allow_prepaid_card', true)) {
464
+				if ($source_object && 'token' === $source_object->object && 'prepaid' === $source_object->card->funding) {
465
+					$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');
466
+					throw new WC_Stripe_Exception(print_r($source_object, true), $localized_message);
467 467
 				}
468 468
 			}
469 469
 
470
-			if ( empty( $prepared_source->source ) ) {
471
-				$localized_message = __( 'Payment processing failed. Please retry.', 'woocommerce-gateway-stripe' );
472
-				throw new WC_Stripe_Exception( print_r( $prepared_source, true ), $localized_message );
470
+			if (empty($prepared_source->source)) {
471
+				$localized_message = __('Payment processing failed. Please retry.', 'woocommerce-gateway-stripe');
472
+				throw new WC_Stripe_Exception(print_r($prepared_source, true), $localized_message);
473 473
 			}
474 474
 
475
-			$this->save_source_to_order( $order, $prepared_source );
475
+			$this->save_source_to_order($order, $prepared_source);
476 476
 
477 477
 			// Result from Stripe API request.
478 478
 			$response = null;
479 479
 
480
-			if ( $order->get_total() > 0 ) {
480
+			if ($order->get_total() > 0) {
481 481
 				// This will throw exception if not valid.
482
-				$this->validate_minimum_order_amount( $order );
482
+				$this->validate_minimum_order_amount($order);
483 483
 
484 484
 				/*
485 485
 				 * Check if card 3DS is required or optional with 3DS setting.
@@ -488,109 +488,109 @@  discard block
 block discarded – undo
488 488
 				 * Note that if we need to save source, the original source must be first
489 489
 				 * attached to a customer in Stripe before it can be charged.
490 490
 				 */
491
-				if ( $this->is_3ds_required( $source_object ) ) {
492
-					$response = $this->create_3ds_source( $order, $source_object );
491
+				if ($this->is_3ds_required($source_object)) {
492
+					$response = $this->create_3ds_source($order, $source_object);
493 493
 
494
-					if ( ! empty( $response->error ) ) {
494
+					if ( ! empty($response->error)) {
495 495
 						$localized_message = $response->error->message;
496 496
 
497
-						$order->add_order_note( $localized_message );
497
+						$order->add_order_note($localized_message);
498 498
 
499
-						throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message );
499
+						throw new WC_Stripe_Exception(print_r($response, true), $localized_message);
500 500
 					}
501 501
 
502 502
 					// Update order meta with 3DS source.
503
-					if ( WC_Stripe_Helper::is_pre_30() ) {
504
-						update_post_meta( $order_id, '_stripe_source_id', $response->id );
503
+					if (WC_Stripe_Helper::is_pre_30()) {
504
+						update_post_meta($order_id, '_stripe_source_id', $response->id);
505 505
 					} else {
506
-						$order->update_meta_data( '_stripe_source_id', $response->id );
506
+						$order->update_meta_data('_stripe_source_id', $response->id);
507 507
 						$order->save();
508 508
 					}
509 509
 
510
-					WC_Stripe_Logger::log( 'Info: Redirecting to 3DS...' );
510
+					WC_Stripe_Logger::log('Info: Redirecting to 3DS...');
511 511
 
512 512
 					return array(
513 513
 						'result'   => 'success',
514
-						'redirect' => esc_url_raw( $response->redirect->url ),
514
+						'redirect' => esc_url_raw($response->redirect->url),
515 515
 					);
516 516
 				}
517 517
 
518
-				WC_Stripe_Logger::log( "Info: Begin processing payment for order $order_id for the amount of {$order->get_total()}" );
518
+				WC_Stripe_Logger::log("Info: Begin processing payment for order $order_id for the amount of {$order->get_total()}");
519 519
 
520 520
 				// Make the request.
521
-				$response = WC_Stripe_API::request( $this->generate_payment_request( $order, $prepared_source ) );
521
+				$response = WC_Stripe_API::request($this->generate_payment_request($order, $prepared_source));
522 522
 
523
-				if ( ! empty( $response->error ) ) {
523
+				if ( ! empty($response->error)) {
524 524
 					// If it is an API error such connection or server, let's retry.
525
-					if ( 'api_connection_error' === $response->error->type || 'api_error' === $response->error->type ) {
526
-						if ( $retry ) {
527
-							sleep( 5 );
528
-							return $this->process_payment( $order_id, false, $force_save_source );
525
+					if ('api_connection_error' === $response->error->type || 'api_error' === $response->error->type) {
526
+						if ($retry) {
527
+							sleep(5);
528
+							return $this->process_payment($order_id, false, $force_save_source);
529 529
 						} else {
530 530
 							$localized_message = 'API connection error and retries exhausted.';
531
-							$order->add_order_note( $localized_message );
532
-							throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message );
531
+							$order->add_order_note($localized_message);
532
+							throw new WC_Stripe_Exception(print_r($response, true), $localized_message);
533 533
 						}
534 534
 					}
535 535
 
536 536
 					// We want to retry.
537
-					if ( $this->is_retryable_error( $response->error ) ) {
538
-						if ( $retry ) {
537
+					if ($this->is_retryable_error($response->error)) {
538
+						if ($retry) {
539 539
 							// Don't do anymore retries after this.
540
-							if ( 5 <= $this->retry_interval ) {
540
+							if (5 <= $this->retry_interval) {
541 541
 
542
-								return $this->process_payment( $order_id, false, $force_save_source );
542
+								return $this->process_payment($order_id, false, $force_save_source);
543 543
 							}
544 544
 
545
-							sleep( $this->retry_interval );
545
+							sleep($this->retry_interval);
546 546
 
547 547
 							$this->retry_interval++;
548
-							return $this->process_payment( $order_id, true, $force_save_source );
548
+							return $this->process_payment($order_id, true, $force_save_source);
549 549
 						} else {
550
-							$localized_message = __( 'On going requests error and retries exhausted.', 'woocommerce-gateway-stripe' );
551
-							$order->add_order_note( $localized_message );
552
-							throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message );
550
+							$localized_message = __('On going requests error and retries exhausted.', 'woocommerce-gateway-stripe');
551
+							$order->add_order_note($localized_message);
552
+							throw new WC_Stripe_Exception(print_r($response, true), $localized_message);
553 553
 						}
554 554
 					}
555 555
 
556 556
 					// Customer param wrong? The user may have been deleted on stripe's end. Remove customer_id. Can be retried without.
557
-					if ( preg_match( '/No such customer/i', $response->error->message ) && $retry ) {
558
-						if ( WC_Stripe_Helper::is_pre_30() ) {
559
-							delete_user_meta( $order->customer_user, '_stripe_customer_id' );
560
-							delete_post_meta( $order_id, '_stripe_customer_id' );
557
+					if (preg_match('/No such customer/i', $response->error->message) && $retry) {
558
+						if (WC_Stripe_Helper::is_pre_30()) {
559
+							delete_user_meta($order->customer_user, '_stripe_customer_id');
560
+							delete_post_meta($order_id, '_stripe_customer_id');
561 561
 						} else {
562
-							delete_user_meta( $order->get_customer_id(), '_stripe_customer_id' );
563
-							$order->delete_meta_data( '_stripe_customer_id' );
562
+							delete_user_meta($order->get_customer_id(), '_stripe_customer_id');
563
+							$order->delete_meta_data('_stripe_customer_id');
564 564
 							$order->save();
565 565
 						}
566 566
 
567
-						return $this->process_payment( $order_id, false, $force_save_source );
568
-					} elseif ( preg_match( '/No such token/i', $response->error->message ) && $prepared_source->token_id ) {
567
+						return $this->process_payment($order_id, false, $force_save_source);
568
+					} elseif (preg_match('/No such token/i', $response->error->message) && $prepared_source->token_id) {
569 569
 						// Source param wrong? The CARD may have been deleted on stripe's end. Remove token and show message.
570
-						$wc_token = WC_Payment_Tokens::get( $prepared_source->token_id );
570
+						$wc_token = WC_Payment_Tokens::get($prepared_source->token_id);
571 571
 						$wc_token->delete();
572
-						$localized_message = __( 'This card is no longer available and has been removed.', 'woocommerce-gateway-stripe' );
573
-						$order->add_order_note( $localized_message );
574
-						throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message );
572
+						$localized_message = __('This card is no longer available and has been removed.', 'woocommerce-gateway-stripe');
573
+						$order->add_order_note($localized_message);
574
+						throw new WC_Stripe_Exception(print_r($response, true), $localized_message);
575 575
 					}
576 576
 
577 577
 					$localized_messages = WC_Stripe_Helper::get_localized_messages();
578 578
 
579
-					if ( 'card_error' === $response->error->type ) {
580
-						$localized_message = isset( $localized_messages[ $response->error->code ] ) ? $localized_messages[ $response->error->code ] : $response->error->message;
579
+					if ('card_error' === $response->error->type) {
580
+						$localized_message = isset($localized_messages[$response->error->code]) ? $localized_messages[$response->error->code] : $response->error->message;
581 581
 					} else {
582
-						$localized_message = isset( $localized_messages[ $response->error->type ] ) ? $localized_messages[ $response->error->type ] : $response->error->message;
582
+						$localized_message = isset($localized_messages[$response->error->type]) ? $localized_messages[$response->error->type] : $response->error->message;
583 583
 					}
584 584
 
585
-					$order->add_order_note( $localized_message );
585
+					$order->add_order_note($localized_message);
586 586
 
587
-					throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message );
587
+					throw new WC_Stripe_Exception(print_r($response, true), $localized_message);
588 588
 				}
589 589
 
590
-				do_action( 'wc_gateway_stripe_process_payment', $response, $order );
590
+				do_action('wc_gateway_stripe_process_payment', $response, $order);
591 591
 
592 592
 				// Process valid response.
593
-				$this->process_response( $response, $order );
593
+				$this->process_response($response, $order);
594 594
 			} else {
595 595
 				$order->payment_complete();
596 596
 			}
@@ -601,17 +601,17 @@  discard block
 block discarded – undo
601 601
 			// Return thank you page redirect.
602 602
 			return array(
603 603
 				'result'   => 'success',
604
-				'redirect' => $this->get_return_url( $order ),
604
+				'redirect' => $this->get_return_url($order),
605 605
 			);
606 606
 
607
-		} catch ( WC_Stripe_Exception $e ) {
608
-			wc_add_notice( $e->getLocalizedMessage(), 'error' );
609
-			WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() );
607
+		} catch (WC_Stripe_Exception $e) {
608
+			wc_add_notice($e->getLocalizedMessage(), 'error');
609
+			WC_Stripe_Logger::log('Error: ' . $e->getMessage());
610 610
 
611
-			do_action( 'wc_gateway_stripe_process_payment_error', $e, $order );
611
+			do_action('wc_gateway_stripe_process_payment_error', $e, $order);
612 612
 
613
-			if ( $order->has_status( array( 'pending', 'failed' ) ) ) {
614
-				$this->send_failed_order_email( $order_id );
613
+			if ($order->has_status(array('pending', 'failed'))) {
614
+				$this->send_failed_order_email($order_id);
615 615
 			}
616 616
 
617 617
 			return array(
Please login to merge, or discard this patch.
includes/payment-methods/class-wc-gateway-stripe-sofort.php 1 patch
Spacing   +79 added lines, -79 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) {
2
+if ( ! defined('ABSPATH')) {
3 3
 	exit;
4 4
 }
5 5
 
@@ -57,9 +57,9 @@  discard block
 block discarded – undo
57 57
 	 */
58 58
 	public function __construct() {
59 59
 		$this->id                   = 'stripe_sofort';
60
-		$this->method_title         = __( 'Stripe SOFORT', 'woocommerce-gateway-stripe' );
60
+		$this->method_title         = __('Stripe SOFORT', 'woocommerce-gateway-stripe');
61 61
 		/* translators: link */
62
-		$this->method_description   = sprintf( __( 'All other general Stripe settings can be adjusted <a href="%s">here</a>.', 'woocommerce-gateway-stripe' ), admin_url( 'admin.php?page=wc-settings&tab=checkout&section=stripe' ) );
62
+		$this->method_description   = sprintf(__('All other general Stripe settings can be adjusted <a href="%s">here</a>.', 'woocommerce-gateway-stripe'), admin_url('admin.php?page=wc-settings&tab=checkout&section=stripe'));
63 63
 		$this->supports             = array(
64 64
 			'products',
65 65
 			'refunds',
@@ -71,25 +71,25 @@  discard block
 block discarded – undo
71 71
 		// Load the settings.
72 72
 		$this->init_settings();
73 73
 
74
-		$main_settings              = get_option( 'woocommerce_stripe_settings' );
75
-		$this->title                = $this->get_option( 'title' );
76
-		$this->description          = $this->get_option( 'description' );
77
-		$this->enabled              = $this->get_option( 'enabled' );
78
-		$this->testmode             = ( ! empty( $main_settings['testmode'] ) && 'yes' === $main_settings['testmode'] ) ? true : false;
79
-		$this->saved_cards          = ( ! empty( $main_settings['saved_cards'] ) && 'yes' === $main_settings['saved_cards'] ) ? true : false;
80
-		$this->publishable_key      = ! empty( $main_settings['publishable_key'] ) ? $main_settings['publishable_key'] : '';
81
-		$this->secret_key           = ! empty( $main_settings['secret_key'] ) ? $main_settings['secret_key'] : '';
82
-		$this->statement_descriptor = ! empty( $main_settings['statement_descriptor'] ) ? $main_settings['statement_descriptor'] : '';
83
-
84
-		if ( $this->testmode ) {
85
-			$this->publishable_key = ! empty( $main_settings['test_publishable_key'] ) ? $main_settings['test_publishable_key'] : '';
86
-			$this->secret_key      = ! empty( $main_settings['test_secret_key'] ) ? $main_settings['test_secret_key'] : '';
74
+		$main_settings              = get_option('woocommerce_stripe_settings');
75
+		$this->title                = $this->get_option('title');
76
+		$this->description          = $this->get_option('description');
77
+		$this->enabled              = $this->get_option('enabled');
78
+		$this->testmode             = ( ! empty($main_settings['testmode']) && 'yes' === $main_settings['testmode']) ? true : false;
79
+		$this->saved_cards          = ( ! empty($main_settings['saved_cards']) && 'yes' === $main_settings['saved_cards']) ? true : false;
80
+		$this->publishable_key      = ! empty($main_settings['publishable_key']) ? $main_settings['publishable_key'] : '';
81
+		$this->secret_key           = ! empty($main_settings['secret_key']) ? $main_settings['secret_key'] : '';
82
+		$this->statement_descriptor = ! empty($main_settings['statement_descriptor']) ? $main_settings['statement_descriptor'] : '';
83
+
84
+		if ($this->testmode) {
85
+			$this->publishable_key = ! empty($main_settings['test_publishable_key']) ? $main_settings['test_publishable_key'] : '';
86
+			$this->secret_key      = ! empty($main_settings['test_secret_key']) ? $main_settings['test_secret_key'] : '';
87 87
 		}
88 88
 
89
-		add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) );
90
-		add_action( 'admin_notices', array( $this, 'check_environment' ) );
91
-		add_action( 'admin_head', array( $this, 'remove_admin_notice' ) );
92
-		add_action( 'wp_enqueue_scripts', array( $this, 'payment_scripts' ) );
89
+		add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options'));
90
+		add_action('admin_notices', array($this, 'check_environment'));
91
+		add_action('admin_head', array($this, 'remove_admin_notice'));
92
+		add_action('wp_enqueue_scripts', array($this, 'payment_scripts'));
93 93
 	}
94 94
 
95 95
 	/**
@@ -99,19 +99,19 @@  discard block
 block discarded – undo
99 99
 	 * @version 4.0.0
100 100
 	 */
101 101
 	public function check_environment() {
102
-		if ( ! current_user_can( 'manage_woocommerce' ) ) {
102
+		if ( ! current_user_can('manage_woocommerce')) {
103 103
 			return;
104 104
 		}
105 105
 
106 106
 		$environment_warning = $this->get_environment_warning();
107 107
 
108
-		if ( $environment_warning ) {
109
-			$this->add_admin_notice( 'bad_environment', 'error', $environment_warning );
108
+		if ($environment_warning) {
109
+			$this->add_admin_notice('bad_environment', 'error', $environment_warning);
110 110
 		}
111 111
 
112
-		foreach ( (array) $this->notices as $notice_key => $notice ) {
113
-			echo "<div class='" . esc_attr( $notice['class'] ) . "'><p>";
114
-			echo wp_kses( $notice['message'], array( 'a' => array( 'href' => array() ) ) );
112
+		foreach ((array) $this->notices as $notice_key => $notice) {
113
+			echo "<div class='" . esc_attr($notice['class']) . "'><p>";
114
+			echo wp_kses($notice['message'], array('a' => array('href' => array())));
115 115
 			echo '</p></div>';
116 116
 		}
117 117
 	}
@@ -124,8 +124,8 @@  discard block
 block discarded – undo
124 124
 	 * @version 4.0.0
125 125
 	 */
126 126
 	public function get_environment_warning() {
127
-		if ( 'yes' === $this->enabled && ! in_array( get_woocommerce_currency(), $this->get_supported_currency() ) ) {
128
-			$message = __( 'SOFORT is enabled - it requires store currency to be set to Euros.', 'woocommerce-gateway-stripe' );
127
+		if ('yes' === $this->enabled && ! in_array(get_woocommerce_currency(), $this->get_supported_currency())) {
128
+			$message = __('SOFORT is enabled - it requires store currency to be set to Euros.', 'woocommerce-gateway-stripe');
129 129
 
130 130
 			return $message;
131 131
 		}
@@ -141,9 +141,9 @@  discard block
 block discarded – undo
141 141
 	 * @return array
142 142
 	 */
143 143
 	public function get_supported_currency() {
144
-		return apply_filters( 'wc_stripe_sofort_supported_currencies', array(
144
+		return apply_filters('wc_stripe_sofort_supported_currencies', array(
145 145
 			'EUR',
146
-		) );
146
+		));
147 147
 	}
148 148
 
149 149
 	/**
@@ -154,7 +154,7 @@  discard block
 block discarded – undo
154 154
 	 * @return bool
155 155
 	 */
156 156
 	public function is_available() {
157
-		if ( ! in_array( get_woocommerce_currency(), $this->get_supported_currency() ) ) {
157
+		if ( ! in_array(get_woocommerce_currency(), $this->get_supported_currency())) {
158 158
 			return false;
159 159
 		}
160 160
 
@@ -175,7 +175,7 @@  discard block
 block discarded – undo
175 175
 
176 176
 		$icons_str .= $icons['sofort'];
177 177
 
178
-		return apply_filters( 'woocommerce_gateway_icon', $icons_str, $this->id );
178
+		return apply_filters('woocommerce_gateway_icon', $icons_str, $this->id);
179 179
 	}
180 180
 
181 181
 	/**
@@ -186,19 +186,19 @@  discard block
 block discarded – undo
186 186
 	 * @access public
187 187
 	 */
188 188
 	public function payment_scripts() {
189
-		if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) && ! is_add_payment_method_page() ) {
189
+		if ( ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order']) && ! is_add_payment_method_page()) {
190 190
 			return;
191 191
 		}
192 192
 
193
-		wp_enqueue_style( 'stripe_paymentfonts' );
194
-		wp_enqueue_script( 'woocommerce_stripe' );
193
+		wp_enqueue_style('stripe_paymentfonts');
194
+		wp_enqueue_script('woocommerce_stripe');
195 195
 	}
196 196
 
197 197
 	/**
198 198
 	 * Initialize Gateway Settings Form Fields.
199 199
 	 */
200 200
 	public function init_form_fields() {
201
-		$this->form_fields = require( WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-sofort-settings.php' );
201
+		$this->form_fields = require(WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-sofort-settings.php');
202 202
 	}
203 203
 
204 204
 	/**
@@ -209,25 +209,25 @@  discard block
 block discarded – undo
209 209
 		$total = WC()->cart->total;
210 210
 
211 211
 		// If paying from order, we need to get total from order not cart.
212
-		if ( isset( $_GET['pay_for_order'] ) && ! empty( $_GET['key'] ) ) {
213
-			$order = wc_get_order( wc_get_order_id_by_order_key( wc_clean( $_GET['key'] ) ) );
212
+		if (isset($_GET['pay_for_order']) && ! empty($_GET['key'])) {
213
+			$order = wc_get_order(wc_get_order_id_by_order_key(wc_clean($_GET['key'])));
214 214
 			$total = $order->get_total();
215 215
 		}
216 216
 
217
-		if ( is_add_payment_method_page() ) {
218
-			$pay_button_text = __( 'Add Payment', 'woocommerce-gateway-stripe' );
219
-			$total        = '';
217
+		if (is_add_payment_method_page()) {
218
+			$pay_button_text = __('Add Payment', 'woocommerce-gateway-stripe');
219
+			$total = '';
220 220
 		} else {
221 221
 			$pay_button_text = '';
222 222
 		}
223 223
 
224 224
 		echo '<div
225 225
 			id="stripe-sofort-payment-data"
226
-			data-amount="' . esc_attr( WC_Stripe_Helper::get_stripe_amount( $total ) ) . '"
227
-			data-currency="' . esc_attr( strtolower( get_woocommerce_currency() ) ) . '">';
226
+			data-amount="' . esc_attr(WC_Stripe_Helper::get_stripe_amount($total)) . '"
227
+			data-currency="' . esc_attr(strtolower(get_woocommerce_currency())) . '">';
228 228
 
229
-		if ( $this->description ) {
230
-			echo apply_filters( 'wc_stripe_description', wpautop( wp_kses_post( $this->description ) ) );
229
+		if ($this->description) {
230
+			echo apply_filters('wc_stripe_description', wpautop(wp_kses_post($this->description)));
231 231
 		}
232 232
 
233 233
 		echo '</div>';
@@ -241,28 +241,28 @@  discard block
 block discarded – undo
241 241
 	 * @param object $order
242 242
 	 * @return mixed
243 243
 	 */
244
-	public function create_source( $order ) {
244
+	public function create_source($order) {
245 245
 		$currency              = WC_Stripe_Helper::is_pre_30() ? $order->get_order_currency() : $order->get_currency();
246 246
 		$bank_country          = WC_Stripe_Helper::is_pre_30() ? $order->billing_country : $order->get_billing_country();
247
-		$return_url            = $this->get_stripe_return_url( $order );
247
+		$return_url            = $this->get_stripe_return_url($order);
248 248
 		$post_data             = array();
249
-		$post_data['amount']   = WC_Stripe_Helper::get_stripe_amount( $order->get_total(), $currency );
250
-		$post_data['currency'] = strtolower( $currency );
249
+		$post_data['amount']   = WC_Stripe_Helper::get_stripe_amount($order->get_total(), $currency);
250
+		$post_data['currency'] = strtolower($currency);
251 251
 		$post_data['type']     = 'sofort';
252
-		$post_data['owner']    = $this->get_owner_details( $order );
253
-		$post_data['redirect'] = array( 'return_url' => $return_url );
252
+		$post_data['owner']    = $this->get_owner_details($order);
253
+		$post_data['redirect'] = array('return_url' => $return_url);
254 254
 		$post_data['sofort']   = array(
255 255
 			'country'            => $bank_country,
256 256
 			'preferred_language' => $this->get_locale(),
257 257
 		);
258 258
 
259
-		if ( ! empty( $this->statement_descriptor ) ) {
260
-			$post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor( $this->statement_descriptor );
259
+		if ( ! empty($this->statement_descriptor)) {
260
+			$post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor($this->statement_descriptor);
261 261
 		}
262 262
 
263
-		WC_Stripe_Logger::log( 'Info: Begin creating SOFORT source' );
263
+		WC_Stripe_Logger::log('Info: Begin creating SOFORT source');
264 264
 
265
-		return WC_Stripe_API::request( apply_filters( 'wc_stripe_sofort_source', $post_data, $order ), 'sources' );
265
+		return WC_Stripe_API::request(apply_filters('wc_stripe_sofort_source', $post_data, $order), 'sources');
266 266
 	}
267 267
 
268 268
 	/**
@@ -276,59 +276,59 @@  discard block
 block discarded – undo
276 276
 	 *
277 277
 	 * @return array|void
278 278
 	 */
279
-	public function process_payment( $order_id, $retry = true, $force_save_source = false ) {
279
+	public function process_payment($order_id, $retry = true, $force_save_source = false) {
280 280
 		try {
281
-			$order = wc_get_order( $order_id );
281
+			$order = wc_get_order($order_id);
282 282
 
283 283
 			// This will throw exception if not valid.
284
-			$this->validate_minimum_order_amount( $order );
284
+			$this->validate_minimum_order_amount($order);
285 285
 
286 286
 			// This comes from the create account checkbox in the checkout page.
287
-			$create_account = ! empty( $_POST['createaccount'] ) ? true : false;
287
+			$create_account = ! empty($_POST['createaccount']) ? true : false;
288 288
 
289
-			if ( $create_account ) {
289
+			if ($create_account) {
290 290
 				$new_customer_id     = WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id();
291
-				$new_stripe_customer = new WC_Stripe_Customer( $new_customer_id );
291
+				$new_stripe_customer = new WC_Stripe_Customer($new_customer_id);
292 292
 				$new_stripe_customer->create_customer();
293 293
 			}
294 294
 
295
-			$response = $this->create_source( $order );
295
+			$response = $this->create_source($order);
296 296
 
297
-			if ( ! empty( $response->error ) ) {
298
-				$order->add_order_note( $response->error->message );
297
+			if ( ! empty($response->error)) {
298
+				$order->add_order_note($response->error->message);
299 299
 
300 300
 				$localized_messages = WC_Stripe_Helper::get_localized_messages();
301 301
 
302
-				if ( 'invalid_sofort_country' === $response->error->code ) {
303
-					$localized_message = isset( $localized_messages[ $response->error->code ] ) ? $localized_messages[ $response->error->code ] : $response->error->message;
302
+				if ('invalid_sofort_country' === $response->error->code) {
303
+					$localized_message = isset($localized_messages[$response->error->code]) ? $localized_messages[$response->error->code] : $response->error->message;
304 304
 				} else {
305
-					$localized_message = isset( $localized_messages[ $response->error->type ] ) ? $localized_messages[ $response->error->type ] : $response->error->message;
305
+					$localized_message = isset($localized_messages[$response->error->type]) ? $localized_messages[$response->error->type] : $response->error->message;
306 306
 				}
307 307
 
308
-				throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message );
308
+				throw new WC_Stripe_Exception(print_r($response, true), $localized_message);
309 309
 			}
310 310
 
311
-			if ( WC_Stripe_Helper::is_pre_30() ) {
312
-				update_post_meta( $order_id, '_stripe_source_id', $response->id );
311
+			if (WC_Stripe_Helper::is_pre_30()) {
312
+				update_post_meta($order_id, '_stripe_source_id', $response->id);
313 313
 			} else {
314
-				$order->update_meta_data( '_stripe_source_id', $response->id );
314
+				$order->update_meta_data('_stripe_source_id', $response->id);
315 315
 				$order->save();
316 316
 			}
317 317
 
318
-			WC_Stripe_Logger::log( 'Info: Redirecting to SOFORT...' );
318
+			WC_Stripe_Logger::log('Info: Redirecting to SOFORT...');
319 319
 
320 320
 			return array(
321 321
 				'result'   => 'success',
322
-				'redirect' => esc_url_raw( $response->redirect->url ),
322
+				'redirect' => esc_url_raw($response->redirect->url),
323 323
 			);
324
-		} catch ( WC_Stripe_Exception $e ) {
325
-			wc_add_notice( $e->getLocalizedMessage(), 'error' );
326
-			WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() );
324
+		} catch (WC_Stripe_Exception $e) {
325
+			wc_add_notice($e->getLocalizedMessage(), 'error');
326
+			WC_Stripe_Logger::log('Error: ' . $e->getMessage());
327 327
 
328
-			do_action( 'wc_gateway_stripe_process_payment_error', $e, $order );
328
+			do_action('wc_gateway_stripe_process_payment_error', $e, $order);
329 329
 
330
-			if ( $order->has_status( array( 'pending', 'failed' ) ) ) {
331
-				$this->send_failed_order_email( $order_id );
330
+			if ($order->has_status(array('pending', 'failed'))) {
331
+				$this->send_failed_order_email($order_id);
332 332
 			}
333 333
 
334 334
 			return array(
Please login to merge, or discard this patch.
includes/payment-methods/class-wc-gateway-stripe-bancontact.php 1 patch
Spacing   +77 added lines, -77 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) {
2
+if ( ! defined('ABSPATH')) {
3 3
 	exit;
4 4
 }
5 5
 
@@ -57,9 +57,9 @@  discard block
 block discarded – undo
57 57
 	 */
58 58
 	public function __construct() {
59 59
 		$this->id                   = 'stripe_bancontact';
60
-		$this->method_title         = __( 'Stripe Bancontact', 'woocommerce-gateway-stripe' );
60
+		$this->method_title         = __('Stripe Bancontact', 'woocommerce-gateway-stripe');
61 61
 		/* translators: link */
62
-		$this->method_description   = sprintf( __( 'All other general Stripe settings can be adjusted <a href="%s">here</a>.', 'woocommerce-gateway-stripe' ), admin_url( 'admin.php?page=wc-settings&tab=checkout&section=stripe' ) );
62
+		$this->method_description   = sprintf(__('All other general Stripe settings can be adjusted <a href="%s">here</a>.', 'woocommerce-gateway-stripe'), admin_url('admin.php?page=wc-settings&tab=checkout&section=stripe'));
63 63
 		$this->supports             = array(
64 64
 			'products',
65 65
 			'refunds',
@@ -71,25 +71,25 @@  discard block
 block discarded – undo
71 71
 		// Load the settings.
72 72
 		$this->init_settings();
73 73
 
74
-		$main_settings              = get_option( 'woocommerce_stripe_settings' );
75
-		$this->title                = $this->get_option( 'title' );
76
-		$this->description          = $this->get_option( 'description' );
77
-		$this->enabled              = $this->get_option( 'enabled' );
78
-		$this->testmode             = ( ! empty( $main_settings['testmode'] ) && 'yes' === $main_settings['testmode'] ) ? true : false;
79
-		$this->saved_cards          = ( ! empty( $main_settings['saved_cards'] ) && 'yes' === $main_settings['saved_cards'] ) ? true : false;
80
-		$this->publishable_key      = ! empty( $main_settings['publishable_key'] ) ? $main_settings['publishable_key'] : '';
81
-		$this->secret_key           = ! empty( $main_settings['secret_key'] ) ? $main_settings['secret_key'] : '';
82
-		$this->statement_descriptor = ! empty( $main_settings['statement_descriptor'] ) ? $main_settings['statement_descriptor'] : '';
83
-
84
-		if ( $this->testmode ) {
85
-			$this->publishable_key = ! empty( $main_settings['test_publishable_key'] ) ? $main_settings['test_publishable_key'] : '';
86
-			$this->secret_key      = ! empty( $main_settings['test_secret_key'] ) ? $main_settings['test_secret_key'] : '';
74
+		$main_settings              = get_option('woocommerce_stripe_settings');
75
+		$this->title                = $this->get_option('title');
76
+		$this->description          = $this->get_option('description');
77
+		$this->enabled              = $this->get_option('enabled');
78
+		$this->testmode             = ( ! empty($main_settings['testmode']) && 'yes' === $main_settings['testmode']) ? true : false;
79
+		$this->saved_cards          = ( ! empty($main_settings['saved_cards']) && 'yes' === $main_settings['saved_cards']) ? true : false;
80
+		$this->publishable_key      = ! empty($main_settings['publishable_key']) ? $main_settings['publishable_key'] : '';
81
+		$this->secret_key           = ! empty($main_settings['secret_key']) ? $main_settings['secret_key'] : '';
82
+		$this->statement_descriptor = ! empty($main_settings['statement_descriptor']) ? $main_settings['statement_descriptor'] : '';
83
+
84
+		if ($this->testmode) {
85
+			$this->publishable_key = ! empty($main_settings['test_publishable_key']) ? $main_settings['test_publishable_key'] : '';
86
+			$this->secret_key      = ! empty($main_settings['test_secret_key']) ? $main_settings['test_secret_key'] : '';
87 87
 		}
88 88
 
89
-		add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) );
90
-		add_action( 'admin_notices', array( $this, 'check_environment' ) );
91
-		add_action( 'admin_head', array( $this, 'remove_admin_notice' ) );
92
-		add_action( 'wp_enqueue_scripts', array( $this, 'payment_scripts' ) );
89
+		add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options'));
90
+		add_action('admin_notices', array($this, 'check_environment'));
91
+		add_action('admin_head', array($this, 'remove_admin_notice'));
92
+		add_action('wp_enqueue_scripts', array($this, 'payment_scripts'));
93 93
 	}
94 94
 
95 95
 	/**
@@ -99,19 +99,19 @@  discard block
 block discarded – undo
99 99
 	 * @version 4.0.0
100 100
 	 */
101 101
 	public function check_environment() {
102
-		if ( ! current_user_can( 'manage_woocommerce' ) ) {
102
+		if ( ! current_user_can('manage_woocommerce')) {
103 103
 			return;
104 104
 		}
105 105
 
106 106
 		$environment_warning = $this->get_environment_warning();
107 107
 
108
-		if ( $environment_warning ) {
109
-			$this->add_admin_notice( 'bad_environment', 'error', $environment_warning );
108
+		if ($environment_warning) {
109
+			$this->add_admin_notice('bad_environment', 'error', $environment_warning);
110 110
 		}
111 111
 
112
-		foreach ( (array) $this->notices as $notice_key => $notice ) {
113
-			echo "<div class='" . esc_attr( $notice['class'] ) . "'><p>";
114
-			echo wp_kses( $notice['message'], array( 'a' => array( 'href' => array() ) ) );
112
+		foreach ((array) $this->notices as $notice_key => $notice) {
113
+			echo "<div class='" . esc_attr($notice['class']) . "'><p>";
114
+			echo wp_kses($notice['message'], array('a' => array('href' => array())));
115 115
 			echo '</p></div>';
116 116
 		}
117 117
 	}
@@ -124,8 +124,8 @@  discard block
 block discarded – undo
124 124
 	 * @version 4.0.0
125 125
 	 */
126 126
 	public function get_environment_warning() {
127
-		if ( 'yes' === $this->enabled && ! in_array( get_woocommerce_currency(), $this->get_supported_currency() ) ) {
128
-			$message = __( 'Bancontact is enabled - it requires store currency to be set to Euros.', 'woocommerce-gateway-stripe' );
127
+		if ('yes' === $this->enabled && ! in_array(get_woocommerce_currency(), $this->get_supported_currency())) {
128
+			$message = __('Bancontact is enabled - it requires store currency to be set to Euros.', 'woocommerce-gateway-stripe');
129 129
 
130 130
 			return $message;
131 131
 		}
@@ -141,9 +141,9 @@  discard block
 block discarded – undo
141 141
 	 * @return array
142 142
 	 */
143 143
 	public function get_supported_currency() {
144
-		return apply_filters( 'wc_stripe_bancontact_supported_currencies', array(
144
+		return apply_filters('wc_stripe_bancontact_supported_currencies', array(
145 145
 			'EUR',
146
-		) );
146
+		));
147 147
 	}
148 148
 
149 149
 	/**
@@ -154,7 +154,7 @@  discard block
 block discarded – undo
154 154
 	 * @return bool
155 155
 	 */
156 156
 	public function is_available() {
157
-		if ( ! in_array( get_woocommerce_currency(), $this->get_supported_currency() ) ) {
157
+		if ( ! in_array(get_woocommerce_currency(), $this->get_supported_currency())) {
158 158
 			return false;
159 159
 		}
160 160
 
@@ -175,7 +175,7 @@  discard block
 block discarded – undo
175 175
 
176 176
 		$icons_str .= $icons['bancontact'];
177 177
 
178
-		return apply_filters( 'woocommerce_gateway_icon', $icons_str, $this->id );
178
+		return apply_filters('woocommerce_gateway_icon', $icons_str, $this->id);
179 179
 	}
180 180
 
181 181
 	/**
@@ -186,19 +186,19 @@  discard block
 block discarded – undo
186 186
 	 * @access public
187 187
 	 */
188 188
 	public function payment_scripts() {
189
-		if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) && ! is_add_payment_method_page() ) {
189
+		if ( ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order']) && ! is_add_payment_method_page()) {
190 190
 			return;
191 191
 		}
192 192
 
193
-		wp_enqueue_style( 'stripe_paymentfonts' );
194
-		wp_enqueue_script( 'woocommerce_stripe' );
193
+		wp_enqueue_style('stripe_paymentfonts');
194
+		wp_enqueue_script('woocommerce_stripe');
195 195
 	}
196 196
 
197 197
 	/**
198 198
 	 * Initialize Gateway Settings Form Fields.
199 199
 	 */
200 200
 	public function init_form_fields() {
201
-		$this->form_fields = require( WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-bancontact-settings.php' );
201
+		$this->form_fields = require(WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-bancontact-settings.php');
202 202
 	}
203 203
 
204 204
 	/**
@@ -209,25 +209,25 @@  discard block
 block discarded – undo
209 209
 		$total = WC()->cart->total;
210 210
 
211 211
 		// If paying from order, we need to get total from order not cart.
212
-		if ( isset( $_GET['pay_for_order'] ) && ! empty( $_GET['key'] ) ) {
213
-			$order = wc_get_order( wc_get_order_id_by_order_key( wc_clean( $_GET['key'] ) ) );
212
+		if (isset($_GET['pay_for_order']) && ! empty($_GET['key'])) {
213
+			$order = wc_get_order(wc_get_order_id_by_order_key(wc_clean($_GET['key'])));
214 214
 			$total = $order->get_total();
215 215
 		}
216 216
 
217
-		if ( is_add_payment_method_page() ) {
218
-			$pay_button_text = __( 'Add Payment', 'woocommerce-gateway-stripe' );
219
-			$total        = '';
217
+		if (is_add_payment_method_page()) {
218
+			$pay_button_text = __('Add Payment', 'woocommerce-gateway-stripe');
219
+			$total = '';
220 220
 		} else {
221 221
 			$pay_button_text = '';
222 222
 		}
223 223
 
224 224
 		echo '<div
225 225
 			id="stripe-bancontact-payment-data"
226
-			data-amount="' . esc_attr( WC_Stripe_Helper::get_stripe_amount( $total ) ) . '"
227
-			data-currency="' . esc_attr( strtolower( get_woocommerce_currency() ) ) . '">';
226
+			data-amount="' . esc_attr(WC_Stripe_Helper::get_stripe_amount($total)) . '"
227
+			data-currency="' . esc_attr(strtolower(get_woocommerce_currency())) . '">';
228 228
 
229
-		if ( $this->description ) {
230
-			echo apply_filters( 'wc_stripe_description', wpautop( wp_kses_post( $this->description ) ) );
229
+		if ($this->description) {
230
+			echo apply_filters('wc_stripe_description', wpautop(wp_kses_post($this->description)));
231 231
 		}
232 232
 
233 233
 		echo '</div>';
@@ -241,25 +241,25 @@  discard block
 block discarded – undo
241 241
 	 * @param object $order
242 242
 	 * @return mixed
243 243
 	 */
244
-	public function create_source( $order ) {
244
+	public function create_source($order) {
245 245
 		$currency                = WC_Stripe_Helper::is_pre_30() ? $order->get_order_currency() : $order->get_currency();
246 246
 		$order_id                = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
247
-		$return_url              = $this->get_stripe_return_url( $order );
247
+		$return_url              = $this->get_stripe_return_url($order);
248 248
 		$post_data               = array();
249
-		$post_data['amount']     = WC_Stripe_Helper::get_stripe_amount( $order->get_total(), $currency );
250
-		$post_data['currency']   = strtolower( $currency );
249
+		$post_data['amount']     = WC_Stripe_Helper::get_stripe_amount($order->get_total(), $currency);
250
+		$post_data['currency']   = strtolower($currency);
251 251
 		$post_data['type']       = 'bancontact';
252
-		$post_data['owner']      = $this->get_owner_details( $order );
253
-		$post_data['redirect']   = array( 'return_url' => $return_url );
254
-		$post_data['bancontact'] = array( 'preferred_language' => $this->get_locale() );
252
+		$post_data['owner']      = $this->get_owner_details($order);
253
+		$post_data['redirect']   = array('return_url' => $return_url);
254
+		$post_data['bancontact'] = array('preferred_language' => $this->get_locale());
255 255
 
256
-		if ( ! empty( $this->statement_descriptor ) ) {
257
-			$post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor( $this->statement_descriptor );
256
+		if ( ! empty($this->statement_descriptor)) {
257
+			$post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor($this->statement_descriptor);
258 258
 		}
259 259
 
260
-		WC_Stripe_Logger::log( 'Info: Begin creating Bancontact source' );
260
+		WC_Stripe_Logger::log('Info: Begin creating Bancontact source');
261 261
 
262
-		return WC_Stripe_API::request( apply_filters( 'wc_stripe_bancontact_source', $post_data, $order ), 'sources' );
262
+		return WC_Stripe_API::request(apply_filters('wc_stripe_bancontact_source', $post_data, $order), 'sources');
263 263
 	}
264 264
 
265 265
 	/**
@@ -273,51 +273,51 @@  discard block
 block discarded – undo
273 273
 	 *
274 274
 	 * @return array|void
275 275
 	 */
276
-	public function process_payment( $order_id, $retry = true, $force_save_source = false ) {
276
+	public function process_payment($order_id, $retry = true, $force_save_source = false) {
277 277
 		try {
278
-			$order = wc_get_order( $order_id );
278
+			$order = wc_get_order($order_id);
279 279
 
280 280
 			// This will throw exception if not valid.
281
-			$this->validate_minimum_order_amount( $order );
281
+			$this->validate_minimum_order_amount($order);
282 282
 
283 283
 			// This comes from the create account checkbox in the checkout page.
284
-			$create_account = ! empty( $_POST['createaccount'] ) ? true : false;
284
+			$create_account = ! empty($_POST['createaccount']) ? true : false;
285 285
 
286
-			if ( $create_account ) {
286
+			if ($create_account) {
287 287
 				$new_customer_id     = WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id();
288
-				$new_stripe_customer = new WC_Stripe_Customer( $new_customer_id );
288
+				$new_stripe_customer = new WC_Stripe_Customer($new_customer_id);
289 289
 				$new_stripe_customer->create_customer();
290 290
 			}
291 291
 
292
-			$response = $this->create_source( $order );
292
+			$response = $this->create_source($order);
293 293
 
294
-			if ( ! empty( $response->error ) ) {
295
-				$order->add_order_note( $response->error->message );
294
+			if ( ! empty($response->error)) {
295
+				$order->add_order_note($response->error->message);
296 296
 
297
-				throw new WC_Stripe_Exception( print_r( $response, true ), $response->error->message );
297
+				throw new WC_Stripe_Exception(print_r($response, true), $response->error->message);
298 298
 			}
299 299
 
300
-			if ( WC_Stripe_Helper::is_pre_30() ) {
301
-				update_post_meta( $order_id, '_stripe_source_id', $response->id );
300
+			if (WC_Stripe_Helper::is_pre_30()) {
301
+				update_post_meta($order_id, '_stripe_source_id', $response->id);
302 302
 			} else {
303
-				$order->update_meta_data( '_stripe_source_id', $response->id );
303
+				$order->update_meta_data('_stripe_source_id', $response->id);
304 304
 				$order->save();
305 305
 			}
306 306
 
307
-			WC_Stripe_Logger::log( 'Info: Redirecting to Bancontact...' );
307
+			WC_Stripe_Logger::log('Info: Redirecting to Bancontact...');
308 308
 
309 309
 			return array(
310 310
 				'result'   => 'success',
311
-				'redirect' => esc_url_raw( $response->redirect->url ),
311
+				'redirect' => esc_url_raw($response->redirect->url),
312 312
 			);
313
-		} catch ( WC_Stripe_Exception $e ) {
314
-			wc_add_notice( $e->getLocalizedMessage(), 'error' );
315
-			WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() );
313
+		} catch (WC_Stripe_Exception $e) {
314
+			wc_add_notice($e->getLocalizedMessage(), 'error');
315
+			WC_Stripe_Logger::log('Error: ' . $e->getMessage());
316 316
 
317
-			do_action( 'wc_gateway_stripe_process_payment_error', $e, $order );
317
+			do_action('wc_gateway_stripe_process_payment_error', $e, $order);
318 318
 
319
-			if ( $order->has_status( array( 'pending', 'failed' ) ) ) {
320
-				$this->send_failed_order_email( $order_id );
319
+			if ($order->has_status(array('pending', 'failed'))) {
320
+				$this->send_failed_order_email($order_id);
321 321
 			}
322 322
 
323 323
 			return array(
Please login to merge, or discard this patch.
includes/abstracts/abstract-wc-stripe-payment-gateway.php 1 patch
Spacing   +207 added lines, -208 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
 
@@ -21,7 +21,7 @@  discard block
 block discarded – undo
21 21
 	 * @since 4.0.5
22 22
 	 * @param array $error
23 23
 	 */
24
-	public function is_retryable_error( $error ) {
24
+	public function is_retryable_error($error) {
25 25
 		return (
26 26
 			'invalid_request_error' === $error->type ||
27 27
 			'idempotency_error' === $error->type ||
@@ -33,11 +33,11 @@  discard block
 block discarded – undo
33 33
 	 * Check if this gateway is enabled
34 34
 	 */
35 35
 	public function is_available() {
36
-		if ( 'yes' === $this->enabled ) {
37
-			if ( ! $this->testmode && is_checkout() && ! is_ssl() ) {
36
+		if ('yes' === $this->enabled) {
37
+			if ( ! $this->testmode && is_checkout() && ! is_ssl()) {
38 38
 				return false;
39 39
 			}
40
-			if ( ! $this->secret_key || ! $this->publishable_key ) {
40
+			if ( ! $this->secret_key || ! $this->publishable_key) {
41 41
 				return false;
42 42
 			}
43 43
 			return true;
@@ -52,8 +52,8 @@  discard block
 block discarded – undo
52 52
 	 * @since 4.0.0
53 53
 	 * @version 4.0.0
54 54
 	 */
55
-	public function add_admin_notice( $slug, $class, $message ) {
56
-		$this->notices[ $slug ] = array(
55
+	public function add_admin_notice($slug, $class, $message) {
56
+		$this->notices[$slug] = array(
57 57
 			'class'   => $class,
58 58
 			'message' => $message,
59 59
 		);
@@ -66,8 +66,8 @@  discard block
 block discarded – undo
66 66
 	 * @version 4.0.0
67 67
 	 */
68 68
 	public function remove_admin_notice() {
69
-		if ( did_action( 'woocommerce_update_options' ) ) {
70
-			remove_action( 'admin_notices', array( $this, 'check_environment' ) );
69
+		if (did_action('woocommerce_update_options')) {
70
+			remove_action('admin_notices', array($this, 'check_environment'));
71 71
 		}
72 72
 	}
73 73
 
@@ -79,7 +79,7 @@  discard block
 block discarded – undo
79 79
 	 * @return array
80 80
 	 */
81 81
 	public function payment_icons() {
82
-		return apply_filters( 'wc_stripe_payment_icons', array(
82
+		return apply_filters('wc_stripe_payment_icons', array(
83 83
 			'visa'       => '<i class="stripe-pf stripe-pf-visa stripe-pf-right" alt="Visa" aria-hidden="true"></i>',
84 84
 			'amex'       => '<i class="stripe-pf stripe-pf-american-express stripe-pf-right" alt="Amex" aria-hidden="true"></i>',
85 85
 			'mastercard' => '<i class="stripe-pf stripe-pf-mastercard stripe-pf-right" alt="Mastercard" aria-hidden="true"></i>',
@@ -96,7 +96,7 @@  discard block
 block discarded – undo
96 96
 			'eps'        => '<i class="stripe-pf stripe-pf-eps stripe-pf-right" alt="EPS" aria-hidden="true"></i>',
97 97
 			'sofort'     => '<i class="stripe-pf stripe-pf-sofort stripe-pf-right" alt="SOFORT" aria-hidden="true"></i>',
98 98
 			'sepa'       => '<i class="stripe-pf stripe-pf-sepa stripe-pf-right" alt="SEPA" aria-hidden="true"></i>',
99
-		) );
99
+		));
100 100
 	}
101 101
 
102 102
 	/**
@@ -107,10 +107,10 @@  discard block
 block discarded – undo
107 107
 	 * @version 4.0.0
108 108
 	 * @param object $order
109 109
 	 */
110
-	public function validate_minimum_order_amount( $order ) {
111
-		if ( $order->get_total() * 100 < WC_Stripe_Helper::get_minimum_amount() ) {
110
+	public function validate_minimum_order_amount($order) {
111
+		if ($order->get_total() * 100 < WC_Stripe_Helper::get_minimum_amount()) {
112 112
 			/* translators: 1) dollar amount */
113
-			throw new WC_Stripe_Exception( 'Did not meet minimum amount', sprintf( __( 'Sorry, the minimum allowed order total is %1$s to use this payment method.', 'woocommerce-gateway-stripe' ), wc_price( WC_Stripe_Helper::get_minimum_amount() / 100 ) ) );
113
+			throw new WC_Stripe_Exception('Did not meet minimum amount', sprintf(__('Sorry, the minimum allowed order total is %1$s to use this payment method.', 'woocommerce-gateway-stripe'), wc_price(WC_Stripe_Helper::get_minimum_amount() / 100)));
114 114
 		}
115 115
 	}
116 116
 
@@ -120,14 +120,14 @@  discard block
 block discarded – undo
120 120
 	 * @since 4.0.0
121 121
 	 * @version 4.0.0
122 122
 	 */
123
-	public function get_transaction_url( $order ) {
124
-		if ( $this->testmode ) {
123
+	public function get_transaction_url($order) {
124
+		if ($this->testmode) {
125 125
 			$this->view_transaction_url = 'https://dashboard.stripe.com/test/payments/%s';
126 126
 		} else {
127 127
 			$this->view_transaction_url = 'https://dashboard.stripe.com/payments/%s';
128 128
 		}
129 129
 
130
-		return parent::get_transaction_url( $order );
130
+		return parent::get_transaction_url($order);
131 131
 	}
132 132
 
133 133
 	/**
@@ -136,15 +136,15 @@  discard block
 block discarded – undo
136 136
 	 * @since 4.0.0
137 137
 	 * @version 4.0.0
138 138
 	 */
139
-	public function get_stripe_customer_id( $order ) {
140
-		$customer = get_user_meta( WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id(), '_stripe_customer_id', true );
139
+	public function get_stripe_customer_id($order) {
140
+		$customer = get_user_meta(WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id(), '_stripe_customer_id', true);
141 141
 
142
-		if ( empty( $customer ) ) {
142
+		if (empty($customer)) {
143 143
 			// Try to get it via the order.
144
-			if ( WC_Stripe_Helper::is_pre_30() ) {
145
-				return get_post_meta( $order->id, '_stripe_customer_id', true );
144
+			if (WC_Stripe_Helper::is_pre_30()) {
145
+				return get_post_meta($order->id, '_stripe_customer_id', true);
146 146
 			} else {
147
-				return $order->get_meta( '_stripe_customer_id', true );
147
+				return $order->get_meta('_stripe_customer_id', true);
148 148
 			}
149 149
 		} else {
150 150
 			return $customer;
@@ -161,9 +161,9 @@  discard block
 block discarded – undo
161 161
 	 * @param object $order
162 162
 	 * @param int $id Stripe session id.
163 163
 	 */
164
-	public function get_stripe_return_url( $order = null, $id = null ) {
165
-		if ( is_object( $order ) ) {
166
-			if ( empty( $id ) ) {
164
+	public function get_stripe_return_url($order = null, $id = null) {
165
+		if (is_object($order)) {
166
+			if (empty($id)) {
167 167
 				$id = uniqid();
168 168
 			}
169 169
 
@@ -174,10 +174,10 @@  discard block
 block discarded – undo
174 174
 				'order_id'       => $order_id,
175 175
 			);
176 176
 
177
-			return esc_url_raw( add_query_arg( $args, $this->get_return_url( $order ) ) );
177
+			return esc_url_raw(add_query_arg($args, $this->get_return_url($order)));
178 178
 		}
179 179
 
180
-		return esc_url_raw( add_query_arg( array( 'utm_nooverride' => '1' ), $this->get_return_url() ) );
180
+		return esc_url_raw(add_query_arg(array('utm_nooverride' => '1'), $this->get_return_url()));
181 181
 	}
182 182
 
183 183
 	/**
@@ -185,8 +185,8 @@  discard block
 block discarded – undo
185 185
 	 * @param  int  $order_id
186 186
 	 * @return boolean
187 187
 	 */
188
-	public function has_subscription( $order_id ) {
189
-		return ( function_exists( 'wcs_order_contains_subscription' ) && ( wcs_order_contains_subscription( $order_id ) || wcs_is_subscription( $order_id ) || wcs_order_contains_renewal( $order_id ) ) );
188
+	public function has_subscription($order_id) {
189
+		return (function_exists('wcs_order_contains_subscription') && (wcs_order_contains_subscription($order_id) || wcs_is_subscription($order_id) || wcs_order_contains_renewal($order_id)));
190 190
 	}
191 191
 
192 192
 	/**
@@ -198,34 +198,33 @@  discard block
 block discarded – undo
198 198
 	 * @param  object $source
199 199
 	 * @return array()
200 200
 	 */
201
-	public function generate_payment_request( $order, $source ) {
202
-		$settings                          = get_option( 'woocommerce_stripe_settings', array() );
203
-		$statement_descriptor              = ! empty( $settings['statement_descriptor'] ) ? str_replace( "'", '', $settings['statement_descriptor'] ) : '';
204
-		$capture                           = ! empty( $settings['capture'] ) && 'yes' === $settings['capture'] ? true : false;
201
+	public function generate_payment_request($order, $source) {
202
+		$settings                          = get_option('woocommerce_stripe_settings', array());
203
+		$statement_descriptor              = ! empty($settings['statement_descriptor']) ? str_replace("'", '', $settings['statement_descriptor']) : '';
204
+		$capture                           = ! empty($settings['capture']) && 'yes' === $settings['capture'] ? true : false;
205 205
 		$post_data                         = array();
206
-		$post_data['currency']             = strtolower( WC_Stripe_Helper::is_pre_30() ? $order->get_order_currency() : $order->get_currency() );
207
-		$post_data['amount']               = WC_Stripe_Helper::get_stripe_amount( $order->get_total(), $post_data['currency'] );
206
+		$post_data['currency']             = strtolower(WC_Stripe_Helper::is_pre_30() ? $order->get_order_currency() : $order->get_currency());
207
+		$post_data['amount']               = WC_Stripe_Helper::get_stripe_amount($order->get_total(), $post_data['currency']);
208 208
 		/* translators: 1) blog name 2) order number */
209
-		$post_data['description']          = sprintf( __( '%1$s - Order %2$s', 'woocommerce-gateway-stripe' ), wp_specialchars_decode( get_bloginfo( 'name' ), ENT_QUOTES ), $order->get_order_number() );
209
+		$post_data['description']          = sprintf(__('%1$s - Order %2$s', 'woocommerce-gateway-stripe'), wp_specialchars_decode(get_bloginfo('name'), ENT_QUOTES), $order->get_order_number());
210 210
 		$billing_email      = WC_Stripe_Helper::is_pre_30() ? $order->billing_email : $order->get_billing_email();
211 211
 		$billing_first_name = WC_Stripe_Helper::is_pre_30() ? $order->billing_first_name : $order->get_billing_first_name();
212 212
 		$billing_last_name  = WC_Stripe_Helper::is_pre_30() ? $order->billing_last_name : $order->get_billing_last_name();
213 213
 
214
-		if ( ! empty( $billing_email ) && apply_filters( 'wc_stripe_send_stripe_receipt', false ) ) {
214
+		if ( ! empty($billing_email) && apply_filters('wc_stripe_send_stripe_receipt', false)) {
215 215
 			$post_data['receipt_email'] = $billing_email;
216 216
 		}
217 217
 
218
-		switch ( WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method() ) {
219
-			case 'stripe':
220
-				if ( ! empty( $statement_descriptor ) ) {
221
-					$post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor( $statement_descriptor );
218
+		switch (WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method()) {
219
+			case 'stripe' : if ( ! empty($statement_descriptor)) {
220
+					$post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor($statement_descriptor);
222 221
 				}
223 222
 
224 223
 				$post_data['capture'] = $capture ? 'true' : 'false';
225 224
 				break;
226 225
 			case 'stripe_sepa':
227
-				if ( ! empty( $statement_descriptor ) ) {
228
-					$post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor( $statement_descriptor );
226
+				if ( ! empty($statement_descriptor)) {
227
+					$post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor($statement_descriptor);
229 228
 				}
230 229
 				break;
231 230
 		}
@@ -233,25 +232,25 @@  discard block
 block discarded – undo
233 232
 		$post_data['expand[]'] = 'balance_transaction';
234 233
 
235 234
 		$metadata = array(
236
-			__( 'customer_name', 'woocommerce-gateway-stripe' ) => sanitize_text_field( $billing_first_name ) . ' ' . sanitize_text_field( $billing_last_name ),
237
-			__( 'customer_email', 'woocommerce-gateway-stripe' ) => sanitize_email( $billing_email ),
235
+			__('customer_name', 'woocommerce-gateway-stripe') => sanitize_text_field($billing_first_name) . ' ' . sanitize_text_field($billing_last_name),
236
+			__('customer_email', 'woocommerce-gateway-stripe') => sanitize_email($billing_email),
238 237
 			'order_id' => WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(),
239 238
 		);
240 239
 
241
-		if ( $this->has_subscription( WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id() ) ) {
240
+		if ($this->has_subscription(WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id())) {
242 241
 			$metadata += array(
243 242
 				'payment_type' => 'recurring',
244
-				'site_url'     => esc_url( get_site_url() ),
243
+				'site_url'     => esc_url(get_site_url()),
245 244
 			);
246 245
 		}
247 246
 
248
-		$post_data['metadata'] = apply_filters( 'wc_stripe_payment_metadata', $metadata, $order, $source );
247
+		$post_data['metadata'] = apply_filters('wc_stripe_payment_metadata', $metadata, $order, $source);
249 248
 
250
-		if ( $source->customer ) {
249
+		if ($source->customer) {
251 250
 			$post_data['customer'] = $source->customer;
252 251
 		}
253 252
 
254
-		if ( $source->source ) {
253
+		if ($source->source) {
255 254
 			$post_data['source'] = $source->source;
256 255
 		}
257 256
 
@@ -263,79 +262,79 @@  discard block
 block discarded – undo
263 262
 		 * @param WC_Order $order
264 263
 		 * @param object $source
265 264
 		 */
266
-		return apply_filters( 'wc_stripe_generate_payment_request', $post_data, $order, $source );
265
+		return apply_filters('wc_stripe_generate_payment_request', $post_data, $order, $source);
267 266
 	}
268 267
 
269 268
 	/**
270 269
 	 * Store extra meta data for an order from a Stripe Response.
271 270
 	 */
272
-	public function process_response( $response, $order ) {
273
-		WC_Stripe_Logger::log( 'Processing response: ' . print_r( $response, true ) );
271
+	public function process_response($response, $order) {
272
+		WC_Stripe_Logger::log('Processing response: ' . print_r($response, true));
274 273
 
275 274
 		$order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
276 275
 
277
-		$captured = ( isset( $response->captured ) && $response->captured ) ? 'yes' : 'no';
276
+		$captured = (isset($response->captured) && $response->captured) ? 'yes' : 'no';
278 277
 
279 278
 		// Store charge data
280
-		WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, '_stripe_charge_captured', $captured ) : $order->update_meta_data( '_stripe_charge_captured', $captured );
279
+		WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, '_stripe_charge_captured', $captured) : $order->update_meta_data('_stripe_charge_captured', $captured);
281 280
 
282 281
 		// Store other data such as fees
283
-		if ( isset( $response->balance_transaction ) && isset( $response->balance_transaction->fee ) ) {
282
+		if (isset($response->balance_transaction) && isset($response->balance_transaction->fee)) {
284 283
 			// Fees and Net needs to both come from Stripe to be accurate as the returned
285 284
 			// values are in the local currency of the Stripe account, not from WC.
286
-			$fee = ! empty( $response->balance_transaction->fee ) ? WC_Stripe_Helper::format_balance_fee( $response->balance_transaction, 'fee' ) : 0;
287
-			$net = ! empty( $response->balance_transaction->net ) ? WC_Stripe_Helper::format_balance_fee( $response->balance_transaction, 'net' ) : 0;
288
-			WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, self::META_NAME_FEE, $fee ) : $order->update_meta_data( self::META_NAME_FEE, $fee );
289
-			WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, self::META_NAME_NET, $net ) : $order->update_meta_data( self::META_NAME_NET, $net );
285
+			$fee = ! empty($response->balance_transaction->fee) ? WC_Stripe_Helper::format_balance_fee($response->balance_transaction, 'fee') : 0;
286
+			$net = ! empty($response->balance_transaction->net) ? WC_Stripe_Helper::format_balance_fee($response->balance_transaction, 'net') : 0;
287
+			WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, self::META_NAME_FEE, $fee) : $order->update_meta_data(self::META_NAME_FEE, $fee);
288
+			WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, self::META_NAME_NET, $net) : $order->update_meta_data(self::META_NAME_NET, $net);
290 289
 		}
291 290
 
292
-		if ( 'yes' === $captured ) {
291
+		if ('yes' === $captured) {
293 292
 			/**
294 293
 			 * Charge can be captured but in a pending state. Payment methods
295 294
 			 * that are asynchronous may take couple days to clear. Webhook will
296 295
 			 * take care of the status changes.
297 296
 			 */
298
-			if ( 'pending' === $response->status ) {
299
-				$order_stock_reduced = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_order_stock_reduced', true ) : $order->get_meta( '_order_stock_reduced', true );
297
+			if ('pending' === $response->status) {
298
+				$order_stock_reduced = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_order_stock_reduced', true) : $order->get_meta('_order_stock_reduced', true);
300 299
 
301
-				if ( ! $order_stock_reduced ) {
302
-					WC_Stripe_Helper::is_pre_30() ? $order->reduce_order_stock() : wc_reduce_stock_levels( $order_id );
300
+				if ( ! $order_stock_reduced) {
301
+					WC_Stripe_Helper::is_pre_30() ? $order->reduce_order_stock() : wc_reduce_stock_levels($order_id);
303 302
 				}
304 303
 
305
-				WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, '_transaction_id', $response->id ) : $order->set_transaction_id( $response->id );
304
+				WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, '_transaction_id', $response->id) : $order->set_transaction_id($response->id);
306 305
 				/* translators: transaction id */
307
-				$order->update_status( 'on-hold', sprintf( __( 'Stripe charge awaiting payment: %s.', 'woocommerce-gateway-stripe' ), $response->id ) );
306
+				$order->update_status('on-hold', sprintf(__('Stripe charge awaiting payment: %s.', 'woocommerce-gateway-stripe'), $response->id));
308 307
 			}
309 308
 
310
-			if ( 'succeeded' === $response->status ) {
311
-				$order->payment_complete( $response->id );
309
+			if ('succeeded' === $response->status) {
310
+				$order->payment_complete($response->id);
312 311
 
313 312
 				/* translators: transaction id */
314
-				$message = sprintf( __( 'Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe' ), $response->id );
315
-				$order->add_order_note( $message );
313
+				$message = sprintf(__('Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe'), $response->id);
314
+				$order->add_order_note($message);
316 315
 			}
317 316
 
318
-			if ( 'failed' === $response->status ) {
319
-				$localized_message = __( 'Payment processing failed. Please retry.', 'woocommerce-gateway-stripe' );
320
-				$order->add_order_note( $localized_message );
321
-				throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message );
317
+			if ('failed' === $response->status) {
318
+				$localized_message = __('Payment processing failed. Please retry.', 'woocommerce-gateway-stripe');
319
+				$order->add_order_note($localized_message);
320
+				throw new WC_Stripe_Exception(print_r($response, true), $localized_message);
322 321
 			}
323 322
 		} else {
324
-			WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, '_transaction_id', $response->id ) : $order->set_transaction_id( $response->id );
323
+			WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, '_transaction_id', $response->id) : $order->set_transaction_id($response->id);
325 324
 
326
-			if ( $order->has_status( array( 'pending', 'failed' ) ) ) {
327
-				WC_Stripe_Helper::is_pre_30() ? $order->reduce_order_stock() : wc_reduce_stock_levels( $order_id );
325
+			if ($order->has_status(array('pending', 'failed'))) {
326
+				WC_Stripe_Helper::is_pre_30() ? $order->reduce_order_stock() : wc_reduce_stock_levels($order_id);
328 327
 			}
329 328
 
330 329
 			/* translators: transaction id */
331
-			$order->update_status( 'on-hold', sprintf( __( 'Stripe charge authorized (Charge ID: %s). Process order to take payment, or cancel to remove the pre-authorization.', 'woocommerce-gateway-stripe' ), $response->id ) );
330
+			$order->update_status('on-hold', sprintf(__('Stripe charge authorized (Charge ID: %s). Process order to take payment, or cancel to remove the pre-authorization.', 'woocommerce-gateway-stripe'), $response->id));
332 331
 		}
333 332
 
334
-		if ( is_callable( array( $order, 'save' ) ) ) {
333
+		if (is_callable(array($order, 'save'))) {
335 334
 			$order->save();
336 335
 		}
337 336
 
338
-		do_action( 'wc_gateway_stripe_process_response', $response, $order );
337
+		do_action('wc_gateway_stripe_process_response', $response, $order);
339 338
 
340 339
 		return $response;
341 340
 	}
@@ -348,10 +347,10 @@  discard block
 block discarded – undo
348 347
 	 * @param int $order_id
349 348
 	 * @return null
350 349
 	 */
351
-	public function send_failed_order_email( $order_id ) {
350
+	public function send_failed_order_email($order_id) {
352 351
 		$emails = WC()->mailer()->get_emails();
353
-		if ( ! empty( $emails ) && ! empty( $order_id ) ) {
354
-			$emails['WC_Email_Failed_Order']->trigger( $order_id );
352
+		if ( ! empty($emails) && ! empty($order_id)) {
353
+			$emails['WC_Email_Failed_Order']->trigger($order_id);
355 354
 		}
356 355
 	}
357 356
 
@@ -363,7 +362,7 @@  discard block
 block discarded – undo
363 362
 	 * @param object $order
364 363
 	 * @return object $details
365 364
 	 */
366
-	public function get_owner_details( $order ) {
365
+	public function get_owner_details($order) {
367 366
 		$billing_first_name = WC_Stripe_Helper::is_pre_30() ? $order->billing_first_name : $order->get_billing_first_name();
368 367
 		$billing_last_name  = WC_Stripe_Helper::is_pre_30() ? $order->billing_last_name : $order->get_billing_last_name();
369 368
 
@@ -374,8 +373,8 @@  discard block
 block discarded – undo
374 373
 
375 374
 		$phone                             = WC_Stripe_Helper::is_pre_30() ? $order->billing_phone : $order->get_billing_phone();
376 375
 
377
-		if ( ! empty( $phone ) ) {
378
-			$details['phone']              = $phone;
376
+		if ( ! empty($phone)) {
377
+			$details['phone'] = $phone;
379 378
 		}
380 379
 
381 380
 		$details['address']['line1']       = WC_Stripe_Helper::is_pre_30() ? $order->billing_address_1 : $order->get_billing_address_1();
@@ -385,7 +384,7 @@  discard block
 block discarded – undo
385 384
 		$details['address']['postal_code'] = WC_Stripe_Helper::is_pre_30() ? $order->billing_postcode : $order->get_billing_postcode();
386 385
 		$details['address']['country']     = WC_Stripe_Helper::is_pre_30() ? $order->billing_country : $order->get_billing_country();
387 386
 
388
-		return (object) apply_filters( 'wc_stripe_owner_details', $details, $order );
387
+		return (object) apply_filters('wc_stripe_owner_details', $details, $order);
389 388
 	}
390 389
 
391 390
 	/**
@@ -394,16 +393,16 @@  discard block
 block discarded – undo
394 393
 	 * @since 4.0.3
395 394
 	 */
396 395
 	public function get_source_object() {
397
-		$source = ! empty( $_POST['stripe_source'] ) ? wc_clean( $_POST['stripe_source'] ) : '';
396
+		$source = ! empty($_POST['stripe_source']) ? wc_clean($_POST['stripe_source']) : '';
398 397
 
399
-		if ( empty( $source ) ) {
398
+		if (empty($source)) {
400 399
 			return '';
401 400
 		}
402 401
 
403
-		$source_object = WC_Stripe_API::retrieve( 'sources/' . $source );
402
+		$source_object = WC_Stripe_API::retrieve('sources/' . $source);
404 403
 
405
-		if ( ! empty( $source_object->error ) ) {
406
-			throw new WC_Stripe_Exception( print_r( $source_object, true ), $source_object->error->message );
404
+		if ( ! empty($source_object->error)) {
405
+			throw new WC_Stripe_Exception(print_r($source_object, true), $source_object->error->message);
407 406
 		}
408 407
 
409 408
 		return $source_object;
@@ -416,11 +415,11 @@  discard block
 block discarded – undo
416 415
 	 * @param object $source_object
417 416
 	 * @return bool
418 417
 	 */
419
-	public function is_3ds_required( $source_object ) {
418
+	public function is_3ds_required($source_object) {
420 419
 		return (
421
-			$source_object && ! empty( $source_object->card ) ) &&
422
-			( 'card' === $source_object->type && 'required' === $source_object->card->three_d_secure ||
423
-			( $this->three_d_secure && 'optional' === $source_object->card->three_d_secure )
420
+			$source_object && ! empty($source_object->card) ) &&
421
+			('card' === $source_object->type && 'required' === $source_object->card->three_d_secure ||
422
+			($this->three_d_secure && 'optional' === $source_object->card->three_d_secure)
424 423
 		);
425 424
 	}
426 425
 
@@ -431,8 +430,8 @@  discard block
 block discarded – undo
431 430
 	 * @param object $source_object
432 431
 	 * @return bool
433 432
 	 */
434
-	public function is_3ds_card( $source_object ) {
435
-		return ( $source_object && 'three_d_secure' === $source_object->type );
433
+	public function is_3ds_card($source_object) {
434
+		return ($source_object && 'three_d_secure' === $source_object->type);
436 435
 	}
437 436
 
438 437
 	/**
@@ -445,22 +444,22 @@  discard block
 block discarded – undo
445 444
 	 * @param string $return_url
446 445
 	 * @return mixed
447 446
 	 */
448
-	public function create_3ds_source( $order, $source_object, $return_url = '' ) {
447
+	public function create_3ds_source($order, $source_object, $return_url = '') {
449 448
 		$currency                    = WC_Stripe_Helper::is_pre_30() ? $order->get_order_currency() : $order->get_currency();
450 449
 		$order_id                    = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
451
-		$return_url                  = empty( $return_url ) ? $this->get_stripe_return_url( $order ) : $return_url;
450
+		$return_url                  = empty($return_url) ? $this->get_stripe_return_url($order) : $return_url;
452 451
 
453 452
 		$post_data                   = array();
454
-		$post_data['amount']         = WC_Stripe_Helper::get_stripe_amount( $order->get_total(), $currency );
455
-		$post_data['currency']       = strtolower( $currency );
453
+		$post_data['amount']         = WC_Stripe_Helper::get_stripe_amount($order->get_total(), $currency);
454
+		$post_data['currency']       = strtolower($currency);
456 455
 		$post_data['type']           = 'three_d_secure';
457
-		$post_data['owner']          = $this->get_owner_details( $order );
458
-		$post_data['three_d_secure'] = array( 'card' => $source_object->id );
459
-		$post_data['redirect']       = array( 'return_url' => $return_url );
456
+		$post_data['owner']          = $this->get_owner_details($order);
457
+		$post_data['three_d_secure'] = array('card' => $source_object->id);
458
+		$post_data['redirect']       = array('return_url' => $return_url);
460 459
 
461
-		WC_Stripe_Logger::log( 'Info: Begin creating 3DS source...' );
460
+		WC_Stripe_Logger::log('Info: Begin creating 3DS source...');
462 461
 
463
-		return WC_Stripe_API::request( apply_filters( 'wc_stripe_3ds_source', $post_data, $order ), 'sources' );
462
+		return WC_Stripe_API::request(apply_filters('wc_stripe_3ds_source', $post_data, $order), 'sources');
464 463
 	}
465 464
 
466 465
 	/**
@@ -477,54 +476,54 @@  discard block
 block discarded – undo
477 476
 	 * @throws Exception When card was not added or for and invalid card.
478 477
 	 * @return object
479 478
 	 */
480
-	public function prepare_source( $source_object = '', $user_id, $force_save_source = false ) {
481
-		$customer           = new WC_Stripe_Customer( $user_id );
479
+	public function prepare_source($source_object = '', $user_id, $force_save_source = false) {
480
+		$customer           = new WC_Stripe_Customer($user_id);
482 481
 		$set_customer       = true;
483
-		$force_save_source  = apply_filters( 'wc_stripe_force_save_source', $force_save_source, $customer );
482
+		$force_save_source  = apply_filters('wc_stripe_force_save_source', $force_save_source, $customer);
484 483
 		$source_id          = '';
485 484
 		$wc_token_id        = false;
486
-		$payment_method     = isset( $_POST['payment_method'] ) ? wc_clean( $_POST['payment_method'] ) : 'stripe';
485
+		$payment_method     = isset($_POST['payment_method']) ? wc_clean($_POST['payment_method']) : 'stripe';
487 486
 
488 487
 		// New CC info was entered and we have a new source to process.
489
-		if ( ! empty( $source_object ) ) {
488
+		if ( ! empty($source_object)) {
490 489
 			$source_id = $source_object->id;
491 490
 
492 491
 			// This checks to see if customer opted to save the payment method to file.
493
-			$maybe_saved_card = isset( $_POST[ 'wc-' . $payment_method . '-new-payment-method' ] ) && ! empty( $_POST[ 'wc-' . $payment_method . '-new-payment-method' ] );
492
+			$maybe_saved_card = isset($_POST['wc-' . $payment_method . '-new-payment-method']) && ! empty($_POST['wc-' . $payment_method . '-new-payment-method']);
494 493
 
495 494
 			/**
496 495
 			 * This is true if the user wants to store the card to their account.
497 496
 			 * Criteria to save to file is they are logged in, they opted to save or product requirements and the source is
498 497
 			 * actually reusable. Either that or force_save_source is true.
499 498
 			 */
500
-			if ( ( $user_id && $this->saved_cards && $maybe_saved_card && 'reusable' === $source_object->usage ) || $force_save_source ) {
501
-				$response = $customer->add_source( $source_object->id );
499
+			if (($user_id && $this->saved_cards && $maybe_saved_card && 'reusable' === $source_object->usage) || $force_save_source) {
500
+				$response = $customer->add_source($source_object->id);
502 501
 
503
-				if ( ! empty( $response->error ) ) {
504
-					throw new WC_Stripe_Exception( print_r( $response, true ), $response->error->message );
502
+				if ( ! empty($response->error)) {
503
+					throw new WC_Stripe_Exception(print_r($response, true), $response->error->message);
505 504
 				}
506 505
 			}
507
-		} elseif ( isset( $_POST[ 'wc-' . $payment_method . '-payment-token' ] ) && 'new' !== $_POST[ 'wc-' . $payment_method . '-payment-token' ] ) {
506
+		} elseif (isset($_POST['wc-' . $payment_method . '-payment-token']) && 'new' !== $_POST['wc-' . $payment_method . '-payment-token']) {
508 507
 			// Use an existing token, and then process the payment
509
-			$wc_token_id = wc_clean( $_POST[ 'wc-' . $payment_method . '-payment-token' ] );
510
-			$wc_token    = WC_Payment_Tokens::get( $wc_token_id );
508
+			$wc_token_id = wc_clean($_POST['wc-' . $payment_method . '-payment-token']);
509
+			$wc_token    = WC_Payment_Tokens::get($wc_token_id);
511 510
 
512
-			if ( ! $wc_token || $wc_token->get_user_id() !== get_current_user_id() ) {
513
-				WC()->session->set( 'refresh_totals', true );
514
-				throw new WC_Stripe_Exception( 'Invalid payment method', __( 'Invalid payment method. Please input a new card number.', 'woocommerce-gateway-stripe' ) );
511
+			if ( ! $wc_token || $wc_token->get_user_id() !== get_current_user_id()) {
512
+				WC()->session->set('refresh_totals', true);
513
+				throw new WC_Stripe_Exception('Invalid payment method', __('Invalid payment method. Please input a new card number.', 'woocommerce-gateway-stripe'));
515 514
 			}
516 515
 
517 516
 			$source_id = $wc_token->get_token();
518
-		} elseif ( isset( $_POST['stripe_token'] ) && 'new' !== $_POST['stripe_token'] ) {
519
-			$stripe_token     = wc_clean( $_POST['stripe_token'] );
520
-			$maybe_saved_card = isset( $_POST[ 'wc-' . $payment_method . '-new-payment-method' ] ) && ! empty( $_POST[ 'wc-' . $payment_method . '-new-payment-method' ] );
517
+		} elseif (isset($_POST['stripe_token']) && 'new' !== $_POST['stripe_token']) {
518
+			$stripe_token     = wc_clean($_POST['stripe_token']);
519
+			$maybe_saved_card = isset($_POST['wc-' . $payment_method . '-new-payment-method']) && ! empty($_POST['wc-' . $payment_method . '-new-payment-method']);
521 520
 
522 521
 			// This is true if the user wants to store the card to their account.
523
-			if ( ( $user_id && $this->saved_cards && $maybe_saved_card ) || $force_save_source ) {
524
-				$response = $customer->add_source( $stripe_token );
522
+			if (($user_id && $this->saved_cards && $maybe_saved_card) || $force_save_source) {
523
+				$response = $customer->add_source($stripe_token);
525 524
 
526
-				if ( ! empty( $response->error ) ) {
527
-					throw new WC_Stripe_Exception( print_r( $response, true ), $response->error->message );
525
+				if ( ! empty($response->error)) {
526
+					throw new WC_Stripe_Exception(print_r($response, true), $response->error->message);
528 527
 				}
529 528
 			} else {
530 529
 				$set_customer = false;
@@ -532,7 +531,7 @@  discard block
 block discarded – undo
532 531
 			}
533 532
 		}
534 533
 
535
-		if ( ! $set_customer ) {
534
+		if ( ! $set_customer) {
536 535
 			$customer_id = false;
537 536
 		} else {
538 537
 			$customer_id = $customer->get_id() ? $customer->get_id() : false;
@@ -558,37 +557,37 @@  discard block
 block discarded – undo
558 557
 	 * @param object $order
559 558
 	 * @return object
560 559
 	 */
561
-	public function prepare_order_source( $order = null ) {
560
+	public function prepare_order_source($order = null) {
562 561
 		$stripe_customer = new WC_Stripe_Customer();
563 562
 		$stripe_source   = false;
564 563
 		$token_id        = false;
565 564
 
566
-		if ( $order ) {
565
+		if ($order) {
567 566
 			$order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
568 567
 
569
-			$stripe_customer_id = get_post_meta( $order_id, '_stripe_customer_id', true );
568
+			$stripe_customer_id = get_post_meta($order_id, '_stripe_customer_id', true);
570 569
 
571
-			if ( $stripe_customer_id ) {
572
-				$stripe_customer->set_id( $stripe_customer_id );
570
+			if ($stripe_customer_id) {
571
+				$stripe_customer->set_id($stripe_customer_id);
573 572
 			}
574 573
 
575
-			$source_id = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_stripe_source_id', true ) : $order->get_meta( '_stripe_source_id', true );
574
+			$source_id = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_stripe_source_id', true) : $order->get_meta('_stripe_source_id', true);
576 575
 
577 576
 			// Since 4.0.0, we changed card to source so we need to account for that.
578
-			if ( empty( $source_id ) ) {
579
-				$source_id = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_stripe_card_id', true ) : $order->get_meta( '_stripe_card_id', true );
577
+			if (empty($source_id)) {
578
+				$source_id = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_stripe_card_id', true) : $order->get_meta('_stripe_card_id', true);
580 579
 
581 580
 				// Take this opportunity to update the key name.
582
-				WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, '_stripe_source_id', $source_id ) : $order->update_meta_data( '_stripe_source_id', $source_id );
581
+				WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, '_stripe_source_id', $source_id) : $order->update_meta_data('_stripe_source_id', $source_id);
583 582
 
584
-				if ( is_callable( array( $order, 'save' ) ) ) {
583
+				if (is_callable(array($order, 'save'))) {
585 584
 					$order->save();
586 585
 				}
587 586
 			}
588 587
 
589
-			if ( $source_id ) {
588
+			if ($source_id) {
590 589
 				$stripe_source = $source_id;
591
-			} elseif ( apply_filters( 'wc_stripe_use_default_customer_source', true ) ) {
590
+			} elseif (apply_filters('wc_stripe_use_default_customer_source', true)) {
592 591
 				/*
593 592
 				 * We can attempt to charge the customer's default source
594 593
 				 * by sending empty source id.
@@ -612,27 +611,27 @@  discard block
 block discarded – undo
612 611
 	 * @param WC_Order $order For to which the source applies.
613 612
 	 * @param stdClass $source Source information.
614 613
 	 */
615
-	public function save_source_to_order( $order, $source ) {
614
+	public function save_source_to_order($order, $source) {
616 615
 		$order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
617 616
 
618 617
 		// Store source in the order.
619
-		if ( $source->customer ) {
620
-			if ( WC_Stripe_Helper::is_pre_30() ) {
621
-				update_post_meta( $order_id, '_stripe_customer_id', $source->customer );
618
+		if ($source->customer) {
619
+			if (WC_Stripe_Helper::is_pre_30()) {
620
+				update_post_meta($order_id, '_stripe_customer_id', $source->customer);
622 621
 			} else {
623
-				$order->update_meta_data( '_stripe_customer_id', $source->customer );
622
+				$order->update_meta_data('_stripe_customer_id', $source->customer);
624 623
 			}
625 624
 		}
626 625
 
627
-		if ( $source->source ) {
628
-			if ( WC_Stripe_Helper::is_pre_30() ) {
629
-				update_post_meta( $order_id, '_stripe_source_id', $source->source );
626
+		if ($source->source) {
627
+			if (WC_Stripe_Helper::is_pre_30()) {
628
+				update_post_meta($order_id, '_stripe_source_id', $source->source);
630 629
 			} else {
631
-				$order->update_meta_data( '_stripe_source_id', $source->source );
630
+				$order->update_meta_data('_stripe_source_id', $source->source);
632 631
 			}
633 632
 		}
634 633
 
635
-		if ( is_callable( array( $order, 'save' ) ) ) {
634
+		if (is_callable(array($order, 'save'))) {
636 635
 			$order->save();
637 636
 		}
638 637
 	}
@@ -646,27 +645,27 @@  discard block
 block discarded – undo
646 645
 	 * @param object $order The order object
647 646
 	 * @param int $balance_transaction_id
648 647
 	 */
649
-	public function update_fees( $order, $balance_transaction_id ) {
648
+	public function update_fees($order, $balance_transaction_id) {
650 649
 		$order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
651 650
 
652
-		$balance_transaction = WC_Stripe_API::retrieve( 'balance/history/' . $balance_transaction_id );
651
+		$balance_transaction = WC_Stripe_API::retrieve('balance/history/' . $balance_transaction_id);
653 652
 
654
-		if ( empty( $balance_transaction->error ) ) {
655
-			if ( isset( $balance_transaction ) && isset( $balance_transaction->fee ) ) {
653
+		if (empty($balance_transaction->error)) {
654
+			if (isset($balance_transaction) && isset($balance_transaction->fee)) {
656 655
 				// Fees and Net needs to both come from Stripe to be accurate as the returned
657 656
 				// values are in the local currency of the Stripe account, not from WC.
658
-				$fee = ! empty( $balance_transaction->fee ) ? WC_Stripe_Helper::format_balance_fee( $balance_transaction, 'fee' ) : 0;
659
-				$net = ! empty( $balance_transaction->net ) ? WC_Stripe_Helper::format_balance_fee( $balance_transaction, 'net' ) : 0;
657
+				$fee = ! empty($balance_transaction->fee) ? WC_Stripe_Helper::format_balance_fee($balance_transaction, 'fee') : 0;
658
+				$net = ! empty($balance_transaction->net) ? WC_Stripe_Helper::format_balance_fee($balance_transaction, 'net') : 0;
660 659
 
661
-				WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, self::META_NAME_FEE, $fee ) : $order->update_meta_data( self::META_NAME_FEE, $fee );
662
-				WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, self::META_NAME_NET, $net ) : $order->update_meta_data( self::META_NAME_NET, $net );
660
+				WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, self::META_NAME_FEE, $fee) : $order->update_meta_data(self::META_NAME_FEE, $fee);
661
+				WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, self::META_NAME_NET, $net) : $order->update_meta_data(self::META_NAME_NET, $net);
663 662
 
664
-				if ( is_callable( array( $order, 'save' ) ) ) {
663
+				if (is_callable(array($order, 'save'))) {
665 664
 					$order->save();
666 665
 				}
667 666
 			}
668 667
 		} else {
669
-			WC_Stripe_Logger::log( "Unable to update fees/net meta for order: {$order_id}" );
668
+			WC_Stripe_Logger::log("Unable to update fees/net meta for order: {$order_id}");
670 669
 		}
671 670
 	}
672 671
 
@@ -679,33 +678,33 @@  discard block
 block discarded – undo
679 678
 	 * @param  float $amount
680 679
 	 * @return bool
681 680
 	 */
682
-	public function process_refund( $order_id, $amount = null, $reason = '' ) {
683
-		$order = wc_get_order( $order_id );
681
+	public function process_refund($order_id, $amount = null, $reason = '') {
682
+		$order = wc_get_order($order_id);
684 683
 
685
-		if ( ! $order || ! $order->get_transaction_id() ) {
684
+		if ( ! $order || ! $order->get_transaction_id()) {
686 685
 			return false;
687 686
 		}
688 687
 
689 688
 		$request = array();
690 689
 
691
-		if ( WC_Stripe_Helper::is_pre_30() ) {
692
-			$order_currency = get_post_meta( $order_id, '_order_currency', true );
693
-			$captured       = get_post_meta( $order_id, '_stripe_charge_captured', true );
690
+		if (WC_Stripe_Helper::is_pre_30()) {
691
+			$order_currency = get_post_meta($order_id, '_order_currency', true);
692
+			$captured       = get_post_meta($order_id, '_stripe_charge_captured', true);
694 693
 		} else {
695 694
 			$order_currency = $order->get_currency();
696
-			$captured       = $order->get_meta( '_stripe_charge_captured', true );
695
+			$captured       = $order->get_meta('_stripe_charge_captured', true);
697 696
 		}
698 697
 
699
-		if ( ! is_null( $amount ) ) {
700
-			$request['amount'] = WC_Stripe_Helper::get_stripe_amount( $amount, $order_currency );
698
+		if ( ! is_null($amount)) {
699
+			$request['amount'] = WC_Stripe_Helper::get_stripe_amount($amount, $order_currency);
701 700
 		}
702 701
 
703 702
 		// If order is only authorized, don't pass amount.
704
-		if ( 'yes' !== $captured ) {
705
-			unset( $request['amount'] );
703
+		if ('yes' !== $captured) {
704
+			unset($request['amount']);
706 705
 		}
707 706
 
708
-		if ( $reason ) {
707
+		if ($reason) {
709 708
 			$request['metadata'] = array(
710 709
 				'reason' => $reason,
711 710
 			);
@@ -713,33 +712,33 @@  discard block
 block discarded – undo
713 712
 
714 713
 		$request['charge'] = $order->get_transaction_id();
715 714
 
716
-		WC_Stripe_Logger::log( "Info: Beginning refund for order {$order->get_transaction_id()} for the amount of {$amount}" );
715
+		WC_Stripe_Logger::log("Info: Beginning refund for order {$order->get_transaction_id()} for the amount of {$amount}");
717 716
 
718
-		$response = WC_Stripe_API::request( $request, 'refunds' );
717
+		$response = WC_Stripe_API::request($request, 'refunds');
719 718
 
720
-		if ( ! empty( $response->error ) ) {
721
-			WC_Stripe_Logger::log( 'Error: ' . $response->error->message );
719
+		if ( ! empty($response->error)) {
720
+			WC_Stripe_Logger::log('Error: ' . $response->error->message);
722 721
 
723 722
 			return $response;
724 723
 
725
-		} elseif ( ! empty( $response->id ) ) {
726
-			WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, '_stripe_refund_id', $response->id ) : $order->update_meta_data( '_stripe_refund_id', $response->id );
724
+		} elseif ( ! empty($response->id)) {
725
+			WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, '_stripe_refund_id', $response->id) : $order->update_meta_data('_stripe_refund_id', $response->id);
727 726
 
728
-			$amount = wc_price( $response->amount / 100 );
727
+			$amount = wc_price($response->amount / 100);
729 728
 
730
-			if ( in_array( strtolower( $order->get_currency() ), WC_Stripe_Helper::no_decimal_currencies() ) ) {
731
-				$amount = wc_price( $response->amount );
729
+			if (in_array(strtolower($order->get_currency()), WC_Stripe_Helper::no_decimal_currencies())) {
730
+				$amount = wc_price($response->amount);
732 731
 			}
733 732
 
734
-			if ( isset( $response->balance_transaction ) ) {
735
-				$this->update_fees( $order, $response->balance_transaction );
733
+			if (isset($response->balance_transaction)) {
734
+				$this->update_fees($order, $response->balance_transaction);
736 735
 			}
737 736
 
738 737
 			/* translators: 1) dollar amount 2) transaction id 3) refund message */
739
-			$refund_message = ( isset( $captured ) && 'yes' === $captured ) ? sprintf( __( 'Refunded %1$s - Refund ID: %2$s - Reason: %3$s', 'woocommerce-gateway-stripe' ), $amount, $response->id, $reason ) : __( 'Pre-Authorization Released', 'woocommerce-gateway-stripe' );
738
+			$refund_message = (isset($captured) && 'yes' === $captured) ? sprintf(__('Refunded %1$s - Refund ID: %2$s - Reason: %3$s', 'woocommerce-gateway-stripe'), $amount, $response->id, $reason) : __('Pre-Authorization Released', 'woocommerce-gateway-stripe');
740 739
 
741
-			$order->add_order_note( $refund_message );
742
-			WC_Stripe_Logger::log( 'Success: ' . html_entity_decode( strip_tags( $refund_message ) ) );
740
+			$order->add_order_note($refund_message);
741
+			WC_Stripe_Logger::log('Success: ' . html_entity_decode(strip_tags($refund_message)));
743 742
 
744 743
 			return true;
745 744
 		}
@@ -754,44 +753,44 @@  discard block
 block discarded – undo
754 753
 	 */
755 754
 	public function add_payment_method() {
756 755
 		$error     = false;
757
-		$error_msg = __( 'There was a problem adding the card.', 'woocommerce-gateway-stripe' );
756
+		$error_msg = __('There was a problem adding the card.', 'woocommerce-gateway-stripe');
758 757
 		$source_id = '';
759 758
 
760
-		if ( empty( $_POST['stripe_source'] ) && empty( $_POST['stripe_token'] ) || ! is_user_logged_in() ) {
759
+		if (empty($_POST['stripe_source']) && empty($_POST['stripe_token']) || ! is_user_logged_in()) {
761 760
 			$error = true;
762 761
 		}
763 762
 
764
-		$stripe_customer = new WC_Stripe_Customer( get_current_user_id() );
763
+		$stripe_customer = new WC_Stripe_Customer(get_current_user_id());
765 764
 
766
-		$source = ! empty( $_POST['stripe_source'] ) ? wc_clean( $_POST['stripe_source'] ) : '';
765
+		$source = ! empty($_POST['stripe_source']) ? wc_clean($_POST['stripe_source']) : '';
767 766
 
768
-		$source_object = WC_Stripe_API::retrieve( 'sources/' . $source );
767
+		$source_object = WC_Stripe_API::retrieve('sources/' . $source);
769 768
 
770
-		if ( isset( $source_object ) ) {
771
-			if ( ! empty( $source_object->error ) ) {
769
+		if (isset($source_object)) {
770
+			if ( ! empty($source_object->error)) {
772 771
 				$error = true;
773 772
 			}
774 773
 
775 774
 			$source_id = $source_object->id;
776
-		} elseif ( isset( $_POST['stripe_token'] ) ) {
777
-			$source_id = wc_clean( $_POST['stripe_token'] );
775
+		} elseif (isset($_POST['stripe_token'])) {
776
+			$source_id = wc_clean($_POST['stripe_token']);
778 777
 		}
779 778
 
780
-		$response = $stripe_customer->add_source( $source_id );
779
+		$response = $stripe_customer->add_source($source_id);
781 780
 
782
-		if ( ! $response || is_wp_error( $response ) || ! empty( $response->error ) ) {
781
+		if ( ! $response || is_wp_error($response) || ! empty($response->error)) {
783 782
 			$error = true;
784 783
 		}
785 784
 
786
-		if ( $error ) {
787
-			wc_add_notice( $error_msg, 'error' );
788
-			WC_Stripe_Logger::log( 'Add payment method Error: ' . $error_msg );
785
+		if ($error) {
786
+			wc_add_notice($error_msg, 'error');
787
+			WC_Stripe_Logger::log('Add payment method Error: ' . $error_msg);
789 788
 			return;
790 789
 		}
791 790
 
792 791
 		return array(
793 792
 			'result'   => 'success',
794
-			'redirect' => wc_get_endpoint_url( 'payment-methods' ),
793
+			'redirect' => wc_get_endpoint_url('payment-methods'),
795 794
 		);
796 795
 	}
797 796
 
@@ -808,10 +807,10 @@  discard block
 block discarded – undo
808 807
 		 * Stripe expects Norwegian to only be passed NO.
809 808
 		 * But WP has different dialects.
810 809
 		 */
811
-		if ( 'NO' === substr( $locale, 3, 2 ) ) {
810
+		if ('NO' === substr($locale, 3, 2)) {
812 811
 			$locale = 'no';
813 812
 		} else {
814
-			$locale = substr( get_locale(), 0, 2 );
813
+			$locale = substr(get_locale(), 0, 2);
815 814
 		}
816 815
 
817 816
 		return $locale;
Please login to merge, or discard this patch.