Skip to content

Commit 4de831a

Browse files
committed
Merge remote-tracking branch 'origin/MAGETWO-59600' into bugs
2 parents 1e69052 + 8cef0bb commit 4de831a

File tree

6 files changed

+341
-136
lines changed

6 files changed

+341
-136
lines changed

app/code/Magento/Paypal/Controller/Express/GetToken.php

Lines changed: 49 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,11 @@
1313
use Magento\Framework\Exception\LocalizedException;
1414
use Magento\Framework\Webapi\Exception;
1515
use Magento\Paypal\Model\Express\Checkout;
16+
use Magento\Framework\App\ObjectManager;
1617

1718
/**
1819
* Class GetToken
20+
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
1921
*/
2022
class GetToken extends AbstractExpress
2123
{
@@ -40,6 +42,46 @@ class GetToken extends AbstractExpress
4042
*/
4143
protected $_checkoutType = \Magento\Paypal\Model\Express\Checkout::class;
4244

45+
/**
46+
* @var \Psr\Log\LoggerInterface
47+
*/
48+
private $logger;
49+
50+
/**
51+
* @param \Magento\Framework\App\Action\Context $context
52+
* @param \Magento\Customer\Model\Session $customerSession
53+
* @param \Magento\Checkout\Model\Session $checkoutSession
54+
* @param \Magento\Sales\Model\OrderFactory $orderFactory
55+
* @param \Magento\Paypal\Model\Express\Checkout\Factory $checkoutFactory
56+
* @param \Magento\Framework\Session\Generic $paypalSession
57+
* @param \Magento\Framework\Url\Helper\Data $urlHelper
58+
* @param \Magento\Customer\Model\Url $customerUrl
59+
* @param \Psr\Log\LoggerInterface|null $logger
60+
*/
61+
public function __construct(
62+
\Magento\Framework\App\Action\Context $context,
63+
\Magento\Customer\Model\Session $customerSession,
64+
\Magento\Checkout\Model\Session $checkoutSession,
65+
\Magento\Sales\Model\OrderFactory $orderFactory,
66+
\Magento\Paypal\Model\Express\Checkout\Factory $checkoutFactory,
67+
\Magento\Framework\Session\Generic $paypalSession,
68+
\Magento\Framework\Url\Helper\Data $urlHelper,
69+
\Magento\Customer\Model\Url $customerUrl,
70+
\Psr\Log\LoggerInterface $logger = null
71+
) {
72+
$this->logger = $logger ?: ObjectManager::getInstance()->get(\Psr\Log\LoggerInterface::class);
73+
parent::__construct(
74+
$context,
75+
$customerSession,
76+
$checkoutSession,
77+
$orderFactory,
78+
$checkoutFactory,
79+
$paypalSession,
80+
$urlHelper,
81+
$customerUrl
82+
);
83+
}
84+
4385
/**
4486
* @inheritdoc
4587
*/
@@ -56,10 +98,13 @@ public function execute()
5698
$this->_initToken($token);
5799
$controllerResult->setData(['url' => $url]);
58100
} catch (LocalizedException $exception) {
59-
$this->messageManager->addExceptionMessage(
60-
$exception,
61-
$exception->getMessage()
62-
);
101+
$this->logger->critical($exception);
102+
$controllerResult->setData([
103+
'message' => [
104+
'text' => $exception->getMessage(),
105+
'type' => 'error'
106+
]
107+
]);
63108
} catch (\Exception $exception) {
64109
$this->messageManager->addExceptionMessage(
65110
$exception,

app/code/Magento/Paypal/view/frontend/web/js/action/set-payment-method.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,10 @@ define([
4444

4545
return storage[method](
4646
serviceUrl, JSON.stringify(payload)
47-
).fail(
48-
function (response) {
49-
errorProcessor.process(response, messageContainer);
50-
fullScreenLoader.stopLoader();
51-
}
52-
);
47+
).fail(function (response) {
48+
errorProcessor.process(response, messageContainer);
49+
}).always(function () {
50+
fullScreenLoader.stopLoader();
51+
});
5352
};
5453
});

app/code/Magento/Paypal/view/frontend/web/js/in-context/express-checkout.js

Lines changed: 80 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -2,98 +2,88 @@
22
* Copyright © Magento, Inc. All rights reserved.
33
* See COPYING.txt for license details.
44
*/
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';
4414

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();
9035
}
91-
}, this);
9236

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+
}
9453

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+
}
9662
}
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+
});

app/code/Magento/Paypal/view/frontend/web/js/view/payment/method-renderer/in-context/checkout-express.js

Lines changed: 38 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ define(
1111
'Magento_Checkout/js/model/payment/additional-validators',
1212
'Magento_Ui/js/lib/view/utils/dom-observer',
1313
'paypalInContextExpressCheckout',
14-
'Magento_Customer/js/customer-data'
14+
'Magento_Customer/js/customer-data',
15+
'Magento_Ui/js/model/messageList'
1516
],
1617
function (
1718
_,
@@ -21,7 +22,8 @@ define(
2122
additionalValidators,
2223
domObserver,
2324
paypalExpressCheckout,
24-
customerData
25+
customerData,
26+
messageList
2527
) {
2628
'use strict';
2729

@@ -33,7 +35,6 @@ define(
3335
defaults: {
3436
template: 'Magento_Paypal/payment/paypal-express-in-context',
3537
clientConfig: {
36-
3738
/**
3839
* @param {Object} event
3940
*/
@@ -42,41 +43,42 @@ define(
4243

4344
if (additionalValidators.validate()) {
4445
paypalExpressCheckout.checkout.initXO();
45-
this.selectPaymentMethod();
46-
setPaymentMethodAction(this.messageContainer).done(
47-
function () {
48-
$('body').trigger('processStart');
49-
50-
$.get(
51-
this.path,
52-
{
53-
button: 0
54-
}
55-
).done(
56-
function (response) {
57-
if (response && response.url) {
58-
paypalExpressCheckout.checkout.startFlow(response.url);
59-
60-
return;
61-
}
6246

63-
paypalExpressCheckout.checkout.closeFlow();
64-
window.location.reload();
65-
}
66-
).fail(
67-
function () {
68-
paypalExpressCheckout.checkout.closeFlow();
69-
window.location.reload();
70-
}
71-
).always(
72-
function () {
73-
$('body').trigger('processStop');
74-
customerData.invalidate(['cart']);
47+
this.selectPaymentMethod();
48+
setPaymentMethodAction(this.messageContainer).done(function () {
49+
$('body').trigger('processStart');
50+
51+
$.get(this.path, {
52+
button: 0
53+
}).done(function (response) {
54+
var message = response && response.message;
55+
56+
if (message) {
57+
if (message.type === 'error') {
58+
messageList.addErrorMessage({
59+
message: message.text
60+
});
61+
} else {
62+
messageList.addSuccessMessage({
63+
message: message.text
64+
});
7565
}
76-
);
77-
78-
}.bind(this)
79-
);
66+
}
67+
68+
if (response && response.url) {
69+
paypalExpressCheckout.checkout.startFlow(response.url);
70+
71+
return;
72+
}
73+
74+
paypalExpressCheckout.checkout.closeFlow();
75+
}).fail(function () {
76+
paypalExpressCheckout.checkout.closeFlow();
77+
}).always(function () {
78+
$('body').trigger('processStop');
79+
customerData.invalidate(['cart']);
80+
});
81+
}.bind(this));
8082
}
8183
}
8284
}

0 commit comments

Comments
 (0)