Class: NewStoreApi::InjectedOrderRequest

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

Overview

An order placed in an external system, identified by its external_id in NewStore. An order contains a list of shipments and the products in each shipment.

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(channel_name = nil, channel_type = nil, currency = nil, external_id = nil, shipments = nil, shop = nil, shop_locale = nil, associate_id = SKIP, billing_address = SKIP, customer_email = SKIP, customer_language = SKIP, customer_name = SKIP, extended_attributes = SKIP, external_customer_id = SKIP, ip_address = SKIP, is_fulfilled = false, is_historical = false, is_offline = false, is_preconfirmed = false, notification_blacklist = SKIP, payments = SKIP, placed_at = SKIP, price_method = SKIP, shipping_address = SKIP, store_id = SKIP) ⇒ InjectedOrderRequest

Returns a new instance of InjectedOrderRequest.



192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
# File 'lib/new_store_api/models/injected_order_request.rb', line 192

def initialize(channel_name = nil, channel_type = nil, currency = nil,
               external_id = nil, shipments = nil, shop = nil,
               shop_locale = nil, associate_id = SKIP,
               billing_address = SKIP, customer_email = SKIP,
               customer_language = SKIP, customer_name = SKIP,
               extended_attributes = SKIP, external_customer_id = SKIP,
               ip_address = SKIP, is_fulfilled = false,
               is_historical = false, is_offline = false,
               is_preconfirmed = false, notification_blacklist = SKIP,
               payments = SKIP, placed_at = SKIP, price_method = SKIP,
               shipping_address = SKIP, store_id = SKIP)
  @associate_id = associate_id unless associate_id == SKIP
  @billing_address = billing_address unless billing_address == SKIP
  @channel_name = channel_name
  @channel_type = channel_type
  @currency = currency
  @customer_email = customer_email unless customer_email == SKIP
  @customer_language = customer_language unless customer_language == SKIP
  @customer_name = customer_name unless customer_name == SKIP
  @extended_attributes = extended_attributes unless extended_attributes == SKIP
  @external_customer_id = external_customer_id unless external_customer_id == SKIP
  @external_id = external_id
  @ip_address = ip_address unless ip_address == SKIP
  @is_fulfilled = is_fulfilled unless is_fulfilled == SKIP
  @is_historical = is_historical unless is_historical == SKIP
  @is_offline = is_offline unless is_offline == SKIP
  @is_preconfirmed = is_preconfirmed unless is_preconfirmed == SKIP
  @notification_blacklist = notification_blacklist unless notification_blacklist == SKIP
  @payments = payments unless payments == SKIP
  @placed_at = placed_at unless placed_at == SKIP
  @price_method = price_method unless price_method == SKIP
  @shipments = shipments
  @shipping_address = shipping_address unless shipping_address == SKIP
  @shop = shop
  @shop_locale = shop_locale
  @store_id = store_id unless store_id == SKIP
end

Instance Attribute Details

#associate_idString

ID of the store associate who processed this order.

Returns:

  • (String)


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

def associate_id
  @associate_id
end

#billing_addressInjectedOrderAddress

ID of the store associate who processed this order.



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

def billing_address
  @billing_address
end

#channel_nameString

A string used to distinguish between various sources of orders.

Returns:

  • (String)


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

def channel_name
  @channel_name
end

#channel_typeChannelType1Enum

A string used to distinguish between various sources of orders.

Returns:



29
30
31
# File 'lib/new_store_api/models/injected_order_request.rb', line 29

def channel_type
  @channel_type
end

#currencyCurrency2Enum

The currency for all the prices contained within this payload.

Returns:



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

def currency
  @currency
end

#customer_emailString

The currency for all the prices contained within this payload.

Returns:

  • (String)


37
38
39
# File 'lib/new_store_api/models/injected_order_request.rb', line 37

def customer_email
  @customer_email
end

#customer_languageString

Language code according to ISO 639-1 to be used in the communication with the consumer (e.g. 'de', 'en' or 'fr')

Returns:

  • (String)


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

def customer_language
  @customer_language
end

#customer_nameString

Language code according to ISO 639-1 to be used in the communication with the consumer (e.g. 'de', 'en' or 'fr')

Returns:

  • (String)


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

def customer_name
  @customer_name
end

#extended_attributesArray[InjectedOrderExtendedAttribute]

Language code according to ISO 639-1 to be used in the communication with the consumer (e.g. 'de', 'en' or 'fr')

Returns:



52
53
54
# File 'lib/new_store_api/models/injected_order_request.rb', line 52

def extended_attributes
  @extended_attributes
end

#external_customer_idString

Language code according to ISO 639-1 to be used in the communication with the consumer (e.g. 'de', 'en' or 'fr')

Returns:

  • (String)


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

def external_customer_id
  @external_customer_id
end

#external_idString

Language code according to ISO 639-1 to be used in the communication with the consumer (e.g. 'de', 'en' or 'fr')

Returns:

  • (String)


62
63
64
# File 'lib/new_store_api/models/injected_order_request.rb', line 62

def external_id
  @external_id
end

#ip_addressObject

Language code according to ISO 639-1 to be used in the communication with the consumer (e.g. 'de', 'en' or 'fr')

Returns:

  • (Object)


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

def ip_address
  @ip_address
end

#is_fulfilledTrueClass | FalseClass

Set to true if the order was already fulfilled. It is either an in-store purchase, or the order was fulfilled by an external system.

Returns:

  • (TrueClass | FalseClass)


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

def is_fulfilled
  @is_fulfilled
end

#is_historicalTrueClass | FalseClass

Set to true if the order is historical was created and fulfilled by an external system.

Returns:

  • (TrueClass | FalseClass)


77
78
79
# File 'lib/new_store_api/models/injected_order_request.rb', line 77

def is_historical
  @is_historical
end

#is_offlineTrueClass | FalseClass

Set to true if the order was handled offline. It is an in-store purchase with internet connection failure.

Returns:

  • (TrueClass | FalseClass)


82
83
84
# File 'lib/new_store_api/models/injected_order_request.rb', line 82

def is_offline
  @is_offline
end

#is_preconfirmedTrueClass | FalseClass

Set to true, if the customer was already notified about order being placed. This is always true for in-store orders.

Returns:

  • (TrueClass | FalseClass)


87
88
89
# File 'lib/new_store_api/models/injected_order_request.rb', line 87

def is_preconfirmed
  @is_preconfirmed
end

#notification_blacklistArray[String]

Excludes the specified notifications from being sent to the customer.

Returns:

  • (Array[String])


91
92
93
# File 'lib/new_store_api/models/injected_order_request.rb', line 91

def notification_blacklist
  @notification_blacklist
end

#paymentsArray[InjectedOrderPayment]

Excludes the specified notifications from being sent to the customer.

Returns:



95
96
97
# File 'lib/new_store_api/models/injected_order_request.rb', line 95

def payments
  @payments
end

#placed_atDateTime

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

Returns:

  • (DateTime)


100
101
102
# File 'lib/new_store_api/models/injected_order_request.rb', line 100

def placed_at
  @placed_at
end

#price_methodF11nTaxMethodEnum

Specifies if the prices for the shipment items and shipping options include tax or not. This is used in calculating the total order price to determine if the tax price should be included in the calculation or not.

Returns:



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

def price_method
  @price_method
end

#shipmentsArray[Object]

Specifies if the prices for the shipment items and shipping options include tax or not. This is used in calculating the total order price to determine if the tax price should be included in the calculation or not.

Returns:

  • (Array[Object])


112
113
114
# File 'lib/new_store_api/models/injected_order_request.rb', line 112

def shipments
  @shipments
end

#shipping_addressInjectedOrderAddress

Specifies if the prices for the shipment items and shipping options include tax or not. This is used in calculating the total order price to determine if the tax price should be included in the calculation or not.



118
119
120
# File 'lib/new_store_api/models/injected_order_request.rb', line 118

def shipping_address
  @shipping_address
end

#shopString

The shop containing the items of the order.

Returns:

  • (String)


122
123
124
# File 'lib/new_store_api/models/injected_order_request.rb', line 122

def shop
  @shop
end

#shop_localeString

The locale of the customer used for the shop, in RFC 5646.

Returns:

  • (String)


126
127
128
# File 'lib/new_store_api/models/injected_order_request.rb', line 126

def shop_locale
  @shop_locale
end

#store_idString

ID of the store where this order was placed.

Returns:

  • (String)


130
131
132
# File 'lib/new_store_api/models/injected_order_request.rb', line 130

def store_id
  @store_id
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
# File 'lib/new_store_api/models/injected_order_request.rb', line 231

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  channel_name = hash.key?('channel_name') ? hash['channel_name'] : nil
  channel_type = hash.key?('channel_type') ? hash['channel_type'] : nil
  currency = hash.key?('currency') ? hash['currency'] : nil
  external_id = hash.key?('external_id') ? hash['external_id'] : nil
  shipments = hash.key?('shipments') ? APIHelper.deserialize_union_type(
    UnionTypeLookUp.get(:InjectedOrderShipment2), hash['shipments']
  ) : nil
  shop = hash.key?('shop') ? hash['shop'] : nil
  shop_locale = hash.key?('shop_locale') ? hash['shop_locale'] : nil
  associate_id = hash.key?('associate_id') ? hash['associate_id'] : SKIP
  billing_address = InjectedOrderAddress.from_hash(hash['billing_address']) if
    hash['billing_address']
  customer_email =
    hash.key?('customer_email') ? hash['customer_email'] : SKIP
  customer_language =
    hash.key?('customer_language') ? hash['customer_language'] : SKIP
  customer_name = hash.key?('customer_name') ? hash['customer_name'] : SKIP
  # 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 << (InjectedOrderExtendedAttribute.from_hash(structure) if structure)
    end
  end

  extended_attributes = SKIP unless hash.key?('extended_attributes')
  external_customer_id =
    hash.key?('external_customer_id') ? hash['external_customer_id'] : SKIP
  ip_address = hash.key?('ip_address') ? APIHelper.deserialize_union_type(
    UnionTypeLookUp.get(:InjectedOrderRequestIpAddress), hash['ip_address']
  ) : SKIP
  is_fulfilled = hash['is_fulfilled'] ||= false
  is_historical = hash['is_historical'] ||= false
  is_offline = hash['is_offline'] ||= false
  is_preconfirmed = hash['is_preconfirmed'] ||= false
  notification_blacklist =
    hash.key?('notification_blacklist') ? hash['notification_blacklist'] : SKIP
  # Parameter is an array, so we need to iterate through it
  payments = nil
  unless hash['payments'].nil?
    payments = []
    hash['payments'].each do |structure|
      payments << (InjectedOrderPayment.from_hash(structure) if structure)
    end
  end

  payments = SKIP unless hash.key?('payments')
  placed_at = if hash.key?('placed_at')
                (DateTimeHelper.from_rfc3339(hash['placed_at']) if hash['placed_at'])
              else
                SKIP
              end
  price_method = hash.key?('price_method') ? hash['price_method'] : SKIP
  shipping_address = InjectedOrderAddress.from_hash(hash['shipping_address']) if
    hash['shipping_address']
  store_id = hash.key?('store_id') ? hash['store_id'] : SKIP

  # Create object from extracted values.
  InjectedOrderRequest.new(channel_name,
                           channel_type,
                           currency,
                           external_id,
                           shipments,
                           shop,
                           shop_locale,
                           associate_id,
                           billing_address,
                           customer_email,
                           customer_language,
                           customer_name,
                           extended_attributes,
                           external_customer_id,
                           ip_address,
                           is_fulfilled,
                           is_historical,
                           is_offline,
                           is_preconfirmed,
                           notification_blacklist,
                           payments,
                           placed_at,
                           price_method,
                           shipping_address,
                           store_id)
end

.namesObject

A mapping from model property names to API property names.



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
# File 'lib/new_store_api/models/injected_order_request.rb', line 133

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['associate_id'] = 'associate_id'
  @_hash['billing_address'] = 'billing_address'
  @_hash['channel_name'] = 'channel_name'
  @_hash['channel_type'] = 'channel_type'
  @_hash['currency'] = 'currency'
  @_hash['customer_email'] = 'customer_email'
  @_hash['customer_language'] = 'customer_language'
  @_hash['customer_name'] = 'customer_name'
  @_hash['extended_attributes'] = 'extended_attributes'
  @_hash['external_customer_id'] = 'external_customer_id'
  @_hash['external_id'] = 'external_id'
  @_hash['ip_address'] = 'ip_address'
  @_hash['is_fulfilled'] = 'is_fulfilled'
  @_hash['is_historical'] = 'is_historical'
  @_hash['is_offline'] = 'is_offline'
  @_hash['is_preconfirmed'] = 'is_preconfirmed'
  @_hash['notification_blacklist'] = 'notification_blacklist'
  @_hash['payments'] = 'payments'
  @_hash['placed_at'] = 'placed_at'
  @_hash['price_method'] = 'price_method'
  @_hash['shipments'] = 'shipments'
  @_hash['shipping_address'] = 'shipping_address'
  @_hash['shop'] = 'shop'
  @_hash['shop_locale'] = 'shop_locale'
  @_hash['store_id'] = 'store_id'
  @_hash
end

.nullablesObject

An array for nullable fields



188
189
190
# File 'lib/new_store_api/models/injected_order_request.rb', line 188

def self.nullables
  []
end

.optionalsObject

An array for optional fields



164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
# File 'lib/new_store_api/models/injected_order_request.rb', line 164

def self.optionals
  %w[
    associate_id
    billing_address
    customer_email
    customer_language
    customer_name
    extended_attributes
    external_customer_id
    ip_address
    is_fulfilled
    is_historical
    is_offline
    is_preconfirmed
    notification_blacklist
    payments
    placed_at
    price_method
    shipping_address
    store_id
  ]
end

.validate(value) ⇒ Object

Validates an instance of the object from a given value.

Parameters:



327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
# File 'lib/new_store_api/models/injected_order_request.rb', line 327

def self.validate(value)
  if value.instance_of? self
    return (
      APIHelper.valid_type?(value.channel_name,
                            ->(val) { val.instance_of? String }) and
        APIHelper.valid_type?(value.channel_type,
                              ->(val) { ChannelType1Enum.validate(val) }) and
        APIHelper.valid_type?(value.currency,
                              ->(val) { Currency2Enum.validate(val) }) and
        APIHelper.valid_type?(value.external_id,
                              ->(val) { val.instance_of? String }) and
        UnionTypeLookUp.get(:InjectedOrderShipment2)
                       .validate(value.shipments) and
        APIHelper.valid_type?(value.shop,
                              ->(val) { val.instance_of? String }) and
        APIHelper.valid_type?(value.shop_locale,
                              ->(val) { val.instance_of? String })
    )
  end

  return false unless value.instance_of? Hash

  (
    APIHelper.valid_type?(value['channel_name'],
                          ->(val) { val.instance_of? String }) and
      APIHelper.valid_type?(value['channel_type'],
                            ->(val) { ChannelType1Enum.validate(val) }) and
      APIHelper.valid_type?(value['currency'],
                            ->(val) { Currency2Enum.validate(val) }) and
      APIHelper.valid_type?(value['external_id'],
                            ->(val) { val.instance_of? String }) and
      UnionTypeLookUp.get(:InjectedOrderShipment2)
                     .validate(value['shipments']) and
      APIHelper.valid_type?(value['shop'],
                            ->(val) { val.instance_of? String }) and
      APIHelper.valid_type?(value['shop_locale'],
                            ->(val) { val.instance_of? String })
  )
end

Instance Method Details

#inspectObject

Provides a debugging-friendly string with detailed object information.



384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
# File 'lib/new_store_api/models/injected_order_request.rb', line 384

def inspect
  class_name = self.class.name.split('::').last
  "<#{class_name} associate_id: #{@associate_id.inspect}, billing_address:"\
  " #{@billing_address.inspect}, channel_name: #{@channel_name.inspect}, channel_type:"\
  " #{@channel_type.inspect}, currency: #{@currency.inspect}, customer_email:"\
  " #{@customer_email.inspect}, customer_language: #{@customer_language.inspect},"\
  " customer_name: #{@customer_name.inspect}, extended_attributes:"\
  " #{@extended_attributes.inspect}, external_customer_id: #{@external_customer_id.inspect},"\
  " external_id: #{@external_id.inspect}, ip_address: #{@ip_address.inspect}, is_fulfilled:"\
  " #{@is_fulfilled.inspect}, is_historical: #{@is_historical.inspect}, is_offline:"\
  " #{@is_offline.inspect}, is_preconfirmed: #{@is_preconfirmed.inspect},"\
  " notification_blacklist: #{@notification_blacklist.inspect}, payments:"\
  " #{@payments.inspect}, placed_at: #{@placed_at.inspect}, price_method:"\
  " #{@price_method.inspect}, shipments: #{@shipments.inspect}, shipping_address:"\
  " #{@shipping_address.inspect}, shop: #{@shop.inspect}, shop_locale:"\
  " #{@shop_locale.inspect}, store_id: #{@store_id.inspect}>"
end

#to_custom_placed_atObject



321
322
323
# File 'lib/new_store_api/models/injected_order_request.rb', line 321

def to_custom_placed_at
  DateTimeHelper.to_rfc3339(placed_at)
end

#to_sObject

Provides a human-readable string representation of the object.



368
369
370
371
372
373
374
375
376
377
378
379
380
381
# File 'lib/new_store_api/models/injected_order_request.rb', line 368

def to_s
  class_name = self.class.name.split('::').last
  "<#{class_name} associate_id: #{@associate_id}, billing_address: #{@billing_address},"\
  " channel_name: #{@channel_name}, channel_type: #{@channel_type}, currency: #{@currency},"\
  " customer_email: #{@customer_email}, customer_language: #{@customer_language},"\
  " customer_name: #{@customer_name}, extended_attributes: #{@extended_attributes},"\
  " external_customer_id: #{@external_customer_id}, external_id: #{@external_id}, ip_address:"\
  " #{@ip_address}, is_fulfilled: #{@is_fulfilled}, is_historical: #{@is_historical},"\
  " is_offline: #{@is_offline}, is_preconfirmed: #{@is_preconfirmed}, notification_blacklist:"\
  " #{@notification_blacklist}, payments: #{@payments}, placed_at: #{@placed_at},"\
  " price_method: #{@price_method}, shipments: #{@shipments}, shipping_address:"\
  " #{@shipping_address}, shop: #{@shop}, shop_locale: #{@shop_locale}, store_id:"\
  " #{@store_id}>"
end