Repository navigation
0.1.8: Fix webhook payment detection, retries, and logging - #78
Open
michaelshimeles wants to merge 2 commits into
Open
michaelshimeles wants to merge 2 commits into
michaelshimeles wants to merge 2 commits into
Conversation
…ated `handleSubscriptionUpdated` fetches the existing subscription row and then ignores it, patching `status` unconditionally. Stripe does not guarantee webhook ordering and retries failed deliveries for up to three days, so an older `customer.subscription.updated` carrying `status: "active"` can be delivered after `customer.subscription.deleted` and rewrite the row back to active. The row then contradicts Stripe indefinitely — nothing corrects it until some later event happens to arrive — so an application gating access on `listSubscriptionsByUserId` keeps serving a customer who has cancelled. Reproducible against real infrastructure with `stripe events resend` on an `updated` event after the subscription is deleted, not only in tests. `canceled` is already terminal in Stripe's own model: a cancelled subscription never returns to an active state, because resubscribing mints a new subscription id. So ignoring a non-canceled update to a canceled row does not change semantics — it stops the component's cache disagreeing with Stripe. Deliberately narrow. Only resurrection is blocked; a redelivered `canceled` update still refreshes the row's other fields, which the second test asserts. `handleSubscriptionDeleted` is unchanged, since forcing `canceled` is always correct. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
- payment_intent.succeeded finds the invoice through the Invoice Payments API. PaymentIntent.invoice no longer exists from API version 2025-03-31.basil, so subscription renewals were being recorded as one-time payments. - Failures while syncing a checkout's invoice or checking a payment's invoice now propagate, so the route returns 500 and Stripe redelivers instead of getting a 200 for an incomplete sync. - Webhook logs use fixed messages plus the event ID and type. Raw errors could include the payload, signature header, or customer fields (#76). A new onError option hands the error to the app. - Invoices without a customer are skipped instead of failing validation, and expanded Stripe objects in payloads are read by ID. Co-authored-by: Cursor <cursoragent@cursor.com>
commit: |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
First of five stacked PRs. This one and the next two make up the 0.1.8 patch on the current Stripe v22 SDK. The fourth is the 0.2.0 breaking release, and the fifth adds webhook dedupe and ordering on top of it.
What changed
payment_intent.succeedednow finds the payment's invoice through the Invoice Payments API. Stripe removedPaymentIntent.invoicein API version2025-03-31.basil, so on any current webhook endpoint the subscription check never matched and every renewal was saved topaymentsas a one-time payment. Payloads that still carry the old field use it directly.catchblocks inprocessEventthat logged and kept going are gone. If the subscription or invoice read duringcheckout.session.completedfails, or the invoice lookup for a payment fails, the route now returns 500 so Stripe redelivers. Before, it returned 200 and the sync stayed incomplete.onErroroption onregisterRoutesreceives the error, the stage, and the verified event so apps can report it themselves. IfonErrorthrows, the response doesn't change.v.string()validation and retrying for days. Customer, subscription, invoice, and payment intent references now go through one helper that accepts an ID, an expanded object, or null.customer.subscription.updatedcan't revive a canceled subscription.Fixes #76.
Testing
npm run build,npm test(55 passing),npm run typecheck,npm run lint.