Your browser (Internet Explorer 6) is out of date. It has known security flaws and may not display all features of this and other websites. Learn how to update your browser.
X

Getting Response from Interswitch WebPay API in C#

I got one of my well respected colleagues trying to fix Interswitch Webpay for a client and it looks like I have been so lucky to have got this same endpoint implemented in PHP because we seems not be able to get the right response from Webpay. After intense debugging we got the C# code working and I decided to document our observations. Find below what worked


HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://stageserv.interswitchng.com/test_paydirect/api/v1/gettransaction.json?" + param);
request.Method = "GET";
request.Timeout = 1000000;
request.ContentType = "application/json";
request.Headers.Add("Hash", hash);
request.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322; .NET CLR 2.0.50727)";

Stream dataStream = null;
using (WebResponse response = request.GetResponse())
{
    using (dataStream = response.GetResponseStream())
    {
        using (StreamReader reader = new StreamReader(dataStream))
        {
            string responseFromServer = reader.ReadToEnd();
            string res = string.Format("Status Code: {0}, Response: {1}", ((HttpWebResponse)response).StatusCode,
                responseFromServer);

            var json = JsonConvert.DeserializeObject(responseFromServer);
            
            _response.ResponseCode = json.ResponseCode;
            _response.ResponseDescription = json.ResponseDescription;
            _response.PaymentReference = json.PaymentReference;

            return _response;
        }
    }
}

param, this is as specified in Interswitch WebPay's documentation.

Hope this helps someone, drop a comment if it does.

 


comments powered by Disqus