I have followed sample-module-payment-gateway to implement Payment method in Magento 2.
But for some strange reason, Custom Config Provider in Magento is not working. It throws Following error :
TypeError: window.checkoutConfig.payment.test_finance is undefined
Here is the di.xml
<?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\Checkout\Model\CompositeConfigProvider">
<arguments>
<argument name="configProviders" xsi:type="array">
<item name="Test_finance" xsi:type="object">TestCapital\Finance\Model\CustomConfigProvider</item>
</argument>
</arguments>
</type>
<virtualType name="TestFinanceFacade" type="Magento\Payment\Model\Method\Adapter">
<arguments>
<argument name="code" xsi:type="const">TestCapital\Finance\Model\Payment\TestFinance::METHOD_CODE</argument>
<argument name="formBlockType" xsi:type="string">TestCapital\Finance\Block\Form</argument>
<argument name="infoBlockType" xsi:type="string">TestCapital\Finance\Block\Info</argument>
<argument name="valueHandlerPool" xsi:type="object">TestCapitalValueHandlerPool</argument>
<!-- argument name="validatorPool" xsi:type="object">TestCapitalValidatorPool</argument -->
<!-- argument name="commandPool" xsi:type="object">TestCapitalCommandPool</argument -->
</arguments>
</virtualType>
<virtualType name="TestFinanceConfig" type="Magento\Payment\Gateway\Config\Config">
<arguments>
<argument name="test_finance" xsi:type="const">TestCapital\Finance\Model\CustomConfigProvider::METHOD_CODE</argument>
</arguments>
</virtualType>
<!-- Value handlers infrastructure -->
<virtualType name="TestFinaceGatewayValueHandlerPool" type="Magento\Payment\Gateway\Config\ValueHandlerPool">
<arguments>
<argument name="handlers" xsi:type="array">
<item name="default" xsi:type="string">TestFinaceConfigValueHandler</item>
</argument>
</arguments>
</virtualType>
<virtualType name="TestFinaceConfigValueHandler" type="Magento\Payment\Gateway\Config\ConfigValueHandler">
<arguments>
<argument name="configInterface" xsi:type="object">TestFinanceConfig</argument>
</arguments>
</virtualType>
<type name="TestCapital\Finance\Block\Info">
<arguments>
<argument name="config" xsi:type="object">TestFinanceConfig</argument>
</arguments>
</type>
</config>
TestCapital/Finance/Model/CustomConfigProvider.php
namespace TestCapital\Finance\Model;
use Magento\Checkout\Model\ConfigProviderInterface;
use Magento\Framework\Escaper;
use Magento\Payment\Helper\Data as PaymentHelper;
class CustomConfigProvider implements ConfigProviderInterface {
const METHOD_CODE = 'test_finance';
public function getConfig() {
$config = [
'payment' => array (
self::METHOD_CODE => array (
'storedCards' => $this->getStoredCards(),
)
)
];
return $config;
}
public function getStoredCards(){
$result = array();
$result['0'] = "Test";
$result['1'] = "Test1";
return $result;
}
}
TestCapital/Finance/view/frontend/web/js/view/payment/method-renderer/test-finance-method.js
getStoreCard: function() {
return window.checkoutConfig.payment.test_finance.storedCards;
},
TestCapital/Finance/view/frontend/web/template/payment/omni_finance.html
<label>Select Finance Package</label>
<select name="payment[subscription_id]" class="select input-text required-entry"
data-bind="
attr: {id: getCode()+'_payment_profile_id'},
options: getCardList(),
optionsValue: 'value',
optionsText: 'type',
optionsCaption: $t('--Please Select A Package--'),
">
</select>
Best Answer
Eventually got this Resolved.
I had misplaced
di.xml
once i moved di.xml to
etc/frontend
folder everything works fine now.Anyone looking for this, Here is the correct location for di.xml