Skip to content

Commit

Permalink
Merge pull request #808 from stripe/remi-add-invoicice-lins
Browse files Browse the repository at this point in the history
Add support for listing lines on an Invoice directly
  • Loading branch information
remi-stripe authored Nov 19, 2019
2 parents 0e24d89 + 8d8976a commit 416d1d7
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
17 changes: 17 additions & 0 deletions lib/Invoice.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
}
}
11 changes: 11 additions & 0 deletions tests/Stripe/InvoiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
class InvoiceTest extends TestCase
{
const TEST_RESOURCE_ID = 'in_123';
const TEST_LINE_ID = 'ii_123';

public function testIsListable()
{
Expand Down Expand Up @@ -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));
}
}

0 comments on commit 416d1d7

Please sign in to comment.