Example #1
0
        public static void UpdateTillFetch(QueryPullAPIModel resp, int FetchedRecords)
        {
            int i = 0;

            using (SqlConnection con = new SqlConnection(CONSTANTS.DBConn))
            {
                try
                {
                    con.Open();
                    SqlCommand com = new SqlCommand("UPDATE TillPaymentFetching SET LastFetch=@LastFetch,OffSetValue=@OffSetValue where BusinessShortCode=@ShortCode", con)
                    {
                        CommandType = CommandType.Text
                    };

                    com.Parameters.AddWithValue("@ShortCode", resp.ShortCode);
                    com.Parameters.AddWithValue("@LastFetch", resp.EndDate);
                    com.Parameters.AddWithValue("@OffSetValue", FetchedRecords);
                    i = com.ExecuteNonQuery();
                }
                catch (Exception ex)
                {
                    // ErrorLogger.writeLogs("sql Executor: " + ex.Message);
                }
            }
        }
Example #2
0
        public static PullRequestModel PullPayments(QueryPullAPIModel request, string ConsumerKey, string ConsumerSecret)
        {
            //var serializer = new JavaScriptSerializer();
            string         serializedBodyRequest = JsonConvert.SerializeObject(request);
            HttpWebRequest httpRequest           = (HttpWebRequest)WebRequest.Create(CONSTANTS.PullAPIQuery);

            httpRequest.ContentType = "application/json";
            httpRequest.Method      = "POST";
            httpRequest.Headers.Add("Authorization", "Bearer " + PullAPIHttp.GetAuthen(ConsumerKey, ConsumerSecret));
            using (var streamWriter = new StreamWriter(httpRequest.GetRequestStream()))
            {
                streamWriter.Write(serializedBodyRequest);
                streamWriter.Flush();
                streamWriter.Close();
            }
            try
            {
                HttpWebResponse httpResponse = (HttpWebResponse)httpRequest.GetResponse();
                var             result       = "";
                using (var responseStream = new StreamReader(httpResponse.GetResponseStream()))
                {
                    result = responseStream.ReadToEnd();
                }
                PullRequestModel resp = JsonConvert.DeserializeObject <PullRequestModel>(result);
                Console.WriteLine("" + request.ShortCode + "    " + resp.ResponseCode + "   " + resp.ResponseMessage);
                if (resp == null)
                {
                    Console.WriteLine("An error has occurred");
                }
                if (resp.ResponseCode == "1000")
                {
                    PullAPISQL.ProcessPulledPayments(resp, request.ShortCode);
                    PullAPISQL.UpdateTillFetch(request, resp.Response[0].Count);
                }
                else
                {
                    PullAPISQL.UpdateTillFetch(request, 0);
                }

                Console.WriteLine(resp.ToString());
                return(resp);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
                //  Console.ReadLine();
                return(null);
            }
        }
Example #3
0
        static void QueryAPI(string BusinessShortCode, DateTime LastFetch)
        {
            string ConsumerKey    = "SMlhAybuDaPM0hF1D5yf0qpqxpT9bRST";
            string ConsumerSecret = "gKzz96uxFZRGHRnA";
            var    _data          = new QueryPullAPIModel()
            {
                ShortCode   = BusinessShortCode,
                StartDate   = LastFetch.AddMinutes(-4).ToString("yyyy-MM-dd HH:mm:ss"),
                EndDate     = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
                OffSetValue = 0
            };

            var Response = PullAPIHttp.PullPayments(_data, ConsumerKey, ConsumerSecret);
            //Console.WriteLine(JsonConvert.SerializeObject(Response).ToString());
            //return 0;
        }