Completed
Push — master ( 213d43...10c9fb )
by Florian
8s
created

Component.extend.requestIbanBic   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
/**
2
 * PAYONE Magento 2 Connector is free software: you can redistribute it and/or modify
3
 * it under the terms of the GNU Lesser General Public License as published by
4
 * the Free Software Foundation, either version 3 of the License, or
5
 * (at your option) any later version.
6
 *
7
 * PAYONE Magento 2 Connector is distributed in the hope that it will be useful,
8
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10
 * GNU Lesser General Public License for more details.
11
 *
12
 * You should have received a copy of the GNU Lesser General Public License
13
 * along with PAYONE Magento 2 Connector. If not, see <http://www.gnu.org/licenses/>.
14
 *
15
 * PHP version 5
16
 *
17
 * @category  Payone
18
 * @package   Payone_Magento2_Plugin
19
 * @author    FATCHIP GmbH <[email protected]>
20
 * @copyright 2003 - 2016 Payone GmbH
21
 * @license   <http://www.gnu.org/licenses/> GNU Lesser General Public License
22
 * @link      http://www.payone.de
23
 */
24
define(
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
25
    [
26
        'Payone_Core/js/view/payment/method-renderer/base',
27
        'Magento_Ui/js/model/messageList',
28
        'mage/translate'
29
    ],
30
    function (Component, messageList, $t) {
31
        'use strict';
32
        return Component.extend({
33
            defaults: {
34
                template: 'Payone_Core/payment/obt_sofortueberweisung',
35
                iban: '',
36
                bic: ''
37
            },
38
            
39
            initObservable: function () {
40
                this._super()
41
                    .observe([
42
                        'iban',
43
                        'bic'
44
                    ]);
45
                return this;
46
            },
47
48
            validate: function () {
49
                if (this.requestIbanBic() == 1) {
50
                    if (this.iban() == '') {
51
                        this.messageContainer.addErrorMessage({'message': $t('Please enter a valid IBAN.')});
52
                        return false;
53
                    }
54
                    if (this.bic() == '') {
55
                        this.messageContainer.addErrorMessage({'message': $t('Please enter a valid BIC.')});
56
                        return false;
57
                    }
58
                }
59
                return true;
60
            },
61
62
            /** Returns payment method instructions */
63
            getInstructions: function () {
64
                return window.checkoutConfig.payment.instructions[this.item.method];
65
            },
66
            
67
            getCleanedNumber: function (sDirtyNumber) {
68
                var sCleanedNumber = '';
69
                var sTmpChar;
70
                for (var i = 0; i < sDirtyNumber.length; i++) {
71
                    sTmpChar = sDirtyNumber.charAt(i);
72
                    if (sTmpChar != ' ' && (!isNaN(sTmpChar) || /^[A-Za-z]/.test(sTmpChar))) {
73
                        if (/^[a-z]/.test(sTmpChar)) {
74
                            sTmpChar = sTmpChar.toUpperCase();
75
                        }
76
                        sCleanedNumber = sCleanedNumber + sTmpChar;
77
                    }
78
                }
79
                return sCleanedNumber;
80
            },
81
            getData: function () {
82
                if (this.requestIbanBic() == 1) {
83
                    document.getElementById(this.getCode() + '_iban').value = this.getCleanedNumber(this.iban());
84
                    document.getElementById(this.getCode() + '_bic').value = this.getCleanedNumber(this.bic());
85
86
                    var parentReturn = this._super();
87
                    if (parentReturn.additional_data === null) {
88
                        parentReturn.additional_data = {};
89
                    }
90
                    parentReturn.additional_data.iban = this.getCleanedNumber(this.iban());
91
                    parentReturn.additional_data.bic = this.getCleanedNumber(this.bic());
92
                    return parentReturn;
93
                }
94
                return this._super();
95
            },
96
            requestIbanBic: function () {
97
                return window.checkoutConfig.payment.payone.requestIbanBicSofortUeberweisung;
98
            }
99
        });
100
    }
101
);
102