Completed
Pull Request — master (#1263)
by
unknown
01:47
created
includes/class-wc-stripe-helper.php 1 patch
Spacing   +95 added lines, -95 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
 
@@ -22,12 +22,12 @@  discard block
 block discarded – undo
22 22
 	 * @param object $order
23 23
 	 * @return string $currency
24 24
 	 */
25
-	public static function get_stripe_currency( $order = null ) {
26
-		if ( is_null( $order ) ) {
25
+	public static function get_stripe_currency($order = null) {
26
+		if (is_null($order)) {
27 27
 			return false;
28 28
 		}
29 29
 
30
-		return $order->get_meta( self::META_NAME_STRIPE_CURRENCY, true );
30
+		return $order->get_meta(self::META_NAME_STRIPE_CURRENCY, true);
31 31
 	}
32 32
 
33 33
 	/**
@@ -37,12 +37,12 @@  discard block
 block discarded – undo
37 37
 	 * @param object $order
38 38
 	 * @param string $currency
39 39
 	 */
40
-	public static function update_stripe_currency( $order = null, $currency ) {
41
-		if ( is_null( $order ) ) {
40
+	public static function update_stripe_currency($order = null, $currency) {
41
+		if (is_null($order)) {
42 42
 			return false;
43 43
 		}
44 44
 
45
-		$order->update_meta_data( self::META_NAME_STRIPE_CURRENCY, $currency );
45
+		$order->update_meta_data(self::META_NAME_STRIPE_CURRENCY, $currency);
46 46
 	}
47 47
 
48 48
 	/**
@@ -52,20 +52,20 @@  discard block
 block discarded – undo
52 52
 	 * @param object $order
53 53
 	 * @return string $amount
54 54
 	 */
55
-	public static function get_stripe_fee( $order = null ) {
56
-		if ( is_null( $order ) ) {
55
+	public static function get_stripe_fee($order = null) {
56
+		if (is_null($order)) {
57 57
 			return false;
58 58
 		}
59 59
 
60
-		$amount = $order->get_meta( self::META_NAME_FEE, true );
60
+		$amount = $order->get_meta(self::META_NAME_FEE, true);
61 61
 
62 62
 		// If not found let's check for legacy name.
63
-		if ( empty( $amount ) ) {
64
-			$amount = $order->get_meta( self::LEGACY_META_NAME_FEE, true );
63
+		if (empty($amount)) {
64
+			$amount = $order->get_meta(self::LEGACY_META_NAME_FEE, true);
65 65
 
66 66
 			// If found update to new name.
67
-			if ( $amount ) {
68
-				self::update_stripe_fee( $order, $amount );
67
+			if ($amount) {
68
+				self::update_stripe_fee($order, $amount);
69 69
 			}
70 70
 		}
71 71
 
@@ -79,12 +79,12 @@  discard block
 block discarded – undo
79 79
 	 * @param object $order
80 80
 	 * @param float $amount
81 81
 	 */
82
-	public static function update_stripe_fee( $order = null, $amount = 0.0 ) {
83
-		if ( is_null( $order ) ) {
82
+	public static function update_stripe_fee($order = null, $amount = 0.0) {
83
+		if (is_null($order)) {
84 84
 			return false;
85 85
 		}
86 86
 
87
-		$order->update_meta_data( self::META_NAME_FEE, $amount );
87
+		$order->update_meta_data(self::META_NAME_FEE, $amount);
88 88
 	}
89 89
 
90 90
 	/**
@@ -93,15 +93,15 @@  discard block
 block discarded – undo
93 93
 	 * @since 4.1.0
94 94
 	 * @param object $order
95 95
 	 */
96
-	public static function delete_stripe_fee( $order = null ) {
97
-		if ( is_null( $order ) ) {
96
+	public static function delete_stripe_fee($order = null) {
97
+		if (is_null($order)) {
98 98
 			return false;
99 99
 		}
100 100
 
101 101
 		$order_id = $order->get_id();
102 102
 
103
-		delete_post_meta( $order_id, self::META_NAME_FEE );
104
-		delete_post_meta( $order_id, self::LEGACY_META_NAME_FEE );
103
+		delete_post_meta($order_id, self::META_NAME_FEE);
104
+		delete_post_meta($order_id, self::LEGACY_META_NAME_FEE);
105 105
 	}
106 106
 
107 107
 	/**
@@ -111,20 +111,20 @@  discard block
 block discarded – undo
111 111
 	 * @param object $order
112 112
 	 * @return string $amount
113 113
 	 */
114
-	public static function get_stripe_net( $order = null ) {
115
-		if ( is_null( $order ) ) {
114
+	public static function get_stripe_net($order = null) {
115
+		if (is_null($order)) {
116 116
 			return false;
117 117
 		}
118 118
 
119
-		$amount = $order->get_meta( self::META_NAME_NET, true );
119
+		$amount = $order->get_meta(self::META_NAME_NET, true);
120 120
 
121 121
 		// If not found let's check for legacy name.
122
-		if ( empty( $amount ) ) {
123
-			$amount = $order->get_meta( self::LEGACY_META_NAME_NET, true );
122
+		if (empty($amount)) {
123
+			$amount = $order->get_meta(self::LEGACY_META_NAME_NET, true);
124 124
 
125 125
 			// If found update to new name.
126
-			if ( $amount ) {
127
-				self::update_stripe_net( $order, $amount );
126
+			if ($amount) {
127
+				self::update_stripe_net($order, $amount);
128 128
 			}
129 129
 		}
130 130
 
@@ -138,12 +138,12 @@  discard block
 block discarded – undo
138 138
 	 * @param object $order
139 139
 	 * @param float $amount
140 140
 	 */
141
-	public static function update_stripe_net( $order = null, $amount = 0.0 ) {
142
-		if ( is_null( $order ) ) {
141
+	public static function update_stripe_net($order = null, $amount = 0.0) {
142
+		if (is_null($order)) {
143 143
 			return false;
144 144
 		}
145 145
 
146
-		$order->update_meta_data( self::META_NAME_NET, $amount );
146
+		$order->update_meta_data(self::META_NAME_NET, $amount);
147 147
 	}
148 148
 
149 149
 	/**
@@ -152,15 +152,15 @@  discard block
 block discarded – undo
152 152
 	 * @since 4.1.0
153 153
 	 * @param object $order
154 154
 	 */
155
-	public static function delete_stripe_net( $order = null ) {
156
-		if ( is_null( $order ) ) {
155
+	public static function delete_stripe_net($order = null) {
156
+		if (is_null($order)) {
157 157
 			return false;
158 158
 		}
159 159
 
160 160
 		$order_id = $order->get_id();
161 161
 
162
-		delete_post_meta( $order_id, self::META_NAME_NET );
163
-		delete_post_meta( $order_id, self::LEGACY_META_NAME_NET );
162
+		delete_post_meta($order_id, self::META_NAME_NET);
163
+		delete_post_meta($order_id, self::LEGACY_META_NAME_NET);
164 164
 	}
165 165
 
166 166
 	/**
@@ -171,15 +171,15 @@  discard block
 block discarded – undo
171 171
 	 *
172 172
 	 * @return float|int
173 173
 	 */
174
-	public static function get_stripe_amount( $total, $currency = '' ) {
175
-		if ( ! $currency ) {
174
+	public static function get_stripe_amount($total, $currency = '') {
175
+		if ( ! $currency) {
176 176
 			$currency = get_woocommerce_currency();
177 177
 		}
178 178
 
179
-		if ( in_array( strtolower( $currency ), self::no_decimal_currencies() ) ) {
180
-			return absint( $total );
179
+		if (in_array(strtolower($currency), self::no_decimal_currencies())) {
180
+			return absint($total);
181 181
 		} else {
182
-			return absint( wc_format_decimal( ( (float) $total * 100 ), wc_get_price_decimals() ) ); // In cents.
182
+			return absint(wc_format_decimal(((float) $total * 100), wc_get_price_decimals())); // In cents.
183 183
 		}
184 184
 	}
185 185
 
@@ -194,24 +194,24 @@  discard block
 block discarded – undo
194 194
 		return apply_filters(
195 195
 			'wc_stripe_localized_messages',
196 196
 			array(
197
-				'invalid_number'           => __( 'The card number is not a valid credit card number.', 'woocommerce-gateway-stripe' ),
198
-				'invalid_expiry_month'     => __( 'The card\'s expiration month is invalid.', 'woocommerce-gateway-stripe' ),
199
-				'invalid_expiry_year'      => __( 'The card\'s expiration year is invalid.', 'woocommerce-gateway-stripe' ),
200
-				'invalid_cvc'              => __( 'The card\'s security code is invalid.', 'woocommerce-gateway-stripe' ),
201
-				'incorrect_number'         => __( 'The card number is incorrect.', 'woocommerce-gateway-stripe' ),
202
-				'incomplete_number'        => __( 'The card number is incomplete.', 'woocommerce-gateway-stripe' ),
203
-				'incomplete_cvc'           => __( 'The card\'s security code is incomplete.', 'woocommerce-gateway-stripe' ),
204
-				'incomplete_expiry'        => __( 'The card\'s expiration date is incomplete.', 'woocommerce-gateway-stripe' ),
205
-				'expired_card'             => __( 'The card has expired.', 'woocommerce-gateway-stripe' ),
206
-				'incorrect_cvc'            => __( 'The card\'s security code is incorrect.', 'woocommerce-gateway-stripe' ),
207
-				'incorrect_zip'            => __( 'The card\'s zip code failed validation.', 'woocommerce-gateway-stripe' ),
208
-				'invalid_expiry_year_past' => __( 'The card\'s expiration year is in the past', 'woocommerce-gateway-stripe' ),
209
-				'card_declined'            => __( 'The card was declined.', 'woocommerce-gateway-stripe' ),
210
-				'missing'                  => __( 'There is no card on a customer that is being charged.', 'woocommerce-gateway-stripe' ),
211
-				'processing_error'         => __( 'An error occurred while processing the card.', 'woocommerce-gateway-stripe' ),
212
-				'invalid_request_error'    => __( 'Unable to process this payment, please try again or use alternative method.', 'woocommerce-gateway-stripe' ),
213
-				'invalid_sofort_country'   => __( 'The billing country is not accepted by SOFORT. Please try another country.', 'woocommerce-gateway-stripe' ),
214
-				'email_invalid'            => __( 'Invalid email address, please correct and try again.', 'woocommerce-gateway-stripe' ),
197
+				'invalid_number'           => __('The card number is not a valid credit card number.', 'woocommerce-gateway-stripe'),
198
+				'invalid_expiry_month'     => __('The card\'s expiration month is invalid.', 'woocommerce-gateway-stripe'),
199
+				'invalid_expiry_year'      => __('The card\'s expiration year is invalid.', 'woocommerce-gateway-stripe'),
200
+				'invalid_cvc'              => __('The card\'s security code is invalid.', 'woocommerce-gateway-stripe'),
201
+				'incorrect_number'         => __('The card number is incorrect.', 'woocommerce-gateway-stripe'),
202
+				'incomplete_number'        => __('The card number is incomplete.', 'woocommerce-gateway-stripe'),
203
+				'incomplete_cvc'           => __('The card\'s security code is incomplete.', 'woocommerce-gateway-stripe'),
204
+				'incomplete_expiry'        => __('The card\'s expiration date is incomplete.', 'woocommerce-gateway-stripe'),
205
+				'expired_card'             => __('The card has expired.', 'woocommerce-gateway-stripe'),
206
+				'incorrect_cvc'            => __('The card\'s security code is incorrect.', 'woocommerce-gateway-stripe'),
207
+				'incorrect_zip'            => __('The card\'s zip code failed validation.', 'woocommerce-gateway-stripe'),
208
+				'invalid_expiry_year_past' => __('The card\'s expiration year is in the past', 'woocommerce-gateway-stripe'),
209
+				'card_declined'            => __('The card was declined.', 'woocommerce-gateway-stripe'),
210
+				'missing'                  => __('There is no card on a customer that is being charged.', 'woocommerce-gateway-stripe'),
211
+				'processing_error'         => __('An error occurred while processing the card.', 'woocommerce-gateway-stripe'),
212
+				'invalid_request_error'    => __('Unable to process this payment, please try again or use alternative method.', 'woocommerce-gateway-stripe'),
213
+				'invalid_sofort_country'   => __('The billing country is not accepted by SOFORT. Please try another country.', 'woocommerce-gateway-stripe'),
214
+				'email_invalid'            => __('Invalid email address, please correct and try again.', 'woocommerce-gateway-stripe'),
215 215
 			)
216 216
 		);
217 217
 	}
@@ -252,24 +252,24 @@  discard block
 block discarded – undo
252 252
 	 * @param string $type Type of number to format
253 253
 	 * @return string
254 254
 	 */
255
-	public static function format_balance_fee( $balance_transaction, $type = 'fee' ) {
256
-		if ( ! is_object( $balance_transaction ) ) {
255
+	public static function format_balance_fee($balance_transaction, $type = 'fee') {
256
+		if ( ! is_object($balance_transaction)) {
257 257
 			return;
258 258
 		}
259 259
 
260
-		if ( in_array( strtolower( $balance_transaction->currency ), self::no_decimal_currencies() ) ) {
261
-			if ( 'fee' === $type ) {
260
+		if (in_array(strtolower($balance_transaction->currency), self::no_decimal_currencies())) {
261
+			if ('fee' === $type) {
262 262
 				return $balance_transaction->fee;
263 263
 			}
264 264
 
265 265
 			return $balance_transaction->net;
266 266
 		}
267 267
 
268
-		if ( 'fee' === $type ) {
269
-			return number_format( $balance_transaction->fee / 100, 2, '.', '' );
268
+		if ('fee' === $type) {
269
+			return number_format($balance_transaction->fee / 100, 2, '.', '');
270 270
 		}
271 271
 
272
-		return number_format( $balance_transaction->net / 100, 2, '.', '' );
272
+		return number_format($balance_transaction->net / 100, 2, '.', '');
273 273
 	}
274 274
 
275 275
 	/**
@@ -277,7 +277,7 @@  discard block
 block discarded – undo
277 277
 	 */
278 278
 	public static function get_minimum_amount() {
279 279
 		// Check order amount
280
-		switch ( get_woocommerce_currency() ) {
280
+		switch (get_woocommerce_currency()) {
281 281
 			case 'USD':
282 282
 			case 'CAD':
283 283
 			case 'EUR':
@@ -322,14 +322,14 @@  discard block
 block discarded – undo
322 322
 	 * @param string $method The payment method to get the settings from.
323 323
 	 * @param string $setting The name of the setting to get.
324 324
 	 */
325
-	public static function get_settings( $method = null, $setting = null ) {
326
-		$all_settings = null === $method ? get_option( 'woocommerce_stripe_settings', array() ) : get_option( 'woocommerce_stripe_' . $method . '_settings', array() );
325
+	public static function get_settings($method = null, $setting = null) {
326
+		$all_settings = null === $method ? get_option('woocommerce_stripe_settings', array()) : get_option('woocommerce_stripe_' . $method . '_settings', array());
327 327
 
328
-		if ( null === $setting ) {
328
+		if (null === $setting) {
329 329
 			return $all_settings;
330 330
 		}
331 331
 
332
-		return isset( $all_settings[ $setting ] ) ? $all_settings[ $setting ] : '';
332
+		return isset($all_settings[$setting]) ? $all_settings[$setting] : '';
333 333
 	}
334 334
 
335 335
 	/**
@@ -339,7 +339,7 @@  discard block
 block discarded – undo
339 339
 	 * @return bool
340 340
 	 */
341 341
 	public static function is_pre_orders_exists() {
342
-		return class_exists( 'WC_Pre_Orders_Order' );
342
+		return class_exists('WC_Pre_Orders_Order');
343 343
 	}
344 344
 
345 345
 	/**
@@ -349,8 +349,8 @@  discard block
 block discarded – undo
349 349
 	 * @param string $version Version to check against.
350 350
 	 * @return bool
351 351
 	 */
352
-	public static function is_wc_lt( $version ) {
353
-		return version_compare( WC_VERSION, $version, '<' );
352
+	public static function is_wc_lt($version) {
353
+		return version_compare(WC_VERSION, $version, '<');
354 354
 	}
355 355
 
356 356
 	/**
@@ -363,7 +363,7 @@  discard block
 block discarded – undo
363 363
 	 * @return string
364 364
 	 */
365 365
 	public static function get_webhook_url() {
366
-		return add_query_arg( 'wc-api', 'wc_stripe', trailingslashit( get_home_url() ) );
366
+		return add_query_arg('wc-api', 'wc_stripe', trailingslashit(get_home_url()));
367 367
 	}
368 368
 
369 369
 	/**
@@ -373,13 +373,13 @@  discard block
 block discarded – undo
373 373
 	 * @version 4.0.0
374 374
 	 * @param string $source_id
375 375
 	 */
376
-	public static function get_order_by_source_id( $source_id ) {
376
+	public static function get_order_by_source_id($source_id) {
377 377
 		global $wpdb;
378 378
 
379
-		$order_id = $wpdb->get_var( $wpdb->prepare( "SELECT DISTINCT ID FROM $wpdb->posts as posts LEFT JOIN $wpdb->postmeta as meta ON posts.ID = meta.post_id WHERE meta.meta_value = %s AND meta.meta_key = %s", $source_id, '_stripe_source_id' ) );
379
+		$order_id = $wpdb->get_var($wpdb->prepare("SELECT DISTINCT ID FROM $wpdb->posts as posts LEFT JOIN $wpdb->postmeta as meta ON posts.ID = meta.post_id WHERE meta.meta_value = %s AND meta.meta_key = %s", $source_id, '_stripe_source_id'));
380 380
 
381
-		if ( ! empty( $order_id ) ) {
382
-			return wc_get_order( $order_id );
381
+		if ( ! empty($order_id)) {
382
+			return wc_get_order($order_id);
383 383
 		}
384 384
 
385 385
 		return false;
@@ -392,17 +392,17 @@  discard block
 block discarded – undo
392 392
 	 * @since 4.1.16 Return false if charge_id is empty.
393 393
 	 * @param string $charge_id
394 394
 	 */
395
-	public static function get_order_by_charge_id( $charge_id ) {
395
+	public static function get_order_by_charge_id($charge_id) {
396 396
 		global $wpdb;
397 397
 
398
-		if ( empty( $charge_id ) ) {
398
+		if (empty($charge_id)) {
399 399
 			return false;
400 400
 		}
401 401
 
402
-		$order_id = $wpdb->get_var( $wpdb->prepare( "SELECT DISTINCT ID FROM $wpdb->posts as posts LEFT JOIN $wpdb->postmeta as meta ON posts.ID = meta.post_id WHERE meta.meta_value = %s AND meta.meta_key = %s", $charge_id, '_transaction_id' ) );
402
+		$order_id = $wpdb->get_var($wpdb->prepare("SELECT DISTINCT ID FROM $wpdb->posts as posts LEFT JOIN $wpdb->postmeta as meta ON posts.ID = meta.post_id WHERE meta.meta_value = %s AND meta.meta_key = %s", $charge_id, '_transaction_id'));
403 403
 
404
-		if ( ! empty( $order_id ) ) {
405
-			return wc_get_order( $order_id );
404
+		if ( ! empty($order_id)) {
405
+			return wc_get_order($order_id);
406 406
 		}
407 407
 
408 408
 		return false;
@@ -415,13 +415,13 @@  discard block
 block discarded – undo
415 415
 	 * @param string $intent_id The ID of the intent.
416 416
 	 * @return WC_Order|bool Either an order or false when not found.
417 417
 	 */
418
-	public static function get_order_by_intent_id( $intent_id ) {
418
+	public static function get_order_by_intent_id($intent_id) {
419 419
 		global $wpdb;
420 420
 
421
-		$order_id = $wpdb->get_var( $wpdb->prepare( "SELECT DISTINCT ID FROM $wpdb->posts as posts LEFT JOIN $wpdb->postmeta as meta ON posts.ID = meta.post_id WHERE meta.meta_value = %s AND meta.meta_key = %s", $intent_id, '_stripe_intent_id' ) );
421
+		$order_id = $wpdb->get_var($wpdb->prepare("SELECT DISTINCT ID FROM $wpdb->posts as posts LEFT JOIN $wpdb->postmeta as meta ON posts.ID = meta.post_id WHERE meta.meta_value = %s AND meta.meta_key = %s", $intent_id, '_stripe_intent_id'));
422 422
 
423
-		if ( ! empty( $order_id ) ) {
424
-			return wc_get_order( $order_id );
423
+		if ( ! empty($order_id)) {
424
+			return wc_get_order($order_id);
425 425
 		}
426 426
 
427 427
 		return false;
@@ -434,13 +434,13 @@  discard block
 block discarded – undo
434 434
 	 * @param string $intent_id The ID of the intent.
435 435
 	 * @return WC_Order|bool Either an order or false when not found.
436 436
 	 */
437
-	public static function get_order_by_setup_intent_id( $intent_id ) {
437
+	public static function get_order_by_setup_intent_id($intent_id) {
438 438
 		global $wpdb;
439 439
 
440
-		$order_id = $wpdb->get_var( $wpdb->prepare( "SELECT DISTINCT ID FROM $wpdb->posts as posts LEFT JOIN $wpdb->postmeta as meta ON posts.ID = meta.post_id WHERE meta.meta_value = %s AND meta.meta_key = %s", $intent_id, '_stripe_setup_intent' ) );
440
+		$order_id = $wpdb->get_var($wpdb->prepare("SELECT DISTINCT ID FROM $wpdb->posts as posts LEFT JOIN $wpdb->postmeta as meta ON posts.ID = meta.post_id WHERE meta.meta_value = %s AND meta.meta_key = %s", $intent_id, '_stripe_setup_intent'));
441 441
 
442
-		if ( ! empty( $order_id ) ) {
443
-			return wc_get_order( $order_id );
442
+		if ( ! empty($order_id)) {
443
+			return wc_get_order($order_id);
444 444
 		}
445 445
 
446 446
 		return false;
@@ -456,13 +456,13 @@  discard block
 block discarded – undo
456 456
 	 * @param string $statement_descriptor
457 457
 	 * @return string $statement_descriptor Sanitized statement descriptor
458 458
 	 */
459
-	public static function clean_statement_descriptor( $statement_descriptor = '' ) {
460
-		$disallowed_characters = array( '<', '>', '"', "'", '{', '}' );
459
+	public static function clean_statement_descriptor($statement_descriptor = '') {
460
+		$disallowed_characters = array('<', '>', '"', "'", '{', '}');
461 461
 
462 462
 		// Remove special characters.
463
-		$statement_descriptor = str_replace( $disallowed_characters, '', $statement_descriptor );
463
+		$statement_descriptor = str_replace($disallowed_characters, '', $statement_descriptor);
464 464
 
465
-		$statement_descriptor = substr( trim( $statement_descriptor ), 0, 22 );
465
+		$statement_descriptor = substr(trim($statement_descriptor), 0, 22);
466 466
 
467 467
 		return $statement_descriptor;
468 468
 	}
Please login to merge, or discard this patch.