1. Go to this page and download the library: Download clubedev/pagbank-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/ */
clubedev / pagbank-php example snippets
use ClubeDev\PagBank\PagBank;
$payment = new PagBank(
pagBankToken: 'SEU_TOKEN_PAGBANK',
clubeDevToken: 'SEU_TOKEN_CLUBEDEV',
sandbox: true // true = ambiente de testes
);
use ClubeDev\PagBank\Domain\Client;
use ClubeDev\PagBank\Domain\Phone;
use ClubeDev\PagBank\Domain\Item;
use ClubeDev\PagBank\Domain\Shipping;
use ClubeDev\PagBank\Domain\Address;
use ClubeDev\PagBank\Domain\Payment;
use ClubeDev\PagBank\Domain\Payment\Pix;
$response = $payment->createPayment(
reference: "identificação-informada-por-você", // Geralmente utilizado algum id
client: new Client(
document: "12345678909",
name: "João",
email: "[email protected]",
phones: [ // Opcional
new Phone(
country: 55,
area: 21,
number: 999121314
),
new Phone(
country: 55,
area: 21,
number: 999151617
),
]
),
items: [ // Opcional
new Item(
name: 'Item X',
quantity: 1,
unit_amount: 12.99
)
],
shipping: new Shipping( // Opcional
address: new Address(
street: 'Rua 01',
number: '01', // Opcional
complement: 'Q01 L01', // Opcional
locality: 'Bairro',
city: 'Cidade',
state_code: 'SP',
postal_code: '01310930'
)
),
payment: new Payment(
pix: new Pix(
expiration_date: "2025-12-01 12:00:00",
amount: 25.90
)
),
webhook_url: 'https://exemplo.com/webhook' // Opcional
);
use ClubeDev\PagBank\Domain\Shipping;
new Shipping(
address: new Address(...),
);
use ClubeDev\PagBank\Domain\Payment\Holder;
new Holder(
document: '123.456.789-09',
name: 'Fulano Teste',
email: '[email protected]',
address: new Address(...)
)
use ClubeDev\PagBank\Domain\Payment\CreditCard;
new CreditCard(
amount: 11.50,
description: 'Descrição do pagamento',
soft_descriptor: 'NOMEFATURA', // Descrição que aparecerá na fatura do cartão
holder: new Holder(...),
card_token: 'TOKEN_GERADO_PELO_SDK_JS',
installments: 1,
charge_id: null, // Preenchido automaticamente pelo backend
reference: null, // Preenchido automaticamente pelo backend
authorization_code: null, // Preenchido automaticamente pelo backend
nsu: null, // Preenchido automaticamente pelo backend
brand: null, // Preenchido automaticamente pelo backend
card_number: null, // Preenchido automaticamente pelo backend
expiration: null, // Preenchido automaticamente pelo backend
)
use ClubeDev\PagBank\Domain\Payment\Title;
new Title(
amount: 11.50,
description: 'Descrição do boleto para controle interno',
due_date: '2025-12-01',
holder: new Holder(...),
instruction_line_1: 'Não receber após vencimento',
instruction_line_2: 'Pagável apenas na loterica',
charge_id: null, // Preenchido automaticamente pelo backend
bar_code: null, // Preenchido automaticamente pelo backend
url: null, // Preenchido automaticamente pelo backend
)
use ClubeDev\PagBank\Domain\Payment\Pix;
new Pix(
amount: 11.50,
expiration_date: '2025-12-01 12:30:00',
charge_id: null, // Preenchido automaticamente pelo backend
qrcode: null, // Preenchido automaticamente pelo backend
qrcode_image: null, // Preenchido automaticamente pelo backend
)
use ClubeDev\PagBank\Domain\Payment;
new Payment(
pix: new Pix(...),
title: new Title(...),
credit_card: new CreditCard(...),
paid_at: null, // Preenchido automaticamente pelo backend
status: null, // Preenchido automaticamente pelo backend
full_refunded: null, // Preenchido automaticamente pelo backend
paid: null, // Preenchido automaticamente pelo backend
refunded: null, // Preenchido automaticamente pelo backend
)