Completed
Push — master ( 68b21a...50e6b5 )
by Florian
12s
created

js/payone/core/ratepay.js   A

Complexity

Total Complexity 20
Complexity/F 4

Size

Lines of Code 160
Function Count 5

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 0
nc 1
dl 0
loc 160
rs 10
c 2
b 0
f 0
wmc 20
mnd 3
bc 20
fnc 5
bpm 4
cpm 4
noi 11

4 Functions

Rating   Name   Duplication   Size   Complexity  
B ratepay.js ➔ payoneRatepayCustomerDobInput 0 14 5
A ratepay.js ➔ payoneSwitchPayRate 0 16 2
A Validation.add(ꞌvalidate-18-yearsꞌ) 0 9 2
C ratepay.js ➔ payoneRatepayRateCalculatorAction 0 87 8
1
/**
2
 *
3
 * NOTICE OF LICENSE
4
 *
5
 * This source file is subject to the GNU General Public License (GPL 3)
6
 * that is bundled with this package in the file LICENSE.txt
7
 *
8
 * DISCLAIMER
9
 *
10
 * Do not edit or add to this file if you wish to upgrade Payone_Core to newer
11
 * versions in the future. If you wish to customize Payone_Core for your
12
 * needs please refer to http://www.payone.de for more information.
13
 *
14
 * @category        Payone
15
 * @package         js
16
 * @subpackage      payone
17
 * @copyright       Copyright (c) 2016 <[email protected]> - www.fatchip.com
18
 * @author          Robert Müller <[email protected]>
19
 * @license         <http://www.gnu.org/licenses/> GNU General Public License (GPL 3)
20
 * @link            http://www.fatchip.com
21
 *
22
 *
23
 * @category        Payone
24
 * @package         js
25
 * @subpackage      payone
26
 * @copyright       Copyright (c) 2016 <[email protected]> - www.e3n.de
27
 * @author          Tim Rein <[email protected]>
28
 * @license         <http://www.gnu.org/licenses/> GNU General Public License (GPL 3)
29
 * @link            http://www.e3n.de
30
 */
31
32
/**
33
 *
34
 * @param mode
35
 * @param paymentMethod
36
 * @param url
37
 */
38
function payoneSwitchRateOrRuntime(mode, paymentMethod, url)
0 ignored issues
show
Unused Code introduced by
The parameter url is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
39
{
40
    if (mode == 'rate') {
41
        document.getElementById(paymentMethod + '_SwitchToTerm').className = 'ratepay-Active';
42
        document.getElementById(paymentMethod + '_SwitchToRuntime').className = '';
43
        document.getElementById(paymentMethod + '_ContentTerm').style.display = 'block';
44
        document.getElementById(paymentMethod + '_ContentRuntime').style.display = 'none';
45
    } else if (mode == 'runtime') {
46
        document.getElementById(paymentMethod + '_SwitchToRuntime').className = 'ratepay-Active';
47
        document.getElementById(paymentMethod + '_SwitchToTerm').className = '';
48
        document.getElementById(paymentMethod + '_ContentRuntime').style.display = 'block';
49
        document.getElementById(paymentMethod + '_ContentTerm').style.display = 'none';
50
    }
51
}
52
53
/**
54
 *
55
 * @param mode
56
 * @param paymentMethod
57
 * @param url
58
 */
59
function payoneRatepayRateCalculatorAction(mode, paymentMethod, url)
60
{
61
    var calcValue,
62
        calcMethod,
63
        notification,
64
        html,
65
        ratePayshopId,
66
        amount,
67
        ratePayCurrency,
68
        ajaxLoader = $("ajaxLoaderId"),
69
        cover = $("cover");
70
71
    ajaxLoader.setStyle(
72
        {
73
        display: 'block'
74
        }
75
    );
76
    cover.setStyle(
77
        {
78
        display: 'block'
79
        }
80
    );
81
82
83
    if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
84
        xmlhttp = new XMLHttpRequest();
0 ignored issues
show
Bug introduced by
The variable xmlhttp seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.xmlhttp.
Loading history...
Bug introduced by
The variable XMLHttpRequest seems to be never declared. If this is a global, consider adding a /** global: XMLHttpRequest */ 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...
85
    } else {// code for IE6, IE5
86
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
0 ignored issues
show
Bug introduced by
The variable ActiveXObject seems to be never declared. If this is a global, consider adding a /** global: ActiveXObject */ 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...
87
    }
88
89
    amount = document.getElementById('amount').value;
90
    ratePayshopId = document.getElementById('ratePayShopId').value;
91
    ratePayCurrency = document.getElementById('ratePayCurrency').value;
92
    if (mode == 'rate') {
93
        calcValue = document.getElementById(paymentMethod + '-rate').value;
94
95
96
        calcMethod = 'calculation-by-rate';
97
        if (document.getElementById('debitSelect')) {
98
            dueDate = document.getElementById('debitSelect').value;
0 ignored issues
show
Bug introduced by
The variable dueDate seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.dueDate.
Loading history...
99
        } else {
100
            dueDate= '';
101
        }
102
    } else if (mode == 'runtime') {
103
        calcValue = document.getElementById(paymentMethod + '-runtime').value;
104
        calcMethod = 'calculation-by-time';
105
        notification = (document.getElementById(paymentMethod + '_Notification') == null) ? 0 : 1;
106
        if(document.getElementById('debitSelectRuntime')){
107
            dueDate = document.getElementById('debitSelectRuntime').value;
108
        } else {
109
            dueDate= '';
110
        }
111
    }
112
113
    xmlhttp.open("POST", url, false);
114
115
    xmlhttp.setRequestHeader(
116
        "Content-Type",
117
        "application/x-www-form-urlencoded"
118
    );
119
120
    xmlhttp.send(
121
        "paymentMethod=" + paymentMethod + "&calcValue=" + calcValue + "&calcMethod=" + calcMethod + "&dueDate=" + dueDate
0 ignored issues
show
Bug introduced by
The variable calcMethod does not seem to be initialized in case mode == "runtime" on line 102 is false. Are you sure this can never be the case?
Loading history...
Bug introduced by
The variable dueDate does not seem to be initialized in case mode == "runtime" on line 102 is false. Are you sure this can never be the case?
Loading history...
Bug introduced by
The variable calcValue does not seem to be initialized in case mode == "runtime" on line 102 is false. Are you sure this can never be the case?
Loading history...
122
                 + "&notification=" + notification
0 ignored issues
show
Bug introduced by
The variable notification seems to not be initialized for all possible execution paths.
Loading history...
123
                 + "&ratePayshopId=" + ratePayshopId + "&ratePayCurrency=" + ratePayCurrency + "&amount=" + amount
124
    );
125
126
    if (xmlhttp.responseText != null) {
127
        html = xmlhttp.responseText;
128
        document.getElementById(paymentMethod + '_ResultContainer').innerHTML = html;
129
        document.getElementById(paymentMethod + '_ResultContainer').style.display = 'block';
130
        document.getElementById(paymentMethod + '_ResultContainer').style.padding = '3px 0 0 0';
131
        document.getElementById(paymentMethod + '_SwitchToTerm').style.display = 'none';
132
133
        ajaxLoader.setStyle(
134
            {
135
            display: 'none'
136
            }
137
        );
138
        cover.setStyle(
139
            {
140
            display: 'none'
141
            }
142
        );
143
    }
144
145
}
146
/**
147
 * @param element
148
 */
149
function payoneSwitchPayRate(element)
150
{
151
    if(element.value === 'RPS'){
152
        $("ratepay-main-cont").setStyle(
153
            {
154
            display: 'block'
155
            }
156
        );
157
    } else {
158
        $("ratepay-main-cont").setStyle(
159
            {
160
            display: 'none'
161
            }
162
        );
163
    }
164
}
165
166
/**
167
 *
168
 * @param payment_code
169
 */
170
function payoneRatepayCustomerDobInput(payment_code)
171
{
172
    var daySelect = $(payment_code + '_additional_fields_customer_dob_day');
173
    var monthSelect = $(payment_code + '_additional_fields_customer_dob_month');
174
    var yearSelect = $(payment_code + '_additional_fields_customer_dob_year');
175
    var hiddenDobFull = $(payment_code + '_additional_fields_customer_dob_full');
176
177
    if (daySelect == undefined || monthSelect == undefined || yearSelect == undefined
178
        || hiddenDobFull == undefined)  {
179
        return;
180
    }
181
182
    hiddenDobFull.value = yearSelect.value + "-" + monthSelect.value + "-" + daySelect.value;
183
}
184
185
var Translator = new Translate([]);
0 ignored issues
show
Bug introduced by
The variable Translate seems to be never declared. If this is a global, consider adding a /** global: Translate */ 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...
186
187
Validation.add(
0 ignored issues
show
Bug introduced by
The variable Validation seems to be never declared. If this is a global, consider adding a /** global: Validation */ 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...
188
    'validate-18-years', Translator.translate('You have to be at least 18 years old to use this payment type!'), function (value) {
189
    var oBirthDate = new Date(value);
190
    var oMinDate = new Date(new Date().setYear(new Date().getFullYear() - 18));
191
    if(oBirthDate > oMinDate) {
192
        return false;
193
    }
194
195
    return true;
196
    }
197
);