Class: AbacatePay::Resources::Customers
- Defined in:
- lib/abacate_pay/resources/customers.rb,
lib/abacate_pay/resources/customers/metadata.rb
Overview
Represents a customer in the AbacatePay system.
The API returns the customer fields at the top level of the object:
{ "id": "cust_...", "name": "Ana", "email": "ana@example.com",
"cellphone": "...", "taxId": "...", "metadata": {} }
Earlier versions of this class only mapped id and a nested metadata,
so every other field was silently dropped and customer.metadata.name
came back nil for real API data.
Both shapes work now: the fields are exposed directly, and metadata
keeps answering for code written against the previous interface.
Defined Under Namespace
Classes: Metadata
Constant Summary collapse
- RESOURCE_PROPERTIES =
{ metadata: "AbacatePay::Resources::Customers::Metadata" }.freeze
- IDENTITY_FIELDS =
Fields the API sends inside the customer object.
%i[name email cellphone tax_id].freeze
Instance Attribute Summary collapse
-
#cellphone ⇒ String?
readonly
Customer's cellphone number.
-
#country ⇒ Object
readonly
Returns the value of attribute country.
-
#dev_mode ⇒ Object
readonly
Returns the value of attribute dev_mode.
-
#email ⇒ String?
readonly
Customer's email address.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#metadata ⇒ Customers::Metadata?
readonly
The identity fields, wrapped.
-
#name ⇒ String?
readonly
Customer's name.
-
#tax_id ⇒ String?
readonly
Customer's tax identification number.
-
#zip_code ⇒ Object
readonly
Returns the value of attribute zip_code.
Instance Method Summary collapse
-
#dev_mode? ⇒ Boolean?
Whether this customer belongs to Dev mode.
-
#initialize(data) ⇒ Customers
constructor
A new instance of Customers.
Constructor Details
#initialize(data) ⇒ Customers
Returns a new instance of Customers.
41 42 43 |
# File 'lib/abacate_pay/resources/customers.rb', line 41 def initialize(data) fill(data) end |
Instance Attribute Details
#cellphone ⇒ String?
Returns Customer's cellphone number.
35 36 37 |
# File 'lib/abacate_pay/resources/customers.rb', line 35 def cellphone @cellphone end |
#country ⇒ Object
Returns the value of attribute country.
26 27 28 |
# File 'lib/abacate_pay/resources/customers.rb', line 26 def country @country end |
#dev_mode ⇒ Object
Returns the value of attribute dev_mode.
26 27 28 |
# File 'lib/abacate_pay/resources/customers.rb', line 26 def dev_mode @dev_mode end |
#email ⇒ String?
Returns Customer's email address.
32 33 34 |
# File 'lib/abacate_pay/resources/customers.rb', line 32 def email @email end |
#id ⇒ Object
Returns the value of attribute id.
26 27 28 |
# File 'lib/abacate_pay/resources/customers.rb', line 26 def id @id end |
#metadata ⇒ Customers::Metadata?
The identity fields, wrapped.
Kept because customer.metadata.name is what the README documented and
what existing integrations call. When the API sends the fields at the
top level, this builds the wrapper from them rather than returning the
empty object the API puts in metadata.
58 59 60 61 62 63 64 65 |
# File 'lib/abacate_pay/resources/customers.rb', line 58 def return @metadata if (@metadata) identity = IDENTITY_FIELDS.to_h { |field| [field, public_send(field)] }.compact return @metadata if identity.empty? Customers::Metadata.new(identity) end |
#name ⇒ String?
Returns Customer's name.
29 30 31 |
# File 'lib/abacate_pay/resources/customers.rb', line 29 def name @name end |
#tax_id ⇒ String?
Returns Customer's tax identification number.
38 39 40 |
# File 'lib/abacate_pay/resources/customers.rb', line 38 def tax_id @tax_id end |
#zip_code ⇒ Object
Returns the value of attribute zip_code.
26 27 28 |
# File 'lib/abacate_pay/resources/customers.rb', line 26 def zip_code @zip_code end |
Instance Method Details
#dev_mode? ⇒ Boolean?
Returns Whether this customer belongs to Dev mode.
46 47 48 |
# File 'lib/abacate_pay/resources/customers.rb', line 46 def dev_mode? @dev_mode end |