BPe on Node.js

Hellooo my fellow developer!

Are you looking for an easy and quick way to issue BPe on node.js (bus ticket e-invoce)?

So grab your coffee and get ready, because in this post I’m going to show you our npm package for issuing bpe’s using NS Tecnologia’s BPe API.

First, download our library through our GitHub or directly from the npm package using the command “npm install ns-bpe-node”.

After downloading the package, head to the folder in Visual Studio Code where we can see the composition of the project.

modules BPe on node.js

You will find a “ns_modules” folder, which are the NS Tecnologia modules, inside there is the “api_module” folders where our communication with the API is located through the “postRequest” function, the “bpe_module” folder that contains the issue functions, BPe events and utilities.

In the root folder of the project, you will find the “configParceiro.js” file. In this file, we placed as an example the Token that is for the exclusive use of NS partners for secure communication and the CNPJ of the BPe issuer.
(This is an example form for passing this data, and the partner can choose which way it will pass)

config partner BPe on node.js

To issue our example BPe, add a JSON file to the root folder, having all the mandatory fields to issue a BPe through the NS API
After that, call the issue function. You can create a file called “issueBPe.js” and in it, invoke emitirBPeSincrono function that will send the json file to the NS API. 

Next, make the query of processing status to get the return from SEFAZ for this BPe and finally it will download the XML file, already authorized and the PDF to print this BPe.

emitir BPe on node.js

See the image below: at the start of the file, we have the reference to the “emitSincrono”, class so that we can invoke the “emitirBPeSincrono” function.

Below that we have the reference to our JSON file with the BPe data.
And finally, the call to our function emitBPeSincrono, passing the necessary parameters (In the sequence: content, tpAmb, tpDown, pathToSave).

require e caminho BPe on node.js

With that, you are prepared to issue a BPe via the NS technology API using our npm package.
In the VSCode terminal use the command “node .\emitirBPe.js” to call the synchronous function and issue the BPe.

emissão BPe on node.js

You can see the authorized response for the BPe, showing information such as the “cStat: 100” that comes directly from Sefaz along with the “xMotivo: Authorized use of BPe”. The access key of the document and the protocol number of authorization (nProt) that is very important to save so that events can be made in this BPe if necessary.

retorno BPe on node.js

So, that is it for now!

We hope you liked this post, we have a video showing the whole step by step to issue BPe using Node.JS and our npm package. You can access the video in this link 👇

Gostou do Post? Caso você não conheça nossa API entre em contato conosco! 

 

Deixe um comentário

O seu endereço de e-mail não será publicado. Campos obrigatórios são marcados com *