Completed
Push — master ( 978eca...29f640 )
by Roy
02:33
created
includes/legacy/class-wc-gateway-stripe.php 1 patch
Spacing   +186 added lines, -186 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) {
2
+if ( ! defined('ABSPATH')) {
3 3
 	exit;
4 4
 }
5 5
 
@@ -15,8 +15,8 @@  discard block
 block discarded – undo
15 15
 	 */
16 16
 	public function __construct() {
17 17
 		$this->id                   = 'stripe';
18
-		$this->method_title         = __( 'Stripe', 'woocommerce-gateway-stripe' );
19
-		$this->method_description   = __( 'Stripe works by adding credit card fields on the checkout and then sending the details to Stripe for verification.', 'woocommerce-gateway-stripe' );
18
+		$this->method_title         = __('Stripe', 'woocommerce-gateway-stripe');
19
+		$this->method_description   = __('Stripe works by adding credit card fields on the checkout and then sending the details to Stripe for verification.', 'woocommerce-gateway-stripe');
20 20
 		$this->has_fields           = true;
21 21
 		$this->view_transaction_url = 'https://dashboard.stripe.com/payments/%s';
22 22
 		$this->supports             = array(
@@ -42,35 +42,35 @@  discard block
 block discarded – undo
42 42
 		$this->init_settings();
43 43
 
44 44
 		// Get setting values.
45
-		$this->title                  = $this->get_option( 'title' );
46
-		$this->description            = $this->get_option( 'description' );
47
-		$this->enabled                = $this->get_option( 'enabled' );
48
-		$this->testmode               = 'yes' === $this->get_option( 'testmode' );
49
-		$this->capture                = 'yes' === $this->get_option( 'capture', 'yes' );
50
-		$this->stripe_checkout        = 'yes' === $this->get_option( 'stripe_checkout' );
51
-		$this->stripe_checkout_locale = $this->get_option( 'stripe_checkout_locale' );
52
-		$this->stripe_checkout_image  = $this->get_option( 'stripe_checkout_image', '' );
53
-		$this->saved_cards            = 'yes' === $this->get_option( 'saved_cards' );
54
-		$this->secret_key             = $this->testmode ? $this->get_option( 'test_secret_key' ) : $this->get_option( 'secret_key' );
55
-		$this->publishable_key        = $this->testmode ? $this->get_option( 'test_publishable_key' ) : $this->get_option( 'publishable_key' );
56
-		$this->bitcoin                = 'USD' === strtoupper( get_woocommerce_currency() ) && 'yes' === $this->get_option( 'stripe_bitcoin' );
57
-		$this->logging                = 'yes' === $this->get_option( 'logging' );
58
-
59
-		if ( $this->stripe_checkout ) {
60
-			$this->order_button_text = __( 'Continue to payment', 'woocommerce-gateway-stripe' );
45
+		$this->title                  = $this->get_option('title');
46
+		$this->description            = $this->get_option('description');
47
+		$this->enabled                = $this->get_option('enabled');
48
+		$this->testmode               = 'yes' === $this->get_option('testmode');
49
+		$this->capture                = 'yes' === $this->get_option('capture', 'yes');
50
+		$this->stripe_checkout        = 'yes' === $this->get_option('stripe_checkout');
51
+		$this->stripe_checkout_locale = $this->get_option('stripe_checkout_locale');
52
+		$this->stripe_checkout_image  = $this->get_option('stripe_checkout_image', '');
53
+		$this->saved_cards            = 'yes' === $this->get_option('saved_cards');
54
+		$this->secret_key             = $this->testmode ? $this->get_option('test_secret_key') : $this->get_option('secret_key');
55
+		$this->publishable_key        = $this->testmode ? $this->get_option('test_publishable_key') : $this->get_option('publishable_key');
56
+		$this->bitcoin                = 'USD' === strtoupper(get_woocommerce_currency()) && 'yes' === $this->get_option('stripe_bitcoin');
57
+		$this->logging                = 'yes' === $this->get_option('logging');
58
+
59
+		if ($this->stripe_checkout) {
60
+			$this->order_button_text = __('Continue to payment', 'woocommerce-gateway-stripe');
61 61
 		}
62 62
 
63
-		if ( $this->testmode ) {
64
-			$this->description .= ' ' . sprintf( __( 'TEST MODE ENABLED. In test mode, you can use the card number 4242424242424242 with any CVC and a valid expiration date or check the documentation "<a href="%s">Testing Stripe</a>" for more card numbers.', 'woocommerce-gateway-stripe' ), 'https://stripe.com/docs/testing' );
65
-			$this->description  = trim( $this->description );
63
+		if ($this->testmode) {
64
+			$this->description .= ' ' . sprintf(__('TEST MODE ENABLED. In test mode, you can use the card number 4242424242424242 with any CVC and a valid expiration date or check the documentation "<a href="%s">Testing Stripe</a>" for more card numbers.', 'woocommerce-gateway-stripe'), 'https://stripe.com/docs/testing');
65
+			$this->description  = trim($this->description);
66 66
 		}
67 67
 
68
-		WC_Stripe_API::set_secret_key( $this->secret_key );
68
+		WC_Stripe_API::set_secret_key($this->secret_key);
69 69
 
70 70
 		// Hooks
71
-		add_action( 'wp_enqueue_scripts', array( $this, 'payment_scripts' ) );
72
-		add_action( 'admin_notices', array( $this, 'admin_notices' ) );
73
-		add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) );
71
+		add_action('wp_enqueue_scripts', array($this, 'payment_scripts'));
72
+		add_action('admin_notices', array($this, 'admin_notices'));
73
+		add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options'));
74 74
 	}
75 75
 
76 76
 	/**
@@ -80,37 +80,37 @@  discard block
 block discarded – undo
80 80
 	 * @return string
81 81
 	 */
82 82
 	public function get_icon() {
83
-		$ext   = version_compare( WC()->version, '2.6', '>=' ) ? '.svg' : '.png';
84
-		$style = version_compare( WC()->version, '2.6', '>=' ) ? 'style="margin-left: 0.3em"' : '';
83
+		$ext   = version_compare(WC()->version, '2.6', '>=') ? '.svg' : '.png';
84
+		$style = version_compare(WC()->version, '2.6', '>=') ? 'style="margin-left: 0.3em"' : '';
85 85
 
86
-		$icon  = '<img src="' . WC_HTTPS::force_https_url( WC()->plugin_url() . '/assets/images/icons/credit-cards/visa' . $ext ) . '" alt="Visa" width="32" ' . $style . ' />';
87
-		$icon .= '<img src="' . WC_HTTPS::force_https_url( WC()->plugin_url() . '/assets/images/icons/credit-cards/mastercard' . $ext ) . '" alt="Mastercard" width="32" ' . $style . ' />';
88
-		$icon .= '<img src="' . WC_HTTPS::force_https_url( WC()->plugin_url() . '/assets/images/icons/credit-cards/amex' . $ext ) . '" alt="Amex" width="32" ' . $style . ' />';
86
+		$icon  = '<img src="' . WC_HTTPS::force_https_url(WC()->plugin_url() . '/assets/images/icons/credit-cards/visa' . $ext) . '" alt="Visa" width="32" ' . $style . ' />';
87
+		$icon .= '<img src="' . WC_HTTPS::force_https_url(WC()->plugin_url() . '/assets/images/icons/credit-cards/mastercard' . $ext) . '" alt="Mastercard" width="32" ' . $style . ' />';
88
+		$icon .= '<img src="' . WC_HTTPS::force_https_url(WC()->plugin_url() . '/assets/images/icons/credit-cards/amex' . $ext) . '" alt="Amex" width="32" ' . $style . ' />';
89 89
 
90 90
 		$base_location = wc_get_base_location();
91 91
 
92
-		if ( 'US' === $base_location['country'] ) {
93
-			$icon .= '<img src="' . WC_HTTPS::force_https_url( WC()->plugin_url() . '/assets/images/icons/credit-cards/discover' . $ext ) . '" alt="Discover" width="32" ' . $style . ' />';
94
-			$icon .= '<img src="' . WC_HTTPS::force_https_url( WC()->plugin_url() . '/assets/images/icons/credit-cards/jcb' . $ext ) . '" alt="JCB" width="32" ' . $style . ' />';
95
-			$icon .= '<img src="' . WC_HTTPS::force_https_url( WC()->plugin_url() . '/assets/images/icons/credit-cards/diners' . $ext ) . '" alt="Diners" width="32" ' . $style . ' />';
92
+		if ('US' === $base_location['country']) {
93
+			$icon .= '<img src="' . WC_HTTPS::force_https_url(WC()->plugin_url() . '/assets/images/icons/credit-cards/discover' . $ext) . '" alt="Discover" width="32" ' . $style . ' />';
94
+			$icon .= '<img src="' . WC_HTTPS::force_https_url(WC()->plugin_url() . '/assets/images/icons/credit-cards/jcb' . $ext) . '" alt="JCB" width="32" ' . $style . ' />';
95
+			$icon .= '<img src="' . WC_HTTPS::force_https_url(WC()->plugin_url() . '/assets/images/icons/credit-cards/diners' . $ext) . '" alt="Diners" width="32" ' . $style . ' />';
96 96
 		}
97 97
 
98
-		if ( $this->bitcoin ) {
99
-			$icon .= '<img src="' . WC_HTTPS::force_https_url( plugins_url( '/assets/images/bitcoin' . $ext, WC_STRIPE_MAIN_FILE ) ) . '" alt="Bitcoin" width="32" ' . $style . ' />';
98
+		if ($this->bitcoin) {
99
+			$icon .= '<img src="' . WC_HTTPS::force_https_url(plugins_url('/assets/images/bitcoin' . $ext, WC_STRIPE_MAIN_FILE)) . '" alt="Bitcoin" width="32" ' . $style . ' />';
100 100
 		}
101 101
 
102
-		return apply_filters( 'woocommerce_gateway_icon', $icon, $this->id );
102
+		return apply_filters('woocommerce_gateway_icon', $icon, $this->id);
103 103
 	}
104 104
 
105 105
 	/**
106 106
 	 * Get Stripe amount to pay
107 107
 	 * @return float
108 108
 	 */
109
-	public function get_stripe_amount( $total, $currency = '' ) {
110
-		if ( ! $currency ) {
109
+	public function get_stripe_amount($total, $currency = '') {
110
+		if ( ! $currency) {
111 111
 			$currency = get_woocommerce_currency();
112 112
 		}
113
-		switch ( strtoupper( $currency ) ) {
113
+		switch (strtoupper($currency)) {
114 114
 			// Zero decimal currencies
115 115
 			case 'BIF' :
116 116
 			case 'CLP' :
@@ -127,10 +127,10 @@  discard block
 block discarded – undo
127 127
 			case 'XAF' :
128 128
 			case 'XOF' :
129 129
 			case 'XPF' :
130
-				$total = absint( $total );
130
+				$total = absint($total);
131 131
 				break;
132 132
 			default :
133
-				$total = round( $total, 2 ) * 100; // In cents
133
+				$total = round($total, 2) * 100; // In cents
134 134
 				break;
135 135
 		}
136 136
 		return $total;
@@ -140,31 +140,31 @@  discard block
 block discarded – undo
140 140
 	 * Check if SSL is enabled and notify the user
141 141
 	 */
142 142
 	public function admin_notices() {
143
-		if ( $this->enabled == 'no' ) {
143
+		if ($this->enabled == 'no') {
144 144
 			return;
145 145
 		}
146 146
 
147
-		$addons = ( class_exists( 'WC_Subscriptions_Order' ) || class_exists( 'WC_Pre_Orders_Order' ) ) ? '_addons' : '';
147
+		$addons = (class_exists('WC_Subscriptions_Order') || class_exists('WC_Pre_Orders_Order')) ? '_addons' : '';
148 148
 
149 149
 		// Check required fields
150
-		if ( ! $this->secret_key ) {
151
-			echo '<div class="error"><p>' . sprintf( __( 'Stripe error: Please enter your secret key <a href="%s">here</a>', 'woocommerce-gateway-stripe' ), admin_url( 'admin.php?page=wc-settings&tab=checkout&section=wc_gateway_stripe' . $addons ) ) . '</p></div>';
150
+		if ( ! $this->secret_key) {
151
+			echo '<div class="error"><p>' . sprintf(__('Stripe error: Please enter your secret key <a href="%s">here</a>', 'woocommerce-gateway-stripe'), admin_url('admin.php?page=wc-settings&tab=checkout&section=wc_gateway_stripe' . $addons)) . '</p></div>';
152 152
 			return;
153 153
 
154
-		} elseif ( ! $this->publishable_key ) {
155
-			echo '<div class="error"><p>' . sprintf( __( 'Stripe error: Please enter your publishable key <a href="%s">here</a>', 'woocommerce-gateway-stripe' ), admin_url( 'admin.php?page=wc-settings&tab=checkout&section=wc_gateway_stripe' . $addons ) ) . '</p></div>';
154
+		} elseif ( ! $this->publishable_key) {
155
+			echo '<div class="error"><p>' . sprintf(__('Stripe error: Please enter your publishable key <a href="%s">here</a>', 'woocommerce-gateway-stripe'), admin_url('admin.php?page=wc-settings&tab=checkout&section=wc_gateway_stripe' . $addons)) . '</p></div>';
156 156
 			return;
157 157
 		}
158 158
 
159 159
 		// Simple check for duplicate keys
160
-		if ( $this->secret_key == $this->publishable_key ) {
161
-			echo '<div class="error"><p>' . sprintf( __( 'Stripe error: Your secret and publishable keys match. Please check and re-enter.', 'woocommerce-gateway-stripe' ), admin_url( 'admin.php?page=wc-settings&tab=checkout&section=wc_gateway_stripe' . $addons ) ) . '</p></div>';
160
+		if ($this->secret_key == $this->publishable_key) {
161
+			echo '<div class="error"><p>' . sprintf(__('Stripe error: Your secret and publishable keys match. Please check and re-enter.', 'woocommerce-gateway-stripe'), admin_url('admin.php?page=wc-settings&tab=checkout&section=wc_gateway_stripe' . $addons)) . '</p></div>';
162 162
 			return;
163 163
 		}
164 164
 
165 165
 		// Show message if enabled and FORCE SSL is disabled and WordpressHTTPS plugin is not detected
166
-		if ( ( function_exists( 'wc_site_is_https' ) && ! wc_site_is_https() ) && ( 'no' === get_option( 'woocommerce_force_ssl_checkout' ) && ! class_exists( 'WordPressHTTPS' ) ) ) {
167
-			echo '<div class="error"><p>' . sprintf( __( 'Stripe is enabled, but the <a href="%s">force SSL option</a> is disabled; your checkout may not be secure! Please enable SSL and ensure your server has a valid SSL certificate - Stripe will only work in test mode.', 'woocommerce-gateway-stripe' ), admin_url( 'admin.php?page=wc-settings&tab=checkout' ) ) . '</p></div>';
166
+		if ((function_exists('wc_site_is_https') && ! wc_site_is_https()) && ('no' === get_option('woocommerce_force_ssl_checkout') && ! class_exists('WordPressHTTPS'))) {
167
+			echo '<div class="error"><p>' . sprintf(__('Stripe is enabled, but the <a href="%s">force SSL option</a> is disabled; your checkout may not be secure! Please enable SSL and ensure your server has a valid SSL certificate - Stripe will only work in test mode.', 'woocommerce-gateway-stripe'), admin_url('admin.php?page=wc-settings&tab=checkout')) . '</p></div>';
168 168
 		}
169 169
 	}
170 170
 
@@ -172,11 +172,11 @@  discard block
 block discarded – undo
172 172
 	 * Check if this gateway is enabled
173 173
 	 */
174 174
 	public function is_available() {
175
-		if ( 'yes' === $this->enabled ) {
176
-			if ( ! $this->testmode && is_checkout() && ! is_ssl() ) {
175
+		if ('yes' === $this->enabled) {
176
+			if ( ! $this->testmode && is_checkout() && ! is_ssl()) {
177 177
 				return false;
178 178
 			}
179
-			if ( ! $this->secret_key || ! $this->publishable_key ) {
179
+			if ( ! $this->secret_key || ! $this->publishable_key) {
180 180
 				return false;
181 181
 			}
182 182
 			return true;
@@ -188,9 +188,9 @@  discard block
 block discarded – undo
188 188
 	 * Initialise Gateway Settings Form Fields
189 189
 	 */
190 190
 	public function init_form_fields() {
191
-		$this->form_fields = include( untrailingslashit( plugin_dir_path( WC_STRIPE_MAIN_FILE ) ) . '/includes/settings-stripe.php' );
191
+		$this->form_fields = include(untrailingslashit(plugin_dir_path(WC_STRIPE_MAIN_FILE)) . '/includes/settings-stripe.php');
192 192
 
193
-		wc_enqueue_js( "
193
+		wc_enqueue_js("
194 194
 			jQuery( function( $ ) {
195 195
 				$( '#woocommerce_stripe_stripe_checkout' ).change(function(){
196 196
 					if ( $( this ).is( ':checked' ) ) {
@@ -210,25 +210,25 @@  discard block
 block discarded – undo
210 210
 		?>
211 211
 		<fieldset class="stripe-legacy-payment-fields">
212 212
 			<?php
213
-				if ( $this->description ) {
214
-					echo apply_filters( 'wc_stripe_description', wpautop( wp_kses_post( $this->description ) ) );
213
+				if ($this->description) {
214
+					echo apply_filters('wc_stripe_description', wpautop(wp_kses_post($this->description)));
215 215
 				}
216
-				if ( $this->saved_cards && is_user_logged_in() ) {
217
-					$stripe_customer = new WC_Stripe_Customer( get_current_user_id() );
216
+				if ($this->saved_cards && is_user_logged_in()) {
217
+					$stripe_customer = new WC_Stripe_Customer(get_current_user_id());
218 218
 					?>
219 219
 					<p class="form-row form-row-wide">
220
-						<a class="<?php echo apply_filters( 'wc_stripe_manage_saved_cards_class', 'button' ); ?>" style="float:right;" href="<?php echo apply_filters( 'wc_stripe_manage_saved_cards_url', get_permalink( get_option( 'woocommerce_myaccount_page_id' ) ) ); ?>#saved-cards"><?php esc_html_e( 'Manage cards', 'woocommerce-gateway-stripe' ); ?></a>
220
+						<a class="<?php echo apply_filters('wc_stripe_manage_saved_cards_class', 'button'); ?>" style="float:right;" href="<?php echo apply_filters('wc_stripe_manage_saved_cards_url', get_permalink(get_option('woocommerce_myaccount_page_id'))); ?>#saved-cards"><?php esc_html_e('Manage cards', 'woocommerce-gateway-stripe'); ?></a>
221 221
 						<?php
222
-						if ( $cards = $stripe_customer->get_cards() ) {
222
+						if ($cards = $stripe_customer->get_cards()) {
223 223
 							$default_card = $cards[0]->id;
224
-							foreach ( (array) $cards as $card ) {
225
-								if ( 'card' !== $card->object ) {
224
+							foreach ((array) $cards as $card) {
225
+								if ('card' !== $card->object) {
226 226
 									continue;
227 227
 								}
228 228
 								?>
229
-								<label for="stripe_card_<?php echo $card->id; ?>" class="brand-<?php echo esc_attr( strtolower( $card->brand ) ); ?>">
230
-									<input type="radio" id="stripe_card_<?php echo $card->id; ?>" name="wc-stripe-payment-token" value="<?php echo $card->id; ?>" <?php checked( $default_card, $card->id ) ?> />
231
-									<?php printf( __( '%s card ending in %s (Expires %s/%s)', 'woocommerce-gateway-stripe' ), $card->brand, $card->last4, $card->exp_month, $card->exp_year ); ?>
229
+								<label for="stripe_card_<?php echo $card->id; ?>" class="brand-<?php echo esc_attr(strtolower($card->brand)); ?>">
230
+									<input type="radio" id="stripe_card_<?php echo $card->id; ?>" name="wc-stripe-payment-token" value="<?php echo $card->id; ?>" <?php checked($default_card, $card->id) ?> />
231
+									<?php printf(__('%s card ending in %s (Expires %s/%s)', 'woocommerce-gateway-stripe'), $card->brand, $card->last4, $card->exp_month, $card->exp_year); ?>
232 232
 								</label>
233 233
 								<?php
234 234
 							}
@@ -236,7 +236,7 @@  discard block
 block discarded – undo
236 236
 						?>
237 237
 						<label for="new">
238 238
 							<input type="radio" id="new" name="wc-stripe-payment-token" value="new" />
239
-							<?php _e( 'Use a new credit card', 'woocommerce-gateway-stripe' ); ?>
239
+							<?php _e('Use a new credit card', 'woocommerce-gateway-stripe'); ?>
240 240
 						</label>
241 241
 					</p>
242 242
 					<?php
@@ -244,8 +244,8 @@  discard block
 block discarded – undo
244 244
 
245 245
 				$user = wp_get_current_user();
246 246
 
247
-				if ( $user ) {
248
-					$user_email = get_user_meta( $user->ID, 'billing_email', true );
247
+				if ($user) {
248
+					$user_email = get_user_meta($user->ID, 'billing_email', true);
249 249
 					$user_email = $user_email ? $user_email : $user->user_email;
250 250
 				} else {
251 251
 					$user_email = '';
@@ -253,22 +253,22 @@  discard block
 block discarded – undo
253 253
 
254 254
 				$display = '';
255 255
 
256
-				if ( $this->stripe_checkout || $this->saved_cards && ! empty( $cards ) ) {
256
+				if ($this->stripe_checkout || $this->saved_cards && ! empty($cards)) {
257 257
 					$display = 'style="display:none;"';
258 258
 				}
259 259
 
260 260
 				echo '<div ' . $display . ' id="stripe-payment-data"
261 261
 					data-description=""
262
-					data-email="' . esc_attr( $user_email ) . '"
263
-					data-amount="' . esc_attr( $this->get_stripe_amount( WC()->cart->total ) ) . '"
264
-					data-name="' . esc_attr( get_bloginfo( 'name', 'display' ) ) . '"
265
-					data-currency="' . esc_attr( strtolower( get_woocommerce_currency() ) ) . '"
266
-					data-image="' . esc_attr( $this->stripe_checkout_image ) . '"
267
-					data-bitcoin="' . esc_attr( $this->bitcoin ? 'true' : 'false' ) . '"
268
-					data-locale="' . esc_attr( $this->stripe_checkout_locale ? $this->stripe_checkout_locale : 'en' ) . '">';
269
-
270
-				if ( ! $this->stripe_checkout ) {
271
-					$this->credit_card_form( array( 'fields_have_names' => false ) );
262
+					data-email="' . esc_attr($user_email) . '"
263
+					data-amount="' . esc_attr($this->get_stripe_amount(WC()->cart->total)) . '"
264
+					data-name="' . esc_attr(get_bloginfo('name', 'display')) . '"
265
+					data-currency="' . esc_attr(strtolower(get_woocommerce_currency())) . '"
266
+					data-image="' . esc_attr($this->stripe_checkout_image) . '"
267
+					data-bitcoin="' . esc_attr($this->bitcoin ? 'true' : 'false') . '"
268
+					data-locale="' . esc_attr($this->stripe_checkout_locale ? $this->stripe_checkout_locale : 'en') . '">';
269
+
270
+				if ( ! $this->stripe_checkout) {
271
+					$this->credit_card_form(array('fields_have_names' => false));
272 272
 				}
273 273
 
274 274
 				echo '</div>';
@@ -285,27 +285,27 @@  discard block
 block discarded – undo
285 285
 	 * @access public
286 286
 	 */
287 287
 	public function payment_scripts() {
288
-		if ( $this->stripe_checkout ) {
289
-			wp_enqueue_script( 'stripe', 'https://checkout.stripe.com/v2/checkout.js', '', '2.0', true );
290
-			wp_enqueue_script( 'woocommerce_stripe', plugins_url( 'assets/js/stripe-checkout.js', WC_STRIPE_MAIN_FILE ), array( 'stripe' ), WC_STRIPE_VERSION, true );
288
+		if ($this->stripe_checkout) {
289
+			wp_enqueue_script('stripe', 'https://checkout.stripe.com/v2/checkout.js', '', '2.0', true);
290
+			wp_enqueue_script('woocommerce_stripe', plugins_url('assets/js/stripe-checkout.js', WC_STRIPE_MAIN_FILE), array('stripe'), WC_STRIPE_VERSION, true);
291 291
 		} else {
292
-			wp_enqueue_script( 'stripe', 'https://js.stripe.com/v2/', '', '1.0', true );
293
-			wp_enqueue_script( 'woocommerce_stripe', plugins_url( 'assets/js/stripe.js', WC_STRIPE_MAIN_FILE ), array( 'jquery-payment', 'stripe' ), WC_STRIPE_VERSION, true );
292
+			wp_enqueue_script('stripe', 'https://js.stripe.com/v2/', '', '1.0', true);
293
+			wp_enqueue_script('woocommerce_stripe', plugins_url('assets/js/stripe.js', WC_STRIPE_MAIN_FILE), array('jquery-payment', 'stripe'), WC_STRIPE_VERSION, true);
294 294
 		}
295 295
 
296 296
 		$stripe_params = array(
297 297
 			'key'                  => $this->publishable_key,
298
-			'i18n_terms'           => __( 'Please accept the terms and conditions first', 'woocommerce-gateway-stripe' ),
299
-			'i18n_required_fields' => __( 'Please fill in required checkout fields first', 'woocommerce-gateway-stripe' ),
298
+			'i18n_terms'           => __('Please accept the terms and conditions first', 'woocommerce-gateway-stripe'),
299
+			'i18n_required_fields' => __('Please fill in required checkout fields first', 'woocommerce-gateway-stripe'),
300 300
 		);
301 301
 
302 302
 		// If we're on the pay page we need to pass stripe.js the address of the order.
303
-		if ( is_checkout_pay_page() && isset( $_GET['order'] ) && isset( $_GET['order_id'] ) ) {
304
-			$order_key = urldecode( $_GET['order'] );
305
-			$order_id  = absint( $_GET['order_id'] );
306
-			$order     = wc_get_order( $order_id );
303
+		if (is_checkout_pay_page() && isset($_GET['order']) && isset($_GET['order_id'])) {
304
+			$order_key = urldecode($_GET['order']);
305
+			$order_id  = absint($_GET['order_id']);
306
+			$order     = wc_get_order($order_id);
307 307
 
308
-			if ( $order->id === $order_id && $order->order_key === $order_key ) {
308
+			if ($order->id === $order_id && $order->order_key === $order_key) {
309 309
 				$stripe_params['billing_first_name'] = $order->billing_first_name;
310 310
 				$stripe_params['billing_last_name']  = $order->billing_last_name;
311 311
 				$stripe_params['billing_address_1']  = $order->billing_address_1;
@@ -317,7 +317,7 @@  discard block
 block discarded – undo
317 317
 			}
318 318
 		}
319 319
 
320
-		wp_localize_script( 'woocommerce_stripe', 'wc_stripe_params', apply_filters( 'wc_stripe_params', $stripe_params ) );
320
+		wp_localize_script('woocommerce_stripe', 'wc_stripe_params', apply_filters('wc_stripe_params', $stripe_params));
321 321
 	}
322 322
 
323 323
 	/**
@@ -326,28 +326,28 @@  discard block
 block discarded – undo
326 326
 	 * @param  object $source
327 327
 	 * @return array()
328 328
 	 */
329
-	protected function generate_payment_request( $order, $source ) {
329
+	protected function generate_payment_request($order, $source) {
330 330
 		$post_data                = array();
331
-		$post_data['currency']    = strtolower( $order->get_order_currency() ? $order->get_order_currency() : get_woocommerce_currency() );
332
-		$post_data['amount']      = $this->get_stripe_amount( $order->get_total(), $post_data['currency'] );
333
-		$post_data['description'] = sprintf( __( '%s - Order %s', 'woocommerce-gateway-stripe' ), wp_specialchars_decode( get_bloginfo( 'name' ), ENT_QUOTES ), $order->get_order_number() );
331
+		$post_data['currency']    = strtolower($order->get_order_currency() ? $order->get_order_currency() : get_woocommerce_currency());
332
+		$post_data['amount']      = $this->get_stripe_amount($order->get_total(), $post_data['currency']);
333
+		$post_data['description'] = sprintf(__('%s - Order %s', 'woocommerce-gateway-stripe'), wp_specialchars_decode(get_bloginfo('name'), ENT_QUOTES), $order->get_order_number());
334 334
 		$post_data['capture']     = $this->capture ? 'true' : 'false';
335 335
 
336
-		if ( ! empty( $order->billing_email ) && apply_filters( 'wc_stripe_send_stripe_receipt', false ) ) {
336
+		if ( ! empty($order->billing_email) && apply_filters('wc_stripe_send_stripe_receipt', false)) {
337 337
 			$post_data['receipt_email'] = $order->billing_email;
338 338
 		}
339 339
 
340
-		$post_data['expand[]']    = 'balance_transaction';
340
+		$post_data['expand[]'] = 'balance_transaction';
341 341
 
342
-		if ( $source->customer ) {
342
+		if ($source->customer) {
343 343
 			$post_data['customer'] = $source->customer;
344 344
 		}
345 345
 
346
-		if ( $source->source ) {
346
+		if ($source->source) {
347 347
 			$post_data['source'] = $source->source;
348 348
 		}
349 349
 
350
-		return apply_filters( 'wc_stripe_generate_payment_request', $post_data, $order, $source );
350
+		return apply_filters('wc_stripe_generate_payment_request', $post_data, $order, $source);
351 351
 	}
352 352
 
353 353
 	/**
@@ -355,22 +355,22 @@  discard block
 block discarded – undo
355 355
 	 * @param  bool $force_customer Should we force customer creation?
356 356
 	 * @return object
357 357
 	 */
358
-	protected function get_source( $user_id, $force_customer = false ) {
359
-		$stripe_customer = new WC_Stripe_Customer( $user_id );
358
+	protected function get_source($user_id, $force_customer = false) {
359
+		$stripe_customer = new WC_Stripe_Customer($user_id);
360 360
 		$stripe_source   = false;
361 361
 		$token_id        = false;
362 362
 
363 363
 		// New CC info was entered and we have a new token to process
364
-		if ( isset( $_POST['stripe_token'] ) ) {
365
-			$stripe_token     = wc_clean( $_POST['stripe_token'] );
366
-			$maybe_saved_card = isset( $_POST['wc-stripe-new-payment-method'] ) && ! empty( $_POST['wc-stripe-new-payment-method'] );
364
+		if (isset($_POST['stripe_token'])) {
365
+			$stripe_token     = wc_clean($_POST['stripe_token']);
366
+			$maybe_saved_card = isset($_POST['wc-stripe-new-payment-method']) && ! empty($_POST['wc-stripe-new-payment-method']);
367 367
 
368 368
 			// This is true if the user wants to store the card to their account.
369
-			if ( ( $user_id && $this->saved_cards && $maybe_saved_card ) || $force_customer ) {
370
-				$stripe_source = $stripe_customer->add_card( $stripe_token );
369
+			if (($user_id && $this->saved_cards && $maybe_saved_card) || $force_customer) {
370
+				$stripe_source = $stripe_customer->add_card($stripe_token);
371 371
 
372
-				if ( is_wp_error( $stripe_source ) ) {
373
-					throw new Exception( $stripe_source->get_error_message() );
372
+				if (is_wp_error($stripe_source)) {
373
+					throw new Exception($stripe_source->get_error_message());
374 374
 				}
375 375
 
376 376
 			} else {
@@ -381,8 +381,8 @@  discard block
 block discarded – undo
381 381
 		}
382 382
 
383 383
 		// Use an existing token, and then process the payment
384
-		elseif ( isset( $_POST['wc-stripe-payment-token'] ) && 'new' !== $_POST['wc-stripe-payment-token'] ) {
385
-			$stripe_source = wc_clean( $_POST['wc-stripe-payment-token'] );
384
+		elseif (isset($_POST['wc-stripe-payment-token']) && 'new' !== $_POST['wc-stripe-payment-token']) {
385
+			$stripe_source = wc_clean($_POST['wc-stripe-payment-token']);
386 386
 		}
387 387
 
388 388
 		return (object) array(
@@ -403,16 +403,16 @@  discard block
 block discarded – undo
403 403
 	 * @param object $order
404 404
 	 * @return object
405 405
 	 */
406
-	protected function get_order_source( $order = null ) {
406
+	protected function get_order_source($order = null) {
407 407
 		$stripe_customer = new WC_Stripe_Customer();
408 408
 		$stripe_source   = false;
409 409
 		$token_id        = false;
410 410
 
411
-		if ( $order ) {
412
-			if ( $meta_value = get_post_meta( $order->id, '_stripe_customer_id', true ) ) {
413
-				$stripe_customer->set_id( $meta_value );
411
+		if ($order) {
412
+			if ($meta_value = get_post_meta($order->id, '_stripe_customer_id', true)) {
413
+				$stripe_customer->set_id($meta_value);
414 414
 			}
415
-			if ( $meta_value = get_post_meta( $order->id, '_stripe_card_id', true ) ) {
415
+			if ($meta_value = get_post_meta($order->id, '_stripe_card_id', true)) {
416 416
 				$stripe_source = $meta_value;
417 417
 			}
418 418
 		}
@@ -427,43 +427,43 @@  discard block
 block discarded – undo
427 427
 	/**
428 428
 	 * Process the payment
429 429
 	 */
430
-	public function process_payment( $order_id, $retry = true, $force_customer = false ) {
430
+	public function process_payment($order_id, $retry = true, $force_customer = false) {
431 431
 		try {
432
-			$order  = wc_get_order( $order_id );
433
-			$source = $this->get_source( get_current_user_id(), $force_customer );
432
+			$order  = wc_get_order($order_id);
433
+			$source = $this->get_source(get_current_user_id(), $force_customer);
434 434
 
435
-			if ( empty( $source->source ) && empty( $source->customer ) ) {
436
-				$error_msg = __( 'Please enter your card details to make a payment.', 'woocommerce-gateway-stripe' );
437
-				$error_msg .= ' ' . __( 'Developers: Please make sure that you are including jQuery and there are no JavaScript errors on the page.', 'woocommerce-gateway-stripe' );
438
-				throw new Exception( $error_msg );
435
+			if (empty($source->source) && empty($source->customer)) {
436
+				$error_msg = __('Please enter your card details to make a payment.', 'woocommerce-gateway-stripe');
437
+				$error_msg .= ' ' . __('Developers: Please make sure that you are including jQuery and there are no JavaScript errors on the page.', 'woocommerce-gateway-stripe');
438
+				throw new Exception($error_msg);
439 439
 			}
440 440
 
441 441
 			// Store source to order meta
442
-			$this->save_source( $order, $source );
442
+			$this->save_source($order, $source);
443 443
 
444 444
 			// Handle payment
445
-			if ( $order->get_total() > 0 ) {
445
+			if ($order->get_total() > 0) {
446 446
 
447
-				if ( $order->get_total() * 100 < WC_Stripe::get_minimum_amount() ) {
448
-					throw new Exception( sprintf( __( 'Sorry, the minimum allowed order total is %1$s to use this payment method.', 'woocommerce-gateway-stripe' ), wc_price( WC_Stripe::get_minimum_amount() / 100 ) ) );
447
+				if ($order->get_total() * 100 < WC_Stripe::get_minimum_amount()) {
448
+					throw new Exception(sprintf(__('Sorry, the minimum allowed order total is %1$s to use this payment method.', 'woocommerce-gateway-stripe'), wc_price(WC_Stripe::get_minimum_amount() / 100)));
449 449
 				}
450 450
 
451
-				WC_Stripe::log( "Info: Begin processing payment for order $order_id for the amount of {$order->get_total()}" );
451
+				WC_Stripe::log("Info: Begin processing payment for order $order_id for the amount of {$order->get_total()}");
452 452
 
453 453
 				// Make the request
454
-				$response = WC_Stripe_API::request( $this->generate_payment_request( $order, $source ) );
454
+				$response = WC_Stripe_API::request($this->generate_payment_request($order, $source));
455 455
 
456
-				if ( is_wp_error( $response ) ) {
456
+				if (is_wp_error($response)) {
457 457
 					// Customer param wrong? The user may have been deleted on stripe's end. Remove customer_id. Can be retried without.
458
-					if ( 'customer' === $response->get_error_code() && $retry ) {
459
-						delete_user_meta( get_current_user_id(), '_stripe_customer_id' );
460
-						return $this->process_payment( $order_id, false, $force_customer );
458
+					if ('customer' === $response->get_error_code() && $retry) {
459
+						delete_user_meta(get_current_user_id(), '_stripe_customer_id');
460
+						return $this->process_payment($order_id, false, $force_customer);
461 461
 					}
462
-					throw new Exception( $response->get_error_code() . ': ' . $response->get_error_message() );
462
+					throw new Exception($response->get_error_code() . ': ' . $response->get_error_message());
463 463
 				}
464 464
 
465 465
 				// Process valid response
466
-				$this->process_response( $response, $order );
466
+				$this->process_response($response, $order);
467 467
 			} else {
468 468
 				$order->payment_complete();
469 469
 			}
@@ -474,13 +474,13 @@  discard block
 block discarded – undo
474 474
 			// Return thank you page redirect
475 475
 			return array(
476 476
 				'result'   => 'success',
477
-				'redirect' => $this->get_return_url( $order )
477
+				'redirect' => $this->get_return_url($order)
478 478
 			);
479 479
 
480
-		} catch ( Exception $e ) {
481
-			wc_add_notice( $e->getMessage(), 'error' );
482
-			WC()->session->set( 'refresh_totals', true );
483
-			WC_Stripe::log( sprintf( __( 'Error: %s', 'woocommerce-gateway-stripe' ), $e->getMessage() ) );
480
+		} catch (Exception $e) {
481
+			wc_add_notice($e->getMessage(), 'error');
482
+			WC()->session->set('refresh_totals', true);
483
+			WC_Stripe::log(sprintf(__('Error: %s', 'woocommerce-gateway-stripe'), $e->getMessage()));
484 484
 			return;
485 485
 		}
486 486
 	}
@@ -488,45 +488,45 @@  discard block
 block discarded – undo
488 488
 	/**
489 489
 	 * Save source to order.
490 490
 	 */
491
-	protected function save_source( $order, $source ) {
491
+	protected function save_source($order, $source) {
492 492
 		// Store source in the order
493
-		if ( $source->customer ) {
494
-			update_post_meta( $order->id, '_stripe_customer_id', $source->customer );
493
+		if ($source->customer) {
494
+			update_post_meta($order->id, '_stripe_customer_id', $source->customer);
495 495
 		}
496
-		if ( $source->source ) {
497
-			update_post_meta( $order->id, '_stripe_card_id', $source->source->id );
496
+		if ($source->source) {
497
+			update_post_meta($order->id, '_stripe_card_id', $source->source->id);
498 498
 		}
499 499
 	}
500 500
 
501 501
 	/**
502 502
 	 * Store extra meta data for an order from a Stripe Response.
503 503
 	 */
504
-	public function process_response( $response, $order ) {
505
-		WC_Stripe::log( "Processing response: " . print_r( $response, true ) );
504
+	public function process_response($response, $order) {
505
+		WC_Stripe::log("Processing response: " . print_r($response, true));
506 506
 
507 507
 		// Store charge data
508
-		update_post_meta( $order->id, '_stripe_charge_id', $response->id );
509
-		update_post_meta( $order->id, '_stripe_charge_captured', $response->captured ? 'yes' : 'no' );
508
+		update_post_meta($order->id, '_stripe_charge_id', $response->id);
509
+		update_post_meta($order->id, '_stripe_charge_captured', $response->captured ? 'yes' : 'no');
510 510
 
511 511
 		// Store other data such as fees
512
-		if ( isset( $response->balance_transaction ) && isset( $response->balance_transaction->fee ) ) {
513
-			$fee = number_format( $response->balance_transaction->fee / 100, 2, '.', '' );
514
-			update_post_meta( $order->id, 'Stripe Fee', $fee );
515
-			update_post_meta( $order->id, 'Net Revenue From Stripe', $order->get_total() - $fee );
512
+		if (isset($response->balance_transaction) && isset($response->balance_transaction->fee)) {
513
+			$fee = number_format($response->balance_transaction->fee / 100, 2, '.', '');
514
+			update_post_meta($order->id, 'Stripe Fee', $fee);
515
+			update_post_meta($order->id, 'Net Revenue From Stripe', $order->get_total() - $fee);
516 516
 		}
517 517
 
518
-		if ( $response->captured ) {
519
-			$order->payment_complete( $response->id );
520
-			WC_Stripe::log( "Successful charge: $response->id" );
518
+		if ($response->captured) {
519
+			$order->payment_complete($response->id);
520
+			WC_Stripe::log("Successful charge: $response->id");
521 521
 		} else {
522
-			update_post_meta( $order->id, '_transaction_id', $response->id, true );
522
+			update_post_meta($order->id, '_transaction_id', $response->id, true);
523 523
 
524
-			if ( $order->has_status( array( 'pending', 'failed' ) ) ) {
524
+			if ($order->has_status(array('pending', 'failed'))) {
525 525
 				$order->reduce_order_stock();
526 526
 			}
527 527
 
528
-			$order->update_status( 'on-hold', sprintf( __( 'Stripe charge authorized (Charge ID: %s). Process order to take payment, or cancel to remove the pre-authorization.', 'woocommerce-gateway-stripe' ), $response->id ) );
529
-			WC_Stripe::log( "Successful auth: $response->id" );
528
+			$order->update_status('on-hold', sprintf(__('Stripe charge authorized (Charge ID: %s). Process order to take payment, or cancel to remove the pre-authorization.', 'woocommerce-gateway-stripe'), $response->id));
529
+			WC_Stripe::log("Successful auth: $response->id");
530 530
 		}
531 531
 
532 532
 		return $response;
@@ -538,21 +538,21 @@  discard block
 block discarded – undo
538 538
 	 * @since 3.0.0
539 539
 	 */
540 540
 	public function add_payment_method() {
541
-		if ( empty( $_POST['stripe_token'] ) || ! is_user_logged_in() ) {
542
-			wc_add_notice( __( 'There was a problem adding the card.', 'woocommerce-gateway-stripe' ), 'error' );
541
+		if (empty($_POST['stripe_token']) || ! is_user_logged_in()) {
542
+			wc_add_notice(__('There was a problem adding the card.', 'woocommerce-gateway-stripe'), 'error');
543 543
 			return;
544 544
 		}
545 545
 
546
-		$stripe_customer = new WC_Stripe_Customer( get_current_user_id() );
547
-		$result          = $stripe_customer->add_card( wc_clean( $_POST['stripe_token'] ) );
546
+		$stripe_customer = new WC_Stripe_Customer(get_current_user_id());
547
+		$result          = $stripe_customer->add_card(wc_clean($_POST['stripe_token']));
548 548
 
549
-		if ( is_wp_error( $result ) ) {
550
-			throw new Exception( $result->get_error_message() );
549
+		if (is_wp_error($result)) {
550
+			throw new Exception($result->get_error_message());
551 551
 		}
552 552
 
553 553
 		return array(
554 554
 			'result'   => 'success',
555
-			'redirect' => wc_get_endpoint_url( 'payment-methods' ),
555
+			'redirect' => wc_get_endpoint_url('payment-methods'),
556 556
 		);
557 557
 	}
558 558
 
@@ -562,36 +562,36 @@  discard block
 block discarded – undo
562 562
 	 * @param  float $amount
563 563
 	 * @return bool
564 564
 	 */
565
-	public function process_refund( $order_id, $amount = null, $reason = '' ) {
566
-		$order = wc_get_order( $order_id );
565
+	public function process_refund($order_id, $amount = null, $reason = '') {
566
+		$order = wc_get_order($order_id);
567 567
 
568
-		if ( ! $order || ! $order->get_transaction_id() ) {
568
+		if ( ! $order || ! $order->get_transaction_id()) {
569 569
 			return false;
570 570
 		}
571 571
 
572 572
 		$body = array();
573 573
 
574
-		if ( ! is_null( $amount ) ) {
575
-			$body['amount']	= $this->get_stripe_amount( $amount );
574
+		if ( ! is_null($amount)) {
575
+			$body['amount'] = $this->get_stripe_amount($amount);
576 576
 		}
577 577
 
578
-		if ( $reason ) {
578
+		if ($reason) {
579 579
 			$body['metadata'] = array(
580 580
 				'reason'	=> $reason,
581 581
 			);
582 582
 		}
583 583
 
584
-		WC_Stripe::log( "Info: Beginning refund for order $order_id for the amount of {$amount}" );
584
+		WC_Stripe::log("Info: Beginning refund for order $order_id for the amount of {$amount}");
585 585
 
586
-		$response = WC_Stripe_API::request( $body, 'charges/' . $order->get_transaction_id() . '/refunds' );
586
+		$response = WC_Stripe_API::request($body, 'charges/' . $order->get_transaction_id() . '/refunds');
587 587
 
588
-		if ( is_wp_error( $response ) ) {
589
-			WC_Stripe::log( "Error: " . $response->get_error_message() );
588
+		if (is_wp_error($response)) {
589
+			WC_Stripe::log("Error: " . $response->get_error_message());
590 590
 			return $response;
591
-		} elseif ( ! empty( $response->id ) ) {
592
-			$refund_message = sprintf( __( 'Refunded %s - Refund ID: %s - Reason: %s', 'woocommerce-gateway-stripe' ), wc_price( $response->amount / 100 ), $response->id, $reason );
593
-			$order->add_order_note( $refund_message );
594
-			WC_Stripe::log( "Success: " . html_entity_decode( strip_tags( $refund_message ) ) );
591
+		} elseif ( ! empty($response->id)) {
592
+			$refund_message = sprintf(__('Refunded %s - Refund ID: %s - Reason: %s', 'woocommerce-gateway-stripe'), wc_price($response->amount / 100), $response->id, $reason);
593
+			$order->add_order_note($refund_message);
594
+			WC_Stripe::log("Success: " . html_entity_decode(strip_tags($refund_message)));
595 595
 			return true;
596 596
 		}
597 597
 	}
Please login to merge, or discard this patch.