Skip to content

0.1.8: Fix webhook payment detection, retries, and logging - #78

Open
michaelshimeles wants to merge 2 commits into
mainfrom
fix/webhook-correctness
Open

michaelshimeles wants to merge 2 commits into
mainfrom
fix/webhook-correctness

Conversation

@michaelshimeles

Copy link
Copy Markdown
Collaborator

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.succeeded now finds the payment's invoice through the Invoice Payments API. Stripe removed PaymentIntent.invoice in API version 2025-03-31.basil, so on any current webhook endpoint the subscription check never matched and every renewal was saved to payments as a one-time payment. Payloads that still carry the old field use it directly.
  • The two catch blocks in processEvent that logged and kept going are gone. If the subscription or invoice read during checkout.session.completed fails, 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.
  • Webhook logs use fixed messages plus the event ID and type. The raw errors could include the payload, the signature header, Stripe response headers, or customer fields from a rejected mutation. A new onError option on registerRoutes receives the error, the stage, and the verified event so apps can report it themselves. If onError throws, the response doesn't change.
  • Invoices without a customer are skipped instead of failing 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.
  • Includes fix(component): treat canceled as terminal in handleSubscriptionUpdated #68, cherry-picked with its author, so an older customer.subscription.updated can't revive a canceled subscription.

Fixes #76.

Testing

  • npm run build, npm test (55 passing), npm run typecheck, npm run lint.
  • New tests cover renewals linked through invoice payments, one-off invoice payments, the legacy field, propagated lookup failures, invoices with no customer, and expanded customer objects. The route tests feed errors that carry a fake email, signature, and request ID, and check that none of them reach the console.

BrandonShutter and others added 2 commits November 3, 2026 16:40
…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>
@pkg-pr-new

pkg-pr-new Bot commented Nov 3, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/@convex-dev/stripe@78

commit: 115a872

@michaelshimeles
michaelshimeles marked this pull request as ready for review November 3, 2026 22:01
@michaelshimeles
michaelshimeles added this pull request to stack #83 November 3, 2026 22:02

This branch has not been deployed

No deployments
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

Successfully merging this pull request may close these issues.

Avoid logging raw webhook errors containing customer data and signature headers

2 participants