-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1231 from BearGroup/release/5.17.0
Release/5.17.0
- Loading branch information
Showing
31 changed files
with
1,007 additions
and
351 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
<?php | ||
|
||
namespace Amazon\Pay\Controller\Checkout; | ||
|
||
use Amazon\Pay\Model\CheckoutSessionManagement; | ||
use Magento\Checkout\Model\Session; | ||
use Magento\Framework\App\Action\HttpGetActionInterface; | ||
use Magento\Framework\App\RequestInterface; | ||
use Magento\Framework\Controller\ResultFactory; | ||
use Magento\Framework\Message\ManagerInterface; | ||
use Magento\Sales\Model\Order; | ||
use Amazon\Pay\Gateway\Config\Config; | ||
|
||
class Cancel implements HttpGetActionInterface | ||
{ | ||
/** | ||
* @var RequestInterface | ||
*/ | ||
protected $request; | ||
|
||
/** | ||
* @var ResultFactory | ||
*/ | ||
protected $resultFactory; | ||
|
||
/** | ||
* @var Session | ||
*/ | ||
protected $magentoCheckoutSession; | ||
|
||
/** | ||
* @var CheckoutSessionManagement | ||
*/ | ||
protected $checkoutSessionManagement; | ||
|
||
/** | ||
* @var ManagerInterface | ||
*/ | ||
protected $messageManager; | ||
|
||
/** | ||
* @param RequestInterface $request | ||
* @param ResultFactory $resultFactory | ||
* @param Session $magentoCheckoutSession | ||
* @param CheckoutSessionManagement $checkoutSessionManagement | ||
* @param ManagerInterface $messageManager | ||
*/ | ||
public function __construct( | ||
RequestInterface $request, | ||
ResultFactory $resultFactory, | ||
Session $magentoCheckoutSession, | ||
CheckoutSessionManagement $checkoutSessionManagement, | ||
ManagerInterface $messageManager | ||
) { | ||
$this->request = $request; | ||
$this->resultFactory = $resultFactory; | ||
$this->magentoCheckoutSession = $magentoCheckoutSession; | ||
$this->checkoutSessionManagement = $checkoutSessionManagement; | ||
$this->messageManager = $messageManager; | ||
} | ||
|
||
/** | ||
* Handle cancelling Amazon Pay orders when necessary | ||
* | ||
* @return \Magento\Framework\App\ResponseInterface|\Magento\Framework\Controller\ResultInterface | ||
* @throws \Magento\Framework\Exception\LocalizedException | ||
* @throws \Magento\Framework\Exception\NoSuchEntityException | ||
*/ | ||
public function execute() | ||
{ | ||
$redirectParam = $this->request->getParam('redirect'); | ||
$result = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT); | ||
|
||
// redirect to cart if no redirect param provided | ||
if (empty($redirectParam)) { | ||
return $result->setPath('checkout/cart'); | ||
} | ||
|
||
// check if there is an order still in the session, then and cancel it | ||
if ($order = $this->magentoCheckoutSession->getLastRealOrder()) { | ||
if (!empty($order->getData()) | ||
&& $order->getState() !== Order::STATE_CANCELED | ||
&& $order->getPayment() | ||
&& ( | ||
$order->getPayment()->getMethod() === Config::CODE || | ||
$order->getPayment()->getMethod() === Config::VAULT_CODE | ||
) | ||
) { | ||
$quote = $this->magentoCheckoutSession->getQuote(); | ||
|
||
if (!$quote->getIsActive()) { | ||
$this->checkoutSessionManagement->cancelOrder($order, $quote); | ||
|
||
$this->magentoCheckoutSession->restoreQuote(); | ||
|
||
$this->messageManager->addErrorMessage(__('This transaction was cancelled. Please try again.')); | ||
} | ||
} | ||
} | ||
|
||
$result = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT); | ||
|
||
return $result->setUrl(base64_decode($redirectParam)); // phpcs:ignore Magento2.Functions.DiscouragedFunction | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
<?php | ||
/** | ||
* Copyright © Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"). | ||
* You may not use this file except in compliance with the License. | ||
* A copy of the License is located at | ||
* | ||
* http://aws.amazon.com/apache2.0 | ||
* | ||
* or in the "license" file accompanying this file. This file is distributed | ||
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either | ||
* express or implied. See the License for the specific language governing | ||
* permissions and limitations under the License. | ||
*/ | ||
namespace Amazon\Pay\Controller\Checkout; | ||
|
||
use Amazon\Pay\Model\CheckoutSessionManagement; | ||
use Magento\Framework\App\Action\HttpPostActionInterface; | ||
use Magento\Framework\App\ObjectManager; | ||
use Amazon\Pay\Logger\ExceptionLogger; | ||
use Magento\Framework\App\RequestInterface; | ||
use Magento\Framework\Controller\Result\JsonFactory; | ||
use Magento\Framework\Message\ManagerInterface; | ||
|
||
class PlaceOrder implements HttpPostActionInterface | ||
{ | ||
/** | ||
* @var CheckoutSessionManagement | ||
*/ | ||
private $amazonCheckoutSessionManagement; | ||
|
||
/** | ||
* @var JsonFactory | ||
*/ | ||
private $jsonFactory; | ||
|
||
/** | ||
* @var ManagerInterface | ||
*/ | ||
protected $messageManager; | ||
|
||
/** | ||
* @var ExceptionLogger | ||
*/ | ||
private $exceptionLogger; | ||
|
||
/** | ||
* @var RequestInterface | ||
*/ | ||
protected $request; | ||
|
||
/** | ||
* PlaceOrder constructor. | ||
* | ||
* @param CheckoutSessionManagement $checkoutSessionManagement | ||
* @param JsonFactory $jsonFactory | ||
* @param ManagerInterface $messageManager | ||
* @param RequestInterface $request | ||
* @param ExceptionLogger|null $exceptionLogger | ||
*/ | ||
public function __construct( | ||
CheckoutSessionManagement $checkoutSessionManagement, | ||
JsonFactory $jsonFactory, | ||
ManagerInterface $messageManager, | ||
RequestInterface $request, | ||
ExceptionLogger $exceptionLogger = null | ||
) { | ||
$this->amazonCheckoutSessionManagement = $checkoutSessionManagement; | ||
$this->exceptionLogger = $exceptionLogger ?: ObjectManager::getInstance()->get(ExceptionLogger::class); | ||
$this->messageManager = $messageManager; | ||
$this->request = $request; | ||
$this->jsonFactory = $jsonFactory; | ||
} | ||
|
||
/** | ||
* Execute PlaceOrder Controller | ||
* | ||
* @inheirtdoc | ||
*/ | ||
public function execute() | ||
{ | ||
$result = ['success' => false]; | ||
try { | ||
// Bypass cache check in \Magento\PageCache\Model\DepersonalizeChecker | ||
$this->request->setParams(['ajax' => 1]); | ||
$amazonCheckoutSessionId = $this->request->getParam('amazonCheckoutSessionId'); | ||
|
||
$result = $this->amazonCheckoutSessionManagement->placeOrder($amazonCheckoutSessionId); | ||
if (!$result['success']) { | ||
$this->messageManager->addErrorMessage($result['message']); | ||
} | ||
} catch (\Exception $e) { | ||
$this->exceptionLogger->logException($e); | ||
$this->messageManager->addErrorMessage($e->getMessage()); | ||
} | ||
$jsonResult = $this->jsonFactory->create(); | ||
return $jsonResult->setData($result); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.