Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

pix-utils

thalesog14.7kMIT2.8.1TypeScript support: included

Set of tools to parse, generate and validate payments of Brazil Instant Payment System (Pix)

pix, bacen, pix-utils, utils, emv, emvqr, qrcode

readme

pix-utils

Pix-Utils

License Stars
Version Build Status

Pix-Utils is a set of tools to parse, generate and validate payments of Brazil Instant Payment System (Pix), making fast and simple to handle charges and proccess then in your project.

🚀 Usage

Install the package in your project

yarn add pix-utils

Create Static Pix

import { createStaticPix, hasError } from 'pix-utils';

const pix = createStaticPix({
  merchantName: 'Thales Ogliari',
  merchantCity: 'Sao Paulo',
  pixKey: 'nubank@thalesog.com',
  infoAdicional: 'Gerado por Pix-Utils',
  transactionAmount: 1,
});

if (!hasError(pix)) {
  const brCode = pix.toBRCode();
  // 00020126650014br.gov.bcb.pix0119nubank@thalesog.com0220Gerado por Pix-Utils52040000530398654041.005802BR5914Thales Ogliari6009Sao Paulo62070503***63046069
}

Create Dynamic Pix

import { createDynamicPix, hasError } from 'pix-utils';

const pix = createDynamicPix({
  merchantName: 'Thales Ogliari',
  merchantCity: 'Sao Paulo',
  url: 'https://pix.thalesogliari.com.br',
});

if (!hasError(pix)) {
  const brCode = pix.toBRCode();
  // 00020126540014br.gov.bcb.pix2532https://pix.thalesogliari.com.br5204000053039865802BR5914Thales Ogliari6009SAO PAULO62070503***63043FD3
}

Throw errors

By default, pix-utils wont throw an error when parsing an invalid pix, but you can enable it by using the throwIfError function.

import { createDynamicPix } from 'pix-utils';

const pix = createDynamicPix({
  merchantName: 'Thales Ogliari',
  merchantCity: 'Sao Paulo',
  url: 'https://pix.thalesogliari.com.br',
}).throwIfError();

const brCode = pix.toBRCode();
// 00020126540014br.gov.bcb.pix2532https://pix.thalesogliari.com.br5204000053039865802BR5914Thales Ogliari6009SAO PAULO62070503***63043FD3

Parse BRCode

const pix = parsePix(
  '00020126650014br.gov.bcb.pix0119nubank@thalesog.com0220Gerado por Pix-Utils52040000530398654041.005802BR5914Thales Ogliari6015SAO MIGUEL DO O62070503***6304059A'
);

// {
//   type: 'STATIC',
//   merchantCategoryCode: '0000',
//   transactionCurrency: '986',
//   countryCode: 'BR',
//   merchantName: 'Thales Ogliari',
//   merchantCity: 'SAO MIGUEL DO O',
//   pixKey: 'nubank@thalesog.com',
//   transactionAmount: 1,
//   infoAdicional: 'Gerado por Pix-Utils',
//   txid: '***',
//   toBRCode: [Function: toBRCode],
//   toImage: [Function: toImage]
// }

Export to Base64 Image

const pix = parsePix(
  '00020126650014br.gov.bcb.pix0119nubank@thalesog.com0220Gerado por Pix-Utils52040000530398654041.005802BR5914Thales Ogliari6015SAO MIGUEL DO O62070503***6304059A'
);

pix.toImage();
// data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAOQAAADkCAYAAACIV4iNAAAAAklEQVR4AewaftIAAAwHSURBVO3BQW4sy7LgQDKh/W...

🍰 Contributing

Please contribute using GitHub Flow. Create a branch, add commits, and open a pull request.

📝 License

This project is under MIT license.

#

Developed with 💚 by @thalesog 🇧🇷

changelog

2.8.1 (2025-05-30)

Bug Fixes

  • export pixDynamicPayload types and update PIXRecPayload structure (#36) (8316595)

2.8.0 (2025-05-28)

Features

  • rename composite functionality to recurrence (#35) (5ebee6a)

2.7.1 (2025-05-23)

Bug Fixes

  • add new enums and types for Pix payload structure (#34) (081e586)

2.7.0 (2025-05-22)

Bug Fixes

  • ci: correct test workflow file extension (#33) (68bc907)

Features

  • add funcionality for composite emv (#32) (94d9587)

2.6.0 (2024-08-19)

Features

  • expose oneTime option to add the Point of Initiation Method tag to the EMV (#25) (b1d3db5)

2.5.0 (2023-01-06)

Features

  • added fss field for generating and parsing brCodes (#21) (55216e2)

2.4.2 (2022-11-29)

Bug Fixes

2.4.1 (2022-11-20)

Bug Fixes

  • remove amount tag on no amount emv (#19) (f90f98a)

2.4.0 (2022-10-11)

Features

2.3.3 (2022-08-28)

Bug Fixes

2.3.2 (2022-08-28)

Bug Fixes

  • undefined throwIfError when object is ok (#7) (1470770)

2.3.1 (2022-08-28)

Bug Fixes

2.3.0 (2022-08-28)

Features

Changelog

All notable changes to this project will be documented in this file. See standard-version for commit guidelines.

2.1.0 (2021-09-27)

Features

  • error type rewriten, pix type enum (b70ab11)
  • pix creation, some refactoring and directory organization (c3957ea)
  • pix to base64 image and dynamic payload fetch (24746bc)

Bug Fixes

  • fix missing HTMLCanvasElement (0ac4854)
  • static pixKey and dynamic url parameters emv id (657a087)