Subscription plans

Create, list, change and archive subscription plans from your own code. A plan is a price many customers can subscribe to, with its own sign-up page.

On this page

The plan object

A plan is a price many customers can subscribe to: a name, an amount per period and how often it bills, with an optional free trial. It's the same plan you make under Subscriptions → Plans in the dashboard, and it shows up there. Its url is a public sign-up page where a customer gives their name and email and pays the first invoice. You can also put a customer on it yourself with Create a subscription and plan.

A plan only sets what new subscriptions start with. Each subscription copies the plan's price, interval, trial and settings when it's made, so changing or archiving a plan never changes the subscriptions already on it. Nothing is ever charged automatically: each period, a subscription issues an invoice its customer pays themselves.

FieldTypeDescription
idstringThe plan's id, spl_…
objectstring"subscription_plan"
livemodebooleanfalse for Test mode, true for Live mode
namestringWhat customers see, such as Pro. Each invoice's line reads it
descriptionstring or nullA sentence or two for the sign-up page
featuresarrayUp to 8 short texts the sign-up page lists
currencystringUSD, EUR, GBP, CAD, AUD, INR or SEK
amountstringOne period's price before tax, such as "49.00"
intervalobjectHow often it bills: unit (day, week, month or year) and count, such as { "unit": "month", "count": 3 } for every three months
trial_daysintegerFree days before the first paid period, 0 for none
tax_percent, tax_labelstring or nullThe tax each invoice adds ("8.25", "Sales tax")
termsstring or nullYour terms, printed on each invoice
billingobjectHow each period's invoice is sent and collected. See The billing object
routingobjectWhich card providers its invoices offer. See The routing field
collectobject or nullWhat the payment page asks besides the email. See The collect field
success_urlstring or nullWhere the customer lands once an invoice is paid
payout_wallet_idstring or nullThe saved wallet its invoices pay, pw_…, or null for the account's payout wallet
self_servebooleanWhether its page takes sign-ups. Off, the page says so and only you add subscribers
urlstringThe sign-up page, https://pay.railbed.io/subscribe/…. Share it, or link to it from your pricing page
statusstringactive, or archived: it takes no new subscribers, and its subscribers carry on
subscribersobjectIts subscriptions now: paying (started, and active or past due), trialing, and total (every one not canceled)
mrrstringWhat its paying subscribers add up to a month, before tax, in its currency
versionintegerGoes up with every change. Send it back as expected_version when you update it
created, updatedintegerWhen it was made and last changed, in Unix seconds
warningsarrayOn create and update only, and only when there is something to say: what the card providers' minimums mean for this price. See Provider minimums
A plan
{
  "id": "spl_8Hq2mVx5RtLc3NwZb7Ks",
  "object": "subscription_plan",
  "livemode": false,
  "name": "Pro",
  "description": "Everything in Starter, plus priority support.",
  "features": [
    "5 seats",
    "Priority support",
    "Monthly report"
  ],
  "currency": "USD",
  "amount": "49.00",
  "interval": {
    "unit": "month",
    "count": 1
  },
  "trial_days": 0,
  "tax_percent": null,
  "tax_label": null,
  "terms": "Cancel any time from your subscription page.",
  "billing": {
    "lead_days": 7,
    "terms_days": 3,
    "cancel_after_days": 14,
    "reminders": [
      -3,
      0,
      3,
      7
    ],
    "send_emails": true,
    "email_receipts": true,
    "allow_customer_cancel": true
  },
  "routing": {
    "choice": "buyer",
    "provider": null,
    "fallback": true,
    "providers": null
  },
  "collect": null,
  "success_url": null,
  "payout_wallet_id": null,
  "self_serve": true,
  "url": "https://pay.railbed.io/subscribe/5e2b9c71d04a4f68b3c8e1a7f9d2c6b0",
  "status": "active",
  "subscribers": {
    "paying": 0,
    "trialing": 0,
    "total": 0
  },
  "mrr": "0.00",
  "version": 0,
  "created": 1790380525,
  "updated": 1790380525
}
200 OK

The billing object

Plans and subscriptions share it. Leave it out and a plan gets the defaults for its interval; send only the fields you want to change.

FieldTypeDescription
lead_daysintegerHow many days before its period an invoice goes out: 0, 1, 3, 7 or 14, and at most half the period
terms_daysintegerHow many days after the period starts it's due: 0, 1, 3, 7, 14 or 30, and less than the period. A daily plan's invoice is due the day it goes out
cancel_after_daysinteger or nullUnpaid this many days past its due date, the subscription ends: 3, 7, 14, 30 or 60. null keeps it past due until you act
remindersarray or nullDays around each due date when Railbed emails a reminder, from -7, -3, -1, 0, 1, 3, 7, 14 and 30. null for none
send_emailsbooleanRailbed emails each invoice and its reminders in your business's name. Turn it off to send your own from the subscription.invoice_issued event
email_receiptsbooleanThe customer gets a receipt for each payment
allow_customer_cancelbooleanThe customer can cancel from their subscription page (and the customer portal). It then ends when the time they paid for does

The defaults follow the interval. Monthly or longer: sent 7 days ahead (14 for yearly or longer), due 3 days into the period, ended 14 days past due, reminders at [-3, 0, 3, 7]. Weekly to under a month: 1 day ahead, due after 1 day, ended 7 days past due, reminders at [0, 3]. Shorter: sent and due on the day, ended 3 days past due, no reminders. Every default emails invoices and receipts and lets the customer cancel.

Create a subscription plan

POST /v1/subscription_plans

Makes an active plan in the credential's mode. Its sign-up page works at once.

ParameterTypeDescription
namestring RequiredUp to 80 characters
currencystring RequiredUSD, EUR, GBP, CAD, AUD, INR or SEK, in any letter case
amountstring RequiredOne period's price before tax, a decimal string such as "49.00". With tax it must be from 1.00 to 100,000.00 and at least the smallest card payment
intervalobject Requiredunit and count: every 1–365 days, 1–52 weeks, 1–24 months or 1–3 years
descriptionstringUp to 300 characters
featuresarrayUp to 8 texts of up to 80 characters each
trial_daysinteger0–365. Default 0
taxobject{ "percent": "8.25", "label": "Sales tax" }
termsstringYour terms, up to 2,000 characters
billingobjectSee The billing object
routingobjectAs on a payment link
collectobjectAs on a checkout session
success_urlstringWhere the customer lands once an invoice is paid. Live mode needs a public https:// page on your own site
payout_wallet_idstringOne of the account's other saved wallets, pw_…. List payout wallets gives their ids
self_servebooleanIts page takes sign-ups. Default true

Money is always a decimal string, never a JSON number. A field plans don't have is refused with 400 unknown_field, and the message names the one you probably meant.

curl https://pay.railbed.io/v1/subscription_plans \
  -H "Authorization: Bearer $RAILBED_SECRET_KEY" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: plan-pro-monthly" \
  -d '{
    "name": "Pro",
    "description": "Everything in Starter, plus priority support.",
    "features": ["5 seats", "Priority support", "Monthly report"],
    "currency": "USD",
    "amount": "49.00",
    "interval": { "unit": "month", "count": 1 },
    "terms": "Cancel any time from your subscription page."
  }'
Response
{
  "id": "spl_8Hq2mVx5RtLc3NwZb7Ks",
  "object": "subscription_plan",
  "livemode": false,
  "name": "Pro",
  "description": "Everything in Starter, plus priority support.",
  "features": [
    "5 seats",
    "Priority support",
    "Monthly report"
  ],
  "currency": "USD",
  "amount": "49.00",
  "interval": {
    "unit": "month",
    "count": 1
  },
  "trial_days": 0,
  "tax_percent": null,
  "tax_label": null,
  "terms": "Cancel any time from your subscription page.",
  "billing": {
    "lead_days": 7,
    "terms_days": 3,
    "cancel_after_days": 14,
    "reminders": [
      -3,
      0,
      3,
      7
    ],
    "send_emails": true,
    "email_receipts": true,
    "allow_customer_cancel": true
  },
  "routing": {
    "choice": "buyer",
    "provider": null,
    "fallback": true,
    "providers": null
  },
  "collect": null,
  "success_url": null,
  "payout_wallet_id": null,
  "self_serve": true,
  "url": "https://pay.railbed.io/subscribe/5e2b9c71d04a4f68b3c8e1a7f9d2c6b0",
  "status": "active",
  "subscribers": {
    "paying": 0,
    "trialing": 0,
    "total": 0
  },
  "mrr": "0.00",
  "version": 0,
  "created": 1790380525,
  "updated": 1790380525
}
201 Created

Retries. Send an Idempotency-Key (1–120 printable ASCII characters): the same key with the same body (compared as sent, in any field order) answers the plan it made, with 200, for 24 hours; the same key with a different body is 409 idempotency_conflict.

ErrorCause
400 unknown_fieldA field plans don't have, here or inside interval, tax or billing. field names it
400 missing_name, 400 invalid_features, 400 too_longNo name; features isn't a list of at most 8 texts (field names the item, such as features.2); or a text field is over its limit
400 invalid_amount, 400 invalid_currencyThe price isn't a decimal string above zero, its total is outside 1.00–100,000.00 or under the smallest card payment, or the currency isn't supported
400 invalid_interval, 400 invalid_trialThe interval is outside its bounds, or trial_days isn't a whole number from 0 to 365
400 invalid_billing, 400 invalid_reminders, 400 invalid_valueA billing value isn't one of its choices or doesn't fit the interval, or a switch isn't true or false. field names it, such as billing.lead_days
400 invalid_tax, 400 invalid_routing, 400 invalid_collect, 400 invalid_url, 400 invalid_payout_walletAs on Create an invoice
409 idempotency_conflict, 409 idempotency_in_progressThe key was used with a different body, or its first request hasn't finished: retry after Retry-After
409 payout_wallet_unusableLive mode, and the wallet in payout_wallet_id can't take live payments
409 commerce_paused, 403 integration_disabledThe account has paused payments, or the API is turned off for it

Retrieve a subscription plan

GET /v1/subscription_plans/:id

Returns one of your plans in the credential's mode, with its subscriber counts as they are now. One in the other mode is 404 not_found, and the message says which mode it's in.

cURL
curl https://pay.railbed.io/v1/subscription_plans/spl_8Hq2mVx5RtLc3NwZb7Ks \
  -H "Authorization: Bearer $RAILBED_SECRET_KEY"

To list its subscribers, use List subscriptions with plan=spl_….

Update a subscription plan

PATCH /v1/subscription_plans/:id

Changes the fields you send and leaves the rest, with the parameters of Create a subscription plan. Send null to clear an optional field. A change reaches new subscribers only: subscriptions already on the plan keep the price, interval and settings they started with. To change one of those, use Update a subscription. A new interval resets billing to that interval's defaults unless you send billing too.

ParameterTypeDescription
statusstringarchived to stop new subscribers (its page says it's no longer available, and Create a subscription on it answers 409 plan_archived), or active to restore it. Its subscribers carry on either way
expected_versionintegerThe version you read. If anyone changed the plan since, it answers 409 plan_changed instead of overwriting their change
cURL
curl -X PATCH https://pay.railbed.io/v1/subscription_plans/spl_8Hq2mVx5RtLc3NwZb7Ks \
  -H "Authorization: Bearer $RAILBED_SECRET_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "status": "archived", "expected_version": 0 }'

A plan is never deleted, so its subscriptions and figures keep their history: archive it instead.

ErrorCause
409 plan_changedSomeone changed it since expected_version, or while the request ran. Read it again, then make your change
400 invalid_statusstatus isn't active or archived
400 invalid_expected_versionNot a whole number

The create errors apply to the fields you send.

List subscription plans

GET /v1/subscription_plans

Returns your plans in the credential's mode, newest first.

ParameterTypeDescription
limitinteger1–100. Default 20
starting_afterstringA plan id from the previous page's next_cursor
statusstringactive or archived
created_gteintegerCreated on or after this Unix timestamp in seconds
created_lteintegerCreated on or before this Unix timestamp in seconds, including the whole ending second
cURL
curl "https://pay.railbed.io/v1/subscription_plans?status=active" \
  -H "Authorization: Bearer $RAILBED_SECRET_KEY"
Response
{
  "data": [
    {
      "id": "spl_8Hq2mVx5RtLc3NwZb7Ks",
      "object": "subscription_plan",
      "livemode": false,
      "name": "Pro",
      "description": "Everything in Starter, plus priority support.",
      "features": [
        "5 seats",
        "Priority support",
        "Monthly report"
      ],
      "currency": "USD",
      "amount": "49.00",
      "interval": {
        "unit": "month",
        "count": 1
      },
      "trial_days": 0,
      "tax_percent": null,
      "tax_label": null,
      "terms": "Cancel any time from your subscription page.",
      "billing": {
        "lead_days": 7,
        "terms_days": 3,
        "cancel_after_days": 14,
        "reminders": [
          -3,
          0,
          3,
          7
        ],
        "send_emails": true,
        "email_receipts": true,
        "allow_customer_cancel": true
      },
      "routing": {
        "choice": "buyer",
        "provider": null,
        "fallback": true,
        "providers": null
      },
      "collect": null,
      "success_url": null,
      "payout_wallet_id": null,
      "self_serve": true,
      "url": "https://pay.railbed.io/subscribe/5e2b9c71d04a4f68b3c8e1a7f9d2c6b0",
      "status": "active",
      "subscribers": {
        "paying": 0,
        "trialing": 0,
        "total": 0
      },
      "mrr": "0.00",
      "version": 0,
      "created": 1790380525,
      "updated": 1790380525
    }
  ],
  "has_more": false,
  "next_cursor": null
}
200 OK

Access

Retrieving and listing need the payments:read scope, which Read only keys have. Creating and changing need checkouts:write, which Full access keys and agents with full access have. Plans send no webhook events of their own; their subscriptions do (Subscription events).

Updated · This page as Markdown