Skip to main content
This API allows you to create and manage subscriptions for your account. Subscriptions represent recurring billing arrangements with customers, supporting multiple phases for complex billing scenarios like trials, promotional periods, and plan changes.

The subscription object

id
string
Unique identifier with sub_ prefix (e.g., sub_abc123def456).
customer_id
string
The customer’s ID associated with this subscription.
proration_behavior
string
How proration is handled: create_prorations, always_invoice, or none.
billing_cycle_anchor
string
The anchor date for billing cycles (ISO 8601).
start_date
string
When the subscription started (ISO 8601).
end_date
string
When the subscription ends. null for ongoing subscriptions.
next_billing_date
string
When the next invoice will be generated (ISO 8601).
total_amount
string
The total recurring amount for the subscription.
phases
array
Array of subscription phases.
created_at
string
When the subscription was created (ISO 8601).
updated_at
string
When the subscription was last updated (ISO 8601).

List subscriptions

GET /v1/subscriptions
Retrieves a paginated list of all subscriptions in your account.
page
integer
default:"1"
Page number for pagination. Results are returned 25 items per page.
curl https://api.gettrxn.com/v1/subscriptions \
  -H "Authorization: Bearer $TRXN_TOKEN"
Response
{
  "subscriptions": [
    {
      "id": "sub_abc123def456",
      "customer_id": "cus_xyz789",
      "proration_behavior": "create_prorations",
      "billing_cycle_anchor": "2025-02-01T00:00:00Z",
      "start_date": "2025-01-15T00:00:00Z",
      "end_date": null,
      "next_billing_date": "2025-02-15T00:00:00Z",
      "total_amount": "99.99",
      "created_at": "2025-01-15T12:00:00Z",
      "updated_at": "2025-01-15T12:00:00Z",
      "phases": [
        {
          "start_date": "2025-01-15T00:00:00Z",
          "end_date": null,
          "is_active": true,
          "items": [
            {
              "price_id": "pri_abc123",
              "product_id": "pro_xyz789",
              "product_name": "Premium Plan",
              "quantity": 1,
              "unit_amount": "99.99",
              "overridden_price_amount": null,
              "effective_price": "99.99",
              "recurring": true,
              "interval": "month",
              "interval_count": 1
            }
          ]
        }
      ]
    }
  ],
  "pagination": {
    "page": 1,
    "pages": 2,
    "count": 45
  }
}

Get subscription

GET /v1/subscriptions/:id
Retrieves a specific subscription by ID with all phases and items.
id
string
required
The subscription’s ID (e.g., sub_abc123def456).
curl https://api.gettrxn.com/v1/subscriptions/sub_abc123def456 \
  -H "Authorization: Bearer $TRXN_TOKEN"
Response
{
  "id": "sub_abc123def456",
  "customer_id": "cus_xyz789",
  "proration_behavior": "create_prorations",
  "billing_cycle_anchor": "2025-02-01T00:00:00Z",
  "start_date": "2025-01-15T00:00:00Z",
  "end_date": null,
  "next_billing_date": "2025-02-15T00:00:00Z",
  "total_amount": "99.99",
  "created_at": "2025-01-15T12:00:00Z",
  "updated_at": "2025-01-15T12:00:00Z",
  "phases": [
    {
      "start_date": "2025-01-15T00:00:00Z",
      "end_date": null,
      "is_active": true,
      "items": [
        {
          "price_id": "pri_abc123",
          "product_id": "pro_xyz789",
          "product_name": "Premium Plan",
          "quantity": 1,
          "unit_amount": "99.99",
          "overridden_price_amount": null,
          "effective_price": "99.99",
          "recurring": true,
          "interval": "month",
          "interval_count": 1
        }
      ]
    }
  ]
}

Create subscription

POST /v1/subscriptions
Creates a new subscription with phases and items.
customer_id
string
required
The customer’s ID. Must belong to your account.
proration_behavior
string
default:"create_prorations"
How to handle proration. One of: create_prorations, always_invoice, none.
billing_cycle_anchor
string
The anchor date for billing cycles (ISO 8601 format).
phases
array
required
Array of phase objects. Must include at least one phase.

Simple subscription

curl -X POST https://api.gettrxn.com/v1/subscriptions \
  -H "Authorization: Bearer $TRXN_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "customer_id": "cus_xyz789",
    "billing_cycle_anchor": "2025-02-01T00:00:00Z",
    "proration_behavior": "create_prorations",
    "phases": [
      {
        "start_date": "2025-01-15",
        "items": [
          {"price_id": "pri_monthly_plan", "quantity": 1}
        ]
      }
    ]
  }'
Response
{
  "id": "sub_new123subscription456",
  "customer_id": "cus_xyz789",
  "proration_behavior": "create_prorations",
  "billing_cycle_anchor": "2025-02-01T00:00:00Z",
  "start_date": "2025-01-15T00:00:00Z",
  "end_date": null,
  "next_billing_date": "2025-02-01T00:00:00Z",
  "total_amount": "99.99",
  "created_at": "2025-01-15T14:30:00Z",
  "updated_at": "2025-01-15T14:30:00Z",
  "phases": [...]
}

Multi-phase subscription (trial then paid)

Create a subscription with a trial phase followed by a paid phase:
curl -X POST https://api.gettrxn.com/v1/subscriptions \
  -H "Authorization: Bearer $TRXN_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "customer_id": "cus_xyz789",
    "phases": [
      {
        "start_date": "2025-01-15",
        "end_date": "2025-02-15",
        "items": [
          {"price_id": "pri_trial_plan", "quantity": 1}
        ]
      },
      {
        "start_date": "2025-02-15",
        "items": [
          {"price_id": "pri_monthly_plan", "quantity": 1}
        ]
      }
    ]
  }'

Error responses

Customer not found
{
  "error": "Customer not found"
}
Price not found
{
  "error": "Price not found: pri_invalid123"
}
Missing phases
{
  "errors": {
    "subscription_phases": ["must have at least one phase"]
  }
}

Update subscription

PATCH /v1/subscriptions/:id
Updates an existing subscription’s proration behavior or billing cycle anchor.
id
string
required
The subscription’s ID.
proration_behavior
string
How to handle proration. One of: create_prorations, always_invoice, none.
billing_cycle_anchor
string
The anchor date for billing cycles (ISO 8601 format).
curl -X PATCH https://api.gettrxn.com/v1/subscriptions/sub_abc123def456 \
  -H "Authorization: Bearer $TRXN_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "proration_behavior": "none"
  }'
Response
{
  "id": "sub_abc123def456",
  "customer_id": "cus_xyz789",
  "proration_behavior": "none",
  "billing_cycle_anchor": "2025-02-01T00:00:00Z",
  "start_date": "2025-01-15T00:00:00Z",
  "end_date": null,
  "next_billing_date": "2025-02-15T00:00:00Z",
  "total_amount": "99.99",
  "created_at": "2025-01-15T12:00:00Z",
  "updated_at": "2025-01-16T10:00:00Z",
  "phases": [...]
}

Delete subscription

DELETE /v1/subscriptions/:id
Cancels and deletes a subscription.
id
string
required
The subscription’s ID.
curl -X DELETE https://api.gettrxn.com/v1/subscriptions/sub_abc123def456 \
  -H "Authorization: Bearer $TRXN_TOKEN"
Returns 204 No Content on successful deletion.

Proration behavior values

ValueDescription
create_prorationsCreate prorated charges/credits when subscription changes mid-billing cycle (default).
always_invoiceAlways create a full invoice immediately regardless of billing cycle.
noneNo proration — charges start on the next billing cycle.

Subscription phases

Subscriptions support multiple phases to handle complex billing scenarios:
  • Trial phases: Free or discounted periods at the start of a subscription.
  • Promotional phases: Temporary discounts or special pricing.
  • Plan changes: Scheduled upgrades or downgrades.
  • Ongoing phases: Indefinite billing with no end date.

Phase rules

All recurring items within a phase must have the same interval (e.g., all monthly). Phases cannot overlap and must be sequential without gaps.
  1. Phases must have at least one item.
  2. All recurring items within a phase must have the same interval.
  3. Phases cannot overlap.
  4. Phases must be sequential without gaps (if an end date is specified).
  5. Only one phase can be active at any time.

Billing cycle anchor

The billing_cycle_anchor determines when recurring invoices are generated:
  • If set, invoices are generated relative to this date.
  • If not set, invoices are generated relative to the subscription start date.
  • Useful for aligning billing to specific dates (e.g., 1st of the month).

Automatic invoice generation

When a subscription is created:
  1. An initial invoice may be generated based on proration behavior.
  2. Recurring invoices are automatically generated on billing dates.
  3. The next_billing_date field shows when the next invoice will be created.

Integration example

# 1. Create a customer
curl -X POST https://api.gettrxn.com/v1/customers \
  -H "Authorization: Bearer $TRXN_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"email": "[email protected]"}'

# Response: {"id": "cus_abc123", ...}

# 2. Create a subscription with a trial and regular phase
curl -X POST https://api.gettrxn.com/v1/subscriptions \
  -H "Authorization: Bearer $TRXN_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "customer_id": "cus_abc123",
    "phases": [
      {
        "start_date": "2025-01-15",
        "end_date": "2025-01-29",
        "items": [
          {"price_id": "pri_free_trial", "quantity": 1}
        ]
      },
      {
        "start_date": "2025-01-29",
        "items": [
          {"price_id": "pri_monthly_plan", "quantity": 1}
        ]
      }
    ]
  }'

# 3. Check subscription status
curl https://api.gettrxn.com/v1/subscriptions/sub_xyz789 \
  -H "Authorization: Bearer $TRXN_TOKEN"

# 4. Update proration behavior if needed
curl -X PATCH https://api.gettrxn.com/v1/subscriptions/sub_xyz789 \
  -H "Authorization: Bearer $TRXN_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"proration_behavior": "none"}'

Sandbox support

The API respects sandbox scoping. If your API token is associated with a sandbox, you can only access subscriptions created in that sandbox. Subscriptions created in sandbox mode will be isolated from production data.