Skip to content
Snippets Groups Projects
Commit 57244346 authored by Dominik Hebeler's avatar Dominik Hebeler
Browse files

fixed card payments

parent 24305f82
No related branches found
No related tags found
No related merge requests found
...@@ -293,6 +293,24 @@ class Paypal extends PaymentProcessor { ...@@ -293,6 +293,24 @@ class Paypal extends PaymentProcessor {
}); });
} }
// Client Token for handling credit card payments
async generateClientToken() {
const accessToken = await this.#generateAccessToken();
const response = await fetch(`${base}/v1/identity/generate-token`, {
method: "post",
headers: {
Authorization: `Bearer ${accessToken}`,
"Accept-Language": "en_US",
"Content-Type": "application/json",
},
});
const data = await response.json();
return data.client_token;
}
/** /**
* Turns class object into serializable data to store in redis db * Turns class object into serializable data to store in redis db
* *
......
...@@ -31,7 +31,7 @@ router.get("/:funding_source", async (req, res) => { ...@@ -31,7 +31,7 @@ router.get("/:funding_source", async (req, res) => {
res.header({ "Access-Control-Allow-Origin": "https://www.paypal.com" }); res.header({ "Access-Control-Allow-Origin": "https://www.paypal.com" });
if (req.params.funding_source === "card") { if (req.params.funding_source === "card") {
let client_token = await generateClientToken(); let client_token = await new Paypal().generateClientToken();
req.data.checkout.payment.paypal.client_token = client_token; req.data.checkout.payment.paypal.client_token = client_token;
} }
...@@ -119,18 +119,20 @@ router.post("/:funding_source/order/cancel", async (req, res) => { ...@@ -119,18 +119,20 @@ router.post("/:funding_source/order/cancel", async (req, res) => {
router.use("/card/order/capture", async (req, res, next) => { router.use("/card/order/capture", async (req, res, next) => {
console.debug(req.body.order_id); console.debug(req.body.order_id);
Order.LOAD_ORDER_FROM_ID(req.body.order_id) Order.LOAD_ORDER_FROM_ID(req.body.order_id)
.then((order) => loaded_order.getPaymentProcessor().verify3D()) .then((order) => order.getPaymentProcessor().verify_3D())
.then(() => next("route")) .then(() => next("route"))
.catch((reason) => { .catch((reason) => {
console.debug(reason); console.debug(reason);
res.status(400).json({ msg: "3D Verification Failed" }); res.status(400).json({
errors: [
{ type: "PAYPAL_CARD_3D_ERROR", msg: "3D Verification Failed" },
],
});
}); });
}); });
// capture payment & store order information or fullfill order // capture payment & store order information or fullfill order
router.post("/:funding_source/order/capture", async (req, res) => { router.post("/:funding_source/order/capture", async (req, res) => {
//res.status(200).json({ test: "test" });
//return;
Order.LOAD_ORDER_FROM_ID(req.body.order_id).then( Order.LOAD_ORDER_FROM_ID(req.body.order_id).then(
/** /**
* @param {Order} loaded_order * @param {Order} loaded_order
...@@ -155,7 +157,14 @@ router.post("/:funding_source/order/capture", async (req, res) => { ...@@ -155,7 +157,14 @@ router.post("/:funding_source/order/capture", async (req, res) => {
console.debug(reason); console.debug(reason);
res res
.status(400) .status(400)
.json({ errors: [{ msg: "Couldn't capture the payment" }] }); .json({
errors: [
{
type: "PAYMENT_NOT_COMPLETED_ERROR",
msg: "Couldn't capture the payment",
},
],
});
}); });
} }
); );
...@@ -339,22 +348,4 @@ async function refundPayment(capture_ids) { ...@@ -339,22 +348,4 @@ async function refundPayment(capture_ids) {
return Promise.all(promises); return Promise.all(promises);
} }
// Client Token for handling credit card payments
async function generateClientToken() {
const accessToken = await generateAccessToken();
const response = await fetch(`${base}/v1/identity/generate-token`, {
method: "post",
headers: {
Authorization: `Bearer ${accessToken}`,
"Accept-Language": "en_US",
"Content-Type": "application/json",
},
});
const data = await response.json();
return data.client_token;
}
// generate an access token using client id and app secret // generate an access token using client id and app secret
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment