Completed
Push — master ( 302e86...a53ae1 )
by Roy
01:59
created
includes/class-wc-stripe-webhook-handler.php 1 patch
Spacing   +141 added lines, -141 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
 
@@ -17,7 +17,7 @@  discard block
 block discarded – undo
17 17
 	 * @version 4.0.0
18 18
 	 */
19 19
 	public function __construct() {
20
-		add_action( 'woocommerce_api_wc_stripe', array( $this, 'check_for_webhook' ) );
20
+		add_action('woocommerce_api_wc_stripe', array($this, 'check_for_webhook'));
21 21
 	}
22 22
 
23 23
 	/**
@@ -27,24 +27,24 @@  discard block
 block discarded – undo
27 27
 	 * @version 4.0.0
28 28
 	 */
29 29
 	public function check_for_webhook() {
30
-		if ( ( 'POST' !== $_SERVER['REQUEST_METHOD'] )
31
-			|| ! isset( $_GET['wc-api'] )
32
-			|| ( 'wc_stripe' !== $_GET['wc-api'] )
30
+		if (('POST' !== $_SERVER['REQUEST_METHOD'])
31
+			|| ! isset($_GET['wc-api'])
32
+			|| ('wc_stripe' !== $_GET['wc-api'])
33 33
 		) {
34 34
 			return;
35 35
 		}
36 36
 
37
-		$request_body    = file_get_contents( 'php://input' );
38
-		$request_headers = array_change_key_case( $this->get_request_headers(), CASE_UPPER );
37
+		$request_body    = file_get_contents('php://input');
38
+		$request_headers = array_change_key_case($this->get_request_headers(), CASE_UPPER);
39 39
 
40 40
 		// Validate it to make sure it is legit.
41
-		if ( $this->is_valid_request( $request_headers, $request_body ) ) {
42
-			$this->process_webhook( $request_body );
43
-			status_header( 200 );
41
+		if ($this->is_valid_request($request_headers, $request_body)) {
42
+			$this->process_webhook($request_body);
43
+			status_header(200);
44 44
 			exit;
45 45
 		} else {
46
-			WC_Stripe_Logger::log( 'Incoming webhook failed validation: ' . print_r( $request_body, true ) );
47
-			status_header( 400 );
46
+			WC_Stripe_Logger::log('Incoming webhook failed validation: ' . print_r($request_body, true));
47
+			status_header(400);
48 48
 			exit;
49 49
 		}
50 50
 	}
@@ -59,12 +59,12 @@  discard block
 block discarded – undo
59 59
 	 * @param string $request_body The request body from Stripe.
60 60
 	 * @return bool
61 61
 	 */
62
-	public function is_valid_request( $request_headers = null, $request_body = null ) {
63
-		if ( null === $request_headers || null === $request_body ) {
62
+	public function is_valid_request($request_headers = null, $request_body = null) {
63
+		if (null === $request_headers || null === $request_body) {
64 64
 			return false;
65 65
 		}
66 66
 
67
-		if ( ! empty( $request_headers['USER-AGENT'] ) && ! preg_match( '/Stripe/', $request_headers['USER-AGENT'] ) ) {
67
+		if ( ! empty($request_headers['USER-AGENT']) && ! preg_match('/Stripe/', $request_headers['USER-AGENT'])) {
68 68
 			return false;
69 69
 		}
70 70
 
@@ -80,11 +80,11 @@  discard block
 block discarded – undo
80 80
 	 * @version 4.0.0
81 81
 	 */
82 82
 	public function get_request_headers() {
83
-		if ( ! function_exists( 'getallheaders' ) ) {
83
+		if ( ! function_exists('getallheaders')) {
84 84
 			$headers = [];
85
-			foreach ( $_SERVER as $name => $value ) {
86
-				if ( 'HTTP_' === substr( $name, 0, 5 ) ) {
87
-					$headers[ str_replace( ' ', '-', ucwords( strtolower( str_replace( '_', ' ', substr( $name, 5 ) ) ) ) ) ] = $value;
85
+			foreach ($_SERVER as $name => $value) {
86
+				if ('HTTP_' === substr($name, 0, 5)) {
87
+					$headers[str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', substr($name, 5)))))] = $value;
88 88
 				}
89 89
 			}
90 90
 
@@ -103,30 +103,30 @@  discard block
 block discarded – undo
103 103
 	 * @param object $notification
104 104
 	 * @param bool $retry
105 105
 	 */
106
-	public function process_webhook_payment( $notification, $retry = true ) {
106
+	public function process_webhook_payment($notification, $retry = true) {
107 107
 		// The following 2 payment methods are synchronous so does not need to be handle via webhook.
108
-		if ( 'card' === $notification->data->object->type || 'sepa_debit' === $notification->data->object->type ) {
108
+		if ('card' === $notification->data->object->type || 'sepa_debit' === $notification->data->object->type) {
109 109
 			return;
110 110
 		}
111 111
 
112
-		$order = WC_Stripe_Helper::get_order_by_source_id( $notification->data->object->id );
112
+		$order = WC_Stripe_Helper::get_order_by_source_id($notification->data->object->id);
113 113
 
114
-		if ( ! $order ) {
115
-			WC_Stripe_Logger::log( 'Could not find order via source ID: ' . $notification->data->object->id );
114
+		if ( ! $order) {
115
+			WC_Stripe_Logger::log('Could not find order via source ID: ' . $notification->data->object->id);
116 116
 			return;
117 117
 		}
118 118
 
119 119
 		$order_id  = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
120 120
 		$source_id = $notification->data->object->id;
121 121
 
122
-		$is_pending_receiver = ( 'receiver' === $notification->data->object->flow );
122
+		$is_pending_receiver = ('receiver' === $notification->data->object->flow);
123 123
 
124 124
 		try {
125
-			if ( 'processing' === $order->get_status() || 'completed' === $order->get_status() ) {
125
+			if ('processing' === $order->get_status() || 'completed' === $order->get_status()) {
126 126
 				return;
127 127
 			}
128 128
 
129
-			if ( 'on-hold' === $order->get_status() && ! $is_pending_receiver ) {
129
+			if ('on-hold' === $order->get_status() && ! $is_pending_receiver) {
130 130
 				return;
131 131
 			}
132 132
 
@@ -134,73 +134,73 @@  discard block
 block discarded – undo
134 134
 			$response = null;
135 135
 
136 136
 			// This will throw exception if not valid.
137
-			$this->validate_minimum_order_amount( $order );
137
+			$this->validate_minimum_order_amount($order);
138 138
 
139
-			WC_Stripe_Logger::log( "Info: (Webhook) Begin processing payment for order $order_id for the amount of {$order->get_total()}" );
139
+			WC_Stripe_Logger::log("Info: (Webhook) Begin processing payment for order $order_id for the amount of {$order->get_total()}");
140 140
 
141 141
 			// Prep source object.
142 142
 			$source_object           = new stdClass();
143 143
 			$source_object->token_id = '';
144
-			$source_object->customer = $this->get_stripe_customer_id( $order );
144
+			$source_object->customer = $this->get_stripe_customer_id($order);
145 145
 			$source_object->source   = $source_id;
146 146
 
147 147
 			// Make the request.
148
-			$response = WC_Stripe_API::request( $this->generate_payment_request( $order, $source_object ) );
148
+			$response = WC_Stripe_API::request($this->generate_payment_request($order, $source_object));
149 149
 
150
-			if ( ! empty( $response->error ) ) {
150
+			if ( ! empty($response->error)) {
151 151
 				// If it is an API error such connection or server, let's retry.
152
-				if ( 'api_connection_error' === $response->error->type || 'api_error' === $response->error->type ) {
153
-					if ( $retry ) {
154
-						sleep( 5 );
155
-						return $this->process_payment( $order_id, false );
152
+				if ('api_connection_error' === $response->error->type || 'api_error' === $response->error->type) {
153
+					if ($retry) {
154
+						sleep(5);
155
+						return $this->process_payment($order_id, false);
156 156
 					} else {
157 157
 						$message = 'API connection error and retries exhausted.';
158
-						$order->add_order_note( $message );
159
-						throw new Exception( $message );
158
+						$order->add_order_note($message);
159
+						throw new Exception($message);
160 160
 					}
161 161
 				}
162 162
 
163 163
 				// Customer param wrong? The user may have been deleted on stripe's end. Remove customer_id. Can be retried without.
164
-				if ( preg_match( '/No such customer/i', $response->error->message ) && $retry ) {
165
-					delete_user_meta( WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id(), '_stripe_customer_id' );
164
+				if (preg_match('/No such customer/i', $response->error->message) && $retry) {
165
+					delete_user_meta(WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id(), '_stripe_customer_id');
166 166
 
167
-					return $this->process_payment( $order_id, false );
167
+					return $this->process_payment($order_id, false);
168 168
 
169
-				} elseif ( preg_match( '/No such token/i', $response->error->message ) && $source_object->token_id ) {
169
+				} elseif (preg_match('/No such token/i', $response->error->message) && $source_object->token_id) {
170 170
 					// Source param wrong? The CARD may have been deleted on stripe's end. Remove token and show message.
171
-					$wc_token = WC_Payment_Tokens::get( $source_object->token_id );
171
+					$wc_token = WC_Payment_Tokens::get($source_object->token_id);
172 172
 					$wc_token->delete();
173
-					$message = __( 'This card is no longer available and has been removed.', 'woocommerce-gateway-stripe' );
174
-					$order->add_order_note( $message );
175
-					throw new Exception( $message );
173
+					$message = __('This card is no longer available and has been removed.', 'woocommerce-gateway-stripe');
174
+					$order->add_order_note($message);
175
+					throw new Exception($message);
176 176
 				}
177 177
 
178 178
 				$localized_messages = WC_Stripe_Helper::get_localized_messages();
179 179
 
180
-				if ( 'card_error' === $response->error->type ) {
181
-					$message = isset( $localized_messages[ $response->error->code ] ) ? $localized_messages[ $response->error->code ] : $response->error->message;
180
+				if ('card_error' === $response->error->type) {
181
+					$message = isset($localized_messages[$response->error->code]) ? $localized_messages[$response->error->code] : $response->error->message;
182 182
 				} else {
183
-					$message = isset( $localized_messages[ $response->error->type ] ) ? $localized_messages[ $response->error->type ] : $response->error->message;
183
+					$message = isset($localized_messages[$response->error->type]) ? $localized_messages[$response->error->type] : $response->error->message;
184 184
 				}
185 185
 
186
-				$order->add_order_note( $message );
186
+				$order->add_order_note($message);
187 187
 
188
-				throw new Exception( $message );
188
+				throw new Exception($message);
189 189
 			}
190 190
 
191
-			do_action( 'wc_gateway_stripe_process_webhook_payment', $response, $order );
191
+			do_action('wc_gateway_stripe_process_webhook_payment', $response, $order);
192 192
 
193
-			$this->process_response( $response, $order );
193
+			$this->process_response($response, $order);
194 194
 
195
-		} catch ( Exception $e ) {
196
-			WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() );
195
+		} catch (Exception $e) {
196
+			WC_Stripe_Logger::log('Error: ' . $e->getMessage());
197 197
 
198
-			do_action( 'wc_gateway_stripe_process_webhook_payment_error', $e, $order );
198
+			do_action('wc_gateway_stripe_process_webhook_payment_error', $e, $order);
199 199
 
200
-			$statuses = array( 'pending', 'failed' );
200
+			$statuses = array('pending', 'failed');
201 201
 
202
-			if ( $order->has_status( $statuses ) ) {
203
-				$this->send_failed_order_email( $order_id );
202
+			if ($order->has_status($statuses)) {
203
+				$this->send_failed_order_email($order_id);
204 204
 			}
205 205
 		}
206 206
 	}
@@ -214,18 +214,18 @@  discard block
 block discarded – undo
214 214
 	 * @version 4.0.0
215 215
 	 * @param object $notification
216 216
 	 */
217
-	public function process_webhook_dispute( $notification ) {
218
-		$order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->id );
217
+	public function process_webhook_dispute($notification) {
218
+		$order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->id);
219 219
 
220
-		if ( ! $order ) {
221
-			WC_Stripe_Logger::log( 'Could not find order via charge ID: ' . $notification->data->object->id );
220
+		if ( ! $order) {
221
+			WC_Stripe_Logger::log('Could not find order via charge ID: ' . $notification->data->object->id);
222 222
 			return;
223 223
 		}
224 224
 
225
-		$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' ) );
225
+		$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'));
226 226
 
227
-		do_action( 'wc_gateway_stripe_process_webhook_payment_error', $order, $notification );
228
-		$this->send_failed_order_email( $order_id );
227
+		do_action('wc_gateway_stripe_process_webhook_payment_error', $order, $notification);
228
+		$this->send_failed_order_email($order_id);
229 229
 	}
230 230
 
231 231
 	/**
@@ -236,41 +236,41 @@  discard block
 block discarded – undo
236 236
 	 * @version 4.0.0
237 237
 	 * @param object $notification
238 238
 	 */
239
-	public function process_webhook_capture( $notification ) {
240
-		$order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->id );
239
+	public function process_webhook_capture($notification) {
240
+		$order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->id);
241 241
 
242
-		if ( ! $order ) {
243
-			WC_Stripe_Logger::log( 'Could not find order via charge ID: ' . $notification->data->object->id );
242
+		if ( ! $order) {
243
+			WC_Stripe_Logger::log('Could not find order via charge ID: ' . $notification->data->object->id);
244 244
 			return;
245 245
 		}
246 246
 
247 247
 		$order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
248 248
 
249
-		if ( 'stripe' === ( WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method() ) ) {
250
-			$charge   = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_transaction_id', true ) : $order->get_transaction_id();
251
-			$captured = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_stripe_charge_captured', true ) : $order->get_meta( '_stripe_charge_captured', true );
249
+		if ('stripe' === (WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method())) {
250
+			$charge   = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_transaction_id', true) : $order->get_transaction_id();
251
+			$captured = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_stripe_charge_captured', true) : $order->get_meta('_stripe_charge_captured', true);
252 252
 
253
-			if ( $charge && 'no' === $captured ) {
254
-				WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, '_stripe_charge_captured', 'yes' ) : $order->update_meta_data( '_stripe_charge_captured', 'yes' );
253
+			if ($charge && 'no' === $captured) {
254
+				WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, '_stripe_charge_captured', 'yes') : $order->update_meta_data('_stripe_charge_captured', 'yes');
255 255
 
256 256
 				// Store other data such as fees
257
-				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 );
257
+				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);
258 258
 
259
-				if ( isset( $notification->data->object->balance_transaction ) ) {
260
-					$this->update_fees( $order, $notification->data->object->balance_transaction );
259
+				if (isset($notification->data->object->balance_transaction)) {
260
+					$this->update_fees($order, $notification->data->object->balance_transaction);
261 261
 				}
262 262
 
263
-				if ( is_callable( array( $order, 'save' ) ) ) {
263
+				if (is_callable(array($order, 'save'))) {
264 264
 					$order->save();
265 265
 				}
266 266
 
267 267
 				/* translators: transaction id */
268
-				$order->update_status( $order->needs_processing() ? 'processing' : 'completed', sprintf( __( 'Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe' ), $notification->data->object->id ) );
268
+				$order->update_status($order->needs_processing() ? 'processing' : 'completed', sprintf(__('Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe'), $notification->data->object->id));
269 269
 
270 270
 				// Check and see if capture is partial.
271
-				if ( $this->is_partial_capture( $notification ) ) {
272
-					$order->set_total( $this->get_partial_amount_to_charge( $notification ) );
273
-					$order->add_note( __( 'This charge was partially captured via Stripe Dashboard', 'woocommerce-gateway-stripe' ) );
271
+				if ($this->is_partial_capture($notification)) {
272
+					$order->set_total($this->get_partial_amount_to_charge($notification));
273
+					$order->add_note(__('This charge was partially captured via Stripe Dashboard', 'woocommerce-gateway-stripe'));
274 274
 					$order->save();
275 275
 				}
276 276
 			}
@@ -285,38 +285,38 @@  discard block
 block discarded – undo
285 285
 	 * @version 4.0.0
286 286
 	 * @param object $notification
287 287
 	 */
288
-	public function process_webhook_charge_succeeded( $notification ) {
288
+	public function process_webhook_charge_succeeded($notification) {
289 289
 		// The following payment methods are synchronous so does not need to be handle via webhook.
290
-		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 ) ) {
290
+		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)) {
291 291
 			return;
292 292
 		}
293 293
 
294
-		$order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->id );
294
+		$order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->id);
295 295
 
296
-		if ( ! $order ) {
297
-			WC_Stripe_Logger::log( 'Could not find order via charge ID: ' . $notification->data->object->id );
296
+		if ( ! $order) {
297
+			WC_Stripe_Logger::log('Could not find order via charge ID: ' . $notification->data->object->id);
298 298
 			return;
299 299
 		}
300 300
 
301 301
 		$order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
302 302
 
303
-		if ( 'on-hold' !== $order->get_status() ) {
303
+		if ('on-hold' !== $order->get_status()) {
304 304
 			return;
305 305
 		}
306 306
 
307 307
 		// Store other data such as fees
308
-		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 );
308
+		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);
309 309
 
310
-		if ( isset( $notification->data->object->balance_transaction ) ) {
311
-			$this->update_fees( $order, $notification->data->object->balance_transaction );
310
+		if (isset($notification->data->object->balance_transaction)) {
311
+			$this->update_fees($order, $notification->data->object->balance_transaction);
312 312
 		}
313 313
 
314
-		if ( is_callable( array( $order, 'save' ) ) ) {
314
+		if (is_callable(array($order, 'save'))) {
315 315
 			$order->save();
316 316
 		}
317 317
 
318 318
 		/* translators: transaction id */
319
-		$order->update_status( $order->needs_processing() ? 'processing' : 'completed', sprintf( __( 'Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe' ), $notification->data->object->id ) );
319
+		$order->update_status($order->needs_processing() ? 'processing' : 'completed', sprintf(__('Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe'), $notification->data->object->id));
320 320
 	}
321 321
 
322 322
 	/**
@@ -327,23 +327,23 @@  discard block
 block discarded – undo
327 327
 	 * @version 4.0.0
328 328
 	 * @param object $notification
329 329
 	 */
330
-	public function process_webhook_charge_failed( $notification ) {
331
-		$order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->id );
330
+	public function process_webhook_charge_failed($notification) {
331
+		$order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->id);
332 332
 
333
-		if ( ! $order ) {
334
-			WC_Stripe_Logger::log( 'Could not find order via charge ID: ' . $notification->data->object->id );
333
+		if ( ! $order) {
334
+			WC_Stripe_Logger::log('Could not find order via charge ID: ' . $notification->data->object->id);
335 335
 			return;
336 336
 		}
337 337
 
338 338
 		$order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
339 339
 
340
-		if ( 'on-hold' !== $order->get_status() ) {
340
+		if ('on-hold' !== $order->get_status()) {
341 341
 			return;
342 342
 		}
343 343
 
344
-		$order->update_status( 'failed', __( 'This payment failed to clear.', 'woocommerce-gateway-stripe' ) );
344
+		$order->update_status('failed', __('This payment failed to clear.', 'woocommerce-gateway-stripe'));
345 345
 
346
-		do_action( 'wc_gateway_stripe_process_webhook_payment_error', $order, $notification );
346
+		do_action('wc_gateway_stripe_process_webhook_payment_error', $order, $notification);
347 347
 	}
348 348
 
349 349
 	/**
@@ -354,23 +354,23 @@  discard block
 block discarded – undo
354 354
 	 * @version 4.0.0
355 355
 	 * @param object $notification
356 356
 	 */
357
-	public function process_webhook_source_canceled( $notification ) {
358
-		$order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->id );
357
+	public function process_webhook_source_canceled($notification) {
358
+		$order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->id);
359 359
 
360
-		if ( ! $order ) {
361
-			WC_Stripe_Logger::log( 'Could not find order via charge ID: ' . $notification->data->object->id );
360
+		if ( ! $order) {
361
+			WC_Stripe_Logger::log('Could not find order via charge ID: ' . $notification->data->object->id);
362 362
 			return;
363 363
 		}
364 364
 
365 365
 		$order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
366 366
 
367
-		if ( 'on-hold' !== $order->get_status() || 'cancelled' !== $order->get_status() ) {
367
+		if ('on-hold' !== $order->get_status() || 'cancelled' !== $order->get_status()) {
368 368
 			return;
369 369
 		}
370 370
 
371
-		$order->update_status( 'cancelled', __( 'This payment has cancelled.', 'woocommerce-gateway-stripe' ) );
371
+		$order->update_status('cancelled', __('This payment has cancelled.', 'woocommerce-gateway-stripe'));
372 372
 
373
-		do_action( 'wc_gateway_stripe_process_webhook_payment_error', $order, $notification );
373
+		do_action('wc_gateway_stripe_process_webhook_payment_error', $order, $notification);
374 374
 	}
375 375
 
376 376
 	/**
@@ -381,31 +381,31 @@  discard block
 block discarded – undo
381 381
 	 * @version 4.0.0
382 382
 	 * @param object $notification
383 383
 	 */
384
-	public function process_webhook_refund( $notification ) {
385
-		$order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->id );
384
+	public function process_webhook_refund($notification) {
385
+		$order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->id);
386 386
 
387
-		if ( ! $order ) {
388
-			WC_Stripe_Logger::log( 'Could not find order via charge ID: ' . $notification->data->object->id );
387
+		if ( ! $order) {
388
+			WC_Stripe_Logger::log('Could not find order via charge ID: ' . $notification->data->object->id);
389 389
 			return;
390 390
 		}
391 391
 
392 392
 		$order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
393 393
 
394
-		if ( 'stripe' === ( WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method() ) ) {
395
-			$charge   = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_transaction_id', true ) : $order->get_transaction_id();
396
-			$captured = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_stripe_charge_captured', true ) : $order->get_meta( '_stripe_charge_captured', true );
394
+		if ('stripe' === (WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method())) {
395
+			$charge   = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_transaction_id', true) : $order->get_transaction_id();
396
+			$captured = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_stripe_charge_captured', true) : $order->get_meta('_stripe_charge_captured', true);
397 397
 
398 398
 			// Only refund captured charge.
399
-			if ( $charge && 'yes' === $captured ) {
399
+			if ($charge && 'yes' === $captured) {
400 400
 				// Create the refund.
401
-				$refund = wc_create_refund( array(
401
+				$refund = wc_create_refund(array(
402 402
 					'order_id'       => $order_id,
403
-					'amount'         => $this->get_refund_amount( $notification ),
404
-					'reason'         => __( 'Refunded via Stripe Dashboard', 'woocommerce-gateway-stripe' ),
405
-				) );
403
+					'amount'         => $this->get_refund_amount($notification),
404
+					'reason'         => __('Refunded via Stripe Dashboard', 'woocommerce-gateway-stripe'),
405
+				));
406 406
 
407
-				if ( is_wp_error( $refund ) ) {
408
-					WC_Stripe_Logger::log( $refund->get_error_message() );
407
+				if (is_wp_error($refund)) {
408
+					WC_Stripe_Logger::log($refund->get_error_message());
409 409
 				}
410 410
 			}
411 411
 		}
@@ -418,7 +418,7 @@  discard block
 block discarded – undo
418 418
 	 * @version 4.0.0
419 419
 	 * @param object $notification
420 420
 	 */
421
-	public function is_partial_capture( $notification ) {
421
+	public function is_partial_capture($notification) {
422 422
 		return 0 < $notification->data->object->amount_refunded;
423 423
 	}
424 424
 
@@ -429,11 +429,11 @@  discard block
 block discarded – undo
429 429
 	 * @version 4.0.0
430 430
 	 * @param object $notification
431 431
 	 */
432
-	public function get_refund_amount( $notification ) {
433
-		if ( $this->is_partial_capture( $notification ) ) {
432
+	public function get_refund_amount($notification) {
433
+		if ($this->is_partial_capture($notification)) {
434 434
 			$amount = $notification->data->object->amount_refunded / 100;
435 435
 
436
-			if ( in_array( strtolower( $notification->data->object->currency ), WC_Stripe_Helper::no_decimal_currencies() ) ) {
436
+			if (in_array(strtolower($notification->data->object->currency), WC_Stripe_Helper::no_decimal_currencies())) {
437 437
 				$amount = $notification->data->object->amount_refunded;
438 438
 			}
439 439
 
@@ -450,12 +450,12 @@  discard block
 block discarded – undo
450 450
 	 * @version 4.0.0
451 451
 	 * @param object $notification
452 452
 	 */
453
-	public function get_partial_amount_to_charge( $notification ) {
454
-		if ( $this->is_partial_capture( $notification ) ) {
455
-			$amount = ( $notification->data->object->amount - $notification->data->object->amount_refunded ) / 100;
453
+	public function get_partial_amount_to_charge($notification) {
454
+		if ($this->is_partial_capture($notification)) {
455
+			$amount = ($notification->data->object->amount - $notification->data->object->amount_refunded) / 100;
456 456
 
457
-			if ( in_array( strtolower( $notification->data->object->currency ), WC_Stripe_Helper::no_decimal_currencies() ) ) {
458
-				$amount = ( $notification->data->object->amount - $notification->data->object->amount_refunded );
457
+			if (in_array(strtolower($notification->data->object->currency), WC_Stripe_Helper::no_decimal_currencies())) {
458
+				$amount = ($notification->data->object->amount - $notification->data->object->amount_refunded);
459 459
 			}
460 460
 
461 461
 			return $amount;
@@ -471,36 +471,36 @@  discard block
 block discarded – undo
471 471
 	 * @version 4.0.0
472 472
 	 * @param string $request_body
473 473
 	 */
474
-	public function process_webhook( $request_body ) {
475
-		$notification = json_decode( $request_body );
474
+	public function process_webhook($request_body) {
475
+		$notification = json_decode($request_body);
476 476
 
477
-		switch ( $notification->type ) {
477
+		switch ($notification->type) {
478 478
 			case 'source.chargeable':
479
-				$this->process_webhook_payment( $notification );
479
+				$this->process_webhook_payment($notification);
480 480
 				break;
481 481
 
482 482
 			case 'source.canceled':
483
-				$this->process_webhook_source_canceled( $notification );
483
+				$this->process_webhook_source_canceled($notification);
484 484
 				break;
485 485
 
486 486
 			case 'charge.succeeded':
487
-				$this->process_webhook_charge_succeeded( $notification );
487
+				$this->process_webhook_charge_succeeded($notification);
488 488
 				break;
489 489
 
490 490
 			case 'charge.failed':
491
-				$this->process_webhook_charge_failed( $notification );
491
+				$this->process_webhook_charge_failed($notification);
492 492
 				break;
493 493
 
494 494
 			case 'charge.captured':
495
-				$this->process_webhook_capture( $notification );
495
+				$this->process_webhook_capture($notification);
496 496
 				break;
497 497
 
498 498
 			case 'charge.dispute.created':
499
-				$this->process_webhook_dispute( $notification );
499
+				$this->process_webhook_dispute($notification);
500 500
 				break;
501 501
 
502 502
 			case 'charge.refunded':
503
-				$this->process_webhook_refund( $notification );
503
+				$this->process_webhook_refund($notification);
504 504
 				break;
505 505
 
506 506
 		}
Please login to merge, or discard this patch.
includes/class-wc-stripe-customer.php 1 patch
Spacing   +85 added lines, -85 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) {
2
+if ( ! defined('ABSPATH')) {
3 3
 	exit;
4 4
 }
5 5
 
@@ -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
 
@@ -90,14 +90,14 @@  discard block
 block discarded – undo
90 90
 	 * Get data from the Stripe API about this customer
91 91
 	 */
92 92
 	public function get_customer_data() {
93
-		$this->customer_data = get_transient( 'stripe_customer_' . $this->get_id() );
93
+		$this->customer_data = get_transient('stripe_customer_' . $this->get_id());
94 94
 
95
-		if ( empty( $this->customer_data ) && $this->get_id() && false === $this->customer_data ) {
96
-			$response = WC_Stripe_API::request( array(), 'customers/' . $this->get_id() );
95
+		if (empty($this->customer_data) && $this->get_id() && false === $this->customer_data) {
96
+			$response = WC_Stripe_API::request(array(), 'customers/' . $this->get_id());
97 97
 
98
-			if ( empty( $response->error ) ) {
99
-				$this->set_customer_data( $response );
100
-				set_transient( 'stripe_customer_' . $this->get_id(), $response, HOUR_IN_SECONDS * 48 );
98
+			if (empty($response->error)) {
99
+				$this->set_customer_data($response);
100
+				set_transient('stripe_customer_' . $this->get_id(), $response, HOUR_IN_SECONDS * 48);
101 101
 			}
102 102
 		}
103 103
 
@@ -112,7 +112,7 @@  discard block
 block discarded – undo
112 112
 		$data   = $this->get_customer_data();
113 113
 		$source = '';
114 114
 
115
-		if ( $data ) {
115
+		if ($data) {
116 116
 			$source = $data->default_source;
117 117
 		}
118 118
 
@@ -124,13 +124,13 @@  discard block
 block discarded – undo
124 124
 	 * @param array $args
125 125
 	 * @return WP_Error|int
126 126
 	 */
127
-	public function create_customer( $args = array() ) {
128
-		$billing_email = isset( $_POST['billing_email'] ) ? filter_var( $_POST['billing_email'], FILTER_SANITIZE_EMAIL ) : '';
127
+	public function create_customer($args = array()) {
128
+		$billing_email = isset($_POST['billing_email']) ? filter_var($_POST['billing_email'], FILTER_SANITIZE_EMAIL) : '';
129 129
 		$user = $this->get_user();
130 130
 
131
-		if ( $user ) {
132
-			$billing_first_name = get_user_meta( $user->ID, 'billing_first_name', true );
133
-			$billing_last_name  = get_user_meta( $user->ID, 'billing_last_name', true );
131
+		if ($user) {
132
+			$billing_first_name = get_user_meta($user->ID, 'billing_first_name', true);
133
+			$billing_last_name  = get_user_meta($user->ID, 'billing_last_name', true);
134 134
 
135 135
 			$defaults = array(
136 136
 				'email'       => $user->user_email,
@@ -145,24 +145,24 @@  discard block
 block discarded – undo
145 145
 
146 146
 		$metadata = array();
147 147
 
148
-		$defaults['metadata'] = apply_filters( 'wc_stripe_customer_metadata', $metadata, $user );
148
+		$defaults['metadata'] = apply_filters('wc_stripe_customer_metadata', $metadata, $user);
149 149
 
150
-		$args     = wp_parse_args( $args, $defaults );
151
-		$response = WC_Stripe_API::request( apply_filters( 'wc_stripe_create_customer_args', $args ), 'customers' );
150
+		$args     = wp_parse_args($args, $defaults);
151
+		$response = WC_Stripe_API::request(apply_filters('wc_stripe_create_customer_args', $args), 'customers');
152 152
 
153
-		if ( ! empty( $response->error ) ) {
154
-			throw new Exception( $response->error->message );
153
+		if ( ! empty($response->error)) {
154
+			throw new Exception($response->error->message);
155 155
 		}
156 156
 
157
-		$this->set_id( $response->id );
157
+		$this->set_id($response->id);
158 158
 		$this->clear_cache();
159
-		$this->set_customer_data( $response );
159
+		$this->set_customer_data($response);
160 160
 
161
-		if ( $this->get_user_id() ) {
162
-			update_user_meta( $this->get_user_id(), '_stripe_customer_id', $response->id );
161
+		if ($this->get_user_id()) {
162
+			update_user_meta($this->get_user_id(), '_stripe_customer_id', $response->id);
163 163
 		}
164 164
 
165
-		do_action( 'woocommerce_stripe_add_customer', $args, $response );
165
+		do_action('woocommerce_stripe_add_customer', $args, $response);
166 166
 
167 167
 		return $response->id;
168 168
 	}
@@ -173,72 +173,72 @@  discard block
 block discarded – undo
173 173
 	 * @param bool $retry
174 174
 	 * @return WP_Error|int
175 175
 	 */
176
-	public function add_source( $source_id, $retry = true ) {
177
-		if ( ! $this->get_id() ) {
176
+	public function add_source($source_id, $retry = true) {
177
+		if ( ! $this->get_id()) {
178 178
 			$this->create_customer();
179 179
 		}
180 180
 
181
-		$response = WC_Stripe_API::request( array(
181
+		$response = WC_Stripe_API::request(array(
182 182
 			'source' => $source_id,
183
-		), 'customers/' . $this->get_id() . '/sources' );
183
+		), 'customers/' . $this->get_id() . '/sources');
184 184
 
185
-		if ( ! empty( $response->error ) ) {
185
+		if ( ! empty($response->error)) {
186 186
 			// It is possible the WC user once was linked to a customer on Stripe
187 187
 			// but no longer exists. Instead of failing, lets try to create a
188 188
 			// new customer.
189
-			if ( preg_match( '/No such customer/i', $response->error->message ) ) {
190
-				delete_user_meta( $this->get_user_id(), '_stripe_customer_id' );
189
+			if (preg_match('/No such customer/i', $response->error->message)) {
190
+				delete_user_meta($this->get_user_id(), '_stripe_customer_id');
191 191
 				$this->create_customer();
192
-				return $this->add_source( $source_id, false );
192
+				return $this->add_source($source_id, false);
193 193
 			} else {
194 194
 				return $response;
195 195
 			}
196
-		} elseif ( empty( $response->id ) ) {
197
-			return new WP_Error( 'error', __( 'Unable to add payment source.', 'woocommerce-gateway-stripe' ) );
196
+		} elseif (empty($response->id)) {
197
+			return new WP_Error('error', __('Unable to add payment source.', 'woocommerce-gateway-stripe'));
198 198
 		}
199 199
 
200 200
 		// Add token to WooCommerce.
201
-		if ( $this->get_user_id() && class_exists( 'WC_Payment_Token_CC' ) ) {
202
-			if ( ! empty( $response->type ) ) {
203
-				switch ( $response->type ) {
201
+		if ($this->get_user_id() && class_exists('WC_Payment_Token_CC')) {
202
+			if ( ! empty($response->type)) {
203
+				switch ($response->type) {
204 204
 					case 'alipay':
205 205
 						break;
206 206
 					case 'sepa_debit':
207 207
 						$wc_token = new WC_Payment_Token_SEPA();
208
-						$wc_token->set_token( $response->id );
209
-						$wc_token->set_gateway_id( 'stripe_sepa' );
210
-						$wc_token->set_last4( $response->sepa_debit->last4 );
208
+						$wc_token->set_token($response->id);
209
+						$wc_token->set_gateway_id('stripe_sepa');
210
+						$wc_token->set_last4($response->sepa_debit->last4);
211 211
 						break;
212 212
 					default:
213
-						if ( 'source' === $response->object && 'card' === $response->type ) {
213
+						if ('source' === $response->object && 'card' === $response->type) {
214 214
 							$wc_token = new WC_Payment_Token_CC();
215
-							$wc_token->set_token( $response->id );
216
-							$wc_token->set_gateway_id( 'stripe' );
217
-							$wc_token->set_card_type( strtolower( $response->card->brand ) );
218
-							$wc_token->set_last4( $response->card->last4 );
219
-							$wc_token->set_expiry_month( $response->card->exp_month );
220
-							$wc_token->set_expiry_year( $response->card->exp_year );
215
+							$wc_token->set_token($response->id);
216
+							$wc_token->set_gateway_id('stripe');
217
+							$wc_token->set_card_type(strtolower($response->card->brand));
218
+							$wc_token->set_last4($response->card->last4);
219
+							$wc_token->set_expiry_month($response->card->exp_month);
220
+							$wc_token->set_expiry_year($response->card->exp_year);
221 221
 						}
222 222
 						break;
223 223
 				}
224 224
 			} else {
225 225
 				// Legacy.
226 226
 				$wc_token = new WC_Payment_Token_CC();
227
-				$wc_token->set_token( $response->id );
228
-				$wc_token->set_gateway_id( 'stripe' );
229
-				$wc_token->set_card_type( strtolower( $response->brand ) );
230
-				$wc_token->set_last4( $response->last4 );
231
-				$wc_token->set_expiry_month( $response->exp_month );
232
-				$wc_token->set_expiry_year( $response->exp_year );
227
+				$wc_token->set_token($response->id);
228
+				$wc_token->set_gateway_id('stripe');
229
+				$wc_token->set_card_type(strtolower($response->brand));
230
+				$wc_token->set_last4($response->last4);
231
+				$wc_token->set_expiry_month($response->exp_month);
232
+				$wc_token->set_expiry_year($response->exp_year);
233 233
 			}
234 234
 
235
-			$wc_token->set_user_id( $this->get_user_id() );
235
+			$wc_token->set_user_id($this->get_user_id());
236 236
 			$wc_token->save();
237 237
 		}
238 238
 
239 239
 		$this->clear_cache();
240 240
 
241
-		do_action( 'woocommerce_stripe_add_source', $this->get_id(), $wc_token, $response, $source_id );
241
+		do_action('woocommerce_stripe_add_source', $this->get_id(), $wc_token, $response, $source_id);
242 242
 
243 243
 		return $response->id;
244 244
 	}
@@ -250,38 +250,38 @@  discard block
 block discarded – undo
250 250
 	 * @return array
251 251
 	 */
252 252
 	public function get_sources() {
253
-		$sources = get_transient( 'stripe_sources_' . $this->get_id() );
253
+		$sources = get_transient('stripe_sources_' . $this->get_id());
254 254
 
255
-		if ( false === $sources ) {
256
-			$response = WC_Stripe_API::request( array(
255
+		if (false === $sources) {
256
+			$response = WC_Stripe_API::request(array(
257 257
 				'limit'       => 100,
258
-			), 'customers/' . $this->get_id() . '/sources', 'GET' );
258
+			), 'customers/' . $this->get_id() . '/sources', 'GET');
259 259
 
260
-			if ( ! empty( $response->error ) ) {
260
+			if ( ! empty($response->error)) {
261 261
 				return array();
262 262
 			}
263 263
 
264
-			if ( is_array( $response->data ) ) {
264
+			if (is_array($response->data)) {
265 265
 				$sources = $response->data;
266 266
 			}
267 267
 
268
-			set_transient( 'stripe_sources_' . $this->get_id(), $sources, HOUR_IN_SECONDS * 24 );
268
+			set_transient('stripe_sources_' . $this->get_id(), $sources, HOUR_IN_SECONDS * 24);
269 269
 		}
270 270
 
271
-		return empty( $sources ) ? array() : $sources;
271
+		return empty($sources) ? array() : $sources;
272 272
 	}
273 273
 
274 274
 	/**
275 275
 	 * Delete a source from stripe.
276 276
 	 * @param string $source_id
277 277
 	 */
278
-	public function delete_source( $source_id ) {
279
-		$response = WC_Stripe_API::request( array(), 'customers/' . $this->get_id() . '/sources/' . sanitize_text_field( $source_id ), 'DELETE' );
278
+	public function delete_source($source_id) {
279
+		$response = WC_Stripe_API::request(array(), 'customers/' . $this->get_id() . '/sources/' . sanitize_text_field($source_id), 'DELETE');
280 280
 
281 281
 		$this->clear_cache();
282 282
 
283
-		if ( empty( $response->error ) ) {
284
-			do_action( 'wc_stripe_delete_source', $this->get_id(), $response );
283
+		if (empty($response->error)) {
284
+			do_action('wc_stripe_delete_source', $this->get_id(), $response);
285 285
 
286 286
 			return true;
287 287
 		}
@@ -293,15 +293,15 @@  discard block
 block discarded – undo
293 293
 	 * Set default source in Stripe
294 294
 	 * @param string $source_id
295 295
 	 */
296
-	public function set_default_source( $source_id ) {
297
-		$response = WC_Stripe_API::request( array(
298
-			'default_source' => sanitize_text_field( $source_id ),
299
-		), 'customers/' . $this->get_id(), 'POST' );
296
+	public function set_default_source($source_id) {
297
+		$response = WC_Stripe_API::request(array(
298
+			'default_source' => sanitize_text_field($source_id),
299
+		), 'customers/' . $this->get_id(), 'POST');
300 300
 
301 301
 		$this->clear_cache();
302 302
 
303
-		if ( empty( $response->error ) ) {
304
-			do_action( 'wc_stripe_set_default_source', $this->get_id(), $response );
303
+		if (empty($response->error)) {
304
+			do_action('wc_stripe_set_default_source', $this->get_id(), $response);
305 305
 
306 306
 			return true;
307 307
 		}
@@ -313,8 +313,8 @@  discard block
 block discarded – undo
313 313
 	 * Deletes caches for this users cards.
314 314
 	 */
315 315
 	public function clear_cache() {
316
-		delete_transient( 'stripe_sources_' . $this->get_id() );
317
-		delete_transient( 'stripe_customer_' . $this->get_id() );
316
+		delete_transient('stripe_sources_' . $this->get_id());
317
+		delete_transient('stripe_customer_' . $this->get_id());
318 318
 		$this->customer_data = array();
319 319
 	}
320 320
 }
Please login to merge, or discard this patch.
includes/class-wc-stripe-api.php 1 patch
Spacing   +25 added lines, -25 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,13 +95,13 @@  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
-			$headers['Idempotency-Key'] = uniqid( 'stripe_' );
103
+		if ('charges' === $api && 'POST' === $method) {
104
+			$headers['Idempotency-Key'] = uniqid('stripe_');
105 105
 		}
106 106
 
107 107
 		$response = wp_safe_remote_post(
@@ -109,17 +109,17 @@  discard block
 block discarded – undo
109 109
 			array(
110 110
 				'method'  => $method,
111 111
 				'headers' => $headers,
112
-				'body'    => apply_filters( 'woocommerce_stripe_request_body', $request, $api ),
112
+				'body'    => apply_filters('woocommerce_stripe_request_body', $request, $api),
113 113
 				'timeout' => 70,
114 114
 			)
115 115
 		);
116 116
 
117
-		if ( is_wp_error( $response ) || empty( $response['body'] ) ) {
118
-			WC_Stripe_Logger::log( 'Error Response: ' . print_r( $response, true ) );
119
-			throw new Exception( __( 'There was a problem connecting to the Stripe API endpoint.', 'woocommerce-gateway-stripe' ) );
117
+		if (is_wp_error($response) || empty($response['body'])) {
118
+			WC_Stripe_Logger::log('Error Response: ' . print_r($response, true));
119
+			throw new Exception(__('There was a problem connecting to the Stripe API endpoint.', 'woocommerce-gateway-stripe'));
120 120
 		}
121 121
 
122
-		return json_decode( $response['body'] );
122
+		return json_decode($response['body']);
123 123
 	}
124 124
 
125 125
 	/**
@@ -129,8 +129,8 @@  discard block
 block discarded – undo
129 129
 	 * @version 4.0.0
130 130
 	 * @param string $api
131 131
 	 */
132
-	public static function retrieve( $api ) {
133
-		WC_Stripe_Logger::log( "{$api}" );
132
+	public static function retrieve($api) {
133
+		WC_Stripe_Logger::log("{$api}");
134 134
 
135 135
 		$ua = self::get_user_agent();
136 136
 
@@ -143,11 +143,11 @@  discard block
 block discarded – undo
143 143
 			)
144 144
 		);
145 145
 
146
-		if ( is_wp_error( $response ) || empty( $response['body'] ) ) {
147
-			WC_Stripe_Logger::log( 'Error Response: ' . print_r( $response, true ) );
148
-			return new WP_Error( 'stripe_error', __( 'There was a problem connecting to the Stripe API endpoint.', 'woocommerce-gateway-stripe' ) );
146
+		if (is_wp_error($response) || empty($response['body'])) {
147
+			WC_Stripe_Logger::log('Error Response: ' . print_r($response, true));
148
+			return new WP_Error('stripe_error', __('There was a problem connecting to the Stripe API endpoint.', 'woocommerce-gateway-stripe'));
149 149
 		}
150 150
 
151
-		return json_decode( $response['body'] );
151
+		return json_decode($response['body']);
152 152
 	}
153 153
 }
Please login to merge, or discard this patch.
includes/payment-methods/class-wc-gateway-stripe-bitcoin.php 1 patch
Spacing   +88 added lines, -88 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) {
2
+if ( ! defined('ABSPATH')) {
3 3
 	exit;
4 4
 }
5 5
 
@@ -64,9 +64,9 @@  discard block
 block discarded – undo
64 64
 	 */
65 65
 	public function __construct() {
66 66
 		$this->id                   = 'stripe_bitcoin';
67
-		$this->method_title         = __( 'Stripe Bitcoin', 'woocommerce-gateway-stripe' );
67
+		$this->method_title         = __('Stripe Bitcoin', 'woocommerce-gateway-stripe');
68 68
 		/* translators: link */
69
-		$this->method_description   = sprintf( __( 'All other general Stripe settings can be adjusted <a href="%s">here</a>.', 'woocommerce-gateway-stripe' ), admin_url( 'admin.php?page=wc-settings&tab=checkout&section=stripe' ) );
69
+		$this->method_description   = sprintf(__('All other general Stripe settings can be adjusted <a href="%s">here</a>.', 'woocommerce-gateway-stripe'), admin_url('admin.php?page=wc-settings&tab=checkout&section=stripe'));
70 70
 		$this->supports             = array(
71 71
 			'products',
72 72
 			'refunds',
@@ -78,29 +78,29 @@  discard block
 block discarded – undo
78 78
 		// Load the settings.
79 79
 		$this->init_settings();
80 80
 
81
-		$main_settings              = get_option( 'woocommerce_stripe_settings' );
82
-		$this->title                = $this->get_option( 'title' );
83
-		$this->description          = $this->get_option( 'description' );
84
-		$this->enabled              = $this->get_option( 'enabled' );
85
-		$this->testmode             = ( ! empty( $main_settings['testmode'] ) && 'yes' === $main_settings['testmode'] ) ? true : false;
86
-		$this->saved_cards          = ( ! empty( $main_settings['saved_cards'] ) && 'yes' === $main_settings['saved_cards'] ) ? true : false;
87
-		$this->publishable_key      = ! empty( $main_settings['publishable_key'] ) ? $main_settings['publishable_key'] : '';
88
-		$this->secret_key           = ! empty( $main_settings['secret_key'] ) ? $main_settings['secret_key'] : '';
89
-		$this->statement_descriptor = ! empty( $main_settings['statement_descriptor'] ) ? $main_settings['statement_descriptor'] : '';
90
-
91
-		if ( $this->testmode ) {
92
-			$this->publishable_key = ! empty( $main_settings['test_publishable_key'] ) ? $main_settings['test_publishable_key'] : '';
93
-			$this->secret_key      = ! empty( $main_settings['test_secret_key'] ) ? $main_settings['test_secret_key'] : '';
81
+		$main_settings              = get_option('woocommerce_stripe_settings');
82
+		$this->title                = $this->get_option('title');
83
+		$this->description          = $this->get_option('description');
84
+		$this->enabled              = $this->get_option('enabled');
85
+		$this->testmode             = ( ! empty($main_settings['testmode']) && 'yes' === $main_settings['testmode']) ? true : false;
86
+		$this->saved_cards          = ( ! empty($main_settings['saved_cards']) && 'yes' === $main_settings['saved_cards']) ? true : false;
87
+		$this->publishable_key      = ! empty($main_settings['publishable_key']) ? $main_settings['publishable_key'] : '';
88
+		$this->secret_key           = ! empty($main_settings['secret_key']) ? $main_settings['secret_key'] : '';
89
+		$this->statement_descriptor = ! empty($main_settings['statement_descriptor']) ? $main_settings['statement_descriptor'] : '';
90
+
91
+		if ($this->testmode) {
92
+			$this->publishable_key = ! empty($main_settings['test_publishable_key']) ? $main_settings['test_publishable_key'] : '';
93
+			$this->secret_key      = ! empty($main_settings['test_secret_key']) ? $main_settings['test_secret_key'] : '';
94 94
 		}
95 95
 
96
-		add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) );
97
-		add_action( 'admin_notices', array( $this, 'check_environment' ) );
98
-		add_action( 'admin_head', array( $this, 'remove_admin_notice' ) );
99
-		add_action( 'wp_enqueue_scripts', array( $this, 'payment_scripts' ) );
100
-		add_action( 'woocommerce_thankyou_stripe_bitcoin', array( $this, 'thankyou_page' ) );
96
+		add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options'));
97
+		add_action('admin_notices', array($this, 'check_environment'));
98
+		add_action('admin_head', array($this, 'remove_admin_notice'));
99
+		add_action('wp_enqueue_scripts', array($this, 'payment_scripts'));
100
+		add_action('woocommerce_thankyou_stripe_bitcoin', array($this, 'thankyou_page'));
101 101
 
102 102
 		// Customer Emails
103
-		add_action( 'woocommerce_email_before_order_table', array( $this, 'email_instructions' ), 10, 3 );
103
+		add_action('woocommerce_email_before_order_table', array($this, 'email_instructions'), 10, 3);
104 104
 	}
105 105
 
106 106
 	/**
@@ -110,19 +110,19 @@  discard block
 block discarded – undo
110 110
 	 * @version 4.0.0
111 111
 	 */
112 112
 	public function check_environment() {
113
-		if ( ! current_user_can( 'manage_woocommerce' ) ) {
113
+		if ( ! current_user_can('manage_woocommerce')) {
114 114
 			return;
115 115
 		}
116 116
 
117 117
 		$environment_warning = $this->get_environment_warning();
118 118
 
119
-		if ( $environment_warning ) {
120
-			$this->add_admin_notice( 'bad_environment', 'error', $environment_warning );
119
+		if ($environment_warning) {
120
+			$this->add_admin_notice('bad_environment', 'error', $environment_warning);
121 121
 		}
122 122
 
123
-		foreach ( (array) $this->notices as $notice_key => $notice ) {
124
-			echo "<div class='" . esc_attr( $notice['class'] ) . "'><p>";
125
-			echo wp_kses( $notice['message'], array( 'a' => array( 'href' => array() ) ) );
123
+		foreach ((array) $this->notices as $notice_key => $notice) {
124
+			echo "<div class='" . esc_attr($notice['class']) . "'><p>";
125
+			echo wp_kses($notice['message'], array('a' => array('href' => array())));
126 126
 			echo '</p></div>';
127 127
 		}
128 128
 	}
@@ -135,8 +135,8 @@  discard block
 block discarded – undo
135 135
 	 * @version 4.0.0
136 136
 	 */
137 137
 	public function get_environment_warning() {
138
-		if ( 'yes' === $this->enabled && ! in_array( get_woocommerce_currency(), $this->get_supported_currency() ) ) {
139
-			$message = __( 'Bitcoin is enabled - it requires store currency to be set to USD.', 'woocommerce-gateway-stripe' );
138
+		if ('yes' === $this->enabled && ! in_array(get_woocommerce_currency(), $this->get_supported_currency())) {
139
+			$message = __('Bitcoin is enabled - it requires store currency to be set to USD.', 'woocommerce-gateway-stripe');
140 140
 
141 141
 			return $message;
142 142
 		}
@@ -152,9 +152,9 @@  discard block
 block discarded – undo
152 152
 	 * @return array
153 153
 	 */
154 154
 	public function get_supported_currency() {
155
-		return apply_filters( 'wc_stripe_bitcoin_supported_currencies', array(
155
+		return apply_filters('wc_stripe_bitcoin_supported_currencies', array(
156 156
 			'USD',
157
-		) );
157
+		));
158 158
 	}
159 159
 
160 160
 	/**
@@ -165,7 +165,7 @@  discard block
 block discarded – undo
165 165
 	 * @return bool
166 166
 	 */
167 167
 	public function is_available() {
168
-		if ( ! in_array( get_woocommerce_currency(), $this->get_supported_currency() ) ) {
168
+		if ( ! in_array(get_woocommerce_currency(), $this->get_supported_currency())) {
169 169
 			return false;
170 170
 		}
171 171
 
@@ -186,7 +186,7 @@  discard block
 block discarded – undo
186 186
 
187 187
 		$icons_str .= $icons['bitcoin'];
188 188
 
189
-		return apply_filters( 'woocommerce_gateway_icon', $icons_str, $this->id );
189
+		return apply_filters('woocommerce_gateway_icon', $icons_str, $this->id);
190 190
 	}
191 191
 
192 192
 	/**
@@ -197,19 +197,19 @@  discard block
 block discarded – undo
197 197
 	 * @access public
198 198
 	 */
199 199
 	public function payment_scripts() {
200
-		if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) && ! is_add_payment_method_page() ) {
200
+		if ( ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order']) && ! is_add_payment_method_page()) {
201 201
 			return;
202 202
 		}
203 203
 
204
-		wp_enqueue_style( 'stripe_paymentfonts' );
205
-		wp_enqueue_script( 'woocommerce_stripe' );
204
+		wp_enqueue_style('stripe_paymentfonts');
205
+		wp_enqueue_script('woocommerce_stripe');
206 206
 	}
207 207
 
208 208
 	/**
209 209
 	 * Initialize Gateway Settings Form Fields.
210 210
 	 */
211 211
 	public function init_form_fields() {
212
-		$this->form_fields = require( WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-bitcoin-settings.php' );
212
+		$this->form_fields = require(WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-bitcoin-settings.php');
213 213
 	}
214 214
 
215 215
 	/**
@@ -220,25 +220,25 @@  discard block
 block discarded – undo
220 220
 		$total                = WC()->cart->total;
221 221
 
222 222
 		// If paying from order, we need to get total from order not cart.
223
-		if ( isset( $_GET['pay_for_order'] ) && ! empty( $_GET['key'] ) ) {
224
-			$order = wc_get_order( wc_get_order_id_by_order_key( wc_clean( $_GET['key'] ) ) );
223
+		if (isset($_GET['pay_for_order']) && ! empty($_GET['key'])) {
224
+			$order = wc_get_order(wc_get_order_id_by_order_key(wc_clean($_GET['key'])));
225 225
 			$total = $order->get_total();
226 226
 		}
227 227
 
228
-		if ( is_add_payment_method_page() ) {
229
-			$pay_button_text = __( 'Add Payment', 'woocommerce-gateway-stripe' );
230
-			$total        = '';
228
+		if (is_add_payment_method_page()) {
229
+			$pay_button_text = __('Add Payment', 'woocommerce-gateway-stripe');
230
+			$total = '';
231 231
 		} else {
232 232
 			$pay_button_text = '';
233 233
 		}
234 234
 
235 235
 		echo '<div
236 236
 			id="stripe-bitcoin-payment-data"
237
-			data-amount="' . esc_attr( WC_Stripe_Helper::get_stripe_amount( $total ) ) . '"
238
-			data-currency="' . esc_attr( strtolower( get_woocommerce_currency() ) ) . '">';
237
+			data-amount="' . esc_attr(WC_Stripe_Helper::get_stripe_amount($total)) . '"
238
+			data-currency="' . esc_attr(strtolower(get_woocommerce_currency())) . '">';
239 239
 
240
-		if ( $this->description ) {
241
-			echo apply_filters( 'wc_stripe_description', wpautop( wp_kses_post( $this->description ) ) );
240
+		if ($this->description) {
241
+			echo apply_filters('wc_stripe_description', wpautop(wp_kses_post($this->description)));
242 242
 		}
243 243
 
244 244
 		echo '</div>';
@@ -249,8 +249,8 @@  discard block
 block discarded – undo
249 249
 	 *
250 250
 	 * @param int $order_id
251 251
 	 */
252
-	public function thankyou_page( $order_id ) {
253
-		$this->get_instructions( $order_id );
252
+	public function thankyou_page($order_id) {
253
+		$this->get_instructions($order_id);
254 254
 	}
255 255
 
256 256
 	/**
@@ -262,13 +262,13 @@  discard block
 block discarded – undo
262 262
 	 * @param bool $sent_to_admin
263 263
 	 * @param bool $plain_text
264 264
 	 */
265
-	public function email_instructions( $order, $sent_to_admin, $plain_text = false ) {
265
+	public function email_instructions($order, $sent_to_admin, $plain_text = false) {
266 266
 		$order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
267 267
 
268 268
 		$payment_method = WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method();
269 269
 
270
-		if ( ! $sent_to_admin && 'stripe_bitcoin' === $payment_method && $order->has_status( 'on-hold' ) ) {
271
-			$this->get_instructions( $order_id, $plain_text );
270
+		if ( ! $sent_to_admin && 'stripe_bitcoin' === $payment_method && $order->has_status('on-hold')) {
271
+			$this->get_instructions($order_id, $plain_text);
272 272
 		}
273 273
 	}
274 274
 
@@ -279,38 +279,38 @@  discard block
 block discarded – undo
279 279
 	 * @version 4.0.0
280 280
 	 * @param int $order_id
281 281
 	 */
282
-	public function get_instructions( $order_id, $plain_text = false ) {
283
-		$data = get_post_meta( $order_id, '_stripe_bitcoin', true );
282
+	public function get_instructions($order_id, $plain_text = false) {
283
+		$data = get_post_meta($order_id, '_stripe_bitcoin', true);
284 284
 
285
-		if ( $plain_text ) {
286
-			esc_html_e( 'Please pay the following:', 'woocommerce-gateway-stripe' ) . "\n\n";
285
+		if ($plain_text) {
286
+			esc_html_e('Please pay the following:', 'woocommerce-gateway-stripe') . "\n\n";
287 287
 			echo "=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\n\n";
288
-			esc_html_e( 'Bitcoin Amount:', 'woocommerce-gateway-stripe' ) . "\n\n";
288
+			esc_html_e('Bitcoin Amount:', 'woocommerce-gateway-stripe') . "\n\n";
289 289
 			echo $data['amount'] . "\n\n";
290 290
 			echo "=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\n\n";
291
-			esc_html_e( 'Receiver:', 'woocommerce-gateway-stripe' ) . "\n\n";
291
+			esc_html_e('Receiver:', 'woocommerce-gateway-stripe') . "\n\n";
292 292
 			echo $data['address'] . "\n\n";
293 293
 			echo "=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\n\n";
294
-			esc_html_e( 'URI:', 'woocommerce-gateway-stripe' ) . "\n\n";
294
+			esc_html_e('URI:', 'woocommerce-gateway-stripe') . "\n\n";
295 295
 			echo $data['uri'] . "\n\n";
296 296
 		} else {
297 297
 			?>
298
-			<h3><?php esc_html_e( 'Please pay the following:', 'woocommerce-gateway-stripe' ); ?></h3>
298
+			<h3><?php esc_html_e('Please pay the following:', 'woocommerce-gateway-stripe'); ?></h3>
299 299
 			<ul class="woocommerce-order-overview woocommerce-thankyou-order-details order_details">
300 300
 			<li class="woocommerce-order-overview__order order">
301
-				<?php esc_html_e( 'Bitcoin Amount:', 'woocommerce-gateway-stripe' ); ?>
301
+				<?php esc_html_e('Bitcoin Amount:', 'woocommerce-gateway-stripe'); ?>
302 302
 				<strong><?php echo $data['amount']; ?></strong>
303 303
 			</li>
304 304
 			<li class="woocommerce-order-overview__order order">
305
-				<?php esc_html_e( 'Receiver:', 'woocommerce-gateway-stripe' ); ?>
305
+				<?php esc_html_e('Receiver:', 'woocommerce-gateway-stripe'); ?>
306 306
 				<strong><?php echo $data['address']; ?></strong>
307 307
 			</li>
308 308
 			<li class="woocommerce-order-overview__order order">
309
-				<?php esc_html_e( 'URI:', 'woocommerce-gateway-stripe' ); ?>
309
+				<?php esc_html_e('URI:', 'woocommerce-gateway-stripe'); ?>
310 310
 				<strong>
311 311
 				<?php
312 312
 				/* translators: link */
313
-				printf( __( '<a href="%s">Pay Bitcoin</a>', 'woocommerce-gateway-stripe' ), $data['uri'] );
313
+				printf(__('<a href="%s">Pay Bitcoin</a>', 'woocommerce-gateway-stripe'), $data['uri']);
314 314
 				?>
315 315
 				</strong>
316 316
 			</li>
@@ -327,7 +327,7 @@  discard block
 block discarded – undo
327 327
 	 * @param object $order
328 328
 	 * @param object $source_object
329 329
 	 */
330
-	public function save_instructions( $order, $source_object ) {
330
+	public function save_instructions($order, $source_object) {
331 331
 		$data = array(
332 332
 			'amount'  => $source_object->bitcoin->amount,
333 333
 			'address' => $source_object->bitcoin->address,
@@ -336,7 +336,7 @@  discard block
 block discarded – undo
336 336
 
337 337
 		$order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
338 338
 
339
-		update_post_meta( $order_id, '_stripe_bitcoin', $data );
339
+		update_post_meta($order_id, '_stripe_bitcoin', $data);
340 340
 	}
341 341
 
342 342
 	/**
@@ -350,40 +350,40 @@  discard block
 block discarded – undo
350 350
 	 *
351 351
 	 * @return array|void
352 352
 	 */
353
-	public function process_payment( $order_id, $retry = true, $force_save_source = false ) {
353
+	public function process_payment($order_id, $retry = true, $force_save_source = false) {
354 354
 		try {
355
-			$order = wc_get_order( $order_id );
356
-			$source_object = ! empty( $_POST['stripe_source'] ) ? json_decode( stripslashes( $_POST['stripe_source'] ) ) : false;
355
+			$order = wc_get_order($order_id);
356
+			$source_object = ! empty($_POST['stripe_source']) ? json_decode(stripslashes($_POST['stripe_source'])) : false;
357 357
 
358 358
 			// This comes from the create account checkbox in the checkout page.
359
-			$create_account = ! empty( $_POST['createaccount'] ) ? true : false;
359
+			$create_account = ! empty($_POST['createaccount']) ? true : false;
360 360
 
361
-			if ( $create_account ) {
361
+			if ($create_account) {
362 362
 				$new_customer_id     = WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id();
363
-				$new_stripe_customer = new WC_Stripe_Customer( $new_customer_id );
363
+				$new_stripe_customer = new WC_Stripe_Customer($new_customer_id);
364 364
 				$new_stripe_customer->create_customer();
365 365
 			}
366 366
 
367
-			$prepared_source = $this->prepare_source( get_current_user_id(), $force_save_source );
367
+			$prepared_source = $this->prepare_source(get_current_user_id(), $force_save_source);
368 368
 
369
-			if ( empty( $prepared_source->source ) ) {
370
-				$error_msg = __( 'Payment processing failed. Please retry.', 'woocommerce-gateway-stripe' );
371
-				throw new Exception( $error_msg );
369
+			if (empty($prepared_source->source)) {
370
+				$error_msg = __('Payment processing failed. Please retry.', 'woocommerce-gateway-stripe');
371
+				throw new Exception($error_msg);
372 372
 			}
373 373
 
374 374
 			// Store source to order meta.
375
-			$this->save_source( $order, $prepared_source );
375
+			$this->save_source($order, $prepared_source);
376 376
 
377 377
 
378 378
 			// This will throw exception if not valid.
379
-			$this->validate_minimum_order_amount( $order );
379
+			$this->validate_minimum_order_amount($order);
380 380
 
381
-			$this->save_instructions( $order, $source_object );
381
+			$this->save_instructions($order, $source_object);
382 382
 
383 383
 			// Mark as on-hold (we're awaiting the payment)
384
-			$order->update_status( 'on-hold', __( 'Awaiting Bitcoin payment', 'woocommerce-gateway-stripe' ) );
384
+			$order->update_status('on-hold', __('Awaiting Bitcoin payment', 'woocommerce-gateway-stripe'));
385 385
 
386
-			wc_reduce_stock_levels( $order_id );
386
+			wc_reduce_stock_levels($order_id);
387 387
 
388 388
 			// Remove cart
389 389
 			WC()->cart->empty_cart();
@@ -391,16 +391,16 @@  discard block
 block discarded – undo
391 391
 			// Return thankyou redirect
392 392
 			return array(
393 393
 				'result'    => 'success',
394
-				'redirect'  => $this->get_return_url( $order ),
394
+				'redirect'  => $this->get_return_url($order),
395 395
 			);
396
-		} catch ( Exception $e ) {
397
-			wc_add_notice( $e->getMessage(), 'error' );
398
-			WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() );
396
+		} catch (Exception $e) {
397
+			wc_add_notice($e->getMessage(), 'error');
398
+			WC_Stripe_Logger::log('Error: ' . $e->getMessage());
399 399
 
400
-			do_action( 'wc_gateway_stripe_process_payment_error', $e, $order );
400
+			do_action('wc_gateway_stripe_process_payment_error', $e, $order);
401 401
 
402
-			if ( $order->has_status( array( 'pending', 'failed' ) ) ) {
403
-				$this->send_failed_order_email( $order_id );
402
+			if ($order->has_status(array('pending', 'failed'))) {
403
+				$this->send_failed_order_email($order_id);
404 404
 			}
405 405
 
406 406
 			return array(
Please login to merge, or discard this patch.
includes/payment-methods/class-wc-gateway-stripe-ideal.php 1 patch
Spacing   +76 added lines, -76 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) {
2
+if ( ! defined('ABSPATH')) {
3 3
 	exit;
4 4
 }
5 5
 
@@ -57,9 +57,9 @@  discard block
 block discarded – undo
57 57
 	 */
58 58
 	public function __construct() {
59 59
 		$this->id                   = 'stripe_ideal';
60
-		$this->method_title         = __( 'Stripe iDeal', 'woocommerce-gateway-stripe' );
60
+		$this->method_title         = __('Stripe iDeal', 'woocommerce-gateway-stripe');
61 61
 		/* translators: link */
62
-		$this->method_description   = sprintf( __( 'All other general Stripe settings can be adjusted <a href="%s">here</a>.', 'woocommerce-gateway-stripe' ), admin_url( 'admin.php?page=wc-settings&tab=checkout&section=stripe' ) );
62
+		$this->method_description   = sprintf(__('All other general Stripe settings can be adjusted <a href="%s">here</a>.', 'woocommerce-gateway-stripe'), admin_url('admin.php?page=wc-settings&tab=checkout&section=stripe'));
63 63
 		$this->supports             = array(
64 64
 			'products',
65 65
 			'refunds',
@@ -71,25 +71,25 @@  discard block
 block discarded – undo
71 71
 		// Load the settings.
72 72
 		$this->init_settings();
73 73
 
74
-		$main_settings              = get_option( 'woocommerce_stripe_settings' );
75
-		$this->title                = $this->get_option( 'title' );
76
-		$this->description          = $this->get_option( 'description' );
77
-		$this->enabled              = $this->get_option( 'enabled' );
78
-		$this->testmode             = ( ! empty( $main_settings['testmode'] ) && 'yes' === $main_settings['testmode'] ) ? true : false;
79
-		$this->saved_cards          = ( ! empty( $main_settings['saved_cards'] ) && 'yes' === $main_settings['saved_cards'] ) ? true : false;
80
-		$this->publishable_key      = ! empty( $main_settings['publishable_key'] ) ? $main_settings['publishable_key'] : '';
81
-		$this->secret_key           = ! empty( $main_settings['secret_key'] ) ? $main_settings['secret_key'] : '';
82
-		$this->statement_descriptor = ! empty( $main_settings['statement_descriptor'] ) ? $main_settings['statement_descriptor'] : '';
83
-
84
-		if ( $this->testmode ) {
85
-			$this->publishable_key = ! empty( $main_settings['test_publishable_key'] ) ? $main_settings['test_publishable_key'] : '';
86
-			$this->secret_key      = ! empty( $main_settings['test_secret_key'] ) ? $main_settings['test_secret_key'] : '';
74
+		$main_settings              = get_option('woocommerce_stripe_settings');
75
+		$this->title                = $this->get_option('title');
76
+		$this->description          = $this->get_option('description');
77
+		$this->enabled              = $this->get_option('enabled');
78
+		$this->testmode             = ( ! empty($main_settings['testmode']) && 'yes' === $main_settings['testmode']) ? true : false;
79
+		$this->saved_cards          = ( ! empty($main_settings['saved_cards']) && 'yes' === $main_settings['saved_cards']) ? true : false;
80
+		$this->publishable_key      = ! empty($main_settings['publishable_key']) ? $main_settings['publishable_key'] : '';
81
+		$this->secret_key           = ! empty($main_settings['secret_key']) ? $main_settings['secret_key'] : '';
82
+		$this->statement_descriptor = ! empty($main_settings['statement_descriptor']) ? $main_settings['statement_descriptor'] : '';
83
+
84
+		if ($this->testmode) {
85
+			$this->publishable_key = ! empty($main_settings['test_publishable_key']) ? $main_settings['test_publishable_key'] : '';
86
+			$this->secret_key      = ! empty($main_settings['test_secret_key']) ? $main_settings['test_secret_key'] : '';
87 87
 		}
88 88
 
89
-		add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) );
90
-		add_action( 'admin_notices', array( $this, 'check_environment' ) );
91
-		add_action( 'admin_head', array( $this, 'remove_admin_notice' ) );
92
-		add_action( 'wp_enqueue_scripts', array( $this, 'payment_scripts' ) );
89
+		add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options'));
90
+		add_action('admin_notices', array($this, 'check_environment'));
91
+		add_action('admin_head', array($this, 'remove_admin_notice'));
92
+		add_action('wp_enqueue_scripts', array($this, 'payment_scripts'));
93 93
 	}
94 94
 
95 95
 	/**
@@ -99,19 +99,19 @@  discard block
 block discarded – undo
99 99
 	 * @version 4.0.0
100 100
 	 */
101 101
 	public function check_environment() {
102
-		if ( ! current_user_can( 'manage_woocommerce' ) ) {
102
+		if ( ! current_user_can('manage_woocommerce')) {
103 103
 			return;
104 104
 		}
105 105
 
106 106
 		$environment_warning = $this->get_environment_warning();
107 107
 
108
-		if ( $environment_warning ) {
109
-			$this->add_admin_notice( 'bad_environment', 'error', $environment_warning );
108
+		if ($environment_warning) {
109
+			$this->add_admin_notice('bad_environment', 'error', $environment_warning);
110 110
 		}
111 111
 
112
-		foreach ( (array) $this->notices as $notice_key => $notice ) {
113
-			echo "<div class='" . esc_attr( $notice['class'] ) . "'><p>";
114
-			echo wp_kses( $notice['message'], array( 'a' => array( 'href' => array() ) ) );
112
+		foreach ((array) $this->notices as $notice_key => $notice) {
113
+			echo "<div class='" . esc_attr($notice['class']) . "'><p>";
114
+			echo wp_kses($notice['message'], array('a' => array('href' => array())));
115 115
 			echo '</p></div>';
116 116
 		}
117 117
 	}
@@ -124,8 +124,8 @@  discard block
 block discarded – undo
124 124
 	 * @version 4.0.0
125 125
 	 */
126 126
 	public function get_environment_warning() {
127
-		if ( 'yes' === $this->enabled && ! in_array( get_woocommerce_currency(), $this->get_supported_currency() ) ) {
128
-			$message = __( 'iDeal is enabled - it requires store currency to be set to Euros.', 'woocommerce-gateway-stripe' );
127
+		if ('yes' === $this->enabled && ! in_array(get_woocommerce_currency(), $this->get_supported_currency())) {
128
+			$message = __('iDeal is enabled - it requires store currency to be set to Euros.', 'woocommerce-gateway-stripe');
129 129
 
130 130
 			return $message;
131 131
 		}
@@ -141,9 +141,9 @@  discard block
 block discarded – undo
141 141
 	 * @return array
142 142
 	 */
143 143
 	public function get_supported_currency() {
144
-		return apply_filters( 'wc_stripe_ideal_supported_currencies', array(
144
+		return apply_filters('wc_stripe_ideal_supported_currencies', array(
145 145
 			'EUR',
146
-		) );
146
+		));
147 147
 	}
148 148
 
149 149
 	/**
@@ -154,7 +154,7 @@  discard block
 block discarded – undo
154 154
 	 * @return bool
155 155
 	 */
156 156
 	public function is_available() {
157
-		if ( ! in_array( get_woocommerce_currency(), $this->get_supported_currency() ) ) {
157
+		if ( ! in_array(get_woocommerce_currency(), $this->get_supported_currency())) {
158 158
 			return false;
159 159
 		}
160 160
 
@@ -175,7 +175,7 @@  discard block
 block discarded – undo
175 175
 
176 176
 		$icons_str .= $icons['ideal'];
177 177
 
178
-		return apply_filters( 'woocommerce_gateway_icon', $icons_str, $this->id );
178
+		return apply_filters('woocommerce_gateway_icon', $icons_str, $this->id);
179 179
 	}
180 180
 
181 181
 	/**
@@ -186,19 +186,19 @@  discard block
 block discarded – undo
186 186
 	 * @access public
187 187
 	 */
188 188
 	public function payment_scripts() {
189
-		if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) && ! is_add_payment_method_page() ) {
189
+		if ( ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order']) && ! is_add_payment_method_page()) {
190 190
 			return;
191 191
 		}
192 192
 
193
-		wp_enqueue_style( 'stripe_paymentfonts' );
194
-		wp_enqueue_script( 'woocommerce_stripe' );
193
+		wp_enqueue_style('stripe_paymentfonts');
194
+		wp_enqueue_script('woocommerce_stripe');
195 195
 	}
196 196
 
197 197
 	/**
198 198
 	 * Initialize Gateway Settings Form Fields.
199 199
 	 */
200 200
 	public function init_form_fields() {
201
-		$this->form_fields = require( WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-ideal-settings.php' );
201
+		$this->form_fields = require(WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-ideal-settings.php');
202 202
 	}
203 203
 
204 204
 	/**
@@ -209,25 +209,25 @@  discard block
 block discarded – undo
209 209
 		$total                = WC()->cart->total;
210 210
 
211 211
 		// If paying from order, we need to get total from order not cart.
212
-		if ( isset( $_GET['pay_for_order'] ) && ! empty( $_GET['key'] ) ) {
213
-			$order = wc_get_order( wc_get_order_id_by_order_key( wc_clean( $_GET['key'] ) ) );
212
+		if (isset($_GET['pay_for_order']) && ! empty($_GET['key'])) {
213
+			$order = wc_get_order(wc_get_order_id_by_order_key(wc_clean($_GET['key'])));
214 214
 			$total = $order->get_total();
215 215
 		}
216 216
 
217
-		if ( is_add_payment_method_page() ) {
218
-			$pay_button_text = __( 'Add Payment', 'woocommerce-gateway-stripe' );
219
-			$total        = '';
217
+		if (is_add_payment_method_page()) {
218
+			$pay_button_text = __('Add Payment', 'woocommerce-gateway-stripe');
219
+			$total = '';
220 220
 		} else {
221 221
 			$pay_button_text = '';
222 222
 		}
223 223
 
224 224
 		echo '<div
225 225
 			id="stripe-ideal-payment-data"
226
-			data-amount="' . esc_attr( WC_Stripe_Helper::get_stripe_amount( $total ) ) . '"
227
-			data-currency="' . esc_attr( strtolower( get_woocommerce_currency() ) ) . '">';
226
+			data-amount="' . esc_attr(WC_Stripe_Helper::get_stripe_amount($total)) . '"
227
+			data-currency="' . esc_attr(strtolower(get_woocommerce_currency())) . '">';
228 228
 
229
-		if ( $this->description ) {
230
-			echo apply_filters( 'wc_stripe_description', wpautop( wp_kses_post( $this->description ) ) );
229
+		if ($this->description) {
230
+			echo apply_filters('wc_stripe_description', wpautop(wp_kses_post($this->description)));
231 231
 		}
232 232
 
233 233
 		echo '</div>';
@@ -241,24 +241,24 @@  discard block
 block discarded – undo
241 241
 	 * @param object $order
242 242
 	 * @return mixed
243 243
 	 */
244
-	public function create_source( $order ) {
244
+	public function create_source($order) {
245 245
 		$currency                          = WC_Stripe_Helper::is_pre_30() ? $order->get_order_currency() : $order->get_currency();
246 246
 		$order_id                          = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
247
-		$return_url                        = $this->get_stripe_return_url( $order );
247
+		$return_url                        = $this->get_stripe_return_url($order);
248 248
 		$post_data                         = array();
249
-		$post_data['amount']               = WC_Stripe_Helper::get_stripe_amount( $order->get_total(), $currency );
250
-		$post_data['currency']             = strtolower( $currency );
249
+		$post_data['amount']               = WC_Stripe_Helper::get_stripe_amount($order->get_total(), $currency);
250
+		$post_data['currency']             = strtolower($currency);
251 251
 		$post_data['type']                 = 'ideal';
252
-		$post_data['owner']                = $this->get_owner_details( $order );
253
-		$post_data['redirect']             = array( 'return_url' => $return_url );
252
+		$post_data['owner']                = $this->get_owner_details($order);
253
+		$post_data['redirect']             = array('return_url' => $return_url);
254 254
 
255
-		if ( ! empty( $this->statement_descriptor ) ) {
256
-			$post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor( $this->statement_descriptor );
255
+		if ( ! empty($this->statement_descriptor)) {
256
+			$post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor($this->statement_descriptor);
257 257
 		}
258 258
 
259
-		WC_Stripe_Logger::log( 'Info: Begin creating iDeal source' );
259
+		WC_Stripe_Logger::log('Info: Begin creating iDeal source');
260 260
 
261
-		return WC_Stripe_API::request( $post_data, 'sources' );
261
+		return WC_Stripe_API::request($post_data, 'sources');
262 262
 	}
263 263
 
264 264
 	/**
@@ -272,51 +272,51 @@  discard block
 block discarded – undo
272 272
 	 *
273 273
 	 * @return array|void
274 274
 	 */
275
-	public function process_payment( $order_id, $retry = true, $force_save_source = false ) {
275
+	public function process_payment($order_id, $retry = true, $force_save_source = false) {
276 276
 		try {
277
-			$order = wc_get_order( $order_id );
277
+			$order = wc_get_order($order_id);
278 278
 
279 279
 			// This will throw exception if not valid.
280
-			$this->validate_minimum_order_amount( $order );
280
+			$this->validate_minimum_order_amount($order);
281 281
 
282 282
 			// This comes from the create account checkbox in the checkout page.
283
-			$create_account = ! empty( $_POST['createaccount'] ) ? true : false;
283
+			$create_account = ! empty($_POST['createaccount']) ? true : false;
284 284
 
285
-			if ( $create_account ) {
285
+			if ($create_account) {
286 286
 				$new_customer_id     = WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id();
287
-				$new_stripe_customer = new WC_Stripe_Customer( $new_customer_id );
287
+				$new_stripe_customer = new WC_Stripe_Customer($new_customer_id);
288 288
 				$new_stripe_customer->create_customer();
289 289
 			}
290 290
 
291
-			$response = $this->create_source( $order );
291
+			$response = $this->create_source($order);
292 292
 
293
-			if ( ! empty( $response->error ) ) {
294
-				$order->add_order_note( $response->error->message );
293
+			if ( ! empty($response->error)) {
294
+				$order->add_order_note($response->error->message);
295 295
 
296
-				throw new Exception( $response->error->message );
296
+				throw new Exception($response->error->message);
297 297
 			}
298 298
 
299
-			if ( WC_Stripe_Helper::is_pre_30() ) {
300
-				update_post_meta( $order_id, '_stripe_source_id', $response->id );
299
+			if (WC_Stripe_Helper::is_pre_30()) {
300
+				update_post_meta($order_id, '_stripe_source_id', $response->id);
301 301
 			} else {
302
-				$order->update_meta_data( '_stripe_source_id', $response->id );
302
+				$order->update_meta_data('_stripe_source_id', $response->id);
303 303
 				$order->save();
304 304
 			}
305 305
 
306
-			WC_Stripe_Logger::log( 'Info: Redirecting to iDeal...' );
306
+			WC_Stripe_Logger::log('Info: Redirecting to iDeal...');
307 307
 
308 308
 			return array(
309 309
 				'result'   => 'success',
310
-				'redirect' => esc_url_raw( $response->redirect->url ),
310
+				'redirect' => esc_url_raw($response->redirect->url),
311 311
 			);
312
-		} catch ( Exception $e ) {
313
-			wc_add_notice( $e->getMessage(), 'error' );
314
-			WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() );
312
+		} catch (Exception $e) {
313
+			wc_add_notice($e->getMessage(), 'error');
314
+			WC_Stripe_Logger::log('Error: ' . $e->getMessage());
315 315
 
316
-			do_action( 'wc_gateway_stripe_process_payment_error', $e, $order );
316
+			do_action('wc_gateway_stripe_process_payment_error', $e, $order);
317 317
 
318
-			if ( $order->has_status( array( 'pending', 'failed' ) ) ) {
319
-				$this->send_failed_order_email( $order_id );
318
+			if ($order->has_status(array('pending', 'failed'))) {
319
+				$this->send_failed_order_email($order_id);
320 320
 			}
321 321
 
322 322
 			return array(
Please login to merge, or discard this patch.
includes/payment-methods/class-wc-gateway-stripe-sofort.php 1 patch
Spacing   +85 added lines, -85 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) {
2
+if ( ! defined('ABSPATH')) {
3 3
 	exit;
4 4
 }
5 5
 
@@ -57,9 +57,9 @@  discard block
 block discarded – undo
57 57
 	 */
58 58
 	public function __construct() {
59 59
 		$this->id                   = 'stripe_sofort';
60
-		$this->method_title         = __( 'Stripe SOFORT', 'woocommerce-gateway-stripe' );
60
+		$this->method_title         = __('Stripe SOFORT', 'woocommerce-gateway-stripe');
61 61
 		/* translators: link */
62
-		$this->method_description   = sprintf( __( 'All other general Stripe settings can be adjusted <a href="%s">here</a>.', 'woocommerce-gateway-stripe' ), admin_url( 'admin.php?page=wc-settings&tab=checkout&section=stripe' ) );
62
+		$this->method_description   = sprintf(__('All other general Stripe settings can be adjusted <a href="%s">here</a>.', 'woocommerce-gateway-stripe'), admin_url('admin.php?page=wc-settings&tab=checkout&section=stripe'));
63 63
 		$this->supports             = array(
64 64
 			'products',
65 65
 			'refunds',
@@ -71,25 +71,25 @@  discard block
 block discarded – undo
71 71
 		// Load the settings.
72 72
 		$this->init_settings();
73 73
 
74
-		$main_settings              = get_option( 'woocommerce_stripe_settings' );
75
-		$this->title                = $this->get_option( 'title' );
76
-		$this->description          = $this->get_option( 'description' );
77
-		$this->enabled              = $this->get_option( 'enabled' );
78
-		$this->testmode             = ( ! empty( $main_settings['testmode'] ) && 'yes' === $main_settings['testmode'] ) ? true : false;
79
-		$this->saved_cards          = ( ! empty( $main_settings['saved_cards'] ) && 'yes' === $main_settings['saved_cards'] ) ? true : false;
80
-		$this->publishable_key      = ! empty( $main_settings['publishable_key'] ) ? $main_settings['publishable_key'] : '';
81
-		$this->secret_key           = ! empty( $main_settings['secret_key'] ) ? $main_settings['secret_key'] : '';
82
-		$this->statement_descriptor = ! empty( $main_settings['statement_descriptor'] ) ? $main_settings['statement_descriptor'] : '';
83
-
84
-		if ( $this->testmode ) {
85
-			$this->publishable_key = ! empty( $main_settings['test_publishable_key'] ) ? $main_settings['test_publishable_key'] : '';
86
-			$this->secret_key      = ! empty( $main_settings['test_secret_key'] ) ? $main_settings['test_secret_key'] : '';
74
+		$main_settings              = get_option('woocommerce_stripe_settings');
75
+		$this->title                = $this->get_option('title');
76
+		$this->description          = $this->get_option('description');
77
+		$this->enabled              = $this->get_option('enabled');
78
+		$this->testmode             = ( ! empty($main_settings['testmode']) && 'yes' === $main_settings['testmode']) ? true : false;
79
+		$this->saved_cards          = ( ! empty($main_settings['saved_cards']) && 'yes' === $main_settings['saved_cards']) ? true : false;
80
+		$this->publishable_key      = ! empty($main_settings['publishable_key']) ? $main_settings['publishable_key'] : '';
81
+		$this->secret_key           = ! empty($main_settings['secret_key']) ? $main_settings['secret_key'] : '';
82
+		$this->statement_descriptor = ! empty($main_settings['statement_descriptor']) ? $main_settings['statement_descriptor'] : '';
83
+
84
+		if ($this->testmode) {
85
+			$this->publishable_key = ! empty($main_settings['test_publishable_key']) ? $main_settings['test_publishable_key'] : '';
86
+			$this->secret_key      = ! empty($main_settings['test_secret_key']) ? $main_settings['test_secret_key'] : '';
87 87
 		}
88 88
 
89
-		add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) );
90
-		add_action( 'admin_notices', array( $this, 'check_environment' ) );
91
-		add_action( 'admin_head', array( $this, 'remove_admin_notice' ) );
92
-		add_action( 'wp_enqueue_scripts', array( $this, 'payment_scripts' ) );
89
+		add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options'));
90
+		add_action('admin_notices', array($this, 'check_environment'));
91
+		add_action('admin_head', array($this, 'remove_admin_notice'));
92
+		add_action('wp_enqueue_scripts', array($this, 'payment_scripts'));
93 93
 	}
94 94
 
95 95
 	/**
@@ -99,19 +99,19 @@  discard block
 block discarded – undo
99 99
 	 * @version 4.0.0
100 100
 	 */
101 101
 	public function check_environment() {
102
-		if ( ! current_user_can( 'manage_woocommerce' ) ) {
102
+		if ( ! current_user_can('manage_woocommerce')) {
103 103
 			return;
104 104
 		}
105 105
 
106 106
 		$environment_warning = $this->get_environment_warning();
107 107
 
108
-		if ( $environment_warning ) {
109
-			$this->add_admin_notice( 'bad_environment', 'error', $environment_warning );
108
+		if ($environment_warning) {
109
+			$this->add_admin_notice('bad_environment', 'error', $environment_warning);
110 110
 		}
111 111
 
112
-		foreach ( (array) $this->notices as $notice_key => $notice ) {
113
-			echo "<div class='" . esc_attr( $notice['class'] ) . "'><p>";
114
-			echo wp_kses( $notice['message'], array( 'a' => array( 'href' => array() ) ) );
112
+		foreach ((array) $this->notices as $notice_key => $notice) {
113
+			echo "<div class='" . esc_attr($notice['class']) . "'><p>";
114
+			echo wp_kses($notice['message'], array('a' => array('href' => array())));
115 115
 			echo '</p></div>';
116 116
 		}
117 117
 	}
@@ -124,8 +124,8 @@  discard block
 block discarded – undo
124 124
 	 * @version 4.0.0
125 125
 	 */
126 126
 	public function get_environment_warning() {
127
-		if ( 'yes' === $this->enabled && ! in_array( get_woocommerce_currency(), $this->get_supported_currency() ) ) {
128
-			$message = __( 'SOFORT is enabled - it requires store currency to be set to Euros.', 'woocommerce-gateway-stripe' );
127
+		if ('yes' === $this->enabled && ! in_array(get_woocommerce_currency(), $this->get_supported_currency())) {
128
+			$message = __('SOFORT is enabled - it requires store currency to be set to Euros.', 'woocommerce-gateway-stripe');
129 129
 
130 130
 			return $message;
131 131
 		}
@@ -141,9 +141,9 @@  discard block
 block discarded – undo
141 141
 	 * @return array
142 142
 	 */
143 143
 	public function get_supported_currency() {
144
-		return apply_filters( 'wc_stripe_sofort_supported_currencies', array(
144
+		return apply_filters('wc_stripe_sofort_supported_currencies', array(
145 145
 			'EUR',
146
-		) );
146
+		));
147 147
 	}
148 148
 
149 149
 	/**
@@ -154,7 +154,7 @@  discard block
 block discarded – undo
154 154
 	 * @return bool
155 155
 	 */
156 156
 	public function is_available() {
157
-		if ( ! in_array( get_woocommerce_currency(), $this->get_supported_currency() ) ) {
157
+		if ( ! in_array(get_woocommerce_currency(), $this->get_supported_currency())) {
158 158
 			return false;
159 159
 		}
160 160
 
@@ -175,7 +175,7 @@  discard block
 block discarded – undo
175 175
 
176 176
 		$icons_str .= $icons['sofort'];
177 177
 
178
-		return apply_filters( 'woocommerce_gateway_icon', $icons_str, $this->id );
178
+		return apply_filters('woocommerce_gateway_icon', $icons_str, $this->id);
179 179
 	}
180 180
 
181 181
 	/**
@@ -186,19 +186,19 @@  discard block
 block discarded – undo
186 186
 	 * @access public
187 187
 	 */
188 188
 	public function payment_scripts() {
189
-		if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) && ! is_add_payment_method_page() ) {
189
+		if ( ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order']) && ! is_add_payment_method_page()) {
190 190
 			return;
191 191
 		}
192 192
 
193
-		wp_enqueue_style( 'stripe_paymentfonts' );
194
-		wp_enqueue_script( 'woocommerce_stripe' );
193
+		wp_enqueue_style('stripe_paymentfonts');
194
+		wp_enqueue_script('woocommerce_stripe');
195 195
 	}
196 196
 
197 197
 	/**
198 198
 	 * Initialize Gateway Settings Form Fields.
199 199
 	 */
200 200
 	public function init_form_fields() {
201
-		$this->form_fields = require( WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-sofort-settings.php' );
201
+		$this->form_fields = require(WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-sofort-settings.php');
202 202
 	}
203 203
 
204 204
 	/**
@@ -217,24 +217,24 @@  discard block
 block discarded – undo
217 217
 			'IT' => 'Italy',
218 218
 		);
219 219
 		?>
220
-		<fieldset id="wc-<?php echo esc_attr( $this->id ); ?>-form" class="wc-payment-form">
221
-			<?php do_action( 'woocommerce_credit_card_form_start', $this->id ); ?>
220
+		<fieldset id="wc-<?php echo esc_attr($this->id); ?>-form" class="wc-payment-form">
221
+			<?php do_action('woocommerce_credit_card_form_start', $this->id); ?>
222 222
 			<label for="stripe-bank-country">
223
-				<?php _e( 'Country origin of your bank.', 'woocommerce-gateway-stripe' ); ?>
223
+				<?php _e('Country origin of your bank.', 'woocommerce-gateway-stripe'); ?>
224 224
 			</label>
225 225
 			<br />
226 226
 			<p class="form-row form-row-wide validate-required">
227 227
 			<select id="stripe-bank-country" class="wc-enhanced-select" name="stripe_sofort_bank_country">
228
-				<option value="-1"><?php esc_html_e( 'Choose Bank Country', 'woocommerce-gateway-stripe' ); ?></option>
229
-				<?php foreach ( $supported_countries as $code => $country ) { ?>
230
-				<option value="<?php echo esc_attr( $code ); ?>"><?php echo esc_html( $country ); ?></option>
228
+				<option value="-1"><?php esc_html_e('Choose Bank Country', 'woocommerce-gateway-stripe'); ?></option>
229
+				<?php foreach ($supported_countries as $code => $country) { ?>
230
+				<option value="<?php echo esc_attr($code); ?>"><?php echo esc_html($country); ?></option>
231 231
 				<?php } ?>
232 232
 			</select>
233 233
 			</p>
234 234
 
235 235
 			<!-- Used to display form errors -->
236 236
 			<div class="stripe-source-errors" role="alert"></div>
237
-			<?php do_action( 'woocommerce_credit_card_form_end', $this->id ); ?>
237
+			<?php do_action('woocommerce_credit_card_form_end', $this->id); ?>
238 238
 			<div class="clear"></div>
239 239
 		</fieldset>
240 240
 		<?php
@@ -248,25 +248,25 @@  discard block
 block discarded – undo
248 248
 		$total                = WC()->cart->total;
249 249
 
250 250
 		// If paying from order, we need to get total from order not cart.
251
-		if ( isset( $_GET['pay_for_order'] ) && ! empty( $_GET['key'] ) ) {
252
-			$order = wc_get_order( wc_get_order_id_by_order_key( wc_clean( $_GET['key'] ) ) );
251
+		if (isset($_GET['pay_for_order']) && ! empty($_GET['key'])) {
252
+			$order = wc_get_order(wc_get_order_id_by_order_key(wc_clean($_GET['key'])));
253 253
 			$total = $order->get_total();
254 254
 		}
255 255
 
256
-		if ( is_add_payment_method_page() ) {
257
-			$pay_button_text = __( 'Add Payment', 'woocommerce-gateway-stripe' );
258
-			$total        = '';
256
+		if (is_add_payment_method_page()) {
257
+			$pay_button_text = __('Add Payment', 'woocommerce-gateway-stripe');
258
+			$total = '';
259 259
 		} else {
260 260
 			$pay_button_text = '';
261 261
 		}
262 262
 
263 263
 		echo '<div
264 264
 			id="stripe-sofort-payment-data"
265
-			data-amount="' . esc_attr( WC_Stripe_Helper::get_stripe_amount( $total ) ) . '"
266
-			data-currency="' . esc_attr( strtolower( get_woocommerce_currency() ) ) . '">';
265
+			data-amount="' . esc_attr(WC_Stripe_Helper::get_stripe_amount($total)) . '"
266
+			data-currency="' . esc_attr(strtolower(get_woocommerce_currency())) . '">';
267 267
 
268
-		if ( $this->description ) {
269
-			echo apply_filters( 'wc_stripe_description', wpautop( wp_kses_post( $this->description ) ) );
268
+		if ($this->description) {
269
+			echo apply_filters('wc_stripe_description', wpautop(wp_kses_post($this->description)));
270 270
 		}
271 271
 
272 272
 		$this->form();
@@ -282,26 +282,26 @@  discard block
 block discarded – undo
282 282
 	 * @param object $order
283 283
 	 * @return mixed
284 284
 	 */
285
-	public function create_source( $order ) {
285
+	public function create_source($order) {
286 286
 		$currency                          = WC_Stripe_Helper::is_pre_30() ? $order->get_order_currency() : $order->get_currency();
287 287
 		$order_id                          = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
288
-		$bank_country                      = wc_clean( $_POST['stripe_sofort_bank_country'] );
289
-		$return_url                        = $this->get_stripe_return_url( $order );
288
+		$bank_country                      = wc_clean($_POST['stripe_sofort_bank_country']);
289
+		$return_url                        = $this->get_stripe_return_url($order);
290 290
 		$post_data                         = array();
291
-		$post_data['amount']               = WC_Stripe_Helper::get_stripe_amount( $order->get_total(), $currency );
292
-		$post_data['currency']             = strtolower( $currency );
291
+		$post_data['amount']               = WC_Stripe_Helper::get_stripe_amount($order->get_total(), $currency);
292
+		$post_data['currency']             = strtolower($currency);
293 293
 		$post_data['type']                 = 'sofort';
294
-		$post_data['owner']                = $this->get_owner_details( $order );
295
-		$post_data['redirect']             = array( 'return_url' => $return_url );
296
-		$post_data['sofort']               = array( 'country' => $bank_country );
294
+		$post_data['owner']                = $this->get_owner_details($order);
295
+		$post_data['redirect']             = array('return_url' => $return_url);
296
+		$post_data['sofort']               = array('country' => $bank_country);
297 297
 
298
-		if ( ! empty( $this->statement_descriptor ) ) {
299
-			$post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor( $this->statement_descriptor );
298
+		if ( ! empty($this->statement_descriptor)) {
299
+			$post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor($this->statement_descriptor);
300 300
 		}
301 301
 
302
-		WC_Stripe_Logger::log( 'Info: Begin creating SOFORT source' );
302
+		WC_Stripe_Logger::log('Info: Begin creating SOFORT source');
303 303
 
304
-		return WC_Stripe_API::request( $post_data, 'sources' );
304
+		return WC_Stripe_API::request($post_data, 'sources');
305 305
 	}
306 306
 
307 307
 	/**
@@ -315,51 +315,51 @@  discard block
 block discarded – undo
315 315
 	 *
316 316
 	 * @return array|void
317 317
 	 */
318
-	public function process_payment( $order_id, $retry = true, $force_save_source = false ) {
318
+	public function process_payment($order_id, $retry = true, $force_save_source = false) {
319 319
 		try {
320
-			$order = wc_get_order( $order_id );
320
+			$order = wc_get_order($order_id);
321 321
 
322 322
 			// This will throw exception if not valid.
323
-			$this->validate_minimum_order_amount( $order );
323
+			$this->validate_minimum_order_amount($order);
324 324
 
325 325
 			// This comes from the create account checkbox in the checkout page.
326
-			$create_account = ! empty( $_POST['createaccount'] ) ? true : false;
326
+			$create_account = ! empty($_POST['createaccount']) ? true : false;
327 327
 
328
-			if ( $create_account ) {
328
+			if ($create_account) {
329 329
 				$new_customer_id     = WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id();
330
-				$new_stripe_customer = new WC_Stripe_Customer( $new_customer_id );
330
+				$new_stripe_customer = new WC_Stripe_Customer($new_customer_id);
331 331
 				$new_stripe_customer->create_customer();
332 332
 			}
333 333
 
334
-			$response = $this->create_source( $order );
334
+			$response = $this->create_source($order);
335 335
 
336
-			if ( ! empty( $response->error ) ) {
337
-				$order->add_order_note( $response->error->message );
336
+			if ( ! empty($response->error)) {
337
+				$order->add_order_note($response->error->message);
338 338
 
339
-				throw new Exception( $response->error->message );
339
+				throw new Exception($response->error->message);
340 340
 			}
341 341
 
342
-			if ( WC_Stripe_Helper::is_pre_30() ) {
343
-				update_post_meta( $order_id, '_stripe_source_id', $response->id );
342
+			if (WC_Stripe_Helper::is_pre_30()) {
343
+				update_post_meta($order_id, '_stripe_source_id', $response->id);
344 344
 			} else {
345
-				$order->update_meta_data( '_stripe_source_id', $response->id );
345
+				$order->update_meta_data('_stripe_source_id', $response->id);
346 346
 				$order->save();
347 347
 			}
348 348
 
349
-			WC_Stripe_Logger::log( 'Info: Redirecting to SOFORT...' );
349
+			WC_Stripe_Logger::log('Info: Redirecting to SOFORT...');
350 350
 
351 351
 			return array(
352 352
 				'result'   => 'success',
353
-				'redirect' => esc_url_raw( $response->redirect->url ),
353
+				'redirect' => esc_url_raw($response->redirect->url),
354 354
 			);
355
-		} catch ( Exception $e ) {
356
-			wc_add_notice( $e->getMessage(), 'error' );
357
-			WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() );
355
+		} catch (Exception $e) {
356
+			wc_add_notice($e->getMessage(), 'error');
357
+			WC_Stripe_Logger::log('Error: ' . $e->getMessage());
358 358
 
359
-			do_action( 'wc_gateway_stripe_process_payment_error', $e, $order );
359
+			do_action('wc_gateway_stripe_process_payment_error', $e, $order);
360 360
 
361
-			if ( $order->has_status( array( 'pending', 'failed' ) ) ) {
362
-				$this->send_failed_order_email( $order_id );
361
+			if ($order->has_status(array('pending', 'failed'))) {
362
+				$this->send_failed_order_email($order_id);
363 363
 			}
364 364
 
365 365
 			return array(
Please login to merge, or discard this patch.
includes/payment-methods/class-wc-gateway-stripe-giropay.php 1 patch
Spacing   +76 added lines, -76 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) {
2
+if ( ! defined('ABSPATH')) {
3 3
 	exit;
4 4
 }
5 5
 
@@ -57,9 +57,9 @@  discard block
 block discarded – undo
57 57
 	 */
58 58
 	public function __construct() {
59 59
 		$this->id                   = 'stripe_giropay';
60
-		$this->method_title         = __( 'Stripe Giropay', 'woocommerce-gateway-stripe' );
60
+		$this->method_title         = __('Stripe Giropay', 'woocommerce-gateway-stripe');
61 61
 		/* translators: link */
62
-		$this->method_description   = sprintf( __( 'All other general Stripe settings can be adjusted <a href="%s">here</a>.', 'woocommerce-gateway-stripe' ), admin_url( 'admin.php?page=wc-settings&tab=checkout&section=stripe' ) );
62
+		$this->method_description   = sprintf(__('All other general Stripe settings can be adjusted <a href="%s">here</a>.', 'woocommerce-gateway-stripe'), admin_url('admin.php?page=wc-settings&tab=checkout&section=stripe'));
63 63
 		$this->supports             = array(
64 64
 			'products',
65 65
 			'refunds',
@@ -71,25 +71,25 @@  discard block
 block discarded – undo
71 71
 		// Load the settings.
72 72
 		$this->init_settings();
73 73
 
74
-		$main_settings              = get_option( 'woocommerce_stripe_settings' );
75
-		$this->title                = $this->get_option( 'title' );
76
-		$this->description          = $this->get_option( 'description' );
77
-		$this->enabled              = $this->get_option( 'enabled' );
78
-		$this->testmode             = ( ! empty( $main_settings['testmode'] ) && 'yes' === $main_settings['testmode'] ) ? true : false;
79
-		$this->saved_cards          = ( ! empty( $main_settings['saved_cards'] ) && 'yes' === $main_settings['saved_cards'] ) ? true : false;
80
-		$this->publishable_key      = ! empty( $main_settings['publishable_key'] ) ? $main_settings['publishable_key'] : '';
81
-		$this->secret_key           = ! empty( $main_settings['secret_key'] ) ? $main_settings['secret_key'] : '';
82
-		$this->statement_descriptor = ! empty( $main_settings['statement_descriptor'] ) ? $main_settings['statement_descriptor'] : '';
83
-
84
-		if ( $this->testmode ) {
85
-			$this->publishable_key = ! empty( $main_settings['test_publishable_key'] ) ? $main_settings['test_publishable_key'] : '';
86
-			$this->secret_key      = ! empty( $main_settings['test_secret_key'] ) ? $main_settings['test_secret_key'] : '';
74
+		$main_settings              = get_option('woocommerce_stripe_settings');
75
+		$this->title                = $this->get_option('title');
76
+		$this->description          = $this->get_option('description');
77
+		$this->enabled              = $this->get_option('enabled');
78
+		$this->testmode             = ( ! empty($main_settings['testmode']) && 'yes' === $main_settings['testmode']) ? true : false;
79
+		$this->saved_cards          = ( ! empty($main_settings['saved_cards']) && 'yes' === $main_settings['saved_cards']) ? true : false;
80
+		$this->publishable_key      = ! empty($main_settings['publishable_key']) ? $main_settings['publishable_key'] : '';
81
+		$this->secret_key           = ! empty($main_settings['secret_key']) ? $main_settings['secret_key'] : '';
82
+		$this->statement_descriptor = ! empty($main_settings['statement_descriptor']) ? $main_settings['statement_descriptor'] : '';
83
+
84
+		if ($this->testmode) {
85
+			$this->publishable_key = ! empty($main_settings['test_publishable_key']) ? $main_settings['test_publishable_key'] : '';
86
+			$this->secret_key      = ! empty($main_settings['test_secret_key']) ? $main_settings['test_secret_key'] : '';
87 87
 		}
88 88
 
89
-		add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) );
90
-		add_action( 'admin_notices', array( $this, 'check_environment' ) );
91
-		add_action( 'admin_head', array( $this, 'remove_admin_notice' ) );
92
-		add_action( 'wp_enqueue_scripts', array( $this, 'payment_scripts' ) );
89
+		add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options'));
90
+		add_action('admin_notices', array($this, 'check_environment'));
91
+		add_action('admin_head', array($this, 'remove_admin_notice'));
92
+		add_action('wp_enqueue_scripts', array($this, 'payment_scripts'));
93 93
 	}
94 94
 
95 95
 	/**
@@ -99,19 +99,19 @@  discard block
 block discarded – undo
99 99
 	 * @version 4.0.0
100 100
 	 */
101 101
 	public function check_environment() {
102
-		if ( ! current_user_can( 'manage_woocommerce' ) ) {
102
+		if ( ! current_user_can('manage_woocommerce')) {
103 103
 			return;
104 104
 		}
105 105
 
106 106
 		$environment_warning = $this->get_environment_warning();
107 107
 
108
-		if ( $environment_warning ) {
109
-			$this->add_admin_notice( 'bad_environment', 'error', $environment_warning );
108
+		if ($environment_warning) {
109
+			$this->add_admin_notice('bad_environment', 'error', $environment_warning);
110 110
 		}
111 111
 
112
-		foreach ( (array) $this->notices as $notice_key => $notice ) {
113
-			echo "<div class='" . esc_attr( $notice['class'] ) . "'><p>";
114
-			echo wp_kses( $notice['message'], array( 'a' => array( 'href' => array() ) ) );
112
+		foreach ((array) $this->notices as $notice_key => $notice) {
113
+			echo "<div class='" . esc_attr($notice['class']) . "'><p>";
114
+			echo wp_kses($notice['message'], array('a' => array('href' => array())));
115 115
 			echo '</p></div>';
116 116
 		}
117 117
 	}
@@ -124,8 +124,8 @@  discard block
 block discarded – undo
124 124
 	 * @version 4.0.0
125 125
 	 */
126 126
 	public function get_environment_warning() {
127
-		if ( 'yes' === $this->enabled && ! in_array( get_woocommerce_currency(), $this->get_supported_currency() ) ) {
128
-			$message = __( 'Giropay is enabled - it requires store currency to be set to Euros.', 'woocommerce-gateway-stripe' );
127
+		if ('yes' === $this->enabled && ! in_array(get_woocommerce_currency(), $this->get_supported_currency())) {
128
+			$message = __('Giropay is enabled - it requires store currency to be set to Euros.', 'woocommerce-gateway-stripe');
129 129
 
130 130
 			return $message;
131 131
 		}
@@ -141,9 +141,9 @@  discard block
 block discarded – undo
141 141
 	 * @return array
142 142
 	 */
143 143
 	public function get_supported_currency() {
144
-		return apply_filters( 'wc_stripe_giropay_supported_currencies', array(
144
+		return apply_filters('wc_stripe_giropay_supported_currencies', array(
145 145
 			'EUR',
146
-		) );
146
+		));
147 147
 	}
148 148
 
149 149
 	/**
@@ -154,7 +154,7 @@  discard block
 block discarded – undo
154 154
 	 * @return bool
155 155
 	 */
156 156
 	public function is_available() {
157
-		if ( ! in_array( get_woocommerce_currency(), $this->get_supported_currency() ) ) {
157
+		if ( ! in_array(get_woocommerce_currency(), $this->get_supported_currency())) {
158 158
 			return false;
159 159
 		}
160 160
 
@@ -175,7 +175,7 @@  discard block
 block discarded – undo
175 175
 
176 176
 		$icons_str .= $icons['giropay'];
177 177
 
178
-		return apply_filters( 'woocommerce_gateway_icon', $icons_str, $this->id );
178
+		return apply_filters('woocommerce_gateway_icon', $icons_str, $this->id);
179 179
 	}
180 180
 
181 181
 	/**
@@ -186,19 +186,19 @@  discard block
 block discarded – undo
186 186
 	 * @access public
187 187
 	 */
188 188
 	public function payment_scripts() {
189
-		if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) && ! is_add_payment_method_page() ) {
189
+		if ( ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order']) && ! is_add_payment_method_page()) {
190 190
 			return;
191 191
 		}
192 192
 
193
-		wp_enqueue_style( 'stripe_paymentfonts' );
194
-		wp_enqueue_script( 'woocommerce_stripe' );
193
+		wp_enqueue_style('stripe_paymentfonts');
194
+		wp_enqueue_script('woocommerce_stripe');
195 195
 	}
196 196
 
197 197
 	/**
198 198
 	 * Initialize Gateway Settings Form Fields.
199 199
 	 */
200 200
 	public function init_form_fields() {
201
-		$this->form_fields = require( WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-giropay-settings.php' );
201
+		$this->form_fields = require(WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-giropay-settings.php');
202 202
 	}
203 203
 
204 204
 	/**
@@ -209,25 +209,25 @@  discard block
 block discarded – undo
209 209
 		$total                = WC()->cart->total;
210 210
 
211 211
 		// If paying from order, we need to get total from order not cart.
212
-		if ( isset( $_GET['pay_for_order'] ) && ! empty( $_GET['key'] ) ) {
213
-			$order = wc_get_order( wc_get_order_id_by_order_key( wc_clean( $_GET['key'] ) ) );
212
+		if (isset($_GET['pay_for_order']) && ! empty($_GET['key'])) {
213
+			$order = wc_get_order(wc_get_order_id_by_order_key(wc_clean($_GET['key'])));
214 214
 			$total = $order->get_total();
215 215
 		}
216 216
 
217
-		if ( is_add_payment_method_page() ) {
218
-			$pay_button_text = __( 'Add Payment', 'woocommerce-gateway-stripe' );
219
-			$total        = '';
217
+		if (is_add_payment_method_page()) {
218
+			$pay_button_text = __('Add Payment', 'woocommerce-gateway-stripe');
219
+			$total = '';
220 220
 		} else {
221 221
 			$pay_button_text = '';
222 222
 		}
223 223
 
224 224
 		echo '<div
225 225
 			id="stripe-giropay-payment-data"
226
-			data-amount="' . esc_attr( WC_Stripe_Helper::get_stripe_amount( $total ) ) . '"
227
-			data-currency="' . esc_attr( strtolower( get_woocommerce_currency() ) ) . '">';
226
+			data-amount="' . esc_attr(WC_Stripe_Helper::get_stripe_amount($total)) . '"
227
+			data-currency="' . esc_attr(strtolower(get_woocommerce_currency())) . '">';
228 228
 
229
-		if ( $this->description ) {
230
-			echo apply_filters( 'wc_stripe_description', wpautop( wp_kses_post( $this->description ) ) );
229
+		if ($this->description) {
230
+			echo apply_filters('wc_stripe_description', wpautop(wp_kses_post($this->description)));
231 231
 		}
232 232
 
233 233
 		echo '</div>';
@@ -241,24 +241,24 @@  discard block
 block discarded – undo
241 241
 	 * @param object $order
242 242
 	 * @return mixed
243 243
 	 */
244
-	public function create_source( $order ) {
244
+	public function create_source($order) {
245 245
 		$currency                          = WC_Stripe_Helper::is_pre_30() ? $order->get_order_currency() : $order->get_currency();
246 246
 		$order_id                          = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
247
-		$return_url                        = $this->get_stripe_return_url( $order );
247
+		$return_url                        = $this->get_stripe_return_url($order);
248 248
 		$post_data                         = array();
249
-		$post_data['amount']               = WC_Stripe_Helper::get_stripe_amount( $order->get_total(), $currency );
250
-		$post_data['currency']             = strtolower( $currency );
249
+		$post_data['amount']               = WC_Stripe_Helper::get_stripe_amount($order->get_total(), $currency);
250
+		$post_data['currency']             = strtolower($currency);
251 251
 		$post_data['type']                 = 'giropay';
252
-		$post_data['owner']                = $this->get_owner_details( $order );
253
-		$post_data['redirect']             = array( 'return_url' => $return_url );
252
+		$post_data['owner']                = $this->get_owner_details($order);
253
+		$post_data['redirect']             = array('return_url' => $return_url);
254 254
 
255
-		if ( ! empty( $this->statement_descriptor ) ) {
256
-			$post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor( $this->statement_descriptor );
255
+		if ( ! empty($this->statement_descriptor)) {
256
+			$post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor($this->statement_descriptor);
257 257
 		}
258 258
 
259
-		WC_Stripe_Logger::log( 'Info: Begin creating Giropay source' );
259
+		WC_Stripe_Logger::log('Info: Begin creating Giropay source');
260 260
 
261
-		return WC_Stripe_API::request( $post_data, 'sources' );
261
+		return WC_Stripe_API::request($post_data, 'sources');
262 262
 	}
263 263
 
264 264
 	/**
@@ -272,51 +272,51 @@  discard block
 block discarded – undo
272 272
 	 *
273 273
 	 * @return array|void
274 274
 	 */
275
-	public function process_payment( $order_id, $retry = true, $force_save_source = false ) {
275
+	public function process_payment($order_id, $retry = true, $force_save_source = false) {
276 276
 		try {
277
-			$order = wc_get_order( $order_id );
277
+			$order = wc_get_order($order_id);
278 278
 
279 279
 			// This will throw exception if not valid.
280
-			$this->validate_minimum_order_amount( $order );
280
+			$this->validate_minimum_order_amount($order);
281 281
 
282 282
 			// This comes from the create account checkbox in the checkout page.
283
-			$create_account = ! empty( $_POST['createaccount'] ) ? true : false;
283
+			$create_account = ! empty($_POST['createaccount']) ? true : false;
284 284
 
285
-			if ( $create_account ) {
285
+			if ($create_account) {
286 286
 				$new_customer_id     = WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id();
287
-				$new_stripe_customer = new WC_Stripe_Customer( $new_customer_id );
287
+				$new_stripe_customer = new WC_Stripe_Customer($new_customer_id);
288 288
 				$new_stripe_customer->create_customer();
289 289
 			}
290 290
 
291
-			$response = $this->create_source( $order );
291
+			$response = $this->create_source($order);
292 292
 
293
-			if ( ! empty( $response->error ) ) {
294
-				$order->add_order_note( $response->error->message );
293
+			if ( ! empty($response->error)) {
294
+				$order->add_order_note($response->error->message);
295 295
 
296
-				throw new Exception( $response->error->message );
296
+				throw new Exception($response->error->message);
297 297
 			}
298 298
 
299
-			if ( WC_Stripe_Helper::is_pre_30() ) {
300
-				update_post_meta( $order_id, '_stripe_source_id', $response->id );
299
+			if (WC_Stripe_Helper::is_pre_30()) {
300
+				update_post_meta($order_id, '_stripe_source_id', $response->id);
301 301
 			} else {
302
-				$order->update_meta_data( '_stripe_source_id', $response->id );
302
+				$order->update_meta_data('_stripe_source_id', $response->id);
303 303
 				$order->save();
304 304
 			}
305 305
 
306
-			WC_Stripe_Logger::log( 'Info: Redirecting to Giropay...' );
306
+			WC_Stripe_Logger::log('Info: Redirecting to Giropay...');
307 307
 
308 308
 			return array(
309 309
 				'result'   => 'success',
310
-				'redirect' => esc_url_raw( $response->redirect->url ),
310
+				'redirect' => esc_url_raw($response->redirect->url),
311 311
 			);
312
-		} catch ( Exception $e ) {
313
-			wc_add_notice( $e->getMessage(), 'error' );
314
-			WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() );
312
+		} catch (Exception $e) {
313
+			wc_add_notice($e->getMessage(), 'error');
314
+			WC_Stripe_Logger::log('Error: ' . $e->getMessage());
315 315
 
316
-			do_action( 'wc_gateway_stripe_process_payment_error', $e, $order );
316
+			do_action('wc_gateway_stripe_process_payment_error', $e, $order);
317 317
 
318
-			if ( $order->has_status( array( 'pending', 'failed' ) ) ) {
319
-				$this->send_failed_order_email( $order_id );
318
+			if ($order->has_status(array('pending', 'failed'))) {
319
+				$this->send_failed_order_email($order_id);
320 320
 			}
321 321
 
322 322
 			return array(
Please login to merge, or discard this patch.
includes/payment-methods/class-wc-gateway-stripe-sepa.php 1 patch
Spacing   +97 added lines, -97 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) {
2
+if ( ! defined('ABSPATH')) {
3 3
 	exit;
4 4
 }
5 5
 
@@ -57,9 +57,9 @@  discard block
 block discarded – undo
57 57
 	 */
58 58
 	public function __construct() {
59 59
 		$this->id                   = 'stripe_sepa';
60
-		$this->method_title         = __( 'Stripe SEPA Direct Debit', 'woocommerce-gateway-stripe' );
60
+		$this->method_title         = __('Stripe SEPA Direct Debit', 'woocommerce-gateway-stripe');
61 61
 		/* translators: link */
62
-		$this->method_description   = sprintf( __( 'All other general Stripe settings can be adjusted <a href="%s">here</a>.', 'woocommerce-gateway-stripe' ), admin_url( 'admin.php?page=wc-settings&tab=checkout&section=stripe' ) );
62
+		$this->method_description   = sprintf(__('All other general Stripe settings can be adjusted <a href="%s">here</a>.', 'woocommerce-gateway-stripe'), admin_url('admin.php?page=wc-settings&tab=checkout&section=stripe'));
63 63
 		$this->supports             = array(
64 64
 			'products',
65 65
 			'refunds',
@@ -84,25 +84,25 @@  discard block
 block discarded – undo
84 84
 		// Load the settings.
85 85
 		$this->init_settings();
86 86
 
87
-		$main_settings              = get_option( 'woocommerce_stripe_settings' );
88
-		$this->title                = $this->get_option( 'title' );
89
-		$this->description          = $this->get_option( 'description' );
90
-		$this->enabled              = $this->get_option( 'enabled' );
91
-		$this->testmode             = ( ! empty( $main_settings['testmode'] ) && 'yes' === $main_settings['testmode'] ) ? true : false;
92
-		$this->saved_cards          = ( ! empty( $main_settings['saved_cards'] ) && 'yes' === $main_settings['saved_cards'] ) ? true : false;
93
-		$this->publishable_key      = ! empty( $main_settings['publishable_key'] ) ? $main_settings['publishable_key'] : '';
94
-		$this->secret_key           = ! empty( $main_settings['secret_key'] ) ? $main_settings['secret_key'] : '';
95
-		$this->statement_descriptor = ! empty( $main_settings['statement_descriptor'] ) ? $main_settings['statement_descriptor'] : '';
96
-
97
-		if ( $this->testmode ) {
98
-			$this->publishable_key = ! empty( $main_settings['test_publishable_key'] ) ? $main_settings['test_publishable_key'] : '';
99
-			$this->secret_key      = ! empty( $main_settings['test_secret_key'] ) ? $main_settings['test_secret_key'] : '';
87
+		$main_settings              = get_option('woocommerce_stripe_settings');
88
+		$this->title                = $this->get_option('title');
89
+		$this->description          = $this->get_option('description');
90
+		$this->enabled              = $this->get_option('enabled');
91
+		$this->testmode             = ( ! empty($main_settings['testmode']) && 'yes' === $main_settings['testmode']) ? true : false;
92
+		$this->saved_cards          = ( ! empty($main_settings['saved_cards']) && 'yes' === $main_settings['saved_cards']) ? true : false;
93
+		$this->publishable_key      = ! empty($main_settings['publishable_key']) ? $main_settings['publishable_key'] : '';
94
+		$this->secret_key           = ! empty($main_settings['secret_key']) ? $main_settings['secret_key'] : '';
95
+		$this->statement_descriptor = ! empty($main_settings['statement_descriptor']) ? $main_settings['statement_descriptor'] : '';
96
+
97
+		if ($this->testmode) {
98
+			$this->publishable_key = ! empty($main_settings['test_publishable_key']) ? $main_settings['test_publishable_key'] : '';
99
+			$this->secret_key      = ! empty($main_settings['test_secret_key']) ? $main_settings['test_secret_key'] : '';
100 100
 		}
101 101
 
102
-		add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) );
103
-		add_action( 'admin_notices', array( $this, 'check_environment' ) );
104
-		add_action( 'admin_head', array( $this, 'remove_admin_notice' ) );
105
-		add_action( 'wp_enqueue_scripts', array( $this, 'payment_scripts' ) );
102
+		add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options'));
103
+		add_action('admin_notices', array($this, 'check_environment'));
104
+		add_action('admin_head', array($this, 'remove_admin_notice'));
105
+		add_action('wp_enqueue_scripts', array($this, 'payment_scripts'));
106 106
 	}
107 107
 
108 108
 	/**
@@ -112,19 +112,19 @@  discard block
 block discarded – undo
112 112
 	 * @version 4.0.0
113 113
 	 */
114 114
 	public function check_environment() {
115
-		if ( ! current_user_can( 'manage_woocommerce' ) ) {
115
+		if ( ! current_user_can('manage_woocommerce')) {
116 116
 			return;
117 117
 		}
118 118
 
119 119
 		$environment_warning = $this->get_environment_warning();
120 120
 
121
-		if ( $environment_warning ) {
122
-			$this->add_admin_notice( 'bad_environment', 'error', $environment_warning );
121
+		if ($environment_warning) {
122
+			$this->add_admin_notice('bad_environment', 'error', $environment_warning);
123 123
 		}
124 124
 
125
-		foreach ( (array) $this->notices as $notice_key => $notice ) {
126
-			echo "<div class='" . esc_attr( $notice['class'] ) . "'><p>";
127
-			echo wp_kses( $notice['message'], array( 'a' => array( 'href' => array() ) ) );
125
+		foreach ((array) $this->notices as $notice_key => $notice) {
126
+			echo "<div class='" . esc_attr($notice['class']) . "'><p>";
127
+			echo wp_kses($notice['message'], array('a' => array('href' => array())));
128 128
 			echo '</p></div>';
129 129
 		}
130 130
 	}
@@ -137,8 +137,8 @@  discard block
 block discarded – undo
137 137
 	 * @version 4.0.0
138 138
 	 */
139 139
 	public function get_environment_warning() {
140
-		if ( 'yes' === $this->enabled && ! in_array( get_woocommerce_currency(), $this->get_supported_currency() ) ) {
141
-			$message = __( 'SEPA is enabled - it requires store currency to be set to Euros.', 'woocommerce-gateway-stripe' );
140
+		if ('yes' === $this->enabled && ! in_array(get_woocommerce_currency(), $this->get_supported_currency())) {
141
+			$message = __('SEPA is enabled - it requires store currency to be set to Euros.', 'woocommerce-gateway-stripe');
142 142
 
143 143
 			return $message;
144 144
 		}
@@ -154,9 +154,9 @@  discard block
 block discarded – undo
154 154
 	 * @return array
155 155
 	 */
156 156
 	public function get_supported_currency() {
157
-		return apply_filters( 'wc_stripe_sepa_supported_currencies', array(
157
+		return apply_filters('wc_stripe_sepa_supported_currencies', array(
158 158
 			'EUR',
159
-		) );
159
+		));
160 160
 	}
161 161
 
162 162
 	/**
@@ -167,7 +167,7 @@  discard block
 block discarded – undo
167 167
 	 * @return bool
168 168
 	 */
169 169
 	public function is_available() {
170
-		if ( ! in_array( get_woocommerce_currency(), $this->get_supported_currency() ) ) {
170
+		if ( ! in_array(get_woocommerce_currency(), $this->get_supported_currency())) {
171 171
 			return false;
172 172
 		}
173 173
 
@@ -188,7 +188,7 @@  discard block
 block discarded – undo
188 188
 
189 189
 		$icons_str .= $icons['sepa'];
190 190
 
191
-		return apply_filters( 'woocommerce_gateway_icon', $icons_str, $this->id );
191
+		return apply_filters('woocommerce_gateway_icon', $icons_str, $this->id);
192 192
 	}
193 193
 
194 194
 	/**
@@ -199,19 +199,19 @@  discard block
 block discarded – undo
199 199
 	 * @access public
200 200
 	 */
201 201
 	public function payment_scripts() {
202
-		if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) && ! is_add_payment_method_page() ) {
202
+		if ( ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order']) && ! is_add_payment_method_page()) {
203 203
 			return;
204 204
 		}
205 205
 
206
-		wp_enqueue_style( 'stripe_paymentfonts' );
207
-		wp_enqueue_script( 'woocommerce_stripe' );
206
+		wp_enqueue_style('stripe_paymentfonts');
207
+		wp_enqueue_script('woocommerce_stripe');
208 208
 	}
209 209
 
210 210
 	/**
211 211
 	 * Initialize Gateway Settings Form Fields.
212 212
 	 */
213 213
 	public function init_form_fields() {
214
-		$this->form_fields = require( WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-sepa-settings.php' );
214
+		$this->form_fields = require(WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-sepa-settings.php');
215 215
 	}
216 216
 
217 217
 	/**
@@ -223,7 +223,7 @@  discard block
 block discarded – undo
223 223
 	 */
224 224
 	public function mandate_display() {
225 225
 		/* translators: statement descriptor */
226
-		printf( __( 'By providing your IBAN and confirming this payment, you are authorizing %s and Stripe, our payment service provider, to send instructions to your bank to debit your account and your bank to debit your account in accordance with those instructions. You are entitled to a refund from your bank under the terms and conditions of your agreement with your bank. A refund must be claimed within 8 weeks starting from the date on which your account was debited.', 'woocommerce-gateway-stripe' ), WC_Stripe_Helper::clean_statement_descriptor( $this->statement_descriptor ) );
226
+		printf(__('By providing your IBAN and confirming this payment, you are authorizing %s and Stripe, our payment service provider, to send instructions to your bank to debit your account and your bank to debit your account in accordance with those instructions. You are entitled to a refund from your bank under the terms and conditions of your agreement with your bank. A refund must be claimed within 8 weeks starting from the date on which your account was debited.', 'woocommerce-gateway-stripe'), WC_Stripe_Helper::clean_statement_descriptor($this->statement_descriptor));
227 227
 	}
228 228
 
229 229
 	/**
@@ -234,24 +234,24 @@  discard block
 block discarded – undo
234 234
 	 */
235 235
 	public function form() {
236 236
 		?>
237
-		<fieldset id="wc-<?php echo esc_attr( $this->id ); ?>-form" class="wc-payment-form">
238
-			<?php do_action( 'woocommerce_credit_card_form_start', $this->id ); ?>
237
+		<fieldset id="wc-<?php echo esc_attr($this->id); ?>-form" class="wc-payment-form">
238
+			<?php do_action('woocommerce_credit_card_form_start', $this->id); ?>
239 239
 			<p class="wc-stripe-sepa-mandate" style="margin-bottom:40px;"><?php $this->mandate_display(); ?></p>
240 240
 			<p class="form-row form-row-wide validate-required">
241 241
 				<label for="stripe-sepa-owner">
242
-					<?php esc_html_e( 'IBAN Account Name.', 'woocommerce-gateway-stripe' ); ?>
242
+					<?php esc_html_e('IBAN Account Name.', 'woocommerce-gateway-stripe'); ?>
243 243
 				</label>
244 244
 				<input id="stripe-sepa-owner" name="stripe_sepa_owner" value="" style="border:1px solid #ddd;margin:5px 0;padding:10px 5px;background-color:#fff;outline:0;" />
245 245
 			</p>
246 246
 			<p class="form-row form-row-wide validate-required">
247 247
 				<label for="stripe-sepa-iban">
248
-					<?php esc_html_e( 'IBAN Account Number.', 'woocommerce-gateway-stripe' ); ?>
248
+					<?php esc_html_e('IBAN Account Number.', 'woocommerce-gateway-stripe'); ?>
249 249
 				</label>
250 250
 				<input id="stripe-sepa-iban" name="stripe_sepa_iban" value="" style="border:1px solid #ddd;margin:5px 0;padding:10px 5px;background-color:#fff;outline:0;" />
251 251
 			</p>
252 252
 			<!-- Used to display form errors -->
253 253
 			<div class="stripe-source-errors" role="alert"></div>
254
-			<?php do_action( 'woocommerce_credit_card_form_end', $this->id ); ?>
254
+			<?php do_action('woocommerce_credit_card_form_end', $this->id); ?>
255 255
 			<div class="clear"></div>
256 256
 		</fieldset>
257 257
 		<?php
@@ -263,42 +263,42 @@  discard block
 block discarded – undo
263 263
 	public function payment_fields() {
264 264
 		$user                 = wp_get_current_user();
265 265
 		$total                = WC()->cart->total;
266
-		$display_tokenization = $this->supports( 'tokenization' ) && is_checkout() && $this->saved_cards;
266
+		$display_tokenization = $this->supports('tokenization') && is_checkout() && $this->saved_cards;
267 267
 
268 268
 		// If paying from order, we need to get total from order not cart.
269
-		if ( isset( $_GET['pay_for_order'] ) && ! empty( $_GET['key'] ) ) {
270
-			$order = wc_get_order( wc_get_order_id_by_order_key( wc_clean( $_GET['key'] ) ) );
269
+		if (isset($_GET['pay_for_order']) && ! empty($_GET['key'])) {
270
+			$order = wc_get_order(wc_get_order_id_by_order_key(wc_clean($_GET['key'])));
271 271
 			$total = $order->get_total();
272 272
 		}
273 273
 
274
-		if ( is_add_payment_method_page() ) {
275
-			$pay_button_text = __( 'Add Payment', 'woocommerce-gateway-stripe' );
276
-			$total        = '';
274
+		if (is_add_payment_method_page()) {
275
+			$pay_button_text = __('Add Payment', 'woocommerce-gateway-stripe');
276
+			$total = '';
277 277
 		} else {
278 278
 			$pay_button_text = '';
279 279
 		}
280 280
 
281 281
 		echo '<div
282 282
 			id="stripe-sepa_debit-payment-data"
283
-			data-amount="' . esc_attr( WC_Stripe_Helper::get_stripe_amount( $total ) ) . '"
284
-			data-currency="' . esc_attr( strtolower( get_woocommerce_currency() ) ) . '">';
283
+			data-amount="' . esc_attr(WC_Stripe_Helper::get_stripe_amount($total)) . '"
284
+			data-currency="' . esc_attr(strtolower(get_woocommerce_currency())) . '">';
285 285
 
286
-		if ( $this->description ) {
287
-			if ( $this->testmode ) {
288
-				$this->description .= ' ' . __( 'TEST MODE ENABLED. In test mode, you can use IBAN number DE89370400440532013000.', 'woocommerce-gateway-stripe' );
289
-				$this->description  = trim( $this->description );
286
+		if ($this->description) {
287
+			if ($this->testmode) {
288
+				$this->description .= ' ' . __('TEST MODE ENABLED. In test mode, you can use IBAN number DE89370400440532013000.', 'woocommerce-gateway-stripe');
289
+				$this->description  = trim($this->description);
290 290
 			}
291
-			echo apply_filters( 'wc_stripe_description', wpautop( wp_kses_post( $this->description ) ) );
291
+			echo apply_filters('wc_stripe_description', wpautop(wp_kses_post($this->description)));
292 292
 		}
293 293
 
294
-		if ( $display_tokenization ) {
294
+		if ($display_tokenization) {
295 295
 			$this->tokenization_script();
296 296
 			$this->saved_payment_methods();
297 297
 		}
298 298
 
299 299
 		$this->form();
300 300
 
301
-		if ( apply_filters( 'wc_stripe_display_save_payment_method_checkbox', $display_tokenization ) && ! is_add_payment_method_page() && ! isset( $_GET['change_payment_method'] ) ) {
301
+		if (apply_filters('wc_stripe_display_save_payment_method_checkbox', $display_tokenization) && ! is_add_payment_method_page() && ! isset($_GET['change_payment_method'])) {
302 302
 			$this->save_payment_method_checkbox();
303 303
 		}
304 304
 
@@ -316,80 +316,80 @@  discard block
 block discarded – undo
316 316
 	 *
317 317
 	 * @return array|void
318 318
 	 */
319
-	public function process_payment( $order_id, $retry = true, $force_save_source = false ) {
319
+	public function process_payment($order_id, $retry = true, $force_save_source = false) {
320 320
 		try {
321
-			$order = wc_get_order( $order_id );
321
+			$order = wc_get_order($order_id);
322 322
 
323 323
 			// This comes from the create account checkbox in the checkout page.
324
-			$create_account = ! empty( $_POST['createaccount'] ) ? true : false;
324
+			$create_account = ! empty($_POST['createaccount']) ? true : false;
325 325
 
326
-			if ( $create_account ) {
326
+			if ($create_account) {
327 327
 				$new_customer_id     = WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id();
328
-				$new_stripe_customer = new WC_Stripe_Customer( $new_customer_id );
328
+				$new_stripe_customer = new WC_Stripe_Customer($new_customer_id);
329 329
 				$new_stripe_customer->create_customer();
330 330
 			}
331 331
 
332
-			$prepared_source = $this->prepare_source( get_current_user_id(), $force_save_source );
332
+			$prepared_source = $this->prepare_source(get_current_user_id(), $force_save_source);
333 333
 
334 334
 			// Store source to order meta.
335
-			$this->save_source( $order, $prepared_source );
335
+			$this->save_source($order, $prepared_source);
336 336
 
337 337
 			// Result from Stripe API request.
338 338
 			$response = null;
339 339
 
340
-			if ( $order->get_total() > 0 ) {
340
+			if ($order->get_total() > 0) {
341 341
 				// This will throw exception if not valid.
342
-				$this->validate_minimum_order_amount( $order );
342
+				$this->validate_minimum_order_amount($order);
343 343
 
344
-				WC_Stripe_Logger::log( "Info: Begin processing payment for order $order_id for the amount of {$order->get_total()}" );
344
+				WC_Stripe_Logger::log("Info: Begin processing payment for order $order_id for the amount of {$order->get_total()}");
345 345
 
346 346
 				// Make the request.
347
-				$response = WC_Stripe_API::request( $this->generate_payment_request( $order, $prepared_source ) );
347
+				$response = WC_Stripe_API::request($this->generate_payment_request($order, $prepared_source));
348 348
 
349
-				if ( ! empty( $response->error ) ) {
349
+				if ( ! empty($response->error)) {
350 350
 					// If it is an API error such connection or server, let's retry.
351
-					if ( 'api_connection_error' === $response->error->type || 'api_error' === $response->error->type ) {
352
-						if ( $retry ) {
353
-							sleep( 5 );
354
-							return $this->process_payment( $order_id, false, $force_save_source );
351
+					if ('api_connection_error' === $response->error->type || 'api_error' === $response->error->type) {
352
+						if ($retry) {
353
+							sleep(5);
354
+							return $this->process_payment($order_id, false, $force_save_source);
355 355
 						} else {
356 356
 							$message = 'API connection error and retries exhausted.';
357
-							$order->add_order_note( $message );
358
-							throw new Exception( $message );
357
+							$order->add_order_note($message);
358
+							throw new Exception($message);
359 359
 						}
360 360
 					}
361 361
 
362 362
 					// Customer param wrong? The user may have been deleted on stripe's end. Remove customer_id. Can be retried without.
363
-					if ( preg_match( '/No such customer/i', $response->error->message ) && $retry ) {
364
-						delete_user_meta( WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id(), '_stripe_customer_id' );
363
+					if (preg_match('/No such customer/i', $response->error->message) && $retry) {
364
+						delete_user_meta(WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id(), '_stripe_customer_id');
365 365
 
366
-						return $this->process_payment( $order_id, false, $force_save_source );
367
-					} elseif ( preg_match( '/No such token/i', $response->error->message ) && $prepared_source->token_id ) {
366
+						return $this->process_payment($order_id, false, $force_save_source);
367
+					} elseif (preg_match('/No such token/i', $response->error->message) && $prepared_source->token_id) {
368 368
 						// Source param wrong? The CARD may have been deleted on stripe's end. Remove token and show message.
369
-						$wc_token = WC_Payment_Tokens::get( $prepared_source->token_id );
369
+						$wc_token = WC_Payment_Tokens::get($prepared_source->token_id);
370 370
 						$wc_token->delete();
371
-						$message = __( 'This card is no longer available and has been removed.', 'woocommerce-gateway-stripe' );
372
-						$order->add_order_note( $message );
373
-						throw new Exception( $message );
371
+						$message = __('This card is no longer available and has been removed.', 'woocommerce-gateway-stripe');
372
+						$order->add_order_note($message);
373
+						throw new Exception($message);
374 374
 					}
375 375
 
376 376
 					$localized_messages = WC_Stripe_Helper::get_localized_messages();
377 377
 
378
-					if ( 'card_error' === $response->error->type ) {
379
-						$message = isset( $localized_messages[ $response->error->code ] ) ? $localized_messages[ $response->error->code ] : $response->error->message;
378
+					if ('card_error' === $response->error->type) {
379
+						$message = isset($localized_messages[$response->error->code]) ? $localized_messages[$response->error->code] : $response->error->message;
380 380
 					} else {
381
-						$message = isset( $localized_messages[ $response->error->type ] ) ? $localized_messages[ $response->error->type ] : $response->error->message;
381
+						$message = isset($localized_messages[$response->error->type]) ? $localized_messages[$response->error->type] : $response->error->message;
382 382
 					}
383 383
 
384
-					$order->add_order_note( $message );
384
+					$order->add_order_note($message);
385 385
 
386
-					throw new Exception( $message );
386
+					throw new Exception($message);
387 387
 				}
388 388
 
389
-				do_action( 'wc_gateway_stripe_process_payment', $response, $order );
389
+				do_action('wc_gateway_stripe_process_payment', $response, $order);
390 390
 
391 391
 				// Process valid response.
392
-				$this->process_response( $response, $order );
392
+				$this->process_response($response, $order);
393 393
 			} else {
394 394
 				$order->payment_complete();
395 395
 			}
@@ -400,17 +400,17 @@  discard block
 block discarded – undo
400 400
 			// Return thank you page redirect.
401 401
 			return array(
402 402
 				'result'   => 'success',
403
-				'redirect' => $this->get_return_url( $order ),
403
+				'redirect' => $this->get_return_url($order),
404 404
 			);
405 405
 
406
-		} catch ( Exception $e ) {
407
-			wc_add_notice( $e->getMessage(), 'error' );
408
-			WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() );
406
+		} catch (Exception $e) {
407
+			wc_add_notice($e->getMessage(), 'error');
408
+			WC_Stripe_Logger::log('Error: ' . $e->getMessage());
409 409
 
410
-			do_action( 'wc_gateway_stripe_process_payment_error', $e, $order );
410
+			do_action('wc_gateway_stripe_process_payment_error', $e, $order);
411 411
 
412
-			if ( $order->has_status( array( 'pending', 'failed' ) ) ) {
413
-				$this->send_failed_order_email( $order_id );
412
+			if ($order->has_status(array('pending', 'failed'))) {
413
+				$this->send_failed_order_email($order_id);
414 414
 			}
415 415
 
416 416
 			return array(
Please login to merge, or discard this patch.
includes/payment-methods/class-wc-gateway-stripe-p24.php 1 patch
Spacing   +74 added lines, -74 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) {
2
+if ( ! defined('ABSPATH')) {
3 3
 	exit;
4 4
 }
5 5
 
@@ -57,9 +57,9 @@  discard block
 block discarded – undo
57 57
 	 */
58 58
 	public function __construct() {
59 59
 		$this->id                   = 'stripe_p24';
60
-		$this->method_title         = __( 'Stripe P24', 'woocommerce-gateway-stripe' );
60
+		$this->method_title         = __('Stripe P24', 'woocommerce-gateway-stripe');
61 61
 		/* translators: link */
62
-		$this->method_description   = sprintf( __( 'All other general Stripe settings can be adjusted <a href="%s">here</a>.', 'woocommerce-gateway-stripe' ), admin_url( 'admin.php?page=wc-settings&tab=checkout&section=stripe' ) );
62
+		$this->method_description   = sprintf(__('All other general Stripe settings can be adjusted <a href="%s">here</a>.', 'woocommerce-gateway-stripe'), admin_url('admin.php?page=wc-settings&tab=checkout&section=stripe'));
63 63
 		$this->supports             = array(
64 64
 			'products',
65 65
 			'refunds',
@@ -71,25 +71,25 @@  discard block
 block discarded – undo
71 71
 		// Load the settings.
72 72
 		$this->init_settings();
73 73
 
74
-		$main_settings              = get_option( 'woocommerce_stripe_settings' );
75
-		$this->title                = $this->get_option( 'title' );
76
-		$this->description          = $this->get_option( 'description' );
77
-		$this->enabled              = $this->get_option( 'enabled' );
78
-		$this->testmode             = ( ! empty( $main_settings['testmode'] ) && 'yes' === $main_settings['testmode'] ) ? true : false;
79
-		$this->saved_cards          = ( ! empty( $main_settings['saved_cards'] ) && 'yes' === $main_settings['saved_cards'] ) ? true : false;
80
-		$this->publishable_key      = ! empty( $main_settings['publishable_key'] ) ? $main_settings['publishable_key'] : '';
81
-		$this->secret_key           = ! empty( $main_settings['secret_key'] ) ? $main_settings['secret_key'] : '';
82
-		$this->statement_descriptor = ! empty( $main_settings['statement_descriptor'] ) ? $main_settings['statement_descriptor'] : '';
83
-
84
-		if ( $this->testmode ) {
85
-			$this->publishable_key = ! empty( $main_settings['test_publishable_key'] ) ? $main_settings['test_publishable_key'] : '';
86
-			$this->secret_key      = ! empty( $main_settings['test_secret_key'] ) ? $main_settings['test_secret_key'] : '';
74
+		$main_settings              = get_option('woocommerce_stripe_settings');
75
+		$this->title                = $this->get_option('title');
76
+		$this->description          = $this->get_option('description');
77
+		$this->enabled              = $this->get_option('enabled');
78
+		$this->testmode             = ( ! empty($main_settings['testmode']) && 'yes' === $main_settings['testmode']) ? true : false;
79
+		$this->saved_cards          = ( ! empty($main_settings['saved_cards']) && 'yes' === $main_settings['saved_cards']) ? true : false;
80
+		$this->publishable_key      = ! empty($main_settings['publishable_key']) ? $main_settings['publishable_key'] : '';
81
+		$this->secret_key           = ! empty($main_settings['secret_key']) ? $main_settings['secret_key'] : '';
82
+		$this->statement_descriptor = ! empty($main_settings['statement_descriptor']) ? $main_settings['statement_descriptor'] : '';
83
+
84
+		if ($this->testmode) {
85
+			$this->publishable_key = ! empty($main_settings['test_publishable_key']) ? $main_settings['test_publishable_key'] : '';
86
+			$this->secret_key      = ! empty($main_settings['test_secret_key']) ? $main_settings['test_secret_key'] : '';
87 87
 		}
88 88
 
89
-		add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) );
90
-		add_action( 'admin_notices', array( $this, 'check_environment' ) );
91
-		add_action( 'admin_head', array( $this, 'remove_admin_notice' ) );
92
-		add_action( 'wp_enqueue_scripts', array( $this, 'payment_scripts' ) );
89
+		add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options'));
90
+		add_action('admin_notices', array($this, 'check_environment'));
91
+		add_action('admin_head', array($this, 'remove_admin_notice'));
92
+		add_action('wp_enqueue_scripts', array($this, 'payment_scripts'));
93 93
 	}
94 94
 
95 95
 	/**
@@ -99,19 +99,19 @@  discard block
 block discarded – undo
99 99
 	 * @version 4.0.0
100 100
 	 */
101 101
 	public function check_environment() {
102
-		if ( ! current_user_can( 'manage_woocommerce' ) ) {
102
+		if ( ! current_user_can('manage_woocommerce')) {
103 103
 			return;
104 104
 		}
105 105
 
106 106
 		$environment_warning = $this->get_environment_warning();
107 107
 
108
-		if ( $environment_warning ) {
109
-			$this->add_admin_notice( 'bad_environment', 'error', $environment_warning );
108
+		if ($environment_warning) {
109
+			$this->add_admin_notice('bad_environment', 'error', $environment_warning);
110 110
 		}
111 111
 
112
-		foreach ( (array) $this->notices as $notice_key => $notice ) {
113
-			echo "<div class='" . esc_attr( $notice['class'] ) . "'><p>";
114
-			echo wp_kses( $notice['message'], array( 'a' => array( 'href' => array() ) ) );
112
+		foreach ((array) $this->notices as $notice_key => $notice) {
113
+			echo "<div class='" . esc_attr($notice['class']) . "'><p>";
114
+			echo wp_kses($notice['message'], array('a' => array('href' => array())));
115 115
 			echo '</p></div>';
116 116
 		}
117 117
 	}
@@ -124,8 +124,8 @@  discard block
 block discarded – undo
124 124
 	 * @version 4.0.0
125 125
 	 */
126 126
 	public function get_environment_warning() {
127
-		if ( 'yes' === $this->enabled && ! in_array( get_woocommerce_currency(), $this->get_supported_currency() ) ) {
128
-			$message = __( 'P24 is enabled - it requires store currency to be set to Euros or Polish Zloty.', 'woocommerce-gateway-stripe' );
127
+		if ('yes' === $this->enabled && ! in_array(get_woocommerce_currency(), $this->get_supported_currency())) {
128
+			$message = __('P24 is enabled - it requires store currency to be set to Euros or Polish Zloty.', 'woocommerce-gateway-stripe');
129 129
 
130 130
 			return $message;
131 131
 		}
@@ -141,10 +141,10 @@  discard block
 block discarded – undo
141 141
 	 * @return array
142 142
 	 */
143 143
 	public function get_supported_currency() {
144
-		return apply_filters( 'wc_stripe_p24_supported_currencies', array(
144
+		return apply_filters('wc_stripe_p24_supported_currencies', array(
145 145
 			'EUR',
146 146
 			'PLN',
147
-		) );
147
+		));
148 148
 	}
149 149
 
150 150
 	/**
@@ -155,7 +155,7 @@  discard block
 block discarded – undo
155 155
 	 * @return bool
156 156
 	 */
157 157
 	public function is_available() {
158
-		if ( ! in_array( get_woocommerce_currency(), $this->get_supported_currency() ) ) {
158
+		if ( ! in_array(get_woocommerce_currency(), $this->get_supported_currency())) {
159 159
 			return false;
160 160
 		}
161 161
 
@@ -176,7 +176,7 @@  discard block
 block discarded – undo
176 176
 
177 177
 		$icons_str .= $icons['p24'];
178 178
 
179
-		return apply_filters( 'woocommerce_gateway_icon', $icons_str, $this->id );
179
+		return apply_filters('woocommerce_gateway_icon', $icons_str, $this->id);
180 180
 	}
181 181
 
182 182
 	/**
@@ -187,19 +187,19 @@  discard block
 block discarded – undo
187 187
 	 * @access public
188 188
 	 */
189 189
 	public function payment_scripts() {
190
-		if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) && ! is_add_payment_method_page() ) {
190
+		if ( ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order']) && ! is_add_payment_method_page()) {
191 191
 			return;
192 192
 		}
193 193
 
194
-		wp_enqueue_style( 'stripe_paymentfonts' );
195
-		wp_enqueue_script( 'woocommerce_stripe' );
194
+		wp_enqueue_style('stripe_paymentfonts');
195
+		wp_enqueue_script('woocommerce_stripe');
196 196
 	}
197 197
 
198 198
 	/**
199 199
 	 * Initialize Gateway Settings Form Fields.
200 200
 	 */
201 201
 	public function init_form_fields() {
202
-		$this->form_fields = require( WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-p24-settings.php' );
202
+		$this->form_fields = require(WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-p24-settings.php');
203 203
 	}
204 204
 
205 205
 	/**
@@ -210,25 +210,25 @@  discard block
 block discarded – undo
210 210
 		$total                = WC()->cart->total;
211 211
 
212 212
 		// If paying from order, we need to get total from order not cart.
213
-		if ( isset( $_GET['pay_for_order'] ) && ! empty( $_GET['key'] ) ) {
214
-			$order = wc_get_order( wc_get_order_id_by_order_key( wc_clean( $_GET['key'] ) ) );
213
+		if (isset($_GET['pay_for_order']) && ! empty($_GET['key'])) {
214
+			$order = wc_get_order(wc_get_order_id_by_order_key(wc_clean($_GET['key'])));
215 215
 			$total = $order->get_total();
216 216
 		}
217 217
 
218
-		if ( is_add_payment_method_page() ) {
219
-			$pay_button_text = __( 'Add Payment', 'woocommerce-gateway-stripe' );
220
-			$total        = '';
218
+		if (is_add_payment_method_page()) {
219
+			$pay_button_text = __('Add Payment', 'woocommerce-gateway-stripe');
220
+			$total = '';
221 221
 		} else {
222 222
 			$pay_button_text = '';
223 223
 		}
224 224
 
225 225
 		echo '<div
226 226
 			id="stripe-p24-payment-data"
227
-			data-amount="' . esc_attr( WC_Stripe_Helper::get_stripe_amount( $total ) ) . '"
228
-			data-currency="' . esc_attr( strtolower( get_woocommerce_currency() ) ) . '">';
227
+			data-amount="' . esc_attr(WC_Stripe_Helper::get_stripe_amount($total)) . '"
228
+			data-currency="' . esc_attr(strtolower(get_woocommerce_currency())) . '">';
229 229
 
230
-		if ( $this->description ) {
231
-			echo apply_filters( 'wc_stripe_description', wpautop( wp_kses_post( $this->description ) ) );
230
+		if ($this->description) {
231
+			echo apply_filters('wc_stripe_description', wpautop(wp_kses_post($this->description)));
232 232
 		}
233 233
 
234 234
 		echo '</div>';
@@ -242,20 +242,20 @@  discard block
 block discarded – undo
242 242
 	 * @param object $order
243 243
 	 * @return mixed
244 244
 	 */
245
-	public function create_source( $order ) {
245
+	public function create_source($order) {
246 246
 		$currency              = WC_Stripe_Helper::is_pre_30() ? $order->get_order_currency() : $order->get_currency();
247 247
 		$order_id              = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
248
-		$return_url            = $this->get_stripe_return_url( $order );
248
+		$return_url            = $this->get_stripe_return_url($order);
249 249
 		$post_data             = array();
250
-		$post_data['amount']   = WC_Stripe_Helper::get_stripe_amount( $order->get_total(), $currency );
251
-		$post_data['currency'] = strtolower( $currency );
250
+		$post_data['amount']   = WC_Stripe_Helper::get_stripe_amount($order->get_total(), $currency);
251
+		$post_data['currency'] = strtolower($currency);
252 252
 		$post_data['type']     = 'p24';
253
-		$post_data['owner']    = $this->get_owner_details( $order );
254
-		$post_data['redirect'] = array( 'return_url' => $return_url );
253
+		$post_data['owner']    = $this->get_owner_details($order);
254
+		$post_data['redirect'] = array('return_url' => $return_url);
255 255
 
256
-		WC_Stripe_Logger::log( 'Info: Begin creating P24 source' );
256
+		WC_Stripe_Logger::log('Info: Begin creating P24 source');
257 257
 
258
-		return WC_Stripe_API::request( $post_data, 'sources' );
258
+		return WC_Stripe_API::request($post_data, 'sources');
259 259
 	}
260 260
 
261 261
 	/**
@@ -269,51 +269,51 @@  discard block
 block discarded – undo
269 269
 	 *
270 270
 	 * @return array|void
271 271
 	 */
272
-	public function process_payment( $order_id, $retry = true, $force_save_source = false ) {
272
+	public function process_payment($order_id, $retry = true, $force_save_source = false) {
273 273
 		try {
274
-			$order = wc_get_order( $order_id );
274
+			$order = wc_get_order($order_id);
275 275
 
276 276
 			// This will throw exception if not valid.
277
-			$this->validate_minimum_order_amount( $order );
277
+			$this->validate_minimum_order_amount($order);
278 278
 
279 279
 			// This comes from the create account checkbox in the checkout page.
280
-			$create_account = ! empty( $_POST['createaccount'] ) ? true : false;
280
+			$create_account = ! empty($_POST['createaccount']) ? true : false;
281 281
 
282
-			if ( $create_account ) {
282
+			if ($create_account) {
283 283
 				$new_customer_id     = WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id();
284
-				$new_stripe_customer = new WC_Stripe_Customer( $new_customer_id );
284
+				$new_stripe_customer = new WC_Stripe_Customer($new_customer_id);
285 285
 				$new_stripe_customer->create_customer();
286 286
 			}
287 287
 
288
-			$response = $this->create_source( $order );
288
+			$response = $this->create_source($order);
289 289
 
290
-			if ( ! empty( $response->error ) ) {
291
-				$order->add_order_note( $response->error->message );
290
+			if ( ! empty($response->error)) {
291
+				$order->add_order_note($response->error->message);
292 292
 
293
-				throw new Exception( $response->error->message );
293
+				throw new Exception($response->error->message);
294 294
 			}
295 295
 
296
-			if ( WC_Stripe_Helper::is_pre_30() ) {
297
-				update_post_meta( $order_id, '_stripe_source_id', $response->id );
296
+			if (WC_Stripe_Helper::is_pre_30()) {
297
+				update_post_meta($order_id, '_stripe_source_id', $response->id);
298 298
 			} else {
299
-				$order->update_meta_data( '_stripe_source_id', $response->id );
299
+				$order->update_meta_data('_stripe_source_id', $response->id);
300 300
 				$order->save();
301 301
 			}
302 302
 
303
-			WC_Stripe_Logger::log( 'Info: Redirecting to P24...' );
303
+			WC_Stripe_Logger::log('Info: Redirecting to P24...');
304 304
 
305 305
 			return array(
306 306
 				'result'   => 'success',
307
-				'redirect' => esc_url_raw( $response->redirect->url ),
307
+				'redirect' => esc_url_raw($response->redirect->url),
308 308
 			);
309
-		} catch ( Exception $e ) {
310
-			wc_add_notice( $e->getMessage(), 'error' );
311
-			WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() );
309
+		} catch (Exception $e) {
310
+			wc_add_notice($e->getMessage(), 'error');
311
+			WC_Stripe_Logger::log('Error: ' . $e->getMessage());
312 312
 
313
-			do_action( 'wc_gateway_stripe_process_payment_error', $e, $order );
313
+			do_action('wc_gateway_stripe_process_payment_error', $e, $order);
314 314
 
315
-			if ( $order->has_status( array( 'pending', 'failed' ) ) ) {
316
-				$this->send_failed_order_email( $order_id );
315
+			if ($order->has_status(array('pending', 'failed'))) {
316
+				$this->send_failed_order_email($order_id);
317 317
 			}
318 318
 
319 319
 			return array(
Please login to merge, or discard this patch.