Skip to content

Commit

Permalink
Merge pull request #66 from GSadee/fix-configuring-payment-methods
Browse files Browse the repository at this point in the history
Fix configuring allowed payment methods if the list is empty
  • Loading branch information
Zales0123 authored Jun 14, 2023
2 parents 666b633 + 8b0c6c5 commit c7e4efd
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 1 deletion.
16 changes: 16 additions & 0 deletions spec/Provider/SaferpayPaymentMethodsProviderSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -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([]);
}
}
4 changes: 4 additions & 0 deletions src/Provider/SaferpayPaymentMethodsProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 %}
<div class="ui icon info message">
<i class="info circle icon"></i>
<div class="content">{{ 'commerce_weavers_saferpay.form.configure_payment_methods.empty_list'|trans }}</div>
</div>
{% 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}) }}
3 changes: 3 additions & 0 deletions translations/messages.en.yaml
Original file line number Diff line number Diff line change
@@ -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'
Expand Down

0 comments on commit c7e4efd

Please sign in to comment.