From 3f05bd208cba2d57446ad95d8383be2ed1089c87 Mon Sep 17 00:00:00 2001 From: Mateja Date: Fri, 16 Jul 2021 02:20:32 +0200 Subject: Setup and capture test transactions. --- server/controllers/transaction.js | 59 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) (limited to 'server/controllers') diff --git a/server/controllers/transaction.js b/server/controllers/transaction.js index a2226be..c540a7b 100644 --- a/server/controllers/transaction.js +++ b/server/controllers/transaction.js @@ -5,11 +5,70 @@ const {siteUrl} = require('../config/env'); module.exports = { async setup(req, res) { + let transactionData = { + intent: 'CAPTURE', + purchase_units: [{ + amount: { + currency_code: 'USD', + value: '180.00', + breakdown: { + item_total: { + currency_code: "USD", + value: "180.00" + }, + } + }, + items: [ + { + name: "T-Shirt", + unit_amount: { + currency_code: "USD", + value: "90.00" + }, + quantity: "1" + }, + { + name: "Shoes", + unit_amount: { + currency_code: "USD", + value: "45.00" + }, + quantity: "2" + } + ] + }] + }; + const request = new paypal.orders.OrdersCreateRequest(); + request.prefer("return=representation"); + request.requestBody(transactionData); + + let order; + try { + order = await paypalClient.execute(request); + } catch (err) { + console.error(err); + return res.sendStatus(500); + } + console.log(order); + + res.status(200).json({orderId: order.result.id}); }, async capture(req, res) { + const request = new paypal.orders.OrdersCaptureRequest(req.body.orderId); + request.requestBody({}); + + try { + const capture = await paypalClient.execute(request); + console.log(capture); + console.log(capture.result); + } catch (err) { + console.error(err); + return res.sendStatus(500); + } + res.sendStatus(200); } }; -- cgit v1.2.3