balanced 0.7.2 → 0.7.4
Sign up to get free protection for your applications and to get access to all the features.
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/Gemfile +0 -1
- data/examples/examples.rb +2 -0
- data/examples/exception_handling.rb +43 -0
- data/lib/balanced.rb +1 -0
- data/lib/balanced/client.rb +2 -2
- data/lib/balanced/error.rb +16 -1
- data/lib/balanced/resources/account.rb +10 -6
- data/lib/balanced/resources/bank_account.rb +4 -3
- data/lib/balanced/resources/card.rb +12 -0
- data/lib/balanced/resources/customer.rb +16 -3
- data/lib/balanced/resources/resource.rb +54 -25
- data/lib/balanced/version.rb +1 -1
- data/scenarios/bank_account_delete/definition.rb +1 -1
- data/scenarios/bank_account_delete/request.rb +1 -1
- data/scenarios/bank_account_delete/ruby.mako +2 -2
- data/scenarios/card_delete/definition.rb +1 -0
- data/scenarios/card_delete/request.rb +3 -0
- data/scenarios/card_delete/ruby.mako +11 -0
- data/scenarios/card_update/ruby.mako +1 -1
- data/spec/balanced/error_spec.rb +14 -0
- data/spec/balanced/resources/account_spec.rb +76 -2
- data/spec/balanced/resources/bank_account_spec.rb +53 -12
- data/spec/balanced/resources/card_spec.rb +36 -0
- data/spec/balanced/resources/credit_spec.rb +1 -1
- data/spec/balanced/resources/customer_spec.rb +85 -0
- data/spec/spec_helper.rb +10 -0
- metadata +10 -2
data/.ruby-gemset
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
balanced-ruby
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
ruby-2.0.0-p247
|
data/Gemfile
CHANGED
data/examples/examples.rb
CHANGED
@@ -137,6 +137,8 @@ bank_account = Balanced::BankAccount.new(
|
|
137
137
|
:type => "checking"
|
138
138
|
).save
|
139
139
|
|
140
|
+
raise "Should not have an account" if bank_account.has_account?
|
141
|
+
|
140
142
|
puts "now let's credit it, the super-simple way"
|
141
143
|
credit = bank_account.credit(
|
142
144
|
:amount => 500
|
@@ -0,0 +1,43 @@
|
|
1
|
+
cwd = File.dirname(File.dirname(File.absolute_path(__FILE__)))
|
2
|
+
$:.unshift(cwd + "/lib")
|
3
|
+
require 'balanced'
|
4
|
+
|
5
|
+
begin
|
6
|
+
Balanced::Card
|
7
|
+
rescue NameError
|
8
|
+
raise "wtf"
|
9
|
+
end
|
10
|
+
|
11
|
+
require 'balanced'
|
12
|
+
|
13
|
+
Balanced.configure("8bb66df4e80711e290df026ba7cd33d0")
|
14
|
+
|
15
|
+
puts "create our marketplace"
|
16
|
+
begin
|
17
|
+
marketplace = Balanced::Marketplace.new.save
|
18
|
+
rescue Balanced::Conflict => ex
|
19
|
+
# balanced automatically maps the body's response
|
20
|
+
# for convenience, so for example:
|
21
|
+
puts ex.response[:body]
|
22
|
+
# you'll notice this hash is mapped to nice attributes
|
23
|
+
raise "Not Present" if ex.response[:body]["status"] != ex.status
|
24
|
+
# you can find all of the attributes here:
|
25
|
+
# https://docs.balancedpayments.com/current/api?language=bash#errors
|
26
|
+
marketplace = Balanced::Marketplace.mine
|
27
|
+
end
|
28
|
+
|
29
|
+
# create a new card
|
30
|
+
|
31
|
+
card = Balanced::Card.new(
|
32
|
+
:card_number => "5105105105105100",
|
33
|
+
:expiration_month => "12",
|
34
|
+
:expiration_year => "2015",
|
35
|
+
:phone_number => "INCORRECT PHONE NUMBER"
|
36
|
+
)
|
37
|
+
|
38
|
+
begin
|
39
|
+
card.save
|
40
|
+
rescue Balanced::BadRequest => ex
|
41
|
+
puts ex.extras[:phone_number]
|
42
|
+
puts "All the fields that have errors are: #{ex.extras.keys}"
|
43
|
+
end
|
data/lib/balanced.rb
CHANGED
data/lib/balanced/client.rb
CHANGED
@@ -14,8 +14,8 @@ module Balanced
|
|
14
14
|
:port => 5000,
|
15
15
|
:version => '1',
|
16
16
|
:logging_level => 'WARN',
|
17
|
-
:connection_timeout =>
|
18
|
-
:read_timeout =>
|
17
|
+
:connection_timeout => 60,
|
18
|
+
:read_timeout => 60,
|
19
19
|
:logger => nil,
|
20
20
|
:ssl_verify => true,
|
21
21
|
:faraday_adapter => Faraday.default_adapter
|
data/lib/balanced/error.rb
CHANGED
@@ -42,8 +42,23 @@ module Balanced
|
|
42
42
|
attr_reader :message
|
43
43
|
alias :error_message :message
|
44
44
|
|
45
|
-
|
45
|
+
# @param [String, nil] message a description of the exception
|
46
|
+
def initialize(message = nil)
|
46
47
|
@message = message
|
48
|
+
super(message)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
# Raised when attempted to create a debit or hold for a card not associated to an account
|
53
|
+
class UnassociatedCardError < StandardError
|
54
|
+
# @param [Balanced::Card] card
|
55
|
+
def initialize(card)
|
56
|
+
@card = card
|
57
|
+
super(error_message)
|
58
|
+
end
|
59
|
+
|
60
|
+
def error_message
|
61
|
+
"The Balanced::Card with uri=#{@card.attributes['uri']} is not associated to an account"
|
47
62
|
end
|
48
63
|
end
|
49
64
|
|
@@ -111,18 +111,22 @@ module Balanced
|
|
111
111
|
|
112
112
|
# Associates the Card represented by +card_uri+ with this Account.
|
113
113
|
#
|
114
|
-
# @return [
|
115
|
-
def add_card
|
116
|
-
|
114
|
+
# @return [Account]
|
115
|
+
def add_card(card)
|
116
|
+
card.save if card.kind_of?(Balanced::Card) && card.hash.nil?
|
117
|
+
self.card_uri = Balanced::Utils.extract_uri_from_object(card)
|
117
118
|
save
|
118
119
|
end
|
119
120
|
|
120
121
|
# Associates the BankAccount represented by +bank_account_uri+ with this
|
121
122
|
# Account.
|
122
123
|
#
|
123
|
-
# @return [
|
124
|
-
def add_bank_account
|
125
|
-
|
124
|
+
# @return [Account]
|
125
|
+
def add_bank_account(bank_account)
|
126
|
+
if bank_account.kind_of?(Balanced::BankAccount) && bank_account.fingerprint.nil?
|
127
|
+
bank_account.save
|
128
|
+
end
|
129
|
+
self.bank_account_uri = Balanced::Utils.extract_uri_from_object(bank_account)
|
126
130
|
save
|
127
131
|
end
|
128
132
|
|
@@ -59,10 +59,10 @@ module Balanced
|
|
59
59
|
options = args.last.is_a?(Hash) ? args.pop : {}
|
60
60
|
amount = args[0] || options.fetch(:amount) { nil }
|
61
61
|
description = args[1] || options.fetch(:description) { nil }
|
62
|
-
|
62
|
+
appears_on_statement_as = args[3] || options.fetch(:appears_on_statement_as) { nil }
|
63
|
+
|
63
64
|
if self.has_account?
|
64
65
|
meta = args[2] || options.fetch(:meta) { nil }
|
65
|
-
appears_on_statement_as = args[3] || options.fetch(:appears_on_statement_as) { nil }
|
66
66
|
destination_uri = args[4] || options.fetch(:destination_uri) { self.uri }
|
67
67
|
credit = self.account.credit(
|
68
68
|
:amount => amount,
|
@@ -75,7 +75,8 @@ module Balanced
|
|
75
75
|
credit = Credit.new(
|
76
76
|
:uri => self.credits_uri,
|
77
77
|
:amount => amount,
|
78
|
-
:description => description
|
78
|
+
:description => description,
|
79
|
+
:appears_on_statement_as => appears_on_statement_as
|
79
80
|
)
|
80
81
|
credit.save
|
81
82
|
end
|
@@ -36,6 +36,8 @@ module Balanced
|
|
36
36
|
meta = args[3] || options.fetch(:meta) { nil }
|
37
37
|
description = args[3] || options.fetch(:description) { nil }
|
38
38
|
|
39
|
+
ensure_associated_to_account!
|
40
|
+
|
39
41
|
self.account.debit(
|
40
42
|
:amount => amount,
|
41
43
|
:appears_on_statement_as => appears_on_statement_as,
|
@@ -55,6 +57,8 @@ module Balanced
|
|
55
57
|
amount = args[0] || options.fetch(:amount) { nil }
|
56
58
|
meta = args[1] || options.fetch(:meta) { nil }
|
57
59
|
|
60
|
+
ensure_associated_to_account!
|
61
|
+
|
58
62
|
self.account.hold(
|
59
63
|
:amount => amount,
|
60
64
|
:meta => meta,
|
@@ -67,6 +71,14 @@ module Balanced
|
|
67
71
|
save
|
68
72
|
end
|
69
73
|
|
74
|
+
private
|
75
|
+
# Ensure that one of account, account_uri, customer or customer_uri are set.
|
76
|
+
# Otherwise raise an exception.
|
77
|
+
def ensure_associated_to_account!
|
78
|
+
if attributes.values_at('account', 'account_uri', 'customer', 'customer_uri').compact.empty?
|
79
|
+
raise UnassociatedCardError.new(self)
|
80
|
+
end
|
81
|
+
end
|
70
82
|
end
|
71
83
|
|
72
84
|
end
|
@@ -19,6 +19,19 @@ module Balanced
|
|
19
19
|
super attributes
|
20
20
|
end
|
21
21
|
|
22
|
+
# Attempts to find an existing customer by email
|
23
|
+
#
|
24
|
+
# *NOTE:* There is no unique constraint on email_address.
|
25
|
+
# Multiple customers with the same email may exist.
|
26
|
+
# Only one Customer is returned.
|
27
|
+
#
|
28
|
+
# @param [String] email An email of a customer
|
29
|
+
# @return [Customer] if customer is found
|
30
|
+
# @return [nil] if customer is not found
|
31
|
+
def self.find_by_email email
|
32
|
+
self.find(:first, :email => email)
|
33
|
+
end
|
34
|
+
|
22
35
|
def debit(options = {})
|
23
36
|
amount = options[:amount]
|
24
37
|
appears_on_statement_as = options[:appears_on_statement_as]
|
@@ -60,7 +73,7 @@ module Balanced
|
|
60
73
|
|
61
74
|
# Associates the Card represented by 'card' with this Customer.
|
62
75
|
#
|
63
|
-
# @return [
|
76
|
+
# @return [Customer]
|
64
77
|
|
65
78
|
def add_card(card)
|
66
79
|
card.save if card.kind_of?(Balanced::Card) && card.hash.nil?
|
@@ -71,9 +84,9 @@ module Balanced
|
|
71
84
|
# Associates the BankAccount represented by bank_account with this
|
72
85
|
# Customer.
|
73
86
|
#
|
74
|
-
# @return [
|
87
|
+
# @return [Customer]
|
75
88
|
def add_bank_account(bank_account)
|
76
|
-
if bank_account.kind_of?(Balanced::BankAccount) && bank_account.
|
89
|
+
if bank_account.kind_of?(Balanced::BankAccount) && bank_account.fingerprint.nil?
|
77
90
|
bank_account.save
|
78
91
|
end
|
79
92
|
self.bank_account_uri = Balanced::Utils.extract_uri_from_object(bank_account)
|
@@ -67,6 +67,10 @@ module Balanced
|
|
67
67
|
Balanced.delete @attributes[:uri]
|
68
68
|
end
|
69
69
|
|
70
|
+
def unstore
|
71
|
+
destroy
|
72
|
+
end
|
73
|
+
|
70
74
|
def reload the_response = nil
|
71
75
|
if the_response
|
72
76
|
return if the_response.body.to_s.length.zero?
|
@@ -90,9 +94,45 @@ module Balanced
|
|
90
94
|
attr = method.to_s.chop
|
91
95
|
@attributes[attr] = args[0]
|
92
96
|
else
|
93
|
-
|
97
|
+
# This piece of code is a bit disgusting. We will clean it up soon,
|
98
|
+
# but basically, we were creating closures using this code snippet
|
99
|
+
# but those closures were transferred to the actual classes themselves
|
100
|
+
# so you would have something like BankAccount.new.account and this
|
101
|
+
# will give the last closure added for a BankAccount even if it has
|
102
|
+
# nothing to do with the actual class itself.
|
103
|
+
#
|
104
|
+
# This caused some weird errors, so the best thing to do was to just
|
105
|
+
# move this piece of code and "dynamically" enable it for all
|
106
|
+
# method requests that are essentially #{method}_uri.
|
107
|
+
#
|
108
|
+
# This solves the acute problem, for now.
|
109
|
+
if @attributes.has_key? "#{method}_uri"
|
110
|
+
|
111
|
+
value = @attributes["#{method}_uri"]
|
112
|
+
# what if the server returns a _uri that we don't know how to
|
113
|
+
# construct? Welp, we catch that NameError and return to super.
|
114
|
+
begin
|
115
|
+
values_class = Balanced.from_uri(value)
|
116
|
+
rescue NameError
|
117
|
+
super
|
118
|
+
end
|
119
|
+
|
120
|
+
# if uri is a collection -> this would definitely be if
|
121
|
+
# it ends in a symbol then we should allow a lazy executor of
|
122
|
+
# the query pager
|
123
|
+
if Balanced.is_collection(value)
|
124
|
+
pager = Balanced::Pager.new value, {}
|
125
|
+
return pager.to_a
|
126
|
+
else
|
127
|
+
return values_class.find(value)
|
128
|
+
end
|
129
|
+
|
130
|
+
else
|
131
|
+
super
|
132
|
+
end
|
94
133
|
end
|
95
134
|
end
|
135
|
+
|
96
136
|
def self.included(base)
|
97
137
|
base.extend ClassMethods
|
98
138
|
end
|
@@ -143,37 +183,26 @@ module Balanced
|
|
143
183
|
return payload if payload[:uri].nil?
|
144
184
|
klass = Balanced.from_uri(payload[:uri])
|
145
185
|
instance = klass.new payload
|
186
|
+
|
187
|
+
# http://stackoverflow.com/a/2495650/133514
|
188
|
+
instance_eigen = class << instance; self; end
|
189
|
+
|
146
190
|
payload.each do |name, value|
|
147
|
-
|
148
|
-
attr_accessor name.to_s
|
149
|
-
}
|
191
|
+
|
150
192
|
# here is where our interpretations will begin.
|
151
193
|
# if the value is a sub-resource, lets instantiate the class
|
152
194
|
# and set it correctly
|
153
195
|
if value.instance_of? Hash and value.has_key? 'uri'
|
154
196
|
value = construct_from_response value
|
155
|
-
elsif name =~ /_uri$/
|
156
|
-
modified_name = name.sub(/_uri$/, '')
|
157
|
-
klass.instance_eval {
|
158
|
-
define_method(modified_name) {
|
159
|
-
values_class = Balanced.from_uri(value)
|
160
|
-
# if uri is a collection -> this would definitely be if it ends in a symbol
|
161
|
-
# then we should allow a lazy executor of the query pager
|
162
|
-
if Balanced.is_collection(value)
|
163
|
-
pager = Pager.new value, {}
|
164
|
-
pager.to_a
|
165
|
-
else
|
166
|
-
values_class.find(value)
|
167
|
-
end
|
168
|
-
}
|
169
|
-
}
|
170
197
|
end
|
171
198
|
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
199
|
+
# Get attribute
|
200
|
+
instance.class.send(:define_method, name, proc{@attributes[name]})
|
201
|
+
# Set attribute
|
202
|
+
instance.class.send(:define_method, "#{name}=", proc{ |value| @attributes[name] = value })
|
203
|
+
# Is attribute present?
|
204
|
+
instance.class.send(:define_method, "#{name}?", proc{ !!@attributes[name] })
|
205
|
+
|
177
206
|
instance.send("#{name}=".to_s, value)
|
178
207
|
end
|
179
208
|
instance
|
@@ -192,7 +221,7 @@ module Balanced
|
|
192
221
|
end
|
193
222
|
|
194
223
|
def paginate options = {}
|
195
|
-
Pager.new uri, options
|
224
|
+
Balanced::Pager.new uri, options
|
196
225
|
end
|
197
226
|
alias scoped paginate
|
198
227
|
alias where paginate
|
data/lib/balanced/version.rb
CHANGED
@@ -1 +1 @@
|
|
1
|
-
Balanced::BankAccount.
|
1
|
+
Balanced::BankAccount.unstore
|
@@ -1,11 +1,11 @@
|
|
1
1
|
% if mode == 'definition':
|
2
|
-
Balanced::BankAccount.
|
2
|
+
Balanced::BankAccount.unstore
|
3
3
|
|
4
4
|
% else:
|
5
5
|
require 'balanced'
|
6
6
|
Balanced.configure('8af725c6d54611e2bf5e026ba7f8ec28')
|
7
7
|
|
8
8
|
bank_account = Balanced::BankAccount.find('/v1/bank_accounts/BA4eTWiY1VPXkGpjaU6XPBhu')
|
9
|
-
bank_account.
|
9
|
+
bank_account.unstore
|
10
10
|
|
11
11
|
% endif
|
@@ -0,0 +1 @@
|
|
1
|
+
Balanced::Card.unstore
|
@@ -7,7 +7,7 @@ Balanced.configure('8af725c6d54611e2bf5e026ba7f8ec28')
|
|
7
7
|
|
8
8
|
card = Balanced::Card.find('/v1/marketplaces/TEST-MP4erLnXCYoaeyr3tx95WSKc/cards/CC4wel9K6ASutW6zqCWZpjsj')
|
9
9
|
card.meta = {
|
10
|
-
|
10
|
+
'facebook.user_id' => '0192837465', 'my-own-customer-id' => '12345', 'twitter.id' => '1234987650'
|
11
11
|
}
|
12
12
|
card.save
|
13
13
|
|
data/spec/balanced/error_spec.rb
CHANGED
@@ -39,4 +39,18 @@ describe Balanced::StandardError do
|
|
39
39
|
|
40
40
|
its(:message) { should == 'ohnoe!' }
|
41
41
|
its(:error_message) { should == 'ohnoe!' }
|
42
|
+
its(:to_s) { should == 'ohnoe!' }
|
43
|
+
its(:inspect) { should == '#<Balanced::StandardError: ohnoe!>' }
|
44
|
+
end
|
45
|
+
|
46
|
+
describe Balanced::UnassociatedCardError do
|
47
|
+
let(:card) { Balanced::Card.new(uri: '/v1/marketplaces/123/cards/235') }
|
48
|
+
|
49
|
+
subject do
|
50
|
+
Balanced::UnassociatedCardError.new(card)
|
51
|
+
end
|
52
|
+
|
53
|
+
its(:message) do
|
54
|
+
should == "The Balanced::Card with uri=#{card.attributes['uri']} is not associated to an account"
|
55
|
+
end
|
42
56
|
end
|
@@ -171,7 +171,7 @@ describe Balanced::Account, :vcr do
|
|
171
171
|
end
|
172
172
|
end
|
173
173
|
|
174
|
-
describe "#add_bank_account", :vcr do
|
174
|
+
describe "#add_bank_account using uri", :vcr do
|
175
175
|
before do
|
176
176
|
@new_bank_account = @marketplace.create_bank_account(
|
177
177
|
:account_number => "1234567890",
|
@@ -194,6 +194,30 @@ describe Balanced::Account, :vcr do
|
|
194
194
|
it { should eql 2 }
|
195
195
|
end
|
196
196
|
end
|
197
|
+
|
198
|
+
describe "#add_bank_account using tokenized object", :vcr do
|
199
|
+
before do
|
200
|
+
@new_bank_account = @marketplace.create_bank_account(
|
201
|
+
:account_number => "1234567890",
|
202
|
+
:bank_code => "321174851",
|
203
|
+
:name => "Jack Q Merchant"
|
204
|
+
)
|
205
|
+
end
|
206
|
+
|
207
|
+
describe "when executing" do
|
208
|
+
it { -> { @merchant.add_bank_account(@new_bank_account) }.should_not raise_error }
|
209
|
+
end
|
210
|
+
|
211
|
+
describe "after executing", :vcr do
|
212
|
+
before do
|
213
|
+
@merchant.add_bank_account(@new_bank_account)
|
214
|
+
@bank_accounts = Balanced::BankAccount.find(@merchant.bank_accounts_uri).items
|
215
|
+
end
|
216
|
+
|
217
|
+
subject { @bank_accounts.size }
|
218
|
+
it { should eql 2 }
|
219
|
+
end
|
220
|
+
end
|
197
221
|
end
|
198
222
|
|
199
223
|
describe "buyer" do
|
@@ -301,7 +325,7 @@ describe Balanced::Account, :vcr do
|
|
301
325
|
end
|
302
326
|
end
|
303
327
|
|
304
|
-
describe "#add_card" do
|
328
|
+
describe "#add_card with uri" do
|
305
329
|
describe "when executing", :vcr do
|
306
330
|
before do
|
307
331
|
card = Balanced::Card.new(
|
@@ -350,6 +374,56 @@ describe Balanced::Account, :vcr do
|
|
350
374
|
it { should eql 2 }
|
351
375
|
end
|
352
376
|
end
|
377
|
+
|
378
|
+
describe "#add_card with tokenized object" do
|
379
|
+
describe "when executing", :vcr do
|
380
|
+
before do
|
381
|
+
card = Balanced::Card.new(
|
382
|
+
:card_number => "4111111111111111",
|
383
|
+
:expiration_month => "12",
|
384
|
+
:expiration_year => "2015",
|
385
|
+
).save
|
386
|
+
@new_card = Balanced::Card.new(
|
387
|
+
:card_number => "4111111111111111",
|
388
|
+
:expiration_month => "1",
|
389
|
+
:expiration_year => "2015",
|
390
|
+
).save
|
391
|
+
@buyer = Balanced::Account.new(
|
392
|
+
:uri => @marketplace.accounts_uri,
|
393
|
+
:email_address => "buyer3@example.org",
|
394
|
+
:card_uri => card.uri,
|
395
|
+
:name => "Jack Q Buyer"
|
396
|
+
).save
|
397
|
+
end
|
398
|
+
it do
|
399
|
+
-> { @buyer.add_card(@new_card) }.should_not raise_error
|
400
|
+
end
|
401
|
+
end
|
402
|
+
describe "after executing", :vcr do
|
403
|
+
before do
|
404
|
+
card = Balanced::Card.new(
|
405
|
+
:card_number => "4111111111111111",
|
406
|
+
:expiration_month => "12",
|
407
|
+
:expiration_year => "2015",
|
408
|
+
).save
|
409
|
+
@new_card = Balanced::Card.new(
|
410
|
+
:card_number => "5105105105105100",
|
411
|
+
:expiration_month => "1",
|
412
|
+
:expiration_year => "2017",
|
413
|
+
).save
|
414
|
+
@buyer = Balanced::Account.new(
|
415
|
+
:uri => @marketplace.accounts_uri,
|
416
|
+
:email_address => "buyer4@example.org",
|
417
|
+
:card_uri => card.uri,
|
418
|
+
:name => "Jack Q Buyer"
|
419
|
+
).save
|
420
|
+
@buyer.add_card(@new_card)
|
421
|
+
@cards = Balanced::Card.find @buyer.cards_uri
|
422
|
+
end
|
423
|
+
subject { @cards.items.size }
|
424
|
+
it { should eql 2 }
|
425
|
+
end
|
426
|
+
end
|
353
427
|
|
354
428
|
describe "#promote_to_merchant" do
|
355
429
|
describe "when executing", :vcr do
|
@@ -120,26 +120,67 @@ describe Balanced::BankAccount, :vcr do
|
|
120
120
|
its(:routing_number) { should eql '321174851' }
|
121
121
|
end
|
122
122
|
|
123
|
-
describe '
|
123
|
+
describe 'without an account', :vcr do
|
124
124
|
before do
|
125
|
-
@
|
126
|
-
bank_account = @marketplace.create_bank_account(
|
125
|
+
@bank_account = @marketplace.create_bank_account(
|
127
126
|
:account_number => "1234567890111",
|
128
127
|
:bank_code => "021000021",
|
129
128
|
:name => "Timmy T. McTimmerson",
|
130
129
|
:type => "checking"
|
131
130
|
)
|
132
|
-
@account.add_bank_account(bank_account.uri)
|
133
|
-
bank_account = bank_account.reload
|
134
|
-
@credit_with_account = bank_account.credit(
|
135
|
-
:amount => 500,
|
136
|
-
:description => 'Blahblahblah'
|
137
|
-
)
|
138
131
|
end
|
132
|
+
|
133
|
+
describe 'with appears_on_statement_as', :vcr do
|
134
|
+
before do
|
135
|
+
@credit = @bank_account.credit(amount: 1000, description: "Testing", appears_on_statement_as: "Test Company")
|
136
|
+
end
|
137
|
+
|
138
|
+
subject { @credit }
|
139
|
+
its(:appears_on_statement_as) { should eql 'Test Company' }
|
140
|
+
end
|
141
|
+
end
|
139
142
|
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
+
describe 'with an account', :vcr do
|
144
|
+
before do
|
145
|
+
@bank_account = @marketplace.create_bank_account(
|
146
|
+
:account_number => "1234567890111",
|
147
|
+
:bank_code => "021000021",
|
148
|
+
:name => "Timmy T. McTimmerson",
|
149
|
+
:type => "checking"
|
150
|
+
)
|
151
|
+
@account = @marketplace.create_account
|
152
|
+
@account.add_bank_account(@bank_account.uri)
|
153
|
+
@bank_account.reload
|
154
|
+
end
|
155
|
+
|
156
|
+
describe 'with appears_on_statement_as', :vcr do
|
157
|
+
before do
|
158
|
+
@credit = @bank_account.credit(
|
159
|
+
:amount => 1000,
|
160
|
+
:description => "Blahblahblah",
|
161
|
+
:appears_on_statement_as => "Test Company"
|
162
|
+
)
|
163
|
+
end
|
164
|
+
|
165
|
+
subject { @credit }
|
166
|
+
it { should respond_to :account }
|
167
|
+
it { should be_instance_of Balanced::Credit }
|
168
|
+
its(:appears_on_statement_as) { should eql 'Test Company' }
|
169
|
+
end
|
170
|
+
|
171
|
+
describe 'without appears_on_statement_as', :vcr do
|
172
|
+
before do
|
173
|
+
@credit = @bank_account.credit(
|
174
|
+
:amount => 1000,
|
175
|
+
:description => "Testing",
|
176
|
+
)
|
177
|
+
end
|
178
|
+
|
179
|
+
subject { @credit }
|
180
|
+
it { should respond_to :account }
|
181
|
+
it { should be_instance_of Balanced::Credit }
|
182
|
+
its(:appears_on_statement_as) { should eql 'example.com' }
|
183
|
+
end
|
143
184
|
end
|
144
185
|
end
|
145
186
|
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Balanced::Card, '#debit', vcr: true, marketplace: true do
|
4
|
+
it 'raises an exception with an unassociated card' do
|
5
|
+
card = Balanced::Card.new
|
6
|
+
expect {
|
7
|
+
card.debit
|
8
|
+
}.to raise_error(Balanced::UnassociatedCardError)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
describe Balanced::Card, '#hold', vcr: true, marketplace: true do
|
13
|
+
it 'raises an exception with an unassociated card' do
|
14
|
+
card = Balanced::Card.new
|
15
|
+
expect {
|
16
|
+
card.hold
|
17
|
+
}.to raise_error(Balanced::UnassociatedCardError)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
describe Balanced::Card, '#debit', vcr: true, marketplace: true do
|
22
|
+
it 'debits the card if an account is set' do
|
23
|
+
# tokenize card
|
24
|
+
card = Balanced::Card.new(
|
25
|
+
card_number: '4111111111111111',
|
26
|
+
expiration_year: '2016',
|
27
|
+
expiration_month: '12')
|
28
|
+
card.save
|
29
|
+
|
30
|
+
# associate card to account
|
31
|
+
Balanced::Account.new(email_address: 'user@example.com', name: 'John Doe', card_uri: card.uri).save
|
32
|
+
|
33
|
+
card = Balanced::Card.find(card.uri)
|
34
|
+
card.debit(amount: 10000).should be_instance_of Balanced::Debit
|
35
|
+
end
|
36
|
+
end
|
@@ -104,6 +104,39 @@ describe Balanced::Customer, :vcr do
|
|
104
104
|
end
|
105
105
|
end
|
106
106
|
|
107
|
+
describe "#delete card", :vcr do
|
108
|
+
before do
|
109
|
+
@card_2 = @marketplace.create_card(
|
110
|
+
:card_number => "4111111111111111",
|
111
|
+
:expiration_month => "12",
|
112
|
+
:expiration_year => "2015",
|
113
|
+
).save
|
114
|
+
@card_2.unstore
|
115
|
+
end
|
116
|
+
it "Should throw 404 on deleted card" do
|
117
|
+
expect{
|
118
|
+
Balanced::Card.find(@card_2.uri)
|
119
|
+
}.to raise_error
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
describe "#delete bank account", :vcr do
|
124
|
+
before do
|
125
|
+
@bank_account_2 = @marketplace.create_bank_account(
|
126
|
+
:account_number => "0987654321",
|
127
|
+
:bank_code => "321174851",
|
128
|
+
:name => "Timmy T. McTimmerson",
|
129
|
+
:type => "checking"
|
130
|
+
)
|
131
|
+
@bank_account_2.unstore
|
132
|
+
end
|
133
|
+
it "Should throw 404 on deleted card" do
|
134
|
+
expect {
|
135
|
+
Balanced::BankAccount.find(@bank_account_2.uri)
|
136
|
+
}.to raise_error
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
107
140
|
describe "#add_bank_account using tokenized object", :vcr do
|
108
141
|
before do
|
109
142
|
@customer = @marketplace.create_customer
|
@@ -144,6 +177,37 @@ describe Balanced::Customer, :vcr do
|
|
144
177
|
end
|
145
178
|
end
|
146
179
|
|
180
|
+
describe "#find_by_email", :vcr => { :record => :new_episodes } do
|
181
|
+
before do
|
182
|
+
api_key = Balanced::ApiKey.new.save
|
183
|
+
Balanced.configure api_key.secret
|
184
|
+
@marketplace = Balanced::Marketplace.new.save
|
185
|
+
customer = @marketplace.create_customer(
|
186
|
+
:name => "Bill",
|
187
|
+
:email => "bill@bill.com",
|
188
|
+
:business_name => "Bill Inc.",
|
189
|
+
:ssn_last4 => "1234",
|
190
|
+
:address => {
|
191
|
+
:line1 => "1234 1st Street",
|
192
|
+
:city => "San Francisco",
|
193
|
+
:state => "CA"
|
194
|
+
}
|
195
|
+
).save
|
196
|
+
end
|
197
|
+
|
198
|
+
context "email address is in system", :vcr => { :record => :new_episodes } do
|
199
|
+
it "should return customer object" do
|
200
|
+
Balanced::Customer.find_by_email("bill@bill.com").should be_instance_of Balanced::Customer
|
201
|
+
end
|
202
|
+
end
|
203
|
+
|
204
|
+
context "email address does not exist", :vcr => { :record => :new_episodes } do
|
205
|
+
it "should return nil" do
|
206
|
+
Balanced::Customer.find_by_email("foo@bar.com").should be_nil
|
207
|
+
end
|
208
|
+
end
|
209
|
+
end
|
210
|
+
|
147
211
|
describe "#debit" do
|
148
212
|
before do
|
149
213
|
@customer = @marketplace.create_customer
|
@@ -223,6 +287,27 @@ describe Balanced::Customer, :vcr do
|
|
223
287
|
@customer.active_bank_account.should_not be_nil
|
224
288
|
end
|
225
289
|
end
|
290
|
+
|
291
|
+
describe "find_by_email", :vcr do
|
292
|
+
before do
|
293
|
+
@customer = @marketplace.create_customer(
|
294
|
+
:email => "balanced-ruby-issue-110@example.com"
|
295
|
+
)
|
296
|
+
end
|
297
|
+
|
298
|
+
it "should return 401 unauthorized if not authenticated" do
|
299
|
+
@customer.uri.should_not be_nil
|
300
|
+
key = Balanced.client.api_key
|
301
|
+
Balanced.configure(nil)
|
302
|
+
expect {
|
303
|
+
Balanced::Customer.find(
|
304
|
+
:first,
|
305
|
+
email: "balanced-ruby-issue-110@example.com")
|
306
|
+
}.to raise_error Balanced::Unauthorized
|
307
|
+
Balanced.configure(key)
|
308
|
+
end
|
309
|
+
|
310
|
+
end
|
226
311
|
end
|
227
312
|
|
228
313
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -37,6 +37,16 @@ RSpec.configure do |c|
|
|
37
37
|
Balanced.configure api_key.secret
|
38
38
|
Balanced::Marketplace.new.save
|
39
39
|
end
|
40
|
+
|
41
|
+
# @example Use this metadata to create a marketplace in a before block
|
42
|
+
# describe "something under test", vcr: true, marketplace: true do
|
43
|
+
# it "works" do
|
44
|
+
# # ...
|
45
|
+
# end
|
46
|
+
# end
|
47
|
+
c.before(:each, marketplace: true) do
|
48
|
+
make_marketplace
|
49
|
+
end
|
40
50
|
end
|
41
51
|
|
42
52
|
|
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.7.
|
4
|
+
version: 0.7.4
|
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: 2013-
|
12
|
+
date: 2013-08-06 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: faraday
|
@@ -55,6 +55,8 @@ files:
|
|
55
55
|
- .gitignore
|
56
56
|
- .rbenv-version
|
57
57
|
- .rspec
|
58
|
+
- .ruby-gemset
|
59
|
+
- .ruby-version
|
58
60
|
- .travis.yml
|
59
61
|
- CONTRIBUTORS
|
60
62
|
- Gemfile
|
@@ -77,6 +79,7 @@ files:
|
|
77
79
|
- examples/customers.rb
|
78
80
|
- examples/events_and_callbacks.rb
|
79
81
|
- examples/examples.rb
|
82
|
+
- examples/exception_handling.rb
|
80
83
|
- lib/balanced.rb
|
81
84
|
- lib/balanced/client.rb
|
82
85
|
- lib/balanced/error.rb
|
@@ -175,6 +178,9 @@ files:
|
|
175
178
|
- scenarios/card_create/definition.rb
|
176
179
|
- scenarios/card_create/request.rb
|
177
180
|
- scenarios/card_create/ruby.mako
|
181
|
+
- scenarios/card_delete/definition.rb
|
182
|
+
- scenarios/card_delete/request.rb
|
183
|
+
- scenarios/card_delete/ruby.mako
|
178
184
|
- scenarios/card_invalidate/definition.rb
|
179
185
|
- scenarios/card_invalidate/request.rb
|
180
186
|
- scenarios/card_invalidate/ruby.mako
|
@@ -324,6 +330,7 @@ files:
|
|
324
330
|
- spec/balanced/resources/api_key_spec.rb
|
325
331
|
- spec/balanced/resources/bank_account_spec.rb
|
326
332
|
- spec/balanced/resources/callback_spec.rb
|
333
|
+
- spec/balanced/resources/card_spec.rb
|
327
334
|
- spec/balanced/resources/credit_spec.rb
|
328
335
|
- spec/balanced/resources/customer_spec.rb
|
329
336
|
- spec/balanced/resources/hold_spec.rb
|
@@ -368,6 +375,7 @@ test_files:
|
|
368
375
|
- spec/balanced/resources/api_key_spec.rb
|
369
376
|
- spec/balanced/resources/bank_account_spec.rb
|
370
377
|
- spec/balanced/resources/callback_spec.rb
|
378
|
+
- spec/balanced/resources/card_spec.rb
|
371
379
|
- spec/balanced/resources/credit_spec.rb
|
372
380
|
- spec/balanced/resources/customer_spec.rb
|
373
381
|
- spec/balanced/resources/hold_spec.rb
|