Billing Guide

Set up subscriptions

Implement recurring billing to charge your customers on a weekly, monthly, or yearly basis. Kopo Pay handles prorations, renewals, and automated email notifications for you.

1

Create a Product and Price

Before subscribing a customer, you need to define what they are buying. Products describe what you sell, and Prices define how much and how often to charge.

const product = await kopopay.products.create({
  name: 'Premium Plan',
});

const price = await kopopay.prices.create({
  product: product.id,
  unit_amount: 1000,
  currency: 'usd',
  recurring: { interval: 'month' },
});
2

Create a Customer

To start a subscription, you need a Customer object to attach the billing details and payment method.

const customer = await kopopay.customers.create({
  email: 'customer@example.com',
  payment_method: 'pm_card_visa', // Set after collecting PM
  invoice_settings: { default_payment_method: 'pm_card_visa' },
});
3

Start the Subscription

Subscribe the customer to the price you created. This will automatically generate invoices and charge the customer.

const subscription = await kopopay.subscriptions.create({
  customer: customer.id,
  items: [{ price: price.id }],
  payment_behavior: 'default_incomplete',
  payment_settings: { save_default_payment_method: 'on_subscription' },
  expand: ['latest_invoice.payment_intent'],
});