Skip to main content
This example demonstrates a full integration flow: initializing the client, creating a customer, and starting a subscription.

Prerequisites

  • Node.js v14+
  • credibill-node installed

Full Script

index.js
require('dotenv').config();
const { Credibill } = require('credibill-node');

// Initialize with Secret Key
const credibill = new Credibill(process.env.CREDIBILL_SECRET_KEY);

async function main() {
  try {
    // 1. Create a Customer
    console.log('Creating customer...');
    const customer = await credibill.customers.create({
      email: '[email protected]',
      name: 'Startup Inc',
      paymentMethod: 'pm_card_visa'
    });
    console.log(`Customer created: ${customer.id}`);

    // 2. Create a Plan (usually done in Dashboard, but shown here for completeness)
    // Note: In production, use existing plan IDs.
    
    // 3. Subscribe the Customer
    console.log('Subscribing customer...');
    const subscription = await credibill.subscriptions.create({
      customerId: customer.id,
      planId: 'plan_starter_monthly'
    });

    console.log(`Subscription status: ${subscription.status}`);
    
  } catch (error) {
    console.error('Error:', error.message);
  }
}

main();