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

AutoPagingIterator does not work with an invoice that has more than 10 line items that use tax rates #1422

Open
padre opened this issue Jan 12, 2023 · 6 comments
Assignees

Comments

@padre
Copy link

padre commented Jan 12, 2023

Describe the bug

#1400 (comment)

To Reproduce

$stripe = new \Stripe\StripeClient('stripe-secret');

$invoice = $stripe->invoices->retrieve('in_xxx', [
    'expand' => ['lines.data.tax_amounts.tax_rate'],
]);

foreach ($invoice->lines->autoPagingIterator() as $line) {
    foreach ($line->tax_amounts as $tax_amount) {
        $tax_rate = $tax_amount->tax_rate;
        echo $tax_rate->display_name . ' ' . $tax_rate->percentage . '%' . PHP_EOL;
    }
}

Expected behavior

All lines on an invoice should be expanded, but it'll fail with the following error:

Attempt to read property "display_name" on string

Code snippets

No response

OS

Ubuntu / Centos

PHP version

PHP 8.1

Library version

stripe/stripe-php v10.3.0

API version

2022-11-15

Additional context

No response

@pakrym-stripe
Copy link
Contributor

pakrym-stripe commented Jan 17, 2023

I'm sorry for the confusion, the service fix didn't cover all the cases we assumed. I'll work on getting this resolved.

@driesvints
Copy link

@pakrym-stripe can't we just merge my PR in the meantime?

@pakrym-stripe
Copy link
Contributor

I'm sorry @driesvints, while merging your PR will unblock this issue, the ability to change filter parameters is not a feature we'd like to support long-term on all collections.

Is it possible for you to use manual pagination as a temporary workaround?

@driesvints
Copy link

No worries. Unfortunately not as we just need to get all line items to display on the custom invoice.

@pakrym-stripe
Copy link
Contributor

You can get all items by manually iterating pages:


$invoice = $stripe->invoices->retrieve('in_....', [
    'expand' => ['lines.data.price.product'],
]);


$page = $invoice->lines;
while (true) {
    foreach ($page as $item) {
        echo($item["price"]);
    }
    $page = $page->nextPage([
        'expand' => ['data.price.product'],
    ]);

    if ($page->isEmpty()) {
        break;
    }
}

@driesvints
Copy link

@pakrym-stripe thank you for that example. I've sent this in for Cashier: laravel/cashier-stripe#1503

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

No branches or pull requests

4 participants