Completed
Push — master ( 341936...178071 )
by Florian
03:31
created

view/frontend/web/js/action/installmentplan.js   A

Complexity

Total Complexity 6
Complexity/F 1.5

Size

Lines of Code 55
Function Count 4

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 55
c 0
b 0
f 0
wmc 6
rs 10
cc 0
nc 1
mnd 1
bc 8
fnc 4
bpm 2
cpm 1.5
noi 1

1 Function

Rating   Name   Duplication   Size   Complexity  
A installmentplan.js ➔ define 0 48 1
1
/**
2
 * PAYONE Magento 2 Connector is free software: you can redistribute it and/or modify
3
 * it under the terms of the GNU Lesser General Public License as published by
4
 * the Free Software Foundation, either version 3 of the License, or
5
 * (at your option) any later version.
6
 *
7
 * PAYONE Magento 2 Connector is distributed in the hope that it will be useful,
8
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10
 * GNU Lesser General Public License for more details.
11
 *
12
 * You should have received a copy of the GNU Lesser General Public License
13
 * along with PAYONE Magento 2 Connector. If not, see <http://www.gnu.org/licenses/>.
14
 *
15
 * PHP version 5
16
 *
17
 * @category  Payone
18
 * @package   Payone_Magento2_Plugin
19
 * @author    FATCHIP GmbH <[email protected]>
20
 * @copyright 2003 - 2017 Payone GmbH
21
 * @license   <http://www.gnu.org/licenses/> GNU Lesser General Public License
22
 * @link      http://www.payone.de
23
 */
24
/*jshint browser:true jquery:true*/
25
/*global alert*/
26
define([
27
    'jquery',
28
    'Magento_Checkout/js/model/url-builder',
29
    'mage/storage',
30
    'Magento_Checkout/js/model/full-screen-loader',
31
    'Magento_Checkout/js/model/quote',
32
    'Magento_Customer/js/model/customer'
33
], function ($, urlBuilder, storage, fullScreenLoader, quote, customer) {
34
    'use strict';
35
36
    /** Override default place order action and add agreement_ids to request */
37
    return function (baseView, birthday) {
38
        var serviceUrl;
39
40
        var request = {
41
            birthday: birthday
42
        };
43
        if (!customer.isLoggedIn()) {
44
            serviceUrl = urlBuilder.createUrl('/guest-carts/:quoteId/payone-installmentPlan', {
45
                quoteId: quote.getQuoteId()
46
            });
47
            request.email = quote.guestEmail;
48
        } else {
49
            serviceUrl = urlBuilder.createUrl('/carts/mine/payone-installmentPlan', {});
50
        }
51
52
        fullScreenLoader.startLoader();
53
54
        return storage.post(
55
            serviceUrl,
56
            JSON.stringify(request)
57
        ).done(
58
            function (response) {
59
                if (response.success == true) {
60
                    $('#' + baseView.getCode() + '_installmentplan').html(response.installment_plan_html);
61
                    $('#' + baseView.getCode() + '_installmentplan').show();
62
                    $('#' + baseView.getCode() + '_check').hide();
63
                    $('#' + baseView.getCode() + '_submit').show();
64
                    $('#' + baseView.getCode() + '_birthday_field').hide();
65
                    $('#' + baseView.getCode() + '_iban_field').show();
66
                    $('#' + baseView.getCode() + '_bic_field').show();
67
                } else {
68
                    alert(response.errormessage);
69
                }
70
                fullScreenLoader.stopLoader();
71
            }
72
        ).fail(
73
            function (response) {
0 ignored issues
show
Unused Code introduced by
The parameter response 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...
74
                //errorProcessor.process(response, messageContainer);
75
                alert('An error occured.');
76
                fullScreenLoader.stopLoader();
77
            }
78
        );
79
    };
80
});
81