title: How to render HTML response that returned from a Payment gateway using asp.net mvc
body: <p>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.. </p>
  
  <p>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.</p>
  
  <p>Below is the code that I used to integrate with the Payment Gateway:</p>
  
  <pre><code>  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" +
           "&amp;access_code=My Code" +
           "&amp;merchant_identifier=My Identifier" +
           "&amp;merchant_reference=" + MyReference +
           "&amp;customer_email=Name@email.com" +
           "&amp;amount=" + VALUE +
           "&amp;currency=JOD&amp;language=ar" +
           "&amp;return_url=" + BaseURL + "umbraco/surface/FortResponse/working" +
           "&amp;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();
          }
  
      }
  </code></pre>
  
  <p>Which works when I call it by the browser but doesn't when I call it by JS/Ajax.</p>
  
  <p>Any insight would be appreciated.</p>