Class: NewStoreApi::OrderCompletedDto

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

Overview

order.completed is sent when all order items are fulfilled (or cancelled). Note that payment processing might not be complete yet.

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(id = nil, items = nil, capture_type = SKIP) ⇒ OrderCompletedDto

Returns a new instance of OrderCompletedDto.



48
49
50
51
52
# File 'lib/new_store_api/models/order_completed_dto.rb', line 48

def initialize(id = nil, items = nil, capture_type = SKIP)
  @capture_type = capture_type unless capture_type == SKIP
  @id = id
  @items = items
end

Instance Attribute Details

#capture_typeString

Indicates the capture type of the order. If the order has been placed in the Associate App or any mPOS then the capture type is pos. If the order has been injected then the capture_type is injection.

Returns:

  • (String)


17
18
19
# File 'lib/new_store_api/models/order_completed_dto.rb', line 17

def capture_type
  @capture_type
end

#idString

Unique ID for the order.

Returns:

  • (String)


21
22
23
# File 'lib/new_store_api/models/order_completed_dto.rb', line 21

def id
  @id
end

#itemsArray[Item9]

List containing items in the order; one list index equals one item.

Returns:



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

def items
  @items
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/new_store_api/models/order_completed_dto.rb', line 55

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  id = hash.key?('id') ? hash['id'] : nil
  # Parameter is an array, so we need to iterate through it
  items = nil
  unless hash['items'].nil?
    items = []
    hash['items'].each do |structure|
      items << (Item9.from_hash(structure) if structure)
    end
  end

  items = nil unless hash.key?('items')
  capture_type = hash.key?('capture_type') ? hash['capture_type'] : SKIP

  # Create object from extracted values.
  OrderCompletedDto.new(id,
                        items,
                        capture_type)
end

.namesObject

A mapping from model property names to API property names.



28
29
30
31
32
33
34
# File 'lib/new_store_api/models/order_completed_dto.rb', line 28

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

.nullablesObject

An array for nullable fields



44
45
46
# File 'lib/new_store_api/models/order_completed_dto.rb', line 44

def self.nullables
  []
end

.optionalsObject

An array for optional fields



37
38
39
40
41
# File 'lib/new_store_api/models/order_completed_dto.rb', line 37

def self.optionals
  %w[
    capture_type
  ]
end

.validate(value) ⇒ Object

Validates an instance of the object from a given value.

Parameters:



80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/new_store_api/models/order_completed_dto.rb', line 80

def self.validate(value)
  if value.instance_of? self
    return (
      APIHelper.valid_type?(value.id,
                            ->(val) { val.instance_of? String }) and
        APIHelper.valid_type?(value.items,
                              ->(val) { Item9.validate(val) },
                              is_model_hash: true,
                              is_inner_model_hash: true)
    )
  end

  return false unless value.instance_of? Hash

  (
    APIHelper.valid_type?(value['id'],
                          ->(val) { val.instance_of? String }) and
      APIHelper.valid_type?(value['items'],
                            ->(val) { Item9.validate(val) },
                            is_model_hash: true,
                            is_inner_model_hash: true)
  )
end

Instance Method Details

#inspectObject

Provides a debugging-friendly string with detailed object information.



111
112
113
114
115
# File 'lib/new_store_api/models/order_completed_dto.rb', line 111

def inspect
  class_name = self.class.name.split('::').last
  "<#{class_name} capture_type: #{@capture_type.inspect}, id: #{@id.inspect}, items:"\
  " #{@items.inspect}>"
end

#to_sObject

Provides a human-readable string representation of the object.



105
106
107
108
# File 'lib/new_store_api/models/order_completed_dto.rb', line 105

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