Criar Saque
Cria uma solicitação de saque manual.
POST /api/withdraws
Endpoint
POST https://api.divipay.com.br/api/withdrawsHeaders
| Header | Valor | Obrigatório |
|---|---|---|
| Authorization | Bearer | Sim |
| Content-Type | application/json | Sim |
Tipos de Saque
1. Saque via Chave Pix
json
{
"type": "DICT",
"amount": 500.00,
"keyPix": "joao@email.com",
"customerId": "sub_abc123"
}2. Saque via Dados Bancários
json
{
"type": "MANU",
"amount": 500.00,
"accountHolderDocument": "12345678901",
"accountHolderName": "João Silva",
"account": "12345",
"accountType": "CC",
"agency": "0001",
"ispb": "00000000",
"customerId": "sub_abc123"
}3. Pagamento de Boleto
json
{
"type": "BILLET",
"amount": 500.00,
"billetCode": "34191790010104351004791020150008291070026000",
"customerId": "sub_abc123"
}Exemplo - Saque Pix
bash
curl -X POST https://api.divipay.com.br/api/withdraws \
-H "Authorization: Bearer SEU_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"type": "DICT",
"amount": 500.00,
"keyPix": "joao@email.com",
"customerId": "sub_abc123"
}'javascript
const response = await fetch(
'https://api.divipay.com.br/api/withdraws',
{
method: 'POST',
headers: {
'Authorization': 'Bearer SEU_TOKEN',
'Content-Type': 'application/json'
},
body: JSON.stringify({
type: 'DICT',
amount: 500.00,
keyPix: 'joao@email.com',
customerId: 'sub_abc123'
})
}
);
const withdraw = await response.json();python
import requests
response = requests.post(
'https://api.divipay.com.br/api/withdraws',
headers={
'Authorization': 'Bearer SEU_TOKEN',
'Content-Type': 'application/json'
},
json={
'type': 'DICT',
'amount': 500.00,
'keyPix': 'joao@email.com',
'customerId': 'sub_abc123'
}
)
withdraw = response.json()Resposta de Sucesso
Status: 201 Created
json
{
"id": "wtd_xyz789abc",
"status": "PENDING"
}Tipos de Conta
| Tipo | Descrição |
|---|---|
| CC | Conta Corrente |
| OP | Conta Poupança |
Status do Saque
| Status | Descrição |
|---|---|
| PENDING | Aguardando processamento |
| PROCESSING | Em processamento |
| FINISHED | Concluído |
| CANCELED | Cancelado |
Exemplo Completo
javascript
async function createWithdraw(data) {
try {
// Validar saldo
const customer = await fetch(
`https://api.divipay.com.br/api/customer/${data.customerId}`,
{
headers: { 'Authorization': `Bearer ${token}` }
}
).then(r => r.json());
const available = customer.balance - customer.blockedBalance;
if (available < data.amount) {
throw new Error('Saldo insuficiente');
}
// Criar saque
const response = await fetch(
'https://api.divipay.com.br/api/withdraws',
{
method: 'POST',
headers: {
'Authorization': `Bearer ${token}`,
'Content-Type': 'application/json'
},
body: JSON.stringify(data)
}
);
if (!response.ok) {
const error = await response.json();
throw new Error(error.message);
}
const withdraw = await response.json();
console.log('✅ Saque criado:', withdraw.id);
return withdraw;
} catch (error) {
console.error('❌ Erro ao criar saque:', error);
throw error;
}
}
// Uso
const withdraw = await createWithdraw({
type: 'DICT',
amount: 500.00,
keyPix: 'joao@email.com',
customerId: 'sub_abc123'
});Validações
javascript
function validateWithdrawData(data) {
const errors = [];
// Validar valor
if (!data.amount || data.amount <= 0) {
errors.push('Valor deve ser maior que zero');
}
// Validar tipo
if (!['DICT', 'MANU', 'BILLET'].includes(data.type)) {
errors.push('Tipo de saque inválido');
}
// Validar campos específicos
if (data.type === 'DICT' && !data.keyPix) {
errors.push('Chave Pix é obrigatória');
}
if (data.type === 'MANU') {
if (!data.accountHolderDocument) {
errors.push('CPF/CNPJ do titular é obrigatório');
}
if (!data.account) {
errors.push('Número da conta é obrigatório');
}
if (!data.agency) {
errors.push('Agência é obrigatória');
}
if (!data.ispb) {
errors.push('ISPB é obrigatório');
}
}
if (data.type === 'BILLET' && !data.billetCode) {
errors.push('Código do boleto é obrigatório');
}
if (errors.length > 0) {
throw new Error(errors.join(', '));
}
}Interface de Saque
javascript
// React Component
function WithdrawForm({ customerId, onSuccess }) {
const [type, setType] = useState('DICT');
const [amount, setAmount] = useState('');
const [keyPix, setKeyPix] = useState('');
const [loading, setLoading] = useState(false);
async function handleSubmit(e) {
e.preventDefault();
setLoading(true);
try {
const withdraw = await createWithdraw({
type,
amount: parseFloat(amount),
keyPix,
customerId
});
alert('Saque solicitado com sucesso!');
onSuccess?.(withdraw);
} catch (error) {
alert('Erro: ' + error.message);
} finally {
setLoading(false);
}
}
return (
<form onSubmit={handleSubmit}>
<h2>Solicitar Saque</h2>
<select value={type} onChange={(e) => setType(e.target.value)}>
<option value="DICT">Chave Pix</option>
<option value="MANU">Dados Bancários</option>
<option value="BILLET">Boleto</option>
</select>
<input
type="number"
placeholder="Valor"
value={amount}
onChange={(e) => setAmount(e.target.value)}
step="0.01"
required
/>
{type === 'DICT' && (
<input
type="text"
placeholder="Chave Pix"
value={keyPix}
onChange={(e) => setKeyPix(e.target.value)}
required
/>
)}
<button type="submit" disabled={loading}>
{loading ? 'Processando...' : 'Solicitar Saque'}
</button>
</form>
);
}Webhook
Quando o saque for concluído:
json
{
"event": "withdraw.completed",
"withdrawId": "wtd_xyz789",
"customerId": "sub_abc123",
"amount": 500.00,
"completedAt": "2024-11-04T16:00:00.000Z",
"status": "FINISHED"
}Prazos
- Pix: Até 1 dia útil
- TED: Até 3 dias úteis
- Boleto: Imediato (pagamento)