generated from ecomplus/application-starter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
create-transaction.js
49 lines (44 loc) · 1.82 KB
/
create-transaction.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
45
46
47
48
49
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 Create Transaction module objects:
* `params`: https://apx-mods.e-com.plus/api/v1/create_transaction/schema.json?store_id=100
* `response`: https://apx-mods.e-com.plus/api/v1/create_transaction/response_schema.json?store_id=100
*
* Examples in published apps:
* https://github.com/ecomplus/app-pagarme/blob/master/functions/routes/ecom/modules/create-transaction.js
* https://github.com/ecomplus/app-custom-payment/blob/master/functions/routes/ecom/modules/create-transaction.js
*/
const { params, application } = req.body
const { storeId } = req
// merge all app options configured by merchant
const appData = Object.assign({}, application.data, application.hidden_data)
// setup required `transaction` response object
const transaction = {}
// indicates whether the buyer should be redirected to payment link right after checkout
let redirectToPayment = false
/**
* Do the stuff here, call external web service or just fill the `transaction` object
* according to the `appData` configured options for the chosen payment method.
*/
// WIP:
switch (params.payment_method.code) {
case 'credit_card':
// you may need to handle card hash and create transaction on gateway API
break
case 'banking_billet':
// create new "Boleto bancário"
break
case 'online_debit':
redirectToPayment = true
break
default:
break
}
res.send({
redirect_to_payment: redirectToPayment,
transaction
})
}