Conditions | 1 |
Paths | 768 |
Total Lines | 136 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | /** |
||
35 | function (Component, $, $t, quote, urlBuilder, installmentplan, additionalValidators) { |
||
36 | 'use strict'; |
||
37 | return Component.extend({ |
||
38 | defaults: { |
||
39 | template: 'Payone_Core/payment/payolution_installment', |
||
40 | birthday: '', |
||
41 | birthmonth: '', |
||
42 | birthyear: '', |
||
43 | tradeRegistryNumber: '', |
||
44 | iban: '', |
||
45 | bic: '', |
||
46 | agreement: false |
||
47 | }, |
||
48 | initObservable: function () { |
||
49 | this._super() |
||
50 | .observe([ |
||
51 | 'birthday', |
||
52 | 'birthmonth', |
||
53 | 'birthyear', |
||
54 | 'tradeRegistryNumber', |
||
55 | 'iban', |
||
56 | 'bic', |
||
57 | 'agreement' |
||
58 | ]); |
||
59 | return this; |
||
60 | }, |
||
61 | getData: function () { |
||
62 | document.getElementById(this.getCode() + '_iban').value = this.getCleanedNumber(this.iban()); |
||
63 | document.getElementById(this.getCode() + '_bic').value = this.getCleanedNumber(this.bic()); |
||
64 | |||
65 | var parentReturn = this._super(); |
||
66 | if (parentReturn.additional_data === null) { |
||
67 | parentReturn.additional_data = {}; |
||
68 | } |
||
69 | if (this.requestBirthday()) { |
||
70 | parentReturn.additional_data.dateofbirth = this.birthyear() + this.birthmonth() + this.birthday(); |
||
71 | } |
||
72 | if (this.isB2bMode()) { |
||
73 | parentReturn.additional_data.trade_registry_number = this.tradeRegistryNumber(); |
||
74 | parentReturn.additional_data.b2bmode = true; |
||
75 | } |
||
76 | parentReturn.additional_data.iban = this.getCleanedNumber(this.iban()); |
||
77 | parentReturn.additional_data.bic = this.getCleanedNumber(this.bic()); |
||
78 | parentReturn.additional_data.duration = $('#' + this.getCode() + '_duration').val(); |
||
79 | return parentReturn; |
||
80 | }, |
||
81 | getCleanedNumber: function (sDirtyNumber) { |
||
82 | var sCleanedNumber = ''; |
||
83 | var sTmpChar; |
||
84 | for (var i = 0; i < sDirtyNumber.length; i++) { |
||
85 | sTmpChar = sDirtyNumber.charAt(i); |
||
86 | if (sTmpChar != ' ' && (!isNaN(sTmpChar) || /^[A-Za-z]/.test(sTmpChar))) { |
||
87 | if (/^[a-z]/.test(sTmpChar)) { |
||
88 | sTmpChar = sTmpChar.toUpperCase(); |
||
89 | } |
||
90 | sCleanedNumber = sCleanedNumber + sTmpChar; |
||
91 | } |
||
92 | } |
||
93 | return sCleanedNumber; |
||
94 | }, |
||
95 | /** Returns payment method instructions */ |
||
96 | getInstructions: function () { |
||
97 | return window.checkoutConfig.payment.instructions[this.item.method]; |
||
98 | }, |
||
99 | displayPayolutionOverlay: function () { |
||
100 | $('#' + this.getCode() + '_overlay').show(); |
||
101 | }, |
||
102 | removePayolutionOverlay: function () { |
||
103 | $('#' + this.getCode() + '_overlay').hide(); |
||
104 | }, |
||
105 | getPrivacyDeclaration: function () { |
||
106 | return window.checkoutConfig.payment.payone.payolution.privacyDeclaration.invoice; |
||
107 | }, |
||
108 | isB2bMode: function () { |
||
109 | if (window.checkoutConfig.payment.payone.payolution.b2bMode.invoice == true && |
||
110 | quote.billingAddress() != null && |
||
111 | typeof quote.billingAddress().company != 'undefined' && |
||
112 | quote.billingAddress().company != '' |
||
113 | ) { |
||
114 | return true; |
||
115 | } |
||
116 | return false; |
||
117 | }, |
||
118 | requestBirthday: function () { |
||
119 | return !this.isB2bMode(); |
||
120 | }, |
||
121 | validate: function () { |
||
122 | if (this.requestBirthday() == true && !this.isBirthdayValid(this.birthyear(), this.birthmonth(), this.birthday())) { |
||
123 | this.messageContainer.addErrorMessage({'message': $t('You have to be at least 18 years old to use this payment type!')}); |
||
124 | return false; |
||
125 | } |
||
126 | if (this.agreement() == false) { |
||
127 | this.messageContainer.addErrorMessage({'message': $t('Please confirm the transmission of the necessary data to payolution!')}); |
||
128 | return false; |
||
129 | } |
||
130 | if ($('#' + this.getCode() + '_installmentplan').html() != '' && $('#' + this.getCode() + '_duration').val() == '') { |
||
131 | this.messageContainer.addErrorMessage({'message': $t('Please select your desired number of installments')}); |
||
132 | return false; |
||
133 | } |
||
134 | if ($('#' + this.getCode() + '_duration').val() != '' && this.iban() == '') { |
||
135 | this.messageContainer.addErrorMessage({'message': $t('Please enter a valid IBAN.')}); |
||
136 | return false; |
||
137 | } |
||
138 | if ($('#' + this.getCode() + '_duration').val() != '' &&this.bic() == '') { |
||
139 | this.messageContainer.addErrorMessage({'message': $t('Please enter a valid BIC.')}); |
||
140 | return false; |
||
141 | } |
||
142 | return true; |
||
143 | }, |
||
144 | handleInstallment: function () { |
||
145 | if (this.validate() && additionalValidators.validate()) { |
||
146 | window.payolution_installment = this; |
||
147 | window.switchInstallmentPlan = window.switchInstallmentPlan || function (sKey, sCode, iInstallments) { |
||
148 | window.payolution_installment.switchInstallmentPlan(sKey, sCode, iInstallments); |
||
149 | } |
||
150 | installmentplan(this, '19601212'); |
||
151 | } |
||
152 | }, |
||
153 | switchInstallmentPlan: function (sKey, sCode, iInstallments) { |
||
154 | $$('.payolution_installmentplans').each( |
||
155 | function (e) { |
||
156 | e.hide(); |
||
157 | } |
||
158 | ); |
||
159 | $$('.payolution_installment_overview').each( |
||
160 | function (e) { |
||
161 | e.hide(); |
||
162 | } |
||
163 | ); |
||
164 | |||
165 | $('#payolution_installmentplan_' + sKey).show(); |
||
166 | $('#payolution_installment_overview_' + sKey).show(); |
||
167 | $('#' + sCode + '_duration').val(iInstallments); |
||
168 | } |
||
169 | }); |
||
170 | } |
||
171 | ); |
||
172 |