js/payone/core/client_api.js   A
last analyzed

Complexity

Total Complexity 9
Complexity/F 1.13

Size

Lines of Code 93
Function Count 8

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 9
c 1
b 0
f 0
dl 0
loc 93
rs 10
cc 0
nc 1
mnd 1
bc 9
fnc 8
bpm 1.125
cpm 1.125
noi 4

2 Functions

Rating   Name   Duplication   Size   Complexity  
A PAYONE.Callback.invoke 0 8 1
A PAYONE.Gateway 0 52 1
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
0 ignored issues
show
Documentation introduced by
The parameter data does not exist. Did you maybe forget to remove this comment?
Loading history...
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);
0 ignored issues
show
Bug introduced by
The variable PayoneRequest seems to be never declared. If this is a global, consider adding a /** global: PayoneRequest */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
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) {
0 ignored issues
show
Complexity introduced by
A for in loop automatically includes the property of any prototype object, consider checking the key using hasOwnProperty.

When iterating over the keys of an object, this includes not only the keys of the object, but also keys contained in the prototype of that object. It is generally a best practice to check for these keys specifically:

var someObject;
for (var key in someObject) {
    if ( ! someObject.hasOwnProperty(key)) {
        continue; // Skip keys from the prototype.
    }

    doSomethingWith(key);
}
Loading history...
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);
0 ignored issues
show
Bug introduced by
The variable payoneCallbackFunction seems to be never declared. If this is a global, consider adding a /** global: payoneCallbackFunction */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
93
94
        var callback = this.callback;
95
        callback(response);
96
    }
97
};
98