Completed
Push — master ( 861445...fc7d9d )
by Florian
9s
created

creditcard-method.js ➔ ... ➔ ???   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
rs 10
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(
25
    [
26
        'jquery',
27
        'Payone_Core/js/view/payment/method-renderer/base',
28
        'Magento_Ui/js/model/messageList',
29
        'mage/translate',
30
        'Magento_Checkout/js/model/full-screen-loader'
31
    ],
32
    function ($, Component, messageList, $t, fullScreenLoader) {
33
        'use strict';
34
        return Component.extend({
35
            defaults: {
36
                template: 'Payone_Core/payment/creditcard',
37
                firstname: '',
38
                lastname: '',
39
                pseudocardpan: ''
40
            },
41
            
42
            initObservable: function () {
43
                this._super()
44
                    .observe([
45
                        'firstname',
46
                        'lastname',
47
                        'pseudocardpan'
48
                    ]);
49
                return this;
50
            },
51
            
52
            getData: function () {
53
                var parentReturn = this._super();
54
                if (parentReturn.additional_data === null) {
55
                    parentReturn.additional_data = {};
56
                }
57
                parentReturn.additional_data.firstname = this.firstname();
58
                parentReturn.additional_data.lastname = this.lastname();
59
                parentReturn.additional_data.pseudocardpan = document.getElementById(this.getCode() + '_pseudocardpan').value;
60
                return parentReturn;
61
            },
62
            
63
            handleIframes: function () {
64
                var fieldconfig = window.checkoutConfig.payment.payone.fieldConfig;
65
                if (typeof fieldconfig.language != 'undefined') {
66
                    if (fieldconfig.language == 'de') {
67
                        fieldconfig.language = Payone.ClientApi.Language.de;
0 ignored issues
show
Bug introduced by
The variable Payone seems to be never declared. If this is a global, consider adding a /** global: Payone */ 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...
68
                    } else if (fieldconfig.language == 'en') {
69
                        fieldconfig.language = Payone.ClientApi.Language.en;
70
                    }
71
                }
72
73
                window.iframes = new Payone.ClientApi.HostedIFrames(fieldconfig, window.checkoutConfig.payment.payone.hostedRequest);
74
                window.iframes.setCardType("V");
75
76
                var sCardTypeId = this.getCode() + '_credit_card_type';
77
                if (document.getElementById(sCardTypeId)) {
78
                    document.getElementById(sCardTypeId).onchange = function () {
79
                        window.iframes.setCardType(this.value); // on change: set new type of credit card to process
80
                    };
81
                }
82
            },
83
            showCvc: function () {
84
                return window.checkoutConfig.payment.payone.checkCvc;
85
            },
86
            getInstructions: function () {
87
                return window.checkoutConfig.payment.instructions[this.item.method];
88
            },
89
            getCreditcardTypes: function () {
90
                return window.checkoutConfig.payment.payone.availableCardTypes;
91
            },
92
            getHostedParam: function (sParam) {
93
                return window.checkoutConfig.payment.payone.hostedParams[sParam];
94
            },
95
            getCcMonths: function () {
96
                return window.checkoutConfig.payment.ccform.months[this.getCode()];
97
            },
98
            getCcYears: function () {
99
                return window.checkoutConfig.payment.ccform.years[this.getCode()];
100
            },
101
            getCcMonthsValues: function () {
102
                return _.map(this.getCcMonths(), function (value, key) {
0 ignored issues
show
Bug introduced by
The variable _ seems to be never declared. If this is a global, consider adding a /** global: _ */ 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...
103
                    return {
104
                        'value': key,
105
                        'month': value
106
                    }
107
                });
108
            },
109
            getCcYearsValues: function () {
110
                return _.map(this.getCcYears(), function (value, key) {
0 ignored issues
show
Bug introduced by
The variable _ seems to be never declared. If this is a global, consider adding a /** global: _ */ 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...
111
                    return {
112
                        'value': key,
113
                        'year': value
114
                    };
115
                });
116
            },
117
118
            validate: function () {
119
                if (document.getElementById(this.getCode() + '_credit_card_type').value == '') {
120
                    this.messageContainer.addErrorMessage({'message': $t('Please choose the creditcard type.')});
121
                    return false;
122
                }
123
                if (this.firstname() == '') {
124
                    this.messageContainer.addErrorMessage({'message': $t('Please enter the firstname.')});
125
                    return false;
126
                }
127
                if (this.lastname() == '') {
128
                    this.messageContainer.addErrorMessage({'message': $t('Please enter the lastname.')});
129
                    return false;
130
                }
131
                return true;
132
            },
133
            
134
            handleCreditcardCheck: function () {
135
                // PayOne Request if the data is valid
136
                if (window.iframes.isComplete()) {
137
                    window.ccjs = this;
138
                    window.processPayoneResponseCCHosted = window.processPayoneResponseCCHosted || function (response) {
139
                            window.ccjs.processPayoneResponseCCHosted(response);
140
                        };
141
                    window.iframes.creditCardCheck('processPayoneResponseCCHosted'); // Perform "CreditCardCheck" to create and get a
142
                    // PseudoCardPan; then call your function "payCallback"
143
                    fullScreenLoader.startLoader();
144
                } else {
145
                    this.messageContainer.addErrorMessage({'message': $t("Please enter complete data.")});
146
                }
147
            },
148
            
149
            processPayoneResponseCCHosted: function (response) {
150
                fullScreenLoader.stopLoader();
151
                if (response.status === "VALID") {
152
                    if (document.getElementById(this.getCode() + '_pseudocardpan')) {
153
                        document.getElementById(this.getCode() + '_pseudocardpan').value = response.pseudocardpan;
154
                    }
155
156
                    this.handleRedirectAction('payone/onepage/redirect/');
157
                } else if (response.status === "INVALID") {
158
                    this.messageContainer.addErrorMessage({'message': $t(response.errormessage)});
159
                } else if (response.status === "ERROR") {
160
                    this.messageContainer.addErrorMessage({'message': $t(response.errormessage)});
161
                }
162
            }
163
        });
164
    
165
    }
166
);
167