This guide will walk you through integrating Credibill into your application. We’ll install the SDK, authenticate, and create your first customer.
Prerequisites
Before you begin, make sure you have:
- A Credibill account. Sign up here.
- An API Key from the Developer Dashboard.
- Node.js installed on your machine.
1. Install the SDK
Install the official Node.js SDK using your preferred package manager.
npm install credibill-node
2. Initialize the Client
Import the library and initialize it with your Secret API Key.
import { Credibill } from 'credibill-node';
const credibill = new Credibill('sk_test_...');
Never expose your Secret API Key in client-side code. Always perform billing operations from your backend server.
3. Create a Customer
A Customer represents a business or individual that subscribes to your service.
const customer = await credibill.customers.create({
email: '[email protected]',
name: 'Jane Doe',
paymentMethod: 'pm_card_visa' // Test payment method ID
});
console.log(customer.id);
// Output: cus_123456789
4. Subscribe the Customer
Now, subscribe the customer to a plan. Ensure you have created a plan in your dashboard first.
const subscription = await credibill.subscriptions.create({
customerId: customer.id,
planId: 'plan_pro_monthly'
});
console.log('Subscription active:', subscription.status);
Next Steps
You’ve successfully billed your first customer! Explore deeper into the platform: