Skip to content
Open
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
4 changes: 4 additions & 0 deletions UPGRADE-2.1.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# UPGRADE FROM 2.1.0 TO 2.1.1

1. `OrderPartiallyRefundedStateResolver` now checks whether the `partially_refund` transition is applicable via the state machine instead of comparing the payment state directly, so the transition (and its side effects) is applied again for every subsequent partial refund on an already partially refunded order.

# UPGRADE FROM 2.0 TO 2.1

1. The minimum supported Symfony version has been raised to `6.4` and `7.4` — earlier 7.x releases (`7.1`, `7.2`, `7.3`) are no longer supported.
Expand Down
3 changes: 1 addition & 2 deletions src/StateResolver/OrderPartiallyRefundedStateResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
use Doctrine\ORM\EntityManagerInterface;
use Sylius\Abstraction\StateMachine\StateMachineInterface;
use Sylius\Component\Core\Model\OrderInterface;
use Sylius\Component\Core\OrderPaymentStates;
use Sylius\Component\Core\OrderPaymentTransitions;
use Sylius\Component\Core\Repository\OrderRepositoryInterface;
use Sylius\RefundPlugin\Exception\OrderNotFound;
Expand All @@ -39,7 +38,7 @@ public function resolve(string $orderNumber): void
throw OrderNotFound::withNumber($orderNumber);
}

if ($order->getPaymentState() === OrderPaymentStates::STATE_PARTIALLY_REFUNDED) {
if (!$this->stateMachineFactory->can($order, OrderPaymentTransitions::GRAPH, OrderPaymentTransitions::TRANSITION_PARTIALLY_REFUND)) {
return;
}

Expand Down
6 changes: 6 additions & 0 deletions tests/TestApplication/config/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,9 @@ imports:
twig:
paths:
'%kernel.project_dir%/../../../tests/TestApplication/templates': ~

knp_snappy:
pdf:
enabled: true
binary: '%env(resolve:WKHTMLTOPDF_PATH)%'
options: []
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
use PHPUnit\Framework\TestCase;
use Sylius\Abstraction\StateMachine\StateMachineInterface;
use Sylius\Component\Core\Model\OrderInterface;
use Sylius\Component\Core\OrderPaymentStates;
use Sylius\Component\Core\OrderPaymentTransitions;
use Sylius\Component\Core\Repository\OrderRepositoryInterface;
use Sylius\RefundPlugin\Exception\OrderNotFound;
Expand Down Expand Up @@ -62,10 +61,11 @@ public function it_marks_order_as_partially_refunded(): void
->with('000777')
->willReturn($order);

$order
$stateMachine
->expects(self::once())
->method('getPaymentState')
->willReturn(OrderPaymentStates::STATE_PAID);
->method('can')
->with($order, OrderPaymentTransitions::GRAPH, OrderPaymentTransitions::TRANSITION_PARTIALLY_REFUND)
->willReturn(true);

$stateMachine
->expects(self::once())
Expand All @@ -80,7 +80,7 @@ public function it_marks_order_as_partially_refunded(): void
}

#[Test]
public function it_does_nothing_if_order_is_already_marked_as_partially_refunded(): void
public function it_marks_order_as_partially_refunded_again_if_it_is_already_partially_refunded(): void
{
$orderRepository = $this->createMock(OrderRepositoryInterface::class);
$stateMachine = $this->createMock(StateMachineInterface::class);
Expand All @@ -95,15 +95,54 @@ public function it_does_nothing_if_order_is_already_marked_as_partially_refunded
->with('000777')
->willReturn($order);

$order
$stateMachine
->expects(self::once())
->method('getPaymentState')
->willReturn(OrderPaymentStates::STATE_PARTIALLY_REFUNDED);
->method('can')
->with($order, OrderPaymentTransitions::GRAPH, OrderPaymentTransitions::TRANSITION_PARTIALLY_REFUND)
->willReturn(true);

$stateMachine
->expects(self::once())
->method('apply')
->with($order, OrderPaymentTransitions::GRAPH, OrderPaymentTransitions::TRANSITION_PARTIALLY_REFUND);

$orderManager
->expects(self::once())
->method('flush');

$resolver->resolve('000777');
}

#[Test]
public function it_does_nothing_if_partially_refund_transition_is_not_applicable(): void
{
$orderRepository = $this->createMock(OrderRepositoryInterface::class);
$stateMachine = $this->createMock(StateMachineInterface::class);
$orderManager = $this->createMock(EntityManagerInterface::class);
$order = $this->createMock(OrderInterface::class);

$resolver = new OrderPartiallyRefundedStateResolver($orderRepository, $stateMachine, $orderManager);

$orderRepository
->expects(self::once())
->method('findOneByNumber')
->with('000777')
->willReturn($order);

$stateMachine
->expects(self::once())
->method('can')
->with($order, OrderPaymentTransitions::GRAPH, OrderPaymentTransitions::TRANSITION_PARTIALLY_REFUND)
->willReturn(false);

$stateMachine
->expects($this->never())
->method('apply');

$orderManager
->expects($this->never())
->method('flush');

$resolver->resolve('000777');
}

Expand Down Expand Up @@ -139,10 +178,11 @@ public function it_uses_winzou_state_machine_if_abstraction_not_passed_to_mark_o
->with('000777')
->willReturn($order);

$order
$this->stateMachineFactory
->expects(self::once())
->method('getPaymentState')
->willReturn(OrderPaymentStates::STATE_PAID);
->method('can')
->with($order, OrderPaymentTransitions::GRAPH, OrderPaymentTransitions::TRANSITION_PARTIALLY_REFUND)
->willReturn(true);

$this->stateMachineFactory
->expects(self::once())
Expand Down
Loading