diff --git a/spec/ProcessManager/RefundPaymentProcessManagerSpec.php b/spec/ProcessManager/RefundPaymentProcessManagerSpec.php index bc8edd6d6..d06ac3dfa 100644 --- a/spec/ProcessManager/RefundPaymentProcessManagerSpec.php +++ b/spec/ProcessManager/RefundPaymentProcessManagerSpec.php @@ -13,18 +13,21 @@ use Sylius\RefundPlugin\Event\UnitsRefunded; use Sylius\RefundPlugin\Factory\RefundPaymentFactoryInterface; use Sylius\RefundPlugin\Model\OrderItemUnitRefund; +use Sylius\RefundPlugin\Provider\RelatedPaymentIdProviderInterface; use Sylius\RefundPlugin\StateResolver\OrderFullyRefundedStateResolverInterface; final class RefundPaymentProcessManagerSpec extends ObjectBehavior { function let( OrderFullyRefundedStateResolverInterface $orderFullyRefundedStateResolver, + RelatedPaymentIdProviderInterface $relatedPaymentIdProvider, RefundPaymentFactoryInterface $refundPaymentFactory, EntityManagerInterface $entityManager, EventBus $eventBus ): void { $this->beConstructedWith( $orderFullyRefundedStateResolver, + $relatedPaymentIdProvider, $refundPaymentFactory, $entityManager, $eventBus @@ -33,6 +36,7 @@ function let( function it_reacts_on_units_refunded_event_and_creates_refund_payment( OrderFullyRefundedStateResolverInterface $orderFullyRefundedStateResolver, + RelatedPaymentIdProviderInterface $relatedPaymentIdProvider, RefundPaymentFactoryInterface $refundPaymentFactory, EntityManagerInterface $entityManager, RefundPaymentInterface $refundPayment, @@ -55,13 +59,16 @@ function it_reacts_on_units_refunded_event_and_creates_refund_payment( $refundPayment->getOrderNumber()->willReturn('000222'); $refundPayment->getAmount()->willReturn(1000); + $relatedPaymentIdProvider->getForRefundPayment($refundPayment)->willReturn(3); + $eventBus->dispatch(Argument::that(function (RefundPaymentGenerated $event): bool { return $event->id() === 10 && $event->orderNumber() === '000222' && $event->amount() === 1000 && $event->currencyCode() === 'USD' && - $event->paymentMethodId() === 1 + $event->paymentMethodId() === 1 && + $event->paymentId() === 3 ; }))->shouldBeCalled(); diff --git a/src/ProcessManager/RefundPaymentProcessManager.php b/src/ProcessManager/RefundPaymentProcessManager.php index a5824ec89..7ffab579f 100644 --- a/src/ProcessManager/RefundPaymentProcessManager.php +++ b/src/ProcessManager/RefundPaymentProcessManager.php @@ -10,6 +10,7 @@ use Sylius\RefundPlugin\Event\RefundPaymentGenerated; use Sylius\RefundPlugin\Event\UnitsRefunded; use Sylius\RefundPlugin\Factory\RefundPaymentFactoryInterface; +use Sylius\RefundPlugin\Provider\RelatedPaymentIdProviderInterface; use Sylius\RefundPlugin\StateResolver\OrderFullyRefundedStateResolverInterface; final class RefundPaymentProcessManager @@ -17,6 +18,9 @@ final class RefundPaymentProcessManager /** @var OrderFullyRefundedStateResolverInterface */ private $orderFullyRefundedStateResolver; + /** @var RelatedPaymentIdProviderInterface */ + private $relatedPaymentIdProvider; + /** @var RefundPaymentFactoryInterface */ private $refundPaymentFactory; @@ -28,11 +32,13 @@ final class RefundPaymentProcessManager public function __construct( OrderFullyRefundedStateResolverInterface $orderFullyRefundedStateResolver, + RelatedPaymentIdProviderInterface $relatedPaymentIdProvider, RefundPaymentFactoryInterface $refundPaymentFactory, EntityManagerInterface $entityManager, EventBus $eventBus ) { $this->orderFullyRefundedStateResolver = $orderFullyRefundedStateResolver; + $this->relatedPaymentIdProvider = $relatedPaymentIdProvider; $this->refundPaymentFactory = $refundPaymentFactory; $this->entityManager = $entityManager; $this->eventBus = $eventBus; @@ -57,7 +63,7 @@ public function __invoke(UnitsRefunded $event): void $event->amount(), $event->currencyCode(), $event->paymentMethodId(), - 1 + $this->relatedPaymentIdProvider->getForRefundPayment($refundPayment) )); $this->orderFullyRefundedStateResolver->resolve($event->orderNumber());