Beacon

Billing API

View as Markdown

Billing API

Core endpoints for checkout creation, subscription confirmation, and customer portal.

reference • updated 2026-03-15

Goal

Operate the full recurring billing lifecycle: start checkout, confirm post-payment state, and provide self-service access with organization-level traceability.

Endpoints and operational contract

EndpointWhen to useKey requirements
POST /v1/billing/subscription-checkoutsstart a new subscription or upgradeBearer token, valid plan, Idempotency-Key
POST /v1/billing/subscriptions/{subscription_id}/confirmreconcile final state after checkout returnvalid subscription_id, organization context
POST /v1/billing/customer-portal/sessionsopen self-service plan/payment managementmapped customer and authorized role
  1. 11) Create checkout

    Create a session with plan, billing cycle, and organization context. Persist checkoutSessionId.
  2. 22) Redirect user

    Send the user to checkoutUrl and prevent duplicate submit in the frontend.
  3. 33) Confirm state

    After callback/return, call .../confirm to close state deterministically.
  4. 44) Expose portal safely

    Generate portal sessions only for approved profiles.

Checkout creation example

bash
curl -X POST https://api.beacon.pt/v1/billing/subscription-checkouts \
  -H "Authorization: Bearer <access_token>" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: chk_<operation_id>" \
  -d '{
    "organizationId": "<organization_id>",
    "plan": "plus",
    "billingCycle": "monthly",
    "mode": "test"
  }'
json
{
  "checkoutSessionId": "cs_123",
  "checkoutUrl": "https://checkout.stripe.com/c/pay/cs_123",
  "expiresAt": "2026-03-15T10:30:00Z"
}

Idempotency, retries, and consistency

  • Reuse the same Idempotency-Key for the same logical operation.
  • Apply exponential backoff + jitter for transient failures (429, 5xx).
  • Do not assume success from redirect alone; final state must be confirmed by endpoint and events.

Frequent errors

CodeTypical causeRecommended action
401invalid/expired tokenrenew credentials and retry
403insufficient scopereview token permissions for billing
409idempotency conflictreuse original result, avoid duplicate operations
422inconsistent payloadfix plan/cycle/organization values

Go-live checklist

  • Full test flow passes in mode=test with no pending states.
  • Alerts configured for confirmation failures and retry spikes.
  • Portal access restricted by role with audit trail.