Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions omise/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
<Account id='account_test_5kms3d70v77fs5c37v6' at 0x108cec240>

: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.
Expand Down
64 changes: 64 additions & 0 deletions omise/test/test_account.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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,
}
)