Completed
Push — master ( a0c464...2c2ec3 )
by Roy
92:26
created
includes/class-wc-gateway-stripe.php 1 patch
Spacing   +208 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
 
@@ -85,8 +85,8 @@  discard block
 block discarded – undo
85 85
 	 */
86 86
 	public function __construct() {
87 87
 		$this->id                   = 'stripe';
88
-		$this->method_title         = __( 'Stripe', 'woocommerce-gateway-stripe' );
89
-		$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' );
88
+		$this->method_title         = __('Stripe', 'woocommerce-gateway-stripe');
89
+		$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');
90 90
 		$this->has_fields           = true;
91 91
 		$this->view_transaction_url = 'https://dashboard.stripe.com/payments/%s';
92 92
 		$this->supports             = array(
@@ -114,35 +114,35 @@  discard block
 block discarded – undo
114 114
 		$this->init_settings();
115 115
 
116 116
 		// Get setting values.
117
-		$this->title                  = $this->get_option( 'title' );
118
-		$this->description            = $this->get_option( 'description' );
119
-		$this->enabled                = $this->get_option( 'enabled' );
120
-		$this->testmode               = 'yes' === $this->get_option( 'testmode' );
121
-		$this->capture                = 'yes' === $this->get_option( 'capture', 'yes' );
122
-		$this->stripe_checkout        = 'yes' === $this->get_option( 'stripe_checkout' );
123
-		$this->stripe_checkout_locale = $this->get_option( 'stripe_checkout_locale' );
124
-		$this->stripe_checkout_image  = $this->get_option( 'stripe_checkout_image', '' );
125
-		$this->saved_cards            = 'yes' === $this->get_option( 'saved_cards' );
126
-		$this->secret_key             = $this->testmode ? $this->get_option( 'test_secret_key' ) : $this->get_option( 'secret_key' );
127
-		$this->publishable_key        = $this->testmode ? $this->get_option( 'test_publishable_key' ) : $this->get_option( 'publishable_key' );
128
-		$this->bitcoin                = 'USD' === strtoupper( get_woocommerce_currency() ) && 'yes' === $this->get_option( 'stripe_bitcoin' );
129
-		$this->logging                = 'yes' === $this->get_option( 'logging' );
117
+		$this->title                  = $this->get_option('title');
118
+		$this->description            = $this->get_option('description');
119
+		$this->enabled                = $this->get_option('enabled');
120
+		$this->testmode               = 'yes' === $this->get_option('testmode');
121
+		$this->capture                = 'yes' === $this->get_option('capture', 'yes');
122
+		$this->stripe_checkout        = 'yes' === $this->get_option('stripe_checkout');
123
+		$this->stripe_checkout_locale = $this->get_option('stripe_checkout_locale');
124
+		$this->stripe_checkout_image  = $this->get_option('stripe_checkout_image', '');
125
+		$this->saved_cards            = 'yes' === $this->get_option('saved_cards');
126
+		$this->secret_key             = $this->testmode ? $this->get_option('test_secret_key') : $this->get_option('secret_key');
127
+		$this->publishable_key        = $this->testmode ? $this->get_option('test_publishable_key') : $this->get_option('publishable_key');
128
+		$this->bitcoin                = 'USD' === strtoupper(get_woocommerce_currency()) && 'yes' === $this->get_option('stripe_bitcoin');
129
+		$this->logging                = 'yes' === $this->get_option('logging');
130 130
 
131
-		if ( $this->stripe_checkout ) {
132
-			$this->order_button_text = __( 'Continue to payment', 'woocommerce-gateway-stripe' );
131
+		if ($this->stripe_checkout) {
132
+			$this->order_button_text = __('Continue to payment', 'woocommerce-gateway-stripe');
133 133
 		}
134 134
 
135
-		if ( $this->testmode ) {
136
-			$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' );
137
-			$this->description  = trim( $this->description );
135
+		if ($this->testmode) {
136
+			$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');
137
+			$this->description  = trim($this->description);
138 138
 		}
139 139
 
140
-		WC_Stripe_API::set_secret_key( $this->secret_key );
140
+		WC_Stripe_API::set_secret_key($this->secret_key);
141 141
 
142 142
 		// Hooks.
143
-		add_action( 'wp_enqueue_scripts', array( $this, 'payment_scripts' ) );
144
-		add_action( 'admin_notices', array( $this, 'admin_notices' ) );
145
-		add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) );
143
+		add_action('wp_enqueue_scripts', array($this, 'payment_scripts'));
144
+		add_action('admin_notices', array($this, 'admin_notices'));
145
+		add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options'));
146 146
 	}
147 147
 
148 148
 	/**
@@ -152,24 +152,24 @@  discard block
 block discarded – undo
152 152
 	 * @return string
153 153
 	 */
154 154
 	public function get_icon() {
155
-		$ext   = version_compare( WC()->version, '2.6', '>=' ) ? '.svg' : '.png';
156
-		$style = version_compare( WC()->version, '2.6', '>=' ) ? 'style="margin-left: 0.3em"' : '';
155
+		$ext   = version_compare(WC()->version, '2.6', '>=') ? '.svg' : '.png';
156
+		$style = version_compare(WC()->version, '2.6', '>=') ? 'style="margin-left: 0.3em"' : '';
157 157
 
158
-		$icon  = '<img src="' . WC_HTTPS::force_https_url( WC()->plugin_url() . '/assets/images/icons/credit-cards/visa' . $ext ) . '" alt="Visa" width="32" ' . $style . ' />';
159
-		$icon .= '<img src="' . WC_HTTPS::force_https_url( WC()->plugin_url() . '/assets/images/icons/credit-cards/mastercard' . $ext ) . '" alt="Mastercard" width="32" ' . $style . ' />';
160
-		$icon .= '<img src="' . WC_HTTPS::force_https_url( WC()->plugin_url() . '/assets/images/icons/credit-cards/amex' . $ext ) . '" alt="Amex" width="32" ' . $style . ' />';
158
+		$icon  = '<img src="' . WC_HTTPS::force_https_url(WC()->plugin_url() . '/assets/images/icons/credit-cards/visa' . $ext) . '" alt="Visa" width="32" ' . $style . ' />';
159
+		$icon .= '<img src="' . WC_HTTPS::force_https_url(WC()->plugin_url() . '/assets/images/icons/credit-cards/mastercard' . $ext) . '" alt="Mastercard" width="32" ' . $style . ' />';
160
+		$icon .= '<img src="' . WC_HTTPS::force_https_url(WC()->plugin_url() . '/assets/images/icons/credit-cards/amex' . $ext) . '" alt="Amex" width="32" ' . $style . ' />';
161 161
 
162
-		if ( 'USD' === get_woocommerce_currency() ) {
163
-			$icon .= '<img src="' . WC_HTTPS::force_https_url( WC()->plugin_url() . '/assets/images/icons/credit-cards/discover' . $ext ) . '" alt="Discover" width="32" ' . $style . ' />';
164
-			$icon .= '<img src="' . WC_HTTPS::force_https_url( WC()->plugin_url() . '/assets/images/icons/credit-cards/jcb' . $ext ) . '" alt="JCB" width="32" ' . $style . ' />';
165
-			$icon .= '<img src="' . WC_HTTPS::force_https_url( WC()->plugin_url() . '/assets/images/icons/credit-cards/diners' . $ext ) . '" alt="Diners" width="32" ' . $style . ' />';
162
+		if ('USD' === get_woocommerce_currency()) {
163
+			$icon .= '<img src="' . WC_HTTPS::force_https_url(WC()->plugin_url() . '/assets/images/icons/credit-cards/discover' . $ext) . '" alt="Discover" width="32" ' . $style . ' />';
164
+			$icon .= '<img src="' . WC_HTTPS::force_https_url(WC()->plugin_url() . '/assets/images/icons/credit-cards/jcb' . $ext) . '" alt="JCB" width="32" ' . $style . ' />';
165
+			$icon .= '<img src="' . WC_HTTPS::force_https_url(WC()->plugin_url() . '/assets/images/icons/credit-cards/diners' . $ext) . '" alt="Diners" width="32" ' . $style . ' />';
166 166
 		}
167 167
 
168
-		if ( 'yes' === $this->bitcoin && 'yes' === $this->stripe_checkout ) {
169
-			$icon .= '<img src="' . WC_HTTPS::force_https_url( plugins_url( '/assets/images/bitcoin' . $ext, WC_STRIPE_MAIN_FILE ) ) . '" alt="Bitcoin" width="32" ' . $style . ' />';
168
+		if ('yes' === $this->bitcoin && 'yes' === $this->stripe_checkout) {
169
+			$icon .= '<img src="' . WC_HTTPS::force_https_url(plugins_url('/assets/images/bitcoin' . $ext, WC_STRIPE_MAIN_FILE)) . '" alt="Bitcoin" width="32" ' . $style . ' />';
170 170
 		}
171 171
 
172
-		return apply_filters( 'woocommerce_gateway_icon', $icon, $this->id );
172
+		return apply_filters('woocommerce_gateway_icon', $icon, $this->id);
173 173
 	}
174 174
 
175 175
 	/**
@@ -180,11 +180,11 @@  discard block
 block discarded – undo
180 180
 	 *
181 181
 	 * @return float|int
182 182
 	 */
183
-	public function get_stripe_amount( $total, $currency = '' ) {
184
-		if ( ! $currency ) {
183
+	public function get_stripe_amount($total, $currency = '') {
184
+		if ( ! $currency) {
185 185
 			$currency = get_woocommerce_currency();
186 186
 		}
187
-		switch ( strtoupper( $currency ) ) {
187
+		switch (strtoupper($currency)) {
188 188
 			// Zero decimal currencies.
189 189
 			case 'BIF' :
190 190
 			case 'CLP' :
@@ -201,10 +201,10 @@  discard block
 block discarded – undo
201 201
 			case 'XAF' :
202 202
 			case 'XOF' :
203 203
 			case 'XPF' :
204
-				$total = absint( $total );
204
+				$total = absint($total);
205 205
 				break;
206 206
 			default :
207
-				$total = round( $total, 2 ) * 100; // In cents.
207
+				$total = round($total, 2) * 100; // In cents.
208 208
 				break;
209 209
 		}
210 210
 		return $total;
@@ -214,13 +214,13 @@  discard block
 block discarded – undo
214 214
 	 * Check if SSL is enabled and notify the user
215 215
 	 */
216 216
 	public function admin_notices() {
217
-		if ( 'no' === $this->enabled ) {
217
+		if ('no' === $this->enabled) {
218 218
 			return;
219 219
 		}
220 220
 
221 221
 		// Show message if enabled and FORCE SSL is disabled and WordpressHTTPS plugin is not detected.
222
-		if ( ( function_exists( 'wc_site_is_https' ) && ! wc_site_is_https() ) && ( 'no' === get_option( 'woocommerce_force_ssl_checkout' ) && ! class_exists( 'WordPressHTTPS' ) ) ) {
223
-			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>';
222
+		if ((function_exists('wc_site_is_https') && ! wc_site_is_https()) && ('no' === get_option('woocommerce_force_ssl_checkout') && ! class_exists('WordPressHTTPS'))) {
223
+			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>';
224 224
 		}
225 225
 	}
226 226
 
@@ -228,11 +228,11 @@  discard block
 block discarded – undo
228 228
 	 * Check if this gateway is enabled
229 229
 	 */
230 230
 	public function is_available() {
231
-		if ( 'yes' === $this->enabled ) {
232
-			if ( ! $this->testmode && is_checkout() && ! is_ssl() ) {
231
+		if ('yes' === $this->enabled) {
232
+			if ( ! $this->testmode && is_checkout() && ! is_ssl()) {
233 233
 				return false;
234 234
 			}
235
-			if ( ! $this->secret_key || ! $this->publishable_key ) {
235
+			if ( ! $this->secret_key || ! $this->publishable_key) {
236 236
 				return false;
237 237
 			}
238 238
 			return true;
@@ -244,9 +244,9 @@  discard block
 block discarded – undo
244 244
 	 * Initialise Gateway Settings Form Fields
245 245
 	 */
246 246
 	public function init_form_fields() {
247
-		$this->form_fields = include( 'settings-stripe.php' );
247
+		$this->form_fields = include('settings-stripe.php');
248 248
 
249
-		wc_enqueue_js( "
249
+		wc_enqueue_js("
250 250
 			jQuery( function( $ ) {
251 251
 				$( '#woocommerce_stripe_stripe_checkout' ).change(function(){
252 252
 					if ( $( this ).is( ':checked' ) ) {
@@ -260,7 +260,7 @@  discard block
 block discarded – undo
260 260
 					var value = $( this ).val();
261 261
 
262 262
 					if ( value.indexOf( '_test_' ) >= 0 ) {
263
-						$( 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>' );
263
+						$( 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>' );
264 264
 					} else {
265 265
 						$( this ).css( 'border-color', '' );
266 266
 						$( '.stripe-error-description', $( this ).parent() ).remove();
@@ -271,7 +271,7 @@  discard block
 block discarded – undo
271 271
 					var value = $( this ).val();
272 272
 
273 273
 					if ( value.indexOf( '_live_' ) >= 0 ) {
274
-						$( 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>' );
274
+						$( 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>' );
275 275
 					} else {
276 276
 						$( this ).css( 'border-color', '' );
277 277
 						$( '.stripe-error-description', $( this ).parent() ).remove();
@@ -286,46 +286,46 @@  discard block
 block discarded – undo
286 286
 	 */
287 287
 	public function payment_fields() {
288 288
 		$user                 = wp_get_current_user();
289
-		$display_tokenization = $this->supports( 'tokenization' ) && is_checkout() && $this->saved_cards;
289
+		$display_tokenization = $this->supports('tokenization') && is_checkout() && $this->saved_cards;
290 290
 
291
-		if ( $user->ID ) {
292
-			$user_email = get_user_meta( $user->ID, 'billing_email', true );
291
+		if ($user->ID) {
292
+			$user_email = get_user_meta($user->ID, 'billing_email', true);
293 293
 			$user_email = $user_email ? $user_email : $user->user_email;
294 294
 		} else {
295 295
 			$user_email = '';
296 296
 		}
297 297
 
298
-		if ( is_add_payment_method_page() ) {
299
-			$pay_button_text = __( 'Add Card', 'woocommerce-gateway-stripe' );
298
+		if (is_add_payment_method_page()) {
299
+			$pay_button_text = __('Add Card', 'woocommerce-gateway-stripe');
300 300
 		} else {
301 301
 			$pay_button_text = '';
302 302
 		}
303 303
 
304 304
 		echo '<div
305 305
 			id="stripe-payment-data"
306
-			data-panel-label="' . esc_attr( $pay_button_text ) . '"
306
+			data-panel-label="' . esc_attr($pay_button_text) . '"
307 307
 			data-description=""
308
-			data-email="' . esc_attr( $user_email ) . '"
309
-			data-amount="' . esc_attr( $this->get_stripe_amount( WC()->cart->total ) ) . '"
310
-			data-name="' . esc_attr( get_bloginfo( 'name', 'display' ) ) . '"
311
-			data-currency="' . esc_attr( strtolower( get_woocommerce_currency() ) ) . '"
312
-			data-image="' . esc_attr( $this->stripe_checkout_image ) . '"
313
-			data-bitcoin="' . esc_attr( $this->bitcoin ? 'true' : 'false' ) . '"
314
-			data-locale="' . esc_attr( $this->stripe_checkout_locale ? $this->stripe_checkout_locale : 'en' ) . '">';
308
+			data-email="' . esc_attr($user_email) . '"
309
+			data-amount="' . esc_attr($this->get_stripe_amount(WC()->cart->total)) . '"
310
+			data-name="' . esc_attr(get_bloginfo('name', 'display')) . '"
311
+			data-currency="' . esc_attr(strtolower(get_woocommerce_currency())) . '"
312
+			data-image="' . esc_attr($this->stripe_checkout_image) . '"
313
+			data-bitcoin="' . esc_attr($this->bitcoin ? 'true' : 'false') . '"
314
+			data-locale="' . esc_attr($this->stripe_checkout_locale ? $this->stripe_checkout_locale : 'en') . '">';
315 315
 
316
-		if ( $this->description ) {
317
-			echo apply_filters( 'wc_stripe_description', wpautop( wp_kses_post( $this->description ) ) );
316
+		if ($this->description) {
317
+			echo apply_filters('wc_stripe_description', wpautop(wp_kses_post($this->description)));
318 318
 		}
319 319
 
320
-		if ( $display_tokenization ) {
320
+		if ($display_tokenization) {
321 321
 			$this->tokenization_script();
322 322
 			$this->saved_payment_methods();
323 323
 		}
324 324
 
325
-		if ( ! $this->stripe_checkout ) {
325
+		if ( ! $this->stripe_checkout) {
326 326
 			$this->form();
327 327
 			
328
-			if ( $display_tokenization ) {
328
+			if ($display_tokenization) {
329 329
 				$this->save_payment_method_checkbox();
330 330
 			}
331 331
 		}
@@ -341,20 +341,20 @@  discard block
 block discarded – undo
341 341
 	 * @return array
342 342
 	 */
343 343
 	public function get_localized_messages() {
344
-		return apply_filters( 'wc_stripe_localized_messages', array(
345
-			'invalid_number'        => __( 'The card number is not a valid credit card number.', 'woocommerce-gateway-stripe' ),
346
-			'invalid_expiry_month'  => __( 'The card\'s expiration month is invalid.', 'woocommerce-gateway-stripe' ),
347
-			'invalid_expiry_year'   => __( 'The card\'s expiration year is invalid.', 'woocommerce-gateway-stripe' ),
348
-			'invalid_cvc'           => __( 'The card\'s security code is invalid.', 'woocommerce-gateway-stripe' ),
349
-			'incorrect_number'      => __( 'The card number is incorrect.', 'woocommerce-gateway-stripe' ),
350
-			'expired_card'          => __( 'The card has expired.', 'woocommerce-gateway-stripe' ),
351
-			'incorrect_cvc'         => __( 'The card\'s security code is incorrect.', 'woocommerce-gateway-stripe' ),
352
-			'incorrect_zip'         => __( 'The card\'s zip code failed validation.', 'woocommerce-gateway-stripe' ),
353
-			'card_declined'         => __( 'The card was declined.', 'woocommerce-gateway-stripe' ),
354
-			'missing'               => __( 'There is no card on a customer that is being charged.', 'woocommerce-gateway-stripe' ),
355
-			'processing_error'      => __( 'An error occurred while processing the card.', 'woocommerce-gateway-stripe' ),
356
-			'invalid_request_error' => __( 'Could not find payment information.', 'woocommerce-gateway-stripe' ),
357
-			) );
344
+		return apply_filters('wc_stripe_localized_messages', array(
345
+			'invalid_number'        => __('The card number is not a valid credit card number.', 'woocommerce-gateway-stripe'),
346
+			'invalid_expiry_month'  => __('The card\'s expiration month is invalid.', 'woocommerce-gateway-stripe'),
347
+			'invalid_expiry_year'   => __('The card\'s expiration year is invalid.', 'woocommerce-gateway-stripe'),
348
+			'invalid_cvc'           => __('The card\'s security code is invalid.', 'woocommerce-gateway-stripe'),
349
+			'incorrect_number'      => __('The card number is incorrect.', 'woocommerce-gateway-stripe'),
350
+			'expired_card'          => __('The card has expired.', 'woocommerce-gateway-stripe'),
351
+			'incorrect_cvc'         => __('The card\'s security code is incorrect.', 'woocommerce-gateway-stripe'),
352
+			'incorrect_zip'         => __('The card\'s zip code failed validation.', 'woocommerce-gateway-stripe'),
353
+			'card_declined'         => __('The card was declined.', 'woocommerce-gateway-stripe'),
354
+			'missing'               => __('There is no card on a customer that is being charged.', 'woocommerce-gateway-stripe'),
355
+			'processing_error'      => __('An error occurred while processing the card.', 'woocommerce-gateway-stripe'),
356
+			'invalid_request_error' => __('Could not find payment information.', 'woocommerce-gateway-stripe'),
357
+			));
358 358
 	}
359 359
 
360 360
 	/**
@@ -365,26 +365,26 @@  discard block
 block discarded – undo
365 365
 	 * @access public
366 366
 	 */
367 367
 	public function payment_scripts() {
368
-		$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
368
+		$suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';
369 369
 		
370
-		if ( $this->stripe_checkout ) {
371
-			wp_enqueue_script( 'stripe', 'https://checkout.stripe.com/v2/checkout.js', '', '2.0', true );
372
-			wp_enqueue_script( 'woocommerce_stripe', plugins_url( 'assets/js/stripe_checkout' . $suffix . '.js', WC_STRIPE_MAIN_FILE ), array( 'stripe' ), WC_STRIPE_VERSION, true );
370
+		if ($this->stripe_checkout) {
371
+			wp_enqueue_script('stripe', 'https://checkout.stripe.com/v2/checkout.js', '', '2.0', true);
372
+			wp_enqueue_script('woocommerce_stripe', plugins_url('assets/js/stripe_checkout' . $suffix . '.js', WC_STRIPE_MAIN_FILE), array('stripe'), WC_STRIPE_VERSION, true);
373 373
 		} else {
374
-			wp_enqueue_script( 'stripe', 'https://js.stripe.com/v2/', '', '1.0', true );
375
-			wp_enqueue_script( 'woocommerce_stripe', plugins_url( 'assets/js/stripe' . $suffix . '.js', WC_STRIPE_MAIN_FILE ), array( 'jquery-payment', 'stripe' ), WC_STRIPE_VERSION, true );
374
+			wp_enqueue_script('stripe', 'https://js.stripe.com/v2/', '', '1.0', true);
375
+			wp_enqueue_script('woocommerce_stripe', plugins_url('assets/js/stripe' . $suffix . '.js', WC_STRIPE_MAIN_FILE), array('jquery-payment', 'stripe'), WC_STRIPE_VERSION, true);
376 376
 		}
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'] = $order->billing_first_name;
390 390
 			$stripe_params['billing_last_name']  = $order->billing_last_name;
@@ -396,14 +396,14 @@  discard block
 block discarded – undo
396 396
 			$stripe_params['billing_country']    = $order->billing_country;
397 397
 		}
398 398
 
399
-		$stripe_params['no_prepaid_card_msg']                     = __( 'Sorry, we\'re not accepting prepaid cards at this time.', 'woocommerce-gateway-stripe' );
400
-		$stripe_params['allow_prepaid_card']                      = apply_filters( 'wc_stripe_allow_prepaid_card', true ) ? 'yes' : 'no';
401
-		$stripe_params['stripe_checkout_require_billing_address'] = apply_filters( 'wc_stripe_checkout_require_billing_address', false ) ? 'yes' : 'no';
399
+		$stripe_params['no_prepaid_card_msg']                     = __('Sorry, we\'re not accepting prepaid cards at this time.', 'woocommerce-gateway-stripe');
400
+		$stripe_params['allow_prepaid_card']                      = apply_filters('wc_stripe_allow_prepaid_card', true) ? 'yes' : 'no';
401
+		$stripe_params['stripe_checkout_require_billing_address'] = apply_filters('wc_stripe_checkout_require_billing_address', false) ? 'yes' : 'no';
402 402
 
403 403
 		// merge localized messages to be use in JS
404
-		$stripe_params = array_merge( $stripe_params, $this->get_localized_messages() );
404
+		$stripe_params = array_merge($stripe_params, $this->get_localized_messages());
405 405
 
406
-		wp_localize_script( 'woocommerce_stripe', 'wc_stripe_params', apply_filters( 'wc_stripe_params', $stripe_params ) );
406
+		wp_localize_script('woocommerce_stripe', 'wc_stripe_params', apply_filters('wc_stripe_params', $stripe_params));
407 407
 	}
408 408
 
409 409
 	/**
@@ -412,24 +412,24 @@  discard block
 block discarded – undo
412 412
 	 * @param  object $source
413 413
 	 * @return array()
414 414
 	 */
415
-	protected function generate_payment_request( $order, $source ) {
415
+	protected function generate_payment_request($order, $source) {
416 416
 		$post_data                = array();
417
-		$post_data['currency']    = strtolower( $order->get_order_currency() ? $order->get_order_currency() : get_woocommerce_currency() );
418
-		$post_data['amount']      = $this->get_stripe_amount( $order->get_total(), $post_data['currency'] );
419
-		$post_data['description'] = sprintf( __( '%s - Order %s', 'woocommerce-gateway-stripe' ), wp_specialchars_decode( get_bloginfo( 'name' ), ENT_QUOTES ), $order->get_order_number() );
417
+		$post_data['currency']    = strtolower($order->get_order_currency() ? $order->get_order_currency() : get_woocommerce_currency());
418
+		$post_data['amount']      = $this->get_stripe_amount($order->get_total(), $post_data['currency']);
419
+		$post_data['description'] = sprintf(__('%s - Order %s', 'woocommerce-gateway-stripe'), wp_specialchars_decode(get_bloginfo('name'), ENT_QUOTES), $order->get_order_number());
420 420
 		$post_data['capture']     = $this->capture ? 'true' : 'false';
421 421
 
422
-		if ( ! empty( $order->billing_email ) && apply_filters( 'wc_stripe_send_stripe_receipt', false ) ) {
422
+		if ( ! empty($order->billing_email) && apply_filters('wc_stripe_send_stripe_receipt', false)) {
423 423
 			$post_data['receipt_email'] = $order->billing_email;
424 424
 		}
425 425
 
426
-		$post_data['expand[]']    = 'balance_transaction';
426
+		$post_data['expand[]'] = 'balance_transaction';
427 427
 
428
-		if ( $source->customer ) {
428
+		if ($source->customer) {
429 429
 			$post_data['customer'] = $source->customer;
430 430
 		}
431 431
 
432
-		if ( $source->source ) {
432
+		if ($source->source) {
433 433
 			$post_data['source'] = $source->source;
434 434
 		}
435 435
 
@@ -441,7 +441,7 @@  discard block
 block discarded – undo
441 441
 		 * @param WC_Order $order
442 442
 		 * @param object $source
443 443
 		 */
444
-		return apply_filters( 'wc_stripe_generate_payment_request', $post_data, $order, $source );
444
+		return apply_filters('wc_stripe_generate_payment_request', $post_data, $order, $source);
445 445
 	}
446 446
 
447 447
 	/**
@@ -453,22 +453,22 @@  discard block
 block discarded – undo
453 453
 	 * @throws Exception When card was not added or for and invalid card.
454 454
 	 * @return object
455 455
 	 */
456
-	protected function get_source( $user_id, $force_customer = false ) {
457
-		$stripe_customer = new WC_Stripe_Customer( $user_id );
456
+	protected function get_source($user_id, $force_customer = false) {
457
+		$stripe_customer = new WC_Stripe_Customer($user_id);
458 458
 		$stripe_source   = false;
459 459
 		$token_id        = false;
460 460
 
461 461
 		// New CC info was entered and we have a new token to process
462
-		if ( isset( $_POST['stripe_token'] ) ) {
463
-			$stripe_token     = wc_clean( $_POST['stripe_token'] );
464
-			$maybe_saved_card = isset( $_POST['wc-stripe-new-payment-method'] ) && ! empty( $_POST['wc-stripe-new-payment-method'] );
462
+		if (isset($_POST['stripe_token'])) {
463
+			$stripe_token     = wc_clean($_POST['stripe_token']);
464
+			$maybe_saved_card = isset($_POST['wc-stripe-new-payment-method']) && ! empty($_POST['wc-stripe-new-payment-method']);
465 465
 
466 466
 			// This is true if the user wants to store the card to their account.
467
-			if ( ( $user_id && $this->saved_cards && $maybe_saved_card ) || $force_customer ) {
468
-				$stripe_source = $stripe_customer->add_card( $stripe_token );
467
+			if (($user_id && $this->saved_cards && $maybe_saved_card) || $force_customer) {
468
+				$stripe_source = $stripe_customer->add_card($stripe_token);
469 469
 
470
-				if ( is_wp_error( $stripe_source ) ) {
471
-					throw new Exception( $stripe_source->get_error_message() );
470
+				if (is_wp_error($stripe_source)) {
471
+					throw new Exception($stripe_source->get_error_message());
472 472
 				}
473 473
 
474 474
 			} else {
@@ -479,13 +479,13 @@  discard block
 block discarded – undo
479 479
 		}
480 480
 
481 481
 		// Use an existing token, and then process the payment
482
-		elseif ( isset( $_POST['wc-stripe-payment-token'] ) && 'new' !== $_POST['wc-stripe-payment-token'] ) {
483
-			$token_id = wc_clean( $_POST['wc-stripe-payment-token'] );
484
-			$token    = WC_Payment_Tokens::get( $token_id );
482
+		elseif (isset($_POST['wc-stripe-payment-token']) && 'new' !== $_POST['wc-stripe-payment-token']) {
483
+			$token_id = wc_clean($_POST['wc-stripe-payment-token']);
484
+			$token    = WC_Payment_Tokens::get($token_id);
485 485
 
486
-			if ( ! $token || $token->get_user_id() !== get_current_user_id() ) {
487
-				WC()->session->set( 'refresh_totals', true );
488
-				throw new Exception( __( 'Invalid payment method. Please input a new card number.', 'woocommerce-gateway-stripe' ) );
486
+			if ( ! $token || $token->get_user_id() !== get_current_user_id()) {
487
+				WC()->session->set('refresh_totals', true);
488
+				throw new Exception(__('Invalid payment method. Please input a new card number.', 'woocommerce-gateway-stripe'));
489 489
 			}
490 490
 
491 491
 			$stripe_source = $token->get_token();
@@ -509,16 +509,16 @@  discard block
 block discarded – undo
509 509
 	 * @param object $order
510 510
 	 * @return object
511 511
 	 */
512
-	protected function get_order_source( $order = null ) {
512
+	protected function get_order_source($order = null) {
513 513
 		$stripe_customer = new WC_Stripe_Customer();
514 514
 		$stripe_source   = false;
515 515
 		$token_id        = false;
516 516
 
517
-		if ( $order ) {
518
-			if ( $meta_value = get_post_meta( $order->id, '_stripe_customer_id', true ) ) {
519
-				$stripe_customer->set_id( $meta_value );
517
+		if ($order) {
518
+			if ($meta_value = get_post_meta($order->id, '_stripe_customer_id', true)) {
519
+				$stripe_customer->set_id($meta_value);
520 520
 			}
521
-			if ( $meta_value = get_post_meta( $order->id, '_stripe_card_id', true ) ) {
521
+			if ($meta_value = get_post_meta($order->id, '_stripe_card_id', true)) {
522 522
 				$stripe_source = $meta_value;
523 523
 			}
524 524
 		}
@@ -541,50 +541,50 @@  discard block
 block discarded – undo
541 541
 	 *
542 542
 	 * @return array|void
543 543
 	 */
544
-	public function process_payment( $order_id, $retry = true, $force_customer = false ) {
544
+	public function process_payment($order_id, $retry = true, $force_customer = false) {
545 545
 		try {
546
-			$order  = wc_get_order( $order_id );
547
-			$source = $this->get_source( get_current_user_id(), $force_customer );
546
+			$order  = wc_get_order($order_id);
547
+			$source = $this->get_source(get_current_user_id(), $force_customer);
548 548
 
549
-			if ( empty( $source->source ) && empty( $source->customer ) ) {
550
-				$error_msg = __( 'Please enter your card details to make a payment.', 'woocommerce-gateway-stripe' );
551
-				$error_msg .= ' ' . __( 'Developers: Please make sure that you are including jQuery and there are no JavaScript errors on the page.', 'woocommerce-gateway-stripe' );
552
-				throw new Exception( $error_msg );
549
+			if (empty($source->source) && empty($source->customer)) {
550
+				$error_msg = __('Please enter your card details to make a payment.', 'woocommerce-gateway-stripe');
551
+				$error_msg .= ' ' . __('Developers: Please make sure that you are including jQuery and there are no JavaScript errors on the page.', 'woocommerce-gateway-stripe');
552
+				throw new Exception($error_msg);
553 553
 			}
554 554
 
555 555
 			// Store source to order meta.
556
-			$this->save_source( $order, $source );
556
+			$this->save_source($order, $source);
557 557
 
558 558
 			// Handle payment.
559
-			if ( $order->get_total() > 0 ) {
559
+			if ($order->get_total() > 0) {
560 560
 
561
-				if ( $order->get_total() * 100 < 50 ) {
562
-					throw new Exception( __( 'Sorry, the minimum allowed order total is 0.50 to use this payment method.', 'woocommerce-gateway-stripe' ) );
561
+				if ($order->get_total() * 100 < 50) {
562
+					throw new Exception(__('Sorry, the minimum allowed order total is 0.50 to use this payment method.', 'woocommerce-gateway-stripe'));
563 563
 				}
564 564
 
565
-				WC_Stripe::log( "Info: Begin processing payment for order $order_id for the amount of {$order->get_total()}" );
565
+				WC_Stripe::log("Info: Begin processing payment for order $order_id for the amount of {$order->get_total()}");
566 566
 
567 567
 				// Make the request.
568
-				$response = WC_Stripe_API::request( $this->generate_payment_request( $order, $source ) );
568
+				$response = WC_Stripe_API::request($this->generate_payment_request($order, $source));
569 569
 
570
-				if ( is_wp_error( $response ) ) {
570
+				if (is_wp_error($response)) {
571 571
 					// Customer param wrong? The user may have been deleted on stripe's end. Remove customer_id. Can be retried without.
572
-					if ( 'customer' === $response->get_error_code() && $retry ) {
573
-						delete_user_meta( get_current_user_id(), '_stripe_customer_id' );
574
-						return $this->process_payment( $order_id, false, $force_customer );
572
+					if ('customer' === $response->get_error_code() && $retry) {
573
+						delete_user_meta(get_current_user_id(), '_stripe_customer_id');
574
+						return $this->process_payment($order_id, false, $force_customer);
575 575
 						// Source param wrong? The CARD may have been deleted on stripe's end. Remove token and show message.
576
-					} elseif ( 'source' === $response->get_error_code() && $source->token_id ) {
577
-						$token = WC_Payment_Tokens::get( $source->token_id );
576
+					} elseif ('source' === $response->get_error_code() && $source->token_id) {
577
+						$token = WC_Payment_Tokens::get($source->token_id);
578 578
 						$token->delete();
579
-						throw new Exception( __( 'This card is no longer available and has been removed.', 'woocommerce-gateway-stripe' ) );
579
+						throw new Exception(__('This card is no longer available and has been removed.', 'woocommerce-gateway-stripe'));
580 580
 					}
581 581
 					$localized_messages = $this->get_localized_messages();
582 582
 
583
-					throw new Exception( ( isset( $localized_messages[ $response->get_error_code() ] ) ? $localized_messages[ $response->get_error_code() ] : $response->get_error_message() ) );
583
+					throw new Exception((isset($localized_messages[$response->get_error_code()]) ? $localized_messages[$response->get_error_code()] : $response->get_error_message()));
584 584
 				}
585 585
 
586 586
 				// Process valid response.
587
-				$this->process_response( $response, $order );
587
+				$this->process_response($response, $order);
588 588
 			} else {
589 589
 				$order->payment_complete();
590 590
 			}
@@ -595,16 +595,16 @@  discard block
 block discarded – undo
595 595
 			// Return thank you page redirect.
596 596
 			return array(
597 597
 				'result'   => 'success',
598
-				'redirect' => $this->get_return_url( $order )
598
+				'redirect' => $this->get_return_url($order)
599 599
 			);
600 600
 
601
-		} catch ( Exception $e ) {
602
-			wc_add_notice( $e->getMessage(), 'error' );
603
-			WC()->session->set( 'refresh_totals', true );
604
-			WC_Stripe::log( sprintf( __( 'Error: %s', 'woocommerce-gateway-stripe' ), $e->getMessage() ) );
601
+		} catch (Exception $e) {
602
+			wc_add_notice($e->getMessage(), 'error');
603
+			WC()->session->set('refresh_totals', true);
604
+			WC_Stripe::log(sprintf(__('Error: %s', 'woocommerce-gateway-stripe'), $e->getMessage()));
605 605
 
606
-			if ( $order->has_status( array( 'pending', 'failed' ) ) ) {
607
-				$this->send_failed_order_email( $order_id );
606
+			if ($order->has_status(array('pending', 'failed'))) {
607
+				$this->send_failed_order_email($order_id);
608 608
 			}
609 609
 
610 610
 			return;
@@ -617,49 +617,49 @@  discard block
 block discarded – undo
617 617
 	 * @param WC_Order $order For to which the source applies.
618 618
 	 * @param stdClass $source Source information.
619 619
 	 */
620
-	protected function save_source( $order, $source ) {
620
+	protected function save_source($order, $source) {
621 621
 		// Store source in the order.
622
-		if ( $source->customer ) {
623
-			update_post_meta( $order->id, '_stripe_customer_id', $source->customer );
622
+		if ($source->customer) {
623
+			update_post_meta($order->id, '_stripe_customer_id', $source->customer);
624 624
 		}
625
-		if ( $source->source ) {
626
-			update_post_meta( $order->id, '_stripe_card_id', $source->source );
625
+		if ($source->source) {
626
+			update_post_meta($order->id, '_stripe_card_id', $source->source);
627 627
 		}
628 628
 	}
629 629
 
630 630
 	/**
631 631
 	 * Store extra meta data for an order from a Stripe Response.
632 632
 	 */
633
-	public function process_response( $response, $order ) {
634
-		WC_Stripe::log( "Processing response: " . print_r( $response, true ) );
633
+	public function process_response($response, $order) {
634
+		WC_Stripe::log("Processing response: " . print_r($response, true));
635 635
 
636 636
 		// Store charge data
637
-		update_post_meta( $order->id, '_stripe_charge_id', $response->id );
638
-		update_post_meta( $order->id, '_stripe_charge_captured', $response->captured ? 'yes' : 'no' );
637
+		update_post_meta($order->id, '_stripe_charge_id', $response->id);
638
+		update_post_meta($order->id, '_stripe_charge_captured', $response->captured ? 'yes' : 'no');
639 639
 
640 640
 		// Store other data such as fees
641
-		if ( isset( $response->balance_transaction ) && isset( $response->balance_transaction->fee ) ) {
642
-			$fee = number_format( $response->balance_transaction->fee / 100, 2, '.', '' );
643
-			update_post_meta( $order->id, 'Stripe Fee', $fee );
644
-			update_post_meta( $order->id, 'Net Revenue From Stripe', $order->get_total() - $fee );
641
+		if (isset($response->balance_transaction) && isset($response->balance_transaction->fee)) {
642
+			$fee = number_format($response->balance_transaction->fee / 100, 2, '.', '');
643
+			update_post_meta($order->id, 'Stripe Fee', $fee);
644
+			update_post_meta($order->id, 'Net Revenue From Stripe', $order->get_total() - $fee);
645 645
 		}
646 646
 
647
-		if ( $response->captured ) {
648
-			$order->payment_complete( $response->id );
647
+		if ($response->captured) {
648
+			$order->payment_complete($response->id);
649 649
 
650
-			$message = sprintf( __( 'Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe' ), $response->id );
651
-			$order->add_order_note( $message );
652
-			WC_Stripe::log( 'Success: ' . $message );
650
+			$message = sprintf(__('Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe'), $response->id);
651
+			$order->add_order_note($message);
652
+			WC_Stripe::log('Success: ' . $message);
653 653
 
654 654
 		} else {
655
-			add_post_meta( $order->id, '_transaction_id', $response->id, true );
655
+			add_post_meta($order->id, '_transaction_id', $response->id, true);
656 656
 
657
-			if ( $order->has_status( array( 'pending', 'failed' ) ) ) {
657
+			if ($order->has_status(array('pending', 'failed'))) {
658 658
 				$order->reduce_order_stock();
659 659
 			}
660 660
 
661
-			$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 ) );
662
-			WC_Stripe::log( "Successful auth: $response->id" );
661
+			$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));
662
+			WC_Stripe::log("Successful auth: $response->id");
663 663
 		}
664 664
 
665 665
 		return $response;
@@ -671,32 +671,32 @@  discard block
 block discarded – undo
671 671
 	 * @since 3.0.0
672 672
 	 */
673 673
 	public function add_payment_method() {
674
-		if ( empty( $_POST['stripe_token'] ) || ! is_user_logged_in() ) {
675
-			wc_add_notice( __( 'There was a problem adding the card.', 'woocommerce-gateway-stripe' ), 'error' );
674
+		if (empty($_POST['stripe_token']) || ! is_user_logged_in()) {
675
+			wc_add_notice(__('There was a problem adding the card.', 'woocommerce-gateway-stripe'), 'error');
676 676
 			return;
677 677
 		}
678 678
 
679
-		$stripe_customer = new WC_Stripe_Customer( get_current_user_id() );
680
-		$card            = $stripe_customer->add_card( wc_clean( $_POST['stripe_token'] ) );
679
+		$stripe_customer = new WC_Stripe_Customer(get_current_user_id());
680
+		$card            = $stripe_customer->add_card(wc_clean($_POST['stripe_token']));
681 681
 
682
-		if ( is_wp_error( $card ) ) {
682
+		if (is_wp_error($card)) {
683 683
 			$localized_messages = $this->get_localized_messages();
684
-			$error_msg = __( 'There was a problem adding the card.', 'woocommerce-gateway-stripe' );
684
+			$error_msg = __('There was a problem adding the card.', 'woocommerce-gateway-stripe');
685 685
 
686 686
 			// loop through the errors to find matching localized message
687
-			foreach ( $card->errors as $error => $msg ) {
688
-				if ( isset( $localized_messages[ $error ] ) ) {
689
-					$error_msg = $localized_messages[ $error ];
687
+			foreach ($card->errors as $error => $msg) {
688
+				if (isset($localized_messages[$error])) {
689
+					$error_msg = $localized_messages[$error];
690 690
 				}
691 691
 			}
692 692
 
693
-			wc_add_notice( $error_msg, 'error' );
693
+			wc_add_notice($error_msg, 'error');
694 694
 			return;
695 695
 		}
696 696
 
697 697
 		return array(
698 698
 			'result'   => 'success',
699
-			'redirect' => wc_get_endpoint_url( 'payment-methods' ),
699
+			'redirect' => wc_get_endpoint_url('payment-methods'),
700 700
 		);
701 701
 	}
702 702
 
@@ -706,36 +706,36 @@  discard block
 block discarded – undo
706 706
 	 * @param  float $amount
707 707
 	 * @return bool
708 708
 	 */
709
-	public function process_refund( $order_id, $amount = null, $reason = '' ) {
710
-		$order = wc_get_order( $order_id );
709
+	public function process_refund($order_id, $amount = null, $reason = '') {
710
+		$order = wc_get_order($order_id);
711 711
 
712
-		if ( ! $order || ! $order->get_transaction_id() ) {
712
+		if ( ! $order || ! $order->get_transaction_id()) {
713 713
 			return false;
714 714
 		}
715 715
 
716 716
 		$body = array();
717 717
 
718
-		if ( ! is_null( $amount ) ) {
719
-			$body['amount']	= $this->get_stripe_amount( $amount );
718
+		if ( ! is_null($amount)) {
719
+			$body['amount'] = $this->get_stripe_amount($amount);
720 720
 		}
721 721
 
722
-		if ( $reason ) {
722
+		if ($reason) {
723 723
 			$body['metadata'] = array(
724 724
 				'reason'	=> $reason,
725 725
 			);
726 726
 		}
727 727
 
728
-		WC_Stripe::log( "Info: Beginning refund for order $order_id for the amount of {$amount}" );
728
+		WC_Stripe::log("Info: Beginning refund for order $order_id for the amount of {$amount}");
729 729
 
730
-		$response = WC_Stripe_API::request( $body, 'charges/' . $order->get_transaction_id() . '/refunds' );
730
+		$response = WC_Stripe_API::request($body, 'charges/' . $order->get_transaction_id() . '/refunds');
731 731
 
732
-		if ( is_wp_error( $response ) ) {
733
-			WC_Stripe::log( "Error: " . $response->get_error_message() );
732
+		if (is_wp_error($response)) {
733
+			WC_Stripe::log("Error: " . $response->get_error_message());
734 734
 			return $response;
735
-		} elseif ( ! empty( $response->id ) ) {
736
-			$refund_message = sprintf( __( 'Refunded %s - Refund ID: %s - Reason: %s', 'woocommerce-gateway-stripe' ), wc_price( $response->amount / 100 ), $response->id, $reason );
737
-			$order->add_order_note( $refund_message );
738
-			WC_Stripe::log( "Success: " . html_entity_decode( strip_tags( $refund_message ) ) );
735
+		} elseif ( ! empty($response->id)) {
736
+			$refund_message = sprintf(__('Refunded %s - Refund ID: %s - Reason: %s', 'woocommerce-gateway-stripe'), wc_price($response->amount / 100), $response->id, $reason);
737
+			$order->add_order_note($refund_message);
738
+			WC_Stripe::log("Success: " . html_entity_decode(strip_tags($refund_message)));
739 739
 			return true;
740 740
 		}
741 741
 	}
@@ -748,10 +748,10 @@  discard block
 block discarded – undo
748 748
 	 * @param int $order_id
749 749
 	 * @return null
750 750
 	 */
751
-	public function send_failed_order_email( $order_id ) {
751
+	public function send_failed_order_email($order_id) {
752 752
 		$emails = WC()->mailer()->get_emails();
753
-		if ( ! empty( $emails ) && ! empty( $order_id ) ) {
754
-			$emails['WC_Email_Failed_Order']->trigger( $order_id );
753
+		if ( ! empty($emails) && ! empty($order_id)) {
754
+			$emails['WC_Email_Failed_Order']->trigger($order_id);
755 755
 		}
756 756
 	}
757 757
 }
Please login to merge, or discard this patch.