Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

You should not use waitUntil, Stripe will wait for your webhook response before redirecting, removing the need for a success page that checks that Stripe already sent the webhook #15

Open
remorses opened this issue Jan 29, 2025 · 6 comments

Comments

@remorses
Copy link

From Stripe docs https://docs.stripe.com/checkout/fulfillment?payment-ui=stripe-hosted#redirect-hosted-checkout:

When you have a webhook endpoint set up to listen for checkout.session.completed events and you set a success_url, Checkout waits for your server to respond to the webhook event delivery before redirecting your customer. If you use this approach, make sure your server responds to checkout.session.completed events as quickly as possible.

@remorses remorses changed the title You should not use waitUntil, Stripe will wait for your webhook response before redirecting, removing the need for a success page that checks that Stripe already sent the webhook You should not use waitUntil, Stripe will wait for your webhook response before redirecting, removing the need for a success page that checks that Stripe already sent the webhook Jan 29, 2025
@odicho
Copy link

odicho commented Jan 30, 2025

That's exactly what waitUntil is for! It allows you to queue the processing so it doesn't block you from proceeding, which allows us to return ASAP. The waitUntil allows the processing to finish asynchronously before shutting down the function.

https://vercel.com/changelog/waituntil-is-now-available-for-vercel-functions

@remorses
Copy link
Author

If you use waituntil Stripe will redirect the user before you saved the subscription in your database

@odicho
Copy link

odicho commented Jan 30, 2025

That's what syncStripeDataToKV is for. It will always call Stripe's API to check the subscriptions. Even if you get redirected to /success/ before the webhook is fully processed, we still check the subscriptions via the Stripe API.

I think the overall strategy is to use the webhooks as a trigger to go check the Stripe API. This way, we don't have to rely on the data that comes from the webhooks.

@santiagopuentep
Copy link

From Stripe docs https://docs.stripe.com/checkout/fulfillment?payment-ui=stripe-hosted#redirect-hosted-checkout:

When you have a webhook endpoint set up to listen for checkout.session.completed events and you set a success_url, Checkout waits for your server to respond to the webhook event delivery before redirecting your customer. If you use this approach, make sure your server responds to checkout.session.completed events as quickly as possible.

This is simply not truth. I just checked blocking all webhook responses (never responding to anything) and the checkout session redirects in the same way, so the Stripe docs seem to be wrong. I'm simply responding as soon as possible (since it has no effect) and saving the data in my db afterwards.

@remorses
Copy link
Author

remorses commented Feb 5, 2025

How much time did it take to redirect? Maybe there is a timeout

@santiagopuentep
Copy link

How much time did it take to redirect? Maybe there is a timeout

It redirects after it does whatever background job it has to do, no matter your response to any of the webhooks (you receive multiple webhooks while it's processing the checkout).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants