Files
member-console/internal/stripe
..
2026-04-05 03:51:31 -05:00
2026-04-05 03:51:31 -05:00
2026-04-07 03:24:12 -05:00
2026-04-05 03:51:31 -05:00
2026-04-03 19:25:24 -05:00

Stripe Integration (internal)

This package implements the Stripe provider integration. For self-hosting setup instructions, see docs/stripe.md.

Data flow

Operator creates product/price in MC
  → Row inserted into billing schema
  → Outbox entry enqueued (integration.outbox)
  → Temporal outbox poller picks up entry
  → Stripe API call (creates Stripe object)
  → Mapping row written (stripe.*_mappings)

Stripe sends webhook
  → POST /webhooks/stripe
  → Inserted into integration.webhook_events
  → Temporal webhook processor picks up event
  → Mapping row created/updated/confirmed
  → Core billing tables updated (subscriptions, invoices, payments)

Mapping tables

Each billing entity has a corresponding mapping table in the stripe schema:

MC table Mapping table Stripe ID column
billing.products stripe.product_mappings stripe_product_id
billing.prices stripe.price_mappings stripe_price_id
billing.accounts stripe.customer_mappings stripe_customer_id
billing.subscriptions stripe.subscription_mappings stripe_subscription_id
billing.invoices stripe.invoice_mappings stripe_invoice_id
billing.payments stripe.payment_mappings stripe_payment_intent_id

Each mapping row has a sync_status: pending, synced, or deleted.

No Stripe IDs appear on core billing tables (Decision 113). The mapping tables are the only join point.

Provider config

stripe.provider_configs is a singleton row (enforced by CHECK (id = 1)) storing the account ID and mode (test/live). Credentials live in environment variables, never in the database.

Temporal workflows

Two long-running workflows in internal/workflows/stripe/:

  • stripe-outbox-poller (outbox.go) — Polls integration.outbox for pending entries, executes them (Stripe API calls), writes mapping rows. Uses ContinueAsNew.
  • stripe-webhook-processor (webhook.go) — Polls integration.webhook_events, dispatches to per-event-type handlers.

Both start automatically on member-console start.

Outbox actions

Action type Trigger Executor
create_stripe_customer Billing account creation executeCreateStripeCustomer
create_stripe_product Migration seed / operator UI executeCreateStripeProduct
create_stripe_price Migration seed / operator UI executeCreateStripePrice

Key files

  • migrations/ — Schema and mapping table DDL, seed outbox entries
  • queries/ — sqlc queries for mapping table CRUD
  • ensure_customer.go — Stripe Customer creation payload
  • internal/workflows/stripe/outbox.go — Outbox poller and executors
  • internal/workflows/stripe/webhook.go — Webhook event dispatcher and handlers
  • internal/server/stripe_webhook.go — HTTP handler for POST /webhooks/stripe