Skip to content

Implement backend support for recurring subscriptions #331

@yuvraj-shishodia

Description

@yuvraj-shishodia

Description

Implement backend support for recurring subscriptions while keeping the existing
one-time donation flow fully intact. This includes new authenticated endpoints
for setup intents and subscription creation, per-campaign Stripe product and
price management, and webhook updates to persist subscription and invoice data
in Firestore.


Scope

Backend Endpoints

  • Add createSetupIntent.ts HTTPS function to:
    • Verify Firebase ID token
    • Ensure or reuse a Stripe customer
    • Return SetupIntent clientSecret and customerId for saving payment methods
  • Add createSubscription.ts HTTPS function to:
    • Verify authentication
    • Get or create a recurring Stripe price per campaign and interval
    • Attach payment method to customer
    • Create Stripe subscription
    • Return subscription status or paymentIntentClientSecret when 3DS is required
  • Export new functions from index.ts
  • Add shared request/response types in subscription.ts (+ index export)

Subscription & Pricing Logic

Campaign Products

  • Use a per-campaign Stripe product
  • Store product ID on {campaignId}.billingProductId
  • Create the product if missing, then reuse for all recurring prices

Pricing

  • Support recurring intervals:
    • Monthly (1 month)
    • Quarterly (3 months)
    • Yearly (1 year)
  • Currency defaults to EUR
  • Custom donation amounts supported:
    • Server accepts amount in minor units
    • Matching recurring price is created or reused on the campaign product

Webhook Integration

  • Extend handleStripeWebhook.ts to:
    • Upsert subscriptions/{subscriptionId} documents
    • Upsert donations/{invoiceId} documents for recurring invoices
    • Increment campaign totals once per successful invoice (idempotent)
  • Preserve existing one-time donation handling for
    payment_intent.succeeded without changes

Acceptance Criteria

  • SetupIntent endpoint implemented and authenticated
  • Subscription creation endpoint implemented and authenticated
  • Per-campaign Stripe product created and reused correctly
  • Dynamic recurring prices supported per amount and interval
  • Monthly, quarterly, and yearly subscriptions supported
  • Webhook persists subscriptions and invoice-backed donations
  • Campaign totals incremented idempotently
  • One-time donation flow remains unchanged
  • No regressions introduced

Notes

  • Frontend wiring for recurring donations will be tracked separately
  • Relies on existing Stripe webhook infrastructure and Firestore schema

Metadata

Metadata

Assignees

No one assigned

    Labels

    BackendBackend authenticationsP1-HighImportant for milestonePaymentPayment ProcessenhancementNew feature or requestsize:XL1+ month

    Type

    No type

    Projects

    Status

    Todo

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions