Example #1
0
        //public ResultRootObject RequestQuote(string PartnerToken, string RegistrationNo, string make, string model, string PartnerReference)
        public ResultRootObject RequestQuote(string PartnerToken, string RegistrationNo, string suminsured, string make, string model, int PaymentTermId, int VehicleYear, int CoverTypeId, int VehicleUsage, string PartnerReference)
        {
            //string PSK = "127782435202916376850511";
            string _json = "";


            make  = RemoveSpecialChars(make);
            model = RemoveSpecialChars(model);

            //var CustomerInfo = (CustomerModel)HttpContext.Current.Session["CustomerDataModal"];

            List <VehicleObjectVRN> obj = new List <VehicleObjectVRN>();

            //foreach (var item in listofvehicles)
            //{

            //obj.Add(new VehicleObjectVRN { VRN = RegistrationNo, DurationMonths = (PaymentTermId == 1 ? 12 : PaymentTermId), VehicleValue = Convert.ToInt32(suminsured), YearManufacture = Convert.ToInt32(VehicleYear), InsuranceType = Convert.ToInt32(CoverTypeId), VehicleType = Convert.ToInt32(VehicleUsage), TaxClass = 1, Make = make, Model = model, EntityType = "", Town = CustomerInfo.City, Address1 = CustomerInfo.AddressLine1, Address2 = CustomerInfo.AddressLine2, CompanyName = "", FirstName = CustomerInfo.FirstName, LastName = CustomerInfo.LastName, IDNumber = CustomerInfo.NationalIdentificationNumber, MSISDN = CustomerInfo.CountryCode + CustomerInfo.PhoneNumber });

            obj.Add(new VehicleObjectVRN {
                VRN = RegistrationNo
            });

            //}

            QuoteArgumentsVRN objArg = new QuoteArgumentsVRN();

            objArg.PartnerReference = Guid.NewGuid().ToString();;
            objArg.Date             = DateTime.Now.ToString("yyyyMMddhhmmss");
            objArg.Version          = "2.0";
            objArg.PartnerToken     = PartnerToken;
            objArg.Request          = new QuoteFunctionObjectVRN {
                Function = "TPIQuote", Vehicles = obj
            };

            _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();

            ICEQuoteRequestVRN objroot = new ICEQuoteRequestVRN();

            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("http://api-test.icecash.com/request/20523588");
            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);

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


            //int PaymentTermId=Convert.ToInt32(json.Response.Quotes[0].Policy.DurationMonths);

            if (json.Response.Quotes != null && json.Response.Quotes.Count > 0)
            {
                if (json.Response.Quotes[0].Policy != null)
                {
                    var Setting = InsuranceContext.Settings.All();
                    var DiscountOnRenewalSettings = Setting.Where(x => x.keyname == "Discount On Renewal").FirstOrDefault();
                    var premium = Convert.ToDecimal(json.Response.Quotes[0].Policy.CoverAmount);
                    switch (PaymentTermId)
                    {
                    case 1:
                        var AnnualRiskPremium = premium;
                        if (DiscountOnRenewalSettings.ValueType == Convert.ToInt32(eSettingValueType.percentage))
                        {
                            json.LoyaltyDiscount = ((AnnualRiskPremium * Convert.ToDecimal(DiscountOnRenewalSettings.value)) / 100);
                        }
                        if (DiscountOnRenewalSettings.ValueType == Convert.ToInt32(eSettingValueType.amount))
                        {
                            json.LoyaltyDiscount = Convert.ToDecimal(DiscountOnRenewalSettings.value);
                        }
                        break;

                    case 3:
                        var QuaterlyRiskPremium = premium;
                        if (DiscountOnRenewalSettings.ValueType == Convert.ToInt32(eSettingValueType.percentage))
                        {
                            json.LoyaltyDiscount = ((QuaterlyRiskPremium * Convert.ToDecimal(DiscountOnRenewalSettings.value)) / 100);
                        }
                        if (DiscountOnRenewalSettings.ValueType == Convert.ToInt32(eSettingValueType.amount))
                        {
                            json.LoyaltyDiscount = Convert.ToDecimal(DiscountOnRenewalSettings.value);
                        }
                        break;

                    case 4:
                        var TermlyRiskPremium = premium;
                        if (DiscountOnRenewalSettings.ValueType == Convert.ToInt32(eSettingValueType.percentage))
                        {
                            json.LoyaltyDiscount = ((TermlyRiskPremium * Convert.ToDecimal(DiscountOnRenewalSettings.value)) / 100);
                        }
                        if (DiscountOnRenewalSettings.ValueType == Convert.ToInt32(eSettingValueType.amount))
                        {
                            json.LoyaltyDiscount = Convert.ToDecimal(DiscountOnRenewalSettings.value);
                        }
                        break;
                    }
                }
            }
            return(json);
        }
Example #2
0
        public ResultRootObject checkVehicleExistsWithVRN(List <RiskDetailModel> listofvehicles, string PartnerToken, string PartnerReference)
        {
            string _json = "";

            List <VehicleObjectVRN> obj = new List <VehicleObjectVRN>();

            // var CustomerInfo = (CustomerModel)HttpContext.Current.Session["CustomerDataModal"];


            foreach (var item in listofvehicles)
            {
                obj.Add(new VehicleObjectVRN {
                    VRN = item.RegistrationNo
                });
            }

            QuoteArgumentsVRN objArg = new QuoteArgumentsVRN();

            objArg.PartnerReference = Guid.NewGuid().ToString();
            objArg.Date             = DateTime.Now.ToString("yyyyMMddhhmmss");
            objArg.Version          = "2.0";
            objArg.PartnerToken     = PartnerToken;
            objArg.Request          = new QuoteFunctionObjectVRN {
                Function = "TPIQuote", Vehicles = obj
            };



            _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();

            //ICEQuoteRequest objroot = new ICEQuoteRequest();

            ICEQuoteRequestVRN objroot = new ICEQuoteRequestVRN();

            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("http://api-test.icecash.com/request/20523588");



            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);

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

            return(json);
        }