Skip to content

Commit 604da58

Browse files
committed
Improve extendibility of OrderRefundsListAction
1 parent 4bd5c14 commit 604da58

5 files changed

+69
-9
lines changed

UPGRADE-1.4.md

+9-1
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;
@@ -202,3 +202,11 @@ deprecated code:
202202

203203
and it replaces the `refund_type` attribute for the `sylius_refund.refund_unit_total_provider` tag.
204204
Therefore, the `refund_type` attribute becomes deprecated as well.
205+
206+
18. The interface method `Sylius\RefundPlugin\Provider\RefundPaymentMethodsProviderInterface::findForChannel` has been
207+
replaced with `Sylius\RefundPlugin\Provider\RefundPaymentMethodsProviderInterface::findForOrder`:
208+
209+
```diff
210+
- public function findForChannel(ChannelInterface $channel): array;
211+
+ public function findForOrder(OrderInterface $order): array;
212+
```

spec/Provider/SupportedRefundPaymentMethodsProviderSpec.php

+33
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;
@@ -33,6 +34,38 @@ function it_implements_refund_payment_methods_provider_interface(): void
3334
}
3435

3536
function it_provides_only_supported_payment_methods(
37+
PaymentMethodRepositoryInterface $paymentMethodRepository,
38+
OrderInterface $order,
39+
ChannelInterface $channel,
40+
PaymentMethodInterface $offlinePaymentMethod,
41+
PaymentMethodInterface $payPalPaymentMethod,
42+
PaymentMethodInterface $stripePaymentMethod,
43+
GatewayConfigInterface $offlineGatewayConfig,
44+
GatewayConfigInterface $payPalGatewayConfig,
45+
GatewayConfigInterface $stripeGatewayConfig,
46+
): void {
47+
$order->getChannel()->willReturn($channel);
48+
49+
$paymentMethodRepository->findEnabledForChannel($channel)->willReturn([
50+
$offlinePaymentMethod,
51+
$payPalPaymentMethod,
52+
$stripePaymentMethod,
53+
]);
54+
55+
$offlinePaymentMethod->getGatewayConfig()->willReturn($offlineGatewayConfig);
56+
$offlineGatewayConfig->getFactoryName()->willReturn('offline');
57+
58+
$payPalPaymentMethod->getGatewayConfig()->willReturn($payPalGatewayConfig);
59+
$payPalGatewayConfig->getFactoryName()->willReturn('paypal');
60+
61+
$stripePaymentMethod->getGatewayConfig()->willReturn($stripeGatewayConfig);
62+
$stripeGatewayConfig->getFactoryName()->willReturn('stripe');
63+
64+
$this->findForOrder($order)->shouldReturn([$offlinePaymentMethod, $stripePaymentMethod]);
65+
}
66+
67+
/** @legacy will be removed in RefundPlugin 2.0 */
68+
function it_provides_only_supported_payment_methods_legacy(
3669
PaymentMethodRepositoryInterface $paymentMethodRepository,
3770
ChannelInterface $channel,
3871
PaymentMethodInterface $offlinePaymentMethod,

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

+17
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;
@@ -31,6 +32,22 @@ public function __construct(PaymentMethodRepositoryInterface $paymentMethodRepos
3132
}
3233

3334
public function findForChannel(ChannelInterface $channel): array
35+
{
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 $this->find($channel);
39+
}
40+
41+
public function findForOrder(OrderInterface $order): array
42+
{
43+
/** @var ChannelInterface|null $channel */
44+
$channel = $order->getChannel();
45+
Assert::notNull($channel);
46+
47+
return $this->find($channel);
48+
}
49+
50+
private function find(ChannelInterface $channel): array
3451
{
3552
return array_values(array_filter(
3653
$this->paymentMethodRepository->findEnabledForChannel($channel),

0 commit comments

Comments
 (0)