Skip to content

Commit

Permalink
Merge pull request #1049 from BearGroup/release/5.4.0
Browse files Browse the repository at this point in the history
Release/5.4.0
  • Loading branch information
Christian Zichichi authored May 20, 2021
2 parents da88579 + 0ee9949 commit 75e8b4b
Show file tree
Hide file tree
Showing 9 changed files with 245 additions and 39 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Change Log

## 5.4.0
* Fixed credential validation when inheriting from parent scope
* Fixed issue to properly handle when Amazon Pay returns empty buyer ID
* Fixed issue with using Alexa notifications and custom carriers
* Fixed issue where a quote could be submitted to Magento multiple times

## 5.3.0
* Support for OneStepCheckout v1.2.047+
* Added sort order to payment method config
Expand Down
6 changes: 5 additions & 1 deletion Controller/Login.php
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ protected function getAmazonCustomer($token)
$userInfo = $this->amazonAdapter
->getBuyer($token);

if (is_array($userInfo) && isset($userInfo['buyerId'])) {
if (is_array($userInfo) && !empty($userInfo['buyerId'])) {
$data = [
'id' => $userInfo['buyerId'],
'email' => $userInfo['email'],
Expand All @@ -188,7 +188,11 @@ protected function getAmazonCustomer($token)
$amazonCustomer = $this->amazonCustomerFactory->create($data);

return $amazonCustomer;

} else {
$this->logger->error('Amazon buyerId is empty. Token: ' . $token);
}

} catch (\Exception $e) {
$this->logger->error($e);
$this->messageManager->addErrorMessage(__('Error processing Amazon Login'));
Expand Down
7 changes: 7 additions & 0 deletions Model/Alexa.php
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,13 @@ public function addDeliveryNotification($track)
if ($this->canAddDeliveryNotification($track)) {
$chargePermissionId = $this->getChargePermissionId($track->getShipment()->getOrder());
$carrierCode = $this->getCarrierCode($track);

if ($carrierCode == "CUSTOM") {
throw new \Magento\Framework\Exception\NotFoundException(
new Phrase('No matched Alexa Notification carrier for: ' . $track->getTitle())
);
}

$response = $this->apiCall($track->getStoreId(), 'deliveryTrackers', [json_encode([
'amazonOrderReferenceId' => $chargePermissionId,
'deliveryDetails' => [[
Expand Down
20 changes: 17 additions & 3 deletions Model/AmazonConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,6 @@ public function useMultiCurrency($store = null)
*
* @param string $scope
* @param null $scopeCode
* @param null $store
*
* @return string
*/
Expand All @@ -406,12 +405,28 @@ public function getPrivateKey($scope = ScopeInterface::SCOPE_STORE, $scopeCode =
);
}

/**
* Return Private Key Selected method (text or pem)
*
* @param string $scope
* @param null $scopeCode
*
* @return string
*/
public function getPrivateKeySelected($scope = ScopeInterface::SCOPE_STORE, $scopeCode = null)
{
return $this->scopeConfig->getValue(
'payment/amazon_payment_v2/private_key_selected',
$scope,
$scopeCode
);
}

/**
* Return Public Key
*
* @param string $scope
* @param null $scopeCode
* @param null $store
*
* @return string
*/
Expand All @@ -429,7 +444,6 @@ public function getPublicKey($scope = ScopeInterface::SCOPE_STORE, $scopeCode =
*
* @param string $scope
* @param null $scopeCode
* @param null $store
*
* @return string
*/
Expand Down
33 changes: 31 additions & 2 deletions Model/CheckoutSessionManagement.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,11 @@ class CheckoutSessionManagement implements \Amazon\Pay\Api\CheckoutSessionManage
*/
private $carts = [];

/**
* @var \Magento\Sales\Model\ResourceModel\Order\CollectionFactory
*/
private $orderCollectionFactory;

/**
* CheckoutSessionManagement constructor.
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
Expand All @@ -151,6 +156,7 @@ class CheckoutSessionManagement implements \Amazon\Pay\Api\CheckoutSessionManage
* @param \Amazon\Pay\Model\AsyncManagement\Charge $asyncCharge
* @param \Magento\Sales\Api\TransactionRepositoryInterface $transactionRepository
* @param \Magento\Framework\Api\SearchCriteriaBuilder $searchCriteriaBuilder
* @param \Magento\Sales\Model\ResourceModel\Order\CollectionFactory $orderCollectionFactory
*/
public function __construct(
\Magento\Store\Model\StoreManagerInterface $storeManager,
Expand All @@ -170,7 +176,8 @@ public function __construct(
\Amazon\Pay\Model\AsyncManagement $asyncManagement,
\Amazon\Pay\Model\AsyncManagement\Charge $asyncCharge,
\Magento\Sales\Api\TransactionRepositoryInterface $transactionRepository,
\Magento\Framework\Api\SearchCriteriaBuilder $searchCriteriaBuilder
\Magento\Framework\Api\SearchCriteriaBuilder $searchCriteriaBuilder,
\Magento\Sales\Model\ResourceModel\Order\CollectionFactory $orderCollectionFactory
) {
$this->storeManager = $storeManager;
$this->quoteIdMaskFactory = $quoteIdMaskFactory;
Expand All @@ -190,6 +197,7 @@ public function __construct(
$this->asyncCharge = $asyncCharge;
$this->transactionRepository = $transactionRepository;
$this->searchCriteriaBuilder = $searchCriteriaBuilder;
$this->orderCollectionFactory = $orderCollectionFactory;
}

/**
Expand All @@ -216,6 +224,27 @@ protected function canCheckoutWithAmazon()
!$this->amazonHelper->hasRestrictedProducts($this->magentoCheckoutSession->getQuote());
}

/**
* In some particular cases an error occurs in Magento where an order with the same quoteId
* is duplicated in a very short time difference.
* This method checks if there is already an order created for that particular Quote.
* https://github.com/magento/magento2/issues/13952
* @param Quote $quote
* @return bool
*/
protected function canSubmitQuote($quote)
{
if (!$quote->getIsActive()) {
return false;
}

$orderCollection = $this->orderCollectionFactory->create()
->addFieldToSelect('increment_id')
->addFieldToFilter('quote_id', ['eq' => $quote->getId()]);

return ($orderCollection->count() == 0);
}

/**
* @param mixed $amazonCheckoutSessionId
* @param bool $isShippingAddress
Expand Down Expand Up @@ -501,7 +530,7 @@ public function completeCheckoutSession($amazonSessionId)
{
$cart = $this->magentoCheckoutSession->getQuote();

if (empty($amazonSessionId) || !$this->canCheckoutWithAmazon()) {
if (empty($amazonSessionId) || !$this->canCheckoutWithAmazon() || !$this->canSubmitQuote($cart)) {
return [
'success' => false,
'message' => __("Unable to complete Amazon Pay checkout"),
Expand Down
Loading

0 comments on commit 75e8b4b

Please sign in to comment.