boletoman 0.0.1 → 0.0.2
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 +4 -4
- data/.gitignore +1 -0
- data/CHANGELOG.md +6 -0
- data/Gemfile +4 -0
- data/README.md +122 -5
- data/boletoman.gemspec +4 -0
- data/lib/boletoman/builders/base.rb +7 -0
- data/lib/boletoman/builders/formatter.rb +4 -0
- data/lib/boletoman/builders/itau.rb +3 -7
- data/lib/boletoman/builders/santander.rb +46 -0
- data/lib/boletoman/config.rb +4 -17
- data/lib/boletoman/itau_config.rb +17 -0
- data/lib/boletoman/santander_config.rb +23 -0
- data/lib/boletoman/services/itau/boleto/formatter.rb +5 -1
- data/lib/boletoman/services/itau/token/cache.rb +5 -1
- data/lib/boletoman/services/santander/billing.rb +66 -0
- data/lib/boletoman/services/santander/billing_response.rb +25 -0
- data/lib/boletoman/services/santander/boleto/boleto.rb +15 -0
- data/lib/boletoman/services/santander/boleto/facade.rb +44 -0
- data/lib/boletoman/services/santander/boleto/ticket.rb +121 -0
- data/lib/boletoman/services/santander/boleto/ticket_formatter.rb +92 -0
- data/lib/boletoman/services/santander/query/facade.rb +32 -0
- data/lib/boletoman/services/santander/query/query.rb +15 -0
- data/lib/boletoman/services/santander/query/ticket.rb +32 -0
- data/lib/boletoman/services/santander/request.rb +39 -0
- data/lib/boletoman/services/santander/ticket.rb +28 -0
- data/lib/boletoman/services/santander/ticket_response.rb +17 -0
- data/lib/boletoman/services/soap/request.rb +51 -0
- data/lib/boletoman/services/soap/response.rb +18 -0
- data/lib/boletoman/version.rb +1 -1
- data/lib/boletoman.rb +2 -0
- metadata +75 -3
- data/lib/boletoman/builders/itau_formatter.rb +0 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a62aa93b0f790679bb266c6ccbdefd77f0d3d78c
|
4
|
+
data.tar.gz: fccacda66c32b14badadcdd50c276a754e4a581b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 61980fad534000a2b554f19dac4a3679d7e4d9cceab7623ea62e4c4aa30616ef1083e1c9eef41dc98b64ed3c06b89920fc57d6fb6203f5d2f795cf9e4f0038b1
|
7
|
+
data.tar.gz: d6f32fa23b48bfcedbd5cf28258897898c9e49d8fc219f6e394a3c75dbbe6c4cd13855b91d10bad24fb107d35599313982ddf1a1fba2afda8d5d89ef3af188f3
|
data/.gitignore
CHANGED
data/CHANGELOG.md
CHANGED
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,12 +1,16 @@
|
|
1
1
|
# Boletoman
|
2
2
|
|
3
3
|
[](https://travis-ci.org/glaucocustodio/boletoman)
|
4
|
+
[](https://coveralls.io/github/glaucocustodio/boletoman?branch=master)
|
4
5
|
|
5
|
-
Gema responsável por gerar boletos
|
6
|
+
Gema responsável por gerar boletos para bancos brasileiros que requerem chamada a serviços web para obter o código de barras previamente. Bancos suportados no momento:
|
6
7
|
|
7
|
-
- Itaú (API de Registro de Cobrança)
|
8
|
+
- Itaú (via API de Registro de Cobrança)
|
9
|
+
- Santander (via SOAP Cobrança Online)
|
8
10
|
|
9
|
-
|
11
|
+
Usa a gema Bbrcobranca para gerar os arquivos pdf.
|
12
|
+
|
13
|
+
## Instalação
|
10
14
|
|
11
15
|
Adicione a linha no seu Gemfile
|
12
16
|
|
@@ -24,7 +28,30 @@ Ou instale você mesmo:
|
|
24
28
|
|
25
29
|
## Uso
|
26
30
|
|
27
|
-
###
|
31
|
+
### Itaú
|
32
|
+
|
33
|
+
Chamadas implementadas:
|
34
|
+
|
35
|
+
- geração de token autorizador
|
36
|
+
- geração de boleto
|
37
|
+
|
38
|
+
Configure o acesso, se estiver no Rails, pode ser colocado em `config/initializers/boletoman.rb`:
|
39
|
+
|
40
|
+
```ruby
|
41
|
+
Boletoman.configure do |config|
|
42
|
+
config.env = :production # qualquer outro symbol será considerado ambiente de desenvolvimento
|
43
|
+
config.redis = $redis # opcional: instancia do redis para cachear o token
|
44
|
+
|
45
|
+
config.itau = Boletoman::Itau.configure do |itau_config|
|
46
|
+
itau_config.client_id = 'kl3j2423'
|
47
|
+
itau_config.client_secret = 'w2H-DWAd2lkjdwa2323ADwad3232dwa1209709lj1l098jUUy2fb9XlsrQ2'
|
48
|
+
itau_config.key = '4t5g129w-61wt-78e0-io70-lo10178h6711'
|
49
|
+
itau_config.identificator = '87987098709871'
|
50
|
+
end
|
51
|
+
end
|
52
|
+
```
|
53
|
+
|
54
|
+
Passe os dados e faça a chamada:
|
28
55
|
|
29
56
|
```ruby
|
30
57
|
builder = Boletoman::Builders::Itau.new({
|
@@ -50,12 +77,98 @@ builder = Boletoman::Builders::Itau.new({
|
|
50
77
|
due_date: Date.new(2018, 12, 20),
|
51
78
|
nosso_numero: '10030033',
|
52
79
|
value: 520.80,
|
80
|
+
acceptance: 'S' # aceite
|
53
81
|
}
|
54
82
|
})
|
55
83
|
|
56
84
|
pdf = builder.build
|
57
85
|
|
58
|
-
IO.binwrite('boleto.pdf', pdf) # salva binário no arquivo
|
86
|
+
IO.binwrite('boleto-itau.pdf', pdf) # salva binário no arquivo
|
87
|
+
```
|
88
|
+
|
89
|
+
O builder irá registrar o boleto no banco e gerar um pdf.
|
90
|
+
|
91
|
+
### Santander
|
92
|
+
|
93
|
+
Chamadas implementadas:
|
94
|
+
|
95
|
+
- consulta título
|
96
|
+
- registra título
|
97
|
+
- solicitação de ticket de segurança
|
98
|
+
|
99
|
+
Configure o acesso, se estiver no Rails, pode ser colocado em `config/initializers/boletoman.rb`:
|
100
|
+
|
101
|
+
```ruby
|
102
|
+
Boletoman.configure do |config|
|
103
|
+
config.env = :production # qualquer outro symbol será considerado ambiente de desenvolvimento
|
104
|
+
|
105
|
+
config.santander = Boletoman::Santander.configure do |santander|
|
106
|
+
santander.station = '1A2B'
|
107
|
+
santander.covenant = '1234567'
|
108
|
+
# path do certificado
|
109
|
+
santander.certificate = 'lib/certificado.cer'
|
110
|
+
santander.certificate_key = 'lib/certificado.pem'
|
111
|
+
# em caso de querer passar certificado via proxy do nginx por ex, defina:
|
112
|
+
santander.use_certificate = false
|
113
|
+
santander.ticket_wsdl_url = 'https://meuproxy.com/dl-ticket-services/TicketEndpointService/TicketEndpointService.wsdl'
|
114
|
+
end
|
115
|
+
end
|
116
|
+
```
|
117
|
+
|
118
|
+
Passe os dados e faça a chamada:
|
119
|
+
|
120
|
+
```ruby
|
121
|
+
builder = Boletoman::Builders::Santander.new({
|
122
|
+
# dados do cedente
|
123
|
+
transferor: {
|
124
|
+
name: 'EMPRESA CEDENTE LTDA',
|
125
|
+
document: '86.521.120/0001-50', # cnpj
|
126
|
+
branch: '0036', # agencia
|
127
|
+
checking_account: '119097', # conta
|
128
|
+
wallet: '109', # carteira
|
129
|
+
},
|
130
|
+
# dados do pagador
|
131
|
+
payer: {
|
132
|
+
document: '714.295.500-74', # cpf
|
133
|
+
name: 'JOSE SILVA',
|
134
|
+
street: 'Rua Edson Pereira Dias, 123',
|
135
|
+
city: 'Sumaré',
|
136
|
+
state: 'SP',
|
137
|
+
zip_code: '17535-004',
|
138
|
+
},
|
139
|
+
# dados do boleto
|
140
|
+
boleto: {
|
141
|
+
due_date: Date.new(2018, 12, 20),
|
142
|
+
nosso_numero: '10030033',
|
143
|
+
value: 520.80,
|
144
|
+
acceptance: 'S' # aceite
|
145
|
+
}
|
146
|
+
})
|
147
|
+
|
148
|
+
pdf = builder.build
|
149
|
+
|
150
|
+
IO.binwrite('boleto-santander.pdf', pdf) # salva binário no arquivo
|
151
|
+
```
|
152
|
+
|
153
|
+
O builder irá registrar o boleto no banco e gerar um pdf.
|
154
|
+
|
155
|
+
#### Consultar boleto
|
156
|
+
|
157
|
+
```ruby
|
158
|
+
Boletoman::Services::Santander::Query::Facade.new(nsu).call # NSU do banco
|
159
|
+
|
160
|
+
# => { barcode: '03923500000671005391763800000098669934890101', line: '0317176380000009866399934952350000067610058901' }
|
161
|
+
```
|
162
|
+
|
163
|
+
#### Registrar boleto
|
164
|
+
|
165
|
+
Se quiser apenas registrar um boleto sem gerar pdf:
|
166
|
+
|
167
|
+
```ruby
|
168
|
+
# mesmo conjunto de dados passado para o builder acima
|
169
|
+
Boletoman::Services::Santander::Boleto::Facade.new(data).call
|
170
|
+
|
171
|
+
# => { barcode: '03923500000671005391763800000098669934890101', line: '0317176380000009866399934952350000067610058901', nosso_numero: '12345678', nsu: '456789', ticket: '/XPwu7tJ6CgbTWIGNtW7gO7GH/orhi0IjLOzzs70r+RVJlOUYQJyzXpR3k30RPxv5SlJU9/mN/P+Aw0vzA/JGmLqAF...' }
|
59
172
|
```
|
60
173
|
|
61
174
|
## Desenvolvimento
|
@@ -74,6 +187,10 @@ Atualize o número da versão em `version.rb` e rode:
|
|
74
187
|
|
75
188
|
`bundle exec rake release`
|
76
189
|
|
190
|
+
## TODO
|
191
|
+
|
192
|
+
- remover alguns valores hard coded no gerador Itaú como `juros`, `multa`, `grupo_desconto`, `indicador_pagamento_parcial` e `recebimento_divergente` (eu ainda não precisei de outros)
|
193
|
+
|
77
194
|
## License
|
78
195
|
|
79
196
|
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/boletoman.gemspec
CHANGED
@@ -26,8 +26,12 @@ Gem::Specification.new do |spec|
|
|
26
26
|
spec.add_development_dependency "rspec", "~> 3.0"
|
27
27
|
spec.add_development_dependency "webmock"
|
28
28
|
spec.add_development_dependency "fakeredis"
|
29
|
+
spec.add_development_dependency "pry"
|
30
|
+
spec.add_development_dependency "timecop"
|
31
|
+
spec.add_development_dependency "awesome_print"
|
29
32
|
|
30
33
|
spec.add_dependency 'faraday'
|
31
34
|
spec.add_dependency 'activesupport'
|
32
35
|
spec.add_dependency 'bbrcobranca'
|
36
|
+
spec.add_dependency 'savon'
|
33
37
|
end
|
@@ -1,3 +1,6 @@
|
|
1
|
+
require "bbrcobranca"
|
2
|
+
require_relative "formatter"
|
3
|
+
|
1
4
|
module Boletoman
|
2
5
|
module Builders
|
3
6
|
class Base
|
@@ -19,6 +22,10 @@ module Boletoman
|
|
19
22
|
to_s.demodulize.downcase
|
20
23
|
end
|
21
24
|
|
25
|
+
def formatter
|
26
|
+
@formatter ||= Formatter.new(data)
|
27
|
+
end
|
28
|
+
|
22
29
|
# segunda via
|
23
30
|
def duplicate?
|
24
31
|
data.dig(:boleto, :duplicate) == true
|
@@ -1,7 +1,5 @@
|
|
1
1
|
require 'boletoman/services/itau/boleto/request'
|
2
2
|
require_relative 'base'
|
3
|
-
require_relative 'itau_formatter'
|
4
|
-
require "bbrcobranca"
|
5
3
|
|
6
4
|
module Boletoman
|
7
5
|
module Builders
|
@@ -20,19 +18,17 @@ module Boletoman
|
|
20
18
|
sacado_endereco: formatter.payer_address,
|
21
19
|
valor: formatter.value,
|
22
20
|
data_vencimento: formatter.due_date,
|
23
|
-
aceite:
|
21
|
+
aceite: formatter.acceptance,
|
24
22
|
codigo_barras: barcode,
|
25
23
|
nosso_numero: nosso_numero,
|
24
|
+
instrucao1: formatter.instruction1,
|
25
|
+
instrucao2: formatter.instruction2,
|
26
26
|
instrucao3: formatter.instruction3
|
27
27
|
)
|
28
28
|
end
|
29
29
|
|
30
30
|
private
|
31
31
|
|
32
|
-
def formatter
|
33
|
-
@formatter ||= ItauFormatter.new(data)
|
34
|
-
end
|
35
|
-
|
36
32
|
def barcode
|
37
33
|
boleto_data.barcode
|
38
34
|
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'boletoman/services/santander/boleto/facade'
|
2
|
+
require_relative 'base'
|
3
|
+
|
4
|
+
module Boletoman
|
5
|
+
module Builders
|
6
|
+
class Santander < Base
|
7
|
+
def instance
|
8
|
+
@instance ||= Bbrcobranca::Boleto::Santander.new(
|
9
|
+
carteira: formatter.wallet,
|
10
|
+
convenio: formatter.covenant,
|
11
|
+
agencia: formatter.branch,
|
12
|
+
conta_corrente: formatter.checking_account,
|
13
|
+
cedente: formatter.transferor_name,
|
14
|
+
documento_cedente: formatter.transferor_document,
|
15
|
+
data_documento: formatter.issue_date,
|
16
|
+
data_processamento: formatter.issue_date,
|
17
|
+
sacado: formatter.payer_name,
|
18
|
+
sacado_documento: formatter.payer_document,
|
19
|
+
sacado_endereco: formatter.payer_address,
|
20
|
+
valor: formatter.value,
|
21
|
+
data_vencimento: formatter.due_date,
|
22
|
+
aceite: formatter.acceptance,
|
23
|
+
codigo_barras: barcode,
|
24
|
+
nosso_numero: nosso_numero,
|
25
|
+
instrucao1: formatter.instruction1,
|
26
|
+
instrucao2: formatter.instruction2,
|
27
|
+
instrucao3: formatter.instruction3
|
28
|
+
)
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
def barcode
|
34
|
+
duplicate? ? data[:boleto][:barcode] : remote_response[:barcode]
|
35
|
+
end
|
36
|
+
|
37
|
+
def nosso_numero
|
38
|
+
duplicate? ? data[:boleto][:nosso_numero] : remote_response[:nosso_numero]
|
39
|
+
end
|
40
|
+
|
41
|
+
def remote_response
|
42
|
+
@remote_response ||= ::Boletoman::Services::Santander::Boleto::Facade.new(data).call
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
data/lib/boletoman/config.rb
CHANGED
@@ -1,3 +1,6 @@
|
|
1
|
+
require "boletoman/itau_config"
|
2
|
+
require "boletoman/santander_config"
|
3
|
+
|
1
4
|
module Boletoman
|
2
5
|
class << self
|
3
6
|
attr_accessor :configuration
|
@@ -9,7 +12,7 @@ module Boletoman
|
|
9
12
|
end
|
10
13
|
|
11
14
|
class Configuration
|
12
|
-
attr_accessor :env, :redis, :itau
|
15
|
+
attr_accessor :env, :redis, :itau, :santander
|
13
16
|
|
14
17
|
def initialize
|
15
18
|
@env = :dev
|
@@ -19,20 +22,4 @@ module Boletoman
|
|
19
22
|
env == :production
|
20
23
|
end
|
21
24
|
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
25
|
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Boletoman
|
2
|
+
class ItauConfiguration
|
3
|
+
attr_accessor :token, :key, :identificator, :client_id, :client_secret
|
4
|
+
end
|
5
|
+
|
6
|
+
class Itau
|
7
|
+
class << self
|
8
|
+
attr_accessor :configuration
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.configure
|
12
|
+
self.configuration ||= ItauConfiguration.new
|
13
|
+
yield(configuration)
|
14
|
+
self
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Boletoman
|
2
|
+
class SantanderConfiguration
|
3
|
+
attr_accessor :covenant, :station, :certificate, :certificate_key, :use_certificate,
|
4
|
+
:ticket_wsdl_url
|
5
|
+
|
6
|
+
def initialize()
|
7
|
+
@ticket_wsdl_url = 'https://ymbdlb.santander.com.br/dl-ticket-services/TicketEndpointService/TicketEndpointService.wsdl'
|
8
|
+
@use_certificate = true
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
class Santander
|
13
|
+
class << self
|
14
|
+
attr_accessor :configuration
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.configure
|
18
|
+
self.configuration ||= SantanderConfiguration.new
|
19
|
+
yield(configuration)
|
20
|
+
self
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -22,7 +22,7 @@ module Boletoman
|
|
22
22
|
conta_beneficiario: transferor_account,
|
23
23
|
digito_verificador_conta_beneficiario: transferor_account_digit
|
24
24
|
},
|
25
|
-
titulo_aceite:
|
25
|
+
titulo_aceite: acceptance,
|
26
26
|
pagador: {
|
27
27
|
cpf_cnpj_pagador: payer_document,
|
28
28
|
nome_pagador: payer_name,
|
@@ -127,6 +127,10 @@ module Boletoman
|
|
127
127
|
(data[:boleto][:value].round(2) * 100).truncate.to_s.rjust(16, '0')
|
128
128
|
end
|
129
129
|
|
130
|
+
def acceptance
|
131
|
+
data[:boleto][:acceptance] || 'N'
|
132
|
+
end
|
133
|
+
|
130
134
|
def issue_date
|
131
135
|
Date.today.to_s
|
132
136
|
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
require_relative 'request'
|
2
|
+
require_relative 'billing_response'
|
3
|
+
|
4
|
+
module Boletoman
|
5
|
+
module Services
|
6
|
+
module Santander
|
7
|
+
class Billing < Request
|
8
|
+
attr_reader :ticket
|
9
|
+
attr_writer :nsu, :nsu_date
|
10
|
+
|
11
|
+
def initialize(**args)
|
12
|
+
@ticket = args[:ticket]
|
13
|
+
@nsu = args[:nsu]
|
14
|
+
@nsu_date = args[:nsu_date]
|
15
|
+
end
|
16
|
+
|
17
|
+
def wsdl
|
18
|
+
"https://ymbcash.santander.com.br/ymbsrv/CobrancaEndpointService/CobrancaEndpointService.wsdl".freeze
|
19
|
+
end
|
20
|
+
|
21
|
+
def requires_certificate?
|
22
|
+
::Boletoman.configuration.santander.configuration.use_certificate
|
23
|
+
end
|
24
|
+
|
25
|
+
def message
|
26
|
+
{
|
27
|
+
dto: {
|
28
|
+
dtNsu: nsu_date,
|
29
|
+
estacao: station,
|
30
|
+
nsu: nsu,
|
31
|
+
ticket: ticket,
|
32
|
+
tpAmbiente: env
|
33
|
+
}
|
34
|
+
}
|
35
|
+
end
|
36
|
+
|
37
|
+
def response_class
|
38
|
+
::Boletoman::Services::Santander::BillingResponse
|
39
|
+
end
|
40
|
+
|
41
|
+
private
|
42
|
+
|
43
|
+
def env
|
44
|
+
production? ? 'P' : 'T'
|
45
|
+
end
|
46
|
+
|
47
|
+
def nsu_date
|
48
|
+
(@nsu_date || Date.today).strftime("%d%m%Y")
|
49
|
+
end
|
50
|
+
|
51
|
+
def nsu
|
52
|
+
prefix = production? ? nil : 'TST'
|
53
|
+
"#{prefix}#{@nsu}"
|
54
|
+
end
|
55
|
+
|
56
|
+
def production?
|
57
|
+
::Boletoman.configuration.production_env?
|
58
|
+
end
|
59
|
+
|
60
|
+
def station
|
61
|
+
::Boletoman.configuration.santander.configuration.station
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'boletoman/services/soap/response'
|
2
|
+
|
3
|
+
module Boletoman
|
4
|
+
module Services
|
5
|
+
module Santander
|
6
|
+
class BillingResponse < Soap::Response
|
7
|
+
def success?
|
8
|
+
barcode.present?
|
9
|
+
end
|
10
|
+
|
11
|
+
def barcode
|
12
|
+
body.dig(:return, :titulo, :cd_barra)
|
13
|
+
end
|
14
|
+
|
15
|
+
def line
|
16
|
+
body.dig(:return, :titulo, :lin_dig)
|
17
|
+
end
|
18
|
+
|
19
|
+
def nosso_numero
|
20
|
+
body.dig(:return, :titulo, :nosso_numero)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require_relative 'ticket'
|
2
|
+
require_relative 'boleto'
|
3
|
+
|
4
|
+
module Boletoman
|
5
|
+
module Services
|
6
|
+
module Santander
|
7
|
+
module Boleto
|
8
|
+
class Facade
|
9
|
+
attr_reader :data
|
10
|
+
|
11
|
+
def initialize(data)
|
12
|
+
@data = data
|
13
|
+
end
|
14
|
+
|
15
|
+
def call
|
16
|
+
{
|
17
|
+
barcode: boleto_response.barcode,
|
18
|
+
line: boleto_response.line,
|
19
|
+
nosso_numero: boleto_response.nosso_numero,
|
20
|
+
nsu: nsu,
|
21
|
+
ticket: ticket_response.ticket
|
22
|
+
}
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def boleto_response
|
28
|
+
@boleto_response ||= Boleto.new(
|
29
|
+
ticket: ticket_response.ticket, nsu: nsu, nsu_date: data[:boleto][:issue_date]
|
30
|
+
).call
|
31
|
+
end
|
32
|
+
|
33
|
+
def nsu
|
34
|
+
@nsu ||= data[:boleto][:nsu] || SecureRandom.hex(3)
|
35
|
+
end
|
36
|
+
|
37
|
+
def ticket_response
|
38
|
+
@ticket_response ||= Ticket.new(data).call
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,121 @@
|
|
1
|
+
require_relative '../ticket'
|
2
|
+
require_relative 'ticket_formatter'
|
3
|
+
|
4
|
+
module Boletoman
|
5
|
+
module Services
|
6
|
+
module Santander
|
7
|
+
module Boleto
|
8
|
+
class Ticket < Services::Santander::Ticket
|
9
|
+
attr_reader :data
|
10
|
+
|
11
|
+
def initialize(data)
|
12
|
+
@data = data
|
13
|
+
end
|
14
|
+
|
15
|
+
def message
|
16
|
+
{
|
17
|
+
'TicketRequest' => {
|
18
|
+
dados: {
|
19
|
+
entry: [
|
20
|
+
{
|
21
|
+
key: 'CONVENIO.COD-BANCO',
|
22
|
+
value: BANK_CODE
|
23
|
+
},
|
24
|
+
{
|
25
|
+
key: 'CONVENIO.COD-CONVENIO',
|
26
|
+
value: covenant
|
27
|
+
},
|
28
|
+
{
|
29
|
+
key: 'PAGADOR.TP-DOC',
|
30
|
+
value: formatter.document_type
|
31
|
+
},
|
32
|
+
{
|
33
|
+
key: 'PAGADOR.NUM-DOC',
|
34
|
+
value: formatter.document
|
35
|
+
},
|
36
|
+
{
|
37
|
+
key: 'PAGADOR.NOME',
|
38
|
+
value: formatter.payer_name
|
39
|
+
},
|
40
|
+
{
|
41
|
+
key: 'PAGADOR.ENDER',
|
42
|
+
value: formatter.payer_street
|
43
|
+
},
|
44
|
+
{
|
45
|
+
key: 'PAGADOR.BAIRRO',
|
46
|
+
value: formatter.payer_neighborhood
|
47
|
+
},
|
48
|
+
{
|
49
|
+
key: 'PAGADOR.CIDADE',
|
50
|
+
value: formatter.payer_city
|
51
|
+
},
|
52
|
+
{
|
53
|
+
key: 'PAGADOR.UF',
|
54
|
+
value: formatter.payer_state
|
55
|
+
},
|
56
|
+
{
|
57
|
+
key: 'PAGADOR.CEP',
|
58
|
+
value: formatter.payer_zip_code
|
59
|
+
},
|
60
|
+
{
|
61
|
+
key: 'TITULO.SEU-NUMERO',
|
62
|
+
value: formatter.full_nosso_numero
|
63
|
+
},
|
64
|
+
{
|
65
|
+
key: 'TITULO.NOSSO-NUMERO',
|
66
|
+
value: formatter.full_nosso_numero
|
67
|
+
},
|
68
|
+
{
|
69
|
+
key: 'TITULO.DT-VENCTO',
|
70
|
+
value: formatter.due_date
|
71
|
+
},
|
72
|
+
{
|
73
|
+
key: 'TITULO.DT-EMISSAO',
|
74
|
+
value: formatter.issue_date
|
75
|
+
},
|
76
|
+
{
|
77
|
+
key: 'TITULO.ESPECIE',
|
78
|
+
value: 17
|
79
|
+
},
|
80
|
+
{
|
81
|
+
key: 'TITULO.VL-NOMINAL',
|
82
|
+
value: formatter.value
|
83
|
+
},
|
84
|
+
{
|
85
|
+
key: 'TITULO.PC-MULTA',
|
86
|
+
value: formatter.penalty_percentage
|
87
|
+
},
|
88
|
+
{
|
89
|
+
key: 'TITULO.QT-DIAS-MULTA',
|
90
|
+
value: formatter.penalty_days
|
91
|
+
},
|
92
|
+
{
|
93
|
+
key: 'TITULO.PC-JURO',
|
94
|
+
value: formatter.interest_percentage
|
95
|
+
},
|
96
|
+
{
|
97
|
+
key: 'MENSAGEM',
|
98
|
+
value: formatter.message
|
99
|
+
}
|
100
|
+
]
|
101
|
+
},
|
102
|
+
expiracao: '100',
|
103
|
+
sistema: 'YMB'
|
104
|
+
}
|
105
|
+
}
|
106
|
+
end
|
107
|
+
|
108
|
+
private
|
109
|
+
|
110
|
+
def formatter
|
111
|
+
@formatter ||= TicketFormatter.new(data)
|
112
|
+
end
|
113
|
+
|
114
|
+
def covenant
|
115
|
+
::Boletoman.configuration.santander.configuration.covenant
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
@@ -0,0 +1,92 @@
|
|
1
|
+
require 'active_support/all'
|
2
|
+
|
3
|
+
module Boletoman
|
4
|
+
module Services
|
5
|
+
module Santander
|
6
|
+
module Boleto
|
7
|
+
class TicketFormatter
|
8
|
+
attr_reader :raw
|
9
|
+
|
10
|
+
def initialize(raw)
|
11
|
+
@raw = raw
|
12
|
+
end
|
13
|
+
|
14
|
+
def document_type
|
15
|
+
raw[:payer][:document].strip.length == 11 ? "01" : "02"
|
16
|
+
end
|
17
|
+
|
18
|
+
def document
|
19
|
+
raw[:payer][:document].remove(/\D/)
|
20
|
+
end
|
21
|
+
|
22
|
+
def payer_name
|
23
|
+
raw[:payer][:name].first(40)
|
24
|
+
end
|
25
|
+
|
26
|
+
def payer_street
|
27
|
+
raw[:payer][:street].first(40)
|
28
|
+
end
|
29
|
+
|
30
|
+
def payer_neighborhood
|
31
|
+
raw[:payer][:neighborhood].first(30)
|
32
|
+
end
|
33
|
+
|
34
|
+
def payer_city
|
35
|
+
raw[:payer][:city].first(20)
|
36
|
+
end
|
37
|
+
|
38
|
+
def payer_state
|
39
|
+
raw[:payer][:state]
|
40
|
+
end
|
41
|
+
|
42
|
+
def payer_zip_code
|
43
|
+
raw[:payer][:zip_code].remove(/\D/)
|
44
|
+
end
|
45
|
+
|
46
|
+
def due_date
|
47
|
+
raw[:boleto][:due_date].strftime("%d%m%Y")
|
48
|
+
end
|
49
|
+
|
50
|
+
def issue_date
|
51
|
+
(raw[:boleto][:issue_date] || Date.today).strftime("%d%m%Y")
|
52
|
+
end
|
53
|
+
|
54
|
+
def value
|
55
|
+
as_int(raw[:boleto][:value])
|
56
|
+
end
|
57
|
+
|
58
|
+
def penalty_percentage
|
59
|
+
as_int(raw[:boleto][:penalty_percentage]) || '00'
|
60
|
+
end
|
61
|
+
|
62
|
+
def penalty_days
|
63
|
+
raw[:boleto][:penalty_days] || '00'
|
64
|
+
end
|
65
|
+
|
66
|
+
def interest_percentage
|
67
|
+
as_int(raw[:boleto][:interest_percentage]) || '00'
|
68
|
+
end
|
69
|
+
|
70
|
+
def full_nosso_numero
|
71
|
+
nosso_numero = raw[:boleto][:nosso_numero]
|
72
|
+
verificator_digit = nosso_numero.modulo11(
|
73
|
+
multiplicador: (2..9).to_a, mapeamento: { 10 => 0, 11 => 0 }
|
74
|
+
) { |total| 11 - (total % 11) }
|
75
|
+
|
76
|
+
"#{nosso_numero}#{verificator_digit}"
|
77
|
+
end
|
78
|
+
|
79
|
+
def message
|
80
|
+
raw[:message]
|
81
|
+
end
|
82
|
+
|
83
|
+
private
|
84
|
+
|
85
|
+
def as_int(value)
|
86
|
+
("%.2f" % value).remove('.')
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require_relative 'ticket'
|
2
|
+
require_relative 'query'
|
3
|
+
|
4
|
+
module Boletoman
|
5
|
+
module Services
|
6
|
+
module Santander
|
7
|
+
module Query
|
8
|
+
class Facade
|
9
|
+
attr_reader :nsu
|
10
|
+
|
11
|
+
def initialize(nsu)
|
12
|
+
@nsu = nsu
|
13
|
+
end
|
14
|
+
|
15
|
+
def call
|
16
|
+
{ barcode: query_response.barcode, line: query_response.line }
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def ticket_response
|
22
|
+
@ticket_response ||= Ticket.new.call
|
23
|
+
end
|
24
|
+
|
25
|
+
def query_response
|
26
|
+
@query_response ||= Query.new(ticket: ticket_response.ticket, nsu: nsu).call
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require_relative '../ticket'
|
2
|
+
|
3
|
+
module Boletoman
|
4
|
+
module Services
|
5
|
+
module Santander
|
6
|
+
module Query
|
7
|
+
class Ticket < Services::Santander::Ticket
|
8
|
+
def message
|
9
|
+
{
|
10
|
+
'TicketRequest' => {
|
11
|
+
dados: {
|
12
|
+
entry: [
|
13
|
+
{
|
14
|
+
key: 'CONVENIO.COD-BANCO',
|
15
|
+
value: BANK_CODE
|
16
|
+
},
|
17
|
+
{
|
18
|
+
key: 'CONVENIO.COD-CONVENIO',
|
19
|
+
value: ::Boletoman.configuration.santander.configuration.covenant
|
20
|
+
}
|
21
|
+
]
|
22
|
+
},
|
23
|
+
expiracao: '100',
|
24
|
+
sistema: 'YMB'
|
25
|
+
}
|
26
|
+
}
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'boletoman/services/soap/request'
|
2
|
+
|
3
|
+
module Boletoman
|
4
|
+
module Services
|
5
|
+
module Santander
|
6
|
+
class Request < Soap::Request
|
7
|
+
def extra_config_options
|
8
|
+
certificate_config
|
9
|
+
end
|
10
|
+
|
11
|
+
def requires_certificate?
|
12
|
+
raise NotImplementedError
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def certificate_config
|
18
|
+
return {} unless requires_certificate?
|
19
|
+
{
|
20
|
+
ssl_cert_file: certificate,
|
21
|
+
ssl_cert_key_file: certificate_key
|
22
|
+
}
|
23
|
+
end
|
24
|
+
|
25
|
+
def certificate
|
26
|
+
path = ::Boletoman.configuration.santander.configuration.certificate
|
27
|
+
raise "Arquivo do certificado não existe" unless File.exist?(path)
|
28
|
+
File.expand_path(path)
|
29
|
+
end
|
30
|
+
|
31
|
+
def certificate_key
|
32
|
+
path = ::Boletoman.configuration.santander.configuration.certificate_key
|
33
|
+
raise "Arquivo chave do certificado não existe" unless File.exist?(path)
|
34
|
+
File.expand_path(path)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require_relative 'request'
|
2
|
+
require_relative 'ticket_response'
|
3
|
+
|
4
|
+
module Boletoman
|
5
|
+
module Services
|
6
|
+
module Santander
|
7
|
+
class Ticket < Request
|
8
|
+
BANK_CODE = '0033'.freeze
|
9
|
+
|
10
|
+
def wsdl
|
11
|
+
::Boletoman.configuration.santander.configuration.ticket_wsdl_url
|
12
|
+
end
|
13
|
+
|
14
|
+
def requires_certificate?
|
15
|
+
false
|
16
|
+
end
|
17
|
+
|
18
|
+
def operation
|
19
|
+
:create
|
20
|
+
end
|
21
|
+
|
22
|
+
def response_class
|
23
|
+
::Boletoman::Services::Santander::TicketResponse
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'boletoman/services/soap/response'
|
2
|
+
|
3
|
+
module Boletoman
|
4
|
+
module Services
|
5
|
+
module Santander
|
6
|
+
class TicketResponse < Soap::Response
|
7
|
+
def success?
|
8
|
+
body[:ticket_response][:ret_code] == "0"
|
9
|
+
end
|
10
|
+
|
11
|
+
def ticket
|
12
|
+
body[:ticket_response][:ticket]
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'savon'
|
2
|
+
|
3
|
+
module Boletoman
|
4
|
+
module Services
|
5
|
+
module Soap
|
6
|
+
class Request
|
7
|
+
def call
|
8
|
+
response_class.new(response, self).tap do |response|
|
9
|
+
raise "Falha ao chamar operação #{operation}: #{response.body}" unless response.success?
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def response_class
|
14
|
+
"#{self.class}Response".constantize
|
15
|
+
end
|
16
|
+
|
17
|
+
def response
|
18
|
+
client.call(operation, message: message)
|
19
|
+
end
|
20
|
+
|
21
|
+
def client
|
22
|
+
@client ||= Savon.client(config_options)
|
23
|
+
end
|
24
|
+
|
25
|
+
def operation
|
26
|
+
raise NotImplementedError
|
27
|
+
end
|
28
|
+
|
29
|
+
def message
|
30
|
+
raise NotImplementedError
|
31
|
+
end
|
32
|
+
|
33
|
+
def config_options
|
34
|
+
wsdl_config.merge(extra_config_options)
|
35
|
+
end
|
36
|
+
|
37
|
+
def wsdl_config
|
38
|
+
{ wsdl: wsdl }
|
39
|
+
end
|
40
|
+
|
41
|
+
def extra_config_options
|
42
|
+
{}
|
43
|
+
end
|
44
|
+
|
45
|
+
def wsdl
|
46
|
+
raise NotImplementedError
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Boletoman
|
2
|
+
module Services
|
3
|
+
module Soap
|
4
|
+
class Response
|
5
|
+
attr_reader :raw_response, :requester
|
6
|
+
|
7
|
+
def initialize(raw_response, requester)
|
8
|
+
@raw_response = raw_response
|
9
|
+
@requester = requester
|
10
|
+
end
|
11
|
+
|
12
|
+
def body
|
13
|
+
raw_response.body["#{requester.operation}_response".to_sym]
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
data/lib/boletoman/version.rb
CHANGED
data/lib/boletoman.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: boletoman
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Glauco Custódio
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-09-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -80,6 +80,48 @@ dependencies:
|
|
80
80
|
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: pry
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
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: timecop
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
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: awesome_print
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
83
125
|
- !ruby/object:Gem::Dependency
|
84
126
|
name: faraday
|
85
127
|
requirement: !ruby/object:Gem::Requirement
|
@@ -122,6 +164,20 @@ dependencies:
|
|
122
164
|
- - ">="
|
123
165
|
- !ruby/object:Gem::Version
|
124
166
|
version: '0'
|
167
|
+
- !ruby/object:Gem::Dependency
|
168
|
+
name: savon
|
169
|
+
requirement: !ruby/object:Gem::Requirement
|
170
|
+
requirements:
|
171
|
+
- - ">="
|
172
|
+
- !ruby/object:Gem::Version
|
173
|
+
version: '0'
|
174
|
+
type: :runtime
|
175
|
+
prerelease: false
|
176
|
+
version_requirements: !ruby/object:Gem::Requirement
|
177
|
+
requirements:
|
178
|
+
- - ">="
|
179
|
+
- !ruby/object:Gem::Version
|
180
|
+
version: '0'
|
125
181
|
description: Gema responsável por gerar boletos em pdf para bancos brasileiros que
|
126
182
|
requerem chamada a serviços web para obter o código de barras previamente.
|
127
183
|
email:
|
@@ -146,14 +202,30 @@ files:
|
|
146
202
|
- lib/boletoman/builders/base.rb
|
147
203
|
- lib/boletoman/builders/formatter.rb
|
148
204
|
- lib/boletoman/builders/itau.rb
|
149
|
-
- lib/boletoman/builders/
|
205
|
+
- lib/boletoman/builders/santander.rb
|
150
206
|
- lib/boletoman/config.rb
|
207
|
+
- lib/boletoman/itau_config.rb
|
208
|
+
- lib/boletoman/santander_config.rb
|
151
209
|
- lib/boletoman/services/itau/boleto/formatter.rb
|
152
210
|
- lib/boletoman/services/itau/boleto/request.rb
|
153
211
|
- lib/boletoman/services/itau/boleto/response.rb
|
154
212
|
- lib/boletoman/services/itau/token/cache.rb
|
155
213
|
- lib/boletoman/services/itau/token/request.rb
|
156
214
|
- lib/boletoman/services/itau/token/response.rb
|
215
|
+
- lib/boletoman/services/santander/billing.rb
|
216
|
+
- lib/boletoman/services/santander/billing_response.rb
|
217
|
+
- lib/boletoman/services/santander/boleto/boleto.rb
|
218
|
+
- lib/boletoman/services/santander/boleto/facade.rb
|
219
|
+
- lib/boletoman/services/santander/boleto/ticket.rb
|
220
|
+
- lib/boletoman/services/santander/boleto/ticket_formatter.rb
|
221
|
+
- lib/boletoman/services/santander/query/facade.rb
|
222
|
+
- lib/boletoman/services/santander/query/query.rb
|
223
|
+
- lib/boletoman/services/santander/query/ticket.rb
|
224
|
+
- lib/boletoman/services/santander/request.rb
|
225
|
+
- lib/boletoman/services/santander/ticket.rb
|
226
|
+
- lib/boletoman/services/santander/ticket_response.rb
|
227
|
+
- lib/boletoman/services/soap/request.rb
|
228
|
+
- lib/boletoman/services/soap/response.rb
|
157
229
|
- lib/boletoman/version.rb
|
158
230
|
homepage: https://github.com/glaucocustodio/boletoman
|
159
231
|
licenses:
|