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
/**
* Copyright © 2016 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
/**
* Customer store credit(balance) application
*/
/*global define,alert*/
define(
[
'ko',
'jquery',
'Magento_Checkout/js/model/quote',
'Magento_Checkout/js/model/resource-url-manager',
'Magento_Checkout/js/model/error-processor',
'Magento_SalesRule/js/model/payment/discount-messages',
'mage/storage',
'mage/translate',
'Magento_Checkout/js/action/get-payment-information',
'Magento_Checkout/js/model/totals'
],
function (
ko,
$,
quote,
urlManager,
errorProcessor,
messageContainer,
storage,
$t,
getPaymentInformationAction,
totals
) {
'use strict';
return function (couponCode, isApplied, isLoading) {
var quoteId = quote.getQuoteId();
var url = urlManager.getApplyCouponUrl(couponCode, quoteId);
var message = $t('Your coupon was successfully applied.');
return storage.put(
url,
{},
false
).done(
function (response) {
if (response) {
var deferred = $.Deferred();
isLoading(false);
isApplied(true);
totals.isLoading(true);
getPaymentInformationAction(deferred);
$.when(deferred).done(function () {
totals.isLoading(false);
});
messageContainer.addSuccessMessage({'message': message});
}
}
).fail(
function (response) {
isLoading(false);
totals.isLoading(false);
errorProcessor.process(response, messageContainer);
}
);
};
}
);
Here in this js file you can see
if (response) {
var deferred = $.Deferred();
isLoading(false);
isApplied(true);
totals.isLoading(true);
getPaymentInformationAction(deferred);
$.when(deferred).done(function () {
totals.isLoading(false);
});
messageContainer.addSuccessMessage({'message': message});
}
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 !!
We can set the image in html template, like Paypal
We add the image in html template
vendor/magento/module-paypal/view/frontend/web/template/payment/paypal-express.html
<!-- PayPal Logo -->
<img data-bind="attr: {src: getPaymentAcceptanceMarkSrc(), alt: $t('Acceptance Mark')}"
class="payment-icon"/>
Try to get the image path from the global checkout config js variable
vendor/magento/module-paypal/view/frontend/web/js/view/payment/method-renderer/paypal-express-abstract.js
/** Returns payment acceptance mark image path */
getPaymentAcceptanceMarkSrc: function () {
return window.checkoutConfig.payment.paypalExpress.paymentAcceptanceMarkSrc;
},
We need to set this config in config provider:
vendor/magento/module-paypal/Model/ExpressConfigProvider.php
$config = [
'payment' => [
'paypalExpress' => [
'paymentAcceptanceMarkHref' => $this->config->getPaymentMarkWhatIsPaypalUrl(
$this->localeResolver
),
'paymentAcceptanceMarkSrc' => $this->config->getPaymentMarkImageUrl(
$locale
),
'isContextCheckout' => false,
'inContextConfig' => []
]
]
];
Best Answer
Its quite a lot of works. You need to go to that payment module, find
find something like this:
right below it, put something like this:
and then you need to specify the knockoutJS data-bind function, in this case fpxImageSrc'. Go to
then right below Component extend, it should look like:
Add single line fpxImageSrc or whatever name you choose, inside that file, like this one at that particular spot:
then you need to create one phtml templates file, in this case I name it payment_image.phtml. The file should be inside
right after that, you add something like this code:
then you need to add this phtml template on layout, the layout files can be found inside the module:
there, you need to add
after that, create block file, in this case I named it PopulateFpx.php, inside the module:
and then:
and then put the image file, in this case I named it fpx_logo.png, inside: