Module: PaymentKit::Resources::Customers
- Included in:
- Client
- Defined in:
- lib/payment_kit/resources/customers.rb
Overview
Customers, credit balance and credit notes.
Write methods accept the body positionally or as keywords, and take an
optional idempotency_key::
client.create_customer(email: "a@b.com")
client.create_customer({ email: "a@b.com" }, idempotency_key: "signup-42")
Instance Method Summary collapse
-
#create_balance_transaction(customer_id, params = nil) ⇒ Object
Deprecated. Use #set_credit_balance.
-
#create_credit_note(customer_id, params = nil) ⇒ Object
Appends a credit note (an additive adjustment) to the customer balance.
-
#create_customer(params = nil) ⇒ Object
POST /customers/ — takes
email,first_name,last_name,business_name,address,currency,metadataand friends. -
#list_credit_notes(customer_id, params = {}) ⇒ Object
GET /customers/id/credit-notes — newest first; filter with
currency. -
#list_customers(params = {}) ⇒ Object
GET /customers/ — auto-paginated Array of customers.
-
#retrieve_customer(id) ⇒ Object
GET /customers/id.
-
#set_credit_balance(customer_id, params = nil) ⇒ Object
Sets the customer's credit balance to an ABSOLUTE target for the given currency — PaymentKit issues or voids credit to reach it.
-
#update_customer(id, params = nil) ⇒ Object
PUT /customers/id — only the fields you send are changed.
Instance Method Details
#create_balance_transaction(customer_id, params = nil) ⇒ Object
Deprecated. Use #set_credit_balance. The name implied delta semantics, but the endpoint sets an absolute target balance.
41 42 43 44 45 |
# File 'lib/payment_kit/resources/customers.rb', line 41 def create_balance_transaction(customer_id, params = nil, **) warn("[PaymentKit] create_balance_transaction is deprecated; use set_credit_balance. " \ "The endpoint sets an absolute target balance, not a delta.") set_credit_balance(customer_id, params, **) end |
#create_credit_note(customer_id, params = nil) ⇒ Object
Appends a credit note (an additive adjustment) to the customer balance.
Always pass a stable idempotency_key: a double submit issues two notes.
reason is required and must be one of proration_excess,
manual_adjustment, auto_apply or debit_settlement.
52 53 54 |
# File 'lib/payment_kit/resources/customers.rb', line 52 def create_credit_note(customer_id, params = nil, **) post("/customers/#{customer_id}/credit-notes", params, **) end |
#create_customer(params = nil) ⇒ Object
POST /customers/ — takes email, first_name, last_name,
business_name, address, currency, metadata and friends.
19 |
# File 'lib/payment_kit/resources/customers.rb', line 19 def create_customer(params = nil, **) = post("/customers/", params, **) |
#list_credit_notes(customer_id, params = {}) ⇒ Object
GET /customers/id/credit-notes — newest first; filter with currency.
57 58 59 |
# File 'lib/payment_kit/resources/customers.rb', line 57 def list_credit_notes(customer_id, params = {}) list("/customers/#{customer_id}/credit-notes", params) end |
#list_customers(params = {}) ⇒ Object
GET /customers/ — auto-paginated Array of customers.
28 |
# File 'lib/payment_kit/resources/customers.rb', line 28 def list_customers(params = {}) = list("/customers/", params) |
#retrieve_customer(id) ⇒ Object
GET /customers/id
22 |
# File 'lib/payment_kit/resources/customers.rb', line 22 def retrieve_customer(id) = get("/customers/#{id}") |
#set_credit_balance(customer_id, params = nil) ⇒ Object
Sets the customer's credit balance to an ABSOLUTE target for the given currency — PaymentKit issues or voids credit to reach it. This is not a delta; use #create_credit_note to add credit incrementally.
client.set_credit_balance("cus_1", amount_atom: 5000, currency: "USD")
35 36 37 |
# File 'lib/payment_kit/resources/customers.rb', line 35 def set_credit_balance(customer_id, params = nil, **) patch("/customers/#{customer_id}/credit-balance", params, **) end |
#update_customer(id, params = nil) ⇒ Object
PUT /customers/id — only the fields you send are changed.
25 |
# File 'lib/payment_kit/resources/customers.rb', line 25 def update_customer(id, params = nil, **) = put("/customers/#{id}", params, **) |