diff --git a/README.md b/README.md index 1137b278..e41ee162 100644 --- a/README.md +++ b/README.md @@ -95,7 +95,8 @@ Result: "category": "API Test", "type": "GIFT_VOUCHER", "gift": { - "amount": 5000 + "amount": 10000, + "balance": 5000 }, "start_date": "2016-03-01T10:00:00Z", "expiration_date": null, @@ -600,9 +601,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({ @@ -875,6 +876,7 @@ new_price = utils.calculate_price(base_price, voucher, unit_price) ### Changelog +- **2016-12-02** - `1.4.2` - Support gift vouchers in utils - **2016-10-04** - `1.4.1` - Publish update - **2016-07-18** - `1.4.0` - Voucher code pattern - **2016-07-18** - `1.3.0` - Update voucher diff --git a/setup.py b/setup.py index f7c16093..3895cad7 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.1' +__version__ = '1.4.2' __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.')