Class: Nombaone::Resources::Customers
- Inherits:
-
BaseResource
- Object
- BaseResource
- Nombaone::Resources::Customers
- Defined in:
- lib/nombaone/resources/customers.rb,
sig/nombaone/resources.rbs
Overview
Customers — the people and businesses you bill.
Instance Method Summary collapse
-
#apply_discount(id, coupon:, request_options: {}) ⇒ NombaObject
Apply a coupon to a customer.
-
#create(email:, name:, phone: OMIT, metadata: OMIT, request_options: {}) ⇒ NombaObject
Create a customer.
-
#grant_credit(id, amount_in_kobo:, source: OMIT, source_reference: OMIT, metadata: OMIT, request_options: {}) ⇒ NombaObject
Grant credit to a customer.
-
#list(email: OMIT, limit: OMIT, cursor: OMIT, request_options: {}) ⇒ Page<NombaObject>
List customers, newest first.
-
#remove_discount(id, request_options: {}) ⇒ NombaObject
Remove the customer's active discount.
-
#retrieve(id, request_options: {}) ⇒ NombaObject
Retrieve a customer by id.
-
#retrieve_credit_balance(id, request_options: {}) ⇒ NombaObject
Retrieve the customer's credit balance and the grants behind it.
-
#update(id, name: OMIT, phone: OMIT, metadata: OMIT, request_options: {}) ⇒ NombaObject
Update a customer's mutable fields.
-
#void_credit(id, grant_id, request_options: {}) ⇒ NombaObject
Void a credit grant — its remaining balance becomes unusable.
Methods inherited from BaseResource
#encode, #initialize, #request, #request_page
Constructor Details
This class inherits a constructor from Nombaone::Resources::BaseResource
Instance Method Details
#apply_discount(id, coupon:, request_options: {}) ⇒ NombaObject
Apply a coupon to a customer. The resulting discount shapes every future invoice for the customer until it ends or is removed.
92 93 94 95 |
# File 'lib/nombaone/resources/customers.rb', line 92 def apply_discount(id, coupon:, request_options: {}) request(:post, "/customers/#{encode(id)}/discount", body: { coupon: coupon }, options: ) end |
#create(email:, name:, phone: OMIT, metadata: OMIT, request_options: {}) ⇒ NombaObject
Create a customer.
30 31 32 33 34 |
# File 'lib/nombaone/resources/customers.rb', line 30 def create(email:, name:, phone: OMIT, metadata: OMIT, request_options: {}) request(:post, "/customers", body: { email: email, name: name, phone: phone, metadata: }, options: ) end |
#grant_credit(id, amount_in_kobo:, source: OMIT, source_reference: OMIT, metadata: OMIT, request_options: {}) ⇒ NombaObject
Grant credit to a customer. Credit is drawn down oldest-grant-first by future invoices before any payment rail is charged.
This moves money-shaped state, so the API requires an Idempotency-Key;
the SDK sends one automatically. Pass request_options[:idempotency_key]
to keep the grant idempotent across process restarts.
125 126 127 128 129 130 131 132 133 134 135 |
# File 'lib/nombaone/resources/customers.rb', line 125 def grant_credit(id, amount_in_kobo:, source: OMIT, source_reference: OMIT, metadata: OMIT, request_options: {}) request(:post, "/customers/#{encode(id)}/credit", body: { amount_in_kobo: amount_in_kobo, source: source, source_reference: source_reference, metadata: , }, options: ) end |
#list(email: OMIT, limit: OMIT, cursor: OMIT, request_options: {}) ⇒ Page<NombaObject>
List customers, newest first.
74 75 76 77 78 |
# File 'lib/nombaone/resources/customers.rb', line 74 def list(email: OMIT, limit: OMIT, cursor: OMIT, request_options: {}) request_page("/customers", query: { email: email, limit: limit, cursor: cursor }, options: ) end |
#remove_discount(id, request_options: {}) ⇒ NombaObject
Remove the customer's active discount. Returns the ended discount.
102 103 104 |
# File 'lib/nombaone/resources/customers.rb', line 102 def remove_discount(id, request_options: {}) request(:delete, "/customers/#{encode(id)}/discount", options: ) end |
#retrieve(id, request_options: {}) ⇒ NombaObject
Retrieve a customer by id.
43 44 45 |
# File 'lib/nombaone/resources/customers.rb', line 43 def retrieve(id, request_options: {}) request(:get, "/customers/#{encode(id)}", options: ) end |
#retrieve_credit_balance(id, request_options: {}) ⇒ NombaObject
Retrieve the customer's credit balance and the grants behind it.
142 143 144 |
# File 'lib/nombaone/resources/customers.rb', line 142 def retrieve_credit_balance(id, request_options: {}) request(:get, "/customers/#{encode(id)}/credit", options: ) end |
#update(id, name: OMIT, phone: OMIT, metadata: OMIT, request_options: {}) ⇒ NombaObject
Update a customer's mutable fields. At least one field is required.
58 59 60 61 62 |
# File 'lib/nombaone/resources/customers.rb', line 58 def update(id, name: OMIT, phone: OMIT, metadata: OMIT, request_options: {}) request(:patch, "/customers/#{encode(id)}", body: { name: name, phone: phone, metadata: }, options: ) end |
#void_credit(id, grant_id, request_options: {}) ⇒ NombaObject
Void a credit grant — its remaining balance becomes unusable. Consumed credit is untouched.
154 155 156 157 |
# File 'lib/nombaone/resources/customers.rb', line 154 def void_credit(id, grant_id, request_options: {}) request(:delete, "/customers/#{encode(id)}/credit/#{encode(grant_id)}", options: ) end |