Os exemplos abaixo seguem o fluxo mais comum do seller: autenticar, gerar uma cobrança PIX e validar a assinatura do webhook de retorno.
const authResponse = await fetch('https://api.xxxpay.online/api/auth/login', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
client_id: process.env.XXXPAY_CLIENT_ID,
client_secret: process.env.XXXPAY_CLIENT_SECRET,
}),
});
const authData = await authResponse.json();
const depositResponse = await fetch('https://api.xxxpay.online/api/payments/deposit', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${authData.token}`,
},
body: JSON.stringify({
amount: 25.90,
external_id: 'pedido-1001',
clientCallbackUrl: 'https://seller.exemplo.com/webhooks/xxxpay/deposit',
payer: {
name: 'Cliente da Silva',
email: 'cliente@seller.com',
document: '12345678909',
phone: '5547999999999',
},
}),
});
$auth = Http::post('https://api.xxxpay.online/api/auth/login', [
'client_id' => env('XXXPAY_CLIENT_ID'),
'client_secret' => env('XXXPAY_CLIENT_SECRET'),
])->throw()->json();
$deposit = Http::withToken($auth['token'])
->post('https://api.xxxpay.online/api/payments/deposit', [
'amount' => 25.90,
'external_id' => 'pedido-1001',
'clientCallbackUrl' => 'https://seller.exemplo.com/webhooks/xxxpay/deposit',
'payer' => [
'name' => 'Cliente da Silva',
'email' => 'cliente@seller.com',
'document' => '12345678909',
'phone' => '5547999999999',
],
])->throw()->json();
import os
import requests
auth = requests.post(
'https://api.xxxpay.online/api/auth/login',
json={
'client_id': os.environ['XXXPAY_CLIENT_ID'],
'client_secret': os.environ['XXXPAY_CLIENT_SECRET'],
},
)
auth.raise_for_status()
token = auth.json()['token']
deposit = requests.post(
'https://api.xxxpay.online/api/payments/deposit',
headers={'Authorization': f'Bearer {token}'},
json={
'amount': 25.90,
'external_id': 'pedido-1001',
'clientCallbackUrl': 'https://seller.exemplo.com/webhooks/xxxpay/deposit',
'payer': {
'name': 'Cliente da Silva',
'email': 'cliente@seller.com',
'document': '12345678909',
'phone': '5547999999999',
},
},
)
deposit.raise_for_status()
import crypto from 'node:crypto';
function verifyWebhook({ rawBody, timestamp, signature, secret }) {
const expected = crypto
.createHmac('sha256', secret)
.update(`${timestamp}.${rawBody}`, 'utf8')
.digest('hex');
return crypto.timingSafeEqual(
Buffer.from(expected, 'hex'),
Buffer.from(signature, 'hex'),
);
}