Completed
Push — master ( 1968f4...2723f5 )
by Roy
02:26
created
woocommerce-gateway-stripe.php 2 patches
Doc Comments   +2 added lines patch added patch discarded remove patch
@@ -141,6 +141,8 @@
 block discarded – undo
141 141
 
142 142
 		/**
143 143
 		 * Allow this class and other classes to add slug keyed notices (to avoid duplication)
144
+		 * @param string $slug
145
+		 * @param string $class
144 146
 		 */
145 147
 		public function add_admin_notice( $slug, $class, $message ) {
146 148
 			$this->notices[ $slug ] = array(
Please login to merge, or discard this 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,33 +117,33 @@  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
-			include_once( dirname( __FILE__ ) . '/includes/class-wc-stripe-payment-request.php' );
139
+			include_once(dirname(__FILE__) . '/includes/class-wc-stripe-payment-request.php');
140 140
 		}
141 141
 
142 142
 		/**
143 143
 		 * Allow this class and other classes to add slug keyed notices (to avoid duplication)
144 144
 		 */
145
-		public function add_admin_notice( $slug, $class, $message ) {
146
-			$this->notices[ $slug ] = array(
145
+		public function add_admin_notice($slug, $class, $message) {
146
+			$this->notices[$slug] = array(
147 147
 				'class'   => $class,
148 148
 				'message' => $message,
149 149
 			);
@@ -156,21 +156,21 @@  discard block
 block discarded – undo
156 156
 		public function check_environment() {
157 157
 			$environment_warning = self::get_environment_warning();
158 158
 
159
-			if ( $environment_warning && is_plugin_active( plugin_basename( __FILE__ ) ) ) {
160
-				$this->add_admin_notice( 'bad_environment', 'error', $environment_warning );
159
+			if ($environment_warning && is_plugin_active(plugin_basename(__FILE__))) {
160
+				$this->add_admin_notice('bad_environment', 'error', $environment_warning);
161 161
 			}
162 162
 
163 163
 			// Check if secret key present. Otherwise prompt, via notice, to go to
164 164
 			// setting.
165
-			if ( ! class_exists( 'WC_Stripe_API' ) ) {
166
-				include_once( dirname( __FILE__ ) . '/includes/class-wc-stripe-api.php' );
165
+			if ( ! class_exists('WC_Stripe_API')) {
166
+				include_once(dirname(__FILE__) . '/includes/class-wc-stripe-api.php');
167 167
 			}
168 168
 
169 169
 			$secret = WC_Stripe_API::get_secret_key();
170 170
 
171
-			if ( empty( $secret ) && ! ( isset( $_GET['page'], $_GET['section'] ) && 'wc-settings' === $_GET['page'] && 'stripe' === $_GET['section'] ) ) {
171
+			if (empty($secret) && ! (isset($_GET['page'], $_GET['section']) && 'wc-settings' === $_GET['page'] && 'stripe' === $_GET['section'])) {
172 172
 				$setting_link = $this->get_setting_link();
173
-				$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 ) );
173
+				$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 174
 			}
175 175
 		}
176 176
 
@@ -179,24 +179,24 @@  discard block
 block discarded – undo
179 179
 		 * found or false if the environment has no problems.
180 180
 		 */
181 181
 		static function get_environment_warning() {
182
-			if ( version_compare( phpversion(), WC_STRIPE_MIN_PHP_VER, '<' ) ) {
183
-				$message = __( 'WooCommerce Stripe - The minimum PHP version required for this plugin is %1$s. You are running %2$s.', 'woocommerce-gateway-stripe' );
182
+			if (version_compare(phpversion(), WC_STRIPE_MIN_PHP_VER, '<')) {
183
+				$message = __('WooCommerce Stripe - The minimum PHP version required for this plugin is %1$s. You are running %2$s.', 'woocommerce-gateway-stripe');
184 184
 
185
-				return sprintf( $message, WC_STRIPE_MIN_PHP_VER, phpversion() );
185
+				return sprintf($message, WC_STRIPE_MIN_PHP_VER, phpversion());
186 186
 			}
187 187
 
188
-			if ( ! defined( 'WC_VERSION' ) ) {
189
-				return __( 'WooCommerce Stripe requires WooCommerce to be activated to work.', 'woocommerce-gateway-stripe' );
188
+			if ( ! defined('WC_VERSION')) {
189
+				return __('WooCommerce Stripe requires WooCommerce to be activated to work.', 'woocommerce-gateway-stripe');
190 190
 			}
191 191
 
192
-			if ( version_compare( WC_VERSION, WC_STRIPE_MIN_WC_VER, '<' ) ) {
193
-				$message = __( 'WooCommerce Stripe - The minimum WooCommerce version required for this plugin is %1$s. You are running %2$s.', 'woocommerce-gateway-stripe' );
192
+			if (version_compare(WC_VERSION, WC_STRIPE_MIN_WC_VER, '<')) {
193
+				$message = __('WooCommerce Stripe - The minimum WooCommerce version required for this plugin is %1$s. You are running %2$s.', 'woocommerce-gateway-stripe');
194 194
 
195
-				return sprintf( $message, WC_STRIPE_MIN_WC_VER, WC_VERSION );
195
+				return sprintf($message, WC_STRIPE_MIN_WC_VER, WC_VERSION);
196 196
 			}
197 197
 
198
-			if ( ! function_exists( 'curl_init' ) ) {
199
-				return __( 'WooCommerce Stripe - cURL is not installed.', 'woocommerce-gateway-stripe' );
198
+			if ( ! function_exists('curl_init')) {
199
+				return __('WooCommerce Stripe - cURL is not installed.', 'woocommerce-gateway-stripe');
200 200
 			}
201 201
 
202 202
 			return false;
@@ -207,15 +207,15 @@  discard block
 block discarded – undo
207 207
 		 *
208 208
 		 * @since 1.0.0
209 209
 		 */
210
-		public function plugin_action_links( $links ) {
210
+		public function plugin_action_links($links) {
211 211
 			$setting_link = $this->get_setting_link();
212 212
 
213 213
 			$plugin_links = array(
214
-				'<a href="' . $setting_link . '">' . __( 'Settings', 'woocommerce-gateway-stripe' ) . '</a>',
215
-				'<a href="https://docs.woothemes.com/document/stripe/">' . __( 'Docs', 'woocommerce-gateway-stripe' ) . '</a>',
216
-				'<a href="http://support.woothemes.com/">' . __( 'Support', 'woocommerce-gateway-stripe' ) . '</a>',
214
+				'<a href="' . $setting_link . '">' . __('Settings', 'woocommerce-gateway-stripe') . '</a>',
215
+				'<a href="https://docs.woothemes.com/document/stripe/">' . __('Docs', 'woocommerce-gateway-stripe') . '</a>',
216
+				'<a href="http://support.woothemes.com/">' . __('Support', 'woocommerce-gateway-stripe') . '</a>',
217 217
 			);
218
-			return array_merge( $plugin_links, $links );
218
+			return array_merge($plugin_links, $links);
219 219
 		}
220 220
 
221 221
 		/**
@@ -226,20 +226,20 @@  discard block
 block discarded – undo
226 226
 		 * @return string Setting link
227 227
 		 */
228 228
 		public function get_setting_link() {
229
-			$use_id_as_section = class_exists( 'WC' ) ? version_compare( WC()->version, '2.6', '>=' ) : false;
229
+			$use_id_as_section = class_exists('WC') ? version_compare(WC()->version, '2.6', '>=') : false;
230 230
 
231
-			$section_slug = $use_id_as_section ? 'stripe' : strtolower( 'WC_Gateway_Stripe' );
231
+			$section_slug = $use_id_as_section ? 'stripe' : strtolower('WC_Gateway_Stripe');
232 232
 
233
-			return admin_url( 'admin.php?page=wc-settings&tab=checkout&section=' . $section_slug );
233
+			return admin_url('admin.php?page=wc-settings&tab=checkout&section=' . $section_slug);
234 234
 		}
235 235
 
236 236
 		/**
237 237
 		 * Display any notices we've collected thus far (e.g. for connection, disconnection)
238 238
 		 */
239 239
 		public function admin_notices() {
240
-			foreach ( (array) $this->notices as $notice_key => $notice ) {
241
-				echo "<div class='" . esc_attr( $notice['class'] ) . "'><p>";
242
-				echo wp_kses( $notice['message'], array( 'a' => array( 'href' => array() ) ) );
240
+			foreach ((array) $this->notices as $notice_key => $notice) {
241
+				echo "<div class='" . esc_attr($notice['class']) . "'><p>";
242
+				echo wp_kses($notice['message'], array('a' => array('href' => array())));
243 243
 				echo '</p></div>';
244 244
 			}
245 245
 		}
@@ -250,28 +250,28 @@  discard block
 block discarded – undo
250 250
 		 * @since 1.0.0
251 251
 		 */
252 252
 		public function init_gateways() {
253
-			if ( class_exists( 'WC_Subscriptions_Order' ) && function_exists( 'wcs_create_renewal_order' ) ) {
253
+			if (class_exists('WC_Subscriptions_Order') && function_exists('wcs_create_renewal_order')) {
254 254
 				$this->subscription_support_enabled = true;
255 255
 			}
256 256
 
257
-			if ( class_exists( 'WC_Pre_Orders_Order' ) ) {
257
+			if (class_exists('WC_Pre_Orders_Order')) {
258 258
 				$this->pre_order_enabled = true;
259 259
 			}
260 260
 
261
-			if ( ! class_exists( 'WC_Payment_Gateway' ) ) {
261
+			if ( ! class_exists('WC_Payment_Gateway')) {
262 262
 				return;
263 263
 			}
264 264
 
265
-			if ( class_exists( 'WC_Payment_Gateway_CC' ) ) {
266
-				include_once( dirname( __FILE__ ) . '/includes/class-wc-gateway-stripe.php' );
267
-				include_once( dirname( __FILE__ ) . '/includes/class-wc-stripe-apple-pay.php' );
265
+			if (class_exists('WC_Payment_Gateway_CC')) {
266
+				include_once(dirname(__FILE__) . '/includes/class-wc-gateway-stripe.php');
267
+				include_once(dirname(__FILE__) . '/includes/class-wc-stripe-apple-pay.php');
268 268
 			} else {
269
-				include_once( dirname( __FILE__ ) . '/includes/legacy/class-wc-gateway-stripe.php' );
270
-				include_once( dirname( __FILE__ ) . '/includes/legacy/class-wc-gateway-stripe-saved-cards.php' );
269
+				include_once(dirname(__FILE__) . '/includes/legacy/class-wc-gateway-stripe.php');
270
+				include_once(dirname(__FILE__) . '/includes/legacy/class-wc-gateway-stripe-saved-cards.php');
271 271
 			}
272 272
 
273
-			load_plugin_textdomain( 'woocommerce-gateway-stripe', false, plugin_basename( dirname( __FILE__ ) ) . '/languages' );
274
-			add_filter( 'woocommerce_payment_gateways', array( $this, 'add_gateways' ) );
273
+			load_plugin_textdomain('woocommerce-gateway-stripe', false, plugin_basename(dirname(__FILE__)) . '/languages');
274
+			add_filter('woocommerce_payment_gateways', array($this, 'add_gateways'));
275 275
 
276 276
 			$load_addons = (
277 277
 				$this->subscription_support_enabled
@@ -279,8 +279,8 @@  discard block
 block discarded – undo
279 279
 				$this->pre_order_enabled
280 280
 			);
281 281
 
282
-			if ( $load_addons ) {
283
-				require_once( dirname( __FILE__ ) . '/includes/class-wc-gateway-stripe-addons.php' );
282
+			if ($load_addons) {
283
+				require_once(dirname(__FILE__) . '/includes/class-wc-gateway-stripe-addons.php');
284 284
 			}
285 285
 		}
286 286
 
@@ -289,8 +289,8 @@  discard block
 block discarded – undo
289 289
 		 *
290 290
 		 * @since 1.0.0
291 291
 		 */
292
-		public function add_gateways( $methods ) {
293
-			if ( $this->subscription_support_enabled || $this->pre_order_enabled ) {
292
+		public function add_gateways($methods) {
293
+			if ($this->subscription_support_enabled || $this->pre_order_enabled) {
294 294
 				$methods[] = 'WC_Gateway_Stripe_Addons';
295 295
 			} else {
296 296
 				$methods[] = 'WC_Gateway_Stripe';
@@ -303,35 +303,35 @@  discard block
 block discarded – undo
303 303
 		 *
304 304
 		 * @param  int $order_id
305 305
 		 */
306
-		public function capture_payment( $order_id ) {
307
-			$order = wc_get_order( $order_id );
306
+		public function capture_payment($order_id) {
307
+			$order = wc_get_order($order_id);
308 308
 
309
-			if ( 'stripe' === $order->payment_method ) {
310
-				$charge   = get_post_meta( $order_id, '_stripe_charge_id', true );
311
-				$captured = get_post_meta( $order_id, '_stripe_charge_captured', true );
309
+			if ('stripe' === $order->payment_method) {
310
+				$charge   = get_post_meta($order_id, '_stripe_charge_id', true);
311
+				$captured = get_post_meta($order_id, '_stripe_charge_captured', true);
312 312
 
313
-				if ( $charge && 'no' === $captured ) {
314
-					$result = WC_Stripe_API::request( array(
313
+				if ($charge && 'no' === $captured) {
314
+					$result = WC_Stripe_API::request(array(
315 315
 						'amount'   => $order->get_total() * 100,
316 316
 						'expand[]' => 'balance_transaction',
317
-					), 'charges/' . $charge . '/capture' );
317
+					), 'charges/' . $charge . '/capture');
318 318
 
319
-					if ( is_wp_error( $result ) ) {
320
-						$order->add_order_note( __( 'Unable to capture charge!', 'woocommerce-gateway-stripe' ) . ' ' . $result->get_error_message() );
319
+					if (is_wp_error($result)) {
320
+						$order->add_order_note(__('Unable to capture charge!', 'woocommerce-gateway-stripe') . ' ' . $result->get_error_message());
321 321
 					} else {
322
-						$order->add_order_note( sprintf( __( 'Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe' ), $result->id ) );
323
-						update_post_meta( $order->id, '_stripe_charge_captured', 'yes' );
322
+						$order->add_order_note(sprintf(__('Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe'), $result->id));
323
+						update_post_meta($order->id, '_stripe_charge_captured', 'yes');
324 324
 
325 325
 						// Store other data such as fees
326
-						update_post_meta( $order->id, 'Stripe Payment ID', $result->id );
326
+						update_post_meta($order->id, 'Stripe Payment ID', $result->id);
327 327
 
328
-						if ( isset( $result->balance_transaction ) && isset( $result->balance_transaction->fee ) ) {
328
+						if (isset($result->balance_transaction) && isset($result->balance_transaction->fee)) {
329 329
 							// Fees and Net needs to both come from Stripe to be accurate as the returned
330 330
 							// values are in the local currency of the Stripe account, not from WC.
331
-							$fee = ! empty( $result->balance_transaction->fee ) ? number_format( $result->balance_transaction->fee / 100, 2, '.', '' ) : 0;
332
-							$net = ! empty( $result->balance_transaction->net ) ? number_format( $result->balance_transaction->net / 100, 2, '.', '' ) : 0;
333
-							update_post_meta( $order->id, 'Stripe Fee', $fee );
334
-							update_post_meta( $order->id, 'Net Revenue From Stripe', $net );
331
+							$fee = ! empty($result->balance_transaction->fee) ? number_format($result->balance_transaction->fee / 100, 2, '.', '') : 0;
332
+							$net = ! empty($result->balance_transaction->net) ? number_format($result->balance_transaction->net / 100, 2, '.', '') : 0;
333
+							update_post_meta($order->id, 'Stripe Fee', $fee);
334
+							update_post_meta($order->id, 'Net Revenue From Stripe', $net);
335 335
 						}
336 336
 					}
337 337
 				}
@@ -343,23 +343,23 @@  discard block
 block discarded – undo
343 343
 		 *
344 344
 		 * @param  int $order_id
345 345
 		 */
346
-		public function cancel_payment( $order_id ) {
347
-			$order = wc_get_order( $order_id );
346
+		public function cancel_payment($order_id) {
347
+			$order = wc_get_order($order_id);
348 348
 
349
-			if ( 'stripe' === $order->payment_method ) {
350
-				$charge   = get_post_meta( $order_id, '_stripe_charge_id', true );
349
+			if ('stripe' === $order->payment_method) {
350
+				$charge = get_post_meta($order_id, '_stripe_charge_id', true);
351 351
 
352
-				if ( $charge ) {
353
-					$result = WC_Stripe_API::request( array(
352
+				if ($charge) {
353
+					$result = WC_Stripe_API::request(array(
354 354
 						'amount' => $order->get_total() * 100,
355
-					), 'charges/' . $charge . '/refund' );
355
+					), 'charges/' . $charge . '/refund');
356 356
 
357
-					if ( is_wp_error( $result ) ) {
358
-						$order->add_order_note( __( 'Unable to refund charge!', 'woocommerce-gateway-stripe' ) . ' ' . $result->get_error_message() );
357
+					if (is_wp_error($result)) {
358
+						$order->add_order_note(__('Unable to refund charge!', 'woocommerce-gateway-stripe') . ' ' . $result->get_error_message());
359 359
 					} else {
360
-						$order->add_order_note( sprintf( __( 'Stripe charge refunded (Charge ID: %s)', 'woocommerce-gateway-stripe' ), $result->id ) );
361
-						delete_post_meta( $order->id, '_stripe_charge_captured' );
362
-						delete_post_meta( $order->id, '_stripe_charge_id' );
360
+						$order->add_order_note(sprintf(__('Stripe charge refunded (Charge ID: %s)', 'woocommerce-gateway-stripe'), $result->id));
361
+						delete_post_meta($order->id, '_stripe_charge_captured');
362
+						delete_post_meta($order->id, '_stripe_charge_id');
363 363
 					}
364 364
 				}
365 365
 			}
@@ -370,28 +370,28 @@  discard block
 block discarded – undo
370 370
 		 * @param array $tokens
371 371
 		 * @return array
372 372
 		 */
373
-		public function woocommerce_get_customer_payment_tokens( $tokens, $customer_id, $gateway_id ) {
374
-			if ( is_user_logged_in() && 'stripe' === $gateway_id && class_exists( 'WC_Payment_Token_CC' ) ) {
375
-				$stripe_customer = new WC_Stripe_Customer( $customer_id );
373
+		public function woocommerce_get_customer_payment_tokens($tokens, $customer_id, $gateway_id) {
374
+			if (is_user_logged_in() && 'stripe' === $gateway_id && class_exists('WC_Payment_Token_CC')) {
375
+				$stripe_customer = new WC_Stripe_Customer($customer_id);
376 376
 				$stripe_cards    = $stripe_customer->get_cards();
377 377
 				$stored_tokens   = array();
378 378
 
379
-				foreach ( $tokens as $token ) {
379
+				foreach ($tokens as $token) {
380 380
 					$stored_tokens[] = $token->get_token();
381 381
 				}
382 382
 
383
-				foreach ( $stripe_cards as $card ) {
384
-					if ( ! in_array( $card->id, $stored_tokens ) ) {
383
+				foreach ($stripe_cards as $card) {
384
+					if ( ! in_array($card->id, $stored_tokens)) {
385 385
 						$token = new WC_Payment_Token_CC();
386
-						$token->set_token( $card->id );
387
-						$token->set_gateway_id( 'stripe' );
388
-						$token->set_card_type( strtolower( $card->brand ) );
389
-						$token->set_last4( $card->last4 );
390
-						$token->set_expiry_month( $card->exp_month );
391
-						$token->set_expiry_year( $card->exp_year );
392
-						$token->set_user_id( $customer_id );
386
+						$token->set_token($card->id);
387
+						$token->set_gateway_id('stripe');
388
+						$token->set_card_type(strtolower($card->brand));
389
+						$token->set_last4($card->last4);
390
+						$token->set_expiry_month($card->exp_month);
391
+						$token->set_expiry_year($card->exp_year);
392
+						$token->set_user_id($customer_id);
393 393
 						$token->save();
394
-						$tokens[ $token->get_id() ] = $token;
394
+						$tokens[$token->get_id()] = $token;
395 395
 					}
396 396
 				}
397 397
 			}
@@ -401,21 +401,21 @@  discard block
 block discarded – undo
401 401
 		/**
402 402
 		 * Delete token from Stripe
403 403
 		 */
404
-		public function woocommerce_payment_token_deleted( $token_id, $token ) {
405
-			if ( 'stripe' === $token->get_gateway_id() ) {
406
-				$stripe_customer = new WC_Stripe_Customer( get_current_user_id() );
407
-				$stripe_customer->delete_card( $token->get_token() );
404
+		public function woocommerce_payment_token_deleted($token_id, $token) {
405
+			if ('stripe' === $token->get_gateway_id()) {
406
+				$stripe_customer = new WC_Stripe_Customer(get_current_user_id());
407
+				$stripe_customer->delete_card($token->get_token());
408 408
 			}
409 409
 		}
410 410
 
411 411
 		/**
412 412
 		 * Set as default in Stripe
413 413
 		 */
414
-		public function woocommerce_payment_token_set_default( $token_id ) {
415
-			$token = WC_Payment_Tokens::get( $token_id );
416
-			if ( 'stripe' === $token->get_gateway_id() ) {
417
-				$stripe_customer = new WC_Stripe_Customer( get_current_user_id() );
418
-				$stripe_customer->set_default_card( $token->get_token() );
414
+		public function woocommerce_payment_token_set_default($token_id) {
415
+			$token = WC_Payment_Tokens::get($token_id);
416
+			if ('stripe' === $token->get_gateway_id()) {
417
+				$stripe_customer = new WC_Stripe_Customer(get_current_user_id());
418
+				$stripe_customer->set_default_card($token->get_token());
419 419
 			}
420 420
 		}
421 421
 
@@ -424,7 +424,7 @@  discard block
 block discarded – undo
424 424
 		 */
425 425
 		public static function get_minimum_amount() {
426 426
 			// Check order amount
427
-			switch ( get_woocommerce_currency() ) {
427
+			switch (get_woocommerce_currency()) {
428 428
 				case 'USD':
429 429
 				case 'CAD':
430 430
 				case 'EUR':
@@ -468,12 +468,12 @@  discard block
 block discarded – undo
468 468
 		 * And fits on your back?
469 469
 		 * It's log, log, log
470 470
 		 */
471
-		public static function log( $message ) {
472
-			if ( empty( self::$log ) ) {
471
+		public static function log($message) {
472
+			if (empty(self::$log)) {
473 473
 				self::$log = new WC_Logger();
474 474
 			}
475 475
 
476
-			self::$log->add( 'woocommerce-gateway-stripe', $message );
476
+			self::$log->add('woocommerce-gateway-stripe', $message);
477 477
 		}
478 478
 	}
479 479
 
Please login to merge, or discard this patch.
includes/class-wc-gateway-stripe.php 1 patch
Spacing   +226 added lines, -226 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
 
@@ -113,8 +113,8 @@  discard block
 block discarded – undo
113 113
 	 */
114 114
 	public function __construct() {
115 115
 		$this->id                   = 'stripe';
116
-		$this->method_title         = __( 'Stripe', 'woocommerce-gateway-stripe' );
117
-		$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' );
116
+		$this->method_title         = __('Stripe', 'woocommerce-gateway-stripe');
117
+		$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');
118 118
 		$this->has_fields           = true;
119 119
 		$this->view_transaction_url = 'https://dashboard.stripe.com/payments/%s';
120 120
 		$this->supports             = array(
@@ -142,39 +142,39 @@  discard block
 block discarded – undo
142 142
 		$this->init_settings();
143 143
 
144 144
 		// Get setting values.
145
-		$this->title                  = $this->get_option( 'title' );
146
-		$this->description            = $this->get_option( 'description' );
147
-		$this->enabled                = $this->get_option( 'enabled' );
148
-		$this->testmode               = 'yes' === $this->get_option( 'testmode' );
149
-		$this->capture                = 'yes' === $this->get_option( 'capture', 'yes' );
150
-		$this->statement_descriptor   = $this->get_option( 'statement_descriptor', wp_specialchars_decode( get_bloginfo( 'name' ), ENT_QUOTES ) );
151
-		$this->stripe_checkout        = 'yes' === $this->get_option( 'stripe_checkout' );
152
-		$this->stripe_checkout_locale = $this->get_option( 'stripe_checkout_locale' );
153
-		$this->stripe_checkout_image  = $this->get_option( 'stripe_checkout_image', '' );
154
-		$this->saved_cards            = 'yes' === $this->get_option( 'saved_cards' );
155
-		$this->secret_key             = $this->testmode ? $this->get_option( 'test_secret_key' ) : $this->get_option( 'secret_key' );
156
-		$this->publishable_key        = $this->testmode ? $this->get_option( 'test_publishable_key' ) : $this->get_option( 'publishable_key' );
157
-		$this->bitcoin                = 'USD' === strtoupper( get_woocommerce_currency() ) && 'yes' === $this->get_option( 'stripe_bitcoin' );
158
-		$this->apple_pay              = 'yes' === $this->get_option( 'apple_pay' );
159
-		$this->apple_pay_button       = $this->get_option( 'apple_pay_button', 'black' );
160
-		$this->logging                = 'yes' === $this->get_option( 'logging' );
161
-		$this->allow_remember_me      = 'yes' === $this->get_option( 'allow_remember_me', 'no' );
162
-
163
-		if ( $this->stripe_checkout ) {
164
-			$this->order_button_text = __( 'Continue to payment', 'woocommerce-gateway-stripe' );
165
-		}
166
-
167
-		if ( $this->testmode ) {
168
-			$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' );
169
-			$this->description  = trim( $this->description );
170
-		}
171
-
172
-		WC_Stripe_API::set_secret_key( $this->secret_key );
145
+		$this->title                  = $this->get_option('title');
146
+		$this->description            = $this->get_option('description');
147
+		$this->enabled                = $this->get_option('enabled');
148
+		$this->testmode               = 'yes' === $this->get_option('testmode');
149
+		$this->capture                = 'yes' === $this->get_option('capture', 'yes');
150
+		$this->statement_descriptor   = $this->get_option('statement_descriptor', wp_specialchars_decode(get_bloginfo('name'), ENT_QUOTES));
151
+		$this->stripe_checkout        = 'yes' === $this->get_option('stripe_checkout');
152
+		$this->stripe_checkout_locale = $this->get_option('stripe_checkout_locale');
153
+		$this->stripe_checkout_image  = $this->get_option('stripe_checkout_image', '');
154
+		$this->saved_cards            = 'yes' === $this->get_option('saved_cards');
155
+		$this->secret_key             = $this->testmode ? $this->get_option('test_secret_key') : $this->get_option('secret_key');
156
+		$this->publishable_key        = $this->testmode ? $this->get_option('test_publishable_key') : $this->get_option('publishable_key');
157
+		$this->bitcoin                = 'USD' === strtoupper(get_woocommerce_currency()) && 'yes' === $this->get_option('stripe_bitcoin');
158
+		$this->apple_pay              = 'yes' === $this->get_option('apple_pay');
159
+		$this->apple_pay_button       = $this->get_option('apple_pay_button', 'black');
160
+		$this->logging                = 'yes' === $this->get_option('logging');
161
+		$this->allow_remember_me      = 'yes' === $this->get_option('allow_remember_me', 'no');
162
+
163
+		if ($this->stripe_checkout) {
164
+			$this->order_button_text = __('Continue to payment', 'woocommerce-gateway-stripe');
165
+		}
166
+
167
+		if ($this->testmode) {
168
+			$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');
169
+			$this->description  = trim($this->description);
170
+		}
171
+
172
+		WC_Stripe_API::set_secret_key($this->secret_key);
173 173
 
174 174
 		// Hooks.
175
-		add_action( 'wp_enqueue_scripts', array( $this, 'payment_scripts' ) );
176
-		add_action( 'admin_notices', array( $this, 'admin_notices' ) );
177
-		add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) );
175
+		add_action('wp_enqueue_scripts', array($this, 'payment_scripts'));
176
+		add_action('admin_notices', array($this, 'admin_notices'));
177
+		add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options'));
178 178
 	}
179 179
 
180 180
 	/**
@@ -184,24 +184,24 @@  discard block
 block discarded – undo
184 184
 	 * @return string
185 185
 	 */
186 186
 	public function get_icon() {
187
-		$ext   = version_compare( WC()->version, '2.6', '>=' ) ? '.svg' : '.png';
188
-		$style = version_compare( WC()->version, '2.6', '>=' ) ? 'style="margin-left: 0.3em"' : '';
187
+		$ext   = version_compare(WC()->version, '2.6', '>=') ? '.svg' : '.png';
188
+		$style = version_compare(WC()->version, '2.6', '>=') ? 'style="margin-left: 0.3em"' : '';
189 189
 
190
-		$icon  = '<img src="' . WC_HTTPS::force_https_url( WC()->plugin_url() . '/assets/images/icons/credit-cards/visa' . $ext ) . '" alt="Visa" width="32" ' . $style . ' />';
191
-		$icon .= '<img src="' . WC_HTTPS::force_https_url( WC()->plugin_url() . '/assets/images/icons/credit-cards/mastercard' . $ext ) . '" alt="Mastercard" width="32" ' . $style . ' />';
192
-		$icon .= '<img src="' . WC_HTTPS::force_https_url( WC()->plugin_url() . '/assets/images/icons/credit-cards/amex' . $ext ) . '" alt="Amex" width="32" ' . $style . ' />';
190
+		$icon  = '<img src="' . WC_HTTPS::force_https_url(WC()->plugin_url() . '/assets/images/icons/credit-cards/visa' . $ext) . '" alt="Visa" width="32" ' . $style . ' />';
191
+		$icon .= '<img src="' . WC_HTTPS::force_https_url(WC()->plugin_url() . '/assets/images/icons/credit-cards/mastercard' . $ext) . '" alt="Mastercard" width="32" ' . $style . ' />';
192
+		$icon .= '<img src="' . WC_HTTPS::force_https_url(WC()->plugin_url() . '/assets/images/icons/credit-cards/amex' . $ext) . '" alt="Amex" width="32" ' . $style . ' />';
193 193
 
194
-		if ( 'USD' === get_woocommerce_currency() ) {
195
-			$icon .= '<img src="' . WC_HTTPS::force_https_url( WC()->plugin_url() . '/assets/images/icons/credit-cards/discover' . $ext ) . '" alt="Discover" width="32" ' . $style . ' />';
196
-			$icon .= '<img src="' . WC_HTTPS::force_https_url( WC()->plugin_url() . '/assets/images/icons/credit-cards/jcb' . $ext ) . '" alt="JCB" width="32" ' . $style . ' />';
197
-			$icon .= '<img src="' . WC_HTTPS::force_https_url( WC()->plugin_url() . '/assets/images/icons/credit-cards/diners' . $ext ) . '" alt="Diners" width="32" ' . $style . ' />';
194
+		if ('USD' === get_woocommerce_currency()) {
195
+			$icon .= '<img src="' . WC_HTTPS::force_https_url(WC()->plugin_url() . '/assets/images/icons/credit-cards/discover' . $ext) . '" alt="Discover" width="32" ' . $style . ' />';
196
+			$icon .= '<img src="' . WC_HTTPS::force_https_url(WC()->plugin_url() . '/assets/images/icons/credit-cards/jcb' . $ext) . '" alt="JCB" width="32" ' . $style . ' />';
197
+			$icon .= '<img src="' . WC_HTTPS::force_https_url(WC()->plugin_url() . '/assets/images/icons/credit-cards/diners' . $ext) . '" alt="Diners" width="32" ' . $style . ' />';
198 198
 		}
199 199
 
200
-		if ( $this->bitcoin && $this->stripe_checkout ) {
201
-			$icon .= '<img src="' . WC_HTTPS::force_https_url( plugins_url( '/assets/images/bitcoin' . $ext, WC_STRIPE_MAIN_FILE ) ) . '" alt="Bitcoin" width="24" ' . $style . ' />';
200
+		if ($this->bitcoin && $this->stripe_checkout) {
201
+			$icon .= '<img src="' . WC_HTTPS::force_https_url(plugins_url('/assets/images/bitcoin' . $ext, WC_STRIPE_MAIN_FILE)) . '" alt="Bitcoin" width="24" ' . $style . ' />';
202 202
 		}
203 203
 
204
-		return apply_filters( 'woocommerce_gateway_icon', $icon, $this->id );
204
+		return apply_filters('woocommerce_gateway_icon', $icon, $this->id);
205 205
 	}
206 206
 
207 207
 	/**
@@ -212,11 +212,11 @@  discard block
 block discarded – undo
212 212
 	 *
213 213
 	 * @return float|int
214 214
 	 */
215
-	public function get_stripe_amount( $total, $currency = '' ) {
216
-		if ( ! $currency ) {
215
+	public function get_stripe_amount($total, $currency = '') {
216
+		if ( ! $currency) {
217 217
 			$currency = get_woocommerce_currency();
218 218
 		}
219
-		switch ( strtoupper( $currency ) ) {
219
+		switch (strtoupper($currency)) {
220 220
 			// Zero decimal currencies.
221 221
 			case 'BIF' :
222 222
 			case 'CLP' :
@@ -233,10 +233,10 @@  discard block
 block discarded – undo
233 233
 			case 'XAF' :
234 234
 			case 'XOF' :
235 235
 			case 'XPF' :
236
-				$total = absint( $total );
236
+				$total = absint($total);
237 237
 				break;
238 238
 			default :
239
-				$total = round( $total, 2 ) * 100; // In cents.
239
+				$total = round($total, 2) * 100; // In cents.
240 240
 				break;
241 241
 		}
242 242
 		return $total;
@@ -246,13 +246,13 @@  discard block
 block discarded – undo
246 246
 	 * Check if SSL is enabled and notify the user
247 247
 	 */
248 248
 	public function admin_notices() {
249
-		if ( 'no' === $this->enabled ) {
249
+		if ('no' === $this->enabled) {
250 250
 			return;
251 251
 		}
252 252
 
253 253
 		// Show message if enabled and FORCE SSL is disabled and WordpressHTTPS plugin is not detected.
254
-		if ( ( function_exists( 'wc_site_is_https' ) && ! wc_site_is_https() ) && ( 'no' === get_option( 'woocommerce_force_ssl_checkout' ) && ! class_exists( 'WordPressHTTPS' ) ) ) {
255
-			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>';
254
+		if ((function_exists('wc_site_is_https') && ! wc_site_is_https()) && ('no' === get_option('woocommerce_force_ssl_checkout') && ! class_exists('WordPressHTTPS'))) {
255
+			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>';
256 256
 		}
257 257
 	}
258 258
 
@@ -260,11 +260,11 @@  discard block
 block discarded – undo
260 260
 	 * Check if this gateway is enabled
261 261
 	 */
262 262
 	public function is_available() {
263
-		if ( 'yes' === $this->enabled ) {
264
-			if ( ! $this->testmode && is_checkout() && ! is_ssl() ) {
263
+		if ('yes' === $this->enabled) {
264
+			if ( ! $this->testmode && is_checkout() && ! is_ssl()) {
265 265
 				return false;
266 266
 			}
267
-			if ( ! $this->secret_key || ! $this->publishable_key ) {
267
+			if ( ! $this->secret_key || ! $this->publishable_key) {
268 268
 				return false;
269 269
 			}
270 270
 			return true;
@@ -276,9 +276,9 @@  discard block
 block discarded – undo
276 276
 	 * Initialise Gateway Settings Form Fields
277 277
 	 */
278 278
 	public function init_form_fields() {
279
-		$this->form_fields = include( 'settings-stripe.php' );
279
+		$this->form_fields = include('settings-stripe.php');
280 280
 
281
-		wc_enqueue_js( "
281
+		wc_enqueue_js("
282 282
 			jQuery( function( $ ) {
283 283
 				$( document.body ).on( 'change', '#woocommerce_stripe_testmode', function() {
284 284
 					var test_secret_key = $( '#woocommerce_stripe_test_secret_key' ).parents( 'tr' ).eq( 0 ),
@@ -323,7 +323,7 @@  discard block
 block discarded – undo
323 323
 					var value = $( this ).val();
324 324
 
325 325
 					if ( value.indexOf( '_test_' ) >= 0 ) {
326
-						$( 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>' );
326
+						$( 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>' );
327 327
 					} else {
328 328
 						$( this ).css( 'border-color', '' );
329 329
 						$( '.stripe-error-description', $( this ).parent() ).remove();
@@ -334,7 +334,7 @@  discard block
 block discarded – undo
334 334
 					var value = $( this ).val();
335 335
 
336 336
 					if ( value.indexOf( '_live_' ) >= 0 ) {
337
-						$( 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>' );
337
+						$( 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>' );
338 338
 					} else {
339 339
 						$( this ).css( 'border-color', '' );
340 340
 						$( '.stripe-error-description', $( this ).parent() ).remove();
@@ -349,54 +349,54 @@  discard block
 block discarded – undo
349 349
 	 */
350 350
 	public function payment_fields() {
351 351
 		$user                 = wp_get_current_user();
352
-		$display_tokenization = $this->supports( 'tokenization' ) && is_checkout() && $this->saved_cards;
352
+		$display_tokenization = $this->supports('tokenization') && is_checkout() && $this->saved_cards;
353 353
 		$total                = WC()->cart->total;
354 354
 
355 355
 		// If paying from order, we need to get total from order not cart.
356
-		if ( isset( $_GET['pay_for_order'] ) && isset( $_GET['key'] ) ) {
357
-			$order = wc_get_order( wc_get_order_id_by_order_key( wc_clean( $_GET['key'] ) ) );
356
+		if (isset($_GET['pay_for_order']) && isset($_GET['key'])) {
357
+			$order = wc_get_order(wc_get_order_id_by_order_key(wc_clean($_GET['key'])));
358 358
 			$total = $order->get_total();
359 359
 		}
360 360
 
361
-		if ( $user->ID ) {
362
-			$user_email = get_user_meta( $user->ID, 'billing_email', true );
361
+		if ($user->ID) {
362
+			$user_email = get_user_meta($user->ID, 'billing_email', true);
363 363
 			$user_email = $user_email ? $user_email : $user->user_email;
364 364
 		} else {
365 365
 			$user_email = '';
366 366
 		}
367 367
 
368
-		if ( is_add_payment_method_page() ) {
369
-			$pay_button_text = __( 'Add Card', 'woocommerce-gateway-stripe' );
368
+		if (is_add_payment_method_page()) {
369
+			$pay_button_text = __('Add Card', 'woocommerce-gateway-stripe');
370 370
 		} else {
371 371
 			$pay_button_text = '';
372 372
 		}
373 373
 
374 374
 		echo '<div
375 375
 			id="stripe-payment-data"
376
-			data-panel-label="' . esc_attr( $pay_button_text ) . '"
376
+			data-panel-label="' . esc_attr($pay_button_text) . '"
377 377
 			data-description=""
378
-			data-email="' . esc_attr( $user_email ) . '"
379
-			data-amount="' . esc_attr( $this->get_stripe_amount( $total ) ) . '"
380
-			data-name="' . esc_attr( $this->statement_descriptor ) . '"
381
-			data-currency="' . esc_attr( strtolower( get_woocommerce_currency() ) ) . '"
382
-			data-image="' . esc_attr( $this->stripe_checkout_image ) . '"
383
-			data-bitcoin="' . esc_attr( $this->bitcoin ? 'true' : 'false' ) . '"
384
-			data-locale="' . esc_attr( $this->stripe_checkout_locale ? $this->stripe_checkout_locale : 'en' ) . '"
385
-			data-allow-remember-me="' . esc_attr( $this->allow_remember_me ? 'true' : 'false' ) . '">';
378
+			data-email="' . esc_attr($user_email) . '"
379
+			data-amount="' . esc_attr($this->get_stripe_amount($total)) . '"
380
+			data-name="' . esc_attr($this->statement_descriptor) . '"
381
+			data-currency="' . esc_attr(strtolower(get_woocommerce_currency())) . '"
382
+			data-image="' . esc_attr($this->stripe_checkout_image) . '"
383
+			data-bitcoin="' . esc_attr($this->bitcoin ? 'true' : 'false') . '"
384
+			data-locale="' . esc_attr($this->stripe_checkout_locale ? $this->stripe_checkout_locale : 'en') . '"
385
+			data-allow-remember-me="' . esc_attr($this->allow_remember_me ? 'true' : 'false') . '">';
386 386
 
387
-		if ( $this->description ) {
388
-			echo apply_filters( 'wc_stripe_description', wpautop( wp_kses_post( $this->description ) ) );
387
+		if ($this->description) {
388
+			echo apply_filters('wc_stripe_description', wpautop(wp_kses_post($this->description)));
389 389
 		}
390 390
 
391
-		if ( $display_tokenization ) {
391
+		if ($display_tokenization) {
392 392
 			$this->tokenization_script();
393 393
 			$this->saved_payment_methods();
394 394
 		}
395 395
 
396
-		if ( ! $this->stripe_checkout ) {
396
+		if ( ! $this->stripe_checkout) {
397 397
 			$this->form();
398 398
 
399
-			if ( $display_tokenization ) {
399
+			if ($display_tokenization) {
400 400
 				$this->save_payment_method_checkbox();
401 401
 			}
402 402
 		}
@@ -412,20 +412,20 @@  discard block
 block discarded – undo
412 412
 	 * @return array
413 413
 	 */
414 414
 	public function get_localized_messages() {
415
-		return apply_filters( 'wc_stripe_localized_messages', array(
416
-			'invalid_number'        => __( 'The card number is not a valid credit card number.', 'woocommerce-gateway-stripe' ),
417
-			'invalid_expiry_month'  => __( 'The card\'s expiration month is invalid.', 'woocommerce-gateway-stripe' ),
418
-			'invalid_expiry_year'   => __( 'The card\'s expiration year is invalid.', 'woocommerce-gateway-stripe' ),
419
-			'invalid_cvc'           => __( 'The card\'s security code is invalid.', 'woocommerce-gateway-stripe' ),
420
-			'incorrect_number'      => __( 'The card number is incorrect.', 'woocommerce-gateway-stripe' ),
421
-			'expired_card'          => __( 'The card has expired.', 'woocommerce-gateway-stripe' ),
422
-			'incorrect_cvc'         => __( 'The card\'s security code is incorrect.', 'woocommerce-gateway-stripe' ),
423
-			'incorrect_zip'         => __( 'The card\'s zip code failed validation.', 'woocommerce-gateway-stripe' ),
424
-			'card_declined'         => __( 'The card was declined.', 'woocommerce-gateway-stripe' ),
425
-			'missing'               => __( 'There is no card on a customer that is being charged.', 'woocommerce-gateway-stripe' ),
426
-			'processing_error'      => __( 'An error occurred while processing the card.', 'woocommerce-gateway-stripe' ),
427
-			'invalid_request_error' => __( 'Could not find payment information.', 'woocommerce-gateway-stripe' ),
428
-		) );
415
+		return apply_filters('wc_stripe_localized_messages', array(
416
+			'invalid_number'        => __('The card number is not a valid credit card number.', 'woocommerce-gateway-stripe'),
417
+			'invalid_expiry_month'  => __('The card\'s expiration month is invalid.', 'woocommerce-gateway-stripe'),
418
+			'invalid_expiry_year'   => __('The card\'s expiration year is invalid.', 'woocommerce-gateway-stripe'),
419
+			'invalid_cvc'           => __('The card\'s security code is invalid.', 'woocommerce-gateway-stripe'),
420
+			'incorrect_number'      => __('The card number is incorrect.', 'woocommerce-gateway-stripe'),
421
+			'expired_card'          => __('The card has expired.', 'woocommerce-gateway-stripe'),
422
+			'incorrect_cvc'         => __('The card\'s security code is incorrect.', 'woocommerce-gateway-stripe'),
423
+			'incorrect_zip'         => __('The card\'s zip code failed validation.', 'woocommerce-gateway-stripe'),
424
+			'card_declined'         => __('The card was declined.', 'woocommerce-gateway-stripe'),
425
+			'missing'               => __('There is no card on a customer that is being charged.', 'woocommerce-gateway-stripe'),
426
+			'processing_error'      => __('An error occurred while processing the card.', 'woocommerce-gateway-stripe'),
427
+			'invalid_request_error' => __('Could not find payment information.', 'woocommerce-gateway-stripe'),
428
+		));
429 429
 	}
430 430
 
431 431
 	/**
@@ -436,30 +436,30 @@  discard block
 block discarded – undo
436 436
 	 * @access public
437 437
 	 */
438 438
 	public function payment_scripts() {
439
-		if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) ) {
439
+		if ( ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order'])) {
440 440
 			return;
441 441
 		}
442 442
 
443
-		$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
443
+		$suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';
444 444
 
445
-		if ( $this->stripe_checkout ) {
446
-			wp_enqueue_script( 'stripe_checkout', 'https://checkout.stripe.com/v2/checkout.js', '', '2.0', true );
447
-			wp_enqueue_script( 'woocommerce_stripe', plugins_url( 'assets/js/stripe_checkout' . $suffix . '.js', WC_STRIPE_MAIN_FILE ), array( 'stripe' ), WC_STRIPE_VERSION, true );
445
+		if ($this->stripe_checkout) {
446
+			wp_enqueue_script('stripe_checkout', 'https://checkout.stripe.com/v2/checkout.js', '', '2.0', true);
447
+			wp_enqueue_script('woocommerce_stripe', plugins_url('assets/js/stripe_checkout' . $suffix . '.js', WC_STRIPE_MAIN_FILE), array('stripe'), WC_STRIPE_VERSION, true);
448 448
 		} else {
449
-			wp_enqueue_script( 'stripe', 'https://js.stripe.com/v2/', '', '1.0', true );
450
-			wp_enqueue_script( 'woocommerce_stripe', plugins_url( 'assets/js/stripe' . $suffix . '.js', WC_STRIPE_MAIN_FILE ), array( 'jquery-payment', 'stripe' ), WC_STRIPE_VERSION, true );
449
+			wp_enqueue_script('stripe', 'https://js.stripe.com/v2/', '', '1.0', true);
450
+			wp_enqueue_script('woocommerce_stripe', plugins_url('assets/js/stripe' . $suffix . '.js', WC_STRIPE_MAIN_FILE), array('jquery-payment', 'stripe'), WC_STRIPE_VERSION, true);
451 451
 		}
452 452
 
453 453
 		$stripe_params = array(
454 454
 			'key'                  => $this->publishable_key,
455
-			'i18n_terms'           => __( 'Please accept the terms and conditions first', 'woocommerce-gateway-stripe' ),
456
-			'i18n_required_fields' => __( 'Please fill in required checkout fields first', 'woocommerce-gateway-stripe' ),
455
+			'i18n_terms'           => __('Please accept the terms and conditions first', 'woocommerce-gateway-stripe'),
456
+			'i18n_required_fields' => __('Please fill in required checkout fields first', 'woocommerce-gateway-stripe'),
457 457
 		);
458 458
 
459 459
 		// If we're on the pay page we need to pass stripe.js the address of the order.
460
-		if ( isset( $_GET['pay_for_order'] ) && 'true' === $_GET['pay_for_order'] ) {
461
-			$order_id = wc_get_order_id_by_order_key( urldecode( $_GET['key'] ) );
462
-			$order    = wc_get_order( $order_id );
460
+		if (isset($_GET['pay_for_order']) && 'true' === $_GET['pay_for_order']) {
461
+			$order_id = wc_get_order_id_by_order_key(urldecode($_GET['key']));
462
+			$order    = wc_get_order($order_id);
463 463
 
464 464
 			$stripe_params['billing_first_name'] = $order->billing_first_name;
465 465
 			$stripe_params['billing_last_name']  = $order->billing_last_name;
@@ -471,14 +471,14 @@  discard block
 block discarded – undo
471 471
 			$stripe_params['billing_country']    = $order->billing_country;
472 472
 		}
473 473
 
474
-		$stripe_params['no_prepaid_card_msg']                     = __( 'Sorry, we\'re not accepting prepaid cards at this time.', 'woocommerce-gateway-stripe' );
475
-		$stripe_params['allow_prepaid_card']                      = apply_filters( 'wc_stripe_allow_prepaid_card', true ) ? 'yes' : 'no';
476
-		$stripe_params['stripe_checkout_require_billing_address'] = apply_filters( 'wc_stripe_checkout_require_billing_address', false ) ? 'yes' : 'no';
474
+		$stripe_params['no_prepaid_card_msg']                     = __('Sorry, we\'re not accepting prepaid cards at this time.', 'woocommerce-gateway-stripe');
475
+		$stripe_params['allow_prepaid_card']                      = apply_filters('wc_stripe_allow_prepaid_card', true) ? 'yes' : 'no';
476
+		$stripe_params['stripe_checkout_require_billing_address'] = apply_filters('wc_stripe_checkout_require_billing_address', false) ? 'yes' : 'no';
477 477
 
478 478
 		// merge localized messages to be use in JS
479
-		$stripe_params = array_merge( $stripe_params, $this->get_localized_messages() );
479
+		$stripe_params = array_merge($stripe_params, $this->get_localized_messages());
480 480
 
481
-		wp_localize_script( 'woocommerce_stripe', 'wc_stripe_params', apply_filters( 'wc_stripe_params', $stripe_params ) );
481
+		wp_localize_script('woocommerce_stripe', 'wc_stripe_params', apply_filters('wc_stripe_params', $stripe_params));
482 482
 	}
483 483
 
484 484
 	/**
@@ -487,24 +487,24 @@  discard block
 block discarded – undo
487 487
 	 * @param  object $source
488 488
 	 * @return array()
489 489
 	 */
490
-	protected function generate_payment_request( $order, $source ) {
490
+	protected function generate_payment_request($order, $source) {
491 491
 		$post_data                = array();
492
-		$post_data['currency']    = strtolower( $order->get_order_currency() ? $order->get_order_currency() : get_woocommerce_currency() );
493
-		$post_data['amount']      = $this->get_stripe_amount( $order->get_total(), $post_data['currency'] );
494
-		$post_data['description'] = sprintf( __( '%1$s - Order %2$s', 'woocommerce-gateway-stripe' ), $this->statement_descriptor, $order->get_order_number() );
492
+		$post_data['currency']    = strtolower($order->get_order_currency() ? $order->get_order_currency() : get_woocommerce_currency());
493
+		$post_data['amount']      = $this->get_stripe_amount($order->get_total(), $post_data['currency']);
494
+		$post_data['description'] = sprintf(__('%1$s - Order %2$s', 'woocommerce-gateway-stripe'), $this->statement_descriptor, $order->get_order_number());
495 495
 		$post_data['capture']     = $this->capture ? 'true' : 'false';
496 496
 
497
-		if ( ! empty( $order->billing_email ) && apply_filters( 'wc_stripe_send_stripe_receipt', false ) ) {
497
+		if ( ! empty($order->billing_email) && apply_filters('wc_stripe_send_stripe_receipt', false)) {
498 498
 			$post_data['receipt_email'] = $order->billing_email;
499 499
 		}
500 500
 
501
-		$post_data['expand[]']    = 'balance_transaction';
501
+		$post_data['expand[]'] = 'balance_transaction';
502 502
 
503
-		if ( $source->customer ) {
503
+		if ($source->customer) {
504 504
 			$post_data['customer'] = $source->customer;
505 505
 		}
506 506
 
507
-		if ( $source->source ) {
507
+		if ($source->source) {
508 508
 			$post_data['source'] = $source->source;
509 509
 		}
510 510
 
@@ -516,7 +516,7 @@  discard block
 block discarded – undo
516 516
 		 * @param WC_Order $order
517 517
 		 * @param object $source
518 518
 		 */
519
-		return apply_filters( 'wc_stripe_generate_payment_request', $post_data, $order, $source );
519
+		return apply_filters('wc_stripe_generate_payment_request', $post_data, $order, $source);
520 520
 	}
521 521
 
522 522
 	/**
@@ -528,37 +528,37 @@  discard block
 block discarded – undo
528 528
 	 * @throws Exception When card was not added or for and invalid card.
529 529
 	 * @return object
530 530
 	 */
531
-	protected function get_source( $user_id, $force_customer = false ) {
532
-		$stripe_customer = new WC_Stripe_Customer( $user_id );
531
+	protected function get_source($user_id, $force_customer = false) {
532
+		$stripe_customer = new WC_Stripe_Customer($user_id);
533 533
 		$stripe_source   = false;
534 534
 		$token_id        = false;
535 535
 
536 536
 		// New CC info was entered and we have a new token to process
537
-		if ( isset( $_POST['stripe_token'] ) ) {
538
-			$stripe_token     = wc_clean( $_POST['stripe_token'] );
539
-			$maybe_saved_card = isset( $_POST['wc-stripe-new-payment-method'] ) && ! empty( $_POST['wc-stripe-new-payment-method'] );
537
+		if (isset($_POST['stripe_token'])) {
538
+			$stripe_token     = wc_clean($_POST['stripe_token']);
539
+			$maybe_saved_card = isset($_POST['wc-stripe-new-payment-method']) && ! empty($_POST['wc-stripe-new-payment-method']);
540 540
 
541 541
 			// This is true if the user wants to store the card to their account.
542
-			if ( ( $user_id && $this->saved_cards && $maybe_saved_card ) || $force_customer ) {
543
-				$stripe_source = $stripe_customer->add_card( $stripe_token );
542
+			if (($user_id && $this->saved_cards && $maybe_saved_card) || $force_customer) {
543
+				$stripe_source = $stripe_customer->add_card($stripe_token);
544 544
 
545
-				if ( is_wp_error( $stripe_source ) ) {
546
-					throw new Exception( $stripe_source->get_error_message() );
545
+				if (is_wp_error($stripe_source)) {
546
+					throw new Exception($stripe_source->get_error_message());
547 547
 				}
548 548
 			} else {
549 549
 				// Not saving token, so don't define customer either.
550 550
 				$stripe_source   = $stripe_token;
551 551
 				$stripe_customer = false;
552 552
 			}
553
-		} elseif ( isset( $_POST['wc-stripe-payment-token'] ) && 'new' !== $_POST['wc-stripe-payment-token'] ) {
553
+		} elseif (isset($_POST['wc-stripe-payment-token']) && 'new' !== $_POST['wc-stripe-payment-token']) {
554 554
 			// Use an existing token, and then process the payment
555 555
 
556
-			$token_id = wc_clean( $_POST['wc-stripe-payment-token'] );
557
-			$token    = WC_Payment_Tokens::get( $token_id );
556
+			$token_id = wc_clean($_POST['wc-stripe-payment-token']);
557
+			$token    = WC_Payment_Tokens::get($token_id);
558 558
 
559
-			if ( ! $token || $token->get_user_id() !== get_current_user_id() ) {
560
-				WC()->session->set( 'refresh_totals', true );
561
-				throw new Exception( __( 'Invalid payment method. Please input a new card number.', 'woocommerce-gateway-stripe' ) );
559
+			if ( ! $token || $token->get_user_id() !== get_current_user_id()) {
560
+				WC()->session->set('refresh_totals', true);
561
+				throw new Exception(__('Invalid payment method. Please input a new card number.', 'woocommerce-gateway-stripe'));
562 562
 			}
563 563
 
564 564
 			$stripe_source = $token->get_token();
@@ -582,16 +582,16 @@  discard block
 block discarded – undo
582 582
 	 * @param object $order
583 583
 	 * @return object
584 584
 	 */
585
-	protected function get_order_source( $order = null ) {
585
+	protected function get_order_source($order = null) {
586 586
 		$stripe_customer = new WC_Stripe_Customer();
587 587
 		$stripe_source   = false;
588 588
 		$token_id        = false;
589 589
 
590
-		if ( $order ) {
591
-			if ( $meta_value = get_post_meta( $order->id, '_stripe_customer_id', true ) ) {
592
-				$stripe_customer->set_id( $meta_value );
590
+		if ($order) {
591
+			if ($meta_value = get_post_meta($order->id, '_stripe_customer_id', true)) {
592
+				$stripe_customer->set_id($meta_value);
593 593
 			}
594
-			if ( $meta_value = get_post_meta( $order->id, '_stripe_card_id', true ) ) {
594
+			if ($meta_value = get_post_meta($order->id, '_stripe_card_id', true)) {
595 595
 				$stripe_source = $meta_value;
596 596
 			}
597 597
 		}
@@ -614,50 +614,50 @@  discard block
 block discarded – undo
614 614
 	 *
615 615
 	 * @return array|void
616 616
 	 */
617
-	public function process_payment( $order_id, $retry = true, $force_customer = false ) {
617
+	public function process_payment($order_id, $retry = true, $force_customer = false) {
618 618
 		try {
619
-			$order  = wc_get_order( $order_id );
620
-			$source = $this->get_source( get_current_user_id(), $force_customer );
619
+			$order  = wc_get_order($order_id);
620
+			$source = $this->get_source(get_current_user_id(), $force_customer);
621 621
 
622
-			if ( empty( $source->source ) && empty( $source->customer ) ) {
623
-				$error_msg = __( 'Please enter your card details to make a payment.', 'woocommerce-gateway-stripe' );
624
-				$error_msg .= ' ' . __( 'Developers: Please make sure that you are including jQuery and there are no JavaScript errors on the page.', 'woocommerce-gateway-stripe' );
625
-				throw new Exception( $error_msg );
622
+			if (empty($source->source) && empty($source->customer)) {
623
+				$error_msg = __('Please enter your card details to make a payment.', 'woocommerce-gateway-stripe');
624
+				$error_msg .= ' ' . __('Developers: Please make sure that you are including jQuery and there are no JavaScript errors on the page.', 'woocommerce-gateway-stripe');
625
+				throw new Exception($error_msg);
626 626
 			}
627 627
 
628 628
 			// Store source to order meta.
629
-			$this->save_source( $order, $source );
629
+			$this->save_source($order, $source);
630 630
 
631 631
 			// Handle payment.
632
-			if ( $order->get_total() > 0 ) {
632
+			if ($order->get_total() > 0) {
633 633
 
634
-				if ( $order->get_total() * 100 < WC_Stripe::get_minimum_amount() ) {
635
-					throw new Exception( sprintf( __( 'Sorry, the minimum allowed order total is %1$s to use this payment method.', 'woocommerce-gateway-stripe' ), wc_price( WC_Stripe::get_minimum_amount() / 100 ) ) );
634
+				if ($order->get_total() * 100 < WC_Stripe::get_minimum_amount()) {
635
+					throw new Exception(sprintf(__('Sorry, the minimum allowed order total is %1$s to use this payment method.', 'woocommerce-gateway-stripe'), wc_price(WC_Stripe::get_minimum_amount() / 100)));
636 636
 				}
637 637
 
638
-				$this->log( "Info: Begin processing payment for order $order_id for the amount of {$order->get_total()}" );
638
+				$this->log("Info: Begin processing payment for order $order_id for the amount of {$order->get_total()}");
639 639
 
640 640
 				// Make the request.
641
-				$response = WC_Stripe_API::request( $this->generate_payment_request( $order, $source ) );
641
+				$response = WC_Stripe_API::request($this->generate_payment_request($order, $source));
642 642
 
643
-				if ( is_wp_error( $response ) ) {
643
+				if (is_wp_error($response)) {
644 644
 					// Customer param wrong? The user may have been deleted on stripe's end. Remove customer_id. Can be retried without.
645
-					if ( 'customer' === $response->get_error_code() && $retry ) {
646
-						delete_user_meta( get_current_user_id(), '_stripe_customer_id' );
647
-						return $this->process_payment( $order_id, false, $force_customer );
645
+					if ('customer' === $response->get_error_code() && $retry) {
646
+						delete_user_meta(get_current_user_id(), '_stripe_customer_id');
647
+						return $this->process_payment($order_id, false, $force_customer);
648 648
 						// Source param wrong? The CARD may have been deleted on stripe's end. Remove token and show message.
649
-					} elseif ( 'source' === $response->get_error_code() && $source->token_id ) {
650
-						$token = WC_Payment_Tokens::get( $source->token_id );
649
+					} elseif ('source' === $response->get_error_code() && $source->token_id) {
650
+						$token = WC_Payment_Tokens::get($source->token_id);
651 651
 						$token->delete();
652
-						throw new Exception( __( 'This card is no longer available and has been removed.', 'woocommerce-gateway-stripe' ) );
652
+						throw new Exception(__('This card is no longer available and has been removed.', 'woocommerce-gateway-stripe'));
653 653
 					}
654 654
 					$localized_messages = $this->get_localized_messages();
655 655
 
656
-					throw new Exception( ( isset( $localized_messages[ $response->get_error_code() ] ) ? $localized_messages[ $response->get_error_code() ] : $response->get_error_message() ) );
656
+					throw new Exception((isset($localized_messages[$response->get_error_code()]) ? $localized_messages[$response->get_error_code()] : $response->get_error_message()));
657 657
 				}
658 658
 
659 659
 				// Process valid response.
660
-				$this->process_response( $response, $order );
660
+				$this->process_response($response, $order);
661 661
 			} else {
662 662
 				$order->payment_complete();
663 663
 			}
@@ -665,23 +665,23 @@  discard block
 block discarded – undo
665 665
 			// Remove cart.
666 666
 			WC()->cart->empty_cart();
667 667
 
668
-			do_action( 'wc_gateway_stripe_process_payment', $response, $order );
668
+			do_action('wc_gateway_stripe_process_payment', $response, $order);
669 669
 
670 670
 			// Return thank you page redirect.
671 671
 			return array(
672 672
 				'result'   => 'success',
673
-				'redirect' => $this->get_return_url( $order ),
673
+				'redirect' => $this->get_return_url($order),
674 674
 			);
675 675
 
676
-		} catch ( Exception $e ) {
677
-			wc_add_notice( $e->getMessage(), 'error' );
678
-			$this->log( sprintf( __( 'Error: %s', 'woocommerce-gateway-stripe' ), $e->getMessage() ) );
676
+		} catch (Exception $e) {
677
+			wc_add_notice($e->getMessage(), 'error');
678
+			$this->log(sprintf(__('Error: %s', 'woocommerce-gateway-stripe'), $e->getMessage()));
679 679
 
680
-			if ( $order->has_status( array( 'pending', 'failed' ) ) ) {
681
-				$this->send_failed_order_email( $order_id );
680
+			if ($order->has_status(array('pending', 'failed'))) {
681
+				$this->send_failed_order_email($order_id);
682 682
 			}
683 683
 
684
-			do_action( 'wc_gateway_stripe_process_payment_error', $e, $order );
684
+			do_action('wc_gateway_stripe_process_payment_error', $e, $order);
685 685
 
686 686
 			return array(
687 687
 				'result'   => 'fail',
@@ -696,52 +696,52 @@  discard block
 block discarded – undo
696 696
 	 * @param WC_Order $order For to which the source applies.
697 697
 	 * @param stdClass $source Source information.
698 698
 	 */
699
-	protected function save_source( $order, $source ) {
699
+	protected function save_source($order, $source) {
700 700
 		// Store source in the order.
701
-		if ( $source->customer ) {
702
-			update_post_meta( $order->id, '_stripe_customer_id', $source->customer );
701
+		if ($source->customer) {
702
+			update_post_meta($order->id, '_stripe_customer_id', $source->customer);
703 703
 		}
704
-		if ( $source->source ) {
705
-			update_post_meta( $order->id, '_stripe_card_id', $source->source );
704
+		if ($source->source) {
705
+			update_post_meta($order->id, '_stripe_card_id', $source->source);
706 706
 		}
707 707
 	}
708 708
 
709 709
 	/**
710 710
 	 * Store extra meta data for an order from a Stripe Response.
711 711
 	 */
712
-	public function process_response( $response, $order ) {
713
-		$this->log( 'Processing response: ' . print_r( $response, true ) );
712
+	public function process_response($response, $order) {
713
+		$this->log('Processing response: ' . print_r($response, true));
714 714
 
715 715
 		// Store charge data
716
-		update_post_meta( $order->id, '_stripe_charge_id', $response->id );
717
-		update_post_meta( $order->id, '_stripe_charge_captured', $response->captured ? 'yes' : 'no' );
716
+		update_post_meta($order->id, '_stripe_charge_id', $response->id);
717
+		update_post_meta($order->id, '_stripe_charge_captured', $response->captured ? 'yes' : 'no');
718 718
 
719 719
 		// Store other data such as fees
720
-		if ( isset( $response->balance_transaction ) && isset( $response->balance_transaction->fee ) ) {
720
+		if (isset($response->balance_transaction) && isset($response->balance_transaction->fee)) {
721 721
 			// Fees and Net needs to both come from Stripe to be accurate as the returned
722 722
 			// values are in the local currency of the Stripe account, not from WC.
723
-			$fee = ! empty( $response->balance_transaction->fee ) ? number_format( $response->balance_transaction->fee / 100, 2, '.', '' ) : 0;
724
-			$net = ! empty( $response->balance_transaction->net ) ? number_format( $response->balance_transaction->net / 100, 2, '.', '' ) : 0;
725
-			update_post_meta( $order->id, 'Stripe Fee', $fee );
726
-			update_post_meta( $order->id, 'Net Revenue From Stripe', $net );
723
+			$fee = ! empty($response->balance_transaction->fee) ? number_format($response->balance_transaction->fee / 100, 2, '.', '') : 0;
724
+			$net = ! empty($response->balance_transaction->net) ? number_format($response->balance_transaction->net / 100, 2, '.', '') : 0;
725
+			update_post_meta($order->id, 'Stripe Fee', $fee);
726
+			update_post_meta($order->id, 'Net Revenue From Stripe', $net);
727 727
 		}
728 728
 
729
-		if ( $response->captured ) {
730
-			$order->payment_complete( $response->id );
729
+		if ($response->captured) {
730
+			$order->payment_complete($response->id);
731 731
 
732
-			$message = sprintf( __( 'Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe' ), $response->id );
733
-			$order->add_order_note( $message );
734
-			$this->log( 'Success: ' . $message );
732
+			$message = sprintf(__('Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe'), $response->id);
733
+			$order->add_order_note($message);
734
+			$this->log('Success: ' . $message);
735 735
 
736 736
 		} else {
737
-			add_post_meta( $order->id, '_transaction_id', $response->id, true );
737
+			add_post_meta($order->id, '_transaction_id', $response->id, true);
738 738
 
739
-			if ( $order->has_status( array( 'pending', 'failed' ) ) ) {
739
+			if ($order->has_status(array('pending', 'failed'))) {
740 740
 				$order->reduce_order_stock();
741 741
 			}
742 742
 
743
-			$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 ) );
744
-			$this->log( "Successful auth: $response->id" );
743
+			$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));
744
+			$this->log("Successful auth: $response->id");
745 745
 		}
746 746
 
747 747
 		return $response;
@@ -753,32 +753,32 @@  discard block
 block discarded – undo
753 753
 	 * @since 3.0.0
754 754
 	 */
755 755
 	public function add_payment_method() {
756
-		if ( empty( $_POST['stripe_token'] ) || ! is_user_logged_in() ) {
757
-			wc_add_notice( __( 'There was a problem adding the card.', 'woocommerce-gateway-stripe' ), 'error' );
756
+		if (empty($_POST['stripe_token']) || ! is_user_logged_in()) {
757
+			wc_add_notice(__('There was a problem adding the card.', 'woocommerce-gateway-stripe'), 'error');
758 758
 			return;
759 759
 		}
760 760
 
761
-		$stripe_customer = new WC_Stripe_Customer( get_current_user_id() );
762
-		$card            = $stripe_customer->add_card( wc_clean( $_POST['stripe_token'] ) );
761
+		$stripe_customer = new WC_Stripe_Customer(get_current_user_id());
762
+		$card            = $stripe_customer->add_card(wc_clean($_POST['stripe_token']));
763 763
 
764
-		if ( is_wp_error( $card ) ) {
764
+		if (is_wp_error($card)) {
765 765
 			$localized_messages = $this->get_localized_messages();
766
-			$error_msg = __( 'There was a problem adding the card.', 'woocommerce-gateway-stripe' );
766
+			$error_msg = __('There was a problem adding the card.', 'woocommerce-gateway-stripe');
767 767
 
768 768
 			// loop through the errors to find matching localized message
769
-			foreach ( $card->errors as $error => $msg ) {
770
-				if ( isset( $localized_messages[ $error ] ) ) {
771
-					$error_msg = $localized_messages[ $error ];
769
+			foreach ($card->errors as $error => $msg) {
770
+				if (isset($localized_messages[$error])) {
771
+					$error_msg = $localized_messages[$error];
772 772
 				}
773 773
 			}
774 774
 
775
-			wc_add_notice( $error_msg, 'error' );
775
+			wc_add_notice($error_msg, 'error');
776 776
 			return;
777 777
 		}
778 778
 
779 779
 		return array(
780 780
 			'result'   => 'success',
781
-			'redirect' => wc_get_endpoint_url( 'payment-methods' ),
781
+			'redirect' => wc_get_endpoint_url('payment-methods'),
782 782
 		);
783 783
 	}
784 784
 
@@ -788,36 +788,36 @@  discard block
 block discarded – undo
788 788
 	 * @param  float $amount
789 789
 	 * @return bool
790 790
 	 */
791
-	public function process_refund( $order_id, $amount = null, $reason = '' ) {
792
-		$order = wc_get_order( $order_id );
791
+	public function process_refund($order_id, $amount = null, $reason = '') {
792
+		$order = wc_get_order($order_id);
793 793
 
794
-		if ( ! $order || ! $order->get_transaction_id() ) {
794
+		if ( ! $order || ! $order->get_transaction_id()) {
795 795
 			return false;
796 796
 		}
797 797
 
798 798
 		$body = array();
799 799
 
800
-		if ( ! is_null( $amount ) ) {
801
-			$body['amount']	= $this->get_stripe_amount( $amount );
800
+		if ( ! is_null($amount)) {
801
+			$body['amount'] = $this->get_stripe_amount($amount);
802 802
 		}
803 803
 
804
-		if ( $reason ) {
804
+		if ($reason) {
805 805
 			$body['metadata'] = array(
806 806
 				'reason'	=> $reason,
807 807
 			);
808 808
 		}
809 809
 
810
-		$this->log( "Info: Beginning refund for order $order_id for the amount of {$amount}" );
810
+		$this->log("Info: Beginning refund for order $order_id for the amount of {$amount}");
811 811
 
812
-		$response = WC_Stripe_API::request( $body, 'charges/' . $order->get_transaction_id() . '/refunds' );
812
+		$response = WC_Stripe_API::request($body, 'charges/' . $order->get_transaction_id() . '/refunds');
813 813
 
814
-		if ( is_wp_error( $response ) ) {
815
-			$this->log( 'Error: ' . $response->get_error_message() );
814
+		if (is_wp_error($response)) {
815
+			$this->log('Error: ' . $response->get_error_message());
816 816
 			return $response;
817
-		} elseif ( ! empty( $response->id ) ) {
818
-			$refund_message = sprintf( __( 'Refunded %1$s - Refund ID: %2$s - Reason: %3$s', 'woocommerce-gateway-stripe' ), wc_price( $response->amount / 100 ), $response->id, $reason );
819
-			$order->add_order_note( $refund_message );
820
-			$this->log( 'Success: ' . html_entity_decode( strip_tags( $refund_message ) ) );
817
+		} elseif ( ! empty($response->id)) {
818
+			$refund_message = sprintf(__('Refunded %1$s - Refund ID: %2$s - Reason: %3$s', 'woocommerce-gateway-stripe'), wc_price($response->amount / 100), $response->id, $reason);
819
+			$order->add_order_note($refund_message);
820
+			$this->log('Success: ' . html_entity_decode(strip_tags($refund_message)));
821 821
 			return true;
822 822
 		}
823 823
 	}
@@ -830,10 +830,10 @@  discard block
 block discarded – undo
830 830
 	 * @param int $order_id
831 831
 	 * @return null
832 832
 	 */
833
-	public function send_failed_order_email( $order_id ) {
833
+	public function send_failed_order_email($order_id) {
834 834
 		$emails = WC()->mailer()->get_emails();
835
-		if ( ! empty( $emails ) && ! empty( $order_id ) ) {
836
-			$emails['WC_Email_Failed_Order']->trigger( $order_id );
835
+		if ( ! empty($emails) && ! empty($order_id)) {
836
+			$emails['WC_Email_Failed_Order']->trigger($order_id);
837 837
 		}
838 838
 	}
839 839
 
@@ -845,9 +845,9 @@  discard block
 block discarded – undo
845 845
 	 *
846 846
 	 * @param string $message
847 847
 	 */
848
-	public function log( $message ) {
849
-		if ( $this->logging ) {
850
-			WC_Stripe::log( $message );
848
+	public function log($message) {
849
+		if ($this->logging) {
850
+			WC_Stripe::log($message);
851 851
 		}
852 852
 	}
853 853
 }
Please login to merge, or discard this patch.
includes/class-wc-gateway-stripe-addons.php 1 patch
Spacing   +125 added lines, -125 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) {
2
+if ( ! defined('ABSPATH')) {
3 3
 	exit;
4 4
 }
5 5
 
@@ -16,22 +16,22 @@  discard block
 block discarded – undo
16 16
 	public function __construct() {
17 17
 		parent::__construct();
18 18
 
19
-		if ( class_exists( 'WC_Subscriptions_Order' ) ) {
20
-			add_action( 'woocommerce_scheduled_subscription_payment_' . $this->id, array( $this, 'scheduled_subscription_payment' ), 10, 2 );
21
-			add_action( 'wcs_resubscribe_order_created', array( $this, 'delete_resubscribe_meta' ), 10 );
22
-			add_action( 'wcs_renewal_order_created', array( $this, 'delete_renewal_meta' ), 10 );
23
-			add_action( 'woocommerce_subscription_failing_payment_method_updated_stripe', array( $this, 'update_failing_payment_method' ), 10, 2 );
19
+		if (class_exists('WC_Subscriptions_Order')) {
20
+			add_action('woocommerce_scheduled_subscription_payment_' . $this->id, array($this, 'scheduled_subscription_payment'), 10, 2);
21
+			add_action('wcs_resubscribe_order_created', array($this, 'delete_resubscribe_meta'), 10);
22
+			add_action('wcs_renewal_order_created', array($this, 'delete_renewal_meta'), 10);
23
+			add_action('woocommerce_subscription_failing_payment_method_updated_stripe', array($this, 'update_failing_payment_method'), 10, 2);
24 24
 
25 25
 			// display the credit card used for a subscription in the "My Subscriptions" table
26
-			add_filter( 'woocommerce_my_subscriptions_payment_method', array( $this, 'maybe_render_subscription_payment_method' ), 10, 2 );
26
+			add_filter('woocommerce_my_subscriptions_payment_method', array($this, 'maybe_render_subscription_payment_method'), 10, 2);
27 27
 
28 28
 			// allow store managers to manually set Stripe as the payment method on a subscription
29
-			add_filter( 'woocommerce_subscription_payment_meta', array( $this, 'add_subscription_payment_meta' ), 10, 2 );
30
-			add_filter( 'woocommerce_subscription_validate_payment_meta', array( $this, 'validate_subscription_payment_meta' ), 10, 2 );
29
+			add_filter('woocommerce_subscription_payment_meta', array($this, 'add_subscription_payment_meta'), 10, 2);
30
+			add_filter('woocommerce_subscription_validate_payment_meta', array($this, 'validate_subscription_payment_meta'), 10, 2);
31 31
 		}
32 32
 
33
-		if ( class_exists( 'WC_Pre_Orders_Order' ) ) {
34
-			add_action( 'wc_pre_orders_process_pre_order_completion_payment_' . $this->id, array( $this, 'process_pre_order_release_payment' ) );
33
+		if (class_exists('WC_Pre_Orders_Order')) {
34
+			add_action('wc_pre_orders_process_pre_order_completion_payment_' . $this->id, array($this, 'process_pre_order_release_payment'));
35 35
 		}
36 36
 	}
37 37
 
@@ -40,8 +40,8 @@  discard block
 block discarded – undo
40 40
 	 * @param  int  $order_id
41 41
 	 * @return boolean
42 42
 	 */
43
-	protected function is_subscription( $order_id ) {
44
-		return ( function_exists( 'wcs_order_contains_subscription' ) && ( wcs_order_contains_subscription( $order_id ) || wcs_is_subscription( $order_id ) || wcs_order_contains_renewal( $order_id ) ) );
43
+	protected function is_subscription($order_id) {
44
+		return (function_exists('wcs_order_contains_subscription') && (wcs_order_contains_subscription($order_id) || wcs_is_subscription($order_id) || wcs_order_contains_renewal($order_id)));
45 45
 	}
46 46
 
47 47
 	/**
@@ -49,8 +49,8 @@  discard block
 block discarded – undo
49 49
 	 * @param  int  $order_id
50 50
 	 * @return boolean
51 51
 	 */
52
-	protected function is_pre_order( $order_id ) {
53
-		return ( class_exists( 'WC_Pre_Orders_Order' ) && WC_Pre_Orders_Order::order_contains_pre_order( $order_id ) );
52
+	protected function is_pre_order($order_id) {
53
+		return (class_exists('WC_Pre_Orders_Order') && WC_Pre_Orders_Order::order_contains_pre_order($order_id));
54 54
 	}
55 55
 
56 56
 	/**
@@ -58,37 +58,37 @@  discard block
 block discarded – undo
58 58
 	 * @param  int $order_id
59 59
 	 * @return array
60 60
 	 */
61
-	public function process_payment( $order_id, $retry = true, $force_customer = false ) {
62
-		if ( $this->is_subscription( $order_id ) ) {
61
+	public function process_payment($order_id, $retry = true, $force_customer = false) {
62
+		if ($this->is_subscription($order_id)) {
63 63
 			// Regular payment with force customer enabled
64
-			return parent::process_payment( $order_id, true, true );
64
+			return parent::process_payment($order_id, true, true);
65 65
 
66
-		} elseif ( $this->is_pre_order( $order_id ) ) {
67
-			return $this->process_pre_order( $order_id, $retry, $force_customer );
66
+		} elseif ($this->is_pre_order($order_id)) {
67
+			return $this->process_pre_order($order_id, $retry, $force_customer);
68 68
 
69 69
 		} else {
70
-			return parent::process_payment( $order_id, $retry, $force_customer );
70
+			return parent::process_payment($order_id, $retry, $force_customer);
71 71
 		}
72 72
 	}
73 73
 
74 74
 	/**
75 75
 	 * Updates other subscription sources.
76 76
 	 */
77
-	protected function save_source( $order, $source ) {
78
-		parent::save_source( $order, $source );
77
+	protected function save_source($order, $source) {
78
+		parent::save_source($order, $source);
79 79
 
80 80
 		// Also store it on the subscriptions being purchased or paid for in the order
81
-		if ( function_exists( 'wcs_order_contains_subscription' ) && wcs_order_contains_subscription( $order->id ) ) {
82
-			$subscriptions = wcs_get_subscriptions_for_order( $order->id );
83
-		} elseif ( function_exists( 'wcs_order_contains_renewal' ) && wcs_order_contains_renewal( $order->id ) ) {
84
-			$subscriptions = wcs_get_subscriptions_for_renewal_order( $order->id );
81
+		if (function_exists('wcs_order_contains_subscription') && wcs_order_contains_subscription($order->id)) {
82
+			$subscriptions = wcs_get_subscriptions_for_order($order->id);
83
+		} elseif (function_exists('wcs_order_contains_renewal') && wcs_order_contains_renewal($order->id)) {
84
+			$subscriptions = wcs_get_subscriptions_for_renewal_order($order->id);
85 85
 		} else {
86 86
 			$subscriptions = array();
87 87
 		}
88 88
 
89
-		foreach ( $subscriptions as $subscription ) {
90
-			update_post_meta( $subscription->id, '_stripe_customer_id', $source->customer );
91
-			update_post_meta( $subscription->id, '_stripe_card_id', $source->source );
89
+		foreach ($subscriptions as $subscription) {
90
+			update_post_meta($subscription->id, '_stripe_customer_id', $source->customer);
91
+			update_post_meta($subscription->id, '_stripe_card_id', $source->source);
92 92
 		}
93 93
 	}
94 94
 
@@ -99,38 +99,38 @@  discard block
 block discarded – undo
99 99
 	 * @param string $stripe_token (default: '')
100 100
 	 * @param  bool initial_payment
101 101
 	 */
102
-	public function process_subscription_payment( $order = '', $amount = 0 ) {
103
-		if ( $amount * 100 < WC_Stripe::get_minimum_amount() ) {
104
-			return new WP_Error( 'stripe_error', sprintf( __( 'Sorry, the minimum allowed order total is %1$s to use this payment method.', 'woocommerce-gateway-stripe' ), wc_price( WC_Stripe::get_minimum_amount() / 100 ) ) );
102
+	public function process_subscription_payment($order = '', $amount = 0) {
103
+		if ($amount * 100 < WC_Stripe::get_minimum_amount()) {
104
+			return new WP_Error('stripe_error', sprintf(__('Sorry, the minimum allowed order total is %1$s to use this payment method.', 'woocommerce-gateway-stripe'), wc_price(WC_Stripe::get_minimum_amount() / 100)));
105 105
 		}
106 106
 
107 107
 		// Get source from order
108
-		$source = $this->get_order_source( $order );
108
+		$source = $this->get_order_source($order);
109 109
 
110 110
 		// If no order source was defined, use user source instead.
111
-		if ( ! $source->customer ) {
112
-			$source = $this->get_source( $order->customer_user );
111
+		if ( ! $source->customer) {
112
+			$source = $this->get_source($order->customer_user);
113 113
 		}
114 114
 
115 115
 		// Or fail :(
116
-		if ( ! $source->customer ) {
117
-			return new WP_Error( 'stripe_error', __( 'Customer not found', 'woocommerce-gateway-stripe' ) );
116
+		if ( ! $source->customer) {
117
+			return new WP_Error('stripe_error', __('Customer not found', 'woocommerce-gateway-stripe'));
118 118
 		}
119 119
 
120
-		$this->log( "Info: Begin processing subscription payment for order {$order->id} for the amount of {$amount}" );
120
+		$this->log("Info: Begin processing subscription payment for order {$order->id} for the amount of {$amount}");
121 121
 
122 122
 		// Make the request
123
-		$request             = $this->generate_payment_request( $order, $source );
123
+		$request             = $this->generate_payment_request($order, $source);
124 124
 		$request['capture']  = 'true';
125
-		$request['amount']   = $this->get_stripe_amount( $amount, $request['currency'] );
125
+		$request['amount']   = $this->get_stripe_amount($amount, $request['currency']);
126 126
 		$request['metadata'] = array(
127 127
 			'payment_type'   => 'recurring',
128 128
 		);
129
-		$response            = WC_Stripe_API::request( $request );
129
+		$response            = WC_Stripe_API::request($request);
130 130
 
131 131
 		// Process valid response
132
-		if ( ! is_wp_error( $response ) ) {
133
-			$this->process_response( $response, $order );
132
+		if ( ! is_wp_error($response)) {
133
+			$this->process_response($response, $order);
134 134
 		}
135 135
 
136 136
 		return $response;
@@ -141,42 +141,42 @@  discard block
 block discarded – undo
141 141
 	 * @param int $order_id
142 142
 	 * @return array
143 143
 	 */
144
-	public function process_pre_order( $order_id, $retry, $force_customer ) {
145
-		if ( WC_Pre_Orders_Order::order_requires_payment_tokenization( $order_id ) ) {
144
+	public function process_pre_order($order_id, $retry, $force_customer) {
145
+		if (WC_Pre_Orders_Order::order_requires_payment_tokenization($order_id)) {
146 146
 			try {
147
-				$order = wc_get_order( $order_id );
147
+				$order = wc_get_order($order_id);
148 148
 
149
-				if ( $order->get_total() * 100 < WC_Stripe::get_minimum_amount() ) {
150
-					throw new Exception( sprintf( __( 'Sorry, the minimum allowed order total is %1$s to use this payment method.', 'woocommerce-gateway-stripe' ), wc_price( WC_Stripe::get_minimum_amount() / 100 ) ) );
149
+				if ($order->get_total() * 100 < WC_Stripe::get_minimum_amount()) {
150
+					throw new Exception(sprintf(__('Sorry, the minimum allowed order total is %1$s to use this payment method.', 'woocommerce-gateway-stripe'), wc_price(WC_Stripe::get_minimum_amount() / 100)));
151 151
 				}
152 152
 
153
-				$source = $this->get_source( get_current_user_id(), true );
153
+				$source = $this->get_source(get_current_user_id(), true);
154 154
 
155 155
 				// We need a source on file to continue.
156
-				if ( empty( $source->customer ) || empty( $source->source ) ) {
157
-					throw new Exception( __( 'Unable to store payment details. Please try again.', 'woocommerce-gateway-stripe' ) );
156
+				if (empty($source->customer) || empty($source->source)) {
157
+					throw new Exception(__('Unable to store payment details. Please try again.', 'woocommerce-gateway-stripe'));
158 158
 				}
159 159
 
160 160
 				// Store source to order meta
161
-				$this->save_source( $order, $source );
161
+				$this->save_source($order, $source);
162 162
 
163 163
 				// Remove cart
164 164
 				WC()->cart->empty_cart();
165 165
 
166 166
 				// Is pre ordered!
167
-				WC_Pre_Orders_Order::mark_order_as_pre_ordered( $order );
167
+				WC_Pre_Orders_Order::mark_order_as_pre_ordered($order);
168 168
 
169 169
 				// Return thank you page redirect
170 170
 				return array(
171 171
 					'result'   => 'success',
172
-					'redirect' => $this->get_return_url( $order ),
172
+					'redirect' => $this->get_return_url($order),
173 173
 				);
174
-			} catch ( Exception $e ) {
175
-				wc_add_notice( $e->getMessage(), 'error' );
174
+			} catch (Exception $e) {
175
+				wc_add_notice($e->getMessage(), 'error');
176 176
 				return;
177 177
 			}
178 178
 		} else {
179
-			return parent::process_payment( $order_id, $retry, $force_customer );
179
+			return parent::process_payment($order_id, $retry, $force_customer);
180 180
 		}
181 181
 	}
182 182
 
@@ -185,7 +185,7 @@  discard block
 block discarded – undo
185 185
 	 * @param WC_Order $order
186 186
 	 * @return void
187 187
 	 */
188
-	public function process_pre_order_release_payment( $order ) {
188
+	public function process_pre_order_release_payment($order) {
189 189
 		try {
190 190
 			// Define some callbacks if the first attempt fails.
191 191
 			$retry_callbacks = array(
@@ -193,32 +193,32 @@  discard block
 block discarded – undo
193 193
 				'remove_order_customer_before_retry',
194 194
 			);
195 195
 
196
-			while ( 1 ) {
197
-				$source   = $this->get_order_source( $order );
198
-				$response = WC_Stripe_API::request( $this->generate_payment_request( $order, $source ) );
196
+			while (1) {
197
+				$source   = $this->get_order_source($order);
198
+				$response = WC_Stripe_API::request($this->generate_payment_request($order, $source));
199 199
 
200
-				if ( is_wp_error( $response ) ) {
201
-					if ( 0 === sizeof( $retry_callbacks ) ) {
202
-						throw new Exception( $response->get_error_message() );
200
+				if (is_wp_error($response)) {
201
+					if (0 === sizeof($retry_callbacks)) {
202
+						throw new Exception($response->get_error_message());
203 203
 					} else {
204
-						$retry_callback = array_shift( $retry_callbacks );
205
-						call_user_func( array( $this, $retry_callback ), $order );
204
+						$retry_callback = array_shift($retry_callbacks);
205
+						call_user_func(array($this, $retry_callback), $order);
206 206
 					}
207 207
 				} else {
208 208
 					// Successful
209
-					$this->process_response( $response, $order );
209
+					$this->process_response($response, $order);
210 210
 					break;
211 211
 				}
212 212
 			}
213
-		} catch ( Exception $e ) {
214
-			$order_note = sprintf( __( 'Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe' ), $e->getMessage() );
213
+		} catch (Exception $e) {
214
+			$order_note = sprintf(__('Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe'), $e->getMessage());
215 215
 
216 216
 			// Mark order as failed if not already set,
217 217
 			// otherwise, make sure we add the order note so we can detect when someone fails to check out multiple times
218
-			if ( ! $order->has_status( 'failed' ) ) {
219
-				$order->update_status( 'failed', $order_note );
218
+			if ( ! $order->has_status('failed')) {
219
+				$order->update_status('failed', $order_note);
220 220
 			} else {
221
-				$order->add_order_note( $order_note );
221
+				$order->add_order_note($order_note);
222 222
 			}
223 223
 		}
224 224
 	}
@@ -227,20 +227,20 @@  discard block
 block discarded – undo
227 227
 	 * Don't transfer Stripe customer/token meta to resubscribe orders.
228 228
 	 * @param int $resubscribe_order The order created for the customer to resubscribe to the old expired/cancelled subscription
229 229
 	 */
230
-	public function delete_resubscribe_meta( $resubscribe_order ) {
231
-		delete_post_meta( $resubscribe_order->id, '_stripe_customer_id' );
232
-		delete_post_meta( $resubscribe_order->id, '_stripe_card_id' );
233
-		$this->delete_renewal_meta( $resubscribe_order );
230
+	public function delete_resubscribe_meta($resubscribe_order) {
231
+		delete_post_meta($resubscribe_order->id, '_stripe_customer_id');
232
+		delete_post_meta($resubscribe_order->id, '_stripe_card_id');
233
+		$this->delete_renewal_meta($resubscribe_order);
234 234
 	}
235 235
 
236 236
 	/**
237 237
 	 * Don't transfer Stripe fee/ID meta to renewal orders.
238 238
 	 * @param int $resubscribe_order The order created for the customer to resubscribe to the old expired/cancelled subscription
239 239
 	 */
240
-	public function delete_renewal_meta( $renewal_order ) {
241
-		delete_post_meta( $renewal_order->id, 'Stripe Fee' );
242
-		delete_post_meta( $renewal_order->id, 'Net Revenue From Stripe' );
243
-		delete_post_meta( $renewal_order->id, 'Stripe Payment ID' );
240
+	public function delete_renewal_meta($renewal_order) {
241
+		delete_post_meta($renewal_order->id, 'Stripe Fee');
242
+		delete_post_meta($renewal_order->id, 'Net Revenue From Stripe');
243
+		delete_post_meta($renewal_order->id, 'Stripe Payment ID');
244 244
 		return $renewal_order;
245 245
 	}
246 246
 
@@ -250,11 +250,11 @@  discard block
 block discarded – undo
250 250
 	 * @param $amount_to_charge float The amount to charge.
251 251
 	 * @param $renewal_order WC_Order A WC_Order object created to record the renewal payment.
252 252
 	 */
253
-	public function scheduled_subscription_payment( $amount_to_charge, $renewal_order ) {
254
-		$response = $this->process_subscription_payment( $renewal_order, $amount_to_charge );
253
+	public function scheduled_subscription_payment($amount_to_charge, $renewal_order) {
254
+		$response = $this->process_subscription_payment($renewal_order, $amount_to_charge);
255 255
 
256
-		if ( is_wp_error( $response ) ) {
257
-			$renewal_order->update_status( 'failed', sprintf( __( 'Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe' ), $response->get_error_message() ) );
256
+		if (is_wp_error($response)) {
257
+			$renewal_order->update_status('failed', sprintf(__('Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe'), $response->get_error_message()));
258 258
 		}
259 259
 	}
260 260
 
@@ -262,16 +262,16 @@  discard block
 block discarded – undo
262 262
 	 * Remove order meta
263 263
 	 * @param  object $order
264 264
 	 */
265
-	public function remove_order_source_before_retry( $order ) {
266
-		delete_post_meta( $order->id, '_stripe_card_id' );
265
+	public function remove_order_source_before_retry($order) {
266
+		delete_post_meta($order->id, '_stripe_card_id');
267 267
 	}
268 268
 
269 269
 	/**
270 270
 	 * Remove order meta
271 271
 	 * @param  object $order
272 272
 	 */
273
-	public function remove_order_customer_before_retry( $order ) {
274
-		delete_post_meta( $order->id, '_stripe_customer_id' );
273
+	public function remove_order_customer_before_retry($order) {
274
+		delete_post_meta($order->id, '_stripe_customer_id');
275 275
 	}
276 276
 
277 277
 	/**
@@ -283,9 +283,9 @@  discard block
 block discarded – undo
283 283
 	 * @param WC_Order $renewal_order The order which recorded the successful payment (to make up for the failed automatic payment).
284 284
 	 * @return void
285 285
 	 */
286
-	public function update_failing_payment_method( $subscription, $renewal_order ) {
287
-		update_post_meta( $subscription->id, '_stripe_customer_id', $renewal_order->stripe_customer_id );
288
-		update_post_meta( $subscription->id, '_stripe_card_id', $renewal_order->stripe_card_id );
286
+	public function update_failing_payment_method($subscription, $renewal_order) {
287
+		update_post_meta($subscription->id, '_stripe_customer_id', $renewal_order->stripe_customer_id);
288
+		update_post_meta($subscription->id, '_stripe_card_id', $renewal_order->stripe_card_id);
289 289
 	}
290 290
 
291 291
 	/**
@@ -297,15 +297,15 @@  discard block
 block discarded – undo
297 297
 	 * @param WC_Subscription $subscription An instance of a subscription object
298 298
 	 * @return array
299 299
 	 */
300
-	public function add_subscription_payment_meta( $payment_meta, $subscription ) {
301
-		$payment_meta[ $this->id ] = array(
300
+	public function add_subscription_payment_meta($payment_meta, $subscription) {
301
+		$payment_meta[$this->id] = array(
302 302
 			'post_meta' => array(
303 303
 				'_stripe_customer_id' => array(
304
-					'value' => get_post_meta( $subscription->id, '_stripe_customer_id', true ),
304
+					'value' => get_post_meta($subscription->id, '_stripe_customer_id', true),
305 305
 					'label' => 'Stripe Customer ID',
306 306
 				),
307 307
 				'_stripe_card_id' => array(
308
-					'value' => get_post_meta( $subscription->id, '_stripe_card_id', true ),
308
+					'value' => get_post_meta($subscription->id, '_stripe_card_id', true),
309 309
 					'label' => 'Stripe Card ID',
310 310
 				),
311 311
 			),
@@ -322,17 +322,17 @@  discard block
 block discarded – undo
322 322
 	 * @param array $payment_meta associative array of meta data required for automatic payments
323 323
 	 * @return array
324 324
 	 */
325
-	public function validate_subscription_payment_meta( $payment_method_id, $payment_meta ) {
326
-		if ( $this->id === $payment_method_id ) {
325
+	public function validate_subscription_payment_meta($payment_method_id, $payment_meta) {
326
+		if ($this->id === $payment_method_id) {
327 327
 
328
-			if ( ! isset( $payment_meta['post_meta']['_stripe_customer_id']['value'] ) || empty( $payment_meta['post_meta']['_stripe_customer_id']['value'] ) ) {
329
-				throw new Exception( 'A "_stripe_customer_id" value is required.' );
330
-			} elseif ( 0 !== strpos( $payment_meta['post_meta']['_stripe_customer_id']['value'], 'cus_' ) ) {
331
-				throw new Exception( 'Invalid customer ID. A valid "_stripe_customer_id" must begin with "cus_".' );
328
+			if ( ! isset($payment_meta['post_meta']['_stripe_customer_id']['value']) || empty($payment_meta['post_meta']['_stripe_customer_id']['value'])) {
329
+				throw new Exception('A "_stripe_customer_id" value is required.');
330
+			} elseif (0 !== strpos($payment_meta['post_meta']['_stripe_customer_id']['value'], 'cus_')) {
331
+				throw new Exception('Invalid customer ID. A valid "_stripe_customer_id" must begin with "cus_".');
332 332
 			}
333 333
 
334
-			if ( ! empty( $payment_meta['post_meta']['_stripe_card_id']['value'] ) && 0 !== strpos( $payment_meta['post_meta']['_stripe_card_id']['value'], 'card_' ) ) {
335
-				throw new Exception( 'Invalid card ID. A valid "_stripe_card_id" must begin with "card_".' );
334
+			if ( ! empty($payment_meta['post_meta']['_stripe_card_id']['value']) && 0 !== strpos($payment_meta['post_meta']['_stripe_card_id']['value'], 'card_')) {
335
+				throw new Exception('Invalid card ID. A valid "_stripe_card_id" must begin with "card_".');
336 336
 			}
337 337
 		}
338 338
 	}
@@ -345,43 +345,43 @@  discard block
 block discarded – undo
345 345
 	 * @param WC_Subscription $subscription the subscription details
346 346
 	 * @return string the subscription payment method
347 347
 	 */
348
-	public function maybe_render_subscription_payment_method( $payment_method_to_display, $subscription ) {
348
+	public function maybe_render_subscription_payment_method($payment_method_to_display, $subscription) {
349 349
 		// bail for other payment methods
350
-		if ( $this->id !== $subscription->payment_method || ! $subscription->customer_user ) {
350
+		if ($this->id !== $subscription->payment_method || ! $subscription->customer_user) {
351 351
 			return $payment_method_to_display;
352 352
 		}
353 353
 
354 354
 		$stripe_customer    = new WC_Stripe_Customer();
355
-		$stripe_customer_id = get_post_meta( $subscription->id, '_stripe_customer_id', true );
356
-		$stripe_card_id     = get_post_meta( $subscription->id, '_stripe_card_id', true );
355
+		$stripe_customer_id = get_post_meta($subscription->id, '_stripe_customer_id', true);
356
+		$stripe_card_id     = get_post_meta($subscription->id, '_stripe_card_id', true);
357 357
 
358 358
 		// If we couldn't find a Stripe customer linked to the subscription, fallback to the user meta data.
359
-		if ( ! $stripe_customer_id || ! is_string( $stripe_customer_id ) ) {
359
+		if ( ! $stripe_customer_id || ! is_string($stripe_customer_id)) {
360 360
 			$user_id            = $subscription->customer_user;
361
-			$stripe_customer_id = get_user_meta( $user_id, '_stripe_customer_id', true );
362
-			$stripe_card_id     = get_user_meta( $user_id, '_stripe_card_id', true );
361
+			$stripe_customer_id = get_user_meta($user_id, '_stripe_customer_id', true);
362
+			$stripe_card_id     = get_user_meta($user_id, '_stripe_card_id', true);
363 363
 		}
364 364
 
365 365
 		// If we couldn't find a Stripe customer linked to the account, fallback to the order meta data.
366
-		if ( ( ! $stripe_customer_id || ! is_string( $stripe_customer_id ) ) && false !== $subscription->order ) {
367
-			$stripe_customer_id = get_post_meta( $subscription->order->id, '_stripe_customer_id', true );
368
-			$stripe_card_id     = get_post_meta( $subscription->order->id, '_stripe_card_id', true );
366
+		if (( ! $stripe_customer_id || ! is_string($stripe_customer_id)) && false !== $subscription->order) {
367
+			$stripe_customer_id = get_post_meta($subscription->order->id, '_stripe_customer_id', true);
368
+			$stripe_card_id     = get_post_meta($subscription->order->id, '_stripe_card_id', true);
369 369
 		}
370 370
 
371
-		$stripe_customer->set_id( $stripe_customer_id );
371
+		$stripe_customer->set_id($stripe_customer_id);
372 372
 		$cards = $stripe_customer->get_cards();
373 373
 
374
-		if ( $cards ) {
374
+		if ($cards) {
375 375
 			$found_card = false;
376
-			foreach ( $cards as $card ) {
377
-				if ( $card->id === $stripe_card_id ) {
376
+			foreach ($cards as $card) {
377
+				if ($card->id === $stripe_card_id) {
378 378
 					$found_card                = true;
379
-					$payment_method_to_display = sprintf( __( 'Via %1$s card ending in %2$s', 'woocommerce-gateway-stripe' ), ( isset( $card->type ) ? $card->type : $card->brand ), $card->last4 );
379
+					$payment_method_to_display = sprintf(__('Via %1$s card ending in %2$s', 'woocommerce-gateway-stripe'), (isset($card->type) ? $card->type : $card->brand), $card->last4);
380 380
 					break;
381 381
 				}
382 382
 			}
383
-			if ( ! $found_card ) {
384
-				$payment_method_to_display = sprintf( __( 'Via %1$s card ending in %2$s', 'woocommerce-gateway-stripe' ), ( isset( $cards[0]->type ) ? $cards[0]->type : $cards[0]->brand ), $cards[0]->last4 );
383
+			if ( ! $found_card) {
384
+				$payment_method_to_display = sprintf(__('Via %1$s card ending in %2$s', 'woocommerce-gateway-stripe'), (isset($cards[0]->type) ? $cards[0]->type : $cards[0]->brand), $cards[0]->last4);
385 385
 			}
386 386
 		}
387 387
 
@@ -396,11 +396,11 @@  discard block
 block discarded – undo
396 396
 	 *
397 397
 	 * @param string $message
398 398
 	 */
399
-	public function log( $message ) {
400
-		$options = get_option( 'woocommerce_stripe_settings' );
399
+	public function log($message) {
400
+		$options = get_option('woocommerce_stripe_settings');
401 401
 
402
-		if ( 'yes' === $options['logging'] ) {
403
-			WC_Stripe::log( $message );
402
+		if ('yes' === $options['logging']) {
403
+			WC_Stripe::log($message);
404 404
 		}
405 405
 	}
406 406
 }
Please login to merge, or discard this patch.
includes/settings-stripe.php 1 patch
Spacing   +69 added lines, -69 removed lines patch added patch discarded remove patch
@@ -1,177 +1,177 @@
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) {
2
+if ( ! defined('ABSPATH')) {
3 3
 	exit;
4 4
 }
5 5
 
6
-return apply_filters( 'wc_stripe_settings',
6
+return apply_filters('wc_stripe_settings',
7 7
 	array(
8 8
 		'enabled' => array(
9
-			'title'       => __( 'Enable/Disable', 'woocommerce-gateway-stripe' ),
10
-			'label'       => __( 'Enable Stripe', 'woocommerce-gateway-stripe' ),
9
+			'title'       => __('Enable/Disable', 'woocommerce-gateway-stripe'),
10
+			'label'       => __('Enable Stripe', 'woocommerce-gateway-stripe'),
11 11
 			'type'        => 'checkbox',
12 12
 			'description' => '',
13 13
 			'default'     => 'no',
14 14
 		),
15 15
 		'title' => array(
16
-			'title'       => __( 'Title', 'woocommerce-gateway-stripe' ),
16
+			'title'       => __('Title', 'woocommerce-gateway-stripe'),
17 17
 			'type'        => 'text',
18
-			'description' => __( 'This controls the title which the user sees during checkout.', 'woocommerce-gateway-stripe' ),
19
-			'default'     => __( 'Credit Card (Stripe)', 'woocommerce-gateway-stripe' ),
18
+			'description' => __('This controls the title which the user sees during checkout.', 'woocommerce-gateway-stripe'),
19
+			'default'     => __('Credit Card (Stripe)', 'woocommerce-gateway-stripe'),
20 20
 			'desc_tip'    => true,
21 21
 		),
22 22
 		'description' => array(
23
-			'title'       => __( 'Description', 'woocommerce-gateway-stripe' ),
23
+			'title'       => __('Description', 'woocommerce-gateway-stripe'),
24 24
 			'type'        => 'text',
25
-			'description' => __( 'This controls the description which the user sees during checkout.', 'woocommerce-gateway-stripe' ),
26
-			'default'     => __( 'Pay with your credit card via Stripe.', 'woocommerce-gateway-stripe' ),
25
+			'description' => __('This controls the description which the user sees during checkout.', 'woocommerce-gateway-stripe'),
26
+			'default'     => __('Pay with your credit card via Stripe.', 'woocommerce-gateway-stripe'),
27 27
 			'desc_tip'    => true,
28 28
 		),
29 29
 		'testmode' => array(
30
-			'title'       => __( 'Test mode', 'woocommerce-gateway-stripe' ),
31
-			'label'       => __( 'Enable Test Mode', 'woocommerce-gateway-stripe' ),
30
+			'title'       => __('Test mode', 'woocommerce-gateway-stripe'),
31
+			'label'       => __('Enable Test Mode', 'woocommerce-gateway-stripe'),
32 32
 			'type'        => 'checkbox',
33
-			'description' => __( 'Place the payment gateway in test mode using test API keys.', 'woocommerce-gateway-stripe' ),
33
+			'description' => __('Place the payment gateway in test mode using test API keys.', 'woocommerce-gateway-stripe'),
34 34
 			'default'     => 'yes',
35 35
 			'desc_tip'    => true,
36 36
 		),
37 37
 		'test_secret_key' => array(
38
-			'title'       => __( 'Test Secret Key', 'woocommerce-gateway-stripe' ),
38
+			'title'       => __('Test 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
 		'test_publishable_key' => array(
45
-			'title'       => __( 'Test Publishable Key', 'woocommerce-gateway-stripe' ),
45
+			'title'       => __('Test 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
 		'secret_key' => array(
52
-			'title'       => __( 'Live Secret Key', 'woocommerce-gateway-stripe' ),
52
+			'title'       => __('Live 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
 		'publishable_key' => array(
59
-			'title'       => __( 'Live Publishable Key', 'woocommerce-gateway-stripe' ),
59
+			'title'       => __('Live 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
 		'statement_descriptor' => array(
66
-			'title'       => __( 'Statement Descriptor', 'woocommerce-gateway-stripe' ),
66
+			'title'       => __('Statement Descriptor', 'woocommerce-gateway-stripe'),
67 67
 			'type'        => 'text',
68
-			'description' => __( 'Extra information about a charge. This will appear on your customer’s credit card statement.', 'woocommerce-gateway-stripe' ),
68
+			'description' => __('Extra information about a charge. This will appear on your customer’s credit card statement.', 'woocommerce-gateway-stripe'),
69 69
 			'default'     => '',
70 70
 			'desc_tip'    => true,
71 71
 		),
72 72
 		'capture' => array(
73
-			'title'       => __( 'Capture', 'woocommerce-gateway-stripe' ),
74
-			'label'       => __( 'Capture charge immediately', 'woocommerce-gateway-stripe' ),
73
+			'title'       => __('Capture', 'woocommerce-gateway-stripe'),
74
+			'label'       => __('Capture charge immediately', 'woocommerce-gateway-stripe'),
75 75
 			'type'        => 'checkbox',
76
-			'description' => __( 'Whether or not to immediately capture the charge. When unchecked, the charge issues an authorization and will need to be captured later. Uncaptured charges expire in 7 days.', 'woocommerce-gateway-stripe' ),
76
+			'description' => __('Whether or not to immediately capture the charge. When unchecked, the charge issues an authorization and will need to be captured later. Uncaptured charges expire in 7 days.', 'woocommerce-gateway-stripe'),
77 77
 			'default'     => 'yes',
78 78
 			'desc_tip'    => true,
79 79
 		),
80 80
 		'stripe_checkout' => array(
81
-			'title'       => __( 'Stripe Checkout', 'woocommerce-gateway-stripe' ),
82
-			'label'       => __( 'Enable Stripe Checkout', 'woocommerce-gateway-stripe' ),
81
+			'title'       => __('Stripe Checkout', 'woocommerce-gateway-stripe'),
82
+			'label'       => __('Enable Stripe Checkout', 'woocommerce-gateway-stripe'),
83 83
 			'type'        => 'checkbox',
84
-			'description' => __( 'If enabled, this option shows a "pay" button and modal credit card form on the checkout, instead of credit card fields directly on the page.', 'woocommerce-gateway-stripe' ),
84
+			'description' => __('If enabled, this option shows a "pay" button and modal credit card form on the checkout, instead of credit card fields directly on the page.', 'woocommerce-gateway-stripe'),
85 85
 			'default'     => 'no',
86 86
 			'desc_tip'    => true,
87 87
 		),
88 88
 		'allow_remember_me' => array(
89
-			'title'       => __( 'Allow Remember Me', 'woocommerce-gateway-stripe' ),
90
-			'label'       => __( 'Enable Remember Me', 'woocommerce-gateway-stripe' ),
89
+			'title'       => __('Allow Remember Me', 'woocommerce-gateway-stripe'),
90
+			'label'       => __('Enable Remember Me', 'woocommerce-gateway-stripe'),
91 91
 			'type'        => 'checkbox',
92
-			'description' => __( 'If enabled, this option shows a "Remember Me" checkbox which when checked by the customer will persist their details.', 'woocommerce-gateway-stripe' ),
92
+			'description' => __('If enabled, this option shows a "Remember Me" checkbox which when checked by the customer will persist their details.', 'woocommerce-gateway-stripe'),
93 93
 			'default'     => 'yes',
94 94
 			'desc_tip'    => true,
95 95
 		),
96 96
 		'stripe_checkout_locale' => array(
97
-			'title'       => __( 'Stripe Checkout locale', 'woocommerce-gateway-stripe' ),
97
+			'title'       => __('Stripe Checkout locale', 'woocommerce-gateway-stripe'),
98 98
 			'type'        => 'select',
99 99
 			'class'       => 'wc-enhanced-select',
100
-			'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' ),
100
+			'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'),
101 101
 			'default'     => 'en',
102 102
 			'desc_tip'    => true,
103 103
 			'options'     => array(
104
-				'auto' => __( 'Auto', 'woocommerce-gateway-stripe' ),
105
-				'zh'   => __( 'Simplified Chinese', 'woocommerce-gateway-stripe' ),
106
-				'da'   => __( 'Danish', 'woocommerce-gateway-stripe' ),
107
-				'nl'   => __( 'Dutch', 'woocommerce-gateway-stripe' ),
108
-				'en'   => __( 'English', 'woocommerce-gateway-stripe' ),
109
-				'fi'   => __( 'Finnish', 'woocommerce-gateway-stripe' ),
110
-				'fr'   => __( 'French', 'woocommerce-gateway-stripe' ),
111
-				'de'   => __( 'German', 'woocommerce-gateway-stripe' ),
112
-				'it'   => __( 'Italian', 'woocommerce-gateway-stripe' ),
113
-				'ja'   => __( 'Japanese', 'woocommerce-gateway-stripe' ),
114
-				'no'   => __( 'Norwegian', 'woocommerce-gateway-stripe' ),
115
-				'es'   => __( 'Spanish', 'woocommerce-gateway-stripe' ),
116
-				'sv'   => __( 'Swedish', 'woocommerce-gateway-stripe' ),
104
+				'auto' => __('Auto', 'woocommerce-gateway-stripe'),
105
+				'zh'   => __('Simplified Chinese', 'woocommerce-gateway-stripe'),
106
+				'da'   => __('Danish', 'woocommerce-gateway-stripe'),
107
+				'nl'   => __('Dutch', 'woocommerce-gateway-stripe'),
108
+				'en'   => __('English', 'woocommerce-gateway-stripe'),
109
+				'fi'   => __('Finnish', 'woocommerce-gateway-stripe'),
110
+				'fr'   => __('French', 'woocommerce-gateway-stripe'),
111
+				'de'   => __('German', 'woocommerce-gateway-stripe'),
112
+				'it'   => __('Italian', 'woocommerce-gateway-stripe'),
113
+				'ja'   => __('Japanese', 'woocommerce-gateway-stripe'),
114
+				'no'   => __('Norwegian', 'woocommerce-gateway-stripe'),
115
+				'es'   => __('Spanish', 'woocommerce-gateway-stripe'),
116
+				'sv'   => __('Swedish', 'woocommerce-gateway-stripe'),
117 117
 			),
118 118
 		),
119 119
 		'stripe_bitcoin' => array(
120
-			'title'       => __( 'Bitcoin Currency', 'woocommerce-gateway-stripe' ),
121
-			'label'       => __( 'Enable Bitcoin Currency', 'woocommerce-gateway-stripe' ),
120
+			'title'       => __('Bitcoin Currency', 'woocommerce-gateway-stripe'),
121
+			'label'       => __('Enable Bitcoin Currency', 'woocommerce-gateway-stripe'),
122 122
 			'type'        => 'checkbox',
123
-			'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' ),
123
+			'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'),
124 124
 			'default'     => 'no',
125 125
 			'desc_tip'    => true,
126 126
 		),
127 127
 		'stripe_checkout_image' => array(
128
-			'title'       => __( 'Stripe Checkout Image', 'woocommerce-gateway-stripe' ),
129
-			'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' ),
128
+			'title'       => __('Stripe Checkout Image', 'woocommerce-gateway-stripe'),
129
+			'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'),
130 130
 			'type'        => 'text',
131 131
 			'default'     => '',
132 132
 			'desc_tip'    => true,
133 133
 		),
134 134
 		'request_payment_api' => array(
135
-			'title'       => __( 'Payment Request API', 'woocommerce-gateway-stripe' ),
136
-			'label'       => __( 'Enable Payment Request API', 'woocommerce-gateway-stripe' ),
135
+			'title'       => __('Payment Request API', 'woocommerce-gateway-stripe'),
136
+			'label'       => __('Enable Payment Request API', 'woocommerce-gateway-stripe'),
137 137
 			'type'        => 'checkbox',
138
-			'description' => __( 'If enabled, users will be able to pay using the Payment Request API if supported by the browser.', 'woocommerce-gateway-stripe' ),
138
+			'description' => __('If enabled, users will be able to pay using the Payment Request API if supported by the browser.', 'woocommerce-gateway-stripe'),
139 139
 			'default'     => 'no',
140 140
 			'desc_tip'    => true,
141 141
 		),
142 142
 		'apple_pay' => array(
143
-			'title'       => __( 'Apple Pay', 'woocommerce-gateway-stripe' ),
144
-			'label'       => sprintf( __( 'Enable Apple Pay. Please see %1$sTerms & Conditions%2$s', 'woocommerce-gateway-stripe' ), '<a href="https://stripe.com/apple-pay/legal" target="_blank">', '</a>' ),
143
+			'title'       => __('Apple Pay', 'woocommerce-gateway-stripe'),
144
+			'label'       => sprintf(__('Enable Apple Pay. Please see %1$sTerms & Conditions%2$s', 'woocommerce-gateway-stripe'), '<a href="https://stripe.com/apple-pay/legal" target="_blank">', '</a>'),
145 145
 			'type'        => 'checkbox',
146
-			'description' => __( 'If enabled, users will be able to pay with Apple Pay.', 'woocommerce-gateway-stripe' ),
146
+			'description' => __('If enabled, users will be able to pay with Apple Pay.', 'woocommerce-gateway-stripe'),
147 147
 			'default'     => 'no',
148 148
 			'desc_tip'    => true,
149 149
 		),
150 150
 		'apple_pay_button' => array(
151
-			'title'       => __( 'Apple Pay Button Style', 'woocommerce-gateway-stripe' ),
152
-			'label'       => __( 'Button Style', 'woocommerce-gateway-stripe' ),
151
+			'title'       => __('Apple Pay Button Style', 'woocommerce-gateway-stripe'),
152
+			'label'       => __('Button Style', 'woocommerce-gateway-stripe'),
153 153
 			'type'        => 'select',
154
-			'description' => __( 'Select the button style you would like to show.', 'woocommerce-gateway-stripe' ),
154
+			'description' => __('Select the button style you would like to show.', 'woocommerce-gateway-stripe'),
155 155
 			'default'     => 'black',
156 156
 			'desc_tip'    => true,
157 157
 			'options'     => array(
158
-				'black' => __( 'Black', 'woocommerce-gateway-stripe' ),
159
-				'white' => __( 'White', 'woocommerce-gateway-stripe' ),
158
+				'black' => __('Black', 'woocommerce-gateway-stripe'),
159
+				'white' => __('White', 'woocommerce-gateway-stripe'),
160 160
 			),
161 161
 		),
162 162
 		'saved_cards' => array(
163
-			'title'       => __( 'Saved Cards', 'woocommerce-gateway-stripe' ),
164
-			'label'       => __( 'Enable Payment via Saved Cards', 'woocommerce-gateway-stripe' ),
163
+			'title'       => __('Saved Cards', 'woocommerce-gateway-stripe'),
164
+			'label'       => __('Enable Payment via Saved Cards', 'woocommerce-gateway-stripe'),
165 165
 			'type'        => 'checkbox',
166
-			'description' => __( 'If enabled, users will be able to pay with a saved card during checkout. Card details are saved on Stripe servers, not on your store.', 'woocommerce-gateway-stripe' ),
166
+			'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'),
167 167
 			'default'     => 'no',
168 168
 			'desc_tip'    => true,
169 169
 		),
170 170
 		'logging' => array(
171
-			'title'       => __( 'Logging', 'woocommerce-gateway-stripe' ),
172
-			'label'       => __( 'Log debug messages', 'woocommerce-gateway-stripe' ),
171
+			'title'       => __('Logging', 'woocommerce-gateway-stripe'),
172
+			'label'       => __('Log debug messages', 'woocommerce-gateway-stripe'),
173 173
 			'type'        => 'checkbox',
174
-			'description' => __( 'Save debug messages to the WooCommerce System Status log.', 'woocommerce-gateway-stripe' ),
174
+			'description' => __('Save debug messages to the WooCommerce System Status log.', 'woocommerce-gateway-stripe'),
175 175
 			'default'     => 'no',
176 176
 			'desc_tip'    => true,
177 177
 		),
Please login to merge, or discard this patch.
includes/class-wc-stripe-api.php 1 patch
Spacing   +22 added lines, -22 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) {
2
+if ( ! defined('ABSPATH')) {
3 3
 	exit;
4 4
 }
5 5
 
@@ -25,7 +25,7 @@  discard block
 block discarded – undo
25 25
 	 * Set secret API Key.
26 26
 	 * @param string $key
27 27
 	 */
28
-	public static function set_secret_key( $secret_key ) {
28
+	public static function set_secret_key($secret_key) {
29 29
 		self::$secret_key = $secret_key;
30 30
 	}
31 31
 
@@ -34,11 +34,11 @@  discard block
 block discarded – undo
34 34
 	 * @return string
35 35
 	 */
36 36
 	public static function get_secret_key() {
37
-		if ( ! self::$secret_key ) {
38
-			$options = get_option( 'woocommerce_stripe_settings' );
37
+		if ( ! self::$secret_key) {
38
+			$options = get_option('woocommerce_stripe_settings');
39 39
 
40
-			if ( isset( $options['testmode'], $options['secret_key'], $options['test_secret_key'] ) ) {
41
-				self::set_secret_key( 'yes' === $options['testmode'] ? $options['test_secret_key'] : $options['secret_key'] );
40
+			if (isset($options['testmode'], $options['secret_key'], $options['test_secret_key'])) {
41
+				self::set_secret_key('yes' === $options['testmode'] ? $options['test_secret_key'] : $options['secret_key']);
42 42
 			}
43 43
 		}
44 44
 		return self::$secret_key;
@@ -51,39 +51,39 @@  discard block
 block discarded – undo
51 51
 	 * @param string $api
52 52
 	 * @return array|WP_Error
53 53
 	 */
54
-	public static function request( $request, $api = 'charges', $method = 'POST' ) {
55
-		self::log( "{$api} request: " . print_r( $request, true ) );
54
+	public static function request($request, $api = 'charges', $method = 'POST') {
55
+		self::log("{$api} request: " . print_r($request, true));
56 56
 
57 57
 		$response = wp_safe_remote_post(
58 58
 			self::ENDPOINT . $api,
59 59
 			array(
60 60
 				'method'        => $method,
61 61
 				'headers'       => array(
62
-					'Authorization'  => 'Basic ' . base64_encode( self::get_secret_key() . ':' ),
62
+					'Authorization'  => 'Basic ' . base64_encode(self::get_secret_key() . ':'),
63 63
 					'Stripe-Version' => '2016-03-07',
64 64
 				),
65
-				'body'       => apply_filters( 'woocommerce_stripe_request_body', $request, $api ),
65
+				'body'       => apply_filters('woocommerce_stripe_request_body', $request, $api),
66 66
 				'timeout'    => 70,
67 67
 				'user-agent' => 'WooCommerce ' . WC()->version,
68 68
 			)
69 69
 		);
70 70
 
71
-		if ( is_wp_error( $response ) || empty( $response['body'] ) ) {
72
-			self::log( 'Error Response: ' . print_r( $response, true ) );
73
-			return new WP_Error( 'stripe_error', __( 'There was a problem connecting to the payment gateway.', 'woocommerce-gateway-stripe' ) );
71
+		if (is_wp_error($response) || empty($response['body'])) {
72
+			self::log('Error Response: ' . print_r($response, true));
73
+			return new WP_Error('stripe_error', __('There was a problem connecting to the payment gateway.', 'woocommerce-gateway-stripe'));
74 74
 		}
75 75
 
76
-		$parsed_response = json_decode( $response['body'] );
76
+		$parsed_response = json_decode($response['body']);
77 77
 		// Handle response
78
-		if ( ! empty( $parsed_response->error ) ) {
79
-			if ( ! empty( $parsed_response->error->param ) ) {
78
+		if ( ! empty($parsed_response->error)) {
79
+			if ( ! empty($parsed_response->error->param)) {
80 80
 				$code = $parsed_response->error->param;
81
-			} elseif ( ! empty( $parsed_response->error->code ) ) {
81
+			} elseif ( ! empty($parsed_response->error->code)) {
82 82
 				$code = $parsed_response->error->code;
83 83
 			} else {
84 84
 				$code = 'stripe_error';
85 85
 			}
86
-			return new WP_Error( $code, $parsed_response->error->message );
86
+			return new WP_Error($code, $parsed_response->error->message);
87 87
 		} else {
88 88
 			return $parsed_response;
89 89
 		}
@@ -97,11 +97,11 @@  discard block
 block discarded – undo
97 97
 	 *
98 98
 	 * @param string $message
99 99
 	 */
100
-	public static function log( $message ) {
101
-		$options = get_option( 'woocommerce_stripe_settings' );
100
+	public static function log($message) {
101
+		$options = get_option('woocommerce_stripe_settings');
102 102
 
103
-		if ( 'yes' === $options['logging'] ) {
104
-			WC_Stripe::log( $message );
103
+		if ('yes' === $options['logging']) {
104
+			WC_Stripe::log($message);
105 105
 		}
106 106
 	}
107 107
 }
Please login to merge, or discard this patch.