Beispiel #1
0
        public string QueryPayCode(String SessionKey, String payCode, String subscriberId)
        {
            ServicePointManager.ServerCertificateValidationCallback += (sender, cert, chain, sslPolicyErrors) => true;

            ServicePointManager.SecurityProtocol =
                (SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls) | (SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12);

            var iswResponse = string.Empty;

            try
            {
                String additionalParameters = "";


                QueryPayCodeStatus req = new QueryPayCodeStatus();
                req.paycode      = payCode;
                req.subscriberID = subscriberId;

                //String hashKey = Hash512("GENTOKEN" + tokenrequest.accountNo + tokenrequest.oneTimePin + tokenrequest.subscriberId);

                TokenGeneration generation = new TokenGeneration();
                iswResponse = generation.QueryPaycode("", subscriberId, req);
                nLogger.Info("Before Getting Authorisation");
                nLogger.Info("response :::::: " + iswResponse);
            }
            catch (WebException ex)
            {
                nLogger.Info(ex.ToString());
                try
                {
                    using (WebResponse response = ex.Response)
                    {
                        HttpWebResponse httpResponse = (HttpWebResponse)response;
                        nLogger.Info("Error code: {0}", httpResponse.StatusCode);
                        nLogger.Info("Status Description: {0}", httpResponse.StatusDescription);
                        string text = "";
                        using (Stream data = response.GetResponseStream())
                        {
                            text = new StreamReader(data).ReadToEnd();
                            nLogger.Info(text);
                        }
                    }
                }
                catch
                { nLogger.Info("Something went wrong"); }

                nLogger.Error(ex);
            }
            catch (Exception ex)
            {
                nLogger.Error(ex);
            }

            return(iswResponse);
        }
Beispiel #2
0
        public string QueryPaycode(String SessionKey,
                                   String subsciberId, QueryPayCodeStatus querypayCodeStatus)
        {
            string responseString = "";

            try
            {
                nLogger.Info("About to Get Response...  QueryPaycode ");

                //if (SessionKey != Hash512("GENTOKEN" + tokenrequest.accountNo + tokenrequest.oneTimePin + tokenrequest.subscriberId))
                //{
                //    return "67|Security Validation Failed";
                //}
                ServicePointManager.ServerCertificateValidationCallback += (sender, cert, chain, sslPolicyErrors) => true;

                ServicePointManager.SecurityProtocol =
                    (SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls) | (SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12);

                String httpMethod  = "GET";
                String resourceUrl = ConfigurationManager.AppSettings["AresourceUrlForQueryPayCode"];
                resourceUrl = resourceUrl.Replace("{subscriberId}", subsciberId);//Set the account number in the end point
                String clientId        = ConfigurationManager.AppSettings["AclientId"];
                String clientSecretKey = ConfigurationManager.AppSettings["AclientSecretKey"];

                String signatureMethod = "SHA1";//"SHA-1"

                HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(resourceUrl);
                httpWebRequest.Method = httpMethod;
                String clientIdBase64 = GetAsBase64(clientId);
                String authorization  = AUTHORIZATION_REALM + " " + clientIdBase64;


                long   timestamp = GetCurrentUnixTimestampMillis() / 1000;
                Guid   uuid      = Guid.NewGuid();
                String nonce     = uuid.ToString().Replace("-", "").Replace("+", "");

                String encodedResourceUrl = UpperCaseUrlEncode(resourceUrl);
                String signatureCipher    = httpMethod + "&" + encodedResourceUrl + "&"
                                            + timestamp + "&" + nonce + "&" + clientId + "&"
                                            + clientSecretKey;



                //if (!String.IsNullOrWhiteSpace(additionalParameters))
                //    signatureCipher = signatureCipher + "&" + additionalParameters;


                MessageDigest messageDigest = MessageDigest
                                              .GetInstance(signatureMethod);
                byte[] signatureBytes = messageDigest
                                        .Digest(Encoding.UTF8.GetBytes(signatureCipher)); //    // encode signature as base 64
                String signature = Convert.ToBase64String(signatureBytes);                //.Replace("+","%2B");

                httpWebRequest.Timeout          = 60000;
                httpWebRequest.ReadWriteTimeout = 60000;
                httpWebRequest.ContentType      = "application/json";
                httpWebRequest.KeepAlive        = false;
                //httpWebRequest.Headers.Add(HttpRequestHeader.Authorization, authorization);


                // httpWebRequest.Headers.Add("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)");
                String token = "";
                token = GetPassport();

                httpWebRequest.Headers.Add(HttpRequestHeader.Authorization, "InterswitchAuth " + clientIdBase64);

                httpWebRequest.Headers.Add(TIMESTAMP, timestamp.ToString());
                httpWebRequest.Headers.Add(NONCE, nonce);
                httpWebRequest.Headers.Add(SIGNATURE_METHOD, signatureMethod);
                httpWebRequest.Headers.Add(SIGNATURE, signature);
                httpWebRequest.Headers.Add(ACCESS_TOKEN, token);
                httpWebRequest.Headers.Add(paycode, querypayCodeStatus.paycode);
                //httpWebRequest.Headers.Add("frontEndPartnerId", FrontEndPartners.WEMA);
                //Authorization: Bearer (Access Token)
                //httpWebRequest.Headers.Add("Authorization", "eyJhbGciOiJSUzI1NiJ9.eyJzY29wZSI6WyJwcm9maWxlIl0sImV4cCI6MTQ3MTYwODQxNCwianRpIjoiNGM5YzEyODAtZTVjMC00OWQwLTkxOGQtZGJiYTI0NDczYjdlIiwiY2xpZW50X2lkIjoiSUtJQURGQjZGNTNGRUUzQ0U0QjY5MUIzNDNDNTVEMjk1NkJFMUNGNEE5QkMifQ.GY7U2UMVvUHSTqz_ybapCxEIA0jHUQdxXL_iuPOE_rcXecz7n0AzsFbM_Nt9bdOGRszQJ8amB3PUf638BR9lVCRWZU73OXN6G5G6o8t-ZjP2GThc4J-34sLl-yZWGZpP4Fu4uMKgz07276QSvMEPWPIBhvUYS2x1PAgXQXUV4ayGT3ps9ROv2uTkMhKgQsWyMUNsvnWSGDSQbVK7AUPFruYAMk-jxo8loY8T3edqRP-rk7ZO48SiLoNhq-YLTU_RLUK76g8c8RtKphOR2HGXOPW0IInxPKvpM5dItg6VxTdeHiJPnEPMlhVcMbvQjbe");

                Logheaders(httpWebRequest.Headers);

                String postData = JsonConvert.SerializeObject(querypayCodeStatus);
                nLogger.Info("post data query paycode  " + postData + "resource url" + resourceUrl);
                //StreamWriter requestWriter = new StreamWriter(httpWebRequest.GetRequestStream());
                ////requestWriter.Write(postData);
                //requestWriter.Close();


                nLogger.Info("About to Get Response...  ");
                var response = (HttpWebResponse)httpWebRequest.GetResponse();

                //nLogger.Info("RESPONSE: " + response.StatusCode);
                if (HttpStatusCode.OK == response.StatusCode || HttpStatusCode.Created == response.StatusCode)//Successful
                {
                    // Get the stream containing content returned by the server.
                    Stream dataStream = response.GetResponseStream();
                    // Open the stream using a StreamReader for easy access.
                    StreamReader reader = new StreamReader(dataStream);
                    // Read the content.
                    responseString = reader.ReadToEnd();
                }
                nLogger.Info("responseString " + responseString);
            }
            catch (WebException ex)
            {
                try
                {
                    nLogger.Error(ex);
                    nLogger.Info(ex.StackTrace);
                    nLogger.Info(ex.Message);

                    using (WebResponse response = ex.Response)
                    {
                        HttpWebResponse httpResponse = (HttpWebResponse)response;
                        nLogger.Info("Error code: {0}", httpResponse.StatusCode);
                        nLogger.Info("Status Description: {0}", httpResponse.StatusDescription);
                        string text = "";
                        using (Stream data = response.GetResponseStream())
                        {
                            text = new StreamReader(data).ReadToEnd();
                            nLogger.Info(text);
                        }
                    }
                }
                catch
                {
                }
            }
            catch (Exception ex)
            {
                //nLogger.Info(ex);
                nLogger.Info(ex.ToString());
            }

            return(responseString);
        }