Skip to main content

Recurring Payments

Implement subscription and recurring payment flows with Pelago.

Overview

Pelago supports recurring payments through payment links with scheduling capabilities.

Creating a Subscription

const subscription = await pelago.subscriptions.create({
customerId: 'cust_abc123',
amount: 9.99,
currency: 'USD',
cryptocurrency: 'USDC',
network: 'stellar',
interval: 'monthly',
intervalCount: 1,
merchantWallet: 'GXXXXX...',
metadata: {
plan: 'premium',
tier: 'monthly'
}
});

Subscription Lifecycle

Billing Intervals

IntervalExample
dailyEvery day
weeklyEvery 7 days
monthlySame day each month
yearlySame day each year

Handling Renewals

// Webhook: subscription.payment_succeeded
app.post('/webhook', (req, res) => {
const event = req.body;

if (event.type === 'subscription.payment_succeeded') {
const { subscriptionId, paymentId, nextBillingDate } = event.data;

// Extend customer access
await extendSubscription(subscriptionId, nextBillingDate);
}
});

Cancellation

await pelago.subscriptions.cancel('sub_abc123', {
cancelAtPeriodEnd: true // Complete current period
});