From 9495e6c2f01c8d001479381e438131f2cf4da925 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Wiktor?= Date: Fri, 2 Dec 2016 09:54:11 +0100 Subject: [PATCH] utils - support gift vouchers --- README.md | 11 +++++++---- setup.py | 2 +- voucherify/utils.py | 12 ++++++++++-- 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 812d7a33..46867259 100644 --- a/README.md +++ b/README.md @@ -83,7 +83,9 @@ Result: "category": "API Test", "type": "GIFT_VOUCHER", "gift": { - "amount": 5000 + "amount": 10000, + "balance": 5000 + }, "start_date": "2016-03-01T10:00:00Z", "expiration_date": null, @@ -544,9 +546,9 @@ voucherify.redeem({ ##### 5. With order amount -Redeeming a gift voucher requires to pass an amount that you wish to withdraw from the voucher. -The same applies to vouchers with validation rules on order's total amount. -Order amount have to be expressed in cents, as an integer. For example $22.50 should be provided as 2250: +Redeeming a gift voucher requires passing order amount. The same applies to vouchers with validation rules on order's total amount. +Order amount have to be expressed in cents, as an integer. For example $22.50 should be provided as 2250. +Gift voucher balance will be used to cover the order amount entirely or partially. ```python voucherify.redeem({ @@ -819,6 +821,7 @@ new_price = utils.calculate_price(base_price, voucher, unit_price) ### Changelog +- **2016-12-02** - `1.4.1` - Support gift vouchers in utils - **2016-07-18** - `1.4.0` - Voucher code pattern - **2016-07-18** - `1.3.0` - Update voucher - **2016-06-23** - `1.2.1` - Gift vouchers diff --git a/setup.py b/setup.py index 1400853e..f7c16093 100755 --- a/setup.py +++ b/setup.py @@ -4,7 +4,7 @@ sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'voucherify')) -__version__ = '1.4.0' +__version__ = '1.4.1' __pypi_username__ = 'voucherify' __pypi_packagename__ = 'voucherify' __github_username__ = 'voucherifyio' diff --git a/voucherify/utils.py b/voucherify/utils.py index bbb7e226..459da083 100644 --- a/voucherify/utils.py +++ b/voucherify/utils.py @@ -21,7 +21,11 @@ def validate_unit_discount(discount=None): def calculate_price(base_price, voucher, unit_price): e = 100 - + + if 'gift' in voucher: + discount = min(voucher['gift']['balance'] / e, base_price) + return round_money(base_price - discount) + if not 'discount' in voucher: raise Exception('Unsupported voucher type.') @@ -49,7 +53,11 @@ def calculate_price(base_price, voucher, unit_price): def calculate_discount(base_price, voucher, unit_price): e = 100 - + + if 'gift' in voucher: + discount = min(voucher['gift']['balance'] / e, base_price) + return round_money(discount) + if not 'discount' in voucher: raise Exception('Unsupported voucher type.')