Skip to content

Commit

Permalink
fix issues with sort-order of status-changes
Browse files Browse the repository at this point in the history
  • Loading branch information
rommelfreddy committed Mar 27, 2024
1 parent 631a300 commit 683e582
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 11 deletions.
15 changes: 6 additions & 9 deletions src/Components/RatepayApi/Subscriber/AutoDeliverySubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,9 @@

use Exception;
use Psr\Log\LoggerInterface;
use Ratepay\RpayPayments\Components\PaymentHandler\Event\PaymentSuccessfulEvent;
use Ratepay\RpayPayments\Components\RatepayApi\Dto\OrderOperationData;
use Ratepay\RpayPayments\Components\RatepayApi\Dto\PaymentRequestData;
use Ratepay\RpayPayments\Components\RatepayApi\Event\ResponseEvent;
use Ratepay\RpayPayments\Components\RatepayApi\Service\Request\PaymentDeliverService;
use Ratepay\RpayPayments\Components\RatepayApi\Service\Request\PaymentRequestService;
use Ratepay\RpayPayments\Core\PluginConfigService;
use Ratepay\RpayPayments\Util\CriteriaHelper;
use Shopware\Core\Checkout\Order\OrderEntity;
Expand All @@ -38,19 +36,18 @@ public function __construct(
public static function getSubscribedEvents(): array
{
return [
PaymentRequestService::EVENT_SUCCESSFUL => ['onSuccess', 5],
PaymentSuccessfulEvent::class => 'onSuccess',
];
}

public function onSuccess(ResponseEvent $requestEvent): void
public function onSuccess(PaymentSuccessfulEvent $event): void
{
if ($this->configService->isAutoDeliveryOfVirtualProductsDisabled()) {
return;
}

/** @var PaymentRequestData $requestData */
$requestData = $requestEvent->getRequestData();
$order = $this->orderRepository->search(CriteriaHelper::getCriteriaForOrder($requestData->getOrder()->getId()), $requestData->getContext())->first();
// we will reload the order completely to have all extension-data
$order = $this->orderRepository->search(CriteriaHelper::getCriteriaForOrder($event->getOrder()->getId()), $event->getContext())->first();

if (!$order instanceof OrderEntity) {
return; // should never occur - just to be safe.
Expand All @@ -68,7 +65,7 @@ public function onSuccess(ResponseEvent $requestEvent): void
if ($lineItemsToDeliver !== []) {
try {
$this->deliverService->doRequest(new OrderOperationData(
$requestEvent->getContext(),
$event->getContext(),
$order,
OrderOperationData::OPERATION_DELIVER,
$lineItemsToDeliver,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function __construct(
public static function getSubscribedEvents(): array
{
return [
PaymentRequestService::EVENT_SUCCESSFUL => ['onSuccess', 1000],
PaymentRequestService::EVENT_SUCCESSFUL => 'onSuccess',
PaymentRequestService::EVENT_FAILED => 'onFailure',
];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function __construct(
public static function getSubscribedEvents(): array
{
return [
PaymentSuccessfulEvent::class => 'changeTransactionState',
PaymentSuccessfulEvent::class => ['changeTransactionState', 6000],
];
}

Expand Down

0 comments on commit 683e582

Please sign in to comment.