forked from jeffcarp/braintree-angular
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbraintree-factory.js
52 lines (42 loc) · 1.19 KB
/
braintree-factory.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
var braintree = require('braintree-web');
function braintreeFactory(clientTokenPath, $http) {
var $braintree = {};
$braintree.clientToken = null;
Object.keys(braintree).forEach(function(key) {
$braintree[key] = braintree[key];
});
function getClientToken() {
return $http.get(clientTokenPath);
}
$braintree.getClientToken = function() {
return getClientToken();
};
$braintree.setupDropin = function(options) {
getClientToken()
.success(function(token) {
braintree.setup(token, 'dropin', options);
})
.error(function(data, status) {
console.error('error fetching client token at '+clientTokenPath, data, status);
});
};
$braintree.setupPayPal = function(options) {
getClientToken()
.success(function(token) {
braintree.setup(token, 'paypal', options);
})
.error(function(data, status) {
console.error('error fetching client token at '+clientTokenPath, data, status);
});
};
return $braintree;
}
var fullBraintreeFactory = [
'clientTokenPath',
'$http',
braintreeFactory
];
module.exports = {
braintreeFactory: braintreeFactory,
fullBraintreeFactory: fullBraintreeFactory
};