@@ -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( $post_data, 'sources' ); |
|
261 | + return WC_Stripe_API::request($post_data, '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_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( $post_data, 'sources' ); |
|
258 | + return WC_Stripe_API::request($post_data, '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 | |
@@ -26,7 +26,7 @@ discard block |
||
26 | 26 | * Set secret API Key. |
27 | 27 | * @param string $key |
28 | 28 | */ |
29 | - public static function set_secret_key( $secret_key ) { |
|
29 | + public static function set_secret_key($secret_key) { |
|
30 | 30 | self::$secret_key = $secret_key; |
31 | 31 | } |
32 | 32 | |
@@ -35,11 +35,11 @@ discard block |
||
35 | 35 | * @return string |
36 | 36 | */ |
37 | 37 | public static function get_secret_key() { |
38 | - if ( ! self::$secret_key ) { |
|
39 | - $options = get_option( 'woocommerce_stripe_settings' ); |
|
38 | + if ( ! self::$secret_key) { |
|
39 | + $options = get_option('woocommerce_stripe_settings'); |
|
40 | 40 | |
41 | - if ( isset( $options['testmode'], $options['secret_key'], $options['test_secret_key'] ) ) { |
|
42 | - self::set_secret_key( 'yes' === $options['testmode'] ? $options['test_secret_key'] : $options['secret_key'] ); |
|
41 | + if (isset($options['testmode'], $options['secret_key'], $options['test_secret_key'])) { |
|
42 | + self::set_secret_key('yes' === $options['testmode'] ? $options['test_secret_key'] : $options['secret_key']); |
|
43 | 43 | } |
44 | 44 | } |
45 | 45 | return self::$secret_key; |
@@ -78,12 +78,12 @@ discard block |
||
78 | 78 | $user_agent = self::get_user_agent(); |
79 | 79 | $app_info = $user_agent['application']; |
80 | 80 | |
81 | - return apply_filters( 'woocommerce_stripe_request_headers', array( |
|
82 | - 'Authorization' => 'Basic ' . base64_encode( self::get_secret_key() . ':' ), |
|
81 | + return apply_filters('woocommerce_stripe_request_headers', array( |
|
82 | + 'Authorization' => 'Basic ' . base64_encode(self::get_secret_key() . ':'), |
|
83 | 83 | 'Stripe-Version' => self::STRIPE_API_VERSION, |
84 | 84 | 'User-Agent' => $app_info['name'] . '/' . $app_info['version'] . ' (' . $app_info['url'] . ')', |
85 | - 'X-Stripe-Client-User-Agent' => json_encode( $user_agent ), |
|
86 | - ) ); |
|
85 | + 'X-Stripe-Client-User-Agent' => json_encode($user_agent), |
|
86 | + )); |
|
87 | 87 | } |
88 | 88 | |
89 | 89 | /** |
@@ -95,13 +95,13 @@ discard block |
||
95 | 95 | * @param string $api |
96 | 96 | * @return array|WP_Error |
97 | 97 | */ |
98 | - public static function request( $request, $api = 'charges', $method = 'POST' ) { |
|
99 | - WC_Stripe_Logger::log( "{$api} request: " . print_r( $request, true ) ); |
|
98 | + public static function request($request, $api = 'charges', $method = 'POST') { |
|
99 | + WC_Stripe_Logger::log("{$api} request: " . print_r($request, true)); |
|
100 | 100 | |
101 | 101 | $headers = self::get_headers(); |
102 | 102 | |
103 | - if ( 'charges' === $api && 'POST' === $method ) { |
|
104 | - $headers['Idempotency-Key'] = uniqid( 'stripe_' ); |
|
103 | + if ('charges' === $api && 'POST' === $method) { |
|
104 | + $headers['Idempotency-Key'] = uniqid('stripe_'); |
|
105 | 105 | } |
106 | 106 | |
107 | 107 | $response = wp_safe_remote_post( |
@@ -109,17 +109,17 @@ discard block |
||
109 | 109 | array( |
110 | 110 | 'method' => $method, |
111 | 111 | 'headers' => $headers, |
112 | - 'body' => apply_filters( 'woocommerce_stripe_request_body', $request, $api ), |
|
112 | + 'body' => apply_filters('woocommerce_stripe_request_body', $request, $api), |
|
113 | 113 | 'timeout' => 70, |
114 | 114 | ) |
115 | 115 | ); |
116 | 116 | |
117 | - if ( is_wp_error( $response ) || empty( $response['body'] ) ) { |
|
118 | - WC_Stripe_Logger::log( 'Error Response: ' . print_r( $response, true ) ); |
|
119 | - throw new WC_Stripe_Exception( print_r( $response, true ), __( 'There was a problem connecting to the Stripe API endpoint.', 'woocommerce-gateway-stripe' ) ); |
|
117 | + if (is_wp_error($response) || empty($response['body'])) { |
|
118 | + WC_Stripe_Logger::log('Error Response: ' . print_r($response, true)); |
|
119 | + throw new WC_Stripe_Exception(print_r($response, true), __('There was a problem connecting to the Stripe API endpoint.', 'woocommerce-gateway-stripe')); |
|
120 | 120 | } |
121 | 121 | |
122 | - return json_decode( $response['body'] ); |
|
122 | + return json_decode($response['body']); |
|
123 | 123 | } |
124 | 124 | |
125 | 125 | /** |
@@ -129,8 +129,8 @@ discard block |
||
129 | 129 | * @version 4.0.0 |
130 | 130 | * @param string $api |
131 | 131 | */ |
132 | - public static function retrieve( $api ) { |
|
133 | - WC_Stripe_Logger::log( "{$api}" ); |
|
132 | + public static function retrieve($api) { |
|
133 | + WC_Stripe_Logger::log("{$api}"); |
|
134 | 134 | |
135 | 135 | $ua = self::get_user_agent(); |
136 | 136 | |
@@ -143,11 +143,11 @@ discard block |
||
143 | 143 | ) |
144 | 144 | ); |
145 | 145 | |
146 | - if ( is_wp_error( $response ) || empty( $response['body'] ) ) { |
|
147 | - WC_Stripe_Logger::log( 'Error Response: ' . print_r( $response, true ) ); |
|
148 | - return new WP_Error( 'stripe_error', __( 'There was a problem connecting to the Stripe API endpoint.', 'woocommerce-gateway-stripe' ) ); |
|
146 | + if (is_wp_error($response) || empty($response['body'])) { |
|
147 | + WC_Stripe_Logger::log('Error Response: ' . print_r($response, true)); |
|
148 | + return new WP_Error('stripe_error', __('There was a problem connecting to the Stripe API endpoint.', 'woocommerce-gateway-stripe')); |
|
149 | 149 | } |
150 | 150 | |
151 | - return json_decode( $response['body'] ); |
|
151 | + return json_decode($response['body']); |
|
152 | 152 | } |
153 | 153 | } |
@@ -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,24 +37,24 @@ 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 | - ) ); |
|
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 | + )); |
|
58 | 58 | } |
59 | 59 | |
60 | 60 | /** |
@@ -91,24 +91,24 @@ discard block |
||
91 | 91 | * @param string $type Type of number to format |
92 | 92 | * @return string |
93 | 93 | */ |
94 | - public static function format_balance_fee( $balance_transaction, $type = 'fee' ) { |
|
95 | - if ( ! is_object( $balance_transaction ) ) { |
|
94 | + public static function format_balance_fee($balance_transaction, $type = 'fee') { |
|
95 | + if ( ! is_object($balance_transaction)) { |
|
96 | 96 | return; |
97 | 97 | } |
98 | 98 | |
99 | - if ( in_array( strtolower( $balance_transaction->currency ), self::no_decimal_currencies() ) ) { |
|
100 | - if ( 'fee' === $type ) { |
|
99 | + if (in_array(strtolower($balance_transaction->currency), self::no_decimal_currencies())) { |
|
100 | + if ('fee' === $type) { |
|
101 | 101 | return $balance_transaction->fee; |
102 | 102 | } |
103 | 103 | |
104 | 104 | return $balance_transaction->net; |
105 | 105 | } |
106 | 106 | |
107 | - if ( 'fee' === $type ) { |
|
108 | - return number_format( $balance_transaction->fee / 100, 2, '.', '' ); |
|
107 | + if ('fee' === $type) { |
|
108 | + return number_format($balance_transaction->fee / 100, 2, '.', ''); |
|
109 | 109 | } |
110 | 110 | |
111 | - return number_format( $balance_transaction->net / 100, 2, '.', '' ); |
|
111 | + return number_format($balance_transaction->net / 100, 2, '.', ''); |
|
112 | 112 | } |
113 | 113 | |
114 | 114 | /** |
@@ -116,7 +116,7 @@ discard block |
||
116 | 116 | */ |
117 | 117 | public static function get_minimum_amount() { |
118 | 118 | // Check order amount |
119 | - switch ( get_woocommerce_currency() ) { |
|
119 | + switch (get_woocommerce_currency()) { |
|
120 | 120 | case 'USD': |
121 | 121 | case 'CAD': |
122 | 122 | case 'EUR': |
@@ -161,14 +161,14 @@ discard block |
||
161 | 161 | * @param string $method The payment method to get the settings from. |
162 | 162 | * @param string $setting The name of the setting to get. |
163 | 163 | */ |
164 | - public static function get_settings( $method = null, $setting = null ) { |
|
165 | - $all_settings = null === $method ? get_option( 'woocommerce_stripe_settings', array() ) : get_option( 'woocommerce_stripe_' . $method . '_settings', array() ); |
|
164 | + public static function get_settings($method = null, $setting = null) { |
|
165 | + $all_settings = null === $method ? get_option('woocommerce_stripe_settings', array()) : get_option('woocommerce_stripe_' . $method . '_settings', array()); |
|
166 | 166 | |
167 | - if ( null === $setting ) { |
|
167 | + if (null === $setting) { |
|
168 | 168 | return $all_settings; |
169 | 169 | } |
170 | 170 | |
171 | - return isset( $all_settings[ $setting ] ) ? $all_settings[ $setting ] : ''; |
|
171 | + return isset($all_settings[$setting]) ? $all_settings[$setting] : ''; |
|
172 | 172 | } |
173 | 173 | |
174 | 174 | /** |
@@ -179,7 +179,7 @@ discard block |
||
179 | 179 | * @return bool |
180 | 180 | */ |
181 | 181 | public static function is_pre_30() { |
182 | - return version_compare( WC_VERSION, '3.0.0', '<' ); |
|
182 | + return version_compare(WC_VERSION, '3.0.0', '<'); |
|
183 | 183 | } |
184 | 184 | |
185 | 185 | /** |
@@ -192,7 +192,7 @@ discard block |
||
192 | 192 | * @return string |
193 | 193 | */ |
194 | 194 | public static function get_webhook_url() { |
195 | - return add_query_arg( 'wc-api', 'wc_stripe', trailingslashit( get_home_url() ) ); |
|
195 | + return add_query_arg('wc-api', 'wc_stripe', trailingslashit(get_home_url())); |
|
196 | 196 | } |
197 | 197 | |
198 | 198 | /** |
@@ -202,13 +202,13 @@ discard block |
||
202 | 202 | * @version 4.0.0 |
203 | 203 | * @param string $source_id |
204 | 204 | */ |
205 | - public static function get_order_by_source_id( $source_id ) { |
|
205 | + public static function get_order_by_source_id($source_id) { |
|
206 | 206 | global $wpdb; |
207 | 207 | |
208 | - $order_id = $wpdb->get_var( $wpdb->prepare( "SELECT DISTINCT ID FROM $wpdb->posts as posts LEFT JOIN $wpdb->postmeta as meta ON posts.ID = meta.post_id WHERE meta.meta_value = %s", $source_id ) ); |
|
208 | + $order_id = $wpdb->get_var($wpdb->prepare("SELECT DISTINCT ID FROM $wpdb->posts as posts LEFT JOIN $wpdb->postmeta as meta ON posts.ID = meta.post_id WHERE meta.meta_value = %s", $source_id)); |
|
209 | 209 | |
210 | - if ( ! empty( $order_id ) ) { |
|
211 | - return wc_get_order( $order_id ); |
|
210 | + if ( ! empty($order_id)) { |
|
211 | + return wc_get_order($order_id); |
|
212 | 212 | } |
213 | 213 | |
214 | 214 | return false; |
@@ -221,13 +221,13 @@ discard block |
||
221 | 221 | * @version 4.0.0 |
222 | 222 | * @param string $charge_id |
223 | 223 | */ |
224 | - public static function get_order_by_charge_id( $charge_id ) { |
|
224 | + public static function get_order_by_charge_id($charge_id) { |
|
225 | 225 | global $wpdb; |
226 | 226 | |
227 | - $order_id = $wpdb->get_var( $wpdb->prepare( "SELECT DISTINCT ID FROM $wpdb->posts as posts LEFT JOIN $wpdb->postmeta as meta ON posts.ID = meta.post_id WHERE meta.meta_value = %s", $charge_id ) ); |
|
227 | + $order_id = $wpdb->get_var($wpdb->prepare("SELECT DISTINCT ID FROM $wpdb->posts as posts LEFT JOIN $wpdb->postmeta as meta ON posts.ID = meta.post_id WHERE meta.meta_value = %s", $charge_id)); |
|
228 | 228 | |
229 | - if ( ! empty( $order_id ) ) { |
|
230 | - return wc_get_order( $order_id ); |
|
229 | + if ( ! empty($order_id)) { |
|
230 | + return wc_get_order($order_id); |
|
231 | 231 | } |
232 | 232 | |
233 | 233 | return false; |
@@ -243,13 +243,13 @@ discard block |
||
243 | 243 | * @param string $statement_descriptor |
244 | 244 | * @return string $statement_descriptor Sanitized statement descriptor |
245 | 245 | */ |
246 | - public static function clean_statement_descriptor( $statement_descriptor = '' ) { |
|
247 | - $disallowed_characters = array( '<', '>', '"', "'" ); |
|
246 | + public static function clean_statement_descriptor($statement_descriptor = '') { |
|
247 | + $disallowed_characters = array('<', '>', '"', "'"); |
|
248 | 248 | |
249 | 249 | // Remove special characters. |
250 | - $statement_descriptor = str_replace( $disallowed_characters, '', $statement_descriptor ); |
|
250 | + $statement_descriptor = str_replace($disallowed_characters, '', $statement_descriptor); |
|
251 | 251 | |
252 | - $statement_descriptor = substr( trim( $statement_descriptor ), 0, 22 ); |
|
252 | + $statement_descriptor = substr(trim($statement_descriptor), 0, 22); |
|
253 | 253 | |
254 | 254 | return $statement_descriptor; |
255 | 255 | } |
@@ -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 | |
@@ -90,14 +90,14 @@ discard block |
||
90 | 90 | * Get data from the Stripe API about this customer |
91 | 91 | */ |
92 | 92 | public function get_customer_data() { |
93 | - $this->customer_data = get_transient( 'stripe_customer_' . $this->get_id() ); |
|
93 | + $this->customer_data = get_transient('stripe_customer_' . $this->get_id()); |
|
94 | 94 | |
95 | - if ( empty( $this->customer_data ) && $this->get_id() && false === $this->customer_data ) { |
|
96 | - $response = WC_Stripe_API::request( array(), 'customers/' . $this->get_id() ); |
|
95 | + if (empty($this->customer_data) && $this->get_id() && false === $this->customer_data) { |
|
96 | + $response = WC_Stripe_API::request(array(), 'customers/' . $this->get_id()); |
|
97 | 97 | |
98 | - if ( empty( $response->error ) ) { |
|
99 | - $this->set_customer_data( $response ); |
|
100 | - set_transient( 'stripe_customer_' . $this->get_id(), $response, HOUR_IN_SECONDS * 48 ); |
|
98 | + if (empty($response->error)) { |
|
99 | + $this->set_customer_data($response); |
|
100 | + set_transient('stripe_customer_' . $this->get_id(), $response, HOUR_IN_SECONDS * 48); |
|
101 | 101 | } |
102 | 102 | } |
103 | 103 | |
@@ -112,7 +112,7 @@ discard block |
||
112 | 112 | $data = $this->get_customer_data(); |
113 | 113 | $source = ''; |
114 | 114 | |
115 | - if ( $data ) { |
|
115 | + if ($data) { |
|
116 | 116 | $source = $data->default_source; |
117 | 117 | } |
118 | 118 | |
@@ -124,13 +124,13 @@ discard block |
||
124 | 124 | * @param array $args |
125 | 125 | * @return WP_Error|int |
126 | 126 | */ |
127 | - public function create_customer( $args = array() ) { |
|
128 | - $billing_email = isset( $_POST['billing_email'] ) ? filter_var( $_POST['billing_email'], FILTER_SANITIZE_EMAIL ) : ''; |
|
127 | + public function create_customer($args = array()) { |
|
128 | + $billing_email = isset($_POST['billing_email']) ? filter_var($_POST['billing_email'], FILTER_SANITIZE_EMAIL) : ''; |
|
129 | 129 | $user = $this->get_user(); |
130 | 130 | |
131 | - if ( $user ) { |
|
132 | - $billing_first_name = get_user_meta( $user->ID, 'billing_first_name', true ); |
|
133 | - $billing_last_name = get_user_meta( $user->ID, 'billing_last_name', true ); |
|
131 | + if ($user) { |
|
132 | + $billing_first_name = get_user_meta($user->ID, 'billing_first_name', true); |
|
133 | + $billing_last_name = get_user_meta($user->ID, 'billing_last_name', true); |
|
134 | 134 | |
135 | 135 | $defaults = array( |
136 | 136 | 'email' => $user->user_email, |
@@ -145,24 +145,24 @@ discard block |
||
145 | 145 | |
146 | 146 | $metadata = array(); |
147 | 147 | |
148 | - $defaults['metadata'] = apply_filters( 'wc_stripe_customer_metadata', $metadata, $user ); |
|
148 | + $defaults['metadata'] = apply_filters('wc_stripe_customer_metadata', $metadata, $user); |
|
149 | 149 | |
150 | - $args = wp_parse_args( $args, $defaults ); |
|
151 | - $response = WC_Stripe_API::request( apply_filters( 'wc_stripe_create_customer_args', $args ), 'customers' ); |
|
150 | + $args = wp_parse_args($args, $defaults); |
|
151 | + $response = WC_Stripe_API::request(apply_filters('wc_stripe_create_customer_args', $args), 'customers'); |
|
152 | 152 | |
153 | - if ( ! empty( $response->error ) ) { |
|
154 | - throw new WC_Stripe_Exception( print_r( $response, true ), $response->error->message ); |
|
153 | + if ( ! empty($response->error)) { |
|
154 | + throw new WC_Stripe_Exception(print_r($response, true), $response->error->message); |
|
155 | 155 | } |
156 | 156 | |
157 | - $this->set_id( $response->id ); |
|
157 | + $this->set_id($response->id); |
|
158 | 158 | $this->clear_cache(); |
159 | - $this->set_customer_data( $response ); |
|
159 | + $this->set_customer_data($response); |
|
160 | 160 | |
161 | - if ( $this->get_user_id() ) { |
|
162 | - update_user_meta( $this->get_user_id(), '_stripe_customer_id', $response->id ); |
|
161 | + if ($this->get_user_id()) { |
|
162 | + update_user_meta($this->get_user_id(), '_stripe_customer_id', $response->id); |
|
163 | 163 | } |
164 | 164 | |
165 | - do_action( 'woocommerce_stripe_add_customer', $args, $response ); |
|
165 | + do_action('woocommerce_stripe_add_customer', $args, $response); |
|
166 | 166 | |
167 | 167 | return $response->id; |
168 | 168 | } |
@@ -173,72 +173,72 @@ discard block |
||
173 | 173 | * @param bool $retry |
174 | 174 | * @return WP_Error|int |
175 | 175 | */ |
176 | - public function add_source( $source_id, $retry = true ) { |
|
177 | - if ( ! $this->get_id() ) { |
|
178 | - $this->set_id( $this->create_customer() ); |
|
176 | + public function add_source($source_id, $retry = true) { |
|
177 | + if ( ! $this->get_id()) { |
|
178 | + $this->set_id($this->create_customer()); |
|
179 | 179 | } |
180 | 180 | |
181 | - $response = WC_Stripe_API::request( array( |
|
181 | + $response = WC_Stripe_API::request(array( |
|
182 | 182 | 'source' => $source_id, |
183 | - ), 'customers/' . $this->get_id() . '/sources' ); |
|
183 | + ), 'customers/' . $this->get_id() . '/sources'); |
|
184 | 184 | |
185 | - if ( ! empty( $response->error ) ) { |
|
185 | + if ( ! empty($response->error)) { |
|
186 | 186 | // It is possible the WC user once was linked to a customer on Stripe |
187 | 187 | // but no longer exists. Instead of failing, lets try to create a |
188 | 188 | // new customer. |
189 | - if ( preg_match( '/No such customer/i', $response->error->message ) ) { |
|
190 | - delete_user_meta( $this->get_user_id(), '_stripe_customer_id' ); |
|
189 | + if (preg_match('/No such customer/i', $response->error->message)) { |
|
190 | + delete_user_meta($this->get_user_id(), '_stripe_customer_id'); |
|
191 | 191 | $this->create_customer(); |
192 | - return $this->add_source( $source_id, false ); |
|
192 | + return $this->add_source($source_id, false); |
|
193 | 193 | } else { |
194 | 194 | return $response; |
195 | 195 | } |
196 | - } elseif ( empty( $response->id ) ) { |
|
197 | - return new WP_Error( 'error', __( 'Unable to add payment source.', 'woocommerce-gateway-stripe' ) ); |
|
196 | + } elseif (empty($response->id)) { |
|
197 | + return new WP_Error('error', __('Unable to add payment source.', 'woocommerce-gateway-stripe')); |
|
198 | 198 | } |
199 | 199 | |
200 | 200 | // Add token to WooCommerce. |
201 | - if ( $this->get_user_id() && class_exists( 'WC_Payment_Token_CC' ) ) { |
|
202 | - if ( ! empty( $response->type ) ) { |
|
203 | - switch ( $response->type ) { |
|
201 | + if ($this->get_user_id() && class_exists('WC_Payment_Token_CC')) { |
|
202 | + if ( ! empty($response->type)) { |
|
203 | + switch ($response->type) { |
|
204 | 204 | case 'alipay': |
205 | 205 | break; |
206 | 206 | case 'sepa_debit': |
207 | 207 | $wc_token = new WC_Payment_Token_SEPA(); |
208 | - $wc_token->set_token( $response->id ); |
|
209 | - $wc_token->set_gateway_id( 'stripe_sepa' ); |
|
210 | - $wc_token->set_last4( $response->sepa_debit->last4 ); |
|
208 | + $wc_token->set_token($response->id); |
|
209 | + $wc_token->set_gateway_id('stripe_sepa'); |
|
210 | + $wc_token->set_last4($response->sepa_debit->last4); |
|
211 | 211 | break; |
212 | 212 | default: |
213 | - if ( 'source' === $response->object && 'card' === $response->type ) { |
|
213 | + if ('source' === $response->object && 'card' === $response->type) { |
|
214 | 214 | $wc_token = new WC_Payment_Token_CC(); |
215 | - $wc_token->set_token( $response->id ); |
|
216 | - $wc_token->set_gateway_id( 'stripe' ); |
|
217 | - $wc_token->set_card_type( strtolower( $response->card->brand ) ); |
|
218 | - $wc_token->set_last4( $response->card->last4 ); |
|
219 | - $wc_token->set_expiry_month( $response->card->exp_month ); |
|
220 | - $wc_token->set_expiry_year( $response->card->exp_year ); |
|
215 | + $wc_token->set_token($response->id); |
|
216 | + $wc_token->set_gateway_id('stripe'); |
|
217 | + $wc_token->set_card_type(strtolower($response->card->brand)); |
|
218 | + $wc_token->set_last4($response->card->last4); |
|
219 | + $wc_token->set_expiry_month($response->card->exp_month); |
|
220 | + $wc_token->set_expiry_year($response->card->exp_year); |
|
221 | 221 | } |
222 | 222 | break; |
223 | 223 | } |
224 | 224 | } else { |
225 | 225 | // Legacy. |
226 | 226 | $wc_token = new WC_Payment_Token_CC(); |
227 | - $wc_token->set_token( $response->id ); |
|
228 | - $wc_token->set_gateway_id( 'stripe' ); |
|
229 | - $wc_token->set_card_type( strtolower( $response->brand ) ); |
|
230 | - $wc_token->set_last4( $response->last4 ); |
|
231 | - $wc_token->set_expiry_month( $response->exp_month ); |
|
232 | - $wc_token->set_expiry_year( $response->exp_year ); |
|
227 | + $wc_token->set_token($response->id); |
|
228 | + $wc_token->set_gateway_id('stripe'); |
|
229 | + $wc_token->set_card_type(strtolower($response->brand)); |
|
230 | + $wc_token->set_last4($response->last4); |
|
231 | + $wc_token->set_expiry_month($response->exp_month); |
|
232 | + $wc_token->set_expiry_year($response->exp_year); |
|
233 | 233 | } |
234 | 234 | |
235 | - $wc_token->set_user_id( $this->get_user_id() ); |
|
235 | + $wc_token->set_user_id($this->get_user_id()); |
|
236 | 236 | $wc_token->save(); |
237 | 237 | } |
238 | 238 | |
239 | 239 | $this->clear_cache(); |
240 | 240 | |
241 | - do_action( 'woocommerce_stripe_add_source', $this->get_id(), $wc_token, $response, $source_id ); |
|
241 | + do_action('woocommerce_stripe_add_source', $this->get_id(), $wc_token, $response, $source_id); |
|
242 | 242 | |
243 | 243 | return $response->id; |
244 | 244 | } |
@@ -250,46 +250,46 @@ discard block |
||
250 | 250 | * @return array |
251 | 251 | */ |
252 | 252 | public function get_sources() { |
253 | - if ( ! $this->get_id() ) { |
|
253 | + if ( ! $this->get_id()) { |
|
254 | 254 | return array(); |
255 | 255 | } |
256 | 256 | |
257 | - $sources = get_transient( 'stripe_sources_' . $this->get_id() ); |
|
257 | + $sources = get_transient('stripe_sources_' . $this->get_id()); |
|
258 | 258 | |
259 | - if ( false === $sources ) { |
|
260 | - $response = WC_Stripe_API::request( array( |
|
259 | + if (false === $sources) { |
|
260 | + $response = WC_Stripe_API::request(array( |
|
261 | 261 | 'limit' => 100, |
262 | - ), 'customers/' . $this->get_id() . '/sources', 'GET' ); |
|
262 | + ), 'customers/' . $this->get_id() . '/sources', 'GET'); |
|
263 | 263 | |
264 | - if ( ! empty( $response->error ) ) { |
|
264 | + if ( ! empty($response->error)) { |
|
265 | 265 | return array(); |
266 | 266 | } |
267 | 267 | |
268 | - if ( is_array( $response->data ) ) { |
|
268 | + if (is_array($response->data)) { |
|
269 | 269 | $sources = $response->data; |
270 | 270 | } |
271 | 271 | |
272 | - set_transient( 'stripe_sources_' . $this->get_id(), $sources, HOUR_IN_SECONDS * 24 ); |
|
272 | + set_transient('stripe_sources_' . $this->get_id(), $sources, HOUR_IN_SECONDS * 24); |
|
273 | 273 | } |
274 | 274 | |
275 | - return empty( $sources ) ? array() : $sources; |
|
275 | + return empty($sources) ? array() : $sources; |
|
276 | 276 | } |
277 | 277 | |
278 | 278 | /** |
279 | 279 | * Delete a source from stripe. |
280 | 280 | * @param string $source_id |
281 | 281 | */ |
282 | - public function delete_source( $source_id ) { |
|
283 | - if ( ! $this->get_id() ) { |
|
282 | + public function delete_source($source_id) { |
|
283 | + if ( ! $this->get_id()) { |
|
284 | 284 | return false; |
285 | 285 | } |
286 | 286 | |
287 | - $response = WC_Stripe_API::request( array(), 'customers/' . $this->get_id() . '/sources/' . sanitize_text_field( $source_id ), 'DELETE' ); |
|
287 | + $response = WC_Stripe_API::request(array(), 'customers/' . $this->get_id() . '/sources/' . sanitize_text_field($source_id), 'DELETE'); |
|
288 | 288 | |
289 | 289 | $this->clear_cache(); |
290 | 290 | |
291 | - if ( empty( $response->error ) ) { |
|
292 | - do_action( 'wc_stripe_delete_source', $this->get_id(), $response ); |
|
291 | + if (empty($response->error)) { |
|
292 | + do_action('wc_stripe_delete_source', $this->get_id(), $response); |
|
293 | 293 | |
294 | 294 | return true; |
295 | 295 | } |
@@ -301,15 +301,15 @@ discard block |
||
301 | 301 | * Set default source in Stripe |
302 | 302 | * @param string $source_id |
303 | 303 | */ |
304 | - public function set_default_source( $source_id ) { |
|
305 | - $response = WC_Stripe_API::request( array( |
|
306 | - 'default_source' => sanitize_text_field( $source_id ), |
|
307 | - ), 'customers/' . $this->get_id(), 'POST' ); |
|
304 | + public function set_default_source($source_id) { |
|
305 | + $response = WC_Stripe_API::request(array( |
|
306 | + 'default_source' => sanitize_text_field($source_id), |
|
307 | + ), 'customers/' . $this->get_id(), 'POST'); |
|
308 | 308 | |
309 | 309 | $this->clear_cache(); |
310 | 310 | |
311 | - if ( empty( $response->error ) ) { |
|
312 | - do_action( 'wc_stripe_set_default_source', $this->get_id(), $response ); |
|
311 | + if (empty($response->error)) { |
|
312 | + do_action('wc_stripe_set_default_source', $this->get_id(), $response); |
|
313 | 313 | |
314 | 314 | return true; |
315 | 315 | } |
@@ -321,8 +321,8 @@ discard block |
||
321 | 321 | * Deletes caches for this users cards. |
322 | 322 | */ |
323 | 323 | public function clear_cache() { |
324 | - delete_transient( 'stripe_sources_' . $this->get_id() ); |
|
325 | - delete_transient( 'stripe_customer_' . $this->get_id() ); |
|
324 | + delete_transient('stripe_sources_' . $this->get_id()); |
|
325 | + delete_transient('stripe_customer_' . $this->get_id()); |
|
326 | 326 | $this->customer_data = array(); |
327 | 327 | } |
328 | 328 | } |
@@ -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,7 +17,7 @@ discard block |
||
17 | 17 | * @version 4.0.0 |
18 | 18 | */ |
19 | 19 | public function __construct() { |
20 | - add_action( 'woocommerce_api_wc_stripe', array( $this, 'check_for_webhook' ) ); |
|
20 | + add_action('woocommerce_api_wc_stripe', array($this, 'check_for_webhook')); |
|
21 | 21 | } |
22 | 22 | |
23 | 23 | /** |
@@ -27,24 +27,24 @@ discard block |
||
27 | 27 | * @version 4.0.0 |
28 | 28 | */ |
29 | 29 | public function check_for_webhook() { |
30 | - if ( ( 'POST' !== $_SERVER['REQUEST_METHOD'] ) |
|
31 | - || ! isset( $_GET['wc-api'] ) |
|
32 | - || ( 'wc_stripe' !== $_GET['wc-api'] ) |
|
30 | + if (('POST' !== $_SERVER['REQUEST_METHOD']) |
|
31 | + || ! isset($_GET['wc-api']) |
|
32 | + || ('wc_stripe' !== $_GET['wc-api']) |
|
33 | 33 | ) { |
34 | 34 | return; |
35 | 35 | } |
36 | 36 | |
37 | - $request_body = file_get_contents( 'php://input' ); |
|
38 | - $request_headers = array_change_key_case( $this->get_request_headers(), CASE_UPPER ); |
|
37 | + $request_body = file_get_contents('php://input'); |
|
38 | + $request_headers = array_change_key_case($this->get_request_headers(), CASE_UPPER); |
|
39 | 39 | |
40 | 40 | // Validate it to make sure it is legit. |
41 | - if ( $this->is_valid_request( $request_headers, $request_body ) ) { |
|
42 | - $this->process_webhook( $request_body ); |
|
43 | - status_header( 200 ); |
|
41 | + if ($this->is_valid_request($request_headers, $request_body)) { |
|
42 | + $this->process_webhook($request_body); |
|
43 | + status_header(200); |
|
44 | 44 | exit; |
45 | 45 | } else { |
46 | - WC_Stripe_Logger::log( 'Incoming webhook failed validation: ' . print_r( $request_body, true ) ); |
|
47 | - status_header( 400 ); |
|
46 | + WC_Stripe_Logger::log('Incoming webhook failed validation: ' . print_r($request_body, true)); |
|
47 | + status_header(400); |
|
48 | 48 | exit; |
49 | 49 | } |
50 | 50 | } |
@@ -59,12 +59,12 @@ discard block |
||
59 | 59 | * @param string $request_body The request body from Stripe. |
60 | 60 | * @return bool |
61 | 61 | */ |
62 | - public function is_valid_request( $request_headers = null, $request_body = null ) { |
|
63 | - if ( null === $request_headers || null === $request_body ) { |
|
62 | + public function is_valid_request($request_headers = null, $request_body = null) { |
|
63 | + if (null === $request_headers || null === $request_body) { |
|
64 | 64 | return false; |
65 | 65 | } |
66 | 66 | |
67 | - if ( ! empty( $request_headers['USER-AGENT'] ) && ! preg_match( '/Stripe/', $request_headers['USER-AGENT'] ) ) { |
|
67 | + if ( ! empty($request_headers['USER-AGENT']) && ! preg_match('/Stripe/', $request_headers['USER-AGENT'])) { |
|
68 | 68 | return false; |
69 | 69 | } |
70 | 70 | |
@@ -80,11 +80,11 @@ discard block |
||
80 | 80 | * @version 4.0.0 |
81 | 81 | */ |
82 | 82 | public function get_request_headers() { |
83 | - if ( ! function_exists( 'getallheaders' ) ) { |
|
83 | + if ( ! function_exists('getallheaders')) { |
|
84 | 84 | $headers = []; |
85 | - foreach ( $_SERVER as $name => $value ) { |
|
86 | - if ( 'HTTP_' === substr( $name, 0, 5 ) ) { |
|
87 | - $headers[ str_replace( ' ', '-', ucwords( strtolower( str_replace( '_', ' ', substr( $name, 5 ) ) ) ) ) ] = $value; |
|
85 | + foreach ($_SERVER as $name => $value) { |
|
86 | + if ('HTTP_' === substr($name, 0, 5)) { |
|
87 | + $headers[str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', substr($name, 5)))))] = $value; |
|
88 | 88 | } |
89 | 89 | } |
90 | 90 | |
@@ -103,30 +103,30 @@ discard block |
||
103 | 103 | * @param object $notification |
104 | 104 | * @param bool $retry |
105 | 105 | */ |
106 | - public function process_webhook_payment( $notification, $retry = true ) { |
|
106 | + public function process_webhook_payment($notification, $retry = true) { |
|
107 | 107 | // The following 2 payment methods are synchronous so does not need to be handle via webhook. |
108 | - if ( 'card' === $notification->data->object->type || 'sepa_debit' === $notification->data->object->type ) { |
|
108 | + if ('card' === $notification->data->object->type || 'sepa_debit' === $notification->data->object->type) { |
|
109 | 109 | return; |
110 | 110 | } |
111 | 111 | |
112 | - $order = WC_Stripe_Helper::get_order_by_source_id( $notification->data->object->id ); |
|
112 | + $order = WC_Stripe_Helper::get_order_by_source_id($notification->data->object->id); |
|
113 | 113 | |
114 | - if ( ! $order ) { |
|
115 | - WC_Stripe_Logger::log( 'Could not find order via source ID: ' . $notification->data->object->id ); |
|
114 | + if ( ! $order) { |
|
115 | + WC_Stripe_Logger::log('Could not find order via source ID: ' . $notification->data->object->id); |
|
116 | 116 | return; |
117 | 117 | } |
118 | 118 | |
119 | 119 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
120 | 120 | $source_id = $notification->data->object->id; |
121 | 121 | |
122 | - $is_pending_receiver = ( 'receiver' === $notification->data->object->flow ); |
|
122 | + $is_pending_receiver = ('receiver' === $notification->data->object->flow); |
|
123 | 123 | |
124 | 124 | try { |
125 | - if ( 'processing' === $order->get_status() || 'completed' === $order->get_status() ) { |
|
125 | + if ('processing' === $order->get_status() || 'completed' === $order->get_status()) { |
|
126 | 126 | return; |
127 | 127 | } |
128 | 128 | |
129 | - if ( 'on-hold' === $order->get_status() && ! $is_pending_receiver ) { |
|
129 | + if ('on-hold' === $order->get_status() && ! $is_pending_receiver) { |
|
130 | 130 | return; |
131 | 131 | } |
132 | 132 | |
@@ -134,73 +134,73 @@ discard block |
||
134 | 134 | $response = null; |
135 | 135 | |
136 | 136 | // This will throw exception if not valid. |
137 | - $this->validate_minimum_order_amount( $order ); |
|
137 | + $this->validate_minimum_order_amount($order); |
|
138 | 138 | |
139 | - WC_Stripe_Logger::log( "Info: (Webhook) Begin processing payment for order $order_id for the amount of {$order->get_total()}" ); |
|
139 | + WC_Stripe_Logger::log("Info: (Webhook) Begin processing payment for order $order_id for the amount of {$order->get_total()}"); |
|
140 | 140 | |
141 | 141 | // Prep source object. |
142 | 142 | $source_object = new stdClass(); |
143 | 143 | $source_object->token_id = ''; |
144 | - $source_object->customer = $this->get_stripe_customer_id( $order ); |
|
144 | + $source_object->customer = $this->get_stripe_customer_id($order); |
|
145 | 145 | $source_object->source = $source_id; |
146 | 146 | |
147 | 147 | // Make the request. |
148 | - $response = WC_Stripe_API::request( $this->generate_payment_request( $order, $source_object ) ); |
|
148 | + $response = WC_Stripe_API::request($this->generate_payment_request($order, $source_object)); |
|
149 | 149 | |
150 | - if ( ! empty( $response->error ) ) { |
|
150 | + if ( ! empty($response->error)) { |
|
151 | 151 | // If it is an API error such connection or server, let's retry. |
152 | - if ( 'api_connection_error' === $response->error->type || 'api_error' === $response->error->type ) { |
|
153 | - if ( $retry ) { |
|
154 | - sleep( 5 ); |
|
155 | - return $this->process_payment( $order_id, false ); |
|
152 | + if ('api_connection_error' === $response->error->type || 'api_error' === $response->error->type) { |
|
153 | + if ($retry) { |
|
154 | + sleep(5); |
|
155 | + return $this->process_payment($order_id, false); |
|
156 | 156 | } else { |
157 | 157 | $localized_message = 'API connection error and retries exhausted.'; |
158 | - $order->add_order_note( $localized_message ); |
|
159 | - throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message ); |
|
158 | + $order->add_order_note($localized_message); |
|
159 | + throw new WC_Stripe_Exception(print_r($response, true), $localized_message); |
|
160 | 160 | } |
161 | 161 | } |
162 | 162 | |
163 | 163 | // Customer param wrong? The user may have been deleted on stripe's end. Remove customer_id. Can be retried without. |
164 | - if ( preg_match( '/No such customer/i', $response->error->message ) && $retry ) { |
|
165 | - delete_user_meta( WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id(), '_stripe_customer_id' ); |
|
164 | + if (preg_match('/No such customer/i', $response->error->message) && $retry) { |
|
165 | + delete_user_meta(WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id(), '_stripe_customer_id'); |
|
166 | 166 | |
167 | - return $this->process_payment( $order_id, false ); |
|
167 | + return $this->process_payment($order_id, false); |
|
168 | 168 | |
169 | - } elseif ( preg_match( '/No such token/i', $response->error->message ) && $source_object->token_id ) { |
|
169 | + } elseif (preg_match('/No such token/i', $response->error->message) && $source_object->token_id) { |
|
170 | 170 | // Source param wrong? The CARD may have been deleted on stripe's end. Remove token and show message. |
171 | - $wc_token = WC_Payment_Tokens::get( $source_object->token_id ); |
|
171 | + $wc_token = WC_Payment_Tokens::get($source_object->token_id); |
|
172 | 172 | $wc_token->delete(); |
173 | - $message = __( 'This card is no longer available and has been removed.', 'woocommerce-gateway-stripe' ); |
|
174 | - $order->add_order_note( $message ); |
|
175 | - throw new WC_Stripe_Exception( print_r( $response, true ), $message ); |
|
173 | + $message = __('This card is no longer available and has been removed.', 'woocommerce-gateway-stripe'); |
|
174 | + $order->add_order_note($message); |
|
175 | + throw new WC_Stripe_Exception(print_r($response, true), $message); |
|
176 | 176 | } |
177 | 177 | |
178 | 178 | $localized_messages = WC_Stripe_Helper::get_localized_messages(); |
179 | 179 | |
180 | - if ( 'card_error' === $response->error->type ) { |
|
181 | - $localized_message = isset( $localized_messages[ $response->error->code ] ) ? $localized_messages[ $response->error->code ] : $response->error->message; |
|
180 | + if ('card_error' === $response->error->type) { |
|
181 | + $localized_message = isset($localized_messages[$response->error->code]) ? $localized_messages[$response->error->code] : $response->error->message; |
|
182 | 182 | } else { |
183 | - $localized_message = isset( $localized_messages[ $response->error->type ] ) ? $localized_messages[ $response->error->type ] : $response->error->message; |
|
183 | + $localized_message = isset($localized_messages[$response->error->type]) ? $localized_messages[$response->error->type] : $response->error->message; |
|
184 | 184 | } |
185 | 185 | |
186 | - $order->add_order_note( $localized_message ); |
|
186 | + $order->add_order_note($localized_message); |
|
187 | 187 | |
188 | - throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message ); |
|
188 | + throw new WC_Stripe_Exception(print_r($response, true), $localized_message); |
|
189 | 189 | } |
190 | 190 | |
191 | - do_action( 'wc_gateway_stripe_process_webhook_payment', $response, $order ); |
|
191 | + do_action('wc_gateway_stripe_process_webhook_payment', $response, $order); |
|
192 | 192 | |
193 | - $this->process_response( $response, $order ); |
|
193 | + $this->process_response($response, $order); |
|
194 | 194 | |
195 | - } catch ( WC_Stripe_Exception $e ) { |
|
196 | - WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() ); |
|
195 | + } catch (WC_Stripe_Exception $e) { |
|
196 | + WC_Stripe_Logger::log('Error: ' . $e->getMessage()); |
|
197 | 197 | |
198 | - do_action( 'wc_gateway_stripe_process_webhook_payment_error', $e, $order ); |
|
198 | + do_action('wc_gateway_stripe_process_webhook_payment_error', $e, $order); |
|
199 | 199 | |
200 | - $statuses = array( 'pending', 'failed' ); |
|
200 | + $statuses = array('pending', 'failed'); |
|
201 | 201 | |
202 | - if ( $order->has_status( $statuses ) ) { |
|
203 | - $this->send_failed_order_email( $order_id ); |
|
202 | + if ($order->has_status($statuses)) { |
|
203 | + $this->send_failed_order_email($order_id); |
|
204 | 204 | } |
205 | 205 | } |
206 | 206 | } |
@@ -214,18 +214,18 @@ discard block |
||
214 | 214 | * @version 4.0.0 |
215 | 215 | * @param object $notification |
216 | 216 | */ |
217 | - public function process_webhook_dispute( $notification ) { |
|
218 | - $order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->id ); |
|
217 | + public function process_webhook_dispute($notification) { |
|
218 | + $order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->id); |
|
219 | 219 | |
220 | - if ( ! $order ) { |
|
221 | - WC_Stripe_Logger::log( 'Could not find order via charge ID: ' . $notification->data->object->id ); |
|
220 | + if ( ! $order) { |
|
221 | + WC_Stripe_Logger::log('Could not find order via charge ID: ' . $notification->data->object->id); |
|
222 | 222 | return; |
223 | 223 | } |
224 | 224 | |
225 | - $order->update_status( 'on-hold', __( 'A dispute was created for this order. Response is needed. Please go to your Stripe Dashboard to review this dispute.', 'woocommerce-gateway-stripe' ) ); |
|
225 | + $order->update_status('on-hold', __('A dispute was created for this order. Response is needed. Please go to your Stripe Dashboard to review this dispute.', 'woocommerce-gateway-stripe')); |
|
226 | 226 | |
227 | - do_action( 'wc_gateway_stripe_process_webhook_payment_error', $order, $notification ); |
|
228 | - $this->send_failed_order_email( $order_id ); |
|
227 | + do_action('wc_gateway_stripe_process_webhook_payment_error', $order, $notification); |
|
228 | + $this->send_failed_order_email($order_id); |
|
229 | 229 | } |
230 | 230 | |
231 | 231 | /** |
@@ -236,41 +236,41 @@ discard block |
||
236 | 236 | * @version 4.0.0 |
237 | 237 | * @param object $notification |
238 | 238 | */ |
239 | - public function process_webhook_capture( $notification ) { |
|
240 | - $order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->id ); |
|
239 | + public function process_webhook_capture($notification) { |
|
240 | + $order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->id); |
|
241 | 241 | |
242 | - if ( ! $order ) { |
|
243 | - WC_Stripe_Logger::log( 'Could not find order via charge ID: ' . $notification->data->object->id ); |
|
242 | + if ( ! $order) { |
|
243 | + WC_Stripe_Logger::log('Could not find order via charge ID: ' . $notification->data->object->id); |
|
244 | 244 | return; |
245 | 245 | } |
246 | 246 | |
247 | 247 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
248 | 248 | |
249 | - if ( 'stripe' === ( WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method() ) ) { |
|
250 | - $charge = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_transaction_id', true ) : $order->get_transaction_id(); |
|
251 | - $captured = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_stripe_charge_captured', true ) : $order->get_meta( '_stripe_charge_captured', true ); |
|
249 | + if ('stripe' === (WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method())) { |
|
250 | + $charge = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_transaction_id', true) : $order->get_transaction_id(); |
|
251 | + $captured = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_stripe_charge_captured', true) : $order->get_meta('_stripe_charge_captured', true); |
|
252 | 252 | |
253 | - if ( $charge && 'no' === $captured ) { |
|
254 | - WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, '_stripe_charge_captured', 'yes' ) : $order->update_meta_data( '_stripe_charge_captured', 'yes' ); |
|
253 | + if ($charge && 'no' === $captured) { |
|
254 | + WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, '_stripe_charge_captured', 'yes') : $order->update_meta_data('_stripe_charge_captured', 'yes'); |
|
255 | 255 | |
256 | 256 | // Store other data such as fees |
257 | - WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, '_transaction_id', $notification->data->object->id ) : $order->set_transaction_id( $notification->data->object->id ); |
|
257 | + WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, '_transaction_id', $notification->data->object->id) : $order->set_transaction_id($notification->data->object->id); |
|
258 | 258 | |
259 | - if ( isset( $notification->data->object->balance_transaction ) ) { |
|
260 | - $this->update_fees( $order, $notification->data->object->balance_transaction ); |
|
259 | + if (isset($notification->data->object->balance_transaction)) { |
|
260 | + $this->update_fees($order, $notification->data->object->balance_transaction); |
|
261 | 261 | } |
262 | 262 | |
263 | - if ( is_callable( array( $order, 'save' ) ) ) { |
|
263 | + if (is_callable(array($order, 'save'))) { |
|
264 | 264 | $order->save(); |
265 | 265 | } |
266 | 266 | |
267 | 267 | /* translators: transaction id */ |
268 | - $order->update_status( $order->needs_processing() ? 'processing' : 'completed', sprintf( __( 'Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe' ), $notification->data->object->id ) ); |
|
268 | + $order->update_status($order->needs_processing() ? 'processing' : 'completed', sprintf(__('Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe'), $notification->data->object->id)); |
|
269 | 269 | |
270 | 270 | // Check and see if capture is partial. |
271 | - if ( $this->is_partial_capture( $notification ) ) { |
|
272 | - $order->set_total( $this->get_partial_amount_to_charge( $notification ) ); |
|
273 | - $order->add_note( __( 'This charge was partially captured via Stripe Dashboard', 'woocommerce-gateway-stripe' ) ); |
|
271 | + if ($this->is_partial_capture($notification)) { |
|
272 | + $order->set_total($this->get_partial_amount_to_charge($notification)); |
|
273 | + $order->add_note(__('This charge was partially captured via Stripe Dashboard', 'woocommerce-gateway-stripe')); |
|
274 | 274 | $order->save(); |
275 | 275 | } |
276 | 276 | } |
@@ -285,38 +285,38 @@ discard block |
||
285 | 285 | * @version 4.0.0 |
286 | 286 | * @param object $notification |
287 | 287 | */ |
288 | - public function process_webhook_charge_succeeded( $notification ) { |
|
288 | + public function process_webhook_charge_succeeded($notification) { |
|
289 | 289 | // The following payment methods are synchronous so does not need to be handle via webhook. |
290 | - if ( ( isset( $notification->data->object->source->type ) && 'card' === $notification->data->object->source->type ) || ( isset( $notification->data->object->source->type ) && 'three_d_secure' === $notification->data->object->source->type ) ) { |
|
290 | + if ((isset($notification->data->object->source->type) && 'card' === $notification->data->object->source->type) || (isset($notification->data->object->source->type) && 'three_d_secure' === $notification->data->object->source->type)) { |
|
291 | 291 | return; |
292 | 292 | } |
293 | 293 | |
294 | - $order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->id ); |
|
294 | + $order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->id); |
|
295 | 295 | |
296 | - if ( ! $order ) { |
|
297 | - WC_Stripe_Logger::log( 'Could not find order via charge ID: ' . $notification->data->object->id ); |
|
296 | + if ( ! $order) { |
|
297 | + WC_Stripe_Logger::log('Could not find order via charge ID: ' . $notification->data->object->id); |
|
298 | 298 | return; |
299 | 299 | } |
300 | 300 | |
301 | 301 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
302 | 302 | |
303 | - if ( 'on-hold' !== $order->get_status() ) { |
|
303 | + if ('on-hold' !== $order->get_status()) { |
|
304 | 304 | return; |
305 | 305 | } |
306 | 306 | |
307 | 307 | // Store other data such as fees |
308 | - WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, '_transaction_id', $notification->data->object->id ) : $order->set_transaction_id( $notification->data->object->id ); |
|
308 | + WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, '_transaction_id', $notification->data->object->id) : $order->set_transaction_id($notification->data->object->id); |
|
309 | 309 | |
310 | - if ( isset( $notification->data->object->balance_transaction ) ) { |
|
311 | - $this->update_fees( $order, $notification->data->object->balance_transaction ); |
|
310 | + if (isset($notification->data->object->balance_transaction)) { |
|
311 | + $this->update_fees($order, $notification->data->object->balance_transaction); |
|
312 | 312 | } |
313 | 313 | |
314 | - if ( is_callable( array( $order, 'save' ) ) ) { |
|
314 | + if (is_callable(array($order, 'save'))) { |
|
315 | 315 | $order->save(); |
316 | 316 | } |
317 | 317 | |
318 | 318 | /* translators: transaction id */ |
319 | - $order->update_status( $order->needs_processing() ? 'processing' : 'completed', sprintf( __( 'Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe' ), $notification->data->object->id ) ); |
|
319 | + $order->update_status($order->needs_processing() ? 'processing' : 'completed', sprintf(__('Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe'), $notification->data->object->id)); |
|
320 | 320 | } |
321 | 321 | |
322 | 322 | /** |
@@ -327,23 +327,23 @@ discard block |
||
327 | 327 | * @version 4.0.0 |
328 | 328 | * @param object $notification |
329 | 329 | */ |
330 | - public function process_webhook_charge_failed( $notification ) { |
|
331 | - $order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->id ); |
|
330 | + public function process_webhook_charge_failed($notification) { |
|
331 | + $order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->id); |
|
332 | 332 | |
333 | - if ( ! $order ) { |
|
334 | - WC_Stripe_Logger::log( 'Could not find order via charge ID: ' . $notification->data->object->id ); |
|
333 | + if ( ! $order) { |
|
334 | + WC_Stripe_Logger::log('Could not find order via charge ID: ' . $notification->data->object->id); |
|
335 | 335 | return; |
336 | 336 | } |
337 | 337 | |
338 | 338 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
339 | 339 | |
340 | - if ( 'on-hold' !== $order->get_status() ) { |
|
340 | + if ('on-hold' !== $order->get_status()) { |
|
341 | 341 | return; |
342 | 342 | } |
343 | 343 | |
344 | - $order->update_status( 'failed', __( 'This payment failed to clear.', 'woocommerce-gateway-stripe' ) ); |
|
344 | + $order->update_status('failed', __('This payment failed to clear.', 'woocommerce-gateway-stripe')); |
|
345 | 345 | |
346 | - do_action( 'wc_gateway_stripe_process_webhook_payment_error', $order, $notification ); |
|
346 | + do_action('wc_gateway_stripe_process_webhook_payment_error', $order, $notification); |
|
347 | 347 | } |
348 | 348 | |
349 | 349 | /** |
@@ -354,23 +354,23 @@ discard block |
||
354 | 354 | * @version 4.0.0 |
355 | 355 | * @param object $notification |
356 | 356 | */ |
357 | - public function process_webhook_source_canceled( $notification ) { |
|
358 | - $order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->id ); |
|
357 | + public function process_webhook_source_canceled($notification) { |
|
358 | + $order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->id); |
|
359 | 359 | |
360 | - if ( ! $order ) { |
|
361 | - WC_Stripe_Logger::log( 'Could not find order via charge ID: ' . $notification->data->object->id ); |
|
360 | + if ( ! $order) { |
|
361 | + WC_Stripe_Logger::log('Could not find order via charge ID: ' . $notification->data->object->id); |
|
362 | 362 | return; |
363 | 363 | } |
364 | 364 | |
365 | 365 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
366 | 366 | |
367 | - if ( 'on-hold' !== $order->get_status() || 'cancelled' !== $order->get_status() ) { |
|
367 | + if ('on-hold' !== $order->get_status() || 'cancelled' !== $order->get_status()) { |
|
368 | 368 | return; |
369 | 369 | } |
370 | 370 | |
371 | - $order->update_status( 'cancelled', __( 'This payment has cancelled.', 'woocommerce-gateway-stripe' ) ); |
|
371 | + $order->update_status('cancelled', __('This payment has cancelled.', 'woocommerce-gateway-stripe')); |
|
372 | 372 | |
373 | - do_action( 'wc_gateway_stripe_process_webhook_payment_error', $order, $notification ); |
|
373 | + do_action('wc_gateway_stripe_process_webhook_payment_error', $order, $notification); |
|
374 | 374 | } |
375 | 375 | |
376 | 376 | /** |
@@ -381,37 +381,37 @@ discard block |
||
381 | 381 | * @version 4.0.0 |
382 | 382 | * @param object $notification |
383 | 383 | */ |
384 | - public function process_webhook_refund( $notification ) { |
|
385 | - $order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->id ); |
|
384 | + public function process_webhook_refund($notification) { |
|
385 | + $order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->id); |
|
386 | 386 | |
387 | - if ( ! $order ) { |
|
388 | - WC_Stripe_Logger::log( 'Could not find order via charge ID: ' . $notification->data->object->id ); |
|
387 | + if ( ! $order) { |
|
388 | + WC_Stripe_Logger::log('Could not find order via charge ID: ' . $notification->data->object->id); |
|
389 | 389 | return; |
390 | 390 | } |
391 | 391 | |
392 | 392 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
393 | 393 | |
394 | - if ( 'stripe' === ( WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method() ) ) { |
|
395 | - $charge = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_transaction_id', true ) : $order->get_transaction_id(); |
|
396 | - $captured = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_stripe_charge_captured', true ) : $order->get_meta( '_stripe_charge_captured', true ); |
|
397 | - $refund_id = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_stripe_refund_id', true ) : $order->get_meta( '_stripe_refund_id', true ); |
|
394 | + if ('stripe' === (WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method())) { |
|
395 | + $charge = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_transaction_id', true) : $order->get_transaction_id(); |
|
396 | + $captured = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_stripe_charge_captured', true) : $order->get_meta('_stripe_charge_captured', true); |
|
397 | + $refund_id = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_stripe_refund_id', true) : $order->get_meta('_stripe_refund_id', true); |
|
398 | 398 | |
399 | 399 | // If the refund ID matches, don't continue to prevent double refunding. |
400 | - if ( $notification->data->object->refunds->data[0]->id === $refund_id ) { |
|
400 | + if ($notification->data->object->refunds->data[0]->id === $refund_id) { |
|
401 | 401 | return; |
402 | 402 | } |
403 | 403 | |
404 | 404 | // Only refund captured charge. |
405 | - if ( $charge && 'yes' === $captured ) { |
|
405 | + if ($charge && 'yes' === $captured) { |
|
406 | 406 | // Create the refund. |
407 | - $refund = wc_create_refund( array( |
|
407 | + $refund = wc_create_refund(array( |
|
408 | 408 | 'order_id' => $order_id, |
409 | - 'amount' => $this->get_refund_amount( $notification ), |
|
410 | - 'reason' => __( 'Refunded via Stripe Dashboard', 'woocommerce-gateway-stripe' ), |
|
411 | - ) ); |
|
409 | + 'amount' => $this->get_refund_amount($notification), |
|
410 | + 'reason' => __('Refunded via Stripe Dashboard', 'woocommerce-gateway-stripe'), |
|
411 | + )); |
|
412 | 412 | |
413 | - if ( is_wp_error( $refund ) ) { |
|
414 | - WC_Stripe_Logger::log( $refund->get_error_message() ); |
|
413 | + if (is_wp_error($refund)) { |
|
414 | + WC_Stripe_Logger::log($refund->get_error_message()); |
|
415 | 415 | } |
416 | 416 | } |
417 | 417 | } |
@@ -424,7 +424,7 @@ discard block |
||
424 | 424 | * @version 4.0.0 |
425 | 425 | * @param object $notification |
426 | 426 | */ |
427 | - public function is_partial_capture( $notification ) { |
|
427 | + public function is_partial_capture($notification) { |
|
428 | 428 | return 0 < $notification->data->object->amount_refunded; |
429 | 429 | } |
430 | 430 | |
@@ -435,11 +435,11 @@ discard block |
||
435 | 435 | * @version 4.0.0 |
436 | 436 | * @param object $notification |
437 | 437 | */ |
438 | - public function get_refund_amount( $notification ) { |
|
439 | - if ( $this->is_partial_capture( $notification ) ) { |
|
438 | + public function get_refund_amount($notification) { |
|
439 | + if ($this->is_partial_capture($notification)) { |
|
440 | 440 | $amount = $notification->data->object->amount_refunded / 100; |
441 | 441 | |
442 | - if ( in_array( strtolower( $notification->data->object->currency ), WC_Stripe_Helper::no_decimal_currencies() ) ) { |
|
442 | + if (in_array(strtolower($notification->data->object->currency), WC_Stripe_Helper::no_decimal_currencies())) { |
|
443 | 443 | $amount = $notification->data->object->amount_refunded; |
444 | 444 | } |
445 | 445 | |
@@ -456,12 +456,12 @@ discard block |
||
456 | 456 | * @version 4.0.0 |
457 | 457 | * @param object $notification |
458 | 458 | */ |
459 | - public function get_partial_amount_to_charge( $notification ) { |
|
460 | - if ( $this->is_partial_capture( $notification ) ) { |
|
461 | - $amount = ( $notification->data->object->amount - $notification->data->object->amount_refunded ) / 100; |
|
459 | + public function get_partial_amount_to_charge($notification) { |
|
460 | + if ($this->is_partial_capture($notification)) { |
|
461 | + $amount = ($notification->data->object->amount - $notification->data->object->amount_refunded) / 100; |
|
462 | 462 | |
463 | - if ( in_array( strtolower( $notification->data->object->currency ), WC_Stripe_Helper::no_decimal_currencies() ) ) { |
|
464 | - $amount = ( $notification->data->object->amount - $notification->data->object->amount_refunded ); |
|
463 | + if (in_array(strtolower($notification->data->object->currency), WC_Stripe_Helper::no_decimal_currencies())) { |
|
464 | + $amount = ($notification->data->object->amount - $notification->data->object->amount_refunded); |
|
465 | 465 | } |
466 | 466 | |
467 | 467 | return $amount; |
@@ -477,36 +477,36 @@ discard block |
||
477 | 477 | * @version 4.0.0 |
478 | 478 | * @param string $request_body |
479 | 479 | */ |
480 | - public function process_webhook( $request_body ) { |
|
481 | - $notification = json_decode( $request_body ); |
|
480 | + public function process_webhook($request_body) { |
|
481 | + $notification = json_decode($request_body); |
|
482 | 482 | |
483 | - switch ( $notification->type ) { |
|
483 | + switch ($notification->type) { |
|
484 | 484 | case 'source.chargeable': |
485 | - $this->process_webhook_payment( $notification ); |
|
485 | + $this->process_webhook_payment($notification); |
|
486 | 486 | break; |
487 | 487 | |
488 | 488 | case 'source.canceled': |
489 | - $this->process_webhook_source_canceled( $notification ); |
|
489 | + $this->process_webhook_source_canceled($notification); |
|
490 | 490 | break; |
491 | 491 | |
492 | 492 | case 'charge.succeeded': |
493 | - $this->process_webhook_charge_succeeded( $notification ); |
|
493 | + $this->process_webhook_charge_succeeded($notification); |
|
494 | 494 | break; |
495 | 495 | |
496 | 496 | case 'charge.failed': |
497 | - $this->process_webhook_charge_failed( $notification ); |
|
497 | + $this->process_webhook_charge_failed($notification); |
|
498 | 498 | break; |
499 | 499 | |
500 | 500 | case 'charge.captured': |
501 | - $this->process_webhook_capture( $notification ); |
|
501 | + $this->process_webhook_capture($notification); |
|
502 | 502 | break; |
503 | 503 | |
504 | 504 | case 'charge.dispute.created': |
505 | - $this->process_webhook_dispute( $notification ); |
|
505 | + $this->process_webhook_dispute($notification); |
|
506 | 506 | break; |
507 | 507 | |
508 | 508 | case 'charge.refunded': |
509 | - $this->process_webhook_refund( $notification ); |
|
509 | + $this->process_webhook_refund($notification); |
|
510 | 510 | break; |
511 | 511 | |
512 | 512 | } |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if ( ! defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | 5 | |
@@ -20,12 +20,12 @@ discard block |
||
20 | 20 | public function __construct() { |
21 | 21 | self::$_this = $this; |
22 | 22 | |
23 | - add_action( 'wp', array( $this, 'maybe_process_redirect_order' ) ); |
|
24 | - add_action( 'woocommerce_order_status_on-hold_to_processing', array( $this, 'capture_payment' ) ); |
|
25 | - add_action( 'woocommerce_order_status_on-hold_to_completed', array( $this, 'capture_payment' ) ); |
|
26 | - add_action( 'woocommerce_order_status_on-hold_to_cancelled', array( $this, 'cancel_payment' ) ); |
|
27 | - add_action( 'woocommerce_order_status_on-hold_to_refunded', array( $this, 'cancel_payment' ) ); |
|
28 | - add_action( 'wc_ajax_wc_stripe_validate_checkout', array( $this, 'validate_checkout' ) ); |
|
23 | + add_action('wp', array($this, 'maybe_process_redirect_order')); |
|
24 | + add_action('woocommerce_order_status_on-hold_to_processing', array($this, 'capture_payment')); |
|
25 | + add_action('woocommerce_order_status_on-hold_to_completed', array($this, 'capture_payment')); |
|
26 | + add_action('woocommerce_order_status_on-hold_to_cancelled', array($this, 'cancel_payment')); |
|
27 | + add_action('woocommerce_order_status_on-hold_to_refunded', array($this, 'cancel_payment')); |
|
28 | + add_action('wc_ajax_wc_stripe_validate_checkout', array($this, 'validate_checkout')); |
|
29 | 29 | } |
30 | 30 | |
31 | 31 | /** |
@@ -46,25 +46,25 @@ discard block |
||
46 | 46 | * @since 4.0.0 |
47 | 47 | * @version 4.0.0 |
48 | 48 | */ |
49 | - public function process_redirect_payment( $order_id, $retry = true ) { |
|
49 | + public function process_redirect_payment($order_id, $retry = true) { |
|
50 | 50 | try { |
51 | - $source = wc_clean( $_GET['source'] ); |
|
51 | + $source = wc_clean($_GET['source']); |
|
52 | 52 | |
53 | - if ( empty( $source ) ) { |
|
53 | + if (empty($source)) { |
|
54 | 54 | return; |
55 | 55 | } |
56 | 56 | |
57 | - if ( empty( $order_id ) ) { |
|
57 | + if (empty($order_id)) { |
|
58 | 58 | return; |
59 | 59 | } |
60 | 60 | |
61 | - $order = wc_get_order( $order_id ); |
|
61 | + $order = wc_get_order($order_id); |
|
62 | 62 | |
63 | - if ( ! is_object( $order ) ) { |
|
63 | + if ( ! is_object($order)) { |
|
64 | 64 | return; |
65 | 65 | } |
66 | 66 | |
67 | - if ( 'processing' === $order->get_status() || 'completed' === $order->get_status() || 'on-hold' === $order->get_status() ) { |
|
67 | + if ('processing' === $order->get_status() || 'completed' === $order->get_status() || 'on-hold' === $order->get_status()) { |
|
68 | 68 | return; |
69 | 69 | } |
70 | 70 | |
@@ -72,101 +72,101 @@ discard block |
||
72 | 72 | $response = null; |
73 | 73 | |
74 | 74 | // This will throw exception if not valid. |
75 | - $this->validate_minimum_order_amount( $order ); |
|
75 | + $this->validate_minimum_order_amount($order); |
|
76 | 76 | |
77 | - WC_Stripe_Logger::log( "Info: (Redirect) Begin processing payment for order $order_id for the amount of {$order->get_total()}" ); |
|
77 | + WC_Stripe_Logger::log("Info: (Redirect) Begin processing payment for order $order_id for the amount of {$order->get_total()}"); |
|
78 | 78 | |
79 | 79 | // Prep source object. |
80 | 80 | $source_object = new stdClass(); |
81 | 81 | $source_object->token_id = ''; |
82 | - $source_object->customer = $this->get_stripe_customer_id( $order ); |
|
82 | + $source_object->customer = $this->get_stripe_customer_id($order); |
|
83 | 83 | $source_object->source = $source; |
84 | 84 | |
85 | 85 | /** |
86 | 86 | * First check if the source is chargeable at this time. If not, |
87 | 87 | * webhook will take care of it later. |
88 | 88 | */ |
89 | - $source_info = WC_Stripe_API::retrieve( 'sources/' . $source ); |
|
89 | + $source_info = WC_Stripe_API::retrieve('sources/' . $source); |
|
90 | 90 | |
91 | - if ( ! empty( $source_info->error ) ) { |
|
92 | - throw new WC_Stripe_Exception( print_r( $source_info, true ), $source_info->error->message ); |
|
91 | + if ( ! empty($source_info->error)) { |
|
92 | + throw new WC_Stripe_Exception(print_r($source_info, true), $source_info->error->message); |
|
93 | 93 | } |
94 | 94 | |
95 | - if ( 'failed' === $source_info->status || 'canceled' === $source_info->status ) { |
|
96 | - throw new WC_Stripe_Exception( print_r( $source_info, true ), __( 'Unable to process this payment, please try again or use alternative method.', 'woocommerce-gateway-stripe' ) ); |
|
95 | + if ('failed' === $source_info->status || 'canceled' === $source_info->status) { |
|
96 | + throw new WC_Stripe_Exception(print_r($source_info, true), __('Unable to process this payment, please try again or use alternative method.', 'woocommerce-gateway-stripe')); |
|
97 | 97 | } |
98 | 98 | |
99 | 99 | // If already consumed, then ignore request. |
100 | - if ( 'consumed' === $source_info->status ) { |
|
100 | + if ('consumed' === $source_info->status) { |
|
101 | 101 | return; |
102 | 102 | } |
103 | 103 | |
104 | 104 | // If not chargeable, then ignore request. |
105 | - if ( 'chargeable' !== $source_info->status ) { |
|
105 | + if ('chargeable' !== $source_info->status) { |
|
106 | 106 | return; |
107 | 107 | } |
108 | 108 | |
109 | 109 | // Make the request. |
110 | - $response = WC_Stripe_API::request( $this->generate_payment_request( $order, $source_object ) ); |
|
110 | + $response = WC_Stripe_API::request($this->generate_payment_request($order, $source_object)); |
|
111 | 111 | |
112 | - if ( ! empty( $response->error ) ) { |
|
112 | + if ( ! empty($response->error)) { |
|
113 | 113 | // If it is an API error such connection or server, let's retry. |
114 | - if ( 'api_connection_error' === $response->error->type || 'api_error' === $response->error->type ) { |
|
115 | - if ( $retry ) { |
|
116 | - sleep( 5 ); |
|
117 | - return $this->process_redirect_payment( $order_id, false ); |
|
114 | + if ('api_connection_error' === $response->error->type || 'api_error' === $response->error->type) { |
|
115 | + if ($retry) { |
|
116 | + sleep(5); |
|
117 | + return $this->process_redirect_payment($order_id, false); |
|
118 | 118 | } else { |
119 | 119 | $message = 'API connection error and retries exhausted.'; |
120 | - $order->add_order_note( $message ); |
|
121 | - throw new WC_Stripe_Exception( print_r( $response, true ), $message ); |
|
120 | + $order->add_order_note($message); |
|
121 | + throw new WC_Stripe_Exception(print_r($response, true), $message); |
|
122 | 122 | } |
123 | 123 | } |
124 | 124 | |
125 | 125 | // Customer param wrong? The user may have been deleted on stripe's end. Remove customer_id. Can be retried without. |
126 | - if ( preg_match( '/No such customer/i', $response->error->message ) && $retry ) { |
|
127 | - delete_user_meta( WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id(), '_stripe_customer_id' ); |
|
126 | + if (preg_match('/No such customer/i', $response->error->message) && $retry) { |
|
127 | + delete_user_meta(WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id(), '_stripe_customer_id'); |
|
128 | 128 | |
129 | - return $this->process_redirect_payment( $order_id, false ); |
|
129 | + return $this->process_redirect_payment($order_id, false); |
|
130 | 130 | |
131 | - } elseif ( preg_match( '/No such token/i', $response->error->message ) && $source_object->token_id ) { |
|
131 | + } elseif (preg_match('/No such token/i', $response->error->message) && $source_object->token_id) { |
|
132 | 132 | // Source param wrong? The CARD may have been deleted on stripe's end. Remove token and show message. |
133 | 133 | |
134 | - $wc_token = WC_Payment_Tokens::get( $source_object->token_id ); |
|
134 | + $wc_token = WC_Payment_Tokens::get($source_object->token_id); |
|
135 | 135 | $wc_token->delete(); |
136 | - $message = __( 'This card is no longer available and has been removed.', 'woocommerce-gateway-stripe' ); |
|
137 | - $order->add_order_note( $message ); |
|
138 | - throw new WC_Stripe_Exception( print_r( $response, true ), $message ); |
|
136 | + $message = __('This card is no longer available and has been removed.', 'woocommerce-gateway-stripe'); |
|
137 | + $order->add_order_note($message); |
|
138 | + throw new WC_Stripe_Exception(print_r($response, true), $message); |
|
139 | 139 | } |
140 | 140 | |
141 | 141 | $localized_messages = WC_Stripe_Helper::get_localized_messages(); |
142 | 142 | |
143 | - if ( 'card_error' === $response->error->type ) { |
|
144 | - $message = isset( $localized_messages[ $response->error->code ] ) ? $localized_messages[ $response->error->code ] : $response->error->message; |
|
143 | + if ('card_error' === $response->error->type) { |
|
144 | + $message = isset($localized_messages[$response->error->code]) ? $localized_messages[$response->error->code] : $response->error->message; |
|
145 | 145 | } else { |
146 | - $message = isset( $localized_messages[ $response->error->type ] ) ? $localized_messages[ $response->error->type ] : $response->error->message; |
|
146 | + $message = isset($localized_messages[$response->error->type]) ? $localized_messages[$response->error->type] : $response->error->message; |
|
147 | 147 | } |
148 | 148 | |
149 | - throw new WC_Stripe_Exception( print_r( $response, true ), $message ); |
|
149 | + throw new WC_Stripe_Exception(print_r($response, true), $message); |
|
150 | 150 | } |
151 | 151 | |
152 | - do_action( 'wc_gateway_stripe_process_redirect_payment', $response, $order ); |
|
152 | + do_action('wc_gateway_stripe_process_redirect_payment', $response, $order); |
|
153 | 153 | |
154 | - $this->process_response( $response, $order ); |
|
154 | + $this->process_response($response, $order); |
|
155 | 155 | |
156 | - } catch ( WC_Stripe_Exception $e ) { |
|
157 | - WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() ); |
|
156 | + } catch (WC_Stripe_Exception $e) { |
|
157 | + WC_Stripe_Logger::log('Error: ' . $e->getMessage()); |
|
158 | 158 | |
159 | - do_action( 'wc_gateway_stripe_process_redirect_payment_error', $e, $order ); |
|
159 | + do_action('wc_gateway_stripe_process_redirect_payment_error', $e, $order); |
|
160 | 160 | |
161 | 161 | /* translators: error message */ |
162 | - $order->update_status( 'failed', sprintf( __( 'Stripe payment failed: %s', 'woocommerce-gateway-stripe' ), $e->getLocalizedMessage() ) ); |
|
162 | + $order->update_status('failed', sprintf(__('Stripe payment failed: %s', 'woocommerce-gateway-stripe'), $e->getLocalizedMessage())); |
|
163 | 163 | |
164 | - if ( $order->has_status( array( 'pending', 'failed' ) ) ) { |
|
165 | - $this->send_failed_order_email( $order_id ); |
|
164 | + if ($order->has_status(array('pending', 'failed'))) { |
|
165 | + $this->send_failed_order_email($order_id); |
|
166 | 166 | } |
167 | 167 | |
168 | - wc_add_notice( $e->getLocalizedMessage(), 'error' ); |
|
169 | - wp_safe_redirect( wc_get_checkout_url() ); |
|
168 | + wc_add_notice($e->getLocalizedMessage(), 'error'); |
|
169 | + wp_safe_redirect(wc_get_checkout_url()); |
|
170 | 170 | exit; |
171 | 171 | } |
172 | 172 | } |
@@ -178,13 +178,13 @@ discard block |
||
178 | 178 | * @version 4.0.0 |
179 | 179 | */ |
180 | 180 | public function maybe_process_redirect_order() { |
181 | - if ( ! is_order_received_page() || empty( $_GET['client_secret'] ) || empty( $_GET['source'] ) ) { |
|
181 | + if ( ! is_order_received_page() || empty($_GET['client_secret']) || empty($_GET['source'])) { |
|
182 | 182 | return; |
183 | 183 | } |
184 | 184 | |
185 | - $order_id = wc_clean( $_GET['order_id'] ); |
|
185 | + $order_id = wc_clean($_GET['order_id']); |
|
186 | 186 | |
187 | - $this->process_redirect_payment( $order_id ); |
|
187 | + $this->process_redirect_payment($order_id); |
|
188 | 188 | } |
189 | 189 | |
190 | 190 | /** |
@@ -194,52 +194,52 @@ discard block |
||
194 | 194 | * @version 4.0.0 |
195 | 195 | * @param int $order_id |
196 | 196 | */ |
197 | - public function capture_payment( $order_id ) { |
|
198 | - $order = wc_get_order( $order_id ); |
|
197 | + public function capture_payment($order_id) { |
|
198 | + $order = wc_get_order($order_id); |
|
199 | 199 | |
200 | - if ( 'stripe' === ( WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method() ) ) { |
|
201 | - $charge = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_transaction_id', true ) : $order->get_transaction_id(); |
|
202 | - $captured = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_stripe_charge_captured', true ) : $order->get_meta( '_stripe_charge_captured', true ); |
|
200 | + if ('stripe' === (WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method())) { |
|
201 | + $charge = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_transaction_id', true) : $order->get_transaction_id(); |
|
202 | + $captured = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_stripe_charge_captured', true) : $order->get_meta('_stripe_charge_captured', true); |
|
203 | 203 | |
204 | - if ( $charge && 'no' === $captured ) { |
|
204 | + if ($charge && 'no' === $captured) { |
|
205 | 205 | $order_total = $order->get_total(); |
206 | 206 | |
207 | - if ( 0 < $order->get_total_refunded() ) { |
|
207 | + if (0 < $order->get_total_refunded()) { |
|
208 | 208 | $order_total = $order_total - $order->get_total_refunded(); |
209 | 209 | } |
210 | 210 | |
211 | - $result = WC_Stripe_API::request( array( |
|
212 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $order_total ), |
|
211 | + $result = WC_Stripe_API::request(array( |
|
212 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($order_total), |
|
213 | 213 | 'expand[]' => 'balance_transaction', |
214 | - ), 'charges/' . $charge . '/capture' ); |
|
214 | + ), 'charges/' . $charge . '/capture'); |
|
215 | 215 | |
216 | - if ( ! empty( $result->error ) ) { |
|
216 | + if ( ! empty($result->error)) { |
|
217 | 217 | /* translators: error message */ |
218 | - $order->update_status( 'failed', sprintf( __( 'Unable to capture charge! %s', 'woocommerce-gateway-stripe' ), $result->error->message ) ); |
|
218 | + $order->update_status('failed', sprintf(__('Unable to capture charge! %s', 'woocommerce-gateway-stripe'), $result->error->message)); |
|
219 | 219 | } else { |
220 | 220 | /* translators: transaction id */ |
221 | - $order->add_order_note( sprintf( __( 'Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe' ), $result->id ) ); |
|
222 | - WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, '_stripe_charge_captured', 'yes' ) : $order->update_meta_data( '_stripe_charge_captured', 'yes' ); |
|
221 | + $order->add_order_note(sprintf(__('Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe'), $result->id)); |
|
222 | + WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, '_stripe_charge_captured', 'yes') : $order->update_meta_data('_stripe_charge_captured', 'yes'); |
|
223 | 223 | |
224 | 224 | // Store other data such as fees |
225 | - WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, '_transaction_id', $result->id ) : $order->set_transaction_id( $result->id ); |
|
225 | + WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, '_transaction_id', $result->id) : $order->set_transaction_id($result->id); |
|
226 | 226 | |
227 | - if ( isset( $result->balance_transaction ) && isset( $result->balance_transaction->fee ) ) { |
|
227 | + if (isset($result->balance_transaction) && isset($result->balance_transaction->fee)) { |
|
228 | 228 | // Fees and Net needs to both come from Stripe to be accurate as the returned |
229 | 229 | // values are in the local currency of the Stripe account, not from WC. |
230 | - $fee = ! empty( $result->balance_transaction->fee ) ? WC_Stripe_Helper::format_balance_fee( $result->balance_transaction, 'fee' ) : 0; |
|
231 | - $net = ! empty( $result->balance_transaction->net ) ? WC_Stripe_Helper::format_balance_fee( $result->balance_transaction, 'net' ) : 0; |
|
232 | - WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, parent::META_NAME_FEE, $fee ) : $order->update_meta_data( parent::META_NAME_FEE, $fee ); |
|
233 | - WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, parent::META_NAME_NET, $net ) : $order->update_meta_data( parent::META_NAME_NET, $net ); |
|
230 | + $fee = ! empty($result->balance_transaction->fee) ? WC_Stripe_Helper::format_balance_fee($result->balance_transaction, 'fee') : 0; |
|
231 | + $net = ! empty($result->balance_transaction->net) ? WC_Stripe_Helper::format_balance_fee($result->balance_transaction, 'net') : 0; |
|
232 | + WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, parent::META_NAME_FEE, $fee) : $order->update_meta_data(parent::META_NAME_FEE, $fee); |
|
233 | + WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, parent::META_NAME_NET, $net) : $order->update_meta_data(parent::META_NAME_NET, $net); |
|
234 | 234 | } |
235 | 235 | |
236 | - if ( is_callable( array( $order, 'save' ) ) ) { |
|
236 | + if (is_callable(array($order, 'save'))) { |
|
237 | 237 | $order->save(); |
238 | 238 | } |
239 | 239 | } |
240 | 240 | |
241 | 241 | // This hook fires when admin manually changes order status to processing or completed. |
242 | - do_action( 'woocommerce_stripe_process_manual_capture', $order, $result ); |
|
242 | + do_action('woocommerce_stripe_process_manual_capture', $order, $result); |
|
243 | 243 | } |
244 | 244 | } |
245 | 245 | } |
@@ -251,32 +251,32 @@ discard block |
||
251 | 251 | * @version 4.0.0 |
252 | 252 | * @param int $order_id |
253 | 253 | */ |
254 | - public function cancel_payment( $order_id ) { |
|
255 | - $order = wc_get_order( $order_id ); |
|
254 | + public function cancel_payment($order_id) { |
|
255 | + $order = wc_get_order($order_id); |
|
256 | 256 | |
257 | - if ( 'stripe' === ( WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method() ) ) { |
|
258 | - $charge_id = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_transaction_id', true ) : $order->get_transaction_id(); |
|
257 | + if ('stripe' === (WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method())) { |
|
258 | + $charge_id = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_transaction_id', true) : $order->get_transaction_id(); |
|
259 | 259 | |
260 | - if ( $charge_id ) { |
|
261 | - $result = WC_Stripe_API::request( array( |
|
262 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $order->get_total() ), |
|
263 | - ), 'charges/' . $charge_id . '/refund' ); |
|
260 | + if ($charge_id) { |
|
261 | + $result = WC_Stripe_API::request(array( |
|
262 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($order->get_total()), |
|
263 | + ), 'charges/' . $charge_id . '/refund'); |
|
264 | 264 | |
265 | - if ( ! empty( $result->error ) ) { |
|
266 | - $order->add_order_note( __( 'Unable to refund charge!', 'woocommerce-gateway-stripe' ) . ' ' . $result->error->message ); |
|
265 | + if ( ! empty($result->error)) { |
|
266 | + $order->add_order_note(__('Unable to refund charge!', 'woocommerce-gateway-stripe') . ' ' . $result->error->message); |
|
267 | 267 | } else { |
268 | 268 | /* translators: transaction id */ |
269 | - $order->add_order_note( sprintf( __( 'Stripe charge refunded (Charge ID: %s)', 'woocommerce-gateway-stripe' ), $result->id ) ); |
|
270 | - WC_Stripe_Helper::is_pre_30() ? delete_post_meta( $order_id, '_stripe_charge_captured' ) : $order->delete_meta_data( '_stripe_charge_captured' ); |
|
271 | - WC_Stripe_Helper::is_pre_30() ? delete_post_meta( $order_id, '_transaction_id' ) : $order->delete_meta_data( '_stripe_transaction_id' ); |
|
269 | + $order->add_order_note(sprintf(__('Stripe charge refunded (Charge ID: %s)', 'woocommerce-gateway-stripe'), $result->id)); |
|
270 | + WC_Stripe_Helper::is_pre_30() ? delete_post_meta($order_id, '_stripe_charge_captured') : $order->delete_meta_data('_stripe_charge_captured'); |
|
271 | + WC_Stripe_Helper::is_pre_30() ? delete_post_meta($order_id, '_transaction_id') : $order->delete_meta_data('_stripe_transaction_id'); |
|
272 | 272 | |
273 | - if ( is_callable( array( $order, 'save' ) ) ) { |
|
273 | + if (is_callable(array($order, 'save'))) { |
|
274 | 274 | $order->save(); |
275 | 275 | } |
276 | 276 | } |
277 | 277 | |
278 | 278 | // This hook fires when admin manually changes order status to cancel. |
279 | - do_action( 'woocommerce_stripe_process_manual_cancel', $order, $result ); |
|
279 | + do_action('woocommerce_stripe_process_manual_cancel', $order, $result); |
|
280 | 280 | } |
281 | 281 | } |
282 | 282 | } |
@@ -289,21 +289,21 @@ discard block |
||
289 | 289 | * @param string $field |
290 | 290 | * @return string $error_field |
291 | 291 | */ |
292 | - public function normalize_field( $field ) { |
|
292 | + public function normalize_field($field) { |
|
293 | 293 | $checkout_fields = WC()->checkout->get_checkout_fields(); |
294 | 294 | $org_str = array(); |
295 | 295 | $replace_str = array(); |
296 | 296 | |
297 | - if ( array_key_exists( $field, $checkout_fields['billing'] ) ) { |
|
298 | - $error_field = __( 'Billing', 'woocommerce-gateway-stripe' ) . ' ' . $checkout_fields['billing'][ $field ]['label']; |
|
299 | - } elseif ( array_key_exists( $field, $checkout_fields['shipping'] ) ) { |
|
300 | - $error_field = __( 'Shipping', 'woocommerce-gateway-stripe' ) . ' ' . $checkout_fields['shipping'][ $field ]['label']; |
|
301 | - } elseif ( array_key_exists( $field, $checkout_fields['order'] ) ) { |
|
302 | - $error_field = $checkout_fields['order'][ $field ]['label']; |
|
303 | - } elseif ( array_key_exists( $field, $checkout_fields['account'] ) ) { |
|
304 | - $error_field = $checkout_fields['account'][ $field ]['label']; |
|
297 | + if (array_key_exists($field, $checkout_fields['billing'])) { |
|
298 | + $error_field = __('Billing', 'woocommerce-gateway-stripe') . ' ' . $checkout_fields['billing'][$field]['label']; |
|
299 | + } elseif (array_key_exists($field, $checkout_fields['shipping'])) { |
|
300 | + $error_field = __('Shipping', 'woocommerce-gateway-stripe') . ' ' . $checkout_fields['shipping'][$field]['label']; |
|
301 | + } elseif (array_key_exists($field, $checkout_fields['order'])) { |
|
302 | + $error_field = $checkout_fields['order'][$field]['label']; |
|
303 | + } elseif (array_key_exists($field, $checkout_fields['account'])) { |
|
304 | + $error_field = $checkout_fields['account'][$field]['label']; |
|
305 | 305 | } else { |
306 | - $error_field = str_replace( '_', ' ', $field ); |
|
306 | + $error_field = str_replace('_', ' ', $field); |
|
307 | 307 | |
308 | 308 | $org_str[] = 'stripe'; |
309 | 309 | $replace_str[] = ''; |
@@ -318,9 +318,9 @@ discard block |
||
318 | 318 | $replace_str[] = 'SOFORT'; |
319 | 319 | |
320 | 320 | $org_str[] = 'owner'; |
321 | - $replace_str[] = __( 'Owner', 'woocommerce-gateway-stripe' ); |
|
321 | + $replace_str[] = __('Owner', 'woocommerce-gateway-stripe'); |
|
322 | 322 | |
323 | - $error_field = str_replace( $org_str, $replace_str, $error_field ); |
|
323 | + $error_field = str_replace($org_str, $replace_str, $error_field); |
|
324 | 324 | } |
325 | 325 | |
326 | 326 | return $error_field; |
@@ -333,157 +333,157 @@ discard block |
||
333 | 333 | * @version 4.0.0 |
334 | 334 | */ |
335 | 335 | public function validate_checkout() { |
336 | - if ( ! wp_verify_nonce( $_POST['nonce'], '_wc_stripe_nonce' ) ) { |
|
337 | - wp_die( __( 'Cheatin’ huh?', 'woocommerce-gateway-stripe' ) ); |
|
336 | + if ( ! wp_verify_nonce($_POST['nonce'], '_wc_stripe_nonce')) { |
|
337 | + wp_die(__('Cheatin’ huh?', 'woocommerce-gateway-stripe')); |
|
338 | 338 | } |
339 | 339 | |
340 | 340 | $errors = new WP_Error(); |
341 | - parse_str( $_POST['required_fields'], $required_fields ); |
|
342 | - parse_str( $_POST['all_fields'], $all_fields ); |
|
343 | - $source_type = isset( $_POST['source_type'] ) ? wc_clean( $_POST['source_type'] ) : ''; |
|
341 | + parse_str($_POST['required_fields'], $required_fields); |
|
342 | + parse_str($_POST['all_fields'], $all_fields); |
|
343 | + $source_type = isset($_POST['source_type']) ? wc_clean($_POST['source_type']) : ''; |
|
344 | 344 | $validate_shipping_fields = false; |
345 | 345 | $create_account = false; |
346 | 346 | |
347 | - $all_fields = apply_filters( 'wc_stripe_validate_checkout_all_fields', $all_fields ); |
|
348 | - $required_fields = apply_filters( 'wc_stripe_validate_checkout_required_fields', $required_fields ); |
|
347 | + $all_fields = apply_filters('wc_stripe_validate_checkout_all_fields', $all_fields); |
|
348 | + $required_fields = apply_filters('wc_stripe_validate_checkout_required_fields', $required_fields); |
|
349 | 349 | |
350 | - array_walk_recursive( $required_fields, 'wc_clean' ); |
|
351 | - array_walk_recursive( $all_fields, 'wc_clean' ); |
|
350 | + array_walk_recursive($required_fields, 'wc_clean'); |
|
351 | + array_walk_recursive($all_fields, 'wc_clean'); |
|
352 | 352 | |
353 | 353 | // Remove unneeded required fields depending on source type. |
354 | - if ( 'stripe_sepa' !== $source_type ) { |
|
355 | - unset( $required_fields['stripe_sepa_owner'] ); |
|
356 | - unset( $required_fields['stripe_sepa_iban'] ); |
|
354 | + if ('stripe_sepa' !== $source_type) { |
|
355 | + unset($required_fields['stripe_sepa_owner']); |
|
356 | + unset($required_fields['stripe_sepa_iban']); |
|
357 | 357 | } |
358 | 358 | |
359 | - if ( 'stripe_sofort' !== $source_type ) { |
|
360 | - unset( $required_fields['stripe_sofort_bank_country'] ); |
|
359 | + if ('stripe_sofort' !== $source_type) { |
|
360 | + unset($required_fields['stripe_sofort_bank_country']); |
|
361 | 361 | } |
362 | 362 | |
363 | 363 | /** |
364 | 364 | * If ship to different address checkbox is checked then we need |
365 | 365 | * to validate shipping fields too. |
366 | 366 | */ |
367 | - if ( isset( $all_fields['ship_to_different_address'] ) ) { |
|
367 | + if (isset($all_fields['ship_to_different_address'])) { |
|
368 | 368 | $validate_shipping_fields = true; |
369 | 369 | } |
370 | 370 | |
371 | 371 | // Check if createaccount is checked. |
372 | - if ( isset( $all_fields['createaccount'] ) ) { |
|
372 | + if (isset($all_fields['createaccount'])) { |
|
373 | 373 | $create_account = true; |
374 | 374 | } |
375 | 375 | |
376 | 376 | // Check if required fields are empty. |
377 | - foreach ( $required_fields as $field => $field_value ) { |
|
377 | + foreach ($required_fields as $field => $field_value) { |
|
378 | 378 | // Check for shipping field. |
379 | - if ( preg_match( '/^shipping_/', $field ) && ! $validate_shipping_fields ) { |
|
379 | + if (preg_match('/^shipping_/', $field) && ! $validate_shipping_fields) { |
|
380 | 380 | continue; |
381 | 381 | } |
382 | 382 | |
383 | 383 | // Check create account name. |
384 | - if ( 'account_username' === $field && ! $create_account ) { |
|
384 | + if ('account_username' === $field && ! $create_account) { |
|
385 | 385 | continue; |
386 | 386 | } |
387 | 387 | |
388 | 388 | // Check create account password. |
389 | - if ( 'account_password' === $field && ! $create_account ) { |
|
389 | + if ('account_password' === $field && ! $create_account) { |
|
390 | 390 | continue; |
391 | 391 | } |
392 | 392 | |
393 | 393 | // Check if is SEPA. |
394 | - if ( 'stripe_sepa' !== $source_type && 'stripe_sepa_owner' === $field ) { |
|
394 | + if ('stripe_sepa' !== $source_type && 'stripe_sepa_owner' === $field) { |
|
395 | 395 | continue; |
396 | 396 | } |
397 | 397 | |
398 | - if ( 'stripe_sepa' !== $source_type && 'stripe_sepa_iban' === $field ) { |
|
398 | + if ('stripe_sepa' !== $source_type && 'stripe_sepa_iban' === $field) { |
|
399 | 399 | $continue; |
400 | 400 | } |
401 | 401 | |
402 | - if ( empty( $field_value ) || '-1' === $field_value ) { |
|
403 | - $error_field = $this->normalize_field( $field ); |
|
402 | + if (empty($field_value) || '-1' === $field_value) { |
|
403 | + $error_field = $this->normalize_field($field); |
|
404 | 404 | /* translators: error field name */ |
405 | - $errors->add( 'validation', sprintf( __( '<strong>%s</strong> cannot be empty', 'woocommerce-gateway-stripe' ), $error_field ) ); |
|
405 | + $errors->add('validation', sprintf(__('<strong>%s</strong> cannot be empty', 'woocommerce-gateway-stripe'), $error_field)); |
|
406 | 406 | } |
407 | 407 | } |
408 | 408 | |
409 | 409 | // Check if email is valid format. |
410 | - if ( ! empty( $required_fields['billing_email'] ) && ! is_email( $required_fields['billing_email'] ) ) { |
|
411 | - $errors->add( 'validation', __( 'Email is not valid', 'woocommerce-gateway-stripe' ) ); |
|
410 | + if ( ! empty($required_fields['billing_email']) && ! is_email($required_fields['billing_email'])) { |
|
411 | + $errors->add('validation', __('Email is not valid', 'woocommerce-gateway-stripe')); |
|
412 | 412 | } |
413 | 413 | |
414 | 414 | // Check if phone number is valid format. |
415 | - if ( ! empty( $required_fields['billing_phone'] ) ) { |
|
416 | - $phone = wc_format_phone_number( $required_fields['billing_phone'] ); |
|
415 | + if ( ! empty($required_fields['billing_phone'])) { |
|
416 | + $phone = wc_format_phone_number($required_fields['billing_phone']); |
|
417 | 417 | |
418 | - if ( '' !== $phone && ! WC_Validation::is_phone( $phone ) ) { |
|
418 | + if ('' !== $phone && ! WC_Validation::is_phone($phone)) { |
|
419 | 419 | /* translators: %s: phone number */ |
420 | - $errors->add( 'validation', __( 'Please enter a valid phone number.', 'woocommerce-gateway-stripe' ) ); |
|
420 | + $errors->add('validation', __('Please enter a valid phone number.', 'woocommerce-gateway-stripe')); |
|
421 | 421 | } |
422 | 422 | } |
423 | 423 | |
424 | 424 | // Check if postal code is valid format. |
425 | - if ( ! empty( $required_fields['billing_postcode'] ) ) { |
|
426 | - $country = isset( $required_fields['billing_country'] ) ? $required_fields['billing_country'] : WC()->customer->get_billing_country(); |
|
427 | - $postcode = wc_format_postcode( $required_fields['billing_postcode'], $country ); |
|
425 | + if ( ! empty($required_fields['billing_postcode'])) { |
|
426 | + $country = isset($required_fields['billing_country']) ? $required_fields['billing_country'] : WC()->customer->get_billing_country(); |
|
427 | + $postcode = wc_format_postcode($required_fields['billing_postcode'], $country); |
|
428 | 428 | |
429 | - if ( '' !== $required_fields['billing_postcode'] && ! WC_Validation::is_postcode( $postcode, $country ) ) { |
|
430 | - $errors->add( 'validation', __( 'Please enter a valid billing postcode / ZIP.', 'woocommerce-gateway-stripe' ) ); |
|
429 | + if ('' !== $required_fields['billing_postcode'] && ! WC_Validation::is_postcode($postcode, $country)) { |
|
430 | + $errors->add('validation', __('Please enter a valid billing postcode / ZIP.', 'woocommerce-gateway-stripe')); |
|
431 | 431 | } |
432 | 432 | } |
433 | 433 | |
434 | 434 | // Don't check this on add payment method page. |
435 | - if ( ( isset( $_POST['is_add_payment_page'] ) && 'no' === $_POST['is_add_payment_page'] ) ) { |
|
436 | - if ( empty( $all_fields['woocommerce_checkout_update_totals'] ) && empty( $all_fields['terms'] ) && apply_filters( 'woocommerce_checkout_show_terms', wc_get_page_id( 'terms' ) > 0 ) ) { |
|
437 | - $errors->add( 'terms', __( 'You must accept our Terms & Conditions.', 'woocommerce-gateway-stripe' ) ); |
|
435 | + if ((isset($_POST['is_add_payment_page']) && 'no' === $_POST['is_add_payment_page'])) { |
|
436 | + if (empty($all_fields['woocommerce_checkout_update_totals']) && empty($all_fields['terms']) && apply_filters('woocommerce_checkout_show_terms', wc_get_page_id('terms') > 0)) { |
|
437 | + $errors->add('terms', __('You must accept our Terms & Conditions.', 'woocommerce-gateway-stripe')); |
|
438 | 438 | } |
439 | 439 | } |
440 | 440 | |
441 | - if ( WC()->cart->needs_shipping() && $validate_shipping_fields ) { |
|
441 | + if (WC()->cart->needs_shipping() && $validate_shipping_fields) { |
|
442 | 442 | // Check if postal code is valid format. |
443 | - if ( ! empty( $required_fields['shipping_postcode'] ) ) { |
|
444 | - $country = isset( $required_fields['shipping_country'] ) ? $required_fields['shipping_country'] : WC()->customer->get_shipping_country(); |
|
445 | - $postcode = wc_format_postcode( $required_fields['shipping_postcode'], $country ); |
|
443 | + if ( ! empty($required_fields['shipping_postcode'])) { |
|
444 | + $country = isset($required_fields['shipping_country']) ? $required_fields['shipping_country'] : WC()->customer->get_shipping_country(); |
|
445 | + $postcode = wc_format_postcode($required_fields['shipping_postcode'], $country); |
|
446 | 446 | |
447 | - if ( '' !== $required_fields['shipping_postcode'] && ! WC_Validation::is_postcode( $postcode, $country ) ) { |
|
448 | - $errors->add( 'validation', __( 'Please enter a valid shipping postcode / ZIP.', 'woocommerce-gateway-stripe' ) ); |
|
447 | + if ('' !== $required_fields['shipping_postcode'] && ! WC_Validation::is_postcode($postcode, $country)) { |
|
448 | + $errors->add('validation', __('Please enter a valid shipping postcode / ZIP.', 'woocommerce-gateway-stripe')); |
|
449 | 449 | } |
450 | 450 | } |
451 | 451 | } |
452 | 452 | |
453 | - if ( WC()->cart->needs_shipping() ) { |
|
453 | + if (WC()->cart->needs_shipping()) { |
|
454 | 454 | $shipping_country = WC()->customer->get_shipping_country(); |
455 | 455 | |
456 | - if ( empty( $shipping_country ) ) { |
|
457 | - $errors->add( 'shipping', __( 'Please enter an address to continue.', 'woocommerce-gateway-stripe' ) ); |
|
458 | - } elseif ( ! in_array( WC()->customer->get_shipping_country(), array_keys( WC()->countries->get_shipping_countries() ) ) ) { |
|
456 | + if (empty($shipping_country)) { |
|
457 | + $errors->add('shipping', __('Please enter an address to continue.', 'woocommerce-gateway-stripe')); |
|
458 | + } elseif ( ! in_array(WC()->customer->get_shipping_country(), array_keys(WC()->countries->get_shipping_countries()))) { |
|
459 | 459 | /* translators: country name */ |
460 | - $errors->add( 'shipping', sprintf( __( 'Unfortunately <strong>we do not ship %s</strong>. Please enter an alternative shipping address.', 'woocommerce-gateway-stripe' ), WC()->countries->shipping_to_prefix() . ' ' . WC()->customer->get_shipping_country() ) ); |
|
460 | + $errors->add('shipping', sprintf(__('Unfortunately <strong>we do not ship %s</strong>. Please enter an alternative shipping address.', 'woocommerce-gateway-stripe'), WC()->countries->shipping_to_prefix() . ' ' . WC()->customer->get_shipping_country())); |
|
461 | 461 | } else { |
462 | - $chosen_shipping_methods = WC()->session->get( 'chosen_shipping_methods' ); |
|
462 | + $chosen_shipping_methods = WC()->session->get('chosen_shipping_methods'); |
|
463 | 463 | |
464 | - foreach ( WC()->shipping->get_packages() as $i => $package ) { |
|
465 | - if ( ! isset( $chosen_shipping_methods[ $i ], $package['rates'][ $chosen_shipping_methods[ $i ] ] ) ) { |
|
466 | - $errors->add( 'shipping', __( 'No shipping method has been selected. Please double check your address, or contact us if you need any help.', 'woocommerce-gateway-stripe' ) ); |
|
464 | + foreach (WC()->shipping->get_packages() as $i => $package) { |
|
465 | + if ( ! isset($chosen_shipping_methods[$i], $package['rates'][$chosen_shipping_methods[$i]])) { |
|
466 | + $errors->add('shipping', __('No shipping method has been selected. Please double check your address, or contact us if you need any help.', 'woocommerce-gateway-stripe')); |
|
467 | 467 | } |
468 | 468 | } |
469 | 469 | } |
470 | 470 | } |
471 | 471 | |
472 | - if ( WC()->cart->needs_payment() ) { |
|
472 | + if (WC()->cart->needs_payment()) { |
|
473 | 473 | $available_gateways = WC()->payment_gateways->get_available_payment_gateways(); |
474 | 474 | |
475 | - if ( ! isset( $available_gateways[ $all_fields['payment_method'] ] ) ) { |
|
476 | - $errors->add( 'payment', __( 'Invalid payment method.', 'woocommerce-gateway-stripe' ) ); |
|
475 | + if ( ! isset($available_gateways[$all_fields['payment_method']])) { |
|
476 | + $errors->add('payment', __('Invalid payment method.', 'woocommerce-gateway-stripe')); |
|
477 | 477 | } else { |
478 | - $available_gateways[ $all_fields['payment_method'] ]->validate_fields(); |
|
478 | + $available_gateways[$all_fields['payment_method']]->validate_fields(); |
|
479 | 479 | } |
480 | 480 | } |
481 | 481 | |
482 | - if ( 0 === count( $errors->errors ) ) { |
|
483 | - wp_send_json( 'success' ); |
|
482 | + if (0 === count($errors->errors)) { |
|
483 | + wp_send_json('success'); |
|
484 | 484 | } else { |
485 | - foreach ( $errors->get_error_messages() as $message ) { |
|
486 | - wc_add_notice( $message, 'error' ); |
|
485 | + foreach ($errors->get_error_messages() as $message) { |
|
486 | + wc_add_notice($message, 'error'); |
|
487 | 487 | } |
488 | 488 | |
489 | 489 | $this->send_ajax_failure_response(); |
@@ -497,9 +497,9 @@ discard block |
||
497 | 497 | * @version 4.0.0 |
498 | 498 | */ |
499 | 499 | public function send_ajax_failure_response() { |
500 | - if ( is_ajax() ) { |
|
500 | + if (is_ajax()) { |
|
501 | 501 | // only print notices if not reloading the checkout, otherwise they're lost in the page reload. |
502 | - if ( ! isset( WC()->session->reload_checkout ) ) { |
|
502 | + if ( ! isset(WC()->session->reload_checkout)) { |
|
503 | 503 | ob_start(); |
504 | 504 | wc_print_notices(); |
505 | 505 | $messages = ob_get_clean(); |
@@ -507,14 +507,14 @@ discard block |
||
507 | 507 | |
508 | 508 | $response = array( |
509 | 509 | 'result' => 'failure', |
510 | - 'messages' => isset( $messages ) ? $messages : '', |
|
511 | - 'refresh' => isset( WC()->session->refresh_totals ), |
|
512 | - 'reload' => isset( WC()->session->reload_checkout ), |
|
510 | + 'messages' => isset($messages) ? $messages : '', |
|
511 | + 'refresh' => isset(WC()->session->refresh_totals), |
|
512 | + 'reload' => isset(WC()->session->reload_checkout), |
|
513 | 513 | ); |
514 | 514 | |
515 | - unset( WC()->session->refresh_totals, WC()->session->reload_checkout ); |
|
515 | + unset(WC()->session->refresh_totals, WC()->session->reload_checkout); |
|
516 | 516 | |
517 | - wp_send_json( $response ); |
|
517 | + wp_send_json($response); |
|
518 | 518 | } |
519 | 519 | } |
520 | 520 | } |
@@ -1,207 +1,207 @@ |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if ( ! defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | 5 | |
6 | 6 | $webhook_url = WC_Stripe_Helper::get_webhook_url(); |
7 | 7 | |
8 | -return apply_filters( 'wc_stripe_settings', |
|
8 | +return apply_filters('wc_stripe_settings', |
|
9 | 9 | array( |
10 | 10 | 'enabled' => array( |
11 | - 'title' => __( 'Enable/Disable', 'woocommerce-gateway-stripe' ), |
|
12 | - 'label' => __( 'Enable Stripe', 'woocommerce-gateway-stripe' ), |
|
11 | + 'title' => __('Enable/Disable', 'woocommerce-gateway-stripe'), |
|
12 | + 'label' => __('Enable Stripe', 'woocommerce-gateway-stripe'), |
|
13 | 13 | 'type' => 'checkbox', |
14 | 14 | 'description' => '', |
15 | 15 | 'default' => 'no', |
16 | 16 | ), |
17 | 17 | 'title' => array( |
18 | - 'title' => __( 'Title', 'woocommerce-gateway-stripe' ), |
|
18 | + 'title' => __('Title', 'woocommerce-gateway-stripe'), |
|
19 | 19 | 'type' => 'text', |
20 | - 'description' => __( 'This controls the title which the user sees during checkout.', 'woocommerce-gateway-stripe' ), |
|
21 | - 'default' => __( 'Credit Card (Stripe)', 'woocommerce-gateway-stripe' ), |
|
20 | + 'description' => __('This controls the title which the user sees during checkout.', 'woocommerce-gateway-stripe'), |
|
21 | + 'default' => __('Credit Card (Stripe)', 'woocommerce-gateway-stripe'), |
|
22 | 22 | 'desc_tip' => true, |
23 | 23 | ), |
24 | 24 | 'description' => array( |
25 | - 'title' => __( 'Description', 'woocommerce-gateway-stripe' ), |
|
25 | + 'title' => __('Description', 'woocommerce-gateway-stripe'), |
|
26 | 26 | 'type' => 'text', |
27 | - 'description' => __( 'This controls the description which the user sees during checkout.', 'woocommerce-gateway-stripe' ), |
|
28 | - 'default' => __( 'Pay with your credit card via Stripe.', 'woocommerce-gateway-stripe' ), |
|
27 | + 'description' => __('This controls the description which the user sees during checkout.', 'woocommerce-gateway-stripe'), |
|
28 | + 'default' => __('Pay with your credit card via Stripe.', 'woocommerce-gateway-stripe'), |
|
29 | 29 | 'desc_tip' => true, |
30 | 30 | ), |
31 | 31 | 'webhook' => array( |
32 | - 'title' => __( 'Webhook Endpoints', 'woocommerce-gateway-stripe' ), |
|
32 | + 'title' => __('Webhook Endpoints', 'woocommerce-gateway-stripe'), |
|
33 | 33 | 'type' => 'title', |
34 | 34 | /* translators: webhook URL */ |
35 | - 'description' => sprintf( __( 'You must add the webhook endpoint <strong style="background-color:#ddd;"> %s </strong> to your Stripe Account Settings <a href="https://dashboard.stripe.com/account/webhooks" target="_blank">Here</a> so you can receive notifications on the charge statuses.', 'woocommerce-gateway-stripe' ), $webhook_url ), |
|
35 | + 'description' => sprintf(__('You must add the webhook endpoint <strong style="background-color:#ddd;"> %s </strong> to your Stripe Account Settings <a href="https://dashboard.stripe.com/account/webhooks" target="_blank">Here</a> so you can receive notifications on the charge statuses.', 'woocommerce-gateway-stripe'), $webhook_url), |
|
36 | 36 | ), |
37 | 37 | 'testmode' => array( |
38 | - 'title' => __( 'Test mode', 'woocommerce-gateway-stripe' ), |
|
39 | - 'label' => __( 'Enable Test Mode', 'woocommerce-gateway-stripe' ), |
|
38 | + 'title' => __('Test mode', 'woocommerce-gateway-stripe'), |
|
39 | + 'label' => __('Enable Test Mode', 'woocommerce-gateway-stripe'), |
|
40 | 40 | 'type' => 'checkbox', |
41 | - 'description' => __( 'Place the payment gateway in test mode using test API keys.', 'woocommerce-gateway-stripe' ), |
|
41 | + 'description' => __('Place the payment gateway in test mode using test API keys.', 'woocommerce-gateway-stripe'), |
|
42 | 42 | 'default' => 'yes', |
43 | 43 | 'desc_tip' => true, |
44 | 44 | ), |
45 | 45 | 'test_publishable_key' => array( |
46 | - 'title' => __( 'Test Publishable Key', 'woocommerce-gateway-stripe' ), |
|
46 | + 'title' => __('Test Publishable Key', 'woocommerce-gateway-stripe'), |
|
47 | 47 | 'type' => 'password', |
48 | - 'description' => __( 'Get your API keys from your stripe account.', 'woocommerce-gateway-stripe' ), |
|
48 | + 'description' => __('Get your API keys from your stripe account.', 'woocommerce-gateway-stripe'), |
|
49 | 49 | 'default' => '', |
50 | 50 | 'desc_tip' => true, |
51 | 51 | ), |
52 | 52 | 'test_secret_key' => array( |
53 | - 'title' => __( 'Test Secret Key', 'woocommerce-gateway-stripe' ), |
|
53 | + 'title' => __('Test Secret Key', 'woocommerce-gateway-stripe'), |
|
54 | 54 | 'type' => 'password', |
55 | - 'description' => __( 'Get your API keys from your stripe account.', 'woocommerce-gateway-stripe' ), |
|
55 | + 'description' => __('Get your API keys from your stripe account.', 'woocommerce-gateway-stripe'), |
|
56 | 56 | 'default' => '', |
57 | 57 | 'desc_tip' => true, |
58 | 58 | ), |
59 | 59 | 'publishable_key' => array( |
60 | - 'title' => __( 'Live Publishable Key', 'woocommerce-gateway-stripe' ), |
|
60 | + 'title' => __('Live Publishable Key', 'woocommerce-gateway-stripe'), |
|
61 | 61 | 'type' => 'password', |
62 | - 'description' => __( 'Get your API keys from your stripe account.', 'woocommerce-gateway-stripe' ), |
|
62 | + 'description' => __('Get your API keys from your stripe account.', 'woocommerce-gateway-stripe'), |
|
63 | 63 | 'default' => '', |
64 | 64 | 'desc_tip' => true, |
65 | 65 | ), |
66 | 66 | 'secret_key' => array( |
67 | - 'title' => __( 'Live Secret Key', 'woocommerce-gateway-stripe' ), |
|
67 | + 'title' => __('Live Secret Key', 'woocommerce-gateway-stripe'), |
|
68 | 68 | 'type' => 'password', |
69 | - 'description' => __( 'Get your API keys from your stripe account.', 'woocommerce-gateway-stripe' ), |
|
69 | + 'description' => __('Get your API keys from your stripe account.', 'woocommerce-gateway-stripe'), |
|
70 | 70 | 'default' => '', |
71 | 71 | 'desc_tip' => true, |
72 | 72 | ), |
73 | 73 | 'inline_cc_form' => array( |
74 | - 'title' => __( 'Inline Credit Card Form', 'woocommerce-gateway-stripe' ), |
|
74 | + 'title' => __('Inline Credit Card Form', 'woocommerce-gateway-stripe'), |
|
75 | 75 | 'type' => 'checkbox', |
76 | - 'description' => __( 'Choose the style you want to show for your credit card form. When unchecked, the credit card form will display separate credit card number field, expiry date field and cvc field.', 'woocommerce-gateway-stripe' ), |
|
76 | + 'description' => __('Choose the style you want to show for your credit card form. When unchecked, the credit card form will display separate credit card number field, expiry date field and cvc field.', 'woocommerce-gateway-stripe'), |
|
77 | 77 | 'default' => 'no', |
78 | 78 | 'desc_tip' => true, |
79 | 79 | ), |
80 | 80 | 'statement_descriptor' => array( |
81 | - 'title' => __( 'Statement Descriptor', 'woocommerce-gateway-stripe' ), |
|
81 | + 'title' => __('Statement Descriptor', 'woocommerce-gateway-stripe'), |
|
82 | 82 | 'type' => 'text', |
83 | - 'description' => __( 'This may be up to 22 characters. The statement description must contain at least one letter, may not include ><"\' characters, and will appear on your customer\'s statement in capital letters.' ), |
|
83 | + 'description' => __('This may be up to 22 characters. The statement description must contain at least one letter, may not include ><"\' characters, and will appear on your customer\'s statement in capital letters.'), |
|
84 | 84 | 'default' => '', |
85 | 85 | 'desc_tip' => true, |
86 | 86 | ), |
87 | 87 | 'capture' => array( |
88 | - 'title' => __( 'Capture', 'woocommerce-gateway-stripe' ), |
|
89 | - 'label' => __( 'Capture charge immediately', 'woocommerce-gateway-stripe' ), |
|
88 | + 'title' => __('Capture', 'woocommerce-gateway-stripe'), |
|
89 | + 'label' => __('Capture charge immediately', 'woocommerce-gateway-stripe'), |
|
90 | 90 | 'type' => 'checkbox', |
91 | - 'description' => __( 'Whether or not to immediately capture the charge. When unchecked, the charge issues an authorization and will need to be captured later. Uncaptured charges expire in 7 days.', 'woocommerce-gateway-stripe' ), |
|
91 | + 'description' => __('Whether or not to immediately capture the charge. When unchecked, the charge issues an authorization and will need to be captured later. Uncaptured charges expire in 7 days.', 'woocommerce-gateway-stripe'), |
|
92 | 92 | 'default' => 'yes', |
93 | 93 | 'desc_tip' => true, |
94 | 94 | ), |
95 | 95 | 'three_d_secure' => array( |
96 | - 'title' => __( '3D Secure', 'woocommerce-gateway-stripe' ), |
|
97 | - 'label' => __( 'Require 3D Secure when applicable', 'woocommerce-gateway-stripe' ), |
|
96 | + 'title' => __('3D Secure', 'woocommerce-gateway-stripe'), |
|
97 | + 'label' => __('Require 3D Secure when applicable', 'woocommerce-gateway-stripe'), |
|
98 | 98 | 'type' => 'checkbox', |
99 | - 'description' => __( 'Some payment methods have 3D Secure feature. This is an extra security layer for your store. Choose how to handle payments when 3D Secure is optional. Enabling would require customers to use 3D Secure when optional.', 'woocommerce-gateway-stripe' ), |
|
99 | + 'description' => __('Some payment methods have 3D Secure feature. This is an extra security layer for your store. Choose how to handle payments when 3D Secure is optional. Enabling would require customers to use 3D Secure when optional.', 'woocommerce-gateway-stripe'), |
|
100 | 100 | 'default' => 'no', |
101 | 101 | 'desc_tip' => true, |
102 | 102 | ), |
103 | 103 | 'stripe_checkout' => array( |
104 | - 'title' => __( 'Stripe Checkout', 'woocommerce-gateway-stripe' ), |
|
105 | - 'label' => __( 'Enable Stripe Checkout', 'woocommerce-gateway-stripe' ), |
|
104 | + 'title' => __('Stripe Checkout', 'woocommerce-gateway-stripe'), |
|
105 | + 'label' => __('Enable Stripe Checkout', 'woocommerce-gateway-stripe'), |
|
106 | 106 | 'type' => 'checkbox', |
107 | - 'description' => __( 'If enabled, this option shows a "pay" button and modal credit card form on the checkout, instead of credit card fields directly on the page.', 'woocommerce-gateway-stripe' ), |
|
107 | + 'description' => __('If enabled, this option shows a "pay" button and modal credit card form on the checkout, instead of credit card fields directly on the page.', 'woocommerce-gateway-stripe'), |
|
108 | 108 | 'default' => 'no', |
109 | 109 | 'desc_tip' => true, |
110 | 110 | ), |
111 | 111 | 'stripe_checkout_locale' => array( |
112 | - 'title' => __( 'Stripe Checkout locale', 'woocommerce-gateway-stripe' ), |
|
112 | + 'title' => __('Stripe Checkout locale', 'woocommerce-gateway-stripe'), |
|
113 | 113 | 'type' => 'select', |
114 | 114 | 'class' => 'wc-enhanced-select', |
115 | - 'description' => __( 'Language to display in Stripe Checkout modal. Specify Auto to display Checkout in the user\'s preferred language, if available. English will be used by default.', 'woocommerce-gateway-stripe' ), |
|
115 | + 'description' => __('Language to display in Stripe Checkout modal. Specify Auto to display Checkout in the user\'s preferred language, if available. English will be used by default.', 'woocommerce-gateway-stripe'), |
|
116 | 116 | 'default' => 'en', |
117 | 117 | 'desc_tip' => true, |
118 | 118 | 'options' => array( |
119 | - 'auto' => __( 'Auto', 'woocommerce-gateway-stripe' ), |
|
120 | - 'zh' => __( 'Simplified Chinese', 'woocommerce-gateway-stripe' ), |
|
121 | - 'da' => __( 'Danish', 'woocommerce-gateway-stripe' ), |
|
122 | - 'nl' => __( 'Dutch', 'woocommerce-gateway-stripe' ), |
|
123 | - 'en' => __( 'English', 'woocommerce-gateway-stripe' ), |
|
124 | - 'fi' => __( 'Finnish', 'woocommerce-gateway-stripe' ), |
|
125 | - 'fr' => __( 'French', 'woocommerce-gateway-stripe' ), |
|
126 | - 'de' => __( 'German', 'woocommerce-gateway-stripe' ), |
|
127 | - 'it' => __( 'Italian', 'woocommerce-gateway-stripe' ), |
|
128 | - 'ja' => __( 'Japanese', 'woocommerce-gateway-stripe' ), |
|
129 | - 'no' => __( 'Norwegian', 'woocommerce-gateway-stripe' ), |
|
130 | - 'es' => __( 'Spanish', 'woocommerce-gateway-stripe' ), |
|
131 | - 'sv' => __( 'Swedish', 'woocommerce-gateway-stripe' ), |
|
119 | + 'auto' => __('Auto', 'woocommerce-gateway-stripe'), |
|
120 | + 'zh' => __('Simplified Chinese', 'woocommerce-gateway-stripe'), |
|
121 | + 'da' => __('Danish', 'woocommerce-gateway-stripe'), |
|
122 | + 'nl' => __('Dutch', 'woocommerce-gateway-stripe'), |
|
123 | + 'en' => __('English', 'woocommerce-gateway-stripe'), |
|
124 | + 'fi' => __('Finnish', 'woocommerce-gateway-stripe'), |
|
125 | + 'fr' => __('French', 'woocommerce-gateway-stripe'), |
|
126 | + 'de' => __('German', 'woocommerce-gateway-stripe'), |
|
127 | + 'it' => __('Italian', 'woocommerce-gateway-stripe'), |
|
128 | + 'ja' => __('Japanese', 'woocommerce-gateway-stripe'), |
|
129 | + 'no' => __('Norwegian', 'woocommerce-gateway-stripe'), |
|
130 | + 'es' => __('Spanish', 'woocommerce-gateway-stripe'), |
|
131 | + 'sv' => __('Swedish', 'woocommerce-gateway-stripe'), |
|
132 | 132 | ), |
133 | 133 | ), |
134 | 134 | 'stripe_bitcoin' => array( |
135 | - 'title' => __( 'Bitcoin Currency', 'woocommerce-gateway-stripe' ), |
|
136 | - 'label' => __( 'Enable Bitcoin Currency', 'woocommerce-gateway-stripe' ), |
|
135 | + 'title' => __('Bitcoin Currency', 'woocommerce-gateway-stripe'), |
|
136 | + 'label' => __('Enable Bitcoin Currency', 'woocommerce-gateway-stripe'), |
|
137 | 137 | 'type' => 'checkbox', |
138 | - 'description' => __( 'If enabled, an option to accept bitcoin will show on the checkout modal. Note: Stripe Checkout needs to be enabled and store currency must be set to USD.', 'woocommerce-gateway-stripe' ), |
|
138 | + 'description' => __('If enabled, an option to accept bitcoin will show on the checkout modal. Note: Stripe Checkout needs to be enabled and store currency must be set to USD.', 'woocommerce-gateway-stripe'), |
|
139 | 139 | 'default' => 'no', |
140 | 140 | 'desc_tip' => true, |
141 | 141 | ), |
142 | 142 | 'stripe_checkout_image' => array( |
143 | - 'title' => __( 'Stripe Checkout Image', 'woocommerce-gateway-stripe' ), |
|
144 | - 'description' => __( 'Optionally enter the URL to a 128x128px image of your brand or product. e.g. <code>https://yoursite.com/wp-content/uploads/2013/09/yourimage.jpg</code>', 'woocommerce-gateway-stripe' ), |
|
143 | + 'title' => __('Stripe Checkout Image', 'woocommerce-gateway-stripe'), |
|
144 | + 'description' => __('Optionally enter the URL to a 128x128px image of your brand or product. e.g. <code>https://yoursite.com/wp-content/uploads/2013/09/yourimage.jpg</code>', 'woocommerce-gateway-stripe'), |
|
145 | 145 | 'type' => 'text', |
146 | 146 | 'default' => '', |
147 | 147 | 'desc_tip' => true, |
148 | 148 | ), |
149 | 149 | 'payment_request' => array( |
150 | - 'title' => __( 'Payment Request Buttons', 'woocommerce-gateway-stripe' ), |
|
150 | + 'title' => __('Payment Request Buttons', 'woocommerce-gateway-stripe'), |
|
151 | 151 | /* translators: 1) br tag 2) opening anchor tag 3) closing anchor tag */ |
152 | - 'label' => sprintf( __( 'Enable Payment Request Buttons. (Apple Pay/Chrome Payment Request API) %1$sBy using Apple Pay, you agree to %2$s and %3$s\'s terms of service.', 'woocommerce-gateway-stripe' ), '<br />', '<a href="https://stripe.com/apple-pay/legal" target="_blank">Stripe</a>', '<a href="https://developer.apple.com/apple-pay/acceptable-use-guidelines-for-websites/" target="_blank">Apple</a>' ), |
|
152 | + 'label' => sprintf(__('Enable Payment Request Buttons. (Apple Pay/Chrome Payment Request API) %1$sBy using Apple Pay, you agree to %2$s and %3$s\'s terms of service.', 'woocommerce-gateway-stripe'), '<br />', '<a href="https://stripe.com/apple-pay/legal" target="_blank">Stripe</a>', '<a href="https://developer.apple.com/apple-pay/acceptable-use-guidelines-for-websites/" target="_blank">Apple</a>'), |
|
153 | 153 | 'type' => 'checkbox', |
154 | - 'description' => __( 'If enabled, users will be able to pay using Apple Pay or Chrome Payment Request if supported by the browser.', 'woocommerce-gateway-stripe' ), |
|
154 | + 'description' => __('If enabled, users will be able to pay using Apple Pay or Chrome Payment Request if supported by the browser.', 'woocommerce-gateway-stripe'), |
|
155 | 155 | 'default' => 'yes', |
156 | 156 | 'desc_tip' => true, |
157 | 157 | ), |
158 | 158 | 'payment_request_button_type' => array( |
159 | - 'title' => __( 'Payment Request Button Type', 'woocommerce-gateway-stripe' ), |
|
160 | - 'label' => __( 'Button Type', 'woocommerce-gateway-stripe' ), |
|
159 | + 'title' => __('Payment Request Button Type', 'woocommerce-gateway-stripe'), |
|
160 | + 'label' => __('Button Type', 'woocommerce-gateway-stripe'), |
|
161 | 161 | 'type' => 'select', |
162 | - 'description' => __( 'Select the button type you would like to show.', 'woocommerce-gateway-stripe' ), |
|
162 | + 'description' => __('Select the button type you would like to show.', 'woocommerce-gateway-stripe'), |
|
163 | 163 | 'default' => 'buy', |
164 | 164 | 'desc_tip' => true, |
165 | 165 | 'options' => array( |
166 | - 'default' => __( 'Default', 'woocommerce-gateway-stripe' ), |
|
167 | - 'buy' => __( 'Buy', 'woocommerce-gateway-stripe' ), |
|
168 | - 'donate' => __( 'Donate', 'woocommerce-gateway-stripe' ), |
|
166 | + 'default' => __('Default', 'woocommerce-gateway-stripe'), |
|
167 | + 'buy' => __('Buy', 'woocommerce-gateway-stripe'), |
|
168 | + 'donate' => __('Donate', 'woocommerce-gateway-stripe'), |
|
169 | 169 | ), |
170 | 170 | ), |
171 | 171 | 'payment_request_button_theme' => array( |
172 | - 'title' => __( 'Payment Request Button Theme', 'woocommerce-gateway-stripe' ), |
|
173 | - 'label' => __( 'Button Theme', 'woocommerce-gateway-stripe' ), |
|
172 | + 'title' => __('Payment Request Button Theme', 'woocommerce-gateway-stripe'), |
|
173 | + 'label' => __('Button Theme', 'woocommerce-gateway-stripe'), |
|
174 | 174 | 'type' => 'select', |
175 | - 'description' => __( 'Select the button theme you would like to show.', 'woocommerce-gateway-stripe' ), |
|
175 | + 'description' => __('Select the button theme you would like to show.', 'woocommerce-gateway-stripe'), |
|
176 | 176 | 'default' => 'dark', |
177 | 177 | 'desc_tip' => true, |
178 | 178 | 'options' => array( |
179 | - 'dark' => __( 'Dark', 'woocommerce-gateway-stripe' ), |
|
180 | - 'light' => __( 'Light', 'woocommerce-gateway-stripe' ), |
|
181 | - 'light-outline' => __( 'Light-Outline', 'woocommerce-gateway-stripe' ), |
|
179 | + 'dark' => __('Dark', 'woocommerce-gateway-stripe'), |
|
180 | + 'light' => __('Light', 'woocommerce-gateway-stripe'), |
|
181 | + 'light-outline' => __('Light-Outline', 'woocommerce-gateway-stripe'), |
|
182 | 182 | ), |
183 | 183 | ), |
184 | 184 | 'payment_request_button_height' => array( |
185 | - 'title' => __( 'Payment Request Button Height', 'woocommerce-gateway-stripe' ), |
|
186 | - 'label' => __( 'Button Height', 'woocommerce-gateway-stripe' ), |
|
185 | + 'title' => __('Payment Request Button Height', 'woocommerce-gateway-stripe'), |
|
186 | + 'label' => __('Button Height', 'woocommerce-gateway-stripe'), |
|
187 | 187 | 'type' => 'text', |
188 | - 'description' => __( 'Enter the height you would like the button to be in pixels. Width will always be 100%.', 'woocommerce-gateway-stripe' ), |
|
188 | + 'description' => __('Enter the height you would like the button to be in pixels. Width will always be 100%.', 'woocommerce-gateway-stripe'), |
|
189 | 189 | 'default' => '44', |
190 | 190 | 'desc_tip' => true, |
191 | 191 | ), |
192 | 192 | 'saved_cards' => array( |
193 | - 'title' => __( 'Saved Cards', 'woocommerce-gateway-stripe' ), |
|
194 | - 'label' => __( 'Enable Payment via Saved Cards', 'woocommerce-gateway-stripe' ), |
|
193 | + 'title' => __('Saved Cards', 'woocommerce-gateway-stripe'), |
|
194 | + 'label' => __('Enable Payment via Saved Cards', 'woocommerce-gateway-stripe'), |
|
195 | 195 | 'type' => 'checkbox', |
196 | - 'description' => __( 'If enabled, users will be able to pay with a saved card during checkout. Card details are saved on Stripe servers, not on your store.', 'woocommerce-gateway-stripe' ), |
|
196 | + 'description' => __('If enabled, users will be able to pay with a saved card during checkout. Card details are saved on Stripe servers, not on your store.', 'woocommerce-gateway-stripe'), |
|
197 | 197 | 'default' => 'no', |
198 | 198 | 'desc_tip' => true, |
199 | 199 | ), |
200 | 200 | 'logging' => array( |
201 | - 'title' => __( 'Logging', 'woocommerce-gateway-stripe' ), |
|
202 | - 'label' => __( 'Log debug messages', 'woocommerce-gateway-stripe' ), |
|
201 | + 'title' => __('Logging', 'woocommerce-gateway-stripe'), |
|
202 | + 'label' => __('Log debug messages', 'woocommerce-gateway-stripe'), |
|
203 | 203 | 'type' => 'checkbox', |
204 | - 'description' => __( 'Save debug messages to the WooCommerce System Status log.', 'woocommerce-gateway-stripe' ), |
|
204 | + 'description' => __('Save debug messages to the WooCommerce System Status log.', 'woocommerce-gateway-stripe'), |
|
205 | 205 | 'default' => 'no', |
206 | 206 | 'desc_tip' => true, |
207 | 207 | ), |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if ( ! defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | 5 | |
@@ -18,11 +18,11 @@ discard block |
||
18 | 18 | * Check if this gateway is enabled |
19 | 19 | */ |
20 | 20 | public function is_available() { |
21 | - if ( 'yes' === $this->enabled ) { |
|
22 | - if ( ! $this->testmode && is_checkout() && ! is_ssl() ) { |
|
21 | + if ('yes' === $this->enabled) { |
|
22 | + if ( ! $this->testmode && is_checkout() && ! is_ssl()) { |
|
23 | 23 | return false; |
24 | 24 | } |
25 | - if ( ! $this->secret_key || ! $this->publishable_key ) { |
|
25 | + if ( ! $this->secret_key || ! $this->publishable_key) { |
|
26 | 26 | return false; |
27 | 27 | } |
28 | 28 | return true; |
@@ -37,8 +37,8 @@ discard block |
||
37 | 37 | * @since 4.0.0 |
38 | 38 | * @version 4.0.0 |
39 | 39 | */ |
40 | - public function add_admin_notice( $slug, $class, $message ) { |
|
41 | - $this->notices[ $slug ] = array( |
|
40 | + public function add_admin_notice($slug, $class, $message) { |
|
41 | + $this->notices[$slug] = array( |
|
42 | 42 | 'class' => $class, |
43 | 43 | 'message' => $message, |
44 | 44 | ); |
@@ -51,8 +51,8 @@ discard block |
||
51 | 51 | * @version 4.0.0 |
52 | 52 | */ |
53 | 53 | public function remove_admin_notice() { |
54 | - if ( did_action( 'woocommerce_update_options' ) ) { |
|
55 | - remove_action( 'admin_notices', array( $this, 'check_environment' ) ); |
|
54 | + if (did_action('woocommerce_update_options')) { |
|
55 | + remove_action('admin_notices', array($this, 'check_environment')); |
|
56 | 56 | } |
57 | 57 | } |
58 | 58 | |
@@ -64,7 +64,7 @@ discard block |
||
64 | 64 | * @return array |
65 | 65 | */ |
66 | 66 | public function payment_icons() { |
67 | - return apply_filters( 'wc_stripe_payment_icons', array( |
|
67 | + return apply_filters('wc_stripe_payment_icons', array( |
|
68 | 68 | 'visa' => '<i class="stripe-pf stripe-pf-visa stripe-pf-right" alt="Visa" aria-hidden="true"></i>', |
69 | 69 | 'amex' => '<i class="stripe-pf stripe-pf-american-express stripe-pf-right" alt="Amex" aria-hidden="true"></i>', |
70 | 70 | 'mastercard' => '<i class="stripe-pf stripe-pf-mastercard stripe-pf-right" alt="Mastercard" aria-hidden="true"></i>', |
@@ -81,7 +81,7 @@ discard block |
||
81 | 81 | 'eps' => '<i class="stripe-pf stripe-pf-eps stripe-pf-right" alt="EPS" aria-hidden="true"></i>', |
82 | 82 | 'sofort' => '<i class="stripe-pf stripe-pf-sofort stripe-pf-right" alt="SOFORT" aria-hidden="true"></i>', |
83 | 83 | 'sepa' => '<i class="stripe-pf stripe-pf-sepa stripe-pf-right" alt="SEPA" aria-hidden="true"></i>', |
84 | - ) ); |
|
84 | + )); |
|
85 | 85 | } |
86 | 86 | |
87 | 87 | /** |
@@ -92,10 +92,10 @@ discard block |
||
92 | 92 | * @version 4.0.0 |
93 | 93 | * @param object $order |
94 | 94 | */ |
95 | - public function validate_minimum_order_amount( $order ) { |
|
96 | - if ( $order->get_total() * 100 < WC_Stripe_Helper::get_minimum_amount() ) { |
|
95 | + public function validate_minimum_order_amount($order) { |
|
96 | + if ($order->get_total() * 100 < WC_Stripe_Helper::get_minimum_amount()) { |
|
97 | 97 | /* translators: 1) dollar amount */ |
98 | - throw new WC_Stripe_Exception( 'Did not meet minimum amount', sprintf( __( 'Sorry, the minimum allowed order total is %1$s to use this payment method.', 'woocommerce-gateway-stripe' ), wc_price( WC_Stripe_Helper::get_minimum_amount() / 100 ) ) ); |
|
98 | + throw new WC_Stripe_Exception('Did not meet minimum amount', sprintf(__('Sorry, the minimum allowed order total is %1$s to use this payment method.', 'woocommerce-gateway-stripe'), wc_price(WC_Stripe_Helper::get_minimum_amount() / 100))); |
|
99 | 99 | } |
100 | 100 | } |
101 | 101 | |
@@ -105,14 +105,14 @@ discard block |
||
105 | 105 | * @since 4.0.0 |
106 | 106 | * @version 4.0.0 |
107 | 107 | */ |
108 | - public function get_transaction_url( $order ) { |
|
109 | - if ( $this->testmode ) { |
|
108 | + public function get_transaction_url($order) { |
|
109 | + if ($this->testmode) { |
|
110 | 110 | $this->view_transaction_url = 'https://dashboard.stripe.com/test/payments/%s'; |
111 | 111 | } else { |
112 | 112 | $this->view_transaction_url = 'https://dashboard.stripe.com/payments/%s'; |
113 | 113 | } |
114 | 114 | |
115 | - return parent::get_transaction_url( $order ); |
|
115 | + return parent::get_transaction_url($order); |
|
116 | 116 | } |
117 | 117 | |
118 | 118 | /** |
@@ -121,15 +121,15 @@ discard block |
||
121 | 121 | * @since 4.0.0 |
122 | 122 | * @version 4.0.0 |
123 | 123 | */ |
124 | - public function get_stripe_customer_id( $order ) { |
|
125 | - $customer = get_user_meta( WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id(), '_stripe_customer_id', true ); |
|
124 | + public function get_stripe_customer_id($order) { |
|
125 | + $customer = get_user_meta(WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id(), '_stripe_customer_id', true); |
|
126 | 126 | |
127 | - if ( empty( $customer ) ) { |
|
127 | + if (empty($customer)) { |
|
128 | 128 | // Try to get it via the order. |
129 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
130 | - return get_post_meta( $order->id, '_stripe_customer_id', true ); |
|
129 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
130 | + return get_post_meta($order->id, '_stripe_customer_id', true); |
|
131 | 131 | } else { |
132 | - return $order->get_meta( '_stripe_customer_id', true ); |
|
132 | + return $order->get_meta('_stripe_customer_id', true); |
|
133 | 133 | } |
134 | 134 | } else { |
135 | 135 | return $customer; |
@@ -146,9 +146,9 @@ discard block |
||
146 | 146 | * @param object $order |
147 | 147 | * @param int $id Stripe session id. |
148 | 148 | */ |
149 | - public function get_stripe_return_url( $order = null, $id = null ) { |
|
150 | - if ( is_object( $order ) ) { |
|
151 | - if ( empty( $id ) ) { |
|
149 | + public function get_stripe_return_url($order = null, $id = null) { |
|
150 | + if (is_object($order)) { |
|
151 | + if (empty($id)) { |
|
152 | 152 | $id = uniqid(); |
153 | 153 | } |
154 | 154 | |
@@ -159,10 +159,10 @@ discard block |
||
159 | 159 | 'order_id' => $order_id, |
160 | 160 | ); |
161 | 161 | |
162 | - return esc_url_raw( add_query_arg( $args, $this->get_return_url( $order ) ) ); |
|
162 | + return esc_url_raw(add_query_arg($args, $this->get_return_url($order))); |
|
163 | 163 | } |
164 | 164 | |
165 | - return esc_url_raw( add_query_arg( array( 'utm_nooverride' => '1' ), $this->get_return_url() ) ); |
|
165 | + return esc_url_raw(add_query_arg(array('utm_nooverride' => '1'), $this->get_return_url())); |
|
166 | 166 | } |
167 | 167 | |
168 | 168 | /** |
@@ -174,27 +174,26 @@ discard block |
||
174 | 174 | * @param object $source |
175 | 175 | * @return array() |
176 | 176 | */ |
177 | - public function generate_payment_request( $order, $source ) { |
|
178 | - $settings = get_option( 'woocommerce_stripe_settings', array() ); |
|
179 | - $statement_descriptor = ! empty( $settings['statement_descriptor'] ) ? str_replace( "'", '', $settings['statement_descriptor'] ) : ''; |
|
180 | - $capture = ! empty( $settings['capture'] ) && 'yes' === $settings['capture'] ? true : false; |
|
177 | + public function generate_payment_request($order, $source) { |
|
178 | + $settings = get_option('woocommerce_stripe_settings', array()); |
|
179 | + $statement_descriptor = ! empty($settings['statement_descriptor']) ? str_replace("'", '', $settings['statement_descriptor']) : ''; |
|
180 | + $capture = ! empty($settings['capture']) && 'yes' === $settings['capture'] ? true : false; |
|
181 | 181 | $post_data = array(); |
182 | - $post_data['currency'] = strtolower( WC_Stripe_Helper::is_pre_30() ? $order->get_order_currency() : $order->get_currency() ); |
|
183 | - $post_data['amount'] = WC_Stripe_Helper::get_stripe_amount( $order->get_total(), $post_data['currency'] ); |
|
182 | + $post_data['currency'] = strtolower(WC_Stripe_Helper::is_pre_30() ? $order->get_order_currency() : $order->get_currency()); |
|
183 | + $post_data['amount'] = WC_Stripe_Helper::get_stripe_amount($order->get_total(), $post_data['currency']); |
|
184 | 184 | /* translators: 1) blog name 2) order number */ |
185 | - $post_data['description'] = sprintf( __( '%1$s - Order %2$s', 'woocommerce-gateway-stripe' ), wp_specialchars_decode( get_bloginfo( 'name' ), ENT_QUOTES ), $order->get_order_number() ); |
|
185 | + $post_data['description'] = sprintf(__('%1$s - Order %2$s', 'woocommerce-gateway-stripe'), wp_specialchars_decode(get_bloginfo('name'), ENT_QUOTES), $order->get_order_number()); |
|
186 | 186 | $billing_email = WC_Stripe_Helper::is_pre_30() ? $order->billing_email : $order->get_billing_email(); |
187 | 187 | $billing_first_name = WC_Stripe_Helper::is_pre_30() ? $order->billing_first_name : $order->get_billing_first_name(); |
188 | 188 | $billing_last_name = WC_Stripe_Helper::is_pre_30() ? $order->billing_last_name : $order->get_billing_last_name(); |
189 | 189 | |
190 | - if ( ! empty( $billing_email ) && apply_filters( 'wc_stripe_send_stripe_receipt', false ) ) { |
|
190 | + if ( ! empty($billing_email) && apply_filters('wc_stripe_send_stripe_receipt', false)) { |
|
191 | 191 | $post_data['receipt_email'] = $billing_email; |
192 | 192 | } |
193 | 193 | |
194 | - switch ( WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method() ) { |
|
195 | - case 'stripe': |
|
196 | - if ( ! empty( $statement_descriptor ) ) { |
|
197 | - $post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor( $statement_descriptor ); |
|
194 | + switch (WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method()) { |
|
195 | + case 'stripe' : if ( ! empty($statement_descriptor)) { |
|
196 | + $post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor($statement_descriptor); |
|
198 | 197 | } |
199 | 198 | |
200 | 199 | $post_data['capture'] = $capture ? 'true' : 'false'; |
@@ -204,18 +203,18 @@ discard block |
||
204 | 203 | $post_data['expand[]'] = 'balance_transaction'; |
205 | 204 | |
206 | 205 | $metadata = array( |
207 | - __( 'customer_name', 'woocommerce-gateway-stripe' ) => sanitize_text_field( $billing_first_name ) . ' ' . sanitize_text_field( $billing_last_name ), |
|
208 | - __( 'customer_email', 'woocommerce-gateway-stripe' ) => sanitize_email( $billing_email ), |
|
206 | + __('customer_name', 'woocommerce-gateway-stripe') => sanitize_text_field($billing_first_name) . ' ' . sanitize_text_field($billing_last_name), |
|
207 | + __('customer_email', 'woocommerce-gateway-stripe') => sanitize_email($billing_email), |
|
209 | 208 | 'order_id' => WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(), |
210 | 209 | ); |
211 | 210 | |
212 | - $post_data['metadata'] = apply_filters( 'wc_stripe_payment_metadata', $metadata, $order, $source ); |
|
211 | + $post_data['metadata'] = apply_filters('wc_stripe_payment_metadata', $metadata, $order, $source); |
|
213 | 212 | |
214 | - if ( $source->customer ) { |
|
213 | + if ($source->customer) { |
|
215 | 214 | $post_data['customer'] = $source->customer; |
216 | 215 | } |
217 | 216 | |
218 | - if ( $source->source ) { |
|
217 | + if ($source->source) { |
|
219 | 218 | $post_data['source'] = $source->source; |
220 | 219 | } |
221 | 220 | |
@@ -227,77 +226,77 @@ discard block |
||
227 | 226 | * @param WC_Order $order |
228 | 227 | * @param object $source |
229 | 228 | */ |
230 | - return apply_filters( 'wc_stripe_generate_payment_request', $post_data, $order, $source ); |
|
229 | + return apply_filters('wc_stripe_generate_payment_request', $post_data, $order, $source); |
|
231 | 230 | } |
232 | 231 | |
233 | 232 | /** |
234 | 233 | * Store extra meta data for an order from a Stripe Response. |
235 | 234 | */ |
236 | - public function process_response( $response, $order ) { |
|
237 | - WC_Stripe_Logger::log( 'Processing response: ' . print_r( $response, true ) ); |
|
235 | + public function process_response($response, $order) { |
|
236 | + WC_Stripe_Logger::log('Processing response: ' . print_r($response, true)); |
|
238 | 237 | |
239 | 238 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
240 | 239 | |
241 | - $captured = ( isset( $response->captured ) && $response->captured ) ? 'yes' : 'no'; |
|
240 | + $captured = (isset($response->captured) && $response->captured) ? 'yes' : 'no'; |
|
242 | 241 | |
243 | 242 | // Store charge data |
244 | - WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, '_stripe_charge_captured', $captured ) : $order->update_meta_data( '_stripe_charge_captured', $captured ); |
|
243 | + WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, '_stripe_charge_captured', $captured) : $order->update_meta_data('_stripe_charge_captured', $captured); |
|
245 | 244 | |
246 | 245 | // Store other data such as fees |
247 | - if ( isset( $response->balance_transaction ) && isset( $response->balance_transaction->fee ) ) { |
|
246 | + if (isset($response->balance_transaction) && isset($response->balance_transaction->fee)) { |
|
248 | 247 | // Fees and Net needs to both come from Stripe to be accurate as the returned |
249 | 248 | // values are in the local currency of the Stripe account, not from WC. |
250 | - $fee = ! empty( $response->balance_transaction->fee ) ? WC_Stripe_Helper::format_balance_fee( $response->balance_transaction, 'fee' ) : 0; |
|
251 | - $net = ! empty( $response->balance_transaction->net ) ? WC_Stripe_Helper::format_balance_fee( $response->balance_transaction, 'net' ) : 0; |
|
252 | - WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, self::META_NAME_FEE, $fee ) : $order->update_meta_data( self::META_NAME_FEE, $fee ); |
|
253 | - WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, self::META_NAME_NET, $net ) : $order->update_meta_data( self::META_NAME_NET, $net ); |
|
249 | + $fee = ! empty($response->balance_transaction->fee) ? WC_Stripe_Helper::format_balance_fee($response->balance_transaction, 'fee') : 0; |
|
250 | + $net = ! empty($response->balance_transaction->net) ? WC_Stripe_Helper::format_balance_fee($response->balance_transaction, 'net') : 0; |
|
251 | + WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, self::META_NAME_FEE, $fee) : $order->update_meta_data(self::META_NAME_FEE, $fee); |
|
252 | + WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, self::META_NAME_NET, $net) : $order->update_meta_data(self::META_NAME_NET, $net); |
|
254 | 253 | } |
255 | 254 | |
256 | - if ( 'yes' === $captured ) { |
|
255 | + if ('yes' === $captured) { |
|
257 | 256 | /** |
258 | 257 | * Charge can be captured but in a pending state. Payment methods |
259 | 258 | * that are asynchronous may take couple days to clear. Webhook will |
260 | 259 | * take care of the status changes. |
261 | 260 | */ |
262 | - if ( 'pending' === $response->status ) { |
|
263 | - if ( ! wc_string_to_bool( get_post_meta( $order_id, '_order_stock_reduced', true ) ) ) { |
|
264 | - WC_Stripe_Helper::is_pre_30() ? $order->reduce_order_stock() : wc_reduce_stock_levels( $order_id ); |
|
261 | + if ('pending' === $response->status) { |
|
262 | + if ( ! wc_string_to_bool(get_post_meta($order_id, '_order_stock_reduced', true))) { |
|
263 | + WC_Stripe_Helper::is_pre_30() ? $order->reduce_order_stock() : wc_reduce_stock_levels($order_id); |
|
265 | 264 | } |
266 | 265 | |
267 | - WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, '_transaction_id', $response->id, true ) : $order->set_transaction_id( $response->id ); |
|
266 | + WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, '_transaction_id', $response->id, true) : $order->set_transaction_id($response->id); |
|
268 | 267 | /* translators: transaction id */ |
269 | - $order->update_status( 'on-hold', sprintf( __( 'Stripe charge awaiting payment: %s.', 'woocommerce-gateway-stripe' ), $response->id ) ); |
|
268 | + $order->update_status('on-hold', sprintf(__('Stripe charge awaiting payment: %s.', 'woocommerce-gateway-stripe'), $response->id)); |
|
270 | 269 | } |
271 | 270 | |
272 | - if ( 'succeeded' === $response->status ) { |
|
273 | - $order->payment_complete( $response->id ); |
|
271 | + if ('succeeded' === $response->status) { |
|
272 | + $order->payment_complete($response->id); |
|
274 | 273 | |
275 | 274 | /* translators: transaction id */ |
276 | - $message = sprintf( __( 'Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe' ), $response->id ); |
|
277 | - $order->add_order_note( $message ); |
|
275 | + $message = sprintf(__('Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe'), $response->id); |
|
276 | + $order->add_order_note($message); |
|
278 | 277 | } |
279 | 278 | |
280 | - if ( 'failed' === $response->status ) { |
|
281 | - $localized_message = __( 'Payment processing failed. Please retry.', 'woocommerce-gateway-stripe' ); |
|
282 | - $order->add_order_note( $localized_message ); |
|
283 | - throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message ); |
|
279 | + if ('failed' === $response->status) { |
|
280 | + $localized_message = __('Payment processing failed. Please retry.', 'woocommerce-gateway-stripe'); |
|
281 | + $order->add_order_note($localized_message); |
|
282 | + throw new WC_Stripe_Exception(print_r($response, true), $localized_message); |
|
284 | 283 | } |
285 | 284 | } else { |
286 | - WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, '_transaction_id', $response->id, true ) : $order->set_transaction_id( $response->id ); |
|
285 | + WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, '_transaction_id', $response->id, true) : $order->set_transaction_id($response->id); |
|
287 | 286 | |
288 | - if ( $order->has_status( array( 'pending', 'failed' ) ) ) { |
|
289 | - WC_Stripe_Helper::is_pre_30() ? $order->reduce_order_stock() : wc_reduce_stock_levels( $order_id ); |
|
287 | + if ($order->has_status(array('pending', 'failed'))) { |
|
288 | + WC_Stripe_Helper::is_pre_30() ? $order->reduce_order_stock() : wc_reduce_stock_levels($order_id); |
|
290 | 289 | } |
291 | 290 | |
292 | 291 | /* translators: transaction id */ |
293 | - $order->update_status( 'on-hold', sprintf( __( 'Stripe charge authorized (Charge ID: %s). Process order to take payment, or cancel to remove the pre-authorization.', 'woocommerce-gateway-stripe' ), $response->id ) ); |
|
292 | + $order->update_status('on-hold', sprintf(__('Stripe charge authorized (Charge ID: %s). Process order to take payment, or cancel to remove the pre-authorization.', 'woocommerce-gateway-stripe'), $response->id)); |
|
294 | 293 | } |
295 | 294 | |
296 | - if ( is_callable( array( $order, 'save' ) ) ) { |
|
295 | + if (is_callable(array($order, 'save'))) { |
|
297 | 296 | $order->save(); |
298 | 297 | } |
299 | 298 | |
300 | - do_action( 'wc_gateway_stripe_process_response', $response, $order ); |
|
299 | + do_action('wc_gateway_stripe_process_response', $response, $order); |
|
301 | 300 | |
302 | 301 | return $response; |
303 | 302 | } |
@@ -310,10 +309,10 @@ discard block |
||
310 | 309 | * @param int $order_id |
311 | 310 | * @return null |
312 | 311 | */ |
313 | - public function send_failed_order_email( $order_id ) { |
|
312 | + public function send_failed_order_email($order_id) { |
|
314 | 313 | $emails = WC()->mailer()->get_emails(); |
315 | - if ( ! empty( $emails ) && ! empty( $order_id ) ) { |
|
316 | - $emails['WC_Email_Failed_Order']->trigger( $order_id ); |
|
314 | + if ( ! empty($emails) && ! empty($order_id)) { |
|
315 | + $emails['WC_Email_Failed_Order']->trigger($order_id); |
|
317 | 316 | } |
318 | 317 | } |
319 | 318 | |
@@ -325,7 +324,7 @@ discard block |
||
325 | 324 | * @param object $order |
326 | 325 | * @return object $details |
327 | 326 | */ |
328 | - public function get_owner_details( $order ) { |
|
327 | + public function get_owner_details($order) { |
|
329 | 328 | $billing_first_name = WC_Stripe_Helper::is_pre_30() ? $order->billing_first_name : $order->get_billing_first_name(); |
330 | 329 | $billing_last_name = WC_Stripe_Helper::is_pre_30() ? $order->billing_last_name : $order->get_billing_last_name(); |
331 | 330 | |
@@ -336,8 +335,8 @@ discard block |
||
336 | 335 | |
337 | 336 | $phone = WC_Stripe_Helper::is_pre_30() ? $order->billing_phone : $order->get_billing_phone(); |
338 | 337 | |
339 | - if ( ! empty( $phone ) ) { |
|
340 | - $details['phone'] = $phone; |
|
338 | + if ( ! empty($phone)) { |
|
339 | + $details['phone'] = $phone; |
|
341 | 340 | } |
342 | 341 | |
343 | 342 | $details['address']['line1'] = WC_Stripe_Helper::is_pre_30() ? $order->billing_address_1 : $order->get_billing_address_1(); |
@@ -347,7 +346,7 @@ discard block |
||
347 | 346 | $details['address']['postal_code'] = WC_Stripe_Helper::is_pre_30() ? $order->billing_postcode : $order->get_billing_postcode(); |
348 | 347 | $details['address']['country'] = WC_Stripe_Helper::is_pre_30() ? $order->billing_country : $order->get_billing_country(); |
349 | 348 | |
350 | - return (object) apply_filters( 'wc_stripe_owner_details', $details, $order ); |
|
349 | + return (object) apply_filters('wc_stripe_owner_details', $details, $order); |
|
351 | 350 | } |
352 | 351 | |
353 | 352 | /** |
@@ -356,16 +355,16 @@ discard block |
||
356 | 355 | * @since 4.0.3 |
357 | 356 | */ |
358 | 357 | public function create_source_object() { |
359 | - $source = ! empty( $_POST['stripe_source'] ) ? wc_clean( $_POST['stripe_source'] ) : ''; |
|
358 | + $source = ! empty($_POST['stripe_source']) ? wc_clean($_POST['stripe_source']) : ''; |
|
360 | 359 | |
361 | - if ( empty( $source ) ) { |
|
360 | + if (empty($source)) { |
|
362 | 361 | return ''; |
363 | 362 | } |
364 | 363 | |
365 | - $source_object = WC_Stripe_API::retrieve( 'sources/' . $source ); |
|
364 | + $source_object = WC_Stripe_API::retrieve('sources/' . $source); |
|
366 | 365 | |
367 | - if ( ! empty( $source_object->error ) ) { |
|
368 | - throw new WC_Stripe_Exception( print_r( $source_object, true ), $source_object->error->message ); |
|
366 | + if ( ! empty($source_object->error)) { |
|
367 | + throw new WC_Stripe_Exception(print_r($source_object, true), $source_object->error->message); |
|
369 | 368 | } |
370 | 369 | |
371 | 370 | return $source_object; |
@@ -385,58 +384,58 @@ discard block |
||
385 | 384 | * @throws Exception When card was not added or for and invalid card. |
386 | 385 | * @return object |
387 | 386 | */ |
388 | - public function prepare_source( $source_object = '', $user_id, $force_save_source = false ) { |
|
389 | - $customer = new WC_Stripe_Customer( $user_id ); |
|
387 | + public function prepare_source($source_object = '', $user_id, $force_save_source = false) { |
|
388 | + $customer = new WC_Stripe_Customer($user_id); |
|
390 | 389 | $set_customer = true; |
391 | - $force_save_source = apply_filters( 'wc_stripe_force_save_source', $force_save_source, $customer ); |
|
390 | + $force_save_source = apply_filters('wc_stripe_force_save_source', $force_save_source, $customer); |
|
392 | 391 | $source = ''; |
393 | 392 | $wc_token_id = false; |
394 | - $payment_method = isset( $_POST['payment_method'] ) ? wc_clean( $_POST['payment_method'] ) : 'stripe'; |
|
393 | + $payment_method = isset($_POST['payment_method']) ? wc_clean($_POST['payment_method']) : 'stripe'; |
|
395 | 394 | |
396 | 395 | // New CC info was entered and we have a new source to process. |
397 | - if ( ! empty( $source_object ) ) { |
|
396 | + if ( ! empty($source_object)) { |
|
398 | 397 | // This gets the source object from Stripe. |
399 | 398 | $source = $source_object; |
400 | 399 | |
401 | 400 | // This checks to see if customer opted to save the payment method to file. |
402 | - $maybe_saved_card = isset( $_POST[ 'wc-' . $payment_method . '-new-payment-method' ] ) && ! empty( $_POST[ 'wc-' . $payment_method . '-new-payment-method' ] ); |
|
401 | + $maybe_saved_card = isset($_POST['wc-' . $payment_method . '-new-payment-method']) && ! empty($_POST['wc-' . $payment_method . '-new-payment-method']); |
|
403 | 402 | |
404 | 403 | /** |
405 | 404 | * This is true if the user wants to store the card to their account. |
406 | 405 | * Criteria to save to file is they are logged in, they opted to save or product requirements and the source is |
407 | 406 | * actually reusable. Either that or force_save_source is true. |
408 | 407 | */ |
409 | - if ( ( $user_id && $this->saved_cards && $maybe_saved_card && 'reusable' === $source->usage ) || $force_save_source ) { |
|
410 | - $source = $customer->add_source( $source->id ); |
|
408 | + if (($user_id && $this->saved_cards && $maybe_saved_card && 'reusable' === $source->usage) || $force_save_source) { |
|
409 | + $source = $customer->add_source($source->id); |
|
411 | 410 | |
412 | - if ( ! empty( $source->error ) ) { |
|
413 | - throw new WC_Stripe_Exception( print_r( $source, true ), $source->error->message ); |
|
411 | + if ( ! empty($source->error)) { |
|
412 | + throw new WC_Stripe_Exception(print_r($source, true), $source->error->message); |
|
414 | 413 | } |
415 | 414 | } else { |
416 | 415 | $source = $source->id; |
417 | 416 | } |
418 | - } elseif ( isset( $_POST[ 'wc-' . $payment_method . '-payment-token' ] ) && 'new' !== $_POST[ 'wc-' . $payment_method . '-payment-token' ] ) { |
|
417 | + } elseif (isset($_POST['wc-' . $payment_method . '-payment-token']) && 'new' !== $_POST['wc-' . $payment_method . '-payment-token']) { |
|
419 | 418 | // Use an existing token, and then process the payment |
420 | 419 | |
421 | - $wc_token_id = wc_clean( $_POST[ 'wc-' . $payment_method . '-payment-token' ] ); |
|
422 | - $wc_token = WC_Payment_Tokens::get( $wc_token_id ); |
|
420 | + $wc_token_id = wc_clean($_POST['wc-' . $payment_method . '-payment-token']); |
|
421 | + $wc_token = WC_Payment_Tokens::get($wc_token_id); |
|
423 | 422 | |
424 | - if ( ! $wc_token || $wc_token->get_user_id() !== get_current_user_id() ) { |
|
425 | - WC()->session->set( 'refresh_totals', true ); |
|
426 | - throw new WC_Stripe_Exception( 'Invalid payment method', __( 'Invalid payment method. Please input a new card number.', 'woocommerce-gateway-stripe' ) ); |
|
423 | + if ( ! $wc_token || $wc_token->get_user_id() !== get_current_user_id()) { |
|
424 | + WC()->session->set('refresh_totals', true); |
|
425 | + throw new WC_Stripe_Exception('Invalid payment method', __('Invalid payment method. Please input a new card number.', 'woocommerce-gateway-stripe')); |
|
427 | 426 | } |
428 | 427 | |
429 | 428 | $source = $wc_token->get_token(); |
430 | - } elseif ( isset( $_POST['stripe_token'] ) && 'new' !== $_POST['stripe_token'] ) { |
|
431 | - $stripe_token = wc_clean( $_POST['stripe_token'] ); |
|
432 | - $maybe_saved_card = isset( $_POST[ 'wc-' . $payment_method . '-new-payment-method' ] ) && ! empty( $_POST[ 'wc-' . $payment_method . '-new-payment-method' ] ); |
|
429 | + } elseif (isset($_POST['stripe_token']) && 'new' !== $_POST['stripe_token']) { |
|
430 | + $stripe_token = wc_clean($_POST['stripe_token']); |
|
431 | + $maybe_saved_card = isset($_POST['wc-' . $payment_method . '-new-payment-method']) && ! empty($_POST['wc-' . $payment_method . '-new-payment-method']); |
|
433 | 432 | |
434 | 433 | // This is true if the user wants to store the card to their account. |
435 | - if ( ( $user_id && $this->saved_cards && $maybe_saved_card ) || $force_save_source ) { |
|
436 | - $source = $customer->add_source( $stripe_token ); |
|
434 | + if (($user_id && $this->saved_cards && $maybe_saved_card) || $force_save_source) { |
|
435 | + $source = $customer->add_source($stripe_token); |
|
437 | 436 | |
438 | - if ( ! empty( $source->error ) ) { |
|
439 | - throw new WC_Stripe_Exception( print_r( $source, true ), $source->error->message ); |
|
437 | + if ( ! empty($source->error)) { |
|
438 | + throw new WC_Stripe_Exception(print_r($source, true), $source->error->message); |
|
440 | 439 | } |
441 | 440 | } else { |
442 | 441 | $set_customer = false; |
@@ -444,7 +443,7 @@ discard block |
||
444 | 443 | } |
445 | 444 | } |
446 | 445 | |
447 | - if ( ! $set_customer ) { |
|
446 | + if ( ! $set_customer) { |
|
448 | 447 | $customer_id = false; |
449 | 448 | } else { |
450 | 449 | $customer_id = $customer->get_id() ? $customer->get_id() : false; |
@@ -465,27 +464,27 @@ discard block |
||
465 | 464 | * @param WC_Order $order For to which the source applies. |
466 | 465 | * @param stdClass $source Source information. |
467 | 466 | */ |
468 | - public function save_source( $order, $source ) { |
|
467 | + public function save_source($order, $source) { |
|
469 | 468 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
470 | 469 | |
471 | 470 | // Store source in the order. |
472 | - if ( $source->customer ) { |
|
473 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
474 | - update_post_meta( $order_id, '_stripe_customer_id', $source->customer ); |
|
471 | + if ($source->customer) { |
|
472 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
473 | + update_post_meta($order_id, '_stripe_customer_id', $source->customer); |
|
475 | 474 | } else { |
476 | - $order->update_meta_data( '_stripe_customer_id', $source->customer ); |
|
475 | + $order->update_meta_data('_stripe_customer_id', $source->customer); |
|
477 | 476 | } |
478 | 477 | } |
479 | 478 | |
480 | - if ( $source->source ) { |
|
481 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
482 | - update_post_meta( $order_id, '_stripe_source_id', $source->source ); |
|
479 | + if ($source->source) { |
|
480 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
481 | + update_post_meta($order_id, '_stripe_source_id', $source->source); |
|
483 | 482 | } else { |
484 | - $order->update_meta_data( '_stripe_source_id', $source->source ); |
|
483 | + $order->update_meta_data('_stripe_source_id', $source->source); |
|
485 | 484 | } |
486 | 485 | } |
487 | 486 | |
488 | - if ( is_callable( array( $order, 'save' ) ) ) { |
|
487 | + if (is_callable(array($order, 'save'))) { |
|
489 | 488 | $order->save(); |
490 | 489 | } |
491 | 490 | } |
@@ -503,35 +502,35 @@ discard block |
||
503 | 502 | * @param object $order |
504 | 503 | * @return object |
505 | 504 | */ |
506 | - public function prepare_order_source( $order = null ) { |
|
505 | + public function prepare_order_source($order = null) { |
|
507 | 506 | $stripe_customer = new WC_Stripe_Customer(); |
508 | 507 | $stripe_source = false; |
509 | 508 | $token_id = false; |
510 | 509 | |
511 | - if ( $order ) { |
|
510 | + if ($order) { |
|
512 | 511 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
513 | 512 | |
514 | - $stripe_customer_id = get_post_meta( $order_id, '_stripe_customer_id', true ); |
|
513 | + $stripe_customer_id = get_post_meta($order_id, '_stripe_customer_id', true); |
|
515 | 514 | |
516 | - if ( $stripe_customer_id ) { |
|
517 | - $stripe_customer->set_id( $stripe_customer_id ); |
|
515 | + if ($stripe_customer_id) { |
|
516 | + $stripe_customer->set_id($stripe_customer_id); |
|
518 | 517 | } |
519 | 518 | |
520 | - $source_id = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_stripe_source_id', true ) : $order->get_meta( '_stripe_source_id', true ); |
|
519 | + $source_id = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_stripe_source_id', true) : $order->get_meta('_stripe_source_id', true); |
|
521 | 520 | |
522 | 521 | // Since 4.0.0, we changed card to source so we need to account for that. |
523 | - if ( empty( $source_id ) ) { |
|
524 | - $source_id = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_stripe_card_id', true ) : $order->get_meta( '_stripe_card_id', true ); |
|
522 | + if (empty($source_id)) { |
|
523 | + $source_id = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_stripe_card_id', true) : $order->get_meta('_stripe_card_id', true); |
|
525 | 524 | |
526 | 525 | // Take this opportunity to update the key name. |
527 | - WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, '_stripe_source_id', $source_id ) : $order->update_meta_data( '_stripe_source_id', $source_id ); |
|
526 | + WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, '_stripe_source_id', $source_id) : $order->update_meta_data('_stripe_source_id', $source_id); |
|
528 | 527 | |
529 | - if ( is_callable( array( $order, 'save' ) ) ) { |
|
528 | + if (is_callable(array($order, 'save'))) { |
|
530 | 529 | $order->save(); |
531 | 530 | } |
532 | 531 | } |
533 | 532 | |
534 | - if ( $source_id ) { |
|
533 | + if ($source_id) { |
|
535 | 534 | $stripe_source = $source_id; |
536 | 535 | } |
537 | 536 | } |
@@ -552,27 +551,27 @@ discard block |
||
552 | 551 | * @param object $order The order object |
553 | 552 | * @param int $balance_transaction_id |
554 | 553 | */ |
555 | - public function update_fees( $order, $balance_transaction_id ) { |
|
554 | + public function update_fees($order, $balance_transaction_id) { |
|
556 | 555 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
557 | 556 | |
558 | - $balance_transaction = WC_Stripe_API::retrieve( 'balance/history/' . $balance_transaction_id ); |
|
557 | + $balance_transaction = WC_Stripe_API::retrieve('balance/history/' . $balance_transaction_id); |
|
559 | 558 | |
560 | - if ( empty( $balance_transaction->error ) ) { |
|
561 | - if ( isset( $balance_transaction ) && isset( $balance_transaction->fee ) ) { |
|
559 | + if (empty($balance_transaction->error)) { |
|
560 | + if (isset($balance_transaction) && isset($balance_transaction->fee)) { |
|
562 | 561 | // Fees and Net needs to both come from Stripe to be accurate as the returned |
563 | 562 | // values are in the local currency of the Stripe account, not from WC. |
564 | - $fee = ! empty( $balance_transaction->fee ) ? WC_Stripe_Helper::format_balance_fee( $balance_transaction, 'fee' ) : 0; |
|
565 | - $net = ! empty( $balance_transaction->net ) ? WC_Stripe_Helper::format_balance_fee( $balance_transaction, 'net' ) : 0; |
|
563 | + $fee = ! empty($balance_transaction->fee) ? WC_Stripe_Helper::format_balance_fee($balance_transaction, 'fee') : 0; |
|
564 | + $net = ! empty($balance_transaction->net) ? WC_Stripe_Helper::format_balance_fee($balance_transaction, 'net') : 0; |
|
566 | 565 | |
567 | - WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, self::META_NAME_FEE, $fee ) : $order->update_meta_data( self::META_NAME_FEE, $fee ); |
|
568 | - WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, self::META_NAME_NET, $net ) : $order->update_meta_data( self::META_NAME_NET, $net ); |
|
566 | + WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, self::META_NAME_FEE, $fee) : $order->update_meta_data(self::META_NAME_FEE, $fee); |
|
567 | + WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, self::META_NAME_NET, $net) : $order->update_meta_data(self::META_NAME_NET, $net); |
|
569 | 568 | |
570 | - if ( is_callable( array( $order, 'save' ) ) ) { |
|
569 | + if (is_callable(array($order, 'save'))) { |
|
571 | 570 | $order->save(); |
572 | 571 | } |
573 | 572 | } |
574 | 573 | } else { |
575 | - WC_Stripe_Logger::log( "Unable to update fees/net meta for order: {$order_id}" ); |
|
574 | + WC_Stripe_Logger::log("Unable to update fees/net meta for order: {$order_id}"); |
|
576 | 575 | } |
577 | 576 | } |
578 | 577 | |
@@ -585,57 +584,57 @@ discard block |
||
585 | 584 | * @param float $amount |
586 | 585 | * @return bool |
587 | 586 | */ |
588 | - public function process_refund( $order_id, $amount = null, $reason = '' ) { |
|
589 | - $order = wc_get_order( $order_id ); |
|
587 | + public function process_refund($order_id, $amount = null, $reason = '') { |
|
588 | + $order = wc_get_order($order_id); |
|
590 | 589 | |
591 | - if ( ! $order || ! $order->get_transaction_id() ) { |
|
590 | + if ( ! $order || ! $order->get_transaction_id()) { |
|
592 | 591 | return false; |
593 | 592 | } |
594 | 593 | |
595 | 594 | $body = array(); |
596 | 595 | |
597 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
598 | - $order_currency = get_post_meta( $order_id, '_order_currency', true ); |
|
596 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
597 | + $order_currency = get_post_meta($order_id, '_order_currency', true); |
|
599 | 598 | } else { |
600 | 599 | $order_currency = $order->get_currency(); |
601 | 600 | } |
602 | 601 | |
603 | - if ( ! is_null( $amount ) ) { |
|
604 | - $body['amount'] = WC_Stripe_Helper::get_stripe_amount( $amount, $order_currency ); |
|
602 | + if ( ! is_null($amount)) { |
|
603 | + $body['amount'] = WC_Stripe_Helper::get_stripe_amount($amount, $order_currency); |
|
605 | 604 | } |
606 | 605 | |
607 | - if ( $reason ) { |
|
606 | + if ($reason) { |
|
608 | 607 | $body['metadata'] = array( |
609 | 608 | 'reason' => $reason, |
610 | 609 | ); |
611 | 610 | } |
612 | 611 | |
613 | - WC_Stripe_Logger::log( "Info: Beginning refund for order {$order->get_transaction_id()} for the amount of {$amount}" ); |
|
612 | + WC_Stripe_Logger::log("Info: Beginning refund for order {$order->get_transaction_id()} for the amount of {$amount}"); |
|
614 | 613 | |
615 | - $response = WC_Stripe_API::request( $body, 'charges/' . $order->get_transaction_id() . '/refunds' ); |
|
614 | + $response = WC_Stripe_API::request($body, 'charges/' . $order->get_transaction_id() . '/refunds'); |
|
616 | 615 | |
617 | - if ( ! empty( $response->error ) ) { |
|
618 | - WC_Stripe_Logger::log( 'Error: ' . $response->error->message ); |
|
616 | + if ( ! empty($response->error)) { |
|
617 | + WC_Stripe_Logger::log('Error: ' . $response->error->message); |
|
619 | 618 | |
620 | 619 | return $response; |
621 | 620 | |
622 | - } elseif ( ! empty( $response->id ) ) { |
|
623 | - WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, '_stripe_refund_id', $response->id ) : $order->update_meta_data( '_stripe_refund_id', $response->id ); |
|
621 | + } elseif ( ! empty($response->id)) { |
|
622 | + WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, '_stripe_refund_id', $response->id) : $order->update_meta_data('_stripe_refund_id', $response->id); |
|
624 | 623 | |
625 | - $amount = wc_price( $response->amount / 100 ); |
|
624 | + $amount = wc_price($response->amount / 100); |
|
626 | 625 | |
627 | - if ( in_array( strtolower( $order->get_currency() ), WC_Stripe_Helper::no_decimal_currencies() ) ) { |
|
628 | - $amount = wc_price( $response->amount ); |
|
626 | + if (in_array(strtolower($order->get_currency()), WC_Stripe_Helper::no_decimal_currencies())) { |
|
627 | + $amount = wc_price($response->amount); |
|
629 | 628 | } |
630 | 629 | |
631 | - if ( isset( $response->balance_transaction ) ) { |
|
632 | - $this->update_fees( $order, $response->balance_transaction ); |
|
630 | + if (isset($response->balance_transaction)) { |
|
631 | + $this->update_fees($order, $response->balance_transaction); |
|
633 | 632 | } |
634 | 633 | |
635 | 634 | /* translators: 1) dollar amount 2) transaction id 3) refund message */ |
636 | - $refund_message = sprintf( __( 'Refunded %1$s - Refund ID: %2$s - Reason: %3$s', 'woocommerce-gateway-stripe' ), $amount, $response->id, $reason ); |
|
637 | - $order->add_order_note( $refund_message ); |
|
638 | - WC_Stripe_Logger::log( 'Success: ' . html_entity_decode( strip_tags( $refund_message ) ) ); |
|
635 | + $refund_message = sprintf(__('Refunded %1$s - Refund ID: %2$s - Reason: %3$s', 'woocommerce-gateway-stripe'), $amount, $response->id, $reason); |
|
636 | + $order->add_order_note($refund_message); |
|
637 | + WC_Stripe_Logger::log('Success: ' . html_entity_decode(strip_tags($refund_message))); |
|
639 | 638 | |
640 | 639 | return true; |
641 | 640 | } |
@@ -650,44 +649,44 @@ discard block |
||
650 | 649 | */ |
651 | 650 | public function add_payment_method() { |
652 | 651 | $error = false; |
653 | - $error_msg = __( 'There was a problem adding the card.', 'woocommerce-gateway-stripe' ); |
|
652 | + $error_msg = __('There was a problem adding the card.', 'woocommerce-gateway-stripe'); |
|
654 | 653 | $source_id = ''; |
655 | 654 | |
656 | - if ( empty( $_POST['stripe_source'] ) && empty( $_POST['stripe_token'] ) || ! is_user_logged_in() ) { |
|
655 | + if (empty($_POST['stripe_source']) && empty($_POST['stripe_token']) || ! is_user_logged_in()) { |
|
657 | 656 | $error = true; |
658 | 657 | } |
659 | 658 | |
660 | - $stripe_customer = new WC_Stripe_Customer( get_current_user_id() ); |
|
659 | + $stripe_customer = new WC_Stripe_Customer(get_current_user_id()); |
|
661 | 660 | |
662 | - $source = ! empty( $_POST['stripe_source'] ) ? wc_clean( $_POST['stripe_source'] ) : ''; |
|
661 | + $source = ! empty($_POST['stripe_source']) ? wc_clean($_POST['stripe_source']) : ''; |
|
663 | 662 | |
664 | - $source_object = WC_Stripe_API::retrieve( 'sources/' . $source ); |
|
663 | + $source_object = WC_Stripe_API::retrieve('sources/' . $source); |
|
665 | 664 | |
666 | - if ( isset( $source_object ) ) { |
|
667 | - if ( ! empty( $source_object->error ) ) { |
|
665 | + if (isset($source_object)) { |
|
666 | + if ( ! empty($source_object->error)) { |
|
668 | 667 | $error = true; |
669 | 668 | } |
670 | 669 | |
671 | 670 | $source_id = $source_object->id; |
672 | - } elseif ( isset( $_POST['stripe_token'] ) ) { |
|
673 | - $source_id = wc_clean( $_POST['stripe_token'] ); |
|
671 | + } elseif (isset($_POST['stripe_token'])) { |
|
672 | + $source_id = wc_clean($_POST['stripe_token']); |
|
674 | 673 | } |
675 | 674 | |
676 | - $response = $stripe_customer->add_source( $source_id ); |
|
675 | + $response = $stripe_customer->add_source($source_id); |
|
677 | 676 | |
678 | - if ( ! $response || is_wp_error( $response ) || ! empty( $response->error ) ) { |
|
677 | + if ( ! $response || is_wp_error($response) || ! empty($response->error)) { |
|
679 | 678 | $error = true; |
680 | 679 | } |
681 | 680 | |
682 | - if ( $error ) { |
|
683 | - wc_add_notice( $error_msg, 'error' ); |
|
684 | - WC_Stripe_Logger::log( 'Add payment method Error: ' . $error_msg ); |
|
681 | + if ($error) { |
|
682 | + wc_add_notice($error_msg, 'error'); |
|
683 | + WC_Stripe_Logger::log('Add payment method Error: ' . $error_msg); |
|
685 | 684 | return; |
686 | 685 | } |
687 | 686 | |
688 | 687 | return array( |
689 | 688 | 'result' => 'success', |
690 | - 'redirect' => wc_get_endpoint_url( 'payment-methods' ), |
|
689 | + 'redirect' => wc_get_endpoint_url('payment-methods'), |
|
691 | 690 | ); |
692 | 691 | } |
693 | 692 | } |