Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove inexistent order canceled webhook #93

Merged
merged 6 commits into from
Nov 29, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions Controller/Webhooks/Index.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public function execute()

try {
$content = $this->getRequest()->getContent();

$headers = $this->getRequest()->getHeaders()->toArray();
$signature = hash_hmac('sha256', $content, $this->_monduConfig->getWebhookSecret());
if ($signature !== ($headers['X-Mondu-Signature'] ?? null)) {
Expand All @@ -94,7 +94,6 @@ public function execute()
case 'order/pending':
[$resBody, $resStatus] = $this->handlePending($params);
break;
case 'order/canceled':
case 'order/declined':
[$resBody, $resStatus] = $this->handleDeclinedOrCanceled($params);
break;
Expand Down Expand Up @@ -135,7 +134,8 @@ public function handlePending($params): array
if (empty($order->getData())) {
return [['message' => 'Order does not exist', 'error' => 0], 200];
}

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

return [['message' => 'ok', 'error' => 0], 200];
Expand Down Expand Up @@ -163,6 +163,8 @@ public function handleConfirmed($params): array
return [['message' => 'Order does not exist', 'error' => 0], 200];
}

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

return [['message' => 'ok', 'error' => 0], 200];
Expand Down
2 changes: 1 addition & 1 deletion Model/Ui/ConfigProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public function getApiUrl($path = null): string
return $baseUrl . ($path ? '/'.$path : '');
}

/**
/**
* Returns mondu.js url
*
* @return string
Expand Down
8 changes: 1 addition & 7 deletions Observer/Config/Save.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ class Save implements ObserverInterface
private $subscriptions = [
'order/confirmed',
'order/declined',
'order/pending',
'order/canceled'
'order/pending'
];

/**
Expand Down Expand Up @@ -94,11 +93,6 @@ public function execute(Observer $observer)
->setTopic('order/declined')
->process();

$this->requestFactory
->create(RequestFactory::WEBHOOKS_REQUEST_METHOD)
->setTopic('order/canceled')
->process();

$this->monduConfig->clearConfigurationCache();
} catch (\Exception $e) {
throw new LocalizedException(__($e->getMessage()));
Expand Down
17 changes: 16 additions & 1 deletion Observer/CreateOrder.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ public function _execute(Observer $observer)

$order->setData('mondu_reference_id', $orderUid);
$order->addStatusHistoryComment(__('Mondu: order id %1', $orderData['uuid']));

$order = $this->assignMagentoStatus($order, $orderData['state']);
$order->save();
$this->monduFileLogger->info('Saved the order in Magento ', ['orderNumber' => $order->getIncrementId()]);

Expand Down Expand Up @@ -184,4 +184,19 @@ protected function confirmAuthorizedOrder($orderData, $orderNumber)
}
return $orderData;
}

/**
* AssignMagentoStatus
*
* @param Order $order
* @param string $monduOrderState
* @return Order
*/
protected function assignMagentoStatus($order, $monduOrderState)
{
if ($monduOrderState === 'pending') {
$order->setStatus(Order::STATE_PAYMENT_REVIEW);
}
return $order;
}
}
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_gmbh/magento2-payment",
"description": "Mondu payment method for magento 2",
"type": "magento2-module",
"version": "2.2.1",
"version": "2.2.2",
"license": [
"MIT"
],
Expand Down
8 changes: 5 additions & 3 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,19 @@ services:
ports:
- 80:8080
environment:
- BITNAMI_DEBUG=true
- MAGENTO_HOST=localhost
- MAGENTO_MODE=developer
- MAGENTO_DATABASE_HOST=mariadb
- MAGENTO_DATABASE_PORT_NUMBER=3306
- MAGENTO_DATABASE_USER=bn_magento
- MAGENTO_DATABASE_NAME=bitnami_magento
- MAGENTO_ELASTICSEARCH_HOST=elasticsearch
- MAGENTO_ELASTICSEARCH_PORT_NUMBER=9200
- MAGENTO_USERNAME=mondu
- MAGENTO_PASSWORD=mondu
- MAGENTO_PASSWORD=mondu123
- [email protected]
- ALLOW_EMPTY_PASSWORD=yes
- ELASTICSEARCH_HOST=elasticsearch
- ELASTICSEARCH_PORT_NUMBER=9200
- PHP_MEMORY_LIMIT=5120M
volumes:
- magento_data:/bitnami/magento
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="2.2.1">
<module name="Mondu_Mondu" setup_version="2.2.2">
<sequence>
<module name="Magento_Sales"/>
<module name="Magento_Payment"/>
Expand Down