Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.18.3
* Added compatibility with Magento 2.4.8/PHP 8.4
* Fixed cron job error caused by function visibility
* Fixed security logic around APB flow
* Added black as a text color option for promo widget

## 5.18.2
* Added security enhancements around Express Checkout
* Changed when Magento order ID is sent to Amazon to improve traceability
Expand Down
2 changes: 1 addition & 1 deletion Command/Async/ProcessCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function __construct(
\Amazon\Pay\Model\ResourceModel\Async\CollectionFactory $asyncCollectionFactory,
\Amazon\Pay\Model\AsyncUpdater $asyncUpdater,
\Magento\Framework\App\State $state,
string $name = null
?string $name = null
) {
$this->asyncCollectionFactory = $asyncCollectionFactory;
$this->asyncUpdater = $asyncUpdater;
Expand Down
2 changes: 1 addition & 1 deletion Controller/Adminhtml/Pay/AutoKeyExchangePoll.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public function __construct(
AutoKeyExchange $autoKeyExchange,
ScopeConfigInterface $scopeConfig,
JsonFactory $jsonResultFactory,
ExceptionLogger $exceptionLogger = null
?ExceptionLogger $exceptionLogger = null
) {
parent::__construct($context);
$this->autoKeyExchange = $autoKeyExchange;
Expand Down
2 changes: 1 addition & 1 deletion Controller/AutoKeyExchange/Listener.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public function __construct(
\Magento\Framework\App\Action\Context $context,
\Magento\Framework\Controller\Result\JsonFactory $jsonResultFactory,
\Amazon\Pay\Model\Config\AutoKeyExchange $autokeyexchange,
ExceptionLogger $exceptionLogger = null
?ExceptionLogger $exceptionLogger = null
) {
$this->autokeyexchange = $autokeyexchange;
$this->jsonResultFactory = $jsonResultFactory;
Expand Down
2 changes: 1 addition & 1 deletion Controller/Checkout/CompleteSession.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public function __construct(
\Magento\Framework\Stdlib\CookieManagerInterface $cookieManager,
\Magento\Framework\Stdlib\Cookie\CookieMetadataFactory $cookieMetadataFactory,
\Magento\Store\Model\StoreManagerInterface $storeManager,
ExceptionLogger $exceptionLogger = null
?ExceptionLogger $exceptionLogger = null
) {
parent::__construct($context);
$this->amazonCheckoutSessionManagement = $checkoutSessionManagement;
Expand Down
2 changes: 1 addition & 1 deletion Controller/Checkout/PlaceOrder.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public function __construct(
JsonFactory $jsonFactory,
ManagerInterface $messageManager,
RequestInterface $request,
ExceptionLogger $exceptionLogger = null
?ExceptionLogger $exceptionLogger = null
) {
$this->amazonCheckoutSessionManagement = $checkoutSessionManagement;
$this->exceptionLogger = $exceptionLogger ?: ObjectManager::getInstance()->get(ExceptionLogger::class);
Expand Down
2 changes: 1 addition & 1 deletion Gateway/Command/CaptureStrategyCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public function __construct(
TransactionRepositoryInterface $transactionRepository,
SearchCriteriaBuilder $searchCriteriaBuilder,
FilterBuilder $filterBuilder,
ExceptionLogger $exceptionLogger = null
?ExceptionLogger $exceptionLogger = null
) {
$this->commandPool = $commandPool;
$this->transactionRepository = $transactionRepository;
Expand Down
4 changes: 2 additions & 2 deletions Model/Async.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ public function __construct(
\Magento\Framework\Model\Context $context,
\Magento\Framework\Registry $registry,
\Magento\Framework\Stdlib\DateTime\DateTimeFactory $dateFactory,
\Magento\Framework\Model\ResourceModel\AbstractResource $resource = null,
\Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null,
?\Magento\Framework\Model\ResourceModel\AbstractResource $resource = null,
?\Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null,
array $data = []
) {
parent::__construct(
Expand Down
35 changes: 25 additions & 10 deletions Model/CheckoutSessionManagement.php
Original file line number Diff line number Diff line change
Expand Up @@ -815,17 +815,18 @@ public function completeCheckoutSession($amazonSessionId, $cartId = null, $order
*/
public function placeOrder($amazonSessionId, $quoteId = null)
{

// verify the shipping address has not been modified in Magento, it must match
// the one selected in the Amazon checkout session (express checkout only)
if ($amznShippingAddress = $this->getShippingAddress($amazonSessionId)) {
$amazonAddress = $amznShippingAddress[0];
$magentoAddress = $this->session->getQuoteFromIdOrSession($quoteId)->getShippingAddress();
if (!$this->addressHelper->validateShippingIsSame($amazonAddress, $magentoAddress)) {
return $this->handleCompleteCheckoutSessionError(
self::ADDRESS_CHANGED_CHECKOUT_ERROR_MESSAGE,
$this->getAddressMismatchDetails($amazonAddress, $magentoAddress)
);
if ($this->isExpressCheckoutFlow()) {
if ($amznShippingAddress = $this->getShippingAddress($amazonSessionId)) {
$amazonAddress = $amznShippingAddress[0];
$magentoAddress = $this->session->getQuoteFromIdOrSession($quoteId)->getShippingAddress();
if (!$this->addressHelper->validateShippingIsSame($amazonAddress, $magentoAddress)) {
return $this->handleCompleteCheckoutSessionError(
self::ADDRESS_CHANGED_CHECKOUT_ERROR_MESSAGE,
$this->getAddressMismatchDetails($amazonAddress, $magentoAddress)
);
}
}
}

Expand Down Expand Up @@ -915,7 +916,7 @@ public function placeOrder($amazonSessionId, $quoteId = null)
* @param mixed $amazonSession
* @return \Magento\Framework\Phrase|mixed
*/
protected function getCanceledMessage($amazonSession)
public function getCanceledMessage($amazonSession)
{
if ($amazonSession['statusDetails']['reasonCode'] == 'BuyerCanceled') {
return $this->getTranslationString('This transaction was cancelled. Please try again.');
Expand Down Expand Up @@ -953,6 +954,20 @@ protected function getAddressMismatchDetails($amazonAddress, $magentoAddress)
]);
}

/**
* Determine whether the checkout session was completed via Express Checkout
*
* @return bool
*/
protected function isExpressCheckoutFlow()
{
$stack = debug_backtrace(DEBUG_BACKTRACE_PROVIDE_OBJECT);
return !empty(array_filter($stack, function ($entry) {
return isset($entry['class'])
&& $entry['class'] === 'Amazon\\Pay\\Controller\\Checkout\\PlaceOrder\\Interceptor';
}));
}

/**
* Update vault token
*
Expand Down
4 changes: 2 additions & 2 deletions Model/Config/File/PrivateKeyPem.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ public function __construct(
\Magento\Config\Model\Config\Backend\File\RequestData\RequestDataInterface $requestData,
\Magento\Framework\Filesystem $filesystem,
\Magento\Framework\Encryption\EncryptorInterface $encryptor,
\Magento\Framework\Model\ResourceModel\AbstractResource $resource = null,
\Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null,
?\Magento\Framework\Model\ResourceModel\AbstractResource $resource = null,
?\Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null,
array $data = []
) {
parent::__construct(
Expand Down
37 changes: 37 additions & 0 deletions Model/Config/Source/PromoFontColor.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?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\Model\Config\Source;

class PromoFontColor extends ButtonColor implements \Magento\Framework\Data\OptionSourceInterface
{
/**
* Create option array from font color choices
*
* @return array
*/
public function toOptionArray()
{
$values = parent::toOptionArray();
$values[] = [
'label' => __('Black'),
'value' => 'Black'
];

return $values;
}
}
2 changes: 1 addition & 1 deletion Model/Resolver/CheckoutSessionConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function __construct(
* @param array|null $args
* @return array|Value|mixed
*/
public function resolve(Field $field, $context, ResolveInfo $info, array $value = null, array $args = null)
public function resolve(Field $field, $context, ResolveInfo $info, ?array $value = null, ?array $args = null)
{
$cartId = $args['cartId'] ?? null;
$omitPayloads = $args['omitPayloads'] ?? false;
Expand Down
2 changes: 1 addition & 1 deletion Model/Resolver/CheckoutSessionDetails.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function __construct(
* @return array
* @throws GraphQlInputException
*/
public function resolve(Field $field, $context, ResolveInfo $info, array $value = null, array $args = null)
public function resolve(Field $field, $context, ResolveInfo $info, ?array $value = null, ?array $args = null)
{
$amazonSessionId = $args['amazonSessionId'] ?? false;
$queryTypes = $args['queryTypes'] ?? false;
Expand Down
2 changes: 1 addition & 1 deletion Model/Resolver/CheckoutSessionDetailsV2.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class CheckoutSessionDetailsV2 extends CheckoutSessionDetails implements Resolve
* @return array
* @throws GraphQlInputException
*/
public function resolve(Field $field, $context, ResolveInfo $info, array $value = null, array $args = null)
public function resolve(Field $field, $context, ResolveInfo $info, ?array $value = null, ?array $args = null)
{
$amazonSessionId = $args['amazonSessionId'] ?? false;
$queryTypes = ['shipping','billing','payment'];
Expand Down
2 changes: 1 addition & 1 deletion Model/Resolver/CheckoutSessionSignIn.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function __construct(
* @return array[]
* @throws GraphQlInputException
*/
public function resolve(Field $field, $context, ResolveInfo $info, array $value = null, array $args = null)
public function resolve(Field $field, $context, ResolveInfo $info, ?array $value = null, ?array $args = null)
{
$buyerToken = $args['buyerToken'] ?? false;

Expand Down
2 changes: 1 addition & 1 deletion Model/Resolver/CompleteCheckoutSession.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function __construct(
* @return array|false[]|int|Value|mixed
* @throws GraphQlInputException
*/
public function resolve(Field $field, $context, ResolveInfo $info, array $value = null, array $args = null)
public function resolve(Field $field, $context, ResolveInfo $info, ?array $value = null, ?array $args = null)
{
$cartId = $args['cartId'] ?? false;
$checkoutSessionId = $args['amazonSessionId'] ?? false;
Expand Down
2 changes: 1 addition & 1 deletion Model/Resolver/SetCustomerLink.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function __construct(
* @return array[]|Value|mixed
* @throws GraphQlInputException
*/
public function resolve(Field $field, $context, ResolveInfo $info, array $value = null, array $args = null)
public function resolve(Field $field, $context, ResolveInfo $info, ?array $value = null, ?array $args = null)
{
$buyerToken = $args['buyerToken'] ?? false;
$password = $args['password'] ?? false;
Expand Down
2 changes: 1 addition & 1 deletion Model/Resolver/UpdateCheckoutSession.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function __construct(
* @return array|false[]|int
* @throws GraphQlInputException
*/
public function resolve(Field $field, $context, ResolveInfo $info, array $value = null, array $args = null)
public function resolve(Field $field, $context, ResolveInfo $info, ?array $value = null, ?array $args = null)
{
$cartId = $args['cartId'] ?? false;
$checkoutSessionId = $args['amazonSessionId'] ?? false;
Expand Down
63 changes: 63 additions & 0 deletions Plugin/CloseAuthTransaction.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?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\Plugin;

use Amazon\Pay\Gateway\Config\Config;
use Magento\Sales\Api\OrderPaymentRepositoryInterface;
use Magento\Sales\Model\Order\Payment\Transaction;

class CloseAuthTransaction
{
/**
* @var OrderPaymentRepositoryInterface
*/
protected $orderPaymentRepository;

/**
* @param \Magento\Sales\Api\OrderPaymentRepositoryInterface $orderPaymentRepository
*/
public function __construct(OrderPaymentRepositoryInterface $orderPaymentRepository)
{
$this->orderPaymentRepository = $orderPaymentRepository;
}

/**
* Ensure transaction saves before attempting to close parent (self) infinitely.
*
* Added for change of parent transaction linkage in 2.4.8.
*
* @param Transaction $subject
* @param bool $shouldSave
* @return array
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*/
public function beforeClose(
Transaction $subject,
bool $shouldSave = true
) {
if ($paymentId = $subject->getPaymentId()) {
if ($payment = $this->orderPaymentRepository->get($paymentId)) {
$paymentMethod = $payment->getMethod() ?? '';
if ($paymentMethod == Config::CODE && $subject->getTxnType() == Transaction::TYPE_AUTH) {
$shouldSave = true;
$subject->isFailsafe(true);
}
}
}

return [$shouldSave];
}
}
5 changes: 3 additions & 2 deletions Plugin/PaymentTransactionIdUpdate.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
namespace Amazon\Pay\Plugin;

use Amazon\Pay\Gateway\Config\Config;
use Magento\Sales\Api\Data\OrderPaymentInterface;
use Magento\Sales\Model\Order\Payment\Transaction;
use Magento\Sales\Model\Order\Payment\Transaction\ManagerInterface;
Expand All @@ -37,8 +38,8 @@ public function beforeGenerateTransactionId(
$type,
$transactionBasedOn = false
) {
$paymentMethodTitle = $payment->getAdditionalInformation('method_title') ?? '';
if (strpos($paymentMethodTitle, 'Amazon Pay') !== false && $type == Transaction::TYPE_VOID) {
$paymentMethod = $payment->getMethod() ?? '';
if ($paymentMethod == Config::CODE && $type == Transaction::TYPE_VOID) {
$chargePermissionId = $payment->getAdditionalInformation('charge_permission_id');
if (empty($chargePermissionId)) {
$transactionId = explode('-', $payment->getAuthorizationTransaction()->getTxnId());
Expand Down
2 changes: 1 addition & 1 deletion Plugin/RecurringChargePermissionUpdate.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public function beforeSavePaymentInformationAndPlaceOrder(
PaymentInformationManagement $subject,
$cartId,
\Magento\Quote\Api\Data\PaymentInterface $paymentMethod,
\Magento\Quote\Api\Data\AddressInterface $billingAddress = null
?\Magento\Quote\Api\Data\AddressInterface $billingAddress = null
) {
if ($paymentMethod->getMethod() === 'amazon_payment_v2_vault') {
$quote = $this->cartRepository->getActive($cartId);
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ The following table provides an overview on which Git branch is compatible to wh
Magento Version | Github Branch | Latest release
---|---|---
2.2.6 - 2.2.11 (EOL) | [V2checkout-1.2.x](https://github.com/amzn/amazon-payments-magento-2-plugin/tree/V2checkout-1.2.x) | 1.20.0 (EOL)
2.3.0 - 2.4.x | [master](https://github.com/amzn/amazon-payments-magento-2-plugin/tree/master) | 5.18.2
2.3.0 - 2.4.x | [master](https://github.com/amzn/amazon-payments-magento-2-plugin/tree/master) | 5.18.3

## Release Notes
See [CHANGELOG.md](/CHANGELOG.md)
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "amzn/amazon-pay-magento-2-module",
"description": "Official Magento2 Plugin to integrate with Amazon Pay",
"type": "magento2-module",
"version": "5.18.2",
"version": "5.18.3",
"license": [
"Apache-2.0"
],
Expand All @@ -18,7 +18,7 @@
"guzzlehttp/guzzle": "^6.2.0"
},
"require": {
"php": "~7.0.13||~7.1.0||~7.2.0||~7.3.0||~7.4.0||~8.0.0||~8.1.0||~8.2.0||~8.3.0",
"php": "~7.1.0||~7.2.0||~7.3.0||~7.4.0||~8.0.0||~8.1.0||~8.2.0||~8.3.0||~8.4.0",
"magento/framework": "^102.0||^103.0",
"magento/module-sales": "^100.0||^101.0||^102.0||^103.0",
"magento/module-checkout": "^100.0",
Expand Down
2 changes: 1 addition & 1 deletion etc/adminhtml/system.xml
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@
<field id="promo_message_color" translate="label" type="select" sortOrder="130" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Promo Message Color</label>
<config_path>payment/amazon_payment_v2/promo_message_color</config_path>
<source_model>Amazon\Pay\Model\Config\Source\ButtonColor</source_model>
<source_model>Amazon\Pay\Model\Config\Source\PromoFontColor</source_model>
</field>
<field id="promo_message_font_size" translate="label" type="select" sortOrder="140" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Promo Message Font Size</label>
Expand Down
3 changes: 3 additions & 0 deletions etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,9 @@
<type name="Magento\Sales\Model\Order\Payment\Transaction\Manager">
<plugin name="amazon_pay_update_transaction_id" type="Amazon\Pay\Plugin\PaymentTransactionIdUpdate" sortOrder="1" />
</type>
<type name="Magento\Sales\Model\Order\Payment\Transaction">
<plugin name="amazon_pay_close_auth_prevent_recursion" type="Amazon\Pay\Plugin\CloseAuthTransaction" sortOrder="1" />
</type>
<type name="Magento\Config\Model\Config">
<plugin name="amazon_pay_config" type="Amazon\Pay\Plugin\ConfigCredentialsValidator" sortOrder="100" disabled="false"/>
</type>
Expand Down