Java library to build brazil's PIX Copy & Paste. Useful to build charges.
Biblioteca java para construir PIX copia e cola. Útil para criar "cobranças" com dados predefinidos.
Built with java 17
<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 anIllegalArgumentExceptionis 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.
Build simple copia e cola.
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();// when key is a phone number, for instance: (11) 98181-1212
PixTarget.builder().chavePix("+5511981811212").build();// when key is a e-mail
PixTarget.builder().chavePix("someone@gmail.com").build();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.- 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(lowercasebr.gov.bcb.pixis also accepted). Other GUIs will be rejected. - Amount (54) is required for parsing to succeed.