### Configure Example Credentials Source: https://github.com/efipay/sdk-node-apis-efi/blob/master/README.md Set up your credentials in the `credentials.js` file within the examples directory. This file is used by the example scripts. ```javascript module.exports = { // PRODUÇÃO = false // HOMOLOGAÇÃO = true sandbox: false, client_id: 'seuClientId', client_secret: 'seuClientSecret', certificate: 'caminhoAteOCertificadoPix', cert_base64: false, // Indica se o certificado está em base64 ou não } ``` -------------------------------- ### Clone Repository and Install Dependencies Source: https://github.com/efipay/sdk-node-apis-efi/blob/master/README.md Clone the SDK repository and install its dependencies to run the provided examples. ```bash $ git clone git@github.com:efipay/sdk-node-apis-efi.git $ cd sdk-node-apis-efi/examples $ npm install ``` -------------------------------- ### Run Example Script Source: https://github.com/efipay/sdk-node-apis-efi/blob/master/README.md Execute a specific example script, such as `createCharge.js`, after setting up your credentials. ```bash $ node createCharge.js ``` -------------------------------- ### Install Efí Pay Node.js SDK Source: https://github.com/efipay/sdk-node-apis-efi/blob/master/README.md Install the SDK using npm. This is the first step to integrate Efí Pay services into your Node.js application. ```bash npm install sdk-node-apis-efi ``` -------------------------------- ### Create Carnet (Payment Booklet) Source: https://context7.com/efipay/sdk-node-apis-efi/llms.txt Creates a payment booklet with multiple installments using bank slips. ```APIDOC ## POST /carnes ### Description Creates a payment booklet with multiple installments using bank slips. ### Method POST ### Endpoint /carnes ### Parameters #### Request Body - **items** (array) - Required - Array of items included in the carnet. - **name** (string) - Required - Name of the item. - **value** (number) - Required - Value of the item in cents. - **amount** (number) - Required - Quantity of the item. - **customer** (object) - Required - Customer information. - **name** (string) - Required - Customer's full name. - **cpf** (string) - Required - Customer's CPF. - **email** (string) - Required - Customer's email address. - **phone_number** (string) - Required - Customer's phone number. - **expire_at** (string) - Required - The due date of the first installment (YYYY-MM-DD). - **repeats** (number) - Required - The number of installments. - **split_items** (boolean) - Required - Whether to split items across installments. - **metadata** (object) - Optional - Custom metadata. - **custom_id** (string) - A custom identifier for the carnet. - **notification_url** (string) - URL for webhook notifications. - **configurations** (object) - Optional - Payment configurations. - **fine** (number) - The fine percentage (e.g., 200 for 2%). - **interest** (object) - Interest configuration. - **value** (number) - The interest rate value. - **type** (string) - The type of interest ('daily' or 'monthly'). ### Request Example ```json { "items": [ { "name": "Pacote de Serviços", "value": 100000, "amount": 1 } ], "customer": { "name": "João Silva", "cpf": "94271564656", "email": "joao@email.com", "phone_number": "31999998888" }, "expire_at": "2024-02-15", "repeats": 12, "split_items": false, "metadata": { "custom_id": "CARNE-001", "notification_url": "https://seu-site.com/webhook" }, "configurations": { "fine": 200, "interest": { "value": 33, "type": "daily" } } } ``` ### Response #### Success Response (200) - **data** (object) - **carnet_id** (string) - The ID of the created carnet. - **link** (string) - The link to the payment booklet. - **pdf** (object) - **carnet** (string) - URL to the carnet PDF. - **charges** (array) - Array of charges (installments). - **parcel** (number) - The installment number. - **barcode** (string) - The barcode for the installment. #### Response Example ```json { "data": { "carnet_id": "carnet-12345", "link": "https://example.com/pay/carnet/12345", "pdf": { "carnet": "https://example.com/pdf/carnet-12345.pdf" }, "charges": [ { "parcel": 1, "barcode": "barcode1" }, { "parcel": 2, "barcode": "barcode2" } ] } } ``` ``` -------------------------------- ### Initiate Pix Payment via Open Finance Source: https://context7.com/efipay/sdk-node-apis-efi/llms.txt Starts a Pix payment through Open Finance, allowing debit from any financial institution. Requires payer and payee details, along with payment value and identifiers. ```javascript const EfiPay = require('sdk-node-apis-efi') const options = require('./credentials') const body = { pagador: { idParticipante: 'identificador-instituicao', // ID da instituição do pagador cpf: '12345678900', }, favorecido: { contaBanco: { codigoBanco: '364', // código do banco Efí agencia: '0001', documento: '12345678000195', nome: 'Sua Empresa LTDA', tipoConta: 'CACC', // conta corrente }, }, detalhes: { valor: '150.00', idProprio: 'PEDIDO-123', infoPagador: 'Pagamento do pedido #123', }, } const efipay = new EfiPay(options) efipay.ofStartPixPayment({}, body) .then((resposta) => { console.log('Pagamento iniciado!') console.log('ID Pagamento:', resposta.identificadorPagamento) console.log('Redirect URI:', resposta.redirectURI) // Redirecione o usuário para redirectURI para autorizar o pagamento }) .catch((error) => { console.log('Erro:', error) }) ``` -------------------------------- ### List Card Installments Source: https://context7.com/efipay/sdk-node-apis-efi/llms.txt Queries available installment options for a given amount and card brand. Useful for displaying payment options to users. ```javascript const EfiPay = require('sdk-node-apis-efi') const options = require('./credentials') const params = { total: 100000, // R$ 1.000,00 brand: 'visa', // visa, mastercard, amex, elo, hipercard } const efipay = new EfiPay(options) efipay.getInstallments(params) .then((resposta) => { console.log('Taxa:', resposta.data.rate, '%') console.log('Bandeira:', resposta.data.name) resposta.data.installments.forEach((parcela) => { const juros = parcela.has_interest ? `(${parcela.interest_percentage}% juros)` : '(sem juros)' console.log(`${parcela.installment}x de ${parcela.currency} ${juros}`) }) }) .catch((error) => { console.log('Erro:', error) }) ``` -------------------------------- ### Generate Financial Reconciliation Report Source: https://context7.com/efipay/sdk-node-apis-efi/llms.txt Request and download a statement report for financial reconciliation. This example shows how to request the report, wait for processing, and then save the CSV data. ```javascript const EfiPay = require('sdk-node-apis-efi') const options = require('./credentials') const body = { dataMovimento: '2024-01-15', tipoRegistros: { pixRecebido: true, pixEnviadoChave: true, pixDevolucaoEnviada: true, pixDevolucaoRecebida: true, saldoDiaAnterior: true, saldoDia: true, }, } const efipay = new EfiPay(options) efipay.createReport({}, body) .then((resposta) => { console.log('Relatório solicitado!') console.log('ID:', resposta.id) console.log('Status:', resposta.status) // Aguardar processamento e baixar setTimeout(() => { efipay.detailReport({ id: resposta.id }) .then((resultado) => { if (typeof resultado === 'string') { // CSV pronto const fs = require('fs') fs.writeFileSync('extrato.csv', resultado) console.log('Extrato salvo em extrato.csv') } else { console.log('Processando:', resultado.status) } }) }, 5000) }) .catch((error) => { console.log('Erro:', error) }) ``` -------------------------------- ### Create Payment Carnet Source: https://context7.com/efipay/sdk-node-apis-efi/llms.txt Generates a payment carnets (installments) using bank slips. Configure items, customer details, and payment terms like expiration and interest rates. ```javascript const EfiPay = require('sdk-node-apis-efi') const options = require('./credentials') const body = { items: [ { name: 'Pacote de Serviços', value: 100000, // R$ 1.000,00 amount: 1, }, ], customer: { name: 'João Silva', cpf: '94271564656', email: 'joao@email.com', phone_number: '31999998888', }, expire_at: '2024-02-15', // data do primeiro vencimento repeats: 12, // número de parcelas split_items: false, metadata: { custom_id: 'CARNE-001', notification_url: 'https://seu-site.com/webhook', }, configurations: { fine: 200, // multa de 2% interest: { value: 33, // juros de 0,33% ao dia (1% ao mês) type: 'daily', }, }, } const efipay = new EfiPay(options) efipay.createCarnet({}, body) .then((resposta) => { console.log('Carnê criado:', resposta.data.carnet_id) console.log('Link do carnê:', resposta.data.link) console.log('PDF:', resposta.data.pdf.carnet) resposta.data.charges.forEach((parcela) => { console.log(`Parcela ${parcela.parcel}: ${parcela.barcode}`) }) }) .catch((error) => { console.log('Erro:', error) }) ``` -------------------------------- ### GET /pix/qr-code/{id} Source: https://context7.com/efipay/sdk-node-apis-efi/llms.txt Generates a Pix QR code image from the location ID of a Pix charge. ```APIDOC ## GET /pix/qr-code/{id} ### Description Generates the QR Code image from the location ID of a Pix charge. ### Method GET ### Endpoint /pix/qr-code/{id} ### Parameters #### Path Parameters - **id** (integer) - Required - The location ID returned when creating the charge. ### Response #### Success Response (200) - **qrcode** (string) - The QR code as plain text. - **imagemQrcode** (string) - The QR code image in base64 format (PNG). - **linkVisualizacao** (string) - A URL to view the QR code. #### Response Example ```json { "qrcode": "00020126580014br.gov.bcb.pix0114sua-chave-pix@efipay.com.br520400005303***...", "imagemQrcode": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGQAAABkCAYAAAB+f35AAAAAAElFTkSuQmCC", "linkVisualizacao": "https://api.efipay.com.br/pix/v2/charges/12345/qrcode" } ``` ``` -------------------------------- ### Generate Pix QR Code Source: https://context7.com/efipay/sdk-node-apis-efi/llms.txt Generates a Pix QR code image (both text and base64 encoded) from a Pix charge's location ID. Includes an example of how to save the base64 image to a file. ```javascript const EfiPay = require('sdk-node-apis-efi') const options = require('./credentials') const params = { id: 12345, // ID do location retornado na criação da cobrança } const efipay = new EfiPay(options) efipay.pixGenerateQRCode(params) .then((resposta) => { console.log('QR Code (texto):', resposta.qrcode) console.log('QR Code (imagem base64):', resposta.imagemQrcode) console.log('Link visualização:', resposta.linkVisualizacao) // Para salvar a imagem const fs = require('fs') const base64Data = resposta.imagemQrcode.replace(/^data:image\/png;base64,/, '') fs.writeFileSync('qrcode.png', base64Data, 'base64') }) .catch((error) => { console.log('Erro:', error) }) ``` -------------------------------- ### Create Subscription with Bank Slip Source: https://context7.com/efipay/sdk-node-apis-efi/llms.txt Use this to create a subscription linked to a plan with payment via bank slip. Ensure the 'credentials' file is correctly configured. ```javascript const EfiPay = require('sdk-node-apis-efi') const options = require('./credentials') const params = { id: 1000, // ID do plano } const body = { items: [ { name: 'Assinatura Premium', value: 9990, // R$ 99,90 amount: 1, }, ], payment: { banking_billet: { expire_at: '2024-02-15', customer: { name: 'Maria Souza', cpf: '12345678900', email: 'maria@email.com', phone_number: '11988887777', }, configurations: { fine: 200, interest: { value: 33, type: 'daily', }, }, }, }, metadata: { notification_url: 'https://seu-site.com/webhook', }, } const efipay = new EfiPay(options) efipay.createOneStepSubscription(params, body) .then((resposta) => { console.log('Assinatura criada:', resposta.data.subscription_id) console.log('Status:', resposta.data.status) console.log('Próxima cobrança:', resposta.data.first_execution) console.log('Código de barras:', resposta.data.barcode) }) .catch((error) => { console.log('Erro:', error) }) ``` -------------------------------- ### Criar Cobrança com Boleto (One Step) - SDK Node.js Source: https://context7.com/efipay/sdk-node-apis-efi/llms.txt Gera uma cobrança completa com boleto bancário em uma única requisição. Inclui dados do cliente e detalhes do pagamento. A resposta contém o ID da cobrança, código de barras, link de pagamento e PDF. ```javascript const EfiPay = require('sdk-node-apis-efi') const options = require('./credentials') const body = { payment: { banking_billet: { expire_at: '2024-12-20', customer: { name: 'Gorbadoc Oldbuck', email: 'cliente@email.com.br', cpf: '94271564656', birth: '1977-01-15', phone_number: '5144916523', }, }, }, items: [ { name: 'Produto 1', value: 500, // valor em centavos (R$ 5,00) amount: 1, }, ], shippings: [ { name: 'Frete', value: 100, // R$ 1,00 }, ], } const efipay = new EfiPay(options) efipay.createOneStepCharge([], body) .then((resposta) => { console.log('Cobrança criada:', resposta) // Resposta inclui: charge_id, barcode, link, pdf, pix (qrcode) }) .catch((error) => { console.log('Erro:', error.code, error.error_description) }) ``` -------------------------------- ### Instalar e Configurar SDK Node.js Efí Pay Source: https://context7.com/efipay/sdk-node-apis-efi/llms.txt Instala o SDK via npm e configura as credenciais para autenticação em produção ou homologação. Certificados são necessários para operações Pix. ```javascript // Instalação via npm // $ npm install sdk-node-apis-efi // Importação do módulo const EfiPay = require('sdk-node-apis-efi') // ou usando ES Modules import EfiPay from 'sdk-node-apis-efi' // Configuração das credenciais const options = { // PRODUÇÃO = false // HOMOLOGAÇÃO = true sandbox: false, client_id: 'seu_client_id', client_secret: 'seu_client_secret', certificate: 'caminho/ate/seu/certificado.p12', // Certificado para Pix cert_base64: false, // true se o certificado estiver em base64 } // Instanciando o cliente const efipay = new EfiPay(options) ``` -------------------------------- ### Instantiate Efí Pay SDK Source: https://github.com/efipay/sdk-node-apis-efi/blob/master/README.md Instantiate the EfiPay module with your configuration options. This object will be used to interact with Efí Pay APIs. ```javascript const efipay = new EfiPay(options) ``` -------------------------------- ### POST /pix/immediate Source: https://context7.com/efipay/sdk-node-apis-efi/llms.txt Creates an immediate Pix charge without a predefined TXID, returning a QR code and a copy-paste code. ```APIDOC ## POST /pix/immediate ### Description Creates an immediate Pix charge without a predefined TXID, returning a QR code and a copy-paste code. ### Method POST ### Endpoint /pix/immediate ### Request Body - **calendario** (object) - Required - Contains charge calendar information. - **expiracao** (integer) - Required - Expiration time in seconds. - **devedor** (object) - Required - Debtor information. - **cpf** (string) - Required - Debtor's CPF. - **nome** (string) - Required - Debtor's full name. - **valor** (object) - Required - Payment amount. - **original** (string) - Required - The original amount in BRL. - **chave** (string) - Required - The registered Pix key. - **infoAdicionais** (array) - Optional - Additional information. - **nome** (string) - Required - Name of the additional info. - **valor** (string) - Required - Value of the additional info. ### Request Example ```json { "calendario": { "expiracao": 3600 }, "devedor": { "cpf": "94271564656", "nome": "Gorbadock Oldbuck" }, "valor": { "original": "123.45" }, "chave": "sua-chave-pix@efipay.com.br", "infoAdicionais": [ { "nome": "Pagamento em", "valor": "Loja Virtual XYZ" }, { "nome": "Pedido", "valor": "#12345" } ] } ``` ### Response #### Success Response (200) - **txid** (string) - Transaction ID. - **status** (string) - Charge status. - **pixCopiaECola** (string) - Pix copy-paste code. - **location** (string) - Location URL for the charge. #### Response Example ```json { "txid": "some_txid", "status": "CONCLUIDA", "pixCopiaECola": "00020126580014br.gov.bcb.pix0114sua-chave-pix@efipay.com.br520400005303***...", "location": "https://api.efipay.com.br/pix/v2/charges/some_location_id" } ``` ``` -------------------------------- ### List Configured Webhooks Source: https://context7.com/efipay/sdk-node-apis-efi/llms.txt Lists all configured Pix webhooks within a specified date range. ```APIDOC ## GET /pix/webhooks ### Description Lists all configured Pix webhooks within a specified date range. ### Method GET ### Endpoint /pix/webhooks ### Parameters #### Query Parameters - **inicio** (string) - Required - The start date and time for the query (ISO 8601 format). - **fim** (string) - Required - The end date and time for the query (ISO 8601 format). ### Response #### Success Response (200) - **webhooks** (array) - An array of webhook objects. - **chave** (string) - The Pix key associated with the webhook. - **webhookUrl** (string) - The configured webhook URL. #### Response Example ```json { "webhooks": [ { "chave": "sua-chave-pix", "webhookUrl": "https://seu-dominio.com.br/webhook/pix" } ] } ``` ``` -------------------------------- ### Configure Efí Pay SDK Credentials Source: https://github.com/efipay/sdk-node-apis-efi/blob/master/README.md Configure your API credentials and sandbox mode. Ensure the certificate path is correct for production or sandbox environments. ```javascript module.exports = { // PRODUÇÃO = false // HOMOLOGAÇÃO = true sandbox: false, client_id: 'seuClientId', client_secret: 'seuClientSecret', certificate: 'caminho/Ate/O/Certificado/Pix', cert_base64: false, // Indica se o certificado está em base64 ou não } ``` -------------------------------- ### Create Subscription Plan Source: https://context7.com/efipay/sdk-node-apis-efi/llms.txt Sets up a plan for recurring charges, commonly used for subscriptions. Define the interval between charges and the total number of repetitions. ```javascript const EfiPay = require('sdk-node-apis-efi') const options = require('./credentials') const body = { name: 'Plano Premium Mensal', interval: 1, // cobrança a cada 1 mês repeats: 12, // 12 cobranças (null para ilimitado) } const efipay = new EfiPay(options) efipay.createPlan({}, body) .then((resposta) => { console.log('Plano criado!') console.log('Plan ID:', resposta.data.plan_id) console.log('Nome:', resposta.data.name) console.log('Intervalo:', resposta.data.interval, 'mês(es)') }) .catch((error) => { console.log('Erro:', error) }) ``` -------------------------------- ### Create and Manage Pix Keys (EVP) Source: https://context7.com/efipay/sdk-node-apis-efi/llms.txt Creates, lists, and deletes random Pix keys (EVP) from the account. ```APIDOC ## POST /pix/evp ### Description Creates a new random Pix key (EVP). ### Method POST ### Endpoint /pix/evp ### Response #### Success Response (200) - **chave** (string) - The newly created random Pix key. #### Response Example ```json { "chave": "random-pix-key-example" } ``` ``` ```APIDOC ## GET /pix/evp ### Description Lists all registered random Pix keys (EVP). ### Method GET ### Endpoint /pix/evp ### Response #### Success Response (200) - **chaves** (array) - An array of registered Pix keys. #### Response Example ```json { "chaves": ["key1", "key2"] } ``` ``` ```APIDOC ## DELETE /pix/evp ### Description Deletes a specific random Pix key (EVP). ### Method DELETE ### Endpoint /pix/evp ### Parameters #### Query Parameters - **chave** (string) - Required - The Pix key to be removed. ### Response #### Success Response (200) - (No specific response body mentioned, typically indicates success) #### Response Example (Success is indicated by a 200 status code without an error payload.) ``` -------------------------------- ### Create and Manage Pix Keys (EVP) Source: https://context7.com/efipay/sdk-node-apis-efi/llms.txt Handles the creation, listing, and deletion of random Pix keys (EVP) for your account. Use the `pixDeleteEvp` function with the specific key to remove it. ```javascript const EfiPay = require('sdk-node-apis-efi') const options = require('./credentials') const efipay = new EfiPay(options) // Criar nova chave aleatória efipay.pixCreateEvp() .then((resposta) => { console.log('Nova chave criada:', resposta.chave) }) .catch((error) => { console.log('Erro:', error) }) ``` ```javascript // Listar todas as chaves efipay.pixListEvp() .then((resposta) => { console.log('Chaves cadastradas:', resposta.chaves) }) ``` ```javascript // Excluir chave efipay.pixDeleteEvp({ chave: 'chave-a-ser-removida' }) .then(() => { console.log('Chave removida com sucesso') }) ``` -------------------------------- ### Create Subscription Plan Source: https://context7.com/efipay/sdk-node-apis-efi/llms.txt Creates a plan for recurring charges (subscriptions). ```APIDOC ## POST /plans ### Description Creates a plan for recurring charges (subscriptions). ### Method POST ### Endpoint /plans ### Parameters #### Request Body - **name** (string) - Required - The name of the plan. - **interval** (number) - Required - The interval between charges in months. - **repeats** (number) - Optional - The total number of charges (null for unlimited). ### Request Example ```json { "name": "Plano Premium Mensal", "interval": 1, "repeats": 12 } ``` ### Response #### Success Response (200) - **data** (object) - **plan_id** (string) - The ID of the created plan. - **name** (string) - The name of the plan. - **interval** (number) - The interval between charges in months. #### Response Example ```json { "data": { "plan_id": "plan-abcde", "name": "Plano Premium Mensal", "interval": 1 } } ``` ``` -------------------------------- ### Create Immediate Pix Charge Source: https://context7.com/efipay/sdk-node-apis-efi/llms.txt Use this to create an immediate Pix charge without a predefined TXID. It returns a QR code and a copy-paste code. Ensure your Pix key is registered. ```javascript const EfiPay = require('sdk-node-apis-efi') const options = require('./credentials') const body = { calendario: { expiracao: 3600, // tempo em segundos (1 hora) }, devedor: { cpf: '94271564656', nome: 'Gorbadock Oldbuck', }, valor: { original: '123.45', // valor em reais }, chave: 'sua-chave-pix@efipay.com.br', // chave Pix cadastrada infoAdicionais: [ { nome: 'Pagamento em', valor: 'Loja Virtual XYZ', }, { nome: 'Pedido', valor: '#12345', }, ], } const efipay = new EfiPay(options) efipay.pixCreateImmediateCharge({}, body) .then((resposta) => { console.log('TXID:', resposta.txid) console.log('Status:', resposta.status) console.log('Pix Copia e Cola:', resposta.pixCopiaECola) console.log('Location:', resposta.location) }) .catch((error) => { console.log('Erro:', error.nome, error.mensagem) }) ``` -------------------------------- ### Configure Pix Webhook Source: https://context7.com/efipay/sdk-node-apis-efi/llms.txt Sets up a callback URL to receive Pix payment notifications. Ensure your domain is correctly configured to receive these notifications. ```javascript const EfiPay = require('sdk-node-apis-efi') const options = require('./credentials') const params = { chave: 'sua-chave-pix', } const body = { webhookUrl: 'https://seu-dominio.com.br/webhook/pix', } const efipay = new EfiPay(options) efipay.pixConfigWebhook(params, body) .then((resposta) => { console.log('Webhook configurado:', resposta.webhookUrl) }) .catch((error) => { console.log('Erro:', error) }) ``` ```javascript // Listar webhooks configurados efipay.pixListWebhook({ inicio: '2024-01-01T00:00:00Z', fim: '2024-12-31T23:59:59Z' }) .then((resposta) => { resposta.webhooks.forEach((wh) => { console.log(`Chave: ${wh.chave} | URL: ${wh.webhookUrl}`) }) }) ``` -------------------------------- ### Criar Cobrança com Cartão de Crédito - SDK Node.js Source: https://context7.com/efipay/sdk-node-apis-efi/llms.txt Processa pagamentos com cartão de crédito usando um token gerado no frontend. A resposta indica o status da transação ('approved', 'waiting', 'unpaid'), o ID da cobrança e as parcelas. ```javascript const EfiPay = require('sdk-node-apis-efi') const options = require('./credentials') const body = { payment: { credit_card: { installments: 1, // número de parcelas payment_token: '83d52dbd590d9ebc991938c711ddd31f65df89a5', // token gerado no frontend billing_address: { street: 'Rua Principal', number: '100', neighborhood: 'Centro', zipcode: '35400000', city: 'Ouro Preto', state: 'MG', }, customer: { name: 'Gorbadoc Oldbuck', email: 'cliente@email.com.br', cpf: '94271564656', birth: '1977-01-15', phone_number: '5144916523', }, }, }, items: [ { name: 'Produto Premium', value: 10000, // R$ 100,00 amount: 2, }, ], } const efipay = new EfiPay(options) efipay.createOneStepCharge([], body) .then((resposta) => { console.log('Status:', resposta.data.status) // 'approved', 'waiting', 'unpaid' console.log('Charge ID:', resposta.data.charge_id) console.log('Parcelas:', resposta.data.installments) }) .catch((error) => { console.log('Recusado:', error.error_description) }) ``` -------------------------------- ### Import Efí Pay SDK Module Source: https://github.com/efipay/sdk-node-apis-efi/blob/master/README.md Import the SDK module into your Node.js project. Supports both CommonJS and ES Module syntax. ```javascript const EfiPay = require('sdk-node-apis-efi') ``` ```javascript import EfiPay from 'sdk-node-apis-efi' ``` -------------------------------- ### Create a Charge with Efí Pay SDK Source: https://github.com/efipay/sdk-node-apis-efi/blob/master/README.md Create a payment charge by defining the items and their quantities. The response will contain details of the created charge. ```javascript let chargeInput = { items: [ { name: 'Product A', value: 1000, amount: 2, }, ] } efipay.createCharge({}, chargeInput) .then((resposta) => { console.log(resposta) }) .catch((error) => { console.log(error) }) ``` -------------------------------- ### POST /pix/due Source: https://context7.com/efipay/sdk-node-apis-efi/llms.txt Creates a Pix charge with a due date, including configurable fines, interest, and discounts. ```APIDOC ## POST /pix/due ### Description Creates a Pix charge with a due date, including configurable fines, interest, and discounts. ### Method POST ### Endpoint /pix/due ### Parameters #### Query Parameters - **txid** (string) - Required - Custom transaction ID (max 35 alphanumeric characters). ### Request Body - **calendario** (object) - Required - Contains charge calendar information. - **dataDeVencimento** (string) - Required - The due date in YYYY-MM-DD format. - **validadeAposVencimento** (integer) - Optional - Number of days the charge is valid after the due date. - **devedor** (object) - Required - Debtor information. - **cpf** (string) - Optional - Debtor's CPF. - **nome** (string) - Required - Debtor's full name. - **logradouro** (string) - Optional - Debtor's street address. - **cidade** (string) - Optional - Debtor's city. - **uf** (string) - Optional - Debtor's state (UF). - **cep** (string) - Optional - Debtor's postal code. - **valor** (object) - Required - Payment amount details. - **original** (string) - Required - The original amount in BRL. - **multa** (object) - Optional - Fine details. - **modalidade** (integer) - Required - Fine modality (2 for percentage). - **valorPerc** (string) - Required - Fine percentage value. - **juros** (object) - Optional - Interest details. - **modalidade** (integer) - Required - Interest modality (2 for daily percentage). - **valorPerc** (string) - Required - Daily interest percentage value. - **desconto** (object) - Optional - Discount details. - **modalidade** (integer) - Required - Discount modality (1 for fixed value until a date). - **descontoDataFixa** (array) - Required if modalidade is 1. - **data** (string) - Required - The date the discount is valid until (YYYY-MM-DD). - **valorPerc** (string) - Required - The fixed discount amount in BRL. - **chave** (string) - Required - The registered Pix key. - **solicitacaoPagador** (string) - Optional - A payer-requested message. ### Request Example ```json { "calendario": { "dataDeVencimento": "2024-12-31", "validadeAposVencimento": 30 }, "devedor": { "cpf": "94271564656", "nome": "João da Silva", "logradouro": "Rua das Flores, 123", "cidade": "São Paulo", "uf": "SP", "cep": "01234567" }, "valor": { "original": "500.00", "multa": { "modalidade": 2, "valorPerc": "2.00" }, "juros": { "modalidade": 2, "valorPerc": "0.033" }, "desconto": { "modalidade": 1, "descontoDataFixa": [ { "data": "2024-12-25", "valorPerc": "50.00" } ] } }, "chave": "sua-chave-pix", "solicitacaoPagador": "Referente à fatura #456" } ``` ### Response #### Success Response (200) - **CobV** (object) - Details of the created charge with due date. #### Response Example ```json { "CobV": { "txid": "COBV123456789", "status": "EM_ABERTO", "calendario": { "dataDeVencimento": "2024-12-31", "validadeAposVencimento": 30 }, "valor": { "original": "500.00", "multa": { "modalidade": 2, "valorPerc": "2.00" }, "juros": { "modalidade": 2, "valorPerc": "0.033" }, "desconto": { "modalidade": 1, "descontoDataFixa": [ { "data": "2024-12-25", "valorPerc": "50.00" } ] } }, "chave": "sua-chave-pix", "solicitacaoPagador": "Referente à fatura #456" } } ``` ``` -------------------------------- ### Create Pix Charge Batch with Due Date Source: https://context7.com/efipay/sdk-node-apis-efi/llms.txt Use this to create multiple Pix charges with a due date in a single request. Ensure your EfiPay options are correctly configured. ```javascript const EfiPay = require('sdk-node-apis-efi') const options = require('./credentials') const params = { id: 1001, // ID do lote } const body = { descricao: 'Lote de mensalidades Janeiro/2024', cobsv: [ { txid: 'MENS001JAN2024', calendario: { dataDeVencimento: '2024-01-31', validadeAposVencimento: 30, }, devedor: { cpf: '12345678900', nome: 'Cliente 1', logradouro: 'Rua A, 100', cidade: 'São Paulo', uf: 'SP', cep: '01234567', }, valor: { original: '150.00', }, chave: 'sua-chave-pix', solicitacaoPagador: 'Mensalidade Janeiro', }, { txid: 'MENS002JAN2024', calendario: { dataDeVencimento: '2024-01-31', validadeAposVencimento: 30, }, devedor: { cpf: '98765432100', nome: 'Cliente 2', logradouro: 'Rua B, 200', cidade: 'Rio de Janeiro', uf: 'RJ', cep: '20000000', }, valor: { original: '200.00', }, chave: 'sua-chave-pix', solicitacaoPagador: 'Mensalidade Janeiro', }, ], } const efipay = new EfiPay(options) efipay.pixCreateDueChargeBatch(params, body) .then(() => { console.log('Lote criado com sucesso!') // Consultar status do lote return efipay.pixDetailDueChargeBatch({ id: 1001 }) }) .then((resposta) => { console.log('Status do lote:') resposta.cobsv.forEach((cob) => { console.log(`TXID: ${cob.txid} | Status: ${cob.status}`) }) }) .catch((error) => { console.log('Erro:', error) }) ``` -------------------------------- ### Create Payment Link Source: https://context7.com/efipay/sdk-node-apis-efi/llms.txt Generates a payment link that accepts multiple payment methods. Configure discounts and expiration dates as needed. ```javascript const EfiPay = require('sdk-node-apis-efi') const options = require('./credentials') const body = { items: [ { name: 'Curso Online Completo', value: 29900, // R$ 299,00 amount: 1, }, ], settings: { payment_method: 'all', // 'banking_billet', 'credit_card', 'all' expire_at: '2024-03-31', request_delivery_address: false, billet_discount: 500, // R$ 5,00 de desconto no boleto card_discount: 1000, // R$ 10,00 de desconto no cartão conditional_discount: { type: 'percentage', value: 1000, // 10% until_date: '2024-02-28', }, message: 'Aproveite nossa promoção!', }, metadata: { custom_id: 'LINK-001', notification_url: 'https://seu-site.com/webhook', }, } const efipay = new EfiPay(options) efipay.createOneStepLink({}, body) .then((resposta) => { console.log('Link criado!') console.log('URL de pagamento:', resposta.data.payment_url) console.log('Charge ID:', resposta.data.charge_id) console.log('Expira em:', resposta.data.expire_at) }) .catch((error) => { console.log('Erro:', error) }) ``` -------------------------------- ### Configure Pix Webhook Source: https://context7.com/efipay/sdk-node-apis-efi/llms.txt Configures the callback URL to receive Pix payment notifications. ```APIDOC ## POST /pix/webhooks ### Description Configures the callback URL to receive Pix payment notifications. ### Method POST ### Endpoint /pix/webhooks ### Parameters #### Query Parameters - **chave** (string) - Required - The Pix key to associate with the webhook. #### Request Body - **webhookUrl** (string) - Required - The URL where notifications will be sent. ### Request Example ```json { "webhookUrl": "https://seu-dominio.com.br/webhook/pix" } ``` ### Response #### Success Response (200) - **webhookUrl** (string) - The configured webhook URL. #### Response Example ```json { "webhookUrl": "https://seu-dominio.com.br/webhook/pix" } ``` ``` -------------------------------- ### Open Finance - Iniciar Pagamento Pix Source: https://context7.com/efipay/sdk-node-apis-efi/llms.txt Initiates a Pix payment via Open Finance, allowing debit from any financial institution. It returns a payment identifier and a redirect URI for user authorization. ```APIDOC ## Open Finance - Iniciar Pagamento Pix ### Description Initiates a Pix payment via Open Finance, allowing debit from any financial institution. It returns a payment identifier and a redirect URI for user authorization. ### Method POST ### Endpoint /pix/openfinance/pagamentos ### Parameters #### Request Body - **pagador** (object) - Required - Information about the payer's institution and CPF. - **idParticipante** (string) - Required - The participant ID of the payer's institution. - **cpf** (string) - Required - The payer's CPF. - **favorecido** (object) - Required - Information about the beneficiary's bank account. - **contaBanco** (object) - Required - Details of the beneficiary's bank account. - **codigoBanco** (string) - Required - The Efi bank code. - **agencia** (string) - Required - The bank agency number. - **documento** (string) - Required - The beneficiary's document number (CNPJ/CPF). - **nome** (string) - Required - The beneficiary's name. - **tipoConta** (string) - Required - The type of account (e.g., 'CACC' for checking account). - **detalhes** (object) - Required - Details of the payment. - **valor** (string) - Required - The payment amount. - **idProprio** (string) - Required - A unique identifier for the payment. - **infoPagador** (string) - Optional - Additional information from the payer. ### Request Example ```json { "pagador": { "idParticipante": "identificador-instituicao", "cpf": "12345678900" }, "favorecido": { "contaBanco": { "codigoBanco": "364", "agencia": "0001", "documento": "12345678000195", "nome": "Sua Empresa LTDA", "tipoConta": "CACC" } }, "detalhes": { "valor": "150.00", "idProprio": "PEDIDO-123", "infoPagador": "Pagamento do pedido #123" } } ``` ### Response #### Success Response (200) - **identificadorPagamento** (string) - The unique identifier for the initiated payment. - **redirectURI** (string) - The URI to redirect the user for payment authorization. #### Response Example ```json { "identificadorPagamento": "some-payment-id", "redirectURI": "https://example.com/authorize-payment?token=..." } ``` ```