Completed
Pull Request — master (#953)
by asdf
02:36
created
includes/class-wc-stripe-api.php 2 patches
Doc Comments   -1 removed lines patch added patch discarded remove patch
@@ -23,7 +23,6 @@
 block discarded – undo
23 23
 
24 24
 	/**
25 25
 	 * Set secret API Key.
26
-	 * @param string $key
27 26
 	 */
28 27
 	public static function set_secret_key( $secret_key ) {
29 28
 		self::$secret_key = $secret_key;
Please login to merge, or discard this patch.
Spacing   +28 added lines, -28 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) {
2
+if ( ! defined('ABSPATH')) {
3 3
 	exit;
4 4
 }
5 5
 
@@ -26,7 +26,7 @@  discard block
 block discarded – undo
26 26
 	 * Set secret API Key.
27 27
 	 * @param string $key
28 28
 	 */
29
-	public static function set_secret_key( $secret_key ) {
29
+	public static function set_secret_key($secret_key) {
30 30
 		self::$secret_key = $secret_key;
31 31
 	}
32 32
 
@@ -35,11 +35,11 @@  discard block
 block discarded – undo
35 35
 	 * @return string
36 36
 	 */
37 37
 	public static function get_secret_key() {
38
-		if ( ! self::$secret_key ) {
39
-			$options = get_option( 'woocommerce_stripe_settings' );
38
+		if ( ! self::$secret_key) {
39
+			$options = get_option('woocommerce_stripe_settings');
40 40
 
41
-			if ( isset( $options['testmode'], $options['secret_key'], $options['test_secret_key'] ) ) {
42
-				self::set_secret_key( 'yes' === $options['testmode'] ? $options['test_secret_key'] : $options['secret_key'] );
41
+			if (isset($options['testmode'], $options['secret_key'], $options['test_secret_key'])) {
42
+				self::set_secret_key('yes' === $options['testmode'] ? $options['test_secret_key'] : $options['secret_key']);
43 43
 			}
44 44
 		}
45 45
 		return self::$secret_key;
@@ -81,10 +81,10 @@  discard block
 block discarded – undo
81 81
 		return apply_filters(
82 82
 			'woocommerce_stripe_request_headers',
83 83
 			array(
84
-				'Authorization'              => 'Basic ' . base64_encode( self::get_secret_key() . ':' ),
84
+				'Authorization'              => 'Basic ' . base64_encode(self::get_secret_key() . ':'),
85 85
 				'Stripe-Version'             => self::STRIPE_API_VERSION,
86 86
 				'User-Agent'                 => $app_info['name'] . '/' . $app_info['version'] . ' (' . $app_info['url'] . ')',
87
-				'X-Stripe-Client-User-Agent' => json_encode( $user_agent ),
87
+				'X-Stripe-Client-User-Agent' => json_encode($user_agent),
88 88
 			)
89 89
 		);
90 90
 	}
@@ -99,16 +99,16 @@  discard block
 block discarded – undo
99 99
 	 * @param bool $with_headers To get the response with headers.
100 100
 	 * @return array|WP_Error
101 101
 	 */
102
-	public static function request( $request, $api = 'charges', $method = 'POST', $with_headers = false ) {
103
-		WC_Stripe_Logger::log( "{$api} request: " . print_r( $request, true ) );
102
+	public static function request($request, $api = 'charges', $method = 'POST', $with_headers = false) {
103
+		WC_Stripe_Logger::log("{$api} request: " . print_r($request, true));
104 104
 
105 105
 		$headers         = self::get_headers();
106 106
 		$idempotency_key = '';
107 107
 
108
-		if ( 'charges' === $api && 'POST' === $method ) {
109
-			$customer        = ! empty( $request['customer'] ) ? $request['customer'] : '';
110
-			$source          = ! empty( $request['source'] ) ? $request['source'] : $customer;
111
-			$idempotency_key = apply_filters( 'wc_stripe_idempotency_key', $request['metadata']['order_id'] . '-' . $source, $request );
108
+		if ('charges' === $api && 'POST' === $method) {
109
+			$customer        = ! empty($request['customer']) ? $request['customer'] : '';
110
+			$source          = ! empty($request['source']) ? $request['source'] : $customer;
111
+			$idempotency_key = apply_filters('wc_stripe_idempotency_key', $request['metadata']['order_id'] . '-' . $source, $request);
112 112
 
113 113
 			$headers['Idempotency-Key'] = $idempotency_key;
114 114
 		}
@@ -118,14 +118,14 @@  discard block
 block discarded – undo
118 118
 			array(
119 119
 				'method'  => $method,
120 120
 				'headers' => $headers,
121
-				'body'    => apply_filters( 'woocommerce_stripe_request_body', $request, $api ),
121
+				'body'    => apply_filters('woocommerce_stripe_request_body', $request, $api),
122 122
 				'timeout' => 70,
123 123
 			)
124 124
 		);
125 125
 
126
-		if ( is_wp_error( $response ) || empty( $response['body'] ) ) {
126
+		if (is_wp_error($response) || empty($response['body'])) {
127 127
 			WC_Stripe_Logger::log(
128
-				'Error Response: ' . print_r( $response, true ) . PHP_EOL . PHP_EOL . 'Failed request: ' . print_r(
128
+				'Error Response: ' . print_r($response, true) . PHP_EOL . PHP_EOL . 'Failed request: ' . print_r(
129 129
 					array(
130 130
 						'api'             => $api,
131 131
 						'request'         => $request,
@@ -135,17 +135,17 @@  discard block
 block discarded – undo
135 135
 				)
136 136
 			);
137 137
 
138
-			throw new WC_Stripe_Exception( print_r( $response, true ), __( 'There was a problem connecting to the Stripe API endpoint.', 'woocommerce-gateway-stripe' ) );
138
+			throw new WC_Stripe_Exception(print_r($response, true), __('There was a problem connecting to the Stripe API endpoint.', 'woocommerce-gateway-stripe'));
139 139
 		}
140 140
 
141
-		if ( $with_headers ) {
141
+		if ($with_headers) {
142 142
 			return array(
143
-				'headers' => wp_remote_retrieve_headers( $response ),
144
-				'body'    => json_decode( $response['body'] ),
143
+				'headers' => wp_remote_retrieve_headers($response),
144
+				'body'    => json_decode($response['body']),
145 145
 			);
146 146
 		}
147 147
 
148
-		return json_decode( $response['body'] );
148
+		return json_decode($response['body']);
149 149
 	}
150 150
 
151 151
 	/**
@@ -155,8 +155,8 @@  discard block
 block discarded – undo
155 155
 	 * @version 4.0.0
156 156
 	 * @param string $api
157 157
 	 */
158
-	public static function retrieve( $api ) {
159
-		WC_Stripe_Logger::log( "{$api}" );
158
+	public static function retrieve($api) {
159
+		WC_Stripe_Logger::log("{$api}");
160 160
 
161 161
 		$response = wp_safe_remote_get(
162 162
 			self::ENDPOINT . $api,
@@ -167,11 +167,11 @@  discard block
 block discarded – undo
167 167
 			)
168 168
 		);
169 169
 
170
-		if ( is_wp_error( $response ) || empty( $response['body'] ) ) {
171
-			WC_Stripe_Logger::log( 'Error Response: ' . print_r( $response, true ) );
172
-			return new WP_Error( 'stripe_error', __( 'There was a problem connecting to the Stripe API endpoint.', 'woocommerce-gateway-stripe' ) );
170
+		if (is_wp_error($response) || empty($response['body'])) {
171
+			WC_Stripe_Logger::log('Error Response: ' . print_r($response, true));
172
+			return new WP_Error('stripe_error', __('There was a problem connecting to the Stripe API endpoint.', 'woocommerce-gateway-stripe'));
173 173
 		}
174 174
 
175
-		return json_decode( $response['body'] );
175
+		return json_decode($response['body']);
176 176
 	}
177 177
 }
Please login to merge, or discard this patch.
includes/payment-methods/class-wc-gateway-stripe-alipay.php 2 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -289,7 +289,7 @@
 block discarded – undo
289 289
 	 *
290 290
 	 * @param int  $order_id Reference.
291 291
 	 * @param bool $retry Should we retry on fail.
292
-	 * @param bool $force_save_source Force payment source to be saved.
292
+	 * @param bool $force_save_save Force payment source to be saved.
293 293
 	 *
294 294
 	 * @throws Exception If payment will not be accepted.
295 295
 	 *
Please login to merge, or discard this patch.
Spacing   +68 added lines, -68 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) {
2
+if ( ! defined('ABSPATH')) {
3 3
 	exit;
4 4
 }
5 5
 
@@ -57,9 +57,9 @@  discard block
 block discarded – undo
57 57
 	 */
58 58
 	public function __construct() {
59 59
 		$this->id           = 'stripe_alipay';
60
-		$this->method_title = __( 'Stripe Alipay', 'woocommerce-gateway-stripe' );
60
+		$this->method_title = __('Stripe Alipay', 'woocommerce-gateway-stripe');
61 61
 		/* translators: link */
62
-		$this->method_description = sprintf( __( 'All other general Stripe settings can be adjusted <a href="%s">here</a>.', 'woocommerce-gateway-stripe' ), admin_url( 'admin.php?page=wc-settings&tab=checkout&section=stripe' ) );
62
+		$this->method_description = sprintf(__('All other general Stripe settings can be adjusted <a href="%s">here</a>.', 'woocommerce-gateway-stripe'), admin_url('admin.php?page=wc-settings&tab=checkout&section=stripe'));
63 63
 		$this->supports           = array(
64 64
 			'products',
65 65
 			'refunds',
@@ -71,23 +71,23 @@  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( '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('wp_enqueue_scripts', array($this, 'payment_scripts'));
91 91
 	}
92 92
 
93 93
 	/**
@@ -122,7 +122,7 @@  discard block
 block discarded – undo
122 122
 	 * @return bool
123 123
 	 */
124 124
 	public function is_available() {
125
-		if ( ! in_array( get_woocommerce_currency(), $this->get_supported_currency() ) ) {
125
+		if ( ! in_array(get_woocommerce_currency(), $this->get_supported_currency())) {
126 126
 			return false;
127 127
 		}
128 128
 
@@ -141,9 +141,9 @@  discard block
 block discarded – undo
141 141
 
142 142
 		$icons_str = '';
143 143
 
144
-		$icons_str .= isset( $icons['alipay'] ) ? $icons['alipay'] : '';
144
+		$icons_str .= isset($icons['alipay']) ? $icons['alipay'] : '';
145 145
 
146
-		return apply_filters( 'woocommerce_gateway_icon', $icons_str, $this->id );
146
+		return apply_filters('woocommerce_gateway_icon', $icons_str, $this->id);
147 147
 	}
148 148
 
149 149
 	/**
@@ -153,19 +153,19 @@  discard block
 block discarded – undo
153 153
 	 * @version 4.0.0
154 154
 	 */
155 155
 	public function payment_scripts() {
156
-		if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) && ! is_add_payment_method_page() ) {
156
+		if ( ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order']) && ! is_add_payment_method_page()) {
157 157
 			return;
158 158
 		}
159 159
 
160
-		wp_enqueue_style( 'stripe_styles' );
161
-		wp_enqueue_script( 'woocommerce_stripe' );
160
+		wp_enqueue_style('stripe_styles');
161
+		wp_enqueue_script('woocommerce_stripe');
162 162
 	}
163 163
 
164 164
 	/**
165 165
 	 * Initialize Gateway Settings Form Fields.
166 166
 	 */
167 167
 	public function init_form_fields() {
168
-		$this->form_fields = require( WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-alipay-settings.php' );
168
+		$this->form_fields = require(WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-alipay-settings.php');
169 169
 	}
170 170
 
171 171
 	/**
@@ -177,13 +177,13 @@  discard block
 block discarded – undo
177 177
 		$description = $this->get_description();
178 178
 
179 179
 		// If paying from order, we need to get total from order not cart.
180
-		if ( isset( $_GET['pay_for_order'] ) && ! empty( $_GET['key'] ) ) {
181
-			$order = wc_get_order( wc_get_order_id_by_order_key( wc_clean( $_GET['key'] ) ) );
180
+		if (isset($_GET['pay_for_order']) && ! empty($_GET['key'])) {
181
+			$order = wc_get_order(wc_get_order_id_by_order_key(wc_clean($_GET['key'])));
182 182
 			$total = $order->get_total();
183 183
 		}
184 184
 
185
-		if ( is_add_payment_method_page() ) {
186
-			$pay_button_text = __( 'Add Payment', 'woocommerce-gateway-stripe' );
185
+		if (is_add_payment_method_page()) {
186
+			$pay_button_text = __('Add Payment', 'woocommerce-gateway-stripe');
187 187
 			$total           = '';
188 188
 		} else {
189 189
 			$pay_button_text = '';
@@ -191,11 +191,11 @@  discard block
 block discarded – undo
191 191
 
192 192
 		echo '<div
193 193
 			id="stripe-alipay-payment-data"
194
-			data-amount="' . esc_attr( WC_Stripe_Helper::get_stripe_amount( $total ) ) . '"
195
-			data-currency="' . esc_attr( strtolower( get_woocommerce_currency() ) ) . '">';
194
+			data-amount="' . esc_attr(WC_Stripe_Helper::get_stripe_amount($total)) . '"
195
+			data-currency="' . esc_attr(strtolower(get_woocommerce_currency())) . '">';
196 196
 
197
-		if ( $description ) {
198
-			echo apply_filters( 'wc_stripe_description', wpautop( wp_kses_post( $description ) ), $this->id );
197
+		if ($description) {
198
+			echo apply_filters('wc_stripe_description', wpautop(wp_kses_post($description)), $this->id);
199 199
 		}
200 200
 
201 201
 		echo '</div>';
@@ -209,24 +209,24 @@  discard block
 block discarded – undo
209 209
 	 * @param object $order
210 210
 	 * @return mixed
211 211
 	 */
212
-	public function create_source( $order ) {
213
-		$currency              = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->get_order_currency() : $order->get_currency();
214
-		$order_id              = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->id : $order->get_id();
215
-		$return_url            = $this->get_stripe_return_url( $order );
212
+	public function create_source($order) {
213
+		$currency              = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->get_order_currency() : $order->get_currency();
214
+		$order_id              = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->id : $order->get_id();
215
+		$return_url            = $this->get_stripe_return_url($order);
216 216
 		$post_data             = array();
217
-		$post_data['amount']   = WC_Stripe_Helper::get_stripe_amount( $order->get_total(), $currency );
218
-		$post_data['currency'] = strtolower( $currency );
217
+		$post_data['amount']   = WC_Stripe_Helper::get_stripe_amount($order->get_total(), $currency);
218
+		$post_data['currency'] = strtolower($currency);
219 219
 		$post_data['type']     = 'alipay';
220
-		$post_data['owner']    = $this->get_owner_details( $order );
221
-		$post_data['redirect'] = array( 'return_url' => $return_url );
220
+		$post_data['owner']    = $this->get_owner_details($order);
221
+		$post_data['redirect'] = array('return_url' => $return_url);
222 222
 
223
-		if ( ! empty( $this->statement_descriptor ) ) {
224
-			$post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor( $this->statement_descriptor );
223
+		if ( ! empty($this->statement_descriptor)) {
224
+			$post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor($this->statement_descriptor);
225 225
 		}
226 226
 
227
-		WC_Stripe_Logger::log( 'Info: Begin creating Alipay source' );
227
+		WC_Stripe_Logger::log('Info: Begin creating Alipay source');
228 228
 
229
-		return WC_Stripe_API::request( apply_filters( 'wc_stripe_alipay_source', $post_data, $order ), 'sources' );
229
+		return WC_Stripe_API::request(apply_filters('wc_stripe_alipay_source', $post_data, $order), 'sources');
230 230
 	}
231 231
 
232 232
 	/**
@@ -240,53 +240,53 @@  discard block
 block discarded – undo
240 240
 	 *
241 241
 	 * @return array|void
242 242
 	 */
243
-	public function process_payment( $order_id, $retry = true, $force_save_save = false ) {
243
+	public function process_payment($order_id, $retry = true, $force_save_save = false) {
244 244
 		try {
245
-			$order = wc_get_order( $order_id );
245
+			$order = wc_get_order($order_id);
246 246
 
247 247
 			// This will throw exception if not valid.
248
-			$this->validate_minimum_order_amount( $order );
248
+			$this->validate_minimum_order_amount($order);
249 249
 
250 250
 			// This comes from the create account checkbox in the checkout page.
251
-			$create_account = ! empty( $_POST['createaccount'] ) ? true : false;
251
+			$create_account = ! empty($_POST['createaccount']) ? true : false;
252 252
 
253
-			if ( $create_account ) {
254
-				$new_customer_id     = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->customer_user : $order->get_customer_id();
255
-				$new_stripe_customer = new WC_Stripe_Customer( $new_customer_id );
253
+			if ($create_account) {
254
+				$new_customer_id     = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->customer_user : $order->get_customer_id();
255
+				$new_stripe_customer = new WC_Stripe_Customer($new_customer_id);
256 256
 				$new_stripe_customer->create_customer();
257 257
 			}
258 258
 
259
-			$response = $this->create_source( $order );
259
+			$response = $this->create_source($order);
260 260
 
261
-			if ( ! empty( $response->error ) ) {
262
-				$order->add_order_note( $response->error->message );
261
+			if ( ! empty($response->error)) {
262
+				$order->add_order_note($response->error->message);
263 263
 
264
-				throw new WC_Stripe_Exception( print_r( $response, true ), $response->error->message );
264
+				throw new WC_Stripe_Exception(print_r($response, true), $response->error->message);
265 265
 			}
266 266
 
267
-			if ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ) {
268
-				update_post_meta( $order_id, '_stripe_source_id', $response->id );
267
+			if (WC_Stripe_Helper::is_wc_lt('3.0')) {
268
+				update_post_meta($order_id, '_stripe_source_id', $response->id);
269 269
 			} else {
270
-				$order->update_meta_data( '_stripe_source_id', $response->id );
270
+				$order->update_meta_data('_stripe_source_id', $response->id);
271 271
 				$order->save();
272 272
 			}
273 273
 
274
-			WC_Stripe_Logger::log( 'Info: Redirecting to Alipay...' );
274
+			WC_Stripe_Logger::log('Info: Redirecting to Alipay...');
275 275
 
276 276
 			return array(
277 277
 				'result'   => 'success',
278
-				'redirect' => esc_url_raw( $response->redirect->url ),
278
+				'redirect' => esc_url_raw($response->redirect->url),
279 279
 			);
280
-		} catch ( WC_Stripe_Exception $e ) {
281
-			wc_add_notice( $e->getLocalizedMessage(), 'error' );
282
-			WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() );
280
+		} catch (WC_Stripe_Exception $e) {
281
+			wc_add_notice($e->getLocalizedMessage(), 'error');
282
+			WC_Stripe_Logger::log('Error: ' . $e->getMessage());
283 283
 
284
-			do_action( 'wc_gateway_stripe_process_payment_error', $e, $order );
284
+			do_action('wc_gateway_stripe_process_payment_error', $e, $order);
285 285
 
286
-			$statuses = array( 'pending', 'failed' );
286
+			$statuses = array('pending', 'failed');
287 287
 
288
-			if ( $order->has_status( $statuses ) ) {
289
-				$this->send_failed_order_email( $order_id );
288
+			if ($order->has_status($statuses)) {
289
+				$this->send_failed_order_email($order_id);
290 290
 			}
291 291
 
292 292
 			return array(
Please login to merge, or discard this patch.
tests/phpunit/test-wc-stripe.php 1 patch
Spacing   +21 added lines, -21 removed lines patch added patch discarded remove patch
@@ -2,12 +2,12 @@  discard block
 block discarded – undo
2 2
 
3 3
 class WC_Stripe_Test extends WP_UnitTestCase {
4 4
 	public function test_constants_defined() {
5
-		$this->assertTrue( defined( 'WC_STRIPE_VERSION' ) );
6
-		$this->assertTrue( defined( 'WC_STRIPE_MIN_PHP_VER' ) );
7
-		$this->assertTrue( defined( 'WC_STRIPE_MIN_WC_VER' ) );
8
-		$this->assertTrue( defined( 'WC_STRIPE_MAIN_FILE' ) );
9
-		$this->assertTrue( defined( 'WC_STRIPE_PLUGIN_URL' ) );
10
-		$this->assertTrue( defined( 'WC_STRIPE_PLUGIN_PATH' ) );
5
+		$this->assertTrue(defined('WC_STRIPE_VERSION'));
6
+		$this->assertTrue(defined('WC_STRIPE_MIN_PHP_VER'));
7
+		$this->assertTrue(defined('WC_STRIPE_MIN_WC_VER'));
8
+		$this->assertTrue(defined('WC_STRIPE_MAIN_FILE'));
9
+		$this->assertTrue(defined('WC_STRIPE_PLUGIN_URL'));
10
+		$this->assertTrue(defined('WC_STRIPE_PLUGIN_PATH'));
11 11
 	}
12 12
 
13 13
 	/**
@@ -15,11 +15,11 @@  discard block
 block discarded – undo
15 15
 	 * This test will see if we're indeed converting the price correctly.
16 16
 	 */
17 17
 	public function test_price_conversion_before_send_to_stripe() {
18
-		$this->assertEquals( 10050, WC_Stripe_Helper::get_stripe_amount( 100.50, 'USD' ) );
19
-		$this->assertEquals( 10050, WC_Stripe_Helper::get_stripe_amount( 10050, 'JPY' ) );
20
-		$this->assertEquals( 100, WC_Stripe_Helper::get_stripe_amount( 100.50, 'JPY' ) );
21
-		$this->assertEquals( 10050, WC_Stripe_Helper::get_stripe_amount( 100.50 ) );
22
-		$this->assertInternalType( 'int', WC_Stripe_Helper::get_stripe_amount( 100.50, 'USD' ) );
18
+		$this->assertEquals(10050, WC_Stripe_Helper::get_stripe_amount(100.50, 'USD'));
19
+		$this->assertEquals(10050, WC_Stripe_Helper::get_stripe_amount(10050, 'JPY'));
20
+		$this->assertEquals(100, WC_Stripe_Helper::get_stripe_amount(100.50, 'JPY'));
21
+		$this->assertEquals(10050, WC_Stripe_Helper::get_stripe_amount(100.50));
22
+		$this->assertInternalType('int', WC_Stripe_Helper::get_stripe_amount(100.50, 'USD'));
23 23
 	}
24 24
 
25 25
 	/**
@@ -33,37 +33,37 @@  discard block
 block discarded – undo
33 33
 		$balance_fee1->net = 10000;
34 34
 		$balance_fee1->currency = 'USD';
35 35
 
36
-		$this->assertEquals( 105.00, WC_Stripe_Helper::format_balance_fee( $balance_fee1, 'fee' ) );
36
+		$this->assertEquals(105.00, WC_Stripe_Helper::format_balance_fee($balance_fee1, 'fee'));
37 37
 
38 38
 		$balance_fee2 = new stdClass();
39 39
 		$balance_fee2->fee = 10500;
40 40
 		$balance_fee2->net = 10000;
41 41
 		$balance_fee2->currency = 'JPY';
42 42
 
43
-		$this->assertEquals( 10500, WC_Stripe_Helper::format_balance_fee( $balance_fee2, 'fee' ) );
43
+		$this->assertEquals(10500, WC_Stripe_Helper::format_balance_fee($balance_fee2, 'fee'));
44 44
 
45 45
 		$balance_fee3 = new stdClass();
46 46
 		$balance_fee3->fee = 10500;
47 47
 		$balance_fee3->net = 10000;
48 48
 		$balance_fee3->currency = 'USD';
49 49
 
50
-		$this->assertEquals( 100.00, WC_Stripe_Helper::format_balance_fee( $balance_fee3, 'net' ) );
50
+		$this->assertEquals(100.00, WC_Stripe_Helper::format_balance_fee($balance_fee3, 'net'));
51 51
 
52 52
 		$balance_fee4 = new stdClass();
53 53
 		$balance_fee4->fee = 10500;
54 54
 		$balance_fee4->net = 10000;
55 55
 		$balance_fee4->currency = 'JPY';
56 56
 
57
-		$this->assertEquals( 10000, WC_Stripe_Helper::format_balance_fee( $balance_fee4, 'net' ) );
57
+		$this->assertEquals(10000, WC_Stripe_Helper::format_balance_fee($balance_fee4, 'net'));
58 58
 
59 59
 		$balance_fee5 = new stdClass();
60 60
 		$balance_fee5->fee = 10500;
61 61
 		$balance_fee5->net = 10000;
62 62
 		$balance_fee5->currency = 'USD';
63 63
 
64
-		$this->assertEquals( 105.00, WC_Stripe_Helper::format_balance_fee( $balance_fee5 ) );
64
+		$this->assertEquals(105.00, WC_Stripe_Helper::format_balance_fee($balance_fee5));
65 65
 
66
-		$this->assertInternalType( 'string', WC_Stripe_Helper::format_balance_fee( $balance_fee5 ) );
66
+		$this->assertInternalType('string', WC_Stripe_Helper::format_balance_fee($balance_fee5));
67 67
 	}
68 68
 
69 69
 	/**
@@ -76,27 +76,27 @@  discard block
 block discarded – undo
76 76
 			'expected' => 'Tests Store',
77 77
 		);
78 78
 
79
-		$this->assertEquals( $statement_descriptor1['expected'], WC_Stripe_Helper::clean_statement_descriptor( $statement_descriptor1['actual'] ) );
79
+		$this->assertEquals($statement_descriptor1['expected'], WC_Stripe_Helper::clean_statement_descriptor($statement_descriptor1['actual']));
80 80
 
81 81
 		$statement_descriptor2 = array(
82 82
 			'actual'   => 'Test\'s Store > Driving Course Range',
83 83
 			'expected' => 'Tests Store  Driving C',
84 84
 		);
85 85
 
86
-		$this->assertEquals( $statement_descriptor2['expected'], WC_Stripe_Helper::clean_statement_descriptor( $statement_descriptor2['actual'] ) );
86
+		$this->assertEquals($statement_descriptor2['expected'], WC_Stripe_Helper::clean_statement_descriptor($statement_descriptor2['actual']));
87 87
 
88 88
 		$statement_descriptor3 = array(
89 89
 			'actual'   => 'Test\'s Store < Driving Course Range',
90 90
 			'expected' => 'Tests Store  Driving C',
91 91
 		);
92 92
 
93
-		$this->assertEquals( $statement_descriptor3['expected'], WC_Stripe_Helper::clean_statement_descriptor( $statement_descriptor3['actual'] ) );
93
+		$this->assertEquals($statement_descriptor3['expected'], WC_Stripe_Helper::clean_statement_descriptor($statement_descriptor3['actual']));
94 94
 
95 95
 		$statement_descriptor4 = array(
96 96
 			'actual'   => 'Test\'s Store " Driving Course Range',
97 97
 			'expected' => 'Tests Store  Driving C',
98 98
 		);
99 99
 
100
-		$this->assertEquals( $statement_descriptor4['expected'], WC_Stripe_Helper::clean_statement_descriptor( $statement_descriptor4['actual'] ) );
100
+		$this->assertEquals($statement_descriptor4['expected'], WC_Stripe_Helper::clean_statement_descriptor($statement_descriptor4['actual']));
101 101
 	}
102 102
 }
Please login to merge, or discard this patch.
includes/class-wc-stripe-customer.php 2 patches
Doc Comments   -1 removed lines patch added patch discarded remove patch
@@ -213,7 +213,6 @@
 block discarded – undo
213 213
 	/**
214 214
 	 * Get a customers saved sources using their Stripe ID.
215 215
 	 *
216
-	 * @param  string $customer_id
217 216
 	 * @return array
218 217
 	 */
219 218
 	public function get_sources() {
Please login to merge, or discard this patch.
Spacing   +82 added lines, -82 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,10 +32,10 @@  discard block
 block discarded – undo
32 32
 	 * Constructor
33 33
 	 * @param int $user_id The WP user ID
34 34
 	 */
35
-	public function __construct( $user_id = 0 ) {
36
-		if ( $user_id ) {
37
-			$this->set_user_id( $user_id );
38
-			$this->set_id( get_user_meta( $user_id, '_stripe_customer_id', true ) );
35
+	public function __construct($user_id = 0) {
36
+		if ($user_id) {
37
+			$this->set_user_id($user_id);
38
+			$this->set_id(get_user_meta($user_id, '_stripe_customer_id', true));
39 39
 		}
40 40
 	}
41 41
 
@@ -51,15 +51,15 @@  discard block
 block discarded – undo
51 51
 	 * Set Stripe customer ID.
52 52
 	 * @param [type] $id [description]
53 53
 	 */
54
-	public function set_id( $id ) {
54
+	public function set_id($id) {
55 55
 		// Backwards compat for customer ID stored in array format. (Pre 3.0)
56
-		if ( is_array( $id ) && isset( $id['customer_id'] ) ) {
56
+		if (is_array($id) && isset($id['customer_id'])) {
57 57
 			$id = $id['customer_id'];
58 58
 
59
-			update_user_meta( $this->get_user_id(), '_stripe_customer_id', $id );
59
+			update_user_meta($this->get_user_id(), '_stripe_customer_id', $id);
60 60
 		}
61 61
 
62
-		$this->id = wc_clean( $id );
62
+		$this->id = wc_clean($id);
63 63
 	}
64 64
 
65 65
 	/**
@@ -67,15 +67,15 @@  discard block
 block discarded – undo
67 67
 	 * @return int
68 68
 	 */
69 69
 	public function get_user_id() {
70
-		return absint( $this->user_id );
70
+		return absint($this->user_id);
71 71
 	}
72 72
 
73 73
 	/**
74 74
 	 * Set User ID used by WordPress.
75 75
 	 * @param int $user_id
76 76
 	 */
77
-	public function set_user_id( $user_id ) {
78
-		$this->user_id = absint( $user_id );
77
+	public function set_user_id($user_id) {
78
+		$this->user_id = absint($user_id);
79 79
 	}
80 80
 
81 81
 	/**
@@ -83,13 +83,13 @@  discard block
 block discarded – undo
83 83
 	 * @return WP_User
84 84
 	 */
85 85
 	protected function get_user() {
86
-		return $this->get_user_id() ? get_user_by( 'id', $this->get_user_id() ) : false;
86
+		return $this->get_user_id() ? get_user_by('id', $this->get_user_id()) : false;
87 87
 	}
88 88
 
89 89
 	/**
90 90
 	 * Store data from the Stripe API about this customer
91 91
 	 */
92
-	public function set_customer_data( $data ) {
92
+	public function set_customer_data($data) {
93 93
 		$this->customer_data = $data;
94 94
 	}
95 95
 
@@ -98,25 +98,25 @@  discard block
 block discarded – undo
98 98
 	 * @param array $args
99 99
 	 * @return WP_Error|int
100 100
 	 */
101
-	public function create_customer( $args = array() ) {
102
-		$billing_email = isset( $_POST['billing_email'] ) ? filter_var( $_POST['billing_email'], FILTER_SANITIZE_EMAIL ) : '';
101
+	public function create_customer($args = array()) {
102
+		$billing_email = isset($_POST['billing_email']) ? filter_var($_POST['billing_email'], FILTER_SANITIZE_EMAIL) : '';
103 103
 		$user          = $this->get_user();
104 104
 
105
-		if ( $user ) {
106
-			$billing_first_name = get_user_meta( $user->ID, 'billing_first_name', true );
107
-			$billing_last_name  = get_user_meta( $user->ID, 'billing_last_name', true );
105
+		if ($user) {
106
+			$billing_first_name = get_user_meta($user->ID, 'billing_first_name', true);
107
+			$billing_last_name  = get_user_meta($user->ID, 'billing_last_name', true);
108 108
 
109 109
 			// If billing first name does not exists try the user first name.
110
-			if ( empty( $billing_first_name ) ) {
111
-				$billing_first_name = get_user_meta( $user->ID, 'first_name', true );
110
+			if (empty($billing_first_name)) {
111
+				$billing_first_name = get_user_meta($user->ID, 'first_name', true);
112 112
 			}
113 113
 
114 114
 			// If billing last name does not exists try the user last name.
115
-			if ( empty( $billing_last_name ) ) {
116
-				$billing_last_name = get_user_meta( $user->ID, 'last_name', true );
115
+			if (empty($billing_last_name)) {
116
+				$billing_last_name = get_user_meta($user->ID, 'last_name', true);
117 117
 			}
118 118
 
119
-			$description = __( 'Name', 'woocommerce-gateway-stripe' ) . ': ' . $billing_first_name . ' ' . $billing_last_name . ' ' . __( 'Username', 'woocommerce-gateway-stripe' ) . ': ' . $user->user_login;
119
+			$description = __('Name', 'woocommerce-gateway-stripe') . ': ' . $billing_first_name . ' ' . $billing_last_name . ' ' . __('Username', 'woocommerce-gateway-stripe') . ': ' . $user->user_login;
120 120
 
121 121
 			$defaults = array(
122 122
 				'email'       => $user->user_email,
@@ -131,24 +131,24 @@  discard block
 block discarded – undo
131 131
 
132 132
 		$metadata = array();
133 133
 
134
-		$defaults['metadata'] = apply_filters( 'wc_stripe_customer_metadata', $metadata, $user );
134
+		$defaults['metadata'] = apply_filters('wc_stripe_customer_metadata', $metadata, $user);
135 135
 
136
-		$args     = wp_parse_args( $args, $defaults );
137
-		$response = WC_Stripe_API::request( apply_filters( 'wc_stripe_create_customer_args', $args ), 'customers' );
136
+		$args     = wp_parse_args($args, $defaults);
137
+		$response = WC_Stripe_API::request(apply_filters('wc_stripe_create_customer_args', $args), 'customers');
138 138
 
139
-		if ( ! empty( $response->error ) ) {
140
-			throw new WC_Stripe_Exception( print_r( $response, true ), $response->error->message );
139
+		if ( ! empty($response->error)) {
140
+			throw new WC_Stripe_Exception(print_r($response, true), $response->error->message);
141 141
 		}
142 142
 
143
-		$this->set_id( $response->id );
143
+		$this->set_id($response->id);
144 144
 		$this->clear_cache();
145
-		$this->set_customer_data( $response );
145
+		$this->set_customer_data($response);
146 146
 
147
-		if ( $this->get_user_id() ) {
148
-			update_user_meta( $this->get_user_id(), '_stripe_customer_id', $response->id );
147
+		if ($this->get_user_id()) {
148
+			update_user_meta($this->get_user_id(), '_stripe_customer_id', $response->id);
149 149
 		}
150 150
 
151
-		do_action( 'woocommerce_stripe_add_customer', $args, $response );
151
+		do_action('woocommerce_stripe_add_customer', $args, $response);
152 152
 
153 153
 		return $response->id;
154 154
 	}
@@ -160,11 +160,11 @@  discard block
 block discarded – undo
160 160
 	 * @since 4.1.2
161 161
 	 * @param array $error
162 162
 	 */
163
-	public function is_no_such_customer_error( $error ) {
163
+	public function is_no_such_customer_error($error) {
164 164
 		return (
165 165
 			$error &&
166 166
 			'invalid_request_error' === $error->type &&
167
-			preg_match( '/No such customer/i', $error->message )
167
+			preg_match('/No such customer/i', $error->message)
168 168
 		);
169 169
 	}
170 170
 
@@ -174,9 +174,9 @@  discard block
 block discarded – undo
174 174
 	 * @param bool $retry
175 175
 	 * @return WP_Error|int
176 176
 	 */
177
-	public function add_source( $source_id, $retry = true ) {
178
-		if ( ! $this->get_id() ) {
179
-			$this->set_id( $this->create_customer() );
177
+	public function add_source($source_id, $retry = true) {
178
+		if ( ! $this->get_id()) {
179
+			$this->set_id($this->create_customer());
180 180
 		}
181 181
 
182 182
 		$response = WC_Stripe_API::request(
@@ -188,63 +188,63 @@  discard block
 block discarded – undo
188 188
 
189 189
 		$wc_token = false;
190 190
 
191
-		if ( ! empty( $response->error ) ) {
191
+		if ( ! empty($response->error)) {
192 192
 			// It is possible the WC user once was linked to a customer on Stripe
193 193
 			// but no longer exists. Instead of failing, lets try to create a
194 194
 			// new customer.
195
-			if ( $this->is_no_such_customer_error( $response->error ) ) {
196
-				delete_user_meta( $this->get_user_id(), '_stripe_customer_id' );
195
+			if ($this->is_no_such_customer_error($response->error)) {
196
+				delete_user_meta($this->get_user_id(), '_stripe_customer_id');
197 197
 				$this->create_customer();
198
-				return $this->add_source( $source_id, false );
198
+				return $this->add_source($source_id, false);
199 199
 			} else {
200 200
 				return $response;
201 201
 			}
202
-		} elseif ( empty( $response->id ) ) {
203
-			return new WP_Error( 'error', __( 'Unable to add payment source.', 'woocommerce-gateway-stripe' ) );
202
+		} elseif (empty($response->id)) {
203
+			return new WP_Error('error', __('Unable to add payment source.', 'woocommerce-gateway-stripe'));
204 204
 		}
205 205
 
206 206
 		// Add token to WooCommerce.
207
-		if ( $this->get_user_id() && class_exists( 'WC_Payment_Token_CC' ) ) {
208
-			if ( ! empty( $response->type ) ) {
209
-				switch ( $response->type ) {
207
+		if ($this->get_user_id() && class_exists('WC_Payment_Token_CC')) {
208
+			if ( ! empty($response->type)) {
209
+				switch ($response->type) {
210 210
 					case 'alipay':
211 211
 						break;
212 212
 					case 'sepa_debit':
213 213
 						$wc_token = new WC_Payment_Token_SEPA();
214
-						$wc_token->set_token( $response->id );
215
-						$wc_token->set_gateway_id( 'stripe_sepa' );
216
-						$wc_token->set_last4( $response->sepa_debit->last4 );
214
+						$wc_token->set_token($response->id);
215
+						$wc_token->set_gateway_id('stripe_sepa');
216
+						$wc_token->set_last4($response->sepa_debit->last4);
217 217
 						break;
218 218
 					default:
219
-						if ( 'source' === $response->object && 'card' === $response->type ) {
219
+						if ('source' === $response->object && 'card' === $response->type) {
220 220
 							$wc_token = new WC_Payment_Token_CC();
221
-							$wc_token->set_token( $response->id );
222
-							$wc_token->set_gateway_id( 'stripe' );
223
-							$wc_token->set_card_type( strtolower( $response->card->brand ) );
224
-							$wc_token->set_last4( $response->card->last4 );
225
-							$wc_token->set_expiry_month( $response->card->exp_month );
226
-							$wc_token->set_expiry_year( $response->card->exp_year );
221
+							$wc_token->set_token($response->id);
222
+							$wc_token->set_gateway_id('stripe');
223
+							$wc_token->set_card_type(strtolower($response->card->brand));
224
+							$wc_token->set_last4($response->card->last4);
225
+							$wc_token->set_expiry_month($response->card->exp_month);
226
+							$wc_token->set_expiry_year($response->card->exp_year);
227 227
 						}
228 228
 						break;
229 229
 				}
230 230
 			} else {
231 231
 				// Legacy.
232 232
 				$wc_token = new WC_Payment_Token_CC();
233
-				$wc_token->set_token( $response->id );
234
-				$wc_token->set_gateway_id( 'stripe' );
235
-				$wc_token->set_card_type( strtolower( $response->brand ) );
236
-				$wc_token->set_last4( $response->last4 );
237
-				$wc_token->set_expiry_month( $response->exp_month );
238
-				$wc_token->set_expiry_year( $response->exp_year );
233
+				$wc_token->set_token($response->id);
234
+				$wc_token->set_gateway_id('stripe');
235
+				$wc_token->set_card_type(strtolower($response->brand));
236
+				$wc_token->set_last4($response->last4);
237
+				$wc_token->set_expiry_month($response->exp_month);
238
+				$wc_token->set_expiry_year($response->exp_year);
239 239
 			}
240 240
 
241
-			$wc_token->set_user_id( $this->get_user_id() );
241
+			$wc_token->set_user_id($this->get_user_id());
242 242
 			$wc_token->save();
243 243
 		}
244 244
 
245 245
 		$this->clear_cache();
246 246
 
247
-		do_action( 'woocommerce_stripe_add_source', $this->get_id(), $wc_token, $response, $source_id );
247
+		do_action('woocommerce_stripe_add_source', $this->get_id(), $wc_token, $response, $source_id);
248 248
 
249 249
 		return $response->id;
250 250
 	}
@@ -256,11 +256,11 @@  discard block
 block discarded – undo
256 256
 	 * @return array
257 257
 	 */
258 258
 	public function get_sources() {
259
-		if ( ! $this->get_id() ) {
259
+		if ( ! $this->get_id()) {
260 260
 			return array();
261 261
 		}
262 262
 
263
-		$sources = get_transient( 'stripe_sources_' . $this->get_id() );
263
+		$sources = get_transient('stripe_sources_' . $this->get_id());
264 264
 
265 265
 		$response = WC_Stripe_API::request(
266 266
 			array(
@@ -270,32 +270,32 @@  discard block
 block discarded – undo
270 270
 			'GET'
271 271
 		);
272 272
 
273
-		if ( ! empty( $response->error ) ) {
273
+		if ( ! empty($response->error)) {
274 274
 			return array();
275 275
 		}
276 276
 
277
-		if ( is_array( $response->data ) ) {
277
+		if (is_array($response->data)) {
278 278
 			$sources = $response->data;
279 279
 		}
280 280
 
281
-		return empty( $sources ) ? array() : $sources;
281
+		return empty($sources) ? array() : $sources;
282 282
 	}
283 283
 
284 284
 	/**
285 285
 	 * Delete a source from stripe.
286 286
 	 * @param string $source_id
287 287
 	 */
288
-	public function delete_source( $source_id ) {
289
-		if ( ! $this->get_id() ) {
288
+	public function delete_source($source_id) {
289
+		if ( ! $this->get_id()) {
290 290
 			return false;
291 291
 		}
292 292
 
293
-		$response = WC_Stripe_API::request( array(), 'customers/' . $this->get_id() . '/sources/' . sanitize_text_field( $source_id ), 'DELETE' );
293
+		$response = WC_Stripe_API::request(array(), 'customers/' . $this->get_id() . '/sources/' . sanitize_text_field($source_id), 'DELETE');
294 294
 
295 295
 		$this->clear_cache();
296 296
 
297
-		if ( empty( $response->error ) ) {
298
-			do_action( 'wc_stripe_delete_source', $this->get_id(), $response );
297
+		if (empty($response->error)) {
298
+			do_action('wc_stripe_delete_source', $this->get_id(), $response);
299 299
 
300 300
 			return true;
301 301
 		}
@@ -307,10 +307,10 @@  discard block
 block discarded – undo
307 307
 	 * Set default source in Stripe
308 308
 	 * @param string $source_id
309 309
 	 */
310
-	public function set_default_source( $source_id ) {
310
+	public function set_default_source($source_id) {
311 311
 		$response = WC_Stripe_API::request(
312 312
 			array(
313
-				'default_source' => sanitize_text_field( $source_id ),
313
+				'default_source' => sanitize_text_field($source_id),
314 314
 			),
315 315
 			'customers/' . $this->get_id(),
316 316
 			'POST'
@@ -318,8 +318,8 @@  discard block
 block discarded – undo
318 318
 
319 319
 		$this->clear_cache();
320 320
 
321
-		if ( empty( $response->error ) ) {
322
-			do_action( 'wc_stripe_set_default_source', $this->get_id(), $response );
321
+		if (empty($response->error)) {
322
+			do_action('wc_stripe_set_default_source', $this->get_id(), $response);
323 323
 
324 324
 			return true;
325 325
 		}
@@ -331,8 +331,8 @@  discard block
 block discarded – undo
331 331
 	 * Deletes caches for this users cards.
332 332
 	 */
333 333
 	public function clear_cache() {
334
-		delete_transient( 'stripe_sources_' . $this->get_id() );
335
-		delete_transient( 'stripe_customer_' . $this->get_id() );
334
+		delete_transient('stripe_sources_' . $this->get_id());
335
+		delete_transient('stripe_customer_' . $this->get_id());
336 336
 		$this->customer_data = array();
337 337
 	}
338 338
 }
Please login to merge, or discard this patch.
includes/payment-methods/class-wc-stripe-payment-request.php 2 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -104,7 +104,7 @@
 block discarded – undo
104 104
 	 * Get this instance.
105 105
 	 *
106 106
 	 * @since 4.0.6
107
-	 * @return class
107
+	 * @return WC_Stripe_Payment_Request
108 108
 	 */
109 109
 	public static function instance() {
110 110
 		return self::$_this;
Please login to merge, or discard this patch.
Spacing   +298 added lines, -298 removed lines patch added patch discarded remove patch
@@ -6,7 +6,7 @@  discard block
 block discarded – undo
6 6
  * @since   4.0.0
7 7
  */
8 8
 
9
-if ( ! defined( 'ABSPATH' ) ) {
9
+if ( ! defined('ABSPATH')) {
10 10
 	exit;
11 11
 }
12 12
 
@@ -64,41 +64,41 @@  discard block
 block discarded – undo
64 64
 	 */
65 65
 	public function __construct() {
66 66
 		self::$_this            = $this;
67
-		$this->stripe_settings  = get_option( 'woocommerce_stripe_settings', array() );
68
-		$this->testmode         = ( ! empty( $this->stripe_settings['testmode'] ) && 'yes' === $this->stripe_settings['testmode'] ) ? true : false;
69
-		$this->publishable_key  = ! empty( $this->stripe_settings['publishable_key'] ) ? $this->stripe_settings['publishable_key'] : '';
70
-		$this->secret_key       = ! empty( $this->stripe_settings['secret_key'] ) ? $this->stripe_settings['secret_key'] : '';
71
-		$this->total_label      = ! empty( $this->stripe_settings['statement_descriptor'] ) ? WC_Stripe_Helper::clean_statement_descriptor( $this->stripe_settings['statement_descriptor'] ) : '';
67
+		$this->stripe_settings  = get_option('woocommerce_stripe_settings', array());
68
+		$this->testmode         = ( ! empty($this->stripe_settings['testmode']) && 'yes' === $this->stripe_settings['testmode']) ? true : false;
69
+		$this->publishable_key  = ! empty($this->stripe_settings['publishable_key']) ? $this->stripe_settings['publishable_key'] : '';
70
+		$this->secret_key       = ! empty($this->stripe_settings['secret_key']) ? $this->stripe_settings['secret_key'] : '';
71
+		$this->total_label      = ! empty($this->stripe_settings['statement_descriptor']) ? WC_Stripe_Helper::clean_statement_descriptor($this->stripe_settings['statement_descriptor']) : '';
72 72
 
73
-		if ( $this->testmode ) {
74
-			$this->publishable_key = ! empty( $this->stripe_settings['test_publishable_key'] ) ? $this->stripe_settings['test_publishable_key'] : '';
75
-			$this->secret_key      = ! empty( $this->stripe_settings['test_secret_key'] ) ? $this->stripe_settings['test_secret_key'] : '';
73
+		if ($this->testmode) {
74
+			$this->publishable_key = ! empty($this->stripe_settings['test_publishable_key']) ? $this->stripe_settings['test_publishable_key'] : '';
75
+			$this->secret_key      = ! empty($this->stripe_settings['test_secret_key']) ? $this->stripe_settings['test_secret_key'] : '';
76 76
 		}
77 77
 
78
-		$this->total_label = str_replace( "'", '', $this->total_label ) . apply_filters( 'wc_stripe_payment_request_total_label_suffix', ' (via WooCommerce)' );
78
+		$this->total_label = str_replace("'", '', $this->total_label) . apply_filters('wc_stripe_payment_request_total_label_suffix', ' (via WooCommerce)');
79 79
 
80 80
 		// Checks if Stripe Gateway is enabled.
81
-		if ( empty( $this->stripe_settings ) || ( isset( $this->stripe_settings['enabled'] ) && 'yes' !== $this->stripe_settings['enabled'] ) ) {
81
+		if (empty($this->stripe_settings) || (isset($this->stripe_settings['enabled']) && 'yes' !== $this->stripe_settings['enabled'])) {
82 82
 			return;
83 83
 		}
84 84
 
85 85
 		// Checks if Payment Request is enabled.
86
-		if ( ! isset( $this->stripe_settings['payment_request'] ) || 'yes' !== $this->stripe_settings['payment_request'] ) {
86
+		if ( ! isset($this->stripe_settings['payment_request']) || 'yes' !== $this->stripe_settings['payment_request']) {
87 87
 			return;
88 88
 		}
89 89
 
90 90
 		// Don't load for change payment method page.
91
-		if ( isset( $_GET['change_payment_method'] ) ) {
91
+		if (isset($_GET['change_payment_method'])) {
92 92
 			return;
93 93
 		}
94 94
 
95
-		$wc_default_country = substr( get_option( 'woocommerce_default_country' ), 0, 2 );
95
+		$wc_default_country = substr(get_option('woocommerce_default_country'), 0, 2);
96 96
 
97
-		if ( ! in_array( $wc_default_country, $this->get_stripe_supported_countries() ) ) {
97
+		if ( ! in_array($wc_default_country, $this->get_stripe_supported_countries())) {
98 98
 			return;
99 99
 		}
100 100
 
101
-		add_action( 'template_redirect', array( $this, 'set_session' ) );
101
+		add_action('template_redirect', array($this, 'set_session'));
102 102
 		$this->init();
103 103
 	}
104 104
 
@@ -109,7 +109,7 @@  discard block
 block discarded – undo
109 109
 	 * @return array The list of countries.
110 110
 	 */
111 111
 	public function get_stripe_supported_countries() {
112
-		return apply_filters( 'wc_stripe_supported_countries', array( 'AT', 'AU', 'BE', 'BR', 'CA', 'CH', 'DE', 'DK', 'EE', 'ES', 'FI', 'FR', 'GB', 'HK', 'IE', 'IN', 'IT', 'JP', 'LT', 'LU', 'LV', 'MX', 'NL', 'NZ', 'NO', 'PH', 'PL', 'PR', 'PT', 'RO', 'SE', 'SG', 'SK', 'US' ) );
112
+		return apply_filters('wc_stripe_supported_countries', array('AT', 'AU', 'BE', 'BR', 'CA', 'CH', 'DE', 'DK', 'EE', 'ES', 'FI', 'FR', 'GB', 'HK', 'IE', 'IN', 'IT', 'JP', 'LT', 'LU', 'LV', 'MX', 'NL', 'NZ', 'NO', 'PH', 'PL', 'PR', 'PT', 'RO', 'SE', 'SG', 'SK', 'US'));
113 113
 	}
114 114
 
115 115
 	/**
@@ -119,7 +119,7 @@  discard block
 block discarded – undo
119 119
 	 * @return bool
120 120
 	 */
121 121
 	public function are_keys_set() {
122
-		if ( empty( $this->secret_key ) || empty( $this->publishable_key ) ) {
122
+		if (empty($this->secret_key) || empty($this->publishable_key)) {
123 123
 			return false;
124 124
 		}
125 125
 
@@ -143,18 +143,18 @@  discard block
 block discarded – undo
143 143
 	 * @since 4.0.0
144 144
 	 */
145 145
 	public function set_session() {
146
-		if ( ! is_product() || ( isset( WC()->session ) && WC()->session->has_session() ) ) {
146
+		if ( ! is_product() || (isset(WC()->session) && WC()->session->has_session())) {
147 147
 			return;
148 148
 		}
149 149
 
150
-		$session_class = apply_filters( 'woocommerce_session_handler', 'WC_Session_Handler' );
150
+		$session_class = apply_filters('woocommerce_session_handler', 'WC_Session_Handler');
151 151
 		$wc_session    = new $session_class();
152 152
 
153
-		if ( version_compare( WC_VERSION, '3.3', '>=' ) ) {
153
+		if (version_compare(WC_VERSION, '3.3', '>=')) {
154 154
 			$wc_session->init();
155 155
 		}
156 156
 
157
-		$wc_session->set_customer_session_cookie( true );
157
+		$wc_session->set_customer_session_cookie(true);
158 158
 	}
159 159
 
160 160
 	/**
@@ -164,40 +164,40 @@  discard block
 block discarded – undo
164 164
 	 * @version 4.0.0
165 165
 	 */
166 166
 	public function init() {
167
-		add_action( 'wp_enqueue_scripts', array( $this, 'scripts' ) );
167
+		add_action('wp_enqueue_scripts', array($this, 'scripts'));
168 168
 
169 169
 		/*
170 170
 		 * In order to display the Payment Request button in the correct position,
171 171
 		 * a new hook was added to WooCommerce 3.0. In older versions of WooCommerce,
172 172
 		 * CSS is used to position the button.
173 173
 		 */
174
-		if ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ) {
175
-			add_action( 'woocommerce_after_add_to_cart_button', array( $this, 'display_payment_request_button_html' ), 1 );
176
-			add_action( 'woocommerce_after_add_to_cart_button', array( $this, 'display_payment_request_button_separator_html' ), 2 );
174
+		if (WC_Stripe_Helper::is_wc_lt('3.0')) {
175
+			add_action('woocommerce_after_add_to_cart_button', array($this, 'display_payment_request_button_html'), 1);
176
+			add_action('woocommerce_after_add_to_cart_button', array($this, 'display_payment_request_button_separator_html'), 2);
177 177
 		} else {
178
-			add_action( 'woocommerce_after_add_to_cart_quantity', array( $this, 'display_payment_request_button_html' ), 1 );
179
-			add_action( 'woocommerce_after_add_to_cart_quantity', array( $this, 'display_payment_request_button_separator_html' ), 2 );
178
+			add_action('woocommerce_after_add_to_cart_quantity', array($this, 'display_payment_request_button_html'), 1);
179
+			add_action('woocommerce_after_add_to_cart_quantity', array($this, 'display_payment_request_button_separator_html'), 2);
180 180
 		}
181 181
 
182
-		add_action( 'woocommerce_proceed_to_checkout', array( $this, 'display_payment_request_button_html' ), 1 );
183
-		add_action( 'woocommerce_proceed_to_checkout', array( $this, 'display_payment_request_button_separator_html' ), 2 );
182
+		add_action('woocommerce_proceed_to_checkout', array($this, 'display_payment_request_button_html'), 1);
183
+		add_action('woocommerce_proceed_to_checkout', array($this, 'display_payment_request_button_separator_html'), 2);
184 184
 
185
-		add_action( 'woocommerce_checkout_before_customer_details', array( $this, 'display_payment_request_button_html' ), 1 );
186
-		add_action( 'woocommerce_checkout_before_customer_details', array( $this, 'display_payment_request_button_separator_html' ), 2 );
185
+		add_action('woocommerce_checkout_before_customer_details', array($this, 'display_payment_request_button_html'), 1);
186
+		add_action('woocommerce_checkout_before_customer_details', array($this, 'display_payment_request_button_separator_html'), 2);
187 187
 
188
-		add_action( 'wc_ajax_wc_stripe_get_cart_details', array( $this, 'ajax_get_cart_details' ) );
189
-		add_action( 'wc_ajax_wc_stripe_get_shipping_options', array( $this, 'ajax_get_shipping_options' ) );
190
-		add_action( 'wc_ajax_wc_stripe_update_shipping_method', array( $this, 'ajax_update_shipping_method' ) );
191
-		add_action( 'wc_ajax_wc_stripe_create_order', array( $this, 'ajax_create_order' ) );
192
-		add_action( 'wc_ajax_wc_stripe_add_to_cart', array( $this, 'ajax_add_to_cart' ) );
193
-		add_action( 'wc_ajax_wc_stripe_get_selected_product_data', array( $this, 'ajax_get_selected_product_data' ) );
194
-		add_action( 'wc_ajax_wc_stripe_clear_cart', array( $this, 'ajax_clear_cart' ) );
195
-		add_action( 'wc_ajax_wc_stripe_log_errors', array( $this, 'ajax_log_errors' ) );
188
+		add_action('wc_ajax_wc_stripe_get_cart_details', array($this, 'ajax_get_cart_details'));
189
+		add_action('wc_ajax_wc_stripe_get_shipping_options', array($this, 'ajax_get_shipping_options'));
190
+		add_action('wc_ajax_wc_stripe_update_shipping_method', array($this, 'ajax_update_shipping_method'));
191
+		add_action('wc_ajax_wc_stripe_create_order', array($this, 'ajax_create_order'));
192
+		add_action('wc_ajax_wc_stripe_add_to_cart', array($this, 'ajax_add_to_cart'));
193
+		add_action('wc_ajax_wc_stripe_get_selected_product_data', array($this, 'ajax_get_selected_product_data'));
194
+		add_action('wc_ajax_wc_stripe_clear_cart', array($this, 'ajax_clear_cart'));
195
+		add_action('wc_ajax_wc_stripe_log_errors', array($this, 'ajax_log_errors'));
196 196
 
197
-		add_filter( 'woocommerce_gateway_title', array( $this, 'filter_gateway_title' ), 10, 2 );
198
-		add_filter( 'woocommerce_validate_postcode', array( $this, 'postal_code_validation' ), 10, 3 );
197
+		add_filter('woocommerce_gateway_title', array($this, 'filter_gateway_title'), 10, 2);
198
+		add_filter('woocommerce_validate_postcode', array($this, 'postal_code_validation'), 10, 3);
199 199
 
200
-		add_action( 'woocommerce_checkout_order_processed', array( $this, 'add_order_meta' ), 10, 2 );
200
+		add_action('woocommerce_checkout_order_processed', array($this, 'add_order_meta'), 10, 2);
201 201
 	}
202 202
 
203 203
 	/**
@@ -208,7 +208,7 @@  discard block
 block discarded – undo
208 208
 	 * @return string
209 209
 	 */
210 210
 	public function get_button_type() {
211
-		return isset( $this->stripe_settings['payment_request_button_type'] ) ? $this->stripe_settings['payment_request_button_type'] : 'default';
211
+		return isset($this->stripe_settings['payment_request_button_type']) ? $this->stripe_settings['payment_request_button_type'] : 'default';
212 212
 	}
213 213
 
214 214
 	/**
@@ -219,7 +219,7 @@  discard block
 block discarded – undo
219 219
 	 * @return string
220 220
 	 */
221 221
 	public function get_button_theme() {
222
-		return isset( $this->stripe_settings['payment_request_button_theme'] ) ? $this->stripe_settings['payment_request_button_theme'] : 'dark';
222
+		return isset($this->stripe_settings['payment_request_button_theme']) ? $this->stripe_settings['payment_request_button_theme'] : 'dark';
223 223
 	}
224 224
 
225 225
 	/**
@@ -230,7 +230,7 @@  discard block
 block discarded – undo
230 230
 	 * @return string
231 231
 	 */
232 232
 	public function get_button_height() {
233
-		return isset( $this->stripe_settings['payment_request_button_height'] ) ? str_replace( 'px', '', $this->stripe_settings['payment_request_button_height'] ) : '64';
233
+		return isset($this->stripe_settings['payment_request_button_height']) ? str_replace('px', '', $this->stripe_settings['payment_request_button_height']) : '64';
234 234
 	}
235 235
 
236 236
 	/**
@@ -240,40 +240,40 @@  discard block
 block discarded – undo
240 240
 	 * @version 4.0.0
241 241
 	 */
242 242
 	public function get_product_data() {
243
-		if ( ! is_product() ) {
243
+		if ( ! is_product()) {
244 244
 			return false;
245 245
 		}
246 246
 
247 247
 		global $post;
248 248
 
249
-		$product = wc_get_product( $post->ID );
249
+		$product = wc_get_product($post->ID);
250 250
 
251 251
 		$data  = array();
252 252
 		$items = array();
253 253
 
254 254
 		$items[] = array(
255
-			'label'  => WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $product->name : $product->get_name(),
256
-			'amount' => WC_Stripe_Helper::get_stripe_amount( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $product->price : $product->get_price() ),
255
+			'label'  => WC_Stripe_Helper::is_wc_lt('3.0') ? $product->name : $product->get_name(),
256
+			'amount' => WC_Stripe_Helper::get_stripe_amount(WC_Stripe_Helper::is_wc_lt('3.0') ? $product->price : $product->get_price()),
257 257
 		);
258 258
 
259
-		if ( wc_tax_enabled() ) {
259
+		if (wc_tax_enabled()) {
260 260
 			$items[] = array(
261
-				'label'   => __( 'Tax', 'woocommerce-gateway-stripe' ),
261
+				'label'   => __('Tax', 'woocommerce-gateway-stripe'),
262 262
 				'amount'  => 0,
263 263
 				'pending' => true,
264 264
 			);
265 265
 		}
266 266
 
267
-		if ( wc_shipping_enabled() && $product->needs_shipping() ) {
267
+		if (wc_shipping_enabled() && $product->needs_shipping()) {
268 268
 			$items[] = array(
269
-				'label'   => __( 'Shipping', 'woocommerce-gateway-stripe' ),
269
+				'label'   => __('Shipping', 'woocommerce-gateway-stripe'),
270 270
 				'amount'  => 0,
271 271
 				'pending' => true,
272 272
 			);
273 273
 
274 274
 			$data['shippingOptions'] = array(
275 275
 				'id'     => 'pending',
276
-				'label'  => __( 'Pending', 'woocommerce-gateway-stripe' ),
276
+				'label'  => __('Pending', 'woocommerce-gateway-stripe'),
277 277
 				'detail' => '',
278 278
 				'amount' => 0,
279 279
 			);
@@ -281,41 +281,41 @@  discard block
 block discarded – undo
281 281
 
282 282
 		$data['displayItems'] = $items;
283 283
 		$data['total']        = array(
284
-			'label'   => apply_filters( 'wc_stripe_payment_request_total_label', $this->total_label ),
285
-			'amount'  => WC_Stripe_Helper::get_stripe_amount( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $product->price : $product->get_price() ),
284
+			'label'   => apply_filters('wc_stripe_payment_request_total_label', $this->total_label),
285
+			'amount'  => WC_Stripe_Helper::get_stripe_amount(WC_Stripe_Helper::is_wc_lt('3.0') ? $product->price : $product->get_price()),
286 286
 			'pending' => true,
287 287
 		);
288 288
 
289
-		$data['requestShipping'] = ( wc_shipping_enabled() && $product->needs_shipping() );
290
-		$data['currency']        = strtolower( get_woocommerce_currency() );
291
-		$data['country_code']    = substr( get_option( 'woocommerce_default_country' ), 0, 2 );
289
+		$data['requestShipping'] = (wc_shipping_enabled() && $product->needs_shipping());
290
+		$data['currency']        = strtolower(get_woocommerce_currency());
291
+		$data['country_code']    = substr(get_option('woocommerce_default_country'), 0, 2);
292 292
 
293
-		return apply_filters( 'wc_stripe_payment_request_product_data', $data, $product );
293
+		return apply_filters('wc_stripe_payment_request_product_data', $data, $product);
294 294
 	}
295 295
 
296 296
 	/**
297 297
 	 * Filters the gateway title to reflect Payment Request type
298 298
 	 *
299 299
 	 */
300
-	public function filter_gateway_title( $title, $id ) {
300
+	public function filter_gateway_title($title, $id) {
301 301
 		global $post;
302 302
 
303
-		if ( ! is_object( $post ) ) {
303
+		if ( ! is_object($post)) {
304 304
 			return $title;
305 305
 		}
306 306
 
307
-		if ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ) {
308
-			$method_title = get_post_meta( $post->ID, '_payment_method_title', true );
307
+		if (WC_Stripe_Helper::is_wc_lt('3.0')) {
308
+			$method_title = get_post_meta($post->ID, '_payment_method_title', true);
309 309
 		} else {
310
-			$order        = wc_get_order( $post->ID );
311
-			$method_title = is_object( $order ) ? $order->get_payment_method_title() : '';
310
+			$order        = wc_get_order($post->ID);
311
+			$method_title = is_object($order) ? $order->get_payment_method_title() : '';
312 312
 		}
313 313
 
314
-		if ( 'stripe' === $id && ! empty( $method_title ) && 'Apple Pay (Stripe)' === $method_title ) {
314
+		if ('stripe' === $id && ! empty($method_title) && 'Apple Pay (Stripe)' === $method_title) {
315 315
 			return $method_title;
316 316
 		}
317 317
 
318
-		if ( 'stripe' === $id && ! empty( $method_title ) && 'Chrome Payment Request (Stripe)' === $method_title ) {
318
+		if ('stripe' === $id && ! empty($method_title) && 'Chrome Payment Request (Stripe)' === $method_title) {
319 319
 			return $method_title;
320 320
 		}
321 321
 
@@ -328,16 +328,16 @@  discard block
 block discarded – undo
328 328
 	 * @since 3.1.4
329 329
 	 * @version 4.0.0
330 330
 	 */
331
-	public function postal_code_validation( $valid, $postcode, $country ) {
331
+	public function postal_code_validation($valid, $postcode, $country) {
332 332
 		$gateways = WC()->payment_gateways->get_available_payment_gateways();
333 333
 
334
-		if ( ! isset( $gateways['stripe'] ) ) {
334
+		if ( ! isset($gateways['stripe'])) {
335 335
 			return $valid;
336 336
 		}
337 337
 
338
-		$payment_request_type = isset( $_POST['payment_request_type'] ) ? wc_clean( $_POST['payment_request_type'] ) : '';
338
+		$payment_request_type = isset($_POST['payment_request_type']) ? wc_clean($_POST['payment_request_type']) : '';
339 339
 
340
-		if ( 'apple_pay' !== $payment_request_type ) {
340
+		if ('apple_pay' !== $payment_request_type) {
341 341
 			return $valid;
342 342
 		}
343 343
 
@@ -347,7 +347,7 @@  discard block
 block discarded – undo
347 347
 		 * the order and not let it go through. The remedy for now is just to remove this validation.
348 348
 		 * Note that this only works with shipping providers that don't validate full postal codes.
349 349
 		 */
350
-		if ( 'GB' === $country || 'CA' === $country ) {
350
+		if ('GB' === $country || 'CA' === $country) {
351 351
 			return true;
352 352
 		}
353 353
 
@@ -362,29 +362,29 @@  discard block
 block discarded – undo
362 362
 	 * @param int $order_id
363 363
 	 * @param array $posted_data The posted data from checkout form.
364 364
 	 */
365
-	public function add_order_meta( $order_id, $posted_data ) {
366
-		if ( empty( $_POST['payment_request_type'] ) ) {
365
+	public function add_order_meta($order_id, $posted_data) {
366
+		if (empty($_POST['payment_request_type'])) {
367 367
 			return;
368 368
 		}
369 369
 
370
-		$order = wc_get_order( $order_id );
370
+		$order = wc_get_order($order_id);
371 371
 
372
-		$payment_request_type = wc_clean( $_POST['payment_request_type'] );
372
+		$payment_request_type = wc_clean($_POST['payment_request_type']);
373 373
 
374
-		if ( 'apple_pay' === $payment_request_type ) {
375
-			if ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ) {
376
-				update_post_meta( $order_id, '_payment_method_title', 'Apple Pay (Stripe)' );
374
+		if ('apple_pay' === $payment_request_type) {
375
+			if (WC_Stripe_Helper::is_wc_lt('3.0')) {
376
+				update_post_meta($order_id, '_payment_method_title', 'Apple Pay (Stripe)');
377 377
 			} else {
378
-				$order->set_payment_method_title( 'Apple Pay (Stripe)' );
378
+				$order->set_payment_method_title('Apple Pay (Stripe)');
379 379
 				$order->save();
380 380
 			}
381 381
 		}
382 382
 
383
-		if ( 'payment_request_api' === $payment_request_type ) {
384
-			if ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ) {
385
-				update_post_meta( $order_id, '_payment_method_title', 'Chrome Payment Request (Stripe)' );
383
+		if ('payment_request_api' === $payment_request_type) {
384
+			if (WC_Stripe_Helper::is_wc_lt('3.0')) {
385
+				update_post_meta($order_id, '_payment_method_title', 'Chrome Payment Request (Stripe)');
386 386
 			} else {
387
-				$order->set_payment_method_title( 'Chrome Payment Request (Stripe)' );
387
+				$order->set_payment_method_title('Chrome Payment Request (Stripe)');
388 388
 				$order->save();
389 389
 			}
390 390
 		}
@@ -421,15 +421,15 @@  discard block
 block discarded – undo
421 421
 	 * @return bool
422 422
 	 */
423 423
 	public function allowed_items_in_cart() {
424
-		foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {
425
-			$_product = apply_filters( 'woocommerce_cart_item_product', $cart_item['data'], $cart_item, $cart_item_key );
424
+		foreach (WC()->cart->get_cart() as $cart_item_key => $cart_item) {
425
+			$_product = apply_filters('woocommerce_cart_item_product', $cart_item['data'], $cart_item, $cart_item_key);
426 426
 
427
-			if ( ! in_array( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $_product->product_type : $_product->get_type() ), $this->supported_product_types() ) ) {
427
+			if ( ! in_array((WC_Stripe_Helper::is_wc_lt('3.0') ? $_product->product_type : $_product->get_type()), $this->supported_product_types())) {
428 428
 				return false;
429 429
 			}
430 430
 
431 431
 			// Pre Orders compatbility where we don't support charge upon release.
432
-			if ( class_exists( 'WC_Pre_Orders_Order' ) && WC_Pre_Orders_Cart::cart_contains_pre_order() && WC_Pre_Orders_Product::product_is_charged_upon_release( WC_Pre_Orders_Cart::get_pre_order_product() ) ) {
432
+			if (class_exists('WC_Pre_Orders_Order') && WC_Pre_Orders_Cart::cart_contains_pre_order() && WC_Pre_Orders_Product::product_is_charged_upon_release(WC_Pre_Orders_Cart::get_pre_order_product())) {
433 433
 				return false;
434 434
 			}
435 435
 		}
@@ -445,83 +445,83 @@  discard block
 block discarded – undo
445 445
 	 */
446 446
 	public function scripts() {
447 447
 		// If keys are not set bail.
448
-		if ( ! $this->are_keys_set() ) {
449
-			WC_Stripe_Logger::log( 'Keys are not set correctly.' );
448
+		if ( ! $this->are_keys_set()) {
449
+			WC_Stripe_Logger::log('Keys are not set correctly.');
450 450
 			return;
451 451
 		}
452 452
 
453 453
 		// If no SSL bail.
454
-		if ( ! $this->testmode && ! is_ssl() ) {
455
-			WC_Stripe_Logger::log( 'Stripe Payment Request live mode requires SSL.' );
454
+		if ( ! $this->testmode && ! is_ssl()) {
455
+			WC_Stripe_Logger::log('Stripe Payment Request live mode requires SSL.');
456 456
 			return;
457 457
 		}
458 458
 
459
-		if ( ! is_product() && ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) ) {
459
+		if ( ! is_product() && ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order'])) {
460 460
 			return;
461 461
 		}
462 462
 
463
-		if ( is_product() ) {
463
+		if (is_product()) {
464 464
 			global $post;
465 465
 
466
-			$product = wc_get_product( $post->ID );
466
+			$product = wc_get_product($post->ID);
467 467
 
468
-			if ( ! is_object( $product ) || ! in_array( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $product->product_type : $product->get_type() ), $this->supported_product_types() ) ) {
468
+			if ( ! is_object($product) || ! in_array((WC_Stripe_Helper::is_wc_lt('3.0') ? $product->product_type : $product->get_type()), $this->supported_product_types())) {
469 469
 				return;
470 470
 			}
471 471
 
472
-			if ( apply_filters( 'wc_stripe_hide_payment_request_on_product_page', false, $post ) ) {
472
+			if (apply_filters('wc_stripe_hide_payment_request_on_product_page', false, $post)) {
473 473
 				return;
474 474
 			}
475 475
 		}
476 476
 
477
-		$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
477
+		$suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';
478 478
 
479 479
 		$stripe_params = array(
480
-			'ajax_url'        => WC_AJAX::get_endpoint( '%%endpoint%%' ),
480
+			'ajax_url'        => WC_AJAX::get_endpoint('%%endpoint%%'),
481 481
 			'stripe'          => array(
482 482
 				'key'                => $this->publishable_key,
483
-				'allow_prepaid_card' => apply_filters( 'wc_stripe_allow_prepaid_card', true ) ? 'yes' : 'no',
483
+				'allow_prepaid_card' => apply_filters('wc_stripe_allow_prepaid_card', true) ? 'yes' : 'no',
484 484
 			),
485 485
 			'nonce'           => array(
486
-				'payment'                   => wp_create_nonce( 'wc-stripe-payment-request' ),
487
-				'shipping'                  => wp_create_nonce( 'wc-stripe-payment-request-shipping' ),
488
-				'update_shipping'           => wp_create_nonce( 'wc-stripe-update-shipping-method' ),
489
-				'checkout'                  => wp_create_nonce( 'woocommerce-process_checkout' ),
490
-				'add_to_cart'               => wp_create_nonce( 'wc-stripe-add-to-cart' ),
491
-				'get_selected_product_data' => wp_create_nonce( 'wc-stripe-get-selected-product-data' ),
492
-				'log_errors'                => wp_create_nonce( 'wc-stripe-log-errors' ),
493
-				'clear_cart'                => wp_create_nonce( 'wc-stripe-clear-cart' ),
486
+				'payment'                   => wp_create_nonce('wc-stripe-payment-request'),
487
+				'shipping'                  => wp_create_nonce('wc-stripe-payment-request-shipping'),
488
+				'update_shipping'           => wp_create_nonce('wc-stripe-update-shipping-method'),
489
+				'checkout'                  => wp_create_nonce('woocommerce-process_checkout'),
490
+				'add_to_cart'               => wp_create_nonce('wc-stripe-add-to-cart'),
491
+				'get_selected_product_data' => wp_create_nonce('wc-stripe-get-selected-product-data'),
492
+				'log_errors'                => wp_create_nonce('wc-stripe-log-errors'),
493
+				'clear_cart'                => wp_create_nonce('wc-stripe-clear-cart'),
494 494
 			),
495 495
 			'i18n'            => array(
496
-				'no_prepaid_card'  => __( 'Sorry, we\'re not accepting prepaid cards at this time.', 'woocommerce-gateway-stripe' ),
496
+				'no_prepaid_card'  => __('Sorry, we\'re not accepting prepaid cards at this time.', 'woocommerce-gateway-stripe'),
497 497
 				/* translators: Do not translate the [option] placeholder */
498
-				'unknown_shipping' => __( 'Unknown shipping option "[option]".', 'woocommerce-gateway-stripe' ),
498
+				'unknown_shipping' => __('Unknown shipping option "[option]".', 'woocommerce-gateway-stripe'),
499 499
 			),
500 500
 			'checkout'        => array(
501 501
 				'url'            => wc_get_checkout_url(),
502
-				'currency_code'  => strtolower( get_woocommerce_currency() ),
503
-				'country_code'   => substr( get_option( 'woocommerce_default_country' ), 0, 2 ),
502
+				'currency_code'  => strtolower(get_woocommerce_currency()),
503
+				'country_code'   => substr(get_option('woocommerce_default_country'), 0, 2),
504 504
 				'needs_shipping' => WC()->cart->needs_shipping() ? 'yes' : 'no',
505 505
 			),
506 506
 			'button'          => array(
507 507
 				'type'   => $this->get_button_type(),
508 508
 				'theme'  => $this->get_button_theme(),
509 509
 				'height' => $this->get_button_height(),
510
-				'locale' => apply_filters( 'wc_stripe_payment_request_button_locale', substr( get_locale(), 0, 2 ) ), // Default format is en_US.
510
+				'locale' => apply_filters('wc_stripe_payment_request_button_locale', substr(get_locale(), 0, 2)), // Default format is en_US.
511 511
 			),
512 512
 			'is_product_page' => is_product(),
513 513
 			'product'         => $this->get_product_data(),
514 514
 		);
515 515
 
516
-		wp_register_script( 'stripe', 'https://js.stripe.com/v3/', '', '3.0', true );
517
-		wp_register_script( 'wc_stripe_payment_request', plugins_url( 'assets/js/stripe-payment-request' . $suffix . '.js', WC_STRIPE_MAIN_FILE ), array( 'jquery', 'stripe' ), WC_STRIPE_VERSION, true );
516
+		wp_register_script('stripe', 'https://js.stripe.com/v3/', '', '3.0', true);
517
+		wp_register_script('wc_stripe_payment_request', plugins_url('assets/js/stripe-payment-request' . $suffix . '.js', WC_STRIPE_MAIN_FILE), array('jquery', 'stripe'), WC_STRIPE_VERSION, true);
518 518
 
519
-		wp_localize_script( 'wc_stripe_payment_request', 'wc_stripe_payment_request_params', apply_filters( 'wc_stripe_payment_request_params', $stripe_params ) );
519
+		wp_localize_script('wc_stripe_payment_request', 'wc_stripe_payment_request_params', apply_filters('wc_stripe_payment_request_params', $stripe_params));
520 520
 
521
-		wp_enqueue_script( 'wc_stripe_payment_request' );
521
+		wp_enqueue_script('wc_stripe_payment_request');
522 522
 
523 523
 		$gateways = WC()->payment_gateways->get_available_payment_gateways();
524
-		if ( isset( $gateways['stripe'] ) ) {
524
+		if (isset($gateways['stripe'])) {
525 525
 			$gateways['stripe']->payment_scripts();
526 526
 		}
527 527
 	}
@@ -537,37 +537,37 @@  discard block
 block discarded – undo
537 537
 
538 538
 		$gateways = WC()->payment_gateways->get_available_payment_gateways();
539 539
 
540
-		if ( ! isset( $gateways['stripe'] ) ) {
540
+		if ( ! isset($gateways['stripe'])) {
541 541
 			return;
542 542
 		}
543 543
 
544
-		if ( ! is_cart() && ! is_checkout() && ! is_product() && ! isset( $_GET['pay_for_order'] ) ) {
544
+		if ( ! is_cart() && ! is_checkout() && ! is_product() && ! isset($_GET['pay_for_order'])) {
545 545
 			return;
546 546
 		}
547 547
 
548
-		if ( is_product() && apply_filters( 'wc_stripe_hide_payment_request_on_product_page', false, $post ) ) {
548
+		if (is_product() && apply_filters('wc_stripe_hide_payment_request_on_product_page', false, $post)) {
549 549
 			return;
550 550
 		}
551 551
 
552
-		if ( is_checkout() && ! apply_filters( 'wc_stripe_show_payment_request_on_checkout', false, $post ) ) {
552
+		if (is_checkout() && ! apply_filters('wc_stripe_show_payment_request_on_checkout', false, $post)) {
553 553
 			return;
554 554
 		}
555 555
 
556
-		if ( is_product() ) {
557
-			$product = wc_get_product( $post->ID );
556
+		if (is_product()) {
557
+			$product = wc_get_product($post->ID);
558 558
 
559
-			if ( ! is_object( $product ) || ! in_array( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $product->product_type : $product->get_type() ), $this->supported_product_types() ) ) {
559
+			if ( ! is_object($product) || ! in_array((WC_Stripe_Helper::is_wc_lt('3.0') ? $product->product_type : $product->get_type()), $this->supported_product_types())) {
560 560
 				return;
561 561
 			}
562 562
 
563 563
 			// Pre Orders charge upon release not supported.
564
-			if ( class_exists( 'WC_Pre_Orders_Order' ) && WC_Pre_Orders_Product::product_is_charged_upon_release( $product ) ) {
565
-				WC_Stripe_Logger::log( 'Pre Order charge upon release is not supported. ( Payment Request button disabled )' );
564
+			if (class_exists('WC_Pre_Orders_Order') && WC_Pre_Orders_Product::product_is_charged_upon_release($product)) {
565
+				WC_Stripe_Logger::log('Pre Order charge upon release is not supported. ( Payment Request button disabled )');
566 566
 				return;
567 567
 			}
568 568
 		} else {
569
-			if ( ! $this->allowed_items_in_cart() ) {
570
-				WC_Stripe_Logger::log( 'Items in the cart has unsupported product type ( Payment Request button disabled )' );
569
+			if ( ! $this->allowed_items_in_cart()) {
570
+				WC_Stripe_Logger::log('Items in the cart has unsupported product type ( Payment Request button disabled )');
571 571
 				return;
572 572
 			}
573 573
 		}
@@ -591,42 +591,42 @@  discard block
 block discarded – undo
591 591
 
592 592
 		$gateways = WC()->payment_gateways->get_available_payment_gateways();
593 593
 
594
-		if ( ! isset( $gateways['stripe'] ) ) {
594
+		if ( ! isset($gateways['stripe'])) {
595 595
 			return;
596 596
 		}
597 597
 
598
-		if ( ! is_cart() && ! is_checkout() && ! is_product() && ! isset( $_GET['pay_for_order'] ) ) {
598
+		if ( ! is_cart() && ! is_checkout() && ! is_product() && ! isset($_GET['pay_for_order'])) {
599 599
 			return;
600 600
 		}
601 601
 
602
-		if ( is_product() && apply_filters( 'wc_stripe_hide_payment_request_on_product_page', false, $post ) ) {
602
+		if (is_product() && apply_filters('wc_stripe_hide_payment_request_on_product_page', false, $post)) {
603 603
 			return;
604 604
 		}
605 605
 
606
-		if ( is_checkout() && ! apply_filters( 'wc_stripe_show_payment_request_on_checkout', false, $post ) ) {
606
+		if (is_checkout() && ! apply_filters('wc_stripe_show_payment_request_on_checkout', false, $post)) {
607 607
 			return;
608 608
 		}
609 609
 
610
-		if ( is_product() ) {
611
-			$product = wc_get_product( $post->ID );
610
+		if (is_product()) {
611
+			$product = wc_get_product($post->ID);
612 612
 
613
-			if ( ! is_object( $product ) || ! in_array( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $product->product_type : $product->get_type() ), $this->supported_product_types() ) ) {
613
+			if ( ! is_object($product) || ! in_array((WC_Stripe_Helper::is_wc_lt('3.0') ? $product->product_type : $product->get_type()), $this->supported_product_types())) {
614 614
 				return;
615 615
 			}
616 616
 
617 617
 			// Pre Orders charge upon release not supported.
618
-			if ( class_exists( 'WC_Pre_Orders_Order' ) && WC_Pre_Orders_Product::product_is_charged_upon_release( $product ) ) {
619
-				WC_Stripe_Logger::log( 'Pre Order charge upon release is not supported. ( Payment Request button disabled )' );
618
+			if (class_exists('WC_Pre_Orders_Order') && WC_Pre_Orders_Product::product_is_charged_upon_release($product)) {
619
+				WC_Stripe_Logger::log('Pre Order charge upon release is not supported. ( Payment Request button disabled )');
620 620
 				return;
621 621
 			}
622 622
 		} else {
623
-			if ( ! $this->allowed_items_in_cart() ) {
624
-				WC_Stripe_Logger::log( 'Items in the cart has unsupported product type ( Payment Request button disabled )' );
623
+			if ( ! $this->allowed_items_in_cart()) {
624
+				WC_Stripe_Logger::log('Items in the cart has unsupported product type ( Payment Request button disabled )');
625 625
 				return;
626 626
 			}
627 627
 		}
628 628
 		?>
629
-		<p id="wc-stripe-payment-request-button-separator" style="margin-top:1.5em;text-align:center;display:none;">&mdash; <?php esc_html_e( 'OR', 'woocommerce-gateway-stripe' ); ?> &mdash;</p>
629
+		<p id="wc-stripe-payment-request-button-separator" style="margin-top:1.5em;text-align:center;display:none;">&mdash; <?php esc_html_e('OR', 'woocommerce-gateway-stripe'); ?> &mdash;</p>
630 630
 		<?php
631 631
 	}
632 632
 
@@ -637,11 +637,11 @@  discard block
 block discarded – undo
637 637
 	 * @version 4.0.0
638 638
 	 */
639 639
 	public function ajax_log_errors() {
640
-		check_ajax_referer( 'wc-stripe-log-errors', 'security' );
640
+		check_ajax_referer('wc-stripe-log-errors', 'security');
641 641
 
642
-		$errors = wc_clean( stripslashes( $_POST['errors'] ) );
642
+		$errors = wc_clean(stripslashes($_POST['errors']));
643 643
 
644
-		WC_Stripe_Logger::log( $errors );
644
+		WC_Stripe_Logger::log($errors);
645 645
 
646 646
 		exit;
647 647
 	}
@@ -653,7 +653,7 @@  discard block
 block discarded – undo
653 653
 	 * @version 4.0.0
654 654
 	 */
655 655
 	public function ajax_clear_cart() {
656
-		check_ajax_referer( 'wc-stripe-clear-cart', 'security' );
656
+		check_ajax_referer('wc-stripe-clear-cart', 'security');
657 657
 
658 658
 		WC()->cart->empty_cart();
659 659
 		exit;
@@ -663,10 +663,10 @@  discard block
 block discarded – undo
663 663
 	 * Get cart details.
664 664
 	 */
665 665
 	public function ajax_get_cart_details() {
666
-		check_ajax_referer( 'wc-stripe-payment-request', 'security' );
666
+		check_ajax_referer('wc-stripe-payment-request', 'security');
667 667
 
668
-		if ( ! defined( 'WOOCOMMERCE_CART' ) ) {
669
-			define( 'WOOCOMMERCE_CART', true );
668
+		if ( ! defined('WOOCOMMERCE_CART')) {
669
+			define('WOOCOMMERCE_CART', true);
670 670
 		}
671 671
 
672 672
 		WC()->cart->calculate_totals();
@@ -677,14 +677,14 @@  discard block
 block discarded – undo
677 677
 		$data = array(
678 678
 			'shipping_required' => WC()->cart->needs_shipping(),
679 679
 			'order_data'        => array(
680
-				'currency'     => strtolower( $currency ),
681
-				'country_code' => substr( get_option( 'woocommerce_default_country' ), 0, 2 ),
680
+				'currency'     => strtolower($currency),
681
+				'country_code' => substr(get_option('woocommerce_default_country'), 0, 2),
682 682
 			),
683 683
 		);
684 684
 
685 685
 		$data['order_data'] += $this->build_display_items();
686 686
 
687
-		wp_send_json( $data );
687
+		wp_send_json($data);
688 688
 	}
689 689
 
690 690
 	/**
@@ -695,7 +695,7 @@  discard block
 block discarded – undo
695 695
 	 * @see WC_Shipping::get_packages().
696 696
 	 */
697 697
 	public function ajax_get_shipping_options() {
698
-		check_ajax_referer( 'wc-stripe-payment-request-shipping', 'security' );
698
+		check_ajax_referer('wc-stripe-payment-request-shipping', 'security');
699 699
 
700 700
 		try {
701 701
 			// Set the shipping package.
@@ -711,34 +711,34 @@  discard block
 block discarded – undo
711 711
 				)
712 712
 			);
713 713
 
714
-			$this->calculate_shipping( apply_filters( 'wc_stripe_payment_request_shipping_posted_values', $posted ) );
714
+			$this->calculate_shipping(apply_filters('wc_stripe_payment_request_shipping_posted_values', $posted));
715 715
 
716 716
 			// Set the shipping options.
717 717
 			$data     = array();
718 718
 			$packages = WC()->shipping->get_packages();
719 719
 
720
-			if ( ! empty( $packages ) && WC()->customer->has_calculated_shipping() ) {
721
-				foreach ( $packages as $package_key => $package ) {
722
-					if ( empty( $package['rates'] ) ) {
723
-						throw new Exception( __( 'Unable to find shipping method for address.', 'woocommerce-gateway-stripe' ) );
720
+			if ( ! empty($packages) && WC()->customer->has_calculated_shipping()) {
721
+				foreach ($packages as $package_key => $package) {
722
+					if (empty($package['rates'])) {
723
+						throw new Exception(__('Unable to find shipping method for address.', 'woocommerce-gateway-stripe'));
724 724
 					}
725 725
 
726
-					foreach ( $package['rates'] as $key => $rate ) {
726
+					foreach ($package['rates'] as $key => $rate) {
727 727
 						$data['shipping_options'][] = array(
728 728
 							'id'     => $rate->id,
729 729
 							'label'  => $rate->label,
730 730
 							'detail' => '',
731
-							'amount' => WC_Stripe_Helper::get_stripe_amount( $rate->cost ),
731
+							'amount' => WC_Stripe_Helper::get_stripe_amount($rate->cost),
732 732
 						);
733 733
 					}
734 734
 				}
735 735
 			} else {
736
-				throw new Exception( __( 'Unable to find shipping method for address.', 'woocommerce-gateway-stripe' ) );
736
+				throw new Exception(__('Unable to find shipping method for address.', 'woocommerce-gateway-stripe'));
737 737
 			}
738 738
 
739
-			if ( isset( $data[0] ) ) {
739
+			if (isset($data[0])) {
740 740
 				// Auto select the first shipping method.
741
-				WC()->session->set( 'chosen_shipping_methods', array( $data[0]['id'] ) );
741
+				WC()->session->set('chosen_shipping_methods', array($data[0]['id']));
742 742
 			}
743 743
 
744 744
 			WC()->cart->calculate_totals();
@@ -746,12 +746,12 @@  discard block
 block discarded – undo
746 746
 			$data          += $this->build_display_items();
747 747
 			$data['result'] = 'success';
748 748
 
749
-			wp_send_json( $data );
750
-		} catch ( Exception $e ) {
749
+			wp_send_json($data);
750
+		} catch (Exception $e) {
751 751
 			$data          += $this->build_display_items();
752 752
 			$data['result'] = 'invalid_shipping_address';
753 753
 
754
-			wp_send_json( $data );
754
+			wp_send_json($data);
755 755
 		}
756 756
 	}
757 757
 
@@ -759,22 +759,22 @@  discard block
 block discarded – undo
759 759
 	 * Update shipping method.
760 760
 	 */
761 761
 	public function ajax_update_shipping_method() {
762
-		check_ajax_referer( 'wc-stripe-update-shipping-method', 'security' );
762
+		check_ajax_referer('wc-stripe-update-shipping-method', 'security');
763 763
 
764
-		if ( ! defined( 'WOOCOMMERCE_CART' ) ) {
765
-			define( 'WOOCOMMERCE_CART', true );
764
+		if ( ! defined('WOOCOMMERCE_CART')) {
765
+			define('WOOCOMMERCE_CART', true);
766 766
 		}
767 767
 
768
-		$chosen_shipping_methods = WC()->session->get( 'chosen_shipping_methods' );
769
-		$shipping_method         = filter_input( INPUT_POST, 'shipping_method', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY );
768
+		$chosen_shipping_methods = WC()->session->get('chosen_shipping_methods');
769
+		$shipping_method         = filter_input(INPUT_POST, 'shipping_method', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY);
770 770
 
771
-		if ( is_array( $shipping_method ) ) {
772
-			foreach ( $shipping_method as $i => $value ) {
773
-				$chosen_shipping_methods[ $i ] = wc_clean( $value );
771
+		if (is_array($shipping_method)) {
772
+			foreach ($shipping_method as $i => $value) {
773
+				$chosen_shipping_methods[$i] = wc_clean($value);
774 774
 			}
775 775
 		}
776 776
 
777
-		WC()->session->set( 'chosen_shipping_methods', $chosen_shipping_methods );
777
+		WC()->session->set('chosen_shipping_methods', $chosen_shipping_methods);
778 778
 
779 779
 		WC()->cart->calculate_totals();
780 780
 
@@ -782,7 +782,7 @@  discard block
 block discarded – undo
782 782
 		$data          += $this->build_display_items();
783 783
 		$data['result'] = 'success';
784 784
 
785
-		wp_send_json( $data );
785
+		wp_send_json($data);
786 786
 	}
787 787
 
788 788
 	/**
@@ -793,46 +793,46 @@  discard block
 block discarded – undo
793 793
 	 * @return array $data
794 794
 	 */
795 795
 	public function ajax_get_selected_product_data() {
796
-		check_ajax_referer( 'wc-stripe-get-selected-product-data', 'security' );
796
+		check_ajax_referer('wc-stripe-get-selected-product-data', 'security');
797 797
 
798 798
 		try {
799
-			$product_id   = absint( $_POST['product_id'] );
800
-			$qty          = ! isset( $_POST['qty'] ) ? 1 : apply_filters( 'woocommerce_add_to_cart_quantity', absint( $_POST['qty'] ), $product_id );
801
-			$product      = wc_get_product( $product_id );
799
+			$product_id   = absint($_POST['product_id']);
800
+			$qty          = ! isset($_POST['qty']) ? 1 : apply_filters('woocommerce_add_to_cart_quantity', absint($_POST['qty']), $product_id);
801
+			$product      = wc_get_product($product_id);
802 802
 			$variation_id = null;
803 803
 
804
-			if ( ! is_a( $product, 'WC_Product' ) ) {
805
-				throw new Exception( sprintf( __( 'Product with the ID (%d) cannot be found.', 'woocommerce-gateway-stripe' ), $product_id ) );
804
+			if ( ! is_a($product, 'WC_Product')) {
805
+				throw new Exception(sprintf(__('Product with the ID (%d) cannot be found.', 'woocommerce-gateway-stripe'), $product_id));
806 806
 			}
807 807
 
808
-			if ( 'variable' === ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $product->product_type : $product->get_type() ) && isset( $_POST['attributes'] ) ) {
809
-				$attributes = array_map( 'wc_clean', $_POST['attributes'] );
808
+			if ('variable' === (WC_Stripe_Helper::is_wc_lt('3.0') ? $product->product_type : $product->get_type()) && isset($_POST['attributes'])) {
809
+				$attributes = array_map('wc_clean', $_POST['attributes']);
810 810
 
811
-				if ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ) {
812
-					$variation_id = $product->get_matching_variation( $attributes );
811
+				if (WC_Stripe_Helper::is_wc_lt('3.0')) {
812
+					$variation_id = $product->get_matching_variation($attributes);
813 813
 				} else {
814
-					$data_store   = WC_Data_Store::load( 'product' );
815
-					$variation_id = $data_store->find_matching_product_variation( $product, $attributes );
814
+					$data_store   = WC_Data_Store::load('product');
815
+					$variation_id = $data_store->find_matching_product_variation($product, $attributes);
816 816
 				}
817 817
 
818
-				if ( ! empty( $variation_id ) ) {
819
-					$product = wc_get_product( $variation_id );
818
+				if ( ! empty($variation_id)) {
819
+					$product = wc_get_product($variation_id);
820 820
 				}
821
-			} elseif ( 'simple' === ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $product->product_type : $product->get_type() ) ) {
822
-				$product = wc_get_product( $product_id );
821
+			} elseif ('simple' === (WC_Stripe_Helper::is_wc_lt('3.0') ? $product->product_type : $product->get_type())) {
822
+				$product = wc_get_product($product_id);
823 823
 			}
824 824
 
825 825
 			// Force quantity to 1 if sold individually and check for existing item in cart.
826
-			if ( $product->is_sold_individually() ) {
827
-				$qty = apply_filters( 'wc_stripe_payment_request_add_to_cart_sold_individually_quantity', 1, $qty, $product_id, $variation_id );
826
+			if ($product->is_sold_individually()) {
827
+				$qty = apply_filters('wc_stripe_payment_request_add_to_cart_sold_individually_quantity', 1, $qty, $product_id, $variation_id);
828 828
 			}
829 829
 
830
-			if ( ! $product->has_enough_stock( $qty ) ) {
830
+			if ( ! $product->has_enough_stock($qty)) {
831 831
 				/* translators: 1: product name 2: quantity in stock */
832
-				throw new Exception( sprintf( __( 'You cannot add that amount of "%1$s"; to the cart because there is not enough stock (%2$s remaining).', 'woocommerce-gateway-stripe' ), $product->get_name(), wc_format_stock_quantity_for_display( $product->get_stock_quantity(), $product ) ) );
832
+				throw new Exception(sprintf(__('You cannot add that amount of "%1$s"; to the cart because there is not enough stock (%2$s remaining).', 'woocommerce-gateway-stripe'), $product->get_name(), wc_format_stock_quantity_for_display($product->get_stock_quantity(), $product)));
833 833
 			}
834 834
 
835
-			$total = $qty * ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $product->price : $product->get_price() );
835
+			$total = $qty * (WC_Stripe_Helper::is_wc_lt('3.0') ? $product->price : $product->get_price());
836 836
 
837 837
 			$quantity_label = 1 < $qty ? ' (x' . $qty . ')' : '';
838 838
 
@@ -840,28 +840,28 @@  discard block
 block discarded – undo
840 840
 			$items = array();
841 841
 
842 842
 			$items[] = array(
843
-				'label'  => ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $product->name : $product->get_name() ) . $quantity_label,
844
-				'amount' => WC_Stripe_Helper::get_stripe_amount( $total ),
843
+				'label'  => (WC_Stripe_Helper::is_wc_lt('3.0') ? $product->name : $product->get_name()) . $quantity_label,
844
+				'amount' => WC_Stripe_Helper::get_stripe_amount($total),
845 845
 			);
846 846
 
847
-			if ( wc_tax_enabled() ) {
847
+			if (wc_tax_enabled()) {
848 848
 				$items[] = array(
849
-					'label'   => __( 'Tax', 'woocommerce-gateway-stripe' ),
849
+					'label'   => __('Tax', 'woocommerce-gateway-stripe'),
850 850
 					'amount'  => 0,
851 851
 					'pending' => true,
852 852
 				);
853 853
 			}
854 854
 
855
-			if ( wc_shipping_enabled() && $product->needs_shipping() ) {
855
+			if (wc_shipping_enabled() && $product->needs_shipping()) {
856 856
 				$items[] = array(
857
-					'label'   => __( 'Shipping', 'woocommerce-gateway-stripe' ),
857
+					'label'   => __('Shipping', 'woocommerce-gateway-stripe'),
858 858
 					'amount'  => 0,
859 859
 					'pending' => true,
860 860
 				);
861 861
 
862 862
 				$data['shippingOptions'] = array(
863 863
 					'id'     => 'pending',
864
-					'label'  => __( 'Pending', 'woocommerce-gateway-stripe' ),
864
+					'label'  => __('Pending', 'woocommerce-gateway-stripe'),
865 865
 					'detail' => '',
866 866
 					'amount' => 0,
867 867
 				);
@@ -870,17 +870,17 @@  discard block
 block discarded – undo
870 870
 			$data['displayItems'] = $items;
871 871
 			$data['total']        = array(
872 872
 				'label'   => $this->total_label,
873
-				'amount'  => WC_Stripe_Helper::get_stripe_amount( $total ),
873
+				'amount'  => WC_Stripe_Helper::get_stripe_amount($total),
874 874
 				'pending' => true,
875 875
 			);
876 876
 
877
-			$data['requestShipping'] = ( wc_shipping_enabled() && $product->needs_shipping() );
878
-			$data['currency']        = strtolower( get_woocommerce_currency() );
879
-			$data['country_code']    = substr( get_option( 'woocommerce_default_country' ), 0, 2 );
877
+			$data['requestShipping'] = (wc_shipping_enabled() && $product->needs_shipping());
878
+			$data['currency']        = strtolower(get_woocommerce_currency());
879
+			$data['country_code']    = substr(get_option('woocommerce_default_country'), 0, 2);
880 880
 
881
-			wp_send_json( $data );
882
-		} catch ( Exception $e ) {
883
-			wp_send_json( array( 'error' => wp_strip_all_tags( $e->getMessage() ) ) );
881
+			wp_send_json($data);
882
+		} catch (Exception $e) {
883
+			wp_send_json(array('error' => wp_strip_all_tags($e->getMessage())));
884 884
 		}
885 885
 	}
886 886
 
@@ -892,36 +892,36 @@  discard block
 block discarded – undo
892 892
 	 * @return array $data
893 893
 	 */
894 894
 	public function ajax_add_to_cart() {
895
-		check_ajax_referer( 'wc-stripe-add-to-cart', 'security' );
895
+		check_ajax_referer('wc-stripe-add-to-cart', 'security');
896 896
 
897
-		if ( ! defined( 'WOOCOMMERCE_CART' ) ) {
898
-			define( 'WOOCOMMERCE_CART', true );
897
+		if ( ! defined('WOOCOMMERCE_CART')) {
898
+			define('WOOCOMMERCE_CART', true);
899 899
 		}
900 900
 
901 901
 		WC()->shipping->reset_shipping();
902 902
 
903
-		$product_id = absint( $_POST['product_id'] );
904
-		$qty        = ! isset( $_POST['qty'] ) ? 1 : absint( $_POST['qty'] );
905
-		$product    = wc_get_product( $product_id );
903
+		$product_id = absint($_POST['product_id']);
904
+		$qty        = ! isset($_POST['qty']) ? 1 : absint($_POST['qty']);
905
+		$product    = wc_get_product($product_id);
906 906
 
907 907
 		// First empty the cart to prevent wrong calculation.
908 908
 		WC()->cart->empty_cart();
909 909
 
910
-		if ( 'variable' === ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $product->product_type : $product->get_type() ) && isset( $_POST['attributes'] ) ) {
911
-			$attributes = array_map( 'wc_clean', $_POST['attributes'] );
910
+		if ('variable' === (WC_Stripe_Helper::is_wc_lt('3.0') ? $product->product_type : $product->get_type()) && isset($_POST['attributes'])) {
911
+			$attributes = array_map('wc_clean', $_POST['attributes']);
912 912
 
913
-			if ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ) {
914
-				$variation_id = $product->get_matching_variation( $attributes );
913
+			if (WC_Stripe_Helper::is_wc_lt('3.0')) {
914
+				$variation_id = $product->get_matching_variation($attributes);
915 915
 			} else {
916
-				$data_store   = WC_Data_Store::load( 'product' );
917
-				$variation_id = $data_store->find_matching_product_variation( $product, $attributes );
916
+				$data_store   = WC_Data_Store::load('product');
917
+				$variation_id = $data_store->find_matching_product_variation($product, $attributes);
918 918
 			}
919 919
 
920
-			WC()->cart->add_to_cart( $product->get_id(), $qty, $variation_id, $attributes );
920
+			WC()->cart->add_to_cart($product->get_id(), $qty, $variation_id, $attributes);
921 921
 		}
922 922
 
923
-		if ( 'simple' === ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $product->product_type : $product->get_type() ) ) {
924
-			WC()->cart->add_to_cart( $product->get_id(), $qty );
923
+		if ('simple' === (WC_Stripe_Helper::is_wc_lt('3.0') ? $product->product_type : $product->get_type())) {
924
+			WC()->cart->add_to_cart($product->get_id(), $qty);
925 925
 		}
926 926
 
927 927
 		WC()->cart->calculate_totals();
@@ -930,7 +930,7 @@  discard block
 block discarded – undo
930 930
 		$data          += $this->build_display_items();
931 931
 		$data['result'] = 'success';
932 932
 
933
-		wp_send_json( $data );
933
+		wp_send_json($data);
934 934
 	}
935 935
 
936 936
 	/**
@@ -943,31 +943,31 @@  discard block
 block discarded – undo
943 943
 	 * @version 4.0.0
944 944
 	 */
945 945
 	public function normalize_state() {
946
-		$billing_country  = ! empty( $_POST['billing_country'] ) ? wc_clean( $_POST['billing_country'] ) : '';
947
-		$shipping_country = ! empty( $_POST['shipping_country'] ) ? wc_clean( $_POST['shipping_country'] ) : '';
948
-		$billing_state    = ! empty( $_POST['billing_state'] ) ? wc_clean( $_POST['billing_state'] ) : '';
949
-		$shipping_state   = ! empty( $_POST['shipping_state'] ) ? wc_clean( $_POST['shipping_state'] ) : '';
946
+		$billing_country  = ! empty($_POST['billing_country']) ? wc_clean($_POST['billing_country']) : '';
947
+		$shipping_country = ! empty($_POST['shipping_country']) ? wc_clean($_POST['shipping_country']) : '';
948
+		$billing_state    = ! empty($_POST['billing_state']) ? wc_clean($_POST['billing_state']) : '';
949
+		$shipping_state   = ! empty($_POST['shipping_state']) ? wc_clean($_POST['shipping_state']) : '';
950 950
 
951
-		if ( $billing_state && $billing_country ) {
952
-			$valid_states = WC()->countries->get_states( $billing_country );
951
+		if ($billing_state && $billing_country) {
952
+			$valid_states = WC()->countries->get_states($billing_country);
953 953
 
954 954
 			// Valid states found for country.
955
-			if ( ! empty( $valid_states ) && is_array( $valid_states ) && sizeof( $valid_states ) > 0 ) {
956
-				foreach ( $valid_states as $state_abbr => $state ) {
957
-					if ( preg_match( '/' . preg_quote( $state ) . '/i', $billing_state ) ) {
955
+			if ( ! empty($valid_states) && is_array($valid_states) && sizeof($valid_states) > 0) {
956
+				foreach ($valid_states as $state_abbr => $state) {
957
+					if (preg_match('/' . preg_quote($state) . '/i', $billing_state)) {
958 958
 						$_POST['billing_state'] = $state_abbr;
959 959
 					}
960 960
 				}
961 961
 			}
962 962
 		}
963 963
 
964
-		if ( $shipping_state && $shipping_country ) {
965
-			$valid_states = WC()->countries->get_states( $shipping_country );
964
+		if ($shipping_state && $shipping_country) {
965
+			$valid_states = WC()->countries->get_states($shipping_country);
966 966
 
967 967
 			// Valid states found for country.
968
-			if ( ! empty( $valid_states ) && is_array( $valid_states ) && sizeof( $valid_states ) > 0 ) {
969
-				foreach ( $valid_states as $state_abbr => $state ) {
970
-					if ( preg_match( '/' . preg_quote( $state ) . '/i', $shipping_state ) ) {
968
+			if ( ! empty($valid_states) && is_array($valid_states) && sizeof($valid_states) > 0) {
969
+				foreach ($valid_states as $state_abbr => $state) {
970
+					if (preg_match('/' . preg_quote($state) . '/i', $shipping_state)) {
971 971
 						$_POST['shipping_state'] = $state_abbr;
972 972
 					}
973 973
 				}
@@ -982,19 +982,19 @@  discard block
 block discarded – undo
982 982
 	 * @version 4.0.0
983 983
 	 */
984 984
 	public function ajax_create_order() {
985
-		if ( WC()->cart->is_empty() ) {
986
-			wp_send_json_error( __( 'Empty cart', 'woocommerce-gateway-stripe' ) );
985
+		if (WC()->cart->is_empty()) {
986
+			wp_send_json_error(__('Empty cart', 'woocommerce-gateway-stripe'));
987 987
 		}
988 988
 
989
-		if ( ! defined( 'WOOCOMMERCE_CHECKOUT' ) ) {
990
-			define( 'WOOCOMMERCE_CHECKOUT', true );
989
+		if ( ! defined('WOOCOMMERCE_CHECKOUT')) {
990
+			define('WOOCOMMERCE_CHECKOUT', true);
991 991
 		}
992 992
 
993 993
 		$this->normalize_state();
994 994
 
995 995
 		WC()->checkout()->process_checkout();
996 996
 
997
-		die( 0 );
997
+		die(0);
998 998
 	}
999 999
 
1000 1000
 	/**
@@ -1004,41 +1004,41 @@  discard block
 block discarded – undo
1004 1004
 	 * @version 4.0.0
1005 1005
 	 * @param array $address
1006 1006
 	 */
1007
-	protected function calculate_shipping( $address = array() ) {
1007
+	protected function calculate_shipping($address = array()) {
1008 1008
 		$country   = $address['country'];
1009 1009
 		$state     = $address['state'];
1010 1010
 		$postcode  = $address['postcode'];
1011 1011
 		$city      = $address['city'];
1012 1012
 		$address_1 = $address['address'];
1013 1013
 		$address_2 = $address['address_2'];
1014
-		$wc_states = WC()->countries->get_states( $country );
1014
+		$wc_states = WC()->countries->get_states($country);
1015 1015
 
1016 1016
 		/**
1017 1017
 		 * In some versions of Chrome, state can be a full name. So we need
1018 1018
 		 * to convert that to abbreviation as WC is expecting that.
1019 1019
 		 */
1020
-		if ( 2 < strlen( $state ) && ! empty( $wc_states ) ) {
1021
-			$state = array_search( ucwords( strtolower( $state ) ), $wc_states, true );
1020
+		if (2 < strlen($state) && ! empty($wc_states)) {
1021
+			$state = array_search(ucwords(strtolower($state)), $wc_states, true);
1022 1022
 		}
1023 1023
 
1024 1024
 		WC()->shipping->reset_shipping();
1025 1025
 
1026
-		if ( $postcode && WC_Validation::is_postcode( $postcode, $country ) ) {
1027
-			$postcode = wc_format_postcode( $postcode, $country );
1026
+		if ($postcode && WC_Validation::is_postcode($postcode, $country)) {
1027
+			$postcode = wc_format_postcode($postcode, $country);
1028 1028
 		}
1029 1029
 
1030
-		if ( $country ) {
1031
-			WC()->customer->set_location( $country, $state, $postcode, $city );
1032
-			WC()->customer->set_shipping_location( $country, $state, $postcode, $city );
1030
+		if ($country) {
1031
+			WC()->customer->set_location($country, $state, $postcode, $city);
1032
+			WC()->customer->set_shipping_location($country, $state, $postcode, $city);
1033 1033
 		} else {
1034
-			WC_Stripe_Helper::is_wc_lt( '3.0' ) ? WC()->customer->set_to_base() : WC()->customer->set_billing_address_to_base();
1035
-			WC_Stripe_Helper::is_wc_lt( '3.0' ) ? WC()->customer->set_shipping_to_base() : WC()->customer->set_shipping_address_to_base();
1034
+			WC_Stripe_Helper::is_wc_lt('3.0') ? WC()->customer->set_to_base() : WC()->customer->set_billing_address_to_base();
1035
+			WC_Stripe_Helper::is_wc_lt('3.0') ? WC()->customer->set_shipping_to_base() : WC()->customer->set_shipping_address_to_base();
1036 1036
 		}
1037 1037
 
1038
-		if ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ) {
1039
-			WC()->customer->calculated_shipping( true );
1038
+		if (WC_Stripe_Helper::is_wc_lt('3.0')) {
1039
+			WC()->customer->calculated_shipping(true);
1040 1040
 		} else {
1041
-			WC()->customer->set_calculated_shipping( true );
1041
+			WC()->customer->set_calculated_shipping(true);
1042 1042
 			WC()->customer->save();
1043 1043
 		}
1044 1044
 
@@ -1055,17 +1055,17 @@  discard block
 block discarded – undo
1055 1055
 		$packages[0]['destination']['address']   = $address_1;
1056 1056
 		$packages[0]['destination']['address_2'] = $address_2;
1057 1057
 
1058
-		foreach ( WC()->cart->get_cart() as $item ) {
1059
-			if ( $item['data']->needs_shipping() ) {
1060
-				if ( isset( $item['line_total'] ) ) {
1058
+		foreach (WC()->cart->get_cart() as $item) {
1059
+			if ($item['data']->needs_shipping()) {
1060
+				if (isset($item['line_total'])) {
1061 1061
 					$packages[0]['contents_cost'] += $item['line_total'];
1062 1062
 				}
1063 1063
 			}
1064 1064
 		}
1065 1065
 
1066
-		$packages = apply_filters( 'woocommerce_cart_shipping_packages', $packages );
1066
+		$packages = apply_filters('woocommerce_cart_shipping_packages', $packages);
1067 1067
 
1068
-		WC()->shipping->calculate_shipping( $packages );
1068
+		WC()->shipping->calculate_shipping($packages);
1069 1069
 	}
1070 1070
 
1071 1071
 	/**
@@ -1074,19 +1074,19 @@  discard block
 block discarded – undo
1074 1074
 	 * @since 3.1.0
1075 1075
 	 * @version 4.0.0
1076 1076
 	 */
1077
-	protected function build_shipping_methods( $shipping_methods ) {
1078
-		if ( empty( $shipping_methods ) ) {
1077
+	protected function build_shipping_methods($shipping_methods) {
1078
+		if (empty($shipping_methods)) {
1079 1079
 			return array();
1080 1080
 		}
1081 1081
 
1082 1082
 		$shipping = array();
1083 1083
 
1084
-		foreach ( $shipping_methods as $method ) {
1084
+		foreach ($shipping_methods as $method) {
1085 1085
 			$shipping[] = array(
1086 1086
 				'id'     => $method['id'],
1087 1087
 				'label'  => $method['label'],
1088 1088
 				'detail' => '',
1089
-				'amount' => WC_Stripe_Helper::get_stripe_amount( $method['amount']['value'] ),
1089
+				'amount' => WC_Stripe_Helper::get_stripe_amount($method['amount']['value']),
1090 1090
 			);
1091 1091
 		}
1092 1092
 
@@ -1100,8 +1100,8 @@  discard block
 block discarded – undo
1100 1100
 	 * @version 4.0.0
1101 1101
 	 */
1102 1102
 	protected function build_display_items() {
1103
-		if ( ! defined( 'WOOCOMMERCE_CART' ) ) {
1104
-			define( 'WOOCOMMERCE_CART', true );
1103
+		if ( ! defined('WOOCOMMERCE_CART')) {
1104
+			define('WOOCOMMERCE_CART', true);
1105 1105
 		}
1106 1106
 
1107 1107
 		$items     = array();
@@ -1109,71 +1109,71 @@  discard block
 block discarded – undo
1109 1109
 		$discounts = 0;
1110 1110
 
1111 1111
 		// Default show only subtotal instead of itemization.
1112
-		if ( ! apply_filters( 'wc_stripe_payment_request_hide_itemization', true ) ) {
1113
-			foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {
1112
+		if ( ! apply_filters('wc_stripe_payment_request_hide_itemization', true)) {
1113
+			foreach (WC()->cart->get_cart() as $cart_item_key => $cart_item) {
1114 1114
 				$amount         = $cart_item['line_subtotal'];
1115 1115
 				$subtotal      += $cart_item['line_subtotal'];
1116 1116
 				$quantity_label = 1 < $cart_item['quantity'] ? ' (x' . $cart_item['quantity'] . ')' : '';
1117 1117
 
1118
-				$product_name = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $cart_item['data']->post->post_title : $cart_item['data']->get_name();
1118
+				$product_name = WC_Stripe_Helper::is_wc_lt('3.0') ? $cart_item['data']->post->post_title : $cart_item['data']->get_name();
1119 1119
 
1120 1120
 				$item = array(
1121 1121
 					'label'  => $product_name . $quantity_label,
1122
-					'amount' => WC_Stripe_Helper::get_stripe_amount( $amount ),
1122
+					'amount' => WC_Stripe_Helper::get_stripe_amount($amount),
1123 1123
 				);
1124 1124
 
1125 1125
 				$items[] = $item;
1126 1126
 			}
1127 1127
 		}
1128 1128
 
1129
-		if ( version_compare( WC_VERSION, '3.2', '<' ) ) {
1130
-			$discounts = wc_format_decimal( WC()->cart->get_cart_discount_total(), WC()->cart->dp );
1129
+		if (version_compare(WC_VERSION, '3.2', '<')) {
1130
+			$discounts = wc_format_decimal(WC()->cart->get_cart_discount_total(), WC()->cart->dp);
1131 1131
 		} else {
1132
-			$applied_coupons = array_values( WC()->cart->get_coupon_discount_totals() );
1132
+			$applied_coupons = array_values(WC()->cart->get_coupon_discount_totals());
1133 1133
 
1134
-			foreach ( $applied_coupons as $amount ) {
1134
+			foreach ($applied_coupons as $amount) {
1135 1135
 				$discounts += (float) $amount;
1136 1136
 			}
1137 1137
 		}
1138 1138
 
1139
-		$discounts   = wc_format_decimal( $discounts, WC()->cart->dp );
1140
-		$tax         = wc_format_decimal( WC()->cart->tax_total + WC()->cart->shipping_tax_total, WC()->cart->dp );
1141
-		$shipping    = wc_format_decimal( WC()->cart->shipping_total, WC()->cart->dp );
1142
-		$items_total = wc_format_decimal( WC()->cart->cart_contents_total, WC()->cart->dp ) + $discounts;
1143
-		$order_total = version_compare( WC_VERSION, '3.2', '<' ) ? wc_format_decimal( $items_total + $tax + $shipping - $discounts, WC()->cart->dp ) : WC()->cart->get_total( false );
1139
+		$discounts   = wc_format_decimal($discounts, WC()->cart->dp);
1140
+		$tax         = wc_format_decimal(WC()->cart->tax_total + WC()->cart->shipping_tax_total, WC()->cart->dp);
1141
+		$shipping    = wc_format_decimal(WC()->cart->shipping_total, WC()->cart->dp);
1142
+		$items_total = wc_format_decimal(WC()->cart->cart_contents_total, WC()->cart->dp) + $discounts;
1143
+		$order_total = version_compare(WC_VERSION, '3.2', '<') ? wc_format_decimal($items_total + $tax + $shipping - $discounts, WC()->cart->dp) : WC()->cart->get_total(false);
1144 1144
 
1145
-		if ( wc_tax_enabled() ) {
1145
+		if (wc_tax_enabled()) {
1146 1146
 			$items[] = array(
1147
-				'label'  => esc_html( __( 'Tax', 'woocommerce-gateway-stripe' ) ),
1148
-				'amount' => WC_Stripe_Helper::get_stripe_amount( $tax ),
1147
+				'label'  => esc_html(__('Tax', 'woocommerce-gateway-stripe')),
1148
+				'amount' => WC_Stripe_Helper::get_stripe_amount($tax),
1149 1149
 			);
1150 1150
 		}
1151 1151
 
1152
-		if ( WC()->cart->needs_shipping() ) {
1152
+		if (WC()->cart->needs_shipping()) {
1153 1153
 			$items[] = array(
1154
-				'label'  => esc_html( __( 'Shipping', 'woocommerce-gateway-stripe' ) ),
1155
-				'amount' => WC_Stripe_Helper::get_stripe_amount( $shipping ),
1154
+				'label'  => esc_html(__('Shipping', 'woocommerce-gateway-stripe')),
1155
+				'amount' => WC_Stripe_Helper::get_stripe_amount($shipping),
1156 1156
 			);
1157 1157
 		}
1158 1158
 
1159
-		if ( WC()->cart->has_discount() ) {
1159
+		if (WC()->cart->has_discount()) {
1160 1160
 			$items[] = array(
1161
-				'label'  => esc_html( __( 'Discount', 'woocommerce-gateway-stripe' ) ),
1162
-				'amount' => WC_Stripe_Helper::get_stripe_amount( $discounts ),
1161
+				'label'  => esc_html(__('Discount', 'woocommerce-gateway-stripe')),
1162
+				'amount' => WC_Stripe_Helper::get_stripe_amount($discounts),
1163 1163
 			);
1164 1164
 		}
1165 1165
 
1166
-		if ( version_compare( WC_VERSION, '3.2', '<' ) ) {
1166
+		if (version_compare(WC_VERSION, '3.2', '<')) {
1167 1167
 			$cart_fees = WC()->cart->fees;
1168 1168
 		} else {
1169 1169
 			$cart_fees = WC()->cart->get_fees();
1170 1170
 		}
1171 1171
 
1172 1172
 		// Include fees and taxes as display items.
1173
-		foreach ( $cart_fees as $key => $fee ) {
1173
+		foreach ($cart_fees as $key => $fee) {
1174 1174
 			$items[] = array(
1175 1175
 				'label'  => $fee->name,
1176
-				'amount' => WC_Stripe_Helper::get_stripe_amount( $fee->amount ),
1176
+				'amount' => WC_Stripe_Helper::get_stripe_amount($fee->amount),
1177 1177
 			);
1178 1178
 		}
1179 1179
 
@@ -1181,7 +1181,7 @@  discard block
 block discarded – undo
1181 1181
 			'displayItems' => $items,
1182 1182
 			'total'        => array(
1183 1183
 				'label'   => $this->total_label,
1184
-				'amount'  => max( 0, apply_filters( 'woocommerce_stripe_calculated_total', WC_Stripe_Helper::get_stripe_amount( $order_total ), $order_total, WC()->cart ) ),
1184
+				'amount'  => max(0, apply_filters('woocommerce_stripe_calculated_total', WC_Stripe_Helper::get_stripe_amount($order_total), $order_total, WC()->cart)),
1185 1185
 				'pending' => false,
1186 1186
 			),
1187 1187
 		);
Please login to merge, or discard this patch.
includes/compat/class-wc-stripe-sepa-subs-compat.php 2 patches
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -138,7 +138,7 @@  discard block
 block discarded – undo
138 138
 	 * @param float $amount
139 139
 	 * @param mixed $renewal_order
140 140
 	 * @param bool $retry Should we retry the process?
141
-	 * @param object $previous_error
141
+	 * @param boolean $previous_error
142 142
 	 */
143 143
 	public function process_subscription_payment( $amount = 0.0, $renewal_order, $retry = true, $previous_error ) {
144 144
 		try {
@@ -241,7 +241,7 @@  discard block
 block discarded – undo
241 241
 
242 242
 	/**
243 243
 	 * Don't transfer Stripe fee/ID meta to renewal orders.
244
-	 * @param int $resubscribe_order The order created for the customer to resubscribe to the old expired/cancelled subscription
244
+	 * @param integer $renewal_order
245 245
 	 */
246 246
 	public function delete_renewal_meta( $renewal_order ) {
247 247
 		WC_Stripe_Helper::delete_stripe_fee( $renewal_order );
Please login to merge, or discard this patch.
Spacing   +154 added lines, -154 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) {
2
+if ( ! defined('ABSPATH')) {
3 3
 	exit;
4 4
 }
5 5
 
@@ -15,21 +15,21 @@  discard block
 block discarded – undo
15 15
 	public function __construct() {
16 16
 		parent::__construct();
17 17
 
18
-		if ( class_exists( 'WC_Subscriptions_Order' ) ) {
19
-			add_action( 'woocommerce_scheduled_subscription_payment_' . $this->id, array( $this, 'scheduled_subscription_payment' ), 10, 2 );
20
-			add_action( 'wcs_resubscribe_order_created', array( $this, 'delete_resubscribe_meta' ), 10 );
21
-			add_action( 'wcs_renewal_order_created', array( $this, 'delete_renewal_meta' ), 10 );
22
-			add_action( 'woocommerce_subscription_failing_payment_method_updated_stripe', array( $this, 'update_failing_payment_method' ), 10, 2 );
23
-			add_action( 'wc_stripe_sepa_payment_fields', array( $this, 'display_update_subs_payment_checkout' ) );
24
-			add_action( 'wc_stripe_add_payment_method_' . $this->id . '_success', array( $this, 'handle_add_payment_method_success' ), 10, 2 );
18
+		if (class_exists('WC_Subscriptions_Order')) {
19
+			add_action('woocommerce_scheduled_subscription_payment_' . $this->id, array($this, 'scheduled_subscription_payment'), 10, 2);
20
+			add_action('wcs_resubscribe_order_created', array($this, 'delete_resubscribe_meta'), 10);
21
+			add_action('wcs_renewal_order_created', array($this, 'delete_renewal_meta'), 10);
22
+			add_action('woocommerce_subscription_failing_payment_method_updated_stripe', array($this, 'update_failing_payment_method'), 10, 2);
23
+			add_action('wc_stripe_sepa_payment_fields', array($this, 'display_update_subs_payment_checkout'));
24
+			add_action('wc_stripe_add_payment_method_' . $this->id . '_success', array($this, 'handle_add_payment_method_success'), 10, 2);
25 25
 
26 26
 			// Display the credit card used for a subscription in the "My Subscriptions" table.
27
-			add_filter( 'woocommerce_my_subscriptions_payment_method', array( $this, 'maybe_render_subscription_payment_method' ), 10, 2 );
27
+			add_filter('woocommerce_my_subscriptions_payment_method', array($this, 'maybe_render_subscription_payment_method'), 10, 2);
28 28
 
29 29
 			// Allow store managers to manually set Stripe as the payment method on a subscription.
30
-			add_filter( 'woocommerce_subscription_payment_meta', array( $this, 'add_subscription_payment_meta' ), 10, 2 );
31
-			add_filter( 'woocommerce_subscription_validate_payment_meta', array( $this, 'validate_subscription_payment_meta' ), 10, 2 );
32
-			add_filter( 'wc_stripe_display_save_payment_method_checkbox', array( $this, 'maybe_hide_save_checkbox' ) );
30
+			add_filter('woocommerce_subscription_payment_meta', array($this, 'add_subscription_payment_meta'), 10, 2);
31
+			add_filter('woocommerce_subscription_validate_payment_meta', array($this, 'validate_subscription_payment_meta'), 10, 2);
32
+			add_filter('wc_stripe_display_save_payment_method_checkbox', array($this, 'maybe_hide_save_checkbox'));
33 33
 		}
34 34
 	}
35 35
 
@@ -49,8 +49,8 @@  discard block
 block discarded – undo
49 49
 	 * @since 4.0.0
50 50
 	 * @version 4.0.0
51 51
 	 */
52
-	public function maybe_hide_save_checkbox( $display_tokenization ) {
53
-		if ( WC_Subscriptions_Cart::cart_contains_subscription() ) {
52
+	public function maybe_hide_save_checkbox($display_tokenization) {
53
+		if (WC_Subscriptions_Cart::cart_contains_subscription()) {
54 54
 			return false;
55 55
 		}
56 56
 
@@ -62,8 +62,8 @@  discard block
 block discarded – undo
62 62
 	 * @param  int  $order_id
63 63
 	 * @return boolean
64 64
 	 */
65
-	public function has_subscription( $order_id ) {
66
-		return ( function_exists( 'wcs_order_contains_subscription' ) && ( wcs_order_contains_subscription( $order_id ) || wcs_is_subscription( $order_id ) || wcs_order_contains_renewal( $order_id ) ) );
65
+	public function has_subscription($order_id) {
66
+		return (function_exists('wcs_order_contains_subscription') && (wcs_order_contains_subscription($order_id) || wcs_is_subscription($order_id) || wcs_order_contains_renewal($order_id)));
67 67
 	}
68 68
 
69 69
 	/**
@@ -73,7 +73,7 @@  discard block
 block discarded – undo
73 73
 	 * @return bool
74 74
 	 */
75 75
 	public function is_subs_change_payment() {
76
-		return ( isset( $_GET['pay_for_order'] ) && isset( $_GET['change_payment_method'] ) );
76
+		return (isset($_GET['pay_for_order']) && isset($_GET['change_payment_method']));
77 77
 	}
78 78
 
79 79
 	/**
@@ -84,8 +84,8 @@  discard block
 block discarded – undo
84 84
 	 */
85 85
 	public function display_update_subs_payment_checkout() {
86 86
 		if (
87
-			apply_filters( 'wc_stripe_display_update_subs_payment_method_card_checkbox', true ) &&
88
-			wcs_user_has_subscription( get_current_user_id(), '', 'active' ) &&
87
+			apply_filters('wc_stripe_display_update_subs_payment_method_card_checkbox', true) &&
88
+			wcs_user_has_subscription(get_current_user_id(), '', 'active') &&
89 89
 			is_add_payment_method_page()
90 90
 		) {
91 91
 			printf(
@@ -93,8 +93,8 @@  discard block
 block discarded – undo
93 93
 					<input id="wc-%1$s-update-subs-payment-method-card" name="wc-%1$s-update-subs-payment-method-card" type="checkbox" value="true" style="width:auto;" />
94 94
 					<label for="wc-%1$s-update-subs-payment-method-card" style="display:inline;">%2$s</label>
95 95
 				</p>',
96
-				esc_attr( $this->id ),
97
-				esc_html( apply_filters( 'wc_stripe_save_to_subs_text', __( 'Update the Payment Method used for all of my active subscriptions (optional).', 'woocommerce-gateway-stripe' ) ) )
96
+				esc_attr($this->id),
97
+				esc_html(apply_filters('wc_stripe_save_to_subs_text', __('Update the Payment Method used for all of my active subscriptions (optional).', 'woocommerce-gateway-stripe')))
98 98
 			);
99 99
 		}
100 100
 	}
@@ -106,16 +106,16 @@  discard block
 block discarded – undo
106 106
 	 * @param string $source_id
107 107
 	 * @param object $source_object
108 108
 	 */
109
-	public function handle_add_payment_method_success( $source_id, $source_object ) {
110
-		if ( isset( $_POST[ 'wc-' . $this->id . '-update-subs-payment-method-card' ] ) ) {
109
+	public function handle_add_payment_method_success($source_id, $source_object) {
110
+		if (isset($_POST['wc-' . $this->id . '-update-subs-payment-method-card'])) {
111 111
 			$all_subs = wcs_get_users_subscriptions();
112 112
 
113
-			if ( ! empty( $all_subs ) ) {
114
-				foreach ( $all_subs as $sub ) {
115
-					if ( 'active' === $sub->get_status() ) {
116
-						update_post_meta( $sub->get_id(), '_stripe_source_id', $source_id );
117
-						update_post_meta( $sub->get_id(), '_payment_method', $this->id );
118
-						update_post_meta( $sub->get_id(), '_payment_method_title', $this->method_title );
113
+			if ( ! empty($all_subs)) {
114
+				foreach ($all_subs as $sub) {
115
+					if ('active' === $sub->get_status()) {
116
+						update_post_meta($sub->get_id(), '_stripe_source_id', $source_id);
117
+						update_post_meta($sub->get_id(), '_payment_method', $this->id);
118
+						update_post_meta($sub->get_id(), '_payment_method_title', $this->method_title);
119 119
 					}
120 120
 				}
121 121
 			}
@@ -128,24 +128,24 @@  discard block
 block discarded – undo
128 128
 	 * @since 3.1.0
129 129
 	 * @version 4.0.0
130 130
 	 */
131
-	public function save_source_to_order( $order, $source ) {
132
-		parent::save_source_to_order( $order, $source );
131
+	public function save_source_to_order($order, $source) {
132
+		parent::save_source_to_order($order, $source);
133 133
 
134
-		$order_id = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->id : $order->get_id();
134
+		$order_id = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->id : $order->get_id();
135 135
 
136 136
 		// Also store it on the subscriptions being purchased or paid for in the order.
137
-		if ( function_exists( 'wcs_order_contains_subscription' ) && wcs_order_contains_subscription( $order_id ) ) {
138
-			$subscriptions = wcs_get_subscriptions_for_order( $order_id );
139
-		} elseif ( function_exists( 'wcs_order_contains_renewal' ) && wcs_order_contains_renewal( $order_id ) ) {
140
-			$subscriptions = wcs_get_subscriptions_for_renewal_order( $order_id );
137
+		if (function_exists('wcs_order_contains_subscription') && wcs_order_contains_subscription($order_id)) {
138
+			$subscriptions = wcs_get_subscriptions_for_order($order_id);
139
+		} elseif (function_exists('wcs_order_contains_renewal') && wcs_order_contains_renewal($order_id)) {
140
+			$subscriptions = wcs_get_subscriptions_for_renewal_order($order_id);
141 141
 		} else {
142 142
 			$subscriptions = array();
143 143
 		}
144 144
 
145
-		foreach ( $subscriptions as $subscription ) {
146
-			$subscription_id = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $subscription->id : $subscription->get_id();
147
-			update_post_meta( $subscription_id, '_stripe_customer_id', $source->customer );
148
-			update_post_meta( $subscription_id, '_stripe_source_id', $source->source );
145
+		foreach ($subscriptions as $subscription) {
146
+			$subscription_id = WC_Stripe_Helper::is_wc_lt('3.0') ? $subscription->id : $subscription->get_id();
147
+			update_post_meta($subscription_id, '_stripe_customer_id', $source->customer);
148
+			update_post_meta($subscription_id, '_stripe_source_id', $source->source);
149 149
 		}
150 150
 	}
151 151
 
@@ -154,16 +154,16 @@  discard block
 block discarded – undo
154 154
 	 * @param  int $order_id
155 155
 	 * @return array
156 156
 	 */
157
-	public function process_payment( $order_id, $retry = true, $force_save_source = false, $previous_error = false ) {
158
-		if ( $this->has_subscription( $order_id ) ) {
159
-			if ( $this->is_subs_change_payment() ) {
160
-				return $this->change_subs_payment_method( $order_id );
157
+	public function process_payment($order_id, $retry = true, $force_save_source = false, $previous_error = false) {
158
+		if ($this->has_subscription($order_id)) {
159
+			if ($this->is_subs_change_payment()) {
160
+				return $this->change_subs_payment_method($order_id);
161 161
 			}
162 162
 
163 163
 			// Regular payment with force customer enabled
164
-			return parent::process_payment( $order_id, $retry, true, $previous_error );
164
+			return parent::process_payment($order_id, $retry, true, $previous_error);
165 165
 		} else {
166
-			return parent::process_payment( $order_id, $retry, $force_save_source, $previous_error );
166
+			return parent::process_payment($order_id, $retry, $force_save_source, $previous_error);
167 167
 		}
168 168
 	}
169 169
 
@@ -173,27 +173,27 @@  discard block
 block discarded – undo
173 173
 	 * @since 4.0.4
174 174
 	 * @param int $order_id
175 175
 	 */
176
-	public function change_subs_payment_method( $order_id ) {
176
+	public function change_subs_payment_method($order_id) {
177 177
 		try {
178
-			$subscription    = wc_get_order( $order_id );
179
-			$prepared_source = $this->prepare_source( get_current_user_id(), true );
178
+			$subscription    = wc_get_order($order_id);
179
+			$prepared_source = $this->prepare_source(get_current_user_id(), true);
180 180
 
181
-			if ( empty( $prepared_source->source ) ) {
182
-				$localized_message = __( 'Payment processing failed. Please retry.', 'woocommerce-gateway-stripe' );
183
-				throw new WC_Stripe_Exception( print_r( $prepared_source, true ), $localized_message );
181
+			if (empty($prepared_source->source)) {
182
+				$localized_message = __('Payment processing failed. Please retry.', 'woocommerce-gateway-stripe');
183
+				throw new WC_Stripe_Exception(print_r($prepared_source, true), $localized_message);
184 184
 			}
185 185
 
186
-			$this->save_source_to_order( $subscription, $prepared_source );
186
+			$this->save_source_to_order($subscription, $prepared_source);
187 187
 
188
-			do_action( 'wc_stripe_change_subs_payment_method_success', $prepared_source->source, $prepared_source );
188
+			do_action('wc_stripe_change_subs_payment_method_success', $prepared_source->source, $prepared_source);
189 189
 
190 190
 			return array(
191 191
 				'result'   => 'success',
192
-				'redirect' => $this->get_return_url( $subscription ),
192
+				'redirect' => $this->get_return_url($subscription),
193 193
 			);
194
-		} catch ( WC_Stripe_Exception $e ) {
195
-			wc_add_notice( $e->getLocalizedMessage(), 'error' );
196
-			WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() );
194
+		} catch (WC_Stripe_Exception $e) {
195
+			wc_add_notice($e->getLocalizedMessage(), 'error');
196
+			WC_Stripe_Logger::log('Error: ' . $e->getMessage());
197 197
 		}
198 198
 	}
199 199
 
@@ -203,8 +203,8 @@  discard block
 block discarded – undo
203 203
 	 * @param $amount_to_charge float The amount to charge.
204 204
 	 * @param $renewal_order WC_Order A WC_Order object created to record the renewal payment.
205 205
 	 */
206
-	public function scheduled_subscription_payment( $amount_to_charge, $renewal_order ) {
207
-		$this->process_subscription_payment( $amount_to_charge, $renewal_order, true, false );
206
+	public function scheduled_subscription_payment($amount_to_charge, $renewal_order) {
207
+		$this->process_subscription_payment($amount_to_charge, $renewal_order, true, false);
208 208
 	}
209 209
 
210 210
 	/**
@@ -218,86 +218,86 @@  discard block
 block discarded – undo
218 218
 	 * @param bool $retry Should we retry the process?
219 219
 	 * @param object $previous_error
220 220
 	 */
221
-	public function process_subscription_payment( $amount = 0.0, $renewal_order, $retry = true, $previous_error ) {
221
+	public function process_subscription_payment($amount = 0.0, $renewal_order, $retry = true, $previous_error) {
222 222
 		try {
223
-			if ( $amount * 100 < WC_Stripe_Helper::get_minimum_amount() ) {
223
+			if ($amount * 100 < WC_Stripe_Helper::get_minimum_amount()) {
224 224
 				/* translators: minimum amount */
225
-				return new WP_Error( 'stripe_error', sprintf( __( 'Sorry, the minimum allowed order total is %1$s to use this payment method.', 'woocommerce-gateway-stripe' ), wc_price( WC_Stripe_Helper::get_minimum_amount() / 100 ) ) );
225
+				return new WP_Error('stripe_error', sprintf(__('Sorry, the minimum allowed order total is %1$s to use this payment method.', 'woocommerce-gateway-stripe'), wc_price(WC_Stripe_Helper::get_minimum_amount() / 100)));
226 226
 			}
227 227
 
228
-			$order_id = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $renewal_order->id : $renewal_order->get_id();
228
+			$order_id = WC_Stripe_Helper::is_wc_lt('3.0') ? $renewal_order->id : $renewal_order->get_id();
229 229
 
230 230
 			// Get source from order
231
-			$prepared_source = $this->prepare_order_source( $renewal_order );
231
+			$prepared_source = $this->prepare_order_source($renewal_order);
232 232
 			$source_object   = $prepared_source->source_object;
233 233
 
234
-			if ( ! $prepared_source->customer ) {
235
-				return new WP_Error( 'stripe_error', __( 'Customer not found', 'woocommerce-gateway-stripe' ) );
234
+			if ( ! $prepared_source->customer) {
235
+				return new WP_Error('stripe_error', __('Customer not found', 'woocommerce-gateway-stripe'));
236 236
 			}
237 237
 
238
-			WC_Stripe_Logger::log( "Info: Begin processing subscription payment for order {$order_id} for the amount of {$amount}" );
238
+			WC_Stripe_Logger::log("Info: Begin processing subscription payment for order {$order_id} for the amount of {$amount}");
239 239
 
240 240
 			/* If we're doing a retry and source is chargeable, we need to pass
241 241
 			 * a different idempotency key and retry for success.
242 242
 			 */
243
-			if ( is_object( $source_object ) && empty( $source_object->error ) && $this->need_update_idempotency_key( $source_object, $previous_error ) ) {
244
-				add_filter( 'wc_stripe_idempotency_key', array( $this, 'change_idempotency_key' ), 10, 2 );
243
+			if (is_object($source_object) && empty($source_object->error) && $this->need_update_idempotency_key($source_object, $previous_error)) {
244
+				add_filter('wc_stripe_idempotency_key', array($this, 'change_idempotency_key'), 10, 2);
245 245
 			}
246 246
 
247
-			if ( ( $this->is_no_such_source_error( $previous_error ) || $this->is_no_linked_source_error( $previous_error ) ) && apply_filters( 'wc_stripe_use_default_customer_source', true ) ) {
247
+			if (($this->is_no_such_source_error($previous_error) || $this->is_no_linked_source_error($previous_error)) && apply_filters('wc_stripe_use_default_customer_source', true)) {
248 248
 				// Passing empty source will charge customer default.
249 249
 				$prepared_source->source = '';
250 250
 			}
251 251
 
252
-			$request            = $this->generate_payment_request( $renewal_order, $prepared_source );
252
+			$request            = $this->generate_payment_request($renewal_order, $prepared_source);
253 253
 			$request['capture'] = 'true';
254
-			$request['amount']  = WC_Stripe_Helper::get_stripe_amount( $amount, $request['currency'] );
255
-			$response           = WC_Stripe_API::request( $request );
254
+			$request['amount']  = WC_Stripe_Helper::get_stripe_amount($amount, $request['currency']);
255
+			$response           = WC_Stripe_API::request($request);
256 256
 
257
-			if ( ! empty( $response->error ) ) {
257
+			if ( ! empty($response->error)) {
258 258
 				// We want to retry.
259
-				if ( $this->is_retryable_error( $response->error ) ) {
260
-					if ( $retry ) {
259
+				if ($this->is_retryable_error($response->error)) {
260
+					if ($retry) {
261 261
 						// Don't do anymore retries after this.
262
-						if ( 5 <= $this->retry_interval ) {
263
-							return $this->process_subscription_payment( $amount, $renewal_order, false, $response->error );
262
+						if (5 <= $this->retry_interval) {
263
+							return $this->process_subscription_payment($amount, $renewal_order, false, $response->error);
264 264
 						}
265 265
 
266
-						sleep( $this->retry_interval );
266
+						sleep($this->retry_interval);
267 267
 
268 268
 						$this->retry_interval++;
269 269
 
270
-						return $this->process_subscription_payment( $amount, $renewal_order, true, $response->error );
270
+						return $this->process_subscription_payment($amount, $renewal_order, true, $response->error);
271 271
 					} else {
272
-						$localized_message = __( 'Sorry, we are unable to process your payment at this time. Please retry later.', 'woocommerce-gateway-stripe' );
273
-						$renewal_order->add_order_note( $localized_message );
274
-						throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message );
272
+						$localized_message = __('Sorry, we are unable to process your payment at this time. Please retry later.', 'woocommerce-gateway-stripe');
273
+						$renewal_order->add_order_note($localized_message);
274
+						throw new WC_Stripe_Exception(print_r($response, true), $localized_message);
275 275
 					}
276 276
 				}
277 277
 
278 278
 				$localized_messages = WC_Stripe_Helper::get_localized_messages();
279 279
 
280
-				if ( 'card_error' === $response->error->type ) {
281
-					$localized_message = isset( $localized_messages[ $response->error->code ] ) ? $localized_messages[ $response->error->code ] : $response->error->message;
280
+				if ('card_error' === $response->error->type) {
281
+					$localized_message = isset($localized_messages[$response->error->code]) ? $localized_messages[$response->error->code] : $response->error->message;
282 282
 				} else {
283
-					$localized_message = isset( $localized_messages[ $response->error->type ] ) ? $localized_messages[ $response->error->type ] : $response->error->message;
283
+					$localized_message = isset($localized_messages[$response->error->type]) ? $localized_messages[$response->error->type] : $response->error->message;
284 284
 				}
285 285
 
286
-				$renewal_order->add_order_note( $localized_message );
286
+				$renewal_order->add_order_note($localized_message);
287 287
 
288
-				throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message );
288
+				throw new WC_Stripe_Exception(print_r($response, true), $localized_message);
289 289
 			}
290 290
 
291
-			do_action( 'wc_gateway_stripe_process_payment', $response, $renewal_order );
291
+			do_action('wc_gateway_stripe_process_payment', $response, $renewal_order);
292 292
 
293
-			$this->process_response( $response, $renewal_order );
294
-		} catch ( WC_Stripe_Exception $e ) {
295
-			WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() );
293
+			$this->process_response($response, $renewal_order);
294
+		} catch (WC_Stripe_Exception $e) {
295
+			WC_Stripe_Logger::log('Error: ' . $e->getMessage());
296 296
 
297
-			do_action( 'wc_gateway_stripe_process_payment_error', $e, $renewal_order );
297
+			do_action('wc_gateway_stripe_process_payment_error', $e, $renewal_order);
298 298
 
299 299
 			/* translators: error message */
300
-			$renewal_order->update_status( 'failed' );
300
+			$renewal_order->update_status('failed');
301 301
 		}
302 302
 	}
303 303
 
@@ -305,21 +305,21 @@  discard block
 block discarded – undo
305 305
 	 * Don't transfer Stripe customer/token meta to resubscribe orders.
306 306
 	 * @param int $resubscribe_order The order created for the customer to resubscribe to the old expired/cancelled subscription
307 307
 	 */
308
-	public function delete_resubscribe_meta( $resubscribe_order ) {
309
-		delete_post_meta( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $resubscribe_order->id : $resubscribe_order->get_id() ), '_stripe_customer_id' );
310
-		delete_post_meta( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $resubscribe_order->id : $resubscribe_order->get_id() ), '_stripe_source_id' );
308
+	public function delete_resubscribe_meta($resubscribe_order) {
309
+		delete_post_meta((WC_Stripe_Helper::is_wc_lt('3.0') ? $resubscribe_order->id : $resubscribe_order->get_id()), '_stripe_customer_id');
310
+		delete_post_meta((WC_Stripe_Helper::is_wc_lt('3.0') ? $resubscribe_order->id : $resubscribe_order->get_id()), '_stripe_source_id');
311 311
 		// For BW compat will remove in future
312
-		delete_post_meta( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $resubscribe_order->id : $resubscribe_order->get_id() ), '_stripe_card_id' );
313
-		$this->delete_renewal_meta( $resubscribe_order );
312
+		delete_post_meta((WC_Stripe_Helper::is_wc_lt('3.0') ? $resubscribe_order->id : $resubscribe_order->get_id()), '_stripe_card_id');
313
+		$this->delete_renewal_meta($resubscribe_order);
314 314
 	}
315 315
 
316 316
 	/**
317 317
 	 * Don't transfer Stripe fee/ID meta to renewal orders.
318 318
 	 * @param int $resubscribe_order The order created for the customer to resubscribe to the old expired/cancelled subscription
319 319
 	 */
320
-	public function delete_renewal_meta( $renewal_order ) {
321
-		WC_Stripe_Helper::delete_stripe_fee( $renewal_order );
322
-		WC_Stripe_Helper::delete_stripe_net( $renewal_order );
320
+	public function delete_renewal_meta($renewal_order) {
321
+		WC_Stripe_Helper::delete_stripe_fee($renewal_order);
322
+		WC_Stripe_Helper::delete_stripe_net($renewal_order);
323 323
 
324 324
 		return $renewal_order;
325 325
 	}
@@ -333,14 +333,14 @@  discard block
 block discarded – undo
333 333
 	 * @param WC_Order $renewal_order The order which recorded the successful payment (to make up for the failed automatic payment).
334 334
 	 * @return void
335 335
 	 */
336
-	public function update_failing_payment_method( $subscription, $renewal_order ) {
337
-		if ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ) {
338
-			update_post_meta( $subscription->id, '_stripe_customer_id', $renewal_order->stripe_customer_id );
339
-			update_post_meta( $subscription->id, '_stripe_source_id', $renewal_order->stripe_source_id );
336
+	public function update_failing_payment_method($subscription, $renewal_order) {
337
+		if (WC_Stripe_Helper::is_wc_lt('3.0')) {
338
+			update_post_meta($subscription->id, '_stripe_customer_id', $renewal_order->stripe_customer_id);
339
+			update_post_meta($subscription->id, '_stripe_source_id', $renewal_order->stripe_source_id);
340 340
 
341 341
 		} else {
342
-			update_post_meta( $subscription->get_id(), '_stripe_customer_id', $renewal_order->get_meta( '_stripe_customer_id', true ) );
343
-			update_post_meta( $subscription->get_id(), '_stripe_source_id', $renewal_order->get_meta( '_stripe_source_id', true ) );
342
+			update_post_meta($subscription->get_id(), '_stripe_customer_id', $renewal_order->get_meta('_stripe_customer_id', true));
343
+			update_post_meta($subscription->get_id(), '_stripe_source_id', $renewal_order->get_meta('_stripe_source_id', true));
344 344
 		}
345 345
 	}
346 346
 
@@ -353,21 +353,21 @@  discard block
 block discarded – undo
353 353
 	 * @param WC_Subscription $subscription An instance of a subscription object
354 354
 	 * @return array
355 355
 	 */
356
-	public function add_subscription_payment_meta( $payment_meta, $subscription ) {
357
-		$source_id = get_post_meta( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $subscription->id : $subscription->get_id() ), '_stripe_source_id', true );
356
+	public function add_subscription_payment_meta($payment_meta, $subscription) {
357
+		$source_id = get_post_meta((WC_Stripe_Helper::is_wc_lt('3.0') ? $subscription->id : $subscription->get_id()), '_stripe_source_id', true);
358 358
 
359 359
 		// For BW compat will remove in future.
360
-		if ( empty( $source_id ) ) {
361
-			$source_id = get_post_meta( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $subscription->id : $subscription->get_id() ), '_stripe_card_id', true );
360
+		if (empty($source_id)) {
361
+			$source_id = get_post_meta((WC_Stripe_Helper::is_wc_lt('3.0') ? $subscription->id : $subscription->get_id()), '_stripe_card_id', true);
362 362
 
363 363
 			// Take this opportunity to update the key name.
364
-			WC_Stripe_Helper::is_wc_lt( '3.0' ) ? update_post_meta( $subscription->id, '_stripe_source_id', $source_id ) : update_post_meta( $subscription->get_id(), '_stripe_source_id', $source_id );
364
+			WC_Stripe_Helper::is_wc_lt('3.0') ? update_post_meta($subscription->id, '_stripe_source_id', $source_id) : update_post_meta($subscription->get_id(), '_stripe_source_id', $source_id);
365 365
 		}
366 366
 
367
-		$payment_meta[ $this->id ] = array(
367
+		$payment_meta[$this->id] = array(
368 368
 			'post_meta' => array(
369 369
 				'_stripe_customer_id' => array(
370
-					'value' => get_post_meta( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $subscription->id : $subscription->get_id() ), '_stripe_customer_id', true ),
370
+					'value' => get_post_meta((WC_Stripe_Helper::is_wc_lt('3.0') ? $subscription->id : $subscription->get_id()), '_stripe_customer_id', true),
371 371
 					'label' => 'Stripe Customer ID',
372 372
 				),
373 373
 				'_stripe_source_id'   => array(
@@ -388,22 +388,22 @@  discard block
 block discarded – undo
388 388
 	 * @param array $payment_meta associative array of meta data required for automatic payments
389 389
 	 * @return array
390 390
 	 */
391
-	public function validate_subscription_payment_meta( $payment_method_id, $payment_meta ) {
392
-		if ( $this->id === $payment_method_id ) {
391
+	public function validate_subscription_payment_meta($payment_method_id, $payment_meta) {
392
+		if ($this->id === $payment_method_id) {
393 393
 
394
-			if ( ! isset( $payment_meta['post_meta']['_stripe_customer_id']['value'] ) || empty( $payment_meta['post_meta']['_stripe_customer_id']['value'] ) ) {
395
-				throw new Exception( __( 'A "Stripe Customer ID" value is required.', 'woocommerce-gateway-stripe' ) );
396
-			} elseif ( 0 !== strpos( $payment_meta['post_meta']['_stripe_customer_id']['value'], 'cus_' ) ) {
397
-				throw new Exception( __( 'Invalid customer ID. A valid "Stripe Customer ID" must begin with "cus_".', 'woocommerce-gateway-stripe' ) );
394
+			if ( ! isset($payment_meta['post_meta']['_stripe_customer_id']['value']) || empty($payment_meta['post_meta']['_stripe_customer_id']['value'])) {
395
+				throw new Exception(__('A "Stripe Customer ID" value is required.', 'woocommerce-gateway-stripe'));
396
+			} elseif (0 !== strpos($payment_meta['post_meta']['_stripe_customer_id']['value'], 'cus_')) {
397
+				throw new Exception(__('Invalid customer ID. A valid "Stripe Customer ID" must begin with "cus_".', 'woocommerce-gateway-stripe'));
398 398
 			}
399 399
 
400 400
 			if (
401
-				( ! empty( $payment_meta['post_meta']['_stripe_source_id']['value'] )
402
-				&& 0 !== strpos( $payment_meta['post_meta']['_stripe_source_id']['value'], 'card_' ) )
403
-				&& ( ! empty( $payment_meta['post_meta']['_stripe_source_id']['value'] )
404
-				&& 0 !== strpos( $payment_meta['post_meta']['_stripe_source_id']['value'], 'src_' ) ) ) {
401
+				( ! empty($payment_meta['post_meta']['_stripe_source_id']['value'])
402
+				&& 0 !== strpos($payment_meta['post_meta']['_stripe_source_id']['value'], 'card_'))
403
+				&& ( ! empty($payment_meta['post_meta']['_stripe_source_id']['value'])
404
+				&& 0 !== strpos($payment_meta['post_meta']['_stripe_source_id']['value'], 'src_')) ) {
405 405
 
406
-				throw new Exception( __( 'Invalid source ID. A valid source "Stripe Source ID" must begin with "src_" or "card_".', 'woocommerce-gateway-stripe' ) );
406
+				throw new Exception(__('Invalid source ID. A valid source "Stripe Source ID" must begin with "src_" or "card_".', 'woocommerce-gateway-stripe'));
407 407
 			}
408 408
 		}
409 409
 	}
@@ -416,67 +416,67 @@  discard block
 block discarded – undo
416 416
 	 * @param WC_Subscription $subscription the subscription details
417 417
 	 * @return string the subscription payment method
418 418
 	 */
419
-	public function maybe_render_subscription_payment_method( $payment_method_to_display, $subscription ) {
420
-		$customer_user = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $subscription->customer_user : $subscription->get_customer_id();
419
+	public function maybe_render_subscription_payment_method($payment_method_to_display, $subscription) {
420
+		$customer_user = WC_Stripe_Helper::is_wc_lt('3.0') ? $subscription->customer_user : $subscription->get_customer_id();
421 421
 
422 422
 		// bail for other payment methods
423
-		if ( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $subscription->payment_method : $subscription->get_payment_method() ) !== $this->id || ! $customer_user ) {
423
+		if ((WC_Stripe_Helper::is_wc_lt('3.0') ? $subscription->payment_method : $subscription->get_payment_method()) !== $this->id || ! $customer_user) {
424 424
 			return $payment_method_to_display;
425 425
 		}
426 426
 
427
-		$stripe_source_id = get_post_meta( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $subscription->id : $subscription->get_id() ), '_stripe_source_id', true );
427
+		$stripe_source_id = get_post_meta((WC_Stripe_Helper::is_wc_lt('3.0') ? $subscription->id : $subscription->get_id()), '_stripe_source_id', true);
428 428
 
429 429
 		// For BW compat will remove in future.
430
-		if ( empty( $stripe_source_id ) ) {
431
-			$stripe_source_id = get_post_meta( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $subscription->id : $subscription->get_id() ), '_stripe_card_id', true );
430
+		if (empty($stripe_source_id)) {
431
+			$stripe_source_id = get_post_meta((WC_Stripe_Helper::is_wc_lt('3.0') ? $subscription->id : $subscription->get_id()), '_stripe_card_id', true);
432 432
 
433 433
 			// Take this opportunity to update the key name.
434
-			WC_Stripe_Helper::is_wc_lt( '3.0' ) ? update_post_meta( $subscription->id, '_stripe_source_id', $stripe_source_id ) : update_post_meta( $subscription->get_id(), '_stripe_source_id', $stripe_source_id );
434
+			WC_Stripe_Helper::is_wc_lt('3.0') ? update_post_meta($subscription->id, '_stripe_source_id', $stripe_source_id) : update_post_meta($subscription->get_id(), '_stripe_source_id', $stripe_source_id);
435 435
 		}
436 436
 
437 437
 		$stripe_customer    = new WC_Stripe_Customer();
438
-		$stripe_customer_id = get_post_meta( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $subscription->id : $subscription->get_id() ), '_stripe_customer_id', true );
438
+		$stripe_customer_id = get_post_meta((WC_Stripe_Helper::is_wc_lt('3.0') ? $subscription->id : $subscription->get_id()), '_stripe_customer_id', true);
439 439
 
440 440
 		// If we couldn't find a Stripe customer linked to the subscription, fallback to the user meta data.
441
-		if ( ! $stripe_customer_id || ! is_string( $stripe_customer_id ) ) {
441
+		if ( ! $stripe_customer_id || ! is_string($stripe_customer_id)) {
442 442
 			$user_id            = $customer_user;
443
-			$stripe_customer_id = get_user_meta( $user_id, '_stripe_customer_id', true );
444
-			$stripe_source_id   = get_user_meta( $user_id, '_stripe_source_id', true );
443
+			$stripe_customer_id = get_user_meta($user_id, '_stripe_customer_id', true);
444
+			$stripe_source_id   = get_user_meta($user_id, '_stripe_source_id', true);
445 445
 
446 446
 			// For BW compat will remove in future.
447
-			if ( empty( $stripe_source_id ) ) {
448
-				$stripe_source_id = get_user_meta( $user_id, '_stripe_card_id', true );
447
+			if (empty($stripe_source_id)) {
448
+				$stripe_source_id = get_user_meta($user_id, '_stripe_card_id', true);
449 449
 
450 450
 				// Take this opportunity to update the key name.
451
-				update_user_meta( $user_id, '_stripe_source_id', $stripe_source_id );
451
+				update_user_meta($user_id, '_stripe_source_id', $stripe_source_id);
452 452
 			}
453 453
 		}
454 454
 
455 455
 		// If we couldn't find a Stripe customer linked to the account, fallback to the order meta data.
456
-		if ( ( ! $stripe_customer_id || ! is_string( $stripe_customer_id ) ) && false !== $subscription->order ) {
457
-			$stripe_customer_id = get_post_meta( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $subscription->order->id : $subscription->get_parent_id() ), '_stripe_customer_id', true );
458
-			$stripe_source_id   = get_post_meta( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $subscription->order->id : $subscription->get_parent_id() ), '_stripe_source_id', true );
456
+		if (( ! $stripe_customer_id || ! is_string($stripe_customer_id)) && false !== $subscription->order) {
457
+			$stripe_customer_id = get_post_meta((WC_Stripe_Helper::is_wc_lt('3.0') ? $subscription->order->id : $subscription->get_parent_id()), '_stripe_customer_id', true);
458
+			$stripe_source_id   = get_post_meta((WC_Stripe_Helper::is_wc_lt('3.0') ? $subscription->order->id : $subscription->get_parent_id()), '_stripe_source_id', true);
459 459
 
460 460
 			// For BW compat will remove in future.
461
-			if ( empty( $stripe_source_id ) ) {
462
-				$stripe_source_id = get_post_meta( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $subscription->order->id : $subscription->get_parent_id() ), '_stripe_card_id', true );
461
+			if (empty($stripe_source_id)) {
462
+				$stripe_source_id = get_post_meta((WC_Stripe_Helper::is_wc_lt('3.0') ? $subscription->order->id : $subscription->get_parent_id()), '_stripe_card_id', true);
463 463
 
464 464
 				// Take this opportunity to update the key name.
465
-				WC_Stripe_Helper::is_wc_lt( '3.0' ) ? update_post_meta( $subscription->order->id, '_stripe_source_id', $stripe_source_id ) : update_post_meta( $subscription->get_parent_id(), '_stripe_source_id', $stripe_source_id );
465
+				WC_Stripe_Helper::is_wc_lt('3.0') ? update_post_meta($subscription->order->id, '_stripe_source_id', $stripe_source_id) : update_post_meta($subscription->get_parent_id(), '_stripe_source_id', $stripe_source_id);
466 466
 			}
467 467
 		}
468 468
 
469
-		$stripe_customer->set_id( $stripe_customer_id );
469
+		$stripe_customer->set_id($stripe_customer_id);
470 470
 
471 471
 		$sources                   = $stripe_customer->get_sources();
472
-		$payment_method_to_display = __( 'N/A', 'woocommerce-gateway-stripe' );
472
+		$payment_method_to_display = __('N/A', 'woocommerce-gateway-stripe');
473 473
 
474
-		if ( $sources ) {
475
-			foreach ( $sources as $source ) {
476
-				if ( $source->id === $stripe_source_id ) {
477
-					if ( $source->sepa_debit ) {
474
+		if ($sources) {
475
+			foreach ($sources as $source) {
476
+				if ($source->id === $stripe_source_id) {
477
+					if ($source->sepa_debit) {
478 478
 						/* translators: 1) last 4 digits of SEPA Direct Debit */
479
-						$payment_method_to_display = sprintf( __( 'Via SEPA Direct Debit ending in %1$s', 'woocommerce-gateway-stripe' ), $source->sepa_debit->last4 );
479
+						$payment_method_to_display = sprintf(__('Via SEPA Direct Debit ending in %1$s', 'woocommerce-gateway-stripe'), $source->sepa_debit->last4);
480 480
 					}
481 481
 
482 482
 					break;
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 4.2' );
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 4.2');
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/compat/class-wc-stripe-subs-compat.php 2 patches
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -138,7 +138,7 @@  discard block
 block discarded – undo
138 138
 	 * @param float $amount
139 139
 	 * @param mixed $renewal_order
140 140
 	 * @param bool $retry Should we retry the process?
141
-	 * @param object $previous_error
141
+	 * @param boolean $previous_error
142 142
 	 */
143 143
 	public function process_subscription_payment( $amount = 0.0, $renewal_order, $retry = true, $previous_error ) {
144 144
 		try {
@@ -241,7 +241,7 @@  discard block
 block discarded – undo
241 241
 
242 242
 	/**
243 243
 	 * Don't transfer Stripe fee/ID meta to renewal orders.
244
-	 * @param int $resubscribe_order The order created for the customer to resubscribe to the old expired/cancelled subscription
244
+	 * @param integer $renewal_order
245 245
 	 */
246 246
 	public function delete_renewal_meta( $renewal_order ) {
247 247
 		WC_Stripe_Helper::delete_stripe_fee( $renewal_order );
Please login to merge, or discard this patch.
Spacing   +161 added lines, -161 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) {
2
+if ( ! defined('ABSPATH')) {
3 3
 	exit;
4 4
 }
5 5
 
@@ -15,21 +15,21 @@  discard block
 block discarded – undo
15 15
 	public function __construct() {
16 16
 		parent::__construct();
17 17
 
18
-		if ( class_exists( 'WC_Subscriptions_Order' ) ) {
19
-			add_action( 'woocommerce_scheduled_subscription_payment_' . $this->id, array( $this, 'scheduled_subscription_payment' ), 10, 2 );
20
-			add_action( 'wcs_resubscribe_order_created', array( $this, 'delete_resubscribe_meta' ), 10 );
21
-			add_action( 'wcs_renewal_order_created', array( $this, 'delete_renewal_meta' ), 10 );
22
-			add_action( 'woocommerce_subscription_failing_payment_method_updated_stripe', array( $this, 'update_failing_payment_method' ), 10, 2 );
23
-			add_action( 'wc_stripe_cards_payment_fields', array( $this, 'display_update_subs_payment_checkout' ) );
24
-			add_action( 'wc_stripe_add_payment_method_' . $this->id . '_success', array( $this, 'handle_add_payment_method_success' ), 10, 2 );
18
+		if (class_exists('WC_Subscriptions_Order')) {
19
+			add_action('woocommerce_scheduled_subscription_payment_' . $this->id, array($this, 'scheduled_subscription_payment'), 10, 2);
20
+			add_action('wcs_resubscribe_order_created', array($this, 'delete_resubscribe_meta'), 10);
21
+			add_action('wcs_renewal_order_created', array($this, 'delete_renewal_meta'), 10);
22
+			add_action('woocommerce_subscription_failing_payment_method_updated_stripe', array($this, 'update_failing_payment_method'), 10, 2);
23
+			add_action('wc_stripe_cards_payment_fields', array($this, 'display_update_subs_payment_checkout'));
24
+			add_action('wc_stripe_add_payment_method_' . $this->id . '_success', array($this, 'handle_add_payment_method_success'), 10, 2);
25 25
 
26 26
 			// display the credit card used for a subscription in the "My Subscriptions" table
27
-			add_filter( 'woocommerce_my_subscriptions_payment_method', array( $this, 'maybe_render_subscription_payment_method' ), 10, 2 );
27
+			add_filter('woocommerce_my_subscriptions_payment_method', array($this, 'maybe_render_subscription_payment_method'), 10, 2);
28 28
 
29 29
 			// allow store managers to manually set Stripe as the payment method on a subscription
30
-			add_filter( 'woocommerce_subscription_payment_meta', array( $this, 'add_subscription_payment_meta' ), 10, 2 );
31
-			add_filter( 'woocommerce_subscription_validate_payment_meta', array( $this, 'validate_subscription_payment_meta' ), 10, 2 );
32
-			add_filter( 'wc_stripe_display_save_payment_method_checkbox', array( $this, 'maybe_hide_save_checkbox' ) );
30
+			add_filter('woocommerce_subscription_payment_meta', array($this, 'add_subscription_payment_meta'), 10, 2);
31
+			add_filter('woocommerce_subscription_validate_payment_meta', array($this, 'validate_subscription_payment_meta'), 10, 2);
32
+			add_filter('wc_stripe_display_save_payment_method_checkbox', array($this, 'maybe_hide_save_checkbox'));
33 33
 		}
34 34
 	}
35 35
 
@@ -49,8 +49,8 @@  discard block
 block discarded – undo
49 49
 	 * @since 4.0.0
50 50
 	 * @version 4.0.0
51 51
 	 */
52
-	public function maybe_hide_save_checkbox( $display_tokenization ) {
53
-		if ( WC_Subscriptions_Cart::cart_contains_subscription() ) {
52
+	public function maybe_hide_save_checkbox($display_tokenization) {
53
+		if (WC_Subscriptions_Cart::cart_contains_subscription()) {
54 54
 			return false;
55 55
 		}
56 56
 
@@ -62,8 +62,8 @@  discard block
 block discarded – undo
62 62
 	 * @param  int  $order_id
63 63
 	 * @return boolean
64 64
 	 */
65
-	public function has_subscription( $order_id ) {
66
-		return ( function_exists( 'wcs_order_contains_subscription' ) && ( wcs_order_contains_subscription( $order_id ) || wcs_is_subscription( $order_id ) || wcs_order_contains_renewal( $order_id ) ) );
65
+	public function has_subscription($order_id) {
66
+		return (function_exists('wcs_order_contains_subscription') && (wcs_order_contains_subscription($order_id) || wcs_is_subscription($order_id) || wcs_order_contains_renewal($order_id)));
67 67
 	}
68 68
 
69 69
 	/**
@@ -73,7 +73,7 @@  discard block
 block discarded – undo
73 73
 	 * @return bool
74 74
 	 */
75 75
 	public function is_subs_change_payment() {
76
-		return ( isset( $_GET['pay_for_order'] ) && isset( $_GET['change_payment_method'] ) );
76
+		return (isset($_GET['pay_for_order']) && isset($_GET['change_payment_method']));
77 77
 	}
78 78
 
79 79
 	/**
@@ -84,8 +84,8 @@  discard block
 block discarded – undo
84 84
 	 */
85 85
 	public function display_update_subs_payment_checkout() {
86 86
 		if (
87
-			apply_filters( 'wc_stripe_display_update_subs_payment_method_card_checkbox', true ) &&
88
-			wcs_user_has_subscription( get_current_user_id(), '', 'active' ) &&
87
+			apply_filters('wc_stripe_display_update_subs_payment_method_card_checkbox', true) &&
88
+			wcs_user_has_subscription(get_current_user_id(), '', 'active') &&
89 89
 			is_add_payment_method_page()
90 90
 		) {
91 91
 			printf(
@@ -93,8 +93,8 @@  discard block
 block discarded – undo
93 93
 					<input id="wc-%1$s-update-subs-payment-method-card" name="wc-%1$s-update-subs-payment-method-card" type="checkbox" value="true" style="width:auto;" />
94 94
 					<label for="wc-%1$s-update-subs-payment-method-card" style="display:inline;">%2$s</label>
95 95
 				</p>',
96
-				esc_attr( $this->id ),
97
-				esc_html( apply_filters( 'wc_stripe_save_to_subs_text', __( 'Update the Payment Method used for all of my active subscriptions (optional).', 'woocommerce-gateway-stripe' ) ) )
96
+				esc_attr($this->id),
97
+				esc_html(apply_filters('wc_stripe_save_to_subs_text', __('Update the Payment Method used for all of my active subscriptions (optional).', 'woocommerce-gateway-stripe')))
98 98
 			);
99 99
 		}
100 100
 	}
@@ -106,16 +106,16 @@  discard block
 block discarded – undo
106 106
 	 * @param string $source_id
107 107
 	 * @param object $source_object
108 108
 	 */
109
-	public function handle_add_payment_method_success( $source_id, $source_object ) {
110
-		if ( isset( $_POST[ 'wc-' . $this->id . '-update-subs-payment-method-card' ] ) ) {
109
+	public function handle_add_payment_method_success($source_id, $source_object) {
110
+		if (isset($_POST['wc-' . $this->id . '-update-subs-payment-method-card'])) {
111 111
 			$all_subs = wcs_get_users_subscriptions();
112 112
 
113
-			if ( ! empty( $all_subs ) ) {
114
-				foreach ( $all_subs as $sub ) {
115
-					if ( 'active' === $sub->get_status() ) {
116
-						update_post_meta( $sub->get_id(), '_stripe_source_id', $source_id );
117
-						update_post_meta( $sub->get_id(), '_payment_method', $this->id );
118
-						update_post_meta( $sub->get_id(), '_payment_method_title', $this->method_title );
113
+			if ( ! empty($all_subs)) {
114
+				foreach ($all_subs as $sub) {
115
+					if ('active' === $sub->get_status()) {
116
+						update_post_meta($sub->get_id(), '_stripe_source_id', $source_id);
117
+						update_post_meta($sub->get_id(), '_payment_method', $this->id);
118
+						update_post_meta($sub->get_id(), '_payment_method_title', $this->method_title);
119 119
 					}
120 120
 				}
121 121
 			}
@@ -129,34 +129,34 @@  discard block
 block discarded – undo
129 129
 	 * @since 4.1.11 Remove 3DS check as it is not needed.
130 130
 	 * @param int $order_id
131 131
 	 */
132
-	public function change_subs_payment_method( $order_id ) {
132
+	public function change_subs_payment_method($order_id) {
133 133
 		try {
134
-			$subscription    = wc_get_order( $order_id );
135
-			$prepared_source = $this->prepare_source( get_current_user_id(), true );
134
+			$subscription    = wc_get_order($order_id);
135
+			$prepared_source = $this->prepare_source(get_current_user_id(), true);
136 136
 			$source_object   = $prepared_source->source_object;
137 137
 
138 138
 			// Check if we don't allow prepaid credit cards.
139
-			if ( ! apply_filters( 'wc_stripe_allow_prepaid_card', true ) && $this->is_prepaid_card( $source_object ) ) {
140
-				$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' );
141
-				throw new WC_Stripe_Exception( print_r( $source_object, true ), $localized_message );
139
+			if ( ! apply_filters('wc_stripe_allow_prepaid_card', true) && $this->is_prepaid_card($source_object)) {
140
+				$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');
141
+				throw new WC_Stripe_Exception(print_r($source_object, true), $localized_message);
142 142
 			}
143 143
 
144
-			if ( empty( $prepared_source->source ) ) {
145
-				$localized_message = __( 'Payment processing failed. Please retry.', 'woocommerce-gateway-stripe' );
146
-				throw new WC_Stripe_Exception( print_r( $prepared_source, true ), $localized_message );
144
+			if (empty($prepared_source->source)) {
145
+				$localized_message = __('Payment processing failed. Please retry.', 'woocommerce-gateway-stripe');
146
+				throw new WC_Stripe_Exception(print_r($prepared_source, true), $localized_message);
147 147
 			}
148 148
 
149
-			$this->save_source_to_order( $subscription, $prepared_source );
149
+			$this->save_source_to_order($subscription, $prepared_source);
150 150
 
151
-			do_action( 'wc_stripe_change_subs_payment_method_success', $prepared_source->source, $prepared_source );
151
+			do_action('wc_stripe_change_subs_payment_method_success', $prepared_source->source, $prepared_source);
152 152
 
153 153
 			return array(
154 154
 				'result'   => 'success',
155
-				'redirect' => $this->get_return_url( $subscription ),
155
+				'redirect' => $this->get_return_url($subscription),
156 156
 			);
157
-		} catch ( WC_Stripe_Exception $e ) {
158
-			wc_add_notice( $e->getLocalizedMessage(), 'error' );
159
-			WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() );
157
+		} catch (WC_Stripe_Exception $e) {
158
+			wc_add_notice($e->getLocalizedMessage(), 'error');
159
+			WC_Stripe_Logger::log('Error: ' . $e->getMessage());
160 160
 		}
161 161
 	}
162 162
 
@@ -165,16 +165,16 @@  discard block
 block discarded – undo
165 165
 	 * @param  int $order_id
166 166
 	 * @return array
167 167
 	 */
168
-	public function process_payment( $order_id, $retry = true, $force_save_source = false, $previous_error = false ) {
169
-		if ( $this->has_subscription( $order_id ) ) {
170
-			if ( $this->is_subs_change_payment() ) {
171
-				return $this->change_subs_payment_method( $order_id );
168
+	public function process_payment($order_id, $retry = true, $force_save_source = false, $previous_error = false) {
169
+		if ($this->has_subscription($order_id)) {
170
+			if ($this->is_subs_change_payment()) {
171
+				return $this->change_subs_payment_method($order_id);
172 172
 			}
173 173
 
174 174
 			// Regular payment with force customer enabled
175
-			return parent::process_payment( $order_id, $retry, true, $previous_error );
175
+			return parent::process_payment($order_id, $retry, true, $previous_error);
176 176
 		} else {
177
-			return parent::process_payment( $order_id, $retry, $force_save_source, $previous_error );
177
+			return parent::process_payment($order_id, $retry, $force_save_source, $previous_error);
178 178
 		}
179 179
 	}
180 180
 
@@ -184,8 +184,8 @@  discard block
 block discarded – undo
184 184
 	 * @param $amount_to_charge float The amount to charge.
185 185
 	 * @param $renewal_order WC_Order A WC_Order object created to record the renewal payment.
186 186
 	 */
187
-	public function scheduled_subscription_payment( $amount_to_charge, $renewal_order ) {
188
-		$this->process_subscription_payment( $amount_to_charge, $renewal_order, true, false );
187
+	public function scheduled_subscription_payment($amount_to_charge, $renewal_order) {
188
+		$this->process_subscription_payment($amount_to_charge, $renewal_order, true, false);
189 189
 	}
190 190
 
191 191
 	/**
@@ -199,86 +199,86 @@  discard block
 block discarded – undo
199 199
 	 * @param bool $retry Should we retry the process?
200 200
 	 * @param object $previous_error
201 201
 	 */
202
-	public function process_subscription_payment( $amount = 0.0, $renewal_order, $retry = true, $previous_error ) {
202
+	public function process_subscription_payment($amount = 0.0, $renewal_order, $retry = true, $previous_error) {
203 203
 		try {
204
-			if ( $amount * 100 < WC_Stripe_Helper::get_minimum_amount() ) {
204
+			if ($amount * 100 < WC_Stripe_Helper::get_minimum_amount()) {
205 205
 				/* translators: minimum amount */
206
-				return new WP_Error( 'stripe_error', sprintf( __( 'Sorry, the minimum allowed order total is %1$s to use this payment method.', 'woocommerce-gateway-stripe' ), wc_price( WC_Stripe_Helper::get_minimum_amount() / 100 ) ) );
206
+				return new WP_Error('stripe_error', sprintf(__('Sorry, the minimum allowed order total is %1$s to use this payment method.', 'woocommerce-gateway-stripe'), wc_price(WC_Stripe_Helper::get_minimum_amount() / 100)));
207 207
 			}
208 208
 
209
-			$order_id = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $renewal_order->id : $renewal_order->get_id();
209
+			$order_id = WC_Stripe_Helper::is_wc_lt('3.0') ? $renewal_order->id : $renewal_order->get_id();
210 210
 
211 211
 			// Get source from order
212
-			$prepared_source = $this->prepare_order_source( $renewal_order );
212
+			$prepared_source = $this->prepare_order_source($renewal_order);
213 213
 			$source_object   = $prepared_source->source_object;
214 214
 
215
-			if ( ! $prepared_source->customer ) {
216
-				return new WP_Error( 'stripe_error', __( 'Customer not found', 'woocommerce-gateway-stripe' ) );
215
+			if ( ! $prepared_source->customer) {
216
+				return new WP_Error('stripe_error', __('Customer not found', 'woocommerce-gateway-stripe'));
217 217
 			}
218 218
 
219
-			WC_Stripe_Logger::log( "Info: Begin processing subscription payment for order {$order_id} for the amount of {$amount}" );
219
+			WC_Stripe_Logger::log("Info: Begin processing subscription payment for order {$order_id} for the amount of {$amount}");
220 220
 
221 221
 			/* If we're doing a retry and source is chargeable, we need to pass
222 222
 			 * a different idempotency key and retry for success.
223 223
 			 */
224
-			if ( is_object( $source_object ) && empty( $source_object->error ) && $this->need_update_idempotency_key( $source_object, $previous_error ) ) {
225
-				add_filter( 'wc_stripe_idempotency_key', array( $this, 'change_idempotency_key' ), 10, 2 );
224
+			if (is_object($source_object) && empty($source_object->error) && $this->need_update_idempotency_key($source_object, $previous_error)) {
225
+				add_filter('wc_stripe_idempotency_key', array($this, 'change_idempotency_key'), 10, 2);
226 226
 			}
227 227
 
228
-			if ( ( $this->is_no_such_source_error( $previous_error ) || $this->is_no_linked_source_error( $previous_error ) ) && apply_filters( 'wc_stripe_use_default_customer_source', true ) ) {
228
+			if (($this->is_no_such_source_error($previous_error) || $this->is_no_linked_source_error($previous_error)) && apply_filters('wc_stripe_use_default_customer_source', true)) {
229 229
 				// Passing empty source will charge customer default.
230 230
 				$prepared_source->source = '';
231 231
 			}
232 232
 
233
-			$request            = $this->generate_payment_request( $renewal_order, $prepared_source );
233
+			$request            = $this->generate_payment_request($renewal_order, $prepared_source);
234 234
 			$request['capture'] = 'true';
235
-			$request['amount']  = WC_Stripe_Helper::get_stripe_amount( $amount, $request['currency'] );
236
-			$response           = WC_Stripe_API::request( $request );
235
+			$request['amount']  = WC_Stripe_Helper::get_stripe_amount($amount, $request['currency']);
236
+			$response           = WC_Stripe_API::request($request);
237 237
 
238
-			if ( ! empty( $response->error ) ) {
238
+			if ( ! empty($response->error)) {
239 239
 				// We want to retry.
240
-				if ( $this->is_retryable_error( $response->error ) ) {
241
-					if ( $retry ) {
240
+				if ($this->is_retryable_error($response->error)) {
241
+					if ($retry) {
242 242
 						// Don't do anymore retries after this.
243
-						if ( 5 <= $this->retry_interval ) {
244
-							return $this->process_subscription_payment( $amount, $renewal_order, false, $response->error );
243
+						if (5 <= $this->retry_interval) {
244
+							return $this->process_subscription_payment($amount, $renewal_order, false, $response->error);
245 245
 						}
246 246
 
247
-						sleep( $this->retry_interval );
247
+						sleep($this->retry_interval);
248 248
 
249 249
 						$this->retry_interval++;
250 250
 
251
-						return $this->process_subscription_payment( $amount, $renewal_order, true, $response->error );
251
+						return $this->process_subscription_payment($amount, $renewal_order, true, $response->error);
252 252
 					} else {
253
-						$localized_message = __( 'Sorry, we are unable to process your payment at this time. Please retry later.', 'woocommerce-gateway-stripe' );
254
-						$renewal_order->add_order_note( $localized_message );
255
-						throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message );
253
+						$localized_message = __('Sorry, we are unable to process your payment at this time. Please retry later.', 'woocommerce-gateway-stripe');
254
+						$renewal_order->add_order_note($localized_message);
255
+						throw new WC_Stripe_Exception(print_r($response, true), $localized_message);
256 256
 					}
257 257
 				}
258 258
 
259 259
 				$localized_messages = WC_Stripe_Helper::get_localized_messages();
260 260
 
261
-				if ( 'card_error' === $response->error->type ) {
262
-					$localized_message = isset( $localized_messages[ $response->error->code ] ) ? $localized_messages[ $response->error->code ] : $response->error->message;
261
+				if ('card_error' === $response->error->type) {
262
+					$localized_message = isset($localized_messages[$response->error->code]) ? $localized_messages[$response->error->code] : $response->error->message;
263 263
 				} else {
264
-					$localized_message = isset( $localized_messages[ $response->error->type ] ) ? $localized_messages[ $response->error->type ] : $response->error->message;
264
+					$localized_message = isset($localized_messages[$response->error->type]) ? $localized_messages[$response->error->type] : $response->error->message;
265 265
 				}
266 266
 
267
-				$renewal_order->add_order_note( $localized_message );
267
+				$renewal_order->add_order_note($localized_message);
268 268
 
269
-				throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message );
269
+				throw new WC_Stripe_Exception(print_r($response, true), $localized_message);
270 270
 			}
271 271
 
272
-			do_action( 'wc_gateway_stripe_process_payment', $response, $renewal_order );
272
+			do_action('wc_gateway_stripe_process_payment', $response, $renewal_order);
273 273
 
274
-			$this->process_response( $response, $renewal_order );
275
-		} catch ( WC_Stripe_Exception $e ) {
276
-			WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() );
274
+			$this->process_response($response, $renewal_order);
275
+		} catch (WC_Stripe_Exception $e) {
276
+			WC_Stripe_Logger::log('Error: ' . $e->getMessage());
277 277
 
278
-			do_action( 'wc_gateway_stripe_process_payment_error', $e, $renewal_order );
278
+			do_action('wc_gateway_stripe_process_payment_error', $e, $renewal_order);
279 279
 
280 280
 			/* translators: error message */
281
-			$renewal_order->update_status( 'failed' );
281
+			$renewal_order->update_status('failed');
282 282
 		}
283 283
 	}
284 284
 
@@ -288,24 +288,24 @@  discard block
 block discarded – undo
288 288
 	 * @since 3.1.0
289 289
 	 * @version 4.0.0
290 290
 	 */
291
-	public function save_source_to_order( $order, $source ) {
292
-		parent::save_source_to_order( $order, $source );
291
+	public function save_source_to_order($order, $source) {
292
+		parent::save_source_to_order($order, $source);
293 293
 
294
-		$order_id = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->id : $order->get_id();
294
+		$order_id = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->id : $order->get_id();
295 295
 
296 296
 		// Also store it on the subscriptions being purchased or paid for in the order
297
-		if ( function_exists( 'wcs_order_contains_subscription' ) && wcs_order_contains_subscription( $order_id ) ) {
298
-			$subscriptions = wcs_get_subscriptions_for_order( $order_id );
299
-		} elseif ( function_exists( 'wcs_order_contains_renewal' ) && wcs_order_contains_renewal( $order_id ) ) {
300
-			$subscriptions = wcs_get_subscriptions_for_renewal_order( $order_id );
297
+		if (function_exists('wcs_order_contains_subscription') && wcs_order_contains_subscription($order_id)) {
298
+			$subscriptions = wcs_get_subscriptions_for_order($order_id);
299
+		} elseif (function_exists('wcs_order_contains_renewal') && wcs_order_contains_renewal($order_id)) {
300
+			$subscriptions = wcs_get_subscriptions_for_renewal_order($order_id);
301 301
 		} else {
302 302
 			$subscriptions = array();
303 303
 		}
304 304
 
305
-		foreach ( $subscriptions as $subscription ) {
306
-			$subscription_id = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $subscription->id : $subscription->get_id();
307
-			update_post_meta( $subscription_id, '_stripe_customer_id', $source->customer );
308
-			update_post_meta( $subscription_id, '_stripe_source_id', $source->source );
305
+		foreach ($subscriptions as $subscription) {
306
+			$subscription_id = WC_Stripe_Helper::is_wc_lt('3.0') ? $subscription->id : $subscription->get_id();
307
+			update_post_meta($subscription_id, '_stripe_customer_id', $source->customer);
308
+			update_post_meta($subscription_id, '_stripe_source_id', $source->source);
309 309
 		}
310 310
 	}
311 311
 
@@ -313,21 +313,21 @@  discard block
 block discarded – undo
313 313
 	 * Don't transfer Stripe customer/token meta to resubscribe orders.
314 314
 	 * @param int $resubscribe_order The order created for the customer to resubscribe to the old expired/cancelled subscription
315 315
 	 */
316
-	public function delete_resubscribe_meta( $resubscribe_order ) {
317
-		delete_post_meta( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $resubscribe_order->id : $resubscribe_order->get_id() ), '_stripe_customer_id' );
318
-		delete_post_meta( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $resubscribe_order->id : $resubscribe_order->get_id() ), '_stripe_source_id' );
316
+	public function delete_resubscribe_meta($resubscribe_order) {
317
+		delete_post_meta((WC_Stripe_Helper::is_wc_lt('3.0') ? $resubscribe_order->id : $resubscribe_order->get_id()), '_stripe_customer_id');
318
+		delete_post_meta((WC_Stripe_Helper::is_wc_lt('3.0') ? $resubscribe_order->id : $resubscribe_order->get_id()), '_stripe_source_id');
319 319
 		// For BW compat will remove in future
320
-		delete_post_meta( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $resubscribe_order->id : $resubscribe_order->get_id() ), '_stripe_card_id' );
321
-		$this->delete_renewal_meta( $resubscribe_order );
320
+		delete_post_meta((WC_Stripe_Helper::is_wc_lt('3.0') ? $resubscribe_order->id : $resubscribe_order->get_id()), '_stripe_card_id');
321
+		$this->delete_renewal_meta($resubscribe_order);
322 322
 	}
323 323
 
324 324
 	/**
325 325
 	 * Don't transfer Stripe fee/ID meta to renewal orders.
326 326
 	 * @param int $resubscribe_order The order created for the customer to resubscribe to the old expired/cancelled subscription
327 327
 	 */
328
-	public function delete_renewal_meta( $renewal_order ) {
329
-		WC_Stripe_Helper::delete_stripe_fee( $renewal_order );
330
-		WC_Stripe_Helper::delete_stripe_net( $renewal_order );
328
+	public function delete_renewal_meta($renewal_order) {
329
+		WC_Stripe_Helper::delete_stripe_fee($renewal_order);
330
+		WC_Stripe_Helper::delete_stripe_net($renewal_order);
331 331
 
332 332
 		return $renewal_order;
333 333
 	}
@@ -341,14 +341,14 @@  discard block
 block discarded – undo
341 341
 	 * @param WC_Order $renewal_order The order which recorded the successful payment (to make up for the failed automatic payment).
342 342
 	 * @return void
343 343
 	 */
344
-	public function update_failing_payment_method( $subscription, $renewal_order ) {
345
-		if ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ) {
346
-			update_post_meta( $subscription->id, '_stripe_customer_id', $renewal_order->stripe_customer_id );
347
-			update_post_meta( $subscription->id, '_stripe_source_id', $renewal_order->stripe_source_id );
344
+	public function update_failing_payment_method($subscription, $renewal_order) {
345
+		if (WC_Stripe_Helper::is_wc_lt('3.0')) {
346
+			update_post_meta($subscription->id, '_stripe_customer_id', $renewal_order->stripe_customer_id);
347
+			update_post_meta($subscription->id, '_stripe_source_id', $renewal_order->stripe_source_id);
348 348
 
349 349
 		} else {
350
-			update_post_meta( $subscription->get_id(), '_stripe_customer_id', $renewal_order->get_meta( '_stripe_customer_id', true ) );
351
-			update_post_meta( $subscription->get_id(), '_stripe_source_id', $renewal_order->get_meta( '_stripe_source_id', true ) );
350
+			update_post_meta($subscription->get_id(), '_stripe_customer_id', $renewal_order->get_meta('_stripe_customer_id', true));
351
+			update_post_meta($subscription->get_id(), '_stripe_source_id', $renewal_order->get_meta('_stripe_source_id', true));
352 352
 		}
353 353
 	}
354 354
 
@@ -361,23 +361,23 @@  discard block
 block discarded – undo
361 361
 	 * @param WC_Subscription $subscription An instance of a subscription object
362 362
 	 * @return array
363 363
 	 */
364
-	public function add_subscription_payment_meta( $payment_meta, $subscription ) {
365
-		$subscription_id = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $subscription->id : $subscription->get_id();
366
-		$source_id       = get_post_meta( $subscription_id, '_stripe_source_id', true );
364
+	public function add_subscription_payment_meta($payment_meta, $subscription) {
365
+		$subscription_id = WC_Stripe_Helper::is_wc_lt('3.0') ? $subscription->id : $subscription->get_id();
366
+		$source_id       = get_post_meta($subscription_id, '_stripe_source_id', true);
367 367
 
368 368
 		// For BW compat will remove in future.
369
-		if ( empty( $source_id ) ) {
370
-			$source_id = get_post_meta( $subscription_id, '_stripe_card_id', true );
369
+		if (empty($source_id)) {
370
+			$source_id = get_post_meta($subscription_id, '_stripe_card_id', true);
371 371
 
372 372
 			// Take this opportunity to update the key name.
373
-			update_post_meta( $subscription_id, '_stripe_source_id', $source_id );
374
-			delete_post_meta( $subscription_id, '_stripe_card_id', $source_id );
373
+			update_post_meta($subscription_id, '_stripe_source_id', $source_id);
374
+			delete_post_meta($subscription_id, '_stripe_card_id', $source_id);
375 375
 		}
376 376
 
377
-		$payment_meta[ $this->id ] = array(
377
+		$payment_meta[$this->id] = array(
378 378
 			'post_meta' => array(
379 379
 				'_stripe_customer_id' => array(
380
-					'value' => get_post_meta( $subscription_id, '_stripe_customer_id', true ),
380
+					'value' => get_post_meta($subscription_id, '_stripe_customer_id', true),
381 381
 					'label' => 'Stripe Customer ID',
382 382
 				),
383 383
 				'_stripe_source_id'   => array(
@@ -400,22 +400,22 @@  discard block
 block discarded – undo
400 400
 	 * @param array $payment_meta associative array of meta data required for automatic payments
401 401
 	 * @return array
402 402
 	 */
403
-	public function validate_subscription_payment_meta( $payment_method_id, $payment_meta ) {
404
-		if ( $this->id === $payment_method_id ) {
403
+	public function validate_subscription_payment_meta($payment_method_id, $payment_meta) {
404
+		if ($this->id === $payment_method_id) {
405 405
 
406
-			if ( ! isset( $payment_meta['post_meta']['_stripe_customer_id']['value'] ) || empty( $payment_meta['post_meta']['_stripe_customer_id']['value'] ) ) {
407
-				throw new Exception( __( 'A "Stripe Customer ID" value is required.', 'woocommerce-gateway-stripe' ) );
408
-			} elseif ( 0 !== strpos( $payment_meta['post_meta']['_stripe_customer_id']['value'], 'cus_' ) ) {
409
-				throw new Exception( __( 'Invalid customer ID. A valid "Stripe Customer ID" must begin with "cus_".', 'woocommerce-gateway-stripe' ) );
406
+			if ( ! isset($payment_meta['post_meta']['_stripe_customer_id']['value']) || empty($payment_meta['post_meta']['_stripe_customer_id']['value'])) {
407
+				throw new Exception(__('A "Stripe Customer ID" value is required.', 'woocommerce-gateway-stripe'));
408
+			} elseif (0 !== strpos($payment_meta['post_meta']['_stripe_customer_id']['value'], 'cus_')) {
409
+				throw new Exception(__('Invalid customer ID. A valid "Stripe Customer ID" must begin with "cus_".', 'woocommerce-gateway-stripe'));
410 410
 			}
411 411
 
412 412
 			if (
413
-				( ! empty( $payment_meta['post_meta']['_stripe_source_id']['value'] )
414
-				&& 0 !== strpos( $payment_meta['post_meta']['_stripe_source_id']['value'], 'card_' ) )
415
-				&& ( ! empty( $payment_meta['post_meta']['_stripe_source_id']['value'] )
416
-				&& 0 !== strpos( $payment_meta['post_meta']['_stripe_source_id']['value'], 'src_' ) ) ) {
413
+				( ! empty($payment_meta['post_meta']['_stripe_source_id']['value'])
414
+				&& 0 !== strpos($payment_meta['post_meta']['_stripe_source_id']['value'], 'card_'))
415
+				&& ( ! empty($payment_meta['post_meta']['_stripe_source_id']['value'])
416
+				&& 0 !== strpos($payment_meta['post_meta']['_stripe_source_id']['value'], 'src_')) ) {
417 417
 
418
-				throw new Exception( __( 'Invalid source ID. A valid source "Stripe Source ID" must begin with "src_" or "card_".', 'woocommerce-gateway-stripe' ) );
418
+				throw new Exception(__('Invalid source ID. A valid source "Stripe Source ID" must begin with "src_" or "card_".', 'woocommerce-gateway-stripe'));
419 419
 			}
420 420
 		}
421 421
 	}
@@ -428,75 +428,75 @@  discard block
 block discarded – undo
428 428
 	 * @param WC_Subscription $subscription the subscription details
429 429
 	 * @return string the subscription payment method
430 430
 	 */
431
-	public function maybe_render_subscription_payment_method( $payment_method_to_display, $subscription ) {
432
-		$customer_user = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $subscription->customer_user : $subscription->get_customer_id();
431
+	public function maybe_render_subscription_payment_method($payment_method_to_display, $subscription) {
432
+		$customer_user = WC_Stripe_Helper::is_wc_lt('3.0') ? $subscription->customer_user : $subscription->get_customer_id();
433 433
 
434 434
 		// bail for other payment methods
435
-		if ( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $subscription->payment_method : $subscription->get_payment_method() ) !== $this->id || ! $customer_user ) {
435
+		if ((WC_Stripe_Helper::is_wc_lt('3.0') ? $subscription->payment_method : $subscription->get_payment_method()) !== $this->id || ! $customer_user) {
436 436
 			return $payment_method_to_display;
437 437
 		}
438 438
 
439
-		$stripe_source_id = get_post_meta( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $subscription->id : $subscription->get_id() ), '_stripe_source_id', true );
439
+		$stripe_source_id = get_post_meta((WC_Stripe_Helper::is_wc_lt('3.0') ? $subscription->id : $subscription->get_id()), '_stripe_source_id', true);
440 440
 
441 441
 		// For BW compat will remove in future.
442
-		if ( empty( $stripe_source_id ) ) {
443
-			$stripe_source_id = get_post_meta( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $subscription->id : $subscription->get_id() ), '_stripe_card_id', true );
442
+		if (empty($stripe_source_id)) {
443
+			$stripe_source_id = get_post_meta((WC_Stripe_Helper::is_wc_lt('3.0') ? $subscription->id : $subscription->get_id()), '_stripe_card_id', true);
444 444
 
445 445
 			// Take this opportunity to update the key name.
446
-			WC_Stripe_Helper::is_wc_lt( '3.0' ) ? update_post_meta( $subscription->id, '_stripe_source_id', $stripe_source_id ) : update_post_meta( $subscription->get_id(), '_stripe_source_id', $stripe_source_id );
446
+			WC_Stripe_Helper::is_wc_lt('3.0') ? update_post_meta($subscription->id, '_stripe_source_id', $stripe_source_id) : update_post_meta($subscription->get_id(), '_stripe_source_id', $stripe_source_id);
447 447
 		}
448 448
 
449 449
 		$stripe_customer    = new WC_Stripe_Customer();
450
-		$stripe_customer_id = get_post_meta( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $subscription->id : $subscription->get_id() ), '_stripe_customer_id', true );
450
+		$stripe_customer_id = get_post_meta((WC_Stripe_Helper::is_wc_lt('3.0') ? $subscription->id : $subscription->get_id()), '_stripe_customer_id', true);
451 451
 
452 452
 		// If we couldn't find a Stripe customer linked to the subscription, fallback to the user meta data.
453
-		if ( ! $stripe_customer_id || ! is_string( $stripe_customer_id ) ) {
453
+		if ( ! $stripe_customer_id || ! is_string($stripe_customer_id)) {
454 454
 			$user_id            = $customer_user;
455
-			$stripe_customer_id = get_user_meta( $user_id, '_stripe_customer_id', true );
456
-			$stripe_source_id   = get_user_meta( $user_id, '_stripe_source_id', true );
455
+			$stripe_customer_id = get_user_meta($user_id, '_stripe_customer_id', true);
456
+			$stripe_source_id   = get_user_meta($user_id, '_stripe_source_id', true);
457 457
 
458 458
 			// For BW compat will remove in future.
459
-			if ( empty( $stripe_source_id ) ) {
460
-				$stripe_source_id = get_user_meta( $user_id, '_stripe_card_id', true );
459
+			if (empty($stripe_source_id)) {
460
+				$stripe_source_id = get_user_meta($user_id, '_stripe_card_id', true);
461 461
 
462 462
 				// Take this opportunity to update the key name.
463
-				update_user_meta( $user_id, '_stripe_source_id', $stripe_source_id );
463
+				update_user_meta($user_id, '_stripe_source_id', $stripe_source_id);
464 464
 			}
465 465
 		}
466 466
 
467 467
 		// If we couldn't find a Stripe customer linked to the account, fallback to the order meta data.
468
-		if ( ( ! $stripe_customer_id || ! is_string( $stripe_customer_id ) ) && false !== $subscription->order ) {
469
-			$stripe_customer_id = get_post_meta( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $subscription->order->id : $subscription->get_parent_id() ), '_stripe_customer_id', true );
470
-			$stripe_source_id   = get_post_meta( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $subscription->order->id : $subscription->get_parent_id() ), '_stripe_source_id', true );
468
+		if (( ! $stripe_customer_id || ! is_string($stripe_customer_id)) && false !== $subscription->order) {
469
+			$stripe_customer_id = get_post_meta((WC_Stripe_Helper::is_wc_lt('3.0') ? $subscription->order->id : $subscription->get_parent_id()), '_stripe_customer_id', true);
470
+			$stripe_source_id   = get_post_meta((WC_Stripe_Helper::is_wc_lt('3.0') ? $subscription->order->id : $subscription->get_parent_id()), '_stripe_source_id', true);
471 471
 
472 472
 			// For BW compat will remove in future.
473
-			if ( empty( $stripe_source_id ) ) {
474
-				$stripe_source_id = get_post_meta( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $subscription->order->id : $subscription->get_parent_id() ), '_stripe_card_id', true );
473
+			if (empty($stripe_source_id)) {
474
+				$stripe_source_id = get_post_meta((WC_Stripe_Helper::is_wc_lt('3.0') ? $subscription->order->id : $subscription->get_parent_id()), '_stripe_card_id', true);
475 475
 
476 476
 				// Take this opportunity to update the key name.
477
-				WC_Stripe_Helper::is_wc_lt( '3.0' ) ? update_post_meta( $subscription->order->id, '_stripe_source_id', $stripe_source_id ) : update_post_meta( $subscription->get_parent_id(), '_stripe_source_id', $stripe_source_id );
477
+				WC_Stripe_Helper::is_wc_lt('3.0') ? update_post_meta($subscription->order->id, '_stripe_source_id', $stripe_source_id) : update_post_meta($subscription->get_parent_id(), '_stripe_source_id', $stripe_source_id);
478 478
 			}
479 479
 		}
480 480
 
481
-		$stripe_customer->set_id( $stripe_customer_id );
481
+		$stripe_customer->set_id($stripe_customer_id);
482 482
 
483 483
 		$sources                   = $stripe_customer->get_sources();
484
-		$payment_method_to_display = __( 'N/A', 'woocommerce-gateway-stripe' );
484
+		$payment_method_to_display = __('N/A', 'woocommerce-gateway-stripe');
485 485
 
486
-		if ( $sources ) {
486
+		if ($sources) {
487 487
 			$card = false;
488 488
 
489
-			foreach ( $sources as $source ) {
490
-				if ( isset( $source->type ) && 'card' === $source->type ) {
489
+			foreach ($sources as $source) {
490
+				if (isset($source->type) && 'card' === $source->type) {
491 491
 					$card = $source->card;
492
-				} elseif ( isset( $source->object ) && 'card' === $source->object ) {
492
+				} elseif (isset($source->object) && 'card' === $source->object) {
493 493
 					$card = $source;
494 494
 				}
495 495
 
496
-				if ( $source->id === $stripe_source_id ) {
497
-					if ( $card ) {
496
+				if ($source->id === $stripe_source_id) {
497
+					if ($card) {
498 498
 						/* translators: 1) card brand 2) last 4 digits */
499
-						$payment_method_to_display = sprintf( __( 'Via %1$s card ending in %2$s', 'woocommerce-gateway-stripe' ), ( isset( $card->brand ) ? $card->brand : __( 'N/A', 'woocommerce-gateway-stripe' ) ), $card->last4 );
499
+						$payment_method_to_display = sprintf(__('Via %1$s card ending in %2$s', 'woocommerce-gateway-stripe'), (isset($card->brand) ? $card->brand : __('N/A', 'woocommerce-gateway-stripe')), $card->last4);
500 500
 					}
501 501
 
502 502
 					break;
Please login to merge, or discard this patch.
includes/class-wc-stripe-payment-tokens.php 1 patch
Spacing   +63 added lines, -63 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
 
@@ -21,11 +21,11 @@  discard block
 block discarded – undo
21 21
 	public function __construct() {
22 22
 		self::$_this = $this;
23 23
 
24
-		add_filter( 'woocommerce_get_customer_payment_tokens', array( $this, 'woocommerce_get_customer_payment_tokens' ), 10, 3 );
25
-		add_filter( 'woocommerce_payment_methods_list_item', array( $this, 'get_account_saved_payment_methods_list_item_sepa' ), 10, 2 );
26
-		add_filter( 'woocommerce_get_credit_card_type_label', array( $this, 'normalize_sepa_label' ) );
27
-		add_action( 'woocommerce_payment_token_deleted', array( $this, 'woocommerce_payment_token_deleted' ), 10, 2 );
28
-		add_action( 'woocommerce_payment_token_set_default', array( $this, 'woocommerce_payment_token_set_default' ) );
24
+		add_filter('woocommerce_get_customer_payment_tokens', array($this, 'woocommerce_get_customer_payment_tokens'), 10, 3);
25
+		add_filter('woocommerce_payment_methods_list_item', array($this, 'get_account_saved_payment_methods_list_item_sepa'), 10, 2);
26
+		add_filter('woocommerce_get_credit_card_type_label', array($this, 'normalize_sepa_label'));
27
+		add_action('woocommerce_payment_token_deleted', array($this, 'woocommerce_payment_token_deleted'), 10, 2);
28
+		add_action('woocommerce_payment_token_set_default', array($this, 'woocommerce_payment_token_set_default'));
29 29
 	}
30 30
 
31 31
 	/**
@@ -46,8 +46,8 @@  discard block
 block discarded – undo
46 46
 	 * @param string $label
47 47
 	 * @return string $label
48 48
 	 */
49
-	public function normalize_sepa_label( $label ) {
50
-		if ( 'sepa iban' === strtolower( $label ) ) {
49
+	public function normalize_sepa_label($label) {
50
+		if ('sepa iban' === strtolower($label)) {
51 51
 			return 'SEPA IBAN';
52 52
 		}
53 53
 
@@ -61,19 +61,19 @@  discard block
 block discarded – undo
61 61
 	 * @param int $customer_id
62 62
 	 * @return bool
63 63
 	 */
64
-	public static function customer_has_saved_methods( $customer_id ) {
65
-		$gateways = array( 'stripe', 'stripe_sepa' );
64
+	public static function customer_has_saved_methods($customer_id) {
65
+		$gateways = array('stripe', 'stripe_sepa');
66 66
 
67
-		if ( empty( $customer_id ) ) {
67
+		if (empty($customer_id)) {
68 68
 			return false;
69 69
 		}
70 70
 
71 71
 		$has_token = false;
72 72
 
73
-		foreach ( $gateways as $gateway ) {
74
-			$tokens = WC_Payment_Tokens::get_customer_tokens( $customer_id, $gateway );
73
+		foreach ($gateways as $gateway) {
74
+			$tokens = WC_Payment_Tokens::get_customer_tokens($customer_id, $gateway);
75 75
 
76
-			if ( ! empty( $tokens ) ) {
76
+			if ( ! empty($tokens)) {
77 77
 				$has_token = true;
78 78
 				break;
79 79
 			}
@@ -90,67 +90,67 @@  discard block
 block discarded – undo
90 90
 	 * @param array $tokens
91 91
 	 * @return array
92 92
 	 */
93
-	public function woocommerce_get_customer_payment_tokens( $tokens = array(), $customer_id, $gateway_id ) {
94
-		if ( is_user_logged_in() && class_exists( 'WC_Payment_Token_CC' ) ) {
93
+	public function woocommerce_get_customer_payment_tokens($tokens = array(), $customer_id, $gateway_id) {
94
+		if (is_user_logged_in() && class_exists('WC_Payment_Token_CC')) {
95 95
 			$stored_tokens = array();
96 96
 
97
-			foreach ( $tokens as $token ) {
97
+			foreach ($tokens as $token) {
98 98
 				$stored_tokens[] = $token->get_token();
99 99
 			}
100 100
 
101
-			if ( 'stripe' === $gateway_id ) {
102
-				$stripe_customer = new WC_Stripe_Customer( $customer_id );
101
+			if ('stripe' === $gateway_id) {
102
+				$stripe_customer = new WC_Stripe_Customer($customer_id);
103 103
 				$stripe_sources  = $stripe_customer->get_sources();
104 104
 
105
-				foreach ( $stripe_sources as $source ) {
106
-					if ( isset( $source->type ) && 'card' === $source->type ) {
107
-						if ( ! in_array( $source->id, $stored_tokens ) ) {
105
+				foreach ($stripe_sources as $source) {
106
+					if (isset($source->type) && 'card' === $source->type) {
107
+						if ( ! in_array($source->id, $stored_tokens)) {
108 108
 							$token = new WC_Payment_Token_CC();
109
-							$token->set_token( $source->id );
110
-							$token->set_gateway_id( 'stripe' );
111
-
112
-							if ( 'source' === $source->object && 'card' === $source->type ) {
113
-								$token->set_card_type( strtolower( $source->card->brand ) );
114
-								$token->set_last4( $source->card->last4 );
115
-								$token->set_expiry_month( $source->card->exp_month );
116
-								$token->set_expiry_year( $source->card->exp_year );
109
+							$token->set_token($source->id);
110
+							$token->set_gateway_id('stripe');
111
+
112
+							if ('source' === $source->object && 'card' === $source->type) {
113
+								$token->set_card_type(strtolower($source->card->brand));
114
+								$token->set_last4($source->card->last4);
115
+								$token->set_expiry_month($source->card->exp_month);
116
+								$token->set_expiry_year($source->card->exp_year);
117 117
 							}
118 118
 
119
-							$token->set_user_id( $customer_id );
119
+							$token->set_user_id($customer_id);
120 120
 							$token->save();
121
-							$tokens[ $token->get_id() ] = $token;
121
+							$tokens[$token->get_id()] = $token;
122 122
 						}
123 123
 					} else {
124
-						if ( ! in_array( $source->id, $stored_tokens ) && 'card' === $source->object ) {
124
+						if ( ! in_array($source->id, $stored_tokens) && 'card' === $source->object) {
125 125
 							$token = new WC_Payment_Token_CC();
126
-							$token->set_token( $source->id );
127
-							$token->set_gateway_id( 'stripe' );
128
-							$token->set_card_type( strtolower( $source->brand ) );
129
-							$token->set_last4( $source->last4 );
130
-							$token->set_expiry_month( $source->exp_month );
131
-							$token->set_expiry_year( $source->exp_year );
132
-							$token->set_user_id( $customer_id );
126
+							$token->set_token($source->id);
127
+							$token->set_gateway_id('stripe');
128
+							$token->set_card_type(strtolower($source->brand));
129
+							$token->set_last4($source->last4);
130
+							$token->set_expiry_month($source->exp_month);
131
+							$token->set_expiry_year($source->exp_year);
132
+							$token->set_user_id($customer_id);
133 133
 							$token->save();
134
-							$tokens[ $token->get_id() ] = $token;
134
+							$tokens[$token->get_id()] = $token;
135 135
 						}
136 136
 					}
137 137
 				}
138 138
 			}
139 139
 
140
-			if ( 'stripe_sepa' === $gateway_id ) {
141
-				$stripe_customer = new WC_Stripe_Customer( $customer_id );
140
+			if ('stripe_sepa' === $gateway_id) {
141
+				$stripe_customer = new WC_Stripe_Customer($customer_id);
142 142
 				$stripe_sources  = $stripe_customer->get_sources();
143 143
 
144
-				foreach ( $stripe_sources as $source ) {
145
-					if ( isset( $source->type ) && 'sepa_debit' === $source->type ) {
146
-						if ( ! in_array( $source->id, $stored_tokens ) ) {
144
+				foreach ($stripe_sources as $source) {
145
+					if (isset($source->type) && 'sepa_debit' === $source->type) {
146
+						if ( ! in_array($source->id, $stored_tokens)) {
147 147
 							$token = new WC_Payment_Token_SEPA();
148
-							$token->set_token( $source->id );
149
-							$token->set_gateway_id( 'stripe_sepa' );
150
-							$token->set_last4( $source->sepa_debit->last4 );
151
-							$token->set_user_id( $customer_id );
148
+							$token->set_token($source->id);
149
+							$token->set_gateway_id('stripe_sepa');
150
+							$token->set_last4($source->sepa_debit->last4);
151
+							$token->set_user_id($customer_id);
152 152
 							$token->save();
153
-							$tokens[ $token->get_id() ] = $token;
153
+							$tokens[$token->get_id()] = $token;
154 154
 						}
155 155
 					}
156 156
 				}
@@ -169,10 +169,10 @@  discard block
 block discarded – undo
169 169
 	 * @param  WC_Payment_Token $payment_token The payment token associated with this method entry
170 170
 	 * @return array                           Filtered item
171 171
 	 */
172
-	public function get_account_saved_payment_methods_list_item_sepa( $item, $payment_token ) {
173
-		if ( 'sepa' === strtolower( $payment_token->get_type() ) ) {
172
+	public function get_account_saved_payment_methods_list_item_sepa($item, $payment_token) {
173
+		if ('sepa' === strtolower($payment_token->get_type())) {
174 174
 			$item['method']['last4'] = $payment_token->get_last4();
175
-			$item['method']['brand'] = esc_html__( 'SEPA IBAN', 'woocommerce-gateway-stripe' );
175
+			$item['method']['brand'] = esc_html__('SEPA IBAN', 'woocommerce-gateway-stripe');
176 176
 		}
177 177
 
178 178
 		return $item;
@@ -184,10 +184,10 @@  discard block
 block discarded – undo
184 184
 	 * @since 3.1.0
185 185
 	 * @version 4.0.0
186 186
 	 */
187
-	public function woocommerce_payment_token_deleted( $token_id, $token ) {
188
-		if ( 'stripe' === $token->get_gateway_id() || 'stripe_sepa' === $token->get_gateway_id() ) {
189
-			$stripe_customer = new WC_Stripe_Customer( get_current_user_id() );
190
-			$stripe_customer->delete_source( $token->get_token() );
187
+	public function woocommerce_payment_token_deleted($token_id, $token) {
188
+		if ('stripe' === $token->get_gateway_id() || 'stripe_sepa' === $token->get_gateway_id()) {
189
+			$stripe_customer = new WC_Stripe_Customer(get_current_user_id());
190
+			$stripe_customer->delete_source($token->get_token());
191 191
 		}
192 192
 	}
193 193
 
@@ -197,12 +197,12 @@  discard block
 block discarded – undo
197 197
 	 * @since 3.1.0
198 198
 	 * @version 4.0.0
199 199
 	 */
200
-	public function woocommerce_payment_token_set_default( $token_id ) {
201
-		$token = WC_Payment_Tokens::get( $token_id );
200
+	public function woocommerce_payment_token_set_default($token_id) {
201
+		$token = WC_Payment_Tokens::get($token_id);
202 202
 
203
-		if ( 'stripe' === $token->get_gateway_id() || 'stripe_sepa' === $token->get_gateway_id() ) {
204
-			$stripe_customer = new WC_Stripe_Customer( get_current_user_id() );
205
-			$stripe_customer->set_default_source( $token->get_token() );
203
+		if ('stripe' === $token->get_gateway_id() || 'stripe_sepa' === $token->get_gateway_id()) {
204
+			$stripe_customer = new WC_Stripe_Customer(get_current_user_id());
205
+			$stripe_customer->set_default_source($token->get_token());
206 206
 		}
207 207
 	}
208 208
 }
Please login to merge, or discard this patch.