Completed
Push — master ( 1b679c...e05b34 )
by
unknown
19s queued 10s
created

web/js/view/payment/method-renderer/pagantis.js (1 issue)

Check for missing return statements.

Best Practice Complexity Minor
1
define(
2
    [
3
        'jquery',
4
        'Magento_Checkout/js/view/payment/default',
5
        'mage/url',
6
        'Magento_Customer/js/customer-data',
7
        'Magento_Checkout/js/model/error-processor',
8
        'Magento_Checkout/js/model/full-screen-loader',
9
        'Magento_Checkout/js/model/quote',
10
        '//cdn.pagantis.com/js/pg-v2/sdk.js',
11
        '//cdn.pagamastarde.com/js/pmt-v2/sdk.js',
12
        'Magento_Checkout/js/action/select-payment-method',
13
        'Magento_Checkout/js/checkout-data',
14
        'Magento_Checkout/js/model/totals',
15
        'Magento_Catalog/js/price-utils'
16
    ],
17
    function ($, Component, url, customerData, errorProcessor, fullScreenLoader, quote, pgSDK, pmtSDK, selectPaymentMethodAction, checkoutData, totals, priceUtils) {
18
        'use strict';
19
20
        window.checkoutConfig.payment.pagantis.guestEmail = quote.guestEmail;
21
22
        return Component.extend({
23
                defaults: {
24
                    template: 'Pagantis_Pagantis/payment/checkout-form'
25
                },
26
27
                redirectAfterPlaceOrder: false,
28
29
                loadSimulator: function ()
30
                {
31
                    setTimeout(function(){
32
                        if (window.checkoutConfig.payment.pagantis.enabled  !='0' &&
33
                            window.checkoutConfig.payment.pagantis.publicKey!=''  &&
34
                            window.checkoutConfig.payment.pagantis.secretKey!='')
35
                        {
36
37
                            var locale = window.checkoutConfig.payment.pagantis.locale;
38
                            if (locale=='es'|| locale=='') {
39
                                var sdk = pmtSDK;
40
                            } else {
41
                                var sdk = pgSDK;
42
                            }
43
44
                            if (typeof sdk !== 'undefined')
0 ignored issues
show
Complexity Best Practice introduced by
There is no return statement if typeof sdk !== "undefined" 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...
45
                            {
46
                                sdk.simulator.init({
47
                                    publicKey: window.checkoutConfig.payment.pagantis.publicKey,
48
                                    selector: '.pagantisSimulator',
49
                                    totalAmount: window.checkoutConfig.payment.pagantis.total,
50
                                    locale: window.checkoutConfig.payment.pagantis.locale
51
                                });
52
                                return false;
53
                            }
54
                        }
55
                    }, 3000);
56
                },
57
58
                getTitle: function () {
59
                    return window.checkoutConfig.payment.pagantis.title
60
                },
61
62
                getSubtitle: function () {
63
                    return window.checkoutConfig.payment.pagantis.subtitle
64
                },
65
66
                getDisplayMode: function () {
67
                    return window.checkoutConfig.payment.pagantis.displayMode
68
                },
69
70
                getImage: function () {
71
                    return window.checkoutConfig.payment.pagantis.image
72
                },
73
74
                selectPaymentMethod: function() {
75
                    selectPaymentMethodAction(this.getData());
76
                    checkoutData.setSelectedPaymentMethod(this.item.method);
77
                    return true;
78
                },
79
80
                placeOrder: function () {
81
                    var paymentUrl = url.build('pagantis/Payment');
82
                    $.post(paymentUrl, { email: window.checkoutConfig.payment.pagantis.guestEmail }, 'json')
83
                        .done(function (response) {
84
                            window.location.replace(response);
85
                        })
86
                        .fail(function (response) {
87
                            window.location.replace(response);
88
                        })
89
                },
90
            });
91
    }
92
);
93