Skip to content

rprata/pixcode

Repository files navigation

Pixcode

Support Node of LTS npm version npm version dependencies typescript License mit

Description

Pixcode module is used to handler PIX qrcode based on BCB specification and BRCode Manual. It's completely written in typescript for node js.

How to use

Importing in your project:

npm install pixcode

Using in your code:

Parser

import { parse } from 'pixcode'
...
const qrcode = '00020101021226720014br.gov.bcb.pix2550bx.com.br/pix/8b3da2f3-9a41-40d1-a91a-bd93113bd4415204000053039865406123.455802BR5913Fulano de Tal6008BRASILIA62190515RP12345678-2019630445C8'
const result = parse(qrcode)
console.log(result)
{
   "payloadFormatIndicator":{
      "id":"00",
      "name":"Payload Format Indicator",
      "length":2,
      "value":"01",
      "mandatory":true,
      "description":"versão do payloadQRCPS-MPM, fixo em \"01\""
   },
   "pointOfInitiationMethod":{
      "id":"01",
      "name":"Point of Initiation Method",
      "length":2,
      "value":"12",
      "mandatory":false,
      "description":"\"11\" (QR reutilizável) ou \"12\" (QR utilizável apenas uma vez)"
   },
   "merchantAccountInformation":{
      "id":"26",
      "name":"Merchant Account Information",
      "length":72,
      "value":"0014br.gov.bcb.pix2550bx.com.br/pix/8b3da2f3-9a41-40d1-a91a-bd93113bd441",
      "mandatory":true,
      "description":"indica arranjo específico / \"00\" (GUI) obrigatório / \"01..99\" conform BCB"
   },
   "merchantCategoryCode":{
      "id":"52",
      "name":"Merchant Category Code",
      "length":4,
      "value":"0000",
      "mandatory":true,
      "description":"\"0000\" ou MCC ISO18245"
   },
   "transactionCurrency":{
      "id":"53",
      "name":"Transaction Currency",
      "length":3,
      "value":"986",
      "mandatory":true,
      "description":"ISO4217"
   },
   "transactionAmount":{
      "id":"54",
      "name":"Transaction Amount",
      "length":6,
      "value":"123.45",
      "mandatory":false,
      "description":"valor da transação. Ex.: \"0\", \"1.00\", \"123.99\""
   },
   "countryCode":{
      "id":"58",
      "name":"Country Code",
      "length":2,
      "value":"BR",
      "mandatory":true,
      "description":"código de país ISO3166-1 alpha 2"
   },
   "merchantName":{
      "id":"59",
      "name":"Merchant Name",
      "length":13,
      "value":"Fulano de Tal",
      "mandatory":true,
      "description":"nome do beneficiário/recebedor"
   },
   "merchantCity":{
      "id":"60",
      "name":"Merchant City",
      "length":8,
      "value":"BRASILIA",
      "mandatory":true,
      "description":"cidade onde é efetuada a transação"
   },
   "postalCode":{
      "id":"61",
      "name":"Postal Code",
      "length":0,
      "value":"",
      "mandatory":false,
      "description":"CEP da localidade onde é efetuada a transação"
   },
   "additionalDataField":{
      "id":"62",
      "name":"Additional Data Field",
      "length":19,
      "value":"0515RP12345678-2019",
      "mandatory":false,
      "description":"Campos adicionais"
   },
   "unreservedTemplates":{
      "id":"",
      "name":"Unreserved Templates",
      "length":0,
      "value":"",
      "mandatory":false,
      "description":"Campos não reservados"
   },
   "crc":{
      "id":"63",
      "name":"CRC",
      "length":4,
      "value":"45C8",
      "mandatory":true,
      "description":"CRC"
   }
}

Generator

import { generate } from 'pixcode'
...
const pixcode = {
  payloadFormatIndicator: {
    id: EmvTag.PayloadFormatIndicator,
    length: 2,
    value: '01'
  },
  pointOfInitiationMethod: {
    id: EmvTag.PointOfInitiationMethod,
    length: 2,
    value: '12'
  },
  merchantAccountInformation: {
    id: EmvTag.MerchantAccountInformation,
    length: 72,
    value: '0014br.gov.bcb.pix2550bx.com.br/pix/8b3da2f3-9a41-40d1-a91a-bd93113bd441'
  },
  merchantCategoryCode: {
    id: EmvTag.MerchantCategoryCode,
    length: 4,
    value: '0000'
  },
  transactionCurrency: {
    id: EmvTag.TransactionCurrency,
    length: 3,
    value: '986'
  },
  transactionAmount: {
    id: EmvTag.TransactionAmount,
    length: 5,
    value: '99.99'
  },
  countryCode: {
    id: EmvTag.CountryCode,
    name: 'Country Code',
    length: 2,
    value: 'BR'
  },
  merchantName: {
    id: EmvTag.MerchantName,
    length: 14,
    value: 'Ciclano de Tal'
  },
  merchantCity: {
    id: EmvTag.MerchantCity,
    name: 'Merchant City',
    length: 14,
    value: 'RIO DE JANEIRO'
  },
  additionalDataField: {
    id: EmvTag.AdditionalDataField,
    name: 'Additional Data Field',
    length: 19,
    value: '0515RP12345678-2019'
  }
}
const result = await generate(pixcode as PIXCode)
console.log(result.payload())

console.log(result.base64())
00020101021226720014br.gov.bcb.pix2550bx.com.br/pix/8b3da2f3-9a41-40d1-a91a-bd93113bd441520400005303986540599.995802BR5914Ciclano de Tal6014RIO DE JANEIRO62190515RP12345678-201963047A12

data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAOQAAADkCAYAAACIV4iNAAAAAklEQVR4AewaftIAAAxHSURBVO3BQY4cSRLAQDLR//8yV0c/BZCoailm4Wb2B2utKzysta7xsNa6xsNa6xoPa61rPKy1rvGw1rrGw1rrGg9rrWs8rLWu8bDWusbDWusaD2utazysta7xsNa6xsNa6xo/fEjlb6qYVKaKSWWq+E0qJxUnKlPFicpUcaJyUnGiMlVMKt9UcaIyVUwqf1PFJx7WWtd4WGtd42GtdY0fvqzim1TeUJkqTlROKiaVqWKqOFF5Q2WqOFF5o+JE5UTlpOJE5UTlmyq+SeWbHtZa13hYa13jYa11jR9+mcobFZ+oOFGZKiaVSWWq+ETFicpUMalMFZPKGypTxVQxqfymihOVb1J5o+I3Pay1rvGw1rrGw1rrGj/8x1VMKlPFicpUcaJyUnGi8obKicpUMalMFZPKicpvqvhExf+Th7XWNR7WWtd4WGtd44f/OJVPVJyoTBWTyqRyUjGpTBWTyhsqn1A5qZhU3lCZKiaVqWKq+H/2sNa6xsNa6xoPa61r/PDLKn5TxaTyhspUMVV8k8pU8UbFGypvVHyTylQxqZyoTBXfVHGTh7XWNR7WWtd4WGtd44cvU/mbVKaKSWWqmFROVKaKk4pJZaqYVKaKN1Smim9SmSpOKiaVNyomlROVqeJE5WYPa61rPKy1rvGw1rrGDx+q+JcqvkllqphUPqHyTRVvqEwVJxXfpHKiMlWcVJxU/Jc8rLWu8bDWusbDWusaP3xIZao4UfmbKk4qTlSmikllUnmj4g2Vv0nlpGJSmSq+SWWqmFSmihOVqWJSeaPiEw9rrWs8rLWu8bDWusYP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vGw1rrGw1rrGg9rrWs8rLWu8bDWusbDWusaD2utazysta7xsNa6xsNa6xoPa61rPKy1rvGw1rrG/wDld87ghnF8gQAAAABJRU5ErkJggg==

Types and Interfaces:

interface TLV {
    id: string;
    name: string;
    length: number;
    value: string;
    mandatory: boolean;
    description: string;
}

interface PIXCode {
    payloadFormatIndicator: TLV;
    pointOfInitiationMethod: TLV;
    merchantAccountInformation: TLV;
    merchantCategoryCode: TLV;
    transactionCurrency: TLV;
    transactionAmount: TLV;
    countryCode: TLV;
    merchantName: TLV;
    merchantCity: TLV;
    postalCode: TLV;
    additionalDataField: TLV;
    unreservedTemplates: TLV;
    crc: TLV;
}

interface QRCode {
  payload: () => string,
  base64: () => string
}