boletos-ademitech 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.
- package/.eslintrc.json +25 -0
- package/LICENSE +661 -0
- package/README.md +50 -0
- package/examples/gerar-boleto-BancoDoBrasil.js +72 -0
- package/examples/gerar-boleto-bradesco.js +58 -0
- package/examples/gerar-boleto-cecred.js +59 -0
- package/index.d.ts +372 -0
- package/lib/boleto/bancos/banco-do-brasil.js +125 -0
- package/lib/boleto/bancos/bradesco.js +115 -0
- package/lib/boleto/bancos/caixa.js +140 -0
- package/lib/boleto/bancos/cecred.js +117 -0
- package/lib/boleto/bancos/itau.js +124 -0
- package/lib/boleto/bancos/logotipos/ailos.png +0 -0
- package/lib/boleto/bancos/logotipos/banco-do-brasil.png +0 -0
- package/lib/boleto/bancos/logotipos/bradesco.png +0 -0
- package/lib/boleto/bancos/logotipos/caixa-economica-federal.png +0 -0
- package/lib/boleto/bancos/logotipos/itau.png +0 -0
- package/lib/boleto/bancos/logotipos/santander.png +0 -0
- package/lib/boleto/bancos/logotipos/sicoob.png +0 -0
- package/lib/boleto/bancos/logotipos/sicredi.png +0 -0
- package/lib/boleto/bancos/santander.js +118 -0
- package/lib/boleto/bancos/sicoob.js +118 -0
- package/lib/boleto/bancos/sicredi.js +143 -0
- package/lib/boleto/codigo-de-barras-builder.js +38 -0
- package/lib/boleto/fontes/Code25I.ttf +0 -0
- package/lib/boleto/fontes/Times New Roman Bold Italic.ttf +0 -0
- package/lib/boleto/fontes/Times New Roman Bold.ttf +0 -0
- package/lib/boleto/fontes/Times New Roman Italic.ttf +0 -0
- package/lib/boleto/fontes/Times New Roman.ttf +0 -0
- package/lib/boleto/gerador-de-boleto.js +1198 -0
- package/lib/boleto/gerador-de-digito-padrao.js +42 -0
- package/lib/boleto/gerador-de-linha-digitavel.js +26 -0
- package/lib/boleto/imagens/tesoura128.png +0 -0
- package/lib/boleto/valida-codigo-barras.js +12 -0
- package/lib/index.js +14 -0
- package/lib/metodosPublicos/boletoMetodos.js +50 -0
- package/lib/pdf-gerador.js +26 -0
- package/lib/stringify/boletoStringify.js +49 -0
- package/lib/utils/array-utils.js +13 -0
- package/lib/utils/date-utils.js +8 -0
- package/lib/utils/functions/bancosUtils.js +104 -0
- package/lib/utils/functions/boletoUtils.js +895 -0
- package/lib/utils/functions/formatacoesUtils.js +287 -0
- package/lib/utils/functions/validacoesUtils.js +233 -0
- package/lib/utils/math-utils.js +53 -0
- package/lib/utils/object-utils.js +8 -0
- package/lib/utils/stream-utils.js +6 -0
- package/lib/utils/string-utils.js +60 -0
- package/package.json +60 -0
- package/tests/bancos-test.js +116 -0
- package/tests/boleto/bancos/bradesco-test.js +145 -0
- package/tests/boleto/bancos/caixa-test.js +428 -0
- package/tests/boleto/bancos/itau-test.js +342 -0
- package/tests/boleto/bancos/sicoob-test.js +341 -0
- package/tests/boleto/gerador-de-digito-padrao-test.js +22 -0
- package/tests/boleto-test.js +349 -0
- package/tests/brasil-test.js +66 -0
- package/tests/formatacoes-test.js +349 -0
- package/tests/validacoes-test.js +309 -0
- package/tmp/boletos/.gitkeep +0 -0
package/package.json
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "boletos-ademitech",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Gerar boletos para vários bancos",
|
|
5
|
+
"main": "lib/index.js",
|
|
6
|
+
"directories": {
|
|
7
|
+
"example": "examples",
|
|
8
|
+
"lib": "lib",
|
|
9
|
+
"test": "tests"
|
|
10
|
+
},
|
|
11
|
+
"scripts": {
|
|
12
|
+
"test": "nodeunit ./tests/*test.js && nodeunit ./tests/boleto/bancos/*test.js && nodeunit ./tests/boleto/*test.js",
|
|
13
|
+
"lint": "eslint .",
|
|
14
|
+
"gerarBradesco": "node ./examples/gerar-boleto-bradesco.js",
|
|
15
|
+
"gerarCecred": "node ./examples/gerar-boleto-cecred.js",
|
|
16
|
+
"gerarBrasil": "node ./examples/gerar-boleto-BancoDoBrasil.js"
|
|
17
|
+
},
|
|
18
|
+
"keywords": [
|
|
19
|
+
"gerador",
|
|
20
|
+
"boleto",
|
|
21
|
+
"boletos",
|
|
22
|
+
"bancario",
|
|
23
|
+
"banco",
|
|
24
|
+
"cecred",
|
|
25
|
+
"sicredi",
|
|
26
|
+
"ailos",
|
|
27
|
+
"viacredi",
|
|
28
|
+
"bradesco",
|
|
29
|
+
"brasil",
|
|
30
|
+
"itau",
|
|
31
|
+
"caixa",
|
|
32
|
+
"economica",
|
|
33
|
+
"federal",
|
|
34
|
+
"santander",
|
|
35
|
+
"sicoob"
|
|
36
|
+
],
|
|
37
|
+
"author": {
|
|
38
|
+
"name": "Thiago Fernandes",
|
|
39
|
+
"email": "thiago.silva@ademicon.com.br"
|
|
40
|
+
},
|
|
41
|
+
"license": "ISC",
|
|
42
|
+
"engines": {
|
|
43
|
+
"node": ">=10.0.0"
|
|
44
|
+
},
|
|
45
|
+
"dependencies": {
|
|
46
|
+
"base64-stream": "^1.0.0",
|
|
47
|
+
"moment": "^2.30.1",
|
|
48
|
+
"moment-timezone": "^0.5.45",
|
|
49
|
+
"pdfkit": "0.10.0",
|
|
50
|
+
"qrcode": "^1.5.3"
|
|
51
|
+
},
|
|
52
|
+
"devDependencies": {
|
|
53
|
+
"eslint": "^6.5.1",
|
|
54
|
+
"nodeunit": "0.11.3"
|
|
55
|
+
},
|
|
56
|
+
"repository": {
|
|
57
|
+
"type": "git",
|
|
58
|
+
"url": "https://github.com/Ademitech-Sales-Tech-Team/boletos.git"
|
|
59
|
+
}
|
|
60
|
+
}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
const bancos = require('../lib/utils/functions/bancosUtils');
|
|
2
|
+
|
|
3
|
+
module.exports = {
|
|
4
|
+
itau: {
|
|
5
|
+
'calcularDigitoVerificador': function(test) {
|
|
6
|
+
test.equal(bancos.itau.calcularDigitoVerificador('0654', '08711'), '3');
|
|
7
|
+
test.done();
|
|
8
|
+
},
|
|
9
|
+
|
|
10
|
+
'validarAgenciaEConta': function(test) {
|
|
11
|
+
test.ok(bancos.itau.validarAgenciaEConta('0654', '087113'));
|
|
12
|
+
test.done();
|
|
13
|
+
},
|
|
14
|
+
|
|
15
|
+
'validarAgencia - Verifica que sempre retorna falso': function(test) {
|
|
16
|
+
//O itaú utiliza apenas um DV para agência e conta, este método está disponível
|
|
17
|
+
//apenas para se adequar a interface
|
|
18
|
+
test.equal(bancos.itau.validarAgencia('0654'), false);
|
|
19
|
+
test.done();
|
|
20
|
+
},
|
|
21
|
+
|
|
22
|
+
'validarConta - Verifica que sempre retorna falso': function(test) {
|
|
23
|
+
//O itaú utiliza apenas um DV para agência e conta, este método está disponível
|
|
24
|
+
//apenas para se adequar a interface
|
|
25
|
+
test.equal(bancos.itau.validarConta('087113'), false);
|
|
26
|
+
test.done();
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
|
|
30
|
+
'341': {
|
|
31
|
+
'Verifica que mesmas funções disposniveis em bancos.itau estão disponiveis em banco["341"]': function(test) {
|
|
32
|
+
test.equal(bancos.itau.calcularDigitoVerificador.toString(), bancos['341'].calcularDigitoVerificador.toString());
|
|
33
|
+
test.equal(bancos.itau.validarAgenciaEConta.toString(), bancos['341'].validarAgenciaEConta.toString());
|
|
34
|
+
test.equal(bancos.itau.validarAgencia.toString(), bancos['341'].validarAgencia.toString());
|
|
35
|
+
test.equal(bancos.itau.validarConta.toString(), bancos['341'].validarConta.toString());
|
|
36
|
+
|
|
37
|
+
test.done();
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
|
|
41
|
+
bancoDoBrasil: {
|
|
42
|
+
'calcularDigitoVerificador - Verifica que cálculo funciona para agência': function(test) {
|
|
43
|
+
test.equal(bancos.bancoDoBrasil.calcularDigitoVerificador('1507'), '5');
|
|
44
|
+
test.done();
|
|
45
|
+
},
|
|
46
|
+
|
|
47
|
+
'calcularDigitoVerificador - Verifica que cálculo funciona para conta': function(test) {
|
|
48
|
+
test.equal(bancos.bancoDoBrasil.calcularDigitoVerificador('33203'), '8');
|
|
49
|
+
test.done();
|
|
50
|
+
},
|
|
51
|
+
|
|
52
|
+
'validarAgenciaEConta': function(test) {
|
|
53
|
+
test.ok(bancos.bancoDoBrasil.validarAgenciaEConta('15075', '332038'));
|
|
54
|
+
test.done();
|
|
55
|
+
},
|
|
56
|
+
|
|
57
|
+
'validarAgencia': function(test) {
|
|
58
|
+
test.ok(bancos.bancoDoBrasil.validarAgencia('15075'));
|
|
59
|
+
test.done();
|
|
60
|
+
},
|
|
61
|
+
|
|
62
|
+
'validarConta': function(test) {
|
|
63
|
+
test.ok(bancos.bancoDoBrasil.validarConta('332038'));
|
|
64
|
+
test.done();
|
|
65
|
+
}
|
|
66
|
+
},
|
|
67
|
+
|
|
68
|
+
'001': {
|
|
69
|
+
'Verifica que mesmas funções disposniveis em bancos.bancoDoBrasil estão disponiveis em banco["001"]': function(test) {
|
|
70
|
+
test.equal(bancos.bancoDoBrasil.calcularDigitoVerificador.toString(), bancos['001'].calcularDigitoVerificador.toString());
|
|
71
|
+
test.equal(bancos.bancoDoBrasil.validarAgenciaEConta.toString(), bancos['001'].validarAgenciaEConta.toString());
|
|
72
|
+
test.equal(bancos.bancoDoBrasil.validarAgencia.toString(), bancos['001'].validarAgencia.toString());
|
|
73
|
+
test.equal(bancos.bancoDoBrasil.validarConta.toString(), bancos['001'].validarConta.toString());
|
|
74
|
+
|
|
75
|
+
test.done();
|
|
76
|
+
}
|
|
77
|
+
},
|
|
78
|
+
|
|
79
|
+
/*bradesco: {
|
|
80
|
+
'calcularDigitoVerificador - Verifica que cálculo funciona para agência': function(test) {
|
|
81
|
+
test.equal(bancos.bradesco.calcularDigitoVerificador('655'), '0');
|
|
82
|
+
test.done();
|
|
83
|
+
},
|
|
84
|
+
|
|
85
|
+
'calcularDigitoVerificador - Verifica que cálculo funciona para conta': function(test) {
|
|
86
|
+
test.equal(bancos.bradesco.calcularDigitoVerificador('3'), '5');
|
|
87
|
+
test.done();
|
|
88
|
+
},
|
|
89
|
+
|
|
90
|
+
'validarAgenciaEConta': function(test) {
|
|
91
|
+
test.ok(bancos.bradesco.validarAgenciaEConta('6550', '35'));
|
|
92
|
+
test.done();
|
|
93
|
+
},
|
|
94
|
+
|
|
95
|
+
'validarAgencia': function(test) {
|
|
96
|
+
test.ok(bancos.bradesco.validarAgencia('6550'));
|
|
97
|
+
test.done();
|
|
98
|
+
},
|
|
99
|
+
|
|
100
|
+
'validarConta': function(test) {
|
|
101
|
+
test.equal(bancos.bradesco.validarConta('35'));
|
|
102
|
+
test.done();
|
|
103
|
+
}
|
|
104
|
+
},
|
|
105
|
+
|
|
106
|
+
'237': {
|
|
107
|
+
'Verifica que mesmas funções disposniveis em bancos.bradesco estão disponiveis em banco["237"]': function(test) {
|
|
108
|
+
test.equal(bancos.bradesco.calcularDigitoVerificador.toString(), bancos['237'].calcularDigitoVerificador.toString());
|
|
109
|
+
test.equal(bancos.bradesco.validarAgenciaEConta.toString(), bancos['237'].validarAgenciaEConta.toString());
|
|
110
|
+
test.equal(bancos.bradesco.validarAgencia.toString(), bancos['237'].validarAgencia.toString());
|
|
111
|
+
test.equal(bancos.bradesco.validarConta.toString(), bancos['237'].validarConta.toString());
|
|
112
|
+
|
|
113
|
+
test.done();
|
|
114
|
+
}
|
|
115
|
+
}*/
|
|
116
|
+
};
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
const PdfGerador = require('../../../lib/pdf-gerador');
|
|
2
|
+
var fs = require('fs'),
|
|
3
|
+
boletos = require('../../../lib/utils/functions/boletoUtils.js'),
|
|
4
|
+
Bradesco = require('../../../lib/boleto/bancos/bradesco.js'),
|
|
5
|
+
geradorDeLinhaDigitavel = require('../../../lib/boleto/gerador-de-linha-digitavel.js'),
|
|
6
|
+
|
|
7
|
+
Datas = boletos.Datas,
|
|
8
|
+
Endereco = boletos.Endereco,
|
|
9
|
+
Beneficiario = boletos.Beneficiario,
|
|
10
|
+
Pagador = boletos.Pagador,
|
|
11
|
+
Boleto = boletos.Boleto,
|
|
12
|
+
|
|
13
|
+
banco,
|
|
14
|
+
boleto;
|
|
15
|
+
|
|
16
|
+
module.exports = {
|
|
17
|
+
setUp: function(done) {
|
|
18
|
+
banco = new Bradesco();
|
|
19
|
+
|
|
20
|
+
var datas = Datas.novasDatas();
|
|
21
|
+
|
|
22
|
+
datas.comDocumento('02-04-2020');
|
|
23
|
+
datas.comProcessamento('02-04-2020');
|
|
24
|
+
datas.comVencimento('02-04-2020');
|
|
25
|
+
|
|
26
|
+
var beneficiario = Beneficiario.novoBeneficiario();
|
|
27
|
+
beneficiario.comNome('Leonardo Bessa');
|
|
28
|
+
beneficiario.comRegistroNacional('73114004652');
|
|
29
|
+
beneficiario.comAgencia('2949');
|
|
30
|
+
beneficiario.comDigitoAgencia('1');
|
|
31
|
+
beneficiario.comCodigoBeneficiario('6580');
|
|
32
|
+
beneficiario.comDigitoCodigoBeneficiario('3');
|
|
33
|
+
beneficiario.comNumeroConvenio('1207113');
|
|
34
|
+
beneficiario.comCarteira('6');
|
|
35
|
+
beneficiario.comNossoNumero('3');
|
|
36
|
+
beneficiario.comDigitoNossoNumero('7');
|
|
37
|
+
|
|
38
|
+
var enderecoDoBeneficiario = Endereco.novoEndereco();
|
|
39
|
+
enderecoDoBeneficiario.comLogradouro('Rua da Programação');
|
|
40
|
+
enderecoDoBeneficiario.comBairro('Zona Rural');
|
|
41
|
+
enderecoDoBeneficiario.comCep('71550050');
|
|
42
|
+
enderecoDoBeneficiario.comCidade('Patos de Minas');
|
|
43
|
+
enderecoDoBeneficiario.comUf('MG');
|
|
44
|
+
beneficiario.comEndereco(enderecoDoBeneficiario);
|
|
45
|
+
|
|
46
|
+
var pagador = Pagador.novoPagador();
|
|
47
|
+
pagador.comNome('Fulano');
|
|
48
|
+
pagador.comRegistroNacional('97264269604');
|
|
49
|
+
|
|
50
|
+
var enderecoDoPagador = Endereco.novoEndereco();
|
|
51
|
+
enderecoDoPagador.comLogradouro('Avenida dos Testes Unitários');
|
|
52
|
+
enderecoDoPagador.comBairro('Barra da Tijuca');
|
|
53
|
+
enderecoDoPagador.comCep('72000000');
|
|
54
|
+
enderecoDoPagador.comCidade('Rio de Janeiro');
|
|
55
|
+
enderecoDoPagador.comUf('RJ');
|
|
56
|
+
pagador.comEndereco(enderecoDoPagador);
|
|
57
|
+
|
|
58
|
+
boleto = Boleto.novoBoleto();
|
|
59
|
+
boleto.comDatas(datas);
|
|
60
|
+
boleto.comBeneficiario(beneficiario);
|
|
61
|
+
boleto.comBanco(banco);
|
|
62
|
+
boleto.comPagador(pagador);
|
|
63
|
+
boleto.comValor(1);
|
|
64
|
+
boleto.comNumeroDoDocumento('4323');
|
|
65
|
+
boleto.comLocaisDePagamento([
|
|
66
|
+
'Pagável preferencialmente na rede Bradesco ou no Bradesco expresso'
|
|
67
|
+
]);
|
|
68
|
+
|
|
69
|
+
done();
|
|
70
|
+
},
|
|
71
|
+
|
|
72
|
+
'Nosso número formatado deve ter 11 digitos': function(test) {
|
|
73
|
+
var nossoNumero = banco.getNossoNumeroFormatado(boleto.getBeneficiario());
|
|
74
|
+
test.equals(11, nossoNumero.length);
|
|
75
|
+
test.equals('00000000003', nossoNumero);
|
|
76
|
+
|
|
77
|
+
test.done();
|
|
78
|
+
},
|
|
79
|
+
|
|
80
|
+
'Carteira formatado deve ter dois dígitos': function(test) {
|
|
81
|
+
var carteiraFormatado = banco.getCarteiraFormatado(boleto.getBeneficiario());
|
|
82
|
+
|
|
83
|
+
test.equals(2, carteiraFormatado.length);
|
|
84
|
+
test.equals('06', carteiraFormatado);
|
|
85
|
+
test.done();
|
|
86
|
+
},
|
|
87
|
+
|
|
88
|
+
'Conta corrente formatada deve ter sete dígitos': function(test) {
|
|
89
|
+
var codigoFormatado = banco.getCodigoFormatado(boleto.getBeneficiario());
|
|
90
|
+
|
|
91
|
+
test.equals(7, codigoFormatado.length);
|
|
92
|
+
test.equals('0006580', codigoFormatado);
|
|
93
|
+
test.done();
|
|
94
|
+
},
|
|
95
|
+
|
|
96
|
+
'Testa geração de linha digitavel': function(test) {
|
|
97
|
+
var codigoDeBarras = banco.geraCodigoDeBarrasPara(boleto),
|
|
98
|
+
linhaEsperada = '23792.94909 60000.000004 03000.658009 9 81550000000100';
|
|
99
|
+
|
|
100
|
+
test.equal(linhaEsperada, geradorDeLinhaDigitavel(codigoDeBarras, banco));
|
|
101
|
+
test.done();
|
|
102
|
+
},
|
|
103
|
+
|
|
104
|
+
'Testa código de barras': function(test) {
|
|
105
|
+
var codigoDeBarras = banco.geraCodigoDeBarrasPara(boleto);
|
|
106
|
+
|
|
107
|
+
test.equal('23799815500000001002949060000000000300065800', codigoDeBarras);
|
|
108
|
+
test.done();
|
|
109
|
+
},
|
|
110
|
+
|
|
111
|
+
'Verifica nome correto do banco': function(test) {
|
|
112
|
+
test.equals(banco.getNome(), 'Banco Bradesco S.A.');
|
|
113
|
+
test.done();
|
|
114
|
+
},
|
|
115
|
+
|
|
116
|
+
'Verifica a numeração correta do banco': function(test) {
|
|
117
|
+
test.equal(banco.getNumeroFormatadoComDigito(), '237-2');
|
|
118
|
+
test.done();
|
|
119
|
+
},
|
|
120
|
+
|
|
121
|
+
'Verifica que arquivo de imagem do logotipo existe': function(test) {
|
|
122
|
+
test.ok(fs.existsSync(banco.getImagem()));
|
|
123
|
+
test.done();
|
|
124
|
+
},
|
|
125
|
+
|
|
126
|
+
'Verifica deve imprimir o nome do banco no boleto': function(test) {
|
|
127
|
+
test.ok(!banco.getImprimirNome());
|
|
128
|
+
test.done();
|
|
129
|
+
},
|
|
130
|
+
|
|
131
|
+
'Exibir campo CIP retorna verdadeiro': function(test) {
|
|
132
|
+
test.equal(banco.exibirCampoCip(), true);
|
|
133
|
+
test.done();
|
|
134
|
+
},
|
|
135
|
+
|
|
136
|
+
'Verifica criação de pdf': function(test) {
|
|
137
|
+
new PdfGerador(boleto).pdfFile(
|
|
138
|
+
'../tests/boleto/bancos/boleto-bradesco.pdf'
|
|
139
|
+
).then(async({path})=>{
|
|
140
|
+
test.ok(fs.existsSync(path));
|
|
141
|
+
test.equal(fs.unlinkSync(path), undefined);
|
|
142
|
+
test.done();
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
};
|