Skip to content

Listar Saques

Lista os saques realizados.

GET /api/withdraws

Endpoint

GET https://api.divipay.com.br/api/withdraws

Headers

HeaderValorObrigatório
AuthorizationBearerSim

Query Parameters

ParâmetroTipoDescriçãoObrigatório
limitnumberQuantidade de registros (padrão 20)Não
offsetnumberRegistros a pular (paginação)Não
customerIdstringFiltrar por sub-contaNão

Exemplo de Requisição

bash
curl -X GET "https://api.divipay.com.br/api/withdraws?limit=10&offset=0" \
  -H "Authorization: Bearer SEU_TOKEN"
bash
curl -X GET "https://api.divipay.com.br/api/withdraws?customerId=sub_abc123" \
  -H "Authorization: Bearer SEU_TOKEN"
javascript
const response = await fetch(
  'https://api.divipay.com.br/api/withdraws?limit=10&offset=0',
  {
    headers: {
      'Authorization': 'Bearer SEU_TOKEN'
    }
  }
);

const withdraws = await response.json();
python
import requests

response = requests.get(
    'https://api.divipay.com.br/api/withdraws',
    params={
        'limit': 10,
        'offset': 0
    },
    headers={
        'Authorization': 'Bearer SEU_TOKEN'
    }
)

withdraws = response.json()

Resposta de Sucesso

Status: 200 OK

json
{
  "data": [
    {
      "id": "wtd_xyz789",
      "status": "FINISHED",
      "amount": 500.00,
      "type": "DICT",
      "createdAt": "2024-11-04T15:00:00.000Z",
      "completedAt": "2024-11-04T16:00:00.000Z",
      "customerId": "sub_abc123"
    },
    {
      "id": "wtd_abc456",
      "status": "PENDING",
      "amount": 300.00,
      "type": "MANU",
      "createdAt": "2024-11-04T14:00:00.000Z",
      "customerId": "sub_abc123"
    }
  ],
  "total": 2,
  "limit": 10,
  "offset": 0
}

Exemplo de Uso

Listar com Paginação

javascript
async function listWithdraws(page = 1, limit = 20) {
  const offset = (page - 1) * limit;

  const response = await fetch(
    `https://api.divipay.com.br/api/withdraws?limit=${limit}&offset=${offset}`,
    {
      headers: { 'Authorization': `Bearer ${token}` }
    }
  );

  const data = await response.json();

  return {
    withdraws: data.data,
    total: data.total,
    page,
    totalPages: Math.ceil(data.total / limit)
  };
}

// Uso
const result = await listWithdraws(1, 20);
console.log(`Página 1 de ${result.totalPages}`);
console.log(`Total de saques: ${result.total}`);

Filtrar por Sub-conta

javascript
async function getCustomerWithdraws(customerId) {
  const response = await fetch(
    `https://api.divipay.com.br/api/withdraws?customerId=${customerId}`,
    {
      headers: { 'Authorization': `Bearer ${token}` }
    }
  );

  const data = await response.json();
  return data.data;
}

// Uso
const withdraws = await getCustomerWithdraws('sub_abc123');
console.log(`${withdraws.length} saques encontrados`);

Filtrar por Status

javascript
async function getWithdrawsByStatus(status) {
  const response = await fetch(
    'https://api.divipay.com.br/api/withdraws',
    {
      headers: { 'Authorization': `Bearer ${token}` }
    }
  );

  const data = await response.json();
  
  return data.data.filter(w => w.status === status);
}

// Uso
const pending = await getWithdrawsByStatus('PENDING');
console.log(`${pending.length} saques pendentes`);

Calcular Total

javascript
async function getTotalWithdrawn(customerId) {
  const withdraws = await getCustomerWithdraws(customerId);
  
  const total = withdraws
    .filter(w => w.status === 'FINISHED')
    .reduce((sum, w) => sum + w.amount, 0);

  return total;
}

// Uso
const total = await getTotalWithdrawn('sub_abc123');
console.log(`Total sacado: R$ ${total.toFixed(2)}`);

Interface de Listagem

javascript
// React Component
function WithdrawsList({ customerId }) {
  const [withdraws, setWithdraws] = useState([]);
  const [loading, setLoading] = useState(true);
  const [page, setPage] = useState(1);

  useEffect(() => {
    loadWithdraws();
  }, [page]);

  async function loadWithdraws() {
    setLoading(true);
    try {
      const result = await listWithdraws(page, 20);
      setWithdraws(result.withdraws);
    } catch (error) {
      console.error('Erro ao carregar saques:', error);
    } finally {
      setLoading(false);
    }
  }

  function getStatusBadge(status) {
    const colors = {
      'PENDING': 'orange',
      'PROCESSING': 'blue',
      'FINISHED': 'green',
      'CANCELED': 'red'
    };

    return (
      <span style={{ 
        backgroundColor: colors[status], 
        color: 'white',
        padding: '4px 8px',
        borderRadius: '4px'
      }}>
        {status}
      </span>
    );
  }

  if (loading) return <div>Carregando...</div>;

  return (
    <div>
      <h2>Saques</h2>
      
      <table>
        <thead>
          <tr>
            <th>ID</th>
            <th>Valor</th>
            <th>Tipo</th>
            <th>Status</th>
            <th>Data</th>
          </tr>
        </thead>
        <tbody>
          {withdraws.map(withdraw => (
            <tr key={withdraw.id}>
              <td>{withdraw.id}</td>
              <td>R$ {withdraw.amount.toFixed(2)}</td>
              <td>{withdraw.type}</td>
              <td>{getStatusBadge(withdraw.status)}</td>
              <td>{new Date(withdraw.createdAt).toLocaleDateString()}</td>
            </tr>
          ))}
        </tbody>
      </table>

      <div>
        <button onClick={() => setPage(p => Math.max(1, p - 1))}>
          Anterior
        </button>
        <span>Página {page}</span>
        <button onClick={() => setPage(p => p + 1)}>
          Próxima
        </button>
      </div>
    </div>
  );
}

Exportar para CSV

javascript
function exportToCSV(withdraws) {
  const headers = ['ID', 'Valor', 'Tipo', 'Status', 'Data'];
  
  const rows = withdraws.map(w => [
    w.id,
    w.amount.toFixed(2),
    w.type,
    w.status,
    new Date(w.createdAt).toLocaleDateString()
  ]);

  const csv = [
    headers.join(','),
    ...rows.map(row => row.join(','))
  ].join('\n');

  const blob = new Blob([csv], { type: 'text/csv' });
  const url = URL.createObjectURL(blob);
  
  const a = document.createElement('a');
  a.href = url;
  a.download = 'saques.csv';
  a.click();
}

Próximos Passos

Documentação da API DiviPay