Skip to content

Commit cc31a38

Browse files
committed
MC-41638: [Paypal Express Checkout] Can't place an order
1 parent d6962a0 commit cc31a38

File tree

1 file changed

+26
-3
lines changed

1 file changed

+26
-3
lines changed

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

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ class GetTokenData extends AbstractExpress implements HttpGetActionInterface
7676
private $guestCartRepository;
7777

7878
/**
79-
* @var UserContextInterface
79+
* @var UserContextInterface|null
8080
*/
8181
private $userContext;
8282

@@ -109,7 +109,7 @@ public function __construct(
109109
CustomerRepository $customerRepository,
110110
CartRepositoryInterface $cartRepository,
111111
GuestCartRepositoryInterface $guestCartRepository,
112-
UserContextInterface $userContext
112+
UserContextInterface $userContext = null
113113
) {
114114
parent::__construct(
115115
$context,
@@ -162,9 +162,32 @@ public function execute(): ResultInterface
162162
$responseContent['error_message'] = __('Sorry, but something went wrong');
163163
}
164164

165+
if (!$responseContent['success']) {
166+
$this->messageManager->addErrorMessage($responseContent['error_message']);
167+
}
168+
165169
return $controllerResult->setData($responseContent);
166170
}
167171

172+
/**
173+
* Prepare quote specified for checkout.
174+
*
175+
* @return \Magento\Quote\Api\Data\CartInterface
176+
* @throws LocalizedException
177+
*/
178+
private function prepareQuote()
179+
{
180+
$quoteId = $this->getRequest()->getParam('quote_id');
181+
if ($quoteId) {
182+
$quote = $this->userContext->getUserId()
183+
? $this->cartRepository->get($quoteId)
184+
: $this->guestCartRepository->get($quoteId);
185+
if ((int)$quote->getCustomer()->getId() === (int)$this->userContext->getUserId()) {
186+
return $quote;
187+
}
188+
}
189+
return $this->_getQuote();
190+
}
168191
/**
169192
* Get paypal token
170193
*
@@ -173,7 +196,7 @@ public function execute(): ResultInterface
173196
*/
174197
private function getToken(): ?string
175198
{
176-
$quote = $this->_getQuote();
199+
$quote = $this->prepareQuote();
177200
$this->_initCheckout($quote);
178201

179202
if ($quote->getIsMultiShipping()) {

0 commit comments

Comments
 (0)