Read More
Read More
Menu Close

    Redirect to third party link after order place magento2

    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 magento2.
    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 ?
    Read 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 magento2.

    Thank you.



    . . .
    Discuss on Helpdesk

    Leave a Comment

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


  • Viet duong
    Thank a lot,
    I am a newbie in Magento2,
    I need to post Form and get Response to third party after order placed. please help
  • Back to Top