Class: MusicTodayApiWrapper::Resources::Checkout::Order

Inherits:
Object
  • Object
show all
Defined in:
lib/resources/checkout/order.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(customer, payment, destinations = [], items = [], promotions = []) ⇒ Order

Returns a new instance of Order.



14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/resources/checkout/order.rb', line 14

def initialize(customer, payment, destinations = [], items = [],
  promotions = [])
  config = MusicTodayApiWrapper::Configuration.new

  @catalog = config.catalog.to_i
  @channel = config.channel
  @prefix = config.order_prefix
  @customer = customer
  @payment = payment
  @destinations = destinations
  @items = items
  @promotions = promotions
end

Instance Attribute Details

#customerObject

Returns the value of attribute customer.



12
13
14
# File 'lib/resources/checkout/order.rb', line 12

def customer
  @customer
end

#destinationsObject

Returns the value of attribute destinations.



12
13
14
# File 'lib/resources/checkout/order.rb', line 12

def destinations
  @destinations
end

#itemsObject

Returns the value of attribute items.



12
13
14
# File 'lib/resources/checkout/order.rb', line 12

def items
  @items
end

Instance Method Details

#as_hashObject

rubocop:disable MethodLength



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/resources/checkout/order.rb', line 29

def as_hash
  dynamic_id = @prefix + Time.now.to_i.to_s

  { storeId: @catalog,
    channel: @channel,
    orderDate: DateTime.now.to_s,
    clientOrderId: dynamic_id,
    clientCustomerId: dynamic_id,
    sendConfEmail: true,
    sendDigitalConfEmail: true,
    applyFraudCheck: true,
    validateOnly: false,
    taxPrepaid: false,
    billing: { customer: @customer.as_hash,
               payments: [@payment.as_hash] },
    currency: 'USD',
    destinations: @destinations.map(&:as_hash),
    lineItems: @items.map(&:as_hash),
    promotions: @promotions.map(&:as_hash) }.compact
end