Class: Levelup::Requests::CreateOrder

Inherits:
Base show all
Includes:
Templates::MerchantAndUserAuthenticated
Defined in:
lib/levelup/requests/create_order.rb

Overview

Represents a request to create an order for the specified user at the specified merchant.

Constant Summary

Constants inherited from Base

Base::ALLOWED_REQUEST_METHODS

Instance Attribute Summary collapse

Attributes included from Templates::MerchantAndUserAuthenticated

#merchant_access_token, #user_access_token

Instance Method Summary collapse

Methods included from Templates::MerchantAndUserAuthenticated

#auth_type

Methods inherited from Base

#auth_type, #headers, instance_variables_excluded_from_hash, #send_to_api

Methods inherited from Templates::DataParcel

excluded?, #initialize, instance_variables_excluded_from_hash

Constructor Details

This class inherits a constructor from Levelup::Templates::DataParcel

Instance Attribute Details

#identifier_from_merchantObject

A merchant-supplied unique ID for this order. Optional.



10
11
12
# File 'lib/levelup/requests/create_order.rb', line 10

def identifier_from_merchant
  @identifier_from_merchant
end

#itemsObject

An array of Item objects (or hashes representing them) representing all items purchased by this order.



8
9
10
# File 'lib/levelup/requests/create_order.rb', line 8

def items
  @items
end

#location_idObject

The LevelUp ID for the location from which this order was requested.



12
13
14
# File 'lib/levelup/requests/create_order.rb', line 12

def location_id
  @location_id
end

#spend_amountObject

The total amount (in cents) spent on this order.



14
15
16
# File 'lib/levelup/requests/create_order.rb', line 14

def spend_amount
  @spend_amount
end

Instance Method Details

#bodyObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/levelup/requests/create_order.rb', line 16

def body
  items = (@items || []).map do |item|
    if item.empty?
      next
    end

    { item: item }
  end

  order_hash = to_hash
  order_hash[:items] = items

  { order: order_hash }
end

#response_from_hash(hash) ⇒ Object



31
32
33
# File 'lib/levelup/requests/create_order.rb', line 31

def response_from_hash(hash)
  Responses::Success.new(hash['order'])
end