Skip to content

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_abc123

Customer Parameters

ParameterTypeRequiredDescription
emailstringYesCustomer email address
namestringNoCustomer full name
phonestringNoPhone number
addressobjectNoBilling address
metadataobjectNoCustom key-value data

Address Object

FieldTypeDescription
line1stringStreet address
line2stringApartment, suite, etc.
citystringCity
statestringState/province
postalCodestringPostal/ZIP code
countrystringTwo-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.

Fyber Payment API