Back to Top

Redirect to Third Party Link after Order Placement in Magento 2

Updated 16 February 2024

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

/*global define*/
    function (ko, $, Component, setPaymentMethodAction) {
        'use strict';
        return Component.extend({
            defaults: {
                redirectAfterPlaceOrder: false,
                template: 'Test_Testpayment/payment/testpayment'
            afterPlaceOrder: function () {
                return false;

Now, create set payment method action file:

file path: app/code/Test/Testpayment/frontend/web/js/action/set-payment-method-action.js

Searching for an experienced
Magento 2 Company ?
Find out More
/*jshint jquery:true*/
    function ($, quote, urlBuilder, storage, errorProcessor, customer, fullScreenLoader) {
        'use strict';
        return function (messageContainer) {
            $.mage.redirect(url); //url is your url


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 🙂

. . .

Leave a Comment

Your email address will not be published. Required fields are marked*


  • Viet duong
  • Back to Top

    Message Sent!

    If you have more details or questions, you can reply to the received confirmation email.

    Back to Home