Skip to content

Commit

Permalink
[DP-468] Retrieve Invoice endpoint (#29)
Browse files Browse the repository at this point in the history
  • Loading branch information
pkopac authored May 29, 2017
1 parent 83643a1 commit 289adad
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 1 deletion.
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ $ds = ChartMogul\DataSource::create([
]);
```

**Get a Datasource by UUID**
**Get a Datasource**

```php
ChartMogul\DataSource::retrieve($uuid);
Expand Down Expand Up @@ -398,6 +398,12 @@ $invoices = ChartMogul\Invoice::all([
]);
```

**Retrieve an Invoice**

```php
$invoice = ChartMogul\Invoice::retrieve('inv_uuid');
```

### Transactions

**Create a Transaction**
Expand Down
3 changes: 3 additions & 0 deletions src/Invoice.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use ChartMogul\LineItems\Subscription as SubsItem;
use ChartMogul\Service\AllTrait;
use ChartMogul\Service\DestroyTrait;
use ChartMogul\Service\GetTrait;
use ChartMogul\Resource\AbstractResource;
use ChartMogul\Transactions\AbstractTransaction;
use ChartMogul\Transactions\Payment;
Expand All @@ -21,6 +22,8 @@ class Invoice extends AbstractResource
{
use AllTrait;
use DestroyTrait;
use GetTrait;

/**
* @ignore
*/
Expand Down
69 changes: 69 additions & 0 deletions tests/Unit/InvoiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,53 @@ class InvoiceTest extends PHPUnit_Framework_TestCase
"total_pages": 3
}';

const RETRIEVE_INVOICE_JSON = '{
"uuid": "inv_565c73b2-85b9-49c9-a25e-2b7df6a677c9",
"external_id": "INV0001",
"date": "2015-11-01T00:00:00.000Z",
"due_date": "2015-11-15T00:00:00.000Z",
"currency": "USD",
"line_items": [
{
"uuid": "li_d72e6843-5793-41d0-bfdf-0269514c9c56",
"external_id": null,
"type": "subscription",
"subscription_uuid": "sub_e6bc5407-e258-4de0-bb43-61faaf062035",
"plan_uuid": "pl_eed05d54-75b4-431b-adb2-eb6b9e543206",
"prorated": false,
"service_period_start": "2015-11-01T00:00:00.000Z",
"service_period_end": "2015-12-01T00:00:00.000Z",
"amount_in_cents": 5000,
"quantity": 1,
"discount_code": "PSO86",
"discount_amount_in_cents": 1000,
"tax_amount_in_cents": 900,
"account_code": null
},
{
"uuid": "li_0cc8c112-beac-416d-af11-f35744ca4e83",
"external_id": null,
"type": "one_time",
"description": "Setup Fees",
"amount_in_cents": 2500,
"quantity": 1,
"discount_code": "PSO86",
"discount_amount_in_cents": 500,
"tax_amount_in_cents": 450,
"account_code": null
}
],
"transactions": [
{
"uuid": "tr_879d560a-1bec-41bb-986e-665e38a2f7bc",
"external_id": null,
"type": "payment",
"date": "2015-11-05T00:14:23.000Z",
"result": "successful"
}
]
}';

public function testAllInvoices()
{
$stream = Psr7\stream_for(InvoiceTest::ALL_INVOICE_JSON);
Expand Down Expand Up @@ -114,4 +161,26 @@ public function testDestroyInvoiceNotFound()
$cmClient = new Client(null, $mockClient);
$result = (new Invoice(["uuid" => "inv_123"], $cmClient))->destroy();
}

public function testRetrieveInvoice()
{
$stream = Psr7\stream_for(InvoiceTest::RETRIEVE_INVOICE_JSON);
$response = new Response(200, ['Content-Type' => 'application/json'], $stream);
$mockClient = new \Http\Mock\Client();
$mockClient->addResponse($response);

$uuid = 'inv_565c73b2-85b9-49c9-a25e-2b7df6a677c9';

$cmClient = new Client(null, $mockClient);
$result = Invoice::retrieve($uuid, $cmClient);
$request = $mockClient->getRequests()[0];

$this->assertEquals("GET", $request->getMethod());
$uri = $request->getUri();
$this->assertEquals("", $uri->getQuery());
$this->assertEquals("/v1/invoices/".$uuid, $uri->getPath());

$this->assertTrue($result instanceof Invoice);
$this->assertEquals($uuid, $result->uuid);
}
}

0 comments on commit 289adad

Please sign in to comment.