Xtopay

Subscriptions API

Model pricing plans, manage customer subscriptions, trials, and renewals.

Subscriptions API

The Subscriptions API lets you build recurring billing relationships with your customers. You can charge customers on a recurring schedule (daily, weekly, monthly, yearly), offer free trials, pause memberships, and handle cancellations.


Subscription Lifecycle & States

A subscription automatically compiles and sends invoices to the associated customer at the start of each billing period. Subscriptions can progress through the following statuses:

StatusDescription
INCOMPLETESubscription is created, but the initial invoice is unpaid.
TRIALINGThe customer is in a free trial period. No payments are charged yet.
ACTIVEThe subscription is active and in good standing.
PAST_DUEAn invoice payment attempt failed. Renewals are retried.
UNPAIDRetries failed, and the subscription is unpaid (access should be restricted).
CANCELEDThe subscription has been cancelled and is inactive.
PAUSEDBilling cycles are temporarily paused and can be resumed.

Create a Subscription

Subscribe a customer to a pricing plan.

POST /subscriptions

Request Parameters

ParameterTypeRequiredDescription
customerIdstringYesID of the Customer record.
priceIdstringYesID of the price representing the plan.
quantityintegerNoQuantity of seats/units (defaults to 1).
trialDaysintegerNoNumber of free trial days before billing starts.

Example Request

curl https://api.xtopay.co/subscriptions \
  -H "Authorization: Bearer YOUR_SESSION_OR_SECRET_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "customerId": "cust_cl8z2e9z...",
    "priceId": "price_cl8z2e8z...",
    "quantity": 1,
    "trialDays": 14
  }'

Example Response

{
  "success": true,
  "data": {
    "id": "sub_cl9a1b2c3000...",
    "customerId": "cust_cl8z2e9z...",
    "status": "TRIALING",
    "currency": "GHS",
    "trialStart": "2026-06-05T12:00:00Z",
    "trialEnd": "2026-06-19T12:00:00Z",
    "currentPeriodStart": "2026-06-05T12:00:00Z",
    "currentPeriodEnd": "2026-06-19T12:00:00Z",
    "createdAt": "2026-06-05T12:00:00Z"
  }
}

Cancel a Subscription

Cancel a subscription immediately or schedule it to cancel at the end of the current billing period.

PATCH /subscriptions/:id/cancel

Request Parameters

ParameterTypeRequiredDescription
atPeriodEndbooleanNoIf true, waits until the end of the billing period to cancel. If false, cancels immediately.

Example Request

curl -X PATCH https://api.xtopay.co/subscriptions/sub_cl9a1b2c3000.../cancel \
  -H "Authorization: Bearer YOUR_SESSION_OR_SECRET_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "atPeriodEnd": true
  }'

Example Response

{
  "success": true,
  "data": {
    "id": "sub_cl9a1b2c3000...",
    "status": "ACTIVE",
    "cancelAt": "2026-07-05T12:00:00Z",
    "canceledAt": "2026-06-05T12:45:00Z"
  }
}

Pause a Subscription

Pause recurring billing cycles. The subscription status transitions to PAUSED.

PATCH /subscriptions/:id/pause

Example Request

curl -X PATCH https://api.xtopay.co/subscriptions/sub_cl9a1b2c3000.../pause \
  -H "Authorization: Bearer YOUR_SESSION_OR_SECRET_KEY"

Example Response

{
  "success": true,
  "data": {
    "id": "sub_cl9a1b2c3000...",
    "status": "PAUSED"
  }
}

Resume a Subscription

Resume a paused subscription to reactive billing cycles.

PATCH /subscriptions/:id/resume

Example Request

curl -X PATCH https://api.xtopay.co/subscriptions/sub_cl9a1b2c3000.../resume \
  -H "Authorization: Bearer YOUR_SESSION_OR_SECRET_KEY"

Example Response

{
  "success": true,
  "data": {
    "id": "sub_cl9a1b2c3000...",
    "status": "ACTIVE"
  }
}

How is this guide?

Edit this page on GitHub
Last updated on June 6, 2026

On this page