Documentation Index
Fetch the complete documentation index at: https://docs.usealpa.com/llms.txt
Use this file to discover all available pages before exploring further.
Alpa PHP SDK
SDK oficial da Alpa 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.alpa vcs https://github.com/anthonymengottii/alpa-php-sdk
composer require alpa/alpa-php:dev-main
Uso Rápido
<?php
require 'vendor/autoload.php';
use Alpa\AlpaClient;
$alpa = new AlpaClient($_ENV['ALPA_API_KEY']);
Criar Link de Pagamento
$link = $alpa->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.usealpa.com/l/abc123',
'createdAt' => '2026-04-08T00:00:00.000Z',
'updatedAt' => '2026-04-08T00:00:00.000Z',
]
Criar Transação PIX
$tx = $alpa->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 = $alpa->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 (!$alpa->verifyWebhookSignature($payload, $signature, $_ENV['ALPA_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 Alpa\Exceptions\AlpaValidationException;
use Alpa\Exceptions\AlpaException;
try {
$tx = $alpa->transactions->create([...]);
} catch (AlpaValidationException $e) {
echo 'Dados inválidos: ' . $e->getMessage();
} catch (AlpaException $e) {
echo 'Erro ' . $e->getStatusCode() . ': ' . $e->getMessage();
}