Skip to content

Commit 7404b2e

Browse files
authored
[DP-468] Retrieve Invoice endpoint (#11)
* [DP-468] Retrieve Invoice endpoint * Real UUID * Actually readme update * OK, added a commit hook
1 parent ce8a6ec commit 7404b2e

File tree

4 files changed

+74
-1
lines changed

4 files changed

+74
-1
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,7 @@ import chartmogul
188188
chartmogul.Invoice.create(config, uuid='cus_5915ee5a-babd-406b-b8ce-d207133fb4cb', data={})
189189
chartmogul.Invoice.all(config, uuid='cus_5915ee5a-babd-406b-b8ce-d207133fb4cb', page=2, per_page=10)
190190
chartmogul.Invoice.all(config, customer_uuid='cus_f466e33d-ff2b-4a11-8f85-417eb02157a7', external_id='INV0001')
191+
chartmogul.Invoice.retrieve(config, uuid='inv_22910fc6-c931-48e7-ac12-90d2cb5f0059')
191192
```
192193

193194
#### [Transactions](https://dev.chartmogul.com/docs/transactions)

chartmogul/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
"""
3030

3131
__title__ = 'chartmogul'
32-
__version__ = '1.1.3'
32+
__version__ = '1.1.4'
3333
__build__ = 0x000000
3434
__author__ = 'ChartMogul Ltd'
3535
__license__ = 'MIT'

chartmogul/api/invoice.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,3 +66,4 @@ def all(cls, config, **kwargs):
6666

6767
Invoice.all_any = Invoice._method('all', 'get', '/invoices')
6868
Invoice.destroy = Invoice._method('destroy', 'delete', '/invoices{/uuid}')
69+
Invoice.retrieve = Invoice._method('retrieve', 'get', '/invoices{/uuid}')

test/api/test_invoice.py

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,55 @@
204204
}
205205
"""
206206

207+
retrieveInvoiceExample = """
208+
{
209+
"uuid": "inv_22910fc6-c931-48e7-ac12-90d2cb5f0059",
210+
"external_id": "INV0001",
211+
"date": "2015-11-01T00:00:00.000Z",
212+
"due_date": "2015-11-15T00:00:00.000Z",
213+
"currency": "USD",
214+
"line_items": [
215+
{
216+
"uuid": "li_d72e6843-5793-41d0-bfdf-0269514c9c56",
217+
"external_id": null,
218+
"type": "subscription",
219+
"subscription_uuid": "sub_e6bc5407-e258-4de0-bb43-61faaf062035",
220+
"plan_uuid": "pl_eed05d54-75b4-431b-adb2-eb6b9e543206",
221+
"prorated": false,
222+
"service_period_start": "2015-11-01T00:00:00.000Z",
223+
"service_period_end": "2015-12-01T00:00:00.000Z",
224+
"amount_in_cents": 5000,
225+
"quantity": 1,
226+
"discount_code": "PSO86",
227+
"discount_amount_in_cents": 1000,
228+
"tax_amount_in_cents": 900,
229+
"account_code": null
230+
},
231+
{
232+
"uuid": "li_0cc8c112-beac-416d-af11-f35744ca4e83",
233+
"external_id": null,
234+
"type": "one_time",
235+
"description": "Setup Fees",
236+
"amount_in_cents": 2500,
237+
"quantity": 1,
238+
"discount_code": "PSO86",
239+
"discount_amount_in_cents": 500,
240+
"tax_amount_in_cents": 450,
241+
"account_code": null
242+
}
243+
],
244+
"transactions": [
245+
{
246+
"uuid": "tr_879d560a-1bec-41bb-986e-665e38a2f7bc",
247+
"external_id": null,
248+
"type": "payment",
249+
"date": "2015-11-05T00:14:23.000Z",
250+
"result": "successful"
251+
}
252+
]
253+
}
254+
"""
255+
207256
class InvoiceTestCase(unittest.TestCase):
208257
"""
209258
Tests most important Import API part and its nested schemas.
@@ -323,3 +372,25 @@ def test_delete_not_found(self, mock_requests):
323372
result = Invoice.destroy(config, uuid='inv_f466e33d-ff2b-4a11-8f85-417eb02157a7').get()
324373

325374
self.assertEqual(mock_requests.call_count, 1, "expected call")
375+
376+
@requests_mock.mock()
377+
def test_retrieve_invoice(self, mock_requests):
378+
379+
mock_requests.register_uri(
380+
'GET',
381+
("https://api.chartmogul.com/v1/invoices/inv_22910fc6-c931-48e7-ac12-90d2cb5f0059"),
382+
request_headers={'Authorization': 'Basic dG9rZW46c2VjcmV0'},
383+
headers={'Content-Type': 'application/json'},
384+
status_code=200,
385+
text=retrieveInvoiceExample
386+
)
387+
388+
config = Config("token", "secret") # is actually checked in mock
389+
result = Invoice.retrieve(config, uuid='inv_22910fc6-c931-48e7-ac12-90d2cb5f0059').get()
390+
391+
self.assertEqual(mock_requests.call_count, 1, "expected call")
392+
393+
# Struct too complex to do 1:1 comparison
394+
self.assertTrue(isinstance(result, Invoice))
395+
396+
self.assertEqual(result.uuid, 'inv_22910fc6-c931-48e7-ac12-90d2cb5f0059')

0 commit comments

Comments
 (0)