-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
56 lines (50 loc) · 1.58 KB
/
index.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
var request = require('request');
Payum = function(serverUrl) {
var payum = this;
payum.serverUrl = serverUrl;
payum.payment = {
create: function(payment, callback) {
var options = {
uri: payum.serverUrl + '/payments',
body: payment,
json: true
};
request.post(options, function (error, response, body) {
if (!error && response.statusCode == 201) {
callback(null, body.payment);
} else {
callback(error);
}
});
},
get: function(id, callback) {
request.get(payum.serverUrl + '/payments/' + id, function (error, response, body) {
if (!error && response.statusCode == 200) {
var data = JSON.parse(body);
callback(null, data.payment);
} else {
callback(error);
}
});
}
};
payum.token = {
create: function(token, callback) {
var options = {
uri: payum.serverUrl + '/tokens',
body: token,
json: true
};
request.post(options, function (error, response, body) {
if (!error && response.statusCode == 201) {
callback(null, body.token);
} else {
callback(error);
}
});
}
};
};
module.exports = function(serverUrl) {
return new Payum(serverUrl);
};