diff --git a/omise/__init__.py b/omise/__init__.py index 93bf31c..fa12c63 100644 --- a/omise/__init__.py +++ b/omise/__init__.py @@ -1207,6 +1207,26 @@ def update(self, **kwargs): self._instance_path(self._attributes['id']), changed)) + def accept(self): + """Accept the dispute. + + Basic usage:: + + >>> import omise + >>> omise.api_secret = 'skey_test_4xs8breq3htbkj03d2x' + >>> dspt = omise.Dispute.retrieve('dspt_test_5mr57xawhq7j28az3ak') + >>> dspt.status + 'open' + >>> dspt.accept() + + >>> dspt.status + 'lost' + + :rtype: Dispute + """ + path = self._instance_path(self._attributes['id']) + ('accept',) + return self._reload_data(self._request('patch', path)) + class Event(_MainResource, Base): """API class representing an event in an account. diff --git a/omise/test/test_dispute.py b/omise/test/test_dispute.py index 3d79e01..e4174a8 100644 --- a/omise/test/test_dispute.py +++ b/omise/test/test_dispute.py @@ -22,7 +22,7 @@ def _makeOne(self): 'location': '/disputes/dspt_test', 'amount': 100000, 'currency': 'thb', - 'status': 'pending', + 'status': 'open', 'message': None, 'charge': 'chrg_test', 'created': '2015-03-23T05:24:39Z' @@ -169,3 +169,24 @@ def test_update(self, api_call): 'https://api.omise.co/disputes/dspt_test', {'message': 'Foobar Baz'} ) + + @mock.patch('requests.patch') + def test_accept(self, api_call): + dispute = self._makeOne() + class_ = self._getTargetClass() + self.mockResponse(api_call, """{ + "object": "dispute", + "id": "dspt_test", + "livemode": false, + "status": "lost" + }""") + + self.assertTrue(isinstance(dispute, class_)) + self.assertEqual(dispute.status, 'open') + + dispute.accept() + self.assertEqual(dispute.status, 'lost') + self.assertRequest( + api_call, + 'https://api.omise.co/disputes/dspt_test/accept' + ) \ No newline at end of file