Skip to content

Commit

Permalink
Merge branch 'release/v3.0.1' into 'master'
Browse files Browse the repository at this point in the history
release/v3.0.1 into master

See merge request agence-dnd/marketplace/magento-2/external/module-checkout-magento2-plugin!21
  • Loading branch information
Rémi V committed Mar 17, 2022
2 parents 0e5d5b5 + 1bcaffb commit c9518e8
Show file tree
Hide file tree
Showing 15 changed files with 148 additions and 71 deletions.
3 changes: 2 additions & 1 deletion Controller/Payment/Verify.php
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,8 @@ public function execute(): ResponseInterface
]);
}

if (isset($response->metadata['successUrl']) && !str_contains(
if (isset($response->metadata['successUrl']) &&
false === strpos(
$response->metadata['successUrl'],
'checkout_com/payment/verify'
)) {
Expand Down
2 changes: 1 addition & 1 deletion Gateway/Config/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ public function getMethodsConfig(): array
* @var string[] $method
*/
foreach($paymentMethodsConfig as $key => $method) {
if (str_contains($key, 'checkoutcom')
if (false !== strpos($key, 'checkoutcom')
&& isset($method['active'])
&& (int)$method['active'] === 1
) {
Expand Down
18 changes: 12 additions & 6 deletions Helper/Logger.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Framework\Message\ManagerInterface;
use Magento\Store\Model\ScopeInterface;
use Zend\Log\Writer\Stream;
use Psr\Log\LoggerInterface;

/**
* Class Logger
Expand All @@ -39,19 +39,28 @@ class Logger
* @var ScopeConfigInterface $scopeConfig
*/
private $scopeConfig;
/**
* $logger field
*
* @var LoggerInterface $logger
*/
private $logger;

/**
* Logger constructor
*
* @param ManagerInterface $messageManager
* @param ScopeConfigInterface $scopeConfig
* @param LoggerInterface $logger
*/
public function __construct(
ManagerInterface $messageManager,
ScopeConfigInterface $scopeConfig
ScopeConfigInterface $scopeConfig,
LoggerInterface $logger
) {
$this->messageManager = $messageManager;
$this->scopeConfig = $scopeConfig;
$this->logger = $logger;
}

/**
Expand All @@ -77,10 +86,7 @@ public function write($msg): void

// Handle the file logging
if ($debug && $fileLogging) {
$writer = new Stream(BP . '/var/log/checkoutcom_magento2.log');
$logger = new \Zend\Log\Logger();
$logger->addWriter($writer);
$logger->info($msg);
$this->logger->debug('Checkout Logging: ', $msg);
}
}

Expand Down
29 changes: 19 additions & 10 deletions Model/Methods/AbstractMethod.php
Original file line number Diff line number Diff line change
Expand Up @@ -227,9 +227,9 @@ abstract class AbstractMethod extends AbstractExtensibleModel implements MethodI
/**
* Core store config
*
* @var ScopeConfigInterface $_scopeConfig
* @var ScopeConfigInterface $scopeConfig
*/
protected $_scopeConfig;
protected $scopeConfig;
/**
* $logger field
*
Expand All @@ -256,8 +256,6 @@ abstract class AbstractMethod extends AbstractExtensibleModel implements MethodI
private $config;

/**
* AbstractMethod constructor
*
* @param Config $config
* @param Context $context
* @param Registry $registry
Expand All @@ -266,10 +264,11 @@ abstract class AbstractMethod extends AbstractExtensibleModel implements MethodI
* @param Data $paymentData
* @param ScopeConfigInterface $scopeConfig
* @param Logger $logger
* @param DirectoryHelper $directory
* @param DataObjectFactory $dataObjectFactory
* @param AbstractResource|null $resource
* @param AbstractDb|null $resourceCollection
* @param array $data
* @param DirectoryHelper|null $directory
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
*/
public function __construct(
Expand All @@ -281,11 +280,11 @@ public function __construct(
Data $paymentData,
ScopeConfigInterface $scopeConfig,
Logger $logger,
DirectoryHelper $directory,
DataObjectFactory $dataObjectFactory,
AbstractResource $resource = null,
AbstractDb $resourceCollection = null,
array $data = [],
DirectoryHelper $directory,
DataObjectFactory $dataObjectFactory
array $data = []
) {
parent::__construct(
$context,
Expand All @@ -298,7 +297,7 @@ public function __construct(
);
$this->config = $config;
$this->_paymentData = $paymentData;
$this->_scopeConfig = $scopeConfig;
$this->scopeConfig = $scopeConfig;
$this->logger = $logger;
$this->directory = $directory;
$this->data = $data;
Expand Down Expand Up @@ -583,7 +582,7 @@ public function getConfigData($field, $storeId = null)
}
$path = 'payment/' . $this->getCode() . '/' . $field;

return $this->_scopeConfig->getValue($path, ScopeInterface::SCOPE_STORE, $storeId);
return $this->scopeConfig->getValue($path, ScopeInterface::SCOPE_STORE, $storeId);
}

/**
Expand Down Expand Up @@ -1037,4 +1036,14 @@ protected function initializeData(array $data = []): void
$this->_formBlockType = $data['formBlockType'];
}
}

/**
* Description isModuleActive function
*
* @return bool
*/
public function isModuleActive(): bool
{
return (bool)$this->scopeConfig->getValue('settings/checkoutcom_configuration/active');
}
}
15 changes: 8 additions & 7 deletions Model/Methods/AlternativePaymentMethod.php
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,7 @@ class AlternativePaymentMethod extends AbstractMethod
* @param AbstractDb|null $resourceCollection
* @param array $data
* @param DirectoryHelper $directoryHelper
* @param DataObjectFactory $dataObjectFactory
*/
public function __construct(
Context $context,
Expand Down Expand Up @@ -343,11 +344,11 @@ public function __construct(
Display $display,
StoreManagerInterface $storeManager,
Curl $curl,
DirectoryHelper $directoryHelper,
DataObjectFactory $dataObjectFactory,
AbstractResource $resource = null,
AbstractDb $resourceCollection = null,
array $data = [],
DirectoryHelper $directoryHelper,
DataObjectFactory $dataObjectFactory
array $data = []
) {
parent::__construct(
$config,
Expand All @@ -358,11 +359,11 @@ public function __construct(
$paymentData,
$scopeConfig,
$logger,
$directoryHelper,
$dataObjectFactory,
$resource,
$resourceCollection,
$data,
$directoryHelper,
$dataObjectFactory
$data
);

$this->urlBuilder = $urlBuilder;
Expand Down Expand Up @@ -1026,7 +1027,7 @@ public function isAvailable(CartInterface $quote = null): bool
}
}
}
if (parent::isAvailable($quote) && null !== $quote) {
if ($this->isModuleActive() && parent::isAvailable($quote) && null !== $quote) {
return $this->config->getValue('active', $this->_code)
&& count($this->config->getApms()) > 0
&& !$this->backendAuthSession->isLoggedIn()
Expand Down
17 changes: 9 additions & 8 deletions Model/Methods/ApplePayMethod.php
Original file line number Diff line number Diff line change
Expand Up @@ -174,10 +174,11 @@ class ApplePayMethod extends AbstractMethod
* @param StoreManagerInterface $storeManager
* @param QuoteHandlerService $quoteHandler
* @param MagentoLoggerHelper $ckoLogger
* @param DirectoryHelper $directoryHelper
* @param DataObjectFactory $dataObjectFactory
* @param AbstractResource|null $resource
* @param AbstractDb|null $resourceCollection
* @param array $data
* @param DirectoryHelper $directoryHelper
*/
public function __construct(
Context $context,
Expand All @@ -194,11 +195,11 @@ public function __construct(
StoreManagerInterface $storeManager,
QuoteHandlerService $quoteHandler,
MagentoLoggerHelper $ckoLogger,
DirectoryHelper $directoryHelper,
DataObjectFactory $dataObjectFactory,
AbstractResource $resource = null,
AbstractDb $resourceCollection = null,
array $data = [],
DirectoryHelper $directoryHelper,
DataObjectFactory $dataObjectFactory
array $data = []
) {
parent::__construct(
$config,
Expand All @@ -209,11 +210,11 @@ public function __construct(
$paymentData,
$scopeConfig,
$logger,
$directoryHelper,
$dataObjectFactory,
$resource,
$resourceCollection,
$data,
$directoryHelper,
$dataObjectFactory
$data
);

$this->backendAuthSession = $backendAuthSession;
Expand Down Expand Up @@ -497,7 +498,7 @@ public function refund(InfoInterface $payment, $amount): AbstractMethod
*/
public function isAvailable(CartInterface $quote = null): bool
{
if (parent::isAvailable($quote) && null !== $quote) {
if ($this->isModuleActive() && parent::isAvailable($quote) && null !== $quote) {
return $this->config->getValue('active', $this->_code) && $this->config->getValue(
'enabled_on_checkout',
$this->_code
Expand Down
17 changes: 9 additions & 8 deletions Model/Methods/CardPaymentMethod.php
Original file line number Diff line number Diff line change
Expand Up @@ -190,10 +190,11 @@ class CardPaymentMethod extends AbstractMethod
* @param QuoteHandlerService $quoteHandler
* @param CardHandlerService $cardHandler
* @param LoggerHelper $ckoLogger
* @param DirectoryHelper $directoryHelper
* @param DataObjectFactory $dataObjectFactory
* @param AbstractResource|null $resource
* @param AbstractDb|null $resourceCollection
* @param array $data
* @param DirectoryHelper $directoryHelper
*/
public function __construct(
Context $context,
Expand All @@ -212,11 +213,11 @@ public function __construct(
QuoteHandlerService $quoteHandler,
CardHandlerService $cardHandler,
LoggerHelper $ckoLogger,
DirectoryHelper $directoryHelper,
DataObjectFactory $dataObjectFactory,
AbstractResource $resource = null,
AbstractDb $resourceCollection = null,
array $data = [],
DirectoryHelper $directoryHelper,
DataObjectFactory $dataObjectFactory
array $data = []
) {
parent::__construct(
$config,
Expand All @@ -227,11 +228,11 @@ public function __construct(
$paymentData,
$scopeConfig,
$logger,
$directoryHelper,
$dataObjectFactory,
$resource,
$resourceCollection,
$data,
$directoryHelper,
$dataObjectFactory
$data
);

$this->backendAuthSession = $backendAuthSession;
Expand Down Expand Up @@ -556,7 +557,7 @@ public function refund(InfoInterface $payment, $amount): AbstractMethod
*/
public function isAvailable(CartInterface $quote = null): bool
{
if (parent::isAvailable($quote) && null !== $quote) {
if ($this->isModuleActive() && parent::isAvailable($quote) && null !== $quote) {
return $this->config->getValue('active', $this->_code) && !$this->backendAuthSession->isLoggedIn();
}

Expand Down
17 changes: 9 additions & 8 deletions Model/Methods/GooglePayMethod.php
Original file line number Diff line number Diff line change
Expand Up @@ -174,10 +174,11 @@ class GooglePayMethod extends AbstractMethod
* @param QuoteHandlerService $quoteHandler
* @param LoggerHelper $ckoLogger
* @param Session $backendAuthSession
* @param DirectoryHelper $directoryHelper
* @param DataObjectFactory $dataObjectFactory
* @param AbstractResource|null $resource
* @param AbstractDb|null $resourceCollection
* @param array $data
* @param DirectoryHelper $directoryHelper
*/
public function __construct(
Context $context,
Expand All @@ -194,11 +195,11 @@ public function __construct(
QuoteHandlerService $quoteHandler,
LoggerHelper $ckoLogger,
Session $backendAuthSession,
DirectoryHelper $directoryHelper,
DataObjectFactory $dataObjectFactory,
AbstractResource $resource = null,
AbstractDb $resourceCollection = null,
array $data = [],
DirectoryHelper $directoryHelper,
DataObjectFactory $dataObjectFactory
array $data = []
) {
parent::__construct(
$config,
Expand All @@ -209,11 +210,11 @@ public function __construct(
$paymentData,
$scopeConfig,
$logger,
$directoryHelper,
$dataObjectFactory,
$resource,
$resourceCollection,
$data,
$directoryHelper,
$dataObjectFactory
$data
);

$this->config = $config;
Expand Down Expand Up @@ -487,7 +488,7 @@ public function refund(InfoInterface $payment, $amount): AbstractMethod
*/
public function isAvailable(CartInterface $quote = null): bool
{
if (parent::isAvailable($quote) && null !== $quote) {
if ($this->isModuleActive() && parent::isAvailable($quote) && null !== $quote) {
return $this->config->getValue('active', $this->_code) && !$this->backendAuthSession->isLoggedIn();
}

Expand Down
Loading

0 comments on commit c9518e8

Please sign in to comment.