1. Go to this page and download the library: Download nwiry/bompix-sdk-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/ */
nwiry / bompix-sdk-php example snippets
use Nwiry\BompixSDK\Request\AuthRequest;
// Inicialize a autenticação
$auth = new AuthRequest("{SUA_CHAVE_DE_API}", "{SUA_CHAVE_SECRETA}");
// Execute a autenticação e obtenha a resposta da API
$responseAuth = $auth->login()->getResponse();
// Armazene o token e o tempo de expiração
$token = $responseAuth->token;
$expiresIn = $responseAuth->expires_in;
use Nwiry\BompixSDK\Link;
use Nwiry\BompixSDK\Request\LinkRequest;
// Inicialize a instância de link
$link = new Link("nomedomeulink");
// Crie o link de pagamento
$linkRequest = new LinkRequest($responseAuth, $link);
$result = $linkRequest->create()->getResponse();
// Armazene os detalhes do link
$linkId = $result->id;
$linkSlug = $result->slug;
use Nwiry\BompixSDK\Link;
use Nwiry\BompixSDK\Request\LinkRequest;
// Obtenha um link específico via ID
$link = new Link("nomedomeulink");
$linkRequest = new LinkRequest($responseAuth, $link);
$linkDetails = $linkRequest->get(1);
// Obtenha os detalhes do link
$linkId = $linkDetails->id;
$linkSlug = $linkDetails->slug;
$linkUrl = $linkDetails->url;
// Obtenha uma lista de links
$links = $linkRequest->getAll();
foreach ($links as $link) {
echo $link->id;
echo $link->slug;
echo $link->url;
}
use Nwiry\BompixSDK\Link;
use Nwiry\BompixSDK\Payment;
use Nwiry\BompixSDK\PaymentMessage;
use Nwiry\BompixSDK\Request\LinkRequest;
use Nwiry\BompixSDK\Request\PaymentRequest;
// Obtenha o link
$link = new Link("nomedomeulink");
$linkRequest = new LinkRequest($responseAuth, $link);
$linkDetails = $linkRequest->get(slug: $link->slug);
// Defina os dados do pagamento
$paymentData = new Payment(5.35, $linkDetails->id);
$payerMessage = new PaymentMessage("João", "Pagamento da fatura #1", "[email protected]");
$paymentData->setMessage($payerMessage);
// Crie o pagamento
$paymentRequest = new PaymentRequest($responseAuth, $paymentData);
$payment = $paymentRequest->create()->getResponse();
// Armazene os detalhes do pagamento
$paymentUuid = $payment->uuid;
$paymentQrcode = $payment->qrcode;
$paymentQrcodePng = $payment->qrcode_png;
$paymentPixDuration = $payment->pix_duration;
use Nwiry\BompixSDK\Request\PaymentRequest;
// Obtenha um pagamento específico
$paymentRequest = new PaymentRequest($responseAuth);
$payment = $paymentRequest->get("{UUID}");
// Obtenha uma lista de pagamentos
$payments = $paymentRequest->getAll();
foreach ($payments as $payment) {
echo $payment->uuid;
echo $payment->qrcode;
echo $payment->qrcode_png;
echo $payment->pix_duration;
echo $payment->paid ? "Pago" : "Não Pago";
}
use Nwiry\BompixSDK\Webhook;
use Nwiry\BompixSDK\Request\WebhookRequest;
// Crie um novo webhook
$linkDetails = $linkRequest->get(slug: $link->slug);
$webhookData = new Webhook($linkDetails->id, "{SUA_URL_PARA_NOTIFICACAO}");
$webhookRequest = new WebhookRequest($responseAuth, $webhookData);
$webhook = $webhookRequest->create()->getResponse();
// Obtenha um webhook específico
$webhookDetails = $webhookRequest->get($webhook->id);
// Obtenha uma lista de webhooks
$webhooks = $webhookRequest->getAll();
// Delete um webhook
$webhookRequest->delete($webhook->id);
use Nwiry\BompixSDK\Notification;
use Nwiry\BompixSDK\Request\PaymentRequest;
// Inicialize a instância de notificação na rota do seu webhook
$notification = new Notification();
$event = $notification->processNotification();
// Verifique a veracidade da notificação
$payment = (new PaymentRequest($responseAuth))->get($event->uuid);
$isPaid = $payment->paid ? "Pagamento efetuado com sucesso" : "O pagamento ainda não foi efetuado";