I am developing a magento custom payment method(gateway) and in order to redirect the user to the gateway I want to set on the checkout form to redirect to the custom gateways url with the coresponding parameters. So I created a custom controller action and want to redirect the user there so the POST data is created and from there to my custom gateways checkout page(http://somewhereonthenet.com).
The problem is that I do not know how to set the route or url for my action in the javascript so I can use it there. The javascript to redirect to my method is as follows:
/** Redirect to gateway */
continueToGateway: function () {
if (additionalValidators.validate()) {
//update payment method information if additional data was changed
this.selectPaymentMethod();
setPaymentMethodAction(this.messageContainer).done(
function () {
customerData.invalidate(['cart']);
$.mage.redirect(
window.checkoutConfig.payment // Dont know what to put here and how to set it
);
}
;
return false;
}
}
And in the template it looks like this:
<div class="actions-toolbar">
<div class="primary">
<button class="action primary checkout" type="submit"
data-bind="click: continueToGateway, enable: (getCode() == isChecked())"
disabled>
<span data-bind="i18n: 'Continue to gateway'"></span>
</button>
</div>
</div>
The code is working and it goes to the $.mage.redirect()
but I do not know how to insert my module action url here.
So in this code I have to redirect to my custom action how to do that? Any help is appreciated.
Best Answer
Create a di.xml [Vendor]/[Module]/etc/frontend/di.xml
Create a config provider [Vendor]/[Module]/Model/CustomConfigProvider.php
now you can access this from js following way