@@ -1,10 +1,10 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if ( ! defined('ABSPATH')) { |
|
3 | 3 | exit; // Exit if accessed directly |
4 | 4 | } |
5 | 5 | |
6 | 6 | // if uninstall not called from WordPress exit |
7 | -if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) { |
|
7 | +if ( ! defined('WP_UNINSTALL_PLUGIN')) { |
|
8 | 8 | exit; |
9 | 9 | } |
10 | 10 | |
@@ -13,20 +13,20 @@ discard block |
||
13 | 13 | * wp-config.php. This is to prevent data loss when deleting the plugin from the backend |
14 | 14 | * and to ensure only the site owner can perform this action. |
15 | 15 | */ |
16 | -if ( defined( 'WC_REMOVE_ALL_DATA' ) && true === WC_REMOVE_ALL_DATA ) { |
|
16 | +if (defined('WC_REMOVE_ALL_DATA') && true === WC_REMOVE_ALL_DATA) { |
|
17 | 17 | // Delete options. |
18 | - delete_option( 'woocommerce_stripe_settings' ); |
|
19 | - delete_option( 'wc_stripe_show_request_api_notice' ); |
|
20 | - delete_option( 'wc_stripe_show_apple_pay_notice' ); |
|
21 | - delete_option( 'wc_stripe_show_ssl_notice' ); |
|
22 | - delete_option( 'wc_stripe_show_keys_notice' ); |
|
23 | - delete_option( 'wc_stripe_version' ); |
|
24 | - delete_option( 'woocommerce_stripe_bancontact_settings' ); |
|
25 | - delete_option( 'woocommerce_stripe_alipay_settings' ); |
|
26 | - delete_option( 'woocommerce_stripe_bitcoin_settings' ); |
|
27 | - delete_option( 'woocommerce_stripe_ideal_settings' ); |
|
28 | - delete_option( 'woocommerce_stripe_p24_settings' ); |
|
29 | - delete_option( 'woocommerce_stripe_giropay_settings' ); |
|
30 | - delete_option( 'woocommerce_stripe_sepa_settings' ); |
|
31 | - delete_option( 'woocommerce_stripe_sofort_settings' ); |
|
18 | + delete_option('woocommerce_stripe_settings'); |
|
19 | + delete_option('wc_stripe_show_request_api_notice'); |
|
20 | + delete_option('wc_stripe_show_apple_pay_notice'); |
|
21 | + delete_option('wc_stripe_show_ssl_notice'); |
|
22 | + delete_option('wc_stripe_show_keys_notice'); |
|
23 | + delete_option('wc_stripe_version'); |
|
24 | + delete_option('woocommerce_stripe_bancontact_settings'); |
|
25 | + delete_option('woocommerce_stripe_alipay_settings'); |
|
26 | + delete_option('woocommerce_stripe_bitcoin_settings'); |
|
27 | + delete_option('woocommerce_stripe_ideal_settings'); |
|
28 | + delete_option('woocommerce_stripe_p24_settings'); |
|
29 | + delete_option('woocommerce_stripe_giropay_settings'); |
|
30 | + delete_option('woocommerce_stripe_sepa_settings'); |
|
31 | + delete_option('woocommerce_stripe_sofort_settings'); |
|
32 | 32 | } |
@@ -7,7 +7,7 @@ discard block |
||
7 | 7 | * @since 4.0.2 |
8 | 8 | */ |
9 | 9 | |
10 | -if ( ! defined( 'ABSPATH' ) ) { |
|
10 | +if ( ! defined('ABSPATH')) { |
|
11 | 11 | exit; // Exit if accessed directly |
12 | 12 | } |
13 | 13 | |
@@ -23,9 +23,9 @@ discard block |
||
23 | 23 | * @param string $error_message Full response |
24 | 24 | * @param string $localized_message user-friendly translated error message |
25 | 25 | */ |
26 | - public function __construct( $error_message = '', $localized_message = '' ) { |
|
26 | + public function __construct($error_message = '', $localized_message = '') { |
|
27 | 27 | $this->localized_message = $localized_message; |
28 | - parent::__construct( $error_message ); |
|
28 | + parent::__construct($error_message); |
|
29 | 29 | } |
30 | 30 | |
31 | 31 | /** |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if ( ! defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | 5 | |
@@ -17,15 +17,15 @@ discard block |
||
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,25 +37,25 @@ discard block |
||
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' => __( 'Unable to process this payment, please try again or use alternative method.', 'woocommerce-gateway-stripe' ), |
|
57 | - 'invalid_sofort_country' => __( 'The billing country is not accepted by SOFORT. Please try another country.', 'woocommerce-gateway-stripe' ), |
|
58 | - ) ); |
|
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' => __('Unable to process this payment, please try again or use alternative method.', 'woocommerce-gateway-stripe'), |
|
57 | + 'invalid_sofort_country' => __('The billing country is not accepted by SOFORT. Please try another country.', 'woocommerce-gateway-stripe'), |
|
58 | + )); |
|
59 | 59 | } |
60 | 60 | |
61 | 61 | /** |
@@ -92,24 +92,24 @@ discard block |
||
92 | 92 | * @param string $type Type of number to format |
93 | 93 | * @return string |
94 | 94 | */ |
95 | - public static function format_balance_fee( $balance_transaction, $type = 'fee' ) { |
|
96 | - if ( ! is_object( $balance_transaction ) ) { |
|
95 | + public static function format_balance_fee($balance_transaction, $type = 'fee') { |
|
96 | + if ( ! is_object($balance_transaction)) { |
|
97 | 97 | return; |
98 | 98 | } |
99 | 99 | |
100 | - if ( in_array( strtolower( $balance_transaction->currency ), self::no_decimal_currencies() ) ) { |
|
101 | - if ( 'fee' === $type ) { |
|
100 | + if (in_array(strtolower($balance_transaction->currency), self::no_decimal_currencies())) { |
|
101 | + if ('fee' === $type) { |
|
102 | 102 | return $balance_transaction->fee; |
103 | 103 | } |
104 | 104 | |
105 | 105 | return $balance_transaction->net; |
106 | 106 | } |
107 | 107 | |
108 | - if ( 'fee' === $type ) { |
|
109 | - return number_format( $balance_transaction->fee / 100, 2, '.', '' ); |
|
108 | + if ('fee' === $type) { |
|
109 | + return number_format($balance_transaction->fee / 100, 2, '.', ''); |
|
110 | 110 | } |
111 | 111 | |
112 | - return number_format( $balance_transaction->net / 100, 2, '.', '' ); |
|
112 | + return number_format($balance_transaction->net / 100, 2, '.', ''); |
|
113 | 113 | } |
114 | 114 | |
115 | 115 | /** |
@@ -117,7 +117,7 @@ discard block |
||
117 | 117 | */ |
118 | 118 | public static function get_minimum_amount() { |
119 | 119 | // Check order amount |
120 | - switch ( get_woocommerce_currency() ) { |
|
120 | + switch (get_woocommerce_currency()) { |
|
121 | 121 | case 'USD': |
122 | 122 | case 'CAD': |
123 | 123 | case 'EUR': |
@@ -162,14 +162,14 @@ discard block |
||
162 | 162 | * @param string $method The payment method to get the settings from. |
163 | 163 | * @param string $setting The name of the setting to get. |
164 | 164 | */ |
165 | - public static function get_settings( $method = null, $setting = null ) { |
|
166 | - $all_settings = null === $method ? get_option( 'woocommerce_stripe_settings', array() ) : get_option( 'woocommerce_stripe_' . $method . '_settings', array() ); |
|
165 | + public static function get_settings($method = null, $setting = null) { |
|
166 | + $all_settings = null === $method ? get_option('woocommerce_stripe_settings', array()) : get_option('woocommerce_stripe_' . $method . '_settings', array()); |
|
167 | 167 | |
168 | - if ( null === $setting ) { |
|
168 | + if (null === $setting) { |
|
169 | 169 | return $all_settings; |
170 | 170 | } |
171 | 171 | |
172 | - return isset( $all_settings[ $setting ] ) ? $all_settings[ $setting ] : ''; |
|
172 | + return isset($all_settings[$setting]) ? $all_settings[$setting] : ''; |
|
173 | 173 | } |
174 | 174 | |
175 | 175 | /** |
@@ -180,7 +180,7 @@ discard block |
||
180 | 180 | * @return bool |
181 | 181 | */ |
182 | 182 | public static function is_pre_30() { |
183 | - return version_compare( WC_VERSION, '3.0.0', '<' ); |
|
183 | + return version_compare(WC_VERSION, '3.0.0', '<'); |
|
184 | 184 | } |
185 | 185 | |
186 | 186 | /** |
@@ -193,7 +193,7 @@ discard block |
||
193 | 193 | * @return string |
194 | 194 | */ |
195 | 195 | public static function get_webhook_url() { |
196 | - return add_query_arg( 'wc-api', 'wc_stripe', trailingslashit( get_home_url() ) ); |
|
196 | + return add_query_arg('wc-api', 'wc_stripe', trailingslashit(get_home_url())); |
|
197 | 197 | } |
198 | 198 | |
199 | 199 | /** |
@@ -203,13 +203,13 @@ discard block |
||
203 | 203 | * @version 4.0.0 |
204 | 204 | * @param string $source_id |
205 | 205 | */ |
206 | - public static function get_order_by_source_id( $source_id ) { |
|
206 | + public static function get_order_by_source_id($source_id) { |
|
207 | 207 | global $wpdb; |
208 | 208 | |
209 | - $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 | + $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)); |
|
210 | 210 | |
211 | - if ( ! empty( $order_id ) ) { |
|
212 | - return wc_get_order( $order_id ); |
|
211 | + if ( ! empty($order_id)) { |
|
212 | + return wc_get_order($order_id); |
|
213 | 213 | } |
214 | 214 | |
215 | 215 | return false; |
@@ -222,13 +222,13 @@ discard block |
||
222 | 222 | * @version 4.0.0 |
223 | 223 | * @param string $charge_id |
224 | 224 | */ |
225 | - public static function get_order_by_charge_id( $charge_id ) { |
|
225 | + public static function get_order_by_charge_id($charge_id) { |
|
226 | 226 | global $wpdb; |
227 | 227 | |
228 | - $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 | + $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)); |
|
229 | 229 | |
230 | - if ( ! empty( $order_id ) ) { |
|
231 | - return wc_get_order( $order_id ); |
|
230 | + if ( ! empty($order_id)) { |
|
231 | + return wc_get_order($order_id); |
|
232 | 232 | } |
233 | 233 | |
234 | 234 | return false; |
@@ -244,13 +244,13 @@ discard block |
||
244 | 244 | * @param string $statement_descriptor |
245 | 245 | * @return string $statement_descriptor Sanitized statement descriptor |
246 | 246 | */ |
247 | - public static function clean_statement_descriptor( $statement_descriptor = '' ) { |
|
248 | - $disallowed_characters = array( '<', '>', '"', "'" ); |
|
247 | + public static function clean_statement_descriptor($statement_descriptor = '') { |
|
248 | + $disallowed_characters = array('<', '>', '"', "'"); |
|
249 | 249 | |
250 | 250 | // Remove special characters. |
251 | - $statement_descriptor = str_replace( $disallowed_characters, '', $statement_descriptor ); |
|
251 | + $statement_descriptor = str_replace($disallowed_characters, '', $statement_descriptor); |
|
252 | 252 | |
253 | - $statement_descriptor = substr( trim( $statement_descriptor ), 0, 22 ); |
|
253 | + $statement_descriptor = substr(trim($statement_descriptor), 0, 22); |
|
254 | 254 | |
255 | 255 | return $statement_descriptor; |
256 | 256 | } |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if ( ! defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | 5 | |
@@ -57,9 +57,9 @@ discard block |
||
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§ion=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§ion=stripe')); |
|
63 | 63 | $this->supports = array( |
64 | 64 | 'products', |
65 | 65 | 'refunds', |
@@ -71,25 +71,25 @@ discard block |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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( apply_filters( 'wc_stripe_p24_source', $post_data, $order ), 'sources' ); |
|
258 | + return WC_Stripe_API::request(apply_filters('wc_stripe_p24_source', $post_data, $order), 'sources'); |
|
259 | 259 | } |
260 | 260 | |
261 | 261 | /** |
@@ -269,51 +269,51 @@ discard block |
||
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 WC_Stripe_Exception( print_r( $response, true ), $response->error->message ); |
|
293 | + throw new WC_Stripe_Exception(print_r($response, true), $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 ( WC_Stripe_Exception $e ) { |
|
310 | - wc_add_notice( $e->getLocalizedMessage(), 'error' ); |
|
311 | - WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() ); |
|
309 | + } catch (WC_Stripe_Exception $e) { |
|
310 | + wc_add_notice($e->getLocalizedMessage(), '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( |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if ( ! defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | 5 | |
@@ -57,9 +57,9 @@ discard block |
||
57 | 57 | */ |
58 | 58 | public function __construct() { |
59 | 59 | $this->id = 'stripe_alipay'; |
60 | - $this->method_title = __( 'Stripe Alipay', 'woocommerce-gateway-stripe' ); |
|
60 | + $this->method_title = __('Stripe Alipay', 'woocommerce-gateway-stripe'); |
|
61 | 61 | /* translators: link */ |
62 | - $this->method_description = sprintf( __( 'All other general Stripe settings can be adjusted <a href="%s">here</a>.', 'woocommerce-gateway-stripe' ), admin_url( 'admin.php?page=wc-settings&tab=checkout§ion=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§ion=stripe')); |
|
63 | 63 | $this->supports = array( |
64 | 64 | 'products', |
65 | 65 | 'refunds', |
@@ -71,25 +71,25 @@ discard block |
||
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 |
||
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 | } |
@@ -125,10 +125,10 @@ discard block |
||
125 | 125 | */ |
126 | 126 | public function get_environment_warning() { |
127 | 127 | if ( |
128 | - 'yes' === $this->enabled && ! in_array( get_woocommerce_currency(), $this->get_supported_currency() ) |
|
128 | + 'yes' === $this->enabled && ! in_array(get_woocommerce_currency(), $this->get_supported_currency()) |
|
129 | 129 | ) { |
130 | 130 | /* translators: supported currency list */ |
131 | - $message = sprintf( __( 'Alipay is enabled - it requires store currency to be set to %s', 'woocommerce-gateway-stripe' ), implode( ', ', $this->get_supported_currency() ) ); |
|
131 | + $message = sprintf(__('Alipay is enabled - it requires store currency to be set to %s', 'woocommerce-gateway-stripe'), implode(', ', $this->get_supported_currency())); |
|
132 | 132 | |
133 | 133 | return $message; |
134 | 134 | } |
@@ -144,7 +144,7 @@ discard block |
||
144 | 144 | * @return array |
145 | 145 | */ |
146 | 146 | public function get_supported_currency() { |
147 | - return apply_filters( 'wc_stripe_alipay_supported_currencies', array( |
|
147 | + return apply_filters('wc_stripe_alipay_supported_currencies', array( |
|
148 | 148 | 'EUR', |
149 | 149 | 'AUD', |
150 | 150 | 'CAD', |
@@ -154,7 +154,7 @@ discard block |
||
154 | 154 | 'NZD', |
155 | 155 | 'SGD', |
156 | 156 | 'USD', |
157 | - ) ); |
|
157 | + )); |
|
158 | 158 | } |
159 | 159 | |
160 | 160 | /** |
@@ -165,7 +165,7 @@ discard block |
||
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 |
||
186 | 186 | |
187 | 187 | $icons_str .= $icons['alipay']; |
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 | /** |
@@ -196,19 +196,19 @@ discard block |
||
196 | 196 | * @version 4.0.0 |
197 | 197 | */ |
198 | 198 | public function payment_scripts() { |
199 | - if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) && ! is_add_payment_method_page() ) { |
|
199 | + if ( ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order']) && ! is_add_payment_method_page()) { |
|
200 | 200 | return; |
201 | 201 | } |
202 | 202 | |
203 | - wp_enqueue_style( 'stripe_paymentfonts' ); |
|
204 | - wp_enqueue_script( 'woocommerce_stripe' ); |
|
203 | + wp_enqueue_style('stripe_paymentfonts'); |
|
204 | + wp_enqueue_script('woocommerce_stripe'); |
|
205 | 205 | } |
206 | 206 | |
207 | 207 | /** |
208 | 208 | * Initialize Gateway Settings Form Fields. |
209 | 209 | */ |
210 | 210 | public function init_form_fields() { |
211 | - $this->form_fields = require( WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-alipay-settings.php' ); |
|
211 | + $this->form_fields = require(WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-alipay-settings.php'); |
|
212 | 212 | } |
213 | 213 | |
214 | 214 | /** |
@@ -219,25 +219,25 @@ discard block |
||
219 | 219 | $total = WC()->cart->total; |
220 | 220 | |
221 | 221 | // If paying from order, we need to get total from order not cart. |
222 | - if ( isset( $_GET['pay_for_order'] ) && ! empty( $_GET['key'] ) ) { |
|
223 | - $order = wc_get_order( wc_get_order_id_by_order_key( wc_clean( $_GET['key'] ) ) ); |
|
222 | + if (isset($_GET['pay_for_order']) && ! empty($_GET['key'])) { |
|
223 | + $order = wc_get_order(wc_get_order_id_by_order_key(wc_clean($_GET['key']))); |
|
224 | 224 | $total = $order->get_total(); |
225 | 225 | } |
226 | 226 | |
227 | - if ( is_add_payment_method_page() ) { |
|
228 | - $pay_button_text = __( 'Add Payment', 'woocommerce-gateway-stripe' ); |
|
229 | - $total = ''; |
|
227 | + if (is_add_payment_method_page()) { |
|
228 | + $pay_button_text = __('Add Payment', 'woocommerce-gateway-stripe'); |
|
229 | + $total = ''; |
|
230 | 230 | } else { |
231 | 231 | $pay_button_text = ''; |
232 | 232 | } |
233 | 233 | |
234 | 234 | echo '<div |
235 | 235 | id="stripe-alipay-payment-data" |
236 | - data-amount="' . esc_attr( WC_Stripe_Helper::get_stripe_amount( $total ) ) . '" |
|
237 | - data-currency="' . esc_attr( strtolower( get_woocommerce_currency() ) ) . '">'; |
|
236 | + data-amount="' . esc_attr(WC_Stripe_Helper::get_stripe_amount($total)) . '" |
|
237 | + data-currency="' . esc_attr(strtolower(get_woocommerce_currency())) . '">'; |
|
238 | 238 | |
239 | - if ( $this->description ) { |
|
240 | - echo apply_filters( 'wc_stripe_description', wpautop( wp_kses_post( $this->description ) ) ); |
|
239 | + if ($this->description) { |
|
240 | + echo apply_filters('wc_stripe_description', wpautop(wp_kses_post($this->description))); |
|
241 | 241 | } |
242 | 242 | |
243 | 243 | echo '</div>'; |
@@ -251,24 +251,24 @@ discard block |
||
251 | 251 | * @param object $order |
252 | 252 | * @return mixed |
253 | 253 | */ |
254 | - public function create_source( $order ) { |
|
254 | + public function create_source($order) { |
|
255 | 255 | $currency = WC_Stripe_Helper::is_pre_30() ? $order->get_order_currency() : $order->get_currency(); |
256 | 256 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
257 | - $return_url = $this->get_stripe_return_url( $order ); |
|
257 | + $return_url = $this->get_stripe_return_url($order); |
|
258 | 258 | $post_data = array(); |
259 | - $post_data['amount'] = WC_Stripe_Helper::get_stripe_amount( $order->get_total(), $currency ); |
|
260 | - $post_data['currency'] = strtolower( $currency ); |
|
259 | + $post_data['amount'] = WC_Stripe_Helper::get_stripe_amount($order->get_total(), $currency); |
|
260 | + $post_data['currency'] = strtolower($currency); |
|
261 | 261 | $post_data['type'] = 'alipay'; |
262 | - $post_data['owner'] = $this->get_owner_details( $order ); |
|
263 | - $post_data['redirect'] = array( 'return_url' => $return_url ); |
|
262 | + $post_data['owner'] = $this->get_owner_details($order); |
|
263 | + $post_data['redirect'] = array('return_url' => $return_url); |
|
264 | 264 | |
265 | - if ( ! empty( $this->statement_descriptor ) ) { |
|
266 | - $post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor( $this->statement_descriptor ); |
|
265 | + if ( ! empty($this->statement_descriptor)) { |
|
266 | + $post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor($this->statement_descriptor); |
|
267 | 267 | } |
268 | 268 | |
269 | - WC_Stripe_Logger::log( 'Info: Begin creating Alipay source' ); |
|
269 | + WC_Stripe_Logger::log('Info: Begin creating Alipay source'); |
|
270 | 270 | |
271 | - return WC_Stripe_API::request( apply_filters( 'wc_stripe_alipay_source', $post_data, $order ), 'sources' ); |
|
271 | + return WC_Stripe_API::request(apply_filters('wc_stripe_alipay_source', $post_data, $order), 'sources'); |
|
272 | 272 | } |
273 | 273 | |
274 | 274 | /** |
@@ -282,53 +282,53 @@ discard block |
||
282 | 282 | * |
283 | 283 | * @return array|void |
284 | 284 | */ |
285 | - public function process_payment( $order_id, $retry = true, $force_save_save = false ) { |
|
285 | + public function process_payment($order_id, $retry = true, $force_save_save = false) { |
|
286 | 286 | try { |
287 | - $order = wc_get_order( $order_id ); |
|
287 | + $order = wc_get_order($order_id); |
|
288 | 288 | |
289 | 289 | // This will throw exception if not valid. |
290 | - $this->validate_minimum_order_amount( $order ); |
|
290 | + $this->validate_minimum_order_amount($order); |
|
291 | 291 | |
292 | 292 | // This comes from the create account checkbox in the checkout page. |
293 | - $create_account = ! empty( $_POST['createaccount'] ) ? true : false; |
|
293 | + $create_account = ! empty($_POST['createaccount']) ? true : false; |
|
294 | 294 | |
295 | - if ( $create_account ) { |
|
295 | + if ($create_account) { |
|
296 | 296 | $new_customer_id = WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id(); |
297 | - $new_stripe_customer = new WC_Stripe_Customer( $new_customer_id ); |
|
297 | + $new_stripe_customer = new WC_Stripe_Customer($new_customer_id); |
|
298 | 298 | $new_stripe_customer->create_customer(); |
299 | 299 | } |
300 | 300 | |
301 | - $response = $this->create_source( $order ); |
|
301 | + $response = $this->create_source($order); |
|
302 | 302 | |
303 | - if ( ! empty( $response->error ) ) { |
|
304 | - $order->add_order_note( $response->error->message ); |
|
303 | + if ( ! empty($response->error)) { |
|
304 | + $order->add_order_note($response->error->message); |
|
305 | 305 | |
306 | - throw new WC_Stripe_Exception( print_r( $response, true ), $response->error->message ); |
|
306 | + throw new WC_Stripe_Exception(print_r($response, true), $response->error->message); |
|
307 | 307 | } |
308 | 308 | |
309 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
310 | - update_post_meta( $order_id, '_stripe_source_id', $response->id ); |
|
309 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
310 | + update_post_meta($order_id, '_stripe_source_id', $response->id); |
|
311 | 311 | } else { |
312 | - $order->update_meta_data( '_stripe_source_id', $response->id ); |
|
312 | + $order->update_meta_data('_stripe_source_id', $response->id); |
|
313 | 313 | $order->save(); |
314 | 314 | } |
315 | 315 | |
316 | - WC_Stripe_Logger::log( 'Info: Redirecting to Alipay...' ); |
|
316 | + WC_Stripe_Logger::log('Info: Redirecting to Alipay...'); |
|
317 | 317 | |
318 | 318 | return array( |
319 | 319 | 'result' => 'success', |
320 | - 'redirect' => esc_url_raw( $response->redirect->url ), |
|
320 | + 'redirect' => esc_url_raw($response->redirect->url), |
|
321 | 321 | ); |
322 | - } catch ( WC_Stripe_Exception $e ) { |
|
323 | - wc_add_notice( $e->getLocalizedMessage(), 'error' ); |
|
324 | - WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() ); |
|
322 | + } catch (WC_Stripe_Exception $e) { |
|
323 | + wc_add_notice($e->getLocalizedMessage(), 'error'); |
|
324 | + WC_Stripe_Logger::log('Error: ' . $e->getMessage()); |
|
325 | 325 | |
326 | - do_action( 'wc_gateway_stripe_process_payment_error', $e, $order ); |
|
326 | + do_action('wc_gateway_stripe_process_payment_error', $e, $order); |
|
327 | 327 | |
328 | - $statuses = array( 'pending', 'failed' ); |
|
328 | + $statuses = array('pending', 'failed'); |
|
329 | 329 | |
330 | - if ( $order->has_status( $statuses ) ) { |
|
331 | - $this->send_failed_order_email( $order_id ); |
|
330 | + if ($order->has_status($statuses)) { |
|
331 | + $this->send_failed_order_email($order_id); |
|
332 | 332 | } |
333 | 333 | |
334 | 334 | return array( |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if ( ! defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | 5 | |
@@ -57,9 +57,9 @@ discard block |
||
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§ion=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§ion=stripe')); |
|
63 | 63 | $this->supports = array( |
64 | 64 | 'products', |
65 | 65 | 'refunds', |
@@ -71,25 +71,25 @@ discard block |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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( apply_filters( 'wc_stripe_giropay_source', $post_data, $order ), 'sources' ); |
|
261 | + return WC_Stripe_API::request(apply_filters('wc_stripe_giropay_source', $post_data, $order), 'sources'); |
|
262 | 262 | } |
263 | 263 | |
264 | 264 | /** |
@@ -272,51 +272,51 @@ discard block |
||
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 WC_Stripe_Exception( print_r( $response, true ), $response->error->message ); |
|
296 | + throw new WC_Stripe_Exception(print_r($response, true), $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 ( WC_Stripe_Exception $e ) { |
|
313 | - wc_add_notice( $e->getLocalizedMessage(), 'error' ); |
|
314 | - WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() ); |
|
312 | + } catch (WC_Stripe_Exception $e) { |
|
313 | + wc_add_notice($e->getLocalizedMessage(), '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( |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if ( ! defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | 5 | |
@@ -57,9 +57,9 @@ discard block |
||
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§ion=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§ion=stripe')); |
|
63 | 63 | $this->supports = array( |
64 | 64 | 'products', |
65 | 65 | 'refunds', |
@@ -71,25 +71,25 @@ discard block |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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( apply_filters( 'wc_stripe_ideal_source', $post_data, $order ), 'sources' ); |
|
261 | + return WC_Stripe_API::request(apply_filters('wc_stripe_ideal_source', $post_data, $order), 'sources'); |
|
262 | 262 | } |
263 | 263 | |
264 | 264 | /** |
@@ -272,51 +272,51 @@ discard block |
||
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 WC_Stripe_Exception( print_r( $response, true ), $response->error->message ); |
|
296 | + throw new WC_Stripe_Exception(print_r($response, true), $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 ( WC_Stripe_Exception $e ) { |
|
313 | - wc_add_notice( $e->getLocalizedMessage(), 'error' ); |
|
314 | - WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() ); |
|
312 | + } catch (WC_Stripe_Exception $e) { |
|
313 | + wc_add_notice($e->getLocalizedMessage(), '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( |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if ( ! defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | 5 | |
@@ -32,10 +32,10 @@ discard block |
||
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 |
||
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 |
||
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 |
||
76 | 76 | * @return WP_User |
77 | 77 | */ |
78 | 78 | protected function get_user() { |
79 | - return $this->get_user_id() ? get_user_by( 'id', $this->get_user_id() ) : false; |
|
79 | + return $this->get_user_id() ? get_user_by('id', $this->get_user_id()) : false; |
|
80 | 80 | } |
81 | 81 | |
82 | 82 | /** |
83 | 83 | * Store data from the Stripe API about this customer |
84 | 84 | */ |
85 | - public function set_customer_data( $data ) { |
|
85 | + public function set_customer_data($data) { |
|
86 | 86 | $this->customer_data = $data; |
87 | 87 | } |
88 | 88 | |
@@ -91,13 +91,13 @@ discard block |
||
91 | 91 | * @param array $args |
92 | 92 | * @return WP_Error|int |
93 | 93 | */ |
94 | - public function create_customer( $args = array() ) { |
|
95 | - $billing_email = isset( $_POST['billing_email'] ) ? filter_var( $_POST['billing_email'], FILTER_SANITIZE_EMAIL ) : ''; |
|
94 | + public function create_customer($args = array()) { |
|
95 | + $billing_email = isset($_POST['billing_email']) ? filter_var($_POST['billing_email'], FILTER_SANITIZE_EMAIL) : ''; |
|
96 | 96 | $user = $this->get_user(); |
97 | 97 | |
98 | - if ( $user ) { |
|
99 | - $billing_first_name = get_user_meta( $user->ID, 'billing_first_name', true ); |
|
100 | - $billing_last_name = get_user_meta( $user->ID, 'billing_last_name', true ); |
|
98 | + if ($user) { |
|
99 | + $billing_first_name = get_user_meta($user->ID, 'billing_first_name', true); |
|
100 | + $billing_last_name = get_user_meta($user->ID, 'billing_last_name', true); |
|
101 | 101 | |
102 | 102 | $defaults = array( |
103 | 103 | 'email' => $user->user_email, |
@@ -112,24 +112,24 @@ discard block |
||
112 | 112 | |
113 | 113 | $metadata = array(); |
114 | 114 | |
115 | - $defaults['metadata'] = apply_filters( 'wc_stripe_customer_metadata', $metadata, $user ); |
|
115 | + $defaults['metadata'] = apply_filters('wc_stripe_customer_metadata', $metadata, $user); |
|
116 | 116 | |
117 | - $args = wp_parse_args( $args, $defaults ); |
|
118 | - $response = WC_Stripe_API::request( apply_filters( 'wc_stripe_create_customer_args', $args ), 'customers' ); |
|
117 | + $args = wp_parse_args($args, $defaults); |
|
118 | + $response = WC_Stripe_API::request(apply_filters('wc_stripe_create_customer_args', $args), 'customers'); |
|
119 | 119 | |
120 | - if ( ! empty( $response->error ) ) { |
|
121 | - throw new WC_Stripe_Exception( print_r( $response, true ), $response->error->message ); |
|
120 | + if ( ! empty($response->error)) { |
|
121 | + throw new WC_Stripe_Exception(print_r($response, true), $response->error->message); |
|
122 | 122 | } |
123 | 123 | |
124 | - $this->set_id( $response->id ); |
|
124 | + $this->set_id($response->id); |
|
125 | 125 | $this->clear_cache(); |
126 | - $this->set_customer_data( $response ); |
|
126 | + $this->set_customer_data($response); |
|
127 | 127 | |
128 | - if ( $this->get_user_id() ) { |
|
129 | - update_user_meta( $this->get_user_id(), '_stripe_customer_id', $response->id ); |
|
128 | + if ($this->get_user_id()) { |
|
129 | + update_user_meta($this->get_user_id(), '_stripe_customer_id', $response->id); |
|
130 | 130 | } |
131 | 131 | |
132 | - do_action( 'woocommerce_stripe_add_customer', $args, $response ); |
|
132 | + do_action('woocommerce_stripe_add_customer', $args, $response); |
|
133 | 133 | |
134 | 134 | return $response->id; |
135 | 135 | } |
@@ -140,72 +140,72 @@ discard block |
||
140 | 140 | * @param bool $retry |
141 | 141 | * @return WP_Error|int |
142 | 142 | */ |
143 | - public function add_source( $source_id, $retry = true ) { |
|
144 | - if ( ! $this->get_id() ) { |
|
145 | - $this->set_id( $this->create_customer() ); |
|
143 | + public function add_source($source_id, $retry = true) { |
|
144 | + if ( ! $this->get_id()) { |
|
145 | + $this->set_id($this->create_customer()); |
|
146 | 146 | } |
147 | 147 | |
148 | - $response = WC_Stripe_API::request( array( |
|
148 | + $response = WC_Stripe_API::request(array( |
|
149 | 149 | 'source' => $source_id, |
150 | - ), 'customers/' . $this->get_id() . '/sources' ); |
|
150 | + ), 'customers/' . $this->get_id() . '/sources'); |
|
151 | 151 | |
152 | - if ( ! empty( $response->error ) ) { |
|
152 | + if ( ! empty($response->error)) { |
|
153 | 153 | // It is possible the WC user once was linked to a customer on Stripe |
154 | 154 | // but no longer exists. Instead of failing, lets try to create a |
155 | 155 | // new customer. |
156 | - if ( preg_match( '/No such customer/i', $response->error->message ) ) { |
|
157 | - delete_user_meta( $this->get_user_id(), '_stripe_customer_id' ); |
|
156 | + if (preg_match('/No such customer/i', $response->error->message)) { |
|
157 | + delete_user_meta($this->get_user_id(), '_stripe_customer_id'); |
|
158 | 158 | $this->create_customer(); |
159 | - return $this->add_source( $source_id, false ); |
|
159 | + return $this->add_source($source_id, false); |
|
160 | 160 | } else { |
161 | 161 | return $response; |
162 | 162 | } |
163 | - } elseif ( empty( $response->id ) ) { |
|
164 | - return new WP_Error( 'error', __( 'Unable to add payment source.', 'woocommerce-gateway-stripe' ) ); |
|
163 | + } elseif (empty($response->id)) { |
|
164 | + return new WP_Error('error', __('Unable to add payment source.', 'woocommerce-gateway-stripe')); |
|
165 | 165 | } |
166 | 166 | |
167 | 167 | // Add token to WooCommerce. |
168 | - if ( $this->get_user_id() && class_exists( 'WC_Payment_Token_CC' ) ) { |
|
169 | - if ( ! empty( $response->type ) ) { |
|
170 | - switch ( $response->type ) { |
|
168 | + if ($this->get_user_id() && class_exists('WC_Payment_Token_CC')) { |
|
169 | + if ( ! empty($response->type)) { |
|
170 | + switch ($response->type) { |
|
171 | 171 | case 'alipay': |
172 | 172 | break; |
173 | 173 | case 'sepa_debit': |
174 | 174 | $wc_token = new WC_Payment_Token_SEPA(); |
175 | - $wc_token->set_token( $response->id ); |
|
176 | - $wc_token->set_gateway_id( 'stripe_sepa' ); |
|
177 | - $wc_token->set_last4( $response->sepa_debit->last4 ); |
|
175 | + $wc_token->set_token($response->id); |
|
176 | + $wc_token->set_gateway_id('stripe_sepa'); |
|
177 | + $wc_token->set_last4($response->sepa_debit->last4); |
|
178 | 178 | break; |
179 | 179 | default: |
180 | - if ( 'source' === $response->object && 'card' === $response->type ) { |
|
180 | + if ('source' === $response->object && 'card' === $response->type) { |
|
181 | 181 | $wc_token = new WC_Payment_Token_CC(); |
182 | - $wc_token->set_token( $response->id ); |
|
183 | - $wc_token->set_gateway_id( 'stripe' ); |
|
184 | - $wc_token->set_card_type( strtolower( $response->card->brand ) ); |
|
185 | - $wc_token->set_last4( $response->card->last4 ); |
|
186 | - $wc_token->set_expiry_month( $response->card->exp_month ); |
|
187 | - $wc_token->set_expiry_year( $response->card->exp_year ); |
|
182 | + $wc_token->set_token($response->id); |
|
183 | + $wc_token->set_gateway_id('stripe'); |
|
184 | + $wc_token->set_card_type(strtolower($response->card->brand)); |
|
185 | + $wc_token->set_last4($response->card->last4); |
|
186 | + $wc_token->set_expiry_month($response->card->exp_month); |
|
187 | + $wc_token->set_expiry_year($response->card->exp_year); |
|
188 | 188 | } |
189 | 189 | break; |
190 | 190 | } |
191 | 191 | } else { |
192 | 192 | // Legacy. |
193 | 193 | $wc_token = new WC_Payment_Token_CC(); |
194 | - $wc_token->set_token( $response->id ); |
|
195 | - $wc_token->set_gateway_id( 'stripe' ); |
|
196 | - $wc_token->set_card_type( strtolower( $response->brand ) ); |
|
197 | - $wc_token->set_last4( $response->last4 ); |
|
198 | - $wc_token->set_expiry_month( $response->exp_month ); |
|
199 | - $wc_token->set_expiry_year( $response->exp_year ); |
|
194 | + $wc_token->set_token($response->id); |
|
195 | + $wc_token->set_gateway_id('stripe'); |
|
196 | + $wc_token->set_card_type(strtolower($response->brand)); |
|
197 | + $wc_token->set_last4($response->last4); |
|
198 | + $wc_token->set_expiry_month($response->exp_month); |
|
199 | + $wc_token->set_expiry_year($response->exp_year); |
|
200 | 200 | } |
201 | 201 | |
202 | - $wc_token->set_user_id( $this->get_user_id() ); |
|
202 | + $wc_token->set_user_id($this->get_user_id()); |
|
203 | 203 | $wc_token->save(); |
204 | 204 | } |
205 | 205 | |
206 | 206 | $this->clear_cache(); |
207 | 207 | |
208 | - do_action( 'woocommerce_stripe_add_source', $this->get_id(), $wc_token, $response, $source_id ); |
|
208 | + do_action('woocommerce_stripe_add_source', $this->get_id(), $wc_token, $response, $source_id); |
|
209 | 209 | |
210 | 210 | return $response->id; |
211 | 211 | } |
@@ -217,42 +217,42 @@ discard block |
||
217 | 217 | * @return array |
218 | 218 | */ |
219 | 219 | public function get_sources() { |
220 | - if ( ! $this->get_id() ) { |
|
220 | + if ( ! $this->get_id()) { |
|
221 | 221 | return array(); |
222 | 222 | } |
223 | 223 | |
224 | - $sources = get_transient( 'stripe_sources_' . $this->get_id() ); |
|
224 | + $sources = get_transient('stripe_sources_' . $this->get_id()); |
|
225 | 225 | |
226 | - $response = WC_Stripe_API::request( array( |
|
226 | + $response = WC_Stripe_API::request(array( |
|
227 | 227 | 'limit' => 100, |
228 | - ), 'customers/' . $this->get_id() . '/sources', 'GET' ); |
|
228 | + ), 'customers/' . $this->get_id() . '/sources', 'GET'); |
|
229 | 229 | |
230 | - if ( ! empty( $response->error ) ) { |
|
230 | + if ( ! empty($response->error)) { |
|
231 | 231 | return array(); |
232 | 232 | } |
233 | 233 | |
234 | - if ( is_array( $response->data ) ) { |
|
234 | + if (is_array($response->data)) { |
|
235 | 235 | $sources = $response->data; |
236 | 236 | } |
237 | 237 | |
238 | - return empty( $sources ) ? array() : $sources; |
|
238 | + return empty($sources) ? array() : $sources; |
|
239 | 239 | } |
240 | 240 | |
241 | 241 | /** |
242 | 242 | * Delete a source from stripe. |
243 | 243 | * @param string $source_id |
244 | 244 | */ |
245 | - public function delete_source( $source_id ) { |
|
246 | - if ( ! $this->get_id() ) { |
|
245 | + public function delete_source($source_id) { |
|
246 | + if ( ! $this->get_id()) { |
|
247 | 247 | return false; |
248 | 248 | } |
249 | 249 | |
250 | - $response = WC_Stripe_API::request( array(), 'customers/' . $this->get_id() . '/sources/' . sanitize_text_field( $source_id ), 'DELETE' ); |
|
250 | + $response = WC_Stripe_API::request(array(), 'customers/' . $this->get_id() . '/sources/' . sanitize_text_field($source_id), 'DELETE'); |
|
251 | 251 | |
252 | 252 | $this->clear_cache(); |
253 | 253 | |
254 | - if ( empty( $response->error ) ) { |
|
255 | - do_action( 'wc_stripe_delete_source', $this->get_id(), $response ); |
|
254 | + if (empty($response->error)) { |
|
255 | + do_action('wc_stripe_delete_source', $this->get_id(), $response); |
|
256 | 256 | |
257 | 257 | return true; |
258 | 258 | } |
@@ -264,15 +264,15 @@ discard block |
||
264 | 264 | * Set default source in Stripe |
265 | 265 | * @param string $source_id |
266 | 266 | */ |
267 | - public function set_default_source( $source_id ) { |
|
268 | - $response = WC_Stripe_API::request( array( |
|
269 | - 'default_source' => sanitize_text_field( $source_id ), |
|
270 | - ), 'customers/' . $this->get_id(), 'POST' ); |
|
267 | + public function set_default_source($source_id) { |
|
268 | + $response = WC_Stripe_API::request(array( |
|
269 | + 'default_source' => sanitize_text_field($source_id), |
|
270 | + ), 'customers/' . $this->get_id(), 'POST'); |
|
271 | 271 | |
272 | 272 | $this->clear_cache(); |
273 | 273 | |
274 | - if ( empty( $response->error ) ) { |
|
275 | - do_action( 'wc_stripe_set_default_source', $this->get_id(), $response ); |
|
274 | + if (empty($response->error)) { |
|
275 | + do_action('wc_stripe_set_default_source', $this->get_id(), $response); |
|
276 | 276 | |
277 | 277 | return true; |
278 | 278 | } |
@@ -284,8 +284,8 @@ discard block |
||
284 | 284 | * Deletes caches for this users cards. |
285 | 285 | */ |
286 | 286 | public function clear_cache() { |
287 | - delete_transient( 'stripe_sources_' . $this->get_id() ); |
|
288 | - delete_transient( 'stripe_customer_' . $this->get_id() ); |
|
287 | + delete_transient('stripe_sources_' . $this->get_id()); |
|
288 | + delete_transient('stripe_customer_' . $this->get_id()); |
|
289 | 289 | $this->customer_data = array(); |
290 | 290 | } |
291 | 291 | } |
@@ -2,12 +2,12 @@ discard block |
||
2 | 2 | |
3 | 3 | class WC_Stripe_Test extends WP_UnitTestCase { |
4 | 4 | public function test_constants_defined() { |
5 | - $this->assertTrue( defined( 'WC_STRIPE_VERSION' ) ); |
|
6 | - $this->assertTrue( defined( 'WC_STRIPE_MIN_PHP_VER' ) ); |
|
7 | - $this->assertTrue( defined( 'WC_STRIPE_MIN_WC_VER' ) ); |
|
8 | - $this->assertTrue( defined( 'WC_STRIPE_MAIN_FILE' ) ); |
|
9 | - $this->assertTrue( defined( 'WC_STRIPE_PLUGIN_URL' ) ); |
|
10 | - $this->assertTrue( defined( 'WC_STRIPE_PLUGIN_PATH' ) ); |
|
5 | + $this->assertTrue(defined('WC_STRIPE_VERSION')); |
|
6 | + $this->assertTrue(defined('WC_STRIPE_MIN_PHP_VER')); |
|
7 | + $this->assertTrue(defined('WC_STRIPE_MIN_WC_VER')); |
|
8 | + $this->assertTrue(defined('WC_STRIPE_MAIN_FILE')); |
|
9 | + $this->assertTrue(defined('WC_STRIPE_PLUGIN_URL')); |
|
10 | + $this->assertTrue(defined('WC_STRIPE_PLUGIN_PATH')); |
|
11 | 11 | } |
12 | 12 | |
13 | 13 | /** |
@@ -15,11 +15,11 @@ discard block |
||
15 | 15 | * This test will see if we're indeed converting the price correctly. |
16 | 16 | */ |
17 | 17 | public function test_price_conversion_before_send_to_stripe() { |
18 | - $this->assertEquals( 10050, WC_Stripe_Helper::get_stripe_amount( 100.50, 'USD' ) ); |
|
19 | - $this->assertEquals( 10050, WC_Stripe_Helper::get_stripe_amount( 10050, 'JPY' ) ); |
|
20 | - $this->assertEquals( 100, WC_Stripe_Helper::get_stripe_amount( 100.50, 'JPY' ) ); |
|
21 | - $this->assertEquals( 10050, WC_Stripe_Helper::get_stripe_amount( 100.50 ) ); |
|
22 | - $this->assertInternalType( 'int', WC_Stripe_Helper::get_stripe_amount( 100.50, 'USD' ) ); |
|
18 | + $this->assertEquals(10050, WC_Stripe_Helper::get_stripe_amount(100.50, 'USD')); |
|
19 | + $this->assertEquals(10050, WC_Stripe_Helper::get_stripe_amount(10050, 'JPY')); |
|
20 | + $this->assertEquals(100, WC_Stripe_Helper::get_stripe_amount(100.50, 'JPY')); |
|
21 | + $this->assertEquals(10050, WC_Stripe_Helper::get_stripe_amount(100.50)); |
|
22 | + $this->assertInternalType('int', WC_Stripe_Helper::get_stripe_amount(100.50, 'USD')); |
|
23 | 23 | } |
24 | 24 | |
25 | 25 | /** |
@@ -33,37 +33,37 @@ discard block |
||
33 | 33 | $balance_fee1->net = 10000; |
34 | 34 | $balance_fee1->currency = 'USD'; |
35 | 35 | |
36 | - $this->assertEquals( 105.00, WC_Stripe_Helper::format_balance_fee( $balance_fee1, 'fee' ) ); |
|
36 | + $this->assertEquals(105.00, WC_Stripe_Helper::format_balance_fee($balance_fee1, 'fee')); |
|
37 | 37 | |
38 | 38 | $balance_fee2 = new stdClass(); |
39 | 39 | $balance_fee2->fee = 10500; |
40 | 40 | $balance_fee2->net = 10000; |
41 | 41 | $balance_fee2->currency = 'JPY'; |
42 | 42 | |
43 | - $this->assertEquals( 10500, WC_Stripe_Helper::format_balance_fee( $balance_fee2, 'fee' ) ); |
|
43 | + $this->assertEquals(10500, WC_Stripe_Helper::format_balance_fee($balance_fee2, 'fee')); |
|
44 | 44 | |
45 | 45 | $balance_fee3 = new stdClass(); |
46 | 46 | $balance_fee3->fee = 10500; |
47 | 47 | $balance_fee3->net = 10000; |
48 | 48 | $balance_fee3->currency = 'USD'; |
49 | 49 | |
50 | - $this->assertEquals( 100.00, WC_Stripe_Helper::format_balance_fee( $balance_fee3, 'net' ) ); |
|
50 | + $this->assertEquals(100.00, WC_Stripe_Helper::format_balance_fee($balance_fee3, 'net')); |
|
51 | 51 | |
52 | 52 | $balance_fee4 = new stdClass(); |
53 | 53 | $balance_fee4->fee = 10500; |
54 | 54 | $balance_fee4->net = 10000; |
55 | 55 | $balance_fee4->currency = 'JPY'; |
56 | 56 | |
57 | - $this->assertEquals( 10000, WC_Stripe_Helper::format_balance_fee( $balance_fee4, 'net' ) ); |
|
57 | + $this->assertEquals(10000, WC_Stripe_Helper::format_balance_fee($balance_fee4, 'net')); |
|
58 | 58 | |
59 | 59 | $balance_fee5 = new stdClass(); |
60 | 60 | $balance_fee5->fee = 10500; |
61 | 61 | $balance_fee5->net = 10000; |
62 | 62 | $balance_fee5->currency = 'USD'; |
63 | 63 | |
64 | - $this->assertEquals( 105.00, WC_Stripe_Helper::format_balance_fee( $balance_fee5 ) ); |
|
64 | + $this->assertEquals(105.00, WC_Stripe_Helper::format_balance_fee($balance_fee5)); |
|
65 | 65 | |
66 | - $this->assertInternalType( 'string', WC_Stripe_Helper::format_balance_fee( $balance_fee5 ) ); |
|
66 | + $this->assertInternalType('string', WC_Stripe_Helper::format_balance_fee($balance_fee5)); |
|
67 | 67 | } |
68 | 68 | |
69 | 69 | /** |
@@ -76,28 +76,28 @@ discard block |
||
76 | 76 | 'expected' => 'Tests Store', |
77 | 77 | ); |
78 | 78 | |
79 | - $this->assertEquals( $statement_descriptor1['expected'], WC_Stripe_Helper::clean_statement_descriptor( $statement_descriptor1['actual'] ) ); |
|
79 | + $this->assertEquals($statement_descriptor1['expected'], WC_Stripe_Helper::clean_statement_descriptor($statement_descriptor1['actual'])); |
|
80 | 80 | |
81 | 81 | $statement_descriptor2 = array( |
82 | 82 | 'actual' => 'Test\'s Store > Driving Course Range', |
83 | 83 | 'expected' => 'Tests Store Driving C', |
84 | 84 | ); |
85 | 85 | |
86 | - $this->assertEquals( $statement_descriptor2['expected'], WC_Stripe_Helper::clean_statement_descriptor( $statement_descriptor2['actual'] ) ); |
|
86 | + $this->assertEquals($statement_descriptor2['expected'], WC_Stripe_Helper::clean_statement_descriptor($statement_descriptor2['actual'])); |
|
87 | 87 | |
88 | 88 | $statement_descriptor3 = array( |
89 | 89 | 'actual' => 'Test\'s Store < Driving Course Range', |
90 | 90 | 'expected' => 'Tests Store Driving C', |
91 | 91 | ); |
92 | 92 | |
93 | - $this->assertEquals( $statement_descriptor3['expected'], WC_Stripe_Helper::clean_statement_descriptor( $statement_descriptor3['actual'] ) ); |
|
93 | + $this->assertEquals($statement_descriptor3['expected'], WC_Stripe_Helper::clean_statement_descriptor($statement_descriptor3['actual'])); |
|
94 | 94 | |
95 | 95 | $statement_descriptor4 = array( |
96 | 96 | 'actual' => 'Test\'s Store " Driving Course Range', |
97 | 97 | 'expected' => 'Tests Store Driving C', |
98 | 98 | ); |
99 | 99 | |
100 | - $this->assertEquals( $statement_descriptor4['expected'], WC_Stripe_Helper::clean_statement_descriptor( $statement_descriptor4['actual'] ) ); |
|
100 | + $this->assertEquals($statement_descriptor4['expected'], WC_Stripe_Helper::clean_statement_descriptor($statement_descriptor4['actual'])); |
|
101 | 101 | } |
102 | 102 | |
103 | 103 | /** |
@@ -109,12 +109,12 @@ discard block |
||
109 | 109 | $source = new stdClass(); |
110 | 110 | $source->type = 'three_d_secure'; |
111 | 111 | |
112 | - $this->assertEquals( true, $stripe->is_3ds_card( $source ) ); |
|
112 | + $this->assertEquals(true, $stripe->is_3ds_card($source)); |
|
113 | 113 | |
114 | 114 | $source = new stdClass(); |
115 | 115 | $source->type = 'card'; |
116 | 116 | |
117 | - $this->assertEquals( false, $stripe->is_3ds_card( $source ) ); |
|
117 | + $this->assertEquals(false, $stripe->is_3ds_card($source)); |
|
118 | 118 | } |
119 | 119 | |
120 | 120 | /** |
@@ -128,20 +128,20 @@ discard block |
||
128 | 128 | $source->card = new stdClass(); |
129 | 129 | $source->card->three_d_secure = 'required'; |
130 | 130 | |
131 | - $this->assertEquals( true, $stripe->is_3ds_required( $source ) ); |
|
131 | + $this->assertEquals(true, $stripe->is_3ds_required($source)); |
|
132 | 132 | |
133 | 133 | $source = new stdClass(); |
134 | 134 | $source->type = 'card'; |
135 | 135 | $source->card = new stdClass(); |
136 | 136 | $source->card->three_d_secure = 'optional'; |
137 | 137 | |
138 | - $this->assertEquals( false, $stripe->is_3ds_required( $source ) ); |
|
138 | + $this->assertEquals(false, $stripe->is_3ds_required($source)); |
|
139 | 139 | |
140 | 140 | $source = new stdClass(); |
141 | 141 | $source->type = 'card'; |
142 | 142 | $source->card = new stdClass(); |
143 | 143 | $source->card->three_d_secure = 'not_supported'; |
144 | 144 | |
145 | - $this->assertEquals( false, $stripe->is_3ds_required( $source ) ); |
|
145 | + $this->assertEquals(false, $stripe->is_3ds_required($source)); |
|
146 | 146 | } |
147 | 147 | } |