Completed
Push — master ( 08c5b9...8b6449 )
by pablo
15s queued 11s
created

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

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
        'Magento_Checkout/js/action/select-payment-method',
12
        'Magento_Checkout/js/checkout-data',
13
        'Magento_Checkout/js/model/totals',
14
        'Magento_Catalog/js/price-utils'
15
    ],
16
    function ($, Component, url, customerData, errorProcessor, fullScreenLoader, quote, pgSDK, selectPaymentMethodAction, checkoutData, totals, priceUtils) {
17
        'use strict';
18
19
        window.checkoutConfig.payment.pagantis.guestEmail = quote.guestEmail;
20
21
        return Component.extend({
22
            defaults: {
23
                template: 'Pagantis_Pagantis/payment/checkout-form'
24
            },
25
26
            redirectAfterPlaceOrder: false,
27
28
            loadSimulator: function () {
29
                window.loadingSimulator = setTimeout(function () {
30
                    if (window.checkoutConfig.payment.pagantis.enabled  !='0' &&
0 ignored issues
show
Complexity Best Practice introduced by
There is no return statement if window.checkoutConfig.pa...roduct_simulator == "1" 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...
31
                        window.checkoutConfig.payment.pagantis.publicKey!=''  &&
32
                        window.checkoutConfig.payment.pagantis.secretKey!='' &&
33
                        window.checkoutConfig.payment.pagantis.product_simulator=='1') {
34
                        var locale = window.checkoutConfig.payment.pagantis.locale;
35
                        var sdk = pgSDK;
36
37
                        var simulator_options = {
38
                            numInstalments : window.checkoutConfig.payment.pagantis.quotesStart,
39
                            type : eval(window.checkoutConfig.payment.pagantis.type),
40
                            skin : eval(window.checkoutConfig.payment.pagantis.skin),
41
                            publicKey: window.checkoutConfig.payment.pagantis.publicKey,
42
                            selector: window.checkoutConfig.payment.pagantis.position,
43
                            totalAmount: window.checkoutConfig.payment.pagantis.total,
44
                            locale: window.checkoutConfig.payment.pagantis.locale,
45
                            country: window.checkoutConfig.payment.pagantis.country,
46
                            totalPromotedAmount : window.checkoutConfig.payment.pagantis.promotedAmount
47
                        };
48
49
                        if (typeof sdk !== 'undefined') {
50
                            window.MGSimulatorId = sdk.simulator.init(simulator_options);
51
                            return false;
52
                        }
53
                    }
54
                }, 3000);
55
            },
56
57
            getTitle: function () {
58
                return window.checkoutConfig.payment.pagantis.title
59
            },
60
61
            getSubtitle: function () {
62
                return window.checkoutConfig.payment.pagantis.subtitle
63
            },
64
65
            getDisplayMode: function () {
66
                return window.checkoutConfig.payment.pagantis.displayMode
67
            },
68
69
            getImage: function () {
70
                return window.checkoutConfig.payment.pagantis.image
71
            },
72
73
            placeOrder: function () {
74
                var paymentUrl = url.build('pagantis/Payment');
75
                $.post(paymentUrl, { email: window.checkoutConfig.payment.pagantis.guestEmail }, 'json')
76
                    .done(function (response) {
77
                        window.location.replace(response);
78
                    })
79
                    .fail(function (response) {
80
                        window.location.replace(response);
81
                    })
82
            },
83
            });
84
    }
85
);
86