forked from ppkavinda/group-project
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
47 lines (39 loc) · 1.26 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
#!/usr/bin/env node
const express = require('express')
const bodyParser = require('body-parser')
const mysql = require('mysql')
const connection = mysql.createConnection({
host: 'localhost',
user: 'root',
password: '',
database: 'athwela'
})
const app = express()
const port = 3000
const redis = require('redis')
const client = redis.createClient()
app.use(bodyParser.json())
app.use(bodyParser.urlencoded({
extended: true
}))
app.post('/checkout/notify', (req, res) => {
let sql1 = `INSERT INTO payments
(id, amount, currency, status_code, order_id, created_at, updated_at)
VALUES (?, ?, ?, ?, ?, ?, ?)`
let sql2 = `UPDATE orders SET payment_id=?, status=1 WHERE id=?`
let data = [req.body.payment_id, req.body.payhere_amount, req.body.payhere_currency, req.body.status_code, req.body.order_id, new Date(), new Date()]
connection.query(sql1, data, function (err, result) {
if (err) {
console.log('err1', err)
}
})
connection.query(sql2, [req.body.payment_id, req.body.order_id], function (err, result) {
if (err) {
console.log('err2', err)
}
})
res.sendStatus(200)
})
app.listen(port, function () {
console.log('server started')
})