forked from defri-ansyah/Ankasa-API
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
96 lines (86 loc) · 2.35 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
require('dotenv').config()
const express = require('express')
const morgan = require('morgan')
const app = express()
const PORT = process.env.DB_PORT || 3000
const bodyParser = require('body-parser')
var cors = require('cors')
const routes = require('./src/routes/index')
const response = require('./src/helpers/response');
const cron = require('node-cron');
app.use(cors())
app.use(bodyParser.urlencoded({ extended: false }))
app.use(bodyParser.json())
app.use(morgan('dev'))
app.use('/images', express.static('./uploads'))
// routes
app.use('/api', routes)
// error handling
app.use((err, req, res, next) => {
response(res, null, { status: err.status || 'Failed', statusCode: err.statusCode || 400 }, { message: err.message })
})
const ticketingController = require('./src/controllers/ticketingControllers');
const midtransClient = require('midtrans-client');
// Create Core API instance
const coreApi = new midtransClient.CoreApi({
isProduction: false,
serverKey: process.env.MIDTRANS_SERVER_KEY,
clientKey: process.env.MIDTRANS_CLIENT_KEY
});
let parameter = {
"payment_type": "bank_transfer",
"transaction_details": {
"gross_amount": 44000,
"order_id": "order-101c-{{$timestamp}}"
},
"customer_details": {
"email": "noreply@example.com",
"first_name": "budi",
"last_name": "utomo",
"phone": "+6281 1234 1234"
},
"item_details": [
{
"id": "item01",
"price": 21000,
"quantity": 1,
"name": "Ayam Zozozo"
},
{
"id": "item02",
"price": 23000,
"quantity": 1,
"name": "Ayam Xoxoxo"
}
],
"bank_transfer": {
"bank": "bca",
"va_number": "12345678901",
"free_text": {
"inquiry": [
{
"id": "Your Custom Text in ID language",
"en": "Your Custom Text in EN language"
}
],
"payment": [
{
"id": "Your Custom Text in ID language",
"en": "Your Custom Text in EN language"
}
]
}
}
};
// charge transaction
// coreApi.charge(parameter)
// .then((chargeResponse) => {
// console.log('chargeResponse:');
// console.log(chargeResponse);
// });
cron.schedule('* * * * *', () => {
console.log('background process running')
ticketingController.confrimPayment(coreApi)
}).start()
app.listen(PORT, () => console.log(`server is running port ${PORT}
http://localhost:${PORT}`))