diff --git a/config/services/context_provider.php b/config/services/context_provider.php index 1acb4a01..70a4775e 100644 --- a/config/services/context_provider.php +++ b/config/services/context_provider.php @@ -5,18 +5,10 @@ namespace Symfony\Component\DependencyInjection\Loader\Configurator; use CommerceWeavers\SyliusTpayPlugin\ContextProvider\RegulationsUrlContextProvider; -use CommerceWeavers\SyliusTpayPlugin\PayByLinkPayment\ContextProvider\BankListContextProvider; return static function(ContainerConfigurator $container): void { $services = $container->services(); - $services->set(BankListContextProvider::class) - ->args([ - service('commerce_weavers_sylius_tpay.tpay.provider.validated_tpay_api_bank_list'), - ]) - ->tag('sylius.ui.template_event.context_provider') - ; - $services->set(RegulationsUrlContextProvider::class) ->args([ service('sylius.context.locale'), diff --git a/config/services/pay_by_link_payment/context_provider.php b/config/services/pay_by_link_payment/context_provider.php index 9e511ce3..a57a6fa7 100644 --- a/config/services/pay_by_link_payment/context_provider.php +++ b/config/services/pay_by_link_payment/context_provider.php @@ -12,6 +12,7 @@ $services->set('commerce_weavers_sylius_tpay.pay_by_link_payment.context_provider.bank_list', BankListContextProvider::class) ->args([ service('commerce_weavers_sylius_tpay.tpay.provider.validated_tpay_api_bank_list'), + service('payum.dynamic_gateways.cypher'), ]) ->tag('sylius.ui.template_event.context_provider') ; diff --git a/src/PayByLinkPayment/ContextProvider/BankListContextProvider.php b/src/PayByLinkPayment/ContextProvider/BankListContextProvider.php index c7d32c1b..d629b09b 100644 --- a/src/PayByLinkPayment/ContextProvider/BankListContextProvider.php +++ b/src/PayByLinkPayment/ContextProvider/BankListContextProvider.php @@ -4,7 +4,11 @@ namespace CommerceWeavers\SyliusTpayPlugin\PayByLinkPayment\ContextProvider; +use CommerceWeavers\SyliusTpayPlugin\PayByLinkPayment\Payum\Factory\GatewayFactory as PayByLinkGatewayFactory; use CommerceWeavers\SyliusTpayPlugin\Tpay\Provider\ValidTpayChannelListProviderInterface; +use Payum\Core\Model\GatewayConfigInterface; +use Payum\Core\Security\CryptedInterface; +use Payum\Core\Security\CypherInterface; use Sylius\Bundle\UiBundle\ContextProvider\ContextProviderInterface; use Sylius\Bundle\UiBundle\Registry\TemplateBlock; use Sylius\Component\Core\Model\OrderInterface; @@ -19,6 +23,7 @@ final class BankListContextProvider implements ContextProviderInterface public function __construct( private readonly ValidTpayChannelListProviderInterface $validTpayChannelListProvider, + private readonly CypherInterface $cypher, ) { } @@ -28,21 +33,24 @@ public function provide(array $templateContext, TemplateBlock $templateBlock): a $templateContext['banks'] = []; $paymentMethod = $this->resolvePaymentMethod($templateContext); - $gatewayConfig = $paymentMethod?->getGatewayConfig()?->getConfig() ?? []; + $gatewayConfig = $paymentMethod?->getGatewayConfig(); if ( null === $paymentMethod || - 'pay_by_link' !== ($gatewayConfig['type'] ?? null) + null === $gatewayConfig || + PayByLinkGatewayFactory::NAME !== $gatewayConfig->getFactoryName() ) { return $templateContext; } + $decryptedGatewayConfig = $this->getEncryptedGatewayConfig($gatewayConfig); + /** * @phpstan-ignore-next-line * * @var string|null $tpayChannelId */ - $tpayChannelId = $gatewayConfig['tpay_channel_id'] ?? null; + $tpayChannelId = $decryptedGatewayConfig['tpay_channel_id'] ?? null; $templateContext['defaultTpayChannelId'] = $tpayChannelId; $templateContext['banks'] = null === $tpayChannelId ? $this->validTpayChannelListProvider->provide() : []; @@ -82,4 +90,13 @@ private function resolvePaymentMethod(array $templateContext): ?PaymentMethodInt return $paymentMethod; } + + private function getEncryptedGatewayConfig(GatewayConfigInterface $gatewayConfig): array + { + if ($gatewayConfig instanceof CryptedInterface) { + $gatewayConfig->decrypt($this->cypher); + } + + return $gatewayConfig->getConfig(); + } } diff --git a/src/PayByLinkPayment/Form/Type/GatewayConfigurationType.php b/src/PayByLinkPayment/Form/Type/GatewayConfigurationType.php index 92134556..07c99c63 100644 --- a/src/PayByLinkPayment/Form/Type/GatewayConfigurationType.php +++ b/src/PayByLinkPayment/Form/Type/GatewayConfigurationType.php @@ -5,7 +5,26 @@ namespace CommerceWeavers\SyliusTpayPlugin\PayByLinkPayment\Form\Type; use CommerceWeavers\SyliusTpayPlugin\Form\Type\AbstractTpayGatewayConfigurationType; +use Symfony\Component\Form\Extension\Core\Type\TextType; +use Symfony\Component\Form\FormBuilderInterface; final class GatewayConfigurationType extends AbstractTpayGatewayConfigurationType { + public function buildForm(FormBuilderInterface $builder, array $options): void + { + parent::buildForm($builder, $options); + + $builder + ->add( + 'tpay_channel_id', + TextType::class, + [ + 'empty_data' => '', + 'label' => 'commerce_weavers_sylius_tpay.admin.gateway_configuration.tpay_channel_id', + 'help' => 'commerce_weavers_sylius_tpay.admin.gateway_configuration.tpay_channel_id_help', + 'required' => false, + ], + ) + ; + } } diff --git a/templates/admin/payment_method/test_connection.html.twig b/templates/admin/payment_method/test_connection.html.twig index e989d3e6..938ac992 100644 --- a/templates/admin/payment_method/test_connection.html.twig +++ b/templates/admin/payment_method/test_connection.html.twig @@ -1,4 +1,4 @@ -{% if resource.gatewayConfig.factoryName == 'tpay' %} +{% if resource.gatewayConfig.factoryName == 'tpay_pbl' %}