@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if ( ! defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | 5 | |
@@ -65,9 +65,9 @@ discard block |
||
65 | 65 | public function __construct() { |
66 | 66 | $this->retry_interval = 1; |
67 | 67 | $this->id = 'stripe_sepa'; |
68 | - $this->method_title = __( 'Stripe SEPA Direct Debit', 'woocommerce-gateway-stripe' ); |
|
68 | + $this->method_title = __('Stripe SEPA Direct Debit', 'woocommerce-gateway-stripe'); |
|
69 | 69 | /* translators: link */ |
70 | - $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' ) ); |
|
70 | + $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')); |
|
71 | 71 | $this->supports = array( |
72 | 72 | 'products', |
73 | 73 | 'refunds', |
@@ -92,25 +92,25 @@ discard block |
||
92 | 92 | // Load the settings. |
93 | 93 | $this->init_settings(); |
94 | 94 | |
95 | - $main_settings = get_option( 'woocommerce_stripe_settings' ); |
|
96 | - $this->title = $this->get_option( 'title' ); |
|
97 | - $this->description = $this->get_option( 'description' ); |
|
98 | - $this->enabled = $this->get_option( 'enabled' ); |
|
99 | - $this->testmode = ( ! empty( $main_settings['testmode'] ) && 'yes' === $main_settings['testmode'] ) ? true : false; |
|
100 | - $this->saved_cards = ( ! empty( $main_settings['saved_cards'] ) && 'yes' === $main_settings['saved_cards'] ) ? true : false; |
|
101 | - $this->publishable_key = ! empty( $main_settings['publishable_key'] ) ? $main_settings['publishable_key'] : ''; |
|
102 | - $this->secret_key = ! empty( $main_settings['secret_key'] ) ? $main_settings['secret_key'] : ''; |
|
103 | - $this->statement_descriptor = ! empty( $main_settings['statement_descriptor'] ) ? $main_settings['statement_descriptor'] : ''; |
|
104 | - |
|
105 | - if ( $this->testmode ) { |
|
106 | - $this->publishable_key = ! empty( $main_settings['test_publishable_key'] ) ? $main_settings['test_publishable_key'] : ''; |
|
107 | - $this->secret_key = ! empty( $main_settings['test_secret_key'] ) ? $main_settings['test_secret_key'] : ''; |
|
95 | + $main_settings = get_option('woocommerce_stripe_settings'); |
|
96 | + $this->title = $this->get_option('title'); |
|
97 | + $this->description = $this->get_option('description'); |
|
98 | + $this->enabled = $this->get_option('enabled'); |
|
99 | + $this->testmode = ( ! empty($main_settings['testmode']) && 'yes' === $main_settings['testmode']) ? true : false; |
|
100 | + $this->saved_cards = ( ! empty($main_settings['saved_cards']) && 'yes' === $main_settings['saved_cards']) ? true : false; |
|
101 | + $this->publishable_key = ! empty($main_settings['publishable_key']) ? $main_settings['publishable_key'] : ''; |
|
102 | + $this->secret_key = ! empty($main_settings['secret_key']) ? $main_settings['secret_key'] : ''; |
|
103 | + $this->statement_descriptor = ! empty($main_settings['statement_descriptor']) ? $main_settings['statement_descriptor'] : ''; |
|
104 | + |
|
105 | + if ($this->testmode) { |
|
106 | + $this->publishable_key = ! empty($main_settings['test_publishable_key']) ? $main_settings['test_publishable_key'] : ''; |
|
107 | + $this->secret_key = ! empty($main_settings['test_secret_key']) ? $main_settings['test_secret_key'] : ''; |
|
108 | 108 | } |
109 | 109 | |
110 | - add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) ); |
|
111 | - add_action( 'admin_notices', array( $this, 'check_environment' ) ); |
|
112 | - add_action( 'admin_head', array( $this, 'remove_admin_notice' ) ); |
|
113 | - add_action( 'wp_enqueue_scripts', array( $this, 'payment_scripts' ) ); |
|
110 | + add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options')); |
|
111 | + add_action('admin_notices', array($this, 'check_environment')); |
|
112 | + add_action('admin_head', array($this, 'remove_admin_notice')); |
|
113 | + add_action('wp_enqueue_scripts', array($this, 'payment_scripts')); |
|
114 | 114 | } |
115 | 115 | |
116 | 116 | /** |
@@ -120,19 +120,19 @@ discard block |
||
120 | 120 | * @version 4.0.0 |
121 | 121 | */ |
122 | 122 | public function check_environment() { |
123 | - if ( ! current_user_can( 'manage_woocommerce' ) ) { |
|
123 | + if ( ! current_user_can('manage_woocommerce')) { |
|
124 | 124 | return; |
125 | 125 | } |
126 | 126 | |
127 | 127 | $environment_warning = $this->get_environment_warning(); |
128 | 128 | |
129 | - if ( $environment_warning ) { |
|
130 | - $this->add_admin_notice( 'bad_environment', 'error', $environment_warning ); |
|
129 | + if ($environment_warning) { |
|
130 | + $this->add_admin_notice('bad_environment', 'error', $environment_warning); |
|
131 | 131 | } |
132 | 132 | |
133 | - foreach ( (array) $this->notices as $notice_key => $notice ) { |
|
134 | - echo "<div class='" . esc_attr( $notice['class'] ) . "'><p>"; |
|
135 | - echo wp_kses( $notice['message'], array( 'a' => array( 'href' => array() ) ) ); |
|
133 | + foreach ((array) $this->notices as $notice_key => $notice) { |
|
134 | + echo "<div class='" . esc_attr($notice['class']) . "'><p>"; |
|
135 | + echo wp_kses($notice['message'], array('a' => array('href' => array()))); |
|
136 | 136 | echo '</p></div>'; |
137 | 137 | } |
138 | 138 | } |
@@ -145,8 +145,8 @@ discard block |
||
145 | 145 | * @version 4.0.0 |
146 | 146 | */ |
147 | 147 | public function get_environment_warning() { |
148 | - if ( 'yes' === $this->enabled && ! in_array( get_woocommerce_currency(), $this->get_supported_currency() ) ) { |
|
149 | - $message = __( 'SEPA is enabled - it requires store currency to be set to Euros.', 'woocommerce-gateway-stripe' ); |
|
148 | + if ('yes' === $this->enabled && ! in_array(get_woocommerce_currency(), $this->get_supported_currency())) { |
|
149 | + $message = __('SEPA is enabled - it requires store currency to be set to Euros.', 'woocommerce-gateway-stripe'); |
|
150 | 150 | |
151 | 151 | return $message; |
152 | 152 | } |
@@ -162,9 +162,9 @@ discard block |
||
162 | 162 | * @return array |
163 | 163 | */ |
164 | 164 | public function get_supported_currency() { |
165 | - return apply_filters( 'wc_stripe_sepa_supported_currencies', array( |
|
165 | + return apply_filters('wc_stripe_sepa_supported_currencies', array( |
|
166 | 166 | 'EUR', |
167 | - ) ); |
|
167 | + )); |
|
168 | 168 | } |
169 | 169 | |
170 | 170 | /** |
@@ -175,11 +175,11 @@ discard block |
||
175 | 175 | * @return bool |
176 | 176 | */ |
177 | 177 | public function is_available() { |
178 | - if ( ! in_array( get_woocommerce_currency(), $this->get_supported_currency() ) ) { |
|
178 | + if ( ! in_array(get_woocommerce_currency(), $this->get_supported_currency())) { |
|
179 | 179 | return false; |
180 | 180 | } |
181 | 181 | |
182 | - if ( is_add_payment_method_page() && ! $this->saved_cards ) { |
|
182 | + if (is_add_payment_method_page() && ! $this->saved_cards) { |
|
183 | 183 | return false; |
184 | 184 | } |
185 | 185 | |
@@ -200,7 +200,7 @@ discard block |
||
200 | 200 | |
201 | 201 | $icons_str .= $icons['sepa']; |
202 | 202 | |
203 | - return apply_filters( 'woocommerce_gateway_icon', $icons_str, $this->id ); |
|
203 | + return apply_filters('woocommerce_gateway_icon', $icons_str, $this->id); |
|
204 | 204 | } |
205 | 205 | |
206 | 206 | /** |
@@ -211,19 +211,19 @@ discard block |
||
211 | 211 | * @access public |
212 | 212 | */ |
213 | 213 | public function payment_scripts() { |
214 | - if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) && ! is_add_payment_method_page() ) { |
|
214 | + if ( ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order']) && ! is_add_payment_method_page()) { |
|
215 | 215 | return; |
216 | 216 | } |
217 | 217 | |
218 | - wp_enqueue_style( 'stripe_paymentfonts' ); |
|
219 | - wp_enqueue_script( 'woocommerce_stripe' ); |
|
218 | + wp_enqueue_style('stripe_paymentfonts'); |
|
219 | + wp_enqueue_script('woocommerce_stripe'); |
|
220 | 220 | } |
221 | 221 | |
222 | 222 | /** |
223 | 223 | * Initialize Gateway Settings Form Fields. |
224 | 224 | */ |
225 | 225 | public function init_form_fields() { |
226 | - $this->form_fields = require( WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-sepa-settings.php' ); |
|
226 | + $this->form_fields = require(WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-sepa-settings.php'); |
|
227 | 227 | } |
228 | 228 | |
229 | 229 | /** |
@@ -235,7 +235,7 @@ discard block |
||
235 | 235 | */ |
236 | 236 | public function mandate_display() { |
237 | 237 | /* translators: statement descriptor */ |
238 | - 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 ) ); |
|
238 | + 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)); |
|
239 | 239 | } |
240 | 240 | |
241 | 241 | /** |
@@ -246,24 +246,24 @@ discard block |
||
246 | 246 | */ |
247 | 247 | public function form() { |
248 | 248 | ?> |
249 | - <fieldset id="wc-<?php echo esc_attr( $this->id ); ?>-form" class="wc-payment-form"> |
|
250 | - <?php do_action( 'woocommerce_credit_card_form_start', $this->id ); ?> |
|
249 | + <fieldset id="wc-<?php echo esc_attr($this->id); ?>-form" class="wc-payment-form"> |
|
250 | + <?php do_action('woocommerce_credit_card_form_start', $this->id); ?> |
|
251 | 251 | <p class="wc-stripe-sepa-mandate" style="margin-bottom:40px;"><?php $this->mandate_display(); ?></p> |
252 | 252 | <p class="form-row form-row-wide"> |
253 | 253 | <label for="stripe-sepa-owner"> |
254 | - <?php esc_html_e( 'IBAN Account Name.', 'woocommerce-gateway-stripe' ); ?> <span class="required">*</span> |
|
254 | + <?php esc_html_e('IBAN Account Name.', 'woocommerce-gateway-stripe'); ?> <span class="required">*</span> |
|
255 | 255 | </label> |
256 | 256 | <input id="stripe-sepa-owner" name="stripe_sepa_owner" value="" style="border:1px solid #ddd;margin:5px 0;padding:10px 5px;background-color:#fff;outline:0;" /> |
257 | 257 | </p> |
258 | 258 | <p class="form-row form-row-wide"> |
259 | 259 | <label for="stripe-sepa-iban"> |
260 | - <?php esc_html_e( 'IBAN Account Number.', 'woocommerce-gateway-stripe' ); ?> <span class="required">*</span> |
|
260 | + <?php esc_html_e('IBAN Account Number.', 'woocommerce-gateway-stripe'); ?> <span class="required">*</span> |
|
261 | 261 | </label> |
262 | 262 | <input id="stripe-sepa-iban" name="stripe_sepa_iban" value="" style="border:1px solid #ddd;margin:5px 0;padding:10px 5px;background-color:#fff;outline:0;" /> |
263 | 263 | </p> |
264 | 264 | <!-- Used to display form errors --> |
265 | 265 | <div class="stripe-source-errors" role="alert"></div> |
266 | - <?php do_action( 'woocommerce_credit_card_form_end', $this->id ); ?> |
|
266 | + <?php do_action('woocommerce_credit_card_form_end', $this->id); ?> |
|
267 | 267 | <div class="clear"></div> |
268 | 268 | </fieldset> |
269 | 269 | <?php |
@@ -275,42 +275,42 @@ discard block |
||
275 | 275 | public function payment_fields() { |
276 | 276 | $user = wp_get_current_user(); |
277 | 277 | $total = WC()->cart->total; |
278 | - $display_tokenization = $this->supports( 'tokenization' ) && is_checkout() && $this->saved_cards; |
|
278 | + $display_tokenization = $this->supports('tokenization') && is_checkout() && $this->saved_cards; |
|
279 | 279 | |
280 | 280 | // If paying from order, we need to get total from order not cart. |
281 | - if ( isset( $_GET['pay_for_order'] ) && ! empty( $_GET['key'] ) ) { |
|
282 | - $order = wc_get_order( wc_get_order_id_by_order_key( wc_clean( $_GET['key'] ) ) ); |
|
281 | + if (isset($_GET['pay_for_order']) && ! empty($_GET['key'])) { |
|
282 | + $order = wc_get_order(wc_get_order_id_by_order_key(wc_clean($_GET['key']))); |
|
283 | 283 | $total = $order->get_total(); |
284 | 284 | } |
285 | 285 | |
286 | - if ( is_add_payment_method_page() ) { |
|
287 | - $pay_button_text = __( 'Add Payment', 'woocommerce-gateway-stripe' ); |
|
288 | - $total = ''; |
|
286 | + if (is_add_payment_method_page()) { |
|
287 | + $pay_button_text = __('Add Payment', 'woocommerce-gateway-stripe'); |
|
288 | + $total = ''; |
|
289 | 289 | } else { |
290 | 290 | $pay_button_text = ''; |
291 | 291 | } |
292 | 292 | |
293 | 293 | echo '<div |
294 | 294 | id="stripe-sepa_debit-payment-data" |
295 | - data-amount="' . esc_attr( WC_Stripe_Helper::get_stripe_amount( $total ) ) . '" |
|
296 | - data-currency="' . esc_attr( strtolower( get_woocommerce_currency() ) ) . '">'; |
|
295 | + data-amount="' . esc_attr(WC_Stripe_Helper::get_stripe_amount($total)) . '" |
|
296 | + data-currency="' . esc_attr(strtolower(get_woocommerce_currency())) . '">'; |
|
297 | 297 | |
298 | - if ( $this->description ) { |
|
299 | - if ( $this->testmode ) { |
|
300 | - $this->description .= ' ' . __( 'TEST MODE ENABLED. In test mode, you can use IBAN number DE89370400440532013000.', 'woocommerce-gateway-stripe' ); |
|
301 | - $this->description = trim( $this->description ); |
|
298 | + if ($this->description) { |
|
299 | + if ($this->testmode) { |
|
300 | + $this->description .= ' ' . __('TEST MODE ENABLED. In test mode, you can use IBAN number DE89370400440532013000.', 'woocommerce-gateway-stripe'); |
|
301 | + $this->description = trim($this->description); |
|
302 | 302 | } |
303 | - echo apply_filters( 'wc_stripe_description', wpautop( wp_kses_post( $this->description ) ) ); |
|
303 | + echo apply_filters('wc_stripe_description', wpautop(wp_kses_post($this->description))); |
|
304 | 304 | } |
305 | 305 | |
306 | - if ( $display_tokenization ) { |
|
306 | + if ($display_tokenization) { |
|
307 | 307 | $this->tokenization_script(); |
308 | 308 | $this->saved_payment_methods(); |
309 | 309 | } |
310 | 310 | |
311 | 311 | $this->form(); |
312 | 312 | |
313 | - if ( apply_filters( 'wc_stripe_display_save_payment_method_checkbox', $display_tokenization ) && ! is_add_payment_method_page() && ! isset( $_GET['change_payment_method'] ) ) { |
|
313 | + if (apply_filters('wc_stripe_display_save_payment_method_checkbox', $display_tokenization) && ! is_add_payment_method_page() && ! isset($_GET['change_payment_method'])) { |
|
314 | 314 | $this->save_payment_method_checkbox(); |
315 | 315 | } |
316 | 316 | |
@@ -328,95 +328,95 @@ discard block |
||
328 | 328 | * |
329 | 329 | * @return array|void |
330 | 330 | */ |
331 | - public function process_payment( $order_id, $retry = true, $force_save_source = false ) { |
|
331 | + public function process_payment($order_id, $retry = true, $force_save_source = false) { |
|
332 | 332 | try { |
333 | - $order = wc_get_order( $order_id ); |
|
333 | + $order = wc_get_order($order_id); |
|
334 | 334 | |
335 | 335 | // This comes from the create account checkbox in the checkout page. |
336 | - $create_account = ! empty( $_POST['createaccount'] ) ? true : false; |
|
336 | + $create_account = ! empty($_POST['createaccount']) ? true : false; |
|
337 | 337 | |
338 | - if ( $create_account ) { |
|
338 | + if ($create_account) { |
|
339 | 339 | $new_customer_id = WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id(); |
340 | - $new_stripe_customer = new WC_Stripe_Customer( $new_customer_id ); |
|
340 | + $new_stripe_customer = new WC_Stripe_Customer($new_customer_id); |
|
341 | 341 | $new_stripe_customer->create_customer(); |
342 | 342 | } |
343 | 343 | |
344 | - $prepared_source = $this->prepare_source( get_current_user_id(), $force_save_source ); |
|
344 | + $prepared_source = $this->prepare_source(get_current_user_id(), $force_save_source); |
|
345 | 345 | |
346 | - $this->save_source_to_order( $order, $prepared_source ); |
|
346 | + $this->save_source_to_order($order, $prepared_source); |
|
347 | 347 | |
348 | 348 | // Result from Stripe API request. |
349 | 349 | $response = null; |
350 | 350 | |
351 | - if ( $order->get_total() > 0 ) { |
|
351 | + if ($order->get_total() > 0) { |
|
352 | 352 | // This will throw exception if not valid. |
353 | - $this->validate_minimum_order_amount( $order ); |
|
353 | + $this->validate_minimum_order_amount($order); |
|
354 | 354 | |
355 | - WC_Stripe_Logger::log( "Info: Begin processing payment for order $order_id for the amount of {$order->get_total()}" ); |
|
355 | + WC_Stripe_Logger::log("Info: Begin processing payment for order $order_id for the amount of {$order->get_total()}"); |
|
356 | 356 | |
357 | 357 | // Make the request. |
358 | - $response = WC_Stripe_API::request( $this->generate_payment_request( $order, $prepared_source ) ); |
|
358 | + $response = WC_Stripe_API::request($this->generate_payment_request($order, $prepared_source)); |
|
359 | 359 | |
360 | - if ( ! empty( $response->error ) ) { |
|
360 | + if ( ! empty($response->error)) { |
|
361 | 361 | // Customer param wrong? The user may have been deleted on stripe's end. Remove customer_id. Can be retried without. |
362 | - if ( preg_match( '/No such customer/i', $response->error->message ) && $retry ) { |
|
363 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
364 | - delete_user_meta( $order->customer_user, '_stripe_customer_id' ); |
|
365 | - delete_post_meta( $order_id, '_stripe_customer_id' ); |
|
362 | + if (preg_match('/No such customer/i', $response->error->message) && $retry) { |
|
363 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
364 | + delete_user_meta($order->customer_user, '_stripe_customer_id'); |
|
365 | + delete_post_meta($order_id, '_stripe_customer_id'); |
|
366 | 366 | } else { |
367 | - delete_user_meta( $order->get_customer_id(), '_stripe_customer_id' ); |
|
368 | - $order->delete_meta_data( '_stripe_customer_id' ); |
|
367 | + delete_user_meta($order->get_customer_id(), '_stripe_customer_id'); |
|
368 | + $order->delete_meta_data('_stripe_customer_id'); |
|
369 | 369 | $order->save(); |
370 | 370 | } |
371 | 371 | |
372 | - return $this->process_payment( $order_id, false, $force_save_source ); |
|
373 | - } elseif ( preg_match( '/No such token/i', $response->error->message ) && $prepared_source->token_id ) { |
|
372 | + return $this->process_payment($order_id, false, $force_save_source); |
|
373 | + } elseif (preg_match('/No such token/i', $response->error->message) && $prepared_source->token_id) { |
|
374 | 374 | // Source param wrong? The CARD may have been deleted on stripe's end. Remove token and show message. |
375 | - $wc_token = WC_Payment_Tokens::get( $prepared_source->token_id ); |
|
375 | + $wc_token = WC_Payment_Tokens::get($prepared_source->token_id); |
|
376 | 376 | $wc_token->delete(); |
377 | - $localized_message = __( 'This card is no longer available and has been removed.', 'woocommerce-gateway-stripe' ); |
|
378 | - $order->add_order_note( $localized_message ); |
|
379 | - throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message ); |
|
377 | + $localized_message = __('This card is no longer available and has been removed.', 'woocommerce-gateway-stripe'); |
|
378 | + $order->add_order_note($localized_message); |
|
379 | + throw new WC_Stripe_Exception(print_r($response, true), $localized_message); |
|
380 | 380 | } |
381 | 381 | |
382 | 382 | // We want to retry. |
383 | - if ( $this->is_retryable_error( $response->error ) ) { |
|
384 | - if ( $retry ) { |
|
383 | + if ($this->is_retryable_error($response->error)) { |
|
384 | + if ($retry) { |
|
385 | 385 | // Don't do anymore retries after this. |
386 | - if ( 5 <= $this->retry_interval ) { |
|
386 | + if (5 <= $this->retry_interval) { |
|
387 | 387 | |
388 | - return $this->process_payment( $order_id, false, $force_save_source ); |
|
388 | + return $this->process_payment($order_id, false, $force_save_source); |
|
389 | 389 | } |
390 | 390 | |
391 | - sleep( $this->retry_interval ); |
|
391 | + sleep($this->retry_interval); |
|
392 | 392 | |
393 | 393 | $this->retry_interval++; |
394 | 394 | |
395 | - return $this->process_payment( $order_id, true, $force_save_source ); |
|
395 | + return $this->process_payment($order_id, true, $force_save_source); |
|
396 | 396 | } else { |
397 | - $localized_message = __( 'On going requests error and retries exhausted.', 'woocommerce-gateway-stripe' ); |
|
398 | - $order->add_order_note( $localized_message ); |
|
399 | - throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message ); |
|
397 | + $localized_message = __('On going requests error and retries exhausted.', 'woocommerce-gateway-stripe'); |
|
398 | + $order->add_order_note($localized_message); |
|
399 | + throw new WC_Stripe_Exception(print_r($response, true), $localized_message); |
|
400 | 400 | } |
401 | 401 | } |
402 | 402 | |
403 | 403 | $localized_messages = WC_Stripe_Helper::get_localized_messages(); |
404 | 404 | |
405 | - if ( 'card_error' === $response->error->type ) { |
|
406 | - $localized_message = isset( $localized_messages[ $response->error->code ] ) ? $localized_messages[ $response->error->code ] : $response->error->message; |
|
405 | + if ('card_error' === $response->error->type) { |
|
406 | + $localized_message = isset($localized_messages[$response->error->code]) ? $localized_messages[$response->error->code] : $response->error->message; |
|
407 | 407 | } else { |
408 | - $localized_message = isset( $localized_messages[ $response->error->type ] ) ? $localized_messages[ $response->error->type ] : $response->error->message; |
|
408 | + $localized_message = isset($localized_messages[$response->error->type]) ? $localized_messages[$response->error->type] : $response->error->message; |
|
409 | 409 | } |
410 | 410 | |
411 | - $order->add_order_note( $localized_message ); |
|
411 | + $order->add_order_note($localized_message); |
|
412 | 412 | |
413 | - throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message ); |
|
413 | + throw new WC_Stripe_Exception(print_r($response, true), $localized_message); |
|
414 | 414 | } |
415 | 415 | |
416 | - do_action( 'wc_gateway_stripe_process_payment', $response, $order ); |
|
416 | + do_action('wc_gateway_stripe_process_payment', $response, $order); |
|
417 | 417 | |
418 | 418 | // Process valid response. |
419 | - $this->process_response( $response, $order ); |
|
419 | + $this->process_response($response, $order); |
|
420 | 420 | } else { |
421 | 421 | $order->payment_complete(); |
422 | 422 | } |
@@ -427,17 +427,17 @@ discard block |
||
427 | 427 | // Return thank you page redirect. |
428 | 428 | return array( |
429 | 429 | 'result' => 'success', |
430 | - 'redirect' => $this->get_return_url( $order ), |
|
430 | + 'redirect' => $this->get_return_url($order), |
|
431 | 431 | ); |
432 | 432 | |
433 | - } catch ( WC_Stripe_Exception $e ) { |
|
434 | - wc_add_notice( $e->getLocalizedMessage(), 'error' ); |
|
435 | - WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() ); |
|
433 | + } catch (WC_Stripe_Exception $e) { |
|
434 | + wc_add_notice($e->getLocalizedMessage(), 'error'); |
|
435 | + WC_Stripe_Logger::log('Error: ' . $e->getMessage()); |
|
436 | 436 | |
437 | - do_action( 'wc_gateway_stripe_process_payment_error', $e, $order ); |
|
437 | + do_action('wc_gateway_stripe_process_payment_error', $e, $order); |
|
438 | 438 | |
439 | - if ( $order->has_status( array( 'pending', 'failed' ) ) ) { |
|
440 | - $this->send_failed_order_email( $order_id ); |
|
439 | + if ($order->has_status(array('pending', 'failed'))) { |
|
440 | + $this->send_failed_order_email($order_id); |
|
441 | 441 | } |
442 | 442 | |
443 | 443 | 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 | |
@@ -106,9 +106,9 @@ discard block |
||
106 | 106 | public function __construct() { |
107 | 107 | $this->retry_interval = 1; |
108 | 108 | $this->id = 'stripe'; |
109 | - $this->method_title = __( 'Stripe', 'woocommerce-gateway-stripe' ); |
|
109 | + $this->method_title = __('Stripe', 'woocommerce-gateway-stripe'); |
|
110 | 110 | /* translators: 1) link to Stripe register page 2) link to Stripe api keys page */ |
111 | - $this->method_description = sprintf( __( 'Stripe works by adding payment fields on the checkout and then sending the details to Stripe for verification. <a href="%1$s" target="_blank">Sign up</a> for a Stripe account, and <a href="%2$s" target="_blank">get your Stripe account keys</a>.', 'woocommerce-gateway-stripe' ), 'https://dashboard.stripe.com/register', 'https://dashboard.stripe.com/account/apikeys' ); |
|
111 | + $this->method_description = sprintf(__('Stripe works by adding payment fields on the checkout and then sending the details to Stripe for verification. <a href="%1$s" target="_blank">Sign up</a> for a Stripe account, and <a href="%2$s" target="_blank">get your Stripe account keys</a>.', 'woocommerce-gateway-stripe'), 'https://dashboard.stripe.com/register', 'https://dashboard.stripe.com/account/apikeys'); |
|
112 | 112 | $this->has_fields = true; |
113 | 113 | $this->supports = array( |
114 | 114 | 'products', |
@@ -135,32 +135,32 @@ discard block |
||
135 | 135 | $this->init_settings(); |
136 | 136 | |
137 | 137 | // Get setting values. |
138 | - $this->title = $this->get_option( 'title' ); |
|
139 | - $this->description = $this->get_option( 'description' ); |
|
140 | - $this->enabled = $this->get_option( 'enabled' ); |
|
141 | - $this->testmode = 'yes' === $this->get_option( 'testmode' ); |
|
142 | - $this->inline_cc_form = 'yes' === $this->get_option( 'inline_cc_form' ); |
|
143 | - $this->capture = 'yes' === $this->get_option( 'capture', 'yes' ); |
|
144 | - $this->statement_descriptor = WC_Stripe_Helper::clean_statement_descriptor( $this->get_option( 'statement_descriptor' ) ); |
|
145 | - $this->three_d_secure = 'yes' === $this->get_option( 'three_d_secure' ); |
|
146 | - $this->stripe_checkout = 'yes' === $this->get_option( 'stripe_checkout' ); |
|
147 | - $this->stripe_checkout_image = $this->get_option( 'stripe_checkout_image', '' ); |
|
148 | - $this->saved_cards = 'yes' === $this->get_option( 'saved_cards' ); |
|
149 | - $this->secret_key = $this->testmode ? $this->get_option( 'test_secret_key' ) : $this->get_option( 'secret_key' ); |
|
150 | - $this->publishable_key = $this->testmode ? $this->get_option( 'test_publishable_key' ) : $this->get_option( 'publishable_key' ); |
|
151 | - $this->bitcoin = 'USD' === strtoupper( get_woocommerce_currency() ) && 'yes' === $this->get_option( 'stripe_bitcoin' ); |
|
152 | - $this->payment_request = 'yes' === $this->get_option( 'payment_request', 'yes' ); |
|
153 | - |
|
154 | - if ( $this->stripe_checkout ) { |
|
155 | - $this->order_button_text = __( 'Continue to payment', 'woocommerce-gateway-stripe' ); |
|
138 | + $this->title = $this->get_option('title'); |
|
139 | + $this->description = $this->get_option('description'); |
|
140 | + $this->enabled = $this->get_option('enabled'); |
|
141 | + $this->testmode = 'yes' === $this->get_option('testmode'); |
|
142 | + $this->inline_cc_form = 'yes' === $this->get_option('inline_cc_form'); |
|
143 | + $this->capture = 'yes' === $this->get_option('capture', 'yes'); |
|
144 | + $this->statement_descriptor = WC_Stripe_Helper::clean_statement_descriptor($this->get_option('statement_descriptor')); |
|
145 | + $this->three_d_secure = 'yes' === $this->get_option('three_d_secure'); |
|
146 | + $this->stripe_checkout = 'yes' === $this->get_option('stripe_checkout'); |
|
147 | + $this->stripe_checkout_image = $this->get_option('stripe_checkout_image', ''); |
|
148 | + $this->saved_cards = 'yes' === $this->get_option('saved_cards'); |
|
149 | + $this->secret_key = $this->testmode ? $this->get_option('test_secret_key') : $this->get_option('secret_key'); |
|
150 | + $this->publishable_key = $this->testmode ? $this->get_option('test_publishable_key') : $this->get_option('publishable_key'); |
|
151 | + $this->bitcoin = 'USD' === strtoupper(get_woocommerce_currency()) && 'yes' === $this->get_option('stripe_bitcoin'); |
|
152 | + $this->payment_request = 'yes' === $this->get_option('payment_request', 'yes'); |
|
153 | + |
|
154 | + if ($this->stripe_checkout) { |
|
155 | + $this->order_button_text = __('Continue to payment', 'woocommerce-gateway-stripe'); |
|
156 | 156 | } |
157 | 157 | |
158 | - WC_Stripe_API::set_secret_key( $this->secret_key ); |
|
158 | + WC_Stripe_API::set_secret_key($this->secret_key); |
|
159 | 159 | |
160 | 160 | // Hooks. |
161 | - add_action( 'wp_enqueue_scripts', array( $this, 'payment_scripts' ) ); |
|
162 | - add_action( 'admin_enqueue_scripts', array( $this, 'admin_scripts' ) ); |
|
163 | - add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) ); |
|
161 | + add_action('wp_enqueue_scripts', array($this, 'payment_scripts')); |
|
162 | + add_action('admin_enqueue_scripts', array($this, 'admin_scripts')); |
|
163 | + add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options')); |
|
164 | 164 | } |
165 | 165 | |
166 | 166 | /** |
@@ -170,7 +170,7 @@ discard block |
||
170 | 170 | * @return bool |
171 | 171 | */ |
172 | 172 | public function are_keys_set() { |
173 | - if ( empty( $this->secret_key ) || empty( $this->publishable_key ) ) { |
|
173 | + if (empty($this->secret_key) || empty($this->publishable_key)) { |
|
174 | 174 | return false; |
175 | 175 | } |
176 | 176 | |
@@ -183,7 +183,7 @@ discard block |
||
183 | 183 | * @since 4.0.2 |
184 | 184 | */ |
185 | 185 | public function is_available() { |
186 | - if ( is_add_payment_method_page() && ! $this->saved_cards ) { |
|
186 | + if (is_add_payment_method_page() && ! $this->saved_cards) { |
|
187 | 187 | return false; |
188 | 188 | } |
189 | 189 | |
@@ -206,24 +206,24 @@ discard block |
||
206 | 206 | $icons_str .= $icons['amex']; |
207 | 207 | $icons_str .= $icons['mastercard']; |
208 | 208 | |
209 | - if ( 'USD' === get_woocommerce_currency() ) { |
|
209 | + if ('USD' === get_woocommerce_currency()) { |
|
210 | 210 | $icons_str .= $icons['discover']; |
211 | 211 | $icons_str .= $icons['jcb']; |
212 | 212 | $icons_str .= $icons['diners']; |
213 | 213 | } |
214 | 214 | |
215 | - if ( $this->bitcoin && $this->stripe_checkout ) { |
|
215 | + if ($this->bitcoin && $this->stripe_checkout) { |
|
216 | 216 | $icons_str .= $icons['bitcoin']; |
217 | 217 | } |
218 | 218 | |
219 | - return apply_filters( 'woocommerce_gateway_icon', $icons_str, $this->id ); |
|
219 | + return apply_filters('woocommerce_gateway_icon', $icons_str, $this->id); |
|
220 | 220 | } |
221 | 221 | |
222 | 222 | /** |
223 | 223 | * Initialise Gateway Settings Form Fields |
224 | 224 | */ |
225 | 225 | public function init_form_fields() { |
226 | - $this->form_fields = require( dirname( __FILE__ ) . '/admin/stripe-settings.php' ); |
|
226 | + $this->form_fields = require(dirname(__FILE__) . '/admin/stripe-settings.php'); |
|
227 | 227 | } |
228 | 228 | |
229 | 229 | /** |
@@ -231,68 +231,68 @@ discard block |
||
231 | 231 | */ |
232 | 232 | public function payment_fields() { |
233 | 233 | $user = wp_get_current_user(); |
234 | - $display_tokenization = $this->supports( 'tokenization' ) && is_checkout() && $this->saved_cards; |
|
234 | + $display_tokenization = $this->supports('tokenization') && is_checkout() && $this->saved_cards; |
|
235 | 235 | $total = WC()->cart->total; |
236 | 236 | $user_email = ''; |
237 | 237 | |
238 | 238 | // If paying from order, we need to get total from order not cart. |
239 | - if ( isset( $_GET['pay_for_order'] ) && ! empty( $_GET['key'] ) ) { |
|
240 | - $order = wc_get_order( wc_get_order_id_by_order_key( wc_clean( $_GET['key'] ) ) ); |
|
239 | + if (isset($_GET['pay_for_order']) && ! empty($_GET['key'])) { |
|
240 | + $order = wc_get_order(wc_get_order_id_by_order_key(wc_clean($_GET['key']))); |
|
241 | 241 | $total = $order->get_total(); |
242 | 242 | $user_email = WC_Stripe_Helper::is_pre_30() ? $order->billing_email : $order->get_billing_email(); |
243 | 243 | } else { |
244 | - if ( $user->ID ) { |
|
245 | - $user_email = get_user_meta( $user->ID, 'billing_email', true ); |
|
244 | + if ($user->ID) { |
|
245 | + $user_email = get_user_meta($user->ID, 'billing_email', true); |
|
246 | 246 | $user_email = $user_email ? $user_email : $user->user_email; |
247 | 247 | } |
248 | 248 | } |
249 | 249 | |
250 | - if ( is_add_payment_method_page() ) { |
|
251 | - $pay_button_text = __( 'Add Card', 'woocommerce-gateway-stripe' ); |
|
252 | - $total = ''; |
|
250 | + if (is_add_payment_method_page()) { |
|
251 | + $pay_button_text = __('Add Card', 'woocommerce-gateway-stripe'); |
|
252 | + $total = ''; |
|
253 | 253 | } else { |
254 | 254 | $pay_button_text = ''; |
255 | 255 | } |
256 | 256 | |
257 | 257 | echo '<div |
258 | 258 | id="stripe-payment-data" |
259 | - data-panel-label="' . esc_attr( $pay_button_text ) . '" |
|
259 | + data-panel-label="' . esc_attr($pay_button_text) . '" |
|
260 | 260 | data-description="" |
261 | - data-email="' . esc_attr( $user_email ) . '" |
|
262 | - data-amount="' . esc_attr( WC_Stripe_Helper::get_stripe_amount( $total ) ) . '" |
|
263 | - data-name="' . esc_attr( $this->statement_descriptor ) . '" |
|
264 | - data-currency="' . esc_attr( strtolower( get_woocommerce_currency() ) ) . '" |
|
265 | - data-image="' . esc_attr( $this->stripe_checkout_image ) . '" |
|
266 | - data-bitcoin="' . esc_attr( ( $this->bitcoin && $this->capture ) ? 'true' : 'false' ) . '" |
|
267 | - data-locale="' . esc_attr( apply_filters( 'wc_stripe_checkout_locale', $this->get_locale() ) ) . '" |
|
268 | - data-three-d-secure="' . esc_attr( $this->three_d_secure ? 'true' : 'false' ) . '" |
|
269 | - data-allow-remember-me="' . esc_attr( $this->saved_cards ? 'true' : 'false' ) . '">'; |
|
270 | - |
|
271 | - if ( $this->description ) { |
|
272 | - if ( $this->testmode ) { |
|
261 | + data-email="' . esc_attr($user_email) . '" |
|
262 | + data-amount="' . esc_attr(WC_Stripe_Helper::get_stripe_amount($total)) . '" |
|
263 | + data-name="' . esc_attr($this->statement_descriptor) . '" |
|
264 | + data-currency="' . esc_attr(strtolower(get_woocommerce_currency())) . '" |
|
265 | + data-image="' . esc_attr($this->stripe_checkout_image) . '" |
|
266 | + data-bitcoin="' . esc_attr(($this->bitcoin && $this->capture) ? 'true' : 'false') . '" |
|
267 | + data-locale="' . esc_attr(apply_filters('wc_stripe_checkout_locale', $this->get_locale())) . '" |
|
268 | + data-three-d-secure="' . esc_attr($this->three_d_secure ? 'true' : 'false') . '" |
|
269 | + data-allow-remember-me="' . esc_attr($this->saved_cards ? 'true' : 'false') . '">'; |
|
270 | + |
|
271 | + if ($this->description) { |
|
272 | + if ($this->testmode) { |
|
273 | 273 | /* translators: link to Stripe testing page */ |
274 | - $this->description .= ' ' . sprintf( __( 'TEST MODE ENABLED. In test mode, you can use the card number 4242424242424242 with any CVC and a valid expiration date or check the documentation "<a href="%s" target="_blank">Testing Stripe</a>" for more card numbers.', 'woocommerce-gateway-stripe' ), 'https://stripe.com/docs/testing' ); |
|
275 | - $this->description = trim( $this->description ); |
|
274 | + $this->description .= ' ' . sprintf(__('TEST MODE ENABLED. In test mode, you can use the card number 4242424242424242 with any CVC and a valid expiration date or check the documentation "<a href="%s" target="_blank">Testing Stripe</a>" for more card numbers.', 'woocommerce-gateway-stripe'), 'https://stripe.com/docs/testing'); |
|
275 | + $this->description = trim($this->description); |
|
276 | 276 | } |
277 | - echo apply_filters( 'wc_stripe_description', wpautop( wp_kses_post( $this->description ) ) ); |
|
277 | + echo apply_filters('wc_stripe_description', wpautop(wp_kses_post($this->description))); |
|
278 | 278 | } |
279 | 279 | |
280 | - if ( $display_tokenization ) { |
|
280 | + if ($display_tokenization) { |
|
281 | 281 | $this->tokenization_script(); |
282 | 282 | $this->saved_payment_methods(); |
283 | 283 | } |
284 | 284 | |
285 | - if ( ! $this->stripe_checkout ) { |
|
286 | - if ( apply_filters( 'wc_stripe_use_elements_checkout_form', true ) ) { |
|
285 | + if ( ! $this->stripe_checkout) { |
|
286 | + if (apply_filters('wc_stripe_use_elements_checkout_form', true)) { |
|
287 | 287 | $this->elements_form(); |
288 | 288 | } else { |
289 | - WC_Stripe_Logger::log( 'DEPRECATED! Since version 4.0. Stripe Elements is used. This legacy credit card form will be removed by version 5.0!' ); |
|
289 | + WC_Stripe_Logger::log('DEPRECATED! Since version 4.0. Stripe Elements is used. This legacy credit card form will be removed by version 5.0!'); |
|
290 | 290 | $this->form(); |
291 | 291 | echo '<div class="stripe-source-errors" role="alert"></div>'; |
292 | 292 | } |
293 | 293 | } |
294 | 294 | |
295 | - if ( apply_filters( 'wc_stripe_display_save_payment_method_checkbox', $display_tokenization ) && ! is_add_payment_method_page() && ! isset( $_GET['change_payment_method'] ) ) { |
|
295 | + if (apply_filters('wc_stripe_display_save_payment_method_checkbox', $display_tokenization) && ! is_add_payment_method_page() && ! isset($_GET['change_payment_method'])) { |
|
296 | 296 | $this->save_payment_method_checkbox(); |
297 | 297 | } |
298 | 298 | |
@@ -307,12 +307,12 @@ discard block |
||
307 | 307 | */ |
308 | 308 | public function elements_form() { |
309 | 309 | ?> |
310 | - <fieldset id="wc-<?php echo esc_attr( $this->id ); ?>-cc-form" class="wc-credit-card-form wc-payment-form" style="background:transparent;"> |
|
311 | - <?php do_action( 'woocommerce_credit_card_form_start', $this->id ); ?> |
|
310 | + <fieldset id="wc-<?php echo esc_attr($this->id); ?>-cc-form" class="wc-credit-card-form wc-payment-form" style="background:transparent;"> |
|
311 | + <?php do_action('woocommerce_credit_card_form_start', $this->id); ?> |
|
312 | 312 | |
313 | - <?php if ( $this->inline_cc_form ) { ?> |
|
313 | + <?php if ($this->inline_cc_form) { ?> |
|
314 | 314 | <label for="card-element"> |
315 | - <?php esc_html_e( 'Credit or debit card', 'woocommerce-gateway-stripe' ); ?> |
|
315 | + <?php esc_html_e('Credit or debit card', 'woocommerce-gateway-stripe'); ?> |
|
316 | 316 | </label> |
317 | 317 | |
318 | 318 | <div id="stripe-card-element" style="background:#fff;padding:0 1em;border:1px solid #ddd;margin:5px 0;padding:10px 5px;"> |
@@ -320,7 +320,7 @@ discard block |
||
320 | 320 | </div> |
321 | 321 | <?php } else { ?> |
322 | 322 | <div class="form-row form-row-wide"> |
323 | - <label><?php _e( 'Card Number', 'woocommerce-gateway-stripe' ); ?> <span class="required">*</span></label> |
|
323 | + <label><?php _e('Card Number', 'woocommerce-gateway-stripe'); ?> <span class="required">*</span></label> |
|
324 | 324 | |
325 | 325 | <div id="stripe-card-element" style="background:#fff;padding:0 1em;border:1px solid #ddd;margin:5px 0;padding:10px 5px;"> |
326 | 326 | <!-- a Stripe Element will be inserted here. --> |
@@ -328,7 +328,7 @@ discard block |
||
328 | 328 | </div> |
329 | 329 | |
330 | 330 | <div class="form-row form-row-first"> |
331 | - <label><?php _e( 'Expiry Date', 'woocommerce-gateway-stripe' ); ?> <span class="required">*</span></label> |
|
331 | + <label><?php _e('Expiry Date', 'woocommerce-gateway-stripe'); ?> <span class="required">*</span></label> |
|
332 | 332 | |
333 | 333 | <div id="stripe-exp-element" style="background:#fff;padding:0 1em;border:1px solid #ddd;margin:5px 0;padding:10px 5px;"> |
334 | 334 | <!-- a Stripe Element will be inserted here. --> |
@@ -336,7 +336,7 @@ discard block |
||
336 | 336 | </div> |
337 | 337 | |
338 | 338 | <div class="form-row form-row-last"> |
339 | - <label><?php _e( 'Card Code (CVC)', 'woocommerce-gateway-stripe' ); ?> <span class="required">*</span></label> |
|
339 | + <label><?php _e('Card Code (CVC)', 'woocommerce-gateway-stripe'); ?> <span class="required">*</span></label> |
|
340 | 340 | <div id="stripe-cvc-element" style="background:#fff;padding:0 1em;border:1px solid #ddd;margin:5px 0;padding:10px 5px;"> |
341 | 341 | <!-- a Stripe Element will be inserted here. --> |
342 | 342 | </div> |
@@ -346,7 +346,7 @@ discard block |
||
346 | 346 | |
347 | 347 | <!-- Used to display form errors --> |
348 | 348 | <div class="stripe-source-errors" role="alert"></div> |
349 | - <?php do_action( 'woocommerce_credit_card_form_end', $this->id ); ?> |
|
349 | + <?php do_action('woocommerce_credit_card_form_end', $this->id); ?> |
|
350 | 350 | <div class="clear"></div> |
351 | 351 | </fieldset> |
352 | 352 | <?php |
@@ -359,13 +359,13 @@ discard block |
||
359 | 359 | * @version 3.1.0 |
360 | 360 | */ |
361 | 361 | public function admin_scripts() { |
362 | - if ( 'woocommerce_page_wc-settings' !== get_current_screen()->id ) { |
|
362 | + if ('woocommerce_page_wc-settings' !== get_current_screen()->id) { |
|
363 | 363 | return; |
364 | 364 | } |
365 | 365 | |
366 | - $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
366 | + $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; |
|
367 | 367 | |
368 | - wp_enqueue_script( 'woocommerce_stripe_admin', plugins_url( 'assets/js/stripe-admin' . $suffix . '.js', WC_STRIPE_MAIN_FILE ), array(), WC_STRIPE_VERSION, true ); |
|
368 | + wp_enqueue_script('woocommerce_stripe_admin', plugins_url('assets/js/stripe-admin' . $suffix . '.js', WC_STRIPE_MAIN_FILE), array(), WC_STRIPE_VERSION, true); |
|
369 | 369 | } |
370 | 370 | |
371 | 371 | /** |
@@ -377,46 +377,46 @@ discard block |
||
377 | 377 | * @version 4.0.0 |
378 | 378 | */ |
379 | 379 | public function payment_scripts() { |
380 | - if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) && ! is_add_payment_method_page() && ! isset( $_GET['change_payment_method'] ) ) { |
|
380 | + if ( ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order']) && ! is_add_payment_method_page() && ! isset($_GET['change_payment_method'])) { |
|
381 | 381 | return; |
382 | 382 | } |
383 | 383 | |
384 | 384 | // If Stripe is not enabled bail. |
385 | - if ( 'no' === $this->enabled ) { |
|
385 | + if ('no' === $this->enabled) { |
|
386 | 386 | return; |
387 | 387 | } |
388 | 388 | |
389 | 389 | // If keys are not set bail. |
390 | - if ( ! $this->are_keys_set() ) { |
|
391 | - WC_Stripe_Logger::log( 'Keys are not set correctly.' ); |
|
390 | + if ( ! $this->are_keys_set()) { |
|
391 | + WC_Stripe_Logger::log('Keys are not set correctly.'); |
|
392 | 392 | return; |
393 | 393 | } |
394 | 394 | |
395 | 395 | // If no SSL bail. |
396 | - if ( ! $this->testmode && ! is_ssl() ) { |
|
397 | - WC_Stripe_Logger::log( 'Stripe requires SSL.' ); |
|
396 | + if ( ! $this->testmode && ! is_ssl()) { |
|
397 | + WC_Stripe_Logger::log('Stripe requires SSL.'); |
|
398 | 398 | return; |
399 | 399 | } |
400 | 400 | |
401 | - $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
401 | + $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; |
|
402 | 402 | |
403 | - wp_register_style( 'stripe_paymentfonts', plugins_url( 'assets/css/stripe-paymentfonts.css', WC_STRIPE_MAIN_FILE ), array(), '1.2.5' ); |
|
404 | - wp_enqueue_style( 'stripe_paymentfonts' ); |
|
405 | - wp_register_script( 'stripe_checkout', 'https://checkout.stripe.com/checkout.js', '', WC_STRIPE_VERSION, true ); |
|
406 | - wp_register_script( 'stripev2', 'https://js.stripe.com/v2/', '', '2.0', true ); |
|
407 | - wp_register_script( 'stripe', 'https://js.stripe.com/v3/', '', '3.0', true ); |
|
408 | - wp_register_script( 'woocommerce_stripe', plugins_url( 'assets/js/stripe' . $suffix . '.js', WC_STRIPE_MAIN_FILE ), array( 'jquery-payment', 'stripev2', 'stripe' ), WC_STRIPE_VERSION, true ); |
|
403 | + wp_register_style('stripe_paymentfonts', plugins_url('assets/css/stripe-paymentfonts.css', WC_STRIPE_MAIN_FILE), array(), '1.2.5'); |
|
404 | + wp_enqueue_style('stripe_paymentfonts'); |
|
405 | + wp_register_script('stripe_checkout', 'https://checkout.stripe.com/checkout.js', '', WC_STRIPE_VERSION, true); |
|
406 | + wp_register_script('stripev2', 'https://js.stripe.com/v2/', '', '2.0', true); |
|
407 | + wp_register_script('stripe', 'https://js.stripe.com/v3/', '', '3.0', true); |
|
408 | + wp_register_script('woocommerce_stripe', plugins_url('assets/js/stripe' . $suffix . '.js', WC_STRIPE_MAIN_FILE), array('jquery-payment', 'stripev2', 'stripe'), WC_STRIPE_VERSION, true); |
|
409 | 409 | |
410 | 410 | $stripe_params = array( |
411 | 411 | 'key' => $this->publishable_key, |
412 | - 'i18n_terms' => __( 'Please accept the terms and conditions first', 'woocommerce-gateway-stripe' ), |
|
413 | - 'i18n_required_fields' => __( 'Please fill in required checkout fields first', 'woocommerce-gateway-stripe' ), |
|
412 | + 'i18n_terms' => __('Please accept the terms and conditions first', 'woocommerce-gateway-stripe'), |
|
413 | + 'i18n_required_fields' => __('Please fill in required checkout fields first', 'woocommerce-gateway-stripe'), |
|
414 | 414 | ); |
415 | 415 | |
416 | 416 | // If we're on the pay page we need to pass stripe.js the address of the order. |
417 | - if ( isset( $_GET['pay_for_order'] ) && 'true' === $_GET['pay_for_order'] ) { |
|
418 | - $order_id = wc_get_order_id_by_order_key( urldecode( $_GET['key'] ) ); |
|
419 | - $order = wc_get_order( $order_id ); |
|
417 | + if (isset($_GET['pay_for_order']) && 'true' === $_GET['pay_for_order']) { |
|
418 | + $order_id = wc_get_order_id_by_order_key(urldecode($_GET['key'])); |
|
419 | + $order = wc_get_order($order_id); |
|
420 | 420 | |
421 | 421 | $stripe_params['billing_first_name'] = WC_Stripe_Helper::is_pre_30() ? $order->billing_first_name : $order->get_billing_first_name(); |
422 | 422 | $stripe_params['billing_last_name'] = WC_Stripe_Helper::is_pre_30() ? $order->billing_last_name : $order->get_billing_last_name(); |
@@ -428,39 +428,39 @@ discard block |
||
428 | 428 | $stripe_params['billing_country'] = WC_Stripe_Helper::is_pre_30() ? $order->billing_country : $order->get_billing_country(); |
429 | 429 | } |
430 | 430 | |
431 | - $stripe_params['no_prepaid_card_msg'] = __( 'Sorry, we\'re not accepting prepaid cards at this time. Your credit card has not been charge. Please try with alternative payment method.', 'woocommerce-gateway-stripe' ); |
|
432 | - $stripe_params['no_sepa_owner_msg'] = __( 'Please enter your IBAN account name.', 'woocommerce-gateway-stripe' ); |
|
433 | - $stripe_params['no_sepa_iban_msg'] = __( 'Please enter your IBAN account number.', 'woocommerce-gateway-stripe' ); |
|
434 | - $stripe_params['sepa_mandate_notification'] = apply_filters( 'wc_stripe_sepa_mandate_notification', 'email' ); |
|
435 | - $stripe_params['allow_prepaid_card'] = apply_filters( 'wc_stripe_allow_prepaid_card', true ) ? 'yes' : 'no'; |
|
431 | + $stripe_params['no_prepaid_card_msg'] = __('Sorry, we\'re not accepting prepaid cards at this time. Your credit card has not been charge. Please try with alternative payment method.', 'woocommerce-gateway-stripe'); |
|
432 | + $stripe_params['no_sepa_owner_msg'] = __('Please enter your IBAN account name.', 'woocommerce-gateway-stripe'); |
|
433 | + $stripe_params['no_sepa_iban_msg'] = __('Please enter your IBAN account number.', 'woocommerce-gateway-stripe'); |
|
434 | + $stripe_params['sepa_mandate_notification'] = apply_filters('wc_stripe_sepa_mandate_notification', 'email'); |
|
435 | + $stripe_params['allow_prepaid_card'] = apply_filters('wc_stripe_allow_prepaid_card', true) ? 'yes' : 'no'; |
|
436 | 436 | $stripe_params['inline_cc_form'] = $this->inline_cc_form ? 'yes' : 'no'; |
437 | - $stripe_params['stripe_checkout_require_billing_address'] = apply_filters( 'wc_stripe_checkout_require_billing_address', false ) ? 'yes' : 'no'; |
|
438 | - $stripe_params['is_checkout'] = ( is_checkout() && empty( $_GET['pay_for_order'] ) ) ? 'yes' : 'no'; |
|
437 | + $stripe_params['stripe_checkout_require_billing_address'] = apply_filters('wc_stripe_checkout_require_billing_address', false) ? 'yes' : 'no'; |
|
438 | + $stripe_params['is_checkout'] = (is_checkout() && empty($_GET['pay_for_order'])) ? 'yes' : 'no'; |
|
439 | 439 | $stripe_params['return_url'] = $this->get_stripe_return_url(); |
440 | - $stripe_params['ajaxurl'] = WC_AJAX::get_endpoint( '%%endpoint%%' ); |
|
441 | - $stripe_params['stripe_nonce'] = wp_create_nonce( '_wc_stripe_nonce' ); |
|
440 | + $stripe_params['ajaxurl'] = WC_AJAX::get_endpoint('%%endpoint%%'); |
|
441 | + $stripe_params['stripe_nonce'] = wp_create_nonce('_wc_stripe_nonce'); |
|
442 | 442 | $stripe_params['statement_descriptor'] = $this->statement_descriptor; |
443 | - $stripe_params['use_elements'] = apply_filters( 'wc_stripe_use_elements_checkout_form', true ) ? 'yes' : 'no'; |
|
444 | - $stripe_params['elements_options'] = apply_filters( 'wc_stripe_elements_options', array() ); |
|
443 | + $stripe_params['use_elements'] = apply_filters('wc_stripe_use_elements_checkout_form', true) ? 'yes' : 'no'; |
|
444 | + $stripe_params['elements_options'] = apply_filters('wc_stripe_elements_options', array()); |
|
445 | 445 | $stripe_params['is_stripe_checkout'] = $this->stripe_checkout ? 'yes' : 'no'; |
446 | - $stripe_params['is_change_payment_page'] = isset( $_GET['change_payment_method'] ) ? 'yes' : 'no'; |
|
447 | - $stripe_params['is_pay_for_order_page'] = isset( $_GET['pay_for_order'] ) ? 'yes' : 'no'; |
|
448 | - $stripe_params['validate_modal_checkout'] = apply_filters( 'wc_stripe_validate_modal_checkout', false ) ? 'yes' : 'no'; |
|
449 | - $stripe_params['elements_styling'] = apply_filters( 'wc_stripe_elements_styling', false ); |
|
450 | - $stripe_params['elements_classes'] = apply_filters( 'wc_stripe_elements_classes', false ); |
|
446 | + $stripe_params['is_change_payment_page'] = isset($_GET['change_payment_method']) ? 'yes' : 'no'; |
|
447 | + $stripe_params['is_pay_for_order_page'] = isset($_GET['pay_for_order']) ? 'yes' : 'no'; |
|
448 | + $stripe_params['validate_modal_checkout'] = apply_filters('wc_stripe_validate_modal_checkout', false) ? 'yes' : 'no'; |
|
449 | + $stripe_params['elements_styling'] = apply_filters('wc_stripe_elements_styling', false); |
|
450 | + $stripe_params['elements_classes'] = apply_filters('wc_stripe_elements_classes', false); |
|
451 | 451 | |
452 | 452 | // merge localized messages to be use in JS |
453 | - $stripe_params = array_merge( $stripe_params, WC_Stripe_Helper::get_localized_messages() ); |
|
453 | + $stripe_params = array_merge($stripe_params, WC_Stripe_Helper::get_localized_messages()); |
|
454 | 454 | |
455 | - wp_localize_script( 'woocommerce_stripe', 'wc_stripe_params', apply_filters( 'wc_stripe_params', $stripe_params ) ); |
|
456 | - wp_localize_script( 'woocommerce_stripe_checkout', 'wc_stripe_params', apply_filters( 'wc_stripe_params', $stripe_params ) ); |
|
455 | + wp_localize_script('woocommerce_stripe', 'wc_stripe_params', apply_filters('wc_stripe_params', $stripe_params)); |
|
456 | + wp_localize_script('woocommerce_stripe_checkout', 'wc_stripe_params', apply_filters('wc_stripe_params', $stripe_params)); |
|
457 | 457 | |
458 | - if ( $this->stripe_checkout ) { |
|
459 | - wp_enqueue_script( 'stripe_checkout' ); |
|
458 | + if ($this->stripe_checkout) { |
|
459 | + wp_enqueue_script('stripe_checkout'); |
|
460 | 460 | } |
461 | 461 | |
462 | 462 | $this->tokenization_script(); |
463 | - wp_enqueue_script( 'woocommerce_stripe' ); |
|
463 | + wp_enqueue_script('woocommerce_stripe'); |
|
464 | 464 | } |
465 | 465 | |
466 | 466 | /** |
@@ -476,41 +476,41 @@ discard block |
||
476 | 476 | * |
477 | 477 | * @return array|void |
478 | 478 | */ |
479 | - public function process_payment( $order_id, $retry = true, $force_save_source = false ) { |
|
479 | + public function process_payment($order_id, $retry = true, $force_save_source = false) { |
|
480 | 480 | try { |
481 | - $order = wc_get_order( $order_id ); |
|
481 | + $order = wc_get_order($order_id); |
|
482 | 482 | |
483 | 483 | // This comes from the create account checkbox in the checkout page. |
484 | - $create_account = ! empty( $_POST['createaccount'] ) ? true : false; |
|
484 | + $create_account = ! empty($_POST['createaccount']) ? true : false; |
|
485 | 485 | |
486 | - if ( $create_account ) { |
|
486 | + if ($create_account) { |
|
487 | 487 | $new_customer_id = WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id(); |
488 | - $new_stripe_customer = new WC_Stripe_Customer( $new_customer_id ); |
|
488 | + $new_stripe_customer = new WC_Stripe_Customer($new_customer_id); |
|
489 | 489 | $new_stripe_customer->create_customer(); |
490 | 490 | } |
491 | 491 | |
492 | - $prepared_source = $this->prepare_source( get_current_user_id(), $force_save_source ); |
|
492 | + $prepared_source = $this->prepare_source(get_current_user_id(), $force_save_source); |
|
493 | 493 | $source_object = $prepared_source->source_object; |
494 | 494 | |
495 | 495 | // Check if we don't allow prepaid credit cards. |
496 | - if ( ! apply_filters( 'wc_stripe_allow_prepaid_card', true ) && $this->is_prepaid_card( $source_object ) ) { |
|
497 | - $localized_message = __( 'Sorry, we\'re not accepting prepaid cards at this time. Your credit card has not been charge. Please try with alternative payment method.', 'woocommerce-gateway-stripe' ); |
|
498 | - throw new WC_Stripe_Exception( print_r( $source_object, true ), $localized_message ); |
|
496 | + if ( ! apply_filters('wc_stripe_allow_prepaid_card', true) && $this->is_prepaid_card($source_object)) { |
|
497 | + $localized_message = __('Sorry, we\'re not accepting prepaid cards at this time. Your credit card has not been charge. Please try with alternative payment method.', 'woocommerce-gateway-stripe'); |
|
498 | + throw new WC_Stripe_Exception(print_r($source_object, true), $localized_message); |
|
499 | 499 | } |
500 | 500 | |
501 | - if ( empty( $prepared_source->source ) ) { |
|
502 | - $localized_message = __( 'Payment processing failed. Please retry.', 'woocommerce-gateway-stripe' ); |
|
503 | - throw new WC_Stripe_Exception( print_r( $prepared_source, true ), $localized_message ); |
|
501 | + if (empty($prepared_source->source)) { |
|
502 | + $localized_message = __('Payment processing failed. Please retry.', 'woocommerce-gateway-stripe'); |
|
503 | + throw new WC_Stripe_Exception(print_r($prepared_source, true), $localized_message); |
|
504 | 504 | } |
505 | 505 | |
506 | - $this->save_source_to_order( $order, $prepared_source ); |
|
506 | + $this->save_source_to_order($order, $prepared_source); |
|
507 | 507 | |
508 | 508 | // Result from Stripe API request. |
509 | 509 | $response = null; |
510 | 510 | |
511 | - if ( $order->get_total() > 0 ) { |
|
511 | + if ($order->get_total() > 0) { |
|
512 | 512 | // This will throw exception if not valid. |
513 | - $this->validate_minimum_order_amount( $order ); |
|
513 | + $this->validate_minimum_order_amount($order); |
|
514 | 514 | |
515 | 515 | /* |
516 | 516 | * Check if card 3DS is required or optional with 3DS setting. |
@@ -519,105 +519,105 @@ discard block |
||
519 | 519 | * Note that if we need to save source, the original source must be first |
520 | 520 | * attached to a customer in Stripe before it can be charged. |
521 | 521 | */ |
522 | - if ( $this->is_3ds_required( $source_object ) ) { |
|
523 | - $response = $this->create_3ds_source( $order, $source_object ); |
|
522 | + if ($this->is_3ds_required($source_object)) { |
|
523 | + $response = $this->create_3ds_source($order, $source_object); |
|
524 | 524 | |
525 | - if ( ! empty( $response->error ) ) { |
|
525 | + if ( ! empty($response->error)) { |
|
526 | 526 | $localized_message = $response->error->message; |
527 | 527 | |
528 | - $order->add_order_note( $localized_message ); |
|
528 | + $order->add_order_note($localized_message); |
|
529 | 529 | |
530 | - throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message ); |
|
530 | + throw new WC_Stripe_Exception(print_r($response, true), $localized_message); |
|
531 | 531 | } |
532 | 532 | |
533 | 533 | // Update order meta with 3DS source. |
534 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
535 | - update_post_meta( $order_id, '_stripe_source_id', $response->id ); |
|
534 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
535 | + update_post_meta($order_id, '_stripe_source_id', $response->id); |
|
536 | 536 | } else { |
537 | - $order->update_meta_data( '_stripe_source_id', $response->id ); |
|
537 | + $order->update_meta_data('_stripe_source_id', $response->id); |
|
538 | 538 | $order->save(); |
539 | 539 | } |
540 | 540 | |
541 | - WC_Stripe_Logger::log( 'Info: Redirecting to 3DS...' ); |
|
541 | + WC_Stripe_Logger::log('Info: Redirecting to 3DS...'); |
|
542 | 542 | |
543 | 543 | return array( |
544 | 544 | 'result' => 'success', |
545 | - 'redirect' => esc_url_raw( $response->redirect->url ), |
|
545 | + 'redirect' => esc_url_raw($response->redirect->url), |
|
546 | 546 | ); |
547 | 547 | } |
548 | 548 | |
549 | - WC_Stripe_Logger::log( "Info: Begin processing payment for order $order_id for the amount of {$order->get_total()}" ); |
|
549 | + WC_Stripe_Logger::log("Info: Begin processing payment for order $order_id for the amount of {$order->get_total()}"); |
|
550 | 550 | |
551 | 551 | /* If we're doing a retry and source is chargeable, we need to pass |
552 | 552 | * a different idempotency key and retry for success. |
553 | 553 | */ |
554 | - if ( 1 < $this->retry_interval && ! empty( $source_object ) && 'chargeable' === $source_object->status ) { |
|
555 | - add_filter( 'wc_stripe_idempotency_key', array( $this, 'change_idempotency_key' ), 10, 2 ); |
|
554 | + if (1 < $this->retry_interval && ! empty($source_object) && 'chargeable' === $source_object->status) { |
|
555 | + add_filter('wc_stripe_idempotency_key', array($this, 'change_idempotency_key'), 10, 2); |
|
556 | 556 | } |
557 | 557 | |
558 | 558 | // Make the request. |
559 | - $response = WC_Stripe_API::request( $this->generate_payment_request( $order, $prepared_source ) ); |
|
559 | + $response = WC_Stripe_API::request($this->generate_payment_request($order, $prepared_source)); |
|
560 | 560 | |
561 | - if ( ! empty( $response->error ) ) { |
|
561 | + if ( ! empty($response->error)) { |
|
562 | 562 | // Customer param wrong? The user may have been deleted on stripe's end. Remove customer_id. Can be retried without. |
563 | - if ( preg_match( '/No such customer/i', $response->error->message ) && $retry ) { |
|
564 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
565 | - delete_user_meta( $order->customer_user, '_stripe_customer_id' ); |
|
566 | - delete_post_meta( $order_id, '_stripe_customer_id' ); |
|
563 | + if (preg_match('/No such customer/i', $response->error->message) && $retry) { |
|
564 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
565 | + delete_user_meta($order->customer_user, '_stripe_customer_id'); |
|
566 | + delete_post_meta($order_id, '_stripe_customer_id'); |
|
567 | 567 | } else { |
568 | - delete_user_meta( $order->get_customer_id(), '_stripe_customer_id' ); |
|
569 | - $order->delete_meta_data( '_stripe_customer_id' ); |
|
568 | + delete_user_meta($order->get_customer_id(), '_stripe_customer_id'); |
|
569 | + $order->delete_meta_data('_stripe_customer_id'); |
|
570 | 570 | $order->save(); |
571 | 571 | } |
572 | 572 | |
573 | - return $this->process_payment( $order_id, false, $force_save_source ); |
|
574 | - } elseif ( preg_match( '/No such token/i', $response->error->message ) && $prepared_source->token_id ) { |
|
573 | + return $this->process_payment($order_id, false, $force_save_source); |
|
574 | + } elseif (preg_match('/No such token/i', $response->error->message) && $prepared_source->token_id) { |
|
575 | 575 | // Source param wrong? The CARD may have been deleted on stripe's end. Remove token and show message. |
576 | - $wc_token = WC_Payment_Tokens::get( $prepared_source->token_id ); |
|
576 | + $wc_token = WC_Payment_Tokens::get($prepared_source->token_id); |
|
577 | 577 | $wc_token->delete(); |
578 | - $localized_message = __( 'This card is no longer available and has been removed.', 'woocommerce-gateway-stripe' ); |
|
579 | - $order->add_order_note( $localized_message ); |
|
580 | - throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message ); |
|
578 | + $localized_message = __('This card is no longer available and has been removed.', 'woocommerce-gateway-stripe'); |
|
579 | + $order->add_order_note($localized_message); |
|
580 | + throw new WC_Stripe_Exception(print_r($response, true), $localized_message); |
|
581 | 581 | } |
582 | 582 | |
583 | 583 | // We want to retry. |
584 | - if ( $this->is_retryable_error( $response->error ) ) { |
|
585 | - if ( $retry ) { |
|
584 | + if ($this->is_retryable_error($response->error)) { |
|
585 | + if ($retry) { |
|
586 | 586 | // Don't do anymore retries after this. |
587 | - if ( 5 <= $this->retry_interval ) { |
|
587 | + if (5 <= $this->retry_interval) { |
|
588 | 588 | |
589 | - return $this->process_payment( $order_id, false, $force_save_source ); |
|
589 | + return $this->process_payment($order_id, false, $force_save_source); |
|
590 | 590 | } |
591 | 591 | |
592 | - sleep( $this->retry_interval ); |
|
592 | + sleep($this->retry_interval); |
|
593 | 593 | |
594 | 594 | $this->retry_interval++; |
595 | 595 | |
596 | - return $this->process_payment( $order_id, true, $force_save_source ); |
|
596 | + return $this->process_payment($order_id, true, $force_save_source); |
|
597 | 597 | } else { |
598 | - $localized_message = __( 'On going requests error and retries exhausted.', 'woocommerce-gateway-stripe' ); |
|
599 | - $order->add_order_note( $localized_message ); |
|
600 | - throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message ); |
|
598 | + $localized_message = __('On going requests error and retries exhausted.', 'woocommerce-gateway-stripe'); |
|
599 | + $order->add_order_note($localized_message); |
|
600 | + throw new WC_Stripe_Exception(print_r($response, true), $localized_message); |
|
601 | 601 | } |
602 | 602 | } |
603 | 603 | |
604 | 604 | $localized_messages = WC_Stripe_Helper::get_localized_messages(); |
605 | 605 | |
606 | - if ( 'card_error' === $response->error->type ) { |
|
607 | - $localized_message = isset( $localized_messages[ $response->error->code ] ) ? $localized_messages[ $response->error->code ] : $response->error->message; |
|
606 | + if ('card_error' === $response->error->type) { |
|
607 | + $localized_message = isset($localized_messages[$response->error->code]) ? $localized_messages[$response->error->code] : $response->error->message; |
|
608 | 608 | } else { |
609 | - $localized_message = isset( $localized_messages[ $response->error->type ] ) ? $localized_messages[ $response->error->type ] : $response->error->message; |
|
609 | + $localized_message = isset($localized_messages[$response->error->type]) ? $localized_messages[$response->error->type] : $response->error->message; |
|
610 | 610 | } |
611 | 611 | |
612 | - $order->add_order_note( $localized_message ); |
|
612 | + $order->add_order_note($localized_message); |
|
613 | 613 | |
614 | - throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message ); |
|
614 | + throw new WC_Stripe_Exception(print_r($response, true), $localized_message); |
|
615 | 615 | } |
616 | 616 | |
617 | - do_action( 'wc_gateway_stripe_process_payment', $response, $order ); |
|
617 | + do_action('wc_gateway_stripe_process_payment', $response, $order); |
|
618 | 618 | |
619 | 619 | // Process valid response. |
620 | - $this->process_response( $response, $order ); |
|
620 | + $this->process_response($response, $order); |
|
621 | 621 | } else { |
622 | 622 | $order->payment_complete(); |
623 | 623 | } |
@@ -628,20 +628,20 @@ discard block |
||
628 | 628 | // Return thank you page redirect. |
629 | 629 | return array( |
630 | 630 | 'result' => 'success', |
631 | - 'redirect' => $this->get_return_url( $order ), |
|
631 | + 'redirect' => $this->get_return_url($order), |
|
632 | 632 | ); |
633 | 633 | |
634 | - } catch ( WC_Stripe_Exception $e ) { |
|
635 | - wc_add_notice( $e->getLocalizedMessage(), 'error' ); |
|
636 | - WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() ); |
|
634 | + } catch (WC_Stripe_Exception $e) { |
|
635 | + wc_add_notice($e->getLocalizedMessage(), 'error'); |
|
636 | + WC_Stripe_Logger::log('Error: ' . $e->getMessage()); |
|
637 | 637 | |
638 | - do_action( 'wc_gateway_stripe_process_payment_error', $e, $order ); |
|
638 | + do_action('wc_gateway_stripe_process_payment_error', $e, $order); |
|
639 | 639 | |
640 | 640 | /* translators: error message */ |
641 | - $order->update_status( 'failed' ); |
|
641 | + $order->update_status('failed'); |
|
642 | 642 | |
643 | - if ( $order->has_status( array( 'pending', 'failed' ) ) ) { |
|
644 | - $this->send_failed_order_email( $order_id ); |
|
643 | + if ($order->has_status(array('pending', 'failed'))) { |
|
644 | + $this->send_failed_order_email($order_id); |
|
645 | 645 | } |
646 | 646 | |
647 | 647 | 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 | |
@@ -21,7 +21,7 @@ discard block |
||
21 | 21 | * @since 4.0.5 |
22 | 22 | * @param array $error |
23 | 23 | */ |
24 | - public function is_retryable_error( $error ) { |
|
24 | + public function is_retryable_error($error) { |
|
25 | 25 | return ( |
26 | 26 | 'invalid_request_error' === $error->type || |
27 | 27 | 'idempotency_error' === $error->type || |
@@ -35,11 +35,11 @@ discard block |
||
35 | 35 | * Check if this gateway is enabled |
36 | 36 | */ |
37 | 37 | public function is_available() { |
38 | - if ( 'yes' === $this->enabled ) { |
|
39 | - if ( ! $this->testmode && is_checkout() && ! is_ssl() ) { |
|
38 | + if ('yes' === $this->enabled) { |
|
39 | + if ( ! $this->testmode && is_checkout() && ! is_ssl()) { |
|
40 | 40 | return false; |
41 | 41 | } |
42 | - if ( ! $this->secret_key || ! $this->publishable_key ) { |
|
42 | + if ( ! $this->secret_key || ! $this->publishable_key) { |
|
43 | 43 | return false; |
44 | 44 | } |
45 | 45 | return true; |
@@ -54,8 +54,8 @@ discard block |
||
54 | 54 | * @since 4.0.0 |
55 | 55 | * @version 4.0.0 |
56 | 56 | */ |
57 | - public function add_admin_notice( $slug, $class, $message ) { |
|
58 | - $this->notices[ $slug ] = array( |
|
57 | + public function add_admin_notice($slug, $class, $message) { |
|
58 | + $this->notices[$slug] = array( |
|
59 | 59 | 'class' => $class, |
60 | 60 | 'message' => $message, |
61 | 61 | ); |
@@ -68,8 +68,8 @@ discard block |
||
68 | 68 | * @version 4.0.0 |
69 | 69 | */ |
70 | 70 | public function remove_admin_notice() { |
71 | - if ( did_action( 'woocommerce_update_options' ) ) { |
|
72 | - remove_action( 'admin_notices', array( $this, 'check_environment' ) ); |
|
71 | + if (did_action('woocommerce_update_options')) { |
|
72 | + remove_action('admin_notices', array($this, 'check_environment')); |
|
73 | 73 | } |
74 | 74 | } |
75 | 75 | |
@@ -81,7 +81,7 @@ discard block |
||
81 | 81 | * @return array |
82 | 82 | */ |
83 | 83 | public function payment_icons() { |
84 | - return apply_filters( 'wc_stripe_payment_icons', array( |
|
84 | + return apply_filters('wc_stripe_payment_icons', array( |
|
85 | 85 | 'visa' => '<i class="stripe-pf stripe-pf-visa stripe-pf-right" alt="Visa" aria-hidden="true"></i>', |
86 | 86 | 'amex' => '<i class="stripe-pf stripe-pf-american-express stripe-pf-right" alt="Amex" aria-hidden="true"></i>', |
87 | 87 | 'mastercard' => '<i class="stripe-pf stripe-pf-mastercard stripe-pf-right" alt="Mastercard" aria-hidden="true"></i>', |
@@ -98,7 +98,7 @@ discard block |
||
98 | 98 | 'eps' => '<i class="stripe-pf stripe-pf-eps stripe-pf-right" alt="EPS" aria-hidden="true"></i>', |
99 | 99 | 'sofort' => '<i class="stripe-pf stripe-pf-sofort stripe-pf-right" alt="SOFORT" aria-hidden="true"></i>', |
100 | 100 | 'sepa' => '<i class="stripe-pf stripe-pf-sepa stripe-pf-right" alt="SEPA" aria-hidden="true"></i>', |
101 | - ) ); |
|
101 | + )); |
|
102 | 102 | } |
103 | 103 | |
104 | 104 | /** |
@@ -109,10 +109,10 @@ discard block |
||
109 | 109 | * @version 4.0.0 |
110 | 110 | * @param object $order |
111 | 111 | */ |
112 | - public function validate_minimum_order_amount( $order ) { |
|
113 | - if ( $order->get_total() * 100 < WC_Stripe_Helper::get_minimum_amount() ) { |
|
112 | + public function validate_minimum_order_amount($order) { |
|
113 | + if ($order->get_total() * 100 < WC_Stripe_Helper::get_minimum_amount()) { |
|
114 | 114 | /* translators: 1) dollar amount */ |
115 | - 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 ) ) ); |
|
115 | + 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))); |
|
116 | 116 | } |
117 | 117 | } |
118 | 118 | |
@@ -122,14 +122,14 @@ discard block |
||
122 | 122 | * @since 4.0.0 |
123 | 123 | * @version 4.0.0 |
124 | 124 | */ |
125 | - public function get_transaction_url( $order ) { |
|
126 | - if ( $this->testmode ) { |
|
125 | + public function get_transaction_url($order) { |
|
126 | + if ($this->testmode) { |
|
127 | 127 | $this->view_transaction_url = 'https://dashboard.stripe.com/test/payments/%s'; |
128 | 128 | } else { |
129 | 129 | $this->view_transaction_url = 'https://dashboard.stripe.com/payments/%s'; |
130 | 130 | } |
131 | 131 | |
132 | - return parent::get_transaction_url( $order ); |
|
132 | + return parent::get_transaction_url($order); |
|
133 | 133 | } |
134 | 134 | |
135 | 135 | /** |
@@ -138,15 +138,15 @@ discard block |
||
138 | 138 | * @since 4.0.0 |
139 | 139 | * @version 4.0.0 |
140 | 140 | */ |
141 | - public function get_stripe_customer_id( $order ) { |
|
142 | - $customer = get_user_meta( WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id(), '_stripe_customer_id', true ); |
|
141 | + public function get_stripe_customer_id($order) { |
|
142 | + $customer = get_user_meta(WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id(), '_stripe_customer_id', true); |
|
143 | 143 | |
144 | - if ( empty( $customer ) ) { |
|
144 | + if (empty($customer)) { |
|
145 | 145 | // Try to get it via the order. |
146 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
147 | - return get_post_meta( $order->id, '_stripe_customer_id', true ); |
|
146 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
147 | + return get_post_meta($order->id, '_stripe_customer_id', true); |
|
148 | 148 | } else { |
149 | - return $order->get_meta( '_stripe_customer_id', true ); |
|
149 | + return $order->get_meta('_stripe_customer_id', true); |
|
150 | 150 | } |
151 | 151 | } else { |
152 | 152 | return $customer; |
@@ -163,9 +163,9 @@ discard block |
||
163 | 163 | * @param object $order |
164 | 164 | * @param int $id Stripe session id. |
165 | 165 | */ |
166 | - public function get_stripe_return_url( $order = null, $id = null ) { |
|
167 | - if ( is_object( $order ) ) { |
|
168 | - if ( empty( $id ) ) { |
|
166 | + public function get_stripe_return_url($order = null, $id = null) { |
|
167 | + if (is_object($order)) { |
|
168 | + if (empty($id)) { |
|
169 | 169 | $id = uniqid(); |
170 | 170 | } |
171 | 171 | |
@@ -176,10 +176,10 @@ discard block |
||
176 | 176 | 'order_id' => $order_id, |
177 | 177 | ); |
178 | 178 | |
179 | - return esc_url_raw( add_query_arg( $args, $this->get_return_url( $order ) ) ); |
|
179 | + return esc_url_raw(add_query_arg($args, $this->get_return_url($order))); |
|
180 | 180 | } |
181 | 181 | |
182 | - return esc_url_raw( add_query_arg( array( 'utm_nooverride' => '1' ), $this->get_return_url() ) ); |
|
182 | + return esc_url_raw(add_query_arg(array('utm_nooverride' => '1'), $this->get_return_url())); |
|
183 | 183 | } |
184 | 184 | |
185 | 185 | /** |
@@ -187,8 +187,8 @@ discard block |
||
187 | 187 | * @param int $order_id |
188 | 188 | * @return boolean |
189 | 189 | */ |
190 | - public function has_subscription( $order_id ) { |
|
191 | - return ( function_exists( 'wcs_order_contains_subscription' ) && ( wcs_order_contains_subscription( $order_id ) || wcs_is_subscription( $order_id ) || wcs_order_contains_renewal( $order_id ) ) ); |
|
190 | + public function has_subscription($order_id) { |
|
191 | + return (function_exists('wcs_order_contains_subscription') && (wcs_order_contains_subscription($order_id) || wcs_is_subscription($order_id) || wcs_order_contains_renewal($order_id))); |
|
192 | 192 | } |
193 | 193 | |
194 | 194 | /** |
@@ -200,34 +200,33 @@ discard block |
||
200 | 200 | * @param object $prepared_source |
201 | 201 | * @return array() |
202 | 202 | */ |
203 | - public function generate_payment_request( $order, $prepared_source ) { |
|
204 | - $settings = get_option( 'woocommerce_stripe_settings', array() ); |
|
205 | - $statement_descriptor = ! empty( $settings['statement_descriptor'] ) ? str_replace( "'", '', $settings['statement_descriptor'] ) : ''; |
|
206 | - $capture = ! empty( $settings['capture'] ) && 'yes' === $settings['capture'] ? true : false; |
|
203 | + public function generate_payment_request($order, $prepared_source) { |
|
204 | + $settings = get_option('woocommerce_stripe_settings', array()); |
|
205 | + $statement_descriptor = ! empty($settings['statement_descriptor']) ? str_replace("'", '', $settings['statement_descriptor']) : ''; |
|
206 | + $capture = ! empty($settings['capture']) && 'yes' === $settings['capture'] ? true : false; |
|
207 | 207 | $post_data = array(); |
208 | - $post_data['currency'] = strtolower( WC_Stripe_Helper::is_pre_30() ? $order->get_order_currency() : $order->get_currency() ); |
|
209 | - $post_data['amount'] = WC_Stripe_Helper::get_stripe_amount( $order->get_total(), $post_data['currency'] ); |
|
208 | + $post_data['currency'] = strtolower(WC_Stripe_Helper::is_pre_30() ? $order->get_order_currency() : $order->get_currency()); |
|
209 | + $post_data['amount'] = WC_Stripe_Helper::get_stripe_amount($order->get_total(), $post_data['currency']); |
|
210 | 210 | /* translators: 1) blog name 2) order number */ |
211 | - $post_data['description'] = sprintf( __( '%1$s - Order %2$s', 'woocommerce-gateway-stripe' ), wp_specialchars_decode( get_bloginfo( 'name' ), ENT_QUOTES ), $order->get_order_number() ); |
|
211 | + $post_data['description'] = sprintf(__('%1$s - Order %2$s', 'woocommerce-gateway-stripe'), wp_specialchars_decode(get_bloginfo('name'), ENT_QUOTES), $order->get_order_number()); |
|
212 | 212 | $billing_email = WC_Stripe_Helper::is_pre_30() ? $order->billing_email : $order->get_billing_email(); |
213 | 213 | $billing_first_name = WC_Stripe_Helper::is_pre_30() ? $order->billing_first_name : $order->get_billing_first_name(); |
214 | 214 | $billing_last_name = WC_Stripe_Helper::is_pre_30() ? $order->billing_last_name : $order->get_billing_last_name(); |
215 | 215 | |
216 | - if ( ! empty( $billing_email ) && apply_filters( 'wc_stripe_send_stripe_receipt', false ) ) { |
|
216 | + if ( ! empty($billing_email) && apply_filters('wc_stripe_send_stripe_receipt', false)) { |
|
217 | 217 | $post_data['receipt_email'] = $billing_email; |
218 | 218 | } |
219 | 219 | |
220 | - switch ( WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method() ) { |
|
221 | - case 'stripe': |
|
222 | - if ( ! empty( $statement_descriptor ) ) { |
|
223 | - $post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor( $statement_descriptor ); |
|
220 | + switch (WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method()) { |
|
221 | + case 'stripe' : if ( ! empty($statement_descriptor)) { |
|
222 | + $post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor($statement_descriptor); |
|
224 | 223 | } |
225 | 224 | |
226 | 225 | $post_data['capture'] = $capture ? 'true' : 'false'; |
227 | 226 | break; |
228 | 227 | case 'stripe_sepa': |
229 | - if ( ! empty( $statement_descriptor ) ) { |
|
230 | - $post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor( $statement_descriptor ); |
|
228 | + if ( ! empty($statement_descriptor)) { |
|
229 | + $post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor($statement_descriptor); |
|
231 | 230 | } |
232 | 231 | break; |
233 | 232 | } |
@@ -235,25 +234,25 @@ discard block |
||
235 | 234 | $post_data['expand[]'] = 'balance_transaction'; |
236 | 235 | |
237 | 236 | $metadata = array( |
238 | - __( 'customer_name', 'woocommerce-gateway-stripe' ) => sanitize_text_field( $billing_first_name ) . ' ' . sanitize_text_field( $billing_last_name ), |
|
239 | - __( 'customer_email', 'woocommerce-gateway-stripe' ) => sanitize_email( $billing_email ), |
|
237 | + __('customer_name', 'woocommerce-gateway-stripe') => sanitize_text_field($billing_first_name) . ' ' . sanitize_text_field($billing_last_name), |
|
238 | + __('customer_email', 'woocommerce-gateway-stripe') => sanitize_email($billing_email), |
|
240 | 239 | 'order_id' => WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(), |
241 | 240 | ); |
242 | 241 | |
243 | - if ( $this->has_subscription( WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id() ) ) { |
|
242 | + if ($this->has_subscription(WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id())) { |
|
244 | 243 | $metadata += array( |
245 | 244 | 'payment_type' => 'recurring', |
246 | - 'site_url' => esc_url( get_site_url() ), |
|
245 | + 'site_url' => esc_url(get_site_url()), |
|
247 | 246 | ); |
248 | 247 | } |
249 | 248 | |
250 | - $post_data['metadata'] = apply_filters( 'wc_stripe_payment_metadata', $metadata, $order, $prepared_source ); |
|
249 | + $post_data['metadata'] = apply_filters('wc_stripe_payment_metadata', $metadata, $order, $prepared_source); |
|
251 | 250 | |
252 | - if ( $prepared_source->customer ) { |
|
251 | + if ($prepared_source->customer) { |
|
253 | 252 | $post_data['customer'] = $prepared_source->customer; |
254 | 253 | } |
255 | 254 | |
256 | - if ( $prepared_source->source ) { |
|
255 | + if ($prepared_source->source) { |
|
257 | 256 | $post_data['source'] = $prepared_source->source; |
258 | 257 | } |
259 | 258 | |
@@ -265,79 +264,79 @@ discard block |
||
265 | 264 | * @param WC_Order $order |
266 | 265 | * @param object $source |
267 | 266 | */ |
268 | - return apply_filters( 'wc_stripe_generate_payment_request', $post_data, $order, $prepared_source ); |
|
267 | + return apply_filters('wc_stripe_generate_payment_request', $post_data, $order, $prepared_source); |
|
269 | 268 | } |
270 | 269 | |
271 | 270 | /** |
272 | 271 | * Store extra meta data for an order from a Stripe Response. |
273 | 272 | */ |
274 | - public function process_response( $response, $order ) { |
|
275 | - WC_Stripe_Logger::log( 'Processing response: ' . print_r( $response, true ) ); |
|
273 | + public function process_response($response, $order) { |
|
274 | + WC_Stripe_Logger::log('Processing response: ' . print_r($response, true)); |
|
276 | 275 | |
277 | 276 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
278 | 277 | |
279 | - $captured = ( isset( $response->captured ) && $response->captured ) ? 'yes' : 'no'; |
|
278 | + $captured = (isset($response->captured) && $response->captured) ? 'yes' : 'no'; |
|
280 | 279 | |
281 | 280 | // Store charge data. |
282 | - WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, '_stripe_charge_captured', $captured ) : $order->update_meta_data( '_stripe_charge_captured', $captured ); |
|
281 | + WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, '_stripe_charge_captured', $captured) : $order->update_meta_data('_stripe_charge_captured', $captured); |
|
283 | 282 | |
284 | 283 | // Store other data such as fees. |
285 | - if ( isset( $response->balance_transaction ) && isset( $response->balance_transaction->fee ) ) { |
|
284 | + if (isset($response->balance_transaction) && isset($response->balance_transaction->fee)) { |
|
286 | 285 | // Fees and Net needs to both come from Stripe to be accurate as the returned |
287 | 286 | // values are in the local currency of the Stripe account, not from WC. |
288 | - $fee = ! empty( $response->balance_transaction->fee ) ? WC_Stripe_Helper::format_balance_fee( $response->balance_transaction, 'fee' ) : 0; |
|
289 | - $net = ! empty( $response->balance_transaction->net ) ? WC_Stripe_Helper::format_balance_fee( $response->balance_transaction, 'net' ) : 0; |
|
290 | - WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, self::META_NAME_FEE, $fee ) : $order->update_meta_data( self::META_NAME_FEE, $fee ); |
|
291 | - WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, self::META_NAME_NET, $net ) : $order->update_meta_data( self::META_NAME_NET, $net ); |
|
287 | + $fee = ! empty($response->balance_transaction->fee) ? WC_Stripe_Helper::format_balance_fee($response->balance_transaction, 'fee') : 0; |
|
288 | + $net = ! empty($response->balance_transaction->net) ? WC_Stripe_Helper::format_balance_fee($response->balance_transaction, 'net') : 0; |
|
289 | + WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, self::META_NAME_FEE, $fee) : $order->update_meta_data(self::META_NAME_FEE, $fee); |
|
290 | + WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, self::META_NAME_NET, $net) : $order->update_meta_data(self::META_NAME_NET, $net); |
|
292 | 291 | } |
293 | 292 | |
294 | - if ( 'yes' === $captured ) { |
|
293 | + if ('yes' === $captured) { |
|
295 | 294 | /** |
296 | 295 | * Charge can be captured but in a pending state. Payment methods |
297 | 296 | * that are asynchronous may take couple days to clear. Webhook will |
298 | 297 | * take care of the status changes. |
299 | 298 | */ |
300 | - if ( 'pending' === $response->status ) { |
|
301 | - $order_stock_reduced = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_order_stock_reduced', true ) : $order->get_meta( '_order_stock_reduced', true ); |
|
299 | + if ('pending' === $response->status) { |
|
300 | + $order_stock_reduced = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_order_stock_reduced', true) : $order->get_meta('_order_stock_reduced', true); |
|
302 | 301 | |
303 | - if ( ! $order_stock_reduced ) { |
|
304 | - WC_Stripe_Helper::is_pre_30() ? $order->reduce_order_stock() : wc_reduce_stock_levels( $order_id ); |
|
302 | + if ( ! $order_stock_reduced) { |
|
303 | + WC_Stripe_Helper::is_pre_30() ? $order->reduce_order_stock() : wc_reduce_stock_levels($order_id); |
|
305 | 304 | } |
306 | 305 | |
307 | - WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, '_transaction_id', $response->id ) : $order->set_transaction_id( $response->id ); |
|
306 | + WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, '_transaction_id', $response->id) : $order->set_transaction_id($response->id); |
|
308 | 307 | /* translators: transaction id */ |
309 | - $order->update_status( 'on-hold', sprintf( __( 'Stripe charge awaiting payment: %s.', 'woocommerce-gateway-stripe' ), $response->id ) ); |
|
308 | + $order->update_status('on-hold', sprintf(__('Stripe charge awaiting payment: %s.', 'woocommerce-gateway-stripe'), $response->id)); |
|
310 | 309 | } |
311 | 310 | |
312 | - if ( 'succeeded' === $response->status ) { |
|
313 | - $order->payment_complete( $response->id ); |
|
311 | + if ('succeeded' === $response->status) { |
|
312 | + $order->payment_complete($response->id); |
|
314 | 313 | |
315 | 314 | /* translators: transaction id */ |
316 | - $message = sprintf( __( 'Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe' ), $response->id ); |
|
317 | - $order->add_order_note( $message ); |
|
315 | + $message = sprintf(__('Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe'), $response->id); |
|
316 | + $order->add_order_note($message); |
|
318 | 317 | } |
319 | 318 | |
320 | - if ( 'failed' === $response->status ) { |
|
321 | - $localized_message = __( 'Payment processing failed. Please retry.', 'woocommerce-gateway-stripe' ); |
|
322 | - $order->add_order_note( $localized_message ); |
|
323 | - throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message ); |
|
319 | + if ('failed' === $response->status) { |
|
320 | + $localized_message = __('Payment processing failed. Please retry.', 'woocommerce-gateway-stripe'); |
|
321 | + $order->add_order_note($localized_message); |
|
322 | + throw new WC_Stripe_Exception(print_r($response, true), $localized_message); |
|
324 | 323 | } |
325 | 324 | } else { |
326 | - WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, '_transaction_id', $response->id ) : $order->set_transaction_id( $response->id ); |
|
325 | + WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, '_transaction_id', $response->id) : $order->set_transaction_id($response->id); |
|
327 | 326 | |
328 | - if ( $order->has_status( array( 'pending', 'failed' ) ) ) { |
|
329 | - WC_Stripe_Helper::is_pre_30() ? $order->reduce_order_stock() : wc_reduce_stock_levels( $order_id ); |
|
327 | + if ($order->has_status(array('pending', 'failed'))) { |
|
328 | + WC_Stripe_Helper::is_pre_30() ? $order->reduce_order_stock() : wc_reduce_stock_levels($order_id); |
|
330 | 329 | } |
331 | 330 | |
332 | 331 | /* translators: transaction id */ |
333 | - $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 ) ); |
|
332 | + $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)); |
|
334 | 333 | } |
335 | 334 | |
336 | - if ( is_callable( array( $order, 'save' ) ) ) { |
|
335 | + if (is_callable(array($order, 'save'))) { |
|
337 | 336 | $order->save(); |
338 | 337 | } |
339 | 338 | |
340 | - do_action( 'wc_gateway_stripe_process_response', $response, $order ); |
|
339 | + do_action('wc_gateway_stripe_process_response', $response, $order); |
|
341 | 340 | |
342 | 341 | return $response; |
343 | 342 | } |
@@ -350,10 +349,10 @@ discard block |
||
350 | 349 | * @param int $order_id |
351 | 350 | * @return null |
352 | 351 | */ |
353 | - public function send_failed_order_email( $order_id ) { |
|
352 | + public function send_failed_order_email($order_id) { |
|
354 | 353 | $emails = WC()->mailer()->get_emails(); |
355 | - if ( ! empty( $emails ) && ! empty( $order_id ) ) { |
|
356 | - $emails['WC_Email_Failed_Order']->trigger( $order_id ); |
|
354 | + if ( ! empty($emails) && ! empty($order_id)) { |
|
355 | + $emails['WC_Email_Failed_Order']->trigger($order_id); |
|
357 | 356 | } |
358 | 357 | } |
359 | 358 | |
@@ -365,7 +364,7 @@ discard block |
||
365 | 364 | * @param object $order |
366 | 365 | * @return object $details |
367 | 366 | */ |
368 | - public function get_owner_details( $order ) { |
|
367 | + public function get_owner_details($order) { |
|
369 | 368 | $billing_first_name = WC_Stripe_Helper::is_pre_30() ? $order->billing_first_name : $order->get_billing_first_name(); |
370 | 369 | $billing_last_name = WC_Stripe_Helper::is_pre_30() ? $order->billing_last_name : $order->get_billing_last_name(); |
371 | 370 | |
@@ -376,8 +375,8 @@ discard block |
||
376 | 375 | |
377 | 376 | $phone = WC_Stripe_Helper::is_pre_30() ? $order->billing_phone : $order->get_billing_phone(); |
378 | 377 | |
379 | - if ( ! empty( $phone ) ) { |
|
380 | - $details['phone'] = $phone; |
|
378 | + if ( ! empty($phone)) { |
|
379 | + $details['phone'] = $phone; |
|
381 | 380 | } |
382 | 381 | |
383 | 382 | $details['address']['line1'] = WC_Stripe_Helper::is_pre_30() ? $order->billing_address_1 : $order->get_billing_address_1(); |
@@ -387,7 +386,7 @@ discard block |
||
387 | 386 | $details['address']['postal_code'] = WC_Stripe_Helper::is_pre_30() ? $order->billing_postcode : $order->get_billing_postcode(); |
388 | 387 | $details['address']['country'] = WC_Stripe_Helper::is_pre_30() ? $order->billing_country : $order->get_billing_country(); |
389 | 388 | |
390 | - return (object) apply_filters( 'wc_stripe_owner_details', $details, $order ); |
|
389 | + return (object) apply_filters('wc_stripe_owner_details', $details, $order); |
|
391 | 390 | } |
392 | 391 | |
393 | 392 | /** |
@@ -396,15 +395,15 @@ discard block |
||
396 | 395 | * @since 4.0.3 |
397 | 396 | * @param string $source_id The source ID to get source object for. |
398 | 397 | */ |
399 | - public function get_source_object( $source_id = '' ) { |
|
400 | - if ( empty( $source_id ) ) { |
|
398 | + public function get_source_object($source_id = '') { |
|
399 | + if (empty($source_id)) { |
|
401 | 400 | return ''; |
402 | 401 | } |
403 | 402 | |
404 | - $source_object = WC_Stripe_API::retrieve( 'sources/' . $source_id ); |
|
403 | + $source_object = WC_Stripe_API::retrieve('sources/' . $source_id); |
|
405 | 404 | |
406 | - if ( ! empty( $source_object->error ) ) { |
|
407 | - throw new WC_Stripe_Exception( print_r( $source_object, true ), $source_object->error->message ); |
|
405 | + if ( ! empty($source_object->error)) { |
|
406 | + throw new WC_Stripe_Exception(print_r($source_object, true), $source_object->error->message); |
|
408 | 407 | } |
409 | 408 | |
410 | 409 | return $source_object; |
@@ -417,11 +416,11 @@ discard block |
||
417 | 416 | * @param object $source_object |
418 | 417 | * @return bool |
419 | 418 | */ |
420 | - public function is_3ds_required( $source_object ) { |
|
419 | + public function is_3ds_required($source_object) { |
|
421 | 420 | return ( |
422 | - $source_object && ! empty( $source_object->card ) ) && |
|
423 | - ( 'card' === $source_object->type && 'required' === $source_object->card->three_d_secure || |
|
424 | - ( $this->three_d_secure && 'optional' === $source_object->card->three_d_secure ) |
|
421 | + $source_object && ! empty($source_object->card) ) && |
|
422 | + ('card' === $source_object->type && 'required' === $source_object->card->three_d_secure || |
|
423 | + ($this->three_d_secure && 'optional' === $source_object->card->three_d_secure) |
|
425 | 424 | ); |
426 | 425 | } |
427 | 426 | |
@@ -432,8 +431,8 @@ discard block |
||
432 | 431 | * @param object $source_object |
433 | 432 | * @return bool |
434 | 433 | */ |
435 | - public function is_3ds_card( $source_object ) { |
|
436 | - return ( $source_object && 'three_d_secure' === $source_object->type ); |
|
434 | + public function is_3ds_card($source_object) { |
|
435 | + return ($source_object && 'three_d_secure' === $source_object->type); |
|
437 | 436 | } |
438 | 437 | |
439 | 438 | /** |
@@ -443,8 +442,8 @@ discard block |
||
443 | 442 | * @param object $source_object |
444 | 443 | * @return bool |
445 | 444 | */ |
446 | - public function is_prepaid_card( $source_object ) { |
|
447 | - return ( $source_object && 'token' === $source_object->object && 'prepaid' === $source_object->card->funding ); |
|
445 | + public function is_prepaid_card($source_object) { |
|
446 | + return ($source_object && 'token' === $source_object->object && 'prepaid' === $source_object->card->funding); |
|
448 | 447 | } |
449 | 448 | |
450 | 449 | /** |
@@ -457,22 +456,22 @@ discard block |
||
457 | 456 | * @param string $return_url |
458 | 457 | * @return mixed |
459 | 458 | */ |
460 | - public function create_3ds_source( $order, $source_object, $return_url = '' ) { |
|
459 | + public function create_3ds_source($order, $source_object, $return_url = '') { |
|
461 | 460 | $currency = WC_Stripe_Helper::is_pre_30() ? $order->get_order_currency() : $order->get_currency(); |
462 | 461 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
463 | - $return_url = empty( $return_url ) ? $this->get_stripe_return_url( $order ) : $return_url; |
|
462 | + $return_url = empty($return_url) ? $this->get_stripe_return_url($order) : $return_url; |
|
464 | 463 | |
465 | 464 | $post_data = array(); |
466 | - $post_data['amount'] = WC_Stripe_Helper::get_stripe_amount( $order->get_total(), $currency ); |
|
467 | - $post_data['currency'] = strtolower( $currency ); |
|
465 | + $post_data['amount'] = WC_Stripe_Helper::get_stripe_amount($order->get_total(), $currency); |
|
466 | + $post_data['currency'] = strtolower($currency); |
|
468 | 467 | $post_data['type'] = 'three_d_secure'; |
469 | - $post_data['owner'] = $this->get_owner_details( $order ); |
|
470 | - $post_data['three_d_secure'] = array( 'card' => $source_object->id ); |
|
471 | - $post_data['redirect'] = array( 'return_url' => $return_url ); |
|
468 | + $post_data['owner'] = $this->get_owner_details($order); |
|
469 | + $post_data['three_d_secure'] = array('card' => $source_object->id); |
|
470 | + $post_data['redirect'] = array('return_url' => $return_url); |
|
472 | 471 | |
473 | - WC_Stripe_Logger::log( 'Info: Begin creating 3DS source...' ); |
|
472 | + WC_Stripe_Logger::log('Info: Begin creating 3DS source...'); |
|
474 | 473 | |
475 | - return WC_Stripe_API::request( apply_filters( 'wc_stripe_3ds_source', $post_data, $order ), 'sources' ); |
|
474 | + return WC_Stripe_API::request(apply_filters('wc_stripe_3ds_source', $post_data, $order), 'sources'); |
|
476 | 475 | } |
477 | 476 | |
478 | 477 | /** |
@@ -488,56 +487,56 @@ discard block |
||
488 | 487 | * @throws Exception When card was not added or for and invalid card. |
489 | 488 | * @return object |
490 | 489 | */ |
491 | - public function prepare_source( $user_id, $force_save_source = false ) { |
|
492 | - $customer = new WC_Stripe_Customer( $user_id ); |
|
490 | + public function prepare_source($user_id, $force_save_source = false) { |
|
491 | + $customer = new WC_Stripe_Customer($user_id); |
|
493 | 492 | $set_customer = true; |
494 | - $force_save_source = apply_filters( 'wc_stripe_force_save_source', $force_save_source, $customer ); |
|
493 | + $force_save_source = apply_filters('wc_stripe_force_save_source', $force_save_source, $customer); |
|
495 | 494 | $source_object = ''; |
496 | 495 | $source_id = ''; |
497 | 496 | $wc_token_id = false; |
498 | - $payment_method = isset( $_POST['payment_method'] ) ? wc_clean( $_POST['payment_method'] ) : 'stripe'; |
|
497 | + $payment_method = isset($_POST['payment_method']) ? wc_clean($_POST['payment_method']) : 'stripe'; |
|
499 | 498 | |
500 | 499 | // New CC info was entered and we have a new source to process. |
501 | - if ( ! empty( $_POST['stripe_source'] ) ) { |
|
502 | - $source_object = self::get_source_object( wc_clean( $_POST['stripe_source'] ) ); |
|
500 | + if ( ! empty($_POST['stripe_source'])) { |
|
501 | + $source_object = self::get_source_object(wc_clean($_POST['stripe_source'])); |
|
503 | 502 | $source_id = $source_object->id; |
504 | 503 | |
505 | 504 | // This checks to see if customer opted to save the payment method to file. |
506 | - $maybe_saved_card = isset( $_POST[ 'wc-' . $payment_method . '-new-payment-method' ] ) && ! empty( $_POST[ 'wc-' . $payment_method . '-new-payment-method' ] ); |
|
505 | + $maybe_saved_card = isset($_POST['wc-' . $payment_method . '-new-payment-method']) && ! empty($_POST['wc-' . $payment_method . '-new-payment-method']); |
|
507 | 506 | |
508 | 507 | /** |
509 | 508 | * This is true if the user wants to store the card to their account. |
510 | 509 | * Criteria to save to file is they are logged in, they opted to save or product requirements and the source is |
511 | 510 | * actually reusable. Either that or force_save_source is true. |
512 | 511 | */ |
513 | - if ( ( $user_id && $this->saved_cards && $maybe_saved_card && 'reusable' === $source_object->usage ) || $force_save_source ) { |
|
514 | - $response = $customer->add_source( $source_object->id ); |
|
512 | + if (($user_id && $this->saved_cards && $maybe_saved_card && 'reusable' === $source_object->usage) || $force_save_source) { |
|
513 | + $response = $customer->add_source($source_object->id); |
|
515 | 514 | |
516 | - if ( ! empty( $response->error ) ) { |
|
517 | - throw new WC_Stripe_Exception( print_r( $response, true ), $response->error->message ); |
|
515 | + if ( ! empty($response->error)) { |
|
516 | + throw new WC_Stripe_Exception(print_r($response, true), $response->error->message); |
|
518 | 517 | } |
519 | 518 | } |
520 | - } elseif ( isset( $_POST[ 'wc-' . $payment_method . '-payment-token' ] ) && 'new' !== $_POST[ 'wc-' . $payment_method . '-payment-token' ] ) { |
|
519 | + } elseif (isset($_POST['wc-' . $payment_method . '-payment-token']) && 'new' !== $_POST['wc-' . $payment_method . '-payment-token']) { |
|
521 | 520 | // Use an existing token, and then process the payment. |
522 | - $wc_token_id = wc_clean( $_POST[ 'wc-' . $payment_method . '-payment-token' ] ); |
|
523 | - $wc_token = WC_Payment_Tokens::get( $wc_token_id ); |
|
521 | + $wc_token_id = wc_clean($_POST['wc-' . $payment_method . '-payment-token']); |
|
522 | + $wc_token = WC_Payment_Tokens::get($wc_token_id); |
|
524 | 523 | |
525 | - if ( ! $wc_token || $wc_token->get_user_id() !== get_current_user_id() ) { |
|
526 | - WC()->session->set( 'refresh_totals', true ); |
|
527 | - throw new WC_Stripe_Exception( 'Invalid payment method', __( 'Invalid payment method. Please input a new card number.', 'woocommerce-gateway-stripe' ) ); |
|
524 | + if ( ! $wc_token || $wc_token->get_user_id() !== get_current_user_id()) { |
|
525 | + WC()->session->set('refresh_totals', true); |
|
526 | + throw new WC_Stripe_Exception('Invalid payment method', __('Invalid payment method. Please input a new card number.', 'woocommerce-gateway-stripe')); |
|
528 | 527 | } |
529 | 528 | |
530 | 529 | $source_id = $wc_token->get_token(); |
531 | - } elseif ( isset( $_POST['stripe_token'] ) && 'new' !== $_POST['stripe_token'] ) { |
|
532 | - $stripe_token = wc_clean( $_POST['stripe_token'] ); |
|
533 | - $maybe_saved_card = isset( $_POST[ 'wc-' . $payment_method . '-new-payment-method' ] ) && ! empty( $_POST[ 'wc-' . $payment_method . '-new-payment-method' ] ); |
|
530 | + } elseif (isset($_POST['stripe_token']) && 'new' !== $_POST['stripe_token']) { |
|
531 | + $stripe_token = wc_clean($_POST['stripe_token']); |
|
532 | + $maybe_saved_card = isset($_POST['wc-' . $payment_method . '-new-payment-method']) && ! empty($_POST['wc-' . $payment_method . '-new-payment-method']); |
|
534 | 533 | |
535 | 534 | // This is true if the user wants to store the card to their account. |
536 | - if ( ( $user_id && $this->saved_cards && $maybe_saved_card ) || $force_save_source ) { |
|
537 | - $response = $customer->add_source( $stripe_token ); |
|
535 | + if (($user_id && $this->saved_cards && $maybe_saved_card) || $force_save_source) { |
|
536 | + $response = $customer->add_source($stripe_token); |
|
538 | 537 | |
539 | - if ( ! empty( $response->error ) ) { |
|
540 | - throw new WC_Stripe_Exception( print_r( $response, true ), $response->error->message ); |
|
538 | + if ( ! empty($response->error)) { |
|
539 | + throw new WC_Stripe_Exception(print_r($response, true), $response->error->message); |
|
541 | 540 | } |
542 | 541 | } else { |
543 | 542 | $set_customer = false; |
@@ -545,14 +544,14 @@ discard block |
||
545 | 544 | } |
546 | 545 | } |
547 | 546 | |
548 | - if ( ! $set_customer ) { |
|
547 | + if ( ! $set_customer) { |
|
549 | 548 | $customer_id = false; |
550 | 549 | } else { |
551 | 550 | $customer_id = $customer->get_id() ? $customer->get_id() : false; |
552 | 551 | } |
553 | 552 | |
554 | - if ( empty( $source_object ) ) { |
|
555 | - $source_object = self::get_source_object( $source_id ); |
|
553 | + if (empty($source_object)) { |
|
554 | + $source_object = self::get_source_object($source_id); |
|
556 | 555 | } |
557 | 556 | |
558 | 557 | return (object) array( |
@@ -576,37 +575,37 @@ discard block |
||
576 | 575 | * @param object $order |
577 | 576 | * @return object |
578 | 577 | */ |
579 | - public function prepare_order_source( $order = null ) { |
|
578 | + public function prepare_order_source($order = null) { |
|
580 | 579 | $stripe_customer = new WC_Stripe_Customer(); |
581 | 580 | $stripe_source = false; |
582 | 581 | $token_id = false; |
583 | 582 | |
584 | - if ( $order ) { |
|
583 | + if ($order) { |
|
585 | 584 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
586 | 585 | |
587 | - $stripe_customer_id = get_post_meta( $order_id, '_stripe_customer_id', true ); |
|
586 | + $stripe_customer_id = get_post_meta($order_id, '_stripe_customer_id', true); |
|
588 | 587 | |
589 | - if ( $stripe_customer_id ) { |
|
590 | - $stripe_customer->set_id( $stripe_customer_id ); |
|
588 | + if ($stripe_customer_id) { |
|
589 | + $stripe_customer->set_id($stripe_customer_id); |
|
591 | 590 | } |
592 | 591 | |
593 | - $source_id = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_stripe_source_id', true ) : $order->get_meta( '_stripe_source_id', true ); |
|
592 | + $source_id = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_stripe_source_id', true) : $order->get_meta('_stripe_source_id', true); |
|
594 | 593 | |
595 | 594 | // Since 4.0.0, we changed card to source so we need to account for that. |
596 | - if ( empty( $source_id ) ) { |
|
597 | - $source_id = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_stripe_card_id', true ) : $order->get_meta( '_stripe_card_id', true ); |
|
595 | + if (empty($source_id)) { |
|
596 | + $source_id = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_stripe_card_id', true) : $order->get_meta('_stripe_card_id', true); |
|
598 | 597 | |
599 | 598 | // Take this opportunity to update the key name. |
600 | - WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, '_stripe_source_id', $source_id ) : $order->update_meta_data( '_stripe_source_id', $source_id ); |
|
599 | + WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, '_stripe_source_id', $source_id) : $order->update_meta_data('_stripe_source_id', $source_id); |
|
601 | 600 | |
602 | - if ( is_callable( array( $order, 'save' ) ) ) { |
|
601 | + if (is_callable(array($order, 'save'))) { |
|
603 | 602 | $order->save(); |
604 | 603 | } |
605 | 604 | } |
606 | 605 | |
607 | - if ( $source_id ) { |
|
606 | + if ($source_id) { |
|
608 | 607 | $stripe_source = $source_id; |
609 | - } elseif ( apply_filters( 'wc_stripe_use_default_customer_source', true ) ) { |
|
608 | + } elseif (apply_filters('wc_stripe_use_default_customer_source', true)) { |
|
610 | 609 | /* |
611 | 610 | * We can attempt to charge the customer's default source |
612 | 611 | * by sending empty source id. |
@@ -630,27 +629,27 @@ discard block |
||
630 | 629 | * @param WC_Order $order For to which the source applies. |
631 | 630 | * @param stdClass $source Source information. |
632 | 631 | */ |
633 | - public function save_source_to_order( $order, $source ) { |
|
632 | + public function save_source_to_order($order, $source) { |
|
634 | 633 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
635 | 634 | |
636 | 635 | // Store source in the order. |
637 | - if ( $source->customer ) { |
|
638 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
639 | - update_post_meta( $order_id, '_stripe_customer_id', $source->customer ); |
|
636 | + if ($source->customer) { |
|
637 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
638 | + update_post_meta($order_id, '_stripe_customer_id', $source->customer); |
|
640 | 639 | } else { |
641 | - $order->update_meta_data( '_stripe_customer_id', $source->customer ); |
|
640 | + $order->update_meta_data('_stripe_customer_id', $source->customer); |
|
642 | 641 | } |
643 | 642 | } |
644 | 643 | |
645 | - if ( $source->source ) { |
|
646 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
647 | - update_post_meta( $order_id, '_stripe_source_id', $source->source ); |
|
644 | + if ($source->source) { |
|
645 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
646 | + update_post_meta($order_id, '_stripe_source_id', $source->source); |
|
648 | 647 | } else { |
649 | - $order->update_meta_data( '_stripe_source_id', $source->source ); |
|
648 | + $order->update_meta_data('_stripe_source_id', $source->source); |
|
650 | 649 | } |
651 | 650 | } |
652 | 651 | |
653 | - if ( is_callable( array( $order, 'save' ) ) ) { |
|
652 | + if (is_callable(array($order, 'save'))) { |
|
654 | 653 | $order->save(); |
655 | 654 | } |
656 | 655 | } |
@@ -664,35 +663,35 @@ discard block |
||
664 | 663 | * @param object $order The order object |
665 | 664 | * @param int $balance_transaction_id |
666 | 665 | */ |
667 | - public function update_fees( $order, $balance_transaction_id ) { |
|
666 | + public function update_fees($order, $balance_transaction_id) { |
|
668 | 667 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
669 | 668 | |
670 | - $balance_transaction = WC_Stripe_API::retrieve( 'balance/history/' . $balance_transaction_id ); |
|
669 | + $balance_transaction = WC_Stripe_API::retrieve('balance/history/' . $balance_transaction_id); |
|
671 | 670 | |
672 | - if ( empty( $balance_transaction->error ) ) { |
|
673 | - if ( isset( $balance_transaction ) && isset( $balance_transaction->fee ) ) { |
|
671 | + if (empty($balance_transaction->error)) { |
|
672 | + if (isset($balance_transaction) && isset($balance_transaction->fee)) { |
|
674 | 673 | // Fees and Net needs to both come from Stripe to be accurate as the returned |
675 | 674 | // values are in the local currency of the Stripe account, not from WC. |
676 | - $fee_refund = ! empty( $balance_transaction->fee ) ? WC_Stripe_Helper::format_balance_fee( $balance_transaction, 'fee' ) : 0; |
|
677 | - $net_refund = ! empty( $balance_transaction->net ) ? WC_Stripe_Helper::format_balance_fee( $balance_transaction, 'net' ) : 0; |
|
675 | + $fee_refund = ! empty($balance_transaction->fee) ? WC_Stripe_Helper::format_balance_fee($balance_transaction, 'fee') : 0; |
|
676 | + $net_refund = ! empty($balance_transaction->net) ? WC_Stripe_Helper::format_balance_fee($balance_transaction, 'net') : 0; |
|
678 | 677 | |
679 | 678 | // Current data fee & net. |
680 | - $fee_current = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, self::META_NAME_FEE, true ) : $order->get_meta( self::META_NAME_FEE, true ); |
|
681 | - $net_current = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, self::META_NAME_NET, true ) : $order->get_meta( self::META_NAME_NET, true ); |
|
679 | + $fee_current = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, self::META_NAME_FEE, true) : $order->get_meta(self::META_NAME_FEE, true); |
|
680 | + $net_current = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, self::META_NAME_NET, true) : $order->get_meta(self::META_NAME_NET, true); |
|
682 | 681 | |
683 | 682 | // Calculation. |
684 | 683 | $fee = (float) $fee_current + (float) $fee_refund; |
685 | 684 | $net = (float) $net_current + (float) $net_refund; |
686 | 685 | |
687 | - WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, self::META_NAME_FEE, $fee ) : $order->update_meta_data( self::META_NAME_FEE, $fee ); |
|
688 | - WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, self::META_NAME_NET, $net ) : $order->update_meta_data( self::META_NAME_NET, $net ); |
|
686 | + WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, self::META_NAME_FEE, $fee) : $order->update_meta_data(self::META_NAME_FEE, $fee); |
|
687 | + WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, self::META_NAME_NET, $net) : $order->update_meta_data(self::META_NAME_NET, $net); |
|
689 | 688 | |
690 | - if ( is_callable( array( $order, 'save' ) ) ) { |
|
689 | + if (is_callable(array($order, 'save'))) { |
|
691 | 690 | $order->save(); |
692 | 691 | } |
693 | 692 | } |
694 | 693 | } else { |
695 | - WC_Stripe_Logger::log( "Unable to update fees/net meta for order: {$order_id}" ); |
|
694 | + WC_Stripe_Logger::log("Unable to update fees/net meta for order: {$order_id}"); |
|
696 | 695 | } |
697 | 696 | } |
698 | 697 | |
@@ -705,33 +704,33 @@ discard block |
||
705 | 704 | * @param float $amount |
706 | 705 | * @return bool |
707 | 706 | */ |
708 | - public function process_refund( $order_id, $amount = null, $reason = '' ) { |
|
709 | - $order = wc_get_order( $order_id ); |
|
707 | + public function process_refund($order_id, $amount = null, $reason = '') { |
|
708 | + $order = wc_get_order($order_id); |
|
710 | 709 | |
711 | - if ( ! $order || ! $order->get_transaction_id() ) { |
|
710 | + if ( ! $order || ! $order->get_transaction_id()) { |
|
712 | 711 | return false; |
713 | 712 | } |
714 | 713 | |
715 | 714 | $request = array(); |
716 | 715 | |
717 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
718 | - $order_currency = get_post_meta( $order_id, '_order_currency', true ); |
|
719 | - $captured = get_post_meta( $order_id, '_stripe_charge_captured', true ); |
|
716 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
717 | + $order_currency = get_post_meta($order_id, '_order_currency', true); |
|
718 | + $captured = get_post_meta($order_id, '_stripe_charge_captured', true); |
|
720 | 719 | } else { |
721 | 720 | $order_currency = $order->get_currency(); |
722 | - $captured = $order->get_meta( '_stripe_charge_captured', true ); |
|
721 | + $captured = $order->get_meta('_stripe_charge_captured', true); |
|
723 | 722 | } |
724 | 723 | |
725 | - if ( ! is_null( $amount ) ) { |
|
726 | - $request['amount'] = WC_Stripe_Helper::get_stripe_amount( $amount, $order_currency ); |
|
724 | + if ( ! is_null($amount)) { |
|
725 | + $request['amount'] = WC_Stripe_Helper::get_stripe_amount($amount, $order_currency); |
|
727 | 726 | } |
728 | 727 | |
729 | 728 | // If order is only authorized, don't pass amount. |
730 | - if ( 'yes' !== $captured ) { |
|
731 | - unset( $request['amount'] ); |
|
729 | + if ('yes' !== $captured) { |
|
730 | + unset($request['amount']); |
|
732 | 731 | } |
733 | 732 | |
734 | - if ( $reason ) { |
|
733 | + if ($reason) { |
|
735 | 734 | $request['metadata'] = array( |
736 | 735 | 'reason' => $reason, |
737 | 736 | ); |
@@ -739,35 +738,35 @@ discard block |
||
739 | 738 | |
740 | 739 | $request['charge'] = $order->get_transaction_id(); |
741 | 740 | |
742 | - WC_Stripe_Logger::log( "Info: Beginning refund for order {$order->get_transaction_id()} for the amount of {$amount}" ); |
|
741 | + WC_Stripe_Logger::log("Info: Beginning refund for order {$order->get_transaction_id()} for the amount of {$amount}"); |
|
743 | 742 | |
744 | - $request = apply_filters( 'wc_stripe_refund_request', $request, $order ); |
|
743 | + $request = apply_filters('wc_stripe_refund_request', $request, $order); |
|
745 | 744 | |
746 | - $response = WC_Stripe_API::request( $request, 'refunds' ); |
|
745 | + $response = WC_Stripe_API::request($request, 'refunds'); |
|
747 | 746 | |
748 | - if ( ! empty( $response->error ) ) { |
|
749 | - WC_Stripe_Logger::log( 'Error: ' . $response->error->message ); |
|
747 | + if ( ! empty($response->error)) { |
|
748 | + WC_Stripe_Logger::log('Error: ' . $response->error->message); |
|
750 | 749 | |
751 | 750 | return $response; |
752 | 751 | |
753 | - } elseif ( ! empty( $response->id ) ) { |
|
754 | - WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, '_stripe_refund_id', $response->id ) : $order->update_meta_data( '_stripe_refund_id', $response->id ); |
|
752 | + } elseif ( ! empty($response->id)) { |
|
753 | + WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, '_stripe_refund_id', $response->id) : $order->update_meta_data('_stripe_refund_id', $response->id); |
|
755 | 754 | |
756 | - $amount = wc_price( $response->amount / 100 ); |
|
755 | + $amount = wc_price($response->amount / 100); |
|
757 | 756 | |
758 | - if ( in_array( strtolower( $order->get_currency() ), WC_Stripe_Helper::no_decimal_currencies() ) ) { |
|
759 | - $amount = wc_price( $response->amount ); |
|
757 | + if (in_array(strtolower($order->get_currency()), WC_Stripe_Helper::no_decimal_currencies())) { |
|
758 | + $amount = wc_price($response->amount); |
|
760 | 759 | } |
761 | 760 | |
762 | - if ( isset( $response->balance_transaction ) ) { |
|
763 | - $this->update_fees( $order, $response->balance_transaction ); |
|
761 | + if (isset($response->balance_transaction)) { |
|
762 | + $this->update_fees($order, $response->balance_transaction); |
|
764 | 763 | } |
765 | 764 | |
766 | 765 | /* translators: 1) dollar amount 2) transaction id 3) refund message */ |
767 | - $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' ); |
|
766 | + $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'); |
|
768 | 767 | |
769 | - $order->add_order_note( $refund_message ); |
|
770 | - WC_Stripe_Logger::log( 'Success: ' . html_entity_decode( strip_tags( $refund_message ) ) ); |
|
768 | + $order->add_order_note($refund_message); |
|
769 | + WC_Stripe_Logger::log('Success: ' . html_entity_decode(strip_tags($refund_message))); |
|
771 | 770 | |
772 | 771 | return true; |
773 | 772 | } |
@@ -782,44 +781,44 @@ discard block |
||
782 | 781 | */ |
783 | 782 | public function add_payment_method() { |
784 | 783 | $error = false; |
785 | - $error_msg = __( 'There was a problem adding the card.', 'woocommerce-gateway-stripe' ); |
|
784 | + $error_msg = __('There was a problem adding the card.', 'woocommerce-gateway-stripe'); |
|
786 | 785 | $source_id = ''; |
787 | 786 | |
788 | - if ( empty( $_POST['stripe_source'] ) && empty( $_POST['stripe_token'] ) || ! is_user_logged_in() ) { |
|
787 | + if (empty($_POST['stripe_source']) && empty($_POST['stripe_token']) || ! is_user_logged_in()) { |
|
789 | 788 | $error = true; |
790 | 789 | } |
791 | 790 | |
792 | - $stripe_customer = new WC_Stripe_Customer( get_current_user_id() ); |
|
791 | + $stripe_customer = new WC_Stripe_Customer(get_current_user_id()); |
|
793 | 792 | |
794 | - $source = ! empty( $_POST['stripe_source'] ) ? wc_clean( $_POST['stripe_source'] ) : ''; |
|
793 | + $source = ! empty($_POST['stripe_source']) ? wc_clean($_POST['stripe_source']) : ''; |
|
795 | 794 | |
796 | - $source_object = WC_Stripe_API::retrieve( 'sources/' . $source ); |
|
795 | + $source_object = WC_Stripe_API::retrieve('sources/' . $source); |
|
797 | 796 | |
798 | - if ( isset( $source_object ) ) { |
|
799 | - if ( ! empty( $source_object->error ) ) { |
|
797 | + if (isset($source_object)) { |
|
798 | + if ( ! empty($source_object->error)) { |
|
800 | 799 | $error = true; |
801 | 800 | } |
802 | 801 | |
803 | 802 | $source_id = $source_object->id; |
804 | - } elseif ( isset( $_POST['stripe_token'] ) ) { |
|
805 | - $source_id = wc_clean( $_POST['stripe_token'] ); |
|
803 | + } elseif (isset($_POST['stripe_token'])) { |
|
804 | + $source_id = wc_clean($_POST['stripe_token']); |
|
806 | 805 | } |
807 | 806 | |
808 | - $response = $stripe_customer->add_source( $source_id ); |
|
807 | + $response = $stripe_customer->add_source($source_id); |
|
809 | 808 | |
810 | - if ( ! $response || is_wp_error( $response ) || ! empty( $response->error ) ) { |
|
809 | + if ( ! $response || is_wp_error($response) || ! empty($response->error)) { |
|
811 | 810 | $error = true; |
812 | 811 | } |
813 | 812 | |
814 | - if ( $error ) { |
|
815 | - wc_add_notice( $error_msg, 'error' ); |
|
816 | - WC_Stripe_Logger::log( 'Add payment method Error: ' . $error_msg ); |
|
813 | + if ($error) { |
|
814 | + wc_add_notice($error_msg, 'error'); |
|
815 | + WC_Stripe_Logger::log('Add payment method Error: ' . $error_msg); |
|
817 | 816 | return; |
818 | 817 | } |
819 | 818 | |
820 | 819 | return array( |
821 | 820 | 'result' => 'success', |
822 | - 'redirect' => wc_get_endpoint_url( 'payment-methods' ), |
|
821 | + 'redirect' => wc_get_endpoint_url('payment-methods'), |
|
823 | 822 | ); |
824 | 823 | } |
825 | 824 | |
@@ -836,10 +835,10 @@ discard block |
||
836 | 835 | * Stripe expects Norwegian to only be passed NO. |
837 | 836 | * But WP has different dialects. |
838 | 837 | */ |
839 | - if ( 'NO' === substr( $locale, 3, 2 ) ) { |
|
838 | + if ('NO' === substr($locale, 3, 2)) { |
|
840 | 839 | $locale = 'no'; |
841 | 840 | } else { |
842 | - $locale = substr( get_locale(), 0, 2 ); |
|
841 | + $locale = substr(get_locale(), 0, 2); |
|
843 | 842 | } |
844 | 843 | |
845 | 844 | return $locale; |
@@ -853,9 +852,9 @@ discard block |
||
853 | 852 | * @param string $idempotency_key |
854 | 853 | * @param array $request |
855 | 854 | */ |
856 | - public function change_idempotency_key( $idempotency_key, $request ) { |
|
857 | - $customer = ! empty( $request['customer'] ) ? $request['customer'] : ''; |
|
858 | - $source = ! empty( $request['source'] ) ? $request['source'] : $customer; |
|
855 | + public function change_idempotency_key($idempotency_key, $request) { |
|
856 | + $customer = ! empty($request['customer']) ? $request['customer'] : ''; |
|
857 | + $source = ! empty($request['source']) ? $request['source'] : $customer; |
|
859 | 858 | $count = $this->retry_interval; |
860 | 859 | |
861 | 860 | return $request['metadata']['order_id'] . '-' . $count . '-' . $source; |
@@ -869,8 +868,8 @@ discard block |
||
869 | 868 | * @since 4.0.6 |
870 | 869 | * @param array $headers |
871 | 870 | */ |
872 | - public function is_original_request( $headers ) { |
|
873 | - if ( $headers['original-request'] === $headers['request-id'] ) { |
|
871 | + public function is_original_request($headers) { |
|
872 | + if ($headers['original-request'] === $headers['request-id']) { |
|
874 | 873 | return true; |
875 | 874 | } |
876 | 875 |
@@ -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,11 +97,11 @@ 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 = []; |
102 | - foreach ( $_SERVER as $name => $value ) { |
|
103 | - if ( 'HTTP_' === substr( $name, 0, 5 ) ) { |
|
104 | - $headers[ str_replace( ' ', '-', ucwords( strtolower( str_replace( '_', ' ', substr( $name, 5 ) ) ) ) ) ] = $value; |
|
102 | + foreach ($_SERVER as $name => $value) { |
|
103 | + if ('HTTP_' === substr($name, 0, 5)) { |
|
104 | + $headers[str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', substr($name, 5)))))] = $value; |
|
105 | 105 | } |
106 | 106 | } |
107 | 107 | |
@@ -120,30 +120,30 @@ discard block |
||
120 | 120 | * @param object $notification |
121 | 121 | * @param bool $retry |
122 | 122 | */ |
123 | - public function process_webhook_payment( $notification, $retry = true ) { |
|
123 | + public function process_webhook_payment($notification, $retry = true) { |
|
124 | 124 | // The following 2 payment methods are synchronous so does not need to be handle via webhook. |
125 | - if ( 'card' === $notification->data->object->type || 'sepa_debit' === $notification->data->object->type ) { |
|
125 | + if ('card' === $notification->data->object->type || 'sepa_debit' === $notification->data->object->type) { |
|
126 | 126 | return; |
127 | 127 | } |
128 | 128 | |
129 | - $order = WC_Stripe_Helper::get_order_by_source_id( $notification->data->object->id ); |
|
129 | + $order = WC_Stripe_Helper::get_order_by_source_id($notification->data->object->id); |
|
130 | 130 | |
131 | - if ( ! $order ) { |
|
132 | - WC_Stripe_Logger::log( 'Could not find order via source ID: ' . $notification->data->object->id ); |
|
131 | + if ( ! $order) { |
|
132 | + WC_Stripe_Logger::log('Could not find order via source ID: ' . $notification->data->object->id); |
|
133 | 133 | return; |
134 | 134 | } |
135 | 135 | |
136 | 136 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
137 | 137 | $source_id = $notification->data->object->id; |
138 | 138 | |
139 | - $is_pending_receiver = ( 'receiver' === $notification->data->object->flow ); |
|
139 | + $is_pending_receiver = ('receiver' === $notification->data->object->flow); |
|
140 | 140 | |
141 | 141 | try { |
142 | - if ( 'processing' === $order->get_status() || 'completed' === $order->get_status() ) { |
|
142 | + if ('processing' === $order->get_status() || 'completed' === $order->get_status()) { |
|
143 | 143 | return; |
144 | 144 | } |
145 | 145 | |
146 | - if ( 'on-hold' === $order->get_status() && ! $is_pending_receiver ) { |
|
146 | + if ('on-hold' === $order->get_status() && ! $is_pending_receiver) { |
|
147 | 147 | return; |
148 | 148 | } |
149 | 149 | |
@@ -151,95 +151,95 @@ discard block |
||
151 | 151 | $response = null; |
152 | 152 | |
153 | 153 | // This will throw exception if not valid. |
154 | - $this->validate_minimum_order_amount( $order ); |
|
154 | + $this->validate_minimum_order_amount($order); |
|
155 | 155 | |
156 | - WC_Stripe_Logger::log( "Info: (Webhook) Begin processing payment for order $order_id for the amount of {$order->get_total()}" ); |
|
156 | + WC_Stripe_Logger::log("Info: (Webhook) Begin processing payment for order $order_id for the amount of {$order->get_total()}"); |
|
157 | 157 | |
158 | 158 | // Prep source object. |
159 | 159 | $source_object = new stdClass(); |
160 | 160 | $source_object->token_id = ''; |
161 | - $source_object->customer = $this->get_stripe_customer_id( $order ); |
|
161 | + $source_object->customer = $this->get_stripe_customer_id($order); |
|
162 | 162 | $source_object->source = $source_id; |
163 | 163 | |
164 | 164 | // Make the request. |
165 | - $response = WC_Stripe_API::request( $this->generate_payment_request( $order, $source_object ), 'charges', 'POST', true ); |
|
165 | + $response = WC_Stripe_API::request($this->generate_payment_request($order, $source_object), 'charges', 'POST', true); |
|
166 | 166 | $headers = $response['headers']; |
167 | 167 | $response = $response['body']; |
168 | 168 | |
169 | - if ( ! empty( $response->error ) ) { |
|
169 | + if ( ! empty($response->error)) { |
|
170 | 170 | // We want to retry. |
171 | - if ( $this->is_retryable_error( $response->error ) ) { |
|
172 | - if ( $retry ) { |
|
171 | + if ($this->is_retryable_error($response->error)) { |
|
172 | + if ($retry) { |
|
173 | 173 | // Don't do anymore retries after this. |
174 | - if ( 5 <= $this->retry_interval ) { |
|
174 | + if (5 <= $this->retry_interval) { |
|
175 | 175 | |
176 | - return $this->process_webhook_payment( $notification, false ); |
|
176 | + return $this->process_webhook_payment($notification, false); |
|
177 | 177 | } |
178 | 178 | |
179 | - sleep( $this->retry_interval ); |
|
179 | + sleep($this->retry_interval); |
|
180 | 180 | |
181 | 181 | $this->retry_interval++; |
182 | - return $this->process_webhook_payment( $notification, true ); |
|
182 | + return $this->process_webhook_payment($notification, true); |
|
183 | 183 | } else { |
184 | - $localized_message = __( 'On going requests error and retries exhausted.', 'woocommerce-gateway-stripe' ); |
|
185 | - $order->add_order_note( $localized_message ); |
|
186 | - throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message ); |
|
184 | + $localized_message = __('On going requests error and retries exhausted.', 'woocommerce-gateway-stripe'); |
|
185 | + $order->add_order_note($localized_message); |
|
186 | + throw new WC_Stripe_Exception(print_r($response, true), $localized_message); |
|
187 | 187 | } |
188 | 188 | } |
189 | 189 | |
190 | 190 | // Customer param wrong? The user may have been deleted on stripe's end. Remove customer_id. Can be retried without. |
191 | - if ( preg_match( '/No such customer/i', $response->error->message ) && $retry ) { |
|
192 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
193 | - delete_user_meta( $order->customer_user, '_stripe_customer_id' ); |
|
194 | - delete_post_meta( $order_id, '_stripe_customer_id' ); |
|
191 | + if (preg_match('/No such customer/i', $response->error->message) && $retry) { |
|
192 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
193 | + delete_user_meta($order->customer_user, '_stripe_customer_id'); |
|
194 | + delete_post_meta($order_id, '_stripe_customer_id'); |
|
195 | 195 | } else { |
196 | - delete_user_meta( $order->get_customer_id(), '_stripe_customer_id' ); |
|
197 | - $order->delete_meta_data( '_stripe_customer_id' ); |
|
196 | + delete_user_meta($order->get_customer_id(), '_stripe_customer_id'); |
|
197 | + $order->delete_meta_data('_stripe_customer_id'); |
|
198 | 198 | $order->save(); |
199 | 199 | } |
200 | 200 | |
201 | - return $this->process_webhook_payment( $notification, false ); |
|
201 | + return $this->process_webhook_payment($notification, false); |
|
202 | 202 | |
203 | - } elseif ( preg_match( '/No such token/i', $response->error->message ) && $source_object->token_id ) { |
|
203 | + } elseif (preg_match('/No such token/i', $response->error->message) && $source_object->token_id) { |
|
204 | 204 | // Source param wrong? The CARD may have been deleted on stripe's end. Remove token and show message. |
205 | - $wc_token = WC_Payment_Tokens::get( $source_object->token_id ); |
|
205 | + $wc_token = WC_Payment_Tokens::get($source_object->token_id); |
|
206 | 206 | $wc_token->delete(); |
207 | - $message = __( 'This card is no longer available and has been removed.', 'woocommerce-gateway-stripe' ); |
|
208 | - $order->add_order_note( $message ); |
|
209 | - throw new WC_Stripe_Exception( print_r( $response, true ), $message ); |
|
207 | + $message = __('This card is no longer available and has been removed.', 'woocommerce-gateway-stripe'); |
|
208 | + $order->add_order_note($message); |
|
209 | + throw new WC_Stripe_Exception(print_r($response, true), $message); |
|
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', $e, $order ); |
|
237 | + do_action('wc_gateway_stripe_process_webhook_payment_error', $e, $order); |
|
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 | 268 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
269 | - $this->send_failed_order_email( $order_id ); |
|
269 | + $this->send_failed_order_email($order_id); |
|
270 | 270 | } |
271 | 271 | |
272 | 272 | /** |
@@ -277,41 +277,41 @@ 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 | 288 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
289 | 289 | |
290 | - if ( 'stripe' === ( WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method() ) ) { |
|
291 | - $charge = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_transaction_id', true ) : $order->get_transaction_id(); |
|
292 | - $captured = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_stripe_charge_captured', true ) : $order->get_meta( '_stripe_charge_captured', true ); |
|
290 | + if ('stripe' === (WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method())) { |
|
291 | + $charge = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_transaction_id', true) : $order->get_transaction_id(); |
|
292 | + $captured = WC_Stripe_Helper::is_pre_30() ? 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_pre_30() ? 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_pre_30() ? 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_pre_30() ? update_post_meta( $order_id, '_transaction_id', $notification->data->object->id ) : $order->set_transaction_id( $notification->data->object->id ); |
|
298 | + WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, '_transaction_id', $notification->data->object->id) : $order->set_transaction_id($notification->data->object->id); |
|
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 | - if ( is_callable( array( $order, 'save' ) ) ) { |
|
304 | + if (is_callable(array($order, 'save'))) { |
|
305 | 305 | $order->save(); |
306 | 306 | } |
307 | 307 | |
308 | 308 | /* translators: transaction id */ |
309 | - $order->update_status( $order->needs_processing() ? 'processing' : 'completed', sprintf( __( 'Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe' ), $notification->data->object->id ) ); |
|
309 | + $order->update_status($order->needs_processing() ? 'processing' : 'completed', sprintf(__('Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe'), $notification->data->object->id)); |
|
310 | 310 | |
311 | 311 | // Check and see if capture is partial. |
312 | - if ( $this->is_partial_capture( $notification ) ) { |
|
313 | - $order->set_total( $this->get_partial_amount_to_charge( $notification ) ); |
|
314 | - $order->add_order_note( __( 'This charge was partially captured via Stripe Dashboard', 'woocommerce-gateway-stripe' ) ); |
|
312 | + if ($this->is_partial_capture($notification)) { |
|
313 | + $order->set_total($this->get_partial_amount_to_charge($notification)); |
|
314 | + $order->add_order_note(__('This charge was partially captured via Stripe Dashboard', 'woocommerce-gateway-stripe')); |
|
315 | 315 | $order->save(); |
316 | 316 | } |
317 | 317 | } |
@@ -326,38 +326,38 @@ discard block |
||
326 | 326 | * @version 4.0.0 |
327 | 327 | * @param object $notification |
328 | 328 | */ |
329 | - public function process_webhook_charge_succeeded( $notification ) { |
|
329 | + public function process_webhook_charge_succeeded($notification) { |
|
330 | 330 | // The following payment methods are synchronous so does not need to be handle via webhook. |
331 | - 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 ) ) { |
|
331 | + 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)) { |
|
332 | 332 | return; |
333 | 333 | } |
334 | 334 | |
335 | - $order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->id ); |
|
335 | + $order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->id); |
|
336 | 336 | |
337 | - if ( ! $order ) { |
|
338 | - WC_Stripe_Logger::log( 'Could not find order via charge ID: ' . $notification->data->object->id ); |
|
337 | + if ( ! $order) { |
|
338 | + WC_Stripe_Logger::log('Could not find order via charge ID: ' . $notification->data->object->id); |
|
339 | 339 | return; |
340 | 340 | } |
341 | 341 | |
342 | 342 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
343 | 343 | |
344 | - if ( 'on-hold' !== $order->get_status() ) { |
|
344 | + if ('on-hold' !== $order->get_status()) { |
|
345 | 345 | return; |
346 | 346 | } |
347 | 347 | |
348 | 348 | // Store other data such as fees |
349 | - WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, '_transaction_id', $notification->data->object->id ) : $order->set_transaction_id( $notification->data->object->id ); |
|
349 | + WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, '_transaction_id', $notification->data->object->id) : $order->set_transaction_id($notification->data->object->id); |
|
350 | 350 | |
351 | - if ( isset( $notification->data->object->balance_transaction ) ) { |
|
352 | - $this->update_fees( $order, $notification->data->object->balance_transaction ); |
|
351 | + if (isset($notification->data->object->balance_transaction)) { |
|
352 | + $this->update_fees($order, $notification->data->object->balance_transaction); |
|
353 | 353 | } |
354 | 354 | |
355 | - if ( is_callable( array( $order, 'save' ) ) ) { |
|
355 | + if (is_callable(array($order, 'save'))) { |
|
356 | 356 | $order->save(); |
357 | 357 | } |
358 | 358 | |
359 | 359 | /* translators: transaction id */ |
360 | - $order->update_status( $order->needs_processing() ? 'processing' : 'completed', sprintf( __( 'Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe' ), $notification->data->object->id ) ); |
|
360 | + $order->update_status($order->needs_processing() ? 'processing' : 'completed', sprintf(__('Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe'), $notification->data->object->id)); |
|
361 | 361 | } |
362 | 362 | |
363 | 363 | /** |
@@ -368,23 +368,23 @@ discard block |
||
368 | 368 | * @version 4.0.0 |
369 | 369 | * @param object $notification |
370 | 370 | */ |
371 | - public function process_webhook_charge_failed( $notification ) { |
|
372 | - $order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->id ); |
|
371 | + public function process_webhook_charge_failed($notification) { |
|
372 | + $order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->id); |
|
373 | 373 | |
374 | - if ( ! $order ) { |
|
375 | - WC_Stripe_Logger::log( 'Could not find order via charge ID: ' . $notification->data->object->id ); |
|
374 | + if ( ! $order) { |
|
375 | + WC_Stripe_Logger::log('Could not find order via charge ID: ' . $notification->data->object->id); |
|
376 | 376 | return; |
377 | 377 | } |
378 | 378 | |
379 | 379 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
380 | 380 | |
381 | - if ( 'on-hold' !== $order->get_status() ) { |
|
381 | + if ('on-hold' !== $order->get_status()) { |
|
382 | 382 | return; |
383 | 383 | } |
384 | 384 | |
385 | - $order->update_status( 'failed', __( 'This payment failed to clear.', 'woocommerce-gateway-stripe' ) ); |
|
385 | + $order->update_status('failed', __('This payment failed to clear.', 'woocommerce-gateway-stripe')); |
|
386 | 386 | |
387 | - do_action( 'wc_gateway_stripe_process_webhook_payment_error', $order, $notification ); |
|
387 | + do_action('wc_gateway_stripe_process_webhook_payment_error', $order, $notification); |
|
388 | 388 | } |
389 | 389 | |
390 | 390 | /** |
@@ -395,23 +395,23 @@ discard block |
||
395 | 395 | * @version 4.0.0 |
396 | 396 | * @param object $notification |
397 | 397 | */ |
398 | - public function process_webhook_source_canceled( $notification ) { |
|
399 | - $order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->id ); |
|
398 | + public function process_webhook_source_canceled($notification) { |
|
399 | + $order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->id); |
|
400 | 400 | |
401 | - if ( ! $order ) { |
|
402 | - WC_Stripe_Logger::log( 'Could not find order via charge ID: ' . $notification->data->object->id ); |
|
401 | + if ( ! $order) { |
|
402 | + WC_Stripe_Logger::log('Could not find order via charge ID: ' . $notification->data->object->id); |
|
403 | 403 | return; |
404 | 404 | } |
405 | 405 | |
406 | 406 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
407 | 407 | |
408 | - if ( 'on-hold' !== $order->get_status() || 'cancelled' !== $order->get_status() ) { |
|
408 | + if ('on-hold' !== $order->get_status() || 'cancelled' !== $order->get_status()) { |
|
409 | 409 | return; |
410 | 410 | } |
411 | 411 | |
412 | - $order->update_status( 'cancelled', __( 'This payment has cancelled.', 'woocommerce-gateway-stripe' ) ); |
|
412 | + $order->update_status('cancelled', __('This payment has cancelled.', 'woocommerce-gateway-stripe')); |
|
413 | 413 | |
414 | - do_action( 'wc_gateway_stripe_process_webhook_payment_error', $order, $notification ); |
|
414 | + do_action('wc_gateway_stripe_process_webhook_payment_error', $order, $notification); |
|
415 | 415 | } |
416 | 416 | |
417 | 417 | /** |
@@ -422,42 +422,42 @@ discard block |
||
422 | 422 | * @version 4.0.0 |
423 | 423 | * @param object $notification |
424 | 424 | */ |
425 | - public function process_webhook_refund( $notification ) { |
|
426 | - $order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->id ); |
|
425 | + public function process_webhook_refund($notification) { |
|
426 | + $order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->id); |
|
427 | 427 | |
428 | - if ( ! $order ) { |
|
429 | - WC_Stripe_Logger::log( 'Could not find order via charge ID: ' . $notification->data->object->id ); |
|
428 | + if ( ! $order) { |
|
429 | + WC_Stripe_Logger::log('Could not find order via charge ID: ' . $notification->data->object->id); |
|
430 | 430 | return; |
431 | 431 | } |
432 | 432 | |
433 | 433 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
434 | 434 | |
435 | - if ( 'stripe' === ( WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method() ) ) { |
|
436 | - $charge = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_transaction_id', true ) : $order->get_transaction_id(); |
|
437 | - $captured = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_stripe_charge_captured', true ) : $order->get_meta( '_stripe_charge_captured', true ); |
|
438 | - $refund_id = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_stripe_refund_id', true ) : $order->get_meta( '_stripe_refund_id', true ); |
|
435 | + if ('stripe' === (WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method())) { |
|
436 | + $charge = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_transaction_id', true) : $order->get_transaction_id(); |
|
437 | + $captured = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_stripe_charge_captured', true) : $order->get_meta('_stripe_charge_captured', true); |
|
438 | + $refund_id = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_stripe_refund_id', true) : $order->get_meta('_stripe_refund_id', true); |
|
439 | 439 | |
440 | 440 | // If the refund ID matches, don't continue to prevent double refunding. |
441 | - if ( $notification->data->object->refunds->data[0]->id === $refund_id ) { |
|
441 | + if ($notification->data->object->refunds->data[0]->id === $refund_id) { |
|
442 | 442 | return; |
443 | 443 | } |
444 | 444 | |
445 | 445 | // Only refund captured charge. |
446 | - if ( $charge ) { |
|
447 | - $reason = ( isset( $captured ) && 'yes' === $captured ) ? __( 'Refunded via Stripe Dashboard', 'woocommerce-gateway-stripe' ) : __( 'Pre-Authorization Released via Stripe Dashboard', 'woocommerce-gateway-stripe' ); |
|
446 | + if ($charge) { |
|
447 | + $reason = (isset($captured) && 'yes' === $captured) ? __('Refunded via Stripe Dashboard', 'woocommerce-gateway-stripe') : __('Pre-Authorization Released via Stripe Dashboard', 'woocommerce-gateway-stripe'); |
|
448 | 448 | |
449 | 449 | // Create the refund. |
450 | - $refund = wc_create_refund( array( |
|
450 | + $refund = wc_create_refund(array( |
|
451 | 451 | 'order_id' => $order_id, |
452 | - 'amount' => $this->get_refund_amount( $notification ), |
|
452 | + 'amount' => $this->get_refund_amount($notification), |
|
453 | 453 | 'reason' => $reason, |
454 | - ) ); |
|
454 | + )); |
|
455 | 455 | |
456 | - if ( is_wp_error( $refund ) ) { |
|
457 | - WC_Stripe_Logger::log( $refund->get_error_message() ); |
|
456 | + if (is_wp_error($refund)) { |
|
457 | + WC_Stripe_Logger::log($refund->get_error_message()); |
|
458 | 458 | } |
459 | 459 | |
460 | - $order->add_order_note( $reason ); |
|
460 | + $order->add_order_note($reason); |
|
461 | 461 | } |
462 | 462 | } |
463 | 463 | } |
@@ -468,21 +468,21 @@ discard block |
||
468 | 468 | * @since 4.0.6 |
469 | 469 | * @param object $notification |
470 | 470 | */ |
471 | - public function process_review_opened( $notification ) { |
|
472 | - $order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->charge ); |
|
471 | + public function process_review_opened($notification) { |
|
472 | + $order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->charge); |
|
473 | 473 | |
474 | - if ( ! $order ) { |
|
475 | - WC_Stripe_Logger::log( 'Could not find order via charge ID: ' . $notification->data->object->charge ); |
|
474 | + if ( ! $order) { |
|
475 | + WC_Stripe_Logger::log('Could not find order via charge ID: ' . $notification->data->object->charge); |
|
476 | 476 | return; |
477 | 477 | } |
478 | 478 | |
479 | 479 | /* translators: 1) The URL to the order. 2) The reason type. */ |
480 | - $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 ); |
|
480 | + $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); |
|
481 | 481 | |
482 | - if ( apply_filters( 'wc_stripe_webhook_review_change_order_status', true, $order, $notification ) ) { |
|
483 | - $order->update_status( 'on-hold', $message ); |
|
482 | + if (apply_filters('wc_stripe_webhook_review_change_order_status', true, $order, $notification)) { |
|
483 | + $order->update_status('on-hold', $message); |
|
484 | 484 | } else { |
485 | - $order->add_order_note( $message ); |
|
485 | + $order->add_order_note($message); |
|
486 | 486 | } |
487 | 487 | } |
488 | 488 | |
@@ -492,25 +492,25 @@ discard block |
||
492 | 492 | * @since 4.0.6 |
493 | 493 | * @param object $notification |
494 | 494 | */ |
495 | - public function process_review_closed( $notification ) { |
|
496 | - $order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->charge ); |
|
495 | + public function process_review_closed($notification) { |
|
496 | + $order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->charge); |
|
497 | 497 | |
498 | - if ( ! $order ) { |
|
499 | - WC_Stripe_Logger::log( 'Could not find order via charge ID: ' . $notification->data->object->charge ); |
|
498 | + if ( ! $order) { |
|
499 | + WC_Stripe_Logger::log('Could not find order via charge ID: ' . $notification->data->object->charge); |
|
500 | 500 | return; |
501 | 501 | } |
502 | 502 | |
503 | 503 | /* translators: 1) The reason type. */ |
504 | - $message = sprintf( __( 'The opened review for this order is now closed. Reason: (%s)', 'woocommerce-gateway-stripe' ), $notification->data->object->reason ); |
|
504 | + $message = sprintf(__('The opened review for this order is now closed. Reason: (%s)', 'woocommerce-gateway-stripe'), $notification->data->object->reason); |
|
505 | 505 | |
506 | - if ( 'on-hold' === $order->get_status() ) { |
|
507 | - if ( apply_filters( 'wc_stripe_webhook_review_change_order_status', true, $order, $notification ) ) { |
|
508 | - $order->update_status( 'processing', $message ); |
|
506 | + if ('on-hold' === $order->get_status()) { |
|
507 | + if (apply_filters('wc_stripe_webhook_review_change_order_status', true, $order, $notification)) { |
|
508 | + $order->update_status('processing', $message); |
|
509 | 509 | } else { |
510 | - $order->add_order_note( $message ); |
|
510 | + $order->add_order_note($message); |
|
511 | 511 | } |
512 | 512 | } else { |
513 | - $order->add_order_note( $message ); |
|
513 | + $order->add_order_note($message); |
|
514 | 514 | } |
515 | 515 | } |
516 | 516 | |
@@ -521,7 +521,7 @@ discard block |
||
521 | 521 | * @version 4.0.0 |
522 | 522 | * @param object $notification |
523 | 523 | */ |
524 | - public function is_partial_capture( $notification ) { |
|
524 | + public function is_partial_capture($notification) { |
|
525 | 525 | return 0 < $notification->data->object->amount_refunded; |
526 | 526 | } |
527 | 527 | |
@@ -532,11 +532,11 @@ discard block |
||
532 | 532 | * @version 4.0.0 |
533 | 533 | * @param object $notification |
534 | 534 | */ |
535 | - public function get_refund_amount( $notification ) { |
|
536 | - if ( $this->is_partial_capture( $notification ) ) { |
|
535 | + public function get_refund_amount($notification) { |
|
536 | + if ($this->is_partial_capture($notification)) { |
|
537 | 537 | $amount = $notification->data->object->amount_refunded / 100; |
538 | 538 | |
539 | - if ( in_array( strtolower( $notification->data->object->currency ), WC_Stripe_Helper::no_decimal_currencies() ) ) { |
|
539 | + if (in_array(strtolower($notification->data->object->currency), WC_Stripe_Helper::no_decimal_currencies())) { |
|
540 | 540 | $amount = $notification->data->object->amount_refunded; |
541 | 541 | } |
542 | 542 | |
@@ -553,12 +553,12 @@ discard block |
||
553 | 553 | * @version 4.0.0 |
554 | 554 | * @param object $notification |
555 | 555 | */ |
556 | - public function get_partial_amount_to_charge( $notification ) { |
|
557 | - if ( $this->is_partial_capture( $notification ) ) { |
|
558 | - $amount = ( $notification->data->object->amount - $notification->data->object->amount_refunded ) / 100; |
|
556 | + public function get_partial_amount_to_charge($notification) { |
|
557 | + if ($this->is_partial_capture($notification)) { |
|
558 | + $amount = ($notification->data->object->amount - $notification->data->object->amount_refunded) / 100; |
|
559 | 559 | |
560 | - if ( in_array( strtolower( $notification->data->object->currency ), WC_Stripe_Helper::no_decimal_currencies() ) ) { |
|
561 | - $amount = ( $notification->data->object->amount - $notification->data->object->amount_refunded ); |
|
560 | + if (in_array(strtolower($notification->data->object->currency), WC_Stripe_Helper::no_decimal_currencies())) { |
|
561 | + $amount = ($notification->data->object->amount - $notification->data->object->amount_refunded); |
|
562 | 562 | } |
563 | 563 | |
564 | 564 | return $amount; |
@@ -574,44 +574,44 @@ discard block |
||
574 | 574 | * @version 4.0.0 |
575 | 575 | * @param string $request_body |
576 | 576 | */ |
577 | - public function process_webhook( $request_body ) { |
|
578 | - $notification = json_decode( $request_body ); |
|
577 | + public function process_webhook($request_body) { |
|
578 | + $notification = json_decode($request_body); |
|
579 | 579 | |
580 | - switch ( $notification->type ) { |
|
580 | + switch ($notification->type) { |
|
581 | 581 | case 'source.chargeable': |
582 | - $this->process_webhook_payment( $notification ); |
|
582 | + $this->process_webhook_payment($notification); |
|
583 | 583 | break; |
584 | 584 | |
585 | 585 | case 'source.canceled': |
586 | - $this->process_webhook_source_canceled( $notification ); |
|
586 | + $this->process_webhook_source_canceled($notification); |
|
587 | 587 | break; |
588 | 588 | |
589 | 589 | case 'charge.succeeded': |
590 | - $this->process_webhook_charge_succeeded( $notification ); |
|
590 | + $this->process_webhook_charge_succeeded($notification); |
|
591 | 591 | break; |
592 | 592 | |
593 | 593 | case 'charge.failed': |
594 | - $this->process_webhook_charge_failed( $notification ); |
|
594 | + $this->process_webhook_charge_failed($notification); |
|
595 | 595 | break; |
596 | 596 | |
597 | 597 | case 'charge.captured': |
598 | - $this->process_webhook_capture( $notification ); |
|
598 | + $this->process_webhook_capture($notification); |
|
599 | 599 | break; |
600 | 600 | |
601 | 601 | case 'charge.dispute.created': |
602 | - $this->process_webhook_dispute( $notification ); |
|
602 | + $this->process_webhook_dispute($notification); |
|
603 | 603 | break; |
604 | 604 | |
605 | 605 | case 'charge.refunded': |
606 | - $this->process_webhook_refund( $notification ); |
|
606 | + $this->process_webhook_refund($notification); |
|
607 | 607 | break; |
608 | 608 | |
609 | 609 | case 'review.opened': |
610 | - $this->process_review_opened( $notification ); |
|
610 | + $this->process_review_opened($notification); |
|
611 | 611 | break; |
612 | 612 | |
613 | 613 | case 'review.closed': |
614 | - $this->process_review_closed( $notification ); |
|
614 | + $this->process_review_closed($notification); |
|
615 | 615 | break; |
616 | 616 | |
617 | 617 | } |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if ( ! defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | 5 | |
@@ -26,7 +26,7 @@ discard block |
||
26 | 26 | * Set secret API Key. |
27 | 27 | * @param string $key |
28 | 28 | */ |
29 | - public static function set_secret_key( $secret_key ) { |
|
29 | + public static function set_secret_key($secret_key) { |
|
30 | 30 | self::$secret_key = $secret_key; |
31 | 31 | } |
32 | 32 | |
@@ -35,11 +35,11 @@ discard block |
||
35 | 35 | * @return string |
36 | 36 | */ |
37 | 37 | public static function get_secret_key() { |
38 | - if ( ! self::$secret_key ) { |
|
39 | - $options = get_option( 'woocommerce_stripe_settings' ); |
|
38 | + if ( ! self::$secret_key) { |
|
39 | + $options = get_option('woocommerce_stripe_settings'); |
|
40 | 40 | |
41 | - if ( isset( $options['testmode'], $options['secret_key'], $options['test_secret_key'] ) ) { |
|
42 | - self::set_secret_key( 'yes' === $options['testmode'] ? $options['test_secret_key'] : $options['secret_key'] ); |
|
41 | + if (isset($options['testmode'], $options['secret_key'], $options['test_secret_key'])) { |
|
42 | + self::set_secret_key('yes' === $options['testmode'] ? $options['test_secret_key'] : $options['secret_key']); |
|
43 | 43 | } |
44 | 44 | } |
45 | 45 | return self::$secret_key; |
@@ -78,12 +78,12 @@ discard block |
||
78 | 78 | $user_agent = self::get_user_agent(); |
79 | 79 | $app_info = $user_agent['application']; |
80 | 80 | |
81 | - return apply_filters( 'woocommerce_stripe_request_headers', array( |
|
82 | - 'Authorization' => 'Basic ' . base64_encode( self::get_secret_key() . ':' ), |
|
81 | + return apply_filters('woocommerce_stripe_request_headers', array( |
|
82 | + 'Authorization' => 'Basic ' . base64_encode(self::get_secret_key() . ':'), |
|
83 | 83 | 'Stripe-Version' => self::STRIPE_API_VERSION, |
84 | 84 | 'User-Agent' => $app_info['name'] . '/' . $app_info['version'] . ' (' . $app_info['url'] . ')', |
85 | - 'X-Stripe-Client-User-Agent' => json_encode( $user_agent ), |
|
86 | - ) ); |
|
85 | + 'X-Stripe-Client-User-Agent' => json_encode($user_agent), |
|
86 | + )); |
|
87 | 87 | } |
88 | 88 | |
89 | 89 | /** |
@@ -96,16 +96,16 @@ discard block |
||
96 | 96 | * @param bool $with_headers To get the response with headers. |
97 | 97 | * @return array|WP_Error |
98 | 98 | */ |
99 | - public static function request( $request, $api = 'charges', $method = 'POST', $with_headers = false ) { |
|
100 | - WC_Stripe_Logger::log( "{$api} request: " . print_r( $request, true ) ); |
|
99 | + public static function request($request, $api = 'charges', $method = 'POST', $with_headers = false) { |
|
100 | + WC_Stripe_Logger::log("{$api} request: " . print_r($request, true)); |
|
101 | 101 | |
102 | 102 | $headers = self::get_headers(); |
103 | 103 | |
104 | - if ( 'charges' === $api && 'POST' === $method ) { |
|
105 | - $customer = ! empty( $request['customer'] ) ? $request['customer'] : ''; |
|
106 | - $source = ! empty( $request['source'] ) ? $request['source'] : $customer; |
|
104 | + if ('charges' === $api && 'POST' === $method) { |
|
105 | + $customer = ! empty($request['customer']) ? $request['customer'] : ''; |
|
106 | + $source = ! empty($request['source']) ? $request['source'] : $customer; |
|
107 | 107 | |
108 | - $headers['Idempotency-Key'] = apply_filters( 'wc_stripe_idempotency_key', $request['metadata']['order_id'] . '-' . $source, $request ); |
|
108 | + $headers['Idempotency-Key'] = apply_filters('wc_stripe_idempotency_key', $request['metadata']['order_id'] . '-' . $source, $request); |
|
109 | 109 | } |
110 | 110 | |
111 | 111 | $response = wp_safe_remote_post( |
@@ -113,21 +113,21 @@ discard block |
||
113 | 113 | array( |
114 | 114 | 'method' => $method, |
115 | 115 | 'headers' => $headers, |
116 | - 'body' => apply_filters( 'woocommerce_stripe_request_body', $request, $api ), |
|
116 | + 'body' => apply_filters('woocommerce_stripe_request_body', $request, $api), |
|
117 | 117 | 'timeout' => 70, |
118 | 118 | ) |
119 | 119 | ); |
120 | 120 | |
121 | - if ( is_wp_error( $response ) || empty( $response['body'] ) ) { |
|
122 | - WC_Stripe_Logger::log( 'Error Response: ' . print_r( $response, true ) ); |
|
123 | - throw new WC_Stripe_Exception( print_r( $response, true ), __( 'There was a problem connecting to the Stripe API endpoint.', 'woocommerce-gateway-stripe' ) ); |
|
121 | + if (is_wp_error($response) || empty($response['body'])) { |
|
122 | + WC_Stripe_Logger::log('Error Response: ' . print_r($response, true)); |
|
123 | + throw new WC_Stripe_Exception(print_r($response, true), __('There was a problem connecting to the Stripe API endpoint.', 'woocommerce-gateway-stripe')); |
|
124 | 124 | } |
125 | 125 | |
126 | - if ( $with_headers ) { |
|
127 | - return array( 'headers' => wp_remote_retrieve_headers( $response ), 'body' => json_decode( $response['body'] ) ); |
|
126 | + if ($with_headers) { |
|
127 | + return array('headers' => wp_remote_retrieve_headers($response), 'body' => json_decode($response['body'])); |
|
128 | 128 | } |
129 | 129 | |
130 | - return json_decode( $response['body'] ); |
|
130 | + return json_decode($response['body']); |
|
131 | 131 | } |
132 | 132 | |
133 | 133 | /** |
@@ -137,8 +137,8 @@ discard block |
||
137 | 137 | * @version 4.0.0 |
138 | 138 | * @param string $api |
139 | 139 | */ |
140 | - public static function retrieve( $api ) { |
|
141 | - WC_Stripe_Logger::log( "{$api}" ); |
|
140 | + public static function retrieve($api) { |
|
141 | + WC_Stripe_Logger::log("{$api}"); |
|
142 | 142 | |
143 | 143 | $response = wp_safe_remote_get( |
144 | 144 | self::ENDPOINT . $api, |
@@ -149,11 +149,11 @@ discard block |
||
149 | 149 | ) |
150 | 150 | ); |
151 | 151 | |
152 | - if ( is_wp_error( $response ) || empty( $response['body'] ) ) { |
|
153 | - WC_Stripe_Logger::log( 'Error Response: ' . print_r( $response, true ) ); |
|
154 | - return new WP_Error( 'stripe_error', __( 'There was a problem connecting to the Stripe API endpoint.', 'woocommerce-gateway-stripe' ) ); |
|
152 | + if (is_wp_error($response) || empty($response['body'])) { |
|
153 | + WC_Stripe_Logger::log('Error Response: ' . print_r($response, true)); |
|
154 | + return new WP_Error('stripe_error', __('There was a problem connecting to the Stripe API endpoint.', 'woocommerce-gateway-stripe')); |
|
155 | 155 | } |
156 | 156 | |
157 | - return json_decode( $response['body'] ); |
|
157 | + return json_decode($response['body']); |
|
158 | 158 | } |
159 | 159 | } |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if ( ! defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | 5 | |
@@ -23,12 +23,12 @@ discard block |
||
23 | 23 | |
24 | 24 | $this->retry_interval = 1; |
25 | 25 | |
26 | - add_action( 'wp', array( $this, 'maybe_process_redirect_order' ) ); |
|
27 | - add_action( 'woocommerce_order_status_on-hold_to_processing', array( $this, 'capture_payment' ) ); |
|
28 | - add_action( 'woocommerce_order_status_on-hold_to_completed', array( $this, 'capture_payment' ) ); |
|
29 | - add_action( 'woocommerce_order_status_on-hold_to_cancelled', array( $this, 'cancel_payment' ) ); |
|
30 | - add_action( 'woocommerce_order_status_on-hold_to_refunded', array( $this, 'cancel_payment' ) ); |
|
31 | - add_action( 'wc_ajax_wc_stripe_validate_checkout', array( $this, 'validate_checkout' ) ); |
|
26 | + add_action('wp', array($this, 'maybe_process_redirect_order')); |
|
27 | + add_action('woocommerce_order_status_on-hold_to_processing', array($this, 'capture_payment')); |
|
28 | + add_action('woocommerce_order_status_on-hold_to_completed', array($this, 'capture_payment')); |
|
29 | + add_action('woocommerce_order_status_on-hold_to_cancelled', array($this, 'cancel_payment')); |
|
30 | + add_action('woocommerce_order_status_on-hold_to_refunded', array($this, 'cancel_payment')); |
|
31 | + add_action('wc_ajax_wc_stripe_validate_checkout', array($this, 'validate_checkout')); |
|
32 | 32 | } |
33 | 33 | |
34 | 34 | /** |
@@ -49,25 +49,25 @@ discard block |
||
49 | 49 | * @since 4.0.0 |
50 | 50 | * @version 4.0.0 |
51 | 51 | */ |
52 | - public function process_redirect_payment( $order_id, $retry = true ) { |
|
52 | + public function process_redirect_payment($order_id, $retry = true) { |
|
53 | 53 | try { |
54 | - $source = wc_clean( $_GET['source'] ); |
|
54 | + $source = wc_clean($_GET['source']); |
|
55 | 55 | |
56 | - if ( empty( $source ) ) { |
|
56 | + if (empty($source)) { |
|
57 | 57 | return; |
58 | 58 | } |
59 | 59 | |
60 | - if ( empty( $order_id ) ) { |
|
60 | + if (empty($order_id)) { |
|
61 | 61 | return; |
62 | 62 | } |
63 | 63 | |
64 | - $order = wc_get_order( $order_id ); |
|
64 | + $order = wc_get_order($order_id); |
|
65 | 65 | |
66 | - if ( ! is_object( $order ) ) { |
|
66 | + if ( ! is_object($order)) { |
|
67 | 67 | return; |
68 | 68 | } |
69 | 69 | |
70 | - if ( 'processing' === $order->get_status() || 'completed' === $order->get_status() || 'on-hold' === $order->get_status() ) { |
|
70 | + if ('processing' === $order->get_status() || 'completed' === $order->get_status() || 'on-hold' === $order->get_status()) { |
|
71 | 71 | return; |
72 | 72 | } |
73 | 73 | |
@@ -75,129 +75,129 @@ discard block |
||
75 | 75 | $response = null; |
76 | 76 | |
77 | 77 | // This will throw exception if not valid. |
78 | - $this->validate_minimum_order_amount( $order ); |
|
78 | + $this->validate_minimum_order_amount($order); |
|
79 | 79 | |
80 | - WC_Stripe_Logger::log( "Info: (Redirect) Begin processing payment for order $order_id for the amount of {$order->get_total()}" ); |
|
80 | + WC_Stripe_Logger::log("Info: (Redirect) Begin processing payment for order $order_id for the amount of {$order->get_total()}"); |
|
81 | 81 | |
82 | 82 | /** |
83 | 83 | * First check if the source is chargeable at this time. If not, |
84 | 84 | * webhook will take care of it later. |
85 | 85 | */ |
86 | - $source_info = WC_Stripe_API::retrieve( 'sources/' . $source ); |
|
86 | + $source_info = WC_Stripe_API::retrieve('sources/' . $source); |
|
87 | 87 | |
88 | - if ( ! empty( $source_info->error ) ) { |
|
89 | - throw new WC_Stripe_Exception( print_r( $source_info, true ), $source_info->error->message ); |
|
88 | + if ( ! empty($source_info->error)) { |
|
89 | + throw new WC_Stripe_Exception(print_r($source_info, true), $source_info->error->message); |
|
90 | 90 | } |
91 | 91 | |
92 | - if ( 'failed' === $source_info->status || 'canceled' === $source_info->status ) { |
|
93 | - throw new WC_Stripe_Exception( print_r( $source_info, true ), __( 'Unable to process this payment, please try again or use alternative method.', 'woocommerce-gateway-stripe' ) ); |
|
92 | + if ('failed' === $source_info->status || 'canceled' === $source_info->status) { |
|
93 | + throw new WC_Stripe_Exception(print_r($source_info, true), __('Unable to process this payment, please try again or use alternative method.', 'woocommerce-gateway-stripe')); |
|
94 | 94 | } |
95 | 95 | |
96 | 96 | // If already consumed, then ignore request. |
97 | - if ( 'consumed' === $source_info->status ) { |
|
97 | + if ('consumed' === $source_info->status) { |
|
98 | 98 | return; |
99 | 99 | } |
100 | 100 | |
101 | 101 | // If not chargeable, then ignore request. |
102 | - if ( 'chargeable' !== $source_info->status ) { |
|
102 | + if ('chargeable' !== $source_info->status) { |
|
103 | 103 | return; |
104 | 104 | } |
105 | 105 | |
106 | 106 | // Prep source object. |
107 | 107 | $source_object = new stdClass(); |
108 | 108 | $source_object->token_id = ''; |
109 | - $source_object->customer = $this->get_stripe_customer_id( $order ); |
|
109 | + $source_object->customer = $this->get_stripe_customer_id($order); |
|
110 | 110 | $source_object->source = $source_info->id; |
111 | 111 | |
112 | 112 | /* If we're doing a retry and source is chargeable, we need to pass |
113 | 113 | * a different idempotency key and retry for success. |
114 | 114 | */ |
115 | - if ( 1 < $this->retry_interval && 'chargeable' === $source_info->status ) { |
|
116 | - add_filter( 'wc_stripe_idempotency_key', array( $this, 'change_idempotency_key' ), 10, 2 ); |
|
115 | + if (1 < $this->retry_interval && 'chargeable' === $source_info->status) { |
|
116 | + add_filter('wc_stripe_idempotency_key', array($this, 'change_idempotency_key'), 10, 2); |
|
117 | 117 | } |
118 | 118 | |
119 | 119 | // Make the request. |
120 | - $response = WC_Stripe_API::request( $this->generate_payment_request( $order, $source_object ), 'charges', 'POST', true ); |
|
120 | + $response = WC_Stripe_API::request($this->generate_payment_request($order, $source_object), 'charges', 'POST', true); |
|
121 | 121 | $headers = $response['headers']; |
122 | 122 | $response = $response['body']; |
123 | 123 | |
124 | - if ( ! empty( $response->error ) ) { |
|
124 | + if ( ! empty($response->error)) { |
|
125 | 125 | // Customer param wrong? The user may have been deleted on stripe's end. Remove customer_id. Can be retried without. |
126 | - if ( preg_match( '/No such customer/i', $response->error->message ) && $retry ) { |
|
127 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
128 | - delete_user_meta( $order->customer_user, '_stripe_customer_id' ); |
|
129 | - delete_post_meta( $order_id, '_stripe_customer_id' ); |
|
126 | + if (preg_match('/No such customer/i', $response->error->message) && $retry) { |
|
127 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
128 | + delete_user_meta($order->customer_user, '_stripe_customer_id'); |
|
129 | + delete_post_meta($order_id, '_stripe_customer_id'); |
|
130 | 130 | } else { |
131 | - delete_user_meta( $order->get_customer_id(), '_stripe_customer_id' ); |
|
132 | - $order->delete_meta_data( '_stripe_customer_id' ); |
|
131 | + delete_user_meta($order->get_customer_id(), '_stripe_customer_id'); |
|
132 | + $order->delete_meta_data('_stripe_customer_id'); |
|
133 | 133 | $order->save(); |
134 | 134 | } |
135 | 135 | |
136 | - return $this->process_redirect_payment( $order_id, false ); |
|
136 | + return $this->process_redirect_payment($order_id, false); |
|
137 | 137 | |
138 | - } elseif ( preg_match( '/No such token/i', $response->error->message ) && $source_object->token_id ) { |
|
138 | + } elseif (preg_match('/No such token/i', $response->error->message) && $source_object->token_id) { |
|
139 | 139 | // Source param wrong? The CARD may have been deleted on stripe's end. Remove token and show message. |
140 | 140 | |
141 | - $wc_token = WC_Payment_Tokens::get( $source_object->token_id ); |
|
141 | + $wc_token = WC_Payment_Tokens::get($source_object->token_id); |
|
142 | 142 | $wc_token->delete(); |
143 | - $message = __( 'This card is no longer available and has been removed.', 'woocommerce-gateway-stripe' ); |
|
144 | - $order->add_order_note( $message ); |
|
145 | - throw new WC_Stripe_Exception( print_r( $response, true ), $message ); |
|
143 | + $message = __('This card is no longer available and has been removed.', 'woocommerce-gateway-stripe'); |
|
144 | + $order->add_order_note($message); |
|
145 | + throw new WC_Stripe_Exception(print_r($response, true), $message); |
|
146 | 146 | } |
147 | 147 | |
148 | 148 | // We want to retry. |
149 | - if ( $this->is_retryable_error( $response->error ) ) { |
|
150 | - if ( $retry ) { |
|
149 | + if ($this->is_retryable_error($response->error)) { |
|
150 | + if ($retry) { |
|
151 | 151 | // Don't do anymore retries after this. |
152 | - if ( 5 <= $this->retry_interval ) { |
|
153 | - return $this->process_redirect_payment( $order_id, false ); |
|
152 | + if (5 <= $this->retry_interval) { |
|
153 | + return $this->process_redirect_payment($order_id, false); |
|
154 | 154 | } |
155 | 155 | |
156 | - sleep( $this->retry_interval ); |
|
156 | + sleep($this->retry_interval); |
|
157 | 157 | |
158 | 158 | $this->retry_interval++; |
159 | - return $this->process_redirect_payment( $order_id, true ); |
|
159 | + return $this->process_redirect_payment($order_id, true); |
|
160 | 160 | } else { |
161 | - $localized_message = __( 'On going requests error and retries exhausted.', 'woocommerce-gateway-stripe' ); |
|
162 | - $order->add_order_note( $localized_message ); |
|
163 | - throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message ); |
|
161 | + $localized_message = __('On going requests error and retries exhausted.', 'woocommerce-gateway-stripe'); |
|
162 | + $order->add_order_note($localized_message); |
|
163 | + throw new WC_Stripe_Exception(print_r($response, true), $localized_message); |
|
164 | 164 | } |
165 | 165 | } |
166 | 166 | |
167 | 167 | $localized_messages = WC_Stripe_Helper::get_localized_messages(); |
168 | 168 | |
169 | - if ( 'card_error' === $response->error->type ) { |
|
170 | - $message = isset( $localized_messages[ $response->error->code ] ) ? $localized_messages[ $response->error->code ] : $response->error->message; |
|
169 | + if ('card_error' === $response->error->type) { |
|
170 | + $message = isset($localized_messages[$response->error->code]) ? $localized_messages[$response->error->code] : $response->error->message; |
|
171 | 171 | } else { |
172 | - $message = isset( $localized_messages[ $response->error->type ] ) ? $localized_messages[ $response->error->type ] : $response->error->message; |
|
172 | + $message = isset($localized_messages[$response->error->type]) ? $localized_messages[$response->error->type] : $response->error->message; |
|
173 | 173 | } |
174 | 174 | |
175 | - throw new WC_Stripe_Exception( print_r( $response, true ), $message ); |
|
175 | + throw new WC_Stripe_Exception(print_r($response, true), $message); |
|
176 | 176 | } |
177 | 177 | |
178 | 178 | // To prevent double processing the order on WC side. |
179 | - if ( ! $this->is_original_request( $headers ) ) { |
|
179 | + if ( ! $this->is_original_request($headers)) { |
|
180 | 180 | return; |
181 | 181 | } |
182 | 182 | |
183 | - do_action( 'wc_gateway_stripe_process_redirect_payment', $response, $order ); |
|
183 | + do_action('wc_gateway_stripe_process_redirect_payment', $response, $order); |
|
184 | 184 | |
185 | - $this->process_response( $response, $order ); |
|
185 | + $this->process_response($response, $order); |
|
186 | 186 | |
187 | - } catch ( WC_Stripe_Exception $e ) { |
|
188 | - WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() ); |
|
187 | + } catch (WC_Stripe_Exception $e) { |
|
188 | + WC_Stripe_Logger::log('Error: ' . $e->getMessage()); |
|
189 | 189 | |
190 | - do_action( 'wc_gateway_stripe_process_redirect_payment_error', $e, $order ); |
|
190 | + do_action('wc_gateway_stripe_process_redirect_payment_error', $e, $order); |
|
191 | 191 | |
192 | 192 | /* translators: error message */ |
193 | - $order->update_status( 'failed', sprintf( __( 'Stripe payment failed: %s', 'woocommerce-gateway-stripe' ), $e->getLocalizedMessage() ) ); |
|
193 | + $order->update_status('failed', sprintf(__('Stripe payment failed: %s', 'woocommerce-gateway-stripe'), $e->getLocalizedMessage())); |
|
194 | 194 | |
195 | - if ( $order->has_status( array( 'pending', 'failed' ) ) ) { |
|
196 | - $this->send_failed_order_email( $order_id ); |
|
195 | + if ($order->has_status(array('pending', 'failed'))) { |
|
196 | + $this->send_failed_order_email($order_id); |
|
197 | 197 | } |
198 | 198 | |
199 | - wc_add_notice( $e->getLocalizedMessage(), 'error' ); |
|
200 | - wp_safe_redirect( wc_get_checkout_url() ); |
|
199 | + wc_add_notice($e->getLocalizedMessage(), 'error'); |
|
200 | + wp_safe_redirect(wc_get_checkout_url()); |
|
201 | 201 | exit; |
202 | 202 | } |
203 | 203 | } |
@@ -209,13 +209,13 @@ discard block |
||
209 | 209 | * @version 4.0.0 |
210 | 210 | */ |
211 | 211 | public function maybe_process_redirect_order() { |
212 | - if ( ! is_order_received_page() || empty( $_GET['client_secret'] ) || empty( $_GET['source'] ) ) { |
|
212 | + if ( ! is_order_received_page() || empty($_GET['client_secret']) || empty($_GET['source'])) { |
|
213 | 213 | return; |
214 | 214 | } |
215 | 215 | |
216 | - $order_id = wc_clean( $_GET['order_id'] ); |
|
216 | + $order_id = wc_clean($_GET['order_id']); |
|
217 | 217 | |
218 | - $this->process_redirect_payment( $order_id ); |
|
218 | + $this->process_redirect_payment($order_id); |
|
219 | 219 | } |
220 | 220 | |
221 | 221 | /** |
@@ -225,52 +225,52 @@ discard block |
||
225 | 225 | * @version 4.0.0 |
226 | 226 | * @param int $order_id |
227 | 227 | */ |
228 | - public function capture_payment( $order_id ) { |
|
229 | - $order = wc_get_order( $order_id ); |
|
228 | + public function capture_payment($order_id) { |
|
229 | + $order = wc_get_order($order_id); |
|
230 | 230 | |
231 | - if ( 'stripe' === ( WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method() ) ) { |
|
232 | - $charge = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_transaction_id', true ) : $order->get_transaction_id(); |
|
233 | - $captured = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_stripe_charge_captured', true ) : $order->get_meta( '_stripe_charge_captured', true ); |
|
231 | + if ('stripe' === (WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method())) { |
|
232 | + $charge = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_transaction_id', true) : $order->get_transaction_id(); |
|
233 | + $captured = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_stripe_charge_captured', true) : $order->get_meta('_stripe_charge_captured', true); |
|
234 | 234 | |
235 | - if ( $charge && 'no' === $captured ) { |
|
235 | + if ($charge && 'no' === $captured) { |
|
236 | 236 | $order_total = $order->get_total(); |
237 | 237 | |
238 | - if ( 0 < $order->get_total_refunded() ) { |
|
238 | + if (0 < $order->get_total_refunded()) { |
|
239 | 239 | $order_total = $order_total - $order->get_total_refunded(); |
240 | 240 | } |
241 | 241 | |
242 | - $result = WC_Stripe_API::request( array( |
|
243 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $order_total ), |
|
242 | + $result = WC_Stripe_API::request(array( |
|
243 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($order_total), |
|
244 | 244 | 'expand[]' => 'balance_transaction', |
245 | - ), 'charges/' . $charge . '/capture' ); |
|
245 | + ), 'charges/' . $charge . '/capture'); |
|
246 | 246 | |
247 | - if ( ! empty( $result->error ) ) { |
|
247 | + if ( ! empty($result->error)) { |
|
248 | 248 | /* translators: error message */ |
249 | - $order->update_status( 'failed', sprintf( __( 'Unable to capture charge! %s', 'woocommerce-gateway-stripe' ), $result->error->message ) ); |
|
249 | + $order->update_status('failed', sprintf(__('Unable to capture charge! %s', 'woocommerce-gateway-stripe'), $result->error->message)); |
|
250 | 250 | } else { |
251 | 251 | /* translators: transaction id */ |
252 | - $order->add_order_note( sprintf( __( 'Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe' ), $result->id ) ); |
|
253 | - WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, '_stripe_charge_captured', 'yes' ) : $order->update_meta_data( '_stripe_charge_captured', 'yes' ); |
|
252 | + $order->add_order_note(sprintf(__('Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe'), $result->id)); |
|
253 | + WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, '_stripe_charge_captured', 'yes') : $order->update_meta_data('_stripe_charge_captured', 'yes'); |
|
254 | 254 | |
255 | 255 | // Store other data such as fees |
256 | - WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, '_transaction_id', $result->id ) : $order->set_transaction_id( $result->id ); |
|
256 | + WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, '_transaction_id', $result->id) : $order->set_transaction_id($result->id); |
|
257 | 257 | |
258 | - if ( isset( $result->balance_transaction ) && isset( $result->balance_transaction->fee ) ) { |
|
258 | + if (isset($result->balance_transaction) && isset($result->balance_transaction->fee)) { |
|
259 | 259 | // Fees and Net needs to both come from Stripe to be accurate as the returned |
260 | 260 | // values are in the local currency of the Stripe account, not from WC. |
261 | - $fee = ! empty( $result->balance_transaction->fee ) ? WC_Stripe_Helper::format_balance_fee( $result->balance_transaction, 'fee' ) : 0; |
|
262 | - $net = ! empty( $result->balance_transaction->net ) ? WC_Stripe_Helper::format_balance_fee( $result->balance_transaction, 'net' ) : 0; |
|
263 | - WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, parent::META_NAME_FEE, $fee ) : $order->update_meta_data( parent::META_NAME_FEE, $fee ); |
|
264 | - WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, parent::META_NAME_NET, $net ) : $order->update_meta_data( parent::META_NAME_NET, $net ); |
|
261 | + $fee = ! empty($result->balance_transaction->fee) ? WC_Stripe_Helper::format_balance_fee($result->balance_transaction, 'fee') : 0; |
|
262 | + $net = ! empty($result->balance_transaction->net) ? WC_Stripe_Helper::format_balance_fee($result->balance_transaction, 'net') : 0; |
|
263 | + WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, parent::META_NAME_FEE, $fee) : $order->update_meta_data(parent::META_NAME_FEE, $fee); |
|
264 | + WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, parent::META_NAME_NET, $net) : $order->update_meta_data(parent::META_NAME_NET, $net); |
|
265 | 265 | } |
266 | 266 | |
267 | - if ( is_callable( array( $order, 'save' ) ) ) { |
|
267 | + if (is_callable(array($order, 'save'))) { |
|
268 | 268 | $order->save(); |
269 | 269 | } |
270 | 270 | } |
271 | 271 | |
272 | 272 | // This hook fires when admin manually changes order status to processing or completed. |
273 | - do_action( 'woocommerce_stripe_process_manual_capture', $order, $result ); |
|
273 | + do_action('woocommerce_stripe_process_manual_capture', $order, $result); |
|
274 | 274 | } |
275 | 275 | } |
276 | 276 | } |
@@ -282,14 +282,14 @@ discard block |
||
282 | 282 | * @version 4.0.0 |
283 | 283 | * @param int $order_id |
284 | 284 | */ |
285 | - public function cancel_payment( $order_id ) { |
|
286 | - $order = wc_get_order( $order_id ); |
|
285 | + public function cancel_payment($order_id) { |
|
286 | + $order = wc_get_order($order_id); |
|
287 | 287 | |
288 | - if ( 'stripe' === ( WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method() ) ) { |
|
289 | - $this->process_refund( $order_id ); |
|
288 | + if ('stripe' === (WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method())) { |
|
289 | + $this->process_refund($order_id); |
|
290 | 290 | |
291 | 291 | // This hook fires when admin manually changes order status to cancel. |
292 | - do_action( 'woocommerce_stripe_process_manual_cancel', $order ); |
|
292 | + do_action('woocommerce_stripe_process_manual_cancel', $order); |
|
293 | 293 | } |
294 | 294 | } |
295 | 295 | |
@@ -300,8 +300,8 @@ discard block |
||
300 | 300 | * @version 4.0.0 |
301 | 301 | */ |
302 | 302 | public function validate_checkout() { |
303 | - if ( ! wp_verify_nonce( $_POST['nonce'], '_wc_stripe_nonce' ) ) { |
|
304 | - wp_die( __( 'Cheatin’ huh?', 'woocommerce-gateway-stripe' ) ); |
|
303 | + if ( ! wp_verify_nonce($_POST['nonce'], '_wc_stripe_nonce')) { |
|
304 | + wp_die(__('Cheatin’ huh?', 'woocommerce-gateway-stripe')); |
|
305 | 305 | } |
306 | 306 | |
307 | 307 | /* |
@@ -309,7 +309,7 @@ discard block |
||
309 | 309 | * i.e. wp_send_json( 'success' ); // On successful validation. |
310 | 310 | * i.e. For errors follow WC https://github.com/woocommerce/woocommerce/blob/master/includes/class-wc-checkout.php#L918-L938 |
311 | 311 | */ |
312 | - do_action( 'wc_stripe_validate_modal_checkout_action', $_POST['required_fields'], $_POST['all_fields'] ); |
|
312 | + do_action('wc_stripe_validate_modal_checkout_action', $_POST['required_fields'], $_POST['all_fields']); |
|
313 | 313 | } |
314 | 314 | } |
315 | 315 |
@@ -15,20 +15,20 @@ discard block |
||
15 | 15 | * |
16 | 16 | */ |
17 | 17 | |
18 | -if ( ! defined( 'ABSPATH' ) ) { |
|
18 | +if ( ! defined('ABSPATH')) { |
|
19 | 19 | exit; |
20 | 20 | } |
21 | 21 | |
22 | -if ( ! class_exists( 'WC_Stripe' ) ) : |
|
22 | +if ( ! class_exists('WC_Stripe')) : |
|
23 | 23 | /** |
24 | 24 | * Required minimums and constants |
25 | 25 | */ |
26 | - define( 'WC_STRIPE_VERSION', '4.0.6' ); |
|
27 | - define( 'WC_STRIPE_MIN_PHP_VER', '5.6.0' ); |
|
28 | - define( 'WC_STRIPE_MIN_WC_VER', '2.6.0' ); |
|
29 | - define( 'WC_STRIPE_MAIN_FILE', __FILE__ ); |
|
30 | - define( 'WC_STRIPE_PLUGIN_URL', untrailingslashit( plugins_url( basename( plugin_dir_path( __FILE__ ) ), basename( __FILE__ ) ) ) ); |
|
31 | - define( 'WC_STRIPE_PLUGIN_PATH', untrailingslashit( plugin_dir_path( __FILE__ ) ) ); |
|
26 | + define('WC_STRIPE_VERSION', '4.0.6'); |
|
27 | + define('WC_STRIPE_MIN_PHP_VER', '5.6.0'); |
|
28 | + define('WC_STRIPE_MIN_WC_VER', '2.6.0'); |
|
29 | + define('WC_STRIPE_MAIN_FILE', __FILE__); |
|
30 | + define('WC_STRIPE_PLUGIN_URL', untrailingslashit(plugins_url(basename(plugin_dir_path(__FILE__)), basename(__FILE__)))); |
|
31 | + define('WC_STRIPE_PLUGIN_PATH', untrailingslashit(plugin_dir_path(__FILE__))); |
|
32 | 32 | |
33 | 33 | class WC_Stripe { |
34 | 34 | |
@@ -48,7 +48,7 @@ discard block |
||
48 | 48 | * @return Singleton The *Singleton* instance. |
49 | 49 | */ |
50 | 50 | public static function get_instance() { |
51 | - if ( null === self::$instance ) { |
|
51 | + if (null === self::$instance) { |
|
52 | 52 | self::$instance = new self(); |
53 | 53 | } |
54 | 54 | return self::$instance; |
@@ -81,10 +81,10 @@ discard block |
||
81 | 81 | * *Singleton* via the `new` operator from outside of this class. |
82 | 82 | */ |
83 | 83 | private function __construct() { |
84 | - add_action( 'admin_init', array( $this, 'check_environment' ) ); |
|
85 | - add_action( 'admin_notices', array( $this, 'admin_notices' ), 15 ); |
|
86 | - add_action( 'plugins_loaded', array( $this, 'init' ) ); |
|
87 | - add_action( 'wp_loaded', array( $this, 'hide_notices' ) ); |
|
84 | + add_action('admin_init', array($this, 'check_environment')); |
|
85 | + add_action('admin_notices', array($this, 'admin_notices'), 15); |
|
86 | + add_action('plugins_loaded', array($this, 'init')); |
|
87 | + add_action('wp_loaded', array($this, 'hide_notices')); |
|
88 | 88 | } |
89 | 89 | |
90 | 90 | /** |
@@ -94,44 +94,44 @@ discard block |
||
94 | 94 | * @version 4.0.0 |
95 | 95 | */ |
96 | 96 | public function init() { |
97 | - require_once( dirname( __FILE__ ) . '/includes/class-wc-stripe-exception.php' ); |
|
98 | - require_once( dirname( __FILE__ ) . '/includes/class-wc-stripe-logger.php' ); |
|
99 | - require_once( dirname( __FILE__ ) . '/includes/class-wc-stripe-helper.php' ); |
|
100 | - include_once( dirname( __FILE__ ) . '/includes/class-wc-stripe-api.php' ); |
|
97 | + require_once(dirname(__FILE__) . '/includes/class-wc-stripe-exception.php'); |
|
98 | + require_once(dirname(__FILE__) . '/includes/class-wc-stripe-logger.php'); |
|
99 | + require_once(dirname(__FILE__) . '/includes/class-wc-stripe-helper.php'); |
|
100 | + include_once(dirname(__FILE__) . '/includes/class-wc-stripe-api.php'); |
|
101 | 101 | |
102 | 102 | // Don't hook anything else in the plugin if we're in an incompatible environment. |
103 | - if ( self::get_environment_warning() ) { |
|
103 | + if (self::get_environment_warning()) { |
|
104 | 104 | return; |
105 | 105 | } |
106 | 106 | |
107 | - load_plugin_textdomain( 'woocommerce-gateway-stripe', false, plugin_basename( dirname( __FILE__ ) ) . '/languages' ); |
|
108 | - |
|
109 | - require_once( dirname( __FILE__ ) . '/includes/abstracts/abstract-wc-stripe-payment-gateway.php' ); |
|
110 | - require_once( dirname( __FILE__ ) . '/includes/class-wc-stripe-webhook-handler.php' ); |
|
111 | - require_once( dirname( __FILE__ ) . '/includes/class-wc-stripe-sepa-payment-token.php' ); |
|
112 | - require_once( dirname( __FILE__ ) . '/includes/class-wc-stripe-apple-pay-registration.php' ); |
|
113 | - require_once( dirname( __FILE__ ) . '/includes/class-wc-gateway-stripe.php' ); |
|
114 | - require_once( dirname( __FILE__ ) . '/includes/payment-methods/class-wc-gateway-stripe-bancontact.php' ); |
|
115 | - require_once( dirname( __FILE__ ) . '/includes/payment-methods/class-wc-gateway-stripe-sofort.php' ); |
|
116 | - require_once( dirname( __FILE__ ) . '/includes/payment-methods/class-wc-gateway-stripe-giropay.php' ); |
|
117 | - require_once( dirname( __FILE__ ) . '/includes/payment-methods/class-wc-gateway-stripe-ideal.php' ); |
|
118 | - require_once( dirname( __FILE__ ) . '/includes/payment-methods/class-wc-gateway-stripe-p24.php' ); |
|
119 | - require_once( dirname( __FILE__ ) . '/includes/payment-methods/class-wc-gateway-stripe-alipay.php' ); |
|
120 | - require_once( dirname( __FILE__ ) . '/includes/payment-methods/class-wc-gateway-stripe-sepa.php' ); |
|
121 | - require_once( dirname( __FILE__ ) . '/includes/payment-methods/class-wc-gateway-stripe-bitcoin.php' ); |
|
122 | - require_once( dirname( __FILE__ ) . '/includes/payment-methods/class-wc-stripe-payment-request.php' ); |
|
123 | - require_once( dirname( __FILE__ ) . '/includes/compat/class-wc-stripe-compat.php' ); |
|
124 | - require_once( dirname( __FILE__ ) . '/includes/compat/class-wc-stripe-sepa-compat.php' ); |
|
125 | - require_once( dirname( __FILE__ ) . '/includes/class-wc-stripe-order-handler.php' ); |
|
126 | - require_once( dirname( __FILE__ ) . '/includes/class-wc-stripe-payment-tokens.php' ); |
|
127 | - require_once( dirname( __FILE__ ) . '/includes/class-wc-stripe-customer.php' ); |
|
107 | + load_plugin_textdomain('woocommerce-gateway-stripe', false, plugin_basename(dirname(__FILE__)) . '/languages'); |
|
108 | + |
|
109 | + require_once(dirname(__FILE__) . '/includes/abstracts/abstract-wc-stripe-payment-gateway.php'); |
|
110 | + require_once(dirname(__FILE__) . '/includes/class-wc-stripe-webhook-handler.php'); |
|
111 | + require_once(dirname(__FILE__) . '/includes/class-wc-stripe-sepa-payment-token.php'); |
|
112 | + require_once(dirname(__FILE__) . '/includes/class-wc-stripe-apple-pay-registration.php'); |
|
113 | + require_once(dirname(__FILE__) . '/includes/class-wc-gateway-stripe.php'); |
|
114 | + require_once(dirname(__FILE__) . '/includes/payment-methods/class-wc-gateway-stripe-bancontact.php'); |
|
115 | + require_once(dirname(__FILE__) . '/includes/payment-methods/class-wc-gateway-stripe-sofort.php'); |
|
116 | + require_once(dirname(__FILE__) . '/includes/payment-methods/class-wc-gateway-stripe-giropay.php'); |
|
117 | + require_once(dirname(__FILE__) . '/includes/payment-methods/class-wc-gateway-stripe-ideal.php'); |
|
118 | + require_once(dirname(__FILE__) . '/includes/payment-methods/class-wc-gateway-stripe-p24.php'); |
|
119 | + require_once(dirname(__FILE__) . '/includes/payment-methods/class-wc-gateway-stripe-alipay.php'); |
|
120 | + require_once(dirname(__FILE__) . '/includes/payment-methods/class-wc-gateway-stripe-sepa.php'); |
|
121 | + require_once(dirname(__FILE__) . '/includes/payment-methods/class-wc-gateway-stripe-bitcoin.php'); |
|
122 | + require_once(dirname(__FILE__) . '/includes/payment-methods/class-wc-stripe-payment-request.php'); |
|
123 | + require_once(dirname(__FILE__) . '/includes/compat/class-wc-stripe-compat.php'); |
|
124 | + require_once(dirname(__FILE__) . '/includes/compat/class-wc-stripe-sepa-compat.php'); |
|
125 | + require_once(dirname(__FILE__) . '/includes/class-wc-stripe-order-handler.php'); |
|
126 | + require_once(dirname(__FILE__) . '/includes/class-wc-stripe-payment-tokens.php'); |
|
127 | + require_once(dirname(__FILE__) . '/includes/class-wc-stripe-customer.php'); |
|
128 | 128 | |
129 | 129 | // REMOVE IN THE FUTURE. |
130 | - require_once( dirname( __FILE__ ) . '/includes/deprecated/class-wc-stripe-apple-pay.php' ); |
|
130 | + require_once(dirname(__FILE__) . '/includes/deprecated/class-wc-stripe-apple-pay.php'); |
|
131 | 131 | |
132 | - add_filter( 'woocommerce_payment_gateways', array( $this, 'add_gateways' ) ); |
|
133 | - add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), array( $this, 'plugin_action_links' ) ); |
|
134 | - add_filter( 'woocommerce_get_sections_checkout', array( $this, 'filter_gateway_order_admin' ) ); |
|
132 | + add_filter('woocommerce_payment_gateways', array($this, 'add_gateways')); |
|
133 | + add_filter('plugin_action_links_' . plugin_basename(__FILE__), array($this, 'plugin_action_links')); |
|
134 | + add_filter('woocommerce_get_sections_checkout', array($this, 'filter_gateway_order_admin')); |
|
135 | 135 | } |
136 | 136 | |
137 | 137 | /** |
@@ -141,23 +141,23 @@ discard block |
||
141 | 141 | * @version 4.0.0 |
142 | 142 | */ |
143 | 143 | public function hide_notices() { |
144 | - if ( isset( $_GET['wc-stripe-hide-notice'] ) && isset( $_GET['_wc_stripe_notice_nonce'] ) ) { |
|
145 | - if ( ! wp_verify_nonce( $_GET['_wc_stripe_notice_nonce'], 'wc_stripe_hide_notices_nonce' ) ) { |
|
146 | - wp_die( __( 'Action failed. Please refresh the page and retry.', 'woocommerce-gateway-stripe' ) ); |
|
144 | + if (isset($_GET['wc-stripe-hide-notice']) && isset($_GET['_wc_stripe_notice_nonce'])) { |
|
145 | + if ( ! wp_verify_nonce($_GET['_wc_stripe_notice_nonce'], 'wc_stripe_hide_notices_nonce')) { |
|
146 | + wp_die(__('Action failed. Please refresh the page and retry.', 'woocommerce-gateway-stripe')); |
|
147 | 147 | } |
148 | 148 | |
149 | - if ( ! current_user_can( 'manage_woocommerce' ) ) { |
|
150 | - wp_die( __( 'Cheatin’ huh?', 'woocommerce-gateway-stripe' ) ); |
|
149 | + if ( ! current_user_can('manage_woocommerce')) { |
|
150 | + wp_die(__('Cheatin’ huh?', 'woocommerce-gateway-stripe')); |
|
151 | 151 | } |
152 | 152 | |
153 | - $notice = wc_clean( $_GET['wc-stripe-hide-notice'] ); |
|
153 | + $notice = wc_clean($_GET['wc-stripe-hide-notice']); |
|
154 | 154 | |
155 | - switch ( $notice ) { |
|
155 | + switch ($notice) { |
|
156 | 156 | case 'ssl': |
157 | - update_option( 'wc_stripe_show_ssl_notice', 'no' ); |
|
157 | + update_option('wc_stripe_show_ssl_notice', 'no'); |
|
158 | 158 | break; |
159 | 159 | case 'keys': |
160 | - update_option( 'wc_stripe_show_keys_notice', 'no' ); |
|
160 | + update_option('wc_stripe_show_keys_notice', 'no'); |
|
161 | 161 | break; |
162 | 162 | } |
163 | 163 | } |
@@ -169,8 +169,8 @@ discard block |
||
169 | 169 | * @since 1.0.0 |
170 | 170 | * @version 4.0.0 |
171 | 171 | */ |
172 | - public function add_admin_notice( $slug, $class, $message, $dismissible = false ) { |
|
173 | - $this->notices[ $slug ] = array( |
|
172 | + public function add_admin_notice($slug, $class, $message, $dismissible = false) { |
|
173 | + $this->notices[$slug] = array( |
|
174 | 174 | 'class' => $class, |
175 | 175 | 'message' => $message, |
176 | 176 | 'dismissible' => $dismissible, |
@@ -184,21 +184,21 @@ discard block |
||
184 | 184 | * @version 4.0.0 |
185 | 185 | */ |
186 | 186 | public function admin_notices() { |
187 | - if ( ! current_user_can( 'manage_woocommerce' ) ) { |
|
187 | + if ( ! current_user_can('manage_woocommerce')) { |
|
188 | 188 | return; |
189 | 189 | } |
190 | 190 | |
191 | - foreach ( (array) $this->notices as $notice_key => $notice ) { |
|
192 | - echo '<div class="' . esc_attr( $notice['class'] ) . '" style="position:relative;">'; |
|
191 | + foreach ((array) $this->notices as $notice_key => $notice) { |
|
192 | + echo '<div class="' . esc_attr($notice['class']) . '" style="position:relative;">'; |
|
193 | 193 | |
194 | - if ( $notice['dismissible'] ) { |
|
194 | + if ($notice['dismissible']) { |
|
195 | 195 | ?> |
196 | - <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> |
|
196 | + <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> |
|
197 | 197 | <?php |
198 | 198 | } |
199 | 199 | |
200 | 200 | echo '<p>'; |
201 | - echo wp_kses( $notice['message'], array( 'a' => array( 'href' => array() ) ) ); |
|
201 | + echo wp_kses($notice['message'], array('a' => array('href' => array()))); |
|
202 | 202 | echo '</p></div>'; |
203 | 203 | } |
204 | 204 | } |
@@ -211,26 +211,26 @@ discard block |
||
211 | 211 | * @version 4.0.0 |
212 | 212 | */ |
213 | 213 | public function get_environment_warning() { |
214 | - if ( version_compare( phpversion(), WC_STRIPE_MIN_PHP_VER, '<' ) ) { |
|
214 | + if (version_compare(phpversion(), WC_STRIPE_MIN_PHP_VER, '<')) { |
|
215 | 215 | /* translators: 1) int version 2) int version */ |
216 | - $message = __( 'WooCommerce Stripe - The minimum PHP version required for this plugin is %1$s. You are running %2$s.', 'woocommerce-gateway-stripe' ); |
|
216 | + $message = __('WooCommerce Stripe - The minimum PHP version required for this plugin is %1$s. You are running %2$s.', 'woocommerce-gateway-stripe'); |
|
217 | 217 | |
218 | - return sprintf( $message, WC_STRIPE_MIN_PHP_VER, phpversion() ); |
|
218 | + return sprintf($message, WC_STRIPE_MIN_PHP_VER, phpversion()); |
|
219 | 219 | } |
220 | 220 | |
221 | - if ( ! defined( 'WC_VERSION' ) ) { |
|
222 | - return __( 'WooCommerce Stripe requires WooCommerce to be activated to work.', 'woocommerce-gateway-stripe' ); |
|
221 | + if ( ! defined('WC_VERSION')) { |
|
222 | + return __('WooCommerce Stripe requires WooCommerce to be activated to work.', 'woocommerce-gateway-stripe'); |
|
223 | 223 | } |
224 | 224 | |
225 | - if ( version_compare( WC_VERSION, WC_STRIPE_MIN_WC_VER, '<' ) ) { |
|
225 | + if (version_compare(WC_VERSION, WC_STRIPE_MIN_WC_VER, '<')) { |
|
226 | 226 | /* translators: 1) int version 2) int version */ |
227 | - $message = __( 'WooCommerce Stripe - The minimum WooCommerce version required for this plugin is %1$s. You are running %2$s.', 'woocommerce-gateway-stripe' ); |
|
227 | + $message = __('WooCommerce Stripe - The minimum WooCommerce version required for this plugin is %1$s. You are running %2$s.', 'woocommerce-gateway-stripe'); |
|
228 | 228 | |
229 | - return sprintf( $message, WC_STRIPE_MIN_WC_VER, WC_VERSION ); |
|
229 | + return sprintf($message, WC_STRIPE_MIN_WC_VER, WC_VERSION); |
|
230 | 230 | } |
231 | 231 | |
232 | - if ( ! function_exists( 'curl_init' ) ) { |
|
233 | - return __( 'WooCommerce Stripe - cURL is not installed.', 'woocommerce-gateway-stripe' ); |
|
232 | + if ( ! function_exists('curl_init')) { |
|
233 | + return __('WooCommerce Stripe - cURL is not installed.', 'woocommerce-gateway-stripe'); |
|
234 | 234 | } |
235 | 235 | |
236 | 236 | return false; |
@@ -244,11 +244,11 @@ discard block |
||
244 | 244 | * @return string Setting link |
245 | 245 | */ |
246 | 246 | public function get_setting_link() { |
247 | - $use_id_as_section = function_exists( 'WC' ) ? version_compare( WC()->version, '2.6', '>=' ) : false; |
|
247 | + $use_id_as_section = function_exists('WC') ? version_compare(WC()->version, '2.6', '>=') : false; |
|
248 | 248 | |
249 | - $section_slug = $use_id_as_section ? 'stripe' : strtolower( 'WC_Gateway_Stripe' ); |
|
249 | + $section_slug = $use_id_as_section ? 'stripe' : strtolower('WC_Gateway_Stripe'); |
|
250 | 250 | |
251 | - return admin_url( 'admin.php?page=wc-settings&tab=checkout§ion=' . $section_slug ); |
|
251 | + return admin_url('admin.php?page=wc-settings&tab=checkout§ion=' . $section_slug); |
|
252 | 252 | } |
253 | 253 | |
254 | 254 | /** |
@@ -259,65 +259,65 @@ discard block |
||
259 | 259 | * @version 4.0.0 |
260 | 260 | */ |
261 | 261 | public function check_environment() { |
262 | - if ( ! defined( 'IFRAME_REQUEST' ) && ( WC_STRIPE_VERSION !== get_option( 'wc_stripe_version' ) ) ) { |
|
262 | + if ( ! defined('IFRAME_REQUEST') && (WC_STRIPE_VERSION !== get_option('wc_stripe_version'))) { |
|
263 | 263 | $this->install(); |
264 | 264 | |
265 | - do_action( 'woocommerce_stripe_updated' ); |
|
265 | + do_action('woocommerce_stripe_updated'); |
|
266 | 266 | } |
267 | 267 | |
268 | 268 | $environment_warning = $this->get_environment_warning(); |
269 | 269 | |
270 | - if ( $environment_warning && is_plugin_active( plugin_basename( __FILE__ ) ) ) { |
|
271 | - $this->add_admin_notice( 'bad_environment', 'error', $environment_warning ); |
|
270 | + if ($environment_warning && is_plugin_active(plugin_basename(__FILE__))) { |
|
271 | + $this->add_admin_notice('bad_environment', 'error', $environment_warning); |
|
272 | 272 | } |
273 | 273 | |
274 | - $show_ssl_notice = get_option( 'wc_stripe_show_ssl_notice' ); |
|
275 | - $show_keys_notice = get_option( 'wc_stripe_show_keys_notice' ); |
|
276 | - $options = get_option( 'woocommerce_stripe_settings' ); |
|
277 | - $testmode = ( isset( $options['testmode'] ) && 'yes' === $options['testmode'] ) ? true : false; |
|
278 | - $test_pub_key = isset( $options['test_publishable_key'] ) ? $options['test_publishable_key'] : ''; |
|
279 | - $test_secret_key = isset( $options['test_secret_key'] ) ? $options['test_secret_key'] : ''; |
|
280 | - $live_pub_key = isset( $options['publishable_key'] ) ? $options['publishable_key'] : ''; |
|
281 | - $live_secret_key = isset( $options['secret_key'] ) ? $options['secret_key'] : ''; |
|
274 | + $show_ssl_notice = get_option('wc_stripe_show_ssl_notice'); |
|
275 | + $show_keys_notice = get_option('wc_stripe_show_keys_notice'); |
|
276 | + $options = get_option('woocommerce_stripe_settings'); |
|
277 | + $testmode = (isset($options['testmode']) && 'yes' === $options['testmode']) ? true : false; |
|
278 | + $test_pub_key = isset($options['test_publishable_key']) ? $options['test_publishable_key'] : ''; |
|
279 | + $test_secret_key = isset($options['test_secret_key']) ? $options['test_secret_key'] : ''; |
|
280 | + $live_pub_key = isset($options['publishable_key']) ? $options['publishable_key'] : ''; |
|
281 | + $live_secret_key = isset($options['secret_key']) ? $options['secret_key'] : ''; |
|
282 | 282 | |
283 | - if ( isset( $options['enabled'] ) && 'yes' === $options['enabled'] && empty( $show_keys_notice ) ) { |
|
284 | - $secret = WC_Stripe_API::get_secret_key(); |
|
283 | + if (isset($options['enabled']) && 'yes' === $options['enabled'] && empty($show_keys_notice)) { |
|
284 | + $secret = WC_Stripe_API::get_secret_key(); |
|
285 | 285 | |
286 | - if ( empty( $secret ) && ! ( isset( $_GET['page'], $_GET['section'] ) && 'wc-settings' === $_GET['page'] && 'stripe' === $_GET['section'] ) ) { |
|
286 | + if (empty($secret) && ! (isset($_GET['page'], $_GET['section']) && 'wc-settings' === $_GET['page'] && 'stripe' === $_GET['section'])) { |
|
287 | 287 | $setting_link = $this->get_setting_link(); |
288 | 288 | /* translators: 1) link */ |
289 | - $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 ); |
|
289 | + $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); |
|
290 | 290 | } |
291 | 291 | |
292 | 292 | // Check if keys are entered properly per live/test mode. |
293 | - if ( $testmode ) { |
|
293 | + if ($testmode) { |
|
294 | 294 | if ( |
295 | - ! empty( $test_pub_key ) && ! preg_match( '/^pk_test_/', $test_pub_key ) |
|
296 | - || ( ! empty( $test_secret_key ) && ! preg_match( '/^sk_test_/', $test_secret_key ) |
|
297 | - && ! empty( $test_secret_key ) && ! preg_match( '/^rk_test_/', $test_secret_key ) ) ) |
|
295 | + ! empty($test_pub_key) && ! preg_match('/^pk_test_/', $test_pub_key) |
|
296 | + || ( ! empty($test_secret_key) && ! preg_match('/^sk_test_/', $test_secret_key) |
|
297 | + && ! empty($test_secret_key) && ! preg_match('/^rk_test_/', $test_secret_key)) ) |
|
298 | 298 | { |
299 | 299 | $setting_link = $this->get_setting_link(); |
300 | 300 | /* translators: 1) link */ |
301 | - $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 ); |
|
301 | + $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); |
|
302 | 302 | } |
303 | 303 | } else { |
304 | 304 | if ( |
305 | - ! empty( $live_pub_key ) && ! preg_match( '/^pk_live_/', $live_pub_key ) |
|
306 | - || ( ! empty( $live_secret_key ) && ! preg_match( '/^sk_live_/', $live_secret_key ) |
|
307 | - && ! empty( $live_secret_key ) && ! preg_match( '/^rk_live_/', $live_secret_key ) ) ) |
|
305 | + ! empty($live_pub_key) && ! preg_match('/^pk_live_/', $live_pub_key) |
|
306 | + || ( ! empty($live_secret_key) && ! preg_match('/^sk_live_/', $live_secret_key) |
|
307 | + && ! empty($live_secret_key) && ! preg_match('/^rk_live_/', $live_secret_key)) ) |
|
308 | 308 | { |
309 | 309 | $setting_link = $this->get_setting_link(); |
310 | 310 | /* translators: 1) link */ |
311 | - $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 ); |
|
311 | + $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); |
|
312 | 312 | } |
313 | 313 | } |
314 | 314 | } |
315 | 315 | |
316 | - if ( empty( $show_ssl_notice ) && isset( $options['enabled'] ) && 'yes' === $options['enabled'] ) { |
|
316 | + if (empty($show_ssl_notice) && isset($options['enabled']) && 'yes' === $options['enabled']) { |
|
317 | 317 | // Show message if enabled and FORCE SSL is disabled and WordpressHTTPS plugin is not detected. |
318 | - if ( ( function_exists( 'wc_site_is_https' ) && ! wc_site_is_https() ) && ( 'no' === get_option( 'woocommerce_force_ssl_checkout' ) && ! class_exists( 'WordPressHTTPS' ) ) ) { |
|
318 | + if ((function_exists('wc_site_is_https') && ! wc_site_is_https()) && ('no' === get_option('woocommerce_force_ssl_checkout') && ! class_exists('WordPressHTTPS'))) { |
|
319 | 319 | /* translators: 1) link 2) link */ |
320 | - $this->add_admin_notice( 'ssl', 'notice notice-warning', sprintf( __( 'Stripe is enabled, but the <a href="%1$s">force SSL option</a> is disabled; your checkout may not be secure! Please enable SSL and ensure your server has a valid <a href="%2$s" target="_blank">SSL certificate</a> - Stripe will only work in test mode.', 'woocommerce-gateway-stripe' ), admin_url( 'admin.php?page=wc-settings&tab=checkout' ), 'https://en.wikipedia.org/wiki/Transport_Layer_Security' ), true ); |
|
320 | + $this->add_admin_notice('ssl', 'notice notice-warning', sprintf(__('Stripe is enabled, but the <a href="%1$s">force SSL option</a> is disabled; your checkout may not be secure! Please enable SSL and ensure your server has a valid <a href="%2$s" target="_blank">SSL certificate</a> - Stripe will only work in test mode.', 'woocommerce-gateway-stripe'), admin_url('admin.php?page=wc-settings&tab=checkout'), 'https://en.wikipedia.org/wiki/Transport_Layer_Security'), true); |
|
321 | 321 | } |
322 | 322 | } |
323 | 323 | } |
@@ -329,8 +329,8 @@ discard block |
||
329 | 329 | * @version 4.0.0 |
330 | 330 | */ |
331 | 331 | public function update_plugin_version() { |
332 | - delete_option( 'wc_stripe_version' ); |
|
333 | - update_option( 'wc_stripe_version', WC_STRIPE_VERSION ); |
|
332 | + delete_option('wc_stripe_version'); |
|
333 | + update_option('wc_stripe_version', WC_STRIPE_VERSION); |
|
334 | 334 | } |
335 | 335 | |
336 | 336 | /** |
@@ -340,8 +340,8 @@ discard block |
||
340 | 340 | * @version 3.1.0 |
341 | 341 | */ |
342 | 342 | public function install() { |
343 | - if ( ! defined( 'WC_STRIPE_INSTALLING' ) ) { |
|
344 | - define( 'WC_STRIPE_INSTALLING', true ); |
|
343 | + if ( ! defined('WC_STRIPE_INSTALLING')) { |
|
344 | + define('WC_STRIPE_INSTALLING', true); |
|
345 | 345 | } |
346 | 346 | |
347 | 347 | $this->update_plugin_version(); |
@@ -353,13 +353,13 @@ discard block |
||
353 | 353 | * @since 1.0.0 |
354 | 354 | * @version 4.0.0 |
355 | 355 | */ |
356 | - public function plugin_action_links( $links ) { |
|
356 | + public function plugin_action_links($links) { |
|
357 | 357 | $plugin_links = array( |
358 | - '<a href="admin.php?page=wc-settings&tab=checkout§ion=stripe">' . esc_html__( 'Settings', 'woocommerce-gateway-stripe' ) . '</a>', |
|
359 | - '<a href="https://docs.woocommerce.com/document/stripe/">' . esc_html__( 'Docs', 'woocommerce-gateway-stripe' ) . '</a>', |
|
360 | - '<a href="https://woocommerce.com/contact-us/">' . esc_html__( 'Support', 'woocommerce-gateway-stripe' ) . '</a>', |
|
358 | + '<a href="admin.php?page=wc-settings&tab=checkout§ion=stripe">' . esc_html__('Settings', 'woocommerce-gateway-stripe') . '</a>', |
|
359 | + '<a href="https://docs.woocommerce.com/document/stripe/">' . esc_html__('Docs', 'woocommerce-gateway-stripe') . '</a>', |
|
360 | + '<a href="https://woocommerce.com/contact-us/">' . esc_html__('Support', 'woocommerce-gateway-stripe') . '</a>', |
|
361 | 361 | ); |
362 | - return array_merge( $plugin_links, $links ); |
|
362 | + return array_merge($plugin_links, $links); |
|
363 | 363 | } |
364 | 364 | |
365 | 365 | /** |
@@ -368,8 +368,8 @@ discard block |
||
368 | 368 | * @since 1.0.0 |
369 | 369 | * @version 4.0.0 |
370 | 370 | */ |
371 | - public function add_gateways( $methods ) { |
|
372 | - if ( class_exists( 'WC_Subscriptions_Order' ) && function_exists( 'wcs_create_renewal_order' ) || class_exists( 'WC_Pre_Orders_Order' ) ) { |
|
371 | + public function add_gateways($methods) { |
|
372 | + if (class_exists('WC_Subscriptions_Order') && function_exists('wcs_create_renewal_order') || class_exists('WC_Pre_Orders_Order')) { |
|
373 | 373 | $methods[] = 'WC_Stripe_Compat'; |
374 | 374 | $methods[] = 'WC_Stripe_Sepa_Compat'; |
375 | 375 | } else { |
@@ -394,26 +394,26 @@ discard block |
||
394 | 394 | * @since 4.0.0 |
395 | 395 | * @version 4.0.0 |
396 | 396 | */ |
397 | - public function filter_gateway_order_admin( $sections ) { |
|
398 | - unset( $sections['stripe'] ); |
|
399 | - unset( $sections['stripe_bancontact'] ); |
|
400 | - unset( $sections['stripe_sofort'] ); |
|
401 | - unset( $sections['stripe_giropay'] ); |
|
402 | - unset( $sections['stripe_ideal'] ); |
|
403 | - unset( $sections['stripe_p24'] ); |
|
404 | - unset( $sections['stripe_alipay'] ); |
|
405 | - unset( $sections['stripe_sepa'] ); |
|
406 | - unset( $sections['stripe_bitcoin'] ); |
|
397 | + public function filter_gateway_order_admin($sections) { |
|
398 | + unset($sections['stripe']); |
|
399 | + unset($sections['stripe_bancontact']); |
|
400 | + unset($sections['stripe_sofort']); |
|
401 | + unset($sections['stripe_giropay']); |
|
402 | + unset($sections['stripe_ideal']); |
|
403 | + unset($sections['stripe_p24']); |
|
404 | + unset($sections['stripe_alipay']); |
|
405 | + unset($sections['stripe_sepa']); |
|
406 | + unset($sections['stripe_bitcoin']); |
|
407 | 407 | |
408 | 408 | $sections['stripe'] = 'Stripe'; |
409 | - $sections['stripe_bancontact'] = __( 'Stripe Bancontact', 'woocommerce-gateway-stripe' ); |
|
410 | - $sections['stripe_sofort'] = __( 'Stripe SOFORT', 'woocommerce-gateway-stripe' ); |
|
411 | - $sections['stripe_giropay'] = __( 'Stripe Giropay', 'woocommerce-gateway-stripe' ); |
|
412 | - $sections['stripe_ideal'] = __( 'Stripe iDeal', 'woocommerce-gateway-stripe' ); |
|
413 | - $sections['stripe_p24'] = __( 'Stripe P24', 'woocommerce-gateway-stripe' ); |
|
414 | - $sections['stripe_alipay'] = __( 'Stripe Alipay', 'woocommerce-gateway-stripe' ); |
|
415 | - $sections['stripe_sepa'] = __( 'Stripe SEPA Direct Debit', 'woocommerce-gateway-stripe' ); |
|
416 | - $sections['stripe_bitcoin'] = __( 'Stripe Bitcoin', 'woocommerce-gateway-stripe' ); |
|
409 | + $sections['stripe_bancontact'] = __('Stripe Bancontact', 'woocommerce-gateway-stripe'); |
|
410 | + $sections['stripe_sofort'] = __('Stripe SOFORT', 'woocommerce-gateway-stripe'); |
|
411 | + $sections['stripe_giropay'] = __('Stripe Giropay', 'woocommerce-gateway-stripe'); |
|
412 | + $sections['stripe_ideal'] = __('Stripe iDeal', 'woocommerce-gateway-stripe'); |
|
413 | + $sections['stripe_p24'] = __('Stripe P24', 'woocommerce-gateway-stripe'); |
|
414 | + $sections['stripe_alipay'] = __('Stripe Alipay', 'woocommerce-gateway-stripe'); |
|
415 | + $sections['stripe_sepa'] = __('Stripe SEPA Direct Debit', 'woocommerce-gateway-stripe'); |
|
416 | + $sections['stripe_bitcoin'] = __('Stripe Bitcoin', 'woocommerce-gateway-stripe'); |
|
417 | 417 | |
418 | 418 | return $sections; |
419 | 419 | } |