Completed
Pull Request — master (#319)
by Akeda
02:24
created
includes/payment-methods/class-wc-gateway-stripe-bancontact.php 1 patch
Spacing   +75 added lines, -75 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
 
@@ -57,8 +57,8 @@  discard block
 block discarded – undo
57 57
 	 */
58 58
 	public function __construct() {
59 59
 		$this->id                   = 'stripe_bancontact';
60
-		$this->method_title         = __( 'Stripe Bancontact', 'woocommerce-gateway-stripe' );
61
-		$this->method_description   = sprintf( __( 'All other general Stripe settings can be adjusted <a href="%s">here</a>.', 'woocommerce-gateway-stripe' ), admin_url( 'admin.php?page=wc-settings&tab=checkout&section=stripe' ) );
60
+		$this->method_title         = __('Stripe Bancontact', 'woocommerce-gateway-stripe');
61
+		$this->method_description   = sprintf(__('All other general Stripe settings can be adjusted <a href="%s">here</a>.', 'woocommerce-gateway-stripe'), admin_url('admin.php?page=wc-settings&tab=checkout&section=stripe'));
62 62
 
63 63
 		// Load the form fields.
64 64
 		$this->init_form_fields();
@@ -66,24 +66,24 @@  discard block
 block discarded – undo
66 66
 		// Load the settings.
67 67
 		$this->init_settings();
68 68
 
69
-		$main_settings              = get_option( 'woocommerce_stripe_settings' );
70
-		$this->title                = $this->get_option( 'title' );
71
-		$this->description          = $this->get_option( 'description' );
72
-		$this->enabled              = $this->get_option( 'enabled' );
73
-		$this->testmode             = ( ! empty( $main_settings['testmode'] ) && 'yes' === $main_settings['testmode'] ) ? true : false;
74
-		$this->saved_cards          = ( ! empty( $main_settings['saved_cards'] ) && 'yes' === $main_settings['saved_cards'] ) ? true : false;
75
-		$this->publishable_key      = ! empty( $main_settings['publishable_key'] ) ? $main_settings['publishable_key'] : '';
76
-		$this->secret_key           = ! empty( $main_settings['secret_key'] ) ? $main_settings['secret_key'] : '';
77
-		$this->statement_descriptor = ! empty( $main_settings['statement_descriptor'] ) ? $main_settings['statement_descriptor'] : '';
78
-
79
-		if ( $this->testmode ) {
80
-			$this->publishable_key = ! empty( $main_settings['test_publishable_key'] ) ? $main_settings['test_publishable_key'] : '';
81
-			$this->secret_key      = ! empty( $main_settings['test_secret_key'] ) ? $main_settings['test_secret_key'] : '';
69
+		$main_settings              = get_option('woocommerce_stripe_settings');
70
+		$this->title                = $this->get_option('title');
71
+		$this->description          = $this->get_option('description');
72
+		$this->enabled              = $this->get_option('enabled');
73
+		$this->testmode             = ( ! empty($main_settings['testmode']) && 'yes' === $main_settings['testmode']) ? true : false;
74
+		$this->saved_cards          = ( ! empty($main_settings['saved_cards']) && 'yes' === $main_settings['saved_cards']) ? true : false;
75
+		$this->publishable_key      = ! empty($main_settings['publishable_key']) ? $main_settings['publishable_key'] : '';
76
+		$this->secret_key           = ! empty($main_settings['secret_key']) ? $main_settings['secret_key'] : '';
77
+		$this->statement_descriptor = ! empty($main_settings['statement_descriptor']) ? $main_settings['statement_descriptor'] : '';
78
+
79
+		if ($this->testmode) {
80
+			$this->publishable_key = ! empty($main_settings['test_publishable_key']) ? $main_settings['test_publishable_key'] : '';
81
+			$this->secret_key      = ! empty($main_settings['test_secret_key']) ? $main_settings['test_secret_key'] : '';
82 82
 		}
83 83
 
84
-		add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) );
85
-		add_action( 'admin_notices', array( $this, 'check_environment' ) );
86
-		add_action( 'wp_enqueue_scripts', array( $this, 'payment_scripts' ) );
84
+		add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options'));
85
+		add_action('admin_notices', array($this, 'check_environment'));
86
+		add_action('wp_enqueue_scripts', array($this, 'payment_scripts'));
87 87
 	}
88 88
 
89 89
 	/**
@@ -95,13 +95,13 @@  discard block
 block discarded – undo
95 95
 	public function check_environment() {
96 96
 		$environment_warning = $this->get_environment_warning();
97 97
 
98
-		if ( $environment_warning ) {
99
-			$this->add_admin_notice( 'bad_environment', 'error', $environment_warning );
98
+		if ($environment_warning) {
99
+			$this->add_admin_notice('bad_environment', 'error', $environment_warning);
100 100
 		}
101 101
 
102
-		foreach ( (array) $this->notices as $notice_key => $notice ) {
103
-			echo "<div class='" . esc_attr( $notice['class'] ) . "'><p>";
104
-			echo wp_kses( $notice['message'], array( 'a' => array( 'href' => array() ) ) );
102
+		foreach ((array) $this->notices as $notice_key => $notice) {
103
+			echo "<div class='" . esc_attr($notice['class']) . "'><p>";
104
+			echo wp_kses($notice['message'], array('a' => array('href' => array())));
105 105
 			echo '</p></div>';
106 106
 		}
107 107
 	}
@@ -114,8 +114,8 @@  discard block
 block discarded – undo
114 114
 	 * @version 4.0.0
115 115
 	 */
116 116
 	public function get_environment_warning() {
117
-		if ( 'yes' === $this->enabled && 'EUR' !== get_woocommerce_currency() ) {
118
-			$message = __( 'Bancontact is enabled - it requires store currency to be set to Euros.', 'woocommerce-gateway-stripe' );
117
+		if ('yes' === $this->enabled && 'EUR' !== get_woocommerce_currency()) {
118
+			$message = __('Bancontact is enabled - it requires store currency to be set to Euros.', 'woocommerce-gateway-stripe');
119 119
 
120 120
 			return $message;
121 121
 		}
@@ -131,9 +131,9 @@  discard block
 block discarded – undo
131 131
 	 * @return array
132 132
 	 */
133 133
 	public function payment_icons() {
134
-		return apply_filters( 'wc_stripe_payment_icons', array(
134
+		return apply_filters('wc_stripe_payment_icons', array(
135 135
 			'bancontact' => '<i class="stripe-pf stripe-pf-bancontact-mister-cash stripe-pf-right" alt="Bancontact" aria-hidden="true"></i>',
136
-		) );
136
+		));
137 137
 	}
138 138
 
139 139
 	/**
@@ -150,7 +150,7 @@  discard block
 block discarded – undo
150 150
 
151 151
 		$icons_str .= $icons['bancontact'];
152 152
 
153
-		return apply_filters( 'woocommerce_gateway_icon', $icons_str, $this->id );
153
+		return apply_filters('woocommerce_gateway_icon', $icons_str, $this->id);
154 154
 	}
155 155
 
156 156
 	/**
@@ -161,19 +161,19 @@  discard block
 block discarded – undo
161 161
 	 * @access public
162 162
 	 */
163 163
 	public function payment_scripts() {
164
-		if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) && ! is_add_payment_method_page() ) {
164
+		if ( ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order']) && ! is_add_payment_method_page()) {
165 165
 			return;
166 166
 		}
167 167
 
168
-		$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
168
+		$suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';
169 169
 
170
-		wp_enqueue_style( 'stripe_paymentfonts' );
170
+		wp_enqueue_style('stripe_paymentfonts');
171 171
 
172
-		if ( apply_filters( 'wc_stripe_use_elements_checkout_form', true ) ) {
173
-			wp_enqueue_script( 'stripev3' );
174
-			wp_enqueue_script( 'woocommerce_stripe_elements' );
172
+		if (apply_filters('wc_stripe_use_elements_checkout_form', true)) {
173
+			wp_enqueue_script('stripev3');
174
+			wp_enqueue_script('woocommerce_stripe_elements');
175 175
 		} else {
176
-			wp_enqueue_script( 'woocommerce_stripe' );
176
+			wp_enqueue_script('woocommerce_stripe');
177 177
 		}
178 178
 	}
179 179
 
@@ -181,7 +181,7 @@  discard block
 block discarded – undo
181 181
 	 * Initialize Gateway Settings Form Fields.
182 182
 	 */
183 183
 	public function init_form_fields() {
184
-		$this->form_fields = require( WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-bancontact-settings.php' );
184
+		$this->form_fields = require(WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-bancontact-settings.php');
185 185
 	}
186 186
 
187 187
 	/**
@@ -192,25 +192,25 @@  discard block
 block discarded – undo
192 192
 		$total                = WC()->cart->total;
193 193
 
194 194
 		// If paying from order, we need to get total from order not cart.
195
-		if ( isset( $_GET['pay_for_order'] ) && ! empty( $_GET['key'] ) ) {
196
-			$order = wc_get_order( wc_get_order_id_by_order_key( wc_clean( $_GET['key'] ) ) );
195
+		if (isset($_GET['pay_for_order']) && ! empty($_GET['key'])) {
196
+			$order = wc_get_order(wc_get_order_id_by_order_key(wc_clean($_GET['key'])));
197 197
 			$total = $order->get_total();
198 198
 		}
199 199
 
200
-		if ( is_add_payment_method_page() ) {
201
-			$pay_button_text = __( 'Add Payment', 'woocommerce-gateway-stripe' );
202
-			$total        = '';
200
+		if (is_add_payment_method_page()) {
201
+			$pay_button_text = __('Add Payment', 'woocommerce-gateway-stripe');
202
+			$total = '';
203 203
 		} else {
204 204
 			$pay_button_text = '';
205 205
 		}
206 206
 
207 207
 		echo '<div
208 208
 			id="stripe-bancontact-payment-data"
209
-			data-amount="' . esc_attr( WC_Stripe_Helper::get_stripe_amount( $total ) ) . '"
210
-			data-currency="' . esc_attr( strtolower( get_woocommerce_currency() ) ) . '">';
209
+			data-amount="' . esc_attr(WC_Stripe_Helper::get_stripe_amount($total)) . '"
210
+			data-currency="' . esc_attr(strtolower(get_woocommerce_currency())) . '">';
211 211
 
212
-		if ( $this->description ) {
213
-			echo apply_filters( 'wc_stripe_description', wpautop( wp_kses_post( $this->description ) ) );
212
+		if ($this->description) {
213
+			echo apply_filters('wc_stripe_description', wpautop(wp_kses_post($this->description)));
214 214
 		}
215 215
 
216 216
 		echo '</div>';
@@ -224,26 +224,26 @@  discard block
 block discarded – undo
224 224
 	 * @param object $order
225 225
 	 * @return mixed
226 226
 	 */
227
-	public function create_source( $order ) {
228
-		$currency              = version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->get_order_currency() : $order->get_currency();
229
-		$order_id              = version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->id : $order->get_id();
227
+	public function create_source($order) {
228
+		$currency              = version_compare(WC_VERSION, '3.0.0', '<') ? $order->get_order_currency() : $order->get_currency();
229
+		$order_id              = version_compare(WC_VERSION, '3.0.0', '<') ? $order->id : $order->get_id();
230 230
 		$stripe_session_id     = uniqid();
231 231
 		
232 232
 		// Set the stripe session id in order meta to later match it for security purposes.
233
-		update_post_meta( $order_id, '_stripe_session_id', $stripe_session_id );
234
-		$return_url            = $this->get_stripe_return_url( $order, $stripe_session_id );
233
+		update_post_meta($order_id, '_stripe_session_id', $stripe_session_id);
234
+		$return_url = $this->get_stripe_return_url($order, $stripe_session_id);
235 235
 
236 236
 		$post_data                   = array();
237
-		$post_data['amount']         = WC_Stripe_Helper::get_stripe_amount( $order->get_total(), $currency );
238
-		$post_data['currency']       = strtolower( $currency );
237
+		$post_data['amount']         = WC_Stripe_Helper::get_stripe_amount($order->get_total(), $currency);
238
+		$post_data['currency']       = strtolower($currency);
239 239
 		$post_data['type']           = 'bancontact';
240
-		$post_data['owner']          = $this->get_owner_details( $order );
241
-		$post_data['redirect']       = array( 'return_url' => $return_url );
242
-		$post_data['bancontact']     = array( 'statement_descriptor' => $this->statement_descriptor );
240
+		$post_data['owner']          = $this->get_owner_details($order);
241
+		$post_data['redirect']       = array('return_url' => $return_url);
242
+		$post_data['bancontact']     = array('statement_descriptor' => $this->statement_descriptor);
243 243
 
244
-		WC_Stripe_Logger::log( 'Info: Begin creating Bancontact source' );
244
+		WC_Stripe_Logger::log('Info: Begin creating Bancontact source');
245 245
 
246
-		return WC_Stripe_API::request( $post_data, 'sources' );
246
+		return WC_Stripe_API::request($post_data, 'sources');
247 247
 	}
248 248
 
249 249
 	/**
@@ -257,45 +257,45 @@  discard block
 block discarded – undo
257 257
 	 *
258 258
 	 * @return array|void
259 259
 	 */
260
-	public function process_payment( $order_id, $retry = true, $force_customer = false ) {
260
+	public function process_payment($order_id, $retry = true, $force_customer = false) {
261 261
 		try {
262
-			$order = wc_get_order( $order_id );
262
+			$order = wc_get_order($order_id);
263 263
 
264 264
 			// Handle payment.
265
-			if ( $order->get_total() > 0 ) {
265
+			if ($order->get_total() > 0) {
266 266
 
267
-				if ( $order->get_total() * 100 < WC_Stripe_Helper::get_minimum_amount() ) {
268
-					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_Helper::get_minimum_amount() / 100 ) ) );
267
+				if ($order->get_total() * 100 < WC_Stripe_Helper::get_minimum_amount()) {
268
+					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_Helper::get_minimum_amount() / 100)));
269 269
 				}
270 270
 
271
-				$response = $this->create_source( $order );
271
+				$response = $this->create_source($order);
272 272
 
273
-				if ( is_wp_error( $response ) ) {
273
+				if (is_wp_error($response)) {
274 274
 					$message = $response->get_error_message();
275 275
 
276
-					$order->add_order_note( $message );
276
+					$order->add_order_note($message);
277 277
 
278
-					throw new Exception( $message );
278
+					throw new Exception($message);
279 279
 				}
280 280
 
281
-				WC_Stripe_Logger::log( 'Info: Redirecting to Bancontact...' );
281
+				WC_Stripe_Logger::log('Info: Redirecting to Bancontact...');
282 282
 
283 283
 				return array(
284 284
 					'result'   => 'success',
285
-					'redirect' => esc_url_raw( $response->redirect->url ),
285
+					'redirect' => esc_url_raw($response->redirect->url),
286 286
 				);
287 287
 			} else {
288 288
 				$order->payment_complete();
289 289
 			}
290
-		} catch ( Exception $e ) {
291
-			wc_add_notice( $e->getMessage(), 'error' );
292
-			WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() );
290
+		} catch (Exception $e) {
291
+			wc_add_notice($e->getMessage(), 'error');
292
+			WC_Stripe_Logger::log('Error: ' . $e->getMessage());
293 293
 
294
-			if ( $order->has_status( array( 'pending', 'failed' ) ) ) {
295
-				$this->send_failed_order_email( $order_id );
294
+			if ($order->has_status(array('pending', 'failed'))) {
295
+				$this->send_failed_order_email($order_id);
296 296
 			}
297 297
 
298
-			do_action( 'wc_gateway_stripe_process_payment_error', $e, $order );
298
+			do_action('wc_gateway_stripe_process_payment_error', $e, $order);
299 299
 
300 300
 			return array(
301 301
 				'result'   => 'fail',
Please login to merge, or discard this patch.
includes/payment-methods/class-wc-gateway-stripe-sofort.php 1 patch
Spacing   +84 added lines, -84 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
 
@@ -57,8 +57,8 @@  discard block
 block discarded – undo
57 57
 	 */
58 58
 	public function __construct() {
59 59
 		$this->id                   = 'stripe_sofort';
60
-		$this->method_title         = __( 'Stripe Sofort', 'woocommerce-gateway-stripe' );
61
-		$this->method_description   = sprintf( __( 'All other general Stripe settings can be adjusted <a href="%s">here</a>.', 'woocommerce-gateway-stripe' ), admin_url( 'admin.php?page=wc-settings&tab=checkout&section=stripe' ) );
60
+		$this->method_title         = __('Stripe Sofort', 'woocommerce-gateway-stripe');
61
+		$this->method_description   = sprintf(__('All other general Stripe settings can be adjusted <a href="%s">here</a>.', 'woocommerce-gateway-stripe'), admin_url('admin.php?page=wc-settings&tab=checkout&section=stripe'));
62 62
 
63 63
 		// Load the form fields.
64 64
 		$this->init_form_fields();
@@ -66,24 +66,24 @@  discard block
 block discarded – undo
66 66
 		// Load the settings.
67 67
 		$this->init_settings();
68 68
 
69
-		$main_settings              = get_option( 'woocommerce_stripe_settings' );
70
-		$this->title                = $this->get_option( 'title' );
71
-		$this->description          = $this->get_option( 'description' );
72
-		$this->enabled              = $this->get_option( 'enabled' );
73
-		$this->testmode             = ( ! empty( $main_settings['testmode'] ) && 'yes' === $main_settings['testmode'] ) ? true : false;
74
-		$this->saved_cards          = ( ! empty( $main_settings['saved_cards'] ) && 'yes' === $main_settings['saved_cards'] ) ? true : false;
75
-		$this->publishable_key      = ! empty( $main_settings['publishable_key'] ) ? $main_settings['publishable_key'] : '';
76
-		$this->secret_key           = ! empty( $main_settings['secret_key'] ) ? $main_settings['secret_key'] : '';
77
-		$this->statement_descriptor = ! empty( $main_settings['statement_descriptor'] ) ? $main_settings['statement_descriptor'] : '';
78
-
79
-		if ( $this->testmode ) {
80
-			$this->publishable_key = ! empty( $main_settings['test_publishable_key'] ) ? $main_settings['test_publishable_key'] : '';
81
-			$this->secret_key      = ! empty( $main_settings['test_secret_key'] ) ? $main_settings['test_secret_key'] : '';
69
+		$main_settings              = get_option('woocommerce_stripe_settings');
70
+		$this->title                = $this->get_option('title');
71
+		$this->description          = $this->get_option('description');
72
+		$this->enabled              = $this->get_option('enabled');
73
+		$this->testmode             = ( ! empty($main_settings['testmode']) && 'yes' === $main_settings['testmode']) ? true : false;
74
+		$this->saved_cards          = ( ! empty($main_settings['saved_cards']) && 'yes' === $main_settings['saved_cards']) ? true : false;
75
+		$this->publishable_key      = ! empty($main_settings['publishable_key']) ? $main_settings['publishable_key'] : '';
76
+		$this->secret_key           = ! empty($main_settings['secret_key']) ? $main_settings['secret_key'] : '';
77
+		$this->statement_descriptor = ! empty($main_settings['statement_descriptor']) ? $main_settings['statement_descriptor'] : '';
78
+
79
+		if ($this->testmode) {
80
+			$this->publishable_key = ! empty($main_settings['test_publishable_key']) ? $main_settings['test_publishable_key'] : '';
81
+			$this->secret_key      = ! empty($main_settings['test_secret_key']) ? $main_settings['test_secret_key'] : '';
82 82
 		}
83 83
 
84
-		add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) );
85
-		add_action( 'admin_notices', array( $this, 'check_environment' ) );
86
-		add_action( 'wp_enqueue_scripts', array( $this, 'payment_scripts' ) );
84
+		add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options'));
85
+		add_action('admin_notices', array($this, 'check_environment'));
86
+		add_action('wp_enqueue_scripts', array($this, 'payment_scripts'));
87 87
 	}
88 88
 
89 89
 	/**
@@ -95,13 +95,13 @@  discard block
 block discarded – undo
95 95
 	public function check_environment() {
96 96
 		$environment_warning = $this->get_environment_warning();
97 97
 
98
-		if ( $environment_warning ) {
99
-			$this->add_admin_notice( 'bad_environment', 'error', $environment_warning );
98
+		if ($environment_warning) {
99
+			$this->add_admin_notice('bad_environment', 'error', $environment_warning);
100 100
 		}
101 101
 
102
-		foreach ( (array) $this->notices as $notice_key => $notice ) {
103
-			echo "<div class='" . esc_attr( $notice['class'] ) . "'><p>";
104
-			echo wp_kses( $notice['message'], array( 'a' => array( 'href' => array() ) ) );
102
+		foreach ((array) $this->notices as $notice_key => $notice) {
103
+			echo "<div class='" . esc_attr($notice['class']) . "'><p>";
104
+			echo wp_kses($notice['message'], array('a' => array('href' => array())));
105 105
 			echo '</p></div>';
106 106
 		}
107 107
 	}
@@ -114,8 +114,8 @@  discard block
 block discarded – undo
114 114
 	 * @version 4.0.0
115 115
 	 */
116 116
 	public function get_environment_warning() {
117
-		if ( 'yes' === $this->enabled && 'EUR' !== get_woocommerce_currency() ) {
118
-			$message = __( 'Sofort is enabled - it requires store currency to be set to Euros.', 'woocommerce-gateway-stripe' );
117
+		if ('yes' === $this->enabled && 'EUR' !== get_woocommerce_currency()) {
118
+			$message = __('Sofort is enabled - it requires store currency to be set to Euros.', 'woocommerce-gateway-stripe');
119 119
 
120 120
 			return $message;
121 121
 		}
@@ -131,9 +131,9 @@  discard block
 block discarded – undo
131 131
 	 * @return array
132 132
 	 */
133 133
 	public function payment_icons() {
134
-		return apply_filters( 'wc_stripe_payment_icons', array(
134
+		return apply_filters('wc_stripe_payment_icons', array(
135 135
 			'sofort' => '<i class="stripe-pf stripe-pf-sofort stripe-pf-right" alt="Sofort" aria-hidden="true"></i>',
136
-		) );
136
+		));
137 137
 	}
138 138
 
139 139
 	/**
@@ -150,7 +150,7 @@  discard block
 block discarded – undo
150 150
 
151 151
 		$icons_str .= $icons['sofort'];
152 152
 
153
-		return apply_filters( 'woocommerce_gateway_icon', $icons_str, $this->id );
153
+		return apply_filters('woocommerce_gateway_icon', $icons_str, $this->id);
154 154
 	}
155 155
 
156 156
 	/**
@@ -161,19 +161,19 @@  discard block
 block discarded – undo
161 161
 	 * @access public
162 162
 	 */
163 163
 	public function payment_scripts() {
164
-		if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) && ! is_add_payment_method_page() ) {
164
+		if ( ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order']) && ! is_add_payment_method_page()) {
165 165
 			return;
166 166
 		}
167 167
 
168
-		$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
168
+		$suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';
169 169
 
170
-		wp_enqueue_style( 'stripe_paymentfonts' );
170
+		wp_enqueue_style('stripe_paymentfonts');
171 171
 
172
-		if ( apply_filters( 'wc_stripe_use_elements_checkout_form', true ) ) {
173
-			wp_enqueue_script( 'stripev3' );
174
-			wp_enqueue_script( 'woocommerce_stripe_elements' );
172
+		if (apply_filters('wc_stripe_use_elements_checkout_form', true)) {
173
+			wp_enqueue_script('stripev3');
174
+			wp_enqueue_script('woocommerce_stripe_elements');
175 175
 		} else {
176
-			wp_enqueue_script( 'woocommerce_stripe' );
176
+			wp_enqueue_script('woocommerce_stripe');
177 177
 		}
178 178
 	}
179 179
 
@@ -181,7 +181,7 @@  discard block
 block discarded – undo
181 181
 	 * Initialize Gateway Settings Form Fields.
182 182
 	 */
183 183
 	public function init_form_fields() {
184
-		$this->form_fields = require( WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-sofort-settings.php' );
184
+		$this->form_fields = require(WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-sofort-settings.php');
185 185
 	}
186 186
 
187 187
 	/**
@@ -191,24 +191,24 @@  discard block
 block discarded – undo
191 191
 	 * @version 4.0.0
192 192
 	 */
193 193
 	public function form() {
194
-		$supported_countries = array( 'AT' => 'Austria', 'BE' => 'Belgium', 'DE' => 'Germany', 'NL' => 'Netherlands', 'ES' => 'Spain', 'IT' => 'Italy' );
194
+		$supported_countries = array('AT' => 'Austria', 'BE' => 'Belgium', 'DE' => 'Germany', 'NL' => 'Netherlands', 'ES' => 'Spain', 'IT' => 'Italy');
195 195
 		?>
196
-		<fieldset id="wc-<?php echo esc_attr( $this->id ); ?>-form" class="wc-payment-form">
197
-			<?php do_action( 'woocommerce_credit_card_form_start', $this->id ); ?>
196
+		<fieldset id="wc-<?php echo esc_attr($this->id); ?>-form" class="wc-payment-form">
197
+			<?php do_action('woocommerce_credit_card_form_start', $this->id); ?>
198 198
 			<label for="stripe-bank-country">
199
-				<?php _e( 'Country origin of your bank.', 'woocommerce-gateway-stripe' ); ?>
199
+				<?php _e('Country origin of your bank.', 'woocommerce-gateway-stripe'); ?>
200 200
 			</label>
201 201
 			<br />
202 202
 			<select id="stripe-bank-country" class="wc-enhanced-select validate-required" name="stripe_sofort_bank_country">
203
-				<option value="-1"><?php esc_html_e( 'Choose Bank Country', 'woocommerce-gateway-stripe' ); ?></option>
204
-				<?php foreach ( $supported_countries as $code => $country ) { ?>
205
-				<option value="<?php echo esc_attr( $code ); ?>"><?php echo esc_html( $country ); ?></option>
203
+				<option value="-1"><?php esc_html_e('Choose Bank Country', 'woocommerce-gateway-stripe'); ?></option>
204
+				<?php foreach ($supported_countries as $code => $country) { ?>
205
+				<option value="<?php echo esc_attr($code); ?>"><?php echo esc_html($country); ?></option>
206 206
 				<?php } ?>
207 207
 			</select>
208 208
 
209 209
 			<!-- Used to display form errors -->
210 210
 			<div class="stripe-source-errors" role="alert"></div>
211
-			<?php do_action( 'woocommerce_credit_card_form_end', $this->id ); ?>
211
+			<?php do_action('woocommerce_credit_card_form_end', $this->id); ?>
212 212
 			<div class="clear"></div>
213 213
 		</fieldset>
214 214
 		<?php
@@ -222,25 +222,25 @@  discard block
 block discarded – undo
222 222
 		$total                = WC()->cart->total;
223 223
 
224 224
 		// If paying from order, we need to get total from order not cart.
225
-		if ( isset( $_GET['pay_for_order'] ) && ! empty( $_GET['key'] ) ) {
226
-			$order = wc_get_order( wc_get_order_id_by_order_key( wc_clean( $_GET['key'] ) ) );
225
+		if (isset($_GET['pay_for_order']) && ! empty($_GET['key'])) {
226
+			$order = wc_get_order(wc_get_order_id_by_order_key(wc_clean($_GET['key'])));
227 227
 			$total = $order->get_total();
228 228
 		}
229 229
 
230
-		if ( is_add_payment_method_page() ) {
231
-			$pay_button_text = __( 'Add Payment', 'woocommerce-gateway-stripe' );
232
-			$total        = '';
230
+		if (is_add_payment_method_page()) {
231
+			$pay_button_text = __('Add Payment', 'woocommerce-gateway-stripe');
232
+			$total = '';
233 233
 		} else {
234 234
 			$pay_button_text = '';
235 235
 		}
236 236
 
237 237
 		echo '<div
238 238
 			id="stripe-sofort-payment-data"
239
-			data-amount="' . esc_attr( WC_Stripe_Helper::get_stripe_amount( $total ) ) . '"
240
-			data-currency="' . esc_attr( strtolower( get_woocommerce_currency() ) ) . '">';
239
+			data-amount="' . esc_attr(WC_Stripe_Helper::get_stripe_amount($total)) . '"
240
+			data-currency="' . esc_attr(strtolower(get_woocommerce_currency())) . '">';
241 241
 
242
-		if ( $this->description ) {
243
-			echo apply_filters( 'wc_stripe_description', wpautop( wp_kses_post( $this->description ) ) );
242
+		if ($this->description) {
243
+			echo apply_filters('wc_stripe_description', wpautop(wp_kses_post($this->description)));
244 244
 		}
245 245
 
246 246
 		$this->form();
@@ -256,27 +256,27 @@  discard block
 block discarded – undo
256 256
 	 * @param object $order
257 257
 	 * @return mixed
258 258
 	 */
259
-	public function create_source( $order ) {
260
-		$currency              = version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->get_order_currency() : $order->get_currency();
261
-		$order_id              = version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->id : $order->get_id();
262
-		$bank_country          = wc_clean( $_POST['stripe_sofort_bank_country'] );
259
+	public function create_source($order) {
260
+		$currency              = version_compare(WC_VERSION, '3.0.0', '<') ? $order->get_order_currency() : $order->get_currency();
261
+		$order_id              = version_compare(WC_VERSION, '3.0.0', '<') ? $order->id : $order->get_id();
262
+		$bank_country          = wc_clean($_POST['stripe_sofort_bank_country']);
263 263
 		$stripe_session_id     = uniqid();
264 264
 		
265 265
 		// Set the stripe session id in order meta to later match it for security purposes.
266
-		update_post_meta( $order_id, '_stripe_session_id', $stripe_session_id );
267
-		$return_url            = $this->get_stripe_return_url( $order, $stripe_session_id );
266
+		update_post_meta($order_id, '_stripe_session_id', $stripe_session_id);
267
+		$return_url = $this->get_stripe_return_url($order, $stripe_session_id);
268 268
 
269 269
 		$post_data                   = array();
270
-		$post_data['amount']         = WC_Stripe_Helper::get_stripe_amount( $order->get_total(), $currency );
271
-		$post_data['currency']       = strtolower( $currency );
270
+		$post_data['amount']         = WC_Stripe_Helper::get_stripe_amount($order->get_total(), $currency);
271
+		$post_data['currency']       = strtolower($currency);
272 272
 		$post_data['type']           = 'sofort';
273
-		$post_data['owner']          = $this->get_owner_details( $order );
274
-		$post_data['redirect']       = array( 'return_url' => $return_url );
275
-		$post_data['sofort']         = array( 'statement_descriptor' => $this->statement_descriptor, 'country' => $bank_country );
273
+		$post_data['owner']          = $this->get_owner_details($order);
274
+		$post_data['redirect']       = array('return_url' => $return_url);
275
+		$post_data['sofort']         = array('statement_descriptor' => $this->statement_descriptor, 'country' => $bank_country);
276 276
 
277
-		WC_Stripe_Logger::log( 'Info: Begin creating Sofort source' );
277
+		WC_Stripe_Logger::log('Info: Begin creating Sofort source');
278 278
 
279
-		return WC_Stripe_API::request( $post_data, 'sources' );
279
+		return WC_Stripe_API::request($post_data, 'sources');
280 280
 	}
281 281
 
282 282
 	/**
@@ -290,45 +290,45 @@  discard block
 block discarded – undo
290 290
 	 *
291 291
 	 * @return array|void
292 292
 	 */
293
-	public function process_payment( $order_id, $retry = true, $force_customer = false ) {
293
+	public function process_payment($order_id, $retry = true, $force_customer = false) {
294 294
 		try {
295
-			$order = wc_get_order( $order_id );
295
+			$order = wc_get_order($order_id);
296 296
 
297 297
 			// Handle payment.
298
-			if ( $order->get_total() > 0 ) {
298
+			if ($order->get_total() > 0) {
299 299
 
300
-				if ( $order->get_total() * 100 < WC_Stripe_Helper::get_minimum_amount() ) {
301
-					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_Helper::get_minimum_amount() / 100 ) ) );
300
+				if ($order->get_total() * 100 < WC_Stripe_Helper::get_minimum_amount()) {
301
+					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_Helper::get_minimum_amount() / 100)));
302 302
 				}
303 303
 
304
-				$response = $this->create_source( $order );
304
+				$response = $this->create_source($order);
305 305
 
306
-				if ( is_wp_error( $response ) ) {
306
+				if (is_wp_error($response)) {
307 307
 					$message = $response->get_error_message();
308 308
 
309
-					$order->add_order_note( $message );
309
+					$order->add_order_note($message);
310 310
 
311
-					throw new Exception( $message );
311
+					throw new Exception($message);
312 312
 				}
313 313
 
314
-				WC_Stripe_Logger::log( 'Info: Redirecting to Sofort...' );
314
+				WC_Stripe_Logger::log('Info: Redirecting to Sofort...');
315 315
 
316 316
 				return array(
317 317
 					'result'   => 'success',
318
-					'redirect' => esc_url_raw( $response->redirect->url ),
318
+					'redirect' => esc_url_raw($response->redirect->url),
319 319
 				);
320 320
 			} else {
321 321
 				$order->payment_complete();
322 322
 			}
323
-		} catch ( Exception $e ) {
324
-			wc_add_notice( $e->getMessage(), 'error' );
325
-			WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() );
323
+		} catch (Exception $e) {
324
+			wc_add_notice($e->getMessage(), 'error');
325
+			WC_Stripe_Logger::log('Error: ' . $e->getMessage());
326 326
 
327
-			if ( $order->has_status( array( 'pending', 'failed' ) ) ) {
328
-				$this->send_failed_order_email( $order_id );
327
+			if ($order->has_status(array('pending', 'failed'))) {
328
+				$this->send_failed_order_email($order_id);
329 329
 			}
330 330
 
331
-			do_action( 'wc_gateway_stripe_process_payment_error', $e, $order );
331
+			do_action('wc_gateway_stripe_process_payment_error', $e, $order);
332 332
 
333 333
 			return array(
334 334
 				'result'   => 'fail',
Please login to merge, or discard this patch.
includes/payment-methods/class-wc-gateway-stripe-ideal.php 1 patch
Spacing   +75 added lines, -75 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
 
@@ -57,8 +57,8 @@  discard block
 block discarded – undo
57 57
 	 */
58 58
 	public function __construct() {
59 59
 		$this->id                   = 'stripe_ideal';
60
-		$this->method_title         = __( 'Stripe iDeal', 'woocommerce-gateway-stripe' );
61
-		$this->method_description   = sprintf( __( 'All other general Stripe settings can be adjusted <a href="%s">here</a>.', 'woocommerce-gateway-stripe' ), admin_url( 'admin.php?page=wc-settings&tab=checkout&section=stripe' ) );
60
+		$this->method_title         = __('Stripe iDeal', 'woocommerce-gateway-stripe');
61
+		$this->method_description   = sprintf(__('All other general Stripe settings can be adjusted <a href="%s">here</a>.', 'woocommerce-gateway-stripe'), admin_url('admin.php?page=wc-settings&tab=checkout&section=stripe'));
62 62
 
63 63
 		// Load the form fields.
64 64
 		$this->init_form_fields();
@@ -66,24 +66,24 @@  discard block
 block discarded – undo
66 66
 		// Load the settings.
67 67
 		$this->init_settings();
68 68
 
69
-		$main_settings              = get_option( 'woocommerce_stripe_settings' );
70
-		$this->title                = $this->get_option( 'title' );
71
-		$this->description          = $this->get_option( 'description' );
72
-		$this->enabled              = $this->get_option( 'enabled' );
73
-		$this->testmode             = ( ! empty( $main_settings['testmode'] ) && 'yes' === $main_settings['testmode'] ) ? true : false;
74
-		$this->saved_cards          = ( ! empty( $main_settings['saved_cards'] ) && 'yes' === $main_settings['saved_cards'] ) ? true : false;
75
-		$this->publishable_key      = ! empty( $main_settings['publishable_key'] ) ? $main_settings['publishable_key'] : '';
76
-		$this->secret_key           = ! empty( $main_settings['secret_key'] ) ? $main_settings['secret_key'] : '';
77
-		$this->statement_descriptor = ! empty( $main_settings['statement_descriptor'] ) ? $main_settings['statement_descriptor'] : '';
78
-
79
-		if ( $this->testmode ) {
80
-			$this->publishable_key = ! empty( $main_settings['test_publishable_key'] ) ? $main_settings['test_publishable_key'] : '';
81
-			$this->secret_key      = ! empty( $main_settings['test_secret_key'] ) ? $main_settings['test_secret_key'] : '';
69
+		$main_settings              = get_option('woocommerce_stripe_settings');
70
+		$this->title                = $this->get_option('title');
71
+		$this->description          = $this->get_option('description');
72
+		$this->enabled              = $this->get_option('enabled');
73
+		$this->testmode             = ( ! empty($main_settings['testmode']) && 'yes' === $main_settings['testmode']) ? true : false;
74
+		$this->saved_cards          = ( ! empty($main_settings['saved_cards']) && 'yes' === $main_settings['saved_cards']) ? true : false;
75
+		$this->publishable_key      = ! empty($main_settings['publishable_key']) ? $main_settings['publishable_key'] : '';
76
+		$this->secret_key           = ! empty($main_settings['secret_key']) ? $main_settings['secret_key'] : '';
77
+		$this->statement_descriptor = ! empty($main_settings['statement_descriptor']) ? $main_settings['statement_descriptor'] : '';
78
+
79
+		if ($this->testmode) {
80
+			$this->publishable_key = ! empty($main_settings['test_publishable_key']) ? $main_settings['test_publishable_key'] : '';
81
+			$this->secret_key      = ! empty($main_settings['test_secret_key']) ? $main_settings['test_secret_key'] : '';
82 82
 		}
83 83
 
84
-		add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) );
85
-		add_action( 'admin_notices', array( $this, 'check_environment' ) );
86
-		add_action( 'wp_enqueue_scripts', array( $this, 'payment_scripts' ) );
84
+		add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options'));
85
+		add_action('admin_notices', array($this, 'check_environment'));
86
+		add_action('wp_enqueue_scripts', array($this, 'payment_scripts'));
87 87
 	}
88 88
 
89 89
 	/**
@@ -95,13 +95,13 @@  discard block
 block discarded – undo
95 95
 	public function check_environment() {
96 96
 		$environment_warning = $this->get_environment_warning();
97 97
 
98
-		if ( $environment_warning ) {
99
-			$this->add_admin_notice( 'bad_environment', 'error', $environment_warning );
98
+		if ($environment_warning) {
99
+			$this->add_admin_notice('bad_environment', 'error', $environment_warning);
100 100
 		}
101 101
 
102
-		foreach ( (array) $this->notices as $notice_key => $notice ) {
103
-			echo "<div class='" . esc_attr( $notice['class'] ) . "'><p>";
104
-			echo wp_kses( $notice['message'], array( 'a' => array( 'href' => array() ) ) );
102
+		foreach ((array) $this->notices as $notice_key => $notice) {
103
+			echo "<div class='" . esc_attr($notice['class']) . "'><p>";
104
+			echo wp_kses($notice['message'], array('a' => array('href' => array())));
105 105
 			echo '</p></div>';
106 106
 		}
107 107
 	}
@@ -114,8 +114,8 @@  discard block
 block discarded – undo
114 114
 	 * @version 4.0.0
115 115
 	 */
116 116
 	public function get_environment_warning() {
117
-		if ( 'yes' === $this->enabled && 'EUR' !== get_woocommerce_currency() ) {
118
-			$message = __( 'iDeal is enabled - it requires store currency to be set to Euros.', 'woocommerce-gateway-stripe' );
117
+		if ('yes' === $this->enabled && 'EUR' !== get_woocommerce_currency()) {
118
+			$message = __('iDeal is enabled - it requires store currency to be set to Euros.', 'woocommerce-gateway-stripe');
119 119
 
120 120
 			return $message;
121 121
 		}
@@ -131,9 +131,9 @@  discard block
 block discarded – undo
131 131
 	 * @return array
132 132
 	 */
133 133
 	public function payment_icons() {
134
-		return apply_filters( 'wc_stripe_payment_icons', array(
134
+		return apply_filters('wc_stripe_payment_icons', array(
135 135
 			'ideal' => '<i class="stripe-pf stripe-pf-ideal stripe-pf-right" alt="iDeal" aria-hidden="true"></i>',
136
-		) );
136
+		));
137 137
 	}
138 138
 
139 139
 	/**
@@ -150,7 +150,7 @@  discard block
 block discarded – undo
150 150
 
151 151
 		$icons_str .= $icons['ideal'];
152 152
 
153
-		return apply_filters( 'woocommerce_gateway_icon', $icons_str, $this->id );
153
+		return apply_filters('woocommerce_gateway_icon', $icons_str, $this->id);
154 154
 	}
155 155
 
156 156
 	/**
@@ -161,19 +161,19 @@  discard block
 block discarded – undo
161 161
 	 * @access public
162 162
 	 */
163 163
 	public function payment_scripts() {
164
-		if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) && ! is_add_payment_method_page() ) {
164
+		if ( ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order']) && ! is_add_payment_method_page()) {
165 165
 			return;
166 166
 		}
167 167
 
168
-		$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
168
+		$suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';
169 169
 
170
-		wp_enqueue_style( 'stripe_paymentfonts' );
170
+		wp_enqueue_style('stripe_paymentfonts');
171 171
 
172
-		if ( apply_filters( 'wc_stripe_use_elements_checkout_form', true ) ) {
173
-			wp_enqueue_script( 'stripev3' );
174
-			wp_enqueue_script( 'woocommerce_stripe_elements' );
172
+		if (apply_filters('wc_stripe_use_elements_checkout_form', true)) {
173
+			wp_enqueue_script('stripev3');
174
+			wp_enqueue_script('woocommerce_stripe_elements');
175 175
 		} else {
176
-			wp_enqueue_script( 'woocommerce_stripe' );
176
+			wp_enqueue_script('woocommerce_stripe');
177 177
 		}
178 178
 	}
179 179
 
@@ -181,7 +181,7 @@  discard block
 block discarded – undo
181 181
 	 * Initialize Gateway Settings Form Fields.
182 182
 	 */
183 183
 	public function init_form_fields() {
184
-		$this->form_fields = require( WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-ideal-settings.php' );
184
+		$this->form_fields = require(WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-ideal-settings.php');
185 185
 	}
186 186
 
187 187
 	/**
@@ -192,25 +192,25 @@  discard block
 block discarded – undo
192 192
 		$total                = WC()->cart->total;
193 193
 
194 194
 		// If paying from order, we need to get total from order not cart.
195
-		if ( isset( $_GET['pay_for_order'] ) && ! empty( $_GET['key'] ) ) {
196
-			$order = wc_get_order( wc_get_order_id_by_order_key( wc_clean( $_GET['key'] ) ) );
195
+		if (isset($_GET['pay_for_order']) && ! empty($_GET['key'])) {
196
+			$order = wc_get_order(wc_get_order_id_by_order_key(wc_clean($_GET['key'])));
197 197
 			$total = $order->get_total();
198 198
 		}
199 199
 
200
-		if ( is_add_payment_method_page() ) {
201
-			$pay_button_text = __( 'Add Payment', 'woocommerce-gateway-stripe' );
202
-			$total        = '';
200
+		if (is_add_payment_method_page()) {
201
+			$pay_button_text = __('Add Payment', 'woocommerce-gateway-stripe');
202
+			$total = '';
203 203
 		} else {
204 204
 			$pay_button_text = '';
205 205
 		}
206 206
 
207 207
 		echo '<div
208 208
 			id="stripe-ideal-payment-data"
209
-			data-amount="' . esc_attr( WC_Stripe_Helper::get_stripe_amount( $total ) ) . '"
210
-			data-currency="' . esc_attr( strtolower( get_woocommerce_currency() ) ) . '">';
209
+			data-amount="' . esc_attr(WC_Stripe_Helper::get_stripe_amount($total)) . '"
210
+			data-currency="' . esc_attr(strtolower(get_woocommerce_currency())) . '">';
211 211
 
212
-		if ( $this->description ) {
213
-			echo apply_filters( 'wc_stripe_description', wpautop( wp_kses_post( $this->description ) ) );
212
+		if ($this->description) {
213
+			echo apply_filters('wc_stripe_description', wpautop(wp_kses_post($this->description)));
214 214
 		}
215 215
 
216 216
 		echo '</div>';
@@ -224,26 +224,26 @@  discard block
 block discarded – undo
224 224
 	 * @param object $order
225 225
 	 * @return mixed
226 226
 	 */
227
-	public function create_source( $order ) {
228
-		$currency              = version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->get_order_currency() : $order->get_currency();
229
-		$order_id              = version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->id : $order->get_id();
227
+	public function create_source($order) {
228
+		$currency              = version_compare(WC_VERSION, '3.0.0', '<') ? $order->get_order_currency() : $order->get_currency();
229
+		$order_id              = version_compare(WC_VERSION, '3.0.0', '<') ? $order->id : $order->get_id();
230 230
 		$stripe_session_id     = uniqid();
231 231
 		
232 232
 		// Set the stripe session id in order meta to later match it for security purposes.
233
-		update_post_meta( $order_id, '_stripe_session_id', $stripe_session_id );
234
-		$return_url            = $this->get_stripe_return_url( $order, $stripe_session_id );
233
+		update_post_meta($order_id, '_stripe_session_id', $stripe_session_id);
234
+		$return_url = $this->get_stripe_return_url($order, $stripe_session_id);
235 235
 
236 236
 		$post_data                   = array();
237
-		$post_data['amount']         = WC_Stripe_Helper::get_stripe_amount( $order->get_total(), $currency );
238
-		$post_data['currency']       = strtolower( $currency );
237
+		$post_data['amount']         = WC_Stripe_Helper::get_stripe_amount($order->get_total(), $currency);
238
+		$post_data['currency']       = strtolower($currency);
239 239
 		$post_data['type']           = 'ideal';
240
-		$post_data['owner']          = $this->get_owner_details( $order );
241
-		$post_data['redirect']       = array( 'return_url' => $return_url );
242
-		$post_data['ideal']          = array( 'statement_descriptor' => $this->statement_descriptor );
240
+		$post_data['owner']          = $this->get_owner_details($order);
241
+		$post_data['redirect']       = array('return_url' => $return_url);
242
+		$post_data['ideal']          = array('statement_descriptor' => $this->statement_descriptor);
243 243
 
244
-		WC_Stripe_Logger::log( 'Info: Begin creating iDeal source' );
244
+		WC_Stripe_Logger::log('Info: Begin creating iDeal source');
245 245
 
246
-		return WC_Stripe_API::request( $post_data, 'sources' );
246
+		return WC_Stripe_API::request($post_data, 'sources');
247 247
 	}
248 248
 
249 249
 	/**
@@ -257,45 +257,45 @@  discard block
 block discarded – undo
257 257
 	 *
258 258
 	 * @return array|void
259 259
 	 */
260
-	public function process_payment( $order_id, $retry = true, $force_customer = false ) {
260
+	public function process_payment($order_id, $retry = true, $force_customer = false) {
261 261
 		try {
262
-			$order = wc_get_order( $order_id );
262
+			$order = wc_get_order($order_id);
263 263
 
264 264
 			// Handle payment.
265
-			if ( $order->get_total() > 0 ) {
265
+			if ($order->get_total() > 0) {
266 266
 
267
-				if ( $order->get_total() * 100 < WC_Stripe_Helper::get_minimum_amount() ) {
268
-					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_Helper::get_minimum_amount() / 100 ) ) );
267
+				if ($order->get_total() * 100 < WC_Stripe_Helper::get_minimum_amount()) {
268
+					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_Helper::get_minimum_amount() / 100)));
269 269
 				}
270 270
 
271
-				$response = $this->create_source( $order );
271
+				$response = $this->create_source($order);
272 272
 
273
-				if ( is_wp_error( $response ) ) {
273
+				if (is_wp_error($response)) {
274 274
 					$message = $response->get_error_message();
275 275
 
276
-					$order->add_order_note( $message );
276
+					$order->add_order_note($message);
277 277
 
278
-					throw new Exception( $message );
278
+					throw new Exception($message);
279 279
 				}
280 280
 
281
-				WC_Stripe_Logger::log( 'Info: Redirecting to iDeal...' );
281
+				WC_Stripe_Logger::log('Info: Redirecting to iDeal...');
282 282
 
283 283
 				return array(
284 284
 					'result'   => 'success',
285
-					'redirect' => esc_url_raw( $response->redirect->url ),
285
+					'redirect' => esc_url_raw($response->redirect->url),
286 286
 				);
287 287
 			} else {
288 288
 				$order->payment_complete();
289 289
 			}
290
-		} catch ( Exception $e ) {
291
-			wc_add_notice( $e->getMessage(), 'error' );
292
-			WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() );
290
+		} catch (Exception $e) {
291
+			wc_add_notice($e->getMessage(), 'error');
292
+			WC_Stripe_Logger::log('Error: ' . $e->getMessage());
293 293
 
294
-			if ( $order->has_status( array( 'pending', 'failed' ) ) ) {
295
-				$this->send_failed_order_email( $order_id );
294
+			if ($order->has_status(array('pending', 'failed'))) {
295
+				$this->send_failed_order_email($order_id);
296 296
 			}
297 297
 
298
-			do_action( 'wc_gateway_stripe_process_payment_error', $e, $order );
298
+			do_action('wc_gateway_stripe_process_payment_error', $e, $order);
299 299
 
300 300
 			return array(
301 301
 				'result'   => 'fail',
Please login to merge, or discard this patch.
includes/class-wc-stripe-webhook-handler.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; // Exit if accessed directly
4 4
 }
5 5
 
@@ -17,7 +17,7 @@  discard block
 block discarded – undo
17 17
 	 * @version 4.0.0
18 18
 	 */
19 19
 	public function __construct() {
20
-		add_action( 'woocommerce_api_wc_stripe', array( $this, 'check_for_webhook' ) );
20
+		add_action('woocommerce_api_wc_stripe', array($this, 'check_for_webhook'));
21 21
 	}
22 22
 
23 23
 	/**
@@ -27,21 +27,21 @@  discard block
 block discarded – undo
27 27
 	 * @version 4.0.0
28 28
 	 */
29 29
 	public function check_for_webhook() {
30
-		if ( ( 'POST' !== $_SERVER['REQUEST_METHOD'] )
31
-			|| ! isset( $_GET['wc-api'] )
32
-			|| ( 'wc_stripe' !== $_GET['wc-api'] )
30
+		if (('POST' !== $_SERVER['REQUEST_METHOD'])
31
+			|| ! isset($_GET['wc-api'])
32
+			|| ('wc_stripe' !== $_GET['wc-api'])
33 33
 		) {
34 34
 			return;
35 35
 		}
36 36
 
37
-		$request_body    = file_get_contents( 'php://input' );
38
-		$request_headers = array_change_key_case( $this->get_request_headers(), CASE_UPPER );
37
+		$request_body    = file_get_contents('php://input');
38
+		$request_headers = array_change_key_case($this->get_request_headers(), CASE_UPPER);
39 39
 
40 40
 		// Validate it to make sure it is legit.
41
-		if ( $this->is_valid_request( $request_headers, $request_body ) ) {
42
-			$this->process_webhook( $request_body );
41
+		if ($this->is_valid_request($request_headers, $request_body)) {
42
+			$this->process_webhook($request_body);
43 43
 		} else {
44
-			status_header( 400 );
44
+			status_header(400);
45 45
 			exit;
46 46
 		}
47 47
 	}
@@ -55,16 +55,16 @@  discard block
 block discarded – undo
55 55
 	 * @param string $request_body The request body from Stripe.
56 56
 	 * @return bool
57 57
 	 */
58
-	public function is_valid_request( $request_headers = null, $request_body = null ) {
59
-		if ( null === $request_headers || null === $request_body ) {
58
+	public function is_valid_request($request_headers = null, $request_body = null) {
59
+		if (null === $request_headers || null === $request_body) {
60 60
 			return false;
61 61
 		}
62 62
 
63 63
 		try {
64 64
 
65 65
 			return false;
66
-		} catch ( Exception $e ) {
67
-			WC_Stripe_Logger::log( $e->getMessage() );
66
+		} catch (Exception $e) {
67
+			WC_Stripe_Logger::log($e->getMessage());
68 68
 			return false;
69 69
 		}
70 70
 	}
@@ -78,11 +78,11 @@  discard block
 block discarded – undo
78 78
 	 * @version 4.0.0
79 79
 	 */
80 80
 	public function get_request_headers() {
81
-		if ( ! function_exists( 'getallheaders' ) ) {
81
+		if ( ! function_exists('getallheaders')) {
82 82
 			$headers = [];
83
-			foreach ( $_SERVER as $name => $value ) {
84
-				if ( 'HTTP_' === substr( $name, 0, 5 ) ) {
85
-					$headers[ str_replace( ' ', '-', ucwords( strtolower( str_replace( '_', ' ', substr( $name, 5 ) ) ) ) ) ] = $value;
83
+			foreach ($_SERVER as $name => $value) {
84
+				if ('HTTP_' === substr($name, 0, 5)) {
85
+					$headers[str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', substr($name, 5)))))] = $value;
86 86
 				}
87 87
 			}
88 88
 
@@ -99,13 +99,13 @@  discard block
 block discarded – undo
99 99
 	 * @version 4.0.0
100 100
 	 * @param string $request_body
101 101
 	 */
102
-	public function process_webhook( $request_body = null ) {
103
-		if ( null === $request_body ) {
104
-			status_header( 400 );
102
+	public function process_webhook($request_body = null) {
103
+		if (null === $request_body) {
104
+			status_header(400);
105 105
 			exit;
106 106
 		}
107 107
 
108
-		$notification = json_decode( $request_body );
108
+		$notification = json_decode($request_body);
109 109
 	}
110 110
 }
111 111
 
Please login to merge, or discard this patch.
includes/class-wc-stripe-apple-pay.php 1 patch
Spacing   +304 added lines, -304 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
 
@@ -96,28 +96,28 @@  discard block
 block discarded – undo
96 96
 	public function __construct() {
97 97
 		self::$_this = $this;
98 98
 
99
-		$gateway_settings = get_option( 'woocommerce_stripe_settings', '' );
99
+		$gateway_settings = get_option('woocommerce_stripe_settings', '');
100 100
 
101
-		$this->statement_descriptor = ! empty( $gateway_settings['statement_descriptor'] ) ? $gateway_settings['statement_descriptor'] : wp_specialchars_decode( get_bloginfo( 'name' ), ENT_QUOTES );
101
+		$this->statement_descriptor = ! empty($gateway_settings['statement_descriptor']) ? $gateway_settings['statement_descriptor'] : wp_specialchars_decode(get_bloginfo('name'), ENT_QUOTES);
102 102
 
103 103
 		// If both site title and statement descriptor is not set. Fallback.
104
-		if ( empty( $this->statement_descriptor ) ) {
104
+		if (empty($this->statement_descriptor)) {
105 105
 			$this->statement_descriptor = $_SERVER['SERVER_NAME'];
106 106
 		}
107 107
 
108 108
 		$this->dp                    = wc_get_price_decimals();
109
-		$this->enabled               = ( ! empty( $gateway_settings['enabled'] ) && 'yes' === $gateway_settings['enabled'] ) ? true : false;
110
-		$this->testmode              = ( ! empty( $gateway_settings['testmode'] ) && 'yes' === $gateway_settings['testmode'] ) ? true : false;
111
-		$this->capture               = ( ! empty( $gateway_settings['capture'] ) && 'yes' === $gateway_settings['capture'] ) ? true : false;
112
-		$this->saved_cards           = ( ! empty( $gateway_settings['saved_cards'] ) && 'yes' === $gateway_settings['saved_cards'] ) ? true : false;
113
-		$this->apple_pay             = ( ! empty( $gateway_settings['apple_pay'] ) && 'yes' === $gateway_settings['apple_pay'] ) ? true : false;
114
-		$this->apple_pay_button      = ! empty( $gateway_settings['apple_pay_button'] ) ? $gateway_settings['apple_pay_button'] : 'black';
115
-		$this->apple_pay_button_lang = ! empty( $gateway_settings['apple_pay_button_lang'] ) ? $gateway_settings['apple_pay_button_lang'] : 'en';
116
-		$this->publishable_key       = ! empty( $gateway_settings['publishable_key'] ) ? $gateway_settings['publishable_key'] : '';
109
+		$this->enabled               = ( ! empty($gateway_settings['enabled']) && 'yes' === $gateway_settings['enabled']) ? true : false;
110
+		$this->testmode              = ( ! empty($gateway_settings['testmode']) && 'yes' === $gateway_settings['testmode']) ? true : false;
111
+		$this->capture               = ( ! empty($gateway_settings['capture']) && 'yes' === $gateway_settings['capture']) ? true : false;
112
+		$this->saved_cards           = ( ! empty($gateway_settings['saved_cards']) && 'yes' === $gateway_settings['saved_cards']) ? true : false;
113
+		$this->apple_pay             = ( ! empty($gateway_settings['apple_pay']) && 'yes' === $gateway_settings['apple_pay']) ? true : false;
114
+		$this->apple_pay_button      = ! empty($gateway_settings['apple_pay_button']) ? $gateway_settings['apple_pay_button'] : 'black';
115
+		$this->apple_pay_button_lang = ! empty($gateway_settings['apple_pay_button_lang']) ? $gateway_settings['apple_pay_button_lang'] : 'en';
116
+		$this->publishable_key       = ! empty($gateway_settings['publishable_key']) ? $gateway_settings['publishable_key'] : '';
117 117
 		$this->is_shipping_enabled   = $this->is_shipping_enabled();
118 118
 
119
-		if ( $this->testmode ) {
120
-			$this->publishable_key = ! empty( $gateway_settings['test_publishable_key'] ) ? $gateway_settings['test_publishable_key'] : '';
119
+		if ($this->testmode) {
120
+			$this->publishable_key = ! empty($gateway_settings['test_publishable_key']) ? $gateway_settings['test_publishable_key'] : '';
121 121
 		}
122 122
 
123 123
 		$this->init();
@@ -136,53 +136,53 @@  discard block
 block discarded – undo
136 136
 	 */
137 137
 	public function init() {
138 138
 		// If Apple Pay is not enabled no need to proceed further.
139
-		if ( ! $this->apple_pay || ! $this->enabled ) {
139
+		if ( ! $this->apple_pay || ! $this->enabled) {
140 140
 			return;
141 141
 		}
142 142
 
143
-		add_action( 'wp_enqueue_scripts', array( $this, 'cart_scripts' ) );
144
-		add_action( 'wp_enqueue_scripts', array( $this, 'single_scripts' ) );
143
+		add_action('wp_enqueue_scripts', array($this, 'cart_scripts'));
144
+		add_action('wp_enqueue_scripts', array($this, 'single_scripts'));
145 145
 
146 146
 		/**
147 147
 		 * In order to display the Apple Pay button in the correct position,
148 148
 		 * a new hook was added to WooCommerce 3.0. In older versions of WooCommerce,
149 149
 		 * CSS is used to position the button.
150 150
 		 */
151
-		if ( version_compare( WC_VERSION, '3.0.0', '<' ) ) {
152
-			add_action( 'woocommerce_after_add_to_cart_button', array( $this, 'display_apple_pay_button' ), 1 );
151
+		if (version_compare(WC_VERSION, '3.0.0', '<')) {
152
+			add_action('woocommerce_after_add_to_cart_button', array($this, 'display_apple_pay_button'), 1);
153 153
 		} else {
154
-			add_action( 'woocommerce_after_add_to_cart_quantity', array( $this, 'display_apple_pay_button' ), 1 );
154
+			add_action('woocommerce_after_add_to_cart_quantity', array($this, 'display_apple_pay_button'), 1);
155 155
 		}
156 156
 
157
-		add_action( 'woocommerce_proceed_to_checkout', array( $this, 'display_apple_pay_button' ), 1 );
158
-		add_action( 'woocommerce_proceed_to_checkout', array( $this, 'display_apple_pay_separator_html' ), 2 );
159
-		add_action( 'woocommerce_checkout_before_customer_details', array( $this, 'display_apple_pay_button' ), 1 );
160
-		add_action( 'woocommerce_checkout_before_customer_details', array( $this, 'display_apple_pay_separator_html' ), 2 );
161
-		add_action( 'wc_ajax_wc_stripe_log_apple_pay_errors', array( $this, 'log_apple_pay_errors' ) );
162
-		add_action( 'wc_ajax_wc_stripe_apple_pay', array( $this, 'process_apple_pay' ) );
163
-		add_action( 'wc_ajax_wc_stripe_generate_apple_pay_cart', array( $this, 'generate_apple_pay_cart' ) );
164
-		add_action( 'wc_ajax_wc_stripe_apple_pay_clear_cart', array( $this, 'clear_cart' ) );
165
-		add_action( 'wc_ajax_wc_stripe_generate_apple_pay_single', array( $this, 'generate_apple_pay_single' ) );
166
-		add_action( 'wc_ajax_wc_stripe_apple_pay_get_shipping_methods', array( $this, 'get_shipping_methods' ) );
167
-		add_action( 'wc_ajax_wc_stripe_apple_pay_update_shipping_method', array( $this, 'update_shipping_method' ) );
168
-		add_filter( 'woocommerce_gateway_title', array( $this, 'filter_gateway_title' ), 10, 2 );
169
-		add_filter( 'woocommerce_validate_postcode', array( $this, 'postal_code_validation' ), 10, 3 );
157
+		add_action('woocommerce_proceed_to_checkout', array($this, 'display_apple_pay_button'), 1);
158
+		add_action('woocommerce_proceed_to_checkout', array($this, 'display_apple_pay_separator_html'), 2);
159
+		add_action('woocommerce_checkout_before_customer_details', array($this, 'display_apple_pay_button'), 1);
160
+		add_action('woocommerce_checkout_before_customer_details', array($this, 'display_apple_pay_separator_html'), 2);
161
+		add_action('wc_ajax_wc_stripe_log_apple_pay_errors', array($this, 'log_apple_pay_errors'));
162
+		add_action('wc_ajax_wc_stripe_apple_pay', array($this, 'process_apple_pay'));
163
+		add_action('wc_ajax_wc_stripe_generate_apple_pay_cart', array($this, 'generate_apple_pay_cart'));
164
+		add_action('wc_ajax_wc_stripe_apple_pay_clear_cart', array($this, 'clear_cart'));
165
+		add_action('wc_ajax_wc_stripe_generate_apple_pay_single', array($this, 'generate_apple_pay_single'));
166
+		add_action('wc_ajax_wc_stripe_apple_pay_get_shipping_methods', array($this, 'get_shipping_methods'));
167
+		add_action('wc_ajax_wc_stripe_apple_pay_update_shipping_method', array($this, 'update_shipping_method'));
168
+		add_filter('woocommerce_gateway_title', array($this, 'filter_gateway_title'), 10, 2);
169
+		add_filter('woocommerce_validate_postcode', array($this, 'postal_code_validation'), 10, 3);
170 170
 	}
171 171
 
172 172
 	/**
173 173
 	 * Filters the gateway title to reflect Apple Pay.
174 174
 	 *
175 175
 	 */
176
-	public function filter_gateway_title( $title, $id ) {
176
+	public function filter_gateway_title($title, $id) {
177 177
 		global $post;
178 178
 
179
-		if ( ! is_object( $post ) ) {
179
+		if ( ! is_object($post)) {
180 180
 			return $title;
181 181
 		}
182 182
 
183
-		$method_title = get_post_meta( $post->ID, '_payment_method_title', true );
183
+		$method_title = get_post_meta($post->ID, '_payment_method_title', true);
184 184
 
185
-		if ( 'stripe' === $id && ! empty( $method_title ) && 'Apple Pay (Stripe)' === $method_title ) {
185
+		if ('stripe' === $id && ! empty($method_title) && 'Apple Pay (Stripe)' === $method_title) {
186 186
 			return $method_title;
187 187
 		}
188 188
 
@@ -196,13 +196,13 @@  discard block
 block discarded – undo
196 196
 	 * @version 3.1.4
197 197
 	 */
198 198
 	public function log_apple_pay_errors() {
199
-		if ( ! wp_verify_nonce( $_POST['nonce'], '_wc_stripe_apple_pay_nonce' ) && ! wp_verify_nonce( $_POST['nonce'], '_wc_stripe_apple_pay_cart_nonce' ) ) {
200
-			wp_die( __( 'Cheatin&#8217; huh?', 'woocommerce-gateway-stripe' ) );
199
+		if ( ! wp_verify_nonce($_POST['nonce'], '_wc_stripe_apple_pay_nonce') && ! wp_verify_nonce($_POST['nonce'], '_wc_stripe_apple_pay_cart_nonce')) {
200
+			wp_die(__('Cheatin&#8217; huh?', 'woocommerce-gateway-stripe'));
201 201
 		}
202 202
 
203
-		$errors = wc_clean( stripslashes( $_POST['errors'] ) );
203
+		$errors = wc_clean(stripslashes($_POST['errors']));
204 204
 
205
-		WC_Stripe_Logger::log( $errors );
205
+		WC_Stripe_Logger::log($errors);
206 206
 
207 207
 		exit;
208 208
 	}
@@ -213,10 +213,10 @@  discard block
 block discarded – undo
213 213
 	 * @since 3.1.4
214 214
 	 * @version 3.1.4
215 215
 	 */
216
-	public function postal_code_validation( $valid, $postcode, $country ) {
216
+	public function postal_code_validation($valid, $postcode, $country) {
217 217
 		$gateways = WC()->payment_gateways->get_available_payment_gateways();
218 218
 
219
-		if ( ! $this->apple_pay || ! isset( $gateways['stripe'] ) ) {
219
+		if ( ! $this->apple_pay || ! isset($gateways['stripe'])) {
220 220
 			return $valid;
221 221
 		}
222 222
 
@@ -226,7 +226,7 @@  discard block
 block discarded – undo
226 226
 		 * the order and not let it go through. The remedy for now is just to remove this validation.
227 227
 		 * Note that this only works with shipping providers that don't validate full postal codes.
228 228
 		 */
229
-		if ( 'GB' === $country || 'CA' === $country ) {
229
+		if ('GB' === $country || 'CA' === $country) {
230 230
 			return true;
231 231
 		}
232 232
 
@@ -241,9 +241,9 @@  discard block
 block discarded – undo
241 241
 	 * @return bool
242 242
 	 */
243 243
 	public function is_shipping_enabled() {
244
-		$shipping_enabled = get_option( 'woocommerce_ship_to_countries', '' );
244
+		$shipping_enabled = get_option('woocommerce_ship_to_countries', '');
245 245
 
246
-		if ( 'disabled' === $shipping_enabled ) {
246
+		if ('disabled' === $shipping_enabled) {
247 247
 			return false;
248 248
 		}
249 249
 
@@ -257,42 +257,42 @@  discard block
 block discarded – undo
257 257
 	 * @version 3.1.4
258 258
 	 */
259 259
 	public function single_scripts() {
260
-		if ( ! is_single() ) {
260
+		if ( ! is_single()) {
261 261
 			return;
262 262
 		}
263 263
 
264 264
 		global $post;
265 265
 
266
-		$product = wc_get_product( $post->ID );
266
+		$product = wc_get_product($post->ID);
267 267
 
268
-		if ( ! is_object( $product ) || ! in_array( ( version_compare( WC_VERSION, '3.0.0', '<' ) ? $product->product_type : $product->get_type() ), $this->supported_product_types() ) ) {
268
+		if ( ! is_object($product) || ! in_array((version_compare(WC_VERSION, '3.0.0', '<') ? $product->product_type : $product->get_type()), $this->supported_product_types())) {
269 269
 			return;
270 270
 		}
271 271
 
272
-		$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
272
+		$suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';
273 273
 
274
-		wp_enqueue_style( 'stripe_apple_pay', plugins_url( 'assets/css/stripe-apple-pay.css', WC_STRIPE_MAIN_FILE ), array(), WC_STRIPE_VERSION );
274
+		wp_enqueue_style('stripe_apple_pay', plugins_url('assets/css/stripe-apple-pay.css', WC_STRIPE_MAIN_FILE), array(), WC_STRIPE_VERSION);
275 275
 
276
-		wp_enqueue_script( 'stripe', 'https://js.stripe.com/v2/', '', '1.0', true );
277
-		wp_enqueue_script( 'woocommerce_stripe_apple_pay_single', plugins_url( 'assets/js/stripe-apple-pay-single' . $suffix . '.js', WC_STRIPE_MAIN_FILE ), array( 'stripe' ), WC_STRIPE_VERSION, true );
276
+		wp_enqueue_script('stripe', 'https://js.stripe.com/v2/', '', '1.0', true);
277
+		wp_enqueue_script('woocommerce_stripe_apple_pay_single', plugins_url('assets/js/stripe-apple-pay-single' . $suffix . '.js', WC_STRIPE_MAIN_FILE), array('stripe'), WC_STRIPE_VERSION, true);
278 278
 
279 279
 		$stripe_params = array(
280 280
 			'key'                                           => $this->publishable_key,
281 281
 			'currency_code'                                 => get_woocommerce_currency(),
282
-			'country_code'                                  => substr( get_option( 'woocommerce_default_country' ), 0, 2 ),
282
+			'country_code'                                  => substr(get_option('woocommerce_default_country'), 0, 2),
283 283
 			'label'                                         => $this->statement_descriptor . ' (via WooCommerce)',
284
-			'ajaxurl'                                       => WC_AJAX::get_endpoint( '%%endpoint%%' ),
285
-			'stripe_apple_pay_nonce'                        => wp_create_nonce( '_wc_stripe_apple_pay_nonce' ),
286
-			'stripe_apple_pay_cart_nonce'                   => wp_create_nonce( '_wc_stripe_apple_pay_cart_nonce' ),
287
-			'stripe_apple_pay_get_shipping_methods_nonce'   => wp_create_nonce( '_wc_stripe_apple_pay_get_shipping_methods_nonce' ),
288
-			'stripe_apple_pay_update_shipping_method_nonce' => wp_create_nonce( '_wc_stripe_apple_pay_update_shipping_method_nonce' ),
289
-			'needs_shipping'                                => ( $product->needs_shipping() && $this->is_shipping_enabled ) ? 'yes' : 'no',
284
+			'ajaxurl'                                       => WC_AJAX::get_endpoint('%%endpoint%%'),
285
+			'stripe_apple_pay_nonce'                        => wp_create_nonce('_wc_stripe_apple_pay_nonce'),
286
+			'stripe_apple_pay_cart_nonce'                   => wp_create_nonce('_wc_stripe_apple_pay_cart_nonce'),
287
+			'stripe_apple_pay_get_shipping_methods_nonce'   => wp_create_nonce('_wc_stripe_apple_pay_get_shipping_methods_nonce'),
288
+			'stripe_apple_pay_update_shipping_method_nonce' => wp_create_nonce('_wc_stripe_apple_pay_update_shipping_method_nonce'),
289
+			'needs_shipping'                                => ($product->needs_shipping() && $this->is_shipping_enabled) ? 'yes' : 'no',
290 290
 			'i18n'                                          => array(
291
-				'sub_total' => __( 'Sub-Total', 'woocommerce-gateway-stripe' ),
291
+				'sub_total' => __('Sub-Total', 'woocommerce-gateway-stripe'),
292 292
 			),
293 293
 		);
294 294
 
295
-		wp_localize_script( 'woocommerce_stripe_apple_pay_single', 'wc_stripe_apple_pay_single_params', apply_filters( 'wc_stripe_apple_pay_single_params', $stripe_params ) );
295
+		wp_localize_script('woocommerce_stripe_apple_pay_single', 'wc_stripe_apple_pay_single_params', apply_filters('wc_stripe_apple_pay_single_params', $stripe_params));
296 296
 	}
297 297
 
298 298
 	/**
@@ -302,32 +302,32 @@  discard block
 block discarded – undo
302 302
 	 * @version 3.1.0
303 303
 	 */
304 304
 	public function cart_scripts() {
305
-		if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) ) {
305
+		if ( ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order'])) {
306 306
 			return;
307 307
 		}
308 308
 
309
-		$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
309
+		$suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';
310 310
 
311
-		wp_enqueue_style( 'stripe_apple_pay', plugins_url( 'assets/css/stripe-apple-pay.css', WC_STRIPE_MAIN_FILE ), array(), WC_STRIPE_VERSION );
311
+		wp_enqueue_style('stripe_apple_pay', plugins_url('assets/css/stripe-apple-pay.css', WC_STRIPE_MAIN_FILE), array(), WC_STRIPE_VERSION);
312 312
 
313
-		wp_enqueue_script( 'stripe', 'https://js.stripe.com/v2/', '', '1.0', true );
314
-		wp_enqueue_script( 'woocommerce_stripe_apple_pay', plugins_url( 'assets/js/stripe-apple-pay' . $suffix . '.js', WC_STRIPE_MAIN_FILE ), array( 'stripe' ), WC_STRIPE_VERSION, true );
313
+		wp_enqueue_script('stripe', 'https://js.stripe.com/v2/', '', '1.0', true);
314
+		wp_enqueue_script('woocommerce_stripe_apple_pay', plugins_url('assets/js/stripe-apple-pay' . $suffix . '.js', WC_STRIPE_MAIN_FILE), array('stripe'), WC_STRIPE_VERSION, true);
315 315
 
316 316
 		$stripe_params = array(
317 317
 			'key'                                           => $this->publishable_key,
318 318
 			'currency_code'                                 => get_woocommerce_currency(),
319
-			'country_code'                                  => substr( get_option( 'woocommerce_default_country' ), 0, 2 ),
319
+			'country_code'                                  => substr(get_option('woocommerce_default_country'), 0, 2),
320 320
 			'label'                                         => $this->statement_descriptor . ' (via WooCommerce)',
321
-			'ajaxurl'                                       => WC_AJAX::get_endpoint( '%%endpoint%%' ),
322
-			'stripe_apple_pay_nonce'                        => wp_create_nonce( '_wc_stripe_apple_pay_nonce' ),
323
-			'stripe_apple_pay_cart_nonce'                   => wp_create_nonce( '_wc_stripe_apple_pay_cart_nonce' ),
324
-			'stripe_apple_pay_get_shipping_methods_nonce'   => wp_create_nonce( '_wc_stripe_apple_pay_get_shipping_methods_nonce' ),
325
-			'stripe_apple_pay_update_shipping_method_nonce' => wp_create_nonce( '_wc_stripe_apple_pay_update_shipping_method_nonce' ),
326
-			'needs_shipping'                                => ( WC()->cart->needs_shipping() && $this->is_shipping_enabled ) ? 'yes' : 'no',
321
+			'ajaxurl'                                       => WC_AJAX::get_endpoint('%%endpoint%%'),
322
+			'stripe_apple_pay_nonce'                        => wp_create_nonce('_wc_stripe_apple_pay_nonce'),
323
+			'stripe_apple_pay_cart_nonce'                   => wp_create_nonce('_wc_stripe_apple_pay_cart_nonce'),
324
+			'stripe_apple_pay_get_shipping_methods_nonce'   => wp_create_nonce('_wc_stripe_apple_pay_get_shipping_methods_nonce'),
325
+			'stripe_apple_pay_update_shipping_method_nonce' => wp_create_nonce('_wc_stripe_apple_pay_update_shipping_method_nonce'),
326
+			'needs_shipping'                                => (WC()->cart->needs_shipping() && $this->is_shipping_enabled) ? 'yes' : 'no',
327 327
 			'is_cart_page'                                  => is_cart() ? 'yes' : 'no',
328 328
 		);
329 329
 
330
-		wp_localize_script( 'woocommerce_stripe_apple_pay', 'wc_stripe_apple_pay_params', apply_filters( 'wc_stripe_apple_pay_params', $stripe_params ) );
330
+		wp_localize_script('woocommerce_stripe_apple_pay', 'wc_stripe_apple_pay_params', apply_filters('wc_stripe_apple_pay_params', $stripe_params));
331 331
 	}
332 332
 
333 333
 	/**
@@ -338,11 +338,11 @@  discard block
 block discarded – undo
338 338
 	 * @return array
339 339
 	 */
340 340
 	public function supported_product_types() {
341
-		return apply_filters( 'wc_stripe_apple_pay_supported_types', array(
341
+		return apply_filters('wc_stripe_apple_pay_supported_types', array(
342 342
 			'simple',
343 343
 			'variable',
344 344
 			'variation',
345
-		) );
345
+		));
346 346
 	}
347 347
 
348 348
 	/**
@@ -354,10 +354,10 @@  discard block
 block discarded – undo
354 354
 	 * @return bool
355 355
 	 */
356 356
 	public function allowed_items_in_cart() {
357
-		foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {
358
-			$_product = apply_filters( 'woocommerce_cart_item_product', $cart_item['data'], $cart_item, $cart_item_key );
357
+		foreach (WC()->cart->get_cart() as $cart_item_key => $cart_item) {
358
+			$_product = apply_filters('woocommerce_cart_item_product', $cart_item['data'], $cart_item, $cart_item_key);
359 359
 
360
-			if ( ! in_array( ( version_compare( WC_VERSION, '3.0.0', '<' ) ? $_product->product_type : $_product->get_type() ), $this->supported_product_types() ) ) {
360
+			if ( ! in_array((version_compare(WC_VERSION, '3.0.0', '<') ? $_product->product_type : $_product->get_type()), $this->supported_product_types())) {
361 361
 				return false;
362 362
 			}
363 363
 		}
@@ -378,29 +378,29 @@  discard block
 block discarded – undo
378 378
 		 * In order for the Apple Pay button to show on product detail page,
379 379
 		 * Apple Pay must be enabled and Stripe gateway must be enabled.
380 380
 		 */
381
-		if ( ! $this->apple_pay || ! isset( $gateways['stripe'] ) ) {
382
-			WC_Stripe_Logger::log( 'Apple Pay not enabled or Stripe is not an available gateway ( Apple Pay button disabled )' );
381
+		if ( ! $this->apple_pay || ! isset($gateways['stripe'])) {
382
+			WC_Stripe_Logger::log('Apple Pay not enabled or Stripe is not an available gateway ( Apple Pay button disabled )');
383 383
 			return;
384 384
 		}
385 385
 
386
-		if ( is_single() ) {
386
+		if (is_single()) {
387 387
 			global $post;
388 388
 
389
-			$product = wc_get_product( $post->ID );
389
+			$product = wc_get_product($post->ID);
390 390
 
391
-			if ( ! is_object( $product ) || ! in_array( ( version_compare( WC_VERSION, '3.0.0', '<' ) ? $product->product_type : $product->get_type() ), $this->supported_product_types() ) ) {
391
+			if ( ! is_object($product) || ! in_array((version_compare(WC_VERSION, '3.0.0', '<') ? $product->product_type : $product->get_type()), $this->supported_product_types())) {
392 392
 				return;
393 393
 			}
394 394
 		} else {
395
-			if ( ! $this->allowed_items_in_cart() ) {
396
-				WC_Stripe_Logger::log( 'Items in the cart has unsupported product type ( Apple Pay button disabled )' );
395
+			if ( ! $this->allowed_items_in_cart()) {
396
+				WC_Stripe_Logger::log('Items in the cart has unsupported product type ( Apple Pay button disabled )');
397 397
 				return;
398 398
 			}
399 399
 		}
400 400
 
401 401
 		?>
402 402
 		<div class="apple-pay-button-wrapper">
403
-			<button class="apple-pay-button" lang="<?php echo esc_attr( $this->apple_pay_button_lang ); ?>" style="-webkit-appearance: -apple-pay-button; -apple-pay-button-type: buy; -apple-pay-button-style: <?php echo esc_attr( $this->apple_pay_button ); ?>;display:none;" alt="<?php esc_attr_e( 'Buy with Apple Pay', 'woocommerce-gateway-stripe' ); ?>"></button>
403
+			<button class="apple-pay-button" lang="<?php echo esc_attr($this->apple_pay_button_lang); ?>" style="-webkit-appearance: -apple-pay-button; -apple-pay-button-type: buy; -apple-pay-button-style: <?php echo esc_attr($this->apple_pay_button); ?>;display:none;" alt="<?php esc_attr_e('Buy with Apple Pay', 'woocommerce-gateway-stripe'); ?>"></button>
404 404
 		</div>
405 405
 		<?php
406 406
 	}
@@ -418,17 +418,17 @@  discard block
 block discarded – undo
418 418
 		 * In order for the Apple Pay button to show on cart page,
419 419
 		 * Apple Pay must be enabled and Stripe gateway must be enabled.
420 420
 		 */
421
-		if ( ! $this->apple_pay || ! isset( $gateways['stripe'] ) ) {
422
-			WC_Stripe_Logger::log( 'Apple Pay not enabled or Stripe is not an available gateway ( Apple Pay button disabled )' );
421
+		if ( ! $this->apple_pay || ! isset($gateways['stripe'])) {
422
+			WC_Stripe_Logger::log('Apple Pay not enabled or Stripe is not an available gateway ( Apple Pay button disabled )');
423 423
 			return;
424 424
 		}
425 425
 
426
-		if ( ! $this->allowed_items_in_cart() ) {
427
-			WC_Stripe_Logger::log( 'Items in the cart has unsupported product type ( Apple Pay button disabled )' );
426
+		if ( ! $this->allowed_items_in_cart()) {
427
+			WC_Stripe_Logger::log('Items in the cart has unsupported product type ( Apple Pay button disabled )');
428 428
 			return;
429 429
 		}
430 430
 		?>
431
-		<p class="apple-pay-button-checkout-separator">- <?php esc_html_e( 'Or', 'woocommerce-gateway-stripe' ); ?> -</p>
431
+		<p class="apple-pay-button-checkout-separator">- <?php esc_html_e('Or', 'woocommerce-gateway-stripe'); ?> -</p>
432 432
 		<?php
433 433
 	}
434 434
 
@@ -439,45 +439,45 @@  discard block
 block discarded – undo
439 439
 	 * @version 3.1.0
440 440
 	 */
441 441
 	public function generate_apple_pay_single() {
442
-		if ( ! wp_verify_nonce( $_POST['nonce'], '_wc_stripe_apple_pay_cart_nonce' ) ) {
443
-			wp_die( __( 'Cheatin&#8217; huh?', 'woocommerce-gateway-stripe' ) );
442
+		if ( ! wp_verify_nonce($_POST['nonce'], '_wc_stripe_apple_pay_cart_nonce')) {
443
+			wp_die(__('Cheatin&#8217; huh?', 'woocommerce-gateway-stripe'));
444 444
 		}
445 445
 
446
-		if ( ! defined( 'WOOCOMMERCE_CART' ) ) {
447
-			define( 'WOOCOMMERCE_CART', true );
446
+		if ( ! defined('WOOCOMMERCE_CART')) {
447
+			define('WOOCOMMERCE_CART', true);
448 448
 		}
449 449
 
450 450
 		WC()->shipping->reset_shipping();
451 451
 
452 452
 		global $post;
453 453
 
454
-		$product = wc_get_product( $post->ID );
455
-		$qty     = ! isset( $_POST['qty'] ) ? 1 : absint( $_POST['qty'] );
454
+		$product = wc_get_product($post->ID);
455
+		$qty     = ! isset($_POST['qty']) ? 1 : absint($_POST['qty']);
456 456
 
457 457
 		/**
458 458
 		 * If this page is single product page, we need to simulate
459 459
 		 * adding the product to the cart taken account if it is a
460 460
 		 * simple or variable product.
461 461
 		 */
462
-		if ( is_single() ) {
462
+		if (is_single()) {
463 463
 			// First empty the cart to prevent wrong calculation.
464 464
 			WC()->cart->empty_cart();
465 465
 
466
-			if ( 'variable' === ( version_compare( WC_VERSION, '3.0.0', '<' ) ? $product->product_type : $product->get_type() ) && isset( $_POST['attributes'] ) ) {
467
-				$attributes = array_map( 'wc_clean', $_POST['attributes'] );
466
+			if ('variable' === (version_compare(WC_VERSION, '3.0.0', '<') ? $product->product_type : $product->get_type()) && isset($_POST['attributes'])) {
467
+				$attributes = array_map('wc_clean', $_POST['attributes']);
468 468
 
469
-				if ( version_compare( WC_VERSION, '3.0.0', '<' ) ) {
470
-					$variation_id = $product->get_matching_variation( $attributes );
469
+				if (version_compare(WC_VERSION, '3.0.0', '<')) {
470
+					$variation_id = $product->get_matching_variation($attributes);
471 471
 				} else {
472
-					$data_store = WC_Data_Store::load( 'product' );
473
-					$variation_id = $data_store->find_matching_product_variation( $product, $attributes );
472
+					$data_store = WC_Data_Store::load('product');
473
+					$variation_id = $data_store->find_matching_product_variation($product, $attributes);
474 474
 				}
475 475
 
476
-				WC()->cart->add_to_cart( $product->get_id(), $qty, $variation_id, $attributes );
476
+				WC()->cart->add_to_cart($product->get_id(), $qty, $variation_id, $attributes);
477 477
 			}
478 478
 
479
-			if ( 'simple' === ( version_compare( WC_VERSION, '3.0.0', '<' ) ? $product->product_type : $product->get_type() ) ) {
480
-				WC()->cart->add_to_cart( $product->get_id(), $qty );
479
+			if ('simple' === (version_compare(WC_VERSION, '3.0.0', '<') ? $product->product_type : $product->get_type())) {
480
+				WC()->cart->add_to_cart($product->get_id(), $qty);
481 481
 			}
482 482
 		}
483 483
 
@@ -485,7 +485,7 @@  discard block
 block discarded – undo
485 485
 
486 486
 		$build_items = $this->build_line_items();
487 487
 
488
-		wp_send_json( array( 'line_items' => $build_items['line_items'], 'total' => $build_items['total'] ) );
488
+		wp_send_json(array('line_items' => $build_items['line_items'], 'total' => $build_items['total']));
489 489
 	}
490 490
 
491 491
 	/**
@@ -495,13 +495,13 @@  discard block
 block discarded – undo
495 495
 	 * @version 3.1.0
496 496
 	 */
497 497
 	public function generate_apple_pay_cart() {
498
-		if ( ! wp_verify_nonce( $_POST['nonce'], '_wc_stripe_apple_pay_cart_nonce' ) ) {
499
-			wp_die( __( 'Cheatin&#8217; huh?', 'woocommerce-gateway-stripe' ) );
498
+		if ( ! wp_verify_nonce($_POST['nonce'], '_wc_stripe_apple_pay_cart_nonce')) {
499
+			wp_die(__('Cheatin&#8217; huh?', 'woocommerce-gateway-stripe'));
500 500
 		}
501 501
 
502 502
 		$build_items = $this->build_line_items();
503 503
 
504
-		wp_send_json( array( 'line_items' => $build_items['line_items'], 'total' => $build_items['total'] ) );
504
+		wp_send_json(array('line_items' => $build_items['line_items'], 'total' => $build_items['total']));
505 505
 	}
506 506
 
507 507
 	/**
@@ -522,32 +522,32 @@  discard block
 block discarded – undo
522 522
 	 * @version 3.1.0
523 523
 	 * @param array $address
524 524
 	 */
525
-	public function calculate_shipping( $address = array() ) {
526
-		$country  = strtoupper( $address['countryCode'] );
527
-		$state    = strtoupper( $address['administrativeArea'] );
525
+	public function calculate_shipping($address = array()) {
526
+		$country  = strtoupper($address['countryCode']);
527
+		$state    = strtoupper($address['administrativeArea']);
528 528
 		$postcode = $address['postalCode'];
529 529
 		$city     = $address['locality'];
530 530
 
531 531
 		WC()->shipping->reset_shipping();
532 532
 
533
-		if ( $postcode && ! WC_Validation::is_postcode( $postcode, $country ) ) {
534
-			throw new Exception( __( 'Please enter a valid postcode/ZIP.', 'woocommerce-gateway-stripe' ) );
535
-		} elseif ( $postcode ) {
536
-			$postcode = wc_format_postcode( $postcode, $country );
533
+		if ($postcode && ! WC_Validation::is_postcode($postcode, $country)) {
534
+			throw new Exception(__('Please enter a valid postcode/ZIP.', 'woocommerce-gateway-stripe'));
535
+		} elseif ($postcode) {
536
+			$postcode = wc_format_postcode($postcode, $country);
537 537
 		}
538 538
 
539
-		if ( $country ) {
540
-			WC()->customer->set_location( $country, $state, $postcode, $city );
541
-			WC()->customer->set_shipping_location( $country, $state, $postcode, $city );
539
+		if ($country) {
540
+			WC()->customer->set_location($country, $state, $postcode, $city);
541
+			WC()->customer->set_shipping_location($country, $state, $postcode, $city);
542 542
 		} else {
543 543
 			WC()->customer->set_to_base();
544 544
 			WC()->customer->set_shipping_to_base();
545 545
 		}
546 546
 
547
-		if ( version_compare( WC_VERSION, '3.0', '<' ) ) {
548
-			WC()->customer->calculated_shipping( true );
547
+		if (version_compare(WC_VERSION, '3.0', '<')) {
548
+			WC()->customer->calculated_shipping(true);
549 549
 		} else { 
550
-			WC()->customer->set_calculated_shipping( true );
550
+			WC()->customer->set_calculated_shipping(true);
551 551
 			WC()->customer->save();
552 552
 		}
553 553
 
@@ -571,17 +571,17 @@  discard block
 block discarded – undo
571 571
 		$packages[0]['destination']['postcode']  = $postcode;
572 572
 		$packages[0]['destination']['city']      = $city;
573 573
 
574
-		foreach ( WC()->cart->get_cart() as $item ) {
575
-			if ( $item['data']->needs_shipping() ) {
576
-				if ( isset( $item['line_total'] ) ) {
574
+		foreach (WC()->cart->get_cart() as $item) {
575
+			if ($item['data']->needs_shipping()) {
576
+				if (isset($item['line_total'])) {
577 577
 					$packages[0]['contents_cost'] += $item['line_total'];
578 578
 				}
579 579
 			}
580 580
 		}
581 581
 
582
-		$packages = apply_filters( 'woocommerce_cart_shipping_packages', $packages );
582
+		$packages = apply_filters('woocommerce_cart_shipping_packages', $packages);
583 583
 
584
-		WC()->shipping->calculate_shipping( $packages );
584
+		WC()->shipping->calculate_shipping($packages);
585 585
 	}
586 586
 
587 587
 	/**
@@ -591,18 +591,18 @@  discard block
 block discarded – undo
591 591
 	 * @version 3.1.0
592 592
 	 */
593 593
 	public function get_shipping_methods() {
594
-		if ( ! wp_verify_nonce( $_POST['nonce'], '_wc_stripe_apple_pay_get_shipping_methods_nonce' ) ) {
595
-			wp_die( __( 'Cheatin&#8217; huh?', 'woocommerce-gateway-stripe' ) );
594
+		if ( ! wp_verify_nonce($_POST['nonce'], '_wc_stripe_apple_pay_get_shipping_methods_nonce')) {
595
+			wp_die(__('Cheatin&#8217; huh?', 'woocommerce-gateway-stripe'));
596 596
 		}
597 597
 
598
-		if ( ! defined( 'WOOCOMMERCE_CART' ) ) {
599
-			define( 'WOOCOMMERCE_CART', true );
598
+		if ( ! defined('WOOCOMMERCE_CART')) {
599
+			define('WOOCOMMERCE_CART', true);
600 600
 		}
601 601
 
602 602
 		try {
603
-			$address = array_map( 'wc_clean', $_POST['address'] );
603
+			$address = array_map('wc_clean', $_POST['address']);
604 604
 
605
-			$this->calculate_shipping( $address );
605
+			$this->calculate_shipping($address);
606 606
 
607 607
 			// Set the shipping options.
608 608
 			$currency = get_woocommerce_currency();
@@ -610,13 +610,13 @@  discard block
 block discarded – undo
610 610
 
611 611
 			$packages = WC()->shipping->get_packages();
612 612
 
613
-			if ( ! empty( $packages ) && WC()->customer->has_calculated_shipping() ) {
614
-				foreach ( $packages as $package_key => $package ) {
615
-					if ( empty( $package['rates'] ) ) {
616
-						throw new Exception( __( 'Unable to find shipping method for address.', 'woocommerce-gateway-stripe' ) );
613
+			if ( ! empty($packages) && WC()->customer->has_calculated_shipping()) {
614
+				foreach ($packages as $package_key => $package) {
615
+					if (empty($package['rates'])) {
616
+						throw new Exception(__('Unable to find shipping method for address.', 'woocommerce-gateway-stripe'));
617 617
 					}
618 618
 
619
-					foreach ( $package['rates'] as $key => $rate ) {
619
+					foreach ($package['rates'] as $key => $rate) {
620 620
 						$data[] = array(
621 621
 							'id'       => $rate->id,
622 622
 							'label'    => $rate->label,
@@ -630,19 +630,19 @@  discard block
 block discarded – undo
630 630
 				}
631 631
 
632 632
 				// Auto select the first shipping method.
633
-				WC()->session->set( 'chosen_shipping_methods', array( $data[0]['id'] ) );
633
+				WC()->session->set('chosen_shipping_methods', array($data[0]['id']));
634 634
 
635 635
 				WC()->cart->calculate_totals();
636 636
 
637 637
 				$build_items = $this->build_line_items();
638 638
 
639
-				wp_send_json( array( 'success' => 'true', 'shipping_methods' => $this->build_shipping_methods( $data ), 'line_items' => $build_items['line_items'], 'total' => $build_items['total'] ) );
639
+				wp_send_json(array('success' => 'true', 'shipping_methods' => $this->build_shipping_methods($data), 'line_items' => $build_items['line_items'], 'total' => $build_items['total']));
640 640
 			} else {
641
-				throw new Exception( __( 'Unable to find shipping method for address.', 'woocommerce-gateway-stripe' ) );
641
+				throw new Exception(__('Unable to find shipping method for address.', 'woocommerce-gateway-stripe'));
642 642
 			}
643
-		} catch ( Exception $e ) {
643
+		} catch (Exception $e) {
644 644
 			$build_items = $this->build_line_items();
645
-			wp_send_json( array( 'success' => 'false', 'shipping_methods' => array(), 'line_items' => $build_items['line_items'], 'total' => $build_items['total'] ) );
645
+			wp_send_json(array('success' => 'false', 'shipping_methods' => array(), 'line_items' => $build_items['line_items'], 'total' => $build_items['total']));
646 646
 		}
647 647
 	}
648 648
 
@@ -653,22 +653,22 @@  discard block
 block discarded – undo
653 653
 	 * @version 3.1.0
654 654
 	 */
655 655
 	public function update_shipping_method() {
656
-		if ( ! defined( 'WOOCOMMERCE_CART' ) ) {
657
-			define( 'WOOCOMMERCE_CART', true );
656
+		if ( ! defined('WOOCOMMERCE_CART')) {
657
+			define('WOOCOMMERCE_CART', true);
658 658
 		}
659 659
 
660
-		if ( ! wp_verify_nonce( $_POST['nonce'], '_wc_stripe_apple_pay_update_shipping_method_nonce' ) ) {
661
-			wp_die( __( 'Cheatin&#8217; huh?', 'woocommerce-gateway-stripe' ) );
660
+		if ( ! wp_verify_nonce($_POST['nonce'], '_wc_stripe_apple_pay_update_shipping_method_nonce')) {
661
+			wp_die(__('Cheatin&#8217; huh?', 'woocommerce-gateway-stripe'));
662 662
 		}
663 663
 
664
-		$selected_shipping_method = array_map( 'wc_clean', $_POST['selected_shipping_method'] );
664
+		$selected_shipping_method = array_map('wc_clean', $_POST['selected_shipping_method']);
665 665
 
666
-		WC()->session->set( 'chosen_shipping_methods', array( $selected_shipping_method['identifier'] ) );
666
+		WC()->session->set('chosen_shipping_methods', array($selected_shipping_method['identifier']));
667 667
 
668 668
 		WC()->cart->calculate_totals();
669 669
 
670 670
 		$build_items = $this->build_line_items();
671
-		wp_send_json( array( 'success' => 'true', 'line_items' => $build_items['line_items'], 'total' => $build_items['total'] ) );
671
+		wp_send_json(array('success' => 'true', 'line_items' => $build_items['line_items'], 'total' => $build_items['total']));
672 672
 	}
673 673
 
674 674
 	/**
@@ -679,37 +679,37 @@  discard block
 block discarded – undo
679 679
 	 * @version 3.1.0
680 680
 	 */
681 681
 	public function process_apple_pay() {
682
-		if ( ! wp_verify_nonce( $_POST['nonce'], '_wc_stripe_apple_pay_nonce' ) ) {
683
-			wp_die( __( 'Cheatin&#8217; huh?', 'woocommerce-gateway-stripe' ) );
682
+		if ( ! wp_verify_nonce($_POST['nonce'], '_wc_stripe_apple_pay_nonce')) {
683
+			wp_die(__('Cheatin&#8217; huh?', 'woocommerce-gateway-stripe'));
684 684
 		}
685 685
 
686 686
 		try {
687
-			$result = array_map( 'wc_clean', $_POST['result'] );
687
+			$result = array_map('wc_clean', $_POST['result']);
688 688
 
689
-			$order = $this->create_order( $result );
689
+			$order = $this->create_order($result);
690 690
 
691
-			$order_id = version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->id : $order->get_id();
691
+			$order_id = version_compare(WC_VERSION, '3.0.0', '<') ? $order->id : $order->get_id();
692 692
 
693 693
 			// Handle payment.
694
-			if ( $order->get_total() > 0 ) {
694
+			if ($order->get_total() > 0) {
695 695
 
696
-				if ( $order->get_total() * 100 < WC_Stripe_Helper::get_minimum_amount() ) {
697
-					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_Helper::get_minimum_amount() / 100 ) ) );
696
+				if ($order->get_total() * 100 < WC_Stripe_Helper::get_minimum_amount()) {
697
+					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_Helper::get_minimum_amount() / 100)));
698 698
 				}
699 699
 
700
-				WC_Stripe_Logger::log( "Info: Begin processing payment for order {$order_id} for the amount of {$order->get_total()}" );
700
+				WC_Stripe_Logger::log("Info: Begin processing payment for order {$order_id} for the amount of {$order->get_total()}");
701 701
 
702 702
 				// Make the request.
703
-				$response = WC_Stripe_API::request( $this->generate_payment_request( $order, $result['token']['id'] ) );
703
+				$response = WC_Stripe_API::request($this->generate_payment_request($order, $result['token']['id']));
704 704
 
705
-				if ( is_wp_error( $response ) ) {
705
+				if (is_wp_error($response)) {
706 706
 					$localized_messages = WC_Stripe_Helper::get_localized_messages();
707 707
 
708
-					throw new Exception( ( isset( $localized_messages[ $response->get_error_code() ] ) ? $localized_messages[ $response->get_error_code() ] : $response->get_error_message() ) );
708
+					throw new Exception((isset($localized_messages[$response->get_error_code()]) ? $localized_messages[$response->get_error_code()] : $response->get_error_message()));
709 709
 				}
710 710
 
711 711
 				// Process valid response.
712
-				$this->process_response( $response, $order );
712
+				$this->process_response($response, $order);
713 713
 			} else {
714 714
 				$order->payment_complete();
715 715
 			}
@@ -717,24 +717,24 @@  discard block
 block discarded – undo
717 717
 			// Remove cart.
718 718
 			WC()->cart->empty_cart();
719 719
 
720
-			update_post_meta( $order_id, '_customer_user', get_current_user_id() );
721
-			update_post_meta( $order_id, '_payment_method_title', 'Apple Pay (Stripe)' );
720
+			update_post_meta($order_id, '_customer_user', get_current_user_id());
721
+			update_post_meta($order_id, '_payment_method_title', 'Apple Pay (Stripe)');
722 722
 
723 723
 			// Return thank you page redirect.
724
-			wp_send_json( array(
724
+			wp_send_json(array(
725 725
 				'success'  => 'true',
726
-				'redirect' => $this->get_return_url( $order ),
727
-			) );
726
+				'redirect' => $this->get_return_url($order),
727
+			));
728 728
 
729
-		} catch ( Exception $e ) {
730
-			WC()->session->set( 'refresh_totals', true );
731
-			WC_Stripe_Logger::log( sprintf( __( 'Error: %s', 'woocommerce-gateway-stripe' ), $e->getMessage() ) );
729
+		} catch (Exception $e) {
730
+			WC()->session->set('refresh_totals', true);
731
+			WC_Stripe_Logger::log(sprintf(__('Error: %s', 'woocommerce-gateway-stripe'), $e->getMessage()));
732 732
 
733
-			if ( is_object( $order ) && isset( $order_id ) && $order->has_status( array( 'pending', 'failed' ) ) ) {
734
-				$this->send_failed_order_email( $order_id );
733
+			if (is_object($order) && isset($order_id) && $order->has_status(array('pending', 'failed'))) {
734
+				$this->send_failed_order_email($order_id);
735 735
 			}
736 736
 
737
-			wp_send_json( array( 'success' => 'false', 'msg' => $e->getMessage() ) );
737
+			wp_send_json(array('success' => 'false', 'msg' => $e->getMessage()));
738 738
 		}
739 739
 	}
740 740
 
@@ -744,16 +744,16 @@  discard block
 block discarded – undo
744 744
 	 * @param string $source token
745 745
 	 * @return array()
746 746
 	 */
747
-	public function generate_payment_request( $order, $source ) {
747
+	public function generate_payment_request($order, $source) {
748 748
 		$post_data                = array();
749
-		$post_data['currency']    = strtolower( version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->get_order_currency() : $order->get_currency() );
750
-		$post_data['amount']      = WC_Stripe_Helper::get_stripe_amount( $order->get_total(), $post_data['currency'] );
751
-		$post_data['description'] = sprintf( __( '%1$s - Order %2$s', 'woocommerce-gateway-stripe' ), $this->statement_descriptor, $order->get_order_number() );
749
+		$post_data['currency']    = strtolower(version_compare(WC_VERSION, '3.0.0', '<') ? $order->get_order_currency() : $order->get_currency());
750
+		$post_data['amount']      = WC_Stripe_Helper::get_stripe_amount($order->get_total(), $post_data['currency']);
751
+		$post_data['description'] = sprintf(__('%1$s - Order %2$s', 'woocommerce-gateway-stripe'), $this->statement_descriptor, $order->get_order_number());
752 752
 		$post_data['capture']     = $this->capture ? 'true' : 'false';
753 753
 
754
-		$billing_email      = version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->billing_email : $order->get_billing_email();
754
+		$billing_email = version_compare(WC_VERSION, '3.0.0', '<') ? $order->billing_email : $order->get_billing_email();
755 755
 
756
-		if ( ! empty( $billing_email ) && apply_filters( 'wc_stripe_send_stripe_receipt', false ) ) {
756
+		if ( ! empty($billing_email) && apply_filters('wc_stripe_send_stripe_receipt', false)) {
757 757
 			$post_data['receipt_email'] = $billing_email;
758 758
 		}
759 759
 
@@ -768,7 +768,7 @@  discard block
 block discarded – undo
768 768
 		 * @param WC_Order $order
769 769
 		 * @param object $source
770 770
 		 */
771
-		return apply_filters( 'wc_stripe_generate_payment_request', $post_data, $order );
771
+		return apply_filters('wc_stripe_generate_payment_request', $post_data, $order);
772 772
 	}
773 773
 
774 774
 	/**
@@ -777,14 +777,14 @@  discard block
 block discarded – undo
777 777
 	 * @since 3.1.0
778 778
 	 * @version 3.1.0
779 779
 	 */
780
-	public function build_shipping_methods( $shipping_methods ) {
781
-		if ( empty( $shipping_methods ) ) {
780
+	public function build_shipping_methods($shipping_methods) {
781
+		if (empty($shipping_methods)) {
782 782
 			return array();
783 783
 		}
784 784
 
785 785
 		$shipping = array();
786 786
 
787
-		foreach ( $shipping_methods as $method ) {
787
+		foreach ($shipping_methods as $method) {
788 788
 			$shipping[] = array(
789 789
 				'label'      => $method['label'],
790 790
 				'detail'     => '',
@@ -803,70 +803,70 @@  discard block
 block discarded – undo
803 803
 	 * @version 3.2.0
804 804
 	 */
805 805
 	public function build_line_items() {
806
-		if ( ! defined( 'WOOCOMMERCE_CART' ) ) {
807
-			define( 'WOOCOMMERCE_CART', true );
806
+		if ( ! defined('WOOCOMMERCE_CART')) {
807
+			define('WOOCOMMERCE_CART', true);
808 808
 		}
809 809
 		
810 810
 		$items    = array();
811 811
 		$subtotal = 0;
812 812
 
813
-		foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {
814
-			$amount         = wc_format_decimal( $cart_item['line_subtotal'], $this->dp );
815
-			$subtotal       += $cart_item['line_subtotal'];
813
+		foreach (WC()->cart->get_cart() as $cart_item_key => $cart_item) {
814
+			$amount         = wc_format_decimal($cart_item['line_subtotal'], $this->dp);
815
+			$subtotal += $cart_item['line_subtotal'];
816 816
 			$quantity_label = 1 < $cart_item['quantity'] ? ' (x' . $cart_item['quantity'] . ')' : '';
817 817
 
818
-			$product_name = version_compare( WC_VERSION, '3.0', '<' ) ? $cart_item['data']->post->post_title : $cart_item['data']->get_name();
818
+			$product_name = version_compare(WC_VERSION, '3.0', '<') ? $cart_item['data']->post->post_title : $cart_item['data']->get_name();
819 819
 
820 820
 			$item = array(
821 821
 				'type'   => 'final',
822 822
 				'label'  => $product_name . $quantity_label,
823
-				'amount' => wc_format_decimal( $amount, $this->dp ),
823
+				'amount' => wc_format_decimal($amount, $this->dp),
824 824
 			);
825 825
 
826 826
 			$items[] = $item;
827 827
 		}
828 828
 
829 829
 		// Default show only subtotal instead of itemization.
830
-		if ( apply_filters( 'wc_stripe_apple_pay_disable_itemization', true ) ) {
830
+		if (apply_filters('wc_stripe_apple_pay_disable_itemization', true)) {
831 831
 			$items = array();
832 832
 			$items[] = array(
833 833
 				'type'   => 'final',
834
-				'label'  => esc_html( __( 'Sub-Total', 'woocommerce-gateway-stripe' ) ),
835
-				'amount' => wc_format_decimal( $subtotal, $this->dp ),
834
+				'label'  => esc_html(__('Sub-Total', 'woocommerce-gateway-stripe')),
835
+				'amount' => wc_format_decimal($subtotal, $this->dp),
836 836
 			);
837 837
 		}
838 838
 
839
-		$discounts   = wc_format_decimal( WC()->cart->get_cart_discount_total(), $this->dp );
840
-		$tax         = wc_format_decimal( WC()->cart->tax_total + WC()->cart->shipping_tax_total, $this->dp );
841
-		$shipping    = wc_format_decimal( WC()->cart->shipping_total, $this->dp );
842
-		$item_total  = wc_format_decimal( WC()->cart->cart_contents_total, $this->dp ) + $discounts;
843
-		$order_total = wc_format_decimal( $item_total + $tax + $shipping - $discounts, $this->dp );
839
+		$discounts   = wc_format_decimal(WC()->cart->get_cart_discount_total(), $this->dp);
840
+		$tax         = wc_format_decimal(WC()->cart->tax_total + WC()->cart->shipping_tax_total, $this->dp);
841
+		$shipping    = wc_format_decimal(WC()->cart->shipping_total, $this->dp);
842
+		$item_total  = wc_format_decimal(WC()->cart->cart_contents_total, $this->dp) + $discounts;
843
+		$order_total = wc_format_decimal($item_total + $tax + $shipping - $discounts, $this->dp);
844 844
 
845
-		if ( wc_tax_enabled() ) {
845
+		if (wc_tax_enabled()) {
846 846
 			$items[] = array(
847 847
 				'type'   => 'final',
848
-				'label'  => esc_html( __( 'Tax', 'woocommerce-gateway-stripe' ) ),
848
+				'label'  => esc_html(__('Tax', 'woocommerce-gateway-stripe')),
849 849
 				'amount' => $tax,
850 850
 			);
851 851
 		}
852 852
 
853
-		if ( WC()->cart->needs_shipping() && $this->is_shipping_enabled ) {
853
+		if (WC()->cart->needs_shipping() && $this->is_shipping_enabled) {
854 854
 			$items[] = array(
855 855
 				'type'   => 'final',
856
-				'label'  => esc_html( __( 'Shipping', 'woocommerce-gateway-stripe' ) ),
856
+				'label'  => esc_html(__('Shipping', 'woocommerce-gateway-stripe')),
857 857
 				'amount' => $shipping,
858 858
 			);
859 859
 		}
860 860
 
861
-		if ( WC()->cart->has_discount() ) {
861
+		if (WC()->cart->has_discount()) {
862 862
 			$items[] = array(
863 863
 				'type'   => 'final',
864
-				'label'  => esc_html( __( 'Discount', 'woocommerce-gateway-stripe' ) ),
864
+				'label'  => esc_html(__('Discount', 'woocommerce-gateway-stripe')),
865 865
 				'amount' => '-' . $discounts,
866 866
 			);
867 867
 		}
868 868
 
869
-		return array( 'line_items' => $items, 'total' => $order_total );
869
+		return array('line_items' => $items, 'total' => $order_total);
870 870
 	}
871 871
 
872 872
 	/**
@@ -877,28 +877,28 @@  discard block
 block discarded – undo
877 877
 	 * @param array $data
878 878
 	 * @return object $order
879 879
 	 */
880
-	public function create_order( $data = array() ) {
881
-		if ( empty( $data ) ) {
882
-			throw new Exception( sprintf( __( 'Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe' ), 520 ) );
880
+	public function create_order($data = array()) {
881
+		if (empty($data)) {
882
+			throw new Exception(sprintf(__('Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe'), 520));
883 883
 		}
884 884
 
885
-		if ( ! defined( 'WOOCOMMERCE_CART' ) ) {
886
-			define( 'WOOCOMMERCE_CART', true );
885
+		if ( ! defined('WOOCOMMERCE_CART')) {
886
+			define('WOOCOMMERCE_CART', true);
887 887
 		}
888 888
 
889 889
 		$order = wc_create_order();
890
-		$order_id = version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->id : $order->get_id();
890
+		$order_id = version_compare(WC_VERSION, '3.0.0', '<') ? $order->id : $order->get_id();
891 891
 
892
-		if ( is_wp_error( $order ) ) {
893
-			throw new Exception( sprintf( __( 'Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe' ), 520 ) );
894
-		} elseif ( false === $order ) {
895
-			throw new Exception( sprintf( __( 'Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe' ), 521 ) );
892
+		if (is_wp_error($order)) {
893
+			throw new Exception(sprintf(__('Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe'), 520));
894
+		} elseif (false === $order) {
895
+			throw new Exception(sprintf(__('Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe'), 521));
896 896
 		} else {
897
-			do_action( 'woocommerce_new_order', $order_id );
897
+			do_action('woocommerce_new_order', $order_id);
898 898
 		}
899 899
 
900 900
 		// Store the line items to the new/resumed order
901
-		foreach ( WC()->cart->get_cart() as $cart_item_key => $values ) {
901
+		foreach (WC()->cart->get_cart() as $cart_item_key => $values) {
902 902
 			$item_id = $order->add_product(
903 903
 				$values['data'],
904 904
 				$values['quantity'],
@@ -914,25 +914,25 @@  discard block
 block discarded – undo
914 914
 				)
915 915
 			);
916 916
 
917
-			if ( ! $item_id ) {
918
-				throw new Exception( sprintf( __( 'Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe' ), 525 ) );
917
+			if ( ! $item_id) {
918
+				throw new Exception(sprintf(__('Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe'), 525));
919 919
 			}
920 920
 
921 921
 			// Allow plugins to add order item meta
922
-			if ( version_compare( WC_VERSION, '3.0', '<' ) ) {
923
-				do_action( 'woocommerce_add_order_item_meta', $item_id, $values, $cart_item_key );
922
+			if (version_compare(WC_VERSION, '3.0', '<')) {
923
+				do_action('woocommerce_add_order_item_meta', $item_id, $values, $cart_item_key);
924 924
 			} else {
925
-				do_action( 'woocommerce_new_order_item', $item_id, wc_get_product( $item_id ), $order->get_id() );
925
+				do_action('woocommerce_new_order_item', $item_id, wc_get_product($item_id), $order->get_id());
926 926
 			}
927 927
 		}
928 928
 
929 929
 		// Store fees
930
-		foreach ( WC()->cart->get_fees() as $fee_key => $fee ) {
931
-			if ( version_compare( WC_VERSION, '3.0', '<' ) ) {
932
-				$item_id = $order->add_fee( $fee );
930
+		foreach (WC()->cart->get_fees() as $fee_key => $fee) {
931
+			if (version_compare(WC_VERSION, '3.0', '<')) {
932
+				$item_id = $order->add_fee($fee);
933 933
 			} else {
934 934
 				$item = new WC_Order_Item_Fee();
935
-				$item->set_props( array(
935
+				$item->set_props(array(
936 936
 					'name'      => $fee->name,
937 937
 					'tax_class' => $fee->taxable ? $fee->tax_class : 0,
938 938
 					'total'     => $fee->amount,
@@ -941,79 +941,79 @@  discard block
 block discarded – undo
941 941
 						'total' => $fee->tax_data,
942 942
 					),
943 943
 					'order_id'  => $order->get_id(),
944
-				) );
944
+				));
945 945
 				$item_id = $item->save();
946
-				$order->add_item( $item );
946
+				$order->add_item($item);
947 947
 			}
948 948
 
949
-			if ( ! $item_id ) {
950
-				throw new Exception( sprintf( __( 'Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe' ), 526 ) );
949
+			if ( ! $item_id) {
950
+				throw new Exception(sprintf(__('Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe'), 526));
951 951
 			}
952 952
 
953 953
 			// Allow plugins to add order item meta to fees
954
-			if ( version_compare( WC_VERSION, '3.0', '<' ) ) {
955
-				do_action( 'woocommerce_add_order_fee_meta', $order_id, $item_id, $fee, $fee_key );
954
+			if (version_compare(WC_VERSION, '3.0', '<')) {
955
+				do_action('woocommerce_add_order_fee_meta', $order_id, $item_id, $fee, $fee_key);
956 956
 			} else {
957
-				do_action( 'woocommerce_new_order_item', $item_id, $fee, $order->get_id() );
957
+				do_action('woocommerce_new_order_item', $item_id, $fee, $order->get_id());
958 958
 			}
959 959
 		}
960 960
 
961 961
 		// Store tax rows
962
-		foreach ( array_keys( WC()->cart->taxes + WC()->cart->shipping_taxes ) as $tax_rate_id ) {
963
-			$tax_amount = WC()->cart->get_tax_amount( $tax_rate_id );
964
-			$shipping_tax_amount = WC()->cart->get_shipping_tax_amount( $tax_rate_id );
962
+		foreach (array_keys(WC()->cart->taxes + WC()->cart->shipping_taxes) as $tax_rate_id) {
963
+			$tax_amount = WC()->cart->get_tax_amount($tax_rate_id);
964
+			$shipping_tax_amount = WC()->cart->get_shipping_tax_amount($tax_rate_id);
965 965
 
966
-			if ( version_compare( WC_VERSION, '3.0', '<' ) ) {
967
-				$item_id = $order->add_tax( $tax_rate_id, $tax_amount, $shipping_tax_amount );
966
+			if (version_compare(WC_VERSION, '3.0', '<')) {
967
+				$item_id = $order->add_tax($tax_rate_id, $tax_amount, $shipping_tax_amount);
968 968
 			} else {
969 969
 				$item = new WC_Order_Item_Tax();
970
-				$item->set_props( array(
970
+				$item->set_props(array(
971 971
 					'rate_id'            => $tax_rate_id,
972 972
 					'tax_total'          => $tax_amount,
973 973
 					'shipping_tax_total' => $shipping_tax_amount,
974
-				) );
975
-				$item->set_rate( $tax_rate_id );
976
-				$item->set_order_id( $order->get_id() );
974
+				));
975
+				$item->set_rate($tax_rate_id);
976
+				$item->set_order_id($order->get_id());
977 977
 				$item_id = $item->save();
978
-				$order->add_item( $item );
978
+				$order->add_item($item);
979 979
 			}
980 980
 
981
-			if ( $tax_rate_id && ! $item_id && apply_filters( 'woocommerce_cart_remove_taxes_zero_rate_id', 'zero-rated' ) !== $tax_rate_id ) {
982
-				throw new Exception( sprintf( __( 'Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe' ), 528 ) );
981
+			if ($tax_rate_id && ! $item_id && apply_filters('woocommerce_cart_remove_taxes_zero_rate_id', 'zero-rated') !== $tax_rate_id) {
982
+				throw new Exception(sprintf(__('Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe'), 528));
983 983
 			}
984 984
 		}
985 985
 
986 986
 		// Store coupons
987
-		$discount = WC()->cart->get_coupon_discount_amount( $code );
988
-		$discount_tax = WC()->cart->get_coupon_discount_tax_amount( $code );
987
+		$discount = WC()->cart->get_coupon_discount_amount($code);
988
+		$discount_tax = WC()->cart->get_coupon_discount_tax_amount($code);
989 989
 
990
-		foreach ( WC()->cart->get_coupons() as $code => $coupon ) {
991
-			if ( version_compare( WC_VERSION, '3.0', '<' ) ) {
992
-				$coupon_id = $order->add_coupon( $code, $discount, $discount_tax );
990
+		foreach (WC()->cart->get_coupons() as $code => $coupon) {
991
+			if (version_compare(WC_VERSION, '3.0', '<')) {
992
+				$coupon_id = $order->add_coupon($code, $discount, $discount_tax);
993 993
 			} else {
994 994
 				$item = new WC_Order_Item_Coupon();
995
-				$item->set_props( array(
995
+				$item->set_props(array(
996 996
 					'code'         => $code,
997 997
 					'discount'     => $discount,
998 998
 					'discount_tax' => $discount_tax,
999 999
 					'order_id'     => $order->get_id(),
1000
-				) );
1000
+				));
1001 1001
 				$coupon_id = $item->save();
1002
-				$order->add_item( $item );
1002
+				$order->add_item($item);
1003 1003
 			}
1004 1004
 
1005
-			if ( ! $coupon_id ) {
1006
-				throw new Exception( sprintf( __( 'Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe' ), 529 ) );
1005
+			if ( ! $coupon_id) {
1006
+				throw new Exception(sprintf(__('Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe'), 529));
1007 1007
 			}
1008 1008
 		}
1009 1009
 
1010 1010
 		// Billing address
1011 1011
 		$billing_address = array();
1012
-		if ( ! empty( $data['token']['card'] ) ) {
1012
+		if ( ! empty($data['token']['card'])) {
1013 1013
 			// Name from Stripe is a full name string.
1014
-			$name                          = explode( ' ', $data['token']['card']['name'] );
1015
-			$lastname                      = array_pop( $name );
1016
-			$firstname                     = implode( ' ', $name );
1014
+			$name                          = explode(' ', $data['token']['card']['name']);
1015
+			$lastname                      = array_pop($name);
1016
+			$firstname                     = implode(' ', $name);
1017 1017
 			$billing_address['first_name'] = $firstname;
1018 1018
 			$billing_address['last_name']  = $lastname;
1019 1019
 			$billing_address['email']      = $data['shippingContact']['emailAddress'];
@@ -1028,7 +1028,7 @@  discard block
 block discarded – undo
1028 1028
 
1029 1029
 		// Shipping address.
1030 1030
 		$shipping_address = array();
1031
-		if ( WC()->cart->needs_shipping() && $this->is_shipping_enabled && ! empty( $data['shippingContact'] ) ) {
1031
+		if (WC()->cart->needs_shipping() && $this->is_shipping_enabled && ! empty($data['shippingContact'])) {
1032 1032
 			$shipping_address['first_name'] = $data['shippingContact']['givenName'];
1033 1033
 			$shipping_address['last_name']  = $data['shippingContact']['familyName'];
1034 1034
 			$shipping_address['email']      = $data['shippingContact']['emailAddress'];
@@ -1039,7 +1039,7 @@  discard block
 block discarded – undo
1039 1039
 			$shipping_address['city']       = $data['shippingContact']['locality'];
1040 1040
 			$shipping_address['state']      = $data['shippingContact']['administrativeArea'];
1041 1041
 			$shipping_address['postcode']   = $data['shippingContact']['postalCode'];
1042
-		} elseif ( ! empty( $data['shippingContact'] ) ) {
1042
+		} elseif ( ! empty($data['shippingContact'])) {
1043 1043
 			$shipping_address['first_name'] = $firstname;
1044 1044
 			$shipping_address['last_name']  = $lastname;
1045 1045
 			$shipping_address['email']      = $data['shippingContact']['emailAddress'];
@@ -1052,33 +1052,33 @@  discard block
 block discarded – undo
1052 1052
 			$shipping_address['postcode']   = $data['token']['card']['address_zip'];
1053 1053
 		}
1054 1054
 
1055
-		$order->set_address( $billing_address, 'billing' );
1056
-		$order->set_address( $shipping_address, 'shipping' );
1055
+		$order->set_address($billing_address, 'billing');
1056
+		$order->set_address($shipping_address, 'shipping');
1057 1057
 
1058
-		WC()->shipping->calculate_shipping( WC()->cart->get_shipping_packages() );
1058
+		WC()->shipping->calculate_shipping(WC()->cart->get_shipping_packages());
1059 1059
 
1060 1060
 		// Get the rate object selected by user.
1061
-		foreach ( WC()->shipping->get_packages() as $package_key => $package ) {
1062
-			foreach ( $package['rates'] as $key => $rate ) {
1061
+		foreach (WC()->shipping->get_packages() as $package_key => $package) {
1062
+			foreach ($package['rates'] as $key => $rate) {
1063 1063
 				// Loop through user chosen shipping methods.
1064
-				foreach ( WC()->session->get( 'chosen_shipping_methods' ) as $method ) {
1065
-					if ( $method === $key ) {
1066
-						if ( version_compare( WC_VERSION, '3.0', '<' ) ) {
1067
-							$order->add_shipping( $rate );
1064
+				foreach (WC()->session->get('chosen_shipping_methods') as $method) {
1065
+					if ($method === $key) {
1066
+						if (version_compare(WC_VERSION, '3.0', '<')) {
1067
+							$order->add_shipping($rate);
1068 1068
 						} else {
1069 1069
 							$item = new WC_Order_Item_Shipping();
1070
-							$item->set_props( array(
1070
+							$item->set_props(array(
1071 1071
 								'method_title' => $rate->label,
1072 1072
 								'method_id'    => $rate->id,
1073
-								'total'        => wc_format_decimal( $rate->cost ),
1073
+								'total'        => wc_format_decimal($rate->cost),
1074 1074
 								'taxes'        => $rate->taxes,
1075 1075
 								'order_id'     => $order->get_id(),
1076
-							) );
1077
-							foreach ( $rate->get_meta_data() as $key => $value ) {
1078
-								$item->add_meta_data( $key, $value, true );
1076
+							));
1077
+							foreach ($rate->get_meta_data() as $key => $value) {
1078
+								$item->add_meta_data($key, $value, true);
1079 1079
 							}
1080 1080
 							$item->save();
1081
-							$order->add_item( $item );
1081
+							$order->add_item($item);
1082 1082
 						}
1083 1083
 					}
1084 1084
 				}
@@ -1086,37 +1086,37 @@  discard block
 block discarded – undo
1086 1086
 		}
1087 1087
 
1088 1088
 		$available_gateways = WC()->payment_gateways->get_available_payment_gateways();
1089
-		$order->set_payment_method( $available_gateways['stripe'] );
1089
+		$order->set_payment_method($available_gateways['stripe']);
1090 1090
 		WC()->cart->calculate_totals();
1091 1091
 
1092
-		if ( version_compare( WC_VERSION, '3.0', '<' ) ) {
1093
-			$order->set_total( WC()->cart->shipping_total, 'shipping' );
1094
-			$order->set_total( WC()->cart->get_cart_discount_total(), 'cart_discount' );
1095
-			$order->set_total( WC()->cart->get_cart_discount_tax_total(), 'cart_discount_tax' );
1096
-			$order->set_total( WC()->cart->tax_total, 'tax' );
1097
-			$order->set_total( WC()->cart->shipping_tax_total, 'shipping_tax' );
1098
-			$order->set_total( WC()->cart->total );
1092
+		if (version_compare(WC_VERSION, '3.0', '<')) {
1093
+			$order->set_total(WC()->cart->shipping_total, 'shipping');
1094
+			$order->set_total(WC()->cart->get_cart_discount_total(), 'cart_discount');
1095
+			$order->set_total(WC()->cart->get_cart_discount_tax_total(), 'cart_discount_tax');
1096
+			$order->set_total(WC()->cart->tax_total, 'tax');
1097
+			$order->set_total(WC()->cart->shipping_tax_total, 'shipping_tax');
1098
+			$order->set_total(WC()->cart->total);
1099 1099
 		} else {
1100
-			$order->set_shipping_total( WC()->cart->shipping_total );
1101
-			$order->set_discount_total( WC()->cart->get_cart_discount_total() );
1102
-			$order->set_discount_tax( WC()->cart->get_cart_discount_tax_total() );
1103
-			$order->set_cart_tax( WC()->cart->tax_total );
1104
-			$order->set_shipping_tax( WC()->cart->shipping_tax_total );
1105
-
1106
-			$discounts   = wc_format_decimal( WC()->cart->get_cart_discount_total(), $this->dp );
1107
-			$tax         = wc_format_decimal( WC()->cart->tax_total + WC()->cart->shipping_tax_total, $this->dp );
1108
-			$shipping    = wc_format_decimal( WC()->cart->shipping_total, $this->dp );
1109
-			$item_total  = wc_format_decimal( WC()->cart->cart_contents_total, $this->dp ) + $discounts;
1110
-			$order_total = wc_format_decimal( $item_total + $tax + $shipping - $discounts, $this->dp );
1111
-
1112
-			$order->set_total( $order_total );
1100
+			$order->set_shipping_total(WC()->cart->shipping_total);
1101
+			$order->set_discount_total(WC()->cart->get_cart_discount_total());
1102
+			$order->set_discount_tax(WC()->cart->get_cart_discount_tax_total());
1103
+			$order->set_cart_tax(WC()->cart->tax_total);
1104
+			$order->set_shipping_tax(WC()->cart->shipping_tax_total);
1105
+
1106
+			$discounts   = wc_format_decimal(WC()->cart->get_cart_discount_total(), $this->dp);
1107
+			$tax         = wc_format_decimal(WC()->cart->tax_total + WC()->cart->shipping_tax_total, $this->dp);
1108
+			$shipping    = wc_format_decimal(WC()->cart->shipping_total, $this->dp);
1109
+			$item_total  = wc_format_decimal(WC()->cart->cart_contents_total, $this->dp) + $discounts;
1110
+			$order_total = wc_format_decimal($item_total + $tax + $shipping - $discounts, $this->dp);
1111
+
1112
+			$order->set_total($order_total);
1113 1113
 			$order->save();
1114 1114
 		}
1115 1115
 
1116 1116
 		// If we got here, the order was created without problems!
1117
-		wc_transaction_query( 'commit' );
1117
+		wc_transaction_query('commit');
1118 1118
 
1119
-		do_action( 'woocommerce_checkout_update_order_meta', $order_id, array() );
1119
+		do_action('woocommerce_checkout_update_order_meta', $order_id, array());
1120 1120
 
1121 1121
 		return $order;
1122 1122
 	}
Please login to merge, or discard this patch.
includes/compat/class-wc-gateway-stripe-addons.php 1 patch
Spacing   +132 added lines, -132 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) {
2
+if ( ! defined('ABSPATH')) {
3 3
 	exit;
4 4
 }
5 5
 
@@ -18,25 +18,25 @@  discard block
 block discarded – undo
18 18
 	public function __construct() {
19 19
 		parent::__construct();
20 20
 
21
-		if ( class_exists( 'WC_Subscriptions_Order' ) ) {
22
-			add_action( 'woocommerce_scheduled_subscription_payment_' . $this->id, array( $this, 'scheduled_subscription_payment' ), 10, 2 );
23
-			add_action( 'wcs_resubscribe_order_created', array( $this, 'delete_resubscribe_meta' ), 10 );
24
-			add_action( 'wcs_renewal_order_created', array( $this, 'delete_renewal_meta' ), 10 );
25
-			add_action( 'woocommerce_subscription_failing_payment_method_updated_stripe', array( $this, 'update_failing_payment_method' ), 10, 2 );
21
+		if (class_exists('WC_Subscriptions_Order')) {
22
+			add_action('woocommerce_scheduled_subscription_payment_' . $this->id, array($this, 'scheduled_subscription_payment'), 10, 2);
23
+			add_action('wcs_resubscribe_order_created', array($this, 'delete_resubscribe_meta'), 10);
24
+			add_action('wcs_renewal_order_created', array($this, 'delete_renewal_meta'), 10);
25
+			add_action('woocommerce_subscription_failing_payment_method_updated_stripe', array($this, 'update_failing_payment_method'), 10, 2);
26 26
 
27 27
 			// display the credit card used for a subscription in the "My Subscriptions" table
28
-			add_filter( 'woocommerce_my_subscriptions_payment_method', array( $this, 'maybe_render_subscription_payment_method' ), 10, 2 );
28
+			add_filter('woocommerce_my_subscriptions_payment_method', array($this, 'maybe_render_subscription_payment_method'), 10, 2);
29 29
 
30 30
 			// allow store managers to manually set Stripe as the payment method on a subscription
31
-			add_filter( 'woocommerce_subscription_payment_meta', array( $this, 'add_subscription_payment_meta' ), 10, 2 );
32
-			add_filter( 'woocommerce_subscription_validate_payment_meta', array( $this, 'validate_subscription_payment_meta' ), 10, 2 );
31
+			add_filter('woocommerce_subscription_payment_meta', array($this, 'add_subscription_payment_meta'), 10, 2);
32
+			add_filter('woocommerce_subscription_validate_payment_meta', array($this, 'validate_subscription_payment_meta'), 10, 2);
33 33
 		}
34 34
 
35
-		if ( class_exists( 'WC_Pre_Orders_Order' ) ) {
36
-			add_action( 'wc_pre_orders_process_pre_order_completion_payment_' . $this->id, array( $this, 'process_pre_order_release_payment' ) );
35
+		if (class_exists('WC_Pre_Orders_Order')) {
36
+			add_action('wc_pre_orders_process_pre_order_completion_payment_' . $this->id, array($this, 'process_pre_order_release_payment'));
37 37
 		}
38 38
 
39
-		$this->wc_pre_30 = version_compare( WC_VERSION, '3.0.0', '<' );
39
+		$this->wc_pre_30 = version_compare(WC_VERSION, '3.0.0', '<');
40 40
 	}
41 41
 
42 42
 	/**
@@ -44,8 +44,8 @@  discard block
 block discarded – undo
44 44
 	 * @param  int  $order_id
45 45
 	 * @return boolean
46 46
 	 */
47
-	protected function is_subscription( $order_id ) {
48
-		return ( function_exists( 'wcs_order_contains_subscription' ) && ( wcs_order_contains_subscription( $order_id ) || wcs_is_subscription( $order_id ) || wcs_order_contains_renewal( $order_id ) ) );
47
+	protected function is_subscription($order_id) {
48
+		return (function_exists('wcs_order_contains_subscription') && (wcs_order_contains_subscription($order_id) || wcs_is_subscription($order_id) || wcs_order_contains_renewal($order_id)));
49 49
 	}
50 50
 
51 51
 	/**
@@ -53,8 +53,8 @@  discard block
 block discarded – undo
53 53
 	 * @param  int  $order_id
54 54
 	 * @return boolean
55 55
 	 */
56
-	protected function is_pre_order( $order_id ) {
57
-		return ( class_exists( 'WC_Pre_Orders_Order' ) && WC_Pre_Orders_Order::order_contains_pre_order( $order_id ) );
56
+	protected function is_pre_order($order_id) {
57
+		return (class_exists('WC_Pre_Orders_Order') && WC_Pre_Orders_Order::order_contains_pre_order($order_id));
58 58
 	}
59 59
 
60 60
 	/**
@@ -62,40 +62,40 @@  discard block
 block discarded – undo
62 62
 	 * @param  int $order_id
63 63
 	 * @return array
64 64
 	 */
65
-	public function process_payment( $order_id, $retry = true, $force_customer = false ) {
66
-		if ( $this->is_subscription( $order_id ) ) {
65
+	public function process_payment($order_id, $retry = true, $force_customer = false) {
66
+		if ($this->is_subscription($order_id)) {
67 67
 			// Regular payment with force customer enabled
68
-			return parent::process_payment( $order_id, true, true );
68
+			return parent::process_payment($order_id, true, true);
69 69
 
70
-		} elseif ( $this->is_pre_order( $order_id ) ) {
71
-			return $this->process_pre_order( $order_id, $retry, $force_customer );
70
+		} elseif ($this->is_pre_order($order_id)) {
71
+			return $this->process_pre_order($order_id, $retry, $force_customer);
72 72
 
73 73
 		} else {
74
-			return parent::process_payment( $order_id, $retry, $force_customer );
74
+			return parent::process_payment($order_id, $retry, $force_customer);
75 75
 		}
76 76
 	}
77 77
 
78 78
 	/**
79 79
 	 * Updates other subscription sources.
80 80
 	 */
81
-	protected function save_source( $order, $source ) {
82
-		parent::save_source( $order, $source );
81
+	protected function save_source($order, $source) {
82
+		parent::save_source($order, $source);
83 83
 
84
-		$order_id  = $this->wc_pre_30 ? $order->id : $order->get_id();
84
+		$order_id = $this->wc_pre_30 ? $order->id : $order->get_id();
85 85
 
86 86
 		// Also store it on the subscriptions being purchased or paid for in the order
87
-		if ( function_exists( 'wcs_order_contains_subscription' ) && wcs_order_contains_subscription( $order_id ) ) {
88
-			$subscriptions = wcs_get_subscriptions_for_order( $order_id );
89
-		} elseif ( function_exists( 'wcs_order_contains_renewal' ) && wcs_order_contains_renewal( $order_id ) ) {
90
-			$subscriptions = wcs_get_subscriptions_for_renewal_order( $order_id );
87
+		if (function_exists('wcs_order_contains_subscription') && wcs_order_contains_subscription($order_id)) {
88
+			$subscriptions = wcs_get_subscriptions_for_order($order_id);
89
+		} elseif (function_exists('wcs_order_contains_renewal') && wcs_order_contains_renewal($order_id)) {
90
+			$subscriptions = wcs_get_subscriptions_for_renewal_order($order_id);
91 91
 		} else {
92 92
 			$subscriptions = array();
93 93
 		}
94 94
 
95
-		foreach ( $subscriptions as $subscription ) {
95
+		foreach ($subscriptions as $subscription) {
96 96
 			$subscription_id = $this->wc_pre_30 ? $subscription->id : $subscription->get_id();
97
-			update_post_meta( $subscription_id, '_stripe_customer_id', $source->customer );
98
-			update_post_meta( $subscription_id, '_stripe_card_id', $source->source );
97
+			update_post_meta($subscription_id, '_stripe_customer_id', $source->customer);
98
+			update_post_meta($subscription_id, '_stripe_card_id', $source->source);
99 99
 		}
100 100
 	}
101 101
 
@@ -106,55 +106,55 @@  discard block
 block discarded – undo
106 106
 	 * @param string $stripe_token (default: '')
107 107
 	 * @param  bool initial_payment
108 108
 	 */
109
-	public function process_subscription_payment( $order = '', $amount = 0 ) {
110
-		if ( $amount * 100 < WC_Stripe_Helper::get_minimum_amount() ) {
111
-			return new WP_Error( 'stripe_error', sprintf( __( 'Sorry, the minimum allowed order total is %1$s to use this payment method.', 'woocommerce-gateway-stripe' ), wc_price( WC_Stripe_Helper::get_minimum_amount() / 100 ) ) );
109
+	public function process_subscription_payment($order = '', $amount = 0) {
110
+		if ($amount * 100 < WC_Stripe_Helper::get_minimum_amount()) {
111
+			return new WP_Error('stripe_error', sprintf(__('Sorry, the minimum allowed order total is %1$s to use this payment method.', 'woocommerce-gateway-stripe'), wc_price(WC_Stripe_Helper::get_minimum_amount() / 100)));
112 112
 		}
113 113
 
114 114
 		// Get source from order
115
-		$source = $this->get_order_source( $order );
115
+		$source = $this->get_order_source($order);
116 116
 
117 117
 		// If no order source was defined, use user source instead.
118
-		if ( ! $source->customer ) {
119
-			$source = $this->get_source( ( $this->wc_pre_30 ? $order->customer_user : $order->get_customer_id() ) );
118
+		if ( ! $source->customer) {
119
+			$source = $this->get_source(($this->wc_pre_30 ? $order->customer_user : $order->get_customer_id()));
120 120
 		}
121 121
 
122 122
 		// Or fail :(
123
-		if ( ! $source->customer ) {
124
-			return new WP_Error( 'stripe_error', __( 'Customer not found', 'woocommerce-gateway-stripe' ) );
123
+		if ( ! $source->customer) {
124
+			return new WP_Error('stripe_error', __('Customer not found', 'woocommerce-gateway-stripe'));
125 125
 		}
126 126
 
127 127
 		$order_id = $this->wc_pre_30 ? $order->id : $order->get_id();
128
-		WC_Stripe_Logger::log( "Info: Begin processing subscription payment for order {$order_id} for the amount of {$amount}" );
128
+		WC_Stripe_Logger::log("Info: Begin processing subscription payment for order {$order_id} for the amount of {$amount}");
129 129
 
130 130
 		// Make the request
131
-		$request             = $this->generate_payment_request( $order, $source );
131
+		$request             = $this->generate_payment_request($order, $source);
132 132
 		$request['capture']  = 'true';
133
-		$request['amount']   = WC_Stripe_Helper::get_stripe_amount( $amount, $request['currency'] );
133
+		$request['amount']   = WC_Stripe_Helper::get_stripe_amount($amount, $request['currency']);
134 134
 		$request['metadata'] = array(
135 135
 			'payment_type'   => 'recurring',
136
-			'site_url'       => esc_url( get_site_url() ),
136
+			'site_url'       => esc_url(get_site_url()),
137 137
 		);
138
-		$response            = WC_Stripe_API::request( $request );
138
+		$response = WC_Stripe_API::request($request);
139 139
 
140 140
 		// Process valid response
141
-		if ( is_wp_error( $response ) ) {
142
-			if ( 'missing' === $response->get_error_code() ) {
141
+		if (is_wp_error($response)) {
142
+			if ('missing' === $response->get_error_code()) {
143 143
 				// If we can't link customer to a card, we try to charge by customer ID.
144
-				$request             = $this->generate_payment_request( $order, $this->get_source( ( $this->wc_pre_30 ? $order->customer_user : $order->get_customer_id() ) ) );
144
+				$request             = $this->generate_payment_request($order, $this->get_source(($this->wc_pre_30 ? $order->customer_user : $order->get_customer_id())));
145 145
 				$request['capture']  = 'true';
146
-				$request['amount']   = WC_Stripe_Helper::get_stripe_amount( $amount, $request['currency'] );
146
+				$request['amount']   = WC_Stripe_Helper::get_stripe_amount($amount, $request['currency']);
147 147
 				$request['metadata'] = array(
148 148
 					'payment_type'   => 'recurring',
149
-					'site_url'       => esc_url( get_site_url() ),
149
+					'site_url'       => esc_url(get_site_url()),
150 150
 				);
151
-				$response          = WC_Stripe_API::request( $request );
151
+				$response = WC_Stripe_API::request($request);
152 152
 			} else {
153 153
 				return $response; // Default catch all errors.
154 154
 			}
155 155
 		}
156 156
 
157
-		$this->process_response( $response, $order );
157
+		$this->process_response($response, $order);
158 158
 
159 159
 		return $response;
160 160
 	}
@@ -164,42 +164,42 @@  discard block
 block discarded – undo
164 164
 	 * @param int $order_id
165 165
 	 * @return array
166 166
 	 */
167
-	public function process_pre_order( $order_id, $retry, $force_customer ) {
168
-		if ( WC_Pre_Orders_Order::order_requires_payment_tokenization( $order_id ) ) {
167
+	public function process_pre_order($order_id, $retry, $force_customer) {
168
+		if (WC_Pre_Orders_Order::order_requires_payment_tokenization($order_id)) {
169 169
 			try {
170
-				$order = wc_get_order( $order_id );
170
+				$order = wc_get_order($order_id);
171 171
 
172
-				if ( $order->get_total() * 100 < WC_Stripe_Helper::get_minimum_amount() ) {
173
-					throw new Exception( sprintf( __( 'Sorry, the minimum allowed order total is %1$s to use this payment method.', 'woocommerce-gateway-stripe' ), wc_price( WC_Stripe_Helper::get_minimum_amount() / 100 ) ) );
172
+				if ($order->get_total() * 100 < WC_Stripe_Helper::get_minimum_amount()) {
173
+					throw new Exception(sprintf(__('Sorry, the minimum allowed order total is %1$s to use this payment method.', 'woocommerce-gateway-stripe'), wc_price(WC_Stripe_Helper::get_minimum_amount() / 100)));
174 174
 				}
175 175
 
176
-				$source = $this->get_source( get_current_user_id(), true );
176
+				$source = $this->get_source(get_current_user_id(), true);
177 177
 
178 178
 				// We need a source on file to continue.
179
-				if ( empty( $source->customer ) || empty( $source->source ) ) {
180
-					throw new Exception( __( 'Unable to store payment details. Please try again.', 'woocommerce-gateway-stripe' ) );
179
+				if (empty($source->customer) || empty($source->source)) {
180
+					throw new Exception(__('Unable to store payment details. Please try again.', 'woocommerce-gateway-stripe'));
181 181
 				}
182 182
 
183 183
 				// Store source to order meta
184
-				$this->save_source( $order, $source );
184
+				$this->save_source($order, $source);
185 185
 
186 186
 				// Remove cart
187 187
 				WC()->cart->empty_cart();
188 188
 
189 189
 				// Is pre ordered!
190
-				WC_Pre_Orders_Order::mark_order_as_pre_ordered( $order );
190
+				WC_Pre_Orders_Order::mark_order_as_pre_ordered($order);
191 191
 
192 192
 				// Return thank you page redirect
193 193
 				return array(
194 194
 					'result'   => 'success',
195
-					'redirect' => $this->get_return_url( $order ),
195
+					'redirect' => $this->get_return_url($order),
196 196
 				);
197
-			} catch ( Exception $e ) {
198
-				wc_add_notice( $e->getMessage(), 'error' );
197
+			} catch (Exception $e) {
198
+				wc_add_notice($e->getMessage(), 'error');
199 199
 				return;
200 200
 			}
201 201
 		} else {
202
-			return parent::process_payment( $order_id, $retry, $force_customer );
202
+			return parent::process_payment($order_id, $retry, $force_customer);
203 203
 		}
204 204
 	}
205 205
 
@@ -208,7 +208,7 @@  discard block
 block discarded – undo
208 208
 	 * @param WC_Order $order
209 209
 	 * @return void
210 210
 	 */
211
-	public function process_pre_order_release_payment( $order ) {
211
+	public function process_pre_order_release_payment($order) {
212 212
 		try {
213 213
 			// Define some callbacks if the first attempt fails.
214 214
 			$retry_callbacks = array(
@@ -216,32 +216,32 @@  discard block
 block discarded – undo
216 216
 				'remove_order_customer_before_retry',
217 217
 			);
218 218
 
219
-			while ( 1 ) {
220
-				$source   = $this->get_order_source( $order );
221
-				$response = WC_Stripe_API::request( $this->generate_payment_request( $order, $source ) );
219
+			while (1) {
220
+				$source   = $this->get_order_source($order);
221
+				$response = WC_Stripe_API::request($this->generate_payment_request($order, $source));
222 222
 
223
-				if ( is_wp_error( $response ) ) {
224
-					if ( 0 === sizeof( $retry_callbacks ) ) {
225
-						throw new Exception( $response->get_error_message() );
223
+				if (is_wp_error($response)) {
224
+					if (0 === sizeof($retry_callbacks)) {
225
+						throw new Exception($response->get_error_message());
226 226
 					} else {
227
-						$retry_callback = array_shift( $retry_callbacks );
228
-						call_user_func( array( $this, $retry_callback ), $order );
227
+						$retry_callback = array_shift($retry_callbacks);
228
+						call_user_func(array($this, $retry_callback), $order);
229 229
 					}
230 230
 				} else {
231 231
 					// Successful
232
-					$this->process_response( $response, $order );
232
+					$this->process_response($response, $order);
233 233
 					break;
234 234
 				}
235 235
 			}
236
-		} catch ( Exception $e ) {
237
-			$order_note = sprintf( __( 'Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe' ), $e->getMessage() );
236
+		} catch (Exception $e) {
237
+			$order_note = sprintf(__('Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe'), $e->getMessage());
238 238
 
239 239
 			// Mark order as failed if not already set,
240 240
 			// otherwise, make sure we add the order note so we can detect when someone fails to check out multiple times
241
-			if ( ! $order->has_status( 'failed' ) ) {
242
-				$order->update_status( 'failed', $order_note );
241
+			if ( ! $order->has_status('failed')) {
242
+				$order->update_status('failed', $order_note);
243 243
 			} else {
244
-				$order->add_order_note( $order_note );
244
+				$order->add_order_note($order_note);
245 245
 			}
246 246
 		}
247 247
 	}
@@ -250,20 +250,20 @@  discard block
 block discarded – undo
250 250
 	 * Don't transfer Stripe customer/token meta to resubscribe orders.
251 251
 	 * @param int $resubscribe_order The order created for the customer to resubscribe to the old expired/cancelled subscription
252 252
 	 */
253
-	public function delete_resubscribe_meta( $resubscribe_order ) {
254
-		delete_post_meta( ( $this->wc_pre_30 ? $resubscribe_order->id : $resubscribe_order->get_id() ), '_stripe_customer_id' );
255
-		delete_post_meta( ( $this->wc_pre_30 ? $resubscribe_order->id : $resubscribe_order->get_id() ), '_stripe_card_id' );
256
-		$this->delete_renewal_meta( $resubscribe_order );
253
+	public function delete_resubscribe_meta($resubscribe_order) {
254
+		delete_post_meta(($this->wc_pre_30 ? $resubscribe_order->id : $resubscribe_order->get_id()), '_stripe_customer_id');
255
+		delete_post_meta(($this->wc_pre_30 ? $resubscribe_order->id : $resubscribe_order->get_id()), '_stripe_card_id');
256
+		$this->delete_renewal_meta($resubscribe_order);
257 257
 	}
258 258
 
259 259
 	/**
260 260
 	 * Don't transfer Stripe fee/ID meta to renewal orders.
261 261
 	 * @param int $resubscribe_order The order created for the customer to resubscribe to the old expired/cancelled subscription
262 262
 	 */
263
-	public function delete_renewal_meta( $renewal_order ) {
264
-		delete_post_meta( ( $this->wc_pre_30 ? $renewal_order->id : $renewal_order->get_id() ), 'Stripe Fee' );
265
-		delete_post_meta( ( $this->wc_pre_30 ? $renewal_order->id : $renewal_order->get_id() ), 'Net Revenue From Stripe' );
266
-		delete_post_meta( ( $this->wc_pre_30 ? $renewal_order->id : $renewal_order->get_id() ), 'Stripe Payment ID' );
263
+	public function delete_renewal_meta($renewal_order) {
264
+		delete_post_meta(($this->wc_pre_30 ? $renewal_order->id : $renewal_order->get_id()), 'Stripe Fee');
265
+		delete_post_meta(($this->wc_pre_30 ? $renewal_order->id : $renewal_order->get_id()), 'Net Revenue From Stripe');
266
+		delete_post_meta(($this->wc_pre_30 ? $renewal_order->id : $renewal_order->get_id()), 'Stripe Payment ID');
267 267
 		return $renewal_order;
268 268
 	}
269 269
 
@@ -273,11 +273,11 @@  discard block
 block discarded – undo
273 273
 	 * @param $amount_to_charge float The amount to charge.
274 274
 	 * @param $renewal_order WC_Order A WC_Order object created to record the renewal payment.
275 275
 	 */
276
-	public function scheduled_subscription_payment( $amount_to_charge, $renewal_order ) {
277
-		$response = $this->process_subscription_payment( $renewal_order, $amount_to_charge );
276
+	public function scheduled_subscription_payment($amount_to_charge, $renewal_order) {
277
+		$response = $this->process_subscription_payment($renewal_order, $amount_to_charge);
278 278
 
279
-		if ( is_wp_error( $response ) ) {
280
-			$renewal_order->update_status( 'failed', sprintf( __( 'Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe' ), $response->get_error_message() ) );
279
+		if (is_wp_error($response)) {
280
+			$renewal_order->update_status('failed', sprintf(__('Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe'), $response->get_error_message()));
281 281
 		}
282 282
 	}
283 283
 
@@ -285,18 +285,18 @@  discard block
 block discarded – undo
285 285
 	 * Remove order meta
286 286
 	 * @param  object $order
287 287
 	 */
288
-	public function remove_order_source_before_retry( $order ) {
288
+	public function remove_order_source_before_retry($order) {
289 289
 		$order_id = $this->wc_pre_30 ? $order->id : $order->get_id();
290
-		delete_post_meta( $order_id, '_stripe_card_id' );
290
+		delete_post_meta($order_id, '_stripe_card_id');
291 291
 	}
292 292
 
293 293
 	/**
294 294
 	 * Remove order meta
295 295
 	 * @param  object $order
296 296
 	 */
297
-	public function remove_order_customer_before_retry( $order ) {
297
+	public function remove_order_customer_before_retry($order) {
298 298
 		$order_id = $this->wc_pre_30 ? $order->id : $order->get_id();
299
-		delete_post_meta( $order_id, '_stripe_customer_id' );
299
+		delete_post_meta($order_id, '_stripe_customer_id');
300 300
 	}
301 301
 
302 302
 	/**
@@ -308,13 +308,13 @@  discard block
 block discarded – undo
308 308
 	 * @param WC_Order $renewal_order The order which recorded the successful payment (to make up for the failed automatic payment).
309 309
 	 * @return void
310 310
 	 */
311
-	public function update_failing_payment_method( $subscription, $renewal_order ) {
312
-		if ( $this->wc_pre_30 ) {
313
-			update_post_meta( $subscription->id, '_stripe_customer_id', $renewal_order->stripe_customer_id );
314
-			update_post_meta( $subscription->id, '_stripe_card_id', $renewal_order->stripe_card_id );
311
+	public function update_failing_payment_method($subscription, $renewal_order) {
312
+		if ($this->wc_pre_30) {
313
+			update_post_meta($subscription->id, '_stripe_customer_id', $renewal_order->stripe_customer_id);
314
+			update_post_meta($subscription->id, '_stripe_card_id', $renewal_order->stripe_card_id);
315 315
 		} else {
316
-			$subscription->update_meta_data( '_stripe_customer_id', $renewal_order->get_meta( '_stripe_customer_id', true ) );
317
-			$subscription->update_meta_data( '_stripe_card_id', $renewal_order->get_meta( '_stripe_card_id', true ) );
316
+			$subscription->update_meta_data('_stripe_customer_id', $renewal_order->get_meta('_stripe_customer_id', true));
317
+			$subscription->update_meta_data('_stripe_card_id', $renewal_order->get_meta('_stripe_card_id', true));
318 318
 		}
319 319
 	}
320 320
 
@@ -327,15 +327,15 @@  discard block
 block discarded – undo
327 327
 	 * @param WC_Subscription $subscription An instance of a subscription object
328 328
 	 * @return array
329 329
 	 */
330
-	public function add_subscription_payment_meta( $payment_meta, $subscription ) {
331
-		$payment_meta[ $this->id ] = array(
330
+	public function add_subscription_payment_meta($payment_meta, $subscription) {
331
+		$payment_meta[$this->id] = array(
332 332
 			'post_meta' => array(
333 333
 				'_stripe_customer_id' => array(
334
-					'value' => get_post_meta( ( $this->wc_pre_30 ? $subscription->id : $subscription->get_id() ), '_stripe_customer_id', true ),
334
+					'value' => get_post_meta(($this->wc_pre_30 ? $subscription->id : $subscription->get_id()), '_stripe_customer_id', true),
335 335
 					'label' => 'Stripe Customer ID',
336 336
 				),
337 337
 				'_stripe_card_id' => array(
338
-					'value' => get_post_meta( ( $this->wc_pre_30 ? $subscription->id : $subscription->get_id() ), '_stripe_card_id', true ),
338
+					'value' => get_post_meta(($this->wc_pre_30 ? $subscription->id : $subscription->get_id()), '_stripe_card_id', true),
339 339
 					'label' => 'Stripe Card ID',
340 340
 				),
341 341
 			),
@@ -352,17 +352,17 @@  discard block
 block discarded – undo
352 352
 	 * @param array $payment_meta associative array of meta data required for automatic payments
353 353
 	 * @return array
354 354
 	 */
355
-	public function validate_subscription_payment_meta( $payment_method_id, $payment_meta ) {
356
-		if ( $this->id === $payment_method_id ) {
355
+	public function validate_subscription_payment_meta($payment_method_id, $payment_meta) {
356
+		if ($this->id === $payment_method_id) {
357 357
 
358
-			if ( ! isset( $payment_meta['post_meta']['_stripe_customer_id']['value'] ) || empty( $payment_meta['post_meta']['_stripe_customer_id']['value'] ) ) {
359
-				throw new Exception( 'A "_stripe_customer_id" value is required.' );
360
-			} elseif ( 0 !== strpos( $payment_meta['post_meta']['_stripe_customer_id']['value'], 'cus_' ) ) {
361
-				throw new Exception( 'Invalid customer ID. A valid "_stripe_customer_id" must begin with "cus_".' );
358
+			if ( ! isset($payment_meta['post_meta']['_stripe_customer_id']['value']) || empty($payment_meta['post_meta']['_stripe_customer_id']['value'])) {
359
+				throw new Exception('A "_stripe_customer_id" value is required.');
360
+			} elseif (0 !== strpos($payment_meta['post_meta']['_stripe_customer_id']['value'], 'cus_')) {
361
+				throw new Exception('Invalid customer ID. A valid "_stripe_customer_id" must begin with "cus_".');
362 362
 			}
363 363
 
364
-			if ( ! empty( $payment_meta['post_meta']['_stripe_card_id']['value'] ) && 0 !== strpos( $payment_meta['post_meta']['_stripe_card_id']['value'], 'card_' ) ) {
365
-				throw new Exception( 'Invalid card ID. A valid "_stripe_card_id" must begin with "card_".' );
364
+			if ( ! empty($payment_meta['post_meta']['_stripe_card_id']['value']) && 0 !== strpos($payment_meta['post_meta']['_stripe_card_id']['value'], 'card_')) {
365
+				throw new Exception('Invalid card ID. A valid "_stripe_card_id" must begin with "card_".');
366 366
 			}
367 367
 		}
368 368
 	}
@@ -375,45 +375,45 @@  discard block
 block discarded – undo
375 375
 	 * @param WC_Subscription $subscription the subscription details
376 376
 	 * @return string the subscription payment method
377 377
 	 */
378
-	public function maybe_render_subscription_payment_method( $payment_method_to_display, $subscription ) {
378
+	public function maybe_render_subscription_payment_method($payment_method_to_display, $subscription) {
379 379
 		$customer_user = $this->wc_pre_30 ? $subscription->customer_user : $subscription->get_customer_id();
380 380
 
381 381
 		// bail for other payment methods
382
-		if ( $this->id !== ( $this->wc_pre_30 ? $subscription->payment_method : $subscription->get_payment_method() ) || ! $customer_user ) {
382
+		if ($this->id !== ($this->wc_pre_30 ? $subscription->payment_method : $subscription->get_payment_method()) || ! $customer_user) {
383 383
 			return $payment_method_to_display;
384 384
 		}
385 385
 
386 386
 		$stripe_customer    = new WC_Stripe_Customer();
387
-		$stripe_customer_id = get_post_meta( ( $this->wc_pre_30 ? $subscription->id : $subscription->get_id() ), '_stripe_customer_id', true );
388
-		$stripe_card_id     = get_post_meta( ( $this->wc_pre_30 ? $subscription->id : $subscription->get_id() ), '_stripe_card_id', true );
387
+		$stripe_customer_id = get_post_meta(($this->wc_pre_30 ? $subscription->id : $subscription->get_id()), '_stripe_customer_id', true);
388
+		$stripe_card_id     = get_post_meta(($this->wc_pre_30 ? $subscription->id : $subscription->get_id()), '_stripe_card_id', true);
389 389
 
390 390
 		// If we couldn't find a Stripe customer linked to the subscription, fallback to the user meta data.
391
-		if ( ! $stripe_customer_id || ! is_string( $stripe_customer_id ) ) {
391
+		if ( ! $stripe_customer_id || ! is_string($stripe_customer_id)) {
392 392
 			$user_id            = $customer_user;
393
-			$stripe_customer_id = get_user_meta( $user_id, '_stripe_customer_id', true );
394
-			$stripe_card_id     = get_user_meta( $user_id, '_stripe_card_id', true );
393
+			$stripe_customer_id = get_user_meta($user_id, '_stripe_customer_id', true);
394
+			$stripe_card_id     = get_user_meta($user_id, '_stripe_card_id', true);
395 395
 		}
396 396
 
397 397
 		// If we couldn't find a Stripe customer linked to the account, fallback to the order meta data.
398
-		if ( ( ! $stripe_customer_id || ! is_string( $stripe_customer_id ) ) && false !== $subscription->order ) {
399
-			$stripe_customer_id = get_post_meta( ( $this->wc_pre_30 ? $subscription->order->id : $subscription->get_parent_id() ), '_stripe_customer_id', true );
400
-			$stripe_card_id     = get_post_meta( ( $this->wc_pre_30 ? $subscription->order->id : $subscription->get_parent_id() ), '_stripe_card_id', true );
398
+		if (( ! $stripe_customer_id || ! is_string($stripe_customer_id)) && false !== $subscription->order) {
399
+			$stripe_customer_id = get_post_meta(($this->wc_pre_30 ? $subscription->order->id : $subscription->get_parent_id()), '_stripe_customer_id', true);
400
+			$stripe_card_id     = get_post_meta(($this->wc_pre_30 ? $subscription->order->id : $subscription->get_parent_id()), '_stripe_card_id', true);
401 401
 		}
402 402
 
403
-		$stripe_customer->set_id( $stripe_customer_id );
403
+		$stripe_customer->set_id($stripe_customer_id);
404 404
 		$cards = $stripe_customer->get_sources();
405 405
 
406
-		if ( $cards ) {
406
+		if ($cards) {
407 407
 			$found_card = false;
408
-			foreach ( $cards as $card ) {
409
-				if ( $card->id === $stripe_card_id ) {
408
+			foreach ($cards as $card) {
409
+				if ($card->id === $stripe_card_id) {
410 410
 					$found_card                = true;
411
-					$payment_method_to_display = sprintf( __( 'Via %1$s card ending in %2$s', 'woocommerce-gateway-stripe' ), ( isset( $card->type ) ? $card->type : $card->brand ), $card->last4 );
411
+					$payment_method_to_display = sprintf(__('Via %1$s card ending in %2$s', 'woocommerce-gateway-stripe'), (isset($card->type) ? $card->type : $card->brand), $card->last4);
412 412
 					break;
413 413
 				}
414 414
 			}
415
-			if ( ! $found_card ) {
416
-				$payment_method_to_display = sprintf( __( 'Via %1$s card ending in %2$s', 'woocommerce-gateway-stripe' ), ( isset( $cards[0]->type ) ? $cards[0]->type : $cards[0]->brand ), $cards[0]->last4 );
415
+			if ( ! $found_card) {
416
+				$payment_method_to_display = sprintf(__('Via %1$s card ending in %2$s', 'woocommerce-gateway-stripe'), (isset($cards[0]->type) ? $cards[0]->type : $cards[0]->brand), $cards[0]->last4);
417 417
 			}
418 418
 		}
419 419
 
Please login to merge, or discard this patch.
includes/class-wc-stripe-helper.php 1 patch
Spacing   +36 added lines, -36 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
 
@@ -17,11 +17,11 @@  discard block
 block discarded – undo
17 17
 	 *
18 18
 	 * @return float|int
19 19
 	 */
20
-	public static function get_stripe_amount( $total, $currency = '' ) {
21
-		if ( ! $currency ) {
20
+	public static function get_stripe_amount($total, $currency = '') {
21
+		if ( ! $currency) {
22 22
 			$currency = get_woocommerce_currency();
23 23
 		}
24
-		switch ( strtoupper( $currency ) ) {
24
+		switch (strtoupper($currency)) {
25 25
 			// Zero decimal currencies.
26 26
 			case 'BIF' :
27 27
 			case 'CLP' :
@@ -38,10 +38,10 @@  discard block
 block discarded – undo
38 38
 			case 'XAF' :
39 39
 			case 'XOF' :
40 40
 			case 'XPF' :
41
-				$total = absint( $total );
41
+				$total = absint($total);
42 42
 				break;
43 43
 			default :
44
-				$total = round( $total, 2 ) * 100; // In cents.
44
+				$total = round($total, 2) * 100; // In cents.
45 45
 				break;
46 46
 		}
47 47
 		return $total;
@@ -55,20 +55,20 @@  discard block
 block discarded – undo
55 55
 	 * @return array
56 56
 	 */
57 57
 	public static function get_localized_messages() {
58
-		return apply_filters( 'wc_stripe_localized_messages', array(
59
-			'invalid_number'        => __( 'The card number is not a valid credit card number.', 'woocommerce-gateway-stripe' ),
60
-			'invalid_expiry_month'  => __( 'The card\'s expiration month is invalid.', 'woocommerce-gateway-stripe' ),
61
-			'invalid_expiry_year'   => __( 'The card\'s expiration year is invalid.', 'woocommerce-gateway-stripe' ),
62
-			'invalid_cvc'           => __( 'The card\'s security code is invalid.', 'woocommerce-gateway-stripe' ),
63
-			'incorrect_number'      => __( 'The card number is incorrect.', 'woocommerce-gateway-stripe' ),
64
-			'expired_card'          => __( 'The card has expired.', 'woocommerce-gateway-stripe' ),
65
-			'incorrect_cvc'         => __( 'The card\'s security code is incorrect.', 'woocommerce-gateway-stripe' ),
66
-			'incorrect_zip'         => __( 'The card\'s zip code failed validation.', 'woocommerce-gateway-stripe' ),
67
-			'card_declined'         => __( 'The card was declined.', 'woocommerce-gateway-stripe' ),
68
-			'missing'               => __( 'There is no card on a customer that is being charged.', 'woocommerce-gateway-stripe' ),
69
-			'processing_error'      => __( 'An error occurred while processing the card.', 'woocommerce-gateway-stripe' ),
70
-			'invalid_request_error' => __( 'Could not find payment information.', 'woocommerce-gateway-stripe' ),
71
-		) );
58
+		return apply_filters('wc_stripe_localized_messages', array(
59
+			'invalid_number'        => __('The card number is not a valid credit card number.', 'woocommerce-gateway-stripe'),
60
+			'invalid_expiry_month'  => __('The card\'s expiration month is invalid.', 'woocommerce-gateway-stripe'),
61
+			'invalid_expiry_year'   => __('The card\'s expiration year is invalid.', 'woocommerce-gateway-stripe'),
62
+			'invalid_cvc'           => __('The card\'s security code is invalid.', 'woocommerce-gateway-stripe'),
63
+			'incorrect_number'      => __('The card number is incorrect.', 'woocommerce-gateway-stripe'),
64
+			'expired_card'          => __('The card has expired.', 'woocommerce-gateway-stripe'),
65
+			'incorrect_cvc'         => __('The card\'s security code is incorrect.', 'woocommerce-gateway-stripe'),
66
+			'incorrect_zip'         => __('The card\'s zip code failed validation.', 'woocommerce-gateway-stripe'),
67
+			'card_declined'         => __('The card was declined.', 'woocommerce-gateway-stripe'),
68
+			'missing'               => __('There is no card on a customer that is being charged.', 'woocommerce-gateway-stripe'),
69
+			'processing_error'      => __('An error occurred while processing the card.', 'woocommerce-gateway-stripe'),
70
+			'invalid_request_error' => __('Could not find payment information.', 'woocommerce-gateway-stripe'),
71
+		));
72 72
 	}
73 73
 
74 74
 	/**
@@ -103,24 +103,24 @@  discard block
 block discarded – undo
103 103
 	 * @param object $balance_transaction
104 104
 	 * @param string $type Type of number to format
105 105
 	 */
106
-	public static function format_number( $balance_transaction, $type = 'fee' ) {
107
-		if ( ! is_object( $balance_transaction ) ) {
106
+	public static function format_number($balance_transaction, $type = 'fee') {
107
+		if ( ! is_object($balance_transaction)) {
108 108
 			return;
109 109
 		}
110 110
 
111
-		if ( in_array( strtolower( $balance_transaction->currency ), self::no_decimal_currencies() ) ) {
112
-			if ( 'fee' === $type ) {
111
+		if (in_array(strtolower($balance_transaction->currency), self::no_decimal_currencies())) {
112
+			if ('fee' === $type) {
113 113
 				return $balance_transaction->fee;
114 114
 			}
115 115
 
116 116
 			return $balance_transaction->net;
117 117
 		}
118 118
 
119
-		if ( 'fee' === $type ) {
120
-			return number_format( $balance_transaction->fee / 100, 2, '.', '' );
119
+		if ('fee' === $type) {
120
+			return number_format($balance_transaction->fee / 100, 2, '.', '');
121 121
 		}
122 122
 
123
-		return number_format( $balance_transaction->net / 100, 2, '.', '' );
123
+		return number_format($balance_transaction->net / 100, 2, '.', '');
124 124
 	}
125 125
 
126 126
 	/**
@@ -128,7 +128,7 @@  discard block
 block discarded – undo
128 128
 	 */
129 129
 	public static function get_minimum_amount() {
130 130
 		// Check order amount
131
-		switch ( get_woocommerce_currency() ) {
131
+		switch (get_woocommerce_currency()) {
132 132
 			case 'USD':
133 133
 			case 'CAD':
134 134
 			case 'EUR':
@@ -173,14 +173,14 @@  discard block
 block discarded – undo
173 173
 	 * @param string $method The payment method to get the settings from.
174 174
 	 * @param string $setting The name of the setting to get.
175 175
 	 */
176
-	public static function get_settings( $method = null, $setting = null ) {
177
-		$all_settings = null === $method ? get_option( 'woocommerce_stripe_settings', array() ) : get_option( 'woocommerce_stripe_' . $method . '_settings', array() );
176
+	public static function get_settings($method = null, $setting = null) {
177
+		$all_settings = null === $method ? get_option('woocommerce_stripe_settings', array()) : get_option('woocommerce_stripe_' . $method . '_settings', array());
178 178
 
179
-		if ( null === $setting ) {
179
+		if (null === $setting) {
180 180
 			return $all_settings;
181 181
 		}
182 182
 
183
-		return isset( $all_settings[ $setting ] ) ? $all_settings[ $setting ] : '';
183
+		return isset($all_settings[$setting]) ? $all_settings[$setting] : '';
184 184
 	}
185 185
 
186 186
 	/**
@@ -191,7 +191,7 @@  discard block
 block discarded – undo
191 191
 	 * @return bool
192 192
 	 */
193 193
 	public static function is_pre_30() {
194
-		return version_compare( WC_VERSION, '3.0.0', '<' );
194
+		return version_compare(WC_VERSION, '3.0.0', '<');
195 195
 	}
196 196
 
197 197
 	/**
@@ -204,7 +204,7 @@  discard block
 block discarded – undo
204 204
 	 * @return string
205 205
 	 */
206 206
 	public static function get_webhook_url() {
207
-		return add_query_arg( 'wc-api', 'wc_stripe', trailingslashit( get_home_url() ) );
207
+		return add_query_arg('wc-api', 'wc_stripe', trailingslashit(get_home_url()));
208 208
 	}
209 209
 
210 210
 	/**
@@ -214,9 +214,9 @@  discard block
 block discarded – undo
214 214
 	 * @version 4.0.0
215 215
 	 * @param string $source_id
216 216
 	 */
217
-	public static function get_order_by_source_id( $source_id ) {
217
+	public static function get_order_by_source_id($source_id) {
218 218
 		global $wpdb;
219 219
 
220
-		return $wpdb->get_var( $wpdb->prepare( "SELECT DISTINCT ID FROM $wpdb->posts as posts LEFT JOIN $wpdb->postmeta as meta ON posts.ID = meta.post_id WHERE meta.meta_value = %s", $source_id ) );
220
+		return $wpdb->get_var($wpdb->prepare("SELECT DISTINCT ID FROM $wpdb->posts as posts LEFT JOIN $wpdb->postmeta as meta ON posts.ID = meta.post_id WHERE meta.meta_value = %s", $source_id));
221 221
 	}
222 222
 }
Please login to merge, or discard this patch.
includes/class-wc-stripe-api.php 1 patch
Spacing   +27 added lines, -27 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
 
@@ -26,7 +26,7 @@  discard block
 block discarded – undo
26 26
 	 * Set secret API Key.
27 27
 	 * @param string $key
28 28
 	 */
29
-	public static function set_secret_key( $secret_key ) {
29
+	public static function set_secret_key($secret_key) {
30 30
 		self::$secret_key = $secret_key;
31 31
 	}
32 32
 
@@ -35,11 +35,11 @@  discard block
 block discarded – undo
35 35
 	 * @return string
36 36
 	 */
37 37
 	public static function get_secret_key() {
38
-		if ( ! self::$secret_key ) {
39
-			$options = get_option( 'woocommerce_stripe_settings' );
38
+		if ( ! self::$secret_key) {
39
+			$options = get_option('woocommerce_stripe_settings');
40 40
 
41
-			if ( isset( $options['testmode'], $options['secret_key'], $options['test_secret_key'] ) ) {
42
-				self::set_secret_key( 'yes' === $options['testmode'] ? $options['test_secret_key'] : $options['secret_key'] );
41
+			if (isset($options['testmode'], $options['secret_key'], $options['test_secret_key'])) {
42
+				self::set_secret_key('yes' === $options['testmode'] ? $options['test_secret_key'] : $options['secret_key']);
43 43
 			}
44 44
 		}
45 45
 		return self::$secret_key;
@@ -68,10 +68,10 @@  discard block
 block discarded – undo
68 68
 	 */
69 69
 	public static function get_headers() {
70 70
 		return array(
71
-			'Authorization'   => 'Basic ' . base64_encode( self::get_secret_key() . ':' ),
71
+			'Authorization'   => 'Basic ' . base64_encode(self::get_secret_key() . ':'),
72 72
 			'Stripe-Version'  => self::STRIPE_API_VERSION,
73 73
 			'Idempotency-Key' => uniqid(),
74
-			'X-Stripe-Client-User-Agent' => json_encode( self::get_user_agent() ),
74
+			'X-Stripe-Client-User-Agent' => json_encode(self::get_user_agent()),
75 75
 		);
76 76
 	}
77 77
 
@@ -82,35 +82,35 @@  discard block
 block discarded – undo
82 82
 	 * @param string $api
83 83
 	 * @return array|WP_Error
84 84
 	 */
85
-	public static function request( $request, $api = 'charges', $method = 'POST' ) {
86
-		WC_Stripe_Logger::log( "{$api} request: " . print_r( $request, true ) );
85
+	public static function request($request, $api = 'charges', $method = 'POST') {
86
+		WC_Stripe_Logger::log("{$api} request: " . print_r($request, true));
87 87
 
88 88
 		$response = wp_safe_remote_post(
89 89
 			self::ENDPOINT . $api,
90 90
 			array(
91 91
 				'method'        => $method,
92 92
 				'headers'       => self::get_headers(),
93
-				'body'       => apply_filters( 'woocommerce_stripe_request_body', $request, $api ),
93
+				'body'       => apply_filters('woocommerce_stripe_request_body', $request, $api),
94 94
 				'timeout'    => 70,
95 95
 				'user-agent' => 'WooCommerce ' . WC()->version,
96 96
 			)
97 97
 		);
98 98
 
99
-		if ( is_wp_error( $response ) || empty( $response['body'] ) ) {
100
-			WC_Stripe_Logger::log( 'Error Response: ' . print_r( $response, true ) );
101
-			return new WP_Error( 'stripe_error', __( 'There was a problem connecting to the Stripe API endpoint.', 'woocommerce-gateway-stripe' ) );
99
+		if (is_wp_error($response) || empty($response['body'])) {
100
+			WC_Stripe_Logger::log('Error Response: ' . print_r($response, true));
101
+			return new WP_Error('stripe_error', __('There was a problem connecting to the Stripe API endpoint.', 'woocommerce-gateway-stripe'));
102 102
 		}
103 103
 
104
-		$parsed_response = json_decode( $response['body'] );
104
+		$parsed_response = json_decode($response['body']);
105 105
 
106 106
 		// Handle response
107
-		if ( ! empty( $parsed_response->error ) ) {
108
-			if ( ! empty( $parsed_response->error->code ) ) {
107
+		if ( ! empty($parsed_response->error)) {
108
+			if ( ! empty($parsed_response->error->code)) {
109 109
 				$code = $parsed_response->error->code;
110 110
 			} else {
111 111
 				$code = 'stripe_error';
112 112
 			}
113
-			return new WP_Error( $code, $parsed_response->error->message );
113
+			return new WP_Error($code, $parsed_response->error->message);
114 114
 		} else {
115 115
 			return $parsed_response;
116 116
 		}
@@ -123,8 +123,8 @@  discard block
 block discarded – undo
123 123
 	 * @version 4.0.0
124 124
 	 * @param string $api
125 125
 	 */
126
-	public static function retrieve( $api ) {
127
-		WC_Stripe_Logger::log( "{$api} request: " . print_r( $request, true ) );
126
+	public static function retrieve($api) {
127
+		WC_Stripe_Logger::log("{$api} request: " . print_r($request, true));
128 128
 
129 129
 		$ua = self::get_user_agent();
130 130
 
@@ -138,21 +138,21 @@  discard block
 block discarded – undo
138 138
 			)
139 139
 		);
140 140
 
141
-		if ( is_wp_error( $response ) || empty( $response['body'] ) ) {
142
-			WC_Stripe_Logger::log( 'Error Response: ' . print_r( $response, true ) );
143
-			return new WP_Error( 'stripe_error', __( 'There was a problem connecting to the Stripe API endpoint.', 'woocommerce-gateway-stripe' ) );
141
+		if (is_wp_error($response) || empty($response['body'])) {
142
+			WC_Stripe_Logger::log('Error Response: ' . print_r($response, true));
143
+			return new WP_Error('stripe_error', __('There was a problem connecting to the Stripe API endpoint.', 'woocommerce-gateway-stripe'));
144 144
 		}
145 145
 
146
-		$parsed_response = json_decode( $response['body'] );
146
+		$parsed_response = json_decode($response['body']);
147 147
 
148 148
 		// Handle response
149
-		if ( ! empty( $parsed_response->error ) ) {
150
-			if ( ! empty( $parsed_response->error->code ) ) {
149
+		if ( ! empty($parsed_response->error)) {
150
+			if ( ! empty($parsed_response->error->code)) {
151 151
 				$code = $parsed_response->error->code;
152 152
 			} else {
153 153
 				$code = 'stripe_error';
154 154
 			}
155
-			return new WP_Error( $code, $parsed_response->error->message );
155
+			return new WP_Error($code, $parsed_response->error->message);
156 156
 		} else {
157 157
 			return $parsed_response;
158 158
 		}
Please login to merge, or discard this patch.
includes/class-wc-gateway-stripe.php 1 patch
Spacing   +213 added lines, -213 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
 
@@ -119,8 +119,8 @@  discard block
 block discarded – undo
119 119
 	 */
120 120
 	public function __construct() {
121 121
 		$this->id                   = 'stripe';
122
-		$this->method_title         = __( 'Stripe', 'woocommerce-gateway-stripe' );
123
-		$this->method_description   = sprintf( __( 'Stripe works by adding credit card fields on the checkout and then sending the details to Stripe for verification. <a href="%1$s" target="_blank">Sign up</a> for a Stripe account, and <a href="%2$s" target="_blank">get your Stripe account keys</a>.', 'woocommerce-gateway-stripe' ), 'https://dashboard.stripe.com/register', 'https://dashboard.stripe.com/account/apikeys' );
122
+		$this->method_title         = __('Stripe', 'woocommerce-gateway-stripe');
123
+		$this->method_description   = sprintf(__('Stripe works by adding credit card fields on the checkout and then sending the details to Stripe for verification. <a href="%1$s" target="_blank">Sign up</a> for a Stripe account, and <a href="%2$s" target="_blank">get your Stripe account keys</a>.', 'woocommerce-gateway-stripe'), 'https://dashboard.stripe.com/register', 'https://dashboard.stripe.com/account/apikeys');
124 124
 		$this->has_fields           = true;
125 125
 		$this->supports             = array(
126 126
 			'subscriptions',
@@ -147,43 +147,43 @@  discard block
 block discarded – undo
147 147
 		$this->init_settings();
148 148
 
149 149
 		// Get setting values.
150
-		$this->title                   = $this->get_option( 'title' );
151
-		$this->description             = $this->get_option( 'description' );
152
-		$this->enabled                 = $this->get_option( 'enabled' );
153
-		$this->testmode                = 'yes' === $this->get_option( 'testmode' );
154
-		$this->capture                 = 'yes' === $this->get_option( 'capture', 'yes' );
155
-		$this->statement_descriptor    = $this->get_option( 'statement_descriptor', wp_specialchars_decode( get_bloginfo( 'name' ), ENT_QUOTES ) );
156
-		$this->three_d_secure          = 'yes' === $this->get_option( 'three_d_secure' );
157
-		$this->stripe_checkout         = 'yes' === $this->get_option( 'stripe_checkout' );
158
-		$this->stripe_checkout_locale  = $this->get_option( 'stripe_checkout_locale' );
159
-		$this->stripe_checkout_image   = $this->get_option( 'stripe_checkout_image', '' );
160
-		$this->saved_cards             = 'yes' === $this->get_option( 'saved_cards' );
161
-		$this->secret_key              = $this->testmode ? $this->get_option( 'test_secret_key' ) : $this->get_option( 'secret_key' );
162
-		$this->publishable_key         = $this->testmode ? $this->get_option( 'test_publishable_key' ) : $this->get_option( 'publishable_key' );
163
-		$this->bitcoin                 = 'USD' === strtoupper( get_woocommerce_currency() ) && 'yes' === $this->get_option( 'stripe_bitcoin' );
164
-		$this->apple_pay               = 'yes' === $this->get_option( 'apple_pay', 'yes' );
165
-		$this->apple_pay_domain_set    = 'yes' === $this->get_option( 'apple_pay_domain_set', 'no' );
166
-		$this->apple_pay_button        = $this->get_option( 'apple_pay_button', 'black' );
150
+		$this->title                   = $this->get_option('title');
151
+		$this->description             = $this->get_option('description');
152
+		$this->enabled                 = $this->get_option('enabled');
153
+		$this->testmode                = 'yes' === $this->get_option('testmode');
154
+		$this->capture                 = 'yes' === $this->get_option('capture', 'yes');
155
+		$this->statement_descriptor    = $this->get_option('statement_descriptor', wp_specialchars_decode(get_bloginfo('name'), ENT_QUOTES));
156
+		$this->three_d_secure          = 'yes' === $this->get_option('three_d_secure');
157
+		$this->stripe_checkout         = 'yes' === $this->get_option('stripe_checkout');
158
+		$this->stripe_checkout_locale  = $this->get_option('stripe_checkout_locale');
159
+		$this->stripe_checkout_image   = $this->get_option('stripe_checkout_image', '');
160
+		$this->saved_cards             = 'yes' === $this->get_option('saved_cards');
161
+		$this->secret_key              = $this->testmode ? $this->get_option('test_secret_key') : $this->get_option('secret_key');
162
+		$this->publishable_key         = $this->testmode ? $this->get_option('test_publishable_key') : $this->get_option('publishable_key');
163
+		$this->bitcoin                 = 'USD' === strtoupper(get_woocommerce_currency()) && 'yes' === $this->get_option('stripe_bitcoin');
164
+		$this->apple_pay               = 'yes' === $this->get_option('apple_pay', 'yes');
165
+		$this->apple_pay_domain_set    = 'yes' === $this->get_option('apple_pay_domain_set', 'no');
166
+		$this->apple_pay_button        = $this->get_option('apple_pay_button', 'black');
167 167
 		$this->apple_pay_verify_notice = '';
168 168
 
169
-		if ( $this->stripe_checkout ) {
170
-			$this->order_button_text = __( 'Continue to payment', 'woocommerce-gateway-stripe' );
169
+		if ($this->stripe_checkout) {
170
+			$this->order_button_text = __('Continue to payment', 'woocommerce-gateway-stripe');
171 171
 		}
172 172
 
173
-		if ( $this->testmode ) {
174
-			$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' );
175
-			$this->description  = trim( $this->description );
173
+		if ($this->testmode) {
174
+			$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');
175
+			$this->description  = trim($this->description);
176 176
 		}
177 177
 
178
-		WC_Stripe_API::set_secret_key( $this->secret_key );
178
+		WC_Stripe_API::set_secret_key($this->secret_key);
179 179
 
180 180
 		$this->init_apple_pay();
181 181
 
182 182
 		// Hooks.
183
-		add_action( 'wp_enqueue_scripts', array( $this, 'payment_scripts' ) );
184
-		add_action( 'admin_enqueue_scripts', array( $this, 'admin_scripts' ) );
185
-		add_action( 'admin_notices', array( $this, 'admin_notices' ) );
186
-		add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) );
183
+		add_action('wp_enqueue_scripts', array($this, 'payment_scripts'));
184
+		add_action('admin_enqueue_scripts', array($this, 'admin_scripts'));
185
+		add_action('admin_notices', array($this, 'admin_notices'));
186
+		add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options'));
187 187
 	}
188 188
 
189 189
 	/**
@@ -194,7 +194,7 @@  discard block
 block discarded – undo
194 194
 	 * @return array
195 195
 	 */
196 196
 	public function payment_icons() {
197
-		return apply_filters( 'wc_stripe_payment_icons', array(
197
+		return apply_filters('wc_stripe_payment_icons', array(
198 198
 			'visa'       => '<i class="stripe-pf stripe-pf-visa stripe-pf-right" alt="Visa" aria-hidden="true"></i>',
199 199
 			'amex'       => '<i class="stripe-pf stripe-pf-american-express stripe-pf-right" alt="Amex" aria-hidden="true"></i>',
200 200
 			'mastercard' => '<i class="stripe-pf stripe-pf-mastercard stripe-pf-right" alt="Mastercard" aria-hidden="true"></i>',
@@ -210,7 +210,7 @@  discard block
 block discarded – undo
210 210
 			'eps'        => '<i class="stripe-pf stripe-pf-eps stripe-pf-right" alt="EPS" aria-hidden="true"></i>',
211 211
 			'sofort'     => '<i class="stripe-pf stripe-pf-sofort stripe-pf-right" alt="Sofort" aria-hidden="true"></i>',
212 212
 			'sepa'       => '<i class="stripe-pf stripe-pf-sepa stripe-pf-right" alt="SEPA" aria-hidden="true"></i>',
213
-		) );
213
+		));
214 214
 	}
215 215
 
216 216
 	/**
@@ -229,17 +229,17 @@  discard block
 block discarded – undo
229 229
 		$icons_str .= $icons['amex'];
230 230
 		$icons_str .= $icons['mastercard'];
231 231
 
232
-		if ( 'USD' === get_woocommerce_currency() ) {
232
+		if ('USD' === get_woocommerce_currency()) {
233 233
 			$icons_str .= $icons['discover'];
234 234
 			$icons_str .= $icons['jcb'];
235 235
 			$icons_str .= $icons['diners'];
236 236
 		}
237 237
 
238
-		if ( $this->bitcoin && $this->stripe_checkout ) {
238
+		if ($this->bitcoin && $this->stripe_checkout) {
239 239
 			$icons_str .= $icons['bitcoin'];
240 240
 		}
241 241
 
242
-		return apply_filters( 'woocommerce_gateway_icon', $icons_str, $this->id );
242
+		return apply_filters('woocommerce_gateway_icon', $icons_str, $this->id);
243 243
 	}
244 244
 
245 245
 	/**
@@ -251,9 +251,9 @@  discard block
 block discarded – undo
251 251
 	public function init_apple_pay() {
252 252
 		if (
253 253
 			is_admin() &&
254
-			isset( $_GET['page'] ) && 'wc-settings' === $_GET['page'] &&
255
-			isset( $_GET['tab'] ) && 'checkout' === $_GET['tab'] &&
256
-			isset( $_GET['section'] ) && 'stripe' === $_GET['section'] &&
254
+			isset($_GET['page']) && 'wc-settings' === $_GET['page'] &&
255
+			isset($_GET['tab']) && 'checkout' === $_GET['tab'] &&
256
+			isset($_GET['section']) && 'stripe' === $_GET['section'] &&
257 257
 			$this->apple_pay
258 258
 		) {
259 259
 			$this->process_apple_pay_verification();
@@ -267,9 +267,9 @@  discard block
 block discarded – undo
267 267
 	 * @version 3.1.0
268 268
 	 * @param string $secret_key
269 269
 	 */
270
-	private function register_apple_pay_domain( $secret_key = '' ) {
271
-		if ( empty( $secret_key ) ) {
272
-			throw new Exception( __( 'Unable to verify domain - missing secret key.', 'woocommerce-gateway-stripe' ) );
270
+	private function register_apple_pay_domain($secret_key = '') {
271
+		if (empty($secret_key)) {
272
+			throw new Exception(__('Unable to verify domain - missing secret key.', 'woocommerce-gateway-stripe'));
273 273
 		}
274 274
 
275 275
 		$endpoint = 'https://api.stripe.com/v1/apple_pay/domains';
@@ -283,21 +283,21 @@  discard block
 block discarded – undo
283 283
 			'Authorization' => 'Bearer ' . $secret_key,
284 284
 		);
285 285
 
286
-		$response = wp_remote_post( $endpoint, array(
286
+		$response = wp_remote_post($endpoint, array(
287 287
 			'headers' => $headers,
288
-			'body'    => http_build_query( $data ),
289
-		) );
288
+			'body'    => http_build_query($data),
289
+		));
290 290
 
291
-		if ( is_wp_error( $response ) ) {
292
-			throw new Exception( sprintf( __( 'Unable to verify domain - %s', 'woocommerce-gateway-stripe' ), $response->get_error_message() ) );
291
+		if (is_wp_error($response)) {
292
+			throw new Exception(sprintf(__('Unable to verify domain - %s', 'woocommerce-gateway-stripe'), $response->get_error_message()));
293 293
 		}
294 294
 
295
-		if ( 200 !== $response['response']['code'] ) {
296
-			$parsed_response = json_decode( $response['body'] );
295
+		if (200 !== $response['response']['code']) {
296
+			$parsed_response = json_decode($response['body']);
297 297
 
298 298
 			$this->apple_pay_verify_notice = $parsed_response->error->message;
299 299
 
300
-			throw new Exception( sprintf( __( 'Unable to verify domain - %s', 'woocommerce-gateway-stripe' ), $parsed_response->error->message ) );
300
+			throw new Exception(sprintf(__('Unable to verify domain - %s', 'woocommerce-gateway-stripe'), $parsed_response->error->message));
301 301
 		}
302 302
 	}
303 303
 
@@ -308,48 +308,48 @@  discard block
 block discarded – undo
308 308
 	 * @version 3.1.0
309 309
 	 */
310 310
 	public function process_apple_pay_verification() {
311
-		$gateway_settings = get_option( 'woocommerce_stripe_settings', '' );
311
+		$gateway_settings = get_option('woocommerce_stripe_settings', '');
312 312
 
313 313
 		try {
314
-			$path     = untrailingslashit( preg_replace( "!${_SERVER['SCRIPT_NAME']}$!", '', $_SERVER['SCRIPT_FILENAME'] ) );
314
+			$path     = untrailingslashit(preg_replace("!${_SERVER['SCRIPT_NAME']}$!", '', $_SERVER['SCRIPT_FILENAME']));
315 315
 			$dir      = '.well-known';
316 316
 			$file     = 'apple-developer-merchantid-domain-association';
317 317
 			$fullpath = $path . '/' . $dir . '/' . $file;
318 318
 
319
-			if ( ! empty( $gateway_settings['apple_pay_domain_set'] ) && 'yes' === $gateway_settings['apple_pay_domain_set'] && file_exists( $fullpath ) ) {
319
+			if ( ! empty($gateway_settings['apple_pay_domain_set']) && 'yes' === $gateway_settings['apple_pay_domain_set'] && file_exists($fullpath)) {
320 320
 				return;
321 321
 			}
322 322
 
323
-			if ( ! file_exists( $path . '/' . $dir ) ) {
324
-				if ( ! @mkdir( $path . '/' . $dir, 0755 ) ) {
325
-					throw new Exception( __( 'Unable to create domain association folder to domain root.', 'woocommerce-gateway-stripe' ) );
323
+			if ( ! file_exists($path . '/' . $dir)) {
324
+				if ( ! @mkdir($path . '/' . $dir, 0755)) {
325
+					throw new Exception(__('Unable to create domain association folder to domain root.', 'woocommerce-gateway-stripe'));
326 326
 				}
327 327
 			}
328 328
 
329
-			if ( ! file_exists( $fullpath ) ) {
330
-				if ( ! @copy( WC_STRIPE_PLUGIN_PATH . '/' . $file, $fullpath ) ) {
331
-					throw new Exception( __( 'Unable to copy domain association file to domain root.', 'woocommerce-gateway-stripe' ) );
329
+			if ( ! file_exists($fullpath)) {
330
+				if ( ! @copy(WC_STRIPE_PLUGIN_PATH . '/' . $file, $fullpath)) {
331
+					throw new Exception(__('Unable to copy domain association file to domain root.', 'woocommerce-gateway-stripe'));
332 332
 				}
333 333
 			}
334 334
 
335 335
 			// At this point then the domain association folder and file should be available.
336 336
 			// Proceed to verify/and or verify again.
337
-			$this->register_apple_pay_domain( $this->secret_key );
337
+			$this->register_apple_pay_domain($this->secret_key);
338 338
 
339 339
 			// No errors to this point, verification success!
340 340
 			$gateway_settings['apple_pay_domain_set'] = 'yes';
341 341
 			$this->apple_pay_domain_set = true;
342 342
 
343
-			update_option( 'woocommerce_stripe_settings', $gateway_settings );
343
+			update_option('woocommerce_stripe_settings', $gateway_settings);
344 344
 
345
-			WC_Stripe_Logger::log( 'Your domain has been verified with Apple Pay!' );
345
+			WC_Stripe_Logger::log('Your domain has been verified with Apple Pay!');
346 346
 
347
-		} catch ( Exception $e ) {
347
+		} catch (Exception $e) {
348 348
 			$gateway_settings['apple_pay_domain_set'] = 'no';
349 349
 
350
-			update_option( 'woocommerce_stripe_settings', $gateway_settings );
350
+			update_option('woocommerce_stripe_settings', $gateway_settings);
351 351
 
352
-			WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() );
352
+			WC_Stripe_Logger::log('Error: ' . $e->getMessage());
353 353
 		}
354 354
 	}
355 355
 
@@ -357,11 +357,11 @@  discard block
 block discarded – undo
357 357
 	 * Check if SSL is enabled and notify the user
358 358
 	 */
359 359
 	public function admin_notices() {
360
-		if ( 'no' === $this->enabled ) {
360
+		if ('no' === $this->enabled) {
361 361
 			return;
362 362
 		}
363 363
 
364
-		if ( $this->apple_pay && ! empty( $this->apple_pay_verify_notice ) ) {
364
+		if ($this->apple_pay && ! empty($this->apple_pay_verify_notice)) {
365 365
 			$allowed_html = array(
366 366
 				'a' => array(
367 367
 					'href' => array(),
@@ -369,7 +369,7 @@  discard block
 block discarded – undo
369 369
 				),
370 370
 			);
371 371
 
372
-			echo '<div class="error stripe-apple-pay-message"><p>' . wp_kses( make_clickable( $this->apple_pay_verify_notice ), $allowed_html ) . '</p></div>';
372
+			echo '<div class="error stripe-apple-pay-message"><p>' . wp_kses(make_clickable($this->apple_pay_verify_notice), $allowed_html) . '</p></div>';
373 373
 		}
374 374
 
375 375
 		/**
@@ -377,13 +377,13 @@  discard block
 block discarded – undo
377 377
 		 * when setting screen is displayed. So if domain verification is not set,
378 378
 		 * something went wrong so lets notify user.
379 379
 		 */
380
-		if ( ! empty( $this->secret_key ) && $this->apple_pay && ! $this->apple_pay_domain_set ) {
381
-			echo '<div class="error stripe-apple-pay-message"><p>' . sprintf( __( 'Apple Pay domain verification failed. Please check the %1$slog%2$s to see the issue. (Logging must be enabled to see recorded logs)', 'woocommerce-gateway-stripe' ), '<a href="' . admin_url( 'admin.php?page=wc-status&tab=logs' ) . '">', '</a>' ) . '</p></div>';
380
+		if ( ! empty($this->secret_key) && $this->apple_pay && ! $this->apple_pay_domain_set) {
381
+			echo '<div class="error stripe-apple-pay-message"><p>' . sprintf(__('Apple Pay domain verification failed. Please check the %1$slog%2$s to see the issue. (Logging must be enabled to see recorded logs)', 'woocommerce-gateway-stripe'), '<a href="' . admin_url('admin.php?page=wc-status&tab=logs') . '">', '</a>') . '</p></div>';
382 382
 		}
383 383
 
384 384
 		// Show message if enabled and FORCE SSL is disabled and WordpressHTTPS plugin is not detected.
385
-		if ( ( function_exists( 'wc_site_is_https' ) && ! wc_site_is_https() ) && ( 'no' === get_option( 'woocommerce_force_ssl_checkout' ) && ! class_exists( 'WordPressHTTPS' ) ) ) {
386
-			echo '<div class="error stripe-ssl-message"><p>' . sprintf( __( 'Stripe is enabled, but the <a href="%1$s">force SSL option</a> is disabled; your checkout may not be secure! Please enable SSL and ensure your server has a valid <a href="%2$s" target="_blank">SSL certificate</a> - Stripe will only work in test mode.', 'woocommerce-gateway-stripe' ), admin_url( 'admin.php?page=wc-settings&tab=checkout' ), 'https://en.wikipedia.org/wiki/Transport_Layer_Security' ) . '</p></div>';
385
+		if ((function_exists('wc_site_is_https') && ! wc_site_is_https()) && ('no' === get_option('woocommerce_force_ssl_checkout') && ! class_exists('WordPressHTTPS'))) {
386
+			echo '<div class="error stripe-ssl-message"><p>' . sprintf(__('Stripe is enabled, but the <a href="%1$s">force SSL option</a> is disabled; your checkout may not be secure! Please enable SSL and ensure your server has a valid <a href="%2$s" target="_blank">SSL certificate</a> - Stripe will only work in test mode.', 'woocommerce-gateway-stripe'), admin_url('admin.php?page=wc-settings&tab=checkout'), 'https://en.wikipedia.org/wiki/Transport_Layer_Security') . '</p></div>';
387 387
 		}
388 388
 	}
389 389
 
@@ -391,7 +391,7 @@  discard block
 block discarded – undo
391 391
 	 * Initialise Gateway Settings Form Fields
392 392
 	 */
393 393
 	public function init_form_fields() {
394
-		$this->form_fields = require( dirname( __FILE__ ) . '/admin/stripe-settings.php' );
394
+		$this->form_fields = require(dirname(__FILE__) . '/admin/stripe-settings.php');
395 395
 	}
396 396
 
397 397
 	/**
@@ -399,60 +399,60 @@  discard block
 block discarded – undo
399 399
 	 */
400 400
 	public function payment_fields() {
401 401
 		$user                 = wp_get_current_user();
402
-		$display_tokenization = $this->supports( 'tokenization' ) && is_checkout() && $this->saved_cards;
402
+		$display_tokenization = $this->supports('tokenization') && is_checkout() && $this->saved_cards;
403 403
 		$total                = WC()->cart->total;
404 404
 
405 405
 		// If paying from order, we need to get total from order not cart.
406
-		if ( isset( $_GET['pay_for_order'] ) && ! empty( $_GET['key'] ) ) {
407
-			$order = wc_get_order( wc_get_order_id_by_order_key( wc_clean( $_GET['key'] ) ) );
406
+		if (isset($_GET['pay_for_order']) && ! empty($_GET['key'])) {
407
+			$order = wc_get_order(wc_get_order_id_by_order_key(wc_clean($_GET['key'])));
408 408
 			$total = $order->get_total();
409 409
 		}
410 410
 
411
-		if ( $user->ID ) {
412
-			$user_email = get_user_meta( $user->ID, 'billing_email', true );
411
+		if ($user->ID) {
412
+			$user_email = get_user_meta($user->ID, 'billing_email', true);
413 413
 			$user_email = $user_email ? $user_email : $user->user_email;
414 414
 		} else {
415 415
 			$user_email = '';
416 416
 		}
417 417
 
418
-		if ( is_add_payment_method_page() ) {
419
-			$pay_button_text = __( 'Add Card', 'woocommerce-gateway-stripe' );
420
-			$total        = '';
418
+		if (is_add_payment_method_page()) {
419
+			$pay_button_text = __('Add Card', 'woocommerce-gateway-stripe');
420
+			$total = '';
421 421
 		} else {
422 422
 			$pay_button_text = '';
423 423
 		}
424 424
 
425 425
 		echo '<div
426 426
 			id="stripe-payment-data"
427
-			data-panel-label="' . esc_attr( $pay_button_text ) . '"
427
+			data-panel-label="' . esc_attr($pay_button_text) . '"
428 428
 			data-description=""
429
-			data-email="' . esc_attr( $user_email ) . '"
430
-			data-amount="' . esc_attr( WC_Stripe_Helper::get_stripe_amount( $total ) ) . '"
431
-			data-name="' . esc_attr( $this->statement_descriptor ) . '"
432
-			data-currency="' . esc_attr( strtolower( get_woocommerce_currency() ) ) . '"
433
-			data-image="' . esc_attr( $this->stripe_checkout_image ) . '"
434
-			data-bitcoin="' . esc_attr( $this->bitcoin ? 'true' : 'false' ) . '"
435
-			data-locale="' . esc_attr( $this->stripe_checkout_locale ? $this->stripe_checkout_locale : 'en' ) . '"
436
-			data-three-d-secure="' . esc_attr( $this->three_d_secure ? 'true' : 'false' ) . '"
437
-			data-allow-remember-me="' . esc_attr( $this->saved_cards ? 'true' : 'false' ) . '">';
438
-
439
-		if ( $this->description ) {
440
-			echo apply_filters( 'wc_stripe_description', wpautop( wp_kses_post( $this->description ) ) );
429
+			data-email="' . esc_attr($user_email) . '"
430
+			data-amount="' . esc_attr(WC_Stripe_Helper::get_stripe_amount($total)) . '"
431
+			data-name="' . esc_attr($this->statement_descriptor) . '"
432
+			data-currency="' . esc_attr(strtolower(get_woocommerce_currency())) . '"
433
+			data-image="' . esc_attr($this->stripe_checkout_image) . '"
434
+			data-bitcoin="' . esc_attr($this->bitcoin ? 'true' : 'false') . '"
435
+			data-locale="' . esc_attr($this->stripe_checkout_locale ? $this->stripe_checkout_locale : 'en') . '"
436
+			data-three-d-secure="' . esc_attr($this->three_d_secure ? 'true' : 'false') . '"
437
+			data-allow-remember-me="' . esc_attr($this->saved_cards ? 'true' : 'false') . '">';
438
+
439
+		if ($this->description) {
440
+			echo apply_filters('wc_stripe_description', wpautop(wp_kses_post($this->description)));
441 441
 		}
442 442
 
443
-		if ( $display_tokenization ) {
443
+		if ($display_tokenization) {
444 444
 			$this->tokenization_script();
445 445
 			$this->saved_payment_methods();
446 446
 		}
447 447
 
448
-		if ( ! $this->stripe_checkout ) {
449
-			if ( apply_filters( 'wc_stripe_use_elements_checkout_form', true ) ) {
448
+		if ( ! $this->stripe_checkout) {
449
+			if (apply_filters('wc_stripe_use_elements_checkout_form', true)) {
450 450
 				$this->elements_form();
451 451
 			} else {
452 452
 				$this->form();
453 453
 			}
454 454
 
455
-			if ( apply_filters( 'wc_stripe_display_save_payment_method_checkbox', $display_tokenization ) ) {
455
+			if (apply_filters('wc_stripe_display_save_payment_method_checkbox', $display_tokenization)) {
456 456
 				$this->save_payment_method_checkbox();
457 457
 			}
458 458
 		}
@@ -468,10 +468,10 @@  discard block
 block discarded – undo
468 468
 	 */
469 469
 	public function elements_form() {
470 470
 		?>
471
-		<fieldset id="wc-<?php echo esc_attr( $this->id ); ?>-cc-form" class="wc-credit-card-form wc-payment-form">
472
-			<?php do_action( 'woocommerce_credit_card_form_start', $this->id ); ?>
471
+		<fieldset id="wc-<?php echo esc_attr($this->id); ?>-cc-form" class="wc-credit-card-form wc-payment-form">
472
+			<?php do_action('woocommerce_credit_card_form_start', $this->id); ?>
473 473
 			<label for="card-element">
474
-				<?php _e( 'Credit or debit card', 'woocommerce-gateway-stripe' ); ?>
474
+				<?php _e('Credit or debit card', 'woocommerce-gateway-stripe'); ?>
475 475
 			</label>
476 476
 			
477 477
 			<div id="stripe-card-element" style="background:#fff;padding:0 1em;border-radius:3px;border-width:1px;border-color:#bbb3b9 #c7c1c6 #c7c1c6;border-style:solid;">
@@ -480,7 +480,7 @@  discard block
 block discarded – undo
480 480
 
481 481
 			<!-- Used to display form errors -->
482 482
 			<div class="stripe-source-errors" role="alert"></div>
483
-			<?php do_action( 'woocommerce_credit_card_form_end', $this->id ); ?>
483
+			<?php do_action('woocommerce_credit_card_form_end', $this->id); ?>
484 484
 			<div class="clear"></div>
485 485
 		</fieldset>
486 486
 		<?php
@@ -493,28 +493,28 @@  discard block
 block discarded – undo
493 493
 	 * @version 3.1.0
494 494
 	 */
495 495
 	public function admin_scripts() {
496
-		if ( 'woocommerce_page_wc-settings' !== get_current_screen()->id ) {
496
+		if ('woocommerce_page_wc-settings' !== get_current_screen()->id) {
497 497
 			return;
498 498
 		}
499 499
 
500
-		$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
500
+		$suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';
501 501
 
502
-		wp_enqueue_script( 'woocommerce_stripe_admin', plugins_url( 'assets/js/stripe-admin' . $suffix . '.js', WC_STRIPE_MAIN_FILE ), array(), WC_STRIPE_VERSION, true );
502
+		wp_enqueue_script('woocommerce_stripe_admin', plugins_url('assets/js/stripe-admin' . $suffix . '.js', WC_STRIPE_MAIN_FILE), array(), WC_STRIPE_VERSION, true);
503 503
 
504 504
 		$stripe_admin_params = array(
505 505
 			'localized_messages' => array(
506
-				'not_valid_live_key_msg' => __( 'This is not a valid live key. Live keys start with "sk_live_" and "pk_live_".', 'woocommerce-gateway-stripe' ),
507
-				'not_valid_test_key_msg' => __( 'This is not a valid test key. Test keys start with "sk_test_" and "pk_test_".', 'woocommerce-gateway-stripe' ),
508
-				're_verify_button_text'  => __( 'Re-verify Domain', 'woocommerce-gateway-stripe' ),
509
-				'missing_secret_key'     => __( 'Missing Secret Key. Please set the secret key field above and re-try.', 'woocommerce-gateway-stripe' ),
506
+				'not_valid_live_key_msg' => __('This is not a valid live key. Live keys start with "sk_live_" and "pk_live_".', 'woocommerce-gateway-stripe'),
507
+				'not_valid_test_key_msg' => __('This is not a valid test key. Test keys start with "sk_test_" and "pk_test_".', 'woocommerce-gateway-stripe'),
508
+				're_verify_button_text'  => __('Re-verify Domain', 'woocommerce-gateway-stripe'),
509
+				'missing_secret_key'     => __('Missing Secret Key. Please set the secret key field above and re-try.', 'woocommerce-gateway-stripe'),
510 510
 			),
511
-			'ajaxurl'            => admin_url( 'admin-ajax.php' ),
511
+			'ajaxurl'            => admin_url('admin-ajax.php'),
512 512
 			'nonce'              => array(
513
-				'apple_pay_domain_nonce' => wp_create_nonce( '_wc_stripe_apple_pay_domain_nonce' ),
513
+				'apple_pay_domain_nonce' => wp_create_nonce('_wc_stripe_apple_pay_domain_nonce'),
514 514
 			),
515 515
 		);
516 516
 
517
-		wp_localize_script( 'woocommerce_stripe_admin', 'wc_stripe_admin_params', apply_filters( 'wc_stripe_admin_params', $stripe_admin_params ) );
517
+		wp_localize_script('woocommerce_stripe_admin', 'wc_stripe_admin_params', apply_filters('wc_stripe_admin_params', $stripe_admin_params));
518 518
 	}
519 519
 
520 520
 	/**
@@ -525,72 +525,72 @@  discard block
 block discarded – undo
525 525
 	 * @access public
526 526
 	 */
527 527
 	public function payment_scripts() {
528
-		if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) && ! is_add_payment_method_page() ) {
528
+		if ( ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order']) && ! is_add_payment_method_page()) {
529 529
 			return;
530 530
 		}
531 531
 
532
-		$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
532
+		$suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';
533 533
 
534
-		wp_register_style( 'stripe_paymentfonts', plugins_url( 'assets/css/stripe-paymentfonts.css', WC_STRIPE_MAIN_FILE ), array(), '1.2.5' );
535
-		wp_enqueue_style( 'stripe_paymentfonts' );
536
-		wp_register_script( 'stripe_checkout', 'https://checkout.stripe.com/checkout.js', '', WC_STRIPE_VERSION, true );
537
-		wp_register_script( 'woocommerce_stripe_checkout', plugins_url( 'assets/js/stripe-checkout' . $suffix . '.js', WC_STRIPE_MAIN_FILE ), array( 'stripe_checkout' ), WC_STRIPE_VERSION, true );
538
-		wp_register_script( 'stripev3', 'https://js.stripe.com/v3/', '', '3.0', true );
539
-		wp_register_script( 'woocommerce_stripe_elements', plugins_url( 'assets/js/stripe-elements' . $suffix . '.js', WC_STRIPE_MAIN_FILE ), array( 'jquery-payment', 'stripe' ), WC_STRIPE_VERSION, true );
540
-		wp_register_script( 'woocommerce_stripe', plugins_url( 'assets/js/stripe' . $suffix . '.js', WC_STRIPE_MAIN_FILE ), array( 'jquery-payment', 'stripe' ), WC_STRIPE_VERSION, true );
541
-		wp_register_script( 'stripe', 'https://js.stripe.com/v2/', '', '2.0', true );
534
+		wp_register_style('stripe_paymentfonts', plugins_url('assets/css/stripe-paymentfonts.css', WC_STRIPE_MAIN_FILE), array(), '1.2.5');
535
+		wp_enqueue_style('stripe_paymentfonts');
536
+		wp_register_script('stripe_checkout', 'https://checkout.stripe.com/checkout.js', '', WC_STRIPE_VERSION, true);
537
+		wp_register_script('woocommerce_stripe_checkout', plugins_url('assets/js/stripe-checkout' . $suffix . '.js', WC_STRIPE_MAIN_FILE), array('stripe_checkout'), WC_STRIPE_VERSION, true);
538
+		wp_register_script('stripev3', 'https://js.stripe.com/v3/', '', '3.0', true);
539
+		wp_register_script('woocommerce_stripe_elements', plugins_url('assets/js/stripe-elements' . $suffix . '.js', WC_STRIPE_MAIN_FILE), array('jquery-payment', 'stripe'), WC_STRIPE_VERSION, true);
540
+		wp_register_script('woocommerce_stripe', plugins_url('assets/js/stripe' . $suffix . '.js', WC_STRIPE_MAIN_FILE), array('jquery-payment', 'stripe'), WC_STRIPE_VERSION, true);
541
+		wp_register_script('stripe', 'https://js.stripe.com/v2/', '', '2.0', true);
542 542
 
543 543
 		$stripe_params = array(
544 544
 			'key'                  => $this->publishable_key,
545
-			'i18n_terms'           => __( 'Please accept the terms and conditions first', 'woocommerce-gateway-stripe' ),
546
-			'i18n_required_fields' => __( 'Please fill in required checkout fields first', 'woocommerce-gateway-stripe' ),
545
+			'i18n_terms'           => __('Please accept the terms and conditions first', 'woocommerce-gateway-stripe'),
546
+			'i18n_required_fields' => __('Please fill in required checkout fields first', 'woocommerce-gateway-stripe'),
547 547
 		);
548 548
 
549 549
 		// If we're on the pay page we need to pass stripe.js the address of the order.
550
-		if ( isset( $_GET['pay_for_order'] ) && 'true' === $_GET['pay_for_order'] ) {
551
-			$order_id = wc_get_order_id_by_order_key( urldecode( $_GET['key'] ) );
552
-			$order    = wc_get_order( $order_id );
553
-
554
-			$stripe_params['billing_first_name'] = version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->billing_first_name : $order->get_billing_first_name();
555
-			$stripe_params['billing_last_name']  = version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->billing_last_name : $order->get_billing_last_name();
556
-			$stripe_params['billing_address_1']  = version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->billing_address_1 : $order->get_billing_address_1();
557
-			$stripe_params['billing_address_2']  = version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->billing_address_2 : $order->get_billing_address_2();
558
-			$stripe_params['billing_state']      = version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->billing_state : $order->get_billing_state();
559
-			$stripe_params['billing_city']       = version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->billing_city : $order->get_billing_city();
560
-			$stripe_params['billing_postcode']   = version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->billing_postcode : $order->get_billing_postcode();
561
-			$stripe_params['billing_country']    = version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->billing_country : $order->get_billing_country();
550
+		if (isset($_GET['pay_for_order']) && 'true' === $_GET['pay_for_order']) {
551
+			$order_id = wc_get_order_id_by_order_key(urldecode($_GET['key']));
552
+			$order    = wc_get_order($order_id);
553
+
554
+			$stripe_params['billing_first_name'] = version_compare(WC_VERSION, '3.0.0', '<') ? $order->billing_first_name : $order->get_billing_first_name();
555
+			$stripe_params['billing_last_name']  = version_compare(WC_VERSION, '3.0.0', '<') ? $order->billing_last_name : $order->get_billing_last_name();
556
+			$stripe_params['billing_address_1']  = version_compare(WC_VERSION, '3.0.0', '<') ? $order->billing_address_1 : $order->get_billing_address_1();
557
+			$stripe_params['billing_address_2']  = version_compare(WC_VERSION, '3.0.0', '<') ? $order->billing_address_2 : $order->get_billing_address_2();
558
+			$stripe_params['billing_state']      = version_compare(WC_VERSION, '3.0.0', '<') ? $order->billing_state : $order->get_billing_state();
559
+			$stripe_params['billing_city']       = version_compare(WC_VERSION, '3.0.0', '<') ? $order->billing_city : $order->get_billing_city();
560
+			$stripe_params['billing_postcode']   = version_compare(WC_VERSION, '3.0.0', '<') ? $order->billing_postcode : $order->get_billing_postcode();
561
+			$stripe_params['billing_country']    = version_compare(WC_VERSION, '3.0.0', '<') ? $order->billing_country : $order->get_billing_country();
562 562
 		}
563 563
 
564
-		$stripe_params['no_prepaid_card_msg']                     = __( 'Sorry, we\'re not accepting prepaid cards at this time.', 'woocommerce-gateway-stripe' );
565
-		$stripe_params['no_bank_country_msg']                     = __( 'Please select a country for your bank.', 'woocommerce-gateway-stripe' );
566
-		$stripe_params['no_iban_msg']                             = __( 'Please enter your IBAN account.', 'woocommerce-gateway-stripe' );
567
-		$stripe_params['allow_prepaid_card']                      = apply_filters( 'wc_stripe_allow_prepaid_card', true ) ? 'yes' : 'no';
568
-		$stripe_params['stripe_checkout_require_billing_address'] = apply_filters( 'wc_stripe_checkout_require_billing_address', false ) ? 'yes' : 'no';
569
-		$stripe_params['is_checkout']                             = ( is_checkout() && empty( $_GET['pay_for_order'] ) );
564
+		$stripe_params['no_prepaid_card_msg']                     = __('Sorry, we\'re not accepting prepaid cards at this time.', 'woocommerce-gateway-stripe');
565
+		$stripe_params['no_bank_country_msg']                     = __('Please select a country for your bank.', 'woocommerce-gateway-stripe');
566
+		$stripe_params['no_iban_msg']                             = __('Please enter your IBAN account.', 'woocommerce-gateway-stripe');
567
+		$stripe_params['allow_prepaid_card']                      = apply_filters('wc_stripe_allow_prepaid_card', true) ? 'yes' : 'no';
568
+		$stripe_params['stripe_checkout_require_billing_address'] = apply_filters('wc_stripe_checkout_require_billing_address', false) ? 'yes' : 'no';
569
+		$stripe_params['is_checkout']                             = (is_checkout() && empty($_GET['pay_for_order']));
570 570
 		$stripe_params['return_url']                              = $this->get_stripe_return_url();
571
-		$stripe_params['ajaxurl']                                 = WC_AJAX::get_endpoint( '%%endpoint%%' );
572
-		$stripe_params['stripe_nonce']                            = wp_create_nonce( '_wc_stripe_nonce' );
573
-		$stripe_params['statement_descriptor']                    = str_replace( "'", '', $this->statement_descriptor );
571
+		$stripe_params['ajaxurl']                                 = WC_AJAX::get_endpoint('%%endpoint%%');
572
+		$stripe_params['stripe_nonce']                            = wp_create_nonce('_wc_stripe_nonce');
573
+		$stripe_params['statement_descriptor']                    = str_replace("'", '', $this->statement_descriptor);
574 574
 
575 575
 		// merge localized messages to be use in JS
576
-		$stripe_params = array_merge( $stripe_params, WC_Stripe_Helper::get_localized_messages() );
576
+		$stripe_params = array_merge($stripe_params, WC_Stripe_Helper::get_localized_messages());
577 577
 
578
-		wp_localize_script( 'woocommerce_stripe', 'wc_stripe_params', apply_filters( 'wc_stripe_params', $stripe_params ) );
579
-		wp_localize_script( 'woocommerce_stripe_elements', 'wc_stripe_params', apply_filters( 'wc_stripe_params', $stripe_params ) );
580
-		wp_localize_script( 'woocommerce_stripe_checkout', 'wc_stripe_params', apply_filters( 'wc_stripe_params', $stripe_params ) );
578
+		wp_localize_script('woocommerce_stripe', 'wc_stripe_params', apply_filters('wc_stripe_params', $stripe_params));
579
+		wp_localize_script('woocommerce_stripe_elements', 'wc_stripe_params', apply_filters('wc_stripe_params', $stripe_params));
580
+		wp_localize_script('woocommerce_stripe_checkout', 'wc_stripe_params', apply_filters('wc_stripe_params', $stripe_params));
581 581
 
582
-		if ( $this->stripe_checkout ) {
583
-			wp_enqueue_script( 'stripe_checkout' );
584
-			wp_enqueue_script( 'woocommerce_stripe_checkout' );
582
+		if ($this->stripe_checkout) {
583
+			wp_enqueue_script('stripe_checkout');
584
+			wp_enqueue_script('woocommerce_stripe_checkout');
585 585
 		} else {
586 586
 			// Loading both versions for now as v3 does not support Apple Pay.
587
-			wp_enqueue_script( 'stripe' );
587
+			wp_enqueue_script('stripe');
588 588
 
589
-			if ( apply_filters( 'wc_stripe_use_elements_checkout_form', true ) ) {
590
-				wp_enqueue_script( 'stripev3' );
591
-				wp_enqueue_script( 'woocommerce_stripe_elements' );
589
+			if (apply_filters('wc_stripe_use_elements_checkout_form', true)) {
590
+				wp_enqueue_script('stripev3');
591
+				wp_enqueue_script('woocommerce_stripe_elements');
592 592
 			} else {
593
-				wp_enqueue_script( 'woocommerce_stripe' );
593
+				wp_enqueue_script('woocommerce_stripe');
594 594
 			}
595 595
 		}
596 596
 	}
@@ -604,26 +604,26 @@  discard block
 block discarded – undo
604 604
 	 * @param object $source_object
605 605
 	 * @return mixed
606 606
 	 */
607
-	public function create_3ds_source( $order, $source_object ) {
608
-		$currency              = version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->get_order_currency() : $order->get_currency();
609
-		$order_id              = version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->id : $order->get_id();
607
+	public function create_3ds_source($order, $source_object) {
608
+		$currency              = version_compare(WC_VERSION, '3.0.0', '<') ? $order->get_order_currency() : $order->get_currency();
609
+		$order_id              = version_compare(WC_VERSION, '3.0.0', '<') ? $order->id : $order->get_id();
610 610
 		$stripe_session_id     = uniqid();
611 611
 		
612 612
 		// Set the stripe session id in order meta to later match it for security purposes.
613
-		update_post_meta( $order_id, '_stripe_session_id', $stripe_session_id );
614
-		$return_url            = $this->get_stripe_return_url( $order, $stripe_session_id );
613
+		update_post_meta($order_id, '_stripe_session_id', $stripe_session_id);
614
+		$return_url = $this->get_stripe_return_url($order, $stripe_session_id);
615 615
 
616 616
 		$post_data                   = array();
617
-		$post_data['amount']         = WC_Stripe_Helper::get_stripe_amount( $order->get_total(), $currency );
618
-		$post_data['currency']       = strtolower( $currency );
617
+		$post_data['amount']         = WC_Stripe_Helper::get_stripe_amount($order->get_total(), $currency);
618
+		$post_data['currency']       = strtolower($currency);
619 619
 		$post_data['type']           = 'three_d_secure';
620
-		$post_data['owner']          = $this->get_owner_details( $order );
621
-		$post_data['three_d_secure'] = array( 'card' => $source_object->id );
622
-		$post_data['redirect']       = array( 'return_url' => $return_url );
620
+		$post_data['owner']          = $this->get_owner_details($order);
621
+		$post_data['three_d_secure'] = array('card' => $source_object->id);
622
+		$post_data['redirect']       = array('return_url' => $return_url);
623 623
 
624
-		WC_Stripe_Logger::log( 'Info: Begin creating 3DS source' );
624
+		WC_Stripe_Logger::log('Info: Begin creating 3DS source');
625 625
 
626
-		return WC_Stripe_API::request( $post_data, 'sources' );
626
+		return WC_Stripe_API::request($post_data, 'sources');
627 627
 	}
628 628
 
629 629
 	/**
@@ -637,30 +637,30 @@  discard block
 block discarded – undo
637 637
 	 *
638 638
 	 * @return array|void
639 639
 	 */
640
-	public function process_payment( $order_id, $retry = true, $force_customer = false ) {
640
+	public function process_payment($order_id, $retry = true, $force_customer = false) {
641 641
 		try {
642
-			$order = wc_get_order( $order_id );
643
-			$source_object = ! empty( $_POST['stripe_source_object'] ) ? json_decode( stripslashes( $_POST['stripe_source_object'] ) ) : false;
642
+			$order = wc_get_order($order_id);
643
+			$source_object = ! empty($_POST['stripe_source_object']) ? json_decode(stripslashes($_POST['stripe_source_object'])) : false;
644 644
 
645
-			$source = $this->get_source( get_current_user_id(), $force_customer );
645
+			$source = $this->get_source(get_current_user_id(), $force_customer);
646 646
 
647
-			if ( empty( $source->source ) && empty( $source->customer ) ) {
648
-				$error_msg = __( 'Please enter your card details to make a payment.', 'woocommerce-gateway-stripe' );
649
-				$error_msg .= ' ' . __( 'Developers: Please make sure that you are including jQuery and there are no JavaScript errors on the page.', 'woocommerce-gateway-stripe' );
650
-				throw new Exception( $error_msg );
647
+			if (empty($source->source) && empty($source->customer)) {
648
+				$error_msg = __('Please enter your card details to make a payment.', 'woocommerce-gateway-stripe');
649
+				$error_msg .= ' ' . __('Developers: Please make sure that you are including jQuery and there are no JavaScript errors on the page.', 'woocommerce-gateway-stripe');
650
+				throw new Exception($error_msg);
651 651
 			}
652 652
 
653 653
 			// Store source to order meta.
654
-			$this->save_source( $order, $source );
654
+			$this->save_source($order, $source);
655 655
 
656 656
 			// Result from Stripe API request.
657 657
 			$response = null;
658 658
 
659 659
 			// Handle payment.
660
-			if ( $order->get_total() > 0 ) {
660
+			if ($order->get_total() > 0) {
661 661
 
662
-				if ( $order->get_total() * 100 < WC_Stripe_Helper::get_minimum_amount() ) {
663
-					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_Helper::get_minimum_amount() / 100 ) ) );
662
+				if ($order->get_total() * 100 < WC_Stripe_Helper::get_minimum_amount()) {
663
+					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_Helper::get_minimum_amount() / 100)));
664 664
 				}
665 665
 
666 666
 				/**
@@ -670,60 +670,60 @@  discard block
 block discarded – undo
670 670
 				 * Note that if we need to save source, the original source must be first
671 671
 				 * attached to a customer in Stripe before it can be charged.
672 672
 				 */
673
-				if ( $source_object && ( 'card' === $source_object->type && 'required' === $source_object->card->three_d_secure || ( $this->three_d_secure && 'optional' === $source_object->card->three_d_secure ) ) ) {
673
+				if ($source_object && ('card' === $source_object->type && 'required' === $source_object->card->three_d_secure || ($this->three_d_secure && 'optional' === $source_object->card->three_d_secure))) {
674 674
 
675
-					$response = $this->create_3ds_source( $order, $source_object );
675
+					$response = $this->create_3ds_source($order, $source_object);
676 676
 
677
-					if ( is_wp_error( $response ) ) {
677
+					if (is_wp_error($response)) {
678 678
 						$message = $response->get_error_message();
679 679
 
680
-						$order->add_order_note( $message );
680
+						$order->add_order_note($message);
681 681
 
682
-						throw new Exception( $message );
682
+						throw new Exception($message);
683 683
 					}
684 684
 
685
-					WC_Stripe_Logger::log( 'Info: Redirecting to 3DS...' );
685
+					WC_Stripe_Logger::log('Info: Redirecting to 3DS...');
686 686
 
687 687
 					return array(
688 688
 						'result'   => 'success',
689
-						'redirect' => esc_url_raw( $response->redirect->url ),
689
+						'redirect' => esc_url_raw($response->redirect->url),
690 690
 					);
691 691
 				}
692 692
 
693
-				WC_Stripe_Logger::log( "Info: Begin processing payment for order $order_id for the amount of {$order->get_total()}" );
693
+				WC_Stripe_Logger::log("Info: Begin processing payment for order $order_id for the amount of {$order->get_total()}");
694 694
 
695 695
 				// Make the request.
696
-				$response = WC_Stripe_API::request( $this->generate_payment_request( $order, $source ) );
696
+				$response = WC_Stripe_API::request($this->generate_payment_request($order, $source));
697 697
 
698
-				if ( is_wp_error( $response ) ) {
698
+				if (is_wp_error($response)) {
699 699
 					// Customer param wrong? The user may have been deleted on stripe's end. Remove customer_id. Can be retried without.
700
-					if ( 'customer' === $response->get_error_code() && $retry ) {
701
-						delete_user_meta( get_current_user_id(), '_stripe_customer_id' );
702
-						return $this->process_payment( $order_id, false, $force_customer );
703
-					} elseif ( preg_match( '/No such customer/i', $response->get_error_message() ) && $retry ) {
704
-						delete_user_meta( $order->get_customer_id(), '_stripe_customer_id' );
700
+					if ('customer' === $response->get_error_code() && $retry) {
701
+						delete_user_meta(get_current_user_id(), '_stripe_customer_id');
702
+						return $this->process_payment($order_id, false, $force_customer);
703
+					} elseif (preg_match('/No such customer/i', $response->get_error_message()) && $retry) {
704
+						delete_user_meta($order->get_customer_id(), '_stripe_customer_id');
705 705
 
706
-						return $this->process_redirect_payment( $order_id, false, $source );
706
+						return $this->process_redirect_payment($order_id, false, $source);
707 707
 						// Source param wrong? The CARD may have been deleted on stripe's end. Remove token and show message.
708
-					} elseif ( 'source' === $response->get_error_code() && $source->token_id ) {
709
-						$token = WC_Payment_Tokens::get( $source->token_id );
708
+					} elseif ('source' === $response->get_error_code() && $source->token_id) {
709
+						$token = WC_Payment_Tokens::get($source->token_id);
710 710
 						$token->delete();
711
-						$message = __( 'This card is no longer available and has been removed.', 'woocommerce-gateway-stripe' );
712
-						$order->add_order_note( $message );
713
-						throw new Exception( $message );
711
+						$message = __('This card is no longer available and has been removed.', 'woocommerce-gateway-stripe');
712
+						$order->add_order_note($message);
713
+						throw new Exception($message);
714 714
 					}
715 715
 
716 716
 					$localized_messages = WC_Stripe_Helper::get_localized_messages();
717 717
 
718
-					$message = isset( $localized_messages[ $response->get_error_code() ] ) ? $localized_messages[ $response->get_error_code() ] : $response->get_error_message();
718
+					$message = isset($localized_messages[$response->get_error_code()]) ? $localized_messages[$response->get_error_code()] : $response->get_error_message();
719 719
 
720
-					$order->add_order_note( $message );
720
+					$order->add_order_note($message);
721 721
 
722
-					throw new Exception( $message );
722
+					throw new Exception($message);
723 723
 				}
724 724
 
725 725
 				// Process valid response.
726
-				$this->process_response( $response, $order );
726
+				$this->process_response($response, $order);
727 727
 			} else {
728 728
 				$order->payment_complete();
729 729
 			}
@@ -731,23 +731,23 @@  discard block
 block discarded – undo
731 731
 			// Remove cart.
732 732
 			WC()->cart->empty_cart();
733 733
 
734
-			do_action( 'wc_gateway_stripe_process_payment', $response, $order );
734
+			do_action('wc_gateway_stripe_process_payment', $response, $order);
735 735
 
736 736
 			// Return thank you page redirect.
737 737
 			return array(
738 738
 				'result'   => 'success',
739
-				'redirect' => $this->get_return_url( $order ),
739
+				'redirect' => $this->get_return_url($order),
740 740
 			);
741 741
 
742
-		} catch ( Exception $e ) {
743
-			wc_add_notice( $e->getMessage(), 'error' );
744
-			WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() );
742
+		} catch (Exception $e) {
743
+			wc_add_notice($e->getMessage(), 'error');
744
+			WC_Stripe_Logger::log('Error: ' . $e->getMessage());
745 745
 
746
-			if ( $order->has_status( array( 'pending', 'failed' ) ) ) {
747
-				$this->send_failed_order_email( $order_id );
746
+			if ($order->has_status(array('pending', 'failed'))) {
747
+				$this->send_failed_order_email($order_id);
748 748
 			}
749 749
 
750
-			do_action( 'wc_gateway_stripe_process_payment_error', $e, $order );
750
+			do_action('wc_gateway_stripe_process_payment_error', $e, $order);
751 751
 
752 752
 			return array(
753 753
 				'result'   => 'fail',
Please login to merge, or discard this patch.