Skip to content
Open
Show file tree
Hide file tree
Changes from 2 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
1 change: 1 addition & 0 deletions config/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ sylius_mailer:
knp_snappy:
pdf:
enabled: true
binary: '%env(WKHTMLTOPDF_PATH)%'
Comment thread
rust-le marked this conversation as resolved.
Outdated

sylius_grid:
templates:
Expand Down
5 changes: 4 additions & 1 deletion src/EventProducer/OrderPaymentPaidProducer.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

use Sylius\Component\Core\Model\OrderInterface;
use Sylius\Component\Core\Model\PaymentInterface;
use Sylius\Component\Core\OrderPaymentStates;
use Sylius\InvoicingPlugin\Doctrine\ORM\InvoiceRepositoryInterface;
use Sylius\InvoicingPlugin\Event\OrderPaymentPaid;
use Symfony\Component\Clock\ClockInterface;
Expand Down Expand Up @@ -51,6 +52,8 @@ private function shouldEventBeDispatched(PaymentInterface $payment): bool
/** @var OrderInterface $order */
$order = $payment->getOrder();

return null !== $order && null !== $this->invoiceRepository->findOneByOrder($order);
return null !== $order &&
$order->getPaymentState() === OrderPaymentStates::STATE_PAID &&
null !== $this->invoiceRepository->findOneByOrder($order);
Comment thread
rust-le marked this conversation as resolved.
Outdated
}
}
25 changes: 25 additions & 0 deletions tests/Unit/EventProducer/OrderPaymentPaidProducerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use PHPUnit\Framework\TestCase;
use Sylius\Component\Core\Model\OrderInterface;
use Sylius\Component\Core\Model\PaymentInterface;
use Sylius\Component\Core\OrderPaymentStates;
use Sylius\InvoicingPlugin\Doctrine\ORM\InvoiceRepositoryInterface;
use Sylius\InvoicingPlugin\Entity\InvoiceInterface;
use Sylius\InvoicingPlugin\Event\OrderPaymentPaid;
Expand All @@ -42,6 +43,7 @@ public function it_dispatches_order_payment_paid_event_for_payment(): void

$payment->method('getOrder')->willReturn($order);
$order->method('getNumber')->willReturn('0000001');
$order->method('getPaymentState')->willReturn(OrderPaymentStates::STATE_PAID);
$clock->method('now')->willReturn($dateTime);
$invoiceRepository->method('findOneByOrder')->with($order)->willReturn($invoice);

Expand Down Expand Up @@ -83,6 +85,7 @@ public function it_does_not_dispatch_event_when_there_is_no_invoice_related_to_o

$payment->method('getOrder')->willReturn($order);
$order->method('getNumber')->willReturn('0000001');
$order->method('getPaymentState')->willReturn(OrderPaymentStates::STATE_PAID);
$invoiceRepository->method('findOneByOrder')->with($order)->willReturn(null);

$eventBus->expects($this->never())->method('dispatch');
Expand All @@ -91,4 +94,26 @@ public function it_does_not_dispatch_event_when_there_is_no_invoice_related_to_o
$producer = new OrderPaymentPaidProducer($eventBus, $clock, $invoiceRepository);
$producer($payment);
}

#[Test]
public function it_does_not_dispatch_event_when_order_is_only_partially_paid(): void
{
$eventBus = $this->createMock(MessageBusInterface::class);
$clock = $this->createMock(ClockInterface::class);
$invoiceRepository = $this->createMock(InvoiceRepositoryInterface::class);
$payment = $this->createMock(PaymentInterface::class);
$order = $this->createMock(OrderInterface::class);
$invoice = $this->createMock(InvoiceInterface::class);

$payment->method('getOrder')->willReturn($order);
$order->method('getNumber')->willReturn('0000001');
$order->method('getPaymentState')->willReturn(OrderPaymentStates::STATE_PARTIALLY_PAID);
$invoiceRepository->method('findOneByOrder')->with($order)->willReturn($invoice);

$eventBus->expects($this->never())->method('dispatch');
$clock->expects($this->never())->method('now');

$producer = new OrderPaymentPaidProducer($eventBus, $clock, $invoiceRepository);
$producer($payment);
}
}
Loading