-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #49 from moneimagento/issue/44
Issue/44
- Loading branch information
Showing
21 changed files
with
597 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
/** | ||
* @author Monei Team | ||
* @copyright Copyright © Monei (https://monei.com) | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Monei\MoneiPayment\Api\Service; | ||
|
||
/** | ||
* Monei get payment REST integration service interface. | ||
*/ | ||
interface GetPaymentMethodsInterface | ||
{ | ||
/** | ||
* Service execute method | ||
* | ||
* @return array | ||
*/ | ||
public function execute(): array; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
<?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\Message\ManagerInterface; | ||
use Magento\Framework\Model\Context; | ||
use Magento\Framework\Model\ResourceModel\AbstractResource; | ||
use Magento\Framework\Registry; | ||
use Monei\MoneiPayment\Api\Service\GetPaymentMethodsInterface; | ||
use Monei\MoneiPayment\Model\Payment\Monei; | ||
use Monei\MoneiPayment\Service\Shared\GetAvailableMoneiPaymentMethods; | ||
use Monei\MoneiPayment\Service\Shared\GetMoneiPaymentCodesByMagentoPaymentCode; | ||
|
||
/** | ||
* Get Monei payment method configuration class. | ||
*/ | ||
class Enable extends Value | ||
{ | ||
private GetMoneiPaymentCodesByMagentoPaymentCode $getMoneiPaymentCodesByMagentoPaymentCode; | ||
protected ManagerInterface $messageManager; | ||
private GetAvailableMoneiPaymentMethods $getAvailableMoneiPaymentMethods; | ||
|
||
/** | ||
* Enable constructor. | ||
* | ||
* @param GetPaymentMethodsInterface $getPaymentMethodsService | ||
* @param GetMoneiPaymentCodesByMagentoPaymentCode $getMoneiPaymentCodesByMagentoPaymentCode | ||
* @param Context $context | ||
* @param Registry $registry | ||
* @param ScopeConfigInterface $config | ||
* @param TypeListInterface $cacheTypeList | ||
* @param ManagerInterface $messageManager | ||
* @param AbstractResource|null $resource | ||
* @param AbstractDb|null $resourceCollection | ||
* @param array $data | ||
*/ | ||
public function __construct( | ||
GetAvailableMoneiPaymentMethods $getAvailableMoneiPaymentMethods, | ||
GetMoneiPaymentCodesByMagentoPaymentCode $getMoneiPaymentCodesByMagentoPaymentCode, | ||
Context $context, | ||
Registry $registry, | ||
ScopeConfigInterface $config, | ||
TypeListInterface $cacheTypeList, | ||
ManagerInterface $messageManager, | ||
AbstractResource $resource = null, | ||
AbstractDb $resourceCollection = null, | ||
array $data = []) | ||
{ | ||
parent::__construct($context, $registry, $config, $cacheTypeList, $resource, $resourceCollection, $data); | ||
$this->getAvailableMoneiPaymentMethods = $getAvailableMoneiPaymentMethods; | ||
$this->getMoneiPaymentCodesByMagentoPaymentCode = $getMoneiPaymentCodesByMagentoPaymentCode; | ||
$this->messageManager = $messageManager; | ||
} | ||
|
||
protected function getAvailablePaymentMethods(): array | ||
{ | ||
return $this->getAvailableMoneiPaymentMethods->execute(); | ||
} | ||
|
||
protected function getMoneiPaymentCodesByMagentoPaymentCode(string $magentoPaymentCode): array | ||
{ | ||
return $this->getMoneiPaymentCodesByMagentoPaymentCode->execute($magentoPaymentCode); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?php | ||
|
||
/** | ||
* @author Monei Team | ||
* @copyright Copyright © Monei (https://monei.com) | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Monei\MoneiPayment\Model\Config\Backend; | ||
|
||
use Monei\MoneiPayment\Model\Payment\Monei; | ||
|
||
class EnableBizum extends Enable | ||
{ | ||
protected const PAYMENT_METHOD_CODE = Monei::BIZUM_CODE; | ||
|
||
/** | ||
* @return EnableBizum | ||
*/ | ||
public function beforeSave(): EnableBizum | ||
{ | ||
if (!$this->isPaymentAvailable() && $this->getValue()) { | ||
$this->setValue("0"); | ||
// phpcs:disable | ||
$this->messageManager->addNoticeMessage( | ||
__("Bizum payment method is not available in your Monei account. Please enable it in your Monei account to use it.")); | ||
// phpcs:enable | ||
} | ||
|
||
return parent::beforeSave(); | ||
} | ||
|
||
/** | ||
* @return bool | ||
*/ | ||
private function isPaymentAvailable(): bool | ||
{ | ||
$availablePaymentMethods = $this->getAvailablePaymentMethods(); | ||
$moneiPaymentCodes = $this->getMoneiPaymentCodesByMagentoPaymentCode(self::PAYMENT_METHOD_CODE); | ||
|
||
foreach ($moneiPaymentCodes as $moneiPaymentCode) { | ||
if (in_array($moneiPaymentCode, $availablePaymentMethods, true)) { | ||
return true; | ||
} | ||
} | ||
|
||
return false; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?php | ||
|
||
/** | ||
* @author Monei Team | ||
* @copyright Copyright © Monei (https://monei.com) | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Monei\MoneiPayment\Model\Config\Backend; | ||
|
||
use Monei\MoneiPayment\Model\Payment\Monei; | ||
|
||
class EnableCard extends Enable | ||
{ | ||
protected const PAYMENT_METHOD_CODE = Monei::CARD_CODE; | ||
|
||
/** | ||
* @return EnableBizum | ||
*/ | ||
public function beforeSave(): EnableCard | ||
{ | ||
if (!$this->isPaymentAvailable() && $this->getValue()) { | ||
$this->setValue("0"); | ||
// phpcs:disable | ||
$this->messageManager->addNoticeMessage( | ||
__("Card payment method is not available in your Monei account. Please enable it in your Monei account to use it.")); | ||
// phpcs:enable | ||
} | ||
|
||
return parent::beforeSave(); | ||
} | ||
|
||
/** | ||
* @return bool | ||
*/ | ||
private function isPaymentAvailable(): bool | ||
{ | ||
$availablePaymentMethods = $this->getAvailablePaymentMethods(); | ||
$moneiPaymentCodes = $this->getMoneiPaymentCodesByMagentoPaymentCode(self::PAYMENT_METHOD_CODE); | ||
|
||
foreach ($moneiPaymentCodes as $moneiPaymentCode) { | ||
if (in_array($moneiPaymentCode, $availablePaymentMethods, true)) { | ||
return true; | ||
} | ||
} | ||
|
||
return false; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?php | ||
|
||
/** | ||
* @author Monei Team | ||
* @copyright Copyright © Monei (https://monei.com) | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Monei\MoneiPayment\Model\Config\Backend; | ||
|
||
use Monei\MoneiPayment\Model\Payment\Monei; | ||
|
||
class EnableGoogleApplePay extends Enable | ||
{ | ||
protected const PAYMENT_METHOD_CODE = Monei::GOOGLE_APPLE_CODE; | ||
|
||
/** | ||
* @return EnableBizum | ||
*/ | ||
public function beforeSave(): EnableGoogleApplePay | ||
{ | ||
if (!$this->isPaymentAvailable() && $this->getValue()) { | ||
$this->setValue("0"); | ||
// phpcs:disable | ||
$this->messageManager->addNoticeMessage( | ||
__("Google Pay and Apple Pay payment methods are not available in your Monei account. Enable at least one of them in your Monei account to use it.")); | ||
// phpcs:enable | ||
} | ||
|
||
return parent::beforeSave(); | ||
} | ||
|
||
/** | ||
* @return bool | ||
*/ | ||
private function isPaymentAvailable(): bool | ||
{ | ||
$availablePaymentMethods = $this->getAvailablePaymentMethods(); | ||
$moneiPaymentCodes = $this->getMoneiPaymentCodesByMagentoPaymentCode(self::PAYMENT_METHOD_CODE); | ||
|
||
foreach ($moneiPaymentCodes as $moneiPaymentCode) { | ||
if (in_array($moneiPaymentCode, $availablePaymentMethods, true)) { | ||
return true; | ||
} | ||
} | ||
|
||
return false; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.