@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if ( ! defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | 5 | |
@@ -72,9 +72,9 @@ discard block |
||
72 | 72 | public function __construct() { |
73 | 73 | $this->retry_interval = 1; |
74 | 74 | $this->id = 'stripe_sepa'; |
75 | - $this->method_title = __( 'Stripe SEPA Direct Debit', 'woocommerce-gateway-stripe' ); |
|
75 | + $this->method_title = __('Stripe SEPA Direct Debit', 'woocommerce-gateway-stripe'); |
|
76 | 76 | /* translators: link */ |
77 | - $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' ) ); |
|
77 | + $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')); |
|
78 | 78 | $this->has_fields = true; |
79 | 79 | $this->supports = array( |
80 | 80 | 'products', |
@@ -100,28 +100,28 @@ discard block |
||
100 | 100 | // Load the settings. |
101 | 101 | $this->init_settings(); |
102 | 102 | |
103 | - $main_settings = get_option( 'woocommerce_stripe_settings' ); |
|
104 | - $this->title = $this->get_option( 'title' ); |
|
105 | - $this->description = $this->get_option( 'description' ); |
|
106 | - $this->enabled = $this->get_option( 'enabled' ); |
|
107 | - $this->testmode = ( ! empty( $main_settings['testmode'] ) && 'yes' === $main_settings['testmode'] ) ? true : false; |
|
108 | - $this->saved_cards = ( ! empty( $main_settings['saved_cards'] ) && 'yes' === $main_settings['saved_cards'] ) ? true : false; |
|
109 | - $this->publishable_key = ! empty( $main_settings['publishable_key'] ) ? $main_settings['publishable_key'] : ''; |
|
110 | - $this->secret_key = ! empty( $main_settings['secret_key'] ) ? $main_settings['secret_key'] : ''; |
|
111 | - $this->statement_descriptor = ! empty( $main_settings['statement_descriptor'] ) ? $main_settings['statement_descriptor'] : ''; |
|
112 | - |
|
113 | - if ( $this->testmode ) { |
|
114 | - $this->publishable_key = ! empty( $main_settings['test_publishable_key'] ) ? $main_settings['test_publishable_key'] : ''; |
|
115 | - $this->secret_key = ! empty( $main_settings['test_secret_key'] ) ? $main_settings['test_secret_key'] : ''; |
|
103 | + $main_settings = get_option('woocommerce_stripe_settings'); |
|
104 | + $this->title = $this->get_option('title'); |
|
105 | + $this->description = $this->get_option('description'); |
|
106 | + $this->enabled = $this->get_option('enabled'); |
|
107 | + $this->testmode = ( ! empty($main_settings['testmode']) && 'yes' === $main_settings['testmode']) ? true : false; |
|
108 | + $this->saved_cards = ( ! empty($main_settings['saved_cards']) && 'yes' === $main_settings['saved_cards']) ? true : false; |
|
109 | + $this->publishable_key = ! empty($main_settings['publishable_key']) ? $main_settings['publishable_key'] : ''; |
|
110 | + $this->secret_key = ! empty($main_settings['secret_key']) ? $main_settings['secret_key'] : ''; |
|
111 | + $this->statement_descriptor = ! empty($main_settings['statement_descriptor']) ? $main_settings['statement_descriptor'] : ''; |
|
112 | + |
|
113 | + if ($this->testmode) { |
|
114 | + $this->publishable_key = ! empty($main_settings['test_publishable_key']) ? $main_settings['test_publishable_key'] : ''; |
|
115 | + $this->secret_key = ! empty($main_settings['test_secret_key']) ? $main_settings['test_secret_key'] : ''; |
|
116 | 116 | } |
117 | 117 | |
118 | - add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) ); |
|
119 | - add_action( 'wp_enqueue_scripts', array( $this, 'payment_scripts' ) ); |
|
118 | + add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options')); |
|
119 | + add_action('wp_enqueue_scripts', array($this, 'payment_scripts')); |
|
120 | 120 | |
121 | - if ( WC_Stripe_Helper::is_pre_orders_exists() ) { |
|
121 | + if (WC_Stripe_Helper::is_pre_orders_exists()) { |
|
122 | 122 | $this->pre_orders = new WC_Stripe_Pre_Orders_Compat(); |
123 | 123 | |
124 | - add_action( 'wc_pre_orders_process_pre_order_completion_payment_' . $this->id, array( $this->pre_orders, 'process_pre_order_release_payment' ) ); |
|
124 | + add_action('wc_pre_orders_process_pre_order_completion_payment_' . $this->id, array($this->pre_orders, 'process_pre_order_release_payment')); |
|
125 | 125 | } |
126 | 126 | } |
127 | 127 | |
@@ -149,11 +149,11 @@ discard block |
||
149 | 149 | * @return bool |
150 | 150 | */ |
151 | 151 | public function is_available() { |
152 | - if ( ! in_array( get_woocommerce_currency(), $this->get_supported_currency() ) ) { |
|
152 | + if ( ! in_array(get_woocommerce_currency(), $this->get_supported_currency())) { |
|
153 | 153 | return false; |
154 | 154 | } |
155 | 155 | |
156 | - if ( is_add_payment_method_page() && ! $this->saved_cards ) { |
|
156 | + if (is_add_payment_method_page() && ! $this->saved_cards) { |
|
157 | 157 | return false; |
158 | 158 | } |
159 | 159 | |
@@ -174,7 +174,7 @@ discard block |
||
174 | 174 | |
175 | 175 | $icons_str .= $icons['sepa']; |
176 | 176 | |
177 | - return apply_filters( 'woocommerce_gateway_icon', $icons_str, $this->id ); |
|
177 | + return apply_filters('woocommerce_gateway_icon', $icons_str, $this->id); |
|
178 | 178 | } |
179 | 179 | |
180 | 180 | /** |
@@ -185,19 +185,19 @@ discard block |
||
185 | 185 | * @access public |
186 | 186 | */ |
187 | 187 | public function payment_scripts() { |
188 | - if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) && ! is_add_payment_method_page() ) { |
|
188 | + if ( ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order']) && ! is_add_payment_method_page()) { |
|
189 | 189 | return; |
190 | 190 | } |
191 | 191 | |
192 | - wp_enqueue_style( 'stripe_styles' ); |
|
193 | - wp_enqueue_script( 'woocommerce_stripe' ); |
|
192 | + wp_enqueue_style('stripe_styles'); |
|
193 | + wp_enqueue_script('woocommerce_stripe'); |
|
194 | 194 | } |
195 | 195 | |
196 | 196 | /** |
197 | 197 | * Initialize Gateway Settings Form Fields. |
198 | 198 | */ |
199 | 199 | public function init_form_fields() { |
200 | - $this->form_fields = require( WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-sepa-settings.php' ); |
|
200 | + $this->form_fields = require(WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-sepa-settings.php'); |
|
201 | 201 | } |
202 | 202 | |
203 | 203 | /** |
@@ -209,7 +209,7 @@ discard block |
||
209 | 209 | */ |
210 | 210 | public function mandate_display() { |
211 | 211 | /* translators: statement descriptor */ |
212 | - printf( __( 'By providing your IBAN and confirming this payment, you are authorizing %s and Stripe, our payment service provider, to send instructions to your bank to debit your account and your bank to debit your account in accordance with those instructions. You are entitled to a refund from your bank under the terms and conditions of your agreement with your bank. A refund must be claimed within 8 weeks starting from the date on which your account was debited.', 'woocommerce-gateway-stripe' ), WC_Stripe_Helper::clean_statement_descriptor( $this->statement_descriptor ) ); |
|
212 | + printf(__('By providing your IBAN and confirming this payment, you are authorizing %s and Stripe, our payment service provider, to send instructions to your bank to debit your account and your bank to debit your account in accordance with those instructions. You are entitled to a refund from your bank under the terms and conditions of your agreement with your bank. A refund must be claimed within 8 weeks starting from the date on which your account was debited.', 'woocommerce-gateway-stripe'), WC_Stripe_Helper::clean_statement_descriptor($this->statement_descriptor)); |
|
213 | 213 | } |
214 | 214 | |
215 | 215 | /** |
@@ -220,12 +220,12 @@ discard block |
||
220 | 220 | */ |
221 | 221 | public function form() { |
222 | 222 | ?> |
223 | - <fieldset id="wc-<?php echo esc_attr( $this->id ); ?>-form" class="wc-payment-form"> |
|
224 | - <?php do_action( 'woocommerce_credit_card_form_start', $this->id ); ?> |
|
223 | + <fieldset id="wc-<?php echo esc_attr($this->id); ?>-form" class="wc-payment-form"> |
|
224 | + <?php do_action('woocommerce_credit_card_form_start', $this->id); ?> |
|
225 | 225 | <p class="wc-stripe-sepa-mandate" style="margin-bottom:40px;"><?php $this->mandate_display(); ?></p> |
226 | 226 | <p class="form-row form-row-wide"> |
227 | 227 | <label for="stripe-iban-element"> |
228 | - <?php esc_html_e( 'IBAN.', 'woocommerce-gateway-stripe' ); ?> <span class="required">*</span> |
|
228 | + <?php esc_html_e('IBAN.', 'woocommerce-gateway-stripe'); ?> <span class="required">*</span> |
|
229 | 229 | </label> |
230 | 230 | <div id="stripe-iban-element" class="wc-stripe-iban-element-field"> |
231 | 231 | <!-- A Stripe Element will be inserted here. --> |
@@ -235,7 +235,7 @@ discard block |
||
235 | 235 | <!-- Used to display form errors --> |
236 | 236 | <div class="stripe-source-errors" role="alert"></div> |
237 | 237 | <br /> |
238 | - <?php do_action( 'woocommerce_credit_card_form_end', $this->id ); ?> |
|
238 | + <?php do_action('woocommerce_credit_card_form_end', $this->id); ?> |
|
239 | 239 | <div class="clear"></div> |
240 | 240 | </fieldset> |
241 | 241 | <?php |
@@ -246,45 +246,45 @@ discard block |
||
246 | 246 | */ |
247 | 247 | public function payment_fields() { |
248 | 248 | $total = WC()->cart->total; |
249 | - $display_tokenization = $this->supports( 'tokenization' ) && is_checkout() && $this->saved_cards; |
|
249 | + $display_tokenization = $this->supports('tokenization') && is_checkout() && $this->saved_cards; |
|
250 | 250 | $description = $this->get_description(); |
251 | - $description = ! empty( $description ) ? $description : ''; |
|
251 | + $description = ! empty($description) ? $description : ''; |
|
252 | 252 | |
253 | 253 | // If paying from order, we need to get total from order not cart. |
254 | - if ( isset( $_GET['pay_for_order'] ) && ! empty( $_GET['key'] ) ) { |
|
255 | - $order = wc_get_order( wc_get_order_id_by_order_key( wc_clean( $_GET['key'] ) ) ); |
|
254 | + if (isset($_GET['pay_for_order']) && ! empty($_GET['key'])) { |
|
255 | + $order = wc_get_order(wc_get_order_id_by_order_key(wc_clean($_GET['key']))); |
|
256 | 256 | $total = $order->get_total(); |
257 | 257 | } |
258 | 258 | |
259 | - if ( is_add_payment_method_page() ) { |
|
259 | + if (is_add_payment_method_page()) { |
|
260 | 260 | $total = ''; |
261 | 261 | } |
262 | 262 | |
263 | 263 | echo '<div |
264 | 264 | id="stripe-sepa_debit-payment-data" |
265 | - data-amount="' . esc_attr( WC_Stripe_Helper::get_stripe_amount( $total ) ) . '" |
|
266 | - data-currency="' . esc_attr( strtolower( get_woocommerce_currency() ) ) . '">'; |
|
265 | + data-amount="' . esc_attr(WC_Stripe_Helper::get_stripe_amount($total)) . '" |
|
266 | + data-currency="' . esc_attr(strtolower(get_woocommerce_currency())) . '">'; |
|
267 | 267 | |
268 | - if ( $this->testmode ) { |
|
269 | - $description .= ' ' . __( 'TEST MODE ENABLED. In test mode, you can use IBAN number DE89370400440532013000.', 'woocommerce-gateway-stripe' ); |
|
268 | + if ($this->testmode) { |
|
269 | + $description .= ' ' . __('TEST MODE ENABLED. In test mode, you can use IBAN number DE89370400440532013000.', 'woocommerce-gateway-stripe'); |
|
270 | 270 | } |
271 | 271 | |
272 | - $description = trim( $description ); |
|
272 | + $description = trim($description); |
|
273 | 273 | |
274 | - echo apply_filters( 'wc_stripe_description', wpautop( wp_kses_post( $description ) ), $this->id ); |
|
274 | + echo apply_filters('wc_stripe_description', wpautop(wp_kses_post($description)), $this->id); |
|
275 | 275 | |
276 | - if ( $display_tokenization ) { |
|
276 | + if ($display_tokenization) { |
|
277 | 277 | $this->tokenization_script(); |
278 | 278 | $this->saved_payment_methods(); |
279 | 279 | } |
280 | 280 | |
281 | 281 | $this->form(); |
282 | 282 | |
283 | - if ( apply_filters( 'wc_stripe_display_save_payment_method_checkbox', $display_tokenization ) && ! is_add_payment_method_page() && ! isset( $_GET['change_payment_method'] ) ) { |
|
283 | + if (apply_filters('wc_stripe_display_save_payment_method_checkbox', $display_tokenization) && ! is_add_payment_method_page() && ! isset($_GET['change_payment_method'])) { |
|
284 | 284 | $this->save_payment_method_checkbox(); |
285 | 285 | } |
286 | 286 | |
287 | - do_action( 'wc_stripe_sepa_payment_fields', $this->id ); |
|
287 | + do_action('wc_stripe_sepa_payment_fields', $this->id); |
|
288 | 288 | |
289 | 289 | echo '</div>'; |
290 | 290 | } |
@@ -300,99 +300,99 @@ discard block |
||
300 | 300 | * |
301 | 301 | * @return array|void |
302 | 302 | */ |
303 | - public function process_payment( $order_id, $retry = true, $force_save_source = false ) { |
|
303 | + public function process_payment($order_id, $retry = true, $force_save_source = false) { |
|
304 | 304 | try { |
305 | - $order = wc_get_order( $order_id ); |
|
305 | + $order = wc_get_order($order_id); |
|
306 | 306 | |
307 | - if ( $this->maybe_process_pre_orders( $order_id ) ) { |
|
308 | - return $this->pre_orders->process_pre_order( $order_id ); |
|
307 | + if ($this->maybe_process_pre_orders($order_id)) { |
|
308 | + return $this->pre_orders->process_pre_order($order_id); |
|
309 | 309 | } |
310 | 310 | |
311 | 311 | // This comes from the create account checkbox in the checkout page. |
312 | - $create_account = ! empty( $_POST['createaccount'] ) ? true : false; |
|
312 | + $create_account = ! empty($_POST['createaccount']) ? true : false; |
|
313 | 313 | |
314 | - if ( $create_account ) { |
|
315 | - $new_customer_id = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->customer_user : $order->get_customer_id(); |
|
316 | - $new_stripe_customer = new WC_Stripe_Customer( $new_customer_id ); |
|
314 | + if ($create_account) { |
|
315 | + $new_customer_id = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->customer_user : $order->get_customer_id(); |
|
316 | + $new_stripe_customer = new WC_Stripe_Customer($new_customer_id); |
|
317 | 317 | $new_stripe_customer->create_customer(); |
318 | 318 | } |
319 | 319 | |
320 | - $prepared_source = $this->prepare_source( get_current_user_id(), $force_save_source ); |
|
320 | + $prepared_source = $this->prepare_source(get_current_user_id(), $force_save_source); |
|
321 | 321 | |
322 | - $this->save_source_to_order( $order, $prepared_source ); |
|
322 | + $this->save_source_to_order($order, $prepared_source); |
|
323 | 323 | |
324 | 324 | // Result from Stripe API request. |
325 | 325 | $response = null; |
326 | 326 | |
327 | - if ( $order->get_total() > 0 ) { |
|
327 | + if ($order->get_total() > 0) { |
|
328 | 328 | // This will throw exception if not valid. |
329 | - $this->validate_minimum_order_amount( $order ); |
|
329 | + $this->validate_minimum_order_amount($order); |
|
330 | 330 | |
331 | - WC_Stripe_Logger::log( "Info: Begin processing payment for order $order_id for the amount of {$order->get_total()}" ); |
|
331 | + WC_Stripe_Logger::log("Info: Begin processing payment for order $order_id for the amount of {$order->get_total()}"); |
|
332 | 332 | |
333 | 333 | // Make the request. |
334 | - $response = WC_Stripe_API::request( $this->generate_payment_request( $order, $prepared_source ) ); |
|
334 | + $response = WC_Stripe_API::request($this->generate_payment_request($order, $prepared_source)); |
|
335 | 335 | |
336 | - if ( ! empty( $response->error ) ) { |
|
336 | + if ( ! empty($response->error)) { |
|
337 | 337 | // Customer param wrong? The user may have been deleted on stripe's end. Remove customer_id. Can be retried without. |
338 | - if ( $this->is_no_such_customer_error( $response->error ) ) { |
|
339 | - if ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ) { |
|
340 | - delete_user_meta( $order->customer_user, '_stripe_customer_id' ); |
|
341 | - delete_post_meta( $order_id, '_stripe_customer_id' ); |
|
338 | + if ($this->is_no_such_customer_error($response->error)) { |
|
339 | + if (WC_Stripe_Helper::is_wc_lt('3.0')) { |
|
340 | + delete_user_meta($order->customer_user, '_stripe_customer_id'); |
|
341 | + delete_post_meta($order_id, '_stripe_customer_id'); |
|
342 | 342 | } else { |
343 | - delete_user_meta( $order->get_customer_id(), '_stripe_customer_id' ); |
|
344 | - $order->delete_meta_data( '_stripe_customer_id' ); |
|
343 | + delete_user_meta($order->get_customer_id(), '_stripe_customer_id'); |
|
344 | + $order->delete_meta_data('_stripe_customer_id'); |
|
345 | 345 | $order->save(); |
346 | 346 | } |
347 | 347 | } |
348 | 348 | |
349 | - if ( $this->is_no_such_token_error( $response->error ) && $prepared_source->token_id ) { |
|
349 | + if ($this->is_no_such_token_error($response->error) && $prepared_source->token_id) { |
|
350 | 350 | // Source param wrong? The CARD may have been deleted on stripe's end. Remove token and show message. |
351 | - $wc_token = WC_Payment_Tokens::get( $prepared_source->token_id ); |
|
351 | + $wc_token = WC_Payment_Tokens::get($prepared_source->token_id); |
|
352 | 352 | $wc_token->delete(); |
353 | - $localized_message = __( 'This card is no longer available and has been removed.', 'woocommerce-gateway-stripe' ); |
|
354 | - $order->add_order_note( $localized_message ); |
|
355 | - throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message ); |
|
353 | + $localized_message = __('This card is no longer available and has been removed.', 'woocommerce-gateway-stripe'); |
|
354 | + $order->add_order_note($localized_message); |
|
355 | + throw new WC_Stripe_Exception(print_r($response, true), $localized_message); |
|
356 | 356 | } |
357 | 357 | |
358 | 358 | // We want to retry. |
359 | - if ( $this->is_retryable_error( $response->error ) ) { |
|
360 | - if ( $retry ) { |
|
359 | + if ($this->is_retryable_error($response->error)) { |
|
360 | + if ($retry) { |
|
361 | 361 | // Don't do anymore retries after this. |
362 | - if ( 5 <= $this->retry_interval ) { |
|
362 | + if (5 <= $this->retry_interval) { |
|
363 | 363 | |
364 | - return $this->process_payment( $order_id, false, $force_save_source ); |
|
364 | + return $this->process_payment($order_id, false, $force_save_source); |
|
365 | 365 | } |
366 | 366 | |
367 | - sleep( $this->retry_interval ); |
|
367 | + sleep($this->retry_interval); |
|
368 | 368 | |
369 | 369 | $this->retry_interval++; |
370 | 370 | |
371 | - return $this->process_payment( $order_id, true, $force_save_source ); |
|
371 | + return $this->process_payment($order_id, true, $force_save_source); |
|
372 | 372 | } else { |
373 | - $localized_message = __( 'Sorry, we are unable to process your payment at this time. Please retry later.', 'woocommerce-gateway-stripe' ); |
|
374 | - $order->add_order_note( $localized_message ); |
|
375 | - throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message ); |
|
373 | + $localized_message = __('Sorry, we are unable to process your payment at this time. Please retry later.', 'woocommerce-gateway-stripe'); |
|
374 | + $order->add_order_note($localized_message); |
|
375 | + throw new WC_Stripe_Exception(print_r($response, true), $localized_message); |
|
376 | 376 | } |
377 | 377 | } |
378 | 378 | |
379 | 379 | $localized_messages = WC_Stripe_Helper::get_localized_messages(); |
380 | 380 | |
381 | - if ( 'card_error' === $response->error->type ) { |
|
382 | - $localized_message = isset( $localized_messages[ $response->error->code ] ) ? $localized_messages[ $response->error->code ] : $response->error->message; |
|
381 | + if ('card_error' === $response->error->type) { |
|
382 | + $localized_message = isset($localized_messages[$response->error->code]) ? $localized_messages[$response->error->code] : $response->error->message; |
|
383 | 383 | } else { |
384 | - $localized_message = isset( $localized_messages[ $response->error->type ] ) ? $localized_messages[ $response->error->type ] : $response->error->message; |
|
384 | + $localized_message = isset($localized_messages[$response->error->type]) ? $localized_messages[$response->error->type] : $response->error->message; |
|
385 | 385 | } |
386 | 386 | |
387 | - $order->add_order_note( $localized_message ); |
|
387 | + $order->add_order_note($localized_message); |
|
388 | 388 | |
389 | - throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message ); |
|
389 | + throw new WC_Stripe_Exception(print_r($response, true), $localized_message); |
|
390 | 390 | } |
391 | 391 | |
392 | - do_action( 'wc_gateway_stripe_process_payment', $response, $order ); |
|
392 | + do_action('wc_gateway_stripe_process_payment', $response, $order); |
|
393 | 393 | |
394 | 394 | // Process valid response. |
395 | - $this->process_response( $response, $order ); |
|
395 | + $this->process_response($response, $order); |
|
396 | 396 | } else { |
397 | 397 | $order->payment_complete(); |
398 | 398 | } |
@@ -403,17 +403,17 @@ discard block |
||
403 | 403 | // Return thank you page redirect. |
404 | 404 | return array( |
405 | 405 | 'result' => 'success', |
406 | - 'redirect' => $this->get_return_url( $order ), |
|
406 | + 'redirect' => $this->get_return_url($order), |
|
407 | 407 | ); |
408 | 408 | |
409 | - } catch ( WC_Stripe_Exception $e ) { |
|
410 | - wc_add_notice( $e->getLocalizedMessage(), 'error' ); |
|
411 | - WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() ); |
|
409 | + } catch (WC_Stripe_Exception $e) { |
|
410 | + wc_add_notice($e->getLocalizedMessage(), 'error'); |
|
411 | + WC_Stripe_Logger::log('Error: ' . $e->getMessage()); |
|
412 | 412 | |
413 | - do_action( 'wc_gateway_stripe_process_payment_error', $e, $order ); |
|
413 | + do_action('wc_gateway_stripe_process_payment_error', $e, $order); |
|
414 | 414 | |
415 | - if ( $order->has_status( array( 'pending', 'failed' ) ) ) { |
|
416 | - $this->send_failed_order_email( $order_id ); |
|
415 | + if ($order->has_status(array('pending', 'failed'))) { |
|
416 | + $this->send_failed_order_email($order_id); |
|
417 | 417 | } |
418 | 418 | |
419 | 419 | return array( |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if ( ! defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | 5 | |
@@ -32,9 +32,9 @@ discard block |
||
32 | 32 | */ |
33 | 33 | public function __construct() { |
34 | 34 | $this->retry_interval = 2; |
35 | - $stripe_settings = get_option( 'woocommerce_stripe_settings', array() ); |
|
36 | - $this->testmode = ( ! empty( $stripe_settings['testmode'] ) && 'yes' === $stripe_settings['testmode'] ) ? true : false; |
|
37 | - add_action( 'woocommerce_api_wc_stripe', array( $this, 'check_for_webhook' ) ); |
|
35 | + $stripe_settings = get_option('woocommerce_stripe_settings', array()); |
|
36 | + $this->testmode = ( ! empty($stripe_settings['testmode']) && 'yes' === $stripe_settings['testmode']) ? true : false; |
|
37 | + add_action('woocommerce_api_wc_stripe', array($this, 'check_for_webhook')); |
|
38 | 38 | } |
39 | 39 | |
40 | 40 | /** |
@@ -44,24 +44,24 @@ discard block |
||
44 | 44 | * @version 4.0.0 |
45 | 45 | */ |
46 | 46 | public function check_for_webhook() { |
47 | - if ( ( 'POST' !== $_SERVER['REQUEST_METHOD'] ) |
|
48 | - || ! isset( $_GET['wc-api'] ) |
|
49 | - || ( 'wc_stripe' !== $_GET['wc-api'] ) |
|
47 | + if (('POST' !== $_SERVER['REQUEST_METHOD']) |
|
48 | + || ! isset($_GET['wc-api']) |
|
49 | + || ('wc_stripe' !== $_GET['wc-api']) |
|
50 | 50 | ) { |
51 | 51 | return; |
52 | 52 | } |
53 | 53 | |
54 | - $request_body = file_get_contents( 'php://input' ); |
|
55 | - $request_headers = array_change_key_case( $this->get_request_headers(), CASE_UPPER ); |
|
54 | + $request_body = file_get_contents('php://input'); |
|
55 | + $request_headers = array_change_key_case($this->get_request_headers(), CASE_UPPER); |
|
56 | 56 | |
57 | 57 | // Validate it to make sure it is legit. |
58 | - if ( $this->is_valid_request( $request_headers, $request_body ) ) { |
|
59 | - $this->process_webhook( $request_body ); |
|
60 | - status_header( 200 ); |
|
58 | + if ($this->is_valid_request($request_headers, $request_body)) { |
|
59 | + $this->process_webhook($request_body); |
|
60 | + status_header(200); |
|
61 | 61 | exit; |
62 | 62 | } else { |
63 | - WC_Stripe_Logger::log( 'Incoming webhook failed validation: ' . print_r( $request_body, true ) ); |
|
64 | - status_header( 400 ); |
|
63 | + WC_Stripe_Logger::log('Incoming webhook failed validation: ' . print_r($request_body, true)); |
|
64 | + status_header(400); |
|
65 | 65 | exit; |
66 | 66 | } |
67 | 67 | } |
@@ -76,12 +76,12 @@ discard block |
||
76 | 76 | * @param string $request_body The request body from Stripe. |
77 | 77 | * @return bool |
78 | 78 | */ |
79 | - public function is_valid_request( $request_headers = null, $request_body = null ) { |
|
80 | - if ( null === $request_headers || null === $request_body ) { |
|
79 | + public function is_valid_request($request_headers = null, $request_body = null) { |
|
80 | + if (null === $request_headers || null === $request_body) { |
|
81 | 81 | return false; |
82 | 82 | } |
83 | 83 | |
84 | - if ( ! empty( $request_headers['USER-AGENT'] ) && ! preg_match( '/Stripe/', $request_headers['USER-AGENT'] ) ) { |
|
84 | + if ( ! empty($request_headers['USER-AGENT']) && ! preg_match('/Stripe/', $request_headers['USER-AGENT'])) { |
|
85 | 85 | return false; |
86 | 86 | } |
87 | 87 | |
@@ -97,12 +97,12 @@ discard block |
||
97 | 97 | * @version 4.0.0 |
98 | 98 | */ |
99 | 99 | public function get_request_headers() { |
100 | - if ( ! function_exists( 'getallheaders' ) ) { |
|
100 | + if ( ! function_exists('getallheaders')) { |
|
101 | 101 | $headers = array(); |
102 | 102 | |
103 | - foreach ( $_SERVER as $name => $value ) { |
|
104 | - if ( 'HTTP_' === substr( $name, 0, 5 ) ) { |
|
105 | - $headers[ str_replace( ' ', '-', ucwords( strtolower( str_replace( '_', ' ', substr( $name, 5 ) ) ) ) ) ] = $value; |
|
103 | + foreach ($_SERVER as $name => $value) { |
|
104 | + if ('HTTP_' === substr($name, 0, 5)) { |
|
105 | + $headers[str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', substr($name, 5)))))] = $value; |
|
106 | 106 | } |
107 | 107 | } |
108 | 108 | |
@@ -121,30 +121,30 @@ discard block |
||
121 | 121 | * @param object $notification |
122 | 122 | * @param bool $retry |
123 | 123 | */ |
124 | - public function process_webhook_payment( $notification, $retry = true ) { |
|
124 | + public function process_webhook_payment($notification, $retry = true) { |
|
125 | 125 | // The following 3 payment methods are synchronous so does not need to be handle via webhook. |
126 | - if ( 'card' === $notification->data->object->type || 'sepa_debit' === $notification->data->object->type || 'three_d_secure' === $notification->data->object->type ) { |
|
126 | + if ('card' === $notification->data->object->type || 'sepa_debit' === $notification->data->object->type || 'three_d_secure' === $notification->data->object->type) { |
|
127 | 127 | return; |
128 | 128 | } |
129 | 129 | |
130 | - $order = WC_Stripe_Helper::get_order_by_source_id( $notification->data->object->id ); |
|
130 | + $order = WC_Stripe_Helper::get_order_by_source_id($notification->data->object->id); |
|
131 | 131 | |
132 | - if ( ! $order ) { |
|
133 | - WC_Stripe_Logger::log( 'Could not find order via source ID: ' . $notification->data->object->id ); |
|
132 | + if ( ! $order) { |
|
133 | + WC_Stripe_Logger::log('Could not find order via source ID: ' . $notification->data->object->id); |
|
134 | 134 | return; |
135 | 135 | } |
136 | 136 | |
137 | - $order_id = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->id : $order->get_id(); |
|
137 | + $order_id = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->id : $order->get_id(); |
|
138 | 138 | $source_id = $notification->data->object->id; |
139 | 139 | |
140 | - $is_pending_receiver = ( 'receiver' === $notification->data->object->flow ); |
|
140 | + $is_pending_receiver = ('receiver' === $notification->data->object->flow); |
|
141 | 141 | |
142 | 142 | try { |
143 | - if ( 'processing' === $order->get_status() || 'completed' === $order->get_status() ) { |
|
143 | + if ('processing' === $order->get_status() || 'completed' === $order->get_status()) { |
|
144 | 144 | return; |
145 | 145 | } |
146 | 146 | |
147 | - if ( 'on-hold' === $order->get_status() && ! $is_pending_receiver ) { |
|
147 | + if ('on-hold' === $order->get_status() && ! $is_pending_receiver) { |
|
148 | 148 | return; |
149 | 149 | } |
150 | 150 | |
@@ -152,94 +152,94 @@ discard block |
||
152 | 152 | $response = null; |
153 | 153 | |
154 | 154 | // This will throw exception if not valid. |
155 | - $this->validate_minimum_order_amount( $order ); |
|
155 | + $this->validate_minimum_order_amount($order); |
|
156 | 156 | |
157 | - WC_Stripe_Logger::log( "Info: (Webhook) Begin processing payment for order $order_id for the amount of {$order->get_total()}" ); |
|
157 | + WC_Stripe_Logger::log("Info: (Webhook) Begin processing payment for order $order_id for the amount of {$order->get_total()}"); |
|
158 | 158 | |
159 | 159 | // Prep source object. |
160 | 160 | $source_object = new stdClass(); |
161 | 161 | $source_object->token_id = ''; |
162 | - $source_object->customer = $this->get_stripe_customer_id( $order ); |
|
162 | + $source_object->customer = $this->get_stripe_customer_id($order); |
|
163 | 163 | $source_object->source = $source_id; |
164 | 164 | |
165 | 165 | // Make the request. |
166 | - $response = WC_Stripe_API::request( $this->generate_payment_request( $order, $source_object ), 'charges', 'POST', true ); |
|
166 | + $response = WC_Stripe_API::request($this->generate_payment_request($order, $source_object), 'charges', 'POST', true); |
|
167 | 167 | $headers = $response['headers']; |
168 | 168 | $response = $response['body']; |
169 | 169 | |
170 | - if ( ! empty( $response->error ) ) { |
|
170 | + if ( ! empty($response->error)) { |
|
171 | 171 | // Customer param wrong? The user may have been deleted on stripe's end. Remove customer_id. Can be retried without. |
172 | - if ( $this->is_no_such_customer_error( $response->error ) ) { |
|
173 | - if ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ) { |
|
174 | - delete_user_meta( $order->customer_user, '_stripe_customer_id' ); |
|
175 | - delete_post_meta( $order_id, '_stripe_customer_id' ); |
|
172 | + if ($this->is_no_such_customer_error($response->error)) { |
|
173 | + if (WC_Stripe_Helper::is_wc_lt('3.0')) { |
|
174 | + delete_user_meta($order->customer_user, '_stripe_customer_id'); |
|
175 | + delete_post_meta($order_id, '_stripe_customer_id'); |
|
176 | 176 | } else { |
177 | - delete_user_meta( $order->get_customer_id(), '_stripe_customer_id' ); |
|
178 | - $order->delete_meta_data( '_stripe_customer_id' ); |
|
177 | + delete_user_meta($order->get_customer_id(), '_stripe_customer_id'); |
|
178 | + $order->delete_meta_data('_stripe_customer_id'); |
|
179 | 179 | $order->save(); |
180 | 180 | } |
181 | 181 | } |
182 | 182 | |
183 | - if ( $this->is_no_such_token_error( $response->error ) && $prepared_source->token_id ) { |
|
183 | + if ($this->is_no_such_token_error($response->error) && $prepared_source->token_id) { |
|
184 | 184 | // Source param wrong? The CARD may have been deleted on stripe's end. Remove token and show message. |
185 | - $wc_token = WC_Payment_Tokens::get( $prepared_source->token_id ); |
|
185 | + $wc_token = WC_Payment_Tokens::get($prepared_source->token_id); |
|
186 | 186 | $wc_token->delete(); |
187 | - $localized_message = __( 'This card is no longer available and has been removed.', 'woocommerce-gateway-stripe' ); |
|
188 | - $order->add_order_note( $localized_message ); |
|
189 | - throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message ); |
|
187 | + $localized_message = __('This card is no longer available and has been removed.', 'woocommerce-gateway-stripe'); |
|
188 | + $order->add_order_note($localized_message); |
|
189 | + throw new WC_Stripe_Exception(print_r($response, true), $localized_message); |
|
190 | 190 | } |
191 | 191 | |
192 | 192 | // We want to retry. |
193 | - if ( $this->is_retryable_error( $response->error ) ) { |
|
194 | - if ( $retry ) { |
|
193 | + if ($this->is_retryable_error($response->error)) { |
|
194 | + if ($retry) { |
|
195 | 195 | // Don't do anymore retries after this. |
196 | - if ( 5 <= $this->retry_interval ) { |
|
196 | + if (5 <= $this->retry_interval) { |
|
197 | 197 | |
198 | - return $this->process_webhook_payment( $notification, false ); |
|
198 | + return $this->process_webhook_payment($notification, false); |
|
199 | 199 | } |
200 | 200 | |
201 | - sleep( $this->retry_interval ); |
|
201 | + sleep($this->retry_interval); |
|
202 | 202 | |
203 | 203 | $this->retry_interval++; |
204 | - return $this->process_webhook_payment( $notification, true ); |
|
204 | + return $this->process_webhook_payment($notification, true); |
|
205 | 205 | } else { |
206 | - $localized_message = __( 'Sorry, we are unable to process your payment at this time. Please retry later.', 'woocommerce-gateway-stripe' ); |
|
207 | - $order->add_order_note( $localized_message ); |
|
208 | - throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message ); |
|
206 | + $localized_message = __('Sorry, we are unable to process your payment at this time. Please retry later.', 'woocommerce-gateway-stripe'); |
|
207 | + $order->add_order_note($localized_message); |
|
208 | + throw new WC_Stripe_Exception(print_r($response, true), $localized_message); |
|
209 | 209 | } |
210 | 210 | } |
211 | 211 | |
212 | 212 | $localized_messages = WC_Stripe_Helper::get_localized_messages(); |
213 | 213 | |
214 | - if ( 'card_error' === $response->error->type ) { |
|
215 | - $localized_message = isset( $localized_messages[ $response->error->code ] ) ? $localized_messages[ $response->error->code ] : $response->error->message; |
|
214 | + if ('card_error' === $response->error->type) { |
|
215 | + $localized_message = isset($localized_messages[$response->error->code]) ? $localized_messages[$response->error->code] : $response->error->message; |
|
216 | 216 | } else { |
217 | - $localized_message = isset( $localized_messages[ $response->error->type ] ) ? $localized_messages[ $response->error->type ] : $response->error->message; |
|
217 | + $localized_message = isset($localized_messages[$response->error->type]) ? $localized_messages[$response->error->type] : $response->error->message; |
|
218 | 218 | } |
219 | 219 | |
220 | - $order->add_order_note( $localized_message ); |
|
220 | + $order->add_order_note($localized_message); |
|
221 | 221 | |
222 | - throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message ); |
|
222 | + throw new WC_Stripe_Exception(print_r($response, true), $localized_message); |
|
223 | 223 | } |
224 | 224 | |
225 | 225 | // To prevent double processing the order on WC side. |
226 | - if ( ! $this->is_original_request( $headers ) ) { |
|
226 | + if ( ! $this->is_original_request($headers)) { |
|
227 | 227 | return; |
228 | 228 | } |
229 | 229 | |
230 | - do_action( 'wc_gateway_stripe_process_webhook_payment', $response, $order ); |
|
230 | + do_action('wc_gateway_stripe_process_webhook_payment', $response, $order); |
|
231 | 231 | |
232 | - $this->process_response( $response, $order ); |
|
232 | + $this->process_response($response, $order); |
|
233 | 233 | |
234 | - } catch ( WC_Stripe_Exception $e ) { |
|
235 | - WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() ); |
|
234 | + } catch (WC_Stripe_Exception $e) { |
|
235 | + WC_Stripe_Logger::log('Error: ' . $e->getMessage()); |
|
236 | 236 | |
237 | - do_action( 'wc_gateway_stripe_process_webhook_payment_error', $order, $notification, $e ); |
|
237 | + do_action('wc_gateway_stripe_process_webhook_payment_error', $order, $notification, $e); |
|
238 | 238 | |
239 | - $statuses = array( 'pending', 'failed' ); |
|
239 | + $statuses = array('pending', 'failed'); |
|
240 | 240 | |
241 | - if ( $order->has_status( $statuses ) ) { |
|
242 | - $this->send_failed_order_email( $order_id ); |
|
241 | + if ($order->has_status($statuses)) { |
|
242 | + $this->send_failed_order_email($order_id); |
|
243 | 243 | } |
244 | 244 | } |
245 | 245 | } |
@@ -252,21 +252,21 @@ discard block |
||
252 | 252 | * @since 4.0.0 |
253 | 253 | * @param object $notification |
254 | 254 | */ |
255 | - public function process_webhook_dispute( $notification ) { |
|
256 | - $order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->charge ); |
|
255 | + public function process_webhook_dispute($notification) { |
|
256 | + $order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->charge); |
|
257 | 257 | |
258 | - if ( ! $order ) { |
|
259 | - WC_Stripe_Logger::log( 'Could not find order via charge ID: ' . $notification->data->object->charge ); |
|
258 | + if ( ! $order) { |
|
259 | + WC_Stripe_Logger::log('Could not find order via charge ID: ' . $notification->data->object->charge); |
|
260 | 260 | return; |
261 | 261 | } |
262 | 262 | |
263 | 263 | /* translators: 1) The URL to the order. */ |
264 | - $order->update_status( 'on-hold', sprintf( __( 'A dispute was created for this order. Response is needed. Please go to your <a href="%s" title="Stripe Dashboard" target="_blank">Stripe Dashboard</a> to review this dispute.', 'woocommerce-gateway-stripe' ), $this->get_transaction_url( $order ) ) ); |
|
264 | + $order->update_status('on-hold', sprintf(__('A dispute was created for this order. Response is needed. Please go to your <a href="%s" title="Stripe Dashboard" target="_blank">Stripe Dashboard</a> to review this dispute.', 'woocommerce-gateway-stripe'), $this->get_transaction_url($order))); |
|
265 | 265 | |
266 | - do_action( 'wc_gateway_stripe_process_webhook_payment_error', $order, $notification ); |
|
266 | + do_action('wc_gateway_stripe_process_webhook_payment_error', $order, $notification); |
|
267 | 267 | |
268 | - $order_id = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->id : $order->get_id(); |
|
269 | - $this->send_failed_order_email( $order_id ); |
|
268 | + $order_id = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->id : $order->get_id(); |
|
269 | + $this->send_failed_order_email($order_id); |
|
270 | 270 | } |
271 | 271 | |
272 | 272 | /** |
@@ -277,44 +277,44 @@ discard block |
||
277 | 277 | * @version 4.0.0 |
278 | 278 | * @param object $notification |
279 | 279 | */ |
280 | - public function process_webhook_capture( $notification ) { |
|
281 | - $order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->id ); |
|
280 | + public function process_webhook_capture($notification) { |
|
281 | + $order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->id); |
|
282 | 282 | |
283 | - if ( ! $order ) { |
|
284 | - WC_Stripe_Logger::log( 'Could not find order via charge ID: ' . $notification->data->object->id ); |
|
283 | + if ( ! $order) { |
|
284 | + WC_Stripe_Logger::log('Could not find order via charge ID: ' . $notification->data->object->id); |
|
285 | 285 | return; |
286 | 286 | } |
287 | 287 | |
288 | - $order_id = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->id : $order->get_id(); |
|
288 | + $order_id = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->id : $order->get_id(); |
|
289 | 289 | |
290 | - if ( 'stripe' === ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->payment_method : $order->get_payment_method() ) ) { |
|
291 | - $charge = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? get_post_meta( $order_id, '_transaction_id', true ) : $order->get_transaction_id(); |
|
292 | - $captured = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? get_post_meta( $order_id, '_stripe_charge_captured', true ) : $order->get_meta( '_stripe_charge_captured', true ); |
|
290 | + if ('stripe' === (WC_Stripe_Helper::is_wc_lt('3.0') ? $order->payment_method : $order->get_payment_method())) { |
|
291 | + $charge = WC_Stripe_Helper::is_wc_lt('3.0') ? get_post_meta($order_id, '_transaction_id', true) : $order->get_transaction_id(); |
|
292 | + $captured = WC_Stripe_Helper::is_wc_lt('3.0') ? get_post_meta($order_id, '_stripe_charge_captured', true) : $order->get_meta('_stripe_charge_captured', true); |
|
293 | 293 | |
294 | - if ( $charge && 'no' === $captured ) { |
|
295 | - WC_Stripe_Helper::is_wc_lt( '3.0' ) ? update_post_meta( $order_id, '_stripe_charge_captured', 'yes' ) : $order->update_meta_data( '_stripe_charge_captured', 'yes' ); |
|
294 | + if ($charge && 'no' === $captured) { |
|
295 | + WC_Stripe_Helper::is_wc_lt('3.0') ? update_post_meta($order_id, '_stripe_charge_captured', 'yes') : $order->update_meta_data('_stripe_charge_captured', 'yes'); |
|
296 | 296 | |
297 | 297 | // Store other data such as fees |
298 | - WC_Stripe_Helper::is_wc_lt( '3.0' ) ? update_post_meta( $order_id, '_transaction_id', $notification->data->object->id ) : $order->set_transaction_id( $notification->data->object->id ); |
|
298 | + WC_Stripe_Helper::is_wc_lt('3.0') ? update_post_meta($order_id, '_transaction_id', $notification->data->object->id) : $order->set_transaction_id($notification->data->object->id); |
|
299 | 299 | |
300 | - if ( isset( $notification->data->object->balance_transaction ) ) { |
|
301 | - $this->update_fees( $order, $notification->data->object->balance_transaction ); |
|
300 | + if (isset($notification->data->object->balance_transaction)) { |
|
301 | + $this->update_fees($order, $notification->data->object->balance_transaction); |
|
302 | 302 | } |
303 | 303 | |
304 | 304 | // Check and see if capture is partial. |
305 | - if ( $this->is_partial_capture( $notification ) ) { |
|
306 | - $partial_amount = $this->get_partial_amount_to_charge( $notification ); |
|
307 | - $order->set_total( $partial_amount ); |
|
305 | + if ($this->is_partial_capture($notification)) { |
|
306 | + $partial_amount = $this->get_partial_amount_to_charge($notification); |
|
307 | + $order->set_total($partial_amount); |
|
308 | 308 | /* translators: partial captured amount */ |
309 | - $order->add_order_note( sprintf( __( 'This charge was partially captured via Stripe Dashboard in the amount of: %s', 'woocommerce-gateway-stripe' ), $partial_amount ) ); |
|
309 | + $order->add_order_note(sprintf(__('This charge was partially captured via Stripe Dashboard in the amount of: %s', 'woocommerce-gateway-stripe'), $partial_amount)); |
|
310 | 310 | } else { |
311 | - $order->payment_complete( $notification->data->object->id ); |
|
311 | + $order->payment_complete($notification->data->object->id); |
|
312 | 312 | |
313 | 313 | /* translators: transaction id */ |
314 | - $order->add_order_note( sprintf( __( 'Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe' ), $notification->data->object->id ) ); |
|
314 | + $order->add_order_note(sprintf(__('Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe'), $notification->data->object->id)); |
|
315 | 315 | } |
316 | 316 | |
317 | - if ( is_callable( array( $order, 'save' ) ) ) { |
|
317 | + if (is_callable(array($order, 'save'))) { |
|
318 | 318 | $order->save(); |
319 | 319 | } |
320 | 320 | } |
@@ -329,38 +329,38 @@ discard block |
||
329 | 329 | * @version 4.0.0 |
330 | 330 | * @param object $notification |
331 | 331 | */ |
332 | - public function process_webhook_charge_succeeded( $notification ) { |
|
332 | + public function process_webhook_charge_succeeded($notification) { |
|
333 | 333 | // The following payment methods are synchronous so does not need to be handle via webhook. |
334 | - 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 ) ) { |
|
334 | + 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)) { |
|
335 | 335 | return; |
336 | 336 | } |
337 | 337 | |
338 | - $order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->id ); |
|
338 | + $order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->id); |
|
339 | 339 | |
340 | - if ( ! $order ) { |
|
341 | - WC_Stripe_Logger::log( 'Could not find order via charge ID: ' . $notification->data->object->id ); |
|
340 | + if ( ! $order) { |
|
341 | + WC_Stripe_Logger::log('Could not find order via charge ID: ' . $notification->data->object->id); |
|
342 | 342 | return; |
343 | 343 | } |
344 | 344 | |
345 | - $order_id = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->id : $order->get_id(); |
|
345 | + $order_id = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->id : $order->get_id(); |
|
346 | 346 | |
347 | - if ( 'on-hold' !== $order->get_status() ) { |
|
347 | + if ('on-hold' !== $order->get_status()) { |
|
348 | 348 | return; |
349 | 349 | } |
350 | 350 | |
351 | 351 | // Store other data such as fees |
352 | - WC_Stripe_Helper::is_wc_lt( '3.0' ) ? update_post_meta( $order_id, '_transaction_id', $notification->data->object->id ) : $order->set_transaction_id( $notification->data->object->id ); |
|
352 | + WC_Stripe_Helper::is_wc_lt('3.0') ? update_post_meta($order_id, '_transaction_id', $notification->data->object->id) : $order->set_transaction_id($notification->data->object->id); |
|
353 | 353 | |
354 | - if ( isset( $notification->data->object->balance_transaction ) ) { |
|
355 | - $this->update_fees( $order, $notification->data->object->balance_transaction ); |
|
354 | + if (isset($notification->data->object->balance_transaction)) { |
|
355 | + $this->update_fees($order, $notification->data->object->balance_transaction); |
|
356 | 356 | } |
357 | 357 | |
358 | - $order->payment_complete( $notification->data->object->id ); |
|
358 | + $order->payment_complete($notification->data->object->id); |
|
359 | 359 | |
360 | 360 | /* translators: transaction id */ |
361 | - $order->add_order_note( sprintf( __( 'Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe' ), $notification->data->object->id ) ); |
|
361 | + $order->add_order_note(sprintf(__('Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe'), $notification->data->object->id)); |
|
362 | 362 | |
363 | - if ( is_callable( array( $order, 'save' ) ) ) { |
|
363 | + if (is_callable(array($order, 'save'))) { |
|
364 | 364 | $order->save(); |
365 | 365 | } |
366 | 366 | } |
@@ -372,24 +372,24 @@ discard block |
||
372 | 372 | * @since 4.1.5 Can handle any fail payments from any methods. |
373 | 373 | * @param object $notification |
374 | 374 | */ |
375 | - public function process_webhook_charge_failed( $notification ) { |
|
376 | - $order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->id ); |
|
375 | + public function process_webhook_charge_failed($notification) { |
|
376 | + $order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->id); |
|
377 | 377 | |
378 | - if ( ! $order ) { |
|
379 | - WC_Stripe_Logger::log( 'Could not find order via charge ID: ' . $notification->data->object->id ); |
|
378 | + if ( ! $order) { |
|
379 | + WC_Stripe_Logger::log('Could not find order via charge ID: ' . $notification->data->object->id); |
|
380 | 380 | return; |
381 | 381 | } |
382 | 382 | |
383 | - $order_id = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->id : $order->get_id(); |
|
383 | + $order_id = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->id : $order->get_id(); |
|
384 | 384 | |
385 | 385 | // If order status is already in failed status don't continue. |
386 | - if ( 'failed' === $order->get_status() ) { |
|
386 | + if ('failed' === $order->get_status()) { |
|
387 | 387 | return; |
388 | 388 | } |
389 | 389 | |
390 | - $order->update_status( 'failed', __( 'This payment failed to clear.', 'woocommerce-gateway-stripe' ) ); |
|
390 | + $order->update_status('failed', __('This payment failed to clear.', 'woocommerce-gateway-stripe')); |
|
391 | 391 | |
392 | - do_action( 'wc_gateway_stripe_process_webhook_payment_error', $order, $notification ); |
|
392 | + do_action('wc_gateway_stripe_process_webhook_payment_error', $order, $notification); |
|
393 | 393 | } |
394 | 394 | |
395 | 395 | /** |
@@ -400,24 +400,24 @@ discard block |
||
400 | 400 | * @version 4.0.0 |
401 | 401 | * @param object $notification |
402 | 402 | */ |
403 | - public function process_webhook_source_canceled( $notification ) { |
|
404 | - $order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->id ); |
|
403 | + public function process_webhook_source_canceled($notification) { |
|
404 | + $order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->id); |
|
405 | 405 | |
406 | 406 | // If can't find order by charge ID, try source ID. |
407 | - if ( ! $order ) { |
|
408 | - $order = WC_Stripe_Helper::get_order_by_source_id( $notification->data->object->id ); |
|
407 | + if ( ! $order) { |
|
408 | + $order = WC_Stripe_Helper::get_order_by_source_id($notification->data->object->id); |
|
409 | 409 | |
410 | - if ( ! $order ) { |
|
411 | - WC_Stripe_Logger::log( 'Could not find order via charge/source ID: ' . $notification->data->object->id ); |
|
410 | + if ( ! $order) { |
|
411 | + WC_Stripe_Logger::log('Could not find order via charge/source ID: ' . $notification->data->object->id); |
|
412 | 412 | return; |
413 | 413 | } |
414 | 414 | } |
415 | 415 | |
416 | - if ( 'cancelled' !== $order->get_status() ) { |
|
417 | - $order->update_status( 'cancelled', __( 'This payment has cancelled.', 'woocommerce-gateway-stripe' ) ); |
|
416 | + if ('cancelled' !== $order->get_status()) { |
|
417 | + $order->update_status('cancelled', __('This payment has cancelled.', 'woocommerce-gateway-stripe')); |
|
418 | 418 | } |
419 | 419 | |
420 | - do_action( 'wc_gateway_stripe_process_webhook_payment_error', $order, $notification ); |
|
420 | + do_action('wc_gateway_stripe_process_webhook_payment_error', $order, $notification); |
|
421 | 421 | } |
422 | 422 | |
423 | 423 | /** |
@@ -427,59 +427,59 @@ discard block |
||
427 | 427 | * @version 4.0.0 |
428 | 428 | * @param object $notification |
429 | 429 | */ |
430 | - public function process_webhook_refund( $notification ) { |
|
431 | - $order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->id ); |
|
430 | + public function process_webhook_refund($notification) { |
|
431 | + $order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->id); |
|
432 | 432 | |
433 | - if ( ! $order ) { |
|
434 | - WC_Stripe_Logger::log( 'Could not find order via charge ID: ' . $notification->data->object->id ); |
|
433 | + if ( ! $order) { |
|
434 | + WC_Stripe_Logger::log('Could not find order via charge ID: ' . $notification->data->object->id); |
|
435 | 435 | return; |
436 | 436 | } |
437 | 437 | |
438 | - $order_id = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->id : $order->get_id(); |
|
438 | + $order_id = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->id : $order->get_id(); |
|
439 | 439 | |
440 | - if ( 'stripe' === ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->payment_method : $order->get_payment_method() ) ) { |
|
441 | - $charge = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? get_post_meta( $order_id, '_transaction_id', true ) : $order->get_transaction_id(); |
|
442 | - $captured = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? get_post_meta( $order_id, '_stripe_charge_captured', true ) : $order->get_meta( '_stripe_charge_captured', true ); |
|
443 | - $refund_id = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? get_post_meta( $order_id, '_stripe_refund_id', true ) : $order->get_meta( '_stripe_refund_id', true ); |
|
440 | + if ('stripe' === (WC_Stripe_Helper::is_wc_lt('3.0') ? $order->payment_method : $order->get_payment_method())) { |
|
441 | + $charge = WC_Stripe_Helper::is_wc_lt('3.0') ? get_post_meta($order_id, '_transaction_id', true) : $order->get_transaction_id(); |
|
442 | + $captured = WC_Stripe_Helper::is_wc_lt('3.0') ? get_post_meta($order_id, '_stripe_charge_captured', true) : $order->get_meta('_stripe_charge_captured', true); |
|
443 | + $refund_id = WC_Stripe_Helper::is_wc_lt('3.0') ? get_post_meta($order_id, '_stripe_refund_id', true) : $order->get_meta('_stripe_refund_id', true); |
|
444 | 444 | |
445 | 445 | // If the refund ID matches, don't continue to prevent double refunding. |
446 | - if ( $notification->data->object->refunds->data[0]->id === $refund_id ) { |
|
446 | + if ($notification->data->object->refunds->data[0]->id === $refund_id) { |
|
447 | 447 | return; |
448 | 448 | } |
449 | 449 | |
450 | 450 | // Only refund captured charge. |
451 | - if ( $charge ) { |
|
452 | - $reason = ( isset( $captured ) && 'yes' === $captured ) ? __( 'Refunded via Stripe Dashboard', 'woocommerce-gateway-stripe' ) : __( 'Pre-Authorization Released via Stripe Dashboard', 'woocommerce-gateway-stripe' ); |
|
451 | + if ($charge) { |
|
452 | + $reason = (isset($captured) && 'yes' === $captured) ? __('Refunded via Stripe Dashboard', 'woocommerce-gateway-stripe') : __('Pre-Authorization Released via Stripe Dashboard', 'woocommerce-gateway-stripe'); |
|
453 | 453 | |
454 | 454 | // Create the refund. |
455 | 455 | $refund = wc_create_refund( |
456 | 456 | array( |
457 | 457 | 'order_id' => $order_id, |
458 | - 'amount' => $this->get_refund_amount( $notification ), |
|
458 | + 'amount' => $this->get_refund_amount($notification), |
|
459 | 459 | 'reason' => $reason, |
460 | 460 | ) |
461 | 461 | ); |
462 | 462 | |
463 | - if ( is_wp_error( $refund ) ) { |
|
464 | - WC_Stripe_Logger::log( $refund->get_error_message() ); |
|
463 | + if (is_wp_error($refund)) { |
|
464 | + WC_Stripe_Logger::log($refund->get_error_message()); |
|
465 | 465 | } |
466 | 466 | |
467 | - WC_Stripe_Helper::is_wc_lt( '3.0' ) ? update_post_meta( $order_id, '_stripe_refund_id', $notification->data->object->refunds->data[0]->id ) : $order->update_meta_data( '_stripe_refund_id', $notification->data->object->refunds->data[0]->id ); |
|
467 | + WC_Stripe_Helper::is_wc_lt('3.0') ? update_post_meta($order_id, '_stripe_refund_id', $notification->data->object->refunds->data[0]->id) : $order->update_meta_data('_stripe_refund_id', $notification->data->object->refunds->data[0]->id); |
|
468 | 468 | |
469 | - $amount = wc_price( $notification->data->object->refunds->data[0]->amount / 100 ); |
|
469 | + $amount = wc_price($notification->data->object->refunds->data[0]->amount / 100); |
|
470 | 470 | |
471 | - if ( in_array( strtolower( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->get_order_currency() : $order->get_currency() ), WC_Stripe_Helper::no_decimal_currencies() ) ) { |
|
472 | - $amount = wc_price( $notification->data->object->refunds->data[0]->amount ); |
|
471 | + if (in_array(strtolower(WC_Stripe_Helper::is_wc_lt('3.0') ? $order->get_order_currency() : $order->get_currency()), WC_Stripe_Helper::no_decimal_currencies())) { |
|
472 | + $amount = wc_price($notification->data->object->refunds->data[0]->amount); |
|
473 | 473 | } |
474 | 474 | |
475 | - if ( isset( $notification->data->object->refunds->data[0]->balance_transaction ) ) { |
|
476 | - $this->update_fees( $order, $notification->data->object->refunds->data[0]->balance_transaction ); |
|
475 | + if (isset($notification->data->object->refunds->data[0]->balance_transaction)) { |
|
476 | + $this->update_fees($order, $notification->data->object->refunds->data[0]->balance_transaction); |
|
477 | 477 | } |
478 | 478 | |
479 | 479 | /* translators: 1) dollar amount 2) transaction id 3) refund message */ |
480 | - $refund_message = ( isset( $captured ) && 'yes' === $captured ) ? sprintf( __( 'Refunded %1$s - Refund ID: %2$s - %3$s', 'woocommerce-gateway-stripe' ), $amount, $notification->data->object->refunds->data[0]->id, $reason ) : __( 'Pre-Authorization Released via Stripe Dashboard', 'woocommerce-gateway-stripe' ); |
|
480 | + $refund_message = (isset($captured) && 'yes' === $captured) ? sprintf(__('Refunded %1$s - Refund ID: %2$s - %3$s', 'woocommerce-gateway-stripe'), $amount, $notification->data->object->refunds->data[0]->id, $reason) : __('Pre-Authorization Released via Stripe Dashboard', 'woocommerce-gateway-stripe'); |
|
481 | 481 | |
482 | - $order->add_order_note( $refund_message ); |
|
482 | + $order->add_order_note($refund_message); |
|
483 | 483 | } |
484 | 484 | } |
485 | 485 | } |
@@ -490,21 +490,21 @@ discard block |
||
490 | 490 | * @since 4.0.6 |
491 | 491 | * @param object $notification |
492 | 492 | */ |
493 | - public function process_review_opened( $notification ) { |
|
494 | - $order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->charge ); |
|
493 | + public function process_review_opened($notification) { |
|
494 | + $order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->charge); |
|
495 | 495 | |
496 | - if ( ! $order ) { |
|
497 | - WC_Stripe_Logger::log( 'Could not find order via charge ID: ' . $notification->data->object->charge ); |
|
496 | + if ( ! $order) { |
|
497 | + WC_Stripe_Logger::log('Could not find order via charge ID: ' . $notification->data->object->charge); |
|
498 | 498 | return; |
499 | 499 | } |
500 | 500 | |
501 | 501 | /* translators: 1) The URL to the order. 2) The reason type. */ |
502 | - $message = sprintf( __( 'A review has been opened for this order. Action is needed. Please go to your <a href="%1$s" title="Stripe Dashboard" target="_blank">Stripe Dashboard</a> to review the issue. Reason: (%2$s)', 'woocommerce-gateway-stripe' ), $this->get_transaction_url( $order ), $notification->data->object->reason ); |
|
502 | + $message = sprintf(__('A review has been opened for this order. Action is needed. Please go to your <a href="%1$s" title="Stripe Dashboard" target="_blank">Stripe Dashboard</a> to review the issue. Reason: (%2$s)', 'woocommerce-gateway-stripe'), $this->get_transaction_url($order), $notification->data->object->reason); |
|
503 | 503 | |
504 | - if ( apply_filters( 'wc_stripe_webhook_review_change_order_status', true, $order, $notification ) ) { |
|
505 | - $order->update_status( 'on-hold', $message ); |
|
504 | + if (apply_filters('wc_stripe_webhook_review_change_order_status', true, $order, $notification)) { |
|
505 | + $order->update_status('on-hold', $message); |
|
506 | 506 | } else { |
507 | - $order->add_order_note( $message ); |
|
507 | + $order->add_order_note($message); |
|
508 | 508 | } |
509 | 509 | } |
510 | 510 | |
@@ -514,25 +514,25 @@ discard block |
||
514 | 514 | * @since 4.0.6 |
515 | 515 | * @param object $notification |
516 | 516 | */ |
517 | - public function process_review_closed( $notification ) { |
|
518 | - $order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->charge ); |
|
517 | + public function process_review_closed($notification) { |
|
518 | + $order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->charge); |
|
519 | 519 | |
520 | - if ( ! $order ) { |
|
521 | - WC_Stripe_Logger::log( 'Could not find order via charge ID: ' . $notification->data->object->charge ); |
|
520 | + if ( ! $order) { |
|
521 | + WC_Stripe_Logger::log('Could not find order via charge ID: ' . $notification->data->object->charge); |
|
522 | 522 | return; |
523 | 523 | } |
524 | 524 | |
525 | 525 | /* translators: 1) The reason type. */ |
526 | - $message = sprintf( __( 'The opened review for this order is now closed. Reason: (%s)', 'woocommerce-gateway-stripe' ), $notification->data->object->reason ); |
|
526 | + $message = sprintf(__('The opened review for this order is now closed. Reason: (%s)', 'woocommerce-gateway-stripe'), $notification->data->object->reason); |
|
527 | 527 | |
528 | - if ( 'on-hold' === $order->get_status() ) { |
|
529 | - if ( apply_filters( 'wc_stripe_webhook_review_change_order_status', true, $order, $notification ) ) { |
|
530 | - $order->update_status( 'processing', $message ); |
|
528 | + if ('on-hold' === $order->get_status()) { |
|
529 | + if (apply_filters('wc_stripe_webhook_review_change_order_status', true, $order, $notification)) { |
|
530 | + $order->update_status('processing', $message); |
|
531 | 531 | } else { |
532 | - $order->add_order_note( $message ); |
|
532 | + $order->add_order_note($message); |
|
533 | 533 | } |
534 | 534 | } else { |
535 | - $order->add_order_note( $message ); |
|
535 | + $order->add_order_note($message); |
|
536 | 536 | } |
537 | 537 | } |
538 | 538 | |
@@ -543,7 +543,7 @@ discard block |
||
543 | 543 | * @version 4.0.0 |
544 | 544 | * @param object $notification |
545 | 545 | */ |
546 | - public function is_partial_capture( $notification ) { |
|
546 | + public function is_partial_capture($notification) { |
|
547 | 547 | return 0 < $notification->data->object->amount_refunded; |
548 | 548 | } |
549 | 549 | |
@@ -554,11 +554,11 @@ discard block |
||
554 | 554 | * @version 4.0.0 |
555 | 555 | * @param object $notification |
556 | 556 | */ |
557 | - public function get_refund_amount( $notification ) { |
|
558 | - if ( $this->is_partial_capture( $notification ) ) { |
|
557 | + public function get_refund_amount($notification) { |
|
558 | + if ($this->is_partial_capture($notification)) { |
|
559 | 559 | $amount = $notification->data->object->refunds->data[0]->amount / 100; |
560 | 560 | |
561 | - if ( in_array( strtolower( $notification->data->object->currency ), WC_Stripe_Helper::no_decimal_currencies() ) ) { |
|
561 | + if (in_array(strtolower($notification->data->object->currency), WC_Stripe_Helper::no_decimal_currencies())) { |
|
562 | 562 | $amount = $notification->data->object->refunds->data[0]->amount; |
563 | 563 | } |
564 | 564 | |
@@ -575,12 +575,12 @@ discard block |
||
575 | 575 | * @version 4.0.0 |
576 | 576 | * @param object $notification |
577 | 577 | */ |
578 | - public function get_partial_amount_to_charge( $notification ) { |
|
579 | - if ( $this->is_partial_capture( $notification ) ) { |
|
580 | - $amount = ( $notification->data->object->amount - $notification->data->object->amount_refunded ) / 100; |
|
578 | + public function get_partial_amount_to_charge($notification) { |
|
579 | + if ($this->is_partial_capture($notification)) { |
|
580 | + $amount = ($notification->data->object->amount - $notification->data->object->amount_refunded) / 100; |
|
581 | 581 | |
582 | - if ( in_array( strtolower( $notification->data->object->currency ), WC_Stripe_Helper::no_decimal_currencies() ) ) { |
|
583 | - $amount = ( $notification->data->object->amount - $notification->data->object->amount_refunded ); |
|
582 | + if (in_array(strtolower($notification->data->object->currency), WC_Stripe_Helper::no_decimal_currencies())) { |
|
583 | + $amount = ($notification->data->object->amount - $notification->data->object->amount_refunded); |
|
584 | 584 | } |
585 | 585 | |
586 | 586 | return $amount; |
@@ -596,44 +596,44 @@ discard block |
||
596 | 596 | * @version 4.0.0 |
597 | 597 | * @param string $request_body |
598 | 598 | */ |
599 | - public function process_webhook( $request_body ) { |
|
600 | - $notification = json_decode( $request_body ); |
|
599 | + public function process_webhook($request_body) { |
|
600 | + $notification = json_decode($request_body); |
|
601 | 601 | |
602 | - switch ( $notification->type ) { |
|
602 | + switch ($notification->type) { |
|
603 | 603 | case 'source.chargeable': |
604 | - $this->process_webhook_payment( $notification ); |
|
604 | + $this->process_webhook_payment($notification); |
|
605 | 605 | break; |
606 | 606 | |
607 | 607 | case 'source.canceled': |
608 | - $this->process_webhook_source_canceled( $notification ); |
|
608 | + $this->process_webhook_source_canceled($notification); |
|
609 | 609 | break; |
610 | 610 | |
611 | 611 | case 'charge.succeeded': |
612 | - $this->process_webhook_charge_succeeded( $notification ); |
|
612 | + $this->process_webhook_charge_succeeded($notification); |
|
613 | 613 | break; |
614 | 614 | |
615 | 615 | case 'charge.failed': |
616 | - $this->process_webhook_charge_failed( $notification ); |
|
616 | + $this->process_webhook_charge_failed($notification); |
|
617 | 617 | break; |
618 | 618 | |
619 | 619 | case 'charge.captured': |
620 | - $this->process_webhook_capture( $notification ); |
|
620 | + $this->process_webhook_capture($notification); |
|
621 | 621 | break; |
622 | 622 | |
623 | 623 | case 'charge.dispute.created': |
624 | - $this->process_webhook_dispute( $notification ); |
|
624 | + $this->process_webhook_dispute($notification); |
|
625 | 625 | break; |
626 | 626 | |
627 | 627 | case 'charge.refunded': |
628 | - $this->process_webhook_refund( $notification ); |
|
628 | + $this->process_webhook_refund($notification); |
|
629 | 629 | break; |
630 | 630 | |
631 | 631 | case 'review.opened': |
632 | - $this->process_review_opened( $notification ); |
|
632 | + $this->process_review_opened($notification); |
|
633 | 633 | break; |
634 | 634 | |
635 | 635 | case 'review.closed': |
636 | - $this->process_review_closed( $notification ); |
|
636 | + $this->process_review_closed($notification); |
|
637 | 637 | break; |
638 | 638 | |
639 | 639 | } |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if ( ! defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | 5 | |
@@ -21,7 +21,7 @@ discard block |
||
21 | 21 | */ |
22 | 22 | public function display_admin_settings_webhook_description() { |
23 | 23 | /* translators: 1) webhook url */ |
24 | - return sprintf( __( 'You must add the following webhook endpoint <strong style="background-color:#ddd;"> %s </strong> to your <a href="https://dashboard.stripe.com/account/webhooks" target="_blank">Stripe account settings</a>. This will enable you to receive notifications on the charge statuses.', 'woocommerce-gateway-stripe' ), WC_Stripe_Helper::get_webhook_url() ); |
|
24 | + return sprintf(__('You must add the following webhook endpoint <strong style="background-color:#ddd;"> %s </strong> to your <a href="https://dashboard.stripe.com/account/webhooks" target="_blank">Stripe account settings</a>. This will enable you to receive notifications on the charge statuses.', 'woocommerce-gateway-stripe'), WC_Stripe_Helper::get_webhook_url()); |
|
25 | 25 | } |
26 | 26 | |
27 | 27 | /** |
@@ -35,8 +35,8 @@ discard block |
||
35 | 35 | <input id="wc-%1$s-new-payment-method" name="wc-%1$s-new-payment-method" type="checkbox" value="true" style="width:auto;" /> |
36 | 36 | <label for="wc-%1$s-new-payment-method" style="display:inline;">%2$s</label> |
37 | 37 | </p>', |
38 | - esc_attr( $this->id ), |
|
39 | - esc_html( apply_filters( 'wc_stripe_save_to_account_text', __( 'Save payment information to my account for future purchases.', 'woocommerce-gateway-stripe' ) ) ) |
|
38 | + esc_attr($this->id), |
|
39 | + esc_html(apply_filters('wc_stripe_save_to_account_text', __('Save payment information to my account for future purchases.', 'woocommerce-gateway-stripe'))) |
|
40 | 40 | ); |
41 | 41 | } |
42 | 42 | |
@@ -47,7 +47,7 @@ discard block |
||
47 | 47 | * @since 4.0.5 |
48 | 48 | * @param array $error |
49 | 49 | */ |
50 | - public function is_retryable_error( $error ) { |
|
50 | + public function is_retryable_error($error) { |
|
51 | 51 | return ( |
52 | 52 | 'invalid_request_error' === $error->type || |
53 | 53 | 'idempotency_error' === $error->type || |
@@ -64,11 +64,11 @@ discard block |
||
64 | 64 | * @since 4.1.0 |
65 | 65 | * @param array $error |
66 | 66 | */ |
67 | - public function is_same_idempotency_error( $error ) { |
|
67 | + public function is_same_idempotency_error($error) { |
|
68 | 68 | return ( |
69 | 69 | $error && |
70 | 70 | 'idempotency_error' === $error->type && |
71 | - preg_match( '/Keys for idempotent requests can only be used with the same parameters they were first used with./i', $error->message ) |
|
71 | + preg_match('/Keys for idempotent requests can only be used with the same parameters they were first used with./i', $error->message) |
|
72 | 72 | ); |
73 | 73 | } |
74 | 74 | |
@@ -79,11 +79,11 @@ discard block |
||
79 | 79 | * @since 4.1.0 |
80 | 80 | * @param array $error |
81 | 81 | */ |
82 | - public function is_source_already_consumed_error( $error ) { |
|
82 | + public function is_source_already_consumed_error($error) { |
|
83 | 83 | return ( |
84 | 84 | $error && |
85 | 85 | 'invalid_request_error' === $error->type && |
86 | - preg_match( '/The reusable source you provided is consumed because it was previously charged without being attached to a customer or was detached from a customer. To charge a reusable source multiple time you must attach it to a customer first./i', $error->message ) |
|
86 | + preg_match('/The reusable source you provided is consumed because it was previously charged without being attached to a customer or was detached from a customer. To charge a reusable source multiple time you must attach it to a customer first./i', $error->message) |
|
87 | 87 | ); |
88 | 88 | } |
89 | 89 | |
@@ -94,11 +94,11 @@ discard block |
||
94 | 94 | * @since 4.1.0 |
95 | 95 | * @param array $error |
96 | 96 | */ |
97 | - public function is_no_such_customer_error( $error ) { |
|
97 | + public function is_no_such_customer_error($error) { |
|
98 | 98 | return ( |
99 | 99 | $error && |
100 | 100 | 'invalid_request_error' === $error->type && |
101 | - preg_match( '/No such customer/i', $error->message ) |
|
101 | + preg_match('/No such customer/i', $error->message) |
|
102 | 102 | ); |
103 | 103 | } |
104 | 104 | |
@@ -109,11 +109,11 @@ discard block |
||
109 | 109 | * @since 4.1.0 |
110 | 110 | * @param array $error |
111 | 111 | */ |
112 | - public function is_no_such_token_error( $error ) { |
|
112 | + public function is_no_such_token_error($error) { |
|
113 | 113 | return ( |
114 | 114 | $error && |
115 | 115 | 'invalid_request_error' === $error->type && |
116 | - preg_match( '/No such token/i', $error->message ) |
|
116 | + preg_match('/No such token/i', $error->message) |
|
117 | 117 | ); |
118 | 118 | } |
119 | 119 | |
@@ -124,11 +124,11 @@ discard block |
||
124 | 124 | * @since 4.1.0 |
125 | 125 | * @param array $error |
126 | 126 | */ |
127 | - public function is_no_such_source_error( $error ) { |
|
127 | + public function is_no_such_source_error($error) { |
|
128 | 128 | return ( |
129 | 129 | $error && |
130 | 130 | 'invalid_request_error' === $error->type && |
131 | - preg_match( '/No such source/i', $error->message ) |
|
131 | + preg_match('/No such source/i', $error->message) |
|
132 | 132 | ); |
133 | 133 | } |
134 | 134 | |
@@ -139,11 +139,11 @@ discard block |
||
139 | 139 | * @since 4.1.0 |
140 | 140 | * @param array $error |
141 | 141 | */ |
142 | - public function is_no_linked_source_error( $error ) { |
|
142 | + public function is_no_linked_source_error($error) { |
|
143 | 143 | return ( |
144 | 144 | $error && |
145 | 145 | 'invalid_request_error' === $error->type && |
146 | - preg_match( '/does not have a linked source with ID/i', $error->message ) |
|
146 | + preg_match('/does not have a linked source with ID/i', $error->message) |
|
147 | 147 | ); |
148 | 148 | } |
149 | 149 | |
@@ -156,13 +156,13 @@ discard block |
||
156 | 156 | * @param object $error |
157 | 157 | * @return bool |
158 | 158 | */ |
159 | - public function need_update_idempotency_key( $source_object, $error ) { |
|
159 | + public function need_update_idempotency_key($source_object, $error) { |
|
160 | 160 | return ( |
161 | 161 | $error && |
162 | 162 | 1 < $this->retry_interval && |
163 | - ! empty( $source_object ) && |
|
163 | + ! empty($source_object) && |
|
164 | 164 | 'chargeable' === $source_object->status && |
165 | - self::is_same_idempotency_error( $error ) |
|
165 | + self::is_same_idempotency_error($error) |
|
166 | 166 | ); |
167 | 167 | } |
168 | 168 | |
@@ -172,8 +172,8 @@ discard block |
||
172 | 172 | * @since 4.1.3 |
173 | 173 | */ |
174 | 174 | public function is_available() { |
175 | - if ( 'yes' === $this->enabled ) { |
|
176 | - if ( ! $this->secret_key || ! $this->publishable_key ) { |
|
175 | + if ('yes' === $this->enabled) { |
|
176 | + if ( ! $this->secret_key || ! $this->publishable_key) { |
|
177 | 177 | return false; |
178 | 178 | } |
179 | 179 | return true; |
@@ -190,12 +190,12 @@ discard block |
||
190 | 190 | * @param int $order_id |
191 | 191 | * @return bool |
192 | 192 | */ |
193 | - public function maybe_process_pre_orders( $order_id ) { |
|
193 | + public function maybe_process_pre_orders($order_id) { |
|
194 | 194 | return ( |
195 | 195 | WC_Stripe_Helper::is_pre_orders_exists() && |
196 | - $this->pre_orders->is_pre_order( $order_id ) && |
|
197 | - WC_Pre_Orders_Order::order_requires_payment_tokenization( $order_id ) && |
|
198 | - ! is_wc_endpoint_url( 'order-pay' ) |
|
196 | + $this->pre_orders->is_pre_order($order_id) && |
|
197 | + WC_Pre_Orders_Order::order_requires_payment_tokenization($order_id) && |
|
198 | + ! is_wc_endpoint_url('order-pay') |
|
199 | 199 | ); |
200 | 200 | } |
201 | 201 | |
@@ -205,8 +205,8 @@ discard block |
||
205 | 205 | * @since 1.0.0 |
206 | 206 | * @version 4.0.0 |
207 | 207 | */ |
208 | - public function add_admin_notice( $slug, $class, $message, $dismissible = false ) { |
|
209 | - $this->notices[ $slug ] = array( |
|
208 | + public function add_admin_notice($slug, $class, $message, $dismissible = false) { |
|
209 | + $this->notices[$slug] = array( |
|
210 | 210 | 'class' => $class, |
211 | 211 | 'message' => $message, |
212 | 212 | 'dismissible' => $dismissible, |
@@ -253,10 +253,10 @@ discard block |
||
253 | 253 | * @version 4.0.0 |
254 | 254 | * @param object $order |
255 | 255 | */ |
256 | - public function validate_minimum_order_amount( $order ) { |
|
257 | - if ( $order->get_total() * 100 < WC_Stripe_Helper::get_minimum_amount() ) { |
|
256 | + public function validate_minimum_order_amount($order) { |
|
257 | + if ($order->get_total() * 100 < WC_Stripe_Helper::get_minimum_amount()) { |
|
258 | 258 | /* translators: 1) dollar amount */ |
259 | - 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 ) ) ); |
|
259 | + 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))); |
|
260 | 260 | } |
261 | 261 | } |
262 | 262 | |
@@ -266,14 +266,14 @@ discard block |
||
266 | 266 | * @since 4.0.0 |
267 | 267 | * @version 4.0.0 |
268 | 268 | */ |
269 | - public function get_transaction_url( $order ) { |
|
270 | - if ( $this->testmode ) { |
|
269 | + public function get_transaction_url($order) { |
|
270 | + if ($this->testmode) { |
|
271 | 271 | $this->view_transaction_url = 'https://dashboard.stripe.com/test/payments/%s'; |
272 | 272 | } else { |
273 | 273 | $this->view_transaction_url = 'https://dashboard.stripe.com/payments/%s'; |
274 | 274 | } |
275 | 275 | |
276 | - return parent::get_transaction_url( $order ); |
|
276 | + return parent::get_transaction_url($order); |
|
277 | 277 | } |
278 | 278 | |
279 | 279 | /** |
@@ -282,15 +282,15 @@ discard block |
||
282 | 282 | * @since 4.0.0 |
283 | 283 | * @version 4.0.0 |
284 | 284 | */ |
285 | - public function get_stripe_customer_id( $order ) { |
|
286 | - $customer = get_user_meta( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->customer_user : $order->get_customer_id(), '_stripe_customer_id', true ); |
|
285 | + public function get_stripe_customer_id($order) { |
|
286 | + $customer = get_user_meta(WC_Stripe_Helper::is_wc_lt('3.0') ? $order->customer_user : $order->get_customer_id(), '_stripe_customer_id', true); |
|
287 | 287 | |
288 | - if ( empty( $customer ) ) { |
|
288 | + if (empty($customer)) { |
|
289 | 289 | // Try to get it via the order. |
290 | - if ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ) { |
|
291 | - return get_post_meta( $order->id, '_stripe_customer_id', true ); |
|
290 | + if (WC_Stripe_Helper::is_wc_lt('3.0')) { |
|
291 | + return get_post_meta($order->id, '_stripe_customer_id', true); |
|
292 | 292 | } else { |
293 | - return $order->get_meta( '_stripe_customer_id', true ); |
|
293 | + return $order->get_meta('_stripe_customer_id', true); |
|
294 | 294 | } |
295 | 295 | } else { |
296 | 296 | return $customer; |
@@ -307,23 +307,23 @@ discard block |
||
307 | 307 | * @param object $order |
308 | 308 | * @param int $id Stripe session id. |
309 | 309 | */ |
310 | - public function get_stripe_return_url( $order = null, $id = null ) { |
|
311 | - if ( is_object( $order ) ) { |
|
312 | - if ( empty( $id ) ) { |
|
310 | + public function get_stripe_return_url($order = null, $id = null) { |
|
311 | + if (is_object($order)) { |
|
312 | + if (empty($id)) { |
|
313 | 313 | $id = uniqid(); |
314 | 314 | } |
315 | 315 | |
316 | - $order_id = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->id : $order->get_id(); |
|
316 | + $order_id = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->id : $order->get_id(); |
|
317 | 317 | |
318 | 318 | $args = array( |
319 | 319 | 'utm_nooverride' => '1', |
320 | 320 | 'order_id' => $order_id, |
321 | 321 | ); |
322 | 322 | |
323 | - return esc_url_raw( add_query_arg( $args, $this->get_return_url( $order ) ) ); |
|
323 | + return esc_url_raw(add_query_arg($args, $this->get_return_url($order))); |
|
324 | 324 | } |
325 | 325 | |
326 | - return esc_url_raw( add_query_arg( array( 'utm_nooverride' => '1' ), $this->get_return_url() ) ); |
|
326 | + return esc_url_raw(add_query_arg(array('utm_nooverride' => '1'), $this->get_return_url())); |
|
327 | 327 | } |
328 | 328 | |
329 | 329 | /** |
@@ -331,8 +331,8 @@ discard block |
||
331 | 331 | * @param int $order_id |
332 | 332 | * @return boolean |
333 | 333 | */ |
334 | - public function has_subscription( $order_id ) { |
|
335 | - return ( function_exists( 'wcs_order_contains_subscription' ) && ( wcs_order_contains_subscription( $order_id ) || wcs_is_subscription( $order_id ) || wcs_order_contains_renewal( $order_id ) ) ); |
|
334 | + public function has_subscription($order_id) { |
|
335 | + return (function_exists('wcs_order_contains_subscription') && (wcs_order_contains_subscription($order_id) || wcs_is_subscription($order_id) || wcs_order_contains_renewal($order_id))); |
|
336 | 336 | } |
337 | 337 | |
338 | 338 | /** |
@@ -344,34 +344,33 @@ discard block |
||
344 | 344 | * @param object $prepared_source |
345 | 345 | * @return array() |
346 | 346 | */ |
347 | - public function generate_payment_request( $order, $prepared_source ) { |
|
348 | - $settings = get_option( 'woocommerce_stripe_settings', array() ); |
|
349 | - $statement_descriptor = ! empty( $settings['statement_descriptor'] ) ? str_replace( "'", '', $settings['statement_descriptor'] ) : ''; |
|
350 | - $capture = ! empty( $settings['capture'] ) && 'yes' === $settings['capture'] ? true : false; |
|
347 | + public function generate_payment_request($order, $prepared_source) { |
|
348 | + $settings = get_option('woocommerce_stripe_settings', array()); |
|
349 | + $statement_descriptor = ! empty($settings['statement_descriptor']) ? str_replace("'", '', $settings['statement_descriptor']) : ''; |
|
350 | + $capture = ! empty($settings['capture']) && 'yes' === $settings['capture'] ? true : false; |
|
351 | 351 | $post_data = array(); |
352 | - $post_data['currency'] = strtolower( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->get_order_currency() : $order->get_currency() ); |
|
353 | - $post_data['amount'] = WC_Stripe_Helper::get_stripe_amount( $order->get_total(), $post_data['currency'] ); |
|
352 | + $post_data['currency'] = strtolower(WC_Stripe_Helper::is_wc_lt('3.0') ? $order->get_order_currency() : $order->get_currency()); |
|
353 | + $post_data['amount'] = WC_Stripe_Helper::get_stripe_amount($order->get_total(), $post_data['currency']); |
|
354 | 354 | /* translators: 1) blog name 2) order number */ |
355 | - $post_data['description'] = sprintf( __( '%1$s - Order %2$s', 'woocommerce-gateway-stripe' ), wp_specialchars_decode( get_bloginfo( 'name' ), ENT_QUOTES ), $order->get_order_number() ); |
|
356 | - $billing_email = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->billing_email : $order->get_billing_email(); |
|
357 | - $billing_first_name = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->billing_first_name : $order->get_billing_first_name(); |
|
358 | - $billing_last_name = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->billing_last_name : $order->get_billing_last_name(); |
|
355 | + $post_data['description'] = sprintf(__('%1$s - Order %2$s', 'woocommerce-gateway-stripe'), wp_specialchars_decode(get_bloginfo('name'), ENT_QUOTES), $order->get_order_number()); |
|
356 | + $billing_email = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->billing_email : $order->get_billing_email(); |
|
357 | + $billing_first_name = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->billing_first_name : $order->get_billing_first_name(); |
|
358 | + $billing_last_name = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->billing_last_name : $order->get_billing_last_name(); |
|
359 | 359 | |
360 | - if ( ! empty( $billing_email ) && apply_filters( 'wc_stripe_send_stripe_receipt', false ) ) { |
|
360 | + if ( ! empty($billing_email) && apply_filters('wc_stripe_send_stripe_receipt', false)) { |
|
361 | 361 | $post_data['receipt_email'] = $billing_email; |
362 | 362 | } |
363 | 363 | |
364 | - switch ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->payment_method : $order->get_payment_method() ) { |
|
365 | - case 'stripe': |
|
366 | - if ( ! empty( $statement_descriptor ) ) { |
|
367 | - $post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor( $statement_descriptor ); |
|
364 | + switch (WC_Stripe_Helper::is_wc_lt('3.0') ? $order->payment_method : $order->get_payment_method()) { |
|
365 | + case 'stripe' : if ( ! empty($statement_descriptor)) { |
|
366 | + $post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor($statement_descriptor); |
|
368 | 367 | } |
369 | 368 | |
370 | 369 | $post_data['capture'] = $capture ? 'true' : 'false'; |
371 | 370 | break; |
372 | 371 | case 'stripe_sepa': |
373 | - if ( ! empty( $statement_descriptor ) ) { |
|
374 | - $post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor( $statement_descriptor ); |
|
372 | + if ( ! empty($statement_descriptor)) { |
|
373 | + $post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor($statement_descriptor); |
|
375 | 374 | } |
376 | 375 | break; |
377 | 376 | } |
@@ -379,25 +378,25 @@ discard block |
||
379 | 378 | $post_data['expand[]'] = 'balance_transaction'; |
380 | 379 | |
381 | 380 | $metadata = array( |
382 | - __( 'customer_name', 'woocommerce-gateway-stripe' ) => sanitize_text_field( $billing_first_name ) . ' ' . sanitize_text_field( $billing_last_name ), |
|
383 | - __( 'customer_email', 'woocommerce-gateway-stripe' ) => sanitize_email( $billing_email ), |
|
381 | + __('customer_name', 'woocommerce-gateway-stripe') => sanitize_text_field($billing_first_name) . ' ' . sanitize_text_field($billing_last_name), |
|
382 | + __('customer_email', 'woocommerce-gateway-stripe') => sanitize_email($billing_email), |
|
384 | 383 | 'order_id' => $order->get_order_number(), |
385 | 384 | ); |
386 | 385 | |
387 | - if ( $this->has_subscription( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->id : $order->get_id() ) ) { |
|
386 | + if ($this->has_subscription(WC_Stripe_Helper::is_wc_lt('3.0') ? $order->id : $order->get_id())) { |
|
388 | 387 | $metadata += array( |
389 | 388 | 'payment_type' => 'recurring', |
390 | - 'site_url' => esc_url( get_site_url() ), |
|
389 | + 'site_url' => esc_url(get_site_url()), |
|
391 | 390 | ); |
392 | 391 | } |
393 | 392 | |
394 | - $post_data['metadata'] = apply_filters( 'wc_stripe_payment_metadata', $metadata, $order, $prepared_source ); |
|
393 | + $post_data['metadata'] = apply_filters('wc_stripe_payment_metadata', $metadata, $order, $prepared_source); |
|
395 | 394 | |
396 | - if ( $prepared_source->customer ) { |
|
395 | + if ($prepared_source->customer) { |
|
397 | 396 | $post_data['customer'] = $prepared_source->customer; |
398 | 397 | } |
399 | 398 | |
400 | - if ( $prepared_source->source ) { |
|
399 | + if ($prepared_source->source) { |
|
401 | 400 | $post_data['source'] = $prepared_source->source; |
402 | 401 | } |
403 | 402 | |
@@ -409,83 +408,83 @@ discard block |
||
409 | 408 | * @param WC_Order $order |
410 | 409 | * @param object $source |
411 | 410 | */ |
412 | - return apply_filters( 'wc_stripe_generate_payment_request', $post_data, $order, $prepared_source ); |
|
411 | + return apply_filters('wc_stripe_generate_payment_request', $post_data, $order, $prepared_source); |
|
413 | 412 | } |
414 | 413 | |
415 | 414 | /** |
416 | 415 | * Store extra meta data for an order from a Stripe Response. |
417 | 416 | */ |
418 | - public function process_response( $response, $order ) { |
|
419 | - WC_Stripe_Logger::log( 'Processing response: ' . print_r( $response, true ) ); |
|
417 | + public function process_response($response, $order) { |
|
418 | + WC_Stripe_Logger::log('Processing response: ' . print_r($response, true)); |
|
420 | 419 | |
421 | - $order_id = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->id : $order->get_id(); |
|
420 | + $order_id = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->id : $order->get_id(); |
|
422 | 421 | |
423 | - $captured = ( isset( $response->captured ) && $response->captured ) ? 'yes' : 'no'; |
|
422 | + $captured = (isset($response->captured) && $response->captured) ? 'yes' : 'no'; |
|
424 | 423 | |
425 | 424 | // Store charge data. |
426 | - WC_Stripe_Helper::is_wc_lt( '3.0' ) ? update_post_meta( $order_id, '_stripe_charge_captured', $captured ) : $order->update_meta_data( '_stripe_charge_captured', $captured ); |
|
425 | + WC_Stripe_Helper::is_wc_lt('3.0') ? update_post_meta($order_id, '_stripe_charge_captured', $captured) : $order->update_meta_data('_stripe_charge_captured', $captured); |
|
427 | 426 | |
428 | 427 | // Store other data such as fees. |
429 | - if ( isset( $response->balance_transaction ) && isset( $response->balance_transaction->fee ) ) { |
|
428 | + if (isset($response->balance_transaction) && isset($response->balance_transaction->fee)) { |
|
430 | 429 | // Fees and Net needs to both come from Stripe to be accurate as the returned |
431 | 430 | // values are in the local currency of the Stripe account, not from WC. |
432 | - $fee = ! empty( $response->balance_transaction->fee ) ? WC_Stripe_Helper::format_balance_fee( $response->balance_transaction, 'fee' ) : 0; |
|
433 | - $net = ! empty( $response->balance_transaction->net ) ? WC_Stripe_Helper::format_balance_fee( $response->balance_transaction, 'net' ) : 0; |
|
434 | - WC_Stripe_Helper::update_stripe_fee( $order, $fee ); |
|
435 | - WC_Stripe_Helper::update_stripe_net( $order, $net ); |
|
431 | + $fee = ! empty($response->balance_transaction->fee) ? WC_Stripe_Helper::format_balance_fee($response->balance_transaction, 'fee') : 0; |
|
432 | + $net = ! empty($response->balance_transaction->net) ? WC_Stripe_Helper::format_balance_fee($response->balance_transaction, 'net') : 0; |
|
433 | + WC_Stripe_Helper::update_stripe_fee($order, $fee); |
|
434 | + WC_Stripe_Helper::update_stripe_net($order, $net); |
|
436 | 435 | |
437 | 436 | // Store currency stripe. |
438 | - $currency = ! empty( $response->balance_transaction->currency ) ? strtoupper( $response->balance_transaction->currency ) : null; |
|
439 | - WC_Stripe_Helper::update_stripe_currency( $order, $currency ); |
|
437 | + $currency = ! empty($response->balance_transaction->currency) ? strtoupper($response->balance_transaction->currency) : null; |
|
438 | + WC_Stripe_Helper::update_stripe_currency($order, $currency); |
|
440 | 439 | } |
441 | 440 | |
442 | - if ( 'yes' === $captured ) { |
|
441 | + if ('yes' === $captured) { |
|
443 | 442 | /** |
444 | 443 | * Charge can be captured but in a pending state. Payment methods |
445 | 444 | * that are asynchronous may take couple days to clear. Webhook will |
446 | 445 | * take care of the status changes. |
447 | 446 | */ |
448 | - if ( 'pending' === $response->status ) { |
|
449 | - $order_stock_reduced = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? get_post_meta( $order_id, '_order_stock_reduced', true ) : $order->get_meta( '_order_stock_reduced', true ); |
|
447 | + if ('pending' === $response->status) { |
|
448 | + $order_stock_reduced = WC_Stripe_Helper::is_wc_lt('3.0') ? get_post_meta($order_id, '_order_stock_reduced', true) : $order->get_meta('_order_stock_reduced', true); |
|
450 | 449 | |
451 | - if ( ! $order_stock_reduced ) { |
|
452 | - WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->reduce_order_stock() : wc_reduce_stock_levels( $order_id ); |
|
450 | + if ( ! $order_stock_reduced) { |
|
451 | + WC_Stripe_Helper::is_wc_lt('3.0') ? $order->reduce_order_stock() : wc_reduce_stock_levels($order_id); |
|
453 | 452 | } |
454 | 453 | |
455 | - WC_Stripe_Helper::is_wc_lt( '3.0' ) ? update_post_meta( $order_id, '_transaction_id', $response->id ) : $order->set_transaction_id( $response->id ); |
|
454 | + WC_Stripe_Helper::is_wc_lt('3.0') ? update_post_meta($order_id, '_transaction_id', $response->id) : $order->set_transaction_id($response->id); |
|
456 | 455 | /* translators: transaction id */ |
457 | - $order->update_status( 'on-hold', sprintf( __( 'Stripe charge awaiting payment: %s.', 'woocommerce-gateway-stripe' ), $response->id ) ); |
|
456 | + $order->update_status('on-hold', sprintf(__('Stripe charge awaiting payment: %s.', 'woocommerce-gateway-stripe'), $response->id)); |
|
458 | 457 | } |
459 | 458 | |
460 | - if ( 'succeeded' === $response->status ) { |
|
461 | - $order->payment_complete( $response->id ); |
|
459 | + if ('succeeded' === $response->status) { |
|
460 | + $order->payment_complete($response->id); |
|
462 | 461 | |
463 | 462 | /* translators: transaction id */ |
464 | - $message = sprintf( __( 'Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe' ), $response->id ); |
|
465 | - $order->add_order_note( $message ); |
|
463 | + $message = sprintf(__('Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe'), $response->id); |
|
464 | + $order->add_order_note($message); |
|
466 | 465 | } |
467 | 466 | |
468 | - if ( 'failed' === $response->status ) { |
|
469 | - $localized_message = __( 'Payment processing failed. Please retry.', 'woocommerce-gateway-stripe' ); |
|
470 | - $order->add_order_note( $localized_message ); |
|
471 | - throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message ); |
|
467 | + if ('failed' === $response->status) { |
|
468 | + $localized_message = __('Payment processing failed. Please retry.', 'woocommerce-gateway-stripe'); |
|
469 | + $order->add_order_note($localized_message); |
|
470 | + throw new WC_Stripe_Exception(print_r($response, true), $localized_message); |
|
472 | 471 | } |
473 | 472 | } else { |
474 | - WC_Stripe_Helper::is_wc_lt( '3.0' ) ? update_post_meta( $order_id, '_transaction_id', $response->id ) : $order->set_transaction_id( $response->id ); |
|
473 | + WC_Stripe_Helper::is_wc_lt('3.0') ? update_post_meta($order_id, '_transaction_id', $response->id) : $order->set_transaction_id($response->id); |
|
475 | 474 | |
476 | - if ( $order->has_status( array( 'pending', 'failed' ) ) ) { |
|
477 | - WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->reduce_order_stock() : wc_reduce_stock_levels( $order_id ); |
|
475 | + if ($order->has_status(array('pending', 'failed'))) { |
|
476 | + WC_Stripe_Helper::is_wc_lt('3.0') ? $order->reduce_order_stock() : wc_reduce_stock_levels($order_id); |
|
478 | 477 | } |
479 | 478 | |
480 | 479 | /* translators: transaction id */ |
481 | - $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 ) ); |
|
480 | + $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)); |
|
482 | 481 | } |
483 | 482 | |
484 | - if ( is_callable( array( $order, 'save' ) ) ) { |
|
483 | + if (is_callable(array($order, 'save'))) { |
|
485 | 484 | $order->save(); |
486 | 485 | } |
487 | 486 | |
488 | - do_action( 'wc_gateway_stripe_process_response', $response, $order ); |
|
487 | + do_action('wc_gateway_stripe_process_response', $response, $order); |
|
489 | 488 | |
490 | 489 | return $response; |
491 | 490 | } |
@@ -498,10 +497,10 @@ discard block |
||
498 | 497 | * @param int $order_id |
499 | 498 | * @return null |
500 | 499 | */ |
501 | - public function send_failed_order_email( $order_id ) { |
|
500 | + public function send_failed_order_email($order_id) { |
|
502 | 501 | $emails = WC()->mailer()->get_emails(); |
503 | - if ( ! empty( $emails ) && ! empty( $order_id ) ) { |
|
504 | - $emails['WC_Email_Failed_Order']->trigger( $order_id ); |
|
502 | + if ( ! empty($emails) && ! empty($order_id)) { |
|
503 | + $emails['WC_Email_Failed_Order']->trigger($order_id); |
|
505 | 504 | } |
506 | 505 | } |
507 | 506 | |
@@ -513,36 +512,36 @@ discard block |
||
513 | 512 | * @param object $order |
514 | 513 | * @return object $details |
515 | 514 | */ |
516 | - public function get_owner_details( $order ) { |
|
517 | - $billing_first_name = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->billing_first_name : $order->get_billing_first_name(); |
|
518 | - $billing_last_name = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->billing_last_name : $order->get_billing_last_name(); |
|
515 | + public function get_owner_details($order) { |
|
516 | + $billing_first_name = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->billing_first_name : $order->get_billing_first_name(); |
|
517 | + $billing_last_name = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->billing_last_name : $order->get_billing_last_name(); |
|
519 | 518 | |
520 | 519 | $details = array(); |
521 | 520 | |
522 | 521 | $name = $billing_first_name . ' ' . $billing_last_name; |
523 | - $email = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->billing_email : $order->get_billing_email(); |
|
524 | - $phone = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->billing_phone : $order->get_billing_phone(); |
|
522 | + $email = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->billing_email : $order->get_billing_email(); |
|
523 | + $phone = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->billing_phone : $order->get_billing_phone(); |
|
525 | 524 | |
526 | - if ( ! empty( $phone ) ) { |
|
525 | + if ( ! empty($phone)) { |
|
527 | 526 | $details['phone'] = $phone; |
528 | 527 | } |
529 | 528 | |
530 | - if ( ! empty( $name ) ) { |
|
529 | + if ( ! empty($name)) { |
|
531 | 530 | $details['name'] = $name; |
532 | 531 | } |
533 | 532 | |
534 | - if ( ! empty( $email ) ) { |
|
533 | + if ( ! empty($email)) { |
|
535 | 534 | $details['email'] = $email; |
536 | 535 | } |
537 | 536 | |
538 | - $details['address']['line1'] = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->billing_address_1 : $order->get_billing_address_1(); |
|
539 | - $details['address']['line2'] = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->billing_address_2 : $order->get_billing_address_2(); |
|
540 | - $details['address']['state'] = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->billing_state : $order->get_billing_state(); |
|
541 | - $details['address']['city'] = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->billing_city : $order->get_billing_city(); |
|
542 | - $details['address']['postal_code'] = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->billing_postcode : $order->get_billing_postcode(); |
|
543 | - $details['address']['country'] = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->billing_country : $order->get_billing_country(); |
|
537 | + $details['address']['line1'] = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->billing_address_1 : $order->get_billing_address_1(); |
|
538 | + $details['address']['line2'] = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->billing_address_2 : $order->get_billing_address_2(); |
|
539 | + $details['address']['state'] = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->billing_state : $order->get_billing_state(); |
|
540 | + $details['address']['city'] = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->billing_city : $order->get_billing_city(); |
|
541 | + $details['address']['postal_code'] = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->billing_postcode : $order->get_billing_postcode(); |
|
542 | + $details['address']['country'] = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->billing_country : $order->get_billing_country(); |
|
544 | 543 | |
545 | - return (object) apply_filters( 'wc_stripe_owner_details', $details, $order ); |
|
544 | + return (object) apply_filters('wc_stripe_owner_details', $details, $order); |
|
546 | 545 | } |
547 | 546 | |
548 | 547 | /** |
@@ -551,15 +550,15 @@ discard block |
||
551 | 550 | * @since 4.0.3 |
552 | 551 | * @param string $source_id The source ID to get source object for. |
553 | 552 | */ |
554 | - public function get_source_object( $source_id = '' ) { |
|
555 | - if ( empty( $source_id ) ) { |
|
553 | + public function get_source_object($source_id = '') { |
|
554 | + if (empty($source_id)) { |
|
556 | 555 | return ''; |
557 | 556 | } |
558 | 557 | |
559 | - $source_object = WC_Stripe_API::retrieve( 'sources/' . $source_id ); |
|
558 | + $source_object = WC_Stripe_API::retrieve('sources/' . $source_id); |
|
560 | 559 | |
561 | - if ( ! empty( $source_object->error ) ) { |
|
562 | - throw new WC_Stripe_Exception( print_r( $source_object, true ), $source_object->error->message ); |
|
560 | + if ( ! empty($source_object->error)) { |
|
561 | + throw new WC_Stripe_Exception(print_r($source_object, true), $source_object->error->message); |
|
563 | 562 | } |
564 | 563 | |
565 | 564 | return $source_object; |
@@ -573,13 +572,13 @@ discard block |
||
573 | 572 | * @param object $source_object |
574 | 573 | * @return bool |
575 | 574 | */ |
576 | - public function is_3ds_required( $source_object ) { |
|
575 | + public function is_3ds_required($source_object) { |
|
577 | 576 | return apply_filters( |
578 | 577 | 'wc_stripe_require_3ds', |
579 | 578 | ( |
580 | - $source_object && ! empty( $source_object->card ) ) && |
|
581 | - ( 'card' === $source_object->type && 'required' === $source_object->card->three_d_secure || |
|
582 | - ( $this->three_d_secure && 'recommended' === $source_object->card->three_d_secure ) |
|
579 | + $source_object && ! empty($source_object->card) ) && |
|
580 | + ('card' === $source_object->type && 'required' === $source_object->card->three_d_secure || |
|
581 | + ($this->three_d_secure && 'recommended' === $source_object->card->three_d_secure) |
|
583 | 582 | ), |
584 | 583 | $source_object, |
585 | 584 | $this->three_d_secure |
@@ -593,8 +592,8 @@ discard block |
||
593 | 592 | * @param object $source_object |
594 | 593 | * @return bool |
595 | 594 | */ |
596 | - public function is_3ds_card( $source_object ) { |
|
597 | - return ( $source_object && 'three_d_secure' === $source_object->type ); |
|
595 | + public function is_3ds_card($source_object) { |
|
596 | + return ($source_object && 'three_d_secure' === $source_object->type); |
|
598 | 597 | } |
599 | 598 | |
600 | 599 | /** |
@@ -604,8 +603,8 @@ discard block |
||
604 | 603 | * @param object $source_object |
605 | 604 | * @return bool |
606 | 605 | */ |
607 | - public function is_prepaid_card( $source_object ) { |
|
608 | - return ( $source_object && 'token' === $source_object->object && 'prepaid' === $source_object->card->funding ); |
|
606 | + public function is_prepaid_card($source_object) { |
|
607 | + return ($source_object && 'token' === $source_object->object && 'prepaid' === $source_object->card->funding); |
|
609 | 608 | } |
610 | 609 | |
611 | 610 | /** |
@@ -615,8 +614,8 @@ discard block |
||
615 | 614 | * @param string $source_id |
616 | 615 | * @return bool |
617 | 616 | */ |
618 | - public function is_type_legacy_card( $source_id ) { |
|
619 | - return ( preg_match( '/^card_/', $source_id ) ); |
|
617 | + public function is_type_legacy_card($source_id) { |
|
618 | + return (preg_match('/^card_/', $source_id)); |
|
620 | 619 | } |
621 | 620 | |
622 | 621 | /** |
@@ -626,9 +625,9 @@ discard block |
||
626 | 625 | * @return bool |
627 | 626 | */ |
628 | 627 | public function is_using_saved_payment_method() { |
629 | - $payment_method = isset( $_POST['payment_method'] ) ? wc_clean( $_POST['payment_method'] ) : 'stripe'; |
|
628 | + $payment_method = isset($_POST['payment_method']) ? wc_clean($_POST['payment_method']) : 'stripe'; |
|
630 | 629 | |
631 | - return ( isset( $_POST[ 'wc-' . $payment_method . '-payment-token' ] ) && 'new' !== $_POST[ 'wc-' . $payment_method . '-payment-token' ] ); |
|
630 | + return (isset($_POST['wc-' . $payment_method . '-payment-token']) && 'new' !== $_POST['wc-' . $payment_method . '-payment-token']); |
|
632 | 631 | } |
633 | 632 | |
634 | 633 | /** |
@@ -641,22 +640,22 @@ discard block |
||
641 | 640 | * @param string $return_url |
642 | 641 | * @return mixed |
643 | 642 | */ |
644 | - public function create_3ds_source( $order, $source_object, $return_url = '' ) { |
|
645 | - $currency = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->get_order_currency() : $order->get_currency(); |
|
646 | - $order_id = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->id : $order->get_id(); |
|
647 | - $return_url = empty( $return_url ) ? $this->get_stripe_return_url( $order ) : $return_url; |
|
643 | + public function create_3ds_source($order, $source_object, $return_url = '') { |
|
644 | + $currency = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->get_order_currency() : $order->get_currency(); |
|
645 | + $order_id = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->id : $order->get_id(); |
|
646 | + $return_url = empty($return_url) ? $this->get_stripe_return_url($order) : $return_url; |
|
648 | 647 | |
649 | 648 | $post_data = array(); |
650 | - $post_data['amount'] = WC_Stripe_Helper::get_stripe_amount( $order->get_total(), $currency ); |
|
651 | - $post_data['currency'] = strtolower( $currency ); |
|
649 | + $post_data['amount'] = WC_Stripe_Helper::get_stripe_amount($order->get_total(), $currency); |
|
650 | + $post_data['currency'] = strtolower($currency); |
|
652 | 651 | $post_data['type'] = 'three_d_secure'; |
653 | - $post_data['owner'] = $this->get_owner_details( $order ); |
|
654 | - $post_data['three_d_secure'] = array( 'card' => $source_object->id ); |
|
655 | - $post_data['redirect'] = array( 'return_url' => $return_url ); |
|
652 | + $post_data['owner'] = $this->get_owner_details($order); |
|
653 | + $post_data['three_d_secure'] = array('card' => $source_object->id); |
|
654 | + $post_data['redirect'] = array('return_url' => $return_url); |
|
656 | 655 | |
657 | - WC_Stripe_Logger::log( 'Info: Begin creating 3DS source...' ); |
|
656 | + WC_Stripe_Logger::log('Info: Begin creating 3DS source...'); |
|
658 | 657 | |
659 | - return WC_Stripe_API::request( apply_filters( 'wc_stripe_3ds_source', $post_data, $order ), 'sources' ); |
|
658 | + return WC_Stripe_API::request(apply_filters('wc_stripe_3ds_source', $post_data, $order), 'sources'); |
|
660 | 659 | } |
661 | 660 | |
662 | 661 | /** |
@@ -672,61 +671,61 @@ discard block |
||
672 | 671 | * @throws Exception When card was not added or for and invalid card. |
673 | 672 | * @return object |
674 | 673 | */ |
675 | - public function prepare_source( $user_id, $force_save_source = false ) { |
|
676 | - $customer = new WC_Stripe_Customer( $user_id ); |
|
674 | + public function prepare_source($user_id, $force_save_source = false) { |
|
675 | + $customer = new WC_Stripe_Customer($user_id); |
|
677 | 676 | $set_customer = true; |
678 | - $force_save_source = apply_filters( 'wc_stripe_force_save_source', $force_save_source, $customer ); |
|
677 | + $force_save_source = apply_filters('wc_stripe_force_save_source', $force_save_source, $customer); |
|
679 | 678 | $source_object = ''; |
680 | 679 | $source_id = ''; |
681 | 680 | $wc_token_id = false; |
682 | - $payment_method = isset( $_POST['payment_method'] ) ? wc_clean( $_POST['payment_method'] ) : 'stripe'; |
|
681 | + $payment_method = isset($_POST['payment_method']) ? wc_clean($_POST['payment_method']) : 'stripe'; |
|
683 | 682 | $is_token = false; |
684 | 683 | |
685 | 684 | // New CC info was entered and we have a new source to process. |
686 | - if ( ! empty( $_POST['stripe_source'] ) ) { |
|
687 | - $source_object = self::get_source_object( wc_clean( $_POST['stripe_source'] ) ); |
|
685 | + if ( ! empty($_POST['stripe_source'])) { |
|
686 | + $source_object = self::get_source_object(wc_clean($_POST['stripe_source'])); |
|
688 | 687 | $source_id = $source_object->id; |
689 | 688 | |
690 | 689 | // This checks to see if customer opted to save the payment method to file. |
691 | - $maybe_saved_card = isset( $_POST[ 'wc-' . $payment_method . '-new-payment-method' ] ) && ! empty( $_POST[ 'wc-' . $payment_method . '-new-payment-method' ] ); |
|
690 | + $maybe_saved_card = isset($_POST['wc-' . $payment_method . '-new-payment-method']) && ! empty($_POST['wc-' . $payment_method . '-new-payment-method']); |
|
692 | 691 | |
693 | 692 | /** |
694 | 693 | * This is true if the user wants to store the card to their account. |
695 | 694 | * Criteria to save to file is they are logged in, they opted to save or product requirements and the source is |
696 | 695 | * actually reusable. Either that or force_save_source is true. |
697 | 696 | */ |
698 | - if ( ( $user_id && $this->saved_cards && $maybe_saved_card && 'reusable' === $source_object->usage ) || $force_save_source ) { |
|
699 | - $response = $customer->add_source( $source_object->id ); |
|
697 | + if (($user_id && $this->saved_cards && $maybe_saved_card && 'reusable' === $source_object->usage) || $force_save_source) { |
|
698 | + $response = $customer->add_source($source_object->id); |
|
700 | 699 | |
701 | - if ( ! empty( $response->error ) ) { |
|
702 | - throw new WC_Stripe_Exception( print_r( $response, true ), $response->error->message ); |
|
700 | + if ( ! empty($response->error)) { |
|
701 | + throw new WC_Stripe_Exception(print_r($response, true), $response->error->message); |
|
703 | 702 | } |
704 | 703 | } |
705 | - } elseif ( $this->is_using_saved_payment_method() ) { |
|
704 | + } elseif ($this->is_using_saved_payment_method()) { |
|
706 | 705 | // Use an existing token, and then process the payment. |
707 | - $wc_token_id = wc_clean( $_POST[ 'wc-' . $payment_method . '-payment-token' ] ); |
|
708 | - $wc_token = WC_Payment_Tokens::get( $wc_token_id ); |
|
706 | + $wc_token_id = wc_clean($_POST['wc-' . $payment_method . '-payment-token']); |
|
707 | + $wc_token = WC_Payment_Tokens::get($wc_token_id); |
|
709 | 708 | |
710 | - if ( ! $wc_token || $wc_token->get_user_id() !== get_current_user_id() ) { |
|
711 | - WC()->session->set( 'refresh_totals', true ); |
|
712 | - throw new WC_Stripe_Exception( 'Invalid payment method', __( 'Invalid payment method. Please input a new card number.', 'woocommerce-gateway-stripe' ) ); |
|
709 | + if ( ! $wc_token || $wc_token->get_user_id() !== get_current_user_id()) { |
|
710 | + WC()->session->set('refresh_totals', true); |
|
711 | + throw new WC_Stripe_Exception('Invalid payment method', __('Invalid payment method. Please input a new card number.', 'woocommerce-gateway-stripe')); |
|
713 | 712 | } |
714 | 713 | |
715 | 714 | $source_id = $wc_token->get_token(); |
716 | 715 | |
717 | - if ( $this->is_type_legacy_card( $source_id ) ) { |
|
716 | + if ($this->is_type_legacy_card($source_id)) { |
|
718 | 717 | $is_token = true; |
719 | 718 | } |
720 | - } elseif ( isset( $_POST['stripe_token'] ) && 'new' !== $_POST['stripe_token'] ) { |
|
721 | - $stripe_token = wc_clean( $_POST['stripe_token'] ); |
|
722 | - $maybe_saved_card = isset( $_POST[ 'wc-' . $payment_method . '-new-payment-method' ] ) && ! empty( $_POST[ 'wc-' . $payment_method . '-new-payment-method' ] ); |
|
719 | + } elseif (isset($_POST['stripe_token']) && 'new' !== $_POST['stripe_token']) { |
|
720 | + $stripe_token = wc_clean($_POST['stripe_token']); |
|
721 | + $maybe_saved_card = isset($_POST['wc-' . $payment_method . '-new-payment-method']) && ! empty($_POST['wc-' . $payment_method . '-new-payment-method']); |
|
723 | 722 | |
724 | 723 | // This is true if the user wants to store the card to their account. |
725 | - if ( ( $user_id && $this->saved_cards && $maybe_saved_card ) || $force_save_source ) { |
|
726 | - $response = $customer->add_source( $stripe_token ); |
|
724 | + if (($user_id && $this->saved_cards && $maybe_saved_card) || $force_save_source) { |
|
725 | + $response = $customer->add_source($stripe_token); |
|
727 | 726 | |
728 | - if ( ! empty( $response->error ) ) { |
|
729 | - throw new WC_Stripe_Exception( print_r( $response, true ), $response->error->message ); |
|
727 | + if ( ! empty($response->error)) { |
|
728 | + throw new WC_Stripe_Exception(print_r($response, true), $response->error->message); |
|
730 | 729 | } |
731 | 730 | } else { |
732 | 731 | $set_customer = false; |
@@ -735,14 +734,14 @@ discard block |
||
735 | 734 | } |
736 | 735 | } |
737 | 736 | |
738 | - if ( ! $set_customer ) { |
|
737 | + if ( ! $set_customer) { |
|
739 | 738 | $customer_id = false; |
740 | 739 | } else { |
741 | 740 | $customer_id = $customer->get_id() ? $customer->get_id() : false; |
742 | 741 | } |
743 | 742 | |
744 | - if ( empty( $source_object ) && ! $is_token ) { |
|
745 | - $source_object = self::get_source_object( $source_id ); |
|
743 | + if (empty($source_object) && ! $is_token) { |
|
744 | + $source_object = self::get_source_object($source_id); |
|
746 | 745 | } |
747 | 746 | |
748 | 747 | return (object) array( |
@@ -766,39 +765,39 @@ discard block |
||
766 | 765 | * @param object $order |
767 | 766 | * @return object |
768 | 767 | */ |
769 | - public function prepare_order_source( $order = null ) { |
|
768 | + public function prepare_order_source($order = null) { |
|
770 | 769 | $stripe_customer = new WC_Stripe_Customer(); |
771 | 770 | $stripe_source = false; |
772 | 771 | $token_id = false; |
773 | 772 | $source_object = false; |
774 | 773 | |
775 | - if ( $order ) { |
|
776 | - $order_id = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->id : $order->get_id(); |
|
774 | + if ($order) { |
|
775 | + $order_id = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->id : $order->get_id(); |
|
777 | 776 | |
778 | - $stripe_customer_id = get_post_meta( $order_id, '_stripe_customer_id', true ); |
|
777 | + $stripe_customer_id = get_post_meta($order_id, '_stripe_customer_id', true); |
|
779 | 778 | |
780 | - if ( $stripe_customer_id ) { |
|
781 | - $stripe_customer->set_id( $stripe_customer_id ); |
|
779 | + if ($stripe_customer_id) { |
|
780 | + $stripe_customer->set_id($stripe_customer_id); |
|
782 | 781 | } |
783 | 782 | |
784 | - $source_id = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? get_post_meta( $order_id, '_stripe_source_id', true ) : $order->get_meta( '_stripe_source_id', true ); |
|
783 | + $source_id = WC_Stripe_Helper::is_wc_lt('3.0') ? get_post_meta($order_id, '_stripe_source_id', true) : $order->get_meta('_stripe_source_id', true); |
|
785 | 784 | |
786 | 785 | // Since 4.0.0, we changed card to source so we need to account for that. |
787 | - if ( empty( $source_id ) ) { |
|
788 | - $source_id = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? get_post_meta( $order_id, '_stripe_card_id', true ) : $order->get_meta( '_stripe_card_id', true ); |
|
786 | + if (empty($source_id)) { |
|
787 | + $source_id = WC_Stripe_Helper::is_wc_lt('3.0') ? get_post_meta($order_id, '_stripe_card_id', true) : $order->get_meta('_stripe_card_id', true); |
|
789 | 788 | |
790 | 789 | // Take this opportunity to update the key name. |
791 | - WC_Stripe_Helper::is_wc_lt( '3.0' ) ? update_post_meta( $order_id, '_stripe_source_id', $source_id ) : $order->update_meta_data( '_stripe_source_id', $source_id ); |
|
790 | + WC_Stripe_Helper::is_wc_lt('3.0') ? update_post_meta($order_id, '_stripe_source_id', $source_id) : $order->update_meta_data('_stripe_source_id', $source_id); |
|
792 | 791 | |
793 | - if ( is_callable( array( $order, 'save' ) ) ) { |
|
792 | + if (is_callable(array($order, 'save'))) { |
|
794 | 793 | $order->save(); |
795 | 794 | } |
796 | 795 | } |
797 | 796 | |
798 | - if ( $source_id ) { |
|
797 | + if ($source_id) { |
|
799 | 798 | $stripe_source = $source_id; |
800 | - $source_object = WC_Stripe_API::retrieve( 'sources/' . $source_id ); |
|
801 | - } elseif ( apply_filters( 'wc_stripe_use_default_customer_source', true ) ) { |
|
799 | + $source_object = WC_Stripe_API::retrieve('sources/' . $source_id); |
|
800 | + } elseif (apply_filters('wc_stripe_use_default_customer_source', true)) { |
|
802 | 801 | /* |
803 | 802 | * We can attempt to charge the customer's default source |
804 | 803 | * by sending empty source id. |
@@ -823,27 +822,27 @@ discard block |
||
823 | 822 | * @param WC_Order $order For to which the source applies. |
824 | 823 | * @param stdClass $source Source information. |
825 | 824 | */ |
826 | - public function save_source_to_order( $order, $source ) { |
|
827 | - $order_id = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->id : $order->get_id(); |
|
825 | + public function save_source_to_order($order, $source) { |
|
826 | + $order_id = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->id : $order->get_id(); |
|
828 | 827 | |
829 | 828 | // Store source in the order. |
830 | - if ( $source->customer ) { |
|
831 | - if ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ) { |
|
832 | - update_post_meta( $order_id, '_stripe_customer_id', $source->customer ); |
|
829 | + if ($source->customer) { |
|
830 | + if (WC_Stripe_Helper::is_wc_lt('3.0')) { |
|
831 | + update_post_meta($order_id, '_stripe_customer_id', $source->customer); |
|
833 | 832 | } else { |
834 | - $order->update_meta_data( '_stripe_customer_id', $source->customer ); |
|
833 | + $order->update_meta_data('_stripe_customer_id', $source->customer); |
|
835 | 834 | } |
836 | 835 | } |
837 | 836 | |
838 | - if ( $source->source ) { |
|
839 | - if ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ) { |
|
840 | - update_post_meta( $order_id, '_stripe_source_id', $source->source ); |
|
837 | + if ($source->source) { |
|
838 | + if (WC_Stripe_Helper::is_wc_lt('3.0')) { |
|
839 | + update_post_meta($order_id, '_stripe_source_id', $source->source); |
|
841 | 840 | } else { |
842 | - $order->update_meta_data( '_stripe_source_id', $source->source ); |
|
841 | + $order->update_meta_data('_stripe_source_id', $source->source); |
|
843 | 842 | } |
844 | 843 | } |
845 | 844 | |
846 | - if ( is_callable( array( $order, 'save' ) ) ) { |
|
845 | + if (is_callable(array($order, 'save'))) { |
|
847 | 846 | $order->save(); |
848 | 847 | } |
849 | 848 | } |
@@ -857,38 +856,38 @@ discard block |
||
857 | 856 | * @param object $order The order object |
858 | 857 | * @param int $balance_transaction_id |
859 | 858 | */ |
860 | - public function update_fees( $order, $balance_transaction_id ) { |
|
861 | - $order_id = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->id : $order->get_id(); |
|
859 | + public function update_fees($order, $balance_transaction_id) { |
|
860 | + $order_id = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->id : $order->get_id(); |
|
862 | 861 | |
863 | - $balance_transaction = WC_Stripe_API::retrieve( 'balance/history/' . $balance_transaction_id ); |
|
862 | + $balance_transaction = WC_Stripe_API::retrieve('balance/history/' . $balance_transaction_id); |
|
864 | 863 | |
865 | - if ( empty( $balance_transaction->error ) ) { |
|
866 | - if ( isset( $balance_transaction ) && isset( $balance_transaction->fee ) ) { |
|
864 | + if (empty($balance_transaction->error)) { |
|
865 | + if (isset($balance_transaction) && isset($balance_transaction->fee)) { |
|
867 | 866 | // Fees and Net needs to both come from Stripe to be accurate as the returned |
868 | 867 | // values are in the local currency of the Stripe account, not from WC. |
869 | - $fee_refund = ! empty( $balance_transaction->fee ) ? WC_Stripe_Helper::format_balance_fee( $balance_transaction, 'fee' ) : 0; |
|
870 | - $net_refund = ! empty( $balance_transaction->net ) ? WC_Stripe_Helper::format_balance_fee( $balance_transaction, 'net' ) : 0; |
|
868 | + $fee_refund = ! empty($balance_transaction->fee) ? WC_Stripe_Helper::format_balance_fee($balance_transaction, 'fee') : 0; |
|
869 | + $net_refund = ! empty($balance_transaction->net) ? WC_Stripe_Helper::format_balance_fee($balance_transaction, 'net') : 0; |
|
871 | 870 | |
872 | 871 | // Current data fee & net. |
873 | - $fee_current = WC_Stripe_Helper::get_stripe_fee( $order ); |
|
874 | - $net_current = WC_Stripe_Helper::get_stripe_net( $order ); |
|
872 | + $fee_current = WC_Stripe_Helper::get_stripe_fee($order); |
|
873 | + $net_current = WC_Stripe_Helper::get_stripe_net($order); |
|
875 | 874 | |
876 | 875 | // Calculation. |
877 | 876 | $fee = (float) $fee_current + (float) $fee_refund; |
878 | 877 | $net = (float) $net_current + (float) $net_refund; |
879 | 878 | |
880 | - WC_Stripe_Helper::update_stripe_fee( $order, $fee ); |
|
881 | - WC_Stripe_Helper::update_stripe_net( $order, $net ); |
|
879 | + WC_Stripe_Helper::update_stripe_fee($order, $fee); |
|
880 | + WC_Stripe_Helper::update_stripe_net($order, $net); |
|
882 | 881 | |
883 | - $currency = ! empty( $balance_transaction->currency ) ? strtoupper( $balance_transaction->currency ) : null; |
|
884 | - WC_Stripe_Helper::update_stripe_currency( $order, $currency ); |
|
882 | + $currency = ! empty($balance_transaction->currency) ? strtoupper($balance_transaction->currency) : null; |
|
883 | + WC_Stripe_Helper::update_stripe_currency($order, $currency); |
|
885 | 884 | |
886 | - if ( is_callable( array( $order, 'save' ) ) ) { |
|
885 | + if (is_callable(array($order, 'save'))) { |
|
887 | 886 | $order->save(); |
888 | 887 | } |
889 | 888 | } |
890 | 889 | } else { |
891 | - WC_Stripe_Logger::log( "Unable to update fees/net meta for order: {$order_id}" ); |
|
890 | + WC_Stripe_Logger::log("Unable to update fees/net meta for order: {$order_id}"); |
|
892 | 891 | } |
893 | 892 | } |
894 | 893 | |
@@ -901,33 +900,33 @@ discard block |
||
901 | 900 | * @param float $amount |
902 | 901 | * @return bool |
903 | 902 | */ |
904 | - public function process_refund( $order_id, $amount = null, $reason = '' ) { |
|
905 | - $order = wc_get_order( $order_id ); |
|
903 | + public function process_refund($order_id, $amount = null, $reason = '') { |
|
904 | + $order = wc_get_order($order_id); |
|
906 | 905 | |
907 | - if ( ! $order || ! $order->get_transaction_id() ) { |
|
906 | + if ( ! $order || ! $order->get_transaction_id()) { |
|
908 | 907 | return false; |
909 | 908 | } |
910 | 909 | |
911 | 910 | $request = array(); |
912 | 911 | |
913 | - if ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ) { |
|
914 | - $order_currency = get_post_meta( $order_id, '_order_currency', true ); |
|
915 | - $captured = get_post_meta( $order_id, '_stripe_charge_captured', true ); |
|
912 | + if (WC_Stripe_Helper::is_wc_lt('3.0')) { |
|
913 | + $order_currency = get_post_meta($order_id, '_order_currency', true); |
|
914 | + $captured = get_post_meta($order_id, '_stripe_charge_captured', true); |
|
916 | 915 | } else { |
917 | 916 | $order_currency = $order->get_currency(); |
918 | - $captured = $order->get_meta( '_stripe_charge_captured', true ); |
|
917 | + $captured = $order->get_meta('_stripe_charge_captured', true); |
|
919 | 918 | } |
920 | 919 | |
921 | - if ( ! is_null( $amount ) ) { |
|
922 | - $request['amount'] = WC_Stripe_Helper::get_stripe_amount( $amount, $order_currency ); |
|
920 | + if ( ! is_null($amount)) { |
|
921 | + $request['amount'] = WC_Stripe_Helper::get_stripe_amount($amount, $order_currency); |
|
923 | 922 | } |
924 | 923 | |
925 | 924 | // If order is only authorized, don't pass amount. |
926 | - if ( 'yes' !== $captured ) { |
|
927 | - unset( $request['amount'] ); |
|
925 | + if ('yes' !== $captured) { |
|
926 | + unset($request['amount']); |
|
928 | 927 | } |
929 | 928 | |
930 | - if ( $reason ) { |
|
929 | + if ($reason) { |
|
931 | 930 | $request['metadata'] = array( |
932 | 931 | 'reason' => $reason, |
933 | 932 | ); |
@@ -935,35 +934,35 @@ discard block |
||
935 | 934 | |
936 | 935 | $request['charge'] = $order->get_transaction_id(); |
937 | 936 | |
938 | - WC_Stripe_Logger::log( "Info: Beginning refund for order {$order->get_transaction_id()} for the amount of {$amount}" ); |
|
937 | + WC_Stripe_Logger::log("Info: Beginning refund for order {$order->get_transaction_id()} for the amount of {$amount}"); |
|
939 | 938 | |
940 | - $request = apply_filters( 'wc_stripe_refund_request', $request, $order ); |
|
939 | + $request = apply_filters('wc_stripe_refund_request', $request, $order); |
|
941 | 940 | |
942 | - $response = WC_Stripe_API::request( $request, 'refunds' ); |
|
941 | + $response = WC_Stripe_API::request($request, 'refunds'); |
|
943 | 942 | |
944 | - if ( ! empty( $response->error ) ) { |
|
945 | - WC_Stripe_Logger::log( 'Error: ' . $response->error->message ); |
|
943 | + if ( ! empty($response->error)) { |
|
944 | + WC_Stripe_Logger::log('Error: ' . $response->error->message); |
|
946 | 945 | |
947 | 946 | return $response; |
948 | 947 | |
949 | - } elseif ( ! empty( $response->id ) ) { |
|
950 | - WC_Stripe_Helper::is_wc_lt( '3.0' ) ? update_post_meta( $order_id, '_stripe_refund_id', $response->id ) : $order->update_meta_data( '_stripe_refund_id', $response->id ); |
|
948 | + } elseif ( ! empty($response->id)) { |
|
949 | + WC_Stripe_Helper::is_wc_lt('3.0') ? update_post_meta($order_id, '_stripe_refund_id', $response->id) : $order->update_meta_data('_stripe_refund_id', $response->id); |
|
951 | 950 | |
952 | - $amount = wc_price( $response->amount / 100 ); |
|
951 | + $amount = wc_price($response->amount / 100); |
|
953 | 952 | |
954 | - if ( in_array( strtolower( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->get_order_currency() : $order->get_currency() ), WC_Stripe_Helper::no_decimal_currencies() ) ) { |
|
955 | - $amount = wc_price( $response->amount ); |
|
953 | + if (in_array(strtolower(WC_Stripe_Helper::is_wc_lt('3.0') ? $order->get_order_currency() : $order->get_currency()), WC_Stripe_Helper::no_decimal_currencies())) { |
|
954 | + $amount = wc_price($response->amount); |
|
956 | 955 | } |
957 | 956 | |
958 | - if ( isset( $response->balance_transaction ) ) { |
|
959 | - $this->update_fees( $order, $response->balance_transaction ); |
|
957 | + if (isset($response->balance_transaction)) { |
|
958 | + $this->update_fees($order, $response->balance_transaction); |
|
960 | 959 | } |
961 | 960 | |
962 | 961 | /* translators: 1) dollar amount 2) transaction id 3) refund message */ |
963 | - $refund_message = ( isset( $captured ) && 'yes' === $captured ) ? sprintf( __( 'Refunded %1$s - Refund ID: %2$s - Reason: %3$s', 'woocommerce-gateway-stripe' ), $amount, $response->id, $reason ) : __( 'Pre-Authorization Released', 'woocommerce-gateway-stripe' ); |
|
962 | + $refund_message = (isset($captured) && 'yes' === $captured) ? sprintf(__('Refunded %1$s - Refund ID: %2$s - Reason: %3$s', 'woocommerce-gateway-stripe'), $amount, $response->id, $reason) : __('Pre-Authorization Released', 'woocommerce-gateway-stripe'); |
|
964 | 963 | |
965 | - $order->add_order_note( $refund_message ); |
|
966 | - WC_Stripe_Logger::log( 'Success: ' . html_entity_decode( wp_strip_all_tags( $refund_message ) ) ); |
|
964 | + $order->add_order_note($refund_message); |
|
965 | + WC_Stripe_Logger::log('Success: ' . html_entity_decode(wp_strip_all_tags($refund_message))); |
|
967 | 966 | |
968 | 967 | return true; |
969 | 968 | } |
@@ -978,46 +977,46 @@ discard block |
||
978 | 977 | */ |
979 | 978 | public function add_payment_method() { |
980 | 979 | $error = false; |
981 | - $error_msg = __( 'There was a problem adding the payment method.', 'woocommerce-gateway-stripe' ); |
|
980 | + $error_msg = __('There was a problem adding the payment method.', 'woocommerce-gateway-stripe'); |
|
982 | 981 | $source_id = ''; |
983 | 982 | |
984 | - if ( empty( $_POST['stripe_source'] ) && empty( $_POST['stripe_token'] ) || ! is_user_logged_in() ) { |
|
983 | + if (empty($_POST['stripe_source']) && empty($_POST['stripe_token']) || ! is_user_logged_in()) { |
|
985 | 984 | $error = true; |
986 | 985 | } |
987 | 986 | |
988 | - $stripe_customer = new WC_Stripe_Customer( get_current_user_id() ); |
|
987 | + $stripe_customer = new WC_Stripe_Customer(get_current_user_id()); |
|
989 | 988 | |
990 | - $source = ! empty( $_POST['stripe_source'] ) ? wc_clean( $_POST['stripe_source'] ) : ''; |
|
989 | + $source = ! empty($_POST['stripe_source']) ? wc_clean($_POST['stripe_source']) : ''; |
|
991 | 990 | |
992 | - $source_object = WC_Stripe_API::retrieve( 'sources/' . $source ); |
|
991 | + $source_object = WC_Stripe_API::retrieve('sources/' . $source); |
|
993 | 992 | |
994 | - if ( isset( $source_object ) ) { |
|
995 | - if ( ! empty( $source_object->error ) ) { |
|
993 | + if (isset($source_object)) { |
|
994 | + if ( ! empty($source_object->error)) { |
|
996 | 995 | $error = true; |
997 | 996 | } |
998 | 997 | |
999 | 998 | $source_id = $source_object->id; |
1000 | - } elseif ( isset( $_POST['stripe_token'] ) ) { |
|
1001 | - $source_id = wc_clean( $_POST['stripe_token'] ); |
|
999 | + } elseif (isset($_POST['stripe_token'])) { |
|
1000 | + $source_id = wc_clean($_POST['stripe_token']); |
|
1002 | 1001 | } |
1003 | 1002 | |
1004 | - $response = $stripe_customer->add_source( $source_id ); |
|
1003 | + $response = $stripe_customer->add_source($source_id); |
|
1005 | 1004 | |
1006 | - if ( ! $response || is_wp_error( $response ) || ! empty( $response->error ) ) { |
|
1005 | + if ( ! $response || is_wp_error($response) || ! empty($response->error)) { |
|
1007 | 1006 | $error = true; |
1008 | 1007 | } |
1009 | 1008 | |
1010 | - if ( $error ) { |
|
1011 | - wc_add_notice( $error_msg, 'error' ); |
|
1012 | - WC_Stripe_Logger::log( 'Add payment method Error: ' . $error_msg ); |
|
1009 | + if ($error) { |
|
1010 | + wc_add_notice($error_msg, 'error'); |
|
1011 | + WC_Stripe_Logger::log('Add payment method Error: ' . $error_msg); |
|
1013 | 1012 | return; |
1014 | 1013 | } |
1015 | 1014 | |
1016 | - do_action( 'wc_stripe_add_payment_method_' . $_POST['payment_method'] . '_success', $source_id, $source_object ); |
|
1015 | + do_action('wc_stripe_add_payment_method_' . $_POST['payment_method'] . '_success', $source_id, $source_object); |
|
1017 | 1016 | |
1018 | 1017 | return array( |
1019 | 1018 | 'result' => 'success', |
1020 | - 'redirect' => wc_get_endpoint_url( 'payment-methods' ), |
|
1019 | + 'redirect' => wc_get_endpoint_url('payment-methods'), |
|
1021 | 1020 | ); |
1022 | 1021 | } |
1023 | 1022 | |
@@ -1034,10 +1033,10 @@ discard block |
||
1034 | 1033 | * Stripe expects Norwegian to only be passed NO. |
1035 | 1034 | * But WP has different dialects. |
1036 | 1035 | */ |
1037 | - if ( 'NO' === substr( $locale, 3, 2 ) ) { |
|
1036 | + if ('NO' === substr($locale, 3, 2)) { |
|
1038 | 1037 | $locale = 'no'; |
1039 | 1038 | } else { |
1040 | - $locale = substr( get_locale(), 0, 2 ); |
|
1039 | + $locale = substr(get_locale(), 0, 2); |
|
1041 | 1040 | } |
1042 | 1041 | |
1043 | 1042 | return $locale; |
@@ -1051,9 +1050,9 @@ discard block |
||
1051 | 1050 | * @param string $idempotency_key |
1052 | 1051 | * @param array $request |
1053 | 1052 | */ |
1054 | - public function change_idempotency_key( $idempotency_key, $request ) { |
|
1055 | - $customer = ! empty( $request['customer'] ) ? $request['customer'] : ''; |
|
1056 | - $source = ! empty( $request['source'] ) ? $request['source'] : $customer; |
|
1053 | + public function change_idempotency_key($idempotency_key, $request) { |
|
1054 | + $customer = ! empty($request['customer']) ? $request['customer'] : ''; |
|
1055 | + $source = ! empty($request['source']) ? $request['source'] : $customer; |
|
1057 | 1056 | $count = $this->retry_interval; |
1058 | 1057 | |
1059 | 1058 | return $request['metadata']['order_id'] . '-' . $count . '-' . $source; |
@@ -1067,8 +1066,8 @@ discard block |
||
1067 | 1066 | * @since 4.0.6 |
1068 | 1067 | * @param array $headers |
1069 | 1068 | */ |
1070 | - public function is_original_request( $headers ) { |
|
1071 | - if ( $headers['original-request'] === $headers['request-id'] ) { |
|
1069 | + public function is_original_request($headers) { |
|
1070 | + if ($headers['original-request'] === $headers['request-id']) { |
|
1072 | 1071 | return true; |
1073 | 1072 | } |
1074 | 1073 |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if ( ! defined('ABSPATH')) { |
|
3 | 3 | exit; // Exit if accessed directly |
4 | 4 | } |
5 | 5 | |
@@ -20,32 +20,32 @@ discard block |
||
20 | 20 | * @since 4.0.0 |
21 | 21 | * @version 4.0.0 |
22 | 22 | */ |
23 | - public static function log( $message, $start_time = null, $end_time = null ) { |
|
24 | - if ( ! class_exists( 'WC_Logger' ) ) { |
|
23 | + public static function log($message, $start_time = null, $end_time = null) { |
|
24 | + if ( ! class_exists('WC_Logger')) { |
|
25 | 25 | return; |
26 | 26 | } |
27 | 27 | |
28 | - if ( apply_filters( 'wc_stripe_logging', true, $message ) ) { |
|
29 | - if ( empty( self::$logger ) ) { |
|
30 | - if ( version_compare( WC_VERSION, '3.0.0', '>=' ) ) { |
|
28 | + if (apply_filters('wc_stripe_logging', true, $message)) { |
|
29 | + if (empty(self::$logger)) { |
|
30 | + if (version_compare(WC_VERSION, '3.0.0', '>=')) { |
|
31 | 31 | self::$logger = wc_get_logger(); |
32 | 32 | } else { |
33 | 33 | self::$logger = new WC_Logger(); |
34 | 34 | } |
35 | 35 | } |
36 | 36 | |
37 | - $settings = get_option( 'woocommerce_stripe_settings' ); |
|
37 | + $settings = get_option('woocommerce_stripe_settings'); |
|
38 | 38 | |
39 | - if ( empty( $settings ) || isset( $settings['logging'] ) && 'yes' !== $settings['logging'] ) { |
|
39 | + if (empty($settings) || isset($settings['logging']) && 'yes' !== $settings['logging']) { |
|
40 | 40 | return; |
41 | 41 | } |
42 | 42 | |
43 | - if ( ! is_null( $start_time ) ) { |
|
43 | + if ( ! is_null($start_time)) { |
|
44 | 44 | |
45 | - $formatted_start_time = date_i18n( get_option( 'date_format' ) . ' g:ia', $start_time ); |
|
46 | - $end_time = is_null( $end_time ) ? current_time( 'timestamp' ) : $end_time; |
|
47 | - $formatted_end_time = date_i18n( get_option( 'date_format' ) . ' g:ia', $end_time ); |
|
48 | - $elapsed_time = round( abs( $end_time - $start_time ) / 60, 2 ); |
|
45 | + $formatted_start_time = date_i18n(get_option('date_format') . ' g:ia', $start_time); |
|
46 | + $end_time = is_null($end_time) ? current_time('timestamp') : $end_time; |
|
47 | + $formatted_end_time = date_i18n(get_option('date_format') . ' g:ia', $end_time); |
|
48 | + $elapsed_time = round(abs($end_time - $start_time) / 60, 2); |
|
49 | 49 | |
50 | 50 | $log_entry = "\n" . '====Stripe Version: ' . WC_STRIPE_VERSION . '====' . "\n"; |
51 | 51 | $log_entry .= '====Start Log ' . $formatted_start_time . '====' . "\n" . $message . "\n"; |
@@ -57,10 +57,10 @@ discard block |
||
57 | 57 | |
58 | 58 | } |
59 | 59 | |
60 | - if ( version_compare( WC_VERSION, '3.0.0', '>=' ) ) { |
|
61 | - self::$logger->debug( $log_entry, array( 'source' => self::WC_LOG_FILENAME ) ); |
|
60 | + if (version_compare(WC_VERSION, '3.0.0', '>=')) { |
|
61 | + self::$logger->debug($log_entry, array('source' => self::WC_LOG_FILENAME)); |
|
62 | 62 | } else { |
63 | - self::$logger->add( self::WC_LOG_FILENAME, $log_entry ); |
|
63 | + self::$logger->add(self::WC_LOG_FILENAME, $log_entry); |
|
64 | 64 | } |
65 | 65 | } |
66 | 66 | } |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if ( ! defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | 5 | |
@@ -7,40 +7,40 @@ discard block |
||
7 | 7 | 'wc_stripe_giropay_settings', |
8 | 8 | array( |
9 | 9 | 'geo_target' => array( |
10 | - 'description' => __( 'Relevant Payer Geography: Germany', 'woocommerce-gateway-stripe' ), |
|
10 | + 'description' => __('Relevant Payer Geography: Germany', 'woocommerce-gateway-stripe'), |
|
11 | 11 | 'type' => 'title', |
12 | 12 | ), |
13 | 13 | 'guide' => array( |
14 | - 'description' => __( '<a href="https://stripe.com/payments/payment-methods-guide#giropay" target="_blank">Payment Method Guide</a>', 'woocommerce-gateway-stripe' ), |
|
14 | + 'description' => __('<a href="https://stripe.com/payments/payment-methods-guide#giropay" target="_blank">Payment Method Guide</a>', 'woocommerce-gateway-stripe'), |
|
15 | 15 | 'type' => 'title', |
16 | 16 | ), |
17 | 17 | 'activation' => array( |
18 | - 'description' => __( 'Must be activated from your Stripe Dashboard Settings <a href="https://dashboard.stripe.com/account/payments/settings" target="_blank">here</a>', 'woocommerce-gateway-stripe' ), |
|
18 | + 'description' => __('Must be activated from your Stripe Dashboard Settings <a href="https://dashboard.stripe.com/account/payments/settings" target="_blank">here</a>', 'woocommerce-gateway-stripe'), |
|
19 | 19 | 'type' => 'title', |
20 | 20 | ), |
21 | 21 | 'enabled' => array( |
22 | - 'title' => __( 'Enable/Disable', 'woocommerce-gateway-stripe' ), |
|
23 | - 'label' => __( 'Enable Stripe Giropay', 'woocommerce-gateway-stripe' ), |
|
22 | + 'title' => __('Enable/Disable', 'woocommerce-gateway-stripe'), |
|
23 | + 'label' => __('Enable Stripe Giropay', 'woocommerce-gateway-stripe'), |
|
24 | 24 | 'type' => 'checkbox', |
25 | 25 | 'description' => '', |
26 | 26 | 'default' => 'no', |
27 | 27 | ), |
28 | 28 | 'title' => array( |
29 | - 'title' => __( 'Title', 'woocommerce-gateway-stripe' ), |
|
29 | + 'title' => __('Title', 'woocommerce-gateway-stripe'), |
|
30 | 30 | 'type' => 'text', |
31 | - 'description' => __( 'This controls the title which the user sees during checkout.', 'woocommerce-gateway-stripe' ), |
|
32 | - 'default' => __( 'Giropay', 'woocommerce-gateway-stripe' ), |
|
31 | + 'description' => __('This controls the title which the user sees during checkout.', 'woocommerce-gateway-stripe'), |
|
32 | + 'default' => __('Giropay', 'woocommerce-gateway-stripe'), |
|
33 | 33 | 'desc_tip' => true, |
34 | 34 | ), |
35 | 35 | 'description' => array( |
36 | - 'title' => __( 'Description', 'woocommerce-gateway-stripe' ), |
|
36 | + 'title' => __('Description', 'woocommerce-gateway-stripe'), |
|
37 | 37 | 'type' => 'text', |
38 | - 'description' => __( 'This controls the description which the user sees during checkout.', 'woocommerce-gateway-stripe' ), |
|
39 | - 'default' => __( 'You will be redirected to Giropay.', 'woocommerce-gateway-stripe' ), |
|
38 | + 'description' => __('This controls the description which the user sees during checkout.', 'woocommerce-gateway-stripe'), |
|
39 | + 'default' => __('You will be redirected to Giropay.', 'woocommerce-gateway-stripe'), |
|
40 | 40 | 'desc_tip' => true, |
41 | 41 | ), |
42 | 42 | 'webhook' => array( |
43 | - 'title' => __( 'Webhook Endpoints', 'woocommerce-gateway-stripe' ), |
|
43 | + 'title' => __('Webhook Endpoints', 'woocommerce-gateway-stripe'), |
|
44 | 44 | 'type' => 'title', |
45 | 45 | /* translators: webhook URL */ |
46 | 46 | 'description' => $this->display_admin_settings_webhook_description(), |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if ( ! defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | 5 | |
@@ -7,40 +7,40 @@ discard block |
||
7 | 7 | 'wc_stripe_bancontact_settings', |
8 | 8 | array( |
9 | 9 | 'geo_target' => array( |
10 | - 'description' => __( 'Relevant Payer Geography: Belgium', 'woocommerce-gateway-stripe' ), |
|
10 | + 'description' => __('Relevant Payer Geography: Belgium', 'woocommerce-gateway-stripe'), |
|
11 | 11 | 'type' => 'title', |
12 | 12 | ), |
13 | 13 | 'guide' => array( |
14 | - 'description' => __( '<a href="https://stripe.com/payments/payment-methods-guide#bancontact" target="_blank">Payment Method Guide</a>', 'woocommerce-gateway-stripe' ), |
|
14 | + 'description' => __('<a href="https://stripe.com/payments/payment-methods-guide#bancontact" target="_blank">Payment Method Guide</a>', 'woocommerce-gateway-stripe'), |
|
15 | 15 | 'type' => 'title', |
16 | 16 | ), |
17 | 17 | 'activation' => array( |
18 | - 'description' => __( 'Must be activated from your Stripe Dashboard Settings <a href="https://dashboard.stripe.com/account/payments/settings" target="_blank">here</a>', 'woocommerce-gateway-stripe' ), |
|
18 | + 'description' => __('Must be activated from your Stripe Dashboard Settings <a href="https://dashboard.stripe.com/account/payments/settings" target="_blank">here</a>', 'woocommerce-gateway-stripe'), |
|
19 | 19 | 'type' => 'title', |
20 | 20 | ), |
21 | 21 | 'enabled' => array( |
22 | - 'title' => __( 'Enable/Disable', 'woocommerce-gateway-stripe' ), |
|
23 | - 'label' => __( 'Enable Stripe Bancontact', 'woocommerce-gateway-stripe' ), |
|
22 | + 'title' => __('Enable/Disable', 'woocommerce-gateway-stripe'), |
|
23 | + 'label' => __('Enable Stripe Bancontact', 'woocommerce-gateway-stripe'), |
|
24 | 24 | 'type' => 'checkbox', |
25 | 25 | 'description' => '', |
26 | 26 | 'default' => 'no', |
27 | 27 | ), |
28 | 28 | 'title' => array( |
29 | - 'title' => __( 'Title', 'woocommerce-gateway-stripe' ), |
|
29 | + 'title' => __('Title', 'woocommerce-gateway-stripe'), |
|
30 | 30 | 'type' => 'text', |
31 | - 'description' => __( 'This controls the title which the user sees during checkout.', 'woocommerce-gateway-stripe' ), |
|
32 | - 'default' => __( 'Bancontact', 'woocommerce-gateway-stripe' ), |
|
31 | + 'description' => __('This controls the title which the user sees during checkout.', 'woocommerce-gateway-stripe'), |
|
32 | + 'default' => __('Bancontact', 'woocommerce-gateway-stripe'), |
|
33 | 33 | 'desc_tip' => true, |
34 | 34 | ), |
35 | 35 | 'description' => array( |
36 | - 'title' => __( 'Description', 'woocommerce-gateway-stripe' ), |
|
36 | + 'title' => __('Description', 'woocommerce-gateway-stripe'), |
|
37 | 37 | 'type' => 'text', |
38 | - 'description' => __( 'This controls the description which the user sees during checkout.', 'woocommerce-gateway-stripe' ), |
|
39 | - 'default' => __( 'You will be redirected to Bancontact.', 'woocommerce-gateway-stripe' ), |
|
38 | + 'description' => __('This controls the description which the user sees during checkout.', 'woocommerce-gateway-stripe'), |
|
39 | + 'default' => __('You will be redirected to Bancontact.', 'woocommerce-gateway-stripe'), |
|
40 | 40 | 'desc_tip' => true, |
41 | 41 | ), |
42 | 42 | 'webhook' => array( |
43 | - 'title' => __( 'Webhook Endpoints', 'woocommerce-gateway-stripe' ), |
|
43 | + 'title' => __('Webhook Endpoints', 'woocommerce-gateway-stripe'), |
|
44 | 44 | 'type' => 'title', |
45 | 45 | /* translators: webhook URL */ |
46 | 46 | 'description' => $this->display_admin_settings_webhook_description(), |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if ( ! defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | 5 | |
@@ -7,36 +7,36 @@ discard block |
||
7 | 7 | 'wc_stripe_multibanco_settings', |
8 | 8 | array( |
9 | 9 | 'geo_target' => array( |
10 | - 'description' => __( 'Relevant Payer Geography: Portugal', 'woocommerce-gateway-stripe' ), |
|
10 | + 'description' => __('Relevant Payer Geography: Portugal', 'woocommerce-gateway-stripe'), |
|
11 | 11 | 'type' => 'title', |
12 | 12 | ), |
13 | 13 | 'activation' => array( |
14 | - 'description' => __( 'Must be activated from your Stripe Dashboard Settings <a href="https://dashboard.stripe.com/account/payments/settings" target="_blank">here</a>', 'woocommerce-gateway-stripe' ), |
|
14 | + 'description' => __('Must be activated from your Stripe Dashboard Settings <a href="https://dashboard.stripe.com/account/payments/settings" target="_blank">here</a>', 'woocommerce-gateway-stripe'), |
|
15 | 15 | 'type' => 'title', |
16 | 16 | ), |
17 | 17 | 'enabled' => array( |
18 | - 'title' => __( 'Enable/Disable', 'woocommerce-gateway-stripe' ), |
|
19 | - 'label' => __( 'Enable Stripe Multibanco', 'woocommerce-gateway-stripe' ), |
|
18 | + 'title' => __('Enable/Disable', 'woocommerce-gateway-stripe'), |
|
19 | + 'label' => __('Enable Stripe Multibanco', 'woocommerce-gateway-stripe'), |
|
20 | 20 | 'type' => 'checkbox', |
21 | 21 | 'description' => '', |
22 | 22 | 'default' => 'no', |
23 | 23 | ), |
24 | 24 | 'title' => array( |
25 | - 'title' => __( 'Title', 'woocommerce-gateway-stripe' ), |
|
25 | + 'title' => __('Title', 'woocommerce-gateway-stripe'), |
|
26 | 26 | 'type' => 'text', |
27 | - 'description' => __( 'This controls the title which the user sees during checkout.', 'woocommerce-gateway-stripe' ), |
|
28 | - 'default' => __( 'Multibanco', 'woocommerce-gateway-stripe' ), |
|
27 | + 'description' => __('This controls the title which the user sees during checkout.', 'woocommerce-gateway-stripe'), |
|
28 | + 'default' => __('Multibanco', 'woocommerce-gateway-stripe'), |
|
29 | 29 | 'desc_tip' => true, |
30 | 30 | ), |
31 | 31 | 'description' => array( |
32 | - 'title' => __( 'Description', 'woocommerce-gateway-stripe' ), |
|
32 | + 'title' => __('Description', 'woocommerce-gateway-stripe'), |
|
33 | 33 | 'type' => 'text', |
34 | - 'description' => __( 'This controls the description which the user sees during checkout.', 'woocommerce-gateway-stripe' ), |
|
35 | - 'default' => __( 'You will be redirected to Multibanco.', 'woocommerce-gateway-stripe' ), |
|
34 | + 'description' => __('This controls the description which the user sees during checkout.', 'woocommerce-gateway-stripe'), |
|
35 | + 'default' => __('You will be redirected to Multibanco.', 'woocommerce-gateway-stripe'), |
|
36 | 36 | 'desc_tip' => true, |
37 | 37 | ), |
38 | 38 | 'webhook' => array( |
39 | - 'title' => __( 'Webhook Endpoints', 'woocommerce-gateway-stripe' ), |
|
39 | + 'title' => __('Webhook Endpoints', 'woocommerce-gateway-stripe'), |
|
40 | 40 | 'type' => 'title', |
41 | 41 | /* translators: webhook URL */ |
42 | 42 | 'description' => $this->display_admin_settings_webhook_description(), |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if ( ! defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | 5 | |
@@ -7,40 +7,40 @@ discard block |
||
7 | 7 | 'wc_stripe_ideal_settings', |
8 | 8 | array( |
9 | 9 | 'geo_target' => array( |
10 | - 'description' => __( 'Relevant Payer Geography: The Netherlands', 'woocommerce-gateway-stripe' ), |
|
10 | + 'description' => __('Relevant Payer Geography: The Netherlands', 'woocommerce-gateway-stripe'), |
|
11 | 11 | 'type' => 'title', |
12 | 12 | ), |
13 | 13 | 'guide' => array( |
14 | - 'description' => __( '<a href="https://stripe.com/payments/payment-methods-guide#ideal" target="_blank">Payment Method Guide</a>', 'woocommerce-gateway-stripe' ), |
|
14 | + 'description' => __('<a href="https://stripe.com/payments/payment-methods-guide#ideal" target="_blank">Payment Method Guide</a>', 'woocommerce-gateway-stripe'), |
|
15 | 15 | 'type' => 'title', |
16 | 16 | ), |
17 | 17 | 'activation' => array( |
18 | - 'description' => __( 'Must be activated from your Stripe Dashboard Settings <a href="https://dashboard.stripe.com/account/payments/settings" target="_blank">here</a>', 'woocommerce-gateway-stripe' ), |
|
18 | + 'description' => __('Must be activated from your Stripe Dashboard Settings <a href="https://dashboard.stripe.com/account/payments/settings" target="_blank">here</a>', 'woocommerce-gateway-stripe'), |
|
19 | 19 | 'type' => 'title', |
20 | 20 | ), |
21 | 21 | 'enabled' => array( |
22 | - 'title' => __( 'Enable/Disable', 'woocommerce-gateway-stripe' ), |
|
23 | - 'label' => __( 'Enable Stripe iDeal', 'woocommerce-gateway-stripe' ), |
|
22 | + 'title' => __('Enable/Disable', 'woocommerce-gateway-stripe'), |
|
23 | + 'label' => __('Enable Stripe iDeal', 'woocommerce-gateway-stripe'), |
|
24 | 24 | 'type' => 'checkbox', |
25 | 25 | 'description' => '', |
26 | 26 | 'default' => 'no', |
27 | 27 | ), |
28 | 28 | 'title' => array( |
29 | - 'title' => __( 'Title', 'woocommerce-gateway-stripe' ), |
|
29 | + 'title' => __('Title', 'woocommerce-gateway-stripe'), |
|
30 | 30 | 'type' => 'text', |
31 | - 'description' => __( 'This controls the title which the user sees during checkout.', 'woocommerce-gateway-stripe' ), |
|
32 | - 'default' => __( 'iDeal', 'woocommerce-gateway-stripe' ), |
|
31 | + 'description' => __('This controls the title which the user sees during checkout.', 'woocommerce-gateway-stripe'), |
|
32 | + 'default' => __('iDeal', 'woocommerce-gateway-stripe'), |
|
33 | 33 | 'desc_tip' => true, |
34 | 34 | ), |
35 | 35 | 'description' => array( |
36 | - 'title' => __( 'Description', 'woocommerce-gateway-stripe' ), |
|
36 | + 'title' => __('Description', 'woocommerce-gateway-stripe'), |
|
37 | 37 | 'type' => 'text', |
38 | - 'description' => __( 'This controls the description which the user sees during checkout.', 'woocommerce-gateway-stripe' ), |
|
39 | - 'default' => __( 'You will be redirected to iDeal.', 'woocommerce-gateway-stripe' ), |
|
38 | + 'description' => __('This controls the description which the user sees during checkout.', 'woocommerce-gateway-stripe'), |
|
39 | + 'default' => __('You will be redirected to iDeal.', 'woocommerce-gateway-stripe'), |
|
40 | 40 | 'desc_tip' => true, |
41 | 41 | ), |
42 | 42 | 'webhook' => array( |
43 | - 'title' => __( 'Webhook Endpoints', 'woocommerce-gateway-stripe' ), |
|
43 | + 'title' => __('Webhook Endpoints', 'woocommerce-gateway-stripe'), |
|
44 | 44 | 'type' => 'title', |
45 | 45 | /* translators: webhook URL */ |
46 | 46 | 'description' => $this->display_admin_settings_webhook_description(), |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if ( ! defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | 5 | |
@@ -21,8 +21,8 @@ discard block |
||
21 | 21 | * @since 4.1.0 |
22 | 22 | */ |
23 | 23 | public function __construct() { |
24 | - add_action( 'admin_notices', array( $this, 'admin_notices' ) ); |
|
25 | - add_action( 'wp_loaded', array( $this, 'hide_notices' ) ); |
|
24 | + add_action('admin_notices', array($this, 'admin_notices')); |
|
25 | + add_action('wp_loaded', array($this, 'hide_notices')); |
|
26 | 26 | } |
27 | 27 | |
28 | 28 | /** |
@@ -31,8 +31,8 @@ discard block |
||
31 | 31 | * @since 1.0.0 |
32 | 32 | * @version 4.0.0 |
33 | 33 | */ |
34 | - public function add_admin_notice( $slug, $class, $message, $dismissible = false ) { |
|
35 | - $this->notices[ $slug ] = array( |
|
34 | + public function add_admin_notice($slug, $class, $message, $dismissible = false) { |
|
35 | + $this->notices[$slug] = array( |
|
36 | 36 | 'class' => $class, |
37 | 37 | 'message' => $message, |
38 | 38 | 'dismissible' => $dismissible, |
@@ -46,7 +46,7 @@ discard block |
||
46 | 46 | * @version 4.0.0 |
47 | 47 | */ |
48 | 48 | public function admin_notices() { |
49 | - if ( ! current_user_can( 'manage_woocommerce' ) ) { |
|
49 | + if ( ! current_user_can('manage_woocommerce')) { |
|
50 | 50 | return; |
51 | 51 | } |
52 | 52 | |
@@ -56,17 +56,17 @@ discard block |
||
56 | 56 | // All other payment methods. |
57 | 57 | $this->payment_methods_check_environment(); |
58 | 58 | |
59 | - foreach ( (array) $this->notices as $notice_key => $notice ) { |
|
60 | - echo '<div class="' . esc_attr( $notice['class'] ) . '" style="position:relative;">'; |
|
59 | + foreach ((array) $this->notices as $notice_key => $notice) { |
|
60 | + echo '<div class="' . esc_attr($notice['class']) . '" style="position:relative;">'; |
|
61 | 61 | |
62 | - if ( $notice['dismissible'] ) { |
|
62 | + if ($notice['dismissible']) { |
|
63 | 63 | ?> |
64 | - <a href="<?php echo esc_url( wp_nonce_url( add_query_arg( 'wc-stripe-hide-notice', $notice_key ), 'wc_stripe_hide_notices_nonce', '_wc_stripe_notice_nonce' ) ); ?>" class="woocommerce-message-close notice-dismiss" style="position:absolute;right:1px;padding:9px;text-decoration:none;"></a> |
|
64 | + <a href="<?php echo esc_url(wp_nonce_url(add_query_arg('wc-stripe-hide-notice', $notice_key), 'wc_stripe_hide_notices_nonce', '_wc_stripe_notice_nonce')); ?>" class="woocommerce-message-close notice-dismiss" style="position:absolute;right:1px;padding:9px;text-decoration:none;"></a> |
|
65 | 65 | <?php |
66 | 66 | } |
67 | 67 | |
68 | 68 | echo '<p>'; |
69 | - echo wp_kses( $notice['message'], array( 'a' => array( 'href' => array() ) ) ); |
|
69 | + echo wp_kses($notice['message'], array('a' => array('href' => array()))); |
|
70 | 70 | echo '</p></div>'; |
71 | 71 | } |
72 | 72 | } |
@@ -99,83 +99,83 @@ discard block |
||
99 | 99 | * @version 4.0.0 |
100 | 100 | */ |
101 | 101 | public function stripe_check_environment() { |
102 | - $show_ssl_notice = get_option( 'wc_stripe_show_ssl_notice' ); |
|
103 | - $show_keys_notice = get_option( 'wc_stripe_show_keys_notice' ); |
|
104 | - $show_phpver_notice = get_option( 'wc_stripe_show_phpver_notice' ); |
|
105 | - $show_wcver_notice = get_option( 'wc_stripe_show_wcver_notice' ); |
|
106 | - $show_curl_notice = get_option( 'wc_stripe_show_curl_notice' ); |
|
107 | - $options = get_option( 'woocommerce_stripe_settings' ); |
|
108 | - $testmode = ( isset( $options['testmode'] ) && 'yes' === $options['testmode'] ) ? true : false; |
|
109 | - $test_pub_key = isset( $options['test_publishable_key'] ) ? $options['test_publishable_key'] : ''; |
|
110 | - $test_secret_key = isset( $options['test_secret_key'] ) ? $options['test_secret_key'] : ''; |
|
111 | - $live_pub_key = isset( $options['publishable_key'] ) ? $options['publishable_key'] : ''; |
|
112 | - $live_secret_key = isset( $options['secret_key'] ) ? $options['secret_key'] : ''; |
|
113 | - |
|
114 | - if ( isset( $options['enabled'] ) && 'yes' === $options['enabled'] ) { |
|
115 | - if ( empty( $show_phpver_notice ) ) { |
|
116 | - if ( version_compare( phpversion(), WC_STRIPE_MIN_PHP_VER, '<' ) ) { |
|
102 | + $show_ssl_notice = get_option('wc_stripe_show_ssl_notice'); |
|
103 | + $show_keys_notice = get_option('wc_stripe_show_keys_notice'); |
|
104 | + $show_phpver_notice = get_option('wc_stripe_show_phpver_notice'); |
|
105 | + $show_wcver_notice = get_option('wc_stripe_show_wcver_notice'); |
|
106 | + $show_curl_notice = get_option('wc_stripe_show_curl_notice'); |
|
107 | + $options = get_option('woocommerce_stripe_settings'); |
|
108 | + $testmode = (isset($options['testmode']) && 'yes' === $options['testmode']) ? true : false; |
|
109 | + $test_pub_key = isset($options['test_publishable_key']) ? $options['test_publishable_key'] : ''; |
|
110 | + $test_secret_key = isset($options['test_secret_key']) ? $options['test_secret_key'] : ''; |
|
111 | + $live_pub_key = isset($options['publishable_key']) ? $options['publishable_key'] : ''; |
|
112 | + $live_secret_key = isset($options['secret_key']) ? $options['secret_key'] : ''; |
|
113 | + |
|
114 | + if (isset($options['enabled']) && 'yes' === $options['enabled']) { |
|
115 | + if (empty($show_phpver_notice)) { |
|
116 | + if (version_compare(phpversion(), WC_STRIPE_MIN_PHP_VER, '<')) { |
|
117 | 117 | /* translators: 1) int version 2) int version */ |
118 | - $message = __( 'WooCommerce Stripe - The minimum PHP version required for this plugin is %1$s. You are running %2$s.', 'woocommerce-gateway-stripe' ); |
|
118 | + $message = __('WooCommerce Stripe - The minimum PHP version required for this plugin is %1$s. You are running %2$s.', 'woocommerce-gateway-stripe'); |
|
119 | 119 | |
120 | - $this->add_admin_notice( 'phpver', 'error', sprintf( $message, WC_STRIPE_MIN_PHP_VER, phpversion() ), true ); |
|
120 | + $this->add_admin_notice('phpver', 'error', sprintf($message, WC_STRIPE_MIN_PHP_VER, phpversion()), true); |
|
121 | 121 | |
122 | 122 | return; |
123 | 123 | } |
124 | 124 | } |
125 | 125 | |
126 | - if ( empty( $show_wcver_notice ) ) { |
|
127 | - if ( version_compare( WC_VERSION, WC_STRIPE_MIN_WC_VER, '<' ) ) { |
|
126 | + if (empty($show_wcver_notice)) { |
|
127 | + if (version_compare(WC_VERSION, WC_STRIPE_MIN_WC_VER, '<')) { |
|
128 | 128 | /* translators: 1) int version 2) int version */ |
129 | - $message = __( 'WooCommerce Stripe - The minimum WooCommerce version required for this plugin is %1$s. You are running %2$s.', 'woocommerce-gateway-stripe' ); |
|
129 | + $message = __('WooCommerce Stripe - The minimum WooCommerce version required for this plugin is %1$s. You are running %2$s.', 'woocommerce-gateway-stripe'); |
|
130 | 130 | |
131 | - $this->add_admin_notice( 'wcver', 'notice notice-warning', sprintf( $message, WC_STRIPE_MIN_WC_VER, WC_VERSION ), true ); |
|
131 | + $this->add_admin_notice('wcver', 'notice notice-warning', sprintf($message, WC_STRIPE_MIN_WC_VER, WC_VERSION), true); |
|
132 | 132 | |
133 | 133 | return; |
134 | 134 | } |
135 | 135 | } |
136 | 136 | |
137 | - if ( empty( $show_curl_notice ) ) { |
|
138 | - if ( ! function_exists( 'curl_init' ) ) { |
|
139 | - $this->add_admin_notice( 'curl', 'notice notice-warning', __( 'WooCommerce Stripe - cURL is not installed.', 'woocommerce-gateway-stripe' ), true ); |
|
137 | + if (empty($show_curl_notice)) { |
|
138 | + if ( ! function_exists('curl_init')) { |
|
139 | + $this->add_admin_notice('curl', 'notice notice-warning', __('WooCommerce Stripe - cURL is not installed.', 'woocommerce-gateway-stripe'), true); |
|
140 | 140 | } |
141 | 141 | } |
142 | 142 | |
143 | - if ( empty( $show_keys_notice ) ) { |
|
143 | + if (empty($show_keys_notice)) { |
|
144 | 144 | $secret = WC_Stripe_API::get_secret_key(); |
145 | 145 | |
146 | - if ( empty( $secret ) && ! ( isset( $_GET['page'], $_GET['section'] ) && 'wc-settings' === $_GET['page'] && 'stripe' === $_GET['section'] ) ) { |
|
146 | + if (empty($secret) && ! (isset($_GET['page'], $_GET['section']) && 'wc-settings' === $_GET['page'] && 'stripe' === $_GET['section'])) { |
|
147 | 147 | $setting_link = $this->get_setting_link(); |
148 | 148 | /* translators: 1) link */ |
149 | - $this->add_admin_notice( 'keys', 'notice notice-warning', sprintf( __( 'Stripe is almost ready. To get started, <a href="%s">set your Stripe account keys</a>.', 'woocommerce-gateway-stripe' ), $setting_link ), true ); |
|
149 | + $this->add_admin_notice('keys', 'notice notice-warning', sprintf(__('Stripe is almost ready. To get started, <a href="%s">set your Stripe account keys</a>.', 'woocommerce-gateway-stripe'), $setting_link), true); |
|
150 | 150 | } |
151 | 151 | |
152 | 152 | // Check if keys are entered properly per live/test mode. |
153 | - if ( $testmode ) { |
|
153 | + if ($testmode) { |
|
154 | 154 | if ( |
155 | - ! empty( $test_pub_key ) && ! preg_match( '/^pk_test_/', $test_pub_key ) |
|
156 | - || ( ! empty( $test_secret_key ) && ! preg_match( '/^sk_test_/', $test_secret_key ) |
|
157 | - && ! empty( $test_secret_key ) && ! preg_match( '/^rk_test_/', $test_secret_key ) ) ) { |
|
155 | + ! empty($test_pub_key) && ! preg_match('/^pk_test_/', $test_pub_key) |
|
156 | + || ( ! empty($test_secret_key) && ! preg_match('/^sk_test_/', $test_secret_key) |
|
157 | + && ! empty($test_secret_key) && ! preg_match('/^rk_test_/', $test_secret_key)) ) { |
|
158 | 158 | $setting_link = $this->get_setting_link(); |
159 | 159 | /* translators: 1) link */ |
160 | - $this->add_admin_notice( 'keys', 'notice notice-error', sprintf( __( 'Stripe is in test mode however your test keys may not be valid. Test keys start with pk_test and sk_test or rk_test. Please go to your settings and, <a href="%s">set your Stripe account keys</a>.', 'woocommerce-gateway-stripe' ), $setting_link ), true ); |
|
160 | + $this->add_admin_notice('keys', 'notice notice-error', sprintf(__('Stripe is in test mode however your test keys may not be valid. Test keys start with pk_test and sk_test or rk_test. Please go to your settings and, <a href="%s">set your Stripe account keys</a>.', 'woocommerce-gateway-stripe'), $setting_link), true); |
|
161 | 161 | } |
162 | 162 | } else { |
163 | 163 | if ( |
164 | - ! empty( $live_pub_key ) && ! preg_match( '/^pk_live_/', $live_pub_key ) |
|
165 | - || ( ! empty( $live_secret_key ) && ! preg_match( '/^sk_live_/', $live_secret_key ) |
|
166 | - && ! empty( $live_secret_key ) && ! preg_match( '/^rk_live_/', $live_secret_key ) ) ) { |
|
164 | + ! empty($live_pub_key) && ! preg_match('/^pk_live_/', $live_pub_key) |
|
165 | + || ( ! empty($live_secret_key) && ! preg_match('/^sk_live_/', $live_secret_key) |
|
166 | + && ! empty($live_secret_key) && ! preg_match('/^rk_live_/', $live_secret_key)) ) { |
|
167 | 167 | $setting_link = $this->get_setting_link(); |
168 | 168 | /* translators: 1) link */ |
169 | - $this->add_admin_notice( 'keys', 'notice notice-error', sprintf( __( 'Stripe is in live mode however your test keys may not be valid. Live keys start with pk_live and sk_live or rk_live. Please go to your settings and, <a href="%s">set your Stripe account keys</a>.', 'woocommerce-gateway-stripe' ), $setting_link ), true ); |
|
169 | + $this->add_admin_notice('keys', 'notice notice-error', sprintf(__('Stripe is in live mode however your test keys may not be valid. Live keys start with pk_live and sk_live or rk_live. Please go to your settings and, <a href="%s">set your Stripe account keys</a>.', 'woocommerce-gateway-stripe'), $setting_link), true); |
|
170 | 170 | } |
171 | 171 | } |
172 | 172 | } |
173 | 173 | |
174 | - if ( empty( $show_ssl_notice ) ) { |
|
174 | + if (empty($show_ssl_notice)) { |
|
175 | 175 | // Show message if enabled and FORCE SSL is disabled and WordpressHTTPS plugin is not detected. |
176 | - if ( ! wc_checkout_is_https() ) { |
|
176 | + if ( ! wc_checkout_is_https()) { |
|
177 | 177 | /* translators: 1) link */ |
178 | - $this->add_admin_notice( 'ssl', 'notice notice-warning', sprintf( __( 'Stripe is enabled, but a SSL certificate is not detected. Your checkout may not be secure! Please ensure your server has a valid <a href="%1$s" target="_blank">SSL certificate</a>', 'woocommerce-gateway-stripe' ), 'https://en.wikipedia.org/wiki/Transport_Layer_Security' ), true ); |
|
178 | + $this->add_admin_notice('ssl', 'notice notice-warning', sprintf(__('Stripe is enabled, but a SSL certificate is not detected. Your checkout may not be secure! Please ensure your server has a valid <a href="%1$s" target="_blank">SSL certificate</a>', 'woocommerce-gateway-stripe'), 'https://en.wikipedia.org/wiki/Transport_Layer_Security'), true); |
|
179 | 179 | } |
180 | 180 | } |
181 | 181 | } |
@@ -189,17 +189,17 @@ discard block |
||
189 | 189 | public function payment_methods_check_environment() { |
190 | 190 | $payment_methods = $this->get_payment_methods(); |
191 | 191 | |
192 | - foreach ( $payment_methods as $method => $class ) { |
|
193 | - $show_notice = get_option( 'wc_stripe_show_' . strtolower( $method ) . '_notice' ); |
|
192 | + foreach ($payment_methods as $method => $class) { |
|
193 | + $show_notice = get_option('wc_stripe_show_' . strtolower($method) . '_notice'); |
|
194 | 194 | $gateway = new $class(); |
195 | 195 | |
196 | - if ( 'yes' !== $gateway->enabled || 'no' === $show_notice ) { |
|
196 | + if ('yes' !== $gateway->enabled || 'no' === $show_notice) { |
|
197 | 197 | continue; |
198 | 198 | } |
199 | 199 | |
200 | - if ( ! in_array( get_woocommerce_currency(), $gateway->get_supported_currency() ) ) { |
|
200 | + if ( ! in_array(get_woocommerce_currency(), $gateway->get_supported_currency())) { |
|
201 | 201 | /* translators: %1$s Payment method, %2$s List of supported currencies */ |
202 | - $this->add_admin_notice( $method, 'notice notice-error', sprintf( __( '%1$s is enabled - it requires store currency to be set to %2$s', 'woocommerce-gateway-stripe' ), $method, implode( ', ', $gateway->get_supported_currency() ) ), true ); |
|
202 | + $this->add_admin_notice($method, 'notice notice-error', sprintf(__('%1$s is enabled - it requires store currency to be set to %2$s', 'woocommerce-gateway-stripe'), $method, implode(', ', $gateway->get_supported_currency())), true); |
|
203 | 203 | } |
204 | 204 | } |
205 | 205 | } |
@@ -211,59 +211,59 @@ discard block |
||
211 | 211 | * @version 4.0.0 |
212 | 212 | */ |
213 | 213 | public function hide_notices() { |
214 | - if ( isset( $_GET['wc-stripe-hide-notice'] ) && isset( $_GET['_wc_stripe_notice_nonce'] ) ) { |
|
215 | - if ( ! wp_verify_nonce( $_GET['_wc_stripe_notice_nonce'], 'wc_stripe_hide_notices_nonce' ) ) { |
|
216 | - wp_die( __( 'Action failed. Please refresh the page and retry.', 'woocommerce-gateway-stripe' ) ); |
|
214 | + if (isset($_GET['wc-stripe-hide-notice']) && isset($_GET['_wc_stripe_notice_nonce'])) { |
|
215 | + if ( ! wp_verify_nonce($_GET['_wc_stripe_notice_nonce'], 'wc_stripe_hide_notices_nonce')) { |
|
216 | + wp_die(__('Action failed. Please refresh the page and retry.', 'woocommerce-gateway-stripe')); |
|
217 | 217 | } |
218 | 218 | |
219 | - if ( ! current_user_can( 'manage_woocommerce' ) ) { |
|
220 | - wp_die( __( 'Cheatin’ huh?', 'woocommerce-gateway-stripe' ) ); |
|
219 | + if ( ! current_user_can('manage_woocommerce')) { |
|
220 | + wp_die(__('Cheatin’ huh?', 'woocommerce-gateway-stripe')); |
|
221 | 221 | } |
222 | 222 | |
223 | - $notice = wc_clean( $_GET['wc-stripe-hide-notice'] ); |
|
223 | + $notice = wc_clean($_GET['wc-stripe-hide-notice']); |
|
224 | 224 | |
225 | - switch ( $notice ) { |
|
225 | + switch ($notice) { |
|
226 | 226 | case 'phpver': |
227 | - update_option( 'wc_stripe_show_phpver_notice', 'no' ); |
|
227 | + update_option('wc_stripe_show_phpver_notice', 'no'); |
|
228 | 228 | break; |
229 | 229 | case 'wcver': |
230 | - update_option( 'wc_stripe_show_wcver_notice', 'no' ); |
|
230 | + update_option('wc_stripe_show_wcver_notice', 'no'); |
|
231 | 231 | break; |
232 | 232 | case 'curl': |
233 | - update_option( 'wc_stripe_show_curl_notice', 'no' ); |
|
233 | + update_option('wc_stripe_show_curl_notice', 'no'); |
|
234 | 234 | break; |
235 | 235 | case 'ssl': |
236 | - update_option( 'wc_stripe_show_ssl_notice', 'no' ); |
|
236 | + update_option('wc_stripe_show_ssl_notice', 'no'); |
|
237 | 237 | break; |
238 | 238 | case 'keys': |
239 | - update_option( 'wc_stripe_show_keys_notice', 'no' ); |
|
239 | + update_option('wc_stripe_show_keys_notice', 'no'); |
|
240 | 240 | break; |
241 | 241 | case 'Alipay': |
242 | - update_option( 'wc_stripe_show_alipay_notice', 'no' ); |
|
242 | + update_option('wc_stripe_show_alipay_notice', 'no'); |
|
243 | 243 | break; |
244 | 244 | case 'Bancontact': |
245 | - update_option( 'wc_stripe_show_bancontact_notice', 'no' ); |
|
245 | + update_option('wc_stripe_show_bancontact_notice', 'no'); |
|
246 | 246 | break; |
247 | 247 | case 'EPS': |
248 | - update_option( 'wc_stripe_show_eps_notice', 'no' ); |
|
248 | + update_option('wc_stripe_show_eps_notice', 'no'); |
|
249 | 249 | break; |
250 | 250 | case 'Giropay': |
251 | - update_option( 'wc_stripe_show_giropay_notice', 'no' ); |
|
251 | + update_option('wc_stripe_show_giropay_notice', 'no'); |
|
252 | 252 | break; |
253 | 253 | case 'iDeal': |
254 | - update_option( 'wc_stripe_show_ideal_notice', 'no' ); |
|
254 | + update_option('wc_stripe_show_ideal_notice', 'no'); |
|
255 | 255 | break; |
256 | 256 | case 'Multibanco': |
257 | - update_option( 'wc_stripe_show_multibanco_notice', 'no' ); |
|
257 | + update_option('wc_stripe_show_multibanco_notice', 'no'); |
|
258 | 258 | break; |
259 | 259 | case 'P24': |
260 | - update_option( 'wc_stripe_show_p24_notice', 'no' ); |
|
260 | + update_option('wc_stripe_show_p24_notice', 'no'); |
|
261 | 261 | break; |
262 | 262 | case 'SEPA': |
263 | - update_option( 'wc_stripe_show_sepa_notice', 'no' ); |
|
263 | + update_option('wc_stripe_show_sepa_notice', 'no'); |
|
264 | 264 | break; |
265 | 265 | case 'SOFORT': |
266 | - update_option( 'wc_stripe_show_sofort_notice', 'no' ); |
|
266 | + update_option('wc_stripe_show_sofort_notice', 'no'); |
|
267 | 267 | break; |
268 | 268 | } |
269 | 269 | } |
@@ -277,11 +277,11 @@ discard block |
||
277 | 277 | * @return string Setting link |
278 | 278 | */ |
279 | 279 | public function get_setting_link() { |
280 | - $use_id_as_section = function_exists( 'WC' ) ? version_compare( WC()->version, '2.6', '>=' ) : false; |
|
280 | + $use_id_as_section = function_exists('WC') ? version_compare(WC()->version, '2.6', '>=') : false; |
|
281 | 281 | |
282 | - $section_slug = $use_id_as_section ? 'stripe' : strtolower( 'WC_Gateway_Stripe' ); |
|
282 | + $section_slug = $use_id_as_section ? 'stripe' : strtolower('WC_Gateway_Stripe'); |
|
283 | 283 | |
284 | - return admin_url( 'admin.php?page=wc-settings&tab=checkout§ion=' . $section_slug ); |
|
284 | + return admin_url('admin.php?page=wc-settings&tab=checkout§ion=' . $section_slug); |
|
285 | 285 | } |
286 | 286 | } |
287 | 287 |