Archived
1
0
Fork 0

Add credit card payment method

This commit is contained in:
Ethanell 2020-09-20 12:35:02 +02:00
parent 73a9aae4e4
commit b10424d158
6 changed files with 64 additions and 26 deletions

View file

@ -29,7 +29,9 @@
"index": { "index": {
"welcome": "Welcome to Sandwiches Order Doua", "welcome": "Welcome to Sandwiches Order Doua",
"day": "Day", "day": "Day",
"pay": "Pay" "pay": "Pay",
"payment": "Payment method",
"creditCard": "Credit card"
}, },
"login": { "login": {
"title": "Login", "title": "Login",

View file

@ -29,7 +29,9 @@
"index": { "index": {
"welcome": "Bienvenue sur Sandwiches Order Doua", "welcome": "Bienvenue sur Sandwiches Order Doua",
"day": "Jour", "day": "Jour",
"pay": "Payer" "pay": "Payer",
"payment": "Mode de paiement",
"creditCard": "CB"
}, },
"login": { "login": {
"title": "Se connecter", "title": "Se connecter",

View file

@ -54,9 +54,6 @@ a {
margin: auto; margin: auto;
width: 100%; width: 100%;
font-size: 100%; font-size: 100%;
}
.field input {
height: 2.5vh; height: 2.5vh;
border-top: none; border-top: none;
border-left: none; border-left: none;
@ -64,6 +61,10 @@ a {
border-bottom: 1px gray solid; border-bottom: 1px gray solid;
} }
.field input[type="radio"], .field input[type="checkbox"] {
box-shadow: none;
}
.field input[type="submit"] { .field input[type="submit"] {
height: 4vh; height: 4vh;
border: none; border: none;

View file

@ -7,6 +7,9 @@ let addOrder = require("./utils/addOrder");
router.post("/", async (req, res) => { router.post("/", async (req, res) => {
if (!req.body.payment || ["lyfPay", "creditCard"].indexOf(req.body.payment) < 0)
return error(req, res, "Missing args !", 400);
let order = await addOrder(req, res, { let order = await addOrder(req, res, {
department: req.body.department, department: req.body.department,
firstName: req.body.firstName, firstName: req.body.firstName,

View file

@ -17,32 +17,55 @@ async function sendPayment(req, res, order) {
let baseUrl = `https://${req.hostname}/order`; let baseUrl = `https://${req.hostname}/order`;
let config = req.app.get("config").lyfPay; let config = req.app.get("config").lyfPay;
let url = config.url + "/Payment.aspx?"; let url = "";
let params = {};
let additionalData = JSON.stringify({
"callBackUrl": baseUrl+"/callback",
"callBackEmail":config.warningEmail
});
let params = { if (req.body.payment === "lyfPay") {
lang: "fr", url = config.url + "/Payment.aspx?";
version: "v2.0", params = {
timestamp: Math.floor(payment.date/1000), lang: "fr",
posUuid: config.posUuid, version: "v2.0",
shopReference: payment.shopReference, timestamp: Math.floor(payment.date/1000),
shopOrderReference: order.id, posUuid: config.posUuid,
deliveryFeesAmount: 0, shopReference: payment.shopReference,
amount: order.price*100, shopOrderReference: order.id,
currency: "EUR", deliveryFeesAmount: 0,
mode: "IMMEDIATE", amount: order.price*100,
onSuccess: baseUrl + "/success", currency: "EUR",
onCancel: baseUrl+"/cancel", mode: "IMMEDIATE",
onError: baseUrl+"/error", onSuccess: baseUrl + "/success",
additionalData: JSON.stringify({ onCancel: baseUrl+"/cancel",
"callBackUrl": baseUrl+"/callback", onError: baseUrl+"/error",
"callBackEmail":config.warningEmail additionalData: additionalData,
}), enforcedIdentification: false
enforcedIdentification: false };
}; } else if (req.body.payment === "creditCard") {
url = config.url + "/PaymentCb.aspx?";
params = {
lang: "fr",
posUuid: config.posUuid,
shopReference: payment.shopReference,
shopOrderReference: order.id,
deliveryFeesAmount: 0,
amount: order.price*100,
currency: "EUR",
onSuccess: baseUrl + "/success",
onError: baseUrl+"/error",
additionalData: additionalData,
callbackRequired: true,
mode: "IMMEDIATE"
};
}
params.mac = macCalculator(params, config.secureKey); params.mac = macCalculator(params, config.secureKey);
params.additionalDataEncoded = Buffer.from(params.additionalData).toString("base64"); params.additionalDataEncoded = Buffer.from(params.additionalData).toString("base64");
params.additionalData = undefined; params.additionalData = undefined;
if (req.body.payment === "creditCard")
params.version = "v2.0";
url += Object.keys(params) url += Object.keys(params)
.map(k => encodeURIComponent(k) + "=" + encodeURIComponent(params[k])) .map(k => encodeURIComponent(k) + "=" + encodeURIComponent(params[k]))

View file

@ -32,6 +32,13 @@ block content
a#add-order + a#add-order +
a#remove-order.hide - a#remove-order.hide -
h3=__("index.payment")
div.field.buttons
label(for="lyf_pay") LyfPay
input#lyf_pay(type="radio" name="payment" value="lyfPay" checked)
label(for="credit_card")=__("index.creditCard")
input#credit_card(type="radio" name="payment" value="creditCard")
div.field div.field
+submit(value=__("index.pay")) +submit(value=__("index.pay"))