Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Kevin Meilander 78 posts 384 karma points c-trib
    Feb 08, 2022 @ 17:53
    Kevin Meilander
    0

    How does Vendr get the domain on BeginPaymentForm()

    I'm getting the wrong domain on my checkout step for Vendr.Extensions.BeginPaymentForm(order) form. This is causing issues when the payment processor redirects back to the site (it goes to the wrong domain). It's happening for all payment processors.

    When I look at Context.Request.Host, i see the correct domain, but the form submit URL has the wrong domain.

    I have a few layers of stuff in-front of my server, so I probably have something set wrong, but I can't figure out how this extension get the form submit URL is generated to try to debug the issue. Any details on this would be helpful.

  • Matt Brailsford 4124 posts 22215 karma points MVP 9x c-trib
    Feb 09, 2022 @ 08:34
    Matt Brailsford
    100

    Hi Kevin,

    The URL set on the form created by BeginPaymentForm comes from the payment provider, but from what you've said, I'm not sure this is the one you are having problems with.

    It sounds like it's the return, cancel and callback URLs which are indeed worked out from the current request.

    As of the latest release, our code for working out the baseUrl is

    var xForwardedProto = true;
    var xOriginalHost = true;
    
    string scheme = request.Headers["X-Forwarded-Proto"];
    if (scheme.IsNullOrWhiteSpace())
    {
        scheme = request.GetScheme();
        xForwardedProto = false;
    }
    
    string host = request.Headers["X-Original-Host"];
    if (host.IsNullOrWhiteSpace())
    {
        host = request.GetHost();
        xOriginalHost = false;
    }
    
    int port = int.Parse("0" + request.Headers["X-Forwarded-Port"]);
    if (port == 0)
    {
        string cfVisitor = request.Headers["CF-Visitor"];
        if (!cfVisitor.IsNullOrWhiteSpace())
        {
            port = cfVisitor.InvariantContains("https") ? 443 : 80;
        }
        else
        {
            port = xOriginalHost
                ? xForwardedProto
                    ? scheme.InvariantEquals("https") ? 443 : 80
                    : 80
                : request.GetPort();
        }
    }
    

    GetHost and GetPort or just wrapper extensions that wrap differences between .NET Framework / .NET Core.

    This does of course depend on what version of Vendr you are using as the CF-Visitor stuff was only added in a recent update.

    What do you have in front of your server?

  • Kevin Meilander 78 posts 384 karma points c-trib
    Feb 11, 2022 @ 01:35
    Kevin Meilander
    0

    Thanks.

    I'm using Azure Front Door and it was setting the X-Original-Host header.

    Once we disalbed that so the header wasn't set, everything was worked as expected.

  • Matt Brailsford 4124 posts 22215 karma points MVP 9x c-trib
    Feb 11, 2022 @ 10:56
    Matt Brailsford
    0

    Ahh, great stuff. Glad you found a workaround 👍

Please Sign in or register to post replies

Write your reply to:

Draft