Magento – How to Redirect to a Custom Page After Order is Placed Using JS

checkoutpaymentpayment-gatewaythird-party-module

I want to be able to redirect to a custom page after the order is place so I can build a post request to a 3rd party payment gateway and send the customer to the payment gateway, similar to paypal flow.

Best Answer

At first, your custom payment UI component should extend Checkout default payment or it child - cc form component.

In your custom payment UI component, you can specify afterPlaceOrder method and set redirectAfterPlaceOrder to false to disable default behavior.

All logic, related to place order, is specified in placeOrder method:

placeOrder: function (data, event) {
    var self = this;

    if (event) {
        event.preventDefault();
    }

    if (this.validate() && additionalValidators.validate()) {
        this.isPlaceOrderActionAllowed(false);

        this.getPlaceOrderDeferredObject()
            .fail(
                function () {
                    self.isPlaceOrderActionAllowed(true);
                }
            ).done(
                function () {
                    self.afterPlaceOrder();

                    if (self.redirectAfterPlaceOrder) {
                        redirectOnSuccessAction.execute();
                    }
                }
            );

        return true;
    }

    return false;
}