|
@@ -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,15 +17,15 @@ discard block |
|
|
block discarded – undo |
|
17
|
17
|
* |
|
18
|
18
|
* @return float|int |
|
19
|
19
|
*/ |
|
20
|
|
- public static function get_stripe_amount( $total, $currency = '' ) { |
|
21
|
|
- if ( ! $currency ) { |
|
|
20
|
+ public static function get_stripe_amount($total, $currency = '') { |
|
|
21
|
+ if ( ! $currency) { |
|
22
|
22
|
$currency = get_woocommerce_currency(); |
|
23
|
23
|
} |
|
24
|
24
|
|
|
25
|
|
- if ( in_array( strtolower( $currency ), self::no_decimal_currencies() ) ) { |
|
26
|
|
- return absint( $total ); |
|
|
25
|
+ if (in_array(strtolower($currency), self::no_decimal_currencies())) { |
|
|
26
|
+ return absint($total); |
|
27
|
27
|
} else { |
|
28
|
|
- return absint( wc_format_decimal( ( (float) $total * 100 ), wc_get_price_decimals() ) ); // In cents. |
|
|
28
|
+ return absint(wc_format_decimal(((float) $total * 100), wc_get_price_decimals())); // In cents. |
|
29
|
29
|
} |
|
30
|
30
|
} |
|
31
|
31
|
|
|
@@ -37,24 +37,24 @@ discard block |
|
|
block discarded – undo |
|
37
|
37
|
* @return array |
|
38
|
38
|
*/ |
|
39
|
39
|
public static function get_localized_messages() { |
|
40
|
|
- return apply_filters( 'wc_stripe_localized_messages', array( |
|
41
|
|
- 'invalid_number' => __( 'The card number is not a valid credit card number.', 'woocommerce-gateway-stripe' ), |
|
42
|
|
- 'invalid_expiry_month' => __( 'The card\'s expiration month is invalid.', 'woocommerce-gateway-stripe' ), |
|
43
|
|
- 'invalid_expiry_year' => __( 'The card\'s expiration year is invalid.', 'woocommerce-gateway-stripe' ), |
|
44
|
|
- 'invalid_cvc' => __( 'The card\'s security code is invalid.', 'woocommerce-gateway-stripe' ), |
|
45
|
|
- 'incorrect_number' => __( 'The card number is incorrect.', 'woocommerce-gateway-stripe' ), |
|
46
|
|
- 'incomplete_number' => __( 'The card number is incomplete.', 'woocommerce-gateway-stripe' ), |
|
47
|
|
- 'incomplete_cvc' => __( 'The card\'s security code is incomplete.', 'woocommerce-gateway-stripe' ), |
|
48
|
|
- 'incomplete_expiry' => __( 'The card\'s expiration date is incomplete.', 'woocommerce-gateway-stripe' ), |
|
49
|
|
- 'expired_card' => __( 'The card has expired.', 'woocommerce-gateway-stripe' ), |
|
50
|
|
- 'incorrect_cvc' => __( 'The card\'s security code is incorrect.', 'woocommerce-gateway-stripe' ), |
|
51
|
|
- 'incorrect_zip' => __( 'The card\'s zip code failed validation.', 'woocommerce-gateway-stripe' ), |
|
52
|
|
- 'invalid_expiry_year_past' => __( 'The card\'s expiration year is in the past', 'woocommerce-gateway-stripe' ), |
|
53
|
|
- 'card_declined' => __( 'The card was declined.', 'woocommerce-gateway-stripe' ), |
|
54
|
|
- 'missing' => __( 'There is no card on a customer that is being charged.', 'woocommerce-gateway-stripe' ), |
|
55
|
|
- 'processing_error' => __( 'An error occurred while processing the card.', 'woocommerce-gateway-stripe' ), |
|
56
|
|
- 'invalid_request_error' => __( 'Could not find payment information. Please try with another payment method.', 'woocommerce-gateway-stripe' ), |
|
57
|
|
- ) ); |
|
|
40
|
+ return apply_filters('wc_stripe_localized_messages', array( |
|
|
41
|
+ 'invalid_number' => __('The card number is not a valid credit card number.', 'woocommerce-gateway-stripe'), |
|
|
42
|
+ 'invalid_expiry_month' => __('The card\'s expiration month is invalid.', 'woocommerce-gateway-stripe'), |
|
|
43
|
+ 'invalid_expiry_year' => __('The card\'s expiration year is invalid.', 'woocommerce-gateway-stripe'), |
|
|
44
|
+ 'invalid_cvc' => __('The card\'s security code is invalid.', 'woocommerce-gateway-stripe'), |
|
|
45
|
+ 'incorrect_number' => __('The card number is incorrect.', 'woocommerce-gateway-stripe'), |
|
|
46
|
+ 'incomplete_number' => __('The card number is incomplete.', 'woocommerce-gateway-stripe'), |
|
|
47
|
+ 'incomplete_cvc' => __('The card\'s security code is incomplete.', 'woocommerce-gateway-stripe'), |
|
|
48
|
+ 'incomplete_expiry' => __('The card\'s expiration date is incomplete.', 'woocommerce-gateway-stripe'), |
|
|
49
|
+ 'expired_card' => __('The card has expired.', 'woocommerce-gateway-stripe'), |
|
|
50
|
+ 'incorrect_cvc' => __('The card\'s security code is incorrect.', 'woocommerce-gateway-stripe'), |
|
|
51
|
+ 'incorrect_zip' => __('The card\'s zip code failed validation.', 'woocommerce-gateway-stripe'), |
|
|
52
|
+ 'invalid_expiry_year_past' => __('The card\'s expiration year is in the past', 'woocommerce-gateway-stripe'), |
|
|
53
|
+ 'card_declined' => __('The card was declined.', 'woocommerce-gateway-stripe'), |
|
|
54
|
+ 'missing' => __('There is no card on a customer that is being charged.', 'woocommerce-gateway-stripe'), |
|
|
55
|
+ 'processing_error' => __('An error occurred while processing the card.', 'woocommerce-gateway-stripe'), |
|
|
56
|
+ 'invalid_request_error' => __('Could not find payment information. Please try with another payment method.', 'woocommerce-gateway-stripe'), |
|
|
57
|
+ )); |
|
58
|
58
|
} |
|
59
|
59
|
|
|
60
|
60
|
/** |
|
@@ -91,24 +91,24 @@ discard block |
|
|
block discarded – undo |
|
91
|
91
|
* @param string $type Type of number to format |
|
92
|
92
|
* @return string |
|
93
|
93
|
*/ |
|
94
|
|
- public static function format_balance_fee( $balance_transaction, $type = 'fee' ) { |
|
95
|
|
- if ( ! is_object( $balance_transaction ) ) { |
|
|
94
|
+ public static function format_balance_fee($balance_transaction, $type = 'fee') { |
|
|
95
|
+ if ( ! is_object($balance_transaction)) { |
|
96
|
96
|
return; |
|
97
|
97
|
} |
|
98
|
98
|
|
|
99
|
|
- if ( in_array( strtolower( $balance_transaction->currency ), self::no_decimal_currencies() ) ) { |
|
100
|
|
- if ( 'fee' === $type ) { |
|
|
99
|
+ if (in_array(strtolower($balance_transaction->currency), self::no_decimal_currencies())) { |
|
|
100
|
+ if ('fee' === $type) { |
|
101
|
101
|
return $balance_transaction->fee; |
|
102
|
102
|
} |
|
103
|
103
|
|
|
104
|
104
|
return $balance_transaction->net; |
|
105
|
105
|
} |
|
106
|
106
|
|
|
107
|
|
- if ( 'fee' === $type ) { |
|
108
|
|
- return number_format( $balance_transaction->fee / 100, 2, '.', '' ); |
|
|
107
|
+ if ('fee' === $type) { |
|
|
108
|
+ return number_format($balance_transaction->fee / 100, 2, '.', ''); |
|
109
|
109
|
} |
|
110
|
110
|
|
|
111
|
|
- return number_format( $balance_transaction->net / 100, 2, '.', '' ); |
|
|
111
|
+ return number_format($balance_transaction->net / 100, 2, '.', ''); |
|
112
|
112
|
} |
|
113
|
113
|
|
|
114
|
114
|
/** |
|
@@ -116,7 +116,7 @@ discard block |
|
|
block discarded – undo |
|
116
|
116
|
*/ |
|
117
|
117
|
public static function get_minimum_amount() { |
|
118
|
118
|
// Check order amount |
|
119
|
|
- switch ( get_woocommerce_currency() ) { |
|
|
119
|
+ switch (get_woocommerce_currency()) { |
|
120
|
120
|
case 'USD': |
|
121
|
121
|
case 'CAD': |
|
122
|
122
|
case 'EUR': |
|
@@ -161,14 +161,14 @@ discard block |
|
|
block discarded – undo |
|
161
|
161
|
* @param string $method The payment method to get the settings from. |
|
162
|
162
|
* @param string $setting The name of the setting to get. |
|
163
|
163
|
*/ |
|
164
|
|
- public static function get_settings( $method = null, $setting = null ) { |
|
165
|
|
- $all_settings = null === $method ? get_option( 'woocommerce_stripe_settings', array() ) : get_option( 'woocommerce_stripe_' . $method . '_settings', array() ); |
|
|
164
|
+ public static function get_settings($method = null, $setting = null) { |
|
|
165
|
+ $all_settings = null === $method ? get_option('woocommerce_stripe_settings', array()) : get_option('woocommerce_stripe_' . $method . '_settings', array()); |
|
166
|
166
|
|
|
167
|
|
- if ( null === $setting ) { |
|
|
167
|
+ if (null === $setting) { |
|
168
|
168
|
return $all_settings; |
|
169
|
169
|
} |
|
170
|
170
|
|
|
171
|
|
- return isset( $all_settings[ $setting ] ) ? $all_settings[ $setting ] : ''; |
|
|
171
|
+ return isset($all_settings[$setting]) ? $all_settings[$setting] : ''; |
|
172
|
172
|
} |
|
173
|
173
|
|
|
174
|
174
|
/** |
|
@@ -179,7 +179,7 @@ discard block |
|
|
block discarded – undo |
|
179
|
179
|
* @return bool |
|
180
|
180
|
*/ |
|
181
|
181
|
public static function is_pre_30() { |
|
182
|
|
- return version_compare( WC_VERSION, '3.0.0', '<' ); |
|
|
182
|
+ return version_compare(WC_VERSION, '3.0.0', '<'); |
|
183
|
183
|
} |
|
184
|
184
|
|
|
185
|
185
|
/** |
|
@@ -192,7 +192,7 @@ discard block |
|
|
block discarded – undo |
|
192
|
192
|
* @return string |
|
193
|
193
|
*/ |
|
194
|
194
|
public static function get_webhook_url() { |
|
195
|
|
- return add_query_arg( 'wc-api', 'wc_stripe', trailingslashit( get_home_url() ) ); |
|
|
195
|
+ return add_query_arg('wc-api', 'wc_stripe', trailingslashit(get_home_url())); |
|
196
|
196
|
} |
|
197
|
197
|
|
|
198
|
198
|
/** |
|
@@ -202,13 +202,13 @@ discard block |
|
|
block discarded – undo |
|
202
|
202
|
* @version 4.0.0 |
|
203
|
203
|
* @param string $source_id |
|
204
|
204
|
*/ |
|
205
|
|
- public static function get_order_by_source_id( $source_id ) { |
|
|
205
|
+ public static function get_order_by_source_id($source_id) { |
|
206
|
206
|
global $wpdb; |
|
207
|
207
|
|
|
208
|
|
- $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", $source_id ) ); |
|
|
208
|
+ $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", $source_id)); |
|
209
|
209
|
|
|
210
|
|
- if ( ! empty( $order_id ) ) { |
|
211
|
|
- return wc_get_order( $order_id ); |
|
|
210
|
+ if ( ! empty($order_id)) { |
|
|
211
|
+ return wc_get_order($order_id); |
|
212
|
212
|
} |
|
213
|
213
|
|
|
214
|
214
|
return false; |
|
@@ -221,13 +221,13 @@ discard block |
|
|
block discarded – undo |
|
221
|
221
|
* @version 4.0.0 |
|
222
|
222
|
* @param string $charge_id |
|
223
|
223
|
*/ |
|
224
|
|
- public static function get_order_by_charge_id( $charge_id ) { |
|
|
224
|
+ public static function get_order_by_charge_id($charge_id) { |
|
225
|
225
|
global $wpdb; |
|
226
|
226
|
|
|
227
|
|
- $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", $charge_id ) ); |
|
|
227
|
+ $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", $charge_id)); |
|
228
|
228
|
|
|
229
|
|
- if ( ! empty( $order_id ) ) { |
|
230
|
|
- return wc_get_order( $order_id ); |
|
|
229
|
+ if ( ! empty($order_id)) { |
|
|
230
|
+ return wc_get_order($order_id); |
|
231
|
231
|
} |
|
232
|
232
|
|
|
233
|
233
|
return false; |
|
@@ -243,13 +243,13 @@ discard block |
|
|
block discarded – undo |
|
243
|
243
|
* @param string $statement_descriptor |
|
244
|
244
|
* @return string $statement_descriptor Sanitized statement descriptor |
|
245
|
245
|
*/ |
|
246
|
|
- public static function clean_statement_descriptor( $statement_descriptor = '' ) { |
|
247
|
|
- $disallowed_characters = array( '<', '>', '"', "'" ); |
|
|
246
|
+ public static function clean_statement_descriptor($statement_descriptor = '') { |
|
|
247
|
+ $disallowed_characters = array('<', '>', '"', "'"); |
|
248
|
248
|
|
|
249
|
249
|
// Remove special characters. |
|
250
|
|
- $statement_descriptor = str_replace( $disallowed_characters, '', $statement_descriptor ); |
|
|
250
|
+ $statement_descriptor = str_replace($disallowed_characters, '', $statement_descriptor); |
|
251
|
251
|
|
|
252
|
|
- $statement_descriptor = substr( trim( $statement_descriptor ), 0, 22 ); |
|
|
252
|
+ $statement_descriptor = substr(trim($statement_descriptor), 0, 22); |
|
253
|
253
|
|
|
254
|
254
|
return $statement_descriptor; |
|
255
|
255
|
} |