Customers

The Customer Object

1class Customer
2 attr_accessor :id, :organization_id, :name, :phone, :employee_count,
3 :annual_revenue, :tax_exempt_status, :creation_source,
4 :website, :external_id, :billing_address
5end
6
7class Address
8 attr_accessor :line1, :line2, :city, :state, :zip_code, :country
9end
10
11module TaxExemptStatus
12 NONE = "none"
13 EXEMPT = "exempt"
14 REVERSE = "reverse"
15end
16
17module CreationSource
18 MANUAL = "manual"
19 API = "api"
20 CRM = "crm"
21 OTHER = "other"
22end

Attributes

AttributeTypeDescription
idstringUnique identifier for the customer
organization_idstringOrganization ID the customer belongs to
namestringName of the customer
phonestringOptional phone number
employee_countnumberOptional number of employees
annual_revenuenumberOptional annual revenue
tax_exempt_statusstringOptional tax exempt status (‘none’, ‘exempt’, ‘reverse’)
creation_sourcestringOptional source of creation (‘manual’, ‘api’, ‘crm’, ‘other’)
websitestringOptional website URL
external_idstringOptional external identifier
billing_addressobjectOptional billing address information

Address Attributes

AttributeTypeDescription
line1stringFirst line of the address
line2stringOptional second line of the address
citystringCity name
statestringState or province
zip_codestringZIP or postal code
countrystringCountry name

API Endpoints

Create a Customer

Creates a new customer with the given data.

SDK Functions

1require 'paid_ruby'
2
3# Initialize the client
4api = Paid::Client.new(
5 token: "YOUR-API-KEY"
6)
7
8# Create ther customer
9customer = api.customers.create(
10 name: "Acme Corporation",
11 phone: "+1-555-0123",
12 employee_count: 100,
13 annual_revenue: 1000000,
14 tax_exempt_status: Paid::TaxExemptStatus::NONE,
15 creation_source: Paid::CreationSource::API,
16 website: "https://acme.com",
17 external_id: "acme_123",
18 billing_address: {
19 line1: "123 Business Ave",
20 line2: "Suite 100",
21 city: "San Francisco",
22 state: "CA",
23 zip_code: "94105",
24 country: "USA"
25 }
26)

Returns

Returns the Customer object upon successful creation. It’s recommended to store the returned customer ID in your own system for future reference and operations.

1{
2 id: "uuid",
3 organization_id: "uuid",
4 name: "Acme Corporation",
5 phone: "+1-555-0123",
6 website: "https://acme.com",
7 employee_count: 100,
8 annual_revenue: 1000000,
9 tax_exempt_status: "none",
10 creation_source: "api",
11 external_id: "acme_123",
12 creation_state: "active",
13 billing_address: {
14 city: "San Francisco",
15 line1: "123 Business Ave",
16 line2: "Suite 100",
17 state: "CA",
18 country: "USA",
19 zip_code: "94105"
20 }
21}

Retrieve a Customer

Retrieves a customer by its internal and/or external IDs.

SDK Functions

1# Retrieve customer using its internal ID
2customer = api.customers.get(customer_id: id)
3
4# Retrieve customer using its external (custom) ID
5customer = api.customers.get_by_external_id(external_id: external_id)

Returns

Returns the up-to-date Customer object for a valid identifier. Raises an error if parameters are invalid (e.g. specifying an invalid internal/external customer IDs.

1{
2 id: "uuid",
3 organization_id: "uuid",
4 name: "Acme Corporation",
5 phone: "+1-555-0123",
6 website: "https://acme.com",
7 employee_count: 100,
8 annual_revenue: 1000000,
9 tax_exempt_status: "none",
10 creation_source: "api",
11 external_id: "acme_123",
12 creation_state: "active",
13 billing_address: {
14 city: "San Francisco",
15 line1: "123 Business Ave",
16 line2: "Suite 100",
17 state: "CA",
18 country: "USA",
19 zip_code: "94105"
20 }
21}

List all Customers

Retrieves all customers associated with your organization.

1# List all customers
2customers = api.customers.list()

Returns

Returns the up-to-date list of Customer objects.

1[
2 {
3 id: 'uuid',
4 organization_id: 'uuid',
5 name: 'Acme Corporation',
6 phone: '+1-555-0123',
7 ...
8 },
9 {
10 id: 'uuid',
11 organization_id: 'uuid',
12 name: 'Emca Corporation ',
13 phone: '+1-555-0123',
14 ...
15 }
16]

Update a Customer

Updates an existing customer by its internal and/or external IDs.

SDK Functions

1# Update customer using its internal ID
2update_data = {
3 name: "Acme Corp",
4 phone: "+1-555-0124",
5 employee_count: 150
6}
7
8customer = api.customers.update(
9 customer_id: id,
10 request: update_data
11)
12
13# Update customer using its external (custom) ID
14customer = api.customers.update_by_external_id(
15 external_id: id,
16 request: update_data
17)

Returns

Returns the updated Customer if the update succeeded. Raises an error if update parameters are invalid (e.g. specifying an invalid customer ID)

1{
2 id: "uuid",
3 organization_id: "uuid",
4 name: "Acme Corporation",
5 phone: "+1-555-0123",
6 website: "https://acme.com",
7 employee_count: 100,
8 annual_revenue: 1000000,
9 tax_exempt_status: "none",
10 creation_source: "api",
11 external_id: "acme_123",
12 creation_state: "active",
13 billing_address: {
14 city: "San Francisco",
15 line1: "123 Business Ave",
16 line2: "Suite 100",
17 state: "CA",
18 country: "USA",
19 zip_code: "94105"
20 }
21}

Delete a Customer

Deletes a customer by its internal and/or external IDs.

SDK Functions

1# Delete customer using its internal ID
2api.customers.delete(customer_id: id)
3
4# Delete customer using its external (custom) ID
5api.customers.delete_by_external_id(external_id: id)

Error Handling

The API uses conventional HTTP response codes to indicate the success or failure of requests:

  • 2xx range indicates success
  • 4xx range indicates an error that failed given the information provided
  • 5xx range indicates an error with Paid’s servers

Error Response Format

1{
2 "error": {
3 "message": "Error message",
4 "code": "ERROR_CODE",
5 "details": "Additional error details"
6 }
7}

Common Error Codes

CodeDescription
ACCOUNT_NOT_FOUNDThe specified customer does not exist
INVALID_REQUESTThe request was invalid
UNAUTHORIZEDThe API key is invalid
FORBIDDENThe API key doesn’t have permission to access the resource
INTERNAL_SERVER_ERRORAn error occurred on Paid’s servers