Skip to content

Commit

Permalink
option to select new order state in config, order status consistency …
Browse files Browse the repository at this point in the history
…fix (#42)

* option to select new order state in config, order status consistency fix

* composer json version bump
  • Loading branch information
tikohov20 authored Nov 9, 2022
1 parent 5de53af commit 4113d41
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 14 deletions.
2 changes: 0 additions & 2 deletions Controller/Webhooks/Index.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ public function handlePending($params): array
}

$this->_monduLogger->updateLogMonduData($monduId, $params['order_state']);
$order->setStatus(Order::STATE_PROCESSING)->save();

return [['message' => 'ok', 'error' => 0], 200];
}
Expand All @@ -121,7 +120,6 @@ public function handleConfirmed($params): array
throw new \Exception('Required params missing');
}
$this->_monduLogger->updateLogMonduData($monduId, $params['order_state'], $viban);
$order->setStatus(Order::STATE_PROCESSING)->save();

return [['message' => 'ok', 'error' => 0], 200];
}
Expand Down
41 changes: 40 additions & 1 deletion Model/Ui/ConfigProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
use Magento\Framework\UrlInterface;
use Mondu\Mondu\Gateway\Http\Client\ClientMock;
use Magento\Config\Model\ResourceModel\Config as ResourceConfig;
use Magento\Framework\App\Config\Storage\WriterInterface;
use Magento\Framework\App\Cache\TypeListInterface;

class ConfigProvider implements \Magento\Checkout\Model\ConfigProviderInterface
{
Expand All @@ -22,12 +24,31 @@ class ConfigProvider implements \Magento\Checkout\Model\ConfigProviderInterface
private $encryptor;
private $scopeConfig;

public function __construct(UrlInterface $urlBuilder, ScopeConfigInterface $scopeConfig, ResourceConfig $resourceConfig, EncryptorInterface $encryptor)
/**
* @var WriterInterface
*/
private $configWriter;

/**
* @var TypeListInterface
*/
private $cacheTypeList;

public function __construct(
UrlInterface $urlBuilder,
ScopeConfigInterface $scopeConfig,
ResourceConfig $resourceConfig,
EncryptorInterface $encryptor,
WriterInterface $writer,
TypeListInterface $cacheTypeList
)
{
$this->urlBuilder = $urlBuilder;
$this->scopeConfig = $scopeConfig;
$this->resourceConfig = $resourceConfig;
$this->encryptor = $encryptor;
$this->configWriter = $writer;
$this->cacheTypeList = $cacheTypeList;
}

public function getApiUrl($path = null): string
Expand Down Expand Up @@ -124,6 +145,19 @@ public function updateWebhookSecret($webhookSecret = ""): ConfigProvider
return $this;
}

public function getNewOrderStatus()
{
return $this->scopeConfig->getValue('payment/mondu/order_status');
}

public function updateNewOrderStatus()
{
$status = $this->getNewOrderStatus();

$this->configWriter->save('payment/mondusepa/order_status', $status);
$this->configWriter->save('payment/monduinstallment/order_status', $status);
}

public function getWebhookSecret()
{
$val = $this->scopeConfig->getValue('payment/mondu/' . $this->getMode().'_webhook_secret');
Expand All @@ -134,4 +168,9 @@ public function sendLines()
{
return (bool) $this->scopeConfig->getValue('payment/mondu/send_lines');
}

public function clearConfigurationCache()
{
$this->cacheTypeList->cleanType('config');
}
}
3 changes: 3 additions & 0 deletions Observer/Config/Save.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ public function execute(Observer $observer)
if ($this->_monduConfig->isActive()) {
if ($this->_monduConfig->getApiKey()) {
try {
$this->_monduConfig->updateNewOrderStatus();

$this->_requestFactory->create(RequestFactory::WEBHOOKS_KEYS_REQUEST_METHOD)
->process()
->checkSuccess()
Expand All @@ -57,6 +59,7 @@ public function execute(Observer $observer)
->setTopic('order/canceled')
->process();

$this->_monduConfig->clearConfigurationCache();
} catch (\Exception $e) {
throw new LocalizedException(__($e->getMessage()));
}
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "mondu/magento2-payment",
"description": "Mondu payment method for magento 2",
"type": "magento2-module",
"version": "1.1.5",
"version": "1.1.6",
"license": [
"MIT"
],
Expand Down
5 changes: 5 additions & 0 deletions etc/adminhtml/system.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
<config_path>payment/mondu/active</config_path>
</field>
<field id="order_status" translate="label" type="select" sortOrder="1" showInDefault="1" showInWebsite="1" canRestore="1">
<label>New Order Status</label>
<source_model>Magento\Sales\Model\Config\Source\Order\Status\NewStatus</source_model>
<config_path>payment/mondu/order_status</config_path>
</field>
<field id="title" translate="label" type="text" sortOrder="2" showInDefault="1" showInWebsite="1"
showInStore="1">
<label>Rechnungskauf Title</label>
Expand Down
9 changes: 0 additions & 9 deletions etc/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,12 @@
<!-- <model>CustomPaymentGatewayFacade</model> -->
<mondu_key backend_model="Magento\Config\Model\Config\Backend\Encrypted"/>
<order_status>pending</order_status>
<payment_action>authorize</payment_action>
<title>Rechnungskauf - jetzt kaufen, später bezahlen</title>
<description>Hinweise zur Verarbeitung Ihrer personenbezogenen Daten durch die Mondu GmbH finden Sie hier.</description>
<sandbox>1</sandbox>
<cron>0</cron>
<allowspecific>1</allowspecific>
<specificcountry>DE</specificcountry>
<can_authorize>1</can_authorize>
<can_capture>1</can_capture>
<can_void>1</can_void>
<can_use_checkout>1</can_use_checkout>
<is_gateway>1</is_gateway>
<debugReplaceKeys>MERCHANT_KEY</debugReplaceKeys>
<paymentInfoKeys>FRAUD_MSG_LIST</paymentInfoKeys>
<privateInfoKeys>FRAUD_MSG_LIST</privateInfoKeys>
<sort_order>1</sort_order>
<send_lines>1</send_lines>
</mondu>
Expand Down
2 changes: 1 addition & 1 deletion etc/module.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Mondu_Mondu" setup_version="1.1.0">
<module name="Mondu_Mondu" setup_version="1.1.6">
<sequence>
<module name="Magento_Sales"/>
<module name="Magento_Payment"/>
Expand Down

0 comments on commit 4113d41

Please sign in to comment.