Skip to content

Commit 1eee19f

Browse files
committed
gift vouchers, v 1.2.1
1 parent 08b8841 commit 1eee19f

File tree

3 files changed

+46
-6
lines changed

3 files changed

+46
-6
lines changed

README.md

+37-3
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ Result:
6161
"code": "9mYBpIk",
6262
"campaign": null,
6363
"category": "API Test",
64+
"type": "DISCOUNT_VOUCHER",
6465
"discount": {
6566
"type": "AMOUNT",
6667
"amount_off": 400
@@ -80,9 +81,9 @@ Result:
8081
"code": "AzTsIH",
8182
"campaign": null,
8283
"category": "API Test",
83-
"discount": {
84-
"type": "AMOUNT",
85-
"amount_off": 400
84+
"type": "GIFT_VOUCHER",
85+
"gift": {
86+
"amount": 5000
8687
},
8788
"start_date": "2016-03-01T10:00:00Z",
8889
"expiration_date": null,
@@ -113,6 +114,7 @@ Result:
113114
{
114115
"code": "v1GiJYuuS",
115116
"campaign": "vip",
117+
"type": "DISCOUNT_VOUCHER",
116118
"discount": {
117119
"percent_off": 10.0,
118120
"type": "PERCENT"
@@ -142,6 +144,7 @@ Example:
142144

143145
```python
144146
payload = {
147+
"type": "DISCOUNT_VOUCHER",
145148
"discount": {
146149
"type": "AMOUNT",
147150
"amount_off": 1000 # 10.00
@@ -161,6 +164,7 @@ Result:
161164
"code": "JxiJaV",
162165
"campaign": null,
163166
"category": "API Test",
167+
"type": "DISCOUNT_VOUCHER",
164168
"discount": {
165169
"type": "AMOUNT",
166170
"amount_off": 1000
@@ -303,6 +307,7 @@ Result *(for both)*:
303307
"code": "FR-zT-u9I7zG",
304308
"campaign": "First Ride",
305309
"category": null,
310+
"type": "DISCOUNT_VOUCHER",
306311
"discount": {
307312
"type": "PERCENT",
308313
"amount_off": 50
@@ -359,6 +364,7 @@ Result (voucher details after redemption):
359364
"voucher": {
360365
"code": "v1GiJYuuS",
361366
"campaign": "vip",
367+
"type": "DISCOUNT_VOUCHER",
362368
"discount": {
363369
"percent_off": 10.0,
364370
"type": "PERCENT"
@@ -422,6 +428,7 @@ Result:
422428
"voucher": {
423429
"code": "v1GiJYuuS",
424430
"campaign": "vip",
431+
"type": "DISCOUNT_VOUCHER",
425432
"discount": {
426433
"percent_off": 10.0,
427434
"type": "PERCENT"
@@ -485,6 +492,31 @@ payload = {
485492
voucherify.redeem(payload)
486493
```
487494

495+
##### 4. With customer id
496+
497+
If you already created a customer profile in Voucherify's database, whether it was implicitly by providing it to the `redeem` function or explicitly by invoking the [`customer.create`](#create-customer) method, you can identify your customer in following redemptions by a generated id (starting with `cust_`).
498+
499+
```python
500+
voucherify.redeem({
501+
voucher: "v1GiJYuuS",
502+
customer: {
503+
id: "cust_C9qJ3xKgZFqkpMw7b21MF2ow"
504+
})
505+
```
506+
507+
##### 5. With order amount
508+
509+
Redeeming a gift voucher requires to pass an amount that you wish to withdraw from the voucher.
510+
Order amount have to be expressed in cents, as an integer. For example $22.50 should be provided as 2250:
511+
512+
```python
513+
voucherify.redeem({
514+
voucher: "91Ft4U",
515+
order: {
516+
amount: 2250
517+
})
518+
```
519+
488520
### Listing redemptions
489521

490522
Use `redemptions` to get a filtered list of redemptions.
@@ -540,6 +572,7 @@ Result:
540572
"voucher": {
541573
"code": "v1GiJYuuS",
542574
"campaign": "vip",
575+
"type": "DISCOUNT_VOUCHER",
543576
"discount": {
544577
"percent_off": 10.0,
545578
"type": "PERCENT"
@@ -731,6 +764,7 @@ new_price = utils.calculate_price(base_price, voucher, unit_price)
731764

732765
### Changelog
733766

767+
- **2016-06-23** - `1.2.1` - Gift vouchers
734768
- **2016-06-16** - `1.2.0` - Unified naming convention
735769
- **2016-06-16** - `1.1.0` - Added customer methods
736770
- **2016-06-08** - `1.0.0` - Release version

setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'voucherify'))
66

7-
__version__ = '1.2.0'
7+
__version__ = '1.2.1'
88
__pypi_username__ = 'voucherify'
99
__pypi_packagename__ = 'voucherify'
1010
__github_username__ = 'voucherifyio'

voucherify/utils.py

+8-2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ def validate_unit_discount(discount=None):
2222
def calculate_price(base_price, voucher, unit_price):
2323
e = 100
2424

25+
if not 'discount' in voucher:
26+
raise Exception('Unsupported voucher type.')
27+
2528
if voucher['discount']['type'] == 'PERCENT':
2629
discount = voucher['discount']['percent_off']
2730
validate_percent_discount(discount)
@@ -41,12 +44,15 @@ def calculate_price(base_price, voucher, unit_price):
4144
return round_money(new_price if new_price > 0 else 0)
4245

4346
else:
44-
raise Exception('Unsupported voucher type.')
47+
raise Exception('Unsupported discount type.')
4548

4649

4750
def calculate_discount(base_price, voucher, unit_price):
4851
e = 100
4952

53+
if not 'discount' in voucher:
54+
raise Exception('Unsupported voucher type.')
55+
5056
if voucher['discount']['type'] == 'PERCENT':
5157
discount = voucher['discount']['percent_off']
5258
validate_percent_discount(discount)
@@ -65,7 +71,7 @@ def calculate_discount(base_price, voucher, unit_price):
6571
return round_money(base_price if price_discount > base_price else price_discount)
6672

6773
else:
68-
raise Exception('Unsupported voucher type.')
74+
raise Exception('Unsupported discount type.')
6975

7076

7177
__all__ = ['calculate_price', 'calculate_discount']

0 commit comments

Comments
 (0)