conectiva-boleto_bancario 0.0.2.beta

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.
Files changed (52) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +18 -0
  3. data/.rspec +1 -0
  4. data/.rvmrc +1 -0
  5. data/Changelog.markdown +10 -0
  6. data/Gemfile +3 -0
  7. data/LICENSE +22 -0
  8. data/Planning.markdown +137 -0
  9. data/README.markdown +215 -0
  10. data/Rakefile +9 -0
  11. data/TODO.markdown +11 -0
  12. data/boleto_bancario.gemspec +25 -0
  13. data/documentacoes_dos_boletos/Bradesco/Manual_BRADESCO.PDF +0 -0
  14. data/lib/boleto_bancario.rb +85 -0
  15. data/lib/boleto_bancario/calculos/digitos.rb +35 -0
  16. data/lib/boleto_bancario/calculos/fator_vencimento.rb +87 -0
  17. data/lib/boleto_bancario/calculos/fatores_de_multiplicacao.rb +67 -0
  18. data/lib/boleto_bancario/calculos/linha_digitavel.rb +158 -0
  19. data/lib/boleto_bancario/calculos/modulo10.rb +83 -0
  20. data/lib/boleto_bancario/calculos/modulo11.rb +54 -0
  21. data/lib/boleto_bancario/calculos/modulo11_fator_de2a7.rb +97 -0
  22. data/lib/boleto_bancario/calculos/modulo11_fator_de2a9.rb +83 -0
  23. data/lib/boleto_bancario/calculos/modulo11_fator_de2a9_resto_zero.rb +29 -0
  24. data/lib/boleto_bancario/calculos/modulo11_fator_de9a2_resto_x.rb +101 -0
  25. data/lib/boleto_bancario/calculos/modulo_numero_de_controle.rb +117 -0
  26. data/lib/boleto_bancario/core/banco_brasil.rb +532 -0
  27. data/lib/boleto_bancario/core/banrisul.rb +182 -0
  28. data/lib/boleto_bancario/core/boleto.rb +559 -0
  29. data/lib/boleto_bancario/core/bradesco.rb +285 -0
  30. data/lib/boleto_bancario/core/itau.rb +455 -0
  31. data/lib/boleto_bancario/core/santander.rb +273 -0
  32. data/lib/boleto_bancario/version.rb +4 -0
  33. data/spec/boleto_bancario/calculos/digitos_spec.rb +19 -0
  34. data/spec/boleto_bancario/calculos/fator_vencimento_spec.rb +59 -0
  35. data/spec/boleto_bancario/calculos/fatores_de_multiplicacao_spec.rb +69 -0
  36. data/spec/boleto_bancario/calculos/linha_digitavel_spec.rb +57 -0
  37. data/spec/boleto_bancario/calculos/modulo10_spec.rb +53 -0
  38. data/spec/boleto_bancario/calculos/modulo11_fator_de2a7_spec.rb +43 -0
  39. data/spec/boleto_bancario/calculos/modulo11_fator_de2a9_resto_zero_spec.rb +39 -0
  40. data/spec/boleto_bancario/calculos/modulo11_fator_de2a9_spec.rb +67 -0
  41. data/spec/boleto_bancario/calculos/modulo11_fator_de9a2_resto_x_spec.rb +37 -0
  42. data/spec/boleto_bancario/calculos/modulo11_spec.rb +19 -0
  43. data/spec/boleto_bancario/calculos/modulo_numero_de_controle_spec.rb +37 -0
  44. data/spec/boleto_bancario/core/banco_brasil_spec.rb +383 -0
  45. data/spec/boleto_bancario/core/banrisul_spec.rb +130 -0
  46. data/spec/boleto_bancario/core/boleto_spec.rb +161 -0
  47. data/spec/boleto_bancario/core/bradesco_spec.rb +170 -0
  48. data/spec/boleto_bancario/core/itau_spec.rb +336 -0
  49. data/spec/boleto_bancario/core/santander_spec.rb +135 -0
  50. data/spec/shared_examples/boleto_bancario_shared_example.rb +157 -0
  51. data/spec/spec_helper.rb +14 -0
  52. metadata +211 -0
@@ -0,0 +1,130 @@
1
+ require 'spec_helper'
2
+
3
+ module BoletoBancario
4
+ module Core
5
+ describe Banrisul do
6
+ it_should_behave_like 'boleto bancario'
7
+
8
+ describe "on validations" do
9
+ it "agencia should have 3 digits" do
10
+ should have_valid(:agencia).when("1", "123", 1, 123)
11
+ should_not have_valid(:agencia).when(nil, "", "1234")
12
+ end
13
+
14
+ it "digito agencia should have 2 digits (NC)" do
15
+ should have_valid(:digito_agencia).when("12")
16
+ should_not have_valid(:digito_agencia).when(nil, "", "1", "123")
17
+ end
18
+
19
+ it "codigo cedente should have 07 digits" do
20
+ should have_valid(:codigo_cedente).when("1234567", "12", "12345")
21
+ should_not have_valid(:codigo_cedente).when(nil, "", "12345678", "123456789")
22
+ end
23
+
24
+ it "numero_controle_codigo_cedente should have 2 digits" do
25
+ should have_valid(:digito_codigo_cedente).when("12")
26
+ should_not have_valid(:digito_codigo_cedente).when(nil, "", "1", "123", "1234")
27
+ end
28
+
29
+ it "numero documento should have 8 digits" do
30
+ should have_valid(:numero_documento).when("12345678", "1234")
31
+ should_not have_valid(:numero_documento).when(nil, "", "123456789")
32
+ end
33
+ end
34
+
35
+ describe "#agencia" do
36
+ context "when have a value" do
37
+ subject { Banrisul.new(agencia: '34') }
38
+
39
+ its(:agencia) { should eq '034' }
40
+ end
41
+
42
+ context "when is nil" do
43
+ subject { Banrisul.new(agencia: nil) }
44
+
45
+ its(:agencia) { should be nil }
46
+ end
47
+ end
48
+
49
+ describe "#numero_documento" do
50
+ context "when have a value" do
51
+ subject { Banrisul.new(numero_documento: '1234') }
52
+
53
+ its(:numero_documento) { should eq '00001234' }
54
+ end
55
+
56
+ context "when is nil" do
57
+ subject { Banrisul.new(numero_documento: nil) }
58
+
59
+ its(:numero_documento) { should be nil }
60
+ end
61
+ end
62
+
63
+ describe "#codigo_cedente" do
64
+ context "when have a value" do
65
+ subject { Banrisul.new(codigo_cedente: '1234') }
66
+
67
+ its(:codigo_cedente) { should eq '0001234' }
68
+ end
69
+
70
+ context "when is nil" do
71
+ subject { Banrisul.new(codigo_cedente: nil) }
72
+
73
+ its(:codigo_cedente) { should be nil }
74
+ end
75
+ end
76
+
77
+ describe "#codigo_banco" do
78
+ its(:codigo_banco) { should eq '041' }
79
+ end
80
+
81
+ describe "#digito_codigo_banco" do
82
+ its(:digito_codigo_banco) { should eq '8' }
83
+ end
84
+
85
+ describe "#agencia_codigo_cedente" do
86
+ subject { Banrisul.new(agencia: '100', digito_agencia: '81', codigo_cedente: '0000001', digito_codigo_cedente: '83') }
87
+
88
+ its(:agencia_codigo_cedente) { should eq '100.81 0000001.83' }
89
+ end
90
+
91
+ describe "#nosso_numero" do
92
+ context "using one example from documentation" do
93
+ subject { Banrisul.new(numero_documento: '00009194') }
94
+
95
+ its(:nosso_numero) { should eq '00009194.38' }
96
+ end
97
+
98
+ context "using other example from documentation" do
99
+ subject { Banrisul.new(numero_documento: '00009274') }
100
+
101
+ its(:nosso_numero) { should eq '00009274.22' }
102
+ end
103
+
104
+ context "another example" do
105
+ subject { Banrisul.new(numero_documento: '22832563') }
106
+
107
+ its(:nosso_numero) { should eq '22832563.51' }
108
+ end
109
+ end
110
+
111
+ describe "#codigo_de_barras" do
112
+ context "one example" do
113
+ subject do
114
+ Banrisul.new do |boleto|
115
+ boleto.numero_documento = 22832563
116
+ boleto.agencia = 100
117
+ boleto.digito_agencia = 81
118
+ boleto.data_vencimento = Date.parse('2004-07-04')
119
+ boleto.codigo_cedente = "0000001"
120
+ boleto.valor_documento = 5.0
121
+ end
122
+ end
123
+
124
+ its(:codigo_de_barras) { should eq '04197246200000005002110000000012283256304168' }
125
+ its(:linha_digitavel) { should eq '04192.11008 00000.012286 32563.041683 7 24620000000500' }
126
+ end
127
+ end
128
+ end
129
+ end
130
+ end
@@ -0,0 +1,161 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+
4
+ module BoletoBancario
5
+ module Core
6
+ describe Boleto do
7
+ describe '#initialize' do
8
+ context 'when passing a Hash' do
9
+ subject do
10
+ described_class.new(
11
+ :numero_documento => '191075',
12
+ :valor_documento => 101.99,
13
+ :data_vencimento => Date.new(2012, 10, 10),
14
+ :carteira => '175',
15
+ :agencia => '0098',
16
+ :digito_agencia => '1',
17
+ :conta_corrente => '98701',
18
+ :cedente => 'Nome da razao social',
19
+ :sacado => 'Teste',
20
+ :documento_sacado => '725.275.005-10',
21
+ :endereco_sacado => 'Rua teste, 23045'
22
+ )
23
+ end
24
+
25
+ its(:numero_documento) { should eq '191075' }
26
+ its(:valor_documento) { should eq 101.99 }
27
+ its(:data_vencimento) { should eq Date.new(2012, 10, 10) }
28
+ its(:carteira) { should eq '175' }
29
+ its(:agencia) { should eq '0098' }
30
+ its(:digito_agencia) { should eq '1' }
31
+ its(:conta_corrente) { should eq '98701' }
32
+ its(:codigo_moeda) { should eq '9' }
33
+ its(:cedente) { should eq 'Nome da razao social' }
34
+ its(:especie) { should eq 'R$' }
35
+ its(:especie_documento) { should eq 'DM' }
36
+ its(:data_documento) { should eq Date.today }
37
+ its(:sacado) { should eq 'Teste' }
38
+ its(:documento_sacado) { should eq '725.275.005-10' }
39
+ its(:endereco_sacado) { should eq 'Rua teste, 23045'}
40
+ its(:local_pagamento) { should eq 'PAGÁVEL EM QUALQUER BANCO ATÉ O VENCIMENTO' }
41
+ end
42
+
43
+ context 'when passing a block' do
44
+ subject do
45
+ described_class.new do |boleto|
46
+ boleto.numero_documento = '187390'
47
+ boleto.valor_documento = 1
48
+ boleto.data_vencimento = Date.new(2012, 10, 10)
49
+ boleto.carteira = '109'
50
+ boleto.agencia = '0914'
51
+ boleto.conta_corrente = '82369'
52
+ boleto.codigo_cedente = '90182'
53
+ boleto.endereco_cedente = 'Rua Itapaiuna, 2434'
54
+ boleto.cedente = 'Nome da razao social'
55
+ boleto.documento_cedente = '62.526.713/0001-40'
56
+ boleto.sacado = 'Teste'
57
+ end
58
+ end
59
+
60
+ its(:numero_documento) { should eq '187390' }
61
+ its(:valor_documento) { should eq 1 }
62
+ its(:carteira) { should eq '109' }
63
+ its(:agencia) { should eq '0914' }
64
+ its(:conta_corrente) { should eq '82369' }
65
+ its(:codigo_moeda) { should eq '9' }
66
+ its(:codigo_cedente) { should eq '90182' }
67
+ its(:endereco_cedente) { should eq 'Rua Itapaiuna, 2434' }
68
+ its(:cedente) { should eq 'Nome da razao social' }
69
+ its(:documento_cedente) { should eq '62.526.713/0001-40' }
70
+ its(:sacado) { should eq 'Teste' }
71
+ its(:aceite) { should be true }
72
+ end
73
+ end
74
+
75
+ describe "#carteira_formatada" do
76
+ it "should return 'carteira' as default" do
77
+ subject.stub(:carteira).and_return('Foo')
78
+ subject.carteira_formatada.should eq 'Foo'
79
+ end
80
+ end
81
+
82
+ describe "#valor_documento_formatado" do
83
+ context "when period" do
84
+ before { subject.stub(:valor_documento).and_return(123.45) }
85
+
86
+ its(:valor_formatado_para_codigo_de_barras) { should eq '0000012345' }
87
+ end
88
+
89
+ context "when less than ten" do
90
+ before { subject.stub(:valor_documento).and_return(5.0) }
91
+
92
+ its(:valor_formatado_para_codigo_de_barras) { should eq '0000000500'}
93
+ end
94
+
95
+ context "when have many decimal points" do
96
+ before { subject.stub(:valor_documento).and_return(10.999999) }
97
+
98
+ its(:valor_formatado_para_codigo_de_barras) { should eq '0000001099' }
99
+ end
100
+
101
+ context "when integer" do
102
+ before { subject.stub(:valor_documento).and_return(1_999) }
103
+
104
+ its(:valor_formatado_para_codigo_de_barras) { should eq '0000199900' }
105
+ end
106
+
107
+ context "when period with string" do
108
+ before { subject.stub(:valor_documento).and_return('236.91') }
109
+
110
+ its(:valor_formatado_para_codigo_de_barras) { should eq '0000023691' }
111
+ end
112
+
113
+ context "when period with string with many decimals" do
114
+ before { subject.stub(:valor_documento).and_return('10.999999') }
115
+
116
+ its(:valor_formatado_para_codigo_de_barras) { should eq '0000001099' }
117
+ end
118
+ end
119
+
120
+ describe "#aceite_formatado" do
121
+ context "when is true" do
122
+ subject { described_class.new(aceite: true) }
123
+
124
+ its(:aceite_formatado) { should eq 'S' }
125
+ end
126
+
127
+ context "when is false" do
128
+ subject { described_class.new(aceite: false) }
129
+
130
+ its(:aceite_formatado) { should eq 'N' }
131
+ end
132
+
133
+ context "when is nil" do
134
+ subject { described_class.new(aceite: nil) }
135
+
136
+ its(:aceite_formatado) { should eq 'N' }
137
+ end
138
+ end
139
+
140
+ describe "#codigo_banco" do
141
+ it { expect { subject.codigo_banco }.to raise_error(NotImplementedError) }
142
+ end
143
+
144
+ describe "#digito_codigo_banco" do
145
+ it { expect { subject.digito_codigo_banco }.to raise_error(NotImplementedError) }
146
+ end
147
+
148
+ describe "#agencia_codigo_cedente" do
149
+ it { expect { subject.agencia_codigo_cedente }.to raise_error(NotImplementedError) }
150
+ end
151
+
152
+ describe "#nosso_numero" do
153
+ it { expect { subject.nosso_numero }.to raise_error(NotImplementedError) }
154
+ end
155
+
156
+ describe "#codigo_de_barras_do_banco" do
157
+ it { expect { subject.codigo_de_barras_do_banco }.to raise_error(NotImplementedError) }
158
+ end
159
+ end
160
+ end
161
+ end
@@ -0,0 +1,170 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+
4
+ module BoletoBancario
5
+ module Core
6
+ describe Bradesco do
7
+ it_should_behave_like 'boleto bancario'
8
+
9
+ describe "on validations" do
10
+ it { should have_valid(:agencia).when('1', '123', '1234') }
11
+ it { should_not have_valid(:agencia).when('12345', '123456', '1234567', nil, '') }
12
+
13
+ it { should have_valid(:digito_agencia).when('1', 'X', '4') }
14
+ it { should_not have_valid(:digito_agencia).when(nil, '', '12', '123') }
15
+
16
+ it { should have_valid(:conta_corrente).when('1', '123', '1234') }
17
+ it { should_not have_valid(:conta_corrente).when('12345678', '123456789', nil, '') }
18
+
19
+ it { should have_valid(:digito_conta_corrente).when('1', '4', 'X') }
20
+ it { should_not have_valid(:digito_conta_corrente).when(nil, '', '12', '123') }
21
+
22
+ it { should have_valid(:carteira).when(6, '6', '13') }
23
+ it { should_not have_valid(:carteira).when('', nil, '102', '123') }
24
+
25
+ it { should have_valid(:numero_documento).when(12345678911, '12345678911', '13') }
26
+ it { should_not have_valid(:numero_documento).when('', nil, 123456789112, 1234567891113) }
27
+ end
28
+
29
+ describe "#agencia" do
30
+ context "when have a value" do
31
+ subject { Bradesco.new(:agencia => 2) }
32
+
33
+ its(:agencia) { should eq '0002' }
34
+ end
35
+
36
+ context "when is nil" do
37
+ its(:agencia) { should be nil }
38
+ end
39
+ end
40
+
41
+ describe "#conta_corrente" do
42
+ context "when have a value" do
43
+ subject { Bradesco.new(:conta_corrente => 1) }
44
+
45
+ its(:conta_corrente) { should eq '0000001' }
46
+ end
47
+
48
+ context "when is nil" do
49
+ its(:conta_corrente) { should be nil }
50
+ end
51
+ end
52
+
53
+ describe "#numero_documento" do
54
+ context "when have a value" do
55
+ subject { Bradesco.new(:numero_documento => 1234) }
56
+
57
+ its(:numero_documento) { should eq '00000001234' }
58
+ end
59
+
60
+ context "when is nil" do
61
+ its(:numero_documento) { should be nil }
62
+ end
63
+ end
64
+
65
+ describe "#carteira" do
66
+ context "when have a value" do
67
+ subject { Bradesco.new(:carteira => 3) }
68
+
69
+ its(:carteira) { should eq '03' }
70
+ end
71
+
72
+ context "when is nil" do
73
+ its(:carteira) { should be nil }
74
+ end
75
+ end
76
+
77
+ describe "#carteira_formatada" do
78
+ context "when carteira is '21'" do
79
+ subject { Bradesco.new(:carteira => 21) }
80
+
81
+ its(:carteira_formatada) { should eq '21 – Cobrança Interna Com Registro' }
82
+ end
83
+
84
+ context "when carteira is '22'" do
85
+ subject { Bradesco.new(:carteira => 22) }
86
+
87
+ its(:carteira_formatada) { should eq '22 – Cobrança Interna sem registro' }
88
+ end
89
+
90
+ context "when carteira is '03'" do
91
+ subject { Bradesco.new(:carteira => 3) }
92
+
93
+ its(:carteira_formatada) { should eq '03' }
94
+ end
95
+ end
96
+
97
+ describe "#codigo_banco" do
98
+ its(:codigo_banco) { should eq '237' }
99
+ end
100
+
101
+ describe "#digito_codigo_banco" do
102
+ its(:digito_codigo_banco) { should eq '2' }
103
+ end
104
+
105
+ describe "#agencia_codigo_cedente" do
106
+ subject { Bradesco.new(agencia: '1172', digito_agencia: '0', conta_corrente: '0403005', digito_conta_corrente: '2') }
107
+
108
+ its(:agencia_codigo_cedente) { should eq '1172-0 / 0403005-2'}
109
+ end
110
+
111
+ describe "#nosso_numero" do
112
+ context "documentation example" do
113
+ subject { Bradesco.new(:carteira => '19', :numero_documento => '00000000002') }
114
+
115
+ its(:nosso_numero) { should eq '19/00000000002-8' }
116
+ end
117
+
118
+ context "more examples from documentation" do
119
+ subject { Bradesco.new(:carteira => '19', :numero_documento => '00000000001') }
120
+
121
+ its(:nosso_numero) { should eq '19/00000000001-P' }
122
+ end
123
+
124
+ context "more examples" do
125
+ subject { Bradesco.new(:carteira => '06', :numero_documento => '00075896452') }
126
+
127
+ its(:nosso_numero) { should eq '06/00075896452-5' }
128
+ end
129
+ end
130
+
131
+ describe "#codigo_de_barras" do
132
+ context "more examples" do
133
+ subject do
134
+ Bradesco.new do |boleto|
135
+ boleto.carteira = 6
136
+ boleto.numero_documento = 75896452
137
+ boleto.valor_documento = 2952.95
138
+ boleto.data_vencimento = Date.parse('2012-12-28')
139
+ boleto.agencia = 1172
140
+ boleto.digito_agencia = 0
141
+ boleto.conta_corrente = 403005
142
+ boleto.digito_conta_corrente = 2
143
+ end
144
+ end
145
+
146
+ its(:codigo_de_barras) { should eq '23796556100002952951172060007589645204030050' }
147
+ its(:linha_digitavel) { should eq '23791.17209 60007.589645 52040.300502 6 55610000295295' }
148
+ end
149
+
150
+ context "when carteira '09'" do
151
+ subject do
152
+ Bradesco.new do |boleto|
153
+ boleto.carteira = 9
154
+ boleto.numero_documento = 175896451
155
+ boleto.valor_documento = 2959.78
156
+ boleto.data_vencimento = Date.parse('2012-12-28')
157
+ boleto.agencia = 1172
158
+ boleto.digito_agencia = 0
159
+ boleto.conta_corrente = 403005
160
+ boleto.digito_conta_corrente = 2
161
+ end
162
+ end
163
+
164
+ its(:codigo_de_barras) { should eq '23791556100002959781172090017589645104030050' }
165
+ its(:linha_digitavel) { should eq '23791.17209 90017.589640 51040.300504 1 55610000295978' }
166
+ end
167
+ end
168
+ end
169
+ end
170
+ end