Skip to content

Commit

Permalink
Add check if order has been paid using SeQura payment methods in obse…
Browse files Browse the repository at this point in the history
…rvers

CS-5420
  • Loading branch information
MarijaIv committed May 14, 2024
1 parent eb19842 commit e7b8de3
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
6 changes: 6 additions & 0 deletions Observer/OrderAddressObserver.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Sequra\Core\Controller\Webhook\Index as WebhookController;
use SeQura\Core\Infrastructure\Logger\Logger;
use SeQura\Core\Infrastructure\ServiceRegister;
use Sequra\Core\Model\Ui\ConfigProvider;
use Sequra\Core\Services\BusinessLogic\Utility\SeQuraTranslationProvider;
use Sequra\Core\Services\BusinessLogic\Utility\TransformEntityService;

Expand Down Expand Up @@ -81,6 +82,11 @@ public function execute(Observer $observer): void
private function handleAddressUpdate(MagentoAddress $magentoAddress): void
{
$magentoOrder = $magentoAddress->getOrder();

if ($magentoOrder->getPayment()->getMethod() !== ConfigProvider::CODE) {
return;
}

if ($magentoOrder->getStatus() === Order::STATE_PAYMENT_REVIEW) {
throw new LocalizedException($this->translationProvider->translate('sequra.error.cannotUpdate'));
}
Expand Down
4 changes: 3 additions & 1 deletion Observer/OrderCancellationObserver.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use SeQura\Core\BusinessLogic\Domain\Order\Service\OrderService;
use SeQura\Core\Infrastructure\Logger\Logger;
use SeQura\Core\Infrastructure\ServiceRegister;
use Sequra\Core\Model\Ui\ConfigProvider;
use Sequra\Core\Services\BusinessLogic\Utility\SeQuraTranslationProvider;

/**
Expand Down Expand Up @@ -50,7 +51,8 @@ public function __construct(SeQuraTranslationProvider $translationProvider)
public function execute(Observer $observer): void
{
$orderData = $observer->getData('order');
if (WebhookController::isWebhookProcessing() || $orderData->getStatus() !== Order::STATE_CANCELED) {
if (WebhookController::isWebhookProcessing() || $orderData->getStatus() !== Order::STATE_CANCELED ||
$orderData->getPayment()->getMethod() !== ConfigProvider::CODE) {
return;
}

Expand Down
5 changes: 5 additions & 0 deletions Observer/OrderShipmentObserver.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use SeQura\Core\BusinessLogic\Domain\Order\Service\OrderService;
use SeQura\Core\Infrastructure\Logger\Logger;
use SeQura\Core\Infrastructure\ServiceRegister;
use Sequra\Core\Model\Ui\ConfigProvider;
use Sequra\Core\Services\BusinessLogic\Utility\SeQuraTranslationProvider;
use Sequra\Core\Services\BusinessLogic\Utility\TransformEntityService;

Expand Down Expand Up @@ -77,6 +78,10 @@ private function handleShipment(MagentoShipment $shipmentData): void
{
$orderData = $shipmentData->getOrder();

if ($orderData->getPayment()->getMethod() !== ConfigProvider::CODE) {
return;
}

if ($orderData->getStatus() === Order::STATE_PAYMENT_REVIEW) {
throw new LocalizedException($this->translationProvider->translate('sequra.error.cannotShip'));
}
Expand Down

0 comments on commit e7b8de3

Please sign in to comment.