Add credit card payment method
This commit is contained in:
parent
73a9aae4e4
commit
b10424d158
6 changed files with 64 additions and 26 deletions
|
@ -29,7 +29,9 @@
|
|||
"index": {
|
||||
"welcome": "Welcome to Sandwiches Order Doua",
|
||||
"day": "Day",
|
||||
"pay": "Pay"
|
||||
"pay": "Pay",
|
||||
"payment": "Payment method",
|
||||
"creditCard": "Credit card"
|
||||
},
|
||||
"login": {
|
||||
"title": "Login",
|
||||
|
|
|
@ -29,7 +29,9 @@
|
|||
"index": {
|
||||
"welcome": "Bienvenue sur Sandwiches Order Doua",
|
||||
"day": "Jour",
|
||||
"pay": "Payer"
|
||||
"pay": "Payer",
|
||||
"payment": "Mode de paiement",
|
||||
"creditCard": "CB"
|
||||
},
|
||||
"login": {
|
||||
"title": "Se connecter",
|
||||
|
|
|
@ -54,9 +54,6 @@ a {
|
|||
margin: auto;
|
||||
width: 100%;
|
||||
font-size: 100%;
|
||||
}
|
||||
|
||||
.field input {
|
||||
height: 2.5vh;
|
||||
border-top: none;
|
||||
border-left: none;
|
||||
|
@ -64,6 +61,10 @@ a {
|
|||
border-bottom: 1px gray solid;
|
||||
}
|
||||
|
||||
.field input[type="radio"], .field input[type="checkbox"] {
|
||||
box-shadow: none;
|
||||
}
|
||||
|
||||
.field input[type="submit"] {
|
||||
height: 4vh;
|
||||
border: none;
|
||||
|
|
|
@ -7,6 +7,9 @@ let addOrder = require("./utils/addOrder");
|
|||
|
||||
|
||||
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, {
|
||||
department: req.body.department,
|
||||
firstName: req.body.firstName,
|
||||
|
|
|
@ -17,32 +17,55 @@ async function sendPayment(req, res, order) {
|
|||
|
||||
let baseUrl = `https://${req.hostname}/order`;
|
||||
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 = {
|
||||
lang: "fr",
|
||||
version: "v2.0",
|
||||
timestamp: Math.floor(payment.date/1000),
|
||||
posUuid: config.posUuid,
|
||||
shopReference: payment.shopReference,
|
||||
shopOrderReference: order.id,
|
||||
deliveryFeesAmount: 0,
|
||||
amount: order.price*100,
|
||||
currency: "EUR",
|
||||
mode: "IMMEDIATE",
|
||||
onSuccess: baseUrl + "/success",
|
||||
onCancel: baseUrl+"/cancel",
|
||||
onError: baseUrl+"/error",
|
||||
additionalData: JSON.stringify({
|
||||
"callBackUrl": baseUrl+"/callback",
|
||||
"callBackEmail":config.warningEmail
|
||||
}),
|
||||
enforcedIdentification: false
|
||||
};
|
||||
if (req.body.payment === "lyfPay") {
|
||||
url = config.url + "/Payment.aspx?";
|
||||
params = {
|
||||
lang: "fr",
|
||||
version: "v2.0",
|
||||
timestamp: Math.floor(payment.date/1000),
|
||||
posUuid: config.posUuid,
|
||||
shopReference: payment.shopReference,
|
||||
shopOrderReference: order.id,
|
||||
deliveryFeesAmount: 0,
|
||||
amount: order.price*100,
|
||||
currency: "EUR",
|
||||
mode: "IMMEDIATE",
|
||||
onSuccess: baseUrl + "/success",
|
||||
onCancel: baseUrl+"/cancel",
|
||||
onError: baseUrl+"/error",
|
||||
additionalData: additionalData,
|
||||
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.additionalDataEncoded = Buffer.from(params.additionalData).toString("base64");
|
||||
params.additionalData = undefined;
|
||||
if (req.body.payment === "creditCard")
|
||||
params.version = "v2.0";
|
||||
|
||||
url += Object.keys(params)
|
||||
.map(k => encodeURIComponent(k) + "=" + encodeURIComponent(params[k]))
|
||||
|
|
|
@ -32,6 +32,13 @@ block content
|
|||
a#add-order +
|
||||
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
|
||||
+submit(value=__("index.pay"))
|
||||
|
||||
|
|
Reference in a new issue