Class: NewStoreApi::CardPayment
- Defined in:
- lib/new_store_api/models/card_payment.rb
Overview
A card payment (credit or debit).
Instance Attribute Summary collapse
-
#amount ⇒ Integer
Payment amount, in the currency's minor unit.
-
#billing_address ⇒ Address1
Billing address for this payment instrument.
-
#card ⇒ CardDetails
Card-specific details.
-
#currency ⇒ Currency1Enum
The currency of the payment.
-
#payment_method ⇒ String
readonly
The payment method.
-
#payment_provider ⇒ String
The payment provider that processed the payment, for example
newstoreoradyen. -
#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, card = nil, currency = nil, payment_provider = nil, processed_at = nil, status = nil, billing_address = SKIP) ⇒ CardPayment
constructor
A new instance of CardPayment.
-
#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, card = nil, currency = nil, payment_provider = nil, processed_at = nil, status = nil, billing_address = SKIP) ⇒ CardPayment
Returns a new instance of CardPayment.
80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/new_store_api/models/card_payment.rb', line 80 def initialize(amount = nil, card = nil, currency = nil, payment_provider = nil, processed_at = nil, status = nil, billing_address = SKIP) @amount = amount @billing_address = billing_address unless billing_address == SKIP @card = card @currency = currency @payment_method = 'card' @payment_provider = payment_provider @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/card_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/card_payment.rb', line 24 def billing_address @billing_address end |
#card ⇒ CardDetails
Card-specific details.
28 29 30 |
# File 'lib/new_store_api/models/card_payment.rb', line 28 def card @card end |
#currency ⇒ Currency1Enum
The currency of the payment.
32 33 34 |
# File 'lib/new_store_api/models/card_payment.rb', line 32 def currency @currency end |
#payment_method ⇒ String (readonly)
The payment method.
36 37 38 |
# File 'lib/new_store_api/models/card_payment.rb', line 36 def payment_method @payment_method end |
#payment_provider ⇒ String
The payment provider that processed the payment, for example newstore or
adyen.
41 42 43 |
# File 'lib/new_store_api/models/card_payment.rb', line 41 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.
46 47 48 |
# File 'lib/new_store_api/models/card_payment.rb', line 46 def processed_at @processed_at end |
#status ⇒ PaymentStatusEnum
Whether the payment is already authorized or already captured.
50 51 52 |
# File 'lib/new_store_api/models/card_payment.rb', line 50 def status @status end |
Class Method Details
.from_hash(hash) ⇒ Object
Creates an instance of the object from a hash.
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/new_store_api/models/card_payment.rb', line 94 def self.from_hash(hash) return nil unless hash # Extract variables from the hash. amount = hash.key?('amount') ? hash['amount'] : nil card = CardDetails.from_hash(hash['card']) if hash['card'] currency = hash.key?('currency') ? hash['currency'] : nil payment_provider = hash.key?('payment_provider') ? hash['payment_provider'] : 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. CardPayment.new(amount, card, currency, payment_provider, processed_at, status, billing_address) end |
.names ⇒ Object
A mapping from model property names to API property names.
53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/new_store_api/models/card_payment.rb', line 53 def self.names @_hash = {} if @_hash.nil? @_hash['amount'] = 'amount' @_hash['billing_address'] = 'billing_address' @_hash['card'] = 'card' @_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
74 75 76 77 78 |
# File 'lib/new_store_api/models/card_payment.rb', line 74 def self.nullables %w[ billing_address ] end |
.optionals ⇒ Object
An array for optional fields
67 68 69 70 71 |
# File 'lib/new_store_api/models/card_payment.rb', line 67 def self.optionals %w[ billing_address ] end |
.validate(value) ⇒ Object
Validates an instance of the object from a given value.
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 161 162 163 164 165 |
# File 'lib/new_store_api/models/card_payment.rb', line 125 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.card, ->(val) { CardDetails.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['card'], ->(val) { CardDetails.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.
176 177 178 179 180 181 182 |
# File 'lib/new_store_api/models/card_payment.rb', line 176 def inspect class_name = self.class.name.split('::').last "<#{class_name} amount: #{@amount.inspect}, billing_address: #{@billing_address.inspect},"\ " card: #{@card.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
119 120 121 |
# File 'lib/new_store_api/models/card_payment.rb', line 119 def to_custom_processed_at DateTimeHelper.to_rfc3339(processed_at) end |
#to_s ⇒ Object
Provides a human-readable string representation of the object.
168 169 170 171 172 173 |
# File 'lib/new_store_api/models/card_payment.rb', line 168 def to_s class_name = self.class.name.split('::').last "<#{class_name} amount: #{@amount}, billing_address: #{@billing_address}, card: #{@card},"\ " currency: #{@currency}, payment_method: #{@payment_method}, payment_provider:"\ " #{@payment_provider}, processed_at: #{@processed_at}, status: #{@status}>" end |