Customers
Create and manage customer profiles with billing information and payment methods
Customers are the foundation of billing operations in RevKeen. Every subscription, invoice, and payment is associated with a customer.
Creating Customers
const customer = await client.customers.create({
email: 'john@example.com',
name: 'John Doe',
companyName: 'Acme Inc',
phone: '+1-555-123-4567',
// Optional: Billing address
address: {
line1: '123 Main St',
city: 'San Francisco',
state: 'CA',
postalCode: '94102',
country: 'US',
},
// Optional: Custom metadata
metadata: {
salesforce_id: '00Q123456',
plan: 'enterprise',
},
});
console.log(customer.data.id); // cus_xxxxxxxxCustomer Fields
| Field | Type | Required | Description |
|---|---|---|---|
email | string | Yes | Customer's email address |
name | string | No | Customer's full name |
companyName | string | No | Business or company name |
phone | string | No | Phone number (E.164 format recommended) |
address | object | No | Billing address |
metadata | object | No | Custom key-value pairs |
Listing Customers
// List all customers with pagination
const customers = await client.customers.list({
limit: 20,
page: 1,
});
// Search by email
const customers = await client.customers.list({
email: 'john@example.com',
});
// Auto-pagination
for await (const customer of client.customers.list()) {
console.log(customer.email);
}Updating Customers
const customer = await client.customers.update('cus_xxxxxxxx', {
name: 'John Smith',
metadata: {
plan: 'pro',
upgraded_at: new Date().toISOString(),
},
});Deleting Customers
// Soft delete - marks customer as deleted but retains data
await client.customers.delete('cus_xxxxxxxx');Deleting a customer cancels all active subscriptions and prevents new charges. Historical data is retained for compliance.
Customer Portal
Create a portal session to let customers manage their own billing:
const portal = await client.billingPortal.sessions.create({
customerId: 'cus_xxxxxxxx',
returnUrl: 'https://yourapp.com/account',
});
// Redirect customer to portal
return redirect(portal.data.url);In the portal, customers can:
- View and pay invoices
- Update payment methods
- View subscription details
- Update billing information
- Download receipts