Перейти к основному содержимому
Версия: Next

Subscriptions

Subscriptions enable recurring billing for your customers. Dimebia handles the entire subscription lifecycle from signup to cancellation.

Overview

A subscription represents a recurring billing agreement between you and a customer. Subscriptions automatically generate invoices on a scheduled basis.

Subscription Lifecycle

Active → Past Due → Cancelled/Expired

Paused → Resumed

Create a Subscription

POST /api/subscription/create

Request Body

FieldTypeRequiredDescription
customerIdLongYesCustomer ID
planIdLongYesPlan ID
quantityIntegerNoNumber of seats/units (default: 1)
trialDaysIntegerNoFree trial period in days
couponIdStringNoDiscount coupon code
metadataObjectNoCustom key-value pairs

Example

curl -X POST http://localhost:8080/api/subscription/create \
-H "Content-Type: application/json" \
-H "Authorization: Bearer <YOUR_TOKEN>" \
-d '{
"customerId": 1,
"planId": 1,
"quantity": 5,
"trialDays": 14
}'

Subscription Plans

Plans define the pricing and billing cycle for subscriptions:

FieldDescription
namePlan name (e.g., "Pro", "Enterprise")
intervalBilling interval: DAY, WEEK, MONTH, YEAR
intervalCountNumber of intervals (e.g., 2 for bi-monthly)
amountPrice per unit in cents
currencyCurrency code
trialDaysFree trial period
metadataCustom metadata

Billing Cycles

Dimebia supports flexible billing cycles:

  • Monthly: Most common, billed every month
  • Yearly: Annual billing with discount
  • Weekly: For short-term services
  • Custom: Define your own intervals

Subscription Status

StatusDescription
ACTIVESubscription is active
TRIALINGIn free trial period
PAST_DUEPayment failed, retry pending
CANCELLEDCancelled by user or admin
EXPIREDSubscription term ended
PAUSEDTemporarily paused

Manage Subscriptions

# Cancel subscription
POST /api/subscription/{id}/cancel

# Update subscription
POST /api/subscription/{id}/update

# Activate paused subscription
POST /api/subscription/{id}/activate

# Mark as past due
POST /api/subscription/{id}/mark-past-due

# Expire subscription
POST /api/subscription/{id}/expire

Metered Billing

For usage-based pricing:

POST /api/subscription/{id}/usage
{
"quantity": 100,
"timestamp": "2026-08-18T10:00:00Z",
"metadata": {
"apiCalls": 1000
}
}

Code Examples

Node.js

// Create subscription
const subscription = await client.subscriptions.create({
customerId: 1,
planId: 1,
trialDays: 14,
});

// Cancel at period end
await client.subscriptions.update(subscription.id, {
cancelAtPeriodEnd: true,
});

// List subscriptions
const subscriptions = await client.subscriptions.list({
customerId: 1,
status: 'ACTIVE',
});