PHP code example of flaviomoreir4 / laravel-transfeera

1. Go to this page and download the library: Download flaviomoreir4/laravel-transfeera library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

flaviomoreir4 / laravel-transfeera example snippets


use Transfeera;

// Criar um lote de pagamentos
$batch = Transfeera::batches()->create([
    'name' => 'Pagamento fornecedores',
    'type' => 'manual',
]);

// Consultar saldo
$balance = Transfeera::statement()->getBalance();

// Validar conta bancária (Conta Certa)
$validation = Transfeera::contaCertaValidations()->validate([
    'bank_code' => '341',
    'agency' => '1234',
    'account' => '56789-0',
    'document' => '123.456.789-00',
]);

use FlavioMoreir4\Transfeera\TransfeeraClient;

class PaymentService
{
    public function __construct(
        private TransfeeraClient $transfeera,
    ) {}

    public function payout(array $transfers): BatchResponseDTO
    {
        return $this->transfeera->batches()->create([
            'name' => 'Lote de pagamentos',
            'transfers' => $transfers,
        ]);
    }
}

// Criar lote com transferências
$batch = Transfeera::batches()->create([
    'name' => 'Fornecedores Julho',
    'type' => 'manual',
]);

// Adicionar transferência ao lote
$transfer = Transfeera::transfers($batch['id'])->create([
    'amount' => 150000,                     // R$ 1.500,00 (em centavos)
    'pix_key' => '[email protected]',
    'pix_key_type' => 'email',
    'description' => 'Pagamento nota 123',
]);

// Consultar saldo
$balance = Transfeera::statement()->getBalance();
// ['balance' => 500000, 'blocked' => 100000, 'available' => 400000]

// Criar cobrança Pix com vencimento
$charge = Transfeera::charges()->create([
    'payer_document' => '123.456.789-00',
    'payer_name' => 'João Silva',
    'amount' => 50000,                // R$ 500,00 (centavos)
    'due_date' => '2025-08-15',
    'type' => 'pix',
]);

// Baixar PDF do boleto
$pdf = Transfeera::charges()->downloadPdfByChargeId($charge->id);

// Criar chave Pix
$key = Transfeera::pixKeys()->create([
    'type' => 'email',
    'value' => '[email protected]',
]);

// Criar autorização Pix Automático
$auth = Transfeera::pixAutomaticoAuthorizations()->create([
    'payer_document' => '123.456.789-00',
    'payer_name' => 'João Silva',
    'payer_bank' => '341',
    'limit_amount' => 100000,         // R$ 1.000,00 (centavos)
    'limit_type' => 'monthly',
]);

// Criar instrução de pagamento
$intent = Transfeera::pixAutomaticoPaymentIntents()->create([
    'authorization_id' => $auth->id,
    'amount' => 50000,
    'description' => 'Assinatura mensal',
]);

// Validar conta bancária
$result = Transfeera::contaCertaValidations()->validate([
    'bank_code' => '341',
    'agency' => '1234',
    'account' => '56789-0',
    'document' => '123.456.789-00',
    'account_type' => 'corrente',
]);

// Criar conta digital
$account = Transfeera::accounts()->create([
    'name' => 'Conta Cliente A',
    'document' => '12.345.678/0001-90',
    'type' => 'company',
]);

// Analisar infração individual
$analysis = Transfeera::infractions()->analyze([
    'end_to_end_id' => 'E123456789012024...',
    'infraction_type' => 'fraud',
]);

// Devolução em lote
$result = Transfeera::infractions()->returnBatch([
    'infractions' => [...],
]);

// Ouvir eventos no EventServiceProvider
use FlavioMoreir4\Transfeera\Events\TransfeeraWebhookReceived;

protected $listen = [
    TransfeeraWebhookReceived::class => [
        MinhaListener::class,
    ],
];

use FlavioMoreir4\Transfeera\Exceptions\{
    TransfeeraException,
    TransfeeraAuthenticationException,  // 401
    TransfeeraValidationException,      // 422 — use $e->getErrors()
    TransfeeraRateLimitException,       // 429 — use $e->getRetryAfter()
    PaymentException,                   // Erros em Pagamentos
    ReceivableException,                // Erros em Recebimentos
    PixAutomaticoException,             // Erros em Pix Automático
    ContaCertaException,                // Erros em Conta Certa
    AccountException,                   // Erros no Hub de Contas
    InfractionException,                // Erros em MED/Infrações
};

try {
    $batch = Transfeera::batches()->create([...]);
} catch (TransfeeraValidationException $e) {
    // Campos inválidos
    foreach ($e->getErrors() as $field => $messages) { ... }
} catch (TransfeeraRateLimitException $e) {
    // Rate limit — backoff
    $retryAfter = $e->getRetryAfter();
    $limit = $e->getLimit();
    $remaining = $e->getRemaining();
} catch (PaymentException $e) {
    // Erro específico de pagamentos
}

// Forçar renovação manual
Transfeera::getConfig(); // ou via TokenManager

// Operar como conta específica
$batches = Transfeera::batches('acc_123')->list();

// Criar recurso em nome de outra conta
$batch = Transfeera::batches('acc_456')->create([
    'name' => 'Lote Conta B',
]);
bash
php artisan vendor:publish --tag=transfeera-config
bash
php artisan vendor:publish --tag=transfeera-routes
bash
php artisan transfeera:check
# 🔍 Verificando conectividade e credenciais da API Transfeera...
# 🌐 Testando autenticação: https://login-api-sandbox.transfeera.com/authorization
# OK: Credenciais validadas

php artisan transfeera:check --silent && echo "Transfeera OK"