generated from ecomplus/application-starter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
apply-discount.js
44 lines (37 loc) · 1.42 KB
/
apply-discount.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
exports.post = ({ appSdk, admin }, req, res) => {
/**
* Requests coming from Modules API have two object properties on body: `params` and `application`.
* `application` is a copy of your app installed by the merchant,
* including the properties `data` and `hidden_data` with admin settings configured values.
* JSON Schema reference for the Apply Discount module objects:
* `params`: https://apx-mods.e-com.plus/api/v1/apply_discount/schema.json?store_id=100
* `response`: https://apx-mods.e-com.plus/api/v1/apply_discount/response_schema.json?store_id=100
*
* Complete (advanced) example in our default discouts app:
* https://github.com/ecomplus/discounts/blob/master/routes/ecom/modules/apply-discount.js
*/
const { params, application } = req.body
const { storeId } = req
const response = {}
// merge all app options configured by merchant
const appData = Object.assign({}, application.data, application.hidden_data)
if (appData.available_extra_discount) {
response.available_extra_discount = appData.available_extra_discount
}
if (params.discount_coupon) {
// should match discount by coupon code
}
/* DO THE STUFF HERE TO FILL RESPONSE OBJECT WITH DISCOUNT OPTIONS */
/**
* Sample snippets:
// set discount value
response.discount_rule = {
label: 'X Campaign',
extra_discount: {
value: 20.5,
flags: ['x-coupon']
}
}
*/
res.send(response)
}