-
Notifications
You must be signed in to change notification settings - Fork 5
/
instamojo.js
56 lines (51 loc) · 2 KB
/
instamojo.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
// Variables exported by this module can be imported by other packages and
// applications. See instamojo-tests.js for an example of importing.
export const name = 'instamojo';
Instamojo = function(api_key, auth_token, endpoint){
/*
* Get you `api_key` and `auth_token` from the https://www.instamojo.com/developers/ page.
* Here `endpoint` can be used to specify different API domain, for
* example: https://test.instamojo.com/api/1.1/
*/
var endpoint = typeof endpoint !== 'undefined' ? endpoint : 'https://www.instamojo.com/api/1.1/';
var headers = {'X-Api-Key': api_key, 'X-Auth-Token': auth_token};
var sync_get = Meteor.wrapAsync(HTTP.get);
var sync_post = Meteor.wrapAsync(HTTP.post);
return {
createRequest: function(payload){
var url = endpoint + 'payment-requests/';
var result = sync_post(url, {params: payload, headers: headers});
return result.data;
},
listRequest: function(){
var url = endpoint + 'payment-requests/';
var result = sync_get(url, {headers: headers});
return result.data;
},
getRequestDetails: function(id){
var url = endpoint + 'payment-requests/' + id + '/';
var result = sync_get(url, {headers: headers});
return result.data;
},
getPaymentDetails: function(payment_request_id, payment_id){
var url = endpoint + 'payment-requests/' + payment_request_id + '/' + payment_id + '/';
var result = sync_get(url, {headers: headers});
return result.data;
},
createRefund:function(payload){
var url = enpoint + 'refunds/';
var result = sync_post(url, {params: payload, headers: headers});
return result.data;
},
listRefund:function(){
var url = endpoint + 'refunds/';
var result = sync_get(url, {headers: headers});
return result.data;
},
getRefundDetails:function(id){
var url = endpoint + '/refunds/' + id + '/';
var result = sync_get(url, {headers: headers});
return result.data;
}
};
}