boleto_bancario 0.0.2 → 1.0.0
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 +5 -5
- data/Changelog.markdown +54 -2
- data/README.markdown +660 -189
- data/lib/boleto_bancario/calculos/documento.rb +191 -0
- data/lib/boleto_bancario/calculos/fator_vencimento.rb +78 -31
- data/lib/boleto_bancario/core/boleto.rb +30 -1
- data/lib/boleto_bancario/core/c6_bank.rb +155 -0
- data/lib/boleto_bancario/core/inter.rb +155 -0
- data/lib/boleto_bancario/core/nubank.rb +156 -0
- data/lib/boleto_bancario/locales/pt-BR.yml +55 -0
- data/lib/boleto_bancario/renderers/base.rb +154 -0
- data/lib/boleto_bancario/renderers/html_renderer.rb +92 -0
- data/lib/boleto_bancario/renderers/pdf_renderer.rb +130 -0
- data/lib/boleto_bancario/renderers/png_renderer.rb +66 -0
- data/lib/boleto_bancario/templates/_barcode.html.erb +3 -0
- data/lib/boleto_bancario/templates/_cedente.html.erb +14 -0
- data/lib/boleto_bancario/templates/_header.html.erb +4 -0
- data/lib/boleto_bancario/templates/_instructions.html.erb +10 -0
- data/lib/boleto_bancario/templates/_payment.html.erb +36 -0
- data/lib/boleto_bancario/templates/_sacado.html.erb +10 -0
- data/lib/boleto_bancario/templates/boleto.html.erb +22 -0
- data/lib/boleto_bancario/templates/boleto_styles.css +18 -0
- data/lib/boleto_bancario/version.rb +3 -1
- data/lib/boleto_bancario.rb +23 -6
- data/lib/generators/boleto_bancario/views_generator.rb +47 -0
- metadata +91 -129
- data/.gitignore +0 -19
- data/.rspec +0 -1
- data/.travis.yml +0 -10
- data/Gemfile +0 -3
- data/Planning.markdown +0 -63
- data/Rakefile +0 -15
- data/TODO.markdown +0 -19
- data/boleto_bancario.gemspec +0 -29
- data/documentacoes_dos_boletos/Bradesco/Manual_BRADESCO.PDF +0 -0
- data/lib/boleto_bancario/core/hsbc.rb +0 -170
- data/lib/boleto_bancario/core/real.rb +0 -177
- data/spec/boleto_bancario/calculos/digitos_spec.rb +0 -19
- data/spec/boleto_bancario/calculos/fator_vencimento_spec.rb +0 -59
- data/spec/boleto_bancario/calculos/fatores_de_multiplicacao_spec.rb +0 -69
- data/spec/boleto_bancario/calculos/linha_digitavel_spec.rb +0 -57
- data/spec/boleto_bancario/calculos/modulo10_spec.rb +0 -53
- data/spec/boleto_bancario/calculos/modulo11_fator_de2a7_spec.rb +0 -43
- data/spec/boleto_bancario/calculos/modulo11_fator_de2a9_resto_zero_spec.rb +0 -39
- data/spec/boleto_bancario/calculos/modulo11_fator_de2a9_spec.rb +0 -67
- data/spec/boleto_bancario/calculos/modulo11_fator_de9a2_resto_x_spec.rb +0 -37
- data/spec/boleto_bancario/calculos/modulo11_fator_de9a2_spec.rb +0 -31
- data/spec/boleto_bancario/calculos/modulo11_spec.rb +0 -19
- data/spec/boleto_bancario/calculos/modulo_numero_de_controle_spec.rb +0 -37
- data/spec/boleto_bancario/core/banco_brasil_spec.rb +0 -377
- data/spec/boleto_bancario/core/banrisul_spec.rb +0 -129
- data/spec/boleto_bancario/core/boleto_spec.rb +0 -218
- data/spec/boleto_bancario/core/bradesco_spec.rb +0 -163
- data/spec/boleto_bancario/core/caixa_spec.rb +0 -111
- data/spec/boleto_bancario/core/hsbc_spec.rb +0 -72
- data/spec/boleto_bancario/core/itau_spec.rb +0 -333
- data/spec/boleto_bancario/core/real_spec.rb +0 -104
- data/spec/boleto_bancario/core/santander_spec.rb +0 -137
- data/spec/boleto_bancario/core/sicoob_spec.rb +0 -111
- data/spec/boleto_bancario/core/sicredi_spec.rb +0 -149
- data/spec/inheritance/banco_brasil_spec.rb +0 -22
- data/spec/inheritance/banrisul_spec.rb +0 -22
- data/spec/inheritance/boleto_spec.rb +0 -15
- data/spec/inheritance/bradesco_spec.rb +0 -22
- data/spec/inheritance/caixa_spec.rb +0 -22
- data/spec/inheritance/hsbc_spec.rb +0 -22
- data/spec/inheritance/itau_spec.rb +0 -22
- data/spec/inheritance/real_spec.rb +0 -22
- data/spec/inheritance/santander_spec.rb +0 -22
- data/spec/inheritance/sicoob_spec.rb +0 -22
- data/spec/inheritance/sicredi_spec.rb +0 -22
- data/spec/shared_examples/boleto_bancario_shared_example.rb +0 -151
- data/spec/spec_helper.rb +0 -14
data/Planning.markdown
DELETED
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
# BoletoBancario
|
|
2
|
-
|
|
3
|
-
Emissão de Boletos Bancários em Ruby. Simples, fácil e principalmente, flexível.
|
|
4
|
-
|
|
5
|
-
## Formatos
|
|
6
|
-
|
|
7
|
-
* TODO: Essa parte ainda pode mudar até a versão 0.0.1.
|
|
8
|
-
|
|
9
|
-
Colocar na classe:
|
|
10
|
-
|
|
11
|
-
```ruby
|
|
12
|
-
class BoletoItau < BoletoBancario::Itau
|
|
13
|
-
respond_to :html, :pdf, :png
|
|
14
|
-
end
|
|
15
|
-
```
|
|
16
|
-
|
|
17
|
-
Para renderizar o html:
|
|
18
|
-
|
|
19
|
-
```ruby
|
|
20
|
-
itau = BoletoItau.new
|
|
21
|
-
|
|
22
|
-
itau.respond_with # Irá chamar o método render da instância do objeto passado no método format.
|
|
23
|
-
|
|
24
|
-
itau.respond_with(:pdf)
|
|
25
|
-
```
|
|
26
|
-
|
|
27
|
-
### Criando um novo Formato
|
|
28
|
-
|
|
29
|
-
Em relação a parte de formatos a gem de boleto bancário é extremamente flexível.
|
|
30
|
-
|
|
31
|
-
Basta criar um objeto que responda ao método **render**:
|
|
32
|
-
|
|
33
|
-
```ruby
|
|
34
|
-
module BoletoBancario
|
|
35
|
-
module Formato
|
|
36
|
-
class Html < Boleto
|
|
37
|
-
def render(*args)
|
|
38
|
-
end
|
|
39
|
-
end
|
|
40
|
-
end
|
|
41
|
-
end
|
|
42
|
-
```
|
|
43
|
-
|
|
44
|
-
```ruby
|
|
45
|
-
module BoletoBancario
|
|
46
|
-
module Formato
|
|
47
|
-
class Pdf < Boleto
|
|
48
|
-
def render(*args)
|
|
49
|
-
end
|
|
50
|
-
end
|
|
51
|
-
end
|
|
52
|
-
end
|
|
53
|
-
```
|
|
54
|
-
|
|
55
|
-
## Contribuições
|
|
56
|
-
|
|
57
|
-
Seja um contribuidor. Você pode contribuir de N formas. Seguem elas:
|
|
58
|
-
|
|
59
|
-
* Homologando boletos junto ao banco.
|
|
60
|
-
* Fornecendo documentações mais atualizadas dos Bancos.
|
|
61
|
-
* Escrevendo novos formatos (PDF, PNG), e me avisando para divulgar no Readme.
|
|
62
|
-
* Refatorando código!!
|
|
63
|
-
* Fornecendo Feedback construtivo! (Sempre bem vindo!)
|
data/Rakefile
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
# encoding: utf-8
|
|
2
|
-
require 'bundler/gem_tasks'
|
|
3
|
-
require 'yard'
|
|
4
|
-
require 'rspec/core/rake_task'
|
|
5
|
-
|
|
6
|
-
task :default => :spec
|
|
7
|
-
|
|
8
|
-
desc 'Running Tests'
|
|
9
|
-
RSpec::Core::RakeTask.new(:spec)
|
|
10
|
-
|
|
11
|
-
desc 'Generate documentation'
|
|
12
|
-
YARD::Rake::YardocTask.new do |t|
|
|
13
|
-
t.files = ['lib/**/*.rb', '-', 'LICENSE']
|
|
14
|
-
t.options = ['--main', 'README.markdown', '--no-private', '--title', "Boleto Bancário #{BoletoBancario::VERSION}"]
|
|
15
|
-
end
|
data/TODO.markdown
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
# Road to 1.0.0
|
|
2
|
-
|
|
3
|
-
## Código de barras
|
|
4
|
-
|
|
5
|
-
* Colocar a gem barby para gerar a imagem do código de barras.
|
|
6
|
-
|
|
7
|
-
## Layout
|
|
8
|
-
|
|
9
|
-
* Verificar a questão dos formatos (html, pdf, png).
|
|
10
|
-
|
|
11
|
-
# Outros
|
|
12
|
-
|
|
13
|
-
* Logo dos bancos.
|
|
14
|
-
* Formatacao documento (CPF/CNPJ).
|
|
15
|
-
* Colocar exemplos melhores na documentação de cada banco.
|
|
16
|
-
* Nos exemplos de cada banco colocar os métodos que são chamados pelo objeto.
|
|
17
|
-
* Verificar as validações e suas mensagens de erro.
|
|
18
|
-
* Internacionalização / Locales.
|
|
19
|
-
* Criar páginas explicando cada banco.
|
data/boleto_bancario.gemspec
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
|
2
|
-
require File.expand_path('../lib/boleto_bancario/version', __FILE__)
|
|
3
|
-
|
|
4
|
-
Gem::Specification.new do |gem|
|
|
5
|
-
gem.authors = ["Tomas D'Stefano"]
|
|
6
|
-
gem.email = ["tomas_stefano@successoft.com"]
|
|
7
|
-
gem.description = %q{Emissão de Boletos Bancários em Ruby}
|
|
8
|
-
gem.summary = %q{Emissão de Boletos Bancários em Ruby}
|
|
9
|
-
gem.homepage = "https://github.com/tomas-stefano/boleto_bancario"
|
|
10
|
-
|
|
11
|
-
gem.files = `git ls-files`.split($\).reject { |f| File.extname(f) == '.pdf' }
|
|
12
|
-
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
|
13
|
-
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
|
14
|
-
gem.name = "boleto_bancario"
|
|
15
|
-
gem.require_paths = ["lib"]
|
|
16
|
-
gem.version = BoletoBancario::VERSION
|
|
17
|
-
|
|
18
|
-
gem.add_dependency "rake"
|
|
19
|
-
gem.add_dependency "activesupport", "~> 4.1"
|
|
20
|
-
gem.add_dependency "activemodel", "~> 4.1"
|
|
21
|
-
gem.add_dependency "barby"
|
|
22
|
-
|
|
23
|
-
gem.add_development_dependency "rspec", "~> 2.13"
|
|
24
|
-
gem.add_development_dependency "yard"
|
|
25
|
-
gem.add_development_dependency "valid_attribute", "~> 1.3"
|
|
26
|
-
gem.add_development_dependency "pry", "~> 0.9"
|
|
27
|
-
gem.add_development_dependency "simplecov", "~> 0.2"
|
|
28
|
-
gem.add_development_dependency "simplecov-html", "~> 0.7"
|
|
29
|
-
end
|
|
Binary file
|
|
@@ -1,170 +0,0 @@
|
|
|
1
|
-
# encoding: utf-8
|
|
2
|
-
module BoletoBancario
|
|
3
|
-
module Core
|
|
4
|
-
# Implementação de emissão de boleto bancário pelo Banco HSBC.
|
|
5
|
-
#
|
|
6
|
-
# === Documentação Implementada
|
|
7
|
-
#
|
|
8
|
-
# A documentação na qual essa implementação foi baseada está localizada na pasta
|
|
9
|
-
# 'documentacoes_dos_boletos/hsbc' dentro dessa biblioteca.
|
|
10
|
-
#
|
|
11
|
-
# === Carteiras
|
|
12
|
-
# ______________________________________________
|
|
13
|
-
# | Carteira | Descrição | Produto |
|
|
14
|
-
# | CNR | Cobrança não Registrada | 2 |
|
|
15
|
-
# |______________________________________________|
|
|
16
|
-
#
|
|
17
|
-
class Hsbc < Boleto
|
|
18
|
-
# Tamanho máximo do código do cedente emitido no Boleto.
|
|
19
|
-
# <b>Método criado justamente para ficar documentado o tamanho máximo aceito até a data corrente.</b>
|
|
20
|
-
#
|
|
21
|
-
# @return [Fixnum] 7
|
|
22
|
-
#
|
|
23
|
-
def self.tamanho_maximo_codigo_cedente
|
|
24
|
-
7
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
# Tamanho máximo do número do documento emitido no Boleto.
|
|
28
|
-
# <b>Método criado justamente para ficar documentado o tamanho máximo aceito até a data corrente.</b>
|
|
29
|
-
#
|
|
30
|
-
# @return [Fixnum] 13
|
|
31
|
-
#
|
|
32
|
-
def self.tamanho_maximo_numero_documento
|
|
33
|
-
13
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
# <b>Carteiras suportadas.</b>
|
|
37
|
-
# <b>Método criado para validar se a carteira informada é suportada.</b>
|
|
38
|
-
#
|
|
39
|
-
# @return [Array]
|
|
40
|
-
#
|
|
41
|
-
def self.carteiras_suportadas
|
|
42
|
-
%w[CNR]
|
|
43
|
-
end
|
|
44
|
-
|
|
45
|
-
# Validações para os campos abaixo:
|
|
46
|
-
#
|
|
47
|
-
# * Conta Corrente
|
|
48
|
-
# * Número do documento
|
|
49
|
-
#
|
|
50
|
-
# Se você quiser sobrescrever os metodos, <b>ficará a sua responsabilidade.</b>
|
|
51
|
-
# Basta você sobrescrever os métodos de validação:
|
|
52
|
-
#
|
|
53
|
-
# class Hsbc < BoletoBancario::Core::Hsbc
|
|
54
|
-
# def self.tamanho_maximo_codigo_cedente
|
|
55
|
-
# 5
|
|
56
|
-
# end
|
|
57
|
-
#
|
|
58
|
-
# def self.tamanho_maximo_numero_documento
|
|
59
|
-
# 10
|
|
60
|
-
# end
|
|
61
|
-
# end
|
|
62
|
-
#
|
|
63
|
-
# Obs.: Mudar as regras de validação podem influenciar na emissão do boleto em si.
|
|
64
|
-
# Talvez você precise analisar o efeito no #codigo_de_barras e na #linha_digitável (ambos podem ser
|
|
65
|
-
# sobreescritos também).
|
|
66
|
-
#
|
|
67
|
-
validates :codigo_cedente, presence: true
|
|
68
|
-
|
|
69
|
-
validates :codigo_cedente, length: { maximum: tamanho_maximo_codigo_cedente }, if: :deve_validar_codigo_cedente?
|
|
70
|
-
validates :numero_documento, length: { maximum: tamanho_maximo_numero_documento }, if: :deve_validar_numero_documento?
|
|
71
|
-
|
|
72
|
-
validates :carteira, inclusion: { in: ->(object) { object.class.carteiras_suportadas } }, if: :deve_validar_carteira?
|
|
73
|
-
|
|
74
|
-
# @return [String] 7 caracteres
|
|
75
|
-
#
|
|
76
|
-
def codigo_cedente
|
|
77
|
-
@codigo_cedente.to_s.rjust(7, '0') if @codigo_cedente.present?
|
|
78
|
-
end
|
|
79
|
-
|
|
80
|
-
# @return [String] 13 caracteres
|
|
81
|
-
#
|
|
82
|
-
def numero_documento
|
|
83
|
-
@numero_documento.to_s.rjust(13, '0') if @numero_documento.present?
|
|
84
|
-
end
|
|
85
|
-
|
|
86
|
-
def produto
|
|
87
|
-
'2'
|
|
88
|
-
end
|
|
89
|
-
|
|
90
|
-
# @return [String] Código do Banco descrito na documentação.
|
|
91
|
-
#
|
|
92
|
-
def codigo_banco
|
|
93
|
-
'399'
|
|
94
|
-
end
|
|
95
|
-
|
|
96
|
-
# @return [String] Não possui dígito do código do banco.
|
|
97
|
-
#
|
|
98
|
-
def digito_codigo_banco
|
|
99
|
-
'9'
|
|
100
|
-
end
|
|
101
|
-
|
|
102
|
-
# Campo Agência / Código do Cedente
|
|
103
|
-
#
|
|
104
|
-
# @return [String]
|
|
105
|
-
#
|
|
106
|
-
def agencia_codigo_cedente
|
|
107
|
-
"#{codigo_cedente}"
|
|
108
|
-
end
|
|
109
|
-
|
|
110
|
-
# Nosso numero calculado pelo Tipo Identificador 4 descrito na documentação
|
|
111
|
-
#
|
|
112
|
-
# @return [String]
|
|
113
|
-
#
|
|
114
|
-
def nosso_numero
|
|
115
|
-
"#{numero_documento}#{nosso_numero_dv_1}#{tipo_identificador}#{nosso_numero_dv_2}"
|
|
116
|
-
end
|
|
117
|
-
|
|
118
|
-
def nosso_numero_dv_1
|
|
119
|
-
Modulo11FatorDe9a2.new(numero_documento)
|
|
120
|
-
end
|
|
121
|
-
|
|
122
|
-
def tipo_identificador
|
|
123
|
-
4
|
|
124
|
-
end
|
|
125
|
-
|
|
126
|
-
def nosso_numero_dv_2
|
|
127
|
-
soma = "#{numero_documento}#{nosso_numero_dv_1}#{tipo_identificador}".to_i
|
|
128
|
-
soma += codigo_cedente.to_i
|
|
129
|
-
soma += data_vencimento_para_calculo.to_i
|
|
130
|
-
|
|
131
|
-
Modulo11FatorDe9a2.new(soma)
|
|
132
|
-
end
|
|
133
|
-
|
|
134
|
-
# Data do vencimento para ser usada no calculo do segundto dígito identificador do nosso numero
|
|
135
|
-
#
|
|
136
|
-
# Exemplo: 18/03/2015 => 180315
|
|
137
|
-
#
|
|
138
|
-
# @return [String]
|
|
139
|
-
#
|
|
140
|
-
def data_vencimento_para_calculo
|
|
141
|
-
@data_vencimento.strftime('%d%m%y') if @data_vencimento.present?
|
|
142
|
-
end
|
|
143
|
-
|
|
144
|
-
# === Código de barras do banco
|
|
145
|
-
#
|
|
146
|
-
# _______________________________________________________________________________________
|
|
147
|
-
# | Posição | Tamanho | Descrição |
|
|
148
|
-
# |----------|---------|------------------------------------------------------------------|
|
|
149
|
-
# | 20 - 26 | 07 | Código do Cedente |
|
|
150
|
-
# | 27 - 39 | 13 | Código do Documento |
|
|
151
|
-
# | 40 - 43 | 04 | Data de Vencimento no Formato Juliano. |
|
|
152
|
-
# | 44 – 44 | 01 | Código do Produto CNR, número 2. |
|
|
153
|
-
# |_______________________________________________________________________________________|
|
|
154
|
-
#
|
|
155
|
-
# @return [String]
|
|
156
|
-
#
|
|
157
|
-
def codigo_de_barras_do_banco
|
|
158
|
-
"#{codigo_cedente}#{numero_documento}#{data_vencimento_formato_juliano}#{produto}"
|
|
159
|
-
end
|
|
160
|
-
|
|
161
|
-
# Data do vencimento no formato Juliano composta por 4 dígitos
|
|
162
|
-
#
|
|
163
|
-
# @return [String]
|
|
164
|
-
#
|
|
165
|
-
def data_vencimento_formato_juliano
|
|
166
|
-
"#{@data_vencimento.yday.to_s.rjust(3, '0')}#{@data_vencimento.year.to_s.last}" if @data_vencimento.present?
|
|
167
|
-
end
|
|
168
|
-
end
|
|
169
|
-
end
|
|
170
|
-
end
|
|
@@ -1,177 +0,0 @@
|
|
|
1
|
-
# encoding: utf-8
|
|
2
|
-
module BoletoBancario
|
|
3
|
-
module Core
|
|
4
|
-
# Implementação de emissão de boleto bancário pelo Banco Real.
|
|
5
|
-
#
|
|
6
|
-
# === Documentação Implementada
|
|
7
|
-
#
|
|
8
|
-
# A documentação na qual essa implementação foi baseada está localizada na pasta
|
|
9
|
-
# 'documentacoes_dos_boletos/real' dentro dessa biblioteca.
|
|
10
|
-
#
|
|
11
|
-
# Cobrança sem registro:
|
|
12
|
-
# Nosso número: 13 dígitos
|
|
13
|
-
# Código da Agência: 4 dígitos
|
|
14
|
-
# Número da Conta: 7 dígitos
|
|
15
|
-
#
|
|
16
|
-
# === Código da Carteira
|
|
17
|
-
#
|
|
18
|
-
# '00' - Carteira do convênio
|
|
19
|
-
# '20' - Cobrança Simples
|
|
20
|
-
# '31' - Cobrança Câmbio
|
|
21
|
-
# '42' - Cobrança Caucionada
|
|
22
|
-
# '47' - Cobr. Caucionada Crédito Imobiliário
|
|
23
|
-
# '85' - Cobrança Partilhada
|
|
24
|
-
#
|
|
25
|
-
class Real < Boleto
|
|
26
|
-
# Tamanho máximo de uma agência no Banco Real.
|
|
27
|
-
# <b>Método criado justamente para ficar documentado o tamanho máximo aceito até a data corrente.</b>
|
|
28
|
-
#
|
|
29
|
-
# @return [Fixnum] 4
|
|
30
|
-
#
|
|
31
|
-
def self.tamanho_maximo_agencia
|
|
32
|
-
4
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
# Tamanho máximo da conta corrente no Boleto.
|
|
36
|
-
# <b>Método criado justamente para ficar documentado o tamanho máximo aceito até a data corrente.</b>
|
|
37
|
-
#
|
|
38
|
-
# @return [Fixnum] 7
|
|
39
|
-
#
|
|
40
|
-
def self.tamanho_maximo_conta_corrente
|
|
41
|
-
7
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
# Tamanho máximo do numero do documento no Boleto.
|
|
45
|
-
# <b>Método criado justamente para ficar documentado o tamanho máximo aceito até a data corrente.</b>
|
|
46
|
-
#
|
|
47
|
-
# @return [Fixnum] 13
|
|
48
|
-
#
|
|
49
|
-
def self.tamanho_maximo_numero_documento
|
|
50
|
-
13
|
|
51
|
-
end
|
|
52
|
-
|
|
53
|
-
# <b>Carteiras suportadas.</b>
|
|
54
|
-
#
|
|
55
|
-
# <b>Método criado para validar se a carteira informada é suportada.</b>
|
|
56
|
-
#
|
|
57
|
-
# @return [Array]
|
|
58
|
-
#
|
|
59
|
-
def self.carteiras_suportadas
|
|
60
|
-
%w[00 20 31 42 47 85]
|
|
61
|
-
end
|
|
62
|
-
|
|
63
|
-
# Validações para os campos abaixo:
|
|
64
|
-
#
|
|
65
|
-
# * Agencia
|
|
66
|
-
# * Conta Corrente
|
|
67
|
-
# * Número do documento
|
|
68
|
-
#
|
|
69
|
-
# Se você quiser sobrescrever os metodos, <b>ficará a sua responsabilidade.</b>
|
|
70
|
-
# Basta você sobrescrever os métodos de validação:
|
|
71
|
-
#
|
|
72
|
-
# class Real < BoletoBancario::Core::Real
|
|
73
|
-
# def self.tamanho_maximo_agencia
|
|
74
|
-
# 6
|
|
75
|
-
# end
|
|
76
|
-
#
|
|
77
|
-
# def self.tamanho_maximo_conta_corrente
|
|
78
|
-
# 9
|
|
79
|
-
# end
|
|
80
|
-
#
|
|
81
|
-
# def self.tamanho_maximo_numero_documento
|
|
82
|
-
# 10
|
|
83
|
-
# end
|
|
84
|
-
# end
|
|
85
|
-
#
|
|
86
|
-
# Obs.: Mudar as regras de validação podem influenciar na emissão do boleto em si.
|
|
87
|
-
# Talvez você precise analisar o efeito no #codigo_de_barras e na #linha_digitável (ambos podem ser
|
|
88
|
-
# sobreescritos também).
|
|
89
|
-
#
|
|
90
|
-
validates :agencia, :conta_corrente, presence: true
|
|
91
|
-
|
|
92
|
-
validates :agencia, length: { maximum: tamanho_maximo_agencia }, if: :deve_validar_agencia?
|
|
93
|
-
validates :conta_corrente, length: { maximum: tamanho_maximo_conta_corrente }, if: :deve_validar_conta_corrente?
|
|
94
|
-
validates :numero_documento, length: { maximum: tamanho_maximo_numero_documento }, if: :deve_validar_numero_documento?
|
|
95
|
-
|
|
96
|
-
validates :carteira, inclusion: { in: ->(object) { object.class.carteiras_suportadas } }, if: :deve_validar_carteira?
|
|
97
|
-
|
|
98
|
-
# @return [String] 4 caracteres
|
|
99
|
-
#
|
|
100
|
-
def agencia
|
|
101
|
-
@agencia.to_s.rjust(4, '0') if @agencia.present?
|
|
102
|
-
end
|
|
103
|
-
|
|
104
|
-
# @return [String] 7 caracteres
|
|
105
|
-
#
|
|
106
|
-
def conta_corrente
|
|
107
|
-
@conta_corrente.to_s.rjust(7, '0') if @conta_corrente.present?
|
|
108
|
-
end
|
|
109
|
-
|
|
110
|
-
# @return [String] 13 caracteres
|
|
111
|
-
#
|
|
112
|
-
def numero_documento
|
|
113
|
-
@numero_documento.to_s.rjust(13, '0') if @numero_documento.present?
|
|
114
|
-
end
|
|
115
|
-
|
|
116
|
-
# @return [String] 2 caracteres
|
|
117
|
-
#
|
|
118
|
-
def carteira
|
|
119
|
-
@carteira.to_s.rjust(2, '0') if @carteira.present?
|
|
120
|
-
end
|
|
121
|
-
|
|
122
|
-
# @return [String] Código do Banco descrito na documentação.
|
|
123
|
-
#
|
|
124
|
-
def codigo_banco
|
|
125
|
-
'356'
|
|
126
|
-
end
|
|
127
|
-
|
|
128
|
-
# @return [String] Dígito do código do banco descrito na documentação.
|
|
129
|
-
#
|
|
130
|
-
def digito_codigo_banco
|
|
131
|
-
'5'
|
|
132
|
-
end
|
|
133
|
-
|
|
134
|
-
# Campo Agência/Código Cedente
|
|
135
|
-
#
|
|
136
|
-
# @return [String] Campo descrito na documentação.
|
|
137
|
-
#
|
|
138
|
-
def agencia_codigo_cedente
|
|
139
|
-
"#{agencia}/#{conta_corrente}/#{cobranca_dv}"
|
|
140
|
-
end
|
|
141
|
-
|
|
142
|
-
# Cálculo do Digito verificador da Cobrança
|
|
143
|
-
# Nosso Número + Agência + Conta Corrente
|
|
144
|
-
# Calculado atravez do modulo 10
|
|
145
|
-
#
|
|
146
|
-
# @return [String]
|
|
147
|
-
#
|
|
148
|
-
def cobranca_dv
|
|
149
|
-
Modulo10.new("#{nosso_numero}#{agencia}#{conta_corrente}")
|
|
150
|
-
end
|
|
151
|
-
|
|
152
|
-
# O nosso numero é o mesmo numero que o cliente informa para o numero do documento
|
|
153
|
-
#
|
|
154
|
-
# @return [String]
|
|
155
|
-
#
|
|
156
|
-
def nosso_numero
|
|
157
|
-
"#{numero_documento}"
|
|
158
|
-
end
|
|
159
|
-
|
|
160
|
-
# === Código de barras do banco
|
|
161
|
-
# ____________________________________________________
|
|
162
|
-
# | Posição | Tamanho | Descrição |
|
|
163
|
-
# |---------|---------|--------------------------------|
|
|
164
|
-
# | 20 – 23 | 04 | Agencia |
|
|
165
|
-
# | 24 – 30 | 07 | Conta corrente |
|
|
166
|
-
# | 31 – 31 | 01 | Digito verificador da cobrança |
|
|
167
|
-
# | 32 – 44 | 13 | Nosso numero |
|
|
168
|
-
# |____________________________________________________|
|
|
169
|
-
#
|
|
170
|
-
# @return [String]
|
|
171
|
-
#
|
|
172
|
-
def codigo_de_barras_do_banco
|
|
173
|
-
"#{agencia}#{conta_corrente}#{cobranca_dv}#{nosso_numero}"
|
|
174
|
-
end
|
|
175
|
-
end
|
|
176
|
-
end
|
|
177
|
-
end
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
require 'spec_helper'
|
|
2
|
-
|
|
3
|
-
module BoletoBancario
|
|
4
|
-
module Calculos
|
|
5
|
-
describe Digitos do
|
|
6
|
-
(0..9).each do |number|
|
|
7
|
-
it "should return self when is #{number}" do
|
|
8
|
-
Digitos.new(number).sum.should eq number
|
|
9
|
-
end
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
{ 11 => 2, '18' => 9, 99 => 18, '58' => 13, 112 => 4, '235' => 10 }.each do |number, expecting|
|
|
13
|
-
it "should sum the sum of the digits when is '#{number}', expecting to be '#{expecting}'" do
|
|
14
|
-
Digitos.new(number).sum.should eq expecting
|
|
15
|
-
end
|
|
16
|
-
end
|
|
17
|
-
end
|
|
18
|
-
end
|
|
19
|
-
end
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
require 'spec_helper'
|
|
2
|
-
|
|
3
|
-
module BoletoBancario
|
|
4
|
-
module Calculos
|
|
5
|
-
describe FatorVencimento do
|
|
6
|
-
describe "#base_date" do
|
|
7
|
-
it "should be 1997-10-07" do
|
|
8
|
-
FatorVencimento.new(Date.parse("2012-02-01")).base_date.should eq Date.new(1997, 10, 7)
|
|
9
|
-
end
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
describe "#calculate" do
|
|
13
|
-
it 'should return an empty string when passing nil value' do
|
|
14
|
-
FatorVencimento.new(nil).should eq ''
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
it 'should return an empty string when passing empty value' do
|
|
18
|
-
FatorVencimento.new('').should eq ''
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
it "should calculate the days between expiration date and base date" do
|
|
22
|
-
FatorVencimento.new(Date.parse("2012-12-2")).should eq "5535"
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
it "should calculate equal to itau documentation example" do
|
|
26
|
-
FatorVencimento.new(Date.parse("2000-07-04")).should eq "1001"
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
it "should calculate equal to itau documentation last section of the docs" do
|
|
30
|
-
FatorVencimento.new(Date.parse("2002-05-01")).should eq "1667"
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
it "should calculate to the maximum date equal to itau documentation example" do
|
|
34
|
-
FatorVencimento.new(Date.parse("2025-02-21")).should eq "9999"
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
it "should calculate the days between expiration date one year ago" do
|
|
38
|
-
FatorVencimento.new(Date.parse("2011-05-25")).should eq "4978"
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
it "should calculate the days between expiration date two years ago" do
|
|
42
|
-
FatorVencimento.new(Date.parse("2010-10-02")).should eq "4743"
|
|
43
|
-
end
|
|
44
|
-
|
|
45
|
-
it "should calculate the days between expiration date one year from now" do
|
|
46
|
-
FatorVencimento.new(Date.parse("2013-02-01")).should eq "5596"
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
it "should calculate the days between expiration date eigth years from now" do
|
|
50
|
-
FatorVencimento.new(Date.parse("2020-02-01")).should eq "8152"
|
|
51
|
-
end
|
|
52
|
-
|
|
53
|
-
it "should calculate the days between expiration date formating with 4 digits" do
|
|
54
|
-
FatorVencimento.new(Date.parse("1997-10-08")).should eq "0001"
|
|
55
|
-
end
|
|
56
|
-
end
|
|
57
|
-
end
|
|
58
|
-
end
|
|
59
|
-
end
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
require 'spec_helper'
|
|
2
|
-
|
|
3
|
-
module BoletoBancario
|
|
4
|
-
module Calculos
|
|
5
|
-
describe FatoresDeMultiplicacao do
|
|
6
|
-
context 'with factors of 2 and 1' do
|
|
7
|
-
let(:factors) { [2, 1] }
|
|
8
|
-
|
|
9
|
-
context 'with one digit' do
|
|
10
|
-
subject { FatoresDeMultiplicacao.new(1, fatores: factors) }
|
|
11
|
-
|
|
12
|
-
it { should eq [2] }
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
context 'with four digits' do
|
|
16
|
-
subject { FatoresDeMultiplicacao.new(1234, fatores: factors) }
|
|
17
|
-
|
|
18
|
-
it { should eq [1, 4, 3, 8] }
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
context 'with five digits' do
|
|
22
|
-
subject { FatoresDeMultiplicacao.new(11385, fatores: factors) }
|
|
23
|
-
|
|
24
|
-
it { should eq [2, 1, 6, 8, 10] }
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
context 'with ten digits' do
|
|
28
|
-
subject { FatoresDeMultiplicacao.new(1234567890, fatores: factors) }
|
|
29
|
-
|
|
30
|
-
it { should eq [1, 4, 3, 8, 5, 12, 7, 16, 9, 0] }
|
|
31
|
-
end
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
context 'with factors of 2..9' do
|
|
35
|
-
let(:factors) { (2..9).to_a }
|
|
36
|
-
|
|
37
|
-
context 'with one digit' do
|
|
38
|
-
subject { FatoresDeMultiplicacao.new(4, fatores: factors) }
|
|
39
|
-
|
|
40
|
-
it { should eq [8] }
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
context 'with four digits' do
|
|
44
|
-
subject { FatoresDeMultiplicacao.new(1864, fatores: factors) }
|
|
45
|
-
|
|
46
|
-
it { should eq [ 5, 32, 18, 8] }
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
context 'with ten digits' do
|
|
50
|
-
subject { FatoresDeMultiplicacao.new(1234567890, fatores: factors) }
|
|
51
|
-
end
|
|
52
|
-
|
|
53
|
-
context 'with bradesco documentation example' do
|
|
54
|
-
let(:bradesco_example) { '9999101200000350007772130530150081897500000' }
|
|
55
|
-
subject { FatoresDeMultiplicacao.new(bradesco_example, fatores: factors) }
|
|
56
|
-
|
|
57
|
-
it { should eq [36, 27, 18, 81, 8, 0, 6, 10, 0, 0, 0, 0, 0, 21, 30, 0, 0, 0, 14, 63, 56, 14, 6, 15, 0, 15, 6, 0, 8, 35, 0, 0, 32, 3, 16, 81, 56, 35, 0, 0, 0, 0, 0] }
|
|
58
|
-
end
|
|
59
|
-
|
|
60
|
-
context 'with itau documentation example' do
|
|
61
|
-
let(:itau_example) { '3419166700000123451101234567880057123457000' }
|
|
62
|
-
subject { FatoresDeMultiplicacao.new(itau_example, fatores: factors) }
|
|
63
|
-
|
|
64
|
-
it { should eq [12, 12, 2, 81, 8, 42, 36, 35, 0, 0, 0, 0, 0, 7, 12, 15, 16, 15, 2, 9, 0, 7, 12, 15, 16, 15, 12, 63, 64, 56, 0, 0, 20, 21, 2, 18, 24, 28, 30, 35, 0, 0, 0] }
|
|
65
|
-
end
|
|
66
|
-
end
|
|
67
|
-
end
|
|
68
|
-
end
|
|
69
|
-
end
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
require 'spec_helper'
|
|
2
|
-
|
|
3
|
-
module BoletoBancario
|
|
4
|
-
module Calculos
|
|
5
|
-
describe LinhaDigitavel do
|
|
6
|
-
context "using the Itau documentation example" do
|
|
7
|
-
subject { LinhaDigitavel.new('34196166700000123451091234567880057123457000') }
|
|
8
|
-
|
|
9
|
-
it { should eq '34191.09123 34567.880058 71234.570001 6 16670000012345' }
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
context "using the Bradesco documentation example" do
|
|
13
|
-
subject { LinhaDigitavel.new('99991101200000350007772130530150081897500000') }
|
|
14
|
-
|
|
15
|
-
it { should eq '99997.77213 30530.150082 18975.000003 1 10120000035000' }
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
context "using the HSBC documentation example" do
|
|
19
|
-
subject { LinhaDigitavel.new('39998100100000311551111122222500546666666001') }
|
|
20
|
-
|
|
21
|
-
it { should eq '39991.11119 22222.500542 66666.660015 8 10010000031155' }
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
context "using the Caixa documentation example" do
|
|
25
|
-
subject { LinhaDigitavel.new('10491107400000160000001100128701000901200200') }
|
|
26
|
-
|
|
27
|
-
it { should eq '10490.00118 00128.701000 09012.002003 1 10740000016000' }
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
describe "when 'codigo_de_barras' invalid" do
|
|
31
|
-
context "when is empty" do
|
|
32
|
-
subject { LinhaDigitavel.new('') }
|
|
33
|
-
|
|
34
|
-
it { should eq '' }
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
context "when nil" do
|
|
38
|
-
subject { LinhaDigitavel.new(nil) }
|
|
39
|
-
|
|
40
|
-
it { should eq '' }
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
context "when have less than 44 positions" do
|
|
44
|
-
subject { LinhaDigitavel.new('121212121') }
|
|
45
|
-
|
|
46
|
-
it { should eq '' }
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
context "when have more than 44 positions" do
|
|
50
|
-
subject { LinhaDigitavel.new('12345678901234567890123456789012345678901234567890') }
|
|
51
|
-
|
|
52
|
-
it { should eq '' }
|
|
53
|
-
end
|
|
54
|
-
end
|
|
55
|
-
end
|
|
56
|
-
end
|
|
57
|
-
end
|