-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathapp.js
136 lines (111 loc) · 2.85 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
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
const express = require('express');
const SSLCommerzPayment = require("sslcommerz");
const bodyParser = require('body-parser')
const app = express()
require('dotenv').config()
// parse application/x-www-form-urlencoded
app.use(bodyParser.urlencoded({ extended: false }))
// parse application/json
app.use(bodyParser.json());
app.get('/', async (req, res) => {
/**
* Root url response
*/
return res.status(200).json({
message: "Welcome to sslcommerz app",
url: `${process.env.ROOT}/ssl-request`
})
})
app.get('/ssl-request', async (req, res) => {
/**
* Create ssl session request
*/
const data = {
total_amount: 100,
currency: 'BDT',
tran_id: 'REF123',
success_url: `${process.env.ROOT}/ssl-payment-success`,
fail_url: `${process.env.ROOT}/ssl-payment-fail`,
cancel_url: `${process.env.ROOT}/ssl-payment-cancel`,
shipping_method: 'No',
product_name: 'Computer.',
product_category: 'Electronic',
product_profile: 'general',
cus_name: 'Customer Name',
cus_email: '[email protected]',
cus_add1: 'Dhaka',
cus_add2: 'Dhaka',
cus_city: 'Dhaka',
cus_state: 'Dhaka',
cus_postcode: '1000',
cus_country: 'Bangladesh',
cus_phone: '01711111111',
cus_fax: '01711111111',
multi_card_name: 'mastercard',
value_a: 'ref001_A',
value_b: 'ref002_B',
value_c: 'ref003_C',
value_d: 'ref004_D',
ipn_url: `${process.env.ROOT}/ssl-payment-notification`,
};
const sslcommerz = new SSLCommerzPayment(process.env.STORE_ID, process.env.STORE_PASSWORD, false) //true for live default false for sandbox
sslcommerz.init(data).then(data => {
//process the response that got from sslcommerz
//https://developer.sslcommerz.com/doc/v4/#returned-parameters
if (data?.GatewayPageURL) {
return res.status(200).redirect(data?.GatewayPageURL);
}
else {
return res.status(400).json({
message: "Session was not successful"
});
}
});
});
app.post("/ssl-payment-notification", async (req, res) => {
/**
* If payment notification
*/
return res.status(200).json(
{
data: req.body,
message: 'Payment notification'
}
);
})
app.post("/ssl-payment-success", async (req, res) => {
/**
* If payment successful
*/
return res.status(200).json(
{
data: req.body,
message: 'Payment success'
}
);
})
app.post("/ssl-payment-fail", async (req, res) => {
/**
* If payment failed
*/
return res.status(200).json(
{
data: req.body,
message: 'Payment failed'
}
);
})
app.post("/ssl-payment-cancel", async (req, res) => {
/**
* If payment cancelled
*/
return res.status(200).json(
{
data: req.body,
message: 'Payment cancelled'
}
);
})
app.listen(process.env.PORT, () =>
console.log(`ssl app listening on port ${process.env.PORT}!`),
);