public static void UpdateToken(ICEcashTokenResponse tokenObject)
        {
            string format         = "yyyyMMddHHmmss";
            var    IceDateNowtime = DateTime.Now;
            var    IceExpery      = DateTime.ParseExact(tokenObject.Response.ExpireDate, format, CultureInfo.InvariantCulture);

            var tokenDetails = InsuranceContext.TokenRequests.Single();

            if (tokenDetails != null)
            {
                tokenDetails.Token      = tokenObject.Response.PartnerToken;
                tokenDetails.ExpiryDate = IceExpery;
                tokenDetails.UpdatedOn  = DateTime.Now;
                InsuranceContext.TokenRequests.Update(tokenDetails);
            }
            else
            {
                TokenRequest request = new TokenRequest {
                    Token = tokenObject.Response.PartnerToken, ExpiryDate = IceExpery, UpdatedOn = DateTime.Now
                };
                InsuranceContext.TokenRequests.Insert(request);
            }
        }
        public ICEcashTokenResponse CheckSessionExpired()
        {
            Insurance.Service.ICEcashService ICEcashService = new Insurance.Service.ICEcashService();
            ICEcashTokenResponse             tokenObject    = new ICEcashTokenResponse();

            if (HttpContext.Current.Session["ICEcashToken"] != null)
            {
                var    icevalue       = (ICEcashTokenResponse)HttpContext.Current.Session["ICEcashToken"];
                string format         = "yyyyMMddHHmmss";
                var    IceDateNowtime = DateTime.Now;
                var    IceExpery      = DateTime.ParseExact(icevalue.Response.ExpireDate, format, CultureInfo.InvariantCulture);
                if (IceDateNowtime > IceExpery)
                {
                    ICEcashService.getToken();
                }
                tokenObject = (ICEcashTokenResponse)HttpContext.Current.Session["ICEcashToken"];
            }
            else
            {
                ICEcashService.getToken();
                tokenObject = (ICEcashTokenResponse)HttpContext.Current.Session["ICEcashToken"];
            }
            return(tokenObject);
        }
Beispiel #3
0
        public ICEcashTokenResponse getToken()
        {
            ICEcashTokenResponse json = null;

            try
            {
                //string json = "%7B%20%20%20%22PartnerReference%22%3A%20%228eca64cb-ccf8-4304-a43f-a6eaef441918%22%2C%0A%20%20%20%20%22Date%22%3A%20%22201801080615165001%22%2C%0A%20%20%20%20%22Version%22%3A%20%222.0%22%2C%0A%20%20%20%20%22Request%22%3A%20%7B%0A%20%20%20%20%20%20%20%20%22Function%22%3A%20%22PartnerToken%22%7D%7D";
                //string PSK = "127782435202916376850511";
                string    _json  = "";//"{'PartnerReference':'" + Convert.ToString(Guid.NewGuid()) + "','Date':'" + DateTime.Now.ToString("yyyyMMddhhmmss") + "','Version':'2.0','Request':{'Function':'PartnerToken'}}";
                Arguments objArg = new Arguments();
                objArg.PartnerReference = Guid.NewGuid().ToString();
                objArg.Date             = DateTime.Now.ToString("yyyyMMddhhmmss");
                objArg.Version          = "2.0";
                objArg.Request          = new FunctionObject {
                    Function = "PartnerToken"
                };

                _json = Newtonsoft.Json.JsonConvert.SerializeObject(objArg);

                //string  = json.Reverse()
                string reversejsonString      = new string(_json.Reverse().ToArray());
                string reversepartneridString = new string(PSK.Reverse().ToArray());

                string concatinatedString = reversejsonString + reversepartneridString;

                byte[] toEncodeAsBytes = System.Text.ASCIIEncoding.ASCII.GetBytes(concatinatedString);

                string returnValue = System.Convert.ToBase64String(toEncodeAsBytes);

                string GetSHA512encrypted = SHA512(returnValue);

                string MAC = "";

                for (int i = 0; i < 16; i++)
                {
                    MAC += GetSHA512encrypted.Substring((i * 8), 1);
                }

                MAC = MAC.ToUpper();


                ICERootObject objroot = new ICERootObject();
                objroot.Arguments = objArg;
                objroot.MAC       = MAC;
                objroot.Mode      = "SH";

                var data = Newtonsoft.Json.JsonConvert.SerializeObject(objroot);


                JObject jsonobject = JObject.Parse(data);

                //  var client = new RestClient(SandboxIceCashApi);
                var client  = new RestClient(LiveIceCashApi);
                var request = new RestRequest(Method.POST);
                request.AddHeader("cache-control", "no-cache");
                request.AddHeader("content-type", "application/x-www-form-urlencoded");
                request.AddParameter("application/x-www-form-urlencoded", jsonobject, ParameterType.RequestBody);
                IRestResponse response = client.Execute(request);

                json = JsonConvert.DeserializeObject <ICEcashTokenResponse>(response.Content);

                //HttpContext.Current.Session["ICEcashToken"] = json;
            }
            catch (Exception ex)
            {
                json = new ICEcashTokenResponse()
                {
                    Date = "", PartnerReference = "", Version = "", Response = new TokenReposone()
                    {
                        Result = "0", Message = "A Connection Error Occured ! Please add manually", ExpireDate = "", Function = "", PartnerToken = ""
                    }
                };
            }

            return(json);
        }