Completed
Push — master ( 9d6b36...bc8c17 )
by Roy
02:27
created
woocommerce-gateway-stripe.php 1 patch
Spacing   +124 added lines, -124 removed lines patch added patch discarded remove patch
@@ -25,21 +25,21 @@  discard block
 block discarded – undo
25 25
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
26 26
 */
27 27
 
28
-if ( ! defined( 'ABSPATH' ) ) {
28
+if ( ! defined('ABSPATH')) {
29 29
 	exit;
30 30
 }
31 31
 
32 32
 /**
33 33
  * Required minimums and constants
34 34
  */
35
-define( 'WC_STRIPE_VERSION', '3.0.6' );
36
-define( 'WC_STRIPE_MIN_PHP_VER', '5.3.0' );
37
-define( 'WC_STRIPE_MIN_WC_VER', '2.5.0' );
38
-define( 'WC_STRIPE_MAIN_FILE', __FILE__ );
39
-define( 'WC_STRIPE_PLUGIN_URL', untrailingslashit( plugins_url( basename( plugin_dir_path( __FILE__ ) ), basename( __FILE__ ) ) ) );
40
-define( 'WC_STRIPE_PLUGIN_PATH', untrailingslashit( plugin_dir_path( __FILE__ ) ) );
35
+define('WC_STRIPE_VERSION', '3.0.6');
36
+define('WC_STRIPE_MIN_PHP_VER', '5.3.0');
37
+define('WC_STRIPE_MIN_WC_VER', '2.5.0');
38
+define('WC_STRIPE_MAIN_FILE', __FILE__);
39
+define('WC_STRIPE_PLUGIN_URL', untrailingslashit(plugins_url(basename(plugin_dir_path(__FILE__)), basename(__FILE__))));
40
+define('WC_STRIPE_PLUGIN_PATH', untrailingslashit(plugin_dir_path(__FILE__)));
41 41
 
42
-if ( ! class_exists( 'WC_Stripe' ) ) :
42
+if ( ! class_exists('WC_Stripe')) :
43 43
 
44 44
 	class WC_Stripe {
45 45
 
@@ -59,7 +59,7 @@  discard block
 block discarded – undo
59 59
 		 * @return Singleton The *Singleton* instance.
60 60
 		 */
61 61
 		public static function get_instance() {
62
-			if ( null === self::$instance ) {
62
+			if (null === self::$instance) {
63 63
 				self::$instance = new self();
64 64
 			}
65 65
 			return self::$instance;
@@ -108,9 +108,9 @@  discard block
 block discarded – undo
108 108
 		 * *Singleton* via the `new` operator from outside of this class.
109 109
 		 */
110 110
 		protected function __construct() {
111
-			add_action( 'admin_init', array( $this, 'check_environment' ) );
112
-			add_action( 'admin_notices', array( $this, 'admin_notices' ), 15 );
113
-			add_action( 'plugins_loaded', array( $this, 'init' ) );
111
+			add_action('admin_init', array($this, 'check_environment'));
112
+			add_action('admin_notices', array($this, 'admin_notices'), 15);
113
+			add_action('plugins_loaded', array($this, 'init'));
114 114
 		}
115 115
 
116 116
 		/**
@@ -118,33 +118,33 @@  discard block
 block discarded – undo
118 118
 		 */
119 119
 		public function init() {
120 120
 			// Don't hook anything else in the plugin if we're in an incompatible environment
121
-			if ( self::get_environment_warning() ) {
121
+			if (self::get_environment_warning()) {
122 122
 				return;
123 123
 			}
124 124
 
125
-			include_once( dirname( __FILE__ ) . '/includes/class-wc-stripe-api.php' );
126
-			include_once( dirname( __FILE__ ) . '/includes/class-wc-stripe-customer.php' );
125
+			include_once(dirname(__FILE__) . '/includes/class-wc-stripe-api.php');
126
+			include_once(dirname(__FILE__) . '/includes/class-wc-stripe-customer.php');
127 127
 
128 128
 			// Init the gateway itself
129 129
 			$this->init_gateways();
130 130
 
131
-			add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), array( $this, 'plugin_action_links' ) );
132
-			add_action( 'woocommerce_order_status_on-hold_to_processing', array( $this, 'capture_payment' ) );
133
-			add_action( 'woocommerce_order_status_on-hold_to_completed', array( $this, 'capture_payment' ) );
134
-			add_action( 'woocommerce_order_status_on-hold_to_cancelled', array( $this, 'cancel_payment' ) );
135
-			add_action( 'woocommerce_order_status_on-hold_to_refunded', array( $this, 'cancel_payment' ) );
136
-			add_filter( 'woocommerce_get_customer_payment_tokens', array( $this, 'woocommerce_get_customer_payment_tokens' ), 10, 3 );
137
-			add_action( 'woocommerce_payment_token_deleted', array( $this, 'woocommerce_payment_token_deleted' ), 10, 2 );
138
-			add_action( 'woocommerce_payment_token_set_default', array( $this, 'woocommerce_payment_token_set_default' ) );
131
+			add_filter('plugin_action_links_' . plugin_basename(__FILE__), array($this, 'plugin_action_links'));
132
+			add_action('woocommerce_order_status_on-hold_to_processing', array($this, 'capture_payment'));
133
+			add_action('woocommerce_order_status_on-hold_to_completed', array($this, 'capture_payment'));
134
+			add_action('woocommerce_order_status_on-hold_to_cancelled', array($this, 'cancel_payment'));
135
+			add_action('woocommerce_order_status_on-hold_to_refunded', array($this, 'cancel_payment'));
136
+			add_filter('woocommerce_get_customer_payment_tokens', array($this, 'woocommerce_get_customer_payment_tokens'), 10, 3);
137
+			add_action('woocommerce_payment_token_deleted', array($this, 'woocommerce_payment_token_deleted'), 10, 2);
138
+			add_action('woocommerce_payment_token_set_default', array($this, 'woocommerce_payment_token_set_default'));
139 139
 
140
-			include_once( dirname( __FILE__ ) . '/includes/class-wc-stripe-payment-request.php' );
140
+			include_once(dirname(__FILE__) . '/includes/class-wc-stripe-payment-request.php');
141 141
 		}
142 142
 
143 143
 		/**
144 144
 		 * Allow this class and other classes to add slug keyed notices (to avoid duplication)
145 145
 		 */
146
-		public function add_admin_notice( $slug, $class, $message ) {
147
-			$this->notices[ $slug ] = array(
146
+		public function add_admin_notice($slug, $class, $message) {
147
+			$this->notices[$slug] = array(
148 148
 				'class'   => $class,
149 149
 				'message' => $message,
150 150
 			);
@@ -157,21 +157,21 @@  discard block
 block discarded – undo
157 157
 		public function check_environment() {
158 158
 			$environment_warning = self::get_environment_warning();
159 159
 
160
-			if ( $environment_warning && is_plugin_active( plugin_basename( __FILE__ ) ) ) {
161
-				$this->add_admin_notice( 'bad_environment', 'error', $environment_warning );
160
+			if ($environment_warning && is_plugin_active(plugin_basename(__FILE__))) {
161
+				$this->add_admin_notice('bad_environment', 'error', $environment_warning);
162 162
 			}
163 163
 
164 164
 			// Check if secret key present. Otherwise prompt, via notice, to go to
165 165
 			// setting.
166
-			if ( ! class_exists( 'WC_Stripe_API' ) ) {
167
-				include_once( dirname( __FILE__ ) . '/includes/class-wc-stripe-api.php' );
166
+			if ( ! class_exists('WC_Stripe_API')) {
167
+				include_once(dirname(__FILE__) . '/includes/class-wc-stripe-api.php');
168 168
 			}
169 169
 
170 170
 			$secret = WC_Stripe_API::get_secret_key();
171 171
 
172
-			if ( empty( $secret ) && ! ( isset( $_GET['page'], $_GET['section'] ) && 'wc-settings' === $_GET['page'] && 'stripe' === $_GET['section'] ) ) {
172
+			if (empty($secret) && ! (isset($_GET['page'], $_GET['section']) && 'wc-settings' === $_GET['page'] && 'stripe' === $_GET['section'])) {
173 173
 				$setting_link = $this->get_setting_link();
174
-				$this->add_admin_notice( 'prompt_connect', 'notice notice-warning', sprintf( __( 'Stripe is almost ready. To get started, <a href="%s">set your Stripe account keys</a>.', 'woocommerce-gateway-stripe' ), $setting_link ) );
174
+				$this->add_admin_notice('prompt_connect', 'notice notice-warning', sprintf(__('Stripe is almost ready. To get started, <a href="%s">set your Stripe account keys</a>.', 'woocommerce-gateway-stripe'), $setting_link));
175 175
 			}
176 176
 		}
177 177
 
@@ -180,24 +180,24 @@  discard block
 block discarded – undo
180 180
 		 * found or false if the environment has no problems.
181 181
 		 */
182 182
 		static function get_environment_warning() {
183
-			if ( version_compare( phpversion(), WC_STRIPE_MIN_PHP_VER, '<' ) ) {
184
-				$message = __( 'WooCommerce Stripe - The minimum PHP version required for this plugin is %1$s. You are running %2$s.', 'woocommerce-gateway-stripe' );
183
+			if (version_compare(phpversion(), WC_STRIPE_MIN_PHP_VER, '<')) {
184
+				$message = __('WooCommerce Stripe - The minimum PHP version required for this plugin is %1$s. You are running %2$s.', 'woocommerce-gateway-stripe');
185 185
 
186
-				return sprintf( $message, WC_STRIPE_MIN_PHP_VER, phpversion() );
186
+				return sprintf($message, WC_STRIPE_MIN_PHP_VER, phpversion());
187 187
 			}
188 188
 
189
-			if ( ! defined( 'WC_VERSION' ) ) {
190
-				return __( 'WooCommerce Stripe requires WooCommerce to be activated to work.', 'woocommerce-gateway-stripe' );
189
+			if ( ! defined('WC_VERSION')) {
190
+				return __('WooCommerce Stripe requires WooCommerce to be activated to work.', 'woocommerce-gateway-stripe');
191 191
 			}
192 192
 
193
-			if ( version_compare( WC_VERSION, WC_STRIPE_MIN_WC_VER, '<' ) ) {
194
-				$message = __( 'WooCommerce Stripe - The minimum WooCommerce version required for this plugin is %1$s. You are running %2$s.', 'woocommerce-gateway-stripe' );
193
+			if (version_compare(WC_VERSION, WC_STRIPE_MIN_WC_VER, '<')) {
194
+				$message = __('WooCommerce Stripe - The minimum WooCommerce version required for this plugin is %1$s. You are running %2$s.', 'woocommerce-gateway-stripe');
195 195
 
196
-				return sprintf( $message, WC_STRIPE_MIN_WC_VER, WC_VERSION );
196
+				return sprintf($message, WC_STRIPE_MIN_WC_VER, WC_VERSION);
197 197
 			}
198 198
 
199
-			if ( ! function_exists( 'curl_init' ) ) {
200
-				return __( 'WooCommerce Stripe - cURL is not installed.', 'woocommerce-gateway-stripe' );
199
+			if ( ! function_exists('curl_init')) {
200
+				return __('WooCommerce Stripe - cURL is not installed.', 'woocommerce-gateway-stripe');
201 201
 			}
202 202
 
203 203
 			return false;
@@ -208,15 +208,15 @@  discard block
 block discarded – undo
208 208
 		 *
209 209
 		 * @since 1.0.0
210 210
 		 */
211
-		public function plugin_action_links( $links ) {
211
+		public function plugin_action_links($links) {
212 212
 			$setting_link = $this->get_setting_link();
213 213
 
214 214
 			$plugin_links = array(
215
-				'<a href="' . $setting_link . '">' . __( 'Settings', 'woocommerce-gateway-stripe' ) . '</a>',
216
-				'<a href="https://docs.woothemes.com/document/stripe/">' . __( 'Docs', 'woocommerce-gateway-stripe' ) . '</a>',
217
-				'<a href="http://support.woothemes.com/">' . __( 'Support', 'woocommerce-gateway-stripe' ) . '</a>',
215
+				'<a href="' . $setting_link . '">' . __('Settings', 'woocommerce-gateway-stripe') . '</a>',
216
+				'<a href="https://docs.woothemes.com/document/stripe/">' . __('Docs', 'woocommerce-gateway-stripe') . '</a>',
217
+				'<a href="http://support.woothemes.com/">' . __('Support', 'woocommerce-gateway-stripe') . '</a>',
218 218
 			);
219
-			return array_merge( $plugin_links, $links );
219
+			return array_merge($plugin_links, $links);
220 220
 		}
221 221
 
222 222
 		/**
@@ -227,20 +227,20 @@  discard block
 block discarded – undo
227 227
 		 * @return string Setting link
228 228
 		 */
229 229
 		public function get_setting_link() {
230
-			$use_id_as_section = function_exists( 'WC' ) ? version_compare( WC()->version, '2.6', '>=' ) : false;
230
+			$use_id_as_section = function_exists('WC') ? version_compare(WC()->version, '2.6', '>=') : false;
231 231
 
232
-			$section_slug = $use_id_as_section ? 'stripe' : strtolower( 'WC_Gateway_Stripe' );
232
+			$section_slug = $use_id_as_section ? 'stripe' : strtolower('WC_Gateway_Stripe');
233 233
 
234
-			return admin_url( 'admin.php?page=wc-settings&tab=checkout&section=' . $section_slug );
234
+			return admin_url('admin.php?page=wc-settings&tab=checkout&section=' . $section_slug);
235 235
 		}
236 236
 
237 237
 		/**
238 238
 		 * Display any notices we've collected thus far (e.g. for connection, disconnection)
239 239
 		 */
240 240
 		public function admin_notices() {
241
-			foreach ( (array) $this->notices as $notice_key => $notice ) {
242
-				echo "<div class='" . esc_attr( $notice['class'] ) . "'><p>";
243
-				echo wp_kses( $notice['message'], array( 'a' => array( 'href' => array() ) ) );
241
+			foreach ((array) $this->notices as $notice_key => $notice) {
242
+				echo "<div class='" . esc_attr($notice['class']) . "'><p>";
243
+				echo wp_kses($notice['message'], array('a' => array('href' => array())));
244 244
 				echo '</p></div>';
245 245
 			}
246 246
 		}
@@ -251,28 +251,28 @@  discard block
 block discarded – undo
251 251
 		 * @since 1.0.0
252 252
 		 */
253 253
 		public function init_gateways() {
254
-			if ( class_exists( 'WC_Subscriptions_Order' ) && function_exists( 'wcs_create_renewal_order' ) ) {
254
+			if (class_exists('WC_Subscriptions_Order') && function_exists('wcs_create_renewal_order')) {
255 255
 				$this->subscription_support_enabled = true;
256 256
 			}
257 257
 
258
-			if ( class_exists( 'WC_Pre_Orders_Order' ) ) {
258
+			if (class_exists('WC_Pre_Orders_Order')) {
259 259
 				$this->pre_order_enabled = true;
260 260
 			}
261 261
 
262
-			if ( ! class_exists( 'WC_Payment_Gateway' ) ) {
262
+			if ( ! class_exists('WC_Payment_Gateway')) {
263 263
 				return;
264 264
 			}
265 265
 
266
-			if ( class_exists( 'WC_Payment_Gateway_CC' ) ) {
267
-				include_once( dirname( __FILE__ ) . '/includes/class-wc-gateway-stripe.php' );
268
-				include_once( dirname( __FILE__ ) . '/includes/class-wc-stripe-apple-pay.php' );
266
+			if (class_exists('WC_Payment_Gateway_CC')) {
267
+				include_once(dirname(__FILE__) . '/includes/class-wc-gateway-stripe.php');
268
+				include_once(dirname(__FILE__) . '/includes/class-wc-stripe-apple-pay.php');
269 269
 			} else {
270
-				include_once( dirname( __FILE__ ) . '/includes/legacy/class-wc-gateway-stripe.php' );
271
-				include_once( dirname( __FILE__ ) . '/includes/legacy/class-wc-gateway-stripe-saved-cards.php' );
270
+				include_once(dirname(__FILE__) . '/includes/legacy/class-wc-gateway-stripe.php');
271
+				include_once(dirname(__FILE__) . '/includes/legacy/class-wc-gateway-stripe-saved-cards.php');
272 272
 			}
273 273
 
274
-			load_plugin_textdomain( 'woocommerce-gateway-stripe', false, plugin_basename( dirname( __FILE__ ) ) . '/languages' );
275
-			add_filter( 'woocommerce_payment_gateways', array( $this, 'add_gateways' ) );
274
+			load_plugin_textdomain('woocommerce-gateway-stripe', false, plugin_basename(dirname(__FILE__)) . '/languages');
275
+			add_filter('woocommerce_payment_gateways', array($this, 'add_gateways'));
276 276
 			
277 277
 			$load_addons = (
278 278
 				$this->subscription_support_enabled
@@ -280,8 +280,8 @@  discard block
 block discarded – undo
280 280
 				$this->pre_order_enabled
281 281
 			);
282 282
 
283
-			if ( $load_addons ) {
284
-				require_once( dirname( __FILE__ ) . '/includes/class-wc-gateway-stripe-addons.php' );
283
+			if ($load_addons) {
284
+				require_once(dirname(__FILE__) . '/includes/class-wc-gateway-stripe-addons.php');
285 285
 			}
286 286
 		}
287 287
 
@@ -290,8 +290,8 @@  discard block
 block discarded – undo
290 290
 		 *
291 291
 		 * @since 1.0.0
292 292
 		 */
293
-		public function add_gateways( $methods ) {
294
-			if ( $this->subscription_support_enabled || $this->pre_order_enabled ) {
293
+		public function add_gateways($methods) {
294
+			if ($this->subscription_support_enabled || $this->pre_order_enabled) {
295 295
 				$methods[] = 'WC_Gateway_Stripe_Addons';
296 296
 			} else {
297 297
 				$methods[] = 'WC_Gateway_Stripe';
@@ -304,35 +304,35 @@  discard block
 block discarded – undo
304 304
 		 *
305 305
 		 * @param  int $order_id
306 306
 		 */
307
-		public function capture_payment( $order_id ) {
308
-			$order = wc_get_order( $order_id );
307
+		public function capture_payment($order_id) {
308
+			$order = wc_get_order($order_id);
309 309
 
310
-			if ( 'stripe' === $order->payment_method ) {
311
-				$charge   = get_post_meta( $order_id, '_stripe_charge_id', true );
312
-				$captured = get_post_meta( $order_id, '_stripe_charge_captured', true );
310
+			if ('stripe' === $order->payment_method) {
311
+				$charge   = get_post_meta($order_id, '_stripe_charge_id', true);
312
+				$captured = get_post_meta($order_id, '_stripe_charge_captured', true);
313 313
 
314
-				if ( $charge && 'no' === $captured ) {
315
-					$result = WC_Stripe_API::request( array(
314
+				if ($charge && 'no' === $captured) {
315
+					$result = WC_Stripe_API::request(array(
316 316
 						'amount'   => $order->get_total() * 100,
317 317
 						'expand[]' => 'balance_transaction',
318
-					), 'charges/' . $charge . '/capture' );
318
+					), 'charges/' . $charge . '/capture');
319 319
 
320
-					if ( is_wp_error( $result ) ) {
321
-						$order->add_order_note( __( 'Unable to capture charge!', 'woocommerce-gateway-stripe' ) . ' ' . $result->get_error_message() );
320
+					if (is_wp_error($result)) {
321
+						$order->add_order_note(__('Unable to capture charge!', 'woocommerce-gateway-stripe') . ' ' . $result->get_error_message());
322 322
 					} else {
323
-						$order->add_order_note( sprintf( __( 'Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe' ), $result->id ) );
324
-						update_post_meta( $order->id, '_stripe_charge_captured', 'yes' );
323
+						$order->add_order_note(sprintf(__('Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe'), $result->id));
324
+						update_post_meta($order->id, '_stripe_charge_captured', 'yes');
325 325
 
326 326
 						// Store other data such as fees
327
-						update_post_meta( $order->id, 'Stripe Payment ID', $result->id );
327
+						update_post_meta($order->id, 'Stripe Payment ID', $result->id);
328 328
 
329
-						if ( isset( $result->balance_transaction ) && isset( $result->balance_transaction->fee ) ) {
329
+						if (isset($result->balance_transaction) && isset($result->balance_transaction->fee)) {
330 330
 							// Fees and Net needs to both come from Stripe to be accurate as the returned
331 331
 							// values are in the local currency of the Stripe account, not from WC.
332
-							$fee = ! empty( $result->balance_transaction->fee ) ? number_format( $result->balance_transaction->fee / 100, 2, '.', '' ) : 0;
333
-							$net = ! empty( $result->balance_transaction->net ) ? number_format( $result->balance_transaction->net / 100, 2, '.', '' ) : 0;
334
-							update_post_meta( $order->id, 'Stripe Fee', $fee );
335
-							update_post_meta( $order->id, 'Net Revenue From Stripe', $net );
332
+							$fee = ! empty($result->balance_transaction->fee) ? number_format($result->balance_transaction->fee / 100, 2, '.', '') : 0;
333
+							$net = ! empty($result->balance_transaction->net) ? number_format($result->balance_transaction->net / 100, 2, '.', '') : 0;
334
+							update_post_meta($order->id, 'Stripe Fee', $fee);
335
+							update_post_meta($order->id, 'Net Revenue From Stripe', $net);
336 336
 						}
337 337
 					}
338 338
 				}
@@ -344,23 +344,23 @@  discard block
 block discarded – undo
344 344
 		 *
345 345
 		 * @param  int $order_id
346 346
 		 */
347
-		public function cancel_payment( $order_id ) {
348
-			$order = wc_get_order( $order_id );
347
+		public function cancel_payment($order_id) {
348
+			$order = wc_get_order($order_id);
349 349
 
350
-			if ( 'stripe' === $order->payment_method ) {
351
-				$charge   = get_post_meta( $order_id, '_stripe_charge_id', true );
350
+			if ('stripe' === $order->payment_method) {
351
+				$charge = get_post_meta($order_id, '_stripe_charge_id', true);
352 352
 
353
-				if ( $charge ) {
354
-					$result = WC_Stripe_API::request( array(
353
+				if ($charge) {
354
+					$result = WC_Stripe_API::request(array(
355 355
 						'amount' => $order->get_total() * 100,
356
-					), 'charges/' . $charge . '/refund' );
356
+					), 'charges/' . $charge . '/refund');
357 357
 
358
-					if ( is_wp_error( $result ) ) {
359
-						$order->add_order_note( __( 'Unable to refund charge!', 'woocommerce-gateway-stripe' ) . ' ' . $result->get_error_message() );
358
+					if (is_wp_error($result)) {
359
+						$order->add_order_note(__('Unable to refund charge!', 'woocommerce-gateway-stripe') . ' ' . $result->get_error_message());
360 360
 					} else {
361
-						$order->add_order_note( sprintf( __( 'Stripe charge refunded (Charge ID: %s)', 'woocommerce-gateway-stripe' ), $result->id ) );
362
-						delete_post_meta( $order->id, '_stripe_charge_captured' );
363
-						delete_post_meta( $order->id, '_stripe_charge_id' );
361
+						$order->add_order_note(sprintf(__('Stripe charge refunded (Charge ID: %s)', 'woocommerce-gateway-stripe'), $result->id));
362
+						delete_post_meta($order->id, '_stripe_charge_captured');
363
+						delete_post_meta($order->id, '_stripe_charge_id');
364 364
 					}
365 365
 				}
366 366
 			}
@@ -371,28 +371,28 @@  discard block
 block discarded – undo
371 371
 		 * @param array $tokens
372 372
 		 * @return array
373 373
 		 */
374
-		public function woocommerce_get_customer_payment_tokens( $tokens, $customer_id, $gateway_id ) {
375
-			if ( is_user_logged_in() && 'stripe' === $gateway_id && class_exists( 'WC_Payment_Token_CC' ) ) {
376
-				$stripe_customer = new WC_Stripe_Customer( $customer_id );
374
+		public function woocommerce_get_customer_payment_tokens($tokens, $customer_id, $gateway_id) {
375
+			if (is_user_logged_in() && 'stripe' === $gateway_id && class_exists('WC_Payment_Token_CC')) {
376
+				$stripe_customer = new WC_Stripe_Customer($customer_id);
377 377
 				$stripe_cards    = $stripe_customer->get_cards();
378 378
 				$stored_tokens   = array();
379 379
 
380
-				foreach ( $tokens as $token ) {
380
+				foreach ($tokens as $token) {
381 381
 					$stored_tokens[] = $token->get_token();
382 382
 				}
383 383
 
384
-				foreach ( $stripe_cards as $card ) {
385
-					if ( ! in_array( $card->id, $stored_tokens ) ) {
384
+				foreach ($stripe_cards as $card) {
385
+					if ( ! in_array($card->id, $stored_tokens)) {
386 386
 						$token = new WC_Payment_Token_CC();
387
-						$token->set_token( $card->id );
388
-						$token->set_gateway_id( 'stripe' );
389
-						$token->set_card_type( strtolower( $card->brand ) );
390
-						$token->set_last4( $card->last4 );
391
-						$token->set_expiry_month( $card->exp_month );
392
-						$token->set_expiry_year( $card->exp_year );
393
-						$token->set_user_id( $customer_id );
387
+						$token->set_token($card->id);
388
+						$token->set_gateway_id('stripe');
389
+						$token->set_card_type(strtolower($card->brand));
390
+						$token->set_last4($card->last4);
391
+						$token->set_expiry_month($card->exp_month);
392
+						$token->set_expiry_year($card->exp_year);
393
+						$token->set_user_id($customer_id);
394 394
 						$token->save();
395
-						$tokens[ $token->get_id() ] = $token;
395
+						$tokens[$token->get_id()] = $token;
396 396
 					}
397 397
 				}
398 398
 			}
@@ -402,21 +402,21 @@  discard block
 block discarded – undo
402 402
 		/**
403 403
 		 * Delete token from Stripe
404 404
 		 */
405
-		public function woocommerce_payment_token_deleted( $token_id, $token ) {
406
-			if ( 'stripe' === $token->get_gateway_id() ) {
407
-				$stripe_customer = new WC_Stripe_Customer( get_current_user_id() );
408
-				$stripe_customer->delete_card( $token->get_token() );
405
+		public function woocommerce_payment_token_deleted($token_id, $token) {
406
+			if ('stripe' === $token->get_gateway_id()) {
407
+				$stripe_customer = new WC_Stripe_Customer(get_current_user_id());
408
+				$stripe_customer->delete_card($token->get_token());
409 409
 			}
410 410
 		}
411 411
 
412 412
 		/**
413 413
 		 * Set as default in Stripe
414 414
 		 */
415
-		public function woocommerce_payment_token_set_default( $token_id ) {
416
-			$token = WC_Payment_Tokens::get( $token_id );
417
-			if ( 'stripe' === $token->get_gateway_id() ) {
418
-				$stripe_customer = new WC_Stripe_Customer( get_current_user_id() );
419
-				$stripe_customer->set_default_card( $token->get_token() );
415
+		public function woocommerce_payment_token_set_default($token_id) {
416
+			$token = WC_Payment_Tokens::get($token_id);
417
+			if ('stripe' === $token->get_gateway_id()) {
418
+				$stripe_customer = new WC_Stripe_Customer(get_current_user_id());
419
+				$stripe_customer->set_default_card($token->get_token());
420 420
 			}
421 421
 		}
422 422
 
@@ -425,7 +425,7 @@  discard block
 block discarded – undo
425 425
 		 */
426 426
 		public static function get_minimum_amount() {
427 427
 			// Check order amount
428
-			switch ( get_woocommerce_currency() ) {
428
+			switch (get_woocommerce_currency()) {
429 429
 				case 'USD':
430 430
 				case 'CAD':
431 431
 				case 'EUR':
@@ -469,12 +469,12 @@  discard block
 block discarded – undo
469 469
 		 * And fits on your back?
470 470
 		 * It's log, log, log
471 471
 		 */
472
-		public static function log( $message ) {
473
-			if ( empty( self::$log ) ) {
472
+		public static function log($message) {
473
+			if (empty(self::$log)) {
474 474
 				self::$log = new WC_Logger();
475 475
 			}
476 476
 
477
-			self::$log->add( 'woocommerce-gateway-stripe', $message );
477
+			self::$log->add('woocommerce-gateway-stripe', $message);
478 478
 		}
479 479
 	}
480 480
 
Please login to merge, or discard this patch.