diff --git a/omise/__init__.py b/omise/__init__.py index 93bf31c..eaed5db 100644 --- a/omise/__init__.py +++ b/omise/__init__.py @@ -815,12 +815,19 @@ def refund(self, **kwargs): return refund def list_refunds(self): - """Return all refund that belongs to the charge + """Return all refunds that belong to the charge :rtype: LazyCollection """ return LazyCollection(self._nested_object_path(Refund)) + def list_events(self): + """Return all events that belong to the charge + + :rtype: LazyCollection + """ + return LazyCollection(self._nested_object_path(Event)) + @classmethod def schedule(cls): """Retrieve all charge schedules. diff --git a/omise/test/test_charge.py b/omise/test/test_charge.py index 31f3758..2c74476 100644 --- a/omise/test/test_charge.py +++ b/omise/test/test_charge.py @@ -22,6 +22,10 @@ def _getCollectionClass(self): from .. import Collection return Collection + def _getLazyCollectionClass(self): + from .. import LazyCollection + return LazyCollection + def _makeOne(self): return self._getTargetClass().from_data({ 'card': { @@ -851,3 +855,51 @@ def test_schedule(self, api_call): self.assertEqual(schedules[0].start_date, '2017-06-02') self.assertEqual(schedules[0].end_date, '2018-05-01') self.assertRequest(api_call, 'https://api.omise.co/charges/schedules') + + @mock.patch('requests.get') + def test_list_events(self, api_call): + charge = self._makeOne() + lazy_collection_class_ = self._getLazyCollectionClass() + self.mockResponse(api_call, """{ + "object": "list", + "data": [ + { + "object": "event", + "id": "evnt_test", + "livemode": false, + "location": "/events/evnt_test", + "webhook_deliveries": [ + { + "object": "webhook_delivery", + "id": "whdl_test", + "uri": "https://www.omise.co", + "status": 200 + } + ], + "data": [ + { + "object": "charge", + "id": "chrg_test", + "location": "/charges/chrg_test", + "amount": 100000 + } + ], + "key": "charge.create", + "created_at": "2021-01-29T02:05:20Z" + } + ], + "limit": 20, + "offset": 0, + "total": 2, + "location": null, + "order": "chronological", + "from": "1970-01-01T00:00:00Z", + "to": "2021-02-02T03:16:57Z" + }""") + + events = charge.list_events() + self.assertTrue(isinstance(events, lazy_collection_class_)) + + events = list(events) + self.assertTrue(events[0].id, 'evnt_test') + self.assertTrue(events[0].key, 'charge.create') \ No newline at end of file