woocommerce / woocommerce-gateway-stripe

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

Double refund #838

Open LevinMedia opened 5 years ago

LevinMedia commented 5 years ago

Affected ticket(s)

N/A

What I expected

When I issue a refund, it should only be refunded once.

What happened instead

The refund doubled up

Steps to reproduce the issue

I'm running an WP.com ecomm plan, admining the order through WP-admin - Stripe is in test mode. I'm using card 4242 4242 4242 4242

I placed an order on the front end for one product with multiple items, then visited the edit order screen:

Screen Shot 2019-04-11 at 1 12 08 PM

I refunded 1 item:

Screen Shot 2019-04-11 at 1 16 24 PM

I clicked "Refund 98 cents via stripe" which resulted in a double refund

Screen Shot 2019-04-11 at 1 19 07 PM

I also see a double refund in my order notes, although the refund ID appears to be the same:

Screen Shot 2019-04-11 at 1 21 23 PM
dechov commented 5 years ago

Can you see if there's a _stripe_refund_id in the order meta (e.g. with "Post Meta Inspector" plugin)?

Edit: if there isn't, that would explain the refund being re-processed in response to the webhook – though if there is, we still won't know if it was set in process_refund or process_webhook_refund.

manojmohangit commented 5 years ago

I have also come across with similar issue. I can see _stripe_refund_id in the order meta but it has been added twice and with same refund id. I am also facing an issue with the completed order. On completion of order, I can see two _stripe_charge_captured in the order meta and also woocommerce_order_status_changed hook has been called twice.

SparkleGear commented 4 years ago

This is still an issue in the current release of WooCommerce

image

SparkleGear commented 4 years ago

Interesting that even though the refund was done through the WooCommerce dashboard, the comment sent with the refund is only on one of the refunds and the second refund says stripe dashboard.

dechov commented 4 years ago

Looks like a race condition in which the request [code] immediately triggers the webhook event, the handler for which could run the condition on order meta [code] before it actually gets set upon refund response [code]. Seems we need a more robust check for whether the refund has already been initiated in WooCommerce.

smilingpeanut commented 4 years ago

+1 to this still occurring. Had it happen for several orders on a site today with WP 5.3.2, WC 3.9.1 and Stripe 4.3.1.

dphyled commented 4 years ago

Another report of this in 18057092-hc

Screenshot Screenshot direct link: https://d.pr/i/Z0Rkhr

Now happens for every refund since update to 4.0

dechov commented 4 years ago

Tested with 4.0 and was unable to reproduce the behavior, but was able to after adding a short sleep following the request [code].

One fix that comes to mind is setting a transitory state during the request and then blocking the webhook handling. For example, _stripe_refund_id order meta could be set to some special "pending" value before the request (and unset on error), which can be checked for when the webhook comes in [here].

Another approach would be to just check if that refund ID was already stored, before proceeding with the rest of the refund processing, but the note would inaccurately say "via Stripe Dashboard".

dougaitken commented 4 years ago

https://wordpress.org/support/topic/refunds-are-recorded-twice-in-wp-admin/

mouligreenlaw commented 2 years ago

Another instance: 4579950-zen

neilmccreadie commented 2 years ago

Another instance in 25341799-hc

ArvindKumar08 commented 2 years ago

Does anybody know how these issues were resolved? I am facing the same issue with one of our sites.

polp6880 commented 2 years ago

@ArvindKumar08 my project is actually built on Roots Bedrock/Sage and all I had to do from my end was rebuild and redeploy. The issue hasn't resurfaced since. Definitely a strange one :/

glagonikas commented 2 years ago

in case it helps, the duplicates are getting assigned to the root user instead of the person who actually processed the refund. I assume this will be the case for all other examples, but it goes unnoticed because it's the same user.

image

There is a 1s difference between the two and i think this might be because of the stripe webhook (charge.refunded) firing back to us and doubles up to the API request made from the plugin to stripe

image

This would also explain why one of them is attributed to the root user. The plugin receives the webhook and thinks the order was refunded via the stripe dashboard, but doesn't know who to attribute this to, so it reverts to user id 1 or whoever is the first user of the site.

I would also imagine this only affects partial refunds because on full refunds, it can't really refund any more. I might be wrong on this however.

one solution is to stop those specific webhooks from Stripe since we never process refunds from there, however, I don't think that's the right approach, because we might process the odd one.

Ideally, the plugin should be checking the webhooks and see if the same refund id has already been recorded. if it has, it should ignore it. I can see there is an attempt to do this but i think it's probably not working correctly?

Also, the order meta have two records with the same refund id

image
foosantos commented 2 years ago

Reported on 4579950-zen.

snandos commented 2 years ago

We have the same problem: grafik

Funny enough, that we have the exact same problem with the PayPal integration too: https://github.com/woocommerce/woocommerce-paypal-payments/issues/522 Might this be a problem with WooCommerce itself?

mouligreenlaw commented 2 years ago

Another instance: 5206513-zen

Hastibe commented 2 years ago

We're also encountering this issue. I see that this was originally opened several years ago, and is still open--is there any workaround for this, until it is fixed? And/or any timeframe for it to be fixed?

samholguin commented 2 years ago

Also encountering this issue. The refund is only processed once on Stripe but showing twice on the website. Once by the user who initiated the refund and the 2nd by the root user.

buy commented 2 years ago

Now my baby is almost 1 year old, but this 2018/9 issue is still not resolved ... 😭

image
Nfinley commented 1 year ago

Also encountering this issue in the same way @samholguin mentioned. Is there a workaround?

snandos commented 1 year ago

Also encountering this issue in the same way @samholguin mentioned. Is there a workaround?

The workaround we came across was to disable the refund events on the webhook while leaving the other events enabled. This has the downside that any other refund (for example triggered via the Stripe Dashboard) won't be registered by WooCommerce See https://github.com/woocommerce/woocommerce-paypal-payments/issues/522#issuecomment-1098909297

EDIT: I'm sorry, just saw that @glagonikas already mentioned this approach.

xue28 commented 1 year ago

6191782-zen

stoltzrx commented 1 year ago

6359414 - zen

Guilm commented 1 year ago

:)

EjayhanFernandes commented 1 year ago

6639400-zen

ChrissiePollock commented 1 year ago

6634648-zen

kaushikasomaiya commented 5 months ago

8152570-zen

Nemi5150 commented 5 months ago

Same problem here. I wish there was a way through the interface to disable the refund webhook, but I don’t see one and I am hesitant to disable in code.

Snaacks commented 4 months ago

Zen-8273116

wjrosa commented 4 months ago

I tried to reproduce the issue here with no success. I tried using the latest versions of WC and the Stripe extension. With the "legacy checkout experience" enabled and disabled. Webhook calls are received, but the double refund does not happen because of this line (includes/class-wc-stripe-webhook-handler.php#603):

            // If the refund ID matches, don't continue to prevent double refunding.
            if ( $refund_object->id === $refund_id ) {
                return;
            }

It was added on this PR. So maybe some of the users affected above had an older version of the extension. Still, does not explain the latest reports.

shameemreza commented 3 months ago

Another report here: 8377624-zd