Skip to content

Commit 0fe0815

Browse files
[Refund] Soft deprecate refunds bypassing RefundPlugin
1 parent d4ccbf6 commit 0fe0815

File tree

10 files changed

+84
-1
lines changed

10 files changed

+84
-1
lines changed

config/services/twig.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@
5050
<tag name="twig.extension" />
5151
</service>
5252

53+
<service id="sylius_mollie.twig.extension.legacy_refund" class="Sylius\MolliePlugin\Twig\Extension\LegacyRefundExtension">
54+
<argument type="service" id="sylius_mollie.payum.checker.mollie_gateway_factory" />
55+
<tag name="twig.extension" />
56+
</service>
57+
5358
<service
5459
id="sylius_mollie.twig.component.email_template.form"
5560
class="Sylius\Bundle\UiBundle\Twig\Component\ResourceFormComponent"

config/twig_hooks/admin/payment_method/mollie/create.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ sylius_twig_hooks:
1313
log_level:
1414
template: '@SyliusMolliePlugin/admin/payment_method/form/sections/gateway_configuration/log_level.html.twig'
1515
priority: 100
16+
legacy_refund:
17+
template: '@SyliusMolliePlugin/admin/payment_method/form/sections/gateway_configuration/legacy_refund.html.twig'
18+
priority: 50
1619
mollie_payment_methods:
1720
template: '@SyliusMolliePlugin/admin/payment_method/form/sections/gateway_configuration/mollie_payment_methods.html.twig'
1821
priority: 0

config/twig_hooks/admin/payment_method/mollie/update.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ sylius_twig_hooks:
2424
log_level:
2525
template: '@SyliusMolliePlugin/admin/payment_method/form/sections/gateway_configuration/log_level.html.twig'
2626
priority: 100
27+
legacy_refund:
28+
template: '@SyliusMolliePlugin/admin/payment_method/form/sections/gateway_configuration/legacy_refund.html.twig'
29+
priority: 50
2730
mollie_payment_methods:
2831
template: '@SyliusMolliePlugin/admin/payment_method/form/sections/gateway_configuration/mollie_payment_methods.html.twig'
2932
priority: 0

config/twig_hooks/admin/payment_method/mollie_subscription/create.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ sylius_twig_hooks:
1313
log_level:
1414
template: '@SyliusMolliePlugin/admin/payment_method/form/sections/gateway_configuration/log_level.html.twig'
1515
priority: 100
16+
legacy_refund:
17+
template: '@SyliusMolliePlugin/admin/payment_method/form/sections/gateway_configuration/legacy_refund.html.twig'
18+
priority: 50
1619
mollie_payment_methods:
1720
template: '@SyliusMolliePlugin/admin/payment_method/form/sections/gateway_configuration/mollie_payment_methods.html.twig'
1821
priority: 0

config/twig_hooks/admin/payment_method/mollie_subscription/update.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ sylius_twig_hooks:
1313
log_level:
1414
template: '@SyliusMolliePlugin/admin/payment_method/form/sections/gateway_configuration/log_level.html.twig'
1515
priority: 100
16+
legacy_refund:
17+
template: '@SyliusMolliePlugin/admin/payment_method/form/sections/gateway_configuration/legacy_refund.html.twig'
18+
priority: 50
1619
mollie_payment_methods:
1720
template: '@SyliusMolliePlugin/admin/payment_method/form/sections/gateway_configuration/mollie_payment_methods.html.twig'
1821
priority: 0

src/Form/Type/MollieGatewayConfigurationType.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
use Mollie\Api\Exceptions\ApiException;
1717
use Sylius\MolliePlugin\Client\MollieApiClient;
18+
use Sylius\MolliePlugin\Twig\Extension\LegacyRefundExtension;
1819
use Sylius\MolliePlugin\Validator\Constraints\LiveApiKeyIsNotBlank;
1920
use Symfony\Component\Form\AbstractType;
2021
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
@@ -100,6 +101,11 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
100101
->add('loggerLevel', LoggerLevelChoiceType::class, [
101102
'log_type' => LoggerLevelChoiceType::TYPE_DEBUG,
102103
])
104+
->add(LegacyRefundExtension::CONFIG_KEY, CheckboxType::class, [
105+
'label' => 'sylius_mollie.form.legacy_refund',
106+
'help' => 'sylius_mollie.form.legacy_refund_help',
107+
'required' => false,
108+
])
103109
->add('components', CheckboxType::class, [
104110
'label' => 'sylius_mollie.ui.enable_components',
105111
'attr' => ['class' => 'mollie-components'],
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Sylius Mollie Plugin package.
5+
*
6+
* (c) Sylius Sp. z o.o.
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
declare(strict_types=1);
13+
14+
namespace Sylius\MolliePlugin\Twig\Extension;
15+
16+
use Sylius\Component\Core\Model\PaymentInterface;
17+
use Sylius\MolliePlugin\Entity\GatewayConfigInterface;
18+
use Sylius\MolliePlugin\Payum\Checker\MollieGatewayFactoryCheckerInterface;
19+
use Twig\Extension\AbstractExtension;
20+
use Twig\TwigFunction;
21+
22+
final class LegacyRefundExtension extends AbstractExtension
23+
{
24+
public const CONFIG_KEY = 'legacy_refund';
25+
26+
public function __construct(private MollieGatewayFactoryCheckerInterface $mollieGatewayFactoryChecker)
27+
{
28+
}
29+
30+
/** @return TwigFunction[] */
31+
public function getFunctions(): array
32+
{
33+
return [
34+
new TwigFunction('mollie_legacy_refund_enabled', [$this, 'isLegacyRefundEnabled']),
35+
];
36+
}
37+
38+
public function isLegacyRefundEnabled(PaymentInterface $payment): bool
39+
{
40+
/** @var GatewayConfigInterface|null $gatewayConfig */
41+
$gatewayConfig = $payment->getMethod()?->getGatewayConfig();
42+
if (null === $gatewayConfig || false === $this->mollieGatewayFactoryChecker->isMollieGateway($gatewayConfig)) {
43+
return false;
44+
}
45+
46+
$config = $gatewayConfig->getConfig();
47+
48+
return isset($config[self::CONFIG_KEY]) && true === $config[self::CONFIG_KEY];
49+
}
50+
}

templates/admin/order/show/content/sections/payments/item/actions/refund.html.twig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
{% set refund_link = path('sylius_mollie_admin_order_payment_refund', {'orderId': order.id, 'id': payment.id}) %}
77
{% endif %}
88

9-
{% if sylius_sm_can(payment, constant('Sylius\\Component\\Payment\\PaymentTransitions::GRAPH'), constant('Sylius\\Component\\Payment\\PaymentTransitions::TRANSITION_REFUND')) %}
9+
{% if mollie_legacy_refund_enabled(payment) and sylius_sm_can(payment, constant('Sylius\\Component\\Payment\\PaymentTransitions::GRAPH'), constant('Sylius\\Component\\Payment\\PaymentTransitions::TRANSITION_REFUND')) %}
1010
<form action="{{ refund_link }}" method="POST" novalidate>
1111
<input type="hidden" name="_method" value="PUT">
1212
<input type="hidden" name="_csrf_token" value="{{ csrf_token(payment.id) }}" />
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{% set form = hookable_metadata.context.form.gatewayConfig.config.legacy_refund %}
2+
<div class="card mb-3">
3+
<div class="card-body mt-3">
4+
<div class="row">
5+
{{ form_row(form) }}
6+
</div>
7+
</div>
8+
</div>

translations/messages.en.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,8 @@ sylius_mollie:
212212
enable_all: 'Enable all'
213213
enabled_buy_now_button_help: 'The button is shown on the checkout page'
214214
expiration_date_time: 'Expiration date time'
215+
legacy_refund: 'Enable legacy refund'
216+
legacy_refund_help: 'Allows refunding the whole payment bypassing Sylius refund system. Enabling this options is not recommended and will be removed in future versions.'
215217
methods: 'Choose enabled methods'
216218
no_category: 'No default category'
217219
payment_methods:

0 commit comments

Comments
 (0)