-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'feature/automatic-profile-id' into release-week-07
- Loading branch information
Showing
8 changed files
with
232 additions
and
13 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,24 @@ | ||
<?php | ||
/* | ||
* Copyright Magmodules.eu. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Mollie\Payment\Block\Adminhtml\System\Config\Form; | ||
|
||
use Magento\Config\Block\System\Config\Form\Field; | ||
|
||
class DisabledInput extends Field | ||
{ | ||
/** | ||
* @param \Magento\Framework\Data\Form\Element\AbstractElement $element | ||
* @return string | ||
*/ | ||
protected function _getElementHtml(\Magento\Framework\Data\Form\Element\AbstractElement $element) | ||
{ | ||
$element->setReadonly(true, true); | ||
return parent::_getElementHtml($element); | ||
} | ||
} |
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,85 @@ | ||
<?php | ||
/* | ||
* Copyright Magmodules.eu. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Mollie\Payment\Model\Adminhtml\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 Mollie\Payment\Config; | ||
|
||
class ChangeApiMode extends Value | ||
{ | ||
/** | ||
* @var Config | ||
*/ | ||
private $mollieConfig; | ||
/** | ||
* @var FlushMollieCache | ||
*/ | ||
private $flushMollieCache; | ||
/** | ||
* @var UpdateProfileId | ||
*/ | ||
private $updateProfileId; | ||
|
||
public function __construct( | ||
Context $context, | ||
Registry $registry, | ||
ScopeConfigInterface $config, | ||
TypeListInterface $cacheTypeList, | ||
Config $mollieConfig, | ||
FlushMollieCache $flushMollieCache, | ||
UpdateProfileId $updateProfileId, | ||
AbstractResource $resource = null, | ||
AbstractDb $resourceCollection = null, | ||
array $data = [] | ||
) { | ||
parent::__construct( | ||
$context, | ||
$registry, | ||
$config, | ||
$cacheTypeList, | ||
$resource, | ||
$resourceCollection, | ||
$data | ||
); | ||
|
||
$this->mollieConfig = $mollieConfig; | ||
$this->flushMollieCache = $flushMollieCache; | ||
$this->updateProfileId = $updateProfileId; | ||
} | ||
|
||
public function beforeSave(): self | ||
{ | ||
$this->flushMollieCache->flush(); | ||
|
||
return parent::beforeSave(); | ||
} | ||
|
||
public function afterSave() | ||
{ | ||
$apiKey = $this->getApiKey($this->getValue()); | ||
$this->updateProfileId->execute($apiKey, $this->getScope(), $this->getScopeId()); | ||
|
||
return parent::afterSave(); | ||
} | ||
|
||
private function getApiKey(string $mode): string | ||
{ | ||
if ($mode === 'live') { | ||
return $this->mollieConfig->getLiveApiKey((int)$this->getScopeId()); | ||
} | ||
|
||
return $this->mollieConfig->getTestApiKey((int)$this->getScopeId()); | ||
} | ||
} |
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,19 @@ | ||
<?php | ||
/* | ||
* Copyright Magmodules.eu. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Mollie\Payment\Model\Adminhtml\Backend; | ||
|
||
use Magento\Framework\App\Config\Value; | ||
|
||
class DoNoUpdate extends Value | ||
{ | ||
public function save(): self | ||
{ | ||
return $this; | ||
} | ||
} |
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
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,47 @@ | ||
<?php | ||
/* | ||
* Copyright Magmodules.eu. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Mollie\Payment\Model\Adminhtml\Backend; | ||
|
||
use Magento\Framework\App\Config\Storage\WriterInterface; | ||
use Mollie\Payment\Config; | ||
use Mollie\Payment\Service\Mollie\MollieApiClient; | ||
|
||
class UpdateProfileId | ||
{ | ||
/** | ||
* @var MollieApiClient | ||
*/ | ||
private $mollieApiClient; | ||
/** | ||
* @var WriterInterface | ||
*/ | ||
private $configWriter; | ||
|
||
public function __construct( | ||
MollieApiClient $mollieApiClient, | ||
WriterInterface $configWriter | ||
) { | ||
$this->mollieApiClient = $mollieApiClient; | ||
$this->configWriter = $configWriter; | ||
} | ||
|
||
public function execute(string $apiKey, string $scope, int $scopeId): void | ||
{ | ||
$client = $this->mollieApiClient->loadByApiKey($apiKey); | ||
$profile = $client->profiles->get('me'); | ||
$profileId = $profile->id; | ||
|
||
$this->configWriter->save( | ||
Config::GENERAL_PROFILEID, | ||
$profileId, | ||
$scope, | ||
$scopeId | ||
); | ||
} | ||
} |
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