Class: Balanced::BankAccount
- Inherits:
-
Object
- Object
- Balanced::BankAccount
- Includes:
- Resource
- Defined in:
- lib/balanced/resources/bank_account.rb
Overview
A BankAccount is both a source, and a destination of, funds. You may create Debits and Credits to and from, this funding source.
NOTE: The BankAccount resource does not support creating a Hold.
Instance Attribute Summary
Attributes included from Resource
Class Method Summary collapse
Instance Method Summary collapse
-
#credit(*args) ⇒ Credit
Creates a Credit of funds from your Marketplace’s escrow account to this Account.
-
#debit(*args) ⇒ Debit
Creates a Debit of funds from this BankAccount to your Marketplace’s escrow account.
- #has_account? ⇒ Boolean
-
#initialize(attributes = {}) ⇒ BankAccount
constructor
A new instance of BankAccount.
- #invalidate ⇒ Object
- #verify ⇒ Object
Methods included from Resource
#copy_from, #destroy, #find, included, #method_missing, #reload, #save, #warn_on_positional
Constructor Details
#initialize(attributes = {}) ⇒ BankAccount
Returns a new instance of BankAccount.
17 18 19 20 21 22 23 |
# File 'lib/balanced/resources/bank_account.rb', line 17 def initialize attributes = {} Balanced::Utils.stringify_keys! attributes unless attributes.has_key? 'uri' attributes['uri'] = self.class.uri end super attributes end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Balanced::Resource
Class Method Details
.uri ⇒ Object
10 11 12 13 14 15 |
# File 'lib/balanced/resources/bank_account.rb', line 10 def self.uri # Override the default nesting -- bank accounts can be top-level now # but they can also be nested under marketplaces, which is what we # want to default to unless explicitly set self.collection_path end |
Instance Method Details
#credit(*args) ⇒ Credit
Creates a Credit of funds from your Marketplace’s escrow account to this Account.
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/balanced/resources/bank_account.rb', line 56 def credit *args warn_on_positional args = args.last.is_a?(Hash) ? args.pop : {} amount = args[0] || .fetch(:amount) { nil } description = args[1] || .fetch(:description) { nil } if self.has_account? = args[2] || .fetch(:meta) { nil } appears_on_statement_as = args[3] || .fetch(:appears_on_statement_as) { nil } destination_uri = args[4] || .fetch(:destination_uri) { self.uri } credit = self.account.credit( :amount => amount, :meta => , :description => description, :destination_uri => destination_uri, :appears_on_statement_as => appears_on_statement_as ) else credit = Credit.new( :uri => self.credits_uri, :amount => amount, :description => description ) credit.save end credit end |
#debit(*args) ⇒ Debit
Creates a Debit of funds from this BankAccount to your Marketplace’s escrow account.
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/balanced/resources/bank_account.rb', line 34 def debit *args warn_on_positional args = args.last.is_a?(Hash) ? args.pop : {} amount = args[0] || .fetch(:amount) { nil } appears_on_statement_as = args[1] || .fetch(:appears_on_statement_as) { nil } = args[2] || .fetch(:meta) { nil } description = args[3] || .fetch(:description) { nil } self.account.debit( :amount => amount, :appears_on_statement_as => appears_on_statement_as, :meta => , :description => description, :source_uri => self.uri ) end |
#has_account? ⇒ Boolean
25 26 27 |
# File 'lib/balanced/resources/bank_account.rb', line 25 def has_account? self.respond_to? 'account' and !self.account.nil? end |
#invalidate ⇒ Object
86 87 88 89 |
# File 'lib/balanced/resources/bank_account.rb', line 86 def invalidate self.is_valid = false save end |
#verify ⇒ Object
91 92 93 94 95 |
# File 'lib/balanced/resources/bank_account.rb', line 91 def verify Verification.new( 'uri' => self.verifications_uri ).save end |