Class: Zinc::Order

Inherits:
Resource show all
Defined in:
lib/zinc/order.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Model

#to_hash

Constructor Details

#initialize(hash) ⇒ Order

Returns a new instance of Order.



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

def initialize(hash)
  @request_id         = hash['request_id'] if hash['request_id']
  @_type              = hash['_type'] if hash['_type']
  @code               = hash['code'] if hash['code']
  @message            = hash['message'] if hash['message']
  @status_updates     = hash['status_updates'] if hash['status_updates']
  @error              = hash['error'] if hash['error']
  @price_components   = PriceComponents.new(hash['price_components']) if hash['price_components']
  @merchant_order_ids = hash['merchant_order_ids'].map { |hash| MerchantOrderId.new(hash) } if hash['merchant_order_ids']
  @tracking           = hash['tracking'].map { |hash| Tracking.new(hash) } if hash['tracking']
  @request            = hash['request'] if hash['request']
  @delivery_dates     = hash['delivery_dates'] if hash['delivery_dates']
  @account_status     = AccountStatus.new(hash['account_status']) if hash['account_status']
end

Instance Attribute Details

#_typeObject

Returns the value of attribute _type.



3
4
5
# File 'lib/zinc/order.rb', line 3

def _type
  @_type
end

#account_statusObject

Returns the value of attribute account_status.



3
4
5
# File 'lib/zinc/order.rb', line 3

def 
  @account_status
end

#codeObject

Returns the value of attribute code.



3
4
5
# File 'lib/zinc/order.rb', line 3

def code
  @code
end

#delivery_datesObject

Returns the value of attribute delivery_dates.



3
4
5
# File 'lib/zinc/order.rb', line 3

def delivery_dates
  @delivery_dates
end

#errorObject

Returns the value of attribute error.



3
4
5
# File 'lib/zinc/order.rb', line 3

def error
  @error
end

#merchant_order_idsObject

Returns the value of attribute merchant_order_ids.



3
4
5
# File 'lib/zinc/order.rb', line 3

def merchant_order_ids
  @merchant_order_ids
end

#messageObject

Returns the value of attribute message.



3
4
5
# File 'lib/zinc/order.rb', line 3

def message
  @message
end

#price_componentsObject

Returns the value of attribute price_components.



3
4
5
# File 'lib/zinc/order.rb', line 3

def price_components
  @price_components
end

#requestObject

Returns the value of attribute request.



3
4
5
# File 'lib/zinc/order.rb', line 3

def request
  @request
end

#request_idObject

Returns the value of attribute request_id.



3
4
5
# File 'lib/zinc/order.rb', line 3

def request_id
  @request_id
end

#status_updatesObject

Returns the value of attribute status_updates.



3
4
5
# File 'lib/zinc/order.rb', line 3

def status_updates
  @status_updates
end

#trackingObject

Returns the value of attribute tracking.



3
4
5
# File 'lib/zinc/order.rb', line 3

def tracking
  @tracking
end

Class Method Details

.abort(request_id) ⇒ Object



68
69
70
71
# File 'lib/zinc/order.rb', line 68

def abort(request_id)
  response = post(path: "orders/#{request_id}/abort")
  Order.new(response)
end

.all(offset: 0, limit: 20) ⇒ Object



32
33
34
35
# File 'lib/zinc/order.rb', line 32

def all(offset: 0, limit: 20)
  response = get(path: 'orders', params: { offset: offset, limit: limit })
  response['orders'].map { |hash| Order.new(hash) }
end

.cancel(request_id) ⇒ Object



73
74
75
76
# File 'lib/zinc/order.rb', line 73

def cancel(request_id)
  response = post(path: "orders/#{request_id}/cancel")
  Order.new(response)
end

.create(retailer:, retailer_credentials:, products:, payment_method:, billing_address:, shipping_address:, shipping:, options: {}) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/zinc/order.rb', line 42

def create(retailer:, retailer_credentials:, products:, payment_method:, billing_address:, shipping_address:, shipping:, options: {})
  params = {
    retailer: retailer,
    retailer_credentials: retailer_credentials.to_hash,
    products: products.map(&:to_hash),
    payment_method: payment_method.to_hash,
    billing_address: billing_address.to_hash,
    shipping_address: shipping_address.to_hash,
    shipping: shipping.to_hash
  }

  # Valid options:
  #  - is_gift
  #  - gift_message
  #  - max_price
  #  - webhooks
  #  - client_notes
  #  - promo_codes
  #  - po_number
  #  - bundled
  params.merge!(options) unless params.empty?

  response = post(path: 'orders', params: params)
  Order.new(response)
end

.retrieve(request_id) ⇒ Object



37
38
39
40
# File 'lib/zinc/order.rb', line 37

def retrieve(request_id)
  response = get(path: "orders/#{request_id}")
  Order.new(response)
end