Completed
Push — master ( a5f33a...13719c )
by Florian
9s
created

Component.extend.handleSetPaymentInformation   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 1
dl 0
loc 19
rs 9.4285
c 0
b 0
f 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(
25
    [
26
        'Magento_Checkout/js/view/payment/default',
27
        'jquery',
28
        'Magento_Checkout/js/model/payment/additional-validators',
29
        'Magento_Checkout/js/action/set-payment-information',
30
        'mage/url'
31
    ],
32
    function (Component, $, additionalValidators, setPaymentInformationAction, url) {
33
        'use strict';
34
        return Component.extend({
35
            redirectToPayoneController: function(sUrl) {
36
                window.location.replace(url.build(sUrl));
37
            },
38
39
            handleRedirectAction: function(sUrl) {
40
                var self = this;
41
42
                // update payment method information if additional data was changed
43
                this.selectPaymentMethod();
44
                this.isPlaceOrderActionAllowed(false);
45
46
                this.getPlaceOrderDeferredObject()
47
                    .fail(
48
                        function () {
49
                            self.isPlaceOrderActionAllowed(true);
50
                        }
51
                    ).done(
52
                    function () {
53
                        self.afterPlaceOrder();
54
                        self.redirectToPayoneController(sUrl);
55
                    }
56
                );
57
            },
58
59
            handleSetPaymentInformation: function(sUrl) {
60
                var self = this;
61
62
                // update payment method information if additional data was changed
63
                this.selectPaymentMethod();
64
                this.isPlaceOrderActionAllowed(false);
65
66
                $.when(
67
                    setPaymentInformationAction(this.messageContainer, self.getData())
68
                ).fail(
69
                    function () {
70
                        self.isPlaceOrderActionAllowed(true);
71
                    }
72
                ).done(
73
                    function () {
74
                        self.redirectToPayoneController(sUrl);
75
                    }
76
                );
77
            },
78
79
            continueToPayone: function () {
80
                if (this.validate() && additionalValidators.validate()) {
0 ignored issues
show
Complexity Best Practice introduced by
There is no return statement if this.validate() && addit...alValidators.validate() is false. Are you sure this is correct? If so, consider adding return; explicitly.

This check looks for functions where a return statement is found in some execution paths, but not in all.

Consider this little piece of code

function isBig(a) {
    if (a > 5000) {
        return "yes";
    }
}

console.log(isBig(5001)); //returns yes
console.log(isBig(42)); //returns undefined

The function isBig will only return a specific value when its parameter is bigger than 5000. In any other case, it will implicitly return undefined.

This behaviour may not be what you had intended. In any case, you can add a return undefined to the other execution path to make the return value explicit.

Loading history...
81
                    this.handleRedirectAction('payone/onepage/redirect/');
82
                    return false;
83
                }
84
            },
85
            
86
            handleCreditcardPayment: function () {
87
                var firstValidation = additionalValidators.validate();
88
                if (!(firstValidation)) {
89
                    return false;
90
                }
91
92
                if (this.validate() && firstValidation) {
0 ignored issues
show
Complexity Best Practice introduced by
There is no return statement if this.validate() && firstValidation is false. Are you sure this is correct? If so, consider adding return; explicitly.

This check looks for functions where a return statement is found in some execution paths, but not in all.

Consider this little piece of code

function isBig(a) {
    if (a > 5000) {
        return "yes";
    }
}

console.log(isBig(5001)); //returns yes
console.log(isBig(42)); //returns undefined

The function isBig will only return a specific value when its parameter is bigger than 5000. In any other case, it will implicitly return undefined.

This behaviour may not be what you had intended. In any case, you can add a return undefined to the other execution path to make the return value explicit.

Loading history...
93
                    if (document.getElementById(this.getCode() + '_pseudocardpan').value != '') {
94
                        this.handleRedirectAction('payone/onepage/redirect/');
95
                        return false;
96
                    } else {
97
                        this.handleCreditcardCheck();
0 ignored issues
show
Best Practice introduced by
There is no return statement in this branch, but you do return something in other branches. Did you maybe miss it? If you do not want to return anything, consider adding return undefined; explicitly.
Loading history...
98
                    }
99
                }
100
            },
101
            
102
            handleDebitPayment: function () {
103
                if (this.validate() && additionalValidators.validate()) {
0 ignored issues
show
Complexity Best Practice introduced by
There is no return statement if this.validate() && addit...alValidators.validate() is false. Are you sure this is correct? If so, consider adding return; explicitly.

This check looks for functions where a return statement is found in some execution paths, but not in all.

Consider this little piece of code

function isBig(a) {
    if (a > 5000) {
        return "yes";
    }
}

console.log(isBig(5001)); //returns yes
console.log(isBig(42)); //returns undefined

The function isBig will only return a specific value when its parameter is bigger than 5000. In any other case, it will implicitly return undefined.

This behaviour may not be what you had intended. In any case, you can add a return undefined to the other execution path to make the return value explicit.

Loading history...
104
                    if (window.checkoutConfig.payment.payone.validateBankCode == true && window.checkoutConfig.payment.payone.bankCodeValidatedAndValid == false) {
105
                        this.handleBankaccountCheck();
0 ignored issues
show
Best Practice introduced by
There is no return statement in this branch, but you do return something in other branches. Did you maybe miss it? If you do not want to return anything, consider adding return undefined; explicitly.
Loading history...
106
                    } else {
107
                        this.handleSetPaymentInformation('payone/onepage/debit/');
108
                        return false;
109
                    }
110
                }
111
            }
112
        });
113
    }
114
);
115