Skip to content
moacyrricardoPublic

About

Java library to build brazil's PIX Copy & Paste (PIX copia e cola) (PIX QR CODE estático)

Resources

Stars

1 star

Watchers

1 watching

Forks

Latest commit

 

History

25 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 

Repository files navigation

java-pix

en

Java library to build brazil's PIX Copy & Paste. Useful to build charges.

pt-br

Biblioteca java para construir PIX copia e cola. Útil para criar "cobranças" com dados predefinidos.

usage

Built with java 17

import

<dependency>
    <groupId>com.iskeru</groupId>
    <artifactId>java-pix</artifactId>
    <version>2.0.0</version>
</dependency>

Generated codes follow the BCB BR Code rules for static codes:

  • country (58) defaults to BR; name (59) and city (60) are required, non-ASCII characters are stripped (accents removed), name is capped at 25 and city at 15 characters;
  • the txid (62.05) is optional — when omitted it is sent as ***; when present it must be 1–25 alphanumeric characters (A-Z, a-z, 0-9), otherwise an IllegalArgumentException is thrown;
  • the amount must be positive with at most 2 decimal places, and only BRL is supported.

Ex:

PixCopyAndPaste pix = PixCopyAndPaste.builder()
        .to(PixTarget.builder()
                .chavePix("minha-chave")
                .cidade("SAO PAULO")
                .nome("Person Person")
                .build())
        .transfer(PixTransaction.builder()
                .idTransacao("MEUTXID123")
                .valorTransacao(new BigDecimal("12.34"))
                .build())
        .build();

Atenção (pt-br): o txid é opcional (vai como *** quando ausente), mas se informado deve ter de 1 a 25 caracteres alfanuméricos, sem _, - ou espaços. Nome e cidade são obrigatórios e têm acentos removidos; país assume BR. O valor deve ser positivo, com até 2 casas decimais.

code

Build simple copia e cola.

PIX Key / Chave PIX

PixCopyAndPaste pix = PixCopyAndPaste.builder()
        .to(PixTarget.builder()
                .chavePix("minha-chave")
                .cidade("SAO PAULO")
                .nome("Person Person")
                .build())
        .transfer(PixTransaction.builder().valorTransacao(new BigDecimal("12.34")).build())
        .build();

PIX phone number / telefone

// when key is a phone number, for instance: (11) 98181-1212
PixTarget.builder().chavePix("+5511981811212").build();

PIX E-mail

// when key is a e-mail
PixTarget.builder().chavePix("someone@gmail.com").build();

parse / validate

You can parse and validate a PIX Copy & Paste string generated by this library (or compatible ones).

String payload = "00020126330014BR.GOV.BCB.PIX0111minha-chave520400005303986540512.345802BR5913Person Person6009SAO PAULO62110507myidis16304E3BF";
// a txid of "***" is parsed as null (no txid informed)
PixCopyAndPaste parsed = PixCopyAndPasteParser.parse(payload);

// Access parsed models via getters
PixTarget target = parsed.to();
PixTransaction tx = parsed.transfer();

// A CRC field (63) is validated when present; an invalid CRC throws IllegalArgumentException.
// Payloads without CRC are accepted and parsed as well.

current limitations

  • Only fields used by this project are parsed/validated: 00, 26 (00 GUI, 01 pix key), 52, 53, 54, 58, 59, 60, 62 (05 txid), and 63 (CRC).
  • Unknown/new PIX fields are ignored during parsing.
  • Merchant Account Info GUI is expected to be BR.GOV.BCB.PIX (lowercase br.gov.bcb.pix is also accepted). Other GUIs will be rejected.
  • Amount (54) is required for parsing to succeed.

About

Java library to build brazil's PIX Copy & Paste (PIX copia e cola) (PIX QR CODE estático)

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages