Total Complexity | 4 |
Complexity/F | 1.33 |
Lines of Code | 44 |
Function Count | 3 |
Duplicated Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | define( |
||
2 | [ |
||
3 | 'Magento_Checkout/js/model/quote', |
||
4 | 'Magento_Checkout/js/model/url-builder', |
||
5 | 'mage/storage', |
||
6 | 'Magento_Customer/js/model/customer', |
||
7 | 'Magento_Checkout/js/model/error-processor' |
||
8 | ], |
||
9 | function (quote, urlBuilder, storage, customer, errorProcessor) { |
||
10 | 'use strict'; |
||
11 | |||
12 | return function (paymentData, messageContainer) { |
||
13 | var serviceUrl, payload; |
||
14 | if (customer.isLoggedIn()) { |
||
15 | serviceUrl = urlBuilder.createUrl('/getloy/payment/create', {}); |
||
16 | payload = { |
||
17 | cartId: quote.getQuoteId(), |
||
18 | paymentMethod: paymentData, |
||
19 | billingAddress: quote.billingAddress() |
||
20 | }; |
||
21 | } else { |
||
22 | serviceUrl = urlBuilder.createUrl( |
||
23 | '/getloy/payment/create-guest', { |
||
24 | quoteId: quote.getQuoteId() |
||
25 | } |
||
26 | ); |
||
27 | payload = { |
||
28 | cartId: quote.getQuoteId(), |
||
29 | email: quote.guestEmail, |
||
30 | paymentMethod: paymentData, |
||
31 | billingAddress: quote.billingAddress() |
||
32 | }; |
||
33 | } |
||
34 | |||
35 | return storage |
||
36 | .post(serviceUrl, JSON.stringify(payload)) |
||
37 | .fail( |
||
38 | function (response) { |
||
39 | errorProcessor.process(response, messageContainer); |
||
40 | } |
||
41 | ); |
||
42 | }; |
||
43 | } |
||
44 | ); |
||
45 |