Xtopay

Subscriptions API

Model pricing plans, manage customer subscriptions, billing cycles, 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 manage 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.

DetailDescription
API Endpointhttps://api.xtopay.co/v1/subscriptions
Request TypePOST
Content Typeapplication/json
AuthenticationBasic Base64(clientId:clientSecret)
Required Scopepayments:write

Request Parameters

ParameterTypeRequiredDescription
customerIdStringYesID of the Customer record (e.g. cust_cl8z2e9z...).
priceIdStringYesID of the price representing the plan (e.g. price_cl8z2e8z...).
quantityIntegerNoQuantity of seats or units (defaults to 1).
trialDaysIntegerNoNumber of free trial days before billing cycles start.

Code Examples

curl https://api.xtopay.co/v1/subscriptions \
  -u "YOUR_CLIENT_ID:YOUR_CLIENT_SECRET" \
  -H "Content-Type: application/json" \
  -d '{
    "customerId": "cust_cl8z2e9z50000a",
    "priceId": "price_cl8z2e8z80000b",
    "quantity": 1,
    "trialDays": 14
  }'

Sample Response

201 Created

{
  "success": true,
  "data": {
    "id": "sub_cl9a1b2c30000z",
    "customerId": "cust_cl8z2e9z50000a",
    "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.

DetailDescription
API Endpointhttps://api.xtopay.co/v1/subscriptions/:id/cancel
Request TypePATCH
Content Typeapplication/json
AuthenticationBasic Base64(clientId:clientSecret)
Required Scopepayments:write

Path Parameters

ParameterTypeRequiredDescription
:idStringYesUnique Subscription ID to cancel.

Request Parameters

ParameterTypeRequiredDescription
atPeriodEndBooleanNoIf true, schedules cancellation for the end of the billing period. If false, cancels immediately. Defaults to false.

Code Examples

curl -X PATCH https://api.xtopay.co/v1/subscriptions/sub_cl9a1b2c30000z/cancel \
  -u "YOUR_CLIENT_ID:YOUR_CLIENT_SECRET" \
  -H "Content-Type: application/json" \
  -d '{
    "atPeriodEnd": true
  }'

Sample Response

200 OK

{
  "success": true,
  "data": {
    "id": "sub_cl9a1b2c30000z",
    "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.

DetailDescription
API Endpointhttps://api.xtopay.co/v1/subscriptions/:id/pause
Request TypePATCH
AuthenticationBasic Base64(clientId:clientSecret)
Required Scopepayments:write

Path Parameters

ParameterTypeRequiredDescription
:idStringYesUnique Subscription ID to pause.

Code Examples

curl -X PATCH https://api.xtopay.co/v1/subscriptions/sub_cl9a1b2c30000z/pause \
  -u "YOUR_CLIENT_ID:YOUR_CLIENT_SECRET"

Sample Response

200 OK

{
  "success": true,
  "data": {
    "id": "sub_cl9a1b2c30000z",
    "status": "PAUSED"
  }
}

Resume a Subscription

Resume billing cycles for a paused subscription. The status transitions back to ACTIVE.

DetailDescription
API Endpointhttps://api.xtopay.co/v1/subscriptions/:id/resume
Request TypePATCH
AuthenticationBasic Base64(clientId:clientSecret)
Required Scopepayments:write

Path Parameters

ParameterTypeRequiredDescription
:idStringYesUnique Subscription ID to resume.

Code Examples

curl -X PATCH https://api.xtopay.co/v1/subscriptions/sub_cl9a1b2c30000z/resume \
  -u "YOUR_CLIENT_ID:YOUR_CLIENT_SECRET"

Sample Response

200 OK

{
  "success": true,
  "data": {
    "id": "sub_cl9a1b2c30000z",
    "status": "ACTIVE"
  }
}

How is this guide?

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

On this page