Completed
Push — master ( ecface...cf873e )
by Roy
02:19
created
includes/payment-methods/class-wc-gateway-stripe-bancontact.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_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,25 +241,25 @@  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 );
254
-		$post_data['bancontact'] = array( 'preferred_language' => $this->get_locale() );
252
+		$post_data['owner']      = $this->get_owner_details($order);
253
+		$post_data['redirect']   = array('return_url' => $return_url);
254
+		$post_data['bancontact'] = array('preferred_language' => $this->get_locale());
255 255
 
256
-		if ( ! empty( $this->statement_descriptor ) ) {
257
-			$post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor( $this->statement_descriptor );
256
+		if ( ! empty($this->statement_descriptor)) {
257
+			$post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor($this->statement_descriptor);
258 258
 		}
259 259
 
260
-		WC_Stripe_Logger::log( 'Info: Begin creating Bancontact source' );
260
+		WC_Stripe_Logger::log('Info: Begin creating Bancontact source');
261 261
 
262
-		return WC_Stripe_API::request( apply_filters( 'wc_stripe_bancontact_source', $post_data, $order ), 'sources' );
262
+		return WC_Stripe_API::request(apply_filters('wc_stripe_bancontact_source', $post_data, $order), 'sources');
263 263
 	}
264 264
 
265 265
 	/**
@@ -273,51 +273,51 @@  discard block
 block discarded – undo
273 273
 	 *
274 274
 	 * @return array|void
275 275
 	 */
276
-	public function process_payment( $order_id, $retry = true, $force_save_source = false ) {
276
+	public function process_payment($order_id, $retry = true, $force_save_source = false) {
277 277
 		try {
278
-			$order = wc_get_order( $order_id );
278
+			$order = wc_get_order($order_id);
279 279
 
280 280
 			// This will throw exception if not valid.
281
-			$this->validate_minimum_order_amount( $order );
281
+			$this->validate_minimum_order_amount($order);
282 282
 
283 283
 			// This comes from the create account checkbox in the checkout page.
284
-			$create_account = ! empty( $_POST['createaccount'] ) ? true : false;
284
+			$create_account = ! empty($_POST['createaccount']) ? true : false;
285 285
 
286
-			if ( $create_account ) {
286
+			if ($create_account) {
287 287
 				$new_customer_id     = WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id();
288
-				$new_stripe_customer = new WC_Stripe_Customer( $new_customer_id );
288
+				$new_stripe_customer = new WC_Stripe_Customer($new_customer_id);
289 289
 				$new_stripe_customer->create_customer();
290 290
 			}
291 291
 
292
-			$response = $this->create_source( $order );
292
+			$response = $this->create_source($order);
293 293
 
294
-			if ( ! empty( $response->error ) ) {
295
-				$order->add_order_note( $response->error->message );
294
+			if ( ! empty($response->error)) {
295
+				$order->add_order_note($response->error->message);
296 296
 
297
-				throw new WC_Stripe_Exception( print_r( $response, true ), $response->error->message );
297
+				throw new WC_Stripe_Exception(print_r($response, true), $response->error->message);
298 298
 			}
299 299
 
300
-			if ( WC_Stripe_Helper::is_pre_30() ) {
301
-				update_post_meta( $order_id, '_stripe_source_id', $response->id );
300
+			if (WC_Stripe_Helper::is_pre_30()) {
301
+				update_post_meta($order_id, '_stripe_source_id', $response->id);
302 302
 			} else {
303
-				$order->update_meta_data( '_stripe_source_id', $response->id );
303
+				$order->update_meta_data('_stripe_source_id', $response->id);
304 304
 				$order->save();
305 305
 			}
306 306
 
307
-			WC_Stripe_Logger::log( 'Info: Redirecting to Bancontact...' );
307
+			WC_Stripe_Logger::log('Info: Redirecting to Bancontact...');
308 308
 
309 309
 			return array(
310 310
 				'result'   => 'success',
311
-				'redirect' => esc_url_raw( $response->redirect->url ),
311
+				'redirect' => esc_url_raw($response->redirect->url),
312 312
 			);
313
-		} catch ( WC_Stripe_Exception $e ) {
314
-			wc_add_notice( $e->getLocalizedMessage(), 'error' );
315
-			WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() );
313
+		} catch (WC_Stripe_Exception $e) {
314
+			wc_add_notice($e->getLocalizedMessage(), 'error');
315
+			WC_Stripe_Logger::log('Error: ' . $e->getMessage());
316 316
 
317
-			do_action( 'wc_gateway_stripe_process_payment_error', $e, $order );
317
+			do_action('wc_gateway_stripe_process_payment_error', $e, $order);
318 318
 
319
-			if ( $order->has_status( array( 'pending', 'failed' ) ) ) {
320
-				$this->send_failed_order_email( $order_id );
319
+			if ($order->has_status(array('pending', 'failed'))) {
320
+				$this->send_failed_order_email($order_id);
321 321
 			}
322 322
 
323 323
 			return array(
Please login to merge, or discard this patch.
includes/deprecated/class-wc-stripe-apple-pay.php 1 patch
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -1,12 +1,12 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) {
2
+if ( ! defined('ABSPATH')) {
3 3
 	exit;
4 4
 }
5 5
 
6 6
 /**
7 7
  * DEPRECATED DO NOT USE!!
8 8
  */
9
-if ( ! class_exists( 'WC_Stripe_Apple_Pay' ) ) {
9
+if ( ! class_exists('WC_Stripe_Apple_Pay')) {
10 10
 	class WC_Stripe_Apple_Pay {
11 11
 		/**
12 12
 		 * This Instance.
@@ -20,15 +20,15 @@  discard block
 block discarded – undo
20 20
 		}
21 21
 
22 22
 		public static function instance() {
23
-			WC_Stripe_Logger::log( 'DEPRECATED! WC_Stripe_Apple_Pay class has been hard deprecated. Please remove any code that references this class or instance. This class will be removed by version 5.0' );
23
+			WC_Stripe_Logger::log('DEPRECATED! WC_Stripe_Apple_Pay class has been hard deprecated. Please remove any code that references this class or instance. This class will be removed by version 5.0');
24 24
 			return self::$_this;
25 25
 		}
26 26
 
27
-		public function __get( $var ) {
27
+		public function __get($var) {
28 28
 			return null;
29 29
 		}
30 30
 
31
-		public function __call( $name, $arguments ) {
31
+		public function __call($name, $arguments) {
32 32
 			return null;
33 33
 		}
34 34
 	}
Please login to merge, or discard this patch.
includes/class-wc-stripe-webhook-handler.php 1 patch
Spacing   +179 added lines, -179 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
 
@@ -32,9 +32,9 @@  discard block
 block discarded – undo
32 32
 	 */
33 33
 	public function __construct() {
34 34
 		$this->retry_interval = 2;
35
-		$stripe_settings      = get_option( 'woocommerce_stripe_settings', array() );
36
-		$this->testmode       = ( ! empty( $stripe_settings['testmode'] ) && 'yes' === $stripe_settings['testmode'] ) ? true : false;
37
-		add_action( 'woocommerce_api_wc_stripe', array( $this, 'check_for_webhook' ) );
35
+		$stripe_settings      = get_option('woocommerce_stripe_settings', array());
36
+		$this->testmode       = ( ! empty($stripe_settings['testmode']) && 'yes' === $stripe_settings['testmode']) ? true : false;
37
+		add_action('woocommerce_api_wc_stripe', array($this, 'check_for_webhook'));
38 38
 	}
39 39
 
40 40
 	/**
@@ -44,24 +44,24 @@  discard block
 block discarded – undo
44 44
 	 * @version 4.0.0
45 45
 	 */
46 46
 	public function check_for_webhook() {
47
-		if ( ( 'POST' !== $_SERVER['REQUEST_METHOD'] )
48
-			|| ! isset( $_GET['wc-api'] )
49
-			|| ( 'wc_stripe' !== $_GET['wc-api'] )
47
+		if (('POST' !== $_SERVER['REQUEST_METHOD'])
48
+			|| ! isset($_GET['wc-api'])
49
+			|| ('wc_stripe' !== $_GET['wc-api'])
50 50
 		) {
51 51
 			return;
52 52
 		}
53 53
 
54
-		$request_body    = file_get_contents( 'php://input' );
55
-		$request_headers = array_change_key_case( $this->get_request_headers(), CASE_UPPER );
54
+		$request_body    = file_get_contents('php://input');
55
+		$request_headers = array_change_key_case($this->get_request_headers(), CASE_UPPER);
56 56
 
57 57
 		// Validate it to make sure it is legit.
58
-		if ( $this->is_valid_request( $request_headers, $request_body ) ) {
59
-			$this->process_webhook( $request_body );
60
-			status_header( 200 );
58
+		if ($this->is_valid_request($request_headers, $request_body)) {
59
+			$this->process_webhook($request_body);
60
+			status_header(200);
61 61
 			exit;
62 62
 		} else {
63
-			WC_Stripe_Logger::log( 'Incoming webhook failed validation: ' . print_r( $request_body, true ) );
64
-			status_header( 400 );
63
+			WC_Stripe_Logger::log('Incoming webhook failed validation: ' . print_r($request_body, true));
64
+			status_header(400);
65 65
 			exit;
66 66
 		}
67 67
 	}
@@ -76,12 +76,12 @@  discard block
 block discarded – undo
76 76
 	 * @param string $request_body The request body from Stripe.
77 77
 	 * @return bool
78 78
 	 */
79
-	public function is_valid_request( $request_headers = null, $request_body = null ) {
80
-		if ( null === $request_headers || null === $request_body ) {
79
+	public function is_valid_request($request_headers = null, $request_body = null) {
80
+		if (null === $request_headers || null === $request_body) {
81 81
 			return false;
82 82
 		}
83 83
 
84
-		if ( ! empty( $request_headers['USER-AGENT'] ) && ! preg_match( '/Stripe/', $request_headers['USER-AGENT'] ) ) {
84
+		if ( ! empty($request_headers['USER-AGENT']) && ! preg_match('/Stripe/', $request_headers['USER-AGENT'])) {
85 85
 			return false;
86 86
 		}
87 87
 
@@ -97,11 +97,11 @@  discard block
 block discarded – undo
97 97
 	 * @version 4.0.0
98 98
 	 */
99 99
 	public function get_request_headers() {
100
-		if ( ! function_exists( 'getallheaders' ) ) {
100
+		if ( ! function_exists('getallheaders')) {
101 101
 			$headers = [];
102
-			foreach ( $_SERVER as $name => $value ) {
103
-				if ( 'HTTP_' === substr( $name, 0, 5 ) ) {
104
-					$headers[ str_replace( ' ', '-', ucwords( strtolower( str_replace( '_', ' ', substr( $name, 5 ) ) ) ) ) ] = $value;
102
+			foreach ($_SERVER as $name => $value) {
103
+				if ('HTTP_' === substr($name, 0, 5)) {
104
+					$headers[str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', substr($name, 5)))))] = $value;
105 105
 				}
106 106
 			}
107 107
 
@@ -120,30 +120,30 @@  discard block
 block discarded – undo
120 120
 	 * @param object $notification
121 121
 	 * @param bool $retry
122 122
 	 */
123
-	public function process_webhook_payment( $notification, $retry = true ) {
123
+	public function process_webhook_payment($notification, $retry = true) {
124 124
 		// The following 2 payment methods are synchronous so does not need to be handle via webhook.
125
-		if ( 'card' === $notification->data->object->type || 'sepa_debit' === $notification->data->object->type ) {
125
+		if ('card' === $notification->data->object->type || 'sepa_debit' === $notification->data->object->type) {
126 126
 			return;
127 127
 		}
128 128
 
129
-		$order = WC_Stripe_Helper::get_order_by_source_id( $notification->data->object->id );
129
+		$order = WC_Stripe_Helper::get_order_by_source_id($notification->data->object->id);
130 130
 
131
-		if ( ! $order ) {
132
-			WC_Stripe_Logger::log( 'Could not find order via source ID: ' . $notification->data->object->id );
131
+		if ( ! $order) {
132
+			WC_Stripe_Logger::log('Could not find order via source ID: ' . $notification->data->object->id);
133 133
 			return;
134 134
 		}
135 135
 
136 136
 		$order_id  = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
137 137
 		$source_id = $notification->data->object->id;
138 138
 
139
-		$is_pending_receiver = ( 'receiver' === $notification->data->object->flow );
139
+		$is_pending_receiver = ('receiver' === $notification->data->object->flow);
140 140
 
141 141
 		try {
142
-			if ( 'processing' === $order->get_status() || 'completed' === $order->get_status() ) {
142
+			if ('processing' === $order->get_status() || 'completed' === $order->get_status()) {
143 143
 				return;
144 144
 			}
145 145
 
146
-			if ( 'on-hold' === $order->get_status() && ! $is_pending_receiver ) {
146
+			if ('on-hold' === $order->get_status() && ! $is_pending_receiver) {
147 147
 				return;
148 148
 			}
149 149
 
@@ -151,100 +151,100 @@  discard block
 block discarded – undo
151 151
 			$response = null;
152 152
 
153 153
 			// This will throw exception if not valid.
154
-			$this->validate_minimum_order_amount( $order );
154
+			$this->validate_minimum_order_amount($order);
155 155
 
156
-			WC_Stripe_Logger::log( "Info: (Webhook) Begin processing payment for order $order_id for the amount of {$order->get_total()}" );
156
+			WC_Stripe_Logger::log("Info: (Webhook) Begin processing payment for order $order_id for the amount of {$order->get_total()}");
157 157
 
158 158
 			// Prep source object.
159 159
 			$source_object           = new stdClass();
160 160
 			$source_object->token_id = '';
161
-			$source_object->customer = $this->get_stripe_customer_id( $order );
161
+			$source_object->customer = $this->get_stripe_customer_id($order);
162 162
 			$source_object->source   = $source_id;
163 163
 
164 164
 			// Make the request.
165
-			$response = WC_Stripe_API::request( $this->generate_payment_request( $order, $source_object ) );
165
+			$response = WC_Stripe_API::request($this->generate_payment_request($order, $source_object));
166 166
 
167
-			if ( ! empty( $response->error ) ) {
167
+			if ( ! empty($response->error)) {
168 168
 				// If it is an API error such connection or server, let's retry.
169
-				if ( 'api_connection_error' === $response->error->type || 'api_error' === $response->error->type ) {
170
-					if ( $retry ) {
171
-						sleep( 5 );
172
-						return $this->process_webhook_payment( $notification, false );
169
+				if ('api_connection_error' === $response->error->type || 'api_error' === $response->error->type) {
170
+					if ($retry) {
171
+						sleep(5);
172
+						return $this->process_webhook_payment($notification, false);
173 173
 					} else {
174 174
 						$localized_message = 'API connection error and retries exhausted.';
175
-						$order->add_order_note( $localized_message );
176
-						throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message );
175
+						$order->add_order_note($localized_message);
176
+						throw new WC_Stripe_Exception(print_r($response, true), $localized_message);
177 177
 					}
178 178
 				}
179 179
 
180 180
 				// We want to retry.
181
-				if ( $this->is_retryable_error( $response->error ) ) {
182
-					if ( $retry ) {
181
+				if ($this->is_retryable_error($response->error)) {
182
+					if ($retry) {
183 183
 						// Don't do anymore retries after this.
184
-						if ( 5 <= $this->retry_interval ) {
184
+						if (5 <= $this->retry_interval) {
185 185
 
186
-							return $this->process_webhook_payment( $notification, false );
186
+							return $this->process_webhook_payment($notification, false);
187 187
 						}
188 188
 
189
-						sleep( $this->retry_interval );
189
+						sleep($this->retry_interval);
190 190
 
191 191
 						$this->retry_interval++;
192
-						return $this->process_webhook_payment( $notification, true );
192
+						return $this->process_webhook_payment($notification, true);
193 193
 					} else {
194
-						$localized_message = __( 'On going requests error and retries exhausted.', 'woocommerce-gateway-stripe' );
195
-						$order->add_order_note( $localized_message );
196
-						throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message );
194
+						$localized_message = __('On going requests error and retries exhausted.', 'woocommerce-gateway-stripe');
195
+						$order->add_order_note($localized_message);
196
+						throw new WC_Stripe_Exception(print_r($response, true), $localized_message);
197 197
 					}
198 198
 				}
199 199
 
200 200
 				// Customer param wrong? The user may have been deleted on stripe's end. Remove customer_id. Can be retried without.
201
-				if ( preg_match( '/No such customer/i', $response->error->message ) && $retry ) {
202
-					if ( WC_Stripe_Helper::is_pre_30() ) {
203
-						delete_user_meta( $order->customer_user, '_stripe_customer_id' );
204
-						delete_post_meta( $order_id, '_stripe_customer_id' );
201
+				if (preg_match('/No such customer/i', $response->error->message) && $retry) {
202
+					if (WC_Stripe_Helper::is_pre_30()) {
203
+						delete_user_meta($order->customer_user, '_stripe_customer_id');
204
+						delete_post_meta($order_id, '_stripe_customer_id');
205 205
 					} else {
206
-						delete_user_meta( $order->get_customer_id(), '_stripe_customer_id' );
207
-						$order->delete_meta_data( '_stripe_customer_id' );
206
+						delete_user_meta($order->get_customer_id(), '_stripe_customer_id');
207
+						$order->delete_meta_data('_stripe_customer_id');
208 208
 						$order->save();
209 209
 					}
210 210
 
211
-					return $this->process_webhook_payment( $notification, false );
211
+					return $this->process_webhook_payment($notification, false);
212 212
 
213
-				} elseif ( preg_match( '/No such token/i', $response->error->message ) && $source_object->token_id ) {
213
+				} elseif (preg_match('/No such token/i', $response->error->message) && $source_object->token_id) {
214 214
 					// Source param wrong? The CARD may have been deleted on stripe's end. Remove token and show message.
215
-					$wc_token = WC_Payment_Tokens::get( $source_object->token_id );
215
+					$wc_token = WC_Payment_Tokens::get($source_object->token_id);
216 216
 					$wc_token->delete();
217
-					$message = __( 'This card is no longer available and has been removed.', 'woocommerce-gateway-stripe' );
218
-					$order->add_order_note( $message );
219
-					throw new WC_Stripe_Exception( print_r( $response, true ), $message );
217
+					$message = __('This card is no longer available and has been removed.', 'woocommerce-gateway-stripe');
218
+					$order->add_order_note($message);
219
+					throw new WC_Stripe_Exception(print_r($response, true), $message);
220 220
 				}
221 221
 
222 222
 				$localized_messages = WC_Stripe_Helper::get_localized_messages();
223 223
 
224
-				if ( 'card_error' === $response->error->type ) {
225
-					$localized_message = isset( $localized_messages[ $response->error->code ] ) ? $localized_messages[ $response->error->code ] : $response->error->message;
224
+				if ('card_error' === $response->error->type) {
225
+					$localized_message = isset($localized_messages[$response->error->code]) ? $localized_messages[$response->error->code] : $response->error->message;
226 226
 				} else {
227
-					$localized_message = isset( $localized_messages[ $response->error->type ] ) ? $localized_messages[ $response->error->type ] : $response->error->message;
227
+					$localized_message = isset($localized_messages[$response->error->type]) ? $localized_messages[$response->error->type] : $response->error->message;
228 228
 				}
229 229
 
230
-				$order->add_order_note( $localized_message );
230
+				$order->add_order_note($localized_message);
231 231
 
232
-				throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message );
232
+				throw new WC_Stripe_Exception(print_r($response, true), $localized_message);
233 233
 			}
234 234
 
235
-			do_action( 'wc_gateway_stripe_process_webhook_payment', $response, $order );
235
+			do_action('wc_gateway_stripe_process_webhook_payment', $response, $order);
236 236
 
237
-			$this->process_response( $response, $order );
237
+			$this->process_response($response, $order);
238 238
 
239
-		} catch ( WC_Stripe_Exception $e ) {
240
-			WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() );
239
+		} catch (WC_Stripe_Exception $e) {
240
+			WC_Stripe_Logger::log('Error: ' . $e->getMessage());
241 241
 
242
-			do_action( 'wc_gateway_stripe_process_webhook_payment_error', $e, $order );
242
+			do_action('wc_gateway_stripe_process_webhook_payment_error', $e, $order);
243 243
 
244
-			$statuses = array( 'pending', 'failed' );
244
+			$statuses = array('pending', 'failed');
245 245
 
246
-			if ( $order->has_status( $statuses ) ) {
247
-				$this->send_failed_order_email( $order_id );
246
+			if ($order->has_status($statuses)) {
247
+				$this->send_failed_order_email($order_id);
248 248
 			}
249 249
 		}
250 250
 	}
@@ -257,21 +257,21 @@  discard block
 block discarded – undo
257 257
 	 * @since 4.0.0
258 258
 	 * @param object $notification
259 259
 	 */
260
-	public function process_webhook_dispute( $notification ) {
261
-		$order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->charge );
260
+	public function process_webhook_dispute($notification) {
261
+		$order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->charge);
262 262
 
263
-		if ( ! $order ) {
264
-			WC_Stripe_Logger::log( 'Could not find order via charge ID: ' . $notification->data->object->charge );
263
+		if ( ! $order) {
264
+			WC_Stripe_Logger::log('Could not find order via charge ID: ' . $notification->data->object->charge);
265 265
 			return;
266 266
 		}
267 267
 
268 268
 		/* translators: 1) The URL to the order. */
269
-		$order->update_status( 'on-hold', sprintf( __( 'A dispute was created for this order. Response is needed. Please go to your <a href="%s" title="Stripe Dashboard" target="_blank">Stripe Dashboard</a> to review this dispute.', 'woocommerce-gateway-stripe' ), $this->get_transaction_url( $order ) ) );
269
+		$order->update_status('on-hold', sprintf(__('A dispute was created for this order. Response is needed. Please go to your <a href="%s" title="Stripe Dashboard" target="_blank">Stripe Dashboard</a> to review this dispute.', 'woocommerce-gateway-stripe'), $this->get_transaction_url($order)));
270 270
 
271
-		do_action( 'wc_gateway_stripe_process_webhook_payment_error', $order, $notification );
271
+		do_action('wc_gateway_stripe_process_webhook_payment_error', $order, $notification);
272 272
 
273 273
 		$order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
274
-		$this->send_failed_order_email( $order_id );
274
+		$this->send_failed_order_email($order_id);
275 275
 	}
276 276
 
277 277
 	/**
@@ -282,41 +282,41 @@  discard block
 block discarded – undo
282 282
 	 * @version 4.0.0
283 283
 	 * @param object $notification
284 284
 	 */
285
-	public function process_webhook_capture( $notification ) {
286
-		$order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->id );
285
+	public function process_webhook_capture($notification) {
286
+		$order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->id);
287 287
 
288
-		if ( ! $order ) {
289
-			WC_Stripe_Logger::log( 'Could not find order via charge ID: ' . $notification->data->object->id );
288
+		if ( ! $order) {
289
+			WC_Stripe_Logger::log('Could not find order via charge ID: ' . $notification->data->object->id);
290 290
 			return;
291 291
 		}
292 292
 
293 293
 		$order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
294 294
 
295
-		if ( 'stripe' === ( WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method() ) ) {
296
-			$charge   = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_transaction_id', true ) : $order->get_transaction_id();
297
-			$captured = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_stripe_charge_captured', true ) : $order->get_meta( '_stripe_charge_captured', true );
295
+		if ('stripe' === (WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method())) {
296
+			$charge   = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_transaction_id', true) : $order->get_transaction_id();
297
+			$captured = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_stripe_charge_captured', true) : $order->get_meta('_stripe_charge_captured', true);
298 298
 
299
-			if ( $charge && 'no' === $captured ) {
300
-				WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, '_stripe_charge_captured', 'yes' ) : $order->update_meta_data( '_stripe_charge_captured', 'yes' );
299
+			if ($charge && 'no' === $captured) {
300
+				WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, '_stripe_charge_captured', 'yes') : $order->update_meta_data('_stripe_charge_captured', 'yes');
301 301
 
302 302
 				// Store other data such as fees
303
-				WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, '_transaction_id', $notification->data->object->id ) : $order->set_transaction_id( $notification->data->object->id );
303
+				WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, '_transaction_id', $notification->data->object->id) : $order->set_transaction_id($notification->data->object->id);
304 304
 
305
-				if ( isset( $notification->data->object->balance_transaction ) ) {
306
-					$this->update_fees( $order, $notification->data->object->balance_transaction );
305
+				if (isset($notification->data->object->balance_transaction)) {
306
+					$this->update_fees($order, $notification->data->object->balance_transaction);
307 307
 				}
308 308
 
309
-				if ( is_callable( array( $order, 'save' ) ) ) {
309
+				if (is_callable(array($order, 'save'))) {
310 310
 					$order->save();
311 311
 				}
312 312
 
313 313
 				/* translators: transaction id */
314
-				$order->update_status( $order->needs_processing() ? 'processing' : 'completed', sprintf( __( 'Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe' ), $notification->data->object->id ) );
314
+				$order->update_status($order->needs_processing() ? 'processing' : 'completed', sprintf(__('Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe'), $notification->data->object->id));
315 315
 
316 316
 				// Check and see if capture is partial.
317
-				if ( $this->is_partial_capture( $notification ) ) {
318
-					$order->set_total( $this->get_partial_amount_to_charge( $notification ) );
319
-					$order->add_order_note( __( 'This charge was partially captured via Stripe Dashboard', 'woocommerce-gateway-stripe' ) );
317
+				if ($this->is_partial_capture($notification)) {
318
+					$order->set_total($this->get_partial_amount_to_charge($notification));
319
+					$order->add_order_note(__('This charge was partially captured via Stripe Dashboard', 'woocommerce-gateway-stripe'));
320 320
 					$order->save();
321 321
 				}
322 322
 			}
@@ -331,38 +331,38 @@  discard block
 block discarded – undo
331 331
 	 * @version 4.0.0
332 332
 	 * @param object $notification
333 333
 	 */
334
-	public function process_webhook_charge_succeeded( $notification ) {
334
+	public function process_webhook_charge_succeeded($notification) {
335 335
 		// The following payment methods are synchronous so does not need to be handle via webhook.
336
-		if ( ( isset( $notification->data->object->source->type ) && 'card' === $notification->data->object->source->type ) || ( isset( $notification->data->object->source->type ) && 'three_d_secure' === $notification->data->object->source->type ) ) {
336
+		if ((isset($notification->data->object->source->type) && 'card' === $notification->data->object->source->type) || (isset($notification->data->object->source->type) && 'three_d_secure' === $notification->data->object->source->type)) {
337 337
 			return;
338 338
 		}
339 339
 
340
-		$order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->id );
340
+		$order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->id);
341 341
 
342
-		if ( ! $order ) {
343
-			WC_Stripe_Logger::log( 'Could not find order via charge ID: ' . $notification->data->object->id );
342
+		if ( ! $order) {
343
+			WC_Stripe_Logger::log('Could not find order via charge ID: ' . $notification->data->object->id);
344 344
 			return;
345 345
 		}
346 346
 
347 347
 		$order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
348 348
 
349
-		if ( 'on-hold' !== $order->get_status() ) {
349
+		if ('on-hold' !== $order->get_status()) {
350 350
 			return;
351 351
 		}
352 352
 
353 353
 		// Store other data such as fees
354
-		WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, '_transaction_id', $notification->data->object->id ) : $order->set_transaction_id( $notification->data->object->id );
354
+		WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, '_transaction_id', $notification->data->object->id) : $order->set_transaction_id($notification->data->object->id);
355 355
 
356
-		if ( isset( $notification->data->object->balance_transaction ) ) {
357
-			$this->update_fees( $order, $notification->data->object->balance_transaction );
356
+		if (isset($notification->data->object->balance_transaction)) {
357
+			$this->update_fees($order, $notification->data->object->balance_transaction);
358 358
 		}
359 359
 
360
-		if ( is_callable( array( $order, 'save' ) ) ) {
360
+		if (is_callable(array($order, 'save'))) {
361 361
 			$order->save();
362 362
 		}
363 363
 
364 364
 		/* translators: transaction id */
365
-		$order->update_status( $order->needs_processing() ? 'processing' : 'completed', sprintf( __( 'Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe' ), $notification->data->object->id ) );
365
+		$order->update_status($order->needs_processing() ? 'processing' : 'completed', sprintf(__('Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe'), $notification->data->object->id));
366 366
 	}
367 367
 
368 368
 	/**
@@ -373,23 +373,23 @@  discard block
 block discarded – undo
373 373
 	 * @version 4.0.0
374 374
 	 * @param object $notification
375 375
 	 */
376
-	public function process_webhook_charge_failed( $notification ) {
377
-		$order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->id );
376
+	public function process_webhook_charge_failed($notification) {
377
+		$order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->id);
378 378
 
379
-		if ( ! $order ) {
380
-			WC_Stripe_Logger::log( 'Could not find order via charge ID: ' . $notification->data->object->id );
379
+		if ( ! $order) {
380
+			WC_Stripe_Logger::log('Could not find order via charge ID: ' . $notification->data->object->id);
381 381
 			return;
382 382
 		}
383 383
 
384 384
 		$order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
385 385
 
386
-		if ( 'on-hold' !== $order->get_status() ) {
386
+		if ('on-hold' !== $order->get_status()) {
387 387
 			return;
388 388
 		}
389 389
 
390
-		$order->update_status( 'failed', __( 'This payment failed to clear.', 'woocommerce-gateway-stripe' ) );
390
+		$order->update_status('failed', __('This payment failed to clear.', 'woocommerce-gateway-stripe'));
391 391
 
392
-		do_action( 'wc_gateway_stripe_process_webhook_payment_error', $order, $notification );
392
+		do_action('wc_gateway_stripe_process_webhook_payment_error', $order, $notification);
393 393
 	}
394 394
 
395 395
 	/**
@@ -400,23 +400,23 @@  discard block
 block discarded – undo
400 400
 	 * @version 4.0.0
401 401
 	 * @param object $notification
402 402
 	 */
403
-	public function process_webhook_source_canceled( $notification ) {
404
-		$order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->id );
403
+	public function process_webhook_source_canceled($notification) {
404
+		$order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->id);
405 405
 
406
-		if ( ! $order ) {
407
-			WC_Stripe_Logger::log( 'Could not find order via charge ID: ' . $notification->data->object->id );
406
+		if ( ! $order) {
407
+			WC_Stripe_Logger::log('Could not find order via charge ID: ' . $notification->data->object->id);
408 408
 			return;
409 409
 		}
410 410
 
411 411
 		$order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
412 412
 
413
-		if ( 'on-hold' !== $order->get_status() || 'cancelled' !== $order->get_status() ) {
413
+		if ('on-hold' !== $order->get_status() || 'cancelled' !== $order->get_status()) {
414 414
 			return;
415 415
 		}
416 416
 
417
-		$order->update_status( 'cancelled', __( 'This payment has cancelled.', 'woocommerce-gateway-stripe' ) );
417
+		$order->update_status('cancelled', __('This payment has cancelled.', 'woocommerce-gateway-stripe'));
418 418
 
419
-		do_action( 'wc_gateway_stripe_process_webhook_payment_error', $order, $notification );
419
+		do_action('wc_gateway_stripe_process_webhook_payment_error', $order, $notification);
420 420
 	}
421 421
 
422 422
 	/**
@@ -427,42 +427,42 @@  discard block
 block discarded – undo
427 427
 	 * @version 4.0.0
428 428
 	 * @param object $notification
429 429
 	 */
430
-	public function process_webhook_refund( $notification ) {
431
-		$order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->id );
430
+	public function process_webhook_refund($notification) {
431
+		$order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->id);
432 432
 
433
-		if ( ! $order ) {
434
-			WC_Stripe_Logger::log( 'Could not find order via charge ID: ' . $notification->data->object->id );
433
+		if ( ! $order) {
434
+			WC_Stripe_Logger::log('Could not find order via charge ID: ' . $notification->data->object->id);
435 435
 			return;
436 436
 		}
437 437
 
438 438
 		$order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
439 439
 
440
-		if ( 'stripe' === ( WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method() ) ) {
441
-			$charge    = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_transaction_id', true ) : $order->get_transaction_id();
442
-			$captured  = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_stripe_charge_captured', true ) : $order->get_meta( '_stripe_charge_captured', true );
443
-			$refund_id = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_stripe_refund_id', true ) : $order->get_meta( '_stripe_refund_id', true );
440
+		if ('stripe' === (WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method())) {
441
+			$charge    = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_transaction_id', true) : $order->get_transaction_id();
442
+			$captured  = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_stripe_charge_captured', true) : $order->get_meta('_stripe_charge_captured', true);
443
+			$refund_id = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_stripe_refund_id', true) : $order->get_meta('_stripe_refund_id', true);
444 444
 
445 445
 			// If the refund ID matches, don't continue to prevent double refunding.
446
-			if ( $notification->data->object->refunds->data[0]->id === $refund_id ) {
446
+			if ($notification->data->object->refunds->data[0]->id === $refund_id) {
447 447
 				return;
448 448
 			}
449 449
 
450 450
 			// Only refund captured charge.
451
-			if ( $charge ) {
452
-				$reason = ( isset( $captured ) && 'yes' === $captured ) ? __( 'Refunded via Stripe Dashboard', 'woocommerce-gateway-stripe' ) : __( 'Pre-Authorization Released via Stripe Dashboard', 'woocommerce-gateway-stripe' );
451
+			if ($charge) {
452
+				$reason = (isset($captured) && 'yes' === $captured) ? __('Refunded via Stripe Dashboard', 'woocommerce-gateway-stripe') : __('Pre-Authorization Released via Stripe Dashboard', 'woocommerce-gateway-stripe');
453 453
 
454 454
 				// Create the refund.
455
-				$refund = wc_create_refund( array(
455
+				$refund = wc_create_refund(array(
456 456
 					'order_id'       => $order_id,
457
-					'amount'         => $this->get_refund_amount( $notification ),
457
+					'amount'         => $this->get_refund_amount($notification),
458 458
 					'reason'         => $reason,
459
-				) );
459
+				));
460 460
 
461
-				if ( is_wp_error( $refund ) ) {
462
-					WC_Stripe_Logger::log( $refund->get_error_message() );
461
+				if (is_wp_error($refund)) {
462
+					WC_Stripe_Logger::log($refund->get_error_message());
463 463
 				}
464 464
 
465
-				$order->add_order_note( $reason );
465
+				$order->add_order_note($reason);
466 466
 			}
467 467
 		}
468 468
 	}
@@ -473,21 +473,21 @@  discard block
 block discarded – undo
473 473
 	 * @since 4.0.6
474 474
 	 * @param object $notification
475 475
 	 */
476
-	public function process_review_opened( $notification ) {
477
-		$order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->charge );
476
+	public function process_review_opened($notification) {
477
+		$order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->charge);
478 478
 
479
-		if ( ! $order ) {
480
-			WC_Stripe_Logger::log( 'Could not find order via charge ID: ' . $notification->data->object->charge );
479
+		if ( ! $order) {
480
+			WC_Stripe_Logger::log('Could not find order via charge ID: ' . $notification->data->object->charge);
481 481
 			return;
482 482
 		}
483 483
 
484 484
 		/* translators: 1) The URL to the order. 2) The reason type. */
485
-		$message = sprintf( __( 'A review has been opened for this order. Action is needed. Please go to your <a href="%1$s" title="Stripe Dashboard" target="_blank">Stripe Dashboard</a> to review the issue. Reason: (%2$s)', 'woocommerce-gateway-stripe' ), $this->get_transaction_url( $order ), $notification->data->object->reason );
485
+		$message = sprintf(__('A review has been opened for this order. Action is needed. Please go to your <a href="%1$s" title="Stripe Dashboard" target="_blank">Stripe Dashboard</a> to review the issue. Reason: (%2$s)', 'woocommerce-gateway-stripe'), $this->get_transaction_url($order), $notification->data->object->reason);
486 486
 
487
-		if ( apply_filters( 'wc_stripe_webhook_review_change_order_status', true, $order, $notification ) ) {
488
-			$order->update_status( 'on-hold', $message );
487
+		if (apply_filters('wc_stripe_webhook_review_change_order_status', true, $order, $notification)) {
488
+			$order->update_status('on-hold', $message);
489 489
 		} else {
490
-			$order->add_order_note( $message );
490
+			$order->add_order_note($message);
491 491
 		}
492 492
 	}
493 493
 
@@ -497,25 +497,25 @@  discard block
 block discarded – undo
497 497
 	 * @since 4.0.6
498 498
 	 * @param object $notification
499 499
 	 */
500
-	public function process_review_closed( $notification ) {
501
-		$order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->charge );
500
+	public function process_review_closed($notification) {
501
+		$order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->charge);
502 502
 
503
-		if ( ! $order ) {
504
-			WC_Stripe_Logger::log( 'Could not find order via charge ID: ' . $notification->data->object->charge );
503
+		if ( ! $order) {
504
+			WC_Stripe_Logger::log('Could not find order via charge ID: ' . $notification->data->object->charge);
505 505
 			return;
506 506
 		}
507 507
 
508 508
 		/* translators: 1) The reason type. */
509
-		$message = sprintf( __( 'The opened review for this order is now closed. Reason: (%s)', 'woocommerce-gateway-stripe' ), $notification->data->object->reason );
509
+		$message = sprintf(__('The opened review for this order is now closed. Reason: (%s)', 'woocommerce-gateway-stripe'), $notification->data->object->reason);
510 510
 
511
-		if ( 'on-hold' === $order->get_status() ) {
512
-			if ( apply_filters( 'wc_stripe_webhook_review_change_order_status', true, $order, $notification ) ) {
513
-				$order->update_status( 'processing', $message );
511
+		if ('on-hold' === $order->get_status()) {
512
+			if (apply_filters('wc_stripe_webhook_review_change_order_status', true, $order, $notification)) {
513
+				$order->update_status('processing', $message);
514 514
 			} else {
515
-				$order->add_order_note( $message );
515
+				$order->add_order_note($message);
516 516
 			}
517 517
 		} else {
518
-			$order->add_order_note( $message );
518
+			$order->add_order_note($message);
519 519
 		}
520 520
 	}
521 521
 
@@ -526,7 +526,7 @@  discard block
 block discarded – undo
526 526
 	 * @version 4.0.0
527 527
 	 * @param object $notification
528 528
 	 */
529
-	public function is_partial_capture( $notification ) {
529
+	public function is_partial_capture($notification) {
530 530
 		return 0 < $notification->data->object->amount_refunded;
531 531
 	}
532 532
 
@@ -537,11 +537,11 @@  discard block
 block discarded – undo
537 537
 	 * @version 4.0.0
538 538
 	 * @param object $notification
539 539
 	 */
540
-	public function get_refund_amount( $notification ) {
541
-		if ( $this->is_partial_capture( $notification ) ) {
540
+	public function get_refund_amount($notification) {
541
+		if ($this->is_partial_capture($notification)) {
542 542
 			$amount = $notification->data->object->amount_refunded / 100;
543 543
 
544
-			if ( in_array( strtolower( $notification->data->object->currency ), WC_Stripe_Helper::no_decimal_currencies() ) ) {
544
+			if (in_array(strtolower($notification->data->object->currency), WC_Stripe_Helper::no_decimal_currencies())) {
545 545
 				$amount = $notification->data->object->amount_refunded;
546 546
 			}
547 547
 
@@ -558,12 +558,12 @@  discard block
 block discarded – undo
558 558
 	 * @version 4.0.0
559 559
 	 * @param object $notification
560 560
 	 */
561
-	public function get_partial_amount_to_charge( $notification ) {
562
-		if ( $this->is_partial_capture( $notification ) ) {
563
-			$amount = ( $notification->data->object->amount - $notification->data->object->amount_refunded ) / 100;
561
+	public function get_partial_amount_to_charge($notification) {
562
+		if ($this->is_partial_capture($notification)) {
563
+			$amount = ($notification->data->object->amount - $notification->data->object->amount_refunded) / 100;
564 564
 
565
-			if ( in_array( strtolower( $notification->data->object->currency ), WC_Stripe_Helper::no_decimal_currencies() ) ) {
566
-				$amount = ( $notification->data->object->amount - $notification->data->object->amount_refunded );
565
+			if (in_array(strtolower($notification->data->object->currency), WC_Stripe_Helper::no_decimal_currencies())) {
566
+				$amount = ($notification->data->object->amount - $notification->data->object->amount_refunded);
567 567
 			}
568 568
 
569 569
 			return $amount;
@@ -579,44 +579,44 @@  discard block
 block discarded – undo
579 579
 	 * @version 4.0.0
580 580
 	 * @param string $request_body
581 581
 	 */
582
-	public function process_webhook( $request_body ) {
583
-		$notification = json_decode( $request_body );
582
+	public function process_webhook($request_body) {
583
+		$notification = json_decode($request_body);
584 584
 
585
-		switch ( $notification->type ) {
585
+		switch ($notification->type) {
586 586
 			case 'source.chargeable':
587
-				$this->process_webhook_payment( $notification );
587
+				$this->process_webhook_payment($notification);
588 588
 				break;
589 589
 
590 590
 			case 'source.canceled':
591
-				$this->process_webhook_source_canceled( $notification );
591
+				$this->process_webhook_source_canceled($notification);
592 592
 				break;
593 593
 
594 594
 			case 'charge.succeeded':
595
-				$this->process_webhook_charge_succeeded( $notification );
595
+				$this->process_webhook_charge_succeeded($notification);
596 596
 				break;
597 597
 
598 598
 			case 'charge.failed':
599
-				$this->process_webhook_charge_failed( $notification );
599
+				$this->process_webhook_charge_failed($notification);
600 600
 				break;
601 601
 
602 602
 			case 'charge.captured':
603
-				$this->process_webhook_capture( $notification );
603
+				$this->process_webhook_capture($notification);
604 604
 				break;
605 605
 
606 606
 			case 'charge.dispute.created':
607
-				$this->process_webhook_dispute( $notification );
607
+				$this->process_webhook_dispute($notification);
608 608
 				break;
609 609
 
610 610
 			case 'charge.refunded':
611
-				$this->process_webhook_refund( $notification );
611
+				$this->process_webhook_refund($notification);
612 612
 				break;
613 613
 
614 614
 			case 'review.opened':
615
-				$this->process_review_opened( $notification );
615
+				$this->process_review_opened($notification);
616 616
 				break;
617 617
 
618 618
 			case 'review.closed':
619
-				$this->process_review_closed( $notification );
619
+				$this->process_review_closed($notification);
620 620
 				break;
621 621
 
622 622
 		}
Please login to merge, or discard this patch.
includes/payment-methods/class-wc-gateway-stripe-bitcoin.php 1 patch
Spacing   +89 added lines, -89 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) {
2
+if ( ! defined('ABSPATH')) {
3 3
 	exit;
4 4
 }
5 5
 
@@ -64,9 +64,9 @@  discard block
 block discarded – undo
64 64
 	 */
65 65
 	public function __construct() {
66 66
 		$this->id                   = 'stripe_bitcoin';
67
-		$this->method_title         = __( 'Stripe Bitcoin', 'woocommerce-gateway-stripe' );
67
+		$this->method_title         = __('Stripe Bitcoin', 'woocommerce-gateway-stripe');
68 68
 		/* translators: link */
69
-		$this->method_description   = sprintf( __( 'All other general Stripe settings can be adjusted <a href="%s">here</a>.', 'woocommerce-gateway-stripe' ), admin_url( 'admin.php?page=wc-settings&tab=checkout&section=stripe' ) );
69
+		$this->method_description   = sprintf(__('All other general Stripe settings can be adjusted <a href="%s">here</a>.', 'woocommerce-gateway-stripe'), admin_url('admin.php?page=wc-settings&tab=checkout&section=stripe'));
70 70
 		$this->supports             = array(
71 71
 			'products',
72 72
 			'refunds',
@@ -78,29 +78,29 @@  discard block
 block discarded – undo
78 78
 		// Load the settings.
79 79
 		$this->init_settings();
80 80
 
81
-		$main_settings              = get_option( 'woocommerce_stripe_settings' );
82
-		$this->title                = $this->get_option( 'title' );
83
-		$this->description          = $this->get_option( 'description' );
84
-		$this->enabled              = $this->get_option( 'enabled' );
85
-		$this->testmode             = ( ! empty( $main_settings['testmode'] ) && 'yes' === $main_settings['testmode'] ) ? true : false;
86
-		$this->saved_cards          = ( ! empty( $main_settings['saved_cards'] ) && 'yes' === $main_settings['saved_cards'] ) ? true : false;
87
-		$this->publishable_key      = ! empty( $main_settings['publishable_key'] ) ? $main_settings['publishable_key'] : '';
88
-		$this->secret_key           = ! empty( $main_settings['secret_key'] ) ? $main_settings['secret_key'] : '';
89
-		$this->statement_descriptor = ! empty( $main_settings['statement_descriptor'] ) ? $main_settings['statement_descriptor'] : '';
90
-
91
-		if ( $this->testmode ) {
92
-			$this->publishable_key = ! empty( $main_settings['test_publishable_key'] ) ? $main_settings['test_publishable_key'] : '';
93
-			$this->secret_key      = ! empty( $main_settings['test_secret_key'] ) ? $main_settings['test_secret_key'] : '';
81
+		$main_settings              = get_option('woocommerce_stripe_settings');
82
+		$this->title                = $this->get_option('title');
83
+		$this->description          = $this->get_option('description');
84
+		$this->enabled              = $this->get_option('enabled');
85
+		$this->testmode             = ( ! empty($main_settings['testmode']) && 'yes' === $main_settings['testmode']) ? true : false;
86
+		$this->saved_cards          = ( ! empty($main_settings['saved_cards']) && 'yes' === $main_settings['saved_cards']) ? true : false;
87
+		$this->publishable_key      = ! empty($main_settings['publishable_key']) ? $main_settings['publishable_key'] : '';
88
+		$this->secret_key           = ! empty($main_settings['secret_key']) ? $main_settings['secret_key'] : '';
89
+		$this->statement_descriptor = ! empty($main_settings['statement_descriptor']) ? $main_settings['statement_descriptor'] : '';
90
+
91
+		if ($this->testmode) {
92
+			$this->publishable_key = ! empty($main_settings['test_publishable_key']) ? $main_settings['test_publishable_key'] : '';
93
+			$this->secret_key      = ! empty($main_settings['test_secret_key']) ? $main_settings['test_secret_key'] : '';
94 94
 		}
95 95
 
96
-		add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) );
97
-		add_action( 'admin_notices', array( $this, 'check_environment' ) );
98
-		add_action( 'admin_head', array( $this, 'remove_admin_notice' ) );
99
-		add_action( 'wp_enqueue_scripts', array( $this, 'payment_scripts' ) );
100
-		add_action( 'woocommerce_thankyou_stripe_bitcoin', array( $this, 'thankyou_page' ) );
96
+		add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options'));
97
+		add_action('admin_notices', array($this, 'check_environment'));
98
+		add_action('admin_head', array($this, 'remove_admin_notice'));
99
+		add_action('wp_enqueue_scripts', array($this, 'payment_scripts'));
100
+		add_action('woocommerce_thankyou_stripe_bitcoin', array($this, 'thankyou_page'));
101 101
 
102 102
 		// Customer Emails.
103
-		add_action( 'woocommerce_email_before_order_table', array( $this, 'email_instructions' ), 10, 3 );
103
+		add_action('woocommerce_email_before_order_table', array($this, 'email_instructions'), 10, 3);
104 104
 	}
105 105
 
106 106
 	/**
@@ -110,19 +110,19 @@  discard block
 block discarded – undo
110 110
 	 * @version 4.0.0
111 111
 	 */
112 112
 	public function check_environment() {
113
-		if ( ! current_user_can( 'manage_woocommerce' ) ) {
113
+		if ( ! current_user_can('manage_woocommerce')) {
114 114
 			return;
115 115
 		}
116 116
 
117 117
 		$environment_warning = $this->get_environment_warning();
118 118
 
119
-		if ( $environment_warning ) {
120
-			$this->add_admin_notice( 'bad_environment', 'error', $environment_warning );
119
+		if ($environment_warning) {
120
+			$this->add_admin_notice('bad_environment', 'error', $environment_warning);
121 121
 		}
122 122
 
123
-		foreach ( (array) $this->notices as $notice_key => $notice ) {
124
-			echo "<div class='" . esc_attr( $notice['class'] ) . "'><p>";
125
-			echo wp_kses( $notice['message'], array( 'a' => array( 'href' => array() ) ) );
123
+		foreach ((array) $this->notices as $notice_key => $notice) {
124
+			echo "<div class='" . esc_attr($notice['class']) . "'><p>";
125
+			echo wp_kses($notice['message'], array('a' => array('href' => array())));
126 126
 			echo '</p></div>';
127 127
 		}
128 128
 	}
@@ -136,12 +136,12 @@  discard block
 block discarded – undo
136 136
 	 */
137 137
 	public function get_environment_warning() {
138 138
 		// Add deprecated notice to logs.
139
-		if ( 'yes' === $this->enabled ) {
140
-			WC_Stripe_Logger::log( 'DEPRECATED! Stripe will no longer support Bitcoin and will cease to function on April 23, 2018. Please plan accordingly.' );
139
+		if ('yes' === $this->enabled) {
140
+			WC_Stripe_Logger::log('DEPRECATED! Stripe will no longer support Bitcoin and will cease to function on April 23, 2018. Please plan accordingly.');
141 141
 		}
142 142
 
143
-		if ( 'yes' === $this->enabled && ! in_array( get_woocommerce_currency(), $this->get_supported_currency() ) ) {
144
-			$message = __( 'Bitcoin is enabled - it requires store currency to be set to USD.', 'woocommerce-gateway-stripe' );
143
+		if ('yes' === $this->enabled && ! in_array(get_woocommerce_currency(), $this->get_supported_currency())) {
144
+			$message = __('Bitcoin is enabled - it requires store currency to be set to USD.', 'woocommerce-gateway-stripe');
145 145
 
146 146
 			return $message;
147 147
 		}
@@ -157,9 +157,9 @@  discard block
 block discarded – undo
157 157
 	 * @return array
158 158
 	 */
159 159
 	public function get_supported_currency() {
160
-		return apply_filters( 'wc_stripe_bitcoin_supported_currencies', array(
160
+		return apply_filters('wc_stripe_bitcoin_supported_currencies', array(
161 161
 			'USD',
162
-		) );
162
+		));
163 163
 	}
164 164
 
165 165
 	/**
@@ -170,7 +170,7 @@  discard block
 block discarded – undo
170 170
 	 * @return bool
171 171
 	 */
172 172
 	public function is_available() {
173
-		if ( ! in_array( get_woocommerce_currency(), $this->get_supported_currency() ) ) {
173
+		if ( ! in_array(get_woocommerce_currency(), $this->get_supported_currency())) {
174 174
 			return false;
175 175
 		}
176 176
 
@@ -191,7 +191,7 @@  discard block
 block discarded – undo
191 191
 
192 192
 		$icons_str .= $icons['bitcoin'];
193 193
 
194
-		return apply_filters( 'woocommerce_gateway_icon', $icons_str, $this->id );
194
+		return apply_filters('woocommerce_gateway_icon', $icons_str, $this->id);
195 195
 	}
196 196
 
197 197
 	/**
@@ -202,19 +202,19 @@  discard block
 block discarded – undo
202 202
 	 * @access public
203 203
 	 */
204 204
 	public function payment_scripts() {
205
-		if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) && ! is_add_payment_method_page() ) {
205
+		if ( ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order']) && ! is_add_payment_method_page()) {
206 206
 			return;
207 207
 		}
208 208
 
209
-		wp_enqueue_style( 'stripe_paymentfonts' );
210
-		wp_enqueue_script( 'woocommerce_stripe' );
209
+		wp_enqueue_style('stripe_paymentfonts');
210
+		wp_enqueue_script('woocommerce_stripe');
211 211
 	}
212 212
 
213 213
 	/**
214 214
 	 * Initialize Gateway Settings Form Fields.
215 215
 	 */
216 216
 	public function init_form_fields() {
217
-		$this->form_fields = require( WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-bitcoin-settings.php' );
217
+		$this->form_fields = require(WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-bitcoin-settings.php');
218 218
 	}
219 219
 
220 220
 	/**
@@ -225,25 +225,25 @@  discard block
 block discarded – undo
225 225
 		$total                = WC()->cart->total;
226 226
 
227 227
 		// If paying from order, we need to get total from order not cart.
228
-		if ( isset( $_GET['pay_for_order'] ) && ! empty( $_GET['key'] ) ) {
229
-			$order = wc_get_order( wc_get_order_id_by_order_key( wc_clean( $_GET['key'] ) ) );
228
+		if (isset($_GET['pay_for_order']) && ! empty($_GET['key'])) {
229
+			$order = wc_get_order(wc_get_order_id_by_order_key(wc_clean($_GET['key'])));
230 230
 			$total = $order->get_total();
231 231
 		}
232 232
 
233
-		if ( is_add_payment_method_page() ) {
234
-			$pay_button_text = __( 'Add Payment', 'woocommerce-gateway-stripe' );
235
-			$total        = '';
233
+		if (is_add_payment_method_page()) {
234
+			$pay_button_text = __('Add Payment', 'woocommerce-gateway-stripe');
235
+			$total = '';
236 236
 		} else {
237 237
 			$pay_button_text = '';
238 238
 		}
239 239
 
240 240
 		echo '<div
241 241
 			id="stripe-bitcoin-payment-data"
242
-			data-amount="' . esc_attr( WC_Stripe_Helper::get_stripe_amount( $total ) ) . '"
243
-			data-currency="' . esc_attr( strtolower( get_woocommerce_currency() ) ) . '">';
242
+			data-amount="' . esc_attr(WC_Stripe_Helper::get_stripe_amount($total)) . '"
243
+			data-currency="' . esc_attr(strtolower(get_woocommerce_currency())) . '">';
244 244
 
245
-		if ( $this->description ) {
246
-			echo apply_filters( 'wc_stripe_description', wpautop( wp_kses_post( $this->description ) ) );
245
+		if ($this->description) {
246
+			echo apply_filters('wc_stripe_description', wpautop(wp_kses_post($this->description)));
247 247
 		}
248 248
 
249 249
 		echo '</div>';
@@ -254,8 +254,8 @@  discard block
 block discarded – undo
254 254
 	 *
255 255
 	 * @param int $order_id
256 256
 	 */
257
-	public function thankyou_page( $order_id ) {
258
-		$this->get_instructions( $order_id );
257
+	public function thankyou_page($order_id) {
258
+		$this->get_instructions($order_id);
259 259
 	}
260 260
 
261 261
 	/**
@@ -267,13 +267,13 @@  discard block
 block discarded – undo
267 267
 	 * @param bool $sent_to_admin
268 268
 	 * @param bool $plain_text
269 269
 	 */
270
-	public function email_instructions( $order, $sent_to_admin, $plain_text = false ) {
270
+	public function email_instructions($order, $sent_to_admin, $plain_text = false) {
271 271
 		$order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
272 272
 
273 273
 		$payment_method = WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method();
274 274
 
275
-		if ( ! $sent_to_admin && 'stripe_bitcoin' === $payment_method && $order->has_status( 'on-hold' ) ) {
276
-			$this->get_instructions( $order_id, $plain_text );
275
+		if ( ! $sent_to_admin && 'stripe_bitcoin' === $payment_method && $order->has_status('on-hold')) {
276
+			$this->get_instructions($order_id, $plain_text);
277 277
 		}
278 278
 	}
279 279
 
@@ -284,38 +284,38 @@  discard block
 block discarded – undo
284 284
 	 * @version 4.0.0
285 285
 	 * @param int $order_id
286 286
 	 */
287
-	public function get_instructions( $order_id, $plain_text = false ) {
288
-		$data = get_post_meta( $order_id, '_stripe_bitcoin', true );
287
+	public function get_instructions($order_id, $plain_text = false) {
288
+		$data = get_post_meta($order_id, '_stripe_bitcoin', true);
289 289
 
290
-		if ( $plain_text ) {
291
-			esc_html_e( 'Please pay the following:', 'woocommerce-gateway-stripe' ) . "\n\n";
290
+		if ($plain_text) {
291
+			esc_html_e('Please pay the following:', 'woocommerce-gateway-stripe') . "\n\n";
292 292
 			echo "=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\n\n";
293
-			esc_html_e( 'Bitcoin Amount:', 'woocommerce-gateway-stripe' ) . "\n\n";
293
+			esc_html_e('Bitcoin Amount:', 'woocommerce-gateway-stripe') . "\n\n";
294 294
 			echo $data['amount'] . "\n\n";
295 295
 			echo "=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\n\n";
296
-			esc_html_e( 'Receiver:', 'woocommerce-gateway-stripe' ) . "\n\n";
296
+			esc_html_e('Receiver:', 'woocommerce-gateway-stripe') . "\n\n";
297 297
 			echo $data['address'] . "\n\n";
298 298
 			echo "=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\n\n";
299
-			esc_html_e( 'URI:', 'woocommerce-gateway-stripe' ) . "\n\n";
299
+			esc_html_e('URI:', 'woocommerce-gateway-stripe') . "\n\n";
300 300
 			echo $data['uri'] . "\n\n";
301 301
 		} else {
302 302
 			?>
303
-			<h3><?php esc_html_e( 'Please pay the following:', 'woocommerce-gateway-stripe' ); ?></h3>
303
+			<h3><?php esc_html_e('Please pay the following:', 'woocommerce-gateway-stripe'); ?></h3>
304 304
 			<ul class="woocommerce-order-overview woocommerce-thankyou-order-details order_details">
305 305
 			<li class="woocommerce-order-overview__order order">
306
-				<?php esc_html_e( 'Bitcoin Amount:', 'woocommerce-gateway-stripe' ); ?>
306
+				<?php esc_html_e('Bitcoin Amount:', 'woocommerce-gateway-stripe'); ?>
307 307
 				<strong><?php echo $data['amount']; ?></strong>
308 308
 			</li>
309 309
 			<li class="woocommerce-order-overview__order order">
310
-				<?php esc_html_e( 'Receiver:', 'woocommerce-gateway-stripe' ); ?>
310
+				<?php esc_html_e('Receiver:', 'woocommerce-gateway-stripe'); ?>
311 311
 				<strong><?php echo $data['address']; ?></strong>
312 312
 			</li>
313 313
 			<li class="woocommerce-order-overview__order order">
314
-				<?php esc_html_e( 'URI:', 'woocommerce-gateway-stripe' ); ?>
314
+				<?php esc_html_e('URI:', 'woocommerce-gateway-stripe'); ?>
315 315
 				<strong>
316 316
 				<?php
317 317
 				/* translators: link */
318
-				printf( __( '<a href="%s">Pay Bitcoin</a>', 'woocommerce-gateway-stripe' ), $data['uri'] );
318
+				printf(__('<a href="%s">Pay Bitcoin</a>', 'woocommerce-gateway-stripe'), $data['uri']);
319 319
 				?>
320 320
 				</strong>
321 321
 			</li>
@@ -332,7 +332,7 @@  discard block
 block discarded – undo
332 332
 	 * @param object $order
333 333
 	 * @param object $source_object
334 334
 	 */
335
-	public function save_instructions( $order, $source_object ) {
335
+	public function save_instructions($order, $source_object) {
336 336
 		$data = array(
337 337
 			'amount'  => $source_object->bitcoin->amount,
338 338
 			'address' => $source_object->bitcoin->address,
@@ -341,7 +341,7 @@  discard block
 block discarded – undo
341 341
 
342 342
 		$order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
343 343
 
344
-		update_post_meta( $order_id, '_stripe_bitcoin', $data );
344
+		update_post_meta($order_id, '_stripe_bitcoin', $data);
345 345
 	}
346 346
 
347 347
 	/**
@@ -355,37 +355,37 @@  discard block
 block discarded – undo
355 355
 	 *
356 356
 	 * @return array|void
357 357
 	 */
358
-	public function process_payment( $order_id, $retry = true, $force_save_source = false ) {
358
+	public function process_payment($order_id, $retry = true, $force_save_source = false) {
359 359
 		try {
360
-			$order = wc_get_order( $order_id );
360
+			$order = wc_get_order($order_id);
361 361
 
362 362
 			// This comes from the create account checkbox in the checkout page.
363
-			$create_account = ! empty( $_POST['createaccount'] ) ? true : false;
363
+			$create_account = ! empty($_POST['createaccount']) ? true : false;
364 364
 
365
-			if ( $create_account ) {
365
+			if ($create_account) {
366 366
 				$new_customer_id     = WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id();
367
-				$new_stripe_customer = new WC_Stripe_Customer( $new_customer_id );
367
+				$new_stripe_customer = new WC_Stripe_Customer($new_customer_id);
368 368
 				$new_stripe_customer->create_customer();
369 369
 			}
370 370
 
371
-			$prepared_source = $this->prepare_source( get_current_user_id(), $force_save_source );
371
+			$prepared_source = $this->prepare_source(get_current_user_id(), $force_save_source);
372 372
 
373
-			if ( empty( $prepared_source->source ) ) {
374
-				$localized_message = __( 'Payment processing failed. Please retry.', 'woocommerce-gateway-stripe' );
375
-				throw new WC_Stripe_Exception( print_r( $prepared_source, true ), $localized_message );
373
+			if (empty($prepared_source->source)) {
374
+				$localized_message = __('Payment processing failed. Please retry.', 'woocommerce-gateway-stripe');
375
+				throw new WC_Stripe_Exception(print_r($prepared_source, true), $localized_message);
376 376
 			}
377 377
 
378
-			$this->save_source_to_order( $order, $prepared_source );
378
+			$this->save_source_to_order($order, $prepared_source);
379 379
 
380 380
 			// This will throw exception if not valid.
381
-			$this->validate_minimum_order_amount( $order );
381
+			$this->validate_minimum_order_amount($order);
382 382
 
383
-			$this->save_instructions( $order, $this->get_source_object( $prepared_source->source ) );
383
+			$this->save_instructions($order, $this->get_source_object($prepared_source->source));
384 384
 
385 385
 			// Mark as on-hold (we're awaiting the payment).
386
-			$order->update_status( 'on-hold', __( 'Awaiting Bitcoin payment', 'woocommerce-gateway-stripe' ) );
386
+			$order->update_status('on-hold', __('Awaiting Bitcoin payment', 'woocommerce-gateway-stripe'));
387 387
 
388
-			wc_reduce_stock_levels( $order_id );
388
+			wc_reduce_stock_levels($order_id);
389 389
 
390 390
 			// Remove cart.
391 391
 			WC()->cart->empty_cart();
@@ -393,16 +393,16 @@  discard block
 block discarded – undo
393 393
 			// Return thankyou redirect.
394 394
 			return array(
395 395
 				'result'    => 'success',
396
-				'redirect'  => $this->get_return_url( $order ),
396
+				'redirect'  => $this->get_return_url($order),
397 397
 			);
398
-		} catch ( WC_Stripe_Exception $e ) {
399
-			wc_add_notice( $e->getLocalizedMessage(), 'error' );
400
-			WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() );
398
+		} catch (WC_Stripe_Exception $e) {
399
+			wc_add_notice($e->getLocalizedMessage(), 'error');
400
+			WC_Stripe_Logger::log('Error: ' . $e->getMessage());
401 401
 
402
-			do_action( 'wc_gateway_stripe_process_payment_error', $e, $order );
402
+			do_action('wc_gateway_stripe_process_payment_error', $e, $order);
403 403
 
404
-			if ( $order->has_status( array( 'pending', 'failed' ) ) ) {
405
-				$this->send_failed_order_email( $order_id );
404
+			if ($order->has_status(array('pending', 'failed'))) {
405
+				$this->send_failed_order_email($order_id);
406 406
 			}
407 407
 
408 408
 			return array(
Please login to merge, or discard this patch.
includes/payment-methods/class-wc-gateway-stripe-sepa.php 1 patch
Spacing   +102 added lines, -102 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) {
2
+if ( ! defined('ABSPATH')) {
3 3
 	exit;
4 4
 }
5 5
 
@@ -57,9 +57,9 @@  discard block
 block discarded – undo
57 57
 	 */
58 58
 	public function __construct() {
59 59
 		$this->id                   = 'stripe_sepa';
60
-		$this->method_title         = __( 'Stripe SEPA Direct Debit', 'woocommerce-gateway-stripe' );
60
+		$this->method_title         = __('Stripe SEPA Direct Debit', 'woocommerce-gateway-stripe');
61 61
 		/* translators: link */
62
-		$this->method_description   = sprintf( __( 'All other general Stripe settings can be adjusted <a href="%s">here</a>.', 'woocommerce-gateway-stripe' ), admin_url( 'admin.php?page=wc-settings&tab=checkout&section=stripe' ) );
62
+		$this->method_description   = sprintf(__('All other general Stripe settings can be adjusted <a href="%s">here</a>.', 'woocommerce-gateway-stripe'), admin_url('admin.php?page=wc-settings&tab=checkout&section=stripe'));
63 63
 		$this->supports             = array(
64 64
 			'products',
65 65
 			'refunds',
@@ -84,25 +84,25 @@  discard block
 block discarded – undo
84 84
 		// Load the settings.
85 85
 		$this->init_settings();
86 86
 
87
-		$main_settings              = get_option( 'woocommerce_stripe_settings' );
88
-		$this->title                = $this->get_option( 'title' );
89
-		$this->description          = $this->get_option( 'description' );
90
-		$this->enabled              = $this->get_option( 'enabled' );
91
-		$this->testmode             = ( ! empty( $main_settings['testmode'] ) && 'yes' === $main_settings['testmode'] ) ? true : false;
92
-		$this->saved_cards          = ( ! empty( $main_settings['saved_cards'] ) && 'yes' === $main_settings['saved_cards'] ) ? true : false;
93
-		$this->publishable_key      = ! empty( $main_settings['publishable_key'] ) ? $main_settings['publishable_key'] : '';
94
-		$this->secret_key           = ! empty( $main_settings['secret_key'] ) ? $main_settings['secret_key'] : '';
95
-		$this->statement_descriptor = ! empty( $main_settings['statement_descriptor'] ) ? $main_settings['statement_descriptor'] : '';
96
-
97
-		if ( $this->testmode ) {
98
-			$this->publishable_key = ! empty( $main_settings['test_publishable_key'] ) ? $main_settings['test_publishable_key'] : '';
99
-			$this->secret_key      = ! empty( $main_settings['test_secret_key'] ) ? $main_settings['test_secret_key'] : '';
87
+		$main_settings              = get_option('woocommerce_stripe_settings');
88
+		$this->title                = $this->get_option('title');
89
+		$this->description          = $this->get_option('description');
90
+		$this->enabled              = $this->get_option('enabled');
91
+		$this->testmode             = ( ! empty($main_settings['testmode']) && 'yes' === $main_settings['testmode']) ? true : false;
92
+		$this->saved_cards          = ( ! empty($main_settings['saved_cards']) && 'yes' === $main_settings['saved_cards']) ? true : false;
93
+		$this->publishable_key      = ! empty($main_settings['publishable_key']) ? $main_settings['publishable_key'] : '';
94
+		$this->secret_key           = ! empty($main_settings['secret_key']) ? $main_settings['secret_key'] : '';
95
+		$this->statement_descriptor = ! empty($main_settings['statement_descriptor']) ? $main_settings['statement_descriptor'] : '';
96
+
97
+		if ($this->testmode) {
98
+			$this->publishable_key = ! empty($main_settings['test_publishable_key']) ? $main_settings['test_publishable_key'] : '';
99
+			$this->secret_key      = ! empty($main_settings['test_secret_key']) ? $main_settings['test_secret_key'] : '';
100 100
 		}
101 101
 
102
-		add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) );
103
-		add_action( 'admin_notices', array( $this, 'check_environment' ) );
104
-		add_action( 'admin_head', array( $this, 'remove_admin_notice' ) );
105
-		add_action( 'wp_enqueue_scripts', array( $this, 'payment_scripts' ) );
102
+		add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options'));
103
+		add_action('admin_notices', array($this, 'check_environment'));
104
+		add_action('admin_head', array($this, 'remove_admin_notice'));
105
+		add_action('wp_enqueue_scripts', array($this, 'payment_scripts'));
106 106
 	}
107 107
 
108 108
 	/**
@@ -112,19 +112,19 @@  discard block
 block discarded – undo
112 112
 	 * @version 4.0.0
113 113
 	 */
114 114
 	public function check_environment() {
115
-		if ( ! current_user_can( 'manage_woocommerce' ) ) {
115
+		if ( ! current_user_can('manage_woocommerce')) {
116 116
 			return;
117 117
 		}
118 118
 
119 119
 		$environment_warning = $this->get_environment_warning();
120 120
 
121
-		if ( $environment_warning ) {
122
-			$this->add_admin_notice( 'bad_environment', 'error', $environment_warning );
121
+		if ($environment_warning) {
122
+			$this->add_admin_notice('bad_environment', 'error', $environment_warning);
123 123
 		}
124 124
 
125
-		foreach ( (array) $this->notices as $notice_key => $notice ) {
126
-			echo "<div class='" . esc_attr( $notice['class'] ) . "'><p>";
127
-			echo wp_kses( $notice['message'], array( 'a' => array( 'href' => array() ) ) );
125
+		foreach ((array) $this->notices as $notice_key => $notice) {
126
+			echo "<div class='" . esc_attr($notice['class']) . "'><p>";
127
+			echo wp_kses($notice['message'], array('a' => array('href' => array())));
128 128
 			echo '</p></div>';
129 129
 		}
130 130
 	}
@@ -137,8 +137,8 @@  discard block
 block discarded – undo
137 137
 	 * @version 4.0.0
138 138
 	 */
139 139
 	public function get_environment_warning() {
140
-		if ( 'yes' === $this->enabled && ! in_array( get_woocommerce_currency(), $this->get_supported_currency() ) ) {
141
-			$message = __( 'SEPA is enabled - it requires store currency to be set to Euros.', 'woocommerce-gateway-stripe' );
140
+		if ('yes' === $this->enabled && ! in_array(get_woocommerce_currency(), $this->get_supported_currency())) {
141
+			$message = __('SEPA is enabled - it requires store currency to be set to Euros.', 'woocommerce-gateway-stripe');
142 142
 
143 143
 			return $message;
144 144
 		}
@@ -154,9 +154,9 @@  discard block
 block discarded – undo
154 154
 	 * @return array
155 155
 	 */
156 156
 	public function get_supported_currency() {
157
-		return apply_filters( 'wc_stripe_sepa_supported_currencies', array(
157
+		return apply_filters('wc_stripe_sepa_supported_currencies', array(
158 158
 			'EUR',
159
-		) );
159
+		));
160 160
 	}
161 161
 
162 162
 	/**
@@ -167,11 +167,11 @@  discard block
 block discarded – undo
167 167
 	 * @return bool
168 168
 	 */
169 169
 	public function is_available() {
170
-		if ( ! in_array( get_woocommerce_currency(), $this->get_supported_currency() ) ) {
170
+		if ( ! in_array(get_woocommerce_currency(), $this->get_supported_currency())) {
171 171
 			return false;
172 172
 		}
173 173
 
174
-		if ( is_add_payment_method_page() && ! $this->saved_cards ) {
174
+		if (is_add_payment_method_page() && ! $this->saved_cards) {
175 175
 			return false;
176 176
 		}
177 177
 
@@ -192,7 +192,7 @@  discard block
 block discarded – undo
192 192
 
193 193
 		$icons_str .= $icons['sepa'];
194 194
 
195
-		return apply_filters( 'woocommerce_gateway_icon', $icons_str, $this->id );
195
+		return apply_filters('woocommerce_gateway_icon', $icons_str, $this->id);
196 196
 	}
197 197
 
198 198
 	/**
@@ -203,19 +203,19 @@  discard block
 block discarded – undo
203 203
 	 * @access public
204 204
 	 */
205 205
 	public function payment_scripts() {
206
-		if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) && ! is_add_payment_method_page() ) {
206
+		if ( ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order']) && ! is_add_payment_method_page()) {
207 207
 			return;
208 208
 		}
209 209
 
210
-		wp_enqueue_style( 'stripe_paymentfonts' );
211
-		wp_enqueue_script( 'woocommerce_stripe' );
210
+		wp_enqueue_style('stripe_paymentfonts');
211
+		wp_enqueue_script('woocommerce_stripe');
212 212
 	}
213 213
 
214 214
 	/**
215 215
 	 * Initialize Gateway Settings Form Fields.
216 216
 	 */
217 217
 	public function init_form_fields() {
218
-		$this->form_fields = require( WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-sepa-settings.php' );
218
+		$this->form_fields = require(WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-sepa-settings.php');
219 219
 	}
220 220
 
221 221
 	/**
@@ -227,7 +227,7 @@  discard block
 block discarded – undo
227 227
 	 */
228 228
 	public function mandate_display() {
229 229
 		/* translators: statement descriptor */
230
-		printf( __( 'By providing your IBAN and confirming this payment, you are authorizing %s and Stripe, our payment service provider, to send instructions to your bank to debit your account and your bank to debit your account in accordance with those instructions. You are entitled to a refund from your bank under the terms and conditions of your agreement with your bank. A refund must be claimed within 8 weeks starting from the date on which your account was debited.', 'woocommerce-gateway-stripe' ), WC_Stripe_Helper::clean_statement_descriptor( $this->statement_descriptor ) );
230
+		printf(__('By providing your IBAN and confirming this payment, you are authorizing %s and Stripe, our payment service provider, to send instructions to your bank to debit your account and your bank to debit your account in accordance with those instructions. You are entitled to a refund from your bank under the terms and conditions of your agreement with your bank. A refund must be claimed within 8 weeks starting from the date on which your account was debited.', 'woocommerce-gateway-stripe'), WC_Stripe_Helper::clean_statement_descriptor($this->statement_descriptor));
231 231
 	}
232 232
 
233 233
 	/**
@@ -238,24 +238,24 @@  discard block
 block discarded – undo
238 238
 	 */
239 239
 	public function form() {
240 240
 		?>
241
-		<fieldset id="wc-<?php echo esc_attr( $this->id ); ?>-form" class="wc-payment-form">
242
-			<?php do_action( 'woocommerce_credit_card_form_start', $this->id ); ?>
241
+		<fieldset id="wc-<?php echo esc_attr($this->id); ?>-form" class="wc-payment-form">
242
+			<?php do_action('woocommerce_credit_card_form_start', $this->id); ?>
243 243
 			<p class="wc-stripe-sepa-mandate" style="margin-bottom:40px;"><?php $this->mandate_display(); ?></p>
244 244
 			<p class="form-row form-row-wide">
245 245
 				<label for="stripe-sepa-owner">
246
-					<?php esc_html_e( 'IBAN Account Name.', 'woocommerce-gateway-stripe' ); ?> <span class="required">*</span>
246
+					<?php esc_html_e('IBAN Account Name.', 'woocommerce-gateway-stripe'); ?> <span class="required">*</span>
247 247
 				</label>
248 248
 				<input id="stripe-sepa-owner" name="stripe_sepa_owner" value="" style="border:1px solid #ddd;margin:5px 0;padding:10px 5px;background-color:#fff;outline:0;" />
249 249
 			</p>
250 250
 			<p class="form-row form-row-wide">
251 251
 				<label for="stripe-sepa-iban">
252
-					<?php esc_html_e( 'IBAN Account Number.', 'woocommerce-gateway-stripe' ); ?> <span class="required">*</span>
252
+					<?php esc_html_e('IBAN Account Number.', 'woocommerce-gateway-stripe'); ?> <span class="required">*</span>
253 253
 				</label>
254 254
 				<input id="stripe-sepa-iban" name="stripe_sepa_iban" value="" style="border:1px solid #ddd;margin:5px 0;padding:10px 5px;background-color:#fff;outline:0;" />
255 255
 			</p>
256 256
 			<!-- Used to display form errors -->
257 257
 			<div class="stripe-source-errors" role="alert"></div>
258
-			<?php do_action( 'woocommerce_credit_card_form_end', $this->id ); ?>
258
+			<?php do_action('woocommerce_credit_card_form_end', $this->id); ?>
259 259
 			<div class="clear"></div>
260 260
 		</fieldset>
261 261
 		<?php
@@ -267,42 +267,42 @@  discard block
 block discarded – undo
267 267
 	public function payment_fields() {
268 268
 		$user                 = wp_get_current_user();
269 269
 		$total                = WC()->cart->total;
270
-		$display_tokenization = $this->supports( 'tokenization' ) && is_checkout() && $this->saved_cards;
270
+		$display_tokenization = $this->supports('tokenization') && is_checkout() && $this->saved_cards;
271 271
 
272 272
 		// If paying from order, we need to get total from order not cart.
273
-		if ( isset( $_GET['pay_for_order'] ) && ! empty( $_GET['key'] ) ) {
274
-			$order = wc_get_order( wc_get_order_id_by_order_key( wc_clean( $_GET['key'] ) ) );
273
+		if (isset($_GET['pay_for_order']) && ! empty($_GET['key'])) {
274
+			$order = wc_get_order(wc_get_order_id_by_order_key(wc_clean($_GET['key'])));
275 275
 			$total = $order->get_total();
276 276
 		}
277 277
 
278
-		if ( is_add_payment_method_page() ) {
279
-			$pay_button_text = __( 'Add Payment', 'woocommerce-gateway-stripe' );
280
-			$total        = '';
278
+		if (is_add_payment_method_page()) {
279
+			$pay_button_text = __('Add Payment', 'woocommerce-gateway-stripe');
280
+			$total = '';
281 281
 		} else {
282 282
 			$pay_button_text = '';
283 283
 		}
284 284
 
285 285
 		echo '<div
286 286
 			id="stripe-sepa_debit-payment-data"
287
-			data-amount="' . esc_attr( WC_Stripe_Helper::get_stripe_amount( $total ) ) . '"
288
-			data-currency="' . esc_attr( strtolower( get_woocommerce_currency() ) ) . '">';
287
+			data-amount="' . esc_attr(WC_Stripe_Helper::get_stripe_amount($total)) . '"
288
+			data-currency="' . esc_attr(strtolower(get_woocommerce_currency())) . '">';
289 289
 
290
-		if ( $this->description ) {
291
-			if ( $this->testmode ) {
292
-				$this->description .= ' ' . __( 'TEST MODE ENABLED. In test mode, you can use IBAN number DE89370400440532013000.', 'woocommerce-gateway-stripe' );
293
-				$this->description  = trim( $this->description );
290
+		if ($this->description) {
291
+			if ($this->testmode) {
292
+				$this->description .= ' ' . __('TEST MODE ENABLED. In test mode, you can use IBAN number DE89370400440532013000.', 'woocommerce-gateway-stripe');
293
+				$this->description  = trim($this->description);
294 294
 			}
295
-			echo apply_filters( 'wc_stripe_description', wpautop( wp_kses_post( $this->description ) ) );
295
+			echo apply_filters('wc_stripe_description', wpautop(wp_kses_post($this->description)));
296 296
 		}
297 297
 
298
-		if ( $display_tokenization ) {
298
+		if ($display_tokenization) {
299 299
 			$this->tokenization_script();
300 300
 			$this->saved_payment_methods();
301 301
 		}
302 302
 
303 303
 		$this->form();
304 304
 
305
-		if ( apply_filters( 'wc_stripe_display_save_payment_method_checkbox', $display_tokenization ) && ! is_add_payment_method_page() && ! isset( $_GET['change_payment_method'] ) ) {
305
+		if (apply_filters('wc_stripe_display_save_payment_method_checkbox', $display_tokenization) && ! is_add_payment_method_page() && ! isset($_GET['change_payment_method'])) {
306 306
 			$this->save_payment_method_checkbox();
307 307
 		}
308 308
 
@@ -320,86 +320,86 @@  discard block
 block discarded – undo
320 320
 	 *
321 321
 	 * @return array|void
322 322
 	 */
323
-	public function process_payment( $order_id, $retry = true, $force_save_source = false ) {
323
+	public function process_payment($order_id, $retry = true, $force_save_source = false) {
324 324
 		try {
325
-			$order = wc_get_order( $order_id );
325
+			$order = wc_get_order($order_id);
326 326
 
327 327
 			// This comes from the create account checkbox in the checkout page.
328
-			$create_account = ! empty( $_POST['createaccount'] ) ? true : false;
328
+			$create_account = ! empty($_POST['createaccount']) ? true : false;
329 329
 
330
-			if ( $create_account ) {
330
+			if ($create_account) {
331 331
 				$new_customer_id     = WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id();
332
-				$new_stripe_customer = new WC_Stripe_Customer( $new_customer_id );
332
+				$new_stripe_customer = new WC_Stripe_Customer($new_customer_id);
333 333
 				$new_stripe_customer->create_customer();
334 334
 			}
335 335
 
336
-			$prepared_source = $this->prepare_source( get_current_user_id(), $force_save_source );
336
+			$prepared_source = $this->prepare_source(get_current_user_id(), $force_save_source);
337 337
 
338
-			$this->save_source_to_order( $order, $prepared_source );
338
+			$this->save_source_to_order($order, $prepared_source);
339 339
 
340 340
 			// Result from Stripe API request.
341 341
 			$response = null;
342 342
 
343
-			if ( $order->get_total() > 0 ) {
343
+			if ($order->get_total() > 0) {
344 344
 				// This will throw exception if not valid.
345
-				$this->validate_minimum_order_amount( $order );
345
+				$this->validate_minimum_order_amount($order);
346 346
 
347
-				WC_Stripe_Logger::log( "Info: Begin processing payment for order $order_id for the amount of {$order->get_total()}" );
347
+				WC_Stripe_Logger::log("Info: Begin processing payment for order $order_id for the amount of {$order->get_total()}");
348 348
 
349 349
 				// Make the request.
350
-				$response = WC_Stripe_API::request( $this->generate_payment_request( $order, $prepared_source ) );
350
+				$response = WC_Stripe_API::request($this->generate_payment_request($order, $prepared_source));
351 351
 
352
-				if ( ! empty( $response->error ) ) {
352
+				if ( ! empty($response->error)) {
353 353
 					// If it is an API error such connection or server, let's retry.
354
-					if ( 'api_connection_error' === $response->error->type || 'api_error' === $response->error->type ) {
355
-						if ( $retry ) {
356
-							sleep( 5 );
357
-							return $this->process_payment( $order_id, false, $force_save_source );
354
+					if ('api_connection_error' === $response->error->type || 'api_error' === $response->error->type) {
355
+						if ($retry) {
356
+							sleep(5);
357
+							return $this->process_payment($order_id, false, $force_save_source);
358 358
 						} else {
359 359
 							$localized_message = 'API connection error and retries exhausted.';
360
-							$order->add_order_note( $localized_message );
361
-							throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message );
360
+							$order->add_order_note($localized_message);
361
+							throw new WC_Stripe_Exception(print_r($response, true), $localized_message);
362 362
 						}
363 363
 					}
364 364
 
365 365
 					// Customer param wrong? The user may have been deleted on stripe's end. Remove customer_id. Can be retried without.
366
-					if ( preg_match( '/No such customer/i', $response->error->message ) && $retry ) {
367
-						if ( WC_Stripe_Helper::is_pre_30() ) {
368
-							delete_user_meta( $order->customer_user, '_stripe_customer_id' );
369
-							delete_post_meta( $order_id, '_stripe_customer_id' );
366
+					if (preg_match('/No such customer/i', $response->error->message) && $retry) {
367
+						if (WC_Stripe_Helper::is_pre_30()) {
368
+							delete_user_meta($order->customer_user, '_stripe_customer_id');
369
+							delete_post_meta($order_id, '_stripe_customer_id');
370 370
 						} else {
371
-							delete_user_meta( $order->get_customer_id(), '_stripe_customer_id' );
372
-							$order->delete_meta_data( '_stripe_customer_id' );
371
+							delete_user_meta($order->get_customer_id(), '_stripe_customer_id');
372
+							$order->delete_meta_data('_stripe_customer_id');
373 373
 							$order->save();
374 374
 						}
375 375
 
376
-						return $this->process_payment( $order_id, false, $force_save_source );
377
-					} elseif ( preg_match( '/No such token/i', $response->error->message ) && $prepared_source->token_id ) {
376
+						return $this->process_payment($order_id, false, $force_save_source);
377
+					} elseif (preg_match('/No such token/i', $response->error->message) && $prepared_source->token_id) {
378 378
 						// Source param wrong? The CARD may have been deleted on stripe's end. Remove token and show message.
379
-						$wc_token = WC_Payment_Tokens::get( $prepared_source->token_id );
379
+						$wc_token = WC_Payment_Tokens::get($prepared_source->token_id);
380 380
 						$wc_token->delete();
381
-						$localized_message = __( 'This card is no longer available and has been removed.', 'woocommerce-gateway-stripe' );
382
-						$order->add_order_note( $localized_message );
383
-						throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message );
381
+						$localized_message = __('This card is no longer available and has been removed.', 'woocommerce-gateway-stripe');
382
+						$order->add_order_note($localized_message);
383
+						throw new WC_Stripe_Exception(print_r($response, true), $localized_message);
384 384
 					}
385 385
 
386 386
 					$localized_messages = WC_Stripe_Helper::get_localized_messages();
387 387
 
388
-					if ( 'card_error' === $response->error->type ) {
389
-						$localized_message = isset( $localized_messages[ $response->error->code ] ) ? $localized_messages[ $response->error->code ] : $response->error->message;
388
+					if ('card_error' === $response->error->type) {
389
+						$localized_message = isset($localized_messages[$response->error->code]) ? $localized_messages[$response->error->code] : $response->error->message;
390 390
 					} else {
391
-						$localized_message = isset( $localized_messages[ $response->error->type ] ) ? $localized_messages[ $response->error->type ] : $response->error->message;
391
+						$localized_message = isset($localized_messages[$response->error->type]) ? $localized_messages[$response->error->type] : $response->error->message;
392 392
 					}
393 393
 
394
-					$order->add_order_note( $localized_message );
394
+					$order->add_order_note($localized_message);
395 395
 
396
-					throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message );
396
+					throw new WC_Stripe_Exception(print_r($response, true), $localized_message);
397 397
 				}
398 398
 
399
-				do_action( 'wc_gateway_stripe_process_payment', $response, $order );
399
+				do_action('wc_gateway_stripe_process_payment', $response, $order);
400 400
 
401 401
 				// Process valid response.
402
-				$this->process_response( $response, $order );
402
+				$this->process_response($response, $order);
403 403
 			} else {
404 404
 				$order->payment_complete();
405 405
 			}
@@ -410,17 +410,17 @@  discard block
 block discarded – undo
410 410
 			// Return thank you page redirect.
411 411
 			return array(
412 412
 				'result'   => 'success',
413
-				'redirect' => $this->get_return_url( $order ),
413
+				'redirect' => $this->get_return_url($order),
414 414
 			);
415 415
 
416
-		} catch ( WC_Stripe_Exception $e ) {
417
-			wc_add_notice( $e->getLocalizedMessage(), 'error' );
418
-			WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() );
416
+		} catch (WC_Stripe_Exception $e) {
417
+			wc_add_notice($e->getLocalizedMessage(), 'error');
418
+			WC_Stripe_Logger::log('Error: ' . $e->getMessage());
419 419
 
420
-			do_action( 'wc_gateway_stripe_process_payment_error', $e, $order );
420
+			do_action('wc_gateway_stripe_process_payment_error', $e, $order);
421 421
 
422
-			if ( $order->has_status( array( 'pending', 'failed' ) ) ) {
423
-				$this->send_failed_order_email( $order_id );
422
+			if ($order->has_status(array('pending', 'failed'))) {
423
+				$this->send_failed_order_email($order_id);
424 424
 			}
425 425
 
426 426
 			return array(
Please login to merge, or discard this patch.
includes/class-wc-stripe-order-handler.php 1 patch
Spacing   +173 added lines, -173 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) {
2
+if ( ! defined('ABSPATH')) {
3 3
 	exit;
4 4
 }
5 5
 
@@ -23,12 +23,12 @@  discard block
 block discarded – undo
23 23
 
24 24
 		$this->retry_interval = 1;
25 25
 
26
-		add_action( 'wp', array( $this, 'maybe_process_redirect_order' ) );
27
-		add_action( 'woocommerce_order_status_on-hold_to_processing', array( $this, 'capture_payment' ) );
28
-		add_action( 'woocommerce_order_status_on-hold_to_completed', array( $this, 'capture_payment' ) );
29
-		add_action( 'woocommerce_order_status_on-hold_to_cancelled', array( $this, 'cancel_payment' ) );
30
-		add_action( 'woocommerce_order_status_on-hold_to_refunded', array( $this, 'cancel_payment' ) );
31
-		add_action( 'wc_ajax_wc_stripe_validate_checkout', array( $this, 'validate_checkout' ) );
26
+		add_action('wp', array($this, 'maybe_process_redirect_order'));
27
+		add_action('woocommerce_order_status_on-hold_to_processing', array($this, 'capture_payment'));
28
+		add_action('woocommerce_order_status_on-hold_to_completed', array($this, 'capture_payment'));
29
+		add_action('woocommerce_order_status_on-hold_to_cancelled', array($this, 'cancel_payment'));
30
+		add_action('woocommerce_order_status_on-hold_to_refunded', array($this, 'cancel_payment'));
31
+		add_action('wc_ajax_wc_stripe_validate_checkout', array($this, 'validate_checkout'));
32 32
 	}
33 33
 
34 34
 	/**
@@ -49,25 +49,25 @@  discard block
 block discarded – undo
49 49
 	 * @since 4.0.0
50 50
 	 * @version 4.0.0
51 51
 	 */
52
-	public function process_redirect_payment( $order_id, $retry = true ) {
52
+	public function process_redirect_payment($order_id, $retry = true) {
53 53
 		try {
54
-			$source = wc_clean( $_GET['source'] );
54
+			$source = wc_clean($_GET['source']);
55 55
 
56
-			if ( empty( $source ) ) {
56
+			if (empty($source)) {
57 57
 				return;
58 58
 			}
59 59
 
60
-			if ( empty( $order_id ) ) {
60
+			if (empty($order_id)) {
61 61
 				return;
62 62
 			}
63 63
 
64
-			$order = wc_get_order( $order_id );
64
+			$order = wc_get_order($order_id);
65 65
 
66
-			if ( ! is_object( $order ) ) {
66
+			if ( ! is_object($order)) {
67 67
 				return;
68 68
 			}
69 69
 
70
-			if ( 'processing' === $order->get_status() || 'completed' === $order->get_status() || 'on-hold' === $order->get_status() ) {
70
+			if ('processing' === $order->get_status() || 'completed' === $order->get_status() || 'on-hold' === $order->get_status()) {
71 71
 				return;
72 72
 			}
73 73
 
@@ -75,134 +75,134 @@  discard block
 block discarded – undo
75 75
 			$response = null;
76 76
 
77 77
 			// This will throw exception if not valid.
78
-			$this->validate_minimum_order_amount( $order );
78
+			$this->validate_minimum_order_amount($order);
79 79
 
80
-			WC_Stripe_Logger::log( "Info: (Redirect) Begin processing payment for order $order_id for the amount of {$order->get_total()}" );
80
+			WC_Stripe_Logger::log("Info: (Redirect) Begin processing payment for order $order_id for the amount of {$order->get_total()}");
81 81
 
82 82
 			/**
83 83
 			 * First check if the source is chargeable at this time. If not,
84 84
 			 * webhook will take care of it later.
85 85
 			 */
86
-			$source_info = WC_Stripe_API::retrieve( 'sources/' . $source );
86
+			$source_info = WC_Stripe_API::retrieve('sources/' . $source);
87 87
 
88
-			if ( ! empty( $source_info->error ) ) {
89
-				throw new WC_Stripe_Exception( print_r( $source_info, true ), $source_info->error->message );
88
+			if ( ! empty($source_info->error)) {
89
+				throw new WC_Stripe_Exception(print_r($source_info, true), $source_info->error->message);
90 90
 			}
91 91
 
92
-			if ( 'failed' === $source_info->status || 'canceled' === $source_info->status ) {
93
-				throw new WC_Stripe_Exception( print_r( $source_info, true ), __( 'Unable to process this payment, please try again or use alternative method.', 'woocommerce-gateway-stripe' ) );
92
+			if ('failed' === $source_info->status || 'canceled' === $source_info->status) {
93
+				throw new WC_Stripe_Exception(print_r($source_info, true), __('Unable to process this payment, please try again or use alternative method.', 'woocommerce-gateway-stripe'));
94 94
 			}
95 95
 
96 96
 			// If already consumed, then ignore request.
97
-			if ( 'consumed' === $source_info->status ) {
97
+			if ('consumed' === $source_info->status) {
98 98
 				return;
99 99
 			}
100 100
 
101 101
 			// If not chargeable, then ignore request.
102
-			if ( 'chargeable' !== $source_info->status ) {
102
+			if ('chargeable' !== $source_info->status) {
103 103
 				return;
104 104
 			}
105 105
 
106 106
 			// Prep source object.
107 107
 			$source_object           = new stdClass();
108 108
 			$source_object->token_id = '';
109
-			$source_object->customer = $this->get_stripe_customer_id( $order );
109
+			$source_object->customer = $this->get_stripe_customer_id($order);
110 110
 			$source_object->source   = $source_info->id;
111 111
 
112 112
 			/* If we're doing a retry and source is chargeable, we need to pass
113 113
 			 * a different idempotency key and retry for success.
114 114
 			 */
115
-			if ( 1 < $this->retry_interval && 'chargeable' === $source_info->status ) {
116
-				add_filter( 'wc_stripe_idempotency_key', array( $this, 'change_idempotency_key' ), 10, 2 );
115
+			if (1 < $this->retry_interval && 'chargeable' === $source_info->status) {
116
+				add_filter('wc_stripe_idempotency_key', array($this, 'change_idempotency_key'), 10, 2);
117 117
 			}
118 118
 
119 119
 			// Make the request.
120
-			$response = WC_Stripe_API::request( $this->generate_payment_request( $order, $source_object ) );
120
+			$response = WC_Stripe_API::request($this->generate_payment_request($order, $source_object));
121 121
 
122
-			if ( ! empty( $response->error ) ) {
122
+			if ( ! empty($response->error)) {
123 123
 				// If it is an API error such connection or server, let's retry.
124
-				if ( 'api_connection_error' === $response->error->type || 'api_error' === $response->error->type ) {
125
-					if ( $retry ) {
126
-						sleep( 5 );
127
-						return $this->process_redirect_payment( $order_id, false );
124
+				if ('api_connection_error' === $response->error->type || 'api_error' === $response->error->type) {
125
+					if ($retry) {
126
+						sleep(5);
127
+						return $this->process_redirect_payment($order_id, false);
128 128
 					} else {
129
-						$localized_message = __( 'API connection error and retries exhausted.', 'woocommerce-gateway-stripe' );
130
-						$order->add_order_note( $localized_message );
131
-						throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message );
129
+						$localized_message = __('API connection error and retries exhausted.', 'woocommerce-gateway-stripe');
130
+						$order->add_order_note($localized_message);
131
+						throw new WC_Stripe_Exception(print_r($response, true), $localized_message);
132 132
 					}
133 133
 				}
134 134
 
135 135
 				// We want to retry.
136
-				if ( $this->is_retryable_error( $response->error ) ) {
137
-					if ( $retry ) {
136
+				if ($this->is_retryable_error($response->error)) {
137
+					if ($retry) {
138 138
 						// Don't do anymore retries after this.
139
-						if ( 5 <= $this->retry_interval ) {
140
-							return $this->process_redirect_payment( $order_id, false );
139
+						if (5 <= $this->retry_interval) {
140
+							return $this->process_redirect_payment($order_id, false);
141 141
 						}
142 142
 
143
-						sleep( $this->retry_interval );
143
+						sleep($this->retry_interval);
144 144
 
145 145
 						$this->retry_interval++;
146
-						return $this->process_redirect_payment( $order_id, true );
146
+						return $this->process_redirect_payment($order_id, true);
147 147
 					} else {
148
-						$localized_message = __( 'On going requests error and retries exhausted.', 'woocommerce-gateway-stripe' );
149
-						$order->add_order_note( $localized_message );
150
-						throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message );
148
+						$localized_message = __('On going requests error and retries exhausted.', 'woocommerce-gateway-stripe');
149
+						$order->add_order_note($localized_message);
150
+						throw new WC_Stripe_Exception(print_r($response, true), $localized_message);
151 151
 					}
152 152
 				}
153 153
 
154 154
 				// Customer param wrong? The user may have been deleted on stripe's end. Remove customer_id. Can be retried without.
155
-				if ( preg_match( '/No such customer/i', $response->error->message ) && $retry ) {
156
-					if ( WC_Stripe_Helper::is_pre_30() ) {
157
-						delete_user_meta( $order->customer_user, '_stripe_customer_id' );
158
-						delete_post_meta( $order_id, '_stripe_customer_id' );
155
+				if (preg_match('/No such customer/i', $response->error->message) && $retry) {
156
+					if (WC_Stripe_Helper::is_pre_30()) {
157
+						delete_user_meta($order->customer_user, '_stripe_customer_id');
158
+						delete_post_meta($order_id, '_stripe_customer_id');
159 159
 					} else {
160
-						delete_user_meta( $order->get_customer_id(), '_stripe_customer_id' );
161
-						$order->delete_meta_data( '_stripe_customer_id' );
160
+						delete_user_meta($order->get_customer_id(), '_stripe_customer_id');
161
+						$order->delete_meta_data('_stripe_customer_id');
162 162
 						$order->save();
163 163
 					}
164 164
 
165
-					return $this->process_redirect_payment( $order_id, false );
165
+					return $this->process_redirect_payment($order_id, false);
166 166
 
167
-				} elseif ( preg_match( '/No such token/i', $response->error->message ) && $source_object->token_id ) {
167
+				} elseif (preg_match('/No such token/i', $response->error->message) && $source_object->token_id) {
168 168
 					// Source param wrong? The CARD may have been deleted on stripe's end. Remove token and show message.
169 169
 
170
-					$wc_token = WC_Payment_Tokens::get( $source_object->token_id );
170
+					$wc_token = WC_Payment_Tokens::get($source_object->token_id);
171 171
 					$wc_token->delete();
172
-					$message = __( 'This card is no longer available and has been removed.', 'woocommerce-gateway-stripe' );
173
-					$order->add_order_note( $message );
174
-					throw new WC_Stripe_Exception( print_r( $response, true ), $message );
172
+					$message = __('This card is no longer available and has been removed.', 'woocommerce-gateway-stripe');
173
+					$order->add_order_note($message);
174
+					throw new WC_Stripe_Exception(print_r($response, true), $message);
175 175
 				}
176 176
 
177 177
 				$localized_messages = WC_Stripe_Helper::get_localized_messages();
178 178
 
179
-				if ( 'card_error' === $response->error->type ) {
180
-					$message = isset( $localized_messages[ $response->error->code ] ) ? $localized_messages[ $response->error->code ] : $response->error->message;
179
+				if ('card_error' === $response->error->type) {
180
+					$message = isset($localized_messages[$response->error->code]) ? $localized_messages[$response->error->code] : $response->error->message;
181 181
 				} else {
182
-					$message = isset( $localized_messages[ $response->error->type ] ) ? $localized_messages[ $response->error->type ] : $response->error->message;
182
+					$message = isset($localized_messages[$response->error->type]) ? $localized_messages[$response->error->type] : $response->error->message;
183 183
 				}
184 184
 
185
-				throw new WC_Stripe_Exception( print_r( $response, true ), $message );
185
+				throw new WC_Stripe_Exception(print_r($response, true), $message);
186 186
 			}
187 187
 
188
-			do_action( 'wc_gateway_stripe_process_redirect_payment', $response, $order );
188
+			do_action('wc_gateway_stripe_process_redirect_payment', $response, $order);
189 189
 
190
-			$this->process_response( $response, $order );
190
+			$this->process_response($response, $order);
191 191
 
192
-		} catch ( WC_Stripe_Exception $e ) {
193
-			WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() );
192
+		} catch (WC_Stripe_Exception $e) {
193
+			WC_Stripe_Logger::log('Error: ' . $e->getMessage());
194 194
 
195
-			do_action( 'wc_gateway_stripe_process_redirect_payment_error', $e, $order );
195
+			do_action('wc_gateway_stripe_process_redirect_payment_error', $e, $order);
196 196
 
197 197
 			/* translators: error message */
198
-			$order->update_status( 'failed', sprintf( __( 'Stripe payment failed: %s', 'woocommerce-gateway-stripe' ), $e->getLocalizedMessage() ) );
198
+			$order->update_status('failed', sprintf(__('Stripe payment failed: %s', 'woocommerce-gateway-stripe'), $e->getLocalizedMessage()));
199 199
 
200
-			if ( $order->has_status( array( 'pending', 'failed' ) ) ) {
201
-				$this->send_failed_order_email( $order_id );
200
+			if ($order->has_status(array('pending', 'failed'))) {
201
+				$this->send_failed_order_email($order_id);
202 202
 			}
203 203
 
204
-			wc_add_notice( $e->getLocalizedMessage(), 'error' );
205
-			wp_safe_redirect( wc_get_checkout_url() );
204
+			wc_add_notice($e->getLocalizedMessage(), 'error');
205
+			wp_safe_redirect(wc_get_checkout_url());
206 206
 			exit;
207 207
 		}
208 208
 	}
@@ -214,13 +214,13 @@  discard block
 block discarded – undo
214 214
 	 * @version 4.0.0
215 215
 	 */
216 216
 	public function maybe_process_redirect_order() {
217
-		if ( ! is_order_received_page() || empty( $_GET['client_secret'] ) || empty( $_GET['source'] ) ) {
217
+		if ( ! is_order_received_page() || empty($_GET['client_secret']) || empty($_GET['source'])) {
218 218
 			return;
219 219
 		}
220 220
 
221
-		$order_id = wc_clean( $_GET['order_id'] );
221
+		$order_id = wc_clean($_GET['order_id']);
222 222
 
223
-		$this->process_redirect_payment( $order_id );
223
+		$this->process_redirect_payment($order_id);
224 224
 	}
225 225
 
226 226
 	/**
@@ -230,52 +230,52 @@  discard block
 block discarded – undo
230 230
 	 * @version 4.0.0
231 231
 	 * @param  int $order_id
232 232
 	 */
233
-	public function capture_payment( $order_id ) {
234
-		$order = wc_get_order( $order_id );
233
+	public function capture_payment($order_id) {
234
+		$order = wc_get_order($order_id);
235 235
 
236
-		if ( 'stripe' === ( WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method() ) ) {
237
-			$charge   = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_transaction_id', true ) : $order->get_transaction_id();
238
-			$captured = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_stripe_charge_captured', true ) : $order->get_meta( '_stripe_charge_captured', true );
236
+		if ('stripe' === (WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method())) {
237
+			$charge   = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_transaction_id', true) : $order->get_transaction_id();
238
+			$captured = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_stripe_charge_captured', true) : $order->get_meta('_stripe_charge_captured', true);
239 239
 
240
-			if ( $charge && 'no' === $captured ) {
240
+			if ($charge && 'no' === $captured) {
241 241
 				$order_total = $order->get_total();
242 242
 
243
-				if ( 0 < $order->get_total_refunded() ) {
243
+				if (0 < $order->get_total_refunded()) {
244 244
 					$order_total = $order_total - $order->get_total_refunded();
245 245
 				}
246 246
 
247
-				$result = WC_Stripe_API::request( array(
248
-					'amount'   => WC_Stripe_Helper::get_stripe_amount( $order_total ),
247
+				$result = WC_Stripe_API::request(array(
248
+					'amount'   => WC_Stripe_Helper::get_stripe_amount($order_total),
249 249
 					'expand[]' => 'balance_transaction',
250
-				), 'charges/' . $charge . '/capture' );
250
+				), 'charges/' . $charge . '/capture');
251 251
 
252
-				if ( ! empty( $result->error ) ) {
252
+				if ( ! empty($result->error)) {
253 253
 					/* translators: error message */
254
-					$order->update_status( 'failed', sprintf( __( 'Unable to capture charge! %s', 'woocommerce-gateway-stripe' ), $result->error->message ) );
254
+					$order->update_status('failed', sprintf(__('Unable to capture charge! %s', 'woocommerce-gateway-stripe'), $result->error->message));
255 255
 				} else {
256 256
 					/* translators: transaction id */
257
-					$order->add_order_note( sprintf( __( 'Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe' ), $result->id ) );
258
-					WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, '_stripe_charge_captured', 'yes' ) : $order->update_meta_data( '_stripe_charge_captured', 'yes' );
257
+					$order->add_order_note(sprintf(__('Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe'), $result->id));
258
+					WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, '_stripe_charge_captured', 'yes') : $order->update_meta_data('_stripe_charge_captured', 'yes');
259 259
 
260 260
 					// Store other data such as fees
261
-					WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, '_transaction_id', $result->id ) : $order->set_transaction_id( $result->id );
261
+					WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, '_transaction_id', $result->id) : $order->set_transaction_id($result->id);
262 262
 
263
-					if ( isset( $result->balance_transaction ) && isset( $result->balance_transaction->fee ) ) {
263
+					if (isset($result->balance_transaction) && isset($result->balance_transaction->fee)) {
264 264
 						// Fees and Net needs to both come from Stripe to be accurate as the returned
265 265
 						// values are in the local currency of the Stripe account, not from WC.
266
-						$fee = ! empty( $result->balance_transaction->fee ) ? WC_Stripe_Helper::format_balance_fee( $result->balance_transaction, 'fee' ) : 0;
267
-						$net = ! empty( $result->balance_transaction->net ) ? WC_Stripe_Helper::format_balance_fee( $result->balance_transaction, 'net' ) : 0;
268
-						WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, parent::META_NAME_FEE, $fee ) : $order->update_meta_data( parent::META_NAME_FEE, $fee );
269
-						WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, parent::META_NAME_NET, $net ) : $order->update_meta_data( parent::META_NAME_NET, $net );
266
+						$fee = ! empty($result->balance_transaction->fee) ? WC_Stripe_Helper::format_balance_fee($result->balance_transaction, 'fee') : 0;
267
+						$net = ! empty($result->balance_transaction->net) ? WC_Stripe_Helper::format_balance_fee($result->balance_transaction, 'net') : 0;
268
+						WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, parent::META_NAME_FEE, $fee) : $order->update_meta_data(parent::META_NAME_FEE, $fee);
269
+						WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, parent::META_NAME_NET, $net) : $order->update_meta_data(parent::META_NAME_NET, $net);
270 270
 					}
271 271
 
272
-					if ( is_callable( array( $order, 'save' ) ) ) {
272
+					if (is_callable(array($order, 'save'))) {
273 273
 						$order->save();
274 274
 					}
275 275
 				}
276 276
 
277 277
 				// This hook fires when admin manually changes order status to processing or completed.
278
-				do_action( 'woocommerce_stripe_process_manual_capture', $order, $result );
278
+				do_action('woocommerce_stripe_process_manual_capture', $order, $result);
279 279
 			}
280 280
 		}
281 281
 	}
@@ -287,14 +287,14 @@  discard block
 block discarded – undo
287 287
 	 * @version 4.0.0
288 288
 	 * @param  int $order_id
289 289
 	 */
290
-	public function cancel_payment( $order_id ) {
291
-		$order = wc_get_order( $order_id );
290
+	public function cancel_payment($order_id) {
291
+		$order = wc_get_order($order_id);
292 292
 
293
-		if ( 'stripe' === ( WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method() ) ) {
294
-			$this->process_refund( $order_id );
293
+		if ('stripe' === (WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method())) {
294
+			$this->process_refund($order_id);
295 295
 
296 296
 			// This hook fires when admin manually changes order status to cancel.
297
-			do_action( 'woocommerce_stripe_process_manual_cancel', $order );
297
+			do_action('woocommerce_stripe_process_manual_cancel', $order);
298 298
 		}
299 299
 	}
300 300
 
@@ -306,21 +306,21 @@  discard block
 block discarded – undo
306 306
 	 * @param string $field
307 307
 	 * @return string $error_field
308 308
 	 */
309
-	public function normalize_field( $field ) {
309
+	public function normalize_field($field) {
310 310
 		$checkout_fields = WC()->checkout->get_checkout_fields();
311 311
 		$org_str         = array();
312 312
 		$replace_str     = array();
313 313
 
314
-		if ( array_key_exists( $field, $checkout_fields['billing'] ) ) {
315
-			$error_field = __( 'Billing', 'woocommerce-gateway-stripe' ) . ' ' . $checkout_fields['billing'][ $field ]['label'];
316
-		} elseif ( array_key_exists( $field, $checkout_fields['shipping'] ) ) {
317
-			$error_field = __( 'Shipping', 'woocommerce-gateway-stripe' ) . ' ' . $checkout_fields['shipping'][ $field ]['label'];
318
-		} elseif ( array_key_exists( $field, $checkout_fields['order'] ) ) {
319
-			$error_field = $checkout_fields['order'][ $field ]['label'];
320
-		} elseif ( array_key_exists( $field, $checkout_fields['account'] ) ) {
321
-			$error_field = $checkout_fields['account'][ $field ]['label'];
314
+		if (array_key_exists($field, $checkout_fields['billing'])) {
315
+			$error_field = __('Billing', 'woocommerce-gateway-stripe') . ' ' . $checkout_fields['billing'][$field]['label'];
316
+		} elseif (array_key_exists($field, $checkout_fields['shipping'])) {
317
+			$error_field = __('Shipping', 'woocommerce-gateway-stripe') . ' ' . $checkout_fields['shipping'][$field]['label'];
318
+		} elseif (array_key_exists($field, $checkout_fields['order'])) {
319
+			$error_field = $checkout_fields['order'][$field]['label'];
320
+		} elseif (array_key_exists($field, $checkout_fields['account'])) {
321
+			$error_field = $checkout_fields['account'][$field]['label'];
322 322
 		} else {
323
-			$error_field = str_replace( '_', ' ', $field );
323
+			$error_field = str_replace('_', ' ', $field);
324 324
 
325 325
 			$org_str[]     = 'stripe';
326 326
 			$replace_str[] = '';
@@ -335,9 +335,9 @@  discard block
 block discarded – undo
335 335
 			$replace_str[] = 'SOFORT';
336 336
 
337 337
 			$org_str[]     = 'owner';
338
-			$replace_str[] = __( 'Owner', 'woocommerce-gateway-stripe' );
338
+			$replace_str[] = __('Owner', 'woocommerce-gateway-stripe');
339 339
 
340
-			$error_field   = str_replace( $org_str, $replace_str, $error_field );
340
+			$error_field   = str_replace($org_str, $replace_str, $error_field);
341 341
 		}
342 342
 
343 343
 		return $error_field;
@@ -350,135 +350,135 @@  discard block
 block discarded – undo
350 350
 	 * @version 4.0.0
351 351
 	 */
352 352
 	public function validate_checkout() {
353
-		if ( ! wp_verify_nonce( $_POST['nonce'], '_wc_stripe_nonce' ) ) {
354
-			wp_die( __( 'Cheatin&#8217; huh?', 'woocommerce-gateway-stripe' ) );
353
+		if ( ! wp_verify_nonce($_POST['nonce'], '_wc_stripe_nonce')) {
354
+			wp_die(__('Cheatin&#8217; huh?', 'woocommerce-gateway-stripe'));
355 355
 		}
356 356
 
357
-		parse_str( $_POST['required_fields'], $required_fields );
358
-		parse_str( $_POST['all_fields'], $all_fields );
357
+		parse_str($_POST['required_fields'], $required_fields);
358
+		parse_str($_POST['all_fields'], $all_fields);
359 359
 		$validate_shipping_fields = false;
360 360
 		$create_account           = false;
361 361
 		$errors                   = new WP_Error();
362
-		$all_fields               = apply_filters( 'wc_stripe_validate_checkout_all_fields', $all_fields );
363
-		$required_fields          = apply_filters( 'wc_stripe_validate_checkout_required_fields', $required_fields );
362
+		$all_fields               = apply_filters('wc_stripe_validate_checkout_all_fields', $all_fields);
363
+		$required_fields          = apply_filters('wc_stripe_validate_checkout_required_fields', $required_fields);
364 364
 
365
-		array_walk_recursive( $required_fields, 'wc_clean' );
366
-		array_walk_recursive( $all_fields, 'wc_clean' );
365
+		array_walk_recursive($required_fields, 'wc_clean');
366
+		array_walk_recursive($all_fields, 'wc_clean');
367 367
 
368 368
 		/**
369 369
 		 * If ship to different address checkbox is checked then we need
370 370
 		 * to validate shipping fields too.
371 371
 		 */
372
-		if ( isset( $all_fields['ship_to_different_address'] ) ) {
372
+		if (isset($all_fields['ship_to_different_address'])) {
373 373
 			$validate_shipping_fields = true;
374 374
 		}
375 375
 
376 376
 		// Check if createaccount is checked.
377
-		if ( isset( $all_fields['createaccount'] ) ) {
377
+		if (isset($all_fields['createaccount'])) {
378 378
 			$create_account = true;
379 379
 		}
380 380
 
381 381
 		// Check if required fields are empty.
382
-		foreach ( $required_fields as $field => $field_value ) {
382
+		foreach ($required_fields as $field => $field_value) {
383 383
 			// Check for shipping field.
384
-			if ( preg_match( '/^shipping_/', $field ) && ! $validate_shipping_fields ) {
384
+			if (preg_match('/^shipping_/', $field) && ! $validate_shipping_fields) {
385 385
 				continue;
386 386
 			}
387 387
 
388 388
 			// Check create account name.
389
-			if ( 'account_username' === $field && ! $create_account ) {
389
+			if ('account_username' === $field && ! $create_account) {
390 390
 				continue;
391 391
 			}
392 392
 
393 393
 			// Check create account password.
394
-			if ( 'account_password' === $field && ! $create_account ) {
394
+			if ('account_password' === $field && ! $create_account) {
395 395
 				continue;
396 396
 			}
397 397
 
398
-			if ( empty( $field_value ) || '-1' === $field_value ) {
399
-				$error_field = $this->normalize_field( $field );
398
+			if (empty($field_value) || '-1' === $field_value) {
399
+				$error_field = $this->normalize_field($field);
400 400
 				/* translators: error field name */
401
-				$errors->add( 'validation', sprintf( __( '<strong>%s</strong> cannot be empty', 'woocommerce-gateway-stripe' ), $error_field ) );
401
+				$errors->add('validation', sprintf(__('<strong>%s</strong> cannot be empty', 'woocommerce-gateway-stripe'), $error_field));
402 402
 			}
403 403
 		}
404 404
 
405 405
 		// Check if email is valid format.
406
-		if ( ! empty( $required_fields['billing_email'] ) && ! is_email( $required_fields['billing_email'] ) ) {
407
-			$errors->add( 'validation', __( '<strong>Billing Email</strong> is not valid', 'woocommerce-gateway-stripe' ) );
406
+		if ( ! empty($required_fields['billing_email']) && ! is_email($required_fields['billing_email'])) {
407
+			$errors->add('validation', __('<strong>Billing Email</strong> is not valid', 'woocommerce-gateway-stripe'));
408 408
 		}
409 409
 
410 410
 		// Check if phone number is valid format.
411
-		if ( ! empty( $required_fields['billing_phone'] ) ) {
412
-			$phone = wc_format_phone_number( $required_fields['billing_phone'] );
411
+		if ( ! empty($required_fields['billing_phone'])) {
412
+			$phone = wc_format_phone_number($required_fields['billing_phone']);
413 413
 
414
-			if ( '' !== $phone && ! WC_Validation::is_phone( $phone ) ) {
414
+			if ('' !== $phone && ! WC_Validation::is_phone($phone)) {
415 415
 				/* translators: %s: phone number */
416
-				$errors->add( 'validation', __( 'Please enter a valid phone number.', 'woocommerce-gateway-stripe' ) );
416
+				$errors->add('validation', __('Please enter a valid phone number.', 'woocommerce-gateway-stripe'));
417 417
 			}
418 418
 		}
419 419
 
420 420
 		// Check if postal code is valid format.
421
-		if ( ! empty( $required_fields['billing_postcode'] ) ) {
422
-			$country = isset( $required_fields['billing_country'] ) ? $required_fields['billing_country'] : WC()->customer->get_billing_country();
423
-			$postcode = wc_format_postcode( $required_fields['billing_postcode'], $country );
421
+		if ( ! empty($required_fields['billing_postcode'])) {
422
+			$country = isset($required_fields['billing_country']) ? $required_fields['billing_country'] : WC()->customer->get_billing_country();
423
+			$postcode = wc_format_postcode($required_fields['billing_postcode'], $country);
424 424
 
425
-			if ( '' !== $required_fields['billing_postcode'] && ! WC_Validation::is_postcode( $postcode, $country ) ) {
426
-				$errors->add( 'validation', __( 'Please enter a valid billing postcode / ZIP.', 'woocommerce-gateway-stripe' ) );
425
+			if ('' !== $required_fields['billing_postcode'] && ! WC_Validation::is_postcode($postcode, $country)) {
426
+				$errors->add('validation', __('Please enter a valid billing postcode / ZIP.', 'woocommerce-gateway-stripe'));
427 427
 			}
428 428
 		}
429 429
 
430
-		if ( WC()->cart->needs_shipping() && $validate_shipping_fields ) {
430
+		if (WC()->cart->needs_shipping() && $validate_shipping_fields) {
431 431
 			// Check if postal code is valid format.
432
-			if ( ! empty( $required_fields['shipping_postcode'] ) ) {
433
-				$country = isset( $required_fields['shipping_country'] ) ? $required_fields['shipping_country'] : WC()->customer->get_shipping_country();
434
-				$postcode = wc_format_postcode( $required_fields['shipping_postcode'], $country );
432
+			if ( ! empty($required_fields['shipping_postcode'])) {
433
+				$country = isset($required_fields['shipping_country']) ? $required_fields['shipping_country'] : WC()->customer->get_shipping_country();
434
+				$postcode = wc_format_postcode($required_fields['shipping_postcode'], $country);
435 435
 
436
-				if ( '' !== $required_fields['shipping_postcode'] && ! WC_Validation::is_postcode( $postcode, $country ) ) {
437
-					$errors->add( 'validation', __( 'Please enter a valid shipping postcode / ZIP.', 'woocommerce-gateway-stripe' ) );
436
+				if ('' !== $required_fields['shipping_postcode'] && ! WC_Validation::is_postcode($postcode, $country)) {
437
+					$errors->add('validation', __('Please enter a valid shipping postcode / ZIP.', 'woocommerce-gateway-stripe'));
438 438
 				}
439 439
 			}
440 440
 		}
441 441
 
442
-		if ( WC()->cart->needs_shipping() ) {
442
+		if (WC()->cart->needs_shipping()) {
443 443
 			$shipping_country = WC()->customer->get_shipping_country();
444 444
 
445
-			if ( empty( $shipping_country ) ) {
446
-				$errors->add( 'shipping', __( 'Please enter an address to continue.', 'woocommerce-gateway-stripe' ) );
447
-			} elseif ( ! in_array( WC()->customer->get_shipping_country(), array_keys( WC()->countries->get_shipping_countries() ) ) ) {
445
+			if (empty($shipping_country)) {
446
+				$errors->add('shipping', __('Please enter an address to continue.', 'woocommerce-gateway-stripe'));
447
+			} elseif ( ! in_array(WC()->customer->get_shipping_country(), array_keys(WC()->countries->get_shipping_countries()))) {
448 448
 				/* translators: country name */
449
-				$errors->add( 'shipping', sprintf( __( 'Unfortunately <strong>we do not ship %s</strong>. Please enter an alternative shipping address.', 'woocommerce-gateway-stripe' ), WC()->countries->shipping_to_prefix() . ' ' . WC()->customer->get_shipping_country() ) );
449
+				$errors->add('shipping', sprintf(__('Unfortunately <strong>we do not ship %s</strong>. Please enter an alternative shipping address.', 'woocommerce-gateway-stripe'), WC()->countries->shipping_to_prefix() . ' ' . WC()->customer->get_shipping_country()));
450 450
 			} else {
451
-				$chosen_shipping_methods = WC()->session->get( 'chosen_shipping_methods' );
451
+				$chosen_shipping_methods = WC()->session->get('chosen_shipping_methods');
452 452
 
453
-				foreach ( WC()->shipping->get_packages() as $i => $package ) {
454
-					if ( ! isset( $chosen_shipping_methods[ $i ], $package['rates'][ $chosen_shipping_methods[ $i ] ] ) ) {
455
-						$errors->add( 'shipping', __( 'No shipping method has been selected. Please double check your address, or contact us if you need any help.', 'woocommerce-gateway-stripe' ) );
453
+				foreach (WC()->shipping->get_packages() as $i => $package) {
454
+					if ( ! isset($chosen_shipping_methods[$i], $package['rates'][$chosen_shipping_methods[$i]])) {
455
+						$errors->add('shipping', __('No shipping method has been selected. Please double check your address, or contact us if you need any help.', 'woocommerce-gateway-stripe'));
456 456
 					}
457 457
 				}
458 458
 			}
459 459
 		}
460 460
 
461
-		if ( WC()->cart->needs_payment() ) {
461
+		if (WC()->cart->needs_payment()) {
462 462
 			$available_gateways = WC()->payment_gateways->get_available_payment_gateways();
463 463
 
464
-			if ( ! isset( $available_gateways[ $all_fields['payment_method'] ] ) ) {
465
-				$errors->add( 'payment', __( 'Invalid payment method.', 'woocommerce-gateway-stripe' ) );
464
+			if ( ! isset($available_gateways[$all_fields['payment_method']])) {
465
+				$errors->add('payment', __('Invalid payment method.', 'woocommerce-gateway-stripe'));
466 466
 			} else {
467
-				$available_gateways[ $all_fields['payment_method'] ]->validate_fields();
467
+				$available_gateways[$all_fields['payment_method']]->validate_fields();
468 468
 			}
469 469
 		}
470 470
 
471
-		if ( empty( $all_fields['woocommerce_checkout_update_totals'] ) && empty( $all_fields['terms'] ) && apply_filters( 'woocommerce_checkout_show_terms', wc_get_page_id( 'terms' ) > 0 ) ) {
472
-			$errors->add( 'terms', __( 'You must accept our Terms &amp; Conditions.', 'woocommerce-gateway-stripe' ) );
471
+		if (empty($all_fields['woocommerce_checkout_update_totals']) && empty($all_fields['terms']) && apply_filters('woocommerce_checkout_show_terms', wc_get_page_id('terms') > 0)) {
472
+			$errors->add('terms', __('You must accept our Terms &amp; Conditions.', 'woocommerce-gateway-stripe'));
473 473
 		}
474 474
 
475
-		do_action( 'wc_stripe_validate_checkout', $required_fields, $all_fields, $errors );
475
+		do_action('wc_stripe_validate_checkout', $required_fields, $all_fields, $errors);
476 476
 
477
-		if ( 0 === count( $errors->errors ) ) {
478
-			wp_send_json( 'success' );
477
+		if (0 === count($errors->errors)) {
478
+			wp_send_json('success');
479 479
 		} else {
480
-			foreach ( $errors->get_error_messages() as $message ) {
481
-				wc_add_notice( $message, 'error' );
480
+			foreach ($errors->get_error_messages() as $message) {
481
+				wc_add_notice($message, 'error');
482 482
 			}
483 483
 
484 484
 			$this->send_ajax_failure_response();
@@ -492,9 +492,9 @@  discard block
 block discarded – undo
492 492
 	 * @version 4.0.0
493 493
 	 */
494 494
 	public function send_ajax_failure_response() {
495
-		if ( is_ajax() ) {
495
+		if (is_ajax()) {
496 496
 			// only print notices if not reloading the checkout, otherwise they're lost in the page reload.
497
-			if ( ! isset( WC()->session->reload_checkout ) ) {
497
+			if ( ! isset(WC()->session->reload_checkout)) {
498 498
 				ob_start();
499 499
 				wc_print_notices();
500 500
 				$messages = ob_get_clean();
@@ -502,14 +502,14 @@  discard block
 block discarded – undo
502 502
 
503 503
 			$response = array(
504 504
 				'result'   => 'failure',
505
-				'messages' => isset( $messages ) ? $messages : '',
506
-				'refresh'  => isset( WC()->session->refresh_totals ),
507
-				'reload'   => isset( WC()->session->reload_checkout ),
505
+				'messages' => isset($messages) ? $messages : '',
506
+				'refresh'  => isset(WC()->session->refresh_totals),
507
+				'reload'   => isset(WC()->session->reload_checkout),
508 508
 			);
509 509
 
510
-			unset( WC()->session->refresh_totals, WC()->session->reload_checkout );
510
+			unset(WC()->session->refresh_totals, WC()->session->reload_checkout);
511 511
 
512
-			wp_send_json( $response );
512
+			wp_send_json($response);
513 513
 		}
514 514
 	}
515 515
 }
Please login to merge, or discard this patch.
includes/class-wc-gateway-stripe.php 1 patch
Spacing   +183 added lines, -183 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
 
@@ -106,9 +106,9 @@  discard block
 block discarded – undo
106 106
 	public function __construct() {
107 107
 		$this->retry_interval       = 1;
108 108
 		$this->id                   = 'stripe';
109
-		$this->method_title         = __( 'Stripe', 'woocommerce-gateway-stripe' );
109
+		$this->method_title         = __('Stripe', 'woocommerce-gateway-stripe');
110 110
 		/* translators: 1) link to Stripe register page 2) link to Stripe api keys page */
111
-		$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' );
111
+		$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');
112 112
 		$this->has_fields           = true;
113 113
 		$this->supports             = array(
114 114
 			'products',
@@ -135,32 +135,32 @@  discard block
 block discarded – undo
135 135
 		$this->init_settings();
136 136
 
137 137
 		// Get setting values.
138
-		$this->title                   = $this->get_option( 'title' );
139
-		$this->description             = $this->get_option( 'description' );
140
-		$this->enabled                 = $this->get_option( 'enabled' );
141
-		$this->testmode                = 'yes' === $this->get_option( 'testmode' );
142
-		$this->inline_cc_form          = 'yes' === $this->get_option( 'inline_cc_form' );
143
-		$this->capture                 = 'yes' === $this->get_option( 'capture', 'yes' );
144
-		$this->statement_descriptor    = WC_Stripe_Helper::clean_statement_descriptor( $this->get_option( 'statement_descriptor' ) );
145
-		$this->three_d_secure          = 'yes' === $this->get_option( 'three_d_secure' );
146
-		$this->stripe_checkout         = 'yes' === $this->get_option( 'stripe_checkout' );
147
-		$this->stripe_checkout_image   = $this->get_option( 'stripe_checkout_image', '' );
148
-		$this->saved_cards             = 'yes' === $this->get_option( 'saved_cards' );
149
-		$this->secret_key              = $this->testmode ? $this->get_option( 'test_secret_key' ) : $this->get_option( 'secret_key' );
150
-		$this->publishable_key         = $this->testmode ? $this->get_option( 'test_publishable_key' ) : $this->get_option( 'publishable_key' );
151
-		$this->bitcoin                 = 'USD' === strtoupper( get_woocommerce_currency() ) && 'yes' === $this->get_option( 'stripe_bitcoin' );
152
-		$this->payment_request         = 'yes' === $this->get_option( 'payment_request', 'yes' );
153
-
154
-		if ( $this->stripe_checkout ) {
155
-			$this->order_button_text = __( 'Continue to payment', 'woocommerce-gateway-stripe' );
138
+		$this->title                   = $this->get_option('title');
139
+		$this->description             = $this->get_option('description');
140
+		$this->enabled                 = $this->get_option('enabled');
141
+		$this->testmode                = 'yes' === $this->get_option('testmode');
142
+		$this->inline_cc_form          = 'yes' === $this->get_option('inline_cc_form');
143
+		$this->capture                 = 'yes' === $this->get_option('capture', 'yes');
144
+		$this->statement_descriptor    = WC_Stripe_Helper::clean_statement_descriptor($this->get_option('statement_descriptor'));
145
+		$this->three_d_secure          = 'yes' === $this->get_option('three_d_secure');
146
+		$this->stripe_checkout         = 'yes' === $this->get_option('stripe_checkout');
147
+		$this->stripe_checkout_image   = $this->get_option('stripe_checkout_image', '');
148
+		$this->saved_cards             = 'yes' === $this->get_option('saved_cards');
149
+		$this->secret_key              = $this->testmode ? $this->get_option('test_secret_key') : $this->get_option('secret_key');
150
+		$this->publishable_key         = $this->testmode ? $this->get_option('test_publishable_key') : $this->get_option('publishable_key');
151
+		$this->bitcoin                 = 'USD' === strtoupper(get_woocommerce_currency()) && 'yes' === $this->get_option('stripe_bitcoin');
152
+		$this->payment_request         = 'yes' === $this->get_option('payment_request', 'yes');
153
+
154
+		if ($this->stripe_checkout) {
155
+			$this->order_button_text = __('Continue to payment', 'woocommerce-gateway-stripe');
156 156
 		}
157 157
 
158
-		WC_Stripe_API::set_secret_key( $this->secret_key );
158
+		WC_Stripe_API::set_secret_key($this->secret_key);
159 159
 
160 160
 		// Hooks.
161
-		add_action( 'wp_enqueue_scripts', array( $this, 'payment_scripts' ) );
162
-		add_action( 'admin_enqueue_scripts', array( $this, 'admin_scripts' ) );
163
-		add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) );
161
+		add_action('wp_enqueue_scripts', array($this, 'payment_scripts'));
162
+		add_action('admin_enqueue_scripts', array($this, 'admin_scripts'));
163
+		add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options'));
164 164
 	}
165 165
 
166 166
 	/**
@@ -170,7 +170,7 @@  discard block
 block discarded – undo
170 170
 	 * @return bool
171 171
 	 */
172 172
 	public function are_keys_set() {
173
-		if ( empty( $this->secret_key ) || empty( $this->publishable_key ) ) {
173
+		if (empty($this->secret_key) || empty($this->publishable_key)) {
174 174
 			return false;
175 175
 		}
176 176
 
@@ -183,7 +183,7 @@  discard block
 block discarded – undo
183 183
 	 * @since 4.0.2
184 184
 	 */
185 185
 	public function is_available() {
186
-		if ( is_add_payment_method_page() && ! $this->saved_cards ) {
186
+		if (is_add_payment_method_page() && ! $this->saved_cards) {
187 187
 			return false;
188 188
 		}
189 189
 
@@ -206,24 +206,24 @@  discard block
 block discarded – undo
206 206
 		$icons_str .= $icons['amex'];
207 207
 		$icons_str .= $icons['mastercard'];
208 208
 
209
-		if ( 'USD' === get_woocommerce_currency() ) {
209
+		if ('USD' === get_woocommerce_currency()) {
210 210
 			$icons_str .= $icons['discover'];
211 211
 			$icons_str .= $icons['jcb'];
212 212
 			$icons_str .= $icons['diners'];
213 213
 		}
214 214
 
215
-		if ( $this->bitcoin && $this->stripe_checkout ) {
215
+		if ($this->bitcoin && $this->stripe_checkout) {
216 216
 			$icons_str .= $icons['bitcoin'];
217 217
 		}
218 218
 
219
-		return apply_filters( 'woocommerce_gateway_icon', $icons_str, $this->id );
219
+		return apply_filters('woocommerce_gateway_icon', $icons_str, $this->id);
220 220
 	}
221 221
 
222 222
 	/**
223 223
 	 * Initialise Gateway Settings Form Fields
224 224
 	 */
225 225
 	public function init_form_fields() {
226
-		$this->form_fields = require( dirname( __FILE__ ) . '/admin/stripe-settings.php' );
226
+		$this->form_fields = require(dirname(__FILE__) . '/admin/stripe-settings.php');
227 227
 	}
228 228
 
229 229
 	/**
@@ -231,68 +231,68 @@  discard block
 block discarded – undo
231 231
 	 */
232 232
 	public function payment_fields() {
233 233
 		$user                 = wp_get_current_user();
234
-		$display_tokenization = $this->supports( 'tokenization' ) && is_checkout() && $this->saved_cards;
234
+		$display_tokenization = $this->supports('tokenization') && is_checkout() && $this->saved_cards;
235 235
 		$total                = WC()->cart->total;
236 236
 		$user_email           = '';
237 237
 
238 238
 		// If paying from order, we need to get total from order not cart.
239
-		if ( isset( $_GET['pay_for_order'] ) && ! empty( $_GET['key'] ) ) {
240
-			$order      = wc_get_order( wc_get_order_id_by_order_key( wc_clean( $_GET['key'] ) ) );
239
+		if (isset($_GET['pay_for_order']) && ! empty($_GET['key'])) {
240
+			$order      = wc_get_order(wc_get_order_id_by_order_key(wc_clean($_GET['key'])));
241 241
 			$total      = $order->get_total();
242 242
 			$user_email = WC_Stripe_Helper::is_pre_30() ? $order->billing_email : $order->get_billing_email();
243 243
 		} else {
244
-			if ( $user->ID ) {
245
-				$user_email = get_user_meta( $user->ID, 'billing_email', true );
244
+			if ($user->ID) {
245
+				$user_email = get_user_meta($user->ID, 'billing_email', true);
246 246
 				$user_email = $user_email ? $user_email : $user->user_email;
247 247
 			}
248 248
 		}
249 249
 
250
-		if ( is_add_payment_method_page() ) {
251
-			$pay_button_text = __( 'Add Card', 'woocommerce-gateway-stripe' );
252
-			$total        = '';
250
+		if (is_add_payment_method_page()) {
251
+			$pay_button_text = __('Add Card', 'woocommerce-gateway-stripe');
252
+			$total = '';
253 253
 		} else {
254 254
 			$pay_button_text = '';
255 255
 		}
256 256
 
257 257
 		echo '<div
258 258
 			id="stripe-payment-data"
259
-			data-panel-label="' . esc_attr( $pay_button_text ) . '"
259
+			data-panel-label="' . esc_attr($pay_button_text) . '"
260 260
 			data-description=""
261
-			data-email="' . esc_attr( $user_email ) . '"
262
-			data-amount="' . esc_attr( WC_Stripe_Helper::get_stripe_amount( $total ) ) . '"
263
-			data-name="' . esc_attr( $this->statement_descriptor ) . '"
264
-			data-currency="' . esc_attr( strtolower( get_woocommerce_currency() ) ) . '"
265
-			data-image="' . esc_attr( $this->stripe_checkout_image ) . '"
266
-			data-bitcoin="' . esc_attr( ( $this->bitcoin && $this->capture ) ? 'true' : 'false' ) . '"
267
-			data-locale="' . esc_attr( apply_filters( 'wc_stripe_checkout_locale', $this->get_locale() ) ) . '"
268
-			data-three-d-secure="' . esc_attr( $this->three_d_secure ? 'true' : 'false' ) . '"
269
-			data-allow-remember-me="' . esc_attr( $this->saved_cards ? 'true' : 'false' ) . '">';
270
-
271
-		if ( $this->description ) {
272
-			if ( $this->testmode ) {
261
+			data-email="' . esc_attr($user_email) . '"
262
+			data-amount="' . esc_attr(WC_Stripe_Helper::get_stripe_amount($total)) . '"
263
+			data-name="' . esc_attr($this->statement_descriptor) . '"
264
+			data-currency="' . esc_attr(strtolower(get_woocommerce_currency())) . '"
265
+			data-image="' . esc_attr($this->stripe_checkout_image) . '"
266
+			data-bitcoin="' . esc_attr(($this->bitcoin && $this->capture) ? 'true' : 'false') . '"
267
+			data-locale="' . esc_attr(apply_filters('wc_stripe_checkout_locale', $this->get_locale())) . '"
268
+			data-three-d-secure="' . esc_attr($this->three_d_secure ? 'true' : 'false') . '"
269
+			data-allow-remember-me="' . esc_attr($this->saved_cards ? 'true' : 'false') . '">';
270
+
271
+		if ($this->description) {
272
+			if ($this->testmode) {
273 273
 				/* translators: link to Stripe testing page */
274
-				$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' );
275
-				$this->description  = trim( $this->description );
274
+				$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');
275
+				$this->description  = trim($this->description);
276 276
 			}
277
-			echo apply_filters( 'wc_stripe_description', wpautop( wp_kses_post( $this->description ) ) );
277
+			echo apply_filters('wc_stripe_description', wpautop(wp_kses_post($this->description)));
278 278
 		}
279 279
 
280
-		if ( $display_tokenization ) {
280
+		if ($display_tokenization) {
281 281
 			$this->tokenization_script();
282 282
 			$this->saved_payment_methods();
283 283
 		}
284 284
 
285
-		if ( ! $this->stripe_checkout ) {
286
-			if ( apply_filters( 'wc_stripe_use_elements_checkout_form', true ) ) {
285
+		if ( ! $this->stripe_checkout) {
286
+			if (apply_filters('wc_stripe_use_elements_checkout_form', true)) {
287 287
 				$this->elements_form();
288 288
 			} else {
289
-				WC_Stripe_Logger::log( 'DEPRECATED! Since version 4.0. Stripe Elements is used. This legacy credit card form will be removed by version 5.0!' );
289
+				WC_Stripe_Logger::log('DEPRECATED! Since version 4.0. Stripe Elements is used. This legacy credit card form will be removed by version 5.0!');
290 290
 				$this->form();
291 291
 				echo '<div class="stripe-source-errors" role="alert"></div>';
292 292
 			}
293 293
 		}
294 294
 
295
-		if ( apply_filters( 'wc_stripe_display_save_payment_method_checkbox', $display_tokenization ) && ! is_add_payment_method_page() && ! isset( $_GET['change_payment_method'] ) ) {
295
+		if (apply_filters('wc_stripe_display_save_payment_method_checkbox', $display_tokenization) && ! is_add_payment_method_page() && ! isset($_GET['change_payment_method'])) {
296 296
 			$this->save_payment_method_checkbox();
297 297
 		}
298 298
 
@@ -307,12 +307,12 @@  discard block
 block discarded – undo
307 307
 	 */
308 308
 	public function elements_form() {
309 309
 		?>
310
-		<fieldset id="wc-<?php echo esc_attr( $this->id ); ?>-cc-form" class="wc-credit-card-form wc-payment-form" style="background:transparent;">
311
-			<?php do_action( 'woocommerce_credit_card_form_start', $this->id ); ?>
310
+		<fieldset id="wc-<?php echo esc_attr($this->id); ?>-cc-form" class="wc-credit-card-form wc-payment-form" style="background:transparent;">
311
+			<?php do_action('woocommerce_credit_card_form_start', $this->id); ?>
312 312
 
313
-			<?php if ( $this->inline_cc_form ) { ?>
313
+			<?php if ($this->inline_cc_form) { ?>
314 314
 				<label for="card-element">
315
-					<?php esc_html_e( 'Credit or debit card', 'woocommerce-gateway-stripe' ); ?>
315
+					<?php esc_html_e('Credit or debit card', 'woocommerce-gateway-stripe'); ?>
316 316
 				</label>
317 317
 
318 318
 				<div id="stripe-card-element" style="background:#fff;padding:0 1em;border:1px solid #ddd;margin:5px 0;padding:10px 5px;">
@@ -320,7 +320,7 @@  discard block
 block discarded – undo
320 320
 				</div>
321 321
 			<?php } else { ?>
322 322
 				<div class="form-row form-row-wide">
323
-					<label><?php _e( 'Card Number', 'woocommerce-gateway-stripe' ); ?> <span class="required">*</span></label>
323
+					<label><?php _e('Card Number', 'woocommerce-gateway-stripe'); ?> <span class="required">*</span></label>
324 324
 
325 325
 					<div id="stripe-card-element" style="background:#fff;padding:0 1em;border:1px solid #ddd;margin:5px 0;padding:10px 5px;">
326 326
 					<!-- a Stripe Element will be inserted here. -->
@@ -328,7 +328,7 @@  discard block
 block discarded – undo
328 328
 				</div>
329 329
 
330 330
 				<div class="form-row form-row-first">
331
-					<label><?php _e( 'Expiry Date', 'woocommerce-gateway-stripe' ); ?> <span class="required">*</span></label>
331
+					<label><?php _e('Expiry Date', 'woocommerce-gateway-stripe'); ?> <span class="required">*</span></label>
332 332
 
333 333
 					<div id="stripe-exp-element" style="background:#fff;padding:0 1em;border:1px solid #ddd;margin:5px 0;padding:10px 5px;">
334 334
 					<!-- a Stripe Element will be inserted here. -->
@@ -336,7 +336,7 @@  discard block
 block discarded – undo
336 336
 				</div>
337 337
 
338 338
 				<div class="form-row form-row-last">
339
-					<label><?php _e( 'Card Code (CVC)', 'woocommerce-gateway-stripe' ); ?> <span class="required">*</span></label>
339
+					<label><?php _e('Card Code (CVC)', 'woocommerce-gateway-stripe'); ?> <span class="required">*</span></label>
340 340
 				<div id="stripe-cvc-element" style="background:#fff;padding:0 1em;border:1px solid #ddd;margin:5px 0;padding:10px 5px;">
341 341
 				<!-- a Stripe Element will be inserted here. -->
342 342
 				</div>
@@ -346,7 +346,7 @@  discard block
 block discarded – undo
346 346
 
347 347
 			<!-- Used to display form errors -->
348 348
 			<div class="stripe-source-errors" role="alert"></div>
349
-			<?php do_action( 'woocommerce_credit_card_form_end', $this->id ); ?>
349
+			<?php do_action('woocommerce_credit_card_form_end', $this->id); ?>
350 350
 			<div class="clear"></div>
351 351
 		</fieldset>
352 352
 		<?php
@@ -359,13 +359,13 @@  discard block
 block discarded – undo
359 359
 	 * @version 3.1.0
360 360
 	 */
361 361
 	public function admin_scripts() {
362
-		if ( 'woocommerce_page_wc-settings' !== get_current_screen()->id ) {
362
+		if ('woocommerce_page_wc-settings' !== get_current_screen()->id) {
363 363
 			return;
364 364
 		}
365 365
 
366
-		$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
366
+		$suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';
367 367
 
368
-		wp_enqueue_script( 'woocommerce_stripe_admin', plugins_url( 'assets/js/stripe-admin' . $suffix . '.js', WC_STRIPE_MAIN_FILE ), array(), WC_STRIPE_VERSION, true );
368
+		wp_enqueue_script('woocommerce_stripe_admin', plugins_url('assets/js/stripe-admin' . $suffix . '.js', WC_STRIPE_MAIN_FILE), array(), WC_STRIPE_VERSION, true);
369 369
 	}
370 370
 
371 371
 	/**
@@ -377,46 +377,46 @@  discard block
 block discarded – undo
377 377
 	 * @version 4.0.0
378 378
 	 */
379 379
 	public function payment_scripts() {
380
-		if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) && ! is_add_payment_method_page() && ! isset( $_GET['change_payment_method'] ) ) {
380
+		if ( ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order']) && ! is_add_payment_method_page() && ! isset($_GET['change_payment_method'])) {
381 381
 			return;
382 382
 		}
383 383
 
384 384
 		// If Stripe is not enabled bail.
385
-		if ( 'no' === $this->enabled ) {
385
+		if ('no' === $this->enabled) {
386 386
 			return;
387 387
 		}
388 388
 
389 389
 		// If keys are not set bail.
390
-		if ( ! $this->are_keys_set() ) {
391
-			WC_Stripe_Logger::log( 'Keys are not set correctly.' );
390
+		if ( ! $this->are_keys_set()) {
391
+			WC_Stripe_Logger::log('Keys are not set correctly.');
392 392
 			return;
393 393
 		}
394 394
 
395 395
 		// If no SSL bail.
396
-		if ( ! $this->testmode && ! is_ssl() ) {
397
-			WC_Stripe_Logger::log( 'Stripe requires SSL.' );
396
+		if ( ! $this->testmode && ! is_ssl()) {
397
+			WC_Stripe_Logger::log('Stripe requires SSL.');
398 398
 			return;
399 399
 		}
400 400
 
401
-		$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
401
+		$suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';
402 402
 
403
-		wp_register_style( 'stripe_paymentfonts', plugins_url( 'assets/css/stripe-paymentfonts.css', WC_STRIPE_MAIN_FILE ), array(), '1.2.5' );
404
-		wp_enqueue_style( 'stripe_paymentfonts' );
405
-		wp_register_script( 'stripe_checkout', 'https://checkout.stripe.com/checkout.js', '', WC_STRIPE_VERSION, true );
406
-		wp_register_script( 'stripev2', 'https://js.stripe.com/v2/', '', '2.0', true );
407
-		wp_register_script( 'stripe', 'https://js.stripe.com/v3/', '', '3.0', true );
408
-		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 );
403
+		wp_register_style('stripe_paymentfonts', plugins_url('assets/css/stripe-paymentfonts.css', WC_STRIPE_MAIN_FILE), array(), '1.2.5');
404
+		wp_enqueue_style('stripe_paymentfonts');
405
+		wp_register_script('stripe_checkout', 'https://checkout.stripe.com/checkout.js', '', WC_STRIPE_VERSION, true);
406
+		wp_register_script('stripev2', 'https://js.stripe.com/v2/', '', '2.0', true);
407
+		wp_register_script('stripe', 'https://js.stripe.com/v3/', '', '3.0', true);
408
+		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);
409 409
 
410 410
 		$stripe_params = array(
411 411
 			'key'                  => $this->publishable_key,
412
-			'i18n_terms'           => __( 'Please accept the terms and conditions first', 'woocommerce-gateway-stripe' ),
413
-			'i18n_required_fields' => __( 'Please fill in required checkout fields first', 'woocommerce-gateway-stripe' ),
412
+			'i18n_terms'           => __('Please accept the terms and conditions first', 'woocommerce-gateway-stripe'),
413
+			'i18n_required_fields' => __('Please fill in required checkout fields first', 'woocommerce-gateway-stripe'),
414 414
 		);
415 415
 
416 416
 		// If we're on the pay page we need to pass stripe.js the address of the order.
417
-		if ( isset( $_GET['pay_for_order'] ) && 'true' === $_GET['pay_for_order'] ) {
418
-			$order_id = wc_get_order_id_by_order_key( urldecode( $_GET['key'] ) );
419
-			$order    = wc_get_order( $order_id );
417
+		if (isset($_GET['pay_for_order']) && 'true' === $_GET['pay_for_order']) {
418
+			$order_id = wc_get_order_id_by_order_key(urldecode($_GET['key']));
419
+			$order    = wc_get_order($order_id);
420 420
 
421 421
 			$stripe_params['billing_first_name'] = WC_Stripe_Helper::is_pre_30() ? $order->billing_first_name : $order->get_billing_first_name();
422 422
 			$stripe_params['billing_last_name']  = WC_Stripe_Helper::is_pre_30() ? $order->billing_last_name : $order->get_billing_last_name();
@@ -428,39 +428,39 @@  discard block
 block discarded – undo
428 428
 			$stripe_params['billing_country']    = WC_Stripe_Helper::is_pre_30() ? $order->billing_country : $order->get_billing_country();
429 429
 		}
430 430
 
431
-		$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' );
432
-		$stripe_params['no_sepa_owner_msg']                       = __( 'Please enter your IBAN account name.', 'woocommerce-gateway-stripe' );
433
-		$stripe_params['no_sepa_iban_msg']                        = __( 'Please enter your IBAN account number.', 'woocommerce-gateway-stripe' );
434
-		$stripe_params['sepa_mandate_notification']               = apply_filters( 'wc_stripe_sepa_mandate_notification', 'email' );
435
-		$stripe_params['allow_prepaid_card']                      = apply_filters( 'wc_stripe_allow_prepaid_card', true ) ? 'yes' : 'no';
431
+		$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');
432
+		$stripe_params['no_sepa_owner_msg']                       = __('Please enter your IBAN account name.', 'woocommerce-gateway-stripe');
433
+		$stripe_params['no_sepa_iban_msg']                        = __('Please enter your IBAN account number.', 'woocommerce-gateway-stripe');
434
+		$stripe_params['sepa_mandate_notification']               = apply_filters('wc_stripe_sepa_mandate_notification', 'email');
435
+		$stripe_params['allow_prepaid_card']                      = apply_filters('wc_stripe_allow_prepaid_card', true) ? 'yes' : 'no';
436 436
 		$stripe_params['inline_cc_form']                          = $this->inline_cc_form ? 'yes' : 'no';
437
-		$stripe_params['stripe_checkout_require_billing_address'] = apply_filters( 'wc_stripe_checkout_require_billing_address', false ) ? 'yes' : 'no';
438
-		$stripe_params['is_checkout']                             = ( is_checkout() && empty( $_GET['pay_for_order'] ) ) ? 'yes' : 'no';
437
+		$stripe_params['stripe_checkout_require_billing_address'] = apply_filters('wc_stripe_checkout_require_billing_address', false) ? 'yes' : 'no';
438
+		$stripe_params['is_checkout']                             = (is_checkout() && empty($_GET['pay_for_order'])) ? 'yes' : 'no';
439 439
 		$stripe_params['return_url']                              = $this->get_stripe_return_url();
440
-		$stripe_params['ajaxurl']                                 = WC_AJAX::get_endpoint( '%%endpoint%%' );
441
-		$stripe_params['stripe_nonce']                            = wp_create_nonce( '_wc_stripe_nonce' );
440
+		$stripe_params['ajaxurl']                                 = WC_AJAX::get_endpoint('%%endpoint%%');
441
+		$stripe_params['stripe_nonce']                            = wp_create_nonce('_wc_stripe_nonce');
442 442
 		$stripe_params['statement_descriptor']                    = $this->statement_descriptor;
443
-		$stripe_params['use_elements']                            = apply_filters( 'wc_stripe_use_elements_checkout_form', true ) ? 'yes' : 'no';
444
-		$stripe_params['elements_options']                        = apply_filters( 'wc_stripe_elements_options', array() );
443
+		$stripe_params['use_elements']                            = apply_filters('wc_stripe_use_elements_checkout_form', true) ? 'yes' : 'no';
444
+		$stripe_params['elements_options']                        = apply_filters('wc_stripe_elements_options', array());
445 445
 		$stripe_params['is_stripe_checkout']                      = $this->stripe_checkout ? 'yes' : 'no';
446
-		$stripe_params['is_change_payment_page']                  = isset( $_GET['change_payment_method'] ) ? 'yes' : 'no';
447
-		$stripe_params['is_pay_for_order_page']                   = isset( $_GET['pay_for_order'] ) ? 'yes' : 'no';
448
-		$stripe_params['validate_modal_checkout']                 = apply_filters( 'wc_stripe_validate_model_checkout', true ) ? 'yes' : 'no';
449
-		$stripe_params['elements_styling']                        = apply_filters( 'wc_stripe_elements_styling', false );
450
-		$stripe_params['elements_classes']                        = apply_filters( 'wc_stripe_elements_classes', false );
446
+		$stripe_params['is_change_payment_page']                  = isset($_GET['change_payment_method']) ? 'yes' : 'no';
447
+		$stripe_params['is_pay_for_order_page']                   = isset($_GET['pay_for_order']) ? 'yes' : 'no';
448
+		$stripe_params['validate_modal_checkout']                 = apply_filters('wc_stripe_validate_model_checkout', true) ? 'yes' : 'no';
449
+		$stripe_params['elements_styling']                        = apply_filters('wc_stripe_elements_styling', false);
450
+		$stripe_params['elements_classes']                        = apply_filters('wc_stripe_elements_classes', false);
451 451
 
452 452
 		// merge localized messages to be use in JS
453
-		$stripe_params = array_merge( $stripe_params, WC_Stripe_Helper::get_localized_messages() );
453
+		$stripe_params = array_merge($stripe_params, WC_Stripe_Helper::get_localized_messages());
454 454
 
455
-		wp_localize_script( 'woocommerce_stripe', 'wc_stripe_params', apply_filters( 'wc_stripe_params', $stripe_params ) );
456
-		wp_localize_script( 'woocommerce_stripe_checkout', 'wc_stripe_params', apply_filters( 'wc_stripe_params', $stripe_params ) );
455
+		wp_localize_script('woocommerce_stripe', 'wc_stripe_params', apply_filters('wc_stripe_params', $stripe_params));
456
+		wp_localize_script('woocommerce_stripe_checkout', 'wc_stripe_params', apply_filters('wc_stripe_params', $stripe_params));
457 457
 
458
-		if ( $this->stripe_checkout ) {
459
-			wp_enqueue_script( 'stripe_checkout' );
458
+		if ($this->stripe_checkout) {
459
+			wp_enqueue_script('stripe_checkout');
460 460
 		}
461 461
 
462 462
 		$this->tokenization_script();
463
-		wp_enqueue_script( 'woocommerce_stripe' );
463
+		wp_enqueue_script('woocommerce_stripe');
464 464
 	}
465 465
 
466 466
 	/**
@@ -476,41 +476,41 @@  discard block
 block discarded – undo
476 476
 	 *
477 477
 	 * @return array|void
478 478
 	 */
479
-	public function process_payment( $order_id, $retry = true, $force_save_source = false ) {
479
+	public function process_payment($order_id, $retry = true, $force_save_source = false) {
480 480
 		try {
481
-			$order = wc_get_order( $order_id );
481
+			$order = wc_get_order($order_id);
482 482
 
483 483
 			// This comes from the create account checkbox in the checkout page.
484
-			$create_account = ! empty( $_POST['createaccount'] ) ? true : false;
484
+			$create_account = ! empty($_POST['createaccount']) ? true : false;
485 485
 
486
-			if ( $create_account ) {
486
+			if ($create_account) {
487 487
 				$new_customer_id     = WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id();
488
-				$new_stripe_customer = new WC_Stripe_Customer( $new_customer_id );
488
+				$new_stripe_customer = new WC_Stripe_Customer($new_customer_id);
489 489
 				$new_stripe_customer->create_customer();
490 490
 			}
491 491
 
492
-			$prepared_source = $this->prepare_source( get_current_user_id(), $force_save_source );
492
+			$prepared_source = $this->prepare_source(get_current_user_id(), $force_save_source);
493 493
 			$source_object   = $prepared_source->source_object;
494 494
 
495 495
 			// Check if we don't allow prepaid credit cards.
496
-			if ( ! apply_filters( 'wc_stripe_allow_prepaid_card', true ) && $this->is_prepaid_card( $source_object ) ) {
497
-				$localized_message = __( 'Sorry, we\'re not accepting prepaid cards at this time. Your credit card has not been charge. Please try with alternative payment method.', 'woocommerce-gateway-stripe' );
498
-				throw new WC_Stripe_Exception( print_r( $source_object, true ), $localized_message );
496
+			if ( ! apply_filters('wc_stripe_allow_prepaid_card', true) && $this->is_prepaid_card($source_object)) {
497
+				$localized_message = __('Sorry, we\'re not accepting prepaid cards at this time. Your credit card has not been charge. Please try with alternative payment method.', 'woocommerce-gateway-stripe');
498
+				throw new WC_Stripe_Exception(print_r($source_object, true), $localized_message);
499 499
 			}
500 500
 
501
-			if ( empty( $prepared_source->source ) ) {
502
-				$localized_message = __( 'Payment processing failed. Please retry.', 'woocommerce-gateway-stripe' );
503
-				throw new WC_Stripe_Exception( print_r( $prepared_source, true ), $localized_message );
501
+			if (empty($prepared_source->source)) {
502
+				$localized_message = __('Payment processing failed. Please retry.', 'woocommerce-gateway-stripe');
503
+				throw new WC_Stripe_Exception(print_r($prepared_source, true), $localized_message);
504 504
 			}
505 505
 
506
-			$this->save_source_to_order( $order, $prepared_source );
506
+			$this->save_source_to_order($order, $prepared_source);
507 507
 
508 508
 			// Result from Stripe API request.
509 509
 			$response = null;
510 510
 
511
-			if ( $order->get_total() > 0 ) {
511
+			if ($order->get_total() > 0) {
512 512
 				// This will throw exception if not valid.
513
-				$this->validate_minimum_order_amount( $order );
513
+				$this->validate_minimum_order_amount($order);
514 514
 
515 515
 				/*
516 516
 				 * Check if card 3DS is required or optional with 3DS setting.
@@ -519,117 +519,117 @@  discard block
 block discarded – undo
519 519
 				 * Note that if we need to save source, the original source must be first
520 520
 				 * attached to a customer in Stripe before it can be charged.
521 521
 				 */
522
-				if ( $this->is_3ds_required( $source_object ) ) {
523
-					$response = $this->create_3ds_source( $order, $source_object );
522
+				if ($this->is_3ds_required($source_object)) {
523
+					$response = $this->create_3ds_source($order, $source_object);
524 524
 
525
-					if ( ! empty( $response->error ) ) {
525
+					if ( ! empty($response->error)) {
526 526
 						$localized_message = $response->error->message;
527 527
 
528
-						$order->add_order_note( $localized_message );
528
+						$order->add_order_note($localized_message);
529 529
 
530
-						throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message );
530
+						throw new WC_Stripe_Exception(print_r($response, true), $localized_message);
531 531
 					}
532 532
 
533 533
 					// Update order meta with 3DS source.
534
-					if ( WC_Stripe_Helper::is_pre_30() ) {
535
-						update_post_meta( $order_id, '_stripe_source_id', $response->id );
534
+					if (WC_Stripe_Helper::is_pre_30()) {
535
+						update_post_meta($order_id, '_stripe_source_id', $response->id);
536 536
 					} else {
537
-						$order->update_meta_data( '_stripe_source_id', $response->id );
537
+						$order->update_meta_data('_stripe_source_id', $response->id);
538 538
 						$order->save();
539 539
 					}
540 540
 
541
-					WC_Stripe_Logger::log( 'Info: Redirecting to 3DS...' );
541
+					WC_Stripe_Logger::log('Info: Redirecting to 3DS...');
542 542
 
543 543
 					return array(
544 544
 						'result'   => 'success',
545
-						'redirect' => esc_url_raw( $response->redirect->url ),
545
+						'redirect' => esc_url_raw($response->redirect->url),
546 546
 					);
547 547
 				}
548 548
 
549
-				WC_Stripe_Logger::log( "Info: Begin processing payment for order $order_id for the amount of {$order->get_total()}" );
549
+				WC_Stripe_Logger::log("Info: Begin processing payment for order $order_id for the amount of {$order->get_total()}");
550 550
 
551 551
 				/* If we're doing a retry and source is chargeable, we need to pass
552 552
 				 * a different idempotency key and retry for success.
553 553
 				 */
554
-				if ( 1 < $this->retry_interval && ! empty( $source_object ) && 'chargeable' === $source_object->status ) {
555
-					add_filter( 'wc_stripe_idempotency_key', array( $this, 'change_idempotency_key' ), 10, 2 );
554
+				if (1 < $this->retry_interval && ! empty($source_object) && 'chargeable' === $source_object->status) {
555
+					add_filter('wc_stripe_idempotency_key', array($this, 'change_idempotency_key'), 10, 2);
556 556
 				}
557 557
 
558 558
 				// Make the request.
559
-				$response = WC_Stripe_API::request( $this->generate_payment_request( $order, $prepared_source ) );
559
+				$response = WC_Stripe_API::request($this->generate_payment_request($order, $prepared_source));
560 560
 
561
-				if ( ! empty( $response->error ) ) {
561
+				if ( ! empty($response->error)) {
562 562
 					// If it is an API error such connection or server, let's retry.
563
-					if ( 'api_connection_error' === $response->error->type || 'api_error' === $response->error->type ) {
564
-						if ( $retry ) {
565
-							sleep( 5 );
566
-							return $this->process_payment( $order_id, false, $force_save_source );
563
+					if ('api_connection_error' === $response->error->type || 'api_error' === $response->error->type) {
564
+						if ($retry) {
565
+							sleep(5);
566
+							return $this->process_payment($order_id, false, $force_save_source);
567 567
 						} else {
568 568
 							$localized_message = 'API connection error and retries exhausted.';
569
-							$order->add_order_note( $localized_message );
570
-							throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message );
569
+							$order->add_order_note($localized_message);
570
+							throw new WC_Stripe_Exception(print_r($response, true), $localized_message);
571 571
 						}
572 572
 					}
573 573
 
574 574
 					// We want to retry.
575
-					if ( $this->is_retryable_error( $response->error ) ) {
576
-						if ( $retry ) {
575
+					if ($this->is_retryable_error($response->error)) {
576
+						if ($retry) {
577 577
 							// Don't do anymore retries after this.
578
-							if ( 5 <= $this->retry_interval ) {
578
+							if (5 <= $this->retry_interval) {
579 579
 
580
-								return $this->process_payment( $order_id, false, $force_save_source );
580
+								return $this->process_payment($order_id, false, $force_save_source);
581 581
 							}
582 582
 
583
-							sleep( $this->retry_interval );
583
+							sleep($this->retry_interval);
584 584
 
585 585
 							$this->retry_interval++;
586 586
 
587
-							return $this->process_payment( $order_id, true, $force_save_source );
587
+							return $this->process_payment($order_id, true, $force_save_source);
588 588
 						} else {
589
-							$localized_message = __( 'On going requests error and retries exhausted.', 'woocommerce-gateway-stripe' );
590
-							$order->add_order_note( $localized_message );
591
-							throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message );
589
+							$localized_message = __('On going requests error and retries exhausted.', 'woocommerce-gateway-stripe');
590
+							$order->add_order_note($localized_message);
591
+							throw new WC_Stripe_Exception(print_r($response, true), $localized_message);
592 592
 						}
593 593
 					}
594 594
 
595 595
 					// Customer param wrong? The user may have been deleted on stripe's end. Remove customer_id. Can be retried without.
596
-					if ( preg_match( '/No such customer/i', $response->error->message ) && $retry ) {
597
-						if ( WC_Stripe_Helper::is_pre_30() ) {
598
-							delete_user_meta( $order->customer_user, '_stripe_customer_id' );
599
-							delete_post_meta( $order_id, '_stripe_customer_id' );
596
+					if (preg_match('/No such customer/i', $response->error->message) && $retry) {
597
+						if (WC_Stripe_Helper::is_pre_30()) {
598
+							delete_user_meta($order->customer_user, '_stripe_customer_id');
599
+							delete_post_meta($order_id, '_stripe_customer_id');
600 600
 						} else {
601
-							delete_user_meta( $order->get_customer_id(), '_stripe_customer_id' );
602
-							$order->delete_meta_data( '_stripe_customer_id' );
601
+							delete_user_meta($order->get_customer_id(), '_stripe_customer_id');
602
+							$order->delete_meta_data('_stripe_customer_id');
603 603
 							$order->save();
604 604
 						}
605 605
 
606
-						return $this->process_payment( $order_id, false, $force_save_source );
607
-					} elseif ( preg_match( '/No such token/i', $response->error->message ) && $prepared_source->token_id ) {
606
+						return $this->process_payment($order_id, false, $force_save_source);
607
+					} elseif (preg_match('/No such token/i', $response->error->message) && $prepared_source->token_id) {
608 608
 						// Source param wrong? The CARD may have been deleted on stripe's end. Remove token and show message.
609
-						$wc_token = WC_Payment_Tokens::get( $prepared_source->token_id );
609
+						$wc_token = WC_Payment_Tokens::get($prepared_source->token_id);
610 610
 						$wc_token->delete();
611
-						$localized_message = __( 'This card is no longer available and has been removed.', 'woocommerce-gateway-stripe' );
612
-						$order->add_order_note( $localized_message );
613
-						throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message );
611
+						$localized_message = __('This card is no longer available and has been removed.', 'woocommerce-gateway-stripe');
612
+						$order->add_order_note($localized_message);
613
+						throw new WC_Stripe_Exception(print_r($response, true), $localized_message);
614 614
 					}
615 615
 
616 616
 					$localized_messages = WC_Stripe_Helper::get_localized_messages();
617 617
 
618
-					if ( 'card_error' === $response->error->type ) {
619
-						$localized_message = isset( $localized_messages[ $response->error->code ] ) ? $localized_messages[ $response->error->code ] : $response->error->message;
618
+					if ('card_error' === $response->error->type) {
619
+						$localized_message = isset($localized_messages[$response->error->code]) ? $localized_messages[$response->error->code] : $response->error->message;
620 620
 					} else {
621
-						$localized_message = isset( $localized_messages[ $response->error->type ] ) ? $localized_messages[ $response->error->type ] : $response->error->message;
621
+						$localized_message = isset($localized_messages[$response->error->type]) ? $localized_messages[$response->error->type] : $response->error->message;
622 622
 					}
623 623
 
624
-					$order->add_order_note( $localized_message );
624
+					$order->add_order_note($localized_message);
625 625
 
626
-					throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message );
626
+					throw new WC_Stripe_Exception(print_r($response, true), $localized_message);
627 627
 				}
628 628
 
629
-				do_action( 'wc_gateway_stripe_process_payment', $response, $order );
629
+				do_action('wc_gateway_stripe_process_payment', $response, $order);
630 630
 
631 631
 				// Process valid response.
632
-				$this->process_response( $response, $order );
632
+				$this->process_response($response, $order);
633 633
 			} else {
634 634
 				$order->payment_complete();
635 635
 			}
@@ -640,20 +640,20 @@  discard block
 block discarded – undo
640 640
 			// Return thank you page redirect.
641 641
 			return array(
642 642
 				'result'   => 'success',
643
-				'redirect' => $this->get_return_url( $order ),
643
+				'redirect' => $this->get_return_url($order),
644 644
 			);
645 645
 
646
-		} catch ( WC_Stripe_Exception $e ) {
647
-			wc_add_notice( $e->getLocalizedMessage(), 'error' );
648
-			WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() );
646
+		} catch (WC_Stripe_Exception $e) {
647
+			wc_add_notice($e->getLocalizedMessage(), 'error');
648
+			WC_Stripe_Logger::log('Error: ' . $e->getMessage());
649 649
 
650
-			do_action( 'wc_gateway_stripe_process_payment_error', $e, $order );
650
+			do_action('wc_gateway_stripe_process_payment_error', $e, $order);
651 651
 
652 652
 			/* translators: error message */
653
-			$order->update_status( 'failed' );
653
+			$order->update_status('failed');
654 654
 
655
-			if ( $order->has_status( array( 'pending', 'failed' ) ) ) {
656
-				$this->send_failed_order_email( $order_id );
655
+			if ($order->has_status(array('pending', 'failed'))) {
656
+				$this->send_failed_order_email($order_id);
657 657
 			}
658 658
 
659 659
 			return array(
Please login to merge, or discard this patch.