Skip to content

Commit

Permalink
Merge pull request #61 from moneimagento/issue/60
Browse files Browse the repository at this point in the history
Issue/60
  • Loading branch information
jimmyn authored Jul 31, 2024
2 parents c7c3975 + 289133d commit e91942e
Show file tree
Hide file tree
Showing 9 changed files with 110 additions and 15 deletions.
47 changes: 47 additions & 0 deletions Model/Config/Backend/AccountId.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

/**
* @author Monei Team
* @copyright Copyright © Monei (https://monei.com)
*/

declare(strict_types=1);

namespace Monei\MoneiPayment\Model\Config\Backend;

use Magento\Framework\App\Cache\TypeListInterface;
use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Framework\App\Config\Value;
use Magento\Framework\Data\Collection\AbstractDb;
use Magento\Framework\Model\Context;
use Magento\Framework\Model\ResourceModel\AbstractResource;
use Magento\Framework\Registry;
use Monei\MoneiPayment\Registry\AccountId as RegistryAccountId;

class AccountId extends Value
{
private RegistryAccountId $registryAccountId;

public function __construct(
RegistryAccountId $registryAccountId,
Context $context,
Registry $registry,
ScopeConfigInterface $config,
TypeListInterface $cacheTypeList,
AbstractResource $resource = null,
AbstractDb $resourceCollection = null,
array $data = [])
{
parent::__construct($context, $registry, $config, $cacheTypeList, $resource, $resourceCollection, $data);
$this->registryAccountId = $registryAccountId;
}

public function beforeSave(): AccountId
{
if ($this->getValue()) {
$this->registryAccountId->set($this->getValue());
}

return parent::beforeSave();
}
}
2 changes: 1 addition & 1 deletion Model/Config/Backend/EnableBizum.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class EnableBizum extends Enable
*/
public function beforeSave(): EnableBizum
{
if (!$this->isPaymentAvailable() && $this->getValue()) {
if ($this->getValue() && !$this->isPaymentAvailable()) {
$this->setValue("0");
// phpcs:disable
$this->messageManager->addNoticeMessage(
Expand Down
2 changes: 1 addition & 1 deletion Model/Config/Backend/EnableCard.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class EnableCard extends Enable
*/
public function beforeSave(): EnableCard
{
if (!$this->isPaymentAvailable() && $this->getValue()) {
if ($this->getValue() && !$this->isPaymentAvailable()) {
$this->setValue("0");
// phpcs:disable
$this->messageManager->addNoticeMessage(
Expand Down
2 changes: 1 addition & 1 deletion Model/Config/Backend/EnableGoogleApplePay.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class EnableGoogleApplePay extends Enable
*/
public function beforeSave(): EnableGoogleApplePay
{
if (!$this->isPaymentAvailable() && $this->getValue()) {
if ($this->getValue() && !$this->isPaymentAvailable()) {
$this->setValue("0");
// phpcs:disable
$this->messageManager->addNoticeMessage(
Expand Down
2 changes: 1 addition & 1 deletion Model/Config/Backend/EnableMBWay.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class EnableMBWay extends Enable
*/
public function beforeSave(): EnableMBWay
{
if (!$this->isPaymentAvailable() && $this->getValue()) {
if ($this->getValue() && !$this->isPaymentAvailable()) {
$this->setValue("0");
// phpcs:disable
$this->messageManager->addNoticeMessage(
Expand Down
2 changes: 1 addition & 1 deletion Model/Config/Backend/EnableMultibanco.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class EnableMultibanco extends Enable
*/
public function beforeSave(): EnableMultibanco
{
if (!$this->isPaymentAvailable() && $this->getValue()) {
if ($this->getValue() && !$this->isPaymentAvailable()) {
$this->setValue("0");
// phpcs:disable
$this->messageManager->addNoticeMessage(
Expand Down
25 changes: 25 additions & 0 deletions Registry/AccountId.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

/**
* @author Monei Team
* @copyright Copyright © Monei (https://monei.com)
*/

declare(strict_types=1);

namespace Monei\MoneiPayment\Registry;

class AccountId
{
private ?string $accountId = null;

public function set(string $accountId): void
{
$this->accountId = $accountId;
}

public function get(): ?string
{
return $this->accountId;
}
}
32 changes: 31 additions & 1 deletion Service/GetPaymentMethods.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,14 @@

namespace Monei\MoneiPayment\Service;

use GuzzleHttp\ClientFactory;
use Magento\Framework\Serialize\SerializerInterface;
use Magento\Framework\UrlInterface;
use Magento\Store\Model\StoreManagerInterface;
use Monei\MoneiPayment\Api\Config\MoneiPaymentModuleConfigInterface;
use Monei\MoneiPayment\Api\Service\GetPaymentMethodsInterface;
use Monei\MoneiPayment\Model\Config\Source\ModuleVersion;
use Monei\MoneiPayment\Registry\AccountId as RegistryAccountId;

/**
* Monei get payment REST integration service class.
Expand All @@ -18,6 +25,29 @@ class GetPaymentMethods extends AbstractService implements GetPaymentMethodsInte
{
public const METHOD = 'payment-methods';

private RegistryAccountId $registryAccountId;

public function __construct(
RegistryAccountId $registryAccountId,
ClientFactory $clientFactory,
MoneiPaymentModuleConfigInterface $moduleConfig,
StoreManagerInterface $storeManager,
UrlInterface $urlBuilder,
SerializerInterface $serializer,
Logger $logger,
ModuleVersion $moduleVersion)
{
parent::__construct(
$clientFactory,
$moduleConfig,
$storeManager,
$urlBuilder,
$serializer,
$logger,
$moduleVersion
);
$this->registryAccountId = $registryAccountId;
}

/**
* @inheritDoc
Expand All @@ -27,7 +57,7 @@ public function execute(): array
$this->logger->debug(__METHOD__);

$storeId = (int) $this->storeManager->getStore()->getId();
$accountId = $this->moduleConfig->getAccountId($storeId);
$accountId = $this->registryAccountId->get() ?? $this->moduleConfig->getAccountId($storeId);

$client = $this->createClient();

Expand Down
11 changes: 2 additions & 9 deletions etc/adminhtml/system.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,15 @@
<field id="test_account_id" translate="label comment" sortOrder="35" type="text" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Test Account Id</label>
<validate>required-entry</validate>
<backend_model>Monei\MoneiPayment\Model\Config\Backend\AccountId</backend_model>
<depends>
<field id="mode">1</field>
</depends>
</field>
<field id="production_account_id" translate="label comment" sortOrder="35" type="text" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Production Account Id</label>
<validate>required-entry</validate>
<backend_model>Monei\MoneiPayment\Model\Config\Backend\AccountId</backend_model>
<depends>
<field id="mode">2</field>
</depends>
Expand All @@ -58,25 +60,16 @@
<label>Type of payment</label>
<comment>If client wants to work with pre-authorized payments or not.</comment>
<source_model>Monei\MoneiPayment\Model\Config\Source\TypeOfPayment</source_model>
<depends>
<field id="active">1</field>
</depends>
</field>
<field id="confirmed_status" translate="label comment" type="select" sortOrder="80" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Confirmed Status</label>
<source_model>Magento\Sales\Model\Config\Source\Order\Status\Processing</source_model>
<comment>Selectable with all the processing order statuses</comment>
<depends>
<field id="active">1</field>
</depends>
</field>
<field id="pre_authorized_status" translate="label comment" type="select" sortOrder="90" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Pre-authorized Status</label>
<source_model>Monei\MoneiPayment\Model\Config\Source\PendingStatus</source_model>
<comment>Selectable with all the pending order statuses</comment>
<depends>
<field id="active">1</field>
</depends>
</field>
<field id="heading3" translate="label" sortOrder="100" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Monei Redirect:</label>
Expand Down

0 comments on commit e91942e

Please sign in to comment.