Documentation
Overview
Getting Started
API Reference
Examples
SDKs
JavaScript
WordPress
Guides
Products
Subscriptions
Webhooks

Subscriptions Guide

Set up recurring payments with subscription plans

What is a Subscription?

Subscriptions enable recurring payments at regular intervals. Create subscription plans with daily, weekly, monthly, or yearly billing cycles.

Creating a Subscription Plan

const plan = await caspay.plans.create({ name: 'Pro Plan', description: 'Professional tier with all features', amount: 50000000000, // 50 CSPR interval: 'month', // 'day', 'week', 'month', 'year' intervalCount: 1, // Bill every 1 month trialDays: 7 // Optional 7-day trial });

Billing Intervals

daily

Bill every N days

weekly

Bill every N weeks

monthly

Bill every N months

yearly

Bill every N years

Subscribing a Customer

const subscription = await caspay.subscriptions.create({ planId: 'plan_123', customerWallet: '0x...', startDate: '2024-01-01', metadata: { userId: 'user_456' } });

Customers must approve the subscription contract to enable recurring payments

Managing Subscriptions

Check Status

const sub = await caspay.subscriptions.get('sub_123'); console.log(sub.status); // 'active', 'canceled', 'past_due'

Pause Subscription

await caspay.subscriptions.pause('sub_123');

Resume Subscription

await caspay.subscriptions.resume('sub_123');

Cancel Subscription

await caspay.subscriptions.cancel('sub_123');

Cancelled subscriptions remain active until the end of the current billing period

Subscription Events

Listen to subscription events via webhooks:

subscription.created
subscription.updated
subscription.canceled
subscription.payment_succeeded
subscription.payment_failed