Class: NewStoreApi::InjectedOrderPayment

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

Overview

A payment supplied for this order. Only payments that are already authorized or captured are supported. Tokens that are not authorized are not supported. The validity of a payment is not checked during import, so an order with invalid payments is imported successfully and fulfilled. For example, a payment validity issue can be a voided authorization or an incorrect payment amount.

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, correlation_ref = nil, method = nil, processed_at = nil, processor = nil, type = nil, metadata = SKIP, wallet = SKIP) ⇒ InjectedOrderPayment

Returns a new instance of InjectedOrderPayment.



87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/new_store_api/models/injected_order_payment.rb', line 87

def initialize(amount = nil, correlation_ref = nil, method = nil,
               processed_at = nil, processor = nil, type = nil,
                = SKIP, wallet = SKIP)
  @amount = amount
  @correlation_ref = correlation_ref
  @metadata =  unless  == SKIP
  @method = method
  @processed_at = processed_at
  @processor = processor
  @type = type
  @wallet = wallet unless wallet == SKIP
end

Instance Attribute Details

#amountFloat

TODO: Write general description for this method

Returns:

  • (Float)


20
21
22
# File 'lib/new_store_api/models/injected_order_payment.rb', line 20

def amount
  @amount
end

#correlation_refString

Identifies the payment for the given order among all payments. This identifier must be unique in the given order, regardless of the payment processor.

Returns:

  • (String)


26
27
28
# File 'lib/new_store_api/models/injected_order_payment.rb', line 26

def correlation_ref
  @correlation_ref
end

#metadataObject

Payment method specific information.

Returns:

  • (Object)


30
31
32
# File 'lib/new_store_api/models/injected_order_payment.rb', line 30

def 
  @metadata
end

#methodString

The selected payment method. Typical values are 'cash', 'credit_card', 'gift_card', or 'paypal'. Other values are possible depending on your payment providers.

Returns:

  • (String)


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

def method
  @method
end

#processed_atDateTime

Date representation of when the payment was processed, containing date, time and timezone as defined by https://tools.ietf.org/html/rfc3339 (ISO 8601).

Returns:

  • (DateTime)


42
43
44
# File 'lib/new_store_api/models/injected_order_payment.rb', line 42

def processed_at
  @processed_at
end

#processorString

Identifies the payment provider (processor) used to process the payment. Supported providers are stripe, paypal, cash, gift_card.

Returns:

  • (String)


47
48
49
# File 'lib/new_store_api/models/injected_order_payment.rb', line 47

def processor
  @processor
end

#typeType12Enum

The type of payment information that is passed: either the payment is already authorized, or already captured. The Order Injection API does not support not authorized payments (tokens).

Returns:



53
54
55
# File 'lib/new_store_api/models/injected_order_payment.rb', line 53

def type
  @type
end

#walletString

The payment wallet used in the transaction. For example, Apple Pay, Google Pay, etc. or Direct (when no wallet was used).

Returns:

  • (String)


58
59
60
# File 'lib/new_store_api/models/injected_order_payment.rb', line 58

def wallet
  @wallet
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# File 'lib/new_store_api/models/injected_order_payment.rb', line 101

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  amount = hash.key?('amount') ? hash['amount'] : nil
  correlation_ref =
    hash.key?('correlation_ref') ? hash['correlation_ref'] : nil
  method = hash.key?('method') ? hash['method'] : nil
  processed_at = if hash.key?('processed_at')
                   (DateTimeHelper.from_rfc3339(hash['processed_at']) if hash['processed_at'])
                 end
  processor = hash.key?('processor') ? hash['processor'] : nil
  type = hash.key?('type') ? hash['type'] : nil
   = hash.key?('metadata') ? hash['metadata'] : SKIP
  wallet = hash.key?('wallet') ? hash['wallet'] : SKIP

  # Create object from extracted values.
  InjectedOrderPayment.new(amount,
                           correlation_ref,
                           method,
                           processed_at,
                           processor,
                           type,
                           ,
                           wallet)
end

.namesObject

A mapping from model property names to API property names.



61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/new_store_api/models/injected_order_payment.rb', line 61

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['amount'] = 'amount'
  @_hash['correlation_ref'] = 'correlation_ref'
  @_hash['metadata'] = 'metadata'
  @_hash['method'] = 'method'
  @_hash['processed_at'] = 'processed_at'
  @_hash['processor'] = 'processor'
  @_hash['type'] = 'type'
  @_hash['wallet'] = 'wallet'
  @_hash
end

.nullablesObject

An array for nullable fields



83
84
85
# File 'lib/new_store_api/models/injected_order_payment.rb', line 83

def self.nullables
  []
end

.optionalsObject

An array for optional fields



75
76
77
78
79
80
# File 'lib/new_store_api/models/injected_order_payment.rb', line 75

def self.optionals
  %w[
    metadata
    wallet
  ]
end

.validate(value) ⇒ Object

Validates an instance of the object from a given value.

Parameters:



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
166
167
168
# File 'lib/new_store_api/models/injected_order_payment.rb', line 134

def self.validate(value)
  if value.instance_of? self
    return (
      APIHelper.valid_type?(value.amount,
                            ->(val) { val.instance_of? Float }) and
        APIHelper.valid_type?(value.correlation_ref,
                              ->(val) { val.instance_of? String }) and
        APIHelper.valid_type?(value.method,
                              ->(val) { val.instance_of? String }) and
        APIHelper.valid_type?(value.processed_at,
                              ->(val) { val.instance_of? DateTime }) and
        APIHelper.valid_type?(value.processor,
                              ->(val) { val.instance_of? String }) and
        APIHelper.valid_type?(value.type,
                              ->(val) { Type12Enum.validate(val) })
    )
  end

  return false unless value.instance_of? Hash

  (
    APIHelper.valid_type?(value['amount'],
                          ->(val) { val.instance_of? Float }) and
      APIHelper.valid_type?(value['correlation_ref'],
                            ->(val) { val.instance_of? String }) and
      APIHelper.valid_type?(value['method'],
                            ->(val) { val.instance_of? String }) and
      APIHelper.valid_type?(value['processed_at'],
                            ->(val) { val.instance_of? String }) and
      APIHelper.valid_type?(value['processor'],
                            ->(val) { val.instance_of? String }) and
      APIHelper.valid_type?(value['type'],
                            ->(val) { Type12Enum.validate(val) })
  )
end

Instance Method Details

#inspectObject

Provides a debugging-friendly string with detailed object information.



179
180
181
182
183
184
185
# File 'lib/new_store_api/models/injected_order_payment.rb', line 179

def inspect
  class_name = self.class.name.split('::').last
  "<#{class_name} amount: #{@amount.inspect}, correlation_ref: #{@correlation_ref.inspect},"\
  " metadata: #{@metadata.inspect}, method: #{@method.inspect}, processed_at:"\
  " #{@processed_at.inspect}, processor: #{@processor.inspect}, type: #{@type.inspect},"\
  " wallet: #{@wallet.inspect}>"
end

#to_custom_processed_atObject



128
129
130
# File 'lib/new_store_api/models/injected_order_payment.rb', line 128

def to_custom_processed_at
  DateTimeHelper.to_rfc3339(processed_at)
end

#to_sObject

Provides a human-readable string representation of the object.



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

def to_s
  class_name = self.class.name.split('::').last
  "<#{class_name} amount: #{@amount}, correlation_ref: #{@correlation_ref}, metadata:"\
  " #{@metadata}, method: #{@method}, processed_at: #{@processed_at}, processor:"\
  " #{@processor}, type: #{@type}, wallet: #{@wallet}>"
end