PayGate

Customers

Create and manage customers with the PayGate API.

Customers API

Customers allow you to save payment information for repeat purchases, track payment history, and manage subscriptions.

The Customer Object

{
  "id": "cus_abc123def456",
  "object": "customer",
  "email": "customer@example.com",
  "name": "John Doe",
  "phone": "0241234567",
  "metadata": {
    "user_id": "123"
  },
  "created_at": "2024-01-15T10:00:00Z",
  "updated_at": "2024-01-15T10:00:00Z"
}

Attributes

AttributeTypeDescription
idstringUnique identifier for the customer
objectstringAlways "customer"
emailstringCustomer's email address
namestringCustomer's full name
phonestringCustomer's phone number
metadataobjectCustom key-value pairs
created_atstringISO 8601 timestamp
updated_atstringISO 8601 timestamp

Create a Customer

Creates a new customer.

POST /v1/customers

Request Body

ParameterTypeRequiredDescription
emailstringNoCustomer's email address
namestringNoCustomer's full name
phonestringNoCustomer's phone number
metadataobjectNoCustom metadata
curl -X POST https://api.44.200.142.19.nip.io/v1/customers \
  -H "Authorization: Bearer sk_test_..." \
  -H "Content-Type: application/json" \
  -d '{
    "email": "customer@example.com",
    "name": "John Doe",
    "phone": "0241234567",
    "metadata": {
      "user_id": "123"
    }
  }'
const customer = await paygate.customers.create({
  email: 'customer@example.com',
  name: 'John Doe',
  phone: '0241234567',
  metadata: {
    user_id: '123'
  }
})
customer = client.customers.create(
    email='customer@example.com',
    name='John Doe',
    phone='0241234567',
    metadata={'user_id': '123'}
)
$customer = $paygate->customers->create([
    'email' => 'customer@example.com',
    'name' => 'John Doe',
    'phone' => '0241234567',
    'metadata' => ['user_id' => '123']
]);

Response

{
  "id": "cus_abc123def456",
  "object": "customer",
  "email": "customer@example.com",
  "name": "John Doe",
  "phone": "0241234567",
  "metadata": {
    "user_id": "123"
  },
  "created_at": "2024-01-15T10:00:00Z",
  "updated_at": "2024-01-15T10:00:00Z"
}

Retrieve a Customer

Retrieves a customer by ID.

GET /v1/customers/:id
curl https://api.44.200.142.19.nip.io/v1/customers/cus_abc123def456 \
  -H "Authorization: Bearer sk_test_..."
const customer = await paygate.customers.retrieve('cus_abc123def456')
customer = client.customers.retrieve('cus_abc123def456')

Update a Customer

Updates a customer's information.

PATCH /v1/customers/:id

Request Body

ParameterTypeDescription
emailstringCustomer's email address
namestringCustomer's full name
phonestringCustomer's phone number
metadataobjectCustom metadata
curl -X PATCH https://api.44.200.142.19.nip.io/v1/customers/cus_abc123def456 \
  -H "Authorization: Bearer sk_test_..." \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Jane Doe",
    "metadata": {
      "vip": "true"
    }
  }'
const customer = await paygate.customers.update('cus_abc123def456', {
  name: 'Jane Doe',
  metadata: { vip: 'true' }
})
customer = client.customers.update('cus_abc123def456',
    name='Jane Doe',
    metadata={'vip': 'true'}
)

Delete a Customer

Deletes a customer.

DELETE /v1/customers/:id

Deleting a customer will cancel all active subscriptions and remove payment history association.

curl -X DELETE https://api.44.200.142.19.nip.io/v1/customers/cus_abc123def456 \
  -H "Authorization: Bearer sk_test_..."
const deleted = await paygate.customers.delete('cus_abc123def456')
deleted = client.customers.delete('cus_abc123def456')

Response

{
  "id": "cus_abc123def456",
  "object": "customer",
  "deleted": true
}

List Customers

Returns a list of customers.

GET /v1/customers

Query Parameters

ParameterTypeDescription
limitintegerNumber of results (1-100, default 10)
starting_afterstringCursor for pagination
ending_beforestringCursor for pagination
emailstringFilter by email
created[gte]stringFilter by creation date
created[lte]stringFilter by creation date
curl "https://api.44.200.142.19.nip.io/v1/customers?limit=10" \
  -H "Authorization: Bearer sk_test_..."
const customers = await paygate.customers.list({
  limit: 10
})

// Iterate through all customers
for await (const customer of paygate.customers.list()) {
  console.log(customer.id)
}
customers = client.customers.list(limit=10)

# Iterate through all customers
for customer in client.customers.list():
    print(customer.id)

Response

{
  "object": "list",
  "data": [
    {
      "id": "cus_abc123def456",
      "object": "customer",
      "email": "customer@example.com",
      "name": "John Doe",
      ...
    }
  ],
  "has_more": true,
  "url": "/v1/customers"
}

List Customer Payments

Returns all payments for a customer.

GET /v1/customers/:id/payments
curl "https://api.44.200.142.19.nip.io/v1/customers/cus_abc123def456/payments" \
  -H "Authorization: Bearer sk_test_..."
const payments = await paygate.payments.list({
  customer: 'cus_abc123def456'
})
payments = client.payments.list(customer='cus_abc123def456')

List Customer Subscriptions

Returns all subscriptions for a customer.

GET /v1/customers/:id/subscriptions
curl "https://api.44.200.142.19.nip.io/v1/customers/cus_abc123def456/subscriptions" \
  -H "Authorization: Bearer sk_test_..."
const subscriptions = await paygate.subscriptions.list({
  customer: 'cus_abc123def456'
})
subscriptions = client.subscriptions.list(customer='cus_abc123def456')