### Install Validapix Package Source: https://github.com/valida-pix/validapix-lib/blob/main/dist/README.md Commands to install the library using common package managers. ```bash npm i validapix ``` ```bash yarn add validapix ``` ```bash pnpm add validapix ``` -------------------------------- ### Generate Basic PIX Code Source: https://context7.com/valida-pix/validapix-lib/llms.txt Configure the singleton emv instance with a PIX key and price to generate a standard EMV code. ```typescript import { emv } from "validapix"; // Configuração básica - apenas com chave PIX (obrigatório) emv.pixKey = "exemplo@exemplo.com"; emv.price = 150.99; const codigoPix = emv.generate(); console.log(codigoPix); // Output: 00020126390014BR.GOV.BCB.PIX0117exemplo@exemplo.com5204000053039865405150.995802BR5900600062070503***6304XXXX ``` -------------------------------- ### Generate Pix EMV String Source: https://github.com/valida-pix/validapix-lib/blob/main/dist/README.md Configure the EMV object with a key and price to generate a Pix 'copia e cola' string. ```typescript import { emv } from "validapix"; emv.pixKey = "exemplo@exemplo.com"; emv.price = 150.99; emv.generate(); // retorna o famoso pix copia e cola (emv) ``` -------------------------------- ### emv.generate() - Generate PIX Code Source: https://context7.com/valida-pix/validapix-lib/llms.txt Generates and returns the PIX copy and paste code (EMV) based on configured properties. Throws an error if the PIX key is not defined. ```APIDOC ## emv.generate() - Gerar Código PIX ### Description This method generates and returns the PIX copy and paste code (EMV) based on the configured properties. It will throw an error if the PIX key (`emv.pixKey`) is not defined. ### Method Call Method ### Endpoint N/A (Library Class Method) ### Parameters N/A ### Request Example ```typescript import { emv } from "validapix"; // Complete example with all properties emv.pixKey = "pagamentos@minhaempresa.com.br"; emv.price = 350.00; emv.name = "Empresa Exemplo LTDA"; emv.city = "Belo Horizonte"; emv.id = "VENDA2024001"; try { const codigoPix = emv.generate(); console.log("Código PIX gerado:", codigoPix); // Use this code to generate a QR Code or share directly } catch (error) { console.error("Erro ao gerar PIX:", error.message); // Output if pixKey is not defined: "The pixKey is required!" } // Minimum example (only required fields) emv.pixKey = "minhachave@email.com"; emv.price = 100; emv.name = ""; emv.city = ""; emv.id = ""; const pixMinimo = emv.generate(); console.log("PIX mínimo:", pixMinimo); ``` ### Response #### Success Response (string) - **Generated PIX Code** (string) - The EMV-formatted PIX copy and paste code. #### Response Example ``` 00020126390014BR.GOV.BCB.PIX0117pagamentos@minhaempresa.com.br5204000053039865405350.005802BR5919Empresa Exemplo LTDA6015Belo Horizonte62070503***6304XXXX ``` ### Error Handling - Throws an error if `pixKey` is not defined. - Example error message: "The pixKey is required!" ``` -------------------------------- ### Generate PIX Code with Error Handling Source: https://context7.com/valida-pix/validapix-lib/llms.txt Use the generate method to create the final string, ensuring the PIX key is set to avoid errors. ```typescript import { emv } from "validapix"; // Exemplo completo com todas as propriedades emv.pixKey = "pagamentos@minhaempresa.com.br"; emv.price = 350.00; emv.name = "Empresa Exemplo LTDA"; emv.city = "Belo Horizonte"; emv.id = "VENDA2024001"; try { const codigoPix = emv.generate(); console.log("Código PIX gerado:", codigoPix); // Use este código para gerar um QR Code ou compartilhar diretamente } catch (error) { console.error("Erro ao gerar PIX:", error.message); // Output se pixKey não definida: "The pixKey is required!" } // Exemplo mínimo (apenas campos obrigatórios) emv.pixKey = "minhachave@email.com"; emv.price = 100; emv.name = ""; emv.city = ""; emv.id = ""; const pixMinimo = emv.generate(); console.log("PIX mínimo:", pixMinimo); ``` -------------------------------- ### Configure PIX Key Source: https://context7.com/valida-pix/validapix-lib/llms.txt Set the recipient's PIX key, which can be an email, CPF, CNPJ, phone number, or random key. ```typescript import { emv } from "validapix"; // Usando e-mail como chave PIX emv.pixKey = "pagamentos@minhaempresa.com.br"; // Usando CPF como chave PIX emv.pixKey = "12345678901"; // Usando telefone como chave PIX emv.pixKey = "+5511999999999"; // Usando chave aleatória emv.pixKey = "a1b2c3d4-e5f6-7890-abcd-ef1234567890"; ``` -------------------------------- ### emv.pixKey - Set PIX Key Source: https://context7.com/valida-pix/validapix-lib/llms.txt Configures the PIX key for the recipient. Supports all valid PIX key types. ```APIDOC ## emv.pixKey - Chave PIX do Recebedor ### Description Defines the PIX key of the transaction recipient. Accepts any valid PIX key type: email, CPF, CNPJ, phone, or random key. This property is mandatory for generating the code. ### Method Set Property ### Endpoint N/A (Library Class) ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example ```typescript import { emv } from "validapix"; // Using email as PIX key emv.pixKey = "pagamentos@minhaempresa.com.br"; // Using CPF as PIX key emv.pixKey = "12345678901"; // Using phone as PIX key emv.pixKey = "+5511999999999"; // Using random key emv.pixKey = "a1b2c3d4-e5f6-7890-abcd-ef1234567890"; ``` ### Response N/A (Property Setter) ``` -------------------------------- ### ValidaPix EMV Generator API Source: https://context7.com/valida-pix/validapix-lib/llms.txt The `emv` object is a singleton instance of the `Emv` class used to configure and generate PIX codes. Properties can be set before calling the `generate()` method. ```APIDOC ## ValidaPix EMV Generator API ### Description The `emv` object is a singleton instance of the `Emv` class that allows configuration of all necessary parameters for generating a PIX copy and paste code. Properties can be configured individually before calling the `generate()` method. ### Method N/A (Instance Configuration) ### Endpoint N/A (Library Class) ### Parameters #### Instance Properties - **pixKey** (string) - Required - The PIX key of the recipient (e.g., email, CPF, CNPJ, phone, random key). - **price** (number) - Required - The monetary value of the PIX transaction in BRL. Accepts decimal or integer values. - **name** (string) - Optional - The name of the recipient. Text is automatically normalized. - **city** (string) - Optional - The city of the recipient. Text is automatically normalized. - **id** (string) - Optional - A unique identifier for the transaction. Defaults to "***" if not set. ### Request Example ```typescript import { emv } from "validapix"; // Basic configuration emv.pixKey = "exemplo@exemplo.com"; emv.price = 150.99; const codigoPix = emv.generate(); console.log(codigoPix); ``` ### Response #### Success Response (string) - **Generated PIX Code** (string) - The EMV-formatted PIX copy and paste code. #### Response Example ``` 00020126390014BR.GOV.BCB.PIX0117exemplo@exemplo.com5204000053039865405150.995802BR5900600062070503***6304XXXX ``` ### Error Handling - Throws an error if `pixKey` is not defined. - Example error message: "The pixKey is required!" ``` -------------------------------- ### emv.name - Set Recipient Name Source: https://context7.com/valida-pix/validapix-lib/llms.txt Sets the recipient's name for the transaction. Text is automatically normalized. ```APIDOC ## emv.name - Nome do Recebedor ### Description Defines the recipient's name that will appear in the transaction. The text is automatically normalized, removing accents and special characters to ensure compatibility. ### Method Set Property ### Endpoint N/A (Library Class) ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example ```typescript import { emv } from "validapix"; emv.pixKey = "contato@empresa.com"; emv.price = 250.00; emv.name = "João da Silva Comércio"; // Will be converted to "Joao da Silva Comercio" const codigoPix = emv.generate(); ``` ### Response N/A (Property Setter) ``` -------------------------------- ### emv.city - Set Recipient City Source: https://context7.com/valida-pix/validapix-lib/llms.txt Sets the recipient's city for the transaction. Text is automatically normalized. ```APIDOC ## emv.city - Cidade do Recebedor ### Description Defines the recipient's city for the transaction. Like the name, the text is automatically normalized. ### Method Set Property ### Endpoint N/A (Library Class) ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example ```typescript import { emv } from "validapix"; emv.pixKey = "vendas@loja.com"; emv.price = 75.50; emv.name = "Loja Virtual"; emv.city = "São Paulo"; // Will be converted to "Sao Paulo" const codigoPix = emv.generate(); ``` ### Response N/A (Property Setter) ``` -------------------------------- ### Set Transaction Price Source: https://context7.com/valida-pix/validapix-lib/llms.txt Define the transaction value in BRL. The library automatically formats integers and decimal numbers. ```typescript import { emv } from "validapix"; emv.pixKey = "loja@exemplo.com"; // Valor com centavos emv.price = 99.90; const pix1 = emv.generate(); // Valor inteiro emv.price = 50; const pix2 = emv.generate(); // Valor alto emv.price = 1500.00; const pix3 = emv.generate(); ``` -------------------------------- ### emv.price - Set Transaction Value Source: https://context7.com/valida-pix/validapix-lib/llms.txt Sets the monetary value for the PIX transaction. Handles automatic formatting for decimal and integer values. ```APIDOC ## emv.price - Valor da Transação ### Description Defines the monetary value of the PIX transaction in BRL. Accepts numbers with decimal places or integer values, which will be automatically formatted. ### Method Set Property ### Endpoint N/A (Library Class) ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example ```typescript import { emv } from "validapix"; emv.pixKey = "loja@exemplo.com"; // Value with cents emv.price = 99.90; const pix1 = emv.generate(); // Integer value emv.price = 50; const pix2 = emv.generate(); // High value emv.price = 1500.00; const pix3 = emv.generate(); ``` ### Response N/A (Property Setter) ``` -------------------------------- ### Set Transaction Identifier Source: https://context7.com/valida-pix/validapix-lib/llms.txt Assign a unique ID for payment tracking. Defaults to '***' if not provided. ```typescript import { emv } from "validapix"; emv.pixKey = "financeiro@empresa.com"; emv.price = 199.99; emv.name = "Minha Empresa LTDA"; emv.city = "Rio de Janeiro"; emv.id = "PEDIDO12345"; const codigoPix = emv.generate(); console.log(codigoPix); ``` -------------------------------- ### Set Recipient City Source: https://context7.com/valida-pix/validapix-lib/llms.txt Define the recipient's city, which undergoes automatic text normalization. ```typescript import { emv } from "validapix"; emv.pixKey = "vendas@loja.com"; emv.price = 75.50; emv.name = "Loja Virtual"; emv.city = "São Paulo"; // Será convertido para "Sao Paulo" const codigoPix = emv.generate(); ``` -------------------------------- ### emv.id - Set Transaction Identifier Source: https://context7.com/valida-pix/validapix-lib/llms.txt Sets a unique identifier for the transaction, useful for tracking and reconciliation. ```APIDOC ## emv.id - Identificador da Transação ### Description Defines a unique identifier for the transaction, useful for tracking and reconciliation of payments. If not defined, the default value "***" is used. ### Method Set Property ### Endpoint N/A (Library Class) ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example ```typescript import { emv } from "validapix"; emv.pixKey = "financeiro@empresa.com"; emv.price = 199.99; emv.name = "Minha Empresa LTDA"; emv.city = "Rio de Janeiro"; emv.id = "PEDIDO12345"; const codigoPix = emv.generate(); console.log(codigoPix); ``` ### Response N/A (Property Setter) ``` -------------------------------- ### Set Recipient Name Source: https://context7.com/valida-pix/validapix-lib/llms.txt Assign a recipient name that will be automatically normalized by removing accents and special characters. ```typescript import { emv } from "validapix"; emv.pixKey = "contato@empresa.com"; emv.price = 250.00; emv.name = "João da Silva Comércio"; // Será convertido para "Joao da Silva Comercio" const codigoPix = emv.generate(); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.