-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathWebToPay.js
More file actions
executable file
·66 lines (40 loc) · 1.46 KB
/
Copy pathWebToPay.js
File metadata and controls
executable file
·66 lines (40 loc) · 1.46 KB
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
// Constructor
function WebToPay(cred) {
this.projectid = cred.projectId;
this.sign_password = cred.signPassword;
this.orderid = '';
this.accepturl = '';
this.cancelurl = '';
this.callbackurl = '';
this.version = '1.6';
this.test = '1';
this.payUrl = 'https://www.paysera.com/pay/';
this.xmlUrl = 'https://www.paysera.com/new/api/paymentMethods/';
this.key = 'http://downloads.paysera.com/download/public.key';
}
// class methods
WebToPay.prototype.buildRequest = function() {
var url64 = require("querystring");
var crypto = require('crypto');
var obj = JSON.parse(JSON.stringify(this));
delete obj.sign_password;
delete obj.payUrl;
delete obj.xmlUrl;
var a64 = url64.stringify(obj);
var data64 = new Buffer(a64).toString('base64');
data64 = data64.replace('/', '_');
data = data64.replace('+', '-');
var sign = crypto.createHash('md5').update(data + this.sign_password).digest('hex');
return {'data':data, 'sign':sign};
};
WebToPay.prototype.checkCallback = function(req) {
var crypto = require('crypto');
var ss1 = crypto.createHash('md5').update(req.data + this.sign_password).digest('hex');
var check = req.ss1 == ss1?1:0;
return check;
};
WebToPay.prototype.createUrl = function(req) {
return this.payUrl + '?data='+req.data+'&sign='+req.sign;
}
// export the class
module.exports = WebToPay;