-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
50 lines (44 loc) · 1.42 KB
/
index.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
require('dotenv').config()
const express = require('express');
const { Client, CheckoutAPI } = require('@adyen/api-library');
const uuid = require('uuid');
const adyenClient = new Client({ apiKey: process.env.ADYEN_API_KEY, environment: "TEST" });
const adyenCheckoutApi = new CheckoutAPI(adyenClient);
const app = express();
app.use(express.json())
app.post('/payments/sessions', async (req, res) => {
console.log('/payments/sessions called');
adyenCheckoutApi.PaymentsApi.sessions({
merchantAccount: 'Google338ECOM',
amount: {
value: 1000,
currency: 'EUR'
},
returnUrl: 'https://your-company.com/checkout?shopperOrder=12xy..',
reference: uuid.v4()
}, {
idempotencyKey: uuid.v4()
})
.then(paymentSessionResponse => {
return res.json({
sessionData: paymentSessionResponse.sessionData,
id: paymentSessionResponse.id,
clientSecret: process.env.ADYEN_CLIENT_SECRET,
shopperLocale: 'en-US',
environment: 'Environment.TEST',
merchantName: 'Test merchant'
});
})
.catch(error => {
console.log(error)
return res.status(500).send(`Unable to call Adyen's /session API`);
});
});
app.post('/payments/webhook', async (req, res) => {
console.log(JSON.stringify(req.body, null, 2));
return res.status(200).send('[accepted]');
});
const port = parseInt(process.env.PORT) || 8080;
app.listen(port, () => {
console.log(`Listening on port ${port}`);
});