-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
63 lines (53 loc) · 1.72 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
51
52
53
54
55
56
57
58
59
60
61
62
63
const express = require('express');
var cors = require('cors')
const grantToken = require('./functions/grant_tocken');
const createPayment = require('./functions/create_payment');
const executePayment = require('./functions/execute_payment');
const app = express();
app.use(express.json());
app.use(cors());
app.get('/', (req, res) => {
res.send('Bkash Payment Gateway Request API');
});
app.post('/initiate', (req, res) => {
const { payerReference, callbackURL, amount, merchantInvoiceNumber } = req.body;
grantToken()
.then((id_token) => {
const paymentBody = {
mode: '0011',
payerReference: payerReference,
callbackURL: callbackURL,
amount: amount,
currency: 'BDT',
intent: 'sale',
merchantInvoiceNumber: merchantInvoiceNumber
};
createPayment(id_token, paymentBody)
.then((response) => {
res.send(response);
})
.catch((error) => {
res.send(`Error: ${error.message}`);
});
})
.catch((error) => {
res.send(`Error: ${error.message}`);
});
});
app.post('/execute', (req, res) => {
const { paymentID } = req.body;
grantToken()
.then((id_token) => {
executePayment(paymentID, id_token)
.then((response) => {
res.send(response);
})
.catch((error) => {
res.send(`Error: ${error.message}`);
});
})
.catch((error) => {
res.send(`Error: ${error.message}`);
});
});
app.listen(3000);