Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Could it be that autoPagingIterator is losing initial params? #1055

Closed
tishma opened this issue Dec 2, 2020 · 7 comments
Closed

Could it be that autoPagingIterator is losing initial params? #1055

tishma opened this issue Dec 2, 2020 · 7 comments
Assignees

Comments

@tishma
Copy link

tishma commented Dec 2, 2020

In effect - I'm collecting all invoices for a customer, and since my customer has more than 1 (10-item) page worth of invoices - subsequent requests seem to be collecting other customers' invoices as well, as long as they match starting_after condition. If I increase limit to capture all invoices in a single request - I'm only getting single customer's invoices - as expected.

I have a reason to believe that in this setup - subsequent requests made thru autoPagingIterator are not keeping the parameters. If that's intended - I'd really appreciate the hint on how to achieve the above.

$invoices = $stripeClient->invoices->all(['customer' => $this->stripeCustomer->id, 'expand' => ['data.charge', 'data.subscription']]);
foreach ($invoices->autoPagingIterator() as $invoice) {
               ....

php-stripe version: 7.333
php version: 7.4.11

@tishma tishma changed the title Could it be that autoPagingIterator losing initial params? Could it be that autoPagingIterator is losing initial params? Dec 3, 2020
@remi-stripe remi-stripe self-assigned this Dec 3, 2020
@remi-stripe
Copy link
Contributor

@tishma Thanks for reaching out! I tried to reproduce locally but the code is working properly for me. Here's what I'm doing:

$invoices = $stripe->invoices->all([
  'customer' => 'cus_12345',
  'limit' => 1,
]);

foreach ($invoices->autoPagingIterator() as $invoice) {
    echo "Invoice id: '" . $invoice->id . "' - Customer id: '" . $invoice->customer . "'<br>";
}

When I run that code, I get one invoice per page and I'm properly paginating through all the invoices of my customer and only that one.

Would you be able to try something similar on your end with the right customer id to confirm you're seeing the same thing?

@tishma
Copy link
Author

tishma commented Dec 3, 2020

Hey, thanks for the response. I have collected 2 pieces of evidence using your method (limit - 1, so each invoice comes from a separate request). I only have 2 customers (A and B), so I'm virtually dumping all invoices I've got in my test. Customer B has just 2 invoices, and one is the oldest one while the other is the 5th recent.

  1. I'm looping through all invoices for either of the customers (most recent coming first - by default), and the conclusion is that customer A pretty much shows all invoices (being the owner of the most recent one), while customer B starts with her most recent invoice and again - picks all the remaining ones. Here is the output - left hand customer id is from the invoice returned from the API, and right hand one was used to initiate the query.
cus_IOBi5peXpo8Nz9---cus_IOBi5peXpo8Nz9
cus_IOBi5peXpo8Nz9---cus_IOBi5peXpo8Nz9
cus_IOBi5peXpo8Nz9---cus_IOBi5peXpo8Nz9
cus_IOBi5peXpo8Nz9---cus_IOBi5peXpo8Nz9
cus_INWUfMGGTDBTOa---cus_IOBi5peXpo8Nz9
cus_IOBi5peXpo8Nz9---cus_IOBi5peXpo8Nz9
cus_IOBi5peXpo8Nz9---cus_IOBi5peXpo8Nz9
cus_IOBi5peXpo8Nz9---cus_IOBi5peXpo8Nz9
cus_IOBi5peXpo8Nz9---cus_IOBi5peXpo8Nz9
cus_IOBi5peXpo8Nz9---cus_IOBi5peXpo8Nz9
cus_IOBi5peXpo8Nz9---cus_IOBi5peXpo8Nz9
cus_IOBi5peXpo8Nz9---cus_IOBi5peXpo8Nz9
cus_IOBi5peXpo8Nz9---cus_IOBi5peXpo8Nz9
cus_IOBi5peXpo8Nz9---cus_IOBi5peXpo8Nz9
cus_IOBi5peXpo8Nz9---cus_IOBi5peXpo8Nz9
cus_IOBi5peXpo8Nz9---cus_IOBi5peXpo8Nz9
cus_IOBi5peXpo8Nz9---cus_IOBi5peXpo8Nz9
cus_IOBi5peXpo8Nz9---cus_IOBi5peXpo8Nz9
cus_IOBi5peXpo8Nz9---cus_IOBi5peXpo8Nz9
cus_IOBi5peXpo8Nz9---cus_IOBi5peXpo8Nz9
cus_IOBi5peXpo8Nz9---cus_IOBi5peXpo8Nz9
cus_IOBi5peXpo8Nz9---cus_IOBi5peXpo8Nz9
cus_IOBi5peXpo8Nz9---cus_IOBi5peXpo8Nz9
cus_IOBi5peXpo8Nz9---cus_IOBi5peXpo8Nz9
cus_IOBi5peXpo8Nz9---cus_IOBi5peXpo8Nz9
cus_IOBi5peXpo8Nz9---cus_IOBi5peXpo8Nz9
cus_IOBi5peXpo8Nz9---cus_IOBi5peXpo8Nz9
cus_IOBi5peXpo8Nz9---cus_IOBi5peXpo8Nz9
cus_IOBi5peXpo8Nz9---cus_IOBi5peXpo8Nz9
cus_IOBi5peXpo8Nz9---cus_IOBi5peXpo8Nz9
cus_IOBi5peXpo8Nz9---cus_IOBi5peXpo8Nz9
cus_IOBi5peXpo8Nz9---cus_IOBi5peXpo8Nz9
cus_INWUfMGGTDBTOa---cus_IOBi5peXpo8Nz9
cus_INWUfMGGTDBTOa---cus_INWUfMGGTDBTOa
cus_IOBi5peXpo8Nz9---cus_INWUfMGGTDBTOa
cus_IOBi5peXpo8Nz9---cus_INWUfMGGTDBTOa
cus_IOBi5peXpo8Nz9---cus_INWUfMGGTDBTOa
cus_IOBi5peXpo8Nz9---cus_INWUfMGGTDBTOa
cus_IOBi5peXpo8Nz9---cus_INWUfMGGTDBTOa
cus_IOBi5peXpo8Nz9---cus_INWUfMGGTDBTOa
cus_IOBi5peXpo8Nz9---cus_INWUfMGGTDBTOa
cus_IOBi5peXpo8Nz9---cus_INWUfMGGTDBTOa
cus_IOBi5peXpo8Nz9---cus_INWUfMGGTDBTOa
cus_IOBi5peXpo8Nz9---cus_INWUfMGGTDBTOa
cus_IOBi5peXpo8Nz9---cus_INWUfMGGTDBTOa
cus_IOBi5peXpo8Nz9---cus_INWUfMGGTDBTOa
cus_IOBi5peXpo8Nz9---cus_INWUfMGGTDBTOa
cus_IOBi5peXpo8Nz9---cus_INWUfMGGTDBTOa
cus_IOBi5peXpo8Nz9---cus_INWUfMGGTDBTOa
cus_IOBi5peXpo8Nz9---cus_INWUfMGGTDBTOa
cus_IOBi5peXpo8Nz9---cus_INWUfMGGTDBTOa
cus_IOBi5peXpo8Nz9---cus_INWUfMGGTDBTOa
cus_IOBi5peXpo8Nz9---cus_INWUfMGGTDBTOa
cus_IOBi5peXpo8Nz9---cus_INWUfMGGTDBTOa
cus_IOBi5peXpo8Nz9---cus_INWUfMGGTDBTOa
cus_IOBi5peXpo8Nz9---cus_INWUfMGGTDBTOa
cus_IOBi5peXpo8Nz9---cus_INWUfMGGTDBTOa
cus_IOBi5peXpo8Nz9---cus_INWUfMGGTDBTOa
cus_IOBi5peXpo8Nz9---cus_INWUfMGGTDBTOa
cus_IOBi5peXpo8Nz9---cus_INWUfMGGTDBTOa
cus_IOBi5peXpo8Nz9---cus_INWUfMGGTDBTOa
cus_INWUfMGGTDBTOa---cus_INWUfMGGTDBTOa
  1. My other evidence is that data.charge only expanded on the first iteration, and only shows charge id onwards. I didn't bother to check if subscription expands though.

Screenshot 2020-12-03 at 22 36 43

Screenshot 2020-12-03 at 22 37 26

        $invoices = $stripeClient->invoices->all(['customer' => $this->stripeCustomer->id, 'limit' => 1, 'expand' => ['data.charge', 'data.subscription']]);
        /** @var Invoice $invoice */
        foreach ($invoices->autoPagingIterator() as $invoice) {
            echo $invoice->customer, '---',  $this->stripeCustomer->id, '<br>';

@remi-stripe
Copy link
Contributor

@tishma okay the issue is that you are on an older version of stripe-php that had the bug which we fixed back in May in #942 which was released in 7.36.1. If you upgrade to that version (or rather the latest), it will fix the problem

@tishma
Copy link
Author

tishma commented Dec 3, 2020

Okay, trying.
However, my version was 7.62 which is documented to be less than a month old...
- Updating stripe/stripe-php (v7.62.0 => v7.66.1)

@tishma
Copy link
Author

tishma commented Dec 3, 2020

But it sure is fixed now!

cus_IOBi5peXpo8Nz9---cus_IOBi5peXpo8Nz9
cus_IOBi5peXpo8Nz9---cus_IOBi5peXpo8Nz9
cus_IOBi5peXpo8Nz9---cus_IOBi5peXpo8Nz9
cus_IOBi5peXpo8Nz9---cus_IOBi5peXpo8Nz9
cus_IOBi5peXpo8Nz9---cus_IOBi5peXpo8Nz9
cus_IOBi5peXpo8Nz9---cus_IOBi5peXpo8Nz9
cus_IOBi5peXpo8Nz9---cus_IOBi5peXpo8Nz9
cus_IOBi5peXpo8Nz9---cus_IOBi5peXpo8Nz9
cus_IOBi5peXpo8Nz9---cus_IOBi5peXpo8Nz9
cus_IOBi5peXpo8Nz9---cus_IOBi5peXpo8Nz9
cus_IOBi5peXpo8Nz9---cus_IOBi5peXpo8Nz9
cus_IOBi5peXpo8Nz9---cus_IOBi5peXpo8Nz9
cus_IOBi5peXpo8Nz9---cus_IOBi5peXpo8Nz9
cus_IOBi5peXpo8Nz9---cus_IOBi5peXpo8Nz9
cus_IOBi5peXpo8Nz9---cus_IOBi5peXpo8Nz9
cus_IOBi5peXpo8Nz9---cus_IOBi5peXpo8Nz9
cus_IOBi5peXpo8Nz9---cus_IOBi5peXpo8Nz9
cus_IOBi5peXpo8Nz9---cus_IOBi5peXpo8Nz9
cus_IOBi5peXpo8Nz9---cus_IOBi5peXpo8Nz9
cus_IOBi5peXpo8Nz9---cus_IOBi5peXpo8Nz9
cus_IOBi5peXpo8Nz9---cus_IOBi5peXpo8Nz9
cus_IOBi5peXpo8Nz9---cus_IOBi5peXpo8Nz9
cus_IOBi5peXpo8Nz9---cus_IOBi5peXpo8Nz9
cus_IOBi5peXpo8Nz9---cus_IOBi5peXpo8Nz9
cus_IOBi5peXpo8Nz9---cus_IOBi5peXpo8Nz9
cus_IOBi5peXpo8Nz9---cus_IOBi5peXpo8Nz9
cus_IOBi5peXpo8Nz9---cus_IOBi5peXpo8Nz9
cus_IOBi5peXpo8Nz9---cus_IOBi5peXpo8Nz9
cus_IOBi5peXpo8Nz9---cus_IOBi5peXpo8Nz9
cus_IOBi5peXpo8Nz9---cus_IOBi5peXpo8Nz9
cus_IOBi5peXpo8Nz9---cus_IOBi5peXpo8Nz9
cus_IOBi5peXpo8Nz9---cus_IOBi5peXpo8Nz9
cus_IOBi5peXpo8Nz9---cus_IOBi5peXpo8Nz9
cus_INWUfMGGTDBTOa---cus_INWUfMGGTDBTOa
cus_INWUfMGGTDBTOa---cus_INWUfMGGTDBTOa

@tishma
Copy link
Author

tishma commented Dec 3, 2020

I'm still gonna go for the max limit in order not to throw so many requests at the API, but this is not going to be another thing to keep me awake at night :) Thank you! @remi-stripe

@remi-stripe
Copy link
Contributor

Awesome, glad you got unblocked!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants