wasp-lang / open-saas

A free, open-source SaaS app starter for React & Node.js with superpowers. Full-featured. Community-driven.
https://opensaas.sh
MIT License
8.19k stars 791 forks source link

check what happens if webhook fails when sending subscription status #198

Open vincanger opened 4 months ago

vincanger commented 4 months ago

how do we ensure then that our subscription statuses in our DB are in sync with Stripe's?

Martinsos commented 4 months ago

To explain a bit more: we "cache" status of subscription in User entity, under subscriptionStatus. The realy truth about the status is however on Stripe. We rely on Stripe webhooks to let us know then that status changes, so we update the value in User. But, what if that fails for some reason? We believe that Stripe will try multiple attempts if webhooks are not getting true, but what if server is down long enough for Stripe to give up? Is there a way to tell Stripe to resend all webhooks that never went through on server start (well that might also be challenging to resolve then but ok). Or should we have some conditions (server start, long time since last update) on which we decide to manually check if state is in sync? Stripe might have some docs on best practices here, as I would expected this is a common issue.

vincanger commented 2 months ago

@Martinsos so apparently stripe resends failed webhook events with exponential backoff.

This article explains how to check which webhook events have failed and manually retrigger them, if desired: https://daniellockyer.com/how-to-resend-failed-stripe-webhooks/

Martinsos commented 2 months ago

Nice, that means that likely exponential backoff will help, but if server has been down for a longer time, we should do something manual, possibly what they describe in that article.