PHP code example of flowinpay / flowinpay-php

1. Go to this page and download the library: Download flowinpay/flowinpay-php 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/ */

    

flowinpay / flowinpay-php example snippets




use FlowinPay\FlowinPay;

$fp = new FlowinPay('fpk_sua_chave_aqui');

// Cria uma cobrança PIX de R$ 100 com split
$res = $fp->charges->create([
    'value' => 100,
    'description' => 'Pedido #123',
    'callbackUrl' => 'https://seusite.com/webhooks/flowinpay',
    'split' => [
        ['type' => 'percentage', 'value' => 10, 'recipient' => 'PUBLIC_ID_DO_COPRODUTOR'],
    ],
]);

$charge = $res['charge'];
echo $charge['br_code'];          // PIX copia-e-cola (exiba para o pagador)
echo $charge['payment_link_url']; // link de pagamento pronto
echo $charge['qr_code_image'];    // URL do QR Code

$res = $fp->charges->create(['value' => 50, 'description' => 'Curso']);
$one = $fp->charges->get($res['charge']['id']);
$all = $fp->charges->list();
$fp->charges->cancel($res['charge']['id']);

$saldo = $fp->balance->get();
echo $saldo['balance']['available'];

$fp->withdrawals->create([
    'value' => 100,
    'pix_key' => '[email protected]',
    'pix_key_type' => 'email', // 'cpf' | 'cnpj' | 'email' | 'phone' | 'random'
]);

$res = $fp->webhooks->create([
    'url' => 'https://seusite.com/webhooks/flowinpay',
    'events' => ['charge.completed', 'charge.expired'],
]);
// ⚠️ Guarde o secret — só aparece nesta resposta:
echo $res['webhook']['secret']; // whsec_...

use FlowinPay\Webhook;
use FlowinPay\FlowinPayException;

$raw = file_get_contents('php://input');
$sig = $_SERVER['HTTP_X_FLOWINPAY_SIGNATURE'] ?? null;

try {
    $evento = Webhook::parse($raw, $sig, 'whsec_seu_secret');
} catch (FlowinPayException $e) {
    http_response_code(401);
    exit('assinatura inválida');
}

http_response_code(200); // responda rápido (timeout de 5s)

if ($evento['event'] === 'charge.completed') {
    // libere o produto...
    error_log('Pago: ' . $evento['charge']['correlation_id']);
}

use FlowinPay\FlowinPayException;

try {
    $fp->charges->create(['value' => 1]); // abaixo do mínimo
} catch (FlowinPayException $e) {
    echo $e->status;   // 422
    echo $e->getMessage();
    print_r($e->errors); // erros de validação por campo
}
bash
composer