Completed
Push — master ( 2515df...302e86 )
by Roy
02:08
created
includes/payment-methods/class-wc-gateway-stripe-bitcoin.php 1 patch
Spacing   +88 added lines, -88 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
 	}
@@ -135,8 +135,8 @@  discard block
 block discarded – undo
135 135
 	 * @version 4.0.0
136 136
 	 */
137 137
 	public function get_environment_warning() {
138
-		if ( 'yes' === $this->enabled && ! in_array( get_woocommerce_currency(), $this->get_supported_currency() ) ) {
139
-			$message = __( 'Bitcoin is enabled - it requires store currency to be set to USD.', 'woocommerce-gateway-stripe' );
138
+		if ('yes' === $this->enabled && ! in_array(get_woocommerce_currency(), $this->get_supported_currency())) {
139
+			$message = __('Bitcoin is enabled - it requires store currency to be set to USD.', 'woocommerce-gateway-stripe');
140 140
 
141 141
 			return $message;
142 142
 		}
@@ -152,9 +152,9 @@  discard block
 block discarded – undo
152 152
 	 * @return array
153 153
 	 */
154 154
 	public function get_supported_currency() {
155
-		return apply_filters( 'wc_stripe_bitcoin_supported_currencies', array(
155
+		return apply_filters('wc_stripe_bitcoin_supported_currencies', array(
156 156
 			'USD',
157
-		) );
157
+		));
158 158
 	}
159 159
 
160 160
 	/**
@@ -165,7 +165,7 @@  discard block
 block discarded – undo
165 165
 	 * @return bool
166 166
 	 */
167 167
 	public function is_available() {
168
-		if ( ! in_array( get_woocommerce_currency(), $this->get_supported_currency() ) ) {
168
+		if ( ! in_array(get_woocommerce_currency(), $this->get_supported_currency())) {
169 169
 			return false;
170 170
 		}
171 171
 
@@ -186,7 +186,7 @@  discard block
 block discarded – undo
186 186
 
187 187
 		$icons_str .= $icons['bitcoin'];
188 188
 
189
-		return apply_filters( 'woocommerce_gateway_icon', $icons_str, $this->id );
189
+		return apply_filters('woocommerce_gateway_icon', $icons_str, $this->id);
190 190
 	}
191 191
 
192 192
 	/**
@@ -197,19 +197,19 @@  discard block
 block discarded – undo
197 197
 	 * @access public
198 198
 	 */
199 199
 	public function payment_scripts() {
200
-		if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) && ! is_add_payment_method_page() ) {
200
+		if ( ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order']) && ! is_add_payment_method_page()) {
201 201
 			return;
202 202
 		}
203 203
 
204
-		wp_enqueue_style( 'stripe_paymentfonts' );
205
-		wp_enqueue_script( 'woocommerce_stripe' );
204
+		wp_enqueue_style('stripe_paymentfonts');
205
+		wp_enqueue_script('woocommerce_stripe');
206 206
 	}
207 207
 
208 208
 	/**
209 209
 	 * Initialize Gateway Settings Form Fields.
210 210
 	 */
211 211
 	public function init_form_fields() {
212
-		$this->form_fields = require( WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-bitcoin-settings.php' );
212
+		$this->form_fields = require(WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-bitcoin-settings.php');
213 213
 	}
214 214
 
215 215
 	/**
@@ -220,25 +220,25 @@  discard block
 block discarded – undo
220 220
 		$total                = WC()->cart->total;
221 221
 
222 222
 		// If paying from order, we need to get total from order not cart.
223
-		if ( isset( $_GET['pay_for_order'] ) && ! empty( $_GET['key'] ) ) {
224
-			$order = wc_get_order( wc_get_order_id_by_order_key( wc_clean( $_GET['key'] ) ) );
223
+		if (isset($_GET['pay_for_order']) && ! empty($_GET['key'])) {
224
+			$order = wc_get_order(wc_get_order_id_by_order_key(wc_clean($_GET['key'])));
225 225
 			$total = $order->get_total();
226 226
 		}
227 227
 
228
-		if ( is_add_payment_method_page() ) {
229
-			$pay_button_text = __( 'Add Payment', 'woocommerce-gateway-stripe' );
230
-			$total        = '';
228
+		if (is_add_payment_method_page()) {
229
+			$pay_button_text = __('Add Payment', 'woocommerce-gateway-stripe');
230
+			$total = '';
231 231
 		} else {
232 232
 			$pay_button_text = '';
233 233
 		}
234 234
 
235 235
 		echo '<div
236 236
 			id="stripe-bitcoin-payment-data"
237
-			data-amount="' . esc_attr( WC_Stripe_Helper::get_stripe_amount( $total ) ) . '"
238
-			data-currency="' . esc_attr( strtolower( get_woocommerce_currency() ) ) . '">';
237
+			data-amount="' . esc_attr(WC_Stripe_Helper::get_stripe_amount($total)) . '"
238
+			data-currency="' . esc_attr(strtolower(get_woocommerce_currency())) . '">';
239 239
 
240
-		if ( $this->description ) {
241
-			echo apply_filters( 'wc_stripe_description', wpautop( wp_kses_post( $this->description ) ) );
240
+		if ($this->description) {
241
+			echo apply_filters('wc_stripe_description', wpautop(wp_kses_post($this->description)));
242 242
 		}
243 243
 
244 244
 		echo '</div>';
@@ -249,8 +249,8 @@  discard block
 block discarded – undo
249 249
 	 *
250 250
 	 * @param int $order_id
251 251
 	 */
252
-	public function thankyou_page( $order_id ) {
253
-		$this->get_instructions( $order_id );
252
+	public function thankyou_page($order_id) {
253
+		$this->get_instructions($order_id);
254 254
 	}
255 255
 
256 256
 	/**
@@ -262,13 +262,13 @@  discard block
 block discarded – undo
262 262
 	 * @param bool $sent_to_admin
263 263
 	 * @param bool $plain_text
264 264
 	 */
265
-	public function email_instructions( $order, $sent_to_admin, $plain_text = false ) {
265
+	public function email_instructions($order, $sent_to_admin, $plain_text = false) {
266 266
 		$order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
267 267
 
268 268
 		$payment_method = WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method();
269 269
 
270
-		if ( ! $sent_to_admin && 'stripe_bitcoin' === $payment_method && $order->has_status( 'on-hold' ) ) {
271
-			$this->get_instructions( $order_id, $plain_text );
270
+		if ( ! $sent_to_admin && 'stripe_bitcoin' === $payment_method && $order->has_status('on-hold')) {
271
+			$this->get_instructions($order_id, $plain_text);
272 272
 		}
273 273
 	}
274 274
 
@@ -279,38 +279,38 @@  discard block
 block discarded – undo
279 279
 	 * @version 4.0.0
280 280
 	 * @param int $order_id
281 281
 	 */
282
-	public function get_instructions( $order_id, $plain_text = false ) {
283
-		$data = get_post_meta( $order_id, '_stripe_bitcoin', true );
282
+	public function get_instructions($order_id, $plain_text = false) {
283
+		$data = get_post_meta($order_id, '_stripe_bitcoin', true);
284 284
 
285
-		if ( $plain_text ) {
286
-			esc_html_e( 'Please pay the following:', 'woocommerce-gateway-stripe' ) . "\n\n";
285
+		if ($plain_text) {
286
+			esc_html_e('Please pay the following:', 'woocommerce-gateway-stripe') . "\n\n";
287 287
 			echo "=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\n\n";
288
-			esc_html_e( 'Bitcoin Amount:', 'woocommerce-gateway-stripe' ) . "\n\n";
288
+			esc_html_e('Bitcoin Amount:', 'woocommerce-gateway-stripe') . "\n\n";
289 289
 			echo $data['amount'] . "\n\n";
290 290
 			echo "=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\n\n";
291
-			esc_html_e( 'Receiver:', 'woocommerce-gateway-stripe' ) . "\n\n";
291
+			esc_html_e('Receiver:', 'woocommerce-gateway-stripe') . "\n\n";
292 292
 			echo $data['address'] . "\n\n";
293 293
 			echo "=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\n\n";
294
-			esc_html_e( 'URI:', 'woocommerce-gateway-stripe' ) . "\n\n";
294
+			esc_html_e('URI:', 'woocommerce-gateway-stripe') . "\n\n";
295 295
 			echo $data['uri'] . "\n\n";
296 296
 		} else {
297 297
 			?>
298
-			<h3><?php esc_html_e( 'Please pay the following:', 'woocommerce-gateway-stripe' ); ?></h3>
298
+			<h3><?php esc_html_e('Please pay the following:', 'woocommerce-gateway-stripe'); ?></h3>
299 299
 			<ul class="woocommerce-order-overview woocommerce-thankyou-order-details order_details">
300 300
 			<li class="woocommerce-order-overview__order order">
301
-				<?php esc_html_e( 'Bitcoin Amount:', 'woocommerce-gateway-stripe' ); ?>
301
+				<?php esc_html_e('Bitcoin Amount:', 'woocommerce-gateway-stripe'); ?>
302 302
 				<strong><?php echo $data['amount']; ?></strong>
303 303
 			</li>
304 304
 			<li class="woocommerce-order-overview__order order">
305
-				<?php esc_html_e( 'Receiver:', 'woocommerce-gateway-stripe' ); ?>
305
+				<?php esc_html_e('Receiver:', 'woocommerce-gateway-stripe'); ?>
306 306
 				<strong><?php echo $data['address']; ?></strong>
307 307
 			</li>
308 308
 			<li class="woocommerce-order-overview__order order">
309
-				<?php esc_html_e( 'URI:', 'woocommerce-gateway-stripe' ); ?>
309
+				<?php esc_html_e('URI:', 'woocommerce-gateway-stripe'); ?>
310 310
 				<strong>
311 311
 				<?php
312 312
 				/* translators: link */
313
-				printf( __( '<a href="%s">Pay Bitcoin</a>', 'woocommerce-gateway-stripe' ), $data['uri'] );
313
+				printf(__('<a href="%s">Pay Bitcoin</a>', 'woocommerce-gateway-stripe'), $data['uri']);
314 314
 				?>
315 315
 				</strong>
316 316
 			</li>
@@ -327,7 +327,7 @@  discard block
 block discarded – undo
327 327
 	 * @param object $order
328 328
 	 * @param object $source_object
329 329
 	 */
330
-	public function save_instructions( $order, $source_object ) {
330
+	public function save_instructions($order, $source_object) {
331 331
 		$data = array(
332 332
 			'amount'  => $source_object->bitcoin->amount,
333 333
 			'address' => $source_object->bitcoin->address,
@@ -336,7 +336,7 @@  discard block
 block discarded – undo
336 336
 
337 337
 		$order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
338 338
 
339
-		update_post_meta( $order_id, '_stripe_bitcoin', $data );
339
+		update_post_meta($order_id, '_stripe_bitcoin', $data);
340 340
 	}
341 341
 
342 342
 	/**
@@ -350,40 +350,40 @@  discard block
 block discarded – undo
350 350
 	 *
351 351
 	 * @return array|void
352 352
 	 */
353
-	public function process_payment( $order_id, $retry = true, $force_save_source = false ) {
353
+	public function process_payment($order_id, $retry = true, $force_save_source = false) {
354 354
 		try {
355
-			$order = wc_get_order( $order_id );
356
-			$source_object = ! empty( $_POST['stripe_source'] ) ? json_decode( stripslashes( $_POST['stripe_source'] ) ) : false;
355
+			$order = wc_get_order($order_id);
356
+			$source_object = ! empty($_POST['stripe_source']) ? json_decode(stripslashes($_POST['stripe_source'])) : false;
357 357
 
358 358
 			// This comes from the create account checkbox in the checkout page.
359
-			$create_account = ! empty( $_POST['createaccount'] ) ? true : false;
359
+			$create_account = ! empty($_POST['createaccount']) ? true : false;
360 360
 
361
-			if ( $create_account ) {
361
+			if ($create_account) {
362 362
 				$new_customer_id     = WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id();
363
-				$new_stripe_customer = new WC_Stripe_Customer( $new_customer_id );
363
+				$new_stripe_customer = new WC_Stripe_Customer($new_customer_id);
364 364
 				$new_stripe_customer->create_customer();
365 365
 			}
366 366
 
367
-			$prepared_source = $this->prepare_source( get_current_user_id(), $force_save_source );
367
+			$prepared_source = $this->prepare_source(get_current_user_id(), $force_save_source);
368 368
 
369
-			if ( empty( $prepared_source->source ) ) {
370
-				$error_msg = __( 'Payment processing failed. Please retry.', 'woocommerce-gateway-stripe' );
371
-				throw new Exception( $error_msg );
369
+			if (empty($prepared_source->source)) {
370
+				$error_msg = __('Payment processing failed. Please retry.', 'woocommerce-gateway-stripe');
371
+				throw new Exception($error_msg);
372 372
 			}
373 373
 
374 374
 			// Store source to order meta.
375
-			$this->save_source( $order, $prepared_source );
375
+			$this->save_source($order, $prepared_source);
376 376
 
377 377
 
378 378
 			// This will throw exception if not valid.
379
-			$this->validate_minimum_order_amount( $order );
379
+			$this->validate_minimum_order_amount($order);
380 380
 
381
-			$this->save_instructions( $order, $source_object );
381
+			$this->save_instructions($order, $source_object);
382 382
 
383 383
 			// Mark as on-hold (we're awaiting the payment)
384
-			$order->update_status( 'on-hold', __( 'Awaiting Bitcoin payment', 'woocommerce-gateway-stripe' ) );
384
+			$order->update_status('on-hold', __('Awaiting Bitcoin payment', 'woocommerce-gateway-stripe'));
385 385
 
386
-			wc_reduce_stock_levels( $order_id );
386
+			wc_reduce_stock_levels($order_id);
387 387
 
388 388
 			// Remove cart
389 389
 			WC()->cart->empty_cart();
@@ -391,16 +391,16 @@  discard block
 block discarded – undo
391 391
 			// Return thankyou redirect
392 392
 			return array(
393 393
 				'result'    => 'success',
394
-				'redirect'  => $this->get_return_url( $order ),
394
+				'redirect'  => $this->get_return_url($order),
395 395
 			);
396
-		} catch ( Exception $e ) {
397
-			wc_add_notice( $e->getMessage(), 'error' );
398
-			WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() );
396
+		} catch (Exception $e) {
397
+			wc_add_notice($e->getMessage(), 'error');
398
+			WC_Stripe_Logger::log('Error: ' . $e->getMessage());
399 399
 
400
-			do_action( 'wc_gateway_stripe_process_payment_error', $e, $order );
400
+			do_action('wc_gateway_stripe_process_payment_error', $e, $order);
401 401
 
402
-			if ( $order->has_status( array( 'pending', 'failed' ) ) ) {
403
-				$this->send_failed_order_email( $order_id );
402
+			if ($order->has_status(array('pending', 'failed'))) {
403
+				$this->send_failed_order_email($order_id);
404 404
 			}
405 405
 
406 406
 			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( $post_data, 'sources' );
261
+		return WC_Stripe_API::request($post_data, '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 Exception( $response->error->message );
296
+				throw new Exception($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 ( Exception $e ) {
313
-			wc_add_notice( $e->getMessage(), 'error' );
314
-			WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() );
312
+		} catch (Exception $e) {
313
+			wc_add_notice($e->getMessage(), '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   +85 added lines, -85 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
 	/**
@@ -217,24 +217,24 @@  discard block
 block discarded – undo
217 217
 			'IT' => 'Italy',
218 218
 		);
219 219
 		?>
220
-		<fieldset id="wc-<?php echo esc_attr( $this->id ); ?>-form" class="wc-payment-form">
221
-			<?php do_action( 'woocommerce_credit_card_form_start', $this->id ); ?>
220
+		<fieldset id="wc-<?php echo esc_attr($this->id); ?>-form" class="wc-payment-form">
221
+			<?php do_action('woocommerce_credit_card_form_start', $this->id); ?>
222 222
 			<label for="stripe-bank-country">
223
-				<?php _e( 'Country origin of your bank.', 'woocommerce-gateway-stripe' ); ?>
223
+				<?php _e('Country origin of your bank.', 'woocommerce-gateway-stripe'); ?>
224 224
 			</label>
225 225
 			<br />
226 226
 			<p class="form-row form-row-wide validate-required">
227 227
 			<select id="stripe-bank-country" class="wc-enhanced-select" name="stripe_sofort_bank_country">
228
-				<option value="-1"><?php esc_html_e( 'Choose Bank Country', 'woocommerce-gateway-stripe' ); ?></option>
229
-				<?php foreach ( $supported_countries as $code => $country ) { ?>
230
-				<option value="<?php echo esc_attr( $code ); ?>"><?php echo esc_html( $country ); ?></option>
228
+				<option value="-1"><?php esc_html_e('Choose Bank Country', 'woocommerce-gateway-stripe'); ?></option>
229
+				<?php foreach ($supported_countries as $code => $country) { ?>
230
+				<option value="<?php echo esc_attr($code); ?>"><?php echo esc_html($country); ?></option>
231 231
 				<?php } ?>
232 232
 			</select>
233 233
 			</p>
234 234
 
235 235
 			<!-- Used to display form errors -->
236 236
 			<div class="stripe-source-errors" role="alert"></div>
237
-			<?php do_action( 'woocommerce_credit_card_form_end', $this->id ); ?>
237
+			<?php do_action('woocommerce_credit_card_form_end', $this->id); ?>
238 238
 			<div class="clear"></div>
239 239
 		</fieldset>
240 240
 		<?php
@@ -248,25 +248,25 @@  discard block
 block discarded – undo
248 248
 		$total                = WC()->cart->total;
249 249
 
250 250
 		// If paying from order, we need to get total from order not cart.
251
-		if ( isset( $_GET['pay_for_order'] ) && ! empty( $_GET['key'] ) ) {
252
-			$order = wc_get_order( wc_get_order_id_by_order_key( wc_clean( $_GET['key'] ) ) );
251
+		if (isset($_GET['pay_for_order']) && ! empty($_GET['key'])) {
252
+			$order = wc_get_order(wc_get_order_id_by_order_key(wc_clean($_GET['key'])));
253 253
 			$total = $order->get_total();
254 254
 		}
255 255
 
256
-		if ( is_add_payment_method_page() ) {
257
-			$pay_button_text = __( 'Add Payment', 'woocommerce-gateway-stripe' );
258
-			$total        = '';
256
+		if (is_add_payment_method_page()) {
257
+			$pay_button_text = __('Add Payment', 'woocommerce-gateway-stripe');
258
+			$total = '';
259 259
 		} else {
260 260
 			$pay_button_text = '';
261 261
 		}
262 262
 
263 263
 		echo '<div
264 264
 			id="stripe-sofort-payment-data"
265
-			data-amount="' . esc_attr( WC_Stripe_Helper::get_stripe_amount( $total ) ) . '"
266
-			data-currency="' . esc_attr( strtolower( get_woocommerce_currency() ) ) . '">';
265
+			data-amount="' . esc_attr(WC_Stripe_Helper::get_stripe_amount($total)) . '"
266
+			data-currency="' . esc_attr(strtolower(get_woocommerce_currency())) . '">';
267 267
 
268
-		if ( $this->description ) {
269
-			echo apply_filters( 'wc_stripe_description', wpautop( wp_kses_post( $this->description ) ) );
268
+		if ($this->description) {
269
+			echo apply_filters('wc_stripe_description', wpautop(wp_kses_post($this->description)));
270 270
 		}
271 271
 
272 272
 		$this->form();
@@ -282,26 +282,26 @@  discard block
 block discarded – undo
282 282
 	 * @param object $order
283 283
 	 * @return mixed
284 284
 	 */
285
-	public function create_source( $order ) {
285
+	public function create_source($order) {
286 286
 		$currency                          = WC_Stripe_Helper::is_pre_30() ? $order->get_order_currency() : $order->get_currency();
287 287
 		$order_id                          = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
288
-		$bank_country                      = wc_clean( $_POST['stripe_sofort_bank_country'] );
289
-		$return_url                        = $this->get_stripe_return_url( $order );
288
+		$bank_country                      = wc_clean($_POST['stripe_sofort_bank_country']);
289
+		$return_url                        = $this->get_stripe_return_url($order);
290 290
 		$post_data                         = array();
291
-		$post_data['amount']               = WC_Stripe_Helper::get_stripe_amount( $order->get_total(), $currency );
292
-		$post_data['currency']             = strtolower( $currency );
291
+		$post_data['amount']               = WC_Stripe_Helper::get_stripe_amount($order->get_total(), $currency);
292
+		$post_data['currency']             = strtolower($currency);
293 293
 		$post_data['type']                 = 'sofort';
294
-		$post_data['owner']                = $this->get_owner_details( $order );
295
-		$post_data['redirect']             = array( 'return_url' => $return_url );
296
-		$post_data['sofort']               = array( 'country' => $bank_country );
294
+		$post_data['owner']                = $this->get_owner_details($order);
295
+		$post_data['redirect']             = array('return_url' => $return_url);
296
+		$post_data['sofort']               = array('country' => $bank_country);
297 297
 
298
-		if ( ! empty( $this->statement_descriptor ) ) {
299
-			$post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor( $this->statement_descriptor );
298
+		if ( ! empty($this->statement_descriptor)) {
299
+			$post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor($this->statement_descriptor);
300 300
 		}
301 301
 
302
-		WC_Stripe_Logger::log( 'Info: Begin creating SOFORT source' );
302
+		WC_Stripe_Logger::log('Info: Begin creating SOFORT source');
303 303
 
304
-		return WC_Stripe_API::request( $post_data, 'sources' );
304
+		return WC_Stripe_API::request($post_data, 'sources');
305 305
 	}
306 306
 
307 307
 	/**
@@ -315,51 +315,51 @@  discard block
 block discarded – undo
315 315
 	 *
316 316
 	 * @return array|void
317 317
 	 */
318
-	public function process_payment( $order_id, $retry = true, $force_save_source = false ) {
318
+	public function process_payment($order_id, $retry = true, $force_save_source = false) {
319 319
 		try {
320
-			$order = wc_get_order( $order_id );
320
+			$order = wc_get_order($order_id);
321 321
 
322 322
 			// This will throw exception if not valid.
323
-			$this->validate_minimum_order_amount( $order );
323
+			$this->validate_minimum_order_amount($order);
324 324
 
325 325
 			// This comes from the create account checkbox in the checkout page.
326
-			$create_account = ! empty( $_POST['createaccount'] ) ? true : false;
326
+			$create_account = ! empty($_POST['createaccount']) ? true : false;
327 327
 
328
-			if ( $create_account ) {
328
+			if ($create_account) {
329 329
 				$new_customer_id     = WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id();
330
-				$new_stripe_customer = new WC_Stripe_Customer( $new_customer_id );
330
+				$new_stripe_customer = new WC_Stripe_Customer($new_customer_id);
331 331
 				$new_stripe_customer->create_customer();
332 332
 			}
333 333
 
334
-			$response = $this->create_source( $order );
334
+			$response = $this->create_source($order);
335 335
 
336
-			if ( ! empty( $response->error ) ) {
337
-				$order->add_order_note( $response->error->message );
336
+			if ( ! empty($response->error)) {
337
+				$order->add_order_note($response->error->message);
338 338
 
339
-				throw new Exception( $response->error->message );
339
+				throw new Exception($response->error->message);
340 340
 			}
341 341
 
342
-			if ( WC_Stripe_Helper::is_pre_30() ) {
343
-				update_post_meta( $order_id, '_stripe_source_id', $response->id );
342
+			if (WC_Stripe_Helper::is_pre_30()) {
343
+				update_post_meta($order_id, '_stripe_source_id', $response->id);
344 344
 			} else {
345
-				$order->update_meta_data( '_stripe_source_id', $response->id );
345
+				$order->update_meta_data('_stripe_source_id', $response->id);
346 346
 				$order->save();
347 347
 			}
348 348
 
349
-			WC_Stripe_Logger::log( 'Info: Redirecting to SOFORT...' );
349
+			WC_Stripe_Logger::log('Info: Redirecting to SOFORT...');
350 350
 
351 351
 			return array(
352 352
 				'result'   => 'success',
353
-				'redirect' => esc_url_raw( $response->redirect->url ),
353
+				'redirect' => esc_url_raw($response->redirect->url),
354 354
 			);
355
-		} catch ( Exception $e ) {
356
-			wc_add_notice( $e->getMessage(), 'error' );
357
-			WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() );
355
+		} catch (Exception $e) {
356
+			wc_add_notice($e->getMessage(), 'error');
357
+			WC_Stripe_Logger::log('Error: ' . $e->getMessage());
358 358
 
359
-			do_action( 'wc_gateway_stripe_process_payment_error', $e, $order );
359
+			do_action('wc_gateway_stripe_process_payment_error', $e, $order);
360 360
 
361
-			if ( $order->has_status( array( 'pending', 'failed' ) ) ) {
362
-				$this->send_failed_order_email( $order_id );
361
+			if ($order->has_status(array('pending', 'failed'))) {
362
+				$this->send_failed_order_email($order_id);
363 363
 			}
364 364
 
365 365
 			return array(
Please login to merge, or discard this patch.
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( $post_data, 'sources' );
261
+		return WC_Stripe_API::request($post_data, '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 Exception( $response->error->message );
296
+				throw new Exception($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 ( Exception $e ) {
313
-			wc_add_notice( $e->getMessage(), 'error' );
314
-			WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() );
312
+		} catch (Exception $e) {
313
+			wc_add_notice($e->getMessage(), '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-sepa.php 1 patch
Spacing   +97 added lines, -97 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,7 +167,7 @@  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
 
@@ -188,7 +188,7 @@  discard block
 block discarded – undo
188 188
 
189 189
 		$icons_str .= $icons['sepa'];
190 190
 
191
-		return apply_filters( 'woocommerce_gateway_icon', $icons_str, $this->id );
191
+		return apply_filters('woocommerce_gateway_icon', $icons_str, $this->id);
192 192
 	}
193 193
 
194 194
 	/**
@@ -199,19 +199,19 @@  discard block
 block discarded – undo
199 199
 	 * @access public
200 200
 	 */
201 201
 	public function payment_scripts() {
202
-		if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) && ! is_add_payment_method_page() ) {
202
+		if ( ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order']) && ! is_add_payment_method_page()) {
203 203
 			return;
204 204
 		}
205 205
 
206
-		wp_enqueue_style( 'stripe_paymentfonts' );
207
-		wp_enqueue_script( 'woocommerce_stripe' );
206
+		wp_enqueue_style('stripe_paymentfonts');
207
+		wp_enqueue_script('woocommerce_stripe');
208 208
 	}
209 209
 
210 210
 	/**
211 211
 	 * Initialize Gateway Settings Form Fields.
212 212
 	 */
213 213
 	public function init_form_fields() {
214
-		$this->form_fields = require( WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-sepa-settings.php' );
214
+		$this->form_fields = require(WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-sepa-settings.php');
215 215
 	}
216 216
 
217 217
 	/**
@@ -223,7 +223,7 @@  discard block
 block discarded – undo
223 223
 	 */
224 224
 	public function mandate_display() {
225 225
 		/* translators: statement descriptor */
226
-		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 ) );
226
+		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));
227 227
 	}
228 228
 
229 229
 	/**
@@ -234,24 +234,24 @@  discard block
 block discarded – undo
234 234
 	 */
235 235
 	public function form() {
236 236
 		?>
237
-		<fieldset id="wc-<?php echo esc_attr( $this->id ); ?>-form" class="wc-payment-form">
238
-			<?php do_action( 'woocommerce_credit_card_form_start', $this->id ); ?>
237
+		<fieldset id="wc-<?php echo esc_attr($this->id); ?>-form" class="wc-payment-form">
238
+			<?php do_action('woocommerce_credit_card_form_start', $this->id); ?>
239 239
 			<p class="wc-stripe-sepa-mandate" style="margin-bottom:40px;"><?php $this->mandate_display(); ?></p>
240 240
 			<p class="form-row form-row-wide validate-required">
241 241
 				<label for="stripe-sepa-owner">
242
-					<?php esc_html_e( 'IBAN Account Name.', 'woocommerce-gateway-stripe' ); ?>
242
+					<?php esc_html_e('IBAN Account Name.', 'woocommerce-gateway-stripe'); ?>
243 243
 				</label>
244 244
 				<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;" />
245 245
 			</p>
246 246
 			<p class="form-row form-row-wide validate-required">
247 247
 				<label for="stripe-sepa-iban">
248
-					<?php esc_html_e( 'IBAN Account Number.', 'woocommerce-gateway-stripe' ); ?>
248
+					<?php esc_html_e('IBAN Account Number.', 'woocommerce-gateway-stripe'); ?>
249 249
 				</label>
250 250
 				<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;" />
251 251
 			</p>
252 252
 			<!-- Used to display form errors -->
253 253
 			<div class="stripe-source-errors" role="alert"></div>
254
-			<?php do_action( 'woocommerce_credit_card_form_end', $this->id ); ?>
254
+			<?php do_action('woocommerce_credit_card_form_end', $this->id); ?>
255 255
 			<div class="clear"></div>
256 256
 		</fieldset>
257 257
 		<?php
@@ -263,42 +263,42 @@  discard block
 block discarded – undo
263 263
 	public function payment_fields() {
264 264
 		$user                 = wp_get_current_user();
265 265
 		$total                = WC()->cart->total;
266
-		$display_tokenization = $this->supports( 'tokenization' ) && is_checkout() && $this->saved_cards;
266
+		$display_tokenization = $this->supports('tokenization') && is_checkout() && $this->saved_cards;
267 267
 
268 268
 		// If paying from order, we need to get total from order not cart.
269
-		if ( isset( $_GET['pay_for_order'] ) && ! empty( $_GET['key'] ) ) {
270
-			$order = wc_get_order( wc_get_order_id_by_order_key( wc_clean( $_GET['key'] ) ) );
269
+		if (isset($_GET['pay_for_order']) && ! empty($_GET['key'])) {
270
+			$order = wc_get_order(wc_get_order_id_by_order_key(wc_clean($_GET['key'])));
271 271
 			$total = $order->get_total();
272 272
 		}
273 273
 
274
-		if ( is_add_payment_method_page() ) {
275
-			$pay_button_text = __( 'Add Payment', 'woocommerce-gateway-stripe' );
276
-			$total        = '';
274
+		if (is_add_payment_method_page()) {
275
+			$pay_button_text = __('Add Payment', 'woocommerce-gateway-stripe');
276
+			$total = '';
277 277
 		} else {
278 278
 			$pay_button_text = '';
279 279
 		}
280 280
 
281 281
 		echo '<div
282 282
 			id="stripe-sepa_debit-payment-data"
283
-			data-amount="' . esc_attr( WC_Stripe_Helper::get_stripe_amount( $total ) ) . '"
284
-			data-currency="' . esc_attr( strtolower( get_woocommerce_currency() ) ) . '">';
283
+			data-amount="' . esc_attr(WC_Stripe_Helper::get_stripe_amount($total)) . '"
284
+			data-currency="' . esc_attr(strtolower(get_woocommerce_currency())) . '">';
285 285
 
286
-		if ( $this->description ) {
287
-			if ( $this->testmode ) {
288
-				$this->description .= ' ' . __( 'TEST MODE ENABLED. In test mode, you can use IBAN number DE89370400440532013000.', 'woocommerce-gateway-stripe' );
289
-				$this->description  = trim( $this->description );
286
+		if ($this->description) {
287
+			if ($this->testmode) {
288
+				$this->description .= ' ' . __('TEST MODE ENABLED. In test mode, you can use IBAN number DE89370400440532013000.', 'woocommerce-gateway-stripe');
289
+				$this->description  = trim($this->description);
290 290
 			}
291
-			echo apply_filters( 'wc_stripe_description', wpautop( wp_kses_post( $this->description ) ) );
291
+			echo apply_filters('wc_stripe_description', wpautop(wp_kses_post($this->description)));
292 292
 		}
293 293
 
294
-		if ( $display_tokenization ) {
294
+		if ($display_tokenization) {
295 295
 			$this->tokenization_script();
296 296
 			$this->saved_payment_methods();
297 297
 		}
298 298
 
299 299
 		$this->form();
300 300
 
301
-		if ( apply_filters( 'wc_stripe_display_save_payment_method_checkbox', $display_tokenization ) && ! is_add_payment_method_page() && ! isset( $_GET['change_payment_method'] ) ) {
301
+		if (apply_filters('wc_stripe_display_save_payment_method_checkbox', $display_tokenization) && ! is_add_payment_method_page() && ! isset($_GET['change_payment_method'])) {
302 302
 			$this->save_payment_method_checkbox();
303 303
 		}
304 304
 
@@ -316,80 +316,80 @@  discard block
 block discarded – undo
316 316
 	 *
317 317
 	 * @return array|void
318 318
 	 */
319
-	public function process_payment( $order_id, $retry = true, $force_save_source = false ) {
319
+	public function process_payment($order_id, $retry = true, $force_save_source = false) {
320 320
 		try {
321
-			$order = wc_get_order( $order_id );
321
+			$order = wc_get_order($order_id);
322 322
 
323 323
 			// This comes from the create account checkbox in the checkout page.
324
-			$create_account = ! empty( $_POST['createaccount'] ) ? true : false;
324
+			$create_account = ! empty($_POST['createaccount']) ? true : false;
325 325
 
326
-			if ( $create_account ) {
326
+			if ($create_account) {
327 327
 				$new_customer_id     = WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id();
328
-				$new_stripe_customer = new WC_Stripe_Customer( $new_customer_id );
328
+				$new_stripe_customer = new WC_Stripe_Customer($new_customer_id);
329 329
 				$new_stripe_customer->create_customer();
330 330
 			}
331 331
 
332
-			$prepared_source = $this->prepare_source( get_current_user_id(), $force_save_source );
332
+			$prepared_source = $this->prepare_source(get_current_user_id(), $force_save_source);
333 333
 
334 334
 			// Store source to order meta.
335
-			$this->save_source( $order, $prepared_source );
335
+			$this->save_source($order, $prepared_source);
336 336
 
337 337
 			// Result from Stripe API request.
338 338
 			$response = null;
339 339
 
340
-			if ( $order->get_total() > 0 ) {
340
+			if ($order->get_total() > 0) {
341 341
 				// This will throw exception if not valid.
342
-				$this->validate_minimum_order_amount( $order );
342
+				$this->validate_minimum_order_amount($order);
343 343
 
344
-				WC_Stripe_Logger::log( "Info: Begin processing payment for order $order_id for the amount of {$order->get_total()}" );
344
+				WC_Stripe_Logger::log("Info: Begin processing payment for order $order_id for the amount of {$order->get_total()}");
345 345
 
346 346
 				// Make the request.
347
-				$response = WC_Stripe_API::request( $this->generate_payment_request( $order, $prepared_source ) );
347
+				$response = WC_Stripe_API::request($this->generate_payment_request($order, $prepared_source));
348 348
 
349
-				if ( ! empty( $response->error ) ) {
349
+				if ( ! empty($response->error)) {
350 350
 					// If it is an API error such connection or server, let's retry.
351
-					if ( 'api_connection_error' === $response->error->type || 'api_error' === $response->error->type ) {
352
-						if ( $retry ) {
353
-							sleep( 5 );
354
-							return $this->process_payment( $order_id, false, $force_save_source );
351
+					if ('api_connection_error' === $response->error->type || 'api_error' === $response->error->type) {
352
+						if ($retry) {
353
+							sleep(5);
354
+							return $this->process_payment($order_id, false, $force_save_source);
355 355
 						} else {
356 356
 							$message = 'API connection error and retries exhausted.';
357
-							$order->add_order_note( $message );
358
-							throw new Exception( $message );
357
+							$order->add_order_note($message);
358
+							throw new Exception($message);
359 359
 						}
360 360
 					}
361 361
 
362 362
 					// Customer param wrong? The user may have been deleted on stripe's end. Remove customer_id. Can be retried without.
363
-					if ( preg_match( '/No such customer/i', $response->error->message ) && $retry ) {
364
-						delete_user_meta( WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id(), '_stripe_customer_id' );
363
+					if (preg_match('/No such customer/i', $response->error->message) && $retry) {
364
+						delete_user_meta(WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id(), '_stripe_customer_id');
365 365
 
366
-						return $this->process_payment( $order_id, false, $force_save_source );
367
-					} elseif ( preg_match( '/No such token/i', $response->error->message ) && $prepared_source->token_id ) {
366
+						return $this->process_payment($order_id, false, $force_save_source);
367
+					} elseif (preg_match('/No such token/i', $response->error->message) && $prepared_source->token_id) {
368 368
 						// Source param wrong? The CARD may have been deleted on stripe's end. Remove token and show message.
369
-						$wc_token = WC_Payment_Tokens::get( $prepared_source->token_id );
369
+						$wc_token = WC_Payment_Tokens::get($prepared_source->token_id);
370 370
 						$wc_token->delete();
371
-						$message = __( 'This card is no longer available and has been removed.', 'woocommerce-gateway-stripe' );
372
-						$order->add_order_note( $message );
373
-						throw new Exception( $message );
371
+						$message = __('This card is no longer available and has been removed.', 'woocommerce-gateway-stripe');
372
+						$order->add_order_note($message);
373
+						throw new Exception($message);
374 374
 					}
375 375
 
376 376
 					$localized_messages = WC_Stripe_Helper::get_localized_messages();
377 377
 
378
-					if ( 'card_error' === $response->error->type ) {
379
-						$message = isset( $localized_messages[ $response->error->code ] ) ? $localized_messages[ $response->error->code ] : $response->error->message;
378
+					if ('card_error' === $response->error->type) {
379
+						$message = isset($localized_messages[$response->error->code]) ? $localized_messages[$response->error->code] : $response->error->message;
380 380
 					} else {
381
-						$message = isset( $localized_messages[ $response->error->type ] ) ? $localized_messages[ $response->error->type ] : $response->error->message;
381
+						$message = isset($localized_messages[$response->error->type]) ? $localized_messages[$response->error->type] : $response->error->message;
382 382
 					}
383 383
 
384
-					$order->add_order_note( $message );
384
+					$order->add_order_note($message);
385 385
 
386
-					throw new Exception( $message );
386
+					throw new Exception($message);
387 387
 				}
388 388
 
389
-				do_action( 'wc_gateway_stripe_process_payment', $response, $order );
389
+				do_action('wc_gateway_stripe_process_payment', $response, $order);
390 390
 
391 391
 				// Process valid response.
392
-				$this->process_response( $response, $order );
392
+				$this->process_response($response, $order);
393 393
 			} else {
394 394
 				$order->payment_complete();
395 395
 			}
@@ -400,17 +400,17 @@  discard block
 block discarded – undo
400 400
 			// Return thank you page redirect.
401 401
 			return array(
402 402
 				'result'   => 'success',
403
-				'redirect' => $this->get_return_url( $order ),
403
+				'redirect' => $this->get_return_url($order),
404 404
 			);
405 405
 
406
-		} catch ( Exception $e ) {
407
-			wc_add_notice( $e->getMessage(), 'error' );
408
-			WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() );
406
+		} catch (Exception $e) {
407
+			wc_add_notice($e->getMessage(), 'error');
408
+			WC_Stripe_Logger::log('Error: ' . $e->getMessage());
409 409
 
410
-			do_action( 'wc_gateway_stripe_process_payment_error', $e, $order );
410
+			do_action('wc_gateway_stripe_process_payment_error', $e, $order);
411 411
 
412
-			if ( $order->has_status( array( 'pending', 'failed' ) ) ) {
413
-				$this->send_failed_order_email( $order_id );
412
+			if ($order->has_status(array('pending', 'failed'))) {
413
+				$this->send_failed_order_email($order_id);
414 414
 			}
415 415
 
416 416
 			return array(
Please login to merge, or discard this patch.
includes/payment-methods/class-wc-gateway-stripe-p24.php 1 patch
Spacing   +74 added lines, -74 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_p24';
60
-		$this->method_title         = __( 'Stripe P24', 'woocommerce-gateway-stripe' );
60
+		$this->method_title         = __('Stripe P24', '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 = __( 'P24 is enabled - it requires store currency to be set to Euros or Polish Zloty.', 'woocommerce-gateway-stripe' );
127
+		if ('yes' === $this->enabled && ! in_array(get_woocommerce_currency(), $this->get_supported_currency())) {
128
+			$message = __('P24 is enabled - it requires store currency to be set to Euros or Polish Zloty.', 'woocommerce-gateway-stripe');
129 129
 
130 130
 			return $message;
131 131
 		}
@@ -141,10 +141,10 @@  discard block
 block discarded – undo
141 141
 	 * @return array
142 142
 	 */
143 143
 	public function get_supported_currency() {
144
-		return apply_filters( 'wc_stripe_p24_supported_currencies', array(
144
+		return apply_filters('wc_stripe_p24_supported_currencies', array(
145 145
 			'EUR',
146 146
 			'PLN',
147
-		) );
147
+		));
148 148
 	}
149 149
 
150 150
 	/**
@@ -155,7 +155,7 @@  discard block
 block discarded – undo
155 155
 	 * @return bool
156 156
 	 */
157 157
 	public function is_available() {
158
-		if ( ! in_array( get_woocommerce_currency(), $this->get_supported_currency() ) ) {
158
+		if ( ! in_array(get_woocommerce_currency(), $this->get_supported_currency())) {
159 159
 			return false;
160 160
 		}
161 161
 
@@ -176,7 +176,7 @@  discard block
 block discarded – undo
176 176
 
177 177
 		$icons_str .= $icons['p24'];
178 178
 
179
-		return apply_filters( 'woocommerce_gateway_icon', $icons_str, $this->id );
179
+		return apply_filters('woocommerce_gateway_icon', $icons_str, $this->id);
180 180
 	}
181 181
 
182 182
 	/**
@@ -187,19 +187,19 @@  discard block
 block discarded – undo
187 187
 	 * @access public
188 188
 	 */
189 189
 	public function payment_scripts() {
190
-		if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) && ! is_add_payment_method_page() ) {
190
+		if ( ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order']) && ! is_add_payment_method_page()) {
191 191
 			return;
192 192
 		}
193 193
 
194
-		wp_enqueue_style( 'stripe_paymentfonts' );
195
-		wp_enqueue_script( 'woocommerce_stripe' );
194
+		wp_enqueue_style('stripe_paymentfonts');
195
+		wp_enqueue_script('woocommerce_stripe');
196 196
 	}
197 197
 
198 198
 	/**
199 199
 	 * Initialize Gateway Settings Form Fields.
200 200
 	 */
201 201
 	public function init_form_fields() {
202
-		$this->form_fields = require( WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-p24-settings.php' );
202
+		$this->form_fields = require(WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-p24-settings.php');
203 203
 	}
204 204
 
205 205
 	/**
@@ -210,25 +210,25 @@  discard block
 block discarded – undo
210 210
 		$total                = WC()->cart->total;
211 211
 
212 212
 		// If paying from order, we need to get total from order not cart.
213
-		if ( isset( $_GET['pay_for_order'] ) && ! empty( $_GET['key'] ) ) {
214
-			$order = wc_get_order( wc_get_order_id_by_order_key( wc_clean( $_GET['key'] ) ) );
213
+		if (isset($_GET['pay_for_order']) && ! empty($_GET['key'])) {
214
+			$order = wc_get_order(wc_get_order_id_by_order_key(wc_clean($_GET['key'])));
215 215
 			$total = $order->get_total();
216 216
 		}
217 217
 
218
-		if ( is_add_payment_method_page() ) {
219
-			$pay_button_text = __( 'Add Payment', 'woocommerce-gateway-stripe' );
220
-			$total        = '';
218
+		if (is_add_payment_method_page()) {
219
+			$pay_button_text = __('Add Payment', 'woocommerce-gateway-stripe');
220
+			$total = '';
221 221
 		} else {
222 222
 			$pay_button_text = '';
223 223
 		}
224 224
 
225 225
 		echo '<div
226 226
 			id="stripe-p24-payment-data"
227
-			data-amount="' . esc_attr( WC_Stripe_Helper::get_stripe_amount( $total ) ) . '"
228
-			data-currency="' . esc_attr( strtolower( get_woocommerce_currency() ) ) . '">';
227
+			data-amount="' . esc_attr(WC_Stripe_Helper::get_stripe_amount($total)) . '"
228
+			data-currency="' . esc_attr(strtolower(get_woocommerce_currency())) . '">';
229 229
 
230
-		if ( $this->description ) {
231
-			echo apply_filters( 'wc_stripe_description', wpautop( wp_kses_post( $this->description ) ) );
230
+		if ($this->description) {
231
+			echo apply_filters('wc_stripe_description', wpautop(wp_kses_post($this->description)));
232 232
 		}
233 233
 
234 234
 		echo '</div>';
@@ -242,20 +242,20 @@  discard block
 block discarded – undo
242 242
 	 * @param object $order
243 243
 	 * @return mixed
244 244
 	 */
245
-	public function create_source( $order ) {
245
+	public function create_source($order) {
246 246
 		$currency              = WC_Stripe_Helper::is_pre_30() ? $order->get_order_currency() : $order->get_currency();
247 247
 		$order_id              = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
248
-		$return_url            = $this->get_stripe_return_url( $order );
248
+		$return_url            = $this->get_stripe_return_url($order);
249 249
 		$post_data             = array();
250
-		$post_data['amount']   = WC_Stripe_Helper::get_stripe_amount( $order->get_total(), $currency );
251
-		$post_data['currency'] = strtolower( $currency );
250
+		$post_data['amount']   = WC_Stripe_Helper::get_stripe_amount($order->get_total(), $currency);
251
+		$post_data['currency'] = strtolower($currency);
252 252
 		$post_data['type']     = 'p24';
253
-		$post_data['owner']    = $this->get_owner_details( $order );
254
-		$post_data['redirect'] = array( 'return_url' => $return_url );
253
+		$post_data['owner']    = $this->get_owner_details($order);
254
+		$post_data['redirect'] = array('return_url' => $return_url);
255 255
 
256
-		WC_Stripe_Logger::log( 'Info: Begin creating P24 source' );
256
+		WC_Stripe_Logger::log('Info: Begin creating P24 source');
257 257
 
258
-		return WC_Stripe_API::request( $post_data, 'sources' );
258
+		return WC_Stripe_API::request($post_data, 'sources');
259 259
 	}
260 260
 
261 261
 	/**
@@ -269,51 +269,51 @@  discard block
 block discarded – undo
269 269
 	 *
270 270
 	 * @return array|void
271 271
 	 */
272
-	public function process_payment( $order_id, $retry = true, $force_save_source = false ) {
272
+	public function process_payment($order_id, $retry = true, $force_save_source = false) {
273 273
 		try {
274
-			$order = wc_get_order( $order_id );
274
+			$order = wc_get_order($order_id);
275 275
 
276 276
 			// This will throw exception if not valid.
277
-			$this->validate_minimum_order_amount( $order );
277
+			$this->validate_minimum_order_amount($order);
278 278
 
279 279
 			// This comes from the create account checkbox in the checkout page.
280
-			$create_account = ! empty( $_POST['createaccount'] ) ? true : false;
280
+			$create_account = ! empty($_POST['createaccount']) ? true : false;
281 281
 
282
-			if ( $create_account ) {
282
+			if ($create_account) {
283 283
 				$new_customer_id     = WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id();
284
-				$new_stripe_customer = new WC_Stripe_Customer( $new_customer_id );
284
+				$new_stripe_customer = new WC_Stripe_Customer($new_customer_id);
285 285
 				$new_stripe_customer->create_customer();
286 286
 			}
287 287
 
288
-			$response = $this->create_source( $order );
288
+			$response = $this->create_source($order);
289 289
 
290
-			if ( ! empty( $response->error ) ) {
291
-				$order->add_order_note( $response->error->message );
290
+			if ( ! empty($response->error)) {
291
+				$order->add_order_note($response->error->message);
292 292
 
293
-				throw new Exception( $response->error->message );
293
+				throw new Exception($response->error->message);
294 294
 			}
295 295
 
296
-			if ( WC_Stripe_Helper::is_pre_30() ) {
297
-				update_post_meta( $order_id, '_stripe_source_id', $response->id );
296
+			if (WC_Stripe_Helper::is_pre_30()) {
297
+				update_post_meta($order_id, '_stripe_source_id', $response->id);
298 298
 			} else {
299
-				$order->update_meta_data( '_stripe_source_id', $response->id );
299
+				$order->update_meta_data('_stripe_source_id', $response->id);
300 300
 				$order->save();
301 301
 			}
302 302
 
303
-			WC_Stripe_Logger::log( 'Info: Redirecting to P24...' );
303
+			WC_Stripe_Logger::log('Info: Redirecting to P24...');
304 304
 
305 305
 			return array(
306 306
 				'result'   => 'success',
307
-				'redirect' => esc_url_raw( $response->redirect->url ),
307
+				'redirect' => esc_url_raw($response->redirect->url),
308 308
 			);
309
-		} catch ( Exception $e ) {
310
-			wc_add_notice( $e->getMessage(), 'error' );
311
-			WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() );
309
+		} catch (Exception $e) {
310
+			wc_add_notice($e->getMessage(), 'error');
311
+			WC_Stripe_Logger::log('Error: ' . $e->getMessage());
312 312
 
313
-			do_action( 'wc_gateway_stripe_process_payment_error', $e, $order );
313
+			do_action('wc_gateway_stripe_process_payment_error', $e, $order);
314 314
 
315
-			if ( $order->has_status( array( 'pending', 'failed' ) ) ) {
316
-				$this->send_failed_order_email( $order_id );
315
+			if ($order->has_status(array('pending', 'failed'))) {
316
+				$this->send_failed_order_email($order_id);
317 317
 			}
318 318
 
319 319
 			return array(
Please login to merge, or discard this patch.
includes/payment-methods/class-wc-gateway-stripe-bancontact.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_bancontact';
60
-		$this->method_title         = __( 'Stripe Bancontact', 'woocommerce-gateway-stripe' );
60
+		$this->method_title         = __('Stripe Bancontact', '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 = __( 'Bancontact 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 = __('Bancontact 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_bancontact_supported_currencies', array(
144
+		return apply_filters('wc_stripe_bancontact_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['bancontact'];
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-bancontact-settings.php' );
201
+		$this->form_fields = require(WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-bancontact-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-bancontact-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']                 = 'bancontact';
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 Bancontact source' );
259
+		WC_Stripe_Logger::log('Info: Begin creating Bancontact source');
260 260
 
261
-		return WC_Stripe_API::request( $post_data, 'sources' );
261
+		return WC_Stripe_API::request($post_data, '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 Exception( $response->error->message );
296
+				throw new Exception($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 Bancontact...' );
306
+			WC_Stripe_Logger::log('Info: Redirecting to Bancontact...');
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 ( Exception $e ) {
313
-			wc_add_notice( $e->getMessage(), 'error' );
314
-			WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() );
312
+		} catch (Exception $e) {
313
+			wc_add_notice($e->getMessage(), '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-alipay.php 1 patch
Spacing   +77 added lines, -77 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_alipay';
60
-		$this->method_title         = __( 'Stripe Alipay', 'woocommerce-gateway-stripe' );
60
+		$this->method_title         = __('Stripe Alipay', '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
 	}
@@ -125,10 +125,10 @@  discard block
 block discarded – undo
125 125
 	 */
126 126
 	public function get_environment_warning() {
127 127
 		if (
128
-			'yes' === $this->enabled && ! in_array( get_woocommerce_currency(), $this->get_supported_currency() )
128
+			'yes' === $this->enabled && ! in_array(get_woocommerce_currency(), $this->get_supported_currency())
129 129
 		) {
130 130
 			/* translators: supported currency list */
131
-			$message = sprintf( __( 'Alipay is enabled - it requires store currency to be set to %s', 'woocommerce-gateway-stripe' ), implode( ', ', $this->get_supported_currency() ) );
131
+			$message = sprintf(__('Alipay is enabled - it requires store currency to be set to %s', 'woocommerce-gateway-stripe'), implode(', ', $this->get_supported_currency()));
132 132
 
133 133
 			return $message;
134 134
 		}
@@ -144,7 +144,7 @@  discard block
 block discarded – undo
144 144
 	 * @return array
145 145
 	 */
146 146
 	public function get_supported_currency() {
147
-		return apply_filters( 'wc_stripe_alipay_supported_currencies', array(
147
+		return apply_filters('wc_stripe_alipay_supported_currencies', array(
148 148
 			'EUR',
149 149
 			'AUD',
150 150
 			'CAD',
@@ -154,7 +154,7 @@  discard block
 block discarded – undo
154 154
 			'NZD',
155 155
 			'SGD',
156 156
 			'USD',
157
-		) );
157
+		));
158 158
 	}
159 159
 
160 160
 	/**
@@ -165,7 +165,7 @@  discard block
 block discarded – undo
165 165
 	 * @return bool
166 166
 	 */
167 167
 	public function is_available() {
168
-		if ( ! in_array( get_woocommerce_currency(), $this->get_supported_currency() ) ) {
168
+		if ( ! in_array(get_woocommerce_currency(), $this->get_supported_currency())) {
169 169
 			return false;
170 170
 		}
171 171
 
@@ -186,7 +186,7 @@  discard block
 block discarded – undo
186 186
 
187 187
 		$icons_str .= $icons['alipay'];
188 188
 
189
-		return apply_filters( 'woocommerce_gateway_icon', $icons_str, $this->id );
189
+		return apply_filters('woocommerce_gateway_icon', $icons_str, $this->id);
190 190
 	}
191 191
 
192 192
 	/**
@@ -196,19 +196,19 @@  discard block
 block discarded – undo
196 196
 	 * @version 4.0.0
197 197
 	 */
198 198
 	public function payment_scripts() {
199
-		if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) && ! is_add_payment_method_page() ) {
199
+		if ( ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order']) && ! is_add_payment_method_page()) {
200 200
 			return;
201 201
 		}
202 202
 
203
-		wp_enqueue_style( 'stripe_paymentfonts' );
204
-		wp_enqueue_script( 'woocommerce_stripe' );
203
+		wp_enqueue_style('stripe_paymentfonts');
204
+		wp_enqueue_script('woocommerce_stripe');
205 205
 	}
206 206
 
207 207
 	/**
208 208
 	 * Initialize Gateway Settings Form Fields.
209 209
 	 */
210 210
 	public function init_form_fields() {
211
-		$this->form_fields = require( WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-alipay-settings.php' );
211
+		$this->form_fields = require(WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-alipay-settings.php');
212 212
 	}
213 213
 
214 214
 	/**
@@ -219,25 +219,25 @@  discard block
 block discarded – undo
219 219
 		$total                = WC()->cart->total;
220 220
 
221 221
 		// If paying from order, we need to get total from order not cart.
222
-		if ( isset( $_GET['pay_for_order'] ) && ! empty( $_GET['key'] ) ) {
223
-			$order = wc_get_order( wc_get_order_id_by_order_key( wc_clean( $_GET['key'] ) ) );
222
+		if (isset($_GET['pay_for_order']) && ! empty($_GET['key'])) {
223
+			$order = wc_get_order(wc_get_order_id_by_order_key(wc_clean($_GET['key'])));
224 224
 			$total = $order->get_total();
225 225
 		}
226 226
 
227
-		if ( is_add_payment_method_page() ) {
228
-			$pay_button_text = __( 'Add Payment', 'woocommerce-gateway-stripe' );
229
-			$total        = '';
227
+		if (is_add_payment_method_page()) {
228
+			$pay_button_text = __('Add Payment', 'woocommerce-gateway-stripe');
229
+			$total = '';
230 230
 		} else {
231 231
 			$pay_button_text = '';
232 232
 		}
233 233
 
234 234
 		echo '<div
235 235
 			id="stripe-alipay-payment-data"
236
-			data-amount="' . esc_attr( WC_Stripe_Helper::get_stripe_amount( $total ) ) . '"
237
-			data-currency="' . esc_attr( strtolower( get_woocommerce_currency() ) ) . '">';
236
+			data-amount="' . esc_attr(WC_Stripe_Helper::get_stripe_amount($total)) . '"
237
+			data-currency="' . esc_attr(strtolower(get_woocommerce_currency())) . '">';
238 238
 
239
-		if ( $this->description ) {
240
-			echo apply_filters( 'wc_stripe_description', wpautop( wp_kses_post( $this->description ) ) );
239
+		if ($this->description) {
240
+			echo apply_filters('wc_stripe_description', wpautop(wp_kses_post($this->description)));
241 241
 		}
242 242
 
243 243
 		echo '</div>';
@@ -251,24 +251,24 @@  discard block
 block discarded – undo
251 251
 	 * @param object $order
252 252
 	 * @return mixed
253 253
 	 */
254
-	public function create_source( $order ) {
254
+	public function create_source($order) {
255 255
 		$currency                          = WC_Stripe_Helper::is_pre_30() ? $order->get_order_currency() : $order->get_currency();
256 256
 		$order_id                          = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
257
-		$return_url                        = $this->get_stripe_return_url( $order );
257
+		$return_url                        = $this->get_stripe_return_url($order);
258 258
 		$post_data                         = array();
259
-		$post_data['amount']               = WC_Stripe_Helper::get_stripe_amount( $order->get_total(), $currency );
260
-		$post_data['currency']             = strtolower( $currency );
259
+		$post_data['amount']               = WC_Stripe_Helper::get_stripe_amount($order->get_total(), $currency);
260
+		$post_data['currency']             = strtolower($currency);
261 261
 		$post_data['type']                 = 'alipay';
262
-		$post_data['owner']                = $this->get_owner_details( $order );
263
-		$post_data['redirect']             = array( 'return_url' => $return_url );
262
+		$post_data['owner']                = $this->get_owner_details($order);
263
+		$post_data['redirect']             = array('return_url' => $return_url);
264 264
 
265
-		if ( ! empty( $this->statement_descriptor ) ) {
266
-			$post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor( $this->statement_descriptor );
265
+		if ( ! empty($this->statement_descriptor)) {
266
+			$post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor($this->statement_descriptor);
267 267
 		}
268 268
 
269
-		WC_Stripe_Logger::log( 'Info: Begin creating Alipay source' );
269
+		WC_Stripe_Logger::log('Info: Begin creating Alipay source');
270 270
 
271
-		return WC_Stripe_API::request( $post_data, 'sources' );
271
+		return WC_Stripe_API::request($post_data, 'sources');
272 272
 	}
273 273
 
274 274
 	/**
@@ -282,53 +282,53 @@  discard block
 block discarded – undo
282 282
 	 *
283 283
 	 * @return array|void
284 284
 	 */
285
-	public function process_payment( $order_id, $retry = true, $force_save_save = false ) {
285
+	public function process_payment($order_id, $retry = true, $force_save_save = false) {
286 286
 		try {
287
-			$order = wc_get_order( $order_id );
287
+			$order = wc_get_order($order_id);
288 288
 
289 289
 			// This will throw exception if not valid.
290
-			$this->validate_minimum_order_amount( $order );
290
+			$this->validate_minimum_order_amount($order);
291 291
 
292 292
 			// This comes from the create account checkbox in the checkout page.
293
-			$create_account = ! empty( $_POST['createaccount'] ) ? true : false;
293
+			$create_account = ! empty($_POST['createaccount']) ? true : false;
294 294
 
295
-			if ( $create_account ) {
295
+			if ($create_account) {
296 296
 				$new_customer_id     = WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id();
297
-				$new_stripe_customer = new WC_Stripe_Customer( $new_customer_id );
297
+				$new_stripe_customer = new WC_Stripe_Customer($new_customer_id);
298 298
 				$new_stripe_customer->create_customer();
299 299
 			}
300 300
 
301
-			$response = $this->create_source( $order );
301
+			$response = $this->create_source($order);
302 302
 
303
-			if ( ! empty( $response->error ) ) {
304
-				$order->add_order_note( $response->error->message );
303
+			if ( ! empty($response->error)) {
304
+				$order->add_order_note($response->error->message);
305 305
 
306
-				throw new Exception( $response->error->message );
306
+				throw new Exception($response->error->message);
307 307
 			}
308 308
 
309
-			if ( WC_Stripe_Helper::is_pre_30() ) {
310
-				update_post_meta( $order_id, '_stripe_source_id', $response->id );
309
+			if (WC_Stripe_Helper::is_pre_30()) {
310
+				update_post_meta($order_id, '_stripe_source_id', $response->id);
311 311
 			} else {
312
-				$order->update_meta_data( '_stripe_source_id', $response->id );
312
+				$order->update_meta_data('_stripe_source_id', $response->id);
313 313
 				$order->save();
314 314
 			}
315 315
 
316
-			WC_Stripe_Logger::log( 'Info: Redirecting to Alipay...' );
316
+			WC_Stripe_Logger::log('Info: Redirecting to Alipay...');
317 317
 
318 318
 			return array(
319 319
 				'result'   => 'success',
320
-				'redirect' => esc_url_raw( $response->redirect->url ),
320
+				'redirect' => esc_url_raw($response->redirect->url),
321 321
 			);
322
-		} catch ( Exception $e ) {
323
-			wc_add_notice( $e->getMessage(), 'error' );
324
-			WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() );
322
+		} catch (Exception $e) {
323
+			wc_add_notice($e->getMessage(), 'error');
324
+			WC_Stripe_Logger::log('Error: ' . $e->getMessage());
325 325
 
326
-			do_action( 'wc_gateway_stripe_process_payment_error', $e, $order );
326
+			do_action('wc_gateway_stripe_process_payment_error', $e, $order);
327 327
 
328
-			$statuses = array( 'pending', 'failed' );
328
+			$statuses = array('pending', 'failed');
329 329
 
330
-			if ( $order->has_status( $statuses ) ) {
331
-				$this->send_failed_order_email( $order_id );
330
+			if ($order->has_status($statuses)) {
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/class-wc-gateway-stripe.php 1 patch
Spacing   +201 added lines, -201 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) {
2
+if ( ! defined('ABSPATH')) {
3 3
 	exit;
4 4
 }
5 5
 
@@ -119,9 +119,9 @@  discard block
 block discarded – undo
119 119
 	 */
120 120
 	public function __construct() {
121 121
 		$this->id                   = 'stripe';
122
-		$this->method_title         = __( 'Stripe', 'woocommerce-gateway-stripe' );
122
+		$this->method_title         = __('Stripe', 'woocommerce-gateway-stripe');
123 123
 		/* translators: 1) link to Stripe register page 2) link to Stripe api keys page */
124
-		$this->method_description   = sprintf( __( 'Stripe works by adding payment fields on the checkout and then sending the details to Stripe for verification. <a href="%1$s" target="_blank">Sign up</a> for a Stripe account, and <a href="%2$s" target="_blank">get your Stripe account keys</a>.', 'woocommerce-gateway-stripe' ), 'https://dashboard.stripe.com/register', 'https://dashboard.stripe.com/account/apikeys' );
124
+		$this->method_description   = sprintf(__('Stripe works by adding payment fields on the checkout and then sending the details to Stripe for verification. <a href="%1$s" target="_blank">Sign up</a> for a Stripe account, and <a href="%2$s" target="_blank">get your Stripe account keys</a>.', 'woocommerce-gateway-stripe'), 'https://dashboard.stripe.com/register', 'https://dashboard.stripe.com/account/apikeys');
125 125
 		$this->has_fields           = true;
126 126
 		$this->supports             = array(
127 127
 			'products',
@@ -148,38 +148,38 @@  discard block
 block discarded – undo
148 148
 		$this->init_settings();
149 149
 
150 150
 		// Get setting values.
151
-		$this->title                   = $this->get_option( 'title' );
152
-		$this->description             = $this->get_option( 'description' );
153
-		$this->enabled                 = $this->get_option( 'enabled' );
154
-		$this->testmode                = 'yes' === $this->get_option( 'testmode' );
155
-		$this->inline_cc_form          = 'yes' === $this->get_option( 'inline_cc_form' );
156
-		$this->capture                 = 'yes' === $this->get_option( 'capture', 'yes' );
157
-		$this->statement_descriptor    = WC_Stripe_Helper::clean_statement_descriptor( $this->get_option( 'statement_descriptor' ) );
158
-		$this->three_d_secure          = 'yes' === $this->get_option( 'three_d_secure' );
159
-		$this->stripe_checkout         = 'yes' === $this->get_option( 'stripe_checkout' );
160
-		$this->stripe_checkout_locale  = $this->get_option( 'stripe_checkout_locale' );
161
-		$this->stripe_checkout_image   = $this->get_option( 'stripe_checkout_image', '' );
162
-		$this->saved_cards             = 'yes' === $this->get_option( 'saved_cards' );
163
-		$this->secret_key              = $this->testmode ? $this->get_option( 'test_secret_key' ) : $this->get_option( 'secret_key' );
164
-		$this->publishable_key         = $this->testmode ? $this->get_option( 'test_publishable_key' ) : $this->get_option( 'publishable_key' );
165
-		$this->bitcoin                 = 'USD' === strtoupper( get_woocommerce_currency() ) && 'yes' === $this->get_option( 'stripe_bitcoin' );
166
-		$this->payment_request         = 'yes' === $this->get_option( 'payment_request', 'yes' );
167
-		$this->apple_pay_domain_set    = 'yes' === $this->get_option( 'apple_pay_domain_set', 'no' );
151
+		$this->title                   = $this->get_option('title');
152
+		$this->description             = $this->get_option('description');
153
+		$this->enabled                 = $this->get_option('enabled');
154
+		$this->testmode                = 'yes' === $this->get_option('testmode');
155
+		$this->inline_cc_form          = 'yes' === $this->get_option('inline_cc_form');
156
+		$this->capture                 = 'yes' === $this->get_option('capture', 'yes');
157
+		$this->statement_descriptor    = WC_Stripe_Helper::clean_statement_descriptor($this->get_option('statement_descriptor'));
158
+		$this->three_d_secure          = 'yes' === $this->get_option('three_d_secure');
159
+		$this->stripe_checkout         = 'yes' === $this->get_option('stripe_checkout');
160
+		$this->stripe_checkout_locale  = $this->get_option('stripe_checkout_locale');
161
+		$this->stripe_checkout_image   = $this->get_option('stripe_checkout_image', '');
162
+		$this->saved_cards             = 'yes' === $this->get_option('saved_cards');
163
+		$this->secret_key              = $this->testmode ? $this->get_option('test_secret_key') : $this->get_option('secret_key');
164
+		$this->publishable_key         = $this->testmode ? $this->get_option('test_publishable_key') : $this->get_option('publishable_key');
165
+		$this->bitcoin                 = 'USD' === strtoupper(get_woocommerce_currency()) && 'yes' === $this->get_option('stripe_bitcoin');
166
+		$this->payment_request         = 'yes' === $this->get_option('payment_request', 'yes');
167
+		$this->apple_pay_domain_set    = 'yes' === $this->get_option('apple_pay_domain_set', 'no');
168 168
 		$this->apple_pay_verify_notice = '';
169 169
 
170
-		if ( $this->stripe_checkout ) {
171
-			$this->order_button_text = __( 'Continue to payment', 'woocommerce-gateway-stripe' );
170
+		if ($this->stripe_checkout) {
171
+			$this->order_button_text = __('Continue to payment', 'woocommerce-gateway-stripe');
172 172
 		}
173 173
 
174
-		WC_Stripe_API::set_secret_key( $this->secret_key );
174
+		WC_Stripe_API::set_secret_key($this->secret_key);
175 175
 
176 176
 		$this->init_apple_pay();
177 177
 
178 178
 		// Hooks.
179
-		add_action( 'wp_enqueue_scripts', array( $this, 'payment_scripts' ) );
180
-		add_action( 'admin_enqueue_scripts', array( $this, 'admin_scripts' ) );
181
-		add_action( 'admin_notices', array( $this, 'admin_notices' ) );
182
-		add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) );
179
+		add_action('wp_enqueue_scripts', array($this, 'payment_scripts'));
180
+		add_action('admin_enqueue_scripts', array($this, 'admin_scripts'));
181
+		add_action('admin_notices', array($this, 'admin_notices'));
182
+		add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options'));
183 183
 	}
184 184
 
185 185
 	/**
@@ -198,17 +198,17 @@  discard block
 block discarded – undo
198 198
 		$icons_str .= $icons['amex'];
199 199
 		$icons_str .= $icons['mastercard'];
200 200
 
201
-		if ( 'USD' === get_woocommerce_currency() ) {
201
+		if ('USD' === get_woocommerce_currency()) {
202 202
 			$icons_str .= $icons['discover'];
203 203
 			$icons_str .= $icons['jcb'];
204 204
 			$icons_str .= $icons['diners'];
205 205
 		}
206 206
 
207
-		if ( $this->bitcoin && $this->stripe_checkout ) {
207
+		if ($this->bitcoin && $this->stripe_checkout) {
208 208
 			$icons_str .= $icons['bitcoin'];
209 209
 		}
210 210
 
211
-		return apply_filters( 'woocommerce_gateway_icon', $icons_str, $this->id );
211
+		return apply_filters('woocommerce_gateway_icon', $icons_str, $this->id);
212 212
 	}
213 213
 
214 214
 	/**
@@ -220,9 +220,9 @@  discard block
 block discarded – undo
220 220
 	public function init_apple_pay() {
221 221
 		if (
222 222
 			is_admin() &&
223
-			isset( $_GET['page'] ) && 'wc-settings' === $_GET['page'] &&
224
-			isset( $_GET['tab'] ) && 'checkout' === $_GET['tab'] &&
225
-			isset( $_GET['section'] ) && 'stripe' === $_GET['section'] &&
223
+			isset($_GET['page']) && 'wc-settings' === $_GET['page'] &&
224
+			isset($_GET['tab']) && 'checkout' === $_GET['tab'] &&
225
+			isset($_GET['section']) && 'stripe' === $_GET['section'] &&
226 226
 			$this->payment_request
227 227
 		) {
228 228
 			$this->process_apple_pay_verification();
@@ -236,9 +236,9 @@  discard block
 block discarded – undo
236 236
 	 * @version 3.1.0
237 237
 	 * @param string $secret_key
238 238
 	 */
239
-	private function register_apple_pay_domain( $secret_key = '' ) {
240
-		if ( empty( $secret_key ) ) {
241
-			throw new Exception( __( 'Unable to verify domain - missing secret key.', 'woocommerce-gateway-stripe' ) );
239
+	private function register_apple_pay_domain($secret_key = '') {
240
+		if (empty($secret_key)) {
241
+			throw new Exception(__('Unable to verify domain - missing secret key.', 'woocommerce-gateway-stripe'));
242 242
 		}
243 243
 
244 244
 		$endpoint = 'https://api.stripe.com/v1/apple_pay/domains';
@@ -252,23 +252,23 @@  discard block
 block discarded – undo
252 252
 			'Authorization' => 'Bearer ' . $secret_key,
253 253
 		);
254 254
 
255
-		$response = wp_remote_post( $endpoint, array(
255
+		$response = wp_remote_post($endpoint, array(
256 256
 			'headers' => $headers,
257
-			'body'    => http_build_query( $data ),
258
-		) );
257
+			'body'    => http_build_query($data),
258
+		));
259 259
 
260
-		if ( is_wp_error( $response ) ) {
260
+		if (is_wp_error($response)) {
261 261
 			/* translators: error message */
262
-			throw new Exception( sprintf( __( 'Unable to verify domain - %s', 'woocommerce-gateway-stripe' ), $response->get_error_message() ) );
262
+			throw new Exception(sprintf(__('Unable to verify domain - %s', 'woocommerce-gateway-stripe'), $response->get_error_message()));
263 263
 		}
264 264
 
265
-		if ( 200 !== $response['response']['code'] ) {
266
-			$parsed_response = json_decode( $response['body'] );
265
+		if (200 !== $response['response']['code']) {
266
+			$parsed_response = json_decode($response['body']);
267 267
 
268 268
 			$this->apple_pay_verify_notice = $parsed_response->error->message;
269 269
 
270 270
 			/* translators: error message */
271
-			throw new Exception( sprintf( __( 'Unable to verify domain - %s', 'woocommerce-gateway-stripe' ), $parsed_response->error->message ) );
271
+			throw new Exception(sprintf(__('Unable to verify domain - %s', 'woocommerce-gateway-stripe'), $parsed_response->error->message));
272 272
 		}
273 273
 	}
274 274
 
@@ -279,48 +279,48 @@  discard block
 block discarded – undo
279 279
 	 * @version 3.1.0
280 280
 	 */
281 281
 	public function process_apple_pay_verification() {
282
-		$gateway_settings = get_option( 'woocommerce_stripe_settings', array() );
282
+		$gateway_settings = get_option('woocommerce_stripe_settings', array());
283 283
 
284 284
 		try {
285
-			$path     = untrailingslashit( $_SERVER['DOCUMENT_ROOT'] );
285
+			$path     = untrailingslashit($_SERVER['DOCUMENT_ROOT']);
286 286
 			$dir      = '.well-known';
287 287
 			$file     = 'apple-developer-merchantid-domain-association';
288 288
 			$fullpath = $path . '/' . $dir . '/' . $file;
289 289
 
290
-			if ( ! empty( $gateway_settings['apple_pay_domain_set'] ) && 'yes' === $gateway_settings['apple_pay_domain_set'] && file_exists( $fullpath ) ) {
290
+			if ( ! empty($gateway_settings['apple_pay_domain_set']) && 'yes' === $gateway_settings['apple_pay_domain_set'] && file_exists($fullpath)) {
291 291
 				return;
292 292
 			}
293 293
 
294
-			if ( ! file_exists( $path . '/' . $dir ) ) {
295
-				if ( ! @mkdir( $path . '/' . $dir, 0755 ) ) {
296
-					throw new Exception( __( 'Unable to create domain association folder to domain root.', 'woocommerce-gateway-stripe' ) );
294
+			if ( ! file_exists($path . '/' . $dir)) {
295
+				if ( ! @mkdir($path . '/' . $dir, 0755)) {
296
+					throw new Exception(__('Unable to create domain association folder to domain root.', 'woocommerce-gateway-stripe'));
297 297
 				}
298 298
 			}
299 299
 
300
-			if ( ! file_exists( $fullpath ) ) {
301
-				if ( ! @copy( WC_STRIPE_PLUGIN_PATH . '/' . $file, $fullpath ) ) {
302
-					throw new Exception( __( 'Unable to copy domain association file to domain root.', 'woocommerce-gateway-stripe' ) );
300
+			if ( ! file_exists($fullpath)) {
301
+				if ( ! @copy(WC_STRIPE_PLUGIN_PATH . '/' . $file, $fullpath)) {
302
+					throw new Exception(__('Unable to copy domain association file to domain root.', 'woocommerce-gateway-stripe'));
303 303
 				}
304 304
 			}
305 305
 
306 306
 			// At this point then the domain association folder and file should be available.
307 307
 			// Proceed to verify/and or verify again.
308
-			$this->register_apple_pay_domain( $this->secret_key );
308
+			$this->register_apple_pay_domain($this->secret_key);
309 309
 
310 310
 			// No errors to this point, verification success!
311 311
 			$gateway_settings['apple_pay_domain_set'] = 'yes';
312 312
 			$this->apple_pay_domain_set = true;
313 313
 
314
-			update_option( 'woocommerce_stripe_settings', $gateway_settings );
314
+			update_option('woocommerce_stripe_settings', $gateway_settings);
315 315
 
316
-			WC_Stripe_Logger::log( 'Your domain has been verified with Apple Pay!' );
316
+			WC_Stripe_Logger::log('Your domain has been verified with Apple Pay!');
317 317
 
318
-		} catch ( Exception $e ) {
318
+		} catch (Exception $e) {
319 319
 			$gateway_settings['apple_pay_domain_set'] = 'no';
320 320
 
321
-			update_option( 'woocommerce_stripe_settings', $gateway_settings );
321
+			update_option('woocommerce_stripe_settings', $gateway_settings);
322 322
 
323
-			WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() );
323
+			WC_Stripe_Logger::log('Error: ' . $e->getMessage());
324 324
 		}
325 325
 	}
326 326
 
@@ -328,11 +328,11 @@  discard block
 block discarded – undo
328 328
 	 * Check if SSL is enabled and notify the user
329 329
 	 */
330 330
 	public function admin_notices() {
331
-		if ( 'no' === $this->enabled ) {
331
+		if ('no' === $this->enabled) {
332 332
 			return;
333 333
 		}
334 334
 
335
-		if ( $this->payment_request && ! empty( $this->apple_pay_verify_notice ) ) {
335
+		if ($this->payment_request && ! empty($this->apple_pay_verify_notice)) {
336 336
 			$allowed_html = array(
337 337
 				'a' => array(
338 338
 					'href' => array(),
@@ -340,7 +340,7 @@  discard block
 block discarded – undo
340 340
 				),
341 341
 			);
342 342
 
343
-			echo '<div class="error stripe-apple-pay-message"><p>' . wp_kses( make_clickable( $this->apple_pay_verify_notice ), $allowed_html ) . '</p></div>';
343
+			echo '<div class="error stripe-apple-pay-message"><p>' . wp_kses(make_clickable($this->apple_pay_verify_notice), $allowed_html) . '</p></div>';
344 344
 		}
345 345
 
346 346
 		/**
@@ -348,9 +348,9 @@  discard block
 block discarded – undo
348 348
 		 * when setting screen is displayed. So if domain verification is not set,
349 349
 		 * something went wrong so lets notify user.
350 350
 		 */
351
-		if ( ! empty( $this->secret_key ) && $this->payment_request && ! $this->apple_pay_domain_set ) {
351
+		if ( ! empty($this->secret_key) && $this->payment_request && ! $this->apple_pay_domain_set) {
352 352
 			/* translators: 1) HTML anchor open tag 2) HTML anchor closing tag */
353
-			echo '<div class="error stripe-apple-pay-message"><p>' . sprintf( __( 'Apple Pay domain verification failed. Please check the %1$slog%2$s to see the issue. (Logging must be enabled to see recorded logs)', 'woocommerce-gateway-stripe' ), '<a href="' . admin_url( 'admin.php?page=wc-status&tab=logs' ) . '">', '</a>' ) . '</p></div>';
353
+			echo '<div class="error stripe-apple-pay-message"><p>' . sprintf(__('Apple Pay domain verification failed. Please check the %1$slog%2$s to see the issue. (Logging must be enabled to see recorded logs)', 'woocommerce-gateway-stripe'), '<a href="' . admin_url('admin.php?page=wc-status&tab=logs') . '">', '</a>') . '</p></div>';
354 354
 		}
355 355
 	}
356 356
 
@@ -358,7 +358,7 @@  discard block
 block discarded – undo
358 358
 	 * Initialise Gateway Settings Form Fields
359 359
 	 */
360 360
 	public function init_form_fields() {
361
-		$this->form_fields = require( dirname( __FILE__ ) . '/admin/stripe-settings.php' );
361
+		$this->form_fields = require(dirname(__FILE__) . '/admin/stripe-settings.php');
362 362
 	}
363 363
 
364 364
 	/**
@@ -366,59 +366,59 @@  discard block
 block discarded – undo
366 366
 	 */
367 367
 	public function payment_fields() {
368 368
 		$user                 = wp_get_current_user();
369
-		$display_tokenization = $this->supports( 'tokenization' ) && is_checkout() && $this->saved_cards;
369
+		$display_tokenization = $this->supports('tokenization') && is_checkout() && $this->saved_cards;
370 370
 		$total                = WC()->cart->total;
371 371
 		$user_email           = '';
372 372
 
373 373
 		// If paying from order, we need to get total from order not cart.
374
-		if ( isset( $_GET['pay_for_order'] ) && ! empty( $_GET['key'] ) ) {
375
-			$order      = wc_get_order( wc_get_order_id_by_order_key( wc_clean( $_GET['key'] ) ) );
374
+		if (isset($_GET['pay_for_order']) && ! empty($_GET['key'])) {
375
+			$order      = wc_get_order(wc_get_order_id_by_order_key(wc_clean($_GET['key'])));
376 376
 			$total      = $order->get_total();
377 377
 			$user_email = WC_Stripe_Helper::is_pre_30() ? $order->billing_email : $order->get_billing_email();
378 378
 		} else {
379
-			if ( $user->ID ) {
380
-				$user_email = get_user_meta( $user->ID, 'billing_email', true );
379
+			if ($user->ID) {
380
+				$user_email = get_user_meta($user->ID, 'billing_email', true);
381 381
 				$user_email = $user_email ? $user_email : $user->user_email;
382 382
 			}
383 383
 		}
384 384
 
385
-		if ( is_add_payment_method_page() ) {
386
-			$pay_button_text = __( 'Add Card', 'woocommerce-gateway-stripe' );
387
-			$total        = '';
385
+		if (is_add_payment_method_page()) {
386
+			$pay_button_text = __('Add Card', 'woocommerce-gateway-stripe');
387
+			$total = '';
388 388
 		} else {
389 389
 			$pay_button_text = '';
390 390
 		}
391 391
 
392 392
 		echo '<div
393 393
 			id="stripe-payment-data"
394
-			data-panel-label="' . esc_attr( $pay_button_text ) . '"
394
+			data-panel-label="' . esc_attr($pay_button_text) . '"
395 395
 			data-description=""
396
-			data-email="' . esc_attr( $user_email ) . '"
397
-			data-amount="' . esc_attr( WC_Stripe_Helper::get_stripe_amount( $total ) ) . '"
398
-			data-name="' . esc_attr( $this->statement_descriptor ) . '"
399
-			data-currency="' . esc_attr( strtolower( get_woocommerce_currency() ) ) . '"
400
-			data-image="' . esc_attr( $this->stripe_checkout_image ) . '"
401
-			data-bitcoin="' . esc_attr( $this->bitcoin ? 'true' : 'false' ) . '"
402
-			data-locale="' . esc_attr( $this->stripe_checkout_locale ? $this->stripe_checkout_locale : 'en' ) . '"
403
-			data-three-d-secure="' . esc_attr( $this->three_d_secure ? 'true' : 'false' ) . '"
404
-			data-allow-remember-me="' . esc_attr( $this->saved_cards ? 'true' : 'false' ) . '">';
405
-
406
-		if ( $this->description ) {
407
-			if ( $this->testmode ) {
396
+			data-email="' . esc_attr($user_email) . '"
397
+			data-amount="' . esc_attr(WC_Stripe_Helper::get_stripe_amount($total)) . '"
398
+			data-name="' . esc_attr($this->statement_descriptor) . '"
399
+			data-currency="' . esc_attr(strtolower(get_woocommerce_currency())) . '"
400
+			data-image="' . esc_attr($this->stripe_checkout_image) . '"
401
+			data-bitcoin="' . esc_attr($this->bitcoin ? 'true' : 'false') . '"
402
+			data-locale="' . esc_attr($this->stripe_checkout_locale ? $this->stripe_checkout_locale : 'en') . '"
403
+			data-three-d-secure="' . esc_attr($this->three_d_secure ? 'true' : 'false') . '"
404
+			data-allow-remember-me="' . esc_attr($this->saved_cards ? 'true' : 'false') . '">';
405
+
406
+		if ($this->description) {
407
+			if ($this->testmode) {
408 408
 				/* translators: link to Stripe testing page */
409
-				$this->description .= ' ' . sprintf( __( 'TEST MODE ENABLED. In test mode, you can use the card number 4242424242424242 with any CVC and a valid expiration date or check the documentation "<a href="%s" target="_blank">Testing Stripe</a>" for more card numbers.', 'woocommerce-gateway-stripe' ), 'https://stripe.com/docs/testing' );
410
-				$this->description  = trim( $this->description );
409
+				$this->description .= ' ' . sprintf(__('TEST MODE ENABLED. In test mode, you can use the card number 4242424242424242 with any CVC and a valid expiration date or check the documentation "<a href="%s" target="_blank">Testing Stripe</a>" for more card numbers.', 'woocommerce-gateway-stripe'), 'https://stripe.com/docs/testing');
410
+				$this->description  = trim($this->description);
411 411
 			}
412
-			echo apply_filters( 'wc_stripe_description', wpautop( wp_kses_post( $this->description ) ) );
412
+			echo apply_filters('wc_stripe_description', wpautop(wp_kses_post($this->description)));
413 413
 		}
414 414
 
415
-		if ( $display_tokenization ) {
415
+		if ($display_tokenization) {
416 416
 			$this->tokenization_script();
417 417
 			$this->saved_payment_methods();
418 418
 		}
419 419
 
420
-		if ( ! $this->stripe_checkout ) {
421
-			if ( apply_filters( 'wc_stripe_use_elements_checkout_form', true ) ) {
420
+		if ( ! $this->stripe_checkout) {
421
+			if (apply_filters('wc_stripe_use_elements_checkout_form', true)) {
422 422
 				$this->elements_form();
423 423
 			} else {
424 424
 				$this->form();
@@ -426,7 +426,7 @@  discard block
 block discarded – undo
426 426
 			}
427 427
 		}
428 428
 
429
-		if ( apply_filters( 'wc_stripe_display_save_payment_method_checkbox', $display_tokenization ) && ! is_add_payment_method_page() && ! isset( $_GET['change_payment_method'] ) ) {
429
+		if (apply_filters('wc_stripe_display_save_payment_method_checkbox', $display_tokenization) && ! is_add_payment_method_page() && ! isset($_GET['change_payment_method'])) {
430 430
 			$this->save_payment_method_checkbox();
431 431
 		}
432 432
 
@@ -441,13 +441,13 @@  discard block
 block discarded – undo
441 441
 	 */
442 442
 	public function elements_form() {
443 443
 		?>
444
-		<fieldset id="wc-<?php echo esc_attr( $this->id ); ?>-cc-form" class="wc-credit-card-form wc-payment-form" style="background:transparent;">
445
-			<?php do_action( 'woocommerce_credit_card_form_start', $this->id ); ?>
444
+		<fieldset id="wc-<?php echo esc_attr($this->id); ?>-cc-form" class="wc-credit-card-form wc-payment-form" style="background:transparent;">
445
+			<?php do_action('woocommerce_credit_card_form_start', $this->id); ?>
446 446
 			<label for="card-element">
447
-				<?php esc_html_e( 'Credit or debit card', 'woocommerce-gateway-stripe' ); ?>
447
+				<?php esc_html_e('Credit or debit card', 'woocommerce-gateway-stripe'); ?>
448 448
 			</label>
449 449
 
450
-			<?php if ( $this->inline_cc_form ) { ?>
450
+			<?php if ($this->inline_cc_form) { ?>
451 451
 				<div id="stripe-card-element" style="background:#fff;padding:0 1em;border:1px solid #ddd;margin:5px 0;padding:10px 5px;">
452 452
 				<!-- a Stripe Element will be inserted here. -->
453 453
 				</div>
@@ -466,7 +466,7 @@  discard block
 block discarded – undo
466 466
 
467 467
 			<!-- Used to display form errors -->
468 468
 			<div class="stripe-source-errors" role="alert"></div>
469
-			<?php do_action( 'woocommerce_credit_card_form_end', $this->id ); ?>
469
+			<?php do_action('woocommerce_credit_card_form_end', $this->id); ?>
470 470
 			<div class="clear"></div>
471 471
 		</fieldset>
472 472
 		<?php
@@ -479,13 +479,13 @@  discard block
 block discarded – undo
479 479
 	 * @version 3.1.0
480 480
 	 */
481 481
 	public function admin_scripts() {
482
-		if ( 'woocommerce_page_wc-settings' !== get_current_screen()->id ) {
482
+		if ('woocommerce_page_wc-settings' !== get_current_screen()->id) {
483 483
 			return;
484 484
 		}
485 485
 
486
-		$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
486
+		$suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';
487 487
 
488
-		wp_enqueue_script( 'woocommerce_stripe_admin', plugins_url( 'assets/js/stripe-admin' . $suffix . '.js', WC_STRIPE_MAIN_FILE ), array(), WC_STRIPE_VERSION, true );
488
+		wp_enqueue_script('woocommerce_stripe_admin', plugins_url('assets/js/stripe-admin' . $suffix . '.js', WC_STRIPE_MAIN_FILE), array(), WC_STRIPE_VERSION, true);
489 489
 	}
490 490
 
491 491
 	/**
@@ -497,29 +497,29 @@  discard block
 block discarded – undo
497 497
 	 * @version 4.0.0
498 498
 	 */
499 499
 	public function payment_scripts() {
500
-		if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) && ! is_add_payment_method_page() && ! isset( $_GET['change_payment_method'] ) ) {
500
+		if ( ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order']) && ! is_add_payment_method_page() && ! isset($_GET['change_payment_method'])) {
501 501
 			return;
502 502
 		}
503 503
 
504
-		$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
504
+		$suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';
505 505
 
506
-		wp_register_style( 'stripe_paymentfonts', plugins_url( 'assets/css/stripe-paymentfonts.css', WC_STRIPE_MAIN_FILE ), array(), '1.2.5' );
507
-		wp_enqueue_style( 'stripe_paymentfonts' );
508
-		wp_register_script( 'stripe_checkout', 'https://checkout.stripe.com/checkout.js', '', WC_STRIPE_VERSION, true );
509
-		wp_register_script( 'stripev2', 'https://js.stripe.com/v2/', '', '2.0', true );
510
-		wp_register_script( 'stripe', 'https://js.stripe.com/v3/', '', '3.0', true );
511
-		wp_register_script( 'woocommerce_stripe', plugins_url( 'assets/js/stripe' . $suffix . '.js', WC_STRIPE_MAIN_FILE ), array( 'jquery-payment', 'stripev2', 'stripe' ), WC_STRIPE_VERSION, true );
506
+		wp_register_style('stripe_paymentfonts', plugins_url('assets/css/stripe-paymentfonts.css', WC_STRIPE_MAIN_FILE), array(), '1.2.5');
507
+		wp_enqueue_style('stripe_paymentfonts');
508
+		wp_register_script('stripe_checkout', 'https://checkout.stripe.com/checkout.js', '', WC_STRIPE_VERSION, true);
509
+		wp_register_script('stripev2', 'https://js.stripe.com/v2/', '', '2.0', true);
510
+		wp_register_script('stripe', 'https://js.stripe.com/v3/', '', '3.0', true);
511
+		wp_register_script('woocommerce_stripe', plugins_url('assets/js/stripe' . $suffix . '.js', WC_STRIPE_MAIN_FILE), array('jquery-payment', 'stripev2', 'stripe'), WC_STRIPE_VERSION, true);
512 512
 
513 513
 		$stripe_params = array(
514 514
 			'key'                  => $this->publishable_key,
515
-			'i18n_terms'           => __( 'Please accept the terms and conditions first', 'woocommerce-gateway-stripe' ),
516
-			'i18n_required_fields' => __( 'Please fill in required checkout fields first', 'woocommerce-gateway-stripe' ),
515
+			'i18n_terms'           => __('Please accept the terms and conditions first', 'woocommerce-gateway-stripe'),
516
+			'i18n_required_fields' => __('Please fill in required checkout fields first', 'woocommerce-gateway-stripe'),
517 517
 		);
518 518
 
519 519
 		// If we're on the pay page we need to pass stripe.js the address of the order.
520
-		if ( isset( $_GET['pay_for_order'] ) && 'true' === $_GET['pay_for_order'] ) {
521
-			$order_id = wc_get_order_id_by_order_key( urldecode( $_GET['key'] ) );
522
-			$order    = wc_get_order( $order_id );
520
+		if (isset($_GET['pay_for_order']) && 'true' === $_GET['pay_for_order']) {
521
+			$order_id = wc_get_order_id_by_order_key(urldecode($_GET['key']));
522
+			$order    = wc_get_order($order_id);
523 523
 
524 524
 			$stripe_params['billing_first_name'] = WC_Stripe_Helper::is_pre_30() ? $order->billing_first_name : $order->get_billing_first_name();
525 525
 			$stripe_params['billing_last_name']  = WC_Stripe_Helper::is_pre_30() ? $order->billing_last_name : $order->get_billing_last_name();
@@ -531,37 +531,37 @@  discard block
 block discarded – undo
531 531
 			$stripe_params['billing_country']    = WC_Stripe_Helper::is_pre_30() ? $order->billing_country : $order->get_billing_country();
532 532
 		}
533 533
 
534
-		$stripe_params['no_prepaid_card_msg']                     = __( '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' );
535
-		$stripe_params['no_bank_country_msg']                     = __( 'Please select a country for your bank.', 'woocommerce-gateway-stripe' );
536
-		$stripe_params['no_sepa_owner_msg']                       = __( 'Please enter your IBAN account name.', 'woocommerce-gateway-stripe' );
537
-		$stripe_params['no_sepa_iban_msg']                        = __( 'Please enter your IBAN account number.', 'woocommerce-gateway-stripe' );
538
-		$stripe_params['allow_prepaid_card']                      = apply_filters( 'wc_stripe_allow_prepaid_card', true ) ? 'yes' : 'no';
534
+		$stripe_params['no_prepaid_card_msg']                     = __('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');
535
+		$stripe_params['no_bank_country_msg']                     = __('Please select a country for your bank.', 'woocommerce-gateway-stripe');
536
+		$stripe_params['no_sepa_owner_msg']                       = __('Please enter your IBAN account name.', 'woocommerce-gateway-stripe');
537
+		$stripe_params['no_sepa_iban_msg']                        = __('Please enter your IBAN account number.', 'woocommerce-gateway-stripe');
538
+		$stripe_params['allow_prepaid_card']                      = apply_filters('wc_stripe_allow_prepaid_card', true) ? 'yes' : 'no';
539 539
 		$stripe_params['inline_cc_form']                          = $this->inline_cc_form ? 'yes' : 'no';
540
-		$stripe_params['stripe_checkout_require_billing_address'] = apply_filters( 'wc_stripe_checkout_require_billing_address', false ) ? 'yes' : 'no';
541
-		$stripe_params['is_checkout']                             = ( is_checkout() && empty( $_GET['pay_for_order'] ) );
540
+		$stripe_params['stripe_checkout_require_billing_address'] = apply_filters('wc_stripe_checkout_require_billing_address', false) ? 'yes' : 'no';
541
+		$stripe_params['is_checkout']                             = (is_checkout() && empty($_GET['pay_for_order']));
542 542
 		$stripe_params['return_url']                              = $this->get_stripe_return_url();
543
-		$stripe_params['ajaxurl']                                 = WC_AJAX::get_endpoint( '%%endpoint%%' );
544
-		$stripe_params['stripe_nonce']                            = wp_create_nonce( '_wc_stripe_nonce' );
543
+		$stripe_params['ajaxurl']                                 = WC_AJAX::get_endpoint('%%endpoint%%');
544
+		$stripe_params['stripe_nonce']                            = wp_create_nonce('_wc_stripe_nonce');
545 545
 		$stripe_params['statement_descriptor']                    = $this->statement_descriptor;
546
-		$stripe_params['use_elements']                            = apply_filters( 'wc_stripe_use_elements_checkout_form', true ) ? 'yes' : 'no';
546
+		$stripe_params['use_elements']                            = apply_filters('wc_stripe_use_elements_checkout_form', true) ? 'yes' : 'no';
547 547
 		$stripe_params['is_stripe_checkout']                      = $this->stripe_checkout ? 'yes' : 'no';
548
-		$stripe_params['is_change_payment_page']                  = ( isset( $_GET['pay_for_order'] ) || isset( $_GET['change_payment_method'] ) ) ? 'yes' : 'no';
548
+		$stripe_params['is_change_payment_page']                  = (isset($_GET['pay_for_order']) || isset($_GET['change_payment_method'])) ? 'yes' : 'no';
549 549
 		$stripe_params['is_add_payment_method_page']              = is_add_payment_method_page() ? 'yes' : 'no';
550
-		$stripe_params['elements_styling']                        = apply_filters( 'wc_stripe_elements_styling', false );
551
-		$stripe_params['elements_classes']                        = apply_filters( 'wc_stripe_elements_classes', false );
550
+		$stripe_params['elements_styling']                        = apply_filters('wc_stripe_elements_styling', false);
551
+		$stripe_params['elements_classes']                        = apply_filters('wc_stripe_elements_classes', false);
552 552
 
553 553
 		// merge localized messages to be use in JS
554
-		$stripe_params = array_merge( $stripe_params, WC_Stripe_Helper::get_localized_messages() );
554
+		$stripe_params = array_merge($stripe_params, WC_Stripe_Helper::get_localized_messages());
555 555
 
556
-		wp_localize_script( 'woocommerce_stripe', 'wc_stripe_params', apply_filters( 'wc_stripe_params', $stripe_params ) );
557
-		wp_localize_script( 'woocommerce_stripe_checkout', 'wc_stripe_params', apply_filters( 'wc_stripe_params', $stripe_params ) );
556
+		wp_localize_script('woocommerce_stripe', 'wc_stripe_params', apply_filters('wc_stripe_params', $stripe_params));
557
+		wp_localize_script('woocommerce_stripe_checkout', 'wc_stripe_params', apply_filters('wc_stripe_params', $stripe_params));
558 558
 
559
-		if ( $this->stripe_checkout ) {
560
-			wp_enqueue_script( 'stripe_checkout' );
559
+		if ($this->stripe_checkout) {
560
+			wp_enqueue_script('stripe_checkout');
561 561
 		}
562 562
 
563 563
 		$this->tokenization_script();
564
-		wp_enqueue_script( 'woocommerce_stripe' );
564
+		wp_enqueue_script('woocommerce_stripe');
565 565
 	}
566 566
 
567 567
 	/**
@@ -573,22 +573,22 @@  discard block
 block discarded – undo
573 573
 	 * @param object $source_object
574 574
 	 * @return mixed
575 575
 	 */
576
-	public function create_3ds_source( $order, $source_object ) {
576
+	public function create_3ds_source($order, $source_object) {
577 577
 		$currency                    = WC_Stripe_Helper::is_pre_30() ? $order->get_order_currency() : $order->get_currency();
578 578
 		$order_id                    = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
579
-		$return_url                  = $this->get_stripe_return_url( $order );
579
+		$return_url                  = $this->get_stripe_return_url($order);
580 580
 
581 581
 		$post_data                   = array();
582
-		$post_data['amount']         = WC_Stripe_Helper::get_stripe_amount( $order->get_total(), $currency );
583
-		$post_data['currency']       = strtolower( $currency );
582
+		$post_data['amount']         = WC_Stripe_Helper::get_stripe_amount($order->get_total(), $currency);
583
+		$post_data['currency']       = strtolower($currency);
584 584
 		$post_data['type']           = 'three_d_secure';
585
-		$post_data['owner']          = $this->get_owner_details( $order );
586
-		$post_data['three_d_secure'] = array( 'card' => $source_object->id );
587
-		$post_data['redirect']       = array( 'return_url' => $return_url );
585
+		$post_data['owner']          = $this->get_owner_details($order);
586
+		$post_data['three_d_secure'] = array('card' => $source_object->id);
587
+		$post_data['redirect']       = array('return_url' => $return_url);
588 588
 
589
-		WC_Stripe_Logger::log( 'Info: Begin creating 3DS source' );
589
+		WC_Stripe_Logger::log('Info: Begin creating 3DS source');
590 590
 
591
-		return WC_Stripe_API::request( $post_data, 'sources' );
591
+		return WC_Stripe_API::request($post_data, 'sources');
592 592
 	}
593 593
 
594 594
 	/**
@@ -604,46 +604,46 @@  discard block
 block discarded – undo
604 604
 	 *
605 605
 	 * @return array|void
606 606
 	 */
607
-	public function process_payment( $order_id, $retry = true, $force_save_source = false ) {
607
+	public function process_payment($order_id, $retry = true, $force_save_source = false) {
608 608
 		try {
609
-			$order          = wc_get_order( $order_id );
610
-			$source_object  = ! empty( $_POST['stripe_source'] ) ? json_decode( wc_clean( stripslashes( $_POST['stripe_source'] ) ) ) : false;
609
+			$order          = wc_get_order($order_id);
610
+			$source_object  = ! empty($_POST['stripe_source']) ? json_decode(wc_clean(stripslashes($_POST['stripe_source']))) : false;
611 611
 
612 612
 			// This comes from the create account checkbox in the checkout page.
613
-			$create_account = ! empty( $_POST['createaccount'] ) ? true : false;
613
+			$create_account = ! empty($_POST['createaccount']) ? true : false;
614 614
 
615
-			if ( $create_account ) {
615
+			if ($create_account) {
616 616
 				$new_customer_id     = WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id();
617
-				$new_stripe_customer = new WC_Stripe_Customer( $new_customer_id );
617
+				$new_stripe_customer = new WC_Stripe_Customer($new_customer_id);
618 618
 				$new_stripe_customer->create_customer();
619 619
 			}
620 620
 
621
-			$prepared_source = $this->prepare_source( get_current_user_id(), $force_save_source );
621
+			$prepared_source = $this->prepare_source(get_current_user_id(), $force_save_source);
622 622
 
623 623
 			// Check if we don't allow prepaid credit cards.
624
-			if ( ! apply_filters( 'wc_stripe_allow_prepaid_card', true ) ) {
625
-				$stripe_checkout_object = ! empty( $_POST['stripe_checkout_object'] ) ? json_decode( wc_clean( stripslashes( $_POST['stripe_checkout_object'] ) ) ) : false;
624
+			if ( ! apply_filters('wc_stripe_allow_prepaid_card', true)) {
625
+				$stripe_checkout_object = ! empty($_POST['stripe_checkout_object']) ? json_decode(wc_clean(stripslashes($_POST['stripe_checkout_object']))) : false;
626 626
 
627
-				if ( $stripe_checkout_object && 'token' === $stripe_checkout_object->object && 'prepaid' === $stripe_checkout_object->card->funding ) {
628
-					$error_msg = __( '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' );
629
-					throw new Exception( $error_msg );
627
+				if ($stripe_checkout_object && 'token' === $stripe_checkout_object->object && 'prepaid' === $stripe_checkout_object->card->funding) {
628
+					$error_msg = __('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');
629
+					throw new Exception($error_msg);
630 630
 				}
631 631
 			}
632 632
 
633
-			if ( empty( $prepared_source->source ) ) {
634
-				$error_msg = __( 'Payment processing failed. Please retry.', 'woocommerce-gateway-stripe' );
635
-				throw new Exception( $error_msg );
633
+			if (empty($prepared_source->source)) {
634
+				$error_msg = __('Payment processing failed. Please retry.', 'woocommerce-gateway-stripe');
635
+				throw new Exception($error_msg);
636 636
 			}
637 637
 
638 638
 			// Store source to order meta.
639
-			$this->save_source( $order, $prepared_source );
639
+			$this->save_source($order, $prepared_source);
640 640
 
641 641
 			// Result from Stripe API request.
642 642
 			$response = null;
643 643
 
644
-			if ( $order->get_total() > 0 ) {
644
+			if ($order->get_total() > 0) {
645 645
 				// This will throw exception if not valid.
646
-				$this->validate_minimum_order_amount( $order );
646
+				$this->validate_minimum_order_amount($order);
647 647
 
648 648
 				/**
649 649
 				 * Check if card 3DS is required or optional with 3DS setting.
@@ -652,83 +652,83 @@  discard block
 block discarded – undo
652 652
 				 * Note that if we need to save source, the original source must be first
653 653
 				 * attached to a customer in Stripe before it can be charged.
654 654
 				 */
655
-				if ( $source_object && ( 'card' === $source_object->type && 'required' === $source_object->card->three_d_secure || ( $this->three_d_secure && 'optional' === $source_object->card->three_d_secure ) ) ) {
655
+				if ($source_object && ('card' === $source_object->type && 'required' === $source_object->card->three_d_secure || ($this->three_d_secure && 'optional' === $source_object->card->three_d_secure))) {
656 656
 
657
-					$response = $this->create_3ds_source( $order, $source_object );
657
+					$response = $this->create_3ds_source($order, $source_object);
658 658
 
659
-					if ( ! empty( $response->error ) ) {
659
+					if ( ! empty($response->error)) {
660 660
 						$message = $response->error->message;
661 661
 
662
-						$order->add_order_note( $message );
662
+						$order->add_order_note($message);
663 663
 
664
-						throw new Exception( $message );
664
+						throw new Exception($message);
665 665
 					}
666 666
 
667 667
 					// Update order meta with 3DS source.
668
-					if ( WC_Stripe_Helper::is_pre_30() ) {
669
-						update_post_meta( $order_id, '_stripe_source_id', $response->id );
668
+					if (WC_Stripe_Helper::is_pre_30()) {
669
+						update_post_meta($order_id, '_stripe_source_id', $response->id);
670 670
 					} else {
671
-						$order->update_meta_data( '_stripe_source_id', $response->id );
671
+						$order->update_meta_data('_stripe_source_id', $response->id);
672 672
 						$order->save();
673 673
 					}
674 674
 
675
-					WC_Stripe_Logger::log( 'Info: Redirecting to 3DS...' );
675
+					WC_Stripe_Logger::log('Info: Redirecting to 3DS...');
676 676
 
677 677
 					return array(
678 678
 						'result'   => 'success',
679
-						'redirect' => esc_url_raw( $response->redirect->url ),
679
+						'redirect' => esc_url_raw($response->redirect->url),
680 680
 					);
681 681
 				}
682 682
 
683
-				WC_Stripe_Logger::log( "Info: Begin processing payment for order $order_id for the amount of {$order->get_total()}" );
683
+				WC_Stripe_Logger::log("Info: Begin processing payment for order $order_id for the amount of {$order->get_total()}");
684 684
 
685 685
 				// Make the request.
686
-				$response = WC_Stripe_API::request( $this->generate_payment_request( $order, $prepared_source ) );
686
+				$response = WC_Stripe_API::request($this->generate_payment_request($order, $prepared_source));
687 687
 
688
-				if ( ! empty( $response->error ) ) {
688
+				if ( ! empty($response->error)) {
689 689
 					// If it is an API error such connection or server, let's retry.
690
-					if ( 'api_connection_error' === $response->error->type || 'api_error' === $response->error->type ) {
691
-						if ( $retry ) {
692
-							sleep( 5 );
693
-							return $this->process_payment( $order_id, false, $force_save_source );
690
+					if ('api_connection_error' === $response->error->type || 'api_error' === $response->error->type) {
691
+						if ($retry) {
692
+							sleep(5);
693
+							return $this->process_payment($order_id, false, $force_save_source);
694 694
 						} else {
695 695
 							$message = 'API connection error and retries exhausted.';
696
-							$order->add_order_note( $message );
697
-							throw new Exception( $message );
696
+							$order->add_order_note($message);
697
+							throw new Exception($message);
698 698
 						}
699 699
 					}
700 700
 
701 701
 					// Customer param wrong? The user may have been deleted on stripe's end. Remove customer_id. Can be retried without.
702
-					if ( preg_match( '/No such customer/i', $response->error->message ) && $retry ) {
703
-						delete_user_meta( WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id(), '_stripe_customer_id' );
702
+					if (preg_match('/No such customer/i', $response->error->message) && $retry) {
703
+						delete_user_meta(WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id(), '_stripe_customer_id');
704 704
 
705
-						return $this->process_payment( $order_id, false, $force_save_source );
706
-					} elseif ( preg_match( '/No such token/i', $response->error->message ) && $prepared_source->token_id ) {
705
+						return $this->process_payment($order_id, false, $force_save_source);
706
+					} elseif (preg_match('/No such token/i', $response->error->message) && $prepared_source->token_id) {
707 707
 						// Source param wrong? The CARD may have been deleted on stripe's end. Remove token and show message.
708
-						$wc_token = WC_Payment_Tokens::get( $prepared_source->token_id );
708
+						$wc_token = WC_Payment_Tokens::get($prepared_source->token_id);
709 709
 						$wc_token->delete();
710
-						$message = __( 'This card is no longer available and has been removed.', 'woocommerce-gateway-stripe' );
711
-						$order->add_order_note( $message );
712
-						throw new Exception( $message );
710
+						$message = __('This card is no longer available and has been removed.', 'woocommerce-gateway-stripe');
711
+						$order->add_order_note($message);
712
+						throw new Exception($message);
713 713
 					}
714 714
 
715 715
 					$localized_messages = WC_Stripe_Helper::get_localized_messages();
716 716
 
717
-					if ( 'card_error' === $response->error->type ) {
718
-						$message = isset( $localized_messages[ $response->error->code ] ) ? $localized_messages[ $response->error->code ] : $response->error->message;
717
+					if ('card_error' === $response->error->type) {
718
+						$message = isset($localized_messages[$response->error->code]) ? $localized_messages[$response->error->code] : $response->error->message;
719 719
 					} else {
720
-						$message = isset( $localized_messages[ $response->error->type ] ) ? $localized_messages[ $response->error->type ] : $response->error->message;
720
+						$message = isset($localized_messages[$response->error->type]) ? $localized_messages[$response->error->type] : $response->error->message;
721 721
 					}
722 722
 
723
-					$order->add_order_note( $message );
723
+					$order->add_order_note($message);
724 724
 
725
-					throw new Exception( $message );
725
+					throw new Exception($message);
726 726
 				}
727 727
 
728
-				do_action( 'wc_gateway_stripe_process_payment', $response, $order );
728
+				do_action('wc_gateway_stripe_process_payment', $response, $order);
729 729
 
730 730
 				// Process valid response.
731
-				$this->process_response( $response, $order );
731
+				$this->process_response($response, $order);
732 732
 			} else {
733 733
 				$order->payment_complete();
734 734
 			}
@@ -739,17 +739,17 @@  discard block
 block discarded – undo
739 739
 			// Return thank you page redirect.
740 740
 			return array(
741 741
 				'result'   => 'success',
742
-				'redirect' => $this->get_return_url( $order ),
742
+				'redirect' => $this->get_return_url($order),
743 743
 			);
744 744
 
745
-		} catch ( Exception $e ) {
746
-			wc_add_notice( $e->getMessage(), 'error' );
747
-			WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() );
745
+		} catch (Exception $e) {
746
+			wc_add_notice($e->getMessage(), 'error');
747
+			WC_Stripe_Logger::log('Error: ' . $e->getMessage());
748 748
 
749
-			do_action( 'wc_gateway_stripe_process_payment_error', $e, $order );
749
+			do_action('wc_gateway_stripe_process_payment_error', $e, $order);
750 750
 
751
-			if ( $order->has_status( array( 'pending', 'failed' ) ) ) {
752
-				$this->send_failed_order_email( $order_id );
751
+			if ($order->has_status(array('pending', 'failed'))) {
752
+				$this->send_failed_order_email($order_id);
753 753
 			}
754 754
 
755 755
 			return array(
Please login to merge, or discard this patch.