balanced 1.0.2 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (94) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +5 -0
  3. data/Gemfile +1 -0
  4. data/balanced.gemspec +1 -1
  5. data/lib/balanced/client.rb +1 -2
  6. data/lib/balanced/error.rb +3 -3
  7. data/lib/balanced/resources/card.rb +15 -1
  8. data/lib/balanced/version.rb +1 -1
  9. data/scenarios/api_key_create/ruby.mako +6 -6
  10. data/scenarios/api_key_delete/ruby.mako +2 -2
  11. data/scenarios/api_key_list/ruby.mako +10 -10
  12. data/scenarios/api_key_show/ruby.mako +6 -6
  13. data/scenarios/bank_account_associate_to_customer/ruby.mako +14 -14
  14. data/scenarios/bank_account_create/ruby.mako +11 -11
  15. data/scenarios/bank_account_credit/ruby.mako +15 -15
  16. data/scenarios/bank_account_debit/ruby.mako +15 -15
  17. data/scenarios/bank_account_delete/ruby.mako +2 -2
  18. data/scenarios/bank_account_list/ruby.mako +22 -22
  19. data/scenarios/bank_account_show/ruby.mako +12 -12
  20. data/scenarios/bank_account_update/ruby.mako +12 -12
  21. data/scenarios/bank_account_verification_create/definition.rb +1 -1
  22. data/scenarios/bank_account_verification_create/ruby.mako +10 -10
  23. data/scenarios/bank_account_verification_show/definition.rb +1 -1
  24. data/scenarios/bank_account_verification_show/request.rb +1 -1
  25. data/scenarios/bank_account_verification_show/ruby.mako +10 -10
  26. data/scenarios/bank_account_verification_update/definition.rb +1 -1
  27. data/scenarios/bank_account_verification_update/request.rb +1 -1
  28. data/scenarios/bank_account_verification_update/ruby.mako +10 -10
  29. data/scenarios/callback_create/ruby.mako +4 -4
  30. data/scenarios/callback_delete/ruby.mako +2 -2
  31. data/scenarios/callback_list/ruby.mako +4 -4
  32. data/scenarios/callback_show/ruby.mako +5 -5
  33. data/scenarios/card_associate_to_customer/ruby.mako +21 -12
  34. data/scenarios/card_create/ruby.mako +18 -9
  35. data/scenarios/card_create_creditable/definition.rb +1 -0
  36. data/scenarios/card_create_creditable/request.rb +4 -0
  37. data/scenarios/card_create_creditable/ruby.mako +62 -0
  38. data/scenarios/card_create_dispute/ruby.mako +18 -9
  39. data/scenarios/card_credit/definition.rb +1 -0
  40. data/scenarios/card_credit/request.rb +5 -0
  41. data/scenarios/card_credit/ruby.mako +43 -0
  42. data/scenarios/card_debit/ruby.mako +16 -16
  43. data/scenarios/card_debit_dispute/ruby.mako +15 -15
  44. data/scenarios/card_delete/ruby.mako +2 -2
  45. data/scenarios/card_hold_capture/ruby.mako +16 -16
  46. data/scenarios/card_hold_create/ruby.mako +14 -14
  47. data/scenarios/card_hold_list/ruby.mako +25 -25
  48. data/scenarios/card_hold_show/ruby.mako +14 -14
  49. data/scenarios/card_hold_update/ruby.mako +14 -14
  50. data/scenarios/card_hold_void/ruby.mako +15 -15
  51. data/scenarios/card_list/ruby.mako +36 -18
  52. data/scenarios/card_show/ruby.mako +19 -10
  53. data/scenarios/card_update/ruby.mako +19 -10
  54. data/scenarios/credit_list/ruby.mako +14 -14
  55. data/scenarios/credit_list_bank_account/ruby.mako +2 -2
  56. data/scenarios/credit_order/definition.rb +1 -0
  57. data/scenarios/credit_order/request.rb +7 -0
  58. data/scenarios/credit_order/ruby.mako +26 -0
  59. data/scenarios/credit_show/ruby.mako +15 -15
  60. data/scenarios/credit_update/ruby.mako +15 -15
  61. data/scenarios/customer_create/ruby.mako +20 -18
  62. data/scenarios/customer_delete/ruby.mako +1 -1
  63. data/scenarios/customer_list/ruby.mako +39 -35
  64. data/scenarios/customer_show/ruby.mako +21 -19
  65. data/scenarios/customer_update/ruby.mako +21 -19
  66. data/scenarios/debit_dispute_show/ruby.mako +12 -12
  67. data/scenarios/debit_list/ruby.mako +34 -34
  68. data/scenarios/debit_order/definition.rb +1 -0
  69. data/scenarios/debit_order/request.rb +7 -0
  70. data/scenarios/debit_order/ruby.mako +49 -0
  71. data/scenarios/debit_show/ruby.mako +16 -16
  72. data/scenarios/debit_update/ruby.mako +16 -16
  73. data/scenarios/dispute_list/ruby.mako +11 -11
  74. data/scenarios/dispute_show/ruby.mako +12 -12
  75. data/scenarios/event_list/ruby.mako +56 -55
  76. data/scenarios/event_show/ruby.mako +41 -35
  77. data/scenarios/order_create/ruby.mako +14 -14
  78. data/scenarios/order_list/ruby.mako +45 -13
  79. data/scenarios/order_show/ruby.mako +14 -14
  80. data/scenarios/order_update/ruby.mako +14 -14
  81. data/scenarios/refund_create/ruby.mako +13 -13
  82. data/scenarios/refund_list/ruby.mako +12 -12
  83. data/scenarios/refund_show/ruby.mako +13 -13
  84. data/scenarios/refund_update/ruby.mako +13 -13
  85. data/scenarios/render_mako.rb +1 -1
  86. data/scenarios/reversal_create/ruby.mako +12 -12
  87. data/scenarios/reversal_list/ruby.mako +11 -11
  88. data/scenarios/reversal_show/ruby.mako +12 -12
  89. data/scenarios/reversal_update/ruby.mako +12 -12
  90. data/spec/balanced/resources/card_spec.rb +73 -11
  91. data/spec/balanced/resources/credit_spec.rb +155 -26
  92. data/spec/balanced/response/balanced_exception_middleware_spec.rb +1 -2
  93. data/spec/spec_helper.rb +3 -1
  94. metadata +22 -4
@@ -3,9 +3,9 @@ Balanced::Reversal.save
3
3
 
4
4
  % elif mode == 'request':
5
5
  require 'balanced'
6
- Balanced.configure('ak-test-22IOkhevjZlmRP2do6CZixkkDshTiOjTV')
6
+ Balanced.configure('ak-test-2q80HU8DISm2atgm0iRKRVIePzDb34qYp')
7
7
 
8
- reversal = Balanced::Reversal.fetch('/reversals/RV6qrEOTouLeIJuPu4s73Ra1')
8
+ reversal = Balanced::Reversal.fetch('/reversals/RV7BYCqyLOKwcWigapAoGWdr')
9
9
  reversal.description = 'update this description'
10
10
  reversal.meta = {
11
11
  'refund.reason' => 'user not happy with product',
@@ -15,30 +15,30 @@ reversal.meta = {
15
15
  reversal.save
16
16
 
17
17
  % elif mode == 'response':
18
- #<Balanced::Reversal:0x007fa93b66d2a8
18
+ #<Balanced::Reversal:0x007fa7d40df150
19
19
  @attributes=
20
20
  {"amount"=>3000,
21
- "created_at"=>"2014-04-25T20:18:55.008280Z",
21
+ "created_at"=>"2014-05-15T00:43:48.266113Z",
22
22
  "currency"=>"USD",
23
23
  "description"=>"update this description",
24
24
  "failure_reason"=>nil,
25
25
  "failure_reason_code"=>nil,
26
- "href"=>"/reversals/RV6qrEOTouLeIJuPu4s73Ra1",
27
- "id"=>"RV6qrEOTouLeIJuPu4s73Ra1",
28
- "links"=>{"credit"=>"CR6nBcaGvGc4dtflEB1bjKBP", "order"=>nil},
26
+ "href"=>"/reversals/RV7BYCqyLOKwcWigapAoGWdr",
27
+ "id"=>"RV7BYCqyLOKwcWigapAoGWdr",
28
+ "links"=>{"credit"=>"CR7ushK6kWjPJYdh24QoM1A9", "order"=>nil},
29
29
  "meta"=>
30
30
  {"refund.reason"=>"user not happy with product",
31
31
  "user.notes"=>"very polite on the phone",
32
32
  "user.satisfaction"=>"6"},
33
33
  "status"=>"succeeded",
34
- "transaction_number"=>"RV296-883-6069",
35
- "updated_at"=>"2014-04-25T20:19:01.228936Z"},
34
+ "transaction_number"=>"RV689-626-0403",
35
+ "updated_at"=>"2014-05-15T00:43:58.209158Z"},
36
36
  @hyperlinks=
37
37
  {"credit"=>
38
- #<Proc:0x007fa93b666318/lib/balanced/resources/resource.rb:60 (lambda)>,
38
+ #<Proc:0x007fa7d40dd0a8/lib/balanced/resources/resource.rb:60 (lambda)>,
39
39
  "events"=>
40
- #<Proc:0x007fa93b65c098/lib/balanced/utils.rb:6 (lambda)>,
40
+ #<Proc:0x007fa7d40d70e0/lib/balanced/utils.rb:6 (lambda)>,
41
41
  "order"=>
42
- #<Proc:0x007fa93b655dd8/lib/balanced/utils.rb:6 (lambda)>}>
42
+ #<Proc:0x007fa7d40d5678/lib/balanced/utils.rb:6 (lambda)>}>
43
43
 
44
44
  % endif
@@ -12,22 +12,84 @@ describe Balanced::Card, :vcr do
12
12
  :expiration_year => '2020',
13
13
  :cvv => '123'
14
14
  ).save
15
+ @card.debit(:amount => 1000000)
15
16
  end
16
17
 
17
18
  describe 'card', :vcr do
18
- it 'should be a Balanced::Card' do
19
- @card.should be_instance_of Balanced::Card
19
+ describe 'standard card' do
20
+ it 'should be a Balanced::Card' do
21
+ @card.should be_instance_of Balanced::Card
22
+ end
23
+
24
+ describe 'attributes', :vcr do
25
+ subject { @card }
26
+ its(:href) { should match "/cards/#{@card.id}" }
27
+ its(:number) { should end_with '5100' }
28
+ its(:expiration_month) { should eql 12 }
29
+ its(:expiration_year) { should eql 2020 }
30
+ its(:cvv) { should eql 'xxx' }
31
+ its(:cvv_match) { should eql 'yes' }
32
+ its(:cvv_result) { should eql 'Match' }
33
+ its(:can_credit) { should eql false }
34
+ its(:can_debit) { should eql true }
35
+ its(:bank_name) { should eql 'BANK OF HAWAII' }
36
+ end
20
37
  end
21
38
 
22
- describe 'attributes', :vcr do
23
- subject { @card }
24
- its(:href) { should match "/cards/#{@card.id}" }
25
- its(:number) { should end_with '5100' }
26
- its(:expiration_month) { should eql 12 }
27
- its(:expiration_year) { should eql 2020 }
28
- its(:cvv) { should eql 'xxx' }
29
- its(:cvv_match) { should eql 'yes' }
30
- its(:cvv_result) { should eql 'Match' }
39
+ describe 'card that can be credited' do
40
+ before do
41
+ @push_card = Balanced::Card.new(
42
+ :name => 'Johannes Bach',
43
+ :number => '4342561111111118',
44
+ :expiration_month => '05',
45
+ :expiration_year => '2015',
46
+ :cvv => '123'
47
+ ).save
48
+ end
49
+
50
+ it 'should be a Balanced::Card' do
51
+ @push_card.should be_instance_of Balanced::Card
52
+ end
53
+
54
+ describe 'attributes', :vcr do
55
+ subject { @push_card }
56
+ its(:href) { should match "/cards/#{@push_card.id}" }
57
+ its(:number) { should end_with '1118' }
58
+ its(:expiration_month) { should eql 05 }
59
+ its(:expiration_year) { should eql 2015 }
60
+ its(:cvv) { should eql 'xxx' }
61
+ its(:cvv_match) { should eql 'yes' }
62
+ its(:cvv_result) { should eql 'Match' }
63
+ its(:can_credit) { should eql true }
64
+ its(:can_debit) { should eql true }
65
+ its(:bank_name) { should eql 'WELLS FARGO BANK, N.A.' }
66
+ its(:category) { should eql 'other' }
67
+ its(:type) { should eql 'debit'}
68
+ end
69
+
70
+ describe '#credit' do
71
+ before do
72
+ @meta = {
73
+ 'invoice_id' => '1024'
74
+ }
75
+ @credit = @push_card.credit(
76
+ :amount => 1234,
77
+ :description => 'Some descriptive text',
78
+ :meta => @meta
79
+ )
80
+ end
81
+
82
+ describe 'attributes', :vcr do
83
+ let(:credit) { @credit }
84
+
85
+ it 'should have valid attributes' do
86
+ expect(credit.href).to eq("/credits/#{@credit.id}")
87
+ expect(credit.amount).to eq(1234)
88
+ expect(credit.meta).to eq(@meta)
89
+ expect(credit.status).to eq('succeeded')
90
+ end
91
+ end
92
+ end
31
93
  end
32
94
 
33
95
  describe 'creating a one-time debit', :vcr => {:record => :new_episodes} do
@@ -12,40 +12,169 @@ describe Balanced::Credit, :vcr do
12
12
  ).save
13
13
 
14
14
  # An initial balance for the marketplace
15
- card.debit(:amount => 1000000)
15
+ card.debit(:amount => 10000000)
16
16
  @meta = {"order_id" => "1111"}
17
17
  end
18
18
 
19
- describe '#create', :vcr do
20
- before do
21
- @credit = Balanced::Credit.new(
22
- :amount => 5000,
23
- :description => 'A sweet ride',
24
- :destination => {
25
- :routing_number => '321174851',
26
- :account_number => '0987654321',
27
- :name => 'Timmy T. McTimmerson',
28
- :type => 'checking'
29
- },
30
- :meta => @meta
31
- ).save
32
- end
19
+ context 'BankAccount' do
20
+ describe '#create', :vcr do
21
+ before do
22
+ @credit = Balanced::Credit.new(
23
+ :amount => 5000,
24
+ :description => 'A sweet ride',
25
+ :destination => {
26
+ :routing_number => '321174851',
27
+ :account_number => '0987654321',
28
+ :name => 'Timmy T. McTimmerson',
29
+ :type => 'checking'
30
+ },
31
+ :meta => @meta
32
+ ).save
33
+ end
33
34
 
34
- describe 'amount', :vcr do
35
- subject { @credit.amount }
36
- it { should == 5000 }
37
- end
35
+ describe 'amount', :vcr do
36
+ subject { @credit.amount }
37
+ it { should == 5000 }
38
+ end
38
39
 
39
- describe 'customer', :vcr do
40
- subject { @credit.customer }
41
- it { should be_nil }
42
- end
40
+ describe 'customer', :vcr do
41
+ subject { @credit.customer }
42
+ it { should be_nil }
43
+ end
44
+
45
+ describe 'meta', :vcr do
46
+ subject { @credit.meta }
47
+ it { should eq @meta }
48
+ end
43
49
 
44
- describe 'meta', :vcr do
45
- subject { @credit.meta }
46
- it { should eq @meta }
47
50
  end
51
+ end
52
+
53
+ context 'Card' do
54
+ describe '#create', :vcr do
55
+ context 'succeed' do
56
+ context 'existing card' do
57
+ before do
58
+ @card = Balanced::Card.new(
59
+ :name => 'Johannes Bach',
60
+ :number => '4342561111111118',
61
+ :expiration_month => '05',
62
+ :expiration_year => '2015'
63
+ ).save
64
+
65
+ @credit = Balanced::Credit.new(
66
+ :amount => 250000,
67
+ :description => 'A sweet ride',
68
+ :destination => @card.href,
69
+ :meta => @meta
70
+ ).save
71
+ end
72
+
73
+ describe 'attributes', :vcr do
74
+ let(:credit) { @credit }
75
+
76
+ it 'should have valid attributes' do
77
+ expect(credit.href).to eq("/credits/#{@credit.id}")
78
+ expect(credit.amount).to eq(250000)
79
+ expect(credit.meta).to eq(@meta)
80
+ expect(credit.status).to eq('succeeded')
81
+ end
82
+ end
83
+ end
84
+
85
+ context 'card in request' do
86
+ before do
87
+ @credit = Balanced::Credit.new(
88
+ :amount => 250000,
89
+ :description => 'A sweet ride',
90
+ :destination => {
91
+ :name => 'Johannes Bach',
92
+ :number => '4342561111111118',
93
+ :expiration_month => '05',
94
+ :expiration_year => '2015'
95
+ },
96
+ :meta => @meta
97
+ ).save
98
+ end
99
+
100
+ describe 'attributes', :vcr do
101
+ let(:credit) { @credit }
102
+
103
+ it 'should have valid attributes' do
104
+ expect(credit.href).to eq("/credits/#{@credit.id}")
105
+ expect(credit.amount).to eq(250000)
106
+ expect(credit.meta).to eq(@meta)
107
+ expect(credit.status).to eq('succeeded')
108
+ end
109
+ end
110
+ end
111
+ end
48
112
 
113
+ context 'fail' do
114
+ describe 'can_credit false' do
115
+ context 'card in request' do
116
+ it do
117
+ expect {
118
+ @credit = Balanced::Credit.new(
119
+ :amount => 1234,
120
+ :destination => {
121
+ :name => 'Georg Telemann',
122
+ :number => '4111111111111111',
123
+ :expiration_month => '12',
124
+ :expiration_year => '2016'
125
+ }
126
+ ).save
127
+ }.to raise_exception(Balanced::Conflict)
128
+ end
129
+ end
130
+
131
+ context 'card#credit' do
132
+ it do
133
+ expect {
134
+ @card = Balanced::Card.new(
135
+ :name => 'Georg Telemann',
136
+ :number => '4111111111111111',
137
+ :expiration_month => '12',
138
+ :expiration_year => '2016'
139
+ ).save
140
+ @card.credit(:amount => 1234)
141
+ }.to raise_exception(Balanced::FundingInstrumentNotCreditable)
142
+ end
143
+ end
144
+ end
145
+
146
+ describe 'credit amount limit' do
147
+ it do
148
+ expect {
149
+ @credit = Balanced::Credit.new(
150
+ :amount => 250001,
151
+ :destination => {
152
+ :name => 'Georg Telemann',
153
+ :number => '4342561111111118',
154
+ :expiration_month => '05',
155
+ :expiration_year => '2015'
156
+ }
157
+ ).save
158
+ }.to raise_exception(Balanced::Conflict)
159
+ end
160
+ end
161
+
162
+ describe 'requires cardholder name' do
163
+ it do
164
+ expect {
165
+ @credit = Balanced::Credit.new(
166
+ :amount => 1234,
167
+ :destination => {
168
+ :number => '4342561111111118',
169
+ :expiration_month => '05',
170
+ :expiration_year => '2015'
171
+ }
172
+ ).save
173
+ }.to raise_exception(Balanced::BadRequest)
174
+ end
175
+ end
176
+ end
177
+ end
49
178
  end
50
179
 
51
180
  describe '#reverse', :vcr do
@@ -9,8 +9,7 @@ describe Faraday::Response::RaiseBalancedError, :type => :response do
9
9
  context "integration test" do
10
10
 
11
11
  before(:each) do
12
- Faraday.register_middleware :response,
13
- :handle_balanced_errors => lambda { described_class }
12
+ Faraday::Response.register_middleware :handle_balanced_errors => lambda { described_class }
14
13
  VCR.turn_off!
15
14
  end
16
15
 
@@ -4,6 +4,7 @@ require 'balanced'
4
4
  require 'vcr'
5
5
  require 'json'
6
6
  require 'securerandom'
7
+ require 'webmock'
7
8
 
8
9
  begin
9
10
  require 'ruby-debug'
@@ -14,7 +15,8 @@ end
14
15
 
15
16
  VCR.configure do |c|
16
17
  c.cassette_library_dir = 'spec/cassettes'
17
- c.hook_into :faraday
18
+ #c.hook_into :faraday
19
+ c.hook_into :webmock # TEMP WORK AROUND FOR https://github.com/vcr/vcr/issues/386
18
20
  c.configure_rspec_metadata!
19
21
  c.default_cassette_options = {:record => :new_episodes}
20
22
  c.allow_http_connections_when_no_cassette = true
metadata CHANGED
@@ -1,29 +1,35 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: balanced
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Balanced
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-04-28 00:00:00.000000000 Z
11
+ date: 2014-05-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: 0.8.6
20
+ - - "<="
21
+ - !ruby/object:Gem::Version
22
+ version: 0.9.0
20
23
  type: :runtime
21
24
  prerelease: false
22
25
  version_requirements: !ruby/object:Gem::Requirement
23
26
  requirements:
24
- - - "~>"
27
+ - - ">="
25
28
  - !ruby/object:Gem::Version
26
29
  version: 0.8.6
30
+ - - "<="
31
+ - !ruby/object:Gem::Version
32
+ version: 0.9.0
27
33
  - !ruby/object:Gem::Dependency
28
34
  name: faraday_middleware
29
35
  requirement: !ruby/object:Gem::Requirement
@@ -171,9 +177,15 @@ files:
171
177
  - scenarios/card_create/definition.rb
172
178
  - scenarios/card_create/request.rb
173
179
  - scenarios/card_create/ruby.mako
180
+ - scenarios/card_create_creditable/definition.rb
181
+ - scenarios/card_create_creditable/request.rb
182
+ - scenarios/card_create_creditable/ruby.mako
174
183
  - scenarios/card_create_dispute/definition.rb
175
184
  - scenarios/card_create_dispute/request.rb
176
185
  - scenarios/card_create_dispute/ruby.mako
186
+ - scenarios/card_credit/definition.rb
187
+ - scenarios/card_credit/request.rb
188
+ - scenarios/card_credit/ruby.mako
177
189
  - scenarios/card_debit/definition.rb
178
190
  - scenarios/card_debit/request.rb
179
191
  - scenarios/card_debit/ruby.mako
@@ -216,6 +228,9 @@ files:
216
228
  - scenarios/credit_list_bank_account/definition.rb
217
229
  - scenarios/credit_list_bank_account/request.rb
218
230
  - scenarios/credit_list_bank_account/ruby.mako
231
+ - scenarios/credit_order/definition.rb
232
+ - scenarios/credit_order/request.rb
233
+ - scenarios/credit_order/ruby.mako
219
234
  - scenarios/credit_show/definition.rb
220
235
  - scenarios/credit_show/request.rb
221
236
  - scenarios/credit_show/ruby.mako
@@ -243,6 +258,9 @@ files:
243
258
  - scenarios/debit_list/definition.rb
244
259
  - scenarios/debit_list/request.rb
245
260
  - scenarios/debit_list/ruby.mako
261
+ - scenarios/debit_order/definition.rb
262
+ - scenarios/debit_order/request.rb
263
+ - scenarios/debit_order/ruby.mako
246
264
  - scenarios/debit_show/definition.rb
247
265
  - scenarios/debit_show/request.rb
248
266
  - scenarios/debit_show/ruby.mako