Dynamically determining available payment methods
Some PSP allow determining the available payment methods dynamically, for example depending on the configuration in the PSP system, the customers country of origin or purchase history.
In such a case, a request is made to the payment service provider API, before the list of available payment methods is shown in the checkout.
The response will contain only those payment methods that should be made available to the customer.
In Hyvä checkout, the place to do such an API request is in an after-plugin on the method
The return value of the method contains all available payment methods.
The after-plugin can then remove any payment method that should not be available to the customer.
Be sure to declare the plugin in
etc/frontend/di.xml (not in global or admin scope):
<?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd"> <type name="Magento\Quote\Api\PaymentMethodManagementInterface"> <plugin name="example_payment_method" type="Example\PaymentProvider\Plugin\AvailableMethodsFilterPlugin"/> </type> </config>