diff --git a/omise/__init__.py b/omise/__init__.py index 203ff26..6d36f49 100644 --- a/omise/__init__.py +++ b/omise/__init__.py @@ -252,6 +252,34 @@ def reload(self): """ return self._reload_data(self._request('get', self._instance_path())) + def update(self, **kwargs): + """Update account settings with the given arguments. + + See the `update an account`_ section in the API documentation for list + of available arguments. + + Basic usage:: + + >>> import omise + >>> omise.api_secret = 'skey_test_4xs8breq3htbkj03d2x' + >>> account = omise.Account.retrieve() + >>> account.update(webhook_uri='https://omise-flask-example.herokuapp.com/webhook') + + + :param \*\*kwargs: arguments to update an account. + :rtype: Account + + .. _update an account: + .. https://www.omise.co/account-api#update + """ + + changed = copy.deepcopy(self.changes) + changed.update(kwargs) + return self._reload_data( + self._request('patch', + self._attributes['location'], + changed)) + class Balance(_MainResource, Base): """API class representing balance details. diff --git a/omise/test/test_account.py b/omise/test/test_account.py index 33da0d1..da83b73 100644 --- a/omise/test/test_account.py +++ b/omise/test/test_account.py @@ -10,6 +10,16 @@ def _getTargetClass(self): from .. import Account return Account + def _makeOne(self): + return self._getTargetClass().from_data({ + "object": "account", + "location": "/account", + "id": "acct_test", + "email": None, + "created": "2014-10-20T08:21:42Z", + "chain_enabled": False + }) + @mock.patch('requests.get') def test_retrieve(self, api_call): class_ = self._getTargetClass() @@ -36,3 +46,57 @@ def test_retrieve(self, api_call): account.reload() self.assertEqual(account.id, 'acct_foo') self.assertRequest(api_call, 'https://api.omise.co/account') + + + @mock.patch('requests.patch') + def test_update(self, api_call): + account = self._makeOne() + class_ = self._getTargetClass() + self.mockResponse(api_call, """{ + "object": "account", + "id": "account_test_no1t4tnemucod0e51mo", + "team": "acct_no1t4tnemucod0e51mo", + "livemode": false, + "location": "/account", + "country": "TH", + "currency": "THB", + "email": "somchai.prasert@example.com", + "created_at": "2019-12-31T12:59:59Z", + "supported_currencies": [ + "THB", + "JPY", + "USD", + "EUR", + "GBP", + "SGD", + "AUD", + "CHF", + "CNY", + "DKK", + "HKD" + ], + "api_version": "2019-05-29", + "auto_activate_recipients": true, + "chain_enabled": true, + "zero_interest_installments": true, + "chain_return_uri": "https://omise-flask-example.herokuapp.com", + "webhook_uri": "https://omise-flask-example.herokuapp.com/webhook", + "metadata_export_keys": { + "charge": [ + "color", + "order_id" + ] + } + }""") + + self.assertTrue(isinstance(account, class_)) + self.assertFalse(account.chain_enabled) + account.update(chain_enabled=True) + self.assertTrue(account.chain_enabled) + self.assertRequest( + api_call, + 'https://api.omise.co/account', + { + 'chain_enabled': True, + } + )