Skip to content

Commit

Permalink
If the payment is already captured before this webhook the order woul…
Browse files Browse the repository at this point in the history
…dn't transition to the fulfilled state automatically. Therefore, we see if we can take that transition
  • Loading branch information
loevgaard committed Sep 2, 2024
1 parent be15214 commit 0bc44f4
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/WebhookHandler/OrderPackedWebhookHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use Sylius\Component\Core\Model\OrderItemInterface;
use Sylius\Component\Core\OrderShippingTransitions;
use Sylius\Component\Core\Repository\OrderRepositoryInterface;
use Sylius\Component\Order\OrderTransitions;
use Sylius\Component\Payment\PaymentTransitions;
use Webmozart\Assert\Assert;

Expand Down Expand Up @@ -67,7 +68,7 @@ public function handle(object $data): void
$orderShippingStateMachine = $this->stateMachineFactory->get($order, OrderShippingTransitions::GRAPH);

if ($orderShippingStateMachine->can(OrderShippingTransitions::TRANSITION_SHIP)) {
$this->logger->debug(sprintf('Taking the "%s" transition', OrderShippingTransitions::TRANSITION_SHIP));
$this->logger->debug(sprintf('Shipment: Taking the "%s" transition', OrderShippingTransitions::TRANSITION_SHIP));

$orderShippingStateMachine->apply(OrderShippingTransitions::TRANSITION_SHIP);
}
Expand All @@ -76,6 +77,13 @@ public function handle(object $data): void
$this->completePayment($order);
}

$orderStateMachine = $this->stateMachineFactory->get($order, OrderTransitions::GRAPH);
if ($orderStateMachine->can(OrderTransitions::TRANSITION_FULFILL)) {
$this->logger->debug(sprintf('Order: Taking the "%s" transition', OrderTransitions::TRANSITION_FULFILL));

$orderStateMachine->apply(OrderTransitions::TRANSITION_FULFILL);
}

$this->logger->debug(sprintf('Order state after: %s', $order->getState()));
$this->logger->debug(sprintf('Order checkout state after: %s', (string) $order->getCheckoutState()));
$this->logger->debug(sprintf('Order shipping state state after: %s', (string) $order->getShippingState()));
Expand Down Expand Up @@ -132,7 +140,7 @@ private function completePayment(OrderInterface $order): void
$paymentStateMachine = $this->stateMachineFactory->get($payment, PaymentTransitions::GRAPH);

if ($paymentStateMachine->can(PaymentTransitions::TRANSITION_COMPLETE)) {
$this->logger->debug(sprintf('Taking the "%s" transition', PaymentTransitions::TRANSITION_COMPLETE));
$this->logger->debug(sprintf('Payment: Taking the "%s" transition', PaymentTransitions::TRANSITION_COMPLETE));

$paymentStateMachine->apply(PaymentTransitions::TRANSITION_COMPLETE);
}
Expand Down

0 comments on commit 0bc44f4

Please sign in to comment.