From 4554aad28769769b2a79a23ba18899bb1c09f22b Mon Sep 17 00:00:00 2001 From: Dominik Hebeler <dominik@suma-ev.de> Date: Wed, 14 Dec 2022 14:57:40 +0100 Subject: [PATCH] prepared config for production --- .gitignore | 1 + pass/resources/js/checkout_paypal.js | 11 +++++++++-- pass/routes/checkout/checkout.js | 4 +--- pass/routes/checkout/paypal.js | 25 ++++++++++++------------- 4 files changed, 23 insertions(+), 18 deletions(-) diff --git a/.gitignore b/.gitignore index 7c7c127..5469ec4 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ pass/config/development.json +pass/config/production.json \ No newline at end of file diff --git a/pass/resources/js/checkout_paypal.js b/pass/resources/js/checkout_paypal.js index 7e9890b..b4812dc 100644 --- a/pass/resources/js/checkout_paypal.js +++ b/pass/resources/js/checkout_paypal.js @@ -95,7 +95,6 @@ function get_paypal_checkout_data(funding_source) { headers: { "Content-Type": "application/json;charset=utf-8", }, - body: JSON.stringify({}), }) .then((response) => response.json()) .then((order) => { @@ -241,6 +240,9 @@ function loadCardPayment(checkout_data) { document .getElementById("paypal-card-errors-3d") .classList.remove("hidden"); + cancelPayment( + document.getElementById("paypal-checkout").dataset.order_id + ); } else if ( error.type && error.type === "PAYMENT_NOT_COMPLETED_ERROR" @@ -249,6 +251,9 @@ function loadCardPayment(checkout_data) { document .getElementById("paypal-card-errors-generic") .classList.remove("hidden"); + cancelPayment( + document.getElementById("paypal-checkout").dataset.order_id + ); } else { // Capture was not yet possible ToDo redirect user to Order // There is a chance that webhooks will capture the payment @@ -263,7 +268,9 @@ function loadCardPayment(checkout_data) { }) .catch((reason) => { reason.details.forEach((detail) => { - console.log(detail); + cancelPayment( + document.getElementById("paypal-checkout").dataset.order_id + ); if (detail.issue === "CARD_TYPE_NOT_SUPPORTED") { document .getElementById("paypal-card-errors-invalid-card") diff --git a/pass/routes/checkout/checkout.js b/pass/routes/checkout/checkout.js index 8e4a6c4..c035186 100644 --- a/pass/routes/checkout/checkout.js +++ b/pass/routes/checkout/checkout.js @@ -35,9 +35,7 @@ router.get( order_id: await generate_unique_order_id(), payments: { paypal: { - client_id: config.get( - `payments.paypal.${process.env.NODE_ENV}.client_id` - ), + client_id: config.get(`payments.paypal.client_id`), }, }, }; diff --git a/pass/routes/checkout/paypal.js b/pass/routes/checkout/paypal.js index 77469da..528e20c 100644 --- a/pass/routes/checkout/paypal.js +++ b/pass/routes/checkout/paypal.js @@ -5,11 +5,9 @@ const config = require("config"); const Order = require("../../app/Order.js"); const Key = require("../../app/Key.js"); -const CLIENT_ID = config.get( - `payments.paypal.${process.env.NODE_ENV}.client_id` -); -const APP_SECRET = config.get(`payments.paypal.${process.env.NODE_ENV}.secret`); -const base = config.get(`payments.paypal.${process.env.NODE_ENV}.base`); +const CLIENT_ID = config.get(`payments.paypal.client_id`); +const APP_SECRET = config.get(`payments.paypal.secret`); +const base = config.get(`payments.paypal.base`); const webhook_redis_key = "checkout_paypal_webhook_id"; router.use("/", async (req, res, next) => { @@ -17,9 +15,7 @@ router.use("/", async (req, res, next) => { req.data.checkout.payment = { provider: "paypal", paypal: { - client_id: config.get( - `payments.paypal.${process.env.NODE_ENV}.client_id` - ), + client_id: config.get(`payments.paypal.client_id`), }, }; } @@ -162,7 +158,8 @@ router.post("/:funding_source/order/capture", async (req, res) => { .then(() => loaded_order.setPaymentCompleted(true)) .then(() => Key.CHARGE_KEY(req.data.key.key, loaded_order.getAmount())) .then(() => { - let redirect_url = "/key/" + req.data.key.key; + let redirect_url = + "/key/" + req.data.key.key + "/orders/" + loaded_order.getOrderID(); res.status(200).json({ redirect_url: redirect_url, order: { @@ -527,9 +524,11 @@ async function verifyWebhook() { } }); if (webhook_id !== undefined) { - return redis_client.set(webhook_redis_key, webhook_id).then(() => { - throw "WEBHOOK_ALREADY_REGISTERED"; // Webhook already registered - }); + return redis_client + .setex(webhook_redis_key, 3600, webhook_id) + .then(() => { + throw "WEBHOOK_ALREADY_REGISTERED"; // Webhook already registered + }); } else { // Webhook does not yet exist console.log("Webhook does not yet exist"); @@ -563,7 +562,7 @@ async function verifyWebhook() { }) .then((response_data) => { console.log(JSON.stringify(response_data)); - redis_client.set(webhook_redis_key, response_data.id); + redis_client.setex(webhook_redis_key, 3600, response_data.id); }); }) .catch((reason) => { -- GitLab