@@ -23,17 +23,17 @@ Full documentation is located at [voucherify.readme.io](https://voucherify.readm
23
23
#### Configure through a non-global API object
24
24
25
25
``` python
26
- import voucherify
26
+ from voucherify import Client as voucherifyClient
27
27
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 "
31
31
)
32
32
```
33
33
34
34
#### Listing vouchers
35
35
36
- ` voucherifyClient .list(filter)`
36
+ ` voucherify .list(filter)`
37
37
38
38
Filter parameters:
39
39
@@ -46,7 +46,13 @@ Filter parameters:
46
46
47
47
Example:
48
48
``` 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)
50
56
```
51
57
52
58
Result:
@@ -99,7 +105,7 @@ Result:
99
105
100
106
Example:
101
107
``` python
102
- voucherifyClient .get(' v1GiJYuuS ' )
108
+ voucher = voucherify .get(" Testing7fjWdr " )
103
109
```
104
110
105
111
Result:
@@ -129,40 +135,77 @@ Result:
129
135
```
130
136
#### Creating a voucher
131
137
132
- ` voucherifyClient .create(voucher)`
138
+ ` voucherify .create(voucher)`
133
139
134
140
Example:
135
141
136
142
``` 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
141
147
},
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
+ }
146
178
```
147
179
148
180
#### Disabling a voucher
149
181
150
- ` voucherifyClient .disable(voucher_code)`
182
+ ` voucherify .disable(voucher_code)`
151
183
152
184
Example:
153
185
154
186
``` python
155
- voucherifyClient.disable(' v1GiJYuuS' )
187
+ result = voucherify.disable(" JxiJaV" )
188
+ ```
189
+
190
+ Result:
191
+
192
+ ``` text
193
+ True|None
156
194
```
157
195
158
196
#### Enabling a voucher
159
197
160
- ` voucherifyClient .enable(voucher_code)`
198
+ ` voucherify .enable(voucher_code)`
161
199
162
200
Example:
163
201
164
202
``` python
165
- voucherifyClient.enable(' v1GiJYuuS' )
203
+ result = voucherify.enable(" JxiJaV" )
204
+ ```
205
+
206
+ Result:
207
+ ``` text
208
+ True|None
166
209
```
167
210
168
211
#### Getting voucher redemption
@@ -171,7 +214,7 @@ voucherifyClient.enable('v1GiJYuuS')
171
214
172
215
Example:
173
216
``` python
174
- voucherifyClient .redemption(' v1GiJYuuS ' )
217
+ result = voucherify .redemption(" Testing7fjWdr " )
175
218
```
176
219
177
220
Result:
@@ -192,24 +235,35 @@ Result:
192
235
193
236
#### Publishing voucher
194
237
195
- ` voucherifyClient.publish(campaign_name) `
196
-
197
- ` voucherifyClient.publish(params) `
198
-
199
238
This method selects a voucher that is suitable for publication, adds a publish entry and returns the voucher.
200
239
A voucher is suitable for publication when it's active and has not been published more times than the redemption limit.
201
240
241
+ ##### Publish using campaign name
242
+
243
+ ` voucherify.publish(campaign_name) `
244
+
202
245
Example:
203
246
204
247
``` python
205
- voucherifyClient.publish({
206
- campaign: ' First Ride' ,
207
- channel: ' Email' ,
208
-
209
- })
248
+ result = voucherify.publish(" First Ride" )
210
249
```
211
250
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
+
262
+ }
263
+ result = voucherify.publish(payload)
264
+ ```
265
+
266
+ Result * (for both)* :
213
267
214
268
``` json
215
269
{
@@ -240,7 +294,7 @@ Positive result:
240
294
}
241
295
```
242
296
243
- Possible error :
297
+ Error :
244
298
245
299
``` json
246
300
{
@@ -251,13 +305,13 @@ Possible error:
251
305
252
306
#### Redeeming voucher
253
307
254
- ` voucherifyClient .redeem(voucher_code, tracking_id|customer_profile*)`
308
+ ` voucherify .redeem(voucher_code, tracking_id|customer_profile*)`
255
309
256
310
##### 1. Just by code
257
311
258
312
Example:
259
313
``` python
260
- voucherifyClient .redeem(' v1GiJYuuS ' )
314
+ result = voucherify .redeem(" Testing7fjWdr " )
261
315
```
262
316
263
317
Result (voucher details after redemption):
@@ -301,6 +355,7 @@ Result (voucher details after redemption):
301
355
```
302
356
303
357
Error:
358
+
304
359
``` json
305
360
{
306
361
"code" : 400 ,
@@ -313,11 +368,14 @@ Error:
313
368
314
369
You can provide a tracking id (e.g. your customer's login or a generated id) to the voucher redemption request.
315
370
371
+ Example:
372
+
316
373
``` python
317
- voucherifyClient .redeem(' v1GiJYuuS ' , ' alice.morgan' )
374
+ result = voucherify .redeem(" Testing7fjWdr " , " alice.morgan" )
318
375
```
319
376
320
377
Result:
378
+
321
379
``` json
322
380
{
323
381
"id" : " r_yRmanaA6EgSE9uDYvMQ5Evfp" ,
@@ -366,26 +424,31 @@ Result:
366
424
367
425
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.
368
426
427
+ Example:
428
+
369
429
``` 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
+
434
+ " description" : " " ,
435
+ " metadata" : {
436
+ " locale" : " en-GB" ,
437
+ " shoeSize" : 5 ,
438
+ " favourite_brands" : [" Armani" , " L'Autre Chose" , " Vicini" ]
382
439
}
383
- })
440
+ }
441
+ payload = {
442
+ " voucher" : " v1GiJYuuS" ,
443
+ " customer" : customer
444
+ }
445
+ voucherify.redeem(payload)
384
446
```
385
447
386
448
### Listing redemptions
387
449
388
- Use ` voucherify.redemptions(filter) ` to get a filtered list of redemptions.
450
+ UseUse ` redemptions ` to get a filtered list of redemptions.
451
+
389
452
Filter parameters:
390
453
391
454
- limit (default: 100)
@@ -395,33 +458,34 @@ Filter parameters:
395
458
- result - Success | Failure-NotExist | Failure-Inactive
396
459
- customer
397
460
398
- Example - 1000 successful redemptions from April 2016:
461
+ ` voucherify.redemptions(filter) `
462
+
463
+ Example:
399
464
400
465
``` 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)
408
475
```
409
476
410
477
#### Rollback a redemption
411
478
412
- Use ` voucherify. rollback(redemption_id, tracking_id*, reason*) ` to revert a redemption.
479
+ Use ` rollback ` to revert a redemption.
413
480
It will create a rollback entry in ` redemption.redemption_entries ` and give 1 redemption back to the pool
414
481
(decrease ` redeemed_quantity ` by 1).
415
482
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*) `
420
484
421
485
Example:
422
486
423
487
``` python
424
- voucherifyClient .rollback(' r_irOQWUTAjthQwnkn5JQM1V6N' , ' alice.morgan' )
488
+ result = voucherify .rollback(" r_irOQWUTAjthQwnkn5JQM1V6N" , " alice.morgan" )
425
489
```
426
490
427
491
Result:
@@ -477,19 +541,53 @@ Result:
477
541
}
478
542
```
479
543
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.
480
548
481
549
### Utils
482
550
483
- #### Usage
551
+ Use our set of utils to calculate a price after discount or discount amount.
484
552
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
486
561
from voucherify import utils
487
- ```
488
562
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
490
578
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
+ ```
493
591
494
592
### Changelog
495
593
0 commit comments