PHP code example of femitz / c6bank-php

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

    

femitz / c6bank-php example snippets


use Femitz\C6BankPhp\Client;
use Femitz\C6BankPhp\Config;
use Femitz\C6BankPhp\Environment;
use Femitz\C6BankPhp\PartnerSoftware;
use Femitz\C6BankPhp\Auth\Certificate;
use Femitz\C6BankPhp\Auth\Credentials;

$config = new Config(
    credentials: new Credentials(
        clientId: 'seu-client-id',
        clientSecret: 'seu-client-secret',
    ),
    certificate: new Certificate(
        certPath: '/caminho/para/certificado.crt',
        keyPath: '/caminho/para/chave.key',
        // certPassword: 'opcional',
        // keyPassword: 'opcional',
    ),
    partnerSoftware: new PartnerSoftware(
        name: 'Nome do seu software',
        version: '1.0.0',
    ),
    environment: Environment::Sandbox, // ou Environment::Production
);

$client = new Client($config);

$token = $client->getAccessToken(); // reaproveitado em memória até expirar

echo $token->authorizationHeader(); // "Bearer eyJ..."

use Femitz\C6BankPhp\Bolepix\Address;
use Femitz\C6BankPhp\Bolepix\CreateBolepixRequest;
use Femitz\C6BankPhp\Bolepix\Fees;
use Femitz\C6BankPhp\Bolepix\Payer;
use Femitz\C6BankPhp\Bolepix\PaymentMethod;
use Femitz\C6BankPhp\Bolepix\PixOptions;

$request = new CreateBolepixRequest(
    externalReferenceId: 'seu-id-de-referencia',
    amount: 150.00,
    dueDate: '2026-12-30', // ou uma instância de DateTimeInterface
    payer: new Payer(
        name: 'José da Silva',
        taxId: '12345678910',
        address: new Address(
            address: 'Av. Nove de Julho, 3186',
            neighborhood: 'Jardim Paulista',
            city: 'São Paulo',
            state: 'SP',
            zipCode: '01406000',
        ),
        email: '[email protected]',
    ),
    description: 'Mensalidade referente a Junho/2026',
    daysAfterDueDate: 10,
    fees: new Fees(
        fineValue: 10,
        fineDeadline: 1,
        fineType: 'FIXED_VALUE',
        interestValue: 0.33,
        interestDeadline: 1,
        interestType: 'VALUE_PER_DAY',
    ),
    paymentMethod: new PaymentMethod(
        pix: new PixOptions(
            key: '123e4567-e89b-12d3-a456-426614174000',
            type: 'EVP',
        ),
    ),
);

$bolepix = $client->bolepix()->create($request);

echo $bolepix->bankSlip?->digitableLine;
echo $bolepix->pix?->qrCode;

$bolepix = $client->bolepix()->get('seu-id-de-referencia');

echo $bolepix->status;
echo $bolepix->payer?->name;

$pdf = $client->bolepix()->getPdf('seu-id-de-referencia');

file_put_contents('boleto.pdf', $pdf);

use Femitz\C6BankPhp\Bolepix\BankSlipOptions;
use Femitz\C6BankPhp\Bolepix\UpdateBolepixRequest;
use Femitz\C6BankPhp\Bolepix\UpdatePayerOptions;

$request = new UpdateBolepixRequest(
    amount: 150.00,
    dueDate: '2026-12-30',
    description: 'Mensalidade referente a Junho/2026',
    daysAfterDueDate: 30,
    payer: new UpdatePayerOptions(
        email: '[email protected]',
    ),
    fees: new Fees(
        fineValue: 10,
        fineType: 'FIXED_VALUE',
    ),
    paymentMethod: new PaymentMethod(
        bankSlip: new BankSlipOptions(
            yourNumber: '0000003048',
            instructions: ['Não receber após o vencimento'],
        ),
    ),
    origin: 'e-commerce',
);

$bolepix = $client->bolepix()->update('seu-id-de-referencia', $request);

$client->bolepix()->cancel('seu-id-de-referencia');

use Femitz\C6BankPhp\Webhook\RegisterWebhookRequest;

$request = new RegisterWebhookRequest(
    url: 'https://www.meuendereco.com.br/webhook/xpto',
);

$webhook = $client->webhook()->register($request);

echo $webhook->clientId;
echo $webhook->createdAt;

use Femitz\C6BankPhp\Webhook\WebhookService;

$webhook = $client->webhook()->get(WebhookService::BankSlip);

echo $webhook->url;

$client->webhook()->delete(WebhookService::BankSlip);

use Femitz\C6BankPhp\Webhook\BolepixNotification;
use Femitz\C6BankPhp\Webhook\BolepixNotificationStatus;

$notification = BolepixNotification::fromJson($rawRequestBody);

match ($notification->status) {
    BolepixNotificationStatus::Created => // $notification->bolepix está preenchido
        var_dump($notification->bolepix),
    BolepixNotificationStatus::Paid,
    BolepixNotificationStatus::WaitingConfirmation => // $notification->payment está preenchido
        var_dump($notification->payment),
};
bash
composer