diff options
author | Mateja <mail@matejamaric.com> | 2021-07-16 02:20:32 +0200 |
---|---|---|
committer | Mateja <mail@matejamaric.com> | 2021-07-16 02:20:32 +0200 |
commit | 3f05bd208cba2d57446ad95d8383be2ed1089c87 (patch) | |
tree | 3da912888bcf146a77192bc5effc59a465b6535e /server/controllers | |
parent | 40358139a8ad1cba015c109dde915d6d8955fd99 (diff) | |
download | mevn-ecommerce-3f05bd208cba2d57446ad95d8383be2ed1089c87.tar.gz mevn-ecommerce-3f05bd208cba2d57446ad95d8383be2ed1089c87.zip |
Setup and capture test transactions.
Diffstat (limited to 'server/controllers')
-rw-r--r-- | server/controllers/transaction.js | 59 |
1 files changed, 59 insertions, 0 deletions
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); } }; |