Skip to content

Commit 5e0fccf

Browse files
author
Jakub Reczko
committed
Improved README
1 parent f69f10c commit 5e0fccf

File tree

1 file changed

+167
-69
lines changed

1 file changed

+167
-69
lines changed

README.md

+167-69
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,17 @@ Full documentation is located at [voucherify.readme.io](https://voucherify.readm
2323
#### Configure through a non-global API object
2424

2525
```python
26-
import voucherify
26+
from voucherify import Client as voucherifyClient
2727

28-
voucherifyClient = voucherify.client(
29-
application_id="YOUR-APPLICATION-ID-OBTAINED-FROM-CONFIGURATION",
30-
client_secret_key="YOUR-CLIENT-SECRET-KEY-OBTAINED-FROM-CONFIGURATION"
28+
voucherify = voucherifyClient(
29+
application_id="c70a6f00-cf91-4756-9df5-47628850002b",
30+
client_secret_key="3266b9f8-e246-4f79-bdf0-833929b1380c"
3131
)
3232
```
3333

3434
#### Listing vouchers
3535

36-
`voucherifyClient.list(filter)`
36+
`voucherify.list(filter)`
3737

3838
Filter parameters:
3939

@@ -46,7 +46,13 @@ Filter parameters:
4646

4747
Example:
4848
```python
49-
voucherifyClient.list({limit: 10, skip: 20, category: "API Test"})
49+
filter_params = {
50+
"limit": 10,
51+
"skip": 20,
52+
"category": "API Test"
53+
}
54+
55+
vouchers_list = voucherify.list(filter_params)
5056
```
5157

5258
Result:
@@ -99,7 +105,7 @@ Result:
99105

100106
Example:
101107
```python
102-
voucherifyClient.get('v1GiJYuuS')
108+
voucher = voucherify.get("Testing7fjWdr")
103109
```
104110

105111
Result:
@@ -129,40 +135,77 @@ Result:
129135
```
130136
#### Creating a voucher
131137

132-
`voucherifyClient.create(voucher)`
138+
`voucherify.create(voucher)`
133139

134140
Example:
135141

136142
```python
137-
voucherifyClient.create({
138-
discount: {
139-
type: 'AMOUNT',
140-
amount_off: 1000 // 10.00
143+
payload = {
144+
"discount": {
145+
"type": "AMOUNT",
146+
"amount_off": 1000 # 10.00
141147
},
142-
category: 'Test',
143-
start_date: '2016-01-01T00:00:00Z'
144-
expiration_date: '2016-12-31T23:59:59Z'
145-
})
148+
"category": "API Test",
149+
"start_date": "2016-01-01T00:00:00Z",
150+
"expiration_date": "2016-12-31T23:59:59Z"
151+
}
152+
153+
new_voucher = voucherify.create(payload)
154+
```
155+
156+
Result:
157+
158+
```json
159+
{
160+
"code": "JxiJaV",
161+
"campaign": null,
162+
"category": "API Test",
163+
"discount": {
164+
"type": "AMOUNT",
165+
"amount_off": 1000
166+
},
167+
"start_date": "2016-01-01T00:00:00Z",
168+
"expiration_date": "2016-12-31T23:59:59Z",
169+
"redemption": {
170+
"quantity": 1,
171+
"redeemed_quantity": 0,
172+
"redemption_entries": []
173+
},
174+
"active": true,
175+
"additional_info": null,
176+
"metadata": null
177+
}
146178
```
147179

148180
#### Disabling a voucher
149181

150-
`voucherifyClient.disable(voucher_code)`
182+
`voucherify.disable(voucher_code)`
151183

152184
Example:
153185

154186
```python
155-
voucherifyClient.disable('v1GiJYuuS')
187+
result = voucherify.disable("JxiJaV")
188+
```
189+
190+
Result:
191+
192+
```text
193+
True|None
156194
```
157195

158196
#### Enabling a voucher
159197

160-
`voucherifyClient.enable(voucher_code)`
198+
`voucherify.enable(voucher_code)`
161199

162200
Example:
163201

164202
```python
165-
voucherifyClient.enable('v1GiJYuuS')
203+
result = voucherify.enable("JxiJaV")
204+
```
205+
206+
Result:
207+
```text
208+
True|None
166209
```
167210

168211
#### Getting voucher redemption
@@ -171,7 +214,7 @@ voucherifyClient.enable('v1GiJYuuS')
171214

172215
Example:
173216
```python
174-
voucherifyClient.redemption('v1GiJYuuS')
217+
result = voucherify.redemption("Testing7fjWdr")
175218
```
176219

177220
Result:
@@ -192,24 +235,35 @@ Result:
192235

193236
#### Publishing voucher
194237

195-
`voucherifyClient.publish(campaign_name)`
196-
197-
`voucherifyClient.publish(params)`
198-
199238
This method selects a voucher that is suitable for publication, adds a publish entry and returns the voucher.
200239
A voucher is suitable for publication when it's active and has not been published more times than the redemption limit.
201240

241+
##### Publish using campaign name
242+
243+
`voucherify.publish(campaign_name)`
244+
202245
Example:
203246

204247
```python
205-
voucherifyClient.publish({
206-
campaign: 'First Ride',
207-
channel: 'Email',
208-
customer: '[email protected]'
209-
})
248+
result = voucherify.publish("First Ride")
210249
```
211250

212-
Positive result:
251+
##### Publish using params
252+
253+
`voucherify.publish(params)`
254+
255+
Example:
256+
257+
```python
258+
payload = {
259+
"campaign": "First Ride",
260+
"channel": "Email",
261+
"customer": "[email protected]"
262+
}
263+
result = voucherify.publish(payload)
264+
```
265+
266+
Result *(for both)*:
213267

214268
```json
215269
{
@@ -240,7 +294,7 @@ Positive result:
240294
}
241295
```
242296

243-
Possible error:
297+
Error:
244298

245299
```json
246300
{
@@ -251,13 +305,13 @@ Possible error:
251305

252306
#### Redeeming voucher
253307

254-
`voucherifyClient.redeem(voucher_code, tracking_id|customer_profile*)`
308+
`voucherify.redeem(voucher_code, tracking_id|customer_profile*)`
255309

256310
##### 1. Just by code
257311

258312
Example:
259313
```python
260-
voucherifyClient.redeem('v1GiJYuuS')
314+
result = voucherify.redeem("Testing7fjWdr")
261315
```
262316

263317
Result (voucher details after redemption):
@@ -301,6 +355,7 @@ Result (voucher details after redemption):
301355
```
302356

303357
Error:
358+
304359
```json
305360
{
306361
"code": 400,
@@ -313,11 +368,14 @@ Error:
313368

314369
You can provide a tracking id (e.g. your customer's login or a generated id) to the voucher redemption request.
315370

371+
Example:
372+
316373
```python
317-
voucherifyClient.redeem('v1GiJYuuS', 'alice.morgan')
374+
result = voucherify.redeem("Testing7fjWdr", "alice.morgan")
318375
```
319376

320377
Result:
378+
321379
```json
322380
{
323381
"id": "r_yRmanaA6EgSE9uDYvMQ5Evfp",
@@ -366,26 +424,31 @@ Result:
366424

367425
You can record a detailed customer profile consisting of an `id` (obligatory), `name`, `email`, `description` and a `metadata` section that can include any data you wish.
368426

427+
Example:
428+
369429
```python
370-
voucherifyClient.redeem({
371-
voucher: "v1GiJYuuS",
372-
customer: {
373-
id: "alice.morgan",
374-
name: "Alice Morgan",
375-
376-
description: "",
377-
metadata: {
378-
locale: "en-GB",
379-
shoeSize: 5,
380-
favourite_brands: ["Armani", "L’Autre Chose", "Vicini"]
381-
}
430+
customer = {
431+
"id": "alice.morgan",
432+
"name": "Alice Morgan",
433+
"email": "[email protected]",
434+
"description": "",
435+
"metadata": {
436+
"locale": "en-GB",
437+
"shoeSize": 5,
438+
"favourite_brands": ["Armani", "L'Autre Chose", "Vicini"]
382439
}
383-
})
440+
}
441+
payload = {
442+
"voucher": "v1GiJYuuS",
443+
"customer": customer
444+
}
445+
voucherify.redeem(payload)
384446
```
385447

386448
### Listing redemptions
387449

388-
Use `voucherify.redemptions(filter)` to get a filtered list of redemptions.
450+
UseUse `redemptions` to get a filtered list of redemptions.
451+
389452
Filter parameters:
390453

391454
- limit (default: 100)
@@ -395,33 +458,34 @@ Filter parameters:
395458
- result - Success | Failure-NotExist | Failure-Inactive
396459
- customer
397460

398-
Example - 1000 successful redemptions from April 2016:
461+
`voucherify.redemptions(filter)`
462+
463+
Example:
399464

400465
```python
401-
voucherifyClient.redemptions({
402-
limit: 1000,
403-
page: 0,
404-
start_date: "2016-04-01T00:00:00",
405-
end_date: "2016-04-30T23:59:59",
406-
result: "Success"
407-
})
466+
filter_params = {
467+
"limit": 1000,
468+
"page": 0,
469+
"start_date": "2016-04-01T00:00:00",
470+
"end_date": "2016-04-30T23:59:59",
471+
"result": "Success"
472+
}
473+
474+
redemptions = voucherify.redemptions(filter_params)
408475
```
409476

410477
#### Rollback a redemption
411478

412-
Use `voucherify.rollback(redemption_id, tracking_id*, reason*)` to revert a redemption.
479+
Use `rollback` to revert a redemption.
413480
It will create a rollback entry in `redemption.redemption_entries` and give 1 redemption back to the pool
414481
(decrease `redeemed_quantity` by 1).
415482

416-
Possible errors are:
417-
- 404 - Resource not found - if voucher with given `redemption_id` doesn't exist
418-
- 400 - Already rolled back - if redemption with given `redemption_id` has been rolled back already
419-
- 400 - Invalid redemption id - when trying to rollback a rollback.
483+
`voucherify.rollback(redemption_id, reason*)`
420484

421485
Example:
422486

423487
```python
424-
voucherifyClient.rollback('r_irOQWUTAjthQwnkn5JQM1V6N', 'alice.morgan')
488+
result = voucherify.rollback("r_irOQWUTAjthQwnkn5JQM1V6N", "alice.morgan")
425489
```
426490

427491
Result:
@@ -477,19 +541,53 @@ Result:
477541
}
478542
```
479543

544+
Possible errors are:
545+
- 404 - Resource not found - if voucher with given `redemption_id` doesn't exist
546+
- 400 - Already rolled back - if redemption with given `redemption_id` has been rolled back already
547+
- 400 - Invalid redemption id - when trying to rollback a rollback.
480548

481549
### Utils
482550

483-
#### Usage
551+
Use our set of utils to calculate a price after discount or discount amount.
484552

485-
```
553+
#### Available methods
554+
555+
- `utils.calculatePrice(basePrice, voucher, unit_price)` - Calculate discount amount
556+
- `utils.calculateDiscount(basePrice, voucher, unit_price)` - Calculate new price after discount
557+
558+
#### Example
559+
560+
```Python
486561
from voucherify import utils
487-
```
488562

489-
#### Available methods
563+
# Example voucher object.
564+
# You can use `get` method from API to get correct voucher dictionary shape.
565+
voucher = {
566+
"code": "Testing7fjWdr",
567+
"discount": {
568+
"type": "AMOUNT",
569+
"amount_off": 1080 # 10.80
570+
},
571+
"category": "API Test",
572+
"start_date": "2016-01-01T00:00:00Z",
573+
"expiration_date": "2016-12-31T23:59:59Z"
574+
}
575+
576+
# Price of one item
577+
unit_price = 83.45
490578

491-
- `utils.calculatePrice(basePrice, voucher)`
492-
- `utils.calculateDiscount(basePrice, voucher)`
579+
# Number of items
580+
items_count = 13
581+
582+
# Total price
583+
base_price = unit_price * items_count
584+
585+
# Calculate discount amount
586+
discount = utils.calculate_discount(base_price, voucher, unit_price)
587+
588+
# Calculate new price after discount
589+
new_price = utils.calculate_price(base_price, voucher, unit_price)
590+
```
493591

494592
### Changelog
495593

0 commit comments

Comments
 (0)