Skip to content

Commit

Permalink
Merge pull request #1185 from BearGroup/release/5.15.0
Browse files Browse the repository at this point in the history
Release/5.15.0
  • Loading branch information
NisiPasa authored Apr 27, 2023
2 parents 0f62683 + 5506c02 commit de386a5
Show file tree
Hide file tree
Showing 35 changed files with 1,296 additions and 125 deletions.
59 changes: 59 additions & 0 deletions Api/KeyUpgradeInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?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://www.apache.org/licenses/LICENSE-2.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\Api;

/**
* @api
*/
interface KeyUpgradeInterface
{
/**
* Obtain a new Public Key ID for use with V2 of the Amazon Pay API
*
* @param string $scopeType
* @param integer $scopeCode
* @param string $accessKey
* @return mixed
*/
public function getPublicKeyId(
string $scopeType,
int $scopeCode,
string $accessKey
);

/**
* Get public/private keys for module configuration
*
* @return array
*/
public function getKeyPair();

/**
* Persist keys in configuration
*
* @param string $publicKeyId
* @param string $scopeType
* @param int $scopeId
* @return void
*/
public function updateKeysInConfig(
$publicKeyId,
$scopeType,
$scopeId
);
}
30 changes: 27 additions & 3 deletions Block/Adminhtml/System/Config/AutoKeyExchangeAdmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,25 @@ class AutoKeyExchangeAdmin extends \Magento\Framework\View\Element\Template
private $autokeyexchange;

/**
* @param \Magento\Framework\View\Element\Template\Context $context
* @param \Amazon\Pay\Model\Config\AutoKeyExchange $autokeyexchange
* @param array $data
* @var KeyUpgrade
*/
private $keyUpgrade;

/**
* @param \Magento\Framework\View\Element\Template\Context $context
* @param \Amazon\Pay\Model\Config\AutoKeyExchange $autokeyexchange
* @param \Amazon\Pay\Model\Config\KeyUpgrade $keyUpgrade
* @param array $data
*/
public function __construct(
\Magento\Framework\View\Element\Template\Context $context,
\Amazon\Pay\Model\Config\AutoKeyExchange $autokeyexchange,
\Amazon\Pay\Model\Config\KeyUpgrade $keyUpgrade,
array $data = []
) {
parent::__construct($context, $data);
$this->autokeyexchange = $autokeyexchange;
$this->keyUpgrade = $keyUpgrade;
}

/**
Expand Down Expand Up @@ -64,4 +72,20 @@ public function getCurrency()
}
return $currency;
}

/**
* Whether to display Key Upgrade or AKE
*/
public function canUpgrade()
{
return $this->keyUpgrade->getMwsKeyForScope();
}

/**
* Return Key Upgrade info
*/
public function getKeyUpgradeConfig()
{
return json_encode($this->keyUpgrade->getJsonAmazonKeyUpgradeConfig());
}
}
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Change Log

## 5.15.0
* Added Key Upgrade feature (automatically upgrade CV1 keys to CV2 if updating from legacy module)
* Fixed backward compatibility with Zend availability
* Fixed render issue with multiple Amazon Sign In buttons on the same page

## 5.14.3
* Fixed PHP 7 compatibility

Expand Down
103 changes: 103 additions & 0 deletions Controller/Adminhtml/Pay/ManualKeyUpgrade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
<?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\Adminhtml\Pay;

use Magento\Backend\App\Action\Context;
use Magento\Backend\Controller\Adminhtml\System;
use Magento\Framework\App\Cache\Manager;
use Magento\Framework\App\Cache\Type\Config as CacheTypeConfig;
use Magento\Framework\App\Config\ConfigResource\ConfigInterface;
use Magento\Framework\Controller\Result\JsonFactory;
use Amazon\Pay\Model\Config\KeyUpgrade;

/**
* Manually hits the Key Upgrade endpoint to retrieve a CV2 Public Key ID
*/
class ManualKeyUpgrade extends System
{
/**
* @var ConfigInterface
*/
private $config;

/**
* @var Manager
*/
private $cacheManager;

/**
* @var JsonFactory
*/
private $jsonResultFactory;

/**
* @var KeyUpgrade
*/
private $keyUpgrade;

/**
* @param Context $context
* @param ConfigInterface $config
* @param JsonFactory $jsonResultFactory
* @param Manager $cacheManager
* @param KeyUpgrade $keyUpgrade
*/
public function __construct(
Context $context,
ConfigInterface $config,
JsonFactory $jsonResultFactory,
Manager $cacheManager,
KeyUpgrade $keyUpgrade
) {
parent::__construct($context);
$this->config = $config;
$this->jsonResultFactory = $jsonResultFactory;
$this->cacheManager = $cacheManager;
$this->keyUpgrade = $keyUpgrade;
}

public function execute()
{
$scopeType = $this->_request->getParam('scope');
$scopeCode = (int) $this->_request->getParam('scopeCode');

$publicKeyId = $this->keyUpgrade->getPublicKeyId(
$scopeType,
$scopeCode,
$this->_request->getParam('accessKey')
);

$result = $this->jsonResultFactory->create();
if (!empty($publicKeyId)) {
$this->keyUpgrade->updateKeysInConfig(
$publicKeyId,
$scopeType,
$scopeCode
);

$this->cacheManager->clean([CacheTypeConfig::TYPE_IDENTIFIER]);
$result->setData(['result' => 'success']);
$this->messageManager->addSuccessMessage('Amazon Pay keys upgraded successfully.');
} else {
$result->setData(['result' => 'error']);
$this->messageManager->addErrorMessage('Amazon Pay keys could not be upgraded. '
. 'See the paywithamazon.log for more details');
}

return $result;
}
}
15 changes: 12 additions & 3 deletions Helper/Customer.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
namespace Amazon\Pay\Helper;

use Amazon\Pay\Api\Data\AmazonCustomerInterface;
use Magento\Framework\Validator\ValidatorChain;

class Customer
{
Expand Down Expand Up @@ -79,8 +78,18 @@ public function getAmazonCustomer($buyerInfo)

public function createCustomer(AmazonCustomerInterface $amazonCustomer)
{
if (! ValidatorChain::is($amazonCustomer->getEmail(), '\Magento\Framework\Validator\EmailAddress')) {
throw new ValidatorException(__('the email address for your Amazon account is invalid'));
// Zend classes removed in Magento 2.4.6
if (class_exists(\Magento\Framework\Validator\ValidatorChain::class, true)) {
if (! \Magento\Framework\Validator\ValidatorChain::is(
$amazonCustomer->getEmail(),
\Magento\Framework\Validator\EmailAddress::class
)) {
throw new ValidatorException(__('the email address for your Amazon account is invalid'));
}
} else {
if (! \Zend_Validate::is($amazonCustomer->getEmail(), 'EmailAddress')) {
throw new ValidatorException(__('the email address for your Amazon account is invalid'));
}
}

$customerData = $this->customerLinkManagement->create($amazonCustomer);
Expand Down
Loading

0 comments on commit de386a5

Please sign in to comment.