Completed
Pull Request — master (#91)
by Roy
02:17
created
includes/settings-stripe.php 1 patch
Spacing   +52 added lines, -52 removed lines patch added patch discarded remove patch
@@ -1,138 +1,138 @@
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) {
2
+if ( ! defined('ABSPATH')) {
3 3
 	exit;
4 4
 }
5 5
 
6
-return apply_filters( 'wc_stripe_settings',
6
+return apply_filters('wc_stripe_settings',
7 7
 	array(
8 8
 		'enabled' => array(
9
-			'title'       => __( 'Enable/Disable', 'woocommerce-gateway-stripe' ),
10
-			'label'       => __( 'Enable Stripe', 'woocommerce-gateway-stripe' ),
9
+			'title'       => __('Enable/Disable', 'woocommerce-gateway-stripe'),
10
+			'label'       => __('Enable Stripe', 'woocommerce-gateway-stripe'),
11 11
 			'type'        => 'checkbox',
12 12
 			'description' => '',
13 13
 			'default'     => 'no'
14 14
 		),
15 15
 		'title' => array(
16
-			'title'       => __( 'Title', 'woocommerce-gateway-stripe' ),
16
+			'title'       => __('Title', 'woocommerce-gateway-stripe'),
17 17
 			'type'        => 'text',
18
-			'description' => __( 'This controls the title which the user sees during checkout.', 'woocommerce-gateway-stripe' ),
19
-			'default'     => __( 'Credit Card (Stripe)', 'woocommerce-gateway-stripe' ),
18
+			'description' => __('This controls the title which the user sees during checkout.', 'woocommerce-gateway-stripe'),
19
+			'default'     => __('Credit Card (Stripe)', 'woocommerce-gateway-stripe'),
20 20
 			'desc_tip'    => true,
21 21
 		),
22 22
 		'description' => array(
23
-			'title'       => __( 'Description', 'woocommerce-gateway-stripe' ),
23
+			'title'       => __('Description', 'woocommerce-gateway-stripe'),
24 24
 			'type'        => 'text',
25
-			'description' => __( 'This controls the description which the user sees during checkout.', 'woocommerce-gateway-stripe' ),
26
-			'default'     => __( 'Pay with your credit card via Stripe.', 'woocommerce-gateway-stripe'),
25
+			'description' => __('This controls the description which the user sees during checkout.', 'woocommerce-gateway-stripe'),
26
+			'default'     => __('Pay with your credit card via Stripe.', 'woocommerce-gateway-stripe'),
27 27
 			'desc_tip'    => true,
28 28
 		),
29 29
 		'testmode' => array(
30
-			'title'       => __( 'Test mode', 'woocommerce-gateway-stripe' ),
31
-			'label'       => __( 'Enable Test Mode', 'woocommerce-gateway-stripe' ),
30
+			'title'       => __('Test mode', 'woocommerce-gateway-stripe'),
31
+			'label'       => __('Enable Test Mode', 'woocommerce-gateway-stripe'),
32 32
 			'type'        => 'checkbox',
33
-			'description' => __( 'Place the payment gateway in test mode using test API keys.', 'woocommerce-gateway-stripe' ),
33
+			'description' => __('Place the payment gateway in test mode using test API keys.', 'woocommerce-gateway-stripe'),
34 34
 			'default'     => 'yes',
35 35
 			'desc_tip'    => true,
36 36
 		),
37 37
 		'secret_key' => array(
38
-			'title'       => __( 'Live Secret Key', 'woocommerce-gateway-stripe' ),
38
+			'title'       => __('Live Secret Key', 'woocommerce-gateway-stripe'),
39 39
 			'type'        => 'text',
40
-			'description' => __( 'Get your API keys from your stripe account.', 'woocommerce-gateway-stripe' ),
40
+			'description' => __('Get your API keys from your stripe account.', 'woocommerce-gateway-stripe'),
41 41
 			'default'     => '',
42 42
 			'desc_tip'    => true,
43 43
 		),
44 44
 		'publishable_key' => array(
45
-			'title'       => __( 'Live Publishable Key', 'woocommerce-gateway-stripe' ),
45
+			'title'       => __('Live Publishable Key', 'woocommerce-gateway-stripe'),
46 46
 			'type'        => 'text',
47
-			'description' => __( 'Get your API keys from your stripe account.', 'woocommerce-gateway-stripe' ),
47
+			'description' => __('Get your API keys from your stripe account.', 'woocommerce-gateway-stripe'),
48 48
 			'default'     => '',
49 49
 			'desc_tip'    => true,
50 50
 		),
51 51
 		'test_secret_key' => array(
52
-			'title'       => __( 'Test Secret Key', 'woocommerce-gateway-stripe' ),
52
+			'title'       => __('Test Secret Key', 'woocommerce-gateway-stripe'),
53 53
 			'type'        => 'text',
54
-			'description' => __( 'Get your API keys from your stripe account.', 'woocommerce-gateway-stripe' ),
54
+			'description' => __('Get your API keys from your stripe account.', 'woocommerce-gateway-stripe'),
55 55
 			'default'     => '',
56 56
 			'desc_tip'    => true,
57 57
 		),
58 58
 		'test_publishable_key' => array(
59
-			'title'       => __( 'Test Publishable Key', 'woocommerce-gateway-stripe' ),
59
+			'title'       => __('Test Publishable Key', 'woocommerce-gateway-stripe'),
60 60
 			'type'        => 'text',
61
-			'description' => __( 'Get your API keys from your stripe account.', 'woocommerce-gateway-stripe' ),
61
+			'description' => __('Get your API keys from your stripe account.', 'woocommerce-gateway-stripe'),
62 62
 			'default'     => '',
63 63
 			'desc_tip'    => true,
64 64
 		),
65 65
 		'capture' => array(
66
-			'title'       => __( 'Capture', 'woocommerce-gateway-stripe' ),
67
-			'label'       => __( 'Capture charge immediately', 'woocommerce-gateway-stripe' ),
66
+			'title'       => __('Capture', 'woocommerce-gateway-stripe'),
67
+			'label'       => __('Capture charge immediately', 'woocommerce-gateway-stripe'),
68 68
 			'type'        => 'checkbox',
69
-			'description' => __( 'Whether or not to immediately capture the charge. When unchecked, the charge issues an authorization and will need to be captured later. Uncaptured charges expire in 7 days.', 'woocommerce-gateway-stripe' ),
69
+			'description' => __('Whether or not to immediately capture the charge. When unchecked, the charge issues an authorization and will need to be captured later. Uncaptured charges expire in 7 days.', 'woocommerce-gateway-stripe'),
70 70
 			'default'     => 'yes',
71 71
 			'desc_tip'    => true,
72 72
 		),
73 73
 		'stripe_checkout' => array(
74
-			'title'       => __( 'Stripe Checkout', 'woocommerce-gateway-stripe' ),
75
-			'label'       => __( 'Enable Stripe Checkout', 'woocommerce-gateway-stripe' ),
74
+			'title'       => __('Stripe Checkout', 'woocommerce-gateway-stripe'),
75
+			'label'       => __('Enable Stripe Checkout', 'woocommerce-gateway-stripe'),
76 76
 			'type'        => 'checkbox',
77
-			'description' => __( 'If enabled, this option shows a "pay" button and modal credit card form on the checkout, instead of credit card fields directly on the page.', 'woocommerce-gateway-stripe' ),
77
+			'description' => __('If enabled, this option shows a "pay" button and modal credit card form on the checkout, instead of credit card fields directly on the page.', 'woocommerce-gateway-stripe'),
78 78
 			'default'     => 'no',
79 79
 			'desc_tip'    => true,
80 80
 		),
81 81
 		'stripe_checkout_locale' => array(
82
-			'title'       => __( 'Stripe Checkout locale', 'woocommerce-gateway-stripe' ),
82
+			'title'       => __('Stripe Checkout locale', 'woocommerce-gateway-stripe'),
83 83
 			'type'        => 'select',
84 84
 			'class'       => 'wc-enhanced-select',
85
-			'description' => __( 'Language to display in Stripe Checkout modal. Specify Auto to display Checkout in the user\'s preferred language, if available. English will be used by default.', 'woocommerce-gateway-stripe' ),
85
+			'description' => __('Language to display in Stripe Checkout modal. Specify Auto to display Checkout in the user\'s preferred language, if available. English will be used by default.', 'woocommerce-gateway-stripe'),
86 86
 			'default'     => 'en',
87 87
 			'desc_tip'    => true,
88 88
 			'options'     => array(
89
-				'auto' => __( 'Auto', 'woocommerce-gateway-stripe' ),
90
-				'zh'   => __( 'Simplified Chinese', 'woocommerce-gateway-stripe' ),
91
-				'nl'   => __( 'Dutch', 'woocommerce-gateway-stripe' ),
92
-				'en'   => __( 'English', 'woocommerce-gateway-stripe' ),
93
-				'fr'   => __( 'French', 'woocommerce-gateway-stripe' ),
94
-				'de'   => __( 'German', 'woocommerce-gateway-stripe' ),
95
-				'it'   => __( 'Italian', 'woocommerce-gateway-stripe' ),
96
-				'ja'   => __( 'Japanese', 'woocommerce-gateway-stripe' ),
97
-				'es'   => __( 'Spanish', 'woocommerce-gateway-stripe' ),
89
+				'auto' => __('Auto', 'woocommerce-gateway-stripe'),
90
+				'zh'   => __('Simplified Chinese', 'woocommerce-gateway-stripe'),
91
+				'nl'   => __('Dutch', 'woocommerce-gateway-stripe'),
92
+				'en'   => __('English', 'woocommerce-gateway-stripe'),
93
+				'fr'   => __('French', 'woocommerce-gateway-stripe'),
94
+				'de'   => __('German', 'woocommerce-gateway-stripe'),
95
+				'it'   => __('Italian', 'woocommerce-gateway-stripe'),
96
+				'ja'   => __('Japanese', 'woocommerce-gateway-stripe'),
97
+				'es'   => __('Spanish', 'woocommerce-gateway-stripe'),
98 98
 			),
99 99
 		),
100 100
 		'stripe_bitcoin' => array(
101
-			'title'       => __( 'Bitcoin Currency', 'woocommerce-gateway-stripe' ),
102
-			'label'       => __( 'Enable Bitcoin Currency', 'woocommerce-gateway-stripe' ),
101
+			'title'       => __('Bitcoin Currency', 'woocommerce-gateway-stripe'),
102
+			'label'       => __('Enable Bitcoin Currency', 'woocommerce-gateway-stripe'),
103 103
 			'type'        => 'checkbox',
104
-			'description' => __( 'If enabled, an option to accept bitcoin will show on the checkout modal. Note: Stripe Checkout needs to be enabled and store currency must be set to USD.', 'woocommerce-gateway-stripe' ),
104
+			'description' => __('If enabled, an option to accept bitcoin will show on the checkout modal. Note: Stripe Checkout needs to be enabled and store currency must be set to USD.', 'woocommerce-gateway-stripe'),
105 105
 			'default'     => 'no',
106 106
 			'desc_tip'    => true,
107 107
 		),
108 108
 		'stripe_checkout_image' => array(
109
-			'title'       => __( 'Stripe Checkout Image', 'woocommerce-gateway-stripe' ),
110
-			'description' => __( 'Optionally enter the URL to a 128x128px image of your brand or product. e.g. <code>https://yoursite.com/wp-content/uploads/2013/09/yourimage.jpg</code>', 'woocommerce-gateway-stripe' ),
109
+			'title'       => __('Stripe Checkout Image', 'woocommerce-gateway-stripe'),
110
+			'description' => __('Optionally enter the URL to a 128x128px image of your brand or product. e.g. <code>https://yoursite.com/wp-content/uploads/2013/09/yourimage.jpg</code>', 'woocommerce-gateway-stripe'),
111 111
 			'type'        => 'text',
112 112
 			'default'     => '',
113 113
 			'desc_tip'    => true,
114 114
 		),
115 115
 		'apple_pay' => array(
116
-			'title'       => __( 'Apple Pay', 'woocommerce-gateway-stripe' ),
117
-			'label'       => __( 'Enable Apple Pay', 'woocommerce-gateway-stripe' ),
116
+			'title'       => __('Apple Pay', 'woocommerce-gateway-stripe'),
117
+			'label'       => __('Enable Apple Pay', 'woocommerce-gateway-stripe'),
118 118
 			'type'        => 'checkbox',
119
-			'description' => __( 'If enabled, users will be able to pay with Apple Pay.', 'woocommerce-gateway-stripe' ),
119
+			'description' => __('If enabled, users will be able to pay with Apple Pay.', 'woocommerce-gateway-stripe'),
120 120
 			'default'     => 'no',
121 121
 			'desc_tip'    => true,
122 122
 		),
123 123
 		'saved_cards' => array(
124
-			'title'       => __( 'Saved Cards', 'woocommerce-gateway-stripe' ),
125
-			'label'       => __( 'Enable Payment via Saved Cards', 'woocommerce-gateway-stripe' ),
124
+			'title'       => __('Saved Cards', 'woocommerce-gateway-stripe'),
125
+			'label'       => __('Enable Payment via Saved Cards', 'woocommerce-gateway-stripe'),
126 126
 			'type'        => 'checkbox',
127
-			'description' => __( 'If enabled, users will be able to pay with a saved card during checkout. Card details are saved on Stripe servers, not on your store.', 'woocommerce-gateway-stripe' ),
127
+			'description' => __('If enabled, users will be able to pay with a saved card during checkout. Card details are saved on Stripe servers, not on your store.', 'woocommerce-gateway-stripe'),
128 128
 			'default'     => 'no',
129 129
 			'desc_tip'    => true,
130 130
 		),
131 131
 		'logging' => array(
132
-			'title'       => __( 'Logging', 'woocommerce-gateway-stripe' ),
133
-			'label'       => __( 'Log debug messages', 'woocommerce-gateway-stripe' ),
132
+			'title'       => __('Logging', 'woocommerce-gateway-stripe'),
133
+			'label'       => __('Log debug messages', 'woocommerce-gateway-stripe'),
134 134
 			'type'        => 'checkbox',
135
-			'description' => __( 'Save debug messages to the WooCommerce System Status log.', 'woocommerce-gateway-stripe' ),
135
+			'description' => __('Save debug messages to the WooCommerce System Status log.', 'woocommerce-gateway-stripe'),
136 136
 			'default'     => 'no',
137 137
 			'desc_tip'    => true,
138 138
 		),
Please login to merge, or discard this patch.
woocommerce-gateway-stripe.php 1 patch
Spacing   +123 added lines, -123 removed lines patch added patch discarded remove patch
@@ -25,20 +25,20 @@  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__ ) ) ) );
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 40
 
41
-if ( ! class_exists( 'WC_Stripe' ) ) :
41
+if ( ! class_exists('WC_Stripe')) :
42 42
 
43 43
 class WC_Stripe {
44 44
 
@@ -58,7 +58,7 @@  discard block
 block discarded – undo
58 58
 	 * @return Singleton The *Singleton* instance.
59 59
 	 */
60 60
 	public static function get_instance() {
61
-		if ( null === self::$instance ) {
61
+		if (null === self::$instance) {
62 62
 			self::$instance = new self();
63 63
 		}
64 64
 		return self::$instance;
@@ -107,9 +107,9 @@  discard block
 block discarded – undo
107 107
 	 * *Singleton* via the `new` operator from outside of this class.
108 108
 	 */
109 109
 	protected function __construct() {
110
-		add_action( 'admin_init', array( $this, 'check_environment' ) );
111
-		add_action( 'admin_notices', array( $this, 'admin_notices' ), 15 );
112
-		add_action( 'plugins_loaded', array( $this, 'init' ) );
110
+		add_action('admin_init', array($this, 'check_environment'));
111
+		add_action('admin_notices', array($this, 'admin_notices'), 15);
112
+		add_action('plugins_loaded', array($this, 'init'));
113 113
 	}
114 114
 
115 115
 	/**
@@ -117,31 +117,31 @@  discard block
 block discarded – undo
117 117
 	 */
118 118
 	public function init() {
119 119
 		// Don't hook anything else in the plugin if we're in an incompatible environment
120
-		if ( self::get_environment_warning() ) {
120
+		if (self::get_environment_warning()) {
121 121
 			return;
122 122
 		}
123 123
 
124
-		include_once( dirname( __FILE__ ) . '/includes/class-wc-stripe-api.php' );
125
-		include_once( dirname( __FILE__ ) . '/includes/class-wc-stripe-customer.php' );
124
+		include_once(dirname(__FILE__) . '/includes/class-wc-stripe-api.php');
125
+		include_once(dirname(__FILE__) . '/includes/class-wc-stripe-customer.php');
126 126
 
127 127
 		// Init the gateway itself
128 128
 		$this->init_gateways();
129 129
 
130
-		add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), array( $this, 'plugin_action_links' ) );
131
-		add_action( 'woocommerce_order_status_on-hold_to_processing', array( $this, 'capture_payment' ) );
132
-		add_action( 'woocommerce_order_status_on-hold_to_completed', array( $this, 'capture_payment' ) );
133
-		add_action( 'woocommerce_order_status_on-hold_to_cancelled', array( $this, 'cancel_payment' ) );
134
-		add_action( 'woocommerce_order_status_on-hold_to_refunded', array( $this, 'cancel_payment' ) );
135
-		add_filter( 'woocommerce_get_customer_payment_tokens', array( $this, 'woocommerce_get_customer_payment_tokens' ), 10, 3 );
136
-		add_action( 'woocommerce_payment_token_deleted', array( $this, 'woocommerce_payment_token_deleted' ), 10, 2 );
137
-		add_action( 'woocommerce_payment_token_set_default', array( $this, 'woocommerce_payment_token_set_default' ) );	
130
+		add_filter('plugin_action_links_' . plugin_basename(__FILE__), array($this, 'plugin_action_links'));
131
+		add_action('woocommerce_order_status_on-hold_to_processing', array($this, 'capture_payment'));
132
+		add_action('woocommerce_order_status_on-hold_to_completed', array($this, 'capture_payment'));
133
+		add_action('woocommerce_order_status_on-hold_to_cancelled', array($this, 'cancel_payment'));
134
+		add_action('woocommerce_order_status_on-hold_to_refunded', array($this, 'cancel_payment'));
135
+		add_filter('woocommerce_get_customer_payment_tokens', array($this, 'woocommerce_get_customer_payment_tokens'), 10, 3);
136
+		add_action('woocommerce_payment_token_deleted', array($this, 'woocommerce_payment_token_deleted'), 10, 2);
137
+		add_action('woocommerce_payment_token_set_default', array($this, 'woocommerce_payment_token_set_default'));	
138 138
 	}
139 139
 
140 140
 	/**
141 141
 	 * Allow this class and other classes to add slug keyed notices (to avoid duplication)
142 142
 	 */
143
-	public function add_admin_notice( $slug, $class, $message ) {
144
-		$this->notices[ $slug ] = array(
143
+	public function add_admin_notice($slug, $class, $message) {
144
+		$this->notices[$slug] = array(
145 145
 			'class'   => $class,
146 146
 			'message' => $message
147 147
 		);
@@ -154,21 +154,21 @@  discard block
 block discarded – undo
154 154
 	public function check_environment() {
155 155
 		$environment_warning = self::get_environment_warning();
156 156
 
157
-		if ( $environment_warning && is_plugin_active( plugin_basename( __FILE__ ) ) ) {
158
-			$this->add_admin_notice( 'bad_environment', 'error', $environment_warning );
157
+		if ($environment_warning && is_plugin_active(plugin_basename(__FILE__))) {
158
+			$this->add_admin_notice('bad_environment', 'error', $environment_warning);
159 159
 		}
160 160
 
161 161
 		// Check if secret key present. Otherwise prompt, via notice, to go to
162 162
 		// setting.
163
-		if ( ! class_exists( 'WC_Stripe_API' ) ) {
164
-			include_once( dirname( __FILE__ ) . '/includes/class-wc-stripe-api.php' );
163
+		if ( ! class_exists('WC_Stripe_API')) {
164
+			include_once(dirname(__FILE__) . '/includes/class-wc-stripe-api.php');
165 165
 		}
166 166
 
167 167
 		$secret = WC_Stripe_API::get_secret_key();
168 168
 
169
-		if ( empty( $secret ) && ! ( isset( $_GET['page'], $_GET['section'] ) && 'wc-settings' === $_GET['page'] && 'stripe' === $_GET['section'] ) ) {
169
+		if (empty($secret) && ! (isset($_GET['page'], $_GET['section']) && 'wc-settings' === $_GET['page'] && 'stripe' === $_GET['section'])) {
170 170
 			$setting_link = $this->get_setting_link();
171
-			$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 ) );
171
+			$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));
172 172
 		}
173 173
 	}
174 174
 
@@ -177,24 +177,24 @@  discard block
 block discarded – undo
177 177
 	 * found or false if the environment has no problems.
178 178
 	 */
179 179
 	static function get_environment_warning() {
180
-		if ( version_compare( phpversion(), WC_STRIPE_MIN_PHP_VER, '<' ) ) {
181
-			$message = __( 'WooCommerce Stripe - The minimum PHP version required for this plugin is %1$s. You are running %2$s.', 'woocommerce-gateway-stripe', 'woocommerce-gateway-stripe' );
180
+		if (version_compare(phpversion(), WC_STRIPE_MIN_PHP_VER, '<')) {
181
+			$message = __('WooCommerce Stripe - The minimum PHP version required for this plugin is %1$s. You are running %2$s.', 'woocommerce-gateway-stripe', 'woocommerce-gateway-stripe');
182 182
 
183
-			return sprintf( $message, WC_STRIPE_MIN_PHP_VER, phpversion() );
183
+			return sprintf($message, WC_STRIPE_MIN_PHP_VER, phpversion());
184 184
 		}
185 185
 		
186
-		if ( ! defined( 'WC_VERSION' ) ) {
187
-			return __( 'WooCommerce Stripe requires WooCommerce to be activated to work.', 'woocommerce-gateway-stripe' );
186
+		if ( ! defined('WC_VERSION')) {
187
+			return __('WooCommerce Stripe requires WooCommerce to be activated to work.', 'woocommerce-gateway-stripe');
188 188
 		} 
189 189
 
190
-		if ( version_compare( WC_VERSION, WC_STRIPE_MIN_WC_VER, '<' ) ) {
191
-			$message = __( 'WooCommerce Stripe - The minimum WooCommerce version required for this plugin is %1$s. You are running %2$s.', 'woocommerce-gateway-stripe', 'woocommerce-gateway-stripe' );
190
+		if (version_compare(WC_VERSION, WC_STRIPE_MIN_WC_VER, '<')) {
191
+			$message = __('WooCommerce Stripe - The minimum WooCommerce version required for this plugin is %1$s. You are running %2$s.', 'woocommerce-gateway-stripe', 'woocommerce-gateway-stripe');
192 192
 
193
-			return sprintf( $message, WC_STRIPE_MIN_WC_VER, WC_VERSION );
193
+			return sprintf($message, WC_STRIPE_MIN_WC_VER, WC_VERSION);
194 194
 		}
195 195
 
196
-		if ( ! function_exists( 'curl_init' ) ) {
197
-			return __( 'WooCommerce Stripe - cURL is not installed.', 'woocommerce-gateway-stripe' );
196
+		if ( ! function_exists('curl_init')) {
197
+			return __('WooCommerce Stripe - cURL is not installed.', 'woocommerce-gateway-stripe');
198 198
 		}
199 199
 
200 200
 		return false;
@@ -205,15 +205,15 @@  discard block
 block discarded – undo
205 205
 	 *
206 206
 	 * @since 1.0.0
207 207
 	 */
208
-	public function plugin_action_links( $links ) {
208
+	public function plugin_action_links($links) {
209 209
 		$setting_link = $this->get_setting_link();
210 210
 
211 211
 		$plugin_links = array(
212
-			'<a href="' . $setting_link . '">' . __( 'Settings', 'woocommerce-gateway-stripe' ) . '</a>',
213
-			'<a href="https://docs.woothemes.com/document/stripe/">' . __( 'Docs', 'woocommerce-gateway-stripe' ) . '</a>',
214
-			'<a href="http://support.woothemes.com/">' . __( 'Support', 'woocommerce-gateway-stripe' ) . '</a>',
212
+			'<a href="' . $setting_link . '">' . __('Settings', 'woocommerce-gateway-stripe') . '</a>',
213
+			'<a href="https://docs.woothemes.com/document/stripe/">' . __('Docs', 'woocommerce-gateway-stripe') . '</a>',
214
+			'<a href="http://support.woothemes.com/">' . __('Support', 'woocommerce-gateway-stripe') . '</a>',
215 215
 		);
216
-		return array_merge( $plugin_links, $links );
216
+		return array_merge($plugin_links, $links);
217 217
 	}
218 218
 
219 219
 	/**
@@ -224,20 +224,20 @@  discard block
 block discarded – undo
224 224
 	 * @return string Setting link
225 225
 	 */
226 226
 	public function get_setting_link() {
227
-		$use_id_as_section = version_compare( WC()->version, '2.6', '>=' );
227
+		$use_id_as_section = version_compare(WC()->version, '2.6', '>=');
228 228
 
229
-		$section_slug = $use_id_as_section ? 'stripe' : strtolower( 'WC_Gateway_Stripe' );
229
+		$section_slug = $use_id_as_section ? 'stripe' : strtolower('WC_Gateway_Stripe');
230 230
 
231
-		return admin_url( 'admin.php?page=wc-settings&tab=checkout&section=' . $section_slug );
231
+		return admin_url('admin.php?page=wc-settings&tab=checkout&section=' . $section_slug);
232 232
 	}
233 233
 
234 234
 	/**
235 235
 	 * Display any notices we've collected thus far (e.g. for connection, disconnection)
236 236
 	 */
237 237
 	public function admin_notices() {
238
-		foreach ( (array) $this->notices as $notice_key => $notice ) {
239
-			echo "<div class='" . esc_attr( $notice['class'] ) . "'><p>";
240
-			echo wp_kses( $notice['message'], array( 'a' => array( 'href' => array() ) ) );
238
+		foreach ((array) $this->notices as $notice_key => $notice) {
239
+			echo "<div class='" . esc_attr($notice['class']) . "'><p>";
240
+			echo wp_kses($notice['message'], array('a' => array('href' => array())));
241 241
 			echo "</p></div>";
242 242
 		}
243 243
 	}
@@ -248,28 +248,28 @@  discard block
 block discarded – undo
248 248
 	 * @since 1.0.0
249 249
 	 */
250 250
 	public function init_gateways() {
251
-		if ( class_exists( 'WC_Subscriptions_Order' ) && function_exists( 'wcs_create_renewal_order' ) ) {
251
+		if (class_exists('WC_Subscriptions_Order') && function_exists('wcs_create_renewal_order')) {
252 252
 			$this->subscription_support_enabled = true;
253 253
 		}
254 254
 
255
-		if ( class_exists( 'WC_Pre_Orders_Order' ) ) {
255
+		if (class_exists('WC_Pre_Orders_Order')) {
256 256
 			$this->pre_order_enabled = true;
257 257
 		}
258 258
 
259
-		if ( ! class_exists( 'WC_Payment_Gateway' ) ) {
259
+		if ( ! class_exists('WC_Payment_Gateway')) {
260 260
 			return;
261 261
 		}
262 262
 
263
-		if ( class_exists( 'WC_Payment_Gateway_CC' ) ) {
264
-			include_once( dirname( __FILE__ ) . '/includes/class-wc-gateway-stripe.php' );
265
-			require_once( dirname( __FILE__ ) . '/includes/class-wc-stripe-apple-pay.php' );
263
+		if (class_exists('WC_Payment_Gateway_CC')) {
264
+			include_once(dirname(__FILE__) . '/includes/class-wc-gateway-stripe.php');
265
+			require_once(dirname(__FILE__) . '/includes/class-wc-stripe-apple-pay.php');
266 266
 		} else {
267
-			include_once( dirname( __FILE__ ) . '/includes/legacy/class-wc-gateway-stripe.php' );
268
-			include_once( dirname( __FILE__ ) . '/includes/legacy/class-wc-gateway-stripe-saved-cards.php' );
267
+			include_once(dirname(__FILE__) . '/includes/legacy/class-wc-gateway-stripe.php');
268
+			include_once(dirname(__FILE__) . '/includes/legacy/class-wc-gateway-stripe-saved-cards.php');
269 269
 		}
270 270
 
271
-		load_plugin_textdomain( 'woocommerce-gateway-stripe', false, plugin_basename( dirname( __FILE__ ) ) . '/languages' );
272
-		add_filter( 'woocommerce_payment_gateways', array( $this, 'add_gateways' ) );
271
+		load_plugin_textdomain('woocommerce-gateway-stripe', false, plugin_basename(dirname(__FILE__)) . '/languages');
272
+		add_filter('woocommerce_payment_gateways', array($this, 'add_gateways'));
273 273
 
274 274
 		$load_addons = (
275 275
 			$this->subscription_support_enabled
@@ -277,8 +277,8 @@  discard block
 block discarded – undo
277 277
 			$this->pre_order_enabled
278 278
 		);
279 279
 
280
-		if ( $load_addons ) {
281
-			require_once( dirname( __FILE__ ) . '/includes/class-wc-gateway-stripe-addons.php' );
280
+		if ($load_addons) {
281
+			require_once(dirname(__FILE__) . '/includes/class-wc-gateway-stripe-addons.php');
282 282
 		}
283 283
 	}
284 284
 
@@ -287,8 +287,8 @@  discard block
 block discarded – undo
287 287
 	 *
288 288
 	 * @since 1.0.0
289 289
 	 */
290
-	public function add_gateways( $methods ) {
291
-		if ( $this->subscription_support_enabled || $this->pre_order_enabled ) {
290
+	public function add_gateways($methods) {
291
+		if ($this->subscription_support_enabled || $this->pre_order_enabled) {
292 292
 			$methods[] = 'WC_Gateway_Stripe_Addons';
293 293
 		} else {
294 294
 			$methods[] = 'WC_Gateway_Stripe';
@@ -301,35 +301,35 @@  discard block
 block discarded – undo
301 301
 	 *
302 302
 	 * @param  int $order_id
303 303
 	 */
304
-	public function capture_payment( $order_id ) {
305
-		$order = wc_get_order( $order_id );
304
+	public function capture_payment($order_id) {
305
+		$order = wc_get_order($order_id);
306 306
 
307
-		if ( 'stripe' === $order->payment_method ) {
308
-			$charge   = get_post_meta( $order_id, '_stripe_charge_id', true );
309
-			$captured = get_post_meta( $order_id, '_stripe_charge_captured', true );
307
+		if ('stripe' === $order->payment_method) {
308
+			$charge   = get_post_meta($order_id, '_stripe_charge_id', true);
309
+			$captured = get_post_meta($order_id, '_stripe_charge_captured', true);
310 310
 
311
-			if ( $charge && 'no' === $captured ) {
312
-				$result = WC_Stripe_API::request( array(
311
+			if ($charge && 'no' === $captured) {
312
+				$result = WC_Stripe_API::request(array(
313 313
 					'amount'   => $order->get_total() * 100,
314 314
 					'expand[]' => 'balance_transaction'
315
-				), 'charges/' . $charge . '/capture' );
315
+				), 'charges/' . $charge . '/capture');
316 316
 
317
-				if ( is_wp_error( $result ) ) {
318
-					$order->add_order_note( __( 'Unable to capture charge!', 'woocommerce-gateway-stripe' ) . ' ' . $result->get_error_message() );
317
+				if (is_wp_error($result)) {
318
+					$order->add_order_note(__('Unable to capture charge!', 'woocommerce-gateway-stripe') . ' ' . $result->get_error_message());
319 319
 				} else {
320
-					$order->add_order_note( sprintf( __( 'Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe' ), $result->id ) );
321
-					update_post_meta( $order->id, '_stripe_charge_captured', 'yes' );
320
+					$order->add_order_note(sprintf(__('Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe'), $result->id));
321
+					update_post_meta($order->id, '_stripe_charge_captured', 'yes');
322 322
 
323 323
 					// Store other data such as fees
324
-					update_post_meta( $order->id, 'Stripe Payment ID', $result->id );
324
+					update_post_meta($order->id, 'Stripe Payment ID', $result->id);
325 325
 
326
-					if ( isset( $result->balance_transaction ) && isset( $result->balance_transaction->fee ) ) {
326
+					if (isset($result->balance_transaction) && isset($result->balance_transaction->fee)) {
327 327
 						// Fees and Net needs to both come from Stripe to be accurate as the returned
328 328
 						// values are in the local currency of the Stripe account, not from WC.
329
-						$fee = ! empty( $result->balance_transaction->fee ) ? number_format( $result->balance_transaction->fee / 100, 2, '.', '' ) : 0;
330
-						$net = ! empty( $result->balance_transaction->net ) ? number_format( $result->balance_transaction->net / 100, 2, '.', '' ) : 0;
331
-						update_post_meta( $order->id, 'Stripe Fee', $fee );
332
-						update_post_meta( $order->id, 'Net Revenue From Stripe', $net );
329
+						$fee = ! empty($result->balance_transaction->fee) ? number_format($result->balance_transaction->fee / 100, 2, '.', '') : 0;
330
+						$net = ! empty($result->balance_transaction->net) ? number_format($result->balance_transaction->net / 100, 2, '.', '') : 0;
331
+						update_post_meta($order->id, 'Stripe Fee', $fee);
332
+						update_post_meta($order->id, 'Net Revenue From Stripe', $net);
333 333
 					}
334 334
 				}
335 335
 			}
@@ -341,23 +341,23 @@  discard block
 block discarded – undo
341 341
 	 *
342 342
 	 * @param  int $order_id
343 343
 	 */
344
-	public function cancel_payment( $order_id ) {
345
-		$order = wc_get_order( $order_id );
344
+	public function cancel_payment($order_id) {
345
+		$order = wc_get_order($order_id);
346 346
 
347
-		if ( 'stripe' === $order->payment_method ) {
348
-			$charge   = get_post_meta( $order_id, '_stripe_charge_id', true );
347
+		if ('stripe' === $order->payment_method) {
348
+			$charge = get_post_meta($order_id, '_stripe_charge_id', true);
349 349
 
350
-			if ( $charge ) {
351
-				$result = WC_Stripe_API::request( array(
350
+			if ($charge) {
351
+				$result = WC_Stripe_API::request(array(
352 352
 					'amount' => $order->get_total() * 100,
353
-				), 'charges/' . $charge . '/refund' );
353
+				), 'charges/' . $charge . '/refund');
354 354
 
355
-				if ( is_wp_error( $result ) ) {
356
-					$order->add_order_note( __( 'Unable to refund charge!', 'woocommerce-gateway-stripe' ) . ' ' . $result->get_error_message() );
355
+				if (is_wp_error($result)) {
356
+					$order->add_order_note(__('Unable to refund charge!', 'woocommerce-gateway-stripe') . ' ' . $result->get_error_message());
357 357
 				} else {
358
-					$order->add_order_note( sprintf( __( 'Stripe charge refunded (Charge ID: %s)', 'woocommerce-gateway-stripe' ), $result->id ) );
359
-					delete_post_meta( $order->id, '_stripe_charge_captured' );
360
-					delete_post_meta( $order->id, '_stripe_charge_id' );
358
+					$order->add_order_note(sprintf(__('Stripe charge refunded (Charge ID: %s)', 'woocommerce-gateway-stripe'), $result->id));
359
+					delete_post_meta($order->id, '_stripe_charge_captured');
360
+					delete_post_meta($order->id, '_stripe_charge_id');
361 361
 				}
362 362
 			}
363 363
 		}
@@ -368,28 +368,28 @@  discard block
 block discarded – undo
368 368
 	 * @param array $tokens
369 369
 	 * @return array
370 370
 	 */
371
-	public function woocommerce_get_customer_payment_tokens( $tokens, $customer_id, $gateway_id ) {
372
-		if ( is_user_logged_in() && 'stripe' === $gateway_id && class_exists( 'WC_Payment_Token_CC' ) ) {
373
-			$stripe_customer = new WC_Stripe_Customer( $customer_id );
371
+	public function woocommerce_get_customer_payment_tokens($tokens, $customer_id, $gateway_id) {
372
+		if (is_user_logged_in() && 'stripe' === $gateway_id && class_exists('WC_Payment_Token_CC')) {
373
+			$stripe_customer = new WC_Stripe_Customer($customer_id);
374 374
 			$stripe_cards    = $stripe_customer->get_cards();
375 375
 			$stored_tokens   = array();
376 376
 
377
-			foreach ( $tokens as $token ) {
377
+			foreach ($tokens as $token) {
378 378
 				$stored_tokens[] = $token->get_token();
379 379
 			}
380 380
 
381
-			foreach ( $stripe_cards as $card ) {
382
-				if ( ! in_array( $card->id, $stored_tokens ) ) {
381
+			foreach ($stripe_cards as $card) {
382
+				if ( ! in_array($card->id, $stored_tokens)) {
383 383
 					$token = new WC_Payment_Token_CC();
384
-					$token->set_token( $card->id );
385
-					$token->set_gateway_id( 'stripe' );
386
-					$token->set_card_type( strtolower( $card->brand ) );
387
-					$token->set_last4( $card->last4 );
388
-					$token->set_expiry_month( $card->exp_month  );
389
-					$token->set_expiry_year( $card->exp_year );
390
-					$token->set_user_id( $customer_id );
384
+					$token->set_token($card->id);
385
+					$token->set_gateway_id('stripe');
386
+					$token->set_card_type(strtolower($card->brand));
387
+					$token->set_last4($card->last4);
388
+					$token->set_expiry_month($card->exp_month);
389
+					$token->set_expiry_year($card->exp_year);
390
+					$token->set_user_id($customer_id);
391 391
 					$token->save();
392
-					$tokens[ $token->get_id() ] = $token;
392
+					$tokens[$token->get_id()] = $token;
393 393
 				}
394 394
 			}
395 395
 		}
@@ -399,21 +399,21 @@  discard block
 block discarded – undo
399 399
 	/**
400 400
 	 * Delete token from Stripe
401 401
 	 */
402
-	public function woocommerce_payment_token_deleted( $token_id, $token ) {
403
-		if ( 'stripe' === $token->get_gateway_id() ) {
404
-			$stripe_customer = new WC_Stripe_Customer( get_current_user_id() );
405
-			$stripe_customer->delete_card( $token->get_token() );
402
+	public function woocommerce_payment_token_deleted($token_id, $token) {
403
+		if ('stripe' === $token->get_gateway_id()) {
404
+			$stripe_customer = new WC_Stripe_Customer(get_current_user_id());
405
+			$stripe_customer->delete_card($token->get_token());
406 406
 		}
407 407
 	}
408 408
 
409 409
 	/**
410 410
 	 * Set as default in Stripe
411 411
 	 */
412
-	public function woocommerce_payment_token_set_default( $token_id ) {
413
-		$token = WC_Payment_Tokens::get( $token_id );
414
-		if ( 'stripe' === $token->get_gateway_id() ) {
415
-			$stripe_customer = new WC_Stripe_Customer( get_current_user_id() );
416
-			$stripe_customer->set_default_card( $token->get_token() );
412
+	public function woocommerce_payment_token_set_default($token_id) {
413
+		$token = WC_Payment_Tokens::get($token_id);
414
+		if ('stripe' === $token->get_gateway_id()) {
415
+			$stripe_customer = new WC_Stripe_Customer(get_current_user_id());
416
+			$stripe_customer->set_default_card($token->get_token());
417 417
 		}
418 418
 	}
419 419
 
@@ -425,15 +425,15 @@  discard block
 block discarded – undo
425 425
 	 * And fits on your back?
426 426
 	 * It's log, log, log
427 427
 	 */
428
-	public static function log( $message ) {
429
-		if ( empty( self::$log ) ) {
428
+	public static function log($message) {
429
+		if (empty(self::$log)) {
430 430
 			self::$log = new WC_Logger();
431 431
 		}
432 432
 
433
-		self::$log->add( 'woocommerce-gateway-stripe', $message );
433
+		self::$log->add('woocommerce-gateway-stripe', $message);
434 434
 
435
-		if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
436
-			error_log( $message );
435
+		if (defined('WP_DEBUG') && WP_DEBUG) {
436
+			error_log($message);
437 437
 		}
438 438
 	}
439 439
 }
Please login to merge, or discard this patch.
includes/class-wc-gateway-stripe.php 1 patch
Spacing   +212 added lines, -212 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
 
@@ -92,8 +92,8 @@  discard block
 block discarded – undo
92 92
 	 */
93 93
 	public function __construct() {
94 94
 		$this->id                   = 'stripe';
95
-		$this->method_title         = __( 'Stripe', 'woocommerce-gateway-stripe' );
96
-		$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' );
95
+		$this->method_title         = __('Stripe', 'woocommerce-gateway-stripe');
96
+		$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');
97 97
 		$this->has_fields           = true;
98 98
 		$this->view_transaction_url = 'https://dashboard.stripe.com/payments/%s';
99 99
 		$this->supports             = array(
@@ -121,36 +121,36 @@  discard block
 block discarded – undo
121 121
 		$this->init_settings();
122 122
 
123 123
 		// Get setting values.
124
-		$this->title                  = $this->get_option( 'title' );
125
-		$this->description            = $this->get_option( 'description' );
126
-		$this->enabled                = $this->get_option( 'enabled' );
127
-		$this->testmode               = 'yes' === $this->get_option( 'testmode' );
128
-		$this->capture                = 'yes' === $this->get_option( 'capture', 'yes' );
129
-		$this->stripe_checkout        = 'yes' === $this->get_option( 'stripe_checkout' );
130
-		$this->stripe_checkout_locale = $this->get_option( 'stripe_checkout_locale' );
131
-		$this->stripe_checkout_image  = $this->get_option( 'stripe_checkout_image', '' );
132
-		$this->saved_cards            = 'yes' === $this->get_option( 'saved_cards' );
133
-		$this->secret_key             = $this->testmode ? $this->get_option( 'test_secret_key' ) : $this->get_option( 'secret_key' );
134
-		$this->publishable_key        = $this->testmode ? $this->get_option( 'test_publishable_key' ) : $this->get_option( 'publishable_key' );
135
-		$this->bitcoin                = 'USD' === strtoupper( get_woocommerce_currency() ) && 'yes' === $this->get_option( 'stripe_bitcoin' );
136
-		$this->apple_pay              = 'yes' === $this->get_option( 'apple_pay' );
137
-		$this->logging                = 'yes' === $this->get_option( 'logging' );
124
+		$this->title                  = $this->get_option('title');
125
+		$this->description            = $this->get_option('description');
126
+		$this->enabled                = $this->get_option('enabled');
127
+		$this->testmode               = 'yes' === $this->get_option('testmode');
128
+		$this->capture                = 'yes' === $this->get_option('capture', 'yes');
129
+		$this->stripe_checkout        = 'yes' === $this->get_option('stripe_checkout');
130
+		$this->stripe_checkout_locale = $this->get_option('stripe_checkout_locale');
131
+		$this->stripe_checkout_image  = $this->get_option('stripe_checkout_image', '');
132
+		$this->saved_cards            = 'yes' === $this->get_option('saved_cards');
133
+		$this->secret_key             = $this->testmode ? $this->get_option('test_secret_key') : $this->get_option('secret_key');
134
+		$this->publishable_key        = $this->testmode ? $this->get_option('test_publishable_key') : $this->get_option('publishable_key');
135
+		$this->bitcoin                = 'USD' === strtoupper(get_woocommerce_currency()) && 'yes' === $this->get_option('stripe_bitcoin');
136
+		$this->apple_pay              = 'yes' === $this->get_option('apple_pay');
137
+		$this->logging                = 'yes' === $this->get_option('logging');
138 138
 
139
-		if ( $this->stripe_checkout ) {
140
-			$this->order_button_text = __( 'Continue to payment', 'woocommerce-gateway-stripe' );
139
+		if ($this->stripe_checkout) {
140
+			$this->order_button_text = __('Continue to payment', 'woocommerce-gateway-stripe');
141 141
 		}
142 142
 
143
-		if ( $this->testmode ) {
144
-			$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' );
145
-			$this->description  = trim( $this->description );
143
+		if ($this->testmode) {
144
+			$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');
145
+			$this->description  = trim($this->description);
146 146
 		}
147 147
 
148
-		WC_Stripe_API::set_secret_key( $this->secret_key );
148
+		WC_Stripe_API::set_secret_key($this->secret_key);
149 149
 
150 150
 		// Hooks.
151
-		add_action( 'wp_enqueue_scripts', array( $this, 'payment_scripts' ) );
152
-		add_action( 'admin_notices', array( $this, 'admin_notices' ) );
153
-		add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) );
151
+		add_action('wp_enqueue_scripts', array($this, 'payment_scripts'));
152
+		add_action('admin_notices', array($this, 'admin_notices'));
153
+		add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options'));
154 154
 	}
155 155
 
156 156
 	/**
@@ -160,24 +160,24 @@  discard block
 block discarded – undo
160 160
 	 * @return string
161 161
 	 */
162 162
 	public function get_icon() {
163
-		$ext   = version_compare( WC()->version, '2.6', '>=' ) ? '.svg' : '.png';
164
-		$style = version_compare( WC()->version, '2.6', '>=' ) ? 'style="margin-left: 0.3em"' : '';
163
+		$ext   = version_compare(WC()->version, '2.6', '>=') ? '.svg' : '.png';
164
+		$style = version_compare(WC()->version, '2.6', '>=') ? 'style="margin-left: 0.3em"' : '';
165 165
 
166
-		$icon  = '<img src="' . WC_HTTPS::force_https_url( WC()->plugin_url() . '/assets/images/icons/credit-cards/visa' . $ext ) . '" alt="Visa" width="32" ' . $style . ' />';
167
-		$icon .= '<img src="' . WC_HTTPS::force_https_url( WC()->plugin_url() . '/assets/images/icons/credit-cards/mastercard' . $ext ) . '" alt="Mastercard" width="32" ' . $style . ' />';
168
-		$icon .= '<img src="' . WC_HTTPS::force_https_url( WC()->plugin_url() . '/assets/images/icons/credit-cards/amex' . $ext ) . '" alt="Amex" width="32" ' . $style . ' />';
166
+		$icon  = '<img src="' . WC_HTTPS::force_https_url(WC()->plugin_url() . '/assets/images/icons/credit-cards/visa' . $ext) . '" alt="Visa" width="32" ' . $style . ' />';
167
+		$icon .= '<img src="' . WC_HTTPS::force_https_url(WC()->plugin_url() . '/assets/images/icons/credit-cards/mastercard' . $ext) . '" alt="Mastercard" width="32" ' . $style . ' />';
168
+		$icon .= '<img src="' . WC_HTTPS::force_https_url(WC()->plugin_url() . '/assets/images/icons/credit-cards/amex' . $ext) . '" alt="Amex" width="32" ' . $style . ' />';
169 169
 
170
-		if ( 'USD' === get_woocommerce_currency() ) {
171
-			$icon .= '<img src="' . WC_HTTPS::force_https_url( WC()->plugin_url() . '/assets/images/icons/credit-cards/discover' . $ext ) . '" alt="Discover" width="32" ' . $style . ' />';
172
-			$icon .= '<img src="' . WC_HTTPS::force_https_url( WC()->plugin_url() . '/assets/images/icons/credit-cards/jcb' . $ext ) . '" alt="JCB" width="32" ' . $style . ' />';
173
-			$icon .= '<img src="' . WC_HTTPS::force_https_url( WC()->plugin_url() . '/assets/images/icons/credit-cards/diners' . $ext ) . '" alt="Diners" width="32" ' . $style . ' />';
170
+		if ('USD' === get_woocommerce_currency()) {
171
+			$icon .= '<img src="' . WC_HTTPS::force_https_url(WC()->plugin_url() . '/assets/images/icons/credit-cards/discover' . $ext) . '" alt="Discover" width="32" ' . $style . ' />';
172
+			$icon .= '<img src="' . WC_HTTPS::force_https_url(WC()->plugin_url() . '/assets/images/icons/credit-cards/jcb' . $ext) . '" alt="JCB" width="32" ' . $style . ' />';
173
+			$icon .= '<img src="' . WC_HTTPS::force_https_url(WC()->plugin_url() . '/assets/images/icons/credit-cards/diners' . $ext) . '" alt="Diners" width="32" ' . $style . ' />';
174 174
 		}
175 175
 
176
-		if ( $this->bitcoin && $this->stripe_checkout ) {
177
-			$icon .= '<img src="' . WC_HTTPS::force_https_url( plugins_url( '/assets/images/bitcoin' . $ext, WC_STRIPE_MAIN_FILE ) ) . '" alt="Bitcoin" width="24" ' . $style . ' />';
176
+		if ($this->bitcoin && $this->stripe_checkout) {
177
+			$icon .= '<img src="' . WC_HTTPS::force_https_url(plugins_url('/assets/images/bitcoin' . $ext, WC_STRIPE_MAIN_FILE)) . '" alt="Bitcoin" width="24" ' . $style . ' />';
178 178
 		}
179 179
 
180
-		return apply_filters( 'woocommerce_gateway_icon', $icon, $this->id );
180
+		return apply_filters('woocommerce_gateway_icon', $icon, $this->id);
181 181
 	}
182 182
 
183 183
 	/**
@@ -188,11 +188,11 @@  discard block
 block discarded – undo
188 188
 	 *
189 189
 	 * @return float|int
190 190
 	 */
191
-	public function get_stripe_amount( $total, $currency = '' ) {
192
-		if ( ! $currency ) {
191
+	public function get_stripe_amount($total, $currency = '') {
192
+		if ( ! $currency) {
193 193
 			$currency = get_woocommerce_currency();
194 194
 		}
195
-		switch ( strtoupper( $currency ) ) {
195
+		switch (strtoupper($currency)) {
196 196
 			// Zero decimal currencies.
197 197
 			case 'BIF' :
198 198
 			case 'CLP' :
@@ -209,10 +209,10 @@  discard block
 block discarded – undo
209 209
 			case 'XAF' :
210 210
 			case 'XOF' :
211 211
 			case 'XPF' :
212
-				$total = absint( $total );
212
+				$total = absint($total);
213 213
 				break;
214 214
 			default :
215
-				$total = round( $total, 2 ) * 100; // In cents.
215
+				$total = round($total, 2) * 100; // In cents.
216 216
 				break;
217 217
 		}
218 218
 		return $total;
@@ -222,13 +222,13 @@  discard block
 block discarded – undo
222 222
 	 * Check if SSL is enabled and notify the user
223 223
 	 */
224 224
 	public function admin_notices() {
225
-		if ( 'no' === $this->enabled ) {
225
+		if ('no' === $this->enabled) {
226 226
 			return;
227 227
 		}
228 228
 
229 229
 		// Show message if enabled and FORCE SSL is disabled and WordpressHTTPS plugin is not detected.
230
-		if ( ( function_exists( 'wc_site_is_https' ) && ! wc_site_is_https() ) && ( 'no' === get_option( 'woocommerce_force_ssl_checkout' ) && ! class_exists( 'WordPressHTTPS' ) ) ) {
231
-			echo '<div class="error stripe-ssl-message"><p>' . sprintf( __( 'Stripe is enabled, but the <a href="%s">force SSL option</a> is disabled; your checkout may not be secure! Please enable SSL and ensure your server has a valid SSL certificate - Stripe will only work in test mode.', 'woocommerce-gateway-stripe' ), admin_url( 'admin.php?page=wc-settings&tab=checkout' ) ) . '</p></div>';
230
+		if ((function_exists('wc_site_is_https') && ! wc_site_is_https()) && ('no' === get_option('woocommerce_force_ssl_checkout') && ! class_exists('WordPressHTTPS'))) {
231
+			echo '<div class="error stripe-ssl-message"><p>' . sprintf(__('Stripe is enabled, but the <a href="%s">force SSL option</a> is disabled; your checkout may not be secure! Please enable SSL and ensure your server has a valid SSL certificate - Stripe will only work in test mode.', 'woocommerce-gateway-stripe'), admin_url('admin.php?page=wc-settings&tab=checkout')) . '</p></div>';
232 232
 		}
233 233
 	}
234 234
 
@@ -236,11 +236,11 @@  discard block
 block discarded – undo
236 236
 	 * Check if this gateway is enabled
237 237
 	 */
238 238
 	public function is_available() {
239
-		if ( 'yes' === $this->enabled ) {
240
-			if ( ! $this->testmode && is_checkout() && ! is_ssl() ) {
239
+		if ('yes' === $this->enabled) {
240
+			if ( ! $this->testmode && is_checkout() && ! is_ssl()) {
241 241
 				return false;
242 242
 			}
243
-			if ( ! $this->secret_key || ! $this->publishable_key ) {
243
+			if ( ! $this->secret_key || ! $this->publishable_key) {
244 244
 				return false;
245 245
 			}
246 246
 			return true;
@@ -252,9 +252,9 @@  discard block
 block discarded – undo
252 252
 	 * Initialise Gateway Settings Form Fields
253 253
 	 */
254 254
 	public function init_form_fields() {
255
-		$this->form_fields = include( 'settings-stripe.php' );
255
+		$this->form_fields = include('settings-stripe.php');
256 256
 
257
-		wc_enqueue_js( "
257
+		wc_enqueue_js("
258 258
 			jQuery( function( $ ) {
259 259
 				$( '#woocommerce_stripe_stripe_checkout' ).change(function(){
260 260
 					if ( $( this ).is( ':checked' ) ) {
@@ -268,7 +268,7 @@  discard block
 block discarded – undo
268 268
 					var value = $( this ).val();
269 269
 
270 270
 					if ( value.indexOf( '_test_' ) >= 0 ) {
271
-						$( this ).css( 'border-color', 'red' ).after( '<span class=\"description stripe-error-description\" style=\"color:red; display:block;\">" . __( 'This is not a valid live key. Live keys start with "sk_live_" and "pk_live_".', 'woocommerce-gateway-stripe' ) . "</span>' );
271
+						$( this ).css( 'border-color', 'red' ).after( '<span class=\"description stripe-error-description\" style=\"color:red; display:block;\">" . __('This is not a valid live key. Live keys start with "sk_live_" and "pk_live_".', 'woocommerce-gateway-stripe') . "</span>' );
272 272
 					} else {
273 273
 						$( this ).css( 'border-color', '' );
274 274
 						$( '.stripe-error-description', $( this ).parent() ).remove();
@@ -279,7 +279,7 @@  discard block
 block discarded – undo
279 279
 					var value = $( this ).val();
280 280
 
281 281
 					if ( value.indexOf( '_live_' ) >= 0 ) {
282
-						$( this ).css( 'border-color', 'red' ).after( '<span class=\"description stripe-error-description\" style=\"color:red; display:block;\">" . __( 'This is not a valid test key. Test keys start with "sk_test_" and "pk_test_".', 'woocommerce-gateway-stripe' ) . "</span>' );
282
+						$( this ).css( 'border-color', 'red' ).after( '<span class=\"description stripe-error-description\" style=\"color:red; display:block;\">" . __('This is not a valid test key. Test keys start with "sk_test_" and "pk_test_".', 'woocommerce-gateway-stripe') . "</span>' );
283 283
 					} else {
284 284
 						$( this ).css( 'border-color', '' );
285 285
 						$( '.stripe-error-description', $( this ).parent() ).remove();
@@ -294,46 +294,46 @@  discard block
 block discarded – undo
294 294
 	 */
295 295
 	public function payment_fields() {
296 296
 		$user                 = wp_get_current_user();
297
-		$display_tokenization = $this->supports( 'tokenization' ) && is_checkout() && $this->saved_cards;
297
+		$display_tokenization = $this->supports('tokenization') && is_checkout() && $this->saved_cards;
298 298
 
299
-		if ( $user->ID ) {
300
-			$user_email = get_user_meta( $user->ID, 'billing_email', true );
299
+		if ($user->ID) {
300
+			$user_email = get_user_meta($user->ID, 'billing_email', true);
301 301
 			$user_email = $user_email ? $user_email : $user->user_email;
302 302
 		} else {
303 303
 			$user_email = '';
304 304
 		}
305 305
 
306
-		if ( is_add_payment_method_page() ) {
307
-			$pay_button_text = __( 'Add Card', 'woocommerce-gateway-stripe' );
306
+		if (is_add_payment_method_page()) {
307
+			$pay_button_text = __('Add Card', 'woocommerce-gateway-stripe');
308 308
 		} else {
309 309
 			$pay_button_text = '';
310 310
 		}
311 311
 
312 312
 		echo '<div
313 313
 			id="stripe-payment-data"
314
-			data-panel-label="' . esc_attr( $pay_button_text ) . '"
314
+			data-panel-label="' . esc_attr($pay_button_text) . '"
315 315
 			data-description=""
316
-			data-email="' . esc_attr( $user_email ) . '"
317
-			data-amount="' . esc_attr( $this->get_stripe_amount( WC()->cart->total ) ) . '"
318
-			data-name="' . esc_attr( get_bloginfo( 'name', 'display' ) ) . '"
319
-			data-currency="' . esc_attr( strtolower( get_woocommerce_currency() ) ) . '"
320
-			data-image="' . esc_attr( $this->stripe_checkout_image ) . '"
321
-			data-bitcoin="' . esc_attr( $this->bitcoin ? 'true' : 'false' ) . '"
322
-			data-locale="' . esc_attr( $this->stripe_checkout_locale ? $this->stripe_checkout_locale : 'en' ) . '">';
316
+			data-email="' . esc_attr($user_email) . '"
317
+			data-amount="' . esc_attr($this->get_stripe_amount(WC()->cart->total)) . '"
318
+			data-name="' . esc_attr(get_bloginfo('name', 'display')) . '"
319
+			data-currency="' . esc_attr(strtolower(get_woocommerce_currency())) . '"
320
+			data-image="' . esc_attr($this->stripe_checkout_image) . '"
321
+			data-bitcoin="' . esc_attr($this->bitcoin ? 'true' : 'false') . '"
322
+			data-locale="' . esc_attr($this->stripe_checkout_locale ? $this->stripe_checkout_locale : 'en') . '">';
323 323
 
324
-		if ( $this->description ) {
325
-			echo apply_filters( 'wc_stripe_description', wpautop( wp_kses_post( $this->description ) ) );
324
+		if ($this->description) {
325
+			echo apply_filters('wc_stripe_description', wpautop(wp_kses_post($this->description)));
326 326
 		}
327 327
 
328
-		if ( $display_tokenization ) {
328
+		if ($display_tokenization) {
329 329
 			$this->tokenization_script();
330 330
 			$this->saved_payment_methods();
331 331
 		}
332 332
 
333
-		if ( ! $this->stripe_checkout ) {
333
+		if ( ! $this->stripe_checkout) {
334 334
 			$this->form();
335 335
 			
336
-			if ( $display_tokenization ) {
336
+			if ($display_tokenization) {
337 337
 				$this->save_payment_method_checkbox();
338 338
 			}
339 339
 		}
@@ -349,20 +349,20 @@  discard block
 block discarded – undo
349 349
 	 * @return array
350 350
 	 */
351 351
 	public function get_localized_messages() {
352
-		return apply_filters( 'wc_stripe_localized_messages', array(
353
-			'invalid_number'        => __( 'The card number is not a valid credit card number.', 'woocommerce-gateway-stripe' ),
354
-			'invalid_expiry_month'  => __( 'The card\'s expiration month is invalid.', 'woocommerce-gateway-stripe' ),
355
-			'invalid_expiry_year'   => __( 'The card\'s expiration year is invalid.', 'woocommerce-gateway-stripe' ),
356
-			'invalid_cvc'           => __( 'The card\'s security code is invalid.', 'woocommerce-gateway-stripe' ),
357
-			'incorrect_number'      => __( 'The card number is incorrect.', 'woocommerce-gateway-stripe' ),
358
-			'expired_card'          => __( 'The card has expired.', 'woocommerce-gateway-stripe' ),
359
-			'incorrect_cvc'         => __( 'The card\'s security code is incorrect.', 'woocommerce-gateway-stripe' ),
360
-			'incorrect_zip'         => __( 'The card\'s zip code failed validation.', 'woocommerce-gateway-stripe' ),
361
-			'card_declined'         => __( 'The card was declined.', 'woocommerce-gateway-stripe' ),
362
-			'missing'               => __( 'There is no card on a customer that is being charged.', 'woocommerce-gateway-stripe' ),
363
-			'processing_error'      => __( 'An error occurred while processing the card.', 'woocommerce-gateway-stripe' ),
364
-			'invalid_request_error' => __( 'Could not find payment information.', 'woocommerce-gateway-stripe' ),
365
-			) );
352
+		return apply_filters('wc_stripe_localized_messages', array(
353
+			'invalid_number'        => __('The card number is not a valid credit card number.', 'woocommerce-gateway-stripe'),
354
+			'invalid_expiry_month'  => __('The card\'s expiration month is invalid.', 'woocommerce-gateway-stripe'),
355
+			'invalid_expiry_year'   => __('The card\'s expiration year is invalid.', 'woocommerce-gateway-stripe'),
356
+			'invalid_cvc'           => __('The card\'s security code is invalid.', 'woocommerce-gateway-stripe'),
357
+			'incorrect_number'      => __('The card number is incorrect.', 'woocommerce-gateway-stripe'),
358
+			'expired_card'          => __('The card has expired.', 'woocommerce-gateway-stripe'),
359
+			'incorrect_cvc'         => __('The card\'s security code is incorrect.', 'woocommerce-gateway-stripe'),
360
+			'incorrect_zip'         => __('The card\'s zip code failed validation.', 'woocommerce-gateway-stripe'),
361
+			'card_declined'         => __('The card was declined.', 'woocommerce-gateway-stripe'),
362
+			'missing'               => __('There is no card on a customer that is being charged.', 'woocommerce-gateway-stripe'),
363
+			'processing_error'      => __('An error occurred while processing the card.', 'woocommerce-gateway-stripe'),
364
+			'invalid_request_error' => __('Could not find payment information.', 'woocommerce-gateway-stripe'),
365
+			));
366 366
 	}
367 367
 
368 368
 	/**
@@ -373,30 +373,30 @@  discard block
 block discarded – undo
373 373
 	 * @access public
374 374
 	 */
375 375
 	public function payment_scripts() {
376
-		if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) ) {
376
+		if ( ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order'])) {
377 377
 			return;
378 378
 		}
379 379
 
380
-		$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
380
+		$suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';
381 381
 		
382
-		if ( $this->stripe_checkout ) {
383
-			wp_enqueue_script( 'stripe_checkout', 'https://checkout.stripe.com/v2/checkout.js', '', '2.0', true );
384
-			wp_enqueue_script( 'woocommerce_stripe', plugins_url( 'assets/js/stripe_checkout' . $suffix . '.js', WC_STRIPE_MAIN_FILE ), array( 'stripe' ), WC_STRIPE_VERSION, true );
382
+		if ($this->stripe_checkout) {
383
+			wp_enqueue_script('stripe_checkout', 'https://checkout.stripe.com/v2/checkout.js', '', '2.0', true);
384
+			wp_enqueue_script('woocommerce_stripe', plugins_url('assets/js/stripe_checkout' . $suffix . '.js', WC_STRIPE_MAIN_FILE), array('stripe'), WC_STRIPE_VERSION, true);
385 385
 		} else {
386
-			wp_enqueue_script( 'stripe', 'https://js.stripe.com/v2/', '', '1.0', true );
387
-			wp_enqueue_script( 'woocommerce_stripe', plugins_url( 'assets/js/stripe' . $suffix . '.js', WC_STRIPE_MAIN_FILE ), array( 'jquery-payment', 'stripe' ), WC_STRIPE_VERSION, true );
386
+			wp_enqueue_script('stripe', 'https://js.stripe.com/v2/', '', '1.0', true);
387
+			wp_enqueue_script('woocommerce_stripe', plugins_url('assets/js/stripe' . $suffix . '.js', WC_STRIPE_MAIN_FILE), array('jquery-payment', 'stripe'), WC_STRIPE_VERSION, true);
388 388
 		}
389 389
 
390 390
 		$stripe_params = array(
391 391
 			'key'                  => $this->publishable_key,
392
-			'i18n_terms'           => __( 'Please accept the terms and conditions first', 'woocommerce-gateway-stripe' ),
393
-			'i18n_required_fields' => __( 'Please fill in required checkout fields first', 'woocommerce-gateway-stripe' ),
392
+			'i18n_terms'           => __('Please accept the terms and conditions first', 'woocommerce-gateway-stripe'),
393
+			'i18n_required_fields' => __('Please fill in required checkout fields first', 'woocommerce-gateway-stripe'),
394 394
 		);
395 395
 
396 396
 		// If we're on the pay page we need to pass stripe.js the address of the order.
397
-		if ( isset( $_GET['pay_for_order'] ) && 'true' === $_GET['pay_for_order'] ) {
398
-			$order_id = wc_get_order_id_by_order_key( urldecode( $_GET['key'] ) );
399
-			$order    = wc_get_order( $order_id );
397
+		if (isset($_GET['pay_for_order']) && 'true' === $_GET['pay_for_order']) {
398
+			$order_id = wc_get_order_id_by_order_key(urldecode($_GET['key']));
399
+			$order    = wc_get_order($order_id);
400 400
 
401 401
 			$stripe_params['billing_first_name'] = $order->billing_first_name;
402 402
 			$stripe_params['billing_last_name']  = $order->billing_last_name;
@@ -408,14 +408,14 @@  discard block
 block discarded – undo
408 408
 			$stripe_params['billing_country']    = $order->billing_country;
409 409
 		}
410 410
 
411
-		$stripe_params['no_prepaid_card_msg']                     = __( 'Sorry, we\'re not accepting prepaid cards at this time.', 'woocommerce-gateway-stripe' );
412
-		$stripe_params['allow_prepaid_card']                      = apply_filters( 'wc_stripe_allow_prepaid_card', true ) ? 'yes' : 'no';
413
-		$stripe_params['stripe_checkout_require_billing_address'] = apply_filters( 'wc_stripe_checkout_require_billing_address', false ) ? 'yes' : 'no';
411
+		$stripe_params['no_prepaid_card_msg']                     = __('Sorry, we\'re not accepting prepaid cards at this time.', 'woocommerce-gateway-stripe');
412
+		$stripe_params['allow_prepaid_card']                      = apply_filters('wc_stripe_allow_prepaid_card', true) ? 'yes' : 'no';
413
+		$stripe_params['stripe_checkout_require_billing_address'] = apply_filters('wc_stripe_checkout_require_billing_address', false) ? 'yes' : 'no';
414 414
 
415 415
 		// merge localized messages to be use in JS
416
-		$stripe_params = array_merge( $stripe_params, $this->get_localized_messages() );
416
+		$stripe_params = array_merge($stripe_params, $this->get_localized_messages());
417 417
 
418
-		wp_localize_script( 'woocommerce_stripe', 'wc_stripe_params', apply_filters( 'wc_stripe_params', $stripe_params ) );
418
+		wp_localize_script('woocommerce_stripe', 'wc_stripe_params', apply_filters('wc_stripe_params', $stripe_params));
419 419
 	}
420 420
 
421 421
 	/**
@@ -424,24 +424,24 @@  discard block
 block discarded – undo
424 424
 	 * @param  object $source
425 425
 	 * @return array()
426 426
 	 */
427
-	protected function generate_payment_request( $order, $source ) {
427
+	protected function generate_payment_request($order, $source) {
428 428
 		$post_data                = array();
429
-		$post_data['currency']    = strtolower( $order->get_order_currency() ? $order->get_order_currency() : get_woocommerce_currency() );
430
-		$post_data['amount']      = $this->get_stripe_amount( $order->get_total(), $post_data['currency'] );
431
-		$post_data['description'] = sprintf( __( '%s - Order %s', 'woocommerce-gateway-stripe' ), wp_specialchars_decode( get_bloginfo( 'name' ), ENT_QUOTES ), $order->get_order_number() );
429
+		$post_data['currency']    = strtolower($order->get_order_currency() ? $order->get_order_currency() : get_woocommerce_currency());
430
+		$post_data['amount']      = $this->get_stripe_amount($order->get_total(), $post_data['currency']);
431
+		$post_data['description'] = sprintf(__('%s - Order %s', 'woocommerce-gateway-stripe'), wp_specialchars_decode(get_bloginfo('name'), ENT_QUOTES), $order->get_order_number());
432 432
 		$post_data['capture']     = $this->capture ? 'true' : 'false';
433 433
 
434
-		if ( ! empty( $order->billing_email ) && apply_filters( 'wc_stripe_send_stripe_receipt', false ) ) {
434
+		if ( ! empty($order->billing_email) && apply_filters('wc_stripe_send_stripe_receipt', false)) {
435 435
 			$post_data['receipt_email'] = $order->billing_email;
436 436
 		}
437 437
 
438
-		$post_data['expand[]']    = 'balance_transaction';
438
+		$post_data['expand[]'] = 'balance_transaction';
439 439
 
440
-		if ( $source->customer ) {
440
+		if ($source->customer) {
441 441
 			$post_data['customer'] = $source->customer;
442 442
 		}
443 443
 
444
-		if ( $source->source ) {
444
+		if ($source->source) {
445 445
 			$post_data['source'] = $source->source;
446 446
 		}
447 447
 		
@@ -453,7 +453,7 @@  discard block
 block discarded – undo
453 453
 		 * @param WC_Order $order
454 454
 		 * @param object $source
455 455
 		 */
456
-		return apply_filters( 'wc_stripe_generate_payment_request', $post_data, $order, $source );
456
+		return apply_filters('wc_stripe_generate_payment_request', $post_data, $order, $source);
457 457
 	}
458 458
 
459 459
 	/**
@@ -465,22 +465,22 @@  discard block
 block discarded – undo
465 465
 	 * @throws Exception When card was not added or for and invalid card.
466 466
 	 * @return object
467 467
 	 */
468
-	protected function get_source( $user_id, $force_customer = false ) {
469
-		$stripe_customer = new WC_Stripe_Customer( $user_id );
468
+	protected function get_source($user_id, $force_customer = false) {
469
+		$stripe_customer = new WC_Stripe_Customer($user_id);
470 470
 		$stripe_source   = false;
471 471
 		$token_id        = false;
472 472
 
473 473
 		// New CC info was entered and we have a new token to process
474
-		if ( isset( $_POST['stripe_token'] ) ) {
475
-			$stripe_token     = wc_clean( $_POST['stripe_token'] );
476
-			$maybe_saved_card = isset( $_POST['wc-stripe-new-payment-method'] ) && ! empty( $_POST['wc-stripe-new-payment-method'] );
474
+		if (isset($_POST['stripe_token'])) {
475
+			$stripe_token     = wc_clean($_POST['stripe_token']);
476
+			$maybe_saved_card = isset($_POST['wc-stripe-new-payment-method']) && ! empty($_POST['wc-stripe-new-payment-method']);
477 477
 
478 478
 			// This is true if the user wants to store the card to their account.
479
-			if ( ( $user_id && $this->saved_cards && $maybe_saved_card ) || $force_customer ) {
480
-				$stripe_source = $stripe_customer->add_card( $stripe_token );
479
+			if (($user_id && $this->saved_cards && $maybe_saved_card) || $force_customer) {
480
+				$stripe_source = $stripe_customer->add_card($stripe_token);
481 481
 
482
-				if ( is_wp_error( $stripe_source ) ) {
483
-					throw new Exception( $stripe_source->get_error_message() );
482
+				if (is_wp_error($stripe_source)) {
483
+					throw new Exception($stripe_source->get_error_message());
484 484
 				}
485 485
 
486 486
 			} else {
@@ -491,13 +491,13 @@  discard block
 block discarded – undo
491 491
 		}
492 492
 
493 493
 		// Use an existing token, and then process the payment
494
-		elseif ( isset( $_POST['wc-stripe-payment-token'] ) && 'new' !== $_POST['wc-stripe-payment-token'] ) {
495
-			$token_id = wc_clean( $_POST['wc-stripe-payment-token'] );
496
-			$token    = WC_Payment_Tokens::get( $token_id );
494
+		elseif (isset($_POST['wc-stripe-payment-token']) && 'new' !== $_POST['wc-stripe-payment-token']) {
495
+			$token_id = wc_clean($_POST['wc-stripe-payment-token']);
496
+			$token    = WC_Payment_Tokens::get($token_id);
497 497
 
498
-			if ( ! $token || $token->get_user_id() !== get_current_user_id() ) {
499
-				WC()->session->set( 'refresh_totals', true );
500
-				throw new Exception( __( 'Invalid payment method. Please input a new card number.', 'woocommerce-gateway-stripe' ) );
498
+			if ( ! $token || $token->get_user_id() !== get_current_user_id()) {
499
+				WC()->session->set('refresh_totals', true);
500
+				throw new Exception(__('Invalid payment method. Please input a new card number.', 'woocommerce-gateway-stripe'));
501 501
 			}
502 502
 
503 503
 			$stripe_source = $token->get_token();
@@ -521,16 +521,16 @@  discard block
 block discarded – undo
521 521
 	 * @param object $order
522 522
 	 * @return object
523 523
 	 */
524
-	protected function get_order_source( $order = null ) {
524
+	protected function get_order_source($order = null) {
525 525
 		$stripe_customer = new WC_Stripe_Customer();
526 526
 		$stripe_source   = false;
527 527
 		$token_id        = false;
528 528
 
529
-		if ( $order ) {
530
-			if ( $meta_value = get_post_meta( $order->id, '_stripe_customer_id', true ) ) {
531
-				$stripe_customer->set_id( $meta_value );
529
+		if ($order) {
530
+			if ($meta_value = get_post_meta($order->id, '_stripe_customer_id', true)) {
531
+				$stripe_customer->set_id($meta_value);
532 532
 			}
533
-			if ( $meta_value = get_post_meta( $order->id, '_stripe_card_id', true ) ) {
533
+			if ($meta_value = get_post_meta($order->id, '_stripe_card_id', true)) {
534 534
 				$stripe_source = $meta_value;
535 535
 			}
536 536
 		}
@@ -553,50 +553,50 @@  discard block
 block discarded – undo
553 553
 	 *
554 554
 	 * @return array|void
555 555
 	 */
556
-	public function process_payment( $order_id, $retry = true, $force_customer = false ) {
556
+	public function process_payment($order_id, $retry = true, $force_customer = false) {
557 557
 		try {
558
-			$order  = wc_get_order( $order_id );
559
-			$source = $this->get_source( get_current_user_id(), $force_customer );
558
+			$order  = wc_get_order($order_id);
559
+			$source = $this->get_source(get_current_user_id(), $force_customer);
560 560
 
561
-			if ( empty( $source->source ) && empty( $source->customer ) ) {
562
-				$error_msg = __( 'Please enter your card details to make a payment.', 'woocommerce-gateway-stripe' );
563
-				$error_msg .= ' ' . __( 'Developers: Please make sure that you are including jQuery and there are no JavaScript errors on the page.', 'woocommerce-gateway-stripe' );
564
-				throw new Exception( $error_msg );
561
+			if (empty($source->source) && empty($source->customer)) {
562
+				$error_msg = __('Please enter your card details to make a payment.', 'woocommerce-gateway-stripe');
563
+				$error_msg .= ' ' . __('Developers: Please make sure that you are including jQuery and there are no JavaScript errors on the page.', 'woocommerce-gateway-stripe');
564
+				throw new Exception($error_msg);
565 565
 			}
566 566
 
567 567
 			// Store source to order meta.
568
-			$this->save_source( $order, $source );
568
+			$this->save_source($order, $source);
569 569
 
570 570
 			// Handle payment.
571
-			if ( $order->get_total() > 0 ) {
571
+			if ($order->get_total() > 0) {
572 572
 
573
-				if ( $order->get_total() * 100 < 50 ) {
574
-					throw new Exception( __( 'Sorry, the minimum allowed order total is 0.50 to use this payment method.', 'woocommerce-gateway-stripe' ) );
573
+				if ($order->get_total() * 100 < 50) {
574
+					throw new Exception(__('Sorry, the minimum allowed order total is 0.50 to use this payment method.', 'woocommerce-gateway-stripe'));
575 575
 				}
576 576
 
577
-				WC_Stripe::log( "Info: Begin processing payment for order $order_id for the amount of {$order->get_total()}" );
577
+				WC_Stripe::log("Info: Begin processing payment for order $order_id for the amount of {$order->get_total()}");
578 578
 
579 579
 				// Make the request.
580
-				$response = WC_Stripe_API::request( $this->generate_payment_request( $order, $source ) );
580
+				$response = WC_Stripe_API::request($this->generate_payment_request($order, $source));
581 581
 
582
-				if ( is_wp_error( $response ) ) {
582
+				if (is_wp_error($response)) {
583 583
 					// Customer param wrong? The user may have been deleted on stripe's end. Remove customer_id. Can be retried without.
584
-					if ( 'customer' === $response->get_error_code() && $retry ) {
585
-						delete_user_meta( get_current_user_id(), '_stripe_customer_id' );
586
-						return $this->process_payment( $order_id, false, $force_customer );
584
+					if ('customer' === $response->get_error_code() && $retry) {
585
+						delete_user_meta(get_current_user_id(), '_stripe_customer_id');
586
+						return $this->process_payment($order_id, false, $force_customer);
587 587
 						// Source param wrong? The CARD may have been deleted on stripe's end. Remove token and show message.
588
-					} elseif ( 'source' === $response->get_error_code() && $source->token_id ) {
589
-						$token = WC_Payment_Tokens::get( $source->token_id );
588
+					} elseif ('source' === $response->get_error_code() && $source->token_id) {
589
+						$token = WC_Payment_Tokens::get($source->token_id);
590 590
 						$token->delete();
591
-						throw new Exception( __( 'This card is no longer available and has been removed.', 'woocommerce-gateway-stripe' ) );
591
+						throw new Exception(__('This card is no longer available and has been removed.', 'woocommerce-gateway-stripe'));
592 592
 					}
593 593
 					$localized_messages = $this->get_localized_messages();
594 594
 
595
-					throw new Exception( ( isset( $localized_messages[ $response->get_error_code() ] ) ? $localized_messages[ $response->get_error_code() ] : $response->get_error_message() ) );
595
+					throw new Exception((isset($localized_messages[$response->get_error_code()]) ? $localized_messages[$response->get_error_code()] : $response->get_error_message()));
596 596
 				}
597 597
 
598 598
 				// Process valid response.
599
-				$this->process_response( $response, $order );
599
+				$this->process_response($response, $order);
600 600
 			} else {
601 601
 				$order->payment_complete();
602 602
 			}
@@ -604,23 +604,23 @@  discard block
 block discarded – undo
604 604
 			// Remove cart.
605 605
 			WC()->cart->empty_cart();
606 606
 
607
-			do_action( 'wc_gateway_stripe_process_payment', $response, $order );
607
+			do_action('wc_gateway_stripe_process_payment', $response, $order);
608 608
 
609 609
 			// Return thank you page redirect.
610 610
 			return array(
611 611
 				'result'   => 'success',
612
-				'redirect' => $this->get_return_url( $order )
612
+				'redirect' => $this->get_return_url($order)
613 613
 			);
614 614
 
615
-		} catch ( Exception $e ) {
616
-			wc_add_notice( $e->getMessage(), 'error' );
617
-			WC_Stripe::log( sprintf( __( 'Error: %s', 'woocommerce-gateway-stripe' ), $e->getMessage() ) );
615
+		} catch (Exception $e) {
616
+			wc_add_notice($e->getMessage(), 'error');
617
+			WC_Stripe::log(sprintf(__('Error: %s', 'woocommerce-gateway-stripe'), $e->getMessage()));
618 618
 
619
-			if ( $order->has_status( array( 'pending', 'failed' ) ) ) {
620
-				$this->send_failed_order_email( $order_id );
619
+			if ($order->has_status(array('pending', 'failed'))) {
620
+				$this->send_failed_order_email($order_id);
621 621
 			}
622 622
 
623
-			do_action( 'wc_gateway_stripe_process_payment_error', $e, $order );
623
+			do_action('wc_gateway_stripe_process_payment_error', $e, $order);
624 624
 
625 625
 			return array(
626 626
 				'result'   => 'fail',
@@ -635,52 +635,52 @@  discard block
 block discarded – undo
635 635
 	 * @param WC_Order $order For to which the source applies.
636 636
 	 * @param stdClass $source Source information.
637 637
 	 */
638
-	protected function save_source( $order, $source ) {
638
+	protected function save_source($order, $source) {
639 639
 		// Store source in the order.
640
-		if ( $source->customer ) {
641
-			update_post_meta( $order->id, '_stripe_customer_id', $source->customer );
640
+		if ($source->customer) {
641
+			update_post_meta($order->id, '_stripe_customer_id', $source->customer);
642 642
 		}
643
-		if ( $source->source ) {
644
-			update_post_meta( $order->id, '_stripe_card_id', $source->source );
643
+		if ($source->source) {
644
+			update_post_meta($order->id, '_stripe_card_id', $source->source);
645 645
 		}
646 646
 	}
647 647
 
648 648
 	/**
649 649
 	 * Store extra meta data for an order from a Stripe Response.
650 650
 	 */
651
-	public function process_response( $response, $order ) {
652
-		WC_Stripe::log( "Processing response: " . print_r( $response, true ) );
651
+	public function process_response($response, $order) {
652
+		WC_Stripe::log("Processing response: " . print_r($response, true));
653 653
 
654 654
 		// Store charge data
655
-		update_post_meta( $order->id, '_stripe_charge_id', $response->id );
656
-		update_post_meta( $order->id, '_stripe_charge_captured', $response->captured ? 'yes' : 'no' );
655
+		update_post_meta($order->id, '_stripe_charge_id', $response->id);
656
+		update_post_meta($order->id, '_stripe_charge_captured', $response->captured ? 'yes' : 'no');
657 657
 
658 658
 		// Store other data such as fees
659
-		if ( isset( $response->balance_transaction ) && isset( $response->balance_transaction->fee ) ) {
659
+		if (isset($response->balance_transaction) && isset($response->balance_transaction->fee)) {
660 660
 			// Fees and Net needs to both come from Stripe to be accurate as the returned
661 661
 			// values are in the local currency of the Stripe account, not from WC.
662
-			$fee = ! empty( $response->balance_transaction->fee ) ? number_format( $response->balance_transaction->fee / 100, 2, '.', '' ) : 0;
663
-			$net = ! empty( $response->balance_transaction->net ) ? number_format( $response->balance_transaction->net / 100, 2, '.', '' ) : 0;
664
-			update_post_meta( $order->id, 'Stripe Fee', $fee );
665
-			update_post_meta( $order->id, 'Net Revenue From Stripe', $net );
662
+			$fee = ! empty($response->balance_transaction->fee) ? number_format($response->balance_transaction->fee / 100, 2, '.', '') : 0;
663
+			$net = ! empty($response->balance_transaction->net) ? number_format($response->balance_transaction->net / 100, 2, '.', '') : 0;
664
+			update_post_meta($order->id, 'Stripe Fee', $fee);
665
+			update_post_meta($order->id, 'Net Revenue From Stripe', $net);
666 666
 		}
667 667
 
668
-		if ( $response->captured ) {
669
-			$order->payment_complete( $response->id );
668
+		if ($response->captured) {
669
+			$order->payment_complete($response->id);
670 670
 
671
-			$message = sprintf( __( 'Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe' ), $response->id );
672
-			$order->add_order_note( $message );
673
-			WC_Stripe::log( 'Success: ' . $message );
671
+			$message = sprintf(__('Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe'), $response->id);
672
+			$order->add_order_note($message);
673
+			WC_Stripe::log('Success: ' . $message);
674 674
 
675 675
 		} else {
676
-			add_post_meta( $order->id, '_transaction_id', $response->id, true );
676
+			add_post_meta($order->id, '_transaction_id', $response->id, true);
677 677
 
678
-			if ( $order->has_status( array( 'pending', 'failed' ) ) ) {
678
+			if ($order->has_status(array('pending', 'failed'))) {
679 679
 				$order->reduce_order_stock();
680 680
 			}
681 681
 
682
-			$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 ) );
683
-			WC_Stripe::log( "Successful auth: $response->id" );
682
+			$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));
683
+			WC_Stripe::log("Successful auth: $response->id");
684 684
 		}
685 685
 
686 686
 		return $response;
@@ -692,32 +692,32 @@  discard block
 block discarded – undo
692 692
 	 * @since 3.0.0
693 693
 	 */
694 694
 	public function add_payment_method() {
695
-		if ( empty( $_POST['stripe_token'] ) || ! is_user_logged_in() ) {
696
-			wc_add_notice( __( 'There was a problem adding the card.', 'woocommerce-gateway-stripe' ), 'error' );
695
+		if (empty($_POST['stripe_token']) || ! is_user_logged_in()) {
696
+			wc_add_notice(__('There was a problem adding the card.', 'woocommerce-gateway-stripe'), 'error');
697 697
 			return;
698 698
 		}
699 699
 
700
-		$stripe_customer = new WC_Stripe_Customer( get_current_user_id() );
701
-		$card            = $stripe_customer->add_card( wc_clean( $_POST['stripe_token'] ) );
700
+		$stripe_customer = new WC_Stripe_Customer(get_current_user_id());
701
+		$card            = $stripe_customer->add_card(wc_clean($_POST['stripe_token']));
702 702
 
703
-		if ( is_wp_error( $card ) ) {
703
+		if (is_wp_error($card)) {
704 704
 			$localized_messages = $this->get_localized_messages();
705
-			$error_msg = __( 'There was a problem adding the card.', 'woocommerce-gateway-stripe' );
705
+			$error_msg = __('There was a problem adding the card.', 'woocommerce-gateway-stripe');
706 706
 
707 707
 			// loop through the errors to find matching localized message
708
-			foreach ( $card->errors as $error => $msg ) {
709
-				if ( isset( $localized_messages[ $error ] ) ) {
710
-					$error_msg = $localized_messages[ $error ];
708
+			foreach ($card->errors as $error => $msg) {
709
+				if (isset($localized_messages[$error])) {
710
+					$error_msg = $localized_messages[$error];
711 711
 				}
712 712
 			}
713 713
 
714
-			wc_add_notice( $error_msg, 'error' );
714
+			wc_add_notice($error_msg, 'error');
715 715
 			return;
716 716
 		}
717 717
 
718 718
 		return array(
719 719
 			'result'   => 'success',
720
-			'redirect' => wc_get_endpoint_url( 'payment-methods' ),
720
+			'redirect' => wc_get_endpoint_url('payment-methods'),
721 721
 		);
722 722
 	}
723 723
 
@@ -727,36 +727,36 @@  discard block
 block discarded – undo
727 727
 	 * @param  float $amount
728 728
 	 * @return bool
729 729
 	 */
730
-	public function process_refund( $order_id, $amount = null, $reason = '' ) {
731
-		$order = wc_get_order( $order_id );
730
+	public function process_refund($order_id, $amount = null, $reason = '') {
731
+		$order = wc_get_order($order_id);
732 732
 
733
-		if ( ! $order || ! $order->get_transaction_id() ) {
733
+		if ( ! $order || ! $order->get_transaction_id()) {
734 734
 			return false;
735 735
 		}
736 736
 
737 737
 		$body = array();
738 738
 
739
-		if ( ! is_null( $amount ) ) {
740
-			$body['amount']	= $this->get_stripe_amount( $amount );
739
+		if ( ! is_null($amount)) {
740
+			$body['amount'] = $this->get_stripe_amount($amount);
741 741
 		}
742 742
 
743
-		if ( $reason ) {
743
+		if ($reason) {
744 744
 			$body['metadata'] = array(
745 745
 				'reason'	=> $reason,
746 746
 			);
747 747
 		}
748 748
 
749
-		WC_Stripe::log( "Info: Beginning refund for order $order_id for the amount of {$amount}" );
749
+		WC_Stripe::log("Info: Beginning refund for order $order_id for the amount of {$amount}");
750 750
 
751
-		$response = WC_Stripe_API::request( $body, 'charges/' . $order->get_transaction_id() . '/refunds' );
751
+		$response = WC_Stripe_API::request($body, 'charges/' . $order->get_transaction_id() . '/refunds');
752 752
 
753
-		if ( is_wp_error( $response ) ) {
754
-			WC_Stripe::log( "Error: " . $response->get_error_message() );
753
+		if (is_wp_error($response)) {
754
+			WC_Stripe::log("Error: " . $response->get_error_message());
755 755
 			return $response;
756
-		} elseif ( ! empty( $response->id ) ) {
757
-			$refund_message = sprintf( __( 'Refunded %s - Refund ID: %s - Reason: %s', 'woocommerce-gateway-stripe' ), wc_price( $response->amount / 100 ), $response->id, $reason );
758
-			$order->add_order_note( $refund_message );
759
-			WC_Stripe::log( "Success: " . html_entity_decode( strip_tags( $refund_message ) ) );
756
+		} elseif ( ! empty($response->id)) {
757
+			$refund_message = sprintf(__('Refunded %s - Refund ID: %s - Reason: %s', 'woocommerce-gateway-stripe'), wc_price($response->amount / 100), $response->id, $reason);
758
+			$order->add_order_note($refund_message);
759
+			WC_Stripe::log("Success: " . html_entity_decode(strip_tags($refund_message)));
760 760
 			return true;
761 761
 		}
762 762
 	}
@@ -769,10 +769,10 @@  discard block
 block discarded – undo
769 769
 	 * @param int $order_id
770 770
 	 * @return null
771 771
 	 */
772
-	public function send_failed_order_email( $order_id ) {
772
+	public function send_failed_order_email($order_id) {
773 773
 		$emails = WC()->mailer()->get_emails();
774
-		if ( ! empty( $emails ) && ! empty( $order_id ) ) {
775
-			$emails['WC_Email_Failed_Order']->trigger( $order_id );
774
+		if ( ! empty($emails) && ! empty($order_id)) {
775
+			$emails['WC_Email_Failed_Order']->trigger($order_id);
776 776
 		}
777 777
 	}
778 778
 }
Please login to merge, or discard this patch.
includes/class-wc-stripe-apple-pay.php 1 patch
Spacing   +122 added lines, -122 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
 
@@ -40,7 +40,7 @@  discard block
 block discarded – undo
40 40
 	public function __construct() {
41 41
 		self::$_this = $this;
42 42
 
43
-		$this->_gateway_settings = get_option( 'woocommerce_stripe_settings', '' );
43
+		$this->_gateway_settings = get_option('woocommerce_stripe_settings', '');
44 44
 
45 45
 		$this->init();
46 46
 	}
@@ -57,15 +57,15 @@  discard block
 block discarded – undo
57 57
 	 * @version 3.1.0
58 58
 	 */
59 59
 	public function init() {
60
-		add_action( 'wp_enqueue_scripts', array( $this, 'payment_scripts' ) );
61
-		add_action( 'woocommerce_proceed_to_checkout', array( $this, 'display_apple_pay_button' ), 20 );
62
-		add_action( 'woocommerce_review_order_before_payment', array( $this, 'display_apple_pay_button' ) );
60
+		add_action('wp_enqueue_scripts', array($this, 'payment_scripts'));
61
+		add_action('woocommerce_proceed_to_checkout', array($this, 'display_apple_pay_button'), 20);
62
+		add_action('woocommerce_review_order_before_payment', array($this, 'display_apple_pay_button'));
63 63
 		
64
-		if ( is_admin() ) {
65
-			add_action( 'wp_ajax_wc_stripe_apple_pay', array( $this, 'process_apple_pay' ) );
66
-			add_action( 'wp_ajax_nopriv_wc_stripe_apple_pay', array( $this, 'process_apple_pay' ) );
67
-			add_action( 'wp_ajax_wc_stripe_generate_apple_pay_cart', array( $this, 'generate_apple_pay_cart' ) );
68
-			add_action( 'wp_ajax_nopriv_wc_stripe_generate_apple_pay_cart', array( $this, 'generate_apple_pay_cart' ) );
64
+		if (is_admin()) {
65
+			add_action('wp_ajax_wc_stripe_apple_pay', array($this, 'process_apple_pay'));
66
+			add_action('wp_ajax_nopriv_wc_stripe_apple_pay', array($this, 'process_apple_pay'));
67
+			add_action('wp_ajax_wc_stripe_generate_apple_pay_cart', array($this, 'generate_apple_pay_cart'));
68
+			add_action('wp_ajax_nopriv_wc_stripe_generate_apple_pay_cart', array($this, 'generate_apple_pay_cart'));
69 69
 		}
70 70
 	}
71 71
 
@@ -76,38 +76,38 @@  discard block
 block discarded – undo
76 76
 	 * @version 3.1.0
77 77
 	 */
78 78
 	public function payment_scripts() {
79
-		if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) ) {
79
+		if ( ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order'])) {
80 80
 			return;
81 81
 		}
82 82
 
83
-		if ( ! $this->is_supported_product_type() ) {
83
+		if ( ! $this->is_supported_product_type()) {
84 84
 			return;
85 85
 		}
86 86
 		
87
-		$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
87
+		$suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';
88 88
 		
89
-		wp_enqueue_style( 'stripe_apple_pay', plugins_url( 'assets/css/stripe-apple-pay.css', WC_STRIPE_MAIN_FILE ), array(), WC_STRIPE_VERSION );
89
+		wp_enqueue_style('stripe_apple_pay', plugins_url('assets/css/stripe-apple-pay.css', WC_STRIPE_MAIN_FILE), array(), WC_STRIPE_VERSION);
90 90
 
91
-		wp_enqueue_script( 'stripe', 'https://js.stripe.com/v2/', '', '1.0', true );
92
-		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 );
91
+		wp_enqueue_script('stripe', 'https://js.stripe.com/v2/', '', '1.0', true);
92
+		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);
93 93
 
94 94
 		$publishable_key = 'yes' === $this->_gateway_settings['testmode'] ? $this->_gateway_settings['test_publishable_key'] : $this->_gateway_settings['publishable_key'];
95 95
 
96 96
 		$stripe_params = array(
97 97
 			'key'                         => $publishable_key,
98 98
 			'currency_code'               => get_woocommerce_currency(),
99
-			'country_code'                => substr( get_option( 'woocommerce_default_country' ), 0, 2 ),
100
-			'label'                       => get_bloginfo( 'name', 'display' ),
101
-			'ajaxurl'                     => admin_url( 'admin-ajax.php' ),
102
-			'stripe_apple_pay_nonce'      => wp_create_nonce( '_wc_stripe_apple_pay_nonce' ),
103
-			'stripe_apple_pay_cart_nonce' => wp_create_nonce( '_wc_stripe_apple_pay_cart_nonce' ),
99
+			'country_code'                => substr(get_option('woocommerce_default_country'), 0, 2),
100
+			'label'                       => get_bloginfo('name', 'display'),
101
+			'ajaxurl'                     => admin_url('admin-ajax.php'),
102
+			'stripe_apple_pay_nonce'      => wp_create_nonce('_wc_stripe_apple_pay_nonce'),
103
+			'stripe_apple_pay_cart_nonce' => wp_create_nonce('_wc_stripe_apple_pay_cart_nonce'),
104 104
 			'needs_shipping'              => WC()->cart->needs_shipping() ? 'yes' : 'no',
105
-			'needs_shipping_msg'          => __( 'Please first calculate your shipping.', 'woocommerce-gateway-stripe' ),
105
+			'needs_shipping_msg'          => __('Please first calculate your shipping.', 'woocommerce-gateway-stripe'),
106 106
 			'is_cart_page'                => is_cart() ? 'yes' : 'no',
107 107
 			'chosen_shipping'             => wc_get_chosen_shipping_method_ids(),
108 108
 		);
109 109
 
110
-		wp_localize_script( 'woocommerce_stripe_apple_pay', 'wc_stripe_apple_pay_params', apply_filters( 'wc_stripe_apple_pay_params', $stripe_params ) );
110
+		wp_localize_script('woocommerce_stripe_apple_pay', 'wc_stripe_apple_pay_params', apply_filters('wc_stripe_apple_pay_params', $stripe_params));
111 111
 	}
112 112
 		
113 113
 	/**
@@ -115,8 +115,8 @@  discard block
 block discarded – undo
115 115
 	 *
116 116
 	 */
117 117
 	public function is_supported_product_type() {
118
-		foreach( WC()->cart->get_cart() as $cart_item_key => $values ) {
119
-			if ( 'subscription' === $values['data']->product_type ) {
118
+		foreach (WC()->cart->get_cart() as $cart_item_key => $values) {
119
+			if ('subscription' === $values['data']->product_type) {
120 120
 				return false;
121 121
 			}
122 122
 		}
@@ -139,12 +139,12 @@  discard block
 block discarded – undo
139 139
 		 */
140 140
 		if ( 
141 141
 			'yes' !== $this->_gateway_settings['apple_pay']
142
-			|| ! isset( $gateways['stripe'] ) 
142
+			|| ! isset($gateways['stripe']) 
143 143
 		) {
144 144
 			return;
145 145
 		}
146 146
 
147
-		if ( ! $this->is_supported_product_type() ) {
147
+		if ( ! $this->is_supported_product_type()) {
148 148
 			return;
149 149
 		}
150 150
 		?>
@@ -159,15 +159,15 @@  discard block
 block discarded – undo
159 159
 	 * @version 3.1.0
160 160
 	 */
161 161
 	public function generate_apple_pay_cart() {
162
-		if ( ! defined( 'DOING_AJAX' ) ) {
163
-			define( 'DOING_AJAX', true );
162
+		if ( ! defined('DOING_AJAX')) {
163
+			define('DOING_AJAX', true);
164 164
 		}
165 165
 
166
-		if ( ! wp_verify_nonce( $_POST['nonce'], '_wc_stripe_apple_pay_cart_nonce' ) ) {
167
-			wp_die( __( 'Cheatin&#8217; huh?', 'woocommerce-gateway-stripe' ) );
166
+		if ( ! wp_verify_nonce($_POST['nonce'], '_wc_stripe_apple_pay_cart_nonce')) {
167
+			wp_die(__('Cheatin&#8217; huh?', 'woocommerce-gateway-stripe'));
168 168
 		}
169 169
 
170
-		wp_send_json( array( 'line_items' => $this->build_line_items(), 'total' => WC()->cart->total, 'chosen_shipping' => wc_get_chosen_shipping_method_ids() ) );
170
+		wp_send_json(array('line_items' => $this->build_line_items(), 'total' => WC()->cart->total, 'chosen_shipping' => wc_get_chosen_shipping_method_ids()));
171 171
 	}
172 172
 
173 173
 	/**
@@ -178,39 +178,39 @@  discard block
 block discarded – undo
178 178
 	 * @version 3.1.0
179 179
 	 */
180 180
 	public function process_apple_pay() {
181
-		if ( ! defined( 'DOING_AJAX' ) ) {
182
-			define( 'DOING_AJAX', true );
181
+		if ( ! defined('DOING_AJAX')) {
182
+			define('DOING_AJAX', true);
183 183
 		}
184 184
 
185
-		if ( ! wp_verify_nonce( $_POST['nonce'], '_wc_stripe_apple_pay_nonce' ) ) {
186
-			wp_die( __( 'Cheatin&#8217; huh?', 'woocommerce-gateway-stripe' ) );
185
+		if ( ! wp_verify_nonce($_POST['nonce'], '_wc_stripe_apple_pay_nonce')) {
186
+			wp_die(__('Cheatin&#8217; huh?', 'woocommerce-gateway-stripe'));
187 187
 		}
188 188
 
189 189
 		try {
190
-			$result = array_map( 'wc_clean', $_POST['result'] );
190
+			$result = array_map('wc_clean', $_POST['result']);
191 191
 
192
-			$order = $this->create_order( $result );
192
+			$order = $this->create_order($result);
193 193
 
194 194
 			// Handle payment.
195
-			if ( $order->get_total() > 0 ) {
195
+			if ($order->get_total() > 0) {
196 196
 
197
-				if ( $order->get_total() * 100 < 50 ) {
198
-					throw new Exception( __( 'Sorry, the minimum allowed order total is 0.50 to use this payment method.', 'woocommerce-gateway-stripe' ) );
197
+				if ($order->get_total() * 100 < 50) {
198
+					throw new Exception(__('Sorry, the minimum allowed order total is 0.50 to use this payment method.', 'woocommerce-gateway-stripe'));
199 199
 				}
200 200
 
201
-				WC_Stripe::log( "Info: Begin processing payment for order $order->id for the amount of {$order->get_total()}" );
201
+				WC_Stripe::log("Info: Begin processing payment for order $order->id for the amount of {$order->get_total()}");
202 202
 
203 203
 				// Make the request.
204
-				$response = WC_Stripe_API::request( $this->generate_payment_request( $order, $result['token']['id'] ) );
204
+				$response = WC_Stripe_API::request($this->generate_payment_request($order, $result['token']['id']));
205 205
 
206
-				if ( is_wp_error( $response ) ) {
206
+				if (is_wp_error($response)) {
207 207
 					$localized_messages = $this->get_localized_messages();
208 208
 
209
-					throw new Exception( ( isset( $localized_messages[ $response->get_error_code() ] ) ? $localized_messages[ $response->get_error_code() ] : $response->get_error_message() ) );
209
+					throw new Exception((isset($localized_messages[$response->get_error_code()]) ? $localized_messages[$response->get_error_code()] : $response->get_error_message()));
210 210
 				}
211 211
 
212 212
 				// Process valid response.
213
-				$this->process_response( $response, $order );
213
+				$this->process_response($response, $order);
214 214
 			} else {
215 215
 				$order->payment_complete();
216 216
 			}
@@ -218,23 +218,23 @@  discard block
 block discarded – undo
218 218
 			// Remove cart.
219 219
 			WC()->cart->empty_cart();
220 220
 
221
-			update_post_meta( $order->id, '_customer_user', get_current_user_id() );
221
+			update_post_meta($order->id, '_customer_user', get_current_user_id());
222 222
 
223 223
 			// Return thank you page redirect.
224
-			wp_send_json( array(
224
+			wp_send_json(array(
225 225
 				'success'  => 'true',
226
-				'redirect' => $this->get_return_url( $order ),
227
-			) );
226
+				'redirect' => $this->get_return_url($order),
227
+			));
228 228
 
229
-		} catch ( Exception $e ) {
230
-			WC()->session->set( 'refresh_totals', true );
231
-			WC_Stripe::log( sprintf( __( 'Error: %s', 'woocommerce-gateway-stripe' ), $e->getMessage() ) );
229
+		} catch (Exception $e) {
230
+			WC()->session->set('refresh_totals', true);
231
+			WC_Stripe::log(sprintf(__('Error: %s', 'woocommerce-gateway-stripe'), $e->getMessage()));
232 232
 
233
-			if ( $order->has_status( array( 'pending', 'failed' ) ) ) {
234
-				$this->send_failed_order_email( $order->id );
233
+			if ($order->has_status(array('pending', 'failed'))) {
234
+				$this->send_failed_order_email($order->id);
235 235
 			}
236 236
 
237
-			wp_send_json( array( 'success' => 'false', 'msg' => $e->getMessage() ) );
237
+			wp_send_json(array('success' => 'false', 'msg' => $e->getMessage()));
238 238
 		}
239 239
 	}
240 240
 
@@ -244,14 +244,14 @@  discard block
 block discarded – undo
244 244
 	 * @param string $source token
245 245
 	 * @return array()
246 246
 	 */
247
-	protected function generate_payment_request( $order, $source ) {
247
+	protected function generate_payment_request($order, $source) {
248 248
 		$post_data                = array();
249
-		$post_data['currency']    = strtolower( $order->get_order_currency() ? $order->get_order_currency() : get_woocommerce_currency() );
250
-		$post_data['amount']      = $this->get_stripe_amount( $order->get_total(), $post_data['currency'] );
251
-		$post_data['description'] = sprintf( __( '%s - Order %s', 'woocommerce-gateway-stripe' ), wp_specialchars_decode( get_bloginfo( 'name' ), ENT_QUOTES ), $order->get_order_number() );
249
+		$post_data['currency']    = strtolower($order->get_order_currency() ? $order->get_order_currency() : get_woocommerce_currency());
250
+		$post_data['amount']      = $this->get_stripe_amount($order->get_total(), $post_data['currency']);
251
+		$post_data['description'] = sprintf(__('%s - Order %s', 'woocommerce-gateway-stripe'), wp_specialchars_decode(get_bloginfo('name'), ENT_QUOTES), $order->get_order_number());
252 252
 		$post_data['capture']     = 'yes' === $this->_gateway_settings['capture'] ? 'true' : 'false';
253 253
 
254
-		if ( ! empty( $order->billing_email ) && apply_filters( 'wc_stripe_send_stripe_receipt', false ) ) {
254
+		if ( ! empty($order->billing_email) && apply_filters('wc_stripe_send_stripe_receipt', false)) {
255 255
 			$post_data['receipt_email'] = $order->billing_email;
256 256
 		}
257 257
 
@@ -266,7 +266,7 @@  discard block
 block discarded – undo
266 266
 		 * @param WC_Order $order
267 267
 		 * @param object $source
268 268
 		 */
269
-		return apply_filters( 'wc_stripe_generate_payment_request', $post_data, $order );
269
+		return apply_filters('wc_stripe_generate_payment_request', $post_data, $order);
270 270
 	}
271 271
 
272 272
 	/**
@@ -276,49 +276,49 @@  discard block
 block discarded – undo
276 276
 	 * @version 3.1.0
277 277
 	 */	
278 278
 	public function build_line_items() {
279
-		$decimals = apply_filters( 'wc_stripe_apple_pay_decimals', 2 );
279
+		$decimals = apply_filters('wc_stripe_apple_pay_decimals', 2);
280 280
 
281 281
 		$items = array();
282 282
 
283
-		foreach ( WC()->cart->get_cart() as $cart_item_key => $values ) {
284
-			$amount         = wc_format_decimal( $values['line_subtotal'], $decimals );
283
+		foreach (WC()->cart->get_cart() as $cart_item_key => $values) {
284
+			$amount         = wc_format_decimal($values['line_subtotal'], $decimals);
285 285
 			$quantity_label = 1 < $values['quantity'] ? ' (x' . $values['quantity'] . ')' : '';
286 286
 
287 287
 			$item = array(
288 288
 				'type'   => 'final',
289 289
 				'label'  => $values['data']->post->post_title . $quantity_label,
290
-				'amount' => wc_format_decimal( $amount, $decimals ),
290
+				'amount' => wc_format_decimal($amount, $decimals),
291 291
 			);
292 292
 
293 293
 			$items[] = $item;
294 294
 		}
295 295
 
296
-		$discounts   = wc_format_decimal( WC()->cart->get_cart_discount_total(), $decimals );
297
-		$tax         = wc_format_decimal( WC()->cart->tax_total + WC()->cart->shipping_tax_total, $decimals );
298
-		$shipping    = wc_format_decimal( WC()->cart->shipping_total, $decimals );
299
-		$item_total  = wc_format_decimal( WC()->cart->cart_contents_total, $decimals ) + $discounts;
300
-		$order_total = wc_format_decimal( $item_total + $tax + $shipping, $decimals );
296
+		$discounts   = wc_format_decimal(WC()->cart->get_cart_discount_total(), $decimals);
297
+		$tax         = wc_format_decimal(WC()->cart->tax_total + WC()->cart->shipping_tax_total, $decimals);
298
+		$shipping    = wc_format_decimal(WC()->cart->shipping_total, $decimals);
299
+		$item_total  = wc_format_decimal(WC()->cart->cart_contents_total, $decimals) + $discounts;
300
+		$order_total = wc_format_decimal($item_total + $tax + $shipping, $decimals);
301 301
 
302
-		if ( wc_tax_enabled() ) {
302
+		if (wc_tax_enabled()) {
303 303
 			$items[] = array(
304 304
 				'type'   => 'final',
305
-				'label'  => __( 'Tax', 'woocommerce-gateway-stripe' ),
305
+				'label'  => __('Tax', 'woocommerce-gateway-stripe'),
306 306
 				'amount' => $tax,
307 307
 			);
308 308
 		}
309 309
 
310
-		if ( WC()->cart->needs_shipping() ) {
310
+		if (WC()->cart->needs_shipping()) {
311 311
 			$items[] = array(
312 312
 				'type'   => 'final',
313
-				'label'  => __( 'Shipping', 'woocommerce-gateway-stripe' ),
313
+				'label'  => __('Shipping', 'woocommerce-gateway-stripe'),
314 314
 				'amount' => $shipping,
315 315
 			);
316 316
 		}
317 317
 
318
-		if ( WC()->cart->has_discount() ) {
318
+		if (WC()->cart->has_discount()) {
319 319
 			$items[] = array(
320 320
 				'type'   => 'final',
321
-				'label'  => __( 'Discount', 'woocommerce-gateway-stripe' ),
321
+				'label'  => __('Discount', 'woocommerce-gateway-stripe'),
322 322
 				'amount' => $discounts,
323 323
 			);
324 324
 		}
@@ -334,24 +334,24 @@  discard block
 block discarded – undo
334 334
 	 * @param array $data
335 335
 	 * @return object $order
336 336
 	 */
337
-	public function create_order( $data = array() ) {
338
-		if ( empty( $data ) ) {
339
-			throw new Exception( sprintf( __( 'Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe' ), 520 ) );
337
+	public function create_order($data = array()) {
338
+		if (empty($data)) {
339
+			throw new Exception(sprintf(__('Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe'), 520));
340 340
 		}
341 341
 
342 342
 		$order = wc_create_order();
343 343
 
344
-		if ( is_wp_error( $order ) ) {
345
-			throw new Exception( sprintf( __( 'Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe' ), 520 ) );
346
-		} elseif ( false === $order ) {
347
-			throw new Exception( sprintf( __( 'Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe' ), 521 ) );
344
+		if (is_wp_error($order)) {
345
+			throw new Exception(sprintf(__('Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe'), 520));
346
+		} elseif (false === $order) {
347
+			throw new Exception(sprintf(__('Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe'), 521));
348 348
 		} else {
349 349
 			$order_id = $order->id;
350
-			do_action( 'woocommerce_new_order', $order_id );
350
+			do_action('woocommerce_new_order', $order_id);
351 351
 		}
352 352
 
353 353
 		// Store the line items to the new/resumed order
354
-		foreach ( WC()->cart->get_cart() as $cart_item_key => $values ) {
354
+		foreach (WC()->cart->get_cart() as $cart_item_key => $values) {
355 355
 			$item_id = $order->add_product(
356 356
 				$values['data'],
357 357
 				$values['quantity'],
@@ -367,47 +367,47 @@  discard block
 block discarded – undo
367 367
 				)
368 368
 			);
369 369
 
370
-			if ( ! $item_id ) {
371
-				throw new Exception( sprintf( __( 'Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe' ), 525 ) );
370
+			if ( ! $item_id) {
371
+				throw new Exception(sprintf(__('Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe'), 525));
372 372
 			}
373 373
 
374 374
 			// Allow plugins to add order item meta
375
-			do_action( 'woocommerce_add_order_item_meta', $item_id, $values, $cart_item_key );
375
+			do_action('woocommerce_add_order_item_meta', $item_id, $values, $cart_item_key);
376 376
 		}
377 377
 
378 378
 		// Store fees
379
-		foreach ( WC()->cart->get_fees() as $fee_key => $fee ) {
380
-			$item_id = $order->add_fee( $fee );
379
+		foreach (WC()->cart->get_fees() as $fee_key => $fee) {
380
+			$item_id = $order->add_fee($fee);
381 381
 
382
-			if ( ! $item_id ) {
383
-				throw new Exception( sprintf( __( 'Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe' ), 526 ) );
382
+			if ( ! $item_id) {
383
+				throw new Exception(sprintf(__('Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe'), 526));
384 384
 			}
385 385
 
386 386
 			// Allow plugins to add order item meta to fees
387
-			do_action( 'woocommerce_add_order_fee_meta', $order_id, $item_id, $fee, $fee_key );
387
+			do_action('woocommerce_add_order_fee_meta', $order_id, $item_id, $fee, $fee_key);
388 388
 		}
389 389
 
390 390
 		// Store tax rows
391
-		foreach ( array_keys( WC()->cart->taxes + WC()->cart->shipping_taxes ) as $tax_rate_id ) {
392
-			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 ) {
393
-				throw new Exception( sprintf( __( 'Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe' ), 528 ) );
391
+		foreach (array_keys(WC()->cart->taxes + WC()->cart->shipping_taxes) as $tax_rate_id) {
392
+			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) {
393
+				throw new Exception(sprintf(__('Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe'), 528));
394 394
 			}
395 395
 		}
396 396
 
397 397
 		// Store coupons
398
-		foreach ( WC()->cart->get_coupons() as $code => $coupon ) {
399
-			if ( ! $order->add_coupon( $code, WC()->cart->get_coupon_discount_amount( $code ), WC()->cart->get_coupon_discount_tax_amount( $code ) ) ) {
400
-				throw new Exception( sprintf( __( 'Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe' ), 529 ) );
398
+		foreach (WC()->cart->get_coupons() as $code => $coupon) {
399
+			if ( ! $order->add_coupon($code, WC()->cart->get_coupon_discount_amount($code), WC()->cart->get_coupon_discount_tax_amount($code))) {
400
+				throw new Exception(sprintf(__('Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe'), 529));
401 401
 			}
402 402
 		}
403 403
 
404 404
 		// Billing address
405 405
 		$billing_address = array();
406
-		if ( ! empty( $data['token']['card'] ) ) {
406
+		if ( ! empty($data['token']['card'])) {
407 407
 			// Name from Stripe is a full name string.
408
-			$name                          = explode( ' ', $data['token']['card']['name'] );
409
-			$lastname                      = array_pop( $name );
410
-			$firstname                     = implode( ' ', $name );
408
+			$name                          = explode(' ', $data['token']['card']['name']);
409
+			$lastname                      = array_pop($name);
410
+			$firstname                     = implode(' ', $name);
411 411
 			$billing_address['first_name'] = $firstname;
412 412
 			$billing_address['last_name']  = $lastname;
413 413
 			$billing_address['email']      = $data['shippingContact']['emailAddress'];
@@ -422,7 +422,7 @@  discard block
 block discarded – undo
422 422
 
423 423
 		// Shipping address.
424 424
 		$shipping_address = array();
425
-		if ( WC()->cart->needs_shipping() && ! empty( $data['shippingContact'] ) ) {
425
+		if (WC()->cart->needs_shipping() && ! empty($data['shippingContact'])) {
426 426
 			$shipping_address['first_name'] = $data['shippingContact']['givenName'];
427 427
 			$shipping_address['last_name']  = $data['shippingContact']['familyName'];
428 428
 			$shipping_address['email']      = $data['shippingContact']['emailAddress'];
@@ -432,7 +432,7 @@  discard block
 block discarded – undo
432 432
 			$shipping_address['state']      = $data['shippingContact']['locality'];
433 433
 			$shipping_address['state']      = $data['shippingContact']['administrativeArea'];
434 434
 			$shipping_address['postcode']   = $data['shippingContact']['postalCode'];
435
-		} elseif ( ! empty( $data['shippingContact'] ) ) {
435
+		} elseif ( ! empty($data['shippingContact'])) {
436 436
 			$shipping_address['first_name'] = $firstname;
437 437
 			$shipping_address['last_name']  = $lastname;
438 438
 			$shipping_address['email']      = $data['shippingContact']['emailAddress'];
@@ -445,34 +445,34 @@  discard block
 block discarded – undo
445 445
 			$shipping_address['postcode']   = $data['token']['card']['address_zip'];
446 446
 		}
447 447
 
448
-		$order->set_address( $billing_address, 'billing' );
449
-		$order->set_address( $shipping_address, 'shipping' );
448
+		$order->set_address($billing_address, 'billing');
449
+		$order->set_address($shipping_address, 'shipping');
450 450
 
451
-		WC()->shipping->calculate_shipping( WC()->cart->get_shipping_packages() );
451
+		WC()->shipping->calculate_shipping(WC()->cart->get_shipping_packages());
452 452
 		
453 453
 		// Get the rate object selected by user.
454
-		foreach ( WC()->shipping->get_packages() as $package_key => $package ) {
455
-			foreach ( $package['rates'] as $key => $rate ) {
454
+		foreach (WC()->shipping->get_packages() as $package_key => $package) {
455
+			foreach ($package['rates'] as $key => $rate) {
456 456
 				// Loop through user chosen shipping methods.
457
-				foreach( WC()->session->get( 'chosen_shipping_methods' ) as $method ) {
458
-					if ( $method === $key ) {
459
-						$order->add_shipping( $rate );
457
+				foreach (WC()->session->get('chosen_shipping_methods') as $method) {
458
+					if ($method === $key) {
459
+						$order->add_shipping($rate);
460 460
 					}
461 461
 				}
462 462
 			}
463 463
 		}
464 464
 
465 465
 		$available_gateways = WC()->payment_gateways->get_available_payment_gateways();
466
-		$order->set_payment_method( $available_gateways['stripe'] );
467
-		$order->set_total( WC()->cart->shipping_total, 'shipping' );
468
-		$order->set_total( WC()->cart->get_cart_discount_total(), 'cart_discount' );
469
-		$order->set_total( WC()->cart->get_cart_discount_tax_total(), 'cart_discount_tax' );
470
-		$order->set_total( WC()->cart->tax_total, 'tax' );
471
-		$order->set_total( WC()->cart->shipping_tax_total, 'shipping_tax' );
472
-		$order->set_total( WC()->cart->total );
466
+		$order->set_payment_method($available_gateways['stripe']);
467
+		$order->set_total(WC()->cart->shipping_total, 'shipping');
468
+		$order->set_total(WC()->cart->get_cart_discount_total(), 'cart_discount');
469
+		$order->set_total(WC()->cart->get_cart_discount_tax_total(), 'cart_discount_tax');
470
+		$order->set_total(WC()->cart->tax_total, 'tax');
471
+		$order->set_total(WC()->cart->shipping_tax_total, 'shipping_tax');
472
+		$order->set_total(WC()->cart->total);
473 473
 
474 474
 		// If we got here, the order was created without problems!
475
-		wc_transaction_query( 'commit' );
475
+		wc_transaction_query('commit');
476 476
 
477 477
 		return $order;
478 478
 	}
Please login to merge, or discard this patch.