-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.js
67 lines (55 loc) · 1.61 KB
/
app.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
const express = require('express');
var morgan = require('morgan');
var morganBody = require('morgan-body');
const bodyParser = require('body-parser');
var rp = require('request-promise');
const app = express();
const port = 3000;
app.use(morgan('combined'));
morganBody(app);
app.use(express.static('public'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
async function getToken() {
var options = {
method: 'POST',
url: 'https://checkout.sandbox.bka.sh/v1.2.0-beta/checkout/token/grant',
headers: {
password: 'sandboxTestPassword',
username: 'sandboxTestUser'
},
json: { app_key: 'sandboxAppKay', app_secret: 'sandboxAppSecret' }
};
const tokenObj = await rp(options);
return tokenObj.id_token;
}
app.post('/createRequest', async (req, res) => {
const reqBody = req.body;
const token = await getToken();
var options = {
method: 'POST',
url: 'https://checkout.sandbox.bka.sh/v1.2.0-beta/checkout/payment/create',
headers: {
'x-app-key': 'sandboxAppKay',
authorization: token
},
json: reqBody
};
const body = await rp(options);
res.json(body);
});
app.post('/executeRequest', async (req, res) => {
const paymentID = req.body.paymentID;
const token = await getToken();
var options = {
method: 'POST',
url: `https://checkout.sandbox.bka.sh/v1.2.0-beta/checkout/payment/execute/${paymentID}`,
headers: {
'x-app-key': 'sandboxAppKay',
authorization: token
}
};
const body = await rp(options);
res.json(body);
});
app.listen(port, () => console.log(`App listening on port ${port}!`));