Completed
Pull Request — master (#1075)
by Radoslav
01:58
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
 	}
@@ -101,16 +101,16 @@  discard block
 block discarded – undo
101 101
 	 * @return stdClass|array
102 102
 	 * @throws WC_Stripe_Exception
103 103
 	 */
104
-	public static function request( $request, $api = 'charges', $method = 'POST', $with_headers = false ) {
105
-		WC_Stripe_Logger::log( "{$api} request: " . print_r( $request, true ) );
104
+	public static function request($request, $api = 'charges', $method = 'POST', $with_headers = false) {
105
+		WC_Stripe_Logger::log("{$api} request: " . print_r($request, true));
106 106
 
107 107
 		$headers         = self::get_headers();
108 108
 		$idempotency_key = '';
109 109
 
110
-		if ( 'charges' === $api && 'POST' === $method ) {
111
-			$customer        = ! empty( $request['customer'] ) ? $request['customer'] : '';
112
-			$source          = ! empty( $request['source'] ) ? $request['source'] : $customer;
113
-			$idempotency_key = apply_filters( 'wc_stripe_idempotency_key', $request['metadata']['order_id'] . '-' . $source, $request );
110
+		if ('charges' === $api && 'POST' === $method) {
111
+			$customer        = ! empty($request['customer']) ? $request['customer'] : '';
112
+			$source          = ! empty($request['source']) ? $request['source'] : $customer;
113
+			$idempotency_key = apply_filters('wc_stripe_idempotency_key', $request['metadata']['order_id'] . '-' . $source, $request);
114 114
 
115 115
 			$headers['Idempotency-Key'] = $idempotency_key;
116 116
 		}
@@ -120,14 +120,14 @@  discard block
 block discarded – undo
120 120
 			array(
121 121
 				'method'  => $method,
122 122
 				'headers' => $headers,
123
-				'body'    => apply_filters( 'woocommerce_stripe_request_body', $request, $api ),
123
+				'body'    => apply_filters('woocommerce_stripe_request_body', $request, $api),
124 124
 				'timeout' => 70,
125 125
 			)
126 126
 		);
127 127
 
128
-		if ( is_wp_error( $response ) || empty( $response['body'] ) ) {
128
+		if (is_wp_error($response) || empty($response['body'])) {
129 129
 			WC_Stripe_Logger::log(
130
-				'Error Response: ' . print_r( $response, true ) . PHP_EOL . PHP_EOL . 'Failed request: ' . print_r(
130
+				'Error Response: ' . print_r($response, true) . PHP_EOL . PHP_EOL . 'Failed request: ' . print_r(
131 131
 					array(
132 132
 						'api'             => $api,
133 133
 						'request'         => $request,
@@ -137,17 +137,17 @@  discard block
 block discarded – undo
137 137
 				)
138 138
 			);
139 139
 
140
-			throw new WC_Stripe_Exception( print_r( $response, true ), __( 'There was a problem connecting to the Stripe API endpoint.', 'woocommerce-gateway-stripe' ) );
140
+			throw new WC_Stripe_Exception(print_r($response, true), __('There was a problem connecting to the Stripe API endpoint.', 'woocommerce-gateway-stripe'));
141 141
 		}
142 142
 
143
-		if ( $with_headers ) {
143
+		if ($with_headers) {
144 144
 			return array(
145
-				'headers' => wp_remote_retrieve_headers( $response ),
146
-				'body'    => json_decode( $response['body'] ),
145
+				'headers' => wp_remote_retrieve_headers($response),
146
+				'body'    => json_decode($response['body']),
147 147
 			);
148 148
 		}
149 149
 
150
-		return json_decode( $response['body'] );
150
+		return json_decode($response['body']);
151 151
 	}
152 152
 
153 153
 	/**
@@ -157,8 +157,8 @@  discard block
 block discarded – undo
157 157
 	 * @version 4.0.0
158 158
 	 * @param string $api
159 159
 	 */
160
-	public static function retrieve( $api ) {
161
-		WC_Stripe_Logger::log( "{$api}" );
160
+	public static function retrieve($api) {
161
+		WC_Stripe_Logger::log("{$api}");
162 162
 
163 163
 		$response = wp_safe_remote_get(
164 164
 			self::ENDPOINT . $api,
@@ -169,11 +169,11 @@  discard block
 block discarded – undo
169 169
 			)
170 170
 		);
171 171
 
172
-		if ( is_wp_error( $response ) || empty( $response['body'] ) ) {
173
-			WC_Stripe_Logger::log( 'Error Response: ' . print_r( $response, true ) );
174
-			return new WP_Error( 'stripe_error', __( 'There was a problem connecting to the Stripe API endpoint.', 'woocommerce-gateway-stripe' ) );
172
+		if (is_wp_error($response) || empty($response['body'])) {
173
+			WC_Stripe_Logger::log('Error Response: ' . print_r($response, true));
174
+			return new WP_Error('stripe_error', __('There was a problem connecting to the Stripe API endpoint.', 'woocommerce-gateway-stripe'));
175 175
 		}
176 176
 
177
-		return json_decode( $response['body'] );
177
+		return json_decode($response['body']);
178 178
 	}
179 179
 }
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   +85 added lines, -85 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) {
2
+if ( ! defined('ABSPATH')) {
3 3
 	exit;
4 4
 }
5 5
 
@@ -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,37 +98,37 @@  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 119
 			// translators: %1$s First name, %2$s Second name, %3$s Username.
120
-			$description = sprintf( __( 'Name: %1$s %2$s, Username: %s', 'woocommerce-gateway-stripe' ), $billing_first_name, $billing_last_name, $user->user_login );
120
+			$description = sprintf(__('Name: %1$s %2$s, Username: %s', 'woocommerce-gateway-stripe'), $billing_first_name, $billing_last_name, $user->user_login);
121 121
 
122 122
 			$defaults = array(
123 123
 				'email'       => $user->user_email,
124 124
 				'description' => $description,
125 125
 			);
126 126
 		} else {
127
-			$billing_first_name = isset( $_POST['billing_first_name'] ) ? filter_var( wp_unslash( $_POST['billing_first_name'] ), FILTER_SANITIZE_STRING ) : ''; // phpcs:ignore WordPress.Security.NonceVerification
128
-			$billing_last_name  = isset( $_POST['billing_last_name'] ) ? filter_var( wp_unslash( $_POST['billing_last_name'] ), FILTER_SANITIZE_STRING ) : ''; // phpcs:ignore WordPress.Security.NonceVerification
127
+			$billing_first_name = isset($_POST['billing_first_name']) ? filter_var(wp_unslash($_POST['billing_first_name']), FILTER_SANITIZE_STRING) : ''; // phpcs:ignore WordPress.Security.NonceVerification
128
+			$billing_last_name  = isset($_POST['billing_last_name']) ? filter_var(wp_unslash($_POST['billing_last_name']), FILTER_SANITIZE_STRING) : ''; // phpcs:ignore WordPress.Security.NonceVerification
129 129
 
130 130
 			// translators: %1$s First name, %2$s Second name.
131
-			$description = sprintf( __( 'Name: %1$s %2$s, Guest', 'woocommerce-gateway-stripe' ), $billing_first_name, $billing_last_name );
131
+			$description = sprintf(__('Name: %1$s %2$s, Guest', 'woocommerce-gateway-stripe'), $billing_first_name, $billing_last_name);
132 132
 
133 133
 			$defaults = array(
134 134
 				'email'       => $billing_email,
@@ -138,24 +138,24 @@  discard block
 block discarded – undo
138 138
 
139 139
 		$metadata = array();
140 140
 
141
-		$defaults['metadata'] = apply_filters( 'wc_stripe_customer_metadata', $metadata, $user );
141
+		$defaults['metadata'] = apply_filters('wc_stripe_customer_metadata', $metadata, $user);
142 142
 
143
-		$args     = wp_parse_args( $args, $defaults );
144
-		$response = WC_Stripe_API::request( apply_filters( 'wc_stripe_create_customer_args', $args ), 'customers' );
143
+		$args     = wp_parse_args($args, $defaults);
144
+		$response = WC_Stripe_API::request(apply_filters('wc_stripe_create_customer_args', $args), 'customers');
145 145
 
146
-		if ( ! empty( $response->error ) ) {
147
-			throw new WC_Stripe_Exception( print_r( $response, true ), $response->error->message );
146
+		if ( ! empty($response->error)) {
147
+			throw new WC_Stripe_Exception(print_r($response, true), $response->error->message);
148 148
 		}
149 149
 
150
-		$this->set_id( $response->id );
150
+		$this->set_id($response->id);
151 151
 		$this->clear_cache();
152
-		$this->set_customer_data( $response );
152
+		$this->set_customer_data($response);
153 153
 
154
-		if ( $this->get_user_id() ) {
155
-			update_user_meta( $this->get_user_id(), '_stripe_customer_id', $response->id );
154
+		if ($this->get_user_id()) {
155
+			update_user_meta($this->get_user_id(), '_stripe_customer_id', $response->id);
156 156
 		}
157 157
 
158
-		do_action( 'woocommerce_stripe_add_customer', $args, $response );
158
+		do_action('woocommerce_stripe_add_customer', $args, $response);
159 159
 
160 160
 		return $response->id;
161 161
 	}
@@ -167,11 +167,11 @@  discard block
 block discarded – undo
167 167
 	 * @since 4.1.2
168 168
 	 * @param array $error
169 169
 	 */
170
-	public function is_no_such_customer_error( $error ) {
170
+	public function is_no_such_customer_error($error) {
171 171
 		return (
172 172
 			$error &&
173 173
 			'invalid_request_error' === $error->type &&
174
-			preg_match( '/No such customer/i', $error->message )
174
+			preg_match('/No such customer/i', $error->message)
175 175
 		);
176 176
 	}
177 177
 
@@ -180,9 +180,9 @@  discard block
 block discarded – undo
180 180
 	 * @param string $source_id
181 181
 	 * @return WP_Error|int
182 182
 	 */
183
-	public function add_source( $source_id ) {
184
-		if ( ! $this->get_id() ) {
185
-			$this->set_id( $this->create_customer() );
183
+	public function add_source($source_id) {
184
+		if ( ! $this->get_id()) {
185
+			$this->set_id($this->create_customer());
186 186
 		}
187 187
 
188 188
 		$response = WC_Stripe_API::request(
@@ -194,63 +194,63 @@  discard block
 block discarded – undo
194 194
 
195 195
 		$wc_token = false;
196 196
 
197
-		if ( ! empty( $response->error ) ) {
197
+		if ( ! empty($response->error)) {
198 198
 			// It is possible the WC user once was linked to a customer on Stripe
199 199
 			// but no longer exists. Instead of failing, lets try to create a
200 200
 			// new customer.
201
-			if ( $this->is_no_such_customer_error( $response->error ) ) {
202
-				delete_user_meta( $this->get_user_id(), '_stripe_customer_id' );
201
+			if ($this->is_no_such_customer_error($response->error)) {
202
+				delete_user_meta($this->get_user_id(), '_stripe_customer_id');
203 203
 				$this->create_customer();
204
-				return $this->add_source( $source_id );
204
+				return $this->add_source($source_id);
205 205
 			} else {
206 206
 				return $response;
207 207
 			}
208
-		} elseif ( empty( $response->id ) ) {
209
-			return new WP_Error( 'error', __( 'Unable to add payment source.', 'woocommerce-gateway-stripe' ) );
208
+		} elseif (empty($response->id)) {
209
+			return new WP_Error('error', __('Unable to add payment source.', 'woocommerce-gateway-stripe'));
210 210
 		}
211 211
 
212 212
 		// Add token to WooCommerce.
213
-		if ( $this->get_user_id() && class_exists( 'WC_Payment_Token_CC' ) ) {
214
-			if ( ! empty( $response->type ) ) {
215
-				switch ( $response->type ) {
213
+		if ($this->get_user_id() && class_exists('WC_Payment_Token_CC')) {
214
+			if ( ! empty($response->type)) {
215
+				switch ($response->type) {
216 216
 					case 'alipay':
217 217
 						break;
218 218
 					case 'sepa_debit':
219 219
 						$wc_token = new WC_Payment_Token_SEPA();
220
-						$wc_token->set_token( $response->id );
221
-						$wc_token->set_gateway_id( 'stripe_sepa' );
222
-						$wc_token->set_last4( $response->sepa_debit->last4 );
220
+						$wc_token->set_token($response->id);
221
+						$wc_token->set_gateway_id('stripe_sepa');
222
+						$wc_token->set_last4($response->sepa_debit->last4);
223 223
 						break;
224 224
 					default:
225
-						if ( 'source' === $response->object && 'card' === $response->type ) {
225
+						if ('source' === $response->object && 'card' === $response->type) {
226 226
 							$wc_token = new WC_Payment_Token_CC();
227
-							$wc_token->set_token( $response->id );
228
-							$wc_token->set_gateway_id( 'stripe' );
229
-							$wc_token->set_card_type( strtolower( $response->card->brand ) );
230
-							$wc_token->set_last4( $response->card->last4 );
231
-							$wc_token->set_expiry_month( $response->card->exp_month );
232
-							$wc_token->set_expiry_year( $response->card->exp_year );
227
+							$wc_token->set_token($response->id);
228
+							$wc_token->set_gateway_id('stripe');
229
+							$wc_token->set_card_type(strtolower($response->card->brand));
230
+							$wc_token->set_last4($response->card->last4);
231
+							$wc_token->set_expiry_month($response->card->exp_month);
232
+							$wc_token->set_expiry_year($response->card->exp_year);
233 233
 						}
234 234
 						break;
235 235
 				}
236 236
 			} else {
237 237
 				// Legacy.
238 238
 				$wc_token = new WC_Payment_Token_CC();
239
-				$wc_token->set_token( $response->id );
240
-				$wc_token->set_gateway_id( 'stripe' );
241
-				$wc_token->set_card_type( strtolower( $response->brand ) );
242
-				$wc_token->set_last4( $response->last4 );
243
-				$wc_token->set_expiry_month( $response->exp_month );
244
-				$wc_token->set_expiry_year( $response->exp_year );
239
+				$wc_token->set_token($response->id);
240
+				$wc_token->set_gateway_id('stripe');
241
+				$wc_token->set_card_type(strtolower($response->brand));
242
+				$wc_token->set_last4($response->last4);
243
+				$wc_token->set_expiry_month($response->exp_month);
244
+				$wc_token->set_expiry_year($response->exp_year);
245 245
 			}
246 246
 
247
-			$wc_token->set_user_id( $this->get_user_id() );
247
+			$wc_token->set_user_id($this->get_user_id());
248 248
 			$wc_token->save();
249 249
 		}
250 250
 
251 251
 		$this->clear_cache();
252 252
 
253
-		do_action( 'woocommerce_stripe_add_source', $this->get_id(), $wc_token, $response, $source_id );
253
+		do_action('woocommerce_stripe_add_source', $this->get_id(), $wc_token, $response, $source_id);
254 254
 
255 255
 		return $response->id;
256 256
 	}
@@ -262,11 +262,11 @@  discard block
 block discarded – undo
262 262
 	 * @return array
263 263
 	 */
264 264
 	public function get_sources() {
265
-		if ( ! $this->get_id() ) {
265
+		if ( ! $this->get_id()) {
266 266
 			return array();
267 267
 		}
268 268
 
269
-		$sources = get_transient( 'stripe_sources_' . $this->get_id() );
269
+		$sources = get_transient('stripe_sources_' . $this->get_id());
270 270
 
271 271
 		$response = WC_Stripe_API::request(
272 272
 			array(
@@ -276,32 +276,32 @@  discard block
 block discarded – undo
276 276
 			'GET'
277 277
 		);
278 278
 
279
-		if ( ! empty( $response->error ) ) {
279
+		if ( ! empty($response->error)) {
280 280
 			return array();
281 281
 		}
282 282
 
283
-		if ( is_array( $response->data ) ) {
283
+		if (is_array($response->data)) {
284 284
 			$sources = $response->data;
285 285
 		}
286 286
 
287
-		return empty( $sources ) ? array() : $sources;
287
+		return empty($sources) ? array() : $sources;
288 288
 	}
289 289
 
290 290
 	/**
291 291
 	 * Delete a source from stripe.
292 292
 	 * @param string $source_id
293 293
 	 */
294
-	public function delete_source( $source_id ) {
295
-		if ( ! $this->get_id() ) {
294
+	public function delete_source($source_id) {
295
+		if ( ! $this->get_id()) {
296 296
 			return false;
297 297
 		}
298 298
 
299
-		$response = WC_Stripe_API::request( array(), 'customers/' . $this->get_id() . '/sources/' . sanitize_text_field( $source_id ), 'DELETE' );
299
+		$response = WC_Stripe_API::request(array(), 'customers/' . $this->get_id() . '/sources/' . sanitize_text_field($source_id), 'DELETE');
300 300
 
301 301
 		$this->clear_cache();
302 302
 
303
-		if ( empty( $response->error ) ) {
304
-			do_action( 'wc_stripe_delete_source', $this->get_id(), $response );
303
+		if (empty($response->error)) {
304
+			do_action('wc_stripe_delete_source', $this->get_id(), $response);
305 305
 
306 306
 			return true;
307 307
 		}
@@ -313,10 +313,10 @@  discard block
 block discarded – undo
313 313
 	 * Set default source in Stripe
314 314
 	 * @param string $source_id
315 315
 	 */
316
-	public function set_default_source( $source_id ) {
316
+	public function set_default_source($source_id) {
317 317
 		$response = WC_Stripe_API::request(
318 318
 			array(
319
-				'default_source' => sanitize_text_field( $source_id ),
319
+				'default_source' => sanitize_text_field($source_id),
320 320
 			),
321 321
 			'customers/' . $this->get_id(),
322 322
 			'POST'
@@ -324,8 +324,8 @@  discard block
 block discarded – undo
324 324
 
325 325
 		$this->clear_cache();
326 326
 
327
-		if ( empty( $response->error ) ) {
328
-			do_action( 'wc_stripe_set_default_source', $this->get_id(), $response );
327
+		if (empty($response->error)) {
328
+			do_action('wc_stripe_set_default_source', $this->get_id(), $response);
329 329
 
330 330
 			return true;
331 331
 		}
@@ -337,8 +337,8 @@  discard block
 block discarded – undo
337 337
 	 * Deletes caches for this users cards.
338 338
 	 */
339 339
 	public function clear_cache() {
340
-		delete_transient( 'stripe_sources_' . $this->get_id() );
341
-		delete_transient( 'stripe_customer_' . $this->get_id() );
340
+		delete_transient('stripe_sources_' . $this->get_id());
341
+		delete_transient('stripe_customer_' . $this->get_id());
342 342
 		$this->customer_data = array();
343 343
 	}
344 344
 }
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   +301 added lines, -301 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
 		}
@@ -423,20 +423,20 @@  discard block
 block discarded – undo
423 423
 	 * @return bool
424 424
 	 */
425 425
 	public function allowed_items_in_cart() {
426
-		foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {
427
-			$_product = apply_filters( 'woocommerce_cart_item_product', $cart_item['data'], $cart_item, $cart_item_key );
426
+		foreach (WC()->cart->get_cart() as $cart_item_key => $cart_item) {
427
+			$_product = apply_filters('woocommerce_cart_item_product', $cart_item['data'], $cart_item, $cart_item_key);
428 428
 
429
-			if ( ! in_array( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $_product->product_type : $_product->get_type() ), $this->supported_product_types() ) ) {
429
+			if ( ! in_array((WC_Stripe_Helper::is_wc_lt('3.0') ? $_product->product_type : $_product->get_type()), $this->supported_product_types())) {
430 430
 				return false;
431 431
 			}
432 432
 
433 433
 			// Trial subscriptions with shipping are not supported
434
-			if ( class_exists( 'WC_Subscriptions_Order' ) && WC_Subscriptions_Cart::cart_contains_subscription() && $_product->needs_shipping() && WC_Subscriptions_Product::get_trial_length( $_product ) > 0 ) {
434
+			if (class_exists('WC_Subscriptions_Order') && WC_Subscriptions_Cart::cart_contains_subscription() && $_product->needs_shipping() && WC_Subscriptions_Product::get_trial_length($_product) > 0) {
435 435
 				return false;
436 436
 			}
437 437
 
438 438
 			// Pre Orders compatbility where we don't support charge upon release.
439
-			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() ) ) {
439
+			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())) {
440 440
 				return false;
441 441
 			}
442 442
 		}
@@ -452,83 +452,83 @@  discard block
 block discarded – undo
452 452
 	 */
453 453
 	public function scripts() {
454 454
 		// If keys are not set bail.
455
-		if ( ! $this->are_keys_set() ) {
456
-			WC_Stripe_Logger::log( 'Keys are not set correctly.' );
455
+		if ( ! $this->are_keys_set()) {
456
+			WC_Stripe_Logger::log('Keys are not set correctly.');
457 457
 			return;
458 458
 		}
459 459
 
460 460
 		// If no SSL bail.
461
-		if ( ! $this->testmode && ! is_ssl() ) {
462
-			WC_Stripe_Logger::log( 'Stripe Payment Request live mode requires SSL.' );
461
+		if ( ! $this->testmode && ! is_ssl()) {
462
+			WC_Stripe_Logger::log('Stripe Payment Request live mode requires SSL.');
463 463
 			return;
464 464
 		}
465 465
 
466
-		if ( ! is_product() && ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) ) {
466
+		if ( ! is_product() && ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order'])) {
467 467
 			return;
468 468
 		}
469 469
 
470
-		if ( is_product() ) {
470
+		if (is_product()) {
471 471
 			global $post;
472 472
 
473
-			$product = wc_get_product( $post->ID );
473
+			$product = wc_get_product($post->ID);
474 474
 
475
-			if ( ! is_object( $product ) || ! in_array( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $product->product_type : $product->get_type() ), $this->supported_product_types() ) ) {
475
+			if ( ! is_object($product) || ! in_array((WC_Stripe_Helper::is_wc_lt('3.0') ? $product->product_type : $product->get_type()), $this->supported_product_types())) {
476 476
 				return;
477 477
 			}
478 478
 
479
-			if ( apply_filters( 'wc_stripe_hide_payment_request_on_product_page', false, $post ) ) {
479
+			if (apply_filters('wc_stripe_hide_payment_request_on_product_page', false, $post)) {
480 480
 				return;
481 481
 			}
482 482
 		}
483 483
 
484
-		$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
484
+		$suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';
485 485
 
486 486
 		$stripe_params = array(
487
-			'ajax_url'        => WC_AJAX::get_endpoint( '%%endpoint%%' ),
487
+			'ajax_url'        => WC_AJAX::get_endpoint('%%endpoint%%'),
488 488
 			'stripe'          => array(
489 489
 				'key'                => $this->publishable_key,
490
-				'allow_prepaid_card' => apply_filters( 'wc_stripe_allow_prepaid_card', true ) ? 'yes' : 'no',
490
+				'allow_prepaid_card' => apply_filters('wc_stripe_allow_prepaid_card', true) ? 'yes' : 'no',
491 491
 			),
492 492
 			'nonce'           => array(
493
-				'payment'                   => wp_create_nonce( 'wc-stripe-payment-request' ),
494
-				'shipping'                  => wp_create_nonce( 'wc-stripe-payment-request-shipping' ),
495
-				'update_shipping'           => wp_create_nonce( 'wc-stripe-update-shipping-method' ),
496
-				'checkout'                  => wp_create_nonce( 'woocommerce-process_checkout' ),
497
-				'add_to_cart'               => wp_create_nonce( 'wc-stripe-add-to-cart' ),
498
-				'get_selected_product_data' => wp_create_nonce( 'wc-stripe-get-selected-product-data' ),
499
-				'log_errors'                => wp_create_nonce( 'wc-stripe-log-errors' ),
500
-				'clear_cart'                => wp_create_nonce( 'wc-stripe-clear-cart' ),
493
+				'payment'                   => wp_create_nonce('wc-stripe-payment-request'),
494
+				'shipping'                  => wp_create_nonce('wc-stripe-payment-request-shipping'),
495
+				'update_shipping'           => wp_create_nonce('wc-stripe-update-shipping-method'),
496
+				'checkout'                  => wp_create_nonce('woocommerce-process_checkout'),
497
+				'add_to_cart'               => wp_create_nonce('wc-stripe-add-to-cart'),
498
+				'get_selected_product_data' => wp_create_nonce('wc-stripe-get-selected-product-data'),
499
+				'log_errors'                => wp_create_nonce('wc-stripe-log-errors'),
500
+				'clear_cart'                => wp_create_nonce('wc-stripe-clear-cart'),
501 501
 			),
502 502
 			'i18n'            => array(
503
-				'no_prepaid_card'  => __( 'Sorry, we\'re not accepting prepaid cards at this time.', 'woocommerce-gateway-stripe' ),
503
+				'no_prepaid_card'  => __('Sorry, we\'re not accepting prepaid cards at this time.', 'woocommerce-gateway-stripe'),
504 504
 				/* translators: Do not translate the [option] placeholder */
505
-				'unknown_shipping' => __( 'Unknown shipping option "[option]".', 'woocommerce-gateway-stripe' ),
505
+				'unknown_shipping' => __('Unknown shipping option "[option]".', 'woocommerce-gateway-stripe'),
506 506
 			),
507 507
 			'checkout'        => array(
508 508
 				'url'            => wc_get_checkout_url(),
509
-				'currency_code'  => strtolower( get_woocommerce_currency() ),
510
-				'country_code'   => substr( get_option( 'woocommerce_default_country' ), 0, 2 ),
509
+				'currency_code'  => strtolower(get_woocommerce_currency()),
510
+				'country_code'   => substr(get_option('woocommerce_default_country'), 0, 2),
511 511
 				'needs_shipping' => WC()->cart->needs_shipping() ? 'yes' : 'no',
512 512
 			),
513 513
 			'button'          => array(
514 514
 				'type'   => $this->get_button_type(),
515 515
 				'theme'  => $this->get_button_theme(),
516 516
 				'height' => $this->get_button_height(),
517
-				'locale' => apply_filters( 'wc_stripe_payment_request_button_locale', substr( get_locale(), 0, 2 ) ), // Default format is en_US.
517
+				'locale' => apply_filters('wc_stripe_payment_request_button_locale', substr(get_locale(), 0, 2)), // Default format is en_US.
518 518
 			),
519 519
 			'is_product_page' => is_product(),
520 520
 			'product'         => $this->get_product_data(),
521 521
 		);
522 522
 
523
-		wp_register_script( 'stripe', 'https://js.stripe.com/v3/', '', '3.0', true );
524
-		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 );
523
+		wp_register_script('stripe', 'https://js.stripe.com/v3/', '', '3.0', true);
524
+		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);
525 525
 
526
-		wp_localize_script( 'wc_stripe_payment_request', 'wc_stripe_payment_request_params', apply_filters( 'wc_stripe_payment_request_params', $stripe_params ) );
526
+		wp_localize_script('wc_stripe_payment_request', 'wc_stripe_payment_request_params', apply_filters('wc_stripe_payment_request_params', $stripe_params));
527 527
 
528
-		wp_enqueue_script( 'wc_stripe_payment_request' );
528
+		wp_enqueue_script('wc_stripe_payment_request');
529 529
 
530 530
 		$gateways = WC()->payment_gateways->get_available_payment_gateways();
531
-		if ( isset( $gateways['stripe'] ) ) {
531
+		if (isset($gateways['stripe'])) {
532 532
 			$gateways['stripe']->payment_scripts();
533 533
 		}
534 534
 	}
@@ -544,42 +544,42 @@  discard block
 block discarded – undo
544 544
 
545 545
 		$gateways = WC()->payment_gateways->get_available_payment_gateways();
546 546
 
547
-		if ( ! isset( $gateways['stripe'] ) ) {
547
+		if ( ! isset($gateways['stripe'])) {
548 548
 			return;
549 549
 		}
550 550
 
551
-		if ( ! is_cart() && ! is_checkout() && ! is_product() && ! isset( $_GET['pay_for_order'] ) ) {
551
+		if ( ! is_cart() && ! is_checkout() && ! is_product() && ! isset($_GET['pay_for_order'])) {
552 552
 			return;
553 553
 		}
554 554
 
555
-		if ( is_product() && apply_filters( 'wc_stripe_hide_payment_request_on_product_page', false, $post ) ) {
555
+		if (is_product() && apply_filters('wc_stripe_hide_payment_request_on_product_page', false, $post)) {
556 556
 			return;
557 557
 		}
558 558
 
559
-		if ( is_checkout() && ! apply_filters( 'wc_stripe_show_payment_request_on_checkout', false, $post ) ) {
559
+		if (is_checkout() && ! apply_filters('wc_stripe_show_payment_request_on_checkout', false, $post)) {
560 560
 			return;
561 561
 		}
562 562
 
563
-		if ( is_product() ) {
564
-			$product = wc_get_product( $post->ID );
563
+		if (is_product()) {
564
+			$product = wc_get_product($post->ID);
565 565
 
566
-			if ( ! is_object( $product ) || ! in_array( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $product->product_type : $product->get_type() ), $this->supported_product_types() ) ) {
566
+			if ( ! is_object($product) || ! in_array((WC_Stripe_Helper::is_wc_lt('3.0') ? $product->product_type : $product->get_type()), $this->supported_product_types())) {
567 567
 				return;
568 568
 			}
569 569
 
570 570
 			// Trial subscriptions with shipping are not supported
571
-			if ( class_exists( 'WC_Subscriptions_Order' ) && $product->needs_shipping() && WC_Subscriptions_Product::get_trial_length( $product ) > 0 ) {
571
+			if (class_exists('WC_Subscriptions_Order') && $product->needs_shipping() && WC_Subscriptions_Product::get_trial_length($product) > 0) {
572 572
 				return;
573 573
 			}
574 574
 
575 575
 			// Pre Orders charge upon release not supported.
576
-			if ( class_exists( 'WC_Pre_Orders_Order' ) && WC_Pre_Orders_Product::product_is_charged_upon_release( $product ) ) {
577
-				WC_Stripe_Logger::log( 'Pre Order charge upon release is not supported. ( Payment Request button disabled )' );
576
+			if (class_exists('WC_Pre_Orders_Order') && WC_Pre_Orders_Product::product_is_charged_upon_release($product)) {
577
+				WC_Stripe_Logger::log('Pre Order charge upon release is not supported. ( Payment Request button disabled )');
578 578
 				return;
579 579
 			}
580 580
 		} else {
581
-			if ( ! $this->allowed_items_in_cart() ) {
582
-				WC_Stripe_Logger::log( 'Items in the cart has unsupported product type ( Payment Request button disabled )' );
581
+			if ( ! $this->allowed_items_in_cart()) {
582
+				WC_Stripe_Logger::log('Items in the cart has unsupported product type ( Payment Request button disabled )');
583 583
 				return;
584 584
 			}
585 585
 		}
@@ -603,47 +603,47 @@  discard block
 block discarded – undo
603 603
 
604 604
 		$gateways = WC()->payment_gateways->get_available_payment_gateways();
605 605
 
606
-		if ( ! isset( $gateways['stripe'] ) ) {
606
+		if ( ! isset($gateways['stripe'])) {
607 607
 			return;
608 608
 		}
609 609
 
610
-		if ( ! is_cart() && ! is_checkout() && ! is_product() && ! isset( $_GET['pay_for_order'] ) ) {
610
+		if ( ! is_cart() && ! is_checkout() && ! is_product() && ! isset($_GET['pay_for_order'])) {
611 611
 			return;
612 612
 		}
613 613
 
614
-		if ( is_product() && apply_filters( 'wc_stripe_hide_payment_request_on_product_page', false, $post ) ) {
614
+		if (is_product() && apply_filters('wc_stripe_hide_payment_request_on_product_page', false, $post)) {
615 615
 			return;
616 616
 		}
617 617
 
618
-		if ( is_checkout() && ! apply_filters( 'wc_stripe_show_payment_request_on_checkout', false, $post ) ) {
618
+		if (is_checkout() && ! apply_filters('wc_stripe_show_payment_request_on_checkout', false, $post)) {
619 619
 			return;
620 620
 		}
621 621
 
622
-		if ( is_product() ) {
623
-			$product = wc_get_product( $post->ID );
622
+		if (is_product()) {
623
+			$product = wc_get_product($post->ID);
624 624
 
625
-			if ( ! is_object( $product ) || ! in_array( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $product->product_type : $product->get_type() ), $this->supported_product_types() ) ) {
625
+			if ( ! is_object($product) || ! in_array((WC_Stripe_Helper::is_wc_lt('3.0') ? $product->product_type : $product->get_type()), $this->supported_product_types())) {
626 626
 				return;
627 627
 			}
628 628
 
629 629
 			// Trial subscriptions with shipping are not supported
630
-			if ( class_exists( 'WC_Subscriptions_Order' ) && $product->needs_shipping() && WC_Subscriptions_Product::get_trial_length( $product ) > 0 ) {
630
+			if (class_exists('WC_Subscriptions_Order') && $product->needs_shipping() && WC_Subscriptions_Product::get_trial_length($product) > 0) {
631 631
 				return;
632 632
 			}
633 633
 
634 634
 			// Pre Orders charge upon release not supported.
635
-			if ( class_exists( 'WC_Pre_Orders_Order' ) && WC_Pre_Orders_Product::product_is_charged_upon_release( $product ) ) {
636
-				WC_Stripe_Logger::log( 'Pre Order charge upon release is not supported. ( Payment Request button disabled )' );
635
+			if (class_exists('WC_Pre_Orders_Order') && WC_Pre_Orders_Product::product_is_charged_upon_release($product)) {
636
+				WC_Stripe_Logger::log('Pre Order charge upon release is not supported. ( Payment Request button disabled )');
637 637
 				return;
638 638
 			}
639 639
 		} else {
640
-			if ( ! $this->allowed_items_in_cart() ) {
641
-				WC_Stripe_Logger::log( 'Items in the cart has unsupported product type ( Payment Request button disabled )' );
640
+			if ( ! $this->allowed_items_in_cart()) {
641
+				WC_Stripe_Logger::log('Items in the cart has unsupported product type ( Payment Request button disabled )');
642 642
 				return;
643 643
 			}
644 644
 		}
645 645
 		?>
646
-		<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>
646
+		<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>
647 647
 		<?php
648 648
 	}
649 649
 
@@ -654,11 +654,11 @@  discard block
 block discarded – undo
654 654
 	 * @version 4.0.0
655 655
 	 */
656 656
 	public function ajax_log_errors() {
657
-		check_ajax_referer( 'wc-stripe-log-errors', 'security' );
657
+		check_ajax_referer('wc-stripe-log-errors', 'security');
658 658
 
659
-		$errors = wc_clean( stripslashes( $_POST['errors'] ) );
659
+		$errors = wc_clean(stripslashes($_POST['errors']));
660 660
 
661
-		WC_Stripe_Logger::log( $errors );
661
+		WC_Stripe_Logger::log($errors);
662 662
 
663 663
 		exit;
664 664
 	}
@@ -670,7 +670,7 @@  discard block
 block discarded – undo
670 670
 	 * @version 4.0.0
671 671
 	 */
672 672
 	public function ajax_clear_cart() {
673
-		check_ajax_referer( 'wc-stripe-clear-cart', 'security' );
673
+		check_ajax_referer('wc-stripe-clear-cart', 'security');
674 674
 
675 675
 		WC()->cart->empty_cart();
676 676
 		exit;
@@ -680,10 +680,10 @@  discard block
 block discarded – undo
680 680
 	 * Get cart details.
681 681
 	 */
682 682
 	public function ajax_get_cart_details() {
683
-		check_ajax_referer( 'wc-stripe-payment-request', 'security' );
683
+		check_ajax_referer('wc-stripe-payment-request', 'security');
684 684
 
685
-		if ( ! defined( 'WOOCOMMERCE_CART' ) ) {
686
-			define( 'WOOCOMMERCE_CART', true );
685
+		if ( ! defined('WOOCOMMERCE_CART')) {
686
+			define('WOOCOMMERCE_CART', true);
687 687
 		}
688 688
 
689 689
 		WC()->cart->calculate_totals();
@@ -694,14 +694,14 @@  discard block
 block discarded – undo
694 694
 		$data = array(
695 695
 			'shipping_required' => WC()->cart->needs_shipping(),
696 696
 			'order_data'        => array(
697
-				'currency'     => strtolower( $currency ),
698
-				'country_code' => substr( get_option( 'woocommerce_default_country' ), 0, 2 ),
697
+				'currency'     => strtolower($currency),
698
+				'country_code' => substr(get_option('woocommerce_default_country'), 0, 2),
699 699
 			),
700 700
 		);
701 701
 
702 702
 		$data['order_data'] += $this->build_display_items();
703 703
 
704
-		wp_send_json( $data );
704
+		wp_send_json($data);
705 705
 	}
706 706
 
707 707
 	/**
@@ -712,7 +712,7 @@  discard block
 block discarded – undo
712 712
 	 * @see WC_Shipping::get_packages().
713 713
 	 */
714 714
 	public function ajax_get_shipping_options() {
715
-		check_ajax_referer( 'wc-stripe-payment-request-shipping', 'security' );
715
+		check_ajax_referer('wc-stripe-payment-request-shipping', 'security');
716 716
 
717 717
 		try {
718 718
 			// Set the shipping package.
@@ -728,34 +728,34 @@  discard block
 block discarded – undo
728 728
 				)
729 729
 			);
730 730
 
731
-			$this->calculate_shipping( apply_filters( 'wc_stripe_payment_request_shipping_posted_values', $posted ) );
731
+			$this->calculate_shipping(apply_filters('wc_stripe_payment_request_shipping_posted_values', $posted));
732 732
 
733 733
 			// Set the shipping options.
734 734
 			$data     = array();
735 735
 			$packages = WC()->shipping->get_packages();
736 736
 
737
-			if ( ! empty( $packages ) && WC()->customer->has_calculated_shipping() ) {
738
-				foreach ( $packages as $package_key => $package ) {
739
-					if ( empty( $package['rates'] ) ) {
740
-						throw new Exception( __( 'Unable to find shipping method for address.', 'woocommerce-gateway-stripe' ) );
737
+			if ( ! empty($packages) && WC()->customer->has_calculated_shipping()) {
738
+				foreach ($packages as $package_key => $package) {
739
+					if (empty($package['rates'])) {
740
+						throw new Exception(__('Unable to find shipping method for address.', 'woocommerce-gateway-stripe'));
741 741
 					}
742 742
 
743
-					foreach ( $package['rates'] as $key => $rate ) {
743
+					foreach ($package['rates'] as $key => $rate) {
744 744
 						$data['shipping_options'][] = array(
745 745
 							'id'     => $rate->id,
746 746
 							'label'  => $rate->label,
747 747
 							'detail' => '',
748
-							'amount' => WC_Stripe_Helper::get_stripe_amount( $rate->cost ),
748
+							'amount' => WC_Stripe_Helper::get_stripe_amount($rate->cost),
749 749
 						);
750 750
 					}
751 751
 				}
752 752
 			} else {
753
-				throw new Exception( __( 'Unable to find shipping method for address.', 'woocommerce-gateway-stripe' ) );
753
+				throw new Exception(__('Unable to find shipping method for address.', 'woocommerce-gateway-stripe'));
754 754
 			}
755 755
 
756
-			if ( isset( $data[0] ) ) {
756
+			if (isset($data[0])) {
757 757
 				// Auto select the first shipping method.
758
-				WC()->session->set( 'chosen_shipping_methods', array( $data[0]['id'] ) );
758
+				WC()->session->set('chosen_shipping_methods', array($data[0]['id']));
759 759
 			}
760 760
 
761 761
 			WC()->cart->calculate_totals();
@@ -763,12 +763,12 @@  discard block
 block discarded – undo
763 763
 			$data          += $this->build_display_items();
764 764
 			$data['result'] = 'success';
765 765
 
766
-			wp_send_json( $data );
767
-		} catch ( Exception $e ) {
766
+			wp_send_json($data);
767
+		} catch (Exception $e) {
768 768
 			$data          += $this->build_display_items();
769 769
 			$data['result'] = 'invalid_shipping_address';
770 770
 
771
-			wp_send_json( $data );
771
+			wp_send_json($data);
772 772
 		}
773 773
 	}
774 774
 
@@ -776,22 +776,22 @@  discard block
 block discarded – undo
776 776
 	 * Update shipping method.
777 777
 	 */
778 778
 	public function ajax_update_shipping_method() {
779
-		check_ajax_referer( 'wc-stripe-update-shipping-method', 'security' );
779
+		check_ajax_referer('wc-stripe-update-shipping-method', 'security');
780 780
 
781
-		if ( ! defined( 'WOOCOMMERCE_CART' ) ) {
782
-			define( 'WOOCOMMERCE_CART', true );
781
+		if ( ! defined('WOOCOMMERCE_CART')) {
782
+			define('WOOCOMMERCE_CART', true);
783 783
 		}
784 784
 
785
-		$chosen_shipping_methods = WC()->session->get( 'chosen_shipping_methods' );
786
-		$shipping_method         = filter_input( INPUT_POST, 'shipping_method', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY );
785
+		$chosen_shipping_methods = WC()->session->get('chosen_shipping_methods');
786
+		$shipping_method         = filter_input(INPUT_POST, 'shipping_method', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY);
787 787
 
788
-		if ( is_array( $shipping_method ) ) {
789
-			foreach ( $shipping_method as $i => $value ) {
790
-				$chosen_shipping_methods[ $i ] = wc_clean( $value );
788
+		if (is_array($shipping_method)) {
789
+			foreach ($shipping_method as $i => $value) {
790
+				$chosen_shipping_methods[$i] = wc_clean($value);
791 791
 			}
792 792
 		}
793 793
 
794
-		WC()->session->set( 'chosen_shipping_methods', $chosen_shipping_methods );
794
+		WC()->session->set('chosen_shipping_methods', $chosen_shipping_methods);
795 795
 
796 796
 		WC()->cart->calculate_totals();
797 797
 
@@ -799,7 +799,7 @@  discard block
 block discarded – undo
799 799
 		$data          += $this->build_display_items();
800 800
 		$data['result'] = 'success';
801 801
 
802
-		wp_send_json( $data );
802
+		wp_send_json($data);
803 803
 	}
804 804
 
805 805
 	/**
@@ -810,46 +810,46 @@  discard block
 block discarded – undo
810 810
 	 * @return array $data
811 811
 	 */
812 812
 	public function ajax_get_selected_product_data() {
813
-		check_ajax_referer( 'wc-stripe-get-selected-product-data', 'security' );
813
+		check_ajax_referer('wc-stripe-get-selected-product-data', 'security');
814 814
 
815 815
 		try {
816
-			$product_id   = absint( $_POST['product_id'] );
817
-			$qty          = ! isset( $_POST['qty'] ) ? 1 : apply_filters( 'woocommerce_add_to_cart_quantity', absint( $_POST['qty'] ), $product_id );
818
-			$product      = wc_get_product( $product_id );
816
+			$product_id   = absint($_POST['product_id']);
817
+			$qty          = ! isset($_POST['qty']) ? 1 : apply_filters('woocommerce_add_to_cart_quantity', absint($_POST['qty']), $product_id);
818
+			$product      = wc_get_product($product_id);
819 819
 			$variation_id = null;
820 820
 
821
-			if ( ! is_a( $product, 'WC_Product' ) ) {
822
-				throw new Exception( sprintf( __( 'Product with the ID (%d) cannot be found.', 'woocommerce-gateway-stripe' ), $product_id ) );
821
+			if ( ! is_a($product, 'WC_Product')) {
822
+				throw new Exception(sprintf(__('Product with the ID (%d) cannot be found.', 'woocommerce-gateway-stripe'), $product_id));
823 823
 			}
824 824
 
825
-			if ( 'variable' === ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $product->product_type : $product->get_type() ) && isset( $_POST['attributes'] ) ) {
826
-				$attributes = array_map( 'wc_clean', $_POST['attributes'] );
825
+			if ('variable' === (WC_Stripe_Helper::is_wc_lt('3.0') ? $product->product_type : $product->get_type()) && isset($_POST['attributes'])) {
826
+				$attributes = array_map('wc_clean', $_POST['attributes']);
827 827
 
828
-				if ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ) {
829
-					$variation_id = $product->get_matching_variation( $attributes );
828
+				if (WC_Stripe_Helper::is_wc_lt('3.0')) {
829
+					$variation_id = $product->get_matching_variation($attributes);
830 830
 				} else {
831
-					$data_store   = WC_Data_Store::load( 'product' );
832
-					$variation_id = $data_store->find_matching_product_variation( $product, $attributes );
831
+					$data_store   = WC_Data_Store::load('product');
832
+					$variation_id = $data_store->find_matching_product_variation($product, $attributes);
833 833
 				}
834 834
 
835
-				if ( ! empty( $variation_id ) ) {
836
-					$product = wc_get_product( $variation_id );
835
+				if ( ! empty($variation_id)) {
836
+					$product = wc_get_product($variation_id);
837 837
 				}
838
-			} elseif ( 'simple' === ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $product->product_type : $product->get_type() ) ) {
839
-				$product = wc_get_product( $product_id );
838
+			} elseif ('simple' === (WC_Stripe_Helper::is_wc_lt('3.0') ? $product->product_type : $product->get_type())) {
839
+				$product = wc_get_product($product_id);
840 840
 			}
841 841
 
842 842
 			// Force quantity to 1 if sold individually and check for existing item in cart.
843
-			if ( $product->is_sold_individually() ) {
844
-				$qty = apply_filters( 'wc_stripe_payment_request_add_to_cart_sold_individually_quantity', 1, $qty, $product_id, $variation_id );
843
+			if ($product->is_sold_individually()) {
844
+				$qty = apply_filters('wc_stripe_payment_request_add_to_cart_sold_individually_quantity', 1, $qty, $product_id, $variation_id);
845 845
 			}
846 846
 
847
-			if ( ! $product->has_enough_stock( $qty ) ) {
847
+			if ( ! $product->has_enough_stock($qty)) {
848 848
 				/* translators: 1: product name 2: quantity in stock */
849
-				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 ) ) );
849
+				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)));
850 850
 			}
851 851
 
852
-			$total = $qty * ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $product->price : $product->get_price() );
852
+			$total = $qty * (WC_Stripe_Helper::is_wc_lt('3.0') ? $product->price : $product->get_price());
853 853
 
854 854
 			$quantity_label = 1 < $qty ? ' (x' . $qty . ')' : '';
855 855
 
@@ -857,28 +857,28 @@  discard block
 block discarded – undo
857 857
 			$items = array();
858 858
 
859 859
 			$items[] = array(
860
-				'label'  => ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $product->name : $product->get_name() ) . $quantity_label,
861
-				'amount' => WC_Stripe_Helper::get_stripe_amount( $total ),
860
+				'label'  => (WC_Stripe_Helper::is_wc_lt('3.0') ? $product->name : $product->get_name()) . $quantity_label,
861
+				'amount' => WC_Stripe_Helper::get_stripe_amount($total),
862 862
 			);
863 863
 
864
-			if ( wc_tax_enabled() ) {
864
+			if (wc_tax_enabled()) {
865 865
 				$items[] = array(
866
-					'label'   => __( 'Tax', 'woocommerce-gateway-stripe' ),
866
+					'label'   => __('Tax', 'woocommerce-gateway-stripe'),
867 867
 					'amount'  => 0,
868 868
 					'pending' => true,
869 869
 				);
870 870
 			}
871 871
 
872
-			if ( wc_shipping_enabled() && $product->needs_shipping() ) {
872
+			if (wc_shipping_enabled() && $product->needs_shipping()) {
873 873
 				$items[] = array(
874
-					'label'   => __( 'Shipping', 'woocommerce-gateway-stripe' ),
874
+					'label'   => __('Shipping', 'woocommerce-gateway-stripe'),
875 875
 					'amount'  => 0,
876 876
 					'pending' => true,
877 877
 				);
878 878
 
879 879
 				$data['shippingOptions'] = array(
880 880
 					'id'     => 'pending',
881
-					'label'  => __( 'Pending', 'woocommerce-gateway-stripe' ),
881
+					'label'  => __('Pending', 'woocommerce-gateway-stripe'),
882 882
 					'detail' => '',
883 883
 					'amount' => 0,
884 884
 				);
@@ -887,17 +887,17 @@  discard block
 block discarded – undo
887 887
 			$data['displayItems'] = $items;
888 888
 			$data['total']        = array(
889 889
 				'label'   => $this->total_label,
890
-				'amount'  => WC_Stripe_Helper::get_stripe_amount( $total ),
890
+				'amount'  => WC_Stripe_Helper::get_stripe_amount($total),
891 891
 				'pending' => true,
892 892
 			);
893 893
 
894
-			$data['requestShipping'] = ( wc_shipping_enabled() && $product->needs_shipping() );
895
-			$data['currency']        = strtolower( get_woocommerce_currency() );
896
-			$data['country_code']    = substr( get_option( 'woocommerce_default_country' ), 0, 2 );
894
+			$data['requestShipping'] = (wc_shipping_enabled() && $product->needs_shipping());
895
+			$data['currency']        = strtolower(get_woocommerce_currency());
896
+			$data['country_code']    = substr(get_option('woocommerce_default_country'), 0, 2);
897 897
 
898
-			wp_send_json( $data );
899
-		} catch ( Exception $e ) {
900
-			wp_send_json( array( 'error' => wp_strip_all_tags( $e->getMessage() ) ) );
898
+			wp_send_json($data);
899
+		} catch (Exception $e) {
900
+			wp_send_json(array('error' => wp_strip_all_tags($e->getMessage())));
901 901
 		}
902 902
 	}
903 903
 
@@ -909,36 +909,36 @@  discard block
 block discarded – undo
909 909
 	 * @return array $data
910 910
 	 */
911 911
 	public function ajax_add_to_cart() {
912
-		check_ajax_referer( 'wc-stripe-add-to-cart', 'security' );
912
+		check_ajax_referer('wc-stripe-add-to-cart', 'security');
913 913
 
914
-		if ( ! defined( 'WOOCOMMERCE_CART' ) ) {
915
-			define( 'WOOCOMMERCE_CART', true );
914
+		if ( ! defined('WOOCOMMERCE_CART')) {
915
+			define('WOOCOMMERCE_CART', true);
916 916
 		}
917 917
 
918 918
 		WC()->shipping->reset_shipping();
919 919
 
920
-		$product_id = absint( $_POST['product_id'] );
921
-		$qty        = ! isset( $_POST['qty'] ) ? 1 : absint( $_POST['qty'] );
922
-		$product    = wc_get_product( $product_id );
920
+		$product_id = absint($_POST['product_id']);
921
+		$qty        = ! isset($_POST['qty']) ? 1 : absint($_POST['qty']);
922
+		$product    = wc_get_product($product_id);
923 923
 
924 924
 		// First empty the cart to prevent wrong calculation.
925 925
 		WC()->cart->empty_cart();
926 926
 
927
-		if ( 'variable' === ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $product->product_type : $product->get_type() ) && isset( $_POST['attributes'] ) ) {
928
-			$attributes = array_map( 'wc_clean', $_POST['attributes'] );
927
+		if ('variable' === (WC_Stripe_Helper::is_wc_lt('3.0') ? $product->product_type : $product->get_type()) && isset($_POST['attributes'])) {
928
+			$attributes = array_map('wc_clean', $_POST['attributes']);
929 929
 
930
-			if ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ) {
931
-				$variation_id = $product->get_matching_variation( $attributes );
930
+			if (WC_Stripe_Helper::is_wc_lt('3.0')) {
931
+				$variation_id = $product->get_matching_variation($attributes);
932 932
 			} else {
933
-				$data_store   = WC_Data_Store::load( 'product' );
934
-				$variation_id = $data_store->find_matching_product_variation( $product, $attributes );
933
+				$data_store   = WC_Data_Store::load('product');
934
+				$variation_id = $data_store->find_matching_product_variation($product, $attributes);
935 935
 			}
936 936
 
937
-			WC()->cart->add_to_cart( $product->get_id(), $qty, $variation_id, $attributes );
937
+			WC()->cart->add_to_cart($product->get_id(), $qty, $variation_id, $attributes);
938 938
 		}
939 939
 
940
-		if ( 'simple' === ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $product->product_type : $product->get_type() ) ) {
941
-			WC()->cart->add_to_cart( $product->get_id(), $qty );
940
+		if ('simple' === (WC_Stripe_Helper::is_wc_lt('3.0') ? $product->product_type : $product->get_type())) {
941
+			WC()->cart->add_to_cart($product->get_id(), $qty);
942 942
 		}
943 943
 
944 944
 		WC()->cart->calculate_totals();
@@ -947,7 +947,7 @@  discard block
 block discarded – undo
947 947
 		$data          += $this->build_display_items();
948 948
 		$data['result'] = 'success';
949 949
 
950
-		wp_send_json( $data );
950
+		wp_send_json($data);
951 951
 	}
952 952
 
953 953
 	/**
@@ -960,31 +960,31 @@  discard block
 block discarded – undo
960 960
 	 * @version 4.0.0
961 961
 	 */
962 962
 	public function normalize_state() {
963
-		$billing_country  = ! empty( $_POST['billing_country'] ) ? wc_clean( $_POST['billing_country'] ) : '';
964
-		$shipping_country = ! empty( $_POST['shipping_country'] ) ? wc_clean( $_POST['shipping_country'] ) : '';
965
-		$billing_state    = ! empty( $_POST['billing_state'] ) ? wc_clean( $_POST['billing_state'] ) : '';
966
-		$shipping_state   = ! empty( $_POST['shipping_state'] ) ? wc_clean( $_POST['shipping_state'] ) : '';
963
+		$billing_country  = ! empty($_POST['billing_country']) ? wc_clean($_POST['billing_country']) : '';
964
+		$shipping_country = ! empty($_POST['shipping_country']) ? wc_clean($_POST['shipping_country']) : '';
965
+		$billing_state    = ! empty($_POST['billing_state']) ? wc_clean($_POST['billing_state']) : '';
966
+		$shipping_state   = ! empty($_POST['shipping_state']) ? wc_clean($_POST['shipping_state']) : '';
967 967
 
968
-		if ( $billing_state && $billing_country ) {
969
-			$valid_states = WC()->countries->get_states( $billing_country );
968
+		if ($billing_state && $billing_country) {
969
+			$valid_states = WC()->countries->get_states($billing_country);
970 970
 
971 971
 			// Valid states found for country.
972
-			if ( ! empty( $valid_states ) && is_array( $valid_states ) && sizeof( $valid_states ) > 0 ) {
973
-				foreach ( $valid_states as $state_abbr => $state ) {
974
-					if ( preg_match( '/' . preg_quote( $state ) . '/i', $billing_state ) ) {
972
+			if ( ! empty($valid_states) && is_array($valid_states) && sizeof($valid_states) > 0) {
973
+				foreach ($valid_states as $state_abbr => $state) {
974
+					if (preg_match('/' . preg_quote($state) . '/i', $billing_state)) {
975 975
 						$_POST['billing_state'] = $state_abbr;
976 976
 					}
977 977
 				}
978 978
 			}
979 979
 		}
980 980
 
981
-		if ( $shipping_state && $shipping_country ) {
982
-			$valid_states = WC()->countries->get_states( $shipping_country );
981
+		if ($shipping_state && $shipping_country) {
982
+			$valid_states = WC()->countries->get_states($shipping_country);
983 983
 
984 984
 			// Valid states found for country.
985
-			if ( ! empty( $valid_states ) && is_array( $valid_states ) && sizeof( $valid_states ) > 0 ) {
986
-				foreach ( $valid_states as $state_abbr => $state ) {
987
-					if ( preg_match( '/' . preg_quote( $state ) . '/i', $shipping_state ) ) {
985
+			if ( ! empty($valid_states) && is_array($valid_states) && sizeof($valid_states) > 0) {
986
+				foreach ($valid_states as $state_abbr => $state) {
987
+					if (preg_match('/' . preg_quote($state) . '/i', $shipping_state)) {
988 988
 						$_POST['shipping_state'] = $state_abbr;
989 989
 					}
990 990
 				}
@@ -999,19 +999,19 @@  discard block
 block discarded – undo
999 999
 	 * @version 4.0.0
1000 1000
 	 */
1001 1001
 	public function ajax_create_order() {
1002
-		if ( WC()->cart->is_empty() ) {
1003
-			wp_send_json_error( __( 'Empty cart', 'woocommerce-gateway-stripe' ) );
1002
+		if (WC()->cart->is_empty()) {
1003
+			wp_send_json_error(__('Empty cart', 'woocommerce-gateway-stripe'));
1004 1004
 		}
1005 1005
 
1006
-		if ( ! defined( 'WOOCOMMERCE_CHECKOUT' ) ) {
1007
-			define( 'WOOCOMMERCE_CHECKOUT', true );
1006
+		if ( ! defined('WOOCOMMERCE_CHECKOUT')) {
1007
+			define('WOOCOMMERCE_CHECKOUT', true);
1008 1008
 		}
1009 1009
 
1010 1010
 		$this->normalize_state();
1011 1011
 
1012 1012
 		WC()->checkout()->process_checkout();
1013 1013
 
1014
-		die( 0 );
1014
+		die(0);
1015 1015
 	}
1016 1016
 
1017 1017
 	/**
@@ -1021,41 +1021,41 @@  discard block
 block discarded – undo
1021 1021
 	 * @version 4.0.0
1022 1022
 	 * @param array $address
1023 1023
 	 */
1024
-	protected function calculate_shipping( $address = array() ) {
1024
+	protected function calculate_shipping($address = array()) {
1025 1025
 		$country   = $address['country'];
1026 1026
 		$state     = $address['state'];
1027 1027
 		$postcode  = $address['postcode'];
1028 1028
 		$city      = $address['city'];
1029 1029
 		$address_1 = $address['address'];
1030 1030
 		$address_2 = $address['address_2'];
1031
-		$wc_states = WC()->countries->get_states( $country );
1031
+		$wc_states = WC()->countries->get_states($country);
1032 1032
 
1033 1033
 		/**
1034 1034
 		 * In some versions of Chrome, state can be a full name. So we need
1035 1035
 		 * to convert that to abbreviation as WC is expecting that.
1036 1036
 		 */
1037
-		if ( 2 < strlen( $state ) && ! empty( $wc_states ) ) {
1038
-			$state = array_search( ucwords( strtolower( $state ) ), $wc_states, true );
1037
+		if (2 < strlen($state) && ! empty($wc_states)) {
1038
+			$state = array_search(ucwords(strtolower($state)), $wc_states, true);
1039 1039
 		}
1040 1040
 
1041 1041
 		WC()->shipping->reset_shipping();
1042 1042
 
1043
-		if ( $postcode && WC_Validation::is_postcode( $postcode, $country ) ) {
1044
-			$postcode = wc_format_postcode( $postcode, $country );
1043
+		if ($postcode && WC_Validation::is_postcode($postcode, $country)) {
1044
+			$postcode = wc_format_postcode($postcode, $country);
1045 1045
 		}
1046 1046
 
1047
-		if ( $country ) {
1048
-			WC()->customer->set_location( $country, $state, $postcode, $city );
1049
-			WC()->customer->set_shipping_location( $country, $state, $postcode, $city );
1047
+		if ($country) {
1048
+			WC()->customer->set_location($country, $state, $postcode, $city);
1049
+			WC()->customer->set_shipping_location($country, $state, $postcode, $city);
1050 1050
 		} else {
1051
-			WC_Stripe_Helper::is_wc_lt( '3.0' ) ? WC()->customer->set_to_base() : WC()->customer->set_billing_address_to_base();
1052
-			WC_Stripe_Helper::is_wc_lt( '3.0' ) ? WC()->customer->set_shipping_to_base() : WC()->customer->set_shipping_address_to_base();
1051
+			WC_Stripe_Helper::is_wc_lt('3.0') ? WC()->customer->set_to_base() : WC()->customer->set_billing_address_to_base();
1052
+			WC_Stripe_Helper::is_wc_lt('3.0') ? WC()->customer->set_shipping_to_base() : WC()->customer->set_shipping_address_to_base();
1053 1053
 		}
1054 1054
 
1055
-		if ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ) {
1056
-			WC()->customer->calculated_shipping( true );
1055
+		if (WC_Stripe_Helper::is_wc_lt('3.0')) {
1056
+			WC()->customer->calculated_shipping(true);
1057 1057
 		} else {
1058
-			WC()->customer->set_calculated_shipping( true );
1058
+			WC()->customer->set_calculated_shipping(true);
1059 1059
 			WC()->customer->save();
1060 1060
 		}
1061 1061
 
@@ -1072,17 +1072,17 @@  discard block
 block discarded – undo
1072 1072
 		$packages[0]['destination']['address']   = $address_1;
1073 1073
 		$packages[0]['destination']['address_2'] = $address_2;
1074 1074
 
1075
-		foreach ( WC()->cart->get_cart() as $item ) {
1076
-			if ( $item['data']->needs_shipping() ) {
1077
-				if ( isset( $item['line_total'] ) ) {
1075
+		foreach (WC()->cart->get_cart() as $item) {
1076
+			if ($item['data']->needs_shipping()) {
1077
+				if (isset($item['line_total'])) {
1078 1078
 					$packages[0]['contents_cost'] += $item['line_total'];
1079 1079
 				}
1080 1080
 			}
1081 1081
 		}
1082 1082
 
1083
-		$packages = apply_filters( 'woocommerce_cart_shipping_packages', $packages );
1083
+		$packages = apply_filters('woocommerce_cart_shipping_packages', $packages);
1084 1084
 
1085
-		WC()->shipping->calculate_shipping( $packages );
1085
+		WC()->shipping->calculate_shipping($packages);
1086 1086
 	}
1087 1087
 
1088 1088
 	/**
@@ -1091,19 +1091,19 @@  discard block
 block discarded – undo
1091 1091
 	 * @since 3.1.0
1092 1092
 	 * @version 4.0.0
1093 1093
 	 */
1094
-	protected function build_shipping_methods( $shipping_methods ) {
1095
-		if ( empty( $shipping_methods ) ) {
1094
+	protected function build_shipping_methods($shipping_methods) {
1095
+		if (empty($shipping_methods)) {
1096 1096
 			return array();
1097 1097
 		}
1098 1098
 
1099 1099
 		$shipping = array();
1100 1100
 
1101
-		foreach ( $shipping_methods as $method ) {
1101
+		foreach ($shipping_methods as $method) {
1102 1102
 			$shipping[] = array(
1103 1103
 				'id'     => $method['id'],
1104 1104
 				'label'  => $method['label'],
1105 1105
 				'detail' => '',
1106
-				'amount' => WC_Stripe_Helper::get_stripe_amount( $method['amount']['value'] ),
1106
+				'amount' => WC_Stripe_Helper::get_stripe_amount($method['amount']['value']),
1107 1107
 			);
1108 1108
 		}
1109 1109
 
@@ -1117,8 +1117,8 @@  discard block
 block discarded – undo
1117 1117
 	 * @version 4.0.0
1118 1118
 	 */
1119 1119
 	protected function build_display_items() {
1120
-		if ( ! defined( 'WOOCOMMERCE_CART' ) ) {
1121
-			define( 'WOOCOMMERCE_CART', true );
1120
+		if ( ! defined('WOOCOMMERCE_CART')) {
1121
+			define('WOOCOMMERCE_CART', true);
1122 1122
 		}
1123 1123
 
1124 1124
 		$items     = array();
@@ -1126,71 +1126,71 @@  discard block
 block discarded – undo
1126 1126
 		$discounts = 0;
1127 1127
 
1128 1128
 		// Default show only subtotal instead of itemization.
1129
-		if ( ! apply_filters( 'wc_stripe_payment_request_hide_itemization', true ) ) {
1130
-			foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {
1129
+		if ( ! apply_filters('wc_stripe_payment_request_hide_itemization', true)) {
1130
+			foreach (WC()->cart->get_cart() as $cart_item_key => $cart_item) {
1131 1131
 				$amount         = $cart_item['line_subtotal'];
1132 1132
 				$subtotal      += $cart_item['line_subtotal'];
1133 1133
 				$quantity_label = 1 < $cart_item['quantity'] ? ' (x' . $cart_item['quantity'] . ')' : '';
1134 1134
 
1135
-				$product_name = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $cart_item['data']->post->post_title : $cart_item['data']->get_name();
1135
+				$product_name = WC_Stripe_Helper::is_wc_lt('3.0') ? $cart_item['data']->post->post_title : $cart_item['data']->get_name();
1136 1136
 
1137 1137
 				$item = array(
1138 1138
 					'label'  => $product_name . $quantity_label,
1139
-					'amount' => WC_Stripe_Helper::get_stripe_amount( $amount ),
1139
+					'amount' => WC_Stripe_Helper::get_stripe_amount($amount),
1140 1140
 				);
1141 1141
 
1142 1142
 				$items[] = $item;
1143 1143
 			}
1144 1144
 		}
1145 1145
 
1146
-		if ( version_compare( WC_VERSION, '3.2', '<' ) ) {
1147
-			$discounts = wc_format_decimal( WC()->cart->get_cart_discount_total(), WC()->cart->dp );
1146
+		if (version_compare(WC_VERSION, '3.2', '<')) {
1147
+			$discounts = wc_format_decimal(WC()->cart->get_cart_discount_total(), WC()->cart->dp);
1148 1148
 		} else {
1149
-			$applied_coupons = array_values( WC()->cart->get_coupon_discount_totals() );
1149
+			$applied_coupons = array_values(WC()->cart->get_coupon_discount_totals());
1150 1150
 
1151
-			foreach ( $applied_coupons as $amount ) {
1151
+			foreach ($applied_coupons as $amount) {
1152 1152
 				$discounts += (float) $amount;
1153 1153
 			}
1154 1154
 		}
1155 1155
 
1156
-		$discounts   = wc_format_decimal( $discounts, WC()->cart->dp );
1157
-		$tax         = wc_format_decimal( WC()->cart->tax_total + WC()->cart->shipping_tax_total, WC()->cart->dp );
1158
-		$shipping    = wc_format_decimal( WC()->cart->shipping_total, WC()->cart->dp );
1159
-		$items_total = wc_format_decimal( WC()->cart->cart_contents_total, WC()->cart->dp ) + $discounts;
1160
-		$order_total = version_compare( WC_VERSION, '3.2', '<' ) ? wc_format_decimal( $items_total + $tax + $shipping - $discounts, WC()->cart->dp ) : WC()->cart->get_total( false );
1156
+		$discounts   = wc_format_decimal($discounts, WC()->cart->dp);
1157
+		$tax         = wc_format_decimal(WC()->cart->tax_total + WC()->cart->shipping_tax_total, WC()->cart->dp);
1158
+		$shipping    = wc_format_decimal(WC()->cart->shipping_total, WC()->cart->dp);
1159
+		$items_total = wc_format_decimal(WC()->cart->cart_contents_total, WC()->cart->dp) + $discounts;
1160
+		$order_total = version_compare(WC_VERSION, '3.2', '<') ? wc_format_decimal($items_total + $tax + $shipping - $discounts, WC()->cart->dp) : WC()->cart->get_total(false);
1161 1161
 
1162
-		if ( wc_tax_enabled() ) {
1162
+		if (wc_tax_enabled()) {
1163 1163
 			$items[] = array(
1164
-				'label'  => esc_html( __( 'Tax', 'woocommerce-gateway-stripe' ) ),
1165
-				'amount' => WC_Stripe_Helper::get_stripe_amount( $tax ),
1164
+				'label'  => esc_html(__('Tax', 'woocommerce-gateway-stripe')),
1165
+				'amount' => WC_Stripe_Helper::get_stripe_amount($tax),
1166 1166
 			);
1167 1167
 		}
1168 1168
 
1169
-		if ( WC()->cart->needs_shipping() ) {
1169
+		if (WC()->cart->needs_shipping()) {
1170 1170
 			$items[] = array(
1171
-				'label'  => esc_html( __( 'Shipping', 'woocommerce-gateway-stripe' ) ),
1172
-				'amount' => WC_Stripe_Helper::get_stripe_amount( $shipping ),
1171
+				'label'  => esc_html(__('Shipping', 'woocommerce-gateway-stripe')),
1172
+				'amount' => WC_Stripe_Helper::get_stripe_amount($shipping),
1173 1173
 			);
1174 1174
 		}
1175 1175
 
1176
-		if ( WC()->cart->has_discount() ) {
1176
+		if (WC()->cart->has_discount()) {
1177 1177
 			$items[] = array(
1178
-				'label'  => esc_html( __( 'Discount', 'woocommerce-gateway-stripe' ) ),
1179
-				'amount' => WC_Stripe_Helper::get_stripe_amount( $discounts ),
1178
+				'label'  => esc_html(__('Discount', 'woocommerce-gateway-stripe')),
1179
+				'amount' => WC_Stripe_Helper::get_stripe_amount($discounts),
1180 1180
 			);
1181 1181
 		}
1182 1182
 
1183
-		if ( version_compare( WC_VERSION, '3.2', '<' ) ) {
1183
+		if (version_compare(WC_VERSION, '3.2', '<')) {
1184 1184
 			$cart_fees = WC()->cart->fees;
1185 1185
 		} else {
1186 1186
 			$cart_fees = WC()->cart->get_fees();
1187 1187
 		}
1188 1188
 
1189 1189
 		// Include fees and taxes as display items.
1190
-		foreach ( $cart_fees as $key => $fee ) {
1190
+		foreach ($cart_fees as $key => $fee) {
1191 1191
 			$items[] = array(
1192 1192
 				'label'  => $fee->name,
1193
-				'amount' => WC_Stripe_Helper::get_stripe_amount( $fee->amount ),
1193
+				'amount' => WC_Stripe_Helper::get_stripe_amount($fee->amount),
1194 1194
 			);
1195 1195
 		}
1196 1196
 
@@ -1198,7 +1198,7 @@  discard block
 block discarded – undo
1198 1198
 			'displayItems' => $items,
1199 1199
 			'total'        => array(
1200 1200
 				'label'   => $this->total_label,
1201
-				'amount'  => max( 0, apply_filters( 'woocommerce_stripe_calculated_total', WC_Stripe_Helper::get_stripe_amount( $order_total ), $order_total, WC()->cart ) ),
1201
+				'amount'  => max(0, apply_filters('woocommerce_stripe_calculated_total', WC_Stripe_Helper::get_stripe_amount($order_total), $order_total, WC()->cart)),
1202 1202
 				'pending' => false,
1203 1203
 			),
1204 1204
 		);
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   +181 added lines, -181 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
 			 * WC subscriptions hooks into the "template_redirect" hook with priority 100.
@@ -37,8 +37,8 @@  discard block
 block discarded – undo
37 37
 			 * See: https://github.com/woocommerce/woocommerce-subscriptions/blob/99a75687e109b64cbc07af6e5518458a6305f366/includes/class-wcs-cart-renewal.php#L165
38 38
 			 * If we are in the "You just need to authorize SCA" flow, we don't want that redirection to happen.
39 39
 			 */
40
-			add_action( 'template_redirect', array( $this, 'remove_order_pay_var' ), 99 );
41
-			add_action( 'template_redirect', array( $this, 'restore_order_pay_var' ), 101 );
40
+			add_action('template_redirect', array($this, 'remove_order_pay_var'), 99);
41
+			add_action('template_redirect', array($this, 'restore_order_pay_var'), 101);
42 42
 		}
43 43
 	}
44 44
 
@@ -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,24 +129,24 @@  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
 
137
-			$this->maybe_disallow_prepaid_card( $prepared_source );
138
-			$this->check_source( $prepared_source );
139
-			$this->save_source_to_order( $subscription, $prepared_source );
137
+			$this->maybe_disallow_prepaid_card($prepared_source);
138
+			$this->check_source($prepared_source);
139
+			$this->save_source_to_order($subscription, $prepared_source);
140 140
 
141
-			do_action( 'wc_stripe_change_subs_payment_method_success', $prepared_source->source, $prepared_source );
141
+			do_action('wc_stripe_change_subs_payment_method_success', $prepared_source->source, $prepared_source);
142 142
 
143 143
 			return array(
144 144
 				'result'   => 'success',
145
-				'redirect' => $this->get_return_url( $subscription ),
145
+				'redirect' => $this->get_return_url($subscription),
146 146
 			);
147
-		} catch ( WC_Stripe_Exception $e ) {
148
-			wc_add_notice( $e->getLocalizedMessage(), 'error' );
149
-			WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() );
147
+		} catch (WC_Stripe_Exception $e) {
148
+			wc_add_notice($e->getLocalizedMessage(), 'error');
149
+			WC_Stripe_Logger::log('Error: ' . $e->getMessage());
150 150
 		}
151 151
 	}
152 152
 
@@ -155,16 +155,16 @@  discard block
 block discarded – undo
155 155
 	 * @param  int $order_id
156 156
 	 * @return array
157 157
 	 */
158
-	public function process_payment( $order_id, $retry = true, $force_save_source = false, $previous_error = false ) {
159
-		if ( $this->has_subscription( $order_id ) ) {
160
-			if ( $this->is_subs_change_payment() ) {
161
-				return $this->change_subs_payment_method( $order_id );
158
+	public function process_payment($order_id, $retry = true, $force_save_source = false, $previous_error = false) {
159
+		if ($this->has_subscription($order_id)) {
160
+			if ($this->is_subs_change_payment()) {
161
+				return $this->change_subs_payment_method($order_id);
162 162
 			}
163 163
 
164 164
 			// Regular payment with force customer enabled
165
-			return parent::process_payment( $order_id, $retry, true, $previous_error );
165
+			return parent::process_payment($order_id, $retry, true, $previous_error);
166 166
 		} else {
167
-			return parent::process_payment( $order_id, $retry, $force_save_source, $previous_error );
167
+			return parent::process_payment($order_id, $retry, $force_save_source, $previous_error);
168 168
 		}
169 169
 	}
170 170
 
@@ -176,11 +176,11 @@  discard block
 block discarded – undo
176 176
 	 * @param object   $prepared_source The source that is used for the payment.
177 177
 	 * @return array                    The arguments for the request.
178 178
 	 */
179
-	public function generate_create_intent_request( $order, $prepared_source ) {
180
-		$request = parent::generate_create_intent_request( $order, $prepared_source );
179
+	public function generate_create_intent_request($order, $prepared_source) {
180
+		$request = parent::generate_create_intent_request($order, $prepared_source);
181 181
 
182 182
 		// Non-subscription orders do not need any additional parameters.
183
-		if ( ! $this->has_subscription( $order ) ) {
183
+		if ( ! $this->has_subscription($order)) {
184 184
 			return $request;
185 185
 		}
186 186
 
@@ -196,8 +196,8 @@  discard block
 block discarded – undo
196 196
 	 * @param $amount_to_charge float The amount to charge.
197 197
 	 * @param $renewal_order WC_Order A WC_Order object created to record the renewal payment.
198 198
 	 */
199
-	public function scheduled_subscription_payment( $amount_to_charge, $renewal_order ) {
200
-		$this->process_subscription_payment( $amount_to_charge, $renewal_order, true, false );
199
+	public function scheduled_subscription_payment($amount_to_charge, $renewal_order) {
200
+		$this->process_subscription_payment($amount_to_charge, $renewal_order, true, false);
201 201
 	}
202 202
 
203 203
 	/**
@@ -211,112 +211,112 @@  discard block
 block discarded – undo
211 211
 	 * @param bool $retry Should we retry the process?
212 212
 	 * @param object $previous_error
213 213
 	 */
214
-	public function process_subscription_payment( $amount = 0.0, $renewal_order, $retry = true, $previous_error ) {
214
+	public function process_subscription_payment($amount = 0.0, $renewal_order, $retry = true, $previous_error) {
215 215
 		try {
216
-			if ( $amount * 100 < WC_Stripe_Helper::get_minimum_amount() ) {
216
+			if ($amount * 100 < WC_Stripe_Helper::get_minimum_amount()) {
217 217
 				/* translators: minimum amount */
218
-				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 ) ) );
218
+				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)));
219 219
 			}
220 220
 
221
-			$order_id = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $renewal_order->id : $renewal_order->get_id();
221
+			$order_id = WC_Stripe_Helper::is_wc_lt('3.0') ? $renewal_order->id : $renewal_order->get_id();
222 222
 
223 223
 			// Check for an existing intent, which is associated with the order.
224
-			if ( $this->has_authentication_already_failed( $renewal_order ) ) {
224
+			if ($this->has_authentication_already_failed($renewal_order)) {
225 225
 				return;
226 226
 			}
227 227
 
228 228
 			// Get source from order
229
-			$prepared_source = $this->prepare_order_source( $renewal_order );
229
+			$prepared_source = $this->prepare_order_source($renewal_order);
230 230
 			$source_object   = $prepared_source->source_object;
231 231
 
232
-			if ( ! $prepared_source->customer ) {
233
-				return new WP_Error( 'stripe_error', __( 'Customer not found', 'woocommerce-gateway-stripe' ) );
232
+			if ( ! $prepared_source->customer) {
233
+				return new WP_Error('stripe_error', __('Customer not found', 'woocommerce-gateway-stripe'));
234 234
 			}
235 235
 
236
-			WC_Stripe_Logger::log( "Info: Begin processing subscription payment for order {$order_id} for the amount of {$amount}" );
236
+			WC_Stripe_Logger::log("Info: Begin processing subscription payment for order {$order_id} for the amount of {$amount}");
237 237
 
238 238
 			/* If we're doing a retry and source is chargeable, we need to pass
239 239
 			 * a different idempotency key and retry for success.
240 240
 			 */
241
-			if ( is_object( $source_object ) && empty( $source_object->error ) && $this->need_update_idempotency_key( $source_object, $previous_error ) ) {
242
-				add_filter( 'wc_stripe_idempotency_key', array( $this, 'change_idempotency_key' ), 10, 2 );
241
+			if (is_object($source_object) && empty($source_object->error) && $this->need_update_idempotency_key($source_object, $previous_error)) {
242
+				add_filter('wc_stripe_idempotency_key', array($this, 'change_idempotency_key'), 10, 2);
243 243
 			}
244 244
 
245
-			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 ) ) {
245
+			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)) {
246 246
 				// Passing empty source will charge customer default.
247 247
 				$prepared_source->source = '';
248 248
 			}
249 249
 
250
-			$response = $this->create_and_confirm_intent_for_off_session( $renewal_order, $prepared_source, $amount );
250
+			$response = $this->create_and_confirm_intent_for_off_session($renewal_order, $prepared_source, $amount);
251 251
 
252
-			$is_authentication_required = $this->is_authentication_required_for_payment( $response );
252
+			$is_authentication_required = $this->is_authentication_required_for_payment($response);
253 253
 
254 254
 			// It's only a failed payment if it's an error and it's not of the type 'authentication_required'.
255 255
 			// If it's 'authentication_required', then we should email the user and ask them to authenticate.
256
-			if ( ! empty( $response->error ) && ! $is_authentication_required ) {
256
+			if ( ! empty($response->error) && ! $is_authentication_required) {
257 257
 				// We want to retry.
258
-				if ( $this->is_retryable_error( $response->error ) ) {
259
-					if ( $retry ) {
258
+				if ($this->is_retryable_error($response->error)) {
259
+					if ($retry) {
260 260
 						// Don't do anymore retries after this.
261
-						if ( 5 <= $this->retry_interval ) {
262
-							return $this->process_subscription_payment( $amount, $renewal_order, false, $response->error );
261
+						if (5 <= $this->retry_interval) {
262
+							return $this->process_subscription_payment($amount, $renewal_order, false, $response->error);
263 263
 						}
264 264
 
265
-						sleep( $this->retry_interval );
265
+						sleep($this->retry_interval);
266 266
 
267 267
 						$this->retry_interval++;
268 268
 
269
-						return $this->process_subscription_payment( $amount, $renewal_order, true, $response->error );
269
+						return $this->process_subscription_payment($amount, $renewal_order, true, $response->error);
270 270
 					} else {
271
-						$localized_message = __( 'Sorry, we are unable to process your payment at this time. Please retry later.', 'woocommerce-gateway-stripe' );
272
-						$renewal_order->add_order_note( $localized_message );
273
-						throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message );
271
+						$localized_message = __('Sorry, we are unable to process your payment at this time. Please retry later.', 'woocommerce-gateway-stripe');
272
+						$renewal_order->add_order_note($localized_message);
273
+						throw new WC_Stripe_Exception(print_r($response, true), $localized_message);
274 274
 					}
275 275
 				}
276 276
 
277 277
 				$localized_messages = WC_Stripe_Helper::get_localized_messages();
278 278
 
279
-				if ( 'card_error' === $response->error->type ) {
280
-					$localized_message = isset( $localized_messages[ $response->error->code ] ) ? $localized_messages[ $response->error->code ] : $response->error->message;
279
+				if ('card_error' === $response->error->type) {
280
+					$localized_message = isset($localized_messages[$response->error->code]) ? $localized_messages[$response->error->code] : $response->error->message;
281 281
 				} else {
282
-					$localized_message = isset( $localized_messages[ $response->error->type ] ) ? $localized_messages[ $response->error->type ] : $response->error->message;
282
+					$localized_message = isset($localized_messages[$response->error->type]) ? $localized_messages[$response->error->type] : $response->error->message;
283 283
 				}
284 284
 
285
-				$renewal_order->add_order_note( $localized_message );
285
+				$renewal_order->add_order_note($localized_message);
286 286
 
287
-				throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message );
287
+				throw new WC_Stripe_Exception(print_r($response, true), $localized_message);
288 288
 			}
289 289
 
290 290
 			// Either the charge was successfully captured, or it requires further authentication.
291 291
 
292
-			if ( $is_authentication_required ) {
293
-				do_action( 'wc_gateway_stripe_process_payment_authentication_required', $renewal_order, $response );
292
+			if ($is_authentication_required) {
293
+				do_action('wc_gateway_stripe_process_payment_authentication_required', $renewal_order, $response);
294 294
 
295
-				$error_message = __( 'This transaction requires authentication.', 'woocommerce-gateway-stripe' );
296
-				$renewal_order->add_order_note( $error_message );
295
+				$error_message = __('This transaction requires authentication.', 'woocommerce-gateway-stripe');
296
+				$renewal_order->add_order_note($error_message);
297 297
 
298
-				$charge = end( $response->error->payment_intent->charges->data );
298
+				$charge = end($response->error->payment_intent->charges->data);
299 299
 				$id = $charge->id;
300
-				$order_id = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $renewal_order->id : $renewal_order->get_id();
300
+				$order_id = WC_Stripe_Helper::is_wc_lt('3.0') ? $renewal_order->id : $renewal_order->get_id();
301 301
 
302
-				WC_Stripe_Helper::is_wc_lt( '3.0' ) ? update_post_meta( $order_id, '_transaction_id', $id ) : $renewal_order->set_transaction_id( $id );
303
-				$renewal_order->update_status( 'failed', sprintf( __( 'Stripe charge awaiting authentication by user: %s.', 'woocommerce-gateway-stripe' ), $id ) );
304
-				if ( is_callable( array( $renewal_order, 'save' ) ) ) {
302
+				WC_Stripe_Helper::is_wc_lt('3.0') ? update_post_meta($order_id, '_transaction_id', $id) : $renewal_order->set_transaction_id($id);
303
+				$renewal_order->update_status('failed', sprintf(__('Stripe charge awaiting authentication by user: %s.', 'woocommerce-gateway-stripe'), $id));
304
+				if (is_callable(array($renewal_order, 'save'))) {
305 305
 					$renewal_order->save();
306 306
 				}
307 307
 			} else {
308 308
 				// The charge was successfully captured
309
-				do_action( 'wc_gateway_stripe_process_payment', $response, $renewal_order );
309
+				do_action('wc_gateway_stripe_process_payment', $response, $renewal_order);
310 310
 
311
-				$this->process_response( end( $response->charges->data ), $renewal_order );
311
+				$this->process_response(end($response->charges->data), $renewal_order);
312 312
 			}
313
-		} catch ( WC_Stripe_Exception $e ) {
314
-			WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() );
313
+		} catch (WC_Stripe_Exception $e) {
314
+			WC_Stripe_Logger::log('Error: ' . $e->getMessage());
315 315
 
316
-			do_action( 'wc_gateway_stripe_process_payment_error', $e, $renewal_order );
316
+			do_action('wc_gateway_stripe_process_payment_error', $e, $renewal_order);
317 317
 
318 318
 			/* translators: error message */
319
-			$renewal_order->update_status( 'failed' );
319
+			$renewal_order->update_status('failed');
320 320
 		}
321 321
 	}
322 322
 
@@ -326,24 +326,24 @@  discard block
 block discarded – undo
326 326
 	 * @since 3.1.0
327 327
 	 * @version 4.0.0
328 328
 	 */
329
-	public function save_source_to_order( $order, $source ) {
330
-		parent::save_source_to_order( $order, $source );
329
+	public function save_source_to_order($order, $source) {
330
+		parent::save_source_to_order($order, $source);
331 331
 
332
-		$order_id = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->id : $order->get_id();
332
+		$order_id = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->id : $order->get_id();
333 333
 
334 334
 		// Also store it on the subscriptions being purchased or paid for in the order
335
-		if ( function_exists( 'wcs_order_contains_subscription' ) && wcs_order_contains_subscription( $order_id ) ) {
336
-			$subscriptions = wcs_get_subscriptions_for_order( $order_id );
337
-		} elseif ( function_exists( 'wcs_order_contains_renewal' ) && wcs_order_contains_renewal( $order_id ) ) {
338
-			$subscriptions = wcs_get_subscriptions_for_renewal_order( $order_id );
335
+		if (function_exists('wcs_order_contains_subscription') && wcs_order_contains_subscription($order_id)) {
336
+			$subscriptions = wcs_get_subscriptions_for_order($order_id);
337
+		} elseif (function_exists('wcs_order_contains_renewal') && wcs_order_contains_renewal($order_id)) {
338
+			$subscriptions = wcs_get_subscriptions_for_renewal_order($order_id);
339 339
 		} else {
340 340
 			$subscriptions = array();
341 341
 		}
342 342
 
343
-		foreach ( $subscriptions as $subscription ) {
344
-			$subscription_id = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $subscription->id : $subscription->get_id();
345
-			update_post_meta( $subscription_id, '_stripe_customer_id', $source->customer );
346
-			update_post_meta( $subscription_id, '_stripe_source_id', $source->source );
343
+		foreach ($subscriptions as $subscription) {
344
+			$subscription_id = WC_Stripe_Helper::is_wc_lt('3.0') ? $subscription->id : $subscription->get_id();
345
+			update_post_meta($subscription_id, '_stripe_customer_id', $source->customer);
346
+			update_post_meta($subscription_id, '_stripe_source_id', $source->source);
347 347
 		}
348 348
 	}
349 349
 
@@ -351,26 +351,26 @@  discard block
 block discarded – undo
351 351
 	 * Don't transfer Stripe customer/token meta to resubscribe orders.
352 352
 	 * @param int $resubscribe_order The order created for the customer to resubscribe to the old expired/cancelled subscription
353 353
 	 */
354
-	public function delete_resubscribe_meta( $resubscribe_order ) {
355
-		delete_post_meta( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $resubscribe_order->id : $resubscribe_order->get_id() ), '_stripe_customer_id' );
356
-		delete_post_meta( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $resubscribe_order->id : $resubscribe_order->get_id() ), '_stripe_source_id' );
354
+	public function delete_resubscribe_meta($resubscribe_order) {
355
+		delete_post_meta((WC_Stripe_Helper::is_wc_lt('3.0') ? $resubscribe_order->id : $resubscribe_order->get_id()), '_stripe_customer_id');
356
+		delete_post_meta((WC_Stripe_Helper::is_wc_lt('3.0') ? $resubscribe_order->id : $resubscribe_order->get_id()), '_stripe_source_id');
357 357
 		// For BW compat will remove in future
358
-		delete_post_meta( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $resubscribe_order->id : $resubscribe_order->get_id() ), '_stripe_card_id' );
358
+		delete_post_meta((WC_Stripe_Helper::is_wc_lt('3.0') ? $resubscribe_order->id : $resubscribe_order->get_id()), '_stripe_card_id');
359 359
 		// delete payment intent ID
360
-		delete_post_meta( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $resubscribe_order->id : $resubscribe_order->get_id() ), '_stripe_intent_id' );
361
-		$this->delete_renewal_meta( $resubscribe_order );
360
+		delete_post_meta((WC_Stripe_Helper::is_wc_lt('3.0') ? $resubscribe_order->id : $resubscribe_order->get_id()), '_stripe_intent_id');
361
+		$this->delete_renewal_meta($resubscribe_order);
362 362
 	}
363 363
 
364 364
 	/**
365 365
 	 * Don't transfer Stripe fee/ID meta to renewal orders.
366 366
 	 * @param int $resubscribe_order The order created for the customer to resubscribe to the old expired/cancelled subscription
367 367
 	 */
368
-	public function delete_renewal_meta( $renewal_order ) {
369
-		WC_Stripe_Helper::delete_stripe_fee( $renewal_order );
370
-		WC_Stripe_Helper::delete_stripe_net( $renewal_order );
368
+	public function delete_renewal_meta($renewal_order) {
369
+		WC_Stripe_Helper::delete_stripe_fee($renewal_order);
370
+		WC_Stripe_Helper::delete_stripe_net($renewal_order);
371 371
 
372 372
 		// delete payment intent ID
373
-		delete_post_meta( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $renewal_order->id : $renewal_order->get_id() ), '_stripe_intent_id' );
373
+		delete_post_meta((WC_Stripe_Helper::is_wc_lt('3.0') ? $renewal_order->id : $renewal_order->get_id()), '_stripe_intent_id');
374 374
 
375 375
 		return $renewal_order;
376 376
 	}
@@ -384,14 +384,14 @@  discard block
 block discarded – undo
384 384
 	 * @param WC_Order $renewal_order The order which recorded the successful payment (to make up for the failed automatic payment).
385 385
 	 * @return void
386 386
 	 */
387
-	public function update_failing_payment_method( $subscription, $renewal_order ) {
388
-		if ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ) {
389
-			update_post_meta( $subscription->id, '_stripe_customer_id', $renewal_order->stripe_customer_id );
390
-			update_post_meta( $subscription->id, '_stripe_source_id', $renewal_order->stripe_source_id );
387
+	public function update_failing_payment_method($subscription, $renewal_order) {
388
+		if (WC_Stripe_Helper::is_wc_lt('3.0')) {
389
+			update_post_meta($subscription->id, '_stripe_customer_id', $renewal_order->stripe_customer_id);
390
+			update_post_meta($subscription->id, '_stripe_source_id', $renewal_order->stripe_source_id);
391 391
 
392 392
 		} else {
393
-			update_post_meta( $subscription->get_id(), '_stripe_customer_id', $renewal_order->get_meta( '_stripe_customer_id', true ) );
394
-			update_post_meta( $subscription->get_id(), '_stripe_source_id', $renewal_order->get_meta( '_stripe_source_id', true ) );
393
+			update_post_meta($subscription->get_id(), '_stripe_customer_id', $renewal_order->get_meta('_stripe_customer_id', true));
394
+			update_post_meta($subscription->get_id(), '_stripe_source_id', $renewal_order->get_meta('_stripe_source_id', true));
395 395
 		}
396 396
 	}
397 397
 
@@ -404,23 +404,23 @@  discard block
 block discarded – undo
404 404
 	 * @param WC_Subscription $subscription An instance of a subscription object
405 405
 	 * @return array
406 406
 	 */
407
-	public function add_subscription_payment_meta( $payment_meta, $subscription ) {
408
-		$subscription_id = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $subscription->id : $subscription->get_id();
409
-		$source_id       = get_post_meta( $subscription_id, '_stripe_source_id', true );
407
+	public function add_subscription_payment_meta($payment_meta, $subscription) {
408
+		$subscription_id = WC_Stripe_Helper::is_wc_lt('3.0') ? $subscription->id : $subscription->get_id();
409
+		$source_id       = get_post_meta($subscription_id, '_stripe_source_id', true);
410 410
 
411 411
 		// For BW compat will remove in future.
412
-		if ( empty( $source_id ) ) {
413
-			$source_id = get_post_meta( $subscription_id, '_stripe_card_id', true );
412
+		if (empty($source_id)) {
413
+			$source_id = get_post_meta($subscription_id, '_stripe_card_id', true);
414 414
 
415 415
 			// Take this opportunity to update the key name.
416
-			update_post_meta( $subscription_id, '_stripe_source_id', $source_id );
417
-			delete_post_meta( $subscription_id, '_stripe_card_id', $source_id );
416
+			update_post_meta($subscription_id, '_stripe_source_id', $source_id);
417
+			delete_post_meta($subscription_id, '_stripe_card_id', $source_id);
418 418
 		}
419 419
 
420
-		$payment_meta[ $this->id ] = array(
420
+		$payment_meta[$this->id] = array(
421 421
 			'post_meta' => array(
422 422
 				'_stripe_customer_id' => array(
423
-					'value' => get_post_meta( $subscription_id, '_stripe_customer_id', true ),
423
+					'value' => get_post_meta($subscription_id, '_stripe_customer_id', true),
424 424
 					'label' => 'Stripe Customer ID',
425 425
 				),
426 426
 				'_stripe_source_id'   => array(
@@ -443,22 +443,22 @@  discard block
 block discarded – undo
443 443
 	 * @param array $payment_meta associative array of meta data required for automatic payments
444 444
 	 * @return array
445 445
 	 */
446
-	public function validate_subscription_payment_meta( $payment_method_id, $payment_meta ) {
447
-		if ( $this->id === $payment_method_id ) {
446
+	public function validate_subscription_payment_meta($payment_method_id, $payment_meta) {
447
+		if ($this->id === $payment_method_id) {
448 448
 
449
-			if ( ! isset( $payment_meta['post_meta']['_stripe_customer_id']['value'] ) || empty( $payment_meta['post_meta']['_stripe_customer_id']['value'] ) ) {
450
-				throw new Exception( __( 'A "Stripe Customer ID" value is required.', 'woocommerce-gateway-stripe' ) );
451
-			} elseif ( 0 !== strpos( $payment_meta['post_meta']['_stripe_customer_id']['value'], 'cus_' ) ) {
452
-				throw new Exception( __( 'Invalid customer ID. A valid "Stripe Customer ID" must begin with "cus_".', 'woocommerce-gateway-stripe' ) );
449
+			if ( ! isset($payment_meta['post_meta']['_stripe_customer_id']['value']) || empty($payment_meta['post_meta']['_stripe_customer_id']['value'])) {
450
+				throw new Exception(__('A "Stripe Customer ID" value is required.', 'woocommerce-gateway-stripe'));
451
+			} elseif (0 !== strpos($payment_meta['post_meta']['_stripe_customer_id']['value'], 'cus_')) {
452
+				throw new Exception(__('Invalid customer ID. A valid "Stripe Customer ID" must begin with "cus_".', 'woocommerce-gateway-stripe'));
453 453
 			}
454 454
 
455 455
 			if (
456
-				( ! empty( $payment_meta['post_meta']['_stripe_source_id']['value'] )
457
-				&& 0 !== strpos( $payment_meta['post_meta']['_stripe_source_id']['value'], 'card_' ) )
458
-				&& ( ! empty( $payment_meta['post_meta']['_stripe_source_id']['value'] )
459
-				&& 0 !== strpos( $payment_meta['post_meta']['_stripe_source_id']['value'], 'src_' ) ) ) {
456
+				( ! empty($payment_meta['post_meta']['_stripe_source_id']['value'])
457
+				&& 0 !== strpos($payment_meta['post_meta']['_stripe_source_id']['value'], 'card_'))
458
+				&& ( ! empty($payment_meta['post_meta']['_stripe_source_id']['value'])
459
+				&& 0 !== strpos($payment_meta['post_meta']['_stripe_source_id']['value'], 'src_')) ) {
460 460
 
461
-				throw new Exception( __( 'Invalid source ID. A valid source "Stripe Source ID" must begin with "src_" or "card_".', 'woocommerce-gateway-stripe' ) );
461
+				throw new Exception(__('Invalid source ID. A valid source "Stripe Source ID" must begin with "src_" or "card_".', 'woocommerce-gateway-stripe'));
462 462
 			}
463 463
 		}
464 464
 	}
@@ -471,75 +471,75 @@  discard block
 block discarded – undo
471 471
 	 * @param WC_Subscription $subscription the subscription details
472 472
 	 * @return string the subscription payment method
473 473
 	 */
474
-	public function maybe_render_subscription_payment_method( $payment_method_to_display, $subscription ) {
475
-		$customer_user = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $subscription->customer_user : $subscription->get_customer_id();
474
+	public function maybe_render_subscription_payment_method($payment_method_to_display, $subscription) {
475
+		$customer_user = WC_Stripe_Helper::is_wc_lt('3.0') ? $subscription->customer_user : $subscription->get_customer_id();
476 476
 
477 477
 		// bail for other payment methods
478
-		if ( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $subscription->payment_method : $subscription->get_payment_method() ) !== $this->id || ! $customer_user ) {
478
+		if ((WC_Stripe_Helper::is_wc_lt('3.0') ? $subscription->payment_method : $subscription->get_payment_method()) !== $this->id || ! $customer_user) {
479 479
 			return $payment_method_to_display;
480 480
 		}
481 481
 
482
-		$stripe_source_id = get_post_meta( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $subscription->id : $subscription->get_id() ), '_stripe_source_id', true );
482
+		$stripe_source_id = get_post_meta((WC_Stripe_Helper::is_wc_lt('3.0') ? $subscription->id : $subscription->get_id()), '_stripe_source_id', true);
483 483
 
484 484
 		// For BW compat will remove in future.
485
-		if ( empty( $stripe_source_id ) ) {
486
-			$stripe_source_id = get_post_meta( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $subscription->id : $subscription->get_id() ), '_stripe_card_id', true );
485
+		if (empty($stripe_source_id)) {
486
+			$stripe_source_id = get_post_meta((WC_Stripe_Helper::is_wc_lt('3.0') ? $subscription->id : $subscription->get_id()), '_stripe_card_id', true);
487 487
 
488 488
 			// Take this opportunity to update the key name.
489
-			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 );
489
+			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);
490 490
 		}
491 491
 
492 492
 		$stripe_customer    = new WC_Stripe_Customer();
493
-		$stripe_customer_id = get_post_meta( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $subscription->id : $subscription->get_id() ), '_stripe_customer_id', true );
493
+		$stripe_customer_id = get_post_meta((WC_Stripe_Helper::is_wc_lt('3.0') ? $subscription->id : $subscription->get_id()), '_stripe_customer_id', true);
494 494
 
495 495
 		// If we couldn't find a Stripe customer linked to the subscription, fallback to the user meta data.
496
-		if ( ! $stripe_customer_id || ! is_string( $stripe_customer_id ) ) {
496
+		if ( ! $stripe_customer_id || ! is_string($stripe_customer_id)) {
497 497
 			$user_id            = $customer_user;
498
-			$stripe_customer_id = get_user_meta( $user_id, '_stripe_customer_id', true );
499
-			$stripe_source_id   = get_user_meta( $user_id, '_stripe_source_id', true );
498
+			$stripe_customer_id = get_user_meta($user_id, '_stripe_customer_id', true);
499
+			$stripe_source_id   = get_user_meta($user_id, '_stripe_source_id', true);
500 500
 
501 501
 			// For BW compat will remove in future.
502
-			if ( empty( $stripe_source_id ) ) {
503
-				$stripe_source_id = get_user_meta( $user_id, '_stripe_card_id', true );
502
+			if (empty($stripe_source_id)) {
503
+				$stripe_source_id = get_user_meta($user_id, '_stripe_card_id', true);
504 504
 
505 505
 				// Take this opportunity to update the key name.
506
-				update_user_meta( $user_id, '_stripe_source_id', $stripe_source_id );
506
+				update_user_meta($user_id, '_stripe_source_id', $stripe_source_id);
507 507
 			}
508 508
 		}
509 509
 
510 510
 		// If we couldn't find a Stripe customer linked to the account, fallback to the order meta data.
511
-		if ( ( ! $stripe_customer_id || ! is_string( $stripe_customer_id ) ) && false !== $subscription->order ) {
512
-			$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 );
513
-			$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 );
511
+		if (( ! $stripe_customer_id || ! is_string($stripe_customer_id)) && false !== $subscription->order) {
512
+			$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);
513
+			$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);
514 514
 
515 515
 			// For BW compat will remove in future.
516
-			if ( empty( $stripe_source_id ) ) {
517
-				$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 );
516
+			if (empty($stripe_source_id)) {
517
+				$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);
518 518
 
519 519
 				// Take this opportunity to update the key name.
520
-				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 );
520
+				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);
521 521
 			}
522 522
 		}
523 523
 
524
-		$stripe_customer->set_id( $stripe_customer_id );
524
+		$stripe_customer->set_id($stripe_customer_id);
525 525
 
526 526
 		$sources                   = $stripe_customer->get_sources();
527
-		$payment_method_to_display = __( 'N/A', 'woocommerce-gateway-stripe' );
527
+		$payment_method_to_display = __('N/A', 'woocommerce-gateway-stripe');
528 528
 
529
-		if ( $sources ) {
529
+		if ($sources) {
530 530
 			$card = false;
531 531
 
532
-			foreach ( $sources as $source ) {
533
-				if ( isset( $source->type ) && 'card' === $source->type ) {
532
+			foreach ($sources as $source) {
533
+				if (isset($source->type) && 'card' === $source->type) {
534 534
 					$card = $source->card;
535
-				} elseif ( isset( $source->object ) && 'card' === $source->object ) {
535
+				} elseif (isset($source->object) && 'card' === $source->object) {
536 536
 					$card = $source;
537 537
 				}
538 538
 
539
-				if ( $source->id === $stripe_source_id ) {
540
-					if ( $card ) {
539
+				if ($source->id === $stripe_source_id) {
540
+					if ($card) {
541 541
 						/* translators: 1) card brand 2) last 4 digits */
542
-						$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 );
542
+						$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);
543 543
 					}
544 544
 
545 545
 					break;
@@ -556,7 +556,7 @@  discard block
 block discarded – undo
556 556
 	 */
557 557
 	public function remove_order_pay_var() {
558 558
 		global $wp;
559
-		if ( isset( $_GET['wc-stripe-confirmation'] ) ) {
559
+		if (isset($_GET['wc-stripe-confirmation'])) {
560 560
 			$this->order_pay_var = $wp->query_vars['order-pay'];
561 561
 			$wp->query_vars['order-pay'] = null;
562 562
 		}
@@ -567,7 +567,7 @@  discard block
 block discarded – undo
567 567
 	 */
568 568
 	public function restore_order_pay_var() {
569 569
 		global $wp;
570
-		if ( isset( $this->order_pay_var ) ) {
570
+		if (isset($this->order_pay_var)) {
571 571
 			$wp->query_vars['order-pay'] = $this->order_pay_var;
572 572
 		}
573 573
 	}
@@ -578,13 +578,13 @@  discard block
 block discarded – undo
578 578
 	 * @param WC_Order $renewal_order The renewal order.
579 579
 	 * @return boolean
580 580
 	 */
581
-	public function has_authentication_already_failed( $renewal_order ) {
582
-		$existing_intent = $this->get_intent_from_order( $renewal_order );
581
+	public function has_authentication_already_failed($renewal_order) {
582
+		$existing_intent = $this->get_intent_from_order($renewal_order);
583 583
 
584 584
 		if (
585 585
 			! $existing_intent
586 586
 			|| 'requires_payment_method' !== $existing_intent->status
587
-			|| empty( $existing_intent->last_payment_error )
587
+			|| empty($existing_intent->last_payment_error)
588 588
 			|| 'authentication_required' !== $existing_intent->last_payment_error->code
589 589
 		) {
590 590
 			return false;
@@ -598,12 +598,12 @@  discard block
 block discarded – undo
598 598
 		 *
599 599
 		 * @param WC_Order $renewal_order The order that is being renewed.
600 600
 		 */
601
-		do_action( 'wc_gateway_stripe_process_payment_authentication_required', $renewal_order );
601
+		do_action('wc_gateway_stripe_process_payment_authentication_required', $renewal_order);
602 602
 
603 603
 		// Fail the payment attempt (order would be currently pending because of retry rules).
604
-		$charge    = end( $existing_intent->charges->data );
604
+		$charge    = end($existing_intent->charges->data);
605 605
 		$charge_id = $charge->id;
606
-		$renewal_order->update_status( 'failed', sprintf( __( 'Stripe charge awaiting authentication by user: %s.', 'woocommerce-gateway-stripe' ), $charge_id ) );
606
+		$renewal_order->update_status('failed', sprintf(__('Stripe charge awaiting authentication by user: %s.', 'woocommerce-gateway-stripe'), $charge_id));
607 607
 
608 608
 		return true;
609 609
 	}
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.