I have created a custom payment module, and when I click the Place Order button, I need it to run a set of custom javascript functions. To do this, how do I include a custom function from another javascript file into the /view/frontend/web/js/view/payment/ javascript file?
Submit Button:
<button
data-role="review-save"
type="submit"
data-bind="
attr: {title: $t('Place Order')},
enable: (getCode() == isChecked()),
click: processPayment, <--custom method-renderer function
css: {disabled: !isPlaceOrderActionAllowed()}
"
class="action primary checkout"
disabled
>
<span data-bind="i18n: 'Place Order'"></span>
</button>
method-renderer function
define([
'jquery',
'Magento_Payment/js/view/payment/cc-form',
],
function ($, Component) {
'use strict';
return Component.extend({
defaults: {
template: '<Module>/payment/<File>'
},
context: function() {
return this;
},
getCode: function() {
return '<Code>';
},
isActive: function() {
return true;
},
processPayment() {
authorizePayment(); <-- Custom Javascript Function from seperate file
}
});
}
);
Best Answer
You can use that function in enable property of button.
Method Render function