Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
5 changes: 5 additions & 0 deletions config/services/twig.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@
<tag name="twig.extension" />
</service>

<service id="sylius_mollie.twig.extension.legacy_refund" class="Sylius\MolliePlugin\Twig\Extension\LegacyRefundExtension">
<argument type="service" id="sylius_mollie.payum.checker.mollie_gateway_factory" />
<tag name="twig.extension" />
</service>

<service
id="sylius_mollie.twig.component.email_template.form"
class="Sylius\Bundle\UiBundle\Twig\Component\ResourceFormComponent"
Expand Down
3 changes: 3 additions & 0 deletions config/twig_hooks/admin/payment_method/mollie/create.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ sylius_twig_hooks:
log_level:
template: '@SyliusMolliePlugin/admin/payment_method/form/sections/gateway_configuration/log_level.html.twig'
priority: 100
legacy_refund:
template: '@SyliusMolliePlugin/admin/payment_method/form/sections/gateway_configuration/legacy_refund.html.twig'
priority: 50
mollie_payment_methods:
template: '@SyliusMolliePlugin/admin/payment_method/form/sections/gateway_configuration/mollie_payment_methods.html.twig'
priority: 0
Expand Down
3 changes: 3 additions & 0 deletions config/twig_hooks/admin/payment_method/mollie/update.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ sylius_twig_hooks:
log_level:
template: '@SyliusMolliePlugin/admin/payment_method/form/sections/gateway_configuration/log_level.html.twig'
priority: 100
legacy_refund:
template: '@SyliusMolliePlugin/admin/payment_method/form/sections/gateway_configuration/legacy_refund.html.twig'
priority: 50
mollie_payment_methods:
template: '@SyliusMolliePlugin/admin/payment_method/form/sections/gateway_configuration/mollie_payment_methods.html.twig'
priority: 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ sylius_twig_hooks:
log_level:
template: '@SyliusMolliePlugin/admin/payment_method/form/sections/gateway_configuration/log_level.html.twig'
priority: 100
legacy_refund:
template: '@SyliusMolliePlugin/admin/payment_method/form/sections/gateway_configuration/legacy_refund.html.twig'
priority: 50
mollie_payment_methods:
template: '@SyliusMolliePlugin/admin/payment_method/form/sections/gateway_configuration/mollie_payment_methods.html.twig'
priority: 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ sylius_twig_hooks:
log_level:
template: '@SyliusMolliePlugin/admin/payment_method/form/sections/gateway_configuration/log_level.html.twig'
priority: 100
legacy_refund:
template: '@SyliusMolliePlugin/admin/payment_method/form/sections/gateway_configuration/legacy_refund.html.twig'
priority: 50
mollie_payment_methods:
template: '@SyliusMolliePlugin/admin/payment_method/form/sections/gateway_configuration/mollie_payment_methods.html.twig'
priority: 0
Expand Down
6 changes: 6 additions & 0 deletions src/Form/Type/MollieGatewayConfigurationType.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

use Mollie\Api\Exceptions\ApiException;
use Sylius\MolliePlugin\Client\MollieApiClient;
use Sylius\MolliePlugin\Twig\Extension\LegacyRefundExtension;
use Sylius\MolliePlugin\Validator\Constraints\LiveApiKeyIsNotBlank;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
Expand Down Expand Up @@ -100,6 +101,11 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
->add('loggerLevel', LoggerLevelChoiceType::class, [
'log_type' => LoggerLevelChoiceType::TYPE_DEBUG,
])
->add(LegacyRefundExtension::CONFIG_KEY, CheckboxType::class, [
'label' => 'sylius_mollie.form.legacy_refund',
'help' => 'sylius_mollie.form.legacy_refund_help',
'required' => false,
])
->add('components', CheckboxType::class, [
'label' => 'sylius_mollie.ui.enable_components',
'attr' => ['class' => 'mollie-components'],
Expand Down
50 changes: 50 additions & 0 deletions src/Twig/Extension/LegacyRefundExtension.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php

/*
* This file is part of the Sylius Mollie Plugin package.
*
* (c) Sylius Sp. z o.o.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace Sylius\MolliePlugin\Twig\Extension;

use Sylius\Component\Core\Model\PaymentInterface;
use Sylius\MolliePlugin\Entity\GatewayConfigInterface;
use Sylius\MolliePlugin\Payum\Checker\MollieGatewayFactoryCheckerInterface;
use Twig\Extension\AbstractExtension;
use Twig\TwigFunction;

final class LegacyRefundExtension extends AbstractExtension
{
public const CONFIG_KEY = 'legacy_refund';

public function __construct(private MollieGatewayFactoryCheckerInterface $mollieGatewayFactoryChecker)
{
}

/** @return TwigFunction[] */
public function getFunctions(): array
{
return [
new TwigFunction('mollie_legacy_refund_enabled', [$this, 'isLegacyRefundEnabled']),
];
}

public function isLegacyRefundEnabled(PaymentInterface $payment): bool
{
/** @var GatewayConfigInterface|null $gatewayConfig */
$gatewayConfig = $payment->getMethod()?->getGatewayConfig();
if (null === $gatewayConfig || false === $this->mollieGatewayFactoryChecker->isMollieGateway($gatewayConfig)) {
return false;
}

$config = $gatewayConfig->getConfig();

return isset($config[self::CONFIG_KEY]) && true === $config[self::CONFIG_KEY];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
{% set refund_link = path('sylius_mollie_admin_order_payment_refund', {'orderId': order.id, 'id': payment.id}) %}
{% endif %}

{% if sylius_sm_can(payment, constant('Sylius\\Component\\Payment\\PaymentTransitions::GRAPH'), constant('Sylius\\Component\\Payment\\PaymentTransitions::TRANSITION_REFUND')) %}
{% if mollie_legacy_refund_enabled(payment) and sylius_sm_can(payment, constant('Sylius\\Component\\Payment\\PaymentTransitions::GRAPH'), constant('Sylius\\Component\\Payment\\PaymentTransitions::TRANSITION_REFUND')) %}
<form action="{{ refund_link }}" method="POST" novalidate>
<input type="hidden" name="_method" value="PUT">
<input type="hidden" name="_csrf_token" value="{{ csrf_token(payment.id) }}" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{% set form = hookable_metadata.context.form.gatewayConfig.config.legacy_refund %}
<div class="card mb-3">
<div class="card-body mt-3">
<div class="row">
{{ form_row(form) }}
</div>
</div>
</div>
2 changes: 2 additions & 0 deletions translations/messages.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,8 @@ sylius_mollie:
enable_all: 'Enable all'
enabled_buy_now_button_help: 'The button is shown on the checkout page'
expiration_date_time: 'Expiration date time'
legacy_refund: 'Enable legacy refund'
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.'
methods: 'Choose enabled methods'
no_category: 'No default category'
payment_methods:
Expand Down