diff --git a/UPGRADE.md b/UPGRADE.md
index ce35094c..d1d11270 100644
--- a/UPGRADE.md
+++ b/UPGRADE.md
@@ -80,6 +80,59 @@
1. `sylius_refund_plugin.block_event_listener.account.order_show` and `sylius_refund_plugin.block_event_listener.order_show.credit_memos`
listeners have been replaced by `sylius_ui` configuration
+1. `Sylius\RefundPlugin\Factory\RefundPaymentFactoryInterface` and `Sylius\RefundPlugin\Factory\RefundPaymentFactory`
+ service definitions have been removed and replaced by default resource factory `sylius_refund.factory.refund_payment`
+
+1. The constructor of `Sylius\RefundPlugin\Factory\RefundPaymentFactory` has been changed:
+
+ ```diff
+ - public function __construct(PaymentMethodRepositoryInterface $paymentMethodRepository)
+ + public function __construct(string $className)
+ {
+ - $this->paymentMethodRepository = $paymentMethodRepository;
+ + $this->className = $className;
+ }
+ ```
+
+1. The `createWithData` method of `Sylius\RefundPlugin\Factory\RefundPaymentFactoryInterface` has been changed:
+
+ ```diff
+ public function createWithData(
+ OrderInterface $order,
+ int $amount,
+ string $currencyCode,
+ string $state,
+ - int $paymentMethodId
+ + PaymentMethodInterface $paymentMethod
+ ): RefundPaymentInterface;
+ ```
+
+1. The definition of `Sylius\RefundPlugin\ProcessManager\RefundPaymentProcessManager` has been changed:
+
+ ```diff
+
+
+
+ -
+ +
+
+ +
+
+
+
+
+
+1. The constructor of `Sylius\RefundPlugin\Creator\RefundUnitsCommandCreator` has been changed:
+
+ ```diff
+ - public function __construct(UnitRefundTotalCalculatorInterface $unitRefundTotalCalculator)
+ + public function __construct(RefundUnitsConverterInterface $refundUnitsConverter)
+ {
+ - $this->unitRefundTotalCalculator = $unitRefundTotalCalculator;
+ + $this->refundUnitsConverter = $refundUnitsConverter;
+ }
+ ```
+
### UPGRADE FROM 1.0.0-RC.9 TO 1.0.0-RC.10
1. Support for Sylius 1.8 has been dropped, upgrade your application to [Sylius 1.9](https://github.com/Sylius/Sylius/blob/master/UPGRADE-1.9.md)
diff --git a/features/seeing_credit_memos_on_admin_order_view.feature b/features/seeing_credit_memos_on_admin_order_view.feature
index 503f61f1..9e968304 100644
--- a/features/seeing_credit_memos_on_admin_order_view.feature
+++ b/features/seeing_credit_memos_on_admin_order_view.feature
@@ -16,11 +16,11 @@ Feature: Seeing credit memos in admin order view
And the customer chose "Galaxy Post" shipping method with "Space money" payment
And the order "#00000022" is already paid
And I am logged in as an administrator
-
+
@ui
Scenario: Having all credit memos listed on the order page in ascending order
Given the "#00000022" order's shipping cost already has a refund of "$4.50" with "Space money" payment
- And the 1st "PHP T-Shirt" product from order "#00000022" has a refund of "$5.50" with "Space money" payment
+ And the 1st "PHP T-Shirt" product from order "#00000022" has a refund of "$5.50" with "Space money" payment done later
When I view the summary of the order "#00000022"
Then I should see the credit memo with "$4.50" total as 1st in the list
And I should see the credit memo with "$5.50" total as 2nd in the list
diff --git a/spec/Converter/RefundUnitsConverterSpec.php b/spec/Converter/RefundUnitsConverterSpec.php
new file mode 100644
index 00000000..e253d6a5
--- /dev/null
+++ b/spec/Converter/RefundUnitsConverterSpec.php
@@ -0,0 +1,71 @@
+beConstructedWith($unitRefundTotalCalculator);
+ }
+
+ public function it_implements_refund_units_converter_interface(): void
+ {
+ $this->shouldImplement(RefundUnitsConverterInterface::class);
+ }
+
+ public function it_converts_refund_units_from_request_with_full_prices_to_models(
+ UnitRefundTotalCalculatorInterface $unitRefundTotalCalculator
+ ): void {
+ $unitRefundTotalCalculator->calculateForUnitWithIdAndType(1, RefundType::orderItemUnit(), null)->willReturn(1000);
+ $unitRefundTotalCalculator->calculateForUnitWithIdAndType(2, RefundType::orderItemUnit(), null)->willReturn(3000);
+
+ $this
+ ->convert(
+ [
+ 1 => ['full' => 'on'],
+ 2 => ['full' => 'on'],
+ ],
+ RefundType::orderItemUnit(),
+ OrderItemUnitRefund::class
+ )
+ ->shouldBeLike([new OrderItemUnitRefund(1, 1000), new OrderItemUnitRefund(2, 3000)])
+ ;
+ }
+
+ public function it_converts_refund_units_from_request_with_partial_prices_to_models(
+ UnitRefundTotalCalculatorInterface $unitRefundTotalCalculator
+ ): void {
+ $unitRefundTotalCalculator->calculateForUnitWithIdAndType(1, RefundType::orderItemUnit(), 10.00)->willReturn(1000);
+ $unitRefundTotalCalculator->calculateForUnitWithIdAndType(2, RefundType::orderItemUnit(), null)->willReturn(3000);
+
+ $this
+ ->convert(
+ [
+ 1 => ['amount' => '10.00'],
+ 2 => ['full' => 'on'],
+ ],
+ RefundType::orderItemUnit(),
+ OrderItemUnitRefund::class
+ )
+ ->shouldBeLike([new OrderItemUnitRefund(1, 1000), new OrderItemUnitRefund(2, 3000)])
+ ;
+ }
+}
diff --git a/spec/Creator/RefundUnitsCommandCreatorSpec.php b/spec/Creator/RefundUnitsCommandCreatorSpec.php
index 41f16f89..285bd530 100644
--- a/spec/Creator/RefundUnitsCommandCreatorSpec.php
+++ b/spec/Creator/RefundUnitsCommandCreatorSpec.php
@@ -14,8 +14,8 @@
namespace spec\Sylius\RefundPlugin\Creator;
use PhpSpec\ObjectBehavior;
-use Sylius\RefundPlugin\Calculator\UnitRefundTotalCalculatorInterface;
use Sylius\RefundPlugin\Command\RefundUnits;
+use Sylius\RefundPlugin\Converter\RefundUnitsConverterInterface;
use Sylius\RefundPlugin\Creator\RefundUnitsCommandCreatorInterface;
use Sylius\RefundPlugin\Model\OrderItemUnitRefund;
use Sylius\RefundPlugin\Model\RefundType;
@@ -25,10 +25,9 @@
final class RefundUnitsCommandCreatorSpec extends ObjectBehavior
{
- public function let(
- UnitRefundTotalCalculatorInterface $unitRefundTotalCalculator
- ): void {
- $this->beConstructedWith($unitRefundTotalCalculator);
+ public function let(RefundUnitsConverterInterface $refundUnitsConverter): void
+ {
+ $this->beConstructedWith($refundUnitsConverter);
}
public function it_implements_refund_units_command_creator_interface(): void
@@ -36,10 +35,14 @@ public function it_implements_refund_units_command_creator_interface(): void
$this->shouldImplement(RefundUnitsCommandCreatorInterface::class);
}
- public function it_creates_refund_units_command_from_request_with_full_prices(
- UnitRefundTotalCalculatorInterface $unitRefundTotalCalculator,
+ public function it_creates_refund_units_command_from_request(
+ RefundUnitsConverterInterface $refundUnitsConverter,
Request $request
): void {
+ $firstUnitRefund = new OrderItemUnitRefund(1, 1000);
+ $secondUnitRefund = new OrderItemUnitRefund(2, 3000);
+ $shipmentRefund = new ShipmentRefund(1, 5000);
+
$request->attributes = new ParameterBag(['orderNumber' => '00001111']);
$request->request = new ParameterBag([
'sylius_refund_units' => [
@@ -53,54 +56,45 @@ public function it_creates_refund_units_command_from_request_with_full_prices(
'sylius_refund_comment' => 'Comment',
]);
- $unitRefundTotalCalculator->calculateForUnitWithIdAndType(1, RefundType::orderItemUnit(), null)->willReturn(1000);
- $unitRefundTotalCalculator->calculateForUnitWithIdAndType(2, RefundType::orderItemUnit(), null)->willReturn(3000);
- $unitRefundTotalCalculator->calculateForUnitWithIdAndType(1, RefundType::shipment(), null)->willReturn(5000);
+ $refundUnitsConverter
+ ->convert(
+ [
+ 1 => ['full' => 'on'],
+ 2 => ['full' => 'on'],
+ ],
+ RefundType::orderItemUnit(),
+ OrderItemUnitRefund::class
+ )
+ ->willReturn([$firstUnitRefund, $secondUnitRefund])
+ ;
+ $refundUnitsConverter
+ ->convert(
+ [1 => ['full' => 'on']],
+ RefundType::shipment(),
+ ShipmentRefund::class
+ )
+ ->willReturn([$shipmentRefund])
+ ;
$this->fromRequest($request)->shouldReturnCommand(new RefundUnits(
'00001111',
- [new OrderItemUnitRefund(1, 1000), new OrderItemUnitRefund(2, 3000)],
- [new ShipmentRefund(1, 5000)],
+ [$firstUnitRefund, $secondUnitRefund],
+ [$shipmentRefund],
1,
'Comment'
));
}
- public function it_creates_refund_units_command_from_request_with_partial_prices(
- UnitRefundTotalCalculatorInterface $unitRefundTotalCalculator,
+ public function it_throws_exception_if_there_is_no_units_nor_shipments_provided(
+ RefundUnitsConverterInterface $refundUnitsConverter,
Request $request
): void {
- $request->attributes = new ParameterBag(['orderNumber' => '00001111']);
- $request->request = new ParameterBag([
- 'sylius_refund_units' => [
- 1 => ['amount' => '10.00'],
- 2 => ['full' => 'on'],
- ],
- 'sylius_refund_shipments' => [
- 1 => ['amount' => '5.00'],
- ],
- 'sylius_refund_payment_method' => 1,
- 'sylius_refund_comment' => 'Comment',
- ]);
-
- $unitRefundTotalCalculator->calculateForUnitWithIdAndType(1, RefundType::orderItemUnit(), 10.00)->willReturn(1000);
- $unitRefundTotalCalculator->calculateForUnitWithIdAndType(2, RefundType::orderItemUnit(), null)->willReturn(3000);
- $unitRefundTotalCalculator->calculateForUnitWithIdAndType(1, RefundType::shipment(), 5.00)->willReturn(500);
-
- $this->fromRequest($request)->shouldReturnCommand(new RefundUnits(
- '00001111',
- [new OrderItemUnitRefund(1, 1000), new OrderItemUnitRefund(2, 3000)],
- [new ShipmentRefund(1, 500)],
- 1,
- 'Comment'
- ));
- }
-
- public function it_throws_exception_if_there_is_no_units_nor_shipments_provided(Request $request): void
- {
$request->attributes = new ParameterBag(['orderNumber' => '00001111']);
$request->request = new ParameterBag(['sylius_refund_payment_method' => 1]);
+ $refundUnitsConverter->convert([], RefundType::orderItemUnit(), OrderItemUnitRefund::class)->willReturn([]);
+ $refundUnitsConverter->convert([], RefundType::shipment(), ShipmentRefund::class)->willReturn([]);
+
$this
->shouldThrow(\InvalidArgumentException::class)
->during('fromRequest', [$request])
diff --git a/spec/Factory/RefundPaymentFactorySpec.php b/spec/Factory/RefundPaymentFactorySpec.php
index e638e05a..1d8e62c8 100644
--- a/spec/Factory/RefundPaymentFactorySpec.php
+++ b/spec/Factory/RefundPaymentFactorySpec.php
@@ -16,7 +16,6 @@
use PhpSpec\ObjectBehavior;
use Sylius\Component\Core\Model\OrderInterface;
use Sylius\Component\Core\Model\PaymentMethodInterface;
-use Sylius\Component\Core\Repository\PaymentMethodRepositoryInterface;
use Sylius\RefundPlugin\Entity\RefundPayment;
use Sylius\RefundPlugin\Entity\RefundPaymentInterface;
use Sylius\RefundPlugin\Factory\RefundPaymentFactory;
@@ -24,9 +23,9 @@
final class RefundPaymentFactorySpec extends ObjectBehavior
{
- public function let(PaymentMethodRepositoryInterface $paymentMethodRepository): void
+ public function let(): void
{
- $this->beConstructedWith($paymentMethodRepository);
+ $this->beConstructedWith(RefundPayment::class);
}
public function it_is_initializable(): void
@@ -39,29 +38,25 @@ public function it_implements_refund_payment_factory_interface(): void
$this->shouldImplement(RefundPaymentFactoryInterface::class);
}
- public function it_creates_new_refund_payment(
- PaymentMethodRepositoryInterface $paymentMethodRepository,
- PaymentMethodInterface $paymentMethod,
- OrderInterface $order
+ public function it_creates_a_new_refund_payment(
+ OrderInterface $order,
+ PaymentMethodInterface $paymentMethod
): void {
- $paymentMethodRepository->find(1)->willReturn($paymentMethod);
-
$this
->createWithData(
$order,
1000,
'USD',
RefundPaymentInterface::STATE_NEW,
- 1
+ $paymentMethod
)
- ->shouldBeLike(
- new RefundPayment(
- $order->getWrappedObject(),
- 1000,
- 'USD',
- RefundPaymentInterface::STATE_NEW,
- $paymentMethod->getWrappedObject()
- )
- );
+ ->shouldBeLike(new RefundPayment(
+ $order->getWrappedObject(),
+ 1000,
+ 'USD',
+ RefundPaymentInterface::STATE_NEW,
+ $paymentMethod->getWrappedObject()
+ ))
+ ;
}
}
diff --git a/spec/ProcessManager/RefundPaymentProcessManagerSpec.php b/spec/ProcessManager/RefundPaymentProcessManagerSpec.php
index cfd0ab0b..62e2c642 100644
--- a/spec/ProcessManager/RefundPaymentProcessManagerSpec.php
+++ b/spec/ProcessManager/RefundPaymentProcessManagerSpec.php
@@ -16,7 +16,9 @@
use Doctrine\ORM\EntityManagerInterface;
use PhpSpec\ObjectBehavior;
use Sylius\Component\Core\Model\OrderInterface;
+use Sylius\Component\Core\Model\PaymentMethodInterface;
use Sylius\Component\Core\Repository\OrderRepositoryInterface;
+use Sylius\Component\Core\Repository\PaymentMethodRepositoryInterface;
use Sylius\RefundPlugin\Entity\RefundPaymentInterface;
use Sylius\RefundPlugin\Event\RefundPaymentGenerated;
use Sylius\RefundPlugin\Event\UnitsRefunded;
@@ -36,6 +38,7 @@ public function let(
RelatedPaymentIdProviderInterface $relatedPaymentIdProvider,
RefundPaymentFactoryInterface $refundPaymentFactory,
OrderRepositoryInterface $orderRepository,
+ PaymentMethodRepositoryInterface $paymentMethodRepository,
EntityManagerInterface $entityManager,
MessageBusInterface $eventBus
): void {
@@ -44,6 +47,7 @@ public function let(
$relatedPaymentIdProvider,
$refundPaymentFactory,
$orderRepository,
+ $paymentMethodRepository,
$entityManager,
$eventBus
);
@@ -59,20 +63,20 @@ public function it_reacts_on_units_refunded_event_and_creates_refund_payment(
RelatedPaymentIdProviderInterface $relatedPaymentIdProvider,
RefundPaymentFactoryInterface $refundPaymentFactory,
OrderRepositoryInterface $orderRepository,
+ PaymentMethodRepositoryInterface $paymentMethodRepository,
EntityManagerInterface $entityManager,
MessageBusInterface $eventBus,
RefundPaymentInterface $refundPayment,
- OrderInterface $order
+ OrderInterface $order,
+ PaymentMethodInterface $paymentMethod
): void {
$orderRepository->findOneByNumber('000222')->willReturn($order);
+ $paymentMethodRepository->find(1)->willReturn($paymentMethod);
- $refundPaymentFactory->createWithData(
- $order,
- 1000,
- 'USD',
- RefundPaymentInterface::STATE_NEW,
- 1
- )->willReturn($refundPayment);
+ $refundPaymentFactory
+ ->createWithData($order, 1000, 'USD', RefundPaymentInterface::STATE_NEW, $paymentMethod)
+ ->willReturn($refundPayment)
+ ;
$entityManager->persist($refundPayment)->shouldBeCalled();
$entityManager->flush()->shouldBeCalled();
diff --git a/src/Converter/RefundUnitsConverter.php b/src/Converter/RefundUnitsConverter.php
new file mode 100644
index 00000000..f7dc9ae1
--- /dev/null
+++ b/src/Converter/RefundUnitsConverter.php
@@ -0,0 +1,63 @@
+unitRefundTotalCalculator = $unitRefundTotalCalculator;
+ }
+
+ public function convert(array $units, RefundType $refundType, string $unitRefundClass): array
+ {
+ $units = $this->filterEmptyRefundUnits($units);
+ $refundUnits = [];
+ foreach ($units as $id => $unit) {
+ $total = $this
+ ->unitRefundTotalCalculator
+ ->calculateForUnitWithIdAndType($id, $refundType, $this->getAmount($unit))
+ ;
+
+ $refundUnits[] = new $unitRefundClass((int) $id, $total);
+ }
+
+ return $refundUnits;
+ }
+
+ private function filterEmptyRefundUnits(array $units): array
+ {
+ return array_filter($units, function (array $refundUnit): bool {
+ return (isset($refundUnit['amount']) && $refundUnit['amount'] !== '') || isset($refundUnit['full']);
+ });
+ }
+
+ private function getAmount(array $unit): ?float
+ {
+ if (isset($unit['full'])) {
+ return null;
+ }
+
+ Assert::keyExists($unit, 'amount');
+
+ return (float) $unit['amount'];
+ }
+}
diff --git a/src/Converter/RefundUnitsConverterInterface.php b/src/Converter/RefundUnitsConverterInterface.php
new file mode 100644
index 00000000..bbc6a2b7
--- /dev/null
+++ b/src/Converter/RefundUnitsConverterInterface.php
@@ -0,0 +1,25 @@
+unitRefundTotalCalculator = $unitRefundTotalCalculator;
+ $this->refundUnitsConverter = $refundUnitsConverter;
}
public function fromRequest(Request $request): RefundUnits
{
Assert::true($request->attributes->has('orderNumber'), 'Refunded order number not provided');
- $units = $this->filterEmptyRefundUnits(
- $request->request->has('sylius_refund_units') ? $request->request->all()['sylius_refund_units'] : []
+ $units = $this->refundUnitsConverter->convert(
+ $request->request->has('sylius_refund_units') ? $request->request->all()['sylius_refund_units'] : [],
+ RefundType::orderItemUnit(),
+ OrderItemUnitRefund::class
);
- $shipments = $this->filterEmptyRefundUnits(
- $request->request->has('sylius_refund_shipments') ? $request->request->all()['sylius_refund_shipments'] : []
+
+ $shipments = $this->refundUnitsConverter->convert(
+ $request->request->has('sylius_refund_shipments') ? $request->request->all()['sylius_refund_shipments'] : [],
+ RefundType::shipment(),
+ ShipmentRefund::class
);
if (count($units) === 0 && count($shipments) === 0) {
@@ -53,51 +57,10 @@ public function fromRequest(Request $request): RefundUnits
return new RefundUnits(
$request->attributes->get('orderNumber'),
- $this->parseIdsToUnitRefunds($units, RefundType::orderItemUnit(), OrderItemUnitRefund::class),
- $this->parseIdsToUnitRefunds($shipments, RefundType::shipment(), ShipmentRefund::class),
+ $units,
+ $shipments,
(int) $request->request->get('sylius_refund_payment_method'),
$comment
);
}
-
- /**
- * Parse shipment id's to ShipmentRefund with id and remaining total or amount passed in request
- *
- * @return array|UnitRefundInterface[]
- */
- private function parseIdsToUnitRefunds(array $units, RefundType $refundType, string $unitRefundClass): array
- {
- $refundUnits = [];
- foreach ($units as $id => $unit) {
- $total = $this
- ->unitRefundTotalCalculator
- ->calculateForUnitWithIdAndType($id, $refundType, $this->getAmount($unit))
- ;
-
- $refundUnits[] = new $unitRefundClass((int) $id, $total);
- }
-
- return $refundUnits;
- }
-
- private function filterEmptyRefundUnits(array $units): array
- {
- return array_filter($units, function (array $refundUnit): bool {
- return
- (isset($refundUnit['amount']) && $refundUnit['amount'] !== '')
- || isset($refundUnit['full'])
- ;
- });
- }
-
- private function getAmount(array $unit): ?float
- {
- if (isset($unit['full'])) {
- return null;
- }
-
- Assert::keyExists($unit, 'amount');
-
- return (float) $unit['amount'];
- }
}
diff --git a/src/Factory/RefundPaymentFactory.php b/src/Factory/RefundPaymentFactory.php
index c9b05af4..7525655d 100644
--- a/src/Factory/RefundPaymentFactory.php
+++ b/src/Factory/RefundPaymentFactory.php
@@ -15,18 +15,16 @@
use Sylius\Component\Core\Model\OrderInterface;
use Sylius\Component\Core\Model\PaymentMethodInterface;
-use Sylius\Component\Core\Repository\PaymentMethodRepositoryInterface;
-use Sylius\RefundPlugin\Entity\RefundPayment;
use Sylius\RefundPlugin\Entity\RefundPaymentInterface;
final class RefundPaymentFactory implements RefundPaymentFactoryInterface
{
- /** @var PaymentMethodRepositoryInterface */
- private $paymentMethodRepository;
+ /** @var string */
+ private $className;
- public function __construct(PaymentMethodRepositoryInterface $paymentMethodRepository)
+ public function __construct(string $className)
{
- $this->paymentMethodRepository = $paymentMethodRepository;
+ $this->className = $className;
}
public function createWithData(
@@ -34,11 +32,8 @@ public function createWithData(
int $amount,
string $currencyCode,
string $state,
- int $paymentMethodId
+ PaymentMethodInterface $paymentMethod
): RefundPaymentInterface {
- /** @var PaymentMethodInterface $paymentMethod */
- $paymentMethod = $this->paymentMethodRepository->find($paymentMethodId);
-
- return new RefundPayment($order, $amount, $currencyCode, $state, $paymentMethod);
+ return new $this->className($order, $amount, $currencyCode, $state, $paymentMethod);
}
}
diff --git a/src/Factory/RefundPaymentFactoryInterface.php b/src/Factory/RefundPaymentFactoryInterface.php
index d9fccc42..64d6576c 100644
--- a/src/Factory/RefundPaymentFactoryInterface.php
+++ b/src/Factory/RefundPaymentFactoryInterface.php
@@ -14,6 +14,7 @@
namespace Sylius\RefundPlugin\Factory;
use Sylius\Component\Core\Model\OrderInterface;
+use Sylius\Component\Core\Model\PaymentMethodInterface;
use Sylius\RefundPlugin\Entity\RefundPaymentInterface;
interface RefundPaymentFactoryInterface
@@ -23,6 +24,6 @@ public function createWithData(
int $amount,
string $currencyCode,
string $state,
- int $paymentMethodId
+ PaymentMethodInterface $paymentMethod
): RefundPaymentInterface;
}
diff --git a/src/ProcessManager/RefundPaymentProcessManager.php b/src/ProcessManager/RefundPaymentProcessManager.php
index 9931253b..1d794648 100644
--- a/src/ProcessManager/RefundPaymentProcessManager.php
+++ b/src/ProcessManager/RefundPaymentProcessManager.php
@@ -15,7 +15,9 @@
use Doctrine\ORM\EntityManagerInterface;
use Sylius\Component\Core\Model\OrderInterface;
+use Sylius\Component\Core\Model\PaymentMethodInterface;
use Sylius\Component\Core\Repository\OrderRepositoryInterface;
+use Sylius\Component\Core\Repository\PaymentMethodRepositoryInterface;
use Sylius\RefundPlugin\Entity\RefundPaymentInterface;
use Sylius\RefundPlugin\Event\RefundPaymentGenerated;
use Sylius\RefundPlugin\Event\UnitsRefunded;
@@ -39,6 +41,9 @@ final class RefundPaymentProcessManager implements UnitsRefundedProcessStepInter
/** @var OrderRepositoryInterface */
private $orderRepository;
+ /** @var PaymentMethodRepositoryInterface */
+ private $paymentMethodRepository;
+
/** @var EntityManagerInterface */
private $entityManager;
@@ -50,6 +55,7 @@ public function __construct(
RelatedPaymentIdProviderInterface $relatedPaymentIdProvider,
RefundPaymentFactoryInterface $refundPaymentFactory,
OrderRepositoryInterface $orderRepository,
+ PaymentMethodRepositoryInterface $paymentMethodRepository,
EntityManagerInterface $entityManager,
MessageBusInterface $eventBus
) {
@@ -57,6 +63,7 @@ public function __construct(
$this->relatedPaymentIdProvider = $relatedPaymentIdProvider;
$this->refundPaymentFactory = $refundPaymentFactory;
$this->orderRepository = $orderRepository;
+ $this->paymentMethodRepository = $paymentMethodRepository;
$this->entityManager = $entityManager;
$this->eventBus = $eventBus;
}
@@ -67,12 +74,16 @@ public function next(UnitsRefunded $unitsRefunded): void
$order = $this->orderRepository->findOneByNumber($unitsRefunded->orderNumber());
Assert::notNull($order);
+ /** @var PaymentMethodInterface|null $paymentMethod */
+ $paymentMethod = $this->paymentMethodRepository->find($unitsRefunded->paymentMethodId());
+ Assert::notNull($paymentMethod);
+
$refundPayment = $this->refundPaymentFactory->createWithData(
$order,
$unitsRefunded->amount(),
$unitsRefunded->currencyCode(),
RefundPaymentInterface::STATE_NEW,
- $unitsRefunded->paymentMethodId()
+ $paymentMethod
);
$this->entityManager->persist($refundPayment);
diff --git a/src/Resources/config/app/config.yml b/src/Resources/config/app/config.yml
index 1bc11d2f..3f1b1a40 100644
--- a/src/Resources/config/app/config.yml
+++ b/src/Resources/config/app/config.yml
@@ -19,6 +19,7 @@ sylius_resource:
sylius_refund.refund_payment:
classes:
model: Sylius\RefundPlugin\Entity\RefundPayment
+ factory: Sylius\RefundPlugin\Factory\RefundPaymentFactory
sylius_refund.customer_billing_data:
classes:
model: Sylius\RefundPlugin\Entity\CustomerBillingData
diff --git a/src/Resources/config/services/converters.xml b/src/Resources/config/services/converters.xml
index 91cfeb53..38c8866c 100644
--- a/src/Resources/config/services/converters.xml
+++ b/src/Resources/config/services/converters.xml
@@ -9,6 +9,10 @@
+
+
+
+
diff --git a/src/Resources/config/services/creators.xml b/src/Resources/config/services/creators.xml
index 0c628b0e..9ec3802d 100644
--- a/src/Resources/config/services/creators.xml
+++ b/src/Resources/config/services/creators.xml
@@ -18,7 +18,7 @@
-
+
The "%alias_id%" service alias is deprecated and will be removed in RefundPlugin 1.0, use Sylius\RefundPlugin\Creator\RefundUnitsCommandCreatorInterface instead.
diff --git a/src/Resources/config/services/event_bus.xml b/src/Resources/config/services/event_bus.xml
index b957f77d..a6f1c4ca 100644
--- a/src/Resources/config/services/event_bus.xml
+++ b/src/Resources/config/services/event_bus.xml
@@ -30,8 +30,9 @@
-
+
+
diff --git a/src/Resources/config/services/factories.xml b/src/Resources/config/services/factories.xml
index f004fae0..ee612b47 100644
--- a/src/Resources/config/services/factories.xml
+++ b/src/Resources/config/services/factories.xml
@@ -12,13 +12,6 @@
The "%alias_id%" service alias is deprecated and will be removed in RefundPlugin 1.0, use Sylius\RefundPlugin\Factory\CreditMemoSequenceFactoryInterface instead.
-
-
-
-
- The "%alias_id%" service alias is deprecated and will be removed in RefundPlugin 1.0, use Sylius\RefundPlugin\Factory\RefundPaymentFactoryInterface instead.
-
-
theProductFromOrderHasARefundOfWith($unitNumber, $productName, $orderNumber, $partialTotal, $paymentMethod);
+ }
+
/**
* @Given /^all units from the order "#([^"]+)" are refunded with ("[^"]+" payment)$/
*/
diff --git a/tests/Behat/Services/Factory/FailedRefundPaymentFactory.php b/tests/Behat/Services/Factory/FailedRefundPaymentFactory.php
index eadea5e5..f8a7ef38 100644
--- a/tests/Behat/Services/Factory/FailedRefundPaymentFactory.php
+++ b/tests/Behat/Services/Factory/FailedRefundPaymentFactory.php
@@ -5,6 +5,7 @@
namespace Tests\Sylius\RefundPlugin\Behat\Services\Factory;
use Sylius\Component\Core\Model\OrderInterface;
+use Sylius\Component\Core\Model\PaymentMethodInterface;
use Sylius\RefundPlugin\Entity\RefundPaymentInterface;
use Sylius\RefundPlugin\Factory\RefundPaymentFactoryInterface;
@@ -25,7 +26,7 @@ public function createWithData(
int $amount,
string $currencyCode,
string $state,
- int $paymentMethodId
+ PaymentMethodInterface $paymentMethod
): RefundPaymentInterface {
if (file_exists(self::FAILED_FILE)) {
unlink(self::FAILED_FILE);
@@ -33,7 +34,7 @@ public function createWithData(
throw new \Exception('Refund payment creation failed');
}
- return $this->baseRefundPaymentFactory->createWithData($order, $amount, $currencyCode, $state, $paymentMethodId);
+ return $this->baseRefundPaymentFactory->createWithData($order, $amount, $currencyCode, $state, $paymentMethod);
}
public function failRefundPaymentCreation(): void