Completed
Push — master ( 07cc8d...23d8d4 )
by Roy
01:57
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,35 +80,35 @@  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
-		if ( 'USD' === get_woocommerce_currency() ) {
91
-			$icon .= '<img src="' . WC_HTTPS::force_https_url( WC()->plugin_url() . '/assets/images/icons/credit-cards/discover' . $ext ) . '" alt="Discover" width="32" ' . $style . ' />';
92
-			$icon .= '<img src="' . WC_HTTPS::force_https_url( WC()->plugin_url() . '/assets/images/icons/credit-cards/jcb' . $ext ) . '" alt="JCB" width="32" ' . $style . ' />';
93
-			$icon .= '<img src="' . WC_HTTPS::force_https_url( WC()->plugin_url() . '/assets/images/icons/credit-cards/diners' . $ext ) . '" alt="Diners" width="32" ' . $style . ' />';
90
+		if ('USD' === get_woocommerce_currency()) {
91
+			$icon .= '<img src="' . WC_HTTPS::force_https_url(WC()->plugin_url() . '/assets/images/icons/credit-cards/discover' . $ext) . '" alt="Discover" width="32" ' . $style . ' />';
92
+			$icon .= '<img src="' . WC_HTTPS::force_https_url(WC()->plugin_url() . '/assets/images/icons/credit-cards/jcb' . $ext) . '" alt="JCB" width="32" ' . $style . ' />';
93
+			$icon .= '<img src="' . WC_HTTPS::force_https_url(WC()->plugin_url() . '/assets/images/icons/credit-cards/diners' . $ext) . '" alt="Diners" width="32" ' . $style . ' />';
94 94
 		}
95 95
 
96
-		if ( $this->bitcoin ) {
97
-			$icon .= '<img src="' . WC_HTTPS::force_https_url( plugins_url( '/assets/images/bitcoin' . $ext, WC_STRIPE_MAIN_FILE ) ) . '" alt="Bitcoin" width="32" ' . $style . ' />';
96
+		if ($this->bitcoin) {
97
+			$icon .= '<img src="' . WC_HTTPS::force_https_url(plugins_url('/assets/images/bitcoin' . $ext, WC_STRIPE_MAIN_FILE)) . '" alt="Bitcoin" width="32" ' . $style . ' />';
98 98
 		}
99 99
 
100
-		return apply_filters( 'woocommerce_gateway_icon', $icon, $this->id );
100
+		return apply_filters('woocommerce_gateway_icon', $icon, $this->id);
101 101
 	}
102 102
 
103 103
 	/**
104 104
 	 * Get Stripe amount to pay
105 105
 	 * @return float
106 106
 	 */
107
-	public function get_stripe_amount( $total, $currency = '' ) {
108
-		if ( ! $currency ) {
107
+	public function get_stripe_amount($total, $currency = '') {
108
+		if ( ! $currency) {
109 109
 			$currency = get_woocommerce_currency();
110 110
 		}
111
-		switch ( strtoupper( $currency ) ) {
111
+		switch (strtoupper($currency)) {
112 112
 			// Zero decimal currencies
113 113
 			case 'BIF' :
114 114
 			case 'CLP' :
@@ -125,10 +125,10 @@  discard block
 block discarded – undo
125 125
 			case 'XAF' :
126 126
 			case 'XOF' :
127 127
 			case 'XPF' :
128
-				$total = absint( $total );
128
+				$total = absint($total);
129 129
 				break;
130 130
 			default :
131
-				$total = round( $total, 2 ) * 100; // In cents
131
+				$total = round($total, 2) * 100; // In cents
132 132
 				break;
133 133
 		}
134 134
 		return $total;
@@ -138,31 +138,31 @@  discard block
 block discarded – undo
138 138
 	 * Check if SSL is enabled and notify the user
139 139
 	 */
140 140
 	public function admin_notices() {
141
-		if ( $this->enabled == 'no' ) {
141
+		if ($this->enabled == 'no') {
142 142
 			return;
143 143
 		}
144 144
 
145
-		$addons = ( class_exists( 'WC_Subscriptions_Order' ) || class_exists( 'WC_Pre_Orders_Order' ) ) ? '_addons' : '';
145
+		$addons = (class_exists('WC_Subscriptions_Order') || class_exists('WC_Pre_Orders_Order')) ? '_addons' : '';
146 146
 
147 147
 		// Check required fields
148
-		if ( ! $this->secret_key ) {
149
-			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>';
148
+		if ( ! $this->secret_key) {
149
+			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 150
 			return;
151 151
 
152
-		} elseif ( ! $this->publishable_key ) {
153
-			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>';
152
+		} elseif ( ! $this->publishable_key) {
153
+			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 154
 			return;
155 155
 		}
156 156
 
157 157
 		// Simple check for duplicate keys
158
-		if ( $this->secret_key == $this->publishable_key ) {
159
-			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>';
158
+		if ($this->secret_key == $this->publishable_key) {
159
+			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 160
 			return;
161 161
 		}
162 162
 
163 163
 		// Show message if enabled and FORCE SSL is disabled and WordpressHTTPS plugin is not detected
164
-		if ( ( function_exists( 'wc_site_is_https' ) && ! wc_site_is_https() ) && ( 'no' === get_option( 'woocommerce_force_ssl_checkout' ) && ! class_exists( 'WordPressHTTPS' ) ) ) {
165
-			echo '<div class="error"><p>' . sprintf( __( 'Stripe is enabled, but the <a href="%1$s">force SSL option</a> is disabled; your checkout may not be secure! Please enable SSL and ensure your server has a valid <a href="%2$s" target="_blank">SSL certificate</a> - Stripe will only work in test mode.', 'woocommerce-gateway-stripe' ), admin_url( 'admin.php?page=wc-settings&tab=checkout' ), 'https://en.wikipedia.org/wiki/Transport_Layer_Security' ) . '</p></div>';
164
+		if ((function_exists('wc_site_is_https') && ! wc_site_is_https()) && ('no' === get_option('woocommerce_force_ssl_checkout') && ! class_exists('WordPressHTTPS'))) {
165
+			echo '<div class="error"><p>' . sprintf(__('Stripe is enabled, but the <a href="%1$s">force SSL option</a> is disabled; your checkout may not be secure! Please enable SSL and ensure your server has a valid <a href="%2$s" target="_blank">SSL certificate</a> - Stripe will only work in test mode.', 'woocommerce-gateway-stripe'), admin_url('admin.php?page=wc-settings&tab=checkout'), 'https://en.wikipedia.org/wiki/Transport_Layer_Security') . '</p></div>';
166 166
 		}
167 167
 	}
168 168
 
@@ -170,11 +170,11 @@  discard block
 block discarded – undo
170 170
 	 * Check if this gateway is enabled
171 171
 	 */
172 172
 	public function is_available() {
173
-		if ( 'yes' === $this->enabled ) {
174
-			if ( ! $this->testmode && is_checkout() && ! is_ssl() ) {
173
+		if ('yes' === $this->enabled) {
174
+			if ( ! $this->testmode && is_checkout() && ! is_ssl()) {
175 175
 				return false;
176 176
 			}
177
-			if ( ! $this->secret_key || ! $this->publishable_key ) {
177
+			if ( ! $this->secret_key || ! $this->publishable_key) {
178 178
 				return false;
179 179
 			}
180 180
 			return true;
@@ -186,9 +186,9 @@  discard block
 block discarded – undo
186 186
 	 * Initialise Gateway Settings Form Fields
187 187
 	 */
188 188
 	public function init_form_fields() {
189
-		$this->form_fields = include( untrailingslashit( plugin_dir_path( WC_STRIPE_MAIN_FILE ) ) . '/includes/settings-stripe.php' );
189
+		$this->form_fields = include(untrailingslashit(plugin_dir_path(WC_STRIPE_MAIN_FILE)) . '/includes/settings-stripe.php');
190 190
 
191
-		wc_enqueue_js( "
191
+		wc_enqueue_js("
192 192
 			jQuery( function( $ ) {
193 193
 				$( '#woocommerce_stripe_stripe_checkout' ).change(function(){
194 194
 					if ( $( this ).is( ':checked' ) ) {
@@ -208,25 +208,25 @@  discard block
 block discarded – undo
208 208
 		?>
209 209
 		<fieldset class="stripe-legacy-payment-fields">
210 210
 			<?php
211
-				if ( $this->description ) {
212
-					echo apply_filters( 'wc_stripe_description', wpautop( wp_kses_post( $this->description ) ) );
211
+				if ($this->description) {
212
+					echo apply_filters('wc_stripe_description', wpautop(wp_kses_post($this->description)));
213 213
 				}
214
-				if ( $this->saved_cards && is_user_logged_in() ) {
215
-					$stripe_customer = new WC_Stripe_Customer( get_current_user_id() );
214
+				if ($this->saved_cards && is_user_logged_in()) {
215
+					$stripe_customer = new WC_Stripe_Customer(get_current_user_id());
216 216
 					?>
217 217
 					<p class="form-row form-row-wide">
218
-						<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>
218
+						<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>
219 219
 						<?php
220
-						if ( $cards = $stripe_customer->get_cards() ) {
220
+						if ($cards = $stripe_customer->get_cards()) {
221 221
 							$default_card = $cards[0]->id;
222
-							foreach ( (array) $cards as $card ) {
223
-								if ( 'card' !== $card->object ) {
222
+							foreach ((array) $cards as $card) {
223
+								if ('card' !== $card->object) {
224 224
 									continue;
225 225
 								}
226 226
 								?>
227
-								<label for="stripe_card_<?php echo $card->id; ?>" class="brand-<?php echo esc_attr( strtolower( $card->brand ) ); ?>">
228
-									<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 ) ?> />
229
-									<?php printf( __( '%s card ending in %s (Expires %s/%s)', 'woocommerce-gateway-stripe' ), $card->brand, $card->last4, $card->exp_month, $card->exp_year ); ?>
227
+								<label for="stripe_card_<?php echo $card->id; ?>" class="brand-<?php echo esc_attr(strtolower($card->brand)); ?>">
228
+									<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) ?> />
229
+									<?php printf(__('%s card ending in %s (Expires %s/%s)', 'woocommerce-gateway-stripe'), $card->brand, $card->last4, $card->exp_month, $card->exp_year); ?>
230 230
 								</label>
231 231
 								<?php
232 232
 							}
@@ -234,7 +234,7 @@  discard block
 block discarded – undo
234 234
 						?>
235 235
 						<label for="new">
236 236
 							<input type="radio" id="new" name="wc-stripe-payment-token" value="new" />
237
-							<?php _e( 'Use a new credit card', 'woocommerce-gateway-stripe' ); ?>
237
+							<?php _e('Use a new credit card', 'woocommerce-gateway-stripe'); ?>
238 238
 						</label>
239 239
 					</p>
240 240
 					<?php
@@ -242,8 +242,8 @@  discard block
 block discarded – undo
242 242
 
243 243
 				$user = wp_get_current_user();
244 244
 
245
-				if ( $user ) {
246
-					$user_email = get_user_meta( $user->ID, 'billing_email', true );
245
+				if ($user) {
246
+					$user_email = get_user_meta($user->ID, 'billing_email', true);
247 247
 					$user_email = $user_email ? $user_email : $user->user_email;
248 248
 				} else {
249 249
 					$user_email = '';
@@ -251,22 +251,22 @@  discard block
 block discarded – undo
251 251
 
252 252
 				$display = '';
253 253
 
254
-				if ( $this->stripe_checkout || $this->saved_cards && ! empty( $cards ) ) {
254
+				if ($this->stripe_checkout || $this->saved_cards && ! empty($cards)) {
255 255
 					$display = 'style="display:none;"';
256 256
 				}
257 257
 
258 258
 				echo '<div ' . $display . ' id="stripe-payment-data"
259 259
 					data-description=""
260
-					data-email="' . esc_attr( $user_email ) . '"
261
-					data-amount="' . esc_attr( $this->get_stripe_amount( WC()->cart->total ) ) . '"
262
-					data-name="' . esc_attr( get_bloginfo( 'name', 'display' ) ) . '"
263
-					data-currency="' . esc_attr( strtolower( get_woocommerce_currency() ) ) . '"
264
-					data-image="' . esc_attr( $this->stripe_checkout_image ) . '"
265
-					data-bitcoin="' . esc_attr( $this->bitcoin ? 'true' : 'false' ) . '"
266
-					data-locale="' . esc_attr( $this->stripe_checkout_locale ? $this->stripe_checkout_locale : 'en' ) . '">';
267
-
268
-				if ( ! $this->stripe_checkout ) {
269
-					$this->credit_card_form( array( 'fields_have_names' => false ) );
260
+					data-email="' . esc_attr($user_email) . '"
261
+					data-amount="' . esc_attr($this->get_stripe_amount(WC()->cart->total)) . '"
262
+					data-name="' . esc_attr(get_bloginfo('name', 'display')) . '"
263
+					data-currency="' . esc_attr(strtolower(get_woocommerce_currency())) . '"
264
+					data-image="' . esc_attr($this->stripe_checkout_image) . '"
265
+					data-bitcoin="' . esc_attr($this->bitcoin ? 'true' : 'false') . '"
266
+					data-locale="' . esc_attr($this->stripe_checkout_locale ? $this->stripe_checkout_locale : 'en') . '">';
267
+
268
+				if ( ! $this->stripe_checkout) {
269
+					$this->credit_card_form(array('fields_have_names' => false));
270 270
 				}
271 271
 
272 272
 				echo '</div>';
@@ -283,27 +283,27 @@  discard block
 block discarded – undo
283 283
 	 * @access public
284 284
 	 */
285 285
 	public function payment_scripts() {
286
-		if ( $this->stripe_checkout ) {
287
-			wp_enqueue_script( 'stripe', 'https://checkout.stripe.com/v2/checkout.js', '', '2.0', true );
288
-			wp_enqueue_script( 'woocommerce_stripe', plugins_url( 'assets/js/stripe-checkout.js', WC_STRIPE_MAIN_FILE ), array( 'stripe' ), WC_STRIPE_VERSION, true );
286
+		if ($this->stripe_checkout) {
287
+			wp_enqueue_script('stripe', 'https://checkout.stripe.com/v2/checkout.js', '', '2.0', true);
288
+			wp_enqueue_script('woocommerce_stripe', plugins_url('assets/js/stripe-checkout.js', WC_STRIPE_MAIN_FILE), array('stripe'), WC_STRIPE_VERSION, true);
289 289
 		} else {
290
-			wp_enqueue_script( 'stripe', 'https://js.stripe.com/v2/', '', '1.0', true );
291
-			wp_enqueue_script( 'woocommerce_stripe', plugins_url( 'assets/js/stripe.js', WC_STRIPE_MAIN_FILE ), array( 'jquery-payment', 'stripe' ), WC_STRIPE_VERSION, true );
290
+			wp_enqueue_script('stripe', 'https://js.stripe.com/v2/', '', '1.0', true);
291
+			wp_enqueue_script('woocommerce_stripe', plugins_url('assets/js/stripe.js', WC_STRIPE_MAIN_FILE), array('jquery-payment', 'stripe'), WC_STRIPE_VERSION, true);
292 292
 		}
293 293
 
294 294
 		$stripe_params = array(
295 295
 			'key'                  => $this->publishable_key,
296
-			'i18n_terms'           => __( 'Please accept the terms and conditions first', 'woocommerce-gateway-stripe' ),
297
-			'i18n_required_fields' => __( 'Please fill in required checkout fields first', 'woocommerce-gateway-stripe' ),
296
+			'i18n_terms'           => __('Please accept the terms and conditions first', 'woocommerce-gateway-stripe'),
297
+			'i18n_required_fields' => __('Please fill in required checkout fields first', 'woocommerce-gateway-stripe'),
298 298
 		);
299 299
 
300 300
 		// If we're on the pay page we need to pass stripe.js the address of the order.
301
-		if ( is_checkout_pay_page() && isset( $_GET['order'] ) && isset( $_GET['order_id'] ) ) {
302
-			$order_key = urldecode( $_GET['order'] );
303
-			$order_id  = absint( $_GET['order_id'] );
304
-			$order     = wc_get_order( $order_id );
301
+		if (is_checkout_pay_page() && isset($_GET['order']) && isset($_GET['order_id'])) {
302
+			$order_key = urldecode($_GET['order']);
303
+			$order_id  = absint($_GET['order_id']);
304
+			$order     = wc_get_order($order_id);
305 305
 
306
-			if ( $order->id === $order_id && $order->order_key === $order_key ) {
306
+			if ($order->id === $order_id && $order->order_key === $order_key) {
307 307
 				$stripe_params['billing_first_name'] = $order->billing_first_name;
308 308
 				$stripe_params['billing_last_name']  = $order->billing_last_name;
309 309
 				$stripe_params['billing_address_1']  = $order->billing_address_1;
@@ -315,7 +315,7 @@  discard block
 block discarded – undo
315 315
 			}
316 316
 		}
317 317
 
318
-		wp_localize_script( 'woocommerce_stripe', 'wc_stripe_params', apply_filters( 'wc_stripe_params', $stripe_params ) );
318
+		wp_localize_script('woocommerce_stripe', 'wc_stripe_params', apply_filters('wc_stripe_params', $stripe_params));
319 319
 	}
320 320
 
321 321
 	/**
@@ -324,28 +324,28 @@  discard block
 block discarded – undo
324 324
 	 * @param  object $source
325 325
 	 * @return array()
326 326
 	 */
327
-	protected function generate_payment_request( $order, $source ) {
327
+	protected function generate_payment_request($order, $source) {
328 328
 		$post_data                = array();
329
-		$post_data['currency']    = strtolower( $order->get_order_currency() ? $order->get_order_currency() : get_woocommerce_currency() );
330
-		$post_data['amount']      = $this->get_stripe_amount( $order->get_total(), $post_data['currency'] );
331
-		$post_data['description'] = sprintf( __( '%s - Order %s', 'woocommerce-gateway-stripe' ), wp_specialchars_decode( get_bloginfo( 'name' ), ENT_QUOTES ), $order->get_order_number() );
329
+		$post_data['currency']    = strtolower($order->get_order_currency() ? $order->get_order_currency() : get_woocommerce_currency());
330
+		$post_data['amount']      = $this->get_stripe_amount($order->get_total(), $post_data['currency']);
331
+		$post_data['description'] = sprintf(__('%s - Order %s', 'woocommerce-gateway-stripe'), wp_specialchars_decode(get_bloginfo('name'), ENT_QUOTES), $order->get_order_number());
332 332
 		$post_data['capture']     = $this->capture ? 'true' : 'false';
333 333
 
334
-		if ( ! empty( $order->billing_email ) && apply_filters( 'wc_stripe_send_stripe_receipt', false ) ) {
334
+		if ( ! empty($order->billing_email) && apply_filters('wc_stripe_send_stripe_receipt', false)) {
335 335
 			$post_data['receipt_email'] = $order->billing_email;
336 336
 		}
337 337
 
338
-		$post_data['expand[]']    = 'balance_transaction';
338
+		$post_data['expand[]'] = 'balance_transaction';
339 339
 
340
-		if ( $source->customer ) {
340
+		if ($source->customer) {
341 341
 			$post_data['customer'] = $source->customer;
342 342
 		}
343 343
 
344
-		if ( $source->source ) {
344
+		if ($source->source) {
345 345
 			$post_data['source'] = $source->source;
346 346
 		}
347 347
 
348
-		return apply_filters( 'wc_stripe_generate_payment_request', $post_data, $order, $source );
348
+		return apply_filters('wc_stripe_generate_payment_request', $post_data, $order, $source);
349 349
 	}
350 350
 
351 351
 	/**
@@ -353,22 +353,22 @@  discard block
 block discarded – undo
353 353
 	 * @param  bool $force_customer Should we force customer creation?
354 354
 	 * @return object
355 355
 	 */
356
-	protected function get_source( $user_id, $force_customer = false ) {
357
-		$stripe_customer = new WC_Stripe_Customer( $user_id );
356
+	protected function get_source($user_id, $force_customer = false) {
357
+		$stripe_customer = new WC_Stripe_Customer($user_id);
358 358
 		$stripe_source   = false;
359 359
 		$token_id        = false;
360 360
 
361 361
 		// New CC info was entered and we have a new token to process
362
-		if ( isset( $_POST['stripe_token'] ) ) {
363
-			$stripe_token     = wc_clean( $_POST['stripe_token'] );
364
-			$maybe_saved_card = isset( $_POST['wc-stripe-new-payment-method'] ) && ! empty( $_POST['wc-stripe-new-payment-method'] );
362
+		if (isset($_POST['stripe_token'])) {
363
+			$stripe_token     = wc_clean($_POST['stripe_token']);
364
+			$maybe_saved_card = isset($_POST['wc-stripe-new-payment-method']) && ! empty($_POST['wc-stripe-new-payment-method']);
365 365
 
366 366
 			// This is true if the user wants to store the card to their account.
367
-			if ( ( $user_id && $this->saved_cards && $maybe_saved_card ) || $force_customer ) {
368
-				$stripe_source = $stripe_customer->add_card( $stripe_token );
367
+			if (($user_id && $this->saved_cards && $maybe_saved_card) || $force_customer) {
368
+				$stripe_source = $stripe_customer->add_card($stripe_token);
369 369
 
370
-				if ( is_wp_error( $stripe_source ) ) {
371
-					throw new Exception( $stripe_source->get_error_message() );
370
+				if (is_wp_error($stripe_source)) {
371
+					throw new Exception($stripe_source->get_error_message());
372 372
 				}
373 373
 
374 374
 			} else {
@@ -379,8 +379,8 @@  discard block
 block discarded – undo
379 379
 		}
380 380
 
381 381
 		// Use an existing token, and then process the payment
382
-		elseif ( isset( $_POST['wc-stripe-payment-token'] ) && 'new' !== $_POST['wc-stripe-payment-token'] ) {
383
-			$stripe_source = wc_clean( $_POST['wc-stripe-payment-token'] );
382
+		elseif (isset($_POST['wc-stripe-payment-token']) && 'new' !== $_POST['wc-stripe-payment-token']) {
383
+			$stripe_source = wc_clean($_POST['wc-stripe-payment-token']);
384 384
 		}
385 385
 
386 386
 		return (object) array(
@@ -401,16 +401,16 @@  discard block
 block discarded – undo
401 401
 	 * @param object $order
402 402
 	 * @return object
403 403
 	 */
404
-	protected function get_order_source( $order = null ) {
404
+	protected function get_order_source($order = null) {
405 405
 		$stripe_customer = new WC_Stripe_Customer();
406 406
 		$stripe_source   = false;
407 407
 		$token_id        = false;
408 408
 
409
-		if ( $order ) {
410
-			if ( $meta_value = get_post_meta( $order->id, '_stripe_customer_id', true ) ) {
411
-				$stripe_customer->set_id( $meta_value );
409
+		if ($order) {
410
+			if ($meta_value = get_post_meta($order->id, '_stripe_customer_id', true)) {
411
+				$stripe_customer->set_id($meta_value);
412 412
 			}
413
-			if ( $meta_value = get_post_meta( $order->id, '_stripe_card_id', true ) ) {
413
+			if ($meta_value = get_post_meta($order->id, '_stripe_card_id', true)) {
414 414
 				$stripe_source = $meta_value;
415 415
 			}
416 416
 		}
@@ -425,43 +425,43 @@  discard block
 block discarded – undo
425 425
 	/**
426 426
 	 * Process the payment
427 427
 	 */
428
-	public function process_payment( $order_id, $retry = true, $force_customer = false ) {
428
+	public function process_payment($order_id, $retry = true, $force_customer = false) {
429 429
 		try {
430
-			$order  = wc_get_order( $order_id );
431
-			$source = $this->get_source( get_current_user_id(), $force_customer );
430
+			$order  = wc_get_order($order_id);
431
+			$source = $this->get_source(get_current_user_id(), $force_customer);
432 432
 
433
-			if ( empty( $source->source ) && empty( $source->customer ) ) {
434
-				$error_msg = __( 'Please enter your card details to make a payment.', 'woocommerce-gateway-stripe' );
435
-				$error_msg .= ' ' . __( 'Developers: Please make sure that you are including jQuery and there are no JavaScript errors on the page.', 'woocommerce-gateway-stripe' );
436
-				throw new Exception( $error_msg );
433
+			if (empty($source->source) && empty($source->customer)) {
434
+				$error_msg = __('Please enter your card details to make a payment.', 'woocommerce-gateway-stripe');
435
+				$error_msg .= ' ' . __('Developers: Please make sure that you are including jQuery and there are no JavaScript errors on the page.', 'woocommerce-gateway-stripe');
436
+				throw new Exception($error_msg);
437 437
 			}
438 438
 
439 439
 			// Store source to order meta
440
-			$this->save_source( $order, $source );
440
+			$this->save_source($order, $source);
441 441
 
442 442
 			// Handle payment
443
-			if ( $order->get_total() > 0 ) {
443
+			if ($order->get_total() > 0) {
444 444
 
445
-				if ( $order->get_total() * 100 < WC_Stripe::get_minimum_amount() ) {
446
-					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 ) ) );
445
+				if ($order->get_total() * 100 < WC_Stripe::get_minimum_amount()) {
446
+					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 447
 				}
448 448
 
449
-				WC_Stripe::log( "Info: Begin processing payment for order $order_id for the amount of {$order->get_total()}" );
449
+				WC_Stripe::log("Info: Begin processing payment for order $order_id for the amount of {$order->get_total()}");
450 450
 
451 451
 				// Make the request
452
-				$response = WC_Stripe_API::request( $this->generate_payment_request( $order, $source ) );
452
+				$response = WC_Stripe_API::request($this->generate_payment_request($order, $source));
453 453
 
454
-				if ( is_wp_error( $response ) ) {
454
+				if (is_wp_error($response)) {
455 455
 					// Customer param wrong? The user may have been deleted on stripe's end. Remove customer_id. Can be retried without.
456
-					if ( 'customer' === $response->get_error_code() && $retry ) {
457
-						delete_user_meta( get_current_user_id(), '_stripe_customer_id' );
458
-						return $this->process_payment( $order_id, false, $force_customer );
456
+					if ('customer' === $response->get_error_code() && $retry) {
457
+						delete_user_meta(get_current_user_id(), '_stripe_customer_id');
458
+						return $this->process_payment($order_id, false, $force_customer);
459 459
 					}
460
-					throw new Exception( $response->get_error_code() . ': ' . $response->get_error_message() );
460
+					throw new Exception($response->get_error_code() . ': ' . $response->get_error_message());
461 461
 				}
462 462
 
463 463
 				// Process valid response
464
-				$this->process_response( $response, $order );
464
+				$this->process_response($response, $order);
465 465
 			} else {
466 466
 				$order->payment_complete();
467 467
 			}
@@ -472,13 +472,13 @@  discard block
 block discarded – undo
472 472
 			// Return thank you page redirect
473 473
 			return array(
474 474
 				'result'   => 'success',
475
-				'redirect' => $this->get_return_url( $order )
475
+				'redirect' => $this->get_return_url($order)
476 476
 			);
477 477
 
478
-		} catch ( Exception $e ) {
479
-			wc_add_notice( $e->getMessage(), 'error' );
480
-			WC()->session->set( 'refresh_totals', true );
481
-			WC_Stripe::log( sprintf( __( 'Error: %s', 'woocommerce-gateway-stripe' ), $e->getMessage() ) );
478
+		} catch (Exception $e) {
479
+			wc_add_notice($e->getMessage(), 'error');
480
+			WC()->session->set('refresh_totals', true);
481
+			WC_Stripe::log(sprintf(__('Error: %s', 'woocommerce-gateway-stripe'), $e->getMessage()));
482 482
 			return;
483 483
 		}
484 484
 	}
@@ -486,45 +486,45 @@  discard block
 block discarded – undo
486 486
 	/**
487 487
 	 * Save source to order.
488 488
 	 */
489
-	protected function save_source( $order, $source ) {
489
+	protected function save_source($order, $source) {
490 490
 		// Store source in the order
491
-		if ( $source->customer ) {
492
-			update_post_meta( $order->id, '_stripe_customer_id', $source->customer );
491
+		if ($source->customer) {
492
+			update_post_meta($order->id, '_stripe_customer_id', $source->customer);
493 493
 		}
494
-		if ( $source->source ) {
495
-			update_post_meta( $order->id, '_stripe_card_id', $source->source->id );
494
+		if ($source->source) {
495
+			update_post_meta($order->id, '_stripe_card_id', $source->source->id);
496 496
 		}
497 497
 	}
498 498
 
499 499
 	/**
500 500
 	 * Store extra meta data for an order from a Stripe Response.
501 501
 	 */
502
-	public function process_response( $response, $order ) {
503
-		WC_Stripe::log( "Processing response: " . print_r( $response, true ) );
502
+	public function process_response($response, $order) {
503
+		WC_Stripe::log("Processing response: " . print_r($response, true));
504 504
 
505 505
 		// Store charge data
506
-		update_post_meta( $order->id, '_stripe_charge_id', $response->id );
507
-		update_post_meta( $order->id, '_stripe_charge_captured', $response->captured ? 'yes' : 'no' );
506
+		update_post_meta($order->id, '_stripe_charge_id', $response->id);
507
+		update_post_meta($order->id, '_stripe_charge_captured', $response->captured ? 'yes' : 'no');
508 508
 
509 509
 		// Store other data such as fees
510
-		if ( isset( $response->balance_transaction ) && isset( $response->balance_transaction->fee ) ) {
511
-			$fee = number_format( $response->balance_transaction->fee / 100, 2, '.', '' );
512
-			update_post_meta( $order->id, 'Stripe Fee', $fee );
513
-			update_post_meta( $order->id, 'Net Revenue From Stripe', $order->get_total() - $fee );
510
+		if (isset($response->balance_transaction) && isset($response->balance_transaction->fee)) {
511
+			$fee = number_format($response->balance_transaction->fee / 100, 2, '.', '');
512
+			update_post_meta($order->id, 'Stripe Fee', $fee);
513
+			update_post_meta($order->id, 'Net Revenue From Stripe', $order->get_total() - $fee);
514 514
 		}
515 515
 
516
-		if ( $response->captured ) {
517
-			$order->payment_complete( $response->id );
518
-			WC_Stripe::log( "Successful charge: $response->id" );
516
+		if ($response->captured) {
517
+			$order->payment_complete($response->id);
518
+			WC_Stripe::log("Successful charge: $response->id");
519 519
 		} else {
520
-			update_post_meta( $order->id, '_transaction_id', $response->id, true );
520
+			update_post_meta($order->id, '_transaction_id', $response->id, true);
521 521
 
522
-			if ( $order->has_status( array( 'pending', 'failed' ) ) ) {
522
+			if ($order->has_status(array('pending', 'failed'))) {
523 523
 				$order->reduce_order_stock();
524 524
 			}
525 525
 
526
-			$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 ) );
527
-			WC_Stripe::log( "Successful auth: $response->id" );
526
+			$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));
527
+			WC_Stripe::log("Successful auth: $response->id");
528 528
 		}
529 529
 
530 530
 		return $response;
@@ -536,21 +536,21 @@  discard block
 block discarded – undo
536 536
 	 * @since 3.0.0
537 537
 	 */
538 538
 	public function add_payment_method() {
539
-		if ( empty( $_POST['stripe_token'] ) || ! is_user_logged_in() ) {
540
-			wc_add_notice( __( 'There was a problem adding the card.', 'woocommerce-gateway-stripe' ), 'error' );
539
+		if (empty($_POST['stripe_token']) || ! is_user_logged_in()) {
540
+			wc_add_notice(__('There was a problem adding the card.', 'woocommerce-gateway-stripe'), 'error');
541 541
 			return;
542 542
 		}
543 543
 
544
-		$stripe_customer = new WC_Stripe_Customer( get_current_user_id() );
545
-		$result          = $stripe_customer->add_card( wc_clean( $_POST['stripe_token'] ) );
544
+		$stripe_customer = new WC_Stripe_Customer(get_current_user_id());
545
+		$result          = $stripe_customer->add_card(wc_clean($_POST['stripe_token']));
546 546
 
547
-		if ( is_wp_error( $result ) ) {
548
-			throw new Exception( $result->get_error_message() );
547
+		if (is_wp_error($result)) {
548
+			throw new Exception($result->get_error_message());
549 549
 		}
550 550
 
551 551
 		return array(
552 552
 			'result'   => 'success',
553
-			'redirect' => wc_get_endpoint_url( 'payment-methods' ),
553
+			'redirect' => wc_get_endpoint_url('payment-methods'),
554 554
 		);
555 555
 	}
556 556
 
@@ -560,36 +560,36 @@  discard block
 block discarded – undo
560 560
 	 * @param  float $amount
561 561
 	 * @return bool
562 562
 	 */
563
-	public function process_refund( $order_id, $amount = null, $reason = '' ) {
564
-		$order = wc_get_order( $order_id );
563
+	public function process_refund($order_id, $amount = null, $reason = '') {
564
+		$order = wc_get_order($order_id);
565 565
 
566
-		if ( ! $order || ! $order->get_transaction_id() ) {
566
+		if ( ! $order || ! $order->get_transaction_id()) {
567 567
 			return false;
568 568
 		}
569 569
 
570 570
 		$body = array();
571 571
 
572
-		if ( ! is_null( $amount ) ) {
573
-			$body['amount']	= $this->get_stripe_amount( $amount );
572
+		if ( ! is_null($amount)) {
573
+			$body['amount'] = $this->get_stripe_amount($amount);
574 574
 		}
575 575
 
576
-		if ( $reason ) {
576
+		if ($reason) {
577 577
 			$body['metadata'] = array(
578 578
 				'reason'	=> $reason,
579 579
 			);
580 580
 		}
581 581
 
582
-		WC_Stripe::log( "Info: Beginning refund for order $order_id for the amount of {$amount}" );
582
+		WC_Stripe::log("Info: Beginning refund for order $order_id for the amount of {$amount}");
583 583
 
584
-		$response = WC_Stripe_API::request( $body, 'charges/' . $order->get_transaction_id() . '/refunds' );
584
+		$response = WC_Stripe_API::request($body, 'charges/' . $order->get_transaction_id() . '/refunds');
585 585
 
586
-		if ( is_wp_error( $response ) ) {
587
-			WC_Stripe::log( "Error: " . $response->get_error_message() );
586
+		if (is_wp_error($response)) {
587
+			WC_Stripe::log("Error: " . $response->get_error_message());
588 588
 			return $response;
589
-		} elseif ( ! empty( $response->id ) ) {
590
-			$refund_message = sprintf( __( 'Refunded %s - Refund ID: %s - Reason: %s', 'woocommerce-gateway-stripe' ), wc_price( $response->amount / 100 ), $response->id, $reason );
591
-			$order->add_order_note( $refund_message );
592
-			WC_Stripe::log( "Success: " . html_entity_decode( strip_tags( $refund_message ) ) );
589
+		} elseif ( ! empty($response->id)) {
590
+			$refund_message = sprintf(__('Refunded %s - Refund ID: %s - Reason: %s', 'woocommerce-gateway-stripe'), wc_price($response->amount / 100), $response->id, $reason);
591
+			$order->add_order_note($refund_message);
592
+			WC_Stripe::log("Success: " . html_entity_decode(strip_tags($refund_message)));
593 593
 			return true;
594 594
 		}
595 595
 	}
Please login to merge, or discard this patch.
includes/class-wc-gateway-stripe.php 1 patch
Spacing   +288 added lines, -288 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   = sprintf( __( 'Stripe works by adding credit card fields on the checkout and then sending the details to Stripe for verification. <a href="%1$s" target="_blank">Sign up</a> for a Stripe account, and <a href="%2$s" target="_blank">get your Stripe account keys</a>.', 'woocommerce-gateway-stripe' ), 'https://dashboard.stripe.com/register', 'https://dashboard.stripe.com/account/apikeys' );
123
+		$this->method_title         = __('Stripe', 'woocommerce-gateway-stripe');
124
+		$this->method_description   = sprintf(__('Stripe works by adding credit card fields on the checkout and then sending the details to Stripe for verification. <a href="%1$s" target="_blank">Sign up</a> for a Stripe account, and <a href="%2$s" target="_blank">get your Stripe account keys</a>.', 'woocommerce-gateway-stripe'), 'https://dashboard.stripe.com/register', 'https://dashboard.stripe.com/account/apikeys');
125 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,24 +195,24 @@  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
-		if ( 'USD' === get_woocommerce_currency() ) {
206
-			$icon .= '<img src="' . WC_HTTPS::force_https_url( WC()->plugin_url() . '/assets/images/icons/credit-cards/discover' . $ext ) . '" alt="Discover" width="32" ' . $style . ' />';
207
-			$icon .= '<img src="' . WC_HTTPS::force_https_url( WC()->plugin_url() . '/assets/images/icons/credit-cards/jcb' . $ext ) . '" alt="JCB" width="32" ' . $style . ' />';
208
-			$icon .= '<img src="' . WC_HTTPS::force_https_url( WC()->plugin_url() . '/assets/images/icons/credit-cards/diners' . $ext ) . '" alt="Diners" width="32" ' . $style . ' />';
205
+		if ('USD' === get_woocommerce_currency()) {
206
+			$icon .= '<img src="' . WC_HTTPS::force_https_url(WC()->plugin_url() . '/assets/images/icons/credit-cards/discover' . $ext) . '" alt="Discover" width="32" ' . $style . ' />';
207
+			$icon .= '<img src="' . WC_HTTPS::force_https_url(WC()->plugin_url() . '/assets/images/icons/credit-cards/jcb' . $ext) . '" alt="JCB" width="32" ' . $style . ' />';
208
+			$icon .= '<img src="' . WC_HTTPS::force_https_url(WC()->plugin_url() . '/assets/images/icons/credit-cards/diners' . $ext) . '" alt="Diners" width="32" ' . $style . ' />';
209 209
 		}
210 210
 
211
-		if ( $this->bitcoin && $this->stripe_checkout ) {
212
-			$icon .= '<img src="' . WC_HTTPS::force_https_url( plugins_url( '/assets/images/bitcoin' . $ext, WC_STRIPE_MAIN_FILE ) ) . '" alt="Bitcoin" width="24" ' . $style . ' />';
211
+		if ($this->bitcoin && $this->stripe_checkout) {
212
+			$icon .= '<img src="' . WC_HTTPS::force_https_url(plugins_url('/assets/images/bitcoin' . $ext, WC_STRIPE_MAIN_FILE)) . '" alt="Bitcoin" width="24" ' . $style . ' />';
213 213
 		}
214 214
 
215
-		return apply_filters( 'woocommerce_gateway_icon', $icon, $this->id );
215
+		return apply_filters('woocommerce_gateway_icon', $icon, $this->id);
216 216
 	}
217 217
 
218 218
 	/**
@@ -223,11 +223,11 @@  discard block
 block discarded – undo
223 223
 	 *
224 224
 	 * @return float|int
225 225
 	 */
226
-	public function get_stripe_amount( $total, $currency = '' ) {
227
-		if ( ! $currency ) {
226
+	public function get_stripe_amount($total, $currency = '') {
227
+		if ( ! $currency) {
228 228
 			$currency = get_woocommerce_currency();
229 229
 		}
230
-		switch ( strtoupper( $currency ) ) {
230
+		switch (strtoupper($currency)) {
231 231
 			// Zero decimal currencies.
232 232
 			case 'BIF' :
233 233
 			case 'CLP' :
@@ -244,10 +244,10 @@  discard block
 block discarded – undo
244 244
 			case 'XAF' :
245 245
 			case 'XOF' :
246 246
 			case 'XPF' :
247
-				$total = absint( $total );
247
+				$total = absint($total);
248 248
 				break;
249 249
 			default :
250
-				$total = round( $total, 2 ) * 100; // In cents.
250
+				$total = round($total, 2) * 100; // In cents.
251 251
 				break;
252 252
 		}
253 253
 		return $total;
@@ -262,9 +262,9 @@  discard block
 block discarded – undo
262 262
 	public function init_apple_pay() {
263 263
 		if (
264 264
 			is_admin() &&
265
-			isset( $_GET['page'] ) && 'wc-settings' === $_GET['page'] &&
266
-			isset( $_GET['tab'] ) && 'checkout' === $_GET['tab'] &&
267
-			isset( $_GET['section'] ) && 'stripe' === $_GET['section'] &&
265
+			isset($_GET['page']) && 'wc-settings' === $_GET['page'] &&
266
+			isset($_GET['tab']) && 'checkout' === $_GET['tab'] &&
267
+			isset($_GET['section']) && 'stripe' === $_GET['section'] &&
268 268
 			$this->apple_pay
269 269
 		) {
270 270
 			$this->process_apple_pay_verification();
@@ -278,9 +278,9 @@  discard block
 block discarded – undo
278 278
 	 * @version 3.1.0
279 279
 	 * @param string $secret_key
280 280
 	 */
281
-	private function register_apple_pay_domain( $secret_key = '' ) {
282
-		if ( empty( $secret_key ) ) {
283
-			throw new Exception( __( 'Unable to verify domain - missing secret key.', 'woocommerce-gateway-stripe' ) );
281
+	private function register_apple_pay_domain($secret_key = '') {
282
+		if (empty($secret_key)) {
283
+			throw new Exception(__('Unable to verify domain - missing secret key.', 'woocommerce-gateway-stripe'));
284 284
 		}
285 285
 
286 286
 		$endpoint = 'https://api.stripe.com/v1/apple_pay/domains';
@@ -294,21 +294,21 @@  discard block
 block discarded – undo
294 294
 			'Authorization' => 'Bearer ' . $secret_key,
295 295
 		);
296 296
 
297
-		$response = wp_remote_post( $endpoint, array(
297
+		$response = wp_remote_post($endpoint, array(
298 298
 			'headers' => $headers,
299
-			'body'    => http_build_query( $data ),
300
-		) );
299
+			'body'    => http_build_query($data),
300
+		));
301 301
 
302
-		if ( is_wp_error( $response ) ) {
303
-			throw new Exception( sprintf( __( 'Unable to verify domain - %s', 'woocommerce-gateway-stripe' ), $response->get_error_message() ) );
302
+		if (is_wp_error($response)) {
303
+			throw new Exception(sprintf(__('Unable to verify domain - %s', 'woocommerce-gateway-stripe'), $response->get_error_message()));
304 304
 		}
305 305
 
306
-		if ( 200 !== $response['response']['code'] ) {
307
-			$parsed_response = json_decode( $response['body'] );
306
+		if (200 !== $response['response']['code']) {
307
+			$parsed_response = json_decode($response['body']);
308 308
 
309 309
 			$this->apple_pay_verify_notice = $parsed_response->error->message;
310 310
 
311
-			throw new Exception( sprintf( __( 'Unable to verify domain - %s', 'woocommerce-gateway-stripe' ), $parsed_response->error->message ) );
311
+			throw new Exception(sprintf(__('Unable to verify domain - %s', 'woocommerce-gateway-stripe'), $parsed_response->error->message));
312 312
 		}
313 313
 	}
314 314
 
@@ -319,48 +319,48 @@  discard block
 block discarded – undo
319 319
 	 * @version 3.1.0
320 320
 	 */
321 321
 	public function process_apple_pay_verification() {
322
-		$gateway_settings = get_option( 'woocommerce_stripe_settings', '' );
322
+		$gateway_settings = get_option('woocommerce_stripe_settings', '');
323 323
 
324 324
 		try {
325
-			$path     = untrailingslashit( preg_replace( "!${_SERVER['SCRIPT_NAME']}$!", '', $_SERVER['SCRIPT_FILENAME'] ) );
325
+			$path     = untrailingslashit(preg_replace("!${_SERVER['SCRIPT_NAME']}$!", '', $_SERVER['SCRIPT_FILENAME']));
326 326
 			$dir      = '.well-known';
327 327
 			$file     = 'apple-developer-merchantid-domain-association';
328 328
 			$fullpath = $path . '/' . $dir . '/' . $file;
329 329
 
330
-			if ( ! empty( $gateway_settings['apple_pay_domain_set'] ) && 'yes' === $gateway_settings['apple_pay_domain_set'] && file_exists( $fullpath ) ) {
330
+			if ( ! empty($gateway_settings['apple_pay_domain_set']) && 'yes' === $gateway_settings['apple_pay_domain_set'] && file_exists($fullpath)) {
331 331
 				return;
332 332
 			}
333 333
 
334
-			if ( ! file_exists( $path . '/' . $dir ) ) {
335
-				if ( ! @mkdir( $path . '/' . $dir, 0755 ) ) {
336
-					throw new Exception( __( 'Unable to create domain association folder to domain root.', 'woocommerce-gateway-stripe' ) );
334
+			if ( ! file_exists($path . '/' . $dir)) {
335
+				if ( ! @mkdir($path . '/' . $dir, 0755)) {
336
+					throw new Exception(__('Unable to create domain association folder to domain root.', 'woocommerce-gateway-stripe'));
337 337
 				}
338 338
 			}
339 339
 
340
-			if ( ! file_exists( $fullpath ) ) {
341
-				if ( ! @copy( WC_STRIPE_PLUGIN_PATH . '/' . $file, $fullpath ) ) {
342
-					throw new Exception( __( 'Unable to copy domain association file to domain root.', 'woocommerce-gateway-stripe' ) );
340
+			if ( ! file_exists($fullpath)) {
341
+				if ( ! @copy(WC_STRIPE_PLUGIN_PATH . '/' . $file, $fullpath)) {
342
+					throw new Exception(__('Unable to copy domain association file to domain root.', 'woocommerce-gateway-stripe'));
343 343
 				}
344 344
 			}
345 345
 
346 346
 			// At this point then the domain association folder and file should be available.
347 347
 			// Proceed to verify/and or verify again.
348
-			$this->register_apple_pay_domain( $this->secret_key );
348
+			$this->register_apple_pay_domain($this->secret_key);
349 349
 
350 350
 			// No errors to this point, verification success!
351 351
 			$gateway_settings['apple_pay_domain_set'] = 'yes';
352 352
 			$this->apple_pay_domain_set = true;
353 353
 
354
-			update_option( 'woocommerce_stripe_settings', $gateway_settings );
354
+			update_option('woocommerce_stripe_settings', $gateway_settings);
355 355
 
356
-			$this->log( __( 'Your domain has been verified with Apple Pay!', 'woocommerce-gateway-stripe' ) );
356
+			$this->log(__('Your domain has been verified with Apple Pay!', 'woocommerce-gateway-stripe'));
357 357
 
358
-		} catch ( Exception $e ) {
358
+		} catch (Exception $e) {
359 359
 			$gateway_settings['apple_pay_domain_set'] = 'no';
360 360
 
361
-			update_option( 'woocommerce_stripe_settings', $gateway_settings );
361
+			update_option('woocommerce_stripe_settings', $gateway_settings);
362 362
 
363
-			$this->log( sprintf( __( 'Error: %s', 'woocommerce-gateway-stripe' ), $e->getMessage() ) );
363
+			$this->log(sprintf(__('Error: %s', 'woocommerce-gateway-stripe'), $e->getMessage()));
364 364
 		}
365 365
 	}
366 366
 
@@ -368,11 +368,11 @@  discard block
 block discarded – undo
368 368
 	 * Check if SSL is enabled and notify the user
369 369
 	 */
370 370
 	public function admin_notices() {
371
-		if ( 'no' === $this->enabled ) {
371
+		if ('no' === $this->enabled) {
372 372
 			return;
373 373
 		}
374 374
 
375
-		if ( $this->apple_pay && ! empty( $this->apple_pay_verify_notice ) ) {
375
+		if ($this->apple_pay && ! empty($this->apple_pay_verify_notice)) {
376 376
 			$allowed_html = array(
377 377
 				'a' => array(
378 378
 					'href' => array(),
@@ -380,7 +380,7 @@  discard block
 block discarded – undo
380 380
 				),
381 381
 			);
382 382
 
383
-			echo '<div class="error stripe-apple-pay-message"><p>' . wp_kses( make_clickable( $this->apple_pay_verify_notice ), $allowed_html ) . '</p></div>';
383
+			echo '<div class="error stripe-apple-pay-message"><p>' . wp_kses(make_clickable($this->apple_pay_verify_notice), $allowed_html) . '</p></div>';
384 384
 		}
385 385
 
386 386
 		/**
@@ -388,13 +388,13 @@  discard block
 block discarded – undo
388 388
 		 * when setting screen is displayed. So if domain verification is not set,
389 389
 		 * something went wrong so lets notify user.
390 390
 		 */
391
-		if ( ! empty( $this->secret_key ) && $this->apple_pay && ! $this->apple_pay_domain_set ) {
392
-			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>';
391
+		if ( ! empty($this->secret_key) && $this->apple_pay && ! $this->apple_pay_domain_set) {
392
+			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>';
393 393
 		}
394 394
 
395 395
 		// Show message if enabled and FORCE SSL is disabled and WordpressHTTPS plugin is not detected.
396
-		if ( ( function_exists( 'wc_site_is_https' ) && ! wc_site_is_https() ) && ( 'no' === get_option( 'woocommerce_force_ssl_checkout' ) && ! class_exists( 'WordPressHTTPS' ) ) ) {
397
-			echo '<div class="error stripe-ssl-message"><p>' . sprintf( __( 'Stripe is enabled, but the <a href="%1$s">force SSL option</a> is disabled; your checkout may not be secure! Please enable SSL and ensure your server has a valid <a href="%2$s" target="_blank">SSL certificate</a> - Stripe will only work in test mode.', 'woocommerce-gateway-stripe' ), admin_url( 'admin.php?page=wc-settings&tab=checkout' ), 'https://en.wikipedia.org/wiki/Transport_Layer_Security' ) . '</p></div>';
396
+		if ((function_exists('wc_site_is_https') && ! wc_site_is_https()) && ('no' === get_option('woocommerce_force_ssl_checkout') && ! class_exists('WordPressHTTPS'))) {
397
+			echo '<div class="error stripe-ssl-message"><p>' . sprintf(__('Stripe is enabled, but the <a href="%1$s">force SSL option</a> is disabled; your checkout may not be secure! Please enable SSL and ensure your server has a valid <a href="%2$s" target="_blank">SSL certificate</a> - Stripe will only work in test mode.', 'woocommerce-gateway-stripe'), admin_url('admin.php?page=wc-settings&tab=checkout'), 'https://en.wikipedia.org/wiki/Transport_Layer_Security') . '</p></div>';
398 398
 		}
399 399
 	}
400 400
 
@@ -402,11 +402,11 @@  discard block
 block discarded – undo
402 402
 	 * Check if this gateway is enabled
403 403
 	 */
404 404
 	public function is_available() {
405
-		if ( 'yes' === $this->enabled ) {
406
-			if ( ! $this->testmode && is_checkout() && ! is_ssl() ) {
405
+		if ('yes' === $this->enabled) {
406
+			if ( ! $this->testmode && is_checkout() && ! is_ssl()) {
407 407
 				return false;
408 408
 			}
409
-			if ( ! $this->secret_key || ! $this->publishable_key ) {
409
+			if ( ! $this->secret_key || ! $this->publishable_key) {
410 410
 				return false;
411 411
 			}
412 412
 			return true;
@@ -418,7 +418,7 @@  discard block
 block discarded – undo
418 418
 	 * Initialise Gateway Settings Form Fields
419 419
 	 */
420 420
 	public function init_form_fields() {
421
-		$this->form_fields = include( 'settings-stripe.php' );
421
+		$this->form_fields = include('settings-stripe.php');
422 422
 	}
423 423
 
424 424
 	/**
@@ -426,55 +426,55 @@  discard block
 block discarded – undo
426 426
 	 */
427 427
 	public function payment_fields() {
428 428
 		$user                 = wp_get_current_user();
429
-		$display_tokenization = $this->supports( 'tokenization' ) && is_checkout() && $this->saved_cards;
429
+		$display_tokenization = $this->supports('tokenization') && is_checkout() && $this->saved_cards;
430 430
 		$total                = WC()->cart->total;
431 431
 
432 432
 		// If paying from order, we need to get total from order not cart.
433
-		if ( isset( $_GET['pay_for_order'] ) && ! empty( $_GET['key'] ) ) {
434
-			$order = wc_get_order( wc_get_order_id_by_order_key( wc_clean( $_GET['key'] ) ) );
433
+		if (isset($_GET['pay_for_order']) && ! empty($_GET['key'])) {
434
+			$order = wc_get_order(wc_get_order_id_by_order_key(wc_clean($_GET['key'])));
435 435
 			$total = $order->get_total();
436 436
 		}
437 437
 
438
-		if ( $user->ID ) {
439
-			$user_email = get_user_meta( $user->ID, 'billing_email', true );
438
+		if ($user->ID) {
439
+			$user_email = get_user_meta($user->ID, 'billing_email', true);
440 440
 			$user_email = $user_email ? $user_email : $user->user_email;
441 441
 		} else {
442 442
 			$user_email = '';
443 443
 		}
444 444
 
445
-		if ( is_add_payment_method_page() ) {
446
-			$pay_button_text = __( 'Add Card', 'woocommerce-gateway-stripe' );
447
-			$total        = '';
445
+		if (is_add_payment_method_page()) {
446
+			$pay_button_text = __('Add Card', 'woocommerce-gateway-stripe');
447
+			$total = '';
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 ( apply_filters( 'wc_stripe_display_save_payment_method_checkbox', $display_tokenization ) ) {
477
+			if (apply_filters('wc_stripe_display_save_payment_method_checkbox', $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/checkout.js', '', WC_STRIPE_VERSION, 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/checkout.js', '', WC_STRIPE_VERSION, 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/', '', '2.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/', '', '2.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,38 +648,38 @@  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 );
653
-		$force_customer  = apply_filters( 'wc_stripe_force_customer_creation', $force_customer, $stripe_customer );
651
+	protected function get_source($user_id, $force_customer = false) {
652
+		$stripe_customer = new WC_Stripe_Customer($user_id);
653
+		$force_customer  = apply_filters('wc_stripe_force_customer_creation', $force_customer, $stripe_customer);
654 654
 		$stripe_source   = false;
655 655
 		$token_id        = false;
656 656
 
657 657
 		// New CC info was entered and we have a new token to process
658
-		if ( isset( $_POST['stripe_token'] ) ) {
659
-			$stripe_token     = wc_clean( $_POST['stripe_token'] );
660
-			$maybe_saved_card = isset( $_POST['wc-stripe-new-payment-method'] ) && ! empty( $_POST['wc-stripe-new-payment-method'] );
658
+		if (isset($_POST['stripe_token'])) {
659
+			$stripe_token     = wc_clean($_POST['stripe_token']);
660
+			$maybe_saved_card = isset($_POST['wc-stripe-new-payment-method']) && ! empty($_POST['wc-stripe-new-payment-method']);
661 661
 
662 662
 			// This is true if the user wants to store the card to their account.
663
-			if ( ( $user_id && $this->saved_cards && $maybe_saved_card ) || $force_customer ) {
664
-				$stripe_source = $stripe_customer->add_card( $stripe_token );
663
+			if (($user_id && $this->saved_cards && $maybe_saved_card) || $force_customer) {
664
+				$stripe_source = $stripe_customer->add_card($stripe_token);
665 665
 
666
-				if ( is_wp_error( $stripe_source ) ) {
667
-					throw new Exception( $stripe_source->get_error_message() );
666
+				if (is_wp_error($stripe_source)) {
667
+					throw new Exception($stripe_source->get_error_message());
668 668
 				}
669 669
 			} else {
670 670
 				// Not saving token, so don't define customer either.
671 671
 				$stripe_source   = $stripe_token;
672 672
 				$stripe_customer = false;
673 673
 			}
674
-		} elseif ( isset( $_POST['wc-stripe-payment-token'] ) && 'new' !== $_POST['wc-stripe-payment-token'] ) {
674
+		} elseif (isset($_POST['wc-stripe-payment-token']) && 'new' !== $_POST['wc-stripe-payment-token']) {
675 675
 			// Use an existing token, and then process the payment
676 676
 
677
-			$token_id = wc_clean( $_POST['wc-stripe-payment-token'] );
678
-			$token    = WC_Payment_Tokens::get( $token_id );
677
+			$token_id = wc_clean($_POST['wc-stripe-payment-token']);
678
+			$token    = WC_Payment_Tokens::get($token_id);
679 679
 
680
-			if ( ! $token || $token->get_user_id() !== get_current_user_id() ) {
681
-				WC()->session->set( 'refresh_totals', true );
682
-				throw new Exception( __( 'Invalid payment method. Please input a new card number.', 'woocommerce-gateway-stripe' ) );
680
+			if ( ! $token || $token->get_user_id() !== get_current_user_id()) {
681
+				WC()->session->set('refresh_totals', true);
682
+				throw new Exception(__('Invalid payment method. Please input a new card number.', 'woocommerce-gateway-stripe'));
683 683
 			}
684 684
 
685 685
 			$stripe_source = $token->get_token();
@@ -703,19 +703,19 @@  discard block
 block discarded – undo
703 703
 	 * @param object $order
704 704
 	 * @return object
705 705
 	 */
706
-	protected function get_order_source( $order = null ) {
706
+	protected function get_order_source($order = null) {
707 707
 		$stripe_customer = new WC_Stripe_Customer();
708 708
 		$stripe_source   = false;
709 709
 		$token_id        = false;
710 710
 
711
-		if ( $order ) {
712
-			$order_id = version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->id : $order->get_id();
711
+		if ($order) {
712
+			$order_id = version_compare(WC_VERSION, '3.0.0', '<') ? $order->id : $order->get_id();
713 713
 
714
-			if ( $meta_value = get_post_meta( $order_id, '_stripe_customer_id', true ) ) {
715
-				$stripe_customer->set_id( $meta_value );
714
+			if ($meta_value = get_post_meta($order_id, '_stripe_customer_id', true)) {
715
+				$stripe_customer->set_id($meta_value);
716 716
 			}
717 717
 
718
-			if ( $meta_value = get_post_meta( $order_id, '_stripe_card_id', true ) ) {
718
+			if ($meta_value = get_post_meta($order_id, '_stripe_card_id', true)) {
719 719
 				$stripe_source = $meta_value;
720 720
 			}
721 721
 		}
@@ -738,60 +738,60 @@  discard block
 block discarded – undo
738 738
 	 *
739 739
 	 * @return array|void
740 740
 	 */
741
-	public function process_payment( $order_id, $retry = true, $force_customer = false ) {
741
+	public function process_payment($order_id, $retry = true, $force_customer = false) {
742 742
 		try {
743
-			$order  = wc_get_order( $order_id );
744
-			$source = $this->get_source( get_current_user_id(), $force_customer );
743
+			$order  = wc_get_order($order_id);
744
+			$source = $this->get_source(get_current_user_id(), $force_customer);
745 745
 
746
-			if ( empty( $source->source ) && empty( $source->customer ) ) {
747
-				$error_msg = __( 'Please enter your card details to make a payment.', 'woocommerce-gateway-stripe' );
748
-				$error_msg .= ' ' . __( 'Developers: Please make sure that you are including jQuery and there are no JavaScript errors on the page.', 'woocommerce-gateway-stripe' );
749
-				throw new Exception( $error_msg );
746
+			if (empty($source->source) && empty($source->customer)) {
747
+				$error_msg = __('Please enter your card details to make a payment.', 'woocommerce-gateway-stripe');
748
+				$error_msg .= ' ' . __('Developers: Please make sure that you are including jQuery and there are no JavaScript errors on the page.', 'woocommerce-gateway-stripe');
749
+				throw new Exception($error_msg);
750 750
 			}
751 751
 
752 752
 			// Store source to order meta.
753
-			$this->save_source( $order, $source );
753
+			$this->save_source($order, $source);
754 754
 
755 755
 			// Result from Stripe API request.
756 756
 			$response = null;
757 757
 
758 758
 			// Handle payment.
759
-			if ( $order->get_total() > 0 ) {
759
+			if ($order->get_total() > 0) {
760 760
 
761
-				if ( $order->get_total() * 100 < WC_Stripe::get_minimum_amount() ) {
762
-					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 ) ) );
761
+				if ($order->get_total() * 100 < WC_Stripe::get_minimum_amount()) {
762
+					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)));
763 763
 				}
764 764
 
765
-				$this->log( "Info: Begin processing payment for order $order_id for the amount of {$order->get_total()}" );
765
+				$this->log("Info: Begin processing payment for order $order_id for the amount of {$order->get_total()}");
766 766
 
767 767
 				// Make the request.
768
-				$response = WC_Stripe_API::request( $this->generate_payment_request( $order, $source ) );
768
+				$response = WC_Stripe_API::request($this->generate_payment_request($order, $source));
769 769
 
770
-				if ( is_wp_error( $response ) ) {
770
+				if (is_wp_error($response)) {
771 771
 					// Customer param wrong? The user may have been deleted on stripe's end. Remove customer_id. Can be retried without.
772
-					if ( 'customer' === $response->get_error_code() && $retry ) {
773
-						delete_user_meta( get_current_user_id(), '_stripe_customer_id' );
774
-						return $this->process_payment( $order_id, false, $force_customer );
772
+					if ('customer' === $response->get_error_code() && $retry) {
773
+						delete_user_meta(get_current_user_id(), '_stripe_customer_id');
774
+						return $this->process_payment($order_id, false, $force_customer);
775 775
 						// Source param wrong? The CARD may have been deleted on stripe's end. Remove token and show message.
776
-					} elseif ( 'source' === $response->get_error_code() && $source->token_id ) {
777
-						$token = WC_Payment_Tokens::get( $source->token_id );
776
+					} elseif ('source' === $response->get_error_code() && $source->token_id) {
777
+						$token = WC_Payment_Tokens::get($source->token_id);
778 778
 						$token->delete();
779
-						$message = __( 'This card is no longer available and has been removed.', 'woocommerce-gateway-stripe' );
780
-						$order->add_order_note( $message );
781
-						throw new Exception( $message );
779
+						$message = __('This card is no longer available and has been removed.', 'woocommerce-gateway-stripe');
780
+						$order->add_order_note($message);
781
+						throw new Exception($message);
782 782
 					}
783 783
 
784 784
 					$localized_messages = $this->get_localized_messages();
785 785
 
786
-					$message = isset( $localized_messages[ $response->get_error_code() ] ) ? $localized_messages[ $response->get_error_code() ] : $response->get_error_message();
786
+					$message = isset($localized_messages[$response->get_error_code()]) ? $localized_messages[$response->get_error_code()] : $response->get_error_message();
787 787
 
788
-					$order->add_order_note( $message );
788
+					$order->add_order_note($message);
789 789
 
790
-					throw new Exception( $message );
790
+					throw new Exception($message);
791 791
 				}
792 792
 
793 793
 				// Process valid response.
794
-				$this->process_response( $response, $order );
794
+				$this->process_response($response, $order);
795 795
 			} else {
796 796
 				$order->payment_complete();
797 797
 			}
@@ -799,23 +799,23 @@  discard block
 block discarded – undo
799 799
 			// Remove cart.
800 800
 			WC()->cart->empty_cart();
801 801
 
802
-			do_action( 'wc_gateway_stripe_process_payment', $response, $order );
802
+			do_action('wc_gateway_stripe_process_payment', $response, $order);
803 803
 
804 804
 			// Return thank you page redirect.
805 805
 			return array(
806 806
 				'result'   => 'success',
807
-				'redirect' => $this->get_return_url( $order ),
807
+				'redirect' => $this->get_return_url($order),
808 808
 			);
809 809
 
810
-		} catch ( Exception $e ) {
811
-			wc_add_notice( $e->getMessage(), 'error' );
812
-			$this->log( sprintf( __( 'Error: %s', 'woocommerce-gateway-stripe' ), $e->getMessage() ) );
810
+		} catch (Exception $e) {
811
+			wc_add_notice($e->getMessage(), 'error');
812
+			$this->log(sprintf(__('Error: %s', 'woocommerce-gateway-stripe'), $e->getMessage()));
813 813
 
814
-			if ( $order->has_status( array( 'pending', 'failed' ) ) ) {
815
-				$this->send_failed_order_email( $order_id );
814
+			if ($order->has_status(array('pending', 'failed'))) {
815
+				$this->send_failed_order_email($order_id);
816 816
 			}
817 817
 
818
-			do_action( 'wc_gateway_stripe_process_payment_error', $e, $order );
818
+			do_action('wc_gateway_stripe_process_payment_error', $e, $order);
819 819
 
820 820
 			return array(
821 821
 				'result'   => 'fail',
@@ -830,18 +830,18 @@  discard block
 block discarded – undo
830 830
 	 * @param WC_Order $order For to which the source applies.
831 831
 	 * @param stdClass $source Source information.
832 832
 	 */
833
-	protected function save_source( $order, $source ) {
834
-		$order_id = version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->id : $order->get_id();
833
+	protected function save_source($order, $source) {
834
+		$order_id = version_compare(WC_VERSION, '3.0.0', '<') ? $order->id : $order->get_id();
835 835
 
836 836
 		// Store source in the order.
837
-		if ( $source->customer ) {
838
-			version_compare( WC_VERSION, '3.0.0', '<' ) ? update_post_meta( $order_id, '_stripe_customer_id', $source->customer ) : $order->update_meta_data( '_stripe_customer_id', $source->customer );
837
+		if ($source->customer) {
838
+			version_compare(WC_VERSION, '3.0.0', '<') ? update_post_meta($order_id, '_stripe_customer_id', $source->customer) : $order->update_meta_data('_stripe_customer_id', $source->customer);
839 839
 		}
840
-		if ( $source->source ) {
841
-			version_compare( WC_VERSION, '3.0.0', '<' ) ? update_post_meta( $order_id, '_stripe_card_id', $source->source ) : $order->update_meta_data( '_stripe_card_id', $source->source );
840
+		if ($source->source) {
841
+			version_compare(WC_VERSION, '3.0.0', '<') ? update_post_meta($order_id, '_stripe_card_id', $source->source) : $order->update_meta_data('_stripe_card_id', $source->source);
842 842
 		}
843 843
 
844
-		if ( is_callable( array( $order, 'save' ) ) ) {
844
+		if (is_callable(array($order, 'save'))) {
845 845
 			$order->save();
846 846
 		}
847 847
 	}
@@ -849,44 +849,44 @@  discard block
 block discarded – undo
849 849
 	/**
850 850
 	 * Store extra meta data for an order from a Stripe Response.
851 851
 	 */
852
-	public function process_response( $response, $order ) {
853
-		$this->log( 'Processing response: ' . print_r( $response, true ) );
852
+	public function process_response($response, $order) {
853
+		$this->log('Processing response: ' . print_r($response, true));
854 854
 
855
-		$order_id = version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->id : $order->get_id();
855
+		$order_id = version_compare(WC_VERSION, '3.0.0', '<') ? $order->id : $order->get_id();
856 856
 
857 857
 		// Store charge data
858
-		update_post_meta( $order_id, '_stripe_charge_id', $response->id );
859
-		update_post_meta( $order_id, '_stripe_charge_captured', $response->captured ? 'yes' : 'no' );
858
+		update_post_meta($order_id, '_stripe_charge_id', $response->id);
859
+		update_post_meta($order_id, '_stripe_charge_captured', $response->captured ? 'yes' : 'no');
860 860
 
861 861
 		// Store other data such as fees
862
-		if ( isset( $response->balance_transaction ) && isset( $response->balance_transaction->fee ) ) {
862
+		if (isset($response->balance_transaction) && isset($response->balance_transaction->fee)) {
863 863
 			// Fees and Net needs to both come from Stripe to be accurate as the returned
864 864
 			// values are in the local currency of the Stripe account, not from WC.
865
-			$fee = ! empty( $response->balance_transaction->fee ) ? WC_Stripe::format_number( $response->balance_transaction, 'fee' ) : 0;
866
-			$net = ! empty( $response->balance_transaction->net ) ? WC_Stripe::format_number( $response->balance_transaction, 'net' ) : 0;
867
-			update_post_meta( $order_id, 'Stripe Fee', $fee );
868
-			update_post_meta( $order_id, 'Net Revenue From Stripe', $net );
865
+			$fee = ! empty($response->balance_transaction->fee) ? WC_Stripe::format_number($response->balance_transaction, 'fee') : 0;
866
+			$net = ! empty($response->balance_transaction->net) ? WC_Stripe::format_number($response->balance_transaction, 'net') : 0;
867
+			update_post_meta($order_id, 'Stripe Fee', $fee);
868
+			update_post_meta($order_id, 'Net Revenue From Stripe', $net);
869 869
 		}
870 870
 
871
-		if ( $response->captured ) {
872
-			$order->payment_complete( $response->id );
871
+		if ($response->captured) {
872
+			$order->payment_complete($response->id);
873 873
 
874
-			$message = sprintf( __( 'Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe' ), $response->id );
875
-			$order->add_order_note( $message );
876
-			$this->log( 'Success: ' . $message );
874
+			$message = sprintf(__('Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe'), $response->id);
875
+			$order->add_order_note($message);
876
+			$this->log('Success: ' . $message);
877 877
 
878 878
 		} else {
879
-			update_post_meta( $order_id, '_transaction_id', $response->id, true );
879
+			update_post_meta($order_id, '_transaction_id', $response->id, true);
880 880
 
881
-			if ( $order->has_status( array( 'pending', 'failed' ) ) ) {
882
-				version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->reduce_order_stock() : wc_reduce_stock_levels( $order_id );
881
+			if ($order->has_status(array('pending', 'failed'))) {
882
+				version_compare(WC_VERSION, '3.0.0', '<') ? $order->reduce_order_stock() : wc_reduce_stock_levels($order_id);
883 883
 			}
884 884
 
885
-			$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 ) );
886
-			$this->log( "Successful auth: $response->id" );
885
+			$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));
886
+			$this->log("Successful auth: $response->id");
887 887
 		}
888 888
 
889
-		do_action( 'wc_gateway_stripe_process_response', $response, $order );
889
+		do_action('wc_gateway_stripe_process_response', $response, $order);
890 890
 
891 891
 		return $response;
892 892
 	}
@@ -897,32 +897,32 @@  discard block
 block discarded – undo
897 897
 	 * @since 3.0.0
898 898
 	 */
899 899
 	public function add_payment_method() {
900
-		if ( empty( $_POST['stripe_token'] ) || ! is_user_logged_in() ) {
901
-			wc_add_notice( __( 'There was a problem adding the card.', 'woocommerce-gateway-stripe' ), 'error' );
900
+		if (empty($_POST['stripe_token']) || ! is_user_logged_in()) {
901
+			wc_add_notice(__('There was a problem adding the card.', 'woocommerce-gateway-stripe'), 'error');
902 902
 			return;
903 903
 		}
904 904
 
905
-		$stripe_customer = new WC_Stripe_Customer( get_current_user_id() );
906
-		$card            = $stripe_customer->add_card( wc_clean( $_POST['stripe_token'] ) );
905
+		$stripe_customer = new WC_Stripe_Customer(get_current_user_id());
906
+		$card            = $stripe_customer->add_card(wc_clean($_POST['stripe_token']));
907 907
 
908
-		if ( is_wp_error( $card ) ) {
908
+		if (is_wp_error($card)) {
909 909
 			$localized_messages = $this->get_localized_messages();
910
-			$error_msg = __( 'There was a problem adding the card.', 'woocommerce-gateway-stripe' );
910
+			$error_msg = __('There was a problem adding the card.', 'woocommerce-gateway-stripe');
911 911
 
912 912
 			// loop through the errors to find matching localized message
913
-			foreach ( $card->errors as $error => $msg ) {
914
-				if ( isset( $localized_messages[ $error ] ) ) {
915
-					$error_msg = $localized_messages[ $error ];
913
+			foreach ($card->errors as $error => $msg) {
914
+				if (isset($localized_messages[$error])) {
915
+					$error_msg = $localized_messages[$error];
916 916
 				}
917 917
 			}
918 918
 
919
-			wc_add_notice( $error_msg, 'error' );
919
+			wc_add_notice($error_msg, 'error');
920 920
 			return;
921 921
 		}
922 922
 
923 923
 		return array(
924 924
 			'result'   => 'success',
925
-			'redirect' => wc_get_endpoint_url( 'payment-methods' ),
925
+			'redirect' => wc_get_endpoint_url('payment-methods'),
926 926
 		);
927 927
 	}
928 928
 
@@ -932,36 +932,36 @@  discard block
 block discarded – undo
932 932
 	 * @param  float $amount
933 933
 	 * @return bool
934 934
 	 */
935
-	public function process_refund( $order_id, $amount = null, $reason = '' ) {
936
-		$order = wc_get_order( $order_id );
935
+	public function process_refund($order_id, $amount = null, $reason = '') {
936
+		$order = wc_get_order($order_id);
937 937
 
938
-		if ( ! $order || ! $order->get_transaction_id() ) {
938
+		if ( ! $order || ! $order->get_transaction_id()) {
939 939
 			return false;
940 940
 		}
941 941
 
942 942
 		$body = array();
943 943
 
944
-		if ( ! is_null( $amount ) ) {
945
-			$body['amount']	= $this->get_stripe_amount( $amount );
944
+		if ( ! is_null($amount)) {
945
+			$body['amount'] = $this->get_stripe_amount($amount);
946 946
 		}
947 947
 
948
-		if ( $reason ) {
948
+		if ($reason) {
949 949
 			$body['metadata'] = array(
950 950
 				'reason'	=> $reason,
951 951
 			);
952 952
 		}
953 953
 
954
-		$this->log( "Info: Beginning refund for order $order_id for the amount of {$amount}" );
954
+		$this->log("Info: Beginning refund for order $order_id for the amount of {$amount}");
955 955
 
956
-		$response = WC_Stripe_API::request( $body, 'charges/' . $order->get_transaction_id() . '/refunds' );
956
+		$response = WC_Stripe_API::request($body, 'charges/' . $order->get_transaction_id() . '/refunds');
957 957
 
958
-		if ( is_wp_error( $response ) ) {
959
-			$this->log( 'Error: ' . $response->get_error_message() );
958
+		if (is_wp_error($response)) {
959
+			$this->log('Error: ' . $response->get_error_message());
960 960
 			return $response;
961
-		} elseif ( ! empty( $response->id ) ) {
962
-			$refund_message = sprintf( __( 'Refunded %1$s - Refund ID: %2$s - Reason: %3$s', 'woocommerce-gateway-stripe' ), wc_price( $response->amount / 100 ), $response->id, $reason );
963
-			$order->add_order_note( $refund_message );
964
-			$this->log( 'Success: ' . html_entity_decode( strip_tags( $refund_message ) ) );
961
+		} elseif ( ! empty($response->id)) {
962
+			$refund_message = sprintf(__('Refunded %1$s - Refund ID: %2$s - Reason: %3$s', 'woocommerce-gateway-stripe'), wc_price($response->amount / 100), $response->id, $reason);
963
+			$order->add_order_note($refund_message);
964
+			$this->log('Success: ' . html_entity_decode(strip_tags($refund_message)));
965 965
 			return true;
966 966
 		}
967 967
 	}
@@ -974,10 +974,10 @@  discard block
 block discarded – undo
974 974
 	 * @param int $order_id
975 975
 	 * @return null
976 976
 	 */
977
-	public function send_failed_order_email( $order_id ) {
977
+	public function send_failed_order_email($order_id) {
978 978
 		$emails = WC()->mailer()->get_emails();
979
-		if ( ! empty( $emails ) && ! empty( $order_id ) ) {
980
-			$emails['WC_Email_Failed_Order']->trigger( $order_id );
979
+		if ( ! empty($emails) && ! empty($order_id)) {
980
+			$emails['WC_Email_Failed_Order']->trigger($order_id);
981 981
 		}
982 982
 	}
983 983
 
@@ -989,9 +989,9 @@  discard block
 block discarded – undo
989 989
 	 *
990 990
 	 * @param string $message
991 991
 	 */
992
-	public function log( $message ) {
993
-		if ( $this->logging ) {
994
-			WC_Stripe::log( $message );
992
+	public function log($message) {
993
+		if ($this->logging) {
994
+			WC_Stripe::log($message);
995 995
 		}
996 996
 	}
997 997
 }
Please login to merge, or discard this patch.