This repository has been archived by the owner on Sep 19, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
68 lines (56 loc) · 2.04 KB
/
main.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
var conf = require('./conf.json');
var rpc = require('node-json-rpc');
var express = require('express');
var engine = require('ejs-mate');
var httpAuth = require('http-auth');
var bodyParser = require('body-parser');
var Pay = require('./pay_methods');
var Auth = require('./auth_controll');
var Manager = require('./manager_methods');
var serv = new rpc.Server({
port: conf.payPort,
host: conf.payHost,
path: conf.payPath,
strict: true,
auth: {
ext: {
users: Auth.checkPaymeUser
}
}
});
//Payme API methods
serv.addMethod('CheckPerformTransaction', Pay.CheckPerformTransaction);
serv.addMethod('CreateTransaction', Pay.CreateTransaction);
serv.addMethod('PerformTransaction', Pay.PerformTransaction);
serv.addMethod('CancelTransaction', Pay.CancelTransaction);
serv.addMethod('CheckTransaction', Pay.CheckTransaction);
serv.addMethod('GetStatement', Pay.GetStatement);
serv.addMethod('ChangePassword', Pay.ChangePassword);
serv.addMethod('ShowWallet', function (para, callback) {
callback(null, {no: 4654646, amount: 12000, ownr: {name: "Kseniya", famaly: "Andreeva"}});
});
serv.start(function (error) {
if (error)
throw error;
else
console.log('Server PaymeAPI start on ' + conf.payHost+':'+conf.payPort+conf.payPath);
});
var app = express();
var basic = httpAuth.basic({realm: 'SUPER SECRET STUFF'},Auth.checkUser);
var authMiddleware = httpAuth.connect(basic);
app.engine('ejs', engine);
app.set('view engine', 'ejs');
app.set('views', './views');
app.use(express.static('./public'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended: true}));
app.get('/', authMiddleware, function(req, res){
res.render('home');
});
app.get('/history/:no', authMiddleware, Manager.walletHistory);
app.get('/wallet/:no', authMiddleware, Manager.walletInfo);
app.post('/wallet/new', authMiddleware, Manager.addWallet);
app.post('/payout', authMiddleware, Manager.doPayout);
app.listen(conf.managerPort, function () {
console.log('express start on port ', conf.managerPort);
});