-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
165 lines (142 loc) · 4.13 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
const express = require("express");
const app = express();
const axios = require("axios");
const { json } = require("express");
// This is a public sample test API key.
// Don’t submit any personally identifiable information in requests made with this key.
// Sign in to see your own test API key embedded in code samples.
//const orca = require("stripe")('sk_test_51KP0OALGEyT9T908osoVeWhMnrKSg6YibXTA84rLY5gGWvahr3uHZhAjKGXFicuNgPbZv2uYhIiylKsDHpKBcNuz00da02MYkB');
// const orca = require("@juspay-tech/hyper-node")('snd_c691ade6995743bd88c166ba509ff5da');
let apiKey = "AQEqhmfxLonIaRxDw0m/n3Q5qf3VYp5eHZJTfEBKcCjMgy67uj+B473X9LE3EMFdWw2+5HzctViMSCJMYAc=-HHyfbKKOmMLrYC66SIXv7BLBra9y3aAV94z2eUen1yY=-&Bb>?VTWADF7D$h("
let merchantAccount = "JuspayDEECOM"
app.use(express.json()); // Middleware to parse JSON request bodies
app.post("/sessions", async (req, res) => {
// const { items, country } = req.body;
const config = {
headers: { 'x-API-key': apiKey }
};
const body = {
"merchantAccount": merchantAccount,
"amount": {
"value": 1000,
"currency": "EUR"
},
"returnUrl": "https://your-company.com/checkout?shopperOrder=12xy..",
"reference": "YOUR_PAYMENT_REFERENCE",
"countryCode": "NL"
}
axios.post(
'https://checkout-test.adyen.com/v70/sessions',
body,
config
).then(resp => {
console.log("==> Resp", resp.data)
res.send(resp.data);
}).catch(err => {
console.log("==> Err", err.response.data)
})
})
app.post("/paymentMethods", async (req, res) => {
// const { items, country } = req.body;
const config = {
headers: { 'x-API-key': apiKey }
};
const body = {
"merchantAccount": merchantAccount,
"countryCode": "NL",
"amount": {
"currency": "EUR",
"value": 1000
},
"channel": "Web",
"shopperLocale": "nl-NL"
}
axios.post(
'https://checkout-test.adyen.com/v70/paymentMethods',
body,
config
).then(resp => {
res.send(resp.data);
}).catch(err => {
console.log("==> Err", err.response.data)
})
})
app.post("/payments", async (req, res) => {
// const { items, country } = req.body;
const config = {
headers: { 'x-API-key': apiKey }
};
// console.log("===> req BOdy", req.body)
let data = req.body.data
const body = {
"amount": {
"currency": "EUR",
"value": 1000
},
"reference": "YOUR_ORDER_NUMBER",
"returnUrl": "https://adyen.serveo.net/success",
"merchantAccount": merchantAccount,
"paymentMethod": data.paymentMethod,
"browserInfo": data.browserInfo,
"channel": "Web",
"origin": req.body.origin,
"billingAddress": {
"country": "NL",
"city": "Capital",
"houseNumberOrName": "1",
"postalCode": "1012 DJ",
"stateOrProvince": "DF",
"street": "Main St"
},
"shopperEmail": "s.hopper@example.com",
"shopperIP": "192.0.2.1",
"deliveryAddress": {
"country": "NL",
"city": "Capital",
"houseNumberOrName": "1",
"postalCode": "1012 DJ",
"stateOrProvince": "DF",
"street": "Main St"
}
}
console.log("===> isThreeDS", req.body.isThreeDS)
if (req.body.isThreeDS) {
body["authenticationData"] = {
"threeDSRequestData": {
"nativeThreeDS": "preferred"
}
}
}
axios.post(
'https://checkout-test.adyen.com/v70/payments',
body,
config
).then(resp => {
console.log("==> Resp", resp.data)
res.send(resp.data);
}).catch(err => {
console.log("==> Err", err.response.data)
})
})
app.post("/paymentDetails", async (req, res) => {
// const { items, country } = req.body;
const config = {
headers: { 'x-API-key': apiKey }
};
// console.log("===> req BOdy", req.body)
let data = req.body.data
console.log("==> data", data)
console.log("==> Req", req.body)
const body = data
axios.post(
'https://checkout-test.adyen.com/v70/payments/details',
body,
config
).then(resp => {
console.log("==> paymentDetails Response", resp.data)
res.send(resp.data);
}).catch(err => {
console.log("==> Err", err.response.data)
})
})
app.listen(4242, () => console.log("Node server listening on port 4242!"));