Class: Balanced::Order

Inherits:
Object
  • Object
show all
Includes:
HypermediaRegistry, Resource
Defined in:
lib/balanced/resources/order.rb

Instance Attribute Summary

Attributes included from Resource

#attributes, #href, #hyperlinks, #id, #links

Instance Method Summary collapse

Methods included from HypermediaRegistry

included

Methods included from Resource

#copy_from, #does_resource_respond_to?, #fetch, #hydrate, included, #initialize, #method_missing, #reload, #respond_to?, #respond_to_missing?, #sanitize, #save, #unstore

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Balanced::Resource

Instance Method Details

#cancelObject Also known as: refund



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

def cancel
  reload

  # shouldn't fail unless there's a network outage
  # let's just hope there's not (for the sake of time)
  self.debits.map { |d|
    begin
      d.refund rescue d.refunds.to_a
    end }.flatten
end

#credit_to(options = {}) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
# File 'lib/balanced/resources/order.rb', line 41

def credit_to(options={})
  Balanced::Utils.assert_required_keys(options, :required => [:destination, :amount])

  options[:order] = self.href
  destination = options[:destination]
  
  # should have a way here to disburse more funds to another account, but not required
  credit = destination.credit(options)
    
  credit
end

#debit_from(options = {}) ⇒ Object



30
31
32
33
34
35
36
37
38
39
# File 'lib/balanced/resources/order.rb', line 30

def debit_from(options={})
  Balanced::Utils.assert_required_keys(options, :required => [:source, :amount])

  options[:order] = self.href
  source = options[:source]
  
  debit = source.debit(options)
  
  debit
end