├── .babelrc ├── index.js ├── docs └── manualECommAPISicredi.pdf ├── tests ├── fixtures │ ├── create-with-erro.json │ ├── auth-with-invalid-token.json │ ├── create-without-agency.json │ ├── change-with-success.json │ ├── auth-with-success.json │ ├── auth-with-token-registered.json │ ├── find-with-success.json │ ├── print-with-success.json │ └── create-with-success.json ├── health.spec.js ├── change.spec.js ├── find.spec.js ├── index.spec.js ├── print.spec.js ├── auth.spec.js └── create.spec.js ├── src ├── erros │ └── sicredi.js ├── config.js └── index.js ├── .editorconfig ├── .travis.yml ├── CONTRIBUTING.md ├── exemples └── index.js ├── lib ├── config.js ├── erros │ └── sicredi.js └── index.js ├── LICENSE.md ├── .gitignore ├── package.json └── README.md /.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": ["@babel/preset-env"] 3 | } 4 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | module.exports = require('./src/index').default 2 | -------------------------------------------------------------------------------- /docs/manualECommAPISicredi.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/murilosandiego/node-sicredi/HEAD/docs/manualECommAPISicredi.pdf -------------------------------------------------------------------------------- /tests/fixtures/create-with-erro.json: -------------------------------------------------------------------------------- 1 | { 2 | "codigo": "E0010", 3 | "mensagem": "Campo obrigatorio em branco.", 4 | "parametro": "cpfCnpj" 5 | } 6 | -------------------------------------------------------------------------------- /tests/fixtures/auth-with-invalid-token.json: -------------------------------------------------------------------------------- 1 | { 2 | "codigo": "E0011", 3 | "mensagem": "Tamanho de campo invalido.", 4 | "parametro": "token" 5 | } 6 | -------------------------------------------------------------------------------- /tests/fixtures/create-without-agency.json: -------------------------------------------------------------------------------- 1 | { 2 | "codigo": "E0010", 3 | "mensagem": "Campo obrigatorio em branco.", 4 | "parametro": "agencia" 5 | } 6 | -------------------------------------------------------------------------------- /src/erros/sicredi.js: -------------------------------------------------------------------------------- 1 | export default class SicrediError extends Error { 2 | constructor (error) { 3 | super() 4 | this.error = error 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /tests/fixtures/change-with-success.json: -------------------------------------------------------------------------------- 1 | { 2 | "codigo": "E0029", 3 | "mensagem": "Comando de Instrução realizado com sucesso!", 4 | "parametro": null 5 | } 6 | -------------------------------------------------------------------------------- /tests/fixtures/auth-with-success.json: -------------------------------------------------------------------------------- 1 | { 2 | "chaveTransacao": "99999999999999999999999999999999999999999", 3 | "dataExpiracao": "2019-04-13T18:08:46.471-03:00" 4 | } 5 | -------------------------------------------------------------------------------- /tests/fixtures/auth-with-token-registered.json: -------------------------------------------------------------------------------- 1 | { 2 | "codigo": "0004", 3 | "mensagem": "Existe um Token de Transação válido cadastrado!", 4 | "parametro": "" 5 | } 6 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | indent_style = space 5 | indent_size = 2 6 | end_of_line = lf 7 | charset = utf-8 8 | trim_trailing_whitespace = true 9 | insert_final_newline = true 10 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | 3 | node_js: 4 | - "11" 5 | 6 | cache: 7 | directories: 8 | "node_modules" 9 | 10 | before_script: 11 | - npm run build 12 | 13 | after_success: 14 | - npm run coveralls 15 | -------------------------------------------------------------------------------- /tests/fixtures/find-with-success.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "seuNumero": "9999999999", 4 | "nossoNumero": "99999999", 5 | "nomePagador": "CLIENTE TESTE", 6 | "valor": "500", 7 | "valorLiquidado": "500", 8 | "dataEmissao": "2018-12-13", 9 | "dataVencimento": "2018-12-16", 10 | "dataLiquidacao": "2018-12-13", 11 | "situacao": "LIQUIDADO" 12 | } 13 | ] 14 | -------------------------------------------------------------------------------- /src/config.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | export const API_URL = 4 | 'https://cobrancaonline.sicredi.com.br/sicredi-cobranca-ws-ecomm-api/ecomm/v1/boleto' 5 | export const AUTH_PATH = 'autenticacao' 6 | export const CREATE_PATH = 'emissao' 7 | export const FIND_PATH = 'consulta' 8 | export const PRINT_PATH = 'impressao' 9 | export const CHANGE_PATH = 'comandoInstrucao' 10 | export const HEALTH_PATH = 'health' 11 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing 2 | 3 | 1. Faça um Fork do projeto! 4 | 2. Crie sua feature branch: `git checkout -b my-new-feature` 5 | 3. Commit suas alterações: `git commit -m 'Add some feature'` 6 | 4. Push branch: `git push origin my-new-feature` 7 | 8 | *Relembre que nós temos um pre-push com etapas que analisam e evitam erros* 9 | 10 | **Depois que seu pull request for feito merge**, você poderá exclui-lo com segurança. 11 | -------------------------------------------------------------------------------- /exemples/index.js: -------------------------------------------------------------------------------- 1 | const Sicredi = require('../lib/index').default 2 | 3 | const sicredi = new Sicredi({ 4 | token: '12341234123412341234', 5 | agency: 1234, 6 | assignor: 12345, 7 | station: 99 8 | }) 9 | 10 | sicredi 11 | .find({ 12 | dataInicio: '10/10/2018', 13 | dataFim: '31/12/2018', 14 | tipoData: 'DATA_EMISSAO' 15 | }) 16 | .then(data => { 17 | console.log(data) 18 | }) 19 | .catch(err => console.log(err)) 20 | -------------------------------------------------------------------------------- /lib/config.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | Object.defineProperty(exports, "__esModule", { 4 | value: true 5 | }); 6 | exports.HEALTH_PATH = exports.CHANGE_PATH = exports.PRINT_PATH = exports.FIND_PATH = exports.CREATE_PATH = exports.AUTH_PATH = exports.API_URL = void 0; 7 | var API_URL = 'https://cobrancaonline.sicredi.com.br/sicredi-cobranca-ws-ecomm-api/ecomm/v1/boleto'; 8 | exports.API_URL = API_URL; 9 | var AUTH_PATH = 'autenticacao'; 10 | exports.AUTH_PATH = AUTH_PATH; 11 | var CREATE_PATH = 'emissao'; 12 | exports.CREATE_PATH = CREATE_PATH; 13 | var FIND_PATH = 'consulta'; 14 | exports.FIND_PATH = FIND_PATH; 15 | var PRINT_PATH = 'impressao'; 16 | exports.PRINT_PATH = PRINT_PATH; 17 | var CHANGE_PATH = 'comandoInstrucao'; 18 | exports.CHANGE_PATH = CHANGE_PATH; 19 | var HEALTH_PATH = 'health'; 20 | exports.HEALTH_PATH = HEALTH_PATH; -------------------------------------------------------------------------------- /tests/fixtures/print-with-success.json: -------------------------------------------------------------------------------- 1 | { 2 | "menssagem": "Processado com sucesso.", 3 | "arquivo": "JVBERi0xLjQKJeLjz9MKMSAwIG9iaiA8PC9UeXBlL1hPYmplY3QvUmVzb3VyY2VzPDwvUHJvY1NldCBbL1BERiAvVGV4dCAvSW1hZ2VCIC9JbWFnZUMgL0ltYWdlSV0vRm9udDw8L0FyaWFsLUJvbGRNVCAyIDAgUj4+Pj4vU3VidHlwZS9Gb3JtL0JCb3hbMCAwIDM0OC41IDI2LjldL01hdHJpeCBbMSAwIDAgMSAwIDBdL0xlbmd0aCAxMzMvRm9ybVR5cGUgMS9GaWx0ZXIvRmxhdGVEZWNvZGU+PnN0cmVhbQp4nC2OvQrCQBCEX2VKLdzsXu63NJIyReDAWlCDEpWk8vEdgjPdzLfLLBjR1C+64YQFSrc+S4CLUrDecMabeVdhW2koEgOyqEN9oTmuj8t86D7zdSDC7L5hinXCLvlcTMyyMaFaST6oBYIum7DU6PkyJa9/RdV9ffJ+Ql85bUTPYT8QLCRTCmVuZHN0cmVhbQplbmRvYmoKMyAwIG9iaiA8PC9UeXBlL1hPYmplY3QvUmVzb3VyY2VzPDwvUHJvY1NldCBbL1BERiAvVGV4dCAvSW1hZ2VCIC9JbWFnZUMgL0ltYWdlSV0vRm9udDw8L0FyaWFsLUJvbGRNVCAyIDAgUj4+Pj4vU3VidHlwZS9Gb3JtL0JCb3hbMCAwIDUyLjcgMjYuOF0vTWF0cml4IFsxIDAgMCAxIDAgMF0vTGVuZ3RoIDEwNy9Gb3JtVHlwZSAxL0ZpbHRlci9GbGF0ZURlY29kZT4+c3RyZWFtCnicHY2xCoNAFAR/ZUpTeJ6nF6/NiaWF8MA6EJU" 4 | } 5 | -------------------------------------------------------------------------------- /tests/fixtures/create-with-success.json: -------------------------------------------------------------------------------- 1 | { 2 | "linhaDigitavel": "74899999999999", 3 | "codigoBanco": "748", 4 | "nomeBeneficiario": "EMPRESA", 5 | "enderecoBeneficiario": "R. 1, 708", 6 | "cpfCnpjBeneficiario": "9999999999999", 7 | "cooperativaBeneficiario": "9999", 8 | "postoBeneficiario": "99", 9 | "codigoBeneficiario": "99999", 10 | "dataDocumento": "2019-04-13", 11 | "seuNumero": "0000000002", 12 | "especieDocumento": "B", 13 | "aceite": "N", 14 | "dataProcessamento": "2019-04-13", 15 | "nossoNumero": 999999999, 16 | "especie": "REAL", 17 | "valorDocumento": 6, 18 | "dataVencimento": "2019-05-16", 19 | "nomePagador": "CLIENTE TESTE", 20 | "cpfCnpjPagador": "99999999999", 21 | "enderecoPagador": "R 1", 22 | "dataLimiteDesconto": null, 23 | "valorDesconto": 0, 24 | "jurosMulta": 0, 25 | "instrucao": "teste\r", 26 | "informativo": "teste1\r", 27 | "codigoBarra": "748999999999999999999" 28 | } 29 | -------------------------------------------------------------------------------- /tests/health.spec.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | /* eslint-disable no-unused-expressions */ 3 | 4 | import chai, { expect } from 'chai' 5 | import chaiAsPromised from 'chai-as-promised' 6 | import chaiSubset from 'chai-subset' 7 | import nock from 'nock' 8 | import Sicredi from '../src/index' 9 | 10 | chai.use(chaiAsPromised) 11 | chai.use(chaiSubset) 12 | 13 | describe('health method', () => { 14 | let sicredi 15 | 16 | beforeEach(() => { 17 | sicredi = new Sicredi({ 18 | token: 'foo', 19 | agency: '1234', 20 | station: '12', 21 | assignor: 12345 22 | }) 23 | }) 24 | 25 | it('should have health method', () => { 26 | expect(sicredi.health).to.be.exist 27 | expect(sicredi.health).to.be.a('function') 28 | }) 29 | 30 | it('should health billet with success', () => { 31 | nock( 32 | 'https://cobrancaonline.sicredi.com.br/sicredi-cobranca-ws-ecomm-api/ecomm/v1/boleto' 33 | ) 34 | .get('/health') 35 | .reply(200, {}) 36 | 37 | return expect(sicredi.health()).to.eventually.deep.equal({}) 38 | }) 39 | }) 40 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | Copyright <2019> 3 | 4 | Permission 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: 5 | 6 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 7 | 8 | THE 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. -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | yarn-debug.log* 6 | yarn-error.log* 7 | 8 | # Runtime data 9 | pids 10 | *.pid 11 | *.seed 12 | *.pid.lock 13 | 14 | # Directory for instrumented libs generated by jscoverage/JSCover 15 | lib-cov 16 | 17 | # Coverage directory used by tools like istanbul 18 | coverage 19 | 20 | # nyc test coverage 21 | .nyc_output 22 | 23 | # Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) 24 | .grunt 25 | 26 | # Bower dependency directory (https://bower.io/) 27 | bower_components 28 | 29 | # node-waf configuration 30 | .lock-wscript 31 | 32 | # Compiled binary addons (https://nodejs.org/api/addons.html) 33 | build/Release 34 | 35 | # Dependency directories 36 | node_modules/ 37 | jspm_packages/ 38 | 39 | # TypeScript v1 declaration files 40 | typings/ 41 | 42 | # Optional npm cache directory 43 | .npm 44 | 45 | # Optional eslint cache 46 | .eslintcache 47 | 48 | # Optional REPL history 49 | .node_repl_history 50 | 51 | # Output of 'npm pack' 52 | *.tgz 53 | 54 | # Yarn Integrity file 55 | .yarn-integrity 56 | 57 | # dotenv environment variables file 58 | .env 59 | .env.test 60 | 61 | # parcel-bundler cache (https://parceljs.org/) 62 | .cache 63 | 64 | # next.js build output 65 | .next 66 | 67 | # nuxt.js build output 68 | .nuxt 69 | 70 | # vuepress build output 71 | .vuepress/dist 72 | 73 | # Serverless directories 74 | .serverless/ 75 | 76 | # FuseBox cache 77 | .fusebox/ 78 | 79 | # DynamoDB Local files 80 | .dynamodb/ 81 | 82 | .DS_Store 83 | -------------------------------------------------------------------------------- /tests/change.spec.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | /* eslint-disable no-unused-expressions */ 3 | 4 | import chai, { expect } from 'chai' 5 | import chaiAsPromised from 'chai-as-promised' 6 | import chaiSubset from 'chai-subset' 7 | import nock from 'nock' 8 | import path from 'path' 9 | import Sicredi from '../src/index' 10 | 11 | chai.use(chaiAsPromised) 12 | chai.use(chaiSubset) 13 | 14 | describe('change method', () => { 15 | let sicredi 16 | 17 | beforeEach(() => { 18 | sicredi = new Sicredi({ 19 | token: 'foo', 20 | agency: '1234', 21 | station: '12', 22 | assignor: 12345 23 | }) 24 | }) 25 | 26 | it('should have change method', () => { 27 | expect(sicredi.change).to.be.exist 28 | expect(sicredi.change).to.be.a('function') 29 | }) 30 | 31 | it('should change billet with success', () => { 32 | const body = { 33 | agencia: '1234', 34 | posto: '99', 35 | cedente: '12345', 36 | nossoNumero: '999999999', 37 | seuNumero: '9999999999', 38 | instrucaoComando: 'ALTERACAO_SEU_NUMERO', 39 | tipoVencimento: 'VISTA' 40 | } 41 | 42 | nock( 43 | 'https://cobrancaonline.sicredi.com.br/sicredi-cobranca-ws-ecomm-api/ecomm/v1/boleto' 44 | ) 45 | .post('/comandoInstrucao', { 46 | ...body, 47 | agencia: sicredi.agency, 48 | posto: sicredi.station, 49 | cedente: sicredi.assignor 50 | }) 51 | .replyWithFile( 52 | 200, 53 | path.join(__dirname, '/fixtures/change-with-success.json') 54 | ) 55 | 56 | return expect(sicredi.change(body)).to.eventually.deep.equal({ 57 | codigo: 'E0029', 58 | mensagem: 'Comando de Instrução realizado com sucesso!', 59 | parametro: null 60 | }) 61 | }) 62 | }) 63 | -------------------------------------------------------------------------------- /tests/find.spec.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | /* eslint-disable no-unused-expressions */ 3 | 4 | import chai, { expect } from 'chai' 5 | import chaiAsPromised from 'chai-as-promised' 6 | import chaiSubset from 'chai-subset' 7 | import nock from 'nock' 8 | import path from 'path' 9 | import Sicredi from '../src/index' 10 | 11 | chai.use(chaiAsPromised) 12 | chai.use(chaiSubset) 13 | 14 | describe('find method', () => { 15 | let sicredi 16 | 17 | beforeEach(() => { 18 | sicredi = new Sicredi({ 19 | token: 'foo', 20 | agency: 1234, 21 | station: 99, 22 | assignor: 12345 23 | }) 24 | }) 25 | 26 | it('should have find method', () => { 27 | expect(sicredi.find).to.be.exist 28 | expect(sicredi.find).to.be.a('function') 29 | }) 30 | 31 | it('should return array of billet with success', () => { 32 | const query = { 33 | nossoNumero: 99999999 34 | } 35 | nock( 36 | 'https://cobrancaonline.sicredi.com.br/sicredi-cobranca-ws-ecomm-api/ecomm/v1/boleto' 37 | ) 38 | .get('/consulta') 39 | .query({ 40 | ...query, 41 | agencia: sicredi.agency, 42 | posto: sicredi.station, 43 | cedente: sicredi.assignor 44 | }) 45 | .replyWithFile( 46 | 200, 47 | path.join(__dirname, '/fixtures/find-with-success.json') 48 | ) 49 | 50 | return expect(sicredi.find(query)).to.eventually.deep.equal([ 51 | { 52 | seuNumero: '9999999999', 53 | nossoNumero: '99999999', 54 | nomePagador: 'CLIENTE TESTE', 55 | valor: '500', 56 | valorLiquidado: '500', 57 | dataEmissao: '2018-12-13', 58 | dataVencimento: '2018-12-16', 59 | dataLiquidacao: '2018-12-13', 60 | situacao: 'LIQUIDADO' 61 | } 62 | ]) 63 | }) 64 | }) 65 | -------------------------------------------------------------------------------- /tests/index.spec.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | /* eslint-disable no-unused-expressions */ 3 | 4 | import { expect } from 'chai' 5 | import Sicredi from '../src/index' 6 | 7 | describe('Sicredi Library', () => { 8 | it('should create on instace of Sicredi', () => { 9 | const sicredi = new Sicredi({ 10 | agency: '1234', 11 | station: '10' 12 | }) 13 | expect(sicredi).to.be.an.instanceof(Sicredi) 14 | }) 15 | 16 | it('should receive apiURL as on option', () => { 17 | const sicredi = new Sicredi({ 18 | apiURL: 'foo' 19 | }) 20 | expect(sicredi.apiURL).to.be.equal('foo') 21 | }) 22 | 23 | it('should return apiURL equal `bar`', () => { 24 | const sicredi = new Sicredi({ 25 | apiURL: 'bar' 26 | }) 27 | expect(sicredi.apiURL).to.be.equal('bar') 28 | }) 29 | 30 | it('should use the default apiURL if not provider', () => { 31 | const sicredi = new Sicredi({}) 32 | expect(sicredi.apiURL).to.be.equal( 33 | 'https://cobrancaonline.sicredi.com.br/sicredi-cobranca-ws-ecomm-api/ecomm/v1/boleto' 34 | ) 35 | }) 36 | 37 | it('should receive token as on option', () => { 38 | const sicredi = new Sicredi({ 39 | token: 'bar' 40 | }) 41 | expect(sicredi.token).to.be.equal('bar') 42 | }) 43 | 44 | it('should receive agency as on option', () => { 45 | const sicredi = new Sicredi({ 46 | agency: '1234' 47 | }) 48 | expect(sicredi.agency).to.be.equal('1234') 49 | }) 50 | 51 | it('should receive agency as on option', () => { 52 | const sicredi = new Sicredi({ 53 | station: '99' 54 | }) 55 | expect(sicredi.station).to.be.equal('99') 56 | }) 57 | 58 | it('should receive agency as on option', () => { 59 | const sicredi = new Sicredi({ 60 | assignor: '12345' 61 | }) 62 | expect(sicredi.assignor).to.be.equal('12345') 63 | }) 64 | 65 | it('should have request method', () => { 66 | const sicredi = new Sicredi({}) 67 | expect(sicredi.request).to.exist 68 | expect(sicredi.request).to.be.a('function') 69 | }) 70 | }) 71 | -------------------------------------------------------------------------------- /tests/print.spec.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | /* eslint-disable no-unused-expressions */ 3 | 4 | import chai, { expect } from 'chai' 5 | import chaiAsPromised from 'chai-as-promised' 6 | import chaiSubset from 'chai-subset' 7 | import nock from 'nock' 8 | import path from 'path' 9 | import Sicredi from '../src/index' 10 | 11 | chai.use(chaiAsPromised) 12 | chai.use(chaiSubset) 13 | 14 | describe('print method', () => { 15 | let sicredi 16 | 17 | beforeEach(() => { 18 | sicredi = new Sicredi({ 19 | token: 'foo', 20 | agency: 1234, 21 | station: 99, 22 | assignor: 12345 23 | }) 24 | }) 25 | 26 | it('should have print method', () => { 27 | expect(sicredi.print).to.be.exist 28 | expect(sicredi.print).to.be.a('function') 29 | }) 30 | 31 | it('should return array of billet for print with success', () => { 32 | const query = { 33 | nossoNumero: 99999999 34 | } 35 | 36 | nock( 37 | 'https://cobrancaonline.sicredi.com.br/sicredi-cobranca-ws-ecomm-api/ecomm/v1/boleto' 38 | ) 39 | .get('/impressao') 40 | .query({ 41 | ...query, 42 | agencia: sicredi.agency, 43 | posto: sicredi.station, 44 | cedente: sicredi.assignor 45 | }) 46 | .replyWithFile( 47 | 200, 48 | path.join(__dirname, '/fixtures/print-with-success.json') 49 | ) 50 | 51 | return expect(sicredi.print(query)).to.eventually.deep.equal({ 52 | menssagem: 'Processado com sucesso.', 53 | arquivo: 54 | 'JVBERi0xLjQKJeLjz9MKMSAwIG9iaiA8PC9UeXBlL1hPYmplY3QvUmVzb3VyY2VzPDwvUHJvY1NldCBbL1BERiAvVGV4dCAvSW1hZ2VCIC9JbWFnZUMgL0ltYWdlSV0vRm9udDw8L0FyaWFsLUJvbGRNVCAyIDAgUj4+Pj4vU3VidHlwZS9Gb3JtL0JCb3hbMCAwIDM0OC41IDI2LjldL01hdHJpeCBbMSAwIDAgMSAwIDBdL0xlbmd0aCAxMzMvRm9ybVR5cGUgMS9GaWx0ZXIvRmxhdGVEZWNvZGU+PnN0cmVhbQp4nC2OvQrCQBCEX2VKLdzsXu63NJIyReDAWlCDEpWk8vEdgjPdzLfLLBjR1C+64YQFSrc+S4CLUrDecMabeVdhW2koEgOyqEN9oTmuj8t86D7zdSDC7L5hinXCLvlcTMyyMaFaST6oBYIum7DU6PkyJa9/RdV9ffJ+Ql85bUTPYT8QLCRTCmVuZHN0cmVhbQplbmRvYmoKMyAwIG9iaiA8PC9UeXBlL1hPYmplY3QvUmVzb3VyY2VzPDwvUHJvY1NldCBbL1BERiAvVGV4dCAvSW1hZ2VCIC9JbWFnZUMgL0ltYWdlSV0vRm9udDw8L0FyaWFsLUJvbGRNVCAyIDAgUj4+Pj4vU3VidHlwZS9Gb3JtL0JCb3hbMCAwIDUyLjcgMjYuOF0vTWF0cml4IFsxIDAgMCAxIDAgMF0vTGVuZ3RoIDEwNy9Gb3JtVHlwZSAxL0ZpbHRlci9GbGF0ZURlY29kZT4+c3RyZWFtCnicHY2xCoNAFAR/ZUpTeJ6nF6/NiaWF8MA6EJU' 55 | }) 56 | }) 57 | }) 58 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "node-sicredi", 3 | "version": "1.0.4", 4 | "description": "Uma biblioteca JavaScript para interagir com o WebService EcommResource, para gerenciamento de boletos, do banco Sicredi", 5 | "main": "lib/index.js", 6 | "scripts": { 7 | "clear": "rimraf lib", 8 | "build": "npm run clear && babel --out-dir lib src", 9 | "build:watch": "npm run build -- --watch", 10 | "lint": "standard", 11 | "lint:fix": "standard --fix", 12 | "test": "mocha tests/**/*.spec.js --require @babel/register --require @babel/polyfill", 13 | "test:tdd": "mocha tests/**/*.spec.js --require @babel/register --require @babel/polyfill --watch", 14 | "test:coverage": "nyc npm test -- --exit", 15 | "coveralls": "npm run test:coverage && nyc report --reporter=text-lcov | coveralls" 16 | }, 17 | "files": [ 18 | "lib" 19 | ], 20 | "nyc": { 21 | "functions": 80, 22 | "lines": 80, 23 | "check-coverage": true, 24 | "reporter": [ 25 | "text", 26 | "html" 27 | ], 28 | "exclude": [ 29 | "tests/**", 30 | "./node_modules/" 31 | ] 32 | }, 33 | "repository": { 34 | "type": "git", 35 | "url": "git+https://github.com/murilosandiego/node-sicredi.git" 36 | }, 37 | "keywords": [ 38 | "boleto", 39 | "sicredi", 40 | "node", 41 | "promise" 42 | ], 43 | "author": "Murilo Sandiego (http://murilosandiego.com.br/)", 44 | "license": "MIT", 45 | "bugs": { 46 | "url": "https://github.com/murilosandiego/node-sicredi/issues" 47 | }, 48 | "homepage": "https://github.com/murilosandiego/node-sicredi#readme", 49 | "devDependencies": { 50 | "@babel/cli": "^7.8.4", 51 | "@babel/core": "^7.9.0", 52 | "@babel/node": "^7.8.7", 53 | "@babel/polyfill": "^7.8.7", 54 | "@babel/preset-env": "^7.9.5", 55 | "@babel/register": "^7.9.0", 56 | "chai": "^4.2.0", 57 | "chai-as-promised": "^7.1.1", 58 | "chai-subset": "^1.6.0", 59 | "coveralls": "^3.0.11", 60 | "husky": "^1.3.1", 61 | "mocha": "^7.1.1", 62 | "nock": "^10.0.6", 63 | "nyc": "^14.1.1", 64 | "rimraf": "^2.7.1", 65 | "sinon": "^7.5.0", 66 | "sinon-chai": "^3.5.0", 67 | "standard": "^12.0.1" 68 | }, 69 | "standard": { 70 | "ignore": [ 71 | "lib/" 72 | ], 73 | "globals": [ 74 | "describe", 75 | "context", 76 | "it", 77 | "beforeEach", 78 | "afterEach" 79 | ] 80 | }, 81 | "husky": { 82 | "hooks": { 83 | "pre-push": "npm run lint && npm run test:coverage" 84 | } 85 | }, 86 | "dependencies": { 87 | "request": "^2.88.2", 88 | "request-promise-native": "^1.0.8" 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /tests/auth.spec.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | /* eslint-disable no-unused-expressions */ 3 | 4 | import chai, { expect } from 'chai' 5 | import chaiAsPromised from 'chai-as-promised' 6 | import chaiSubset from 'chai-subset' 7 | import nock from 'nock' 8 | import path from 'path' 9 | import Sicredi from '../src/index' 10 | import SicrediError from '../src/erros/sicredi' 11 | 12 | chai.use(chaiAsPromised) 13 | chai.use(chaiSubset) 14 | 15 | describe('auth method', () => { 16 | let sicredi 17 | 18 | beforeEach(() => { 19 | sicredi = new Sicredi({ 20 | token: 'foo', 21 | agency: '1234', 22 | station: '99' 23 | }) 24 | }) 25 | 26 | afterEach(() => { 27 | nock.cleanAll() 28 | }) 29 | 30 | it('should have auth method', () => { 31 | expect(sicredi.auth).to.exist 32 | expect(sicredi.auth).to.be.a('function') 33 | }) 34 | 35 | context('with erros', () => { 36 | it('should return 404 with token registed', async () => { 37 | nock( 38 | 'https://cobrancaonline.sicredi.com.br/sicredi-cobranca-ws-ecomm-api/ecomm/v1/boleto' 39 | ) 40 | .post('/autenticacao') 41 | .replyWithFile( 42 | 404, 43 | path.join(__dirname, '/fixtures/auth-with-token-registered.json') 44 | ) 45 | 46 | return sicredi.auth('keyMaster').catch(error => { 47 | return expect(error) 48 | .to.be.an.instanceOf(SicrediError) 49 | .and.containSubset({ 50 | error: { 51 | codigo: '0004', 52 | mensagem: 'Existe um Token de Transação válido cadastrado!', 53 | parametro: '' 54 | } 55 | }) 56 | }) 57 | }) 58 | it('should return erro with invalid token', async () => { 59 | nock( 60 | 'https://cobrancaonline.sicredi.com.br/sicredi-cobranca-ws-ecomm-api/ecomm/v1/boleto' 61 | ) 62 | .post('/autenticacao') 63 | .replyWithFile( 64 | 400, 65 | path.join(__dirname, '/fixtures/auth-with-invalid-token.json') 66 | ) 67 | 68 | return sicredi.auth('invalidToken').catch(error => { 69 | return expect(error) 70 | .to.be.an.instanceOf(SicrediError) 71 | .and.containSubset({ 72 | error: { 73 | codigo: 'E0011', 74 | mensagem: 'Tamanho de campo invalido.', 75 | parametro: 'token' 76 | } 77 | }) 78 | }) 79 | }) 80 | }) 81 | 82 | context('with success', () => { 83 | it('should return token with success', () => { 84 | nock( 85 | 'https://cobrancaonline.sicredi.com.br/sicredi-cobranca-ws-ecomm-api/ecomm/v1/boleto' 86 | ) 87 | .post('/autenticacao') 88 | .replyWithFile( 89 | 200, 90 | path.join(__dirname, '/fixtures/auth-with-success.json') 91 | ) 92 | 93 | return expect(sicredi.auth('keyMaster')).to.eventually.deep.equal({ 94 | chaveTransacao: '99999999999999999999999999999999999999999', 95 | dataExpiracao: '2019-04-13T18:08:46.471-03:00' 96 | }) 97 | }) 98 | }) 99 | }) 100 | -------------------------------------------------------------------------------- /src/index.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | import rp from 'request-promise-native' 4 | import SicrediError from './erros/sicredi' 5 | import { 6 | API_URL, 7 | AUTH_PATH, 8 | CREATE_PATH, 9 | FIND_PATH, 10 | PRINT_PATH, 11 | CHANGE_PATH, 12 | HEALTH_PATH 13 | } from './config' 14 | 15 | class Sicredi { 16 | constructor (options) { 17 | this.apiURL = options.apiURL || API_URL 18 | this.token = options.token 19 | this.agency = options.agency 20 | this.assignor = options.assignor 21 | this.station = options.station 22 | this.strictSSL = options.strictSSL || false 23 | } 24 | 25 | request (path, headers, options) { 26 | let optionsRequest = { 27 | strictSSL: this.strictSSL, 28 | uri: `${this.apiURL}/${path}`, 29 | headers, 30 | ...options, 31 | json: true 32 | } 33 | 34 | return rp(optionsRequest) 35 | .then(response => response) 36 | .catch(error => { 37 | throw new SicrediError(error.error) 38 | }) 39 | } 40 | 41 | auth (keyMaster) { 42 | const headers = { 43 | token: keyMaster, 44 | 'Content-Type': 'application/json' 45 | } 46 | 47 | const options = { 48 | method: 'POST' 49 | } 50 | 51 | return this.request(AUTH_PATH, headers, options) 52 | } 53 | 54 | create (body) { 55 | const headers = { 56 | token: this.token, 57 | 'Content-Type': 'application/json' 58 | } 59 | 60 | const options = { 61 | method: 'POST', 62 | body: { 63 | ...body, 64 | agencia: this.agency, 65 | cedente: this.assignor, 66 | posto: this.station 67 | } 68 | } 69 | 70 | return this.request(CREATE_PATH, headers, options) 71 | } 72 | 73 | find (qs) { 74 | const headers = { 75 | token: this.token 76 | } 77 | 78 | const options = { 79 | method: 'GET', 80 | qs: { 81 | ...qs, 82 | agencia: this.agency, 83 | cedente: this.assignor, 84 | posto: this.station 85 | } 86 | } 87 | 88 | return this.request(FIND_PATH, headers, options) 89 | } 90 | 91 | print (qs) { 92 | const headers = { 93 | token: this.token 94 | } 95 | 96 | const options = { 97 | method: 'GET', 98 | qs: { 99 | ...qs, 100 | agencia: this.agency, 101 | cedente: this.assignor, 102 | posto: this.station 103 | } 104 | } 105 | 106 | return this.request(PRINT_PATH, headers, options) 107 | } 108 | 109 | change (body) { 110 | const headers = { 111 | token: this.token, 112 | 'Content-Type': 'application/json' 113 | } 114 | 115 | const options = { 116 | method: 'POST', 117 | body: { 118 | ...body, 119 | agencia: this.agency, 120 | cedente: this.assignor, 121 | posto: this.station 122 | } 123 | } 124 | 125 | return this.request(CHANGE_PATH, headers, options) 126 | } 127 | 128 | health (qs) { 129 | const headers = { 130 | token: this.token 131 | } 132 | 133 | const options = { 134 | method: 'GET' 135 | } 136 | 137 | return this.request(HEALTH_PATH, headers, options) 138 | } 139 | } 140 | export default Sicredi 141 | -------------------------------------------------------------------------------- /lib/erros/sicredi.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | Object.defineProperty(exports, "__esModule", { 4 | value: true 5 | }); 6 | exports["default"] = void 0; 7 | 8 | function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } 9 | 10 | function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } 11 | 12 | function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); } 13 | 14 | function _createSuper(Derived) { return function () { var Super = _getPrototypeOf(Derived), result; if (_isNativeReflectConstruct()) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; } 15 | 16 | function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); } 17 | 18 | function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } 19 | 20 | function _wrapNativeSuper(Class) { var _cache = typeof Map === "function" ? new Map() : undefined; _wrapNativeSuper = function _wrapNativeSuper(Class) { if (Class === null || !_isNativeFunction(Class)) return Class; if (typeof Class !== "function") { throw new TypeError("Super expression must either be null or a function"); } if (typeof _cache !== "undefined") { if (_cache.has(Class)) return _cache.get(Class); _cache.set(Class, Wrapper); } function Wrapper() { return _construct(Class, arguments, _getPrototypeOf(this).constructor); } Wrapper.prototype = Object.create(Class.prototype, { constructor: { value: Wrapper, enumerable: false, writable: true, configurable: true } }); return _setPrototypeOf(Wrapper, Class); }; return _wrapNativeSuper(Class); } 21 | 22 | function _construct(Parent, args, Class) { if (_isNativeReflectConstruct()) { _construct = Reflect.construct; } else { _construct = function _construct(Parent, args, Class) { var a = [null]; a.push.apply(a, args); var Constructor = Function.bind.apply(Parent, a); var instance = new Constructor(); if (Class) _setPrototypeOf(instance, Class.prototype); return instance; }; } return _construct.apply(null, arguments); } 23 | 24 | function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } } 25 | 26 | function _isNativeFunction(fn) { return Function.toString.call(fn).indexOf("[native code]") !== -1; } 27 | 28 | function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } 29 | 30 | function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } 31 | 32 | var SicrediError = /*#__PURE__*/function (_Error) { 33 | _inherits(SicrediError, _Error); 34 | 35 | var _super = _createSuper(SicrediError); 36 | 37 | function SicrediError(error) { 38 | var _this; 39 | 40 | _classCallCheck(this, SicrediError); 41 | 42 | _this = _super.call(this); 43 | _this.error = error; 44 | return _this; 45 | } 46 | 47 | return SicrediError; 48 | }( /*#__PURE__*/_wrapNativeSuper(Error)); 49 | 50 | exports["default"] = SicrediError; -------------------------------------------------------------------------------- /tests/create.spec.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | /* eslint-disable no-unused-expressions */ 3 | 4 | import chai, { expect } from 'chai' 5 | import chaiAsPromised from 'chai-as-promised' 6 | import chaiSubset from 'chai-subset' 7 | import nock from 'nock' 8 | import path from 'path' 9 | import Sicredi from '../src/index' 10 | import SicrediError from '../src/erros/sicredi' 11 | 12 | chai.use(chaiAsPromised) 13 | chai.use(chaiSubset) 14 | 15 | describe('create method', () => { 16 | let sicredi 17 | 18 | beforeEach(() => { 19 | sicredi = new Sicredi({ 20 | token: 'foo', 21 | agency: '1234', 22 | station: '12', 23 | assignor: 12345 24 | }) 25 | }) 26 | 27 | it('should have create method', () => { 28 | expect(sicredi.create).to.be.exist 29 | expect(sicredi.create).to.be.a('function') 30 | }) 31 | 32 | context('with erros', () => { 33 | it('should return erro if required params not insert', () => { 34 | sicredi = new Sicredi({ 35 | token: 'foo', 36 | agency: 1234, 37 | assignor: 12345, 38 | station: 12 39 | }) 40 | 41 | const body = { 42 | nossoNumero: '', 43 | codigoPagador: '', 44 | tipoPessoa: '1', 45 | nome: 'Cliente Teste', 46 | endereco: 'Rua 1', 47 | cidade: 'Rio de Janeiro', 48 | uf: 'RJ', 49 | cep: '99999999', 50 | telefone: '9999999999', 51 | email: 'cliente@email.com', 52 | especieDocumento: 'B', 53 | codigoSacadorAvalista: '000', 54 | seuNumero: '0000000002', 55 | dataVencimento: '16/05/2019', 56 | valor: 6, 57 | tipoDesconto: 'A', 58 | valorDesconto1: null, 59 | dataDesconto1: null, 60 | valorDesconto2: null, 61 | dataDesconto2: null, 62 | valorDesconto3: null, 63 | dataDesconto3: null, 64 | tipoJuros: 'A', 65 | juros: null, 66 | multas: null, 67 | descontoAntecipado: null, 68 | informativo: 'teste1', 69 | mensagem: 'teste', 70 | codigoMensagem: '' 71 | } 72 | 73 | nock( 74 | 'https://cobrancaonline.sicredi.com.br/sicredi-cobranca-ws-ecomm-api/ecomm/v1/boleto' 75 | ) 76 | .post('/emissao', { 77 | ...body, 78 | agencia: sicredi.agency, 79 | posto: sicredi.station, 80 | cedente: sicredi.assignor 81 | }) 82 | .replyWithFile( 83 | 400, 84 | path.join(__dirname, '/fixtures/create-with-erro.json') 85 | ) 86 | 87 | return sicredi.create(body).catch(error => { 88 | return expect(error) 89 | .to.be.an.instanceOf(SicrediError) 90 | .and.containSubset({ 91 | error: { 92 | codigo: 'E0010', 93 | mensagem: 'Campo obrigatorio em branco.', 94 | parametro: 'cpfCnpj' 95 | } 96 | }) 97 | }) 98 | }) 99 | }) 100 | 101 | context('with success', () => { 102 | const body = { 103 | nossoNumero: '', 104 | codigoPagador: '', 105 | tipoPessoa: '1', 106 | cpfCnpj: '99999999999', 107 | nome: 'Cliente Teste', 108 | endereco: 'Rua 1', 109 | cidade: 'Rio de Janeiro', 110 | uf: 'RJ', 111 | cep: '99999999', 112 | telefone: '9999999999', 113 | email: 'cliente@email.com', 114 | especieDocumento: 'B', 115 | codigoSacadorAvalista: '000', 116 | seuNumero: '0000000002', 117 | dataVencimento: '16/05/2019', 118 | valor: 6, 119 | tipoDesconto: 'A', 120 | valorDesconto1: null, 121 | dataDesconto1: null, 122 | valorDesconto2: null, 123 | dataDesconto2: null, 124 | valorDesconto3: null, 125 | dataDesconto3: null, 126 | tipoJuros: 'A', 127 | juros: null, 128 | multas: null, 129 | descontoAntecipado: null, 130 | informativo: 'teste1', 131 | mensagem: 'teste', 132 | codigoMensagem: '' 133 | } 134 | it('should return billet with success', () => { 135 | nock( 136 | 'https://cobrancaonline.sicredi.com.br/sicredi-cobranca-ws-ecomm-api/ecomm/v1/boleto' 137 | ) 138 | .post('/emissao', { 139 | ...body, 140 | agencia: sicredi.agency, 141 | posto: sicredi.station, 142 | cedente: sicredi.assignor 143 | }) 144 | .replyWithFile( 145 | 201, 146 | path.join(__dirname, '/fixtures/create-with-success.json') 147 | ) 148 | 149 | return expect(sicredi.create(body)).to.eventually.deep.equal({ 150 | linhaDigitavel: '74899999999999', 151 | codigoBanco: '748', 152 | nomeBeneficiario: 'EMPRESA', 153 | enderecoBeneficiario: 'R. 1, 708', 154 | cpfCnpjBeneficiario: '9999999999999', 155 | cooperativaBeneficiario: '9999', 156 | postoBeneficiario: '99', 157 | codigoBeneficiario: '99999', 158 | dataDocumento: '2019-04-13', 159 | seuNumero: '0000000002', 160 | especieDocumento: 'B', 161 | aceite: 'N', 162 | dataProcessamento: '2019-04-13', 163 | nossoNumero: 999999999, 164 | especie: 'REAL', 165 | valorDocumento: 6, 166 | dataVencimento: '2019-05-16', 167 | nomePagador: 'CLIENTE TESTE', 168 | cpfCnpjPagador: '99999999999', 169 | enderecoPagador: 'R 1', 170 | dataLimiteDesconto: null, 171 | valorDesconto: 0, 172 | jurosMulta: 0, 173 | instrucao: 'teste\r', 174 | informativo: 'teste1\r', 175 | codigoBarra: '748999999999999999999' 176 | }) 177 | }) 178 | }) 179 | }) 180 | -------------------------------------------------------------------------------- /lib/index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | Object.defineProperty(exports, "__esModule", { 4 | value: true 5 | }); 6 | exports["default"] = void 0; 7 | 8 | var _requestPromiseNative = _interopRequireDefault(require("request-promise-native")); 9 | 10 | var _sicredi = _interopRequireDefault(require("./erros/sicredi")); 11 | 12 | var _config = require("./config"); 13 | 14 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } 15 | 16 | function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; } 17 | 18 | function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; } 19 | 20 | function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } 21 | 22 | function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } 23 | 24 | function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } 25 | 26 | function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } 27 | 28 | var Sicredi = /*#__PURE__*/function () { 29 | function Sicredi(options) { 30 | _classCallCheck(this, Sicredi); 31 | 32 | this.apiURL = options.apiURL || _config.API_URL; 33 | this.token = options.token; 34 | this.agency = options.agency; 35 | this.assignor = options.assignor; 36 | this.station = options.station; 37 | this.strictSSL = options.strictSSL || false; 38 | } 39 | 40 | _createClass(Sicredi, [{ 41 | key: "request", 42 | value: function request(path, headers, options) { 43 | var optionsRequest = _objectSpread({ 44 | strictSSL: this.strictSSL, 45 | uri: "".concat(this.apiURL, "/").concat(path), 46 | headers: headers 47 | }, options, { 48 | json: true 49 | }); 50 | 51 | return (0, _requestPromiseNative["default"])(optionsRequest).then(function (response) { 52 | return response; 53 | })["catch"](function (error) { 54 | throw new _sicredi["default"](error.error); 55 | }); 56 | } 57 | }, { 58 | key: "auth", 59 | value: function auth(keyMaster) { 60 | var headers = { 61 | token: keyMaster, 62 | 'Content-Type': 'application/json' 63 | }; 64 | var options = { 65 | method: 'POST' 66 | }; 67 | return this.request(_config.AUTH_PATH, headers, options); 68 | } 69 | }, { 70 | key: "create", 71 | value: function create(body) { 72 | var headers = { 73 | token: this.token, 74 | 'Content-Type': 'application/json' 75 | }; 76 | var options = { 77 | method: 'POST', 78 | body: _objectSpread({}, body, { 79 | agencia: this.agency, 80 | cedente: this.assignor, 81 | posto: this.station 82 | }) 83 | }; 84 | return this.request(_config.CREATE_PATH, headers, options); 85 | } 86 | }, { 87 | key: "find", 88 | value: function find(qs) { 89 | var headers = { 90 | token: this.token 91 | }; 92 | var options = { 93 | method: 'GET', 94 | qs: _objectSpread({}, qs, { 95 | agencia: this.agency, 96 | cedente: this.assignor, 97 | posto: this.station 98 | }) 99 | }; 100 | return this.request(_config.FIND_PATH, headers, options); 101 | } 102 | }, { 103 | key: "print", 104 | value: function print(qs) { 105 | var headers = { 106 | token: this.token 107 | }; 108 | var options = { 109 | method: 'GET', 110 | qs: _objectSpread({}, qs, { 111 | agencia: this.agency, 112 | cedente: this.assignor, 113 | posto: this.station 114 | }) 115 | }; 116 | return this.request(_config.PRINT_PATH, headers, options); 117 | } 118 | }, { 119 | key: "change", 120 | value: function change(body) { 121 | var headers = { 122 | token: this.token, 123 | 'Content-Type': 'application/json' 124 | }; 125 | var options = { 126 | method: 'POST', 127 | body: _objectSpread({}, body, { 128 | agencia: this.agency, 129 | cedente: this.assignor, 130 | posto: this.station 131 | }) 132 | }; 133 | return this.request(_config.CHANGE_PATH, headers, options); 134 | } 135 | }, { 136 | key: "health", 137 | value: function health(qs) { 138 | var headers = { 139 | token: this.token 140 | }; 141 | var options = { 142 | method: 'GET' 143 | }; 144 | return this.request(_config.HEALTH_PATH, headers, options); 145 | } 146 | }]); 147 | 148 | return Sicredi; 149 | }(); 150 | 151 | var _default = Sicredi; 152 | exports["default"] = _default; -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Node Sicredi 2 | 3 | [![Build Status](https://travis-ci.org/murilosandiego/node-sicredi.svg?branch=master)](https://travis-ci.org/murilosandiego/node-sicredi) 4 | [![Coverage Status](https://coveralls.io/repos/github/murilosandiego/node-sicredi/badge.svg?branch=master)](https://coveralls.io/github/murilosandiego/node-sicredi?branch=master) 5 | [![npm version](https://badge.fury.io/js/node-sicredi.svg)](https://badge.fury.io/js/node-sicredi) 6 | [![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com) 7 | 8 | > Uma biblioteca em Node.js para interagir com o WebService, [EcommResource](docs/manualECommAPISicredi.pdf), do Banco Sicredi, para gerenciamento de boletos. 9 | > Esta tem como objetivo facilitar a criação, consulta, impressão etc de boletos utilizando Promise. 10 | 11 | ### Instalação 12 | 13 | ``` 14 | $ npm install node-sicredi --save 15 | ``` 16 | 17 | ## Como utilizar 18 | 19 | ### ES6 20 | 21 | ```js 22 | import Sicredi from 'node-sicredi'; 23 | 24 | const sicredi = new Sicredi({ 25 | token: 'SEU_TOKEN', 26 | agency: 'AGENCIA', 27 | assignor: 'CEDENTE', 28 | station: 'POSTO', 29 | }); 30 | 31 | // Utilizando um método 32 | sicredi 33 | .find({ 34 | dataInicio: '10/10/2018', 35 | dataFim: '31/12/2018', 36 | tipoData: 'DATA_EMISSAO', 37 | }) 38 | .then(data => { 39 | console.log(data); 40 | }) 41 | .catch(err => console.log(err)); 42 | ``` 43 | 44 | ### CommonJS 45 | 46 | ```js 47 | const Sicredi = require('node-sicredi').default; 48 | 49 | const sicredi = new Sicredi({ 50 | token: 'SEU_TOKEN', 51 | agency: 'AGENCIA', 52 | assignor: 'CEDENTE', 53 | station: 'POSTO', 54 | }); 55 | 56 | sicredi 57 | .find({ 58 | dataInicio: '10/10/2018', 59 | dataFim: '31/12/2018', 60 | tipoData: 'DATA_EMISSAO', 61 | }) 62 | .then(data => { 63 | console.log(data); 64 | }) 65 | .catch(err => console.log(err)); 66 | ``` 67 | 68 | ## Métodos 69 | 70 | ### sicredi.auth('keyMaster') 71 | 72 | > O método “auth” é responsável por criar uma chave criptografada, denominada chaveTransacao (chamamos de token), baseada na chave master. 73 | 74 | **Argumento** 75 | 76 | | Argument | Type | 77 | | ----------- | -------- | 78 | | `keyMaster` | _string_ | 79 | 80 | **Exemplo** 81 | 82 | ```js 83 | import Sicredi from 'node-sicredi'; 84 | 85 | sicredi = new Sicredi({}); 86 | sicredi.auth('keyMaster').then(data => { 87 | //Chave de transação. Obs: Aqui chamamos de token 88 | }); 89 | ``` 90 | 91 | ### sicredi.create(body) 92 | 93 | > O método “create” é responsável pela geração do boleto de Cobrança. 94 | 95 | **Argumento** 96 | 97 | | Argument | Type | 98 | | -------- | -------- | 99 | | `body` | _objeto_ | 100 | 101 | **Exemplo** 102 | 103 | ```js 104 | import Sicredi from 'node-sicredi'; 105 | 106 | const sicredi = new Sicredi({ 107 | token: 'SEU_TOKEN', 108 | agency: 'AGENCIA', 109 | assignor: 'CEDENTE', 110 | station: 'POSTO', 111 | }); 112 | 113 | const body = { 114 | nossoNumero: '', 115 | codigoPagador: '', 116 | tipoPessoa: '1', 117 | nome: 'Cliente Teste', 118 | endereco: 'Rua 1', 119 | cidade: 'Rio de Janeiro', 120 | uf: 'RJ', 121 | cep: '99999999', 122 | telefone: '9999999999', 123 | email: 'cliente@email.com', 124 | especieDocumento: 'B', 125 | codigoSacadorAvalista: '000', 126 | seuNumero: '0000000002', 127 | dataVencimento: '16/05/2019', 128 | valor: 6, 129 | tipoDesconto: 'A', 130 | valorDesconto1: null, 131 | dataDesconto1: null, 132 | valorDesconto2: null, 133 | dataDesconto2: null, 134 | valorDesconto3: null, 135 | dataDesconto3: null, 136 | tipoJuros: 'A', 137 | juros: null, 138 | multas: null, 139 | descontoAntecipado: null, 140 | informativo: 'teste1', 141 | mensagem: 'teste', 142 | codigoMensagem: '', 143 | }; 144 | 145 | sicredi.create(body).then(data => { 146 | // Boleto 147 | }); 148 | ``` 149 | 150 | ### sicredi.find(query) 151 | 152 | > O método “find” é responsável pela consulta da situação de boletos. 153 | 154 | **Argumento** 155 | 156 | | Argument | Type | 157 | | -------- | -------- | 158 | | `query` | _objeto_ | 159 | 160 | **Exemplo** 161 | 162 | ```js 163 | import Sicredi from 'node-sicredi'; 164 | 165 | const sicredi = new Sicredi({ 166 | token: 'SEU_TOKEN', 167 | agency: 'AGENCIA', 168 | assignor: 'CEDENTE', 169 | station: 'POSTO', 170 | }); 171 | 172 | const query = { 173 | nossoNumero: 99999999, 174 | }; 175 | 176 | sicredi.find(query).then(data => { 177 | // Array Boleto(s) 178 | }); 179 | ``` 180 | 181 | ### sicredi.print(query) 182 | 183 | > O método “print” é responsável pela impressão e reimpressão dos boletos de Cobrança. 184 | 185 | **Argumento** 186 | 187 | | Argument | Type | 188 | | -------- | -------- | 189 | | `query` | _objeto_ | 190 | 191 | **Exemplo** 192 | 193 | ```js 194 | import Sicredi from 'node-sicredi'; 195 | 196 | const sicredi = new Sicredi({ 197 | token: 'SEU_TOKEN', 198 | agency: 'AGENCIA', 199 | assignor: 'CEDENTE', 200 | station: 'POSTO', 201 | }); 202 | 203 | const query = { 204 | nossoNumero: 99999999, 205 | }; 206 | 207 | sicredi.print(query).then(data => { 208 | // Boleto 209 | }); 210 | ``` 211 | 212 | ### sicredi.change(body) 213 | 214 | > O método “change” é responsável por alterar dados dos títulos via serviço. 215 | 216 | **Arguments** 217 | 218 | | Argument | Type | 219 | | -------- | -------- | 220 | | `body` | _objeto_ | 221 | 222 | **Exemplo** 223 | 224 | ```js 225 | import Sicredi from 'node-sicredi'; 226 | 227 | const sicredi = new Sicredi({ 228 | token: 'SEU_TOKEN', 229 | agency: 'AGENCIA', 230 | assignor: 'CEDENTE', 231 | station: 'POSTO', 232 | }); 233 | 234 | const body = { 235 | agencia: '1234', 236 | posto: '99', 237 | cedente: '12345', 238 | nossoNumero: '999999999', 239 | seuNumero: '9999999999', 240 | instrucaoComando: 'ALTERACAO_SEU_NUMERO', 241 | tipoVencimento: 'VISTA', 242 | }; 243 | 244 | sicredi.change(body).then(data => { 245 | //Resposta 246 | }); 247 | ``` 248 | 249 | ### sicredi.health() 250 | 251 | > O método “health” é responsável pela verificação da disponibilidade do sistema de Cobrança. 252 | 253 | **Exemplo** 254 | 255 | ```js 256 | import Sicredi from 'node-sicredi'; 257 | 258 | const sicredi = new Sicredi({}); 259 | sicredi.health().then(data => { 260 | //Resposta 261 | }); 262 | ``` 263 | 264 | ## Contribuíndo 265 | 266 | Por favor, leia [CONTRIBUTING.md](CONTRIBUTING.md) para detalhes sobre o processo para enviar pull request. 267 | 268 | ## Autor 269 | 270 | | ![Murilo Sandiego](https://avatars3.githubusercontent.com/u/11686438?s=150&v=4) | 271 | | :-----------------------------------------------------------------------------: | 272 | | [Murilo Sandiego](https://github.com/murilosandiego/) | 273 | 274 | Olhe também a lista de [contribuidores](https://github.com/murilosandiego/node-sicredi/contributors). 275 | 276 | ## License 277 | 278 | Este projeto está licencidado sobre a licença MIT - consulte o arquivo [LICENSE.md](LICENSE.md) para mais detalhes 279 | --------------------------------------------------------------------------------