简体   繁体   English

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

[英]How to render HTML response that returned from a Payment gateway using asp.net mvc

I am trying to integrate with a Payment gateway called PayFort, everything went okay and the method I that I used returns HTML code, which will be the page that a user should see to proceed in the payment process..我正在尝试与名为 PayFort 的支付网关集成,一切顺利,我使用的方法返回 HTML 代码,这将是用户在支付过程中应该看到的页面。

What I need is how to render that HTML response into the browser, I investigated about some solutions and all of them are using StreamReader and Writer I tried it by calling the Payment method URL directly by the browser and it worked perfectly, but when I tried to call it from JS/Ajax it didn't do any action, it didn't launch the HTML response.我需要的是如何将 HTML 响应呈现到浏览器中,我调查了一些解决方案,所有解决方案都在使用 StreamReader 和 Writer 我通过浏览器直接调用 Payment 方法 URL 进行了尝试,它运行良好,但是当我尝试时要从 JS/Ajax 调用它,它没有执行任何操作,也没有启动 HTML 响应。

Below is the code that I used to integrate with the 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 +
         "&customer_email=Name@email.com" +
         "&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();
        }

    }

Which works when I call it by the browser but doesn't when I call it by JS/Ajax.当我通过浏览器调用它时它有效,但当我通过 JS/Ajax 调用它时不起作用。

Any insight would be appreciated.任何见解将不胜感激。

After investigation i found that we can just include a form from front-side like this example: Pay-fort SDK example ,经过调查,我发现我们可以像这个例子一样从前端包含一个表单: Pay-fort SDK example

And no need to render the HTML response from back-side.并且无需从后端呈现 HTML 响应。

Try below ways试试下面的方法

1) Use javaScript success: function(data) { window.location.href="nextstep.aspx"; } 1)使用javaScript success: function(data) { window.location.href="nextstep.aspx"; } success: function(data) { window.location.href="nextstep.aspx"; }
or或者

2) Insert/update response into database. 2) 将响应插入/更新到数据库中。 Redirect user from payment page to VerifyPayment page and get database value here.将用户从支付页面重定向到 VerifyPayment 页面并在此处获取数据库值。

Note: Deploy your application and check, sometimes Ajax calls does not work in local.注意:部署您的应用程序并检查,有时 Ajax 调用在本地不起作用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将 Stripe 支付网关集成到 ASP.NET MVC - How to integrate Stripe payment gateway to ASP.NET MVC 如何使用 ASP.NET MVC 5 创建请求并将客户端重定向到 C# 中的支付网关主卡? - How create request and redirect client to payment gateway master card in C# using ASP.NET MVC 5? 从 ASP.NET MVC 5 中的支付网关重定向回来后的会话销毁问题 - session destroy problem after redirect back from payment gateway in ASP.NET MVC 5 如何使用 ASP.Net 和 C# 从 Paypal 支付网关的返回 URL 中获取交易详细信息 - How to Get Transaction Details from return URL from Paypal Payment Gateway using ASP.Net and C# 如何将ASP.NET MVC ViewResult呈现为HTML? - How to render an ASP.NET MVC ViewResult to HTML? 如何在ASP.NET MVC应用程序中使用Razor-engine中的Html.Displar渲染ModelMetadata对象? - How to render ModelMetadata object using Html.Displar in Razor-engine in ASP.NET MVC app? 如何使用 controller 或在 ASP.NET Core MVC 中查看 wwwroot 文件夹中的 index.html 文件 - How to render index.html file that is in wwwroot folder using controller or view in ASP.NET Core MVC 如何在ASP.NET Web表单中集成Instamojo付款网关 - How to integrate instamojo payment gateway in asp.net web forms 如何在asp.net网站上集成Paypal支付网关 - How to integrate Paypal payment Gateway in asp.net website 如何在ASP.NET中集成ccnow付款网关 - How to integrate ccnow payment gateway in asp.net
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM