|
1
|
|
|
/** |
|
2
|
|
|
* Namespaces |
|
3
|
|
|
* @type {Object} |
|
4
|
|
|
*/ |
|
5
|
|
|
var PAYONE = {}; |
|
6
|
|
|
PAYONE.Handler = {}; |
|
7
|
|
|
PAYONE.Service = {}; |
|
8
|
|
|
PAYONE.Validation = {}; |
|
9
|
|
|
|
|
10
|
|
|
/** |
|
11
|
|
|
* A Gatewaay to send Requests to Payone |
|
12
|
|
|
* |
|
13
|
|
|
* @param data |
|
|
|
|
|
|
14
|
|
|
* @constructor |
|
15
|
|
|
*/ |
|
16
|
|
|
PAYONE.Gateway = function (config, callback) { |
|
17
|
|
|
this.config = config; |
|
18
|
|
|
this.callback = callback; |
|
19
|
|
|
this.request = ''; |
|
20
|
|
|
this.response = ''; |
|
21
|
|
|
|
|
22
|
|
|
this.call = function (data) { |
|
23
|
|
|
|
|
24
|
|
|
this.initRequest(data); |
|
25
|
|
|
|
|
26
|
|
|
// Options |
|
27
|
|
|
var options = { |
|
28
|
|
|
callback_function_name:'PAYONE.Callback.invoke' |
|
29
|
|
|
}; |
|
30
|
|
|
|
|
31
|
|
|
// AJAX Callback |
|
32
|
|
|
PAYONE.Callback.gateway = this; |
|
33
|
|
|
PAYONE.Callback.callback = this.callback; |
|
34
|
|
|
|
|
35
|
|
|
// Send Request to PAYONE |
|
36
|
|
|
var request = new PayoneRequest(this.request, options); |
|
|
|
|
|
|
37
|
|
|
request.checkAndStore(); |
|
38
|
|
|
}; |
|
39
|
|
|
|
|
40
|
|
|
this.initRequest = function (data) { |
|
41
|
|
|
this.request = data; |
|
42
|
|
|
|
|
43
|
|
|
// Add Default Parameters |
|
44
|
|
|
for (var key in this.config) { |
|
|
|
|
|
|
45
|
|
|
this.request[key] = this.config[key]; |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
// init Request |
|
49
|
|
|
this.request.callback_method = 'PAYONE.Callback.invoke'; |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
this.setResponse = function (response) { |
|
53
|
|
|
this.response = response; |
|
54
|
|
|
}; |
|
55
|
|
|
|
|
56
|
|
|
this.getLastResponse = function () { |
|
57
|
|
|
return this.response; |
|
58
|
|
|
}; |
|
59
|
|
|
|
|
60
|
|
|
this.getLastRequest = function () { |
|
61
|
|
|
return this.request; |
|
62
|
|
|
}; |
|
63
|
|
|
|
|
64
|
|
|
this.setCallback = function (callback) { |
|
65
|
|
|
this.callback = callback; |
|
66
|
|
|
}; |
|
67
|
|
|
}; |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* A Callback Object that replaces default PAYONE Callback and improves Callback Handling |
|
71
|
|
|
* |
|
72
|
|
|
* @type {Object} |
|
73
|
|
|
*/ |
|
74
|
|
|
PAYONE.Callback = { |
|
75
|
|
|
/** |
|
76
|
|
|
* @type {Object} reference to the Gateway Object |
|
77
|
|
|
*/ |
|
78
|
|
|
gateway:'', |
|
79
|
|
|
/** |
|
80
|
|
|
* @type callback should be a valid Callback |
|
81
|
|
|
*/ |
|
82
|
|
|
callback:'', |
|
83
|
|
|
|
|
84
|
|
|
/** |
|
85
|
|
|
* Callback entry method |
|
86
|
|
|
* |
|
87
|
|
|
* @param response |
|
88
|
|
|
*/ |
|
89
|
|
|
invoke:function (response) { |
|
90
|
|
|
this.gateway.setResponse(response); |
|
91
|
|
|
|
|
92
|
|
|
document.getElementsByTagName("body")[0].removeChild(payoneCallbackFunction.payoneScript); |
|
|
|
|
|
|
93
|
|
|
|
|
94
|
|
|
var callback = this.callback; |
|
95
|
|
|
callback(response); |
|
96
|
|
|
} |
|
97
|
|
|
}; |
|
98
|
|
|
|