Class: Balanced::Order
- Inherits:
-
Object
- Object
- Balanced::Order
- 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
- #cancel ⇒ Object (also: #refund)
- #credit_to(options = {}) ⇒ Object
- #debit_from(options = {}) ⇒ Object
Methods included from HypermediaRegistry
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
#cancel ⇒ Object 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(={}) Balanced::Utils.assert_required_keys(, :required => [:destination, :amount]) [:order] = self.href destination = [:destination] # should have a way here to disburse more funds to another account, but not required credit = destination.credit() 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(={}) Balanced::Utils.assert_required_keys(, :required => [:source, :amount]) [:order] = self.href source = [:source] debit = source.debit() debit end |