Completed
Pull Request — master (#153)
by Matty
02:41
created
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 1 patch
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.
includes/legacy/class-wc-gateway-stripe.php 1 patch
Spacing   +186 added lines, -186 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) {
2
+if ( ! defined('ABSPATH')) {
3 3
 	exit;
4 4
 }
5 5
 
@@ -15,8 +15,8 @@  discard block
 block discarded – undo
15 15
 	 */
16 16
 	public function __construct() {
17 17
 		$this->id                   = 'stripe';
18
-		$this->method_title         = __( 'Stripe', 'woocommerce-gateway-stripe' );
19
-		$this->method_description   = __( 'Stripe works by adding credit card fields on the checkout and then sending the details to Stripe for verification.', 'woocommerce-gateway-stripe' );
18
+		$this->method_title         = __('Stripe', 'woocommerce-gateway-stripe');
19
+		$this->method_description   = __('Stripe works by adding credit card fields on the checkout and then sending the details to Stripe for verification.', 'woocommerce-gateway-stripe');
20 20
 		$this->has_fields           = true;
21 21
 		$this->view_transaction_url = 'https://dashboard.stripe.com/payments/%s';
22 22
 		$this->supports             = array(
@@ -42,35 +42,35 @@  discard block
 block discarded – undo
42 42
 		$this->init_settings();
43 43
 
44 44
 		// Get setting values.
45
-		$this->title                  = $this->get_option( 'title' );
46
-		$this->description            = $this->get_option( 'description' );
47
-		$this->enabled                = $this->get_option( 'enabled' );
48
-		$this->testmode               = 'yes' === $this->get_option( 'testmode' );
49
-		$this->capture                = 'yes' === $this->get_option( 'capture', 'yes' );
50
-		$this->stripe_checkout        = 'yes' === $this->get_option( 'stripe_checkout' );
51
-		$this->stripe_checkout_locale = $this->get_option( 'stripe_checkout_locale' );
52
-		$this->stripe_checkout_image  = $this->get_option( 'stripe_checkout_image', '' );
53
-		$this->saved_cards            = 'yes' === $this->get_option( 'saved_cards' );
54
-		$this->secret_key             = $this->testmode ? $this->get_option( 'test_secret_key' ) : $this->get_option( 'secret_key' );
55
-		$this->publishable_key        = $this->testmode ? $this->get_option( 'test_publishable_key' ) : $this->get_option( 'publishable_key' );
56
-		$this->bitcoin                = 'USD' === strtoupper( get_woocommerce_currency() ) && 'yes' === $this->get_option( 'stripe_bitcoin' );
57
-		$this->logging                = 'yes' === $this->get_option( 'logging' );
58
-
59
-		if ( $this->stripe_checkout ) {
60
-			$this->order_button_text = __( 'Continue to payment', 'woocommerce-gateway-stripe' );
45
+		$this->title                  = $this->get_option('title');
46
+		$this->description            = $this->get_option('description');
47
+		$this->enabled                = $this->get_option('enabled');
48
+		$this->testmode               = 'yes' === $this->get_option('testmode');
49
+		$this->capture                = 'yes' === $this->get_option('capture', 'yes');
50
+		$this->stripe_checkout        = 'yes' === $this->get_option('stripe_checkout');
51
+		$this->stripe_checkout_locale = $this->get_option('stripe_checkout_locale');
52
+		$this->stripe_checkout_image  = $this->get_option('stripe_checkout_image', '');
53
+		$this->saved_cards            = 'yes' === $this->get_option('saved_cards');
54
+		$this->secret_key             = $this->testmode ? $this->get_option('test_secret_key') : $this->get_option('secret_key');
55
+		$this->publishable_key        = $this->testmode ? $this->get_option('test_publishable_key') : $this->get_option('publishable_key');
56
+		$this->bitcoin                = 'USD' === strtoupper(get_woocommerce_currency()) && 'yes' === $this->get_option('stripe_bitcoin');
57
+		$this->logging                = 'yes' === $this->get_option('logging');
58
+
59
+		if ($this->stripe_checkout) {
60
+			$this->order_button_text = __('Continue to payment', 'woocommerce-gateway-stripe');
61 61
 		}
62 62
 
63
-		if ( $this->testmode ) {
64
-			$this->description .= ' ' . sprintf( __( 'TEST MODE ENABLED. In test mode, you can use the card number 4242424242424242 with any CVC and a valid expiration date or check the documentation "<a href="%s">Testing Stripe</a>" for more card numbers.', 'woocommerce-gateway-stripe' ), 'https://stripe.com/docs/testing' );
65
-			$this->description  = trim( $this->description );
63
+		if ($this->testmode) {
64
+			$this->description .= ' ' . sprintf(__('TEST MODE ENABLED. In test mode, you can use the card number 4242424242424242 with any CVC and a valid expiration date or check the documentation "<a href="%s">Testing Stripe</a>" for more card numbers.', 'woocommerce-gateway-stripe'), 'https://stripe.com/docs/testing');
65
+			$this->description  = trim($this->description);
66 66
 		}
67 67
 
68
-		WC_Stripe_API::set_secret_key( $this->secret_key );
68
+		WC_Stripe_API::set_secret_key($this->secret_key);
69 69
 
70 70
 		// Hooks
71
-		add_action( 'wp_enqueue_scripts', array( $this, 'payment_scripts' ) );
72
-		add_action( 'admin_notices', array( $this, 'admin_notices' ) );
73
-		add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) );
71
+		add_action('wp_enqueue_scripts', array($this, 'payment_scripts'));
72
+		add_action('admin_notices', array($this, 'admin_notices'));
73
+		add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options'));
74 74
 	}
75 75
 
76 76
 	/**
@@ -80,35 +80,35 @@  discard block
 block discarded – undo
80 80
 	 * @return string
81 81
 	 */
82 82
 	public function get_icon() {
83
-		$ext   = version_compare( WC()->version, '2.6', '>=' ) ? '.svg' : '.png';
84
-		$style = version_compare( WC()->version, '2.6', '>=' ) ? 'style="margin-left: 0.3em"' : '';
83
+		$ext   = version_compare(WC()->version, '2.6', '>=') ? '.svg' : '.png';
84
+		$style = version_compare(WC()->version, '2.6', '>=') ? 'style="margin-left: 0.3em"' : '';
85 85
 
86
-		$icon  = '<img src="' . WC_HTTPS::force_https_url( WC()->plugin_url() . '/assets/images/icons/credit-cards/visa' . $ext ) . '" alt="Visa" width="32" ' . $style . ' />';
87
-		$icon .= '<img src="' . WC_HTTPS::force_https_url( WC()->plugin_url() . '/assets/images/icons/credit-cards/mastercard' . $ext ) . '" alt="Mastercard" width="32" ' . $style . ' />';
88
-		$icon .= '<img src="' . WC_HTTPS::force_https_url( WC()->plugin_url() . '/assets/images/icons/credit-cards/amex' . $ext ) . '" alt="Amex" width="32" ' . $style . ' />';
86
+		$icon  = '<img src="' . WC_HTTPS::force_https_url(WC()->plugin_url() . '/assets/images/icons/credit-cards/visa' . $ext) . '" alt="Visa" width="32" ' . $style . ' />';
87
+		$icon .= '<img src="' . WC_HTTPS::force_https_url(WC()->plugin_url() . '/assets/images/icons/credit-cards/mastercard' . $ext) . '" alt="Mastercard" width="32" ' . $style . ' />';
88
+		$icon .= '<img src="' . WC_HTTPS::force_https_url(WC()->plugin_url() . '/assets/images/icons/credit-cards/amex' . $ext) . '" alt="Amex" width="32" ' . $style . ' />';
89 89
 
90
-		if ( 'USD' === get_woocommerce_currency() ) {
91
-			$icon .= '<img src="' . WC_HTTPS::force_https_url( WC()->plugin_url() . '/assets/images/icons/credit-cards/discover' . $ext ) . '" alt="Discover" width="32" ' . $style . ' />';
92
-			$icon .= '<img src="' . WC_HTTPS::force_https_url( WC()->plugin_url() . '/assets/images/icons/credit-cards/jcb' . $ext ) . '" alt="JCB" width="32" ' . $style . ' />';
93
-			$icon .= '<img src="' . WC_HTTPS::force_https_url( WC()->plugin_url() . '/assets/images/icons/credit-cards/diners' . $ext ) . '" alt="Diners" width="32" ' . $style . ' />';
90
+		if ('USD' === get_woocommerce_currency()) {
91
+			$icon .= '<img src="' . WC_HTTPS::force_https_url(WC()->plugin_url() . '/assets/images/icons/credit-cards/discover' . $ext) . '" alt="Discover" width="32" ' . $style . ' />';
92
+			$icon .= '<img src="' . WC_HTTPS::force_https_url(WC()->plugin_url() . '/assets/images/icons/credit-cards/jcb' . $ext) . '" alt="JCB" width="32" ' . $style . ' />';
93
+			$icon .= '<img src="' . WC_HTTPS::force_https_url(WC()->plugin_url() . '/assets/images/icons/credit-cards/diners' . $ext) . '" alt="Diners" width="32" ' . $style . ' />';
94 94
 		}
95 95
 
96
-		if ( $this->bitcoin ) {
97
-			$icon .= '<img src="' . WC_HTTPS::force_https_url( plugins_url( '/assets/images/bitcoin' . $ext, WC_STRIPE_MAIN_FILE ) ) . '" alt="Bitcoin" width="32" ' . $style . ' />';
96
+		if ($this->bitcoin) {
97
+			$icon .= '<img src="' . WC_HTTPS::force_https_url(plugins_url('/assets/images/bitcoin' . $ext, WC_STRIPE_MAIN_FILE)) . '" alt="Bitcoin" width="32" ' . $style . ' />';
98 98
 		}
99 99
 
100
-		return apply_filters( 'woocommerce_gateway_icon', $icon, $this->id );
100
+		return apply_filters('woocommerce_gateway_icon', $icon, $this->id);
101 101
 	}
102 102
 
103 103
 	/**
104 104
 	 * Get Stripe amount to pay
105 105
 	 * @return float
106 106
 	 */
107
-	public function get_stripe_amount( $total, $currency = '' ) {
108
-		if ( ! $currency ) {
107
+	public function get_stripe_amount($total, $currency = '') {
108
+		if ( ! $currency) {
109 109
 			$currency = get_woocommerce_currency();
110 110
 		}
111
-		switch ( strtoupper( $currency ) ) {
111
+		switch (strtoupper($currency)) {
112 112
 			// Zero decimal currencies
113 113
 			case 'BIF' :
114 114
 			case 'CLP' :
@@ -125,10 +125,10 @@  discard block
 block discarded – undo
125 125
 			case 'XAF' :
126 126
 			case 'XOF' :
127 127
 			case 'XPF' :
128
-				$total = absint( $total );
128
+				$total = absint($total);
129 129
 				break;
130 130
 			default :
131
-				$total = round( $total, 2 ) * 100; // In cents
131
+				$total = round($total, 2) * 100; // In cents
132 132
 				break;
133 133
 		}
134 134
 		return $total;
@@ -138,31 +138,31 @@  discard block
 block discarded – undo
138 138
 	 * Check if SSL is enabled and notify the user
139 139
 	 */
140 140
 	public function admin_notices() {
141
-		if ( $this->enabled == 'no' ) {
141
+		if ($this->enabled == 'no') {
142 142
 			return;
143 143
 		}
144 144
 
145
-		$addons = ( class_exists( 'WC_Subscriptions_Order' ) || class_exists( 'WC_Pre_Orders_Order' ) ) ? '_addons' : '';
145
+		$addons = (class_exists('WC_Subscriptions_Order') || class_exists('WC_Pre_Orders_Order')) ? '_addons' : '';
146 146
 
147 147
 		// Check required fields
148
-		if ( ! $this->secret_key ) {
149
-			echo '<div class="error"><p>' . sprintf( __( 'Stripe error: Please enter your secret key <a href="%s">here</a>', 'woocommerce-gateway-stripe' ), admin_url( 'admin.php?page=wc-settings&tab=checkout&section=wc_gateway_stripe' . $addons ) ) . '</p></div>';
148
+		if ( ! $this->secret_key) {
149
+			echo '<div class="error"><p>' . sprintf(__('Stripe error: Please enter your secret key <a href="%s">here</a>', 'woocommerce-gateway-stripe'), admin_url('admin.php?page=wc-settings&tab=checkout&section=wc_gateway_stripe' . $addons)) . '</p></div>';
150 150
 			return;
151 151
 
152
-		} elseif ( ! $this->publishable_key ) {
153
-			echo '<div class="error"><p>' . sprintf( __( 'Stripe error: Please enter your publishable key <a href="%s">here</a>', 'woocommerce-gateway-stripe' ), admin_url( 'admin.php?page=wc-settings&tab=checkout&section=wc_gateway_stripe' . $addons ) ) . '</p></div>';
152
+		} elseif ( ! $this->publishable_key) {
153
+			echo '<div class="error"><p>' . sprintf(__('Stripe error: Please enter your publishable key <a href="%s">here</a>', 'woocommerce-gateway-stripe'), admin_url('admin.php?page=wc-settings&tab=checkout&section=wc_gateway_stripe' . $addons)) . '</p></div>';
154 154
 			return;
155 155
 		}
156 156
 
157 157
 		// Simple check for duplicate keys
158
-		if ( $this->secret_key == $this->publishable_key ) {
159
-			echo '<div class="error"><p>' . sprintf( __( 'Stripe error: Your secret and publishable keys match. Please check and re-enter.', 'woocommerce-gateway-stripe' ), admin_url( 'admin.php?page=wc-settings&tab=checkout&section=wc_gateway_stripe' . $addons ) ) . '</p></div>';
158
+		if ($this->secret_key == $this->publishable_key) {
159
+			echo '<div class="error"><p>' . sprintf(__('Stripe error: Your secret and publishable keys match. Please check and re-enter.', 'woocommerce-gateway-stripe'), admin_url('admin.php?page=wc-settings&tab=checkout&section=wc_gateway_stripe' . $addons)) . '</p></div>';
160 160
 			return;
161 161
 		}
162 162
 
163 163
 		// Show message if enabled and FORCE SSL is disabled and WordpressHTTPS plugin is not detected
164
-		if ( ( function_exists( 'wc_site_is_https' ) && ! wc_site_is_https() ) && ( 'no' === get_option( 'woocommerce_force_ssl_checkout' ) && ! class_exists( 'WordPressHTTPS' ) ) ) {
165
-			echo '<div class="error"><p>' . sprintf( __( 'Stripe is enabled, but the <a href="%s">force SSL option</a> is disabled; your checkout may not be secure! Please enable SSL and ensure your server has a valid SSL certificate - Stripe will only work in test mode.', 'woocommerce-gateway-stripe' ), admin_url( 'admin.php?page=wc-settings&tab=checkout' ) ) . '</p></div>';
164
+		if ((function_exists('wc_site_is_https') && ! wc_site_is_https()) && ('no' === get_option('woocommerce_force_ssl_checkout') && ! class_exists('WordPressHTTPS'))) {
165
+			echo '<div class="error"><p>' . sprintf(__('Stripe is enabled, but the <a href="%s">force SSL option</a> is disabled; your checkout may not be secure! Please enable SSL and ensure your server has a valid SSL certificate - Stripe will only work in test mode.', 'woocommerce-gateway-stripe'), admin_url('admin.php?page=wc-settings&tab=checkout')) . '</p></div>';
166 166
 		}
167 167
 	}
168 168
 
@@ -170,11 +170,11 @@  discard block
 block discarded – undo
170 170
 	 * Check if this gateway is enabled
171 171
 	 */
172 172
 	public function is_available() {
173
-		if ( 'yes' === $this->enabled ) {
174
-			if ( ! $this->testmode && is_checkout() && ! is_ssl() ) {
173
+		if ('yes' === $this->enabled) {
174
+			if ( ! $this->testmode && is_checkout() && ! is_ssl()) {
175 175
 				return false;
176 176
 			}
177
-			if ( ! $this->secret_key || ! $this->publishable_key ) {
177
+			if ( ! $this->secret_key || ! $this->publishable_key) {
178 178
 				return false;
179 179
 			}
180 180
 			return true;
@@ -186,9 +186,9 @@  discard block
 block discarded – undo
186 186
 	 * Initialise Gateway Settings Form Fields
187 187
 	 */
188 188
 	public function init_form_fields() {
189
-		$this->form_fields = include( untrailingslashit( plugin_dir_path( WC_STRIPE_MAIN_FILE ) ) . '/includes/settings-stripe.php' );
189
+		$this->form_fields = include(untrailingslashit(plugin_dir_path(WC_STRIPE_MAIN_FILE)) . '/includes/settings-stripe.php');
190 190
 
191
-		wc_enqueue_js( "
191
+		wc_enqueue_js("
192 192
 			jQuery( function( $ ) {
193 193
 				$( '#woocommerce_stripe_stripe_checkout' ).change(function(){
194 194
 					if ( $( this ).is( ':checked' ) ) {
@@ -208,25 +208,25 @@  discard block
 block discarded – undo
208 208
 		?>
209 209
 		<fieldset class="stripe-legacy-payment-fields">
210 210
 			<?php
211
-				if ( $this->description ) {
212
-					echo apply_filters( 'wc_stripe_description', wpautop( wp_kses_post( $this->description ) ) );
211
+				if ($this->description) {
212
+					echo apply_filters('wc_stripe_description', wpautop(wp_kses_post($this->description)));
213 213
 				}
214
-				if ( $this->saved_cards && is_user_logged_in() ) {
215
-					$stripe_customer = new WC_Stripe_Customer( get_current_user_id() );
214
+				if ($this->saved_cards && is_user_logged_in()) {
215
+					$stripe_customer = new WC_Stripe_Customer(get_current_user_id());
216 216
 					?>
217 217
 					<p class="form-row form-row-wide">
218
-						<a class="<?php echo apply_filters( 'wc_stripe_manage_saved_cards_class', 'button' ); ?>" style="float:right;" href="<?php echo apply_filters( 'wc_stripe_manage_saved_cards_url', get_permalink( get_option( 'woocommerce_myaccount_page_id' ) ) ); ?>#saved-cards"><?php esc_html_e( 'Manage cards', 'woocommerce-gateway-stripe' ); ?></a>
218
+						<a class="<?php echo apply_filters('wc_stripe_manage_saved_cards_class', 'button'); ?>" style="float:right;" href="<?php echo apply_filters('wc_stripe_manage_saved_cards_url', get_permalink(get_option('woocommerce_myaccount_page_id'))); ?>#saved-cards"><?php esc_html_e('Manage cards', 'woocommerce-gateway-stripe'); ?></a>
219 219
 						<?php
220
-						if ( $cards = $stripe_customer->get_cards() ) {
220
+						if ($cards = $stripe_customer->get_cards()) {
221 221
 							$default_card = $cards[0]->id;
222
-							foreach ( (array) $cards as $card ) {
223
-								if ( 'card' !== $card->object ) {
222
+							foreach ((array) $cards as $card) {
223
+								if ('card' !== $card->object) {
224 224
 									continue;
225 225
 								}
226 226
 								?>
227
-								<label for="stripe_card_<?php echo $card->id; ?>" class="brand-<?php echo esc_attr( strtolower( $card->brand ) ); ?>">
228
-									<input type="radio" id="stripe_card_<?php echo $card->id; ?>" name="wc-stripe-payment-token" value="<?php echo $card->id; ?>" <?php checked( $default_card, $card->id ) ?> />
229
-									<?php printf( __( '%s card ending in %s (Expires %s/%s)', 'woocommerce-gateway-stripe' ), $card->brand, $card->last4, $card->exp_month, $card->exp_year ); ?>
227
+								<label for="stripe_card_<?php echo $card->id; ?>" class="brand-<?php echo esc_attr(strtolower($card->brand)); ?>">
228
+									<input type="radio" id="stripe_card_<?php echo $card->id; ?>" name="wc-stripe-payment-token" value="<?php echo $card->id; ?>" <?php checked($default_card, $card->id) ?> />
229
+									<?php printf(__('%s card ending in %s (Expires %s/%s)', 'woocommerce-gateway-stripe'), $card->brand, $card->last4, $card->exp_month, $card->exp_year); ?>
230 230
 								</label>
231 231
 								<?php
232 232
 							}
@@ -234,7 +234,7 @@  discard block
 block discarded – undo
234 234
 						?>
235 235
 						<label for="new">
236 236
 							<input type="radio" id="new" name="wc-stripe-payment-token" value="new" />
237
-							<?php _e( 'Use a new credit card', 'woocommerce-gateway-stripe' ); ?>
237
+							<?php _e('Use a new credit card', 'woocommerce-gateway-stripe'); ?>
238 238
 						</label>
239 239
 					</p>
240 240
 					<?php
@@ -242,8 +242,8 @@  discard block
 block discarded – undo
242 242
 
243 243
 				$user = wp_get_current_user();
244 244
 
245
-				if ( $user ) {
246
-					$user_email = get_user_meta( $user->ID, 'billing_email', true );
245
+				if ($user) {
246
+					$user_email = get_user_meta($user->ID, 'billing_email', true);
247 247
 					$user_email = $user_email ? $user_email : $user->user_email;
248 248
 				} else {
249 249
 					$user_email = '';
@@ -251,22 +251,22 @@  discard block
 block discarded – undo
251 251
 
252 252
 				$display = '';
253 253
 
254
-				if ( $this->stripe_checkout || $this->saved_cards && ! empty( $cards ) ) {
254
+				if ($this->stripe_checkout || $this->saved_cards && ! empty($cards)) {
255 255
 					$display = 'style="display:none;"';
256 256
 				}
257 257
 
258 258
 				echo '<div ' . $display . ' id="stripe-payment-data"
259 259
 					data-description=""
260
-					data-email="' . esc_attr( $user_email ) . '"
261
-					data-amount="' . esc_attr( $this->get_stripe_amount( WC()->cart->total ) ) . '"
262
-					data-name="' . esc_attr( get_bloginfo( 'name', 'display' ) ) . '"
263
-					data-currency="' . esc_attr( strtolower( get_woocommerce_currency() ) ) . '"
264
-					data-image="' . esc_attr( $this->stripe_checkout_image ) . '"
265
-					data-bitcoin="' . esc_attr( $this->bitcoin ? 'true' : 'false' ) . '"
266
-					data-locale="' . esc_attr( $this->stripe_checkout_locale ? $this->stripe_checkout_locale : 'en' ) . '">';
267
-
268
-				if ( ! $this->stripe_checkout ) {
269
-					$this->credit_card_form( array( 'fields_have_names' => false ) );
260
+					data-email="' . esc_attr($user_email) . '"
261
+					data-amount="' . esc_attr($this->get_stripe_amount(WC()->cart->total)) . '"
262
+					data-name="' . esc_attr(get_bloginfo('name', 'display')) . '"
263
+					data-currency="' . esc_attr(strtolower(get_woocommerce_currency())) . '"
264
+					data-image="' . esc_attr($this->stripe_checkout_image) . '"
265
+					data-bitcoin="' . esc_attr($this->bitcoin ? 'true' : 'false') . '"
266
+					data-locale="' . esc_attr($this->stripe_checkout_locale ? $this->stripe_checkout_locale : 'en') . '">';
267
+
268
+				if ( ! $this->stripe_checkout) {
269
+					$this->credit_card_form(array('fields_have_names' => false));
270 270
 				}
271 271
 
272 272
 				echo '</div>';
@@ -283,27 +283,27 @@  discard block
 block discarded – undo
283 283
 	 * @access public
284 284
 	 */
285 285
 	public function payment_scripts() {
286
-		if ( $this->stripe_checkout ) {
287
-			wp_enqueue_script( 'stripe', 'https://checkout.stripe.com/v2/checkout.js', '', '2.0', true );
288
-			wp_enqueue_script( 'woocommerce_stripe', plugins_url( 'assets/js/stripe_checkout.js', WC_STRIPE_MAIN_FILE ), array( 'stripe' ), WC_STRIPE_VERSION, true );
286
+		if ($this->stripe_checkout) {
287
+			wp_enqueue_script('stripe', 'https://checkout.stripe.com/v2/checkout.js', '', '2.0', true);
288
+			wp_enqueue_script('woocommerce_stripe', plugins_url('assets/js/stripe_checkout.js', WC_STRIPE_MAIN_FILE), array('stripe'), WC_STRIPE_VERSION, true);
289 289
 		} else {
290
-			wp_enqueue_script( 'stripe', 'https://js.stripe.com/v2/', '', '1.0', true );
291
-			wp_enqueue_script( 'woocommerce_stripe', plugins_url( 'assets/js/stripe.js', WC_STRIPE_MAIN_FILE ), array( 'jquery-payment', 'stripe' ), WC_STRIPE_VERSION, true );
290
+			wp_enqueue_script('stripe', 'https://js.stripe.com/v2/', '', '1.0', true);
291
+			wp_enqueue_script('woocommerce_stripe', plugins_url('assets/js/stripe.js', WC_STRIPE_MAIN_FILE), array('jquery-payment', 'stripe'), WC_STRIPE_VERSION, true);
292 292
 		}
293 293
 
294 294
 		$stripe_params = array(
295 295
 			'key'                  => $this->publishable_key,
296
-			'i18n_terms'           => __( 'Please accept the terms and conditions first', 'woocommerce-gateway-stripe' ),
297
-			'i18n_required_fields' => __( 'Please fill in required checkout fields first', 'woocommerce-gateway-stripe' ),
296
+			'i18n_terms'           => __('Please accept the terms and conditions first', 'woocommerce-gateway-stripe'),
297
+			'i18n_required_fields' => __('Please fill in required checkout fields first', 'woocommerce-gateway-stripe'),
298 298
 		);
299 299
 
300 300
 		// If we're on the pay page we need to pass stripe.js the address of the order.
301
-		if ( is_checkout_pay_page() && isset( $_GET['order'] ) && isset( $_GET['order_id'] ) ) {
302
-			$order_key = urldecode( $_GET['order'] );
303
-			$order_id  = absint( $_GET['order_id'] );
304
-			$order     = wc_get_order( $order_id );
301
+		if (is_checkout_pay_page() && isset($_GET['order']) && isset($_GET['order_id'])) {
302
+			$order_key = urldecode($_GET['order']);
303
+			$order_id  = absint($_GET['order_id']);
304
+			$order     = wc_get_order($order_id);
305 305
 
306
-			if ( $order->id === $order_id && $order->order_key === $order_key ) {
306
+			if ($order->id === $order_id && $order->order_key === $order_key) {
307 307
 				$stripe_params['billing_first_name'] = $order->billing_first_name;
308 308
 				$stripe_params['billing_last_name']  = $order->billing_last_name;
309 309
 				$stripe_params['billing_address_1']  = $order->billing_address_1;
@@ -315,7 +315,7 @@  discard block
 block discarded – undo
315 315
 			}
316 316
 		}
317 317
 
318
-		wp_localize_script( 'woocommerce_stripe', 'wc_stripe_params', apply_filters( 'wc_stripe_params', $stripe_params ) );
318
+		wp_localize_script('woocommerce_stripe', 'wc_stripe_params', apply_filters('wc_stripe_params', $stripe_params));
319 319
 	}
320 320
 
321 321
 	/**
@@ -324,28 +324,28 @@  discard block
 block discarded – undo
324 324
 	 * @param  object $source
325 325
 	 * @return array()
326 326
 	 */
327
-	protected function generate_payment_request( $order, $source ) {
327
+	protected function generate_payment_request($order, $source) {
328 328
 		$post_data                = array();
329
-		$post_data['currency']    = strtolower( $order->get_order_currency() ? $order->get_order_currency() : get_woocommerce_currency() );
330
-		$post_data['amount']      = $this->get_stripe_amount( $order->get_total(), $post_data['currency'] );
331
-		$post_data['description'] = sprintf( __( '%s - Order %s', 'woocommerce-gateway-stripe' ), wp_specialchars_decode( get_bloginfo( 'name' ), ENT_QUOTES ), $order->get_order_number() );
329
+		$post_data['currency']    = strtolower($order->get_order_currency() ? $order->get_order_currency() : get_woocommerce_currency());
330
+		$post_data['amount']      = $this->get_stripe_amount($order->get_total(), $post_data['currency']);
331
+		$post_data['description'] = sprintf(__('%s - Order %s', 'woocommerce-gateway-stripe'), wp_specialchars_decode(get_bloginfo('name'), ENT_QUOTES), $order->get_order_number());
332 332
 		$post_data['capture']     = $this->capture ? 'true' : 'false';
333 333
 
334
-		if ( ! empty( $order->billing_email ) && apply_filters( 'wc_stripe_send_stripe_receipt', false ) ) {
334
+		if ( ! empty($order->billing_email) && apply_filters('wc_stripe_send_stripe_receipt', false)) {
335 335
 			$post_data['receipt_email'] = $order->billing_email;
336 336
 		}
337 337
 
338
-		$post_data['expand[]']    = 'balance_transaction';
338
+		$post_data['expand[]'] = 'balance_transaction';
339 339
 
340
-		if ( $source->customer ) {
340
+		if ($source->customer) {
341 341
 			$post_data['customer'] = $source->customer;
342 342
 		}
343 343
 
344
-		if ( $source->source ) {
344
+		if ($source->source) {
345 345
 			$post_data['source'] = $source->source;
346 346
 		}
347 347
 
348
-		return apply_filters( 'wc_stripe_generate_payment_request', $post_data, $order, $source );
348
+		return apply_filters('wc_stripe_generate_payment_request', $post_data, $order, $source);
349 349
 	}
350 350
 
351 351
 	/**
@@ -353,22 +353,22 @@  discard block
 block discarded – undo
353 353
 	 * @param  bool $force_customer Should we force customer creation?
354 354
 	 * @return object
355 355
 	 */
356
-	protected function get_source( $user_id, $force_customer = false ) {
357
-		$stripe_customer = new WC_Stripe_Customer( $user_id );
356
+	protected function get_source($user_id, $force_customer = false) {
357
+		$stripe_customer = new WC_Stripe_Customer($user_id);
358 358
 		$stripe_source   = false;
359 359
 		$token_id        = false;
360 360
 
361 361
 		// New CC info was entered and we have a new token to process
362
-		if ( isset( $_POST['stripe_token'] ) ) {
363
-			$stripe_token     = wc_clean( $_POST['stripe_token'] );
364
-			$maybe_saved_card = isset( $_POST['wc-stripe-new-payment-method'] ) && ! empty( $_POST['wc-stripe-new-payment-method'] );
362
+		if (isset($_POST['stripe_token'])) {
363
+			$stripe_token     = wc_clean($_POST['stripe_token']);
364
+			$maybe_saved_card = isset($_POST['wc-stripe-new-payment-method']) && ! empty($_POST['wc-stripe-new-payment-method']);
365 365
 
366 366
 			// This is true if the user wants to store the card to their account.
367
-			if ( ( $user_id && $this->saved_cards && $maybe_saved_card ) || $force_customer ) {
368
-				$stripe_source = $stripe_customer->add_card( $stripe_token );
367
+			if (($user_id && $this->saved_cards && $maybe_saved_card) || $force_customer) {
368
+				$stripe_source = $stripe_customer->add_card($stripe_token);
369 369
 
370
-				if ( is_wp_error( $stripe_source ) ) {
371
-					throw new Exception( $stripe_source->get_error_message() );
370
+				if (is_wp_error($stripe_source)) {
371
+					throw new Exception($stripe_source->get_error_message());
372 372
 				}
373 373
 
374 374
 			} else {
@@ -379,8 +379,8 @@  discard block
 block discarded – undo
379 379
 		}
380 380
 
381 381
 		// Use an existing token, and then process the payment
382
-		elseif ( isset( $_POST['wc-stripe-payment-token'] ) && 'new' !== $_POST['wc-stripe-payment-token'] ) {
383
-			$stripe_source = wc_clean( $_POST['wc-stripe-payment-token'] );
382
+		elseif (isset($_POST['wc-stripe-payment-token']) && 'new' !== $_POST['wc-stripe-payment-token']) {
383
+			$stripe_source = wc_clean($_POST['wc-stripe-payment-token']);
384 384
 		}
385 385
 
386 386
 		return (object) array(
@@ -401,16 +401,16 @@  discard block
 block discarded – undo
401 401
 	 * @param object $order
402 402
 	 * @return object
403 403
 	 */
404
-	protected function get_order_source( $order = null ) {
404
+	protected function get_order_source($order = null) {
405 405
 		$stripe_customer = new WC_Stripe_Customer();
406 406
 		$stripe_source   = false;
407 407
 		$token_id        = false;
408 408
 
409
-		if ( $order ) {
410
-			if ( $meta_value = get_post_meta( $order->id, '_stripe_customer_id', true ) ) {
411
-				$stripe_customer->set_id( $meta_value );
409
+		if ($order) {
410
+			if ($meta_value = get_post_meta($order->id, '_stripe_customer_id', true)) {
411
+				$stripe_customer->set_id($meta_value);
412 412
 			}
413
-			if ( $meta_value = get_post_meta( $order->id, '_stripe_card_id', true ) ) {
413
+			if ($meta_value = get_post_meta($order->id, '_stripe_card_id', true)) {
414 414
 				$stripe_source = $meta_value;
415 415
 			}
416 416
 		}
@@ -425,43 +425,43 @@  discard block
 block discarded – undo
425 425
 	/**
426 426
 	 * Process the payment
427 427
 	 */
428
-	public function process_payment( $order_id, $retry = true, $force_customer = false ) {
428
+	public function process_payment($order_id, $retry = true, $force_customer = false) {
429 429
 		try {
430
-			$order  = wc_get_order( $order_id );
431
-			$source = $this->get_source( get_current_user_id(), $force_customer );
430
+			$order  = wc_get_order($order_id);
431
+			$source = $this->get_source(get_current_user_id(), $force_customer);
432 432
 
433
-			if ( empty( $source->source ) && empty( $source->customer ) ) {
434
-				$error_msg = __( 'Please enter your card details to make a payment.', 'woocommerce-gateway-stripe' );
435
-				$error_msg .= ' ' . __( 'Developers: Please make sure that you are including jQuery and there are no JavaScript errors on the page.', 'woocommerce-gateway-stripe' );
436
-				throw new Exception( $error_msg );
433
+			if (empty($source->source) && empty($source->customer)) {
434
+				$error_msg = __('Please enter your card details to make a payment.', 'woocommerce-gateway-stripe');
435
+				$error_msg .= ' ' . __('Developers: Please make sure that you are including jQuery and there are no JavaScript errors on the page.', 'woocommerce-gateway-stripe');
436
+				throw new Exception($error_msg);
437 437
 			}
438 438
 
439 439
 			// Store source to order meta
440
-			$this->save_source( $order, $source );
440
+			$this->save_source($order, $source);
441 441
 
442 442
 			// Handle payment
443
-			if ( $order->get_total() > 0 ) {
443
+			if ($order->get_total() > 0) {
444 444
 
445
-				if ( $order->get_total() * 100 < WC_Stripe::get_minimum_amount() ) {
446
-					throw new Exception( sprintf( __( 'Sorry, the minimum allowed order total is %1$s to use this payment method.', 'woocommerce-gateway-stripe' ), wc_price( WC_Stripe::get_minimum_amount() / 100 ) ) );
445
+				if ($order->get_total() * 100 < WC_Stripe::get_minimum_amount()) {
446
+					throw new Exception(sprintf(__('Sorry, the minimum allowed order total is %1$s to use this payment method.', 'woocommerce-gateway-stripe'), wc_price(WC_Stripe::get_minimum_amount() / 100)));
447 447
 				}
448 448
 
449
-				WC_Stripe::log( "Info: Begin processing payment for order $order_id for the amount of {$order->get_total()}" );
449
+				WC_Stripe::log("Info: Begin processing payment for order $order_id for the amount of {$order->get_total()}");
450 450
 
451 451
 				// Make the request
452
-				$response = WC_Stripe_API::request( $this->generate_payment_request( $order, $source ) );
452
+				$response = WC_Stripe_API::request($this->generate_payment_request($order, $source));
453 453
 
454
-				if ( is_wp_error( $response ) ) {
454
+				if (is_wp_error($response)) {
455 455
 					// Customer param wrong? The user may have been deleted on stripe's end. Remove customer_id. Can be retried without.
456
-					if ( 'customer' === $response->get_error_code() && $retry ) {
457
-						delete_user_meta( get_current_user_id(), '_stripe_customer_id' );
458
-						return $this->process_payment( $order_id, false, $force_customer );
456
+					if ('customer' === $response->get_error_code() && $retry) {
457
+						delete_user_meta(get_current_user_id(), '_stripe_customer_id');
458
+						return $this->process_payment($order_id, false, $force_customer);
459 459
 					}
460
-					throw new Exception( $response->get_error_code() . ': ' . $response->get_error_message() );
460
+					throw new Exception($response->get_error_code() . ': ' . $response->get_error_message());
461 461
 				}
462 462
 
463 463
 				// Process valid response
464
-				$this->process_response( $response, $order );
464
+				$this->process_response($response, $order);
465 465
 			} else {
466 466
 				$order->payment_complete();
467 467
 			}
@@ -472,13 +472,13 @@  discard block
 block discarded – undo
472 472
 			// Return thank you page redirect
473 473
 			return array(
474 474
 				'result'   => 'success',
475
-				'redirect' => $this->get_return_url( $order )
475
+				'redirect' => $this->get_return_url($order)
476 476
 			);
477 477
 
478
-		} catch ( Exception $e ) {
479
-			wc_add_notice( $e->getMessage(), 'error' );
480
-			WC()->session->set( 'refresh_totals', true );
481
-			WC_Stripe::log( sprintf( __( 'Error: %s', 'woocommerce-gateway-stripe' ), $e->getMessage() ) );
478
+		} catch (Exception $e) {
479
+			wc_add_notice($e->getMessage(), 'error');
480
+			WC()->session->set('refresh_totals', true);
481
+			WC_Stripe::log(sprintf(__('Error: %s', 'woocommerce-gateway-stripe'), $e->getMessage()));
482 482
 			return;
483 483
 		}
484 484
 	}
@@ -486,45 +486,45 @@  discard block
 block discarded – undo
486 486
 	/**
487 487
 	 * Save source to order.
488 488
 	 */
489
-	protected function save_source( $order, $source ) {
489
+	protected function save_source($order, $source) {
490 490
 		// Store source in the order
491
-		if ( $source->customer ) {
492
-			update_post_meta( $order->id, '_stripe_customer_id', $source->customer );
491
+		if ($source->customer) {
492
+			update_post_meta($order->id, '_stripe_customer_id', $source->customer);
493 493
 		}
494
-		if ( $source->source ) {
495
-			update_post_meta( $order->id, '_stripe_card_id', $source->source->id );
494
+		if ($source->source) {
495
+			update_post_meta($order->id, '_stripe_card_id', $source->source->id);
496 496
 		}
497 497
 	}
498 498
 
499 499
 	/**
500 500
 	 * Store extra meta data for an order from a Stripe Response.
501 501
 	 */
502
-	public function process_response( $response, $order ) {
503
-		WC_Stripe::log( "Processing response: " . print_r( $response, true ) );
502
+	public function process_response($response, $order) {
503
+		WC_Stripe::log("Processing response: " . print_r($response, true));
504 504
 
505 505
 		// Store charge data
506
-		update_post_meta( $order->id, '_stripe_charge_id', $response->id );
507
-		update_post_meta( $order->id, '_stripe_charge_captured', $response->captured ? 'yes' : 'no' );
506
+		update_post_meta($order->id, '_stripe_charge_id', $response->id);
507
+		update_post_meta($order->id, '_stripe_charge_captured', $response->captured ? 'yes' : 'no');
508 508
 
509 509
 		// Store other data such as fees
510
-		if ( isset( $response->balance_transaction ) && isset( $response->balance_transaction->fee ) ) {
511
-			$fee = number_format( $response->balance_transaction->fee / 100, 2, '.', '' );
512
-			update_post_meta( $order->id, 'Stripe Fee', $fee );
513
-			update_post_meta( $order->id, 'Net Revenue From Stripe', $order->get_total() - $fee );
510
+		if (isset($response->balance_transaction) && isset($response->balance_transaction->fee)) {
511
+			$fee = number_format($response->balance_transaction->fee / 100, 2, '.', '');
512
+			update_post_meta($order->id, 'Stripe Fee', $fee);
513
+			update_post_meta($order->id, 'Net Revenue From Stripe', $order->get_total() - $fee);
514 514
 		}
515 515
 
516
-		if ( $response->captured ) {
517
-			$order->payment_complete( $response->id );
518
-			WC_Stripe::log( "Successful charge: $response->id" );
516
+		if ($response->captured) {
517
+			$order->payment_complete($response->id);
518
+			WC_Stripe::log("Successful charge: $response->id");
519 519
 		} else {
520
-			add_post_meta( $order->id, '_transaction_id', $response->id, true );
520
+			add_post_meta($order->id, '_transaction_id', $response->id, true);
521 521
 
522
-			if ( $order->has_status( array( 'pending', 'failed' ) ) ) {
522
+			if ($order->has_status(array('pending', 'failed'))) {
523 523
 				$order->reduce_order_stock();
524 524
 			}
525 525
 
526
-			$order->update_status( 'on-hold', sprintf( __( 'Stripe charge authorized (Charge ID: %s). Process order to take payment, or cancel to remove the pre-authorization.', 'woocommerce-gateway-stripe' ), $response->id ) );
527
-			WC_Stripe::log( "Successful auth: $response->id" );
526
+			$order->update_status('on-hold', sprintf(__('Stripe charge authorized (Charge ID: %s). Process order to take payment, or cancel to remove the pre-authorization.', 'woocommerce-gateway-stripe'), $response->id));
527
+			WC_Stripe::log("Successful auth: $response->id");
528 528
 		}
529 529
 
530 530
 		return $response;
@@ -536,21 +536,21 @@  discard block
 block discarded – undo
536 536
 	 * @since 3.0.0
537 537
 	 */
538 538
 	public function add_payment_method() {
539
-		if ( empty( $_POST['stripe_token'] ) || ! is_user_logged_in() ) {
540
-			wc_add_notice( __( 'There was a problem adding the card.', 'woocommerce-gateway-stripe' ), 'error' );
539
+		if (empty($_POST['stripe_token']) || ! is_user_logged_in()) {
540
+			wc_add_notice(__('There was a problem adding the card.', 'woocommerce-gateway-stripe'), 'error');
541 541
 			return;
542 542
 		}
543 543
 
544
-		$stripe_customer = new WC_Stripe_Customer( get_current_user_id() );
545
-		$result          = $stripe_customer->add_card( wc_clean( $_POST['stripe_token'] ) );
544
+		$stripe_customer = new WC_Stripe_Customer(get_current_user_id());
545
+		$result          = $stripe_customer->add_card(wc_clean($_POST['stripe_token']));
546 546
 
547
-		if ( is_wp_error( $result ) ) {
548
-			throw new Exception( $result->get_error_message() );
547
+		if (is_wp_error($result)) {
548
+			throw new Exception($result->get_error_message());
549 549
 		}
550 550
 
551 551
 		return array(
552 552
 			'result'   => 'success',
553
-			'redirect' => wc_get_endpoint_url( 'payment-methods' ),
553
+			'redirect' => wc_get_endpoint_url('payment-methods'),
554 554
 		);
555 555
 	}
556 556
 
@@ -560,36 +560,36 @@  discard block
 block discarded – undo
560 560
 	 * @param  float $amount
561 561
 	 * @return bool
562 562
 	 */
563
-	public function process_refund( $order_id, $amount = null, $reason = '' ) {
564
-		$order = wc_get_order( $order_id );
563
+	public function process_refund($order_id, $amount = null, $reason = '') {
564
+		$order = wc_get_order($order_id);
565 565
 
566
-		if ( ! $order || ! $order->get_transaction_id() ) {
566
+		if ( ! $order || ! $order->get_transaction_id()) {
567 567
 			return false;
568 568
 		}
569 569
 
570 570
 		$body = array();
571 571
 
572
-		if ( ! is_null( $amount ) ) {
573
-			$body['amount']	= $this->get_stripe_amount( $amount );
572
+		if ( ! is_null($amount)) {
573
+			$body['amount'] = $this->get_stripe_amount($amount);
574 574
 		}
575 575
 
576
-		if ( $reason ) {
576
+		if ($reason) {
577 577
 			$body['metadata'] = array(
578 578
 				'reason'	=> $reason,
579 579
 			);
580 580
 		}
581 581
 
582
-		WC_Stripe::log( "Info: Beginning refund for order $order_id for the amount of {$amount}" );
582
+		WC_Stripe::log("Info: Beginning refund for order $order_id for the amount of {$amount}");
583 583
 
584
-		$response = WC_Stripe_API::request( $body, 'charges/' . $order->get_transaction_id() . '/refunds' );
584
+		$response = WC_Stripe_API::request($body, 'charges/' . $order->get_transaction_id() . '/refunds');
585 585
 
586
-		if ( is_wp_error( $response ) ) {
587
-			WC_Stripe::log( "Error: " . $response->get_error_message() );
586
+		if (is_wp_error($response)) {
587
+			WC_Stripe::log("Error: " . $response->get_error_message());
588 588
 			return $response;
589
-		} elseif ( ! empty( $response->id ) ) {
590
-			$refund_message = sprintf( __( 'Refunded %s - Refund ID: %s - Reason: %s', 'woocommerce-gateway-stripe' ), wc_price( $response->amount / 100 ), $response->id, $reason );
591
-			$order->add_order_note( $refund_message );
592
-			WC_Stripe::log( "Success: " . html_entity_decode( strip_tags( $refund_message ) ) );
589
+		} elseif ( ! empty($response->id)) {
590
+			$refund_message = sprintf(__('Refunded %s - Refund ID: %s - Reason: %s', 'woocommerce-gateway-stripe'), wc_price($response->amount / 100), $response->id, $reason);
591
+			$order->add_order_note($refund_message);
592
+			WC_Stripe::log("Success: " . html_entity_decode(strip_tags($refund_message)));
593 593
 			return true;
594 594
 		}
595 595
 	}
Please login to merge, or discard this patch.
includes/class-wc-gateway-stripe-addons.php 1 patch
Spacing   +125 added lines, -125 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
 
@@ -16,22 +16,22 @@  discard block
 block discarded – undo
16 16
 	public function __construct() {
17 17
 		parent::__construct();
18 18
 
19
-		if ( class_exists( 'WC_Subscriptions_Order' ) ) {
20
-			add_action( 'woocommerce_scheduled_subscription_payment_' . $this->id, array( $this, 'scheduled_subscription_payment' ), 10, 2 );
21
-			add_action( 'wcs_resubscribe_order_created', array( $this, 'delete_resubscribe_meta' ), 10 );
22
-			add_action( 'wcs_renewal_order_created', array( $this, 'delete_renewal_meta' ), 10 );
23
-			add_action( 'woocommerce_subscription_failing_payment_method_updated_stripe', array( $this, 'update_failing_payment_method' ), 10, 2 );
19
+		if (class_exists('WC_Subscriptions_Order')) {
20
+			add_action('woocommerce_scheduled_subscription_payment_' . $this->id, array($this, 'scheduled_subscription_payment'), 10, 2);
21
+			add_action('wcs_resubscribe_order_created', array($this, 'delete_resubscribe_meta'), 10);
22
+			add_action('wcs_renewal_order_created', array($this, 'delete_renewal_meta'), 10);
23
+			add_action('woocommerce_subscription_failing_payment_method_updated_stripe', array($this, 'update_failing_payment_method'), 10, 2);
24 24
 
25 25
 			// display the credit card used for a subscription in the "My Subscriptions" table
26
-			add_filter( 'woocommerce_my_subscriptions_payment_method', array( $this, 'maybe_render_subscription_payment_method' ), 10, 2 );
26
+			add_filter('woocommerce_my_subscriptions_payment_method', array($this, 'maybe_render_subscription_payment_method'), 10, 2);
27 27
 
28 28
 			// allow store managers to manually set Stripe as the payment method on a subscription
29
-			add_filter( 'woocommerce_subscription_payment_meta', array( $this, 'add_subscription_payment_meta' ), 10, 2 );
30
-			add_filter( 'woocommerce_subscription_validate_payment_meta', array( $this, 'validate_subscription_payment_meta' ), 10, 2 );
29
+			add_filter('woocommerce_subscription_payment_meta', array($this, 'add_subscription_payment_meta'), 10, 2);
30
+			add_filter('woocommerce_subscription_validate_payment_meta', array($this, 'validate_subscription_payment_meta'), 10, 2);
31 31
 		}
32 32
 
33
-		if ( class_exists( 'WC_Pre_Orders_Order' ) ) {
34
-			add_action( 'wc_pre_orders_process_pre_order_completion_payment_' . $this->id, array( $this, 'process_pre_order_release_payment' ) );
33
+		if (class_exists('WC_Pre_Orders_Order')) {
34
+			add_action('wc_pre_orders_process_pre_order_completion_payment_' . $this->id, array($this, 'process_pre_order_release_payment'));
35 35
 		}
36 36
 	}
37 37
 
@@ -40,8 +40,8 @@  discard block
 block discarded – undo
40 40
 	 * @param  int  $order_id
41 41
 	 * @return boolean
42 42
 	 */
43
-	protected function is_subscription( $order_id ) {
44
-		return ( function_exists( 'wcs_order_contains_subscription' ) && ( wcs_order_contains_subscription( $order_id ) || wcs_is_subscription( $order_id ) || wcs_order_contains_renewal( $order_id ) ) );
43
+	protected function is_subscription($order_id) {
44
+		return (function_exists('wcs_order_contains_subscription') && (wcs_order_contains_subscription($order_id) || wcs_is_subscription($order_id) || wcs_order_contains_renewal($order_id)));
45 45
 	}
46 46
 
47 47
 	/**
@@ -49,8 +49,8 @@  discard block
 block discarded – undo
49 49
 	 * @param  int  $order_id
50 50
 	 * @return boolean
51 51
 	 */
52
-	protected function is_pre_order( $order_id ) {
53
-		return ( class_exists( 'WC_Pre_Orders_Order' ) && WC_Pre_Orders_Order::order_contains_pre_order( $order_id ) );
52
+	protected function is_pre_order($order_id) {
53
+		return (class_exists('WC_Pre_Orders_Order') && WC_Pre_Orders_Order::order_contains_pre_order($order_id));
54 54
 	}
55 55
 
56 56
 	/**
@@ -58,37 +58,37 @@  discard block
 block discarded – undo
58 58
 	 * @param  int $order_id
59 59
 	 * @return array
60 60
 	 */
61
-	public function process_payment( $order_id, $retry = true, $force_customer = false ) {
62
-		if ( $this->is_subscription( $order_id ) ) {
61
+	public function process_payment($order_id, $retry = true, $force_customer = false) {
62
+		if ($this->is_subscription($order_id)) {
63 63
 			// Regular payment with force customer enabled
64
-			return parent::process_payment( $order_id, true, true );
64
+			return parent::process_payment($order_id, true, true);
65 65
 
66
-		} elseif ( $this->is_pre_order( $order_id ) ) {
67
-			return $this->process_pre_order( $order_id, $retry, $force_customer );
66
+		} elseif ($this->is_pre_order($order_id)) {
67
+			return $this->process_pre_order($order_id, $retry, $force_customer);
68 68
 
69 69
 		} else {
70
-			return parent::process_payment( $order_id, $retry, $force_customer );
70
+			return parent::process_payment($order_id, $retry, $force_customer);
71 71
 		}
72 72
 	}
73 73
 
74 74
 	/**
75 75
 	 * Updates other subscription sources.
76 76
 	 */
77
-	protected function save_source( $order, $source ) {
78
-		parent::save_source( $order, $source );
77
+	protected function save_source($order, $source) {
78
+		parent::save_source($order, $source);
79 79
 
80 80
 		// Also store it on the subscriptions being purchased or paid for in the order
81
-		if ( function_exists( 'wcs_order_contains_subscription' ) && wcs_order_contains_subscription( $order->id ) ) {
82
-			$subscriptions = wcs_get_subscriptions_for_order( $order->id );
83
-		} elseif ( function_exists( 'wcs_order_contains_renewal' ) && wcs_order_contains_renewal( $order->id ) ) {
84
-			$subscriptions = wcs_get_subscriptions_for_renewal_order( $order->id );
81
+		if (function_exists('wcs_order_contains_subscription') && wcs_order_contains_subscription($order->id)) {
82
+			$subscriptions = wcs_get_subscriptions_for_order($order->id);
83
+		} elseif (function_exists('wcs_order_contains_renewal') && wcs_order_contains_renewal($order->id)) {
84
+			$subscriptions = wcs_get_subscriptions_for_renewal_order($order->id);
85 85
 		} else {
86 86
 			$subscriptions = array();
87 87
 		}
88 88
 
89
-		foreach ( $subscriptions as $subscription ) {
90
-			update_post_meta( $subscription->id, '_stripe_customer_id', $source->customer );
91
-			update_post_meta( $subscription->id, '_stripe_card_id', $source->source );
89
+		foreach ($subscriptions as $subscription) {
90
+			update_post_meta($subscription->id, '_stripe_customer_id', $source->customer);
91
+			update_post_meta($subscription->id, '_stripe_card_id', $source->source);
92 92
 		}
93 93
 	}
94 94
 
@@ -99,38 +99,38 @@  discard block
 block discarded – undo
99 99
 	 * @param string $stripe_token (default: '')
100 100
 	 * @param  bool initial_payment
101 101
 	 */
102
-	public function process_subscription_payment( $order = '', $amount = 0 ) {
103
-		if ( $amount * 100 < WC_Stripe::get_minimum_amount() ) {
104
-			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 ) ) );
102
+	public function process_subscription_payment($order = '', $amount = 0) {
103
+		if ($amount * 100 < WC_Stripe::get_minimum_amount()) {
104
+			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)));
105 105
 		}
106 106
 
107 107
 		// Get source from order
108
-		$source = $this->get_order_source( $order );
108
+		$source = $this->get_order_source($order);
109 109
 
110 110
 		// If no order source was defined, use user source instead.
111
-		if ( ! $source->customer ) {
112
-			$source = $this->get_source( $order->customer_user );
111
+		if ( ! $source->customer) {
112
+			$source = $this->get_source($order->customer_user);
113 113
 		}
114 114
 
115 115
 		// Or fail :(
116
-		if ( ! $source->customer ) {
117
-			return new WP_Error( 'stripe_error', __( 'Customer not found', 'woocommerce-gateway-stripe' ) );
116
+		if ( ! $source->customer) {
117
+			return new WP_Error('stripe_error', __('Customer not found', 'woocommerce-gateway-stripe'));
118 118
 		}
119 119
 
120
-		$this->log( "Info: Begin processing subscription payment for order {$order->id} for the amount of {$amount}" );
120
+		$this->log("Info: Begin processing subscription payment for order {$order->id} for the amount of {$amount}");
121 121
 
122 122
 		// Make the request
123
-		$request             = $this->generate_payment_request( $order, $source );
123
+		$request             = $this->generate_payment_request($order, $source);
124 124
 		$request['capture']  = 'true';
125
-		$request['amount']   = $this->get_stripe_amount( $amount, $request['currency'] );
125
+		$request['amount']   = $this->get_stripe_amount($amount, $request['currency']);
126 126
 		$request['metadata'] = array(
127 127
 			'payment_type'   => 'recurring',
128 128
 		);
129
-		$response            = WC_Stripe_API::request( $request );
129
+		$response            = WC_Stripe_API::request($request);
130 130
 
131 131
 		// Process valid response
132
-		if ( ! is_wp_error( $response ) ) {
133
-			$this->process_response( $response, $order );
132
+		if ( ! is_wp_error($response)) {
133
+			$this->process_response($response, $order);
134 134
 		}
135 135
 
136 136
 		return $response;
@@ -141,42 +141,42 @@  discard block
 block discarded – undo
141 141
 	 * @param int $order_id
142 142
 	 * @return array
143 143
 	 */
144
-	public function process_pre_order( $order_id, $retry, $force_customer ) {
145
-		if ( WC_Pre_Orders_Order::order_requires_payment_tokenization( $order_id ) ) {
144
+	public function process_pre_order($order_id, $retry, $force_customer) {
145
+		if (WC_Pre_Orders_Order::order_requires_payment_tokenization($order_id)) {
146 146
 			try {
147
-				$order = wc_get_order( $order_id );
147
+				$order = wc_get_order($order_id);
148 148
 
149
-				if ( $order->get_total() * 100 < WC_Stripe::get_minimum_amount() ) {
150
-					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 ) ) );
149
+				if ($order->get_total() * 100 < WC_Stripe::get_minimum_amount()) {
150
+					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)));
151 151
 				}
152 152
 
153
-				$source = $this->get_source( get_current_user_id(), true );
153
+				$source = $this->get_source(get_current_user_id(), true);
154 154
 
155 155
 				// We need a source on file to continue.
156
-				if ( empty( $source->customer ) || empty( $source->source ) ) {
157
-					throw new Exception( __( 'Unable to store payment details. Please try again.', 'woocommerce-gateway-stripe' ) );
156
+				if (empty($source->customer) || empty($source->source)) {
157
+					throw new Exception(__('Unable to store payment details. Please try again.', 'woocommerce-gateway-stripe'));
158 158
 				}
159 159
 
160 160
 				// Store source to order meta
161
-				$this->save_source( $order, $source );
161
+				$this->save_source($order, $source);
162 162
 
163 163
 				// Remove cart
164 164
 				WC()->cart->empty_cart();
165 165
 
166 166
 				// Is pre ordered!
167
-				WC_Pre_Orders_Order::mark_order_as_pre_ordered( $order );
167
+				WC_Pre_Orders_Order::mark_order_as_pre_ordered($order);
168 168
 
169 169
 				// Return thank you page redirect
170 170
 				return array(
171 171
 					'result'   => 'success',
172
-					'redirect' => $this->get_return_url( $order ),
172
+					'redirect' => $this->get_return_url($order),
173 173
 				);
174
-			} catch ( Exception $e ) {
175
-				wc_add_notice( $e->getMessage(), 'error' );
174
+			} catch (Exception $e) {
175
+				wc_add_notice($e->getMessage(), 'error');
176 176
 				return;
177 177
 			}
178 178
 		} else {
179
-			return parent::process_payment( $order_id, $retry, $force_customer );
179
+			return parent::process_payment($order_id, $retry, $force_customer);
180 180
 		}
181 181
 	}
182 182
 
@@ -185,7 +185,7 @@  discard block
 block discarded – undo
185 185
 	 * @param WC_Order $order
186 186
 	 * @return void
187 187
 	 */
188
-	public function process_pre_order_release_payment( $order ) {
188
+	public function process_pre_order_release_payment($order) {
189 189
 		try {
190 190
 			// Define some callbacks if the first attempt fails.
191 191
 			$retry_callbacks = array(
@@ -193,32 +193,32 @@  discard block
 block discarded – undo
193 193
 				'remove_order_customer_before_retry',
194 194
 			);
195 195
 
196
-			while ( 1 ) {
197
-				$source   = $this->get_order_source( $order );
198
-				$response = WC_Stripe_API::request( $this->generate_payment_request( $order, $source ) );
196
+			while (1) {
197
+				$source   = $this->get_order_source($order);
198
+				$response = WC_Stripe_API::request($this->generate_payment_request($order, $source));
199 199
 
200
-				if ( is_wp_error( $response ) ) {
201
-					if ( 0 === sizeof( $retry_callbacks ) ) {
202
-						throw new Exception( $response->get_error_message() );
200
+				if (is_wp_error($response)) {
201
+					if (0 === sizeof($retry_callbacks)) {
202
+						throw new Exception($response->get_error_message());
203 203
 					} else {
204
-						$retry_callback = array_shift( $retry_callbacks );
205
-						call_user_func( array( $this, $retry_callback ), $order );
204
+						$retry_callback = array_shift($retry_callbacks);
205
+						call_user_func(array($this, $retry_callback), $order);
206 206
 					}
207 207
 				} else {
208 208
 					// Successful
209
-					$this->process_response( $response, $order );
209
+					$this->process_response($response, $order);
210 210
 					break;
211 211
 				}
212 212
 			}
213
-		} catch ( Exception $e ) {
214
-			$order_note = sprintf( __( 'Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe' ), $e->getMessage() );
213
+		} catch (Exception $e) {
214
+			$order_note = sprintf(__('Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe'), $e->getMessage());
215 215
 
216 216
 			// Mark order as failed if not already set,
217 217
 			// otherwise, make sure we add the order note so we can detect when someone fails to check out multiple times
218
-			if ( ! $order->has_status( 'failed' ) ) {
219
-				$order->update_status( 'failed', $order_note );
218
+			if ( ! $order->has_status('failed')) {
219
+				$order->update_status('failed', $order_note);
220 220
 			} else {
221
-				$order->add_order_note( $order_note );
221
+				$order->add_order_note($order_note);
222 222
 			}
223 223
 		}
224 224
 	}
@@ -227,20 +227,20 @@  discard block
 block discarded – undo
227 227
 	 * Don't transfer Stripe customer/token meta to resubscribe orders.
228 228
 	 * @param int $resubscribe_order The order created for the customer to resubscribe to the old expired/cancelled subscription
229 229
 	 */
230
-	public function delete_resubscribe_meta( $resubscribe_order ) {
231
-		delete_post_meta( $resubscribe_order->id, '_stripe_customer_id' );
232
-		delete_post_meta( $resubscribe_order->id, '_stripe_card_id' );
233
-		$this->delete_renewal_meta( $resubscribe_order );
230
+	public function delete_resubscribe_meta($resubscribe_order) {
231
+		delete_post_meta($resubscribe_order->id, '_stripe_customer_id');
232
+		delete_post_meta($resubscribe_order->id, '_stripe_card_id');
233
+		$this->delete_renewal_meta($resubscribe_order);
234 234
 	}
235 235
 
236 236
 	/**
237 237
 	 * Don't transfer Stripe fee/ID meta to renewal orders.
238 238
 	 * @param int $resubscribe_order The order created for the customer to resubscribe to the old expired/cancelled subscription
239 239
 	 */
240
-	public function delete_renewal_meta( $renewal_order ) {
241
-		delete_post_meta( $renewal_order->id, 'Stripe Fee' );
242
-		delete_post_meta( $renewal_order->id, 'Net Revenue From Stripe' );
243
-		delete_post_meta( $renewal_order->id, 'Stripe Payment ID' );
240
+	public function delete_renewal_meta($renewal_order) {
241
+		delete_post_meta($renewal_order->id, 'Stripe Fee');
242
+		delete_post_meta($renewal_order->id, 'Net Revenue From Stripe');
243
+		delete_post_meta($renewal_order->id, 'Stripe Payment ID');
244 244
 		return $renewal_order;
245 245
 	}
246 246
 
@@ -250,11 +250,11 @@  discard block
 block discarded – undo
250 250
 	 * @param $amount_to_charge float The amount to charge.
251 251
 	 * @param $renewal_order WC_Order A WC_Order object created to record the renewal payment.
252 252
 	 */
253
-	public function scheduled_subscription_payment( $amount_to_charge, $renewal_order ) {
254
-		$response = $this->process_subscription_payment( $renewal_order, $amount_to_charge );
253
+	public function scheduled_subscription_payment($amount_to_charge, $renewal_order) {
254
+		$response = $this->process_subscription_payment($renewal_order, $amount_to_charge);
255 255
 
256
-		if ( is_wp_error( $response ) ) {
257
-			$renewal_order->update_status( 'failed', sprintf( __( 'Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe' ), $response->get_error_message() ) );
256
+		if (is_wp_error($response)) {
257
+			$renewal_order->update_status('failed', sprintf(__('Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe'), $response->get_error_message()));
258 258
 		}
259 259
 	}
260 260
 
@@ -262,16 +262,16 @@  discard block
 block discarded – undo
262 262
 	 * Remove order meta
263 263
 	 * @param  object $order
264 264
 	 */
265
-	public function remove_order_source_before_retry( $order ) {
266
-		delete_post_meta( $order->id, '_stripe_card_id' );
265
+	public function remove_order_source_before_retry($order) {
266
+		delete_post_meta($order->id, '_stripe_card_id');
267 267
 	}
268 268
 
269 269
 	/**
270 270
 	 * Remove order meta
271 271
 	 * @param  object $order
272 272
 	 */
273
-	public function remove_order_customer_before_retry( $order ) {
274
-		delete_post_meta( $order->id, '_stripe_customer_id' );
273
+	public function remove_order_customer_before_retry($order) {
274
+		delete_post_meta($order->id, '_stripe_customer_id');
275 275
 	}
276 276
 
277 277
 	/**
@@ -283,9 +283,9 @@  discard block
 block discarded – undo
283 283
 	 * @param WC_Order $renewal_order The order which recorded the successful payment (to make up for the failed automatic payment).
284 284
 	 * @return void
285 285
 	 */
286
-	public function update_failing_payment_method( $subscription, $renewal_order ) {
287
-		update_post_meta( $subscription->id, '_stripe_customer_id', $renewal_order->stripe_customer_id );
288
-		update_post_meta( $subscription->id, '_stripe_card_id', $renewal_order->stripe_card_id );
286
+	public function update_failing_payment_method($subscription, $renewal_order) {
287
+		update_post_meta($subscription->id, '_stripe_customer_id', $renewal_order->stripe_customer_id);
288
+		update_post_meta($subscription->id, '_stripe_card_id', $renewal_order->stripe_card_id);
289 289
 	}
290 290
 
291 291
 	/**
@@ -297,15 +297,15 @@  discard block
 block discarded – undo
297 297
 	 * @param WC_Subscription $subscription An instance of a subscription object
298 298
 	 * @return array
299 299
 	 */
300
-	public function add_subscription_payment_meta( $payment_meta, $subscription ) {
301
-		$payment_meta[ $this->id ] = array(
300
+	public function add_subscription_payment_meta($payment_meta, $subscription) {
301
+		$payment_meta[$this->id] = array(
302 302
 			'post_meta' => array(
303 303
 				'_stripe_customer_id' => array(
304
-					'value' => get_post_meta( $subscription->id, '_stripe_customer_id', true ),
304
+					'value' => get_post_meta($subscription->id, '_stripe_customer_id', true),
305 305
 					'label' => 'Stripe Customer ID',
306 306
 				),
307 307
 				'_stripe_card_id' => array(
308
-					'value' => get_post_meta( $subscription->id, '_stripe_card_id', true ),
308
+					'value' => get_post_meta($subscription->id, '_stripe_card_id', true),
309 309
 					'label' => 'Stripe Card ID',
310 310
 				),
311 311
 			),
@@ -322,17 +322,17 @@  discard block
 block discarded – undo
322 322
 	 * @param array $payment_meta associative array of meta data required for automatic payments
323 323
 	 * @return array
324 324
 	 */
325
-	public function validate_subscription_payment_meta( $payment_method_id, $payment_meta ) {
326
-		if ( $this->id === $payment_method_id ) {
325
+	public function validate_subscription_payment_meta($payment_method_id, $payment_meta) {
326
+		if ($this->id === $payment_method_id) {
327 327
 
328
-			if ( ! isset( $payment_meta['post_meta']['_stripe_customer_id']['value'] ) || empty( $payment_meta['post_meta']['_stripe_customer_id']['value'] ) ) {
329
-				throw new Exception( 'A "_stripe_customer_id" value is required.' );
330
-			} elseif ( 0 !== strpos( $payment_meta['post_meta']['_stripe_customer_id']['value'], 'cus_' ) ) {
331
-				throw new Exception( 'Invalid customer ID. A valid "_stripe_customer_id" must begin with "cus_".' );
328
+			if ( ! isset($payment_meta['post_meta']['_stripe_customer_id']['value']) || empty($payment_meta['post_meta']['_stripe_customer_id']['value'])) {
329
+				throw new Exception('A "_stripe_customer_id" value is required.');
330
+			} elseif (0 !== strpos($payment_meta['post_meta']['_stripe_customer_id']['value'], 'cus_')) {
331
+				throw new Exception('Invalid customer ID. A valid "_stripe_customer_id" must begin with "cus_".');
332 332
 			}
333 333
 
334
-			if ( ! empty( $payment_meta['post_meta']['_stripe_card_id']['value'] ) && 0 !== strpos( $payment_meta['post_meta']['_stripe_card_id']['value'], 'card_' ) ) {
335
-				throw new Exception( 'Invalid card ID. A valid "_stripe_card_id" must begin with "card_".' );
334
+			if ( ! empty($payment_meta['post_meta']['_stripe_card_id']['value']) && 0 !== strpos($payment_meta['post_meta']['_stripe_card_id']['value'], 'card_')) {
335
+				throw new Exception('Invalid card ID. A valid "_stripe_card_id" must begin with "card_".');
336 336
 			}
337 337
 		}
338 338
 	}
@@ -345,43 +345,43 @@  discard block
 block discarded – undo
345 345
 	 * @param WC_Subscription $subscription the subscription details
346 346
 	 * @return string the subscription payment method
347 347
 	 */
348
-	public function maybe_render_subscription_payment_method( $payment_method_to_display, $subscription ) {
348
+	public function maybe_render_subscription_payment_method($payment_method_to_display, $subscription) {
349 349
 		// bail for other payment methods
350
-		if ( $this->id !== $subscription->payment_method || ! $subscription->customer_user ) {
350
+		if ($this->id !== $subscription->payment_method || ! $subscription->customer_user) {
351 351
 			return $payment_method_to_display;
352 352
 		}
353 353
 
354 354
 		$stripe_customer    = new WC_Stripe_Customer();
355
-		$stripe_customer_id = get_post_meta( $subscription->id, '_stripe_customer_id', true );
356
-		$stripe_card_id     = get_post_meta( $subscription->id, '_stripe_card_id', true );
355
+		$stripe_customer_id = get_post_meta($subscription->id, '_stripe_customer_id', true);
356
+		$stripe_card_id     = get_post_meta($subscription->id, '_stripe_card_id', true);
357 357
 
358 358
 		// If we couldn't find a Stripe customer linked to the subscription, fallback to the user meta data.
359
-		if ( ! $stripe_customer_id || ! is_string( $stripe_customer_id ) ) {
359
+		if ( ! $stripe_customer_id || ! is_string($stripe_customer_id)) {
360 360
 			$user_id            = $subscription->customer_user;
361
-			$stripe_customer_id = get_user_meta( $user_id, '_stripe_customer_id', true );
362
-			$stripe_card_id     = get_user_meta( $user_id, '_stripe_card_id', true );
361
+			$stripe_customer_id = get_user_meta($user_id, '_stripe_customer_id', true);
362
+			$stripe_card_id     = get_user_meta($user_id, '_stripe_card_id', true);
363 363
 		}
364 364
 
365 365
 		// If we couldn't find a Stripe customer linked to the account, fallback to the order meta data.
366
-		if ( ( ! $stripe_customer_id || ! is_string( $stripe_customer_id ) ) && false !== $subscription->order ) {
367
-			$stripe_customer_id = get_post_meta( $subscription->order->id, '_stripe_customer_id', true );
368
-			$stripe_card_id     = get_post_meta( $subscription->order->id, '_stripe_card_id', true );
366
+		if (( ! $stripe_customer_id || ! is_string($stripe_customer_id)) && false !== $subscription->order) {
367
+			$stripe_customer_id = get_post_meta($subscription->order->id, '_stripe_customer_id', true);
368
+			$stripe_card_id     = get_post_meta($subscription->order->id, '_stripe_card_id', true);
369 369
 		}
370 370
 
371
-		$stripe_customer->set_id( $stripe_customer_id );
371
+		$stripe_customer->set_id($stripe_customer_id);
372 372
 		$cards = $stripe_customer->get_cards();
373 373
 
374
-		if ( $cards ) {
374
+		if ($cards) {
375 375
 			$found_card = false;
376
-			foreach ( $cards as $card ) {
377
-				if ( $card->id === $stripe_card_id ) {
376
+			foreach ($cards as $card) {
377
+				if ($card->id === $stripe_card_id) {
378 378
 					$found_card                = true;
379
-					$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 );
379
+					$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);
380 380
 					break;
381 381
 				}
382 382
 			}
383
-			if ( ! $found_card ) {
384
-				$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 );
383
+			if ( ! $found_card) {
384
+				$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);
385 385
 			}
386 386
 		}
387 387
 
@@ -396,11 +396,11 @@  discard block
 block discarded – undo
396 396
 	 *
397 397
 	 * @param string $message
398 398
 	 */
399
-	public function log( $message ) {
400
-		$options = get_option( 'woocommerce_stripe_settings' );
399
+	public function log($message) {
400
+		$options = get_option('woocommerce_stripe_settings');
401 401
 
402
-		if ( 'yes' === $options['logging'] ) {
403
-			WC_Stripe::log( $message );
402
+		if ('yes' === $options['logging']) {
403
+			WC_Stripe::log($message);
404 404
 		}
405 405
 	}
406 406
 }
Please login to merge, or discard this patch.
includes/class-wc-stripe-api.php 1 patch
Spacing   +22 added lines, -22 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,39 +51,39 @@  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
 		// Handle response
78
-		if ( ! empty( $parsed_response->error ) ) {
79
-			if ( ! empty( $parsed_response->error->param ) ) {
78
+		if ( ! empty($parsed_response->error)) {
79
+			if ( ! empty($parsed_response->error->param)) {
80 80
 				$code = $parsed_response->error->param;
81
-			} elseif ( ! empty( $parsed_response->error->code ) ) {
81
+			} elseif ( ! empty($parsed_response->error->code)) {
82 82
 				$code = $parsed_response->error->code;
83 83
 			} else {
84 84
 				$code = 'stripe_error';
85 85
 			}
86
-			return new WP_Error( $code, $parsed_response->error->message );
86
+			return new WP_Error($code, $parsed_response->error->message);
87 87
 		} else {
88 88
 			return $parsed_response;
89 89
 		}
@@ -97,11 +97,11 @@  discard block
 block discarded – undo
97 97
 	 *
98 98
 	 * @param string $message
99 99
 	 */
100
-	public static function log( $message ) {
101
-		$options = get_option( 'woocommerce_stripe_settings' );
100
+	public static function log($message) {
101
+		$options = get_option('woocommerce_stripe_settings');
102 102
 
103
-		if ( 'yes' === $options['logging'] ) {
104
-			WC_Stripe::log( $message );
103
+		if ('yes' === $options['logging']) {
104
+			WC_Stripe::log($message);
105 105
 		}
106 106
 	}
107 107
 }
Please login to merge, or discard this patch.
includes/class-wc-stripe-customer.php 1 patch
Spacing   +70 added lines, -70 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,44 +169,44 @@  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 ) ) {
184
-			if ( 'customer' === $response->get_error_code() && $retry ) {
183
+		if (is_wp_error($response)) {
184
+			if ('customer' === $response->get_error_code() && $retry) {
185 185
 				$this->create_customer();
186
-				return $this->add_card( $token, false );
186
+				return $this->add_card($token, false);
187 187
 			} else {
188 188
 				return $response;
189 189
 			}
190
-		} elseif ( empty( $response->id ) ) {
191
-			return new WP_Error( 'error', __( 'Unable to add card', 'woocommerce-gateway-stripe' ) );
190
+		} elseif (empty($response->id)) {
191
+			return new WP_Error('error', __('Unable to add card', 'woocommerce-gateway-stripe'));
192 192
 		}
193 193
 
194 194
 		// Add token to WooCommerce
195
-		if ( $this->get_user_id() && class_exists( 'WC_Payment_Token_CC' ) ) {
195
+		if ($this->get_user_id() && class_exists('WC_Payment_Token_CC')) {
196 196
 			$token = new WC_Payment_Token_CC();
197
-			$token->set_token( $response->id );
198
-			$token->set_gateway_id( 'stripe' );
199
-			$token->set_card_type( strtolower( $response->brand ) );
200
-			$token->set_last4( $response->last4 );
201
-			$token->set_expiry_month( $response->exp_month );
202
-			$token->set_expiry_year( $response->exp_year );
203
-			$token->set_user_id( $this->get_user_id() );
197
+			$token->set_token($response->id);
198
+			$token->set_gateway_id('stripe');
199
+			$token->set_card_type(strtolower($response->brand));
200
+			$token->set_last4($response->last4);
201
+			$token->set_expiry_month($response->exp_month);
202
+			$token->set_expiry_year($response->exp_year);
203
+			$token->set_user_id($this->get_user_id());
204 204
 			$token->save();
205 205
 		}
206 206
 
207 207
 		$this->clear_cache();
208 208
 
209
-		do_action( 'woocommerce_stripe_add_card', $this->get_id(), $token, $response );
209
+		do_action('woocommerce_stripe_add_card', $this->get_id(), $token, $response);
210 210
 
211 211
 		return $response->id;
212 212
 	}
@@ -220,20 +220,20 @@  discard block
 block discarded – undo
220 220
 	public function get_cards() {
221 221
 		$cards = array();
222 222
 
223
-		if ( $this->get_id() && false === ( $cards = get_transient( 'stripe_cards_' . $this->get_id() ) ) ) {
224
-			$response = WC_Stripe_API::request( array(
223
+		if ($this->get_id() && false === ($cards = get_transient('stripe_cards_' . $this->get_id()))) {
224
+			$response = WC_Stripe_API::request(array(
225 225
 				'limit'       => 100,
226
-			), 'customers/' . $this->get_id() . '/sources', 'GET' );
226
+			), 'customers/' . $this->get_id() . '/sources', 'GET');
227 227
 
228
-			if ( is_wp_error( $response ) ) {
228
+			if (is_wp_error($response)) {
229 229
 				return array();
230 230
 			}
231 231
 
232
-			if ( is_array( $response->data ) ) {
232
+			if (is_array($response->data)) {
233 233
 				$cards = $response->data;
234 234
 			}
235 235
 
236
-			set_transient( 'stripe_cards_' . $this->get_id(), $cards, HOUR_IN_SECONDS * 48 );
236
+			set_transient('stripe_cards_' . $this->get_id(), $cards, HOUR_IN_SECONDS * 48);
237 237
 		}
238 238
 
239 239
 		return $cards;
@@ -243,13 +243,13 @@  discard block
 block discarded – undo
243 243
 	 * Delete a card from stripe.
244 244
 	 * @param string $card_id
245 245
 	 */
246
-	public function delete_card( $card_id ) {
247
-		$response = WC_Stripe_API::request( array(), 'customers/' . $this->get_id() . '/sources/' . sanitize_text_field( $card_id ), 'DELETE' );
246
+	public function delete_card($card_id) {
247
+		$response = WC_Stripe_API::request(array(), 'customers/' . $this->get_id() . '/sources/' . sanitize_text_field($card_id), 'DELETE');
248 248
 
249 249
 		$this->clear_cache();
250 250
 
251
-		if ( ! is_wp_error( $response ) ) {
252
-			do_action( 'wc_stripe_delete_card', $this->get_id(), $response );
251
+		if ( ! is_wp_error($response)) {
252
+			do_action('wc_stripe_delete_card', $this->get_id(), $response);
253 253
 
254 254
 			return true;
255 255
 		}
@@ -261,15 +261,15 @@  discard block
 block discarded – undo
261 261
 	 * Set default card in Stripe
262 262
 	 * @param string $card_id
263 263
 	 */
264
-	public function set_default_card( $card_id ) {
265
-		$response = WC_Stripe_API::request( array(
266
-			'default_source' => sanitize_text_field( $card_id ),
267
-		), 'customers/' . $this->get_id(), 'POST' );
264
+	public function set_default_card($card_id) {
265
+		$response = WC_Stripe_API::request(array(
266
+			'default_source' => sanitize_text_field($card_id),
267
+		), 'customers/' . $this->get_id(), 'POST');
268 268
 
269 269
 		$this->clear_cache();
270 270
 
271
-		if ( ! is_wp_error( $response ) ) {
272
-			do_action( 'wc_stripe_set_default_card', $this->get_id(), $response );
271
+		if ( ! is_wp_error($response)) {
272
+			do_action('wc_stripe_set_default_card', $this->get_id(), $response);
273 273
 
274 274
 			return true;
275 275
 		}
@@ -281,8 +281,8 @@  discard block
 block discarded – undo
281 281
 	 * Deletes caches for this users cards.
282 282
 	 */
283 283
 	public function clear_cache() {
284
-		delete_transient( 'stripe_cards_' . $this->get_id() );
285
-		delete_transient( 'stripe_customer_' . $this->get_id() );
284
+		delete_transient('stripe_cards_' . $this->get_id());
285
+		delete_transient('stripe_customer_' . $this->get_id());
286 286
 		$this->customer_data = array();
287 287
 	}
288 288
 }
Please login to merge, or discard this patch.
includes/class-wc-stripe-payment-request.php 1 patch
Spacing   +84 added lines, -84 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.1.0
141 141
 	 * @param array $address
142 142
 	 */
143
-	public function calculate_shipping( $address = array() ) {
143
+	public function calculate_shipping($address = array()) {
144 144
 		$country   = $address['country'];
145 145
 		$state     = $address['state'];
146 146
 		$postcode  = $address['postcode'];
@@ -150,19 +150,19 @@  discard block
 block discarded – undo
150 150
 
151 151
 		WC()->shipping->reset_shipping();
152 152
 
153
-		if ( $postcode && WC_Validation::is_postcode( $postcode, $country ) ) {
154
-			$postcode = wc_format_postcode( $postcode, $country );
153
+		if ($postcode && WC_Validation::is_postcode($postcode, $country)) {
154
+			$postcode = wc_format_postcode($postcode, $country);
155 155
 		}
156 156
 
157
-		if ( $country ) {
158
-			WC()->customer->set_location( $country, $state, $postcode, $city );
159
-			WC()->customer->set_shipping_location( $country, $state, $postcode, $city );
157
+		if ($country) {
158
+			WC()->customer->set_location($country, $state, $postcode, $city);
159
+			WC()->customer->set_shipping_location($country, $state, $postcode, $city);
160 160
 		} else {
161 161
 			WC()->customer->set_to_base();
162 162
 			WC()->customer->set_shipping_to_base();
163 163
 		}
164 164
 
165
-		WC()->customer->calculated_shipping( true );
165
+		WC()->customer->calculated_shipping(true);
166 166
 
167 167
 		$packages = array();
168 168
 
@@ -177,17 +177,17 @@  discard block
 block discarded – undo
177 177
 		$packages[0]['destination']['address']   = $address_1;
178 178
 		$packages[0]['destination']['address_2'] = $address_2;
179 179
 
180
-		foreach ( WC()->cart->get_cart() as $item ) {
181
-			if ( $item['data']->needs_shipping() ) {
182
-				if ( isset( $item['line_total'] ) ) {
180
+		foreach (WC()->cart->get_cart() as $item) {
181
+			if ($item['data']->needs_shipping()) {
182
+				if (isset($item['line_total'])) {
183 183
 					$packages[0]['contents_cost'] += $item['line_total'];
184 184
 				}
185 185
 			}
186 186
 		}
187 187
 
188
-		$packages = apply_filters( 'woocommerce_cart_shipping_packages', $packages );
188
+		$packages = apply_filters('woocommerce_cart_shipping_packages', $packages);
189 189
 
190
-		WC()->shipping->calculate_shipping( $packages );
190
+		WC()->shipping->calculate_shipping($packages);
191 191
 	}
192 192
 
193 193
 	/**
@@ -198,19 +198,19 @@  discard block
 block discarded – undo
198 198
 	 * @see WC_Shipping::get_packages().
199 199
 	 */
200 200
 	public function ajax_get_shipping_options() {
201
-		check_ajax_referer( 'wc-stripe-payment-request-shipping', 'security' );
201
+		check_ajax_referer('wc-stripe-payment-request-shipping', 'security');
202 202
 
203 203
 		// Set the shipping package.
204
-		$posted   = filter_input_array( INPUT_POST, array(
204
+		$posted = filter_input_array(INPUT_POST, array(
205 205
 			'country'   => FILTER_SANITIZE_STRING,
206 206
 			'state'     => FILTER_SANITIZE_STRING,
207 207
 			'postcode'  => FILTER_SANITIZE_STRING,
208 208
 			'city'      => FILTER_SANITIZE_STRING,
209 209
 			'address'   => FILTER_SANITIZE_STRING,
210 210
 			'address_2' => FILTER_SANITIZE_STRING,
211
-		) );
211
+		));
212 212
 
213
-		$this->calculate_shipping( $posted );
213
+		$this->calculate_shipping($posted);
214 214
 
215 215
 		// Set the shipping options.
216 216
 		$currency = get_woocommerce_currency();
@@ -218,13 +218,13 @@  discard block
 block discarded – undo
218 218
 
219 219
 		$packages = WC()->shipping->get_packages();
220 220
 
221
-		if ( ! empty( $packages ) && WC()->customer->has_calculated_shipping() ) {
222
-			foreach ( $packages as $package_key => $package ) {
223
-				if ( empty( $package['rates'] ) ) {
221
+		if ( ! empty($packages) && WC()->customer->has_calculated_shipping()) {
222
+			foreach ($packages as $package_key => $package) {
223
+				if (empty($package['rates'])) {
224 224
 					break;
225 225
 				}
226 226
 
227
-				foreach ( $package['rates'] as $key => $rate ) {
227
+				foreach ($package['rates'] as $key => $rate) {
228 228
 					$data[] = array(
229 229
 						'id'       => $rate->id,
230 230
 						'label'    => $rate->label,
@@ -239,60 +239,60 @@  discard block
 block discarded – undo
239 239
 		}
240 240
 
241 241
 		// Auto select when have only one shipping method available.
242
-		if ( 1 === count( $data ) ) {
242
+		if (1 === count($data)) {
243 243
 			$data[0]['selected'] = true;
244 244
 		}
245 245
 
246
-		wp_send_json( $data );
246
+		wp_send_json($data);
247 247
 	}
248 248
 
249 249
 	/**
250 250
 	 * Update shipping method.
251 251
 	 */
252 252
 	public function ajax_update_shipping_method() {
253
-		check_ajax_referer( 'wc-stripe-update-shipping-method', 'security' );
253
+		check_ajax_referer('wc-stripe-update-shipping-method', 'security');
254 254
 
255
-		if ( ! defined( 'WOOCOMMERCE_CART' ) ) {
256
-			define( 'WOOCOMMERCE_CART', true );
255
+		if ( ! defined('WOOCOMMERCE_CART')) {
256
+			define('WOOCOMMERCE_CART', true);
257 257
 		}
258 258
 
259
-		$chosen_shipping_methods = WC()->session->get( 'chosen_shipping_methods' );
260
-		$shipping_method         = filter_input( INPUT_POST, 'shipping_method', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY );
259
+		$chosen_shipping_methods = WC()->session->get('chosen_shipping_methods');
260
+		$shipping_method         = filter_input(INPUT_POST, 'shipping_method', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY);
261 261
 
262
-		if ( is_array( $shipping_method ) ) {
263
-			foreach ( $shipping_method as $i => $value ) {
264
-				$chosen_shipping_methods[ $i ] = wc_clean( $value );
262
+		if (is_array($shipping_method)) {
263
+			foreach ($shipping_method as $i => $value) {
264
+				$chosen_shipping_methods[$i] = wc_clean($value);
265 265
 			}
266 266
 		}
267 267
 
268
-		WC()->session->set( 'chosen_shipping_methods', $chosen_shipping_methods );
268
+		WC()->session->set('chosen_shipping_methods', $chosen_shipping_methods);
269 269
 
270 270
 		WC()->cart->calculate_totals();
271 271
 
272 272
 		// Send back the new cart total and line items to be displayed, such as subtotal, shipping rate(s), fees and taxes.
273
-		$data      = array(
273
+		$data = array(
274 274
 			'total' => WC()->cart->total,
275
-			'items' => $this->compute_display_items( $shipping_method[0] ),
275
+			'items' => $this->compute_display_items($shipping_method[0]),
276 276
 		);
277 277
 
278
-		wp_send_json( $data );
278
+		wp_send_json($data);
279 279
 	}
280 280
 
281 281
 	/**
282 282
 	 * Create order.
283 283
 	 */
284 284
 	public function ajax_create_order() {
285
-		if ( WC()->cart->is_empty() ) {
286
-			wp_send_json_error( __( 'Empty cart', 'woocommerce-gateway-stripe' ) );
285
+		if (WC()->cart->is_empty()) {
286
+			wp_send_json_error(__('Empty cart', 'woocommerce-gateway-stripe'));
287 287
 		}
288 288
 
289
-		if ( ! defined( 'WOOCOMMERCE_CHECKOUT' ) ) {
290
-			define( 'WOOCOMMERCE_CHECKOUT', true );
289
+		if ( ! defined('WOOCOMMERCE_CHECKOUT')) {
290
+			define('WOOCOMMERCE_CHECKOUT', true);
291 291
 		}
292 292
 
293 293
 		WC()->checkout()->process_checkout();
294 294
 
295
-		die( 0 );
295
+		die(0);
296 296
 	}
297 297
 
298 298
 	/**
@@ -300,26 +300,26 @@  discard block
 block discarded – undo
300 300
 	 *
301 301
 	 * @param string shipping_method_id If shipping method ID is provided, will include display items about shipping.
302 302
 	 */
303
-	protected function compute_display_items( $shipping_method_id ) {
303
+	protected function compute_display_items($shipping_method_id) {
304 304
 		$currency = get_woocommerce_currency();
305 305
 		$items = array(
306 306
 			// Subtotal excluding tax, because taxes is a separate item, below.
307 307
 			array(
308
-				'label' => __( 'Subtotal', 'woocommerce-gateway-stripe' ),
308
+				'label' => __('Subtotal', 'woocommerce-gateway-stripe'),
309 309
 				'amount' => array(
310
-					'value'    => max( 0, round( WC()->cart->subtotal_ex_tax, WC()->cart->dp ) ),
310
+					'value'    => max(0, round(WC()->cart->subtotal_ex_tax, WC()->cart->dp)),
311 311
 					'currency' => $currency,
312 312
 				),
313 313
 			),
314 314
 		);
315 315
 		// If a chosen shipping option was provided, add line item(s) for it and include the shipping tax.
316
-		$tax_total = max( 0, round( WC()->cart->tax_total, WC()->cart->dp ) );
317
-		if ( $shipping_method_id ) {
318
-			$tax_total = max( 0, round( WC()->cart->tax_total + WC()->cart->shipping_tax_total, WC()->cart->dp ) );
316
+		$tax_total = max(0, round(WC()->cart->tax_total, WC()->cart->dp));
317
+		if ($shipping_method_id) {
318
+			$tax_total = max(0, round(WC()->cart->tax_total + WC()->cart->shipping_tax_total, WC()->cart->dp));
319 319
 			// Look through the package rates for $shipping_method_id, and when found, add a line item.
320
-			foreach ( WC()->shipping->get_packages() as $package_key => $package ) {
321
-				foreach ( $package['rates'] as $key => $rate ) {
322
-					if ( $rate->id  == $shipping_method_id ) {
320
+			foreach (WC()->shipping->get_packages() as $package_key => $package) {
321
+				foreach ($package['rates'] as $key => $rate) {
322
+					if ($rate->id == $shipping_method_id) {
323 323
 						$items[] = array(
324 324
 							'label' => $rate->label,
325 325
 							'amount' => array(
@@ -333,7 +333,7 @@  discard block
 block discarded – undo
333 333
 			}
334 334
 		}
335 335
 		// Include fees and taxes as display items.
336
-		foreach ( WC()->cart->fees as $key => $fee ) {
336
+		foreach (WC()->cart->fees as $key => $fee) {
337 337
 			$items[] = array(
338 338
 				'label'  => $fee->name,
339 339
 				'amount' => array(
@@ -343,9 +343,9 @@  discard block
 block discarded – undo
343 343
 			);
344 344
 		}
345 345
 		// The tax total may include the shipping taxes if a shipping option is provided.
346
-		if ( 0 < $tax_total ) {
346
+		if (0 < $tax_total) {
347 347
 			$items[] = array(
348
-				'label'  => __( 'Tax', 'woocommerce-gateway-stripe' ),
348
+				'label'  => __('Tax', 'woocommerce-gateway-stripe'),
349 349
 				'amount' => array(
350 350
 					'currency' => $currency,
351 351
 					'value'    => $tax_total,
Please login to merge, or discard this patch.
woocommerce-gateway-stripe.php 1 patch
Spacing   +126 added lines, -126 removed lines patch added patch discarded remove patch
@@ -25,21 +25,21 @@  discard block
 block discarded – undo
25 25
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
26 26
 */
27 27
 
28
-if ( ! defined( 'ABSPATH' ) ) {
28
+if ( ! defined('ABSPATH')) {
29 29
 	exit;
30 30
 }
31 31
 
32 32
 /**
33 33
  * Required minimums and constants
34 34
  */
35
-define( 'WC_STRIPE_VERSION', '3.0.6' );
36
-define( 'WC_STRIPE_MIN_PHP_VER', '5.3.0' );
37
-define( 'WC_STRIPE_MIN_WC_VER', '2.5.0' );
38
-define( 'WC_STRIPE_MAIN_FILE', __FILE__ );
39
-define( 'WC_STRIPE_PLUGIN_URL', untrailingslashit( plugins_url( basename( plugin_dir_path( __FILE__ ) ), basename( __FILE__ ) ) ) );
40
-define( 'WC_STRIPE_PLUGIN_PATH', untrailingslashit( plugin_dir_path( __FILE__ ) ) );
35
+define('WC_STRIPE_VERSION', '3.0.6');
36
+define('WC_STRIPE_MIN_PHP_VER', '5.3.0');
37
+define('WC_STRIPE_MIN_WC_VER', '2.5.0');
38
+define('WC_STRIPE_MAIN_FILE', __FILE__);
39
+define('WC_STRIPE_PLUGIN_URL', untrailingslashit(plugins_url(basename(plugin_dir_path(__FILE__)), basename(__FILE__))));
40
+define('WC_STRIPE_PLUGIN_PATH', untrailingslashit(plugin_dir_path(__FILE__)));
41 41
 
42
-if ( ! class_exists( 'WC_Stripe' ) ) :
42
+if ( ! class_exists('WC_Stripe')) :
43 43
 
44 44
 	class WC_Stripe {
45 45
 
@@ -59,7 +59,7 @@  discard block
 block discarded – undo
59 59
 		 * @return Singleton The *Singleton* instance.
60 60
 		 */
61 61
 		public static function get_instance() {
62
-			if ( null === self::$instance ) {
62
+			if (null === self::$instance) {
63 63
 				self::$instance = new self();
64 64
 			}
65 65
 			return self::$instance;
@@ -108,9 +108,9 @@  discard block
 block discarded – undo
108 108
 		 * *Singleton* via the `new` operator from outside of this class.
109 109
 		 */
110 110
 		protected function __construct() {
111
-			add_action( 'admin_init', array( $this, 'check_environment' ) );
112
-			add_action( 'admin_notices', array( $this, 'admin_notices' ), 15 );
113
-			add_action( 'plugins_loaded', array( $this, 'init' ) );
111
+			add_action('admin_init', array($this, 'check_environment'));
112
+			add_action('admin_notices', array($this, 'admin_notices'), 15);
113
+			add_action('plugins_loaded', array($this, 'init'));
114 114
 		}
115 115
 
116 116
 		/**
@@ -118,33 +118,33 @@  discard block
 block discarded – undo
118 118
 		 */
119 119
 		public function init() {
120 120
 			// Don't hook anything else in the plugin if we're in an incompatible environment
121
-			if ( self::get_environment_warning() ) {
121
+			if (self::get_environment_warning()) {
122 122
 				return;
123 123
 			}
124 124
 
125
-			include_once( dirname( __FILE__ ) . '/includes/class-wc-stripe-api.php' );
126
-			include_once( dirname( __FILE__ ) . '/includes/class-wc-stripe-customer.php' );
125
+			include_once(dirname(__FILE__) . '/includes/class-wc-stripe-api.php');
126
+			include_once(dirname(__FILE__) . '/includes/class-wc-stripe-customer.php');
127 127
 
128 128
 			// Init the gateway itself
129 129
 			$this->init_gateways();
130 130
 
131
-			add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), array( $this, 'plugin_action_links' ) );
132
-			add_action( 'woocommerce_order_status_on-hold_to_processing', array( $this, 'capture_payment' ) );
133
-			add_action( 'woocommerce_order_status_on-hold_to_completed', array( $this, 'capture_payment' ) );
134
-			add_action( 'woocommerce_order_status_on-hold_to_cancelled', array( $this, 'cancel_payment' ) );
135
-			add_action( 'woocommerce_order_status_on-hold_to_refunded', array( $this, 'cancel_payment' ) );
136
-			add_filter( 'woocommerce_get_customer_payment_tokens', array( $this, 'woocommerce_get_customer_payment_tokens' ), 10, 3 );
137
-			add_action( 'woocommerce_payment_token_deleted', array( $this, 'woocommerce_payment_token_deleted' ), 10, 2 );
138
-			add_action( 'woocommerce_payment_token_set_default', array( $this, 'woocommerce_payment_token_set_default' ) );
131
+			add_filter('plugin_action_links_' . plugin_basename(__FILE__), array($this, 'plugin_action_links'));
132
+			add_action('woocommerce_order_status_on-hold_to_processing', array($this, 'capture_payment'));
133
+			add_action('woocommerce_order_status_on-hold_to_completed', array($this, 'capture_payment'));
134
+			add_action('woocommerce_order_status_on-hold_to_cancelled', array($this, 'cancel_payment'));
135
+			add_action('woocommerce_order_status_on-hold_to_refunded', array($this, 'cancel_payment'));
136
+			add_filter('woocommerce_get_customer_payment_tokens', array($this, 'woocommerce_get_customer_payment_tokens'), 10, 3);
137
+			add_action('woocommerce_payment_token_deleted', array($this, 'woocommerce_payment_token_deleted'), 10, 2);
138
+			add_action('woocommerce_payment_token_set_default', array($this, 'woocommerce_payment_token_set_default'));
139 139
 
140
-			include_once( dirname( __FILE__ ) . '/includes/class-wc-stripe-payment-request.php' );
140
+			include_once(dirname(__FILE__) . '/includes/class-wc-stripe-payment-request.php');
141 141
 		}
142 142
 
143 143
 		/**
144 144
 		 * Allow this class and other classes to add slug keyed notices (to avoid duplication)
145 145
 		 */
146
-		public function add_admin_notice( $slug, $class, $message ) {
147
-			$this->notices[ $slug ] = array(
146
+		public function add_admin_notice($slug, $class, $message) {
147
+			$this->notices[$slug] = array(
148 148
 				'class'   => $class,
149 149
 				'message' => $message,
150 150
 			);
@@ -157,21 +157,21 @@  discard block
 block discarded – undo
157 157
 		public function check_environment() {
158 158
 			$environment_warning = self::get_environment_warning();
159 159
 
160
-			if ( $environment_warning && is_plugin_active( plugin_basename( __FILE__ ) ) ) {
161
-				$this->add_admin_notice( 'bad_environment', 'error', $environment_warning );
160
+			if ($environment_warning && is_plugin_active(plugin_basename(__FILE__))) {
161
+				$this->add_admin_notice('bad_environment', 'error', $environment_warning);
162 162
 			}
163 163
 
164 164
 			// Check if secret key present. Otherwise prompt, via notice, to go to
165 165
 			// setting.
166
-			if ( ! class_exists( 'WC_Stripe_API' ) ) {
167
-				include_once( dirname( __FILE__ ) . '/includes/class-wc-stripe-api.php' );
166
+			if ( ! class_exists('WC_Stripe_API')) {
167
+				include_once(dirname(__FILE__) . '/includes/class-wc-stripe-api.php');
168 168
 			}
169 169
 
170 170
 			$secret = WC_Stripe_API::get_secret_key();
171 171
 
172
-			if ( empty( $secret ) && ! ( isset( $_GET['page'], $_GET['section'] ) && 'wc-settings' === $_GET['page'] && 'stripe' === $_GET['section'] ) ) {
172
+			if (empty($secret) && ! (isset($_GET['page'], $_GET['section']) && 'wc-settings' === $_GET['page'] && 'stripe' === $_GET['section'])) {
173 173
 				$setting_link = $this->get_setting_link();
174
-				$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 ) );
174
+				$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));
175 175
 			}
176 176
 		}
177 177
 
@@ -180,24 +180,24 @@  discard block
 block discarded – undo
180 180
 		 * found or false if the environment has no problems.
181 181
 		 */
182 182
 		static function get_environment_warning() {
183
-			if ( version_compare( phpversion(), WC_STRIPE_MIN_PHP_VER, '<' ) ) {
184
-				$message = __( 'WooCommerce Stripe - The minimum PHP version required for this plugin is %1$s. You are running %2$s.', 'woocommerce-gateway-stripe' );
183
+			if (version_compare(phpversion(), WC_STRIPE_MIN_PHP_VER, '<')) {
184
+				$message = __('WooCommerce Stripe - The minimum PHP version required for this plugin is %1$s. You are running %2$s.', 'woocommerce-gateway-stripe');
185 185
 
186
-				return sprintf( $message, WC_STRIPE_MIN_PHP_VER, phpversion() );
186
+				return sprintf($message, WC_STRIPE_MIN_PHP_VER, phpversion());
187 187
 			}
188 188
 
189
-			if ( ! defined( 'WC_VERSION' ) ) {
190
-				return __( 'WooCommerce Stripe requires WooCommerce to be activated to work.', 'woocommerce-gateway-stripe' );
189
+			if ( ! defined('WC_VERSION')) {
190
+				return __('WooCommerce Stripe requires WooCommerce to be activated to work.', 'woocommerce-gateway-stripe');
191 191
 			}
192 192
 
193
-			if ( version_compare( WC_VERSION, WC_STRIPE_MIN_WC_VER, '<' ) ) {
194
-				$message = __( 'WooCommerce Stripe - The minimum WooCommerce version required for this plugin is %1$s. You are running %2$s.', 'woocommerce-gateway-stripe' );
193
+			if (version_compare(WC_VERSION, WC_STRIPE_MIN_WC_VER, '<')) {
194
+				$message = __('WooCommerce Stripe - The minimum WooCommerce version required for this plugin is %1$s. You are running %2$s.', 'woocommerce-gateway-stripe');
195 195
 
196
-				return sprintf( $message, WC_STRIPE_MIN_WC_VER, WC_VERSION );
196
+				return sprintf($message, WC_STRIPE_MIN_WC_VER, WC_VERSION);
197 197
 			}
198 198
 
199
-			if ( ! function_exists( 'curl_init' ) ) {
200
-				return __( 'WooCommerce Stripe - cURL is not installed.', 'woocommerce-gateway-stripe' );
199
+			if ( ! function_exists('curl_init')) {
200
+				return __('WooCommerce Stripe - cURL is not installed.', 'woocommerce-gateway-stripe');
201 201
 			}
202 202
 
203 203
 			return false;
@@ -208,15 +208,15 @@  discard block
 block discarded – undo
208 208
 		 *
209 209
 		 * @since 1.0.0
210 210
 		 */
211
-		public function plugin_action_links( $links ) {
211
+		public function plugin_action_links($links) {
212 212
 			$setting_link = $this->get_setting_link();
213 213
 
214 214
 			$plugin_links = array(
215
-				'<a href="' . $setting_link . '">' . __( 'Settings', 'woocommerce-gateway-stripe' ) . '</a>',
216
-				'<a href="https://docs.woothemes.com/document/stripe/">' . __( 'Docs', 'woocommerce-gateway-stripe' ) . '</a>',
217
-				'<a href="http://support.woothemes.com/">' . __( 'Support', 'woocommerce-gateway-stripe' ) . '</a>',
215
+				'<a href="' . $setting_link . '">' . __('Settings', 'woocommerce-gateway-stripe') . '</a>',
216
+				'<a href="https://docs.woothemes.com/document/stripe/">' . __('Docs', 'woocommerce-gateway-stripe') . '</a>',
217
+				'<a href="http://support.woothemes.com/">' . __('Support', 'woocommerce-gateway-stripe') . '</a>',
218 218
 			);
219
-			return array_merge( $plugin_links, $links );
219
+			return array_merge($plugin_links, $links);
220 220
 		}
221 221
 
222 222
 		/**
@@ -227,20 +227,20 @@  discard block
 block discarded – undo
227 227
 		 * @return string Setting link
228 228
 		 */
229 229
 		public function get_setting_link() {
230
-			$use_id_as_section = function_exists( 'WC' ) ? version_compare( WC()->version, '2.6', '>=' ) : false;
230
+			$use_id_as_section = function_exists('WC') ? version_compare(WC()->version, '2.6', '>=') : false;
231 231
 
232
-			$section_slug = $use_id_as_section ? 'stripe' : strtolower( 'WC_Gateway_Stripe' );
232
+			$section_slug = $use_id_as_section ? 'stripe' : strtolower('WC_Gateway_Stripe');
233 233
 
234
-			return admin_url( 'admin.php?page=wc-settings&tab=checkout&section=' . $section_slug );
234
+			return admin_url('admin.php?page=wc-settings&tab=checkout&section=' . $section_slug);
235 235
 		}
236 236
 
237 237
 		/**
238 238
 		 * Display any notices we've collected thus far (e.g. for connection, disconnection)
239 239
 		 */
240 240
 		public function admin_notices() {
241
-			foreach ( (array) $this->notices as $notice_key => $notice ) {
242
-				echo "<div class='" . esc_attr( $notice['class'] ) . "'><p>";
243
-				echo wp_kses( $notice['message'], array( 'a' => array( 'href' => array() ) ) );
241
+			foreach ((array) $this->notices as $notice_key => $notice) {
242
+				echo "<div class='" . esc_attr($notice['class']) . "'><p>";
243
+				echo wp_kses($notice['message'], array('a' => array('href' => array())));
244 244
 				echo '</p></div>';
245 245
 			}
246 246
 		}
@@ -251,31 +251,31 @@  discard block
 block discarded – undo
251 251
 		 * @since 1.0.0
252 252
 		 */
253 253
 		public function init_gateways() {
254
-			if ( class_exists( 'WC_Subscriptions_Order' ) && function_exists( 'wcs_create_renewal_order' ) ) {
254
+			if (class_exists('WC_Subscriptions_Order') && function_exists('wcs_create_renewal_order')) {
255 255
 				$this->subscription_support_enabled = true;
256 256
 			}
257 257
 
258
-			if ( class_exists( 'WC_Pre_Orders_Order' ) ) {
258
+			if (class_exists('WC_Pre_Orders_Order')) {
259 259
 				$this->pre_order_enabled = true;
260 260
 			}
261 261
 
262
-			if ( ! class_exists( 'WC_Payment_Gateway' ) ) {
262
+			if ( ! class_exists('WC_Payment_Gateway')) {
263 263
 				return;
264 264
 			}
265 265
 
266
-			if ( class_exists( 'WC_Payment_Gateway_CC' ) ) {
267
-				include_once( dirname( __FILE__ ) . '/includes/class-wc-gateway-stripe.php' );
268
-				include_once( dirname( __FILE__ ) . '/includes/class-wc-stripe-apple-pay.php' );
266
+			if (class_exists('WC_Payment_Gateway_CC')) {
267
+				include_once(dirname(__FILE__) . '/includes/class-wc-gateway-stripe.php');
268
+				include_once(dirname(__FILE__) . '/includes/class-wc-stripe-apple-pay.php');
269 269
 			} else {
270
-				include_once( dirname( __FILE__ ) . '/includes/legacy/class-wc-gateway-stripe.php' );
271
-				include_once( dirname( __FILE__ ) . '/includes/legacy/class-wc-gateway-stripe-saved-cards.php' );
270
+				include_once(dirname(__FILE__) . '/includes/legacy/class-wc-gateway-stripe.php');
271
+				include_once(dirname(__FILE__) . '/includes/legacy/class-wc-gateway-stripe-saved-cards.php');
272 272
 			}
273 273
 
274
-			load_plugin_textdomain( 'woocommerce-gateway-stripe', false, plugin_basename( dirname( __FILE__ ) ) . '/languages' );
275
-			add_filter( 'woocommerce_payment_gateways', array( $this, 'add_gateways' ) );
274
+			load_plugin_textdomain('woocommerce-gateway-stripe', false, plugin_basename(dirname(__FILE__)) . '/languages');
275
+			add_filter('woocommerce_payment_gateways', array($this, 'add_gateways'));
276 276
 
277
-			if ( is_admin() ) {
278
-				add_action( 'wp_ajax_wc_stripe_apple_pay_domain', 'WC_Stripe_Apple_Pay::process_apple_pay_domain' );
277
+			if (is_admin()) {
278
+				add_action('wp_ajax_wc_stripe_apple_pay_domain', 'WC_Stripe_Apple_Pay::process_apple_pay_domain');
279 279
 			}
280 280
 			
281 281
 			$load_addons = (
@@ -284,8 +284,8 @@  discard block
 block discarded – undo
284 284
 				$this->pre_order_enabled
285 285
 			);
286 286
 
287
-			if ( $load_addons ) {
288
-				require_once( dirname( __FILE__ ) . '/includes/class-wc-gateway-stripe-addons.php' );
287
+			if ($load_addons) {
288
+				require_once(dirname(__FILE__) . '/includes/class-wc-gateway-stripe-addons.php');
289 289
 			}
290 290
 		}
291 291
 
@@ -294,8 +294,8 @@  discard block
 block discarded – undo
294 294
 		 *
295 295
 		 * @since 1.0.0
296 296
 		 */
297
-		public function add_gateways( $methods ) {
298
-			if ( $this->subscription_support_enabled || $this->pre_order_enabled ) {
297
+		public function add_gateways($methods) {
298
+			if ($this->subscription_support_enabled || $this->pre_order_enabled) {
299 299
 				$methods[] = 'WC_Gateway_Stripe_Addons';
300 300
 			} else {
301 301
 				$methods[] = 'WC_Gateway_Stripe';
@@ -308,35 +308,35 @@  discard block
 block discarded – undo
308 308
 		 *
309 309
 		 * @param  int $order_id
310 310
 		 */
311
-		public function capture_payment( $order_id ) {
312
-			$order = wc_get_order( $order_id );
311
+		public function capture_payment($order_id) {
312
+			$order = wc_get_order($order_id);
313 313
 
314
-			if ( 'stripe' === $order->payment_method ) {
315
-				$charge   = get_post_meta( $order_id, '_stripe_charge_id', true );
316
-				$captured = get_post_meta( $order_id, '_stripe_charge_captured', true );
314
+			if ('stripe' === $order->payment_method) {
315
+				$charge   = get_post_meta($order_id, '_stripe_charge_id', true);
316
+				$captured = get_post_meta($order_id, '_stripe_charge_captured', true);
317 317
 
318
-				if ( $charge && 'no' === $captured ) {
319
-					$result = WC_Stripe_API::request( array(
318
+				if ($charge && 'no' === $captured) {
319
+					$result = WC_Stripe_API::request(array(
320 320
 						'amount'   => $order->get_total() * 100,
321 321
 						'expand[]' => 'balance_transaction',
322
-					), 'charges/' . $charge . '/capture' );
322
+					), 'charges/' . $charge . '/capture');
323 323
 
324
-					if ( is_wp_error( $result ) ) {
325
-						$order->add_order_note( __( 'Unable to capture charge!', 'woocommerce-gateway-stripe' ) . ' ' . $result->get_error_message() );
324
+					if (is_wp_error($result)) {
325
+						$order->add_order_note(__('Unable to capture charge!', 'woocommerce-gateway-stripe') . ' ' . $result->get_error_message());
326 326
 					} else {
327
-						$order->add_order_note( sprintf( __( 'Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe' ), $result->id ) );
328
-						update_post_meta( $order->id, '_stripe_charge_captured', 'yes' );
327
+						$order->add_order_note(sprintf(__('Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe'), $result->id));
328
+						update_post_meta($order->id, '_stripe_charge_captured', 'yes');
329 329
 
330 330
 						// Store other data such as fees
331
-						update_post_meta( $order->id, 'Stripe Payment ID', $result->id );
331
+						update_post_meta($order->id, 'Stripe Payment ID', $result->id);
332 332
 
333
-						if ( isset( $result->balance_transaction ) && isset( $result->balance_transaction->fee ) ) {
333
+						if (isset($result->balance_transaction) && isset($result->balance_transaction->fee)) {
334 334
 							// Fees and Net needs to both come from Stripe to be accurate as the returned
335 335
 							// values are in the local currency of the Stripe account, not from WC.
336
-							$fee = ! empty( $result->balance_transaction->fee ) ? number_format( $result->balance_transaction->fee / 100, 2, '.', '' ) : 0;
337
-							$net = ! empty( $result->balance_transaction->net ) ? number_format( $result->balance_transaction->net / 100, 2, '.', '' ) : 0;
338
-							update_post_meta( $order->id, 'Stripe Fee', $fee );
339
-							update_post_meta( $order->id, 'Net Revenue From Stripe', $net );
336
+							$fee = ! empty($result->balance_transaction->fee) ? number_format($result->balance_transaction->fee / 100, 2, '.', '') : 0;
337
+							$net = ! empty($result->balance_transaction->net) ? number_format($result->balance_transaction->net / 100, 2, '.', '') : 0;
338
+							update_post_meta($order->id, 'Stripe Fee', $fee);
339
+							update_post_meta($order->id, 'Net Revenue From Stripe', $net);
340 340
 						}
341 341
 					}
342 342
 				}
@@ -348,23 +348,23 @@  discard block
 block discarded – undo
348 348
 		 *
349 349
 		 * @param  int $order_id
350 350
 		 */
351
-		public function cancel_payment( $order_id ) {
352
-			$order = wc_get_order( $order_id );
351
+		public function cancel_payment($order_id) {
352
+			$order = wc_get_order($order_id);
353 353
 
354
-			if ( 'stripe' === $order->payment_method ) {
355
-				$charge   = get_post_meta( $order_id, '_stripe_charge_id', true );
354
+			if ('stripe' === $order->payment_method) {
355
+				$charge = get_post_meta($order_id, '_stripe_charge_id', true);
356 356
 
357
-				if ( $charge ) {
358
-					$result = WC_Stripe_API::request( array(
357
+				if ($charge) {
358
+					$result = WC_Stripe_API::request(array(
359 359
 						'amount' => $order->get_total() * 100,
360
-					), 'charges/' . $charge . '/refund' );
360
+					), 'charges/' . $charge . '/refund');
361 361
 
362
-					if ( is_wp_error( $result ) ) {
363
-						$order->add_order_note( __( 'Unable to refund charge!', 'woocommerce-gateway-stripe' ) . ' ' . $result->get_error_message() );
362
+					if (is_wp_error($result)) {
363
+						$order->add_order_note(__('Unable to refund charge!', 'woocommerce-gateway-stripe') . ' ' . $result->get_error_message());
364 364
 					} else {
365
-						$order->add_order_note( sprintf( __( 'Stripe charge refunded (Charge ID: %s)', 'woocommerce-gateway-stripe' ), $result->id ) );
366
-						delete_post_meta( $order->id, '_stripe_charge_captured' );
367
-						delete_post_meta( $order->id, '_stripe_charge_id' );
365
+						$order->add_order_note(sprintf(__('Stripe charge refunded (Charge ID: %s)', 'woocommerce-gateway-stripe'), $result->id));
366
+						delete_post_meta($order->id, '_stripe_charge_captured');
367
+						delete_post_meta($order->id, '_stripe_charge_id');
368 368
 					}
369 369
 				}
370 370
 			}
@@ -375,28 +375,28 @@  discard block
 block discarded – undo
375 375
 		 * @param array $tokens
376 376
 		 * @return array
377 377
 		 */
378
-		public function woocommerce_get_customer_payment_tokens( $tokens, $customer_id, $gateway_id ) {
379
-			if ( is_user_logged_in() && 'stripe' === $gateway_id && class_exists( 'WC_Payment_Token_CC' ) ) {
380
-				$stripe_customer = new WC_Stripe_Customer( $customer_id );
378
+		public function woocommerce_get_customer_payment_tokens($tokens, $customer_id, $gateway_id) {
379
+			if (is_user_logged_in() && 'stripe' === $gateway_id && class_exists('WC_Payment_Token_CC')) {
380
+				$stripe_customer = new WC_Stripe_Customer($customer_id);
381 381
 				$stripe_cards    = $stripe_customer->get_cards();
382 382
 				$stored_tokens   = array();
383 383
 
384
-				foreach ( $tokens as $token ) {
384
+				foreach ($tokens as $token) {
385 385
 					$stored_tokens[] = $token->get_token();
386 386
 				}
387 387
 
388
-				foreach ( $stripe_cards as $card ) {
389
-					if ( ! in_array( $card->id, $stored_tokens ) ) {
388
+				foreach ($stripe_cards as $card) {
389
+					if ( ! in_array($card->id, $stored_tokens)) {
390 390
 						$token = new WC_Payment_Token_CC();
391
-						$token->set_token( $card->id );
392
-						$token->set_gateway_id( 'stripe' );
393
-						$token->set_card_type( strtolower( $card->brand ) );
394
-						$token->set_last4( $card->last4 );
395
-						$token->set_expiry_month( $card->exp_month );
396
-						$token->set_expiry_year( $card->exp_year );
397
-						$token->set_user_id( $customer_id );
391
+						$token->set_token($card->id);
392
+						$token->set_gateway_id('stripe');
393
+						$token->set_card_type(strtolower($card->brand));
394
+						$token->set_last4($card->last4);
395
+						$token->set_expiry_month($card->exp_month);
396
+						$token->set_expiry_year($card->exp_year);
397
+						$token->set_user_id($customer_id);
398 398
 						$token->save();
399
-						$tokens[ $token->get_id() ] = $token;
399
+						$tokens[$token->get_id()] = $token;
400 400
 					}
401 401
 				}
402 402
 			}
@@ -406,21 +406,21 @@  discard block
 block discarded – undo
406 406
 		/**
407 407
 		 * Delete token from Stripe
408 408
 		 */
409
-		public function woocommerce_payment_token_deleted( $token_id, $token ) {
410
-			if ( 'stripe' === $token->get_gateway_id() ) {
411
-				$stripe_customer = new WC_Stripe_Customer( get_current_user_id() );
412
-				$stripe_customer->delete_card( $token->get_token() );
409
+		public function woocommerce_payment_token_deleted($token_id, $token) {
410
+			if ('stripe' === $token->get_gateway_id()) {
411
+				$stripe_customer = new WC_Stripe_Customer(get_current_user_id());
412
+				$stripe_customer->delete_card($token->get_token());
413 413
 			}
414 414
 		}
415 415
 
416 416
 		/**
417 417
 		 * Set as default in Stripe
418 418
 		 */
419
-		public function woocommerce_payment_token_set_default( $token_id ) {
420
-			$token = WC_Payment_Tokens::get( $token_id );
421
-			if ( 'stripe' === $token->get_gateway_id() ) {
422
-				$stripe_customer = new WC_Stripe_Customer( get_current_user_id() );
423
-				$stripe_customer->set_default_card( $token->get_token() );
419
+		public function woocommerce_payment_token_set_default($token_id) {
420
+			$token = WC_Payment_Tokens::get($token_id);
421
+			if ('stripe' === $token->get_gateway_id()) {
422
+				$stripe_customer = new WC_Stripe_Customer(get_current_user_id());
423
+				$stripe_customer->set_default_card($token->get_token());
424 424
 			}
425 425
 		}
426 426
 
@@ -429,7 +429,7 @@  discard block
 block discarded – undo
429 429
 		 */
430 430
 		public static function get_minimum_amount() {
431 431
 			// Check order amount
432
-			switch ( get_woocommerce_currency() ) {
432
+			switch (get_woocommerce_currency()) {
433 433
 				case 'USD':
434 434
 				case 'CAD':
435 435
 				case 'EUR':
@@ -473,12 +473,12 @@  discard block
 block discarded – undo
473 473
 		 * And fits on your back?
474 474
 		 * It's log, log, log
475 475
 		 */
476
-		public static function log( $message ) {
477
-			if ( empty( self::$log ) ) {
476
+		public static function log($message) {
477
+			if (empty(self::$log)) {
478 478
 				self::$log = new WC_Logger();
479 479
 			}
480 480
 
481
-			self::$log->add( 'woocommerce-gateway-stripe', $message );
481
+			self::$log->add('woocommerce-gateway-stripe', $message);
482 482
 		}
483 483
 	}
484 484
 
Please login to merge, or discard this patch.
includes/class-wc-stripe-apple-pay.php 1 patch
Spacing   +200 added lines, -200 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
 
@@ -47,9 +47,9 @@  discard block
 block discarded – undo
47 47
 	public function __construct() {
48 48
 		self::$_this = $this;
49 49
 
50
-		$this->_gateway_settings = get_option( 'woocommerce_stripe_settings', '' );
50
+		$this->_gateway_settings = get_option('woocommerce_stripe_settings', '');
51 51
 
52
-		$this->statement_descriptor = ! empty( $this->_gateway_settings['statement_descriptor'] ) ? $this->_gateway_settings['statement_descriptor'] : wp_specialchars_decode( get_bloginfo( 'name' ), ENT_QUOTES );
52
+		$this->statement_descriptor = ! empty($this->_gateway_settings['statement_descriptor']) ? $this->_gateway_settings['statement_descriptor'] : wp_specialchars_decode(get_bloginfo('name'), ENT_QUOTES);
53 53
 
54 54
 		$this->init();
55 55
 	}
@@ -66,14 +66,14 @@  discard block
 block discarded – undo
66 66
 	 * @version 3.1.0
67 67
 	 */
68 68
 	public function init() {
69
-		add_action( 'wp_enqueue_scripts', array( $this, 'payment_scripts' ) );
70
-		add_action( 'woocommerce_proceed_to_checkout', array( $this, 'display_apple_pay_button' ), 20 );
71
-		add_action( 'woocommerce_checkout_before_customer_details', array( $this, 'display_apple_pay_button' ) );
72
-		add_action( 'wc_ajax_wc_stripe_apple_pay', array( $this, 'process_apple_pay' ) );
73
-		add_action( 'wc_ajax_wc_stripe_generate_apple_pay_cart', array( $this, 'generate_apple_pay_cart' ) );
74
-		add_action( 'wc_ajax_wc_stripe_apple_pay_get_shipping_methods', array( $this, 'get_shipping_methods' ) );
75
-		add_action( 'wc_ajax_wc_stripe_apple_pay_update_shipping_method', array( $this, 'update_shipping_method' ) );
76
-		add_filter( 'woocommerce_gateway_title', array( $this, 'filter_gateway_title' ), 10, 2 );
69
+		add_action('wp_enqueue_scripts', array($this, 'payment_scripts'));
70
+		add_action('woocommerce_proceed_to_checkout', array($this, 'display_apple_pay_button'), 20);
71
+		add_action('woocommerce_checkout_before_customer_details', array($this, 'display_apple_pay_button'));
72
+		add_action('wc_ajax_wc_stripe_apple_pay', array($this, 'process_apple_pay'));
73
+		add_action('wc_ajax_wc_stripe_generate_apple_pay_cart', array($this, 'generate_apple_pay_cart'));
74
+		add_action('wc_ajax_wc_stripe_apple_pay_get_shipping_methods', array($this, 'get_shipping_methods'));
75
+		add_action('wc_ajax_wc_stripe_apple_pay_update_shipping_method', array($this, 'update_shipping_method'));
76
+		add_filter('woocommerce_gateway_title', array($this, 'filter_gateway_title'), 10, 2);
77 77
 	}
78 78
 
79 79
 	/**
@@ -84,47 +84,47 @@  discard block
 block discarded – undo
84 84
 	 * @version 3.1.0
85 85
 	 */
86 86
 	public static function process_apple_pay_domain() {
87
-		if ( ! wp_verify_nonce( $_POST['nonce'], '_wc_stripe_apple_pay_domain_nonce' ) ) {
88
-			wp_die( __( 'Cheatin&#8217; huh?', 'woocommerce-gateway-stripe' ) );
87
+		if ( ! wp_verify_nonce($_POST['nonce'], '_wc_stripe_apple_pay_domain_nonce')) {
88
+			wp_die(__('Cheatin&#8217; huh?', 'woocommerce-gateway-stripe'));
89 89
 		}
90 90
 
91
-		$secret_key = wc_clean( $_POST['secret_key'] );
91
+		$secret_key = wc_clean($_POST['secret_key']);
92 92
 
93 93
 		try {
94
-			$path     = untrailingslashit( preg_replace( "!${_SERVER['SCRIPT_NAME']}$!", '', $_SERVER['SCRIPT_FILENAME'] ) );
94
+			$path     = untrailingslashit(preg_replace("!${_SERVER['SCRIPT_NAME']}$!", '', $_SERVER['SCRIPT_FILENAME']));
95 95
 			$dir      = '.well-known';
96 96
 			$file     = 'apple-developer-merchantid-domain-association';
97 97
 			$fullpath = $path . '/' . $dir . '/' . $file;
98
-			$gateway_settings = get_option( 'woocommerce_stripe_settings', '' );
98
+			$gateway_settings = get_option('woocommerce_stripe_settings', '');
99 99
 
100
-			if ( ! file_exists( $path . '/' . $dir ) || ! file_exists( $fullpath ) ) {
101
-				if ( ! mkdir( $path . '/' . $dir, 0755 ) ) {
102
-					throw new Exception( __( 'Unable to create domain association folder to domain root.', 'woocommerce-gateway-stripe' ) );
100
+			if ( ! file_exists($path . '/' . $dir) || ! file_exists($fullpath)) {
101
+				if ( ! mkdir($path . '/' . $dir, 0755)) {
102
+					throw new Exception(__('Unable to create domain association folder to domain root.', 'woocommerce-gateway-stripe'));
103 103
 				}
104 104
 
105
-				if ( ! file_exists( $path . '/' . $dir . '/' . 'apple-developer-merchantid-domain-association' ) ) {
106
-					if ( ! copy( WC_STRIPE_PLUGIN_PATH . '/' . $file, $fullpath ) ) {
107
-						throw new Exception( __( 'Unable to copy domain association file to domain root.', 'woocommerce-gateway-stripe' ) );
105
+				if ( ! file_exists($path . '/' . $dir . '/' . 'apple-developer-merchantid-domain-association')) {
106
+					if ( ! copy(WC_STRIPE_PLUGIN_PATH . '/' . $file, $fullpath)) {
107
+						throw new Exception(__('Unable to copy domain association file to domain root.', 'woocommerce-gateway-stripe'));
108 108
 					}
109 109
 				}
110 110
 			}
111 111
 
112 112
 			// At this point then the domain association folder and file should be available.
113 113
 			// Proceed to verify/and or verify again.
114
-			WC_Stripe_Apple_Pay::_register_apple_pay_domain( $secret_key );
114
+			WC_Stripe_Apple_Pay::_register_apple_pay_domain($secret_key);
115 115
 
116 116
 			// No errors to this point, verification success!
117 117
 			$gateway_settings['apple_pay_domain_set'] = 'yes';
118 118
 
119
-			update_option( 'woocommerce_stripe_settings', $gateway_settings );
119
+			update_option('woocommerce_stripe_settings', $gateway_settings);
120 120
 
121
-			wp_send_json( array( 'success' => true, 'message' => __( 'Your domain has been verified with Apple Pay!', 'woocommerce-gateway-stripe' ) ) );
122
-		} catch ( Exception $e ) {
121
+			wp_send_json(array('success' => true, 'message' => __('Your domain has been verified with Apple Pay!', 'woocommerce-gateway-stripe')));
122
+		} catch (Exception $e) {
123 123
 			$gateway_settings['apple_pay_domain_set'] = 'no';
124 124
 
125
-			update_option( 'woocommerce_stripe_settings', $gateway_settings );
125
+			update_option('woocommerce_stripe_settings', $gateway_settings);
126 126
 
127
-			wp_send_json( array( 'success' => false, 'message' => $e->getMessage() ) );
127
+			wp_send_json(array('success' => false, 'message' => $e->getMessage()));
128 128
 		}
129 129
 	}
130 130
 
@@ -135,9 +135,9 @@  discard block
 block discarded – undo
135 135
 	 * @version 3.1.0
136 136
 	 * @param string $secret_key
137 137
 	 */
138
-	private static function _register_apple_pay_domain( $secret_key = '' ) {
139
-		if ( empty( $secret_key ) ) {
140
-			throw new Exception( __( 'Unable to verify domain - missing secret key.', 'woocommerce-gateway-stripe' ) );
138
+	private static function _register_apple_pay_domain($secret_key = '') {
139
+		if (empty($secret_key)) {
140
+			throw new Exception(__('Unable to verify domain - missing secret key.', 'woocommerce-gateway-stripe'));
141 141
 		}
142 142
 
143 143
 		$endpoint = 'https://api.stripe.com/v1/apple_pay/domains';
@@ -151,13 +151,13 @@  discard block
 block discarded – undo
151 151
 			'Authorization' => 'Bearer ' . $secret_key,
152 152
 		);
153 153
 
154
-		$response = wp_remote_post( $endpoint, array(
154
+		$response = wp_remote_post($endpoint, array(
155 155
 			'headers' => $headers,
156
-			'body'    => http_build_query( $data ),
157
-		) );
156
+			'body'    => http_build_query($data),
157
+		));
158 158
 
159
-		if ( 200 !== $response['response']['code'] ) {
160
-			throw new Exception( sprintf( __( 'Unable to verify domain - %s', 'woocommerce-gateway-stripe' ), $response['response']['message'] ) );
159
+		if (200 !== $response['response']['code']) {
160
+			throw new Exception(sprintf(__('Unable to verify domain - %s', 'woocommerce-gateway-stripe'), $response['response']['message']));
161 161
 		}
162 162
 	}
163 163
 
@@ -165,16 +165,16 @@  discard block
 block discarded – undo
165 165
 	 * Filters the gateway title to reflect Apple Pay.
166 166
 	 *
167 167
 	 */
168
-	public function filter_gateway_title( $title, $id ) {
168
+	public function filter_gateway_title($title, $id) {
169 169
 		global $post;
170 170
 
171
-		if ( ! is_object( $post ) ) {
171
+		if ( ! is_object($post)) {
172 172
 			return $title;
173 173
 		}
174 174
 
175
-		$method_title = get_post_meta( $post->ID, '_payment_method_title', true );
175
+		$method_title = get_post_meta($post->ID, '_payment_method_title', true);
176 176
 
177
-		if ( 'stripe' === $id && ! empty( $method_title ) ) {
177
+		if ('stripe' === $id && ! empty($method_title)) {
178 178
 			return $method_title;
179 179
 		}
180 180
 
@@ -188,38 +188,38 @@  discard block
 block discarded – undo
188 188
 	 * @version 3.1.0
189 189
 	 */
190 190
 	public function payment_scripts() {
191
-		if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) ) {
191
+		if ( ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order'])) {
192 192
 			return;
193 193
 		}
194 194
 
195
-		if ( ! $this->is_supported_product_type() ) {
195
+		if ( ! $this->is_supported_product_type()) {
196 196
 			return;
197 197
 		}
198 198
 
199
-		$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
199
+		$suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';
200 200
 
201
-		wp_enqueue_style( 'stripe_apple_pay', plugins_url( 'assets/css/stripe-apple-pay.css', WC_STRIPE_MAIN_FILE ), array(), WC_STRIPE_VERSION );
201
+		wp_enqueue_style('stripe_apple_pay', plugins_url('assets/css/stripe-apple-pay.css', WC_STRIPE_MAIN_FILE), array(), WC_STRIPE_VERSION);
202 202
 
203
-		wp_enqueue_script( 'stripe', 'https://js.stripe.com/v2/', '', '1.0', true );
204
-		wp_enqueue_script( 'woocommerce_stripe_apple_pay', plugins_url( 'assets/js/stripe-apple-pay' . $suffix . '.js', WC_STRIPE_MAIN_FILE ), array( 'stripe' ), WC_STRIPE_VERSION, true );
203
+		wp_enqueue_script('stripe', 'https://js.stripe.com/v2/', '', '1.0', true);
204
+		wp_enqueue_script('woocommerce_stripe_apple_pay', plugins_url('assets/js/stripe-apple-pay' . $suffix . '.js', WC_STRIPE_MAIN_FILE), array('stripe'), WC_STRIPE_VERSION, true);
205 205
 
206 206
 		$publishable_key = 'yes' === $this->_gateway_settings['testmode'] ? $this->_gateway_settings['test_publishable_key'] : $this->_gateway_settings['publishable_key'];
207 207
 
208 208
 		$stripe_params = array(
209 209
 			'key'                                           => $publishable_key,
210 210
 			'currency_code'                                 => get_woocommerce_currency(),
211
-			'country_code'                                  => substr( get_option( 'woocommerce_default_country' ), 0, 2 ),
211
+			'country_code'                                  => substr(get_option('woocommerce_default_country'), 0, 2),
212 212
 			'label'                                         => $this->statement_descriptor,
213
-			'ajaxurl'                                       => WC_AJAX::get_endpoint( '%%endpoint%%' ),
214
-			'stripe_apple_pay_nonce'                        => wp_create_nonce( '_wc_stripe_apple_pay_nonce' ),
215
-			'stripe_apple_pay_cart_nonce'                   => wp_create_nonce( '_wc_stripe_apple_pay_cart_nonce' ),
216
-			'stripe_apple_pay_get_shipping_methods_nonce'   => wp_create_nonce( '_wc_stripe_apple_pay_get_shipping_methods_nonce' ),
217
-			'stripe_apple_pay_update_shipping_method_nonce' => wp_create_nonce( '_wc_stripe_apple_pay_update_shipping_method_nonce' ),
213
+			'ajaxurl'                                       => WC_AJAX::get_endpoint('%%endpoint%%'),
214
+			'stripe_apple_pay_nonce'                        => wp_create_nonce('_wc_stripe_apple_pay_nonce'),
215
+			'stripe_apple_pay_cart_nonce'                   => wp_create_nonce('_wc_stripe_apple_pay_cart_nonce'),
216
+			'stripe_apple_pay_get_shipping_methods_nonce'   => wp_create_nonce('_wc_stripe_apple_pay_get_shipping_methods_nonce'),
217
+			'stripe_apple_pay_update_shipping_method_nonce' => wp_create_nonce('_wc_stripe_apple_pay_update_shipping_method_nonce'),
218 218
 			'needs_shipping'                                => WC()->cart->needs_shipping() ? 'yes' : 'no',
219 219
 			'is_cart_page'                                  => is_cart() ? 'yes' : 'no',
220 220
 		);
221 221
 
222
-		wp_localize_script( 'woocommerce_stripe_apple_pay', 'wc_stripe_apple_pay_params', apply_filters( 'wc_stripe_apple_pay_params', $stripe_params ) );
222
+		wp_localize_script('woocommerce_stripe_apple_pay', 'wc_stripe_apple_pay_params', apply_filters('wc_stripe_apple_pay_params', $stripe_params));
223 223
 	}
224 224
 
225 225
 	/**
@@ -227,8 +227,8 @@  discard block
 block discarded – undo
227 227
 	 *
228 228
 	 */
229 229
 	public function is_supported_product_type() {
230
-		foreach ( WC()->cart->get_cart() as $cart_item_key => $values ) {
231
-			if ( 'subscription' === $values['data']->product_type ) {
230
+		foreach (WC()->cart->get_cart() as $cart_item_key => $values) {
231
+			if ('subscription' === $values['data']->product_type) {
232 232
 				return false;
233 233
 			}
234 234
 		}
@@ -251,19 +251,19 @@  discard block
 block discarded – undo
251 251
 		 */
252 252
 		if (
253 253
 			'yes' !== $this->_gateway_settings['apple_pay']
254
-			|| ! isset( $gateways['stripe'] )
254
+			|| ! isset($gateways['stripe'])
255 255
 		) {
256 256
 			return;
257 257
 		}
258 258
 
259
-		if ( ! $this->is_supported_product_type() ) {
259
+		if ( ! $this->is_supported_product_type()) {
260 260
 			return;
261 261
 		}
262 262
 
263
-		$apple_pay_button = ! empty( $this->_gateway_settings['apple_pay_button'] ) ? $this->_gateway_settings['apple_pay_button'] : 'black';
264
-		$button_lang      = ! empty( $this->_gateway_settings['apple_pay_button_lang'] ) ? strtolower( $this->_gateway_settings['apple_pay_button_lang'] ) : 'en';
263
+		$apple_pay_button = ! empty($this->_gateway_settings['apple_pay_button']) ? $this->_gateway_settings['apple_pay_button'] : 'black';
264
+		$button_lang      = ! empty($this->_gateway_settings['apple_pay_button_lang']) ? strtolower($this->_gateway_settings['apple_pay_button_lang']) : 'en';
265 265
 		?>
266
-		<button class="apple-pay-button" lang="<?php echo esc_attr( $button_lang ); ?>" style="-webkit-appearance: -apple-pay-button; -apple-pay-button-type: buy; -apple-pay-button-style: <?php echo esc_attr( $apple_pay_button ); ?>;"></button>
266
+		<button class="apple-pay-button" lang="<?php echo esc_attr($button_lang); ?>" style="-webkit-appearance: -apple-pay-button; -apple-pay-button-type: buy; -apple-pay-button-style: <?php echo esc_attr($apple_pay_button); ?>;"></button>
267 267
 		<?php
268 268
 	}
269 269
 
@@ -274,11 +274,11 @@  discard block
 block discarded – undo
274 274
 	 * @version 3.1.0
275 275
 	 */
276 276
 	public function generate_apple_pay_cart() {
277
-		if ( ! wp_verify_nonce( $_POST['nonce'], '_wc_stripe_apple_pay_cart_nonce' ) ) {
278
-			wp_die( __( 'Cheatin&#8217; huh?', 'woocommerce-gateway-stripe' ) );
277
+		if ( ! wp_verify_nonce($_POST['nonce'], '_wc_stripe_apple_pay_cart_nonce')) {
278
+			wp_die(__('Cheatin&#8217; huh?', 'woocommerce-gateway-stripe'));
279 279
 		}
280 280
 
281
-		wp_send_json( array( 'line_items' => $this->build_line_items(), 'total' => WC()->cart->total ) );
281
+		wp_send_json(array('line_items' => $this->build_line_items(), 'total' => WC()->cart->total));
282 282
 	}
283 283
 
284 284
 	/**
@@ -288,29 +288,29 @@  discard block
 block discarded – undo
288 288
 	 * @version 3.1.0
289 289
 	 * @param array $address
290 290
 	 */
291
-	public function calculate_shipping( $address = array() ) {
292
-		$country  = strtoupper( $address['countryCode'] );
293
-		$state    = strtoupper( $address['administrativeArea'] );
291
+	public function calculate_shipping($address = array()) {
292
+		$country  = strtoupper($address['countryCode']);
293
+		$state    = strtoupper($address['administrativeArea']);
294 294
 		$postcode = $address['postalCode'];
295 295
 		$city     = $address['locality'];
296 296
 
297 297
 		WC()->shipping->reset_shipping();
298 298
 
299
-		if ( $postcode && ! WC_Validation::is_postcode( $postcode, $country ) ) {
300
-			throw new Exception( __( 'Please enter a valid postcode/ZIP.', 'woocommerce-gateway-stripe' ) );
301
-		} elseif ( $postcode ) {
302
-			$postcode = wc_format_postcode( $postcode, $country );
299
+		if ($postcode && ! WC_Validation::is_postcode($postcode, $country)) {
300
+			throw new Exception(__('Please enter a valid postcode/ZIP.', 'woocommerce-gateway-stripe'));
301
+		} elseif ($postcode) {
302
+			$postcode = wc_format_postcode($postcode, $country);
303 303
 		}
304 304
 
305
-		if ( $country ) {
306
-			WC()->customer->set_location( $country, $state, $postcode, $city );
307
-			WC()->customer->set_shipping_location( $country, $state, $postcode, $city );
305
+		if ($country) {
306
+			WC()->customer->set_location($country, $state, $postcode, $city);
307
+			WC()->customer->set_shipping_location($country, $state, $postcode, $city);
308 308
 		} else {
309 309
 			WC()->customer->set_to_base();
310 310
 			WC()->customer->set_shipping_to_base();
311 311
 		}
312 312
 
313
-		WC()->customer->calculated_shipping( true );
313
+		WC()->customer->calculated_shipping(true);
314 314
 
315 315
 		/**
316 316
 		 * Set the shipping package.
@@ -332,17 +332,17 @@  discard block
 block discarded – undo
332 332
 		$packages[0]['destination']['postcode']  = $postcode;
333 333
 		$packages[0]['destination']['city']      = $city;
334 334
 
335
-		foreach ( WC()->cart->get_cart() as $item ) {
336
-			if ( $item['data']->needs_shipping() ) {
337
-				if ( isset( $item['line_total'] ) ) {
335
+		foreach (WC()->cart->get_cart() as $item) {
336
+			if ($item['data']->needs_shipping()) {
337
+				if (isset($item['line_total'])) {
338 338
 					$packages[0]['contents_cost'] += $item['line_total'];
339 339
 				}
340 340
 			}
341 341
 		}
342 342
 
343
-		$packages = apply_filters( 'woocommerce_cart_shipping_packages', $packages );
343
+		$packages = apply_filters('woocommerce_cart_shipping_packages', $packages);
344 344
 
345
-		WC()->shipping->calculate_shipping( $packages );
345
+		WC()->shipping->calculate_shipping($packages);
346 346
 	}
347 347
 
348 348
 	/**
@@ -352,18 +352,18 @@  discard block
 block discarded – undo
352 352
 	 * @version 3.1.0
353 353
 	 */
354 354
 	public function get_shipping_methods() {
355
-		if ( ! wp_verify_nonce( $_POST['nonce'], '_wc_stripe_apple_pay_get_shipping_methods_nonce' ) ) {
356
-			wp_die( __( 'Cheatin&#8217; huh?', 'woocommerce-gateway-stripe' ) );
355
+		if ( ! wp_verify_nonce($_POST['nonce'], '_wc_stripe_apple_pay_get_shipping_methods_nonce')) {
356
+			wp_die(__('Cheatin&#8217; huh?', 'woocommerce-gateway-stripe'));
357 357
 		}
358 358
 
359
-		if ( ! defined( 'WOOCOMMERCE_CART' ) ) {
360
-			define( 'WOOCOMMERCE_CART', true );
359
+		if ( ! defined('WOOCOMMERCE_CART')) {
360
+			define('WOOCOMMERCE_CART', true);
361 361
 		}
362 362
 
363 363
 		try {
364
-			$address = array_map( 'wc_clean', $_POST['address'] );
364
+			$address = array_map('wc_clean', $_POST['address']);
365 365
 
366
-			$this->calculate_shipping( $address );
366
+			$this->calculate_shipping($address);
367 367
 
368 368
 			// Set the shipping options.
369 369
 			$currency = get_woocommerce_currency();
@@ -371,13 +371,13 @@  discard block
 block discarded – undo
371 371
 
372 372
 			$packages = WC()->shipping->get_packages();
373 373
 
374
-			if ( ! empty( $packages ) && WC()->customer->has_calculated_shipping() ) {
375
-				foreach ( $packages as $package_key => $package ) {
376
-					if ( empty( $package['rates'] ) ) {
377
-						throw new Exception( __( 'Unable to find shipping method for address.', 'woocommerce-gateway-stripe' ) );
374
+			if ( ! empty($packages) && WC()->customer->has_calculated_shipping()) {
375
+				foreach ($packages as $package_key => $package) {
376
+					if (empty($package['rates'])) {
377
+						throw new Exception(__('Unable to find shipping method for address.', 'woocommerce-gateway-stripe'));
378 378
 					}
379 379
 
380
-					foreach ( $package['rates'] as $key => $rate ) {
380
+					foreach ($package['rates'] as $key => $rate) {
381 381
 						$data[] = array(
382 382
 							'id'       => $rate->id,
383 383
 							'label'    => $rate->label,
@@ -391,16 +391,16 @@  discard block
 block discarded – undo
391 391
 				}
392 392
 
393 393
 				// Auto select the first shipping method.
394
-				WC()->session->set( 'chosen_shipping_methods', array( $data[0]['id'] ) );
394
+				WC()->session->set('chosen_shipping_methods', array($data[0]['id']));
395 395
 
396 396
 				WC()->cart->calculate_totals();
397 397
 
398
-				wp_send_json( array( 'success' => 'true', 'shipping_methods' => $this->build_shipping_methods( $data ), 'line_items' => $this->build_line_items(), 'total' => WC()->cart->total ) );
398
+				wp_send_json(array('success' => 'true', 'shipping_methods' => $this->build_shipping_methods($data), 'line_items' => $this->build_line_items(), 'total' => WC()->cart->total));
399 399
 			} else {
400
-				throw new Exception( __( 'Unable to find shipping method for address.', 'woocommerce-gateway-stripe' ) );
400
+				throw new Exception(__('Unable to find shipping method for address.', 'woocommerce-gateway-stripe'));
401 401
 			}
402
-		} catch ( Exception $e ) {
403
-			wp_send_json( array( 'success' => 'false', 'shipping_methods' => array(), 'line_items' => $this->build_line_items(), 'total' => WC()->cart->total ) );
402
+		} catch (Exception $e) {
403
+			wp_send_json(array('success' => 'false', 'shipping_methods' => array(), 'line_items' => $this->build_line_items(), 'total' => WC()->cart->total));
404 404
 		}
405 405
 	}
406 406
 
@@ -411,29 +411,29 @@  discard block
 block discarded – undo
411 411
 	 * @version 3.1.0
412 412
 	 */
413 413
 	public function update_shipping_method() {
414
-		if ( ! defined( 'WOOCOMMERCE_CART' ) ) {
415
-			define( 'WOOCOMMERCE_CART', true );
414
+		if ( ! defined('WOOCOMMERCE_CART')) {
415
+			define('WOOCOMMERCE_CART', true);
416 416
 		}
417 417
 
418
-		if ( ! wp_verify_nonce( $_POST['nonce'], '_wc_stripe_apple_pay_update_shipping_method_nonce' ) ) {
419
-			wp_die( __( 'Cheatin&#8217; huh?', 'woocommerce-gateway-stripe' ) );
418
+		if ( ! wp_verify_nonce($_POST['nonce'], '_wc_stripe_apple_pay_update_shipping_method_nonce')) {
419
+			wp_die(__('Cheatin&#8217; huh?', 'woocommerce-gateway-stripe'));
420 420
 		}
421 421
 
422
-		$selected_shipping_method = array_map( 'wc_clean', $_POST['selected_shipping_method'] );
422
+		$selected_shipping_method = array_map('wc_clean', $_POST['selected_shipping_method']);
423 423
 
424
-		WC()->session->set( 'chosen_shipping_methods', array( $selected_shipping_method['identifier'] ) );
424
+		WC()->session->set('chosen_shipping_methods', array($selected_shipping_method['identifier']));
425 425
 
426 426
 		WC()->cart->calculate_totals();
427 427
 
428 428
 		// Send back the new cart total.
429 429
 		$currency  = get_woocommerce_currency();
430
-		$tax_total = max( 0, round( WC()->cart->tax_total + WC()->cart->shipping_tax_total, WC()->cart->dp ) );
430
+		$tax_total = max(0, round(WC()->cart->tax_total + WC()->cart->shipping_tax_total, WC()->cart->dp));
431 431
 		$data      = array(
432 432
 			'total' => WC()->cart->total,
433 433
 		);
434 434
 
435 435
 		// Include fees and taxes as displayItems.
436
-		foreach ( WC()->cart->fees as $key => $fee ) {
436
+		foreach (WC()->cart->fees as $key => $fee) {
437 437
 			$data['items'][] = array(
438 438
 				'label'  => $fee->name,
439 439
 				'amount' => array(
@@ -442,9 +442,9 @@  discard block
 block discarded – undo
442 442
 				),
443 443
 			);
444 444
 		}
445
-		if ( 0 < $tax_total ) {
445
+		if (0 < $tax_total) {
446 446
 			$data['items'][] = array(
447
-				'label'  => __( 'Tax', 'woocommerce-gateway-stripe' ),
447
+				'label'  => __('Tax', 'woocommerce-gateway-stripe'),
448 448
 				'amount' => array(
449 449
 					'currency' => $currency,
450 450
 					'value'    => $tax_total,
@@ -452,7 +452,7 @@  discard block
 block discarded – undo
452 452
 			);
453 453
 		}
454 454
 
455
-		wp_send_json( array( 'success' => 'true', 'line_items' => $this->build_line_items(), 'total' => WC()->cart->total ) );
455
+		wp_send_json(array('success' => 'true', 'line_items' => $this->build_line_items(), 'total' => WC()->cart->total));
456 456
 	}
457 457
 
458 458
 	/**
@@ -463,35 +463,35 @@  discard block
 block discarded – undo
463 463
 	 * @version 3.1.0
464 464
 	 */
465 465
 	public function process_apple_pay() {
466
-		if ( ! wp_verify_nonce( $_POST['nonce'], '_wc_stripe_apple_pay_nonce' ) ) {
467
-			wp_die( __( 'Cheatin&#8217; huh?', 'woocommerce-gateway-stripe' ) );
466
+		if ( ! wp_verify_nonce($_POST['nonce'], '_wc_stripe_apple_pay_nonce')) {
467
+			wp_die(__('Cheatin&#8217; huh?', 'woocommerce-gateway-stripe'));
468 468
 		}
469 469
 
470 470
 		try {
471
-			$result = array_map( 'wc_clean', $_POST['result'] );
471
+			$result = array_map('wc_clean', $_POST['result']);
472 472
 
473
-			$order = $this->create_order( $result );
473
+			$order = $this->create_order($result);
474 474
 
475 475
 			// Handle payment.
476
-			if ( $order->get_total() > 0 ) {
476
+			if ($order->get_total() > 0) {
477 477
 
478
-				if ( $order->get_total() * 100 < WC_Stripe::get_minimum_amount() ) {
479
-					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 ) ) );
478
+				if ($order->get_total() * 100 < WC_Stripe::get_minimum_amount()) {
479
+					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)));
480 480
 				}
481 481
 
482
-				WC_Stripe::log( "Info: Begin processing payment for order $order->id for the amount of {$order->get_total()}" );
482
+				WC_Stripe::log("Info: Begin processing payment for order $order->id for the amount of {$order->get_total()}");
483 483
 
484 484
 				// Make the request.
485
-				$response = WC_Stripe_API::request( $this->generate_payment_request( $order, $result['token']['id'] ) );
485
+				$response = WC_Stripe_API::request($this->generate_payment_request($order, $result['token']['id']));
486 486
 
487
-				if ( is_wp_error( $response ) ) {
487
+				if (is_wp_error($response)) {
488 488
 					$localized_messages = $this->get_localized_messages();
489 489
 
490
-					throw new Exception( ( isset( $localized_messages[ $response->get_error_code() ] ) ? $localized_messages[ $response->get_error_code() ] : $response->get_error_message() ) );
490
+					throw new Exception((isset($localized_messages[$response->get_error_code()]) ? $localized_messages[$response->get_error_code()] : $response->get_error_message()));
491 491
 				}
492 492
 
493 493
 				// Process valid response.
494
-				$this->process_response( $response, $order );
494
+				$this->process_response($response, $order);
495 495
 			} else {
496 496
 				$order->payment_complete();
497 497
 			}
@@ -499,24 +499,24 @@  discard block
 block discarded – undo
499 499
 			// Remove cart.
500 500
 			WC()->cart->empty_cart();
501 501
 
502
-			update_post_meta( $order->id, '_customer_user', get_current_user_id() );
503
-			update_post_meta( $order->id, '_payment_method_title', __( 'Apple Pay (Stripe)', 'woocommerce-gateway-stripe' ) );
502
+			update_post_meta($order->id, '_customer_user', get_current_user_id());
503
+			update_post_meta($order->id, '_payment_method_title', __('Apple Pay (Stripe)', 'woocommerce-gateway-stripe'));
504 504
 
505 505
 			// Return thank you page redirect.
506
-			wp_send_json( array(
506
+			wp_send_json(array(
507 507
 				'success'  => 'true',
508
-				'redirect' => $this->get_return_url( $order ),
509
-			) );
508
+				'redirect' => $this->get_return_url($order),
509
+			));
510 510
 
511
-		} catch ( Exception $e ) {
512
-			WC()->session->set( 'refresh_totals', true );
513
-			WC_Stripe::log( sprintf( __( 'Error: %s', 'woocommerce-gateway-stripe' ), $e->getMessage() ) );
511
+		} catch (Exception $e) {
512
+			WC()->session->set('refresh_totals', true);
513
+			WC_Stripe::log(sprintf(__('Error: %s', 'woocommerce-gateway-stripe'), $e->getMessage()));
514 514
 
515
-			if ( $order->has_status( array( 'pending', 'failed' ) ) ) {
516
-				$this->send_failed_order_email( $order->id );
515
+			if ($order->has_status(array('pending', 'failed'))) {
516
+				$this->send_failed_order_email($order->id);
517 517
 			}
518 518
 
519
-			wp_send_json( array( 'success' => 'false', 'msg' => $e->getMessage() ) );
519
+			wp_send_json(array('success' => 'false', 'msg' => $e->getMessage()));
520 520
 		}
521 521
 	}
522 522
 
@@ -526,14 +526,14 @@  discard block
 block discarded – undo
526 526
 	 * @param string $source token
527 527
 	 * @return array()
528 528
 	 */
529
-	protected function generate_payment_request( $order, $source ) {
529
+	protected function generate_payment_request($order, $source) {
530 530
 		$post_data                = array();
531
-		$post_data['currency']    = strtolower( $order->get_order_currency() ? $order->get_order_currency() : get_woocommerce_currency() );
532
-		$post_data['amount']      = $this->get_stripe_amount( $order->get_total(), $post_data['currency'] );
533
-		$post_data['description'] = sprintf( __( '%1$s - Order %2$s', 'woocommerce-gateway-stripe' ), $this->statement_descriptor, $order->get_order_number() );
531
+		$post_data['currency']    = strtolower($order->get_order_currency() ? $order->get_order_currency() : get_woocommerce_currency());
532
+		$post_data['amount']      = $this->get_stripe_amount($order->get_total(), $post_data['currency']);
533
+		$post_data['description'] = sprintf(__('%1$s - Order %2$s', 'woocommerce-gateway-stripe'), $this->statement_descriptor, $order->get_order_number());
534 534
 		$post_data['capture']     = 'yes' === $this->_gateway_settings['capture'] ? 'true' : 'false';
535 535
 
536
-		if ( ! empty( $order->billing_email ) && apply_filters( 'wc_stripe_send_stripe_receipt', false ) ) {
536
+		if ( ! empty($order->billing_email) && apply_filters('wc_stripe_send_stripe_receipt', false)) {
537 537
 			$post_data['receipt_email'] = $order->billing_email;
538 538
 		}
539 539
 
@@ -548,7 +548,7 @@  discard block
 block discarded – undo
548 548
 		 * @param WC_Order $order
549 549
 		 * @param object $source
550 550
 		 */
551
-		return apply_filters( 'wc_stripe_generate_payment_request', $post_data, $order );
551
+		return apply_filters('wc_stripe_generate_payment_request', $post_data, $order);
552 552
 	}
553 553
 
554 554
 	/**
@@ -557,14 +557,14 @@  discard block
 block discarded – undo
557 557
 	 * @since 3.1.0
558 558
 	 * @version 3.1.0
559 559
 	 */
560
-	public function build_shipping_methods( $shipping_methods ) {
561
-		if ( empty( $shipping_methods ) ) {
560
+	public function build_shipping_methods($shipping_methods) {
561
+		if (empty($shipping_methods)) {
562 562
 			return array();
563 563
 		}
564 564
 
565 565
 		$shipping = array();
566 566
 
567
-		foreach ( $shipping_methods as $method ) {
567
+		foreach ($shipping_methods as $method) {
568 568
 			$shipping[] = array(
569 569
 				'label'      => $method['label'],
570 570
 				'detail'     => '',
@@ -583,53 +583,53 @@  discard block
 block discarded – undo
583 583
 	 * @version 3.1.0
584 584
 	 */
585 585
 	public function build_line_items() {
586
-		if ( ! defined( 'WOOCOMMERCE_CART' ) ) {
587
-			define( 'WOOCOMMERCE_CART', true );
586
+		if ( ! defined('WOOCOMMERCE_CART')) {
587
+			define('WOOCOMMERCE_CART', true);
588 588
 		}
589 589
 
590
-		$decimals = apply_filters( 'wc_stripe_apple_pay_decimals', 2 );
590
+		$decimals = apply_filters('wc_stripe_apple_pay_decimals', 2);
591 591
 
592 592
 		$items = array();
593 593
 
594
-		foreach ( WC()->cart->get_cart() as $cart_item_key => $values ) {
595
-			$amount         = wc_format_decimal( $values['line_subtotal'], $decimals );
594
+		foreach (WC()->cart->get_cart() as $cart_item_key => $values) {
595
+			$amount         = wc_format_decimal($values['line_subtotal'], $decimals);
596 596
 			$quantity_label = 1 < $values['quantity'] ? ' (x' . $values['quantity'] . ')' : '';
597 597
 
598 598
 			$item = array(
599 599
 				'type'   => 'final',
600 600
 				'label'  => $values['data']->post->post_title . $quantity_label,
601
-				'amount' => wc_format_decimal( $amount, $decimals ),
601
+				'amount' => wc_format_decimal($amount, $decimals),
602 602
 			);
603 603
 
604 604
 			$items[] = $item;
605 605
 		}
606 606
 
607
-		$discounts   = wc_format_decimal( WC()->cart->get_cart_discount_total(), $decimals );
608
-		$tax         = wc_format_decimal( WC()->cart->tax_total + WC()->cart->shipping_tax_total, $decimals );
609
-		$shipping    = wc_format_decimal( WC()->cart->shipping_total, $decimals );
610
-		$item_total  = wc_format_decimal( WC()->cart->cart_contents_total, $decimals ) + $discounts;
611
-		$order_total = wc_format_decimal( $item_total + $tax + $shipping, $decimals );
607
+		$discounts   = wc_format_decimal(WC()->cart->get_cart_discount_total(), $decimals);
608
+		$tax         = wc_format_decimal(WC()->cart->tax_total + WC()->cart->shipping_tax_total, $decimals);
609
+		$shipping    = wc_format_decimal(WC()->cart->shipping_total, $decimals);
610
+		$item_total  = wc_format_decimal(WC()->cart->cart_contents_total, $decimals) + $discounts;
611
+		$order_total = wc_format_decimal($item_total + $tax + $shipping, $decimals);
612 612
 
613
-		if ( wc_tax_enabled() ) {
613
+		if (wc_tax_enabled()) {
614 614
 			$items[] = array(
615 615
 				'type'   => 'final',
616
-				'label'  => __( 'Tax', 'woocommerce-gateway-stripe' ),
616
+				'label'  => __('Tax', 'woocommerce-gateway-stripe'),
617 617
 				'amount' => $tax,
618 618
 			);
619 619
 		}
620 620
 
621
-		if ( WC()->cart->needs_shipping() ) {
621
+		if (WC()->cart->needs_shipping()) {
622 622
 			$items[] = array(
623 623
 				'type'   => 'final',
624
-				'label'  => __( 'Shipping', 'woocommerce-gateway-stripe' ),
624
+				'label'  => __('Shipping', 'woocommerce-gateway-stripe'),
625 625
 				'amount' => $shipping,
626 626
 			);
627 627
 		}
628 628
 
629
-		if ( WC()->cart->has_discount() ) {
629
+		if (WC()->cart->has_discount()) {
630 630
 			$items[] = array(
631 631
 				'type'   => 'final',
632
-				'label'  => __( 'Discount', 'woocommerce-gateway-stripe' ),
632
+				'label'  => __('Discount', 'woocommerce-gateway-stripe'),
633 633
 				'amount' => $discounts,
634 634
 			);
635 635
 		}
@@ -645,24 +645,24 @@  discard block
 block discarded – undo
645 645
 	 * @param array $data
646 646
 	 * @return object $order
647 647
 	 */
648
-	public function create_order( $data = array() ) {
649
-		if ( empty( $data ) ) {
650
-			throw new Exception( sprintf( __( 'Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe' ), 520 ) );
648
+	public function create_order($data = array()) {
649
+		if (empty($data)) {
650
+			throw new Exception(sprintf(__('Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe'), 520));
651 651
 		}
652 652
 
653 653
 		$order = wc_create_order();
654 654
 
655
-		if ( is_wp_error( $order ) ) {
656
-			throw new Exception( sprintf( __( 'Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe' ), 520 ) );
657
-		} elseif ( false === $order ) {
658
-			throw new Exception( sprintf( __( 'Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe' ), 521 ) );
655
+		if (is_wp_error($order)) {
656
+			throw new Exception(sprintf(__('Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe'), 520));
657
+		} elseif (false === $order) {
658
+			throw new Exception(sprintf(__('Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe'), 521));
659 659
 		} else {
660 660
 			$order_id = $order->id;
661
-			do_action( 'woocommerce_new_order', $order_id );
661
+			do_action('woocommerce_new_order', $order_id);
662 662
 		}
663 663
 
664 664
 		// Store the line items to the new/resumed order
665
-		foreach ( WC()->cart->get_cart() as $cart_item_key => $values ) {
665
+		foreach (WC()->cart->get_cart() as $cart_item_key => $values) {
666 666
 			$item_id = $order->add_product(
667 667
 				$values['data'],
668 668
 				$values['quantity'],
@@ -678,47 +678,47 @@  discard block
 block discarded – undo
678 678
 				)
679 679
 			);
680 680
 
681
-			if ( ! $item_id ) {
682
-				throw new Exception( sprintf( __( 'Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe' ), 525 ) );
681
+			if ( ! $item_id) {
682
+				throw new Exception(sprintf(__('Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe'), 525));
683 683
 			}
684 684
 
685 685
 			// Allow plugins to add order item meta
686
-			do_action( 'woocommerce_add_order_item_meta', $item_id, $values, $cart_item_key );
686
+			do_action('woocommerce_add_order_item_meta', $item_id, $values, $cart_item_key);
687 687
 		}
688 688
 
689 689
 		// Store fees
690
-		foreach ( WC()->cart->get_fees() as $fee_key => $fee ) {
691
-			$item_id = $order->add_fee( $fee );
690
+		foreach (WC()->cart->get_fees() as $fee_key => $fee) {
691
+			$item_id = $order->add_fee($fee);
692 692
 
693
-			if ( ! $item_id ) {
694
-				throw new Exception( sprintf( __( 'Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe' ), 526 ) );
693
+			if ( ! $item_id) {
694
+				throw new Exception(sprintf(__('Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe'), 526));
695 695
 			}
696 696
 
697 697
 			// Allow plugins to add order item meta to fees
698
-			do_action( 'woocommerce_add_order_fee_meta', $order_id, $item_id, $fee, $fee_key );
698
+			do_action('woocommerce_add_order_fee_meta', $order_id, $item_id, $fee, $fee_key);
699 699
 		}
700 700
 
701 701
 		// Store tax rows
702
-		foreach ( array_keys( WC()->cart->taxes + WC()->cart->shipping_taxes ) as $tax_rate_id ) {
703
-			if ( $tax_rate_id && ! $order->add_tax( $tax_rate_id, WC()->cart->get_tax_amount( $tax_rate_id ), WC()->cart->get_shipping_tax_amount( $tax_rate_id ) ) && apply_filters( 'woocommerce_cart_remove_taxes_zero_rate_id', 'zero-rated' ) !== $tax_rate_id ) {
704
-				throw new Exception( sprintf( __( 'Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe' ), 528 ) );
702
+		foreach (array_keys(WC()->cart->taxes + WC()->cart->shipping_taxes) as $tax_rate_id) {
703
+			if ($tax_rate_id && ! $order->add_tax($tax_rate_id, WC()->cart->get_tax_amount($tax_rate_id), WC()->cart->get_shipping_tax_amount($tax_rate_id)) && apply_filters('woocommerce_cart_remove_taxes_zero_rate_id', 'zero-rated') !== $tax_rate_id) {
704
+				throw new Exception(sprintf(__('Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe'), 528));
705 705
 			}
706 706
 		}
707 707
 
708 708
 		// Store coupons
709
-		foreach ( WC()->cart->get_coupons() as $code => $coupon ) {
710
-			if ( ! $order->add_coupon( $code, WC()->cart->get_coupon_discount_amount( $code ), WC()->cart->get_coupon_discount_tax_amount( $code ) ) ) {
711
-				throw new Exception( sprintf( __( 'Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe' ), 529 ) );
709
+		foreach (WC()->cart->get_coupons() as $code => $coupon) {
710
+			if ( ! $order->add_coupon($code, WC()->cart->get_coupon_discount_amount($code), WC()->cart->get_coupon_discount_tax_amount($code))) {
711
+				throw new Exception(sprintf(__('Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe'), 529));
712 712
 			}
713 713
 		}
714 714
 
715 715
 		// Billing address
716 716
 		$billing_address = array();
717
-		if ( ! empty( $data['token']['card'] ) ) {
717
+		if ( ! empty($data['token']['card'])) {
718 718
 			// Name from Stripe is a full name string.
719
-			$name                          = explode( ' ', $data['token']['card']['name'] );
720
-			$lastname                      = array_pop( $name );
721
-			$firstname                     = implode( ' ', $name );
719
+			$name                          = explode(' ', $data['token']['card']['name']);
720
+			$lastname                      = array_pop($name);
721
+			$firstname                     = implode(' ', $name);
722 722
 			$billing_address['first_name'] = $firstname;
723 723
 			$billing_address['last_name']  = $lastname;
724 724
 			$billing_address['email']      = $data['shippingContact']['emailAddress'];
@@ -733,7 +733,7 @@  discard block
 block discarded – undo
733 733
 
734 734
 		// Shipping address.
735 735
 		$shipping_address = array();
736
-		if ( WC()->cart->needs_shipping() && ! empty( $data['shippingContact'] ) ) {
736
+		if (WC()->cart->needs_shipping() && ! empty($data['shippingContact'])) {
737 737
 			$shipping_address['first_name'] = $data['shippingContact']['givenName'];
738 738
 			$shipping_address['last_name']  = $data['shippingContact']['familyName'];
739 739
 			$shipping_address['email']      = $data['shippingContact']['emailAddress'];
@@ -744,7 +744,7 @@  discard block
 block discarded – undo
744 744
 			$shipping_address['city']       = $data['shippingContact']['locality'];
745 745
 			$shipping_address['state']      = $data['shippingContact']['administrativeArea'];
746 746
 			$shipping_address['postcode']   = $data['shippingContact']['postalCode'];
747
-		} elseif ( ! empty( $data['shippingContact'] ) ) {
747
+		} elseif ( ! empty($data['shippingContact'])) {
748 748
 			$shipping_address['first_name'] = $firstname;
749 749
 			$shipping_address['last_name']  = $lastname;
750 750
 			$shipping_address['email']      = $data['shippingContact']['emailAddress'];
@@ -757,34 +757,34 @@  discard block
 block discarded – undo
757 757
 			$shipping_address['postcode']   = $data['token']['card']['address_zip'];
758 758
 		}
759 759
 
760
-		$order->set_address( $billing_address, 'billing' );
761
-		$order->set_address( $shipping_address, 'shipping' );
760
+		$order->set_address($billing_address, 'billing');
761
+		$order->set_address($shipping_address, 'shipping');
762 762
 
763
-		WC()->shipping->calculate_shipping( WC()->cart->get_shipping_packages() );
763
+		WC()->shipping->calculate_shipping(WC()->cart->get_shipping_packages());
764 764
 
765 765
 		// Get the rate object selected by user.
766
-		foreach ( WC()->shipping->get_packages() as $package_key => $package ) {
767
-			foreach ( $package['rates'] as $key => $rate ) {
766
+		foreach (WC()->shipping->get_packages() as $package_key => $package) {
767
+			foreach ($package['rates'] as $key => $rate) {
768 768
 				// Loop through user chosen shipping methods.
769
-				foreach ( WC()->session->get( 'chosen_shipping_methods' ) as $method ) {
770
-					if ( $method === $key ) {
771
-						$order->add_shipping( $rate );
769
+				foreach (WC()->session->get('chosen_shipping_methods') as $method) {
770
+					if ($method === $key) {
771
+						$order->add_shipping($rate);
772 772
 					}
773 773
 				}
774 774
 			}
775 775
 		}
776 776
 
777 777
 		$available_gateways = WC()->payment_gateways->get_available_payment_gateways();
778
-		$order->set_payment_method( $available_gateways['stripe'] );
779
-		$order->set_total( WC()->cart->shipping_total, 'shipping' );
780
-		$order->set_total( WC()->cart->get_cart_discount_total(), 'cart_discount' );
781
-		$order->set_total( WC()->cart->get_cart_discount_tax_total(), 'cart_discount_tax' );
782
-		$order->set_total( WC()->cart->tax_total, 'tax' );
783
-		$order->set_total( WC()->cart->shipping_tax_total, 'shipping_tax' );
784
-		$order->set_total( WC()->cart->total );
778
+		$order->set_payment_method($available_gateways['stripe']);
779
+		$order->set_total(WC()->cart->shipping_total, 'shipping');
780
+		$order->set_total(WC()->cart->get_cart_discount_total(), 'cart_discount');
781
+		$order->set_total(WC()->cart->get_cart_discount_tax_total(), 'cart_discount_tax');
782
+		$order->set_total(WC()->cart->tax_total, 'tax');
783
+		$order->set_total(WC()->cart->shipping_tax_total, 'shipping_tax');
784
+		$order->set_total(WC()->cart->total);
785 785
 
786 786
 		// If we got here, the order was created without problems!
787
-		wc_transaction_query( 'commit' );
787
+		wc_transaction_query('commit');
788 788
 
789 789
 		return $order;
790 790
 	}
Please login to merge, or discard this patch.