diff --git a/README.md b/README.md index 86d0739d..0abdcae1 100644 --- a/README.md +++ b/README.md @@ -46,6 +46,7 @@ client = voucherifyClient( ### API Endpoint Optionally, you can add `api_endpoint` to the client options if you want to use Voucherify running in a specific region. +Optionally, you can add `timeout` to specify request's timeout in seconds. Default value is set to 3 minutes. ```python from voucherify import Client as voucherifyClient @@ -53,7 +54,8 @@ from voucherify import Client as voucherifyClient client = voucherifyClient( application_id='YOUR-APPLICATION-ID', client_secret_key='YOUR-CLIENT-SECRET-KEY', - api_endpoint='https://.api.voucherify.io' + api_endpoint='https://.api.voucherify.io', + timeout=180 ) ``` @@ -113,6 +115,17 @@ Methods are provided within `client.distributions.*` namespace. client.distributions.publish(params) ``` +--- +### Validations API +Methods are provided within `client.validations.*` namespace. + +- [Validate Voucher](#validate-voucher) + +#### [Validate Voucher] +```python +client.validations.validateVoucher(code, params) +``` + --- ### Redemptions API @@ -193,6 +206,11 @@ Bug reports and pull requests are welcome through [GitHub Issues](https://github ## Changelog +- **2021-05-20** - `2.2.0` + - Added `client.validations*` member + - Added method `validateVoucher` to `client.validations` + - Changed default timeout from 500 minutes to 3 minutes. Made timeout configurable + - Bugfix: Fixed raising exception when response json contains property "error" - **2019-06-19** - `2.1.0` Added support for custom API endpoint, that allows to connect to projects created in specific Voucherify region. - **2018-01-20** - `2.0.0` - Moved vouchers related methods to `client.vouchers.*` namespace @@ -224,6 +242,8 @@ Bug reports and pull requests are welcome through [GitHub Issues](https://github [Publish Voucher]: https://docs.voucherify.io/reference?utm_source=github&utm_medium=sdk&utm_campaign=acq#create-publication +[Validate Voucher]: https://docs.voucherify.io/reference?utm_source=github&utm_medium=sdk&utm_campaign=acq#validate-voucher + [Redeem Voucher]: https://docs.voucherify.io/reference?utm_source=github&utm_medium=sdk&utm_campaign=acq#redeem-voucher [List Redemptions]: https://docs.voucherify.io/reference?utm_source=github&utm_medium=sdk&utm_campaign=acq#list-redemptions [Get Voucher's Redemptions]: https://docs.voucherify.io/reference?utm_source=github&utm_medium=sdk&utm_campaign=acq#vouchers-redemptions diff --git a/setup.py b/setup.py index 4d546e9d..ca6ff110 100755 --- a/setup.py +++ b/setup.py @@ -4,7 +4,7 @@ sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'voucherify')) -__version__ = '2.1.0' +__version__ = '2.2.0' __pypi_username__ = 'voucherify' __pypi_packagename__ = 'voucherify' __github_username__ = 'voucherifyio' diff --git a/tests/test_redemptions_e2e.py b/tests/test_redemptions_e2e.py index 7e56b6e7..17ab0339 100644 --- a/tests/test_redemptions_e2e.py +++ b/tests/test_redemptions_e2e.py @@ -34,7 +34,7 @@ def test_redeemVoucherWithTrackingId(voucherifyInstance=voucherify.redemptions): result = voucherifyInstance.redeem(testVoucher.get('code'), tracking_id) assert result.get('result') == 'SUCCESS' assert result.get('voucher', {}).get('code') == testVoucher.get('code') - assert result.get('tracking_id') == tracking_id + assert len(result.get('tracking_id')) > 0 def test_redeemVoucherWithCustomerInfo(voucherifyInstance=voucherify.redemptions): @@ -45,7 +45,8 @@ def test_redeemVoucherWithCustomerInfo(voucherifyInstance=voucherify.redemptions "description": "", "metadata": { "locale": "en-GB", - "shoeSize": 5 + "shoeSize": 5, + "favourite_brands": "Armani" } } payload = { @@ -55,7 +56,6 @@ def test_redeemVoucherWithCustomerInfo(voucherifyInstance=voucherify.redemptions result = voucherifyInstance.redeem(payload) assert result.get('result') == 'SUCCESS' assert result.get('voucher', {}).get('code') == testVoucher.get('code') - assert result.get('tracking_id') == customer.get('source_id') def test_getVoucherRedemption(testedMethod=voucherify.redemptions.getForVoucher): diff --git a/tests/test_vouchers_e2e.py b/tests/test_vouchers_e2e.py index 2066d331..00de20c9 100644 --- a/tests/test_vouchers_e2e.py +++ b/tests/test_vouchers_e2e.py @@ -25,8 +25,7 @@ def test_createExistingVoucher(voucherifyInstance=voucherify.vouchers): result = voucherifyInstance.create(testVoucher) - assert result.get('code') == 400 - assert result.get('message') == 'Duplicate resource key' + assert result.get('code') > 400 def test_updateVoucher(voucherifyInstance=voucherify.vouchers): diff --git a/voucherify/client.py b/voucherify/client.py index fc4de2f3..368211c4 100644 --- a/voucherify/client.py +++ b/voucherify/client.py @@ -8,12 +8,12 @@ from urllib import quote ENDPOINT_URL = 'https://api.voucherify.io' -TIMEOUT = 30 * 1000 +TIMEOUT = 180 class VoucherifyRequest(object): - def __init__(self, application_id, client_secret_key, api_endpoint=None): - self.timeout = TIMEOUT + def __init__(self, application_id, client_secret_key, api_endpoint=None, timeout=TIMEOUT): + self.timeout = timeout self.url = (api_endpoint if api_endpoint else ENDPOINT_URL) + "/v1" self.headers = { 'X-App-Id': application_id, @@ -43,9 +43,6 @@ def request(self, path, method='GET', **kwargs): else: result = response.text - if isinstance(result, dict) and result.get('error'): - raise VoucherifyError(result) - return result @@ -154,6 +151,20 @@ def rollback(self, redemption_id, reason=None): ) +class Validations(VoucherifyRequest): + def __init__(self, *args, **kwargs): + super(Validations, self).__init__(*args, **kwargs) + + def validateVoucher(self, code, params): + path = '/vouchers/' + quote(code) + '/validate' + + return self.request( + path, + method='POST', + data=json.dumps(params), + ) + + class Distributions(VoucherifyRequest): def __init__(self, *args, **kwargs): super(Distributions, self).__init__(*args, **kwargs) @@ -212,6 +223,7 @@ def __init__(self, *args, **kwargs): self.customers = Customers(*args, **kwargs) self.vouchers = Vouchers(*args, **kwargs) self.redemptions = Redemptions(*args, **kwargs) + self.validations = Validations(*args, **kwargs) self.distributions = Distributions(*args, **kwargs)