|
2 | 2 | * Copyright © Magento, Inc. All rights reserved.
|
3 | 3 | * See COPYING.txt for license details.
|
4 | 4 | */
|
5 |
| -define( |
6 |
| - [ |
7 |
| - 'underscore', |
8 |
| - 'jquery', |
9 |
| - 'uiComponent', |
10 |
| - 'paypalInContextExpressCheckout', |
11 |
| - 'Magento_Customer/js/customer-data', |
12 |
| - 'domReady!' |
13 |
| - ], |
14 |
| - function ( |
15 |
| - _, |
16 |
| - $, |
17 |
| - Component, |
18 |
| - paypalExpressCheckout, |
19 |
| - customerData |
20 |
| - ) { |
21 |
| - 'use strict'; |
22 |
| - |
23 |
| - return Component.extend({ |
24 |
| - |
25 |
| - defaults: { |
26 |
| - clientConfig: { |
27 |
| - |
28 |
| - checkoutInited: false, |
29 |
| - |
30 |
| - /** |
31 |
| - * @param {Object} event |
32 |
| - */ |
33 |
| - click: function (event) { |
34 |
| - $('body').trigger('processStart'); |
35 |
| - |
36 |
| - event.preventDefault(); |
37 |
| - |
38 |
| - if (!this.clientConfig.checkoutInited) { |
39 |
| - paypalExpressCheckout.checkout.initXO(); |
40 |
| - this.clientConfig.checkoutInited = true; |
41 |
| - } else { |
42 |
| - paypalExpressCheckout.checkout.closeFlow(); |
43 |
| - } |
| 5 | +define([ |
| 6 | + 'underscore', |
| 7 | + 'jquery', |
| 8 | + 'uiComponent', |
| 9 | + 'paypalInContextExpressCheckout', |
| 10 | + 'Magento_Customer/js/customer-data', |
| 11 | + 'domReady!' |
| 12 | +], function (_, $, Component, paypalExpressCheckout, customerData) { |
| 13 | + 'use strict'; |
44 | 14 |
|
45 |
| - $.get( |
46 |
| - this.path, |
47 |
| - { |
48 |
| - button: 1 |
49 |
| - } |
50 |
| - ).done( |
51 |
| - function (response) { |
52 |
| - if (response && response.url) { |
53 |
| - paypalExpressCheckout.checkout.startFlow(response.url); |
54 |
| - |
55 |
| - return; |
56 |
| - } |
57 |
| - |
58 |
| - paypalExpressCheckout.checkout.closeFlow(); |
59 |
| - } |
60 |
| - ).fail( |
61 |
| - function () { |
62 |
| - paypalExpressCheckout.checkout.closeFlow(); |
63 |
| - } |
64 |
| - ).always( |
65 |
| - function () { |
66 |
| - $('body').trigger('processStop'); |
67 |
| - customerData.invalidate(['cart']); |
68 |
| - } |
69 |
| - ); |
70 |
| - } |
71 |
| - } |
72 |
| - }, |
73 |
| - |
74 |
| - /** |
75 |
| - * @returns {Object} |
76 |
| - */ |
77 |
| - initialize: function () { |
78 |
| - this._super(); |
79 |
| - |
80 |
| - return this.initClient(); |
81 |
| - }, |
82 |
| - |
83 |
| - /** |
84 |
| - * @returns {Object} |
85 |
| - */ |
86 |
| - initClient: function () { |
87 |
| - _.each(this.clientConfig, function (fn, name) { |
88 |
| - if (typeof fn === 'function') { |
89 |
| - this.clientConfig[name] = fn.bind(this); |
| 15 | + return Component.extend({ |
| 16 | + |
| 17 | + defaults: { |
| 18 | + clientConfig: { |
| 19 | + |
| 20 | + checkoutInited: false, |
| 21 | + |
| 22 | + /** |
| 23 | + * @param {Object} event |
| 24 | + */ |
| 25 | + click: function (event) { |
| 26 | + $('body').trigger('processStart'); |
| 27 | + |
| 28 | + event.preventDefault(); |
| 29 | + |
| 30 | + if (!this.clientConfig.checkoutInited) { |
| 31 | + paypalExpressCheckout.checkout.initXO(); |
| 32 | + this.clientConfig.checkoutInited = true; |
| 33 | + } else { |
| 34 | + paypalExpressCheckout.checkout.closeFlow(); |
90 | 35 | }
|
91 |
| - }, this); |
92 | 36 |
|
93 |
| - paypalExpressCheckout.checkout.setup(this.merchantId, this.clientConfig); |
| 37 | + $.get(this.path, { |
| 38 | + button: 1 |
| 39 | + }).done(function (response) { |
| 40 | + var message = response && response.message; |
| 41 | + |
| 42 | + if (message) { |
| 43 | + customerData.set('messages', { |
| 44 | + messages: [message] |
| 45 | + }); |
| 46 | + } |
| 47 | + |
| 48 | + if (response && response.url) { |
| 49 | + paypalExpressCheckout.checkout.startFlow(response.url); |
| 50 | + |
| 51 | + return; |
| 52 | + } |
94 | 53 |
|
95 |
| - return this; |
| 54 | + paypalExpressCheckout.checkout.closeFlow(); |
| 55 | + }).fail(function () { |
| 56 | + paypalExpressCheckout.checkout.closeFlow(); |
| 57 | + }).always(function () { |
| 58 | + $('body').trigger('processStop'); |
| 59 | + customerData.invalidate(['cart']); |
| 60 | + }); |
| 61 | + } |
96 | 62 | }
|
97 |
| - }); |
98 |
| - } |
99 |
| -); |
| 63 | + }, |
| 64 | + |
| 65 | + /** |
| 66 | + * @returns {Object} |
| 67 | + */ |
| 68 | + initialize: function () { |
| 69 | + this._super(); |
| 70 | + |
| 71 | + return this.initClient(); |
| 72 | + }, |
| 73 | + |
| 74 | + /** |
| 75 | + * @returns {Object} |
| 76 | + */ |
| 77 | + initClient: function () { |
| 78 | + _.each(this.clientConfig, function (fn, name) { |
| 79 | + if (typeof fn === 'function') { |
| 80 | + this.clientConfig[name] = fn.bind(this); |
| 81 | + } |
| 82 | + }, this); |
| 83 | + |
| 84 | + paypalExpressCheckout.checkout.setup(this.merchantId, this.clientConfig); |
| 85 | + |
| 86 | + return this; |
| 87 | + } |
| 88 | + }); |
| 89 | +}); |
0 commit comments