Class: AbacatePay::Resources::Customers

Inherits:
Resource
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ Customers

Returns a new instance of Customers.

Parameters:

  • data (Hash)

    The customer properties



41
42
43
# File 'lib/abacate_pay/resources/customers.rb', line 41

def initialize(data)
  fill(data)
end

Instance Attribute Details

#cellphoneString?

Returns Customer's cellphone number.

Returns:

  • (String, nil)

    Customer's cellphone number



35
36
37
# File 'lib/abacate_pay/resources/customers.rb', line 35

def cellphone
  @cellphone
end

#countryObject

Returns the value of attribute country.



26
27
28
# File 'lib/abacate_pay/resources/customers.rb', line 26

def country
  @country
end

#dev_modeObject

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

#emailString?

Returns Customer's email address.

Returns:

  • (String, nil)

    Customer's email address



32
33
34
# File 'lib/abacate_pay/resources/customers.rb', line 32

def email
  @email
end

#idObject

Returns the value of attribute id.



26
27
28
# File 'lib/abacate_pay/resources/customers.rb', line 26

def id
  @id
end

#metadataCustomers::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.

Returns:



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

#nameString?

Returns Customer's name.

Returns:

  • (String, nil)

    Customer's name



29
30
31
# File 'lib/abacate_pay/resources/customers.rb', line 29

def name
  @name
end

#tax_idString?

Returns Customer's tax identification number.

Returns:

  • (String, nil)

    Customer's tax identification number



38
39
40
# File 'lib/abacate_pay/resources/customers.rb', line 38

def tax_id
  @tax_id
end

#zip_codeObject

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.

Returns:

  • (Boolean, nil)

    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