Completed
Push — master ( 10f2d5...14f50c )
by Boro
07:09
created
includes/class-wc-gateway-stripe.php 2 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -177,7 +177,7 @@
 block discarded – undo
177 177
 	 * @param float  $total Amount due.
178 178
 	 * @param string $currency Accepted currency.
179 179
 	 *
180
-	 * @return float|int
180
+	 * @return double
181 181
 	 */
182 182
 	public function get_stripe_amount( $total, $currency = '' ) {
183 183
 		if ( ! $currency ) {
Please login to merge, or discard this 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.
includes/class-wc-stripe-api.php 2 patches
Doc Comments   -1 removed lines patch added patch discarded remove patch
@@ -23,7 +23,6 @@
 block discarded – undo
23 23
 
24 24
 	/**
25 25
 	 * Set secret API Key.
26
-	 * @param string $key
27 26
 	 */
28 27
 	public static function set_secret_key( $secret_key ) {
29 28
 		self::$secret_key = $secret_key;
Please login to merge, or discard this patch.
Spacing   +21 added lines, -21 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
 
@@ -25,7 +25,7 @@  discard block
 block discarded – undo
25 25
 	 * Set secret API Key.
26 26
 	 * @param string $key
27 27
 	 */
28
-	public static function set_secret_key( $secret_key ) {
28
+	public static function set_secret_key($secret_key) {
29 29
 		self::$secret_key = $secret_key;
30 30
 	}
31 31
 
@@ -34,11 +34,11 @@  discard block
 block discarded – undo
34 34
 	 * @return string
35 35
 	 */
36 36
 	public static function get_secret_key() {
37
-		if ( ! self::$secret_key ) {
38
-			$options = get_option( 'woocommerce_stripe_settings' );
37
+		if ( ! self::$secret_key) {
38
+			$options = get_option('woocommerce_stripe_settings');
39 39
 
40
-			if ( isset( $options['testmode'], $options['secret_key'], $options['test_secret_key'] ) ) {
41
-				self::set_secret_key( 'yes' === $options['testmode'] ? $options['test_secret_key'] : $options['secret_key'] );
40
+			if (isset($options['testmode'], $options['secret_key'], $options['test_secret_key'])) {
41
+				self::set_secret_key('yes' === $options['testmode'] ? $options['test_secret_key'] : $options['secret_key']);
42 42
 			}
43 43
 		}
44 44
 		return self::$secret_key;
@@ -51,38 +51,38 @@  discard block
 block discarded – undo
51 51
 	 * @param string $api
52 52
 	 * @return array|WP_Error
53 53
 	 */
54
-	public static function request( $request, $api = 'charges', $method = 'POST' ) {
55
-		self::log( "{$api} request: " . print_r( $request, true ) );
54
+	public static function request($request, $api = 'charges', $method = 'POST') {
55
+		self::log("{$api} request: " . print_r($request, true));
56 56
 
57 57
 		$response = wp_safe_remote_post(
58 58
 			self::ENDPOINT . $api,
59 59
 			array(
60 60
 				'method'        => $method,
61 61
 				'headers'       => array(
62
-					'Authorization'  => 'Basic ' . base64_encode( self::get_secret_key() . ':' ),
62
+					'Authorization'  => 'Basic ' . base64_encode(self::get_secret_key() . ':'),
63 63
 					'Stripe-Version' => '2016-03-07',
64 64
 				),
65
-				'body'       => apply_filters( 'woocommerce_stripe_request_body', $request, $api ),
65
+				'body'       => apply_filters('woocommerce_stripe_request_body', $request, $api),
66 66
 				'timeout'    => 70,
67 67
 				'user-agent' => 'WooCommerce ' . WC()->version,
68 68
 			)
69 69
 		);
70 70
 
71
-		if ( is_wp_error( $response ) || empty( $response['body'] ) ) {
72
-			self::log( 'Error Response: ' . print_r( $response, true ) );
73
-			return new WP_Error( 'stripe_error', __( 'There was a problem connecting to the payment gateway.', 'woocommerce-gateway-stripe' ) );
71
+		if (is_wp_error($response) || empty($response['body'])) {
72
+			self::log('Error Response: ' . print_r($response, true));
73
+			return new WP_Error('stripe_error', __('There was a problem connecting to the payment gateway.', 'woocommerce-gateway-stripe'));
74 74
 		}
75 75
 
76
-		$parsed_response = json_decode( $response['body'] );
76
+		$parsed_response = json_decode($response['body']);
77 77
 
78 78
 		// Handle response
79
-		if ( ! empty( $parsed_response->error ) ) {
80
-			if ( ! empty( $parsed_response->error->code ) ) {
79
+		if ( ! empty($parsed_response->error)) {
80
+			if ( ! empty($parsed_response->error->code)) {
81 81
 				$code = $parsed_response->error->code;
82 82
 			} else {
83 83
 				$code = 'stripe_error';
84 84
 			}
85
-			return new WP_Error( $code, $parsed_response->error->message );
85
+			return new WP_Error($code, $parsed_response->error->message);
86 86
 		} else {
87 87
 			return $parsed_response;
88 88
 		}
@@ -96,11 +96,11 @@  discard block
 block discarded – undo
96 96
 	 *
97 97
 	 * @param string $message
98 98
 	 */
99
-	public static function log( $message ) {
100
-		$options = get_option( 'woocommerce_stripe_settings' );
99
+	public static function log($message) {
100
+		$options = get_option('woocommerce_stripe_settings');
101 101
 
102
-		if ( 'yes' === $options['logging'] ) {
103
-			WC_Stripe::log( $message );
102
+		if ('yes' === $options['logging']) {
103
+			WC_Stripe::log($message);
104 104
 		}
105 105
 	}
106 106
 }
Please login to merge, or discard this patch.
includes/class-wc-stripe-customer.php 2 patches
Doc Comments   -1 removed lines patch added patch discarded remove patch
@@ -210,7 +210,6 @@
 block discarded – undo
210 210
 	/**
211 211
 	 * Get a customers saved cards using their Stripe ID. Cached.
212 212
 	 *
213
-	 * @param  string $customer_id
214 213
 	 * @return array
215 214
 	 */
216 215
 	public function get_cards() {
Please login to merge, or discard this patch.
Spacing   +73 added lines, -73 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
 
@@ -32,10 +32,10 @@  discard block
 block discarded – undo
32 32
 	 * Constructor
33 33
 	 * @param integer $user_id
34 34
 	 */
35
-	public function __construct( $user_id = 0 ) {
36
-		if ( $user_id ) {
37
-			$this->set_user_id( $user_id );
38
-			$this->set_id( get_user_meta( $user_id, '_stripe_customer_id', true ) );
35
+	public function __construct($user_id = 0) {
36
+		if ($user_id) {
37
+			$this->set_user_id($user_id);
38
+			$this->set_id(get_user_meta($user_id, '_stripe_customer_id', true));
39 39
 		}
40 40
 	}
41 41
 
@@ -51,8 +51,8 @@  discard block
 block discarded – undo
51 51
 	 * Set Stripe customer ID.
52 52
 	 * @param [type] $id [description]
53 53
 	 */
54
-	public function set_id( $id ) {
55
-		$this->id = wc_clean( $id );
54
+	public function set_id($id) {
55
+		$this->id = wc_clean($id);
56 56
 	}
57 57
 
58 58
 	/**
@@ -60,15 +60,15 @@  discard block
 block discarded – undo
60 60
 	 * @return int
61 61
 	 */
62 62
 	public function get_user_id() {
63
-		return absint( $this->user_id );
63
+		return absint($this->user_id);
64 64
 	}
65 65
 
66 66
 	/**
67 67
 	 * Set User ID used by WordPress.
68 68
 	 * @param int $user_id
69 69
 	 */
70
-	public function set_user_id( $user_id ) {
71
-		$this->user_id = absint( $user_id );
70
+	public function set_user_id($user_id) {
71
+		$this->user_id = absint($user_id);
72 72
 	}
73 73
 
74 74
 	/**
@@ -76,13 +76,13 @@  discard block
 block discarded – undo
76 76
 	 * @return WP_User
77 77
 	 */
78 78
 	protected function get_user() {
79
-		return $this->get_user_id() ? get_user_by( 'id', $this->get_user_id() ) : false;
79
+		return $this->get_user_id() ? get_user_by('id', $this->get_user_id()) : false;
80 80
 	}
81 81
 
82 82
 	/**
83 83
 	 * Store data from the Stripe API about this customer
84 84
 	 */
85
-	public function set_customer_data( $data ) {
85
+	public function set_customer_data($data) {
86 86
 		$this->customer_data = $data;
87 87
 	}
88 88
 
@@ -90,12 +90,12 @@  discard block
 block discarded – undo
90 90
 	 * Get data from the Stripe API about this customer
91 91
 	 */
92 92
 	public function get_customer_data() {
93
-		if ( empty( $this->customer_data ) && $this->get_id() && false === ( $this->customer_data = get_transient( 'stripe_customer_' . $this->get_id() ) ) ) {
94
-			$response = WC_Stripe_API::request( array(), 'customers/' . $this->get_id() );
93
+		if (empty($this->customer_data) && $this->get_id() && false === ($this->customer_data = get_transient('stripe_customer_' . $this->get_id()))) {
94
+			$response = WC_Stripe_API::request(array(), 'customers/' . $this->get_id());
95 95
 
96
-			if ( ! is_wp_error( $response ) ) {
97
-				$this->set_customer_data( $response );
98
-				set_transient( 'stripe_customer_' . $this->get_id(), $response, HOUR_IN_SECONDS * 48 );
96
+			if ( ! is_wp_error($response)) {
97
+				$this->set_customer_data($response);
98
+				set_transient('stripe_customer_' . $this->get_id(), $response, HOUR_IN_SECONDS * 48);
99 99
 			}
100 100
 		}
101 101
 		return $this->customer_data;
@@ -109,7 +109,7 @@  discard block
 block discarded – undo
109 109
 		$data   = $this->get_customer_data();
110 110
 		$source = '';
111 111
 
112
-		if ( $data ) {
112
+		if ($data) {
113 113
 			$source = $data->default_source;
114 114
 		}
115 115
 
@@ -121,10 +121,10 @@  discard block
 block discarded – undo
121 121
 	 * @param array $args
122 122
 	 * @return WP_Error|int
123 123
 	 */
124
-	public function create_customer( $args = array() ) {
125
-		if ( $user = $this->get_user() ) {
126
-			$billing_first_name = get_user_meta( $user->ID, 'billing_first_name', true );
127
-			$billing_last_name  = get_user_meta( $user->ID, 'billing_last_name', true );
124
+	public function create_customer($args = array()) {
125
+		if ($user = $this->get_user()) {
126
+			$billing_first_name = get_user_meta($user->ID, 'billing_first_name', true);
127
+			$billing_last_name  = get_user_meta($user->ID, 'billing_last_name', true);
128 128
 
129 129
 			$defaults = array(
130 130
 				'email'       => $user->user_email,
@@ -139,26 +139,26 @@  discard block
 block discarded – undo
139 139
 
140 140
 		$metadata = array();
141 141
 
142
-		$defaults['metadata'] = apply_filters( 'wc_stripe_customer_metadata', $metadata, $user );
142
+		$defaults['metadata'] = apply_filters('wc_stripe_customer_metadata', $metadata, $user);
143 143
 
144
-		$args     = wp_parse_args( $args, $defaults );
145
-		$response = WC_Stripe_API::request( $args, 'customers' );
144
+		$args     = wp_parse_args($args, $defaults);
145
+		$response = WC_Stripe_API::request($args, 'customers');
146 146
 
147
-		if ( is_wp_error( $response ) ) {
147
+		if (is_wp_error($response)) {
148 148
 			return $response;
149
-		} elseif ( empty( $response->id ) ) {
150
-			return new WP_Error( 'stripe_error', __( 'Could not create Stripe customer.', 'woocommerce-gateway-stripe' ) );
149
+		} elseif (empty($response->id)) {
150
+			return new WP_Error('stripe_error', __('Could not create Stripe customer.', 'woocommerce-gateway-stripe'));
151 151
 		}
152 152
 
153
-		$this->set_id( $response->id );
153
+		$this->set_id($response->id);
154 154
 		$this->clear_cache();
155
-		$this->set_customer_data( $response );
155
+		$this->set_customer_data($response);
156 156
 
157
-		if ( $this->get_user_id() ) {
158
-			update_user_meta( $this->get_user_id(), '_stripe_customer_id', $response->id );
157
+		if ($this->get_user_id()) {
158
+			update_user_meta($this->get_user_id(), '_stripe_customer_id', $response->id);
159 159
 		}
160 160
 
161
-		do_action( 'woocommerce_stripe_add_customer', $args, $response );
161
+		do_action('woocommerce_stripe_add_customer', $args, $response);
162 162
 
163 163
 		return $response->id;
164 164
 	}
@@ -169,51 +169,51 @@  discard block
 block discarded – undo
169 169
 	 * @param bool $retry
170 170
 	 * @return WP_Error|int
171 171
 	 */
172
-	public function add_card( $token, $retry = true ) {
173
-		if ( ! $this->get_id() ) {
174
-			if ( ( $response = $this->create_customer() ) && is_wp_error( $response ) ) {
172
+	public function add_card($token, $retry = true) {
173
+		if ( ! $this->get_id()) {
174
+			if (($response = $this->create_customer()) && is_wp_error($response)) {
175 175
 				return $response;
176 176
 			}
177 177
 		}
178 178
 
179
-		$response = WC_Stripe_API::request( array(
179
+		$response = WC_Stripe_API::request(array(
180 180
 			'source' => $token,
181
-		), 'customers/' . $this->get_id() . '/sources' );
181
+		), 'customers/' . $this->get_id() . '/sources');
182 182
 
183
-		if ( is_wp_error( $response ) ) {
183
+		if (is_wp_error($response)) {
184 184
 			// It is possible the WC user once was linked to a customer on Stripe
185 185
 			// but no longer exists. Instead of failing, lets try to create a
186 186
 			// new customer.
187
-			if ( preg_match( '/No such customer:/', $response->get_error_message() ) ) {
188
-				delete_user_meta( $this->get_user_id(), '_stripe_customer_id' );
187
+			if (preg_match('/No such customer:/', $response->get_error_message())) {
188
+				delete_user_meta($this->get_user_id(), '_stripe_customer_id');
189 189
 				$this->create_customer();
190
-				return $this->add_card( $token, false );
191
-			} elseif ( 'customer' === $response->get_error_code() && $retry ) {
190
+				return $this->add_card($token, false);
191
+			} elseif ('customer' === $response->get_error_code() && $retry) {
192 192
 				$this->create_customer();
193
-				return $this->add_card( $token, false );
193
+				return $this->add_card($token, false);
194 194
 			} else {
195 195
 				return $response;
196 196
 			}
197
-		} elseif ( empty( $response->id ) ) {
198
-			return new WP_Error( 'error', __( 'Unable to add card', 'woocommerce-gateway-stripe' ) );
197
+		} elseif (empty($response->id)) {
198
+			return new WP_Error('error', __('Unable to add card', 'woocommerce-gateway-stripe'));
199 199
 		}
200 200
 
201 201
 		// Add token to WooCommerce
202
-		if ( $this->get_user_id() && class_exists( 'WC_Payment_Token_CC' ) ) {
202
+		if ($this->get_user_id() && class_exists('WC_Payment_Token_CC')) {
203 203
 			$token = new WC_Payment_Token_CC();
204
-			$token->set_token( $response->id );
205
-			$token->set_gateway_id( 'stripe' );
206
-			$token->set_card_type( strtolower( $response->brand ) );
207
-			$token->set_last4( $response->last4 );
208
-			$token->set_expiry_month( $response->exp_month );
209
-			$token->set_expiry_year( $response->exp_year );
210
-			$token->set_user_id( $this->get_user_id() );
204
+			$token->set_token($response->id);
205
+			$token->set_gateway_id('stripe');
206
+			$token->set_card_type(strtolower($response->brand));
207
+			$token->set_last4($response->last4);
208
+			$token->set_expiry_month($response->exp_month);
209
+			$token->set_expiry_year($response->exp_year);
210
+			$token->set_user_id($this->get_user_id());
211 211
 			$token->save();
212 212
 		}
213 213
 
214 214
 		$this->clear_cache();
215 215
 
216
-		do_action( 'woocommerce_stripe_add_card', $this->get_id(), $token, $response );
216
+		do_action('woocommerce_stripe_add_card', $this->get_id(), $token, $response);
217 217
 
218 218
 		return $response->id;
219 219
 	}
@@ -227,20 +227,20 @@  discard block
 block discarded – undo
227 227
 	public function get_cards() {
228 228
 		$cards = array();
229 229
 
230
-		if ( $this->get_id() && false === ( $cards = get_transient( 'stripe_cards_' . $this->get_id() ) ) ) {
231
-			$response = WC_Stripe_API::request( array(
230
+		if ($this->get_id() && false === ($cards = get_transient('stripe_cards_' . $this->get_id()))) {
231
+			$response = WC_Stripe_API::request(array(
232 232
 				'limit'       => 100,
233
-			), 'customers/' . $this->get_id() . '/sources', 'GET' );
233
+			), 'customers/' . $this->get_id() . '/sources', 'GET');
234 234
 
235
-			if ( is_wp_error( $response ) ) {
235
+			if (is_wp_error($response)) {
236 236
 				return array();
237 237
 			}
238 238
 
239
-			if ( is_array( $response->data ) ) {
239
+			if (is_array($response->data)) {
240 240
 				$cards = $response->data;
241 241
 			}
242 242
 
243
-			set_transient( 'stripe_cards_' . $this->get_id(), $cards, HOUR_IN_SECONDS * 48 );
243
+			set_transient('stripe_cards_' . $this->get_id(), $cards, HOUR_IN_SECONDS * 48);
244 244
 		}
245 245
 
246 246
 		return $cards;
@@ -250,13 +250,13 @@  discard block
 block discarded – undo
250 250
 	 * Delete a card from stripe.
251 251
 	 * @param string $card_id
252 252
 	 */
253
-	public function delete_card( $card_id ) {
254
-		$response = WC_Stripe_API::request( array(), 'customers/' . $this->get_id() . '/sources/' . sanitize_text_field( $card_id ), 'DELETE' );
253
+	public function delete_card($card_id) {
254
+		$response = WC_Stripe_API::request(array(), 'customers/' . $this->get_id() . '/sources/' . sanitize_text_field($card_id), 'DELETE');
255 255
 
256 256
 		$this->clear_cache();
257 257
 
258
-		if ( ! is_wp_error( $response ) ) {
259
-			do_action( 'wc_stripe_delete_card', $this->get_id(), $response );
258
+		if ( ! is_wp_error($response)) {
259
+			do_action('wc_stripe_delete_card', $this->get_id(), $response);
260 260
 
261 261
 			return true;
262 262
 		}
@@ -268,15 +268,15 @@  discard block
 block discarded – undo
268 268
 	 * Set default card in Stripe
269 269
 	 * @param string $card_id
270 270
 	 */
271
-	public function set_default_card( $card_id ) {
272
-		$response = WC_Stripe_API::request( array(
273
-			'default_source' => sanitize_text_field( $card_id ),
274
-		), 'customers/' . $this->get_id(), 'POST' );
271
+	public function set_default_card($card_id) {
272
+		$response = WC_Stripe_API::request(array(
273
+			'default_source' => sanitize_text_field($card_id),
274
+		), 'customers/' . $this->get_id(), 'POST');
275 275
 
276 276
 		$this->clear_cache();
277 277
 
278
-		if ( ! is_wp_error( $response ) ) {
279
-			do_action( 'wc_stripe_set_default_card', $this->get_id(), $response );
278
+		if ( ! is_wp_error($response)) {
279
+			do_action('wc_stripe_set_default_card', $this->get_id(), $response);
280 280
 
281 281
 			return true;
282 282
 		}
@@ -288,8 +288,8 @@  discard block
 block discarded – undo
288 288
 	 * Deletes caches for this users cards.
289 289
 	 */
290 290
 	public function clear_cache() {
291
-		delete_transient( 'stripe_cards_' . $this->get_id() );
292
-		delete_transient( 'stripe_customer_' . $this->get_id() );
291
+		delete_transient('stripe_cards_' . $this->get_id());
292
+		delete_transient('stripe_customer_' . $this->get_id());
293 293
 		$this->customer_data = array();
294 294
 	}
295 295
 }
Please login to merge, or discard this patch.
includes/legacy/class-wc-gateway-stripe-saved-cards.php 1 patch
Spacing   +24 added lines, -24 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
 
@@ -12,25 +12,25 @@  discard block
 block discarded – undo
12 12
 	 * Constructor
13 13
 	 */
14 14
 	public function __construct() {
15
-		add_action( 'wp', array( $this, 'delete_card' ) );
16
-		add_action( 'woocommerce_after_my_account', array( $this, 'output' ) );
17
-		add_action( 'wp', array( $this, 'default_card' ) );
15
+		add_action('wp', array($this, 'delete_card'));
16
+		add_action('woocommerce_after_my_account', array($this, 'output'));
17
+		add_action('wp', array($this, 'default_card'));
18 18
 	}
19 19
 
20 20
 	/**
21 21
 	 * Display saved cards
22 22
 	 */
23 23
 	public function output() {
24
-		if ( ! is_user_logged_in() ) {
24
+		if ( ! is_user_logged_in()) {
25 25
 			return;
26 26
 		}
27 27
 
28
-		$stripe_customer = new WC_Stripe_Customer( get_current_user_id() );
28
+		$stripe_customer = new WC_Stripe_Customer(get_current_user_id());
29 29
 		$stripe_cards    = $stripe_customer->get_cards();
30 30
 		$default_card    = $stripe_customer->get_default_card();
31 31
 
32
-		if ( $stripe_cards ) {
33
-			wc_get_template( 'saved-cards.php', array( 'cards' => $stripe_cards, 'default_card' => $default_card ), 'woocommerce-gateway-stripe/', untrailingslashit( plugin_dir_path( WC_STRIPE_MAIN_FILE ) ) . '/includes/legacy/templates/' );
32
+		if ($stripe_cards) {
33
+			wc_get_template('saved-cards.php', array('cards' => $stripe_cards, 'default_card' => $default_card), 'woocommerce-gateway-stripe/', untrailingslashit(plugin_dir_path(WC_STRIPE_MAIN_FILE)) . '/includes/legacy/templates/');
34 34
 		}
35 35
 	}
36 36
 
@@ -38,22 +38,22 @@  discard block
 block discarded – undo
38 38
 	 * Delete a card
39 39
 	 */
40 40
 	public function delete_card() {
41
-		if ( ! isset( $_POST['stripe_delete_card'] ) || ! is_account_page() ) {
41
+		if ( ! isset($_POST['stripe_delete_card']) || ! is_account_page()) {
42 42
 			return;
43 43
 		}
44 44
 
45
-		$stripe_customer    = new WC_Stripe_Customer( get_current_user_id() );
45
+		$stripe_customer    = new WC_Stripe_Customer(get_current_user_id());
46 46
 		$stripe_customer_id = $stripe_customer->get_id();
47
-		$delete_card        = sanitize_text_field( $_POST['stripe_delete_card'] );
47
+		$delete_card        = sanitize_text_field($_POST['stripe_delete_card']);
48 48
 
49
-		if ( ! is_user_logged_in() || ! $stripe_customer_id || ! wp_verify_nonce( $_POST['_wpnonce'], "stripe_del_card" ) ) {
50
-			wp_die( __( 'Unable to make default card, please try again', 'woocommerce-gateway-stripe' ) );
49
+		if ( ! is_user_logged_in() || ! $stripe_customer_id || ! wp_verify_nonce($_POST['_wpnonce'], "stripe_del_card")) {
50
+			wp_die(__('Unable to make default card, please try again', 'woocommerce-gateway-stripe'));
51 51
 		}
52 52
 
53
-		if ( ! $stripe_customer->delete_card( $delete_card ) ) {
54
-			wc_add_notice( __( 'Unable to delete card.', 'woocommerce-gateway-stripe' ), 'error' );
53
+		if ( ! $stripe_customer->delete_card($delete_card)) {
54
+			wc_add_notice(__('Unable to delete card.', 'woocommerce-gateway-stripe'), 'error');
55 55
 		} else {
56
-			wc_add_notice( __( 'Card deleted.', 'woocommerce-gateway-stripe' ), 'success' );
56
+			wc_add_notice(__('Card deleted.', 'woocommerce-gateway-stripe'), 'success');
57 57
 		}
58 58
 	}
59 59
 
@@ -61,22 +61,22 @@  discard block
 block discarded – undo
61 61
 	 * Make a card as default method
62 62
 	 */
63 63
 	public function default_card() {
64
-		if ( ! isset( $_POST['stripe_default_card'] ) || ! is_account_page() ) {
64
+		if ( ! isset($_POST['stripe_default_card']) || ! is_account_page()) {
65 65
 			return;
66 66
 		}
67 67
 
68
-		$stripe_customer    = new WC_Stripe_Customer( get_current_user_id() );
68
+		$stripe_customer    = new WC_Stripe_Customer(get_current_user_id());
69 69
 		$stripe_customer_id = $stripe_customer->get_id();
70
-		$default_source     = sanitize_text_field( $_POST['stripe_default_card'] );
70
+		$default_source     = sanitize_text_field($_POST['stripe_default_card']);
71 71
 
72
-		if ( ! is_user_logged_in() || ! $stripe_customer_id || ! wp_verify_nonce( $_POST['_wpnonce'], "stripe_default_card" ) ) {
73
-			wp_die( __( 'Unable to make default card, please try again', 'woocommerce-gateway-stripe' ) );
72
+		if ( ! is_user_logged_in() || ! $stripe_customer_id || ! wp_verify_nonce($_POST['_wpnonce'], "stripe_default_card")) {
73
+			wp_die(__('Unable to make default card, please try again', 'woocommerce-gateway-stripe'));
74 74
 		}
75 75
 
76
-		if ( ! $stripe_customer->set_default_card( $default_source ) ) {
77
-			wc_add_notice( __( 'Unable to update default card.', 'woocommerce-gateway-stripe' ), 'error' );
76
+		if ( ! $stripe_customer->set_default_card($default_source)) {
77
+			wc_add_notice(__('Unable to update default card.', 'woocommerce-gateway-stripe'), 'error');
78 78
 		} else {
79
-			wc_add_notice( __( 'Default card updated.', 'woocommerce-gateway-stripe' ), 'success' );
79
+			wc_add_notice(__('Default card updated.', 'woocommerce-gateway-stripe'), 'success');
80 80
 		}
81 81
 	}
82 82
 }
Please login to merge, or discard this patch.
includes/legacy/templates/saved-cards.php 2 patches
Spacing   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -1,37 +1,37 @@
 block discarded – undo
1
-<h2 id="saved-cards" style="margin-top:40px;"><?php _e( 'Saved cards', 'woocommerce-gateway-stripe' ); ?></h2>
1
+<h2 id="saved-cards" style="margin-top:40px;"><?php _e('Saved cards', 'woocommerce-gateway-stripe'); ?></h2>
2 2
 <table class="shop_table">
3 3
 	<thead>
4 4
 		<tr>
5
-			<th><?php esc_html_e( 'Card', 'woocommerce-gateway-stripe' ); ?></th>
6
-			<th><?php esc_html_e( 'Expires', 'woocommerce-gateway-stripe' ); ?></th>
5
+			<th><?php esc_html_e('Card', 'woocommerce-gateway-stripe'); ?></th>
6
+			<th><?php esc_html_e('Expires', 'woocommerce-gateway-stripe'); ?></th>
7 7
 			<th></th>
8 8
 		</tr>
9 9
 	</thead>
10 10
 	<tbody>
11
-		<?php foreach ( $cards as $card ) :
12
-			if ( 'card' !== $card->object ) {
11
+		<?php foreach ($cards as $card) :
12
+			if ('card' !== $card->object) {
13 13
 				continue;
14 14
 			}
15 15
 
16 16
 			$is_default_card = $card->id === $default_card ? true : false;
17 17
 		?>
18 18
 		<tr>
19
-            <td><?php printf( __( '%s card ending in %s', 'woocommerce-gateway-stripe' ), $card->brand, $card->last4 ); ?>
20
-            	<?php if ( $is_default_card ) echo '<br />' . __( '(Default)', 'woocommerce-gateway-stripe' ); ?>
19
+            <td><?php printf(__('%s card ending in %s', 'woocommerce-gateway-stripe'), $card->brand, $card->last4); ?>
20
+            	<?php if ($is_default_card) echo '<br />' . __('(Default)', 'woocommerce-gateway-stripe'); ?>
21 21
             </td>
22
-            <td><?php printf( __( 'Expires %s/%s', 'woocommerce-gateway-stripe' ), $card->exp_month, $card->exp_year ); ?></td>
22
+            <td><?php printf(__('Expires %s/%s', 'woocommerce-gateway-stripe'), $card->exp_month, $card->exp_year); ?></td>
23 23
 			<td>
24 24
                 <form action="" method="POST">
25
-                    <?php wp_nonce_field ( 'stripe_del_card' ); ?>
26
-                    <input type="hidden" name="stripe_delete_card" value="<?php echo esc_attr( $card->id ); ?>">
27
-                    <input type="submit" class="button" value="<?php esc_attr_e( 'Delete card', 'woocommerce-gateway-stripe' ); ?>">
25
+                    <?php wp_nonce_field('stripe_del_card'); ?>
26
+                    <input type="hidden" name="stripe_delete_card" value="<?php echo esc_attr($card->id); ?>">
27
+                    <input type="submit" class="button" value="<?php esc_attr_e('Delete card', 'woocommerce-gateway-stripe'); ?>">
28 28
                 </form>
29 29
 
30
-                <?php if ( ! $is_default_card ) { ?>
30
+                <?php if ( ! $is_default_card) { ?>
31 31
 	                <form action="" method="POST" style="margin-top:10px;">
32
-	                    <?php wp_nonce_field ( 'stripe_default_card' ); ?>
33
-	                    <input type="hidden" name="stripe_default_card" value="<?php echo esc_attr( $card->id ); ?>">
34
-	                    <input type="submit" class="button" value="<?php esc_attr_e( 'Make Default', 'woocommerce-gateway-stripe' ); ?>">
32
+	                    <?php wp_nonce_field('stripe_default_card'); ?>
33
+	                    <input type="hidden" name="stripe_default_card" value="<?php echo esc_attr($card->id); ?>">
34
+	                    <input type="submit" class="button" value="<?php esc_attr_e('Make Default', 'woocommerce-gateway-stripe'); ?>">
35 35
 	                </form>
36 36
                 <?php } ?>
37 37
 			</td>
Please login to merge, or discard this patch.
Braces   +4 added lines, -1 removed lines patch added patch discarded remove patch
@@ -17,7 +17,10 @@
 block discarded – undo
17 17
 		?>
18 18
 		<tr>
19 19
             <td><?php printf( __( '%s card ending in %s', 'woocommerce-gateway-stripe' ), $card->brand, $card->last4 ); ?>
20
-            	<?php if ( $is_default_card ) echo '<br />' . __( '(Default)', 'woocommerce-gateway-stripe' ); ?>
20
+            	<?php if ( $is_default_card ) {
21
+	echo '<br />' . __( '(Default)', 'woocommerce-gateway-stripe' );
22
+}
23
+?>
21 24
             </td>
22 25
             <td><?php printf( __( 'Expires %s/%s', 'woocommerce-gateway-stripe' ), $card->exp_month, $card->exp_year ); ?></td>
23 26
 			<td>
Please login to merge, or discard this patch.
woocommerce-gateway-stripe.php 2 patches
Doc Comments   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -144,6 +144,8 @@  discard block
 block discarded – undo
144 144
 
145 145
 		/**
146 146
 		 * Allow this class and other classes to add slug keyed notices (to avoid duplication)
147
+		 * @param string $slug
148
+		 * @param string $class
147 149
 		 */
148 150
 		public function add_admin_notice( $slug, $class, $message ) {
149 151
 			$this->notices[ $slug ] = array(
@@ -397,7 +399,7 @@  discard block
 block discarded – undo
397 399
 		/**
398 400
 		 * List of currencies supported by Stripe that has no decimals.
399 401
 		 *
400
-		 * @return array $currencies
402
+		 * @return string[] $currencies
401 403
 		 */
402 404
 		public static function no_decimal_currencies() {
403 405
 			return array(
Please login to merge, or discard this patch.
Spacing   +151 added lines, -151 removed lines patch added patch discarded remove patch
@@ -27,21 +27,21 @@  discard block
 block discarded – undo
27 27
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
28 28
 */
29 29
 
30
-if ( ! defined( 'ABSPATH' ) ) {
30
+if ( ! defined('ABSPATH')) {
31 31
 	exit;
32 32
 }
33 33
 
34 34
 /**
35 35
  * Required minimums and constants
36 36
  */
37
-define( 'WC_STRIPE_VERSION', '3.2.3' );
38
-define( 'WC_STRIPE_MIN_PHP_VER', '5.6.0' );
39
-define( 'WC_STRIPE_MIN_WC_VER', '2.5.0' );
40
-define( 'WC_STRIPE_MAIN_FILE', __FILE__ );
41
-define( 'WC_STRIPE_PLUGIN_URL', untrailingslashit( plugins_url( basename( plugin_dir_path( __FILE__ ) ), basename( __FILE__ ) ) ) );
42
-define( 'WC_STRIPE_PLUGIN_PATH', untrailingslashit( plugin_dir_path( __FILE__ ) ) );
37
+define('WC_STRIPE_VERSION', '3.2.3');
38
+define('WC_STRIPE_MIN_PHP_VER', '5.6.0');
39
+define('WC_STRIPE_MIN_WC_VER', '2.5.0');
40
+define('WC_STRIPE_MAIN_FILE', __FILE__);
41
+define('WC_STRIPE_PLUGIN_URL', untrailingslashit(plugins_url(basename(plugin_dir_path(__FILE__)), basename(__FILE__))));
42
+define('WC_STRIPE_PLUGIN_PATH', untrailingslashit(plugin_dir_path(__FILE__)));
43 43
 
44
-if ( ! class_exists( 'WC_Stripe' ) ) :
44
+if ( ! class_exists('WC_Stripe')) :
45 45
 
46 46
 	class WC_Stripe {
47 47
 
@@ -61,7 +61,7 @@  discard block
 block discarded – undo
61 61
 		 * @return Singleton The *Singleton* instance.
62 62
 		 */
63 63
 		public static function get_instance() {
64
-			if ( null === self::$instance ) {
64
+			if (null === self::$instance) {
65 65
 				self::$instance = new self();
66 66
 			}
67 67
 			return self::$instance;
@@ -110,9 +110,9 @@  discard block
 block discarded – undo
110 110
 		 * *Singleton* via the `new` operator from outside of this class.
111 111
 		 */
112 112
 		protected function __construct() {
113
-			add_action( 'admin_init', array( $this, 'check_environment' ) );
114
-			add_action( 'admin_notices', array( $this, 'admin_notices' ), 15 );
115
-			add_action( 'plugins_loaded', array( $this, 'init' ) );
113
+			add_action('admin_init', array($this, 'check_environment'));
114
+			add_action('admin_notices', array($this, 'admin_notices'), 15);
115
+			add_action('plugins_loaded', array($this, 'init'));
116 116
 		}
117 117
 
118 118
 		/**
@@ -120,35 +120,35 @@  discard block
 block discarded – undo
120 120
 		 */
121 121
 		public function init() {
122 122
 			// Don't hook anything else in the plugin if we're in an incompatible environment
123
-			if ( self::get_environment_warning() ) {
123
+			if (self::get_environment_warning()) {
124 124
 				return;
125 125
 			}
126 126
 
127
-			include_once( dirname( __FILE__ ) . '/includes/class-wc-stripe-api.php' );
128
-			include_once( dirname( __FILE__ ) . '/includes/class-wc-stripe-customer.php' );
127
+			include_once(dirname(__FILE__) . '/includes/class-wc-stripe-api.php');
128
+			include_once(dirname(__FILE__) . '/includes/class-wc-stripe-customer.php');
129 129
 
130 130
 			// Init the gateway itself
131 131
 			$this->init_gateways();
132 132
 
133
-			add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), array( $this, 'plugin_action_links' ) );
134
-			add_action( 'woocommerce_order_status_on-hold_to_processing', array( $this, 'capture_payment' ) );
135
-			add_action( 'woocommerce_order_status_on-hold_to_completed', array( $this, 'capture_payment' ) );
136
-			add_action( 'woocommerce_order_status_on-hold_to_cancelled', array( $this, 'cancel_payment' ) );
137
-			add_action( 'woocommerce_order_status_on-hold_to_refunded', array( $this, 'cancel_payment' ) );
138
-			add_filter( 'woocommerce_get_customer_payment_tokens', array( $this, 'woocommerce_get_customer_payment_tokens' ), 10, 3 );
139
-			add_action( 'woocommerce_payment_token_deleted', array( $this, 'woocommerce_payment_token_deleted' ), 10, 2 );
140
-			add_action( 'woocommerce_payment_token_set_default', array( $this, 'woocommerce_payment_token_set_default' ) );
141
-			add_action( 'wp_ajax_stripe_dismiss_request_api_notice', array( $this, 'dismiss_request_api_notice' ) );
142
-			add_action( 'wp_ajax_stripe_dismiss_apple_pay_notice', array( $this, 'dismiss_apple_pay_notice' ) );
143
-
144
-			include_once( dirname( __FILE__ ) . '/includes/class-wc-stripe-payment-request.php' );
133
+			add_filter('plugin_action_links_' . plugin_basename(__FILE__), array($this, 'plugin_action_links'));
134
+			add_action('woocommerce_order_status_on-hold_to_processing', array($this, 'capture_payment'));
135
+			add_action('woocommerce_order_status_on-hold_to_completed', array($this, 'capture_payment'));
136
+			add_action('woocommerce_order_status_on-hold_to_cancelled', array($this, 'cancel_payment'));
137
+			add_action('woocommerce_order_status_on-hold_to_refunded', array($this, 'cancel_payment'));
138
+			add_filter('woocommerce_get_customer_payment_tokens', array($this, 'woocommerce_get_customer_payment_tokens'), 10, 3);
139
+			add_action('woocommerce_payment_token_deleted', array($this, 'woocommerce_payment_token_deleted'), 10, 2);
140
+			add_action('woocommerce_payment_token_set_default', array($this, 'woocommerce_payment_token_set_default'));
141
+			add_action('wp_ajax_stripe_dismiss_request_api_notice', array($this, 'dismiss_request_api_notice'));
142
+			add_action('wp_ajax_stripe_dismiss_apple_pay_notice', array($this, 'dismiss_apple_pay_notice'));
143
+
144
+			include_once(dirname(__FILE__) . '/includes/class-wc-stripe-payment-request.php');
145 145
 		}
146 146
 
147 147
 		/**
148 148
 		 * Allow this class and other classes to add slug keyed notices (to avoid duplication)
149 149
 		 */
150
-		public function add_admin_notice( $slug, $class, $message ) {
151
-			$this->notices[ $slug ] = array(
150
+		public function add_admin_notice($slug, $class, $message) {
151
+			$this->notices[$slug] = array(
152 152
 				'class'   => $class,
153 153
 				'message' => $message,
154 154
 			);
@@ -159,29 +159,29 @@  discard block
 block discarded – undo
159 159
 		 * or the environment changes after activation. Also handles upgrade routines.
160 160
 		 */
161 161
 		public function check_environment() {
162
-			if ( ! defined( 'IFRAME_REQUEST' ) && ( WC_STRIPE_VERSION !== get_option( 'wc_stripe_version' ) ) ) {
162
+			if ( ! defined('IFRAME_REQUEST') && (WC_STRIPE_VERSION !== get_option('wc_stripe_version'))) {
163 163
 				$this->install();
164 164
 
165
-				do_action( 'woocommerce_stripe_updated' );
165
+				do_action('woocommerce_stripe_updated');
166 166
 			}
167 167
 
168 168
 			$environment_warning = self::get_environment_warning();
169 169
 
170
-			if ( $environment_warning && is_plugin_active( plugin_basename( __FILE__ ) ) ) {
171
-				$this->add_admin_notice( 'bad_environment', 'error', $environment_warning );
170
+			if ($environment_warning && is_plugin_active(plugin_basename(__FILE__))) {
171
+				$this->add_admin_notice('bad_environment', 'error', $environment_warning);
172 172
 			}
173 173
 
174 174
 			// Check if secret key present. Otherwise prompt, via notice, to go to
175 175
 			// setting.
176
-			if ( ! class_exists( 'WC_Stripe_API' ) ) {
177
-				include_once( dirname( __FILE__ ) . '/includes/class-wc-stripe-api.php' );
176
+			if ( ! class_exists('WC_Stripe_API')) {
177
+				include_once(dirname(__FILE__) . '/includes/class-wc-stripe-api.php');
178 178
 			}
179 179
 
180 180
 			$secret = WC_Stripe_API::get_secret_key();
181 181
 
182
-			if ( empty( $secret ) && ! ( isset( $_GET['page'], $_GET['section'] ) && 'wc-settings' === $_GET['page'] && 'stripe' === $_GET['section'] ) ) {
182
+			if (empty($secret) && ! (isset($_GET['page'], $_GET['section']) && 'wc-settings' === $_GET['page'] && 'stripe' === $_GET['section'])) {
183 183
 				$setting_link = $this->get_setting_link();
184
-				$this->add_admin_notice( 'prompt_connect', 'notice notice-warning', sprintf( __( 'Stripe is almost ready. To get started, <a href="%s">set your Stripe account keys</a>.', 'woocommerce-gateway-stripe' ), $setting_link ) );
184
+				$this->add_admin_notice('prompt_connect', 'notice notice-warning', sprintf(__('Stripe is almost ready. To get started, <a href="%s">set your Stripe account keys</a>.', 'woocommerce-gateway-stripe'), $setting_link));
185 185
 			}
186 186
 		}
187 187
 
@@ -193,8 +193,8 @@  discard block
 block discarded – undo
193 193
 		 * @return bool
194 194
 		 */
195 195
 		private static function _update_plugin_version() {
196
-			delete_option( 'wc_stripe_version' );
197
-			update_option( 'wc_stripe_version', WC_STRIPE_VERSION );
196
+			delete_option('wc_stripe_version');
197
+			update_option('wc_stripe_version', WC_STRIPE_VERSION);
198 198
 
199 199
 			return true;
200 200
 		}
@@ -206,7 +206,7 @@  discard block
 block discarded – undo
206 206
 		 * @version 3.1.0
207 207
 		 */
208 208
 		public function dismiss_request_api_notice() {
209
-			update_option( 'wc_stripe_show_request_api_notice', 'no' );
209
+			update_option('wc_stripe_show_request_api_notice', 'no');
210 210
 		}
211 211
 
212 212
 		/**
@@ -216,7 +216,7 @@  discard block
 block discarded – undo
216 216
 		 * @version 3.1.0
217 217
 		 */
218 218
 		public function dismiss_apple_pay_notice() {
219
-			update_option( 'wc_stripe_show_apple_pay_notice', 'no' );
219
+			update_option('wc_stripe_show_apple_pay_notice', 'no');
220 220
 		}
221 221
 
222 222
 		/**
@@ -226,8 +226,8 @@  discard block
 block discarded – undo
226 226
 		 * @version 3.1.0
227 227
 		 */
228 228
 		public function install() {
229
-			if ( ! defined( 'WC_STRIPE_INSTALLING' ) ) {
230
-				define( 'WC_STRIPE_INSTALLING', true );
229
+			if ( ! defined('WC_STRIPE_INSTALLING')) {
230
+				define('WC_STRIPE_INSTALLING', true);
231 231
 			}
232 232
 
233 233
 			$this->_update_plugin_version();
@@ -238,24 +238,24 @@  discard block
 block discarded – undo
238 238
 		 * found or false if the environment has no problems.
239 239
 		 */
240 240
 		static function get_environment_warning() {
241
-			if ( version_compare( phpversion(), WC_STRIPE_MIN_PHP_VER, '<' ) ) {
242
-				$message = __( 'WooCommerce Stripe - The minimum PHP version required for this plugin is %1$s. You are running %2$s.', 'woocommerce-gateway-stripe' );
241
+			if (version_compare(phpversion(), WC_STRIPE_MIN_PHP_VER, '<')) {
242
+				$message = __('WooCommerce Stripe - The minimum PHP version required for this plugin is %1$s. You are running %2$s.', 'woocommerce-gateway-stripe');
243 243
 
244
-				return sprintf( $message, WC_STRIPE_MIN_PHP_VER, phpversion() );
244
+				return sprintf($message, WC_STRIPE_MIN_PHP_VER, phpversion());
245 245
 			}
246 246
 
247
-			if ( ! defined( 'WC_VERSION' ) ) {
248
-				return __( 'WooCommerce Stripe requires WooCommerce to be activated to work.', 'woocommerce-gateway-stripe' );
247
+			if ( ! defined('WC_VERSION')) {
248
+				return __('WooCommerce Stripe requires WooCommerce to be activated to work.', 'woocommerce-gateway-stripe');
249 249
 			}
250 250
 
251
-			if ( version_compare( WC_VERSION, WC_STRIPE_MIN_WC_VER, '<' ) ) {
252
-				$message = __( 'WooCommerce Stripe - The minimum WooCommerce version required for this plugin is %1$s. You are running %2$s.', 'woocommerce-gateway-stripe' );
251
+			if (version_compare(WC_VERSION, WC_STRIPE_MIN_WC_VER, '<')) {
252
+				$message = __('WooCommerce Stripe - The minimum WooCommerce version required for this plugin is %1$s. You are running %2$s.', 'woocommerce-gateway-stripe');
253 253
 
254
-				return sprintf( $message, WC_STRIPE_MIN_WC_VER, WC_VERSION );
254
+				return sprintf($message, WC_STRIPE_MIN_WC_VER, WC_VERSION);
255 255
 			}
256 256
 
257
-			if ( ! function_exists( 'curl_init' ) ) {
258
-				return __( 'WooCommerce Stripe - cURL is not installed.', 'woocommerce-gateway-stripe' );
257
+			if ( ! function_exists('curl_init')) {
258
+				return __('WooCommerce Stripe - cURL is not installed.', 'woocommerce-gateway-stripe');
259 259
 			}
260 260
 
261 261
 			return false;
@@ -266,15 +266,15 @@  discard block
 block discarded – undo
266 266
 		 *
267 267
 		 * @since 1.0.0
268 268
 		 */
269
-		public function plugin_action_links( $links ) {
269
+		public function plugin_action_links($links) {
270 270
 			$setting_link = $this->get_setting_link();
271 271
 
272 272
 			$plugin_links = array(
273
-				'<a href="' . $setting_link . '">' . __( 'Settings', 'woocommerce-gateway-stripe' ) . '</a>',
274
-				'<a href="https://docs.woocommerce.com/document/stripe/">' . __( 'Docs', 'woocommerce-gateway-stripe' ) . '</a>',
275
-				'<a href="https://woocommerce.com/contact-us/">' . __( 'Support', 'woocommerce-gateway-stripe' ) . '</a>',
273
+				'<a href="' . $setting_link . '">' . __('Settings', 'woocommerce-gateway-stripe') . '</a>',
274
+				'<a href="https://docs.woocommerce.com/document/stripe/">' . __('Docs', 'woocommerce-gateway-stripe') . '</a>',
275
+				'<a href="https://woocommerce.com/contact-us/">' . __('Support', 'woocommerce-gateway-stripe') . '</a>',
276 276
 			);
277
-			return array_merge( $plugin_links, $links );
277
+			return array_merge($plugin_links, $links);
278 278
 		}
279 279
 
280 280
 		/**
@@ -285,24 +285,24 @@  discard block
 block discarded – undo
285 285
 		 * @return string Setting link
286 286
 		 */
287 287
 		public function get_setting_link() {
288
-			$use_id_as_section = function_exists( 'WC' ) ? version_compare( WC()->version, '2.6', '>=' ) : false;
288
+			$use_id_as_section = function_exists('WC') ? version_compare(WC()->version, '2.6', '>=') : false;
289 289
 
290
-			$section_slug = $use_id_as_section ? 'stripe' : strtolower( 'WC_Gateway_Stripe' );
290
+			$section_slug = $use_id_as_section ? 'stripe' : strtolower('WC_Gateway_Stripe');
291 291
 
292
-			return admin_url( 'admin.php?page=wc-settings&tab=checkout&section=' . $section_slug );
292
+			return admin_url('admin.php?page=wc-settings&tab=checkout&section=' . $section_slug);
293 293
 		}
294 294
 
295 295
 		/**
296 296
 		 * Display any notices we've collected thus far (e.g. for connection, disconnection)
297 297
 		 */
298 298
 		public function admin_notices() {
299
-			$show_request_api_notice = get_option( 'wc_stripe_show_request_api_notice' );
300
-			$show_apple_pay_notice   = get_option( 'wc_stripe_show_apple_pay_notice' );
299
+			$show_request_api_notice = get_option('wc_stripe_show_request_api_notice');
300
+			$show_apple_pay_notice   = get_option('wc_stripe_show_apple_pay_notice');
301 301
 
302
-			if ( empty( $show_apple_pay_notice ) ) {
302
+			if (empty($show_apple_pay_notice)) {
303 303
 				// @TODO remove this notice in the future.
304 304
 				?>
305
-				<div class="notice notice-warning wc-stripe-apple-pay-notice is-dismissible"><p><?php echo sprintf( esc_html__( 'New Feature! Stripe now supports %s. Your customers can now purchase your products even faster. Apple Pay has been enabled by default.', 'woocommerce-gateway-stripe' ), '<a href="https://woocommerce.com/apple-pay/">Apple Pay</a>'); ?></p></div>
305
+				<div class="notice notice-warning wc-stripe-apple-pay-notice is-dismissible"><p><?php echo sprintf(esc_html__('New Feature! Stripe now supports %s. Your customers can now purchase your products even faster. Apple Pay has been enabled by default.', 'woocommerce-gateway-stripe'), '<a href="https://woocommerce.com/apple-pay/">Apple Pay</a>'); ?></p></div>
306 306
 
307 307
 				<script type="application/javascript">
308 308
 					jQuery( '.wc-stripe-apple-pay-notice' ).on( 'click', '.notice-dismiss', function() {
@@ -310,17 +310,17 @@  discard block
 block discarded – undo
310 310
 							action: 'stripe_dismiss_apple_pay_notice'
311 311
 						};
312 312
 
313
-						jQuery.post( '<?php echo admin_url( 'admin-ajax.php' ); ?>', data );
313
+						jQuery.post( '<?php echo admin_url('admin-ajax.php'); ?>', data );
314 314
 					});
315 315
 				</script>
316 316
 
317 317
 				<?php
318 318
 			}
319 319
 
320
-			if ( empty( $show_request_api_notice ) ) {
320
+			if (empty($show_request_api_notice)) {
321 321
 				// @TODO remove this notice in the future.
322 322
 				?>
323
-				<div class="notice notice-warning wc-stripe-request-api-notice is-dismissible"><p><?php esc_html_e( 'New Feature! Stripe now supports Google Payment Request. Your customers can now use mobile phones with supported browsers such as Chrome to make purchases easier and faster.', 'woocommerce-gateway-stripe' ); ?></p></div>
323
+				<div class="notice notice-warning wc-stripe-request-api-notice is-dismissible"><p><?php esc_html_e('New Feature! Stripe now supports Google Payment Request. Your customers can now use mobile phones with supported browsers such as Chrome to make purchases easier and faster.', 'woocommerce-gateway-stripe'); ?></p></div>
324 324
 
325 325
 				<script type="application/javascript">
326 326
 					jQuery( '.wc-stripe-request-api-notice' ).on( 'click', '.notice-dismiss', function() {
@@ -328,16 +328,16 @@  discard block
 block discarded – undo
328 328
 							action: 'stripe_dismiss_request_api_notice'
329 329
 						};
330 330
 
331
-						jQuery.post( '<?php echo admin_url( 'admin-ajax.php' ); ?>', data );
331
+						jQuery.post( '<?php echo admin_url('admin-ajax.php'); ?>', data );
332 332
 					});
333 333
 				</script>
334 334
 
335 335
 				<?php
336 336
 			}
337 337
 
338
-			foreach ( (array) $this->notices as $notice_key => $notice ) {
339
-				echo "<div class='" . esc_attr( $notice['class'] ) . "'><p>";
340
-				echo wp_kses( $notice['message'], array( 'a' => array( 'href' => array() ) ) );
338
+			foreach ((array) $this->notices as $notice_key => $notice) {
339
+				echo "<div class='" . esc_attr($notice['class']) . "'><p>";
340
+				echo wp_kses($notice['message'], array('a' => array('href' => array())));
341 341
 				echo '</p></div>';
342 342
 			}
343 343
 		}
@@ -348,28 +348,28 @@  discard block
 block discarded – undo
348 348
 		 * @since 1.0.0
349 349
 		 */
350 350
 		public function init_gateways() {
351
-			if ( class_exists( 'WC_Subscriptions_Order' ) && function_exists( 'wcs_create_renewal_order' ) ) {
351
+			if (class_exists('WC_Subscriptions_Order') && function_exists('wcs_create_renewal_order')) {
352 352
 				$this->subscription_support_enabled = true;
353 353
 			}
354 354
 
355
-			if ( class_exists( 'WC_Pre_Orders_Order' ) ) {
355
+			if (class_exists('WC_Pre_Orders_Order')) {
356 356
 				$this->pre_order_enabled = true;
357 357
 			}
358 358
 
359
-			if ( ! class_exists( 'WC_Payment_Gateway' ) ) {
359
+			if ( ! class_exists('WC_Payment_Gateway')) {
360 360
 				return;
361 361
 			}
362 362
 
363
-			if ( class_exists( 'WC_Payment_Gateway_CC' ) ) {
364
-				include_once( dirname( __FILE__ ) . '/includes/class-wc-gateway-stripe.php' );
365
-				include_once( dirname( __FILE__ ) . '/includes/class-wc-stripe-apple-pay.php' );
363
+			if (class_exists('WC_Payment_Gateway_CC')) {
364
+				include_once(dirname(__FILE__) . '/includes/class-wc-gateway-stripe.php');
365
+				include_once(dirname(__FILE__) . '/includes/class-wc-stripe-apple-pay.php');
366 366
 			} else {
367
-				include_once( dirname( __FILE__ ) . '/includes/legacy/class-wc-gateway-stripe.php' );
368
-				include_once( dirname( __FILE__ ) . '/includes/legacy/class-wc-gateway-stripe-saved-cards.php' );
367
+				include_once(dirname(__FILE__) . '/includes/legacy/class-wc-gateway-stripe.php');
368
+				include_once(dirname(__FILE__) . '/includes/legacy/class-wc-gateway-stripe-saved-cards.php');
369 369
 			}
370 370
 
371
-			load_plugin_textdomain( 'woocommerce-gateway-stripe', false, plugin_basename( dirname( __FILE__ ) ) . '/languages' );
372
-			add_filter( 'woocommerce_payment_gateways', array( $this, 'add_gateways' ) );
371
+			load_plugin_textdomain('woocommerce-gateway-stripe', false, plugin_basename(dirname(__FILE__)) . '/languages');
372
+			add_filter('woocommerce_payment_gateways', array($this, 'add_gateways'));
373 373
 
374 374
 			$load_addons = (
375 375
 				$this->subscription_support_enabled
@@ -377,8 +377,8 @@  discard block
 block discarded – undo
377 377
 				$this->pre_order_enabled
378 378
 			);
379 379
 
380
-			if ( $load_addons ) {
381
-				require_once( dirname( __FILE__ ) . '/includes/class-wc-gateway-stripe-addons.php' );
380
+			if ($load_addons) {
381
+				require_once(dirname(__FILE__) . '/includes/class-wc-gateway-stripe-addons.php');
382 382
 			}
383 383
 		}
384 384
 
@@ -387,8 +387,8 @@  discard block
 block discarded – undo
387 387
 		 *
388 388
 		 * @since 1.0.0
389 389
 		 */
390
-		public function add_gateways( $methods ) {
391
-			if ( $this->subscription_support_enabled || $this->pre_order_enabled ) {
390
+		public function add_gateways($methods) {
391
+			if ($this->subscription_support_enabled || $this->pre_order_enabled) {
392 392
 				$methods[] = 'WC_Gateway_Stripe_Addons';
393 393
 			} else {
394 394
 				$methods[] = 'WC_Gateway_Stripe';
@@ -428,24 +428,24 @@  discard block
 block discarded – undo
428 428
 		 * @param object $balance_transaction
429 429
 		 * @param string $type Type of number to format
430 430
 		 */
431
-		public static function format_number( $balance_transaction, $type = 'fee' ) {
432
-			if ( ! is_object( $balance_transaction ) ) {
431
+		public static function format_number($balance_transaction, $type = 'fee') {
432
+			if ( ! is_object($balance_transaction)) {
433 433
 				return;
434 434
 			}
435 435
 
436
-			if ( in_array( strtolower( $balance_transaction->currency ), self::no_decimal_currencies() ) ) {
437
-				if ( 'fee' === $type ) {
436
+			if (in_array(strtolower($balance_transaction->currency), self::no_decimal_currencies())) {
437
+				if ('fee' === $type) {
438 438
 					return $balance_transaction->fee;
439 439
 				}
440 440
 
441 441
 				return $balance_transaction->net;
442 442
 			}
443 443
 
444
-			if ( 'fee' === $type ) {
445
-				return number_format( $balance_transaction->fee / 100, 2, '.', '' );
444
+			if ('fee' === $type) {
445
+				return number_format($balance_transaction->fee / 100, 2, '.', '');
446 446
 			}
447 447
 
448
-			return number_format( $balance_transaction->net / 100, 2, '.', '' );
448
+			return number_format($balance_transaction->net / 100, 2, '.', '');
449 449
 		}
450 450
 
451 451
 		/**
@@ -453,36 +453,36 @@  discard block
 block discarded – undo
453 453
 		 *
454 454
 		 * @param  int $order_id
455 455
 		 */
456
-		public function capture_payment( $order_id ) {
457
-			$order = wc_get_order( $order_id );
456
+		public function capture_payment($order_id) {
457
+			$order = wc_get_order($order_id);
458 458
 
459
-			if ( 'stripe' === ( version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->payment_method : $order->get_payment_method() ) ) {
460
-				$charge   = get_post_meta( $order_id, '_stripe_charge_id', true );
461
-				$captured = get_post_meta( $order_id, '_stripe_charge_captured', true );
459
+			if ('stripe' === (version_compare(WC_VERSION, '3.0.0', '<') ? $order->payment_method : $order->get_payment_method())) {
460
+				$charge   = get_post_meta($order_id, '_stripe_charge_id', true);
461
+				$captured = get_post_meta($order_id, '_stripe_charge_captured', true);
462 462
 
463
-				if ( $charge && 'no' === $captured ) {
464
-					$result = WC_Stripe_API::request( array(
463
+				if ($charge && 'no' === $captured) {
464
+					$result = WC_Stripe_API::request(array(
465 465
 						'amount'   => $order->get_total() * 100,
466 466
 						'expand[]' => 'balance_transaction',
467
-					), 'charges/' . $charge . '/capture' );
467
+					), 'charges/' . $charge . '/capture');
468 468
 
469
-					if ( is_wp_error( $result ) ) {
470
-						$order->add_order_note( __( 'Unable to capture charge!', 'woocommerce-gateway-stripe' ) . ' ' . $result->get_error_message() );
469
+					if (is_wp_error($result)) {
470
+						$order->add_order_note(__('Unable to capture charge!', 'woocommerce-gateway-stripe') . ' ' . $result->get_error_message());
471 471
 					} else {
472
-						$order->add_order_note( sprintf( __( 'Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe' ), $result->id ) );
473
-						update_post_meta( $order_id, '_stripe_charge_captured', 'yes' );
472
+						$order->add_order_note(sprintf(__('Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe'), $result->id));
473
+						update_post_meta($order_id, '_stripe_charge_captured', 'yes');
474 474
 
475 475
 						// Store other data such as fees
476
-						update_post_meta( $order_id, 'Stripe Payment ID', $result->id );
477
-						update_post_meta( $order_id, '_transaction_id', $result->id );
476
+						update_post_meta($order_id, 'Stripe Payment ID', $result->id);
477
+						update_post_meta($order_id, '_transaction_id', $result->id);
478 478
 
479
-						if ( isset( $result->balance_transaction ) && isset( $result->balance_transaction->fee ) ) {
479
+						if (isset($result->balance_transaction) && isset($result->balance_transaction->fee)) {
480 480
 							// Fees and Net needs to both come from Stripe to be accurate as the returned
481 481
 							// values are in the local currency of the Stripe account, not from WC.
482
-							$fee = ! empty( $result->balance_transaction->fee ) ? self::format_number( $result->balance_transaction, 'fee' ) : 0;
483
-							$net = ! empty( $result->balance_transaction->net ) ? self::format_number( $result->balance_transaction, 'net' ) : 0;
484
-							update_post_meta( $order_id, 'Stripe Fee', $fee );
485
-							update_post_meta( $order_id, 'Net Revenue From Stripe', $net );
482
+							$fee = ! empty($result->balance_transaction->fee) ? self::format_number($result->balance_transaction, 'fee') : 0;
483
+							$net = ! empty($result->balance_transaction->net) ? self::format_number($result->balance_transaction, 'net') : 0;
484
+							update_post_meta($order_id, 'Stripe Fee', $fee);
485
+							update_post_meta($order_id, 'Net Revenue From Stripe', $net);
486 486
 						}
487 487
 					}
488 488
 				}
@@ -494,23 +494,23 @@  discard block
 block discarded – undo
494 494
 		 *
495 495
 		 * @param  int $order_id
496 496
 		 */
497
-		public function cancel_payment( $order_id ) {
498
-			$order = wc_get_order( $order_id );
497
+		public function cancel_payment($order_id) {
498
+			$order = wc_get_order($order_id);
499 499
 
500
-			if ( 'stripe' === ( version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->payment_method : $order->get_payment_method() ) ) {
501
-				$charge   = get_post_meta( $order_id, '_stripe_charge_id', true );
500
+			if ('stripe' === (version_compare(WC_VERSION, '3.0.0', '<') ? $order->payment_method : $order->get_payment_method())) {
501
+				$charge = get_post_meta($order_id, '_stripe_charge_id', true);
502 502
 
503
-				if ( $charge ) {
504
-					$result = WC_Stripe_API::request( array(
503
+				if ($charge) {
504
+					$result = WC_Stripe_API::request(array(
505 505
 						'amount' => $order->get_total() * 100,
506
-					), 'charges/' . $charge . '/refund' );
506
+					), 'charges/' . $charge . '/refund');
507 507
 
508
-					if ( is_wp_error( $result ) ) {
509
-						$order->add_order_note( __( 'Unable to refund charge!', 'woocommerce-gateway-stripe' ) . ' ' . $result->get_error_message() );
508
+					if (is_wp_error($result)) {
509
+						$order->add_order_note(__('Unable to refund charge!', 'woocommerce-gateway-stripe') . ' ' . $result->get_error_message());
510 510
 					} else {
511
-						$order->add_order_note( sprintf( __( 'Stripe charge refunded (Charge ID: %s)', 'woocommerce-gateway-stripe' ), $result->id ) );
512
-						delete_post_meta( $order_id, '_stripe_charge_captured' );
513
-						delete_post_meta( $order_id, '_stripe_charge_id' );
511
+						$order->add_order_note(sprintf(__('Stripe charge refunded (Charge ID: %s)', 'woocommerce-gateway-stripe'), $result->id));
512
+						delete_post_meta($order_id, '_stripe_charge_captured');
513
+						delete_post_meta($order_id, '_stripe_charge_id');
514 514
 					}
515 515
 				}
516 516
 			}
@@ -521,28 +521,28 @@  discard block
 block discarded – undo
521 521
 		 * @param array $tokens
522 522
 		 * @return array
523 523
 		 */
524
-		public function woocommerce_get_customer_payment_tokens( $tokens, $customer_id, $gateway_id ) {
525
-			if ( is_user_logged_in() && 'stripe' === $gateway_id && class_exists( 'WC_Payment_Token_CC' ) ) {
526
-				$stripe_customer = new WC_Stripe_Customer( $customer_id );
524
+		public function woocommerce_get_customer_payment_tokens($tokens, $customer_id, $gateway_id) {
525
+			if (is_user_logged_in() && 'stripe' === $gateway_id && class_exists('WC_Payment_Token_CC')) {
526
+				$stripe_customer = new WC_Stripe_Customer($customer_id);
527 527
 				$stripe_cards    = $stripe_customer->get_cards();
528 528
 				$stored_tokens   = array();
529 529
 
530
-				foreach ( $tokens as $token ) {
530
+				foreach ($tokens as $token) {
531 531
 					$stored_tokens[] = $token->get_token();
532 532
 				}
533 533
 
534
-				foreach ( $stripe_cards as $card ) {
535
-					if ( ! in_array( $card->id, $stored_tokens ) ) {
534
+				foreach ($stripe_cards as $card) {
535
+					if ( ! in_array($card->id, $stored_tokens)) {
536 536
 						$token = new WC_Payment_Token_CC();
537
-						$token->set_token( $card->id );
538
-						$token->set_gateway_id( 'stripe' );
539
-						$token->set_card_type( strtolower( $card->brand ) );
540
-						$token->set_last4( $card->last4 );
541
-						$token->set_expiry_month( $card->exp_month );
542
-						$token->set_expiry_year( $card->exp_year );
543
-						$token->set_user_id( $customer_id );
537
+						$token->set_token($card->id);
538
+						$token->set_gateway_id('stripe');
539
+						$token->set_card_type(strtolower($card->brand));
540
+						$token->set_last4($card->last4);
541
+						$token->set_expiry_month($card->exp_month);
542
+						$token->set_expiry_year($card->exp_year);
543
+						$token->set_user_id($customer_id);
544 544
 						$token->save();
545
-						$tokens[ $token->get_id() ] = $token;
545
+						$tokens[$token->get_id()] = $token;
546 546
 					}
547 547
 				}
548 548
 			}
@@ -552,21 +552,21 @@  discard block
 block discarded – undo
552 552
 		/**
553 553
 		 * Delete token from Stripe
554 554
 		 */
555
-		public function woocommerce_payment_token_deleted( $token_id, $token ) {
556
-			if ( 'stripe' === $token->get_gateway_id() ) {
557
-				$stripe_customer = new WC_Stripe_Customer( get_current_user_id() );
558
-				$stripe_customer->delete_card( $token->get_token() );
555
+		public function woocommerce_payment_token_deleted($token_id, $token) {
556
+			if ('stripe' === $token->get_gateway_id()) {
557
+				$stripe_customer = new WC_Stripe_Customer(get_current_user_id());
558
+				$stripe_customer->delete_card($token->get_token());
559 559
 			}
560 560
 		}
561 561
 
562 562
 		/**
563 563
 		 * Set as default in Stripe
564 564
 		 */
565
-		public function woocommerce_payment_token_set_default( $token_id ) {
566
-			$token = WC_Payment_Tokens::get( $token_id );
567
-			if ( 'stripe' === $token->get_gateway_id() ) {
568
-				$stripe_customer = new WC_Stripe_Customer( get_current_user_id() );
569
-				$stripe_customer->set_default_card( $token->get_token() );
565
+		public function woocommerce_payment_token_set_default($token_id) {
566
+			$token = WC_Payment_Tokens::get($token_id);
567
+			if ('stripe' === $token->get_gateway_id()) {
568
+				$stripe_customer = new WC_Stripe_Customer(get_current_user_id());
569
+				$stripe_customer->set_default_card($token->get_token());
570 570
 			}
571 571
 		}
572 572
 
@@ -575,7 +575,7 @@  discard block
 block discarded – undo
575 575
 		 */
576 576
 		public static function get_minimum_amount() {
577 577
 			// Check order amount
578
-			switch ( get_woocommerce_currency() ) {
578
+			switch (get_woocommerce_currency()) {
579 579
 				case 'USD':
580 580
 				case 'CAD':
581 581
 				case 'EUR':
@@ -619,12 +619,12 @@  discard block
 block discarded – undo
619 619
 		 * And fits on your back?
620 620
 		 * It's log, log, log
621 621
 		 */
622
-		public static function log( $message ) {
623
-			if ( empty( self::$log ) ) {
622
+		public static function log($message) {
623
+			if (empty(self::$log)) {
624 624
 				self::$log = new WC_Logger();
625 625
 			}
626 626
 
627
-			self::$log->add( 'woocommerce-gateway-stripe', $message );
627
+			self::$log->add('woocommerce-gateway-stripe', $message);
628 628
 		}
629 629
 	}
630 630
 
Please login to merge, or discard this patch.
includes/class-wc-gateway-stripe-addons.php 2 patches
Doc Comments   +3 added lines, -2 removed lines patch added patch discarded remove patch
@@ -103,7 +103,6 @@  discard block
 block discarded – undo
103 103
 	 * process_subscription_payment function.
104 104
 	 * @param mixed $order
105 105
 	 * @param int $amount (default: 0)
106
-	 * @param string $stripe_token (default: '')
107 106
 	 * @param  bool initial_payment
108 107
 	 */
109 108
 	public function process_subscription_payment( $order = '', $amount = 0 ) {
@@ -160,6 +159,8 @@  discard block
 block discarded – undo
160 159
 	/**
161 160
 	 * Process the pre-order
162 161
 	 * @param int $order_id
162
+	 * @param boolean $retry
163
+	 * @param boolean $force_customer
163 164
 	 * @return array
164 165
 	 */
165 166
 	public function process_pre_order( $order_id, $retry, $force_customer ) {
@@ -256,7 +257,7 @@  discard block
 block discarded – undo
256 257
 
257 258
 	/**
258 259
 	 * Don't transfer Stripe fee/ID meta to renewal orders.
259
-	 * @param int $resubscribe_order The order created for the customer to resubscribe to the old expired/cancelled subscription
260
+	 * @param integer $renewal_order
260 261
 	 */
261 262
 	public function delete_renewal_meta( $renewal_order ) {
262 263
 		delete_post_meta( ( $this->wc_pre_30 ? $renewal_order->id : $renewal_order->get_id() ), 'Stripe Fee' );
Please login to merge, or discard this patch.
Spacing   +136 added lines, -136 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
 
@@ -18,25 +18,25 @@  discard block
 block discarded – undo
18 18
 	public function __construct() {
19 19
 		parent::__construct();
20 20
 
21
-		if ( class_exists( 'WC_Subscriptions_Order' ) ) {
22
-			add_action( 'woocommerce_scheduled_subscription_payment_' . $this->id, array( $this, 'scheduled_subscription_payment' ), 10, 2 );
23
-			add_action( 'wcs_resubscribe_order_created', array( $this, 'delete_resubscribe_meta' ), 10 );
24
-			add_action( 'wcs_renewal_order_created', array( $this, 'delete_renewal_meta' ), 10 );
25
-			add_action( 'woocommerce_subscription_failing_payment_method_updated_stripe', array( $this, 'update_failing_payment_method' ), 10, 2 );
21
+		if (class_exists('WC_Subscriptions_Order')) {
22
+			add_action('woocommerce_scheduled_subscription_payment_' . $this->id, array($this, 'scheduled_subscription_payment'), 10, 2);
23
+			add_action('wcs_resubscribe_order_created', array($this, 'delete_resubscribe_meta'), 10);
24
+			add_action('wcs_renewal_order_created', array($this, 'delete_renewal_meta'), 10);
25
+			add_action('woocommerce_subscription_failing_payment_method_updated_stripe', array($this, 'update_failing_payment_method'), 10, 2);
26 26
 
27 27
 			// display the credit card used for a subscription in the "My Subscriptions" table
28
-			add_filter( 'woocommerce_my_subscriptions_payment_method', array( $this, 'maybe_render_subscription_payment_method' ), 10, 2 );
28
+			add_filter('woocommerce_my_subscriptions_payment_method', array($this, 'maybe_render_subscription_payment_method'), 10, 2);
29 29
 
30 30
 			// allow store managers to manually set Stripe as the payment method on a subscription
31
-			add_filter( 'woocommerce_subscription_payment_meta', array( $this, 'add_subscription_payment_meta' ), 10, 2 );
32
-			add_filter( 'woocommerce_subscription_validate_payment_meta', array( $this, 'validate_subscription_payment_meta' ), 10, 2 );
31
+			add_filter('woocommerce_subscription_payment_meta', array($this, 'add_subscription_payment_meta'), 10, 2);
32
+			add_filter('woocommerce_subscription_validate_payment_meta', array($this, 'validate_subscription_payment_meta'), 10, 2);
33 33
 		}
34 34
 
35
-		if ( class_exists( 'WC_Pre_Orders_Order' ) ) {
36
-			add_action( 'wc_pre_orders_process_pre_order_completion_payment_' . $this->id, array( $this, 'process_pre_order_release_payment' ) );
35
+		if (class_exists('WC_Pre_Orders_Order')) {
36
+			add_action('wc_pre_orders_process_pre_order_completion_payment_' . $this->id, array($this, 'process_pre_order_release_payment'));
37 37
 		}
38 38
 
39
-		$this->wc_pre_30 = version_compare( WC_VERSION, '3.0.0', '<' );
39
+		$this->wc_pre_30 = version_compare(WC_VERSION, '3.0.0', '<');
40 40
 	}
41 41
 
42 42
 	/**
@@ -44,8 +44,8 @@  discard block
 block discarded – undo
44 44
 	 * @param  int  $order_id
45 45
 	 * @return boolean
46 46
 	 */
47
-	protected function is_subscription( $order_id ) {
48
-		return ( function_exists( 'wcs_order_contains_subscription' ) && ( wcs_order_contains_subscription( $order_id ) || wcs_is_subscription( $order_id ) || wcs_order_contains_renewal( $order_id ) ) );
47
+	protected function is_subscription($order_id) {
48
+		return (function_exists('wcs_order_contains_subscription') && (wcs_order_contains_subscription($order_id) || wcs_is_subscription($order_id) || wcs_order_contains_renewal($order_id)));
49 49
 	}
50 50
 
51 51
 	/**
@@ -53,8 +53,8 @@  discard block
 block discarded – undo
53 53
 	 * @param  int  $order_id
54 54
 	 * @return boolean
55 55
 	 */
56
-	protected function is_pre_order( $order_id ) {
57
-		return ( class_exists( 'WC_Pre_Orders_Order' ) && WC_Pre_Orders_Order::order_contains_pre_order( $order_id ) );
56
+	protected function is_pre_order($order_id) {
57
+		return (class_exists('WC_Pre_Orders_Order') && WC_Pre_Orders_Order::order_contains_pre_order($order_id));
58 58
 	}
59 59
 
60 60
 	/**
@@ -62,40 +62,40 @@  discard block
 block discarded – undo
62 62
 	 * @param  int $order_id
63 63
 	 * @return array
64 64
 	 */
65
-	public function process_payment( $order_id, $retry = true, $force_customer = false ) {
66
-		if ( $this->is_subscription( $order_id ) ) {
65
+	public function process_payment($order_id, $retry = true, $force_customer = false) {
66
+		if ($this->is_subscription($order_id)) {
67 67
 			// Regular payment with force customer enabled
68
-			return parent::process_payment( $order_id, true, true );
68
+			return parent::process_payment($order_id, true, true);
69 69
 
70
-		} elseif ( $this->is_pre_order( $order_id ) ) {
71
-			return $this->process_pre_order( $order_id, $retry, $force_customer );
70
+		} elseif ($this->is_pre_order($order_id)) {
71
+			return $this->process_pre_order($order_id, $retry, $force_customer);
72 72
 
73 73
 		} else {
74
-			return parent::process_payment( $order_id, $retry, $force_customer );
74
+			return parent::process_payment($order_id, $retry, $force_customer);
75 75
 		}
76 76
 	}
77 77
 
78 78
 	/**
79 79
 	 * Updates other subscription sources.
80 80
 	 */
81
-	protected function save_source( $order, $source ) {
82
-		parent::save_source( $order, $source );
81
+	protected function save_source($order, $source) {
82
+		parent::save_source($order, $source);
83 83
 
84
-		$order_id  = $this->wc_pre_30 ? $order->id : $order->get_id();
84
+		$order_id = $this->wc_pre_30 ? $order->id : $order->get_id();
85 85
 
86 86
 		// Also store it on the subscriptions being purchased or paid for in the order
87
-		if ( function_exists( 'wcs_order_contains_subscription' ) && wcs_order_contains_subscription( $order_id ) ) {
88
-			$subscriptions = wcs_get_subscriptions_for_order( $order_id );
89
-		} elseif ( function_exists( 'wcs_order_contains_renewal' ) && wcs_order_contains_renewal( $order_id ) ) {
90
-			$subscriptions = wcs_get_subscriptions_for_renewal_order( $order_id );
87
+		if (function_exists('wcs_order_contains_subscription') && wcs_order_contains_subscription($order_id)) {
88
+			$subscriptions = wcs_get_subscriptions_for_order($order_id);
89
+		} elseif (function_exists('wcs_order_contains_renewal') && wcs_order_contains_renewal($order_id)) {
90
+			$subscriptions = wcs_get_subscriptions_for_renewal_order($order_id);
91 91
 		} else {
92 92
 			$subscriptions = array();
93 93
 		}
94 94
 
95
-		foreach ( $subscriptions as $subscription ) {
95
+		foreach ($subscriptions as $subscription) {
96 96
 			$subscription_id = $this->wc_pre_30 ? $subscription->id : $subscription->get_id();
97
-			update_post_meta( $subscription_id, '_stripe_customer_id', $source->customer );
98
-			update_post_meta( $subscription_id, '_stripe_card_id', $source->source );
97
+			update_post_meta($subscription_id, '_stripe_customer_id', $source->customer);
98
+			update_post_meta($subscription_id, '_stripe_card_id', $source->source);
99 99
 		}
100 100
 	}
101 101
 
@@ -106,55 +106,55 @@  discard block
 block discarded – undo
106 106
 	 * @param string $stripe_token (default: '')
107 107
 	 * @param  bool initial_payment
108 108
 	 */
109
-	public function process_subscription_payment( $order = '', $amount = 0 ) {
110
-		if ( $amount * 100 < WC_Stripe::get_minimum_amount() ) {
111
-			return new WP_Error( 'stripe_error', 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 ) ) );
109
+	public function process_subscription_payment($order = '', $amount = 0) {
110
+		if ($amount * 100 < WC_Stripe::get_minimum_amount()) {
111
+			return new WP_Error('stripe_error', 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)));
112 112
 		}
113 113
 
114 114
 		// Get source from order
115
-		$source = $this->get_order_source( $order );
115
+		$source = $this->get_order_source($order);
116 116
 
117 117
 		// If no order source was defined, use user source instead.
118
-		if ( ! $source->customer ) {
119
-			$source = $this->get_source( ( $this->wc_pre_30 ? $order->customer_user : $order->get_customer_id() ) );
118
+		if ( ! $source->customer) {
119
+			$source = $this->get_source(($this->wc_pre_30 ? $order->customer_user : $order->get_customer_id()));
120 120
 		}
121 121
 
122 122
 		// Or fail :(
123
-		if ( ! $source->customer ) {
124
-			return new WP_Error( 'stripe_error', __( 'Customer not found', 'woocommerce-gateway-stripe' ) );
123
+		if ( ! $source->customer) {
124
+			return new WP_Error('stripe_error', __('Customer not found', 'woocommerce-gateway-stripe'));
125 125
 		}
126 126
 
127 127
 		$order_id = $this->wc_pre_30 ? $order->id : $order->get_id();
128
-		$this->log( "Info: Begin processing subscription payment for order {$order_id} for the amount of {$amount}" );
128
+		$this->log("Info: Begin processing subscription payment for order {$order_id} for the amount of {$amount}");
129 129
 
130 130
 		// Make the request
131
-		$request             = $this->generate_payment_request( $order, $source );
131
+		$request             = $this->generate_payment_request($order, $source);
132 132
 		$request['capture']  = 'true';
133
-		$request['amount']   = $this->get_stripe_amount( $amount, $request['currency'] );
133
+		$request['amount']   = $this->get_stripe_amount($amount, $request['currency']);
134 134
 		$request['metadata'] = array(
135 135
 			'payment_type'   => 'recurring',
136
-			'site_url'       => esc_url( get_site_url() ),
136
+			'site_url'       => esc_url(get_site_url()),
137 137
 		);
138
-		$response            = WC_Stripe_API::request( $request );
138
+		$response = WC_Stripe_API::request($request);
139 139
 
140 140
 		// Process valid response
141
-		if ( is_wp_error( $response ) ) {
142
-			if ( 'missing' === $response->get_error_code() ) {
141
+		if (is_wp_error($response)) {
142
+			if ('missing' === $response->get_error_code()) {
143 143
 				// If we can't link customer to a card, we try to charge by customer ID.
144
-				$request             = $this->generate_payment_request( $order, $this->get_source( ( $this->wc_pre_30 ? $order->customer_user : $order->get_customer_id() ) ) );
144
+				$request             = $this->generate_payment_request($order, $this->get_source(($this->wc_pre_30 ? $order->customer_user : $order->get_customer_id())));
145 145
 				$request['capture']  = 'true';
146
-				$request['amount']   = $this->get_stripe_amount( $amount, $request['currency'] );
146
+				$request['amount']   = $this->get_stripe_amount($amount, $request['currency']);
147 147
 				$request['metadata'] = array(
148 148
 					'payment_type'   => 'recurring',
149
-					'site_url'       => esc_url( get_site_url() ),
149
+					'site_url'       => esc_url(get_site_url()),
150 150
 				);
151
-				$response          = WC_Stripe_API::request( $request );
151
+				$response = WC_Stripe_API::request($request);
152 152
 			} else {
153 153
 				return $response; // Default catch all errors.
154 154
 			}
155 155
 		}
156 156
 
157
-		$this->process_response( $response, $order );
157
+		$this->process_response($response, $order);
158 158
 
159 159
 		return $response;
160 160
 	}
@@ -164,42 +164,42 @@  discard block
 block discarded – undo
164 164
 	 * @param int $order_id
165 165
 	 * @return array
166 166
 	 */
167
-	public function process_pre_order( $order_id, $retry, $force_customer ) {
168
-		if ( WC_Pre_Orders_Order::order_requires_payment_tokenization( $order_id ) ) {
167
+	public function process_pre_order($order_id, $retry, $force_customer) {
168
+		if (WC_Pre_Orders_Order::order_requires_payment_tokenization($order_id)) {
169 169
 			try {
170
-				$order = wc_get_order( $order_id );
170
+				$order = wc_get_order($order_id);
171 171
 
172
-				if ( $order->get_total() * 100 < WC_Stripe::get_minimum_amount() ) {
173
-					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 ) ) );
172
+				if ($order->get_total() * 100 < WC_Stripe::get_minimum_amount()) {
173
+					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)));
174 174
 				}
175 175
 
176
-				$source = $this->get_source( get_current_user_id(), true );
176
+				$source = $this->get_source(get_current_user_id(), true);
177 177
 
178 178
 				// We need a source on file to continue.
179
-				if ( empty( $source->customer ) || empty( $source->source ) ) {
180
-					throw new Exception( __( 'Unable to store payment details. Please try again.', 'woocommerce-gateway-stripe' ) );
179
+				if (empty($source->customer) || empty($source->source)) {
180
+					throw new Exception(__('Unable to store payment details. Please try again.', 'woocommerce-gateway-stripe'));
181 181
 				}
182 182
 
183 183
 				// Store source to order meta
184
-				$this->save_source( $order, $source );
184
+				$this->save_source($order, $source);
185 185
 
186 186
 				// Remove cart
187 187
 				WC()->cart->empty_cart();
188 188
 
189 189
 				// Is pre ordered!
190
-				WC_Pre_Orders_Order::mark_order_as_pre_ordered( $order );
190
+				WC_Pre_Orders_Order::mark_order_as_pre_ordered($order);
191 191
 
192 192
 				// Return thank you page redirect
193 193
 				return array(
194 194
 					'result'   => 'success',
195
-					'redirect' => $this->get_return_url( $order ),
195
+					'redirect' => $this->get_return_url($order),
196 196
 				);
197
-			} catch ( Exception $e ) {
198
-				wc_add_notice( $e->getMessage(), 'error' );
197
+			} catch (Exception $e) {
198
+				wc_add_notice($e->getMessage(), 'error');
199 199
 				return;
200 200
 			}
201 201
 		} else {
202
-			return parent::process_payment( $order_id, $retry, $force_customer );
202
+			return parent::process_payment($order_id, $retry, $force_customer);
203 203
 		}
204 204
 	}
205 205
 
@@ -208,7 +208,7 @@  discard block
 block discarded – undo
208 208
 	 * @param WC_Order $order
209 209
 	 * @return void
210 210
 	 */
211
-	public function process_pre_order_release_payment( $order ) {
211
+	public function process_pre_order_release_payment($order) {
212 212
 		try {
213 213
 			// Define some callbacks if the first attempt fails.
214 214
 			$retry_callbacks = array(
@@ -216,32 +216,32 @@  discard block
 block discarded – undo
216 216
 				'remove_order_customer_before_retry',
217 217
 			);
218 218
 
219
-			while ( 1 ) {
220
-				$source   = $this->get_order_source( $order );
221
-				$response = WC_Stripe_API::request( $this->generate_payment_request( $order, $source ) );
219
+			while (1) {
220
+				$source   = $this->get_order_source($order);
221
+				$response = WC_Stripe_API::request($this->generate_payment_request($order, $source));
222 222
 
223
-				if ( is_wp_error( $response ) ) {
224
-					if ( 0 === sizeof( $retry_callbacks ) ) {
225
-						throw new Exception( $response->get_error_message() );
223
+				if (is_wp_error($response)) {
224
+					if (0 === sizeof($retry_callbacks)) {
225
+						throw new Exception($response->get_error_message());
226 226
 					} else {
227
-						$retry_callback = array_shift( $retry_callbacks );
228
-						call_user_func( array( $this, $retry_callback ), $order );
227
+						$retry_callback = array_shift($retry_callbacks);
228
+						call_user_func(array($this, $retry_callback), $order);
229 229
 					}
230 230
 				} else {
231 231
 					// Successful
232
-					$this->process_response( $response, $order );
232
+					$this->process_response($response, $order);
233 233
 					break;
234 234
 				}
235 235
 			}
236
-		} catch ( Exception $e ) {
237
-			$order_note = sprintf( __( 'Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe' ), $e->getMessage() );
236
+		} catch (Exception $e) {
237
+			$order_note = sprintf(__('Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe'), $e->getMessage());
238 238
 
239 239
 			// Mark order as failed if not already set,
240 240
 			// otherwise, make sure we add the order note so we can detect when someone fails to check out multiple times
241
-			if ( ! $order->has_status( 'failed' ) ) {
242
-				$order->update_status( 'failed', $order_note );
241
+			if ( ! $order->has_status('failed')) {
242
+				$order->update_status('failed', $order_note);
243 243
 			} else {
244
-				$order->add_order_note( $order_note );
244
+				$order->add_order_note($order_note);
245 245
 			}
246 246
 		}
247 247
 	}
@@ -250,20 +250,20 @@  discard block
 block discarded – undo
250 250
 	 * Don't transfer Stripe customer/token meta to resubscribe orders.
251 251
 	 * @param int $resubscribe_order The order created for the customer to resubscribe to the old expired/cancelled subscription
252 252
 	 */
253
-	public function delete_resubscribe_meta( $resubscribe_order ) {
254
-		delete_post_meta( ( $this->wc_pre_30 ? $resubscribe_order->id : $resubscribe_order->get_id() ), '_stripe_customer_id' );
255
-		delete_post_meta( ( $this->wc_pre_30 ? $resubscribe_order->id : $resubscribe_order->get_id() ), '_stripe_card_id' );
256
-		$this->delete_renewal_meta( $resubscribe_order );
253
+	public function delete_resubscribe_meta($resubscribe_order) {
254
+		delete_post_meta(($this->wc_pre_30 ? $resubscribe_order->id : $resubscribe_order->get_id()), '_stripe_customer_id');
255
+		delete_post_meta(($this->wc_pre_30 ? $resubscribe_order->id : $resubscribe_order->get_id()), '_stripe_card_id');
256
+		$this->delete_renewal_meta($resubscribe_order);
257 257
 	}
258 258
 
259 259
 	/**
260 260
 	 * Don't transfer Stripe fee/ID meta to renewal orders.
261 261
 	 * @param int $resubscribe_order The order created for the customer to resubscribe to the old expired/cancelled subscription
262 262
 	 */
263
-	public function delete_renewal_meta( $renewal_order ) {
264
-		delete_post_meta( ( $this->wc_pre_30 ? $renewal_order->id : $renewal_order->get_id() ), 'Stripe Fee' );
265
-		delete_post_meta( ( $this->wc_pre_30 ? $renewal_order->id : $renewal_order->get_id() ), 'Net Revenue From Stripe' );
266
-		delete_post_meta( ( $this->wc_pre_30 ? $renewal_order->id : $renewal_order->get_id() ), 'Stripe Payment ID' );
263
+	public function delete_renewal_meta($renewal_order) {
264
+		delete_post_meta(($this->wc_pre_30 ? $renewal_order->id : $renewal_order->get_id()), 'Stripe Fee');
265
+		delete_post_meta(($this->wc_pre_30 ? $renewal_order->id : $renewal_order->get_id()), 'Net Revenue From Stripe');
266
+		delete_post_meta(($this->wc_pre_30 ? $renewal_order->id : $renewal_order->get_id()), 'Stripe Payment ID');
267 267
 		return $renewal_order;
268 268
 	}
269 269
 
@@ -273,11 +273,11 @@  discard block
 block discarded – undo
273 273
 	 * @param $amount_to_charge float The amount to charge.
274 274
 	 * @param $renewal_order WC_Order A WC_Order object created to record the renewal payment.
275 275
 	 */
276
-	public function scheduled_subscription_payment( $amount_to_charge, $renewal_order ) {
277
-		$response = $this->process_subscription_payment( $renewal_order, $amount_to_charge );
276
+	public function scheduled_subscription_payment($amount_to_charge, $renewal_order) {
277
+		$response = $this->process_subscription_payment($renewal_order, $amount_to_charge);
278 278
 
279
-		if ( is_wp_error( $response ) ) {
280
-			$renewal_order->update_status( 'failed', sprintf( __( 'Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe' ), $response->get_error_message() ) );
279
+		if (is_wp_error($response)) {
280
+			$renewal_order->update_status('failed', sprintf(__('Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe'), $response->get_error_message()));
281 281
 		}
282 282
 	}
283 283
 
@@ -285,18 +285,18 @@  discard block
 block discarded – undo
285 285
 	 * Remove order meta
286 286
 	 * @param  object $order
287 287
 	 */
288
-	public function remove_order_source_before_retry( $order ) {
288
+	public function remove_order_source_before_retry($order) {
289 289
 		$order_id = $this->wc_pre_30 ? $order->id : $order->get_id();
290
-		delete_post_meta( $order_id, '_stripe_card_id' );
290
+		delete_post_meta($order_id, '_stripe_card_id');
291 291
 	}
292 292
 
293 293
 	/**
294 294
 	 * Remove order meta
295 295
 	 * @param  object $order
296 296
 	 */
297
-	public function remove_order_customer_before_retry( $order ) {
297
+	public function remove_order_customer_before_retry($order) {
298 298
 		$order_id = $this->wc_pre_30 ? $order->id : $order->get_id();
299
-		delete_post_meta( $order_id, '_stripe_customer_id' );
299
+		delete_post_meta($order_id, '_stripe_customer_id');
300 300
 	}
301 301
 
302 302
 	/**
@@ -308,13 +308,13 @@  discard block
 block discarded – undo
308 308
 	 * @param WC_Order $renewal_order The order which recorded the successful payment (to make up for the failed automatic payment).
309 309
 	 * @return void
310 310
 	 */
311
-	public function update_failing_payment_method( $subscription, $renewal_order ) {
312
-		if ( $this->wc_pre_30 ) {
313
-			update_post_meta( $subscription->id, '_stripe_customer_id', $renewal_order->stripe_customer_id );
314
-			update_post_meta( $subscription->id, '_stripe_card_id', $renewal_order->stripe_card_id );
311
+	public function update_failing_payment_method($subscription, $renewal_order) {
312
+		if ($this->wc_pre_30) {
313
+			update_post_meta($subscription->id, '_stripe_customer_id', $renewal_order->stripe_customer_id);
314
+			update_post_meta($subscription->id, '_stripe_card_id', $renewal_order->stripe_card_id);
315 315
 		} else {
316
-			$subscription->update_meta_data( '_stripe_customer_id', $renewal_order->get_meta( '_stripe_customer_id', true ) );
317
-			$subscription->update_meta_data( '_stripe_card_id', $renewal_order->get_meta( '_stripe_card_id', true ) );
316
+			$subscription->update_meta_data('_stripe_customer_id', $renewal_order->get_meta('_stripe_customer_id', true));
317
+			$subscription->update_meta_data('_stripe_card_id', $renewal_order->get_meta('_stripe_card_id', true));
318 318
 		}
319 319
 	}
320 320
 
@@ -327,15 +327,15 @@  discard block
 block discarded – undo
327 327
 	 * @param WC_Subscription $subscription An instance of a subscription object
328 328
 	 * @return array
329 329
 	 */
330
-	public function add_subscription_payment_meta( $payment_meta, $subscription ) {
331
-		$payment_meta[ $this->id ] = array(
330
+	public function add_subscription_payment_meta($payment_meta, $subscription) {
331
+		$payment_meta[$this->id] = array(
332 332
 			'post_meta' => array(
333 333
 				'_stripe_customer_id' => array(
334
-					'value' => get_post_meta( ( $this->wc_pre_30 ? $subscription->id : $subscription->get_id() ), '_stripe_customer_id', true ),
334
+					'value' => get_post_meta(($this->wc_pre_30 ? $subscription->id : $subscription->get_id()), '_stripe_customer_id', true),
335 335
 					'label' => 'Stripe Customer ID',
336 336
 				),
337 337
 				'_stripe_card_id' => array(
338
-					'value' => get_post_meta( ( $this->wc_pre_30 ? $subscription->id : $subscription->get_id() ), '_stripe_card_id', true ),
338
+					'value' => get_post_meta(($this->wc_pre_30 ? $subscription->id : $subscription->get_id()), '_stripe_card_id', true),
339 339
 					'label' => 'Stripe Card ID',
340 340
 				),
341 341
 			),
@@ -352,17 +352,17 @@  discard block
 block discarded – undo
352 352
 	 * @param array $payment_meta associative array of meta data required for automatic payments
353 353
 	 * @return array
354 354
 	 */
355
-	public function validate_subscription_payment_meta( $payment_method_id, $payment_meta ) {
356
-		if ( $this->id === $payment_method_id ) {
355
+	public function validate_subscription_payment_meta($payment_method_id, $payment_meta) {
356
+		if ($this->id === $payment_method_id) {
357 357
 
358
-			if ( ! isset( $payment_meta['post_meta']['_stripe_customer_id']['value'] ) || empty( $payment_meta['post_meta']['_stripe_customer_id']['value'] ) ) {
359
-				throw new Exception( 'A "_stripe_customer_id" value is required.' );
360
-			} elseif ( 0 !== strpos( $payment_meta['post_meta']['_stripe_customer_id']['value'], 'cus_' ) ) {
361
-				throw new Exception( 'Invalid customer ID. A valid "_stripe_customer_id" must begin with "cus_".' );
358
+			if ( ! isset($payment_meta['post_meta']['_stripe_customer_id']['value']) || empty($payment_meta['post_meta']['_stripe_customer_id']['value'])) {
359
+				throw new Exception('A "_stripe_customer_id" value is required.');
360
+			} elseif (0 !== strpos($payment_meta['post_meta']['_stripe_customer_id']['value'], 'cus_')) {
361
+				throw new Exception('Invalid customer ID. A valid "_stripe_customer_id" must begin with "cus_".');
362 362
 			}
363 363
 
364
-			if ( ! empty( $payment_meta['post_meta']['_stripe_card_id']['value'] ) && 0 !== strpos( $payment_meta['post_meta']['_stripe_card_id']['value'], 'card_' ) ) {
365
-				throw new Exception( 'Invalid card ID. A valid "_stripe_card_id" must begin with "card_".' );
364
+			if ( ! empty($payment_meta['post_meta']['_stripe_card_id']['value']) && 0 !== strpos($payment_meta['post_meta']['_stripe_card_id']['value'], 'card_')) {
365
+				throw new Exception('Invalid card ID. A valid "_stripe_card_id" must begin with "card_".');
366 366
 			}
367 367
 		}
368 368
 	}
@@ -375,45 +375,45 @@  discard block
 block discarded – undo
375 375
 	 * @param WC_Subscription $subscription the subscription details
376 376
 	 * @return string the subscription payment method
377 377
 	 */
378
-	public function maybe_render_subscription_payment_method( $payment_method_to_display, $subscription ) {
378
+	public function maybe_render_subscription_payment_method($payment_method_to_display, $subscription) {
379 379
 		$customer_user = $this->wc_pre_30 ? $subscription->customer_user : $subscription->get_customer_id();
380 380
 
381 381
 		// bail for other payment methods
382
-		if ( $this->id !== ( $this->wc_pre_30 ? $subscription->payment_method : $subscription->get_payment_method() ) || ! $customer_user ) {
382
+		if ($this->id !== ($this->wc_pre_30 ? $subscription->payment_method : $subscription->get_payment_method()) || ! $customer_user) {
383 383
 			return $payment_method_to_display;
384 384
 		}
385 385
 
386 386
 		$stripe_customer    = new WC_Stripe_Customer();
387
-		$stripe_customer_id = get_post_meta( ( $this->wc_pre_30 ? $subscription->id : $subscription->get_id() ), '_stripe_customer_id', true );
388
-		$stripe_card_id     = get_post_meta( ( $this->wc_pre_30 ? $subscription->id : $subscription->get_id() ), '_stripe_card_id', true );
387
+		$stripe_customer_id = get_post_meta(($this->wc_pre_30 ? $subscription->id : $subscription->get_id()), '_stripe_customer_id', true);
388
+		$stripe_card_id     = get_post_meta(($this->wc_pre_30 ? $subscription->id : $subscription->get_id()), '_stripe_card_id', true);
389 389
 
390 390
 		// If we couldn't find a Stripe customer linked to the subscription, fallback to the user meta data.
391
-		if ( ! $stripe_customer_id || ! is_string( $stripe_customer_id ) ) {
391
+		if ( ! $stripe_customer_id || ! is_string($stripe_customer_id)) {
392 392
 			$user_id            = $customer_user;
393
-			$stripe_customer_id = get_user_meta( $user_id, '_stripe_customer_id', true );
394
-			$stripe_card_id     = get_user_meta( $user_id, '_stripe_card_id', true );
393
+			$stripe_customer_id = get_user_meta($user_id, '_stripe_customer_id', true);
394
+			$stripe_card_id     = get_user_meta($user_id, '_stripe_card_id', true);
395 395
 		}
396 396
 
397 397
 		// If we couldn't find a Stripe customer linked to the account, fallback to the order meta data.
398
-		if ( ( ! $stripe_customer_id || ! is_string( $stripe_customer_id ) ) && false !== $subscription->order ) {
399
-			$stripe_customer_id = get_post_meta( ( $this->wc_pre_30 ? $subscription->order->id : $subscription->get_parent_id() ), '_stripe_customer_id', true );
400
-			$stripe_card_id     = get_post_meta( ( $this->wc_pre_30 ? $subscription->order->id : $subscription->get_parent_id() ), '_stripe_card_id', true );
398
+		if (( ! $stripe_customer_id || ! is_string($stripe_customer_id)) && false !== $subscription->order) {
399
+			$stripe_customer_id = get_post_meta(($this->wc_pre_30 ? $subscription->order->id : $subscription->get_parent_id()), '_stripe_customer_id', true);
400
+			$stripe_card_id     = get_post_meta(($this->wc_pre_30 ? $subscription->order->id : $subscription->get_parent_id()), '_stripe_card_id', true);
401 401
 		}
402 402
 
403
-		$stripe_customer->set_id( $stripe_customer_id );
403
+		$stripe_customer->set_id($stripe_customer_id);
404 404
 		$cards = $stripe_customer->get_cards();
405 405
 
406
-		if ( $cards ) {
406
+		if ($cards) {
407 407
 			$found_card = false;
408
-			foreach ( $cards as $card ) {
409
-				if ( $card->id === $stripe_card_id ) {
408
+			foreach ($cards as $card) {
409
+				if ($card->id === $stripe_card_id) {
410 410
 					$found_card                = true;
411
-					$payment_method_to_display = sprintf( __( 'Via %1$s card ending in %2$s', 'woocommerce-gateway-stripe' ), ( isset( $card->type ) ? $card->type : $card->brand ), $card->last4 );
411
+					$payment_method_to_display = sprintf(__('Via %1$s card ending in %2$s', 'woocommerce-gateway-stripe'), (isset($card->type) ? $card->type : $card->brand), $card->last4);
412 412
 					break;
413 413
 				}
414 414
 			}
415
-			if ( ! $found_card ) {
416
-				$payment_method_to_display = sprintf( __( 'Via %1$s card ending in %2$s', 'woocommerce-gateway-stripe' ), ( isset( $cards[0]->type ) ? $cards[0]->type : $cards[0]->brand ), $cards[0]->last4 );
415
+			if ( ! $found_card) {
416
+				$payment_method_to_display = sprintf(__('Via %1$s card ending in %2$s', 'woocommerce-gateway-stripe'), (isset($cards[0]->type) ? $cards[0]->type : $cards[0]->brand), $cards[0]->last4);
417 417
 			}
418 418
 		}
419 419
 
@@ -428,11 +428,11 @@  discard block
 block discarded – undo
428 428
 	 *
429 429
 	 * @param string $message
430 430
 	 */
431
-	public function log( $message ) {
432
-		$options = get_option( 'woocommerce_stripe_settings' );
431
+	public function log($message) {
432
+		$options = get_option('woocommerce_stripe_settings');
433 433
 
434
-		if ( 'yes' === $options['logging'] ) {
435
-			WC_Stripe::log( $message );
434
+		if ('yes' === $options['logging']) {
435
+			WC_Stripe::log($message);
436 436
 		}
437 437
 	}
438 438
 }
Please login to merge, or discard this patch.
includes/class-wc-stripe-payment-request.php 1 patch
Spacing   +88 added lines, -88 removed lines patch added patch discarded remove patch
@@ -7,7 +7,7 @@  discard block
 block discarded – undo
7 7
  * @version 3.1.0
8 8
  */
9 9
 
10
-if ( ! defined( 'ABSPATH' ) ) {
10
+if ( ! defined('ABSPATH')) {
11 11
 	exit;
12 12
 }
13 13
 
@@ -20,12 +20,12 @@  discard block
 block discarded – undo
20 20
 	 * Initialize class actions.
21 21
 	 */
22 22
 	public function __construct() {
23
-		add_action( 'wp_enqueue_scripts', array( $this, 'scripts' ) );
23
+		add_action('wp_enqueue_scripts', array($this, 'scripts'));
24 24
 
25
-		add_action( 'wc_ajax_wc_stripe_get_cart_details', array( $this, 'ajax_get_cart_details' ) );
26
-		add_action( 'wc_ajax_wc_stripe_get_shipping_options', array( $this, 'ajax_get_shipping_options' ) );
27
-		add_action( 'wc_ajax_wc_stripe_update_shipping_method', array( $this, 'ajax_update_shipping_method' ) );
28
-		add_action( 'wc_ajax_wc_stripe_create_order', array( $this, 'ajax_create_order' ) );
25
+		add_action('wc_ajax_wc_stripe_get_cart_details', array($this, 'ajax_get_cart_details'));
26
+		add_action('wc_ajax_wc_stripe_get_shipping_options', array($this, 'ajax_get_shipping_options'));
27
+		add_action('wc_ajax_wc_stripe_update_shipping_method', array($this, 'ajax_update_shipping_method'));
28
+		add_action('wc_ajax_wc_stripe_create_order', array($this, 'ajax_create_order'));
29 29
 	}
30 30
 
31 31
 	/**
@@ -34,10 +34,10 @@  discard block
 block discarded – undo
34 34
 	 * @return bool
35 35
 	 */
36 36
 	protected function is_activated() {
37
-		$options             = get_option( 'woocommerce_stripe_settings', array() );
38
-		$enabled             = isset( $options['enabled'] ) && 'yes' === $options['enabled'];
39
-		$stripe_checkout     = isset( $options['stripe_checkout'] ) && 'yes' !== $options['stripe_checkout'];
40
-		$request_payment_api = isset( $options['request_payment_api'] ) && 'yes' === $options['request_payment_api'];
37
+		$options             = get_option('woocommerce_stripe_settings', array());
38
+		$enabled             = isset($options['enabled']) && 'yes' === $options['enabled'];
39
+		$stripe_checkout     = isset($options['stripe_checkout']) && 'yes' !== $options['stripe_checkout'];
40
+		$request_payment_api = isset($options['request_payment_api']) && 'yes' === $options['request_payment_api'];
41 41
 
42 42
 		return $enabled && $stripe_checkout && $request_payment_api && is_ssl();
43 43
 	}
@@ -48,9 +48,9 @@  discard block
 block discarded – undo
48 48
 	 * @return string
49 49
 	 */
50 50
 	protected function get_publishable_key() {
51
-		$options = get_option( 'woocommerce_stripe_settings', array() );
51
+		$options = get_option('woocommerce_stripe_settings', array());
52 52
 
53
-		if ( empty( $options ) ) {
53
+		if (empty($options)) {
54 54
 			return '';
55 55
 		}
56 56
 
@@ -62,39 +62,39 @@  discard block
 block discarded – undo
62 62
 	 */
63 63
 	public function scripts() {
64 64
 		// Load PaymentRequest only on cart for now.
65
-		if ( ! is_cart() ) {
65
+		if ( ! is_cart()) {
66 66
 			return;
67 67
 		}
68 68
 
69
-		if ( ! $this->is_activated() ) {
69
+		if ( ! $this->is_activated()) {
70 70
 			return;
71 71
 		}
72 72
 
73
-		$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
73
+		$suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';
74 74
 
75
-		wp_enqueue_script( 'stripe', 'https://js.stripe.com/v2/', '', '1.0', true );
76
-		wp_enqueue_script( 'google-payment-request-shim', 'https://storage.googleapis.com/prshim/v1/payment-shim.js', '', '1.0', false );
77
-		wp_enqueue_script( 'wc-stripe-payment-request', plugins_url( 'assets/js/payment-request' . $suffix . '.js', WC_STRIPE_MAIN_FILE ), array( 'jquery', 'stripe' ), WC_STRIPE_VERSION, true );
75
+		wp_enqueue_script('stripe', 'https://js.stripe.com/v2/', '', '1.0', true);
76
+		wp_enqueue_script('google-payment-request-shim', 'https://storage.googleapis.com/prshim/v1/payment-shim.js', '', '1.0', false);
77
+		wp_enqueue_script('wc-stripe-payment-request', plugins_url('assets/js/payment-request' . $suffix . '.js', WC_STRIPE_MAIN_FILE), array('jquery', 'stripe'), WC_STRIPE_VERSION, true);
78 78
 
79 79
 		wp_localize_script(
80 80
 			'wc-stripe-payment-request',
81 81
 			'wcStripePaymentRequestParams',
82 82
 			array(
83
-				'ajax_url' => WC_AJAX::get_endpoint( '%%endpoint%%' ),
83
+				'ajax_url' => WC_AJAX::get_endpoint('%%endpoint%%'),
84 84
 				'stripe'   => array(
85 85
 					'key'                => $this->get_publishable_key(),
86
-					'allow_prepaid_card' => apply_filters( 'wc_stripe_allow_prepaid_card', true ) ? 'yes' : 'no',
86
+					'allow_prepaid_card' => apply_filters('wc_stripe_allow_prepaid_card', true) ? 'yes' : 'no',
87 87
 				),
88 88
 				'nonce'    => array(
89
-					'payment'         => wp_create_nonce( 'wc-stripe-payment-request' ),
90
-					'shipping'        => wp_create_nonce( 'wc-stripe-payment-request-shipping' ),
91
-					'update_shipping' => wp_create_nonce( 'wc-stripe-update-shipping-method' ),
92
-					'checkout'        => wp_create_nonce( 'woocommerce-process_checkout' ),
89
+					'payment'         => wp_create_nonce('wc-stripe-payment-request'),
90
+					'shipping'        => wp_create_nonce('wc-stripe-payment-request-shipping'),
91
+					'update_shipping' => wp_create_nonce('wc-stripe-update-shipping-method'),
92
+					'checkout'        => wp_create_nonce('woocommerce-process_checkout'),
93 93
 				),
94 94
 				'i18n'     => array(
95
-					'no_prepaid_card'  => __( 'Sorry, we\'re not accepting prepaid cards at this time.', 'woocommerce-gateway-stripe' ),
95
+					'no_prepaid_card'  => __('Sorry, we\'re not accepting prepaid cards at this time.', 'woocommerce-gateway-stripe'),
96 96
 					/* translators: Do not translate the [option] placeholder */
97
-					'unknown_shipping' => __( 'Unknown shipping option "[option]".', 'woocommerce-gateway-stripe' ),
97
+					'unknown_shipping' => __('Unknown shipping option "[option]".', 'woocommerce-gateway-stripe'),
98 98
 				),
99 99
 			)
100 100
 		);
@@ -104,10 +104,10 @@  discard block
 block discarded – undo
104 104
 	 * Get cart details.
105 105
 	 */
106 106
 	public function ajax_get_cart_details() {
107
-		check_ajax_referer( 'wc-stripe-payment-request', 'security' );
107
+		check_ajax_referer('wc-stripe-payment-request', 'security');
108 108
 
109
-		if ( ! defined( 'WOOCOMMERCE_CART' ) ) {
110
-			define( 'WOOCOMMERCE_CART', true );
109
+		if ( ! defined('WOOCOMMERCE_CART')) {
110
+			define('WOOCOMMERCE_CART', true);
111 111
 		}
112 112
 
113 113
 		WC()->cart->calculate_totals();
@@ -119,18 +119,18 @@  discard block
 block discarded – undo
119 119
 			'shipping_required' => WC()->cart->needs_shipping(),
120 120
 			'order_data'        => array(
121 121
 				'total' => array(
122
-					'label'  => __( 'Total', 'woocommerce-gateway-stripe' ),
122
+					'label'  => __('Total', 'woocommerce-gateway-stripe'),
123 123
 					'amount' => array(
124
-						'value'    => max( 0, apply_filters( 'woocommerce_calculated_total', round( WC()->cart->cart_contents_total + WC()->cart->fee_total + WC()->cart->tax_total, WC()->cart->dp ), WC()->cart ) ),
124
+						'value'    => max(0, apply_filters('woocommerce_calculated_total', round(WC()->cart->cart_contents_total + WC()->cart->fee_total + WC()->cart->tax_total, WC()->cart->dp), WC()->cart)),
125 125
 						'currency' => $currency,
126 126
 					),
127 127
 				),
128 128
 				// Include line items such as subtotal, fees and taxes. No shipping option is provided here because it is not chosen yet.
129
-				'displayItems' => $this->compute_display_items( null ),
129
+				'displayItems' => $this->compute_display_items(null),
130 130
 			),
131 131
 		);
132 132
 
133
-		wp_send_json( $data );
133
+		wp_send_json($data);
134 134
 	}
135 135
 
136 136
 	/**
@@ -140,7 +140,7 @@  discard block
 block discarded – undo
140 140
 	 * @version 3.2.0
141 141
 	 * @param array $address
142 142
 	 */
143
-	public function calculate_shipping( $address = array() ) {
143
+	public function calculate_shipping($address = array()) {
144 144
 		global $states;
145 145
 
146 146
 		$country   = $address['country'];
@@ -157,28 +157,28 @@  discard block
 block discarded – undo
157 157
 		 * In some versions of Chrome, state can be a full name. So we need
158 158
 		 * to convert that to abbreviation as WC is expecting that.
159 159
 		 */
160
-		if ( 2 < strlen( $state ) ) {
161
-			$state = array_search( ucfirst( strtolower( $state ) ), $states[ $country ] );
160
+		if (2 < strlen($state)) {
161
+			$state = array_search(ucfirst(strtolower($state)), $states[$country]);
162 162
 		}
163 163
 
164 164
 		WC()->shipping->reset_shipping();
165 165
 
166
-		if ( $postcode && WC_Validation::is_postcode( $postcode, $country ) ) {
167
-			$postcode = wc_format_postcode( $postcode, $country );
166
+		if ($postcode && WC_Validation::is_postcode($postcode, $country)) {
167
+			$postcode = wc_format_postcode($postcode, $country);
168 168
 		}
169 169
 
170
-		if ( $country ) {
171
-			WC()->customer->set_location( $country, $state, $postcode, $city );
172
-			WC()->customer->set_shipping_location( $country, $state, $postcode, $city );
170
+		if ($country) {
171
+			WC()->customer->set_location($country, $state, $postcode, $city);
172
+			WC()->customer->set_shipping_location($country, $state, $postcode, $city);
173 173
 		} else {
174 174
 			WC()->customer->set_to_base();
175 175
 			WC()->customer->set_shipping_to_base();
176 176
 		}
177 177
 
178
-		if ( version_compare( WC_VERSION, '3.0', '<' ) ) {
179
-			WC()->customer->calculated_shipping( true );
178
+		if (version_compare(WC_VERSION, '3.0', '<')) {
179
+			WC()->customer->calculated_shipping(true);
180 180
 		} else {
181
-			WC()->customer->set_calculated_shipping( true );
181
+			WC()->customer->set_calculated_shipping(true);
182 182
 			WC()->customer->save();
183 183
 		}
184 184
 
@@ -195,17 +195,17 @@  discard block
 block discarded – undo
195 195
 		$packages[0]['destination']['address']   = $address_1;
196 196
 		$packages[0]['destination']['address_2'] = $address_2;
197 197
 
198
-		foreach ( WC()->cart->get_cart() as $item ) {
199
-			if ( $item['data']->needs_shipping() ) {
200
-				if ( isset( $item['line_total'] ) ) {
198
+		foreach (WC()->cart->get_cart() as $item) {
199
+			if ($item['data']->needs_shipping()) {
200
+				if (isset($item['line_total'])) {
201 201
 					$packages[0]['contents_cost'] += $item['line_total'];
202 202
 				}
203 203
 			}
204 204
 		}
205 205
 
206
-		$packages = apply_filters( 'woocommerce_cart_shipping_packages', $packages );
206
+		$packages = apply_filters('woocommerce_cart_shipping_packages', $packages);
207 207
 
208
-		WC()->shipping->calculate_shipping( $packages );
208
+		WC()->shipping->calculate_shipping($packages);
209 209
 	}
210 210
 
211 211
 	/**
@@ -216,19 +216,19 @@  discard block
 block discarded – undo
216 216
 	 * @see WC_Shipping::get_packages().
217 217
 	 */
218 218
 	public function ajax_get_shipping_options() {
219
-		check_ajax_referer( 'wc-stripe-payment-request-shipping', 'security' );
219
+		check_ajax_referer('wc-stripe-payment-request-shipping', 'security');
220 220
 
221 221
 		// Set the shipping package.
222
-		$posted   = filter_input_array( INPUT_POST, array(
222
+		$posted = filter_input_array(INPUT_POST, array(
223 223
 			'country'   => FILTER_SANITIZE_STRING,
224 224
 			'state'     => FILTER_SANITIZE_STRING,
225 225
 			'postcode'  => FILTER_SANITIZE_STRING,
226 226
 			'city'      => FILTER_SANITIZE_STRING,
227 227
 			'address'   => FILTER_SANITIZE_STRING,
228 228
 			'address_2' => FILTER_SANITIZE_STRING,
229
-		) );
229
+		));
230 230
 
231
-		$this->calculate_shipping( $posted );
231
+		$this->calculate_shipping($posted);
232 232
 
233 233
 		// Set the shipping options.
234 234
 		$currency = get_woocommerce_currency();
@@ -236,13 +236,13 @@  discard block
 block discarded – undo
236 236
 
237 237
 		$packages = WC()->shipping->get_packages();
238 238
 
239
-		if ( ! empty( $packages ) && WC()->customer->has_calculated_shipping() ) {
240
-			foreach ( $packages as $package_key => $package ) {
241
-				if ( empty( $package['rates'] ) ) {
239
+		if ( ! empty($packages) && WC()->customer->has_calculated_shipping()) {
240
+			foreach ($packages as $package_key => $package) {
241
+				if (empty($package['rates'])) {
242 242
 					break;
243 243
 				}
244 244
 
245
-				foreach ( $package['rates'] as $key => $rate ) {
245
+				foreach ($package['rates'] as $key => $rate) {
246 246
 					$data[] = array(
247 247
 						'id'       => $rate->id,
248 248
 						'label'    => $rate->label,
@@ -257,55 +257,55 @@  discard block
 block discarded – undo
257 257
 		}
258 258
 
259 259
 		// Auto select when have only one shipping method available.
260
-		if ( 1 === count( $data ) ) {
260
+		if (1 === count($data)) {
261 261
 			$data[0]['selected'] = true;
262 262
 		}
263 263
 
264
-		wp_send_json( $data );
264
+		wp_send_json($data);
265 265
 	}
266 266
 
267 267
 	/**
268 268
 	 * Update shipping method.
269 269
 	 */
270 270
 	public function ajax_update_shipping_method() {
271
-		check_ajax_referer( 'wc-stripe-update-shipping-method', 'security' );
271
+		check_ajax_referer('wc-stripe-update-shipping-method', 'security');
272 272
 
273
-		if ( ! defined( 'WOOCOMMERCE_CART' ) ) {
274
-			define( 'WOOCOMMERCE_CART', true );
273
+		if ( ! defined('WOOCOMMERCE_CART')) {
274
+			define('WOOCOMMERCE_CART', true);
275 275
 		}
276 276
 
277
-		$chosen_shipping_methods = WC()->session->get( 'chosen_shipping_methods' );
278
-		$shipping_method         = filter_input( INPUT_POST, 'shipping_method', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY );
277
+		$chosen_shipping_methods = WC()->session->get('chosen_shipping_methods');
278
+		$shipping_method         = filter_input(INPUT_POST, 'shipping_method', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY);
279 279
 
280
-		if ( is_array( $shipping_method ) ) {
281
-			foreach ( $shipping_method as $i => $value ) {
282
-				$chosen_shipping_methods[ $i ] = wc_clean( $value );
280
+		if (is_array($shipping_method)) {
281
+			foreach ($shipping_method as $i => $value) {
282
+				$chosen_shipping_methods[$i] = wc_clean($value);
283 283
 			}
284 284
 		}
285 285
 
286
-		WC()->session->set( 'chosen_shipping_methods', $chosen_shipping_methods );
286
+		WC()->session->set('chosen_shipping_methods', $chosen_shipping_methods);
287 287
 
288 288
 		WC()->cart->calculate_totals();
289 289
 
290 290
 		// Send back the new cart total and line items to be displayed, such as subtotal, shipping rate(s), fees and taxes.
291
-		$data      = array(
291
+		$data = array(
292 292
 			'total' => WC()->cart->total,
293
-			'items' => $this->compute_display_items( $shipping_method[0] ),
293
+			'items' => $this->compute_display_items($shipping_method[0]),
294 294
 		);
295 295
 
296
-		wp_send_json( $data );
296
+		wp_send_json($data);
297 297
 	}
298 298
 
299 299
 	/**
300 300
 	 * Create order.
301 301
 	 */
302 302
 	public function ajax_create_order() {
303
-		if ( WC()->cart->is_empty() ) {
304
-			wp_send_json_error( __( 'Empty cart', 'woocommerce-gateway-stripe' ) );
303
+		if (WC()->cart->is_empty()) {
304
+			wp_send_json_error(__('Empty cart', 'woocommerce-gateway-stripe'));
305 305
 		}
306 306
 
307
-		if ( ! defined( 'WOOCOMMERCE_CHECKOUT' ) ) {
308
-			define( 'WOOCOMMERCE_CHECKOUT', true );
307
+		if ( ! defined('WOOCOMMERCE_CHECKOUT')) {
308
+			define('WOOCOMMERCE_CHECKOUT', true);
309 309
 		}
310 310
 		
311 311
 		$_POST['terms'] = 1;
@@ -313,7 +313,7 @@  discard block
 block discarded – undo
313 313
 
314 314
 		WC()->checkout()->process_checkout();
315 315
 
316
-		die( 0 );
316
+		die(0);
317 317
 	}
318 318
 
319 319
 	/**
@@ -321,26 +321,26 @@  discard block
 block discarded – undo
321 321
 	 *
322 322
 	 * @param string shipping_method_id If shipping method ID is provided, will include display items about shipping.
323 323
 	 */
324
-	protected function compute_display_items( $shipping_method_id ) {
324
+	protected function compute_display_items($shipping_method_id) {
325 325
 		$currency = get_woocommerce_currency();
326 326
 		$items = array(
327 327
 			// Subtotal excluding tax, because taxes is a separate item, below.
328 328
 			array(
329
-				'label' => __( 'Subtotal', 'woocommerce-gateway-stripe' ),
329
+				'label' => __('Subtotal', 'woocommerce-gateway-stripe'),
330 330
 				'amount' => array(
331
-					'value'    => max( 0, round( WC()->cart->subtotal_ex_tax, WC()->cart->dp ) ),
331
+					'value'    => max(0, round(WC()->cart->subtotal_ex_tax, WC()->cart->dp)),
332 332
 					'currency' => $currency,
333 333
 				),
334 334
 			),
335 335
 		);
336 336
 		// If a chosen shipping option was provided, add line item(s) for it and include the shipping tax.
337
-		$tax_total = max( 0, round( WC()->cart->tax_total, WC()->cart->dp ) );
338
-		if ( $shipping_method_id ) {
339
-			$tax_total = max( 0, round( WC()->cart->tax_total + WC()->cart->shipping_tax_total, WC()->cart->dp ) );
337
+		$tax_total = max(0, round(WC()->cart->tax_total, WC()->cart->dp));
338
+		if ($shipping_method_id) {
339
+			$tax_total = max(0, round(WC()->cart->tax_total + WC()->cart->shipping_tax_total, WC()->cart->dp));
340 340
 			// Look through the package rates for $shipping_method_id, and when found, add a line item.
341
-			foreach ( WC()->shipping->get_packages() as $package_key => $package ) {
342
-				foreach ( $package['rates'] as $key => $rate ) {
343
-					if ( $rate->id  == $shipping_method_id ) {
341
+			foreach (WC()->shipping->get_packages() as $package_key => $package) {
342
+				foreach ($package['rates'] as $key => $rate) {
343
+					if ($rate->id == $shipping_method_id) {
344 344
 						$items[] = array(
345 345
 							'label' => $rate->label,
346 346
 							'amount' => array(
@@ -354,7 +354,7 @@  discard block
 block discarded – undo
354 354
 			}
355 355
 		}
356 356
 		// Include fees and taxes as display items.
357
-		foreach ( WC()->cart->fees as $key => $fee ) {
357
+		foreach (WC()->cart->fees as $key => $fee) {
358 358
 			$items[] = array(
359 359
 				'label'  => $fee->name,
360 360
 				'amount' => array(
@@ -364,9 +364,9 @@  discard block
 block discarded – undo
364 364
 			);
365 365
 		}
366 366
 		// The tax total may include the shipping taxes if a shipping option is provided.
367
-		if ( 0 < $tax_total ) {
367
+		if (0 < $tax_total) {
368 368
 			$items[] = array(
369
-				'label'  => __( 'Tax', 'woocommerce-gateway-stripe' ),
369
+				'label'  => __('Tax', 'woocommerce-gateway-stripe'),
370 370
 				'amount' => array(
371 371
 					'currency' => $currency,
372 372
 					'value'    => $tax_total,
Please login to merge, or discard this patch.
includes/settings-stripe.php 1 patch
Spacing   +68 added lines, -68 removed lines patch added patch discarded remove patch
@@ -1,176 +1,176 @@
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) {
2
+if ( ! defined('ABSPATH')) {
3 3
 	exit;
4 4
 }
5 5
 
6
-return apply_filters( 'wc_stripe_settings',
6
+return apply_filters('wc_stripe_settings',
7 7
 	array(
8 8
 		'enabled' => array(
9
-			'title'       => __( 'Enable/Disable', 'woocommerce-gateway-stripe' ),
10
-			'label'       => __( 'Enable Stripe', 'woocommerce-gateway-stripe' ),
9
+			'title'       => __('Enable/Disable', 'woocommerce-gateway-stripe'),
10
+			'label'       => __('Enable Stripe', 'woocommerce-gateway-stripe'),
11 11
 			'type'        => 'checkbox',
12 12
 			'description' => '',
13 13
 			'default'     => 'no',
14 14
 		),
15 15
 		'title' => array(
16
-			'title'       => __( 'Title', 'woocommerce-gateway-stripe' ),
16
+			'title'       => __('Title', 'woocommerce-gateway-stripe'),
17 17
 			'type'        => 'text',
18
-			'description' => __( 'This controls the title which the user sees during checkout.', 'woocommerce-gateway-stripe' ),
19
-			'default'     => __( 'Credit Card (Stripe)', 'woocommerce-gateway-stripe' ),
18
+			'description' => __('This controls the title which the user sees during checkout.', 'woocommerce-gateway-stripe'),
19
+			'default'     => __('Credit Card (Stripe)', 'woocommerce-gateway-stripe'),
20 20
 			'desc_tip'    => true,
21 21
 		),
22 22
 		'description' => array(
23
-			'title'       => __( 'Description', 'woocommerce-gateway-stripe' ),
23
+			'title'       => __('Description', 'woocommerce-gateway-stripe'),
24 24
 			'type'        => 'text',
25
-			'description' => __( 'This controls the description which the user sees during checkout.', 'woocommerce-gateway-stripe' ),
26
-			'default'     => __( 'Pay with your credit card via Stripe.', 'woocommerce-gateway-stripe' ),
25
+			'description' => __('This controls the description which the user sees during checkout.', 'woocommerce-gateway-stripe'),
26
+			'default'     => __('Pay with your credit card via Stripe.', 'woocommerce-gateway-stripe'),
27 27
 			'desc_tip'    => true,
28 28
 		),
29 29
 		'testmode' => array(
30
-			'title'       => __( 'Test mode', 'woocommerce-gateway-stripe' ),
31
-			'label'       => __( 'Enable Test Mode', 'woocommerce-gateway-stripe' ),
30
+			'title'       => __('Test mode', 'woocommerce-gateway-stripe'),
31
+			'label'       => __('Enable Test Mode', 'woocommerce-gateway-stripe'),
32 32
 			'type'        => 'checkbox',
33
-			'description' => __( 'Place the payment gateway in test mode using test API keys.', 'woocommerce-gateway-stripe' ),
33
+			'description' => __('Place the payment gateway in test mode using test API keys.', 'woocommerce-gateway-stripe'),
34 34
 			'default'     => 'yes',
35 35
 			'desc_tip'    => true,
36 36
 		),
37 37
 		'test_publishable_key' => array(
38
-			'title'       => __( 'Test Publishable Key', 'woocommerce-gateway-stripe' ),
38
+			'title'       => __('Test Publishable Key', 'woocommerce-gateway-stripe'),
39 39
 			'type'        => 'text',
40
-			'description' => __( 'Get your API keys from your stripe account.', 'woocommerce-gateway-stripe' ),
40
+			'description' => __('Get your API keys from your stripe account.', 'woocommerce-gateway-stripe'),
41 41
 			'default'     => '',
42 42
 			'desc_tip'    => true,
43 43
 		),
44 44
 		'test_secret_key' => array(
45
-			'title'       => __( 'Test Secret Key', 'woocommerce-gateway-stripe' ),
45
+			'title'       => __('Test Secret Key', 'woocommerce-gateway-stripe'),
46 46
 			'type'        => 'text',
47
-			'description' => __( 'Get your API keys from your stripe account.', 'woocommerce-gateway-stripe' ),
47
+			'description' => __('Get your API keys from your stripe account.', 'woocommerce-gateway-stripe'),
48 48
 			'default'     => '',
49 49
 			'desc_tip'    => true,
50 50
 		),
51 51
 		'publishable_key' => array(
52
-			'title'       => __( 'Live Publishable Key', 'woocommerce-gateway-stripe' ),
52
+			'title'       => __('Live Publishable Key', 'woocommerce-gateway-stripe'),
53 53
 			'type'        => 'text',
54
-			'description' => __( 'Get your API keys from your stripe account.', 'woocommerce-gateway-stripe' ),
54
+			'description' => __('Get your API keys from your stripe account.', 'woocommerce-gateway-stripe'),
55 55
 			'default'     => '',
56 56
 			'desc_tip'    => true,
57 57
 		),
58 58
 		'secret_key' => array(
59
-			'title'       => __( 'Live Secret Key', 'woocommerce-gateway-stripe' ),
59
+			'title'       => __('Live Secret Key', 'woocommerce-gateway-stripe'),
60 60
 			'type'        => 'text',
61
-			'description' => __( 'Get your API keys from your stripe account.', 'woocommerce-gateway-stripe' ),
61
+			'description' => __('Get your API keys from your stripe account.', 'woocommerce-gateway-stripe'),
62 62
 			'default'     => '',
63 63
 			'desc_tip'    => true,
64 64
 		),
65 65
 		'statement_descriptor' => array(
66
-			'title'       => __( 'Statement Descriptor', 'woocommerce-gateway-stripe' ),
66
+			'title'       => __('Statement Descriptor', 'woocommerce-gateway-stripe'),
67 67
 			'type'        => 'text',
68
-			'description' => __( 'Extra information about a charge. This will appear on your customer’s credit card statement.', 'woocommerce-gateway-stripe' ),
68
+			'description' => __('Extra information about a charge. This will appear on your customer’s credit card statement.', 'woocommerce-gateway-stripe'),
69 69
 			'default'     => '',
70 70
 			'desc_tip'    => true,
71 71
 		),
72 72
 		'capture' => array(
73
-			'title'       => __( 'Capture', 'woocommerce-gateway-stripe' ),
74
-			'label'       => __( 'Capture charge immediately', 'woocommerce-gateway-stripe' ),
73
+			'title'       => __('Capture', 'woocommerce-gateway-stripe'),
74
+			'label'       => __('Capture charge immediately', 'woocommerce-gateway-stripe'),
75 75
 			'type'        => 'checkbox',
76
-			'description' => __( 'Whether or not to immediately capture the charge. When unchecked, the charge issues an authorization and will need to be captured later. Uncaptured charges expire in 7 days.', 'woocommerce-gateway-stripe' ),
76
+			'description' => __('Whether or not to immediately capture the charge. When unchecked, the charge issues an authorization and will need to be captured later. Uncaptured charges expire in 7 days.', 'woocommerce-gateway-stripe'),
77 77
 			'default'     => 'yes',
78 78
 			'desc_tip'    => true,
79 79
 		),
80 80
 		'stripe_checkout' => array(
81
-			'title'       => __( 'Stripe Checkout', 'woocommerce-gateway-stripe' ),
82
-			'label'       => __( 'Enable Stripe Checkout', 'woocommerce-gateway-stripe' ),
81
+			'title'       => __('Stripe Checkout', 'woocommerce-gateway-stripe'),
82
+			'label'       => __('Enable Stripe Checkout', 'woocommerce-gateway-stripe'),
83 83
 			'type'        => 'checkbox',
84
-			'description' => __( 'If enabled, this option shows a "pay" button and modal credit card form on the checkout, instead of credit card fields directly on the page.', 'woocommerce-gateway-stripe' ),
84
+			'description' => __('If enabled, this option shows a "pay" button and modal credit card form on the checkout, instead of credit card fields directly on the page.', 'woocommerce-gateway-stripe'),
85 85
 			'default'     => 'no',
86 86
 			'desc_tip'    => true,
87 87
 		),
88 88
 		'stripe_checkout_locale' => array(
89
-			'title'       => __( 'Stripe Checkout locale', 'woocommerce-gateway-stripe' ),
89
+			'title'       => __('Stripe Checkout locale', 'woocommerce-gateway-stripe'),
90 90
 			'type'        => 'select',
91 91
 			'class'       => 'wc-enhanced-select',
92
-			'description' => __( 'Language to display in Stripe Checkout modal. Specify Auto to display Checkout in the user\'s preferred language, if available. English will be used by default.', 'woocommerce-gateway-stripe' ),
92
+			'description' => __('Language to display in Stripe Checkout modal. Specify Auto to display Checkout in the user\'s preferred language, if available. English will be used by default.', 'woocommerce-gateway-stripe'),
93 93
 			'default'     => 'en',
94 94
 			'desc_tip'    => true,
95 95
 			'options'     => array(
96
-				'auto' => __( 'Auto', 'woocommerce-gateway-stripe' ),
97
-				'zh'   => __( 'Simplified Chinese', 'woocommerce-gateway-stripe' ),
98
-				'da'   => __( 'Danish', 'woocommerce-gateway-stripe' ),
99
-				'nl'   => __( 'Dutch', 'woocommerce-gateway-stripe' ),
100
-				'en'   => __( 'English', 'woocommerce-gateway-stripe' ),
101
-				'fi'   => __( 'Finnish', 'woocommerce-gateway-stripe' ),
102
-				'fr'   => __( 'French', 'woocommerce-gateway-stripe' ),
103
-				'de'   => __( 'German', 'woocommerce-gateway-stripe' ),
104
-				'it'   => __( 'Italian', 'woocommerce-gateway-stripe' ),
105
-				'ja'   => __( 'Japanese', 'woocommerce-gateway-stripe' ),
106
-				'no'   => __( 'Norwegian', 'woocommerce-gateway-stripe' ),
107
-				'es'   => __( 'Spanish', 'woocommerce-gateway-stripe' ),
108
-				'sv'   => __( 'Swedish', 'woocommerce-gateway-stripe' ),
96
+				'auto' => __('Auto', 'woocommerce-gateway-stripe'),
97
+				'zh'   => __('Simplified Chinese', 'woocommerce-gateway-stripe'),
98
+				'da'   => __('Danish', 'woocommerce-gateway-stripe'),
99
+				'nl'   => __('Dutch', 'woocommerce-gateway-stripe'),
100
+				'en'   => __('English', 'woocommerce-gateway-stripe'),
101
+				'fi'   => __('Finnish', 'woocommerce-gateway-stripe'),
102
+				'fr'   => __('French', 'woocommerce-gateway-stripe'),
103
+				'de'   => __('German', 'woocommerce-gateway-stripe'),
104
+				'it'   => __('Italian', 'woocommerce-gateway-stripe'),
105
+				'ja'   => __('Japanese', 'woocommerce-gateway-stripe'),
106
+				'no'   => __('Norwegian', 'woocommerce-gateway-stripe'),
107
+				'es'   => __('Spanish', 'woocommerce-gateway-stripe'),
108
+				'sv'   => __('Swedish', 'woocommerce-gateway-stripe'),
109 109
 			),
110 110
 		),
111 111
 		'stripe_bitcoin' => array(
112
-			'title'       => __( 'Bitcoin Currency', 'woocommerce-gateway-stripe' ),
113
-			'label'       => __( 'Enable Bitcoin Currency', 'woocommerce-gateway-stripe' ),
112
+			'title'       => __('Bitcoin Currency', 'woocommerce-gateway-stripe'),
113
+			'label'       => __('Enable Bitcoin Currency', 'woocommerce-gateway-stripe'),
114 114
 			'type'        => 'checkbox',
115
-			'description' => __( 'If enabled, an option to accept bitcoin will show on the checkout modal. Note: Stripe Checkout needs to be enabled and store currency must be set to USD.', 'woocommerce-gateway-stripe' ),
115
+			'description' => __('If enabled, an option to accept bitcoin will show on the checkout modal. Note: Stripe Checkout needs to be enabled and store currency must be set to USD.', 'woocommerce-gateway-stripe'),
116 116
 			'default'     => 'no',
117 117
 			'desc_tip'    => true,
118 118
 		),
119 119
 		'stripe_checkout_image' => array(
120
-			'title'       => __( 'Stripe Checkout Image', 'woocommerce-gateway-stripe' ),
121
-			'description' => __( 'Optionally enter the URL to a 128x128px image of your brand or product. e.g. <code>https://yoursite.com/wp-content/uploads/2013/09/yourimage.jpg</code>', 'woocommerce-gateway-stripe' ),
120
+			'title'       => __('Stripe Checkout Image', 'woocommerce-gateway-stripe'),
121
+			'description' => __('Optionally enter the URL to a 128x128px image of your brand or product. e.g. <code>https://yoursite.com/wp-content/uploads/2013/09/yourimage.jpg</code>', 'woocommerce-gateway-stripe'),
122 122
 			'type'        => 'text',
123 123
 			'default'     => '',
124 124
 			'desc_tip'    => true,
125 125
 		),
126 126
 		'request_payment_api' => array(
127
-			'title'       => __( 'Payment Request API', 'woocommerce-gateway-stripe' ),
128
-			'label'       => __( 'Enable Payment Request API', 'woocommerce-gateway-stripe' ),
127
+			'title'       => __('Payment Request API', 'woocommerce-gateway-stripe'),
128
+			'label'       => __('Enable Payment Request API', 'woocommerce-gateway-stripe'),
129 129
 			'type'        => 'checkbox',
130
-			'description' => __( 'If enabled, users will be able to pay using the Payment Request API if supported by the browser.', 'woocommerce-gateway-stripe' ),
130
+			'description' => __('If enabled, users will be able to pay using the Payment Request API if supported by the browser.', 'woocommerce-gateway-stripe'),
131 131
 			'default'     => 'no',
132 132
 			'desc_tip'    => true,
133 133
 		),
134 134
 		'apple_pay' => array(
135
-			'title'       => __( 'Apple Pay', 'woocommerce-gateway-stripe' ),
136
-			'label'       => sprintf( __( 'Enable Apple Pay. %1$sBy using Apple Pay, you agree to %2$s and %3$s\'s terms of service.', 'woocommerce-gateway-stripe' ), '<br />', '<a href="https://stripe.com/apple-pay/legal" target="_blank">Stripe</a>', '<a href="https://developer.apple.com/apple-pay/acceptable-use-guidelines-for-websites/" target="_blank">Apple</a>' ),
135
+			'title'       => __('Apple Pay', 'woocommerce-gateway-stripe'),
136
+			'label'       => sprintf(__('Enable Apple Pay. %1$sBy using Apple Pay, you agree to %2$s and %3$s\'s terms of service.', 'woocommerce-gateway-stripe'), '<br />', '<a href="https://stripe.com/apple-pay/legal" target="_blank">Stripe</a>', '<a href="https://developer.apple.com/apple-pay/acceptable-use-guidelines-for-websites/" target="_blank">Apple</a>'),
137 137
 			'type'        => 'checkbox',
138
-			'description' => __( 'If enabled, users will be able to pay with Apple Pay.', 'woocommerce-gateway-stripe' ),
138
+			'description' => __('If enabled, users will be able to pay with Apple Pay.', 'woocommerce-gateway-stripe'),
139 139
 			'default'     => 'yes',
140 140
 			'desc_tip'    => true,
141 141
 		),
142 142
 		'apple_pay_button' => array(
143
-			'title'       => __( 'Apple Pay Button Style', 'woocommerce-gateway-stripe' ),
144
-			'label'       => __( 'Button Style', 'woocommerce-gateway-stripe' ),
143
+			'title'       => __('Apple Pay Button Style', 'woocommerce-gateway-stripe'),
144
+			'label'       => __('Button Style', 'woocommerce-gateway-stripe'),
145 145
 			'type'        => 'select',
146
-			'description' => __( 'Select the button style you would like to show.', 'woocommerce-gateway-stripe' ),
146
+			'description' => __('Select the button style you would like to show.', 'woocommerce-gateway-stripe'),
147 147
 			'default'     => 'black',
148 148
 			'desc_tip'    => true,
149 149
 			'options'     => array(
150
-				'black' => __( 'Black', 'woocommerce-gateway-stripe' ),
151
-				'white' => __( 'White', 'woocommerce-gateway-stripe' ),
150
+				'black' => __('Black', 'woocommerce-gateway-stripe'),
151
+				'white' => __('White', 'woocommerce-gateway-stripe'),
152 152
 			),
153 153
 		),
154 154
 		'apple_pay_button_lang' => array(
155
-			'title'       => __( 'Apple Pay Button Language', 'woocommerce-gateway-stripe' ),
156
-			'description' => sprintf( __( 'Enter the 2 letter ISO code for the language you would like your Apple Pay Button to display in. Reference available ISO codes <a href="%s" target="_blank">here</a>.', 'woocommerce-gateway-stripe' ), 'http://www.w3schools.com/tags/ref_language_codes.asp' ),
155
+			'title'       => __('Apple Pay Button Language', 'woocommerce-gateway-stripe'),
156
+			'description' => sprintf(__('Enter the 2 letter ISO code for the language you would like your Apple Pay Button to display in. Reference available ISO codes <a href="%s" target="_blank">here</a>.', 'woocommerce-gateway-stripe'), 'http://www.w3schools.com/tags/ref_language_codes.asp'),
157 157
 			'type'        => 'text',
158 158
 			'default'     => 'en',
159 159
 			'desc_tip'    => false,
160 160
 		),
161 161
 		'saved_cards' => array(
162
-			'title'       => __( 'Saved Cards', 'woocommerce-gateway-stripe' ),
163
-			'label'       => __( 'Enable Payment via Saved Cards', 'woocommerce-gateway-stripe' ),
162
+			'title'       => __('Saved Cards', 'woocommerce-gateway-stripe'),
163
+			'label'       => __('Enable Payment via Saved Cards', 'woocommerce-gateway-stripe'),
164 164
 			'type'        => 'checkbox',
165
-			'description' => __( 'If enabled, users will be able to pay with a saved card during checkout. Card details are saved on Stripe servers, not on your store.', 'woocommerce-gateway-stripe' ),
165
+			'description' => __('If enabled, users will be able to pay with a saved card during checkout. Card details are saved on Stripe servers, not on your store.', 'woocommerce-gateway-stripe'),
166 166
 			'default'     => 'no',
167 167
 			'desc_tip'    => true,
168 168
 		),
169 169
 		'logging' => array(
170
-			'title'       => __( 'Logging', 'woocommerce-gateway-stripe' ),
171
-			'label'       => __( 'Log debug messages', 'woocommerce-gateway-stripe' ),
170
+			'title'       => __('Logging', 'woocommerce-gateway-stripe'),
171
+			'label'       => __('Log debug messages', 'woocommerce-gateway-stripe'),
172 172
 			'type'        => 'checkbox',
173
-			'description' => __( 'Save debug messages to the WooCommerce System Status log.', 'woocommerce-gateway-stripe' ),
173
+			'description' => __('Save debug messages to the WooCommerce System Status log.', 'woocommerce-gateway-stripe'),
174 174
 			'default'     => 'no',
175 175
 			'desc_tip'    => true,
176 176
 		),
Please login to merge, or discard this patch.