Completed
Push — master ( 3bc67e...d8e4b2 )
by Roy
06:35
created
includes/legacy/class-wc-gateway-stripe.php 1 patch
Spacing   +186 added lines, -186 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
 
@@ -15,8 +15,8 @@  discard block
 block discarded – undo
15 15
 	 */
16 16
 	public function __construct() {
17 17
 		$this->id                   = 'stripe';
18
-		$this->method_title         = __( 'Stripe', 'woocommerce-gateway-stripe' );
19
-		$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' );
18
+		$this->method_title         = __('Stripe', 'woocommerce-gateway-stripe');
19
+		$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');
20 20
 		$this->has_fields           = true;
21 21
 		$this->view_transaction_url = 'https://dashboard.stripe.com/payments/%s';
22 22
 		$this->supports             = array(
@@ -42,35 +42,35 @@  discard block
 block discarded – undo
42 42
 		$this->init_settings();
43 43
 
44 44
 		// Get setting values.
45
-		$this->title                  = $this->get_option( 'title' );
46
-		$this->description            = $this->get_option( 'description' );
47
-		$this->enabled                = $this->get_option( 'enabled' );
48
-		$this->testmode               = 'yes' === $this->get_option( 'testmode' );
49
-		$this->capture                = 'yes' === $this->get_option( 'capture', 'yes' );
50
-		$this->stripe_checkout        = 'yes' === $this->get_option( 'stripe_checkout' );
51
-		$this->stripe_checkout_locale = $this->get_option( 'stripe_checkout_locale' );
52
-		$this->stripe_checkout_image  = $this->get_option( 'stripe_checkout_image', '' );
53
-		$this->saved_cards            = 'yes' === $this->get_option( 'saved_cards' );
54
-		$this->secret_key             = $this->testmode ? $this->get_option( 'test_secret_key' ) : $this->get_option( 'secret_key' );
55
-		$this->publishable_key        = $this->testmode ? $this->get_option( 'test_publishable_key' ) : $this->get_option( 'publishable_key' );
56
-		$this->bitcoin                = 'USD' === strtoupper( get_woocommerce_currency() ) && 'yes' === $this->get_option( 'stripe_bitcoin' );
57
-		$this->logging                = 'yes' === $this->get_option( 'logging' );
58
-
59
-		if ( $this->stripe_checkout ) {
60
-			$this->order_button_text = __( 'Continue to payment', 'woocommerce-gateway-stripe' );
45
+		$this->title                  = $this->get_option('title');
46
+		$this->description            = $this->get_option('description');
47
+		$this->enabled                = $this->get_option('enabled');
48
+		$this->testmode               = 'yes' === $this->get_option('testmode');
49
+		$this->capture                = 'yes' === $this->get_option('capture', 'yes');
50
+		$this->stripe_checkout        = 'yes' === $this->get_option('stripe_checkout');
51
+		$this->stripe_checkout_locale = $this->get_option('stripe_checkout_locale');
52
+		$this->stripe_checkout_image  = $this->get_option('stripe_checkout_image', '');
53
+		$this->saved_cards            = 'yes' === $this->get_option('saved_cards');
54
+		$this->secret_key             = $this->testmode ? $this->get_option('test_secret_key') : $this->get_option('secret_key');
55
+		$this->publishable_key        = $this->testmode ? $this->get_option('test_publishable_key') : $this->get_option('publishable_key');
56
+		$this->bitcoin                = 'USD' === strtoupper(get_woocommerce_currency()) && 'yes' === $this->get_option('stripe_bitcoin');
57
+		$this->logging                = 'yes' === $this->get_option('logging');
58
+
59
+		if ($this->stripe_checkout) {
60
+			$this->order_button_text = __('Continue to payment', 'woocommerce-gateway-stripe');
61 61
 		}
62 62
 
63
-		if ( $this->testmode ) {
64
-			$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' );
65
-			$this->description  = trim( $this->description );
63
+		if ($this->testmode) {
64
+			$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');
65
+			$this->description  = trim($this->description);
66 66
 		}
67 67
 
68
-		WC_Stripe_API::set_secret_key( $this->secret_key );
68
+		WC_Stripe_API::set_secret_key($this->secret_key);
69 69
 
70 70
 		// Hooks
71
-		add_action( 'wp_enqueue_scripts', array( $this, 'payment_scripts' ) );
72
-		add_action( 'admin_notices', array( $this, 'admin_notices' ) );
73
-		add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) );
71
+		add_action('wp_enqueue_scripts', array($this, 'payment_scripts'));
72
+		add_action('admin_notices', array($this, 'admin_notices'));
73
+		add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options'));
74 74
 	}
75 75
 
76 76
 	/**
@@ -80,37 +80,37 @@  discard block
 block discarded – undo
80 80
 	 * @return string
81 81
 	 */
82 82
 	public function get_icon() {
83
-		$ext   = version_compare( WC()->version, '2.6', '>=' ) ? '.svg' : '.png';
84
-		$style = version_compare( WC()->version, '2.6', '>=' ) ? 'style="margin-left: 0.3em"' : '';
83
+		$ext   = version_compare(WC()->version, '2.6', '>=') ? '.svg' : '.png';
84
+		$style = version_compare(WC()->version, '2.6', '>=') ? 'style="margin-left: 0.3em"' : '';
85 85
 
86
-		$icon  = '<img src="' . WC_HTTPS::force_https_url( WC()->plugin_url() . '/assets/images/icons/credit-cards/visa' . $ext ) . '" alt="Visa" width="32" ' . $style . ' />';
87
-		$icon .= '<img src="' . WC_HTTPS::force_https_url( WC()->plugin_url() . '/assets/images/icons/credit-cards/mastercard' . $ext ) . '" alt="Mastercard" width="32" ' . $style . ' />';
88
-		$icon .= '<img src="' . WC_HTTPS::force_https_url( WC()->plugin_url() . '/assets/images/icons/credit-cards/amex' . $ext ) . '" alt="Amex" width="32" ' . $style . ' />';
86
+		$icon  = '<img src="' . WC_HTTPS::force_https_url(WC()->plugin_url() . '/assets/images/icons/credit-cards/visa' . $ext) . '" alt="Visa" width="32" ' . $style . ' />';
87
+		$icon .= '<img src="' . WC_HTTPS::force_https_url(WC()->plugin_url() . '/assets/images/icons/credit-cards/mastercard' . $ext) . '" alt="Mastercard" width="32" ' . $style . ' />';
88
+		$icon .= '<img src="' . WC_HTTPS::force_https_url(WC()->plugin_url() . '/assets/images/icons/credit-cards/amex' . $ext) . '" alt="Amex" width="32" ' . $style . ' />';
89 89
 
90 90
 		$base_location = wc_get_base_location();
91 91
 
92
-		if ( 'US' === $base_location['country'] ) {
93
-			$icon .= '<img src="' . WC_HTTPS::force_https_url( WC()->plugin_url() . '/assets/images/icons/credit-cards/discover' . $ext ) . '" alt="Discover" width="32" ' . $style . ' />';
94
-			$icon .= '<img src="' . WC_HTTPS::force_https_url( WC()->plugin_url() . '/assets/images/icons/credit-cards/jcb' . $ext ) . '" alt="JCB" width="32" ' . $style . ' />';
95
-			$icon .= '<img src="' . WC_HTTPS::force_https_url( WC()->plugin_url() . '/assets/images/icons/credit-cards/diners' . $ext ) . '" alt="Diners" width="32" ' . $style . ' />';
92
+		if ('US' === $base_location['country']) {
93
+			$icon .= '<img src="' . WC_HTTPS::force_https_url(WC()->plugin_url() . '/assets/images/icons/credit-cards/discover' . $ext) . '" alt="Discover" width="32" ' . $style . ' />';
94
+			$icon .= '<img src="' . WC_HTTPS::force_https_url(WC()->plugin_url() . '/assets/images/icons/credit-cards/jcb' . $ext) . '" alt="JCB" width="32" ' . $style . ' />';
95
+			$icon .= '<img src="' . WC_HTTPS::force_https_url(WC()->plugin_url() . '/assets/images/icons/credit-cards/diners' . $ext) . '" alt="Diners" width="32" ' . $style . ' />';
96 96
 		}
97 97
 
98
-		if ( $this->bitcoin ) {
99
-			$icon .= '<img src="' . WC_HTTPS::force_https_url( plugins_url( '/assets/images/bitcoin' . $ext, WC_STRIPE_MAIN_FILE ) ) . '" alt="Bitcoin" width="32" ' . $style . ' />';
98
+		if ($this->bitcoin) {
99
+			$icon .= '<img src="' . WC_HTTPS::force_https_url(plugins_url('/assets/images/bitcoin' . $ext, WC_STRIPE_MAIN_FILE)) . '" alt="Bitcoin" width="32" ' . $style . ' />';
100 100
 		}
101 101
 
102
-		return apply_filters( 'woocommerce_gateway_icon', $icon, $this->id );
102
+		return apply_filters('woocommerce_gateway_icon', $icon, $this->id);
103 103
 	}
104 104
 
105 105
 	/**
106 106
 	 * Get Stripe amount to pay
107 107
 	 * @return float
108 108
 	 */
109
-	public function get_stripe_amount( $total, $currency = '' ) {
110
-		if ( ! $currency ) {
109
+	public function get_stripe_amount($total, $currency = '') {
110
+		if ( ! $currency) {
111 111
 			$currency = get_woocommerce_currency();
112 112
 		}
113
-		switch ( strtoupper( $currency ) ) {
113
+		switch (strtoupper($currency)) {
114 114
 			// Zero decimal currencies
115 115
 			case 'BIF' :
116 116
 			case 'CLP' :
@@ -127,10 +127,10 @@  discard block
 block discarded – undo
127 127
 			case 'XAF' :
128 128
 			case 'XOF' :
129 129
 			case 'XPF' :
130
-				$total = absint( $total );
130
+				$total = absint($total);
131 131
 				break;
132 132
 			default :
133
-				$total = round( $total, 2 ) * 100; // In cents
133
+				$total = round($total, 2) * 100; // In cents
134 134
 				break;
135 135
 		}
136 136
 		return $total;
@@ -140,31 +140,31 @@  discard block
 block discarded – undo
140 140
 	 * Check if SSL is enabled and notify the user
141 141
 	 */
142 142
 	public function admin_notices() {
143
-		if ( $this->enabled == 'no' ) {
143
+		if ($this->enabled == 'no') {
144 144
 			return;
145 145
 		}
146 146
 
147
-		$addons = ( class_exists( 'WC_Subscriptions_Order' ) || class_exists( 'WC_Pre_Orders_Order' ) ) ? '_addons' : '';
147
+		$addons = (class_exists('WC_Subscriptions_Order') || class_exists('WC_Pre_Orders_Order')) ? '_addons' : '';
148 148
 
149 149
 		// Check required fields
150
-		if ( ! $this->secret_key ) {
151
-			echo '<div class="error"><p>' . sprintf( __( 'Stripe error: Please enter your secret key <a href="%s">here</a>', 'woocommerce-gateway-stripe' ), admin_url( 'admin.php?page=wc-settings&tab=checkout&section=wc_gateway_stripe' . $addons ) ) . '</p></div>';
150
+		if ( ! $this->secret_key) {
151
+			echo '<div class="error"><p>' . sprintf(__('Stripe error: Please enter your secret key <a href="%s">here</a>', 'woocommerce-gateway-stripe'), admin_url('admin.php?page=wc-settings&tab=checkout&section=wc_gateway_stripe' . $addons)) . '</p></div>';
152 152
 			return;
153 153
 
154
-		} elseif ( ! $this->publishable_key ) {
155
-			echo '<div class="error"><p>' . sprintf( __( 'Stripe error: Please enter your publishable key <a href="%s">here</a>', 'woocommerce-gateway-stripe' ), admin_url( 'admin.php?page=wc-settings&tab=checkout&section=wc_gateway_stripe' . $addons ) ) . '</p></div>';
154
+		} elseif ( ! $this->publishable_key) {
155
+			echo '<div class="error"><p>' . sprintf(__('Stripe error: Please enter your publishable key <a href="%s">here</a>', 'woocommerce-gateway-stripe'), admin_url('admin.php?page=wc-settings&tab=checkout&section=wc_gateway_stripe' . $addons)) . '</p></div>';
156 156
 			return;
157 157
 		}
158 158
 
159 159
 		// Simple check for duplicate keys
160
-		if ( $this->secret_key == $this->publishable_key ) {
161
-			echo '<div class="error"><p>' . sprintf( __( 'Stripe error: Your secret and publishable keys match. Please check and re-enter.', 'woocommerce-gateway-stripe' ), admin_url( 'admin.php?page=wc-settings&tab=checkout&section=wc_gateway_stripe' . $addons ) ) . '</p></div>';
160
+		if ($this->secret_key == $this->publishable_key) {
161
+			echo '<div class="error"><p>' . sprintf(__('Stripe error: Your secret and publishable keys match. Please check and re-enter.', 'woocommerce-gateway-stripe'), admin_url('admin.php?page=wc-settings&tab=checkout&section=wc_gateway_stripe' . $addons)) . '</p></div>';
162 162
 			return;
163 163
 		}
164 164
 
165 165
 		// Show message if enabled and FORCE SSL is disabled and WordpressHTTPS plugin is not detected
166
-		if ( ( function_exists( 'wc_site_is_https' ) && ! wc_site_is_https() ) && ( 'no' === get_option( 'woocommerce_force_ssl_checkout' ) && ! class_exists( 'WordPressHTTPS' ) ) ) {
167
-			echo '<div class="error"><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>';
166
+		if ((function_exists('wc_site_is_https') && ! wc_site_is_https()) && ('no' === get_option('woocommerce_force_ssl_checkout') && ! class_exists('WordPressHTTPS'))) {
167
+			echo '<div class="error"><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>';
168 168
 		}
169 169
 	}
170 170
 
@@ -172,11 +172,11 @@  discard block
 block discarded – undo
172 172
 	 * Check if this gateway is enabled
173 173
 	 */
174 174
 	public function is_available() {
175
-		if ( 'yes' === $this->enabled ) {
176
-			if ( ! $this->testmode && is_checkout() && ! is_ssl() ) {
175
+		if ('yes' === $this->enabled) {
176
+			if ( ! $this->testmode && is_checkout() && ! is_ssl()) {
177 177
 				return false;
178 178
 			}
179
-			if ( ! $this->secret_key || ! $this->publishable_key ) {
179
+			if ( ! $this->secret_key || ! $this->publishable_key) {
180 180
 				return false;
181 181
 			}
182 182
 			return true;
@@ -188,9 +188,9 @@  discard block
 block discarded – undo
188 188
 	 * Initialise Gateway Settings Form Fields
189 189
 	 */
190 190
 	public function init_form_fields() {
191
-		$this->form_fields = include( untrailingslashit( plugin_dir_path( WC_STRIPE_MAIN_FILE ) ) . '/includes/settings-stripe.php' );
191
+		$this->form_fields = include(untrailingslashit(plugin_dir_path(WC_STRIPE_MAIN_FILE)) . '/includes/settings-stripe.php');
192 192
 
193
-		wc_enqueue_js( "
193
+		wc_enqueue_js("
194 194
 			jQuery( function( $ ) {
195 195
 				$( '#woocommerce_stripe_stripe_checkout' ).change(function(){
196 196
 					if ( $( this ).is( ':checked' ) ) {
@@ -210,25 +210,25 @@  discard block
 block discarded – undo
210 210
 		?>
211 211
 		<fieldset class="stripe-legacy-payment-fields">
212 212
 			<?php
213
-				if ( $this->description ) {
214
-					echo apply_filters( 'wc_stripe_description', wpautop( wp_kses_post( $this->description ) ) );
213
+				if ($this->description) {
214
+					echo apply_filters('wc_stripe_description', wpautop(wp_kses_post($this->description)));
215 215
 				}
216
-				if ( $this->saved_cards && is_user_logged_in() ) {
217
-					$stripe_customer = new WC_Stripe_Customer( get_current_user_id() );
216
+				if ($this->saved_cards && is_user_logged_in()) {
217
+					$stripe_customer = new WC_Stripe_Customer(get_current_user_id());
218 218
 					?>
219 219
 					<p class="form-row form-row-wide">
220
-						<a class="<?php echo apply_filters( 'wc_stripe_manage_saved_cards_class', 'button' ); ?>" style="float:right;" href="<?php echo apply_filters( 'wc_stripe_manage_saved_cards_url', get_permalink( get_option( 'woocommerce_myaccount_page_id' ) ) ); ?>#saved-cards"><?php esc_html_e( 'Manage cards', 'woocommerce-gateway-stripe' ); ?></a>
220
+						<a class="<?php echo apply_filters('wc_stripe_manage_saved_cards_class', 'button'); ?>" style="float:right;" href="<?php echo apply_filters('wc_stripe_manage_saved_cards_url', get_permalink(get_option('woocommerce_myaccount_page_id'))); ?>#saved-cards"><?php esc_html_e('Manage cards', 'woocommerce-gateway-stripe'); ?></a>
221 221
 						<?php
222
-						if ( $cards = $stripe_customer->get_cards() ) {
222
+						if ($cards = $stripe_customer->get_cards()) {
223 223
 							$default_card = $cards[0]->id;
224
-							foreach ( (array) $cards as $card ) {
225
-								if ( 'card' !== $card->object ) {
224
+							foreach ((array) $cards as $card) {
225
+								if ('card' !== $card->object) {
226 226
 									continue;
227 227
 								}
228 228
 								?>
229
-								<label for="stripe_card_<?php echo $card->id; ?>" class="brand-<?php echo esc_attr( strtolower( $card->brand ) ); ?>">
230
-									<input type="radio" id="stripe_card_<?php echo $card->id; ?>" name="wc-stripe-payment-token" value="<?php echo $card->id; ?>" <?php checked( $default_card, $card->id ) ?> />
231
-									<?php printf( __( '%s card ending in %s (Expires %s/%s)', 'woocommerce-gateway-stripe' ), $card->brand, $card->last4, $card->exp_month, $card->exp_year ); ?>
229
+								<label for="stripe_card_<?php echo $card->id; ?>" class="brand-<?php echo esc_attr(strtolower($card->brand)); ?>">
230
+									<input type="radio" id="stripe_card_<?php echo $card->id; ?>" name="wc-stripe-payment-token" value="<?php echo $card->id; ?>" <?php checked($default_card, $card->id) ?> />
231
+									<?php printf(__('%s card ending in %s (Expires %s/%s)', 'woocommerce-gateway-stripe'), $card->brand, $card->last4, $card->exp_month, $card->exp_year); ?>
232 232
 								</label>
233 233
 								<?php
234 234
 							}
@@ -236,7 +236,7 @@  discard block
 block discarded – undo
236 236
 						?>
237 237
 						<label for="new">
238 238
 							<input type="radio" id="new" name="wc-stripe-payment-token" value="new" />
239
-							<?php _e( 'Use a new credit card', 'woocommerce-gateway-stripe' ); ?>
239
+							<?php _e('Use a new credit card', 'woocommerce-gateway-stripe'); ?>
240 240
 						</label>
241 241
 					</p>
242 242
 					<?php
@@ -244,8 +244,8 @@  discard block
 block discarded – undo
244 244
 
245 245
 				$user = wp_get_current_user();
246 246
 
247
-				if ( $user ) {
248
-					$user_email = get_user_meta( $user->ID, 'billing_email', true );
247
+				if ($user) {
248
+					$user_email = get_user_meta($user->ID, 'billing_email', true);
249 249
 					$user_email = $user_email ? $user_email : $user->user_email;
250 250
 				} else {
251 251
 					$user_email = '';
@@ -253,22 +253,22 @@  discard block
 block discarded – undo
253 253
 
254 254
 				$display = '';
255 255
 
256
-				if ( $this->stripe_checkout || $this->saved_cards && ! empty( $cards ) ) {
256
+				if ($this->stripe_checkout || $this->saved_cards && ! empty($cards)) {
257 257
 					$display = 'style="display:none;"';
258 258
 				}
259 259
 
260 260
 				echo '<div ' . $display . ' id="stripe-payment-data"
261 261
 					data-description=""
262
-					data-email="' . esc_attr( $user_email ) . '"
263
-					data-amount="' . esc_attr( $this->get_stripe_amount( WC()->cart->total ) ) . '"
264
-					data-name="' . esc_attr( get_bloginfo( 'name', 'display' ) ) . '"
265
-					data-currency="' . esc_attr( strtolower( get_woocommerce_currency() ) ) . '"
266
-					data-image="' . esc_attr( $this->stripe_checkout_image ) . '"
267
-					data-bitcoin="' . esc_attr( $this->bitcoin ? 'true' : 'false' ) . '"
268
-					data-locale="' . esc_attr( $this->stripe_checkout_locale ? $this->stripe_checkout_locale : 'en' ) . '">';
269
-
270
-				if ( ! $this->stripe_checkout ) {
271
-					$this->credit_card_form( array( 'fields_have_names' => false ) );
262
+					data-email="' . esc_attr($user_email) . '"
263
+					data-amount="' . esc_attr($this->get_stripe_amount(WC()->cart->total)) . '"
264
+					data-name="' . esc_attr(get_bloginfo('name', 'display')) . '"
265
+					data-currency="' . esc_attr(strtolower(get_woocommerce_currency())) . '"
266
+					data-image="' . esc_attr($this->stripe_checkout_image) . '"
267
+					data-bitcoin="' . esc_attr($this->bitcoin ? 'true' : 'false') . '"
268
+					data-locale="' . esc_attr($this->stripe_checkout_locale ? $this->stripe_checkout_locale : 'en') . '">';
269
+
270
+				if ( ! $this->stripe_checkout) {
271
+					$this->credit_card_form(array('fields_have_names' => false));
272 272
 				}
273 273
 
274 274
 				echo '</div>';
@@ -285,27 +285,27 @@  discard block
 block discarded – undo
285 285
 	 * @access public
286 286
 	 */
287 287
 	public function payment_scripts() {
288
-		if ( $this->stripe_checkout ) {
289
-			wp_enqueue_script( 'stripe', 'https://checkout.stripe.com/v2/checkout.js', '', '2.0', true );
290
-			wp_enqueue_script( 'woocommerce_stripe', plugins_url( 'assets/js/stripe_checkout.js', WC_STRIPE_MAIN_FILE ), array( 'stripe' ), WC_STRIPE_VERSION, true );
288
+		if ($this->stripe_checkout) {
289
+			wp_enqueue_script('stripe', 'https://checkout.stripe.com/v2/checkout.js', '', '2.0', true);
290
+			wp_enqueue_script('woocommerce_stripe', plugins_url('assets/js/stripe_checkout.js', WC_STRIPE_MAIN_FILE), array('stripe'), WC_STRIPE_VERSION, true);
291 291
 		} else {
292
-			wp_enqueue_script( 'stripe', 'https://js.stripe.com/v2/', '', '1.0', true );
293
-			wp_enqueue_script( 'woocommerce_stripe', plugins_url( 'assets/js/stripe.js', WC_STRIPE_MAIN_FILE ), array( 'jquery-payment', 'stripe' ), WC_STRIPE_VERSION, true );
292
+			wp_enqueue_script('stripe', 'https://js.stripe.com/v2/', '', '1.0', true);
293
+			wp_enqueue_script('woocommerce_stripe', plugins_url('assets/js/stripe.js', WC_STRIPE_MAIN_FILE), array('jquery-payment', 'stripe'), WC_STRIPE_VERSION, true);
294 294
 		}
295 295
 
296 296
 		$stripe_params = array(
297 297
 			'key'                  => $this->publishable_key,
298
-			'i18n_terms'           => __( 'Please accept the terms and conditions first', 'woocommerce-gateway-stripe' ),
299
-			'i18n_required_fields' => __( 'Please fill in required checkout fields first', 'woocommerce-gateway-stripe' ),
298
+			'i18n_terms'           => __('Please accept the terms and conditions first', 'woocommerce-gateway-stripe'),
299
+			'i18n_required_fields' => __('Please fill in required checkout fields first', 'woocommerce-gateway-stripe'),
300 300
 		);
301 301
 
302 302
 		// If we're on the pay page we need to pass stripe.js the address of the order.
303
-		if ( is_checkout_pay_page() && isset( $_GET['order'] ) && isset( $_GET['order_id'] ) ) {
304
-			$order_key = urldecode( $_GET['order'] );
305
-			$order_id  = absint( $_GET['order_id'] );
306
-			$order     = wc_get_order( $order_id );
303
+		if (is_checkout_pay_page() && isset($_GET['order']) && isset($_GET['order_id'])) {
304
+			$order_key = urldecode($_GET['order']);
305
+			$order_id  = absint($_GET['order_id']);
306
+			$order     = wc_get_order($order_id);
307 307
 
308
-			if ( $order->id === $order_id && $order->order_key === $order_key ) {
308
+			if ($order->id === $order_id && $order->order_key === $order_key) {
309 309
 				$stripe_params['billing_first_name'] = $order->billing_first_name;
310 310
 				$stripe_params['billing_last_name']  = $order->billing_last_name;
311 311
 				$stripe_params['billing_address_1']  = $order->billing_address_1;
@@ -317,7 +317,7 @@  discard block
 block discarded – undo
317 317
 			}
318 318
 		}
319 319
 
320
-		wp_localize_script( 'woocommerce_stripe', 'wc_stripe_params', apply_filters( 'wc_stripe_params', $stripe_params ) );
320
+		wp_localize_script('woocommerce_stripe', 'wc_stripe_params', apply_filters('wc_stripe_params', $stripe_params));
321 321
 	}
322 322
 
323 323
 	/**
@@ -326,28 +326,28 @@  discard block
 block discarded – undo
326 326
 	 * @param  object $source
327 327
 	 * @return array()
328 328
 	 */
329
-	protected function generate_payment_request( $order, $source ) {
329
+	protected function generate_payment_request($order, $source) {
330 330
 		$post_data                = array();
331
-		$post_data['currency']    = strtolower( $order->get_order_currency() ? $order->get_order_currency() : get_woocommerce_currency() );
332
-		$post_data['amount']      = $this->get_stripe_amount( $order->get_total(), $post_data['currency'] );
333
-		$post_data['description'] = sprintf( __( '%s - Order %s', 'woocommerce-gateway-stripe' ), wp_specialchars_decode( get_bloginfo( 'name' ), ENT_QUOTES ), $order->get_order_number() );
331
+		$post_data['currency']    = strtolower($order->get_order_currency() ? $order->get_order_currency() : get_woocommerce_currency());
332
+		$post_data['amount']      = $this->get_stripe_amount($order->get_total(), $post_data['currency']);
333
+		$post_data['description'] = sprintf(__('%s - Order %s', 'woocommerce-gateway-stripe'), wp_specialchars_decode(get_bloginfo('name'), ENT_QUOTES), $order->get_order_number());
334 334
 		$post_data['capture']     = $this->capture ? 'true' : 'false';
335 335
 
336
-		if ( ! empty( $order->billing_email ) && apply_filters( 'wc_stripe_send_stripe_receipt', false ) ) {
336
+		if ( ! empty($order->billing_email) && apply_filters('wc_stripe_send_stripe_receipt', false)) {
337 337
 			$post_data['receipt_email'] = $order->billing_email;
338 338
 		}
339 339
 
340
-		$post_data['expand[]']    = 'balance_transaction';
340
+		$post_data['expand[]'] = 'balance_transaction';
341 341
 
342
-		if ( $source->customer ) {
342
+		if ($source->customer) {
343 343
 			$post_data['customer'] = $source->customer;
344 344
 		}
345 345
 
346
-		if ( $source->source ) {
346
+		if ($source->source) {
347 347
 			$post_data['source'] = $source->source;
348 348
 		}
349 349
 
350
-		return apply_filters( 'wc_stripe_generate_payment_request', $post_data, $order, $source );
350
+		return apply_filters('wc_stripe_generate_payment_request', $post_data, $order, $source);
351 351
 	}
352 352
 
353 353
 	/**
@@ -355,22 +355,22 @@  discard block
 block discarded – undo
355 355
 	 * @param  bool $force_customer Should we force customer creation?
356 356
 	 * @return object
357 357
 	 */
358
-	protected function get_source( $user_id, $force_customer = false ) {
359
-		$stripe_customer = new WC_Stripe_Customer( $user_id );
358
+	protected function get_source($user_id, $force_customer = false) {
359
+		$stripe_customer = new WC_Stripe_Customer($user_id);
360 360
 		$stripe_source   = false;
361 361
 		$token_id        = false;
362 362
 
363 363
 		// New CC info was entered and we have a new token to process
364
-		if ( isset( $_POST['stripe_token'] ) ) {
365
-			$stripe_token     = wc_clean( $_POST['stripe_token'] );
366
-			$maybe_saved_card = isset( $_POST['wc-stripe-new-payment-method'] ) && ! empty( $_POST['wc-stripe-new-payment-method'] );
364
+		if (isset($_POST['stripe_token'])) {
365
+			$stripe_token     = wc_clean($_POST['stripe_token']);
366
+			$maybe_saved_card = isset($_POST['wc-stripe-new-payment-method']) && ! empty($_POST['wc-stripe-new-payment-method']);
367 367
 
368 368
 			// This is true if the user wants to store the card to their account.
369
-			if ( ( $user_id && $this->saved_cards && $maybe_saved_card ) || $force_customer ) {
370
-				$stripe_source = $stripe_customer->add_card( $stripe_token );
369
+			if (($user_id && $this->saved_cards && $maybe_saved_card) || $force_customer) {
370
+				$stripe_source = $stripe_customer->add_card($stripe_token);
371 371
 
372
-				if ( is_wp_error( $stripe_source ) ) {
373
-					throw new Exception( $stripe_source->get_error_message() );
372
+				if (is_wp_error($stripe_source)) {
373
+					throw new Exception($stripe_source->get_error_message());
374 374
 				}
375 375
 
376 376
 			} else {
@@ -381,8 +381,8 @@  discard block
 block discarded – undo
381 381
 		}
382 382
 
383 383
 		// Use an existing token, and then process the payment
384
-		elseif ( isset( $_POST['wc-stripe-payment-token'] ) && 'new' !== $_POST['wc-stripe-payment-token'] ) {
385
-			$stripe_source = wc_clean( $_POST['wc-stripe-payment-token'] );
384
+		elseif (isset($_POST['wc-stripe-payment-token']) && 'new' !== $_POST['wc-stripe-payment-token']) {
385
+			$stripe_source = wc_clean($_POST['wc-stripe-payment-token']);
386 386
 		}
387 387
 
388 388
 		return (object) array(
@@ -403,16 +403,16 @@  discard block
 block discarded – undo
403 403
 	 * @param object $order
404 404
 	 * @return object
405 405
 	 */
406
-	protected function get_order_source( $order = null ) {
406
+	protected function get_order_source($order = null) {
407 407
 		$stripe_customer = new WC_Stripe_Customer();
408 408
 		$stripe_source   = false;
409 409
 		$token_id        = false;
410 410
 
411
-		if ( $order ) {
412
-			if ( $meta_value = get_post_meta( $order->id, '_stripe_customer_id', true ) ) {
413
-				$stripe_customer->set_id( $meta_value );
411
+		if ($order) {
412
+			if ($meta_value = get_post_meta($order->id, '_stripe_customer_id', true)) {
413
+				$stripe_customer->set_id($meta_value);
414 414
 			}
415
-			if ( $meta_value = get_post_meta( $order->id, '_stripe_card_id', true ) ) {
415
+			if ($meta_value = get_post_meta($order->id, '_stripe_card_id', true)) {
416 416
 				$stripe_source = $meta_value;
417 417
 			}
418 418
 		}
@@ -427,43 +427,43 @@  discard block
 block discarded – undo
427 427
 	/**
428 428
 	 * Process the payment
429 429
 	 */
430
-	public function process_payment( $order_id, $retry = true, $force_customer = false ) {
430
+	public function process_payment($order_id, $retry = true, $force_customer = false) {
431 431
 		try {
432
-			$order  = wc_get_order( $order_id );
433
-			$source = $this->get_source( get_current_user_id(), $force_customer );
432
+			$order  = wc_get_order($order_id);
433
+			$source = $this->get_source(get_current_user_id(), $force_customer);
434 434
 
435
-			if ( empty( $source->source ) && empty( $source->customer ) ) {
436
-				$error_msg = __( 'Please enter your card details to make a payment.', 'woocommerce-gateway-stripe' );
437
-				$error_msg .= ' ' . __( 'Developers: Please make sure that you are including jQuery and there are no JavaScript errors on the page.', 'woocommerce-gateway-stripe' );
438
-				throw new Exception( $error_msg );
435
+			if (empty($source->source) && empty($source->customer)) {
436
+				$error_msg = __('Please enter your card details to make a payment.', 'woocommerce-gateway-stripe');
437
+				$error_msg .= ' ' . __('Developers: Please make sure that you are including jQuery and there are no JavaScript errors on the page.', 'woocommerce-gateway-stripe');
438
+				throw new Exception($error_msg);
439 439
 			}
440 440
 
441 441
 			// Store source to order meta
442
-			$this->save_source( $order, $source );
442
+			$this->save_source($order, $source);
443 443
 
444 444
 			// Handle payment
445
-			if ( $order->get_total() > 0 ) {
445
+			if ($order->get_total() > 0) {
446 446
 
447
-				if ( $order->get_total() * 100 < WC_Stripe::get_minimum_amount() ) {
448
-					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 ) ) );
447
+				if ($order->get_total() * 100 < WC_Stripe::get_minimum_amount()) {
448
+					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)));
449 449
 				}
450 450
 
451
-				WC_Stripe::log( "Info: Begin processing payment for order $order_id for the amount of {$order->get_total()}" );
451
+				WC_Stripe::log("Info: Begin processing payment for order $order_id for the amount of {$order->get_total()}");
452 452
 
453 453
 				// Make the request
454
-				$response = WC_Stripe_API::request( $this->generate_payment_request( $order, $source ) );
454
+				$response = WC_Stripe_API::request($this->generate_payment_request($order, $source));
455 455
 
456
-				if ( is_wp_error( $response ) ) {
456
+				if (is_wp_error($response)) {
457 457
 					// Customer param wrong? The user may have been deleted on stripe's end. Remove customer_id. Can be retried without.
458
-					if ( 'customer' === $response->get_error_code() && $retry ) {
459
-						delete_user_meta( get_current_user_id(), '_stripe_customer_id' );
460
-						return $this->process_payment( $order_id, false, $force_customer );
458
+					if ('customer' === $response->get_error_code() && $retry) {
459
+						delete_user_meta(get_current_user_id(), '_stripe_customer_id');
460
+						return $this->process_payment($order_id, false, $force_customer);
461 461
 					}
462
-					throw new Exception( $response->get_error_code() . ': ' . $response->get_error_message() );
462
+					throw new Exception($response->get_error_code() . ': ' . $response->get_error_message());
463 463
 				}
464 464
 
465 465
 				// Process valid response
466
-				$this->process_response( $response, $order );
466
+				$this->process_response($response, $order);
467 467
 			} else {
468 468
 				$order->payment_complete();
469 469
 			}
@@ -474,13 +474,13 @@  discard block
 block discarded – undo
474 474
 			// Return thank you page redirect
475 475
 			return array(
476 476
 				'result'   => 'success',
477
-				'redirect' => $this->get_return_url( $order )
477
+				'redirect' => $this->get_return_url($order)
478 478
 			);
479 479
 
480
-		} catch ( Exception $e ) {
481
-			wc_add_notice( $e->getMessage(), 'error' );
482
-			WC()->session->set( 'refresh_totals', true );
483
-			WC_Stripe::log( sprintf( __( 'Error: %s', 'woocommerce-gateway-stripe' ), $e->getMessage() ) );
480
+		} catch (Exception $e) {
481
+			wc_add_notice($e->getMessage(), 'error');
482
+			WC()->session->set('refresh_totals', true);
483
+			WC_Stripe::log(sprintf(__('Error: %s', 'woocommerce-gateway-stripe'), $e->getMessage()));
484 484
 			return;
485 485
 		}
486 486
 	}
@@ -488,45 +488,45 @@  discard block
 block discarded – undo
488 488
 	/**
489 489
 	 * Save source to order.
490 490
 	 */
491
-	protected function save_source( $order, $source ) {
491
+	protected function save_source($order, $source) {
492 492
 		// Store source in the order
493
-		if ( $source->customer ) {
494
-			update_post_meta( $order->id, '_stripe_customer_id', $source->customer );
493
+		if ($source->customer) {
494
+			update_post_meta($order->id, '_stripe_customer_id', $source->customer);
495 495
 		}
496
-		if ( $source->source ) {
497
-			update_post_meta( $order->id, '_stripe_card_id', $source->source->id );
496
+		if ($source->source) {
497
+			update_post_meta($order->id, '_stripe_card_id', $source->source->id);
498 498
 		}
499 499
 	}
500 500
 
501 501
 	/**
502 502
 	 * Store extra meta data for an order from a Stripe Response.
503 503
 	 */
504
-	public function process_response( $response, $order ) {
505
-		WC_Stripe::log( "Processing response: " . print_r( $response, true ) );
504
+	public function process_response($response, $order) {
505
+		WC_Stripe::log("Processing response: " . print_r($response, true));
506 506
 
507 507
 		// Store charge data
508
-		update_post_meta( $order->id, '_stripe_charge_id', $response->id );
509
-		update_post_meta( $order->id, '_stripe_charge_captured', $response->captured ? 'yes' : 'no' );
508
+		update_post_meta($order->id, '_stripe_charge_id', $response->id);
509
+		update_post_meta($order->id, '_stripe_charge_captured', $response->captured ? 'yes' : 'no');
510 510
 
511 511
 		// Store other data such as fees
512
-		if ( isset( $response->balance_transaction ) && isset( $response->balance_transaction->fee ) ) {
513
-			$fee = number_format( $response->balance_transaction->fee / 100, 2, '.', '' );
514
-			update_post_meta( $order->id, 'Stripe Fee', $fee );
515
-			update_post_meta( $order->id, 'Net Revenue From Stripe', $order->get_total() - $fee );
512
+		if (isset($response->balance_transaction) && isset($response->balance_transaction->fee)) {
513
+			$fee = number_format($response->balance_transaction->fee / 100, 2, '.', '');
514
+			update_post_meta($order->id, 'Stripe Fee', $fee);
515
+			update_post_meta($order->id, 'Net Revenue From Stripe', $order->get_total() - $fee);
516 516
 		}
517 517
 
518
-		if ( $response->captured ) {
519
-			$order->payment_complete( $response->id );
520
-			WC_Stripe::log( "Successful charge: $response->id" );
518
+		if ($response->captured) {
519
+			$order->payment_complete($response->id);
520
+			WC_Stripe::log("Successful charge: $response->id");
521 521
 		} else {
522
-			add_post_meta( $order->id, '_transaction_id', $response->id, true );
522
+			add_post_meta($order->id, '_transaction_id', $response->id, true);
523 523
 
524
-			if ( $order->has_status( array( 'pending', 'failed' ) ) ) {
524
+			if ($order->has_status(array('pending', 'failed'))) {
525 525
 				$order->reduce_order_stock();
526 526
 			}
527 527
 
528
-			$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 ) );
529
-			WC_Stripe::log( "Successful auth: $response->id" );
528
+			$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));
529
+			WC_Stripe::log("Successful auth: $response->id");
530 530
 		}
531 531
 
532 532
 		return $response;
@@ -538,21 +538,21 @@  discard block
 block discarded – undo
538 538
 	 * @since 3.0.0
539 539
 	 */
540 540
 	public function add_payment_method() {
541
-		if ( empty( $_POST['stripe_token'] ) || ! is_user_logged_in() ) {
542
-			wc_add_notice( __( 'There was a problem adding the card.', 'woocommerce-gateway-stripe' ), 'error' );
541
+		if (empty($_POST['stripe_token']) || ! is_user_logged_in()) {
542
+			wc_add_notice(__('There was a problem adding the card.', 'woocommerce-gateway-stripe'), 'error');
543 543
 			return;
544 544
 		}
545 545
 
546
-		$stripe_customer = new WC_Stripe_Customer( get_current_user_id() );
547
-		$result          = $stripe_customer->add_card( wc_clean( $_POST['stripe_token'] ) );
546
+		$stripe_customer = new WC_Stripe_Customer(get_current_user_id());
547
+		$result          = $stripe_customer->add_card(wc_clean($_POST['stripe_token']));
548 548
 
549
-		if ( is_wp_error( $result ) ) {
550
-			throw new Exception( $result->get_error_message() );
549
+		if (is_wp_error($result)) {
550
+			throw new Exception($result->get_error_message());
551 551
 		}
552 552
 
553 553
 		return array(
554 554
 			'result'   => 'success',
555
-			'redirect' => wc_get_endpoint_url( 'payment-methods' ),
555
+			'redirect' => wc_get_endpoint_url('payment-methods'),
556 556
 		);
557 557
 	}
558 558
 
@@ -562,36 +562,36 @@  discard block
 block discarded – undo
562 562
 	 * @param  float $amount
563 563
 	 * @return bool
564 564
 	 */
565
-	public function process_refund( $order_id, $amount = null, $reason = '' ) {
566
-		$order = wc_get_order( $order_id );
565
+	public function process_refund($order_id, $amount = null, $reason = '') {
566
+		$order = wc_get_order($order_id);
567 567
 
568
-		if ( ! $order || ! $order->get_transaction_id() ) {
568
+		if ( ! $order || ! $order->get_transaction_id()) {
569 569
 			return false;
570 570
 		}
571 571
 
572 572
 		$body = array();
573 573
 
574
-		if ( ! is_null( $amount ) ) {
575
-			$body['amount']	= $this->get_stripe_amount( $amount );
574
+		if ( ! is_null($amount)) {
575
+			$body['amount'] = $this->get_stripe_amount($amount);
576 576
 		}
577 577
 
578
-		if ( $reason ) {
578
+		if ($reason) {
579 579
 			$body['metadata'] = array(
580 580
 				'reason'	=> $reason,
581 581
 			);
582 582
 		}
583 583
 
584
-		WC_Stripe::log( "Info: Beginning refund for order $order_id for the amount of {$amount}" );
584
+		WC_Stripe::log("Info: Beginning refund for order $order_id for the amount of {$amount}");
585 585
 
586
-		$response = WC_Stripe_API::request( $body, 'charges/' . $order->get_transaction_id() . '/refunds' );
586
+		$response = WC_Stripe_API::request($body, 'charges/' . $order->get_transaction_id() . '/refunds');
587 587
 
588
-		if ( is_wp_error( $response ) ) {
589
-			WC_Stripe::log( "Error: " . $response->get_error_message() );
588
+		if (is_wp_error($response)) {
589
+			WC_Stripe::log("Error: " . $response->get_error_message());
590 590
 			return $response;
591
-		} elseif ( ! empty( $response->id ) ) {
592
-			$refund_message = sprintf( __( 'Refunded %s - Refund ID: %s - Reason: %s', 'woocommerce-gateway-stripe' ), wc_price( $response->amount / 100 ), $response->id, $reason );
593
-			$order->add_order_note( $refund_message );
594
-			WC_Stripe::log( "Success: " . html_entity_decode( strip_tags( $refund_message ) ) );
591
+		} elseif ( ! empty($response->id)) {
592
+			$refund_message = sprintf(__('Refunded %s - Refund ID: %s - Reason: %s', 'woocommerce-gateway-stripe'), wc_price($response->amount / 100), $response->id, $reason);
593
+			$order->add_order_note($refund_message);
594
+			WC_Stripe::log("Success: " . html_entity_decode(strip_tags($refund_message)));
595 595
 			return true;
596 596
 		}
597 597
 	}
Please login to merge, or discard this patch.
includes/class-wc-gateway-stripe.php 1 patch
Spacing   +284 added lines, -284 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) {
2
+if ( ! defined('ABSPATH')) {
3 3
 	exit;
4 4
 }
5 5
 
@@ -120,8 +120,8 @@  discard block
 block discarded – undo
120 120
 	 */
121 121
 	public function __construct() {
122 122
 		$this->id                   = 'stripe';
123
-		$this->method_title         = __( 'Stripe', 'woocommerce-gateway-stripe' );
124
-		$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' );
123
+		$this->method_title         = __('Stripe', 'woocommerce-gateway-stripe');
124
+		$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');
125 125
 		$this->has_fields           = true;
126 126
 		$this->view_transaction_url = 'https://dashboard.stripe.com/payments/%s';
127 127
 		$this->supports             = array(
@@ -149,43 +149,43 @@  discard block
 block discarded – undo
149 149
 		$this->init_settings();
150 150
 
151 151
 		// Get setting values.
152
-		$this->title                   = $this->get_option( 'title' );
153
-		$this->description             = $this->get_option( 'description' );
154
-		$this->enabled                 = $this->get_option( 'enabled' );
155
-		$this->testmode                = 'yes' === $this->get_option( 'testmode' );
156
-		$this->capture                 = 'yes' === $this->get_option( 'capture', 'yes' );
157
-		$this->statement_descriptor    = $this->get_option( 'statement_descriptor', wp_specialchars_decode( get_bloginfo( 'name' ), ENT_QUOTES ) );
158
-		$this->stripe_checkout         = 'yes' === $this->get_option( 'stripe_checkout' );
159
-		$this->stripe_checkout_locale  = $this->get_option( 'stripe_checkout_locale' );
160
-		$this->stripe_checkout_image   = $this->get_option( 'stripe_checkout_image', '' );
161
-		$this->saved_cards             = 'yes' === $this->get_option( 'saved_cards' );
162
-		$this->secret_key              = $this->testmode ? $this->get_option( 'test_secret_key' ) : $this->get_option( 'secret_key' );
163
-		$this->publishable_key         = $this->testmode ? $this->get_option( 'test_publishable_key' ) : $this->get_option( 'publishable_key' );
164
-		$this->bitcoin                 = 'USD' === strtoupper( get_woocommerce_currency() ) && 'yes' === $this->get_option( 'stripe_bitcoin' );
165
-		$this->apple_pay               = 'yes' === $this->get_option( 'apple_pay', 'yes' );
166
-		$this->apple_pay_domain_set    = 'yes' === $this->get_option( 'apple_pay_domain_set', 'no' );
167
-		$this->apple_pay_button        = $this->get_option( 'apple_pay_button', 'black' );
168
-		$this->logging                 = 'yes' === $this->get_option( 'logging' );
152
+		$this->title                   = $this->get_option('title');
153
+		$this->description             = $this->get_option('description');
154
+		$this->enabled                 = $this->get_option('enabled');
155
+		$this->testmode                = 'yes' === $this->get_option('testmode');
156
+		$this->capture                 = 'yes' === $this->get_option('capture', 'yes');
157
+		$this->statement_descriptor    = $this->get_option('statement_descriptor', wp_specialchars_decode(get_bloginfo('name'), ENT_QUOTES));
158
+		$this->stripe_checkout         = 'yes' === $this->get_option('stripe_checkout');
159
+		$this->stripe_checkout_locale  = $this->get_option('stripe_checkout_locale');
160
+		$this->stripe_checkout_image   = $this->get_option('stripe_checkout_image', '');
161
+		$this->saved_cards             = 'yes' === $this->get_option('saved_cards');
162
+		$this->secret_key              = $this->testmode ? $this->get_option('test_secret_key') : $this->get_option('secret_key');
163
+		$this->publishable_key         = $this->testmode ? $this->get_option('test_publishable_key') : $this->get_option('publishable_key');
164
+		$this->bitcoin                 = 'USD' === strtoupper(get_woocommerce_currency()) && 'yes' === $this->get_option('stripe_bitcoin');
165
+		$this->apple_pay               = 'yes' === $this->get_option('apple_pay', 'yes');
166
+		$this->apple_pay_domain_set    = 'yes' === $this->get_option('apple_pay_domain_set', 'no');
167
+		$this->apple_pay_button        = $this->get_option('apple_pay_button', 'black');
168
+		$this->logging                 = 'yes' === $this->get_option('logging');
169 169
 		$this->apple_pay_verify_notice = '';
170 170
 
171
-		if ( $this->stripe_checkout ) {
172
-			$this->order_button_text = __( 'Continue to payment', 'woocommerce-gateway-stripe' );
171
+		if ($this->stripe_checkout) {
172
+			$this->order_button_text = __('Continue to payment', 'woocommerce-gateway-stripe');
173 173
 		}
174 174
 
175
-		if ( $this->testmode ) {
176
-			$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' );
177
-			$this->description  = trim( $this->description );
175
+		if ($this->testmode) {
176
+			$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');
177
+			$this->description  = trim($this->description);
178 178
 		}
179 179
 
180
-		WC_Stripe_API::set_secret_key( $this->secret_key );
180
+		WC_Stripe_API::set_secret_key($this->secret_key);
181 181
 
182 182
 		$this->init_apple_pay();
183 183
 
184 184
 		// Hooks.
185
-		add_action( 'wp_enqueue_scripts', array( $this, 'payment_scripts' ) );
186
-		add_action( 'admin_enqueue_scripts', array( $this, 'admin_scripts' ) );
187
-		add_action( 'admin_notices', array( $this, 'admin_notices' ) );
188
-		add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) );
185
+		add_action('wp_enqueue_scripts', array($this, 'payment_scripts'));
186
+		add_action('admin_enqueue_scripts', array($this, 'admin_scripts'));
187
+		add_action('admin_notices', array($this, 'admin_notices'));
188
+		add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options'));
189 189
 	}
190 190
 
191 191
 	/**
@@ -195,26 +195,26 @@  discard block
 block discarded – undo
195 195
 	 * @return string
196 196
 	 */
197 197
 	public function get_icon() {
198
-		$ext   = version_compare( WC()->version, '2.6', '>=' ) ? '.svg' : '.png';
199
-		$style = version_compare( WC()->version, '2.6', '>=' ) ? 'style="margin-left: 0.3em"' : '';
198
+		$ext   = version_compare(WC()->version, '2.6', '>=') ? '.svg' : '.png';
199
+		$style = version_compare(WC()->version, '2.6', '>=') ? 'style="margin-left: 0.3em"' : '';
200 200
 
201
-		$icon  = '<img src="' . WC_HTTPS::force_https_url( WC()->plugin_url() . '/assets/images/icons/credit-cards/visa' . $ext ) . '" alt="Visa" width="32" ' . $style . ' />';
202
-		$icon .= '<img src="' . WC_HTTPS::force_https_url( WC()->plugin_url() . '/assets/images/icons/credit-cards/mastercard' . $ext ) . '" alt="Mastercard" width="32" ' . $style . ' />';
203
-		$icon .= '<img src="' . WC_HTTPS::force_https_url( WC()->plugin_url() . '/assets/images/icons/credit-cards/amex' . $ext ) . '" alt="Amex" width="32" ' . $style . ' />';
201
+		$icon  = '<img src="' . WC_HTTPS::force_https_url(WC()->plugin_url() . '/assets/images/icons/credit-cards/visa' . $ext) . '" alt="Visa" width="32" ' . $style . ' />';
202
+		$icon .= '<img src="' . WC_HTTPS::force_https_url(WC()->plugin_url() . '/assets/images/icons/credit-cards/mastercard' . $ext) . '" alt="Mastercard" width="32" ' . $style . ' />';
203
+		$icon .= '<img src="' . WC_HTTPS::force_https_url(WC()->plugin_url() . '/assets/images/icons/credit-cards/amex' . $ext) . '" alt="Amex" width="32" ' . $style . ' />';
204 204
 
205 205
 		$base_location = wc_get_base_location();
206 206
 
207
-		if ( 'US' === $base_location['country'] ) {
208
-			$icon .= '<img src="' . WC_HTTPS::force_https_url( WC()->plugin_url() . '/assets/images/icons/credit-cards/discover' . $ext ) . '" alt="Discover" width="32" ' . $style . ' />';
209
-			$icon .= '<img src="' . WC_HTTPS::force_https_url( WC()->plugin_url() . '/assets/images/icons/credit-cards/jcb' . $ext ) . '" alt="JCB" width="32" ' . $style . ' />';
210
-			$icon .= '<img src="' . WC_HTTPS::force_https_url( WC()->plugin_url() . '/assets/images/icons/credit-cards/diners' . $ext ) . '" alt="Diners" width="32" ' . $style . ' />';
207
+		if ('US' === $base_location['country']) {
208
+			$icon .= '<img src="' . WC_HTTPS::force_https_url(WC()->plugin_url() . '/assets/images/icons/credit-cards/discover' . $ext) . '" alt="Discover" width="32" ' . $style . ' />';
209
+			$icon .= '<img src="' . WC_HTTPS::force_https_url(WC()->plugin_url() . '/assets/images/icons/credit-cards/jcb' . $ext) . '" alt="JCB" width="32" ' . $style . ' />';
210
+			$icon .= '<img src="' . WC_HTTPS::force_https_url(WC()->plugin_url() . '/assets/images/icons/credit-cards/diners' . $ext) . '" alt="Diners" width="32" ' . $style . ' />';
211 211
 		}
212 212
 
213
-		if ( $this->bitcoin && $this->stripe_checkout ) {
214
-			$icon .= '<img src="' . WC_HTTPS::force_https_url( plugins_url( '/assets/images/bitcoin' . $ext, WC_STRIPE_MAIN_FILE ) ) . '" alt="Bitcoin" width="24" ' . $style . ' />';
213
+		if ($this->bitcoin && $this->stripe_checkout) {
214
+			$icon .= '<img src="' . WC_HTTPS::force_https_url(plugins_url('/assets/images/bitcoin' . $ext, WC_STRIPE_MAIN_FILE)) . '" alt="Bitcoin" width="24" ' . $style . ' />';
215 215
 		}
216 216
 
217
-		return apply_filters( 'woocommerce_gateway_icon', $icon, $this->id );
217
+		return apply_filters('woocommerce_gateway_icon', $icon, $this->id);
218 218
 	}
219 219
 
220 220
 	/**
@@ -225,11 +225,11 @@  discard block
 block discarded – undo
225 225
 	 *
226 226
 	 * @return float|int
227 227
 	 */
228
-	public function get_stripe_amount( $total, $currency = '' ) {
229
-		if ( ! $currency ) {
228
+	public function get_stripe_amount($total, $currency = '') {
229
+		if ( ! $currency) {
230 230
 			$currency = get_woocommerce_currency();
231 231
 		}
232
-		switch ( strtoupper( $currency ) ) {
232
+		switch (strtoupper($currency)) {
233 233
 			// Zero decimal currencies.
234 234
 			case 'BIF' :
235 235
 			case 'CLP' :
@@ -246,10 +246,10 @@  discard block
 block discarded – undo
246 246
 			case 'XAF' :
247 247
 			case 'XOF' :
248 248
 			case 'XPF' :
249
-				$total = absint( $total );
249
+				$total = absint($total);
250 250
 				break;
251 251
 			default :
252
-				$total = round( $total, 2 ) * 100; // In cents.
252
+				$total = round($total, 2) * 100; // In cents.
253 253
 				break;
254 254
 		}
255 255
 		return $total;
@@ -264,9 +264,9 @@  discard block
 block discarded – undo
264 264
 	public function init_apple_pay() {
265 265
 		if ( 
266 266
 			is_admin() && 
267
-			isset( $_GET['page'] ) && 'wc-settings' === $_GET['page'] && 
268
-			isset( $_GET['tab'] ) && 'checkout' === $_GET['tab'] &&
269
-			isset( $_GET['section'] ) && 'stripe' === $_GET['section']
267
+			isset($_GET['page']) && 'wc-settings' === $_GET['page'] && 
268
+			isset($_GET['tab']) && 'checkout' === $_GET['tab'] &&
269
+			isset($_GET['section']) && 'stripe' === $_GET['section']
270 270
 		) {
271 271
 			$this->process_apple_pay_verification();
272 272
 		}
@@ -279,9 +279,9 @@  discard block
 block discarded – undo
279 279
 	 * @version 3.1.0
280 280
 	 * @param string $secret_key
281 281
 	 */
282
-	private function register_apple_pay_domain( $secret_key = '' ) {
283
-		if ( empty( $secret_key ) ) {
284
-			throw new Exception( __( 'Unable to verify domain - missing secret key.', 'woocommerce-gateway-stripe' ) );
282
+	private function register_apple_pay_domain($secret_key = '') {
283
+		if (empty($secret_key)) {
284
+			throw new Exception(__('Unable to verify domain - missing secret key.', 'woocommerce-gateway-stripe'));
285 285
 		}
286 286
 
287 287
 		$endpoint = 'https://api.stripe.com/v1/apple_pay/domains';
@@ -295,21 +295,21 @@  discard block
 block discarded – undo
295 295
 			'Authorization' => 'Bearer ' . $secret_key,
296 296
 		);
297 297
 
298
-		$response = wp_remote_post( $endpoint, array(
298
+		$response = wp_remote_post($endpoint, array(
299 299
 			'headers' => $headers,
300
-			'body'    => http_build_query( $data ),
301
-		) );
300
+			'body'    => http_build_query($data),
301
+		));
302 302
 
303
-		if ( is_wp_error( $response ) ) {
304
-			throw new Exception( sprintf( __( 'Unable to verify domain - %s', 'woocommerce-gateway-stripe' ), $response->get_error_message() ) ); 
303
+		if (is_wp_error($response)) {
304
+			throw new Exception(sprintf(__('Unable to verify domain - %s', 'woocommerce-gateway-stripe'), $response->get_error_message())); 
305 305
 		}
306 306
 
307
-		if ( 200 !== $response['response']['code'] ) {
308
-			$parsed_response = json_decode( $response['body'] );
307
+		if (200 !== $response['response']['code']) {
308
+			$parsed_response = json_decode($response['body']);
309 309
 
310 310
 			$this->apple_pay_verify_notice = $parsed_response->error->message;
311 311
 
312
-			throw new Exception( sprintf( __( 'Unable to verify domain - %s', 'woocommerce-gateway-stripe' ), $parsed_response->error->message ) );
312
+			throw new Exception(sprintf(__('Unable to verify domain - %s', 'woocommerce-gateway-stripe'), $parsed_response->error->message));
313 313
 		}
314 314
 	}
315 315
 
@@ -320,48 +320,48 @@  discard block
 block discarded – undo
320 320
 	 * @version 3.1.0
321 321
 	 */
322 322
 	public function process_apple_pay_verification() {
323
-		$gateway_settings = get_option( 'woocommerce_stripe_settings', '' );
323
+		$gateway_settings = get_option('woocommerce_stripe_settings', '');
324 324
 
325 325
 		try {
326
-			$path     = untrailingslashit( preg_replace( "!${_SERVER['SCRIPT_NAME']}$!", '', $_SERVER['SCRIPT_FILENAME'] ) );
326
+			$path     = untrailingslashit(preg_replace("!${_SERVER['SCRIPT_NAME']}$!", '', $_SERVER['SCRIPT_FILENAME']));
327 327
 			$dir      = '.well-known';
328 328
 			$file     = 'apple-developer-merchantid-domain-association';
329 329
 			$fullpath = $path . '/' . $dir . '/' . $file;
330 330
 
331
-			if ( ! empty( $gateway_settings['apple_pay_domain_set'] ) && 'yes' === $gateway_settings['apple_pay_domain_set'] && file_exists( $fullpath ) ) {
331
+			if ( ! empty($gateway_settings['apple_pay_domain_set']) && 'yes' === $gateway_settings['apple_pay_domain_set'] && file_exists($fullpath)) {
332 332
 				return;
333 333
 			}
334 334
 
335
-			if ( ! file_exists( $path . '/' . $dir ) ) {
336
-				if ( ! @mkdir( $path . '/' . $dir, 0755 ) ) {
337
-					throw new Exception( __( 'Unable to create domain association folder to domain root.', 'woocommerce-gateway-stripe' ) );
335
+			if ( ! file_exists($path . '/' . $dir)) {
336
+				if ( ! @mkdir($path . '/' . $dir, 0755)) {
337
+					throw new Exception(__('Unable to create domain association folder to domain root.', 'woocommerce-gateway-stripe'));
338 338
 				}
339 339
 			}
340 340
 
341
-			if ( ! file_exists( $fullpath ) ) {
342
-				if ( ! @copy( WC_STRIPE_PLUGIN_PATH . '/' . $file, $fullpath ) ) {
343
-					throw new Exception( __( 'Unable to copy domain association file to domain root.', 'woocommerce-gateway-stripe' ) );
341
+			if ( ! file_exists($fullpath)) {
342
+				if ( ! @copy(WC_STRIPE_PLUGIN_PATH . '/' . $file, $fullpath)) {
343
+					throw new Exception(__('Unable to copy domain association file to domain root.', 'woocommerce-gateway-stripe'));
344 344
 				}
345 345
 			}
346 346
 
347 347
 			// At this point then the domain association folder and file should be available.
348 348
 			// Proceed to verify/and or verify again.
349
-			$this->register_apple_pay_domain( $this->secret_key );
349
+			$this->register_apple_pay_domain($this->secret_key);
350 350
 
351 351
 			// No errors to this point, verification success!
352 352
 			$gateway_settings['apple_pay_domain_set'] = 'yes';
353 353
 			$this->apple_pay_domain_set = true;
354 354
 
355
-			update_option( 'woocommerce_stripe_settings', $gateway_settings );
355
+			update_option('woocommerce_stripe_settings', $gateway_settings);
356 356
 
357
-			$this->log( __( 'Your domain has been verified with Apple Pay!', 'woocommerce-gateway-stripe' ) );
357
+			$this->log(__('Your domain has been verified with Apple Pay!', 'woocommerce-gateway-stripe'));
358 358
 
359
-		} catch ( Exception $e ) {
359
+		} catch (Exception $e) {
360 360
 			$gateway_settings['apple_pay_domain_set'] = 'no';
361 361
 
362
-			update_option( 'woocommerce_stripe_settings', $gateway_settings );
362
+			update_option('woocommerce_stripe_settings', $gateway_settings);
363 363
 
364
-			$this->log( sprintf( __( 'Error: %s', 'woocommerce-gateway-stripe' ), $e->getMessage() ) );
364
+			$this->log(sprintf(__('Error: %s', 'woocommerce-gateway-stripe'), $e->getMessage()));
365 365
 		}
366 366
 	}
367 367
 
@@ -369,11 +369,11 @@  discard block
 block discarded – undo
369 369
 	 * Check if SSL is enabled and notify the user
370 370
 	 */
371 371
 	public function admin_notices() {
372
-		if ( 'no' === $this->enabled ) {
372
+		if ('no' === $this->enabled) {
373 373
 			return;
374 374
 		}
375 375
 
376
-		if ( $this->apple_pay && ! empty( $this->apple_pay_verify_notice ) ) {
376
+		if ($this->apple_pay && ! empty($this->apple_pay_verify_notice)) {
377 377
 			$allowed_html = array(
378 378
 				'a' => array(
379 379
 					'href' => array(),
@@ -381,7 +381,7 @@  discard block
 block discarded – undo
381 381
 				),
382 382
 			);
383 383
 
384
-			echo '<div class="error stripe-apple-pay-message"><p>' . wp_kses( make_clickable( $this->apple_pay_verify_notice ), $allowed_html ) . '</p></div>';
384
+			echo '<div class="error stripe-apple-pay-message"><p>' . wp_kses(make_clickable($this->apple_pay_verify_notice), $allowed_html) . '</p></div>';
385 385
 		}
386 386
 
387 387
 		/**
@@ -389,13 +389,13 @@  discard block
 block discarded – undo
389 389
 		 * when setting screen is displayed. So if domain verification is not set,
390 390
 		 * something went wrong so lets notify user.
391 391
 		 */
392
-		if ( ! empty( $this->secret_key ) && $this->apple_pay && ! $this->apple_pay_domain_set ) {
393
-			echo '<div class="error stripe-apple-pay-message"><p>' . sprintf( __( 'Apple Pay domain verification failed. Please check the %1$slog%2$s to see the issue. (Logging must be enabled to see recorded logs)', 'woocommerce-gateway-stripe' ), '<a href="' . admin_url( 'admin.php?page=wc-status&tab=logs' ) . '">', '</a>' ) . '</p></div>';
392
+		if ( ! empty($this->secret_key) && $this->apple_pay && ! $this->apple_pay_domain_set) {
393
+			echo '<div class="error stripe-apple-pay-message"><p>' . sprintf(__('Apple Pay domain verification failed. Please check the %1$slog%2$s to see the issue. (Logging must be enabled to see recorded logs)', 'woocommerce-gateway-stripe'), '<a href="' . admin_url('admin.php?page=wc-status&tab=logs') . '">', '</a>') . '</p></div>';
394 394
 		}
395 395
 
396 396
 		// Show message if enabled and FORCE SSL is disabled and WordpressHTTPS plugin is not detected.
397
-		if ( ( function_exists( 'wc_site_is_https' ) && ! wc_site_is_https() ) && ( 'no' === get_option( 'woocommerce_force_ssl_checkout' ) && ! class_exists( 'WordPressHTTPS' ) ) ) {
398
-			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>';
397
+		if ((function_exists('wc_site_is_https') && ! wc_site_is_https()) && ('no' === get_option('woocommerce_force_ssl_checkout') && ! class_exists('WordPressHTTPS'))) {
398
+			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>';
399 399
 		}
400 400
 	}
401 401
 
@@ -403,11 +403,11 @@  discard block
 block discarded – undo
403 403
 	 * Check if this gateway is enabled
404 404
 	 */
405 405
 	public function is_available() {
406
-		if ( 'yes' === $this->enabled ) {
407
-			if ( ! $this->testmode && is_checkout() && ! is_ssl() ) {
406
+		if ('yes' === $this->enabled) {
407
+			if ( ! $this->testmode && is_checkout() && ! is_ssl()) {
408 408
 				return false;
409 409
 			}
410
-			if ( ! $this->secret_key || ! $this->publishable_key ) {
410
+			if ( ! $this->secret_key || ! $this->publishable_key) {
411 411
 				return false;
412 412
 			}
413 413
 			return true;
@@ -419,7 +419,7 @@  discard block
 block discarded – undo
419 419
 	 * Initialise Gateway Settings Form Fields
420 420
 	 */
421 421
 	public function init_form_fields() {
422
-		$this->form_fields = include( 'settings-stripe.php' );
422
+		$this->form_fields = include('settings-stripe.php');
423 423
 	}
424 424
 
425 425
 	/**
@@ -427,54 +427,54 @@  discard block
 block discarded – undo
427 427
 	 */
428 428
 	public function payment_fields() {
429 429
 		$user                 = wp_get_current_user();
430
-		$display_tokenization = $this->supports( 'tokenization' ) && is_checkout() && $this->saved_cards;
430
+		$display_tokenization = $this->supports('tokenization') && is_checkout() && $this->saved_cards;
431 431
 		$total                = WC()->cart->total;
432 432
 
433 433
 		// If paying from order, we need to get total from order not cart.
434
-		if ( isset( $_GET['pay_for_order'] ) && ! empty( $_GET['key'] ) ) {
435
-			$order = wc_get_order( wc_get_order_id_by_order_key( wc_clean( $_GET['key'] ) ) );
434
+		if (isset($_GET['pay_for_order']) && ! empty($_GET['key'])) {
435
+			$order = wc_get_order(wc_get_order_id_by_order_key(wc_clean($_GET['key'])));
436 436
 			$total = $order->get_total();
437 437
 		}
438 438
 
439
-		if ( $user->ID ) {
440
-			$user_email = get_user_meta( $user->ID, 'billing_email', true );
439
+		if ($user->ID) {
440
+			$user_email = get_user_meta($user->ID, 'billing_email', true);
441 441
 			$user_email = $user_email ? $user_email : $user->user_email;
442 442
 		} else {
443 443
 			$user_email = '';
444 444
 		}
445 445
 
446
-		if ( is_add_payment_method_page() ) {
447
-			$pay_button_text = __( 'Add Card', 'woocommerce-gateway-stripe' );
446
+		if (is_add_payment_method_page()) {
447
+			$pay_button_text = __('Add Card', 'woocommerce-gateway-stripe');
448 448
 		} else {
449 449
 			$pay_button_text = '';
450 450
 		}
451 451
 
452 452
 		echo '<div
453 453
 			id="stripe-payment-data"
454
-			data-panel-label="' . esc_attr( $pay_button_text ) . '"
454
+			data-panel-label="' . esc_attr($pay_button_text) . '"
455 455
 			data-description=""
456
-			data-email="' . esc_attr( $user_email ) . '"
457
-			data-amount="' . esc_attr( $this->get_stripe_amount( $total ) ) . '"
458
-			data-name="' . esc_attr( $this->statement_descriptor ) . '"
459
-			data-currency="' . esc_attr( strtolower( get_woocommerce_currency() ) ) . '"
460
-			data-image="' . esc_attr( $this->stripe_checkout_image ) . '"
461
-			data-bitcoin="' . esc_attr( $this->bitcoin ? 'true' : 'false' ) . '"
462
-			data-locale="' . esc_attr( $this->stripe_checkout_locale ? $this->stripe_checkout_locale : 'en' ) . '"
463
-			data-allow-remember-me="' . esc_attr( $this->saved_cards ? 'true' : 'false' ) . '">';
456
+			data-email="' . esc_attr($user_email) . '"
457
+			data-amount="' . esc_attr($this->get_stripe_amount($total)) . '"
458
+			data-name="' . esc_attr($this->statement_descriptor) . '"
459
+			data-currency="' . esc_attr(strtolower(get_woocommerce_currency())) . '"
460
+			data-image="' . esc_attr($this->stripe_checkout_image) . '"
461
+			data-bitcoin="' . esc_attr($this->bitcoin ? 'true' : 'false') . '"
462
+			data-locale="' . esc_attr($this->stripe_checkout_locale ? $this->stripe_checkout_locale : 'en') . '"
463
+			data-allow-remember-me="' . esc_attr($this->saved_cards ? 'true' : 'false') . '">';
464 464
 
465
-		if ( $this->description ) {
466
-			echo apply_filters( 'wc_stripe_description', wpautop( wp_kses_post( $this->description ) ) );
465
+		if ($this->description) {
466
+			echo apply_filters('wc_stripe_description', wpautop(wp_kses_post($this->description)));
467 467
 		}
468 468
 
469
-		if ( $display_tokenization ) {
469
+		if ($display_tokenization) {
470 470
 			$this->tokenization_script();
471 471
 			$this->saved_payment_methods();
472 472
 		}
473 473
 
474
-		if ( ! $this->stripe_checkout ) {
474
+		if ( ! $this->stripe_checkout) {
475 475
 			$this->form();
476 476
 
477
-			if ( $display_tokenization ) {
477
+			if ($display_tokenization) {
478 478
 				$this->save_payment_method_checkbox();
479 479
 			}
480 480
 		}
@@ -490,20 +490,20 @@  discard block
 block discarded – undo
490 490
 	 * @return array
491 491
 	 */
492 492
 	public function get_localized_messages() {
493
-		return apply_filters( 'wc_stripe_localized_messages', array(
494
-			'invalid_number'        => __( 'The card number is not a valid credit card number.', 'woocommerce-gateway-stripe' ),
495
-			'invalid_expiry_month'  => __( 'The card\'s expiration month is invalid.', 'woocommerce-gateway-stripe' ),
496
-			'invalid_expiry_year'   => __( 'The card\'s expiration year is invalid.', 'woocommerce-gateway-stripe' ),
497
-			'invalid_cvc'           => __( 'The card\'s security code is invalid.', 'woocommerce-gateway-stripe' ),
498
-			'incorrect_number'      => __( 'The card number is incorrect.', 'woocommerce-gateway-stripe' ),
499
-			'expired_card'          => __( 'The card has expired.', 'woocommerce-gateway-stripe' ),
500
-			'incorrect_cvc'         => __( 'The card\'s security code is incorrect.', 'woocommerce-gateway-stripe' ),
501
-			'incorrect_zip'         => __( 'The card\'s zip code failed validation.', 'woocommerce-gateway-stripe' ),
502
-			'card_declined'         => __( 'The card was declined.', 'woocommerce-gateway-stripe' ),
503
-			'missing'               => __( 'There is no card on a customer that is being charged.', 'woocommerce-gateway-stripe' ),
504
-			'processing_error'      => __( 'An error occurred while processing the card.', 'woocommerce-gateway-stripe' ),
505
-			'invalid_request_error' => __( 'Could not find payment information.', 'woocommerce-gateway-stripe' ),
506
-		) );
493
+		return apply_filters('wc_stripe_localized_messages', array(
494
+			'invalid_number'        => __('The card number is not a valid credit card number.', 'woocommerce-gateway-stripe'),
495
+			'invalid_expiry_month'  => __('The card\'s expiration month is invalid.', 'woocommerce-gateway-stripe'),
496
+			'invalid_expiry_year'   => __('The card\'s expiration year is invalid.', 'woocommerce-gateway-stripe'),
497
+			'invalid_cvc'           => __('The card\'s security code is invalid.', 'woocommerce-gateway-stripe'),
498
+			'incorrect_number'      => __('The card number is incorrect.', 'woocommerce-gateway-stripe'),
499
+			'expired_card'          => __('The card has expired.', 'woocommerce-gateway-stripe'),
500
+			'incorrect_cvc'         => __('The card\'s security code is incorrect.', 'woocommerce-gateway-stripe'),
501
+			'incorrect_zip'         => __('The card\'s zip code failed validation.', 'woocommerce-gateway-stripe'),
502
+			'card_declined'         => __('The card was declined.', 'woocommerce-gateway-stripe'),
503
+			'missing'               => __('There is no card on a customer that is being charged.', 'woocommerce-gateway-stripe'),
504
+			'processing_error'      => __('An error occurred while processing the card.', 'woocommerce-gateway-stripe'),
505
+			'invalid_request_error' => __('Could not find payment information.', 'woocommerce-gateway-stripe'),
506
+		));
507 507
 	}
508 508
 
509 509
 	/**
@@ -513,28 +513,28 @@  discard block
 block discarded – undo
513 513
 	 * @version 3.1.0
514 514
 	 */
515 515
 	public function admin_scripts() {
516
-		if ( 'woocommerce_page_wc-settings' !== get_current_screen()->id ) {
516
+		if ('woocommerce_page_wc-settings' !== get_current_screen()->id) {
517 517
 			return;
518 518
 		}
519 519
 
520
-		$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
520
+		$suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';
521 521
 
522
-		wp_enqueue_script( 'woocommerce_stripe_admin', plugins_url( 'assets/js/stripe-admin' . $suffix . '.js', WC_STRIPE_MAIN_FILE ), array(), WC_STRIPE_VERSION, true );
522
+		wp_enqueue_script('woocommerce_stripe_admin', plugins_url('assets/js/stripe-admin' . $suffix . '.js', WC_STRIPE_MAIN_FILE), array(), WC_STRIPE_VERSION, true);
523 523
 
524 524
 		$stripe_admin_params = array(
525 525
 			'localized_messages' => array(
526
-				'not_valid_live_key_msg' => __( 'This is not a valid live key. Live keys start with "sk_live_" and "pk_live_".', 'woocommerce-gateway-stripe' ),
527
-				'not_valid_test_key_msg' => __( 'This is not a valid test key. Test keys start with "sk_test_" and "pk_test_".', 'woocommerce-gateway-stripe' ),
528
-				're_verify_button_text'  => __( 'Re-verify Domain', 'woocommerce-gateway-stripe' ),
529
-				'missing_secret_key'     => __( 'Missing Secret Key. Please set the secret key field above and re-try.', 'woocommerce-gateway-stripe' ),
526
+				'not_valid_live_key_msg' => __('This is not a valid live key. Live keys start with "sk_live_" and "pk_live_".', 'woocommerce-gateway-stripe'),
527
+				'not_valid_test_key_msg' => __('This is not a valid test key. Test keys start with "sk_test_" and "pk_test_".', 'woocommerce-gateway-stripe'),
528
+				're_verify_button_text'  => __('Re-verify Domain', 'woocommerce-gateway-stripe'),
529
+				'missing_secret_key'     => __('Missing Secret Key. Please set the secret key field above and re-try.', 'woocommerce-gateway-stripe'),
530 530
 			),
531
-			'ajaxurl'            => admin_url( 'admin-ajax.php' ),
531
+			'ajaxurl'            => admin_url('admin-ajax.php'),
532 532
 			'nonce'              => array( 
533
-				'apple_pay_domain_nonce' => wp_create_nonce( '_wc_stripe_apple_pay_domain_nonce' ),
533
+				'apple_pay_domain_nonce' => wp_create_nonce('_wc_stripe_apple_pay_domain_nonce'),
534 534
 			),
535 535
 		);
536 536
 
537
-		wp_localize_script( 'woocommerce_stripe_admin', 'wc_stripe_admin_params', apply_filters( 'wc_stripe_admin_params', $stripe_admin_params ) );
537
+		wp_localize_script('woocommerce_stripe_admin', 'wc_stripe_admin_params', apply_filters('wc_stripe_admin_params', $stripe_admin_params));
538 538
 	}
539 539
 
540 540
 	/**
@@ -545,49 +545,49 @@  discard block
 block discarded – undo
545 545
 	 * @access public
546 546
 	 */
547 547
 	public function payment_scripts() {
548
-		if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) && ! is_add_payment_method_page() ) {
548
+		if ( ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order']) && ! is_add_payment_method_page()) {
549 549
 			return;
550 550
 		}
551 551
 
552
-		$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
552
+		$suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';
553 553
 
554
-		if ( $this->stripe_checkout ) {
555
-			wp_enqueue_script( 'stripe_checkout', 'https://checkout.stripe.com/v2/checkout.js', '', '2.0', true );
556
-			wp_enqueue_script( 'woocommerce_stripe', plugins_url( 'assets/js/stripe-checkout' . $suffix . '.js', WC_STRIPE_MAIN_FILE ), array( 'stripe_checkout' ), WC_STRIPE_VERSION, true );
554
+		if ($this->stripe_checkout) {
555
+			wp_enqueue_script('stripe_checkout', 'https://checkout.stripe.com/v2/checkout.js', '', '2.0', true);
556
+			wp_enqueue_script('woocommerce_stripe', plugins_url('assets/js/stripe-checkout' . $suffix . '.js', WC_STRIPE_MAIN_FILE), array('stripe_checkout'), WC_STRIPE_VERSION, true);
557 557
 		} else {
558
-			wp_enqueue_script( 'stripe', 'https://js.stripe.com/v2/', '', '1.0', true );
559
-			wp_enqueue_script( 'woocommerce_stripe', plugins_url( 'assets/js/stripe' . $suffix . '.js', WC_STRIPE_MAIN_FILE ), array( 'jquery-payment', 'stripe' ), WC_STRIPE_VERSION, true );
558
+			wp_enqueue_script('stripe', 'https://js.stripe.com/v2/', '', '1.0', true);
559
+			wp_enqueue_script('woocommerce_stripe', plugins_url('assets/js/stripe' . $suffix . '.js', WC_STRIPE_MAIN_FILE), array('jquery-payment', 'stripe'), WC_STRIPE_VERSION, true);
560 560
 		}
561 561
 
562 562
 		$stripe_params = array(
563 563
 			'key'                  => $this->publishable_key,
564
-			'i18n_terms'           => __( 'Please accept the terms and conditions first', 'woocommerce-gateway-stripe' ),
565
-			'i18n_required_fields' => __( 'Please fill in required checkout fields first', 'woocommerce-gateway-stripe' ),
564
+			'i18n_terms'           => __('Please accept the terms and conditions first', 'woocommerce-gateway-stripe'),
565
+			'i18n_required_fields' => __('Please fill in required checkout fields first', 'woocommerce-gateway-stripe'),
566 566
 		);
567 567
 
568 568
 		// If we're on the pay page we need to pass stripe.js the address of the order.
569
-		if ( isset( $_GET['pay_for_order'] ) && 'true' === $_GET['pay_for_order'] ) {
570
-			$order_id = wc_get_order_id_by_order_key( urldecode( $_GET['key'] ) );
571
-			$order    = wc_get_order( $order_id );
569
+		if (isset($_GET['pay_for_order']) && 'true' === $_GET['pay_for_order']) {
570
+			$order_id = wc_get_order_id_by_order_key(urldecode($_GET['key']));
571
+			$order    = wc_get_order($order_id);
572 572
 
573
-			$stripe_params['billing_first_name'] = version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->billing_first_name : $order->get_billing_first_name();
574
-			$stripe_params['billing_last_name']  = version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->billing_last_name : $order->get_billing_last_name();
575
-			$stripe_params['billing_address_1']  = version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->billing_address_1 : $order->get_billing_address_1();
576
-			$stripe_params['billing_address_2']  = version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->billing_address_2 : $order->get_billing_address_2();
577
-			$stripe_params['billing_state']      = version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->billing_state : $order->get_billing_state();
578
-			$stripe_params['billing_city']       = version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->billing_city : $order->get_billing_city();
579
-			$stripe_params['billing_postcode']   = version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->billing_postcode : $order->get_billing_postcode();
580
-			$stripe_params['billing_country']    = version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->billing_country : $order->get_billing_country();
573
+			$stripe_params['billing_first_name'] = version_compare(WC_VERSION, '3.0.0', '<') ? $order->billing_first_name : $order->get_billing_first_name();
574
+			$stripe_params['billing_last_name']  = version_compare(WC_VERSION, '3.0.0', '<') ? $order->billing_last_name : $order->get_billing_last_name();
575
+			$stripe_params['billing_address_1']  = version_compare(WC_VERSION, '3.0.0', '<') ? $order->billing_address_1 : $order->get_billing_address_1();
576
+			$stripe_params['billing_address_2']  = version_compare(WC_VERSION, '3.0.0', '<') ? $order->billing_address_2 : $order->get_billing_address_2();
577
+			$stripe_params['billing_state']      = version_compare(WC_VERSION, '3.0.0', '<') ? $order->billing_state : $order->get_billing_state();
578
+			$stripe_params['billing_city']       = version_compare(WC_VERSION, '3.0.0', '<') ? $order->billing_city : $order->get_billing_city();
579
+			$stripe_params['billing_postcode']   = version_compare(WC_VERSION, '3.0.0', '<') ? $order->billing_postcode : $order->get_billing_postcode();
580
+			$stripe_params['billing_country']    = version_compare(WC_VERSION, '3.0.0', '<') ? $order->billing_country : $order->get_billing_country();
581 581
 		}
582 582
 
583
-		$stripe_params['no_prepaid_card_msg']                     = __( 'Sorry, we\'re not accepting prepaid cards at this time.', 'woocommerce-gateway-stripe' );
584
-		$stripe_params['allow_prepaid_card']                      = apply_filters( 'wc_stripe_allow_prepaid_card', true ) ? 'yes' : 'no';
585
-		$stripe_params['stripe_checkout_require_billing_address'] = apply_filters( 'wc_stripe_checkout_require_billing_address', false ) ? 'yes' : 'no';
583
+		$stripe_params['no_prepaid_card_msg']                     = __('Sorry, we\'re not accepting prepaid cards at this time.', 'woocommerce-gateway-stripe');
584
+		$stripe_params['allow_prepaid_card']                      = apply_filters('wc_stripe_allow_prepaid_card', true) ? 'yes' : 'no';
585
+		$stripe_params['stripe_checkout_require_billing_address'] = apply_filters('wc_stripe_checkout_require_billing_address', false) ? 'yes' : 'no';
586 586
 
587 587
 		// merge localized messages to be use in JS
588
-		$stripe_params = array_merge( $stripe_params, $this->get_localized_messages() );
588
+		$stripe_params = array_merge($stripe_params, $this->get_localized_messages());
589 589
 
590
-		wp_localize_script( 'woocommerce_stripe', 'wc_stripe_params', apply_filters( 'wc_stripe_params', $stripe_params ) );
590
+		wp_localize_script('woocommerce_stripe', 'wc_stripe_params', apply_filters('wc_stripe_params', $stripe_params));
591 591
 	}
592 592
 
593 593
 	/**
@@ -596,35 +596,35 @@  discard block
 block discarded – undo
596 596
 	 * @param  object $source
597 597
 	 * @return array()
598 598
 	 */
599
-	protected function generate_payment_request( $order, $source ) {
599
+	protected function generate_payment_request($order, $source) {
600 600
 		$post_data                = array();
601
-		$post_data['currency']    = strtolower( version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->get_order_currency() : $order->get_currency() );
602
-		$post_data['amount']      = $this->get_stripe_amount( $order->get_total(), $post_data['currency'] );
603
-		$post_data['description'] = sprintf( __( '%1$s - Order %2$s', 'woocommerce-gateway-stripe' ), $this->statement_descriptor, $order->get_order_number() );
601
+		$post_data['currency']    = strtolower(version_compare(WC_VERSION, '3.0.0', '<') ? $order->get_order_currency() : $order->get_currency());
602
+		$post_data['amount']      = $this->get_stripe_amount($order->get_total(), $post_data['currency']);
603
+		$post_data['description'] = sprintf(__('%1$s - Order %2$s', 'woocommerce-gateway-stripe'), $this->statement_descriptor, $order->get_order_number());
604 604
 		$post_data['capture']     = $this->capture ? 'true' : 'false';
605 605
 
606
-		$billing_email      = version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->billing_email : $order->get_billing_email();
607
-		$billing_first_name = version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->billing_first_name : $order->get_billing_first_name();
608
-		$billing_last_name  = version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->billing_last_name : $order->get_billing_last_name();
606
+		$billing_email      = version_compare(WC_VERSION, '3.0.0', '<') ? $order->billing_email : $order->get_billing_email();
607
+		$billing_first_name = version_compare(WC_VERSION, '3.0.0', '<') ? $order->billing_first_name : $order->get_billing_first_name();
608
+		$billing_last_name  = version_compare(WC_VERSION, '3.0.0', '<') ? $order->billing_last_name : $order->get_billing_last_name();
609 609
 
610
-		if ( ! empty( $billing_email ) && apply_filters( 'wc_stripe_send_stripe_receipt', false ) ) {
610
+		if ( ! empty($billing_email) && apply_filters('wc_stripe_send_stripe_receipt', false)) {
611 611
 			$post_data['receipt_email'] = $billing_email;
612 612
 		}
613 613
 
614
-		$post_data['expand[]']    = 'balance_transaction';
614
+		$post_data['expand[]'] = 'balance_transaction';
615 615
 
616 616
 		$metadata = array(
617
-			__( 'Customer Name', 'woocommerce-gateway-stripe' ) => sanitize_text_field( $billing_first_name ) . ' ' . sanitize_text_field( $billing_last_name ),
618
-			__( 'Customer Email', 'woocommerce-gateway-stripe' ) => sanitize_email( $billing_email ),
617
+			__('Customer Name', 'woocommerce-gateway-stripe') => sanitize_text_field($billing_first_name) . ' ' . sanitize_text_field($billing_last_name),
618
+			__('Customer Email', 'woocommerce-gateway-stripe') => sanitize_email($billing_email),
619 619
 		);
620 620
 
621
-		$post_data['metadata'] = apply_filters( 'wc_stripe_payment_metadata', $metadata, $order, $source );
621
+		$post_data['metadata'] = apply_filters('wc_stripe_payment_metadata', $metadata, $order, $source);
622 622
 
623
-		if ( $source->customer ) {
623
+		if ($source->customer) {
624 624
 			$post_data['customer'] = $source->customer;
625 625
 		}
626 626
 
627
-		if ( $source->source ) {
627
+		if ($source->source) {
628 628
 			$post_data['source'] = $source->source;
629 629
 		}
630 630
 
@@ -636,7 +636,7 @@  discard block
 block discarded – undo
636 636
 		 * @param WC_Order $order
637 637
 		 * @param object $source
638 638
 		 */
639
-		return apply_filters( 'wc_stripe_generate_payment_request', $post_data, $order, $source );
639
+		return apply_filters('wc_stripe_generate_payment_request', $post_data, $order, $source);
640 640
 	}
641 641
 
642 642
 	/**
@@ -648,37 +648,37 @@  discard block
 block discarded – undo
648 648
 	 * @throws Exception When card was not added or for and invalid card.
649 649
 	 * @return object
650 650
 	 */
651
-	protected function get_source( $user_id, $force_customer = false ) {
652
-		$stripe_customer = new WC_Stripe_Customer( $user_id );
651
+	protected function get_source($user_id, $force_customer = false) {
652
+		$stripe_customer = new WC_Stripe_Customer($user_id);
653 653
 		$stripe_source   = false;
654 654
 		$token_id        = false;
655 655
 
656 656
 		// New CC info was entered and we have a new token to process
657
-		if ( isset( $_POST['stripe_token'] ) ) {
658
-			$stripe_token     = wc_clean( $_POST['stripe_token'] );
659
-			$maybe_saved_card = isset( $_POST['wc-stripe-new-payment-method'] ) && ! empty( $_POST['wc-stripe-new-payment-method'] );
657
+		if (isset($_POST['stripe_token'])) {
658
+			$stripe_token     = wc_clean($_POST['stripe_token']);
659
+			$maybe_saved_card = isset($_POST['wc-stripe-new-payment-method']) && ! empty($_POST['wc-stripe-new-payment-method']);
660 660
 
661 661
 			// This is true if the user wants to store the card to their account.
662
-			if ( ( $user_id && $this->saved_cards && $maybe_saved_card ) || $force_customer ) {
663
-				$stripe_source = $stripe_customer->add_card( $stripe_token );
662
+			if (($user_id && $this->saved_cards && $maybe_saved_card) || $force_customer) {
663
+				$stripe_source = $stripe_customer->add_card($stripe_token);
664 664
 
665
-				if ( is_wp_error( $stripe_source ) ) {
666
-					throw new Exception( $stripe_source->get_error_message() );
665
+				if (is_wp_error($stripe_source)) {
666
+					throw new Exception($stripe_source->get_error_message());
667 667
 				}
668 668
 			} else {
669 669
 				// Not saving token, so don't define customer either.
670 670
 				$stripe_source   = $stripe_token;
671 671
 				$stripe_customer = false;
672 672
 			}
673
-		} elseif ( isset( $_POST['wc-stripe-payment-token'] ) && 'new' !== $_POST['wc-stripe-payment-token'] ) {
673
+		} elseif (isset($_POST['wc-stripe-payment-token']) && 'new' !== $_POST['wc-stripe-payment-token']) {
674 674
 			// Use an existing token, and then process the payment
675 675
 
676
-			$token_id = wc_clean( $_POST['wc-stripe-payment-token'] );
677
-			$token    = WC_Payment_Tokens::get( $token_id );
676
+			$token_id = wc_clean($_POST['wc-stripe-payment-token']);
677
+			$token    = WC_Payment_Tokens::get($token_id);
678 678
 
679
-			if ( ! $token || $token->get_user_id() !== get_current_user_id() ) {
680
-				WC()->session->set( 'refresh_totals', true );
681
-				throw new Exception( __( 'Invalid payment method. Please input a new card number.', 'woocommerce-gateway-stripe' ) );
679
+			if ( ! $token || $token->get_user_id() !== get_current_user_id()) {
680
+				WC()->session->set('refresh_totals', true);
681
+				throw new Exception(__('Invalid payment method. Please input a new card number.', 'woocommerce-gateway-stripe'));
682 682
 			}
683 683
 
684 684
 			$stripe_source = $token->get_token();
@@ -702,19 +702,19 @@  discard block
 block discarded – undo
702 702
 	 * @param object $order
703 703
 	 * @return object
704 704
 	 */
705
-	protected function get_order_source( $order = null ) {
705
+	protected function get_order_source($order = null) {
706 706
 		$stripe_customer = new WC_Stripe_Customer();
707 707
 		$stripe_source   = false;
708 708
 		$token_id        = false;
709 709
 
710
-		if ( $order ) {
711
-			$order_id = version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->id : $order->get_id();
710
+		if ($order) {
711
+			$order_id = version_compare(WC_VERSION, '3.0.0', '<') ? $order->id : $order->get_id();
712 712
 
713
-			if ( $meta_value = get_post_meta( $order_id, '_stripe_customer_id', true ) ) {
714
-				$stripe_customer->set_id( $meta_value );
713
+			if ($meta_value = get_post_meta($order_id, '_stripe_customer_id', true)) {
714
+				$stripe_customer->set_id($meta_value);
715 715
 			}
716 716
 
717
-			if ( $meta_value = get_post_meta( $order_id, '_stripe_card_id', true ) ) {
717
+			if ($meta_value = get_post_meta($order_id, '_stripe_card_id', true)) {
718 718
 				$stripe_source = $meta_value;
719 719
 			}
720 720
 		}
@@ -737,57 +737,57 @@  discard block
 block discarded – undo
737 737
 	 *
738 738
 	 * @return array|void
739 739
 	 */
740
-	public function process_payment( $order_id, $retry = true, $force_customer = false ) {
740
+	public function process_payment($order_id, $retry = true, $force_customer = false) {
741 741
 		try {
742
-			$order  = wc_get_order( $order_id );
743
-			$source = $this->get_source( get_current_user_id(), $force_customer );
742
+			$order  = wc_get_order($order_id);
743
+			$source = $this->get_source(get_current_user_id(), $force_customer);
744 744
 
745
-			if ( empty( $source->source ) && empty( $source->customer ) ) {
746
-				$error_msg = __( 'Please enter your card details to make a payment.', 'woocommerce-gateway-stripe' );
747
-				$error_msg .= ' ' . __( 'Developers: Please make sure that you are including jQuery and there are no JavaScript errors on the page.', 'woocommerce-gateway-stripe' );
748
-				throw new Exception( $error_msg );
745
+			if (empty($source->source) && empty($source->customer)) {
746
+				$error_msg = __('Please enter your card details to make a payment.', 'woocommerce-gateway-stripe');
747
+				$error_msg .= ' ' . __('Developers: Please make sure that you are including jQuery and there are no JavaScript errors on the page.', 'woocommerce-gateway-stripe');
748
+				throw new Exception($error_msg);
749 749
 			}
750 750
 
751 751
 			// Store source to order meta.
752
-			$this->save_source( $order, $source );
752
+			$this->save_source($order, $source);
753 753
 
754 754
 			// Handle payment.
755
-			if ( $order->get_total() > 0 ) {
755
+			if ($order->get_total() > 0) {
756 756
 
757
-				if ( $order->get_total() * 100 < WC_Stripe::get_minimum_amount() ) {
758
-					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 ) ) );
757
+				if ($order->get_total() * 100 < WC_Stripe::get_minimum_amount()) {
758
+					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)));
759 759
 				}
760 760
 
761
-				$this->log( "Info: Begin processing payment for order $order_id for the amount of {$order->get_total()}" );
761
+				$this->log("Info: Begin processing payment for order $order_id for the amount of {$order->get_total()}");
762 762
 
763 763
 				// Make the request.
764
-				$response = WC_Stripe_API::request( $this->generate_payment_request( $order, $source ) );
764
+				$response = WC_Stripe_API::request($this->generate_payment_request($order, $source));
765 765
 
766
-				if ( is_wp_error( $response ) ) {
766
+				if (is_wp_error($response)) {
767 767
 					// Customer param wrong? The user may have been deleted on stripe's end. Remove customer_id. Can be retried without.
768
-					if ( 'customer' === $response->get_error_code() && $retry ) {
769
-						delete_user_meta( get_current_user_id(), '_stripe_customer_id' );
770
-						return $this->process_payment( $order_id, false, $force_customer );
768
+					if ('customer' === $response->get_error_code() && $retry) {
769
+						delete_user_meta(get_current_user_id(), '_stripe_customer_id');
770
+						return $this->process_payment($order_id, false, $force_customer);
771 771
 						// Source param wrong? The CARD may have been deleted on stripe's end. Remove token and show message.
772
-					} elseif ( 'source' === $response->get_error_code() && $source->token_id ) {
773
-						$token = WC_Payment_Tokens::get( $source->token_id );
772
+					} elseif ('source' === $response->get_error_code() && $source->token_id) {
773
+						$token = WC_Payment_Tokens::get($source->token_id);
774 774
 						$token->delete();
775
-						$message = __( 'This card is no longer available and has been removed.', 'woocommerce-gateway-stripe' );
776
-						$order->add_order_note( $message );
777
-						throw new Exception( $message );
775
+						$message = __('This card is no longer available and has been removed.', 'woocommerce-gateway-stripe');
776
+						$order->add_order_note($message);
777
+						throw new Exception($message);
778 778
 					}
779 779
 
780 780
 					$localized_messages = $this->get_localized_messages();
781 781
 
782
-					$message = isset( $localized_messages[ $response->get_error_code() ] ) ? $localized_messages[ $response->get_error_code() ] : $response->get_error_message();
782
+					$message = isset($localized_messages[$response->get_error_code()]) ? $localized_messages[$response->get_error_code()] : $response->get_error_message();
783 783
 
784
-					$order->add_order_note( $message );
784
+					$order->add_order_note($message);
785 785
 
786
-					throw new Exception( $message );
786
+					throw new Exception($message);
787 787
 				}
788 788
 
789 789
 				// Process valid response.
790
-				$this->process_response( $response, $order );
790
+				$this->process_response($response, $order);
791 791
 			} else {
792 792
 				$order->payment_complete();
793 793
 			}
@@ -795,23 +795,23 @@  discard block
 block discarded – undo
795 795
 			// Remove cart.
796 796
 			WC()->cart->empty_cart();
797 797
 
798
-			do_action( 'wc_gateway_stripe_process_payment', $response, $order );
798
+			do_action('wc_gateway_stripe_process_payment', $response, $order);
799 799
 
800 800
 			// Return thank you page redirect.
801 801
 			return array(
802 802
 				'result'   => 'success',
803
-				'redirect' => $this->get_return_url( $order ),
803
+				'redirect' => $this->get_return_url($order),
804 804
 			);
805 805
 
806
-		} catch ( Exception $e ) {
807
-			wc_add_notice( $e->getMessage(), 'error' );
808
-			$this->log( sprintf( __( 'Error: %s', 'woocommerce-gateway-stripe' ), $e->getMessage() ) );
806
+		} catch (Exception $e) {
807
+			wc_add_notice($e->getMessage(), 'error');
808
+			$this->log(sprintf(__('Error: %s', 'woocommerce-gateway-stripe'), $e->getMessage()));
809 809
 
810
-			if ( $order->has_status( array( 'pending', 'failed' ) ) ) {
811
-				$this->send_failed_order_email( $order_id );
810
+			if ($order->has_status(array('pending', 'failed'))) {
811
+				$this->send_failed_order_email($order_id);
812 812
 			}
813 813
 
814
-			do_action( 'wc_gateway_stripe_process_payment_error', $e, $order );
814
+			do_action('wc_gateway_stripe_process_payment_error', $e, $order);
815 815
 
816 816
 			return array(
817 817
 				'result'   => 'fail',
@@ -826,56 +826,56 @@  discard block
 block discarded – undo
826 826
 	 * @param WC_Order $order For to which the source applies.
827 827
 	 * @param stdClass $source Source information.
828 828
 	 */
829
-	protected function save_source( $order, $source ) {
830
-		$order_id = version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->id : $order->get_id();
829
+	protected function save_source($order, $source) {
830
+		$order_id = version_compare(WC_VERSION, '3.0.0', '<') ? $order->id : $order->get_id();
831 831
 
832 832
 		// Store source in the order.
833
-		if ( $source->customer ) {
834
-			update_post_meta( $order_id, '_stripe_customer_id', $source->customer );
833
+		if ($source->customer) {
834
+			update_post_meta($order_id, '_stripe_customer_id', $source->customer);
835 835
 		}
836
-		if ( $source->source ) {
837
-			update_post_meta( $order_id, '_stripe_card_id', $source->source );
836
+		if ($source->source) {
837
+			update_post_meta($order_id, '_stripe_card_id', $source->source);
838 838
 		}
839 839
 	}
840 840
 
841 841
 	/**
842 842
 	 * Store extra meta data for an order from a Stripe Response.
843 843
 	 */
844
-	public function process_response( $response, $order ) {
845
-		$this->log( 'Processing response: ' . print_r( $response, true ) );
844
+	public function process_response($response, $order) {
845
+		$this->log('Processing response: ' . print_r($response, true));
846 846
 
847
-		$order_id = version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->id : $order->get_id();
847
+		$order_id = version_compare(WC_VERSION, '3.0.0', '<') ? $order->id : $order->get_id();
848 848
 
849 849
 		// Store charge data
850
-		update_post_meta( $order_id, '_stripe_charge_id', $response->id );
851
-		update_post_meta( $order_id, '_stripe_charge_captured', $response->captured ? 'yes' : 'no' );
850
+		update_post_meta($order_id, '_stripe_charge_id', $response->id);
851
+		update_post_meta($order_id, '_stripe_charge_captured', $response->captured ? 'yes' : 'no');
852 852
 
853 853
 		// Store other data such as fees
854
-		if ( isset( $response->balance_transaction ) && isset( $response->balance_transaction->fee ) ) {
854
+		if (isset($response->balance_transaction) && isset($response->balance_transaction->fee)) {
855 855
 			// Fees and Net needs to both come from Stripe to be accurate as the returned
856 856
 			// values are in the local currency of the Stripe account, not from WC.
857
-			$fee = ! empty( $response->balance_transaction->fee ) ? WC_Stripe::format_number( $response->balance_transaction, 'fee' ) : 0;
858
-			$net = ! empty( $response->balance_transaction->net ) ? WC_Stripe::format_number( $response->balance_transaction, 'net' ) : 0;
859
-			update_post_meta( $order_id, 'Stripe Fee', $fee );
860
-			update_post_meta( $order_id, 'Net Revenue From Stripe', $net );
857
+			$fee = ! empty($response->balance_transaction->fee) ? WC_Stripe::format_number($response->balance_transaction, 'fee') : 0;
858
+			$net = ! empty($response->balance_transaction->net) ? WC_Stripe::format_number($response->balance_transaction, 'net') : 0;
859
+			update_post_meta($order_id, 'Stripe Fee', $fee);
860
+			update_post_meta($order_id, 'Net Revenue From Stripe', $net);
861 861
 		}
862 862
 
863
-		if ( $response->captured ) {
864
-			$order->payment_complete( $response->id );
863
+		if ($response->captured) {
864
+			$order->payment_complete($response->id);
865 865
 
866
-			$message = sprintf( __( 'Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe' ), $response->id );
867
-			$order->add_order_note( $message );
868
-			$this->log( 'Success: ' . $message );
866
+			$message = sprintf(__('Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe'), $response->id);
867
+			$order->add_order_note($message);
868
+			$this->log('Success: ' . $message);
869 869
 
870 870
 		} else {
871
-			add_post_meta( $order_id, '_transaction_id', $response->id, true );
871
+			add_post_meta($order_id, '_transaction_id', $response->id, true);
872 872
 
873
-			if ( $order->has_status( array( 'pending', 'failed' ) ) ) {
874
-				version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->reduce_order_stock() : wc_reduce_stock_levels( $order_id );
873
+			if ($order->has_status(array('pending', 'failed'))) {
874
+				version_compare(WC_VERSION, '3.0.0', '<') ? $order->reduce_order_stock() : wc_reduce_stock_levels($order_id);
875 875
 			}
876 876
 
877
-			$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 ) );
878
-			$this->log( "Successful auth: $response->id" );
877
+			$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));
878
+			$this->log("Successful auth: $response->id");
879 879
 		}
880 880
 
881 881
 		return $response;
@@ -887,32 +887,32 @@  discard block
 block discarded – undo
887 887
 	 * @since 3.0.0
888 888
 	 */
889 889
 	public function add_payment_method() {
890
-		if ( empty( $_POST['stripe_token'] ) || ! is_user_logged_in() ) {
891
-			wc_add_notice( __( 'There was a problem adding the card.', 'woocommerce-gateway-stripe' ), 'error' );
890
+		if (empty($_POST['stripe_token']) || ! is_user_logged_in()) {
891
+			wc_add_notice(__('There was a problem adding the card.', 'woocommerce-gateway-stripe'), 'error');
892 892
 			return;
893 893
 		}
894 894
 
895
-		$stripe_customer = new WC_Stripe_Customer( get_current_user_id() );
896
-		$card            = $stripe_customer->add_card( wc_clean( $_POST['stripe_token'] ) );
895
+		$stripe_customer = new WC_Stripe_Customer(get_current_user_id());
896
+		$card            = $stripe_customer->add_card(wc_clean($_POST['stripe_token']));
897 897
 
898
-		if ( is_wp_error( $card ) ) {
898
+		if (is_wp_error($card)) {
899 899
 			$localized_messages = $this->get_localized_messages();
900
-			$error_msg = __( 'There was a problem adding the card.', 'woocommerce-gateway-stripe' );
900
+			$error_msg = __('There was a problem adding the card.', 'woocommerce-gateway-stripe');
901 901
 
902 902
 			// loop through the errors to find matching localized message
903
-			foreach ( $card->errors as $error => $msg ) {
904
-				if ( isset( $localized_messages[ $error ] ) ) {
905
-					$error_msg = $localized_messages[ $error ];
903
+			foreach ($card->errors as $error => $msg) {
904
+				if (isset($localized_messages[$error])) {
905
+					$error_msg = $localized_messages[$error];
906 906
 				}
907 907
 			}
908 908
 
909
-			wc_add_notice( $error_msg, 'error' );
909
+			wc_add_notice($error_msg, 'error');
910 910
 			return;
911 911
 		}
912 912
 
913 913
 		return array(
914 914
 			'result'   => 'success',
915
-			'redirect' => wc_get_endpoint_url( 'payment-methods' ),
915
+			'redirect' => wc_get_endpoint_url('payment-methods'),
916 916
 		);
917 917
 	}
918 918
 
@@ -922,36 +922,36 @@  discard block
 block discarded – undo
922 922
 	 * @param  float $amount
923 923
 	 * @return bool
924 924
 	 */
925
-	public function process_refund( $order_id, $amount = null, $reason = '' ) {
926
-		$order = wc_get_order( $order_id );
925
+	public function process_refund($order_id, $amount = null, $reason = '') {
926
+		$order = wc_get_order($order_id);
927 927
 
928
-		if ( ! $order || ! $order->get_transaction_id() ) {
928
+		if ( ! $order || ! $order->get_transaction_id()) {
929 929
 			return false;
930 930
 		}
931 931
 
932 932
 		$body = array();
933 933
 
934
-		if ( ! is_null( $amount ) ) {
935
-			$body['amount']	= $this->get_stripe_amount( $amount );
934
+		if ( ! is_null($amount)) {
935
+			$body['amount'] = $this->get_stripe_amount($amount);
936 936
 		}
937 937
 
938
-		if ( $reason ) {
938
+		if ($reason) {
939 939
 			$body['metadata'] = array(
940 940
 				'reason'	=> $reason,
941 941
 			);
942 942
 		}
943 943
 
944
-		$this->log( "Info: Beginning refund for order $order_id for the amount of {$amount}" );
944
+		$this->log("Info: Beginning refund for order $order_id for the amount of {$amount}");
945 945
 
946
-		$response = WC_Stripe_API::request( $body, 'charges/' . $order->get_transaction_id() . '/refunds' );
946
+		$response = WC_Stripe_API::request($body, 'charges/' . $order->get_transaction_id() . '/refunds');
947 947
 
948
-		if ( is_wp_error( $response ) ) {
949
-			$this->log( 'Error: ' . $response->get_error_message() );
948
+		if (is_wp_error($response)) {
949
+			$this->log('Error: ' . $response->get_error_message());
950 950
 			return $response;
951
-		} elseif ( ! empty( $response->id ) ) {
952
-			$refund_message = sprintf( __( 'Refunded %1$s - Refund ID: %2$s - Reason: %3$s', 'woocommerce-gateway-stripe' ), wc_price( $response->amount / 100 ), $response->id, $reason );
953
-			$order->add_order_note( $refund_message );
954
-			$this->log( 'Success: ' . html_entity_decode( strip_tags( $refund_message ) ) );
951
+		} elseif ( ! empty($response->id)) {
952
+			$refund_message = sprintf(__('Refunded %1$s - Refund ID: %2$s - Reason: %3$s', 'woocommerce-gateway-stripe'), wc_price($response->amount / 100), $response->id, $reason);
953
+			$order->add_order_note($refund_message);
954
+			$this->log('Success: ' . html_entity_decode(strip_tags($refund_message)));
955 955
 			return true;
956 956
 		}
957 957
 	}
@@ -964,10 +964,10 @@  discard block
 block discarded – undo
964 964
 	 * @param int $order_id
965 965
 	 * @return null
966 966
 	 */
967
-	public function send_failed_order_email( $order_id ) {
967
+	public function send_failed_order_email($order_id) {
968 968
 		$emails = WC()->mailer()->get_emails();
969
-		if ( ! empty( $emails ) && ! empty( $order_id ) ) {
970
-			$emails['WC_Email_Failed_Order']->trigger( $order_id );
969
+		if ( ! empty($emails) && ! empty($order_id)) {
970
+			$emails['WC_Email_Failed_Order']->trigger($order_id);
971 971
 		}
972 972
 	}
973 973
 
@@ -979,9 +979,9 @@  discard block
 block discarded – undo
979 979
 	 *
980 980
 	 * @param string $message
981 981
 	 */
982
-	public function log( $message ) {
983
-		if ( $this->logging ) {
984
-			WC_Stripe::log( $message );
982
+	public function log($message) {
983
+		if ($this->logging) {
984
+			WC_Stripe::log($message);
985 985
 		}
986 986
 	}
987 987
 }
Please login to merge, or discard this patch.