Webhook de Sub-conta
Configura webhook individual para uma sub-conta.
PUT /api/customer/{id}/webhook
Configura webhook para receber notificações de transações da sub-conta.
Endpoint
PUT https://api.divipay.com.br/api/customer/{id}/webhookHeaders
| Header | Valor | Obrigatório |
|---|---|---|
| Authorization | Bearer | Sim |
| Content-Type | application/json | Sim |
Path Parameters
| Parâmetro | Tipo | Descrição |
|---|---|---|
| id | string | ID da sub-conta |
Body Parameters
| Campo | Tipo | Descrição | Obrigatório |
|---|---|---|---|
| url | string | URL para receber webhooks | Sim |
Exemplo de Requisição
bash
curl -X PUT https://api.divipay.com.br/api/customer/5a4c2b18-8f01-49cc-9e3d-2b3b7f1d4e66/webhook \
-H "Authorization: Bearer SEU_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"url": "https://vendedor.com/webhook"
}'javascript
const response = await fetch(
'https://api.divipay.com.br/api/customer/5a4c2b18-8f01-49cc-9e3d-2b3b7f1d4e66/webhook',
{
method: 'PUT',
headers: {
'Authorization': 'Bearer SEU_TOKEN',
'Content-Type': 'application/json'
},
body: JSON.stringify({
url: 'https://vendedor.com/webhook'
})
}
);
const result = await response.json();Resposta de Sucesso
Status: 201 Created
json
{
"id": "5a4c2b18-8f01-49cc-9e3d-2b3b7f1d4e66",
"name": "Loja Exemplo",
"webhookUrl": "https://vendedor.com/webhook",
"status": 1
}PUT /api/customer/webhook
Configura webhook da conta principal.
Endpoint
PUT https://api.divipay.com.br/api/customer/webhookExemplo
bash
curl -X PUT https://api.divipay.com.br/api/customer/webhook \
-H "Authorization: Bearer SEU_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"url": "https://plataforma.com/webhook"
}'Payload Recebido
Atualmente os webhooks desta API são enviados para eventos de cobrança (Pix e Cartão). Não há payload de saque com withdraw.completed.
Pagamento Confirmado
json
{
"status": "APPROVED",
"id": "8f7c6a2d-4a1b-4de8-9f2d-1e84f7b80c11",
"txId": "E1234567890123456789012345678901",
"transactionCode": "E1234567890123456789012345678901",
"referenceId": "pedido-123",
"amount": 100.00,
"type": "PIX",
"chargeType": "PIX"
}Exemplo de Implementação
javascript
const express = require('express');
const app = express();
app.use(express.json());
// Webhook da sub-conta
app.post('/webhook/seller/:sellerId', async (req, res) => {
const { sellerId } = req.params;
const payload = req.body;
console.log(`Webhook recebido para vendedor ${sellerId}:`, payload.status);
try {
if (payload.status === 'APPROVED' && (payload.type === 'PIX' || payload.type === 'CREDIT_CARD')) {
await handleSellerPayment(sellerId, payload);
} else {
console.log('Payload não tratado:', payload);
}
res.status(200).send('OK');
} catch (error) {
console.error('Erro ao processar webhook:', error);
res.status(500).send('Error');
}
});
async function handleSellerPayment(sellerId, payload) {
// Atualizar saldo do vendedor
await db.sellers.update({
where: { id: sellerId },
data: {
balance: {
increment: payload.amount
}
}
});
// Notificar vendedor
await sendNotification(sellerId, {
title: 'Pagamento Recebido',
message: `Você recebeu R$ ${payload.amount.toFixed(2)}`
});
}
app.listen(3000);