| Conditions | 1 |
| Paths | 512 |
| Total Lines | 136 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 1 | 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 | /** |
||
| 30 | function (Component, quote, $t) { |
||
| 31 | 'use strict'; |
||
| 32 | return Component.extend({ |
||
| 33 | defaults: { |
||
| 34 | template: 'Payone_Core/payment/klarna', |
||
| 35 | telephone: '', |
||
| 36 | addinfo: '', |
||
| 37 | delAddinfo: '', |
||
| 38 | gender: '', |
||
| 39 | personalId: '', |
||
| 40 | birthday: '', |
||
| 41 | birthmonth: '', |
||
| 42 | birthyear: '', |
||
| 43 | agreement: false |
||
| 44 | }, |
||
| 45 | initObservable: function () { |
||
| 46 | this._super() |
||
| 47 | .observe([ |
||
| 48 | 'telephone', |
||
| 49 | 'addinfo', |
||
| 50 | 'delAddinfo', |
||
| 51 | 'gender', |
||
| 52 | 'personalId', |
||
| 53 | 'birthday', |
||
| 54 | 'birthmonth', |
||
| 55 | 'birthyear', |
||
| 56 | 'agreement' |
||
| 57 | ]); |
||
| 58 | return this; |
||
| 59 | }, |
||
| 60 | requestTelephone: function () { |
||
| 61 | if (this.getBillingCountry() !== false && this.getBillingCountry() !== '') { |
||
| 62 | return false; |
||
| 63 | } |
||
| 64 | return true; |
||
| 65 | }, |
||
| 66 | requestAddressAddInfo: function () { |
||
| 67 | if (this.getBillingCountry() !== false && this.getBillingCountry() !== 'NL') { |
||
| 68 | return false; |
||
| 69 | } |
||
| 70 | return true; |
||
| 71 | }, |
||
| 72 | requestDelAddressAddInfo: function () { |
||
| 73 | if (this.getBillingCountry() !== false && this.getBillingCountry() !== 'NL') { |
||
| 74 | return false; |
||
| 75 | } |
||
| 76 | return true; |
||
| 77 | }, |
||
| 78 | requestGender: function () { |
||
| 79 | var aTriggerCountries = ['DE', 'NL', 'AT']; |
||
| 80 | if (this.getBillingCountry() !== false && aTriggerCountries.indexOf(this.getBillingCountry()) !== -1) { |
||
| 81 | if (window.checkoutConfig.payment.payone.customerHasGivenGender == false) { |
||
| 82 | return true; |
||
| 83 | } |
||
| 84 | } |
||
| 85 | return false; |
||
| 86 | }, |
||
| 87 | requestPersonalId: function () { |
||
| 88 | var aTriggerCountries = ['DK', 'FI', 'NO', 'SE']; |
||
| 89 | if (this.getBillingCountry() !== false && aTriggerCountries.indexOf(this.getBillingCountry()) !== -1) { |
||
| 90 | return true; |
||
| 91 | } |
||
| 92 | return false; |
||
| 93 | }, |
||
| 94 | requestBirthday: function () { |
||
| 95 | var aTriggerCountries = ['DE', 'NL', 'AT']; |
||
| 96 | if (this.getBillingCountry() !== false && aTriggerCountries.indexOf(this.getBillingCountry()) !== -1) { |
||
| 97 | if (window.checkoutConfig.payment.payone.customerHasGivenBirthday == false) { |
||
| 98 | return true; |
||
| 99 | } |
||
| 100 | } |
||
| 101 | return false; |
||
| 102 | }, |
||
| 103 | requestAgreement: function () { |
||
| 104 | var aTriggerCountries = ['DE', 'AT']; |
||
| 105 | if (this.getBillingCountry() !== false && aTriggerCountries.indexOf(this.getBillingCountry()) !== -1) { |
||
| 106 | return true; |
||
| 107 | } |
||
| 108 | return false; |
||
| 109 | }, |
||
| 110 | getBillingCountry: function () { |
||
| 111 | if (quote.billingAddress() !== null && typeof quote.billingAddress().countryId !== 'undefined') { |
||
| 112 | return quote.billingAddress().countryId; |
||
| 113 | } |
||
| 114 | return false; |
||
| 115 | }, |
||
| 116 | getData: function () { |
||
| 117 | var parentReturn = this._super(); |
||
| 118 | if (parentReturn.additional_data === null) { |
||
| 119 | parentReturn.additional_data = {}; |
||
| 120 | } |
||
| 121 | parentReturn.additional_data.telephone = this.telephone(); |
||
| 122 | parentReturn.additional_data.addinfo = this.addinfo(); |
||
| 123 | parentReturn.additional_data.del_addinfo = this.delAddinfo(); |
||
| 124 | parentReturn.additional_data.gender = this.gender(); |
||
| 125 | parentReturn.additional_data.personal_id = this.personalId(); |
||
| 126 | parentReturn.additional_data.birthday = this.birthday(); |
||
| 127 | parentReturn.additional_data.birthmonth = this.birthmonth(); |
||
| 128 | parentReturn.additional_data.birthyear = this.birthyear(); |
||
| 129 | return parentReturn; |
||
| 130 | }, |
||
| 131 | getKlarnaStoreId: function () { |
||
| 132 | var storeIds = window.checkoutConfig.payment.payone.klarnaStoreIds; |
||
| 133 | var country = this.getBillingCountry(); |
||
| 134 | if (storeIds.hasOwnProperty(country)) { |
||
| 135 | return storeIds[country]; |
||
| 136 | } |
||
| 137 | return 0; |
||
| 138 | }, |
||
| 139 | getKlarnaUrl: function (sLanguage) { |
||
| 140 | return 'https://cdn.klarna.com/1.0/shared/content/legal/terms/' + this.getKlarnaStoreId() + '/de_' + sLanguage + '/consent'; |
||
| 141 | }, |
||
| 142 | validate: function () { |
||
| 143 | if (this.requestAgreement() === true && this.agreement() === false) { |
||
| 144 | this.messageContainer.addErrorMessage({'message': $t('Please confirm the transmission of the necessary data to Klarna!')}); |
||
| 145 | return false; |
||
| 146 | } |
||
| 147 | return true; |
||
| 148 | }, |
||
| 149 | /** Returns payment method instructions */ |
||
| 150 | getInstructions: function () { |
||
| 151 | return window.checkoutConfig.payment.instructions[this.item.method]; |
||
| 152 | }, |
||
| 153 | loadKlarnaTerms: function () { |
||
| 154 | var oElement = document.getElementById('payone_klarna_invoice_terms'); |
||
| 155 | if (oElement.innerHTML.length === 0) { |
||
| 156 | var terms = new Klarna.Terms.Invoice({ |
||
| 157 | el: oElement, |
||
| 158 | eid: this.getKlarnaStoreId(), // Your merchant ID |
||
| 159 | country: this.getBillingCountry().toLowerCase(), |
||
| 160 | charge: 0 |
||
| 161 | }); |
||
| 162 | } |
||
| 163 | } |
||
| 164 | }); |
||
| 165 | } |
||
| 166 | ); |
||
| 167 |
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.