Customers
The Customers API lets you create and manage customer records for saved cards, subscriptions, and payment history.
Create a Customer
javascript
const customer = await fyber.customers.create({
email: 'john@example.com',
name: 'John Doe',
phone: '+1876-555-0123',
address: {
line1: '123 Main Street',
city: 'Kingston',
postalCode: 'KN1234',
country: 'JM',
},
metadata: {
userId: 'user_123',
},
});
console.log(customer.id); // cus_abc123Customer Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
email | string | Yes | Customer email address |
name | string | No | Customer full name |
phone | string | No | Phone number |
address | object | No | Billing address |
metadata | object | No | Custom key-value data |
Address Object
| Field | Type | Description |
|---|---|---|
line1 | string | Street address |
line2 | string | Apartment, suite, etc. |
city | string | City |
state | string | State/province |
postalCode | string | Postal/ZIP code |
country | string | Two-letter country code |
Retrieve a Customer
javascript
const customer = await fyber.customers.get('cus_123');Update a Customer
javascript
const customer = await fyber.customers.update('cus_123', {
name: 'Jane Doe',
phone: '+1876-555-9999',
});Delete a Customer
javascript
await fyber.customers.delete('cus_123');Deleting a customer also deletes their saved payment methods (tokens) and cancels active subscriptions.
List Customers
javascript
const customers = await fyber.customers.list({
limit: 20,
email: 'john@example.com', // Optional filter
});
for (const customer of customers.data) {
console.log(`${customer.name}: ${customer.email}`);
}Customer Object
json
{
"id": "cus_abc123",
"object": "customer",
"email": "john@example.com",
"name": "John Doe",
"phone": "+1876-555-0123",
"address": {
"line1": "123 Main Street",
"city": "Kingston",
"postalCode": "KN1234",
"country": "JM"
},
"metadata": {
"userId": "user_123"
},
"createdAt": "2024-01-15T10:30:00Z"
}Using Customers with Checkout
Pre-fill customer information in Hosted Checkout:
javascript
// Use existing customer
const session = await fyber.checkout.sessions.create({
customerId: 'cus_123',
// ...
});
// Or create customer inline
const session = await fyber.checkout.sessions.create({
customerEmail: 'new@example.com',
// ...
});Customer with Saved Cards
List a customer's saved payment methods:
javascript
const tokens = await fyber.tokens.list({
customerId: 'cus_123',
});
for (const token of tokens.data) {
console.log(`${token.card.brand} ending in ${token.card.last4}`);
}See Tokens for more on saved payment methods.