Magento has its own api function which provides list of payment depending on the quote. Here you need to just send quote id to get the payment method list.
For example, to get the available payment methods you can use Magento SOAP API v1:
$client = new SoapClient('http://magentohost/api/soap/?wsdl');
// If somestuff requires api authentification,
// then get a session token
$session = $client->login('apiUser', 'apiKey');
$result = $client->call($session, 'cart_payment.list', 'quoteId');
var_dump($result);
See more at http://www.magentocommerce.com/api/soap/checkout/cartPayment/cart_payment.list.html
The rendererList
is observable JavaScript array provided by the Magento_Checkout/js/model/payment/renderer-list
component.
In order to use rendererList
in custom payment module the following should be done:
- Create in your module
view/frontend/layout/checkout_index_index.xml
file and declare new payment renderer component (adding as an image to give an idea):
- Create the
Custom_Payment/js/view/payment/custom_payment.js
component
and add rendererList
component as a dependency. It will allow you to add custom payment renderer into rendererList
array:
define(
[
'uiComponent',
'Magento_Checkout/js/model/payment/renderer-list'
],
function (
Component,
rendererList
) {
'use strict';
rendererList.push(
{
type: 'custom_payment',
component: 'Custom_Payment/js/view/payment/method-renderer/custom-payment-renderer'
}
);
/** Add view logic here if needed */
return Component.extend({});
}
);
- Create
Custom_Payment/js/view/payment/method-renderer/custom-payment-renderer
component and assign template to render custom payment:
define(
[
'jquery',
'Magento_Payment/js/view/payment/iframe',
'Magento_Checkout/js/action/set-payment-information'
],
function ($, Component, setPaymentInformationAction) {
'use strict';
return Component.extend({
defaults: {
template: 'Custom_Payment/payment/custom-payment'
},
...
});
}
);
- Finally, create
Custom_Payment/view/frontend/web/template/payment/custom-payment.html
template to have custom payment form.
All Core Payment modules modifies rendererList
in the way described above.
I hope answer gives you an idea how rendererList
is filled with payment methods.
It is recommended to add custom js files via checkout_index_index.xml
. This has to be done very carefully, respecting nested levels of jsLayout
component.
Let me know if you still have questions.
Best Answer
If you look in default Magento functionality for "Apply Discount" on checkout/payment page, you will get it. Navigate to Magento/module-sales-rule/view/frontend/web/js/action/set-coupon-code.js
Here in this js file you can see
in this code fragment, you can see
getPaymentInformationAction(deferred);
is the one which will reload/refresh payment method as per your requirement . Try this in your custom js with condition. cheers !!