<?php
// Conciliar as cobranças pagas
// Explicação: https://xflowpayments.com/blog/api-pix-php/
require __DIR__ . '/xflow.php';

function cobrancasPagas(string $de, string $ate): Generator
{
    $cursor = null;
    do {
        $query = http_build_query(array_filter([
            'status' => 'paid', 'from' => $de, 'to' => $ate, 'limit' => 100, 'starting_after' => $cursor,
        ]));
        $pagina = xflow('GET', '/charges?' . $query);
        yield from $pagina['data'];
        $cursor = end($pagina['data'])['id'] ?? null;
    } while ($pagina['has_more'] && $cursor !== null);
}

foreach (cobrancasPagas('2026-10-01', '2026-10-31') as $c) {
    echo $c['external_reference'] . ' ' . $c['amountCents'] . PHP_EOL;
}
