boletoman 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +15 -0
- data/.rspec +3 -0
- data/.travis.yml +5 -0
- data/CHANGELOG.md +3 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +21 -0
- data/README.md +79 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/boletoman.gemspec +33 -0
- data/lib/boletoman.rb +6 -0
- data/lib/boletoman/builders/base.rb +28 -0
- data/lib/boletoman/builders/formatter.rb +91 -0
- data/lib/boletoman/builders/itau.rb +49 -0
- data/lib/boletoman/builders/itau_formatter.rb +11 -0
- data/lib/boletoman/config.rb +38 -0
- data/lib/boletoman/services/itau/boleto/formatter.rb +137 -0
- data/lib/boletoman/services/itau/boleto/request.rb +57 -0
- data/lib/boletoman/services/itau/boleto/response.rb +32 -0
- data/lib/boletoman/services/itau/token/cache.rb +36 -0
- data/lib/boletoman/services/itau/token/request.rb +53 -0
- data/lib/boletoman/services/itau/token/response.rb +23 -0
- data/lib/boletoman/version.rb +3 -0
- metadata +183 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 997b37503c6a648aa7c7f0fd7aa2137f5fa3d11f
|
4
|
+
data.tar.gz: e8a0330ed40f5721330627cc10c1151872693331
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 6b38e581a09878d7be7e8cd2ec231f151d5dec54b4947821d5b3b60eba12eac8ee8f71d0139b844e02d31fb38e77f8b150f2cbb6174927e2b9bdb540a7f102ba
|
7
|
+
data.tar.gz: f5722d559bb084012edd8d8e7da56ba11f9f55c13eadf79d0e280f85562d52b74c8a818b58d30815602d86bce3a0ad871240284042bb218943d73985ad58fc4c
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CHANGELOG.md
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2018 Glauco Custódio
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
# Boletoman
|
2
|
+
|
3
|
+
[](https://travis-ci.org/glaucocustodio/boletoman)
|
4
|
+
|
5
|
+
Gema responsável por gerar boletos em pdf para bancos brasileiros que requerem chamada a serviços web para obter o código de barras previamente. Bancos suportados no momento:
|
6
|
+
|
7
|
+
- Itaú (API de Registro de Cobrança)
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
Adicione a linha no seu Gemfile
|
12
|
+
|
13
|
+
```ruby
|
14
|
+
gem 'boletoman'
|
15
|
+
```
|
16
|
+
|
17
|
+
Execute:
|
18
|
+
|
19
|
+
$ bundle
|
20
|
+
|
21
|
+
Ou instale você mesmo:
|
22
|
+
|
23
|
+
$ gem install boletoman
|
24
|
+
|
25
|
+
## Uso
|
26
|
+
|
27
|
+
### Itau
|
28
|
+
|
29
|
+
```ruby
|
30
|
+
builder = Boletoman::Builders::Itau.new({
|
31
|
+
# dados do cedente
|
32
|
+
transferor: {
|
33
|
+
name: 'EMPRESA CEDENTE LTDA',
|
34
|
+
document: '86.521.120/0001-50', # cnpj
|
35
|
+
branch: '0036', # agencia
|
36
|
+
checking_account: '119097', # conta
|
37
|
+
wallet: '109', # carteira
|
38
|
+
},
|
39
|
+
# dados do pagador
|
40
|
+
payer: {
|
41
|
+
document: '714.295.500-74', # cpf
|
42
|
+
name: 'JOSE SILVA',
|
43
|
+
street: 'Rua Edson Pereira Dias, 123',
|
44
|
+
city: 'Sumaré',
|
45
|
+
state: 'SP',
|
46
|
+
zip_code: '17535-004',
|
47
|
+
},
|
48
|
+
# dados do boleto
|
49
|
+
boleto: {
|
50
|
+
due_date: Date.new(2018, 12, 20),
|
51
|
+
nosso_numero: '10030033',
|
52
|
+
value: 520.80,
|
53
|
+
}
|
54
|
+
})
|
55
|
+
|
56
|
+
pdf = builder.build
|
57
|
+
|
58
|
+
IO.binwrite('boleto.pdf', pdf) # salva binário no arquivo
|
59
|
+
```
|
60
|
+
|
61
|
+
## Desenvolvimento
|
62
|
+
|
63
|
+
### Testes
|
64
|
+
|
65
|
+
`rake spec`
|
66
|
+
|
67
|
+
### Console
|
68
|
+
|
69
|
+
`bundle console`
|
70
|
+
|
71
|
+
### Release
|
72
|
+
|
73
|
+
Atualize o número da versão em `version.rb` e rode:
|
74
|
+
|
75
|
+
`bundle exec rake release`
|
76
|
+
|
77
|
+
## License
|
78
|
+
|
79
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "boletoman"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/boletoman.gemspec
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "boletoman/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "boletoman"
|
8
|
+
spec.version = Boletoman::VERSION
|
9
|
+
spec.authors = ["Glauco Custódio"]
|
10
|
+
spec.email = ["glauco.custodio@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Gema responsável por gerar boletos em pdf para bancos brasileiros que requerem chamada a serviços web para obter o código de barras previamente.}
|
13
|
+
spec.description = %q{Gema responsável por gerar boletos em pdf para bancos brasileiros que requerem chamada a serviços web para obter o código de barras previamente.}
|
14
|
+
spec.homepage = "https://github.com/glaucocustodio/boletoman"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
18
|
+
f.match(%r{^(test|spec|features)/})
|
19
|
+
end
|
20
|
+
spec.bindir = "exe"
|
21
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
22
|
+
spec.require_paths = ["lib"]
|
23
|
+
|
24
|
+
spec.add_development_dependency "bundler", "~> 1.16"
|
25
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
26
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
27
|
+
spec.add_development_dependency "webmock"
|
28
|
+
spec.add_development_dependency "fakeredis"
|
29
|
+
|
30
|
+
spec.add_dependency 'faraday'
|
31
|
+
spec.add_dependency 'activesupport'
|
32
|
+
spec.add_dependency 'bbrcobranca'
|
33
|
+
end
|
data/lib/boletoman.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
module Boletoman
|
2
|
+
module Builders
|
3
|
+
class Base
|
4
|
+
attr_reader :data
|
5
|
+
|
6
|
+
def initialize(data)
|
7
|
+
@data = data
|
8
|
+
end
|
9
|
+
|
10
|
+
def build
|
11
|
+
instance.to_pdf
|
12
|
+
end
|
13
|
+
|
14
|
+
def instance
|
15
|
+
raise NotImplementedError
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.generator
|
19
|
+
to_s.demodulize.downcase
|
20
|
+
end
|
21
|
+
|
22
|
+
# segunda via
|
23
|
+
def duplicate?
|
24
|
+
data.dig(:boleto, :duplicate) == true
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,91 @@
|
|
1
|
+
require 'active_support/all'
|
2
|
+
|
3
|
+
module Boletoman
|
4
|
+
module Builders
|
5
|
+
class Formatter
|
6
|
+
attr_accessor :raw
|
7
|
+
|
8
|
+
def initialize(raw)
|
9
|
+
@raw = raw
|
10
|
+
end
|
11
|
+
|
12
|
+
def transferor_name
|
13
|
+
raw[:transferor][:name]
|
14
|
+
end
|
15
|
+
|
16
|
+
def transferor_document
|
17
|
+
raw[:transferor][:document]
|
18
|
+
end
|
19
|
+
|
20
|
+
def covenant
|
21
|
+
raw[:transferor][:covenant]
|
22
|
+
end
|
23
|
+
|
24
|
+
def branch
|
25
|
+
raw[:transferor][:branch]
|
26
|
+
end
|
27
|
+
|
28
|
+
def checking_account
|
29
|
+
raw[:transferor][:checking_account]
|
30
|
+
end
|
31
|
+
|
32
|
+
def wallet
|
33
|
+
raw[:transferor][:wallet]
|
34
|
+
end
|
35
|
+
|
36
|
+
def issue_date
|
37
|
+
raw.dig(:boleto, :issue_date) || Date.today
|
38
|
+
end
|
39
|
+
|
40
|
+
def payer_name
|
41
|
+
raw[:payer][:name]
|
42
|
+
end
|
43
|
+
|
44
|
+
def payer_document
|
45
|
+
raw[:payer][:document]
|
46
|
+
end
|
47
|
+
|
48
|
+
def payer_address
|
49
|
+
full_address_for(raw[:payer])
|
50
|
+
end
|
51
|
+
|
52
|
+
def value
|
53
|
+
format('%1.2f', raw_value)
|
54
|
+
end
|
55
|
+
|
56
|
+
def due_date
|
57
|
+
raw[:boleto][:due_date]
|
58
|
+
end
|
59
|
+
|
60
|
+
def instruction1
|
61
|
+
raw[:boleto][:instruction1]
|
62
|
+
end
|
63
|
+
|
64
|
+
def instruction2
|
65
|
+
raw[:boleto][:instruction2]
|
66
|
+
end
|
67
|
+
|
68
|
+
def instruction3
|
69
|
+
raw[:boleto][:instruction3]
|
70
|
+
end
|
71
|
+
|
72
|
+
def nosso_numero
|
73
|
+
raw[:boleto][:nosso_numero]
|
74
|
+
end
|
75
|
+
|
76
|
+
private
|
77
|
+
|
78
|
+
def full_address_for(payer)
|
79
|
+
%(
|
80
|
+
#{payer[:street]}, #{payer[:number]},
|
81
|
+
#{payer[:neighborhood]} - #{payer[:city]} /
|
82
|
+
#{payer[:state]} - #{payer[:zip_code]}
|
83
|
+
).squish
|
84
|
+
end
|
85
|
+
|
86
|
+
def raw_value
|
87
|
+
raw[:boleto][:value]
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'boletoman/services/itau/boleto/request'
|
2
|
+
require_relative 'base'
|
3
|
+
require_relative 'itau_formatter'
|
4
|
+
require "bbrcobranca"
|
5
|
+
|
6
|
+
module Boletoman
|
7
|
+
module Builders
|
8
|
+
class Itau < Base
|
9
|
+
def instance
|
10
|
+
@instance ||= ::Bbrcobranca::Boleto::Itau.new(
|
11
|
+
carteira: formatter.wallet,
|
12
|
+
agencia: formatter.branch,
|
13
|
+
conta_corrente: formatter.checking_account,
|
14
|
+
cedente: formatter.transferor_name,
|
15
|
+
documento_cedente: formatter.transferor_document,
|
16
|
+
data_documento: formatter.issue_date,
|
17
|
+
data_processamento: formatter.issue_date,
|
18
|
+
sacado: formatter.payer_name,
|
19
|
+
sacado_documento: formatter.payer_document,
|
20
|
+
sacado_endereco: formatter.payer_address,
|
21
|
+
valor: formatter.value,
|
22
|
+
data_vencimento: formatter.due_date,
|
23
|
+
aceite: 'N',
|
24
|
+
codigo_barras: barcode,
|
25
|
+
nosso_numero: nosso_numero,
|
26
|
+
instrucao3: formatter.instruction3
|
27
|
+
)
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def formatter
|
33
|
+
@formatter ||= ItauFormatter.new(data)
|
34
|
+
end
|
35
|
+
|
36
|
+
def barcode
|
37
|
+
boleto_data.barcode
|
38
|
+
end
|
39
|
+
|
40
|
+
def nosso_numero
|
41
|
+
boleto_data.nosso_numero
|
42
|
+
end
|
43
|
+
|
44
|
+
def boleto_data
|
45
|
+
@boleto_data ||= ::Boletoman::Services::Itau::Boleto::Request.new(data).call
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module Boletoman
|
2
|
+
class << self
|
3
|
+
attr_accessor :configuration
|
4
|
+
end
|
5
|
+
|
6
|
+
def self.configure
|
7
|
+
self.configuration ||= Configuration.new
|
8
|
+
yield(configuration)
|
9
|
+
end
|
10
|
+
|
11
|
+
class Configuration
|
12
|
+
attr_accessor :env, :redis, :itau
|
13
|
+
|
14
|
+
def initialize
|
15
|
+
@env = :dev
|
16
|
+
end
|
17
|
+
|
18
|
+
def production_env?
|
19
|
+
env == :production
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
class ItauConfiguration
|
24
|
+
attr_accessor :token, :key, :identificator, :client_id, :client_secret
|
25
|
+
end
|
26
|
+
|
27
|
+
class Itau
|
28
|
+
class << self
|
29
|
+
attr_accessor :configuration
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.configure
|
33
|
+
self.configuration ||= ItauConfiguration.new
|
34
|
+
yield(configuration)
|
35
|
+
self
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,137 @@
|
|
1
|
+
module Boletoman
|
2
|
+
module Services
|
3
|
+
module Itau
|
4
|
+
module Boleto
|
5
|
+
class Formatter
|
6
|
+
attr_reader :data
|
7
|
+
|
8
|
+
def initialize(data)
|
9
|
+
@data = data
|
10
|
+
end
|
11
|
+
|
12
|
+
def format
|
13
|
+
{
|
14
|
+
tipo_ambiente: env,
|
15
|
+
tipo_registro: record_type,
|
16
|
+
tipo_cobranca: billing_type,
|
17
|
+
tipo_produto: '00006',
|
18
|
+
subproduto: '00008',
|
19
|
+
beneficiario: {
|
20
|
+
cpf_cnpj_beneficiario: transferor_document,
|
21
|
+
agencia_beneficiario: transferor_branch,
|
22
|
+
conta_beneficiario: transferor_account,
|
23
|
+
digito_verificador_conta_beneficiario: transferor_account_digit
|
24
|
+
},
|
25
|
+
titulo_aceite: 'N',
|
26
|
+
pagador: {
|
27
|
+
cpf_cnpj_pagador: payer_document,
|
28
|
+
nome_pagador: payer_name,
|
29
|
+
logradouro_pagador: payer_street,
|
30
|
+
cidade_pagador: payer_city,
|
31
|
+
uf_pagador: payer_state,
|
32
|
+
cep_pagador: payer_zip_code
|
33
|
+
},
|
34
|
+
tipo_carteira_titulo: wallet,
|
35
|
+
moeda: { codigo_moeda_cnab: '09' },
|
36
|
+
nosso_numero: nosso_numero,
|
37
|
+
digito_verificador_nosso_numero: nosso_numero_digit,
|
38
|
+
data_vencimento: due_date,
|
39
|
+
valor_cobrado: value,
|
40
|
+
especie: '01',
|
41
|
+
data_emissao: issue_date,
|
42
|
+
tipo_pagamento: 1,
|
43
|
+
indicador_pagamento_parcial: 'false',
|
44
|
+
juros: { tipo_juros: 5 },
|
45
|
+
multa: { tipo_multa: 3 },
|
46
|
+
grupo_desconto: [{ tipo_desconto: '0' }],
|
47
|
+
recebimento_divergente: { tipo_autorizacao_recebimento: '1' }
|
48
|
+
}.to_json
|
49
|
+
end
|
50
|
+
|
51
|
+
private
|
52
|
+
|
53
|
+
def env
|
54
|
+
::Boletoman.configuration.production_env? ? 2 : 1
|
55
|
+
end
|
56
|
+
|
57
|
+
def record_type
|
58
|
+
{ 'registro' => 1, 'alteracao' => 2, 'consulta' => 3 }['registro']
|
59
|
+
end
|
60
|
+
|
61
|
+
def billing_type
|
62
|
+
{
|
63
|
+
'boleto' => 1,
|
64
|
+
'debito automático' => 2,
|
65
|
+
'cartão de crédito' => 3,
|
66
|
+
'TEF reversa' => 4
|
67
|
+
}['boleto']
|
68
|
+
end
|
69
|
+
|
70
|
+
def transferor_document
|
71
|
+
data[:transferor][:document].remove(%r{[.\/-]})
|
72
|
+
end
|
73
|
+
|
74
|
+
def transferor_branch
|
75
|
+
data[:transferor][:branch].rjust(4, '0')
|
76
|
+
end
|
77
|
+
|
78
|
+
def transferor_account
|
79
|
+
data[:transferor][:checking_account][0..-2].rjust(7, '0')
|
80
|
+
end
|
81
|
+
|
82
|
+
def transferor_account_digit
|
83
|
+
data[:transferor][:checking_account].last
|
84
|
+
end
|
85
|
+
|
86
|
+
def wallet
|
87
|
+
data[:transferor][:wallet]
|
88
|
+
end
|
89
|
+
|
90
|
+
def payer_document
|
91
|
+
data[:payer][:document].remove(/[.-]/).rjust(11, '0')
|
92
|
+
end
|
93
|
+
|
94
|
+
def payer_name
|
95
|
+
data[:payer][:name].strip.first(30)
|
96
|
+
end
|
97
|
+
|
98
|
+
def payer_street
|
99
|
+
data[:payer][:street]
|
100
|
+
end
|
101
|
+
|
102
|
+
def payer_city
|
103
|
+
data[:payer][:city]
|
104
|
+
end
|
105
|
+
|
106
|
+
def payer_state
|
107
|
+
data[:payer][:state]
|
108
|
+
end
|
109
|
+
|
110
|
+
def payer_zip_code
|
111
|
+
data[:payer][:zip_code].remove(/[.-]/)
|
112
|
+
end
|
113
|
+
|
114
|
+
def due_date
|
115
|
+
data[:boleto][:due_date].to_s
|
116
|
+
end
|
117
|
+
|
118
|
+
def nosso_numero
|
119
|
+
data[:boleto][:nosso_numero].rjust(8, '0')
|
120
|
+
end
|
121
|
+
|
122
|
+
def nosso_numero_digit
|
123
|
+
"#{transferor_branch}#{transferor_account}#{wallet}#{nosso_numero}".modulo10
|
124
|
+
end
|
125
|
+
|
126
|
+
def value
|
127
|
+
(data[:boleto][:value].round(2) * 100).truncate.to_s.rjust(16, '0')
|
128
|
+
end
|
129
|
+
|
130
|
+
def issue_date
|
131
|
+
Date.today.to_s
|
132
|
+
end
|
133
|
+
end
|
134
|
+
end
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require_relative '../token/cache'
|
2
|
+
require_relative 'formatter'
|
3
|
+
require_relative 'response'
|
4
|
+
|
5
|
+
require "faraday"
|
6
|
+
|
7
|
+
module Boletoman
|
8
|
+
module Services
|
9
|
+
module Itau
|
10
|
+
module Boleto
|
11
|
+
class Request
|
12
|
+
attr_reader :data
|
13
|
+
|
14
|
+
def initialize(data)
|
15
|
+
@data = data
|
16
|
+
end
|
17
|
+
|
18
|
+
def call
|
19
|
+
Response.new(request).tap do |response|
|
20
|
+
raise "Falha ao gerar dados do boleto #{response.body}" if response.error?
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def request
|
27
|
+
::Faraday.new(url: url, headers: headers).send(:post) do |request|
|
28
|
+
request.body = body
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def url
|
33
|
+
'https://gerador-boletos.itau.com.br/router-gateway-app/public/codigo_barras/registro'
|
34
|
+
end
|
35
|
+
|
36
|
+
def body
|
37
|
+
Formatter.new(data).format
|
38
|
+
end
|
39
|
+
|
40
|
+
def headers
|
41
|
+
{
|
42
|
+
'Accept' => 'application/vnd.itau',
|
43
|
+
'Content-Type' => 'application/json',
|
44
|
+
'access_token' => token,
|
45
|
+
'itau-chave' => ::Boletoman.configuration.itau.configuration.key,
|
46
|
+
'identificador' => ::Boletoman.configuration.itau.configuration.identificator
|
47
|
+
}
|
48
|
+
end
|
49
|
+
|
50
|
+
def token
|
51
|
+
Boletoman::Services::Itau::Token::Cache.new.fetch
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module Boletoman
|
2
|
+
module Services
|
3
|
+
module Itau
|
4
|
+
module Boleto
|
5
|
+
class Response
|
6
|
+
attr_reader :status, :body
|
7
|
+
|
8
|
+
def initialize(raw)
|
9
|
+
@status = raw.status
|
10
|
+
@body = JSON.parse(raw.body)
|
11
|
+
end
|
12
|
+
|
13
|
+
def error?
|
14
|
+
status >= 400
|
15
|
+
end
|
16
|
+
|
17
|
+
def barcode
|
18
|
+
body['codigo_barras']
|
19
|
+
end
|
20
|
+
|
21
|
+
def line
|
22
|
+
body['numero_linha_digitavel']
|
23
|
+
end
|
24
|
+
|
25
|
+
def nosso_numero
|
26
|
+
body['nosso_numero'][0..-2] # remove the verificator digit
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require_relative 'request'
|
2
|
+
|
3
|
+
module Boletoman
|
4
|
+
module Services
|
5
|
+
module Itau
|
6
|
+
module Token
|
7
|
+
class Cache
|
8
|
+
KEY = 'boletoman-itau-token'.freeze
|
9
|
+
|
10
|
+
def fetch
|
11
|
+
get || set
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def get
|
17
|
+
redis.get(KEY)
|
18
|
+
end
|
19
|
+
|
20
|
+
def set
|
21
|
+
redis.set(KEY, request.token, ex: request.expires_in)
|
22
|
+
request.token
|
23
|
+
end
|
24
|
+
|
25
|
+
def request
|
26
|
+
@request ||= Request.new.call
|
27
|
+
end
|
28
|
+
|
29
|
+
def redis
|
30
|
+
@redis ||= ::Boletoman.configuration.redis
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require_relative 'response'
|
2
|
+
|
3
|
+
require "faraday"
|
4
|
+
|
5
|
+
module Boletoman
|
6
|
+
module Services
|
7
|
+
module Itau
|
8
|
+
module Token
|
9
|
+
class Request
|
10
|
+
def call
|
11
|
+
Response.new(request)
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def request
|
17
|
+
::Faraday.new(url: url, headers: headers).send(:post) do |request|
|
18
|
+
request.body = params
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def url
|
23
|
+
if ::Boletoman.configuration.production_env?
|
24
|
+
'https://autorizador-boletos.itau.com.br/'
|
25
|
+
else
|
26
|
+
'https://oauth.itau.com.br/identity/connect/token'
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def params
|
31
|
+
{ scope: 'readonly', grant_type: 'client_credentials' }
|
32
|
+
end
|
33
|
+
|
34
|
+
def headers
|
35
|
+
{ authorization: "Basic #{credentials}" }
|
36
|
+
end
|
37
|
+
|
38
|
+
def credentials
|
39
|
+
Base64.strict_encode64("#{client_id}:#{client_secret}")
|
40
|
+
end
|
41
|
+
|
42
|
+
def client_id
|
43
|
+
::Boletoman.configuration.itau.configuration.client_id
|
44
|
+
end
|
45
|
+
|
46
|
+
def client_secret
|
47
|
+
::Boletoman.configuration.itau.configuration.client_secret
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Boletoman
|
2
|
+
module Services
|
3
|
+
module Itau
|
4
|
+
module Token
|
5
|
+
class Response
|
6
|
+
attr_reader :raw
|
7
|
+
|
8
|
+
def initialize(raw)
|
9
|
+
@raw = JSON.parse(raw.body)
|
10
|
+
end
|
11
|
+
|
12
|
+
def token
|
13
|
+
raw["access_token"]
|
14
|
+
end
|
15
|
+
|
16
|
+
def expires_in
|
17
|
+
raw["expires_in"] - 3
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
metadata
ADDED
@@ -0,0 +1,183 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: boletoman
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Glauco Custódio
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-08-31 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.16'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.16'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: webmock
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: fakeredis
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: faraday
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: activesupport
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :runtime
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: bbrcobranca
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :runtime
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
description: Gema responsável por gerar boletos em pdf para bancos brasileiros que
|
126
|
+
requerem chamada a serviços web para obter o código de barras previamente.
|
127
|
+
email:
|
128
|
+
- glauco.custodio@gmail.com
|
129
|
+
executables: []
|
130
|
+
extensions: []
|
131
|
+
extra_rdoc_files: []
|
132
|
+
files:
|
133
|
+
- ".gitignore"
|
134
|
+
- ".rspec"
|
135
|
+
- ".travis.yml"
|
136
|
+
- CHANGELOG.md
|
137
|
+
- Gemfile
|
138
|
+
- LICENSE.txt
|
139
|
+
- README.md
|
140
|
+
- Rakefile
|
141
|
+
- bin/console
|
142
|
+
- bin/setup
|
143
|
+
- boletoman.gemspec
|
144
|
+
- lib/.DS_Store
|
145
|
+
- lib/boletoman.rb
|
146
|
+
- lib/boletoman/builders/base.rb
|
147
|
+
- lib/boletoman/builders/formatter.rb
|
148
|
+
- lib/boletoman/builders/itau.rb
|
149
|
+
- lib/boletoman/builders/itau_formatter.rb
|
150
|
+
- lib/boletoman/config.rb
|
151
|
+
- lib/boletoman/services/itau/boleto/formatter.rb
|
152
|
+
- lib/boletoman/services/itau/boleto/request.rb
|
153
|
+
- lib/boletoman/services/itau/boleto/response.rb
|
154
|
+
- lib/boletoman/services/itau/token/cache.rb
|
155
|
+
- lib/boletoman/services/itau/token/request.rb
|
156
|
+
- lib/boletoman/services/itau/token/response.rb
|
157
|
+
- lib/boletoman/version.rb
|
158
|
+
homepage: https://github.com/glaucocustodio/boletoman
|
159
|
+
licenses:
|
160
|
+
- MIT
|
161
|
+
metadata: {}
|
162
|
+
post_install_message:
|
163
|
+
rdoc_options: []
|
164
|
+
require_paths:
|
165
|
+
- lib
|
166
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
167
|
+
requirements:
|
168
|
+
- - ">="
|
169
|
+
- !ruby/object:Gem::Version
|
170
|
+
version: '0'
|
171
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
172
|
+
requirements:
|
173
|
+
- - ">="
|
174
|
+
- !ruby/object:Gem::Version
|
175
|
+
version: '0'
|
176
|
+
requirements: []
|
177
|
+
rubyforge_project:
|
178
|
+
rubygems_version: 2.6.11
|
179
|
+
signing_key:
|
180
|
+
specification_version: 4
|
181
|
+
summary: Gema responsável por gerar boletos em pdf para bancos brasileiros que requerem
|
182
|
+
chamada a serviços web para obter o código de barras previamente.
|
183
|
+
test_files: []
|