Feat/multi item subscriptions

SI
4mo ago
+5367-151

Summary

  • Extend subscribe() with optional addOnPlanIds so a base plan and add-ons share one Stripe Checkout session / subscription
  • Persist Stripe subscription item IDs and handle multi-item webhook updates, renewals, upgrades, and downgrades
  • Add metered pricing support and docs/e2e coverage for combined checkout and add-on flows

Summary by cubic

Add combined checkout for base plans and add-ons under one Stripe subscription and payment. Adds metered usage billing with usage reporting, hardens multi-item flows for reliability, and adds a tagged-release publish workflow.

  • New Features

    • subscribe() supports addOnPlanIds to combine base + add-ons into one Stripe Checkout/subscription.
    • Persist provider subscription item IDs and process multi-item webhooks for renewals, upgrades/downgrades, deletions; reject removing the only item; reconcile out-of-band item removals.
    • Metered pricing: define plans with price: { meteredBy, unitAmount, interval } and report usage via reportUsage().
    • New methods: addAddOn() and removeAddOn() to attach/detach add-ons on active subscriptions.
    • Reliability and validation: de-dup/limit addOnPlanIds (max 10); serialize add-on attach with an advisory lock and idempotency; paginate Stripe subscription items; reject empty checkout products; omit quantity for metered prices; enforce unitAmount >= $0.01; require metered products in usage checks; surface clear PROVIDER_OPERATION_UNSUPPORTED when provider doesn’t implement optional add/remove/report operations.
  • Migration

    • Run paykitjs push to apply 0003_add_subscription_item_id and 0004_add_metered_pricing.
    • Re-sync products so Stripe meters and metered prices are created for metered plans.
    • If you maintain a custom provider: update createSubscriptionCheckout to accept providerProducts (array). Implement (or explicitly not support) addSubscriptionItem, removeSubscriptionItem, and reportUsageEvent; unsupported operations will throw a clear error.

Summary by CodeRabbit

  • New Features

    • Combine base plans and add-ons in one checkout.
    • Add or remove add-ons from active subscriptions.
    • Support Stripe metered pricing and usage reporting.
    • Preserve subscription items during upgrades, downgrades, renewals, and cancellations.
    • Provide clearer errors for invalid subscription and usage operations.
  • Documentation

    • Added guidance for add-ons, combined checkouts, metered billing, usage reporting, quotas, and webhook behavior.
  • Tests

    • Added end-to-end coverage for add-ons, metered usage, renewals, plan changes, and subscription reconciliation.
  • Chores

    • Added automated package publishing for versioned releases.