UNPKG

3.43 kBMarkdownView Raw
1node-boleto
2=============
3
4Geração de boleto bancário em Node.js. Os algoritmos de geração da linha digitável e do código de barras foram inspirados no [boletophp](https://github.com/BielSystems/boletophp).
5
6## Bancos suportados
7
8- Santander - by [pedrofranceschi](https://github.com/pedrofranceschi) - homologado
9- Bradesco - by [pedrofranceschi](https://github.com/pedrofranceschi)
10
11## Instalação
12
13```
14npm install node-boleto
15```
16
17## Exemplo de uso
18
19Emitindo um boleto:
20
21```javascript
22var Boleto = require('node-boleto').Boleto;
23
24var boleto = new Boleto({
25 'banco': "santander", // nome do banco dentro da pasta 'banks'
26 'data_emissao': new Date(),
27 'data_vencimento': new Date(new Date().getTime() + 5 * 24 * 3600 * 1000), // 5 dias futuramente
28 'valor': 1500, // R$ 15,00 (valor em centavos)
29 'nosso_numero': "1234567",
30 'numero_documento': "123123",
31 'cedente': "Pagar.me Pagamentos S/A",
32 'cedente_cnpj': "18727053000174", // sem pontos e traços
33 'agencia': "3978",
34 'codigo_cedente': "6404154", // PSK (código da carteira)
35 'carteira': "102"
36});
37
38console.log("Linha digitável: " + boleto['linha_digitavel'])
39
40boleto.renderHTML(function(html){
41 console.log(html);
42});
43```
44
45Parseando o arquivo-retorno EDI do banco:
46
47```javascript
48var ediParser = require('node-boleto').EdiParser,
49 fs = require('fs');
50
51var ediFileContent = fs.readFileSync("arquivo.txt").toString();
52
53var parsedFile = ediParser.parse("santander", ediFileContent);
54
55console.log("Boletos pagos: ");
56console.log(parsedFile.boletos);
57```
58
59## Adicionando novos bancos
60
61## Renderização do código de barras
62
63Atualmente, há duas maneiras de renderizar o código de barras: `img` e `bmp`.
64
65A engine `img` utiliza imagens brancas e pretas intercaladas para gerar o código de barras. Dessa forma, todos os browsers desde o IE6 são suportados. Esse modo de renderização, porém, é um pouco mais pesado, já que muitas `divs` são inseridas no HTML para a renderização.
66
67A engine `bmp` aproveita da característica monodimensional dos códigos de barra e gera apenas a primeira linha de pixels do boleto, repetindo as outras linhas por CSS. É mais leve e funciona na maioria dos browser - IE apenas a partir da versão 8.
68
69Para alterar a engine de renderização padrão:
70
71```javascript
72Boleto.barcodeRenderEngine = 'bmp';
73```
74
75## Licença
76
77(The MIT License)
78
79Copyright (c) 2013-2004 Pagar.me Pagamentos S/A
80
81Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
82
83The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
84
85THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.