Generate QR codes and "copia e cola" codes for Brazilian PIX bank transfers

Hello everyone!

My question is mainly directed to Brazilian experts in appsheets (@diogo @diogolupcosta , @mattlops , @jeffcantor and much others… :folded_hands:t3: ) , as they are familiar with this Brazilian form of instant bank transfer using codes and QR Codes called PIX.

However, if other experts of other nationalities in the community know how this method works and can help, I would be very grateful!

I am developing an educational app aimed at Brazilian resident doctors that will serve as a training tool for specialist title exams.

In this app, I would like to generate QR codes and personalized “copy and paste” codes to collect payments from customer using PIX and display them in the app itself for the user. Obviously, the bank details for sending PIX will be mine, but I would also like to obtain some customer identifier through PIX (CPF, for example), as is already traditionally the case in several shopping apps and websites here in Brazil.

This is an example of copy and paste code made in the bank app where I entered the following data: customer name and CPF, billing due date and description of the service provided.

00020101021226990014br.gov.bcb.pix2577qrcode.c6pix.com/qrs2/v2/02pLbAHlBr7uXMKI0L5aXtfmFiLxA7Ttn3I4OdvZHjviF4L16YSw5204000053039865406100.005802BR5925MAURISTON MARTINS ONCOLOG6009SAO PAULO62070503***63049627

And this is the QR code of the code above:

(QR Code Removed by Staff)

I thank you in advance for your attention and generosity in sharing your knowledge.

Hugs from Rio de Janeiro.

2 Likes

Hi there! manda um whatsapp pra mim no 5579999783028

Boa tarde

Amigo consegui fazer o codigo copia e cola depois de quebrar muito a cabeça.

utilizei o script abaixo, gerado no gemini e fiz as alterações para adaptar a minha realidade.

No meu caso identifiquei que o codigo, no caso da Caixa, tinha sete partes que se repetiam

Ai fui decifrando e acabei conseguindo gerar o codigo

Espero que te ajude

 

function gerarCodigoPix(valor, chavePix, descricao) {
// Gerar parte aleatória do código (pode ser ajustado para maior segurança)
const caracteres = ‘ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789’;
let parteAleatoria = ‘’;
for (let i = 0; i < 32; i++) {
parteAleatoria += caracteres.charAt(Math.floor(Math.random() * caracteres.length));
}

// Formatar o código Pix (ajuste o formato conforme a especificação do banco)
const codigoPix = ${valor}-${chavePix}-${descricao}-${parteAleatoria};

return codigoPix;
}

// Exemplo de uso
const valor = “100.00”;
const chavePix = “(PII Removed by Staff)”;
const descricao = “Pagamento de serviço”;

const codigoGerado = gerarCodigoPix(valor, chavePix, descricao);
console.log(codigoGerado);

3 Likes

Olá Marco! Muito obrigado pela ajuda! Você brilhou demais!

Grande abraço!!!

3 Likes

Muito bom Marco, parabens !