Module: LoyverseApi::Endpoints::Customers

Included in:
Client
Defined in:
lib/loyverse_api/endpoints/customers.rb

Instance Method Summary collapse

Instance Method Details

#create_customer(name:, email: nil, phone_number: nil, address: nil, city: nil, region: nil, postal_code: nil, country: nil, customer_code: nil, note: nil, first_visit: nil, total_visits: nil, total_spent: nil) ⇒ Hash

Create a new customer

Parameters:

  • name (String) —

    Customer name

  • email (String) (defaults to: nil) —

    Customer email (optional)

  • phone_number (String) (defaults to: nil) —

    Customer phone number (optional)

  • address (String) (defaults to: nil) —

    Customer address (optional)

  • city (String) (defaults to: nil) —

    Customer city (optional)

  • region (String) (defaults to: nil) —

    Customer region/state (optional)

  • postal_code (String) (defaults to: nil) —

    Customer postal code (optional)

  • country (String) (defaults to: nil) —

    Customer country (optional)

  • customer_code (String) (defaults to: nil) —

    Custom customer code (optional)

  • note (String) (defaults to: nil) —

    Customer note (optional)

  • first_visit (String, Time) (defaults to: nil) —

    Date of first visit (optional)

  • total_visits (Integer) (defaults to: nil) —

    Total number of visits (optional)

  • total_spent (Float) (defaults to: nil) —

    Total amount spent (optional)

Returns:

  • (Hash) —

    Created customer details



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/loyverse_api/endpoints/customers.rb', line 47

def create_customer(
  name:,
  email: nil,
  phone_number: nil,
  address: nil,
  city: nil,
  region: nil,
  postal_code: nil,
  country: nil,
  customer_code: nil,
  note: nil,
  first_visit: nil,
  total_visits: nil,
  total_spent: nil
)
  body = {
    name: name,
    email: email,
    phone_number: phone_number,
    address: address,
    city: city,
    region: region,
    postal_code: postal_code,
    country: country,
    customer_code: customer_code,
    note: note,
    first_visit: format_time(first_visit),
    total_visits: total_visits,
    total_spent: total_spent
  }.compact

  post("customers", body: body)
end

#delete_customer(customer_id) ⇒ Hash

Delete a customer

Parameters:

  • customer_id (String) —

    UUID of the customer

Returns:

  • (Hash) —

    Response



126
127
128
# File 'lib/loyverse_api/endpoints/customers.rb', line 126

def delete_customer(customer_id)
  delete("customers/#{customer_id}")
end

#get_customer(customer_id) ⇒ Hash

Get a specific customer by ID

Parameters:

  • customer_id (String) —

    UUID of the customer

Returns:

  • (Hash) —

    Customer details



7
8
9
# File 'lib/loyverse_api/endpoints/customers.rb', line 7

def get_customer(customer_id)
  get("customers/#{customer_id}")
end

#list_customers(limit: 250, cursor: nil, email: nil, phone_number: nil, updated_at_min: nil, updated_at_max: nil) ⇒ Hash

List customers

Parameters:

  • limit (Integer) (defaults to: 250) —

    Maximum number of results per page (default: 250)

  • cursor (String) (defaults to: nil) —

    Pagination cursor for next page

  • email (String) (defaults to: nil) —

    Filter by email address (optional)

  • phone_number (String) (defaults to: nil) —

    Filter by phone number (optional)

  • updated_at_min (String, Time) (defaults to: nil) —

    Filter by minimum update time (ISO 8601)

  • updated_at_max (String, Time) (defaults to: nil) —

    Filter by maximum update time (ISO 8601)

Returns:

  • (Hash) —

    Response with customers array



19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/loyverse_api/endpoints/customers.rb', line 19

def list_customers(limit: 250, cursor: nil, email: nil, phone_number: nil, updated_at_min: nil, updated_at_max: nil)
  params = {
    limit: limit,
    cursor: cursor,
    email: email,
    phone_number: phone_number,
    updated_at_min: format_time(updated_at_min),
    updated_at_max: format_time(updated_at_max)
  }.compact

  get("customers", params: params)
end

#update_customer(customer_id, name: nil, email: nil, phone_number: nil, address: nil, city: nil, region: nil, postal_code: nil, country: nil, customer_code: nil, note: nil) ⇒ Hash

Update an existing customer

Parameters:

  • customer_id (String) —

    UUID of the customer

  • name (String) (defaults to: nil) —

    Customer name (optional)

  • email (String) (defaults to: nil) —

    Customer email (optional)

  • phone_number (String) (defaults to: nil) —

    Customer phone number (optional)

  • address (String) (defaults to: nil) —

    Customer address (optional)

  • city (String) (defaults to: nil) —

    Customer city (optional)

  • region (String) (defaults to: nil) —

    Customer region/state (optional)

  • postal_code (String) (defaults to: nil) —

    Customer postal code (optional)

  • country (String) (defaults to: nil) —

    Customer country (optional)

  • customer_code (String) (defaults to: nil) —

    Custom customer code (optional)

  • note (String) (defaults to: nil) —

    Customer note (optional)

Returns:

  • (Hash) —

    Updated customer details



94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# File 'lib/loyverse_api/endpoints/customers.rb', line 94

def update_customer(
  customer_id,
  name: nil,
  email: nil,
  phone_number: nil,
  address: nil,
  city: nil,
  region: nil,
  postal_code: nil,
  country: nil,
  customer_code: nil,
  note: nil
)
  body = {
    name: name,
    email: email,
    phone_number: phone_number,
    address: address,
    city: city,
    region: region,
    postal_code: postal_code,
    country: country,
    customer_code: customer_code,
    note: note
  }.compact

  put("customers/#{customer_id}", body: body)
end