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

web/js/view/payment/method-renderer/pagantis.js (4 issues)

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) {
0 ignored issues
show
The parameter selectPaymentMethodAction is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
The parameter checkoutData is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
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
                setTimeout(function () {
31
                    if (window.checkoutConfig.payment.pagantis.enabled  !='0' &&
32
                        window.checkoutConfig.payment.pagantis.publicKey!=''  &&
33
                        window.checkoutConfig.payment.pagantis.secretKey!='') {
34
                        var locale = window.checkoutConfig.payment.pagantis.locale;
35
                        if (locale=='es'|| locale=='') {
36
                            var sdk = pmtSDK;
37
                        } else {
38
                            var sdk = pgSDK;
0 ignored issues
show
Comprehensibility Naming Best Practice introduced by
The variable sdk already seems to be declared on line 36. Consider using another variable name or omitting the var keyword.

This check looks for variables that are declared in multiple lines. There may be several reasons for this.

In the simplest case the variable name was reused by mistake. This may lead to very hard to locate bugs.

If you want to reuse a variable for another purpose, consider declaring it at or near the top of your function and just assigning to it subsequently so it is always declared.

Loading history...
39
                        }
40
41
                        var simulator_options = {
42
                            publicKey: window.checkoutConfig.payment.pagantis.publicKey,
43
                            selector: '.pagantisSimulator',
44
                            totalAmount: window.checkoutConfig.payment.pagantis.total,
45
                            locale: window.checkoutConfig.payment.pagantis.locale,
46
                            totalPromotedAmount : window.checkoutConfig.payment.pagantis.promotedAmount
47
                        };
48
49
                        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...
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