Request Quote

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

/*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 magento2.

Thank you.

 

 

. . .

Comment

Add Your Comment

Be the first to comment.

css.php