Class: NewStoreApi::OrderRequest

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

Overview

The minimum-viable order placement request. Required fields only. This first slice supports in-store cash-and-carry orders from self-checkout machines and Associate App.

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(catalog = nil, channel = nil, fulfillments = nil, line_items = nil, payment = nil, pricing = nil, checkout_id = SKIP, customer = SKIP, extended_attributes = SKIP, external_id = SKIP, gift_wrappings = SKIP) ⇒ OrderRequest

Returns a new instance of OrderRequest.



104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# File 'lib/new_store_api/models/order_request.rb', line 104

def initialize(catalog = nil, channel = nil, fulfillments = nil,
               line_items = nil, payment = nil, pricing = nil,
               checkout_id = SKIP, customer = SKIP,
               extended_attributes = SKIP, external_id = SKIP,
               gift_wrappings = SKIP)
  @catalog = catalog
  @channel = channel
  @checkout_id = checkout_id unless checkout_id == SKIP
  @customer = customer unless customer == SKIP
  @extended_attributes = extended_attributes unless extended_attributes == SKIP
  @external_id = external_id unless external_id == SKIP
  @fulfillments = fulfillments
  @gift_wrappings = gift_wrappings unless gift_wrappings == SKIP
  @line_items = line_items
  @payment = payment
  @pricing = pricing
end

Instance Attribute Details

#catalogCatalog

The catalogue and locale used to resolve the order's items.

Returns:



16
17
18
# File 'lib/new_store_api/models/order_request.rb', line 16

def catalog
  @catalog
end

#channelChannel1

Describes the origin of the order.

Returns:



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

def channel
  @channel
end

#checkout_idString

Associated checkout ID for reconciliation.

Returns:

  • (String)


24
25
26
# File 'lib/new_store_api/models/order_request.rb', line 24

def checkout_id
  @checkout_id
end

#customerCustomer

The customer placing the order. Omitted for anonymous orders.

Returns:



28
29
30
# File 'lib/new_store_api/models/order_request.rb', line 28

def customer
  @customer
end

#extended_attributesArray[ExtendedAttribute]

Tenant-defined name/value pairs for the order, propagated through the platform.

Returns:



33
34
35
# File 'lib/new_store_api/models/order_request.rb', line 33

def extended_attributes
  @extended_attributes
end

#external_idString

Caller-supplied external identifier for correlation and external lookup. Must be unique per tenant when supplied. The order number is generated by the system.

Returns:

  • (String)


39
40
41
# File 'lib/new_store_api/models/order_request.rb', line 39

def external_id
  @external_id
end

#fulfillmentsArray[Fulfillment1]

Caller-supplied external identifier for correlation and external lookup. Must be unique per tenant when supplied. The order number is generated by the system.

Returns:



45
46
47
# File 'lib/new_store_api/models/order_request.rb', line 45

def fulfillments
  @fulfillments
end

#gift_wrappingsArray[GiftWrapping]

Gift wrapping applied to the order's line items. At most one, and it must cover every line item — partial gift wrapping (wrapping only some items) is not yet supported. Omitted when nothing is gift-wrapped.

Returns:



51
52
53
# File 'lib/new_store_api/models/order_request.rb', line 51

def gift_wrappings
  @gift_wrappings
end

#line_itemsArray[LineItem2]

Gift wrapping applied to the order's line items. At most one, and it must cover every line item — partial gift wrapping (wrapping only some items) is not yet supported. Omitted when nothing is gift-wrapped.

Returns:



57
58
59
# File 'lib/new_store_api/models/order_request.rb', line 57

def line_items
  @line_items
end

#paymentPayment

The payments attached to an order.

Returns:



61
62
63
# File 'lib/new_store_api/models/order_request.rb', line 61

def payment
  @payment
end

#pricingPricing

Currency and tax treatment for all prices in the payload.

Returns:



65
66
67
# File 'lib/new_store_api/models/order_request.rb', line 65

def pricing
  @pricing
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
# File 'lib/new_store_api/models/order_request.rb', line 123

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  catalog = Catalog.from_hash(hash['catalog']) if hash['catalog']
  channel = Channel1.from_hash(hash['channel']) if hash['channel']
  # Parameter is an array, so we need to iterate through it
  fulfillments = nil
  unless hash['fulfillments'].nil?
    fulfillments = []
    hash['fulfillments'].each do |structure|
      fulfillments << (Fulfillment1.from_hash(structure) if structure)
    end
  end

  fulfillments = nil unless hash.key?('fulfillments')
  # Parameter is an array, so we need to iterate through it
  line_items = nil
  unless hash['line_items'].nil?
    line_items = []
    hash['line_items'].each do |structure|
      line_items << (LineItem2.from_hash(structure) if structure)
    end
  end

  line_items = nil unless hash.key?('line_items')
  payment = Payment.from_hash(hash['payment']) if hash['payment']
  pricing = Pricing.from_hash(hash['pricing']) if hash['pricing']
  checkout_id = hash.key?('checkout_id') ? hash['checkout_id'] : SKIP
  customer = Customer.from_hash(hash['customer']) if hash['customer']
  # Parameter is an array, so we need to iterate through it
  extended_attributes = nil
  unless hash['extended_attributes'].nil?
    extended_attributes = []
    hash['extended_attributes'].each do |structure|
      extended_attributes << (ExtendedAttribute.from_hash(structure) if structure)
    end
  end

  extended_attributes = SKIP unless hash.key?('extended_attributes')
  external_id = hash.key?('external_id') ? hash['external_id'] : SKIP
  # Parameter is an array, so we need to iterate through it
  gift_wrappings = nil
  unless hash['gift_wrappings'].nil?
    gift_wrappings = []
    hash['gift_wrappings'].each do |structure|
      gift_wrappings << (GiftWrapping.from_hash(structure) if structure)
    end
  end

  gift_wrappings = SKIP unless hash.key?('gift_wrappings')

  # Create object from extracted values.
  OrderRequest.new(catalog,
                   channel,
                   fulfillments,
                   line_items,
                   payment,
                   pricing,
                   checkout_id,
                   customer,
                   extended_attributes,
                   external_id,
                   gift_wrappings)
end

.namesObject

A mapping from model property names to API property names.



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/new_store_api/models/order_request.rb', line 68

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['catalog'] = 'catalog'
  @_hash['channel'] = 'channel'
  @_hash['checkout_id'] = 'checkout_id'
  @_hash['customer'] = 'customer'
  @_hash['extended_attributes'] = 'extended_attributes'
  @_hash['external_id'] = 'external_id'
  @_hash['fulfillments'] = 'fulfillments'
  @_hash['gift_wrappings'] = 'gift_wrappings'
  @_hash['line_items'] = 'line_items'
  @_hash['payment'] = 'payment'
  @_hash['pricing'] = 'pricing'
  @_hash
end

.nullablesObject

An array for nullable fields



96
97
98
99
100
101
102
# File 'lib/new_store_api/models/order_request.rb', line 96

def self.nullables
  %w[
    checkout_id
    customer
    external_id
  ]
end

.optionalsObject

An array for optional fields



85
86
87
88
89
90
91
92
93
# File 'lib/new_store_api/models/order_request.rb', line 85

def self.optionals
  %w[
    checkout_id
    customer
    extended_attributes
    external_id
    gift_wrappings
  ]
end

Instance Method Details

#inspectObject

Provides a debugging-friendly string with detailed object information.



199
200
201
202
203
204
205
206
# File 'lib/new_store_api/models/order_request.rb', line 199

def inspect
  class_name = self.class.name.split('::').last
  "<#{class_name} catalog: #{@catalog.inspect}, channel: #{@channel.inspect}, checkout_id:"\
  " #{@checkout_id.inspect}, customer: #{@customer.inspect}, extended_attributes:"\
  " #{@extended_attributes.inspect}, external_id: #{@external_id.inspect}, fulfillments:"\
  " #{@fulfillments.inspect}, gift_wrappings: #{@gift_wrappings.inspect}, line_items:"\
  " #{@line_items.inspect}, payment: #{@payment.inspect}, pricing: #{@pricing.inspect}>"
end

#to_sObject

Provides a human-readable string representation of the object.



190
191
192
193
194
195
196
# File 'lib/new_store_api/models/order_request.rb', line 190

def to_s
  class_name = self.class.name.split('::').last
  "<#{class_name} catalog: #{@catalog}, channel: #{@channel}, checkout_id: #{@checkout_id},"\
  " customer: #{@customer}, extended_attributes: #{@extended_attributes}, external_id:"\
  " #{@external_id}, fulfillments: #{@fulfillments}, gift_wrappings: #{@gift_wrappings},"\
  " line_items: #{@line_items}, payment: #{@payment}, pricing: #{@pricing}>"
end