Skip to content

Commit

Permalink
Merge pull request #5580 from magento-tsg-csl3/2.4-develop-pr22
Browse files Browse the repository at this point in the history
[TSG-CSL3] For 2.4 (pr22)
  • Loading branch information
viktym committed Apr 14, 2020
2 parents ee78423 + d3adb66 commit c4a7d77
Show file tree
Hide file tree
Showing 31 changed files with 567 additions and 385 deletions.
18 changes: 16 additions & 2 deletions app/code/Magento/Config/App/Config/Source/RuntimeConfigSource.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,12 @@
use Magento\Framework\App\Config\ConfigSourceInterface;
use Magento\Framework\App\Config\ScopeCodeResolver;
use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Framework\App\DeploymentConfig;
use Magento\Framework\App\ObjectManager;
use Magento\Framework\DataObject;
use Magento\Config\Model\ResourceModel\Config\Data\CollectionFactory;
use Magento\Framework\App\Config\Scope\Converter;
use Magento\Framework\DB\Adapter\TableNotFoundException;

/**
* Class for retrieving runtime configuration from database.
Expand All @@ -34,20 +37,27 @@ class RuntimeConfigSource implements ConfigSourceInterface
* @var ScopeCodeResolver
*/
private $scopeCodeResolver;
/**
* @var DeploymentConfig
*/
private $deploymentConfig;

/**
* @param CollectionFactory $collectionFactory
* @param ScopeCodeResolver $scopeCodeResolver
* @param Converter $converter
* @param DeploymentConfig|null $deploymentConfig
*/
public function __construct(
CollectionFactory $collectionFactory,
ScopeCodeResolver $scopeCodeResolver,
Converter $converter
Converter $converter,
?DeploymentConfig $deploymentConfig = null
) {
$this->collectionFactory = $collectionFactory;
$this->converter = $converter;
$this->scopeCodeResolver = $scopeCodeResolver;
$this->deploymentConfig = $deploymentConfig ?? ObjectManager::getInstance()->get(DeploymentConfig::class);
}

/**
Expand All @@ -59,7 +69,7 @@ public function __construct(
*/
public function get($path = '')
{
$data = new DataObject($this->loadConfig());
$data = new DataObject($this->deploymentConfig->isDbAvailable() ? $this->loadConfig() : []);
return $data->getData($path) ?: [];
}

Expand All @@ -75,8 +85,12 @@ private function loadConfig()
{
try {
$collection = $this->collectionFactory->create();
$collection->load();
} catch (\DomainException $e) {
$collection = [];
} catch (TableNotFoundException $exception) {
// database is empty or not setup
$collection = [];
}
$config = [];
foreach ($collection as $item) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,48 +5,57 @@
*/
namespace Magento\Config\Test\Unit\App\Config\Source;

use ArrayIterator;
use Magento\Config\App\Config\Source\RuntimeConfigSource;
use Magento\Config\Model\ResourceModel\Config\Data\Collection;
use Magento\Config\Model\ResourceModel\Config\Data\CollectionFactory;
use Magento\Framework\App\Config\Scope\Converter;
use Magento\Framework\App\Config\ScopeCodeResolver;
use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Framework\App\Config\Value;
use Magento\Framework\App\DeploymentConfig;
use Magento\Framework\DB\Adapter\TableNotFoundException;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;

/**
* Test Class for retrieving runtime configuration from database.
* @package Magento\Config\Test\Unit\App\Config\Source
*/
class RuntimeConfigSourceTest extends \PHPUnit\Framework\TestCase
class RuntimeConfigSourceTest extends TestCase
{
/**
* @var CollectionFactory|\PHPUnit_Framework_MockObject_MockObject
* @var CollectionFactory|MockObject
*/
private $collectionFactory;

/**
* @var ScopeCodeResolver|\PHPUnit_Framework_MockObject_MockObject
* @var ScopeCodeResolver|MockObject
*/
private $scopeCodeResolver;

/**
* @var Converter|\PHPUnit_Framework_MockObject_MockObject
* @var Converter|MockObject
*/
private $converter;

/**
* @var Value|\PHPUnit_Framework_MockObject_MockObject
* @var Value|MockObject
*/
private $configItem;

/**
* @var Value|\PHPUnit_Framework_MockObject_MockObject
* @var Value|MockObject
*/
private $configItemTwo;

/**
* @var RuntimeConfigSource
*/
private $configSource;
/**
* @var DeploymentConfig|MockObject
*/
private $deploymentConfig;

public function setUp()
{
Expand All @@ -68,20 +77,29 @@ public function setUp()
->disableOriginalConstructor()
->setMethods(['getScope', 'getPath', 'getValue', 'getScopeId'])
->getMock();
$this->deploymentConfig = $this->createPartialMock(DeploymentConfig::class, ['isDbAvailable']);
$this->configSource = new RuntimeConfigSource(
$this->collectionFactory,
$this->scopeCodeResolver,
$this->converter
$this->converter,
$this->deploymentConfig
);
}

public function testGet()
{
$this->deploymentConfig->method('isDbAvailable')
->willReturn(true);
$collection = $this->createPartialMock(Collection::class, ['load', 'getIterator']);
$collection->method('load')
->willReturn($collection);
$collection->method('getIterator')
->willReturn(new ArrayIterator([$this->configItem, $this->configItemTwo]));
$scope = 'websites';
$scopeCode = 'myWebsites';
$this->collectionFactory->expects($this->once())
->method('create')
->willReturn([$this->configItem, $this->configItemTwo]);
->willReturn($collection);
$this->configItem->expects($this->exactly(2))
->method('getScope')
->willReturn(ScopeConfigInterface::SCOPE_TYPE_DEFAULT);
Expand Down Expand Up @@ -133,4 +151,22 @@ public function testGet()
$this->configSource->get()
);
}

public function testGetWhenDbIsNotAvailable()
{
$this->deploymentConfig->method('isDbAvailable')->willReturn(false);
$this->assertEquals([], $this->configSource->get());
}

public function testGetWhenDbIsEmpty()
{
$this->deploymentConfig->method('isDbAvailable')
->willReturn(true);
$collection = $this->createPartialMock(Collection::class, ['load']);
$collection->method('load')
->willThrowException($this->createMock(TableNotFoundException::class));
$this->collectionFactory->method('create')
->willReturn($collection);
$this->assertEquals([], $this->configSource->get());
}
}
38 changes: 36 additions & 2 deletions app/code/Magento/Paypal/Model/Payflow/Transparent.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class Transparent extends Payflowpro implements TransparentInterface
*
* @var bool
*/
protected $_canFetchTransactionInfo = false;
protected $_canFetchTransactionInfo = true;

/**
* @var ResponseValidator
Expand Down Expand Up @@ -355,11 +355,11 @@ public function capture(InfoInterface $payment, $amount)
*
* @param InfoInterface $payment
* @return bool
* @throws InvalidTransitionException
* @throws LocalizedException
*/
public function acceptPayment(InfoInterface $payment)
{
$this->validatePaymentTransaction($payment);
if ($this->getConfigPaymentAction() === MethodInterface::ACTION_AUTHORIZE_CAPTURE) {
$invoices = iterator_to_array($payment->getOrder()->getInvoiceCollection());
$invoice = count($invoices) ? reset($invoices) : null;
Expand Down Expand Up @@ -387,6 +387,20 @@ public function denyPayment(InfoInterface $payment)
return true;
}

/**
* @inheritDoc
*/
public function fetchTransactionInfo(InfoInterface $payment, $transactionId)
{
$result = parent::fetchTransactionInfo($payment, $transactionId);
$this->_canFetchTransactionInfo = false;
if ($payment->getIsTransactionApproved()) {
$this->acceptPayment($payment);
}

return $result;
}

/**
* Marks payment as fraudulent.
*
Expand Down Expand Up @@ -444,4 +458,24 @@ private function getZeroAmountAuthorizationId(InfoInterface $payment): string
{
return (string)$payment->getAdditionalInformation(self::PNREF);
}

/**
* Validates payment transaction status on PayPal.
*
* @param InfoInterface $payment
* @throws LocalizedException
*/
private function validatePaymentTransaction(InfoInterface $payment): void
{
if ($payment->canFetchTransactionInfo()) {
$transactionId = $payment->getLastTransId();
parent::fetchTransactionInfo($payment, $transactionId);
$this->_canFetchTransactionInfo = false;
if ($payment->getIsTransactionDenied()) {
throw new LocalizedException(
__('Payment can\'t be accepted since transaction was rejected by merchant.')
);
}
}
}
}
21 changes: 19 additions & 2 deletions app/code/Magento/Paypal/Model/SmartButtonConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
use Magento\Store\Model\ScopeInterface;

/**
* Smart button config
* Smart button configuration.
*/
class SmartButtonConfig
{
Expand Down Expand Up @@ -96,7 +96,14 @@ public function getConfig(string $page): array
private function getDisallowedFunding(): array
{
$disallowedFunding = $this->config->getValue('disable_funding_options');
return $disallowedFunding ? explode(',', $disallowedFunding) : [];
$result = $disallowedFunding ? explode(',', $disallowedFunding) : [];

// PayPal Guest Checkout Credit Card Icons only available when Guest Checkout option is enabled
if ($this->isPaypalGuestCheckoutAllowed() === false && !in_array('CARD', $result)) {
array_push($result, 'CARD');
}

return $result;
}

/**
Expand Down Expand Up @@ -168,4 +175,14 @@ private function updateStyles(array $styles, string $page): array

return $styles;
}

/**
* Returns if is allowed PayPal Guest Checkout.
*
* @return bool
*/
private function isPaypalGuestCheckoutAllowed(): bool
{
return $this->config->getValue('solution_type') === Config::EC_SOLUTION_TYPE_SOLE;
}
}
Loading

0 comments on commit c4a7d77

Please sign in to comment.