Completed
Push — master ( e2f88d...1979c4 )
by Roy
02:13
created
includes/payment-methods/class-wc-gateway-stripe-giropay.php 1 patch
Spacing   +76 added lines, -76 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,9 +57,9 @@  discard block
 block discarded – undo
57 57
 	 */
58 58
 	public function __construct() {
59 59
 		$this->id                   = 'stripe_giropay';
60
-		$this->method_title         = __( 'Stripe Giropay', 'woocommerce-gateway-stripe' );
60
+		$this->method_title         = __('Stripe Giropay', 'woocommerce-gateway-stripe');
61 61
 		/* translators: link */
62
-		$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
+		$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'));
63 63
 		$this->supports             = array(
64 64
 			'products',
65 65
 			'refunds',
@@ -71,25 +71,25 @@  discard block
 block discarded – undo
71 71
 		// Load the settings.
72 72
 		$this->init_settings();
73 73
 
74
-		$main_settings              = get_option( 'woocommerce_stripe_settings' );
75
-		$this->title                = $this->get_option( 'title' );
76
-		$this->description          = $this->get_option( 'description' );
77
-		$this->enabled              = $this->get_option( 'enabled' );
78
-		$this->testmode             = ( ! empty( $main_settings['testmode'] ) && 'yes' === $main_settings['testmode'] ) ? true : false;
79
-		$this->saved_cards          = ( ! empty( $main_settings['saved_cards'] ) && 'yes' === $main_settings['saved_cards'] ) ? true : false;
80
-		$this->publishable_key      = ! empty( $main_settings['publishable_key'] ) ? $main_settings['publishable_key'] : '';
81
-		$this->secret_key           = ! empty( $main_settings['secret_key'] ) ? $main_settings['secret_key'] : '';
82
-		$this->statement_descriptor = ! empty( $main_settings['statement_descriptor'] ) ? $main_settings['statement_descriptor'] : '';
83
-
84
-		if ( $this->testmode ) {
85
-			$this->publishable_key = ! empty( $main_settings['test_publishable_key'] ) ? $main_settings['test_publishable_key'] : '';
86
-			$this->secret_key      = ! empty( $main_settings['test_secret_key'] ) ? $main_settings['test_secret_key'] : '';
74
+		$main_settings              = get_option('woocommerce_stripe_settings');
75
+		$this->title                = $this->get_option('title');
76
+		$this->description          = $this->get_option('description');
77
+		$this->enabled              = $this->get_option('enabled');
78
+		$this->testmode             = ( ! empty($main_settings['testmode']) && 'yes' === $main_settings['testmode']) ? true : false;
79
+		$this->saved_cards          = ( ! empty($main_settings['saved_cards']) && 'yes' === $main_settings['saved_cards']) ? true : false;
80
+		$this->publishable_key      = ! empty($main_settings['publishable_key']) ? $main_settings['publishable_key'] : '';
81
+		$this->secret_key           = ! empty($main_settings['secret_key']) ? $main_settings['secret_key'] : '';
82
+		$this->statement_descriptor = ! empty($main_settings['statement_descriptor']) ? $main_settings['statement_descriptor'] : '';
83
+
84
+		if ($this->testmode) {
85
+			$this->publishable_key = ! empty($main_settings['test_publishable_key']) ? $main_settings['test_publishable_key'] : '';
86
+			$this->secret_key      = ! empty($main_settings['test_secret_key']) ? $main_settings['test_secret_key'] : '';
87 87
 		}
88 88
 
89
-		add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) );
90
-		add_action( 'admin_notices', array( $this, 'check_environment' ) );
91
-		add_action( 'admin_head', array( $this, 'remove_admin_notice' ) );
92
-		add_action( 'wp_enqueue_scripts', array( $this, 'payment_scripts' ) );
89
+		add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options'));
90
+		add_action('admin_notices', array($this, 'check_environment'));
91
+		add_action('admin_head', array($this, 'remove_admin_notice'));
92
+		add_action('wp_enqueue_scripts', array($this, 'payment_scripts'));
93 93
 	}
94 94
 
95 95
 	/**
@@ -99,19 +99,19 @@  discard block
 block discarded – undo
99 99
 	 * @version 4.0.0
100 100
 	 */
101 101
 	public function check_environment() {
102
-		if ( ! current_user_can( 'manage_woocommerce' ) ) {
102
+		if ( ! current_user_can('manage_woocommerce')) {
103 103
 			return;
104 104
 		}
105 105
 
106 106
 		$environment_warning = $this->get_environment_warning();
107 107
 
108
-		if ( $environment_warning ) {
109
-			$this->add_admin_notice( 'bad_environment', 'error', $environment_warning );
108
+		if ($environment_warning) {
109
+			$this->add_admin_notice('bad_environment', 'error', $environment_warning);
110 110
 		}
111 111
 
112
-		foreach ( (array) $this->notices as $notice_key => $notice ) {
113
-			echo "<div class='" . esc_attr( $notice['class'] ) . "'><p>";
114
-			echo wp_kses( $notice['message'], array( 'a' => array( 'href' => array() ) ) );
112
+		foreach ((array) $this->notices as $notice_key => $notice) {
113
+			echo "<div class='" . esc_attr($notice['class']) . "'><p>";
114
+			echo wp_kses($notice['message'], array('a' => array('href' => array())));
115 115
 			echo '</p></div>';
116 116
 		}
117 117
 	}
@@ -124,8 +124,8 @@  discard block
 block discarded – undo
124 124
 	 * @version 4.0.0
125 125
 	 */
126 126
 	public function get_environment_warning() {
127
-		if ( 'yes' === $this->enabled && ! in_array( get_woocommerce_currency(), $this->get_supported_currency() ) ) {
128
-			$message = __( 'Giropay is enabled - it requires store currency to be set to Euros.', 'woocommerce-gateway-stripe' );
127
+		if ('yes' === $this->enabled && ! in_array(get_woocommerce_currency(), $this->get_supported_currency())) {
128
+			$message = __('Giropay is enabled - it requires store currency to be set to Euros.', 'woocommerce-gateway-stripe');
129 129
 
130 130
 			return $message;
131 131
 		}
@@ -141,9 +141,9 @@  discard block
 block discarded – undo
141 141
 	 * @return array
142 142
 	 */
143 143
 	public function get_supported_currency() {
144
-		return apply_filters( 'wc_stripe_giropay_supported_currencies', array(
144
+		return apply_filters('wc_stripe_giropay_supported_currencies', array(
145 145
 			'EUR',
146
-		) );
146
+		));
147 147
 	}
148 148
 
149 149
 	/**
@@ -154,7 +154,7 @@  discard block
 block discarded – undo
154 154
 	 * @return bool
155 155
 	 */
156 156
 	public function is_available() {
157
-		if ( ! in_array( get_woocommerce_currency(), $this->get_supported_currency() ) ) {
157
+		if ( ! in_array(get_woocommerce_currency(), $this->get_supported_currency())) {
158 158
 			return false;
159 159
 		}
160 160
 
@@ -175,7 +175,7 @@  discard block
 block discarded – undo
175 175
 
176 176
 		$icons_str .= $icons['giropay'];
177 177
 
178
-		return apply_filters( 'woocommerce_gateway_icon', $icons_str, $this->id );
178
+		return apply_filters('woocommerce_gateway_icon', $icons_str, $this->id);
179 179
 	}
180 180
 
181 181
 	/**
@@ -186,19 +186,19 @@  discard block
 block discarded – undo
186 186
 	 * @access public
187 187
 	 */
188 188
 	public function payment_scripts() {
189
-		if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) && ! is_add_payment_method_page() ) {
189
+		if ( ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order']) && ! is_add_payment_method_page()) {
190 190
 			return;
191 191
 		}
192 192
 
193
-		wp_enqueue_style( 'stripe_paymentfonts' );
194
-		wp_enqueue_script( 'woocommerce_stripe' );
193
+		wp_enqueue_style('stripe_paymentfonts');
194
+		wp_enqueue_script('woocommerce_stripe');
195 195
 	}
196 196
 
197 197
 	/**
198 198
 	 * Initialize Gateway Settings Form Fields.
199 199
 	 */
200 200
 	public function init_form_fields() {
201
-		$this->form_fields = require( WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-giropay-settings.php' );
201
+		$this->form_fields = require(WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-giropay-settings.php');
202 202
 	}
203 203
 
204 204
 	/**
@@ -209,25 +209,25 @@  discard block
 block discarded – undo
209 209
 		$total                = WC()->cart->total;
210 210
 
211 211
 		// If paying from order, we need to get total from order not cart.
212
-		if ( isset( $_GET['pay_for_order'] ) && ! empty( $_GET['key'] ) ) {
213
-			$order = wc_get_order( wc_get_order_id_by_order_key( wc_clean( $_GET['key'] ) ) );
212
+		if (isset($_GET['pay_for_order']) && ! empty($_GET['key'])) {
213
+			$order = wc_get_order(wc_get_order_id_by_order_key(wc_clean($_GET['key'])));
214 214
 			$total = $order->get_total();
215 215
 		}
216 216
 
217
-		if ( is_add_payment_method_page() ) {
218
-			$pay_button_text = __( 'Add Payment', 'woocommerce-gateway-stripe' );
219
-			$total        = '';
217
+		if (is_add_payment_method_page()) {
218
+			$pay_button_text = __('Add Payment', 'woocommerce-gateway-stripe');
219
+			$total = '';
220 220
 		} else {
221 221
 			$pay_button_text = '';
222 222
 		}
223 223
 
224 224
 		echo '<div
225 225
 			id="stripe-giropay-payment-data"
226
-			data-amount="' . esc_attr( WC_Stripe_Helper::get_stripe_amount( $total ) ) . '"
227
-			data-currency="' . esc_attr( strtolower( get_woocommerce_currency() ) ) . '">';
226
+			data-amount="' . esc_attr(WC_Stripe_Helper::get_stripe_amount($total)) . '"
227
+			data-currency="' . esc_attr(strtolower(get_woocommerce_currency())) . '">';
228 228
 
229
-		if ( $this->description ) {
230
-			echo apply_filters( 'wc_stripe_description', wpautop( wp_kses_post( $this->description ) ) );
229
+		if ($this->description) {
230
+			echo apply_filters('wc_stripe_description', wpautop(wp_kses_post($this->description)));
231 231
 		}
232 232
 
233 233
 		echo '</div>';
@@ -241,24 +241,24 @@  discard block
 block discarded – undo
241 241
 	 * @param object $order
242 242
 	 * @return mixed
243 243
 	 */
244
-	public function create_source( $order ) {
244
+	public function create_source($order) {
245 245
 		$currency                          = WC_Stripe_Helper::is_pre_30() ? $order->get_order_currency() : $order->get_currency();
246 246
 		$order_id                          = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
247
-		$return_url                        = $this->get_stripe_return_url( $order );
247
+		$return_url                        = $this->get_stripe_return_url($order);
248 248
 		$post_data                         = array();
249
-		$post_data['amount']               = WC_Stripe_Helper::get_stripe_amount( $order->get_total(), $currency );
250
-		$post_data['currency']             = strtolower( $currency );
249
+		$post_data['amount']               = WC_Stripe_Helper::get_stripe_amount($order->get_total(), $currency);
250
+		$post_data['currency']             = strtolower($currency);
251 251
 		$post_data['type']                 = 'giropay';
252
-		$post_data['owner']                = $this->get_owner_details( $order );
253
-		$post_data['redirect']             = array( 'return_url' => $return_url );
252
+		$post_data['owner']                = $this->get_owner_details($order);
253
+		$post_data['redirect']             = array('return_url' => $return_url);
254 254
 
255
-		if ( ! empty( $this->statement_descriptor ) ) {
256
-			$post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor( $this->statement_descriptor );
255
+		if ( ! empty($this->statement_descriptor)) {
256
+			$post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor($this->statement_descriptor);
257 257
 		}
258 258
 
259
-		WC_Stripe_Logger::log( 'Info: Begin creating Giropay source' );
259
+		WC_Stripe_Logger::log('Info: Begin creating Giropay source');
260 260
 
261
-		return WC_Stripe_API::request( apply_filters( 'wc_stripe_giropay_source', $post_data, $order ), 'sources' );
261
+		return WC_Stripe_API::request(apply_filters('wc_stripe_giropay_source', $post_data, $order), 'sources');
262 262
 	}
263 263
 
264 264
 	/**
@@ -272,51 +272,51 @@  discard block
 block discarded – undo
272 272
 	 *
273 273
 	 * @return array|void
274 274
 	 */
275
-	public function process_payment( $order_id, $retry = true, $force_save_source = false ) {
275
+	public function process_payment($order_id, $retry = true, $force_save_source = false) {
276 276
 		try {
277
-			$order = wc_get_order( $order_id );
277
+			$order = wc_get_order($order_id);
278 278
 
279 279
 			// This will throw exception if not valid.
280
-			$this->validate_minimum_order_amount( $order );
280
+			$this->validate_minimum_order_amount($order);
281 281
 
282 282
 			// This comes from the create account checkbox in the checkout page.
283
-			$create_account = ! empty( $_POST['createaccount'] ) ? true : false;
283
+			$create_account = ! empty($_POST['createaccount']) ? true : false;
284 284
 
285
-			if ( $create_account ) {
285
+			if ($create_account) {
286 286
 				$new_customer_id     = WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id();
287
-				$new_stripe_customer = new WC_Stripe_Customer( $new_customer_id );
287
+				$new_stripe_customer = new WC_Stripe_Customer($new_customer_id);
288 288
 				$new_stripe_customer->create_customer();
289 289
 			}
290 290
 
291
-			$response = $this->create_source( $order );
291
+			$response = $this->create_source($order);
292 292
 
293
-			if ( ! empty( $response->error ) ) {
294
-				$order->add_order_note( $response->error->message );
293
+			if ( ! empty($response->error)) {
294
+				$order->add_order_note($response->error->message);
295 295
 
296
-				throw new WC_Stripe_Exception( print_r( $response, true ), $response->error->message );
296
+				throw new WC_Stripe_Exception(print_r($response, true), $response->error->message);
297 297
 			}
298 298
 
299
-			if ( WC_Stripe_Helper::is_pre_30() ) {
300
-				update_post_meta( $order_id, '_stripe_source_id', $response->id );
299
+			if (WC_Stripe_Helper::is_pre_30()) {
300
+				update_post_meta($order_id, '_stripe_source_id', $response->id);
301 301
 			} else {
302
-				$order->update_meta_data( '_stripe_source_id', $response->id );
302
+				$order->update_meta_data('_stripe_source_id', $response->id);
303 303
 				$order->save();
304 304
 			}
305 305
 
306
-			WC_Stripe_Logger::log( 'Info: Redirecting to Giropay...' );
306
+			WC_Stripe_Logger::log('Info: Redirecting to Giropay...');
307 307
 
308 308
 			return array(
309 309
 				'result'   => 'success',
310
-				'redirect' => esc_url_raw( $response->redirect->url ),
310
+				'redirect' => esc_url_raw($response->redirect->url),
311 311
 			);
312
-		} catch ( WC_Stripe_Exception $e ) {
313
-			wc_add_notice( $e->getLocalizedMessage(), 'error' );
314
-			WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() );
312
+		} catch (WC_Stripe_Exception $e) {
313
+			wc_add_notice($e->getLocalizedMessage(), 'error');
314
+			WC_Stripe_Logger::log('Error: ' . $e->getMessage());
315 315
 
316
-			do_action( 'wc_gateway_stripe_process_payment_error', $e, $order );
316
+			do_action('wc_gateway_stripe_process_payment_error', $e, $order);
317 317
 
318
-			if ( $order->has_status( array( 'pending', 'failed' ) ) ) {
319
-				$this->send_failed_order_email( $order_id );
318
+			if ($order->has_status(array('pending', 'failed'))) {
319
+				$this->send_failed_order_email($order_id);
320 320
 			}
321 321
 
322 322
 			return array(
Please login to merge, or discard this patch.
includes/payment-methods/class-wc-gateway-stripe-ideal.php 1 patch
Spacing   +76 added lines, -76 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,9 +57,9 @@  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' );
60
+		$this->method_title         = __('Stripe iDeal', 'woocommerce-gateway-stripe');
61 61
 		/* translators: link */
62
-		$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
+		$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'));
63 63
 		$this->supports             = array(
64 64
 			'products',
65 65
 			'refunds',
@@ -71,25 +71,25 @@  discard block
 block discarded – undo
71 71
 		// Load the settings.
72 72
 		$this->init_settings();
73 73
 
74
-		$main_settings              = get_option( 'woocommerce_stripe_settings' );
75
-		$this->title                = $this->get_option( 'title' );
76
-		$this->description          = $this->get_option( 'description' );
77
-		$this->enabled              = $this->get_option( 'enabled' );
78
-		$this->testmode             = ( ! empty( $main_settings['testmode'] ) && 'yes' === $main_settings['testmode'] ) ? true : false;
79
-		$this->saved_cards          = ( ! empty( $main_settings['saved_cards'] ) && 'yes' === $main_settings['saved_cards'] ) ? true : false;
80
-		$this->publishable_key      = ! empty( $main_settings['publishable_key'] ) ? $main_settings['publishable_key'] : '';
81
-		$this->secret_key           = ! empty( $main_settings['secret_key'] ) ? $main_settings['secret_key'] : '';
82
-		$this->statement_descriptor = ! empty( $main_settings['statement_descriptor'] ) ? $main_settings['statement_descriptor'] : '';
83
-
84
-		if ( $this->testmode ) {
85
-			$this->publishable_key = ! empty( $main_settings['test_publishable_key'] ) ? $main_settings['test_publishable_key'] : '';
86
-			$this->secret_key      = ! empty( $main_settings['test_secret_key'] ) ? $main_settings['test_secret_key'] : '';
74
+		$main_settings              = get_option('woocommerce_stripe_settings');
75
+		$this->title                = $this->get_option('title');
76
+		$this->description          = $this->get_option('description');
77
+		$this->enabled              = $this->get_option('enabled');
78
+		$this->testmode             = ( ! empty($main_settings['testmode']) && 'yes' === $main_settings['testmode']) ? true : false;
79
+		$this->saved_cards          = ( ! empty($main_settings['saved_cards']) && 'yes' === $main_settings['saved_cards']) ? true : false;
80
+		$this->publishable_key      = ! empty($main_settings['publishable_key']) ? $main_settings['publishable_key'] : '';
81
+		$this->secret_key           = ! empty($main_settings['secret_key']) ? $main_settings['secret_key'] : '';
82
+		$this->statement_descriptor = ! empty($main_settings['statement_descriptor']) ? $main_settings['statement_descriptor'] : '';
83
+
84
+		if ($this->testmode) {
85
+			$this->publishable_key = ! empty($main_settings['test_publishable_key']) ? $main_settings['test_publishable_key'] : '';
86
+			$this->secret_key      = ! empty($main_settings['test_secret_key']) ? $main_settings['test_secret_key'] : '';
87 87
 		}
88 88
 
89
-		add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) );
90
-		add_action( 'admin_notices', array( $this, 'check_environment' ) );
91
-		add_action( 'admin_head', array( $this, 'remove_admin_notice' ) );
92
-		add_action( 'wp_enqueue_scripts', array( $this, 'payment_scripts' ) );
89
+		add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options'));
90
+		add_action('admin_notices', array($this, 'check_environment'));
91
+		add_action('admin_head', array($this, 'remove_admin_notice'));
92
+		add_action('wp_enqueue_scripts', array($this, 'payment_scripts'));
93 93
 	}
94 94
 
95 95
 	/**
@@ -99,19 +99,19 @@  discard block
 block discarded – undo
99 99
 	 * @version 4.0.0
100 100
 	 */
101 101
 	public function check_environment() {
102
-		if ( ! current_user_can( 'manage_woocommerce' ) ) {
102
+		if ( ! current_user_can('manage_woocommerce')) {
103 103
 			return;
104 104
 		}
105 105
 
106 106
 		$environment_warning = $this->get_environment_warning();
107 107
 
108
-		if ( $environment_warning ) {
109
-			$this->add_admin_notice( 'bad_environment', 'error', $environment_warning );
108
+		if ($environment_warning) {
109
+			$this->add_admin_notice('bad_environment', 'error', $environment_warning);
110 110
 		}
111 111
 
112
-		foreach ( (array) $this->notices as $notice_key => $notice ) {
113
-			echo "<div class='" . esc_attr( $notice['class'] ) . "'><p>";
114
-			echo wp_kses( $notice['message'], array( 'a' => array( 'href' => array() ) ) );
112
+		foreach ((array) $this->notices as $notice_key => $notice) {
113
+			echo "<div class='" . esc_attr($notice['class']) . "'><p>";
114
+			echo wp_kses($notice['message'], array('a' => array('href' => array())));
115 115
 			echo '</p></div>';
116 116
 		}
117 117
 	}
@@ -124,8 +124,8 @@  discard block
 block discarded – undo
124 124
 	 * @version 4.0.0
125 125
 	 */
126 126
 	public function get_environment_warning() {
127
-		if ( 'yes' === $this->enabled && ! in_array( get_woocommerce_currency(), $this->get_supported_currency() ) ) {
128
-			$message = __( 'iDeal is enabled - it requires store currency to be set to Euros.', 'woocommerce-gateway-stripe' );
127
+		if ('yes' === $this->enabled && ! in_array(get_woocommerce_currency(), $this->get_supported_currency())) {
128
+			$message = __('iDeal is enabled - it requires store currency to be set to Euros.', 'woocommerce-gateway-stripe');
129 129
 
130 130
 			return $message;
131 131
 		}
@@ -141,9 +141,9 @@  discard block
 block discarded – undo
141 141
 	 * @return array
142 142
 	 */
143 143
 	public function get_supported_currency() {
144
-		return apply_filters( 'wc_stripe_ideal_supported_currencies', array(
144
+		return apply_filters('wc_stripe_ideal_supported_currencies', array(
145 145
 			'EUR',
146
-		) );
146
+		));
147 147
 	}
148 148
 
149 149
 	/**
@@ -154,7 +154,7 @@  discard block
 block discarded – undo
154 154
 	 * @return bool
155 155
 	 */
156 156
 	public function is_available() {
157
-		if ( ! in_array( get_woocommerce_currency(), $this->get_supported_currency() ) ) {
157
+		if ( ! in_array(get_woocommerce_currency(), $this->get_supported_currency())) {
158 158
 			return false;
159 159
 		}
160 160
 
@@ -175,7 +175,7 @@  discard block
 block discarded – undo
175 175
 
176 176
 		$icons_str .= $icons['ideal'];
177 177
 
178
-		return apply_filters( 'woocommerce_gateway_icon', $icons_str, $this->id );
178
+		return apply_filters('woocommerce_gateway_icon', $icons_str, $this->id);
179 179
 	}
180 180
 
181 181
 	/**
@@ -186,19 +186,19 @@  discard block
 block discarded – undo
186 186
 	 * @access public
187 187
 	 */
188 188
 	public function payment_scripts() {
189
-		if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) && ! is_add_payment_method_page() ) {
189
+		if ( ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order']) && ! is_add_payment_method_page()) {
190 190
 			return;
191 191
 		}
192 192
 
193
-		wp_enqueue_style( 'stripe_paymentfonts' );
194
-		wp_enqueue_script( 'woocommerce_stripe' );
193
+		wp_enqueue_style('stripe_paymentfonts');
194
+		wp_enqueue_script('woocommerce_stripe');
195 195
 	}
196 196
 
197 197
 	/**
198 198
 	 * Initialize Gateway Settings Form Fields.
199 199
 	 */
200 200
 	public function init_form_fields() {
201
-		$this->form_fields = require( WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-ideal-settings.php' );
201
+		$this->form_fields = require(WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-ideal-settings.php');
202 202
 	}
203 203
 
204 204
 	/**
@@ -209,25 +209,25 @@  discard block
 block discarded – undo
209 209
 		$total                = WC()->cart->total;
210 210
 
211 211
 		// If paying from order, we need to get total from order not cart.
212
-		if ( isset( $_GET['pay_for_order'] ) && ! empty( $_GET['key'] ) ) {
213
-			$order = wc_get_order( wc_get_order_id_by_order_key( wc_clean( $_GET['key'] ) ) );
212
+		if (isset($_GET['pay_for_order']) && ! empty($_GET['key'])) {
213
+			$order = wc_get_order(wc_get_order_id_by_order_key(wc_clean($_GET['key'])));
214 214
 			$total = $order->get_total();
215 215
 		}
216 216
 
217
-		if ( is_add_payment_method_page() ) {
218
-			$pay_button_text = __( 'Add Payment', 'woocommerce-gateway-stripe' );
219
-			$total        = '';
217
+		if (is_add_payment_method_page()) {
218
+			$pay_button_text = __('Add Payment', 'woocommerce-gateway-stripe');
219
+			$total = '';
220 220
 		} else {
221 221
 			$pay_button_text = '';
222 222
 		}
223 223
 
224 224
 		echo '<div
225 225
 			id="stripe-ideal-payment-data"
226
-			data-amount="' . esc_attr( WC_Stripe_Helper::get_stripe_amount( $total ) ) . '"
227
-			data-currency="' . esc_attr( strtolower( get_woocommerce_currency() ) ) . '">';
226
+			data-amount="' . esc_attr(WC_Stripe_Helper::get_stripe_amount($total)) . '"
227
+			data-currency="' . esc_attr(strtolower(get_woocommerce_currency())) . '">';
228 228
 
229
-		if ( $this->description ) {
230
-			echo apply_filters( 'wc_stripe_description', wpautop( wp_kses_post( $this->description ) ) );
229
+		if ($this->description) {
230
+			echo apply_filters('wc_stripe_description', wpautop(wp_kses_post($this->description)));
231 231
 		}
232 232
 
233 233
 		echo '</div>';
@@ -241,24 +241,24 @@  discard block
 block discarded – undo
241 241
 	 * @param object $order
242 242
 	 * @return mixed
243 243
 	 */
244
-	public function create_source( $order ) {
244
+	public function create_source($order) {
245 245
 		$currency                          = WC_Stripe_Helper::is_pre_30() ? $order->get_order_currency() : $order->get_currency();
246 246
 		$order_id                          = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
247
-		$return_url                        = $this->get_stripe_return_url( $order );
247
+		$return_url                        = $this->get_stripe_return_url($order);
248 248
 		$post_data                         = array();
249
-		$post_data['amount']               = WC_Stripe_Helper::get_stripe_amount( $order->get_total(), $currency );
250
-		$post_data['currency']             = strtolower( $currency );
249
+		$post_data['amount']               = WC_Stripe_Helper::get_stripe_amount($order->get_total(), $currency);
250
+		$post_data['currency']             = strtolower($currency);
251 251
 		$post_data['type']                 = 'ideal';
252
-		$post_data['owner']                = $this->get_owner_details( $order );
253
-		$post_data['redirect']             = array( 'return_url' => $return_url );
252
+		$post_data['owner']                = $this->get_owner_details($order);
253
+		$post_data['redirect']             = array('return_url' => $return_url);
254 254
 
255
-		if ( ! empty( $this->statement_descriptor ) ) {
256
-			$post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor( $this->statement_descriptor );
255
+		if ( ! empty($this->statement_descriptor)) {
256
+			$post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor($this->statement_descriptor);
257 257
 		}
258 258
 
259
-		WC_Stripe_Logger::log( 'Info: Begin creating iDeal source' );
259
+		WC_Stripe_Logger::log('Info: Begin creating iDeal source');
260 260
 
261
-		return WC_Stripe_API::request( apply_filters( 'wc_stripe_ideal_source', $post_data, $order ), 'sources' );
261
+		return WC_Stripe_API::request(apply_filters('wc_stripe_ideal_source', $post_data, $order), 'sources');
262 262
 	}
263 263
 
264 264
 	/**
@@ -272,51 +272,51 @@  discard block
 block discarded – undo
272 272
 	 *
273 273
 	 * @return array|void
274 274
 	 */
275
-	public function process_payment( $order_id, $retry = true, $force_save_source = false ) {
275
+	public function process_payment($order_id, $retry = true, $force_save_source = false) {
276 276
 		try {
277
-			$order = wc_get_order( $order_id );
277
+			$order = wc_get_order($order_id);
278 278
 
279 279
 			// This will throw exception if not valid.
280
-			$this->validate_minimum_order_amount( $order );
280
+			$this->validate_minimum_order_amount($order);
281 281
 
282 282
 			// This comes from the create account checkbox in the checkout page.
283
-			$create_account = ! empty( $_POST['createaccount'] ) ? true : false;
283
+			$create_account = ! empty($_POST['createaccount']) ? true : false;
284 284
 
285
-			if ( $create_account ) {
285
+			if ($create_account) {
286 286
 				$new_customer_id     = WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id();
287
-				$new_stripe_customer = new WC_Stripe_Customer( $new_customer_id );
287
+				$new_stripe_customer = new WC_Stripe_Customer($new_customer_id);
288 288
 				$new_stripe_customer->create_customer();
289 289
 			}
290 290
 
291
-			$response = $this->create_source( $order );
291
+			$response = $this->create_source($order);
292 292
 
293
-			if ( ! empty( $response->error ) ) {
294
-				$order->add_order_note( $response->error->message );
293
+			if ( ! empty($response->error)) {
294
+				$order->add_order_note($response->error->message);
295 295
 
296
-				throw new WC_Stripe_Exception( print_r( $response, true ), $response->error->message );
296
+				throw new WC_Stripe_Exception(print_r($response, true), $response->error->message);
297 297
 			}
298 298
 
299
-			if ( WC_Stripe_Helper::is_pre_30() ) {
300
-				update_post_meta( $order_id, '_stripe_source_id', $response->id );
299
+			if (WC_Stripe_Helper::is_pre_30()) {
300
+				update_post_meta($order_id, '_stripe_source_id', $response->id);
301 301
 			} else {
302
-				$order->update_meta_data( '_stripe_source_id', $response->id );
302
+				$order->update_meta_data('_stripe_source_id', $response->id);
303 303
 				$order->save();
304 304
 			}
305 305
 
306
-			WC_Stripe_Logger::log( 'Info: Redirecting to iDeal...' );
306
+			WC_Stripe_Logger::log('Info: Redirecting to iDeal...');
307 307
 
308 308
 			return array(
309 309
 				'result'   => 'success',
310
-				'redirect' => esc_url_raw( $response->redirect->url ),
310
+				'redirect' => esc_url_raw($response->redirect->url),
311 311
 			);
312
-		} catch ( WC_Stripe_Exception $e ) {
313
-			wc_add_notice( $e->getLocalizedMessage(), 'error' );
314
-			WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() );
312
+		} catch (WC_Stripe_Exception $e) {
313
+			wc_add_notice($e->getLocalizedMessage(), 'error');
314
+			WC_Stripe_Logger::log('Error: ' . $e->getMessage());
315 315
 
316
-			do_action( 'wc_gateway_stripe_process_payment_error', $e, $order );
316
+			do_action('wc_gateway_stripe_process_payment_error', $e, $order);
317 317
 
318
-			if ( $order->has_status( array( 'pending', 'failed' ) ) ) {
319
-				$this->send_failed_order_email( $order_id );
318
+			if ($order->has_status(array('pending', 'failed'))) {
319
+				$this->send_failed_order_email($order_id);
320 320
 			}
321 321
 
322 322
 			return array(
Please login to merge, or discard this patch.
includes/payment-methods/class-wc-gateway-stripe-sofort.php 1 patch
Spacing   +80 added lines, -80 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,9 +57,9 @@  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' );
60
+		$this->method_title         = __('Stripe SOFORT', 'woocommerce-gateway-stripe');
61 61
 		/* translators: link */
62
-		$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
+		$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'));
63 63
 		$this->supports             = array(
64 64
 			'products',
65 65
 			'refunds',
@@ -71,25 +71,25 @@  discard block
 block discarded – undo
71 71
 		// Load the settings.
72 72
 		$this->init_settings();
73 73
 
74
-		$main_settings              = get_option( 'woocommerce_stripe_settings' );
75
-		$this->title                = $this->get_option( 'title' );
76
-		$this->description          = $this->get_option( 'description' );
77
-		$this->enabled              = $this->get_option( 'enabled' );
78
-		$this->testmode             = ( ! empty( $main_settings['testmode'] ) && 'yes' === $main_settings['testmode'] ) ? true : false;
79
-		$this->saved_cards          = ( ! empty( $main_settings['saved_cards'] ) && 'yes' === $main_settings['saved_cards'] ) ? true : false;
80
-		$this->publishable_key      = ! empty( $main_settings['publishable_key'] ) ? $main_settings['publishable_key'] : '';
81
-		$this->secret_key           = ! empty( $main_settings['secret_key'] ) ? $main_settings['secret_key'] : '';
82
-		$this->statement_descriptor = ! empty( $main_settings['statement_descriptor'] ) ? $main_settings['statement_descriptor'] : '';
83
-
84
-		if ( $this->testmode ) {
85
-			$this->publishable_key = ! empty( $main_settings['test_publishable_key'] ) ? $main_settings['test_publishable_key'] : '';
86
-			$this->secret_key      = ! empty( $main_settings['test_secret_key'] ) ? $main_settings['test_secret_key'] : '';
74
+		$main_settings              = get_option('woocommerce_stripe_settings');
75
+		$this->title                = $this->get_option('title');
76
+		$this->description          = $this->get_option('description');
77
+		$this->enabled              = $this->get_option('enabled');
78
+		$this->testmode             = ( ! empty($main_settings['testmode']) && 'yes' === $main_settings['testmode']) ? true : false;
79
+		$this->saved_cards          = ( ! empty($main_settings['saved_cards']) && 'yes' === $main_settings['saved_cards']) ? true : false;
80
+		$this->publishable_key      = ! empty($main_settings['publishable_key']) ? $main_settings['publishable_key'] : '';
81
+		$this->secret_key           = ! empty($main_settings['secret_key']) ? $main_settings['secret_key'] : '';
82
+		$this->statement_descriptor = ! empty($main_settings['statement_descriptor']) ? $main_settings['statement_descriptor'] : '';
83
+
84
+		if ($this->testmode) {
85
+			$this->publishable_key = ! empty($main_settings['test_publishable_key']) ? $main_settings['test_publishable_key'] : '';
86
+			$this->secret_key      = ! empty($main_settings['test_secret_key']) ? $main_settings['test_secret_key'] : '';
87 87
 		}
88 88
 
89
-		add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) );
90
-		add_action( 'admin_notices', array( $this, 'check_environment' ) );
91
-		add_action( 'admin_head', array( $this, 'remove_admin_notice' ) );
92
-		add_action( 'wp_enqueue_scripts', array( $this, 'payment_scripts' ) );
89
+		add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options'));
90
+		add_action('admin_notices', array($this, 'check_environment'));
91
+		add_action('admin_head', array($this, 'remove_admin_notice'));
92
+		add_action('wp_enqueue_scripts', array($this, 'payment_scripts'));
93 93
 	}
94 94
 
95 95
 	/**
@@ -99,19 +99,19 @@  discard block
 block discarded – undo
99 99
 	 * @version 4.0.0
100 100
 	 */
101 101
 	public function check_environment() {
102
-		if ( ! current_user_can( 'manage_woocommerce' ) ) {
102
+		if ( ! current_user_can('manage_woocommerce')) {
103 103
 			return;
104 104
 		}
105 105
 
106 106
 		$environment_warning = $this->get_environment_warning();
107 107
 
108
-		if ( $environment_warning ) {
109
-			$this->add_admin_notice( 'bad_environment', 'error', $environment_warning );
108
+		if ($environment_warning) {
109
+			$this->add_admin_notice('bad_environment', 'error', $environment_warning);
110 110
 		}
111 111
 
112
-		foreach ( (array) $this->notices as $notice_key => $notice ) {
113
-			echo "<div class='" . esc_attr( $notice['class'] ) . "'><p>";
114
-			echo wp_kses( $notice['message'], array( 'a' => array( 'href' => array() ) ) );
112
+		foreach ((array) $this->notices as $notice_key => $notice) {
113
+			echo "<div class='" . esc_attr($notice['class']) . "'><p>";
114
+			echo wp_kses($notice['message'], array('a' => array('href' => array())));
115 115
 			echo '</p></div>';
116 116
 		}
117 117
 	}
@@ -124,8 +124,8 @@  discard block
 block discarded – undo
124 124
 	 * @version 4.0.0
125 125
 	 */
126 126
 	public function get_environment_warning() {
127
-		if ( 'yes' === $this->enabled && ! in_array( get_woocommerce_currency(), $this->get_supported_currency() ) ) {
128
-			$message = __( 'SOFORT is enabled - it requires store currency to be set to Euros.', 'woocommerce-gateway-stripe' );
127
+		if ('yes' === $this->enabled && ! in_array(get_woocommerce_currency(), $this->get_supported_currency())) {
128
+			$message = __('SOFORT is enabled - it requires store currency to be set to Euros.', 'woocommerce-gateway-stripe');
129 129
 
130 130
 			return $message;
131 131
 		}
@@ -141,9 +141,9 @@  discard block
 block discarded – undo
141 141
 	 * @return array
142 142
 	 */
143 143
 	public function get_supported_currency() {
144
-		return apply_filters( 'wc_stripe_sofort_supported_currencies', array(
144
+		return apply_filters('wc_stripe_sofort_supported_currencies', array(
145 145
 			'EUR',
146
-		) );
146
+		));
147 147
 	}
148 148
 
149 149
 	/**
@@ -154,7 +154,7 @@  discard block
 block discarded – undo
154 154
 	 * @return bool
155 155
 	 */
156 156
 	public function is_available() {
157
-		if ( ! in_array( get_woocommerce_currency(), $this->get_supported_currency() ) ) {
157
+		if ( ! in_array(get_woocommerce_currency(), $this->get_supported_currency())) {
158 158
 			return false;
159 159
 		}
160 160
 
@@ -175,7 +175,7 @@  discard block
 block discarded – undo
175 175
 
176 176
 		$icons_str .= $icons['sofort'];
177 177
 
178
-		return apply_filters( 'woocommerce_gateway_icon', $icons_str, $this->id );
178
+		return apply_filters('woocommerce_gateway_icon', $icons_str, $this->id);
179 179
 	}
180 180
 
181 181
 	/**
@@ -186,19 +186,19 @@  discard block
 block discarded – undo
186 186
 	 * @access public
187 187
 	 */
188 188
 	public function payment_scripts() {
189
-		if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) && ! is_add_payment_method_page() ) {
189
+		if ( ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order']) && ! is_add_payment_method_page()) {
190 190
 			return;
191 191
 		}
192 192
 
193
-		wp_enqueue_style( 'stripe_paymentfonts' );
194
-		wp_enqueue_script( 'woocommerce_stripe' );
193
+		wp_enqueue_style('stripe_paymentfonts');
194
+		wp_enqueue_script('woocommerce_stripe');
195 195
 	}
196 196
 
197 197
 	/**
198 198
 	 * Initialize Gateway Settings Form Fields.
199 199
 	 */
200 200
 	public function init_form_fields() {
201
-		$this->form_fields = require( WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-sofort-settings.php' );
201
+		$this->form_fields = require(WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-sofort-settings.php');
202 202
 	}
203 203
 
204 204
 	/**
@@ -209,25 +209,25 @@  discard block
 block discarded – undo
209 209
 		$total = WC()->cart->total;
210 210
 
211 211
 		// If paying from order, we need to get total from order not cart.
212
-		if ( isset( $_GET['pay_for_order'] ) && ! empty( $_GET['key'] ) ) {
213
-			$order = wc_get_order( wc_get_order_id_by_order_key( wc_clean( $_GET['key'] ) ) );
212
+		if (isset($_GET['pay_for_order']) && ! empty($_GET['key'])) {
213
+			$order = wc_get_order(wc_get_order_id_by_order_key(wc_clean($_GET['key'])));
214 214
 			$total = $order->get_total();
215 215
 		}
216 216
 
217
-		if ( is_add_payment_method_page() ) {
218
-			$pay_button_text = __( 'Add Payment', 'woocommerce-gateway-stripe' );
219
-			$total        = '';
217
+		if (is_add_payment_method_page()) {
218
+			$pay_button_text = __('Add Payment', 'woocommerce-gateway-stripe');
219
+			$total = '';
220 220
 		} else {
221 221
 			$pay_button_text = '';
222 222
 		}
223 223
 
224 224
 		echo '<div
225 225
 			id="stripe-sofort-payment-data"
226
-			data-amount="' . esc_attr( WC_Stripe_Helper::get_stripe_amount( $total ) ) . '"
227
-			data-currency="' . esc_attr( strtolower( get_woocommerce_currency() ) ) . '">';
226
+			data-amount="' . esc_attr(WC_Stripe_Helper::get_stripe_amount($total)) . '"
227
+			data-currency="' . esc_attr(strtolower(get_woocommerce_currency())) . '">';
228 228
 
229
-		if ( $this->description ) {
230
-			echo apply_filters( 'wc_stripe_description', wpautop( wp_kses_post( $this->description ) ) );
229
+		if ($this->description) {
230
+			echo apply_filters('wc_stripe_description', wpautop(wp_kses_post($this->description)));
231 231
 		}
232 232
 
233 233
 		echo '</div>';
@@ -241,28 +241,28 @@  discard block
 block discarded – undo
241 241
 	 * @param object $order
242 242
 	 * @return mixed
243 243
 	 */
244
-	public function create_source( $order ) {
244
+	public function create_source($order) {
245 245
 		$currency              = WC_Stripe_Helper::is_pre_30() ? $order->get_order_currency() : $order->get_currency();
246 246
 		$bank_country          = WC_Stripe_Helper::is_pre_30() ? $order->billing_country : $order->get_billing_country();
247
-		$return_url            = $this->get_stripe_return_url( $order );
247
+		$return_url            = $this->get_stripe_return_url($order);
248 248
 		$post_data             = array();
249
-		$post_data['amount']   = WC_Stripe_Helper::get_stripe_amount( $order->get_total(), $currency );
250
-		$post_data['currency'] = strtolower( $currency );
249
+		$post_data['amount']   = WC_Stripe_Helper::get_stripe_amount($order->get_total(), $currency);
250
+		$post_data['currency'] = strtolower($currency);
251 251
 		$post_data['type']     = 'sofort';
252
-		$post_data['owner']    = $this->get_owner_details( $order );
253
-		$post_data['redirect'] = array( 'return_url' => $return_url );
252
+		$post_data['owner']    = $this->get_owner_details($order);
253
+		$post_data['redirect'] = array('return_url' => $return_url);
254 254
 		$post_data['sofort']   = array(
255 255
 			'country'            => $bank_country,
256
-			'preferred_language' => substr( get_locale(), 0, 2 ),
256
+			'preferred_language' => substr(get_locale(), 0, 2),
257 257
 		);
258 258
 
259
-		if ( ! empty( $this->statement_descriptor ) ) {
260
-			$post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor( $this->statement_descriptor );
259
+		if ( ! empty($this->statement_descriptor)) {
260
+			$post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor($this->statement_descriptor);
261 261
 		}
262 262
 
263
-		WC_Stripe_Logger::log( 'Info: Begin creating SOFORT source' );
263
+		WC_Stripe_Logger::log('Info: Begin creating SOFORT source');
264 264
 
265
-		return WC_Stripe_API::request( apply_filters( 'wc_stripe_sofort_source', $post_data, $order ), 'sources' );
265
+		return WC_Stripe_API::request(apply_filters('wc_stripe_sofort_source', $post_data, $order), 'sources');
266 266
 	}
267 267
 
268 268
 	/**
@@ -276,59 +276,59 @@  discard block
 block discarded – undo
276 276
 	 *
277 277
 	 * @return array|void
278 278
 	 */
279
-	public function process_payment( $order_id, $retry = true, $force_save_source = false ) {
279
+	public function process_payment($order_id, $retry = true, $force_save_source = false) {
280 280
 		try {
281
-			$order = wc_get_order( $order_id );
281
+			$order = wc_get_order($order_id);
282 282
 
283 283
 			// This will throw exception if not valid.
284
-			$this->validate_minimum_order_amount( $order );
284
+			$this->validate_minimum_order_amount($order);
285 285
 
286 286
 			// This comes from the create account checkbox in the checkout page.
287
-			$create_account = ! empty( $_POST['createaccount'] ) ? true : false;
287
+			$create_account = ! empty($_POST['createaccount']) ? true : false;
288 288
 
289
-			if ( $create_account ) {
289
+			if ($create_account) {
290 290
 				$new_customer_id     = WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id();
291
-				$new_stripe_customer = new WC_Stripe_Customer( $new_customer_id );
291
+				$new_stripe_customer = new WC_Stripe_Customer($new_customer_id);
292 292
 				$new_stripe_customer->create_customer();
293 293
 			}
294 294
 
295
-			$response = $this->create_source( $order );
295
+			$response = $this->create_source($order);
296 296
 
297
-			if ( ! empty( $response->error ) ) {
298
-				$order->add_order_note( $response->error->message );
297
+			if ( ! empty($response->error)) {
298
+				$order->add_order_note($response->error->message);
299 299
 
300 300
 				$localized_messages = WC_Stripe_Helper::get_localized_messages();
301 301
 
302
-				if ( 'invalid_sofort_country' === $response->error->code ) {
303
-					$localized_message = isset( $localized_messages[ $response->error->code ] ) ? $localized_messages[ $response->error->code ] : $response->error->message;
302
+				if ('invalid_sofort_country' === $response->error->code) {
303
+					$localized_message = isset($localized_messages[$response->error->code]) ? $localized_messages[$response->error->code] : $response->error->message;
304 304
 				} else {
305
-					$localized_message = isset( $localized_messages[ $response->error->type ] ) ? $localized_messages[ $response->error->type ] : $response->error->message;
305
+					$localized_message = isset($localized_messages[$response->error->type]) ? $localized_messages[$response->error->type] : $response->error->message;
306 306
 				}
307 307
 
308
-				throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message );
308
+				throw new WC_Stripe_Exception(print_r($response, true), $localized_message);
309 309
 			}
310 310
 
311
-			if ( WC_Stripe_Helper::is_pre_30() ) {
312
-				update_post_meta( $order_id, '_stripe_source_id', $response->id );
311
+			if (WC_Stripe_Helper::is_pre_30()) {
312
+				update_post_meta($order_id, '_stripe_source_id', $response->id);
313 313
 			} else {
314
-				$order->update_meta_data( '_stripe_source_id', $response->id );
314
+				$order->update_meta_data('_stripe_source_id', $response->id);
315 315
 				$order->save();
316 316
 			}
317 317
 
318
-			WC_Stripe_Logger::log( 'Info: Redirecting to SOFORT...' );
318
+			WC_Stripe_Logger::log('Info: Redirecting to SOFORT...');
319 319
 
320 320
 			return array(
321 321
 				'result'   => 'success',
322
-				'redirect' => esc_url_raw( $response->redirect->url ),
322
+				'redirect' => esc_url_raw($response->redirect->url),
323 323
 			);
324
-		} catch ( WC_Stripe_Exception $e ) {
325
-			wc_add_notice( $e->getLocalizedMessage(), 'error' );
326
-			WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() );
324
+		} catch (WC_Stripe_Exception $e) {
325
+			wc_add_notice($e->getLocalizedMessage(), 'error');
326
+			WC_Stripe_Logger::log('Error: ' . $e->getMessage());
327 327
 
328
-			do_action( 'wc_gateway_stripe_process_payment_error', $e, $order );
328
+			do_action('wc_gateway_stripe_process_payment_error', $e, $order);
329 329
 
330
-			if ( $order->has_status( array( 'pending', 'failed' ) ) ) {
331
-				$this->send_failed_order_email( $order_id );
330
+			if ($order->has_status(array('pending', 'failed'))) {
331
+				$this->send_failed_order_email($order_id);
332 332
 			}
333 333
 
334 334
 			return array(
Please login to merge, or discard this patch.
includes/compat/class-wc-stripe-compat.php 2 patches
Doc Comments   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -314,7 +314,7 @@  discard block
 block discarded – undo
314 314
 
315 315
 	/**
316 316
 	 * Don't transfer Stripe fee/ID meta to renewal orders.
317
-	 * @param int $resubscribe_order The order created for the customer to resubscribe to the old expired/cancelled subscription
317
+	 * @param integer $renewal_order
318 318
 	 */
319 319
 	public function delete_renewal_meta( $renewal_order ) {
320 320
 		delete_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $renewal_order->id : $renewal_order->get_id() ), 'Stripe Fee' );
@@ -556,6 +556,8 @@  discard block
 block discarded – undo
556 556
 	/**
557 557
 	 * Process the pre-order
558 558
 	 * @param int $order_id
559
+	 * @param boolean $retry
560
+	 * @param boolean $force_save_source
559 561
 	 * @return array
560 562
 	 */
561 563
 	public function process_pre_order( $order_id, $retry, $force_save_source ) {
Please login to merge, or discard this patch.
Spacing   +188 added lines, -188 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) {
2
+if ( ! defined('ABSPATH')) {
3 3
 	exit;
4 4
 }
5 5
 
@@ -15,24 +15,24 @@  discard block
 block discarded – undo
15 15
 	public function __construct() {
16 16
 		parent::__construct();
17 17
 
18
-		if ( class_exists( 'WC_Subscriptions_Order' ) ) {
19
-			add_action( 'woocommerce_scheduled_subscription_payment_' . $this->id, array( $this, 'scheduled_subscription_payment' ), 10, 2 );
20
-			add_action( 'wcs_resubscribe_order_created', array( $this, 'delete_resubscribe_meta' ), 10 );
21
-			add_action( 'wcs_renewal_order_created', array( $this, 'delete_renewal_meta' ), 10 );
22
-			add_action( 'woocommerce_subscription_failing_payment_method_updated_stripe', array( $this, 'update_failing_payment_method' ), 10, 2 );
18
+		if (class_exists('WC_Subscriptions_Order')) {
19
+			add_action('woocommerce_scheduled_subscription_payment_' . $this->id, array($this, 'scheduled_subscription_payment'), 10, 2);
20
+			add_action('wcs_resubscribe_order_created', array($this, 'delete_resubscribe_meta'), 10);
21
+			add_action('wcs_renewal_order_created', array($this, 'delete_renewal_meta'), 10);
22
+			add_action('woocommerce_subscription_failing_payment_method_updated_stripe', array($this, 'update_failing_payment_method'), 10, 2);
23 23
 
24 24
 			// display the credit card used for a subscription in the "My Subscriptions" table
25
-			add_filter( 'woocommerce_my_subscriptions_payment_method', array( $this, 'maybe_render_subscription_payment_method' ), 10, 2 );
25
+			add_filter('woocommerce_my_subscriptions_payment_method', array($this, 'maybe_render_subscription_payment_method'), 10, 2);
26 26
 
27 27
 			// allow store managers to manually set Stripe as the payment method on a subscription
28
-			add_filter( 'woocommerce_subscription_payment_meta', array( $this, 'add_subscription_payment_meta' ), 10, 2 );
29
-			add_filter( 'woocommerce_subscription_validate_payment_meta', array( $this, 'validate_subscription_payment_meta' ), 10, 2 );
30
-			add_filter( 'wc_stripe_display_save_payment_method_checkbox', array( $this, 'maybe_hide_save_checkbox' ) );
31
-			add_filter( 'wc_stripe_payment_metadata', array( $this, 'add_subscription_meta_data' ), 10, 2 );
28
+			add_filter('woocommerce_subscription_payment_meta', array($this, 'add_subscription_payment_meta'), 10, 2);
29
+			add_filter('woocommerce_subscription_validate_payment_meta', array($this, 'validate_subscription_payment_meta'), 10, 2);
30
+			add_filter('wc_stripe_display_save_payment_method_checkbox', array($this, 'maybe_hide_save_checkbox'));
31
+			add_filter('wc_stripe_payment_metadata', array($this, 'add_subscription_meta_data'), 10, 2);
32 32
 		}
33 33
 
34
-		if ( class_exists( 'WC_Pre_Orders_Order' ) ) {
35
-			add_action( 'wc_pre_orders_process_pre_order_completion_payment_' . $this->id, array( $this, 'process_pre_order_release_payment' ) );
34
+		if (class_exists('WC_Pre_Orders_Order')) {
35
+			add_action('wc_pre_orders_process_pre_order_completion_payment_' . $this->id, array($this, 'process_pre_order_release_payment'));
36 36
 		}
37 37
 	}
38 38
 
@@ -43,8 +43,8 @@  discard block
 block discarded – undo
43 43
 	 * @since 4.0.0
44 44
 	 * @version 4.0.0
45 45
 	 */
46
-	public function maybe_hide_save_checkbox( $display_tokenization ) {
47
-		if ( WC_Subscriptions_Cart::cart_contains_subscription() ) {
46
+	public function maybe_hide_save_checkbox($display_tokenization) {
47
+		if (WC_Subscriptions_Cart::cart_contains_subscription()) {
48 48
 			return false;
49 49
 		}
50 50
 
@@ -56,8 +56,8 @@  discard block
 block discarded – undo
56 56
 	 * @param  int  $order_id
57 57
 	 * @return boolean
58 58
 	 */
59
-	public function has_subscription( $order_id ) {
60
-		return ( function_exists( 'wcs_order_contains_subscription' ) && ( wcs_order_contains_subscription( $order_id ) || wcs_is_subscription( $order_id ) || wcs_order_contains_renewal( $order_id ) ) );
59
+	public function has_subscription($order_id) {
60
+		return (function_exists('wcs_order_contains_subscription') && (wcs_order_contains_subscription($order_id) || wcs_is_subscription($order_id) || wcs_order_contains_renewal($order_id)));
61 61
 	}
62 62
 
63 63
 	/**
@@ -67,7 +67,7 @@  discard block
 block discarded – undo
67 67
 	 * @return bool
68 68
 	 */
69 69
 	public function is_subs_change_payment() {
70
-		return ( isset( $_GET['pay_for_order'] ) && isset( $_GET['change_payment_method'] ) );
70
+		return (isset($_GET['pay_for_order']) && isset($_GET['change_payment_method']));
71 71
 	}
72 72
 
73 73
 	/**
@@ -75,8 +75,8 @@  discard block
 block discarded – undo
75 75
 	 * @param  int  $order_id
76 76
 	 * @return boolean
77 77
 	 */
78
-	public function is_pre_order( $order_id ) {
79
-		return ( class_exists( 'WC_Pre_Orders_Order' ) && WC_Pre_Orders_Order::order_contains_pre_order( $order_id ) );
78
+	public function is_pre_order($order_id) {
79
+		return (class_exists('WC_Pre_Orders_Order') && WC_Pre_Orders_Order::order_contains_pre_order($order_id));
80 80
 	}
81 81
 
82 82
 	/**
@@ -85,26 +85,26 @@  discard block
 block discarded – undo
85 85
 	 * @since 4.0.4
86 86
 	 * @param int $order_id
87 87
 	 */
88
-	public function change_subs_payment_method( $order_id ) {
88
+	public function change_subs_payment_method($order_id) {
89 89
 		try {
90
-			$subscription    = wc_get_order( $order_id );
90
+			$subscription    = wc_get_order($order_id);
91 91
 			$source_object   = $this->get_source_object();
92
-			$prepared_source = $this->prepare_source( $source_object, get_current_user_id(), true );
92
+			$prepared_source = $this->prepare_source($source_object, get_current_user_id(), true);
93 93
 
94 94
 			// Check if we don't allow prepaid credit cards.
95
-			if ( ! apply_filters( 'wc_stripe_allow_prepaid_card', true ) ) {
96
-				if ( $source_object && 'token' === $source_object->object && 'prepaid' === $source_object->card->funding ) {
97
-					$localized_message = __( 'Sorry, we\'re not accepting prepaid cards at this time. Your credit card has not been charge. Please try with alternative payment method.', 'woocommerce-gateway-stripe' );
98
-					throw new WC_Stripe_Exception( print_r( $source_object, true ), $localized_message );
95
+			if ( ! apply_filters('wc_stripe_allow_prepaid_card', true)) {
96
+				if ($source_object && 'token' === $source_object->object && 'prepaid' === $source_object->card->funding) {
97
+					$localized_message = __('Sorry, we\'re not accepting prepaid cards at this time. Your credit card has not been charge. Please try with alternative payment method.', 'woocommerce-gateway-stripe');
98
+					throw new WC_Stripe_Exception(print_r($source_object, true), $localized_message);
99 99
 				}
100 100
 			}
101 101
 
102
-			if ( empty( $prepared_source->source ) ) {
103
-				$localized_message = __( 'Payment processing failed. Please retry.', 'woocommerce-gateway-stripe' );
104
-				throw new WC_Stripe_Exception( print_r( $prepared_source, true ), $localized_message );
102
+			if (empty($prepared_source->source)) {
103
+				$localized_message = __('Payment processing failed. Please retry.', 'woocommerce-gateway-stripe');
104
+				throw new WC_Stripe_Exception(print_r($prepared_source, true), $localized_message);
105 105
 			}
106 106
 
107
-			$this->save_source_to_order( $subscription, $prepared_source );
107
+			$this->save_source_to_order($subscription, $prepared_source);
108 108
 
109 109
 			/*
110 110
 			 * Check if card 3DS is required or optional with 3DS setting.
@@ -113,41 +113,41 @@  discard block
 block discarded – undo
113 113
 			 * Note that if we need to save source, the original source must be first
114 114
 			 * attached to a customer in Stripe before it can be charged.
115 115
 			 */
116
-			if ( $this->is_3ds_required( $source_object ) ) {
116
+			if ($this->is_3ds_required($source_object)) {
117 117
 				$order    = $subscription->get_parent();
118
-				$response = $this->create_3ds_source( $order, $source_object, $subscription->get_view_order_url() );
118
+				$response = $this->create_3ds_source($order, $source_object, $subscription->get_view_order_url());
119 119
 
120
-				if ( ! empty( $response->error ) ) {
120
+				if ( ! empty($response->error)) {
121 121
 					$localized_message = $response->error->message;
122 122
 
123
-					$order->add_order_note( $localized_message );
123
+					$order->add_order_note($localized_message);
124 124
 
125
-					throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message );
125
+					throw new WC_Stripe_Exception(print_r($response, true), $localized_message);
126 126
 				}
127 127
 
128 128
 				// Update order meta with 3DS source.
129
-				if ( WC_Stripe_Helper::is_pre_30() ) {
130
-					update_post_meta( $order_id, '_stripe_source_id', $response->id );
129
+				if (WC_Stripe_Helper::is_pre_30()) {
130
+					update_post_meta($order_id, '_stripe_source_id', $response->id);
131 131
 				} else {
132
-					$subscription->update_meta_data( '_stripe_source_id', $response->id );
132
+					$subscription->update_meta_data('_stripe_source_id', $response->id);
133 133
 					$subscription->save();
134 134
 				}
135 135
 
136
-				WC_Stripe_Logger::log( 'Info: Redirecting to 3DS...' );
136
+				WC_Stripe_Logger::log('Info: Redirecting to 3DS...');
137 137
 
138 138
 				return array(
139 139
 					'result'   => 'success',
140
-					'redirect' => esc_url_raw( $response->redirect->url ),
140
+					'redirect' => esc_url_raw($response->redirect->url),
141 141
 				);
142 142
 			}
143 143
 
144 144
 			return array(
145 145
 				'result'   => 'success',
146
-				'redirect' => $this->get_return_url( $subscription ),
146
+				'redirect' => $this->get_return_url($subscription),
147 147
 			);
148
-		} catch ( WC_Stripe_Exception $e ) {
149
-			wc_add_notice( $e->getLocalizedMessage(), 'error' );
150
-			WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() );
148
+		} catch (WC_Stripe_Exception $e) {
149
+			wc_add_notice($e->getLocalizedMessage(), 'error');
150
+			WC_Stripe_Logger::log('Error: ' . $e->getMessage());
151 151
 		}
152 152
 	}
153 153
 
@@ -156,18 +156,18 @@  discard block
 block discarded – undo
156 156
 	 * @param  int $order_id
157 157
 	 * @return array
158 158
 	 */
159
-	public function process_payment( $order_id, $retry = true, $force_save_source = false ) {
160
-		if ( $this->has_subscription( $order_id ) ) {
161
-			if ( $this->is_subs_change_payment() ) {
162
-				return $this->change_subs_payment_method( $order_id );
159
+	public function process_payment($order_id, $retry = true, $force_save_source = false) {
160
+		if ($this->has_subscription($order_id)) {
161
+			if ($this->is_subs_change_payment()) {
162
+				return $this->change_subs_payment_method($order_id);
163 163
 			}
164 164
 
165 165
 			// Regular payment with force customer enabled
166
-			return parent::process_payment( $order_id, true, true );
167
-		} elseif ( $this->is_pre_order( $order_id ) ) {
168
-			return $this->process_pre_order( $order_id, $retry, $force_save_source );
166
+			return parent::process_payment($order_id, true, true);
167
+		} elseif ($this->is_pre_order($order_id)) {
168
+			return $this->process_pre_order($order_id, $retry, $force_save_source);
169 169
 		} else {
170
-			return parent::process_payment( $order_id, $retry, $force_save_source );
170
+			return parent::process_payment($order_id, $retry, $force_save_source);
171 171
 		}
172 172
 	}
173 173
 
@@ -178,14 +178,14 @@  discard block
 block discarded – undo
178 178
 	 * @param array $metadata
179 179
 	 * @param object $order
180 180
 	 */
181
-	public function add_subscription_meta_data( $metadata, $order ) {
182
-		if ( ! $this->has_subscription( WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id() ) ) {
181
+	public function add_subscription_meta_data($metadata, $order) {
182
+		if ( ! $this->has_subscription(WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id())) {
183 183
 			return $metadata;
184 184
 		}
185 185
 
186 186
 		return $metadata += array(
187 187
 			'payment_type'   => 'recurring',
188
-			'site_url'       => esc_url( get_site_url() ),
188
+			'site_url'       => esc_url(get_site_url()),
189 189
 		);
190 190
 	}
191 191
 
@@ -195,24 +195,24 @@  discard block
 block discarded – undo
195 195
 	 * @since 3.1.0
196 196
 	 * @version 4.0.0
197 197
 	 */
198
-	public function save_source_to_order( $order, $source ) {
199
-		parent::save_source_to_order( $order, $source );
198
+	public function save_source_to_order($order, $source) {
199
+		parent::save_source_to_order($order, $source);
200 200
 
201 201
 		$order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
202 202
 
203 203
 		// Also store it on the subscriptions being purchased or paid for in the order
204
-		if ( function_exists( 'wcs_order_contains_subscription' ) && wcs_order_contains_subscription( $order_id ) ) {
205
-			$subscriptions = wcs_get_subscriptions_for_order( $order_id );
206
-		} elseif ( function_exists( 'wcs_order_contains_renewal' ) && wcs_order_contains_renewal( $order_id ) ) {
207
-			$subscriptions = wcs_get_subscriptions_for_renewal_order( $order_id );
204
+		if (function_exists('wcs_order_contains_subscription') && wcs_order_contains_subscription($order_id)) {
205
+			$subscriptions = wcs_get_subscriptions_for_order($order_id);
206
+		} elseif (function_exists('wcs_order_contains_renewal') && wcs_order_contains_renewal($order_id)) {
207
+			$subscriptions = wcs_get_subscriptions_for_renewal_order($order_id);
208 208
 		} else {
209 209
 			$subscriptions = array();
210 210
 		}
211 211
 
212
-		foreach ( $subscriptions as $subscription ) {
212
+		foreach ($subscriptions as $subscription) {
213 213
 			$subscription_id = WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id();
214
-			update_post_meta( $subscription_id, '_stripe_customer_id', $source->customer );
215
-			update_post_meta( $subscription_id, '_stripe_source_id', $source->source );
214
+			update_post_meta($subscription_id, '_stripe_customer_id', $source->customer);
215
+			update_post_meta($subscription_id, '_stripe_source_id', $source->source);
216 216
 		}
217 217
 	}
218 218
 
@@ -225,45 +225,45 @@  discard block
 block discarded – undo
225 225
 	 * @param mixed $renewal_order
226 226
 	 * @param bool $is_retry Is this a retry process.
227 227
 	 */
228
-	public function process_subscription_payment( $amount = 0.0, $renewal_order, $is_retry = false ) {
229
-		if ( $amount * 100 < WC_Stripe_Helper::get_minimum_amount() ) {
228
+	public function process_subscription_payment($amount = 0.0, $renewal_order, $is_retry = false) {
229
+		if ($amount * 100 < WC_Stripe_Helper::get_minimum_amount()) {
230 230
 			/* translators: minimum amount */
231
-			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 ) ) );
231
+			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)));
232 232
 		}
233 233
 
234 234
 		$order_id = WC_Stripe_Helper::is_pre_30() ? $renewal_order->id : $renewal_order->get_id();
235 235
 
236 236
 		// Get source from order
237
-		$prepared_source = $this->prepare_order_source( $renewal_order );
237
+		$prepared_source = $this->prepare_order_source($renewal_order);
238 238
 
239
-		if ( ! $prepared_source->customer ) {
240
-			return new WP_Error( 'stripe_error', __( 'Customer not found', 'woocommerce-gateway-stripe' ) );
239
+		if ( ! $prepared_source->customer) {
240
+			return new WP_Error('stripe_error', __('Customer not found', 'woocommerce-gateway-stripe'));
241 241
 		}
242 242
 
243
-		WC_Stripe_Logger::log( "Info: Begin processing subscription payment for order {$order_id} for the amount of {$amount}" );
243
+		WC_Stripe_Logger::log("Info: Begin processing subscription payment for order {$order_id} for the amount of {$amount}");
244 244
 
245
-		if ( $is_retry ) {
245
+		if ($is_retry) {
246 246
 			// Passing empty source with charge customer default.
247 247
 			$prepared_source->source = '';
248 248
 		}
249 249
 
250
-		$request            = $this->generate_payment_request( $renewal_order, $prepared_source );
250
+		$request            = $this->generate_payment_request($renewal_order, $prepared_source);
251 251
 		$request['capture'] = 'true';
252
-		$request['amount']  = WC_Stripe_Helper::get_stripe_amount( $amount, $request['currency'] );
253
-		$response           = WC_Stripe_API::request( $request );
252
+		$request['amount']  = WC_Stripe_Helper::get_stripe_amount($amount, $request['currency']);
253
+		$response           = WC_Stripe_API::request($request);
254 254
 
255
-		if ( ! empty( $response->error ) || is_wp_error( $response ) ) {
256
-			if ( $is_retry ) {
255
+		if ( ! empty($response->error) || is_wp_error($response)) {
256
+			if ($is_retry) {
257 257
 				/* translators: error message */
258
-				$renewal_order->update_status( 'failed', sprintf( __( 'Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe' ), $response->error->message ) );
258
+				$renewal_order->update_status('failed', sprintf(__('Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe'), $response->error->message));
259 259
 			}
260 260
 
261 261
 			return $response; // Default catch all errors.
262 262
 		}
263 263
 
264
-		$this->process_response( $response, $renewal_order );
264
+		$this->process_response($response, $renewal_order);
265 265
 
266
-		if ( ! $is_retry ) {
266
+		if ( ! $is_retry) {
267 267
 			return $response;
268 268
 		}
269 269
 	}
@@ -272,21 +272,21 @@  discard block
 block discarded – undo
272 272
 	 * Don't transfer Stripe customer/token meta to resubscribe orders.
273 273
 	 * @param int $resubscribe_order The order created for the customer to resubscribe to the old expired/cancelled subscription
274 274
 	 */
275
-	public function delete_resubscribe_meta( $resubscribe_order ) {
276
-		delete_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id() ), '_stripe_customer_id' );
277
-		delete_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id() ), '_stripe_source_id' );
275
+	public function delete_resubscribe_meta($resubscribe_order) {
276
+		delete_post_meta((WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id()), '_stripe_customer_id');
277
+		delete_post_meta((WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id()), '_stripe_source_id');
278 278
 		// For BW compat will remove in future
279
-		delete_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id() ), '_stripe_card_id' );
280
-		$this->delete_renewal_meta( $resubscribe_order );
279
+		delete_post_meta((WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id()), '_stripe_card_id');
280
+		$this->delete_renewal_meta($resubscribe_order);
281 281
 	}
282 282
 
283 283
 	/**
284 284
 	 * Don't transfer Stripe fee/ID meta to renewal orders.
285 285
 	 * @param int $resubscribe_order The order created for the customer to resubscribe to the old expired/cancelled subscription
286 286
 	 */
287
-	public function delete_renewal_meta( $renewal_order ) {
288
-		delete_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $renewal_order->id : $renewal_order->get_id() ), 'Stripe Fee' );
289
-		delete_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $renewal_order->id : $renewal_order->get_id() ), 'Net Revenue From Stripe' );
287
+	public function delete_renewal_meta($renewal_order) {
288
+		delete_post_meta((WC_Stripe_Helper::is_pre_30() ? $renewal_order->id : $renewal_order->get_id()), 'Stripe Fee');
289
+		delete_post_meta((WC_Stripe_Helper::is_pre_30() ? $renewal_order->id : $renewal_order->get_id()), 'Net Revenue From Stripe');
290 290
 		return $renewal_order;
291 291
 	}
292 292
 
@@ -296,21 +296,21 @@  discard block
 block discarded – undo
296 296
 	 * @param $amount_to_charge float The amount to charge.
297 297
 	 * @param $renewal_order WC_Order A WC_Order object created to record the renewal payment.
298 298
 	 */
299
-	public function scheduled_subscription_payment( $amount_to_charge, $renewal_order ) {
300
-		$response = $this->process_subscription_payment( $amount_to_charge, $renewal_order );
299
+	public function scheduled_subscription_payment($amount_to_charge, $renewal_order) {
300
+		$response = $this->process_subscription_payment($amount_to_charge, $renewal_order);
301 301
 
302
-		if ( is_wp_error( $response ) ) {
302
+		if (is_wp_error($response)) {
303 303
 			/* translators: error message */
304
-			$renewal_order->update_status( 'failed', sprintf( __( 'Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe' ), $response->get_error_message() ) );
304
+			$renewal_order->update_status('failed', sprintf(__('Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe'), $response->get_error_message()));
305 305
 		}
306 306
 
307
-		if ( ! empty( $response->error ) ) {
307
+		if ( ! empty($response->error)) {
308 308
 			// This is a very generic error to listen for but worth a retry before total fail.
309
-			if ( isset( $response->error->type ) && 'invalid_request_error' === $response->error->type && apply_filters( 'wc_stripe_use_default_customer_source', true ) ) {
310
-				$this->process_subscription_payment( $amount_to_charge, $renewal_order, true );
309
+			if (isset($response->error->type) && 'invalid_request_error' === $response->error->type && apply_filters('wc_stripe_use_default_customer_source', true)) {
310
+				$this->process_subscription_payment($amount_to_charge, $renewal_order, true);
311 311
 			} else {
312 312
 				/* translators: error message */
313
-				$renewal_order->update_status( 'failed', sprintf( __( 'Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe' ), $response->error->message ) );
313
+				$renewal_order->update_status('failed', sprintf(__('Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe'), $response->error->message));
314 314
 			}
315 315
 		}
316 316
 	}
@@ -319,20 +319,20 @@  discard block
 block discarded – undo
319 319
 	 * Remove order meta
320 320
 	 * @param object $order
321 321
 	 */
322
-	public function remove_order_source_before_retry( $order ) {
322
+	public function remove_order_source_before_retry($order) {
323 323
 		$order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
324
-		delete_post_meta( $order_id, '_stripe_source_id' );
324
+		delete_post_meta($order_id, '_stripe_source_id');
325 325
 		// For BW compat will remove in the future.
326
-		delete_post_meta( $order_id, '_stripe_card_id' );
326
+		delete_post_meta($order_id, '_stripe_card_id');
327 327
 	}
328 328
 
329 329
 	/**
330 330
 	 * Remove order meta
331 331
 	 * @param  object $order
332 332
 	 */
333
-	public function remove_order_customer_before_retry( $order ) {
333
+	public function remove_order_customer_before_retry($order) {
334 334
 		$order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
335
-		delete_post_meta( $order_id, '_stripe_customer_id' );
335
+		delete_post_meta($order_id, '_stripe_customer_id');
336 336
 	}
337 337
 
338 338
 	/**
@@ -344,14 +344,14 @@  discard block
 block discarded – undo
344 344
 	 * @param WC_Order $renewal_order The order which recorded the successful payment (to make up for the failed automatic payment).
345 345
 	 * @return void
346 346
 	 */
347
-	public function update_failing_payment_method( $subscription, $renewal_order ) {
348
-		if ( WC_Stripe_Helper::is_pre_30() ) {
349
-			update_post_meta( $subscription->id, '_stripe_customer_id', $renewal_order->stripe_customer_id );
350
-			update_post_meta( $subscription->id, '_stripe_source_id', $renewal_order->stripe_source_id );
347
+	public function update_failing_payment_method($subscription, $renewal_order) {
348
+		if (WC_Stripe_Helper::is_pre_30()) {
349
+			update_post_meta($subscription->id, '_stripe_customer_id', $renewal_order->stripe_customer_id);
350
+			update_post_meta($subscription->id, '_stripe_source_id', $renewal_order->stripe_source_id);
351 351
 
352 352
 		} else {
353
-			update_post_meta( $subscription->get_id(), '_stripe_customer_id', $renewal_order->get_meta( '_stripe_customer_id', true ) );
354
-			update_post_meta( $subscription->get_id(), '_stripe_source_id', $renewal_order->get_meta( '_stripe_source_id', true ) );
353
+			update_post_meta($subscription->get_id(), '_stripe_customer_id', $renewal_order->get_meta('_stripe_customer_id', true));
354
+			update_post_meta($subscription->get_id(), '_stripe_source_id', $renewal_order->get_meta('_stripe_source_id', true));
355 355
 		}
356 356
 	}
357 357
 
@@ -364,21 +364,21 @@  discard block
 block discarded – undo
364 364
 	 * @param WC_Subscription $subscription An instance of a subscription object
365 365
 	 * @return array
366 366
 	 */
367
-	public function add_subscription_payment_meta( $payment_meta, $subscription ) {
368
-		$source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_source_id', true );
367
+	public function add_subscription_payment_meta($payment_meta, $subscription) {
368
+		$source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_source_id', true);
369 369
 
370 370
 		// For BW compat will remove in future.
371
-		if ( empty( $source_id ) ) {
372
-			$source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_card_id', true );
371
+		if (empty($source_id)) {
372
+			$source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_card_id', true);
373 373
 
374 374
 			// Take this opportunity to update the key name.
375
-			WC_Stripe_Helper::is_pre_30() ? update_post_meta( $subscription->id, '_stripe_source_id', $source_id ) : update_post_meta( $subscription->get_id(), '_stripe_source_id', $source_id );
375
+			WC_Stripe_Helper::is_pre_30() ? update_post_meta($subscription->id, '_stripe_source_id', $source_id) : update_post_meta($subscription->get_id(), '_stripe_source_id', $source_id);
376 376
 		}
377 377
 
378
-		$payment_meta[ $this->id ] = array(
378
+		$payment_meta[$this->id] = array(
379 379
 			'post_meta' => array(
380 380
 				'_stripe_customer_id' => array(
381
-					'value' => get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_customer_id', true ),
381
+					'value' => get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_customer_id', true),
382 382
 					'label' => 'Stripe Customer ID',
383 383
 				),
384 384
 				'_stripe_source_id' => array(
@@ -401,22 +401,22 @@  discard block
 block discarded – undo
401 401
 	 * @param array $payment_meta associative array of meta data required for automatic payments
402 402
 	 * @return array
403 403
 	 */
404
-	public function validate_subscription_payment_meta( $payment_method_id, $payment_meta ) {
405
-		if ( $this->id === $payment_method_id ) {
404
+	public function validate_subscription_payment_meta($payment_method_id, $payment_meta) {
405
+		if ($this->id === $payment_method_id) {
406 406
 
407
-			if ( ! isset( $payment_meta['post_meta']['_stripe_customer_id']['value'] ) || empty( $payment_meta['post_meta']['_stripe_customer_id']['value'] ) ) {
408
-				throw new Exception( __( 'A "Stripe Customer ID" value is required.', 'woocommerce-gateway-stripe' ) );
409
-			} elseif ( 0 !== strpos( $payment_meta['post_meta']['_stripe_customer_id']['value'], 'cus_' ) ) {
410
-				throw new Exception( __( 'Invalid customer ID. A valid "Stripe Customer ID" must begin with "cus_".', 'woocommerce-gateway-stripe' ) );
407
+			if ( ! isset($payment_meta['post_meta']['_stripe_customer_id']['value']) || empty($payment_meta['post_meta']['_stripe_customer_id']['value'])) {
408
+				throw new Exception(__('A "Stripe Customer ID" value is required.', 'woocommerce-gateway-stripe'));
409
+			} elseif (0 !== strpos($payment_meta['post_meta']['_stripe_customer_id']['value'], 'cus_')) {
410
+				throw new Exception(__('Invalid customer ID. A valid "Stripe Customer ID" must begin with "cus_".', 'woocommerce-gateway-stripe'));
411 411
 			}
412 412
 
413 413
 			if (
414
-				( ! empty( $payment_meta['post_meta']['_stripe_source_id']['value'] )
415
-				&& 0 !== strpos( $payment_meta['post_meta']['_stripe_source_id']['value'], 'card_' ) )
416
-				&& ( ! empty( $payment_meta['post_meta']['_stripe_source_id']['value'] )
417
-				&& 0 !== strpos( $payment_meta['post_meta']['_stripe_source_id']['value'], 'src_' ) ) ) {
414
+				( ! empty($payment_meta['post_meta']['_stripe_source_id']['value'])
415
+				&& 0 !== strpos($payment_meta['post_meta']['_stripe_source_id']['value'], 'card_'))
416
+				&& ( ! empty($payment_meta['post_meta']['_stripe_source_id']['value'])
417
+				&& 0 !== strpos($payment_meta['post_meta']['_stripe_source_id']['value'], 'src_')) ) {
418 418
 
419
-				throw new Exception( __( 'Invalid source ID. A valid source "Stripe Source ID" must begin with "src_" or "card_".', 'woocommerce-gateway-stripe' ) );
419
+				throw new Exception(__('Invalid source ID. A valid source "Stripe Source ID" must begin with "src_" or "card_".', 'woocommerce-gateway-stripe'));
420 420
 			}
421 421
 		}
422 422
 	}
@@ -429,91 +429,91 @@  discard block
 block discarded – undo
429 429
 	 * @param WC_Subscription $subscription the subscription details
430 430
 	 * @return string the subscription payment method
431 431
 	 */
432
-	public function maybe_render_subscription_payment_method( $payment_method_to_display, $subscription ) {
432
+	public function maybe_render_subscription_payment_method($payment_method_to_display, $subscription) {
433 433
 		$customer_user = WC_Stripe_Helper::is_pre_30() ? $subscription->customer_user : $subscription->get_customer_id();
434 434
 
435 435
 		// bail for other payment methods
436
-		if ( ( WC_Stripe_Helper::is_pre_30() ? $subscription->payment_method : $subscription->get_payment_method() ) !== $this->id || ! $customer_user ) {
436
+		if ((WC_Stripe_Helper::is_pre_30() ? $subscription->payment_method : $subscription->get_payment_method()) !== $this->id || ! $customer_user) {
437 437
 			return $payment_method_to_display;
438 438
 		}
439 439
 
440
-		$stripe_source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_source_id', true );
440
+		$stripe_source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_source_id', true);
441 441
 
442 442
 		// For BW compat will remove in future.
443
-		if ( empty( $stripe_source_id ) ) {
444
-			$stripe_source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_card_id', true );
443
+		if (empty($stripe_source_id)) {
444
+			$stripe_source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_card_id', true);
445 445
 
446 446
 			// Take this opportunity to update the key name.
447
-			WC_Stripe_Helper::is_pre_30() ? update_post_meta( $subscription->id, '_stripe_source_id', $stripe_source_id ) : update_post_meta( $subscription->get_id(), '_stripe_source_id', $stripe_source_id );
447
+			WC_Stripe_Helper::is_pre_30() ? update_post_meta($subscription->id, '_stripe_source_id', $stripe_source_id) : update_post_meta($subscription->get_id(), '_stripe_source_id', $stripe_source_id);
448 448
 		}
449 449
 
450 450
 		$stripe_customer    = new WC_Stripe_Customer();
451
-		$stripe_customer_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_customer_id', true );
451
+		$stripe_customer_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_customer_id', true);
452 452
 
453 453
 		// If we couldn't find a Stripe customer linked to the subscription, fallback to the user meta data.
454
-		if ( ! $stripe_customer_id || ! is_string( $stripe_customer_id ) ) {
454
+		if ( ! $stripe_customer_id || ! is_string($stripe_customer_id)) {
455 455
 			$user_id            = $customer_user;
456
-			$stripe_customer_id = get_user_meta( $user_id, '_stripe_customer_id', true );
457
-			$stripe_source_id   = get_user_meta( $user_id, '_stripe_source_id', true );
456
+			$stripe_customer_id = get_user_meta($user_id, '_stripe_customer_id', true);
457
+			$stripe_source_id   = get_user_meta($user_id, '_stripe_source_id', true);
458 458
 
459 459
 			// For BW compat will remove in future.
460
-			if ( empty( $stripe_source_id ) ) {
461
-				$stripe_source_id = get_user_meta( $user_id, '_stripe_card_id', true );
460
+			if (empty($stripe_source_id)) {
461
+				$stripe_source_id = get_user_meta($user_id, '_stripe_card_id', true);
462 462
 
463 463
 				// Take this opportunity to update the key name.
464
-				update_user_meta( $user_id, '_stripe_source_id', $stripe_source_id );
464
+				update_user_meta($user_id, '_stripe_source_id', $stripe_source_id);
465 465
 			}
466 466
 		}
467 467
 
468 468
 		// If we couldn't find a Stripe customer linked to the account, fallback to the order meta data.
469
-		if ( ( ! $stripe_customer_id || ! is_string( $stripe_customer_id ) ) && false !== $subscription->order ) {
470
-			$stripe_customer_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id() ), '_stripe_customer_id', true );
471
-			$stripe_source_id   = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id() ), '_stripe_source_id', true );
469
+		if (( ! $stripe_customer_id || ! is_string($stripe_customer_id)) && false !== $subscription->order) {
470
+			$stripe_customer_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id()), '_stripe_customer_id', true);
471
+			$stripe_source_id   = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id()), '_stripe_source_id', true);
472 472
 
473 473
 			// For BW compat will remove in future.
474
-			if ( empty( $stripe_source_id ) ) {
475
-				$stripe_source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id() ), '_stripe_card_id', true );
474
+			if (empty($stripe_source_id)) {
475
+				$stripe_source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id()), '_stripe_card_id', true);
476 476
 
477 477
 				// Take this opportunity to update the key name.
478
-				WC_Stripe_Helper::is_pre_30() ? update_post_meta( $subscription->order->id, '_stripe_source_id', $stripe_source_id ) : update_post_meta( $subscription->get_parent_id(), '_stripe_source_id', $stripe_source_id );
478
+				WC_Stripe_Helper::is_pre_30() ? update_post_meta($subscription->order->id, '_stripe_source_id', $stripe_source_id) : update_post_meta($subscription->get_parent_id(), '_stripe_source_id', $stripe_source_id);
479 479
 			}
480 480
 		}
481 481
 
482
-		$stripe_customer->set_id( $stripe_customer_id );
482
+		$stripe_customer->set_id($stripe_customer_id);
483 483
 		$sources = $stripe_customer->get_sources();
484 484
 
485
-		if ( $sources ) {
485
+		if ($sources) {
486 486
 			$found_source = false;
487
-			foreach ( $sources as $source ) {
488
-				if ( isset( $source->type ) && 'card' === $source->type ) {
487
+			foreach ($sources as $source) {
488
+				if (isset($source->type) && 'card' === $source->type) {
489 489
 					$card = $source->card;
490
-				} elseif ( isset( $source->object ) && 'card' === $source->object ) {
490
+				} elseif (isset($source->object) && 'card' === $source->object) {
491 491
 					$card = $source;
492 492
 				}
493 493
 
494
-				if ( $source->id === $stripe_source_id ) {
494
+				if ($source->id === $stripe_source_id) {
495 495
 					$found_source = true;
496 496
 
497
-					if ( $card ) {
497
+					if ($card) {
498 498
 						/* translators: 1) card brand 2) last 4 digits */
499
-						$payment_method_to_display = sprintf( __( 'Via %1$s card ending in %2$s', 'woocommerce-gateway-stripe' ), ( isset( $card->brand ) ? $card->brand : __( 'N/A', 'woocommerce-gateway-stripe' ) ), $card->last4 );
499
+						$payment_method_to_display = sprintf(__('Via %1$s card ending in %2$s', 'woocommerce-gateway-stripe'), (isset($card->brand) ? $card->brand : __('N/A', 'woocommerce-gateway-stripe')), $card->last4);
500 500
 					} else {
501
-						$payment_method_to_display = __( 'N/A', 'woocommerce-gateway-stripe' );
501
+						$payment_method_to_display = __('N/A', 'woocommerce-gateway-stripe');
502 502
 					}
503 503
 					break;
504 504
 				}
505 505
 			}
506 506
 
507
-			if ( ! $found_source ) {
508
-				if ( 'card' === $sources[0]->type ) {
507
+			if ( ! $found_source) {
508
+				if ('card' === $sources[0]->type) {
509 509
 					$card = $sources[0]->card;
510 510
 				}
511 511
 
512
-				if ( $card ) {
512
+				if ($card) {
513 513
 					/* translators: 1) card brand 2) last 4 digits */
514
-					$payment_method_to_display = sprintf( __( 'Via %1$s card ending in %2$s', 'woocommerce-gateway-stripe' ), ( isset( $card->brand ) ? $card->brand : __( 'N/A', 'woocommerce-gateway-stripe' ) ), $card->last4 );
514
+					$payment_method_to_display = sprintf(__('Via %1$s card ending in %2$s', 'woocommerce-gateway-stripe'), (isset($card->brand) ? $card->brand : __('N/A', 'woocommerce-gateway-stripe')), $card->last4);
515 515
 				} else {
516
-					$payment_method_to_display = __( 'N/A', 'woocommerce-gateway-stripe' );
516
+					$payment_method_to_display = __('N/A', 'woocommerce-gateway-stripe');
517 517
 				}
518 518
 			}
519 519
 		}
@@ -526,42 +526,42 @@  discard block
 block discarded – undo
526 526
 	 * @param int $order_id
527 527
 	 * @return array
528 528
 	 */
529
-	public function process_pre_order( $order_id, $retry, $force_save_source ) {
530
-		if ( WC_Pre_Orders_Order::order_requires_payment_tokenization( $order_id ) ) {
529
+	public function process_pre_order($order_id, $retry, $force_save_source) {
530
+		if (WC_Pre_Orders_Order::order_requires_payment_tokenization($order_id)) {
531 531
 			try {
532
-				$order = wc_get_order( $order_id );
532
+				$order = wc_get_order($order_id);
533 533
 
534
-				if ( $order->get_total() * 100 < WC_Stripe_Helper::get_minimum_amount() ) {
534
+				if ($order->get_total() * 100 < WC_Stripe_Helper::get_minimum_amount()) {
535 535
 					/* translators: minimum amount */
536
-					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 ) ) );
536
+					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)));
537 537
 				}
538 538
 
539
-				$source = $this->prepare_source( $this->get_source_object(), get_current_user_id(), true );
539
+				$source = $this->prepare_source($this->get_source_object(), get_current_user_id(), true);
540 540
 
541 541
 				// We need a source on file to continue.
542
-				if ( empty( $source->customer ) || empty( $source->source ) ) {
543
-					throw new Exception( __( 'Unable to store payment details. Please try again.', 'woocommerce-gateway-stripe' ) );
542
+				if (empty($source->customer) || empty($source->source)) {
543
+					throw new Exception(__('Unable to store payment details. Please try again.', 'woocommerce-gateway-stripe'));
544 544
 				}
545 545
 
546
-				$this->save_source_to_order( $order, $source );
546
+				$this->save_source_to_order($order, $source);
547 547
 
548 548
 				// Remove cart
549 549
 				WC()->cart->empty_cart();
550 550
 
551 551
 				// Is pre ordered!
552
-				WC_Pre_Orders_Order::mark_order_as_pre_ordered( $order );
552
+				WC_Pre_Orders_Order::mark_order_as_pre_ordered($order);
553 553
 
554 554
 				// Return thank you page redirect
555 555
 				return array(
556 556
 					'result'   => 'success',
557
-					'redirect' => $this->get_return_url( $order ),
557
+					'redirect' => $this->get_return_url($order),
558 558
 				);
559
-			} catch ( Exception $e ) {
560
-				wc_add_notice( $e->getMessage(), 'error' );
559
+			} catch (Exception $e) {
560
+				wc_add_notice($e->getMessage(), 'error');
561 561
 				return;
562 562
 			}
563 563
 		} else {
564
-			return parent::process_payment( $order_id, $retry, $force_save_source );
564
+			return parent::process_payment($order_id, $retry, $force_save_source);
565 565
 		}
566 566
 	}
567 567
 
@@ -570,7 +570,7 @@  discard block
 block discarded – undo
570 570
 	 * @param WC_Order $order
571 571
 	 * @return void
572 572
 	 */
573
-	public function process_pre_order_release_payment( $order ) {
573
+	public function process_pre_order_release_payment($order) {
574 574
 		try {
575 575
 			// Define some callbacks if the first attempt fails.
576 576
 			$retry_callbacks = array(
@@ -578,33 +578,33 @@  discard block
 block discarded – undo
578 578
 				'remove_order_customer_before_retry',
579 579
 			);
580 580
 
581
-			while ( 1 ) {
582
-				$source   = $this->prepare_order_source( $order );
583
-				$response = WC_Stripe_API::request( $this->generate_payment_request( $order, $source ) );
581
+			while (1) {
582
+				$source   = $this->prepare_order_source($order);
583
+				$response = WC_Stripe_API::request($this->generate_payment_request($order, $source));
584 584
 
585
-				if ( ! empty( $response->error ) ) {
586
-					if ( 0 === sizeof( $retry_callbacks ) ) {
587
-						throw new Exception( $response->error->message );
585
+				if ( ! empty($response->error)) {
586
+					if (0 === sizeof($retry_callbacks)) {
587
+						throw new Exception($response->error->message);
588 588
 					} else {
589
-						$retry_callback = array_shift( $retry_callbacks );
590
-						call_user_func( array( $this, $retry_callback ), $order );
589
+						$retry_callback = array_shift($retry_callbacks);
590
+						call_user_func(array($this, $retry_callback), $order);
591 591
 					}
592 592
 				} else {
593 593
 					// Successful
594
-					$this->process_response( $response, $order );
594
+					$this->process_response($response, $order);
595 595
 					break;
596 596
 				}
597 597
 			}
598
-		} catch ( Exception $e ) {
598
+		} catch (Exception $e) {
599 599
 			/* translators: error message */
600
-			$order_note = sprintf( __( 'Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe' ), $e->getMessage() );
600
+			$order_note = sprintf(__('Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe'), $e->getMessage());
601 601
 
602 602
 			// Mark order as failed if not already set,
603 603
 			// otherwise, make sure we add the order note so we can detect when someone fails to check out multiple times
604
-			if ( ! $order->has_status( 'failed' ) ) {
605
-				$order->update_status( 'failed', $order_note );
604
+			if ( ! $order->has_status('failed')) {
605
+				$order->update_status('failed', $order_note);
606 606
 			} else {
607
-				$order->add_order_note( $order_note );
607
+				$order->add_order_note($order_note);
608 608
 			}
609 609
 		}
610 610
 	}
Please login to merge, or discard this patch.
includes/compat/class-wc-stripe-sepa-compat.php 2 patches
Doc Comments   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -314,7 +314,7 @@  discard block
 block discarded – undo
314 314
 
315 315
 	/**
316 316
 	 * Don't transfer Stripe fee/ID meta to renewal orders.
317
-	 * @param int $resubscribe_order The order created for the customer to resubscribe to the old expired/cancelled subscription
317
+	 * @param integer $renewal_order
318 318
 	 */
319 319
 	public function delete_renewal_meta( $renewal_order ) {
320 320
 		delete_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $renewal_order->id : $renewal_order->get_id() ), 'Stripe Fee' );
@@ -556,6 +556,8 @@  discard block
 block discarded – undo
556 556
 	/**
557 557
 	 * Process the pre-order
558 558
 	 * @param int $order_id
559
+	 * @param boolean $retry
560
+	 * @param boolean $force_save_source
559 561
 	 * @return array
560 562
 	 */
561 563
 	public function process_pre_order( $order_id, $retry, $force_save_source ) {
Please login to merge, or discard this patch.
Spacing   +160 added lines, -160 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) {
2
+if ( ! defined('ABSPATH')) {
3 3
 	exit;
4 4
 }
5 5
 
@@ -15,24 +15,24 @@  discard block
 block discarded – undo
15 15
 	public function __construct() {
16 16
 		parent::__construct();
17 17
 
18
-		if ( class_exists( 'WC_Subscriptions_Order' ) ) {
19
-			add_action( 'woocommerce_scheduled_subscription_payment_' . $this->id, array( $this, 'scheduled_subscription_payment' ), 10, 2 );
20
-			add_action( 'wcs_resubscribe_order_created', array( $this, 'delete_resubscribe_meta' ), 10 );
21
-			add_action( 'wcs_renewal_order_created', array( $this, 'delete_renewal_meta' ), 10 );
22
-			add_action( 'woocommerce_subscription_failing_payment_method_updated_stripe', array( $this, 'update_failing_payment_method' ), 10, 2 );
18
+		if (class_exists('WC_Subscriptions_Order')) {
19
+			add_action('woocommerce_scheduled_subscription_payment_' . $this->id, array($this, 'scheduled_subscription_payment'), 10, 2);
20
+			add_action('wcs_resubscribe_order_created', array($this, 'delete_resubscribe_meta'), 10);
21
+			add_action('wcs_renewal_order_created', array($this, 'delete_renewal_meta'), 10);
22
+			add_action('woocommerce_subscription_failing_payment_method_updated_stripe', array($this, 'update_failing_payment_method'), 10, 2);
23 23
 
24 24
 			// display the credit card used for a subscription in the "My Subscriptions" table
25
-			add_filter( 'woocommerce_my_subscriptions_payment_method', array( $this, 'maybe_render_subscription_payment_method' ), 10, 2 );
25
+			add_filter('woocommerce_my_subscriptions_payment_method', array($this, 'maybe_render_subscription_payment_method'), 10, 2);
26 26
 
27 27
 			// allow store managers to manually set Stripe as the payment method on a subscription
28
-			add_filter( 'woocommerce_subscription_payment_meta', array( $this, 'add_subscription_payment_meta' ), 10, 2 );
29
-			add_filter( 'woocommerce_subscription_validate_payment_meta', array( $this, 'validate_subscription_payment_meta' ), 10, 2 );
30
-			add_filter( 'wc_stripe_display_save_payment_method_checkbox', array( $this, 'maybe_hide_save_checkbox' ) );
31
-			add_filter( 'wc_stripe_payment_metadata', array( $this, 'add_subscription_meta_data' ), 10, 2 );
28
+			add_filter('woocommerce_subscription_payment_meta', array($this, 'add_subscription_payment_meta'), 10, 2);
29
+			add_filter('woocommerce_subscription_validate_payment_meta', array($this, 'validate_subscription_payment_meta'), 10, 2);
30
+			add_filter('wc_stripe_display_save_payment_method_checkbox', array($this, 'maybe_hide_save_checkbox'));
31
+			add_filter('wc_stripe_payment_metadata', array($this, 'add_subscription_meta_data'), 10, 2);
32 32
 		}
33 33
 
34
-		if ( class_exists( 'WC_Pre_Orders_Order' ) ) {
35
-			add_action( 'wc_pre_orders_process_pre_order_completion_payment_' . $this->id, array( $this, 'process_pre_order_release_payment' ) );
34
+		if (class_exists('WC_Pre_Orders_Order')) {
35
+			add_action('wc_pre_orders_process_pre_order_completion_payment_' . $this->id, array($this, 'process_pre_order_release_payment'));
36 36
 		}
37 37
 	}
38 38
 
@@ -43,8 +43,8 @@  discard block
 block discarded – undo
43 43
 	 * @since 4.0.0
44 44
 	 * @version 4.0.0
45 45
 	 */
46
-	public function maybe_hide_save_checkbox( $display_tokenization ) {
47
-		if ( WC_Subscriptions_Cart::cart_contains_subscription() ) {
46
+	public function maybe_hide_save_checkbox($display_tokenization) {
47
+		if (WC_Subscriptions_Cart::cart_contains_subscription()) {
48 48
 			return false;
49 49
 		}
50 50
 
@@ -56,8 +56,8 @@  discard block
 block discarded – undo
56 56
 	 * @param  int  $order_id
57 57
 	 * @return boolean
58 58
 	 */
59
-	public function has_subscription( $order_id ) {
60
-		return ( function_exists( 'wcs_order_contains_subscription' ) && ( wcs_order_contains_subscription( $order_id ) || wcs_is_subscription( $order_id ) || wcs_order_contains_renewal( $order_id ) ) );
59
+	public function has_subscription($order_id) {
60
+		return (function_exists('wcs_order_contains_subscription') && (wcs_order_contains_subscription($order_id) || wcs_is_subscription($order_id) || wcs_order_contains_renewal($order_id)));
61 61
 	}
62 62
 
63 63
 	/**
@@ -65,8 +65,8 @@  discard block
 block discarded – undo
65 65
 	 * @param  int  $order_id
66 66
 	 * @return boolean
67 67
 	 */
68
-	protected function is_pre_order( $order_id ) {
69
-		return ( class_exists( 'WC_Pre_Orders_Order' ) && WC_Pre_Orders_Order::order_contains_pre_order( $order_id ) );
68
+	protected function is_pre_order($order_id) {
69
+		return (class_exists('WC_Pre_Orders_Order') && WC_Pre_Orders_Order::order_contains_pre_order($order_id));
70 70
 	}
71 71
 
72 72
 	/**
@@ -74,14 +74,14 @@  discard block
 block discarded – undo
74 74
 	 * @param  int $order_id
75 75
 	 * @return array
76 76
 	 */
77
-	public function process_payment( $order_id, $retry = true, $force_save_source = false ) {
78
-		if ( $this->has_subscription( $order_id ) ) {
77
+	public function process_payment($order_id, $retry = true, $force_save_source = false) {
78
+		if ($this->has_subscription($order_id)) {
79 79
 			// Regular payment with force customer enabled
80
-			return parent::process_payment( $order_id, true, true );
81
-		} elseif ( $this->is_pre_order( $order_id ) ) {
82
-			return $this->process_pre_order( $order_id, $retry, $force_save_source );
80
+			return parent::process_payment($order_id, true, true);
81
+		} elseif ($this->is_pre_order($order_id)) {
82
+			return $this->process_pre_order($order_id, $retry, $force_save_source);
83 83
 		} else {
84
-			return parent::process_payment( $order_id, $retry, $force_save_source );
84
+			return parent::process_payment($order_id, $retry, $force_save_source);
85 85
 		}
86 86
 	}
87 87
 
@@ -92,14 +92,14 @@  discard block
 block discarded – undo
92 92
 	 * @param array $metadata
93 93
 	 * @param object $order
94 94
 	 */
95
-	public function add_subscription_meta_data( $metadata, $order ) {
96
-		if ( ! $this->has_subscription( WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id() ) ) {
95
+	public function add_subscription_meta_data($metadata, $order) {
96
+		if ( ! $this->has_subscription(WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id())) {
97 97
 			return $metadata;
98 98
 		}
99 99
 
100 100
 		return $metadata += array(
101 101
 			'payment_type'   => 'recurring',
102
-			'site_url'       => esc_url( get_site_url() ),
102
+			'site_url'       => esc_url(get_site_url()),
103 103
 		);
104 104
 	}
105 105
 
@@ -109,24 +109,24 @@  discard block
 block discarded – undo
109 109
 	 * @since 3.1.0
110 110
 	 * @version 4.0.0
111 111
 	 */
112
-	public function save_source_to_order( $order, $source ) {
113
-		parent::save_source_to_order( $order, $source );
112
+	public function save_source_to_order($order, $source) {
113
+		parent::save_source_to_order($order, $source);
114 114
 
115
-		$order_id  = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
115
+		$order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
116 116
 
117 117
 		// Also store it on the subscriptions being purchased or paid for in the order
118
-		if ( function_exists( 'wcs_order_contains_subscription' ) && wcs_order_contains_subscription( $order_id ) ) {
119
-			$subscriptions = wcs_get_subscriptions_for_order( $order_id );
120
-		} elseif ( function_exists( 'wcs_order_contains_renewal' ) && wcs_order_contains_renewal( $order_id ) ) {
121
-			$subscriptions = wcs_get_subscriptions_for_renewal_order( $order_id );
118
+		if (function_exists('wcs_order_contains_subscription') && wcs_order_contains_subscription($order_id)) {
119
+			$subscriptions = wcs_get_subscriptions_for_order($order_id);
120
+		} elseif (function_exists('wcs_order_contains_renewal') && wcs_order_contains_renewal($order_id)) {
121
+			$subscriptions = wcs_get_subscriptions_for_renewal_order($order_id);
122 122
 		} else {
123 123
 			$subscriptions = array();
124 124
 		}
125 125
 
126
-		foreach ( $subscriptions as $subscription ) {
126
+		foreach ($subscriptions as $subscription) {
127 127
 			$subscription_id = WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id();
128
-			update_post_meta( $subscription_id, '_stripe_customer_id', $source->customer );
129
-			update_post_meta( $subscription_id, '_stripe_source_id', $source->source );
128
+			update_post_meta($subscription_id, '_stripe_customer_id', $source->customer);
129
+			update_post_meta($subscription_id, '_stripe_source_id', $source->source);
130 130
 		}
131 131
 	}
132 132
 
@@ -139,45 +139,45 @@  discard block
 block discarded – undo
139 139
 	 * @param mixed $renewal_order
140 140
 	 * @param bool $is_retry Is this a retry process.
141 141
 	 */
142
-	public function process_subscription_payment( $amount = 0.0, $renewal_order, $is_retry = false ) {
143
-		if ( $amount * 100 < WC_Stripe_Helper::get_minimum_amount() ) {
142
+	public function process_subscription_payment($amount = 0.0, $renewal_order, $is_retry = false) {
143
+		if ($amount * 100 < WC_Stripe_Helper::get_minimum_amount()) {
144 144
 			/* translators: minimum amount */
145
-			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 ) ) );
145
+			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)));
146 146
 		}
147 147
 
148 148
 		$order_id = WC_Stripe_Helper::is_pre_30() ? $renewal_order->id : $renewal_order->get_id();
149 149
 
150 150
 		// Get source from order
151
-		$prepared_source = $this->prepare_order_source( $renewal_order );
151
+		$prepared_source = $this->prepare_order_source($renewal_order);
152 152
 
153
-		if ( ! $prepared_source->customer ) {
154
-			return new WP_Error( 'stripe_error', __( 'Customer not found', 'woocommerce-gateway-stripe' ) );
153
+		if ( ! $prepared_source->customer) {
154
+			return new WP_Error('stripe_error', __('Customer not found', 'woocommerce-gateway-stripe'));
155 155
 		}
156 156
 
157
-		WC_Stripe_Logger::log( "Info: Begin processing subscription payment for order {$order_id} for the amount of {$amount}" );
157
+		WC_Stripe_Logger::log("Info: Begin processing subscription payment for order {$order_id} for the amount of {$amount}");
158 158
 
159
-		if ( $is_retry ) {
159
+		if ($is_retry) {
160 160
 			// Passing empty source with charge customer default.
161 161
 			$prepared_source->source = '';
162 162
 		}
163 163
 
164
-		$request            = $this->generate_payment_request( $renewal_order, $prepared_source );
164
+		$request            = $this->generate_payment_request($renewal_order, $prepared_source);
165 165
 		$request['capture'] = 'true';
166
-		$request['amount']  = WC_Stripe_Helper::get_stripe_amount( $amount, $request['currency'] );
167
-		$response           = WC_Stripe_API::request( $request );
166
+		$request['amount']  = WC_Stripe_Helper::get_stripe_amount($amount, $request['currency']);
167
+		$response           = WC_Stripe_API::request($request);
168 168
 
169
-		if ( ! empty( $response->error ) || is_wp_error( $response ) ) {
170
-			if ( $is_retry ) {
169
+		if ( ! empty($response->error) || is_wp_error($response)) {
170
+			if ($is_retry) {
171 171
 				/* translators: error message */
172
-				$renewal_order->update_status( 'failed', sprintf( __( 'Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe' ), $response->error->message ) );
172
+				$renewal_order->update_status('failed', sprintf(__('Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe'), $response->error->message));
173 173
 			}
174 174
 
175 175
 			return $response; // Default catch all errors.
176 176
 		}
177 177
 
178
-		$this->process_response( $response, $renewal_order );
178
+		$this->process_response($response, $renewal_order);
179 179
 
180
-		if ( ! $is_retry ) {
180
+		if ( ! $is_retry) {
181 181
 			return $response;
182 182
 		}
183 183
 	}
@@ -186,21 +186,21 @@  discard block
 block discarded – undo
186 186
 	 * Don't transfer Stripe customer/token meta to resubscribe orders.
187 187
 	 * @param int $resubscribe_order The order created for the customer to resubscribe to the old expired/cancelled subscription
188 188
 	 */
189
-	public function delete_resubscribe_meta( $resubscribe_order ) {
190
-		delete_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id() ), '_stripe_customer_id' );
191
-		delete_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id() ), '_stripe_source_id' );
189
+	public function delete_resubscribe_meta($resubscribe_order) {
190
+		delete_post_meta((WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id()), '_stripe_customer_id');
191
+		delete_post_meta((WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id()), '_stripe_source_id');
192 192
 		// For BW compat will remove in future
193
-		delete_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id() ), '_stripe_card_id' );
194
-		$this->delete_renewal_meta( $resubscribe_order );
193
+		delete_post_meta((WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id()), '_stripe_card_id');
194
+		$this->delete_renewal_meta($resubscribe_order);
195 195
 	}
196 196
 
197 197
 	/**
198 198
 	 * Don't transfer Stripe fee/ID meta to renewal orders.
199 199
 	 * @param int $resubscribe_order The order created for the customer to resubscribe to the old expired/cancelled subscription
200 200
 	 */
201
-	public function delete_renewal_meta( $renewal_order ) {
202
-		delete_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $renewal_order->id : $renewal_order->get_id() ), 'Stripe Fee' );
203
-		delete_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $renewal_order->id : $renewal_order->get_id() ), 'Net Revenue From Stripe' );
201
+	public function delete_renewal_meta($renewal_order) {
202
+		delete_post_meta((WC_Stripe_Helper::is_pre_30() ? $renewal_order->id : $renewal_order->get_id()), 'Stripe Fee');
203
+		delete_post_meta((WC_Stripe_Helper::is_pre_30() ? $renewal_order->id : $renewal_order->get_id()), 'Net Revenue From Stripe');
204 204
 		return $renewal_order;
205 205
 	}
206 206
 
@@ -210,21 +210,21 @@  discard block
 block discarded – undo
210 210
 	 * @param $amount_to_charge float The amount to charge.
211 211
 	 * @param $renewal_order WC_Order A WC_Order object created to record the renewal payment.
212 212
 	 */
213
-	public function scheduled_subscription_payment( $amount_to_charge, $renewal_order ) {
214
-		$response = $this->process_subscription_payment( $amount_to_charge, $renewal_order );
213
+	public function scheduled_subscription_payment($amount_to_charge, $renewal_order) {
214
+		$response = $this->process_subscription_payment($amount_to_charge, $renewal_order);
215 215
 
216
-		if ( is_wp_error( $response ) ) {
216
+		if (is_wp_error($response)) {
217 217
 			/* translators: error message */
218
-			$renewal_order->update_status( 'failed', sprintf( __( 'Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe' ), $response->get_error_message() ) );
218
+			$renewal_order->update_status('failed', sprintf(__('Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe'), $response->get_error_message()));
219 219
 		}
220 220
 
221
-		if ( ! empty( $response->error ) ) {
221
+		if ( ! empty($response->error)) {
222 222
 			// This is a very generic error to listen for but worth a retry before total fail.
223
-			if ( isset( $response->error->type ) && 'invalid_request_error' === $response->error->type && apply_filters( 'wc_stripe_use_default_customer_source', true ) ) {
224
-				$this->process_subscription_payment( $amount_to_charge, $renewal_order, true );
223
+			if (isset($response->error->type) && 'invalid_request_error' === $response->error->type && apply_filters('wc_stripe_use_default_customer_source', true)) {
224
+				$this->process_subscription_payment($amount_to_charge, $renewal_order, true);
225 225
 			} else {
226 226
 				/* translators: error message */
227
-				$renewal_order->update_status( 'failed', sprintf( __( 'Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe' ), $response->error->message ) );
227
+				$renewal_order->update_status('failed', sprintf(__('Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe'), $response->error->message));
228 228
 			}
229 229
 		}
230 230
 	}
@@ -233,20 +233,20 @@  discard block
 block discarded – undo
233 233
 	 * Remove order meta
234 234
 	 * @param  object $order
235 235
 	 */
236
-	public function remove_order_source_before_retry( $order ) {
236
+	public function remove_order_source_before_retry($order) {
237 237
 		$order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
238
-		delete_post_meta( $order_id, '_stripe_source_id' );
238
+		delete_post_meta($order_id, '_stripe_source_id');
239 239
 		// For BW compat will remove in the future.
240
-		delete_post_meta( $order_id, '_stripe_card_id' );
240
+		delete_post_meta($order_id, '_stripe_card_id');
241 241
 	}
242 242
 
243 243
 	/**
244 244
 	 * Remove order meta
245 245
 	 * @param object $order
246 246
 	 */
247
-	public function remove_order_customer_before_retry( $order ) {
247
+	public function remove_order_customer_before_retry($order) {
248 248
 		$order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
249
-		delete_post_meta( $order_id, '_stripe_customer_id' );
249
+		delete_post_meta($order_id, '_stripe_customer_id');
250 250
 	}
251 251
 
252 252
 	/**
@@ -258,14 +258,14 @@  discard block
 block discarded – undo
258 258
 	 * @param WC_Order $renewal_order The order which recorded the successful payment (to make up for the failed automatic payment).
259 259
 	 * @return void
260 260
 	 */
261
-	public function update_failing_payment_method( $subscription, $renewal_order ) {
262
-		if ( WC_Stripe_Helper::is_pre_30() ) {
263
-			update_post_meta( $subscription->id, '_stripe_customer_id', $renewal_order->stripe_customer_id );
264
-			update_post_meta( $subscription->id, '_stripe_source_id', $renewal_order->stripe_source_id );
261
+	public function update_failing_payment_method($subscription, $renewal_order) {
262
+		if (WC_Stripe_Helper::is_pre_30()) {
263
+			update_post_meta($subscription->id, '_stripe_customer_id', $renewal_order->stripe_customer_id);
264
+			update_post_meta($subscription->id, '_stripe_source_id', $renewal_order->stripe_source_id);
265 265
 
266 266
 		} else {
267
-			update_post_meta( $subscription->get_id(), '_stripe_customer_id', $renewal_order->get_meta( '_stripe_customer_id', true ) );
268
-			update_post_meta( $subscription->get_id(), '_stripe_source_id', $renewal_order->get_meta( '_stripe_source_id', true ) );
267
+			update_post_meta($subscription->get_id(), '_stripe_customer_id', $renewal_order->get_meta('_stripe_customer_id', true));
268
+			update_post_meta($subscription->get_id(), '_stripe_source_id', $renewal_order->get_meta('_stripe_source_id', true));
269 269
 		}
270 270
 	}
271 271
 
@@ -278,21 +278,21 @@  discard block
 block discarded – undo
278 278
 	 * @param WC_Subscription $subscription An instance of a subscription object
279 279
 	 * @return array
280 280
 	 */
281
-	public function add_subscription_payment_meta( $payment_meta, $subscription ) {
282
-		$source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_source_id', true );
281
+	public function add_subscription_payment_meta($payment_meta, $subscription) {
282
+		$source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_source_id', true);
283 283
 
284 284
 		// For BW compat will remove in future.
285
-		if ( empty( $source_id ) ) {
286
-			$source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_card_id', true );
285
+		if (empty($source_id)) {
286
+			$source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_card_id', true);
287 287
 
288 288
 			// Take this opportunity to update the key name.
289
-			WC_Stripe_Helper::is_pre_30() ? update_post_meta( $subscription->id, '_stripe_source_id', $source_id ) : update_post_meta( $subscription->get_id(), '_stripe_source_id', $source_id );
289
+			WC_Stripe_Helper::is_pre_30() ? update_post_meta($subscription->id, '_stripe_source_id', $source_id) : update_post_meta($subscription->get_id(), '_stripe_source_id', $source_id);
290 290
 		}
291 291
 
292
-		$payment_meta[ $this->id ] = array(
292
+		$payment_meta[$this->id] = array(
293 293
 			'post_meta' => array(
294 294
 				'_stripe_customer_id' => array(
295
-					'value' => get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_customer_id', true ),
295
+					'value' => get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_customer_id', true),
296 296
 					'label' => 'Stripe Customer ID',
297 297
 				),
298 298
 				'_stripe_source_id' => array(
@@ -313,22 +313,22 @@  discard block
 block discarded – undo
313 313
 	 * @param array $payment_meta associative array of meta data required for automatic payments
314 314
 	 * @return array
315 315
 	 */
316
-	public function validate_subscription_payment_meta( $payment_method_id, $payment_meta ) {
317
-		if ( $this->id === $payment_method_id ) {
316
+	public function validate_subscription_payment_meta($payment_method_id, $payment_meta) {
317
+		if ($this->id === $payment_method_id) {
318 318
 
319
-			if ( ! isset( $payment_meta['post_meta']['_stripe_customer_id']['value'] ) || empty( $payment_meta['post_meta']['_stripe_customer_id']['value'] ) ) {
320
-				throw new Exception( __( 'A "Stripe Customer ID" value is required.', 'woocommerce-gateway-stripe' ) );
321
-			} elseif ( 0 !== strpos( $payment_meta['post_meta']['_stripe_customer_id']['value'], 'cus_' ) ) {
322
-				throw new Exception( __( 'Invalid customer ID. A valid "Stripe Customer ID" must begin with "cus_".', 'woocommerce-gateway-stripe' ) );
319
+			if ( ! isset($payment_meta['post_meta']['_stripe_customer_id']['value']) || empty($payment_meta['post_meta']['_stripe_customer_id']['value'])) {
320
+				throw new Exception(__('A "Stripe Customer ID" value is required.', 'woocommerce-gateway-stripe'));
321
+			} elseif (0 !== strpos($payment_meta['post_meta']['_stripe_customer_id']['value'], 'cus_')) {
322
+				throw new Exception(__('Invalid customer ID. A valid "Stripe Customer ID" must begin with "cus_".', 'woocommerce-gateway-stripe'));
323 323
 			}
324 324
 
325 325
 			if (
326
-				( ! empty( $payment_meta['post_meta']['_stripe_source_id']['value'] )
327
-				&& 0 !== strpos( $payment_meta['post_meta']['_stripe_source_id']['value'], 'card_' ) )
328
-				&& ( ! empty( $payment_meta['post_meta']['_stripe_source_id']['value'] )
329
-				&& 0 !== strpos( $payment_meta['post_meta']['_stripe_source_id']['value'], 'src_' ) ) ) {
326
+				( ! empty($payment_meta['post_meta']['_stripe_source_id']['value'])
327
+				&& 0 !== strpos($payment_meta['post_meta']['_stripe_source_id']['value'], 'card_'))
328
+				&& ( ! empty($payment_meta['post_meta']['_stripe_source_id']['value'])
329
+				&& 0 !== strpos($payment_meta['post_meta']['_stripe_source_id']['value'], 'src_')) ) {
330 330
 
331
-				throw new Exception( __( 'Invalid source ID. A valid source "Stripe Source ID" must begin with "src_" or "card_".', 'woocommerce-gateway-stripe' ) );
331
+				throw new Exception(__('Invalid source ID. A valid source "Stripe Source ID" must begin with "src_" or "card_".', 'woocommerce-gateway-stripe'));
332 332
 			}
333 333
 		}
334 334
 	}
@@ -341,89 +341,89 @@  discard block
 block discarded – undo
341 341
 	 * @param WC_Subscription $subscription the subscription details
342 342
 	 * @return string the subscription payment method
343 343
 	 */
344
-	public function maybe_render_subscription_payment_method( $payment_method_to_display, $subscription ) {
344
+	public function maybe_render_subscription_payment_method($payment_method_to_display, $subscription) {
345 345
 		$customer_user = WC_Stripe_Helper::is_pre_30() ? $subscription->customer_user : $subscription->get_customer_id();
346 346
 
347 347
 		// bail for other payment methods
348
-		if ( ( WC_Stripe_Helper::is_pre_30() ? $subscription->payment_method : $subscription->get_payment_method() ) !== $this->id || ! $customer_user ) {
348
+		if ((WC_Stripe_Helper::is_pre_30() ? $subscription->payment_method : $subscription->get_payment_method()) !== $this->id || ! $customer_user) {
349 349
 			return $payment_method_to_display;
350 350
 		}
351 351
 
352
-		$stripe_source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_source_id', true );
352
+		$stripe_source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_source_id', true);
353 353
 
354 354
 		// For BW compat will remove in future.
355
-		if ( empty( $stripe_source_id ) ) {
356
-			$stripe_source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_card_id', true );
355
+		if (empty($stripe_source_id)) {
356
+			$stripe_source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_card_id', true);
357 357
 
358 358
 			// Take this opportunity to update the key name.
359
-			WC_Stripe_Helper::is_pre_30() ? update_post_meta( $subscription->id, '_stripe_source_id', $stripe_source_id ) : update_post_meta( $subscription->get_id(), '_stripe_source_id', $stripe_source_id );
359
+			WC_Stripe_Helper::is_pre_30() ? update_post_meta($subscription->id, '_stripe_source_id', $stripe_source_id) : update_post_meta($subscription->get_id(), '_stripe_source_id', $stripe_source_id);
360 360
 		}
361 361
 
362 362
 		$stripe_customer    = new WC_Stripe_Customer();
363
-		$stripe_customer_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_customer_id', true );
363
+		$stripe_customer_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_customer_id', true);
364 364
 
365 365
 		// If we couldn't find a Stripe customer linked to the subscription, fallback to the user meta data.
366
-		if ( ! $stripe_customer_id || ! is_string( $stripe_customer_id ) ) {
366
+		if ( ! $stripe_customer_id || ! is_string($stripe_customer_id)) {
367 367
 			$user_id            = $customer_user;
368
-			$stripe_customer_id = get_user_meta( $user_id, '_stripe_customer_id', true );
369
-			$stripe_source_id   = get_user_meta( $user_id, '_stripe_source_id', true );
368
+			$stripe_customer_id = get_user_meta($user_id, '_stripe_customer_id', true);
369
+			$stripe_source_id   = get_user_meta($user_id, '_stripe_source_id', true);
370 370
 
371 371
 			// For BW compat will remove in future.
372
-			if ( empty( $stripe_source_id ) ) {
373
-				$stripe_source_id = get_user_meta( $user_id, '_stripe_card_id', true );
372
+			if (empty($stripe_source_id)) {
373
+				$stripe_source_id = get_user_meta($user_id, '_stripe_card_id', true);
374 374
 
375 375
 				// Take this opportunity to update the key name.
376
-				update_user_meta( $user_id, '_stripe_source_id', $stripe_source_id );
376
+				update_user_meta($user_id, '_stripe_source_id', $stripe_source_id);
377 377
 			}
378 378
 		}
379 379
 
380 380
 		// If we couldn't find a Stripe customer linked to the account, fallback to the order meta data.
381
-		if ( ( ! $stripe_customer_id || ! is_string( $stripe_customer_id ) ) && false !== $subscription->order ) {
382
-			$stripe_customer_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id() ), '_stripe_customer_id', true );
383
-			$stripe_source_id   = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id() ), '_stripe_source_id', true );
381
+		if (( ! $stripe_customer_id || ! is_string($stripe_customer_id)) && false !== $subscription->order) {
382
+			$stripe_customer_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id()), '_stripe_customer_id', true);
383
+			$stripe_source_id   = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id()), '_stripe_source_id', true);
384 384
 
385 385
 			// For BW compat will remove in future.
386
-			if ( empty( $stripe_source_id ) ) {
387
-				$stripe_source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id() ), '_stripe_card_id', true );
386
+			if (empty($stripe_source_id)) {
387
+				$stripe_source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id()), '_stripe_card_id', true);
388 388
 
389 389
 				// Take this opportunity to update the key name.
390
-				WC_Stripe_Helper::is_pre_30() ? update_post_meta( $subscription->order->id, '_stripe_source_id', $stripe_source_id ) : update_post_meta( $subscription->get_parent_id(), '_stripe_source_id', $stripe_source_id );
390
+				WC_Stripe_Helper::is_pre_30() ? update_post_meta($subscription->order->id, '_stripe_source_id', $stripe_source_id) : update_post_meta($subscription->get_parent_id(), '_stripe_source_id', $stripe_source_id);
391 391
 			}
392 392
 		}
393 393
 
394
-		$stripe_customer->set_id( $stripe_customer_id );
394
+		$stripe_customer->set_id($stripe_customer_id);
395 395
 		$sources = $stripe_customer->get_sources();
396 396
 
397
-		if ( $sources ) {
397
+		if ($sources) {
398 398
 			$found_source = false;
399
-			foreach ( $sources as $source ) {
400
-				if ( isset( $source->type ) && 'card' === $source->type ) {
399
+			foreach ($sources as $source) {
400
+				if (isset($source->type) && 'card' === $source->type) {
401 401
 					$card = $source->card;
402 402
 				}
403 403
 
404
-				if ( $source->id === $stripe_source_id ) {
404
+				if ($source->id === $stripe_source_id) {
405 405
 					$found_source = true;
406 406
 
407
-					if ( $card ) {
407
+					if ($card) {
408 408
 						/* translators: 1) card brand 2) last 4 digits */
409
-						$payment_method_to_display = sprintf( __( 'Via %1$s card ending in %2$s', 'woocommerce-gateway-stripe' ), ( isset( $card->brand ) ? $card->brand : __( 'N/A', 'woocommerce-gateway-stripe' ) ), $card->last4 );
409
+						$payment_method_to_display = sprintf(__('Via %1$s card ending in %2$s', 'woocommerce-gateway-stripe'), (isset($card->brand) ? $card->brand : __('N/A', 'woocommerce-gateway-stripe')), $card->last4);
410 410
 					} else {
411
-						$payment_method_to_display = __( 'N/A', 'woocommerce-gateway-stripe' );
411
+						$payment_method_to_display = __('N/A', 'woocommerce-gateway-stripe');
412 412
 					}
413 413
 					break;
414 414
 				}
415 415
 			}
416 416
 
417
-			if ( ! $found_source ) {
418
-				if ( 'card' === $sources[0]->type ) {
417
+			if ( ! $found_source) {
418
+				if ('card' === $sources[0]->type) {
419 419
 					$card = $sources[0]->card;
420 420
 				}
421 421
 
422
-				if ( $card ) {
422
+				if ($card) {
423 423
 					/* translators: 1) card brand 2) last 4 digits */
424
-					$payment_method_to_display = sprintf( __( 'Via %1$s card ending in %2$s', 'woocommerce-gateway-stripe' ), ( isset( $card->brand ) ? $card->brand : __( 'N/A', 'woocommerce-gateway-stripe' ) ), $card->last4 );
424
+					$payment_method_to_display = sprintf(__('Via %1$s card ending in %2$s', 'woocommerce-gateway-stripe'), (isset($card->brand) ? $card->brand : __('N/A', 'woocommerce-gateway-stripe')), $card->last4);
425 425
 				} else {
426
-					$payment_method_to_display = __( 'N/A', 'woocommerce-gateway-stripe' );
426
+					$payment_method_to_display = __('N/A', 'woocommerce-gateway-stripe');
427 427
 				}
428 428
 			}
429 429
 		}
@@ -436,42 +436,42 @@  discard block
 block discarded – undo
436 436
 	 * @param int $order_id
437 437
 	 * @return array
438 438
 	 */
439
-	public function process_pre_order( $order_id, $retry, $force_save_source ) {
440
-		if ( WC_Pre_Orders_Order::order_requires_payment_tokenization( $order_id ) ) {
439
+	public function process_pre_order($order_id, $retry, $force_save_source) {
440
+		if (WC_Pre_Orders_Order::order_requires_payment_tokenization($order_id)) {
441 441
 			try {
442
-				$order = wc_get_order( $order_id );
442
+				$order = wc_get_order($order_id);
443 443
 
444
-				if ( $order->get_total() * 100 < WC_Stripe_Helper::get_minimum_amount() ) {
444
+				if ($order->get_total() * 100 < WC_Stripe_Helper::get_minimum_amount()) {
445 445
 					/* translators: minimum amount */
446
-					throw new Exception( sprintf( __( 'Sorry, the minimum allowed order total is %1$s to use this payment method.', 'woocommerce-gateway-stripe' ), wc_price( WC_Stripe_Helper::get_minimum_amount() / 100 ) ) );
446
+					throw new Exception(sprintf(__('Sorry, the minimum allowed order total is %1$s to use this payment method.', 'woocommerce-gateway-stripe'), wc_price(WC_Stripe_Helper::get_minimum_amount() / 100)));
447 447
 				}
448 448
 
449
-				$source = $this->prepare_source( $this->get_source_object(), get_current_user_id(), true );
449
+				$source = $this->prepare_source($this->get_source_object(), get_current_user_id(), true);
450 450
 
451 451
 				// We need a source on file to continue.
452
-				if ( empty( $source->customer ) || empty( $source->source ) ) {
453
-					throw new Exception( __( 'Unable to store payment details. Please try again.', 'woocommerce-gateway-stripe' ) );
452
+				if (empty($source->customer) || empty($source->source)) {
453
+					throw new Exception(__('Unable to store payment details. Please try again.', 'woocommerce-gateway-stripe'));
454 454
 				}
455 455
 
456
-				$this->save_source_to_order( $order, $source );
456
+				$this->save_source_to_order($order, $source);
457 457
 
458 458
 				// Remove cart
459 459
 				WC()->cart->empty_cart();
460 460
 
461 461
 				// Is pre ordered!
462
-				WC_Pre_Orders_Order::mark_order_as_pre_ordered( $order );
462
+				WC_Pre_Orders_Order::mark_order_as_pre_ordered($order);
463 463
 
464 464
 				// Return thank you page redirect
465 465
 				return array(
466 466
 					'result'   => 'success',
467
-					'redirect' => $this->get_return_url( $order ),
467
+					'redirect' => $this->get_return_url($order),
468 468
 				);
469
-			} catch ( Exception $e ) {
470
-				wc_add_notice( $e->getMessage(), 'error' );
469
+			} catch (Exception $e) {
470
+				wc_add_notice($e->getMessage(), 'error');
471 471
 				return;
472 472
 			}
473 473
 		} else {
474
-			return parent::process_payment( $order_id, $retry, $force_save_source );
474
+			return parent::process_payment($order_id, $retry, $force_save_source);
475 475
 		}
476 476
 	}
477 477
 
@@ -480,7 +480,7 @@  discard block
 block discarded – undo
480 480
 	 * @param WC_Order $order
481 481
 	 * @return void
482 482
 	 */
483
-	public function process_pre_order_release_payment( $order ) {
483
+	public function process_pre_order_release_payment($order) {
484 484
 		try {
485 485
 			// Define some callbacks if the first attempt fails.
486 486
 			$retry_callbacks = array(
@@ -488,33 +488,33 @@  discard block
 block discarded – undo
488 488
 				'remove_order_customer_before_retry',
489 489
 			);
490 490
 
491
-			while ( 1 ) {
492
-				$source   = $this->prepare_order_source( $order );
493
-				$response = WC_Stripe_API::request( $this->generate_payment_request( $order, $source ) );
491
+			while (1) {
492
+				$source   = $this->prepare_order_source($order);
493
+				$response = WC_Stripe_API::request($this->generate_payment_request($order, $source));
494 494
 
495
-				if ( ! empty( $response->error ) ) {
496
-					if ( 0 === sizeof( $retry_callbacks ) ) {
497
-						throw new Exception( $response->error->message );
495
+				if ( ! empty($response->error)) {
496
+					if (0 === sizeof($retry_callbacks)) {
497
+						throw new Exception($response->error->message);
498 498
 					} else {
499
-						$retry_callback = array_shift( $retry_callbacks );
500
-						call_user_func( array( $this, $retry_callback ), $order );
499
+						$retry_callback = array_shift($retry_callbacks);
500
+						call_user_func(array($this, $retry_callback), $order);
501 501
 					}
502 502
 				} else {
503 503
 					// Successful
504
-					$this->process_response( $response, $order );
504
+					$this->process_response($response, $order);
505 505
 					break;
506 506
 				}
507 507
 			}
508
-		} catch ( Exception $e ) {
508
+		} catch (Exception $e) {
509 509
 			/* translators: error message */
510
-			$order_note = sprintf( __( 'Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe' ), $e->getMessage() );
510
+			$order_note = sprintf(__('Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe'), $e->getMessage());
511 511
 
512 512
 			// Mark order as failed if not already set,
513 513
 			// otherwise, make sure we add the order note so we can detect when someone fails to check out multiple times
514
-			if ( ! $order->has_status( 'failed' ) ) {
515
-				$order->update_status( 'failed', $order_note );
514
+			if ( ! $order->has_status('failed')) {
515
+				$order->update_status('failed', $order_note);
516 516
 			} else {
517
-				$order->add_order_note( $order_note );
517
+				$order->add_order_note($order_note);
518 518
 			}
519 519
 		}
520 520
 	}
Please login to merge, or discard this patch.
includes/payment-methods/class-wc-gateway-stripe-bitcoin.php 1 patch
Spacing   +89 added lines, -89 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
 
@@ -64,9 +64,9 @@  discard block
 block discarded – undo
64 64
 	 */
65 65
 	public function __construct() {
66 66
 		$this->id                   = 'stripe_bitcoin';
67
-		$this->method_title         = __( 'Stripe Bitcoin', 'woocommerce-gateway-stripe' );
67
+		$this->method_title         = __('Stripe Bitcoin', 'woocommerce-gateway-stripe');
68 68
 		/* translators: link */
69
-		$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' ) );
69
+		$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'));
70 70
 		$this->supports             = array(
71 71
 			'products',
72 72
 			'refunds',
@@ -78,29 +78,29 @@  discard block
 block discarded – undo
78 78
 		// Load the settings.
79 79
 		$this->init_settings();
80 80
 
81
-		$main_settings              = get_option( 'woocommerce_stripe_settings' );
82
-		$this->title                = $this->get_option( 'title' );
83
-		$this->description          = $this->get_option( 'description' );
84
-		$this->enabled              = $this->get_option( 'enabled' );
85
-		$this->testmode             = ( ! empty( $main_settings['testmode'] ) && 'yes' === $main_settings['testmode'] ) ? true : false;
86
-		$this->saved_cards          = ( ! empty( $main_settings['saved_cards'] ) && 'yes' === $main_settings['saved_cards'] ) ? true : false;
87
-		$this->publishable_key      = ! empty( $main_settings['publishable_key'] ) ? $main_settings['publishable_key'] : '';
88
-		$this->secret_key           = ! empty( $main_settings['secret_key'] ) ? $main_settings['secret_key'] : '';
89
-		$this->statement_descriptor = ! empty( $main_settings['statement_descriptor'] ) ? $main_settings['statement_descriptor'] : '';
90
-
91
-		if ( $this->testmode ) {
92
-			$this->publishable_key = ! empty( $main_settings['test_publishable_key'] ) ? $main_settings['test_publishable_key'] : '';
93
-			$this->secret_key      = ! empty( $main_settings['test_secret_key'] ) ? $main_settings['test_secret_key'] : '';
81
+		$main_settings              = get_option('woocommerce_stripe_settings');
82
+		$this->title                = $this->get_option('title');
83
+		$this->description          = $this->get_option('description');
84
+		$this->enabled              = $this->get_option('enabled');
85
+		$this->testmode             = ( ! empty($main_settings['testmode']) && 'yes' === $main_settings['testmode']) ? true : false;
86
+		$this->saved_cards          = ( ! empty($main_settings['saved_cards']) && 'yes' === $main_settings['saved_cards']) ? true : false;
87
+		$this->publishable_key      = ! empty($main_settings['publishable_key']) ? $main_settings['publishable_key'] : '';
88
+		$this->secret_key           = ! empty($main_settings['secret_key']) ? $main_settings['secret_key'] : '';
89
+		$this->statement_descriptor = ! empty($main_settings['statement_descriptor']) ? $main_settings['statement_descriptor'] : '';
90
+
91
+		if ($this->testmode) {
92
+			$this->publishable_key = ! empty($main_settings['test_publishable_key']) ? $main_settings['test_publishable_key'] : '';
93
+			$this->secret_key      = ! empty($main_settings['test_secret_key']) ? $main_settings['test_secret_key'] : '';
94 94
 		}
95 95
 
96
-		add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) );
97
-		add_action( 'admin_notices', array( $this, 'check_environment' ) );
98
-		add_action( 'admin_head', array( $this, 'remove_admin_notice' ) );
99
-		add_action( 'wp_enqueue_scripts', array( $this, 'payment_scripts' ) );
100
-		add_action( 'woocommerce_thankyou_stripe_bitcoin', array( $this, 'thankyou_page' ) );
96
+		add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options'));
97
+		add_action('admin_notices', array($this, 'check_environment'));
98
+		add_action('admin_head', array($this, 'remove_admin_notice'));
99
+		add_action('wp_enqueue_scripts', array($this, 'payment_scripts'));
100
+		add_action('woocommerce_thankyou_stripe_bitcoin', array($this, 'thankyou_page'));
101 101
 
102 102
 		// Customer Emails
103
-		add_action( 'woocommerce_email_before_order_table', array( $this, 'email_instructions' ), 10, 3 );
103
+		add_action('woocommerce_email_before_order_table', array($this, 'email_instructions'), 10, 3);
104 104
 	}
105 105
 
106 106
 	/**
@@ -110,19 +110,19 @@  discard block
 block discarded – undo
110 110
 	 * @version 4.0.0
111 111
 	 */
112 112
 	public function check_environment() {
113
-		if ( ! current_user_can( 'manage_woocommerce' ) ) {
113
+		if ( ! current_user_can('manage_woocommerce')) {
114 114
 			return;
115 115
 		}
116 116
 
117 117
 		$environment_warning = $this->get_environment_warning();
118 118
 
119
-		if ( $environment_warning ) {
120
-			$this->add_admin_notice( 'bad_environment', 'error', $environment_warning );
119
+		if ($environment_warning) {
120
+			$this->add_admin_notice('bad_environment', 'error', $environment_warning);
121 121
 		}
122 122
 
123
-		foreach ( (array) $this->notices as $notice_key => $notice ) {
124
-			echo "<div class='" . esc_attr( $notice['class'] ) . "'><p>";
125
-			echo wp_kses( $notice['message'], array( 'a' => array( 'href' => array() ) ) );
123
+		foreach ((array) $this->notices as $notice_key => $notice) {
124
+			echo "<div class='" . esc_attr($notice['class']) . "'><p>";
125
+			echo wp_kses($notice['message'], array('a' => array('href' => array())));
126 126
 			echo '</p></div>';
127 127
 		}
128 128
 	}
@@ -136,12 +136,12 @@  discard block
 block discarded – undo
136 136
 	 */
137 137
 	public function get_environment_warning() {
138 138
 		// Add deprecated notice to logs.
139
-		if ( 'yes' === $this->enabled ) {
140
-			WC_Stripe_Logger::log( 'DEPRECATED! Stripe will no longer support Bitcoin and will cease to function on April 23, 2018. Please plan accordingly.' );
139
+		if ('yes' === $this->enabled) {
140
+			WC_Stripe_Logger::log('DEPRECATED! Stripe will no longer support Bitcoin and will cease to function on April 23, 2018. Please plan accordingly.');
141 141
 		}
142 142
 
143
-		if ( 'yes' === $this->enabled && ! in_array( get_woocommerce_currency(), $this->get_supported_currency() ) ) {
144
-			$message = __( 'Bitcoin is enabled - it requires store currency to be set to USD.', 'woocommerce-gateway-stripe' );
143
+		if ('yes' === $this->enabled && ! in_array(get_woocommerce_currency(), $this->get_supported_currency())) {
144
+			$message = __('Bitcoin is enabled - it requires store currency to be set to USD.', 'woocommerce-gateway-stripe');
145 145
 
146 146
 			return $message;
147 147
 		}
@@ -157,9 +157,9 @@  discard block
 block discarded – undo
157 157
 	 * @return array
158 158
 	 */
159 159
 	public function get_supported_currency() {
160
-		return apply_filters( 'wc_stripe_bitcoin_supported_currencies', array(
160
+		return apply_filters('wc_stripe_bitcoin_supported_currencies', array(
161 161
 			'USD',
162
-		) );
162
+		));
163 163
 	}
164 164
 
165 165
 	/**
@@ -170,7 +170,7 @@  discard block
 block discarded – undo
170 170
 	 * @return bool
171 171
 	 */
172 172
 	public function is_available() {
173
-		if ( ! in_array( get_woocommerce_currency(), $this->get_supported_currency() ) ) {
173
+		if ( ! in_array(get_woocommerce_currency(), $this->get_supported_currency())) {
174 174
 			return false;
175 175
 		}
176 176
 
@@ -191,7 +191,7 @@  discard block
 block discarded – undo
191 191
 
192 192
 		$icons_str .= $icons['bitcoin'];
193 193
 
194
-		return apply_filters( 'woocommerce_gateway_icon', $icons_str, $this->id );
194
+		return apply_filters('woocommerce_gateway_icon', $icons_str, $this->id);
195 195
 	}
196 196
 
197 197
 	/**
@@ -202,19 +202,19 @@  discard block
 block discarded – undo
202 202
 	 * @access public
203 203
 	 */
204 204
 	public function payment_scripts() {
205
-		if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) && ! is_add_payment_method_page() ) {
205
+		if ( ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order']) && ! is_add_payment_method_page()) {
206 206
 			return;
207 207
 		}
208 208
 
209
-		wp_enqueue_style( 'stripe_paymentfonts' );
210
-		wp_enqueue_script( 'woocommerce_stripe' );
209
+		wp_enqueue_style('stripe_paymentfonts');
210
+		wp_enqueue_script('woocommerce_stripe');
211 211
 	}
212 212
 
213 213
 	/**
214 214
 	 * Initialize Gateway Settings Form Fields.
215 215
 	 */
216 216
 	public function init_form_fields() {
217
-		$this->form_fields = require( WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-bitcoin-settings.php' );
217
+		$this->form_fields = require(WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-bitcoin-settings.php');
218 218
 	}
219 219
 
220 220
 	/**
@@ -225,25 +225,25 @@  discard block
 block discarded – undo
225 225
 		$total                = WC()->cart->total;
226 226
 
227 227
 		// If paying from order, we need to get total from order not cart.
228
-		if ( isset( $_GET['pay_for_order'] ) && ! empty( $_GET['key'] ) ) {
229
-			$order = wc_get_order( wc_get_order_id_by_order_key( wc_clean( $_GET['key'] ) ) );
228
+		if (isset($_GET['pay_for_order']) && ! empty($_GET['key'])) {
229
+			$order = wc_get_order(wc_get_order_id_by_order_key(wc_clean($_GET['key'])));
230 230
 			$total = $order->get_total();
231 231
 		}
232 232
 
233
-		if ( is_add_payment_method_page() ) {
234
-			$pay_button_text = __( 'Add Payment', 'woocommerce-gateway-stripe' );
235
-			$total        = '';
233
+		if (is_add_payment_method_page()) {
234
+			$pay_button_text = __('Add Payment', 'woocommerce-gateway-stripe');
235
+			$total = '';
236 236
 		} else {
237 237
 			$pay_button_text = '';
238 238
 		}
239 239
 
240 240
 		echo '<div
241 241
 			id="stripe-bitcoin-payment-data"
242
-			data-amount="' . esc_attr( WC_Stripe_Helper::get_stripe_amount( $total ) ) . '"
243
-			data-currency="' . esc_attr( strtolower( get_woocommerce_currency() ) ) . '">';
242
+			data-amount="' . esc_attr(WC_Stripe_Helper::get_stripe_amount($total)) . '"
243
+			data-currency="' . esc_attr(strtolower(get_woocommerce_currency())) . '">';
244 244
 
245
-		if ( $this->description ) {
246
-			echo apply_filters( 'wc_stripe_description', wpautop( wp_kses_post( $this->description ) ) );
245
+		if ($this->description) {
246
+			echo apply_filters('wc_stripe_description', wpautop(wp_kses_post($this->description)));
247 247
 		}
248 248
 
249 249
 		echo '</div>';
@@ -254,8 +254,8 @@  discard block
 block discarded – undo
254 254
 	 *
255 255
 	 * @param int $order_id
256 256
 	 */
257
-	public function thankyou_page( $order_id ) {
258
-		$this->get_instructions( $order_id );
257
+	public function thankyou_page($order_id) {
258
+		$this->get_instructions($order_id);
259 259
 	}
260 260
 
261 261
 	/**
@@ -267,13 +267,13 @@  discard block
 block discarded – undo
267 267
 	 * @param bool $sent_to_admin
268 268
 	 * @param bool $plain_text
269 269
 	 */
270
-	public function email_instructions( $order, $sent_to_admin, $plain_text = false ) {
270
+	public function email_instructions($order, $sent_to_admin, $plain_text = false) {
271 271
 		$order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
272 272
 
273 273
 		$payment_method = WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method();
274 274
 
275
-		if ( ! $sent_to_admin && 'stripe_bitcoin' === $payment_method && $order->has_status( 'on-hold' ) ) {
276
-			$this->get_instructions( $order_id, $plain_text );
275
+		if ( ! $sent_to_admin && 'stripe_bitcoin' === $payment_method && $order->has_status('on-hold')) {
276
+			$this->get_instructions($order_id, $plain_text);
277 277
 		}
278 278
 	}
279 279
 
@@ -284,38 +284,38 @@  discard block
 block discarded – undo
284 284
 	 * @version 4.0.0
285 285
 	 * @param int $order_id
286 286
 	 */
287
-	public function get_instructions( $order_id, $plain_text = false ) {
288
-		$data = get_post_meta( $order_id, '_stripe_bitcoin', true );
287
+	public function get_instructions($order_id, $plain_text = false) {
288
+		$data = get_post_meta($order_id, '_stripe_bitcoin', true);
289 289
 
290
-		if ( $plain_text ) {
291
-			esc_html_e( 'Please pay the following:', 'woocommerce-gateway-stripe' ) . "\n\n";
290
+		if ($plain_text) {
291
+			esc_html_e('Please pay the following:', 'woocommerce-gateway-stripe') . "\n\n";
292 292
 			echo "=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\n\n";
293
-			esc_html_e( 'Bitcoin Amount:', 'woocommerce-gateway-stripe' ) . "\n\n";
293
+			esc_html_e('Bitcoin Amount:', 'woocommerce-gateway-stripe') . "\n\n";
294 294
 			echo $data['amount'] . "\n\n";
295 295
 			echo "=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\n\n";
296
-			esc_html_e( 'Receiver:', 'woocommerce-gateway-stripe' ) . "\n\n";
296
+			esc_html_e('Receiver:', 'woocommerce-gateway-stripe') . "\n\n";
297 297
 			echo $data['address'] . "\n\n";
298 298
 			echo "=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\n\n";
299
-			esc_html_e( 'URI:', 'woocommerce-gateway-stripe' ) . "\n\n";
299
+			esc_html_e('URI:', 'woocommerce-gateway-stripe') . "\n\n";
300 300
 			echo $data['uri'] . "\n\n";
301 301
 		} else {
302 302
 			?>
303
-			<h3><?php esc_html_e( 'Please pay the following:', 'woocommerce-gateway-stripe' ); ?></h3>
303
+			<h3><?php esc_html_e('Please pay the following:', 'woocommerce-gateway-stripe'); ?></h3>
304 304
 			<ul class="woocommerce-order-overview woocommerce-thankyou-order-details order_details">
305 305
 			<li class="woocommerce-order-overview__order order">
306
-				<?php esc_html_e( 'Bitcoin Amount:', 'woocommerce-gateway-stripe' ); ?>
306
+				<?php esc_html_e('Bitcoin Amount:', 'woocommerce-gateway-stripe'); ?>
307 307
 				<strong><?php echo $data['amount']; ?></strong>
308 308
 			</li>
309 309
 			<li class="woocommerce-order-overview__order order">
310
-				<?php esc_html_e( 'Receiver:', 'woocommerce-gateway-stripe' ); ?>
310
+				<?php esc_html_e('Receiver:', 'woocommerce-gateway-stripe'); ?>
311 311
 				<strong><?php echo $data['address']; ?></strong>
312 312
 			</li>
313 313
 			<li class="woocommerce-order-overview__order order">
314
-				<?php esc_html_e( 'URI:', 'woocommerce-gateway-stripe' ); ?>
314
+				<?php esc_html_e('URI:', 'woocommerce-gateway-stripe'); ?>
315 315
 				<strong>
316 316
 				<?php
317 317
 				/* translators: link */
318
-				printf( __( '<a href="%s">Pay Bitcoin</a>', 'woocommerce-gateway-stripe' ), $data['uri'] );
318
+				printf(__('<a href="%s">Pay Bitcoin</a>', 'woocommerce-gateway-stripe'), $data['uri']);
319 319
 				?>
320 320
 				</strong>
321 321
 			</li>
@@ -332,7 +332,7 @@  discard block
 block discarded – undo
332 332
 	 * @param object $order
333 333
 	 * @param object $source_object
334 334
 	 */
335
-	public function save_instructions( $order, $source_object ) {
335
+	public function save_instructions($order, $source_object) {
336 336
 		$data = array(
337 337
 			'amount'  => $source_object->bitcoin->amount,
338 338
 			'address' => $source_object->bitcoin->address,
@@ -341,7 +341,7 @@  discard block
 block discarded – undo
341 341
 
342 342
 		$order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
343 343
 
344
-		update_post_meta( $order_id, '_stripe_bitcoin', $data );
344
+		update_post_meta($order_id, '_stripe_bitcoin', $data);
345 345
 	}
346 346
 
347 347
 	/**
@@ -355,37 +355,37 @@  discard block
 block discarded – undo
355 355
 	 *
356 356
 	 * @return array|void
357 357
 	 */
358
-	public function process_payment( $order_id, $retry = true, $force_save_source = false ) {
358
+	public function process_payment($order_id, $retry = true, $force_save_source = false) {
359 359
 		try {
360
-			$order = wc_get_order( $order_id );
360
+			$order = wc_get_order($order_id);
361 361
 
362 362
 			// This comes from the create account checkbox in the checkout page.
363
-			$create_account = ! empty( $_POST['createaccount'] ) ? true : false;
363
+			$create_account = ! empty($_POST['createaccount']) ? true : false;
364 364
 
365
-			if ( $create_account ) {
365
+			if ($create_account) {
366 366
 				$new_customer_id     = WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id();
367
-				$new_stripe_customer = new WC_Stripe_Customer( $new_customer_id );
367
+				$new_stripe_customer = new WC_Stripe_Customer($new_customer_id);
368 368
 				$new_stripe_customer->create_customer();
369 369
 			}
370 370
 
371
-			$prepared_source = $this->prepare_source( $this->get_source_object(), get_current_user_id(), $force_save_source );
371
+			$prepared_source = $this->prepare_source($this->get_source_object(), get_current_user_id(), $force_save_source);
372 372
 
373
-			if ( empty( $prepared_source->source ) ) {
374
-				$localized_message = __( 'Payment processing failed. Please retry.', 'woocommerce-gateway-stripe' );
375
-				throw new WC_Stripe_Exception( print_r( $prepared_source, true ), $localized_message );
373
+			if (empty($prepared_source->source)) {
374
+				$localized_message = __('Payment processing failed. Please retry.', 'woocommerce-gateway-stripe');
375
+				throw new WC_Stripe_Exception(print_r($prepared_source, true), $localized_message);
376 376
 			}
377 377
 
378
-			$this->save_source_to_order( $order, $prepared_source );
378
+			$this->save_source_to_order($order, $prepared_source);
379 379
 
380 380
 			// This will throw exception if not valid.
381
-			$this->validate_minimum_order_amount( $order );
381
+			$this->validate_minimum_order_amount($order);
382 382
 
383
-			$this->save_instructions( $order, $this->get_source_object() );
383
+			$this->save_instructions($order, $this->get_source_object());
384 384
 
385 385
 			// Mark as on-hold (we're awaiting the payment)
386
-			$order->update_status( 'on-hold', __( 'Awaiting Bitcoin payment', 'woocommerce-gateway-stripe' ) );
386
+			$order->update_status('on-hold', __('Awaiting Bitcoin payment', 'woocommerce-gateway-stripe'));
387 387
 
388
-			wc_reduce_stock_levels( $order_id );
388
+			wc_reduce_stock_levels($order_id);
389 389
 
390 390
 			// Remove cart
391 391
 			WC()->cart->empty_cart();
@@ -393,16 +393,16 @@  discard block
 block discarded – undo
393 393
 			// Return thankyou redirect
394 394
 			return array(
395 395
 				'result'    => 'success',
396
-				'redirect'  => $this->get_return_url( $order ),
396
+				'redirect'  => $this->get_return_url($order),
397 397
 			);
398
-		} catch ( WC_Stripe_Exception $e ) {
399
-			wc_add_notice( $e->getLocalizedMessage(), 'error' );
400
-			WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() );
398
+		} catch (WC_Stripe_Exception $e) {
399
+			wc_add_notice($e->getLocalizedMessage(), 'error');
400
+			WC_Stripe_Logger::log('Error: ' . $e->getMessage());
401 401
 
402
-			do_action( 'wc_gateway_stripe_process_payment_error', $e, $order );
402
+			do_action('wc_gateway_stripe_process_payment_error', $e, $order);
403 403
 
404
-			if ( $order->has_status( array( 'pending', 'failed' ) ) ) {
405
-				$this->send_failed_order_email( $order_id );
404
+			if ($order->has_status(array('pending', 'failed'))) {
405
+				$this->send_failed_order_email($order_id);
406 406
 			}
407 407
 
408 408
 			return array(
Please login to merge, or discard this patch.
includes/payment-methods/class-wc-gateway-stripe-sepa.php 1 patch
Spacing   +102 added lines, -102 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,9 +57,9 @@  discard block
 block discarded – undo
57 57
 	 */
58 58
 	public function __construct() {
59 59
 		$this->id                   = 'stripe_sepa';
60
-		$this->method_title         = __( 'Stripe SEPA Direct Debit', 'woocommerce-gateway-stripe' );
60
+		$this->method_title         = __('Stripe SEPA Direct Debit', 'woocommerce-gateway-stripe');
61 61
 		/* translators: link */
62
-		$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
+		$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'));
63 63
 		$this->supports             = array(
64 64
 			'products',
65 65
 			'refunds',
@@ -84,25 +84,25 @@  discard block
 block discarded – undo
84 84
 		// Load the settings.
85 85
 		$this->init_settings();
86 86
 
87
-		$main_settings              = get_option( 'woocommerce_stripe_settings' );
88
-		$this->title                = $this->get_option( 'title' );
89
-		$this->description          = $this->get_option( 'description' );
90
-		$this->enabled              = $this->get_option( 'enabled' );
91
-		$this->testmode             = ( ! empty( $main_settings['testmode'] ) && 'yes' === $main_settings['testmode'] ) ? true : false;
92
-		$this->saved_cards          = ( ! empty( $main_settings['saved_cards'] ) && 'yes' === $main_settings['saved_cards'] ) ? true : false;
93
-		$this->publishable_key      = ! empty( $main_settings['publishable_key'] ) ? $main_settings['publishable_key'] : '';
94
-		$this->secret_key           = ! empty( $main_settings['secret_key'] ) ? $main_settings['secret_key'] : '';
95
-		$this->statement_descriptor = ! empty( $main_settings['statement_descriptor'] ) ? $main_settings['statement_descriptor'] : '';
96
-
97
-		if ( $this->testmode ) {
98
-			$this->publishable_key = ! empty( $main_settings['test_publishable_key'] ) ? $main_settings['test_publishable_key'] : '';
99
-			$this->secret_key      = ! empty( $main_settings['test_secret_key'] ) ? $main_settings['test_secret_key'] : '';
87
+		$main_settings              = get_option('woocommerce_stripe_settings');
88
+		$this->title                = $this->get_option('title');
89
+		$this->description          = $this->get_option('description');
90
+		$this->enabled              = $this->get_option('enabled');
91
+		$this->testmode             = ( ! empty($main_settings['testmode']) && 'yes' === $main_settings['testmode']) ? true : false;
92
+		$this->saved_cards          = ( ! empty($main_settings['saved_cards']) && 'yes' === $main_settings['saved_cards']) ? true : false;
93
+		$this->publishable_key      = ! empty($main_settings['publishable_key']) ? $main_settings['publishable_key'] : '';
94
+		$this->secret_key           = ! empty($main_settings['secret_key']) ? $main_settings['secret_key'] : '';
95
+		$this->statement_descriptor = ! empty($main_settings['statement_descriptor']) ? $main_settings['statement_descriptor'] : '';
96
+
97
+		if ($this->testmode) {
98
+			$this->publishable_key = ! empty($main_settings['test_publishable_key']) ? $main_settings['test_publishable_key'] : '';
99
+			$this->secret_key      = ! empty($main_settings['test_secret_key']) ? $main_settings['test_secret_key'] : '';
100 100
 		}
101 101
 
102
-		add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) );
103
-		add_action( 'admin_notices', array( $this, 'check_environment' ) );
104
-		add_action( 'admin_head', array( $this, 'remove_admin_notice' ) );
105
-		add_action( 'wp_enqueue_scripts', array( $this, 'payment_scripts' ) );
102
+		add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options'));
103
+		add_action('admin_notices', array($this, 'check_environment'));
104
+		add_action('admin_head', array($this, 'remove_admin_notice'));
105
+		add_action('wp_enqueue_scripts', array($this, 'payment_scripts'));
106 106
 	}
107 107
 
108 108
 	/**
@@ -112,19 +112,19 @@  discard block
 block discarded – undo
112 112
 	 * @version 4.0.0
113 113
 	 */
114 114
 	public function check_environment() {
115
-		if ( ! current_user_can( 'manage_woocommerce' ) ) {
115
+		if ( ! current_user_can('manage_woocommerce')) {
116 116
 			return;
117 117
 		}
118 118
 
119 119
 		$environment_warning = $this->get_environment_warning();
120 120
 
121
-		if ( $environment_warning ) {
122
-			$this->add_admin_notice( 'bad_environment', 'error', $environment_warning );
121
+		if ($environment_warning) {
122
+			$this->add_admin_notice('bad_environment', 'error', $environment_warning);
123 123
 		}
124 124
 
125
-		foreach ( (array) $this->notices as $notice_key => $notice ) {
126
-			echo "<div class='" . esc_attr( $notice['class'] ) . "'><p>";
127
-			echo wp_kses( $notice['message'], array( 'a' => array( 'href' => array() ) ) );
125
+		foreach ((array) $this->notices as $notice_key => $notice) {
126
+			echo "<div class='" . esc_attr($notice['class']) . "'><p>";
127
+			echo wp_kses($notice['message'], array('a' => array('href' => array())));
128 128
 			echo '</p></div>';
129 129
 		}
130 130
 	}
@@ -137,8 +137,8 @@  discard block
 block discarded – undo
137 137
 	 * @version 4.0.0
138 138
 	 */
139 139
 	public function get_environment_warning() {
140
-		if ( 'yes' === $this->enabled && ! in_array( get_woocommerce_currency(), $this->get_supported_currency() ) ) {
141
-			$message = __( 'SEPA is enabled - it requires store currency to be set to Euros.', 'woocommerce-gateway-stripe' );
140
+		if ('yes' === $this->enabled && ! in_array(get_woocommerce_currency(), $this->get_supported_currency())) {
141
+			$message = __('SEPA is enabled - it requires store currency to be set to Euros.', 'woocommerce-gateway-stripe');
142 142
 
143 143
 			return $message;
144 144
 		}
@@ -154,9 +154,9 @@  discard block
 block discarded – undo
154 154
 	 * @return array
155 155
 	 */
156 156
 	public function get_supported_currency() {
157
-		return apply_filters( 'wc_stripe_sepa_supported_currencies', array(
157
+		return apply_filters('wc_stripe_sepa_supported_currencies', array(
158 158
 			'EUR',
159
-		) );
159
+		));
160 160
 	}
161 161
 
162 162
 	/**
@@ -167,11 +167,11 @@  discard block
 block discarded – undo
167 167
 	 * @return bool
168 168
 	 */
169 169
 	public function is_available() {
170
-		if ( ! in_array( get_woocommerce_currency(), $this->get_supported_currency() ) ) {
170
+		if ( ! in_array(get_woocommerce_currency(), $this->get_supported_currency())) {
171 171
 			return false;
172 172
 		}
173 173
 
174
-		if ( is_add_payment_method_page() && ! $this->saved_cards ) {
174
+		if (is_add_payment_method_page() && ! $this->saved_cards) {
175 175
 			return false;
176 176
 		}
177 177
 
@@ -192,7 +192,7 @@  discard block
 block discarded – undo
192 192
 
193 193
 		$icons_str .= $icons['sepa'];
194 194
 
195
-		return apply_filters( 'woocommerce_gateway_icon', $icons_str, $this->id );
195
+		return apply_filters('woocommerce_gateway_icon', $icons_str, $this->id);
196 196
 	}
197 197
 
198 198
 	/**
@@ -203,19 +203,19 @@  discard block
 block discarded – undo
203 203
 	 * @access public
204 204
 	 */
205 205
 	public function payment_scripts() {
206
-		if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) && ! is_add_payment_method_page() ) {
206
+		if ( ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order']) && ! is_add_payment_method_page()) {
207 207
 			return;
208 208
 		}
209 209
 
210
-		wp_enqueue_style( 'stripe_paymentfonts' );
211
-		wp_enqueue_script( 'woocommerce_stripe' );
210
+		wp_enqueue_style('stripe_paymentfonts');
211
+		wp_enqueue_script('woocommerce_stripe');
212 212
 	}
213 213
 
214 214
 	/**
215 215
 	 * Initialize Gateway Settings Form Fields.
216 216
 	 */
217 217
 	public function init_form_fields() {
218
-		$this->form_fields = require( WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-sepa-settings.php' );
218
+		$this->form_fields = require(WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-sepa-settings.php');
219 219
 	}
220 220
 
221 221
 	/**
@@ -227,7 +227,7 @@  discard block
 block discarded – undo
227 227
 	 */
228 228
 	public function mandate_display() {
229 229
 		/* translators: statement descriptor */
230
-		printf( __( 'By providing your IBAN and confirming this payment, you are authorizing %s and Stripe, our payment service provider, to send instructions to your bank to debit your account and your bank to debit your account in accordance with those instructions. You are entitled to a refund from your bank under the terms and conditions of your agreement with your bank. A refund must be claimed within 8 weeks starting from the date on which your account was debited.', 'woocommerce-gateway-stripe' ), WC_Stripe_Helper::clean_statement_descriptor( $this->statement_descriptor ) );
230
+		printf(__('By providing your IBAN and confirming this payment, you are authorizing %s and Stripe, our payment service provider, to send instructions to your bank to debit your account and your bank to debit your account in accordance with those instructions. You are entitled to a refund from your bank under the terms and conditions of your agreement with your bank. A refund must be claimed within 8 weeks starting from the date on which your account was debited.', 'woocommerce-gateway-stripe'), WC_Stripe_Helper::clean_statement_descriptor($this->statement_descriptor));
231 231
 	}
232 232
 
233 233
 	/**
@@ -238,24 +238,24 @@  discard block
 block discarded – undo
238 238
 	 */
239 239
 	public function form() {
240 240
 		?>
241
-		<fieldset id="wc-<?php echo esc_attr( $this->id ); ?>-form" class="wc-payment-form">
242
-			<?php do_action( 'woocommerce_credit_card_form_start', $this->id ); ?>
241
+		<fieldset id="wc-<?php echo esc_attr($this->id); ?>-form" class="wc-payment-form">
242
+			<?php do_action('woocommerce_credit_card_form_start', $this->id); ?>
243 243
 			<p class="wc-stripe-sepa-mandate" style="margin-bottom:40px;"><?php $this->mandate_display(); ?></p>
244 244
 			<p class="form-row form-row-wide">
245 245
 				<label for="stripe-sepa-owner">
246
-					<?php esc_html_e( 'IBAN Account Name.', 'woocommerce-gateway-stripe' ); ?> <span class="required">*</span>
246
+					<?php esc_html_e('IBAN Account Name.', 'woocommerce-gateway-stripe'); ?> <span class="required">*</span>
247 247
 				</label>
248 248
 				<input id="stripe-sepa-owner" name="stripe_sepa_owner" value="" style="border:1px solid #ddd;margin:5px 0;padding:10px 5px;background-color:#fff;outline:0;" />
249 249
 			</p>
250 250
 			<p class="form-row form-row-wide">
251 251
 				<label for="stripe-sepa-iban">
252
-					<?php esc_html_e( 'IBAN Account Number.', 'woocommerce-gateway-stripe' ); ?> <span class="required">*</span>
252
+					<?php esc_html_e('IBAN Account Number.', 'woocommerce-gateway-stripe'); ?> <span class="required">*</span>
253 253
 				</label>
254 254
 				<input id="stripe-sepa-iban" name="stripe_sepa_iban" value="" style="border:1px solid #ddd;margin:5px 0;padding:10px 5px;background-color:#fff;outline:0;" />
255 255
 			</p>
256 256
 			<!-- Used to display form errors -->
257 257
 			<div class="stripe-source-errors" role="alert"></div>
258
-			<?php do_action( 'woocommerce_credit_card_form_end', $this->id ); ?>
258
+			<?php do_action('woocommerce_credit_card_form_end', $this->id); ?>
259 259
 			<div class="clear"></div>
260 260
 		</fieldset>
261 261
 		<?php
@@ -267,42 +267,42 @@  discard block
 block discarded – undo
267 267
 	public function payment_fields() {
268 268
 		$user                 = wp_get_current_user();
269 269
 		$total                = WC()->cart->total;
270
-		$display_tokenization = $this->supports( 'tokenization' ) && is_checkout() && $this->saved_cards;
270
+		$display_tokenization = $this->supports('tokenization') && is_checkout() && $this->saved_cards;
271 271
 
272 272
 		// If paying from order, we need to get total from order not cart.
273
-		if ( isset( $_GET['pay_for_order'] ) && ! empty( $_GET['key'] ) ) {
274
-			$order = wc_get_order( wc_get_order_id_by_order_key( wc_clean( $_GET['key'] ) ) );
273
+		if (isset($_GET['pay_for_order']) && ! empty($_GET['key'])) {
274
+			$order = wc_get_order(wc_get_order_id_by_order_key(wc_clean($_GET['key'])));
275 275
 			$total = $order->get_total();
276 276
 		}
277 277
 
278
-		if ( is_add_payment_method_page() ) {
279
-			$pay_button_text = __( 'Add Payment', 'woocommerce-gateway-stripe' );
280
-			$total        = '';
278
+		if (is_add_payment_method_page()) {
279
+			$pay_button_text = __('Add Payment', 'woocommerce-gateway-stripe');
280
+			$total = '';
281 281
 		} else {
282 282
 			$pay_button_text = '';
283 283
 		}
284 284
 
285 285
 		echo '<div
286 286
 			id="stripe-sepa_debit-payment-data"
287
-			data-amount="' . esc_attr( WC_Stripe_Helper::get_stripe_amount( $total ) ) . '"
288
-			data-currency="' . esc_attr( strtolower( get_woocommerce_currency() ) ) . '">';
287
+			data-amount="' . esc_attr(WC_Stripe_Helper::get_stripe_amount($total)) . '"
288
+			data-currency="' . esc_attr(strtolower(get_woocommerce_currency())) . '">';
289 289
 
290
-		if ( $this->description ) {
291
-			if ( $this->testmode ) {
292
-				$this->description .= ' ' . __( 'TEST MODE ENABLED. In test mode, you can use IBAN number DE89370400440532013000.', 'woocommerce-gateway-stripe' );
293
-				$this->description  = trim( $this->description );
290
+		if ($this->description) {
291
+			if ($this->testmode) {
292
+				$this->description .= ' ' . __('TEST MODE ENABLED. In test mode, you can use IBAN number DE89370400440532013000.', 'woocommerce-gateway-stripe');
293
+				$this->description  = trim($this->description);
294 294
 			}
295
-			echo apply_filters( 'wc_stripe_description', wpautop( wp_kses_post( $this->description ) ) );
295
+			echo apply_filters('wc_stripe_description', wpautop(wp_kses_post($this->description)));
296 296
 		}
297 297
 
298
-		if ( $display_tokenization ) {
298
+		if ($display_tokenization) {
299 299
 			$this->tokenization_script();
300 300
 			$this->saved_payment_methods();
301 301
 		}
302 302
 
303 303
 		$this->form();
304 304
 
305
-		if ( apply_filters( 'wc_stripe_display_save_payment_method_checkbox', $display_tokenization ) && ! is_add_payment_method_page() && ! isset( $_GET['change_payment_method'] ) ) {
305
+		if (apply_filters('wc_stripe_display_save_payment_method_checkbox', $display_tokenization) && ! is_add_payment_method_page() && ! isset($_GET['change_payment_method'])) {
306 306
 			$this->save_payment_method_checkbox();
307 307
 		}
308 308
 
@@ -320,86 +320,86 @@  discard block
 block discarded – undo
320 320
 	 *
321 321
 	 * @return array|void
322 322
 	 */
323
-	public function process_payment( $order_id, $retry = true, $force_save_source = false ) {
323
+	public function process_payment($order_id, $retry = true, $force_save_source = false) {
324 324
 		try {
325
-			$order = wc_get_order( $order_id );
325
+			$order = wc_get_order($order_id);
326 326
 
327 327
 			// This comes from the create account checkbox in the checkout page.
328
-			$create_account = ! empty( $_POST['createaccount'] ) ? true : false;
328
+			$create_account = ! empty($_POST['createaccount']) ? true : false;
329 329
 
330
-			if ( $create_account ) {
330
+			if ($create_account) {
331 331
 				$new_customer_id     = WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id();
332
-				$new_stripe_customer = new WC_Stripe_Customer( $new_customer_id );
332
+				$new_stripe_customer = new WC_Stripe_Customer($new_customer_id);
333 333
 				$new_stripe_customer->create_customer();
334 334
 			}
335 335
 
336
-			$prepared_source = $this->prepare_source( $this->get_source_object(), get_current_user_id(), $force_save_source );
336
+			$prepared_source = $this->prepare_source($this->get_source_object(), get_current_user_id(), $force_save_source);
337 337
 
338
-			$this->save_source_to_order( $order, $prepared_source );
338
+			$this->save_source_to_order($order, $prepared_source);
339 339
 
340 340
 			// Result from Stripe API request.
341 341
 			$response = null;
342 342
 
343
-			if ( $order->get_total() > 0 ) {
343
+			if ($order->get_total() > 0) {
344 344
 				// This will throw exception if not valid.
345
-				$this->validate_minimum_order_amount( $order );
345
+				$this->validate_minimum_order_amount($order);
346 346
 
347
-				WC_Stripe_Logger::log( "Info: Begin processing payment for order $order_id for the amount of {$order->get_total()}" );
347
+				WC_Stripe_Logger::log("Info: Begin processing payment for order $order_id for the amount of {$order->get_total()}");
348 348
 
349 349
 				// Make the request.
350
-				$response = WC_Stripe_API::request( $this->generate_payment_request( $order, $prepared_source ) );
350
+				$response = WC_Stripe_API::request($this->generate_payment_request($order, $prepared_source));
351 351
 
352
-				if ( ! empty( $response->error ) ) {
352
+				if ( ! empty($response->error)) {
353 353
 					// If it is an API error such connection or server, let's retry.
354
-					if ( 'api_connection_error' === $response->error->type || 'api_error' === $response->error->type ) {
355
-						if ( $retry ) {
356
-							sleep( 5 );
357
-							return $this->process_payment( $order_id, false, $force_save_source );
354
+					if ('api_connection_error' === $response->error->type || 'api_error' === $response->error->type) {
355
+						if ($retry) {
356
+							sleep(5);
357
+							return $this->process_payment($order_id, false, $force_save_source);
358 358
 						} else {
359 359
 							$localized_message = 'API connection error and retries exhausted.';
360
-							$order->add_order_note( $localized_message );
361
-							throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message );
360
+							$order->add_order_note($localized_message);
361
+							throw new WC_Stripe_Exception(print_r($response, true), $localized_message);
362 362
 						}
363 363
 					}
364 364
 
365 365
 					// Customer param wrong? The user may have been deleted on stripe's end. Remove customer_id. Can be retried without.
366
-					if ( preg_match( '/No such customer/i', $response->error->message ) && $retry ) {
367
-						if ( WC_Stripe_Helper::is_pre_30() ) {
368
-							delete_user_meta( $order->customer_user, '_stripe_customer_id' );
369
-							delete_post_meta( $order_id, '_stripe_customer_id' );
366
+					if (preg_match('/No such customer/i', $response->error->message) && $retry) {
367
+						if (WC_Stripe_Helper::is_pre_30()) {
368
+							delete_user_meta($order->customer_user, '_stripe_customer_id');
369
+							delete_post_meta($order_id, '_stripe_customer_id');
370 370
 						} else {
371
-							delete_user_meta( $order->get_customer_id(), '_stripe_customer_id' );
372
-							$order->delete_meta_data( '_stripe_customer_id' );
371
+							delete_user_meta($order->get_customer_id(), '_stripe_customer_id');
372
+							$order->delete_meta_data('_stripe_customer_id');
373 373
 							$order->save();
374 374
 						}
375 375
 
376
-						return $this->process_payment( $order_id, false, $force_save_source );
377
-					} elseif ( preg_match( '/No such token/i', $response->error->message ) && $prepared_source->token_id ) {
376
+						return $this->process_payment($order_id, false, $force_save_source);
377
+					} elseif (preg_match('/No such token/i', $response->error->message) && $prepared_source->token_id) {
378 378
 						// Source param wrong? The CARD may have been deleted on stripe's end. Remove token and show message.
379
-						$wc_token = WC_Payment_Tokens::get( $prepared_source->token_id );
379
+						$wc_token = WC_Payment_Tokens::get($prepared_source->token_id);
380 380
 						$wc_token->delete();
381
-						$localized_message = __( 'This card is no longer available and has been removed.', 'woocommerce-gateway-stripe' );
382
-						$order->add_order_note( $localized_message );
383
-						throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message );
381
+						$localized_message = __('This card is no longer available and has been removed.', 'woocommerce-gateway-stripe');
382
+						$order->add_order_note($localized_message);
383
+						throw new WC_Stripe_Exception(print_r($response, true), $localized_message);
384 384
 					}
385 385
 
386 386
 					$localized_messages = WC_Stripe_Helper::get_localized_messages();
387 387
 
388
-					if ( 'card_error' === $response->error->type ) {
389
-						$localized_message = isset( $localized_messages[ $response->error->code ] ) ? $localized_messages[ $response->error->code ] : $response->error->message;
388
+					if ('card_error' === $response->error->type) {
389
+						$localized_message = isset($localized_messages[$response->error->code]) ? $localized_messages[$response->error->code] : $response->error->message;
390 390
 					} else {
391
-						$localized_message = isset( $localized_messages[ $response->error->type ] ) ? $localized_messages[ $response->error->type ] : $response->error->message;
391
+						$localized_message = isset($localized_messages[$response->error->type]) ? $localized_messages[$response->error->type] : $response->error->message;
392 392
 					}
393 393
 
394
-					$order->add_order_note( $localized_message );
394
+					$order->add_order_note($localized_message);
395 395
 
396
-					throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message );
396
+					throw new WC_Stripe_Exception(print_r($response, true), $localized_message);
397 397
 				}
398 398
 
399
-				do_action( 'wc_gateway_stripe_process_payment', $response, $order );
399
+				do_action('wc_gateway_stripe_process_payment', $response, $order);
400 400
 
401 401
 				// Process valid response.
402
-				$this->process_response( $response, $order );
402
+				$this->process_response($response, $order);
403 403
 			} else {
404 404
 				$order->payment_complete();
405 405
 			}
@@ -410,17 +410,17 @@  discard block
 block discarded – undo
410 410
 			// Return thank you page redirect.
411 411
 			return array(
412 412
 				'result'   => 'success',
413
-				'redirect' => $this->get_return_url( $order ),
413
+				'redirect' => $this->get_return_url($order),
414 414
 			);
415 415
 
416
-		} catch ( WC_Stripe_Exception $e ) {
417
-			wc_add_notice( $e->getLocalizedMessage(), 'error' );
418
-			WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() );
416
+		} catch (WC_Stripe_Exception $e) {
417
+			wc_add_notice($e->getLocalizedMessage(), 'error');
418
+			WC_Stripe_Logger::log('Error: ' . $e->getMessage());
419 419
 
420
-			do_action( 'wc_gateway_stripe_process_payment_error', $e, $order );
420
+			do_action('wc_gateway_stripe_process_payment_error', $e, $order);
421 421
 
422
-			if ( $order->has_status( array( 'pending', 'failed' ) ) ) {
423
-				$this->send_failed_order_email( $order_id );
422
+			if ($order->has_status(array('pending', 'failed'))) {
423
+				$this->send_failed_order_email($order_id);
424 424
 			}
425 425
 
426 426
 			return array(
Please login to merge, or discard this patch.
includes/payment-methods/class-wc-stripe-payment-request.php 1 patch
Spacing   +279 added lines, -279 removed lines patch added patch discarded remove patch
@@ -6,7 +6,7 @@  discard block
 block discarded – undo
6 6
  * @since   3.1.0
7 7
  */
8 8
 
9
-if ( ! defined( 'ABSPATH' ) ) {
9
+if ( ! defined('ABSPATH')) {
10 10
 	exit;
11 11
 }
12 12
 
@@ -56,39 +56,39 @@  discard block
 block discarded – undo
56 56
 	 * @version 4.0.0
57 57
 	 */
58 58
 	public function __construct() {
59
-		$this->stripe_settings         = get_option( 'woocommerce_stripe_settings', array() );
60
-		$this->testmode                = ( ! empty( $this->stripe_settings['testmode'] ) && 'yes' === $this->stripe_settings['testmode'] ) ? true : false;
61
-		$this->publishable_key         = ! empty( $this->stripe_settings['publishable_key'] ) ? $this->stripe_settings['publishable_key'] : '';
62
-		$this->stripe_checkout_enabled = isset( $this->stripe_settings['stripe_checkout'] ) && 'yes' === $this->stripe_settings['stripe_checkout'];
63
-		$this->total_label             = ! empty( $this->stripe_settings['statement_descriptor'] ) ? WC_Stripe_Helper::clean_statement_descriptor( $this->stripe_settings['statement_descriptor'] ) : '';
64
-
65
-		if ( $this->testmode ) {
66
-			$this->publishable_key = ! empty( $this->stripe_settings['test_publishable_key'] ) ? $this->stripe_settings['test_publishable_key'] : '';
59
+		$this->stripe_settings         = get_option('woocommerce_stripe_settings', array());
60
+		$this->testmode                = ( ! empty($this->stripe_settings['testmode']) && 'yes' === $this->stripe_settings['testmode']) ? true : false;
61
+		$this->publishable_key         = ! empty($this->stripe_settings['publishable_key']) ? $this->stripe_settings['publishable_key'] : '';
62
+		$this->stripe_checkout_enabled = isset($this->stripe_settings['stripe_checkout']) && 'yes' === $this->stripe_settings['stripe_checkout'];
63
+		$this->total_label             = ! empty($this->stripe_settings['statement_descriptor']) ? WC_Stripe_Helper::clean_statement_descriptor($this->stripe_settings['statement_descriptor']) : '';
64
+
65
+		if ($this->testmode) {
66
+			$this->publishable_key = ! empty($this->stripe_settings['test_publishable_key']) ? $this->stripe_settings['test_publishable_key'] : '';
67 67
 		}
68 68
 
69 69
 		// If both site title and statement descriptor is not set. Fallback.
70
-		if ( empty( $this->total_label ) ) {
70
+		if (empty($this->total_label)) {
71 71
 			$this->total_label = $_SERVER['SERVER_NAME'];
72 72
 		}
73 73
 
74
-		$this->total_label = str_replace( "'", '', $this->total_label ) . apply_filters( 'wc_stripe_payment_request_total_label_suffix', ' (via WooCommerce)' );
74
+		$this->total_label = str_replace("'", '', $this->total_label) . apply_filters('wc_stripe_payment_request_total_label_suffix', ' (via WooCommerce)');
75 75
 
76 76
 		// Checks if Stripe Gateway is enabled.
77
-		if ( empty( $this->stripe_settings ) || ( isset( $this->stripe_settings['enabled'] ) && 'yes' !== $this->stripe_settings['enabled'] ) ) {
77
+		if (empty($this->stripe_settings) || (isset($this->stripe_settings['enabled']) && 'yes' !== $this->stripe_settings['enabled'])) {
78 78
 			return;
79 79
 		}
80 80
 
81 81
 		// Checks if Payment Request is enabled.
82
-		if ( ! isset( $this->stripe_settings['payment_request'] ) || 'yes' !== $this->stripe_settings['payment_request'] ) {
82
+		if ( ! isset($this->stripe_settings['payment_request']) || 'yes' !== $this->stripe_settings['payment_request']) {
83 83
 			return;
84 84
 		}
85 85
 
86 86
 		// Don't load for change payment method page.
87
-		if ( isset( $_GET['change_payment_method'] ) ) {
87
+		if (isset($_GET['change_payment_method'])) {
88 88
 			return;
89 89
 		}
90 90
 
91
-		add_action( 'woocommerce_init', array( $this, 'set_session' ) );
91
+		add_action('woocommerce_init', array($this, 'set_session'));
92 92
 		$this->init();
93 93
 	}
94 94
 
@@ -99,15 +99,15 @@  discard block
 block discarded – undo
99 99
 	 * @since 4.0.0
100 100
 	 */
101 101
 	public function set_session() {
102
-		if ( ! is_user_logged_in() ) {
102
+		if ( ! is_user_logged_in()) {
103 103
 			$wc_session = new WC_Session_Handler();
104 104
 
105
-			if ( version_compare( WC_VERSION, '3.3', '>=' ) ) {
105
+			if (version_compare(WC_VERSION, '3.3', '>=')) {
106 106
 				$wc_session->init();
107 107
 			}
108 108
 
109
-			if ( ! $wc_session->has_session() ) {
110
-				$wc_session->set_customer_session_cookie( true );
109
+			if ( ! $wc_session->has_session()) {
110
+				$wc_session->set_customer_session_cookie(true);
111 111
 			}
112 112
 		}
113 113
 	}
@@ -119,40 +119,40 @@  discard block
 block discarded – undo
119 119
 	 * @version 4.0.0
120 120
 	 */
121 121
 	public function init() {
122
-		add_action( 'wp_enqueue_scripts', array( $this, 'scripts' ) );
122
+		add_action('wp_enqueue_scripts', array($this, 'scripts'));
123 123
 
124 124
 		/*
125 125
 		 * In order to display the Payment Request button in the correct position,
126 126
 		 * a new hook was added to WooCommerce 3.0. In older versions of WooCommerce,
127 127
 		 * CSS is used to position the button.
128 128
 		 */
129
-		if ( WC_Stripe_Helper::is_pre_30() ) {
130
-			add_action( 'woocommerce_after_add_to_cart_button', array( $this, 'display_payment_request_button_html' ), 1 );
131
-			add_action( 'woocommerce_after_add_to_cart_button', array( $this, 'display_payment_request_button_separator_html' ), 2 );
129
+		if (WC_Stripe_Helper::is_pre_30()) {
130
+			add_action('woocommerce_after_add_to_cart_button', array($this, 'display_payment_request_button_html'), 1);
131
+			add_action('woocommerce_after_add_to_cart_button', array($this, 'display_payment_request_button_separator_html'), 2);
132 132
 		} else {
133
-			add_action( 'woocommerce_after_add_to_cart_quantity', array( $this, 'display_payment_request_button_html' ), 1 );
134
-			add_action( 'woocommerce_after_add_to_cart_quantity', array( $this, 'display_payment_request_button_separator_html' ), 2 );
133
+			add_action('woocommerce_after_add_to_cart_quantity', array($this, 'display_payment_request_button_html'), 1);
134
+			add_action('woocommerce_after_add_to_cart_quantity', array($this, 'display_payment_request_button_separator_html'), 2);
135 135
 		}
136 136
 
137
-		add_action( 'woocommerce_proceed_to_checkout', array( $this, 'display_payment_request_button_html' ), 1 );
138
-		add_action( 'woocommerce_proceed_to_checkout', array( $this, 'display_payment_request_button_separator_html' ), 2 );
137
+		add_action('woocommerce_proceed_to_checkout', array($this, 'display_payment_request_button_html'), 1);
138
+		add_action('woocommerce_proceed_to_checkout', array($this, 'display_payment_request_button_separator_html'), 2);
139 139
 
140
-		add_action( 'woocommerce_checkout_before_customer_details', array( $this, 'display_payment_request_button_html' ), 1 );
141
-		add_action( 'woocommerce_checkout_before_customer_details', array( $this, 'display_payment_request_button_separator_html' ), 2 );
140
+		add_action('woocommerce_checkout_before_customer_details', array($this, 'display_payment_request_button_html'), 1);
141
+		add_action('woocommerce_checkout_before_customer_details', array($this, 'display_payment_request_button_separator_html'), 2);
142 142
 
143
-		add_action( 'wc_ajax_wc_stripe_get_cart_details', array( $this, 'ajax_get_cart_details' ) );
144
-		add_action( 'wc_ajax_wc_stripe_get_shipping_options', array( $this, 'ajax_get_shipping_options' ) );
145
-		add_action( 'wc_ajax_wc_stripe_update_shipping_method', array( $this, 'ajax_update_shipping_method' ) );
146
-		add_action( 'wc_ajax_wc_stripe_create_order', array( $this, 'ajax_create_order' ) );
147
-		add_action( 'wc_ajax_wc_stripe_add_to_cart', array( $this, 'ajax_add_to_cart' ) );
148
-		add_action( 'wc_ajax_wc_stripe_get_selected_product_data', array( $this, 'ajax_get_selected_product_data' ) );
149
-		add_action( 'wc_ajax_wc_stripe_clear_cart', array( $this, 'ajax_clear_cart' ) );
150
-		add_action( 'wc_ajax_wc_stripe_log_errors', array( $this, 'ajax_log_errors' ) );
143
+		add_action('wc_ajax_wc_stripe_get_cart_details', array($this, 'ajax_get_cart_details'));
144
+		add_action('wc_ajax_wc_stripe_get_shipping_options', array($this, 'ajax_get_shipping_options'));
145
+		add_action('wc_ajax_wc_stripe_update_shipping_method', array($this, 'ajax_update_shipping_method'));
146
+		add_action('wc_ajax_wc_stripe_create_order', array($this, 'ajax_create_order'));
147
+		add_action('wc_ajax_wc_stripe_add_to_cart', array($this, 'ajax_add_to_cart'));
148
+		add_action('wc_ajax_wc_stripe_get_selected_product_data', array($this, 'ajax_get_selected_product_data'));
149
+		add_action('wc_ajax_wc_stripe_clear_cart', array($this, 'ajax_clear_cart'));
150
+		add_action('wc_ajax_wc_stripe_log_errors', array($this, 'ajax_log_errors'));
151 151
 
152
-		add_filter( 'woocommerce_gateway_title', array( $this, 'filter_gateway_title' ), 10, 2 );
153
-		add_filter( 'woocommerce_validate_postcode', array( $this, 'postal_code_validation' ), 10, 3 );
152
+		add_filter('woocommerce_gateway_title', array($this, 'filter_gateway_title'), 10, 2);
153
+		add_filter('woocommerce_validate_postcode', array($this, 'postal_code_validation'), 10, 3);
154 154
 
155
-		add_action( 'woocommerce_checkout_order_processed', array( $this, 'add_order_meta' ), 10, 2 );
155
+		add_action('woocommerce_checkout_order_processed', array($this, 'add_order_meta'), 10, 2);
156 156
 	}
157 157
 
158 158
 	/**
@@ -163,7 +163,7 @@  discard block
 block discarded – undo
163 163
 	 * @return string
164 164
 	 */
165 165
 	public function get_button_type() {
166
-		return isset( $this->stripe_settings['payment_request_button_type'] ) ? $this->stripe_settings['payment_request_button_type'] : 'default';
166
+		return isset($this->stripe_settings['payment_request_button_type']) ? $this->stripe_settings['payment_request_button_type'] : 'default';
167 167
 	}
168 168
 
169 169
 	/**
@@ -174,7 +174,7 @@  discard block
 block discarded – undo
174 174
 	 * @return string
175 175
 	 */
176 176
 	public function get_button_theme() {
177
-		return isset( $this->stripe_settings['payment_request_button_theme'] ) ? $this->stripe_settings['payment_request_button_theme'] : 'dark';
177
+		return isset($this->stripe_settings['payment_request_button_theme']) ? $this->stripe_settings['payment_request_button_theme'] : 'dark';
178 178
 	}
179 179
 
180 180
 	/**
@@ -185,7 +185,7 @@  discard block
 block discarded – undo
185 185
 	 * @return string
186 186
 	 */
187 187
 	public function get_button_height() {
188
-		return isset( $this->stripe_settings['payment_request_button_height'] ) ? str_replace( 'px', '', $this->stripe_settings['payment_request_button_height'] ) : '64';
188
+		return isset($this->stripe_settings['payment_request_button_height']) ? str_replace('px', '', $this->stripe_settings['payment_request_button_height']) : '64';
189 189
 	}
190 190
 
191 191
 	/**
@@ -195,40 +195,40 @@  discard block
 block discarded – undo
195 195
 	 * @version 4.0.0
196 196
 	 */
197 197
 	public function get_product_data() {
198
-		if ( ! is_product() ) {
198
+		if ( ! is_product()) {
199 199
 			return false;
200 200
 		}
201 201
 
202 202
 		global $post;
203 203
 
204
-		$product = wc_get_product( $post->ID );
204
+		$product = wc_get_product($post->ID);
205 205
 
206 206
 		$data  = array();
207 207
 		$items = array();
208 208
 
209 209
 		$items[] = array(
210 210
 			'label'  => WC_Stripe_Helper::is_pre_30() ? $product->name : $product->get_name(),
211
-			'amount' => WC_Stripe_Helper::get_stripe_amount( WC_Stripe_Helper::is_pre_30() ? $product->price : $product->get_price() ),
211
+			'amount' => WC_Stripe_Helper::get_stripe_amount(WC_Stripe_Helper::is_pre_30() ? $product->price : $product->get_price()),
212 212
 		);
213 213
 
214
-		if ( wc_tax_enabled() ) {
214
+		if (wc_tax_enabled()) {
215 215
 			$items[] = array(
216
-				'label'   => __( 'Tax', 'woocommerce-gateway-stripe' ),
216
+				'label'   => __('Tax', 'woocommerce-gateway-stripe'),
217 217
 				'amount'  => 0,
218 218
 				'pending' => true,
219 219
 			);
220 220
 		}
221 221
 
222
-		if ( wc_shipping_enabled() && $product->needs_shipping() ) {
222
+		if (wc_shipping_enabled() && $product->needs_shipping()) {
223 223
 			$items[] = array(
224
-				'label'   => __( 'Shipping', 'woocommerce-gateway-stripe' ),
224
+				'label'   => __('Shipping', 'woocommerce-gateway-stripe'),
225 225
 				'amount'  => 0,
226 226
 				'pending' => true,
227 227
 			);
228 228
 
229
-			$data['shippingOptions']  = array(
229
+			$data['shippingOptions'] = array(
230 230
 				'id'     => 'pending',
231
-				'label'  => __( 'Pending', 'woocommerce-gateway-stripe' ),
231
+				'label'  => __('Pending', 'woocommerce-gateway-stripe'),
232 232
 				'detail' => '',
233 233
 				'amount' => 0,
234 234
 			);
@@ -236,41 +236,41 @@  discard block
 block discarded – undo
236 236
 
237 237
 		$data['displayItems'] = $items;
238 238
 		$data['total'] = array(
239
-			'label'   => apply_filters( 'wc_stripe_payment_request_total_label', $this->total_label ),
240
-			'amount'  => WC_Stripe_Helper::get_stripe_amount( WC_Stripe_Helper::is_pre_30() ? $product->price : $product->get_price() ),
239
+			'label'   => apply_filters('wc_stripe_payment_request_total_label', $this->total_label),
240
+			'amount'  => WC_Stripe_Helper::get_stripe_amount(WC_Stripe_Helper::is_pre_30() ? $product->price : $product->get_price()),
241 241
 			'pending' => true,
242 242
 		);
243 243
 
244
-		$data['requestShipping'] = ( wc_shipping_enabled() && $product->needs_shipping() );
245
-		$data['currency']        = strtolower( get_woocommerce_currency() );
246
-		$data['country_code']    = substr( get_option( 'woocommerce_default_country' ), 0, 2 );
244
+		$data['requestShipping'] = (wc_shipping_enabled() && $product->needs_shipping());
245
+		$data['currency']        = strtolower(get_woocommerce_currency());
246
+		$data['country_code']    = substr(get_option('woocommerce_default_country'), 0, 2);
247 247
 
248
-		return apply_filters( 'wc_stripe_payment_request_product_data', $data, $product );
248
+		return apply_filters('wc_stripe_payment_request_product_data', $data, $product);
249 249
 	}
250 250
 
251 251
 	/**
252 252
 	 * Filters the gateway title to reflect Payment Request type
253 253
 	 *
254 254
 	 */
255
-	public function filter_gateway_title( $title, $id ) {
255
+	public function filter_gateway_title($title, $id) {
256 256
 		global $post;
257 257
 
258
-		if ( ! is_object( $post ) ) {
258
+		if ( ! is_object($post)) {
259 259
 			return $title;
260 260
 		}
261 261
 
262
-		if ( WC_Stripe_Helper::is_pre_30() ) {
263
-			$method_title = get_post_meta( $post->ID, '_payment_method_title', true );
262
+		if (WC_Stripe_Helper::is_pre_30()) {
263
+			$method_title = get_post_meta($post->ID, '_payment_method_title', true);
264 264
 		} else {
265
-			$order        = wc_get_order( $post->ID );
266
-			$method_title = is_object( $order ) ? $order->get_payment_method_title() : '';
265
+			$order        = wc_get_order($post->ID);
266
+			$method_title = is_object($order) ? $order->get_payment_method_title() : '';
267 267
 		}
268 268
 
269
-		if ( 'stripe' === $id && ! empty( $method_title ) && 'Apple Pay (Stripe)' === $method_title ) {
269
+		if ('stripe' === $id && ! empty($method_title) && 'Apple Pay (Stripe)' === $method_title) {
270 270
 			return $method_title;
271 271
 		}
272 272
 
273
-		if ( 'stripe' === $id && ! empty( $method_title ) && 'Chrome Payment Request (Stripe)' === $method_title ) {
273
+		if ('stripe' === $id && ! empty($method_title) && 'Chrome Payment Request (Stripe)' === $method_title) {
274 274
 			return $method_title;
275 275
 		}
276 276
 
@@ -283,16 +283,16 @@  discard block
 block discarded – undo
283 283
 	 * @since 3.1.4
284 284
 	 * @version 4.0.0
285 285
 	 */
286
-	public function postal_code_validation( $valid, $postcode, $country ) {
286
+	public function postal_code_validation($valid, $postcode, $country) {
287 287
 		$gateways = WC()->payment_gateways->get_available_payment_gateways();
288 288
 
289
-		if ( ! isset( $gateways['stripe'] ) ) {
289
+		if ( ! isset($gateways['stripe'])) {
290 290
 			return $valid;
291 291
 		}
292 292
 
293
-		$payment_request_type = isset( $_POST['payment_request_type'] ) ? wc_clean( $_POST['payment_request_type'] ) : '';
293
+		$payment_request_type = isset($_POST['payment_request_type']) ? wc_clean($_POST['payment_request_type']) : '';
294 294
 
295
-		if ( 'apple_pay' !== $payment_request_type ) {
295
+		if ('apple_pay' !== $payment_request_type) {
296 296
 			return $valid;
297 297
 		}
298 298
 
@@ -302,7 +302,7 @@  discard block
 block discarded – undo
302 302
 		 * the order and not let it go through. The remedy for now is just to remove this validation.
303 303
 		 * Note that this only works with shipping providers that don't validate full postal codes.
304 304
 		 */
305
-		if ( 'GB' === $country || 'CA' === $country ) {
305
+		if ('GB' === $country || 'CA' === $country) {
306 306
 			return true;
307 307
 		}
308 308
 
@@ -317,29 +317,29 @@  discard block
 block discarded – undo
317 317
 	 * @param int $order_id
318 318
 	 * @param array $posted_data The posted data from checkout form.
319 319
 	 */
320
-	public function add_order_meta( $order_id, $posted_data ) {
321
-		if ( empty( $_POST['payment_request_type'] ) ) {
320
+	public function add_order_meta($order_id, $posted_data) {
321
+		if (empty($_POST['payment_request_type'])) {
322 322
 			return;
323 323
 		}
324 324
 
325
-		$order = wc_get_order( $order_id );
325
+		$order = wc_get_order($order_id);
326 326
 
327
-		$payment_request_type = wc_clean( $_POST['payment_request_type'] );
327
+		$payment_request_type = wc_clean($_POST['payment_request_type']);
328 328
 
329
-		if ( 'apple_pay' === $payment_request_type ) {
330
-			if ( WC_Stripe_Helper::is_pre_30() ) {
331
-				update_post_meta( $order_id, '_payment_method_title', 'Apple Pay (Stripe)' );
329
+		if ('apple_pay' === $payment_request_type) {
330
+			if (WC_Stripe_Helper::is_pre_30()) {
331
+				update_post_meta($order_id, '_payment_method_title', 'Apple Pay (Stripe)');
332 332
 			} else {
333
-				$order->set_payment_method_title( 'Apple Pay (Stripe)' );
333
+				$order->set_payment_method_title('Apple Pay (Stripe)');
334 334
 				$order->save();
335 335
 			}
336 336
 		}
337 337
 
338
-		if ( 'payment_request_api' === $payment_request_type ) {
339
-			if ( WC_Stripe_Helper::is_pre_30() ) {
340
-				update_post_meta( $order_id, '_payment_method_title', 'Chrome Payment Request (Stripe)' );
338
+		if ('payment_request_api' === $payment_request_type) {
339
+			if (WC_Stripe_Helper::is_pre_30()) {
340
+				update_post_meta($order_id, '_payment_method_title', 'Chrome Payment Request (Stripe)');
341 341
 			} else {
342
-				$order->set_payment_method_title( 'Chrome Payment Request (Stripe)' );
342
+				$order->set_payment_method_title('Chrome Payment Request (Stripe)');
343 343
 				$order->save();
344 344
 			}
345 345
 		}
@@ -353,11 +353,11 @@  discard block
 block discarded – undo
353 353
 	 * @return array
354 354
 	 */
355 355
 	public function supported_product_types() {
356
-		return apply_filters( 'wc_stripe_payment_request_supported_types', array(
356
+		return apply_filters('wc_stripe_payment_request_supported_types', array(
357 357
 			'simple',
358 358
 			'variable',
359 359
 			'variation',
360
-		) );
360
+		));
361 361
 	}
362 362
 
363 363
 	/**
@@ -368,15 +368,15 @@  discard block
 block discarded – undo
368 368
 	 * @return bool
369 369
 	 */
370 370
 	public function allowed_items_in_cart() {
371
-		foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {
372
-			$_product = apply_filters( 'woocommerce_cart_item_product', $cart_item['data'], $cart_item, $cart_item_key );
371
+		foreach (WC()->cart->get_cart() as $cart_item_key => $cart_item) {
372
+			$_product = apply_filters('woocommerce_cart_item_product', $cart_item['data'], $cart_item, $cart_item_key);
373 373
 
374
-			if ( ! in_array( ( WC_Stripe_Helper::is_pre_30() ? $_product->product_type : $_product->get_type() ), $this->supported_product_types() ) ) {
374
+			if ( ! in_array((WC_Stripe_Helper::is_pre_30() ? $_product->product_type : $_product->get_type()), $this->supported_product_types())) {
375 375
 				return false;
376 376
 			}
377 377
 
378 378
 			// Pre Orders compatbility where we don't support charge upon release.
379
-			if ( class_exists( 'WC_Pre_Orders_Order' ) && WC_Pre_Orders_Cart::cart_contains_pre_order() && WC_Pre_Orders_Product::product_is_charged_upon_release( WC_Pre_Orders_Cart::get_pre_order_product() ) ) {
379
+			if (class_exists('WC_Pre_Orders_Order') && WC_Pre_Orders_Cart::cart_contains_pre_order() && WC_Pre_Orders_Product::product_is_charged_upon_release(WC_Pre_Orders_Cart::get_pre_order_product())) {
380 380
 				return false;
381 381
 			}
382 382
 		}
@@ -391,71 +391,71 @@  discard block
 block discarded – undo
391 391
 	 * @version 4.0.0
392 392
 	 */
393 393
 	public function scripts() {
394
-		if ( ! is_product() && ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) ) {
394
+		if ( ! is_product() && ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order'])) {
395 395
 			return;
396 396
 		}
397 397
 
398
-		if ( is_product() ) {
398
+		if (is_product()) {
399 399
 			global $post;
400 400
 
401
-			$product = wc_get_product( $post->ID );
401
+			$product = wc_get_product($post->ID);
402 402
 
403
-			if ( ! is_object( $product ) || ! in_array( ( WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type() ), $this->supported_product_types() ) ) {
403
+			if ( ! is_object($product) || ! in_array((WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type()), $this->supported_product_types())) {
404 404
 				return;
405 405
 			}
406 406
 
407
-			if ( apply_filters( 'wc_stripe_hide_payment_request_on_product_page', false ) ) {
407
+			if (apply_filters('wc_stripe_hide_payment_request_on_product_page', false)) {
408 408
 				return;
409 409
 			}
410 410
 		}
411 411
 
412
-		$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
412
+		$suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';
413 413
 
414
-		wp_register_script( 'stripe', 'https://js.stripe.com/v3/', '', '3.0', true );
415
-		wp_register_script( 'wc_stripe_payment_request', plugins_url( 'assets/js/stripe-payment-request' . $suffix . '.js', WC_STRIPE_MAIN_FILE ), array( 'jquery', 'stripe' ), WC_STRIPE_VERSION, true );
414
+		wp_register_script('stripe', 'https://js.stripe.com/v3/', '', '3.0', true);
415
+		wp_register_script('wc_stripe_payment_request', plugins_url('assets/js/stripe-payment-request' . $suffix . '.js', WC_STRIPE_MAIN_FILE), array('jquery', 'stripe'), WC_STRIPE_VERSION, true);
416 416
 
417 417
 		wp_localize_script(
418 418
 			'wc_stripe_payment_request',
419 419
 			'wc_stripe_payment_request_params',
420 420
 			array(
421
-				'ajax_url' => WC_AJAX::get_endpoint( '%%endpoint%%' ),
421
+				'ajax_url' => WC_AJAX::get_endpoint('%%endpoint%%'),
422 422
 				'stripe'   => array(
423 423
 					'key'                => $this->publishable_key,
424
-					'allow_prepaid_card' => apply_filters( 'wc_stripe_allow_prepaid_card', true ) ? 'yes' : 'no',
424
+					'allow_prepaid_card' => apply_filters('wc_stripe_allow_prepaid_card', true) ? 'yes' : 'no',
425 425
 				),
426 426
 				'nonce'    => array(
427
-					'payment'                        => wp_create_nonce( 'wc-stripe-payment-request' ),
428
-					'shipping'                       => wp_create_nonce( 'wc-stripe-payment-request-shipping' ),
429
-					'update_shipping'                => wp_create_nonce( 'wc-stripe-update-shipping-method' ),
430
-					'checkout'                       => wp_create_nonce( 'woocommerce-process_checkout' ),
431
-					'add_to_cart'                    => wp_create_nonce( 'wc-stripe-add-to-cart' ),
432
-					'get_selected_product_data'      => wp_create_nonce( 'wc-stripe-get-selected-product-data' ),
433
-					'log_errors'                     => wp_create_nonce( 'wc-stripe-log-errors' ),
434
-					'clear_cart'                     => wp_create_nonce( 'wc-stripe-clear-cart' ),
427
+					'payment'                        => wp_create_nonce('wc-stripe-payment-request'),
428
+					'shipping'                       => wp_create_nonce('wc-stripe-payment-request-shipping'),
429
+					'update_shipping'                => wp_create_nonce('wc-stripe-update-shipping-method'),
430
+					'checkout'                       => wp_create_nonce('woocommerce-process_checkout'),
431
+					'add_to_cart'                    => wp_create_nonce('wc-stripe-add-to-cart'),
432
+					'get_selected_product_data'      => wp_create_nonce('wc-stripe-get-selected-product-data'),
433
+					'log_errors'                     => wp_create_nonce('wc-stripe-log-errors'),
434
+					'clear_cart'                     => wp_create_nonce('wc-stripe-clear-cart'),
435 435
 				),
436 436
 				'i18n'     => array(
437
-					'no_prepaid_card'  => __( 'Sorry, we\'re not accepting prepaid cards at this time.', 'woocommerce-gateway-stripe' ),
437
+					'no_prepaid_card'  => __('Sorry, we\'re not accepting prepaid cards at this time.', 'woocommerce-gateway-stripe'),
438 438
 					/* translators: Do not translate the [option] placeholder */
439
-					'unknown_shipping' => __( 'Unknown shipping option "[option]".', 'woocommerce-gateway-stripe' ),
439
+					'unknown_shipping' => __('Unknown shipping option "[option]".', 'woocommerce-gateway-stripe'),
440 440
 				),
441 441
 				'checkout' => array(
442 442
 					'url'            => wc_get_checkout_url(),
443
-					'currency_code'  => strtolower( get_woocommerce_currency() ),
444
-					'country_code'   => substr( get_option( 'woocommerce_default_country' ), 0, 2 ),
443
+					'currency_code'  => strtolower(get_woocommerce_currency()),
444
+					'country_code'   => substr(get_option('woocommerce_default_country'), 0, 2),
445 445
 					'needs_shipping' => WC()->cart->needs_shipping() ? 'yes' : 'no',
446 446
 				),
447 447
 				'button' => array(
448 448
 					'type'   => $this->get_button_type(),
449 449
 					'theme'  => $this->get_button_theme(),
450 450
 					'height' => $this->get_button_height(),
451
-					'locale' => substr( get_locale(), 0, 2 ), // Default format is en_US.
451
+					'locale' => substr(get_locale(), 0, 2), // Default format is en_US.
452 452
 				),
453 453
 				'is_product_page' => is_product(),
454 454
 				'product'         => $this->get_product_data(),
455 455
 			)
456 456
 		);
457 457
 
458
-		wp_enqueue_script( 'wc_stripe_payment_request' );
458
+		wp_enqueue_script('wc_stripe_payment_request');
459 459
 	}
460 460
 
461 461
 	/**
@@ -467,39 +467,39 @@  discard block
 block discarded – undo
467 467
 	public function display_payment_request_button_html() {
468 468
 		$gateways = WC()->payment_gateways->get_available_payment_gateways();
469 469
 
470
-		if ( ! isset( $gateways['stripe'] ) ) {
470
+		if ( ! isset($gateways['stripe'])) {
471 471
 			return;
472 472
 		}
473 473
 
474
-		if ( ! is_cart() && ! is_checkout() && ! is_product() && ! isset( $_GET['pay_for_order'] ) ) {
474
+		if ( ! is_cart() && ! is_checkout() && ! is_product() && ! isset($_GET['pay_for_order'])) {
475 475
 			return;
476 476
 		}
477 477
 
478
-		if ( is_product() && apply_filters( 'wc_stripe_hide_payment_request_on_product_page', false ) ) {
478
+		if (is_product() && apply_filters('wc_stripe_hide_payment_request_on_product_page', false)) {
479 479
 			return;
480 480
 		}
481 481
 
482
-		if ( is_checkout() && ! apply_filters( 'wc_stripe_show_payment_request_on_checkout', false ) ) {
482
+		if (is_checkout() && ! apply_filters('wc_stripe_show_payment_request_on_checkout', false)) {
483 483
 			return;
484 484
 		}
485 485
 
486
-		if ( is_product() ) {
486
+		if (is_product()) {
487 487
 			global $post;
488 488
 
489
-			$product = wc_get_product( $post->ID );
489
+			$product = wc_get_product($post->ID);
490 490
 
491
-			if ( ! is_object( $product ) || ! in_array( ( WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type() ), $this->supported_product_types() ) ) {
491
+			if ( ! is_object($product) || ! in_array((WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type()), $this->supported_product_types())) {
492 492
 				return;
493 493
 			}
494 494
 
495 495
 			// Pre Orders charge upon release not supported.
496
-			if ( class_exists( 'WC_Pre_Orders_Order' ) && WC_Pre_Orders_Product::product_is_charged_upon_release( $product ) ) {
497
-				WC_Stripe_Logger::log( 'Pre Order charge upon release is not supported. ( Payment Request button disabled )' );
496
+			if (class_exists('WC_Pre_Orders_Order') && WC_Pre_Orders_Product::product_is_charged_upon_release($product)) {
497
+				WC_Stripe_Logger::log('Pre Order charge upon release is not supported. ( Payment Request button disabled )');
498 498
 				return;
499 499
 			}
500 500
 		} else {
501
-			if ( ! $this->allowed_items_in_cart() ) {
502
-				WC_Stripe_Logger::log( 'Items in the cart has unsupported product type ( Payment Request button disabled )' );
501
+			if ( ! $this->allowed_items_in_cart()) {
502
+				WC_Stripe_Logger::log('Items in the cart has unsupported product type ( Payment Request button disabled )');
503 503
 				return;
504 504
 			}
505 505
 		}
@@ -521,44 +521,44 @@  discard block
 block discarded – undo
521 521
 	public function display_payment_request_button_separator_html() {
522 522
 		$gateways = WC()->payment_gateways->get_available_payment_gateways();
523 523
 
524
-		if ( ! isset( $gateways['stripe'] ) ) {
524
+		if ( ! isset($gateways['stripe'])) {
525 525
 			return;
526 526
 		}
527 527
 
528
-		if ( ! is_cart() && ! is_checkout() && ! is_product() && ! isset( $_GET['pay_for_order'] ) ) {
528
+		if ( ! is_cart() && ! is_checkout() && ! is_product() && ! isset($_GET['pay_for_order'])) {
529 529
 			return;
530 530
 		}
531 531
 
532
-		if ( is_product() && apply_filters( 'wc_stripe_hide_payment_request_on_product_page', false ) ) {
532
+		if (is_product() && apply_filters('wc_stripe_hide_payment_request_on_product_page', false)) {
533 533
 			return;
534 534
 		}
535 535
 
536
-		if ( is_checkout() && ! apply_filters( 'wc_stripe_show_payment_request_on_checkout', false ) ) {
536
+		if (is_checkout() && ! apply_filters('wc_stripe_show_payment_request_on_checkout', false)) {
537 537
 			return;
538 538
 		}
539 539
 
540
-		if ( is_product() ) {
540
+		if (is_product()) {
541 541
 			global $post;
542 542
 
543
-			$product = wc_get_product( $post->ID );
543
+			$product = wc_get_product($post->ID);
544 544
 
545
-			if ( ! is_object( $product ) || ! in_array( ( WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type() ), $this->supported_product_types() ) ) {
545
+			if ( ! is_object($product) || ! in_array((WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type()), $this->supported_product_types())) {
546 546
 				return;
547 547
 			}
548 548
 
549 549
 			// Pre Orders charge upon release not supported.
550
-			if ( class_exists( 'WC_Pre_Orders_Order' ) && WC_Pre_Orders_Product::product_is_charged_upon_release( $product ) ) {
551
-				WC_Stripe_Logger::log( 'Pre Order charge upon release is not supported. ( Payment Request button disabled )' );
550
+			if (class_exists('WC_Pre_Orders_Order') && WC_Pre_Orders_Product::product_is_charged_upon_release($product)) {
551
+				WC_Stripe_Logger::log('Pre Order charge upon release is not supported. ( Payment Request button disabled )');
552 552
 				return;
553 553
 			}
554 554
 		} else {
555
-			if ( ! $this->allowed_items_in_cart() ) {
556
-				WC_Stripe_Logger::log( 'Items in the cart has unsupported product type ( Payment Request button disabled )' );
555
+			if ( ! $this->allowed_items_in_cart()) {
556
+				WC_Stripe_Logger::log('Items in the cart has unsupported product type ( Payment Request button disabled )');
557 557
 				return;
558 558
 			}
559 559
 		}
560 560
 		?>
561
-		<p id="wc-stripe-payment-request-button-separator" style="margin-top:1.5em;text-align:center;display:none;">- <?php esc_html_e( 'OR', 'woocommerce-gateway-stripe' ); ?> -</p>
561
+		<p id="wc-stripe-payment-request-button-separator" style="margin-top:1.5em;text-align:center;display:none;">- <?php esc_html_e('OR', 'woocommerce-gateway-stripe'); ?> -</p>
562 562
 		<?php
563 563
 	}
564 564
 
@@ -569,11 +569,11 @@  discard block
 block discarded – undo
569 569
 	 * @version 4.0.0
570 570
 	 */
571 571
 	public function ajax_log_errors() {
572
-		check_ajax_referer( 'wc-stripe-log-errors', 'security' );
572
+		check_ajax_referer('wc-stripe-log-errors', 'security');
573 573
 
574
-		$errors = wc_clean( stripslashes( $_POST['errors'] ) );
574
+		$errors = wc_clean(stripslashes($_POST['errors']));
575 575
 
576
-		WC_Stripe_Logger::log( $errors );
576
+		WC_Stripe_Logger::log($errors);
577 577
 
578 578
 		exit;
579 579
 	}
@@ -585,7 +585,7 @@  discard block
 block discarded – undo
585 585
 	 * @version 4.0.0
586 586
 	 */
587 587
 	public function ajax_clear_cart() {
588
-		check_ajax_referer( 'wc-stripe-clear-cart', 'security' );
588
+		check_ajax_referer('wc-stripe-clear-cart', 'security');
589 589
 
590 590
 		WC()->cart->empty_cart();
591 591
 		exit;
@@ -595,10 +595,10 @@  discard block
 block discarded – undo
595 595
 	 * Get cart details.
596 596
 	 */
597 597
 	public function ajax_get_cart_details() {
598
-		check_ajax_referer( 'wc-stripe-payment-request', 'security' );
598
+		check_ajax_referer('wc-stripe-payment-request', 'security');
599 599
 
600
-		if ( ! defined( 'WOOCOMMERCE_CART' ) ) {
601
-			define( 'WOOCOMMERCE_CART', true );
600
+		if ( ! defined('WOOCOMMERCE_CART')) {
601
+			define('WOOCOMMERCE_CART', true);
602 602
 		}
603 603
 
604 604
 		WC()->cart->calculate_totals();
@@ -609,14 +609,14 @@  discard block
 block discarded – undo
609 609
 		$data = array(
610 610
 			'shipping_required' => WC()->cart->needs_shipping(),
611 611
 			'order_data'        => array(
612
-				'currency'        => strtolower( $currency ),
613
-				'country_code'    => substr( get_option( 'woocommerce_default_country' ), 0, 2 ),
612
+				'currency'        => strtolower($currency),
613
+				'country_code'    => substr(get_option('woocommerce_default_country'), 0, 2),
614 614
 			),
615 615
 		);
616 616
 
617 617
 		$data['order_data'] += $this->build_display_items();
618 618
 
619
-		wp_send_json( $data );
619
+		wp_send_json($data);
620 620
 	}
621 621
 
622 622
 	/**
@@ -627,47 +627,47 @@  discard block
 block discarded – undo
627 627
 	 * @see WC_Shipping::get_packages().
628 628
 	 */
629 629
 	public function ajax_get_shipping_options() {
630
-		check_ajax_referer( 'wc-stripe-payment-request-shipping', 'security' );
630
+		check_ajax_referer('wc-stripe-payment-request-shipping', 'security');
631 631
 
632 632
 		try {
633 633
 			// Set the shipping package.
634
-			$posted = filter_input_array( INPUT_POST, array(
634
+			$posted = filter_input_array(INPUT_POST, array(
635 635
 				'country'   => FILTER_SANITIZE_STRING,
636 636
 				'state'     => FILTER_SANITIZE_STRING,
637 637
 				'postcode'  => FILTER_SANITIZE_STRING,
638 638
 				'city'      => FILTER_SANITIZE_STRING,
639 639
 				'address'   => FILTER_SANITIZE_STRING,
640 640
 				'address_2' => FILTER_SANITIZE_STRING,
641
-			) );
641
+			));
642 642
 
643
-			$this->calculate_shipping( $posted );
643
+			$this->calculate_shipping($posted);
644 644
 
645 645
 			// Set the shipping options.
646 646
 			$data     = array();
647 647
 			$packages = WC()->shipping->get_packages();
648 648
 
649
-			if ( ! empty( $packages ) && WC()->customer->has_calculated_shipping() ) {
650
-				foreach ( $packages as $package_key => $package ) {
651
-					if ( empty( $package['rates'] ) ) {
652
-						throw new Exception( __( 'Unable to find shipping method for address.', 'woocommerce-gateway-stripe' ) );
649
+			if ( ! empty($packages) && WC()->customer->has_calculated_shipping()) {
650
+				foreach ($packages as $package_key => $package) {
651
+					if (empty($package['rates'])) {
652
+						throw new Exception(__('Unable to find shipping method for address.', 'woocommerce-gateway-stripe'));
653 653
 					}
654 654
 
655
-					foreach ( $package['rates'] as $key => $rate ) {
655
+					foreach ($package['rates'] as $key => $rate) {
656 656
 						$data['shipping_options'][] = array(
657 657
 							'id'       => $rate->id,
658 658
 							'label'    => $rate->label,
659 659
 							'detail'   => '',
660
-							'amount'   => WC_Stripe_Helper::get_stripe_amount( $rate->cost ),
660
+							'amount'   => WC_Stripe_Helper::get_stripe_amount($rate->cost),
661 661
 						);
662 662
 					}
663 663
 				}
664 664
 			} else {
665
-				throw new Exception( __( 'Unable to find shipping method for address.', 'woocommerce-gateway-stripe' ) );
665
+				throw new Exception(__('Unable to find shipping method for address.', 'woocommerce-gateway-stripe'));
666 666
 			}
667 667
 
668
-			if ( isset( $data[0] ) ) {
668
+			if (isset($data[0])) {
669 669
 				// Auto select the first shipping method.
670
-				WC()->session->set( 'chosen_shipping_methods', array( $data[0]['id'] ) );
670
+				WC()->session->set('chosen_shipping_methods', array($data[0]['id']));
671 671
 			}
672 672
 
673 673
 			WC()->cart->calculate_totals();
@@ -675,12 +675,12 @@  discard block
 block discarded – undo
675 675
 			$data += $this->build_display_items();
676 676
 			$data['result'] = 'success';
677 677
 
678
-			wp_send_json( $data );
679
-		} catch ( Exception $e ) {
678
+			wp_send_json($data);
679
+		} catch (Exception $e) {
680 680
 			$data += $this->build_display_items();
681 681
 			$data['result'] = 'invalid_shipping_address';
682 682
 
683
-			wp_send_json( $data );
683
+			wp_send_json($data);
684 684
 		}
685 685
 	}
686 686
 
@@ -688,22 +688,22 @@  discard block
 block discarded – undo
688 688
 	 * Update shipping method.
689 689
 	 */
690 690
 	public function ajax_update_shipping_method() {
691
-		check_ajax_referer( 'wc-stripe-update-shipping-method', 'security' );
691
+		check_ajax_referer('wc-stripe-update-shipping-method', 'security');
692 692
 
693
-		if ( ! defined( 'WOOCOMMERCE_CART' ) ) {
694
-			define( 'WOOCOMMERCE_CART', true );
693
+		if ( ! defined('WOOCOMMERCE_CART')) {
694
+			define('WOOCOMMERCE_CART', true);
695 695
 		}
696 696
 
697
-		$chosen_shipping_methods = WC()->session->get( 'chosen_shipping_methods' );
698
-		$shipping_method         = filter_input( INPUT_POST, 'shipping_method', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY );
697
+		$chosen_shipping_methods = WC()->session->get('chosen_shipping_methods');
698
+		$shipping_method         = filter_input(INPUT_POST, 'shipping_method', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY);
699 699
 
700
-		if ( is_array( $shipping_method ) ) {
701
-			foreach ( $shipping_method as $i => $value ) {
702
-				$chosen_shipping_methods[ $i ] = wc_clean( $value );
700
+		if (is_array($shipping_method)) {
701
+			foreach ($shipping_method as $i => $value) {
702
+				$chosen_shipping_methods[$i] = wc_clean($value);
703 703
 			}
704 704
 		}
705 705
 
706
-		WC()->session->set( 'chosen_shipping_methods', $chosen_shipping_methods );
706
+		WC()->session->set('chosen_shipping_methods', $chosen_shipping_methods);
707 707
 
708 708
 		WC()->cart->calculate_totals();
709 709
 
@@ -711,7 +711,7 @@  discard block
 block discarded – undo
711 711
 		$data += $this->build_display_items();
712 712
 		$data['result'] = 'success';
713 713
 
714
-		wp_send_json( $data );
714
+		wp_send_json($data);
715 715
 	}
716 716
 
717 717
 	/**
@@ -722,31 +722,31 @@  discard block
 block discarded – undo
722 722
 	 * @return array $data
723 723
 	 */
724 724
 	public function ajax_get_selected_product_data() {
725
-		check_ajax_referer( 'wc-stripe-get-selected-product-data', 'security' );
725
+		check_ajax_referer('wc-stripe-get-selected-product-data', 'security');
726 726
 
727
-		$product_id = absint( $_POST['product_id'] );
728
-		$qty = ! isset( $_POST['qty'] ) ? 1 : absint( $_POST['qty'] );
727
+		$product_id = absint($_POST['product_id']);
728
+		$qty = ! isset($_POST['qty']) ? 1 : absint($_POST['qty']);
729 729
 
730
-		$product = wc_get_product( $product_id );
730
+		$product = wc_get_product($product_id);
731 731
 
732
-		if ( 'variable' === ( WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type() ) && isset( $_POST['attributes'] ) ) {
733
-			$attributes = array_map( 'wc_clean', $_POST['attributes'] );
732
+		if ('variable' === (WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type()) && isset($_POST['attributes'])) {
733
+			$attributes = array_map('wc_clean', $_POST['attributes']);
734 734
 
735
-			if ( WC_Stripe_Helper::is_pre_30() ) {
736
-				$variation_id = $product->get_matching_variation( $attributes );
735
+			if (WC_Stripe_Helper::is_pre_30()) {
736
+				$variation_id = $product->get_matching_variation($attributes);
737 737
 			} else {
738
-				$data_store = WC_Data_Store::load( 'product' );
739
-				$variation_id = $data_store->find_matching_product_variation( $product, $attributes );
738
+				$data_store = WC_Data_Store::load('product');
739
+				$variation_id = $data_store->find_matching_product_variation($product, $attributes);
740 740
 			}
741 741
 
742
-			if ( ! empty( $variation_id ) ) {
743
-				$product = wc_get_product( $variation_id );
742
+			if ( ! empty($variation_id)) {
743
+				$product = wc_get_product($variation_id);
744 744
 			}
745
-		} elseif ( 'simple' === ( WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type() ) ) {
746
-			$product = wc_get_product( $product_id );
745
+		} elseif ('simple' === (WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type())) {
746
+			$product = wc_get_product($product_id);
747 747
 		}
748 748
 
749
-		$total = $qty * ( WC_Stripe_Helper::is_pre_30() ? $product->price : $product->get_price() );
749
+		$total = $qty * (WC_Stripe_Helper::is_pre_30() ? $product->price : $product->get_price());
750 750
 
751 751
 		$quantity_label = 1 < $qty ? ' (x' . $qty . ')' : '';
752 752
 
@@ -754,28 +754,28 @@  discard block
 block discarded – undo
754 754
 		$items = array();
755 755
 
756 756
 		$items[] = array(
757
-			'label'  => ( WC_Stripe_Helper::is_pre_30() ? $product->name : $product->get_name() ) . $quantity_label,
758
-			'amount' => WC_Stripe_Helper::get_stripe_amount( $total ),
757
+			'label'  => (WC_Stripe_Helper::is_pre_30() ? $product->name : $product->get_name()) . $quantity_label,
758
+			'amount' => WC_Stripe_Helper::get_stripe_amount($total),
759 759
 		);
760 760
 
761
-		if ( wc_tax_enabled() ) {
761
+		if (wc_tax_enabled()) {
762 762
 			$items[] = array(
763
-				'label'   => __( 'Tax', 'woocommerce-gateway-stripe' ),
763
+				'label'   => __('Tax', 'woocommerce-gateway-stripe'),
764 764
 				'amount'  => 0,
765 765
 				'pending' => true,
766 766
 			);
767 767
 		}
768 768
 
769
-		if ( wc_shipping_enabled() && $product->needs_shipping() ) {
769
+		if (wc_shipping_enabled() && $product->needs_shipping()) {
770 770
 			$items[] = array(
771
-				'label'   => __( 'Shipping', 'woocommerce-gateway-stripe' ),
771
+				'label'   => __('Shipping', 'woocommerce-gateway-stripe'),
772 772
 				'amount'  => 0,
773 773
 				'pending' => true,
774 774
 			);
775 775
 
776
-			$data['shippingOptions']  = array(
776
+			$data['shippingOptions'] = array(
777 777
 				'id'     => 'pending',
778
-				'label'  => __( 'Pending', 'woocommerce-gateway-stripe' ),
778
+				'label'  => __('Pending', 'woocommerce-gateway-stripe'),
779 779
 				'detail' => '',
780 780
 				'amount' => 0,
781 781
 			);
@@ -784,15 +784,15 @@  discard block
 block discarded – undo
784 784
 		$data['displayItems'] = $items;
785 785
 		$data['total'] = array(
786 786
 			'label'   => $this->total_label,
787
-			'amount'  => WC_Stripe_Helper::get_stripe_amount( $total ),
787
+			'amount'  => WC_Stripe_Helper::get_stripe_amount($total),
788 788
 			'pending' => true,
789 789
 		);
790 790
 
791
-		$data['requestShipping'] = ( wc_shipping_enabled() && $product->needs_shipping() );
792
-		$data['currency']        = strtolower( get_woocommerce_currency() );
793
-		$data['country_code']    = substr( get_option( 'woocommerce_default_country' ), 0, 2 );
791
+		$data['requestShipping'] = (wc_shipping_enabled() && $product->needs_shipping());
792
+		$data['currency']        = strtolower(get_woocommerce_currency());
793
+		$data['country_code']    = substr(get_option('woocommerce_default_country'), 0, 2);
794 794
 
795
-		wp_send_json( $data );
795
+		wp_send_json($data);
796 796
 	}
797 797
 
798 798
 	/**
@@ -803,37 +803,37 @@  discard block
 block discarded – undo
803 803
 	 * @return array $data
804 804
 	 */
805 805
 	public function ajax_add_to_cart() {
806
-		check_ajax_referer( 'wc-stripe-add-to-cart', 'security' );
806
+		check_ajax_referer('wc-stripe-add-to-cart', 'security');
807 807
 
808
-		if ( ! defined( 'WOOCOMMERCE_CART' ) ) {
809
-			define( 'WOOCOMMERCE_CART', true );
808
+		if ( ! defined('WOOCOMMERCE_CART')) {
809
+			define('WOOCOMMERCE_CART', true);
810 810
 		}
811 811
 
812 812
 		WC()->shipping->reset_shipping();
813 813
 
814
-		$product_id = absint( $_POST['product_id'] );
815
-		$qty = ! isset( $_POST['qty'] ) ? 1 : absint( $_POST['qty'] );
814
+		$product_id = absint($_POST['product_id']);
815
+		$qty = ! isset($_POST['qty']) ? 1 : absint($_POST['qty']);
816 816
 
817
-		$product = wc_get_product( $product_id );
817
+		$product = wc_get_product($product_id);
818 818
 
819 819
 		// First empty the cart to prevent wrong calculation.
820 820
 		WC()->cart->empty_cart();
821 821
 
822
-		if ( 'variable' === ( WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type() ) && isset( $_POST['attributes'] ) ) {
823
-			$attributes = array_map( 'wc_clean', $_POST['attributes'] );
822
+		if ('variable' === (WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type()) && isset($_POST['attributes'])) {
823
+			$attributes = array_map('wc_clean', $_POST['attributes']);
824 824
 
825
-			if ( WC_Stripe_Helper::is_pre_30() ) {
826
-				$variation_id = $product->get_matching_variation( $attributes );
825
+			if (WC_Stripe_Helper::is_pre_30()) {
826
+				$variation_id = $product->get_matching_variation($attributes);
827 827
 			} else {
828
-				$data_store = WC_Data_Store::load( 'product' );
829
-				$variation_id = $data_store->find_matching_product_variation( $product, $attributes );
828
+				$data_store = WC_Data_Store::load('product');
829
+				$variation_id = $data_store->find_matching_product_variation($product, $attributes);
830 830
 			}
831 831
 
832
-			WC()->cart->add_to_cart( $product->get_id(), $qty, $variation_id, $attributes );
832
+			WC()->cart->add_to_cart($product->get_id(), $qty, $variation_id, $attributes);
833 833
 		}
834 834
 
835
-		if ( 'simple' === ( WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type() ) ) {
836
-			WC()->cart->add_to_cart( $product->get_id(), $qty );
835
+		if ('simple' === (WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type())) {
836
+			WC()->cart->add_to_cart($product->get_id(), $qty);
837 837
 		}
838 838
 
839 839
 		WC()->cart->calculate_totals();
@@ -842,7 +842,7 @@  discard block
 block discarded – undo
842 842
 		$data += $this->build_display_items();
843 843
 		$data['result'] = 'success';
844 844
 
845
-		wp_send_json( $data );
845
+		wp_send_json($data);
846 846
 	}
847 847
 
848 848
 	/**
@@ -855,31 +855,31 @@  discard block
 block discarded – undo
855 855
 	 * @version 4.0.0
856 856
 	 */
857 857
 	public function normalize_state() {
858
-		$billing_country  = ! empty( $_POST['billing_country'] ) ? wc_clean( $_POST['billing_country'] ) : '';
859
-		$shipping_country = ! empty( $_POST['shipping_country'] ) ? wc_clean( $_POST['shipping_country'] ) : '';
860
-		$billing_state    = ! empty( $_POST['billing_state'] ) ? wc_clean( $_POST['billing_state'] ) : '';
861
-		$shipping_state   = ! empty( $_POST['shipping_state'] ) ? wc_clean( $_POST['shipping_state'] ) : '';
858
+		$billing_country  = ! empty($_POST['billing_country']) ? wc_clean($_POST['billing_country']) : '';
859
+		$shipping_country = ! empty($_POST['shipping_country']) ? wc_clean($_POST['shipping_country']) : '';
860
+		$billing_state    = ! empty($_POST['billing_state']) ? wc_clean($_POST['billing_state']) : '';
861
+		$shipping_state   = ! empty($_POST['shipping_state']) ? wc_clean($_POST['shipping_state']) : '';
862 862
 
863
-		if ( $billing_state && $billing_country ) {
864
-			$valid_states = WC()->countries->get_states( $billing_country );
863
+		if ($billing_state && $billing_country) {
864
+			$valid_states = WC()->countries->get_states($billing_country);
865 865
 
866 866
 			// Valid states found for country.
867
-			if ( ! empty( $valid_states ) && is_array( $valid_states ) && sizeof( $valid_states ) > 0 ) {
868
-				foreach ( $valid_states as $state_abbr => $state ) {
869
-					if ( preg_match( '/' . preg_quote( $state ) . '/i', $billing_state ) ) {
867
+			if ( ! empty($valid_states) && is_array($valid_states) && sizeof($valid_states) > 0) {
868
+				foreach ($valid_states as $state_abbr => $state) {
869
+					if (preg_match('/' . preg_quote($state) . '/i', $billing_state)) {
870 870
 						$_POST['billing_state'] = $state_abbr;
871 871
 					}
872 872
 				}
873 873
 			}
874 874
 		}
875 875
 
876
-		if ( $shipping_state && $shipping_country ) {
877
-			$valid_states = WC()->countries->get_states( $shipping_country );
876
+		if ($shipping_state && $shipping_country) {
877
+			$valid_states = WC()->countries->get_states($shipping_country);
878 878
 
879 879
 			// Valid states found for country.
880
-			if ( ! empty( $valid_states ) && is_array( $valid_states ) && sizeof( $valid_states ) > 0 ) {
881
-				foreach ( $valid_states as $state_abbr => $state ) {
882
-					if ( preg_match( '/' . preg_quote( $state ) . '/i', $shipping_state ) ) {
880
+			if ( ! empty($valid_states) && is_array($valid_states) && sizeof($valid_states) > 0) {
881
+				foreach ($valid_states as $state_abbr => $state) {
882
+					if (preg_match('/' . preg_quote($state) . '/i', $shipping_state)) {
883 883
 						$_POST['shipping_state'] = $state_abbr;
884 884
 					}
885 885
 				}
@@ -894,19 +894,19 @@  discard block
 block discarded – undo
894 894
 	 * @version 4.0.0
895 895
 	 */
896 896
 	public function ajax_create_order() {
897
-		if ( WC()->cart->is_empty() ) {
898
-			wp_send_json_error( __( 'Empty cart', 'woocommerce-gateway-stripe' ) );
897
+		if (WC()->cart->is_empty()) {
898
+			wp_send_json_error(__('Empty cart', 'woocommerce-gateway-stripe'));
899 899
 		}
900 900
 
901
-		if ( ! defined( 'WOOCOMMERCE_CHECKOUT' ) ) {
902
-			define( 'WOOCOMMERCE_CHECKOUT', true );
901
+		if ( ! defined('WOOCOMMERCE_CHECKOUT')) {
902
+			define('WOOCOMMERCE_CHECKOUT', true);
903 903
 		}
904 904
 
905 905
 		$this->normalize_state();
906 906
 
907 907
 		WC()->checkout()->process_checkout();
908 908
 
909
-		die( 0 );
909
+		die(0);
910 910
 	}
911 911
 
912 912
 	/**
@@ -916,7 +916,7 @@  discard block
 block discarded – undo
916 916
 	 * @version 4.0.0
917 917
 	 * @param array $address
918 918
 	 */
919
-	protected function calculate_shipping( $address = array() ) {
919
+	protected function calculate_shipping($address = array()) {
920 920
 		global $states;
921 921
 
922 922
 		$country   = $address['country'];
@@ -933,28 +933,28 @@  discard block
 block discarded – undo
933 933
 		 * In some versions of Chrome, state can be a full name. So we need
934 934
 		 * to convert that to abbreviation as WC is expecting that.
935 935
 		 */
936
-		if ( 2 < strlen( $state ) ) {
937
-			$state = array_search( ucfirst( strtolower( $state ) ), $states[ $country ] );
936
+		if (2 < strlen($state)) {
937
+			$state = array_search(ucfirst(strtolower($state)), $states[$country]);
938 938
 		}
939 939
 
940 940
 		WC()->shipping->reset_shipping();
941 941
 
942
-		if ( $postcode && WC_Validation::is_postcode( $postcode, $country ) ) {
943
-			$postcode = wc_format_postcode( $postcode, $country );
942
+		if ($postcode && WC_Validation::is_postcode($postcode, $country)) {
943
+			$postcode = wc_format_postcode($postcode, $country);
944 944
 		}
945 945
 
946
-		if ( $country ) {
947
-			WC()->customer->set_location( $country, $state, $postcode, $city );
948
-			WC()->customer->set_shipping_location( $country, $state, $postcode, $city );
946
+		if ($country) {
947
+			WC()->customer->set_location($country, $state, $postcode, $city);
948
+			WC()->customer->set_shipping_location($country, $state, $postcode, $city);
949 949
 		} else {
950 950
 			WC_Stripe_Helper::is_pre_30() ? WC()->customer->set_to_base() : WC()->customer->set_billing_address_to_base();
951 951
 			WC_Stripe_Helper::is_pre_30() ? WC()->customer->set_shipping_to_base() : WC()->customer->set_shipping_address_to_base();
952 952
 		}
953 953
 
954
-		if ( WC_Stripe_Helper::is_pre_30() ) {
955
-			WC()->customer->calculated_shipping( true );
954
+		if (WC_Stripe_Helper::is_pre_30()) {
955
+			WC()->customer->calculated_shipping(true);
956 956
 		} else {
957
-			WC()->customer->set_calculated_shipping( true );
957
+			WC()->customer->set_calculated_shipping(true);
958 958
 			WC()->customer->save();
959 959
 		}
960 960
 
@@ -971,17 +971,17 @@  discard block
 block discarded – undo
971 971
 		$packages[0]['destination']['address']   = $address_1;
972 972
 		$packages[0]['destination']['address_2'] = $address_2;
973 973
 
974
-		foreach ( WC()->cart->get_cart() as $item ) {
975
-			if ( $item['data']->needs_shipping() ) {
976
-				if ( isset( $item['line_total'] ) ) {
974
+		foreach (WC()->cart->get_cart() as $item) {
975
+			if ($item['data']->needs_shipping()) {
976
+				if (isset($item['line_total'])) {
977 977
 					$packages[0]['contents_cost'] += $item['line_total'];
978 978
 				}
979 979
 			}
980 980
 		}
981 981
 
982
-		$packages = apply_filters( 'woocommerce_cart_shipping_packages', $packages );
982
+		$packages = apply_filters('woocommerce_cart_shipping_packages', $packages);
983 983
 
984
-		WC()->shipping->calculate_shipping( $packages );
984
+		WC()->shipping->calculate_shipping($packages);
985 985
 	}
986 986
 
987 987
 	/**
@@ -990,19 +990,19 @@  discard block
 block discarded – undo
990 990
 	 * @since 3.1.0
991 991
 	 * @version 4.0.0
992 992
 	 */
993
-	protected function build_shipping_methods( $shipping_methods ) {
994
-		if ( empty( $shipping_methods ) ) {
993
+	protected function build_shipping_methods($shipping_methods) {
994
+		if (empty($shipping_methods)) {
995 995
 			return array();
996 996
 		}
997 997
 
998 998
 		$shipping = array();
999 999
 
1000
-		foreach ( $shipping_methods as $method ) {
1000
+		foreach ($shipping_methods as $method) {
1001 1001
 			$shipping[] = array(
1002 1002
 				'id'         => $method['id'],
1003 1003
 				'label'      => $method['label'],
1004 1004
 				'detail'     => '',
1005
-				'amount'     => WC_Stripe_Helper::get_stripe_amount( $method['amount']['value'] ),
1005
+				'amount'     => WC_Stripe_Helper::get_stripe_amount($method['amount']['value']),
1006 1006
 			);
1007 1007
 		}
1008 1008
 
@@ -1016,69 +1016,69 @@  discard block
 block discarded – undo
1016 1016
 	 * @version 4.0.0
1017 1017
 	 */
1018 1018
 	protected function build_display_items() {
1019
-		if ( ! defined( 'WOOCOMMERCE_CART' ) ) {
1020
-			define( 'WOOCOMMERCE_CART', true );
1019
+		if ( ! defined('WOOCOMMERCE_CART')) {
1020
+			define('WOOCOMMERCE_CART', true);
1021 1021
 		}
1022 1022
 
1023 1023
 		$items    = array();
1024 1024
 		$subtotal = 0;
1025 1025
 
1026 1026
 		// Default show only subtotal instead of itemization.
1027
-		if ( ! apply_filters( 'wc_stripe_payment_request_hide_itemization', true ) ) {
1028
-			foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {
1027
+		if ( ! apply_filters('wc_stripe_payment_request_hide_itemization', true)) {
1028
+			foreach (WC()->cart->get_cart() as $cart_item_key => $cart_item) {
1029 1029
 				$amount         = $cart_item['line_subtotal'];
1030
-				$subtotal       += $cart_item['line_subtotal'];
1030
+				$subtotal += $cart_item['line_subtotal'];
1031 1031
 				$quantity_label = 1 < $cart_item['quantity'] ? ' (x' . $cart_item['quantity'] . ')' : '';
1032 1032
 
1033 1033
 				$product_name = WC_Stripe_Helper::is_pre_30() ? $cart_item['data']->post->post_title : $cart_item['data']->get_name();
1034 1034
 
1035 1035
 				$item = array(
1036 1036
 					'label'  => $product_name . $quantity_label,
1037
-					'amount' => WC_Stripe_Helper::get_stripe_amount( $amount ),
1037
+					'amount' => WC_Stripe_Helper::get_stripe_amount($amount),
1038 1038
 				);
1039 1039
 
1040 1040
 				$items[] = $item;
1041 1041
 			}
1042 1042
 		}
1043 1043
 
1044
-		$discounts   = wc_format_decimal( WC()->cart->get_cart_discount_total(), WC()->cart->dp );
1045
-		$tax         = wc_format_decimal( WC()->cart->tax_total + WC()->cart->shipping_tax_total, WC()->cart->dp );
1046
-		$shipping    = wc_format_decimal( WC()->cart->shipping_total, WC()->cart->dp );
1047
-		$items_total = wc_format_decimal( WC()->cart->cart_contents_total, WC()->cart->dp ) + $discounts;
1048
-		$order_total = wc_format_decimal( $items_total + $tax + $shipping - $discounts, WC()->cart->dp );
1044
+		$discounts   = wc_format_decimal(WC()->cart->get_cart_discount_total(), WC()->cart->dp);
1045
+		$tax         = wc_format_decimal(WC()->cart->tax_total + WC()->cart->shipping_tax_total, WC()->cart->dp);
1046
+		$shipping    = wc_format_decimal(WC()->cart->shipping_total, WC()->cart->dp);
1047
+		$items_total = wc_format_decimal(WC()->cart->cart_contents_total, WC()->cart->dp) + $discounts;
1048
+		$order_total = wc_format_decimal($items_total + $tax + $shipping - $discounts, WC()->cart->dp);
1049 1049
 
1050
-		if ( wc_tax_enabled() ) {
1050
+		if (wc_tax_enabled()) {
1051 1051
 			$items[] = array(
1052
-				'label'  => esc_html( __( 'Tax', 'woocommerce-gateway-stripe' ) ),
1053
-				'amount' => WC_Stripe_Helper::get_stripe_amount( $tax ),
1052
+				'label'  => esc_html(__('Tax', 'woocommerce-gateway-stripe')),
1053
+				'amount' => WC_Stripe_Helper::get_stripe_amount($tax),
1054 1054
 			);
1055 1055
 		}
1056 1056
 
1057
-		if ( WC()->cart->needs_shipping() ) {
1057
+		if (WC()->cart->needs_shipping()) {
1058 1058
 			$items[] = array(
1059
-				'label'  => esc_html( __( 'Shipping', 'woocommerce-gateway-stripe' ) ),
1060
-				'amount' => WC_Stripe_Helper::get_stripe_amount( $shipping ),
1059
+				'label'  => esc_html(__('Shipping', 'woocommerce-gateway-stripe')),
1060
+				'amount' => WC_Stripe_Helper::get_stripe_amount($shipping),
1061 1061
 			);
1062 1062
 		}
1063 1063
 
1064
-		if ( WC()->cart->has_discount() ) {
1064
+		if (WC()->cart->has_discount()) {
1065 1065
 			$items[] = array(
1066
-				'label'  => esc_html( __( 'Discount', 'woocommerce-gateway-stripe' ) ),
1067
-				'amount' => WC_Stripe_Helper::get_stripe_amount( $discounts ),
1066
+				'label'  => esc_html(__('Discount', 'woocommerce-gateway-stripe')),
1067
+				'amount' => WC_Stripe_Helper::get_stripe_amount($discounts),
1068 1068
 			);
1069 1069
 		}
1070 1070
 
1071
-		if ( version_compare( WC_VERSION, '3.2', '<' ) ) {
1071
+		if (version_compare(WC_VERSION, '3.2', '<')) {
1072 1072
 			$cart_fees = WC()->cart->fees;
1073 1073
 		} else {
1074 1074
 			$cart_fees = WC()->cart->get_fees();
1075 1075
 		}
1076 1076
 
1077 1077
 		// Include fees and taxes as display items.
1078
-		foreach ( $cart_fees as $key => $fee ) {
1078
+		foreach ($cart_fees as $key => $fee) {
1079 1079
 			$items[] = array(
1080 1080
 				'label'  => $fee->name,
1081
-				'amount' => WC_Stripe_Helper::get_stripe_amount( $fee->amount ),
1081
+				'amount' => WC_Stripe_Helper::get_stripe_amount($fee->amount),
1082 1082
 			);
1083 1083
 		}
1084 1084
 
@@ -1086,7 +1086,7 @@  discard block
 block discarded – undo
1086 1086
 			'displayItems' => $items,
1087 1087
 			'total'      => array(
1088 1088
 				'label'   => $this->total_label,
1089
-				'amount'  => max( 0, apply_filters( 'woocommerce_stripe_calculated_total', WC_Stripe_Helper::get_stripe_amount( $order_total ), $order_total, WC()->cart ) ),
1089
+				'amount'  => max(0, apply_filters('woocommerce_stripe_calculated_total', WC_Stripe_Helper::get_stripe_amount($order_total), $order_total, WC()->cart)),
1090 1090
 				'pending' => false,
1091 1091
 			),
1092 1092
 		);
Please login to merge, or discard this patch.
includes/class-wc-stripe-order-handler.php 1 patch
Spacing   +172 added lines, -172 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
 
@@ -23,12 +23,12 @@  discard block
 block discarded – undo
23 23
 
24 24
 		$this->retry_interval = 2;
25 25
 
26
-		add_action( 'wp', array( $this, 'maybe_process_redirect_order' ) );
27
-		add_action( 'woocommerce_order_status_on-hold_to_processing', array( $this, 'capture_payment' ) );
28
-		add_action( 'woocommerce_order_status_on-hold_to_completed', array( $this, 'capture_payment' ) );
29
-		add_action( 'woocommerce_order_status_on-hold_to_cancelled', array( $this, 'cancel_payment' ) );
30
-		add_action( 'woocommerce_order_status_on-hold_to_refunded', array( $this, 'cancel_payment' ) );
31
-		add_action( 'wc_ajax_wc_stripe_validate_checkout', array( $this, 'validate_checkout' ) );
26
+		add_action('wp', array($this, 'maybe_process_redirect_order'));
27
+		add_action('woocommerce_order_status_on-hold_to_processing', array($this, 'capture_payment'));
28
+		add_action('woocommerce_order_status_on-hold_to_completed', array($this, 'capture_payment'));
29
+		add_action('woocommerce_order_status_on-hold_to_cancelled', array($this, 'cancel_payment'));
30
+		add_action('woocommerce_order_status_on-hold_to_refunded', array($this, 'cancel_payment'));
31
+		add_action('wc_ajax_wc_stripe_validate_checkout', array($this, 'validate_checkout'));
32 32
 	}
33 33
 
34 34
 	/**
@@ -49,25 +49,25 @@  discard block
 block discarded – undo
49 49
 	 * @since 4.0.0
50 50
 	 * @version 4.0.0
51 51
 	 */
52
-	public function process_redirect_payment( $order_id, $retry = true ) {
52
+	public function process_redirect_payment($order_id, $retry = true) {
53 53
 		try {
54
-			$source = wc_clean( $_GET['source'] );
54
+			$source = wc_clean($_GET['source']);
55 55
 
56
-			if ( empty( $source ) ) {
56
+			if (empty($source)) {
57 57
 				return;
58 58
 			}
59 59
 
60
-			if ( empty( $order_id ) ) {
60
+			if (empty($order_id)) {
61 61
 				return;
62 62
 			}
63 63
 
64
-			$order = wc_get_order( $order_id );
64
+			$order = wc_get_order($order_id);
65 65
 
66
-			if ( ! is_object( $order ) ) {
66
+			if ( ! is_object($order)) {
67 67
 				return;
68 68
 			}
69 69
 
70
-			if ( 'processing' === $order->get_status() || 'completed' === $order->get_status() || 'on-hold' === $order->get_status() ) {
70
+			if ('processing' === $order->get_status() || 'completed' === $order->get_status() || 'on-hold' === $order->get_status()) {
71 71
 				return;
72 72
 			}
73 73
 
@@ -75,127 +75,127 @@  discard block
 block discarded – undo
75 75
 			$response = null;
76 76
 
77 77
 			// This will throw exception if not valid.
78
-			$this->validate_minimum_order_amount( $order );
78
+			$this->validate_minimum_order_amount($order);
79 79
 
80
-			WC_Stripe_Logger::log( "Info: (Redirect) Begin processing payment for order $order_id for the amount of {$order->get_total()}" );
80
+			WC_Stripe_Logger::log("Info: (Redirect) Begin processing payment for order $order_id for the amount of {$order->get_total()}");
81 81
 
82 82
 			/**
83 83
 			 * First check if the source is chargeable at this time. If not,
84 84
 			 * webhook will take care of it later.
85 85
 			 */
86
-			$source_info = WC_Stripe_API::retrieve( 'sources/' . $source );
86
+			$source_info = WC_Stripe_API::retrieve('sources/' . $source);
87 87
 
88
-			if ( ! empty( $source_info->error ) ) {
89
-				throw new WC_Stripe_Exception( print_r( $source_info, true ), $source_info->error->message );
88
+			if ( ! empty($source_info->error)) {
89
+				throw new WC_Stripe_Exception(print_r($source_info, true), $source_info->error->message);
90 90
 			}
91 91
 
92
-			if ( 'failed' === $source_info->status || 'canceled' === $source_info->status ) {
93
-				throw new WC_Stripe_Exception( print_r( $source_info, true ), __( 'Unable to process this payment, please try again or use alternative method.', 'woocommerce-gateway-stripe' ) );
92
+			if ('failed' === $source_info->status || 'canceled' === $source_info->status) {
93
+				throw new WC_Stripe_Exception(print_r($source_info, true), __('Unable to process this payment, please try again or use alternative method.', 'woocommerce-gateway-stripe'));
94 94
 			}
95 95
 
96 96
 			// If already consumed, then ignore request.
97
-			if ( 'consumed' === $source_info->status ) {
97
+			if ('consumed' === $source_info->status) {
98 98
 				return;
99 99
 			}
100 100
 
101 101
 			// If not chargeable, then ignore request.
102
-			if ( 'chargeable' !== $source_info->status ) {
102
+			if ('chargeable' !== $source_info->status) {
103 103
 				return;
104 104
 			}
105 105
 
106 106
 			// Prep source object.
107 107
 			$source_object           = new stdClass();
108 108
 			$source_object->token_id = '';
109
-			$source_object->customer = $this->get_stripe_customer_id( $order );
109
+			$source_object->customer = $this->get_stripe_customer_id($order);
110 110
 			$source_object->source   = $source_info->id;
111 111
 
112 112
 			// Make the request.
113
-			$response = WC_Stripe_API::request( $this->generate_payment_request( $order, $source_object ) );
113
+			$response = WC_Stripe_API::request($this->generate_payment_request($order, $source_object));
114 114
 
115
-			if ( ! empty( $response->error ) ) {
115
+			if ( ! empty($response->error)) {
116 116
 				// If it is an API error such connection or server, let's retry.
117
-				if ( 'api_connection_error' === $response->error->type || 'api_error' === $response->error->type ) {
118
-					if ( $retry ) {
119
-						sleep( 5 );
120
-						return $this->process_redirect_payment( $order_id, false );
117
+				if ('api_connection_error' === $response->error->type || 'api_error' === $response->error->type) {
118
+					if ($retry) {
119
+						sleep(5);
120
+						return $this->process_redirect_payment($order_id, false);
121 121
 					} else {
122
-						$localized_message = __( 'API connection error and retries exhausted.', 'woocommerce-gateway-stripe' );
123
-						$order->add_order_note( $localized_message );
124
-						throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message );
122
+						$localized_message = __('API connection error and retries exhausted.', 'woocommerce-gateway-stripe');
123
+						$order->add_order_note($localized_message);
124
+						throw new WC_Stripe_Exception(print_r($response, true), $localized_message);
125 125
 					}
126 126
 				}
127 127
 
128 128
 				// We want to retry.
129
-				if ( $this->is_retryable_error( $response->error ) ) {
130
-					if ( $retry ) {
129
+				if ($this->is_retryable_error($response->error)) {
130
+					if ($retry) {
131 131
 						// Don't do anymore retries after this.
132
-						if ( 5 <= $this->retry_interval ) {
133
-							return $this->process_redirect_payment( $order_id, false );
132
+						if (5 <= $this->retry_interval) {
133
+							return $this->process_redirect_payment($order_id, false);
134 134
 						}
135 135
 
136
-						sleep( $this->retry_interval );
136
+						sleep($this->retry_interval);
137 137
 
138 138
 						$this->retry_interval++;
139
-						return $this->process_redirect_payment( $order_id, true );
139
+						return $this->process_redirect_payment($order_id, true);
140 140
 					} else {
141
-						$localized_message = __( 'On going requests error and retries exhausted.', 'woocommerce-gateway-stripe' );
142
-						$order->add_order_note( $localized_message );
143
-						throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message );
141
+						$localized_message = __('On going requests error and retries exhausted.', 'woocommerce-gateway-stripe');
142
+						$order->add_order_note($localized_message);
143
+						throw new WC_Stripe_Exception(print_r($response, true), $localized_message);
144 144
 					}
145 145
 				}
146 146
 
147 147
 				// Customer param wrong? The user may have been deleted on stripe's end. Remove customer_id. Can be retried without.
148
-				if ( preg_match( '/No such customer/i', $response->error->message ) && $retry ) {
149
-					if ( WC_Stripe_Helper::is_pre_30() ) {
150
-						delete_user_meta( $order->customer_user, '_stripe_customer_id' );
151
-						delete_post_meta( $order_id, '_stripe_customer_id' );
148
+				if (preg_match('/No such customer/i', $response->error->message) && $retry) {
149
+					if (WC_Stripe_Helper::is_pre_30()) {
150
+						delete_user_meta($order->customer_user, '_stripe_customer_id');
151
+						delete_post_meta($order_id, '_stripe_customer_id');
152 152
 					} else {
153
-						delete_user_meta( $order->get_customer_id(), '_stripe_customer_id' );
154
-						$order->delete_meta_data( '_stripe_customer_id' );
153
+						delete_user_meta($order->get_customer_id(), '_stripe_customer_id');
154
+						$order->delete_meta_data('_stripe_customer_id');
155 155
 						$order->save();
156 156
 					}
157 157
 
158
-					return $this->process_redirect_payment( $order_id, false );
158
+					return $this->process_redirect_payment($order_id, false);
159 159
 
160
-				} elseif ( preg_match( '/No such token/i', $response->error->message ) && $source_object->token_id ) {
160
+				} elseif (preg_match('/No such token/i', $response->error->message) && $source_object->token_id) {
161 161
 					// Source param wrong? The CARD may have been deleted on stripe's end. Remove token and show message.
162 162
 
163
-					$wc_token = WC_Payment_Tokens::get( $source_object->token_id );
163
+					$wc_token = WC_Payment_Tokens::get($source_object->token_id);
164 164
 					$wc_token->delete();
165
-					$message = __( 'This card is no longer available and has been removed.', 'woocommerce-gateway-stripe' );
166
-					$order->add_order_note( $message );
167
-					throw new WC_Stripe_Exception( print_r( $response, true ), $message );
165
+					$message = __('This card is no longer available and has been removed.', 'woocommerce-gateway-stripe');
166
+					$order->add_order_note($message);
167
+					throw new WC_Stripe_Exception(print_r($response, true), $message);
168 168
 				}
169 169
 
170 170
 				$localized_messages = WC_Stripe_Helper::get_localized_messages();
171 171
 
172
-				if ( 'card_error' === $response->error->type ) {
173
-					$message = isset( $localized_messages[ $response->error->code ] ) ? $localized_messages[ $response->error->code ] : $response->error->message;
172
+				if ('card_error' === $response->error->type) {
173
+					$message = isset($localized_messages[$response->error->code]) ? $localized_messages[$response->error->code] : $response->error->message;
174 174
 				} else {
175
-					$message = isset( $localized_messages[ $response->error->type ] ) ? $localized_messages[ $response->error->type ] : $response->error->message;
175
+					$message = isset($localized_messages[$response->error->type]) ? $localized_messages[$response->error->type] : $response->error->message;
176 176
 				}
177 177
 
178
-				throw new WC_Stripe_Exception( print_r( $response, true ), $message );
178
+				throw new WC_Stripe_Exception(print_r($response, true), $message);
179 179
 			}
180 180
 
181
-			do_action( 'wc_gateway_stripe_process_redirect_payment', $response, $order );
181
+			do_action('wc_gateway_stripe_process_redirect_payment', $response, $order);
182 182
 
183
-			$this->process_response( $response, $order );
183
+			$this->process_response($response, $order);
184 184
 
185
-		} catch ( WC_Stripe_Exception $e ) {
186
-			WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() );
185
+		} catch (WC_Stripe_Exception $e) {
186
+			WC_Stripe_Logger::log('Error: ' . $e->getMessage());
187 187
 
188
-			do_action( 'wc_gateway_stripe_process_redirect_payment_error', $e, $order );
188
+			do_action('wc_gateway_stripe_process_redirect_payment_error', $e, $order);
189 189
 
190 190
 			/* translators: error message */
191
-			$order->update_status( 'failed', sprintf( __( 'Stripe payment failed: %s', 'woocommerce-gateway-stripe' ), $e->getLocalizedMessage() ) );
191
+			$order->update_status('failed', sprintf(__('Stripe payment failed: %s', 'woocommerce-gateway-stripe'), $e->getLocalizedMessage()));
192 192
 
193
-			if ( $order->has_status( array( 'pending', 'failed' ) ) ) {
194
-				$this->send_failed_order_email( $order_id );
193
+			if ($order->has_status(array('pending', 'failed'))) {
194
+				$this->send_failed_order_email($order_id);
195 195
 			}
196 196
 
197
-			wc_add_notice( $e->getLocalizedMessage(), 'error' );
198
-			wp_safe_redirect( wc_get_checkout_url() );
197
+			wc_add_notice($e->getLocalizedMessage(), 'error');
198
+			wp_safe_redirect(wc_get_checkout_url());
199 199
 			exit;
200 200
 		}
201 201
 	}
@@ -207,13 +207,13 @@  discard block
 block discarded – undo
207 207
 	 * @version 4.0.0
208 208
 	 */
209 209
 	public function maybe_process_redirect_order() {
210
-		if ( ! is_order_received_page() || empty( $_GET['client_secret'] ) || empty( $_GET['source'] ) ) {
210
+		if ( ! is_order_received_page() || empty($_GET['client_secret']) || empty($_GET['source'])) {
211 211
 			return;
212 212
 		}
213 213
 
214
-		$order_id = wc_clean( $_GET['order_id'] );
214
+		$order_id = wc_clean($_GET['order_id']);
215 215
 
216
-		$this->process_redirect_payment( $order_id );
216
+		$this->process_redirect_payment($order_id);
217 217
 	}
218 218
 
219 219
 	/**
@@ -223,52 +223,52 @@  discard block
 block discarded – undo
223 223
 	 * @version 4.0.0
224 224
 	 * @param  int $order_id
225 225
 	 */
226
-	public function capture_payment( $order_id ) {
227
-		$order = wc_get_order( $order_id );
226
+	public function capture_payment($order_id) {
227
+		$order = wc_get_order($order_id);
228 228
 
229
-		if ( 'stripe' === ( WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method() ) ) {
230
-			$charge   = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_transaction_id', true ) : $order->get_transaction_id();
231
-			$captured = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_stripe_charge_captured', true ) : $order->get_meta( '_stripe_charge_captured', true );
229
+		if ('stripe' === (WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method())) {
230
+			$charge   = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_transaction_id', true) : $order->get_transaction_id();
231
+			$captured = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_stripe_charge_captured', true) : $order->get_meta('_stripe_charge_captured', true);
232 232
 
233
-			if ( $charge && 'no' === $captured ) {
233
+			if ($charge && 'no' === $captured) {
234 234
 				$order_total = $order->get_total();
235 235
 
236
-				if ( 0 < $order->get_total_refunded() ) {
236
+				if (0 < $order->get_total_refunded()) {
237 237
 					$order_total = $order_total - $order->get_total_refunded();
238 238
 				}
239 239
 
240
-				$result = WC_Stripe_API::request( array(
241
-					'amount'   => WC_Stripe_Helper::get_stripe_amount( $order_total ),
240
+				$result = WC_Stripe_API::request(array(
241
+					'amount'   => WC_Stripe_Helper::get_stripe_amount($order_total),
242 242
 					'expand[]' => 'balance_transaction',
243
-				), 'charges/' . $charge . '/capture' );
243
+				), 'charges/' . $charge . '/capture');
244 244
 
245
-				if ( ! empty( $result->error ) ) {
245
+				if ( ! empty($result->error)) {
246 246
 					/* translators: error message */
247
-					$order->update_status( 'failed', sprintf( __( 'Unable to capture charge! %s', 'woocommerce-gateway-stripe' ), $result->error->message ) );
247
+					$order->update_status('failed', sprintf(__('Unable to capture charge! %s', 'woocommerce-gateway-stripe'), $result->error->message));
248 248
 				} else {
249 249
 					/* translators: transaction id */
250
-					$order->add_order_note( sprintf( __( 'Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe' ), $result->id ) );
251
-					WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, '_stripe_charge_captured', 'yes' ) : $order->update_meta_data( '_stripe_charge_captured', 'yes' );
250
+					$order->add_order_note(sprintf(__('Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe'), $result->id));
251
+					WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, '_stripe_charge_captured', 'yes') : $order->update_meta_data('_stripe_charge_captured', 'yes');
252 252
 
253 253
 					// Store other data such as fees
254
-					WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, '_transaction_id', $result->id ) : $order->set_transaction_id( $result->id );
254
+					WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, '_transaction_id', $result->id) : $order->set_transaction_id($result->id);
255 255
 
256
-					if ( isset( $result->balance_transaction ) && isset( $result->balance_transaction->fee ) ) {
256
+					if (isset($result->balance_transaction) && isset($result->balance_transaction->fee)) {
257 257
 						// Fees and Net needs to both come from Stripe to be accurate as the returned
258 258
 						// values are in the local currency of the Stripe account, not from WC.
259
-						$fee = ! empty( $result->balance_transaction->fee ) ? WC_Stripe_Helper::format_balance_fee( $result->balance_transaction, 'fee' ) : 0;
260
-						$net = ! empty( $result->balance_transaction->net ) ? WC_Stripe_Helper::format_balance_fee( $result->balance_transaction, 'net' ) : 0;
261
-						WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, parent::META_NAME_FEE, $fee ) : $order->update_meta_data( parent::META_NAME_FEE, $fee );
262
-						WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, parent::META_NAME_NET, $net ) : $order->update_meta_data( parent::META_NAME_NET, $net );
259
+						$fee = ! empty($result->balance_transaction->fee) ? WC_Stripe_Helper::format_balance_fee($result->balance_transaction, 'fee') : 0;
260
+						$net = ! empty($result->balance_transaction->net) ? WC_Stripe_Helper::format_balance_fee($result->balance_transaction, 'net') : 0;
261
+						WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, parent::META_NAME_FEE, $fee) : $order->update_meta_data(parent::META_NAME_FEE, $fee);
262
+						WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, parent::META_NAME_NET, $net) : $order->update_meta_data(parent::META_NAME_NET, $net);
263 263
 					}
264 264
 
265
-					if ( is_callable( array( $order, 'save' ) ) ) {
265
+					if (is_callable(array($order, 'save'))) {
266 266
 						$order->save();
267 267
 					}
268 268
 				}
269 269
 
270 270
 				// This hook fires when admin manually changes order status to processing or completed.
271
-				do_action( 'woocommerce_stripe_process_manual_capture', $order, $result );
271
+				do_action('woocommerce_stripe_process_manual_capture', $order, $result);
272 272
 			}
273 273
 		}
274 274
 	}
@@ -280,14 +280,14 @@  discard block
 block discarded – undo
280 280
 	 * @version 4.0.0
281 281
 	 * @param  int $order_id
282 282
 	 */
283
-	public function cancel_payment( $order_id ) {
284
-		$order = wc_get_order( $order_id );
283
+	public function cancel_payment($order_id) {
284
+		$order = wc_get_order($order_id);
285 285
 
286
-		if ( 'stripe' === ( WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method() ) ) {
287
-			$this->process_refund( $order_id );
286
+		if ('stripe' === (WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method())) {
287
+			$this->process_refund($order_id);
288 288
 
289 289
 			// This hook fires when admin manually changes order status to cancel.
290
-			do_action( 'woocommerce_stripe_process_manual_cancel', $order );
290
+			do_action('woocommerce_stripe_process_manual_cancel', $order);
291 291
 		}
292 292
 	}
293 293
 
@@ -299,21 +299,21 @@  discard block
 block discarded – undo
299 299
 	 * @param string $field
300 300
 	 * @return string $error_field
301 301
 	 */
302
-	public function normalize_field( $field ) {
302
+	public function normalize_field($field) {
303 303
 		$checkout_fields = WC()->checkout->get_checkout_fields();
304 304
 		$org_str         = array();
305 305
 		$replace_str     = array();
306 306
 
307
-		if ( array_key_exists( $field, $checkout_fields['billing'] ) ) {
308
-			$error_field = __( 'Billing', 'woocommerce-gateway-stripe' ) . ' ' . $checkout_fields['billing'][ $field ]['label'];
309
-		} elseif ( array_key_exists( $field, $checkout_fields['shipping'] ) ) {
310
-			$error_field = __( 'Shipping', 'woocommerce-gateway-stripe' ) . ' ' . $checkout_fields['shipping'][ $field ]['label'];
311
-		} elseif ( array_key_exists( $field, $checkout_fields['order'] ) ) {
312
-			$error_field = $checkout_fields['order'][ $field ]['label'];
313
-		} elseif ( array_key_exists( $field, $checkout_fields['account'] ) ) {
314
-			$error_field = $checkout_fields['account'][ $field ]['label'];
307
+		if (array_key_exists($field, $checkout_fields['billing'])) {
308
+			$error_field = __('Billing', 'woocommerce-gateway-stripe') . ' ' . $checkout_fields['billing'][$field]['label'];
309
+		} elseif (array_key_exists($field, $checkout_fields['shipping'])) {
310
+			$error_field = __('Shipping', 'woocommerce-gateway-stripe') . ' ' . $checkout_fields['shipping'][$field]['label'];
311
+		} elseif (array_key_exists($field, $checkout_fields['order'])) {
312
+			$error_field = $checkout_fields['order'][$field]['label'];
313
+		} elseif (array_key_exists($field, $checkout_fields['account'])) {
314
+			$error_field = $checkout_fields['account'][$field]['label'];
315 315
 		} else {
316
-			$error_field = str_replace( '_', ' ', $field );
316
+			$error_field = str_replace('_', ' ', $field);
317 317
 
318 318
 			$org_str[]     = 'stripe';
319 319
 			$replace_str[] = '';
@@ -328,9 +328,9 @@  discard block
 block discarded – undo
328 328
 			$replace_str[] = 'SOFORT';
329 329
 
330 330
 			$org_str[]     = 'owner';
331
-			$replace_str[] = __( 'Owner', 'woocommerce-gateway-stripe' );
331
+			$replace_str[] = __('Owner', 'woocommerce-gateway-stripe');
332 332
 
333
-			$error_field   = str_replace( $org_str, $replace_str, $error_field );
333
+			$error_field   = str_replace($org_str, $replace_str, $error_field);
334 334
 		}
335 335
 
336 336
 		return $error_field;
@@ -343,138 +343,138 @@  discard block
 block discarded – undo
343 343
 	 * @version 4.0.0
344 344
 	 */
345 345
 	public function validate_checkout() {
346
-		if ( ! wp_verify_nonce( $_POST['nonce'], '_wc_stripe_nonce' ) ) {
347
-			wp_die( __( 'Cheatin&#8217; huh?', 'woocommerce-gateway-stripe' ) );
346
+		if ( ! wp_verify_nonce($_POST['nonce'], '_wc_stripe_nonce')) {
347
+			wp_die(__('Cheatin&#8217; huh?', 'woocommerce-gateway-stripe'));
348 348
 		}
349 349
 
350 350
 		$errors = new WP_Error();
351
-		parse_str( $_POST['required_fields'], $required_fields );
352
-		parse_str( $_POST['all_fields'], $all_fields );
353
-		$source_type = isset( $_POST['source_type'] ) ? wc_clean( $_POST['source_type'] ) : '';
351
+		parse_str($_POST['required_fields'], $required_fields);
352
+		parse_str($_POST['all_fields'], $all_fields);
353
+		$source_type = isset($_POST['source_type']) ? wc_clean($_POST['source_type']) : '';
354 354
 		$validate_shipping_fields = false;
355 355
 		$create_account = false;
356 356
 
357
-		$all_fields      = apply_filters( 'wc_stripe_validate_checkout_all_fields', $all_fields );
358
-		$required_fields = apply_filters( 'wc_stripe_validate_checkout_required_fields', $required_fields );
357
+		$all_fields      = apply_filters('wc_stripe_validate_checkout_all_fields', $all_fields);
358
+		$required_fields = apply_filters('wc_stripe_validate_checkout_required_fields', $required_fields);
359 359
 
360
-		array_walk_recursive( $required_fields, 'wc_clean' );
361
-		array_walk_recursive( $all_fields, 'wc_clean' );
360
+		array_walk_recursive($required_fields, 'wc_clean');
361
+		array_walk_recursive($all_fields, 'wc_clean');
362 362
 
363 363
 		/**
364 364
 		 * If ship to different address checkbox is checked then we need
365 365
 		 * to validate shipping fields too.
366 366
 		 */
367
-		if ( isset( $all_fields['ship_to_different_address'] ) ) {
367
+		if (isset($all_fields['ship_to_different_address'])) {
368 368
 			$validate_shipping_fields = true;
369 369
 		}
370 370
 
371 371
 		// Check if createaccount is checked.
372
-		if ( isset( $all_fields['createaccount'] ) ) {
372
+		if (isset($all_fields['createaccount'])) {
373 373
 			$create_account = true;
374 374
 		}
375 375
 
376 376
 		// Check if required fields are empty.
377
-		foreach ( $required_fields as $field => $field_value ) {
377
+		foreach ($required_fields as $field => $field_value) {
378 378
 			// Check for shipping field.
379
-			if ( preg_match( '/^shipping_/', $field ) && ! $validate_shipping_fields ) {
379
+			if (preg_match('/^shipping_/', $field) && ! $validate_shipping_fields) {
380 380
 				continue;
381 381
 			}
382 382
 
383 383
 			// Check create account name.
384
-			if ( 'account_username' === $field && ! $create_account ) {
384
+			if ('account_username' === $field && ! $create_account) {
385 385
 				continue;
386 386
 			}
387 387
 
388 388
 			// Check create account password.
389
-			if ( 'account_password' === $field && ! $create_account ) {
389
+			if ('account_password' === $field && ! $create_account) {
390 390
 				continue;
391 391
 			}
392 392
 
393
-			if ( empty( $field_value ) || '-1' === $field_value ) {
394
-				$error_field = $this->normalize_field( $field );
393
+			if (empty($field_value) || '-1' === $field_value) {
394
+				$error_field = $this->normalize_field($field);
395 395
 				/* translators: error field name */
396
-				$errors->add( 'validation', sprintf( __( '<strong>%s</strong> cannot be empty', 'woocommerce-gateway-stripe' ), $error_field ) );
396
+				$errors->add('validation', sprintf(__('<strong>%s</strong> cannot be empty', 'woocommerce-gateway-stripe'), $error_field));
397 397
 			}
398 398
 		}
399 399
 
400 400
 		// Check if email is valid format.
401
-		if ( ! empty( $required_fields['billing_email'] ) && ! is_email( $required_fields['billing_email'] ) ) {
402
-			$errors->add( 'validation', __( 'Email is not valid', 'woocommerce-gateway-stripe' ) );
401
+		if ( ! empty($required_fields['billing_email']) && ! is_email($required_fields['billing_email'])) {
402
+			$errors->add('validation', __('Email is not valid', 'woocommerce-gateway-stripe'));
403 403
 		}
404 404
 
405 405
 		// Check if phone number is valid format.
406
-		if ( ! empty( $required_fields['billing_phone'] ) ) {
407
-			$phone = wc_format_phone_number( $required_fields['billing_phone'] );
406
+		if ( ! empty($required_fields['billing_phone'])) {
407
+			$phone = wc_format_phone_number($required_fields['billing_phone']);
408 408
 
409
-			if ( '' !== $phone && ! WC_Validation::is_phone( $phone ) ) {
409
+			if ('' !== $phone && ! WC_Validation::is_phone($phone)) {
410 410
 				/* translators: %s: phone number */
411
-				$errors->add( 'validation', __( 'Please enter a valid phone number.', 'woocommerce-gateway-stripe' ) );
411
+				$errors->add('validation', __('Please enter a valid phone number.', 'woocommerce-gateway-stripe'));
412 412
 			}
413 413
 		}
414 414
 
415 415
 		// Check if postal code is valid format.
416
-		if ( ! empty( $required_fields['billing_postcode'] ) ) {
417
-			$country = isset( $required_fields['billing_country'] ) ? $required_fields['billing_country'] : WC()->customer->get_billing_country();
418
-			$postcode = wc_format_postcode( $required_fields['billing_postcode'], $country );
416
+		if ( ! empty($required_fields['billing_postcode'])) {
417
+			$country = isset($required_fields['billing_country']) ? $required_fields['billing_country'] : WC()->customer->get_billing_country();
418
+			$postcode = wc_format_postcode($required_fields['billing_postcode'], $country);
419 419
 
420
-			if ( '' !== $required_fields['billing_postcode'] && ! WC_Validation::is_postcode( $postcode, $country ) ) {
421
-				$errors->add( 'validation', __( 'Please enter a valid billing postcode / ZIP.', 'woocommerce-gateway-stripe' ) );
420
+			if ('' !== $required_fields['billing_postcode'] && ! WC_Validation::is_postcode($postcode, $country)) {
421
+				$errors->add('validation', __('Please enter a valid billing postcode / ZIP.', 'woocommerce-gateway-stripe'));
422 422
 			}
423 423
 		}
424 424
 
425 425
 		// Don't check this on add payment method page.
426
-		if ( ( isset( $_POST['is_add_payment_page'] ) && 'no' === $_POST['is_add_payment_page'] ) ) {
427
-			if ( empty( $all_fields['woocommerce_checkout_update_totals'] ) && empty( $all_fields['terms'] ) && apply_filters( 'woocommerce_checkout_show_terms', wc_get_page_id( 'terms' ) > 0 ) ) {
428
-				$errors->add( 'terms', __( 'You must accept our Terms &amp; Conditions.', 'woocommerce-gateway-stripe' ) );
426
+		if ((isset($_POST['is_add_payment_page']) && 'no' === $_POST['is_add_payment_page'])) {
427
+			if (empty($all_fields['woocommerce_checkout_update_totals']) && empty($all_fields['terms']) && apply_filters('woocommerce_checkout_show_terms', wc_get_page_id('terms') > 0)) {
428
+				$errors->add('terms', __('You must accept our Terms &amp; Conditions.', 'woocommerce-gateway-stripe'));
429 429
 			}
430 430
 		}
431 431
 
432
-		if ( WC()->cart->needs_shipping() && $validate_shipping_fields ) {
432
+		if (WC()->cart->needs_shipping() && $validate_shipping_fields) {
433 433
 			// Check if postal code is valid format.
434
-			if ( ! empty( $required_fields['shipping_postcode'] ) ) {
435
-				$country = isset( $required_fields['shipping_country'] ) ? $required_fields['shipping_country'] : WC()->customer->get_shipping_country();
436
-				$postcode = wc_format_postcode( $required_fields['shipping_postcode'], $country );
434
+			if ( ! empty($required_fields['shipping_postcode'])) {
435
+				$country = isset($required_fields['shipping_country']) ? $required_fields['shipping_country'] : WC()->customer->get_shipping_country();
436
+				$postcode = wc_format_postcode($required_fields['shipping_postcode'], $country);
437 437
 
438
-				if ( '' !== $required_fields['shipping_postcode'] && ! WC_Validation::is_postcode( $postcode, $country ) ) {
439
-					$errors->add( 'validation', __( 'Please enter a valid shipping postcode / ZIP.', 'woocommerce-gateway-stripe' ) );
438
+				if ('' !== $required_fields['shipping_postcode'] && ! WC_Validation::is_postcode($postcode, $country)) {
439
+					$errors->add('validation', __('Please enter a valid shipping postcode / ZIP.', 'woocommerce-gateway-stripe'));
440 440
 				}
441 441
 			}
442 442
 		}
443 443
 
444
-		if ( WC()->cart->needs_shipping() ) {
444
+		if (WC()->cart->needs_shipping()) {
445 445
 			$shipping_country = WC()->customer->get_shipping_country();
446 446
 
447
-			if ( empty( $shipping_country ) ) {
448
-				$errors->add( 'shipping', __( 'Please enter an address to continue.', 'woocommerce-gateway-stripe' ) );
449
-			} elseif ( ! in_array( WC()->customer->get_shipping_country(), array_keys( WC()->countries->get_shipping_countries() ) ) ) {
447
+			if (empty($shipping_country)) {
448
+				$errors->add('shipping', __('Please enter an address to continue.', 'woocommerce-gateway-stripe'));
449
+			} elseif ( ! in_array(WC()->customer->get_shipping_country(), array_keys(WC()->countries->get_shipping_countries()))) {
450 450
 				/* translators: country name */
451
-				$errors->add( 'shipping', sprintf( __( 'Unfortunately <strong>we do not ship %s</strong>. Please enter an alternative shipping address.', 'woocommerce-gateway-stripe' ), WC()->countries->shipping_to_prefix() . ' ' . WC()->customer->get_shipping_country() ) );
451
+				$errors->add('shipping', sprintf(__('Unfortunately <strong>we do not ship %s</strong>. Please enter an alternative shipping address.', 'woocommerce-gateway-stripe'), WC()->countries->shipping_to_prefix() . ' ' . WC()->customer->get_shipping_country()));
452 452
 			} else {
453
-				$chosen_shipping_methods = WC()->session->get( 'chosen_shipping_methods' );
453
+				$chosen_shipping_methods = WC()->session->get('chosen_shipping_methods');
454 454
 
455
-				foreach ( WC()->shipping->get_packages() as $i => $package ) {
456
-					if ( ! isset( $chosen_shipping_methods[ $i ], $package['rates'][ $chosen_shipping_methods[ $i ] ] ) ) {
457
-						$errors->add( 'shipping', __( 'No shipping method has been selected. Please double check your address, or contact us if you need any help.', 'woocommerce-gateway-stripe' ) );
455
+				foreach (WC()->shipping->get_packages() as $i => $package) {
456
+					if ( ! isset($chosen_shipping_methods[$i], $package['rates'][$chosen_shipping_methods[$i]])) {
457
+						$errors->add('shipping', __('No shipping method has been selected. Please double check your address, or contact us if you need any help.', 'woocommerce-gateway-stripe'));
458 458
 					}
459 459
 				}
460 460
 			}
461 461
 		}
462 462
 
463
-		if ( WC()->cart->needs_payment() ) {
463
+		if (WC()->cart->needs_payment()) {
464 464
 			$available_gateways = WC()->payment_gateways->get_available_payment_gateways();
465 465
 
466
-			if ( ! isset( $available_gateways[ $all_fields['payment_method'] ] ) ) {
467
-				$errors->add( 'payment', __( 'Invalid payment method.', 'woocommerce-gateway-stripe' ) );
466
+			if ( ! isset($available_gateways[$all_fields['payment_method']])) {
467
+				$errors->add('payment', __('Invalid payment method.', 'woocommerce-gateway-stripe'));
468 468
 			} else {
469
-				$available_gateways[ $all_fields['payment_method'] ]->validate_fields();
469
+				$available_gateways[$all_fields['payment_method']]->validate_fields();
470 470
 			}
471 471
 		}
472 472
 
473
-		if ( 0 === count( $errors->errors ) ) {
474
-			wp_send_json( 'success' );
473
+		if (0 === count($errors->errors)) {
474
+			wp_send_json('success');
475 475
 		} else {
476
-			foreach ( $errors->get_error_messages() as $message ) {
477
-				wc_add_notice( $message, 'error' );
476
+			foreach ($errors->get_error_messages() as $message) {
477
+				wc_add_notice($message, 'error');
478 478
 			}
479 479
 
480 480
 			$this->send_ajax_failure_response();
@@ -488,9 +488,9 @@  discard block
 block discarded – undo
488 488
 	 * @version 4.0.0
489 489
 	 */
490 490
 	public function send_ajax_failure_response() {
491
-		if ( is_ajax() ) {
491
+		if (is_ajax()) {
492 492
 			// only print notices if not reloading the checkout, otherwise they're lost in the page reload.
493
-			if ( ! isset( WC()->session->reload_checkout ) ) {
493
+			if ( ! isset(WC()->session->reload_checkout)) {
494 494
 				ob_start();
495 495
 				wc_print_notices();
496 496
 				$messages = ob_get_clean();
@@ -498,14 +498,14 @@  discard block
 block discarded – undo
498 498
 
499 499
 			$response = array(
500 500
 				'result'   => 'failure',
501
-				'messages' => isset( $messages ) ? $messages : '',
502
-				'refresh'  => isset( WC()->session->refresh_totals ),
503
-				'reload'   => isset( WC()->session->reload_checkout ),
501
+				'messages' => isset($messages) ? $messages : '',
502
+				'refresh'  => isset(WC()->session->refresh_totals),
503
+				'reload'   => isset(WC()->session->reload_checkout),
504 504
 			);
505 505
 
506
-			unset( WC()->session->refresh_totals, WC()->session->reload_checkout );
506
+			unset(WC()->session->refresh_totals, WC()->session->reload_checkout);
507 507
 
508
-			wp_send_json( $response );
508
+			wp_send_json($response);
509 509
 		}
510 510
 	}
511 511
 }
Please login to merge, or discard this patch.