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

Add check if order has been paid using SeQura payment methods in observers #19

Merged
merged 1 commit into from
May 16, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
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
Loading