Completed
Push — master ( 1137b9...97c77e )
by
unknown
20s queued 11s
created

paylater.js ➔ ... ➔ Component.extend.loadSimulator   A

Complexity

Conditions 1
Paths 3

Size

Total Lines 16
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 12
nc 3
nop 0
dl 0
loc 16
rs 9.8
c 0
b 0
f 0
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.pagamastarde.com/pmt-js-client-sdk/3/js/client-sdk.min.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, pmtClient, selectPaymentMethodAction, checkoutData, totals, priceUtils) {
17
        'use strict';
18
19
        window.checkoutConfig.payment.paylater.guestEmail = quote.guestEmail;
20
21
        window.pmtClient = pmtClient;
22
23
        return Component.extend({
24
                defaults: {
25
                    template: 'DigitalOrigin_Pmt/payment/checkout-form'
26
                },
27
28
                redirectAfterPlaceOrder: false,
29
30
                loadSimulator: function ()
31
                {
32
                    setTimeout(function(){
33
                        if (window.checkoutConfig.payment.paylater.pmtType  !='0' &&
0 ignored issues
show
Complexity Best Practice introduced by pgarces
There is no return statement if window.checkoutConfig.pa...aylater.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...
34
                            window.checkoutConfig.payment.paylater.publicKey!=''  &&
35
                            window.checkoutConfig.payment.paylater.secretKey!='')
36
                        {
37
                            if (typeof window.pmtClient !== 'undefined')
0 ignored issues
show
Complexity Best Practice introduced by pgarces
There is no return statement if typeof window.pmtClient !== "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...
38
                            {
39
                                window.pmtClient.setPublicKey(window.checkoutConfig.payment.paylater.publicKey);
40
                                window.pmtClient.simulator.reload();
41
                                return true;
42
                            }
43
                        }
44
                    }, 3000);
45
                },
46
47
                getSubtitle: function () {
48
                    return window.checkoutConfig.payment.paylater.subtitle
49
                },
50
51
                getPmtNumQuota: function () {
52
                    return window.checkoutConfig.payment.paylater.pmtNumQuota
53
                },
54
55
                dataPmtMaxIns: function () {
56
                    return window.checkoutConfig.payment.paylater.pmtMaxIns
57
                },
58
59
                getPmtType: function () {
60
                    return window.checkoutConfig.payment.paylater.pmtType
61
                },
62
63
                getPmtTotal: function () {
64
                    return priceUtils.formatPrice(totals.totals().grand_total, quote.getPriceFormat());
65
                },
66
67
                getPublicKey: function () {
68
                    return window.checkoutConfig.payment.paylater.publicKey
69
                },
70
71
                getSecretKey: function () {
72
                    return window.checkoutConfig.payment.paylater.secretKey
73
                },
74
75
                getDisplayMode: function () {
76
                    return window.checkoutConfig.payment.paylater.displayMode
77
                },
78
79
                selectPaymentMethod: function() {
80
                    selectPaymentMethodAction(this.getData());
81
                    checkoutData.setSelectedPaymentMethod(this.item.method);
82
                    return true;
83
                },
84
85
                placeOrder: function () {
86
                    var paymentUrl = url.build('paylater/Payment');
87
                    $.post(paymentUrl, { email: window.checkoutConfig.payment.paylater.guestEmail }, 'json')
88
                        .done(function (response) {
89
                            window.location.replace(response);
90
                        })
91
                        .fail(function (response) {
92
                            window.location.replace(response);
93
                        })
94
                },
95
            });
96
    }
97
);
98