Skip to content

feat(core): add a provider-neutral subscription seam - #114

Open
alexasomba wants to merge 12 commits into
emdashCommerce:mainfrom
alexasomba:feat/provider-subscriptions
Open

alexasomba wants to merge 12 commits into
emdashCommerce:mainfrom
alexasomba:feat/provider-subscriptions

Conversation

@alexasomba

@alexasomba alexasomba commented Nov 25, 2026 •

Copy link
Copy Markdown

Part of the Flutterwave follow-up in #97. First half of subscriptions: the core seam. The Flutterwave Payment Plans package follows in #107.

Why

Flutterwave supports subscriptions through Payment Plans, but core's subscription engine is Stripe Billing-specific: Subscription.stripeSubscriptionId, subscriptions/lifecycle.ts calls Stripe directly, and the webhook path only understands Stripe subscription events. A provider package cannot plug into that.

This adds an additive seam for providers that manage billing themselves. Stripe keeps its current path and behaviour.

What

  • PaymentProvider gains optional getSubscription, cancelSubscription and resumeSubscription.
  • ProviderSubscriptionInfo is the normalised state (provider subscription id, status, period, amount, interval).
  • charge.succeeded and PaymentStatusResult can carry subscription. A provider reports the plan/subscription behind the charge.
  • subscriptions/provider.ts stores provider-managed subscriptions and invoices in the existing collections:
    • the first charge creates an order and a local subscription;
    • a later charge is recorded as a paid invoice and extends the period, not as a second order;
    • the provider/plan id and the invoice id are scoped by provider in the unique storage key, so a different provider cannot claim them.
  • subscriptions/lifecycle.ts dispatches cancel/resume to the provider for a provider-managed subscription. Pause and in-place plan changes are refused when the provider does not support them.
  • subscription.updated is a normalised event for a cancellation or status change outside a charge; core updates the local row.
  • Admin and customer portal hide pause and the Stripe billing portal for provider-managed subscriptions, and show Resume for a canceled provider-managed one.
  • Admin and public routes no longer require a Stripe client before they know which provider owns the subscription.

Compatibility

stripeSubscriptionId and stripeInvoiceId keep their names for now; they hold the provider's subscription/plan and invoice id. The changeset documents this. A rename can be a separate pre-1.0 cleanup.

Tests

  • 13 new tests: month-end interval clamping; first charge creates order + subscription; renewal records an invoice and extends the period without a second order; provider id isolation; cancel/resume dispatch; pause refusal; subscription.updated applies a cancellation; the Stripe portal refuses a provider-managed subscription; a paid invoice does not extend the period twice; a no-draft renewal is resolved through getPaymentStatus; an unrelated no-draft charge is acknowledged and ignored; a subscription cart with vendor items is refused.
  • 328 core tests pass on upstream/main, 0 failures.
  • Typecheck clean.
  • Changeset: minor.

Next

The Flutterwave package creates one payment plan per subscription, passes payment_plan on checkout, reports plan from verify/webhook, and cancels via PUT /v3/payment-plans/{id}/cancel. That lands in #107.

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.

1 participant