Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.paybridgenp.com/llms.txt

Use this file to discover all available pages before exploring further.

The PayBridgeNP Billing system handles recurring payments - create a plan, add customers, and start subscriptions. PayBridgeNP generates invoices automatically at each renewal, sends payment links to customers, and manages retries when payments fail.
The Billing API requires a Premium plan on your PayBridgeNP account. You can manage billing from the dashboard without the API on any plan.

Core concepts

Plans define the recurring charge - amount, interval (monthly, yearly, etc.), trial period, and dunning behavior. Plans are templates; subscriptions are instances. Customers are the people being billed. They exist independently of subscriptions - you can have a customer with no active subscriptions. Subscriptions link a customer to a plan. When you create a subscription, PayBridgeNP immediately generates the first invoice (unless there’s a trial period). Invoices are generated automatically at each billing cycle. Each invoice has a payment link that PayBridgeNP sends to the customer. Invoices go from openpaid once the customer pays, or past_due if they don’t pay in time.

Step 1: Create a plan

const plan = await paybridge.billing.plans.create({
  name: "Pro Monthly",
  amount: 99900,          // Rs. 999.00 in paisa
  intervalUnit: "month",
  intervalCount: 1,       // every 1 month
  trialDays: 14,          // 14-day free trial
  gracePeriodDays: 3,     // 3 days after due before going overdue
  overdueAction: "mark_past_due",
});

console.log(plan.id); // bp_...

Interval options

intervalUnitintervalCountBilling frequency
month1Monthly
month3Quarterly
year1Yearly
week2Every 2 weeks
day30Every 30 days

Dunning settings

Dunning controls what happens when a customer doesn’t pay on time:
SettingDescription
gracePeriodDaysDays after due before triggering the overdue action
reminderDaysBeforeDueSend a reminder email N days before the invoice is due
overdueReminderIntervalDaysRepeat overdue reminders every N days
overdueActionWhat to do when overdue: keep_active, mark_past_due, pause, or cancel

Step 2: Create a customer

const customer = await paybridge.billing.customers.create({
  name: "Aarav Sharma",
  email: "aarav@example.com",
  phone: "9801234567",          // optional
  externalCustomerId: "user_123", // optional - your internal user ID
});

console.log(customer.id); // bc_...
The externalCustomerId field lets you link PayBridgeNP customers to your own user records.

Step 3: Create a subscription

const subscription = await paybridge.billing.subscriptions.create({
  customerId: customer.id,
  planId: plan.id,
});

console.log(subscription.id);            // sub_...
console.log(subscription.displayStatus); // "trialing" (if plan has trialDays > 0)
When a subscription is created:
  • If the plan has trialDays > 0 - the subscription starts in trial mode, no invoice is generated until the trial ends
  • Otherwise - an invoice is generated immediately and PayBridgeNP sends a payment link to the customer’s email

Subscription lifecycle

draft → active (trialing) → active → past_due → cancelled
                                    ↳ paused → active
Display statusMeaning
draftStart date is in the future
trialingActive, in trial period - no invoices yet
activeBilling normally
past_dueInvoice unpaid past grace period
pausedBilling paused - no invoices generated
cancelledEnded - no further invoices
completedReached a natural end date

Managing subscriptions

Pause

await paybridge.billing.subscriptions.pause(subscription.id, {
  reason: "Customer requested temporary pause",
});
No invoices are generated while paused. Resume resumes billing from the current period.

Resume

await paybridge.billing.subscriptions.resume(subscription.id);

Cancel

// Cancel immediately
await paybridge.billing.subscriptions.cancel(subscription.id, {
  reason: "Customer churned",
});

// Cancel at end of current period
await paybridge.billing.subscriptions.cancel(subscription.id, {
  atPeriodEnd: true,
});

Change plan

// Change takes effect at the next renewal
await paybridge.billing.subscriptions.changePlan(subscription.id, {
  planId: newPlan.id,
});
The current period continues on the old plan. At renewal, the subscription switches to the new plan.

Invoices

Invoices are read-only from the API - PayBridgeNP creates them automatically. Use them to display billing history to customers.
const { data: invoices } = await paybridge.billing.invoices.list({
  subscriptionId: subscription.id,
});

for (const invoice of invoices) {
  console.log(invoice.status, invoice.amount, invoice.dueAt);
}
Invoice statusMeaning
draftNot yet sent
openSent to customer, awaiting payment
paidCustomer paid
past_dueNot paid by due date
voidedCancelled

Webhook events

PayBridgeNP fires webhook events throughout the subscription lifecycle:
EventWhen
subscription.createdNew subscription created
subscription.activatedTrial ended, billing started
subscription.past_dueInvoice went past due
subscription.pausedSubscription paused
subscription.resumedSubscription resumed
subscription.cancelledSubscription cancelled
invoice.createdNew invoice generated
invoice.paidCustomer paid an invoice
invoice.past_dueInvoice went past due