Redirect Episerver Form to Payment Page on Submission

99 views Asked by At

I'm seeking advice on how to essentially redirect an Episerver form to a payment page immediately after submission, including the form's field information (amount and number). The goal is to redirect the user to a payment gateway when they click "Make Payment," passing along the input from the Episerver form. Essentially, I want to redirect to the payment page with the field information on submission, and let the payment gateway handle the rest.

Form Fields

I attempted to use the "Trigger webhook after submission" option, but unfortunately, it didn't work as expected.

enter image description here

I'm curious if Episerver provides a built-in mechanism to achieve this, or if customization of the form submission method through code changes is necessary. Any insights or guidance would be greatly appreciated!

THis is where the form submission redirect which is a payment gateway with epi form fields enter image description here

1

There are 1 answers

2
Daniel van der Merwe On

It's not clear from your question how the payment gateway expects to receive the information it needs to process the payment. I'll assume that you can send it via querystring for the purposes of this answer.


To modify the URL you post to you can override the BuildReturnResultForSubmitAction method on DataSubmissionService.

Register dependency:

context.Services.AddTransient<DataSubmissionService, CustomDatasubmissionService>();

Inherit and override:

public class CustomDatasubmissionService : DataSubmissionService
{
    protected override SubmitActionResult BuildReturnResultForSubmitAction(bool isJavaScriptSupport, bool isSuccess,
                                            string message, HttpContextBase httpContext, FormContainerBlock formContainer = null, Dictionary<string, object> additionalParams = null,
                                            SubmissionInfo submissionInfo = null, Submission submission = null, bool isProgressiveSubmit = false, string redirectUrl = "")
    {
        var baseResult = base.BuildReturnResultForSubmitAction(isJavaScriptSupport, isSuccess, message, httpContext, formContainer, additionalParams, submissionInfo, submission, isProgressiveSubmit, redirectUrl);
        if (isSuccess) // only set redirect url when sucesss
        {
          // specify your own URL
          baseResult.RedirectUrl = "http://google.com";
        }

        return baseResult;
    }
}

The values from the form submission is available in submissionInfo.

Keep in mind that this code would execute for all form submissions so additional checks would be needed to only run the redirect logic for specific forms.

Code in this answer modified from this post on Optimizely World: https://world.optimizely.com/forum/developers-add-ons-forum/Forms/thread-container/2018/11/redirect-user-from-custom-actor-to-dynamically-generated-url/