Repository navigation
feat(billing): Paddle webhooks + applyBillingEvent (L3) - #7613
Merged
Merged
Conversation
/api/webhooks/paddle verifies Paddle-Signature (HMAC-SHA256 over ts:body, constant-time, 5-minute window, any h1 during rotation; fails closed without config), normalizes subscription/transaction/adjustment events into the provider-neutral seam types, and applies each exactly once through the shared (provider, event_id) ledger. applyBillingEvent writes organization_billing under an occurred_at watermark (no regression from out-of-order or replayed events, no revival of a canceled subscription, one subscription per slot, never over a live Stripe one), keeps the paddle_transaction mirror, grants credit packs once and reverses them on a full refund or chargeback, and alerts the operator on chargebacks, partial refunds and org mismatches. custom_data is untrusted: the row holding the subscription decides the org; custom_data only names one that exists. A Paddle past_due subscription keeps its plan for a 7-day grace (entitlementStatus), wired into the entitlement readers; Stripe rows are unchanged. The Paddle adapter is registered in the seam with parseWebhook; purchase/plan/usage methods throw until L4/L5.
Merge Protections🟢 All 2 merge protections satisfied — ready to merge. Show 2 satisfied protections🟢 dev required CI
🟢 🚦 Auto-queueWhen all merge protections are satisfied and these conditions match, this pull request will be queued automatically.
|
✅ Merged into
|
This was referenced Nov 25, 2026
Closed
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.
Lane L3 of the Paddle Billing plan (after L1 #7499). No migration.
What
app/api/webhooks/paddle/route.ts— verify → normalize → apply exactly once via the shared(provider, event_id)ledger. 503 without (or with an unloadable) Paddle config; 400 on a bad signature; 200 on an applied, ignored or deliberately refused event; 500 on a parse failure, a store failure, or an adjustment whose transaction is not mirrored yet (Paddle redelivers); 413 above 512 KB.lib/billing/paddle/signature.ts—Paddle-Signature(ts+ one or moreh1), HMAC-SHA256 overts:rawBody, constant-time, ±5 min window.lib/billing/paddle/events.ts— zod schemas (loose objects, noas) and normalization into the seam's event types. Plan or AI tier comes from configured price ids, never from custom_data. custom_data that does not parse is dropped.lib/billing/paddle/provider.ts— the Paddle adapter, registered inselect.ts.parseWebhook,modeandisConfiguredwork; the purchase/plan methods (L4) and the usage/document methods (L5) throwPaddleNotImplementedError.lib/billing/events/apply.ts+store.ts— provider-neutralapplyBillingEvent(pure decision core plus a store port) and its Postgres store.lib/billing/plan.tsentitlementStatus— the 7-daypast_duegrace for Paddle rows only, wired intoresolveOrgEntitlements, the usage guard, the usage and members procedures, and the workspace plan label. Stripe rows behave exactly as before.Event → state
subscription.created/updated/activated/trialing/resumed(active/trialing)cancel_effective_atfrom a scheduled cancel (row stays active to that date)subscription.past_duestatus=past_due, plan kept → granted for 7 days from period start, then not; AI tier →ai_free(no grace)subscription.pausedstatus=none, plan → communitysubscription.canceledstatus=canceled, plan → community, never revived by a stale eventtransaction.completedai_credit_grantonce per txn (pack size must be one we sell)transaction.paid/past_due/payment_failedadjustment.*approved refund (full)refunded_at; pack credits zeroedchargeback_at, pack credits zeroed, operator alertGuards: an
occurred_atwatermark per slot and per mirrored transaction (same-instant tie → later lifecycle stage); one subscription per slot (a paid sub supersedes onlypast_dueor a sub-less grant, with an alert); a row with a live Stripe subscription is refused and alerted (dead Stripe ids are cleared); the org is the row already holding the subscription, otherwise the custom_data org if it exists; a mismatch is refused and alerted; a business id held by another org is not copied.Tests
Unit: signature, normalizer,
applyBillingEvent(in-memory store: out-of-order, duplicate, unknown org, mismatch, adjustment reversal, …), route, adapter, grace. Integration: the Postgres store against the real schema and constraints.Left for later lanes
L4: branded lifecycle emails (welcome/dunning/cancel) for Paddle; writing
paddle_business_id/address at checkout; billing UI for past_due grace andcancel_effective_at. L5: usage charges and documents.