medusajs / medusa

The world's most flexible commerce platform.
https://medusajs.com
MIT License
25.7k stars 2.56k forks source link

Stripe Plugin - unreachable API hook endpoint #4333

Open danicapivalicaabram opened 1 year ago

danicapivalicaabram commented 1 year ago

Bug report

Describe the bug

After setting up the medusa-payment-stripe (v1.1.48) plugin, we are unable to automatically capture payment in production.

Our Stripe webhook reports a 100% error rate and our medusa backend logs show returning only 404s on the expected route (POST /stripe/hooks). We have some medusa server customisations which work as expected and for now are using a somewhat older version of medusa (v1.7.0).

In terms of the other plugin functionality, Stripe is available in our regions and we are able to use it in our checkout flow. We are also able to manually capture payment which works as expected.

System information

Medusa version (including plugins):

Steps to reproduce the behavior

We are able to produce the behaviour every time we buy something via the custom storefront, however direct API calls to the expected endpoint also produce a 404 status.

Expected behavior

Automatic capture of payment via stripe.

adrien2p commented 1 year ago

It would be nice to share the error you get on the webhook because the error rate being high can be expected if the cart completion and the webhook are triggered at the same time. We have had multiple discussions around that subject on Discord that have been resolved. The reason is that the webhook is mainly here in case the customer loose his connection to the internet and in that case the webhook can take the relay to ensure the order is being created. In the other case, since the transaction are serializable, if the cart completion is started we expected the webhook to fail because of a concurrent serialize request. In regards to the 404 I will have a look, it has not been reported, I ll need to switch to the old version to see if I can reproduce this locally as well and will let you know.

adrien2p commented 1 year ago

Found the issue, I suggest you upgrade stripe version to 1.1.49, unfortunately, version 1.1.48 introduced a bug by trying to import medusa utils from medusa src which has been resolved in the follow-up versions. Keep me posted 👍

danicapivalicaabram commented 1 year ago

Hi @adrien2p thanks for the response!

I saw the discussions on concurrent serialise requests, however I did not notice us having any issues like that. Our server did not have any error logs and the only thing we noticed is 404s for the stipe hook endpoint. This happened on every request towards the hook, which is what seemed really strange. I wondered could we have caused the issue by adding custom APIs to the server (probably not but still worth noting).

We will upgrade to a newer version, I just wanted to check if perhaps this might be a known issue. Might help someone in the future to know.

adrien2p commented 1 year ago

@danicapivalicaabram as I mentioned, it is a known issue in 1.1.48, but you should be good to go with the version above

raukaute commented 1 year ago

Hey.

Came here because we're facing the same issue. Went live over the weekend and stripe hooks are not working. All 404.

Medusa version 1.16

Payment-Stripe: 6.0.3

piereligio commented 10 months ago

Hey.

Came here because we're facing the same issue. Went live over the weekend and stripe hooks are not working. All 404.

Medusa version 1.16

Payment-Stripe: 6.0.3

Same here about the 404 errors, also on PayPal payment plugin. It's in generally working fine though, except that paypal payments sometimes remain on hold, and I wonder if this issue has to do with that. On stripe seems like they don't go through when this issue happens

olivermrbl commented 10 months ago

@raukaute @piereligio, did you manage to successfully set up the webhook locally?

raukaute commented 10 months ago

@raukaute @piereligio, did you manage to successfully set up the webhook locally?

To my own shame I have to admit that my initial problem was due to setting up the webhook url on paypals side incorrectly. 🙈

However, it still seems kind of unstable/ unreliable for reasons I find hard to track... Looking into my prod server logs I see a lot of failed attempts to post to v2/payments/authorizations/:id. I dont know what exactly is triggering these POST requests as I can not see any checkout activity in the DB related to this.

piereligio commented 10 months ago

@raukaute @piereligio, did you manage to successfully set up the webhook locally?

To my own shame I have to admit that my initial problem was due to setting up the webhook url on paypals side incorrectly. 🙈

However, it still seems kind of unstable/ unreliable for reasons I find hard to track... Looking into my prod server logs I see a lot of failed attempts to post to v2/payments/authorizations/:id. I dont know what exactly is triggering these POST requests as I can not see any checkout activity in the DB related to this.

What error did you do? It's possible it's an error I did as well. I basically set up the webhook as https://mybackenddomain.url/paypal/hooks . I think the POST requests are sent to the server, and not the opposite. It seemed to me that it was a request done from paypal. On the failed payments, it occurs something like 40 times, on successful ones, 16. Yeah there is something odd about this. @olivermrbl Locally I had some trouble with the hooks as well, but I got around them setting up a webhooks.site endpoint.

More specifically, I'm in the situation reported in #4577 . This for sure is happening with paypal plugin, while on stripe while i see some failed purchase, I didn't receive any report from it. So I guess stripe is "failing successfully" at least ahah In both cases it's a thing that only occasionally happens, in the case of paypal, once around every 6 payments

piereligio commented 10 months ago

Should I try to see what happens changing payment plugin versions? I think the 404 errors aren't what cause the issue, because only every X purchases the issue will appear, it's quite random, while the 404 errors are there all the time. So I don't really know what to do. It's even possible that the issue relies in medusa itself, in theory, in how the transaction is handled. Hints for logging it properly?