Skip to content

Commit

Permalink
Use related payment id provider during refund payment generation
Browse files Browse the repository at this point in the history
  • Loading branch information
Zales0123 committed Oct 2, 2018
1 parent 856685b commit 6823c6a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
9 changes: 8 additions & 1 deletion spec/ProcessManager/RefundPaymentProcessManagerSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand All @@ -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();

Expand Down
8 changes: 7 additions & 1 deletion src/ProcessManager/RefundPaymentProcessManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,17 @@
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
{
/** @var OrderFullyRefundedStateResolverInterface */
private $orderFullyRefundedStateResolver;

/** @var RelatedPaymentIdProviderInterface */
private $relatedPaymentIdProvider;

/** @var RefundPaymentFactoryInterface */
private $refundPaymentFactory;

Expand All @@ -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;
Expand All @@ -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());
Expand Down

0 comments on commit 6823c6a

Please sign in to comment.