My sync library was tested in CI against a fake Stripe. That proves the logic, not the integration. So I ran it against a real Stripe test account.
The run: create a product, a price, a customer and a subscription, then call reconcileRecent and check Postgres after each step.
- First run: the row is written.
- Second run, nothing changed in Stripe: no write, revision stays 1.
- Price change: revision goes to 2.
-
cancel_at_period_end, then cancel: both land.
12 of 12 checks passed. The script is in the repo (scripts/e2e-real-stripe.mjs) and refuses any key that isn't sk_test_.
What the mocks hid
The first attempt failed with unlinked_customer. The default user resolver looks up a stripe_customer_links row to know which user owns a Stripe customer. If you only run the scheduled reconcile and never process a checkout event, that row doesn't exist, so every subscription is skipped. In my fake setup the row was always there. The fix is one README line, since the library can't guess which user owns a customer.
Why a scheduled reconcile matters
Stripe retries a failed delivery with exponential backoff for up to 3 days. A reader pointed this out after running three lock variants against my load test. It means an event that fails once can leave the row behind Stripe for minutes or hours. A scheduled reconcileRecent run closes that gap.
What I haven't tested
- Test mode only, one subscription.
- The Vercel Cron route isn't deployed yet. I ran the plain Node script from the README instead.
- No live-mode run.
Code and tests (MIT): https://github.com/navalpro8-lgtm/stripe-subscription-sync
If you've hit other things a fake Stripe wouldn't show, tell me.
Top comments (9)
the unlinked_customer skip is a good catch. I'd also keep those skipped Stripe ids and the as-of of that reconcile, instead of dropping them quietly. a later run can try the link again, and until it finds one I wouldn't treat the skip as proof that the subscription isn't yours. fail closed on that pending row rather than leaving entitlements unapplied.
Fair point. reconcileRecent returns those as failed with reason
unlinked_customerinstead of dropping them, and the next run retries them while the event is still within Stripe's roughly 30 days. Nothing is stored, so you'd have to log them yourself. A pending row that fails closed isn't built. I'll add that to the limitations doc.yeah, that's the part that worried me about not storing them. stripe will only let you retry for about 30 days, and after that there's no list of which ids still need a link.
a small log of the event id, the reason, and the as-of would let a later run keep trying once the window is gone, and keep that pending row failed closed until it actually links. putting that in the limitations doc makes sense until the log exists.
bro if u have have spare 10 mins try running it and tell me where it breaks i would appriciate honest reviews
i can't actually run it against your account from here. what would help a reviewer most is a recorded unlinked_customer event and the reconcile output from that run, so it's obvious whether those ids stay listed after the skip, and whether the pending row stays failed closed until it links.
Stripe doesn't guarantee event order, so in live mode subscription.updated can land before checkout.session.completed and the subscription gets skipped even with your checkout handler working. Worth an e2e variant that fires the events backwards on purpose, imo. fwiw I built Webhook Relay, it stores every delivery and retries the failed ones with backoff.
I have a test for that order: subscription.created before checkout.session.completed returns a 500 and writes nothing, then the checkout event links the customer and the redelivered created event writes the row. So Stripe's retry covers it. Live mode with real timing is the part I haven't run.
The unlinked_customer catch is exactly the kind of thing a fake Stripe makes invisible. The scheduled reconcile is underrated too: with Stripe retrying deliveries for up to 3 days, one missed event can leave the row stale for hours. Have you thought about reconciling invoice events as well, so a failed renewal shows as past_due even if the subscription webhook was the one that went missing?
Invoice events already take the same path. invoice.paid and invoice.payment_failed re-fetch the subscription and write that. Reconcile lists customer.subscription.* events. A failed renewal moves the subscription to past_due, which creates a subscription.updated event in Stripe even if my webhook never got it, so the next reconcile catches it. I haven't tested that exact case yet, thanks for pointing at it.