-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathangular-mangopay.js
55 lines (45 loc) · 1.57 KB
/
angular-mangopay.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
/*
* angular-mangopay v0.0.1
* (c) 2014 Jacopo Cappelli http://www.keepup.pro
* License: MIT
*/
'use strict';
angular.module('jcappelli.mangopay', [])
.factory('mangopay', function ($rootScope, $http) {
return {
sendData: function(cardRegistrationURL, preregistrationData, accessKey, cardNumber, cardExpirationDate, cardCvx , onSuccess, onError) {
console.log("senddata");
var datiMangoPay = {
data: preregistrationData,
accessKeyRef: accessKey,
cardNumber: cardNumber,
cardExpirationDate: cardExpirationDate,
cardCvx: cardCvx
};
console.log("Dati mango pay:"+JSON.stringify(datiMangoPay));
var parametriMango = "";
for(key in datiMangoPay) {
parametriMango += (parametriMango.length > 0 ? '&' : '' ) + key + "=" + encodeURIComponent(datiMangoPay[key]);
}
console.log("Parametri:"+parametriMango);
$http.defaults.useXDomain = true;
delete $http.defaults.headers.common['X-Requested-With'];
return $http({
url: cardRegistrationURL,
method: 'POST',
data: parametriMango,
headers:{'Content-Type':'application/x-www-form-urlencoded; charset=UTF-8'}
})
.success(function(data, status, headers, config) {
$rootScope.$apply(function () {
onSuccess.apply(that, args);
});
}).
error(function(data, status, headers, config) {
$rootScope.$apply(function () {
onError.apply(that, args);
});
});
},
};
});