generated from ecomplus/express-app-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs(modules): link published apps samples, fix typos
fixes #12
- Loading branch information
Showing
4 changed files
with
116 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,49 @@ | ||
exports.post = ({ appSdk, admin }, req, res) => { | ||
/** | ||
* Requests coming from the modules receive a hydrated body with two objects, `params` and application`. | ||
* 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) | ||
|
||
// payment `transaction` object | ||
// required in `response` object and must follow schema: https://apx-mods.e-com.plus/api/v1/create_transaction/response_schema.json?store_id=100 | ||
// setup required `transaction` response object | ||
const transaction = {} | ||
|
||
// Indicates whether the buyer should be redirected to payment link right after checkout | ||
// 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 by the chosen payment_method. | ||
* `response`: https://apx-mods.e-com.plus/api/v1/create_transaction/response_schema.json?store_id=100 | ||
* according to the `appData` configured options for the chosen payment method. | ||
*/ | ||
|
||
// WIP: | ||
switch (params.payment_method.code) { | ||
case 'credit_card': | ||
// | ||
break; | ||
// you may need to handle card hash and create transaction on gateway API | ||
break | ||
case 'banking_billet': | ||
// | ||
break; | ||
// create new "Boleto bancário" | ||
break | ||
case 'online_debit': | ||
// redirectToPayment = true | ||
break; | ||
redirectToPayment = true | ||
break | ||
default: | ||
break; | ||
break | ||
} | ||
|
||
// setup basic required response object | ||
// must follow schema : https://apx-mods.e-com.plus/api/v1/create_transaction/response_schema.json?store_id=100 | ||
const response = { | ||
res.send({ | ||
redirect_to_payment: redirectToPayment, | ||
transaction | ||
} | ||
|
||
res.send(response) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters