Class: NewStoreApi::CashPayment
- Defined in:
- lib/new_store_api/models/cash_payment.rb
Overview
A cash payment.
Instance Attribute Summary collapse
-
#amount ⇒ Integer
Payment amount, in the currency's minor unit.
-
#billing_address ⇒ Address1
Billing address for this payment instrument.
-
#cash ⇒ CashDetails
Cash-specific details.
-
#currency ⇒ Currency1Enum
The currency of the payment.
-
#payment_method ⇒ String
readonly
The payment method.
-
#payment_provider ⇒ String
readonly
The payment provider for a cash payment; always
cash. -
#processed_at ⇒ DateTime
When the payment was processed, as an RFC 3339 (ISO 8601) date-time including date, time and timezone.
-
#status ⇒ PaymentStatusEnum
Whether the payment is already authorized or already captured.
Class Method Summary collapse
-
.from_hash(hash) ⇒ Object
Creates an instance of the object from a hash.
-
.names ⇒ Object
A mapping from model property names to API property names.
-
.nullables ⇒ Object
An array for nullable fields.
-
.optionals ⇒ Object
An array for optional fields.
-
.validate(value) ⇒ Object
Validates an instance of the object from a given value.
Instance Method Summary collapse
-
#initialize(amount = nil, cash = nil, currency = nil, processed_at = nil, status = nil, billing_address = SKIP) ⇒ CashPayment
constructor
A new instance of CashPayment.
-
#inspect ⇒ Object
Provides a debugging-friendly string with detailed object information.
- #to_custom_processed_at ⇒ Object
-
#to_s ⇒ Object
Provides a human-readable string representation of the object.
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
#amount ⇒ Integer
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.
18 19 20 |
# File 'lib/new_store_api/models/cash_payment.rb', line 18 def amount @amount end |
#billing_address ⇒ Address1
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).
24 25 26 |
# File 'lib/new_store_api/models/cash_payment.rb', line 24 def billing_address @billing_address end |
#cash ⇒ CashDetails
Cash-specific details.
28 29 30 |
# File 'lib/new_store_api/models/cash_payment.rb', line 28 def cash @cash end |
#currency ⇒ Currency1Enum
The currency of the payment.
32 33 34 |
# File 'lib/new_store_api/models/cash_payment.rb', line 32 def currency @currency end |
#payment_method ⇒ String (readonly)
The payment method.
36 37 38 |
# File 'lib/new_store_api/models/cash_payment.rb', line 36 def payment_method @payment_method end |
#payment_provider ⇒ String (readonly)
The payment provider for a cash payment; always cash.
40 41 42 |
# File 'lib/new_store_api/models/cash_payment.rb', line 40 def payment_provider @payment_provider end |
#processed_at ⇒ DateTime
When the payment was processed, as an RFC 3339 (ISO 8601) date-time including date, time and timezone.
45 46 47 |
# File 'lib/new_store_api/models/cash_payment.rb', line 45 def processed_at @processed_at end |
#status ⇒ PaymentStatusEnum
Whether the payment is already authorized or already captured.
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 |
.names ⇒ Object
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 |
.nullables ⇒ Object
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 |
.optionals ⇒ Object
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.
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
#inspect ⇒ Object
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_at ⇒ Object
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_s ⇒ Object
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 |