diff --git a/config/services/form.php b/config/services/form.php index 08cfe426..1a3abf54 100644 --- a/config/services/form.php +++ b/config/services/form.php @@ -8,7 +8,6 @@ use CommerceWeavers\SyliusTpayPlugin\Form\DataTransformer\VisaMobilePhoneDataTransformer; use CommerceWeavers\SyliusTpayPlugin\Form\EventListener\DecryptGatewayConfigListener; use CommerceWeavers\SyliusTpayPlugin\Form\EventListener\EncryptGatewayConfigListener; -use CommerceWeavers\SyliusTpayPlugin\Form\EventListener\PreventSavingEmptyPasswordFieldsListener; use CommerceWeavers\SyliusTpayPlugin\Form\EventListener\RemoveUnnecessaryPaymentDetailsFieldsListener; use CommerceWeavers\SyliusTpayPlugin\Form\Extension\CompleteTypeExtension; use CommerceWeavers\SyliusTpayPlugin\Form\Extension\PaymentTypeExtension; @@ -32,7 +31,6 @@ ->args([ service('commerce_weavers_sylius_tpay.form.event_listener.decrypt_gateway_config'), service('commerce_weavers_sylius_tpay.form.event_listener.encrypt_gateway_config'), - service('commerce_weavers_sylius_tpay.form.event_listener.prevent_saving_empty_password_fields'), ]) ->tag( 'sylius.gateway_configuration_type', @@ -71,7 +69,5 @@ ]) ; - $services->set('commerce_weavers_sylius_tpay.form.event_listener.prevent_saving_empty_password_fields', PreventSavingEmptyPasswordFieldsListener::class); - $services->set('commerce_weavers_sylius_tpay.form.event_listener.remove_unnecessary_payment_details_fields', RemoveUnnecessaryPaymentDetailsFieldsListener::class); }; diff --git a/config/services/refunding.php b/config/services/refunding.php index c7535e19..6f4032c5 100644 --- a/config/services/refunding.php +++ b/config/services/refunding.php @@ -4,6 +4,7 @@ namespace Symfony\Component\DependencyInjection\Loader\Configurator; +use CommerceWeavers\SyliusTpayPlugin\Refunding\Checker\RefundPluginAvailabilityChecker; use CommerceWeavers\SyliusTpayPlugin\Refunding\Checker\RefundPluginAvailabilityCheckerInterface; use CommerceWeavers\SyliusTpayPlugin\Refunding\Dispatcher\RefundDispatcher; use CommerceWeavers\SyliusTpayPlugin\Refunding\Dispatcher\RefundDispatcherInterface; @@ -13,7 +14,7 @@ return function(ContainerConfigurator $container): void { $services = $container->services(); - $services->set('commerce_weavers_sylius_tpay.refunding.checker.refund_plugin_availability', RefundPluginAvailabilityCheckerInterface::class) + $services->set('commerce_weavers_sylius_tpay.refunding.checker.refund_plugin_availability', RefundPluginAvailabilityChecker::class) ->alias(RefundPluginAvailabilityCheckerInterface::class, 'commerce_weavers_sylius_tpay.refunding.checker.refund_plugin_availability') ; diff --git a/src/Form/Type/TpayGatewayConfigurationType.php b/src/Form/Type/TpayGatewayConfigurationType.php index a700ea22..59099980 100644 --- a/src/Form/Type/TpayGatewayConfigurationType.php +++ b/src/Form/Type/TpayGatewayConfigurationType.php @@ -6,21 +6,20 @@ use CommerceWeavers\SyliusTpayPlugin\Form\EventListener\DecryptGatewayConfigListenerInterface; use CommerceWeavers\SyliusTpayPlugin\Form\EventListener\EncryptGatewayConfigListenerInterface; -use CommerceWeavers\SyliusTpayPlugin\Form\EventListener\PreventSavingEmptyPasswordFieldsListener; use CommerceWeavers\SyliusTpayPlugin\Tpay\PaymentType; use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\Extension\Core\Type\ChoiceType; -use Symfony\Component\Form\Extension\Core\Type\PasswordType; use Symfony\Component\Form\Extension\Core\Type\TextType; use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Form\FormEvents; +use Symfony\Component\OptionsResolver\OptionsResolver; +use Symfony\Component\Validator\Constraints\NotBlank; final class TpayGatewayConfigurationType extends AbstractType { public function __construct( private readonly DecryptGatewayConfigListenerInterface $decryptGatewayConfigListener, private readonly EncryptGatewayConfigListenerInterface $encryptGatewayConfigListener, - private readonly PreventSavingEmptyPasswordFieldsListener $preventSavingEmptyClientSecretListener, ) { } @@ -35,13 +34,21 @@ public function buildForm(FormBuilderInterface $builder, array $options): void TextType::class, [ 'label' => 'commerce_weavers_sylius_tpay.admin.gateway_configuration.client_id', + 'validation_groups' => ['sylius'], + 'constraints' => [ + new NotBlank(allowNull: false, groups: ['sylius']), + ], ], ) ->add( 'client_secret', - PasswordType::class, + TextType::class, [ 'label' => 'commerce_weavers_sylius_tpay.admin.gateway_configuration.client_secret', + 'validation_groups' => ['sylius'], + 'constraints' => [ + new NotBlank(allowNull: false, groups: ['sylius']), + ], ], ) ->add( @@ -77,27 +84,29 @@ public function buildForm(FormBuilderInterface $builder, array $options): void ], ) ->add( - 'google_merchant_id', + 'notification_security_code', TextType::class, [ 'empty_data' => '', - 'label' => 'commerce_weavers_sylius_tpay.admin.gateway_configuration.google_merchant_id', + 'label' => 'commerce_weavers_sylius_tpay.admin.gateway_configuration.notification_security_code', ], ) ->add( - 'apple_pay_merchant_id', + 'google_merchant_id', TextType::class, [ 'empty_data' => '', - 'label' => 'commerce_weavers_sylius_tpay.admin.gateway_configuration.apple_pay_merchant_id', + 'label' => 'commerce_weavers_sylius_tpay.admin.gateway_configuration.google_merchant_id', + 'required' => false, ], ) ->add( - 'notification_security_code', - PasswordType::class, + 'apple_pay_merchant_id', + TextType::class, [ 'empty_data' => '', - 'label' => 'commerce_weavers_sylius_tpay.admin.gateway_configuration.notification_security_code', + 'label' => 'commerce_weavers_sylius_tpay.admin.gateway_configuration.apple_pay_merchant_id', + 'required' => false, ], ) ->add( @@ -115,6 +124,10 @@ public function buildForm(FormBuilderInterface $builder, array $options): void $builder->addEventListener(FormEvents::PRE_SET_DATA, $this->decryptGatewayConfigListener); $builder->addEventListener(FormEvents::POST_SUBMIT, $this->encryptGatewayConfigListener); - $builder->addEventListener(FormEvents::PRE_SUBMIT, $this->preventSavingEmptyClientSecretListener); + } + + public function configureOptions(OptionsResolver $resolver): void + { + $resolver->setDefault('validation_groups', ['sylius']); } } diff --git a/src/Payum/Factory/TpayGatewayFactory.php b/src/Payum/Factory/TpayGatewayFactory.php index c73a4998..f2a4c1c1 100644 --- a/src/Payum/Factory/TpayGatewayFactory.php +++ b/src/Payum/Factory/TpayGatewayFactory.php @@ -21,15 +21,11 @@ protected function populateConfig(ArrayObject $config): void $config['payum.api'] = function (ArrayObject $config): TpayApi { /** @var array{client_id?: string, client_secret?: string, production_mode?: bool, notification_security_code?: string} $config */ - $clientId = $config['client_id'] ?? null; - $clientSecret = $config['client_secret'] ?? null; + $clientId = $config['client_id'] ?? ''; + $clientSecret = $config['client_secret'] ?? ''; $productionMode = $config['production_mode'] ?? false; $notificationSecretCode = $config['notification_security_code'] ?? null; - if (null === $clientId || null === $clientSecret) { - throw new \InvalidArgumentException('Tpay ClientId and ClientSecret are required.'); - } - return new TpayApi($clientId, $clientSecret, $productionMode, notificationSecretCode: $notificationSecretCode); }; }