-
Notifications
You must be signed in to change notification settings - Fork 3
/
server.js
53 lines (43 loc) · 1.5 KB
/
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
const express = require("express");
const app = express();
app.use(express.static("public"));
app.use(express.json());
const calculateOrderAmount = (items) => {
return 1400;
};
app.post("/create-payment", async (req, res) => {
const { items } = req.body;
/*
If you have two or more “business_country” + “business_label” pairs configured in your Hyperswitch dashboard,
please pass the fields business_country and business_label in this request body.
For accessing more features, you can check out the request body schema for payments-create API here :
https://api-reference.hyperswitch.io/docs/hyperswitch-api-reference/60bae82472db8-payments-create
*/
const hyperswitch_url = "https://sandbox.hyperswitch.io/payments";
const hyperswitch_api_key = "HYPERSWITCH_API_KEY"; // Replace with your actual API key provided by Hyperswitch
const payload = {
amount: calculateOrderAmount(items),
currency: "USD",
};
const headers = {
"Content-Type": "application/json",
"Accept": "application/json",
"api-key": hyperswitch_api_key,
};
try {
const response = await fetch(hyperswitch_url, {
method: "POST",
headers: headers,
body: JSON.stringify(payload),
});
const data = await response.json();
res.send({
client_secret: data.client_secret,
});
} catch (error) {
res.send({
error: error.message || "Unknown error occurred",
});
}
});
app.listen(4242, () => console.log("Node server listening on port 4242!"));