Class: NewStoreApi::CashPayment

Inherits:
BaseModel
  • Object
show all
Defined in:
lib/new_store_api/models/cash_payment.rb

Overview

A cash payment.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseModel

#check_for_conflict, #process_additional_properties, #process_array, #process_basic_value, #process_hash, #to_hash, #to_json

Constructor Details

#initialize(amount = nil, cash = nil, currency = nil, processed_at = nil, status = nil, billing_address = SKIP) ⇒ CashPayment

Returns a new instance of CashPayment.



79
80
81
82
83
84
85
86
87
88
89
# File 'lib/new_store_api/models/cash_payment.rb', line 79

def initialize(amount = nil, cash = nil, currency = nil, processed_at = nil,
               status = nil, billing_address = SKIP)
  @amount = amount
  @billing_address = billing_address unless billing_address == SKIP
  @cash = cash
  @currency = currency
  @payment_method = 'cash'
  @payment_provider = 'cash'
  @processed_at = processed_at
  @status = status
end

Instance Attribute Details

#amountInteger

Payment amount, in the currency's minor unit. The instruments' amounts must add up to the order total: the sum of each line item's price — already net of its discounts — plus its price_tax under TAX_EXCLUDED pricing, plus any fulfillment charges.

Returns:

  • (Integer)


18
19
20
# File 'lib/new_store_api/models/cash_payment.rb', line 18

def amount
  @amount
end

#billing_addressAddress1

Billing address for this payment instrument. Optional. When supplied on more than one instrument, all must be identical (the platform currently supports a single billing address per order).

Returns:



24
25
26
# File 'lib/new_store_api/models/cash_payment.rb', line 24

def billing_address
  @billing_address
end

#cashCashDetails

Cash-specific details.

Returns:



28
29
30
# File 'lib/new_store_api/models/cash_payment.rb', line 28

def cash
  @cash
end

#currencyCurrency1Enum

The currency of the payment.

Returns:



32
33
34
# File 'lib/new_store_api/models/cash_payment.rb', line 32

def currency
  @currency
end

#payment_methodString (readonly)

The payment method.

Returns:

  • (String)


36
37
38
# File 'lib/new_store_api/models/cash_payment.rb', line 36

def payment_method
  @payment_method
end

#payment_providerString (readonly)

The payment provider for a cash payment; always cash.

Returns:

  • (String)


40
41
42
# File 'lib/new_store_api/models/cash_payment.rb', line 40

def payment_provider
  @payment_provider
end

#processed_atDateTime

When the payment was processed, as an RFC 3339 (ISO 8601) date-time including date, time and timezone.

Returns:

  • (DateTime)


45
46
47
# File 'lib/new_store_api/models/cash_payment.rb', line 45

def processed_at
  @processed_at
end

#statusPaymentStatusEnum

Whether the payment is already authorized or already captured.

Returns:



49
50
51
# File 'lib/new_store_api/models/cash_payment.rb', line 49

def status
  @status
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/new_store_api/models/cash_payment.rb', line 92

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  amount = hash.key?('amount') ? hash['amount'] : nil
  cash = CashDetails.from_hash(hash['cash']) if hash['cash']
  currency = hash.key?('currency') ? hash['currency'] : nil
  processed_at = if hash.key?('processed_at')
                   (DateTimeHelper.from_rfc3339(hash['processed_at']) if hash['processed_at'])
                 end
  status = hash.key?('status') ? hash['status'] : nil
  billing_address = Address1.from_hash(hash['billing_address']) if hash['billing_address']

  # Create object from extracted values.
  CashPayment.new(amount,
                  cash,
                  currency,
                  processed_at,
                  status,
                  billing_address)
end

.namesObject

A mapping from model property names to API property names.



52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/new_store_api/models/cash_payment.rb', line 52

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['amount'] = 'amount'
  @_hash['billing_address'] = 'billing_address'
  @_hash['cash'] = 'cash'
  @_hash['currency'] = 'currency'
  @_hash['payment_method'] = 'payment_method'
  @_hash['payment_provider'] = 'payment_provider'
  @_hash['processed_at'] = 'processed_at'
  @_hash['status'] = 'status'
  @_hash
end

.nullablesObject

An array for nullable fields



73
74
75
76
77
# File 'lib/new_store_api/models/cash_payment.rb', line 73

def self.nullables
  %w[
    billing_address
  ]
end

.optionalsObject

An array for optional fields



66
67
68
69
70
# File 'lib/new_store_api/models/cash_payment.rb', line 66

def self.optionals
  %w[
    billing_address
  ]
end

.validate(value) ⇒ Object

Validates an instance of the object from a given value.

Parameters:

  • The (CashPayment | Hash)

    value against the validation is performed.



120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
# File 'lib/new_store_api/models/cash_payment.rb', line 120

def self.validate(value)
  if value.instance_of? self
    return (
      APIHelper.valid_type?(value.amount,
                            ->(val) { val.instance_of? Integer }) and
        APIHelper.valid_type?(value.cash,
                              ->(val) { CashDetails.validate(val) },
                              is_model_hash: true) and
        APIHelper.valid_type?(value.currency,
                              ->(val) { Currency1Enum.validate(val) }) and
        APIHelper.valid_type?(value.payment_method,
                              ->(val) { val.instance_of? String }) and
        APIHelper.valid_type?(value.payment_provider,
                              ->(val) { val.instance_of? String }) and
        APIHelper.valid_type?(value.processed_at,
                              ->(val) { val.instance_of? DateTime }) and
        APIHelper.valid_type?(value.status,
                              ->(val) { PaymentStatusEnum.validate(val) })
    )
  end

  return false unless value.instance_of? Hash

  (
    APIHelper.valid_type?(value['amount'],
                          ->(val) { val.instance_of? Integer }) and
      APIHelper.valid_type?(value['cash'],
                            ->(val) { CashDetails.validate(val) },
                            is_model_hash: true) and
      APIHelper.valid_type?(value['currency'],
                            ->(val) { Currency1Enum.validate(val) }) and
      APIHelper.valid_type?(value['payment_method'],
                            ->(val) { val.instance_of? String }) and
      APIHelper.valid_type?(value['payment_provider'],
                            ->(val) { val.instance_of? String }) and
      APIHelper.valid_type?(value['processed_at'],
                            ->(val) { val.instance_of? String }) and
      APIHelper.valid_type?(value['status'],
                            ->(val) { PaymentStatusEnum.validate(val) })
  )
end

Instance Method Details

#inspectObject

Provides a debugging-friendly string with detailed object information.



171
172
173
174
175
176
177
# File 'lib/new_store_api/models/cash_payment.rb', line 171

def inspect
  class_name = self.class.name.split('::').last
  "<#{class_name} amount: #{@amount.inspect}, billing_address: #{@billing_address.inspect},"\
  " cash: #{@cash.inspect}, currency: #{@currency.inspect}, payment_method:"\
  " #{@payment_method.inspect}, payment_provider: #{@payment_provider.inspect}, processed_at:"\
  " #{@processed_at.inspect}, status: #{@status.inspect}>"
end

#to_custom_processed_atObject



114
115
116
# File 'lib/new_store_api/models/cash_payment.rb', line 114

def to_custom_processed_at
  DateTimeHelper.to_rfc3339(processed_at)
end

#to_sObject

Provides a human-readable string representation of the object.



163
164
165
166
167
168
# File 'lib/new_store_api/models/cash_payment.rb', line 163

def to_s
  class_name = self.class.name.split('::').last
  "<#{class_name} amount: #{@amount}, billing_address: #{@billing_address}, cash: #{@cash},"\
  " currency: #{@currency}, payment_method: #{@payment_method}, payment_provider:"\
  " #{@payment_provider}, processed_at: #{@processed_at}, status: #{@status}>"
end