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": "5a4c2b18-8f01-49cc-9e3d-2b3b7f1d4e66",
"consultId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890"
}2. Saque via Dados Bancários
json
{
"type": "MANU",
"amount": 500.00,
"accountHolderDocument": "12345678901",
"accountHolderName": "João Silva",
"account": "12345",
"accountType": "CACC",
"agency": "0001",
"ispb": "00000000",
"customerId": "5a4c2b18-8f01-49cc-9e3d-2b3b7f1d4e66"
}3. Pagamento de Boleto
json
{
"type": "BILLET",
"amount": 500.00,
"billetCode": "34191790010104351004791020150008291070026000",
"customerId": "5a4c2b18-8f01-49cc-9e3d-2b3b7f1d4e66"
}RECOMENDADO
Antes de criar um saque via chave Pix, valide a chave usando Validar Chave Pix. O consultToken retornado deve ser enviado no campo consultId para garantir que o pagamento será enviado ao destinatário correto.
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": "5a4c2b18-8f01-49cc-9e3d-2b3b7f1d4e66",
"consultId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890"
}'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: '5a4c2b18-8f01-49cc-9e3d-2b3b7f1d4e66',
consultId: 'a1b2c3d4-e5f6-7890-abcd-ef1234567890'
})
}
);
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': '5a4c2b18-8f01-49cc-9e3d-2b3b7f1d4e66',
'consultId': 'a1b2c3d4-e5f6-7890-abcd-ef1234567890'
}
)
withdraw = response.json()Resposta de Sucesso
Status: 201 Created
json
{
"id": "3b2f09c7-99f0-4a6e-9ea5-6a497bb7f301",
"status": "PENDING"
}Tipos de Conta
| Tipo | Descrição |
|---|---|
| CACC | Conta Corrente |
| SVGS | Conta Poupança |
| TRAN | Conta de Pagamento |
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: '5a4c2b18-8f01-49cc-9e3d-2b3b7f1d4e66'
});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.account) {
errors.push('Número da conta é obrigatório');
}
if (!['CACC', 'SVGS', 'TRAN'].includes(data.accountType)) {
errors.push('Tipo de conta inválido');
}
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
Atualmente a API de saque não envia webhook dedicado para withdraws. Para acompanhar o status, use Consultar Saque ou Listar Saques.
Prazos
- Pix: Até 1 dia útil
- TED: Até 3 dias úteis
- Boleto: Imediato (pagamento)