Skip to content

Commit

Permalink
Merge pull request #1080 from BearGroup/release/5.8.0
Browse files Browse the repository at this point in the history
Release/5.8.0
  • Loading branch information
tlundgr authored Sep 21, 2021
2 parents 2cc203f + bb12f84 commit f59865e
Show file tree
Hide file tree
Showing 37 changed files with 353 additions and 22 deletions.
2 changes: 1 addition & 1 deletion Api/CheckoutSessionManagementInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
interface CheckoutSessionManagementInterface
{
/**
* @param mixed|null $cartId
* @param string|null $cartId
* @return mixed
*/
public function getConfig($cartId = null);
Expand Down
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# Change Log

## 5.8.0
* Added log message if we are unable to complete checkout session due to an existing order with same quoteId
* Added email when asynchronous order processing is declined
* Fixed issue with Magento Open Source when configured to only allow a single address line
* Fixed API output for config endpoint to return key/value pairs
* Fixed issue generating Swagger docs (thanks @ebaschiera!)
* Fixed issue with canceling transactions started prior to upgrading to CV2/Marketplace module
* Fixed issue where the Amazon Pay payment method button on Onestepcheckout_Iosc would not trigger when clicking Place Order

## 5.7.1
* Fixed issue when phone number not required and entered in Magento
* Updated API calls to take in a masked cart ID so they can be used without relying on Magento sessions
Expand Down
9 changes: 9 additions & 0 deletions Command/Async/ProcessCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,29 @@ class ProcessCommand extends Command
*/
private $asyncUpdater;

/**
* @var \Magento\Framework\App\State
*/
private $state;

/**
* ProcessCommand constructor.
*
* These dependencies are proxied, update di.xml if changed
* @param \Amazon\Pay\Model\ResourceModel\Async\CollectionFactory $asyncCollectionFactory
* @param \Amazon\Pay\Model\AsyncUpdater $asyncUpdater
* @param \Magento\Framework\App\State $state
* @param string|null $name
*/
public function __construct(
\Amazon\Pay\Model\ResourceModel\Async\CollectionFactory $asyncCollectionFactory,
\Amazon\Pay\Model\AsyncUpdater $asyncUpdater,
\Magento\Framework\App\State $state,
string $name = null
) {
$this->asyncCollectionFactory = $asyncCollectionFactory;
$this->asyncUpdater = $asyncUpdater;
$this->state = $state;
parent::__construct($name);
}

Expand All @@ -46,6 +54,7 @@ protected function configure()

protected function execute(InputInterface $input, OutputInterface $output)
{
$this->state->setAreaCode(\Magento\Framework\App\Area::AREA_ADMINHTML);
$collection = $this->asyncCollectionFactory->create();
$collection->addFieldToFilter(AsyncInterface::IS_PENDING, ['eq' => 1]);
$collection->addOrder(AsyncInterface::ID, Collection::SORT_ORDER_ASC);
Expand Down
6 changes: 5 additions & 1 deletion CustomerData/CheckoutSession.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ public function __construct(
*/
public function getConfig()
{
return $this->checkoutSessionManagement->getConfig();
$data = $this->checkoutSessionManagement->getConfig();
if (count($data) > 0) {
$data = $data[0];
}
return $data;
}
}
2 changes: 1 addition & 1 deletion Gateway/Request/VoidRequestBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public function build(array $buildSubject)

// If we do not have a charge permission on the payment, try the first 3 sections of transaction ID
if (empty($chargePermissionId)) {
$transactionId = explode('-', $paymentDO->getPayment()->getParentTransactionId());
$transactionId = explode('-', $paymentDO->getPayment()->getAuthorizationTransaction()->getTxnId());
$chargePermissionId = implode('-', array_slice($transactionId, 0, 3));
}

Expand Down
35 changes: 29 additions & 6 deletions Helper/Address.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
use Magento\Customer\Api\Data\RegionInterfaceFactory;
use Magento\Directory\Model\RegionFactory;
use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Framework\App\ProductMetadataInterface;
use Magento\Eav\Model\Config as EavConfig;

class Address
{
Expand All @@ -46,16 +48,30 @@ class Address
*/
private $scopeConfig;

/**
* @var eavConfig
*/
private $eavConfig;

/**
* @var productMetadata
*/
private $productMetadata;

public function __construct(
AddressInterfaceFactory $addressFactory,
RegionFactory $regionFactory,
RegionInterfaceFactory $regionDataFactory,
ScopeConfigInterface $config
ScopeConfigInterface $config,
EavConfig $eavConfig,
ProductMetadataInterface $productMetadata
) {
$this->addressFactory = $addressFactory;
$this->regionFactory = $regionFactory;
$this->regionDataFactory = $regionDataFactory;
$this->scopeConfig = $config;
$this->productMetadata = $productMetadata;
$this->eavConfig = $eavConfig;
}

/**
Expand All @@ -67,11 +83,18 @@ public function __construct(
*/
public function convertToMagentoEntity(AmazonAddressInterface $amazonAddress)
{
$addressLinesAllowed = (int) $this->scopeConfig->getValue(
'customer/address/street_lines',
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
);

if ($this->productMetadata->getEdition() == 'Enterprise') {
$addressLinesAllowed = (int) $this->eavConfig->getAttribute(
'customer_address',
'street'
)->getMultilineCount();
} else {
$addressLinesAllowed = (int) $this->scopeConfig->getValue(
'customer/address/street_lines',
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
);
}

$address = $this->addressFactory->create();
$address->setFirstname($amazonAddress->getFirstName());
$address->setLastname($amazonAddress->getLastName());
Expand Down
90 changes: 90 additions & 0 deletions Helper/Email.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
<?php
/**
* Copyright 2020 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\Helper;

use Magento\Framework\App\Helper\AbstractHelper;

class Email extends AbstractHelper
{
/**
* @var \Magento\Store\Model\StoreManagerInterface
*/
private $storeManager;

/**
* @var \Magento\Framework\Mail\Template\TransportBuilder
*/
private $transportBuilder;

/**
* @var \Amazon\Pay\Logger\AsyncIpnLogger
*/
private $asyncLogger;

/**
* @param Context $context
* @param TransportBuilder $transportBuilder
* @param StoreManagerInterface $storeManager
* @param \Amazon\Pay\Logger\AsyncIpnLogger $asyncLogger
*/
public function __construct(
\Magento\Framework\App\Helper\Context $context,
\Magento\Framework\Mail\Template\TransportBuilder $transportBuilder,
\Magento\Store\Model\StoreManagerInterface $storeManager,
\Amazon\Pay\Logger\AsyncIpnLogger $asyncLogger
) {
parent::__construct($context);
$this->transportBuilder = $transportBuilder;
$this->storeManager = $storeManager;
$this->asyncLogger = $asyncLogger;
}

/**
* @param Order $order
*
* @return void
*/
public function sendPaymentDeclinedEmail(\Magento\Sales\Model\Order $order)
{
try {
$storeName = $this->getStoreName($order->getStoreId());
$transport = $this->transportBuilder
->setTemplateIdentifier('amazon_pay_payment_declined')
->setTemplateOptions(
[
'area' => \Magento\Framework\App\Area::AREA_FRONTEND,
'store' => $order->getStoreId()
]
)
->setFrom('general')
->setTemplateVars(['storeName' => $storeName, 'incrementId' => $order->getIncrementId()])
->addTo($order->getCustomerEmail(), $order->getCustomerName())
->getTransport();

$transport->sendMessage();
$this->asyncLogger->info('Payment declined email sent for Order #' . $order->getIncrementId());
} catch (\Exception $e) {
$error = $order->getIncrementId() . '-' . $e->getMessage();
$this->asyncLogger->info('Cannot send payment declined email for Order #' . $error);
}
}

protected function getStoreName($storeId)
{
$store = $this->storeManager->getStore($storeId);
return $store->getFrontendName();
}
}
14 changes: 12 additions & 2 deletions Model/AsyncManagement/Charge.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
use Magento\Sales\Api\Data\InvoiceInterface;
use Magento\Sales\Api\Data\OrderInterface;
use Magento\Sales\Model\Order;
use Magento\Framework\Event\ManagerInterface;

class Charge extends AbstractOperation
{
Expand Down Expand Up @@ -64,6 +65,11 @@ class Charge extends AbstractOperation
*/
private $amazonConfig;

/**
* @var EventManagerInterface
*/
private $eventManager;

/**
* Charge constructor.
* @param \Magento\Framework\Api\SearchCriteriaBuilder $searchCriteriaBuilder
Expand All @@ -77,6 +83,7 @@ class Charge extends AbstractOperation
* @param \Magento\Framework\Notification\NotifierInterface $notifier
* @param \Magento\Backend\Model\UrlInterface $urlBuilder
* @param \Amazon\Pay\Model\AmazonConfig $amazonConfig
* @param \Magento\Framework\Event\ManagerInterface $eventManager
*/
public function __construct(
\Magento\Framework\Api\SearchCriteriaBuilder $searchCriteriaBuilder,
Expand All @@ -89,7 +96,8 @@ public function __construct(
\Magento\Sales\Model\Order\Payment\Transaction\BuilderInterface $transactionBuilder,
\Magento\Framework\Notification\NotifierInterface $notifier,
\Magento\Backend\Model\UrlInterface $urlBuilder,
\Amazon\Pay\Model\AmazonConfig $amazonConfig
\Amazon\Pay\Model\AmazonConfig $amazonConfig,
\Magento\Framework\Event\ManagerInterface $eventManager
) {
parent::__construct($orderRepository, $transactionRepository, $searchCriteriaBuilder);
$this->amazonAdapter = $amazonAdapter;
Expand All @@ -100,6 +108,7 @@ public function __construct(
$this->notifier = $notifier;
$this->urlBuilder = $urlBuilder;
$this->amazonConfig = $amazonConfig;
$this->eventManager = $eventManager;
}

/**
Expand Down Expand Up @@ -222,6 +231,7 @@ public function decline($order, $chargeId, $detail)
);

$this->asyncLogger->info('Charge declined for Order #' . $order->getIncrementId());
$this->eventManager->dispatch('amazon_pay_async_payment_declined', ['order' => $order]);
}
}

Expand Down Expand Up @@ -288,6 +298,7 @@ public function capture($order, $chargeId, $chargeAmount)

if ($invoice && ($invoice->canCapture() || $invoice->getOrder()->getStatus() == Order::STATE_PAYMENT_REVIEW)) {
$order = $invoice->getOrder();
$this->setProcessing($order);
$payment = $order->getPayment();
$invoice->setTransactionId($chargeId);

Expand All @@ -308,7 +319,6 @@ public function capture($order, $chargeId, $chargeAmount)
$payment->setDataUsingMethod('base_amount_paid_online', $chargeAmount);
$payment->addTransactionCommentsToOrder($transaction, $message);
$transaction->setIsClosed(true);
$this->setProcessing($order);
$order->save();
$this->asyncLogger->info('Captured Order #' . $order->getIncrementId());
} else {
Expand Down
19 changes: 14 additions & 5 deletions Model/CheckoutSessionManagement.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,11 @@ class CheckoutSessionManagement implements \Amazon\Pay\Api\CheckoutSessionManage
*/
private $maskedQuoteIdConverter;

/**
* @var \Amazon\Pay\Logger\Logger
*/
private $logger;

/**
* CheckoutSessionManagement constructor.
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
Expand All @@ -167,6 +172,7 @@ class CheckoutSessionManagement implements \Amazon\Pay\Api\CheckoutSessionManage
* @param \Magento\Framework\Api\SearchCriteriaBuilder $searchCriteriaBuilder
* @param \Magento\Sales\Model\ResourceModel\Order\CollectionFactory $orderCollectionFactory
* @param MaskedQuoteIdToQuoteIdInterface $maskedQuoteIdConverter
* @param \Amazon\Pay\Logger\Logger $logger
*/
public function __construct(
\Magento\Store\Model\StoreManagerInterface $storeManager,
Expand All @@ -188,7 +194,8 @@ public function __construct(
\Magento\Sales\Api\TransactionRepositoryInterface $transactionRepository,
\Magento\Framework\Api\SearchCriteriaBuilder $searchCriteriaBuilder,
\Magento\Sales\Model\ResourceModel\Order\CollectionFactory $orderCollectionFactory,
MaskedQuoteIdToQuoteIdInterface $maskedQuoteIdConverter
MaskedQuoteIdToQuoteIdInterface $maskedQuoteIdConverter,
\Amazon\Pay\Logger\Logger $logger
) {
$this->storeManager = $storeManager;
$this->quoteIdMaskFactory = $quoteIdMaskFactory;
Expand All @@ -210,6 +217,7 @@ public function __construct(
$this->searchCriteriaBuilder = $searchCriteriaBuilder;
$this->orderCollectionFactory = $orderCollectionFactory;
$this->maskedQuoteIdConverter = $maskedQuoteIdConverter;
$this->logger = $logger;
}

/**
Expand Down Expand Up @@ -358,7 +366,7 @@ public function getConfig($cartId = null)
$this->amazonConfig->getPaymentAction()
);

$result = [
$result[] = [
'merchant_id' => $this->amazonConfig->getMerchantId(),
'currency' => $this->amazonConfig->getCurrencyCode(),
'button_color' => $this->amazonConfig->getButtonColor(),
Expand Down Expand Up @@ -510,9 +518,9 @@ protected function setProcessing($payment)
if (!empty($invoiceCollection->getItems())) {
$invoiceCollection->getFirstItem()->pay();
}
$order->setState(\Magento\Sales\Model\Order::STATE_PROCESSING)->setStatus(
\Magento\Sales\Model\Order::STATE_PROCESSING
);
$state = \Magento\Sales\Model\Order::STATE_PROCESSING;
$status = $order->getConfig()->getStateDefaultStatus($state);
$order->setState($state)->setStatus($status);
$this->orderRepository->save($order);
}

Expand Down Expand Up @@ -578,6 +586,7 @@ public function completeCheckoutSession($amazonSessionId, $cartId = null)
}

if (empty($amazonSessionId) || !$this->canCheckoutWithAmazon($quote) || !$this->canSubmitQuote($quote)) {
$this->logger->debug("Unable to complete Amazon Pay checkout. Can't submit quote id: " . $quote->getId());
return [
'success' => false,
'message' => __("Unable to complete Amazon Pay checkout"),
Expand Down
Loading

0 comments on commit f59865e

Please sign in to comment.