From 8d8976aed7419fb8bb3fda355f9a0c5590ea4f31 Mon Sep 17 00:00:00 2001 From: Remi Jannel Date: Tue, 19 Nov 2019 14:46:03 -0800 Subject: [PATCH] Add support for listing lines on an Invoice directly --- lib/Invoice.php | 17 +++++++++++++++++ tests/Stripe/InvoiceTest.php | 11 +++++++++++ 2 files changed, 28 insertions(+) diff --git a/lib/Invoice.php b/lib/Invoice.php index 59b7749fa..a5427d445 100644 --- a/lib/Invoice.php +++ b/lib/Invoice.php @@ -76,6 +76,7 @@ class Invoice extends ApiResource use ApiOperations\Delete; use ApiOperations\Retrieve; use ApiOperations\Update; + use ApiOperations\NestedResource; /** * Possible string representations of the billing reason. @@ -114,6 +115,8 @@ class Invoice extends ApiResource const BILLING_CHARGE_AUTOMATICALLY = 'charge_automatically'; const BILLING_SEND_INVOICE = 'send_invoice'; + const PATH_LINES = '/lines'; + /** * @param array|null $params * @param array|string|null $opts @@ -210,4 +213,18 @@ public function voidInvoice($params = null, $opts = null) $this->refreshFrom($response, $opts); return $this; } + + /** + * @param string $id The ID of the invoice on which to retrieve the lins. + * @param array|null $params + * @param array|string|null $opts + * + * @throws \Stripe\Exception\ApiErrorException if the request fails + * + * @return Collection The list of lines (InvoiceLineItem). + */ + public static function allLines($id, $params = null, $opts = null) + { + return self::_allNestedResources($id, static::PATH_LINES, $params, $opts); + } } diff --git a/tests/Stripe/InvoiceTest.php b/tests/Stripe/InvoiceTest.php index 36c28012e..2f177f957 100644 --- a/tests/Stripe/InvoiceTest.php +++ b/tests/Stripe/InvoiceTest.php @@ -5,6 +5,7 @@ class InvoiceTest extends TestCase { const TEST_RESOURCE_ID = 'in_123'; + const TEST_LINE_ID = 'ii_123'; public function testIsListable() { @@ -143,4 +144,14 @@ public function testCanVoidInvoice() $this->assertInstanceOf(\Stripe\Invoice::class, $resource); $this->assertSame($resource, $invoice); } + + public function testCanListLines() + { + $this->expectsRequest( + 'get', + '/v1/invoices/' . self::TEST_RESOURCE_ID . '/lines' + ); + $resources = Invoice::allLines(self::TEST_RESOURCE_ID); + $this->assertTrue(is_array($resources->data)); + } }