Skip to content

Commit

Permalink
Merge pull request #14 from voucherifyio/gift-utils
Browse files Browse the repository at this point in the history
utils - support gift vouchers
  • Loading branch information
tpindel authored Dec 6, 2016
2 parents 9913ab1 + db5e6cf commit 9564608
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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({
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
12 changes: 10 additions & 2 deletions voucherify/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.')

Expand Down Expand Up @@ -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.')

Expand Down

0 comments on commit 9564608

Please sign in to comment.