Class: Chord::Order

Inherits:
Base
  • Object
show all
Defined in:
lib/chord.rb

Instance Attribute Summary

Attributes inherited from Base

#attributes, #id

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

all, #base_path, #base_url, base_url, #delete, #expand!, find, #http_options, http_options, #initialize, #method_missing, #update, where

Constructor Details

This class inherits a constructor from Chord::Base

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Chord::Base

Class Method Details

.base_pathObject



188
189
190
# File 'lib/chord.rb', line 188

def self.base_path
  'orders'
end

.id_attributeObject



192
193
194
# File 'lib/chord.rb', line 192

def self.id_attribute
  'number'
end

Instance Method Details

#complete?Boolean

Returns:

  • (Boolean)


201
202
203
# File 'lib/chord.rb', line 201

def complete?
  state == 'complete'
end

#create_adjustment(order_id, label, discount) ⇒ Object



213
214
215
216
217
218
219
220
221
# File 'lib/chord.rb', line 213

def create_adjustment(order_id, label, discount)
  attributes = {
    label: label,
    discount_by: discount
  }
  self.class.post(base_url + "hub/orders/#{order_id}/adjustments",
    http_options.merge(body: attributes.to_json)
  ).parsed_response
end

#line_itemsObject



196
197
198
199
# File 'lib/chord.rb', line 196

def line_items
  expand! if @attributes['line_items'].nil?
  @attributes['line_items'].map{ |i| LineItem.new(i['id'], i) }
end

#paymentsObject



209
210
211
# File 'lib/chord.rb', line 209

def payments
  self.class.get(base_url + "orders/#{id}/payments", http_options).parsed_response['payments'].map{ |p| Chord::Payment.new(p['id'], p) }
end

#subscription_installment?Boolean

Returns:

  • (Boolean)


223
224
225
# File 'lib/chord.rb', line 223

def subscription_installment?
  channel == 'subscriptions'
end

#subscription_start?Boolean

Returns:

  • (Boolean)


227
228
229
230
# File 'lib/chord.rb', line 227

def subscription_start?
  expand! unless attributes.include?('subscription_in_cart')
  subscription_in_cart
end

#userObject



205
206
207
# File 'lib/chord.rb', line 205

def user
  @user ||= Chord::User.find(attributes['user_id'])
end