woocommerce / woocommerce-gateway-stripe

The official Stripe Payment Gateway for WooCommerce
https://wordpress.org/plugins/woocommerce-gateway-stripe/
229 stars 197 forks source link

WC_Stripe_API::detach_payment_method_from_customer() must be of the type string, null given #2615

Open glagonikas opened 1 year ago

glagonikas commented 1 year ago

Describe the bug We're coming across a number of errors in our logs stating the following

[10-May-2023 06:51:31 UTC] PHP Notice:  Undefined property: stdClass::$source in /home/site/public_html/wp-content/plugins/woocommerce-gateway-stripe/includes/class-wc-stripe-intent-controller.php on line 137
[10-May-2023 06:51:31 UTC] PHP Notice:  Trying to get property 'id' of non-object in /home/site/public_html/wp-content/plugins/woocommerce-gateway-stripe/includes/class-wc-stripe-intent-controller.php on line 137
[10-May-2023 06:51:31 UTC] PHP Fatal error:  Uncaught TypeError: Argument 2 passed to WC_Stripe_API::detach_payment_method_from_customer() must be of the type string, null given, called in /home/site/public_html/wp-content/plugins/woocommerce-gateway-stripe/includes/class-wc-stripe-customer.php on line 472 and defined in /home/site/public_html/wp-content/plugins/woocommerce-gateway-stripe/includes/class-wc-stripe-api.php:327
Stack trace:
#0 /home/site/public_html/wp-content/plugins/woocommerce-gateway-stripe/includes/class-wc-stripe-customer.php(472): WC_Stripe_API::detach_payment_method_from_customer()
#1 /home/site/public_html/wp-content/plugins/woocommerce-gateway-stripe/includes/class-wc-stripe-intent-controller.php(137): WC_Stripe_Customer->delete_source()
#2 /home/site/public_html/wp-includes/class-wp-hook.php(308): WC_Stripe_Intent_Controller->verify_intent()
#3 /home/site/public_html/wp-includes/class-wp-hook.php(332): WP_Hook->apply_filters()
#4 /home/site/public_html/wp-includes/plugin.php(517): WP_Hook->do_action()
#5 /home/site/publi in /home/site/public_html/wp-content/plugins/woocommerce-gateway-stripe/includes/class-wc-stripe-api.php on line 327
[10-May-2023 06:51:31 UTC] PHP error triggered at: https://www.site.com/?wc-ajax=wc_stripe_verify_intent&order=3710233&nonce=XXXXX&redirect_to=https%3A%2F%2Fwww.site.com%2Fcheckout%2Forder-received%2FXXXXX%2F%3Fkey%3Dwc_order_XXXXX%26utm_nooverride%3D1&save_payment_method=1&is_ajax
[10-May-2023 06:51:31 UTC] PHP error message: Array
(
    [type] => 1
    [message] => Uncaught TypeError: Argument 2 passed to WC_Stripe_API::detach_payment_method_from_customer() must be of the type string, null given, called in /home/site/public_html/wp-content/plugins/woocommerce-gateway-stripe/includes/class-wc-stripe-customer.php on line 472 and defined in /home/site/public_html/wp-content/plugins/woocommerce-gateway-stripe/includes/class-wc-stripe-api.php:327
Stack trace:
#0 /home/site/public_html/wp-content/plugins/woocommerce-gateway-stripe/includes/class-wc-stripe-customer.php(472): WC_Stripe_API::detach_payment_method_from_customer()
#1 /home/site/public_html/wp-content/plugins/woocommerce-gateway-stripe/includes/class-wc-stripe-intent-controller.php(137): WC_Stripe_Customer->delete_source()
#2 /home/site/public_html/wp-includes/class-wp-hook.php(308): WC_Stripe_Intent_Controller->verify_intent()
#3 /home/site/public_html/wp-includes/class-wp-hook.php(332): WP_Hook->apply_filters()
#4 /home/site/public_html/wp-includes/plugin.php(517): WP_Hook->do_action()
#5 /home/site/publi
    [file] => /home/site/public_html/wp-content/plugins/woocommerce-gateway-stripe/includes/class-wc-stripe-api.php
    [line] => 327
)

Steps to reproduce While in test mode use cards 4000000000003220 or 4000000000003063, and when the 3ds modal comes up fail the validation. That will result in a payment intent response from the API with an last_payment_error object that does not contain the source. This can be reproduced on vanilla installation.

Additional Context In the comment found here https://github.com/woocommerce/woocommerce-gateway-stripe/blob/12f1e41fe65632fee47156545efdbdd46c3a621e/includes/class-wc-stripe-intent-controller.php#L133-L135 you state that Stripe "Stripe saves the payment method even if the authentication fails for 3DS cards.". This has probably changed and it's what's causing this fatal?

Environment (please complete the following information):

nicomollet commented 1 year ago

Exactly the same problem for me.

duotive commented 1 year ago

This happens for us too.

andreDane commented 1 year ago

Same for us:

Uncaught TypeError: WC_Stripe_API::detach_payment_method_from_customer(): Argument #2 ($payment_method_id) must be of type string, null given, called in /woocommerce-gateway-stripe/includes/class-wc-stripe-customer.php on line 472 and defined in /woocommerce-gateway-stripe/includes/class-wc-stripe-api.php:327 Stack trace: #0 /woocommerce-gateway-stripe/includes/class-wc-stripe-customer.php(472): WC_Stripe_API::detach_payment_method_from_customer() #1 /woocommerce-gateway-stripe/includes/class-wc-stripe-intent-controller.php(132): WC_Stripe_Customer->delete_source() #2 /wp-includes/class-wp-hook.php(308): WC_Stripe_Intent_Controller->verify_intent() #3 /wp-includes/class-wp-hook.php(332): WP_Hook->apply_filters() #4 /wp-includes/plugin.php(517): WP_Hook->do_action() #5 /woocommerce/includes/class-wc-ajax.php(96): do_action() #6 /wp-includes/class-wp-hook.php(308): WC_AJAX::do_wc_ajax() #7 /wp-includes/class-wp-hook.php(332): WP_Hook->apply_filters() #8 /wp-includes/plugin.php(517): WP_Hook->do_action() #9 /wp-includes/template-loader.php(13): do_action() #10 /wp-blog-header.php(19): require_once('...') #11 /index.php(17): require('...') #12 {main} thrown in /woocommerce-gateway-stripe/includes/class-wc-stripe-api.php at row 327

glagonikas commented 1 year ago

@nicomollet @duotive @andreDane do you also see paid orders going into pending / failed?

My PR seems to be resolving the issue and we've not seen any unexpected behaviour so far.

Also, you have more than one gateways? Like Braintree etc?

I'm trying to debug another (possibly related) bug...

kaushikasomaiya commented 11 months ago

Spotted in 6523490-zen while investigating a different issue.

kaushikasomaiya commented 11 months ago

6585471-zen

sybrew commented 10 months ago

This happens when the customer tries to delete their old payment method after a payment has failed.

In WC_Stripe_Intent_Controller::verify_intent(), NULL is passed to WC_Stripe_Customer::delete_source() at code:

$customer = new WC_Stripe_Customer( wp_get_current_user()->ID );
$customer->delete_source( $intent->last_payment_error->source->id )

I'm not sure why an error would be used to fetch the ID, but in any case, a few lines prior, isset( $intent->last_payment_error ) is tested, while $intent->last_payment_error->source->id is used. I recommend extending the test to verify the children-objects' properties or otherwise always falling back to the actual metadata instead of the error.

--

Edit: looking more closely... what does that code even do when we already rely on woocommerce_payment_token_deleted?

shaunkuschel commented 9 months ago

[Internal] We received another report of this on 6712627-zen

kaushikasomaiya commented 8 months ago

7238549-zen

grig-23 commented 7 months ago

7360317-zen - on this site, when a payment fails, a duplicate card entry is created under "payment methods" which is quite odd:

Screenshot 2023-12-04 at 11 23 50

The duplicate payment method does not work, but the original one often does if the customer retries a payment.

This is the error:

Argument 2 passed to WC_Stripe_API::detach_payment_method_from_customer() must be of the type string, null given, called in /home/sportin1/public_html/wp-content/plugins/woocommerce-gateway-stripe/includes/class-wc-stripe-customer.php on line 489 and defined in /home/sportin1/public_html/wp-content/plugins/woocommerce-gateway-stripe/includes/class-wc-stripe-api.php:327

OmarFPG commented 3 months ago

7950081-zd

carolframen commented 2 months ago

8062147-zen

Snaacks commented 1 month ago

8219514-Zen appears to be experiencing this issue as well, may also be a secondary issue involved.

dcx15 commented 3 weeks ago

I am seeing the same error in my site's logs too

csnlima1 commented 3 weeks ago

zen - 8311446