Open app
Moonborn — API · billing

Create a paid subscription (or initiate hosted checkout)

When `paymentMethodId` is supplied, the subscription is created server-side. When `useHostedCheckout=true`, returns a Stripe Checkout URL and defers persistence to the webhook.

POST/v1/billing/subscriptionscope · Bearer (API key or session JWT)
Request body
FieldTypeDescription
planTierreqstring · "free" | "pro" | "team" | "enterprise"
intervalreqstring · "month" | "year"
stripePriceIdstring
paymentMethodIdstring
useHostedCheckoutboolean

Responses

201Subscription created (or checkout pending)
Body
FieldTypeDescription
subscriptionreqobject
subscription.subscriptionIdreqstring
subscription.orgIdreqstring
subscription.planTierreqstring · "free" | "pro" | "team" | "enterprise"
subscription.statusreqstring · "trialing" | "active" | "past_due" | "canceled" | "incomplete" | "unpaid"
subscription.intervalreqstring · "month" | "year"
subscription.currencyreqstring
subscription.recurringAmountMinorreqnumber
subscription.trialEndsAtreqstring
subscription.currentPeriodStartreqstring
subscription.currentPeriodEndreqstring
subscription.cancelAtPeriodEndreqboolean
subscription.createdAtreqstring
subscription.updatedAtreqstring
checkoutUrlreqstring
401Unauthenticated
Body
FieldTypeDescription
errorreqobject
error.codereqstring
error.messagereqstring
402Card declined / payment failed
Body
FieldTypeDescription
errorreqobject
error.codereqstring
error.messagereqstring
409Org already has an active subscription
Body
FieldTypeDescription
errorreqobject
error.codereqstring
error.messagereqstring
422Validation error (unknown plan/interval mismatch)
Body
FieldTypeDescription
errorreqobject
error.codereqstring
error.messagereqstring

Examples

cURL
curl -X POST https://api.moonborn.co/v1/billing/subscription \
  -H "Authorization: Bearer $MOONBORN_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
      "planTier": "free",
      "interval": "month"
    }'
TypeScript
import Moonborn from '@moonborn/sdk';

const client = new Moonborn({ apiKey: process.env.MOONBORN_API_KEY });

const result = await client.billing.createSubscription({
  planTier: "free",
  interval: "month",
});
Python
import os
from moonborn import Moonborn

client = Moonborn(api_key=os.environ["MOONBORN_API_KEY"])

result = client.billing.create_subscription(
    plan_tier="free",
    interval="month",
)