Work with customers (SDK)

United States
Canada

Knowing customer information is central to running a business, so the SDK provides ways for apps to create and maintain up-to-date customer data. Especially important is the ability to connect a customer and card token so that return customers can make payments quickly and easily.

Create a customer

To create an order, call the create a customer endpoint and pass in the minimum required customer information, the customer's email and a source, the card token used for payments.

from clover import Customer

customer = Customer.create(
    email='[email protected]',
    source='clv_1TSTSpbfbN6Jh5CqCm3bMQne'
)
require('dotenv').config();
const Clover = require("clover-ecomm-sdk");

let ACCESS_TOKEN = process.env.ACCESS_TOKEN;
let ENVIRONMENT = process.env.ENVIRONMENT;

const cloverInst = new Clover(ACCESS_TOKEN, {
  environment: ENVIRONMENT
});

let customer = cloverInst.customers.create({
    email:'[email protected]',
    source:'clv_1TSTSpbfbN6Jh5CqCm3bMQne'
});

This returns a token object in JSON. The id value is the unique identifier of the customer.

{
    "id": "ANKHTCV4BZCVW",
    "object": "customer",
    "created": 1580489482717,
    "currency": "usd",
    "email": "[email protected]",
    "sources": {
        "object": "list",
        "data": [
            "7E8EH4WWHK5N6"
        ],
        "has_more": False
    },
    "shipping": {}
}

Additional customer data, such as their name, phone and shipping details, can be included in the request.

from clover import Customer

customer = Customer.create(
    email='[email protected]',
    source='clv_1TSTSpbfbN6Jh5CqCm3bMQne',
    shipping={
        'address': {
            'city': 'Sunnyvale',
            'state': 'CA',
            'line1': '415 N Mathilda Ave',
            'postal_code': '94085'
        }
    },
    name='New Customer',
    phone='555-0125'
)
require('dotenv').config();
const Clover = require("clover-ecomm-sdk");

let ACCESS_TOKEN = process.env.ACCESS_TOKEN;
let ENVIRONMENT = process.env.ENVIRONMENT;

const cloverInst = new Clover(ACCESS_TOKEN, {
  environment: ENVIRONMENT
});

let customer = cloverInst.customers.create({
    email:'[email protected]',
    source: 'clv_1TSTSpbfbN6Jh5CqCm3bMQne',
    shipping: {
      'address': {
          'city': 'Sunnyvale',
          'state': 'CA',
          'line1': '415 N Mathilda Ave',
          'postal_code': '94085'
      }
  },
  name: 'New Customer',
  phone: '555-0125'
});

Update customer information

A customer may need to update their information if they get a new credit card, change addresses, or for a number of other reasons. To update the customer, call the update a customer method with the id of the customer and any data to be changed.

from clover import Customer

update = Customer.modify(customerId, name="Updated Name")
require('dotenv').config();
const Clover = require("clover-ecomm-sdk");

let ACCESS_TOKEN = process.env.ACCESS_TOKEN;
let ENVIRONMENT = process.env.ENVIRONMENT;

const cloverInst = new Clover(ACCESS_TOKEN, {
  environment: ENVIRONMENT
});

cloverInst.customers.update({
  customerId: customerId,
  name: 'Updated Name'
});

This returns a customer object in JSON. See the REST API Reference for complete information about the returned values.

{
  'id': 'AKK8FZK1NCPWC', 
  'object': 'customer',
  'created': 1582322821472,
  'currency': 'usd',
  'email': '[email protected]',
  'phone': '555-0125', 
  'name': 'Updated Name',
  'sources': {
    'object': 'list',
    'data': ['01B0G1CT3GCBT'],
    'has_more': False},
  'shipping': {
    'name': 'Updated Name',
    'phone': '555-0125',
    'address': {
      'line1': '415 N Mathilda Ave',
      'city': 'Sunnyvale',
      'state': 'CA',
      'postal_code': '94085',
      'country': 'US'
      }
    }
}