Passed
Pull Request — master (#35)
by
unknown
14:50 queued 07:21
created

src/view/frontend/web/js/view/payment/method-renderer/pagantis.js   A

Complexity

Total Complexity 13
Complexity/F 1.3

Size

Lines of Code 89
Function Count 10

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 13
eloc 61
dl 0
loc 89
rs 10
c 0
b 0
f 0
mnd 3
bc 3
fnc 10
bpm 0.3
cpm 1.3
noi 9
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
Unused Code introduced by
The parameter priceUtils 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...
Unused Code introduced by
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...
Unused Code introduced by
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...
Unused Code introduced by
The parameter totals 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
                window.loadingSimulator = setTimeout(function () {
31
                    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...agantis.secretKey != "" 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...
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
                            numInstalments : window.checkoutConfig.payment.pagantis.quotesStart,
43
                            type : eval(window.checkoutConfig.payment.pagantis.type),
0 ignored issues
show
Security Performance introduced by
Calls to eval are slow and potentially dangerous, especially on untrusted code. Please consider whether there is another way to achieve your goal.
Loading history...
44
                            skin : eval(window.checkoutConfig.payment.pagantis.skin),
0 ignored issues
show
Security Performance introduced by
Calls to eval are slow and potentially dangerous, especially on untrusted code. Please consider whether there is another way to achieve your goal.
Loading history...
45
                            publicKey: window.checkoutConfig.payment.pagantis.publicKey,
46
                            selector: window.checkoutConfig.payment.pagantis.position,
47
                            totalAmount: window.checkoutConfig.payment.pagantis.total,
48
                            locale: window.checkoutConfig.payment.pagantis.locale,
49
                            country: window.checkoutConfig.payment.pagantis.country,
50
                            totalPromotedAmount : window.checkoutConfig.payment.pagantis.promotedAmount
51
                        };
52
53
                        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...
54
                            window.MGSimulatorId = sdk.simulator.init(simulator_options);
55
                            return false;
56
                        }
57
                    }
58
                }, 3000);
59
            },
60
61
            getTitle: function () {
62
                return window.checkoutConfig.payment.pagantis.title
63
            },
64
65
            getSubtitle: function () {
66
                return window.checkoutConfig.payment.pagantis.subtitle
67
            },
68
69
            getDisplayMode: function () {
70
                return window.checkoutConfig.payment.pagantis.displayMode
71
            },
72
73
            getImage: function () {
74
                return window.checkoutConfig.payment.pagantis.image
75
            },
76
77
            placeOrder: function () {
78
                var paymentUrl = url.build('pagantis/Payment');
79
                $.post(paymentUrl, { email: window.checkoutConfig.payment.pagantis.guestEmail }, 'json')
80
                    .done(function (response) {
81
                        window.location.replace(response);
82
                    })
83
                    .fail(function (response) {
84
                        window.location.replace(response);
85
                    })
86
            },
87
            });
88
    }
89
);
90