Skip to content

Commit 27cb951

Browse files
committed
docs(modules): link published apps samples, fix typos
fixes #12
1 parent a484983 commit 27cb951

4 files changed

Lines changed: 116 additions & 76 deletions

File tree

functions/routes/ecom/modules/apply-discount.js

Lines changed: 26 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,43 @@
11
exports.post = ({ appSdk, admin }, req, res) => {
22
/**
3-
* Requests coming from Modules API have two object properties on body: `params` and `application`.
4-
* `application` is a copy of your app installed by the merchant,
5-
* including the properties `data` and `hidden_data` with admin settings configured values.
6-
* JSON Schema reference for the Apply Discount module objects:
7-
* `params`: https://apx-mods.e-com.plus/api/v1/apply_discount/schema.json?store_id=100
8-
* `response`: https://apx-mods.e-com.plus/api/v1/apply_discount/response_schema.json?store_id=100
9-
*/
3+
* Requests coming from Modules API have two object properties on body: `params` and `application`.
4+
* `application` is a copy of your app installed by the merchant,
5+
* including the properties `data` and `hidden_data` with admin settings configured values.
6+
* JSON Schema reference for the Apply Discount module objects:
7+
* `params`: https://apx-mods.e-com.plus/api/v1/apply_discount/schema.json?store_id=100
8+
* `response`: https://apx-mods.e-com.plus/api/v1/apply_discount/response_schema.json?store_id=100
9+
*
10+
* Complete (advanced) example in our default discouts app:
11+
* https://github.com/ecomplus/discounts/blob/master/routes/ecom/modules/apply-discount.js
12+
*/
1013

1114
const { params, application } = req.body
1215
const { storeId } = req
13-
16+
const response = {}
1417
// merge all app options configured by merchant
1518
const appData = Object.assign({}, application.data, application.hidden_data)
1619

17-
// setup basic required response object
18-
const response = {
19-
discount_rule: {}
20+
if (appData.available_extra_discount) {
21+
response.available_extra_discount = appData.available_extra_discount
22+
}
23+
if (params.discount_coupon) {
24+
// should match discount by coupon code
2025
}
2126

2227
/* DO THE STUFF HERE TO FILL RESPONSE OBJECT WITH DISCOUNT OPTIONS */
23-
/*
24-
// You can set how many discount rules you need.
25-
// But you can leave set up an extra discount that applies with the rules configured in the application.
26-
// example;
27-
if (appData.available_extra_discount) {
28-
const extra = appData.available_extra_discount
29-
const { amount } = params
30-
31-
if (amount.total <= extra.min_amount) {
32-
const discountValue = extra.value
3328

34-
if (extra.type === 'percentage') {
35-
discountValue *= (amount.total / 100)
36-
}
37-
38-
const newAmountTotal = (amount.total - discountValue)
39-
}
40-
41-
response.available_extra_discount = {
42-
...appData.available_extra_discount
29+
/**
30+
* Sample snippets:
31+
32+
// set discount value
33+
response.discount_rule = {
34+
label: 'X Campaign',
35+
extra_discount: {
36+
value: 20.5,
37+
flags: ['x-coupon']
4338
}
4439
}
40+
4541
*/
4642

4743
res.send(response)

functions/routes/ecom/modules/calculate-shipping.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,15 @@ exports.post = ({ appSdk }, req, res) => {
44
* JSON Schema reference for Calculate Shipping module objects:
55
* `params`: https://apx-mods.e-com.plus/api/v1/calculate_shipping/schema.json?store_id=100
66
* `response`: https://apx-mods.e-com.plus/api/v1/calculate_shipping/response_schema.json?store_id=100
7+
*
8+
* Examples in published apps:
9+
* https://github.com/ecomplus/app-mandabem/blob/master/functions/routes/ecom/modules/calculate-shipping.js
10+
* https://github.com/ecomplus/app-datafrete/blob/master/functions/routes/ecom/modules/calculate-shipping.js
11+
* https://github.com/ecomplus/app-jadlog/blob/master/functions/routes/ecom/modules/calculate-shipping.js
712
*/
813

914
const { params, application } = req.body
15+
const { storeId } = req
1016
// setup basic required response object
1117
const response = {
1218
shipping_services: []
@@ -26,5 +32,38 @@ exports.post = ({ appSdk }, req, res) => {
2632

2733
/* DO THE STUFF HERE TO FILL RESPONSE OBJECT WITH SHIPPING SERVICES */
2834

35+
/**
36+
* Sample snippets:
37+
38+
if (params.items) {
39+
let totalWeight = 0
40+
params.items.forEach(item => {
41+
// treat items to ship
42+
totalWeight += item.quantity * item.weight.value
43+
})
44+
}
45+
46+
// add new shipping service option
47+
response.shipping_services.push({
48+
label: appData.label || 'My shipping method',
49+
carrier: 'My carrier',
50+
shipping_line: {
51+
from: appData.from,
52+
to: params.to,
53+
package: {
54+
weight: {
55+
value: totalWeight
56+
}
57+
},
58+
price: 10,
59+
delivery_time: {
60+
days: 3,
61+
working_days: true
62+
}
63+
}
64+
})
65+
66+
*/
67+
2968
res.send(response)
3069
}
Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,49 @@
11
exports.post = ({ appSdk, admin }, req, res) => {
22
/**
3-
* Requests coming from the modules receive a hydrated body with two objects, `params` and application`.
3+
* Requests coming from Modules API have two object properties on body: `params` and `application`.
44
* `application` is a copy of your app installed by the merchant,
55
* including the properties `data` and `hidden_data` with admin settings configured values.
66
* JSON Schema reference for the Create Transaction module objects:
77
* `params`: https://apx-mods.e-com.plus/api/v1/create_transaction/schema.json?store_id=100
88
* `response`: https://apx-mods.e-com.plus/api/v1/create_transaction/response_schema.json?store_id=100
9+
*
10+
* Examples in published apps:
11+
* https://github.com/ecomplus/app-pagarme/blob/master/functions/routes/ecom/modules/create-transaction.js
12+
* https://github.com/ecomplus/app-custom-payment/blob/master/functions/routes/ecom/modules/create-transaction.js
913
*/
1014

1115
const { params, application } = req.body
1216
const { storeId } = req
13-
1417
// merge all app options configured by merchant
1518
const appData = Object.assign({}, application.data, application.hidden_data)
16-
17-
// payment `transaction` object
18-
// required in `response` object and must follow schema: https://apx-mods.e-com.plus/api/v1/create_transaction/response_schema.json?store_id=100
19+
// setup required `transaction` response object
1920
const transaction = {}
2021

21-
// Indicates whether the buyer should be redirected to payment link right after checkout
22+
// indicates whether the buyer should be redirected to payment link right after checkout
2223
let redirectToPayment = false
2324

2425
/**
2526
* Do the stuff here, call external web service or just fill the `transaction` object
26-
* according to the by the chosen payment_method.
27-
* `response`: https://apx-mods.e-com.plus/api/v1/create_transaction/response_schema.json?store_id=100
27+
* according to the `appData` configured options for the chosen payment method.
2828
*/
29+
30+
// WIP:
2931
switch (params.payment_method.code) {
3032
case 'credit_card':
31-
//
32-
break;
33+
// you may need to handle card hash and create transaction on gateway API
34+
break
3335
case 'banking_billet':
34-
//
35-
break;
36+
// create new "Boleto bancário"
37+
break
3638
case 'online_debit':
37-
// redirectToPayment = true
38-
break;
39+
redirectToPayment = true
40+
break
3941
default:
40-
break;
42+
break
4143
}
4244

43-
// setup basic required response object
44-
// must follow schema : https://apx-mods.e-com.plus/api/v1/create_transaction/response_schema.json?store_id=100
45-
const response = {
45+
res.send({
4646
redirect_to_payment: redirectToPayment,
4747
transaction
48-
}
49-
50-
res.send(response)
48+
})
5149
}

functions/routes/ecom/modules/list-payments.js

Lines changed: 32 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,48 @@
11
exports.post = ({ appSdk }, req, res) => {
22
/**
3-
* Requests coming from the modules receive a hydrated body with two objects, `params` and application`.
4-
* In `application` is a copy of your application installed by the merchant, including the properties` data` and `hidden_data`.
5-
* JSON Schema of the list_payments module
3+
* Requests coming from Modules API have two object properties on body: `params` and `application`.
4+
* `application` is a copy of your app installed by the merchant,
5+
* including the properties `data` and `hidden_data` with admin settings configured values.
6+
* JSON Schema reference for the List Payments module objects:
67
* `params`: https://apx-mods.e-com.plus/api/v1/list_payments/schema.json?store_id=100
78
* `response`: https://apx-mods.e-com.plus/api/v1/list_payments/response_schema.json?store_id=100
9+
*
10+
* Examples in published apps:
11+
* https://github.com/ecomplus/app-pagarme/blob/master/functions/routes/ecom/modules/list-payments.js
12+
* https://github.com/ecomplus/app-custom-payment/blob/master/functions/routes/ecom/modules/list-payments.js
813
*/
14+
915
const { params, application } = req.body
1016
const { storeId } = req
11-
12-
// merge all app options configured by merchant
13-
const appData = Object.assign({}, application.data, application.hidden_data)
14-
1517
// setup basic required response object
16-
// Must follow schema: https://apx-mods.e-com.plus/api/v1/list_payments/response_schema.json?store_id=100
1718
const response = {
1819
payment_gateways: []
1920
}
21+
// merge all app options configured by merchant
22+
const appData = Object.assign({}, application.data, application.hidden_data)
2023

2124
/* DO THE STUFF HERE TO FILL RESPONSE OBJECT WITH PAYMENT GATEWAYS */
22-
/*
23-
// eg;
24-
response.payment_gateways.push({
25-
intermediator: {
26-
code: 'paupay',
27-
link: 'https://www.paupay.com.br',
28-
name: 'paupay'
29-
},
30-
payment_url: 'https://www.paupay.com.br/',
31-
type: 'payment',
32-
payment_method: {
33-
code: 'banking_billet',
34-
name: 'Boleto Bancário'
35-
},
36-
label: 'Boleto Bancário',
37-
expiration_date: appData.banking_billet.expiration_date || 14
38-
})
25+
26+
/**
27+
* Sample snippets:
28+
29+
// add new payment method option
30+
response.payment_gateways.push({
31+
intermediator: {
32+
code: 'paupay',
33+
link: 'https://www.palpay.com.br',
34+
name: 'paupay'
35+
},
36+
payment_url: 'https://www.palpay.com.br/',
37+
type: 'payment',
38+
payment_method: {
39+
code: 'banking_billet',
40+
name: 'Boleto Bancário'
41+
},
42+
label: 'Boleto Bancário',
43+
expiration_date: appData.expiration_date || 14
44+
})
45+
3946
*/
4047

4148
res.send(response)

0 commit comments

Comments
 (0)