diff --git a/.gitignore b/.gitignore index 7c7c127b11bb9583e93d7ff5acf7eae69bb58d10..5469ec4c0cd0b1b6d2d56fbde6dbb91bfe985926 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 7e9890b8b511cb876bee34c8b58340c5305a74c9..b4812dce9a73fcc44d8b3620262b36e8cef64ce3 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 8e4a6c462c4aa1f57893df12d53481a953c8c39a..c0351865500779064ebd7b94a6dcba78e604eaf1 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 77469daaf0f98b6b7988f4218d2fc52d68a0b8be..528e20c8884a6306f23e78ed4e16fa3650605d4b 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) => {