Stripe : list all charges with PHP

I tried to list all charges of my Stripe account to get a list of the statement_descriptor (my products) but I there is an error which says cannot find charge…

<?php
$off = 0;
$has_more = True;
$listeProducts = array();
ini_set('max_execution_time', 2000);
while($has_more){
    $req = /Stripe/Charge::all(array("limit" => 100, "starting_after" => $off));
    $res = json_decode($req->__toJSON(), true);

    foreach($res["data"] as &$prodUni){
        array_push($listeProducts, $prodUni["statement_descriptor"]);
    }

    $has_more = $res["has_more"];
    $off += 100;
}
$_SESSION["products"] = $listeProducts;

Here is the error message :

Fatal error: Uncaught exception 'Stripe/Error/InvalidRequest' with message 'No such charge: 0' in C:/wamp64/www/.../stripe-php-5.1.3/lib/ApiRequestor.php:124 from API request '...' in C:/wamp64/www/.../stripe-php-5.1.3/lib/ApiRequestor.php on line 124

I cant put “offset” because deprecated and it does same thing with ending before.

The issue is that I put 0 but charge ID is required…. I don’t want to put charge ID there… I need to do like if I had offset



starting_after takes an object – ideally the last object in the previous fetched result.

See https://stripe.com/docs/api?lang=php#list_charges-starting_after

Fist part of answer to the question is getting the first 100 before you check for has_more.

But after that, I cannt retrieve the first charge, dont forget that when we retrieve with Stripe API the list is in the REVERSE ORDER !!! So I have to get the last or the firt ?? How can I correct my code pease ?
And is this line correct ? $lastId = $res[“data”][“99”][“id”];