Completed
Pull Request — master (#117)
by Roy
02:28
created
includes/class-wc-gateway-stripe.php 1 patch
Spacing   +216 added lines, -216 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
 
@@ -99,8 +99,8 @@  discard block
 block discarded – undo
99 99
 	 */
100 100
 	public function __construct() {
101 101
 		$this->id                   = 'stripe';
102
-		$this->method_title         = __( 'Stripe', 'woocommerce-gateway-stripe' );
103
-		$this->method_description   = __( 'Stripe works by adding credit card fields on the checkout and then sending the details to Stripe for verification.', 'woocommerce-gateway-stripe' );
102
+		$this->method_title         = __('Stripe', 'woocommerce-gateway-stripe');
103
+		$this->method_description   = __('Stripe works by adding credit card fields on the checkout and then sending the details to Stripe for verification.', 'woocommerce-gateway-stripe');
104 104
 		$this->has_fields           = true;
105 105
 		$this->view_transaction_url = 'https://dashboard.stripe.com/payments/%s';
106 106
 		$this->supports             = array(
@@ -128,37 +128,37 @@  discard block
 block discarded – undo
128 128
 		$this->init_settings();
129 129
 
130 130
 		// Get setting values.
131
-		$this->title                  = $this->get_option( 'title' );
132
-		$this->description            = $this->get_option( 'description' );
133
-		$this->enabled                = $this->get_option( 'enabled' );
134
-		$this->testmode               = 'yes' === $this->get_option( 'testmode' );
135
-		$this->capture                = 'yes' === $this->get_option( 'capture', 'yes' );
136
-		$this->stripe_checkout        = 'yes' === $this->get_option( 'stripe_checkout' );
137
-		$this->stripe_checkout_locale = $this->get_option( 'stripe_checkout_locale' );
138
-		$this->stripe_checkout_image  = $this->get_option( 'stripe_checkout_image', '' );
139
-		$this->saved_cards            = 'yes' === $this->get_option( 'saved_cards' );
140
-		$this->secret_key             = $this->testmode ? $this->get_option( 'test_secret_key' ) : $this->get_option( 'secret_key' );
141
-		$this->publishable_key        = $this->testmode ? $this->get_option( 'test_publishable_key' ) : $this->get_option( 'publishable_key' );
142
-		$this->bitcoin                = 'USD' === strtoupper( get_woocommerce_currency() ) && 'yes' === $this->get_option( 'stripe_bitcoin' );
143
-		$this->apple_pay              = 'yes' === $this->get_option( 'apple_pay' );
144
-		$this->logging                = 'yes' === $this->get_option( 'logging' );
145
-		$this->allow_remember_me      = 'yes' === $this->get_option( 'allow_remember_me', 'no' );
131
+		$this->title                  = $this->get_option('title');
132
+		$this->description            = $this->get_option('description');
133
+		$this->enabled                = $this->get_option('enabled');
134
+		$this->testmode               = 'yes' === $this->get_option('testmode');
135
+		$this->capture                = 'yes' === $this->get_option('capture', 'yes');
136
+		$this->stripe_checkout        = 'yes' === $this->get_option('stripe_checkout');
137
+		$this->stripe_checkout_locale = $this->get_option('stripe_checkout_locale');
138
+		$this->stripe_checkout_image  = $this->get_option('stripe_checkout_image', '');
139
+		$this->saved_cards            = 'yes' === $this->get_option('saved_cards');
140
+		$this->secret_key             = $this->testmode ? $this->get_option('test_secret_key') : $this->get_option('secret_key');
141
+		$this->publishable_key        = $this->testmode ? $this->get_option('test_publishable_key') : $this->get_option('publishable_key');
142
+		$this->bitcoin                = 'USD' === strtoupper(get_woocommerce_currency()) && 'yes' === $this->get_option('stripe_bitcoin');
143
+		$this->apple_pay              = 'yes' === $this->get_option('apple_pay');
144
+		$this->logging                = 'yes' === $this->get_option('logging');
145
+		$this->allow_remember_me      = 'yes' === $this->get_option('allow_remember_me', 'no');
146 146
 
147
-		if ( $this->stripe_checkout ) {
148
-			$this->order_button_text = __( 'Continue to payment', 'woocommerce-gateway-stripe' );
147
+		if ($this->stripe_checkout) {
148
+			$this->order_button_text = __('Continue to payment', 'woocommerce-gateway-stripe');
149 149
 		}
150 150
 
151
-		if ( $this->testmode ) {
152
-			$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">Testing Stripe</a>" for more card numbers.', 'woocommerce-gateway-stripe' ), 'https://stripe.com/docs/testing' );
153
-			$this->description  = trim( $this->description );
151
+		if ($this->testmode) {
152
+			$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">Testing Stripe</a>" for more card numbers.', 'woocommerce-gateway-stripe'), 'https://stripe.com/docs/testing');
153
+			$this->description  = trim($this->description);
154 154
 		}
155 155
 
156
-		WC_Stripe_API::set_secret_key( $this->secret_key );
156
+		WC_Stripe_API::set_secret_key($this->secret_key);
157 157
 
158 158
 		// Hooks.
159
-		add_action( 'wp_enqueue_scripts', array( $this, 'payment_scripts' ) );
160
-		add_action( 'admin_notices', array( $this, 'admin_notices' ) );
161
-		add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) );
159
+		add_action('wp_enqueue_scripts', array($this, 'payment_scripts'));
160
+		add_action('admin_notices', array($this, 'admin_notices'));
161
+		add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options'));
162 162
 	}
163 163
 
164 164
 	/**
@@ -168,24 +168,24 @@  discard block
 block discarded – undo
168 168
 	 * @return string
169 169
 	 */
170 170
 	public function get_icon() {
171
-		$ext   = version_compare( WC()->version, '2.6', '>=' ) ? '.svg' : '.png';
172
-		$style = version_compare( WC()->version, '2.6', '>=' ) ? 'style="margin-left: 0.3em"' : '';
171
+		$ext   = version_compare(WC()->version, '2.6', '>=') ? '.svg' : '.png';
172
+		$style = version_compare(WC()->version, '2.6', '>=') ? 'style="margin-left: 0.3em"' : '';
173 173
 
174
-		$icon  = '<img src="' . WC_HTTPS::force_https_url( WC()->plugin_url() . '/assets/images/icons/credit-cards/visa' . $ext ) . '" alt="Visa" width="32" ' . $style . ' />';
175
-		$icon .= '<img src="' . WC_HTTPS::force_https_url( WC()->plugin_url() . '/assets/images/icons/credit-cards/mastercard' . $ext ) . '" alt="Mastercard" width="32" ' . $style . ' />';
176
-		$icon .= '<img src="' . WC_HTTPS::force_https_url( WC()->plugin_url() . '/assets/images/icons/credit-cards/amex' . $ext ) . '" alt="Amex" width="32" ' . $style . ' />';
174
+		$icon  = '<img src="' . WC_HTTPS::force_https_url(WC()->plugin_url() . '/assets/images/icons/credit-cards/visa' . $ext) . '" alt="Visa" width="32" ' . $style . ' />';
175
+		$icon .= '<img src="' . WC_HTTPS::force_https_url(WC()->plugin_url() . '/assets/images/icons/credit-cards/mastercard' . $ext) . '" alt="Mastercard" width="32" ' . $style . ' />';
176
+		$icon .= '<img src="' . WC_HTTPS::force_https_url(WC()->plugin_url() . '/assets/images/icons/credit-cards/amex' . $ext) . '" alt="Amex" width="32" ' . $style . ' />';
177 177
 
178
-		if ( 'USD' === get_woocommerce_currency() ) {
179
-			$icon .= '<img src="' . WC_HTTPS::force_https_url( WC()->plugin_url() . '/assets/images/icons/credit-cards/discover' . $ext ) . '" alt="Discover" width="32" ' . $style . ' />';
180
-			$icon .= '<img src="' . WC_HTTPS::force_https_url( WC()->plugin_url() . '/assets/images/icons/credit-cards/jcb' . $ext ) . '" alt="JCB" width="32" ' . $style . ' />';
181
-			$icon .= '<img src="' . WC_HTTPS::force_https_url( WC()->plugin_url() . '/assets/images/icons/credit-cards/diners' . $ext ) . '" alt="Diners" width="32" ' . $style . ' />';
178
+		if ('USD' === get_woocommerce_currency()) {
179
+			$icon .= '<img src="' . WC_HTTPS::force_https_url(WC()->plugin_url() . '/assets/images/icons/credit-cards/discover' . $ext) . '" alt="Discover" width="32" ' . $style . ' />';
180
+			$icon .= '<img src="' . WC_HTTPS::force_https_url(WC()->plugin_url() . '/assets/images/icons/credit-cards/jcb' . $ext) . '" alt="JCB" width="32" ' . $style . ' />';
181
+			$icon .= '<img src="' . WC_HTTPS::force_https_url(WC()->plugin_url() . '/assets/images/icons/credit-cards/diners' . $ext) . '" alt="Diners" width="32" ' . $style . ' />';
182 182
 		}
183 183
 
184
-		if ( $this->bitcoin && $this->stripe_checkout ) {
185
-			$icon .= '<img src="' . WC_HTTPS::force_https_url( plugins_url( '/assets/images/bitcoin' . $ext, WC_STRIPE_MAIN_FILE ) ) . '" alt="Bitcoin" width="24" ' . $style . ' />';
184
+		if ($this->bitcoin && $this->stripe_checkout) {
185
+			$icon .= '<img src="' . WC_HTTPS::force_https_url(plugins_url('/assets/images/bitcoin' . $ext, WC_STRIPE_MAIN_FILE)) . '" alt="Bitcoin" width="24" ' . $style . ' />';
186 186
 		}
187 187
 
188
-		return apply_filters( 'woocommerce_gateway_icon', $icon, $this->id );
188
+		return apply_filters('woocommerce_gateway_icon', $icon, $this->id);
189 189
 	}
190 190
 
191 191
 	/**
@@ -196,11 +196,11 @@  discard block
 block discarded – undo
196 196
 	 *
197 197
 	 * @return float|int
198 198
 	 */
199
-	public function get_stripe_amount( $total, $currency = '' ) {
200
-		if ( ! $currency ) {
199
+	public function get_stripe_amount($total, $currency = '') {
200
+		if ( ! $currency) {
201 201
 			$currency = get_woocommerce_currency();
202 202
 		}
203
-		switch ( strtoupper( $currency ) ) {
203
+		switch (strtoupper($currency)) {
204 204
 			// Zero decimal currencies.
205 205
 			case 'BIF' :
206 206
 			case 'CLP' :
@@ -217,10 +217,10 @@  discard block
 block discarded – undo
217 217
 			case 'XAF' :
218 218
 			case 'XOF' :
219 219
 			case 'XPF' :
220
-				$total = absint( $total );
220
+				$total = absint($total);
221 221
 				break;
222 222
 			default :
223
-				$total = round( $total, 2 ) * 100; // In cents.
223
+				$total = round($total, 2) * 100; // In cents.
224 224
 				break;
225 225
 		}
226 226
 		return $total;
@@ -230,13 +230,13 @@  discard block
 block discarded – undo
230 230
 	 * Check if SSL is enabled and notify the user
231 231
 	 */
232 232
 	public function admin_notices() {
233
-		if ( 'no' === $this->enabled ) {
233
+		if ('no' === $this->enabled) {
234 234
 			return;
235 235
 		}
236 236
 
237 237
 		// Show message if enabled and FORCE SSL is disabled and WordpressHTTPS plugin is not detected.
238
-		if ( ( function_exists( 'wc_site_is_https' ) && ! wc_site_is_https() ) && ( 'no' === get_option( 'woocommerce_force_ssl_checkout' ) && ! class_exists( 'WordPressHTTPS' ) ) ) {
239
-			echo '<div class="error stripe-ssl-message"><p>' . sprintf( __( 'Stripe is enabled, but the <a href="%s">force SSL option</a> is disabled; your checkout may not be secure! Please enable SSL and ensure your server has a valid SSL certificate - Stripe will only work in test mode.', 'woocommerce-gateway-stripe' ), admin_url( 'admin.php?page=wc-settings&tab=checkout' ) ) . '</p></div>';
238
+		if ((function_exists('wc_site_is_https') && ! wc_site_is_https()) && ('no' === get_option('woocommerce_force_ssl_checkout') && ! class_exists('WordPressHTTPS'))) {
239
+			echo '<div class="error stripe-ssl-message"><p>' . sprintf(__('Stripe is enabled, but the <a href="%s">force SSL option</a> is disabled; your checkout may not be secure! Please enable SSL and ensure your server has a valid SSL certificate - Stripe will only work in test mode.', 'woocommerce-gateway-stripe'), admin_url('admin.php?page=wc-settings&tab=checkout')) . '</p></div>';
240 240
 		}
241 241
 	}
242 242
 
@@ -244,11 +244,11 @@  discard block
 block discarded – undo
244 244
 	 * Check if this gateway is enabled
245 245
 	 */
246 246
 	public function is_available() {
247
-		if ( 'yes' === $this->enabled ) {
248
-			if ( ! $this->testmode && is_checkout() && ! is_ssl() ) {
247
+		if ('yes' === $this->enabled) {
248
+			if ( ! $this->testmode && is_checkout() && ! is_ssl()) {
249 249
 				return false;
250 250
 			}
251
-			if ( ! $this->secret_key || ! $this->publishable_key ) {
251
+			if ( ! $this->secret_key || ! $this->publishable_key) {
252 252
 				return false;
253 253
 			}
254 254
 			return true;
@@ -260,9 +260,9 @@  discard block
 block discarded – undo
260 260
 	 * Initialise Gateway Settings Form Fields
261 261
 	 */
262 262
 	public function init_form_fields() {
263
-		$this->form_fields = include( 'settings-stripe.php' );
263
+		$this->form_fields = include('settings-stripe.php');
264 264
 
265
-		wc_enqueue_js( "
265
+		wc_enqueue_js("
266 266
 			jQuery( function( $ ) {
267 267
 				$( document.body ).on( 'change', '#woocommerce_stripe_testmode', function() {
268 268
 					var test_secret_key = $( '#woocommerce_stripe_test_secret_key' ).parents( 'tr' ).eq( 0 ),
@@ -299,7 +299,7 @@  discard block
 block discarded – undo
299 299
 					var value = $( this ).val();
300 300
 
301 301
 					if ( value.indexOf( '_test_' ) >= 0 ) {
302
-						$( this ).css( 'border-color', 'red' ).after( '<span class=\"description stripe-error-description\" style=\"color:red; display:block;\">" . __( 'This is not a valid live key. Live keys start with "sk_live_" and "pk_live_".', 'woocommerce-gateway-stripe' ) . "</span>' );
302
+						$( this ).css( 'border-color', 'red' ).after( '<span class=\"description stripe-error-description\" style=\"color:red; display:block;\">" . __('This is not a valid live key. Live keys start with "sk_live_" and "pk_live_".', 'woocommerce-gateway-stripe') . "</span>' );
303 303
 					} else {
304 304
 						$( this ).css( 'border-color', '' );
305 305
 						$( '.stripe-error-description', $( this ).parent() ).remove();
@@ -310,7 +310,7 @@  discard block
 block discarded – undo
310 310
 					var value = $( this ).val();
311 311
 
312 312
 					if ( value.indexOf( '_live_' ) >= 0 ) {
313
-						$( this ).css( 'border-color', 'red' ).after( '<span class=\"description stripe-error-description\" style=\"color:red; display:block;\">" . __( 'This is not a valid test key. Test keys start with "sk_test_" and "pk_test_".', 'woocommerce-gateway-stripe' ) . "</span>' );
313
+						$( this ).css( 'border-color', 'red' ).after( '<span class=\"description stripe-error-description\" style=\"color:red; display:block;\">" . __('This is not a valid test key. Test keys start with "sk_test_" and "pk_test_".', 'woocommerce-gateway-stripe') . "</span>' );
314 314
 					} else {
315 315
 						$( this ).css( 'border-color', '' );
316 316
 						$( '.stripe-error-description', $( this ).parent() ).remove();
@@ -325,54 +325,54 @@  discard block
 block discarded – undo
325 325
 	 */
326 326
 	public function payment_fields() {
327 327
 		$user                 = wp_get_current_user();
328
-		$display_tokenization = $this->supports( 'tokenization' ) && is_checkout() && $this->saved_cards;
328
+		$display_tokenization = $this->supports('tokenization') && is_checkout() && $this->saved_cards;
329 329
 		$total                = WC()->cart->total;
330 330
 
331 331
 		// If paying from order, we need to get total from order not cart.
332
-		if ( isset( $_GET['pay_for_order'] ) && isset( $_GET['key'] ) ) {
333
-			$order = wc_get_order( wc_get_order_id_by_order_key( wc_clean( $_GET['key'] ) ) );
332
+		if (isset($_GET['pay_for_order']) && isset($_GET['key'])) {
333
+			$order = wc_get_order(wc_get_order_id_by_order_key(wc_clean($_GET['key'])));
334 334
 			$total = $order->get_total();
335 335
 		}
336 336
 
337
-		if ( $user->ID ) {
338
-			$user_email = get_user_meta( $user->ID, 'billing_email', true );
337
+		if ($user->ID) {
338
+			$user_email = get_user_meta($user->ID, 'billing_email', true);
339 339
 			$user_email = $user_email ? $user_email : $user->user_email;
340 340
 		} else {
341 341
 			$user_email = '';
342 342
 		}
343 343
 
344
-		if ( is_add_payment_method_page() ) {
345
-			$pay_button_text = __( 'Add Card', 'woocommerce-gateway-stripe' );
344
+		if (is_add_payment_method_page()) {
345
+			$pay_button_text = __('Add Card', 'woocommerce-gateway-stripe');
346 346
 		} else {
347 347
 			$pay_button_text = '';
348 348
 		}
349 349
 
350 350
 		echo '<div
351 351
 			id="stripe-payment-data"
352
-			data-panel-label="' . esc_attr( $pay_button_text ) . '"
352
+			data-panel-label="' . esc_attr($pay_button_text) . '"
353 353
 			data-description=""
354
-			data-email="' . esc_attr( $user_email ) . '"
355
-			data-amount="' . esc_attr( $this->get_stripe_amount( $total ) ) . '"
356
-			data-name="' . esc_attr( get_bloginfo( 'name', 'display' ) ) . '"
357
-			data-currency="' . esc_attr( strtolower( get_woocommerce_currency() ) ) . '"
358
-			data-image="' . esc_attr( $this->stripe_checkout_image ) . '"
359
-			data-bitcoin="' . esc_attr( $this->bitcoin ? 'true' : 'false' ) . '"
360
-			data-locale="' . esc_attr( $this->stripe_checkout_locale ? $this->stripe_checkout_locale : 'en' ) . '"
361
-			data-allow-remember-me="' . esc_attr( $this->allow_remember_me ? 'true' : 'false' ) . '">';
354
+			data-email="' . esc_attr($user_email) . '"
355
+			data-amount="' . esc_attr($this->get_stripe_amount($total)) . '"
356
+			data-name="' . esc_attr(get_bloginfo('name', 'display')) . '"
357
+			data-currency="' . esc_attr(strtolower(get_woocommerce_currency())) . '"
358
+			data-image="' . esc_attr($this->stripe_checkout_image) . '"
359
+			data-bitcoin="' . esc_attr($this->bitcoin ? 'true' : 'false') . '"
360
+			data-locale="' . esc_attr($this->stripe_checkout_locale ? $this->stripe_checkout_locale : 'en') . '"
361
+			data-allow-remember-me="' . esc_attr($this->allow_remember_me ? 'true' : 'false') . '">';
362 362
 
363
-		if ( $this->description ) {
364
-			echo apply_filters( 'wc_stripe_description', wpautop( wp_kses_post( $this->description ) ) );
363
+		if ($this->description) {
364
+			echo apply_filters('wc_stripe_description', wpautop(wp_kses_post($this->description)));
365 365
 		}
366 366
 
367
-		if ( $display_tokenization ) {
367
+		if ($display_tokenization) {
368 368
 			$this->tokenization_script();
369 369
 			$this->saved_payment_methods();
370 370
 		}
371 371
 
372
-		if ( ! $this->stripe_checkout ) {
372
+		if ( ! $this->stripe_checkout) {
373 373
 			$this->form();
374 374
 
375
-			if ( $display_tokenization ) {
375
+			if ($display_tokenization) {
376 376
 				$this->save_payment_method_checkbox();
377 377
 			}
378 378
 		}
@@ -388,20 +388,20 @@  discard block
 block discarded – undo
388 388
 	 * @return array
389 389
 	 */
390 390
 	public function get_localized_messages() {
391
-		return apply_filters( 'wc_stripe_localized_messages', array(
392
-			'invalid_number'        => __( 'The card number is not a valid credit card number.', 'woocommerce-gateway-stripe' ),
393
-			'invalid_expiry_month'  => __( 'The card\'s expiration month is invalid.', 'woocommerce-gateway-stripe' ),
394
-			'invalid_expiry_year'   => __( 'The card\'s expiration year is invalid.', 'woocommerce-gateway-stripe' ),
395
-			'invalid_cvc'           => __( 'The card\'s security code is invalid.', 'woocommerce-gateway-stripe' ),
396
-			'incorrect_number'      => __( 'The card number is incorrect.', 'woocommerce-gateway-stripe' ),
397
-			'expired_card'          => __( 'The card has expired.', 'woocommerce-gateway-stripe' ),
398
-			'incorrect_cvc'         => __( 'The card\'s security code is incorrect.', 'woocommerce-gateway-stripe' ),
399
-			'incorrect_zip'         => __( 'The card\'s zip code failed validation.', 'woocommerce-gateway-stripe' ),
400
-			'card_declined'         => __( 'The card was declined.', 'woocommerce-gateway-stripe' ),
401
-			'missing'               => __( 'There is no card on a customer that is being charged.', 'woocommerce-gateway-stripe' ),
402
-			'processing_error'      => __( 'An error occurred while processing the card.', 'woocommerce-gateway-stripe' ),
403
-			'invalid_request_error' => __( 'Could not find payment information.', 'woocommerce-gateway-stripe' ),
404
-			) );
391
+		return apply_filters('wc_stripe_localized_messages', array(
392
+			'invalid_number'        => __('The card number is not a valid credit card number.', 'woocommerce-gateway-stripe'),
393
+			'invalid_expiry_month'  => __('The card\'s expiration month is invalid.', 'woocommerce-gateway-stripe'),
394
+			'invalid_expiry_year'   => __('The card\'s expiration year is invalid.', 'woocommerce-gateway-stripe'),
395
+			'invalid_cvc'           => __('The card\'s security code is invalid.', 'woocommerce-gateway-stripe'),
396
+			'incorrect_number'      => __('The card number is incorrect.', 'woocommerce-gateway-stripe'),
397
+			'expired_card'          => __('The card has expired.', 'woocommerce-gateway-stripe'),
398
+			'incorrect_cvc'         => __('The card\'s security code is incorrect.', 'woocommerce-gateway-stripe'),
399
+			'incorrect_zip'         => __('The card\'s zip code failed validation.', 'woocommerce-gateway-stripe'),
400
+			'card_declined'         => __('The card was declined.', 'woocommerce-gateway-stripe'),
401
+			'missing'               => __('There is no card on a customer that is being charged.', 'woocommerce-gateway-stripe'),
402
+			'processing_error'      => __('An error occurred while processing the card.', 'woocommerce-gateway-stripe'),
403
+			'invalid_request_error' => __('Could not find payment information.', 'woocommerce-gateway-stripe'),
404
+			));
405 405
 	}
406 406
 
407 407
 	/**
@@ -412,30 +412,30 @@  discard block
 block discarded – undo
412 412
 	 * @access public
413 413
 	 */
414 414
 	public function payment_scripts() {
415
-		if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) ) {
415
+		if ( ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order'])) {
416 416
 			return;
417 417
 		}
418 418
 
419
-		$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
419
+		$suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';
420 420
 
421
-		if ( $this->stripe_checkout ) {
422
-			wp_enqueue_script( 'stripe_checkout', 'https://checkout.stripe.com/v2/checkout.js', '', '2.0', true );
423
-			wp_enqueue_script( 'woocommerce_stripe', plugins_url( 'assets/js/stripe_checkout' . $suffix . '.js', WC_STRIPE_MAIN_FILE ), array( 'stripe' ), WC_STRIPE_VERSION, true );
421
+		if ($this->stripe_checkout) {
422
+			wp_enqueue_script('stripe_checkout', 'https://checkout.stripe.com/v2/checkout.js', '', '2.0', true);
423
+			wp_enqueue_script('woocommerce_stripe', plugins_url('assets/js/stripe_checkout' . $suffix . '.js', WC_STRIPE_MAIN_FILE), array('stripe'), WC_STRIPE_VERSION, true);
424 424
 		} else {
425
-			wp_enqueue_script( 'stripe', 'https://js.stripe.com/v2/', '', '1.0', true );
426
-			wp_enqueue_script( 'woocommerce_stripe', plugins_url( 'assets/js/stripe' . $suffix . '.js', WC_STRIPE_MAIN_FILE ), array( 'jquery-payment', 'stripe' ), WC_STRIPE_VERSION, true );
425
+			wp_enqueue_script('stripe', 'https://js.stripe.com/v2/', '', '1.0', true);
426
+			wp_enqueue_script('woocommerce_stripe', plugins_url('assets/js/stripe' . $suffix . '.js', WC_STRIPE_MAIN_FILE), array('jquery-payment', 'stripe'), WC_STRIPE_VERSION, true);
427 427
 		}
428 428
 
429 429
 		$stripe_params = array(
430 430
 			'key'                  => $this->publishable_key,
431
-			'i18n_terms'           => __( 'Please accept the terms and conditions first', 'woocommerce-gateway-stripe' ),
432
-			'i18n_required_fields' => __( 'Please fill in required checkout fields first', 'woocommerce-gateway-stripe' ),
431
+			'i18n_terms'           => __('Please accept the terms and conditions first', 'woocommerce-gateway-stripe'),
432
+			'i18n_required_fields' => __('Please fill in required checkout fields first', 'woocommerce-gateway-stripe'),
433 433
 		);
434 434
 
435 435
 		// If we're on the pay page we need to pass stripe.js the address of the order.
436
-		if ( isset( $_GET['pay_for_order'] ) && 'true' === $_GET['pay_for_order'] ) {
437
-			$order_id = wc_get_order_id_by_order_key( urldecode( $_GET['key'] ) );
438
-			$order    = wc_get_order( $order_id );
436
+		if (isset($_GET['pay_for_order']) && 'true' === $_GET['pay_for_order']) {
437
+			$order_id = wc_get_order_id_by_order_key(urldecode($_GET['key']));
438
+			$order    = wc_get_order($order_id);
439 439
 
440 440
 			$stripe_params['billing_first_name'] = $order->billing_first_name;
441 441
 			$stripe_params['billing_last_name']  = $order->billing_last_name;
@@ -447,14 +447,14 @@  discard block
 block discarded – undo
447 447
 			$stripe_params['billing_country']    = $order->billing_country;
448 448
 		}
449 449
 
450
-		$stripe_params['no_prepaid_card_msg']                     = __( 'Sorry, we\'re not accepting prepaid cards at this time.', 'woocommerce-gateway-stripe' );
451
-		$stripe_params['allow_prepaid_card']                      = apply_filters( 'wc_stripe_allow_prepaid_card', true ) ? 'yes' : 'no';
452
-		$stripe_params['stripe_checkout_require_billing_address'] = apply_filters( 'wc_stripe_checkout_require_billing_address', false ) ? 'yes' : 'no';
450
+		$stripe_params['no_prepaid_card_msg']                     = __('Sorry, we\'re not accepting prepaid cards at this time.', 'woocommerce-gateway-stripe');
451
+		$stripe_params['allow_prepaid_card']                      = apply_filters('wc_stripe_allow_prepaid_card', true) ? 'yes' : 'no';
452
+		$stripe_params['stripe_checkout_require_billing_address'] = apply_filters('wc_stripe_checkout_require_billing_address', false) ? 'yes' : 'no';
453 453
 
454 454
 		// merge localized messages to be use in JS
455
-		$stripe_params = array_merge( $stripe_params, $this->get_localized_messages() );
455
+		$stripe_params = array_merge($stripe_params, $this->get_localized_messages());
456 456
 
457
-		wp_localize_script( 'woocommerce_stripe', 'wc_stripe_params', apply_filters( 'wc_stripe_params', $stripe_params ) );
457
+		wp_localize_script('woocommerce_stripe', 'wc_stripe_params', apply_filters('wc_stripe_params', $stripe_params));
458 458
 	}
459 459
 
460 460
 	/**
@@ -463,24 +463,24 @@  discard block
 block discarded – undo
463 463
 	 * @param  object $source
464 464
 	 * @return array()
465 465
 	 */
466
-	protected function generate_payment_request( $order, $source ) {
466
+	protected function generate_payment_request($order, $source) {
467 467
 		$post_data                = array();
468
-		$post_data['currency']    = strtolower( $order->get_order_currency() ? $order->get_order_currency() : get_woocommerce_currency() );
469
-		$post_data['amount']      = $this->get_stripe_amount( $order->get_total(), $post_data['currency'] );
470
-		$post_data['description'] = sprintf( __( '%s - Order %s', 'woocommerce-gateway-stripe' ), wp_specialchars_decode( get_bloginfo( 'name' ), ENT_QUOTES ), $order->get_order_number() );
468
+		$post_data['currency']    = strtolower($order->get_order_currency() ? $order->get_order_currency() : get_woocommerce_currency());
469
+		$post_data['amount']      = $this->get_stripe_amount($order->get_total(), $post_data['currency']);
470
+		$post_data['description'] = sprintf(__('%s - Order %s', 'woocommerce-gateway-stripe'), wp_specialchars_decode(get_bloginfo('name'), ENT_QUOTES), $order->get_order_number());
471 471
 		$post_data['capture']     = $this->capture ? 'true' : 'false';
472 472
 
473
-		if ( ! empty( $order->billing_email ) && apply_filters( 'wc_stripe_send_stripe_receipt', false ) ) {
473
+		if ( ! empty($order->billing_email) && apply_filters('wc_stripe_send_stripe_receipt', false)) {
474 474
 			$post_data['receipt_email'] = $order->billing_email;
475 475
 		}
476 476
 
477
-		$post_data['expand[]']    = 'balance_transaction';
477
+		$post_data['expand[]'] = 'balance_transaction';
478 478
 
479
-		if ( $source->customer ) {
479
+		if ($source->customer) {
480 480
 			$post_data['customer'] = $source->customer;
481 481
 		}
482 482
 
483
-		if ( $source->source ) {
483
+		if ($source->source) {
484 484
 			$post_data['source'] = $source->source;
485 485
 		}
486 486
 		
@@ -492,7 +492,7 @@  discard block
 block discarded – undo
492 492
 		 * @param WC_Order $order
493 493
 		 * @param object $source
494 494
 		 */
495
-		return apply_filters( 'wc_stripe_generate_payment_request', $post_data, $order, $source );
495
+		return apply_filters('wc_stripe_generate_payment_request', $post_data, $order, $source);
496 496
 	}
497 497
 
498 498
 	/**
@@ -504,22 +504,22 @@  discard block
 block discarded – undo
504 504
 	 * @throws Exception When card was not added or for and invalid card.
505 505
 	 * @return object
506 506
 	 */
507
-	protected function get_source( $user_id, $force_customer = false ) {
508
-		$stripe_customer = new WC_Stripe_Customer( $user_id );
507
+	protected function get_source($user_id, $force_customer = false) {
508
+		$stripe_customer = new WC_Stripe_Customer($user_id);
509 509
 		$stripe_source   = false;
510 510
 		$token_id        = false;
511 511
 
512 512
 		// New CC info was entered and we have a new token to process
513
-		if ( isset( $_POST['stripe_token'] ) ) {
514
-			$stripe_token     = wc_clean( $_POST['stripe_token'] );
515
-			$maybe_saved_card = isset( $_POST['wc-stripe-new-payment-method'] ) && ! empty( $_POST['wc-stripe-new-payment-method'] );
513
+		if (isset($_POST['stripe_token'])) {
514
+			$stripe_token     = wc_clean($_POST['stripe_token']);
515
+			$maybe_saved_card = isset($_POST['wc-stripe-new-payment-method']) && ! empty($_POST['wc-stripe-new-payment-method']);
516 516
 
517 517
 			// This is true if the user wants to store the card to their account.
518
-			if ( ( $user_id && $this->saved_cards && $maybe_saved_card ) || $force_customer ) {
519
-				$stripe_source = $stripe_customer->add_card( $stripe_token );
518
+			if (($user_id && $this->saved_cards && $maybe_saved_card) || $force_customer) {
519
+				$stripe_source = $stripe_customer->add_card($stripe_token);
520 520
 
521
-				if ( is_wp_error( $stripe_source ) ) {
522
-					throw new Exception( $stripe_source->get_error_message() );
521
+				if (is_wp_error($stripe_source)) {
522
+					throw new Exception($stripe_source->get_error_message());
523 523
 				}
524 524
 
525 525
 			} else {
@@ -530,13 +530,13 @@  discard block
 block discarded – undo
530 530
 		}
531 531
 
532 532
 		// Use an existing token, and then process the payment
533
-		elseif ( isset( $_POST['wc-stripe-payment-token'] ) && 'new' !== $_POST['wc-stripe-payment-token'] ) {
534
-			$token_id = wc_clean( $_POST['wc-stripe-payment-token'] );
535
-			$token    = WC_Payment_Tokens::get( $token_id );
533
+		elseif (isset($_POST['wc-stripe-payment-token']) && 'new' !== $_POST['wc-stripe-payment-token']) {
534
+			$token_id = wc_clean($_POST['wc-stripe-payment-token']);
535
+			$token    = WC_Payment_Tokens::get($token_id);
536 536
 
537
-			if ( ! $token || $token->get_user_id() !== get_current_user_id() ) {
538
-				WC()->session->set( 'refresh_totals', true );
539
-				throw new Exception( __( 'Invalid payment method. Please input a new card number.', 'woocommerce-gateway-stripe' ) );
537
+			if ( ! $token || $token->get_user_id() !== get_current_user_id()) {
538
+				WC()->session->set('refresh_totals', true);
539
+				throw new Exception(__('Invalid payment method. Please input a new card number.', 'woocommerce-gateway-stripe'));
540 540
 			}
541 541
 
542 542
 			$stripe_source = $token->get_token();
@@ -560,16 +560,16 @@  discard block
 block discarded – undo
560 560
 	 * @param object $order
561 561
 	 * @return object
562 562
 	 */
563
-	protected function get_order_source( $order = null ) {
563
+	protected function get_order_source($order = null) {
564 564
 		$stripe_customer = new WC_Stripe_Customer();
565 565
 		$stripe_source   = false;
566 566
 		$token_id        = false;
567 567
 
568
-		if ( $order ) {
569
-			if ( $meta_value = get_post_meta( $order->id, '_stripe_customer_id', true ) ) {
570
-				$stripe_customer->set_id( $meta_value );
568
+		if ($order) {
569
+			if ($meta_value = get_post_meta($order->id, '_stripe_customer_id', true)) {
570
+				$stripe_customer->set_id($meta_value);
571 571
 			}
572
-			if ( $meta_value = get_post_meta( $order->id, '_stripe_card_id', true ) ) {
572
+			if ($meta_value = get_post_meta($order->id, '_stripe_card_id', true)) {
573 573
 				$stripe_source = $meta_value;
574 574
 			}
575 575
 		}
@@ -592,50 +592,50 @@  discard block
 block discarded – undo
592 592
 	 *
593 593
 	 * @return array|void
594 594
 	 */
595
-	public function process_payment( $order_id, $retry = true, $force_customer = false ) {
595
+	public function process_payment($order_id, $retry = true, $force_customer = false) {
596 596
 		try {
597
-			$order  = wc_get_order( $order_id );
598
-			$source = $this->get_source( get_current_user_id(), $force_customer );
597
+			$order  = wc_get_order($order_id);
598
+			$source = $this->get_source(get_current_user_id(), $force_customer);
599 599
 
600
-			if ( empty( $source->source ) && empty( $source->customer ) ) {
601
-				$error_msg = __( 'Please enter your card details to make a payment.', 'woocommerce-gateway-stripe' );
602
-				$error_msg .= ' ' . __( 'Developers: Please make sure that you are including jQuery and there are no JavaScript errors on the page.', 'woocommerce-gateway-stripe' );
603
-				throw new Exception( $error_msg );
600
+			if (empty($source->source) && empty($source->customer)) {
601
+				$error_msg = __('Please enter your card details to make a payment.', 'woocommerce-gateway-stripe');
602
+				$error_msg .= ' ' . __('Developers: Please make sure that you are including jQuery and there are no JavaScript errors on the page.', 'woocommerce-gateway-stripe');
603
+				throw new Exception($error_msg);
604 604
 			}
605 605
 
606 606
 			// Store source to order meta.
607
-			$this->save_source( $order, $source );
607
+			$this->save_source($order, $source);
608 608
 
609 609
 			// Handle payment.
610
-			if ( $order->get_total() > 0 ) {
610
+			if ($order->get_total() > 0) {
611 611
 
612
-				if ( $order->get_total() * 100 < WC_Stripe::get_minimum_amount() ) {
613
-					throw new Exception( sprintf( __( 'Sorry, the minimum allowed order total is %1$s to use this payment method.', 'woocommerce-gateway-stripe' ), wc_price( WC_Stripe::get_minimum_amount() / 100 ) ) );
612
+				if ($order->get_total() * 100 < WC_Stripe::get_minimum_amount()) {
613
+					throw new Exception(sprintf(__('Sorry, the minimum allowed order total is %1$s to use this payment method.', 'woocommerce-gateway-stripe'), wc_price(WC_Stripe::get_minimum_amount() / 100)));
614 614
 				}
615 615
 
616
-				WC_Stripe::log( "Info: Begin processing payment for order $order_id for the amount of {$order->get_total()}" );
616
+				WC_Stripe::log("Info: Begin processing payment for order $order_id for the amount of {$order->get_total()}");
617 617
 
618 618
 				// Make the request.
619
-				$response = WC_Stripe_API::request( $this->generate_payment_request( $order, $source ) );
619
+				$response = WC_Stripe_API::request($this->generate_payment_request($order, $source));
620 620
 
621
-				if ( is_wp_error( $response ) ) {
621
+				if (is_wp_error($response)) {
622 622
 					// Customer param wrong? The user may have been deleted on stripe's end. Remove customer_id. Can be retried without.
623
-					if ( 'customer' === $response->get_error_code() && $retry ) {
624
-						delete_user_meta( get_current_user_id(), '_stripe_customer_id' );
625
-						return $this->process_payment( $order_id, false, $force_customer );
623
+					if ('customer' === $response->get_error_code() && $retry) {
624
+						delete_user_meta(get_current_user_id(), '_stripe_customer_id');
625
+						return $this->process_payment($order_id, false, $force_customer);
626 626
 						// Source param wrong? The CARD may have been deleted on stripe's end. Remove token and show message.
627
-					} elseif ( 'source' === $response->get_error_code() && $source->token_id ) {
628
-						$token = WC_Payment_Tokens::get( $source->token_id );
627
+					} elseif ('source' === $response->get_error_code() && $source->token_id) {
628
+						$token = WC_Payment_Tokens::get($source->token_id);
629 629
 						$token->delete();
630
-						throw new Exception( __( 'This card is no longer available and has been removed.', 'woocommerce-gateway-stripe' ) );
630
+						throw new Exception(__('This card is no longer available and has been removed.', 'woocommerce-gateway-stripe'));
631 631
 					}
632 632
 					$localized_messages = $this->get_localized_messages();
633 633
 
634
-					throw new Exception( ( isset( $localized_messages[ $response->get_error_code() ] ) ? $localized_messages[ $response->get_error_code() ] : $response->get_error_message() ) );
634
+					throw new Exception((isset($localized_messages[$response->get_error_code()]) ? $localized_messages[$response->get_error_code()] : $response->get_error_message()));
635 635
 				}
636 636
 
637 637
 				// Process valid response.
638
-				$this->process_response( $response, $order );
638
+				$this->process_response($response, $order);
639 639
 			} else {
640 640
 				$order->payment_complete();
641 641
 			}
@@ -643,23 +643,23 @@  discard block
 block discarded – undo
643 643
 			// Remove cart.
644 644
 			WC()->cart->empty_cart();
645 645
 
646
-			do_action( 'wc_gateway_stripe_process_payment', $response, $order );
646
+			do_action('wc_gateway_stripe_process_payment', $response, $order);
647 647
 
648 648
 			// Return thank you page redirect.
649 649
 			return array(
650 650
 				'result'   => 'success',
651
-				'redirect' => $this->get_return_url( $order )
651
+				'redirect' => $this->get_return_url($order)
652 652
 			);
653 653
 
654
-		} catch ( Exception $e ) {
655
-			wc_add_notice( $e->getMessage(), 'error' );
656
-			WC_Stripe::log( sprintf( __( 'Error: %s', 'woocommerce-gateway-stripe' ), $e->getMessage() ) );
654
+		} catch (Exception $e) {
655
+			wc_add_notice($e->getMessage(), 'error');
656
+			WC_Stripe::log(sprintf(__('Error: %s', 'woocommerce-gateway-stripe'), $e->getMessage()));
657 657
 
658
-			if ( $order->has_status( array( 'pending', 'failed' ) ) ) {
659
-				$this->send_failed_order_email( $order_id );
658
+			if ($order->has_status(array('pending', 'failed'))) {
659
+				$this->send_failed_order_email($order_id);
660 660
 			}
661 661
 
662
-			do_action( 'wc_gateway_stripe_process_payment_error', $e, $order );
662
+			do_action('wc_gateway_stripe_process_payment_error', $e, $order);
663 663
 
664 664
 			return array(
665 665
 				'result'   => 'fail',
@@ -674,52 +674,52 @@  discard block
 block discarded – undo
674 674
 	 * @param WC_Order $order For to which the source applies.
675 675
 	 * @param stdClass $source Source information.
676 676
 	 */
677
-	protected function save_source( $order, $source ) {
677
+	protected function save_source($order, $source) {
678 678
 		// Store source in the order.
679
-		if ( $source->customer ) {
680
-			update_post_meta( $order->id, '_stripe_customer_id', $source->customer );
679
+		if ($source->customer) {
680
+			update_post_meta($order->id, '_stripe_customer_id', $source->customer);
681 681
 		}
682
-		if ( $source->source ) {
683
-			update_post_meta( $order->id, '_stripe_card_id', $source->source );
682
+		if ($source->source) {
683
+			update_post_meta($order->id, '_stripe_card_id', $source->source);
684 684
 		}
685 685
 	}
686 686
 
687 687
 	/**
688 688
 	 * Store extra meta data for an order from a Stripe Response.
689 689
 	 */
690
-	public function process_response( $response, $order ) {
691
-		WC_Stripe::log( "Processing response: " . print_r( $response, true ) );
690
+	public function process_response($response, $order) {
691
+		WC_Stripe::log("Processing response: " . print_r($response, true));
692 692
 
693 693
 		// Store charge data
694
-		update_post_meta( $order->id, '_stripe_charge_id', $response->id );
695
-		update_post_meta( $order->id, '_stripe_charge_captured', $response->captured ? 'yes' : 'no' );
694
+		update_post_meta($order->id, '_stripe_charge_id', $response->id);
695
+		update_post_meta($order->id, '_stripe_charge_captured', $response->captured ? 'yes' : 'no');
696 696
 
697 697
 		// Store other data such as fees
698
-		if ( isset( $response->balance_transaction ) && isset( $response->balance_transaction->fee ) ) {
698
+		if (isset($response->balance_transaction) && isset($response->balance_transaction->fee)) {
699 699
 			// Fees and Net needs to both come from Stripe to be accurate as the returned
700 700
 			// values are in the local currency of the Stripe account, not from WC.
701
-			$fee = ! empty( $response->balance_transaction->fee ) ? number_format( $response->balance_transaction->fee / 100, 2, '.', '' ) : 0;
702
-			$net = ! empty( $response->balance_transaction->net ) ? number_format( $response->balance_transaction->net / 100, 2, '.', '' ) : 0;
703
-			update_post_meta( $order->id, 'Stripe Fee', $fee );
704
-			update_post_meta( $order->id, 'Net Revenue From Stripe', $net );
701
+			$fee = ! empty($response->balance_transaction->fee) ? number_format($response->balance_transaction->fee / 100, 2, '.', '') : 0;
702
+			$net = ! empty($response->balance_transaction->net) ? number_format($response->balance_transaction->net / 100, 2, '.', '') : 0;
703
+			update_post_meta($order->id, 'Stripe Fee', $fee);
704
+			update_post_meta($order->id, 'Net Revenue From Stripe', $net);
705 705
 		}
706 706
 
707
-		if ( $response->captured ) {
708
-			$order->payment_complete( $response->id );
707
+		if ($response->captured) {
708
+			$order->payment_complete($response->id);
709 709
 
710
-			$message = sprintf( __( 'Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe' ), $response->id );
711
-			$order->add_order_note( $message );
712
-			WC_Stripe::log( 'Success: ' . $message );
710
+			$message = sprintf(__('Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe'), $response->id);
711
+			$order->add_order_note($message);
712
+			WC_Stripe::log('Success: ' . $message);
713 713
 
714 714
 		} else {
715
-			add_post_meta( $order->id, '_transaction_id', $response->id, true );
715
+			add_post_meta($order->id, '_transaction_id', $response->id, true);
716 716
 
717
-			if ( $order->has_status( array( 'pending', 'failed' ) ) ) {
717
+			if ($order->has_status(array('pending', 'failed'))) {
718 718
 				$order->reduce_order_stock();
719 719
 			}
720 720
 
721
-			$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 ) );
722
-			WC_Stripe::log( "Successful auth: $response->id" );
721
+			$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));
722
+			WC_Stripe::log("Successful auth: $response->id");
723 723
 		}
724 724
 
725 725
 		return $response;
@@ -731,32 +731,32 @@  discard block
 block discarded – undo
731 731
 	 * @since 3.0.0
732 732
 	 */
733 733
 	public function add_payment_method() {
734
-		if ( empty( $_POST['stripe_token'] ) || ! is_user_logged_in() ) {
735
-			wc_add_notice( __( 'There was a problem adding the card.', 'woocommerce-gateway-stripe' ), 'error' );
734
+		if (empty($_POST['stripe_token']) || ! is_user_logged_in()) {
735
+			wc_add_notice(__('There was a problem adding the card.', 'woocommerce-gateway-stripe'), 'error');
736 736
 			return;
737 737
 		}
738 738
 
739
-		$stripe_customer = new WC_Stripe_Customer( get_current_user_id() );
740
-		$card            = $stripe_customer->add_card( wc_clean( $_POST['stripe_token'] ) );
739
+		$stripe_customer = new WC_Stripe_Customer(get_current_user_id());
740
+		$card            = $stripe_customer->add_card(wc_clean($_POST['stripe_token']));
741 741
 
742
-		if ( is_wp_error( $card ) ) {
742
+		if (is_wp_error($card)) {
743 743
 			$localized_messages = $this->get_localized_messages();
744
-			$error_msg = __( 'There was a problem adding the card.', 'woocommerce-gateway-stripe' );
744
+			$error_msg = __('There was a problem adding the card.', 'woocommerce-gateway-stripe');
745 745
 
746 746
 			// loop through the errors to find matching localized message
747
-			foreach ( $card->errors as $error => $msg ) {
748
-				if ( isset( $localized_messages[ $error ] ) ) {
749
-					$error_msg = $localized_messages[ $error ];
747
+			foreach ($card->errors as $error => $msg) {
748
+				if (isset($localized_messages[$error])) {
749
+					$error_msg = $localized_messages[$error];
750 750
 				}
751 751
 			}
752 752
 
753
-			wc_add_notice( $error_msg, 'error' );
753
+			wc_add_notice($error_msg, 'error');
754 754
 			return;
755 755
 		}
756 756
 
757 757
 		return array(
758 758
 			'result'   => 'success',
759
-			'redirect' => wc_get_endpoint_url( 'payment-methods' ),
759
+			'redirect' => wc_get_endpoint_url('payment-methods'),
760 760
 		);
761 761
 	}
762 762
 
@@ -766,36 +766,36 @@  discard block
 block discarded – undo
766 766
 	 * @param  float $amount
767 767
 	 * @return bool
768 768
 	 */
769
-	public function process_refund( $order_id, $amount = null, $reason = '' ) {
770
-		$order = wc_get_order( $order_id );
769
+	public function process_refund($order_id, $amount = null, $reason = '') {
770
+		$order = wc_get_order($order_id);
771 771
 
772
-		if ( ! $order || ! $order->get_transaction_id() ) {
772
+		if ( ! $order || ! $order->get_transaction_id()) {
773 773
 			return false;
774 774
 		}
775 775
 
776 776
 		$body = array();
777 777
 
778
-		if ( ! is_null( $amount ) ) {
779
-			$body['amount']	= $this->get_stripe_amount( $amount );
778
+		if ( ! is_null($amount)) {
779
+			$body['amount'] = $this->get_stripe_amount($amount);
780 780
 		}
781 781
 
782
-		if ( $reason ) {
782
+		if ($reason) {
783 783
 			$body['metadata'] = array(
784 784
 				'reason'	=> $reason,
785 785
 			);
786 786
 		}
787 787
 
788
-		WC_Stripe::log( "Info: Beginning refund for order $order_id for the amount of {$amount}" );
788
+		WC_Stripe::log("Info: Beginning refund for order $order_id for the amount of {$amount}");
789 789
 
790
-		$response = WC_Stripe_API::request( $body, 'charges/' . $order->get_transaction_id() . '/refunds' );
790
+		$response = WC_Stripe_API::request($body, 'charges/' . $order->get_transaction_id() . '/refunds');
791 791
 
792
-		if ( is_wp_error( $response ) ) {
793
-			WC_Stripe::log( "Error: " . $response->get_error_message() );
792
+		if (is_wp_error($response)) {
793
+			WC_Stripe::log("Error: " . $response->get_error_message());
794 794
 			return $response;
795
-		} elseif ( ! empty( $response->id ) ) {
796
-			$refund_message = sprintf( __( 'Refunded %s - Refund ID: %s - Reason: %s', 'woocommerce-gateway-stripe' ), wc_price( $response->amount / 100 ), $response->id, $reason );
797
-			$order->add_order_note( $refund_message );
798
-			WC_Stripe::log( "Success: " . html_entity_decode( strip_tags( $refund_message ) ) );
795
+		} elseif ( ! empty($response->id)) {
796
+			$refund_message = sprintf(__('Refunded %s - Refund ID: %s - Reason: %s', 'woocommerce-gateway-stripe'), wc_price($response->amount / 100), $response->id, $reason);
797
+			$order->add_order_note($refund_message);
798
+			WC_Stripe::log("Success: " . html_entity_decode(strip_tags($refund_message)));
799 799
 			return true;
800 800
 		}
801 801
 	}
@@ -808,10 +808,10 @@  discard block
 block discarded – undo
808 808
 	 * @param int $order_id
809 809
 	 * @return null
810 810
 	 */
811
-	public function send_failed_order_email( $order_id ) {
811
+	public function send_failed_order_email($order_id) {
812 812
 		$emails = WC()->mailer()->get_emails();
813
-		if ( ! empty( $emails ) && ! empty( $order_id ) ) {
814
-			$emails['WC_Email_Failed_Order']->trigger( $order_id );
813
+		if ( ! empty($emails) && ! empty($order_id)) {
814
+			$emails['WC_Email_Failed_Order']->trigger($order_id);
815 815
 		}
816 816
 	}
817 817
 }
Please login to merge, or discard this patch.