Completed
Push — master ( 57ddc9...4065b6 )
by Roy
04:18
created
includes/class-wc-stripe-api.php 1 patch
Spacing   +26 added lines, -26 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;
@@ -78,12 +78,12 @@  discard block
 block discarded – undo
78 78
 		$user_agent = self::get_user_agent();
79 79
 		$app_info   = $user_agent['application'];
80 80
 
81
-		return apply_filters( 'woocommerce_stripe_request_headers', array(
82
-			'Authorization'              => 'Basic ' . base64_encode( self::get_secret_key() . ':' ),
81
+		return apply_filters('woocommerce_stripe_request_headers', array(
82
+			'Authorization'              => 'Basic ' . base64_encode(self::get_secret_key() . ':'),
83 83
 			'Stripe-Version'             => self::STRIPE_API_VERSION,
84 84
 			'User-Agent'                 => $app_info['name'] . '/' . $app_info['version'] . ' (' . $app_info['url'] . ')',
85
-			'X-Stripe-Client-User-Agent' => json_encode( $user_agent ),
86
-		) );
85
+			'X-Stripe-Client-User-Agent' => json_encode($user_agent),
86
+		));
87 87
 	}
88 88
 
89 89
 	/**
@@ -95,14 +95,14 @@  discard block
 block discarded – undo
95 95
 	 * @param string $api
96 96
 	 * @return array|WP_Error
97 97
 	 */
98
-	public static function request( $request, $api = 'charges', $method = 'POST' ) {
99
-		WC_Stripe_Logger::log( "{$api} request: " . print_r( $request, true ) );
98
+	public static function request($request, $api = 'charges', $method = 'POST') {
99
+		WC_Stripe_Logger::log("{$api} request: " . print_r($request, true));
100 100
 
101 101
 		$headers = self::get_headers();
102 102
 
103
-		if ( 'charges' === $api && 'POST' === $method ) {
104
-			$customer = ! empty( $request['customer'] ) ? $request['customer'] : '';
105
-			$source   = ! empty( $request['source'] ) ? $request['source'] : $customer;
103
+		if ('charges' === $api && 'POST' === $method) {
104
+			$customer = ! empty($request['customer']) ? $request['customer'] : '';
105
+			$source   = ! empty($request['source']) ? $request['source'] : $customer;
106 106
 
107 107
 			$headers['Idempotency-Key'] = $request['metadata']['order_id'] . '-' . $source;
108 108
 		}
@@ -112,17 +112,17 @@  discard block
 block discarded – undo
112 112
 			array(
113 113
 				'method'  => $method,
114 114
 				'headers' => $headers,
115
-				'body'    => apply_filters( 'woocommerce_stripe_request_body', $request, $api ),
115
+				'body'    => apply_filters('woocommerce_stripe_request_body', $request, $api),
116 116
 				'timeout' => 70,
117 117
 			)
118 118
 		);
119 119
 
120
-		if ( is_wp_error( $response ) || empty( $response['body'] ) ) {
121
-			WC_Stripe_Logger::log( 'Error Response: ' . print_r( $response, true ) );
122
-			throw new WC_Stripe_Exception( print_r( $response, true ), __( 'There was a problem connecting to the Stripe API endpoint.', 'woocommerce-gateway-stripe' ) );
120
+		if (is_wp_error($response) || empty($response['body'])) {
121
+			WC_Stripe_Logger::log('Error Response: ' . print_r($response, true));
122
+			throw new WC_Stripe_Exception(print_r($response, true), __('There was a problem connecting to the Stripe API endpoint.', 'woocommerce-gateway-stripe'));
123 123
 		}
124 124
 
125
-		return json_decode( $response['body'] );
125
+		return json_decode($response['body']);
126 126
 	}
127 127
 
128 128
 	/**
@@ -132,8 +132,8 @@  discard block
 block discarded – undo
132 132
 	 * @version 4.0.0
133 133
 	 * @param string $api
134 134
 	 */
135
-	public static function retrieve( $api ) {
136
-		WC_Stripe_Logger::log( "{$api}" );
135
+	public static function retrieve($api) {
136
+		WC_Stripe_Logger::log("{$api}");
137 137
 
138 138
 		$response = wp_safe_remote_get(
139 139
 			self::ENDPOINT . $api,
@@ -144,11 +144,11 @@  discard block
 block discarded – undo
144 144
 			)
145 145
 		);
146 146
 
147
-		if ( is_wp_error( $response ) || empty( $response['body'] ) ) {
148
-			WC_Stripe_Logger::log( 'Error Response: ' . print_r( $response, true ) );
149
-			return new WP_Error( 'stripe_error', __( 'There was a problem connecting to the Stripe API endpoint.', 'woocommerce-gateway-stripe' ) );
147
+		if (is_wp_error($response) || empty($response['body'])) {
148
+			WC_Stripe_Logger::log('Error Response: ' . print_r($response, true));
149
+			return new WP_Error('stripe_error', __('There was a problem connecting to the Stripe API endpoint.', 'woocommerce-gateway-stripe'));
150 150
 		}
151 151
 
152
-		return json_decode( $response['body'] );
152
+		return json_decode($response['body']);
153 153
 	}
154 154
 }
Please login to merge, or discard this patch.
includes/class-wc-stripe-webhook-handler.php 1 patch
Spacing   +157 added lines, -157 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
 
@@ -20,7 +20,7 @@  discard block
 block discarded – undo
20 20
 	 */
21 21
 	public function __construct() {
22 22
 		$this->retry_interval = 2;
23
-		add_action( 'woocommerce_api_wc_stripe', array( $this, 'check_for_webhook' ) );
23
+		add_action('woocommerce_api_wc_stripe', array($this, 'check_for_webhook'));
24 24
 	}
25 25
 
26 26
 	/**
@@ -30,24 +30,24 @@  discard block
 block discarded – undo
30 30
 	 * @version 4.0.0
31 31
 	 */
32 32
 	public function check_for_webhook() {
33
-		if ( ( 'POST' !== $_SERVER['REQUEST_METHOD'] )
34
-			|| ! isset( $_GET['wc-api'] )
35
-			|| ( 'wc_stripe' !== $_GET['wc-api'] )
33
+		if (('POST' !== $_SERVER['REQUEST_METHOD'])
34
+			|| ! isset($_GET['wc-api'])
35
+			|| ('wc_stripe' !== $_GET['wc-api'])
36 36
 		) {
37 37
 			return;
38 38
 		}
39 39
 
40
-		$request_body    = file_get_contents( 'php://input' );
41
-		$request_headers = array_change_key_case( $this->get_request_headers(), CASE_UPPER );
40
+		$request_body    = file_get_contents('php://input');
41
+		$request_headers = array_change_key_case($this->get_request_headers(), CASE_UPPER);
42 42
 
43 43
 		// Validate it to make sure it is legit.
44
-		if ( $this->is_valid_request( $request_headers, $request_body ) ) {
45
-			$this->process_webhook( $request_body );
46
-			status_header( 200 );
44
+		if ($this->is_valid_request($request_headers, $request_body)) {
45
+			$this->process_webhook($request_body);
46
+			status_header(200);
47 47
 			exit;
48 48
 		} else {
49
-			WC_Stripe_Logger::log( 'Incoming webhook failed validation: ' . print_r( $request_body, true ) );
50
-			status_header( 400 );
49
+			WC_Stripe_Logger::log('Incoming webhook failed validation: ' . print_r($request_body, true));
50
+			status_header(400);
51 51
 			exit;
52 52
 		}
53 53
 	}
@@ -62,12 +62,12 @@  discard block
 block discarded – undo
62 62
 	 * @param string $request_body The request body from Stripe.
63 63
 	 * @return bool
64 64
 	 */
65
-	public function is_valid_request( $request_headers = null, $request_body = null ) {
66
-		if ( null === $request_headers || null === $request_body ) {
65
+	public function is_valid_request($request_headers = null, $request_body = null) {
66
+		if (null === $request_headers || null === $request_body) {
67 67
 			return false;
68 68
 		}
69 69
 
70
-		if ( ! empty( $request_headers['USER-AGENT'] ) && ! preg_match( '/Stripe/', $request_headers['USER-AGENT'] ) ) {
70
+		if ( ! empty($request_headers['USER-AGENT']) && ! preg_match('/Stripe/', $request_headers['USER-AGENT'])) {
71 71
 			return false;
72 72
 		}
73 73
 
@@ -83,11 +83,11 @@  discard block
 block discarded – undo
83 83
 	 * @version 4.0.0
84 84
 	 */
85 85
 	public function get_request_headers() {
86
-		if ( ! function_exists( 'getallheaders' ) ) {
86
+		if ( ! function_exists('getallheaders')) {
87 87
 			$headers = [];
88
-			foreach ( $_SERVER as $name => $value ) {
89
-				if ( 'HTTP_' === substr( $name, 0, 5 ) ) {
90
-					$headers[ str_replace( ' ', '-', ucwords( strtolower( str_replace( '_', ' ', substr( $name, 5 ) ) ) ) ) ] = $value;
88
+			foreach ($_SERVER as $name => $value) {
89
+				if ('HTTP_' === substr($name, 0, 5)) {
90
+					$headers[str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', substr($name, 5)))))] = $value;
91 91
 				}
92 92
 			}
93 93
 
@@ -106,30 +106,30 @@  discard block
 block discarded – undo
106 106
 	 * @param object $notification
107 107
 	 * @param bool $retry
108 108
 	 */
109
-	public function process_webhook_payment( $notification, $retry = true ) {
109
+	public function process_webhook_payment($notification, $retry = true) {
110 110
 		// The following 2 payment methods are synchronous so does not need to be handle via webhook.
111
-		if ( 'card' === $notification->data->object->type || 'sepa_debit' === $notification->data->object->type ) {
111
+		if ('card' === $notification->data->object->type || 'sepa_debit' === $notification->data->object->type) {
112 112
 			return;
113 113
 		}
114 114
 
115
-		$order = WC_Stripe_Helper::get_order_by_source_id( $notification->data->object->id );
115
+		$order = WC_Stripe_Helper::get_order_by_source_id($notification->data->object->id);
116 116
 
117
-		if ( ! $order ) {
118
-			WC_Stripe_Logger::log( 'Could not find order via source ID: ' . $notification->data->object->id );
117
+		if ( ! $order) {
118
+			WC_Stripe_Logger::log('Could not find order via source ID: ' . $notification->data->object->id);
119 119
 			return;
120 120
 		}
121 121
 
122 122
 		$order_id  = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
123 123
 		$source_id = $notification->data->object->id;
124 124
 
125
-		$is_pending_receiver = ( 'receiver' === $notification->data->object->flow );
125
+		$is_pending_receiver = ('receiver' === $notification->data->object->flow);
126 126
 
127 127
 		try {
128
-			if ( 'processing' === $order->get_status() || 'completed' === $order->get_status() ) {
128
+			if ('processing' === $order->get_status() || 'completed' === $order->get_status()) {
129 129
 				return;
130 130
 			}
131 131
 
132
-			if ( 'on-hold' === $order->get_status() && ! $is_pending_receiver ) {
132
+			if ('on-hold' === $order->get_status() && ! $is_pending_receiver) {
133 133
 				return;
134 134
 			}
135 135
 
@@ -137,100 +137,100 @@  discard block
 block discarded – undo
137 137
 			$response = null;
138 138
 
139 139
 			// This will throw exception if not valid.
140
-			$this->validate_minimum_order_amount( $order );
140
+			$this->validate_minimum_order_amount($order);
141 141
 
142
-			WC_Stripe_Logger::log( "Info: (Webhook) Begin processing payment for order $order_id for the amount of {$order->get_total()}" );
142
+			WC_Stripe_Logger::log("Info: (Webhook) Begin processing payment for order $order_id for the amount of {$order->get_total()}");
143 143
 
144 144
 			// Prep source object.
145 145
 			$source_object           = new stdClass();
146 146
 			$source_object->token_id = '';
147
-			$source_object->customer = $this->get_stripe_customer_id( $order );
147
+			$source_object->customer = $this->get_stripe_customer_id($order);
148 148
 			$source_object->source   = $source_id;
149 149
 
150 150
 			// Make the request.
151
-			$response = WC_Stripe_API::request( $this->generate_payment_request( $order, $source_object ) );
151
+			$response = WC_Stripe_API::request($this->generate_payment_request($order, $source_object));
152 152
 
153
-			if ( ! empty( $response->error ) ) {
153
+			if ( ! empty($response->error)) {
154 154
 				// If it is an API error such connection or server, let's retry.
155
-				if ( 'api_connection_error' === $response->error->type || 'api_error' === $response->error->type ) {
156
-					if ( $retry ) {
157
-						sleep( 5 );
158
-						return $this->process_webhook_payment( $notification, false );
155
+				if ('api_connection_error' === $response->error->type || 'api_error' === $response->error->type) {
156
+					if ($retry) {
157
+						sleep(5);
158
+						return $this->process_webhook_payment($notification, false);
159 159
 					} else {
160 160
 						$localized_message = 'API connection error and retries exhausted.';
161
-						$order->add_order_note( $localized_message );
162
-						throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message );
161
+						$order->add_order_note($localized_message);
162
+						throw new WC_Stripe_Exception(print_r($response, true), $localized_message);
163 163
 					}
164 164
 				}
165 165
 
166 166
 				// We want to retry.
167
-				if ( $this->is_retryable_error( $response->error ) ) {
168
-					if ( $retry ) {
167
+				if ($this->is_retryable_error($response->error)) {
168
+					if ($retry) {
169 169
 						// Don't do anymore retries after this.
170
-						if ( 5 <= $this->retry_interval ) {
170
+						if (5 <= $this->retry_interval) {
171 171
 
172
-							return $this->process_webhook_payment( $notification, false );
172
+							return $this->process_webhook_payment($notification, false);
173 173
 						}
174 174
 
175
-						sleep( $this->retry_interval );
175
+						sleep($this->retry_interval);
176 176
 
177 177
 						$this->retry_interval++;
178
-						return $this->process_webhook_payment( $notification, true );
178
+						return $this->process_webhook_payment($notification, true);
179 179
 					} else {
180
-						$localized_message = __( 'On going requests error and retries exhausted.', 'woocommerce-gateway-stripe' );
181
-						$order->add_order_note( $localized_message );
182
-						throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message );
180
+						$localized_message = __('On going requests error and retries exhausted.', 'woocommerce-gateway-stripe');
181
+						$order->add_order_note($localized_message);
182
+						throw new WC_Stripe_Exception(print_r($response, true), $localized_message);
183 183
 					}
184 184
 				}
185 185
 
186 186
 				// Customer param wrong? The user may have been deleted on stripe's end. Remove customer_id. Can be retried without.
187
-				if ( preg_match( '/No such customer/i', $response->error->message ) && $retry ) {
188
-					if ( WC_Stripe_Helper::is_pre_30() ) {
189
-						delete_user_meta( $order->customer_user, '_stripe_customer_id' );
190
-						delete_post_meta( $order_id, '_stripe_customer_id' );
187
+				if (preg_match('/No such customer/i', $response->error->message) && $retry) {
188
+					if (WC_Stripe_Helper::is_pre_30()) {
189
+						delete_user_meta($order->customer_user, '_stripe_customer_id');
190
+						delete_post_meta($order_id, '_stripe_customer_id');
191 191
 					} else {
192
-						delete_user_meta( $order->get_customer_id(), '_stripe_customer_id' );
193
-						$order->delete_meta_data( '_stripe_customer_id' );
192
+						delete_user_meta($order->get_customer_id(), '_stripe_customer_id');
193
+						$order->delete_meta_data('_stripe_customer_id');
194 194
 						$order->save();
195 195
 					}
196 196
 
197
-					return $this->process_webhook_payment( $notification, false );
197
+					return $this->process_webhook_payment($notification, false);
198 198
 
199
-				} elseif ( preg_match( '/No such token/i', $response->error->message ) && $source_object->token_id ) {
199
+				} elseif (preg_match('/No such token/i', $response->error->message) && $source_object->token_id) {
200 200
 					// Source param wrong? The CARD may have been deleted on stripe's end. Remove token and show message.
201
-					$wc_token = WC_Payment_Tokens::get( $source_object->token_id );
201
+					$wc_token = WC_Payment_Tokens::get($source_object->token_id);
202 202
 					$wc_token->delete();
203
-					$message = __( 'This card is no longer available and has been removed.', 'woocommerce-gateway-stripe' );
204
-					$order->add_order_note( $message );
205
-					throw new WC_Stripe_Exception( print_r( $response, true ), $message );
203
+					$message = __('This card is no longer available and has been removed.', 'woocommerce-gateway-stripe');
204
+					$order->add_order_note($message);
205
+					throw new WC_Stripe_Exception(print_r($response, true), $message);
206 206
 				}
207 207
 
208 208
 				$localized_messages = WC_Stripe_Helper::get_localized_messages();
209 209
 
210
-				if ( 'card_error' === $response->error->type ) {
211
-					$localized_message = isset( $localized_messages[ $response->error->code ] ) ? $localized_messages[ $response->error->code ] : $response->error->message;
210
+				if ('card_error' === $response->error->type) {
211
+					$localized_message = isset($localized_messages[$response->error->code]) ? $localized_messages[$response->error->code] : $response->error->message;
212 212
 				} else {
213
-					$localized_message = isset( $localized_messages[ $response->error->type ] ) ? $localized_messages[ $response->error->type ] : $response->error->message;
213
+					$localized_message = isset($localized_messages[$response->error->type]) ? $localized_messages[$response->error->type] : $response->error->message;
214 214
 				}
215 215
 
216
-				$order->add_order_note( $localized_message );
216
+				$order->add_order_note($localized_message);
217 217
 
218
-				throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message );
218
+				throw new WC_Stripe_Exception(print_r($response, true), $localized_message);
219 219
 			}
220 220
 
221
-			do_action( 'wc_gateway_stripe_process_webhook_payment', $response, $order );
221
+			do_action('wc_gateway_stripe_process_webhook_payment', $response, $order);
222 222
 
223
-			$this->process_response( $response, $order );
223
+			$this->process_response($response, $order);
224 224
 
225
-		} catch ( WC_Stripe_Exception $e ) {
226
-			WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() );
225
+		} catch (WC_Stripe_Exception $e) {
226
+			WC_Stripe_Logger::log('Error: ' . $e->getMessage());
227 227
 
228
-			do_action( 'wc_gateway_stripe_process_webhook_payment_error', $e, $order );
228
+			do_action('wc_gateway_stripe_process_webhook_payment_error', $e, $order);
229 229
 
230
-			$statuses = array( 'pending', 'failed' );
230
+			$statuses = array('pending', 'failed');
231 231
 
232
-			if ( $order->has_status( $statuses ) ) {
233
-				$this->send_failed_order_email( $order_id );
232
+			if ($order->has_status($statuses)) {
233
+				$this->send_failed_order_email($order_id);
234 234
 			}
235 235
 		}
236 236
 	}
@@ -243,20 +243,20 @@  discard block
 block discarded – undo
243 243
 	 * @since 4.0.0
244 244
 	 * @param object $notification
245 245
 	 */
246
-	public function process_webhook_dispute( $notification ) {
247
-		$order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->charge );
246
+	public function process_webhook_dispute($notification) {
247
+		$order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->charge);
248 248
 
249
-		if ( ! $order ) {
250
-			WC_Stripe_Logger::log( 'Could not find order via charge ID: ' . $notification->data->object->charge );
249
+		if ( ! $order) {
250
+			WC_Stripe_Logger::log('Could not find order via charge ID: ' . $notification->data->object->charge);
251 251
 			return;
252 252
 		}
253 253
 
254
-		$order->update_status( 'on-hold', __( 'A dispute was created for this order. Response is needed. Please go to your Stripe Dashboard to review this dispute.', 'woocommerce-gateway-stripe' ) );
254
+		$order->update_status('on-hold', __('A dispute was created for this order. Response is needed. Please go to your Stripe Dashboard to review this dispute.', 'woocommerce-gateway-stripe'));
255 255
 
256
-		do_action( 'wc_gateway_stripe_process_webhook_payment_error', $order, $notification );
256
+		do_action('wc_gateway_stripe_process_webhook_payment_error', $order, $notification);
257 257
 
258 258
 		$order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
259
-		$this->send_failed_order_email( $order_id );
259
+		$this->send_failed_order_email($order_id);
260 260
 	}
261 261
 
262 262
 	/**
@@ -267,41 +267,41 @@  discard block
 block discarded – undo
267 267
 	 * @version 4.0.0
268 268
 	 * @param object $notification
269 269
 	 */
270
-	public function process_webhook_capture( $notification ) {
271
-		$order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->id );
270
+	public function process_webhook_capture($notification) {
271
+		$order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->id);
272 272
 
273
-		if ( ! $order ) {
274
-			WC_Stripe_Logger::log( 'Could not find order via charge ID: ' . $notification->data->object->id );
273
+		if ( ! $order) {
274
+			WC_Stripe_Logger::log('Could not find order via charge ID: ' . $notification->data->object->id);
275 275
 			return;
276 276
 		}
277 277
 
278 278
 		$order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
279 279
 
280
-		if ( 'stripe' === ( WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method() ) ) {
281
-			$charge   = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_transaction_id', true ) : $order->get_transaction_id();
282
-			$captured = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_stripe_charge_captured', true ) : $order->get_meta( '_stripe_charge_captured', true );
280
+		if ('stripe' === (WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method())) {
281
+			$charge   = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_transaction_id', true) : $order->get_transaction_id();
282
+			$captured = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_stripe_charge_captured', true) : $order->get_meta('_stripe_charge_captured', true);
283 283
 
284
-			if ( $charge && 'no' === $captured ) {
285
-				WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, '_stripe_charge_captured', 'yes' ) : $order->update_meta_data( '_stripe_charge_captured', 'yes' );
284
+			if ($charge && 'no' === $captured) {
285
+				WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, '_stripe_charge_captured', 'yes') : $order->update_meta_data('_stripe_charge_captured', 'yes');
286 286
 
287 287
 				// Store other data such as fees
288
-				WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, '_transaction_id', $notification->data->object->id ) : $order->set_transaction_id( $notification->data->object->id );
288
+				WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, '_transaction_id', $notification->data->object->id) : $order->set_transaction_id($notification->data->object->id);
289 289
 
290
-				if ( isset( $notification->data->object->balance_transaction ) ) {
291
-					$this->update_fees( $order, $notification->data->object->balance_transaction );
290
+				if (isset($notification->data->object->balance_transaction)) {
291
+					$this->update_fees($order, $notification->data->object->balance_transaction);
292 292
 				}
293 293
 
294
-				if ( is_callable( array( $order, 'save' ) ) ) {
294
+				if (is_callable(array($order, 'save'))) {
295 295
 					$order->save();
296 296
 				}
297 297
 
298 298
 				/* translators: transaction id */
299
-				$order->update_status( $order->needs_processing() ? 'processing' : 'completed', sprintf( __( 'Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe' ), $notification->data->object->id ) );
299
+				$order->update_status($order->needs_processing() ? 'processing' : 'completed', sprintf(__('Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe'), $notification->data->object->id));
300 300
 
301 301
 				// Check and see if capture is partial.
302
-				if ( $this->is_partial_capture( $notification ) ) {
303
-					$order->set_total( $this->get_partial_amount_to_charge( $notification ) );
304
-					$order->add_note( __( 'This charge was partially captured via Stripe Dashboard', 'woocommerce-gateway-stripe' ) );
302
+				if ($this->is_partial_capture($notification)) {
303
+					$order->set_total($this->get_partial_amount_to_charge($notification));
304
+					$order->add_note(__('This charge was partially captured via Stripe Dashboard', 'woocommerce-gateway-stripe'));
305 305
 					$order->save();
306 306
 				}
307 307
 			}
@@ -316,38 +316,38 @@  discard block
 block discarded – undo
316 316
 	 * @version 4.0.0
317 317
 	 * @param object $notification
318 318
 	 */
319
-	public function process_webhook_charge_succeeded( $notification ) {
319
+	public function process_webhook_charge_succeeded($notification) {
320 320
 		// The following payment methods are synchronous so does not need to be handle via webhook.
321
-		if ( ( isset( $notification->data->object->source->type ) && 'card' === $notification->data->object->source->type ) || ( isset( $notification->data->object->source->type ) && 'three_d_secure' === $notification->data->object->source->type ) ) {
321
+		if ((isset($notification->data->object->source->type) && 'card' === $notification->data->object->source->type) || (isset($notification->data->object->source->type) && 'three_d_secure' === $notification->data->object->source->type)) {
322 322
 			return;
323 323
 		}
324 324
 
325
-		$order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->id );
325
+		$order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->id);
326 326
 
327
-		if ( ! $order ) {
328
-			WC_Stripe_Logger::log( 'Could not find order via charge ID: ' . $notification->data->object->id );
327
+		if ( ! $order) {
328
+			WC_Stripe_Logger::log('Could not find order via charge ID: ' . $notification->data->object->id);
329 329
 			return;
330 330
 		}
331 331
 
332 332
 		$order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
333 333
 
334
-		if ( 'on-hold' !== $order->get_status() ) {
334
+		if ('on-hold' !== $order->get_status()) {
335 335
 			return;
336 336
 		}
337 337
 
338 338
 		// Store other data such as fees
339
-		WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, '_transaction_id', $notification->data->object->id ) : $order->set_transaction_id( $notification->data->object->id );
339
+		WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, '_transaction_id', $notification->data->object->id) : $order->set_transaction_id($notification->data->object->id);
340 340
 
341
-		if ( isset( $notification->data->object->balance_transaction ) ) {
342
-			$this->update_fees( $order, $notification->data->object->balance_transaction );
341
+		if (isset($notification->data->object->balance_transaction)) {
342
+			$this->update_fees($order, $notification->data->object->balance_transaction);
343 343
 		}
344 344
 
345
-		if ( is_callable( array( $order, 'save' ) ) ) {
345
+		if (is_callable(array($order, 'save'))) {
346 346
 			$order->save();
347 347
 		}
348 348
 
349 349
 		/* translators: transaction id */
350
-		$order->update_status( $order->needs_processing() ? 'processing' : 'completed', sprintf( __( 'Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe' ), $notification->data->object->id ) );
350
+		$order->update_status($order->needs_processing() ? 'processing' : 'completed', sprintf(__('Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe'), $notification->data->object->id));
351 351
 	}
352 352
 
353 353
 	/**
@@ -358,23 +358,23 @@  discard block
 block discarded – undo
358 358
 	 * @version 4.0.0
359 359
 	 * @param object $notification
360 360
 	 */
361
-	public function process_webhook_charge_failed( $notification ) {
362
-		$order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->id );
361
+	public function process_webhook_charge_failed($notification) {
362
+		$order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->id);
363 363
 
364
-		if ( ! $order ) {
365
-			WC_Stripe_Logger::log( 'Could not find order via charge ID: ' . $notification->data->object->id );
364
+		if ( ! $order) {
365
+			WC_Stripe_Logger::log('Could not find order via charge ID: ' . $notification->data->object->id);
366 366
 			return;
367 367
 		}
368 368
 
369 369
 		$order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
370 370
 
371
-		if ( 'on-hold' !== $order->get_status() ) {
371
+		if ('on-hold' !== $order->get_status()) {
372 372
 			return;
373 373
 		}
374 374
 
375
-		$order->update_status( 'failed', __( 'This payment failed to clear.', 'woocommerce-gateway-stripe' ) );
375
+		$order->update_status('failed', __('This payment failed to clear.', 'woocommerce-gateway-stripe'));
376 376
 
377
-		do_action( 'wc_gateway_stripe_process_webhook_payment_error', $order, $notification );
377
+		do_action('wc_gateway_stripe_process_webhook_payment_error', $order, $notification);
378 378
 	}
379 379
 
380 380
 	/**
@@ -385,23 +385,23 @@  discard block
 block discarded – undo
385 385
 	 * @version 4.0.0
386 386
 	 * @param object $notification
387 387
 	 */
388
-	public function process_webhook_source_canceled( $notification ) {
389
-		$order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->id );
388
+	public function process_webhook_source_canceled($notification) {
389
+		$order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->id);
390 390
 
391
-		if ( ! $order ) {
392
-			WC_Stripe_Logger::log( 'Could not find order via charge ID: ' . $notification->data->object->id );
391
+		if ( ! $order) {
392
+			WC_Stripe_Logger::log('Could not find order via charge ID: ' . $notification->data->object->id);
393 393
 			return;
394 394
 		}
395 395
 
396 396
 		$order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
397 397
 
398
-		if ( 'on-hold' !== $order->get_status() || 'cancelled' !== $order->get_status() ) {
398
+		if ('on-hold' !== $order->get_status() || 'cancelled' !== $order->get_status()) {
399 399
 			return;
400 400
 		}
401 401
 
402
-		$order->update_status( 'cancelled', __( 'This payment has cancelled.', 'woocommerce-gateway-stripe' ) );
402
+		$order->update_status('cancelled', __('This payment has cancelled.', 'woocommerce-gateway-stripe'));
403 403
 
404
-		do_action( 'wc_gateway_stripe_process_webhook_payment_error', $order, $notification );
404
+		do_action('wc_gateway_stripe_process_webhook_payment_error', $order, $notification);
405 405
 	}
406 406
 
407 407
 	/**
@@ -412,42 +412,42 @@  discard block
 block discarded – undo
412 412
 	 * @version 4.0.0
413 413
 	 * @param object $notification
414 414
 	 */
415
-	public function process_webhook_refund( $notification ) {
416
-		$order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->id );
415
+	public function process_webhook_refund($notification) {
416
+		$order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->id);
417 417
 
418
-		if ( ! $order ) {
419
-			WC_Stripe_Logger::log( 'Could not find order via charge ID: ' . $notification->data->object->id );
418
+		if ( ! $order) {
419
+			WC_Stripe_Logger::log('Could not find order via charge ID: ' . $notification->data->object->id);
420 420
 			return;
421 421
 		}
422 422
 
423 423
 		$order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
424 424
 
425
-		if ( 'stripe' === ( WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method() ) ) {
426
-			$charge    = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_transaction_id', true ) : $order->get_transaction_id();
427
-			$captured  = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_stripe_charge_captured', true ) : $order->get_meta( '_stripe_charge_captured', true );
428
-			$refund_id = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_stripe_refund_id', true ) : $order->get_meta( '_stripe_refund_id', true );
425
+		if ('stripe' === (WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method())) {
426
+			$charge    = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_transaction_id', true) : $order->get_transaction_id();
427
+			$captured  = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_stripe_charge_captured', true) : $order->get_meta('_stripe_charge_captured', true);
428
+			$refund_id = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_stripe_refund_id', true) : $order->get_meta('_stripe_refund_id', true);
429 429
 
430 430
 			// If the refund ID matches, don't continue to prevent double refunding.
431
-			if ( $notification->data->object->refunds->data[0]->id === $refund_id ) {
431
+			if ($notification->data->object->refunds->data[0]->id === $refund_id) {
432 432
 				return;
433 433
 			}
434 434
 
435 435
 			// Only refund captured charge.
436
-			if ( $charge ) {
437
-				$reason = ( isset( $captured ) && 'yes' === $captured ) ? __( 'Refunded via Stripe Dashboard', 'woocommerce-gateway-stripe' ) : __( 'Pre-Authorization Released via Stripe Dashboard', 'woocommerce-gateway-stripe' );
436
+			if ($charge) {
437
+				$reason = (isset($captured) && 'yes' === $captured) ? __('Refunded via Stripe Dashboard', 'woocommerce-gateway-stripe') : __('Pre-Authorization Released via Stripe Dashboard', 'woocommerce-gateway-stripe');
438 438
 
439 439
 				// Create the refund.
440
-				$refund = wc_create_refund( array(
440
+				$refund = wc_create_refund(array(
441 441
 					'order_id'       => $order_id,
442
-					'amount'         => $this->get_refund_amount( $notification ),
442
+					'amount'         => $this->get_refund_amount($notification),
443 443
 					'reason'         => $reason,
444
-				) );
444
+				));
445 445
 
446
-				if ( is_wp_error( $refund ) ) {
447
-					WC_Stripe_Logger::log( $refund->get_error_message() );
446
+				if (is_wp_error($refund)) {
447
+					WC_Stripe_Logger::log($refund->get_error_message());
448 448
 				}
449 449
 
450
-				$order->add_order_note( $reason );
450
+				$order->add_order_note($reason);
451 451
 			}
452 452
 		}
453 453
 	}
@@ -459,7 +459,7 @@  discard block
 block discarded – undo
459 459
 	 * @version 4.0.0
460 460
 	 * @param object $notification
461 461
 	 */
462
-	public function is_partial_capture( $notification ) {
462
+	public function is_partial_capture($notification) {
463 463
 		return 0 < $notification->data->object->amount_refunded;
464 464
 	}
465 465
 
@@ -470,11 +470,11 @@  discard block
 block discarded – undo
470 470
 	 * @version 4.0.0
471 471
 	 * @param object $notification
472 472
 	 */
473
-	public function get_refund_amount( $notification ) {
474
-		if ( $this->is_partial_capture( $notification ) ) {
473
+	public function get_refund_amount($notification) {
474
+		if ($this->is_partial_capture($notification)) {
475 475
 			$amount = $notification->data->object->amount_refunded / 100;
476 476
 
477
-			if ( in_array( strtolower( $notification->data->object->currency ), WC_Stripe_Helper::no_decimal_currencies() ) ) {
477
+			if (in_array(strtolower($notification->data->object->currency), WC_Stripe_Helper::no_decimal_currencies())) {
478 478
 				$amount = $notification->data->object->amount_refunded;
479 479
 			}
480 480
 
@@ -491,12 +491,12 @@  discard block
 block discarded – undo
491 491
 	 * @version 4.0.0
492 492
 	 * @param object $notification
493 493
 	 */
494
-	public function get_partial_amount_to_charge( $notification ) {
495
-		if ( $this->is_partial_capture( $notification ) ) {
496
-			$amount = ( $notification->data->object->amount - $notification->data->object->amount_refunded ) / 100;
494
+	public function get_partial_amount_to_charge($notification) {
495
+		if ($this->is_partial_capture($notification)) {
496
+			$amount = ($notification->data->object->amount - $notification->data->object->amount_refunded) / 100;
497 497
 
498
-			if ( in_array( strtolower( $notification->data->object->currency ), WC_Stripe_Helper::no_decimal_currencies() ) ) {
499
-				$amount = ( $notification->data->object->amount - $notification->data->object->amount_refunded );
498
+			if (in_array(strtolower($notification->data->object->currency), WC_Stripe_Helper::no_decimal_currencies())) {
499
+				$amount = ($notification->data->object->amount - $notification->data->object->amount_refunded);
500 500
 			}
501 501
 
502 502
 			return $amount;
@@ -512,36 +512,36 @@  discard block
 block discarded – undo
512 512
 	 * @version 4.0.0
513 513
 	 * @param string $request_body
514 514
 	 */
515
-	public function process_webhook( $request_body ) {
516
-		$notification = json_decode( $request_body );
515
+	public function process_webhook($request_body) {
516
+		$notification = json_decode($request_body);
517 517
 
518
-		switch ( $notification->type ) {
518
+		switch ($notification->type) {
519 519
 			case 'source.chargeable':
520
-				$this->process_webhook_payment( $notification );
520
+				$this->process_webhook_payment($notification);
521 521
 				break;
522 522
 
523 523
 			case 'source.canceled':
524
-				$this->process_webhook_source_canceled( $notification );
524
+				$this->process_webhook_source_canceled($notification);
525 525
 				break;
526 526
 
527 527
 			case 'charge.succeeded':
528
-				$this->process_webhook_charge_succeeded( $notification );
528
+				$this->process_webhook_charge_succeeded($notification);
529 529
 				break;
530 530
 
531 531
 			case 'charge.failed':
532
-				$this->process_webhook_charge_failed( $notification );
532
+				$this->process_webhook_charge_failed($notification);
533 533
 				break;
534 534
 
535 535
 			case 'charge.captured':
536
-				$this->process_webhook_capture( $notification );
536
+				$this->process_webhook_capture($notification);
537 537
 				break;
538 538
 
539 539
 			case 'charge.dispute.created':
540
-				$this->process_webhook_dispute( $notification );
540
+				$this->process_webhook_dispute($notification);
541 541
 				break;
542 542
 
543 543
 			case 'charge.refunded':
544
-				$this->process_webhook_refund( $notification );
544
+				$this->process_webhook_refund($notification);
545 545
 				break;
546 546
 
547 547
 		}
Please login to merge, or discard this patch.
includes/admin/stripe-settings.php 1 patch
Spacing   +65 added lines, -65 removed lines patch added patch discarded remove patch
@@ -1,184 +1,184 @@
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) {
2
+if ( ! defined('ABSPATH')) {
3 3
 	exit;
4 4
 }
5 5
 
6 6
 $webhook_url = WC_Stripe_Helper::get_webhook_url();
7 7
 
8
-return apply_filters( 'wc_stripe_settings',
8
+return apply_filters('wc_stripe_settings',
9 9
 	array(
10 10
 		'enabled' => array(
11
-			'title'       => __( 'Enable/Disable', 'woocommerce-gateway-stripe' ),
12
-			'label'       => __( 'Enable Stripe', 'woocommerce-gateway-stripe' ),
11
+			'title'       => __('Enable/Disable', 'woocommerce-gateway-stripe'),
12
+			'label'       => __('Enable Stripe', 'woocommerce-gateway-stripe'),
13 13
 			'type'        => 'checkbox',
14 14
 			'description' => '',
15 15
 			'default'     => 'no',
16 16
 		),
17 17
 		'title' => array(
18
-			'title'       => __( 'Title', 'woocommerce-gateway-stripe' ),
18
+			'title'       => __('Title', 'woocommerce-gateway-stripe'),
19 19
 			'type'        => 'text',
20
-			'description' => __( 'This controls the title which the user sees during checkout.', 'woocommerce-gateway-stripe' ),
21
-			'default'     => __( 'Credit Card (Stripe)', 'woocommerce-gateway-stripe' ),
20
+			'description' => __('This controls the title which the user sees during checkout.', 'woocommerce-gateway-stripe'),
21
+			'default'     => __('Credit Card (Stripe)', 'woocommerce-gateway-stripe'),
22 22
 			'desc_tip'    => true,
23 23
 		),
24 24
 		'description' => array(
25
-			'title'       => __( 'Description', 'woocommerce-gateway-stripe' ),
25
+			'title'       => __('Description', 'woocommerce-gateway-stripe'),
26 26
 			'type'        => 'text',
27
-			'description' => __( 'This controls the description which the user sees during checkout.', 'woocommerce-gateway-stripe' ),
28
-			'default'     => __( 'Pay with your credit card via Stripe.', 'woocommerce-gateway-stripe' ),
27
+			'description' => __('This controls the description which the user sees during checkout.', 'woocommerce-gateway-stripe'),
28
+			'default'     => __('Pay with your credit card via Stripe.', 'woocommerce-gateway-stripe'),
29 29
 			'desc_tip'    => true,
30 30
 		),
31 31
 		'webhook' => array(
32
-			'title'       => __( 'Webhook Endpoints', 'woocommerce-gateway-stripe' ),
32
+			'title'       => __('Webhook Endpoints', 'woocommerce-gateway-stripe'),
33 33
 			'type'        => 'title',
34 34
 			/* translators: webhook URL */
35
-			'description' => sprintf( __( 'You must add the webhook endpoint <strong style="background-color:#ddd;">&nbsp;&nbsp;%s&nbsp;&nbsp;</strong> to your Stripe Account Settings <a href="https://dashboard.stripe.com/account/webhooks" target="_blank">Here</a> so you can receive notifications on the charge statuses.', 'woocommerce-gateway-stripe' ), $webhook_url ),
35
+			'description' => sprintf(__('You must add the webhook endpoint <strong style="background-color:#ddd;">&nbsp;&nbsp;%s&nbsp;&nbsp;</strong> to your Stripe Account Settings <a href="https://dashboard.stripe.com/account/webhooks" target="_blank">Here</a> so you can receive notifications on the charge statuses.', 'woocommerce-gateway-stripe'), $webhook_url),
36 36
 		),
37 37
 		'testmode' => array(
38
-			'title'       => __( 'Test mode', 'woocommerce-gateway-stripe' ),
39
-			'label'       => __( 'Enable Test Mode', 'woocommerce-gateway-stripe' ),
38
+			'title'       => __('Test mode', 'woocommerce-gateway-stripe'),
39
+			'label'       => __('Enable Test Mode', 'woocommerce-gateway-stripe'),
40 40
 			'type'        => 'checkbox',
41
-			'description' => __( 'Place the payment gateway in test mode using test API keys.', 'woocommerce-gateway-stripe' ),
41
+			'description' => __('Place the payment gateway in test mode using test API keys.', 'woocommerce-gateway-stripe'),
42 42
 			'default'     => 'yes',
43 43
 			'desc_tip'    => true,
44 44
 		),
45 45
 		'test_publishable_key' => array(
46
-			'title'       => __( 'Test Publishable Key', 'woocommerce-gateway-stripe' ),
46
+			'title'       => __('Test Publishable Key', 'woocommerce-gateway-stripe'),
47 47
 			'type'        => 'password',
48
-			'description' => __( 'Get your API keys from your stripe account.', 'woocommerce-gateway-stripe' ),
48
+			'description' => __('Get your API keys from your stripe account.', 'woocommerce-gateway-stripe'),
49 49
 			'default'     => '',
50 50
 			'desc_tip'    => true,
51 51
 		),
52 52
 		'test_secret_key' => array(
53
-			'title'       => __( 'Test Secret Key', 'woocommerce-gateway-stripe' ),
53
+			'title'       => __('Test Secret Key', 'woocommerce-gateway-stripe'),
54 54
 			'type'        => 'password',
55
-			'description' => __( 'Get your API keys from your stripe account.', 'woocommerce-gateway-stripe' ),
55
+			'description' => __('Get your API keys from your stripe account.', 'woocommerce-gateway-stripe'),
56 56
 			'default'     => '',
57 57
 			'desc_tip'    => true,
58 58
 		),
59 59
 		'publishable_key' => array(
60
-			'title'       => __( 'Live Publishable Key', 'woocommerce-gateway-stripe' ),
60
+			'title'       => __('Live Publishable Key', 'woocommerce-gateway-stripe'),
61 61
 			'type'        => 'password',
62
-			'description' => __( 'Get your API keys from your stripe account.', 'woocommerce-gateway-stripe' ),
62
+			'description' => __('Get your API keys from your stripe account.', 'woocommerce-gateway-stripe'),
63 63
 			'default'     => '',
64 64
 			'desc_tip'    => true,
65 65
 		),
66 66
 		'secret_key' => array(
67
-			'title'       => __( 'Live Secret Key', 'woocommerce-gateway-stripe' ),
67
+			'title'       => __('Live Secret Key', 'woocommerce-gateway-stripe'),
68 68
 			'type'        => 'password',
69
-			'description' => __( 'Get your API keys from your stripe account.', 'woocommerce-gateway-stripe' ),
69
+			'description' => __('Get your API keys from your stripe account.', 'woocommerce-gateway-stripe'),
70 70
 			'default'     => '',
71 71
 			'desc_tip'    => true,
72 72
 		),
73 73
 		'inline_cc_form' => array(
74
-			'title'       => __( 'Inline Credit Card Form', 'woocommerce-gateway-stripe' ),
74
+			'title'       => __('Inline Credit Card Form', 'woocommerce-gateway-stripe'),
75 75
 			'type'        => 'checkbox',
76
-			'description' => __( 'Choose the style you want to show for your credit card form. When unchecked, the credit card form will display separate credit card number field, expiry date field and cvc field.', 'woocommerce-gateway-stripe' ),
76
+			'description' => __('Choose the style you want to show for your credit card form. When unchecked, the credit card form will display separate credit card number field, expiry date field and cvc field.', 'woocommerce-gateway-stripe'),
77 77
 			'default'     => 'no',
78 78
 			'desc_tip'    => true,
79 79
 		),
80 80
 		'statement_descriptor' => array(
81
-			'title'       => __( 'Statement Descriptor', 'woocommerce-gateway-stripe' ),
81
+			'title'       => __('Statement Descriptor', 'woocommerce-gateway-stripe'),
82 82
 			'type'        => 'text',
83
-			'description' => __( 'This may be up to 22 characters. The statement description must contain at least one letter, may not include ><"\' characters, and will appear on your customer\'s statement in capital letters.', 'woocommerce-gateway-stripe' ),
83
+			'description' => __('This may be up to 22 characters. The statement description must contain at least one letter, may not include ><"\' characters, and will appear on your customer\'s statement in capital letters.', 'woocommerce-gateway-stripe'),
84 84
 			'default'     => '',
85 85
 			'desc_tip'    => true,
86 86
 		),
87 87
 		'capture' => array(
88
-			'title'       => __( 'Capture', 'woocommerce-gateway-stripe' ),
89
-			'label'       => __( 'Capture charge immediately', 'woocommerce-gateway-stripe' ),
88
+			'title'       => __('Capture', 'woocommerce-gateway-stripe'),
89
+			'label'       => __('Capture charge immediately', 'woocommerce-gateway-stripe'),
90 90
 			'type'        => 'checkbox',
91
-			'description' => __( 'Whether or not to immediately capture the charge. When unchecked, the charge issues an authorization and will need to be captured later. Uncaptured charges expire in 7 days.', 'woocommerce-gateway-stripe' ),
91
+			'description' => __('Whether or not to immediately capture the charge. When unchecked, the charge issues an authorization and will need to be captured later. Uncaptured charges expire in 7 days.', 'woocommerce-gateway-stripe'),
92 92
 			'default'     => 'yes',
93 93
 			'desc_tip'    => true,
94 94
 		),
95 95
 		'three_d_secure' => array(
96
-			'title'       => __( '3D Secure', 'woocommerce-gateway-stripe' ),
97
-			'label'       => __( 'Require 3D Secure when applicable', 'woocommerce-gateway-stripe' ),
96
+			'title'       => __('3D Secure', 'woocommerce-gateway-stripe'),
97
+			'label'       => __('Require 3D Secure when applicable', 'woocommerce-gateway-stripe'),
98 98
 			'type'        => 'checkbox',
99
-			'description' => __( 'Some payment methods have 3D Secure feature. This is an extra security layer for your store. Choose how to handle payments when 3D Secure is optional. Enabling would require customers to use 3D Secure when optional.', 'woocommerce-gateway-stripe' ),
99
+			'description' => __('Some payment methods have 3D Secure feature. This is an extra security layer for your store. Choose how to handle payments when 3D Secure is optional. Enabling would require customers to use 3D Secure when optional.', 'woocommerce-gateway-stripe'),
100 100
 			'default'     => 'no',
101 101
 			'desc_tip'    => true,
102 102
 		),
103 103
 		'stripe_checkout' => array(
104
-			'title'       => __( 'Stripe Checkout', 'woocommerce-gateway-stripe' ),
105
-			'label'       => __( 'Enable Stripe Checkout', 'woocommerce-gateway-stripe' ),
104
+			'title'       => __('Stripe Checkout', 'woocommerce-gateway-stripe'),
105
+			'label'       => __('Enable Stripe Checkout', 'woocommerce-gateway-stripe'),
106 106
 			'type'        => 'checkbox',
107
-			'description' => __( 'If enabled, this option shows a "pay" button and modal credit card form on the checkout, instead of credit card fields directly on the page.', 'woocommerce-gateway-stripe' ),
107
+			'description' => __('If enabled, this option shows a "pay" button and modal credit card form on the checkout, instead of credit card fields directly on the page.', 'woocommerce-gateway-stripe'),
108 108
 			'default'     => 'no',
109 109
 			'desc_tip'    => true,
110 110
 		),
111 111
 		'stripe_bitcoin' => array(
112
-			'title'       => __( 'Bitcoin Currency', 'woocommerce-gateway-stripe' ),
113
-			'label'       => __( 'Enable Bitcoin Currency', 'woocommerce-gateway-stripe' ),
112
+			'title'       => __('Bitcoin Currency', 'woocommerce-gateway-stripe'),
113
+			'label'       => __('Enable Bitcoin Currency', 'woocommerce-gateway-stripe'),
114 114
 			'type'        => 'checkbox',
115
-			'description' => __( 'If enabled, an option to accept bitcoin will show on the checkout modal. Note: Stripe Checkout needs to be enabled and store currency must be set to USD.', 'woocommerce-gateway-stripe' ),
115
+			'description' => __('If enabled, an option to accept bitcoin will show on the checkout modal. Note: Stripe Checkout needs to be enabled and store currency must be set to USD.', 'woocommerce-gateway-stripe'),
116 116
 			'default'     => 'no',
117 117
 			'desc_tip'    => true,
118 118
 		),
119 119
 		'stripe_checkout_image' => array(
120
-			'title'       => __( 'Stripe Checkout Image', 'woocommerce-gateway-stripe' ),
121
-			'description' => __( 'Optionally enter the URL to a 128x128px image of your brand or product. e.g. <code>https://yoursite.com/wp-content/uploads/2013/09/yourimage.jpg</code>', 'woocommerce-gateway-stripe' ),
120
+			'title'       => __('Stripe Checkout Image', 'woocommerce-gateway-stripe'),
121
+			'description' => __('Optionally enter the URL to a 128x128px image of your brand or product. e.g. <code>https://yoursite.com/wp-content/uploads/2013/09/yourimage.jpg</code>', 'woocommerce-gateway-stripe'),
122 122
 			'type'        => 'text',
123 123
 			'default'     => '',
124 124
 			'desc_tip'    => true,
125 125
 		),
126 126
 		'payment_request' => array(
127
-			'title'       => __( 'Payment Request Buttons', 'woocommerce-gateway-stripe' ),
127
+			'title'       => __('Payment Request Buttons', 'woocommerce-gateway-stripe'),
128 128
 			/* translators: 1) br tag 2) opening anchor tag 3) closing anchor tag */
129
-			'label'       => sprintf( __( 'Enable Payment Request Buttons. (Apple Pay/Chrome Payment Request API) %1$sBy using Apple Pay, you agree to %2$s and %3$s\'s terms of service.', 'woocommerce-gateway-stripe' ), '<br />', '<a href="https://stripe.com/apple-pay/legal" target="_blank">Stripe</a>', '<a href="https://developer.apple.com/apple-pay/acceptable-use-guidelines-for-websites/" target="_blank">Apple</a>' ),
129
+			'label'       => sprintf(__('Enable Payment Request Buttons. (Apple Pay/Chrome Payment Request API) %1$sBy using Apple Pay, you agree to %2$s and %3$s\'s terms of service.', 'woocommerce-gateway-stripe'), '<br />', '<a href="https://stripe.com/apple-pay/legal" target="_blank">Stripe</a>', '<a href="https://developer.apple.com/apple-pay/acceptable-use-guidelines-for-websites/" target="_blank">Apple</a>'),
130 130
 			'type'        => 'checkbox',
131
-			'description' => __( 'If enabled, users will be able to pay using Apple Pay or Chrome Payment Request if supported by the browser.', 'woocommerce-gateway-stripe' ),
131
+			'description' => __('If enabled, users will be able to pay using Apple Pay or Chrome Payment Request if supported by the browser.', 'woocommerce-gateway-stripe'),
132 132
 			'default'     => 'yes',
133 133
 			'desc_tip'    => true,
134 134
 		),
135 135
 		'payment_request_button_type' => array(
136
-			'title'       => __( 'Payment Request Button Type', 'woocommerce-gateway-stripe' ),
137
-			'label'       => __( 'Button Type', 'woocommerce-gateway-stripe' ),
136
+			'title'       => __('Payment Request Button Type', 'woocommerce-gateway-stripe'),
137
+			'label'       => __('Button Type', 'woocommerce-gateway-stripe'),
138 138
 			'type'        => 'select',
139
-			'description' => __( 'Select the button type you would like to show.', 'woocommerce-gateway-stripe' ),
139
+			'description' => __('Select the button type you would like to show.', 'woocommerce-gateway-stripe'),
140 140
 			'default'     => 'buy',
141 141
 			'desc_tip'    => true,
142 142
 			'options'     => array(
143
-				'default' => __( 'Default', 'woocommerce-gateway-stripe' ),
144
-				'buy'     => __( 'Buy', 'woocommerce-gateway-stripe' ),
145
-				'donate'  => __( 'Donate', 'woocommerce-gateway-stripe' ),
143
+				'default' => __('Default', 'woocommerce-gateway-stripe'),
144
+				'buy'     => __('Buy', 'woocommerce-gateway-stripe'),
145
+				'donate'  => __('Donate', 'woocommerce-gateway-stripe'),
146 146
 			),
147 147
 		),
148 148
 		'payment_request_button_theme' => array(
149
-			'title'       => __( 'Payment Request Button Theme', 'woocommerce-gateway-stripe' ),
150
-			'label'       => __( 'Button Theme', 'woocommerce-gateway-stripe' ),
149
+			'title'       => __('Payment Request Button Theme', 'woocommerce-gateway-stripe'),
150
+			'label'       => __('Button Theme', 'woocommerce-gateway-stripe'),
151 151
 			'type'        => 'select',
152
-			'description' => __( 'Select the button theme you would like to show.', 'woocommerce-gateway-stripe' ),
152
+			'description' => __('Select the button theme you would like to show.', 'woocommerce-gateway-stripe'),
153 153
 			'default'     => 'dark',
154 154
 			'desc_tip'    => true,
155 155
 			'options'     => array(
156
-				'dark'          => __( 'Dark', 'woocommerce-gateway-stripe' ),
157
-				'light'         => __( 'Light', 'woocommerce-gateway-stripe' ),
158
-				'light-outline' => __( 'Light-Outline', 'woocommerce-gateway-stripe' ),
156
+				'dark'          => __('Dark', 'woocommerce-gateway-stripe'),
157
+				'light'         => __('Light', 'woocommerce-gateway-stripe'),
158
+				'light-outline' => __('Light-Outline', 'woocommerce-gateway-stripe'),
159 159
 			),
160 160
 		),
161 161
 		'payment_request_button_height' => array(
162
-			'title'       => __( 'Payment Request Button Height', 'woocommerce-gateway-stripe' ),
163
-			'label'       => __( 'Button Height', 'woocommerce-gateway-stripe' ),
162
+			'title'       => __('Payment Request Button Height', 'woocommerce-gateway-stripe'),
163
+			'label'       => __('Button Height', 'woocommerce-gateway-stripe'),
164 164
 			'type'        => 'text',
165
-			'description' => __( 'Enter the height you would like the button to be in pixels. Width will always be 100%.', 'woocommerce-gateway-stripe' ),
165
+			'description' => __('Enter the height you would like the button to be in pixels. Width will always be 100%.', 'woocommerce-gateway-stripe'),
166 166
 			'default'     => '44',
167 167
 			'desc_tip'    => true,
168 168
 		),
169 169
 		'saved_cards' => array(
170
-			'title'       => __( 'Saved Cards', 'woocommerce-gateway-stripe' ),
171
-			'label'       => __( 'Enable Payment via Saved Cards', 'woocommerce-gateway-stripe' ),
170
+			'title'       => __('Saved Cards', 'woocommerce-gateway-stripe'),
171
+			'label'       => __('Enable Payment via Saved Cards', 'woocommerce-gateway-stripe'),
172 172
 			'type'        => 'checkbox',
173
-			'description' => __( 'If enabled, users will be able to pay with a saved card during checkout. Card details are saved on Stripe servers, not on your store.', 'woocommerce-gateway-stripe' ),
173
+			'description' => __('If enabled, users will be able to pay with a saved card during checkout. Card details are saved on Stripe servers, not on your store.', 'woocommerce-gateway-stripe'),
174 174
 			'default'     => 'no',
175 175
 			'desc_tip'    => true,
176 176
 		),
177 177
 		'logging' => array(
178
-			'title'       => __( 'Logging', 'woocommerce-gateway-stripe' ),
179
-			'label'       => __( 'Log debug messages', 'woocommerce-gateway-stripe' ),
178
+			'title'       => __('Logging', 'woocommerce-gateway-stripe'),
179
+			'label'       => __('Log debug messages', 'woocommerce-gateway-stripe'),
180 180
 			'type'        => 'checkbox',
181
-			'description' => __( 'Save debug messages to the WooCommerce System Status log.', 'woocommerce-gateway-stripe' ),
181
+			'description' => __('Save debug messages to the WooCommerce System Status log.', 'woocommerce-gateway-stripe'),
182 182
 			'default'     => 'no',
183 183
 			'desc_tip'    => true,
184 184
 		),
Please login to merge, or discard this patch.
includes/class-wc-stripe-customer.php 1 patch
Spacing   +79 added lines, -79 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,8 +51,8 @@  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 ) {
55
-		$this->id = wc_clean( $id );
54
+	public function set_id($id) {
55
+		$this->id = wc_clean($id);
56 56
 	}
57 57
 
58 58
 	/**
@@ -60,15 +60,15 @@  discard block
 block discarded – undo
60 60
 	 * @return int
61 61
 	 */
62 62
 	public function get_user_id() {
63
-		return absint( $this->user_id );
63
+		return absint($this->user_id);
64 64
 	}
65 65
 
66 66
 	/**
67 67
 	 * Set User ID used by WordPress.
68 68
 	 * @param int $user_id
69 69
 	 */
70
-	public function set_user_id( $user_id ) {
71
-		$this->user_id = absint( $user_id );
70
+	public function set_user_id($user_id) {
71
+		$this->user_id = absint($user_id);
72 72
 	}
73 73
 
74 74
 	/**
@@ -76,13 +76,13 @@  discard block
 block discarded – undo
76 76
 	 * @return WP_User
77 77
 	 */
78 78
 	protected function get_user() {
79
-		return $this->get_user_id() ? get_user_by( 'id', $this->get_user_id() ) : false;
79
+		return $this->get_user_id() ? get_user_by('id', $this->get_user_id()) : false;
80 80
 	}
81 81
 
82 82
 	/**
83 83
 	 * Store data from the Stripe API about this customer
84 84
 	 */
85
-	public function set_customer_data( $data ) {
85
+	public function set_customer_data($data) {
86 86
 		$this->customer_data = $data;
87 87
 	}
88 88
 
@@ -91,13 +91,13 @@  discard block
 block discarded – undo
91 91
 	 * @param array $args
92 92
 	 * @return WP_Error|int
93 93
 	 */
94
-	public function create_customer( $args = array() ) {
95
-		$billing_email = isset( $_POST['billing_email'] ) ? filter_var( $_POST['billing_email'], FILTER_SANITIZE_EMAIL ) : '';
94
+	public function create_customer($args = array()) {
95
+		$billing_email = isset($_POST['billing_email']) ? filter_var($_POST['billing_email'], FILTER_SANITIZE_EMAIL) : '';
96 96
 		$user = $this->get_user();
97 97
 
98
-		if ( $user ) {
99
-			$billing_first_name = get_user_meta( $user->ID, 'billing_first_name', true );
100
-			$billing_last_name  = get_user_meta( $user->ID, 'billing_last_name', true );
98
+		if ($user) {
99
+			$billing_first_name = get_user_meta($user->ID, 'billing_first_name', true);
100
+			$billing_last_name  = get_user_meta($user->ID, 'billing_last_name', true);
101 101
 
102 102
 			$defaults = array(
103 103
 				'email'       => $user->user_email,
@@ -112,24 +112,24 @@  discard block
 block discarded – undo
112 112
 
113 113
 		$metadata = array();
114 114
 
115
-		$defaults['metadata'] = apply_filters( 'wc_stripe_customer_metadata', $metadata, $user );
115
+		$defaults['metadata'] = apply_filters('wc_stripe_customer_metadata', $metadata, $user);
116 116
 
117
-		$args     = wp_parse_args( $args, $defaults );
118
-		$response = WC_Stripe_API::request( apply_filters( 'wc_stripe_create_customer_args', $args ), 'customers' );
117
+		$args     = wp_parse_args($args, $defaults);
118
+		$response = WC_Stripe_API::request(apply_filters('wc_stripe_create_customer_args', $args), 'customers');
119 119
 
120
-		if ( ! empty( $response->error ) ) {
121
-			throw new WC_Stripe_Exception( print_r( $response, true ), $response->error->message );
120
+		if ( ! empty($response->error)) {
121
+			throw new WC_Stripe_Exception(print_r($response, true), $response->error->message);
122 122
 		}
123 123
 
124
-		$this->set_id( $response->id );
124
+		$this->set_id($response->id);
125 125
 		$this->clear_cache();
126
-		$this->set_customer_data( $response );
126
+		$this->set_customer_data($response);
127 127
 
128
-		if ( $this->get_user_id() ) {
129
-			update_user_meta( $this->get_user_id(), '_stripe_customer_id', $response->id );
128
+		if ($this->get_user_id()) {
129
+			update_user_meta($this->get_user_id(), '_stripe_customer_id', $response->id);
130 130
 		}
131 131
 
132
-		do_action( 'woocommerce_stripe_add_customer', $args, $response );
132
+		do_action('woocommerce_stripe_add_customer', $args, $response);
133 133
 
134 134
 		return $response->id;
135 135
 	}
@@ -140,72 +140,72 @@  discard block
 block discarded – undo
140 140
 	 * @param bool $retry
141 141
 	 * @return WP_Error|int
142 142
 	 */
143
-	public function add_source( $source_id, $retry = true ) {
144
-		if ( ! $this->get_id() ) {
145
-			$this->set_id( $this->create_customer() );
143
+	public function add_source($source_id, $retry = true) {
144
+		if ( ! $this->get_id()) {
145
+			$this->set_id($this->create_customer());
146 146
 		}
147 147
 
148
-		$response = WC_Stripe_API::request( array(
148
+		$response = WC_Stripe_API::request(array(
149 149
 			'source' => $source_id,
150
-		), 'customers/' . $this->get_id() . '/sources' );
150
+		), 'customers/' . $this->get_id() . '/sources');
151 151
 
152
-		if ( ! empty( $response->error ) ) {
152
+		if ( ! empty($response->error)) {
153 153
 			// It is possible the WC user once was linked to a customer on Stripe
154 154
 			// but no longer exists. Instead of failing, lets try to create a
155 155
 			// new customer.
156
-			if ( preg_match( '/No such customer/i', $response->error->message ) ) {
157
-				delete_user_meta( $this->get_user_id(), '_stripe_customer_id' );
156
+			if (preg_match('/No such customer/i', $response->error->message)) {
157
+				delete_user_meta($this->get_user_id(), '_stripe_customer_id');
158 158
 				$this->create_customer();
159
-				return $this->add_source( $source_id, false );
159
+				return $this->add_source($source_id, false);
160 160
 			} else {
161 161
 				return $response;
162 162
 			}
163
-		} elseif ( empty( $response->id ) ) {
164
-			return new WP_Error( 'error', __( 'Unable to add payment source.', 'woocommerce-gateway-stripe' ) );
163
+		} elseif (empty($response->id)) {
164
+			return new WP_Error('error', __('Unable to add payment source.', 'woocommerce-gateway-stripe'));
165 165
 		}
166 166
 
167 167
 		// Add token to WooCommerce.
168
-		if ( $this->get_user_id() && class_exists( 'WC_Payment_Token_CC' ) ) {
169
-			if ( ! empty( $response->type ) ) {
170
-				switch ( $response->type ) {
168
+		if ($this->get_user_id() && class_exists('WC_Payment_Token_CC')) {
169
+			if ( ! empty($response->type)) {
170
+				switch ($response->type) {
171 171
 					case 'alipay':
172 172
 						break;
173 173
 					case 'sepa_debit':
174 174
 						$wc_token = new WC_Payment_Token_SEPA();
175
-						$wc_token->set_token( $response->id );
176
-						$wc_token->set_gateway_id( 'stripe_sepa' );
177
-						$wc_token->set_last4( $response->sepa_debit->last4 );
175
+						$wc_token->set_token($response->id);
176
+						$wc_token->set_gateway_id('stripe_sepa');
177
+						$wc_token->set_last4($response->sepa_debit->last4);
178 178
 						break;
179 179
 					default:
180
-						if ( 'source' === $response->object && 'card' === $response->type ) {
180
+						if ('source' === $response->object && 'card' === $response->type) {
181 181
 							$wc_token = new WC_Payment_Token_CC();
182
-							$wc_token->set_token( $response->id );
183
-							$wc_token->set_gateway_id( 'stripe' );
184
-							$wc_token->set_card_type( strtolower( $response->card->brand ) );
185
-							$wc_token->set_last4( $response->card->last4 );
186
-							$wc_token->set_expiry_month( $response->card->exp_month );
187
-							$wc_token->set_expiry_year( $response->card->exp_year );
182
+							$wc_token->set_token($response->id);
183
+							$wc_token->set_gateway_id('stripe');
184
+							$wc_token->set_card_type(strtolower($response->card->brand));
185
+							$wc_token->set_last4($response->card->last4);
186
+							$wc_token->set_expiry_month($response->card->exp_month);
187
+							$wc_token->set_expiry_year($response->card->exp_year);
188 188
 						}
189 189
 						break;
190 190
 				}
191 191
 			} else {
192 192
 				// Legacy.
193 193
 				$wc_token = new WC_Payment_Token_CC();
194
-				$wc_token->set_token( $response->id );
195
-				$wc_token->set_gateway_id( 'stripe' );
196
-				$wc_token->set_card_type( strtolower( $response->brand ) );
197
-				$wc_token->set_last4( $response->last4 );
198
-				$wc_token->set_expiry_month( $response->exp_month );
199
-				$wc_token->set_expiry_year( $response->exp_year );
194
+				$wc_token->set_token($response->id);
195
+				$wc_token->set_gateway_id('stripe');
196
+				$wc_token->set_card_type(strtolower($response->brand));
197
+				$wc_token->set_last4($response->last4);
198
+				$wc_token->set_expiry_month($response->exp_month);
199
+				$wc_token->set_expiry_year($response->exp_year);
200 200
 			}
201 201
 
202
-			$wc_token->set_user_id( $this->get_user_id() );
202
+			$wc_token->set_user_id($this->get_user_id());
203 203
 			$wc_token->save();
204 204
 		}
205 205
 
206 206
 		$this->clear_cache();
207 207
 
208
-		do_action( 'woocommerce_stripe_add_source', $this->get_id(), $wc_token, $response, $source_id );
208
+		do_action('woocommerce_stripe_add_source', $this->get_id(), $wc_token, $response, $source_id);
209 209
 
210 210
 		return $response->id;
211 211
 	}
@@ -217,42 +217,42 @@  discard block
 block discarded – undo
217 217
 	 * @return array
218 218
 	 */
219 219
 	public function get_sources() {
220
-		if ( ! $this->get_id() ) {
220
+		if ( ! $this->get_id()) {
221 221
 			return array();
222 222
 		}
223 223
 
224
-		$sources = get_transient( 'stripe_sources_' . $this->get_id() );
224
+		$sources = get_transient('stripe_sources_' . $this->get_id());
225 225
 
226
-		$response = WC_Stripe_API::request( array(
226
+		$response = WC_Stripe_API::request(array(
227 227
 			'limit'       => 100,
228
-		), 'customers/' . $this->get_id() . '/sources', 'GET' );
228
+		), 'customers/' . $this->get_id() . '/sources', 'GET');
229 229
 
230
-		if ( ! empty( $response->error ) ) {
230
+		if ( ! empty($response->error)) {
231 231
 			return array();
232 232
 		}
233 233
 
234
-		if ( is_array( $response->data ) ) {
234
+		if (is_array($response->data)) {
235 235
 			$sources = $response->data;
236 236
 		}
237 237
 
238
-		return empty( $sources ) ? array() : $sources;
238
+		return empty($sources) ? array() : $sources;
239 239
 	}
240 240
 
241 241
 	/**
242 242
 	 * Delete a source from stripe.
243 243
 	 * @param string $source_id
244 244
 	 */
245
-	public function delete_source( $source_id ) {
246
-		if ( ! $this->get_id() ) {
245
+	public function delete_source($source_id) {
246
+		if ( ! $this->get_id()) {
247 247
 			return false;
248 248
 		}
249 249
 
250
-		$response = WC_Stripe_API::request( array(), 'customers/' . $this->get_id() . '/sources/' . sanitize_text_field( $source_id ), 'DELETE' );
250
+		$response = WC_Stripe_API::request(array(), 'customers/' . $this->get_id() . '/sources/' . sanitize_text_field($source_id), 'DELETE');
251 251
 
252 252
 		$this->clear_cache();
253 253
 
254
-		if ( empty( $response->error ) ) {
255
-			do_action( 'wc_stripe_delete_source', $this->get_id(), $response );
254
+		if (empty($response->error)) {
255
+			do_action('wc_stripe_delete_source', $this->get_id(), $response);
256 256
 
257 257
 			return true;
258 258
 		}
@@ -264,15 +264,15 @@  discard block
 block discarded – undo
264 264
 	 * Set default source in Stripe
265 265
 	 * @param string $source_id
266 266
 	 */
267
-	public function set_default_source( $source_id ) {
268
-		$response = WC_Stripe_API::request( array(
269
-			'default_source' => sanitize_text_field( $source_id ),
270
-		), 'customers/' . $this->get_id(), 'POST' );
267
+	public function set_default_source($source_id) {
268
+		$response = WC_Stripe_API::request(array(
269
+			'default_source' => sanitize_text_field($source_id),
270
+		), 'customers/' . $this->get_id(), 'POST');
271 271
 
272 272
 		$this->clear_cache();
273 273
 
274
-		if ( empty( $response->error ) ) {
275
-			do_action( 'wc_stripe_set_default_source', $this->get_id(), $response );
274
+		if (empty($response->error)) {
275
+			do_action('wc_stripe_set_default_source', $this->get_id(), $response);
276 276
 
277 277
 			return true;
278 278
 		}
@@ -284,8 +284,8 @@  discard block
 block discarded – undo
284 284
 	 * Deletes caches for this users cards.
285 285
 	 */
286 286
 	public function clear_cache() {
287
-		delete_transient( 'stripe_sources_' . $this->get_id() );
288
-		delete_transient( 'stripe_customer_' . $this->get_id() );
287
+		delete_transient('stripe_sources_' . $this->get_id());
288
+		delete_transient('stripe_customer_' . $this->get_id());
289 289
 		$this->customer_data = array();
290 290
 	}
291 291
 }
Please login to merge, or discard this patch.
includes/compat/class-wc-stripe-sepa-compat.php 1 patch
Spacing   +160 added lines, -160 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) {
2
+if ( ! defined('ABSPATH')) {
3 3
 	exit;
4 4
 }
5 5
 
@@ -15,24 +15,24 @@  discard block
 block discarded – undo
15 15
 	public function __construct() {
16 16
 		parent::__construct();
17 17
 
18
-		if ( class_exists( 'WC_Subscriptions_Order' ) ) {
19
-			add_action( 'woocommerce_scheduled_subscription_payment_' . $this->id, array( $this, 'scheduled_subscription_payment' ), 10, 2 );
20
-			add_action( 'wcs_resubscribe_order_created', array( $this, 'delete_resubscribe_meta' ), 10 );
21
-			add_action( 'wcs_renewal_order_created', array( $this, 'delete_renewal_meta' ), 10 );
22
-			add_action( 'woocommerce_subscription_failing_payment_method_updated_stripe', array( $this, 'update_failing_payment_method' ), 10, 2 );
18
+		if (class_exists('WC_Subscriptions_Order')) {
19
+			add_action('woocommerce_scheduled_subscription_payment_' . $this->id, array($this, 'scheduled_subscription_payment'), 10, 2);
20
+			add_action('wcs_resubscribe_order_created', array($this, 'delete_resubscribe_meta'), 10);
21
+			add_action('wcs_renewal_order_created', array($this, 'delete_renewal_meta'), 10);
22
+			add_action('woocommerce_subscription_failing_payment_method_updated_stripe', array($this, 'update_failing_payment_method'), 10, 2);
23 23
 
24 24
 			// display the credit card used for a subscription in the "My Subscriptions" table
25
-			add_filter( 'woocommerce_my_subscriptions_payment_method', array( $this, 'maybe_render_subscription_payment_method' ), 10, 2 );
25
+			add_filter('woocommerce_my_subscriptions_payment_method', array($this, 'maybe_render_subscription_payment_method'), 10, 2);
26 26
 
27 27
 			// allow store managers to manually set Stripe as the payment method on a subscription
28
-			add_filter( 'woocommerce_subscription_payment_meta', array( $this, 'add_subscription_payment_meta' ), 10, 2 );
29
-			add_filter( 'woocommerce_subscription_validate_payment_meta', array( $this, 'validate_subscription_payment_meta' ), 10, 2 );
30
-			add_filter( 'wc_stripe_display_save_payment_method_checkbox', array( $this, 'maybe_hide_save_checkbox' ) );
31
-			add_filter( 'wc_stripe_payment_metadata', array( $this, 'add_subscription_meta_data' ), 10, 2 );
28
+			add_filter('woocommerce_subscription_payment_meta', array($this, 'add_subscription_payment_meta'), 10, 2);
29
+			add_filter('woocommerce_subscription_validate_payment_meta', array($this, 'validate_subscription_payment_meta'), 10, 2);
30
+			add_filter('wc_stripe_display_save_payment_method_checkbox', array($this, 'maybe_hide_save_checkbox'));
31
+			add_filter('wc_stripe_payment_metadata', array($this, 'add_subscription_meta_data'), 10, 2);
32 32
 		}
33 33
 
34
-		if ( class_exists( 'WC_Pre_Orders_Order' ) ) {
35
-			add_action( 'wc_pre_orders_process_pre_order_completion_payment_' . $this->id, array( $this, 'process_pre_order_release_payment' ) );
34
+		if (class_exists('WC_Pre_Orders_Order')) {
35
+			add_action('wc_pre_orders_process_pre_order_completion_payment_' . $this->id, array($this, 'process_pre_order_release_payment'));
36 36
 		}
37 37
 	}
38 38
 
@@ -43,8 +43,8 @@  discard block
 block discarded – undo
43 43
 	 * @since 4.0.0
44 44
 	 * @version 4.0.0
45 45
 	 */
46
-	public function maybe_hide_save_checkbox( $display_tokenization ) {
47
-		if ( WC_Subscriptions_Cart::cart_contains_subscription() ) {
46
+	public function maybe_hide_save_checkbox($display_tokenization) {
47
+		if (WC_Subscriptions_Cart::cart_contains_subscription()) {
48 48
 			return false;
49 49
 		}
50 50
 
@@ -56,8 +56,8 @@  discard block
 block discarded – undo
56 56
 	 * @param  int  $order_id
57 57
 	 * @return boolean
58 58
 	 */
59
-	public function has_subscription( $order_id ) {
60
-		return ( function_exists( 'wcs_order_contains_subscription' ) && ( wcs_order_contains_subscription( $order_id ) || wcs_is_subscription( $order_id ) || wcs_order_contains_renewal( $order_id ) ) );
59
+	public function has_subscription($order_id) {
60
+		return (function_exists('wcs_order_contains_subscription') && (wcs_order_contains_subscription($order_id) || wcs_is_subscription($order_id) || wcs_order_contains_renewal($order_id)));
61 61
 	}
62 62
 
63 63
 	/**
@@ -65,8 +65,8 @@  discard block
 block discarded – undo
65 65
 	 * @param  int  $order_id
66 66
 	 * @return boolean
67 67
 	 */
68
-	protected function is_pre_order( $order_id ) {
69
-		return ( class_exists( 'WC_Pre_Orders_Order' ) && WC_Pre_Orders_Order::order_contains_pre_order( $order_id ) );
68
+	protected function is_pre_order($order_id) {
69
+		return (class_exists('WC_Pre_Orders_Order') && WC_Pre_Orders_Order::order_contains_pre_order($order_id));
70 70
 	}
71 71
 
72 72
 	/**
@@ -74,14 +74,14 @@  discard block
 block discarded – undo
74 74
 	 * @param  int $order_id
75 75
 	 * @return array
76 76
 	 */
77
-	public function process_payment( $order_id, $retry = true, $force_save_source = false ) {
78
-		if ( $this->has_subscription( $order_id ) ) {
77
+	public function process_payment($order_id, $retry = true, $force_save_source = false) {
78
+		if ($this->has_subscription($order_id)) {
79 79
 			// Regular payment with force customer enabled
80
-			return parent::process_payment( $order_id, true, true );
81
-		} elseif ( $this->is_pre_order( $order_id ) ) {
82
-			return $this->process_pre_order( $order_id, $retry, $force_save_source );
80
+			return parent::process_payment($order_id, true, true);
81
+		} elseif ($this->is_pre_order($order_id)) {
82
+			return $this->process_pre_order($order_id, $retry, $force_save_source);
83 83
 		} else {
84
-			return parent::process_payment( $order_id, $retry, $force_save_source );
84
+			return parent::process_payment($order_id, $retry, $force_save_source);
85 85
 		}
86 86
 	}
87 87
 
@@ -92,14 +92,14 @@  discard block
 block discarded – undo
92 92
 	 * @param array $metadata
93 93
 	 * @param object $order
94 94
 	 */
95
-	public function add_subscription_meta_data( $metadata, $order ) {
96
-		if ( ! $this->has_subscription( WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id() ) ) {
95
+	public function add_subscription_meta_data($metadata, $order) {
96
+		if ( ! $this->has_subscription(WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id())) {
97 97
 			return $metadata;
98 98
 		}
99 99
 
100 100
 		return $metadata += array(
101 101
 			'payment_type'   => 'recurring',
102
-			'site_url'       => esc_url( get_site_url() ),
102
+			'site_url'       => esc_url(get_site_url()),
103 103
 		);
104 104
 	}
105 105
 
@@ -109,24 +109,24 @@  discard block
 block discarded – undo
109 109
 	 * @since 3.1.0
110 110
 	 * @version 4.0.0
111 111
 	 */
112
-	public function save_source_to_order( $order, $source ) {
113
-		parent::save_source_to_order( $order, $source );
112
+	public function save_source_to_order($order, $source) {
113
+		parent::save_source_to_order($order, $source);
114 114
 
115
-		$order_id  = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
115
+		$order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
116 116
 
117 117
 		// Also store it on the subscriptions being purchased or paid for in the order
118
-		if ( function_exists( 'wcs_order_contains_subscription' ) && wcs_order_contains_subscription( $order_id ) ) {
119
-			$subscriptions = wcs_get_subscriptions_for_order( $order_id );
120
-		} elseif ( function_exists( 'wcs_order_contains_renewal' ) && wcs_order_contains_renewal( $order_id ) ) {
121
-			$subscriptions = wcs_get_subscriptions_for_renewal_order( $order_id );
118
+		if (function_exists('wcs_order_contains_subscription') && wcs_order_contains_subscription($order_id)) {
119
+			$subscriptions = wcs_get_subscriptions_for_order($order_id);
120
+		} elseif (function_exists('wcs_order_contains_renewal') && wcs_order_contains_renewal($order_id)) {
121
+			$subscriptions = wcs_get_subscriptions_for_renewal_order($order_id);
122 122
 		} else {
123 123
 			$subscriptions = array();
124 124
 		}
125 125
 
126
-		foreach ( $subscriptions as $subscription ) {
126
+		foreach ($subscriptions as $subscription) {
127 127
 			$subscription_id = WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id();
128
-			update_post_meta( $subscription_id, '_stripe_customer_id', $source->customer );
129
-			update_post_meta( $subscription_id, '_stripe_source_id', $source->source );
128
+			update_post_meta($subscription_id, '_stripe_customer_id', $source->customer);
129
+			update_post_meta($subscription_id, '_stripe_source_id', $source->source);
130 130
 		}
131 131
 	}
132 132
 
@@ -139,45 +139,45 @@  discard block
 block discarded – undo
139 139
 	 * @param mixed $renewal_order
140 140
 	 * @param bool $is_retry Is this a retry process.
141 141
 	 */
142
-	public function process_subscription_payment( $amount = 0.0, $renewal_order, $is_retry = false ) {
143
-		if ( $amount * 100 < WC_Stripe_Helper::get_minimum_amount() ) {
142
+	public function process_subscription_payment($amount = 0.0, $renewal_order, $is_retry = false) {
143
+		if ($amount * 100 < WC_Stripe_Helper::get_minimum_amount()) {
144 144
 			/* translators: minimum amount */
145
-			return new WP_Error( 'stripe_error', sprintf( __( 'Sorry, the minimum allowed order total is %1$s to use this payment method.', 'woocommerce-gateway-stripe' ), wc_price( WC_Stripe_Helper::get_minimum_amount() / 100 ) ) );
145
+			return new WP_Error('stripe_error', sprintf(__('Sorry, the minimum allowed order total is %1$s to use this payment method.', 'woocommerce-gateway-stripe'), wc_price(WC_Stripe_Helper::get_minimum_amount() / 100)));
146 146
 		}
147 147
 
148 148
 		$order_id = WC_Stripe_Helper::is_pre_30() ? $renewal_order->id : $renewal_order->get_id();
149 149
 
150 150
 		// Get source from order
151
-		$prepared_source = $this->prepare_order_source( $renewal_order );
151
+		$prepared_source = $this->prepare_order_source($renewal_order);
152 152
 
153
-		if ( ! $prepared_source->customer ) {
154
-			return new WP_Error( 'stripe_error', __( 'Customer not found', 'woocommerce-gateway-stripe' ) );
153
+		if ( ! $prepared_source->customer) {
154
+			return new WP_Error('stripe_error', __('Customer not found', 'woocommerce-gateway-stripe'));
155 155
 		}
156 156
 
157
-		WC_Stripe_Logger::log( "Info: Begin processing subscription payment for order {$order_id} for the amount of {$amount}" );
157
+		WC_Stripe_Logger::log("Info: Begin processing subscription payment for order {$order_id} for the amount of {$amount}");
158 158
 
159
-		if ( $is_retry ) {
159
+		if ($is_retry) {
160 160
 			// Passing empty source with charge customer default.
161 161
 			$prepared_source->source = '';
162 162
 		}
163 163
 
164
-		$request            = $this->generate_payment_request( $renewal_order, $prepared_source );
164
+		$request            = $this->generate_payment_request($renewal_order, $prepared_source);
165 165
 		$request['capture'] = 'true';
166
-		$request['amount']  = WC_Stripe_Helper::get_stripe_amount( $amount, $request['currency'] );
167
-		$response           = WC_Stripe_API::request( $request );
166
+		$request['amount']  = WC_Stripe_Helper::get_stripe_amount($amount, $request['currency']);
167
+		$response           = WC_Stripe_API::request($request);
168 168
 
169
-		if ( ! empty( $response->error ) || is_wp_error( $response ) ) {
170
-			if ( $is_retry ) {
169
+		if ( ! empty($response->error) || is_wp_error($response)) {
170
+			if ($is_retry) {
171 171
 				/* translators: error message */
172
-				$renewal_order->update_status( 'failed', sprintf( __( 'Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe' ), $response->error->message ) );
172
+				$renewal_order->update_status('failed', sprintf(__('Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe'), $response->error->message));
173 173
 			}
174 174
 
175 175
 			return $response; // Default catch all errors.
176 176
 		}
177 177
 
178
-		$this->process_response( $response, $renewal_order );
178
+		$this->process_response($response, $renewal_order);
179 179
 
180
-		if ( ! $is_retry ) {
180
+		if ( ! $is_retry) {
181 181
 			return $response;
182 182
 		}
183 183
 	}
@@ -186,21 +186,21 @@  discard block
 block discarded – undo
186 186
 	 * Don't transfer Stripe customer/token meta to resubscribe orders.
187 187
 	 * @param int $resubscribe_order The order created for the customer to resubscribe to the old expired/cancelled subscription
188 188
 	 */
189
-	public function delete_resubscribe_meta( $resubscribe_order ) {
190
-		delete_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id() ), '_stripe_customer_id' );
191
-		delete_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id() ), '_stripe_source_id' );
189
+	public function delete_resubscribe_meta($resubscribe_order) {
190
+		delete_post_meta((WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id()), '_stripe_customer_id');
191
+		delete_post_meta((WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id()), '_stripe_source_id');
192 192
 		// For BW compat will remove in future
193
-		delete_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id() ), '_stripe_card_id' );
194
-		$this->delete_renewal_meta( $resubscribe_order );
193
+		delete_post_meta((WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id()), '_stripe_card_id');
194
+		$this->delete_renewal_meta($resubscribe_order);
195 195
 	}
196 196
 
197 197
 	/**
198 198
 	 * Don't transfer Stripe fee/ID meta to renewal orders.
199 199
 	 * @param int $resubscribe_order The order created for the customer to resubscribe to the old expired/cancelled subscription
200 200
 	 */
201
-	public function delete_renewal_meta( $renewal_order ) {
202
-		delete_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $renewal_order->id : $renewal_order->get_id() ), 'Stripe Fee' );
203
-		delete_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $renewal_order->id : $renewal_order->get_id() ), 'Net Revenue From Stripe' );
201
+	public function delete_renewal_meta($renewal_order) {
202
+		delete_post_meta((WC_Stripe_Helper::is_pre_30() ? $renewal_order->id : $renewal_order->get_id()), 'Stripe Fee');
203
+		delete_post_meta((WC_Stripe_Helper::is_pre_30() ? $renewal_order->id : $renewal_order->get_id()), 'Net Revenue From Stripe');
204 204
 		return $renewal_order;
205 205
 	}
206 206
 
@@ -210,21 +210,21 @@  discard block
 block discarded – undo
210 210
 	 * @param $amount_to_charge float The amount to charge.
211 211
 	 * @param $renewal_order WC_Order A WC_Order object created to record the renewal payment.
212 212
 	 */
213
-	public function scheduled_subscription_payment( $amount_to_charge, $renewal_order ) {
214
-		$response = $this->process_subscription_payment( $amount_to_charge, $renewal_order );
213
+	public function scheduled_subscription_payment($amount_to_charge, $renewal_order) {
214
+		$response = $this->process_subscription_payment($amount_to_charge, $renewal_order);
215 215
 
216
-		if ( is_wp_error( $response ) ) {
216
+		if (is_wp_error($response)) {
217 217
 			/* translators: error message */
218
-			$renewal_order->update_status( 'failed', sprintf( __( 'Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe' ), $response->get_error_message() ) );
218
+			$renewal_order->update_status('failed', sprintf(__('Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe'), $response->get_error_message()));
219 219
 		}
220 220
 
221
-		if ( ! empty( $response->error ) ) {
221
+		if ( ! empty($response->error)) {
222 222
 			// This is a very generic error to listen for but worth a retry before total fail.
223
-			if ( isset( $response->error->type ) && 'invalid_request_error' === $response->error->type && apply_filters( 'wc_stripe_use_default_customer_source', true ) ) {
224
-				$this->process_subscription_payment( $amount_to_charge, $renewal_order, true );
223
+			if (isset($response->error->type) && 'invalid_request_error' === $response->error->type && apply_filters('wc_stripe_use_default_customer_source', true)) {
224
+				$this->process_subscription_payment($amount_to_charge, $renewal_order, true);
225 225
 			} else {
226 226
 				/* translators: error message */
227
-				$renewal_order->update_status( 'failed', sprintf( __( 'Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe' ), $response->error->message ) );
227
+				$renewal_order->update_status('failed', sprintf(__('Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe'), $response->error->message));
228 228
 			}
229 229
 		}
230 230
 	}
@@ -233,20 +233,20 @@  discard block
 block discarded – undo
233 233
 	 * Remove order meta
234 234
 	 * @param  object $order
235 235
 	 */
236
-	public function remove_order_source_before_retry( $order ) {
236
+	public function remove_order_source_before_retry($order) {
237 237
 		$order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
238
-		delete_post_meta( $order_id, '_stripe_source_id' );
238
+		delete_post_meta($order_id, '_stripe_source_id');
239 239
 		// For BW compat will remove in the future.
240
-		delete_post_meta( $order_id, '_stripe_card_id' );
240
+		delete_post_meta($order_id, '_stripe_card_id');
241 241
 	}
242 242
 
243 243
 	/**
244 244
 	 * Remove order meta
245 245
 	 * @param object $order
246 246
 	 */
247
-	public function remove_order_customer_before_retry( $order ) {
247
+	public function remove_order_customer_before_retry($order) {
248 248
 		$order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
249
-		delete_post_meta( $order_id, '_stripe_customer_id' );
249
+		delete_post_meta($order_id, '_stripe_customer_id');
250 250
 	}
251 251
 
252 252
 	/**
@@ -258,14 +258,14 @@  discard block
 block discarded – undo
258 258
 	 * @param WC_Order $renewal_order The order which recorded the successful payment (to make up for the failed automatic payment).
259 259
 	 * @return void
260 260
 	 */
261
-	public function update_failing_payment_method( $subscription, $renewal_order ) {
262
-		if ( WC_Stripe_Helper::is_pre_30() ) {
263
-			update_post_meta( $subscription->id, '_stripe_customer_id', $renewal_order->stripe_customer_id );
264
-			update_post_meta( $subscription->id, '_stripe_source_id', $renewal_order->stripe_source_id );
261
+	public function update_failing_payment_method($subscription, $renewal_order) {
262
+		if (WC_Stripe_Helper::is_pre_30()) {
263
+			update_post_meta($subscription->id, '_stripe_customer_id', $renewal_order->stripe_customer_id);
264
+			update_post_meta($subscription->id, '_stripe_source_id', $renewal_order->stripe_source_id);
265 265
 
266 266
 		} else {
267
-			update_post_meta( $subscription->get_id(), '_stripe_customer_id', $renewal_order->get_meta( '_stripe_customer_id', true ) );
268
-			update_post_meta( $subscription->get_id(), '_stripe_source_id', $renewal_order->get_meta( '_stripe_source_id', true ) );
267
+			update_post_meta($subscription->get_id(), '_stripe_customer_id', $renewal_order->get_meta('_stripe_customer_id', true));
268
+			update_post_meta($subscription->get_id(), '_stripe_source_id', $renewal_order->get_meta('_stripe_source_id', true));
269 269
 		}
270 270
 	}
271 271
 
@@ -278,21 +278,21 @@  discard block
 block discarded – undo
278 278
 	 * @param WC_Subscription $subscription An instance of a subscription object
279 279
 	 * @return array
280 280
 	 */
281
-	public function add_subscription_payment_meta( $payment_meta, $subscription ) {
282
-		$source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_source_id', true );
281
+	public function add_subscription_payment_meta($payment_meta, $subscription) {
282
+		$source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_source_id', true);
283 283
 
284 284
 		// For BW compat will remove in future.
285
-		if ( empty( $source_id ) ) {
286
-			$source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_card_id', true );
285
+		if (empty($source_id)) {
286
+			$source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_card_id', true);
287 287
 
288 288
 			// Take this opportunity to update the key name.
289
-			WC_Stripe_Helper::is_pre_30() ? update_post_meta( $subscription->id, '_stripe_source_id', $source_id ) : update_post_meta( $subscription->get_id(), '_stripe_source_id', $source_id );
289
+			WC_Stripe_Helper::is_pre_30() ? update_post_meta($subscription->id, '_stripe_source_id', $source_id) : update_post_meta($subscription->get_id(), '_stripe_source_id', $source_id);
290 290
 		}
291 291
 
292
-		$payment_meta[ $this->id ] = array(
292
+		$payment_meta[$this->id] = array(
293 293
 			'post_meta' => array(
294 294
 				'_stripe_customer_id' => array(
295
-					'value' => get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_customer_id', true ),
295
+					'value' => get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_customer_id', true),
296 296
 					'label' => 'Stripe Customer ID',
297 297
 				),
298 298
 				'_stripe_source_id' => array(
@@ -313,22 +313,22 @@  discard block
 block discarded – undo
313 313
 	 * @param array $payment_meta associative array of meta data required for automatic payments
314 314
 	 * @return array
315 315
 	 */
316
-	public function validate_subscription_payment_meta( $payment_method_id, $payment_meta ) {
317
-		if ( $this->id === $payment_method_id ) {
316
+	public function validate_subscription_payment_meta($payment_method_id, $payment_meta) {
317
+		if ($this->id === $payment_method_id) {
318 318
 
319
-			if ( ! isset( $payment_meta['post_meta']['_stripe_customer_id']['value'] ) || empty( $payment_meta['post_meta']['_stripe_customer_id']['value'] ) ) {
320
-				throw new Exception( __( 'A "Stripe Customer ID" value is required.', 'woocommerce-gateway-stripe' ) );
321
-			} elseif ( 0 !== strpos( $payment_meta['post_meta']['_stripe_customer_id']['value'], 'cus_' ) ) {
322
-				throw new Exception( __( 'Invalid customer ID. A valid "Stripe Customer ID" must begin with "cus_".', 'woocommerce-gateway-stripe' ) );
319
+			if ( ! isset($payment_meta['post_meta']['_stripe_customer_id']['value']) || empty($payment_meta['post_meta']['_stripe_customer_id']['value'])) {
320
+				throw new Exception(__('A "Stripe Customer ID" value is required.', 'woocommerce-gateway-stripe'));
321
+			} elseif (0 !== strpos($payment_meta['post_meta']['_stripe_customer_id']['value'], 'cus_')) {
322
+				throw new Exception(__('Invalid customer ID. A valid "Stripe Customer ID" must begin with "cus_".', 'woocommerce-gateway-stripe'));
323 323
 			}
324 324
 
325 325
 			if (
326
-				( ! empty( $payment_meta['post_meta']['_stripe_source_id']['value'] )
327
-				&& 0 !== strpos( $payment_meta['post_meta']['_stripe_source_id']['value'], 'card_' ) )
328
-				&& ( ! empty( $payment_meta['post_meta']['_stripe_source_id']['value'] )
329
-				&& 0 !== strpos( $payment_meta['post_meta']['_stripe_source_id']['value'], 'src_' ) ) ) {
326
+				( ! empty($payment_meta['post_meta']['_stripe_source_id']['value'])
327
+				&& 0 !== strpos($payment_meta['post_meta']['_stripe_source_id']['value'], 'card_'))
328
+				&& ( ! empty($payment_meta['post_meta']['_stripe_source_id']['value'])
329
+				&& 0 !== strpos($payment_meta['post_meta']['_stripe_source_id']['value'], 'src_')) ) {
330 330
 
331
-				throw new Exception( __( 'Invalid source ID. A valid source "Stripe Source ID" must begin with "src_" or "card_".', 'woocommerce-gateway-stripe' ) );
331
+				throw new Exception(__('Invalid source ID. A valid source "Stripe Source ID" must begin with "src_" or "card_".', 'woocommerce-gateway-stripe'));
332 332
 			}
333 333
 		}
334 334
 	}
@@ -341,89 +341,89 @@  discard block
 block discarded – undo
341 341
 	 * @param WC_Subscription $subscription the subscription details
342 342
 	 * @return string the subscription payment method
343 343
 	 */
344
-	public function maybe_render_subscription_payment_method( $payment_method_to_display, $subscription ) {
344
+	public function maybe_render_subscription_payment_method($payment_method_to_display, $subscription) {
345 345
 		$customer_user = WC_Stripe_Helper::is_pre_30() ? $subscription->customer_user : $subscription->get_customer_id();
346 346
 
347 347
 		// bail for other payment methods
348
-		if ( ( WC_Stripe_Helper::is_pre_30() ? $subscription->payment_method : $subscription->get_payment_method() ) !== $this->id || ! $customer_user ) {
348
+		if ((WC_Stripe_Helper::is_pre_30() ? $subscription->payment_method : $subscription->get_payment_method()) !== $this->id || ! $customer_user) {
349 349
 			return $payment_method_to_display;
350 350
 		}
351 351
 
352
-		$stripe_source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_source_id', true );
352
+		$stripe_source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_source_id', true);
353 353
 
354 354
 		// For BW compat will remove in future.
355
-		if ( empty( $stripe_source_id ) ) {
356
-			$stripe_source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_card_id', true );
355
+		if (empty($stripe_source_id)) {
356
+			$stripe_source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_card_id', true);
357 357
 
358 358
 			// Take this opportunity to update the key name.
359
-			WC_Stripe_Helper::is_pre_30() ? update_post_meta( $subscription->id, '_stripe_source_id', $stripe_source_id ) : update_post_meta( $subscription->get_id(), '_stripe_source_id', $stripe_source_id );
359
+			WC_Stripe_Helper::is_pre_30() ? update_post_meta($subscription->id, '_stripe_source_id', $stripe_source_id) : update_post_meta($subscription->get_id(), '_stripe_source_id', $stripe_source_id);
360 360
 		}
361 361
 
362 362
 		$stripe_customer    = new WC_Stripe_Customer();
363
-		$stripe_customer_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_customer_id', true );
363
+		$stripe_customer_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_customer_id', true);
364 364
 
365 365
 		// If we couldn't find a Stripe customer linked to the subscription, fallback to the user meta data.
366
-		if ( ! $stripe_customer_id || ! is_string( $stripe_customer_id ) ) {
366
+		if ( ! $stripe_customer_id || ! is_string($stripe_customer_id)) {
367 367
 			$user_id            = $customer_user;
368
-			$stripe_customer_id = get_user_meta( $user_id, '_stripe_customer_id', true );
369
-			$stripe_source_id   = get_user_meta( $user_id, '_stripe_source_id', true );
368
+			$stripe_customer_id = get_user_meta($user_id, '_stripe_customer_id', true);
369
+			$stripe_source_id   = get_user_meta($user_id, '_stripe_source_id', true);
370 370
 
371 371
 			// For BW compat will remove in future.
372
-			if ( empty( $stripe_source_id ) ) {
373
-				$stripe_source_id = get_user_meta( $user_id, '_stripe_card_id', true );
372
+			if (empty($stripe_source_id)) {
373
+				$stripe_source_id = get_user_meta($user_id, '_stripe_card_id', true);
374 374
 
375 375
 				// Take this opportunity to update the key name.
376
-				update_user_meta( $user_id, '_stripe_source_id', $stripe_source_id );
376
+				update_user_meta($user_id, '_stripe_source_id', $stripe_source_id);
377 377
 			}
378 378
 		}
379 379
 
380 380
 		// If we couldn't find a Stripe customer linked to the account, fallback to the order meta data.
381
-		if ( ( ! $stripe_customer_id || ! is_string( $stripe_customer_id ) ) && false !== $subscription->order ) {
382
-			$stripe_customer_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id() ), '_stripe_customer_id', true );
383
-			$stripe_source_id   = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id() ), '_stripe_source_id', true );
381
+		if (( ! $stripe_customer_id || ! is_string($stripe_customer_id)) && false !== $subscription->order) {
382
+			$stripe_customer_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id()), '_stripe_customer_id', true);
383
+			$stripe_source_id   = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id()), '_stripe_source_id', true);
384 384
 
385 385
 			// For BW compat will remove in future.
386
-			if ( empty( $stripe_source_id ) ) {
387
-				$stripe_source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id() ), '_stripe_card_id', true );
386
+			if (empty($stripe_source_id)) {
387
+				$stripe_source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id()), '_stripe_card_id', true);
388 388
 
389 389
 				// Take this opportunity to update the key name.
390
-				WC_Stripe_Helper::is_pre_30() ? update_post_meta( $subscription->order->id, '_stripe_source_id', $stripe_source_id ) : update_post_meta( $subscription->get_parent_id(), '_stripe_source_id', $stripe_source_id );
390
+				WC_Stripe_Helper::is_pre_30() ? update_post_meta($subscription->order->id, '_stripe_source_id', $stripe_source_id) : update_post_meta($subscription->get_parent_id(), '_stripe_source_id', $stripe_source_id);
391 391
 			}
392 392
 		}
393 393
 
394
-		$stripe_customer->set_id( $stripe_customer_id );
394
+		$stripe_customer->set_id($stripe_customer_id);
395 395
 		$sources = $stripe_customer->get_sources();
396 396
 
397
-		if ( $sources ) {
397
+		if ($sources) {
398 398
 			$found_source = false;
399
-			foreach ( $sources as $source ) {
400
-				if ( isset( $source->type ) && 'card' === $source->type ) {
399
+			foreach ($sources as $source) {
400
+				if (isset($source->type) && 'card' === $source->type) {
401 401
 					$card = $source->card;
402 402
 				}
403 403
 
404
-				if ( $source->id === $stripe_source_id ) {
404
+				if ($source->id === $stripe_source_id) {
405 405
 					$found_source = true;
406 406
 
407
-					if ( $card ) {
407
+					if ($card) {
408 408
 						/* translators: 1) card brand 2) last 4 digits */
409
-						$payment_method_to_display = sprintf( __( 'Via %1$s card ending in %2$s', 'woocommerce-gateway-stripe' ), ( isset( $card->brand ) ? $card->brand : __( 'N/A', 'woocommerce-gateway-stripe' ) ), $card->last4 );
409
+						$payment_method_to_display = sprintf(__('Via %1$s card ending in %2$s', 'woocommerce-gateway-stripe'), (isset($card->brand) ? $card->brand : __('N/A', 'woocommerce-gateway-stripe')), $card->last4);
410 410
 					} else {
411
-						$payment_method_to_display = __( 'N/A', 'woocommerce-gateway-stripe' );
411
+						$payment_method_to_display = __('N/A', 'woocommerce-gateway-stripe');
412 412
 					}
413 413
 					break;
414 414
 				}
415 415
 			}
416 416
 
417
-			if ( ! $found_source ) {
418
-				if ( 'card' === $sources[0]->type ) {
417
+			if ( ! $found_source) {
418
+				if ('card' === $sources[0]->type) {
419 419
 					$card = $sources[0]->card;
420 420
 				}
421 421
 
422
-				if ( $card ) {
422
+				if ($card) {
423 423
 					/* translators: 1) card brand 2) last 4 digits */
424
-					$payment_method_to_display = sprintf( __( 'Via %1$s card ending in %2$s', 'woocommerce-gateway-stripe' ), ( isset( $card->brand ) ? $card->brand : __( 'N/A', 'woocommerce-gateway-stripe' ) ), $card->last4 );
424
+					$payment_method_to_display = sprintf(__('Via %1$s card ending in %2$s', 'woocommerce-gateway-stripe'), (isset($card->brand) ? $card->brand : __('N/A', 'woocommerce-gateway-stripe')), $card->last4);
425 425
 				} else {
426
-					$payment_method_to_display = __( 'N/A', 'woocommerce-gateway-stripe' );
426
+					$payment_method_to_display = __('N/A', 'woocommerce-gateway-stripe');
427 427
 				}
428 428
 			}
429 429
 		}
@@ -436,42 +436,42 @@  discard block
 block discarded – undo
436 436
 	 * @param int $order_id
437 437
 	 * @return array
438 438
 	 */
439
-	public function process_pre_order( $order_id, $retry, $force_save_source ) {
440
-		if ( WC_Pre_Orders_Order::order_requires_payment_tokenization( $order_id ) ) {
439
+	public function process_pre_order($order_id, $retry, $force_save_source) {
440
+		if (WC_Pre_Orders_Order::order_requires_payment_tokenization($order_id)) {
441 441
 			try {
442
-				$order = wc_get_order( $order_id );
442
+				$order = wc_get_order($order_id);
443 443
 
444
-				if ( $order->get_total() * 100 < WC_Stripe_Helper::get_minimum_amount() ) {
444
+				if ($order->get_total() * 100 < WC_Stripe_Helper::get_minimum_amount()) {
445 445
 					/* translators: minimum amount */
446
-					throw new Exception( sprintf( __( 'Sorry, the minimum allowed order total is %1$s to use this payment method.', 'woocommerce-gateway-stripe' ), wc_price( WC_Stripe_Helper::get_minimum_amount() / 100 ) ) );
446
+					throw new Exception(sprintf(__('Sorry, the minimum allowed order total is %1$s to use this payment method.', 'woocommerce-gateway-stripe'), wc_price(WC_Stripe_Helper::get_minimum_amount() / 100)));
447 447
 				}
448 448
 
449
-				$source = $this->prepare_source( $this->get_source_object(), get_current_user_id(), true );
449
+				$source = $this->prepare_source($this->get_source_object(), get_current_user_id(), true);
450 450
 
451 451
 				// We need a source on file to continue.
452
-				if ( empty( $source->customer ) || empty( $source->source ) ) {
453
-					throw new Exception( __( 'Unable to store payment details. Please try again.', 'woocommerce-gateway-stripe' ) );
452
+				if (empty($source->customer) || empty($source->source)) {
453
+					throw new Exception(__('Unable to store payment details. Please try again.', 'woocommerce-gateway-stripe'));
454 454
 				}
455 455
 
456
-				$this->save_source_to_order( $order, $source );
456
+				$this->save_source_to_order($order, $source);
457 457
 
458 458
 				// Remove cart
459 459
 				WC()->cart->empty_cart();
460 460
 
461 461
 				// Is pre ordered!
462
-				WC_Pre_Orders_Order::mark_order_as_pre_ordered( $order );
462
+				WC_Pre_Orders_Order::mark_order_as_pre_ordered($order);
463 463
 
464 464
 				// Return thank you page redirect
465 465
 				return array(
466 466
 					'result'   => 'success',
467
-					'redirect' => $this->get_return_url( $order ),
467
+					'redirect' => $this->get_return_url($order),
468 468
 				);
469
-			} catch ( Exception $e ) {
470
-				wc_add_notice( $e->getMessage(), 'error' );
469
+			} catch (Exception $e) {
470
+				wc_add_notice($e->getMessage(), 'error');
471 471
 				return;
472 472
 			}
473 473
 		} else {
474
-			return parent::process_payment( $order_id, $retry, $force_save_source );
474
+			return parent::process_payment($order_id, $retry, $force_save_source);
475 475
 		}
476 476
 	}
477 477
 
@@ -480,7 +480,7 @@  discard block
 block discarded – undo
480 480
 	 * @param WC_Order $order
481 481
 	 * @return void
482 482
 	 */
483
-	public function process_pre_order_release_payment( $order ) {
483
+	public function process_pre_order_release_payment($order) {
484 484
 		try {
485 485
 			// Define some callbacks if the first attempt fails.
486 486
 			$retry_callbacks = array(
@@ -488,33 +488,33 @@  discard block
 block discarded – undo
488 488
 				'remove_order_customer_before_retry',
489 489
 			);
490 490
 
491
-			while ( 1 ) {
492
-				$source   = $this->prepare_order_source( $order );
493
-				$response = WC_Stripe_API::request( $this->generate_payment_request( $order, $source ) );
491
+			while (1) {
492
+				$source   = $this->prepare_order_source($order);
493
+				$response = WC_Stripe_API::request($this->generate_payment_request($order, $source));
494 494
 
495
-				if ( ! empty( $response->error ) ) {
496
-					if ( 0 === sizeof( $retry_callbacks ) ) {
497
-						throw new Exception( $response->error->message );
495
+				if ( ! empty($response->error)) {
496
+					if (0 === sizeof($retry_callbacks)) {
497
+						throw new Exception($response->error->message);
498 498
 					} else {
499
-						$retry_callback = array_shift( $retry_callbacks );
500
-						call_user_func( array( $this, $retry_callback ), $order );
499
+						$retry_callback = array_shift($retry_callbacks);
500
+						call_user_func(array($this, $retry_callback), $order);
501 501
 					}
502 502
 				} else {
503 503
 					// Successful
504
-					$this->process_response( $response, $order );
504
+					$this->process_response($response, $order);
505 505
 					break;
506 506
 				}
507 507
 			}
508
-		} catch ( Exception $e ) {
508
+		} catch (Exception $e) {
509 509
 			/* translators: error message */
510
-			$order_note = sprintf( __( 'Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe' ), $e->getMessage() );
510
+			$order_note = sprintf(__('Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe'), $e->getMessage());
511 511
 
512 512
 			// Mark order as failed if not already set,
513 513
 			// otherwise, make sure we add the order note so we can detect when someone fails to check out multiple times
514
-			if ( ! $order->has_status( 'failed' ) ) {
515
-				$order->update_status( 'failed', $order_note );
514
+			if ( ! $order->has_status('failed')) {
515
+				$order->update_status('failed', $order_note);
516 516
 			} else {
517
-				$order->add_order_note( $order_note );
517
+				$order->add_order_note($order_note);
518 518
 			}
519 519
 		}
520 520
 	}
Please login to merge, or discard this patch.
tests/phpunit/test-wc-stripe.php 1 patch
Spacing   +26 added lines, -26 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,28 +76,28 @@  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
 
103 103
 	/**
@@ -109,12 +109,12 @@  discard block
 block discarded – undo
109 109
 		$source = new stdClass();
110 110
 		$source->type = 'three_d_secure';
111 111
 
112
-		$this->assertEquals( true, $stripe->is_3ds_card( $source ) );
112
+		$this->assertEquals(true, $stripe->is_3ds_card($source));
113 113
 
114 114
 		$source = new stdClass();
115 115
 		$source->type = 'card';
116 116
 
117
-		$this->assertEquals( false, $stripe->is_3ds_card( $source ) );
117
+		$this->assertEquals(false, $stripe->is_3ds_card($source));
118 118
 	}
119 119
 
120 120
 	/**
@@ -128,20 +128,20 @@  discard block
 block discarded – undo
128 128
 		$source->card = new stdClass();
129 129
 		$source->card->three_d_secure = 'required';
130 130
 
131
-		$this->assertEquals( true, $stripe->is_3ds_required( $source ) );
131
+		$this->assertEquals(true, $stripe->is_3ds_required($source));
132 132
 
133 133
 		$source = new stdClass();
134 134
 		$source->type = 'card';
135 135
 		$source->card = new stdClass();
136 136
 		$source->card->three_d_secure = 'optional';
137 137
 
138
-		$this->assertEquals( false, $stripe->is_3ds_required( $source ) );
138
+		$this->assertEquals(false, $stripe->is_3ds_required($source));
139 139
 
140 140
 		$source = new stdClass();
141 141
 		$source->type = 'card';
142 142
 		$source->card = new stdClass();
143 143
 		$source->card->three_d_secure = 'not_supported';
144 144
 
145
-		$this->assertEquals( false, $stripe->is_3ds_required( $source ) );
145
+		$this->assertEquals(false, $stripe->is_3ds_required($source));
146 146
 	}
147 147
 }
Please login to merge, or discard this patch.
tests/phpunit/bootstrap.php 1 patch
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -1,28 +1,28 @@
 block discarded – undo
1 1
 <?php
2 2
 
3
-$_tests_dir = getenv( 'WP_TESTS_DIR' );
4
-if ( ! $_tests_dir ) {
3
+$_tests_dir = getenv('WP_TESTS_DIR');
4
+if ( ! $_tests_dir) {
5 5
 	$_tests_dir = '/tmp/wordpress-tests-lib';
6 6
 }
7 7
 
8 8
 require_once $_tests_dir . '/includes/functions.php';
9 9
 
10 10
 function _manually_load_plugin() {
11
-	$plugin_dir = dirname( dirname( dirname( dirname( __FILE__ ) ) ) ) . '/';
11
+	$plugin_dir = dirname(dirname(dirname(dirname(__FILE__)))) . '/';
12 12
 	require $plugin_dir . 'woocommerce-gateway-stripe/woocommerce-gateway-stripe.php';
13 13
 	require $plugin_dir . 'woocommerce/woocommerce.php';
14 14
 }
15 15
 
16
-tests_add_filter( 'muplugins_loaded', '_manually_load_plugin' );
16
+tests_add_filter('muplugins_loaded', '_manually_load_plugin');
17 17
 
18 18
 require $_tests_dir . '/includes/bootstrap.php';
19 19
 
20
-$wc_tests_framework_base_dir = dirname( dirname( dirname( dirname( __FILE__ ) ) ) ) . '/woocommerce/tests/framework/';
21
-require_once( $wc_tests_framework_base_dir . 'class-wc-mock-session-handler.php' );
22
-require_once( $wc_tests_framework_base_dir . 'class-wc-unit-test-case.php' );
23
-require_once( $wc_tests_framework_base_dir . 'helpers/class-wc-helper-product.php' );
24
-require_once( $wc_tests_framework_base_dir . 'helpers/class-wc-helper-coupon.php' );
25
-require_once( $wc_tests_framework_base_dir . 'helpers/class-wc-helper-fee.php' );
26
-require_once( $wc_tests_framework_base_dir . 'helpers/class-wc-helper-shipping.php' );
27
-require_once( $wc_tests_framework_base_dir . 'helpers/class-wc-helper-customer.php' );
28
-require_once( $wc_tests_framework_base_dir . 'helpers/class-wc-helper-order.php' );
20
+$wc_tests_framework_base_dir = dirname(dirname(dirname(dirname(__FILE__)))) . '/woocommerce/tests/framework/';
21
+require_once($wc_tests_framework_base_dir . 'class-wc-mock-session-handler.php');
22
+require_once($wc_tests_framework_base_dir . 'class-wc-unit-test-case.php');
23
+require_once($wc_tests_framework_base_dir . 'helpers/class-wc-helper-product.php');
24
+require_once($wc_tests_framework_base_dir . 'helpers/class-wc-helper-coupon.php');
25
+require_once($wc_tests_framework_base_dir . 'helpers/class-wc-helper-fee.php');
26
+require_once($wc_tests_framework_base_dir . 'helpers/class-wc-helper-shipping.php');
27
+require_once($wc_tests_framework_base_dir . 'helpers/class-wc-helper-customer.php');
28
+require_once($wc_tests_framework_base_dir . 'helpers/class-wc-helper-order.php');
Please login to merge, or discard this patch.
includes/class-wc-stripe-order-handler.php 1 patch
Spacing   +171 added lines, -171 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) {
2
+if ( ! defined('ABSPATH')) {
3 3
 	exit;
4 4
 }
5 5
 
@@ -23,12 +23,12 @@  discard block
 block discarded – undo
23 23
 
24 24
 		$this->retry_interval = 2;
25 25
 
26
-		add_action( 'wp', array( $this, 'maybe_process_redirect_order' ) );
27
-		add_action( 'woocommerce_order_status_on-hold_to_processing', array( $this, 'capture_payment' ) );
28
-		add_action( 'woocommerce_order_status_on-hold_to_completed', array( $this, 'capture_payment' ) );
29
-		add_action( 'woocommerce_order_status_on-hold_to_cancelled', array( $this, 'cancel_payment' ) );
30
-		add_action( 'woocommerce_order_status_on-hold_to_refunded', array( $this, 'cancel_payment' ) );
31
-		add_action( 'wc_ajax_wc_stripe_validate_checkout', array( $this, 'validate_checkout' ) );
26
+		add_action('wp', array($this, 'maybe_process_redirect_order'));
27
+		add_action('woocommerce_order_status_on-hold_to_processing', array($this, 'capture_payment'));
28
+		add_action('woocommerce_order_status_on-hold_to_completed', array($this, 'capture_payment'));
29
+		add_action('woocommerce_order_status_on-hold_to_cancelled', array($this, 'cancel_payment'));
30
+		add_action('woocommerce_order_status_on-hold_to_refunded', array($this, 'cancel_payment'));
31
+		add_action('wc_ajax_wc_stripe_validate_checkout', array($this, 'validate_checkout'));
32 32
 	}
33 33
 
34 34
 	/**
@@ -49,25 +49,25 @@  discard block
 block discarded – undo
49 49
 	 * @since 4.0.0
50 50
 	 * @version 4.0.0
51 51
 	 */
52
-	public function process_redirect_payment( $order_id, $retry = true ) {
52
+	public function process_redirect_payment($order_id, $retry = true) {
53 53
 		try {
54
-			$source = wc_clean( $_GET['source'] );
54
+			$source = wc_clean($_GET['source']);
55 55
 
56
-			if ( empty( $source ) ) {
56
+			if (empty($source)) {
57 57
 				return;
58 58
 			}
59 59
 
60
-			if ( empty( $order_id ) ) {
60
+			if (empty($order_id)) {
61 61
 				return;
62 62
 			}
63 63
 
64
-			$order = wc_get_order( $order_id );
64
+			$order = wc_get_order($order_id);
65 65
 
66
-			if ( ! is_object( $order ) ) {
66
+			if ( ! is_object($order)) {
67 67
 				return;
68 68
 			}
69 69
 
70
-			if ( 'processing' === $order->get_status() || 'completed' === $order->get_status() || 'on-hold' === $order->get_status() ) {
70
+			if ('processing' === $order->get_status() || 'completed' === $order->get_status() || 'on-hold' === $order->get_status()) {
71 71
 				return;
72 72
 			}
73 73
 
@@ -75,127 +75,127 @@  discard block
 block discarded – undo
75 75
 			$response = null;
76 76
 
77 77
 			// This will throw exception if not valid.
78
-			$this->validate_minimum_order_amount( $order );
78
+			$this->validate_minimum_order_amount($order);
79 79
 
80
-			WC_Stripe_Logger::log( "Info: (Redirect) Begin processing payment for order $order_id for the amount of {$order->get_total()}" );
80
+			WC_Stripe_Logger::log("Info: (Redirect) Begin processing payment for order $order_id for the amount of {$order->get_total()}");
81 81
 
82 82
 			/**
83 83
 			 * First check if the source is chargeable at this time. If not,
84 84
 			 * webhook will take care of it later.
85 85
 			 */
86
-			$source_info = WC_Stripe_API::retrieve( 'sources/' . $source );
86
+			$source_info = WC_Stripe_API::retrieve('sources/' . $source);
87 87
 
88
-			if ( ! empty( $source_info->error ) ) {
89
-				throw new WC_Stripe_Exception( print_r( $source_info, true ), $source_info->error->message );
88
+			if ( ! empty($source_info->error)) {
89
+				throw new WC_Stripe_Exception(print_r($source_info, true), $source_info->error->message);
90 90
 			}
91 91
 
92
-			if ( 'failed' === $source_info->status || 'canceled' === $source_info->status ) {
93
-				throw new WC_Stripe_Exception( print_r( $source_info, true ), __( 'Unable to process this payment, please try again or use alternative method.', 'woocommerce-gateway-stripe' ) );
92
+			if ('failed' === $source_info->status || 'canceled' === $source_info->status) {
93
+				throw new WC_Stripe_Exception(print_r($source_info, true), __('Unable to process this payment, please try again or use alternative method.', 'woocommerce-gateway-stripe'));
94 94
 			}
95 95
 
96 96
 			// If already consumed, then ignore request.
97
-			if ( 'consumed' === $source_info->status ) {
97
+			if ('consumed' === $source_info->status) {
98 98
 				return;
99 99
 			}
100 100
 
101 101
 			// If not chargeable, then ignore request.
102
-			if ( 'chargeable' !== $source_info->status ) {
102
+			if ('chargeable' !== $source_info->status) {
103 103
 				return;
104 104
 			}
105 105
 
106 106
 			// Prep source object.
107 107
 			$source_object           = new stdClass();
108 108
 			$source_object->token_id = '';
109
-			$source_object->customer = $this->get_stripe_customer_id( $order );
109
+			$source_object->customer = $this->get_stripe_customer_id($order);
110 110
 			$source_object->source   = $source_info->id;
111 111
 
112 112
 			// Make the request.
113
-			$response = WC_Stripe_API::request( $this->generate_payment_request( $order, $source_object ) );
113
+			$response = WC_Stripe_API::request($this->generate_payment_request($order, $source_object));
114 114
 
115
-			if ( ! empty( $response->error ) ) {
115
+			if ( ! empty($response->error)) {
116 116
 				// If it is an API error such connection or server, let's retry.
117
-				if ( 'api_connection_error' === $response->error->type || 'api_error' === $response->error->type ) {
118
-					if ( $retry ) {
119
-						sleep( 5 );
120
-						return $this->process_redirect_payment( $order_id, false );
117
+				if ('api_connection_error' === $response->error->type || 'api_error' === $response->error->type) {
118
+					if ($retry) {
119
+						sleep(5);
120
+						return $this->process_redirect_payment($order_id, false);
121 121
 					} else {
122
-						$localized_message = __( 'API connection error and retries exhausted.', 'woocommerce-gateway-stripe' );
123
-						$order->add_order_note( $localized_message );
124
-						throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message );
122
+						$localized_message = __('API connection error and retries exhausted.', 'woocommerce-gateway-stripe');
123
+						$order->add_order_note($localized_message);
124
+						throw new WC_Stripe_Exception(print_r($response, true), $localized_message);
125 125
 					}
126 126
 				}
127 127
 
128 128
 				// We want to retry.
129
-				if ( $this->is_retryable_error( $response->error ) ) {
130
-					if ( $retry ) {
129
+				if ($this->is_retryable_error($response->error)) {
130
+					if ($retry) {
131 131
 						// Don't do anymore retries after this.
132
-						if ( 5 <= $this->retry_interval ) {
133
-							return $this->process_redirect_payment( $order_id, false );
132
+						if (5 <= $this->retry_interval) {
133
+							return $this->process_redirect_payment($order_id, false);
134 134
 						}
135 135
 
136
-						sleep( $this->retry_interval );
136
+						sleep($this->retry_interval);
137 137
 
138 138
 						$this->retry_interval++;
139
-						return $this->process_redirect_payment( $order_id, true );
139
+						return $this->process_redirect_payment($order_id, true);
140 140
 					} else {
141
-						$localized_message = __( 'On going requests error and retries exhausted.', 'woocommerce-gateway-stripe' );
142
-						$order->add_order_note( $localized_message );
143
-						throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message );
141
+						$localized_message = __('On going requests error and retries exhausted.', 'woocommerce-gateway-stripe');
142
+						$order->add_order_note($localized_message);
143
+						throw new WC_Stripe_Exception(print_r($response, true), $localized_message);
144 144
 					}
145 145
 				}
146 146
 
147 147
 				// Customer param wrong? The user may have been deleted on stripe's end. Remove customer_id. Can be retried without.
148
-				if ( preg_match( '/No such customer/i', $response->error->message ) && $retry ) {
149
-					if ( WC_Stripe_Helper::is_pre_30() ) {
150
-						delete_user_meta( $order->customer_user, '_stripe_customer_id' );
151
-						delete_post_meta( $order_id, '_stripe_customer_id' );
148
+				if (preg_match('/No such customer/i', $response->error->message) && $retry) {
149
+					if (WC_Stripe_Helper::is_pre_30()) {
150
+						delete_user_meta($order->customer_user, '_stripe_customer_id');
151
+						delete_post_meta($order_id, '_stripe_customer_id');
152 152
 					} else {
153
-						delete_user_meta( $order->get_customer_id(), '_stripe_customer_id' );
154
-						$order->delete_meta_data( '_stripe_customer_id' );
153
+						delete_user_meta($order->get_customer_id(), '_stripe_customer_id');
154
+						$order->delete_meta_data('_stripe_customer_id');
155 155
 						$order->save();
156 156
 					}
157 157
 
158
-					return $this->process_redirect_payment( $order_id, false );
158
+					return $this->process_redirect_payment($order_id, false);
159 159
 
160
-				} elseif ( preg_match( '/No such token/i', $response->error->message ) && $source_object->token_id ) {
160
+				} elseif (preg_match('/No such token/i', $response->error->message) && $source_object->token_id) {
161 161
 					// Source param wrong? The CARD may have been deleted on stripe's end. Remove token and show message.
162 162
 
163
-					$wc_token = WC_Payment_Tokens::get( $source_object->token_id );
163
+					$wc_token = WC_Payment_Tokens::get($source_object->token_id);
164 164
 					$wc_token->delete();
165
-					$message = __( 'This card is no longer available and has been removed.', 'woocommerce-gateway-stripe' );
166
-					$order->add_order_note( $message );
167
-					throw new WC_Stripe_Exception( print_r( $response, true ), $message );
165
+					$message = __('This card is no longer available and has been removed.', 'woocommerce-gateway-stripe');
166
+					$order->add_order_note($message);
167
+					throw new WC_Stripe_Exception(print_r($response, true), $message);
168 168
 				}
169 169
 
170 170
 				$localized_messages = WC_Stripe_Helper::get_localized_messages();
171 171
 
172
-				if ( 'card_error' === $response->error->type ) {
173
-					$message = isset( $localized_messages[ $response->error->code ] ) ? $localized_messages[ $response->error->code ] : $response->error->message;
172
+				if ('card_error' === $response->error->type) {
173
+					$message = isset($localized_messages[$response->error->code]) ? $localized_messages[$response->error->code] : $response->error->message;
174 174
 				} else {
175
-					$message = isset( $localized_messages[ $response->error->type ] ) ? $localized_messages[ $response->error->type ] : $response->error->message;
175
+					$message = isset($localized_messages[$response->error->type]) ? $localized_messages[$response->error->type] : $response->error->message;
176 176
 				}
177 177
 
178
-				throw new WC_Stripe_Exception( print_r( $response, true ), $message );
178
+				throw new WC_Stripe_Exception(print_r($response, true), $message);
179 179
 			}
180 180
 
181
-			do_action( 'wc_gateway_stripe_process_redirect_payment', $response, $order );
181
+			do_action('wc_gateway_stripe_process_redirect_payment', $response, $order);
182 182
 
183
-			$this->process_response( $response, $order );
183
+			$this->process_response($response, $order);
184 184
 
185
-		} catch ( WC_Stripe_Exception $e ) {
186
-			WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() );
185
+		} catch (WC_Stripe_Exception $e) {
186
+			WC_Stripe_Logger::log('Error: ' . $e->getMessage());
187 187
 
188
-			do_action( 'wc_gateway_stripe_process_redirect_payment_error', $e, $order );
188
+			do_action('wc_gateway_stripe_process_redirect_payment_error', $e, $order);
189 189
 
190 190
 			/* translators: error message */
191
-			$order->update_status( 'failed', sprintf( __( 'Stripe payment failed: %s', 'woocommerce-gateway-stripe' ), $e->getLocalizedMessage() ) );
191
+			$order->update_status('failed', sprintf(__('Stripe payment failed: %s', 'woocommerce-gateway-stripe'), $e->getLocalizedMessage()));
192 192
 
193
-			if ( $order->has_status( array( 'pending', 'failed' ) ) ) {
194
-				$this->send_failed_order_email( $order_id );
193
+			if ($order->has_status(array('pending', 'failed'))) {
194
+				$this->send_failed_order_email($order_id);
195 195
 			}
196 196
 
197
-			wc_add_notice( $e->getLocalizedMessage(), 'error' );
198
-			wp_safe_redirect( wc_get_checkout_url() );
197
+			wc_add_notice($e->getLocalizedMessage(), 'error');
198
+			wp_safe_redirect(wc_get_checkout_url());
199 199
 			exit;
200 200
 		}
201 201
 	}
@@ -207,13 +207,13 @@  discard block
 block discarded – undo
207 207
 	 * @version 4.0.0
208 208
 	 */
209 209
 	public function maybe_process_redirect_order() {
210
-		if ( ! is_order_received_page() || empty( $_GET['client_secret'] ) || empty( $_GET['source'] ) ) {
210
+		if ( ! is_order_received_page() || empty($_GET['client_secret']) || empty($_GET['source'])) {
211 211
 			return;
212 212
 		}
213 213
 
214
-		$order_id = wc_clean( $_GET['order_id'] );
214
+		$order_id = wc_clean($_GET['order_id']);
215 215
 
216
-		$this->process_redirect_payment( $order_id );
216
+		$this->process_redirect_payment($order_id);
217 217
 	}
218 218
 
219 219
 	/**
@@ -223,52 +223,52 @@  discard block
 block discarded – undo
223 223
 	 * @version 4.0.0
224 224
 	 * @param  int $order_id
225 225
 	 */
226
-	public function capture_payment( $order_id ) {
227
-		$order = wc_get_order( $order_id );
226
+	public function capture_payment($order_id) {
227
+		$order = wc_get_order($order_id);
228 228
 
229
-		if ( 'stripe' === ( WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method() ) ) {
230
-			$charge   = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_transaction_id', true ) : $order->get_transaction_id();
231
-			$captured = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_stripe_charge_captured', true ) : $order->get_meta( '_stripe_charge_captured', true );
229
+		if ('stripe' === (WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method())) {
230
+			$charge   = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_transaction_id', true) : $order->get_transaction_id();
231
+			$captured = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_stripe_charge_captured', true) : $order->get_meta('_stripe_charge_captured', true);
232 232
 
233
-			if ( $charge && 'no' === $captured ) {
233
+			if ($charge && 'no' === $captured) {
234 234
 				$order_total = $order->get_total();
235 235
 
236
-				if ( 0 < $order->get_total_refunded() ) {
236
+				if (0 < $order->get_total_refunded()) {
237 237
 					$order_total = $order_total - $order->get_total_refunded();
238 238
 				}
239 239
 
240
-				$result = WC_Stripe_API::request( array(
241
-					'amount'   => WC_Stripe_Helper::get_stripe_amount( $order_total ),
240
+				$result = WC_Stripe_API::request(array(
241
+					'amount'   => WC_Stripe_Helper::get_stripe_amount($order_total),
242 242
 					'expand[]' => 'balance_transaction',
243
-				), 'charges/' . $charge . '/capture' );
243
+				), 'charges/' . $charge . '/capture');
244 244
 
245
-				if ( ! empty( $result->error ) ) {
245
+				if ( ! empty($result->error)) {
246 246
 					/* translators: error message */
247
-					$order->update_status( 'failed', sprintf( __( 'Unable to capture charge! %s', 'woocommerce-gateway-stripe' ), $result->error->message ) );
247
+					$order->update_status('failed', sprintf(__('Unable to capture charge! %s', 'woocommerce-gateway-stripe'), $result->error->message));
248 248
 				} else {
249 249
 					/* translators: transaction id */
250
-					$order->add_order_note( sprintf( __( 'Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe' ), $result->id ) );
251
-					WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, '_stripe_charge_captured', 'yes' ) : $order->update_meta_data( '_stripe_charge_captured', 'yes' );
250
+					$order->add_order_note(sprintf(__('Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe'), $result->id));
251
+					WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, '_stripe_charge_captured', 'yes') : $order->update_meta_data('_stripe_charge_captured', 'yes');
252 252
 
253 253
 					// Store other data such as fees
254
-					WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, '_transaction_id', $result->id ) : $order->set_transaction_id( $result->id );
254
+					WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, '_transaction_id', $result->id) : $order->set_transaction_id($result->id);
255 255
 
256
-					if ( isset( $result->balance_transaction ) && isset( $result->balance_transaction->fee ) ) {
256
+					if (isset($result->balance_transaction) && isset($result->balance_transaction->fee)) {
257 257
 						// Fees and Net needs to both come from Stripe to be accurate as the returned
258 258
 						// values are in the local currency of the Stripe account, not from WC.
259
-						$fee = ! empty( $result->balance_transaction->fee ) ? WC_Stripe_Helper::format_balance_fee( $result->balance_transaction, 'fee' ) : 0;
260
-						$net = ! empty( $result->balance_transaction->net ) ? WC_Stripe_Helper::format_balance_fee( $result->balance_transaction, 'net' ) : 0;
261
-						WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, parent::META_NAME_FEE, $fee ) : $order->update_meta_data( parent::META_NAME_FEE, $fee );
262
-						WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, parent::META_NAME_NET, $net ) : $order->update_meta_data( parent::META_NAME_NET, $net );
259
+						$fee = ! empty($result->balance_transaction->fee) ? WC_Stripe_Helper::format_balance_fee($result->balance_transaction, 'fee') : 0;
260
+						$net = ! empty($result->balance_transaction->net) ? WC_Stripe_Helper::format_balance_fee($result->balance_transaction, 'net') : 0;
261
+						WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, parent::META_NAME_FEE, $fee) : $order->update_meta_data(parent::META_NAME_FEE, $fee);
262
+						WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, parent::META_NAME_NET, $net) : $order->update_meta_data(parent::META_NAME_NET, $net);
263 263
 					}
264 264
 
265
-					if ( is_callable( array( $order, 'save' ) ) ) {
265
+					if (is_callable(array($order, 'save'))) {
266 266
 						$order->save();
267 267
 					}
268 268
 				}
269 269
 
270 270
 				// This hook fires when admin manually changes order status to processing or completed.
271
-				do_action( 'woocommerce_stripe_process_manual_capture', $order, $result );
271
+				do_action('woocommerce_stripe_process_manual_capture', $order, $result);
272 272
 			}
273 273
 		}
274 274
 	}
@@ -280,14 +280,14 @@  discard block
 block discarded – undo
280 280
 	 * @version 4.0.0
281 281
 	 * @param  int $order_id
282 282
 	 */
283
-	public function cancel_payment( $order_id ) {
284
-		$order = wc_get_order( $order_id );
283
+	public function cancel_payment($order_id) {
284
+		$order = wc_get_order($order_id);
285 285
 
286
-		if ( 'stripe' === ( WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method() ) ) {
287
-			$this->process_refund( $order_id );
286
+		if ('stripe' === (WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method())) {
287
+			$this->process_refund($order_id);
288 288
 
289 289
 			// This hook fires when admin manually changes order status to cancel.
290
-			do_action( 'woocommerce_stripe_process_manual_cancel', $order );
290
+			do_action('woocommerce_stripe_process_manual_cancel', $order);
291 291
 		}
292 292
 	}
293 293
 
@@ -299,21 +299,21 @@  discard block
 block discarded – undo
299 299
 	 * @param string $field
300 300
 	 * @return string $error_field
301 301
 	 */
302
-	public function normalize_field( $field ) {
302
+	public function normalize_field($field) {
303 303
 		$checkout_fields = WC()->checkout->get_checkout_fields();
304 304
 		$org_str         = array();
305 305
 		$replace_str     = array();
306 306
 
307
-		if ( array_key_exists( $field, $checkout_fields['billing'] ) ) {
308
-			$error_field = __( 'Billing', 'woocommerce-gateway-stripe' ) . ' ' . $checkout_fields['billing'][ $field ]['label'];
309
-		} elseif ( array_key_exists( $field, $checkout_fields['shipping'] ) ) {
310
-			$error_field = __( 'Shipping', 'woocommerce-gateway-stripe' ) . ' ' . $checkout_fields['shipping'][ $field ]['label'];
311
-		} elseif ( array_key_exists( $field, $checkout_fields['order'] ) ) {
312
-			$error_field = $checkout_fields['order'][ $field ]['label'];
313
-		} elseif ( array_key_exists( $field, $checkout_fields['account'] ) ) {
314
-			$error_field = $checkout_fields['account'][ $field ]['label'];
307
+		if (array_key_exists($field, $checkout_fields['billing'])) {
308
+			$error_field = __('Billing', 'woocommerce-gateway-stripe') . ' ' . $checkout_fields['billing'][$field]['label'];
309
+		} elseif (array_key_exists($field, $checkout_fields['shipping'])) {
310
+			$error_field = __('Shipping', 'woocommerce-gateway-stripe') . ' ' . $checkout_fields['shipping'][$field]['label'];
311
+		} elseif (array_key_exists($field, $checkout_fields['order'])) {
312
+			$error_field = $checkout_fields['order'][$field]['label'];
313
+		} elseif (array_key_exists($field, $checkout_fields['account'])) {
314
+			$error_field = $checkout_fields['account'][$field]['label'];
315 315
 		} else {
316
-			$error_field = str_replace( '_', ' ', $field );
316
+			$error_field = str_replace('_', ' ', $field);
317 317
 
318 318
 			$org_str[]     = 'stripe';
319 319
 			$replace_str[] = '';
@@ -328,9 +328,9 @@  discard block
 block discarded – undo
328 328
 			$replace_str[] = 'SOFORT';
329 329
 
330 330
 			$org_str[]     = 'owner';
331
-			$replace_str[] = __( 'Owner', 'woocommerce-gateway-stripe' );
331
+			$replace_str[] = __('Owner', 'woocommerce-gateway-stripe');
332 332
 
333
-			$error_field   = str_replace( $org_str, $replace_str, $error_field );
333
+			$error_field   = str_replace($org_str, $replace_str, $error_field);
334 334
 		}
335 335
 
336 336
 		return $error_field;
@@ -343,135 +343,135 @@  discard block
 block discarded – undo
343 343
 	 * @version 4.0.0
344 344
 	 */
345 345
 	public function validate_checkout() {
346
-		if ( ! wp_verify_nonce( $_POST['nonce'], '_wc_stripe_nonce' ) ) {
347
-			wp_die( __( 'Cheatin&#8217; huh?', 'woocommerce-gateway-stripe' ) );
346
+		if ( ! wp_verify_nonce($_POST['nonce'], '_wc_stripe_nonce')) {
347
+			wp_die(__('Cheatin&#8217; huh?', 'woocommerce-gateway-stripe'));
348 348
 		}
349 349
 
350
-		parse_str( $_POST['required_fields'], $required_fields );
351
-		parse_str( $_POST['all_fields'], $all_fields );
350
+		parse_str($_POST['required_fields'], $required_fields);
351
+		parse_str($_POST['all_fields'], $all_fields);
352 352
 		$validate_shipping_fields = false;
353 353
 		$create_account           = false;
354 354
 		$errors                   = new WP_Error();
355
-		$all_fields               = apply_filters( 'wc_stripe_validate_checkout_all_fields', $all_fields );
356
-		$required_fields          = apply_filters( 'wc_stripe_validate_checkout_required_fields', $required_fields );
355
+		$all_fields               = apply_filters('wc_stripe_validate_checkout_all_fields', $all_fields);
356
+		$required_fields          = apply_filters('wc_stripe_validate_checkout_required_fields', $required_fields);
357 357
 
358
-		array_walk_recursive( $required_fields, 'wc_clean' );
359
-		array_walk_recursive( $all_fields, 'wc_clean' );
358
+		array_walk_recursive($required_fields, 'wc_clean');
359
+		array_walk_recursive($all_fields, 'wc_clean');
360 360
 
361 361
 		/**
362 362
 		 * If ship to different address checkbox is checked then we need
363 363
 		 * to validate shipping fields too.
364 364
 		 */
365
-		if ( isset( $all_fields['ship_to_different_address'] ) ) {
365
+		if (isset($all_fields['ship_to_different_address'])) {
366 366
 			$validate_shipping_fields = true;
367 367
 		}
368 368
 
369 369
 		// Check if createaccount is checked.
370
-		if ( isset( $all_fields['createaccount'] ) ) {
370
+		if (isset($all_fields['createaccount'])) {
371 371
 			$create_account = true;
372 372
 		}
373 373
 
374 374
 		// Check if required fields are empty.
375
-		foreach ( $required_fields as $field => $field_value ) {
375
+		foreach ($required_fields as $field => $field_value) {
376 376
 			// Check for shipping field.
377
-			if ( preg_match( '/^shipping_/', $field ) && ! $validate_shipping_fields ) {
377
+			if (preg_match('/^shipping_/', $field) && ! $validate_shipping_fields) {
378 378
 				continue;
379 379
 			}
380 380
 
381 381
 			// Check create account name.
382
-			if ( 'account_username' === $field && ! $create_account ) {
382
+			if ('account_username' === $field && ! $create_account) {
383 383
 				continue;
384 384
 			}
385 385
 
386 386
 			// Check create account password.
387
-			if ( 'account_password' === $field && ! $create_account ) {
387
+			if ('account_password' === $field && ! $create_account) {
388 388
 				continue;
389 389
 			}
390 390
 
391
-			if ( empty( $field_value ) || '-1' === $field_value ) {
392
-				$error_field = $this->normalize_field( $field );
391
+			if (empty($field_value) || '-1' === $field_value) {
392
+				$error_field = $this->normalize_field($field);
393 393
 				/* translators: error field name */
394
-				$errors->add( 'validation', sprintf( __( '<strong>%s</strong> cannot be empty', 'woocommerce-gateway-stripe' ), $error_field ) );
394
+				$errors->add('validation', sprintf(__('<strong>%s</strong> cannot be empty', 'woocommerce-gateway-stripe'), $error_field));
395 395
 			}
396 396
 		}
397 397
 
398 398
 		// Check if email is valid format.
399
-		if ( ! empty( $required_fields['billing_email'] ) && ! is_email( $required_fields['billing_email'] ) ) {
400
-			$errors->add( 'validation', __( '<strong>Billing Email</strong> is not valid', 'woocommerce-gateway-stripe' ) );
399
+		if ( ! empty($required_fields['billing_email']) && ! is_email($required_fields['billing_email'])) {
400
+			$errors->add('validation', __('<strong>Billing Email</strong> is not valid', 'woocommerce-gateway-stripe'));
401 401
 		}
402 402
 
403 403
 		// Check if phone number is valid format.
404
-		if ( ! empty( $required_fields['billing_phone'] ) ) {
405
-			$phone = wc_format_phone_number( $required_fields['billing_phone'] );
404
+		if ( ! empty($required_fields['billing_phone'])) {
405
+			$phone = wc_format_phone_number($required_fields['billing_phone']);
406 406
 
407
-			if ( '' !== $phone && ! WC_Validation::is_phone( $phone ) ) {
407
+			if ('' !== $phone && ! WC_Validation::is_phone($phone)) {
408 408
 				/* translators: %s: phone number */
409
-				$errors->add( 'validation', __( 'Please enter a valid phone number.', 'woocommerce-gateway-stripe' ) );
409
+				$errors->add('validation', __('Please enter a valid phone number.', 'woocommerce-gateway-stripe'));
410 410
 			}
411 411
 		}
412 412
 
413 413
 		// Check if postal code is valid format.
414
-		if ( ! empty( $required_fields['billing_postcode'] ) ) {
415
-			$country = isset( $required_fields['billing_country'] ) ? $required_fields['billing_country'] : WC()->customer->get_billing_country();
416
-			$postcode = wc_format_postcode( $required_fields['billing_postcode'], $country );
414
+		if ( ! empty($required_fields['billing_postcode'])) {
415
+			$country = isset($required_fields['billing_country']) ? $required_fields['billing_country'] : WC()->customer->get_billing_country();
416
+			$postcode = wc_format_postcode($required_fields['billing_postcode'], $country);
417 417
 
418
-			if ( '' !== $required_fields['billing_postcode'] && ! WC_Validation::is_postcode( $postcode, $country ) ) {
419
-				$errors->add( 'validation', __( 'Please enter a valid billing postcode / ZIP.', 'woocommerce-gateway-stripe' ) );
418
+			if ('' !== $required_fields['billing_postcode'] && ! WC_Validation::is_postcode($postcode, $country)) {
419
+				$errors->add('validation', __('Please enter a valid billing postcode / ZIP.', 'woocommerce-gateway-stripe'));
420 420
 			}
421 421
 		}
422 422
 
423
-		if ( WC()->cart->needs_shipping() && $validate_shipping_fields ) {
423
+		if (WC()->cart->needs_shipping() && $validate_shipping_fields) {
424 424
 			// Check if postal code is valid format.
425
-			if ( ! empty( $required_fields['shipping_postcode'] ) ) {
426
-				$country = isset( $required_fields['shipping_country'] ) ? $required_fields['shipping_country'] : WC()->customer->get_shipping_country();
427
-				$postcode = wc_format_postcode( $required_fields['shipping_postcode'], $country );
425
+			if ( ! empty($required_fields['shipping_postcode'])) {
426
+				$country = isset($required_fields['shipping_country']) ? $required_fields['shipping_country'] : WC()->customer->get_shipping_country();
427
+				$postcode = wc_format_postcode($required_fields['shipping_postcode'], $country);
428 428
 
429
-				if ( '' !== $required_fields['shipping_postcode'] && ! WC_Validation::is_postcode( $postcode, $country ) ) {
430
-					$errors->add( 'validation', __( 'Please enter a valid shipping postcode / ZIP.', 'woocommerce-gateway-stripe' ) );
429
+				if ('' !== $required_fields['shipping_postcode'] && ! WC_Validation::is_postcode($postcode, $country)) {
430
+					$errors->add('validation', __('Please enter a valid shipping postcode / ZIP.', 'woocommerce-gateway-stripe'));
431 431
 				}
432 432
 			}
433 433
 		}
434 434
 
435
-		if ( WC()->cart->needs_shipping() ) {
435
+		if (WC()->cart->needs_shipping()) {
436 436
 			$shipping_country = WC()->customer->get_shipping_country();
437 437
 
438
-			if ( empty( $shipping_country ) ) {
439
-				$errors->add( 'shipping', __( 'Please enter an address to continue.', 'woocommerce-gateway-stripe' ) );
440
-			} elseif ( ! in_array( WC()->customer->get_shipping_country(), array_keys( WC()->countries->get_shipping_countries() ) ) ) {
438
+			if (empty($shipping_country)) {
439
+				$errors->add('shipping', __('Please enter an address to continue.', 'woocommerce-gateway-stripe'));
440
+			} elseif ( ! in_array(WC()->customer->get_shipping_country(), array_keys(WC()->countries->get_shipping_countries()))) {
441 441
 				/* translators: country name */
442
-				$errors->add( 'shipping', sprintf( __( 'Unfortunately <strong>we do not ship %s</strong>. Please enter an alternative shipping address.', 'woocommerce-gateway-stripe' ), WC()->countries->shipping_to_prefix() . ' ' . WC()->customer->get_shipping_country() ) );
442
+				$errors->add('shipping', sprintf(__('Unfortunately <strong>we do not ship %s</strong>. Please enter an alternative shipping address.', 'woocommerce-gateway-stripe'), WC()->countries->shipping_to_prefix() . ' ' . WC()->customer->get_shipping_country()));
443 443
 			} else {
444
-				$chosen_shipping_methods = WC()->session->get( 'chosen_shipping_methods' );
444
+				$chosen_shipping_methods = WC()->session->get('chosen_shipping_methods');
445 445
 
446
-				foreach ( WC()->shipping->get_packages() as $i => $package ) {
447
-					if ( ! isset( $chosen_shipping_methods[ $i ], $package['rates'][ $chosen_shipping_methods[ $i ] ] ) ) {
448
-						$errors->add( 'shipping', __( 'No shipping method has been selected. Please double check your address, or contact us if you need any help.', 'woocommerce-gateway-stripe' ) );
446
+				foreach (WC()->shipping->get_packages() as $i => $package) {
447
+					if ( ! isset($chosen_shipping_methods[$i], $package['rates'][$chosen_shipping_methods[$i]])) {
448
+						$errors->add('shipping', __('No shipping method has been selected. Please double check your address, or contact us if you need any help.', 'woocommerce-gateway-stripe'));
449 449
 					}
450 450
 				}
451 451
 			}
452 452
 		}
453 453
 
454
-		if ( WC()->cart->needs_payment() ) {
454
+		if (WC()->cart->needs_payment()) {
455 455
 			$available_gateways = WC()->payment_gateways->get_available_payment_gateways();
456 456
 
457
-			if ( ! isset( $available_gateways[ $all_fields['payment_method'] ] ) ) {
458
-				$errors->add( 'payment', __( 'Invalid payment method.', 'woocommerce-gateway-stripe' ) );
457
+			if ( ! isset($available_gateways[$all_fields['payment_method']])) {
458
+				$errors->add('payment', __('Invalid payment method.', 'woocommerce-gateway-stripe'));
459 459
 			} else {
460
-				$available_gateways[ $all_fields['payment_method'] ]->validate_fields();
460
+				$available_gateways[$all_fields['payment_method']]->validate_fields();
461 461
 			}
462 462
 		}
463 463
 
464
-		if ( empty( $all_fields['woocommerce_checkout_update_totals'] ) && empty( $all_fields['terms'] ) && apply_filters( 'woocommerce_checkout_show_terms', wc_get_page_id( 'terms' ) > 0 ) ) {
465
-			$errors->add( 'terms', __( 'You must accept our Terms &amp; Conditions.', 'woocommerce-gateway-stripe' ) );
464
+		if (empty($all_fields['woocommerce_checkout_update_totals']) && empty($all_fields['terms']) && apply_filters('woocommerce_checkout_show_terms', wc_get_page_id('terms') > 0)) {
465
+			$errors->add('terms', __('You must accept our Terms &amp; Conditions.', 'woocommerce-gateway-stripe'));
466 466
 		}
467 467
 
468
-		do_action( 'wc_stripe_validate_checkout', $required_fields, $all_fields, $errors );
468
+		do_action('wc_stripe_validate_checkout', $required_fields, $all_fields, $errors);
469 469
 
470
-		if ( 0 === count( $errors->errors ) ) {
471
-			wp_send_json( 'success' );
470
+		if (0 === count($errors->errors)) {
471
+			wp_send_json('success');
472 472
 		} else {
473
-			foreach ( $errors->get_error_messages() as $message ) {
474
-				wc_add_notice( $message, 'error' );
473
+			foreach ($errors->get_error_messages() as $message) {
474
+				wc_add_notice($message, 'error');
475 475
 			}
476 476
 
477 477
 			$this->send_ajax_failure_response();
@@ -485,9 +485,9 @@  discard block
 block discarded – undo
485 485
 	 * @version 4.0.0
486 486
 	 */
487 487
 	public function send_ajax_failure_response() {
488
-		if ( is_ajax() ) {
488
+		if (is_ajax()) {
489 489
 			// only print notices if not reloading the checkout, otherwise they're lost in the page reload.
490
-			if ( ! isset( WC()->session->reload_checkout ) ) {
490
+			if ( ! isset(WC()->session->reload_checkout)) {
491 491
 				ob_start();
492 492
 				wc_print_notices();
493 493
 				$messages = ob_get_clean();
@@ -495,14 +495,14 @@  discard block
 block discarded – undo
495 495
 
496 496
 			$response = array(
497 497
 				'result'   => 'failure',
498
-				'messages' => isset( $messages ) ? $messages : '',
499
-				'refresh'  => isset( WC()->session->refresh_totals ),
500
-				'reload'   => isset( WC()->session->reload_checkout ),
498
+				'messages' => isset($messages) ? $messages : '',
499
+				'refresh'  => isset(WC()->session->refresh_totals),
500
+				'reload'   => isset(WC()->session->reload_checkout),
501 501
 			);
502 502
 
503
-			unset( WC()->session->refresh_totals, WC()->session->reload_checkout );
503
+			unset(WC()->session->refresh_totals, WC()->session->reload_checkout);
504 504
 
505
-			wp_send_json( $response );
505
+			wp_send_json($response);
506 506
 		}
507 507
 	}
508 508
 }
Please login to merge, or discard this patch.
includes/compat/class-wc-stripe-compat.php 1 patch
Spacing   +184 added lines, -184 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,23 +15,23 @@  discard block
 block discarded – undo
15 15
 	public function __construct() {
16 16
 		parent::__construct();
17 17
 
18
-		if ( class_exists( 'WC_Subscriptions_Order' ) ) {
19
-			add_action( 'woocommerce_scheduled_subscription_payment_' . $this->id, array( $this, 'scheduled_subscription_payment' ), 10, 2 );
20
-			add_action( 'wcs_resubscribe_order_created', array( $this, 'delete_resubscribe_meta' ), 10 );
21
-			add_action( 'wcs_renewal_order_created', array( $this, 'delete_renewal_meta' ), 10 );
22
-			add_action( 'woocommerce_subscription_failing_payment_method_updated_stripe', array( $this, 'update_failing_payment_method' ), 10, 2 );
18
+		if (class_exists('WC_Subscriptions_Order')) {
19
+			add_action('woocommerce_scheduled_subscription_payment_' . $this->id, array($this, 'scheduled_subscription_payment'), 10, 2);
20
+			add_action('wcs_resubscribe_order_created', array($this, 'delete_resubscribe_meta'), 10);
21
+			add_action('wcs_renewal_order_created', array($this, 'delete_renewal_meta'), 10);
22
+			add_action('woocommerce_subscription_failing_payment_method_updated_stripe', array($this, 'update_failing_payment_method'), 10, 2);
23 23
 
24 24
 			// display the credit card used for a subscription in the "My Subscriptions" table
25
-			add_filter( 'woocommerce_my_subscriptions_payment_method', array( $this, 'maybe_render_subscription_payment_method' ), 10, 2 );
25
+			add_filter('woocommerce_my_subscriptions_payment_method', array($this, 'maybe_render_subscription_payment_method'), 10, 2);
26 26
 
27 27
 			// allow store managers to manually set Stripe as the payment method on a subscription
28
-			add_filter( 'woocommerce_subscription_payment_meta', array( $this, 'add_subscription_payment_meta' ), 10, 2 );
29
-			add_filter( 'woocommerce_subscription_validate_payment_meta', array( $this, 'validate_subscription_payment_meta' ), 10, 2 );
30
-			add_filter( 'wc_stripe_display_save_payment_method_checkbox', array( $this, 'maybe_hide_save_checkbox' ) );
28
+			add_filter('woocommerce_subscription_payment_meta', array($this, 'add_subscription_payment_meta'), 10, 2);
29
+			add_filter('woocommerce_subscription_validate_payment_meta', array($this, 'validate_subscription_payment_meta'), 10, 2);
30
+			add_filter('wc_stripe_display_save_payment_method_checkbox', array($this, 'maybe_hide_save_checkbox'));
31 31
 		}
32 32
 
33
-		if ( class_exists( 'WC_Pre_Orders_Order' ) ) {
34
-			add_action( 'wc_pre_orders_process_pre_order_completion_payment_' . $this->id, array( $this, 'process_pre_order_release_payment' ) );
33
+		if (class_exists('WC_Pre_Orders_Order')) {
34
+			add_action('wc_pre_orders_process_pre_order_completion_payment_' . $this->id, array($this, 'process_pre_order_release_payment'));
35 35
 		}
36 36
 	}
37 37
 
@@ -42,8 +42,8 @@  discard block
 block discarded – undo
42 42
 	 * @since 4.0.0
43 43
 	 * @version 4.0.0
44 44
 	 */
45
-	public function maybe_hide_save_checkbox( $display_tokenization ) {
46
-		if ( WC_Subscriptions_Cart::cart_contains_subscription() ) {
45
+	public function maybe_hide_save_checkbox($display_tokenization) {
46
+		if (WC_Subscriptions_Cart::cart_contains_subscription()) {
47 47
 			return false;
48 48
 		}
49 49
 
@@ -55,8 +55,8 @@  discard block
 block discarded – undo
55 55
 	 * @param  int  $order_id
56 56
 	 * @return boolean
57 57
 	 */
58
-	public function has_subscription( $order_id ) {
59
-		return ( function_exists( 'wcs_order_contains_subscription' ) && ( wcs_order_contains_subscription( $order_id ) || wcs_is_subscription( $order_id ) || wcs_order_contains_renewal( $order_id ) ) );
58
+	public function has_subscription($order_id) {
59
+		return (function_exists('wcs_order_contains_subscription') && (wcs_order_contains_subscription($order_id) || wcs_is_subscription($order_id) || wcs_order_contains_renewal($order_id)));
60 60
 	}
61 61
 
62 62
 	/**
@@ -66,7 +66,7 @@  discard block
 block discarded – undo
66 66
 	 * @return bool
67 67
 	 */
68 68
 	public function is_subs_change_payment() {
69
-		return ( isset( $_GET['pay_for_order'] ) && isset( $_GET['change_payment_method'] ) );
69
+		return (isset($_GET['pay_for_order']) && isset($_GET['change_payment_method']));
70 70
 	}
71 71
 
72 72
 	/**
@@ -74,8 +74,8 @@  discard block
 block discarded – undo
74 74
 	 * @param  int  $order_id
75 75
 	 * @return boolean
76 76
 	 */
77
-	public function is_pre_order( $order_id ) {
78
-		return ( class_exists( 'WC_Pre_Orders_Order' ) && WC_Pre_Orders_Order::order_contains_pre_order( $order_id ) );
77
+	public function is_pre_order($order_id) {
78
+		return (class_exists('WC_Pre_Orders_Order') && WC_Pre_Orders_Order::order_contains_pre_order($order_id));
79 79
 	}
80 80
 
81 81
 	/**
@@ -84,26 +84,26 @@  discard block
 block discarded – undo
84 84
 	 * @since 4.0.4
85 85
 	 * @param int $order_id
86 86
 	 */
87
-	public function change_subs_payment_method( $order_id ) {
87
+	public function change_subs_payment_method($order_id) {
88 88
 		try {
89
-			$subscription    = wc_get_order( $order_id );
89
+			$subscription    = wc_get_order($order_id);
90 90
 			$source_object   = $this->get_source_object();
91
-			$prepared_source = $this->prepare_source( $source_object, get_current_user_id(), true );
91
+			$prepared_source = $this->prepare_source($source_object, get_current_user_id(), true);
92 92
 
93 93
 			// Check if we don't allow prepaid credit cards.
94
-			if ( ! apply_filters( 'wc_stripe_allow_prepaid_card', true ) ) {
95
-				if ( $source_object && 'token' === $source_object->object && 'prepaid' === $source_object->card->funding ) {
96
-					$localized_message = __( 'Sorry, we\'re not accepting prepaid cards at this time. Your credit card has not been charge. Please try with alternative payment method.', 'woocommerce-gateway-stripe' );
97
-					throw new WC_Stripe_Exception( print_r( $source_object, true ), $localized_message );
94
+			if ( ! apply_filters('wc_stripe_allow_prepaid_card', true)) {
95
+				if ($source_object && 'token' === $source_object->object && 'prepaid' === $source_object->card->funding) {
96
+					$localized_message = __('Sorry, we\'re not accepting prepaid cards at this time. Your credit card has not been charge. Please try with alternative payment method.', 'woocommerce-gateway-stripe');
97
+					throw new WC_Stripe_Exception(print_r($source_object, true), $localized_message);
98 98
 				}
99 99
 			}
100 100
 
101
-			if ( empty( $prepared_source->source ) ) {
102
-				$localized_message = __( 'Payment processing failed. Please retry.', 'woocommerce-gateway-stripe' );
103
-				throw new WC_Stripe_Exception( print_r( $prepared_source, true ), $localized_message );
101
+			if (empty($prepared_source->source)) {
102
+				$localized_message = __('Payment processing failed. Please retry.', 'woocommerce-gateway-stripe');
103
+				throw new WC_Stripe_Exception(print_r($prepared_source, true), $localized_message);
104 104
 			}
105 105
 
106
-			$this->save_source_to_order( $subscription, $prepared_source );
106
+			$this->save_source_to_order($subscription, $prepared_source);
107 107
 
108 108
 			/*
109 109
 			 * Check if card 3DS is required or optional with 3DS setting.
@@ -112,41 +112,41 @@  discard block
 block discarded – undo
112 112
 			 * Note that if we need to save source, the original source must be first
113 113
 			 * attached to a customer in Stripe before it can be charged.
114 114
 			 */
115
-			if ( $this->is_3ds_required( $source_object ) ) {
115
+			if ($this->is_3ds_required($source_object)) {
116 116
 				$order    = $subscription->get_parent();
117
-				$response = $this->create_3ds_source( $order, $source_object, $subscription->get_view_order_url() );
117
+				$response = $this->create_3ds_source($order, $source_object, $subscription->get_view_order_url());
118 118
 
119
-				if ( ! empty( $response->error ) ) {
119
+				if ( ! empty($response->error)) {
120 120
 					$localized_message = $response->error->message;
121 121
 
122
-					$order->add_order_note( $localized_message );
122
+					$order->add_order_note($localized_message);
123 123
 
124
-					throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message );
124
+					throw new WC_Stripe_Exception(print_r($response, true), $localized_message);
125 125
 				}
126 126
 
127 127
 				// Update order meta with 3DS source.
128
-				if ( WC_Stripe_Helper::is_pre_30() ) {
129
-					update_post_meta( $order_id, '_stripe_source_id', $response->id );
128
+				if (WC_Stripe_Helper::is_pre_30()) {
129
+					update_post_meta($order_id, '_stripe_source_id', $response->id);
130 130
 				} else {
131
-					$subscription->update_meta_data( '_stripe_source_id', $response->id );
131
+					$subscription->update_meta_data('_stripe_source_id', $response->id);
132 132
 					$subscription->save();
133 133
 				}
134 134
 
135
-				WC_Stripe_Logger::log( 'Info: Redirecting to 3DS...' );
135
+				WC_Stripe_Logger::log('Info: Redirecting to 3DS...');
136 136
 
137 137
 				return array(
138 138
 					'result'   => 'success',
139
-					'redirect' => esc_url_raw( $response->redirect->url ),
139
+					'redirect' => esc_url_raw($response->redirect->url),
140 140
 				);
141 141
 			}
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,18 +155,18 @@  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 ) {
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) {
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, true, true );
166
-		} elseif ( $this->is_pre_order( $order_id ) ) {
167
-			return $this->process_pre_order( $order_id, $retry, $force_save_source );
165
+			return parent::process_payment($order_id, true, true);
166
+		} elseif ($this->is_pre_order($order_id)) {
167
+			return $this->process_pre_order($order_id, $retry, $force_save_source);
168 168
 		} else {
169
-			return parent::process_payment( $order_id, $retry, $force_save_source );
169
+			return parent::process_payment($order_id, $retry, $force_save_source);
170 170
 		}
171 171
 	}
172 172
 
@@ -176,24 +176,24 @@  discard block
 block discarded – undo
176 176
 	 * @since 3.1.0
177 177
 	 * @version 4.0.0
178 178
 	 */
179
-	public function save_source_to_order( $order, $source ) {
180
-		parent::save_source_to_order( $order, $source );
179
+	public function save_source_to_order($order, $source) {
180
+		parent::save_source_to_order($order, $source);
181 181
 
182 182
 		$order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
183 183
 
184 184
 		// Also store it on the subscriptions being purchased or paid for in the order
185
-		if ( function_exists( 'wcs_order_contains_subscription' ) && wcs_order_contains_subscription( $order_id ) ) {
186
-			$subscriptions = wcs_get_subscriptions_for_order( $order_id );
187
-		} elseif ( function_exists( 'wcs_order_contains_renewal' ) && wcs_order_contains_renewal( $order_id ) ) {
188
-			$subscriptions = wcs_get_subscriptions_for_renewal_order( $order_id );
185
+		if (function_exists('wcs_order_contains_subscription') && wcs_order_contains_subscription($order_id)) {
186
+			$subscriptions = wcs_get_subscriptions_for_order($order_id);
187
+		} elseif (function_exists('wcs_order_contains_renewal') && wcs_order_contains_renewal($order_id)) {
188
+			$subscriptions = wcs_get_subscriptions_for_renewal_order($order_id);
189 189
 		} else {
190 190
 			$subscriptions = array();
191 191
 		}
192 192
 
193
-		foreach ( $subscriptions as $subscription ) {
193
+		foreach ($subscriptions as $subscription) {
194 194
 			$subscription_id = WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id();
195
-			update_post_meta( $subscription_id, '_stripe_customer_id', $source->customer );
196
-			update_post_meta( $subscription_id, '_stripe_source_id', $source->source );
195
+			update_post_meta($subscription_id, '_stripe_customer_id', $source->customer);
196
+			update_post_meta($subscription_id, '_stripe_source_id', $source->source);
197 197
 		}
198 198
 	}
199 199
 
@@ -206,45 +206,45 @@  discard block
 block discarded – undo
206 206
 	 * @param mixed $renewal_order
207 207
 	 * @param bool $is_retry Is this a retry process.
208 208
 	 */
209
-	public function process_subscription_payment( $amount = 0.0, $renewal_order, $is_retry = false ) {
210
-		if ( $amount * 100 < WC_Stripe_Helper::get_minimum_amount() ) {
209
+	public function process_subscription_payment($amount = 0.0, $renewal_order, $is_retry = false) {
210
+		if ($amount * 100 < WC_Stripe_Helper::get_minimum_amount()) {
211 211
 			/* translators: minimum amount */
212
-			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 ) ) );
212
+			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)));
213 213
 		}
214 214
 
215 215
 		$order_id = WC_Stripe_Helper::is_pre_30() ? $renewal_order->id : $renewal_order->get_id();
216 216
 
217 217
 		// Get source from order
218
-		$prepared_source = $this->prepare_order_source( $renewal_order );
218
+		$prepared_source = $this->prepare_order_source($renewal_order);
219 219
 
220
-		if ( ! $prepared_source->customer ) {
221
-			return new WP_Error( 'stripe_error', __( 'Customer not found', 'woocommerce-gateway-stripe' ) );
220
+		if ( ! $prepared_source->customer) {
221
+			return new WP_Error('stripe_error', __('Customer not found', 'woocommerce-gateway-stripe'));
222 222
 		}
223 223
 
224
-		WC_Stripe_Logger::log( "Info: Begin processing subscription payment for order {$order_id} for the amount of {$amount}" );
224
+		WC_Stripe_Logger::log("Info: Begin processing subscription payment for order {$order_id} for the amount of {$amount}");
225 225
 
226
-		if ( $is_retry ) {
226
+		if ($is_retry) {
227 227
 			// Passing empty source with charge customer default.
228 228
 			$prepared_source->source = '';
229 229
 		}
230 230
 
231
-		$request            = $this->generate_payment_request( $renewal_order, $prepared_source );
231
+		$request            = $this->generate_payment_request($renewal_order, $prepared_source);
232 232
 		$request['capture'] = 'true';
233
-		$request['amount']  = WC_Stripe_Helper::get_stripe_amount( $amount, $request['currency'] );
234
-		$response           = WC_Stripe_API::request( $request );
233
+		$request['amount']  = WC_Stripe_Helper::get_stripe_amount($amount, $request['currency']);
234
+		$response           = WC_Stripe_API::request($request);
235 235
 
236
-		if ( ! empty( $response->error ) || is_wp_error( $response ) ) {
237
-			if ( $is_retry ) {
236
+		if ( ! empty($response->error) || is_wp_error($response)) {
237
+			if ($is_retry) {
238 238
 				/* translators: error message */
239
-				$renewal_order->update_status( 'failed', sprintf( __( 'Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe' ), $response->error->message ) );
239
+				$renewal_order->update_status('failed', sprintf(__('Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe'), $response->error->message));
240 240
 			}
241 241
 
242 242
 			return $response; // Default catch all errors.
243 243
 		}
244 244
 
245
-		$this->process_response( $response, $renewal_order );
245
+		$this->process_response($response, $renewal_order);
246 246
 
247
-		if ( ! $is_retry ) {
247
+		if ( ! $is_retry) {
248 248
 			return $response;
249 249
 		}
250 250
 	}
@@ -253,21 +253,21 @@  discard block
 block discarded – undo
253 253
 	 * Don't transfer Stripe customer/token meta to resubscribe orders.
254 254
 	 * @param int $resubscribe_order The order created for the customer to resubscribe to the old expired/cancelled subscription
255 255
 	 */
256
-	public function delete_resubscribe_meta( $resubscribe_order ) {
257
-		delete_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id() ), '_stripe_customer_id' );
258
-		delete_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id() ), '_stripe_source_id' );
256
+	public function delete_resubscribe_meta($resubscribe_order) {
257
+		delete_post_meta((WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id()), '_stripe_customer_id');
258
+		delete_post_meta((WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id()), '_stripe_source_id');
259 259
 		// For BW compat will remove in future
260
-		delete_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id() ), '_stripe_card_id' );
261
-		$this->delete_renewal_meta( $resubscribe_order );
260
+		delete_post_meta((WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id()), '_stripe_card_id');
261
+		$this->delete_renewal_meta($resubscribe_order);
262 262
 	}
263 263
 
264 264
 	/**
265 265
 	 * Don't transfer Stripe fee/ID meta to renewal orders.
266 266
 	 * @param int $resubscribe_order The order created for the customer to resubscribe to the old expired/cancelled subscription
267 267
 	 */
268
-	public function delete_renewal_meta( $renewal_order ) {
269
-		delete_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $renewal_order->id : $renewal_order->get_id() ), 'Stripe Fee' );
270
-		delete_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $renewal_order->id : $renewal_order->get_id() ), 'Net Revenue From Stripe' );
268
+	public function delete_renewal_meta($renewal_order) {
269
+		delete_post_meta((WC_Stripe_Helper::is_pre_30() ? $renewal_order->id : $renewal_order->get_id()), 'Stripe Fee');
270
+		delete_post_meta((WC_Stripe_Helper::is_pre_30() ? $renewal_order->id : $renewal_order->get_id()), 'Net Revenue From Stripe');
271 271
 		return $renewal_order;
272 272
 	}
273 273
 
@@ -277,21 +277,21 @@  discard block
 block discarded – undo
277 277
 	 * @param $amount_to_charge float The amount to charge.
278 278
 	 * @param $renewal_order WC_Order A WC_Order object created to record the renewal payment.
279 279
 	 */
280
-	public function scheduled_subscription_payment( $amount_to_charge, $renewal_order ) {
281
-		$response = $this->process_subscription_payment( $amount_to_charge, $renewal_order );
280
+	public function scheduled_subscription_payment($amount_to_charge, $renewal_order) {
281
+		$response = $this->process_subscription_payment($amount_to_charge, $renewal_order);
282 282
 
283
-		if ( is_wp_error( $response ) ) {
283
+		if (is_wp_error($response)) {
284 284
 			/* translators: error message */
285
-			$renewal_order->update_status( 'failed', sprintf( __( 'Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe' ), $response->get_error_message() ) );
285
+			$renewal_order->update_status('failed', sprintf(__('Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe'), $response->get_error_message()));
286 286
 		}
287 287
 
288
-		if ( ! empty( $response->error ) ) {
288
+		if ( ! empty($response->error)) {
289 289
 			// This is a very generic error to listen for but worth a retry before total fail.
290
-			if ( isset( $response->error->type ) && 'invalid_request_error' === $response->error->type && apply_filters( 'wc_stripe_use_default_customer_source', true ) ) {
291
-				$this->process_subscription_payment( $amount_to_charge, $renewal_order, true );
290
+			if (isset($response->error->type) && 'invalid_request_error' === $response->error->type && apply_filters('wc_stripe_use_default_customer_source', true)) {
291
+				$this->process_subscription_payment($amount_to_charge, $renewal_order, true);
292 292
 			} else {
293 293
 				/* translators: error message */
294
-				$renewal_order->update_status( 'failed', sprintf( __( 'Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe' ), $response->error->message ) );
294
+				$renewal_order->update_status('failed', sprintf(__('Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe'), $response->error->message));
295 295
 			}
296 296
 		}
297 297
 	}
@@ -300,20 +300,20 @@  discard block
 block discarded – undo
300 300
 	 * Remove order meta
301 301
 	 * @param object $order
302 302
 	 */
303
-	public function remove_order_source_before_retry( $order ) {
303
+	public function remove_order_source_before_retry($order) {
304 304
 		$order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
305
-		delete_post_meta( $order_id, '_stripe_source_id' );
305
+		delete_post_meta($order_id, '_stripe_source_id');
306 306
 		// For BW compat will remove in the future.
307
-		delete_post_meta( $order_id, '_stripe_card_id' );
307
+		delete_post_meta($order_id, '_stripe_card_id');
308 308
 	}
309 309
 
310 310
 	/**
311 311
 	 * Remove order meta
312 312
 	 * @param  object $order
313 313
 	 */
314
-	public function remove_order_customer_before_retry( $order ) {
314
+	public function remove_order_customer_before_retry($order) {
315 315
 		$order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
316
-		delete_post_meta( $order_id, '_stripe_customer_id' );
316
+		delete_post_meta($order_id, '_stripe_customer_id');
317 317
 	}
318 318
 
319 319
 	/**
@@ -325,14 +325,14 @@  discard block
 block discarded – undo
325 325
 	 * @param WC_Order $renewal_order The order which recorded the successful payment (to make up for the failed automatic payment).
326 326
 	 * @return void
327 327
 	 */
328
-	public function update_failing_payment_method( $subscription, $renewal_order ) {
329
-		if ( WC_Stripe_Helper::is_pre_30() ) {
330
-			update_post_meta( $subscription->id, '_stripe_customer_id', $renewal_order->stripe_customer_id );
331
-			update_post_meta( $subscription->id, '_stripe_source_id', $renewal_order->stripe_source_id );
328
+	public function update_failing_payment_method($subscription, $renewal_order) {
329
+		if (WC_Stripe_Helper::is_pre_30()) {
330
+			update_post_meta($subscription->id, '_stripe_customer_id', $renewal_order->stripe_customer_id);
331
+			update_post_meta($subscription->id, '_stripe_source_id', $renewal_order->stripe_source_id);
332 332
 
333 333
 		} else {
334
-			update_post_meta( $subscription->get_id(), '_stripe_customer_id', $renewal_order->get_meta( '_stripe_customer_id', true ) );
335
-			update_post_meta( $subscription->get_id(), '_stripe_source_id', $renewal_order->get_meta( '_stripe_source_id', true ) );
334
+			update_post_meta($subscription->get_id(), '_stripe_customer_id', $renewal_order->get_meta('_stripe_customer_id', true));
335
+			update_post_meta($subscription->get_id(), '_stripe_source_id', $renewal_order->get_meta('_stripe_source_id', true));
336 336
 		}
337 337
 	}
338 338
 
@@ -345,21 +345,21 @@  discard block
 block discarded – undo
345 345
 	 * @param WC_Subscription $subscription An instance of a subscription object
346 346
 	 * @return array
347 347
 	 */
348
-	public function add_subscription_payment_meta( $payment_meta, $subscription ) {
349
-		$source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_source_id', true );
348
+	public function add_subscription_payment_meta($payment_meta, $subscription) {
349
+		$source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_source_id', true);
350 350
 
351 351
 		// For BW compat will remove in future.
352
-		if ( empty( $source_id ) ) {
353
-			$source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_card_id', true );
352
+		if (empty($source_id)) {
353
+			$source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_card_id', true);
354 354
 
355 355
 			// Take this opportunity to update the key name.
356
-			WC_Stripe_Helper::is_pre_30() ? update_post_meta( $subscription->id, '_stripe_source_id', $source_id ) : update_post_meta( $subscription->get_id(), '_stripe_source_id', $source_id );
356
+			WC_Stripe_Helper::is_pre_30() ? update_post_meta($subscription->id, '_stripe_source_id', $source_id) : update_post_meta($subscription->get_id(), '_stripe_source_id', $source_id);
357 357
 		}
358 358
 
359
-		$payment_meta[ $this->id ] = array(
359
+		$payment_meta[$this->id] = array(
360 360
 			'post_meta' => array(
361 361
 				'_stripe_customer_id' => array(
362
-					'value' => get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_customer_id', true ),
362
+					'value' => get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_customer_id', true),
363 363
 					'label' => 'Stripe Customer ID',
364 364
 				),
365 365
 				'_stripe_source_id' => array(
@@ -382,22 +382,22 @@  discard block
 block discarded – undo
382 382
 	 * @param array $payment_meta associative array of meta data required for automatic payments
383 383
 	 * @return array
384 384
 	 */
385
-	public function validate_subscription_payment_meta( $payment_method_id, $payment_meta ) {
386
-		if ( $this->id === $payment_method_id ) {
385
+	public function validate_subscription_payment_meta($payment_method_id, $payment_meta) {
386
+		if ($this->id === $payment_method_id) {
387 387
 
388
-			if ( ! isset( $payment_meta['post_meta']['_stripe_customer_id']['value'] ) || empty( $payment_meta['post_meta']['_stripe_customer_id']['value'] ) ) {
389
-				throw new Exception( __( 'A "Stripe Customer ID" value is required.', 'woocommerce-gateway-stripe' ) );
390
-			} elseif ( 0 !== strpos( $payment_meta['post_meta']['_stripe_customer_id']['value'], 'cus_' ) ) {
391
-				throw new Exception( __( 'Invalid customer ID. A valid "Stripe Customer ID" must begin with "cus_".', 'woocommerce-gateway-stripe' ) );
388
+			if ( ! isset($payment_meta['post_meta']['_stripe_customer_id']['value']) || empty($payment_meta['post_meta']['_stripe_customer_id']['value'])) {
389
+				throw new Exception(__('A "Stripe Customer ID" value is required.', 'woocommerce-gateway-stripe'));
390
+			} elseif (0 !== strpos($payment_meta['post_meta']['_stripe_customer_id']['value'], 'cus_')) {
391
+				throw new Exception(__('Invalid customer ID. A valid "Stripe Customer ID" must begin with "cus_".', 'woocommerce-gateway-stripe'));
392 392
 			}
393 393
 
394 394
 			if (
395
-				( ! empty( $payment_meta['post_meta']['_stripe_source_id']['value'] )
396
-				&& 0 !== strpos( $payment_meta['post_meta']['_stripe_source_id']['value'], 'card_' ) )
397
-				&& ( ! empty( $payment_meta['post_meta']['_stripe_source_id']['value'] )
398
-				&& 0 !== strpos( $payment_meta['post_meta']['_stripe_source_id']['value'], 'src_' ) ) ) {
395
+				( ! empty($payment_meta['post_meta']['_stripe_source_id']['value'])
396
+				&& 0 !== strpos($payment_meta['post_meta']['_stripe_source_id']['value'], 'card_'))
397
+				&& ( ! empty($payment_meta['post_meta']['_stripe_source_id']['value'])
398
+				&& 0 !== strpos($payment_meta['post_meta']['_stripe_source_id']['value'], 'src_')) ) {
399 399
 
400
-				throw new Exception( __( 'Invalid source ID. A valid source "Stripe Source ID" must begin with "src_" or "card_".', 'woocommerce-gateway-stripe' ) );
400
+				throw new Exception(__('Invalid source ID. A valid source "Stripe Source ID" must begin with "src_" or "card_".', 'woocommerce-gateway-stripe'));
401 401
 			}
402 402
 		}
403 403
 	}
@@ -410,91 +410,91 @@  discard block
 block discarded – undo
410 410
 	 * @param WC_Subscription $subscription the subscription details
411 411
 	 * @return string the subscription payment method
412 412
 	 */
413
-	public function maybe_render_subscription_payment_method( $payment_method_to_display, $subscription ) {
413
+	public function maybe_render_subscription_payment_method($payment_method_to_display, $subscription) {
414 414
 		$customer_user = WC_Stripe_Helper::is_pre_30() ? $subscription->customer_user : $subscription->get_customer_id();
415 415
 
416 416
 		// bail for other payment methods
417
-		if ( ( WC_Stripe_Helper::is_pre_30() ? $subscription->payment_method : $subscription->get_payment_method() ) !== $this->id || ! $customer_user ) {
417
+		if ((WC_Stripe_Helper::is_pre_30() ? $subscription->payment_method : $subscription->get_payment_method()) !== $this->id || ! $customer_user) {
418 418
 			return $payment_method_to_display;
419 419
 		}
420 420
 
421
-		$stripe_source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_source_id', true );
421
+		$stripe_source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_source_id', true);
422 422
 
423 423
 		// For BW compat will remove in future.
424
-		if ( empty( $stripe_source_id ) ) {
425
-			$stripe_source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_card_id', true );
424
+		if (empty($stripe_source_id)) {
425
+			$stripe_source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_card_id', true);
426 426
 
427 427
 			// Take this opportunity to update the key name.
428
-			WC_Stripe_Helper::is_pre_30() ? update_post_meta( $subscription->id, '_stripe_source_id', $stripe_source_id ) : update_post_meta( $subscription->get_id(), '_stripe_source_id', $stripe_source_id );
428
+			WC_Stripe_Helper::is_pre_30() ? update_post_meta($subscription->id, '_stripe_source_id', $stripe_source_id) : update_post_meta($subscription->get_id(), '_stripe_source_id', $stripe_source_id);
429 429
 		}
430 430
 
431 431
 		$stripe_customer    = new WC_Stripe_Customer();
432
-		$stripe_customer_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_customer_id', true );
432
+		$stripe_customer_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_customer_id', true);
433 433
 
434 434
 		// If we couldn't find a Stripe customer linked to the subscription, fallback to the user meta data.
435
-		if ( ! $stripe_customer_id || ! is_string( $stripe_customer_id ) ) {
435
+		if ( ! $stripe_customer_id || ! is_string($stripe_customer_id)) {
436 436
 			$user_id            = $customer_user;
437
-			$stripe_customer_id = get_user_meta( $user_id, '_stripe_customer_id', true );
438
-			$stripe_source_id   = get_user_meta( $user_id, '_stripe_source_id', true );
437
+			$stripe_customer_id = get_user_meta($user_id, '_stripe_customer_id', true);
438
+			$stripe_source_id   = get_user_meta($user_id, '_stripe_source_id', true);
439 439
 
440 440
 			// For BW compat will remove in future.
441
-			if ( empty( $stripe_source_id ) ) {
442
-				$stripe_source_id = get_user_meta( $user_id, '_stripe_card_id', true );
441
+			if (empty($stripe_source_id)) {
442
+				$stripe_source_id = get_user_meta($user_id, '_stripe_card_id', true);
443 443
 
444 444
 				// Take this opportunity to update the key name.
445
-				update_user_meta( $user_id, '_stripe_source_id', $stripe_source_id );
445
+				update_user_meta($user_id, '_stripe_source_id', $stripe_source_id);
446 446
 			}
447 447
 		}
448 448
 
449 449
 		// If we couldn't find a Stripe customer linked to the account, fallback to the order meta data.
450
-		if ( ( ! $stripe_customer_id || ! is_string( $stripe_customer_id ) ) && false !== $subscription->order ) {
451
-			$stripe_customer_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id() ), '_stripe_customer_id', true );
452
-			$stripe_source_id   = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id() ), '_stripe_source_id', true );
450
+		if (( ! $stripe_customer_id || ! is_string($stripe_customer_id)) && false !== $subscription->order) {
451
+			$stripe_customer_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id()), '_stripe_customer_id', true);
452
+			$stripe_source_id   = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id()), '_stripe_source_id', true);
453 453
 
454 454
 			// For BW compat will remove in future.
455
-			if ( empty( $stripe_source_id ) ) {
456
-				$stripe_source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id() ), '_stripe_card_id', true );
455
+			if (empty($stripe_source_id)) {
456
+				$stripe_source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id()), '_stripe_card_id', true);
457 457
 
458 458
 				// Take this opportunity to update the key name.
459
-				WC_Stripe_Helper::is_pre_30() ? update_post_meta( $subscription->order->id, '_stripe_source_id', $stripe_source_id ) : update_post_meta( $subscription->get_parent_id(), '_stripe_source_id', $stripe_source_id );
459
+				WC_Stripe_Helper::is_pre_30() ? update_post_meta($subscription->order->id, '_stripe_source_id', $stripe_source_id) : update_post_meta($subscription->get_parent_id(), '_stripe_source_id', $stripe_source_id);
460 460
 			}
461 461
 		}
462 462
 
463
-		$stripe_customer->set_id( $stripe_customer_id );
463
+		$stripe_customer->set_id($stripe_customer_id);
464 464
 		$sources = $stripe_customer->get_sources();
465 465
 
466
-		if ( $sources ) {
466
+		if ($sources) {
467 467
 			$found_source = false;
468
-			foreach ( $sources as $source ) {
469
-				if ( isset( $source->type ) && 'card' === $source->type ) {
468
+			foreach ($sources as $source) {
469
+				if (isset($source->type) && 'card' === $source->type) {
470 470
 					$card = $source->card;
471
-				} elseif ( isset( $source->object ) && 'card' === $source->object ) {
471
+				} elseif (isset($source->object) && 'card' === $source->object) {
472 472
 					$card = $source;
473 473
 				}
474 474
 
475
-				if ( $source->id === $stripe_source_id ) {
475
+				if ($source->id === $stripe_source_id) {
476 476
 					$found_source = true;
477 477
 
478
-					if ( $card ) {
478
+					if ($card) {
479 479
 						/* translators: 1) card brand 2) last 4 digits */
480
-						$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 );
480
+						$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);
481 481
 					} else {
482
-						$payment_method_to_display = __( 'N/A', 'woocommerce-gateway-stripe' );
482
+						$payment_method_to_display = __('N/A', 'woocommerce-gateway-stripe');
483 483
 					}
484 484
 					break;
485 485
 				}
486 486
 			}
487 487
 
488
-			if ( ! $found_source ) {
489
-				if ( 'card' === $sources[0]->type ) {
488
+			if ( ! $found_source) {
489
+				if ('card' === $sources[0]->type) {
490 490
 					$card = $sources[0]->card;
491 491
 				}
492 492
 
493
-				if ( $card ) {
493
+				if ($card) {
494 494
 					/* translators: 1) card brand 2) last 4 digits */
495
-					$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 );
495
+					$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);
496 496
 				} else {
497
-					$payment_method_to_display = __( 'N/A', 'woocommerce-gateway-stripe' );
497
+					$payment_method_to_display = __('N/A', 'woocommerce-gateway-stripe');
498 498
 				}
499 499
 			}
500 500
 		}
@@ -507,42 +507,42 @@  discard block
 block discarded – undo
507 507
 	 * @param int $order_id
508 508
 	 * @return array
509 509
 	 */
510
-	public function process_pre_order( $order_id, $retry, $force_save_source ) {
511
-		if ( WC_Pre_Orders_Order::order_requires_payment_tokenization( $order_id ) ) {
510
+	public function process_pre_order($order_id, $retry, $force_save_source) {
511
+		if (WC_Pre_Orders_Order::order_requires_payment_tokenization($order_id)) {
512 512
 			try {
513
-				$order = wc_get_order( $order_id );
513
+				$order = wc_get_order($order_id);
514 514
 
515
-				if ( $order->get_total() * 100 < WC_Stripe_Helper::get_minimum_amount() ) {
515
+				if ($order->get_total() * 100 < WC_Stripe_Helper::get_minimum_amount()) {
516 516
 					/* translators: minimum amount */
517
-					throw new Exception( sprintf( __( 'Sorry, the minimum allowed order total is %1$s to use this payment method.', 'woocommerce-gateway-stripe' ), wc_price( WC_Stripe_Helper::get_minimum_amount() / 100 ) ) );
517
+					throw new Exception(sprintf(__('Sorry, the minimum allowed order total is %1$s to use this payment method.', 'woocommerce-gateway-stripe'), wc_price(WC_Stripe_Helper::get_minimum_amount() / 100)));
518 518
 				}
519 519
 
520
-				$source = $this->prepare_source( $this->get_source_object(), get_current_user_id(), true );
520
+				$source = $this->prepare_source($this->get_source_object(), get_current_user_id(), true);
521 521
 
522 522
 				// We need a source on file to continue.
523
-				if ( empty( $source->customer ) || empty( $source->source ) ) {
524
-					throw new Exception( __( 'Unable to store payment details. Please try again.', 'woocommerce-gateway-stripe' ) );
523
+				if (empty($source->customer) || empty($source->source)) {
524
+					throw new Exception(__('Unable to store payment details. Please try again.', 'woocommerce-gateway-stripe'));
525 525
 				}
526 526
 
527
-				$this->save_source_to_order( $order, $source );
527
+				$this->save_source_to_order($order, $source);
528 528
 
529 529
 				// Remove cart
530 530
 				WC()->cart->empty_cart();
531 531
 
532 532
 				// Is pre ordered!
533
-				WC_Pre_Orders_Order::mark_order_as_pre_ordered( $order );
533
+				WC_Pre_Orders_Order::mark_order_as_pre_ordered($order);
534 534
 
535 535
 				// Return thank you page redirect
536 536
 				return array(
537 537
 					'result'   => 'success',
538
-					'redirect' => $this->get_return_url( $order ),
538
+					'redirect' => $this->get_return_url($order),
539 539
 				);
540
-			} catch ( Exception $e ) {
541
-				wc_add_notice( $e->getMessage(), 'error' );
540
+			} catch (Exception $e) {
541
+				wc_add_notice($e->getMessage(), 'error');
542 542
 				return;
543 543
 			}
544 544
 		} else {
545
-			return parent::process_payment( $order_id, $retry, $force_save_source );
545
+			return parent::process_payment($order_id, $retry, $force_save_source);
546 546
 		}
547 547
 	}
548 548
 
@@ -551,7 +551,7 @@  discard block
 block discarded – undo
551 551
 	 * @param WC_Order $order
552 552
 	 * @return void
553 553
 	 */
554
-	public function process_pre_order_release_payment( $order ) {
554
+	public function process_pre_order_release_payment($order) {
555 555
 		try {
556 556
 			// Define some callbacks if the first attempt fails.
557 557
 			$retry_callbacks = array(
@@ -559,33 +559,33 @@  discard block
 block discarded – undo
559 559
 				'remove_order_customer_before_retry',
560 560
 			);
561 561
 
562
-			while ( 1 ) {
563
-				$source   = $this->prepare_order_source( $order );
564
-				$response = WC_Stripe_API::request( $this->generate_payment_request( $order, $source ) );
562
+			while (1) {
563
+				$source   = $this->prepare_order_source($order);
564
+				$response = WC_Stripe_API::request($this->generate_payment_request($order, $source));
565 565
 
566
-				if ( ! empty( $response->error ) ) {
567
-					if ( 0 === sizeof( $retry_callbacks ) ) {
568
-						throw new Exception( $response->error->message );
566
+				if ( ! empty($response->error)) {
567
+					if (0 === sizeof($retry_callbacks)) {
568
+						throw new Exception($response->error->message);
569 569
 					} else {
570
-						$retry_callback = array_shift( $retry_callbacks );
571
-						call_user_func( array( $this, $retry_callback ), $order );
570
+						$retry_callback = array_shift($retry_callbacks);
571
+						call_user_func(array($this, $retry_callback), $order);
572 572
 					}
573 573
 				} else {
574 574
 					// Successful
575
-					$this->process_response( $response, $order );
575
+					$this->process_response($response, $order);
576 576
 					break;
577 577
 				}
578 578
 			}
579
-		} catch ( Exception $e ) {
579
+		} catch (Exception $e) {
580 580
 			/* translators: error message */
581
-			$order_note = sprintf( __( 'Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe' ), $e->getMessage() );
581
+			$order_note = sprintf(__('Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe'), $e->getMessage());
582 582
 
583 583
 			// Mark order as failed if not already set,
584 584
 			// otherwise, make sure we add the order note so we can detect when someone fails to check out multiple times
585
-			if ( ! $order->has_status( 'failed' ) ) {
586
-				$order->update_status( 'failed', $order_note );
585
+			if ( ! $order->has_status('failed')) {
586
+				$order->update_status('failed', $order_note);
587 587
 			} else {
588
-				$order->add_order_note( $order_note );
588
+				$order->add_order_note($order_note);
589 589
 			}
590 590
 		}
591 591
 	}
Please login to merge, or discard this patch.