Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.upaybr.com/llms.txt

Use this file to discover all available pages before exploring further.

Upay PHP SDK

SDK oficial da Upay para PHP. Compatível com PHP 8.1+.

Instalação

Este SDK ainda não está publicado no Packagist. Instale diretamente pelo GitHub:
composer config repositories.upay vcs https://github.com/anthonymengottii/upay-php-sdk
composer require upay/upay-php:dev-main

Uso Rápido

<?php
require 'vendor/autoload.php';

use Upay\UpayClient;

$upay = new UpayClient($_ENV['UPAY_API_KEY']);
$link = $upay->paymentLinks->create([
    'title'       => 'Produto Premium',
    'amountCents' => 9900,
    'description' => 'Acesso vitalício',
]);

Resposta

[
    'id'          => 'lnk_abc123',
    'title'       => 'Produto Premium',
    'description' => 'Acesso vitalício',
    'amountCents' => 9900,
    'status'      => 'ACTIVE',
    'url'         => 'https://pay.upaybr.com/l/abc123',
    'createdAt'   => '2026-04-08T00:00:00.000Z',
    'updatedAt'   => '2026-04-08T00:00:00.000Z',
]

Criar Transação PIX

$tx = $upay->transactions->create([
    'product'        => 'Curso PHP',
    'paymentMethod'  => 'PIX',
    'amountCents'    => 19900,
    'clientName'     => 'João Silva',
    'clientEmail'    => 'joao@example.com',
    'clientDocument' => '12345678900',
]);

echo $tx['pixCopiaECola'];

Validar Cupom

$result = $upay->coupons->validate('DESCONTO10', 19900);

// $result['valid'], $result['discountCents'], $result['finalAmountCents']

Validação de Webhooks

<?php
$payload   = file_get_contents('php://input');
$signature = $_SERVER['HTTP_X_WEBHOOK_SIGNATURE'] ?? '';

if (!$upay->verifyWebhookSignature($payload, $signature, $_ENV['UPAY_WEBHOOK_SECRET'])) {
    http_response_code(401);
    exit(json_encode(['error' => 'Assinatura inválida']));
}

$event = json_decode($payload, true);
echo json_encode(['received' => true]);

Tratamento de Erros

<?php
use Upay\Exceptions\UpayValidationException;
use Upay\Exceptions\UpayException;

try {
    $tx = $upay->transactions->create([...]);
} catch (UpayValidationException $e) {
    echo 'Dados inválidos: ' . $e->getMessage();
} catch (UpayException $e) {
    echo 'Erro ' . $e->getStatusCode() . ': ' . $e->getMessage();
}