我正在尝试与名为 PayFort 的支付网关集成,一切正常,我使用的方法返回 HTML 代码,这将是用户在支付过程中应该看到的页面。
我需要的是如何将该 HTML 响应呈现到浏览器中,我调查了一些解决方案,它们都使用 StreamReader 和 Writer 我通过浏览器直接调用支付方法 URL 进行了尝试,它运行良好,但是当我尝试从 JS/Ajax 调用它没有执行任何操作,也没有启动 HTML 响应。
下面是我用来与支付网关集成的代码:
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 +
"¤cy=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 调用它时无效。
任何见解将不胜感激。