Skip to content

Commit

Permalink
[14.x] Fix invoice line items (#1503)
Browse files Browse the repository at this point in the history
* Fix invoice line items

* Apply fixes from StyleCI

---------

Co-authored-by: StyleCI Bot <[email protected]>
  • Loading branch information
driesvints and StyleCIBot authored Feb 21, 2023
1 parent fcdbfb5 commit c7aa0c1
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions src/Invoice.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
use Laravel\Cashier\Exceptions\InvalidInvoice;
use Stripe\Customer as StripeCustomer;
use Stripe\Invoice as StripeInvoice;
use Stripe\InvoiceLineItem as StripeInvoiceLineItem;
use Symfony\Component\HttpFoundation\Response;

class Invoice implements Arrayable, Jsonable, JsonSerializable
Expand Down Expand Up @@ -498,10 +497,25 @@ public function invoiceLineItems()

$this->refreshWithExpandedData();

return $this->items = Collection::make($this->invoice->lines->autoPagingIterator())
->map(function (StripeInvoiceLineItem $item) {
return new InvoiceLineItem($this, $item);
})->all();
$page = $this->invoice->lines;

$items = Collection::make();

while (true) {
foreach ($page as $item) {
$items->push(new InvoiceLineItem($this, $item));
}

$page = $page->nextPage([
'expand' => ['data.tax_amounts.tax_rate'],
]);

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

return $this->items = $items->reverse()->all();
}

/**
Expand Down

0 comments on commit c7aa0c1

Please sign in to comment.