Class: Balanced::BankAccount

Inherits:
Object
  • Object
show all
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

#attributes

Class Method Summary collapse

Instance Method Summary collapse

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

.uriObject



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.

Returns:



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

  options = args.last.is_a?(Hash) ? args.pop : {}
  amount = args[0] || options.fetch(:amount) { nil }
  description = args[1] || options.fetch(:description) { nil }

  if self.has_account?
    meta = args[2] || options.fetch(:meta) { nil }
    appears_on_statement_as = args[3] || options.fetch(:appears_on_statement_as) { nil }
    destination_uri = args[4] || options.fetch(:destination_uri) { self.uri }
    credit = self..credit(
        :amount => amount,
        :meta => 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.

Parameters:

  • appears_on_statement_as (String)

    If nil then Balanced will use the domain_name property from your Marketplace.

Returns:



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

  options = args.last.is_a?(Hash) ? args.pop : {}
  amount = args[0] || options.fetch(:amount) { nil }
  appears_on_statement_as = args[1] || options.fetch(:appears_on_statement_as) { nil }
  meta = args[2] || options.fetch(:meta) { nil }
  description = args[3] || options.fetch(:description) { nil }

  self..debit(
      :amount => amount,
      :appears_on_statement_as => appears_on_statement_as,
      :meta => meta,
      :description => description,
      :source_uri => self.uri
  )
end

#has_account?Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/balanced/resources/bank_account.rb', line 25

def has_account?
  self.respond_to? 'account' and !self..nil?
end

#invalidateObject



86
87
88
89
# File 'lib/balanced/resources/bank_account.rb', line 86

def invalidate
  self.is_valid = false
  save
end

#verifyObject



91
92
93
94
95
# File 'lib/balanced/resources/bank_account.rb', line 91

def verify
  Verification.new(
      'uri' => self.verifications_uri
  ).save
end