Skip to content

Commit

Permalink
Merge pull request #1231 from BearGroup/release/5.17.0
Browse files Browse the repository at this point in the history
Release/5.17.0
  • Loading branch information
akshitaWaldia authored Apr 16, 2024
2 parents 2b1fa0b + c0ab4af commit ccf7589
Show file tree
Hide file tree
Showing 31 changed files with 1,007 additions and 351 deletions.
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
# Change Log

## 5.17.0
* Changed sequence of placing Magento order/processing Amazon payment to reduce likelihood of
transactions with no associated order IDs in Seller Central
* Fixed KeyUpgrade patch error when the database tables are prefixed
* Fixed overwriting of existent CV2 configs on KeyUpgrade
* Improved behavior of PDP button (ensure product is added to cart before initiating Amazon checkout)
* Fixed unresponsive PDP button on Safari mobile
* Fixed non-centered PDP button on mobile view
* Fixed incorrect type casting when decrypting Auto Key Exchange payloads
* Fixed updateCheckoutSession call in headless environments when the session helper returns
a new/empty quote (thanks, @bheindl!)
* Changed response format of checkout session details GraphQL query to adhere to best practices
(thanks, @dimitriBouteille!)
* Added Amazon Pay payment region to storeConfig GraphQL query (thanks again, @dimitriBouteiile!)

## 5.16.1
* Remove platform/module version information from button payloads
* Fixed admin display bug regarding upgrading legacy keys when a CV2 public key ID already exists
Expand Down
2 changes: 2 additions & 0 deletions Command/Async/ProcessCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,5 +73,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
/** @var \Amazon\Pay\Model\Async $item */
$this->asyncUpdater->processPending($item);
}

return Command::SUCCESS;
}
}
2 changes: 2 additions & 0 deletions Command/Sales/AmazonChargePermissionCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,5 +125,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
$verified = $referenceID == $orderId;
$output->writeln(var_export($verified));
}

return Command::SUCCESS;
}
}
105 changes: 105 additions & 0 deletions Controller/Checkout/Cancel.php
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
}
}
12 changes: 3 additions & 9 deletions Controller/Checkout/CompleteSession.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,7 @@

class CompleteSession extends \Magento\Framework\App\Action\Action
{
/**
* @var \Amazon\Pay\CustomerData\CheckoutSession
*/
private $amazonCheckoutSession;
protected const GENERIC_COMPLETE_CHECKOUT_ERROR_MESSAGE = 'Unable to complete Amazon Pay checkout.';

/**
* @var \Amazon\Pay\Model\CheckoutSessionManagement
Expand Down Expand Up @@ -58,10 +55,9 @@ class CompleteSession extends \Magento\Framework\App\Action\Action
private $cookieMetadataFactory;

/**
* CompleteCheckout constructor.
* CompleteSession constructor
*
* @param \Magento\Framework\App\Action\Context $context
* @param \Amazon\Pay\CustomerData\CheckoutSession $amazonCheckoutSession
* @param \Amazon\Pay\Model\CheckoutSessionManagement $checkoutSessionManagement
* @param \Amazon\Pay\Model\AmazonConfig $amazonConfig
* @param \Magento\Framework\Stdlib\CookieManagerInterface $cookieManager
Expand All @@ -71,7 +67,6 @@ class CompleteSession extends \Magento\Framework\App\Action\Action
*/
public function __construct(
\Magento\Framework\App\Action\Context $context,
\Amazon\Pay\CustomerData\CheckoutSession $amazonCheckoutSession,
\Amazon\Pay\Model\CheckoutSessionManagement $checkoutSessionManagement,
\Amazon\Pay\Model\AmazonConfig $amazonConfig,
\Magento\Framework\Stdlib\CookieManagerInterface $cookieManager,
Expand All @@ -80,7 +75,6 @@ public function __construct(
ExceptionLogger $exceptionLogger = null
) {
parent::__construct($context);
$this->amazonCheckoutSession = $amazonCheckoutSession;
$this->amazonCheckoutSessionManagement = $checkoutSessionManagement;
$this->amazonConfig = $amazonConfig;
$this->exceptionLogger = $exceptionLogger ?: ObjectManager::getInstance()->get(ExceptionLogger::class);
Expand Down Expand Up @@ -115,7 +109,7 @@ public function execute()
]);
} catch (\Exception $e) {
$this->exceptionLogger->logException($e);
$this->messageManager->addErrorMessage($e->getMessage());
$this->messageManager->addErrorMessage(self::GENERIC_COMPLETE_CHECKOUT_ERROR_MESSAGE);
}

return $this->_redirect('checkout/cart', [
Expand Down
100 changes: 100 additions & 0 deletions Controller/Checkout/PlaceOrder.php
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);
}
}
2 changes: 1 addition & 1 deletion Helper/Session.php
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ public function getQuoteFromIdOrSession($cartId = null)
// we only really want to utilize masked ids here unless retrieved elsewhere
if (empty($cartId) || is_numeric($cartId)) {
$quote = $this->getQuote();
if (!$quote) {
if (!$quote || !$quote->getId()) {
// here we'll check the user context for any available cart data before moving on
$userContextCartId = $this->getCartIdViaUserContext();
if ($userContextCartId !== null) {
Expand Down
10 changes: 8 additions & 2 deletions Model/Adapter/AmazonPayAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -713,11 +713,17 @@ public function signButton($payload, $storeId = null)
protected function getCheckoutCancelUrl()
{
$checkoutCancelUrl = $this->amazonConfig->getCheckoutCancelUrl();

if (empty($checkoutCancelUrl)) {
return $this->getDefaultCancelUrl();
$cancelUrl = $this->getDefaultCancelUrl();
} else {
$cancelUrl = $this->url->getUrl($checkoutCancelUrl);
}

return $this->url->getUrl($checkoutCancelUrl);
return $this->url->getUrl(
'amazon_pay/checkout/cancel',
['redirect' => base64_encode($cancelUrl)]
);
}

/**
Expand Down
Loading

0 comments on commit ccf7589

Please sign in to comment.