forked from hiukim/meteor-braintree-helper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
skwasha:braintree-helper.js
63 lines (49 loc) · 1.91 KB
/
skwasha:braintree-helper.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
Braintree = Npm.require('braintree');
BraintreeHelper = function() {
}
BraintreeHelper.getInstance = function() {
if (BraintreeHelper._instance === undefined) {
BraintreeHelper._instance = new BraintreeHelper();
}
return BraintreeHelper._instance;
}
BraintreeHelper.prototype.connect = function(options) {
this.gateway = new Braintree.connect(options);
}
BraintreeHelper.prototype.getGateway = function() {
return this.gateway;
}
BraintreeHelper.prototype.clientTokenGenerate = function(options, clientId) {
var wrappedCall = Meteor.wrapAsync(this.gateway.clientToken.generate, this.gateway.clientToken);
if (clientId) {
options.clientId = clientId;
}
var response = wrappedCall(options);
return response.clientToken
}
BraintreeHelper.prototype.createSale = function(options) {
var wrappedCall = Meteor.wrapAsync(this.gateway.transaction.sale, this.gateway.transaction);
return wrappedCall(options);
}
BraintreeHelper.prototype.createCustomer = function(options) {
var wrappedCall = Meteor.wrapAsync(this.gateway.customer.create, this.gateway.customer);
var response = wrappedCall(options);
return response
}
BraintreeHelper.prototype.createCreditCard = function(options) {
var wrappedCall = Meteor.wrapAsync(this.gateway.creditCard.create, this.gateway.creditCard);
return wrappedCall(options);
}
BraintreeHelper.prototype.createSubscription = function(options) {
var wrappedCall = Meteor.wrapAsync(this.gateway.subscription.create, this.gateway.subscription);
return wrappedCall(options);
}
BraintreeHelper.prototype.cancelSubscription = function(options) {
var wrappedCall = Meteor.wrapAsync(this.gateway.subscription.cancel, this.gateway.subscription);
return wrappedCall(options);
}
BraintreeHelper.prototype.getCustomer = function(id) {
var wrappedCall = Meteor.wrapAsync(this.gateway.customer.find, this.gateway.customer);
return wrappedCall(id);
}
//TODO: wrap up all the API calls