Class: NewStoreApi::Payment

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

Overview

The payments attached to an order.

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(instruments = nil) ⇒ Payment

Returns a new instance of Payment.



34
35
36
# File 'lib/new_store_api/models/payment.rb', line 34

def initialize(instruments = nil)
  @instruments = instruments
end

Instance Attribute Details

#instrumentsArray[Object]

Already-authorized or already-captured payments to attach to the order. Must be empty for zero-value orders.

Returns:

  • (Array[Object])


15
16
17
# File 'lib/new_store_api/models/payment.rb', line 15

def instruments
  @instruments
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



39
40
41
42
43
44
45
46
47
48
49
# File 'lib/new_store_api/models/payment.rb', line 39

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  instruments = hash.key?('instruments') ? APIHelper.deserialize_union_type(
    UnionTypeLookUp.get(:PaymentInstruments), hash['instruments']
  ) : nil

  # Create object from extracted values.
  Payment.new(instruments)
end

.namesObject

A mapping from model property names to API property names.



18
19
20
21
22
# File 'lib/new_store_api/models/payment.rb', line 18

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['instruments'] = 'instruments'
  @_hash
end

.nullablesObject

An array for nullable fields



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

def self.nullables
  []
end

.optionalsObject

An array for optional fields



25
26
27
# File 'lib/new_store_api/models/payment.rb', line 25

def self.optionals
  []
end

.validate(value) ⇒ Object

Validates an instance of the object from a given value.

Parameters:

  • The (Payment | Hash)

    value against the validation is performed.



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

def self.validate(value)
  if value.instance_of? self
    return UnionTypeLookUp.get(:PaymentInstruments)
                          .validate(value.instruments)
  end

  return false unless value.instance_of? Hash

  UnionTypeLookUp.get(:PaymentInstruments)
                 .validate(value['instruments'])
end

Instance Method Details

#inspectObject

Provides a debugging-friendly string with detailed object information.



72
73
74
75
# File 'lib/new_store_api/models/payment.rb', line 72

def inspect
  class_name = self.class.name.split('::').last
  "<#{class_name} instruments: #{@instruments.inspect}>"
end

#to_sObject

Provides a human-readable string representation of the object.



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

def to_s
  class_name = self.class.name.split('::').last
  "<#{class_name} instruments: #{@instruments}>"
end