js/payone/core/debitpayment.js   B
last analyzed

Complexity

Total Complexity 36
Complexity/F 5.14

Size

Lines of Code 151
Function Count 7

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 36
dl 0
loc 151
rs 8.8
c 1
b 0
f 0
cc 0
nc 1
mnd 2
bc 30
fnc 7
bpm 4.2857
cpm 5.1428
noi 2

6 Functions

Rating   Name   Duplication   Size   Complexity  
A debitpayment.js ➔ enableElement 0 9 2
A debitpayment.js ➔ copyDebitPaymentSepaIban 0 6 1
C debitpayment.js ➔ blockPaymentMethodInputs 0 46 13
C debitpayment.js ➔ checkIbanCountryCode 0 38 11
A debitpayment.js ➔ changeSubmitButtonStatus 0 10 2
A debitpayment.js ➔ disableElement 0 15 3
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) 2012 <[email protected]> - www.noovias.com
18
 * @author          Matthias Walter <[email protected]>
19
 * @license         <http://www.gnu.org/licenses/> GNU General Public License (GPL 3)
20
 * @link            http://www.noovias.com
21
 */
22
23
function showBankData(code, configShowBankData) 
24
{
25
    var bankCountry = $(code + '_bank_country').getValue();
26
    if (configShowBankData && configShowBankData == 1) {
27
        if (bankCountry == "DE") {
28
            $('input_box_payone_account_number').show();
29
            $('input_box_payone_bank_code').show();
30
        } else {
31
            $('input_box_payone_account_number').hide();
32
            $('input_box_payone_bank_code').hide();
33
        }
34
    }
35
}
36
37
/**
38
 *
39
 * @param code
40
 */
41
function checkIbanCountryCode(code) 
42
{
43
    var ibanEl = $(code + '_sepa_iban');
44
    if (!ibanEl || typeof ibanEl === 'undefined') {
45
        return;
46
    }
47
48
    var bankCountryEl = $(code + '_bank_country');
49
    if (!bankCountryEl || typeof bankCountryEl === 'undefined') {
50
        return;
51
    }
52
53
    var bankCountryCode = bankCountryEl.value;
54
    var value = ibanEl.value;
55
    if (value.length < 2) {
56
        return;
57
    }
58
59
    var countryCode = value.substring(0, 2).toUpperCase();
60
    var validationAdvice = $("advice-validate-sepa-iban-countrycode");
61
    if (countryCode != bankCountryCode) {
62
        ibanEl.value = "";
63
        ibanEl.addClassName("validation-failed");
64
        if (!validationAdvice || typeof validationAdvice === 'undefined') {
65
            var valText = Translator.translate("Entered IBAN is not valid for selected bank country");
0 ignored issues
show
Bug introduced by
The variable Translator seems to be never declared. If this is a global, consider adding a /** global: Translator */ 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...
66
            ibanEl.insert(
67
                {
68
                after: '<div class="validation-advice" id="advice-validate-sepa-iban-countrycode">' + valText + '</div>'
69
                }
70
            );
71
        }
72
    } else {
73
        ibanEl.removeClassName('validation-failed');
74
        if (validationAdvice && typeof validationAdvice !== 'undefined') {
75
            validationAdvice.remove();
76
        }
77
    }
78
}
79
80
function disableElement(element) 
81
{
82
    if (element == undefined) {
83
        return;
84
    }
85
86
    element.value = '';
87
    element.disabled = true;
88
    element.removeClassName('required-entry');
89
    element.removeClassName('validation-failed');
90
    var validationHint = element.next('div .validation-advice');
91
    if (typeof validationHint !== 'undefined') {
92
        validationHint.remove();
93
    }
94
}
95
96
function enableElement(element) 
97
{
98
    if (element == undefined) {
99
        return;
100
    }
101
102
    element.disabled = false;
103
    element.toggleClassName('require-entry');
104
}
105
106
function copyDebitPaymentSepaIban(code) 
107
{
108
    var input_sepa_iban_xxx_el = $(code + '_sepa_iban_xxx');
109
    var input_sepa_iban_el = $(code + '_sepa_iban');
110
    input_sepa_iban_el.value = input_sepa_iban_xxx_el.value;
111
}
112
113
function blockPaymentMethodInputs(code, configShowBankData) 
114
{
115
    var input_sepa_iban_el = $(code + '_sepa_iban');
116
    var input_sepa_bic_el = $(code + '_sepa_bic');
117
    var input_account_number_el = $(code + '_account_number');
118
    var input_bank_code_el = $(code + '_bank_code');
119
120
    if (input_sepa_iban_el.value != '' && Validation.get('validate-sepa-iban').test(input_sepa_iban_el.value) == true) {
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...
121
        disableElement(input_account_number_el);
122
        var inputboxpayoneaccountnumber = $('input_box_payone_account_number');
123
        if (inputboxpayoneaccountnumber != undefined) {
124
            inputboxpayoneaccountnumber.hide();
125
        }
126
127
        disableElement(input_bank_code_el);
128
        var inputboxpayonebankcode = $('input_box_payone_bank_code');
129
        if (inputboxpayonebankcode != undefined) {
130
            inputboxpayonebankcode.hide();
131
        }
132
    } else {
133
        enableElement(input_account_number_el);
134
        enableElement(input_bank_code_el);
135
        showBankData(code, configShowBankData);
136
    }
137
138
    if (input_account_number_el != undefined
139
        && input_account_number_el.value != ''
140
        && Validation.get('validate-digits').test(input_account_number_el.value) == true
141
        && input_bank_code_el.value != ''
142
        && Validation.get('validate-bank-code').test(input_bank_code_el.value) == true
143
        && Validation.get('validate-digits').test(input_bank_code_el.value) == true) {
144
        disableElement(input_sepa_iban_el);
145
        $('input_box_payone_sepa_iban').hide();
146
        if(input_sepa_bic_el) {
147
            disableElement(input_sepa_bic_el);
148
            $('input_box_payone_sepa_bic').hide();
149
        }
150
    } else {
151
        enableElement(input_sepa_iban_el);
152
        $('input_box_payone_sepa_iban').show();
153
        if(input_sepa_bic_el) {
154
            enableElement(input_sepa_bic_el);
155
            $('input_box_payone_sepa_bic').show();
156
        }
157
    }
158
}
159
160
/**
161
 *
162
 * @param checkboxEl
163
 */
164
function changeSubmitButtonStatus(checkboxEl) 
165
{
166
    if (checkboxEl.checked) {
167
        $$('.btn-checkout')[0].removeAttribute("disabled");
168
        $$('.btn-checkout')[0].show();
169
    } else {
170
        $$('.btn-checkout')[0].setAttribute("disabled", "disabled");
171
        $$('.btn-checkout')[0].hide();
172
    }
173
}