diff --git a/spec/Provider/SaferpayPaymentMethodsProviderSpec.php b/spec/Provider/SaferpayPaymentMethodsProviderSpec.php index db7d13bf..86e6378b 100644 --- a/spec/Provider/SaferpayPaymentMethodsProviderSpec.php +++ b/spec/Provider/SaferpayPaymentMethodsProviderSpec.php @@ -47,4 +47,20 @@ function it_provides_an_array_with_payment_methods_from_saferpay_api( $this->provide($paymentMethod)->shouldReturn(['TWINT', 'VISA']); } + + function it_provides_an_empty_array_if_no_payment_methods_returned_from_api( + SaferpayClientInterface $client, + PaymentMethodInterface $paymentMethod, + GatewayConfigInterface $gatewayConfig, + ): void { + $paymentMethod->getGatewayConfig()->willReturn($gatewayConfig); + $client->getTerminal($gatewayConfig)->willReturn([ + 'Behavior' => 'DO_NOT_RETRY', + 'ErrorName' => 'VALIDATION_FAILED', + 'ErrorMessage' => 'invalid customerId', + 'StatusCode' => '400', + ]); + + $this->provide($paymentMethod)->shouldReturn([]); + } } diff --git a/src/Provider/SaferpayPaymentMethodsProvider.php b/src/Provider/SaferpayPaymentMethodsProvider.php index fd66f4f6..8aa1e6e9 100644 --- a/src/Provider/SaferpayPaymentMethodsProvider.php +++ b/src/Provider/SaferpayPaymentMethodsProvider.php @@ -20,6 +20,10 @@ public function provide(PaymentMethodInterface $paymentMethod): array Assert::notNull($gatewayConfig); $terminal = $this->client->getTerminal($gatewayConfig); + if (!isset($terminal['PaymentMethods'])) { + return []; + } + /** @var array $paymentMethodsData */ $paymentMethodsData = $terminal['PaymentMethods']; diff --git a/templates/Admin/PaymentMethod/ConfigurePaymentMethods/Form/_content.html.twig b/templates/Admin/PaymentMethod/ConfigurePaymentMethods/Form/_content.html.twig index 1b4f6ede..57a9d26e 100644 --- a/templates/Admin/PaymentMethod/ConfigurePaymentMethods/Form/_content.html.twig +++ b/templates/Admin/PaymentMethod/ConfigurePaymentMethods/Form/_content.html.twig @@ -4,7 +4,14 @@ {% include '@SyliusAdmin/Crud/form_validation_errors_checker.html.twig' %} {{ form_errors(form) }} -{{ sylius_template_event('commerce_weavers_saferpay.admin.payment_method.configure_payment_methods.form.content', _context) }} +{% if form.children.allowed_payment_methods.vars.value is empty %} +
+{% else %} + {{ sylius_template_event('commerce_weavers_saferpay.admin.payment_method.configure_payment_methods.form.content', _context) }} +{% endif %} {{ form_row(form._token) }} {{ form_end(form, {'render_rest': false}) }} diff --git a/translations/messages.en.yaml b/translations/messages.en.yaml index 22671fbc..74baebf5 100644 --- a/translations/messages.en.yaml +++ b/translations/messages.en.yaml @@ -1,4 +1,7 @@ commerce_weavers_saferpay: + form: + configure_payment_methods: + empty_list: 'There are no payment methods to select, check if the payment gateway configuration is correct.' ui: allowed_payment_methods: 'Allowed payment methods' configure_payment_methods: 'Configure payment methods'