boletosimples 0.0.7 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (68) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +1 -1
  3. data/README.md +156 -3
  4. data/boletosimples.gemspec +9 -9
  5. data/lib/boletosimples.rb +38 -4
  6. data/lib/boletosimples/configuration.rb +69 -0
  7. data/lib/boletosimples/extra.rb +8 -0
  8. data/lib/boletosimples/last_request.rb +43 -0
  9. data/lib/boletosimples/middlewares/last_request.rb +9 -0
  10. data/lib/boletosimples/middlewares/raise_error.rb +11 -0
  11. data/lib/boletosimples/middlewares/user_agent.rb +10 -0
  12. data/lib/boletosimples/resources/bank_billet.rb +13 -0
  13. data/lib/boletosimples/resources/base_model.rb +8 -0
  14. data/lib/boletosimples/resources/customer.rb +4 -0
  15. data/lib/boletosimples/resources/partner/user.rb +7 -0
  16. data/lib/boletosimples/resources/transaction.rb +4 -0
  17. data/lib/boletosimples/response_error.rb +43 -0
  18. data/lib/boletosimples/version.rb +1 -1
  19. data/spec/boletosimples/configuration_spec.rb +84 -0
  20. data/spec/boletosimples/extra_spec.rb +31 -0
  21. data/spec/boletosimples/last_request_spec.rb +34 -0
  22. data/spec/boletosimples/resources/bank_billet_spec.rb +75 -0
  23. data/spec/boletosimples/resources/customer_spec.rb +66 -0
  24. data/spec/boletosimples/resources/partner/user_spec.rb +19 -0
  25. data/spec/boletosimples/resources/transactions_spec.rb +17 -0
  26. data/spec/fixtures/vcr_cassettes/configuration/client_credentials/invalid.yml +64 -0
  27. data/spec/fixtures/vcr_cassettes/configuration/client_credentials/valid.yml +56 -0
  28. data/spec/fixtures/vcr_cassettes/extra/userinfo/authenticated.yml +58 -0
  29. data/spec/fixtures/vcr_cassettes/extra/userinfo/not_authenticated.yml +54 -0
  30. data/spec/fixtures/vcr_cassettes/last_request/bank_billets.yml +129 -0
  31. data/spec/fixtures/vcr_cassettes/last_request/userinfo.yml +58 -0
  32. data/spec/fixtures/vcr_cassettes/resources/bank_billet/all.yml +132 -0
  33. data/spec/fixtures/vcr_cassettes/resources/bank_billet/cancel.yml +125 -0
  34. data/spec/fixtures/vcr_cassettes/resources/bank_billet/create/invalid_params.yml +61 -0
  35. data/spec/fixtures/vcr_cassettes/{BoletoSimples_Client/_cancel_bank_billet/already_canceled.yml → resources/bank_billet/create/invalid_root.yml} +24 -24
  36. data/spec/fixtures/vcr_cassettes/{BoletoSimples_Client/_create_bank_billet/with_valid_data.yml → resources/bank_billet/create/valid.yml} +32 -28
  37. data/spec/fixtures/vcr_cassettes/{BoletoSimples_Client/_bank_billet/existing_bank_billet.yml → resources/bank_billet/find.yml} +30 -28
  38. data/spec/fixtures/vcr_cassettes/resources/customer/all.yml +72 -0
  39. data/spec/fixtures/vcr_cassettes/resources/customer/create/invalid_params.yml +59 -0
  40. data/spec/fixtures/vcr_cassettes/resources/customer/create/invalid_root.yml +58 -0
  41. data/spec/fixtures/vcr_cassettes/{BoletoSimples_Client/_create_customer/with_valid_data.yml → resources/customer/create/valid.yml} +30 -26
  42. data/spec/fixtures/vcr_cassettes/resources/customer/find.yml +59 -0
  43. data/spec/fixtures/vcr_cassettes/resources/partner/user/create.yml +60 -0
  44. data/spec/fixtures/vcr_cassettes/resources/transaction/all.yml +62 -0
  45. data/spec/spec_helper.rb +10 -0
  46. data/spec/support/vcr.rb +8 -0
  47. metadata +97 -80
  48. data/example/access_token_example.rb +0 -79
  49. data/example/oauth_example.rb +0 -126
  50. data/lib/boletosimples/client.rb +0 -100
  51. data/lib/boletosimples/oauth_client.rb +0 -74
  52. data/spec/boletosimples/client_spec.rb +0 -415
  53. data/spec/boletosimples/oauth_client_spec.rb +0 -17
  54. data/spec/fixtures/vcr_cassettes/BoletoSimples_Client/_bank_billet/not_found.yml +0 -44
  55. data/spec/fixtures/vcr_cassettes/BoletoSimples_Client/_bank_billets.yml +0 -63
  56. data/spec/fixtures/vcr_cassettes/BoletoSimples_Client/_cancel_bank_billet/with_invalid_bank_billet.yml +0 -54
  57. data/spec/fixtures/vcr_cassettes/BoletoSimples_Client/_cancel_bank_billet/with_valid_bank_billet.yml +0 -71
  58. data/spec/fixtures/vcr_cassettes/BoletoSimples_Client/_create_bank_billet/with_invalid_data.yml +0 -64
  59. data/spec/fixtures/vcr_cassettes/BoletoSimples_Client/_create_customer/with_invalid_data.yml +0 -59
  60. data/spec/fixtures/vcr_cassettes/BoletoSimples_Client/_customer/existing_customer.yml +0 -57
  61. data/spec/fixtures/vcr_cassettes/BoletoSimples_Client/_customer/not_found.yml +0 -58
  62. data/spec/fixtures/vcr_cassettes/BoletoSimples_Client/_customers.yml +0 -59
  63. data/spec/fixtures/vcr_cassettes/BoletoSimples_Client/_transactions.yml +0 -67
  64. data/spec/fixtures/vcr_cassettes/BoletoSimples_Client/_userinfo/with_authentication.yml +0 -56
  65. data/spec/fixtures/vcr_cassettes/BoletoSimples_Client/_userinfo/with_authentication/.yml +0 -56
  66. data/spec/fixtures/vcr_cassettes/BoletoSimples_Client/_userinfo/without_authentication.yml +0 -54
  67. data/spec/fixtures/vcr_cassettes/BoletoSimples_Client/_userinfo/without_authentication/.yml +0 -54
  68. data/spec/fixtures/vcr_cassettes/BoletoSimples_OAuthClient/_userinfo/without_authentication/.yml +0 -62
@@ -1,100 +0,0 @@
1
- require 'httparty'
2
- require 'multi_json'
3
-
4
- module BoletoSimples
5
- class Client
6
- include HTTParty
7
-
8
- PRODUCTION_BASE_URI = 'https://boletosimples.com.br/api/v1'
9
- SANDBOX_BASE_URI = 'https://sandbox.boletosimples.com.br/api/v1'
10
-
11
- def initialize(access_token, options = {})
12
- @access_token = access_token
13
-
14
- # defaults
15
- @production = options.delete(:production)
16
- @base_uri = options[:base_uri] || (@production ? PRODUCTION_BASE_URI : SANDBOX_BASE_URI)
17
- @user_agent = options.delete(:user_agent)
18
-
19
- options[:format] ||= :json
20
- options.each do |k, v|
21
- self.class.send k, v
22
- end
23
- end
24
-
25
- # Users
26
- def userinfo(options = {})
27
- get '/userinfo', options
28
- end
29
-
30
- # Transactions
31
- def transactions(page = 1, options = {})
32
- get '/transactions', { page: page }.merge(options)
33
- end
34
-
35
- # Customers
36
- def customers(page = 1, options = {})
37
- get '/customers', { page: page }.merge(options)
38
- end
39
-
40
- def create_customer(options = {})
41
- post '/customers', customer: options
42
- end
43
-
44
- def customer(id = 1, options = {})
45
- get "/customers/#{id}", options
46
- end
47
-
48
- # Bank Billets
49
- def bank_billets(page = 1, options = {})
50
- get '/bank_billets', { page: page }.merge(options)
51
- end
52
-
53
- def create_bank_billet(options = {})
54
- post '/bank_billets', bank_billet: options
55
- end
56
-
57
- def bank_billet(id, options = {})
58
- get "/bank_billets/#{id}", options
59
- end
60
-
61
- def cancel_bank_billet(id, options = {})
62
- put "/bank_billets/#{id}/cancel", options
63
- end
64
-
65
- # Wrappers for the main HTTP verbs
66
- def get(path, options = {})
67
- http_verb :get, path, options
68
- end
69
-
70
- def post(path, options = {})
71
- http_verb :post, path, options
72
- end
73
-
74
- def put(path, options = {})
75
- http_verb :put, path, options
76
- end
77
-
78
- def patch(path, options = {})
79
- http_verb :patch, path, options
80
- end
81
-
82
- def delete(path, options = {})
83
- http_verb :delete, path, options
84
- end
85
-
86
- def http_verb(verb, path, options = {})
87
- request_options = { body: options.to_json }
88
- request_options[:headers] = {
89
- 'Content-Type' => 'application/json',
90
- 'User-Agent' => @user_agent
91
- }
92
- request_options[:query] ||= {}
93
- request_options[:query].merge!(access_token: @access_token)
94
-
95
- uri = "#{@base_uri}#{path}"
96
- response = self.class.send(verb, uri, request_options)
97
- JSON.parse(response.body)
98
- end
99
- end
100
- end
@@ -1,74 +0,0 @@
1
- require 'oauth2'
2
-
3
- module BoletoSimples
4
- class OAuthClient < Client
5
- # Initializes a BoletoSimples Client using OAuth 2.0 credentials
6
- #
7
- # @param [String] client_id this application's BoletoSimples OAuth2 CLIENT_ID
8
- # @param [String] client_secret this application's BoletoSimples OAuth2 CLIENT_SECRET
9
- # @param [Hash] user_credentials OAuth 2.0 credentials to use
10
- # @option user_credentials [String] access_token Must pass either this or token
11
- # @option user_credentials [String] token Must pass either this or access_token
12
- # @option user_credentials [String] refresh_token Optional
13
- # @option user_credentials [Integer] expires_at Optional
14
- # @option user_credentials [Integer] expires_in Optional
15
- #
16
- # Please note access tokens will be automatically refreshed when expired
17
- # Use the credentials method when finished with the client to retrieve up-to-date credentials
18
- def initialize(client_id, client_secret, user_credentials, options = {})
19
- @production = options.delete(:production)
20
- @base_uri = options[:base_uri] || (@production ? PRODUCTION_BASE_URI : SANDBOX_BASE_URI)
21
- client_opts = {
22
- site: @base_uri,
23
- authorize_url: options[:authorize_url] || "#{@base_uri}/oauth/authorize",
24
- token_url: options[:token_url] || "#{@base_uri}/oauth/token",
25
- raise_errors: false
26
- }
27
- @user_agent = options.delete(:user_agent)
28
- @oauth_client = OAuth2::Client.new(client_id, client_secret, client_opts)
29
- token_hash = user_credentials.dup
30
- token_hash[:access_token] ||= token_hash[:token]
31
- token_hash.delete :expires
32
- fail 'No access token provided' unless token_hash[:access_token]
33
- @oauth_token = OAuth2::AccessToken.from_hash(@oauth_client, token_hash)
34
- end
35
-
36
- # Users
37
- def partner_create_user(options = {})
38
- post '/partner/users', options
39
- end
40
-
41
- def http_verb(verb, path, options = {})
42
- path = remove_leading_slash(path)
43
- request_options = { headers: {
44
- 'Accept-Charset' => 'UTF-8',
45
- 'Content-Type' => 'application/json',
46
- 'User-Agent' => @user_agent
47
- }, body: options.to_json }
48
-
49
- response = oauth_token.request(verb, path, request_options)
50
- JSON.parse(response.body)
51
- end
52
-
53
- def refresh!
54
- fail 'Access token not initialized.' unless @oauth_token
55
- @oauth_token = @oauth_token.refresh!
56
- end
57
-
58
- def oauth_token
59
- fail 'Access token not initialized.' unless @oauth_token
60
- refresh! if @oauth_token.expired?
61
- @oauth_token
62
- end
63
-
64
- def credentials
65
- @oauth_token.to_hash
66
- end
67
-
68
- private
69
-
70
- def remove_leading_slash(path)
71
- path.sub(/^\//, '')
72
- end
73
- end
74
- end
@@ -1,415 +0,0 @@
1
- # encoding: UTF-8
2
-
3
- require 'spec_helper'
4
-
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
-
16
- it { expect(client.userinfo).to eq('error' => 'Você precisa se logar ou registrar antes de prosseguir.') }
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]) }
414
- end
415
- end