如何呈现使用asp.net mvc从付款网关返回的HTML响应

问题描述 投票:1回答:1

我正在尝试与名为PayFort的支付网关集成,一切正常,我使用的方法返回HTML代码,这将是用户在付款过程中应该看到的页面。

[我需要的是如何将HTML响应呈现到浏览器中,我研究了一些解决方案,并且所有解决方案都使用StreamReader和Writer,我尝试通过直接由浏览器调用Payment方法URL来尝试它,并且它工作正常,但是当我试图从JS / Ajax调用它,但它没有执行任何操作,也没有启动HTML响应。

下面是我用于与Payment Gateway集成的代码:

  public string TryPayment(int ID)
    {
        var BaseURL = string.Format("{0}://{1}{2}", Request.Url.Scheme, Request.Url.Authority, Url.Content("~"));

        setConfig();
        api_url = Command.GetAPIURL(Command.IntegrationTypes.Redirect, true);

        package = Umbraco.Content(ID);
        int price = Convert.ToInt32(package.Value("price"));
        VALUE = price;

        MyReference = ("MyReference" + (DateTime.Now).ToString()).Replace(" ", "").Replace(":", "").Replace("/", "");

        createSignature(MyReference, VALUE);


        var newdata = "command=PURCHASE" +
         "&access_code=My Code" +
         "&merchant_identifier=My Identifier" +
         "&merchant_reference=" + MyReference +
         "&[email protected]" +
         "&amount=" + VALUE +
         "&currency=JOD&language=ar" +
         "&return_url=" + BaseURL + "umbraco/surface/FortResponse/working" +
         "&signature=" + signature;
        byte[] dataBytes = Encoding.UTF8.GetBytes(newdata);

        HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://sbcheckout.payfort.com/FortAPI/paymentPage");
        request.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate;
        request.ContentLength = dataBytes.Length;
        request.ContentType = "application/x-www-form-urlencoded";
        request.Method = "POST";

        using (Stream requestBody = request.GetRequestStream())
        {
            requestBody.Write(dataBytes, 0, dataBytes.Length);
        }

        using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
        using (Stream stream = response.GetResponseStream())
        using (StreamReader reader = new StreamReader(stream, Encoding.GetEncoding(response.CharacterSet)))
        {
            return reader.ReadToEnd();
        }

    }

[当我通过浏览器调用它时有效,但是当我通过JS / Ajax调用时不起作用。

任何见识将不胜感激。

我正在尝试与名为PayFort的支付网关集成,一切正常,我使用的方法返回了HTML代码,这将是用户应该看到的继续执行此页面的页面...]]

c# asp.net integration streamreader payfort
1个回答
0
投票
尝试以下方式

1)使用javaScriptsuccess: function(data) { window.location.href="nextstep.aspx"; }

© www.soinside.com 2019 - 2024. All rights reserved.