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

Add support for listing lines on an Invoice directly #808

Merged
merged 1 commit into from
Nov 19, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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));
}
}