I have custom method in my store (I used \Magento\Payment\Model\Method\AbstractMethod class). In the isAvailable method, I get a string that I would like to display to the customer at the checkout. Now, the checkout looks like this:

enter image description here

But I would like to be able to display additional message here, like this:

enter image description here

The additional string is constructed in isAvailable, so all I need is to pass it to method-renderer.js or checkout_index_index.xml (I think).

I can also construct the string in custom controller, so I was thinking of adding some JS to checkout that will hit custom controller with HTTP GET request and then add it to the source, but I hope there is a better way to do it.

  • you need to add additional string on checkout page right ? – Yogesh Nov 13 '17 at 10:30
  • @Yogesh yes, I need to display string when choosing payment option. But this string is different every time. – Adam Ježek Nov 13 '17 at 14:21

I have posted basic code for passing data to checkout payment form which you can modified as per your requirement. create SampleConfigProvider.php under File path :-



 namespace Namespace\Modulename\Model;

 use Magento\Checkout\Model\ConfigProviderInterface;

   * Class SampleConfigProvider

 class SampleConfigProvider implements ConfigProviderInterface

   public function getStoredCards(){
      $result = "This is your string";
      return $result;

   public function getConfig()

     $config = array_merge_recursive($config, [
       'payment' => [
          \Namespace\Modulename\Model\Payment::CODE => [
            'storedCards' => $this->getStoredCards(),
   return $config;

Then add CompositeConfigProvider in frontend/di.xml

File Namespace/Modulename/etc/frontend/di.xml

<?xml version="1.0" encoding="UTF-8"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="Magento\Payment\Model\CcGenericConfigProvider">
    <argument name="methodCodes" xsi:type="array">
        <item name="test_payment" xsi:type="const">Namespace\Modulename\Model\Payment::CODE</item>
<type name="Magento\Checkout\Model\CompositeConfigProvider">
    <argument name="configProviders" xsi:type="array">
        <item name="test_payment_config_provider" xsi:type="object">Namespace\Modulename\Model\SampleConfigProvider</item>

add code in your js file which are present in give path (Namespace/Modulename/view/frontend/web/js/view/payment/method-renderer) :

   getStoreCard: function() {
        return  window.checkoutConfig.payment.PAYMENTMETHODCODE.storedCards;

Now you can get this string your html file which is located on (Namespace/Modulename/view/frontend/web/template/payment)

<span><!-- ko i18n: getStoreCard() --><!-- /ko --></span>

You can adjust location of code based on where you want to display,You can take a reference this answer & this blog .

You should not add string in isAvailable method because when you check in parent class its return boolean value

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.