Skip to content

Commit b199f73

Browse files
committed
Improve extendibility of OrderRefundsListAction
1 parent c3ceef5 commit b199f73

5 files changed

+45
-11
lines changed

UPGRADE-1.4.md

+10-2
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ deprecated code:
175175
}
176176
```
177177

178-
15. The interface method `Sylius\RefundPlugin\Validator\RefundAmountValidatorInterface` has been changed:
178+
15. The interface method `Sylius\RefundPlugin\Validator\RefundAmountValidatorInterface::validateUnits` has been changed:
179179

180180
```diff
181181
- public function validateUnits(array $unitRefunds, RefundTypeInterface $refundType): void;
@@ -192,4 +192,12 @@ deprecated code:
192192
) {
193193
// ...
194194
}
195-
```
195+
```
196+
197+
17. The interface method `Sylius\RefundPlugin\Provider\RefundPaymentMethodsProviderInterface::findForChannel` has been
198+
replaced with `Sylius\RefundPlugin\Provider\RefundPaymentMethodsProviderInterface::findForOrder`:
199+
200+
```diff
201+
- public function findForChannel(ChannelInterface $channel): array;
202+
+ public function findForOrder(OrderInterface $order): array;
203+
```

spec/Provider/SupportedRefundPaymentMethodsProviderSpec.php

+5-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use Payum\Core\Model\GatewayConfigInterface;
1717
use PhpSpec\ObjectBehavior;
1818
use Sylius\Component\Core\Model\ChannelInterface;
19+
use Sylius\Component\Core\Model\OrderInterface;
1920
use Sylius\Component\Core\Model\PaymentMethodInterface;
2021
use Sylius\Component\Core\Repository\PaymentMethodRepositoryInterface;
2122
use Sylius\RefundPlugin\Provider\RefundPaymentMethodsProviderInterface;
@@ -34,6 +35,7 @@ function it_implements_refund_payment_methods_provider_interface(): void
3435

3536
function it_provides_only_supported_payment_methods(
3637
PaymentMethodRepositoryInterface $paymentMethodRepository,
38+
OrderInterface $order,
3739
ChannelInterface $channel,
3840
PaymentMethodInterface $offlinePaymentMethod,
3941
PaymentMethodInterface $payPalPaymentMethod,
@@ -42,6 +44,8 @@ function it_provides_only_supported_payment_methods(
4244
GatewayConfigInterface $payPalGatewayConfig,
4345
GatewayConfigInterface $stripeGatewayConfig,
4446
): void {
47+
$order->getChannel()->willReturn($channel);
48+
4549
$paymentMethodRepository->findEnabledForChannel($channel)->willReturn([
4650
$offlinePaymentMethod,
4751
$payPalPaymentMethod,
@@ -57,6 +61,6 @@ function it_provides_only_supported_payment_methods(
5761
$stripePaymentMethod->getGatewayConfig()->willReturn($stripeGatewayConfig);
5862
$stripeGatewayConfig->getFactoryName()->willReturn('stripe');
5963

60-
$this->findForChannel($channel)->shouldReturn([$offlinePaymentMethod, $stripePaymentMethod]);
64+
$this->findForOrder($order)->shouldReturn([$offlinePaymentMethod, $stripePaymentMethod]);
6165
}
6266
}

src/Action/Admin/OrderRefundsListAction.php

+1-7
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313

1414
namespace Sylius\RefundPlugin\Action\Admin;
1515

16-
use Sylius\Component\Core\Model\ChannelInterface;
1716
use Sylius\Component\Core\Model\OrderInterface;
1817
use Sylius\Component\Core\Repository\OrderRepositoryInterface;
1918
use Sylius\RefundPlugin\Checker\OrderRefundingAvailabilityCheckerInterface;
@@ -26,7 +25,6 @@
2625
use Symfony\Component\HttpFoundation\Session\SessionInterface;
2726
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
2827
use Twig\Environment;
29-
use Webmozart\Assert\Assert;
3028

3129
final class OrderRefundsListAction
3230
{
@@ -56,14 +54,10 @@ public function __invoke(Request $request): Response
5654
return $this->redirectToReferer($order, 'sylius_refund.order_should_be_paid');
5755
}
5856

59-
/** @var ChannelInterface|null $channel */
60-
$channel = $order->getChannel();
61-
Assert::notNull($channel);
62-
6357
return new Response(
6458
$this->twig->render('@SyliusRefundPlugin/orderRefunds.html.twig', [
6559
'order' => $order,
66-
'payment_methods' => $this->refundPaymentMethodsProvider->findForChannel($channel),
60+
'payment_methods' => $this->refundPaymentMethodsProvider->findForOrder($order),
6761
]),
6862
);
6963
}

src/Provider/RefundPaymentMethodsProviderInterface.php

+9-1
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,18 @@
1414
namespace Sylius\RefundPlugin\Provider;
1515

1616
use Sylius\Component\Core\Model\ChannelInterface;
17+
use Sylius\Component\Core\Model\OrderInterface;
1718
use Sylius\Component\Core\Model\PaymentMethodInterface;
1819

20+
/**
21+
* @method PaymentMethodInterface[] findForOrder(OrderInterface $order)
22+
*/
1923
interface RefundPaymentMethodsProviderInterface
2024
{
21-
/** @return array|PaymentMethodInterface[] */
25+
/**
26+
* @deprecated since 1.4, to be removed in 2.0, use findForOrder() instead
27+
*
28+
* @return PaymentMethodInterface[]
29+
*/
2230
public function findForChannel(ChannelInterface $channel): array;
2331
}

src/Provider/SupportedRefundPaymentMethodsProvider.php

+20
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
namespace Sylius\RefundPlugin\Provider;
1515

1616
use Sylius\Component\Core\Model\ChannelInterface;
17+
use Sylius\Component\Core\Model\OrderInterface;
1718
use Sylius\Component\Core\Model\PaymentMethodInterface;
1819
use Sylius\Component\Core\Repository\PaymentMethodRepositoryInterface;
1920
use Webmozart\Assert\Assert;
@@ -32,6 +33,25 @@ public function __construct(PaymentMethodRepositoryInterface $paymentMethodRepos
3233

3334
public function findForChannel(ChannelInterface $channel): array
3435
{
36+
trigger_deprecation('sylius/refund-plugin', '1.4', 'The "%s::findForChannel" method is deprecated and will be removed in 2.0. Use "%s::findForOrder" instead.', self::class, self::class);
37+
38+
return array_values(array_filter(
39+
$this->paymentMethodRepository->findEnabledForChannel($channel),
40+
function (PaymentMethodInterface $paymentMethod): bool {
41+
$gatewayConfig = $paymentMethod->getGatewayConfig();
42+
Assert::notNull($gatewayConfig);
43+
44+
return in_array($gatewayConfig->getFactoryName(), $this->supportedGateways, true);
45+
},
46+
));
47+
}
48+
49+
public function findForOrder(OrderInterface $order): array
50+
{
51+
/** @var ChannelInterface|null $channel */
52+
$channel = $order->getChannel();
53+
Assert::notNull($channel);
54+
3555
return array_values(array_filter(
3656
$this->paymentMethodRepository->findEnabledForChannel($channel),
3757
function (PaymentMethodInterface $paymentMethod): bool {

0 commit comments

Comments
 (0)