balanced 0.5.1 → 0.5.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/CONTRIBUTORS
CHANGED
@@ -7,17 +7,11 @@ module Balanced
|
|
7
7
|
class BankAccount
|
8
8
|
include Balanced::Resource
|
9
9
|
|
10
|
-
def self.has_account?
|
11
|
-
self.respond_to?('account') && !self.account.nil?
|
12
|
-
end
|
13
|
-
|
14
10
|
def self.uri
|
15
|
-
# Override the default nesting -- bank accounts can be
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
self.class.uri
|
20
|
-
end
|
11
|
+
# Override the default nesting -- bank accounts can be top-level now
|
12
|
+
# but they can also be nested under marketplaces, which is what we
|
13
|
+
# want to default to unless explicitly set
|
14
|
+
self.collection_path
|
21
15
|
end
|
22
16
|
|
23
17
|
def initialize attributes = {}
|
@@ -28,6 +22,10 @@ module Balanced
|
|
28
22
|
super attributes
|
29
23
|
end
|
30
24
|
|
25
|
+
def has_account?
|
26
|
+
self.respond_to? 'account' and !self.account.nil?
|
27
|
+
end
|
28
|
+
|
31
29
|
# Creates a Debit of funds from this BankAccount to your Marketplace's escrow account.
|
32
30
|
#
|
33
31
|
# @param [String] appears_on_statement_as If nil then Balanced will use
|
@@ -55,18 +53,28 @@ module Balanced
|
|
55
53
|
options = args.last.is_a?(Hash) ? args.pop : {}
|
56
54
|
amount = args[0] || options.fetch(:amount) { nil }
|
57
55
|
description = args[1] || options.fetch(:description) { nil }
|
58
|
-
|
59
|
-
|
60
|
-
:amount => amount,
|
61
|
-
:description => description,
|
62
|
-
:uri => self.credits_uri,
|
63
|
-
).save
|
64
|
-
else
|
56
|
+
|
57
|
+
if self.has_account?
|
65
58
|
meta = args[2] || options.fetch(:meta) { nil }
|
66
59
|
appears_on_statement_as = args[3] || options.fetch(:appears_on_statement_as) { nil }
|
67
|
-
|
68
|
-
self.account.credit(
|
60
|
+
destination_uri = args[4] || options.fetch(:destination_uri) { self.uri }
|
61
|
+
credit = self.account.credit(
|
62
|
+
:amount => amount,
|
63
|
+
:meta => meta,
|
64
|
+
:description => description,
|
65
|
+
:destination_uri => destination_uri,
|
66
|
+
:appears_on_statement_as => appears_on_statement_as
|
67
|
+
)
|
68
|
+
else
|
69
|
+
credit = Credit.new(
|
70
|
+
:uri => self.credits_uri,
|
71
|
+
:amount => amount,
|
72
|
+
:description => description
|
73
|
+
)
|
74
|
+
credit.save
|
69
75
|
end
|
76
|
+
|
77
|
+
credit
|
70
78
|
end
|
71
79
|
|
72
80
|
def invalidate
|
@@ -118,7 +118,7 @@ module Balanced
|
|
118
118
|
if self == Balanced::Merchant || self == Balanced::Marketplace || self == Balanced::ApiKey
|
119
119
|
collection_path
|
120
120
|
else
|
121
|
-
|
121
|
+
unless Balanced::Marketplace.marketplace_exists?
|
122
122
|
raise Balanced::StandardError, "#{self.name} is nested under a marketplace, which is not created or configured."
|
123
123
|
end
|
124
124
|
|
data/lib/balanced/version.rb
CHANGED
@@ -6,13 +6,13 @@ describe Balanced::BankAccount do
|
|
6
6
|
before do
|
7
7
|
api_key = Balanced::ApiKey.new.save
|
8
8
|
Balanced.configure api_key.secret
|
9
|
+
|
9
10
|
@marketplace = Balanced::Marketplace.new.save
|
10
|
-
card =
|
11
|
+
card = @marketplace.create_card(
|
11
12
|
:card_number => "5105105105105100",
|
12
13
|
:expiration_month => "12",
|
13
14
|
:expiration_year => "2015"
|
14
|
-
)
|
15
|
-
|
15
|
+
)
|
16
16
|
# An initial balance for the marketplace
|
17
17
|
@buyer = @marketplace.create_buyer(
|
18
18
|
:email_address => 'buyer@example.org',
|
@@ -43,18 +43,46 @@ describe Balanced::BankAccount do
|
|
43
43
|
use_vcr_cassette
|
44
44
|
|
45
45
|
before do
|
46
|
-
@bank_account =
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
)
|
46
|
+
@bank_account = @marketplace.create_bank_account(
|
47
|
+
:account_number => "0987654321",
|
48
|
+
:bank_code => "321174851",
|
49
|
+
:name => "Timmy T. McTimmerson",
|
50
|
+
:type => "checking"
|
51
|
+
)
|
52
52
|
end
|
53
53
|
|
54
|
-
|
55
|
-
|
54
|
+
context 'without an account' do
|
55
|
+
|
56
56
|
subject { @bank_account.account }
|
57
57
|
it { should be_nil }
|
58
|
+
|
59
|
+
describe 'has_account?' do
|
60
|
+
|
61
|
+
subject { @bank_account.has_account? }
|
62
|
+
it { should be_false }
|
63
|
+
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
context 'with an account' do
|
68
|
+
use_vcr_cassette
|
69
|
+
before do
|
70
|
+
@account = @marketplace.create_account
|
71
|
+
bank_account = @marketplace.create_bank_account(
|
72
|
+
:account_number => "0987654321",
|
73
|
+
:bank_code => "321174851",
|
74
|
+
:name => "Timmy T. McTimmerson",
|
75
|
+
:type => "checking"
|
76
|
+
)
|
77
|
+
@account.add_bank_account(bank_account.uri)
|
78
|
+
@bank_account_two = bank_account.reload
|
79
|
+
end
|
80
|
+
|
81
|
+
describe 'has_account?' do
|
82
|
+
subject { @bank_account_two.has_account? }
|
83
|
+
it { should be_true }
|
84
|
+
end
|
85
|
+
|
58
86
|
end
|
59
87
|
|
60
88
|
describe 'account_number' do
|
@@ -80,12 +108,42 @@ describe Balanced::BankAccount do
|
|
80
108
|
end
|
81
109
|
|
82
110
|
describe 'bank_account' do
|
83
|
-
use_vcr_cassette
|
84
|
-
|
85
111
|
subject { @credit.bank_account }
|
86
112
|
its(:account_number) {should end_with '4321'}
|
87
113
|
its(:routing_number) {should eql '321174851'}
|
114
|
+
|
88
115
|
end
|
116
|
+
|
117
|
+
describe 'without an account' do
|
118
|
+
subject { @credit }
|
119
|
+
it { should respond_to :account }
|
120
|
+
its(:account) { should be_nil }
|
121
|
+
end
|
122
|
+
|
123
|
+
describe 'with an account' do
|
124
|
+
use_vcr_cassette
|
125
|
+
|
126
|
+
before do
|
127
|
+
@account = @marketplace.create_account
|
128
|
+
bank_account = @marketplace.create_bank_account(
|
129
|
+
:account_number => "1234567890111",
|
130
|
+
:bank_code => "021000021",
|
131
|
+
:name => "Timmy T. McTimmerson",
|
132
|
+
:type => "checking"
|
133
|
+
)
|
134
|
+
@account.add_bank_account(bank_account.uri)
|
135
|
+
bank_account = bank_account.reload
|
136
|
+
@credit_with_account = bank_account.credit(
|
137
|
+
:amount => 500,
|
138
|
+
:description => 'Blahblahblah'
|
139
|
+
)
|
140
|
+
end
|
141
|
+
|
142
|
+
subject { @credit_with_account }
|
143
|
+
it { should respond_to :account }
|
144
|
+
it { should be_instance_of Balanced::Credit }
|
145
|
+
end
|
146
|
+
|
89
147
|
end
|
90
148
|
end
|
91
149
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: balanced
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-12-
|
12
|
+
date: 2012-12-12 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: faraday
|