boletosimples 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (32) hide show
  1. checksums.yaml +4 -4
  2. data/.ruby-version +1 -1
  3. data/CHANGELOG.md +14 -0
  4. data/boletosimples.gemspec +3 -1
  5. data/example/access_token_example.rb +29 -4
  6. data/example/oauth_example.rb +28 -4
  7. data/lib/boletosimples/client.rb +11 -4
  8. data/lib/boletosimples/version.rb +1 -1
  9. data/spec/boletosimples/client_spec.rb +407 -4
  10. data/spec/boletosimples/oauth_client_spec.rb +6 -3
  11. data/spec/fixtures/vcr_cassettes/BoletoSimples_Client/_bank_billet/existing_bank_billet.yml +61 -0
  12. data/spec/fixtures/vcr_cassettes/BoletoSimples_Client/_bank_billet/not_found.yml +44 -0
  13. data/spec/fixtures/vcr_cassettes/BoletoSimples_Client/_bank_billets.yml +63 -0
  14. data/spec/fixtures/vcr_cassettes/BoletoSimples_Client/_cancel_bank_billet/already_canceled.yml +58 -0
  15. data/spec/fixtures/vcr_cassettes/BoletoSimples_Client/_cancel_bank_billet/with_invalid_bank_billet.yml +54 -0
  16. data/spec/fixtures/vcr_cassettes/BoletoSimples_Client/_cancel_bank_billet/with_valid_bank_billet.yml +71 -0
  17. data/spec/fixtures/vcr_cassettes/BoletoSimples_Client/_create_bank_billet/with_invalid_data.yml +64 -0
  18. data/spec/fixtures/vcr_cassettes/BoletoSimples_Client/_create_bank_billet/with_valid_data.yml +66 -0
  19. data/spec/fixtures/vcr_cassettes/BoletoSimples_Client/_create_customer/with_invalid_data.yml +59 -0
  20. data/spec/fixtures/vcr_cassettes/BoletoSimples_Client/_create_customer/with_valid_data.yml +61 -0
  21. data/spec/fixtures/vcr_cassettes/BoletoSimples_Client/_customer/existing_customer.yml +57 -0
  22. data/spec/fixtures/vcr_cassettes/BoletoSimples_Client/_customer/not_found.yml +58 -0
  23. data/spec/fixtures/vcr_cassettes/BoletoSimples_Client/_customers.yml +59 -0
  24. data/spec/fixtures/vcr_cassettes/BoletoSimples_Client/_transactions.yml +67 -0
  25. data/spec/fixtures/vcr_cassettes/BoletoSimples_Client/_userinfo/with_authentication.yml +56 -0
  26. data/spec/fixtures/vcr_cassettes/BoletoSimples_Client/_userinfo/with_authentication/.yml +56 -0
  27. data/spec/fixtures/vcr_cassettes/BoletoSimples_Client/_userinfo/without_authentication.yml +54 -0
  28. data/spec/fixtures/vcr_cassettes/BoletoSimples_Client/_userinfo/without_authentication/.yml +54 -0
  29. data/spec/fixtures/vcr_cassettes/BoletoSimples_OAuthClient/_userinfo/without_authentication/.yml +62 -0
  30. data/spec/spec_helper.rb +18 -0
  31. data/spec/support/vcr.rb +7 -0
  32. metadata +72 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2308d90f08f6bc03b5924e079ea4025c78fdf098
4
- data.tar.gz: 228d16b39a08fb903dae06cecc343063a40a5440
3
+ metadata.gz: 544af5de32ea938f99ed648486d828b9414115f8
4
+ data.tar.gz: 29b5b8c262fa0e1e5c21db89a907ed2e390d4327
5
5
  SHA512:
6
- metadata.gz: c5b659dd17090bb8d4f9a505fc4d7bc873b68e3e265913c48ed32aa6f16693b4b7ae359e8078aea3f2c3a57a19514fd09cc41ceb65df913030ff96f491e57f8e
7
- data.tar.gz: e9542387817afba27ff562706ec11bd6dd806580f2b95656ae7eeb93255eb8d78141327775b5cbfe2e6e523e24dfddf194ee950b556bcfb147b8b675b616f1d0
6
+ metadata.gz: bf70373d7671b92546e502195f903db5206d578ecf715c6d9258ea5ba81c2a5af759e43dcb24694c83740d526d2dd20fbd6ce1ecc6f4256e3b60a46c9123cbbb
7
+ data.tar.gz: de8e4b256b7407fd4fd0ed4661ab1d45253117227fbb881090ceb483797531af97b596c18cd1b647677d4cd920d6e4fb0b9fc664e2140cf5331e74523453fdd6
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 2.1.3
1
+ 2.1.5
data/CHANGELOG.md ADDED
@@ -0,0 +1,14 @@
1
+ # Changelog
2
+
3
+ ## 0.0.7 (unreleased)
4
+
5
+ ### features
6
+
7
+ - Created `client.cancel_bank_billet(id, options)` to cancel bank billets
8
+
9
+ ### improvements
10
+
11
+ - Changed `client.create_customer({ "customer" => params })` to `client.create_customer(params)`
12
+ - Changed `client.create_bank_billet({ "bank_billet" => params })` to `client.create_bank_billet(params)`
13
+
14
+ ### bug fixes
@@ -27,7 +27,9 @@ Gem::Specification.new do |gem|
27
27
 
28
28
  # Gems that must be installed for boletosimples to compile and build
29
29
  gem.add_development_dependency 'pry'
30
- gem.add_development_dependency 'rspec'
30
+ gem.add_development_dependency 'rspec', '~> 3.1'
31
+ gem.add_development_dependency 'vcr', '~> 2.9'
32
+ gem.add_development_dependency 'webmock'
31
33
  gem.add_development_dependency 'rake'
32
34
  gem.add_development_dependency 'coveralls'
33
35
  gem.add_development_dependency 'codeclimate-test-reporter'
@@ -12,7 +12,7 @@ client = BoletoSimples::Client.new('access_token', user_agent: 'Meu e-Commerce (
12
12
 
13
13
  # pp client.customer 2
14
14
  #
15
- # pp client.create_customer({:customer =>
15
+ # pp client.create_customer(
16
16
  # {
17
17
  # person_name: "Joao da Silva",
18
18
  # cnpj_cpf: "012.345.678-90",
@@ -26,13 +26,36 @@ client = BoletoSimples::Client.new('access_token', user_agent: 'Meu e-Commerce (
26
26
  # address_complement: "Sala 4",
27
27
  # phone_number: "2112123434"
28
28
  # }
29
- # })
29
+ # )
30
30
 
31
31
  # pp client.bank_billets
32
32
 
33
33
  # pp client.bank_billet 3
34
34
 
35
- # pp client.create_bank_billet({bank_billet:
35
+ # Boleto normal
36
+ # pp client.create_bank_billet(
37
+ # {
38
+ # amount: 41.01,
39
+ # customer_address: 'Rua quinhentos',
40
+ # customer_address_complement: 'Sala 4',
41
+ # customer_address_number: '111',
42
+ # customer_city_name: 'Rio de Janeiro',
43
+ # customer_cnpj_cpf: '012.345.678-90',
44
+ # customer_email: 'cliente@bom.com',
45
+ # customer_neighborhood: 'Sao Francisco',
46
+ # customer_person_name: 'Joao da Silva',
47
+ # customer_person_type: 'individual',
48
+ # customer_phone_number: '2112123434',
49
+ # customer_state: 'RJ',
50
+ # customer_zipcode: '12312-123',
51
+ # description: 'Despesas do contrato 0012',
52
+ # expire_at: '2014-01-01',
53
+ # notification_url: 'http://example.com.br/notify'
54
+ # }
55
+ # )
56
+
57
+ # Boleto parcelado
58
+ # pp client.create_bank_billet(
36
59
  # {
37
60
  # amount: 41.01,
38
61
  # customer_address: 'Rua quinhentos',
@@ -50,5 +73,7 @@ client = BoletoSimples::Client.new('access_token', user_agent: 'Meu e-Commerce (
50
73
  # description: 'Despesas do contrato 0012',
51
74
  # expire_at: '2014-01-01',
52
75
  # notification_url: 'http://example.com.br/notify',
76
+ # parcels: 3
53
77
  # }
54
- # })
78
+ # )
79
+
@@ -60,7 +60,7 @@ client = BoletoSimples::OAuthClient.new('app_id',
60
60
 
61
61
  # pp client.customer 2
62
62
  #
63
- # pp client.create_customer({:customer =>
63
+ # pp client.create_customer(
64
64
  # {
65
65
  # person_name: "Joao da Silva",
66
66
  # cnpj_cpf: "012.345.678-90",
@@ -74,13 +74,36 @@ client = BoletoSimples::OAuthClient.new('app_id',
74
74
  # address_complement: "Sala 4",
75
75
  # phone_number: "2112123434"
76
76
  # }
77
- # })
77
+ # )
78
78
 
79
79
  # pp client.bank_billets
80
80
 
81
81
  # pp client.bank_billet 3
82
82
 
83
- # pp client.create_bank_billet({bank_billet:
83
+ # Boleto normal
84
+ # pp client.create_bank_billet(
85
+ # {
86
+ # amount: 41.01,
87
+ # customer_address: 'Rua quinhentos',
88
+ # customer_address_complement: 'Sala 4',
89
+ # customer_address_number: '111',
90
+ # customer_city_name: 'Rio de Janeiro',
91
+ # customer_cnpj_cpf: '012.345.678-90',
92
+ # customer_email: 'cliente@bom.com',
93
+ # customer_neighborhood: 'Sao Francisco',
94
+ # customer_person_name: 'Joao da Silva',
95
+ # customer_person_type: 'individual',
96
+ # customer_phone_number: '2112123434',
97
+ # customer_state: 'RJ',
98
+ # customer_zipcode: '12312-123',
99
+ # description: 'Despesas do contrato 0012',
100
+ # expire_at: '2014-01-01',
101
+ # notification_url: 'http://example.com.br/notify'
102
+ # }
103
+ # )
104
+
105
+ # Boleto parcelado
106
+ # pp client.create_bank_billet(
84
107
  # {
85
108
  # amount: 41.01,
86
109
  # customer_address: 'Rua quinhentos',
@@ -98,5 +121,6 @@ client = BoletoSimples::OAuthClient.new('app_id',
98
121
  # description: 'Despesas do contrato 0012',
99
122
  # expire_at: '2014-01-01',
100
123
  # notification_url: 'http://example.com.br/notify',
124
+ # parcels: 3
101
125
  # }
102
- # })
126
+ # )
@@ -38,7 +38,7 @@ module BoletoSimples
38
38
  end
39
39
 
40
40
  def create_customer(options = {})
41
- post '/customers', options
41
+ post '/customers', customer: options
42
42
  end
43
43
 
44
44
  def customer(id = 1, options = {})
@@ -51,15 +51,18 @@ module BoletoSimples
51
51
  end
52
52
 
53
53
  def create_bank_billet(options = {})
54
- post '/bank_billets', options
54
+ post '/bank_billets', bank_billet: options
55
55
  end
56
56
 
57
- def bank_billet(id = 1, options = {})
57
+ def bank_billet(id, options = {})
58
58
  get "/bank_billets/#{id}", options
59
59
  end
60
60
 
61
- # Wrappers for the main HTTP verbs
61
+ def cancel_bank_billet(id, options = {})
62
+ put "/bank_billets/#{id}/cancel", options
63
+ end
62
64
 
65
+ # Wrappers for the main HTTP verbs
63
66
  def get(path, options = {})
64
67
  http_verb :get, path, options
65
68
  end
@@ -72,6 +75,10 @@ module BoletoSimples
72
75
  http_verb :put, path, options
73
76
  end
74
77
 
78
+ def patch(path, options = {})
79
+ http_verb :patch, path, options
80
+ end
81
+
75
82
  def delete(path, options = {})
76
83
  http_verb :delete, path, options
77
84
  end
@@ -1,3 +1,3 @@
1
1
  module BoletoSimples
2
- VERSION = '0.0.6'
2
+ VERSION = '0.0.7'
3
3
  end
@@ -2,11 +2,414 @@
2
2
 
3
3
  require 'spec_helper'
4
4
 
5
- describe BoletoSimples::Client do
6
- describe :userinfo do
7
- context :without_authentication do
8
- let(:client) { BoletoSimples::Client.new(nil, user_agent: 'Meu e-Commerce (meuecommerce@example.com)') }
5
+ RSpec.describe BoletoSimples::Client do
6
+ subject(:client) do
7
+ BoletoSimples::Client.new(access_token, user_agent: 'Meu e-Commerce (meuecommerce@example.com)')
8
+ end
9
+
10
+ let(:access_token) { '9e616874dbf0674ace28170a748c9258ac1f0f87e0a544441ebffe976645bc09' }
11
+
12
+ describe '#userinfo' do
13
+ context 'without authentication', :vcr do
14
+ let(:access_token) { nil }
15
+
9
16
  it { expect(client.userinfo).to eq('error' => 'Você precisa se logar ou registrar antes de prosseguir.') }
10
17
  end
18
+
19
+ context 'with authentication', vcr: { cassette_name: 'BoletoSimples_Client/_userinfo/with_authentication'} do
20
+ let(:json_keys) do
21
+ ["account_level", "account_type",
22
+ "address_city_name", "address_complement",
23
+ "address_neighborhood", "address_number",
24
+ "address_postal_code", "address_state",
25
+ "address_street_name", "business_cnpj",
26
+ "business_legal_name", "business_name",
27
+ "cpf", "date_of_birth", "email", "father_name",
28
+ "first_name", "full_name", "id", "last_name",
29
+ "login_url", "middle_name", "mother_name" , "phone_number"
30
+ ]
31
+ end
32
+
33
+ it { expect(client.userinfo['email']).to eq('marciojunior1991@gmail.com') }
34
+ it { expect(client.userinfo['account_level']).to eq(2) }
35
+ it { expect(client.userinfo.keys).to match_array(json_keys) }
36
+ end
37
+ end
38
+
39
+ describe '#create_customer' do
40
+
41
+ context 'with valid data', vcr: { cassette_name: 'BoletoSimples_Client/_create_customer/with_valid_data' } do
42
+ let(:payload) do
43
+ {
44
+ "id" => 32,
45
+ "mobile_local_code" => nil,
46
+ "mobile_number" => nil,
47
+ "person_type" => "individual",
48
+ "person_name" => "Joao da Silva",
49
+ "cnpj_cpf"=> "012.345.678-90",
50
+ "email" => "cliente@bom.com",
51
+ "address" => "Rua quinhentos",
52
+ "city_name" => "Rio de Janeiro",
53
+ "state" => "RJ",
54
+ "neighborhood" => "bairro",
55
+ "zipcode" => "12312-123",
56
+ "address_number" => "111",
57
+ "address_complement" => "Sala 4",
58
+ "phone_number" => "2112123434"
59
+ }
60
+ end
61
+
62
+ def create_customer
63
+ client.create_customer({
64
+ "person_name" => "Joao da Silva",
65
+ "cnpj_cpf"=> "012.345.678-90",
66
+ "email" => "cliente@bom.com",
67
+ "address" => "Rua quinhentos",
68
+ "city_name" => "Rio de Janeiro",
69
+ "state" => "RJ",
70
+ "neighborhood" => "bairro",
71
+ "zipcode" => "12312-123",
72
+ "address_number" => "111",
73
+ "address_complement" => "Sala 4",
74
+ "phone_number" => "2112123434"
75
+ })
76
+ end
77
+
78
+ it { expect(create_customer).to eq(payload) }
79
+ end
80
+
81
+ context 'with invalid data', vcr: { cassette_name: 'BoletoSimples_Client/_create_customer/with_invalid_data' } do
82
+ let(:payload) do
83
+ {
84
+ "errors" => {
85
+ "cnpj_cpf" => ["não pode ficar em branco"],
86
+ "phone_number" => ["é muito curto (mínimo: 10 caracteres)"]
87
+ }
88
+ }
89
+ end
90
+
91
+ def create_customer
92
+ client.create_customer({
93
+ "person_name" => "Joao da Silva",
94
+ "cnpj_cpf"=> "foo",
95
+ "email" => "cliente@bom.com",
96
+ "address" => "Rua quinhentos",
97
+ "city_name" => "Rio de Janeiro",
98
+ "state" => "RJ",
99
+ "neighborhood" => "bairro",
100
+ "zipcode" => "123",
101
+ "address_number" => "111",
102
+ "address_complement" => "Sala 4",
103
+ "phone_number" => "2123434"
104
+ })
105
+ end
106
+
107
+ it { expect(create_customer).to eq(payload) }
108
+ end
109
+ end
110
+
111
+ describe '#customers', vcr: { cassette_name: 'BoletoSimples_Client/_customers' } do
112
+ let(:customer) do
113
+ {"id"=>32,
114
+ "city_name" => "Rio de Janeiro",
115
+ "person_name" => "Joao da Silva",
116
+ "address" => "Rua quinhentos",
117
+ "address_complement" => "Sala 4",
118
+ "address_number" => "111",
119
+ "mobile_number" => nil,
120
+ "cnpj_cpf" => "012.345.678-90",
121
+ "email" => "cliente@bom.com",
122
+ "neighborhood" => "bairro",
123
+ "person_type" => "individual",
124
+ "phone_number" => "2112123434",
125
+ "zipcode" => "12312-123",
126
+ "mobile_local_code" => nil,
127
+ "state" => "RJ"
128
+ }
129
+ end
130
+
131
+ it { expect(client.customers).to eq([customer]) }
132
+ end
133
+
134
+ describe '#customer' do
135
+
136
+ context "not found", vcr: { cassette_name: 'BoletoSimples_Client/_customer/not_found' } do
137
+ it { expect(client.customer(42)).to eq({"status"=>404, "error"=>"Not Found"}) }
138
+ end
139
+
140
+ context "existing customer", vcr: { cassette_name: 'BoletoSimples_Client/_customer/existing_customer' } do
141
+ let(:customer) do
142
+ {
143
+ "id"=>32,
144
+ "city_name" => "Rio de Janeiro",
145
+ "person_name" => "Joao da Silva",
146
+ "address" => "Rua quinhentos",
147
+ "address_complement" => "Sala 4",
148
+ "address_number" => "111",
149
+ "mobile_number" => nil,
150
+ "cnpj_cpf" => "012.345.678-90",
151
+ "email" => "cliente@bom.com",
152
+ "neighborhood" => "bairro",
153
+ "person_type" => "individual",
154
+ "phone_number" => "2112123434",
155
+ "zipcode" => "12312-123",
156
+ "mobile_local_code" => nil,
157
+ "state" => "RJ"
158
+ }
159
+ end
160
+
161
+ it { expect(client.customer(32)).to eq(customer) }
162
+ end
163
+ end
164
+
165
+ describe '#create_bank_billet' do
166
+
167
+ context 'with valid data', vcr: { cassette_name: 'BoletoSimples_Client/_create_bank_billet/with_valid_data' } do
168
+ let(:payload) do
169
+ {
170
+ "amount" => 9.01,
171
+ "created_via_api" => true,
172
+ "customer_address" => "Rua quinhentos",
173
+ "customer_address_complement" => "Sala 4",
174
+ "customer_address_number" => "111",
175
+ "customer_city_name" => "Rio de Janeiro",
176
+ "customer_cnpj_cpf" => "012.345.678-90",
177
+ "customer_email" => "cliente@bom.com",
178
+ "customer_neighborhood" => "Sao Francisco",
179
+ "customer_person_name" => "Joao da Silva",
180
+ "customer_person_type" => "individual",
181
+ "customer_phone_number" => "2112123434",
182
+ "customer_state" => "RJ",
183
+ "customer_zipcode" => "12312-123",
184
+ "description" => "Despesas do contrato 0012",
185
+ "expire_at" => "2014-01-01",
186
+ "id" => 113,
187
+ "notification_url" => "http://example.com.br/notify",
188
+ "paid_amount" => 0.0,
189
+ "paid_at" => nil,
190
+ "send_email_on_creation" => nil,
191
+ "shorten_url" => nil,
192
+ "status" => "generating"
193
+ }
194
+ end
195
+
196
+ def create_bank_billet
197
+ client.create_bank_billet({
198
+ "amount" => 9.01,
199
+ "customer_address" => 'Rua quinhentos',
200
+ "customer_address_complement" => 'Sala 4',
201
+ "customer_address_number" => '111',
202
+ "customer_city_name" => 'Rio de Janeiro',
203
+ "customer_cnpj_cpf" => '012.345.678-90',
204
+ "customer_email" => 'cliente@bom.com',
205
+ "customer_neighborhood" => 'Sao Francisco',
206
+ "customer_person_name" => 'Joao da Silva',
207
+ "customer_person_type" => 'individual',
208
+ "customer_phone_number" => '2112123434',
209
+ "customer_state" => 'RJ',
210
+ "customer_zipcode" => '12312-123',
211
+ "description" => 'Despesas do contrato 0012',
212
+ "expire_at" => '2014-01-01',
213
+ "notification_url" => 'http://example.com.br/notify'
214
+ })
215
+ end
216
+
217
+ it { expect(create_bank_billet).to eq(payload) }
218
+ end
219
+
220
+ context 'with invalid data', vcr: { cassette_name: 'BoletoSimples_Client/_create_bank_billet/with_invalid_data' } do
221
+ let(:payload) do
222
+ {
223
+ "errors"=> {
224
+ "customer_cnpj_cpf" => ["não pode ficar em branco"],
225
+ "customer_email" => ["não é válido"],
226
+ "customer" => [
227
+ {
228
+ "cnpj_cpf" => ["não pode ficar em branco"],
229
+ "phone_number" => ["é muito curto (mínimo: 10 caracteres)"],
230
+ "email" => ["não é válido"]
231
+ }
232
+ ],
233
+ "amount"=>["deve ser menor ou igual a 10"]
234
+ }
235
+ }
236
+ end
237
+
238
+ def create_bank_billet
239
+ client.create_bank_billet({
240
+ "amount" => 19.01,
241
+ "customer_address" => 'Rua quinhentos',
242
+ "customer_address_complement" => 'Sala 4',
243
+ "customer_address_number" => '111',
244
+ "customer_city_name" => 'Rio de Janeiro',
245
+ "customer_cnpj_cpf" => '34567890',
246
+ "customer_email" => 'cliente',
247
+ "customer_neighborhood" => 'Sao Francisco',
248
+ "customer_person_name" => 'Joao da Silva',
249
+ "customer_person_type" => 'individual',
250
+ "customer_phone_number" => '123434',
251
+ "customer_state" => 'RJ',
252
+ "customer_zipcode" => '12312',
253
+ "description" => 'Despesas do contrato 0012',
254
+ "expire_at" => '2014-01-01',
255
+ "notification_url" => 'http://example.com.br/notify'
256
+ })
257
+ end
258
+
259
+ it { expect(create_bank_billet).to eq(payload) }
260
+ end
261
+ end
262
+
263
+ describe '#bank_billets', vcr: { cassette_name: 'BoletoSimples_Client/_bank_billets' } do
264
+ let(:bank_billet) do
265
+ {
266
+ "id"=>113,
267
+ "expire_at"=>"2014-01-01",
268
+ "paid_at"=>nil,
269
+ "description"=>"Despesas do contrato 0012",
270
+ "status"=>"opened",
271
+ "shorten_url"=>"http://staging.bole.to/nhhvauui",
272
+ "customer_person_type"=>"individual",
273
+ "customer_person_name"=>"Joao da Silva",
274
+ "customer_cnpj_cpf"=>"012.345.678-90",
275
+ "customer_address"=>"Rua quinhentos",
276
+ "customer_state"=>"RJ",
277
+ "customer_neighborhood"=>"Sao Francisco",
278
+ "customer_zipcode"=>"12312-123",
279
+ "customer_address_number"=>"111",
280
+ "customer_address_complement"=>"Sala 4",
281
+ "customer_phone_number"=>"2112123434",
282
+ "customer_email"=>"cliente@bom.com",
283
+ "notification_url"=>"http://example.com.br/notify",
284
+ "send_email_on_creation"=>nil,
285
+ "created_via_api"=>true,
286
+ "customer_city_name"=>"Rio de Janeiro",
287
+ "paid_amount"=>0.0,
288
+ "amount"=>9.01
289
+ }
290
+ end
291
+
292
+ it { expect(client.bank_billets).to eq([bank_billet]) }
293
+ end
294
+
295
+ describe '#bank_billet' do
296
+ context 'not found', vcr: { cassette_name: 'BoletoSimples_Client/_bank_billet/not_found' } do
297
+ it { expect(client.bank_billet(4324)).to eq({ "status"=>"404", "error"=>"Not Found" }) }
298
+ end
299
+
300
+ context 'existing bank billet', vcr: { cassette_name: 'BoletoSimples_Client/_bank_billet/existing_bank_billet' } do
301
+ let(:bank_billet) do
302
+ {
303
+ "id"=>113,
304
+ "expire_at"=>"2014-01-01",
305
+ "paid_at"=>nil,
306
+ "description"=>"Despesas do contrato 0012",
307
+ "status"=>"opened",
308
+ "shorten_url"=>"http://staging.bole.to/nhhvauui",
309
+ "customer_person_type"=>"individual",
310
+ "customer_person_name"=>"Joao da Silva",
311
+ "customer_cnpj_cpf"=>"012.345.678-90",
312
+ "customer_address"=>"Rua quinhentos",
313
+ "customer_state"=>"RJ",
314
+ "customer_neighborhood"=>"Sao Francisco",
315
+ "customer_zipcode"=>"12312-123",
316
+ "customer_address_number"=>"111",
317
+ "customer_address_complement"=>"Sala 4",
318
+ "customer_phone_number"=>"2112123434",
319
+ "customer_email"=>"cliente@bom.com",
320
+ "notification_url"=>"http://example.com.br/notify",
321
+ "send_email_on_creation"=>nil,
322
+ "created_via_api"=>true,
323
+ "customer_city_name"=>"Rio de Janeiro",
324
+ "paid_amount"=>0.0,
325
+ "amount"=>9.01
326
+ }
327
+ end
328
+
329
+ it { expect(client.bank_billet(113)).to eq(bank_billet) }
330
+ end
331
+ end
332
+
333
+ describe '#cancel_bank_billet' do
334
+ context 'with valid bank billet', vcr: { cassette_name: 'BoletoSimples_Client/_cancel_bank_billet/with_valid_bank_billet' } do
335
+ let(:canceled_bank_billet) do
336
+ {
337
+ "amount" => 10.0,
338
+ "created_via_api" => false,
339
+ "customer_address" => "Rua José Scheuer",
340
+ "customer_address_complement" => "",
341
+ "customer_address_number" => "12",
342
+ "customer_city_name" => "Jaraguá do Sul",
343
+ "customer_cnpj_cpf" => "33.368.751/0001-14",
344
+ "customer_email" => "foo@bar.com",
345
+ "customer_neighborhood" => "Amizade",
346
+ "customer_person_name" => "marcio junior",
347
+ "customer_person_type" => "juridical",
348
+ "customer_phone_number" => "",
349
+ "customer_state" => "SC",
350
+ "customer_zipcode" => "89255-800",
351
+ "description" => "foo",
352
+ "expire_at" => "2014-10-19",
353
+ "id" => 245,
354
+ "notification_url" => nil,
355
+ "paid_amount" => 0.0,
356
+ "paid_at" => nil,
357
+ "send_email_on_creation" => nil,
358
+ "shorten_url" => "http://staging.bole.to/ni8jav1w",
359
+ "status" => "canceled"
360
+ }
361
+ end
362
+
363
+ it{ expect(client.cancel_bank_billet(245)).to eq(canceled_bank_billet) }
364
+ end
365
+
366
+ context 'with invalid bank billet', vcr: { cassette_name: 'BoletoSimples_Client/_cancel_bank_billet/with_invalid_bank_billet' } do
367
+ let(:error) do
368
+ {"errors"=>{"status"=>["cannot transition via cancel"]}}
369
+ end
370
+
371
+ it{ expect(client.cancel_bank_billet(113)).to eq(error) }
372
+ end
373
+
374
+ context 'already canceled', vcr: { cassette_name: 'BoletoSimples_Client/_cancel_bank_billet/already_canceled' } do
375
+ let(:error) do
376
+ {"errors"=>{"status"=>["cannot transition via cancel"]}}
377
+ end
378
+
379
+ it{ expect(client.cancel_bank_billet(245)).to eq(error) }
380
+ end
381
+
382
+ end
383
+
384
+ describe '#transactions', vcr: { cassette_name: 'BoletoSimples_Client/_transactions' } do
385
+ let(:credit_tx) do
386
+ {
387
+ "id"=>15,
388
+ "amount"=>9.01,
389
+ "created_at"=>"2014-11-03",
390
+ "description"=>"Boleto Bancário 113",
391
+ "kind"=>"credit",
392
+ "processed_at"=>nil,
393
+ "sent_at"=>nil,
394
+ "status"=>"unprocessed",
395
+ "credit_at"=>"2014-11-06"
396
+ }
397
+ end
398
+
399
+ let(:fee_tx) do
400
+ {
401
+ "id"=>16,
402
+ "amount"=>-5.0,
403
+ "created_at"=>"2014-11-03",
404
+ "description"=>"Boleto Bancário 113",
405
+ "kind"=>"fee",
406
+ "processed_at"=>nil,
407
+ "sent_at"=>nil,
408
+ "status"=>"unprocessed",
409
+ "credit_at"=>"2014-11-06"
410
+ }
411
+ end
412
+
413
+ it { expect(client.transactions).to match_array([fee_tx, credit_tx]) }
11
414
  end
12
415
  end