-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
32 lines (25 loc) · 881 Bytes
/
server.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
const express = require("express");
const app = express();
// replace the test api key with your api publishable key
const hyper = require("@juspay-tech/hyperswitch-node")(
"snd_9d552d20e1f0411e8c9c45193cdc0677"
);
app.use(express.static("public"));
app.use(express.json());
const calculateAmount = (items) => {
// calculate the order amount using request
return 1300;
};
app.post("/create-payment-intent", async (request, response) => {
const { items } = request.body;
//create a payment using amount, currency, metadata etc.
const paymentIntent = await hyper.paymentIntents.create({
amount: calculateAmount(items),
currency: "USD",
});
//return clientSecret to initiate payment flow at the client
response.send({
clientSecret: paymentIntent.client_secret,
});
});
app.listen(4242, () => console.log("Node server listening on port 4242!"));