If in your Magento, you have created a custom payment method, and using payment API for the transaction, and want to redirect to custom url after order place to complete transaction then, you can use following process.
Here is a blog to create custom payment method in Magento 2.
Blog link
Now in payment method file add following code:
file path: app/code/Test/Testpayment/view/frontend/web/js/view/payment/method-renderer/testpayment.js
/*browser:true*/ /*global define*/ define( [ 'ko', 'jquery', 'Magento_Checkout/js/view/payment/default', 'Test_Testpayment/js/action/set-payment-method-action' ], function (ko, $, Component, setPaymentMethodAction) { 'use strict'; return Component.extend({ defaults: { redirectAfterPlaceOrder: false, template: 'Test_Testpayment/payment/testpayment' }, afterPlaceOrder: function () { setPaymentMethodAction(this.messageContainer); return false; } }); } );
Now, create set payment method action file:
file path: app/code/Test/Testpayment/frontend/web/js/action/set-payment-method-action.js
/*jshint jquery:true*/ define( [ 'jquery', 'Magento_Checkout/js/model/quote', 'Magento_Checkout/js/model/url-builder', 'mage/storage', 'Magento_Checkout/js/model/error-processor', 'Magento_Customer/js/model/customer', 'Magento_Checkout/js/model/full-screen-loader' ], function ($, quote, urlBuilder, storage, errorProcessor, customer, fullScreenLoader) { 'use strict'; return function (messageContainer) { $.mage.redirect(url); //url is your url }; } );
Here,
In testpayment.js, we define,
redirectAfterPlaceOrder : false, it means we set default redirection to false.
setPaymentMethodAction: call to set payment method, so, this is your custom file and when your custom payment is got selected then your set-payment-action file get called.
In set-payment-method-action.js file,
we set redirect url to our custom payment method.
After this, flush the cache, and execute the code, and after order place your custom url get executed.
Hope this blog helps you to add functionality in Magento 2.
I hope this blog will help you with Redirect to Third Party Link after Order Placement in Magento 2. You may also check our wide range of best Magento 2 Extensions.
Please reach out to our team via a support ticket if you have any queries.
Try this and if you have any queries then just comment below 🙂
I am a newbie in Magento2,
I need to post Form and get Response to third party after order placed. please help